@sema-agent/core 7.72.0 → 7.73.0
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 +319 -0
- package/dist/agents/inherited-tool-pool.d.ts +26 -1
- package/dist/agents/inherited-tool-pool.js +46 -2
- package/dist/agents/parked-resume-drive.d.ts +10 -0
- package/dist/agents/parked-resume-drive.js +9 -0
- package/dist/agents/retain-ledger.d.ts +3 -0
- package/dist/agents/send-message-tool.js +1 -0
- package/dist/agents/send-user-message-tool.d.ts +12 -0
- package/dist/agents/send-user-message-tool.js +67 -0
- package/dist/agents/subagent-steps.d.ts +9 -0
- package/dist/agents/subagent-steps.js +38 -0
- package/dist/agents/subagent.d.ts +2 -0
- package/dist/agents/subagent.js +43 -12
- package/dist/agents/verify.js +23 -8
- package/dist/agents/yield-adoption.js +3 -1
- package/dist/brain/anthropic.js +14 -9
- package/dist/brain/open-responses.js +4 -5
- package/dist/brain/openai.js +30 -23
- package/dist/brain/stream-engine.js +159 -151
- package/dist/core/actions-digest.d.ts +43 -0
- package/dist/core/actions-digest.js +22 -0
- package/dist/core/allow-entry.js +3 -3
- package/dist/core/auto-mode.d.ts +7 -9
- package/dist/core/auto-mode.js +114 -8
- package/dist/core/checkpoint-features.d.ts +3 -2
- package/dist/core/checkpoint-features.js +1 -1
- package/dist/core/checkpoint-rekey.d.ts +1 -1
- package/dist/core/checkpoint-rekey.js +6 -1
- package/dist/core/checkpoint-requirements.d.ts +23 -3
- package/dist/core/checkpoint-requirements.js +5 -1
- package/dist/core/checkpoint-row-verdict.js +7 -1
- package/dist/core/checkpoint-store.d.ts +24 -2
- package/dist/core/checkpoint-store.js +1 -0
- package/dist/core/child-clamp-seats.d.ts +15 -0
- package/dist/core/child-clamp-seats.js +15 -0
- package/dist/core/delegation-frames.d.ts +1 -0
- package/dist/core/delegation-frames.js +1 -1
- package/dist/core/engine-capabilities.d.ts +5 -1
- package/dist/core/engine-capabilities.js +1 -1
- package/dist/core/engine-notice.d.ts +30 -22
- package/dist/core/engine-version.js +1 -1
- package/dist/core/entries-not-applied.d.ts +19 -7
- package/dist/core/entries-not-applied.js +33 -1
- package/dist/core/governance-codes.d.ts +7 -1
- package/dist/core/governance-codes.js +13 -5
- package/dist/core/hooks.d.ts +3 -0
- package/dist/core/hooks.js +1 -0
- package/dist/core/host-instance.d.ts +23 -0
- package/dist/core/host-instance.js +69 -0
- package/dist/core/instruction-preview.d.ts +63 -0
- package/dist/core/instruction-preview.js +406 -0
- package/dist/core/leg-budget.d.ts +26 -0
- package/dist/core/leg-budget.js +9 -0
- package/dist/core/leg-identity.d.ts +51 -1
- package/dist/core/leg-identity.js +45 -2
- package/dist/core/manager-launch-check.d.ts +48 -0
- package/dist/core/manager-launch-check.js +64 -0
- package/dist/core/mcp-call-meta.d.ts +2 -2
- package/dist/core/mcp-injection-drop.d.ts +20 -10
- package/dist/core/mcp-injection-drop.js +9 -3
- package/dist/core/mcp-server-spec.d.ts +2 -1
- package/dist/core/member-outcome.d.ts +3 -2
- package/dist/core/member-outcome.js +1 -1
- package/dist/core/memory-engine/deletion-record.d.ts +46 -0
- package/dist/core/memory-engine/deletion-record.js +96 -0
- package/dist/core/memory-engine/engine.js +24 -16
- package/dist/core/memory-engine/file-backend.js +7 -5
- package/dist/core/memory-engine/projection-ledger.d.ts +1 -1
- package/dist/core/memory-engine/projection-ledger.js +1 -1
- package/dist/core/memory-engine/scope-contract.d.ts +18 -13
- package/dist/core/memory-engine/scope-contract.js +18 -18
- package/dist/core/memory-engine/sync-client.js +26 -6
- package/dist/core/memory-engine/sync.d.ts +20 -2
- package/dist/core/memory-engine/sync.js +18 -17
- package/dist/core/mode-policy.d.ts +21 -6
- package/dist/core/mode-policy.js +15 -6
- package/dist/core/own-property-receipt.js +11 -4
- package/dist/core/parent-spec-seat.d.ts +13 -11
- package/dist/core/parent-spec-seat.js +13 -9
- package/dist/core/peer-seat.js +3 -3
- package/dist/core/peer-task-store.d.ts +365 -0
- package/dist/core/peer-task-store.js +682 -0
- package/dist/core/permission-rule-consent.js +6 -11
- package/dist/core/permission-rule-model.d.ts +27 -0
- package/dist/core/permission-rule-model.js +33 -5
- package/dist/core/permission-rule-provider.d.ts +35 -33
- package/dist/core/permission-rule-provider.js +38 -295
- package/dist/core/permission-rule-store.d.ts +181 -8
- package/dist/core/permission-rule-store.js +420 -17
- package/dist/core/permission-rule-sync.js +15 -1
- package/dist/core/project-seat.d.ts +55 -0
- package/dist/core/project-seat.js +96 -0
- package/dist/core/protocol-http-auth.d.ts +3 -2
- package/dist/core/protocol-http-auth.js +26 -18
- package/dist/core/remote-env.d.ts +4 -4
- package/dist/core/retired-keys.js +1 -0
- package/dist/core/rule-offer-read.d.ts +1 -1
- package/dist/core/rule-offer-read.js +32 -4
- package/dist/core/run-ledger-seat.d.ts +66 -0
- package/dist/core/run-ledger-seat.js +70 -0
- package/dist/core/run-ledger.d.ts +332 -0
- package/dist/core/run-ledger.js +550 -0
- package/dist/core/runner/checkpoint-scope.d.ts +13 -3
- package/dist/core/runner/checkpoint-scope.js +12 -4
- package/dist/core/runner/construction-doors.js +6 -0
- package/dist/core/runner/contracts.d.ts +21 -5
- package/dist/core/runner/delegation-owner.d.ts +30 -0
- package/dist/core/runner/delegation-owner.js +20 -4
- package/dist/core/runner/finish-reason-seat.js +4 -2
- package/dist/core/runner/leg-frame.js +3 -0
- package/dist/core/runner/nested-memory-lane.d.ts +22 -5
- package/dist/core/runner/nested-memory-lane.js +91 -30
- package/dist/core/runner/person-path-rows.d.ts +21 -16
- package/dist/core/runner/person-path-rows.js +80 -15
- package/dist/core/runner/prepare-caps-and-workflow.js +98 -88
- package/dist/core/runner/prepare-config-doors.d.ts +1 -0
- package/dist/core/runner/prepare-config-doors.js +5 -3
- package/dist/core/runner/prepare-context-lane.js +1 -0
- package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
- package/dist/core/runner/prepare-delegation-surface.js +6 -0
- package/dist/core/runner/prepare-execution-env.d.ts +3 -3
- package/dist/core/runner/prepare-hands-readface.d.ts +5 -2
- package/dist/core/runner/prepare-hands-readface.js +12 -1
- package/dist/core/runner/prepare-inherited-gate.d.ts +6 -3
- package/dist/core/runner/prepare-inherited-gate.js +13 -5
- package/dist/core/runner/prepare-run-refs.d.ts +1 -1
- package/dist/core/runner/prepare-run-refs.js +3 -2
- package/dist/core/runner/prepare-suspend-saga.d.ts +6 -2
- package/dist/core/runner/prepare-suspend-saga.js +4 -2
- package/dist/core/runner/prepare-task.js +36 -27
- package/dist/core/runner/prepare-turn-wiring.d.ts +4 -3
- package/dist/core/runner/prepare-turn-wiring.js +2 -1
- package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -1
- package/dist/core/runner/prepare-wiring-manifest.js +5 -2
- package/dist/core/runner/resume-apply.js +11 -5
- package/dist/core/runner/resume-review-outcome.d.ts +3 -0
- package/dist/core/runner/resume-review-outcome.js +24 -1
- package/dist/core/runner/run-harness-handlers.js +3 -0
- package/dist/core/runner/run-identity-wiring.js +3 -2
- package/dist/core/runner/run-leg.js +3 -0
- package/dist/core/runner/run-notification-lane.js +20 -1
- package/dist/core/runner/run-settle-and-teardown.js +21 -12
- package/dist/core/runner/run-stop-and-final-verify.js +6 -0
- package/dist/core/runner/run-telemetry-and-budget-seats.js +1 -1
- package/dist/core/runner/runtask.d.ts +6 -2
- package/dist/core/runner/runtask.js +21 -9
- package/dist/core/runner/shell-env-withheld.d.ts +3 -2
- package/dist/core/runner/shell-env-withheld.js +1 -2
- package/dist/core/runner/stop-tail-notice.d.ts +10 -2
- package/dist/core/runner/stop-tail-notice.js +9 -2
- package/dist/core/runner/stream-settle-backstop.d.ts +1 -0
- package/dist/core/runner/stream-settle-backstop.js +1 -0
- package/dist/core/runner/task-start-doors.js +6 -3
- package/dist/core/runner/terminal-account.d.ts +6 -1
- package/dist/core/runner/terminal-account.js +16 -1
- package/dist/core/runner/unreadable-person-rows.d.ts +2 -1
- package/dist/core/runner-deps.d.ts +13 -10
- package/dist/core/secret-env.d.ts +53 -37
- package/dist/core/secret-env.js +44 -47
- package/dist/core/session-checkout.d.ts +3 -0
- package/dist/core/session-checkout.js +1 -0
- package/dist/core/session-store.d.ts +12 -6
- package/dist/core/session-store.js +26 -6
- package/dist/core/session.d.ts +31 -8
- package/dist/core/store-contracts/checkpoint-store-contract.js +10 -0
- package/dist/core/store-contracts/peer-task-store-contract.d.ts +21 -0
- package/dist/core/store-contracts/peer-task-store-contract.js +516 -0
- package/dist/core/store-contracts/session-store-contract.d.ts +15 -2
- package/dist/core/store-contracts/session-store-contract.js +87 -3
- package/dist/core/store-contracts/workflow-journal-store-contract.d.ts +19 -1
- package/dist/core/store-contracts/workflow-journal-store-contract.js +89 -1
- package/dist/core/task-event.d.ts +10 -3
- package/dist/core/task-notification.d.ts +96 -10
- package/dist/core/task-notification.js +129 -5
- package/dist/core/task-registry-shared.d.ts +12 -1
- package/dist/core/task-registry-shared.js +3 -1
- package/dist/core/task-registry-workflow.d.ts +1 -1
- package/dist/core/task-registry-workflow.js +9 -1
- package/dist/core/task-registry.d.ts +39 -2
- package/dist/core/task-registry.js +76 -12
- package/dist/core/task-result.d.ts +13 -0
- package/dist/core/task-spec-members.d.ts +3 -1
- package/dist/core/task-spec-members.js +11 -3
- package/dist/core/task-spec.d.ts +48 -22
- package/dist/core/tool-catalog-entries.js +2 -0
- package/dist/core/tool-mount-facts.d.ts +1 -1
- package/dist/core/tool-mount-facts.js +1 -0
- package/dist/core/tool-mount-plan.d.ts +3 -1
- package/dist/core/tool-mount-plan.js +6 -0
- package/dist/core/tool-mount-static.d.ts +1 -1
- package/dist/core/tool-mount-static.js +4 -2
- package/dist/core/tool-result-store.d.ts +19 -2
- package/dist/core/tool-result-store.js +51 -2
- package/dist/core/tool-spec.d.ts +9 -2
- package/dist/core/user-attachment.d.ts +5 -1
- package/dist/core/user-attachment.js +14 -7
- package/dist/core/wiring-manifest.d.ts +26 -20
- package/dist/core/wiring-manifest.js +7 -3
- package/dist/core/workflow-journal-store.d.ts +53 -10
- package/dist/core/workflow-journal-store.js +27 -4
- package/dist/core/workflow-run-store-contract.js +16 -0
- package/dist/core/workflow-run-store.d.ts +9 -7
- package/dist/core/workflow-run-store.js +4 -1
- package/dist/engine/execution-env/node-execution-env.js +3 -1
- package/dist/engine/harness/types.d.ts +24 -1
- package/dist/engine/harness/types.js +10 -0
- package/dist/engine/llm/types.d.ts +5 -7
- package/dist/engine/lsp/node-lsp-manager.js +2 -1
- package/dist/engine/session/import-validate.js +6 -1
- package/dist/engine/session/session.d.ts +15 -2
- package/dist/engine/session/session.js +34 -4
- package/dist/index.d.ts +18 -7
- package/dist/index.js +13 -4
- package/dist/orchestration/run-workflow-tool.js +40 -32
- package/dist/orchestration/workflow-park-adoption.d.ts +51 -12
- package/dist/orchestration/workflow-park-adoption.js +47 -12
- package/dist/orchestration/workflow-stop.d.ts +128 -0
- package/dist/orchestration/workflow-stop.js +156 -0
- package/dist/orchestration/workflow.d.ts +30 -6
- package/dist/orchestration/workflow.js +117 -55
- package/dist/prompts/manager-recipe.d.ts +18 -0
- package/dist/prompts/manager-recipe.js +24 -0
- package/dist/stores/file/permission-rule-store.d.ts +3 -1
- package/dist/stores/file/permission-rule-store.js +0 -1
- package/dist/stores/file/workflow-journal-store.d.ts +16 -3
- package/dist/stores/file/workflow-journal-store.js +93 -5
- package/dist/stores/file/workflow-run-store.d.ts +1 -1
- package/dist/tools/fs/file-write-check.js +9 -3
- package/dist/tools/fs/index.d.ts +8 -7
- package/dist/tools/fs/index.js +4 -4
- package/dist/tools/fs/read-deny-home.d.ts +1 -1
- package/dist/tools/fs/read-deny-home.js +5 -5
- package/dist/tools/fs/read-deny.d.ts +33 -8
- package/dist/tools/fs/read-deny.js +114 -25
- package/dist/tools/fs/safety.d.ts +4 -1
- package/dist/tools/fs/safety.js +4 -2
- package/dist/tools/fs/shell-read-check.d.ts +9 -2
- package/dist/tools/fs/shell-read-check.js +96 -14
- package/dist/tools/fs/shell-read-establish.d.ts +9 -0
- package/dist/tools/fs/shell-read-establish.js +21 -11
- package/dist/tools/fs/shell-read-judge.d.ts +13 -1
- package/dist/tools/fs/shell-read-judge.js +26 -7
- package/dist/tools/fs/shell-read-plan.d.ts +5 -0
- package/dist/tools/fs/shell-read-write-targets.js +17 -9
- package/package.json +2 -2
- package/test/export-surface.snapshot.json +131 -1
- package/wire-changes/answers/core-stores-sql@7.73.0.json +28 -0
- package/wire-changes/answers/core@7.73.0.json +216 -0
- package/wire-changes/answers/mods-kernel@7.73.0.json +7 -0
- package/wire-changes/answers/primitives@7.73.0.json +12 -0
- package/wire-changes/answers/wiki-gate@7.73.0.json +7 -0
- package/wire-changes/core-stores-sql@7.73.0.json +326 -0
- package/wire-changes/core@7.73.0.json +6480 -0
- package/wire-changes/mods-kernel@7.73.0.json +147 -0
- package/wire-changes/primitives@7.73.0.json +227 -0
- package/wire-changes/wiki-gate@7.73.0.json +145 -0
|
@@ -53,7 +53,9 @@ async function adoptYieldedAgents(bag, execute, enrich, leg) {
|
|
|
53
53
|
continue;
|
|
54
54
|
}
|
|
55
55
|
try {
|
|
56
|
-
const
|
|
56
|
+
const ownerGate = ctx.inheritedGateForChildren?.();
|
|
57
|
+
const ownerMode = ownerGate?.permissionModeCeiling?.current ?? ownerGate?.permissionMode;
|
|
58
|
+
const out = await execute({ description: row.description ?? "yielded agent", prompt: "continue", run_in_background: true, ...(row.agentType !== undefined ? { subagent_type: row.agentType } : {}), name: row.name, ...(row.model !== undefined ? { model: row.model } : {}) }, enrich({ toolCallId: `yield-drive-${ticket.claimId}`, reviveClaim: { row: { ...structuredClone(ticket.row), parkClaimId: ticket.claimId }, rev: ticket.reservedRev, parkedResume: { ticket, outcome: { gate: "resource_limit", decision: "continue" }, ...(ownerMode !== undefined ? { inheritedGate: { permissionMode: ownerMode } } : {}) } } }));
|
|
57
59
|
if (typeof out === "object" && out !== null && out.isError === true)
|
|
58
60
|
throw new Error(inlineUntrusted(JSON.stringify(out.content ?? ""), 300));
|
|
59
61
|
adopted.push(row.handle);
|
package/dist/brain/anthropic.js
CHANGED
|
@@ -468,7 +468,6 @@ export function createAnthropicBrain(given = {}) {
|
|
|
468
468
|
let degenTextBlock;
|
|
469
469
|
const rep = createRepetitionPoll();
|
|
470
470
|
let lastDegenCheck = 0;
|
|
471
|
-
let lastDegenCheckThinking = 0;
|
|
472
471
|
const detectRep = config.detectRepetition !== false;
|
|
473
472
|
let messageStopped = false;
|
|
474
473
|
const afterEnd = createStreamEndLedger(ctrl.providerWords);
|
|
@@ -643,10 +642,10 @@ export function createAnthropicBrain(given = {}) {
|
|
|
643
642
|
if (cb.signature)
|
|
644
643
|
acc.startSignature = cb.signature;
|
|
645
644
|
}
|
|
646
|
-
acc.pb = { type: "thinking", thinking: "" };
|
|
647
|
-
partial.content = [acc.pb];
|
|
648
|
-
out.push({ type: "thinking_start", contentIndex: idx, partial: { ...partial } });
|
|
649
645
|
if (acc.text !== "") {
|
|
646
|
+
acc.pb = { type: "thinking", thinking: "" };
|
|
647
|
+
partial.content = [acc.pb];
|
|
648
|
+
out.push({ type: "thinking_start", contentIndex: idx, partial: { ...partial } });
|
|
650
649
|
acc.pb.thinking = acc.text;
|
|
651
650
|
out.push({ type: "thinking_delta", contentIndex: idx, delta: acc.text, partial: { ...partial } });
|
|
652
651
|
}
|
|
@@ -694,12 +693,17 @@ export function createAnthropicBrain(given = {}) {
|
|
|
694
693
|
}
|
|
695
694
|
else if (d.type === "thinking_delta" && d.thinking) {
|
|
696
695
|
acc.startSignature = undefined;
|
|
696
|
+
if (!acc.pb) {
|
|
697
|
+
acc.pb = { type: "thinking", thinking: "" };
|
|
698
|
+
partial.content = [acc.pb];
|
|
699
|
+
out.push({ type: "thinking_start", contentIndex: idx, partial: { ...partial } });
|
|
700
|
+
}
|
|
697
701
|
acc.text += d.thinking;
|
|
698
|
-
if (acc.pb
|
|
702
|
+
if (acc.pb.type === "thinking")
|
|
699
703
|
acc.pb.thinking = acc.text;
|
|
700
704
|
out.push({ type: "thinking_delta", contentIndex: idx, delta: d.thinking, partial: { ...partial } });
|
|
701
|
-
if (detectRep && !degenerate && acc.text.length -
|
|
702
|
-
|
|
705
|
+
if (detectRep && !degenerate && acc.text.length - (acc.lastDegenCheck ?? 0) >= 64) {
|
|
706
|
+
acc.lastDegenCheck = acc.text.length;
|
|
703
707
|
if (rep.poll(acc.text)) {
|
|
704
708
|
degenerate = true;
|
|
705
709
|
ctrl.cancel();
|
|
@@ -720,7 +724,8 @@ export function createAnthropicBrain(given = {}) {
|
|
|
720
724
|
if (acc)
|
|
721
725
|
acc.stopped = true;
|
|
722
726
|
if (acc?.type === "thinking") {
|
|
723
|
-
|
|
727
|
+
if (acc.pb)
|
|
728
|
+
out.push({ type: "thinking_end", contentIndex: idx, content: acc.text, partial: { ...partial } });
|
|
724
729
|
}
|
|
725
730
|
else if (acc?.type === "text") {
|
|
726
731
|
out.push({ type: "text_end", contentIndex: idx, content: acc.text, partial: { ...partial } });
|
|
@@ -783,7 +788,7 @@ export function createAnthropicBrain(given = {}) {
|
|
|
783
788
|
},
|
|
784
789
|
sealForRetry() {
|
|
785
790
|
for (const [idx, acc] of [...blocks.entries()].sort((a, b) => a[0] - b[0])) {
|
|
786
|
-
if (acc.type === "thinking" && !acc.stopped) {
|
|
791
|
+
if (acc.type === "thinking" && !acc.stopped && acc.pb) {
|
|
787
792
|
acc.stopped = true;
|
|
788
793
|
out.push({ type: "thinking_end", contentIndex: idx, content: acc.text, partial: { ...partial } });
|
|
789
794
|
}
|
|
@@ -326,7 +326,6 @@ export function createOpenResponsesBrain(given = {}) {
|
|
|
326
326
|
let degenItem;
|
|
327
327
|
const rep = createRepetitionPoll();
|
|
328
328
|
let lastDegenCheckText = 0;
|
|
329
|
-
let lastDegenCheckReasoning = 0;
|
|
330
329
|
const detectRep = config.detectRepetition !== false;
|
|
331
330
|
let malformedFrames = 0;
|
|
332
331
|
let malformedSample;
|
|
@@ -371,8 +370,8 @@ export function createOpenResponsesBrain(given = {}) {
|
|
|
371
370
|
acc.block.thinking = acc.text;
|
|
372
371
|
partial.content = [acc.block];
|
|
373
372
|
out.push({ type: "thinking_delta", contentIndex: index, delta, partial: { ...partial } });
|
|
374
|
-
if (detectRep && !degenerate && acc.text.length -
|
|
375
|
-
|
|
373
|
+
if (detectRep && !degenerate && acc.text.length - (acc.lastDegenCheck ?? 0) >= DEGENERATE_POLL_CHARS) {
|
|
374
|
+
acc.lastDegenCheck = acc.text.length;
|
|
376
375
|
if (rep.poll(acc.text)) {
|
|
377
376
|
degenerate = true;
|
|
378
377
|
degenFace = "reasoning";
|
|
@@ -413,7 +412,7 @@ export function createOpenResponsesBrain(given = {}) {
|
|
|
413
412
|
return;
|
|
414
413
|
acc.closed = true;
|
|
415
414
|
if (acc.kind === "reasoning") {
|
|
416
|
-
if (acc.block)
|
|
415
|
+
if (acc.block?.type === "thinking")
|
|
417
416
|
out.push({ type: "thinking_end", contentIndex: index, content: acc.text, partial: { ...partial } });
|
|
418
417
|
}
|
|
419
418
|
else if (acc.kind === "message") {
|
|
@@ -612,7 +611,7 @@ export function createOpenResponsesBrain(given = {}) {
|
|
|
612
611
|
for (const [index, acc] of [...items.entries()].sort((a, b) => a[0] - b[0])) {
|
|
613
612
|
if (acc.kind === "reasoning" && !acc.closed) {
|
|
614
613
|
acc.closed = true;
|
|
615
|
-
if (acc.block)
|
|
614
|
+
if (acc.block?.type === "thinking")
|
|
616
615
|
out.push({ type: "thinking_end", contentIndex: index, content: acc.text, partial: { ...partial } });
|
|
617
616
|
}
|
|
618
617
|
}
|
package/dist/brain/openai.js
CHANGED
|
@@ -404,9 +404,11 @@ export function createOpenAIBrain(given = {}) {
|
|
|
404
404
|
let lastDegenCheckReasoning = 0;
|
|
405
405
|
const detectRep = config.detectRepetition !== false;
|
|
406
406
|
let emittedTextStart = false;
|
|
407
|
-
let emittedThinkingStart = false;
|
|
408
|
-
let thinkingClosed = false;
|
|
409
407
|
let textIndex = 0;
|
|
408
|
+
let nextIndex = 0;
|
|
409
|
+
const segments = [];
|
|
410
|
+
let segmentOpen = false;
|
|
411
|
+
let thinkingIndex = 0;
|
|
410
412
|
const toolAccum = new Map();
|
|
411
413
|
const responseIds = responseToolCallIds();
|
|
412
414
|
let finishReason = null;
|
|
@@ -422,25 +424,26 @@ export function createOpenAIBrain(given = {}) {
|
|
|
422
424
|
malformedFrames++;
|
|
423
425
|
malformedSample ??= ctrl.providerWords(data).slice(0, 160);
|
|
424
426
|
};
|
|
425
|
-
|
|
427
|
+
let thinkingBlock = { type: "thinking", thinking: "" };
|
|
426
428
|
const textBlock = { type: "text", text: "" };
|
|
427
429
|
const pushReasoningDelta = (delta) => {
|
|
428
430
|
if (!delta)
|
|
429
431
|
return;
|
|
430
432
|
ctrl.sawContentToken();
|
|
431
|
-
if (
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
433
|
+
if (!segmentOpen) {
|
|
434
|
+
segmentOpen = true;
|
|
435
|
+
thinkingIndex = nextIndex++;
|
|
436
|
+
thinkingBlock = { type: "thinking", thinking: "" };
|
|
437
|
+
lastDegenCheckReasoning = 0;
|
|
435
438
|
partial.content = [thinkingBlock];
|
|
436
|
-
out.push({ type: "thinking_start", contentIndex:
|
|
439
|
+
out.push({ type: "thinking_start", contentIndex: thinkingIndex, partial: { ...partial } });
|
|
437
440
|
}
|
|
438
441
|
accumReasoning += delta;
|
|
439
|
-
thinkingBlock.thinking
|
|
440
|
-
out.push({ type: "thinking_delta", contentIndex:
|
|
441
|
-
if (detectRep && !degenerate &&
|
|
442
|
-
lastDegenCheckReasoning =
|
|
443
|
-
if (rep.poll(
|
|
442
|
+
thinkingBlock.thinking += delta;
|
|
443
|
+
out.push({ type: "thinking_delta", contentIndex: thinkingIndex, delta, partial: { ...partial } });
|
|
444
|
+
if (detectRep && !degenerate && thinkingBlock.thinking.length - lastDegenCheckReasoning >= 64) {
|
|
445
|
+
lastDegenCheckReasoning = thinkingBlock.thinking.length;
|
|
446
|
+
if (rep.poll(thinkingBlock.thinking)) {
|
|
444
447
|
degenerate = true;
|
|
445
448
|
degenFace = "reasoning";
|
|
446
449
|
ctrl.cancel();
|
|
@@ -448,22 +451,27 @@ export function createOpenAIBrain(given = {}) {
|
|
|
448
451
|
}
|
|
449
452
|
};
|
|
450
453
|
const closeThinking = () => {
|
|
451
|
-
if (
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
454
|
+
if (!segmentOpen)
|
|
455
|
+
return false;
|
|
456
|
+
segmentOpen = false;
|
|
457
|
+
segments.push(thinkingBlock.thinking);
|
|
458
|
+
out.push({ type: "thinking_end", contentIndex: thinkingIndex, content: thinkingBlock.thinking, partial: { ...partial } });
|
|
459
|
+
return true;
|
|
455
460
|
};
|
|
456
461
|
const pushTextDelta = (delta) => {
|
|
457
462
|
if (!delta)
|
|
458
463
|
return;
|
|
459
464
|
ctrl.sawContentToken();
|
|
465
|
+
const segmentClosed = closeThinking();
|
|
460
466
|
if (!emittedTextStart) {
|
|
461
|
-
closeThinking();
|
|
462
467
|
emittedTextStart = true;
|
|
463
|
-
textIndex =
|
|
468
|
+
textIndex = nextIndex++;
|
|
464
469
|
partial.content = [textBlock];
|
|
465
470
|
out.push({ type: "text_start", contentIndex: textIndex, partial: { ...partial } });
|
|
466
471
|
}
|
|
472
|
+
else if (segmentClosed) {
|
|
473
|
+
partial.content = [textBlock];
|
|
474
|
+
}
|
|
467
475
|
accumText += delta;
|
|
468
476
|
textBlock.text = accumText;
|
|
469
477
|
out.push({ type: "text_delta", contentIndex: textIndex, delta, partial: { ...partial } });
|
|
@@ -586,8 +594,8 @@ export function createOpenAIBrain(given = {}) {
|
|
|
586
594
|
out.push({ type: "text_end", contentIndex: textIndex, content: textFace, partial: { ...partial } });
|
|
587
595
|
}
|
|
588
596
|
const finalContent = [];
|
|
589
|
-
|
|
590
|
-
|
|
597
|
+
const thinkingBlocks = segments.map((thinking) => ({ type: "thinking", thinking }));
|
|
598
|
+
finalContent.push(...thinkingBlocks);
|
|
591
599
|
if (textFace)
|
|
592
600
|
finalContent.push({ type: "text", text: textFace });
|
|
593
601
|
const toolCalls = [];
|
|
@@ -618,8 +626,7 @@ export function createOpenAIBrain(given = {}) {
|
|
|
618
626
|
const repaired = repairTextToolCalls(textFace, names);
|
|
619
627
|
if (repaired.toolCalls.length > 0) {
|
|
620
628
|
finalContent.length = 0;
|
|
621
|
-
|
|
622
|
-
finalContent.push({ type: "thinking", thinking: accumReasoning });
|
|
629
|
+
finalContent.push(...thinkingBlocks);
|
|
623
630
|
if (repaired.cleanedText)
|
|
624
631
|
finalContent.push({ type: "text", text: repaired.cleanedText });
|
|
625
632
|
for (const repairedCall of repaired.toolCalls) {
|
|
@@ -1142,8 +1142,11 @@ export function runStreamingBrain(args) {
|
|
|
1142
1142
|
void reader.cancel().catch(() => undefined);
|
|
1143
1143
|
};
|
|
1144
1144
|
let midstreamWarning;
|
|
1145
|
+
let activeParser;
|
|
1145
1146
|
const parserOut = Object.create(out);
|
|
1146
1147
|
parserOut.push = (ev) => {
|
|
1148
|
+
if (ev.type === "done" || ev.type === "error")
|
|
1149
|
+
activeParser?.sealForRetry();
|
|
1147
1150
|
if (midstreamWarning !== undefined && (ev.type === "done" || ev.type === "error")) {
|
|
1148
1151
|
const msg = ev.type === "done" ? ev.message : ev.error;
|
|
1149
1152
|
msg.partialFinalized = true;
|
|
@@ -1164,7 +1167,7 @@ export function runStreamingBrain(args) {
|
|
|
1164
1167
|
}
|
|
1165
1168
|
out.push(ev);
|
|
1166
1169
|
};
|
|
1167
|
-
const parser = makeParser({
|
|
1170
|
+
const parser = (activeParser = makeParser({
|
|
1168
1171
|
out: parserOut,
|
|
1169
1172
|
partial,
|
|
1170
1173
|
sawContentToken,
|
|
@@ -1181,175 +1184,180 @@ export function runStreamingBrain(args) {
|
|
|
1181
1184
|
inBandEnvelope = envelope;
|
|
1182
1185
|
producedBeforeFrame = firstTokenSeen;
|
|
1183
1186
|
},
|
|
1184
|
-
});
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
const parserFailed = (e) => {
|
|
1196
|
-
const ended = e instanceof TriedAttemptEnded ? e.ended : undefined;
|
|
1197
|
-
const envelope = ended === undefined ? inBandEnvelope : undefined;
|
|
1198
|
-
const kept = attemptOutput;
|
|
1199
|
-
const failure = {
|
|
1200
|
-
code: ended !== undefined ? extractErrorCode(ended.errorMessage) : brainErrorCodeOf(e),
|
|
1201
|
-
status: undefined,
|
|
1202
|
-
statement: envelope !== undefined && !producedBeforeFrame ? { envelope, inputTooLong: readMember(e, "inputTooLong") === true } : undefined,
|
|
1203
|
-
spent: ended !== undefined
|
|
1204
|
-
? { usage: ended.usage, ...(ended.usageMissing === true ? { usageMissing: true } : {}) }
|
|
1205
|
-
: kept !== undefined
|
|
1206
|
-
? { usage: kept.usage, ...(kept.usageMissing === true ? { usageMissing: true } : {}) }
|
|
1207
|
-
: undefined,
|
|
1208
|
-
};
|
|
1209
|
-
if (fellBackFromStream(failure))
|
|
1187
|
+
}));
|
|
1188
|
+
let arm;
|
|
1189
|
+
let announcement;
|
|
1190
|
+
try {
|
|
1191
|
+
const fellBackFromStream = (failure) => {
|
|
1192
|
+
if (keptOutput()) {
|
|
1193
|
+
keep();
|
|
1194
|
+
return false;
|
|
1195
|
+
}
|
|
1196
|
+
if (!fallBack(failure))
|
|
1197
|
+
return false;
|
|
1210
1198
|
return true;
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1199
|
+
};
|
|
1200
|
+
const parserFailed = (e) => {
|
|
1201
|
+
const ended = e instanceof TriedAttemptEnded ? e.ended : undefined;
|
|
1202
|
+
const envelope = ended === undefined ? inBandEnvelope : undefined;
|
|
1203
|
+
const kept = attemptOutput;
|
|
1204
|
+
const failure = {
|
|
1205
|
+
code: ended !== undefined ? extractErrorCode(ended.errorMessage) : brainErrorCodeOf(e),
|
|
1206
|
+
status: undefined,
|
|
1207
|
+
statement: envelope !== undefined && !producedBeforeFrame ? { envelope, inputTooLong: readMember(e, "inputTooLong") === true } : undefined,
|
|
1208
|
+
spent: ended !== undefined
|
|
1209
|
+
? { usage: ended.usage, ...(ended.usageMissing === true ? { usageMissing: true } : {}) }
|
|
1210
|
+
: kept !== undefined
|
|
1211
|
+
? { usage: kept.usage, ...(kept.usageMissing === true ? { usageMissing: true } : {}) }
|
|
1212
|
+
: undefined,
|
|
1213
|
+
};
|
|
1214
|
+
if (fellBackFromStream(failure))
|
|
1215
|
+
return true;
|
|
1216
|
+
declaredRefused = refusesDeclaredThinking(envelope);
|
|
1218
1217
|
return false;
|
|
1218
|
+
};
|
|
1219
|
+
const INBAND_OVERLOAD_WARNING = "API overloaded mid-response. The response above may be incomplete.";
|
|
1220
|
+
const onLineOverloadTierA = (line) => {
|
|
1221
|
+
try {
|
|
1222
|
+
parser.onLine(line);
|
|
1223
|
+
return false;
|
|
1224
|
+
}
|
|
1225
|
+
catch (e) {
|
|
1226
|
+
if (brainErrorCodeOf(e) !== "server" || !parser.snapshot().hasSubstantiveText)
|
|
1227
|
+
throw e;
|
|
1228
|
+
return true;
|
|
1229
|
+
}
|
|
1230
|
+
};
|
|
1231
|
+
let failure;
|
|
1232
|
+
let fellBack = false;
|
|
1233
|
+
readLoop: for (;;) {
|
|
1234
|
+
let readRes;
|
|
1235
|
+
try {
|
|
1236
|
+
readRes = await reader.read();
|
|
1237
|
+
}
|
|
1238
|
+
catch (e) {
|
|
1239
|
+
if (isAbortError(e) || signal?.aborted)
|
|
1240
|
+
throw e;
|
|
1241
|
+
failure = {
|
|
1242
|
+
kind: "connection",
|
|
1243
|
+
err: new BrainError("network", `mid-stream read failed: ${remoteWords(describeNetworkError(e), req.declared)}`, undefined, { apiError: true }),
|
|
1244
|
+
};
|
|
1245
|
+
break readLoop;
|
|
1246
|
+
}
|
|
1247
|
+
const { done, value } = readRes;
|
|
1248
|
+
if (done)
|
|
1249
|
+
break;
|
|
1250
|
+
buffer += decoder.decode(value, { stream: true });
|
|
1251
|
+
let nl;
|
|
1252
|
+
let start = 0;
|
|
1253
|
+
try {
|
|
1254
|
+
while ((nl = buffer.indexOf("\n", start)) !== -1) {
|
|
1255
|
+
const line = buffer.slice(start, nl);
|
|
1256
|
+
start = nl + 1;
|
|
1257
|
+
if (onLineOverloadTierA(line)) {
|
|
1258
|
+
midstreamWarning = INBAND_OVERLOAD_WARNING;
|
|
1259
|
+
parser.finalize({ truncated: true });
|
|
1260
|
+
return;
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
catch (e) {
|
|
1265
|
+
if (!parserFailed(e))
|
|
1266
|
+
throw e;
|
|
1267
|
+
fellBack = true;
|
|
1268
|
+
break readLoop;
|
|
1269
|
+
}
|
|
1270
|
+
if (start > 0)
|
|
1271
|
+
buffer = buffer.slice(start);
|
|
1219
1272
|
}
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
return true;
|
|
1273
|
+
if (ftTimer) {
|
|
1274
|
+
clearTimeout(ftTimer);
|
|
1275
|
+
ftTimer = undefined;
|
|
1224
1276
|
}
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
try {
|
|
1231
|
-
readRes = await reader.read();
|
|
1277
|
+
firstTokenWait.stop();
|
|
1278
|
+
nextTokenWait.stop();
|
|
1279
|
+
if (idleTimer) {
|
|
1280
|
+
clearTimeout(idleTimer);
|
|
1281
|
+
idleTimer = undefined;
|
|
1232
1282
|
}
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1283
|
+
streamSuspend.disarm();
|
|
1284
|
+
if (!failure && suspendedInStream !== undefined)
|
|
1285
|
+
failure = suspendedInStream;
|
|
1286
|
+
if (!failure && firedFirstTokenDeadlineMs !== undefined) {
|
|
1236
1287
|
failure = {
|
|
1237
|
-
kind: "
|
|
1238
|
-
|
|
1288
|
+
kind: "stalled",
|
|
1289
|
+
watchdog: "first-token",
|
|
1290
|
+
knob: "firstTokenTimeoutMs",
|
|
1291
|
+
timeoutMs: firedFirstTokenDeadlineMs,
|
|
1292
|
+
err: new BrainError("network", `first-token timeout after ${firedFirstTokenDeadlineMs}ms`, undefined, { apiError: true }),
|
|
1239
1293
|
};
|
|
1240
|
-
break readLoop;
|
|
1241
1294
|
}
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
const line = buffer.slice(start, nl);
|
|
1251
|
-
start = nl + 1;
|
|
1252
|
-
if (onLineOverloadTierA(line)) {
|
|
1253
|
-
midstreamWarning = INBAND_OVERLOAD_WARNING;
|
|
1254
|
-
parser.finalize({ truncated: true });
|
|
1255
|
-
return;
|
|
1256
|
-
}
|
|
1257
|
-
}
|
|
1258
|
-
}
|
|
1259
|
-
catch (e) {
|
|
1260
|
-
if (!parserFailed(e))
|
|
1261
|
-
throw e;
|
|
1262
|
-
fellBack = true;
|
|
1263
|
-
break readLoop;
|
|
1264
|
-
}
|
|
1265
|
-
if (start > 0)
|
|
1266
|
-
buffer = buffer.slice(start);
|
|
1267
|
-
}
|
|
1268
|
-
if (ftTimer) {
|
|
1269
|
-
clearTimeout(ftTimer);
|
|
1270
|
-
ftTimer = undefined;
|
|
1271
|
-
}
|
|
1272
|
-
firstTokenWait.stop();
|
|
1273
|
-
nextTokenWait.stop();
|
|
1274
|
-
if (idleTimer) {
|
|
1275
|
-
clearTimeout(idleTimer);
|
|
1276
|
-
idleTimer = undefined;
|
|
1277
|
-
}
|
|
1278
|
-
streamSuspend.disarm();
|
|
1279
|
-
if (!failure && suspendedInStream !== undefined)
|
|
1280
|
-
failure = suspendedInStream;
|
|
1281
|
-
if (!failure && firedFirstTokenDeadlineMs !== undefined) {
|
|
1282
|
-
failure = {
|
|
1283
|
-
kind: "stalled",
|
|
1284
|
-
watchdog: "first-token",
|
|
1285
|
-
knob: "firstTokenTimeoutMs",
|
|
1286
|
-
timeoutMs: firedFirstTokenDeadlineMs,
|
|
1287
|
-
err: new BrainError("network", `first-token timeout after ${firedFirstTokenDeadlineMs}ms`, undefined, { apiError: true }),
|
|
1288
|
-
};
|
|
1289
|
-
}
|
|
1290
|
-
if (!failure && firedIdleDeadlineMs !== undefined) {
|
|
1291
|
-
failure = {
|
|
1292
|
-
kind: "stalled",
|
|
1293
|
-
watchdog: "stream idle",
|
|
1294
|
-
knob: "idleTimeoutMs",
|
|
1295
|
-
timeoutMs: firedIdleDeadlineMs,
|
|
1296
|
-
err: new BrainError("network", `stream idle timeout after ${firedIdleDeadlineMs}ms`, undefined, { apiError: true }),
|
|
1297
|
-
};
|
|
1298
|
-
}
|
|
1299
|
-
if (fellBack || (failure !== undefined && !parser.snapshot().terminalFrameSeen && fellBackFromStream({ code: brainErrorCodeOf(failure.err), status: undefined, statement: undefined, spent: undefined }))) {
|
|
1300
|
-
cleanup?.();
|
|
1301
|
-
cleanup = undefined;
|
|
1302
|
-
continue;
|
|
1303
|
-
}
|
|
1304
|
-
if (!failure) {
|
|
1305
|
-
buffer += decoder.decode();
|
|
1306
|
-
try {
|
|
1307
|
-
if (buffer.trim() && onLineOverloadTierA(buffer))
|
|
1308
|
-
midstreamWarning = INBAND_OVERLOAD_WARNING;
|
|
1309
|
-
parser.finalize(midstreamWarning !== undefined ? { truncated: true } : undefined);
|
|
1295
|
+
if (!failure && firedIdleDeadlineMs !== undefined) {
|
|
1296
|
+
failure = {
|
|
1297
|
+
kind: "stalled",
|
|
1298
|
+
watchdog: "stream idle",
|
|
1299
|
+
knob: "idleTimeoutMs",
|
|
1300
|
+
timeoutMs: firedIdleDeadlineMs,
|
|
1301
|
+
err: new BrainError("network", `stream idle timeout after ${firedIdleDeadlineMs}ms`, undefined, { apiError: true }),
|
|
1302
|
+
};
|
|
1310
1303
|
}
|
|
1311
|
-
|
|
1312
|
-
if (!parserFailed(e))
|
|
1313
|
-
throw e;
|
|
1304
|
+
if (fellBack || (failure !== undefined && !parser.snapshot().terminalFrameSeen && fellBackFromStream({ code: brainErrorCodeOf(failure.err), status: undefined, statement: undefined, spent: undefined }))) {
|
|
1314
1305
|
cleanup?.();
|
|
1315
1306
|
cleanup = undefined;
|
|
1316
1307
|
continue;
|
|
1317
1308
|
}
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1309
|
+
if (!failure) {
|
|
1310
|
+
buffer += decoder.decode();
|
|
1311
|
+
try {
|
|
1312
|
+
if (buffer.trim() && onLineOverloadTierA(buffer))
|
|
1313
|
+
midstreamWarning = INBAND_OVERLOAD_WARNING;
|
|
1314
|
+
parser.finalize(midstreamWarning !== undefined ? { truncated: true } : undefined);
|
|
1315
|
+
}
|
|
1316
|
+
catch (e) {
|
|
1317
|
+
if (!parserFailed(e))
|
|
1318
|
+
throw e;
|
|
1319
|
+
cleanup?.();
|
|
1320
|
+
cleanup = undefined;
|
|
1321
|
+
continue;
|
|
1322
|
+
}
|
|
1323
|
+
return;
|
|
1325
1324
|
}
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1325
|
+
const snap = parser.snapshot();
|
|
1326
|
+
arm = streamCutOf(snap);
|
|
1327
|
+
if (arm === "whole") {
|
|
1328
|
+
try {
|
|
1329
|
+
parser.finalize();
|
|
1330
|
+
}
|
|
1331
|
+
catch (e) {
|
|
1332
|
+
if (!parserFailed(e))
|
|
1333
|
+
throw e;
|
|
1334
|
+
cleanup?.();
|
|
1335
|
+
cleanup = undefined;
|
|
1336
|
+
continue;
|
|
1337
|
+
}
|
|
1338
|
+
return;
|
|
1332
1339
|
}
|
|
1333
|
-
|
|
1340
|
+
if (arm === "keep") {
|
|
1341
|
+
midstreamWarning =
|
|
1342
|
+
failure.kind === "stalled"
|
|
1343
|
+
? "Response stalled mid-stream. The response above may be incomplete."
|
|
1344
|
+
: STREAM_TORN_WARNING;
|
|
1345
|
+
parser.finalize({ truncated: true });
|
|
1346
|
+
return;
|
|
1347
|
+
}
|
|
1348
|
+
if (snap.hasCompletedToolCall)
|
|
1349
|
+
throw failure.err;
|
|
1350
|
+
cleanup?.();
|
|
1351
|
+
cleanup = undefined;
|
|
1352
|
+
announcement = retryAnnouncement(failure);
|
|
1353
|
+
if (arm === "fail")
|
|
1354
|
+
throw failure.err;
|
|
1334
1355
|
}
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
failure.kind === "stalled"
|
|
1338
|
-
? "Response stalled mid-stream. The response above may be incomplete."
|
|
1339
|
-
: STREAM_TORN_WARNING;
|
|
1340
|
-
parser.finalize({ truncated: true });
|
|
1341
|
-
return;
|
|
1356
|
+
finally {
|
|
1357
|
+
parser.sealForRetry();
|
|
1342
1358
|
}
|
|
1343
|
-
if (snap.hasCompletedToolCall)
|
|
1344
|
-
throw failure.err;
|
|
1345
|
-
cleanup?.();
|
|
1346
|
-
cleanup = undefined;
|
|
1347
|
-
const announcement = retryAnnouncement(failure);
|
|
1348
|
-
if (arm === "fail")
|
|
1349
|
-
throw failure.err;
|
|
1350
1359
|
if (arm === "resend_thinking") {
|
|
1351
1360
|
thinkingRetries++;
|
|
1352
|
-
parser.sealForRetry();
|
|
1353
1361
|
const delayMs = 100 * thinkingRetries;
|
|
1354
1362
|
await waitAnnouncingRetry(announcement, { phase: "midstream", attempt: thinkingRetries, maxRetries: THINKING_RETRY_BUDGET, delayMs });
|
|
1355
1363
|
continue;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A WORKER'S ACTIONS DIGEST — what a delegated child did, counted over its whole event stream (every tool call that ended, not
|
|
3
|
+
* the last-steps ring a resume prompt reads): calls by tool, the shell commands it ran with the exit codes the shell reported, and
|
|
4
|
+
* the files it changed. The engine's own record, set beside the child's self-report on the faces a run with a member ledger reads
|
|
5
|
+
* (the `<actions>` section of a completion notification, the ledger row): it says what was done, never whether it was right.
|
|
6
|
+
*
|
|
7
|
+
* Types, one sentence and one shape check — no imports, so every carrier (the step recorder, the notification codec, the ledger)
|
|
8
|
+
* can read it without a cycle.
|
|
9
|
+
*/
|
|
10
|
+
/** One file the child changed, and how many times. */
|
|
11
|
+
export interface ActionsDigestFile {
|
|
12
|
+
readonly path: string;
|
|
13
|
+
readonly edits: number;
|
|
14
|
+
}
|
|
15
|
+
/** See the module head. */
|
|
16
|
+
export interface SubagentActions {
|
|
17
|
+
/** Every tool call that ended, all tools. */
|
|
18
|
+
readonly toolCalls: number;
|
|
19
|
+
/** Calls by tool name, most first (ties by first use); at most {@link ACTIONS_TOOLS_CAP} names — `toolCalls` counts all. */
|
|
20
|
+
readonly byTool: ReadonlyArray<{
|
|
21
|
+
readonly tool: string;
|
|
22
|
+
readonly calls: number;
|
|
23
|
+
}>;
|
|
24
|
+
/** Shell commands, in order, first line each (redacted and cut as every step field is); at most {@link ACTIONS_COMMANDS_CAP}. */
|
|
25
|
+
readonly commands: ReadonlyArray<{
|
|
26
|
+
readonly command: string;
|
|
27
|
+
readonly exitCode?: number;
|
|
28
|
+
}>;
|
|
29
|
+
/** Commands past the listed ones — absent when every command is listed (never `0`). */
|
|
30
|
+
readonly commandsUnlisted?: number;
|
|
31
|
+
/** Files changed; empty when none — the fact a self-report of edits is read against. */
|
|
32
|
+
readonly filesEdited: ReadonlyArray<ActionsDigestFile>;
|
|
33
|
+
}
|
|
34
|
+
/** How many shell commands a digest lists. */
|
|
35
|
+
export declare const ACTIONS_COMMANDS_CAP = 20;
|
|
36
|
+
/** How many tool names a digest lists. */
|
|
37
|
+
export declare const ACTIONS_TOOLS_CAP = 16;
|
|
38
|
+
/** The digest as the one engine line every face reads: `tool calls 9: Read 5, Bash 3, Grep 1 · commands: \`npm test\` (exit 0) ·
|
|
39
|
+
* files edited: none`. */
|
|
40
|
+
export declare function subagentActionsLine(a: SubagentActions): string;
|
|
41
|
+
/** Does a value read as a {@link SubagentActions} — the check a frame that came from outside this process (a boxed frame) passes
|
|
42
|
+
* before it is rendered. A key this build does not read is not judged. */
|
|
43
|
+
export declare function isSubagentActions(v: unknown): v is SubagentActions;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const ACTIONS_COMMANDS_CAP = 20;
|
|
2
|
+
export const ACTIONS_TOOLS_CAP = 16;
|
|
3
|
+
export function subagentActionsLine(a) {
|
|
4
|
+
const tools = a.byTool.length > 0 ? `: ${a.byTool.map((t) => `${t.tool} ${t.calls}`).join(", ")}` : "";
|
|
5
|
+
const commands = a.commands.length === 0
|
|
6
|
+
? "none"
|
|
7
|
+
: `${a.commands.map((c) => `\`${c.command}\`${c.exitCode !== undefined ? ` (exit ${c.exitCode})` : ""}`).join(" · ")}${a.commandsUnlisted !== undefined ? ` · and ${a.commandsUnlisted} more` : ""}`;
|
|
8
|
+
const files = a.filesEdited.length === 0 ? "none" : a.filesEdited.map((f) => `${f.path}${f.edits > 1 ? ` (×${f.edits})` : ""}`).join(", ");
|
|
9
|
+
return `tool calls ${a.toolCalls}${tools} · commands: ${commands} · files edited: ${files}`;
|
|
10
|
+
}
|
|
11
|
+
const isCount = (v) => typeof v === "number" && Number.isSafeInteger(v) && v >= 0;
|
|
12
|
+
export function isSubagentActions(v) {
|
|
13
|
+
if (v === null || typeof v !== "object" || Array.isArray(v))
|
|
14
|
+
return false;
|
|
15
|
+
const a = v;
|
|
16
|
+
const list = (l, item) => Array.isArray(l) && l.every((e) => e !== null && typeof e === "object" && !Array.isArray(e) && item(e));
|
|
17
|
+
return (isCount(a["toolCalls"]) &&
|
|
18
|
+
list(a["byTool"], (e) => typeof e["tool"] === "string" && isCount(e["calls"])) &&
|
|
19
|
+
list(a["commands"], (e) => typeof e["command"] === "string" && (e["exitCode"] === undefined || (typeof e["exitCode"] === "number" && Number.isInteger(e["exitCode"])))) &&
|
|
20
|
+
(a["commandsUnlisted"] === undefined || (isCount(a["commandsUnlisted"]) && a["commandsUnlisted"] > 0)) &&
|
|
21
|
+
list(a["filesEdited"], (e) => typeof e["path"] === "string" && isCount(e["edits"])));
|
|
22
|
+
}
|