@sema-agent/core 7.62.0 → 7.63.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 +528 -0
- package/dist/agents/subagent-transcript-placement.d.ts +23 -0
- package/dist/agents/subagent-transcript-placement.js +14 -0
- package/dist/agents/subagent.js +82 -51
- package/dist/brain/route-adjudicator.js +9 -4
- package/dist/core/approval-object.js +1 -1
- package/dist/core/arg-summary.js +1 -1
- package/dist/core/ask-question.d.ts +2 -2
- package/dist/core/canonical-json.d.ts +23 -13
- package/dist/core/canonical-json.js +4 -4
- package/dist/core/checkpoint-queries.d.ts +47 -4
- package/dist/core/checkpoint-queries.js +36 -16
- package/dist/core/checkpoint-requirements.d.ts +3 -3
- package/dist/core/checkpoint-requirements.js +2 -1
- package/dist/core/checkpoint-row-verdict.d.ts +15 -4
- package/dist/core/checkpoint-row-verdict.js +22 -2
- package/dist/core/checkpoint-store.d.ts +23 -10
- package/dist/core/checkpoint-store.js +45 -4
- package/dist/core/compliance.d.ts +6 -2
- package/dist/core/compliance.js +3 -3
- package/dist/core/engine-attestation.d.ts +1 -1
- package/dist/core/engine-notice.d.ts +19 -4
- package/dist/core/git-worktree-env.d.ts +62 -3
- package/dist/core/git-worktree-env.js +91 -30
- package/dist/core/governance-codes.d.ts +7 -3
- package/dist/core/governance-codes.js +13 -3
- package/dist/core/memory-engine/consolidation-driver.d.ts +32 -17
- package/dist/core/memory-engine/consolidation-driver.js +99 -98
- package/dist/core/memory-engine/consolidation.d.ts +73 -10
- package/dist/core/memory-engine/consolidation.js +167 -11
- package/dist/core/memory-engine/data-plane.d.ts +8 -4
- package/dist/core/memory-engine/data-plane.js +11 -6
- package/dist/core/memory-engine/delegation-settlement.d.ts +37 -35
- package/dist/core/memory-engine/delegation-settlement.js +53 -59
- package/dist/core/memory-engine/dual-root.d.ts +12 -6
- package/dist/core/memory-engine/dual-root.js +9 -5
- package/dist/core/memory-engine/engine.d.ts +98 -35
- package/dist/core/memory-engine/engine.js +477 -380
- package/dist/core/memory-engine/entry-scan.d.ts +8 -0
- package/dist/core/memory-engine/entry-scan.js +3 -0
- package/dist/core/memory-engine/file-backend.d.ts +29 -3
- package/dist/core/memory-engine/file-backend.js +66 -35
- package/dist/core/memory-engine/index.d.ts +7 -7
- package/dist/core/memory-engine/index.js +6 -6
- package/dist/core/memory-engine/landing-admission.d.ts +5 -3
- package/dist/core/memory-engine/landing-admission.js +3 -3
- package/dist/core/memory-engine/layout.d.ts +121 -45
- package/dist/core/memory-engine/layout.js +252 -102
- package/dist/core/memory-engine/memory-backend-contract.d.ts +19 -1
- package/dist/core/memory-engine/memory-backend-contract.js +320 -0
- package/dist/core/memory-engine/memory-deployment.d.ts +31 -8
- package/dist/core/memory-engine/memory-deployment.js +26 -12
- package/dist/core/memory-engine/scope-contract.d.ts +52 -11
- package/dist/core/memory-engine/scope-contract.js +68 -19
- package/dist/core/memory-engine/session-write-home.d.ts +3 -1
- package/dist/core/memory-engine/session-write-home.js +1 -1
- package/dist/core/memory-engine/sync-client.d.ts +3 -1
- package/dist/core/memory-engine/sync-client.js +7 -0
- package/dist/core/memory-engine/sync-report.d.ts +3 -2
- package/dist/core/memory-engine/sync-report.js +6 -2
- package/dist/core/memory-engine/tools.d.ts +2 -2
- package/dist/core/memory-engine/tools.js +10 -10
- package/dist/core/memory-engine/types.d.ts +118 -19
- package/dist/core/memory-engine/types.js +1 -0
- package/dist/core/memory.js +15 -6
- package/dist/core/mods/stations.d.ts +20 -1
- package/dist/core/mods/stations.js +21 -2
- package/dist/core/park-selfcheck.js +2 -2
- package/dist/core/pause-registry.d.ts +2 -0
- package/dist/core/pause-registry.js +3 -0
- package/dist/core/permission-rule-consent.d.ts +10 -3
- package/dist/core/permission-rule-consent.js +37 -24
- package/dist/core/permission-rule-store.d.ts +35 -1
- package/dist/core/permission-rule-store.js +27 -8
- package/dist/core/read-only-shell.js +3 -2
- package/dist/core/redaction-marks.d.ts +8 -0
- package/dist/core/redaction-marks.js +6 -0
- package/dist/core/remote-env.d.ts +12 -1
- package/dist/core/remote-env.js +3 -0
- package/dist/core/runner/child-tree.d.ts +29 -3
- package/dist/core/runner/child-tree.js +39 -16
- package/dist/core/runner/contracts.d.ts +18 -9
- package/dist/core/runner/gate-exit.js +2 -2
- package/dist/core/runner/inherited-ask-grants.js +1 -1
- package/dist/core/runner/memory-consolidation-driver.d.ts +6 -3
- package/dist/core/runner/memory-consolidation-driver.js +4 -4
- package/dist/core/runner/memory-consolidation-write-judge.d.ts +2 -1
- package/dist/core/runner/memory-consolidation-write-judge.js +3 -2
- package/dist/core/runner/person-path-rows.d.ts +8 -3
- package/dist/core/runner/person-path-rows.js +5 -1
- package/dist/core/runner/placement-fence.d.ts +12 -0
- package/dist/core/runner/placement-fence.js +20 -6
- package/dist/core/runner/prepare-ask-lane.js +2 -2
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +4 -1
- package/dist/core/runner/prepare-caps-and-workflow.js +5 -2
- package/dist/core/runner/prepare-execution-env.js +17 -6
- package/dist/core/runner/prepare-hands-readface.d.ts +2 -1
- package/dist/core/runner/prepare-hands-readface.js +4 -3
- package/dist/core/runner/prepare-inherited-gate.d.ts +10 -8
- package/dist/core/runner/prepare-inherited-gate.js +8 -4
- package/dist/core/runner/prepare-memory-engine-session.d.ts +2 -4
- package/dist/core/runner/prepare-memory-engine-session.js +4 -4
- package/dist/core/runner/prepare-memory.d.ts +3 -2
- package/dist/core/runner/prepare-memory.js +28 -20
- package/dist/core/runner/prepare-park-ask.js +4 -3
- package/dist/core/runner/prepare-task.js +15 -12
- package/dist/core/runner/prepare-workspace-restore.js +3 -6
- package/dist/core/runner/run-leg.js +1 -1
- package/dist/core/runner/run-settle-and-teardown.js +3 -2
- package/dist/core/runner/terminal-account.js +1 -1
- package/dist/core/runner-deps.d.ts +6 -2
- package/dist/core/secret-env.d.ts +1 -1
- package/dist/core/secret-env.js +4 -4
- package/dist/core/session-checkout.d.ts +108 -0
- package/dist/core/session-checkout.js +485 -0
- package/dist/core/session-store.d.ts +12 -4
- package/dist/core/session-store.js +23 -3
- package/dist/core/session.d.ts +16 -2
- package/dist/core/session.js +3 -0
- package/dist/core/store-contracts/checkpoint-store-contract.d.ts +0 -12
- package/dist/core/store-contracts/checkpoint-store-contract.js +6 -7
- package/dist/core/store-contracts/session-store-contract.js +39 -0
- package/dist/core/task-event.d.ts +21 -0
- package/dist/core/task-notification.d.ts +9 -1
- package/dist/core/task-notification.js +6 -0
- package/dist/core/task-registry-agent.d.ts +14 -2
- package/dist/core/task-registry-agent.js +45 -19
- package/dist/core/task-registry-shared.d.ts +26 -11
- package/dist/core/task-registry.d.ts +15 -9
- package/dist/core/task-registry.js +9 -10
- package/dist/core/task-spec-members.js +1 -1
- package/dist/core/task-spec.d.ts +20 -0
- package/dist/core/tool-policy.d.ts +14 -12
- package/dist/core/tool-policy.js +11 -10
- package/dist/core/tool-spec.d.ts +38 -19
- package/dist/core/types.d.ts +1 -1
- package/dist/core/untrusted-egress.d.ts +15 -4
- package/dist/core/untrusted-egress.js +23 -22
- package/dist/core/workspace-snapshot.d.ts +3 -1
- package/dist/core/workspace-snapshot.js +1 -0
- package/dist/engine/harness/types.d.ts +66 -1
- package/dist/engine/harness/types.js +108 -0
- package/dist/engine/session/import-validate.js +6 -1
- package/dist/engine/session/session.d.ts +24 -1
- package/dist/engine/session/session.js +45 -1
- package/dist/index.d.ts +7 -4
- package/dist/index.js +7 -4
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/orchestration/run-workflow-tool.d.ts +4 -1
- package/dist/orchestration/run-workflow-tool.js +1 -0
- package/dist/orchestration/workflow.d.ts +3 -0
- package/dist/orchestration/workflow.js +3 -1
- package/dist/stores/file/session-store.js +2 -1
- package/dist/tools/fs/bash-program-position.js +3 -3
- package/dist/tools/fs/program-read-model.d.ts +34 -10
- package/dist/tools/fs/program-read-model.js +37 -7
- package/dist/tools/fs/program-read-model.rows.js +13 -2
- package/dist/tools/fs/read-deny.d.ts +13 -1
- package/dist/tools/fs/read-deny.js +10 -2
- package/dist/tools/fs/removal-targets.js +3 -3
- package/dist/tools/fs/safety.d.ts +2 -0
- package/dist/tools/fs/safety.js +1 -1
- package/dist/tools/fs/shell-read-argv.d.ts +8 -1
- package/dist/tools/fs/shell-read-argv.js +34 -29
- package/dist/tools/fs/shell-read-bindings.d.ts +2 -0
- package/dist/tools/fs/shell-read-bindings.js +5 -1
- package/dist/tools/fs/shell-read-brace.d.ts +18 -0
- package/dist/tools/fs/shell-read-brace.js +79 -0
- package/dist/tools/fs/shell-read-check.js +10 -8
- package/dist/tools/fs/shell-read-establish.js +23 -16
- package/dist/tools/fs/shell-read-judge.d.ts +11 -0
- package/dist/tools/fs/shell-read-judge.js +3 -3
- package/dist/tools/fs/shell-read-plan.d.ts +10 -0
- package/dist/tools/fs/shell-read-plan.js +189 -93
- package/dist/tools/fs/shell-read-start.d.ts +19 -9
- package/dist/tools/fs/shell-read-start.js +20 -12
- package/dist/tools/fs/shell-read-word.d.ts +10 -0
- package/dist/tools/fs/shell-read-word.js +9 -5
- package/dist/tools/fs/shell-read-workdir.d.ts +26 -7
- package/dist/tools/fs/shell-read-workdir.js +73 -12
- package/dist/tools/fs/shell-read-write-targets.js +13 -8
- package/dist/tools/worktree.d.ts +3 -2
- package/dist/tools/worktree.js +7 -35
- package/package.json +3 -2
- package/test/export-surface.snapshot.json +73 -11
- package/wire-changes/core-stores-sql@7.63.0.json +30 -0
- package/wire-changes/core@7.63.0.json +3523 -0
- package/wire-changes/mods-kernel@7.63.0.json +30 -0
- package/wire-changes/primitives@7.63.0.json +445 -0
- package/dist/core/credential-vocabulary.d.ts +0 -176
- package/dist/core/credential-vocabulary.js +0 -190
- package/dist/core/redaction-passes.d.ts +0 -82
- package/dist/core/redaction-passes.js +0 -377
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type SessionPlacement, type SessionStore } from "../core/session.js";
|
|
2
|
+
/**
|
|
3
|
+
* Whether a background child's transcript is placed. Gated on BOTH stores: the row store (the a* handle the tuple joins to) AND the
|
|
4
|
+
* declaration of the session store that creates the transcript (`declaresSubagentPlacement`, the deployment's opt-in) — for a fork
|
|
5
|
+
* that is the store the branch is created in, so the Runner's host fork applies the host store's declaration. Without the declaration gate, a hand-wired durable repo
|
|
6
|
+
* (TtlSessionStore over FileSessionRepo, no `placements`) would persist tuples it never opted into: list-excluded transcripts
|
|
7
|
+
* nothing can address, a release that really deletes under evict:"forget", and a manifest reporting tier "rows" while placed
|
|
8
|
+
* semantics are silently in force. Obligation enforcement below the store keys on the PERSISTED fact — this gate is what keeps
|
|
9
|
+
* that fact deployment-consistent. What it does NOT decide is whether the transcript reaches DISK: an unplaced child still lands
|
|
10
|
+
* in whatever store the child runner is backed by. Placement buys ADDRESSABILITY (the a* handle, cross-restart revival, joint
|
|
11
|
+
* reap), not persistence.
|
|
12
|
+
*/
|
|
13
|
+
export declare function placesSubagentTranscripts(agentStore: unknown, sessions: Pick<SessionStore, "placements">): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* The one tuple a background child's transcript session is created with, on both background lanes: a plain spawn's creating
|
|
16
|
+
* acquire and a fork's creating write. The spawner is the minter — it knows the a* handle, the row's scope and the tree it spawns
|
|
17
|
+
* in — so the parent is the spawning session and the root is that session's root (or itself). It names no owner: the plain lane
|
|
18
|
+
* adds the delegation tree's owner for its acquire's owner cell, a fork records it through the fork's own owner argument.
|
|
19
|
+
*/
|
|
20
|
+
export declare function subagentTranscriptPlacement(spawner: {
|
|
21
|
+
readonly sessionId?: string;
|
|
22
|
+
readonly rootSessionId?: string;
|
|
23
|
+
}, scope: string | undefined, handle: string): Omit<SessionPlacement, "owner">;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { declaresSubagentPlacement } from "../core/session.js";
|
|
2
|
+
export function placesSubagentTranscripts(agentStore, sessions) {
|
|
3
|
+
return agentStore !== undefined && declaresSubagentPlacement(sessions);
|
|
4
|
+
}
|
|
5
|
+
export function subagentTranscriptPlacement(spawner, scope, handle) {
|
|
6
|
+
const root = spawner.rootSessionId ?? spawner.sessionId;
|
|
7
|
+
return {
|
|
8
|
+
kind: "subagent",
|
|
9
|
+
...(scope !== undefined ? { scope } : {}),
|
|
10
|
+
...(spawner.sessionId !== undefined ? { parentSessionId: spawner.sessionId } : {}),
|
|
11
|
+
...(root !== undefined ? { rootSessionId: root } : {}),
|
|
12
|
+
handle,
|
|
13
|
+
};
|
|
14
|
+
}
|
package/dist/agents/subagent.js
CHANGED
|
@@ -32,10 +32,11 @@ import { normalizePeerName, reservedPeerNameReason } from "./cross-session-ref.j
|
|
|
32
32
|
import { SUBAGENT_PROMPT } from "../prompts/default.js";
|
|
33
33
|
import { roleBaseOf } from "../prompt-assembly/role-base.js";
|
|
34
34
|
import { readPromptRole } from "../prompt-assembly/select.js";
|
|
35
|
-
import { hasSessionFork } from "../core/session.js";
|
|
35
|
+
import { declaresSubagentPlacement, hasSessionFork } from "../core/session.js";
|
|
36
36
|
import { isDurablePause, pauseFamily } from "./suspend-guard.js";
|
|
37
37
|
import { childRejection, childTerminalFace, childThrownText } from "./child-failure.js";
|
|
38
38
|
import { forwardSafely } from "../core/runner/forward-sink.js";
|
|
39
|
+
import { callerPlacementSeats } from "../core/runner/child-tree.js";
|
|
39
40
|
import { legTaskIdOf } from "../core/leg-identity.js";
|
|
40
41
|
import { delimitUntrusted, inlineUntrusted } from "../core/untrusted-text.js";
|
|
41
42
|
import { createSafeNotifier } from "../core/safe-notify.js";
|
|
@@ -47,7 +48,8 @@ import { BG_AGENT_REAP_STOP_ERROR, chosenAgentName } from "../core/task-registry
|
|
|
47
48
|
import { readDurableOrgAdmission } from "../core/memory-admission.js";
|
|
48
49
|
import { governanceRetryClass } from "../core/governance-codes.js";
|
|
49
50
|
import { readSkillGrantCapture } from "../core/skill-grant.js";
|
|
50
|
-
import { admitsBackgroundLaunch, completionResultField, oweTerminalDelivery, resolveCompletionSink, terminalFrameFacets } from "../core/task-notification.js";
|
|
51
|
+
import { admitsBackgroundLaunch, completionResultField, moveTerminalDelivery, oweTerminalDelivery, resolveCompletionSink, terminalFrameFacets } from "../core/task-notification.js";
|
|
52
|
+
import { deliverEngineNotice } from "../core/engine-notice.js";
|
|
51
53
|
import { RETAIN_DEFAULT_TTL_MS, RETAIN_DEFAULT_MAX, RUNNING_AGENT_OBSERVE_EVERY_BEATS, DELEGATION_MAX_CONCURRENT_DEFAULT, DELEGATION_MAX_PER_SESSION_DEFAULT } from "../config/defaults.js";
|
|
52
54
|
function rollupDelegatedCost(stats, nested) {
|
|
53
55
|
if (stats.costMicroUsd === undefined)
|
|
@@ -81,6 +83,7 @@ import { LAUNCH_RECEIPT_OWN_WORDS_CLAUSE, launchReceiptNoQuoteClause } from "./l
|
|
|
81
83
|
import { ObserverDigestTap, ObserverPairing, createObserverReportToolSpec, markObserverTaskId, unmarkObserverTaskId, isObserverTaskId, ObserverResumeStateError, ObserverStoppedByUserError, observerFramingPrompt, observerSlug, resolveObserverDeclaration, } from "./observer.js";
|
|
82
84
|
import { SubagentStepRecorder, redactThenCut } from "./subagent-steps.js";
|
|
83
85
|
import { childOwnerKeys, parkCompletionNotify, runningBackgroundUnder } from "./subagent-completion-gate.js";
|
|
86
|
+
import { placesSubagentTranscripts, subagentTranscriptPlacement } from "./subagent-transcript-placement.js";
|
|
84
87
|
import { OUTPUT_TOOL_NAME, mountRuleFace, toolFace } from "../core/tool-catalog-entries.js";
|
|
85
88
|
import { canonicalNameValue } from "../core/permission-rule-model.js";
|
|
86
89
|
import { definitionAllowTools, inheritedChildPool, inheritedHostSeats, inheritedMcpDeclarations, withDefinitionServers, withoutWakerSeats } from "./inherited-tool-pool.js";
|
|
@@ -387,6 +390,7 @@ const SUBAGENT_ERROR_KIND_BY_CODE = {
|
|
|
387
390
|
stream_torn: "network",
|
|
388
391
|
refusal: "logic",
|
|
389
392
|
length_empty: "logic",
|
|
393
|
+
"config.placement_not_honored": "logic",
|
|
390
394
|
};
|
|
391
395
|
const SUBAGENT_RETRYABLE = {
|
|
392
396
|
rate_limit: true,
|
|
@@ -1535,7 +1539,8 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
1535
1539
|
const a = canonicalSubagentTypeArgs(args, acceptedSubagentTypes(), generalPurposeShadowed);
|
|
1536
1540
|
const parentSpecSeat = parentSpecSeatOfCtx(ctx);
|
|
1537
1541
|
const reviveClaim = ctx.reviveClaim;
|
|
1538
|
-
const
|
|
1542
|
+
const parkedLane = reviveClaim?.parkedResume !== undefined ? opts.background?.registry.parkedCompletionSink(reviveClaim.row.handle) : undefined;
|
|
1543
|
+
const backgroundSink = opts.background !== undefined ? resolveCompletionSink(ctx.onTaskNotification ?? parkedLane, opts.background.notify) : undefined;
|
|
1539
1544
|
const backgroundLane = opts.background !== undefined && admitsBackgroundLaunch(backgroundSink);
|
|
1540
1545
|
if (reviveClaim !== undefined && !backgroundLane) {
|
|
1541
1546
|
return notStartedResult({
|
|
@@ -2256,7 +2261,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2256
2261
|
})(),
|
|
2257
2262
|
...(ctx.subagentRetain !== undefined ? { parentRetainLedger: ctx.subagentRetain } : {}),
|
|
2258
2263
|
onForwardEvent: recordingForward,
|
|
2259
|
-
...(ctx.parentCwd
|
|
2264
|
+
...callerPlacementSeats(ctx.parentCwd, ctx.callerRoot),
|
|
2260
2265
|
...(ctx.placementTarget !== undefined ? { placementTarget: ctx.placementTarget } : {}),
|
|
2261
2266
|
...(worktreeDir !== undefined
|
|
2262
2267
|
? { parentCwd: worktreeDir, worktreeOffered: true, onWorkspaceResolved: (ws) => void (childPlacement = ws) }
|
|
@@ -2494,14 +2499,17 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2494
2499
|
const forkTree = await delegationOwnerOf(ctx.delegationOwner);
|
|
2495
2500
|
if (!forkTree.bound)
|
|
2496
2501
|
return ownerUnboundResult(false, forkTree);
|
|
2502
|
+
const forkBg = wantsBackground ? opts.background : undefined;
|
|
2503
|
+
const forkPlacementHandle = forkBg?.agentStore !== undefined ? forkBg.registry.mintTaskId("background_agent") : undefined;
|
|
2504
|
+
const forkOpts = forkPlacementHandle !== undefined ? { placement: subagentTranscriptPlacement(ctx, treeScope, forkPlacementHandle) } : undefined;
|
|
2497
2505
|
try {
|
|
2498
2506
|
if (ctx.hostSessionFork) {
|
|
2499
|
-
const forkHandle = await ctx.hostSessionFork();
|
|
2507
|
+
const forkHandle = await ctx.hostSessionFork(forkOpts);
|
|
2500
2508
|
forkedId = forkHandle?.sessionId ?? null;
|
|
2501
2509
|
releaseForked = forkHandle?.release;
|
|
2502
2510
|
}
|
|
2503
2511
|
else {
|
|
2504
|
-
forkedId = (await opts.runner.sessions.fork?.(ctx.sessionId, forkTree.owner)) ?? null;
|
|
2512
|
+
forkedId = (await opts.runner.sessions.fork?.(ctx.sessionId, forkTree.owner, declaresSubagentPlacement(opts.runner.sessions) ? forkOpts : undefined)) ?? null;
|
|
2505
2513
|
}
|
|
2506
2514
|
}
|
|
2507
2515
|
catch (e) {
|
|
@@ -2551,7 +2559,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2551
2559
|
const forkSettleId = forkSettlementSeat !== undefined ? `bg-${uuidv7()}` : undefined;
|
|
2552
2560
|
if (forkSettlementSeat !== undefined && forkSettleId !== undefined) {
|
|
2553
2561
|
try {
|
|
2554
|
-
registerDelegationLaunch(forkSettlementSeat.
|
|
2562
|
+
await registerDelegationLaunch(forkSettlementSeat.governance, { settleId: forkSettleId, sessionId: forkSettlementSeat.sessionId, now: Date.now, ...(ctx.toolCallId !== undefined ? { toolUseId: ctx.toolCallId } : {}) });
|
|
2555
2563
|
}
|
|
2556
2564
|
catch (e) {
|
|
2557
2565
|
dropHostAbortListener();
|
|
@@ -2563,7 +2571,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2563
2571
|
});
|
|
2564
2572
|
}
|
|
2565
2573
|
}
|
|
2566
|
-
const settleForkRow = (terminal) => {
|
|
2574
|
+
const settleForkRow = async (terminal) => {
|
|
2567
2575
|
if (forkSettlementSeat === undefined || forkSettleId === undefined)
|
|
2568
2576
|
return;
|
|
2569
2577
|
const att = terminal !== undefined ? childAttestation(terminal.kind === "completed") : undefined;
|
|
@@ -2572,7 +2580,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2572
2580
|
let lastErr;
|
|
2573
2581
|
for (let attempt = 0; attempt < 3 && !settled; attempt++) {
|
|
2574
2582
|
try {
|
|
2575
|
-
settleDelegation(forkSettlementSeat.
|
|
2583
|
+
await settleDelegation(forkSettlementSeat.governance, { settleId: forkSettleId, status: verdict, now: Date.now });
|
|
2576
2584
|
settled = true;
|
|
2577
2585
|
}
|
|
2578
2586
|
catch (e) {
|
|
@@ -2581,7 +2589,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2581
2589
|
}
|
|
2582
2590
|
if (settled && verdict === "external") {
|
|
2583
2591
|
try {
|
|
2584
|
-
replayExternalSettlementEffects(forkSettlementSeat.controlDir, { carry: true, now: Date.now });
|
|
2592
|
+
await replayExternalSettlementEffects(forkSettlementSeat.governance, forkSettlementSeat.controlDir, { carry: true, now: Date.now });
|
|
2585
2593
|
}
|
|
2586
2594
|
catch {
|
|
2587
2595
|
}
|
|
@@ -2594,6 +2602,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2594
2602
|
let taskId;
|
|
2595
2603
|
try {
|
|
2596
2604
|
taskId = bg.registry.registerBackgroundAgent({
|
|
2605
|
+
...(forkPlacementHandle !== undefined ? { id: forkPlacementHandle } : {}),
|
|
2597
2606
|
...(bgOwner !== undefined ? { owner: bgOwner } : {}),
|
|
2598
2607
|
...(bgScope !== undefined ? { scope: bgScope } : {}),
|
|
2599
2608
|
...(sessionScopedBg ? { sessionScoped: true } : {}),
|
|
@@ -2621,7 +2630,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2621
2630
|
const wt = await finishWorktree();
|
|
2622
2631
|
if (forkSettlementSeat !== undefined && forkSettleId !== undefined) {
|
|
2623
2632
|
try {
|
|
2624
|
-
settleDelegation(forkSettlementSeat.
|
|
2633
|
+
await settleDelegation(forkSettlementSeat.governance, { settleId: forkSettleId, status: "void", now: Date.now, note: "registration failed before invoke (not dispatched)" });
|
|
2625
2634
|
}
|
|
2626
2635
|
catch {
|
|
2627
2636
|
}
|
|
@@ -2765,8 +2774,9 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2765
2774
|
void bgForkChild
|
|
2766
2775
|
.then(async (child) => {
|
|
2767
2776
|
const childFace = childTerminalFace(child.terminal);
|
|
2768
|
-
settleForkRow(child.terminal);
|
|
2777
|
+
const forkSettled = settleForkRow(child.terminal);
|
|
2769
2778
|
dropHostAbortListener();
|
|
2779
|
+
await forkSettled;
|
|
2770
2780
|
await finishWorktree(child.terminal);
|
|
2771
2781
|
try {
|
|
2772
2782
|
const nsb = child.stats.nested;
|
|
@@ -2847,7 +2857,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2847
2857
|
}
|
|
2848
2858
|
})
|
|
2849
2859
|
.catch((e) => {
|
|
2850
|
-
settleForkRow({ kind: "failed" });
|
|
2860
|
+
void settleForkRow({ kind: "failed" });
|
|
2851
2861
|
dropHostAbortListener();
|
|
2852
2862
|
void finishWorktree();
|
|
2853
2863
|
const killed = abort.signal.aborted;
|
|
@@ -3020,6 +3030,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3020
3030
|
const abort = new AbortController();
|
|
3021
3031
|
const reviveRow = reviveClaim?.row;
|
|
3022
3032
|
const parkedResume = reviveClaim?.parkedResume;
|
|
3033
|
+
let cycleSink = parkedResume !== undefined && parkedLane !== undefined ? parkedLane : notify;
|
|
3023
3034
|
const sessionScopedBg = reviveRow !== undefined ? reviveRow.sessionScoped : ctx.backgroundScope === "session" && ctx.sessionId !== undefined;
|
|
3024
3035
|
const outlivesThisRequest = sessionScopedBg || reviveRow !== undefined;
|
|
3025
3036
|
const onHostAbort = () => abort.abort();
|
|
@@ -3035,7 +3046,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3035
3046
|
const bgScope = treeScope;
|
|
3036
3047
|
const childTreeOwner = () => (reviveRow !== undefined ? rowOwnerReading(opts.runner.sessions, reviveRow.sessionId) : delegationOwnerOf(ctx.delegationOwner));
|
|
3037
3048
|
let placedTreeOwner;
|
|
3038
|
-
if (reviveRow === undefined && bg.agentStore
|
|
3049
|
+
if (reviveRow === undefined && placesSubagentTranscripts(bg.agentStore, opts.runner.sessions)) {
|
|
3039
3050
|
const tree = await childTreeOwner();
|
|
3040
3051
|
if (!tree.bound) {
|
|
3041
3052
|
dropHostAbortListener();
|
|
@@ -3062,7 +3073,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3062
3073
|
const bgSettleId = settlementSeat !== undefined ? `bg-${uuidv7()}` : undefined;
|
|
3063
3074
|
if (settlementSeat !== undefined && bgSettleId !== undefined) {
|
|
3064
3075
|
try {
|
|
3065
|
-
registerDelegationLaunch(settlementSeat.
|
|
3076
|
+
await registerDelegationLaunch(settlementSeat.governance, { settleId: bgSettleId, sessionId: settlementSeat.sessionId, now: Date.now, ...(ctx.toolCallId !== undefined ? { toolUseId: ctx.toolCallId } : {}) });
|
|
3066
3077
|
}
|
|
3067
3078
|
catch (e) {
|
|
3068
3079
|
dropHostAbortListener();
|
|
@@ -3075,7 +3086,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3075
3086
|
});
|
|
3076
3087
|
}
|
|
3077
3088
|
}
|
|
3078
|
-
const settleDelegationRow = (terminal) => {
|
|
3089
|
+
const settleDelegationRow = async (terminal) => {
|
|
3079
3090
|
if (settlementSeat === undefined || bgSettleId === undefined)
|
|
3080
3091
|
return;
|
|
3081
3092
|
const att = terminal !== undefined ? childAttestation(terminal.kind === "completed") : undefined;
|
|
@@ -3084,7 +3095,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3084
3095
|
let lastErr;
|
|
3085
3096
|
for (let attempt = 0; attempt < 3 && !settled; attempt++) {
|
|
3086
3097
|
try {
|
|
3087
|
-
settleDelegation(settlementSeat.
|
|
3098
|
+
await settleDelegation(settlementSeat.governance, { settleId: bgSettleId, status: verdict, now: Date.now });
|
|
3088
3099
|
settled = true;
|
|
3089
3100
|
}
|
|
3090
3101
|
catch (e) {
|
|
@@ -3093,7 +3104,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3093
3104
|
}
|
|
3094
3105
|
if (settled && verdict === "external") {
|
|
3095
3106
|
try {
|
|
3096
|
-
replayExternalSettlementEffects(settlementSeat.controlDir, { carry: true, now: Date.now });
|
|
3107
|
+
await replayExternalSettlementEffects(settlementSeat.governance, settlementSeat.controlDir, { carry: true, now: Date.now });
|
|
3097
3108
|
}
|
|
3098
3109
|
catch {
|
|
3099
3110
|
}
|
|
@@ -3164,7 +3175,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3164
3175
|
const wt = await finishWorktree();
|
|
3165
3176
|
if (settlementSeat !== undefined && bgSettleId !== undefined) {
|
|
3166
3177
|
try {
|
|
3167
|
-
settleDelegation(settlementSeat.
|
|
3178
|
+
await settleDelegation(settlementSeat.governance, { settleId: bgSettleId, status: "void", now: Date.now, note: "registration failed before invoke (not dispatched)" });
|
|
3168
3179
|
}
|
|
3169
3180
|
catch {
|
|
3170
3181
|
}
|
|
@@ -3173,7 +3184,8 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3173
3184
|
}
|
|
3174
3185
|
if (capLedgerKey !== undefined)
|
|
3175
3186
|
chargeDelegationEntryHandle(bg.registry, capLedgerKey, bg.agentStore, reviveRow === undefined ? taskId : undefined);
|
|
3176
|
-
|
|
3187
|
+
if (parkedResume === undefined)
|
|
3188
|
+
oweTerminalDelivery(notify, { task_id: taskId, task_type: "background_agent" });
|
|
3177
3189
|
childInternals.peerSelfRef?.addAxis("h", taskId);
|
|
3178
3190
|
if (agentName !== undefined) {
|
|
3179
3191
|
recordRosterSpawn(ctx.roster, { name: agentName, agentId: taskId, toolUseId: ctx.toolCallId, owner: bgOwner, scope: bgScope, ...(reviveRow !== undefined ? (reviveRow.model !== undefined ? { model: reviveRow.model } : {}) : rowModelKey !== undefined ? { model: rowModelKey } : {}), ...(modelFallback !== undefined ? { modelFallback } : {}), ...(reviveRow !== undefined ? ((reviveRow.rootSessionId ?? reviveRow.parentSessionId) !== undefined ? { rootSessionId: reviveRow.rootSessionId ?? reviveRow.parentSessionId } : {}) : (ctx.rootSessionId ?? ctx.sessionId) !== undefined ? { rootSessionId: ctx.rootSessionId ?? ctx.sessionId } : {}), ...(sessionScopedBg ? { sessionScoped: true } : {}), createdAt: reviveRow?.spawnedAt ?? Date.now() }, (err) => opts.onObserverError?.(err, { site: "roster.recordSpawn" }));
|
|
@@ -3191,24 +3203,30 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3191
3203
|
stepRecorder.lockTo(taskId);
|
|
3192
3204
|
bg.registry.bindBackgroundAgentSession(taskId, bgChildSessionId, opts.runner.sessions);
|
|
3193
3205
|
const bgCycleSeq = bg.registry.backgroundAgentCycleSeq(taskId);
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
const
|
|
3198
|
-
const
|
|
3206
|
+
let retainedCycle;
|
|
3207
|
+
const cycleSeqOfFrames = () => retainedCycle?.cycleSeq ?? (parkedResume !== undefined ? (reviveRow?.seq ?? 1) + 1 : reviveRow?.seq);
|
|
3208
|
+
bg.registry.attachAgentTerminalNotifier(taskId, (ending) => {
|
|
3209
|
+
const stoppedByLanded = ending.status === "killed" ? bg.registry.getStopAttribution(taskId) ?? "system" : undefined;
|
|
3210
|
+
const completionIdLanded = bg.registry.getCompletionId(taskId);
|
|
3211
|
+
const seqLanded = bg.registry.backgroundAgentCycleSeq(taskId);
|
|
3212
|
+
const landedElapsedMs = Date.now() - bgStartedAt;
|
|
3213
|
+
const landedFrame = {
|
|
3199
3214
|
task_id: taskId,
|
|
3200
3215
|
task_type: "background_agent",
|
|
3201
3216
|
toolUseId: ctx.toolCallId,
|
|
3202
|
-
status:
|
|
3217
|
+
status: ending.status,
|
|
3203
3218
|
...terminalFrameFacets({ spawnName: agentName }),
|
|
3204
|
-
|
|
3205
|
-
|
|
3219
|
+
...(cycleSeqOfFrames() !== undefined ? { seq: cycleSeqOfFrames() } : {}),
|
|
3220
|
+
...(stoppedByLanded !== undefined ? { stoppedBy: stoppedByLanded } : {}),
|
|
3221
|
+
summary: ending.status === "failed" ? `Agent "${shortDesc}" failed: ${ending.error ?? "ended"}${ccElapsedTag(landedElapsedMs)}`.slice(0, 300) : ccCompletionText(shortDesc, "killed", "killed", landedElapsedMs),
|
|
3222
|
+
...(ending.status === "failed" && ending.error !== undefined ? { error: ending.error.slice(0, REPORT_FIELD_MAX) } : {}),
|
|
3206
3223
|
sessionId: bgChildSessionId,
|
|
3207
3224
|
resumable: false,
|
|
3208
|
-
...(
|
|
3225
|
+
...(completionIdLanded !== undefined ? { completionId: completionIdLanded } : {}),
|
|
3209
3226
|
};
|
|
3210
|
-
sinkEmit(backgroundChildTerminal(
|
|
3211
|
-
|
|
3227
|
+
sinkEmit(backgroundChildTerminal(landedFrame, { taskId, sessionScoped: sessionScopedBg === true, sessionId: bgChildSessionId, transcriptId: bgChildSessionId, parentToolCallId: ctx.toolCallId, ...(seqLanded !== undefined ? { generation: seqLanded } : {}) }));
|
|
3228
|
+
const landedLane = ending.parkLane ?? cycleSink;
|
|
3229
|
+
notifier.notify(() => landedLane?.(landedFrame, { priority: "next" }), "subagent.landedTerminalNotify");
|
|
3212
3230
|
});
|
|
3213
3231
|
const bgDurableProbe = bg.registry.durableAgentRowProbe(taskId);
|
|
3214
3232
|
const bgRowConfirmed = async () => (bgDurableProbe ? await bgDurableProbe().catch(() => false) : false);
|
|
@@ -3249,6 +3267,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3249
3267
|
if (sessionScopedBg && bgRetainLedger)
|
|
3250
3268
|
ensureSessionReapHook(bg.registry);
|
|
3251
3269
|
const bgRetain = await tryRetainChild(bgRetainLedger, sessionScopedBg && ctx.subagentRetain ? ctx.subagentRetain.ttlMs : undefined, bgChildSessionId, bgDurableProbe, { registry: bg.registry, taskId }, backgroundLegFacts(taskId));
|
|
3270
|
+
retainedCycle = bgRetain;
|
|
3252
3271
|
if (bgRetain) {
|
|
3253
3272
|
bg.registry.markRetainedContinuation(taskId);
|
|
3254
3273
|
const origRelease = bgRetain.release;
|
|
@@ -3300,17 +3319,8 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3300
3319
|
usage: { toolUses: toolStarts },
|
|
3301
3320
|
});
|
|
3302
3321
|
}, () => bg.registry.noteBackgroundAgentActivity(taskId));
|
|
3303
|
-
const bgPlacementRoot = ctx.rootSessionId ?? ctx.sessionId;
|
|
3304
|
-
const bgPlacementParent = ctx.sessionId;
|
|
3305
3322
|
const bgPlacement = placedTreeOwner !== undefined
|
|
3306
|
-
? {
|
|
3307
|
-
kind: "subagent",
|
|
3308
|
-
...(bgScope !== undefined ? { scope: bgScope } : {}),
|
|
3309
|
-
...(bgPlacementParent !== undefined ? { parentSessionId: bgPlacementParent } : {}),
|
|
3310
|
-
...(bgPlacementRoot !== undefined ? { rootSessionId: bgPlacementRoot } : {}),
|
|
3311
|
-
handle: taskId,
|
|
3312
|
-
owner: placedTreeOwner,
|
|
3313
|
-
}
|
|
3323
|
+
? { ...subagentTranscriptPlacement(ctx, bgScope, taskId), owner: placedTreeOwner }
|
|
3314
3324
|
: undefined;
|
|
3315
3325
|
const bgInternals = bgSink
|
|
3316
3326
|
? {
|
|
@@ -3367,6 +3377,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3367
3377
|
const driveParkedResume = async () => {
|
|
3368
3378
|
const pr = parkedResume;
|
|
3369
3379
|
const claimStores = { agentStore: bg.agentStore, checkpointStore: childParkStore };
|
|
3380
|
+
let consumed = false;
|
|
3370
3381
|
const rollbackAndThrow = async (e) => {
|
|
3371
3382
|
let disp = "retry";
|
|
3372
3383
|
try {
|
|
@@ -3374,6 +3385,8 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3374
3385
|
}
|
|
3375
3386
|
catch {
|
|
3376
3387
|
}
|
|
3388
|
+
if (!consumed && disp !== "failed")
|
|
3389
|
+
cycleSink = undefined;
|
|
3377
3390
|
const msg = thrownText(e);
|
|
3378
3391
|
throw new Error(disp === "rolled_back"
|
|
3379
3392
|
? `parked resume rolled back — the approval is still pending (retryable): ${msg}`
|
|
@@ -3432,6 +3445,16 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3432
3445
|
const won = await bg.registry.consumeParkedFlip(taskId, { agentStore: bg.agentStore }, pr.ticket);
|
|
3433
3446
|
if (!won)
|
|
3434
3447
|
throw new Error("the parked row moved under the resume (a stop or another transition won) — resume aborted");
|
|
3448
|
+
moveTerminalDelivery(parkedLane, notify, { task_id: taskId, task_type: "background_agent" });
|
|
3449
|
+
cycleSink = notify;
|
|
3450
|
+
consumed = true;
|
|
3451
|
+
if (parkedLane === undefined && ctx.onTaskNotification === undefined) {
|
|
3452
|
+
deliverEngineNotice(undefined, {
|
|
3453
|
+
code: "delegation.resume_lane_missing",
|
|
3454
|
+
message: `the parked agent ${taskId} was resumed with no run lane in this process to complete into (it parked in another process, or before this one restarted): its completion goes to the deployment's background channel, and a submission still waiting on it elsewhere is not settled by it`,
|
|
3455
|
+
detail: { taskId, ...(reviveRow?.rootSessionId !== undefined ? { rootSessionId: reviveRow.rootSessionId } : {}) },
|
|
3456
|
+
});
|
|
3457
|
+
}
|
|
3435
3458
|
};
|
|
3436
3459
|
let childResult;
|
|
3437
3460
|
try {
|
|
@@ -3478,8 +3501,9 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3478
3501
|
reopened = false;
|
|
3479
3502
|
}
|
|
3480
3503
|
if (reopened) {
|
|
3481
|
-
bg.registry.parkBackgroundAgent(taskId, {
|
|
3504
|
+
const reParked = bg.registry.parkBackgroundAgent(taskId, {
|
|
3482
3505
|
checkpointToken: pr.ticket.token,
|
|
3506
|
+
completionSink: cycleSink,
|
|
3483
3507
|
resolveStop: async () => {
|
|
3484
3508
|
const cpS = childParkStore;
|
|
3485
3509
|
const cp = (await cpS.get(pr.ticket.token));
|
|
@@ -3488,6 +3512,8 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3488
3512
|
return await cpS.expire(pr.ticket.token, cp.scope);
|
|
3489
3513
|
},
|
|
3490
3514
|
});
|
|
3515
|
+
if (reParked === "parked")
|
|
3516
|
+
cycleSink = undefined;
|
|
3491
3517
|
throw new Error(`parked resume could not complete and the approval was REOPENED (still approvable/retryable): ${childResult.terminal.message ?? "failed"}`, { cause: childResult.terminal });
|
|
3492
3518
|
}
|
|
3493
3519
|
}
|
|
@@ -3510,9 +3536,10 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3510
3536
|
void bgChildPromise
|
|
3511
3537
|
.then(async (child) => {
|
|
3512
3538
|
const childFace = childTerminalFace(child.terminal);
|
|
3513
|
-
settleDelegationRow(child.terminal);
|
|
3539
|
+
const rowSettled = settleDelegationRow(child.terminal);
|
|
3514
3540
|
closeObserverWindow(childFace.status);
|
|
3515
3541
|
dropHostAbortListener();
|
|
3542
|
+
await rowSettled;
|
|
3516
3543
|
await finishWorktree(child.terminal);
|
|
3517
3544
|
try {
|
|
3518
3545
|
const ns2 = child.stats.nested;
|
|
@@ -3525,7 +3552,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3525
3552
|
}
|
|
3526
3553
|
catch {
|
|
3527
3554
|
}
|
|
3528
|
-
const seqAtSettle =
|
|
3555
|
+
const seqAtSettle = cycleSeqOfFrames();
|
|
3529
3556
|
const bgHandbackWarning = isDurablePause(child.terminal)
|
|
3530
3557
|
? undefined
|
|
3531
3558
|
: await reviewHandback({
|
|
@@ -3581,6 +3608,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3581
3608
|
? bg.registry.parkBackgroundAgent(taskId, {
|
|
3582
3609
|
checkpointToken: token,
|
|
3583
3610
|
seq: seqAtSettle ?? 1,
|
|
3611
|
+
completionSink: cycleSink,
|
|
3584
3612
|
resolveStop: async () => {
|
|
3585
3613
|
const cpS = childParkStore;
|
|
3586
3614
|
const cp = (await cpS.get(token));
|
|
@@ -3648,7 +3676,8 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3648
3676
|
const bgTerminalSummary = failReasonBg !== undefined
|
|
3649
3677
|
? `Agent "${shortDesc}" failed: ${failReasonBg}${ccElapsedTag(bgElapsedMs)}${observerNote}`.slice(0, 300) + errorKindClause(errClassBg)
|
|
3650
3678
|
: `${ccCompletionText(shortDesc, settled, childFace.status, bgElapsedMs)}${observerNote}`;
|
|
3651
|
-
const
|
|
3679
|
+
const completionSink = cycleSink;
|
|
3680
|
+
const ownsTerminalFaces = completionSink !== undefined && bg.registry.claimAgentTerminalNotify(taskId);
|
|
3652
3681
|
const bgResultField = await completionResultField(bgHandbackResult, (report) => persistTaskArtifact(ctx.taskArtifacts, taskId, report), (ref) => bg.registry.recordArtifactRef(taskId, ref, completionIdBg), notifier);
|
|
3653
3682
|
const completionFrame = {
|
|
3654
3683
|
task_id: taskId,
|
|
@@ -3681,24 +3710,25 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3681
3710
|
owners: gateOwners,
|
|
3682
3711
|
pendingCount: aliveBgCount,
|
|
3683
3712
|
payload: completionFrame,
|
|
3684
|
-
notify,
|
|
3713
|
+
notify: completionSink,
|
|
3685
3714
|
});
|
|
3686
3715
|
}
|
|
3687
3716
|
else if (ownsTerminalFaces) {
|
|
3688
3717
|
try {
|
|
3689
|
-
|
|
3718
|
+
completionSink(completionFrame, { priority: "next" });
|
|
3690
3719
|
}
|
|
3691
3720
|
catch {
|
|
3692
3721
|
}
|
|
3693
3722
|
}
|
|
3694
3723
|
})
|
|
3695
3724
|
.catch(async (e) => {
|
|
3696
|
-
settleDelegationRow({ kind: "failed" });
|
|
3725
|
+
const rowSettled = settleDelegationRow({ kind: "failed" });
|
|
3697
3726
|
closeObserverWindow("failed");
|
|
3698
3727
|
dropHostAbortListener();
|
|
3728
|
+
await rowSettled;
|
|
3699
3729
|
void finishWorktree();
|
|
3700
3730
|
const killed = abort.signal.aborted;
|
|
3701
|
-
const seqAtSettle =
|
|
3731
|
+
const seqAtSettle = cycleSeqOfFrames();
|
|
3702
3732
|
if (bgRetain) {
|
|
3703
3733
|
if (killed)
|
|
3704
3734
|
void bgRetainLedger?.evict(ctx.toolCallId);
|
|
@@ -3723,7 +3753,8 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3723
3753
|
}
|
|
3724
3754
|
const stoppedBy = settled === "killed" ? bg.registry.getStopAttribution(taskId) ?? "system" : undefined;
|
|
3725
3755
|
const observerNote = observerNoteFor(await startBoundedObserverDrain());
|
|
3726
|
-
const
|
|
3756
|
+
const rejectSink = cycleSink;
|
|
3757
|
+
const ownsTerminalFacesReject = rejectSink !== undefined && bg.registry.claimAgentTerminalNotify(taskId);
|
|
3727
3758
|
const rejectFrame = {
|
|
3728
3759
|
task_id: taskId,
|
|
3729
3760
|
task_type: "background_agent",
|
|
@@ -3742,7 +3773,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3742
3773
|
sinkEmit(backgroundChildTerminal(rejectFrame, { taskId, sessionScoped: sessionScopedBg === true, sessionId: bgChildSessionId, transcriptId: bgChildSessionId, parentToolCallId: ctx.toolCallId, ...(bgCycleSeq !== undefined ? { generation: bgCycleSeq } : {}) }));
|
|
3743
3774
|
try {
|
|
3744
3775
|
if (ownsTerminalFacesReject)
|
|
3745
|
-
|
|
3776
|
+
rejectSink(rejectFrame, { priority: "next" });
|
|
3746
3777
|
}
|
|
3747
3778
|
catch {
|
|
3748
3779
|
}
|
|
@@ -5,9 +5,9 @@ import { receiptRefusal, receiveOwnProperties } from "../core/own-property-recei
|
|
|
5
5
|
import { credentialHeaderValues, holdOwnCredentialValues, isBlankCredential, isCredentialHeaderName, isSchemedCredentialHeader } from "../core/secret-env.js";
|
|
6
6
|
import { deliverEngineNotice } from "../core/engine-notice.js";
|
|
7
7
|
import { uuidv7 } from "../engine/session/uuid.js";
|
|
8
|
-
import { REDACTION_MARKS } from "../core/redaction-marks.js";
|
|
9
|
-
import {
|
|
10
|
-
const REDACTED_VALUE =
|
|
8
|
+
import { REDACTION_MARKS, WITHHELD_VALUE_MARK } from "../core/redaction-marks.js";
|
|
9
|
+
import { CREDENTIAL_VOCABULARY } from "@sema-agent/primitives";
|
|
10
|
+
const REDACTED_VALUE = WITHHELD_VALUE_MARK;
|
|
11
11
|
const REDACTED_CREDENTIALS = REDACTION_MARKS.credentials;
|
|
12
12
|
function servableParse(raw) {
|
|
13
13
|
let u;
|
|
@@ -181,7 +181,12 @@ export function joinRequestUrl(root, suffix) {
|
|
|
181
181
|
}
|
|
182
182
|
return composed;
|
|
183
183
|
}
|
|
184
|
-
const AUTHORITY_USERINFO =
|
|
184
|
+
const AUTHORITY_USERINFO = (() => {
|
|
185
|
+
const row = CREDENTIAL_VOCABULARY.values.find((r) => r.id === "url-userinfo");
|
|
186
|
+
if (row === undefined)
|
|
187
|
+
throw new Error('route-adjudicator: the credential vocabulary has no "url-userinfo" row');
|
|
188
|
+
return new RegExp(row.match.source, row.match.flags);
|
|
189
|
+
})();
|
|
185
190
|
export function stripUrlCredentials(text) {
|
|
186
191
|
return text.replace(AUTHORITY_USERINFO, `$1${REDACTED_CREDENTIALS}@`);
|
|
187
192
|
}
|
|
@@ -81,7 +81,7 @@ function judgeTool(row, live, station) {
|
|
|
81
81
|
return { member: "tool", disposition: "veto", code: "resume.target_moved", message: vetoed(row.toolName, "the tool's declaration (what it does, reaches and trusts: its effect, egress, irreversibility, content origin, boundary legs, rule face or model gate) changed after the approval") };
|
|
82
82
|
}
|
|
83
83
|
function judgeTargets(row, live) {
|
|
84
|
-
if ((row.targets === undefined && row.targetReads === undefined) || ("decided" in live && !licenseCovers(row.boundInputHash, live.decided)))
|
|
84
|
+
if ((row.targets === undefined && row.targetReads === undefined) || ("decided" in live && !licenseCovers(row.boundInputHash, row.toolName, live.decided)))
|
|
85
85
|
return undefined;
|
|
86
86
|
const why = landedElsewhere(row.targets, row.targetReads, live);
|
|
87
87
|
return why === undefined ? undefined : { member: "targets", disposition: "veto", code: "resume.target_moved", message: vetoed(row.toolName, why) };
|
package/dist/core/arg-summary.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readProgramPosition } from "../tools/fs/bash-program-position.js";
|
|
2
2
|
import { argvOf, lexShell } from "../shell/lex.js";
|
|
3
|
-
import { isSensitiveRecordKey } from "
|
|
3
|
+
import { isSensitiveRecordKey } from "@sema-agent/primitives";
|
|
4
4
|
import { egressText } from "./untrusted-egress.js";
|
|
5
5
|
const ACTIVITY_ARG_MAX = 80;
|
|
6
6
|
function truncCodePoints(s) {
|
|
@@ -77,8 +77,8 @@ export interface AskQuestionRequest {
|
|
|
77
77
|
* question. `readonly` + same caveat as `principal`. */
|
|
78
78
|
readonly agentId?: string;
|
|
79
79
|
/**
|
|
80
|
-
* The canonical hash of the tool
|
|
81
|
-
* engine's one `
|
|
80
|
+
* The canonical hash of the tool call this question was built from — the call's tool and its arguments, as computed by
|
|
81
|
+
* the engine's one call binding `exactBoundInputHashOf` (the same digest the durable park binds its checkpoint to, so the
|
|
82
82
|
* two lanes are reconcilable against each other). Present only when the engine routed the question
|
|
83
83
|
* — a directly-mounted tool calling its own face carries none.
|
|
84
84
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ReceiptFault } from "./mods/kernel/receive.js";
|
|
2
2
|
/**
|
|
3
3
|
* design/80 D-1 §2 (slice 1a.2) — the engine-only **vetted canonical serializer** used to mint a stable,
|
|
4
|
-
* opaque {@link
|
|
4
|
+
* opaque {@link exactBoundInputHashOf | boundInputHash} over a pending tool call: its tool's name and its arguments.
|
|
5
5
|
*
|
|
6
6
|
* ## Why a bespoke serializer (and why engine-ONLY)
|
|
7
7
|
* The package's only runtime deps are typebox + the MCP SDK — there is no canonical/stable JSON serializer,
|
|
@@ -19,7 +19,9 @@ import { type ReceiptFault } from "./mods/kernel/receive.js";
|
|
|
19
19
|
* ## Canonical form
|
|
20
20
|
* A total function (never throws) that emits a **type-tagged, length-prefixed** string so distinct values of
|
|
21
21
|
* distinct types can never collide (`number 1` ≠ `string "1"` ≠ `boolean`, and `{"a":"b"}` ≠ `{"ab":""}`):
|
|
22
|
-
* - `null` → `N`, `undefined` → `U
|
|
22
|
+
* - `null` → `N`, `undefined` → `U`, at any depth: `{a:undefined}` and `{}` are two forms — the form a workflow call's journal
|
|
23
|
+
* key, the rewrite judge, a file rule store's checksum, a wiring fingerprint and every other digest of a value taken here
|
|
24
|
+
* read; a call's approval binding digests the arguments' JSON form ({@link exactBoundInputHashOf})
|
|
23
25
|
* - boolean → `b1` / `b0`
|
|
24
26
|
* - number → `n:<canonical>`; finite via `String(x)` (shortest round-trippable, deterministic per value);
|
|
25
27
|
* `-0` normalized to `0`; `NaN`/`±Infinity` get explicit distinct tokens (never collapsed to `null`)
|
|
@@ -55,18 +57,26 @@ export declare function canonicalize(value: unknown, standsAt?: number): string;
|
|
|
55
57
|
* constant (the checkpoint row digest) refuses on it. */
|
|
56
58
|
export declare const UNCANONICALIZABLE = "<uncanonicalizable>";
|
|
57
59
|
/**
|
|
58
|
-
* design/80 D-1 §2 —
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
60
|
+
* design/80 D-1 §2 — a SHA-256 (hex) over {@link canonicalize}: the engine's one digest of a value. A call's binding is this digest
|
|
61
|
+
* over `{ tool, input }` ({@link exactBoundInputHashOf}); the other digests the engine takes of a value (a Skill card's lists, a
|
|
62
|
+
* tool's declaration, a question batch) are this digest over that value. The hex digest is fixed-length and opaque — exactly
|
|
63
|
+
* what the operator sees / the D-G signer signs.
|
|
62
64
|
*/
|
|
63
65
|
export declare function boundInputHashOf(value: unknown): string;
|
|
64
66
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
67
|
+
* THE digest an approval binds a CALL by: SHA-256 (hex) over the canonical form of the one record `{ tool, input }` — the tool's name as the
|
|
68
|
+
* call spells it and the arguments in their JSON form ({@link capturedJsonOf}: a record member holding `undefined` absent), one
|
|
69
|
+
* digest for the call in memory and after a durable store's JSON round trip — when an approval can be bound to the arguments
|
|
70
|
+
* ({@link bindableValueOf}), else `undefined`.
|
|
71
|
+
* Every binding of a call mints through it and every comparison of one reads it: the park row's `boundInputHash`, the live ask's
|
|
72
|
+
* and the routed question's reconciliation hash, and an answer's licensed bytes (`inputDigest`, compared by `licenseCovers`) — so
|
|
73
|
+
* one approval covers one tool over one set of bytes, and a call of another tool over the same bytes under the same call id is
|
|
74
|
+
* another question. The name is read as given (no alias or case is resolved: the row, the ask and the record each carry the
|
|
75
|
+
* call's own `toolName`). The record only HOLDS the two members (it is canonicalized at depth −1, {@link canonicalize}), so the
|
|
76
|
+
* arguments count their containers as when digested alone and the form is exact over the whole bindable domain; key order is
|
|
77
|
+
* the serializer's own (sorted), so the two members cannot be permuted.
|
|
68
78
|
*/
|
|
69
|
-
export declare function exactBoundInputHashOf(
|
|
79
|
+
export declare function exactBoundInputHashOf(tool: string, input: unknown): string | undefined;
|
|
70
80
|
/**
|
|
71
81
|
* Why a value is outside the bindable domain: its top is not the payload's shape, a refusal of the receipt it is read by, or one of
|
|
72
82
|
* JSON's own five — a number that is not finite, a hole in a list, a named member on a list, an `undefined` list element, one
|
|
@@ -78,8 +88,8 @@ export type BindingFault = ReceiptFault | {
|
|
|
78
88
|
};
|
|
79
89
|
/**
|
|
80
90
|
* THE judge of the BINDABLE domain — the values an approval can be bound to, and so the only values with an exact digest: plain
|
|
81
|
-
* JSON data (records, dense lists, strings, finite numbers, booleans, `null`; a record member
|
|
82
|
-
*
|
|
91
|
+
* JSON data (records, dense lists, strings, finite numbers, booleans, `null`; a record member holding `undefined` is legal and
|
|
92
|
+
* kept on the copy as given) under a top of the payload's own shape (`top`: a call's arguments are a RECORD — the default, and the
|
|
83
93
|
* only shape an exact digest is taken of; a question's answers are a LIST), a tree (no object met twice), at most 256 levels of
|
|
84
94
|
* containers. Read by the engine's one receipt of a caller's value in {@link BINDING_RECEIPT} (nothing of the caller's runs: a
|
|
85
95
|
* getter, a hidden or symbol-keyed member, a Proxy, a function, a symbol, a bigint, a Map / Set / Date / binary or any other kind
|
|
@@ -96,7 +106,7 @@ export declare function bindableValueOf(value: unknown, top?: BindingTop): {
|
|
|
96
106
|
export type BindingTop = "record" | "list";
|
|
97
107
|
/** THE capture of a caller-supplied payload the engine persists and later compares (a durable decide's edit — a record —, a
|
|
98
108
|
* question's answers — a list): the judge's receipt ({@link bindableValueOf}) kept in the form a durable store's JSON round trip
|
|
99
|
-
* hands back ({@link jsonFormOf}). */
|
|
109
|
+
* hands back ({@link jsonFormOf}) — the form a call's binding digests ({@link exactBoundInputHashOf}). */
|
|
100
110
|
export declare function capturedJsonOf(value: unknown, top?: BindingTop): {
|
|
101
111
|
readonly ok: true;
|
|
102
112
|
readonly value: unknown;
|
|
@@ -13,11 +13,11 @@ export const UNCANONICALIZABLE = "<uncanonicalizable>";
|
|
|
13
13
|
export function boundInputHashOf(value) {
|
|
14
14
|
return createHash("sha256").update(canonicalize(value), "utf8").digest("hex");
|
|
15
15
|
}
|
|
16
|
-
export function exactBoundInputHashOf(
|
|
17
|
-
const
|
|
18
|
-
if (!
|
|
16
|
+
export function exactBoundInputHashOf(tool, input) {
|
|
17
|
+
const captured = capturedJsonOf(input);
|
|
18
|
+
if (!captured.ok)
|
|
19
19
|
return undefined;
|
|
20
|
-
const form = canonicalize(
|
|
20
|
+
const form = canonicalize({ tool, input: captured.value }, -1);
|
|
21
21
|
return form === UNCANONICALIZABLE ? undefined : createHash("sha256").update(form, "utf8").digest("hex");
|
|
22
22
|
}
|
|
23
23
|
export function bindableValueOf(value, top = "record") {
|