feat(home): /api/dispatch surfaces the queue context to the agent

home/render.ts gained an optional queue field (mirroring
OrchestrationTaskRequest.queue from e6bd03b); home/server.ts's
/api/dispatch now sources the queue from caller-supplied body OR
falls back to /tmp/agent-queue-<tab> (the file mirror cloud's
/api/beacon/queue/[tab] writes for cross-stack visibility). Either
source threads through buildPromptForDispatch → renderPromptForDispatch
→ renderQueueBlock, so a home/-dispatched prompt now carries the
same 'User's prompt queue for this project' block the cloud path
already had. Closes the asymmetry: home/ and cloud both surface
queue context to the agent now.

Queue items added after the drained head still render — the agent
sees both what they're currently working on (the dispatch prompt
itself) and what's queued behind it.

tsc clean, npm run test:home 85/85.
This commit is contained in:
g-but committed 2026-05-20 11:39:54 +02:00
1 parent 07549afd2d
commit 1cacfd2417
2 files changed
+32 -2

No files matched your search

+8
View File
@@ -27,6 +27,13 @@ export type RenderInput = {
adapter?: AdapterId;
/** Free-form prompt body when intent === 'custom' (queue items, ad-hoc text). */
customInstructions?: string;
/** Optional snapshot of the user's prompt queue for this project. Threaded
* through to renderTaskForAdapter so the dispatched prompt body surfaces
* "User's prompt queue for this project" — symmetric with the cloud
* /api/orchestration/run path (RunOrchestrationBody.queue). Without this,
* home/'s autonomous dispatches would render the bare next_best scan
* instruction with no queue context. */
queue?: string[];
};
export function renderPromptForDispatch(input: RenderInput): string {
@@ -36,6 +43,7 @@ export function renderPromptForDispatch(input: RenderInput): string {
adapter: input.adapter ?? "claude",
intent: input.intent,
customInstructions: input.customInstructions,
queue: input.queue,
});
}
+24 -2
View File
@@ -521,7 +521,24 @@ const server = http.createServer((req, res) => {
const projectPath =
(typeof parsed.projectPath === "string" && parsed.projectPath) ||
resolveProjectPath(projectName);
const prompt = buildPromptForDispatch(decision, projectState, projectPath);
// Pick up the user's prompt queue if present: caller-supplied (request
// body) wins, else read /tmp/agent-queue-<tab> — the file mirror the
// cloud /api/beacon/queue/[tab] PUT writes (best-effort) for bash-hook
// and home/ compat. Either source flows through buildPromptForDispatch
// → renderTaskForAdapter → renderQueueBlock so the dispatched prompt
// body shows the agent what's pending. Empty/missing queue → no block.
const queue: string[] = (() => {
if (Array.isArray(parsed.queue)) {
return parsed.queue.filter((s: unknown): s is string => typeof s === "string");
}
try {
const file = path.join("/tmp", `agent-queue-${projectName.toLowerCase()}`);
const raw = fs.readFileSync(file, "utf8");
const arr = JSON.parse(raw);
return Array.isArray(arr) ? arr.filter((s: unknown): s is string => typeof s === "string") : [];
} catch { return []; }
})();
const prompt = buildPromptForDispatch(decision, projectState, projectPath, queue);
const intent = decision.action.intent;
// Adapter resolution: caller-supplied wins (lets the UI override per
// dispatch), otherwise fall back to the project's declared adapter
@@ -577,6 +594,7 @@ function buildPromptForDispatch(
decision: Decision,
project: ProjectState,
projectPath?: string,
queue?: string[],
): string {
if (decision.action.kind === "wait") {
// Caller is supposed to short-circuit on wait — never dispatch one.
@@ -590,19 +608,23 @@ function buildPromptForDispatch(
? (intentRaw as OrchestrationTaskIntentId)
: "next_best";
// Queue-drain case: the queue item IS the prompt. Pass it through as
// intent="custom" so renderTaskForAdapter echoes it verbatim.
// intent="custom" so renderTaskForAdapter echoes it verbatim. The
// remaining queue (everything after the drained head) still flows so
// the agent sees what's coming after this run.
if (decision.action.kind === "dispatch" && decision.action.prompt) {
return renderPromptForDispatch({
project: project.project,
projectPath,
intent: "custom",
customInstructions: decision.action.prompt,
queue,
});
}
return renderPromptForDispatch({
project: project.project,
projectPath,
intent,
queue,
});
}