toolroll 0.9.115 → 0.9.117
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/CHANGELOG.md +55 -0
- package/README.md +43 -26
- package/dist/acp-agents.js +14 -1
- package/dist/acp-client.js +19 -1
- package/dist/agent-change-check.js +60 -0
- package/dist/agent-change-schema.js +19 -0
- package/dist/agent-detect.js +11 -1
- package/dist/agent-fence.js +39 -10
- package/dist/agent-network-request.js +108 -0
- package/dist/agent-requests.js +105 -0
- package/dist/approval-summary.js +3 -3
- package/dist/backup.js +17 -1
- package/dist/batch-checks.js +81 -18
- package/dist/browser/terminal.js +41 -41
- package/dist/browser/workspace.css +2 -2
- package/dist/browser/workspace.js +36 -36
- package/dist/builder.js +3 -1
- package/dist/candidate-materialize.js +119 -0
- package/dist/central-enrollment-contract.js +156 -0
- package/dist/central-recovery-stage.js +329 -0
- package/dist/chat-actions.js +101 -2
- package/dist/chat-channel.js +40 -0
- package/dist/check-only-standing.js +13 -0
- package/dist/check-only.js +25 -13
- package/dist/check-recovery-hold.js +199 -0
- package/dist/check-recovery-index-schema.js +3 -0
- package/dist/check-screenshots.js +83 -0
- package/dist/cli.js +125 -6
- package/dist/codex-limits.js +4 -0
- package/dist/connect-cli.js +257 -11
- package/dist/contracts/chat-actions.js +4 -0
- package/dist/contracts/console-api.js +15 -4
- package/dist/contracts/engine-api.js +344 -2
- package/dist/contracts/lead-tools.js +56 -2
- package/dist/contracts/provider.js +1 -1
- package/dist/contracts/route.js +1 -1
- package/dist/contracts/terminal-connection.js +50 -0
- package/dist/converse.js +80 -4
- package/dist/device-pair.js +280 -0
- package/dist/direct-chat-artifacts.js +347 -0
- package/dist/direct-chat-catalog.js +311 -0
- package/dist/direct-chat-fence.js +96 -0
- package/dist/direct-chat-git.js +343 -0
- package/dist/direct-chat-laptop.js +19 -0
- package/dist/direct-chat-schema.js +181 -0
- package/dist/direct-chat-ship.js +861 -0
- package/dist/direct-chat-workspace.js +389 -0
- package/dist/direct-chat.js +2107 -0
- package/dist/doctor.js +1 -1
- package/dist/easy-start.js +18 -0
- package/dist/egress.js +25 -4
- package/dist/engine-chat.js +454 -0
- package/dist/engine-reads.js +141 -13
- package/dist/exec.js +4 -3
- package/dist/flexible-agents.js +8 -16
- package/dist/flexible-authority-end.js +2 -0
- package/dist/flexible-interactive-schema.js +133 -0
- package/dist/flexible-interactive.js +94 -0
- package/dist/flexible-session.js +117 -49
- package/dist/flexible-ship.js +87 -7
- package/dist/flexible-sign-in.js +10 -0
- package/dist/flexible-start.js +21 -3
- package/dist/flexible-thread.js +2 -3
- package/dist/flexible-turns.js +26 -5
- package/dist/flexible.js +13 -0
- package/dist/flow-triggers.js +13 -4
- package/dist/flows-ui.js +54 -20
- package/dist/handoff-cli.js +630 -0
- package/dist/invoke.js +55 -13
- package/dist/lead-contract.js +5 -4
- package/dist/lead-doors.js +80 -1
- package/dist/lead-progress.js +9 -0
- package/dist/lead-tools.js +682 -10
- package/dist/lead.js +37 -9
- package/dist/live-bus.js +11 -0
- package/dist/live-terminal.js +132 -12
- package/dist/local-handoff.js +363 -0
- package/dist/local-owner-acts.js +264 -2
- package/dist/local-owner.js +16 -1
- package/dist/multiplayer-handoff.js +528 -0
- package/dist/multiplayer-presence.js +471 -0
- package/dist/names.js +17 -4
- package/dist/needs-you.js +10 -0
- package/dist/operate.js +280 -19
- package/dist/policy.js +2 -2
- package/dist/project-delete-ui.js +18 -11
- package/dist/project-delete.js +65 -4
- package/dist/project-tools.js +1 -1
- package/dist/prompt.js +1 -1
- package/dist/provider-connection.js +2 -0
- package/dist/provider-home.js +251 -8
- package/dist/provider.js +3 -2
- package/dist/publish.js +119 -64
- package/dist/pull-request-flow.js +35 -14
- package/dist/read-executor-worker.js +1 -1
- package/dist/read-executor.js +95 -1
- package/dist/restore-retirement.js +152 -0
- package/dist/result-follow-ups.js +116 -37
- package/dist/route-change.js +44 -4
- package/dist/scope.js +62 -5
- package/dist/serve.js +49 -5
- package/dist/server/chat.js +94 -13
- package/dist/server/console.css +9 -9
- package/dist/server/direct-chat.js +583 -0
- package/dist/server/engine-api.js +219 -21
- package/dist/server/flows.js +47 -13
- package/dist/server/found-repos.js +25 -0
- package/dist/server/guards.js +20 -6
- package/dist/server/live.js +81 -23
- package/dist/server/pages.js +67 -13
- package/dist/server/people-tokens.js +47 -6
- package/dist/server/remote.js +29 -0
- package/dist/server/render-results.js +6 -2
- package/dist/server/render-settings.js +4 -2
- package/dist/server/render-tasks.js +18 -17
- package/dist/server/route-table.js +69 -2
- package/dist/server/settings.js +22 -7
- package/dist/server/task-views.js +15 -3
- package/dist/server/tasks.js +39 -2
- package/dist/server/terminals.js +185 -11
- package/dist/settings-proofs.js +1 -1
- package/dist/spend-report.js +2 -2
- package/dist/spend.js +3 -3
- package/dist/store.js +600 -59
- package/dist/subagent-admin.js +23 -10
- package/dist/subagent-backup-schema.js +36 -0
- package/dist/subagent-backup.js +92 -0
- package/dist/subagent-week.js +2 -2
- package/dist/subagent-work.js +70 -47
- package/dist/subagents-ui.js +6 -2
- package/dist/subagents.js +5 -2
- package/dist/subscription-chat.js +36 -5
- package/dist/subscription-usage.js +233 -0
- package/dist/task-live.js +2 -1
- package/dist/teardown-git.js +34 -4
- package/dist/terminal-connection.js +159 -0
- package/dist/terminal-safety.js +114 -0
- package/dist/tui/darwin-arm64/toolroll-tui +0 -0
- package/dist/tui/darwin-x64/toolroll-tui +0 -0
- package/dist/tui/linux-arm64/toolroll-tui +0 -0
- package/dist/tui/linux-x64/toolroll-tui +0 -0
- package/dist/tui-contract.js +1 -1
- package/dist/tui-launch.js +32 -1
- package/dist/workspace-identity-schema.js +21 -0
- package/package.json +4 -2
package/dist/subagent-admin.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { validModelId } from "./provider.js";
|
|
1
2
|
import { flowDefinitionOf } from "./flow-engine.js";
|
|
2
3
|
import { handleOf, parseSoul, SUBAGENT_TEMPLATES, subagentLabel } from "./subagents.js";
|
|
3
4
|
export const SUBAGENT_MODELS = ["default", "sonnet", "opus", "haiku"];
|
|
@@ -46,16 +47,28 @@ export function setSubagentState(store, mate, state, by, now) {
|
|
|
46
47
|
store.addSubagentEvent({ subagent: mate.id, kind: state === "paused" ? "paused" : "resumed", said: state === "paused" ? `${by} paused ${name}.` : `${by} set ${name} working again.`, by }, now);
|
|
47
48
|
return { ok: true, said: state === "paused" ? `${name} is paused. Its decisions go to people until you resume it.` : `${name} is working again.` };
|
|
48
49
|
}
|
|
49
|
-
export function subagentSettings(store, mate, change, by, now) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
50
|
+
export function subagentSettings(store, mate, change, by, now, options = {}) {
|
|
51
|
+
return store.transact(() => {
|
|
52
|
+
const current = store.getSubagent(mate.id);
|
|
53
|
+
if (current === null || current.state === "removed")
|
|
54
|
+
return { ok: false, said: "This teammate is no longer on the team." };
|
|
55
|
+
const model = change.model === undefined ? undefined : change.model === "default" ? null : SUBAGENT_MODELS.includes(change.model) ? change.model : undefined;
|
|
56
|
+
if (change.model !== undefined && model === undefined)
|
|
57
|
+
return { ok: false, said: "Choose one of the models listed." };
|
|
58
|
+
if (change.dailyTurns !== undefined && (!Number.isInteger(change.dailyTurns) || change.dailyTurns < 1 || change.dailyTurns > 2000))
|
|
59
|
+
return { ok: false, said: "A daily limit is 1 to 2,000 turns." };
|
|
60
|
+
if (change.manager !== undefined && !store.accountCanAccess(change.manager, current.repo))
|
|
61
|
+
return { ok: false, said: "Its manager must be someone on this project." };
|
|
62
|
+
const backup = change.codexBackupModel;
|
|
63
|
+
if (backup !== undefined && backup !== null && (!validModelId(backup) || ["default", "inherit", ""].includes(backup)))
|
|
64
|
+
return { ok: false, said: "Enter an exact Codex backup model ID, or leave it blank to turn the backup off." };
|
|
65
|
+
if (backup != null && backup !== current.codexBackupModel && (!store.accountCanAccess(by, current.repo) || options.proveBackup?.() !== true))
|
|
66
|
+
return { ok: false, said: "Enter your Toolroll password to enable or change the Codex backup. Nothing changed." };
|
|
67
|
+
store.updateSubagent(current.id, { ...(model === undefined ? {} : { model }), ...(change.dailyTurns === undefined ? {} : { dailyTurns: change.dailyTurns }), ...(change.manager === undefined ? {} : { manager: change.manager }) }, by, now);
|
|
68
|
+
if (backup !== undefined && backup !== current.codexBackupModel)
|
|
69
|
+
store.setSubagentCodexBackup(current.id, backup, by, now);
|
|
70
|
+
return { ok: true, said: "Saved." };
|
|
71
|
+
});
|
|
59
72
|
}
|
|
60
73
|
export const nameOf = (mate) => { const read = parseSoul(mate.soul); return read.ok ? read.soul.name : mate.handle; };
|
|
61
74
|
export const labelOf = (mate) => { const read = parseSoul(mate.soul); return read.ok ? subagentLabel(read.soul) : mate.handle; };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export const V176_ADDED_COLUMNS = Object.freeze({
|
|
2
|
+
subagent: { authority_generation: { definition: "INTEGER NOT NULL DEFAULT 0 CHECK (authority_generation >= 0)", saved: "0" }, codex_backup_model: { definition: "TEXT", saved: "NULL" } },
|
|
3
|
+
subagent_turn: {
|
|
4
|
+
provider: { definition: "TEXT NOT NULL DEFAULT 'claude' CHECK (provider IN ('claude','codex'))", saved: "'claude'" },
|
|
5
|
+
card_entry: { definition: "INTEGER", saved: "NULL" },
|
|
6
|
+
model_reported: { definition: "TEXT", saved: "NULL" },
|
|
7
|
+
backup_of: { definition: "INTEGER REFERENCES subagent_turn(id)", saved: "NULL" },
|
|
8
|
+
authority_generation: { definition: "INTEGER NOT NULL DEFAULT 0 CHECK (authority_generation >= 0)", saved: "0" },
|
|
9
|
+
counted_attempt: { definition: "INTEGER NOT NULL DEFAULT 0 CHECK (counted_attempt IN (0,1))", saved: "0" },
|
|
10
|
+
failure_kind: { definition: "TEXT CHECK (failure_kind IN ('usage-limit','unavailable'))", saved: "NULL" },
|
|
11
|
+
pending: { definition: "INTEGER NOT NULL DEFAULT 0 CHECK (pending IN (0,1))", saved: "0" },
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
export const V176_STEPS = Object.freeze(["subagent-backup-columns"]);
|
|
15
|
+
export const V176_SCHEMA = `
|
|
16
|
+
CREATE UNIQUE INDEX IF NOT EXISTS subagent_backup_once ON subagent_turn(backup_of) WHERE backup_of IS NOT NULL;
|
|
17
|
+
CREATE TRIGGER IF NOT EXISTS subagent_authority_changed AFTER UPDATE OF state, soul, model, codex_backup_model, daily_turns, manager ON subagent
|
|
18
|
+
WHEN NEW.state IS NOT OLD.state OR NEW.soul IS NOT OLD.soul OR NEW.model IS NOT OLD.model
|
|
19
|
+
OR NEW.codex_backup_model IS NOT OLD.codex_backup_model OR NEW.daily_turns IS NOT OLD.daily_turns OR NEW.manager IS NOT OLD.manager
|
|
20
|
+
BEGIN
|
|
21
|
+
UPDATE subagent SET authority_generation = OLD.authority_generation + 1 WHERE id = NEW.id;
|
|
22
|
+
END;
|
|
23
|
+
CREATE TRIGGER IF NOT EXISTS subagent_policy_changed AFTER UPDATE ON org_policy
|
|
24
|
+
BEGIN
|
|
25
|
+
UPDATE subagent SET authority_generation = authority_generation + 1;
|
|
26
|
+
END;
|
|
27
|
+
CREATE TRIGGER IF NOT EXISTS subagent_policy_inserted AFTER INSERT ON org_policy
|
|
28
|
+
BEGIN
|
|
29
|
+
UPDATE subagent SET authority_generation = authority_generation + 1;
|
|
30
|
+
END;
|
|
31
|
+
CREATE TRIGGER IF NOT EXISTS subagent_policy_removed AFTER DELETE ON org_policy
|
|
32
|
+
BEGIN
|
|
33
|
+
UPDATE subagent SET authority_generation = authority_generation + 1;
|
|
34
|
+
END;
|
|
35
|
+
`;
|
|
36
|
+
export const V176_OBJECTS = Object.freeze([...V176_SCHEMA.matchAll(/CREATE (UNIQUE INDEX|TRIGGER) IF NOT EXISTS (\w+)/g)].map(one => [one[1] === "UNIQUE INDEX" ? "index" : "trigger", one[2]]));
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import { claudeTurnRunner } from "./subagents.js";
|
|
3
|
+
import { TURN_MODEL_SCHEMA } from "./contracts/subagent-turn.js";
|
|
4
|
+
import { strictJsonParse } from "./converse.js";
|
|
5
|
+
import { performSubscriptionLeadRequest } from "./subscription-chat.js";
|
|
6
|
+
import { run } from "./exec.js";
|
|
7
|
+
import { ALL_CREDENTIAL_ENV } from "./provider.js";
|
|
8
|
+
import { claudeMachineBilling } from "./spend.js";
|
|
9
|
+
import { inEvalWorld } from "./eval-gate.js";
|
|
10
|
+
export async function subagentAttemptWithBackup(store, mate, card, request, runner = run, clock = () => new Date(), elapsedNow = () => performance.now()) {
|
|
11
|
+
const started = elapsedNow();
|
|
12
|
+
const remaining = () => Math.max(0, Math.min(request.timeoutMs, request.timeoutMs - (elapsedNow() - started)));
|
|
13
|
+
const failure = (said, provider = "claude", model = request.model) => ({ reply: { ok: false, said }, provider, model, backup: provider === "codex", authorize: () => said });
|
|
14
|
+
if (inEvalWorld())
|
|
15
|
+
return failure("Subagents don't run in an eval world.");
|
|
16
|
+
if (remaining() <= 0)
|
|
17
|
+
return failure("The original turn deadline elapsed.");
|
|
18
|
+
const originalFlow = store.getFlow(card.flow);
|
|
19
|
+
const flowRevision = request.flowRevision ?? originalFlow?.revision;
|
|
20
|
+
if (flowRevision === undefined)
|
|
21
|
+
return failure("The flow is no longer available.");
|
|
22
|
+
const freshnessProblem = (provider, model) => {
|
|
23
|
+
if (remaining() <= 0)
|
|
24
|
+
return "The original turn deadline elapsed before the answer could be used.";
|
|
25
|
+
const liveMate = store.getSubagent(mate.id), liveCard = store.getFlowCard(card.id), liveFlow = store.getFlow(card.flow);
|
|
26
|
+
if (liveMate?.state !== "active" || liveMate.authorityGeneration !== mate.authorityGeneration || liveCard?.state !== "active" || liveCard.entry !== card.entry || liveCard.stage !== card.stage || liveFlow?.revision !== flowRevision || liveFlow?.state !== "active")
|
|
27
|
+
return "The attempt's permission or card changed before its answer could be used.";
|
|
28
|
+
if (provider === "codex" && liveMate.codexBackupModel !== model)
|
|
29
|
+
return "The Codex backup's permission changed before its answer could be used.";
|
|
30
|
+
return store.agentPolicyRefusal(provider, model);
|
|
31
|
+
};
|
|
32
|
+
const primary = store.reserveSubagentAttempt({ subagent: mate.id, card: card.id, cardEntry: card.entry, stage: card.stage, authorityGeneration: mate.authorityGeneration, flowRevision, provider: "claude", model: request.model, billing: claudeMachineBilling(store.handle) }, clock());
|
|
33
|
+
if (!primary.ok)
|
|
34
|
+
return failure(primary.why);
|
|
35
|
+
let first;
|
|
36
|
+
try {
|
|
37
|
+
first = await claudeTurnRunner(runner)({ ...request, timeoutMs: remaining() });
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
first = { ok: false, said: "Claude's attempt stopped without a decision." };
|
|
41
|
+
}
|
|
42
|
+
const primaryProblem = freshnessProblem("claude", request.model);
|
|
43
|
+
if (first.ok && primaryProblem !== null)
|
|
44
|
+
first = { ...first, ok: false, said: primaryProblem };
|
|
45
|
+
store.settleSubagentAttempt(primary.id, { ...first, ms: elapsedNow() - started, ...(!first.ok && first.backupReason !== undefined ? { failureKind: first.backupReason } : {}) });
|
|
46
|
+
if (!first.ok && primaryProblem !== null)
|
|
47
|
+
return failure(primaryProblem);
|
|
48
|
+
if (first.ok || first.backupReason === undefined || remaining() <= 0)
|
|
49
|
+
return { reply: first, provider: "claude", model: request.model, backup: false, authorize: () => freshnessProblem("claude", request.model) };
|
|
50
|
+
let signedIn = false;
|
|
51
|
+
try {
|
|
52
|
+
const status = await runner("codex", ["login", "status"], { timeoutMs: Math.min(15_000, remaining()), maxBuffer: 65_536, omitEnv: ALL_CREDENTIAL_ENV, processGroup: true });
|
|
53
|
+
const said = `${status.stdout}\n${status.stderr}`;
|
|
54
|
+
signedIn = status.code === 0 && !status.timedOut && !status.notFound && /^Logged in using ChatGPT\s*$/m.test(said) && !/api key|bedrock/i.test(said);
|
|
55
|
+
}
|
|
56
|
+
catch { }
|
|
57
|
+
if (!signedIn || remaining() <= 0)
|
|
58
|
+
return failure(`${first.said} Codex backup needs a current ChatGPT sign-in.`);
|
|
59
|
+
const current = store.getSubagent(mate.id);
|
|
60
|
+
const model = current?.codexBackupModel;
|
|
61
|
+
if (model === null || model === undefined)
|
|
62
|
+
return failure(`${first.said} Codex backup is no longer enabled.`);
|
|
63
|
+
const backup = store.reserveSubagentAttempt({ subagent: mate.id, card: card.id, cardEntry: card.entry, stage: card.stage, authorityGeneration: mate.authorityGeneration, flowRevision, provider: "codex", model, billing: "subscription", backupOf: primary.id }, clock());
|
|
64
|
+
if (!backup.ok)
|
|
65
|
+
return failure(`${first.said} ${backup.why}`);
|
|
66
|
+
const began = elapsedNow();
|
|
67
|
+
let reply;
|
|
68
|
+
let modelReported = null;
|
|
69
|
+
try {
|
|
70
|
+
if (remaining() <= 0)
|
|
71
|
+
throw new Error("The original turn deadline elapsed.");
|
|
72
|
+
const answered = await performSubscriptionLeadRequest({ provider: "codex-subscription", model, system: "You decide one flow-card turn. Return exactly the supplied subagent decision schema. You have no native tools, repository or MCP access. The host validates any requested project-tool action separately.", dataDocument: request.prompt, history: [], tools: [], outputSchema: TURN_MODEL_SCHEMA, timeoutMs: remaining() }, runner);
|
|
73
|
+
if (!answered.ok)
|
|
74
|
+
reply = { ok: false, said: `Codex backup couldn't decide (${answered.problem}).` };
|
|
75
|
+
else {
|
|
76
|
+
modelReported = answered.answer.modelReported ?? null;
|
|
77
|
+
const parsed = strictJsonParse(Buffer.from(answered.answer.text, "utf8"), 65_536, 12);
|
|
78
|
+
const usage = { tokensIn: answered.answer.tokensIn, tokensOut: answered.answer.tokensOut,
|
|
79
|
+
...(answered.answer.reportedCostUsd == null ? {} : { costUsd: answered.answer.reportedCostUsd }) };
|
|
80
|
+
reply = parsed.ok ? { ok: true, value: parsed.value, ms: elapsedNow() - began, ...usage }
|
|
81
|
+
: { ok: false, said: "Codex backup's answer wasn't a decision.", ...usage };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
reply = { ok: false, said: "Codex backup stopped without a decision." };
|
|
86
|
+
}
|
|
87
|
+
const backupProblem = freshnessProblem("codex", model);
|
|
88
|
+
if (backupProblem !== null)
|
|
89
|
+
reply = { ...reply, ok: false, said: backupProblem };
|
|
90
|
+
store.settleSubagentAttempt(backup.id, { ...reply, ms: elapsedNow() - began, modelReported });
|
|
91
|
+
return { reply, provider: "codex", model: modelReported ?? model, backup: true, authorize: () => freshnessProblem("codex", model) };
|
|
92
|
+
}
|
package/dist/subagent-week.js
CHANGED
|
@@ -24,7 +24,7 @@ export function weekOf(store, mate, now, since = new Date(now.getTime() - WEEK_M
|
|
|
24
24
|
});
|
|
25
25
|
const moved = store.flowMovesOverridden(`${name} (AI)`, since).map(one => ({ said: `${one.by} moved “${one.title.slice(0, 80)}” after ${name} did`, at: one.at, href: flowCardHref(one.flow, one.card) }));
|
|
26
26
|
return {
|
|
27
|
-
since, turns: turns.length, failedTurns: turns.filter(one => !one.ok).length, costUsd: costs.length === 0 ? null : Math.round(costs.reduce((sum, one) => sum + one, 0) * 1e6) / 1e6,
|
|
27
|
+
since, turns: turns.length, pendingTurns: turns.filter(one => one.pending).length, failedTurns: turns.filter(one => !one.ok && !one.pending).length, costUsd: costs.length !== turns.length || costs.length === 0 ? null : Math.round(costs.reduce((sum, one) => sum + one, 0) * 1e6) / 1e6,
|
|
28
28
|
minutes: Math.round(turns.reduce((sum, one) => sum + one.ms, 0) / 60_000),
|
|
29
29
|
decided: count("decided"), handled: count("handled"), handed: count("handed"), asked: count("asked"),
|
|
30
30
|
calls: { made: calls.filter(one => one.state === "done" || one.state === "failed").length, approved: calls.filter(one => one.decidedBy !== null && one.state !== "denied" && one.state !== "refused").length,
|
|
@@ -41,7 +41,7 @@ export function weekWords(mate, week) {
|
|
|
41
41
|
const lines = [
|
|
42
42
|
`${name} decided ${week.decided}, handled ${week.handled}, handed ${week.handed} to people and asked ${week.asked} question${week.asked === 1 ? "" : "s"}.`,
|
|
43
43
|
`Tool calls: ${week.calls.made} made${week.calls.approved > 0 ? ` (${week.calls.approved} after a person approved)` : ""}${week.calls.denied > 0 ? `, ${week.calls.denied} turned down` : ""}${week.calls.refused > 0 ? `, ${week.calls.refused} outside its rules` : ""}${week.calls.undone > 0 ? `, ${week.calls.undone} undone` : ""}.`,
|
|
44
|
-
`${week.turns} turn${week.turns === 1 ? "" : "s"}${week.failedTurns > 0 ? ` (${week.failedTurns} failed)` : ""}, about ${week.minutes} minute${week.minutes === 1 ? "" : "s"} of thinking${week.costUsd === null ? "" : `, ${money(week.costUsd)} at API prices`}.`,
|
|
44
|
+
`${week.turns} turn${week.turns === 1 ? "" : "s"}${week.pendingTurns > 0 ? ` (${week.pendingTurns} unfinished)` : ""}${week.failedTurns > 0 ? ` (${week.failedTurns} failed)` : ""}, about ${week.minutes} minute${week.minutes === 1 ? "" : "s"} of thinking${week.costUsd === null ? "" : `, ${money(week.costUsd)} at API prices`}.`,
|
|
45
45
|
...(week.overrides.length === 0 ? ["Nobody overrode it."] : [`You overrode it ${week.overrides.length} time${week.overrides.length === 1 ? "" : "s"}:`, ...week.overrides.slice(0, 5).map(one => `• ${one.said}`)]),
|
|
46
46
|
];
|
|
47
47
|
return lines.join("\n");
|
package/dist/subagent-work.js
CHANGED
|
@@ -7,6 +7,7 @@ import { LIMITS } from "./decision.js";
|
|
|
7
7
|
import { callName, callOutcome, callWords, inputProblem, makeCall, offeredTools, refreshGrants, ruleFor } from "./subagent-tools.js";
|
|
8
8
|
import { ACCEPT, answerSuggestion, considerSuggestion, memoriesFor, remember } from "./subagent-memory.js";
|
|
9
9
|
import { replyToAsker } from "./subagent-desk.js";
|
|
10
|
+
import { subagentAttemptWithBackup } from "./subagent-backup.js";
|
|
10
11
|
import { claudeMachineBilling } from "./spend.js";
|
|
11
12
|
export const ASKED = "9999-12-31T00:00:00.000Z";
|
|
12
13
|
const CARRY_ON = "Carry on";
|
|
@@ -87,15 +88,18 @@ export async function subagentTurn(store, flow, definition, stage, card, mate, n
|
|
|
87
88
|
const tools = spent ? [] : offeredTools(store, mate);
|
|
88
89
|
const context = { ...contextOf(store, flow, definition, stage, card, mate, tools, spent && made > 0), ...(shorten === undefined ? {} : { shorten }) };
|
|
89
90
|
const asked = Date.now();
|
|
90
|
-
const
|
|
91
|
-
|
|
91
|
+
const attempt = io.turn === undefined && store.getSubagent(mate.id)?.codexBackupModel != null
|
|
92
|
+
? await subagentAttemptWithBackup(store, mate, card, { model, prompt: turnPrompt(context), timeoutMs: TURN_TIMEOUT_MS, flowRevision: flow.revision }) : null;
|
|
93
|
+
const reply = attempt?.reply ?? await (io.turn ?? claudeTurnRunner())({ model, prompt: turnPrompt(context), timeoutMs: TURN_TIMEOUT_MS });
|
|
94
|
+
if (attempt === null)
|
|
95
|
+
store.addSubagentTurn({ subagent: mate.id, card: card.id, model, ok: reply.ok, ms: reply.ok ? reply.ms : Date.now() - asked, costUsd: reply.costUsd ?? null, tokensIn: reply.tokensIn ?? null, tokensOut: reply.tokensOut ?? null }, now);
|
|
92
96
|
if (!reply.ok)
|
|
93
97
|
return { state: "retry", said: reply.said, ...(log.length === 0 ? {} : { log: log.join("\n\n") }) };
|
|
94
98
|
const read = readTurn(reply.value, context);
|
|
95
99
|
if (!read.ok)
|
|
96
100
|
return { state: "retry", said: `${context.name}'s answer wasn't one this zone allows.`, log: [...log, read.issues.map(issue => issue.line).join("\n"), JSON.stringify(reply.value).slice(0, 4000)].join("\n\n") };
|
|
97
101
|
const answer = read.value;
|
|
98
|
-
const header = `${context.name} (${model}) · ${(reply.ms / 1000).toFixed(1)} s`;
|
|
102
|
+
const header = `${context.name} (${attempt?.backup ? `Codex backup · ${attempt.model}` : model}) · ${(reply.ms / 1000).toFixed(1)} s`;
|
|
99
103
|
const over = turnOverruns(answer);
|
|
100
104
|
if (over.length > 0 && !shortened) {
|
|
101
105
|
shortened = true;
|
|
@@ -105,60 +109,79 @@ export async function subagentTurn(store, flow, definition, stage, card, mate, n
|
|
|
105
109
|
continue;
|
|
106
110
|
}
|
|
107
111
|
shorten = undefined;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
+
const accepted = store.transact(() => {
|
|
113
|
+
const problem = attempt?.authorize();
|
|
114
|
+
if (problem != null)
|
|
115
|
+
return { refused: { state: "retry", said: problem } };
|
|
116
|
+
if (answer.remember !== "")
|
|
117
|
+
remember(store, mate, answer.remember, { source: "subagent", card: card.id, by: subagentActor({ name: context.name }) }, now);
|
|
118
|
+
return answer.action === "use_tool" ? {} : { outcome: carryOut(store, flow, definition, stage, card, mate, context, answer, now, io, header) };
|
|
119
|
+
});
|
|
120
|
+
if (accepted.refused !== undefined)
|
|
121
|
+
return accepted.refused;
|
|
122
|
+
if (accepted.outcome !== undefined) {
|
|
123
|
+
const outcome = accepted.outcome;
|
|
112
124
|
return log.length === 0 ? outcome : { ...outcome, log: `${log.join("\n\n")}\n\n${outcome.log ?? ""}`.trim() };
|
|
113
125
|
}
|
|
114
126
|
log.push(`${header}\n\n${JSON.stringify(answer)}`);
|
|
115
|
-
const waiting = await useTool(store, flow, stage, card, mate, context, answer, io, now);
|
|
127
|
+
const waiting = await useTool(store, flow, stage, card, mate, context, answer, io, now, attempt?.authorize);
|
|
116
128
|
if (waiting !== null)
|
|
117
129
|
return { ...waiting, log: log.join("\n\n") };
|
|
118
130
|
}
|
|
119
131
|
}
|
|
120
|
-
async function useTool(store, flow, stage, card, mate, context, answer, io, now) {
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
132
|
+
async function useTool(store, flow, stage, card, mate, context, answer, io, now, authorize) {
|
|
133
|
+
const prepared = store.transact(() => {
|
|
134
|
+
const authorityProblem = authorize?.();
|
|
135
|
+
if (authorityProblem != null)
|
|
136
|
+
return { outcome: { state: "retry", said: authorityProblem } };
|
|
137
|
+
const split = answer.tool.indexOf(".");
|
|
138
|
+
const tool = split < 0 ? answer.tool : answer.tool.slice(0, split), action = split < 0 ? "" : answer.tool.slice(split + 1);
|
|
139
|
+
const receipt = { subagent: mate.id, card: card.id, entry: card.entry, tool: tool.slice(0, 40), action: action.slice(0, 64) || "(none)", why: answer.reason };
|
|
140
|
+
const refuse = (input, said) => { store.addSubagentCall({ ...receipt, input, rule: "never", state: "refused", result: said }, now); return { outcome: null }; };
|
|
141
|
+
if (!(context.tools ?? []).some(one => one.name === answer.tool))
|
|
142
|
+
return refuse({}, `There's no ${answer.tool} among the tools you may use.`);
|
|
143
|
+
let input;
|
|
144
|
+
try {
|
|
145
|
+
const parsed = JSON.parse(answer.input === "" ? "{}" : answer.input);
|
|
146
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
|
|
147
|
+
return refuse({}, "Its input wasn't a JSON object.");
|
|
148
|
+
input = parsed;
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
131
151
|
return refuse({}, "Its input wasn't a JSON object.");
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
152
|
+
}
|
|
153
|
+
const grant = store.subagentGrant(mate.id, tool);
|
|
154
|
+
const info = grant?.actions.find(one => one.name === action);
|
|
155
|
+
if (grant === null || info === undefined)
|
|
156
|
+
return refuse(input, "This tool action is no longer available.");
|
|
157
|
+
const problem = inputProblem(info, input);
|
|
158
|
+
if (problem !== null)
|
|
159
|
+
return refuse(input, problem);
|
|
160
|
+
const rule = ruleFor(grant, action, input);
|
|
161
|
+
if (rule.use === "never")
|
|
162
|
+
return refuse(input, rule.why);
|
|
163
|
+
if (rule.use === "free") {
|
|
164
|
+
const id = store.addSubagentCall({ ...receipt, input, rule: "free", state: "running" }, now);
|
|
165
|
+
return { call: id };
|
|
166
|
+
}
|
|
167
|
+
const soul = { name: context.name, role: context.role };
|
|
168
|
+
const id = store.addSubagentCall({ ...receipt, input, rule: "ask", state: "asked", result: rule.why }, now);
|
|
169
|
+
const words = callWords(tool, action, input, 480);
|
|
170
|
+
const question = store.openSubagentQuestion({ subagent: mate.id, card: card.id, entry: card.entry, question: `Use ${words}?`, options: [{ id: APPROVE, label: "Approve" }, { id: DENY, label: "Deny" }], askedOf: context.person, toolCall: id }, now);
|
|
171
|
+
if (question === null)
|
|
172
|
+
return { outcome: { state: "failed", said: "It asked to make the same call twice." } };
|
|
173
|
+
notifyPeople(store, card, [context.person], null, { key: `teammate-q:${question}`, attention: true, subject: `${subagentLabel(soul)} asks to use ${action} on “${card.title}”`,
|
|
174
|
+
body: `${words}\n\n${answer.reason === "" ? "" : `Why: ${answer.reason}\n`}(${rule.why})\n\nApprove makes exactly this call. Deny stops it. Or answer in words to tell ${context.name} what to do instead.`,
|
|
175
|
+
}, now);
|
|
176
|
+
if (stage.kind !== "approval")
|
|
177
|
+
store.updateFlowCard(card.id, { waiting: `${context.name} asked ${context.person} to approve: ${words}`.slice(0, 300) }, now);
|
|
178
|
+
return { outcome: { state: "waiting", said: `Asked ${context.person} to approve ${action}`, nextAt: ASKED } };
|
|
179
|
+
});
|
|
180
|
+
if ("call" in prepared) {
|
|
181
|
+
await makeCall(store, store.subagentCall(prepared.call), flow.repo, io, now);
|
|
148
182
|
return null;
|
|
149
183
|
}
|
|
150
|
-
|
|
151
|
-
const id = store.addSubagentCall({ ...receipt, input, rule: "ask", state: "asked", result: rule.why }, now);
|
|
152
|
-
const words = callWords(tool, action, input, 480);
|
|
153
|
-
const question = store.openSubagentQuestion({ subagent: mate.id, card: card.id, entry: card.entry, question: `Use ${words}?`, options: [{ id: APPROVE, label: "Approve" }, { id: DENY, label: "Deny" }], askedOf: context.person, toolCall: id }, now);
|
|
154
|
-
if (question === null)
|
|
155
|
-
return { state: "failed", said: "It asked to make the same call twice." };
|
|
156
|
-
notifyPeople(store, card, [context.person], null, { key: `teammate-q:${question}`, attention: true, subject: `${subagentLabel(soul)} asks to use ${action} on “${card.title}”`,
|
|
157
|
-
body: `${words}\n\n${answer.reason === "" ? "" : `Why: ${answer.reason}\n`}(${rule.why})\n\nApprove makes exactly this call. Deny stops it. Or answer in words to tell ${context.name} what to do instead.`,
|
|
158
|
-
}, now);
|
|
159
|
-
if (stage.kind !== "approval")
|
|
160
|
-
store.updateFlowCard(card.id, { waiting: `${context.name} asked ${context.person} to approve: ${words}`.slice(0, 300) }, now);
|
|
161
|
-
return { state: "waiting", said: `Asked ${context.person} to approve ${action}`, nextAt: ASKED };
|
|
184
|
+
return prepared.outcome;
|
|
162
185
|
}
|
|
163
186
|
function keptWhole(store, flow, card, author, text, limit, holds, what, now) {
|
|
164
187
|
const kept = passOn(text, limit, { label: "the card's discussion", href: flowCardHref(flow.id, card.id) }, holds);
|
package/dist/subagents-ui.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { field, input, btn } from "./server/kit.js";
|
|
1
2
|
import { labelOf, nameOf, summaryOf, SUBAGENT_MODELS, zonesOf } from "./subagent-admin.js";
|
|
2
3
|
import { SUBAGENT_TEMPLATES } from "./subagents.js";
|
|
3
4
|
import { projectToolsOf } from "./project-tools.js";
|
|
@@ -122,6 +123,9 @@ export function subagentPageHtml(store, mate, viewer, projectName, canManage, ap
|
|
|
122
123
|
const soul = html `<details class="card"${canManage && html ` open`}><summary>Soul file</summary><p class="meta">Who ${name} is and its rules, read every turn. Version ${mate.version}${latest !== undefined && ` · saved by ${latest.savedBy}, ${when(latest.savedAt)}`} · <a href="/settings/lead/subagents/${mate.id}/soul.md" download>Download</a></p>${canManage
|
|
123
124
|
? postForm(`/settings/lead/subagents/${mate.id}/soul`, html `<label class="sr-only" for="subagent-soul">Soul file</label><textarea id="subagent-soul" name="soul" rows="24" class="mono" maxlength="12000" spellcheck="false">${notice.soulDraft ?? mate.soul}</textarea><button>Save</button>`, { attrs: { "data-soul-form": true } })
|
|
124
125
|
: html `<pre class="mono">${mate.soul}</pre>`}</details>`;
|
|
125
|
-
const
|
|
126
|
-
|
|
126
|
+
const backupProblem = notice.problem?.includes("Codex backup") === true;
|
|
127
|
+
const backupPasswordProblem = backupProblem && notice.problem?.startsWith("Enter your Toolroll password") === true;
|
|
128
|
+
const backup = html `<input type="hidden" name="backupPresent" value="1"><details class="k-disclose" id="backup"${(backupProblem || mate.codexBackupModel !== null) && html ` open`}><summary>Codex backup · ${mate.codexBackupModel === null ? "Off" : "On"}</summary><p class="meta">When Claude hits its limit or isn't installed, send this teammate's card, memory and tool results to Codex through your ChatGPT sign-in. Tool approvals stay the same.</p>${field({ id: "subagent-backup-model", label: "Codex model", hint: "Leave blank to turn off. Each Claude or Codex attempt counts toward the daily limit.", error: backupProblem && !backupPasswordProblem ? notice.problem ?? null : null, control: input({ id: "subagent-backup-model", name: "codexBackupModel", value: notice.backupDraft ?? mate.codexBackupModel ?? "", hint: true, error: backupProblem && !backupPasswordProblem, attrs: { autocomplete: "off", spellcheck: "false" } }) })}${reauth(field({ id: "subagent-backup-password", label: "Password to enable or change backup", error: backupPasswordProblem ? notice.problem ?? null : null, control: input({ id: "subagent-backup-password", name: "password", type: "password", error: backupPasswordProblem, attrs: { autocomplete: "current-password" } }) }))}</details>`;
|
|
129
|
+
const settings = canManage && html `<details class="card"${backupProblem && html ` open`}><summary>Settings</summary>${postForm(`/settings/lead/subagents/${mate.id}/settings`, html `<label>Model<select name="model">${SUBAGENT_MODELS.map(one => html `<option value="${one}"${(mate.model ?? "default") === one && html ` selected`}>${one === "default" ? "The lead chat's model" : one[0].toUpperCase() + one.slice(1)}</option>`)}</select></label><label>Turns a day, at most<input type="number" name="dailyTurns" min="1" max="2000" value="${mate.dailyTurns}"></label><label>Reports to<select name="manager">${[...new Set([mate.manager, ...approvers])].map(one => html `<option value="${one}"${one === mate.manager && html ` selected`}>${one}</option>`)}</select></label>${backup}${btn("Save settings", { type: "submit" })}`)}${postForm(`/settings/lead/subagents/${mate.id}/state`, html `<button class="danger">Remove ${name} from the team</button>`, { attrs: { class: "danger-zone mt-3" }, hidden: { state: "removed" } })}</details>`;
|
|
130
|
+
return html `${notice.problem && !backupProblem && html `<p class="problem" role="alert">${notice.problem}</p>`}${notice.said && html `<p class="said" role="status">${notice.said}</p>`}<p class="meta">${projectName(mate.repo)} · ${mate.state === "active" ? "Working" : "Paused: its decisions go to people"} · reports to ${mate.manager}</p>${manage}${questions.length > 0 && html `<section><h2>Questions</h2>${asked}</section>`}<section class="card"><h2>Today</h2><p class="subagent-summary">${lines(summaryOf(store, mate, startOfDay()).said)}</p></section>${weekSection(store, mate, canManage)}<section class="card"><h2>Works on</h2>${where}</section>${toolsSection(store, mate, canManage)}${deskSection(store, mate, canManage)}${memorySection(store, mate, canManage, notice.query ?? null)}${soul}<details class="card"><summary>What ${name} did</summary>${activity}</details>${settings}`;
|
|
127
131
|
}
|
package/dist/subagents.js
CHANGED
|
@@ -189,13 +189,16 @@ export function claudeTurnRunner(runner = run) {
|
|
|
189
189
|
"-p", "--output-format", "json", "--json-schema", JSON.stringify(TURN_MODEL_SCHEMA), ...CLAUDE_NO_TOOLS_ARGS, ...claudeModelArgs(request.model),
|
|
190
190
|
], { cwd: dir, stdin: request.prompt, timeoutMs: request.timeoutMs, maxBuffer: 512 * 1024, omitEnv: ALL_CREDENTIAL_ENV, processGroup: true });
|
|
191
191
|
if (result.notFound)
|
|
192
|
-
return { ok: false, said: "Claude isn't installed on this computer." };
|
|
192
|
+
return { ok: false, said: "Claude isn't installed on this computer.", backupReason: "unavailable" };
|
|
193
193
|
if (result.timedOut)
|
|
194
194
|
return { ok: false, said: "Claude took too long to decide." };
|
|
195
195
|
const body = claudeJsonBody(result.stdout, 512 * 1024);
|
|
196
196
|
if (result.code !== 0 || body === null || body["is_error"] === true || body["subtype"] !== "success") {
|
|
197
197
|
const why = typeof body?.["subtype"] === "string" && body["subtype"] !== "success" ? ` (${String(body["subtype"]).replace(/_/g, " ").slice(0, 60)})` : result.code !== 0 ? ` (exit ${result.code})` : "";
|
|
198
|
-
|
|
198
|
+
const backupReason = result.code !== 0 && body?.["type"] === "result" && body["is_error"] === true
|
|
199
|
+
&& body["api_error_status"] === 429 && ["usage_limit_reached", "rate_limit_error"].includes(String(body["api_error"])) ? "usage-limit" : undefined;
|
|
200
|
+
return { ok: false, said: backupReason === "usage-limit" ? "Claude reached its usage limit." : CLAUDE_SIGNED_OUT.test(`${result.stdout}${result.stderr}`) ? "Claude isn't signed in on this computer." : `Claude couldn't decide${why}.`,
|
|
201
|
+
...costOf(body ?? {}), ...(backupReason === undefined ? {} : { backupReason }) };
|
|
199
202
|
}
|
|
200
203
|
const cost = costOf(body);
|
|
201
204
|
if (body["structured_output"] !== undefined && body["structured_output"] !== null)
|
|
@@ -38,6 +38,11 @@ function outputSchema(tools) {
|
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
export function composeSubscriptionLeadPrompt(request) {
|
|
41
|
+
const sanitizedHistory = request.history.map(one => (one.role === "operator" && "images" in one ? { role: one.role, text: one.text } : one));
|
|
42
|
+
if (request.outputSchema !== undefined)
|
|
43
|
+
return [request.system,
|
|
44
|
+
"STRUCTURED RESPONSE PROTOCOL: Return only the JSON object required by the supplied output schema. Do not use any harness tools or inspect the computer. DATA and CONVERSATION below are the only context.",
|
|
45
|
+
`DATA:\n${request.dataDocument}`, `CONVERSATION:\n${JSON.stringify(sanitizedHistory)}`].join("\n\n");
|
|
41
46
|
return [
|
|
42
47
|
request.system,
|
|
43
48
|
"SUBSCRIPTION HARNESS PROTOCOL:",
|
|
@@ -47,7 +52,7 @@ export function composeSubscriptionLeadPrompt(request) {
|
|
|
47
52
|
"The host validates and runs those calls, then gives you another step. When finished, return a non-empty text and an empty calls array.",
|
|
48
53
|
`AVAILABLE HOST TOOLS:\n${JSON.stringify(request.tools)}`,
|
|
49
54
|
`DATA:\n${request.dataDocument}`,
|
|
50
|
-
`CONVERSATION:\n${JSON.stringify(
|
|
55
|
+
`CONVERSATION:\n${JSON.stringify(sanitizedHistory)}`,
|
|
51
56
|
].join("\n\n");
|
|
52
57
|
}
|
|
53
58
|
function exactKeys(value, keys) {
|
|
@@ -189,17 +194,28 @@ export async function performSubscriptionLeadRequest(request, runner = run) {
|
|
|
189
194
|
const dir = mkdtempSync(join(tmpdir(), "standing-orders-mate-"));
|
|
190
195
|
try {
|
|
191
196
|
const prompt = composeSubscriptionLeadPrompt(request);
|
|
192
|
-
const
|
|
197
|
+
const images = request.images ?? [];
|
|
198
|
+
const hasImages = images.length > 0;
|
|
199
|
+
const streaming = request.provider !== "codex-subscription" && (request.onText !== undefined || hasImages);
|
|
193
200
|
const schema = request.outputSchema ?? outputSchema(request.tools);
|
|
194
201
|
let command;
|
|
195
202
|
let args;
|
|
203
|
+
let stdinPayload = prompt;
|
|
196
204
|
if (request.provider === "codex-subscription") {
|
|
197
205
|
const schemaFile = join(dir, "response-schema.json");
|
|
198
206
|
writeFileSync(schemaFile, JSON.stringify(schema), { mode: 0o600 });
|
|
207
|
+
const imageArgs = [];
|
|
208
|
+
for (const [idx, img] of images.entries()) {
|
|
209
|
+
const ext = img.mediaType === "image/jpeg" ? "jpg" : img.mediaType === "image/webp" ? "webp" : img.mediaType === "image/gif" ? "gif" : "png";
|
|
210
|
+
const filePath = join(dir, `user-image-${idx + 1}.${ext}`);
|
|
211
|
+
writeFileSync(filePath, Buffer.from(img.dataBase64, "base64"), { mode: 0o600 });
|
|
212
|
+
imageArgs.push("--image", filePath);
|
|
213
|
+
}
|
|
199
214
|
command = "codex";
|
|
200
215
|
args = [
|
|
201
216
|
"exec", "--json", "--ephemeral", "--ignore-user-config", "--ignore-rules", "--skip-git-repo-check",
|
|
202
217
|
"--sandbox", "read-only", "--output-schema", schemaFile,
|
|
218
|
+
...imageArgs,
|
|
203
219
|
"-c", 'approval_policy="never"', "-c", 'web_search="disabled"',
|
|
204
220
|
"-c", "features.shell_tool=false", "-c", "features.unified_exec=false",
|
|
205
221
|
"-c", "features.multi_agent=false", "-c", "features.skill_mcp_dependency_install=false",
|
|
@@ -211,19 +227,34 @@ export async function performSubscriptionLeadRequest(request, runner = run) {
|
|
|
211
227
|
else {
|
|
212
228
|
command = "claude";
|
|
213
229
|
args = [
|
|
214
|
-
"-p",
|
|
230
|
+
"-p",
|
|
231
|
+
...(hasImages ? ["--input-format", "stream-json"] : []),
|
|
232
|
+
...(streaming ? ["--output-format", "stream-json", "--verbose", ...(request.onText !== undefined ? ["--include-partial-messages"] : [])] : ["--output-format", "json"]),
|
|
233
|
+
"--json-schema", JSON.stringify(schema),
|
|
215
234
|
...CLAUDE_NO_TOOLS_ARGS, ...claudeModelArgs(request.model),
|
|
216
235
|
];
|
|
236
|
+
if (hasImages) {
|
|
237
|
+
stdinPayload = `${JSON.stringify({
|
|
238
|
+
type: "user",
|
|
239
|
+
message: {
|
|
240
|
+
role: "user",
|
|
241
|
+
content: [
|
|
242
|
+
...images.map(img => ({ type: "image", source: { type: "base64", media_type: img.mediaType, data: img.dataBase64 } })),
|
|
243
|
+
{ type: "text", text: prompt },
|
|
244
|
+
],
|
|
245
|
+
},
|
|
246
|
+
})}\n`;
|
|
247
|
+
}
|
|
217
248
|
}
|
|
218
249
|
const result = await runner(command, args, {
|
|
219
250
|
cwd: dir,
|
|
220
|
-
stdin:
|
|
251
|
+
stdin: stdinPayload,
|
|
221
252
|
timeoutMs: request.timeoutMs,
|
|
222
253
|
...(request.signal === undefined ? {} : { signal: request.signal }),
|
|
223
254
|
maxBuffer: streaming ? RESPONSE_CAP_BYTES * 16 : RESPONSE_CAP_BYTES,
|
|
224
255
|
omitEnv: ALL_CREDENTIAL_ENV,
|
|
225
256
|
processGroup: true,
|
|
226
|
-
...(streaming ? { onStdout: claudeStreamReader(request.onText) } : {}),
|
|
257
|
+
...(request.onText !== undefined && streaming ? { onStdout: claudeStreamReader(request.onText) } : {}),
|
|
227
258
|
});
|
|
228
259
|
if (result.timedOut)
|
|
229
260
|
return { ok: false, problem: "timeout", quiet: result.stdout.trim() === "" };
|