@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/index.js
CHANGED
|
@@ -1831,7 +1831,7 @@ var SessionEventType;
|
|
|
1831
1831
|
})(SessionEventType || (SessionEventType = {}));
|
|
1832
1832
|
|
|
1833
1833
|
// ../shared/dist/types/mailbox.js
|
|
1834
|
-
var START_EXECUTION_KINDS = ["plan", "orchestrate", "refine"];
|
|
1834
|
+
var START_EXECUTION_KINDS = ["plan", "orchestrate", "refine", "follow_up"];
|
|
1835
1835
|
function normalizeGitRemote(raw) {
|
|
1836
1836
|
const input = (raw ?? "").trim();
|
|
1837
1837
|
if (input === "")
|
|
@@ -6284,6 +6284,11 @@ function looksLikeCompletionAttempt(text) {
|
|
|
6284
6284
|
var COMPLETION_REPAIR_INSTRUCTION = 'Your last message looked like a completion but I could NOT parse it as a valid JSON object with all required fields. Re-emit ONLY a single valid JSON object inside a ```json code fence \u2014 no other text \u2014 with every string value properly escaped (escape any internal double-quotes as \\" and any line breaks as \\n), and make sure title, problemStatement, proposedSolution, impactAssessment, and description are all present and non-empty:\n```json\n{"done": true, "title": "...", "problemStatement": "...", "proposedSolution": "...", "impactAssessment": "...", "description": "..."}\n```';
|
|
6285
6285
|
|
|
6286
6286
|
// ../shared/dist/interview-conversation.js
|
|
6287
|
+
function contentText(content) {
|
|
6288
|
+
if (typeof content === "string")
|
|
6289
|
+
return content;
|
|
6290
|
+
return content.flatMap((b) => b.type === "text" && typeof b.text === "string" ? [b.text] : []).join("\n\n");
|
|
6291
|
+
}
|
|
6287
6292
|
function requestLockReason(saved) {
|
|
6288
6293
|
if (!saved)
|
|
6289
6294
|
return null;
|
|
@@ -6337,6 +6342,10 @@ What a good request covers:
|
|
|
6337
6342
|
${definition.map(renderSection).join("\n")}
|
|
6338
6343
|
Optional topics may be skipped when the person has nothing to add. Never invent or pad facts.
|
|
6339
6344
|
|
|
6345
|
+
What you can and can't do:
|
|
6346
|
+
- The ONLY thing you can change is the request's own text (title and topics), by replying with the completion JSON below. You can't move it to another project, approve or reject it, make a blueprint, start a build, or change tasks, parts or anything else in CompBox.
|
|
6347
|
+
- Never say or imply you did any of those things (no "Done", "Moved", "Approved"). If they ask, say plainly that you can't do that from here and tell them where they can: the idea's page for approving and making the blueprint, "Move to project" on the classic page for a personal idea, or an admin.
|
|
6348
|
+
|
|
6340
6349
|
Before saving for the first time: when the needed topics are covered, show a short preview in plain text (the title, then one or two lines per topic) and ask whether to save it or change anything. Only after they agree, or ask you to save, reply with ONLY a fenced JSON block, no other text:
|
|
6341
6350
|
\`\`\`json
|
|
6342
6351
|
{"done": true, ${shape}}
|
|
@@ -6360,7 +6369,7 @@ function toConversationMessages(turns) {
|
|
|
6360
6369
|
return messages;
|
|
6361
6370
|
}
|
|
6362
6371
|
function renderConversationPrompt(messages) {
|
|
6363
|
-
const lines = messages.map((m) => `${m.role === "assistant" ? "You" : "Them"}: ${m.content}`);
|
|
6372
|
+
const lines = messages.map((m) => `${m.role === "assistant" ? "You" : "Them"}: ${contentText(m.content)}`);
|
|
6364
6373
|
return `The conversation so far:
|
|
6365
6374
|
|
|
6366
6375
|
${lines.join("\n\n")}
|
|
@@ -6750,6 +6759,77 @@ function formatNeedsInputText(req) {
|
|
|
6750
6759
|
return out.join("\n");
|
|
6751
6760
|
}
|
|
6752
6761
|
|
|
6762
|
+
// ../shared/dist/run-progress.js
|
|
6763
|
+
var isoTimestamp = external_exports.string().datetime({ offset: true });
|
|
6764
|
+
var runKindSchema = external_exports.enum(["planning", "build"]);
|
|
6765
|
+
var runStageStatusSchema = external_exports.enum(["pending", "active", "completed", "failed", "skipped"]);
|
|
6766
|
+
var runStateSchema = external_exports.enum([
|
|
6767
|
+
"pending",
|
|
6768
|
+
"active",
|
|
6769
|
+
"completed",
|
|
6770
|
+
"failed",
|
|
6771
|
+
"cancelled",
|
|
6772
|
+
"stalled"
|
|
6773
|
+
]);
|
|
6774
|
+
var runProgressStageSchema = external_exports.object({
|
|
6775
|
+
/** Stable machine key for the stage, unique within the run. */
|
|
6776
|
+
key: external_exports.string().min(1),
|
|
6777
|
+
/** Human-readable label shown in the UI. */
|
|
6778
|
+
label: external_exports.string().min(1),
|
|
6779
|
+
/** Current status of the stage. */
|
|
6780
|
+
status: runStageStatusSchema,
|
|
6781
|
+
/** Optional short detail line (for example "3 of 7 tasks"). */
|
|
6782
|
+
detail: external_exports.string().nullable(),
|
|
6783
|
+
/** When the stage started, or null if it has not started yet. */
|
|
6784
|
+
startedAt: isoTimestamp.nullable(),
|
|
6785
|
+
/** When the stage finished, or null if it has not finished yet. */
|
|
6786
|
+
completedAt: isoTimestamp.nullable()
|
|
6787
|
+
});
|
|
6788
|
+
var runEtaSchema = external_exports.object({
|
|
6789
|
+
/** Estimated seconds left, or null when no estimate can be made. */
|
|
6790
|
+
secondsRemaining: external_exports.number().int().nonnegative().nullable(),
|
|
6791
|
+
/** How much to trust the estimate, based mostly on sample size. */
|
|
6792
|
+
confidence: external_exports.enum(["low", "medium", "high"]),
|
|
6793
|
+
/** Number of past runs the estimate is based on. */
|
|
6794
|
+
sampleSize: external_exports.number().int().nonnegative(),
|
|
6795
|
+
/** True when the run has already taken longer than the estimate. */
|
|
6796
|
+
overrun: external_exports.boolean()
|
|
6797
|
+
});
|
|
6798
|
+
var runProgressBaseSchema = external_exports.object({
|
|
6799
|
+
// --- Identity ---
|
|
6800
|
+
/** Which kind of run this is. */
|
|
6801
|
+
runKind: runKindSchema,
|
|
6802
|
+
// --- Stages ---
|
|
6803
|
+
/** Ordered list of the run's stages. */
|
|
6804
|
+
stages: external_exports.array(runProgressStageSchema),
|
|
6805
|
+
/** Key of the stage currently running, or null if none is running. */
|
|
6806
|
+
currentStageKey: external_exports.string().min(1).nullable(),
|
|
6807
|
+
// --- Counts ---
|
|
6808
|
+
/** Units of work finished (stages for planning, tasks for build). */
|
|
6809
|
+
completed: external_exports.number().int().nonnegative(),
|
|
6810
|
+
/** Total units of work in the run. */
|
|
6811
|
+
total: external_exports.number().int().nonnegative(),
|
|
6812
|
+
// --- State ---
|
|
6813
|
+
/** Overall state of the run. */
|
|
6814
|
+
state: runStateSchema,
|
|
6815
|
+
/** Why the run failed or stalled, or null otherwise. */
|
|
6816
|
+
failureReason: external_exports.string().nullable(),
|
|
6817
|
+
// --- Timing ---
|
|
6818
|
+
/** When the run started. */
|
|
6819
|
+
startedAt: isoTimestamp,
|
|
6820
|
+
/** When progress was last reported. */
|
|
6821
|
+
updatedAt: isoTimestamp,
|
|
6822
|
+
/** Estimated time remaining, or null when there is no estimate. */
|
|
6823
|
+
eta: runEtaSchema.nullable()
|
|
6824
|
+
});
|
|
6825
|
+
var runProgressSchema = runProgressBaseSchema.refine((p) => p.completed <= p.total, {
|
|
6826
|
+
message: "completed must not be greater than total",
|
|
6827
|
+
path: ["completed"]
|
|
6828
|
+
}).refine((p) => p.currentStageKey === null || p.stages.some((s) => s.key === p.currentStageKey), {
|
|
6829
|
+
message: "currentStageKey must match one of the stage keys",
|
|
6830
|
+
path: ["currentStageKey"]
|
|
6831
|
+
});
|
|
6832
|
+
|
|
6753
6833
|
// src/utils/config-store.ts
|
|
6754
6834
|
var DEFAULT_BUILD_STALL_MINUTES = 30;
|
|
6755
6835
|
var DEFAULT_BUILD_MAX_HOURS = 12;
|
|
@@ -7228,7 +7308,7 @@ var cached;
|
|
|
7228
7308
|
function resolveCliVersion() {
|
|
7229
7309
|
if (cached !== void 0) return cached;
|
|
7230
7310
|
if (true) {
|
|
7231
|
-
cached = "1.21.
|
|
7311
|
+
cached = "1.21.14";
|
|
7232
7312
|
return cached;
|
|
7233
7313
|
}
|
|
7234
7314
|
const require2 = createRequire(import.meta.url);
|
|
@@ -9109,7 +9189,8 @@ import Anthropic from "@anthropic-ai/sdk";
|
|
|
9109
9189
|
import { execFile as execFile2, spawn as spawn7, spawnSync } from "node:child_process";
|
|
9110
9190
|
import { randomUUID } from "node:crypto";
|
|
9111
9191
|
import { mkdirSync as mkdirSync9 } from "node:fs";
|
|
9112
|
-
import {
|
|
9192
|
+
import { mkdir as mkdir2, mkdtemp, realpath, rm, writeFile as writeFile2 } from "node:fs/promises";
|
|
9193
|
+
import { homedir as homedir7, tmpdir as tmpdir2 } from "node:os";
|
|
9113
9194
|
import { join as join16 } from "node:path";
|
|
9114
9195
|
|
|
9115
9196
|
// src/utils/run-timings.ts
|
|
@@ -11489,6 +11570,9 @@ function claudeSpawnEnv(base, routing) {
|
|
|
11489
11570
|
}
|
|
11490
11571
|
var SUPPORTED_IMAGE_MEDIA_TYPES = ["image/jpeg", "image/png", "image/gif", "image/webp"];
|
|
11491
11572
|
var MAX_IMAGE_BYTES_PER_TURN = 20 * 1024 * 1024;
|
|
11573
|
+
var defaultWarn = (message) => {
|
|
11574
|
+
console.warn(` \u26A0 ${message}`);
|
|
11575
|
+
};
|
|
11492
11576
|
function normalizeImageMediaType(mime) {
|
|
11493
11577
|
const base = (mime.split(";")[0] ?? "").trim().toLowerCase();
|
|
11494
11578
|
return SUPPORTED_IMAGE_MEDIA_TYPES.includes(base) ? base : null;
|
|
@@ -11496,18 +11580,159 @@ function normalizeImageMediaType(mime) {
|
|
|
11496
11580
|
function isSupportedImageMediaType(mime) {
|
|
11497
11581
|
return normalizeImageMediaType(mime) !== null;
|
|
11498
11582
|
}
|
|
11499
|
-
function
|
|
11500
|
-
|
|
11501
|
-
|
|
11583
|
+
async function apiUserTurnContent(turn, warn = defaultWarn, fetchImpl = fetch) {
|
|
11584
|
+
const all = turn.attachments ?? [];
|
|
11585
|
+
if (all.length === 0) return turn.content;
|
|
11586
|
+
const { fetched } = await fetchAttachments(selectAttachments(all, warn), warn, fetchImpl);
|
|
11587
|
+
const text = appendMissingAttachmentNote(turn.content, all.length - fetched.length);
|
|
11588
|
+
if (fetched.length === 0) return text;
|
|
11589
|
+
return [
|
|
11590
|
+
...fetched.map((f, i) => attachmentBlock(f, i + 1)),
|
|
11591
|
+
{ type: "text", text }
|
|
11592
|
+
];
|
|
11593
|
+
}
|
|
11594
|
+
var PDF_MEDIA_TYPE = "application/pdf";
|
|
11595
|
+
var TEXT_DOCUMENT_MEDIA_TYPES = [
|
|
11596
|
+
"text/plain",
|
|
11597
|
+
"text/csv",
|
|
11598
|
+
"text/markdown",
|
|
11599
|
+
"application/json"
|
|
11600
|
+
];
|
|
11601
|
+
var MAX_ATTACHMENTS_PER_TURN = 8;
|
|
11602
|
+
var MAX_ATTACHMENT_BYTES_PER_TURN = 32 * 1024 * 1024;
|
|
11603
|
+
function baseMime(mime) {
|
|
11604
|
+
return (mime.split(";")[0] ?? "").trim().toLowerCase();
|
|
11605
|
+
}
|
|
11606
|
+
function attachmentKind(mime) {
|
|
11607
|
+
if (isSupportedImageMediaType(mime)) return "image";
|
|
11608
|
+
const base = baseMime(mime);
|
|
11609
|
+
if (base === PDF_MEDIA_TYPE) return "pdf";
|
|
11610
|
+
if (TEXT_DOCUMENT_MEDIA_TYPES.includes(base)) return "text";
|
|
11611
|
+
return null;
|
|
11612
|
+
}
|
|
11613
|
+
function selectAttachments(attachments, warn = defaultWarn) {
|
|
11614
|
+
if (!attachments || attachments.length === 0) return [];
|
|
11615
|
+
const selected = [];
|
|
11616
|
+
let declaredBytes = 0;
|
|
11617
|
+
for (const att of attachments) {
|
|
11618
|
+
if (attachmentKind(att.mimeType) === null) {
|
|
11619
|
+
warn(`Skipping attachment ${att.id}: unsupported type ${att.mimeType}.`);
|
|
11620
|
+
continue;
|
|
11621
|
+
}
|
|
11622
|
+
if (selected.length >= MAX_ATTACHMENTS_PER_TURN) {
|
|
11623
|
+
warn(`Skipping attachment ${att.id}: more than ${String(MAX_ATTACHMENTS_PER_TURN)} on one message.`);
|
|
11624
|
+
continue;
|
|
11625
|
+
}
|
|
11626
|
+
const size = typeof att.sizeBytes === "number" && att.sizeBytes > 0 ? att.sizeBytes : 0;
|
|
11627
|
+
if (declaredBytes + size > MAX_ATTACHMENT_BYTES_PER_TURN) {
|
|
11628
|
+
warn(`Skipping attachment ${att.id}: exceeds the per-message size budget.`);
|
|
11629
|
+
continue;
|
|
11630
|
+
}
|
|
11631
|
+
declaredBytes += size;
|
|
11632
|
+
selected.push(att);
|
|
11633
|
+
}
|
|
11634
|
+
return selected;
|
|
11635
|
+
}
|
|
11636
|
+
async function fetchAttachments(attachments, warn = defaultWarn, fetchImpl = fetch) {
|
|
11637
|
+
const fetched = [];
|
|
11638
|
+
const failed = [];
|
|
11639
|
+
let totalBytes = 0;
|
|
11640
|
+
for (const att of attachments) {
|
|
11641
|
+
const kind = attachmentKind(att.mimeType);
|
|
11642
|
+
if (!kind) {
|
|
11643
|
+
failed.push(att);
|
|
11644
|
+
continue;
|
|
11645
|
+
}
|
|
11646
|
+
try {
|
|
11647
|
+
const res = await fetchImpl(att.signedUrl);
|
|
11648
|
+
if (!res.ok) throw new Error(`fetch failed (HTTP ${String(res.status)})`);
|
|
11649
|
+
const bytes = Buffer.from(await res.arrayBuffer());
|
|
11650
|
+
if (bytes.byteLength === 0) throw new Error("empty response body");
|
|
11651
|
+
if (totalBytes + bytes.byteLength > MAX_ATTACHMENT_BYTES_PER_TURN) {
|
|
11652
|
+
throw new Error("exceeds the per-message size budget");
|
|
11653
|
+
}
|
|
11654
|
+
totalBytes += bytes.byteLength;
|
|
11655
|
+
fetched.push({ attachment: att, kind, bytes });
|
|
11656
|
+
} catch (error) {
|
|
11657
|
+
const message = error instanceof Error ? error.message : "unknown error";
|
|
11658
|
+
warn(`Skipping attachment ${att.id}: ${message}.`);
|
|
11659
|
+
failed.push(att);
|
|
11660
|
+
}
|
|
11661
|
+
}
|
|
11662
|
+
return { fetched, failed };
|
|
11663
|
+
}
|
|
11664
|
+
function attachmentBlock(f, n) {
|
|
11665
|
+
if (f.kind === "image") {
|
|
11666
|
+
const mediaType = normalizeImageMediaType(f.attachment.mimeType) ?? "image/png";
|
|
11667
|
+
return {
|
|
11668
|
+
type: "image",
|
|
11669
|
+
source: { type: "base64", media_type: mediaType, data: f.bytes.toString("base64") }
|
|
11670
|
+
};
|
|
11671
|
+
}
|
|
11672
|
+
if (f.kind === "pdf") {
|
|
11673
|
+
return {
|
|
11674
|
+
type: "document",
|
|
11675
|
+
source: { type: "base64", media_type: PDF_MEDIA_TYPE, data: f.bytes.toString("base64") }
|
|
11676
|
+
};
|
|
11677
|
+
}
|
|
11678
|
+
const label = `attachment ${String(n)} (${baseMime(f.attachment.mimeType)})`;
|
|
11679
|
+
return {
|
|
11680
|
+
type: "text",
|
|
11681
|
+
text: `<<<BEGIN ${label}>>>
|
|
11682
|
+
${f.bytes.toString("utf8")}
|
|
11683
|
+
<<<END ${label}>>>`
|
|
11684
|
+
};
|
|
11502
11685
|
}
|
|
11503
|
-
function
|
|
11504
|
-
if (
|
|
11505
|
-
const noun =
|
|
11506
|
-
const note = `[${String(
|
|
11686
|
+
function appendMissingAttachmentNote(text, count) {
|
|
11687
|
+
if (count <= 0) return text;
|
|
11688
|
+
const noun = count === 1 ? "attachment" : "attachments";
|
|
11689
|
+
const note = `[${String(count)} ${noun} could not be loaded and ${count === 1 ? "is" : "are"} not shown]`;
|
|
11507
11690
|
return text.trim().length > 0 ? `${text}
|
|
11508
11691
|
|
|
11509
11692
|
${note}` : note;
|
|
11510
11693
|
}
|
|
11694
|
+
var EXTENSION_BY_MIME = {
|
|
11695
|
+
"image/png": "png",
|
|
11696
|
+
"image/jpeg": "jpg",
|
|
11697
|
+
"image/gif": "gif",
|
|
11698
|
+
"image/webp": "webp",
|
|
11699
|
+
"application/pdf": "pdf",
|
|
11700
|
+
"text/plain": "txt",
|
|
11701
|
+
"text/csv": "csv",
|
|
11702
|
+
"text/markdown": "md",
|
|
11703
|
+
"application/json": "json"
|
|
11704
|
+
};
|
|
11705
|
+
async function materializeAttachments(dir, attachments, fetchImpl = fetch, warn = defaultWarn) {
|
|
11706
|
+
const all = attachments ?? [];
|
|
11707
|
+
if (all.length === 0) return { files: [], failed: 0 };
|
|
11708
|
+
const { fetched } = await fetchAttachments(selectAttachments(all, warn), warn, fetchImpl);
|
|
11709
|
+
const files = [];
|
|
11710
|
+
if (fetched.length > 0) await mkdir2(dir, { recursive: true });
|
|
11711
|
+
for (const f of fetched) {
|
|
11712
|
+
const mimeType = baseMime(f.attachment.mimeType);
|
|
11713
|
+
const path3 = join16(dir, `attachment-${String(files.length + 1)}.${EXTENSION_BY_MIME[mimeType] ?? "bin"}`);
|
|
11714
|
+
try {
|
|
11715
|
+
await writeFile2(path3, f.bytes);
|
|
11716
|
+
files.push({ path: path3, mimeType });
|
|
11717
|
+
} catch (error) {
|
|
11718
|
+
const message = error instanceof Error ? error.message : "unknown error";
|
|
11719
|
+
warn(`Skipping attachment ${f.attachment.id}: could not save it (${message}).`);
|
|
11720
|
+
}
|
|
11721
|
+
}
|
|
11722
|
+
return { files, failed: all.length - files.length };
|
|
11723
|
+
}
|
|
11724
|
+
function appendAttachmentPaths(text, files, failed) {
|
|
11725
|
+
let out = text;
|
|
11726
|
+
if (files.length > 0) {
|
|
11727
|
+
const list = files.map((f) => `- ${f.path} (${f.mimeType})`).join("\n");
|
|
11728
|
+
const note = `[Attached files \u2014 open them with the Read tool:
|
|
11729
|
+
${list}]`;
|
|
11730
|
+
out = out.trim().length > 0 ? `${out}
|
|
11731
|
+
|
|
11732
|
+
${note}` : note;
|
|
11733
|
+
}
|
|
11734
|
+
return appendMissingAttachmentNote(out, failed);
|
|
11735
|
+
}
|
|
11511
11736
|
function usageLimitMessage(resumeAt) {
|
|
11512
11737
|
return resumeAt ? `The AI usage limit was reached. The run will continue after it resets at ${resumeAt.toISOString()}.` : "The AI usage limit was reached. The run will continue after it resets.";
|
|
11513
11738
|
}
|
|
@@ -11559,6 +11784,17 @@ function claudeCliSessionCwd() {
|
|
|
11559
11784
|
}
|
|
11560
11785
|
return dir;
|
|
11561
11786
|
}
|
|
11787
|
+
function claudeToolArgs(attachmentsDir) {
|
|
11788
|
+
if (!attachmentsDir) return ["--tools", ""];
|
|
11789
|
+
return [
|
|
11790
|
+
"--tools",
|
|
11791
|
+
"Read",
|
|
11792
|
+
"--add-dir",
|
|
11793
|
+
attachmentsDir,
|
|
11794
|
+
"--allowedTools",
|
|
11795
|
+
`Read(/${attachmentsDir}/**)`
|
|
11796
|
+
];
|
|
11797
|
+
}
|
|
11562
11798
|
function runClaudeCliTurn(prompt, opts) {
|
|
11563
11799
|
return new Promise((resolve4, reject) => {
|
|
11564
11800
|
const model = opts.model === void 0 ? ANTHROPIC_MODEL : opts.model;
|
|
@@ -11568,8 +11804,7 @@ function runClaudeCliTurn(prompt, opts) {
|
|
|
11568
11804
|
...model ? ["--model", model] : [],
|
|
11569
11805
|
"--output-format",
|
|
11570
11806
|
"json",
|
|
11571
|
-
|
|
11572
|
-
"",
|
|
11807
|
+
...claudeToolArgs(opts.attachmentsDir),
|
|
11573
11808
|
"--permission-mode",
|
|
11574
11809
|
"dontAsk",
|
|
11575
11810
|
"--safe-mode",
|
|
@@ -11686,11 +11921,43 @@ async function takeConversationStep(job, ctx) {
|
|
|
11686
11921
|
const requestId = savedRequestIdOf(job);
|
|
11687
11922
|
const discussed = requestId !== null && parseSeedPayload(job.payload)?.targetEpicRequestId === requestId;
|
|
11688
11923
|
const saved = requestId ? await loadSavedRequest(ctx.apiBaseUrl, ctx.userApiToken, requestId, discussed) : null;
|
|
11689
|
-
const turns = job.turns.map((t) => ({
|
|
11690
|
-
role: t.role,
|
|
11691
|
-
content: t.role === "user" ? appendAttachmentNote(t.content, imageAttachmentCount(t.attachments)) : t.content
|
|
11692
|
-
}));
|
|
11693
11924
|
const anthropic = ctx.anthropicApiKey ? new Anthropic(anthropicClientOptions(ctx.anthropicApiKey, routing)) : null;
|
|
11925
|
+
const hasAttachments = job.turns.some(
|
|
11926
|
+
(t) => t.role === "user" && (t.attachments?.length ?? 0) > 0
|
|
11927
|
+
);
|
|
11928
|
+
const attachmentsDir = !anthropic && hasAttachments ? await realpath(await mkdtemp(join16(tmpdir2(), "compbox-attachments-"))) : void 0;
|
|
11929
|
+
try {
|
|
11930
|
+
return await converseWithAttachments(job, ctx, {
|
|
11931
|
+
routing,
|
|
11932
|
+
saved,
|
|
11933
|
+
anthropic,
|
|
11934
|
+
attachmentsDir
|
|
11935
|
+
});
|
|
11936
|
+
} finally {
|
|
11937
|
+
if (attachmentsDir) await rm(attachmentsDir, { recursive: true, force: true });
|
|
11938
|
+
}
|
|
11939
|
+
}
|
|
11940
|
+
async function converseWithAttachments(job, ctx, step) {
|
|
11941
|
+
const { routing, saved, anthropic, attachmentsDir } = step;
|
|
11942
|
+
let usedFiles = false;
|
|
11943
|
+
const turns = [];
|
|
11944
|
+
for (const [index, t] of job.turns.entries()) {
|
|
11945
|
+
if (t.role !== "user") {
|
|
11946
|
+
turns.push({ role: t.role, content: t.content });
|
|
11947
|
+
} else if (anthropic) {
|
|
11948
|
+
turns.push({ role: t.role, content: await apiUserTurnContent(t) });
|
|
11949
|
+
} else if (attachmentsDir && (t.attachments?.length ?? 0) > 0) {
|
|
11950
|
+
const { files, failed } = await materializeAttachments(
|
|
11951
|
+
join16(attachmentsDir, `turn-${String(index + 1)}`),
|
|
11952
|
+
t.attachments
|
|
11953
|
+
);
|
|
11954
|
+
if (files.length > 0) usedFiles = true;
|
|
11955
|
+
turns.push({ role: t.role, content: appendAttachmentPaths(t.content, files, failed) });
|
|
11956
|
+
} else {
|
|
11957
|
+
turns.push({ role: t.role, content: t.content });
|
|
11958
|
+
}
|
|
11959
|
+
}
|
|
11960
|
+
const readDir = usedFiles ? attachmentsDir : void 0;
|
|
11694
11961
|
let cliModel = ANTHROPIC_MODEL;
|
|
11695
11962
|
const outcome = await runConversationStep(
|
|
11696
11963
|
{ turns, saved },
|
|
@@ -11712,7 +11979,8 @@ async function takeConversationStep(job, ctx) {
|
|
|
11712
11979
|
systemPrompt: system,
|
|
11713
11980
|
resumeSessionId: void 0,
|
|
11714
11981
|
routing,
|
|
11715
|
-
model: cliModel
|
|
11982
|
+
model: cliModel,
|
|
11983
|
+
attachmentsDir: readDir
|
|
11716
11984
|
})).text;
|
|
11717
11985
|
} catch (error) {
|
|
11718
11986
|
if (cliModel === null || !needsDefaultModel(error)) throw error;
|
|
@@ -11721,7 +11989,8 @@ async function takeConversationStep(job, ctx) {
|
|
|
11721
11989
|
systemPrompt: system,
|
|
11722
11990
|
resumeSessionId: void 0,
|
|
11723
11991
|
routing,
|
|
11724
|
-
model: null
|
|
11992
|
+
model: null,
|
|
11993
|
+
attachmentsDir: readDir
|
|
11725
11994
|
})).text;
|
|
11726
11995
|
}
|
|
11727
11996
|
},
|
|
@@ -12427,9 +12696,11 @@ var ORCHESTRATOR_FINAL_TURN_MAX_CHARS = 4e3;
|
|
|
12427
12696
|
function buildOrchestratorArgs(epicId, sessionId, ownerReply, baseBranch, fastMode, extra) {
|
|
12428
12697
|
return [
|
|
12429
12698
|
"-p",
|
|
12430
|
-
`@orchestrator execute epic ${epicId} --non-interactive` + (ownerReply ? `
|
|
12699
|
+
`@orchestrator execute epic ${epicId} --non-interactive` + (ownerReply || extra?.replyAttachmentsNote ? `
|
|
12700
|
+
|
|
12701
|
+
${freshRunReplyContext(ownerReply ?? "", extra?.replyAttachmentsNote)}` : "") + (extra?.followUp ? `
|
|
12431
12702
|
|
|
12432
|
-
${
|
|
12703
|
+
${followUpContext(extra.followUp)}` : "") + (extra?.ownerNote ? `
|
|
12433
12704
|
|
|
12434
12705
|
${ownerNoteContext(extra.ownerNote)}` : "") + (extra?.deferred && extra.deferred.length > 0 ? `
|
|
12435
12706
|
|
|
@@ -12465,6 +12736,13 @@ function deferredFeaturesText(deferred) {
|
|
|
12465
12736
|
function ownerNoteContext(note) {
|
|
12466
12737
|
return ["The owner restarted this build with this note:", quoteOwnerReply(note)].join("\n\n");
|
|
12467
12738
|
}
|
|
12739
|
+
function followUpContext(message) {
|
|
12740
|
+
return [
|
|
12741
|
+
"This epic's build already finished. Its owner sent this follow-up:",
|
|
12742
|
+
quoteOwnerReply(message, "a follow-up to the finished build"),
|
|
12743
|
+
"Act on it against the epic's blueprint: change features, tasks or code as needed, and report what you changed. If it is unclear, ask with a single COMPBOX_NEEDS_INPUT marker."
|
|
12744
|
+
].join("\n\n");
|
|
12745
|
+
}
|
|
12468
12746
|
function buildOrchestratorContinueArgs(sessionId, prompt, baseBranch, fastMode) {
|
|
12469
12747
|
return [
|
|
12470
12748
|
"-p",
|
|
@@ -12481,6 +12759,23 @@ function buildOrchestratorContinueArgs(sessionId, prompt, baseBranch, fastMode)
|
|
|
12481
12759
|
...fastModeArgs(fastMode)
|
|
12482
12760
|
];
|
|
12483
12761
|
}
|
|
12762
|
+
function parseReplyAttachments(raw) {
|
|
12763
|
+
if (!Array.isArray(raw)) return [];
|
|
12764
|
+
const out = [];
|
|
12765
|
+
for (const item of raw) {
|
|
12766
|
+
if (typeof item !== "object" || item === null) continue;
|
|
12767
|
+
const a = item;
|
|
12768
|
+
if (typeof a.id !== "string" || typeof a.mimeType !== "string" || typeof a.signedUrl !== "string") continue;
|
|
12769
|
+
if (a.signedUrl.trim() === "") continue;
|
|
12770
|
+
out.push({
|
|
12771
|
+
id: a.id,
|
|
12772
|
+
mimeType: a.mimeType,
|
|
12773
|
+
sizeBytes: typeof a.sizeBytes === "number" && Number.isFinite(a.sizeBytes) ? a.sizeBytes : 0,
|
|
12774
|
+
signedUrl: a.signedUrl
|
|
12775
|
+
});
|
|
12776
|
+
}
|
|
12777
|
+
return out;
|
|
12778
|
+
}
|
|
12484
12779
|
var MAX_REPLY_CHARS = 8e3;
|
|
12485
12780
|
var REPLY_OPEN = "<<<OWNER_REPLY";
|
|
12486
12781
|
var REPLY_CLOSE = "OWNER_REPLY>>>";
|
|
@@ -12488,16 +12783,24 @@ function parseReplyResume(job) {
|
|
|
12488
12783
|
const raw = job.resume;
|
|
12489
12784
|
if (typeof raw !== "object" || raw === null) return null;
|
|
12490
12785
|
const r = raw;
|
|
12491
|
-
if (typeof r.reply !== "string"
|
|
12786
|
+
if (typeof r.reply !== "string") return null;
|
|
12787
|
+
const attachments = parseReplyAttachments(r.attachments);
|
|
12788
|
+
if (r.reply.trim() === "" && attachments.length === 0) return null;
|
|
12492
12789
|
const str = (v) => typeof v === "string" && v.trim() !== "" ? v : null;
|
|
12493
12790
|
const result = typeof job.result === "object" && job.result !== null ? job.result : {};
|
|
12494
12791
|
return {
|
|
12495
12792
|
sessionId: str(r.sessionId),
|
|
12496
12793
|
runDir: str(r.runDir),
|
|
12497
12794
|
reply: r.reply,
|
|
12498
|
-
branch: str(result.branch)
|
|
12795
|
+
branch: str(result.branch),
|
|
12796
|
+
attachments
|
|
12499
12797
|
};
|
|
12500
12798
|
}
|
|
12799
|
+
function replyAttachmentsNote(files, failed) {
|
|
12800
|
+
if (files.length === 0 && failed <= 0) return "";
|
|
12801
|
+
const head = "The owner attached files to the reply.";
|
|
12802
|
+
return appendAttachmentPaths(head, files, failed);
|
|
12803
|
+
}
|
|
12501
12804
|
function quoteOwnerReply(reply, kind = "an answer to your question") {
|
|
12502
12805
|
let body = reply.slice(0, MAX_REPLY_CHARS);
|
|
12503
12806
|
for (; ; ) {
|
|
@@ -12524,10 +12827,11 @@ function ownerNotePrompt(epicId, notes, deferred = []) {
|
|
|
12524
12827
|
...deferred.length > 0 ? [deferredFeaturesText(deferred)] : []
|
|
12525
12828
|
].join("\n\n");
|
|
12526
12829
|
}
|
|
12527
|
-
function replyResumePrompt(epicId, reply) {
|
|
12830
|
+
function replyResumePrompt(epicId, reply, attachmentsNote = "") {
|
|
12528
12831
|
return [
|
|
12529
12832
|
`The owner answered your question:`,
|
|
12530
12833
|
quoteOwnerReply(reply),
|
|
12834
|
+
...attachmentsNote ? [attachmentsNote] : [],
|
|
12531
12835
|
`Continue executing epic ${epicId} in non-interactive mode from where you stopped.`,
|
|
12532
12836
|
"If the answer is not enough, ask again with a single COMPBOX_NEEDS_INPUT marker."
|
|
12533
12837
|
].join("\n\n");
|
|
@@ -12535,10 +12839,11 @@ function replyResumePrompt(epicId, reply) {
|
|
|
12535
12839
|
function buildReplyResumeArgs(sessionId, prompt, baseBranch, fastMode) {
|
|
12536
12840
|
return buildOrchestratorContinueArgs(sessionId, prompt, baseBranch, fastMode);
|
|
12537
12841
|
}
|
|
12538
|
-
function freshRunReplyContext(reply) {
|
|
12842
|
+
function freshRunReplyContext(reply, attachmentsNote = "") {
|
|
12539
12843
|
return [
|
|
12540
12844
|
"This build stopped earlier to ask its owner a question. The owner answered:",
|
|
12541
12845
|
quoteOwnerReply(reply),
|
|
12846
|
+
...attachmentsNote ? [attachmentsNote] : [],
|
|
12542
12847
|
"Use the answer where the earlier run stopped. If it is not enough, ask again with a single COMPBOX_NEEDS_INPUT marker."
|
|
12543
12848
|
].join("\n\n");
|
|
12544
12849
|
}
|
|
@@ -12768,17 +13073,35 @@ async function invokeStartExecutionOrchestrate(ctx, deps = {}) {
|
|
|
12768
13073
|
}
|
|
12769
13074
|
const runDir = workspace?.dir ?? projectDir;
|
|
12770
13075
|
if (workspace) deps.activeRunDirs?.add(workspace.dir);
|
|
13076
|
+
let replyAttachmentsDir;
|
|
13077
|
+
let attachmentsNote = "";
|
|
13078
|
+
const replyAttachments = resume?.attachments ?? [];
|
|
13079
|
+
if (replyAttachments.length > 0) {
|
|
13080
|
+
try {
|
|
13081
|
+
replyAttachmentsDir = await realpath(await mkdtemp(join16(tmpdir2(), "compbox-reply-attachments-")));
|
|
13082
|
+
const { files, failed } = await materializeAttachments(
|
|
13083
|
+
replyAttachmentsDir,
|
|
13084
|
+
replyAttachments,
|
|
13085
|
+
deps.fetchImpl ?? fetch
|
|
13086
|
+
);
|
|
13087
|
+
attachmentsNote = replyAttachmentsNote(files, failed);
|
|
13088
|
+
} catch {
|
|
13089
|
+
attachmentsNote = replyAttachmentsNote([], replyAttachments.length);
|
|
13090
|
+
}
|
|
13091
|
+
}
|
|
12771
13092
|
const routing = await resolveRoutingImpl();
|
|
12772
13093
|
const command = resolveClaudeBinary() ?? "claude";
|
|
12773
13094
|
const sessionId = ctx.fix ? void 0 : resumeSessionId ?? (deps.newSessionId ?? randomUUID)();
|
|
12774
13095
|
const runArgs = ctx.fix ? buildFixArgs(ctx.fix, workspace?.baseBranch, ctx.fastMode) : resumeSessionId && resume ? buildReplyResumeArgs(
|
|
12775
13096
|
resumeSessionId,
|
|
12776
|
-
replyResumePrompt(ctx.epicId, resume.reply),
|
|
13097
|
+
replyResumePrompt(ctx.epicId, resume.reply, attachmentsNote),
|
|
12777
13098
|
workspace?.baseBranch,
|
|
12778
13099
|
ctx.fastMode
|
|
12779
13100
|
) : buildOrchestratorArgs(ctx.epicId, sessionId, resume?.reply, workspace?.baseBranch, ctx.fastMode, {
|
|
12780
13101
|
...ctx.ownerNote && { ownerNote: ctx.ownerNote },
|
|
12781
|
-
...ctx.deferredFeatures && { deferred: ctx.deferredFeatures }
|
|
13102
|
+
...ctx.deferredFeatures && { deferred: ctx.deferredFeatures },
|
|
13103
|
+
...ctx.followUp && { followUp: ctx.followUp },
|
|
13104
|
+
...attachmentsNote && { replyAttachmentsNote: attachmentsNote }
|
|
12782
13105
|
});
|
|
12783
13106
|
const args = ctx.keyRun ? keyRunArgs(runArgs) : runArgs;
|
|
12784
13107
|
const routedEnv = claudeSpawnEnv(process.env, routing);
|
|
@@ -13190,6 +13513,7 @@ ${stderr}`;
|
|
|
13190
13513
|
}
|
|
13191
13514
|
}
|
|
13192
13515
|
if (workspace) deps.activeRunDirs?.delete(workspace.dir);
|
|
13516
|
+
if (replyAttachmentsDir) await rm(replyAttachmentsDir, { recursive: true, force: true }).catch(() => void 0);
|
|
13193
13517
|
const timings = buildJobTimings({
|
|
13194
13518
|
install: workspace?.install,
|
|
13195
13519
|
runs: runDurations,
|
|
@@ -13373,7 +13697,7 @@ async function invokeConnectRepo(payload, deps = {}) {
|
|
|
13373
13697
|
const readOrigin = deps.readOrigin ?? readOriginRemote;
|
|
13374
13698
|
const listDirs = deps.listDirs ?? listProjectDirs;
|
|
13375
13699
|
const addDir = deps.addDir ?? ((path3) => addProjectDir(path3));
|
|
13376
|
-
const
|
|
13700
|
+
const mkdir3 = deps.mkdir ?? ((path3) => void mkdirSync10(path3, { recursive: true }));
|
|
13377
13701
|
const p = parsePayload(payload);
|
|
13378
13702
|
if (!p) {
|
|
13379
13703
|
return { status: "failed", result: { error: "The job was missing the project repository. Try again from the project page." } };
|
|
@@ -13410,7 +13734,7 @@ async function invokeConnectRepo(payload, deps = {}) {
|
|
|
13410
13734
|
result: { path: entry2.path, remote, outcome: "adopted", message: `Found an existing copy of ${name} at ${entry2.path} and set it up.` }
|
|
13411
13735
|
};
|
|
13412
13736
|
}
|
|
13413
|
-
|
|
13737
|
+
mkdir3(dirname6(target));
|
|
13414
13738
|
const errors = [];
|
|
13415
13739
|
let cloned = false;
|
|
13416
13740
|
for (const url of cloneUrls(remote)) {
|
|
@@ -13686,6 +14010,16 @@ function parseStartExecutionPayload(payload) {
|
|
|
13686
14010
|
...useAiKey && { useAiKey }
|
|
13687
14011
|
};
|
|
13688
14012
|
}
|
|
14013
|
+
if (p.kind === "follow_up" && typeof p.epicId === "string" && p.epicId.length > 0 && typeof p.parentJobId === "string" && p.parentJobId.length > 0) {
|
|
14014
|
+
return {
|
|
14015
|
+
kind: "follow_up",
|
|
14016
|
+
epicId: p.epicId,
|
|
14017
|
+
parentJobId: p.parentJobId,
|
|
14018
|
+
...typeof p.epicRequestId === "string" && p.epicRequestId.length > 0 && { epicRequestId: p.epicRequestId },
|
|
14019
|
+
...projectRemote && { projectRemote },
|
|
14020
|
+
...useAiKey && { useAiKey }
|
|
14021
|
+
};
|
|
14022
|
+
}
|
|
13689
14023
|
return null;
|
|
13690
14024
|
}
|
|
13691
14025
|
async function handleStartExecution(ctx, job) {
|
|
@@ -13694,7 +14028,7 @@ async function handleStartExecution(ctx, job) {
|
|
|
13694
14028
|
await completeWithFailure(
|
|
13695
14029
|
ctx,
|
|
13696
14030
|
job,
|
|
13697
|
-
'The start_execution job payload was missing or malformed (expected {kind:"plan",epicRequestId}, {kind:"orchestrate",epicId}
|
|
14031
|
+
'The start_execution job payload was missing or malformed (expected {kind:"plan",epicRequestId}, {kind:"orchestrate",epicId}, {kind:"refine",epicId,notes?} or {kind:"follow_up",epicId,parentJobId}).'
|
|
13698
14032
|
);
|
|
13699
14033
|
return;
|
|
13700
14034
|
}
|
|
@@ -13789,6 +14123,15 @@ async function handleStartExecution(ctx, job) {
|
|
|
13789
14123
|
);
|
|
13790
14124
|
return;
|
|
13791
14125
|
}
|
|
14126
|
+
let followUp;
|
|
14127
|
+
if (payload.kind === "follow_up") {
|
|
14128
|
+
followUp = job.turns.find((t) => t.role === "user" && t.content.trim() !== "")?.content;
|
|
14129
|
+
if (!followUp) {
|
|
14130
|
+
await completeWithFailure(ctx, job, "This follow-up has no message to act on. Send the message again.");
|
|
14131
|
+
return;
|
|
14132
|
+
}
|
|
14133
|
+
}
|
|
14134
|
+
const orch = payload.kind === "orchestrate" ? payload : void 0;
|
|
13792
14135
|
const userApiToken = ctx.userApiToken;
|
|
13793
14136
|
if (!userApiToken) {
|
|
13794
14137
|
await completeWithFailure(
|
|
@@ -13809,7 +14152,7 @@ async function handleStartExecution(ctx, job) {
|
|
|
13809
14152
|
const resume = parseReplyResume(job);
|
|
13810
14153
|
console.log(
|
|
13811
14154
|
chalk9.gray(
|
|
13812
|
-
resume ? " Resuming the orchestrator with the owner's reply (start_execution / orchestrate)..." : " Running the orchestrator headless (start_execution / orchestrate)..."
|
|
14155
|
+
resume ? " Resuming the orchestrator with the owner's reply (start_execution / orchestrate)..." : followUp ? " Running the orchestrator on the owner's follow-up (start_execution / follow_up)..." : " Running the orchestrator headless (start_execution / orchestrate)..."
|
|
13813
14156
|
)
|
|
13814
14157
|
);
|
|
13815
14158
|
await runInvokerAndComplete(ctx, job, async () => {
|
|
@@ -13822,11 +14165,12 @@ async function handleStartExecution(ctx, job) {
|
|
|
13822
14165
|
epicId: payload.epicId,
|
|
13823
14166
|
projectDir: jobProjectDir,
|
|
13824
14167
|
...keyRun && { keyRun },
|
|
13825
|
-
...
|
|
13826
|
-
...
|
|
13827
|
-
...
|
|
13828
|
-
...
|
|
13829
|
-
...
|
|
14168
|
+
...orch?.fix && { fix: orch.fix },
|
|
14169
|
+
...orch?.fastMode === true && { fastMode: true },
|
|
14170
|
+
...orch?.ownerNote && { ownerNote: orch.ownerNote },
|
|
14171
|
+
...orch?.deferredFeatures && { deferredFeatures: orch.deferredFeatures },
|
|
14172
|
+
...orch?.freshBranch === true && { freshBranch: true },
|
|
14173
|
+
...followUp && { followUp },
|
|
13830
14174
|
...resume && { resume },
|
|
13831
14175
|
// ENG-345: cloud facts for the preflight (absent on older servers).
|
|
13832
14176
|
cloud: parseCloudFacts(job.cloud),
|
|
@@ -13847,7 +14191,7 @@ async function handleStartExecution(ctx, job) {
|
|
|
13847
14191
|
})
|
|
13848
14192
|
}
|
|
13849
14193
|
);
|
|
13850
|
-
return
|
|
14194
|
+
return orch?.fix ? outcome : applyMergePolicy(mergePolicy, outcome, merge);
|
|
13851
14195
|
});
|
|
13852
14196
|
}
|
|
13853
14197
|
var ACTIVE_RUN_DIRS = /* @__PURE__ */ new Set();
|