feat(inject): record injection history for activity log + prompt autocomplete

Every injection now writes to prompt_history (fire-and-forget, same as the
existing orchestration events). This feeds two already-built but data-starved
features:
- ActivityLogPanel on the Control page (recentActivity feed)
- recentCustomPrompts autocomplete in each project card's composer

Stores full customPrompt text, canonical projectKey, projectPath, adapter,
and resolved intent. Uses parseProjectsConf() to resolve the project dir
without an extra map lookup.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
g-butandClaude Sonnet 4.6 committed 2026-05-09 17:49:17 +02:00
1 parent b3d9e5aabc
commit 383c166e79
1 file changed
+16
+16
View File
@@ -7,10 +7,12 @@ import {
readPrompts,
readPromptMeta,
buildPromptWithSession,
parseProjectsConf,
} from "@/lib/agent-config";
import { injectIntoTab, getZellijTabs } from "@/lib/zellij";
import { cancelActiveBeaconSessions } from "@/app/api/beacon/route";
import { createOrchestrationEvent } from "@/db/queries/orchestration-events";
import { insertPromptHistory } from "@/db/queries/prompt-history";
import { upsertProjectState } from "@/db/queries/project-states";
import { ORCHESTRATION_TASK_INTENT_IDS, type OrchestrationTaskIntentId } from "@/lib/orchestration";
import { getCurrentUserId } from "@/lib/session";
@@ -70,12 +72,26 @@ export async function POST(req: NextRequest) {
? (promptKey as OrchestrationTaskIntentId)
: customPrompt ? "custom" : undefined;
const projectPath = parseProjectsConf().find(
(p) => p.tab.toLowerCase() === canonical.toLowerCase(),
)?.dir ?? canonical;
try {
injectIntoTab(effectiveTab, prompt);
cancelActiveBeaconSessions(effectiveTab);
const nowS = Math.floor(Date.now() / 1000);
// Record injection in prompt history so the activity log and
// recent-custom-prompts autocomplete have real data.
insertPromptHistory(userId, {
projectKey: canonical,
projectPath,
adapter: "claude",
intent: eventIntent ?? "custom",
customPrompt: customPrompt ?? null,
}).catch(() => {});
// Track which prompt is currently running (stop.sh clears this using the live tab name)
fs.writeFileSync(stateFile.prompt(effectiveTab), JSON.stringify({
key: promptKey ?? "custom",