feat: Persist agent prompt in DB so getAgentPrompt survives log cleanup

The `getAgentPrompt` tRPC procedure previously read exclusively from
`.cw/agent-logs/<name>/PROMPT.md`. Once the cleanup-manager removes
that directory, the prompt is gone forever.

Adds a `prompt` text column to the `agents` table and writes the fully
assembled prompt (including workspace layout, inter-agent comms, and
preview sections) to the DB in the same `repository.update()` call
that saves pid/outputFilePath after spawn.

`getAgentPrompt` now reads from DB first (`agent.prompt`) and falls
back to the filesystem only for agents spawned before this change.

Addresses review comment [MMcmVlEK16bBfkJuXvG6h].

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lukas May
2026-03-06 13:13:01 +01:00
parent 269a2d2616
commit b2f4004191
14 changed files with 1239 additions and 11 deletions

View File

@@ -45,6 +45,7 @@ export interface UpdateAgentData {
accountId?: string | null;
pid?: number | null;
exitCode?: number | null;
prompt?: string | null;
outputFilePath?: string | null;
result?: string | null;
pendingQuestions?: string | null;

View File

@@ -265,6 +265,7 @@ export const agents = sqliteTable('agents', {
.default('execute'),
pid: integer('pid'),
exitCode: integer('exit_code'), // Process exit code for debugging crashes
prompt: text('prompt'), // Full assembled prompt passed to the agent process (persisted for durability after log cleanup)
outputFilePath: text('output_file_path'),
result: text('result'),
pendingQuestions: text('pending_questions'),