@mycompbox/compbox-cli 1.21.12 → 1.21.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.tsbuildinfo +1 -1
- package/commands/run.d.ts.map +1 -1
- package/commands/run.js +38 -8
- package/commands/run.js.map +1 -1
- package/index.js +381 -37
- package/package.json +1 -1
- package/utils/agent-invoker.d.ts +116 -6
- package/utils/agent-invoker.d.ts.map +1 -1
- package/utils/agent-invoker.js +332 -22
- package/utils/agent-invoker.js.map +1 -1
package/utils/agent-invoker.js
CHANGED
|
@@ -20,7 +20,8 @@ import Anthropic from "@anthropic-ai/sdk";
|
|
|
20
20
|
import { execFile, spawn, spawnSync } from "node:child_process";
|
|
21
21
|
import { randomUUID } from "node:crypto";
|
|
22
22
|
import { mkdirSync } from "node:fs";
|
|
23
|
-
import {
|
|
23
|
+
import { mkdir, mkdtemp, realpath, rm, writeFile } from "node:fs/promises";
|
|
24
|
+
import { homedir, tmpdir } from "node:os";
|
|
24
25
|
import { join } from "node:path";
|
|
25
26
|
import { resolveRouting, extractCompletionJson, looksLikeCompletionAttempt, meetsComplianceTarget, buildAuditFeedback, COMPLETION_REPAIR_INSTRUCTION, renderConversationPrompt, runConversationStep, savedContextFromRecord, formatNeedsInputText, parseNeedsInputMarker, stripRunnerOnlyFields, } from "@mycompbox/shared";
|
|
26
27
|
// Completion parsing lives in @mycompbox/shared so CompBox's server-side
|
|
@@ -176,17 +177,197 @@ export function buildApiUserContent(text, imageBlocks) {
|
|
|
176
177
|
return [...imageBlocks, { type: "text", text }];
|
|
177
178
|
}
|
|
178
179
|
/**
|
|
179
|
-
* The `content` to push for a USER turn in API mode:
|
|
180
|
-
* blocks
|
|
181
|
-
*
|
|
182
|
-
*
|
|
180
|
+
* The `content` to push for a USER turn in API mode (ENG-374): images become
|
|
181
|
+
* image blocks, PDFs document blocks, and text documents marker-wrapped text
|
|
182
|
+
* blocks, all ahead of the person's text. A turn with no attachments returns
|
|
183
|
+
* its plain text unchanged (no fetch). An attachment that can't be loaded is
|
|
184
|
+
* skipped with a warning and a note in the text — never a failed turn.
|
|
185
|
+
* `fetchImpl` is injectable for tests.
|
|
183
186
|
*/
|
|
184
187
|
export async function apiUserTurnContent(turn, warn = defaultWarn, fetchImpl = fetch) {
|
|
185
|
-
const
|
|
186
|
-
if (
|
|
188
|
+
const all = turn.attachments ?? [];
|
|
189
|
+
if (all.length === 0)
|
|
187
190
|
return turn.content;
|
|
188
|
-
const
|
|
189
|
-
|
|
191
|
+
const { fetched } = await fetchAttachments(selectAttachments(all, warn), warn, fetchImpl);
|
|
192
|
+
const text = appendMissingAttachmentNote(turn.content, all.length - fetched.length);
|
|
193
|
+
if (fetched.length === 0)
|
|
194
|
+
return text;
|
|
195
|
+
return [
|
|
196
|
+
...fetched.map((f, i) => attachmentBlock(f, i + 1)),
|
|
197
|
+
{ type: "text", text },
|
|
198
|
+
];
|
|
199
|
+
}
|
|
200
|
+
// ---------------------------------------------------------------------
|
|
201
|
+
// ENG-374: documents (PDF + text) alongside images, for both runtimes.
|
|
202
|
+
// API mode sends them inline as content blocks; subscription mode writes them
|
|
203
|
+
// to a temp folder (materializeAttachments) and lets `claude -p` Read them.
|
|
204
|
+
// ---------------------------------------------------------------------
|
|
205
|
+
const PDF_MEDIA_TYPE = "application/pdf";
|
|
206
|
+
const TEXT_DOCUMENT_MEDIA_TYPES = [
|
|
207
|
+
"text/plain",
|
|
208
|
+
"text/csv",
|
|
209
|
+
"text/markdown",
|
|
210
|
+
"application/json",
|
|
211
|
+
];
|
|
212
|
+
/** Max attachments (any kind) fed to the model per turn. */
|
|
213
|
+
const MAX_ATTACHMENTS_PER_TURN = 8;
|
|
214
|
+
/** Max cumulative attachment bytes per turn (declared and fetched). */
|
|
215
|
+
const MAX_ATTACHMENT_BYTES_PER_TURN = 32 * 1024 * 1024; // 32 MB
|
|
216
|
+
function baseMime(mime) {
|
|
217
|
+
return (mime.split(";")[0] ?? "").trim().toLowerCase();
|
|
218
|
+
}
|
|
219
|
+
/** What kind of attachment a MIME type is, or null when the model can't use it. Pure. */
|
|
220
|
+
export function attachmentKind(mime) {
|
|
221
|
+
if (isSupportedImageMediaType(mime))
|
|
222
|
+
return "image";
|
|
223
|
+
const base = baseMime(mime);
|
|
224
|
+
if (base === PDF_MEDIA_TYPE)
|
|
225
|
+
return "pdf";
|
|
226
|
+
if (TEXT_DOCUMENT_MEDIA_TYPES.includes(base))
|
|
227
|
+
return "text";
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* The attachments worth fetching for a turn: usable kinds only, capped by
|
|
232
|
+
* count and cumulative declared bytes. Anything dropped is warned about.
|
|
233
|
+
*/
|
|
234
|
+
export function selectAttachments(attachments, warn = defaultWarn) {
|
|
235
|
+
if (!attachments || attachments.length === 0)
|
|
236
|
+
return [];
|
|
237
|
+
const selected = [];
|
|
238
|
+
let declaredBytes = 0;
|
|
239
|
+
for (const att of attachments) {
|
|
240
|
+
if (attachmentKind(att.mimeType) === null) {
|
|
241
|
+
warn(`Skipping attachment ${att.id}: unsupported type ${att.mimeType}.`);
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
if (selected.length >= MAX_ATTACHMENTS_PER_TURN) {
|
|
245
|
+
warn(`Skipping attachment ${att.id}: more than ${String(MAX_ATTACHMENTS_PER_TURN)} on one message.`);
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
const size = typeof att.sizeBytes === "number" && att.sizeBytes > 0 ? att.sizeBytes : 0;
|
|
249
|
+
if (declaredBytes + size > MAX_ATTACHMENT_BYTES_PER_TURN) {
|
|
250
|
+
warn(`Skipping attachment ${att.id}: exceeds the per-message size budget.`);
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
declaredBytes += size;
|
|
254
|
+
selected.push(att);
|
|
255
|
+
}
|
|
256
|
+
return selected;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Download already-selected attachments. A broken, unreachable, empty or
|
|
260
|
+
* over-budget one is skipped with a warning and reported in `failed` — never
|
|
261
|
+
* thrown.
|
|
262
|
+
*/
|
|
263
|
+
export async function fetchAttachments(attachments, warn = defaultWarn, fetchImpl = fetch) {
|
|
264
|
+
const fetched = [];
|
|
265
|
+
const failed = [];
|
|
266
|
+
let totalBytes = 0;
|
|
267
|
+
for (const att of attachments) {
|
|
268
|
+
const kind = attachmentKind(att.mimeType);
|
|
269
|
+
if (!kind) {
|
|
270
|
+
failed.push(att);
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
try {
|
|
274
|
+
const res = await fetchImpl(att.signedUrl);
|
|
275
|
+
if (!res.ok)
|
|
276
|
+
throw new Error(`fetch failed (HTTP ${String(res.status)})`);
|
|
277
|
+
const bytes = Buffer.from(await res.arrayBuffer());
|
|
278
|
+
if (bytes.byteLength === 0)
|
|
279
|
+
throw new Error("empty response body");
|
|
280
|
+
if (totalBytes + bytes.byteLength > MAX_ATTACHMENT_BYTES_PER_TURN) {
|
|
281
|
+
throw new Error("exceeds the per-message size budget");
|
|
282
|
+
}
|
|
283
|
+
totalBytes += bytes.byteLength;
|
|
284
|
+
fetched.push({ attachment: att, kind, bytes });
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
const message = error instanceof Error ? error.message : "unknown error";
|
|
288
|
+
warn(`Skipping attachment ${att.id}: ${message}.`);
|
|
289
|
+
failed.push(att);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return { fetched, failed };
|
|
293
|
+
}
|
|
294
|
+
/** The API content block for one fetched attachment (`n` numbers it for the text markers). Pure. */
|
|
295
|
+
export function attachmentBlock(f, n) {
|
|
296
|
+
if (f.kind === "image") {
|
|
297
|
+
const mediaType = normalizeImageMediaType(f.attachment.mimeType) ?? "image/png";
|
|
298
|
+
return {
|
|
299
|
+
type: "image",
|
|
300
|
+
source: { type: "base64", media_type: mediaType, data: f.bytes.toString("base64") },
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
if (f.kind === "pdf") {
|
|
304
|
+
return {
|
|
305
|
+
type: "document",
|
|
306
|
+
source: { type: "base64", media_type: PDF_MEDIA_TYPE, data: f.bytes.toString("base64") },
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
const label = `attachment ${String(n)} (${baseMime(f.attachment.mimeType)})`;
|
|
310
|
+
return {
|
|
311
|
+
type: "text",
|
|
312
|
+
text: `<<<BEGIN ${label}>>>\n${f.bytes.toString("utf8")}\n<<<END ${label}>>>`,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
/** Adds a note that `count` attachments couldn't be loaded; unchanged when 0. Pure. */
|
|
316
|
+
export function appendMissingAttachmentNote(text, count) {
|
|
317
|
+
if (count <= 0)
|
|
318
|
+
return text;
|
|
319
|
+
const noun = count === 1 ? "attachment" : "attachments";
|
|
320
|
+
const note = `[${String(count)} ${noun} could not be loaded and ${count === 1 ? "is" : "are"} not shown]`;
|
|
321
|
+
return text.trim().length > 0 ? `${text}\n\n${note}` : note;
|
|
322
|
+
}
|
|
323
|
+
const EXTENSION_BY_MIME = {
|
|
324
|
+
"image/png": "png",
|
|
325
|
+
"image/jpeg": "jpg",
|
|
326
|
+
"image/gif": "gif",
|
|
327
|
+
"image/webp": "webp",
|
|
328
|
+
"application/pdf": "pdf",
|
|
329
|
+
"text/plain": "txt",
|
|
330
|
+
"text/csv": "csv",
|
|
331
|
+
"text/markdown": "md",
|
|
332
|
+
"application/json": "json",
|
|
333
|
+
};
|
|
334
|
+
/**
|
|
335
|
+
* Download a turn's attachments into `dir` (created if missing) under
|
|
336
|
+
* generated names (`attachment-1.png`, ...) — never the uploader's filename.
|
|
337
|
+
* Failures are warned about and counted in `failed`, never thrown. The caller
|
|
338
|
+
* owns `dir` and removes it.
|
|
339
|
+
*/
|
|
340
|
+
export async function materializeAttachments(dir, attachments, fetchImpl = fetch, warn = defaultWarn) {
|
|
341
|
+
const all = attachments ?? [];
|
|
342
|
+
if (all.length === 0)
|
|
343
|
+
return { files: [], failed: 0 };
|
|
344
|
+
const { fetched } = await fetchAttachments(selectAttachments(all, warn), warn, fetchImpl);
|
|
345
|
+
const files = [];
|
|
346
|
+
if (fetched.length > 0)
|
|
347
|
+
await mkdir(dir, { recursive: true });
|
|
348
|
+
for (const f of fetched) {
|
|
349
|
+
const mimeType = baseMime(f.attachment.mimeType);
|
|
350
|
+
const path = join(dir, `attachment-${String(files.length + 1)}.${EXTENSION_BY_MIME[mimeType] ?? "bin"}`);
|
|
351
|
+
try {
|
|
352
|
+
await writeFile(path, f.bytes);
|
|
353
|
+
files.push({ path, mimeType });
|
|
354
|
+
}
|
|
355
|
+
catch (error) {
|
|
356
|
+
const message = error instanceof Error ? error.message : "unknown error";
|
|
357
|
+
warn(`Skipping attachment ${f.attachment.id}: could not save it (${message}).`);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return { files, failed: all.length - files.length };
|
|
361
|
+
}
|
|
362
|
+
/** Subscription-mode turn text: the person's text plus the attached files' paths. Pure. */
|
|
363
|
+
export function appendAttachmentPaths(text, files, failed) {
|
|
364
|
+
let out = text;
|
|
365
|
+
if (files.length > 0) {
|
|
366
|
+
const list = files.map((f) => `- ${f.path} (${f.mimeType})`).join("\n");
|
|
367
|
+
const note = `[Attached files — open them with the Read tool:\n${list}]`;
|
|
368
|
+
out = out.trim().length > 0 ? `${out}\n\n${note}` : note;
|
|
369
|
+
}
|
|
370
|
+
return appendMissingAttachmentNote(out, failed);
|
|
190
371
|
}
|
|
191
372
|
/**
|
|
192
373
|
* Subscription-mode (A4) degradation: append an explicit `[N image(s)
|
|
@@ -319,6 +500,23 @@ function claudeCliSessionCwd() {
|
|
|
319
500
|
* `--resume`, not by resending a transcript — cheaper and matches how a
|
|
320
501
|
* human would use the CLI.
|
|
321
502
|
*/
|
|
503
|
+
/**
|
|
504
|
+
* ENG-374: the tool flags for an interview turn. No tools at all, unless an
|
|
505
|
+
* attachments folder is given — then only Read, pre-approved for that folder
|
|
506
|
+
* alone (`//` marks an absolute path in a permission rule). Pure.
|
|
507
|
+
*/
|
|
508
|
+
export function claudeToolArgs(attachmentsDir) {
|
|
509
|
+
if (!attachmentsDir)
|
|
510
|
+
return ["--tools", ""];
|
|
511
|
+
return [
|
|
512
|
+
"--tools",
|
|
513
|
+
"Read",
|
|
514
|
+
"--add-dir",
|
|
515
|
+
attachmentsDir,
|
|
516
|
+
"--allowedTools",
|
|
517
|
+
`Read(/${attachmentsDir}/**)`,
|
|
518
|
+
];
|
|
519
|
+
}
|
|
322
520
|
function runClaudeCliTurn(prompt, opts) {
|
|
323
521
|
return new Promise((resolve, reject) => {
|
|
324
522
|
const model = opts.model === undefined ? ANTHROPIC_MODEL : opts.model;
|
|
@@ -328,8 +526,7 @@ function runClaudeCliTurn(prompt, opts) {
|
|
|
328
526
|
...(model ? ["--model", model] : []),
|
|
329
527
|
"--output-format",
|
|
330
528
|
"json",
|
|
331
|
-
|
|
332
|
-
"",
|
|
529
|
+
...claudeToolArgs(opts.attachmentsDir),
|
|
333
530
|
"--permission-mode",
|
|
334
531
|
"dontAsk",
|
|
335
532
|
"--safe-mode",
|
|
@@ -479,15 +676,50 @@ async function takeConversationStep(job, ctx) {
|
|
|
479
676
|
const saved = requestId
|
|
480
677
|
? await loadSavedRequest(ctx.apiBaseUrl, ctx.userApiToken, requestId, discussed)
|
|
481
678
|
: null;
|
|
482
|
-
const turns = job.turns.map((t) => ({
|
|
483
|
-
role: t.role,
|
|
484
|
-
content: t.role === "user"
|
|
485
|
-
? appendAttachmentNote(t.content, imageAttachmentCount(t.attachments))
|
|
486
|
-
: t.content,
|
|
487
|
-
}));
|
|
488
679
|
const anthropic = ctx.anthropicApiKey
|
|
489
680
|
? new Anthropic(anthropicClientOptions(ctx.anthropicApiKey, routing))
|
|
490
681
|
: null;
|
|
682
|
+
// ENG-374: subscription mode reads attachments from a temp folder that only
|
|
683
|
+
// lives for this step; it's created lazily and always removed below.
|
|
684
|
+
const hasAttachments = job.turns.some((t) => t.role === "user" && (t.attachments?.length ?? 0) > 0);
|
|
685
|
+
const attachmentsDir = !anthropic && hasAttachments
|
|
686
|
+
? await realpath(await mkdtemp(join(tmpdir(), "compbox-attachments-")))
|
|
687
|
+
: undefined;
|
|
688
|
+
try {
|
|
689
|
+
return await converseWithAttachments(job, ctx, {
|
|
690
|
+
routing,
|
|
691
|
+
saved,
|
|
692
|
+
anthropic,
|
|
693
|
+
attachmentsDir,
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
finally {
|
|
697
|
+
if (attachmentsDir)
|
|
698
|
+
await rm(attachmentsDir, { recursive: true, force: true });
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
async function converseWithAttachments(job, ctx, step) {
|
|
702
|
+
const { routing, saved, anthropic, attachmentsDir } = step;
|
|
703
|
+
let usedFiles = false;
|
|
704
|
+
const turns = [];
|
|
705
|
+
for (const [index, t] of job.turns.entries()) {
|
|
706
|
+
if (t.role !== "user") {
|
|
707
|
+
turns.push({ role: t.role, content: t.content });
|
|
708
|
+
}
|
|
709
|
+
else if (anthropic) {
|
|
710
|
+
turns.push({ role: t.role, content: await apiUserTurnContent(t) });
|
|
711
|
+
}
|
|
712
|
+
else if (attachmentsDir && (t.attachments?.length ?? 0) > 0) {
|
|
713
|
+
const { files, failed } = await materializeAttachments(join(attachmentsDir, `turn-${String(index + 1)}`), t.attachments);
|
|
714
|
+
if (files.length > 0)
|
|
715
|
+
usedFiles = true;
|
|
716
|
+
turns.push({ role: t.role, content: appendAttachmentPaths(t.content, files, failed) });
|
|
717
|
+
}
|
|
718
|
+
else {
|
|
719
|
+
turns.push({ role: t.role, content: t.content });
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
const readDir = usedFiles ? attachmentsDir : undefined;
|
|
491
723
|
let cliModel = ANTHROPIC_MODEL;
|
|
492
724
|
const outcome = await runConversationStep({ turns, saved }, {
|
|
493
725
|
reply: async (system, messages) => {
|
|
@@ -508,6 +740,7 @@ async function takeConversationStep(job, ctx) {
|
|
|
508
740
|
resumeSessionId: undefined,
|
|
509
741
|
routing,
|
|
510
742
|
model: cliModel,
|
|
743
|
+
attachmentsDir: readDir,
|
|
511
744
|
})).text;
|
|
512
745
|
}
|
|
513
746
|
catch (error) {
|
|
@@ -519,6 +752,7 @@ async function takeConversationStep(job, ctx) {
|
|
|
519
752
|
resumeSessionId: undefined,
|
|
520
753
|
routing,
|
|
521
754
|
model: null,
|
|
755
|
+
attachmentsDir: readDir,
|
|
522
756
|
})).text;
|
|
523
757
|
}
|
|
524
758
|
},
|
|
@@ -1483,7 +1717,10 @@ export function buildOrchestratorArgs(epicId, sessionId, ownerReply, baseBranch,
|
|
|
1483
1717
|
return [
|
|
1484
1718
|
"-p",
|
|
1485
1719
|
`@orchestrator execute epic ${epicId} --non-interactive` +
|
|
1486
|
-
(ownerReply
|
|
1720
|
+
(ownerReply || extra?.replyAttachmentsNote
|
|
1721
|
+
? `\n\n${freshRunReplyContext(ownerReply ?? "", extra?.replyAttachmentsNote)}`
|
|
1722
|
+
: "") +
|
|
1723
|
+
(extra?.followUp ? `\n\n${followUpContext(extra.followUp)}` : "") +
|
|
1487
1724
|
(extra?.ownerNote ? `\n\n${ownerNoteContext(extra.ownerNote)}` : "") +
|
|
1488
1725
|
(extra?.deferred && extra.deferred.length > 0 ? `\n\n${deferredFeaturesText(extra.deferred)}` : ""),
|
|
1489
1726
|
// A known session id lets the runner resume this same conversation when
|
|
@@ -1535,6 +1772,19 @@ export function deferredFeaturesText(deferred) {
|
|
|
1535
1772
|
export function ownerNoteContext(note) {
|
|
1536
1773
|
return ["The owner restarted this build with this note:", quoteOwnerReply(note)].join("\n\n");
|
|
1537
1774
|
}
|
|
1775
|
+
/**
|
|
1776
|
+
* ENG-366: the owner's follow-up to a finished build, appended after the
|
|
1777
|
+
* @orchestrator command. Quoted as owner text (a request, not instructions
|
|
1778
|
+
* that override the agent's rules).
|
|
1779
|
+
*/
|
|
1780
|
+
export function followUpContext(message) {
|
|
1781
|
+
return [
|
|
1782
|
+
"This epic's build already finished. Its owner sent this follow-up:",
|
|
1783
|
+
quoteOwnerReply(message, "a follow-up to the finished build"),
|
|
1784
|
+
"Act on it against the epic's blueprint: change features, tasks or code as needed, and report what you changed. " +
|
|
1785
|
+
"If it is unclear, ask with a single COMPBOX_NEEDS_INPUT marker.",
|
|
1786
|
+
].join("\n\n");
|
|
1787
|
+
}
|
|
1538
1788
|
/** Claude CLI args that resume the orchestrator's session with {@link orchestratorContinuePrompt}. */
|
|
1539
1789
|
export function buildOrchestratorContinueArgs(sessionId, prompt, baseBranch, fastMode) {
|
|
1540
1790
|
return [
|
|
@@ -1552,6 +1802,28 @@ export function buildOrchestratorContinueArgs(sessionId, prompt, baseBranch, fas
|
|
|
1552
1802
|
...fastModeArgs(fastMode),
|
|
1553
1803
|
];
|
|
1554
1804
|
}
|
|
1805
|
+
/** The well-formed entries of a claimed job's `resume.attachments` (ENG-375). Pure. */
|
|
1806
|
+
function parseReplyAttachments(raw) {
|
|
1807
|
+
if (!Array.isArray(raw))
|
|
1808
|
+
return [];
|
|
1809
|
+
const out = [];
|
|
1810
|
+
for (const item of raw) {
|
|
1811
|
+
if (typeof item !== "object" || item === null)
|
|
1812
|
+
continue;
|
|
1813
|
+
const a = item;
|
|
1814
|
+
if (typeof a.id !== "string" || typeof a.mimeType !== "string" || typeof a.signedUrl !== "string")
|
|
1815
|
+
continue;
|
|
1816
|
+
if (a.signedUrl.trim() === "")
|
|
1817
|
+
continue;
|
|
1818
|
+
out.push({
|
|
1819
|
+
id: a.id,
|
|
1820
|
+
mimeType: a.mimeType,
|
|
1821
|
+
sizeBytes: typeof a.sizeBytes === "number" && Number.isFinite(a.sizeBytes) ? a.sizeBytes : 0,
|
|
1822
|
+
signedUrl: a.signedUrl,
|
|
1823
|
+
});
|
|
1824
|
+
}
|
|
1825
|
+
return out;
|
|
1826
|
+
}
|
|
1555
1827
|
/** Most of the owner's reply that is handed to the agent. */
|
|
1556
1828
|
export const MAX_REPLY_CHARS = 8_000;
|
|
1557
1829
|
const REPLY_OPEN = "<<<OWNER_REPLY";
|
|
@@ -1566,7 +1838,11 @@ export function parseReplyResume(job) {
|
|
|
1566
1838
|
if (typeof raw !== "object" || raw === null)
|
|
1567
1839
|
return null;
|
|
1568
1840
|
const r = raw;
|
|
1569
|
-
if (typeof r.reply !== "string"
|
|
1841
|
+
if (typeof r.reply !== "string")
|
|
1842
|
+
return null;
|
|
1843
|
+
const attachments = parseReplyAttachments(r.attachments);
|
|
1844
|
+
// A reply may be attachments only (ENG-375); with neither there's nothing to resume with.
|
|
1845
|
+
if (r.reply.trim() === "" && attachments.length === 0)
|
|
1570
1846
|
return null;
|
|
1571
1847
|
const str = (v) => (typeof v === "string" && v.trim() !== "" ? v : null);
|
|
1572
1848
|
const result = typeof job.result === "object" && job.result !== null ? job.result : {};
|
|
@@ -1575,8 +1851,20 @@ export function parseReplyResume(job) {
|
|
|
1575
1851
|
runDir: str(r.runDir),
|
|
1576
1852
|
reply: r.reply,
|
|
1577
1853
|
branch: str(result.branch),
|
|
1854
|
+
attachments,
|
|
1578
1855
|
};
|
|
1579
1856
|
}
|
|
1857
|
+
/**
|
|
1858
|
+
* The runner's note listing the reply's attachments as saved files (ENG-375),
|
|
1859
|
+
* or "" when there are none. Kept OUTSIDE the quoted reply: the paths come
|
|
1860
|
+
* from the runner, not the owner. Pure.
|
|
1861
|
+
*/
|
|
1862
|
+
export function replyAttachmentsNote(files, failed) {
|
|
1863
|
+
if (files.length === 0 && failed <= 0)
|
|
1864
|
+
return "";
|
|
1865
|
+
const head = "The owner attached files to the reply.";
|
|
1866
|
+
return appendAttachmentPaths(head, files, failed);
|
|
1867
|
+
}
|
|
1580
1868
|
/** The reply as a clearly delimited, untrusted quote the agent can't mistake for instructions. */
|
|
1581
1869
|
export function quoteOwnerReply(reply, kind = "an answer to your question") {
|
|
1582
1870
|
// Strip the markers until none is left: one pass can re-form a marker
|
|
@@ -1614,10 +1902,11 @@ export function ownerNotePrompt(epicId, notes, deferred = []) {
|
|
|
1614
1902
|
].join("\n\n");
|
|
1615
1903
|
}
|
|
1616
1904
|
/** The prompt that resumes a paused orchestrator session with the owner's reply. */
|
|
1617
|
-
export function replyResumePrompt(epicId, reply) {
|
|
1905
|
+
export function replyResumePrompt(epicId, reply, attachmentsNote = "") {
|
|
1618
1906
|
return [
|
|
1619
1907
|
`The owner answered your question:`,
|
|
1620
1908
|
quoteOwnerReply(reply),
|
|
1909
|
+
...(attachmentsNote ? [attachmentsNote] : []),
|
|
1621
1910
|
`Continue executing epic ${epicId} in non-interactive mode from where you stopped.`,
|
|
1622
1911
|
"If the answer is not enough, ask again with a single COMPBOX_NEEDS_INPUT marker.",
|
|
1623
1912
|
].join("\n\n");
|
|
@@ -1634,10 +1923,11 @@ export function buildReplyResumeArgs(sessionId, prompt, baseBranch, fastMode) {
|
|
|
1634
1923
|
* orchestrator run gets the owner's reply. Appended after the @orchestrator
|
|
1635
1924
|
* command so the agent routing (which keys on the prompt's start) still works.
|
|
1636
1925
|
*/
|
|
1637
|
-
export function freshRunReplyContext(reply) {
|
|
1926
|
+
export function freshRunReplyContext(reply, attachmentsNote = "") {
|
|
1638
1927
|
return [
|
|
1639
1928
|
"This build stopped earlier to ask its owner a question. The owner answered:",
|
|
1640
1929
|
quoteOwnerReply(reply),
|
|
1930
|
+
...(attachmentsNote ? [attachmentsNote] : []),
|
|
1641
1931
|
"Use the answer where the earlier run stopped. If it is not enough, ask again with a single COMPBOX_NEEDS_INPUT marker.",
|
|
1642
1932
|
].join("\n\n");
|
|
1643
1933
|
}
|
|
@@ -1984,6 +2274,22 @@ export async function invokeStartExecutionOrchestrate(ctx, deps = {}) {
|
|
|
1984
2274
|
const runDir = workspace?.dir ?? projectDir;
|
|
1985
2275
|
if (workspace)
|
|
1986
2276
|
deps.activeRunDirs?.add(workspace.dir);
|
|
2277
|
+
// ENG-375: the reply's attachments are saved to a temp folder outside the
|
|
2278
|
+
// run copy (so they're never committed) and listed in the prompt for the
|
|
2279
|
+
// agent to Read. Removed when the run ends.
|
|
2280
|
+
let replyAttachmentsDir;
|
|
2281
|
+
let attachmentsNote = "";
|
|
2282
|
+
const replyAttachments = resume?.attachments ?? [];
|
|
2283
|
+
if (replyAttachments.length > 0) {
|
|
2284
|
+
try {
|
|
2285
|
+
replyAttachmentsDir = await realpath(await mkdtemp(join(tmpdir(), "compbox-reply-attachments-")));
|
|
2286
|
+
const { files, failed } = await materializeAttachments(replyAttachmentsDir, replyAttachments, deps.fetchImpl ?? fetch);
|
|
2287
|
+
attachmentsNote = replyAttachmentsNote(files, failed);
|
|
2288
|
+
}
|
|
2289
|
+
catch {
|
|
2290
|
+
attachmentsNote = replyAttachmentsNote([], replyAttachments.length);
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
1987
2293
|
const routing = await resolveRoutingImpl();
|
|
1988
2294
|
const command = resolveClaudeBinary() ?? "claude";
|
|
1989
2295
|
// A fix run is one focused change, so only a build gets a resumable session.
|
|
@@ -1992,10 +2298,12 @@ export async function invokeStartExecutionOrchestrate(ctx, deps = {}) {
|
|
|
1992
2298
|
const runArgs = ctx.fix
|
|
1993
2299
|
? buildFixArgs(ctx.fix, workspace?.baseBranch, ctx.fastMode)
|
|
1994
2300
|
: resumeSessionId && resume
|
|
1995
|
-
? buildReplyResumeArgs(resumeSessionId, replyResumePrompt(ctx.epicId, resume.reply), workspace?.baseBranch, ctx.fastMode)
|
|
2301
|
+
? buildReplyResumeArgs(resumeSessionId, replyResumePrompt(ctx.epicId, resume.reply, attachmentsNote), workspace?.baseBranch, ctx.fastMode)
|
|
1996
2302
|
: buildOrchestratorArgs(ctx.epicId, sessionId, resume?.reply, workspace?.baseBranch, ctx.fastMode, {
|
|
1997
2303
|
...(ctx.ownerNote && { ownerNote: ctx.ownerNote }),
|
|
1998
2304
|
...(ctx.deferredFeatures && { deferred: ctx.deferredFeatures }),
|
|
2305
|
+
...(ctx.followUp && { followUp: ctx.followUp }),
|
|
2306
|
+
...(attachmentsNote && { replyAttachmentsNote: attachmentsNote }),
|
|
1999
2307
|
});
|
|
2000
2308
|
const args = ctx.keyRun ? keyRunArgs(runArgs) : runArgs;
|
|
2001
2309
|
// pxpipe (ENG-136): inject ANTHROPIC_BASE_URL when routed. COMPBOX_NONINTERACTIVE
|
|
@@ -2476,6 +2784,8 @@ export async function invokeStartExecutionOrchestrate(ctx, deps = {}) {
|
|
|
2476
2784
|
}
|
|
2477
2785
|
if (workspace)
|
|
2478
2786
|
deps.activeRunDirs?.delete(workspace.dir);
|
|
2787
|
+
if (replyAttachmentsDir)
|
|
2788
|
+
await rm(replyAttachmentsDir, { recursive: true, force: true }).catch(() => undefined);
|
|
2479
2789
|
// ENG-352: where the run's time went, for the run page's breakdown.
|
|
2480
2790
|
const timings = buildJobTimings({
|
|
2481
2791
|
install: workspace?.install,
|