@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
|
@@ -35,7 +35,7 @@ import { reviewSubjectOf } from "../agents/delegation-review-faces.js";
|
|
|
35
35
|
import { OUTPUT_TOOL_NAME, TOOL_CATALOG_ENTRIES } from "../core/tool-catalog-entries.js";
|
|
36
36
|
import { readDelegationReview } from "../core/classifier-unavailable-arm.js";
|
|
37
37
|
import { judgeHostToolCeiling, refuseUnusableDefinition } from "../core/runner/sub-agent-deny-lists.js";
|
|
38
|
-
import { definitionSelectorLayer,
|
|
38
|
+
import { announceShadowedDefinitionServers, definitionSelectorLayer, mergeDefinitionServers } from "../agents/inherited-tool-pool.js";
|
|
39
39
|
import { isToolSelectorLayer } from "../agents/tool-filter.js";
|
|
40
40
|
import { legRetiredNameView, selectorLayerUnderView } from "../core/tool-name-aliases.js";
|
|
41
41
|
import { snapshotToolNameList } from "../core/tool-name-list.js";
|
|
@@ -47,7 +47,8 @@ import { callerPlacementSeats } from "../core/runner/child-tree.js";
|
|
|
47
47
|
import { judgedOwnerSeat } from "../core/runner/delegation-owner.js";
|
|
48
48
|
import { WorkflowBudgetExceededError, WorkflowNestingError, WorkflowAgentBlockedError, WorkflowAgentParkedError, WorkflowAgentSchemaError, WorkflowAgentStalledError, WorkflowMaxAgentsError, WORKFLOW_SPAWN_BLOCKED_ERROR_CODE, WORKFLOW_AGENT_OUTLIVED_RUN_CODE, PARK_NOT_PENDING_STATUSES, WORKFLOW_AGENT_PARKED_ERROR_CODE, WORKFLOW_STORE_WAIT_BOUND_MS, firstFailedAgentCodeOf, parkHolderAmong, runParkedOf, workflowRowStatusOf } from "./workflow-types.js";
|
|
49
49
|
import { memberOutcomeOf, memberRefusalsOf } from "../core/member-outcome.js";
|
|
50
|
-
import { CLAIM_REMAINING_UNREADABLE_NOTE, claimRemainingOf, isAnswerRecordClaimHolder, readWorkflowRunTreeWithin, runThatDrove, storeErrorClassOf, workflowLineForkReason, workflowLineTailOf, workflowParkDecisionOf, workflowRunChildrenIn, workflowRunInTree, workflowRunsBelow, workflowRunTreeOfOne, WORKFLOW_TREE_OVER_BOUND_REASON } from "./workflow-park-adoption.js";
|
|
50
|
+
import { CLAIM_REMAINING_UNREADABLE_NOTE, claimRemainingOf, isAnswerRecordClaimHolder, parkBindingFault, readWorkflowRunTreeWithin, runThatDrove, sameClaimKeys, storeErrorClassOf, workflowClaimKeysOf, workflowLineForkReason, workflowLineTailOf, workflowParkDecisionOf, workflowRunChildrenIn, workflowRunInTree, workflowRunsBelow, workflowRunTreeOfOne, WORKFLOW_TREE_OVER_BOUND_REASON } from "./workflow-park-adoption.js";
|
|
51
|
+
import { dropLocalClaimHolder, holdLocalWorkflowRun, noteLocalClaimHolder, readWorkflowStopper, stopWorkflowTree } from "./workflow-stop.js";
|
|
51
52
|
import { WorkflowScriptError } from "./workflow-meta.js";
|
|
52
53
|
import { firstByteLaneKnobMs, STALL_FIRST_BYTE_MS, STALL_FIRST_TOKEN_MS } from "../brain/timeout.js";
|
|
53
54
|
import { asThrownError, codedRefusal, isErrorLike, readMember, thrownIs, thrownName, thrownText } from "../core/thrown-value.js";
|
|
@@ -69,7 +70,6 @@ const MAX_ACTIVITY = 30;
|
|
|
69
70
|
const MAX_REVIEWED_SCHEMA_BYTES = 4096;
|
|
70
71
|
const MAX_REVIEW_REASON_CHARS = 500;
|
|
71
72
|
const MAX_REVIEWED_PROMPT_CHARS = 2_000;
|
|
72
|
-
const MAX_MEMBER_STOPPER_CHARS = 256;
|
|
73
73
|
const MAX_SCHEMA_WALK_DEPTH = 32;
|
|
74
74
|
function isUsableSchema(v) {
|
|
75
75
|
if (v === true)
|
|
@@ -157,13 +157,18 @@ export function applyWorkflowAgentType(spec, agentType, registry) {
|
|
|
157
157
|
if (out.memoryPersistenceCapable === undefined && def.memoryPersistenceCapable !== undefined)
|
|
158
158
|
out.memoryPersistenceCapable = def.memoryPersistenceCapable;
|
|
159
159
|
const ownServers = def.mcp;
|
|
160
|
-
|
|
161
|
-
|
|
160
|
+
let droppedMcp;
|
|
161
|
+
if (ownServers !== undefined && ownServers.length > 0) {
|
|
162
|
+
const merged = mergeDefinitionServers(out.mcp !== undefined ? snapshotAndValidateMcpEntries(out.mcp) : undefined, ownServers);
|
|
163
|
+
out.mcp = merged.servers;
|
|
164
|
+
if (merged.dropped.length > 0)
|
|
165
|
+
droppedMcp = merged.dropped;
|
|
166
|
+
}
|
|
162
167
|
const lists = { allowTools: snapshotToolNameList(def.allowTools), denyTools: snapshotToolNameList(def.denyTools) };
|
|
163
168
|
if (lists.allowTools == null && lists.denyTools == null)
|
|
164
|
-
return { spec: out, agentType: def.name };
|
|
169
|
+
return { spec: out, agentType: def.name, ...(droppedMcp !== undefined ? { droppedMcp } : {}) };
|
|
165
170
|
refuseUnusableDefinition(def.name, lists);
|
|
166
|
-
return { spec: out, agentType: def.name, definitionToolLists: { agentType: def.name, layer: definitionSelectorLayer({ ...lists, ...(ownServers !== undefined ? { mcp: ownServers } : {}) }) } };
|
|
171
|
+
return { spec: out, agentType: def.name, definitionToolLists: { agentType: def.name, layer: definitionSelectorLayer({ ...lists, ...(ownServers !== undefined ? { mcp: ownServers } : {}) }) }, ...(droppedMcp !== undefined ? { droppedMcp } : {}) };
|
|
167
172
|
}
|
|
168
173
|
export function workflowAgentRegistry(opts) {
|
|
169
174
|
const deployment = (opts.agents ?? []).map(snapshotDefinitionLists);
|
|
@@ -340,6 +345,22 @@ function runStoreUnreadableRefusal(fromRunId, cause) {
|
|
|
340
345
|
const what = cause === undefined ? `no answer within ${WORKFLOW_STORE_WAIT_BOUND_MS}ms, or records that name each other in a loop` : storeErrorClassOf(cause.err);
|
|
341
346
|
return new WorkflowParkRefusal("workflow.park_truth_unreadable", `startWorkflow: resume from "${fromRunId}" was REFUSED — the prior run's record, or that of a run it was resumed from, could not be read from the run store (${what}), so its parks cannot be proven.`, { reason: "store_threw" });
|
|
342
347
|
}
|
|
348
|
+
function claimRefusalOf(what, decision) {
|
|
349
|
+
if (decision.stopped !== undefined) {
|
|
350
|
+
return new Error(`startWorkflow: ${what} was REFUSED — the workflow was stopped (workflow_stopped, by ${clampRunIdText(decision.stopped.by)}): no run of it starts another step. Nothing ran; to run the work again, start the workflow again.`);
|
|
351
|
+
}
|
|
352
|
+
const forAnswer = isAnswerRecordClaimHolder(decision.holder);
|
|
353
|
+
const holder = decision.holder !== undefined && !forAnswer ? clampRunIdText(decision.holder) : "";
|
|
354
|
+
const lapse = decision.lapse;
|
|
355
|
+
return new Error(`startWorkflow: ${what} was REFUSED — ` +
|
|
356
|
+
(forAnswer
|
|
357
|
+
? "another leg of the workflow holds the resume claim on it for a moment, to record a person's answer to continuing it (no run holds it): resume again once it gives the claim back. If that leg's process stopped without giving the claim back, "
|
|
358
|
+
: `another run already holds the resume claim on it${holder ? ` (holder: ${holder})` : " (holder unknown to the store)"}. ` +
|
|
359
|
+
"Two concurrent resumes of one source run fork its execution: both replay the same prefix and then " +
|
|
360
|
+
"re-run the whole suffix live, duplicating every side effect. Wait for the holder to reach a terminal " +
|
|
361
|
+
"state (or stop it) and resume again. If the holder's process stopped without giving the claim back, ") +
|
|
362
|
+
`the claim lapses ${lapse?.kind === "at" ? `at ${new Date(lapse.at).toISOString()} at the latest` : `when the journal store's expiry frees it${lapse?.kind === "unreadable" ? ` (${CLAIM_REMAINING_UNREADABLE_NOTE})` : ""}`}, and the same resume goes through then.`);
|
|
363
|
+
}
|
|
343
364
|
function journalStoreClaimRefusal(fromRunId, err) {
|
|
344
365
|
return new WorkflowParkRefusal("workflow.park_truth_unreadable", `startWorkflow: resume from "${fromRunId}" was REFUSED — the journal store threw while the workflow's resume claim was taken (${storeErrorClassOf(err)}), so nothing guards the resume against another one; nothing ran. Resume again once the journal store answers.`, { reason: "store_threw" });
|
|
345
366
|
}
|
|
@@ -601,9 +622,14 @@ export const workflowResumeClaimFallback = {
|
|
|
601
622
|
table.delete(key);
|
|
602
623
|
},
|
|
603
624
|
};
|
|
604
|
-
export function takeWorkflowResumeClaim(store, input) {
|
|
625
|
+
export function takeWorkflowResumeClaim(store, input, carriesDecision = false) {
|
|
626
|
+
const noted = (v) => {
|
|
627
|
+
if (v.granted)
|
|
628
|
+
noteLocalClaimHolder(input.newRunId, carriesDecision);
|
|
629
|
+
return v;
|
|
630
|
+
};
|
|
605
631
|
if (store.resumeClaim === undefined)
|
|
606
|
-
return Promise.resolve({ ...workflowResumeClaimFallback.acquire(store, input), fallback: true });
|
|
632
|
+
return Promise.resolve(noted({ ...workflowResumeClaimFallback.acquire(store, input), fallback: true }));
|
|
607
633
|
let asked;
|
|
608
634
|
try {
|
|
609
635
|
asked = Promise.resolve(store.resumeClaim(input));
|
|
@@ -614,10 +640,37 @@ export function takeWorkflowResumeClaim(store, input) {
|
|
|
614
640
|
return asked
|
|
615
641
|
.then((v) => {
|
|
616
642
|
const granted = Boolean(v.granted);
|
|
617
|
-
|
|
643
|
+
const by = granted ? undefined : v.stopped?.by;
|
|
644
|
+
return noted({ granted, ...(v.holder !== undefined ? { holder: v.holder } : {}), ...(granted ? {} : { lapse: claimRemainingOf(v, Date.now()) }), ...(typeof by === "string" ? { stopped: { by } } : {}), fallback: false });
|
|
618
645
|
});
|
|
619
646
|
}
|
|
647
|
+
export async function takeWorkflowResumeClaims(store, keys, newRunId, scope, carriesDecision = false) {
|
|
648
|
+
const taken = [];
|
|
649
|
+
const giveBack = () => Promise.all(taken.map((t) => releaseWorkflowResumeClaim(store, t.input, t.fallback)));
|
|
650
|
+
let last = { granted: true, fallback: store.resumeClaim === undefined };
|
|
651
|
+
for (const sourceRunId of keys) {
|
|
652
|
+
const input = { sourceRunId, newRunId, scope };
|
|
653
|
+
try {
|
|
654
|
+
last = await takeWorkflowResumeClaim(store, input, carriesDecision);
|
|
655
|
+
}
|
|
656
|
+
catch (err) {
|
|
657
|
+
await giveBack();
|
|
658
|
+
throw err;
|
|
659
|
+
}
|
|
660
|
+
if (!last.granted) {
|
|
661
|
+
await giveBack();
|
|
662
|
+
return last;
|
|
663
|
+
}
|
|
664
|
+
taken.push({ input, fallback: last.fallback });
|
|
665
|
+
}
|
|
666
|
+
return last;
|
|
667
|
+
}
|
|
668
|
+
export async function releaseWorkflowResumeClaims(store, keys, newRunId, scope, fallback) {
|
|
669
|
+
for (const sourceRunId of keys)
|
|
670
|
+
await releaseWorkflowResumeClaim(store, { sourceRunId, newRunId, scope }, fallback);
|
|
671
|
+
}
|
|
620
672
|
export async function releaseWorkflowResumeClaim(store, input, fallback) {
|
|
673
|
+
dropLocalClaimHolder(input.newRunId);
|
|
621
674
|
if (fallback)
|
|
622
675
|
return workflowResumeClaimFallback.release(store, input);
|
|
623
676
|
try {
|
|
@@ -1162,7 +1215,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1162
1215
|
return observed;
|
|
1163
1216
|
};
|
|
1164
1217
|
const journalStore = opts.journalStore;
|
|
1165
|
-
|
|
1218
|
+
const resumeClaims = [];
|
|
1166
1219
|
const replayByOrdinal = [];
|
|
1167
1220
|
let divergence;
|
|
1168
1221
|
const recordedOrdinalOfPosition = new Map();
|
|
@@ -1490,8 +1543,9 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1490
1543
|
const withoutToken = (text, token) => (token === "" ? text : text.split(token).join("<token>"));
|
|
1491
1544
|
const parkBindingBroken = (ordinal, why) => new WorkflowParkRefusal("workflow.park_binding_broken", `workflow resume: ordinal ${ordinal}'s park cannot be bound to its checkpoint (${why}) — the recorded park is inconsistent. Decide the checkpoint through the deployment's approval channel and start a fresh run.`, { ordinal });
|
|
1492
1545
|
const readParkTruth = async (seat, key, ordinal) => {
|
|
1493
|
-
|
|
1494
|
-
|
|
1546
|
+
const keyFault = parkBindingFault(key);
|
|
1547
|
+
if (keyFault !== undefined)
|
|
1548
|
+
throw parkBindingBroken(ordinal, keyFault);
|
|
1495
1549
|
const read = await finalizeWithin(timers, new Promise((resolve) => resolve(seat.get(key.token))).then((cp) => ({ cp }), (err) => ({ err })), "timeout");
|
|
1496
1550
|
if (read === "timeout" || "err" in read) {
|
|
1497
1551
|
throw new WorkflowParkRefusal("workflow.park_truth_unreadable", `workflow resume: ordinal ${ordinal} is recorded as PARKED and its checkpoint could not be read from the checkpoint store (${read === "timeout" ? `the read did not settle within ${WORKFLOW_STORE_WAIT_BOUND_MS}ms` : withoutToken(errText(read.err), key.token)}); the resume is refused rather than run beside a pinned child.`, { reason: "checkpoint_store_threw" });
|
|
@@ -1499,10 +1553,9 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
1499
1553
|
const cp = read.cp;
|
|
1500
1554
|
if (cp === null)
|
|
1501
1555
|
return { kind: "not_pending", key, status: "absent" };
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
throw parkBindingBroken(ordinal, "the checkpoint belongs to another session than the parked row");
|
|
1556
|
+
const rowFault = parkBindingFault(key, cp);
|
|
1557
|
+
if (rowFault !== undefined)
|
|
1558
|
+
throw parkBindingBroken(ordinal, rowFault);
|
|
1506
1559
|
if (cp.status !== "pending")
|
|
1507
1560
|
return { kind: "not_pending", key, status: cp.status, ...(cp.checkpointId !== undefined ? { checkpointId: cp.checkpointId } : {}) };
|
|
1508
1561
|
return { kind: "pending", key, cp };
|
|
@@ -2771,6 +2824,8 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2771
2824
|
if (inheritedModelError !== undefined)
|
|
2772
2825
|
throw inheritedModelError;
|
|
2773
2826
|
const typed = applyWorkflowAgentType(spec, agentOpts.agentType, agentRegistry);
|
|
2827
|
+
if (typed.droppedMcp !== undefined)
|
|
2828
|
+
announceShadowedDefinitionServers({ runner, leg: bornChildSessionId, root: spawnAttribution, agent: typed.agentType, dropped: typed.droppedMcp });
|
|
2774
2829
|
const typedSpec0 = typed.spec;
|
|
2775
2830
|
const typedSpec = withWorkflowChildSeats(typedSpec0, inheritedModelSnap, inheritedThinkingSnap, runnerRoleMap(runner));
|
|
2776
2831
|
const seatedSpec = applyParentSpecSeat(withWorkflowChildPersona(typedSpec, agentOpts.schema ?? typedSpec.outputSchema), opts.parentSpecSeat);
|
|
@@ -2790,7 +2845,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
2790
2845
|
opts.onForwardEvent(e.type === "task_progress" || e.type === "task_started" ? memberStamp(e, callKey, label) : e);
|
|
2791
2846
|
}
|
|
2792
2847
|
: undefined;
|
|
2793
|
-
const baseInternals = { ...parkGapInherit(seatedSpec), ...(agentOpts.isolation ? { isolation: agentOpts.isolation } : {}), ...(opts.parentCwd !== undefined ? { parentCwd: opts.parentCwd } : {}), ...(opts.parentSpecSeat?.
|
|
2848
|
+
const baseInternals = { ...parkGapInherit(seatedSpec), ...(agentOpts.isolation ? { isolation: agentOpts.isolation } : {}), ...(opts.parentCwd !== undefined ? { parentCwd: opts.parentCwd } : {}), ...(opts.parentSpecSeat?.project !== undefined ? { parentProject: opts.parentSpecSeat.project } : {}), ...callerPlacementSeats(opts.parentCwd, opts.callerRoot), ...spawnAttribution, ...definitionSeats(typed), ...(await captureFloorSeatsNow()), ...(enrichedForward !== undefined ? { onForwardEvent: enrichedForward } : {}), delegationTaskType: "workflow", spendParent: memberSpendParent, agentName: label, ...memberSeat(callKey, label), onWorkspaceResolved: createWorkspaceObserver(rec) };
|
|
2794
2849
|
let attempts = 0;
|
|
2795
2850
|
let throttleRetried = false;
|
|
2796
2851
|
let throttleFirst;
|
|
@@ -3237,6 +3292,8 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
3237
3292
|
if (inheritedModelError !== undefined)
|
|
3238
3293
|
throw inheritedModelError;
|
|
3239
3294
|
const typed = applyWorkflowAgentType(spec, agentOpts.agentType, agentRegistry);
|
|
3295
|
+
if (typed.droppedMcp !== undefined)
|
|
3296
|
+
announceShadowedDefinitionServers({ runner, leg: childSessionId, root: spawnAttribution, agent: typed.agentType, dropped: typed.droppedMcp });
|
|
3240
3297
|
const typedSpec0 = typed.spec;
|
|
3241
3298
|
const typedSpec = withWorkflowChildSeats(typedSpec0, inheritedModelSnap, inheritedThinkingSnap, runnerRoleMap(runner));
|
|
3242
3299
|
const seatedSpec = applyParentSpecSeat(withWorkflowChildPersona(typedSpec, agentOpts.schema ?? typedSpec.outputSchema), opts.parentSpecSeat);
|
|
@@ -3266,7 +3323,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
3266
3323
|
...(drive === undefined && !spec.sessionId && childSessionId !== undefined ? { sessionIdMintedBySpawner: true } : {}),
|
|
3267
3324
|
...(agentOpts.isolation ? { isolation: agentOpts.isolation } : {}),
|
|
3268
3325
|
...(opts.parentCwd !== undefined ? { parentCwd: opts.parentCwd } : {}),
|
|
3269
|
-
...(opts.parentSpecSeat?.
|
|
3326
|
+
...(opts.parentSpecSeat?.project !== undefined ? { parentProject: opts.parentSpecSeat.project } : {}),
|
|
3270
3327
|
...callerPlacementSeats(opts.parentCwd, opts.callerRoot),
|
|
3271
3328
|
...spawnAttribution,
|
|
3272
3329
|
...definitionSeats(typed),
|
|
@@ -3637,8 +3694,31 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
3637
3694
|
emitRunLog(`launch: this run's launch record was not kept (${why}) — nothing could continue a card this run parked on, so its agents do not park on approvals.`);
|
|
3638
3695
|
}
|
|
3639
3696
|
}
|
|
3697
|
+
const takeRunClaim = async (keys, what, onThrow) => {
|
|
3698
|
+
const store = journalStore;
|
|
3699
|
+
const fallback = store.resumeClaim === undefined;
|
|
3700
|
+
for (const key of keys) {
|
|
3701
|
+
if (resumeClaims.some((c) => c.sourceRunId === key))
|
|
3702
|
+
continue;
|
|
3703
|
+
if (finalized)
|
|
3704
|
+
throw new Error("workflow run already finalized — its resume admission takes no claim after the run ended");
|
|
3705
|
+
const verdict = takeWorkflowResumeClaim(store, { sourceRunId: key, newRunId: runId, scope }, (parkedResume?.length ?? 0) > 0);
|
|
3706
|
+
resumeClaims.push({ sourceRunId: key, verdict, fallback });
|
|
3707
|
+
let decision;
|
|
3708
|
+
try {
|
|
3709
|
+
decision = await verdict;
|
|
3710
|
+
}
|
|
3711
|
+
catch (err) {
|
|
3712
|
+
throw onThrow(err);
|
|
3713
|
+
}
|
|
3714
|
+
if (!decision.granted)
|
|
3715
|
+
throw claimRefusalOf(what, decision);
|
|
3716
|
+
}
|
|
3717
|
+
};
|
|
3718
|
+
if (opts.resumeFromRunId === undefined && journalStore) {
|
|
3719
|
+
await takeRunClaim([runId], `run "${clampRunIdText(runId)}"`, (err) => new Error(`startWorkflow: run "${clampRunIdText(runId)}" was REFUSED — the journal store threw while the workflow's claim was taken (${storeErrorClassOf(err)}), so nothing guards the run against a continuation of it; nothing ran. Start it again once the journal store answers.`));
|
|
3720
|
+
}
|
|
3640
3721
|
if (opts.resumeFromRunId !== undefined && journalStore) {
|
|
3641
|
-
const usingFallback = journalStore.resumeClaim === undefined;
|
|
3642
3722
|
const named = opts.resumeFromRunId;
|
|
3643
3723
|
let walkThrew;
|
|
3644
3724
|
const walkWithin = (p) => storeWithin(p.catch((err) => ((walkThrew ??= { err }), Promise.reject(err))));
|
|
@@ -3657,38 +3737,18 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
3657
3737
|
const keyTree = store === undefined || heldKey !== undefined ? undefined : await readTree();
|
|
3658
3738
|
if (typeof keyTree === "string")
|
|
3659
3739
|
throw await treeRefusal(keyTree);
|
|
3660
|
-
const
|
|
3740
|
+
const firstKeys = heldKey !== undefined ? [heldKey] : keyTree === undefined ? [named] : workflowClaimKeysOf(keyTree).keys;
|
|
3661
3741
|
const otherRoot = () => new Error(`startWorkflow: resume from "${clampRunIdText(named)}" was REFUSED — the workflow's records now lead to another first run than the one its resume claim was taken for (a run of the workflow was removed or created again meanwhile), so its claim cannot hold it. Resume again.`);
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
const verdict = takeWorkflowResumeClaim(journalStore, { sourceRunId: root, newRunId: runId, scope });
|
|
3665
|
-
resumeClaim = { sourceRunId: root, verdict, fallback: usingFallback };
|
|
3666
|
-
let decision;
|
|
3667
|
-
try {
|
|
3668
|
-
decision = await verdict;
|
|
3669
|
-
}
|
|
3670
|
-
catch (err) {
|
|
3671
|
-
throw journalStoreClaimRefusal(clampRunIdText(named), err);
|
|
3672
|
-
}
|
|
3673
|
-
if (!decision.granted) {
|
|
3674
|
-
const forAnswer = isAnswerRecordClaimHolder(decision.holder);
|
|
3675
|
-
const holder = decision.holder !== undefined && !forAnswer ? clampRunIdText(decision.holder) : "";
|
|
3676
|
-
const lapse = decision.lapse;
|
|
3677
|
-
throw new Error(`startWorkflow: resume from "${clampRunIdText(named)}" was REFUSED — ` +
|
|
3678
|
-
(forAnswer
|
|
3679
|
-
? "another leg of the workflow holds the resume claim on it for a moment, to record a person's answer to continuing it (no run holds it): resume again once it gives the claim back. If that leg's process stopped without giving the claim back, "
|
|
3680
|
-
: `another run already holds the resume claim on it${holder ? ` (holder: ${holder})` : " (holder unknown to the store)"}. ` +
|
|
3681
|
-
"Two concurrent resumes of one source run fork its execution: both replay the same prefix and then " +
|
|
3682
|
-
"re-run the whole suffix live, duplicating every side effect. Wait for the holder to reach a terminal " +
|
|
3683
|
-
"state (or stop it) and resume again. If the holder's process stopped without giving the claim back, ") +
|
|
3684
|
-
`the claim lapses ${lapse?.kind === "at" ? `at ${new Date(lapse.at).toISOString()} at the latest` : `when the journal store's expiry frees it${lapse?.kind === "unreadable" ? ` (${CLAIM_REMAINING_UNREADABLE_NOTE})` : ""}`}, and the same resume goes through then.`);
|
|
3685
|
-
}
|
|
3742
|
+
const claimThrew = (err) => journalStoreClaimRefusal(clampRunIdText(named), err);
|
|
3743
|
+
await takeRunClaim(firstKeys, `resume from "${clampRunIdText(named)}"`, claimThrew);
|
|
3686
3744
|
if (store !== undefined) {
|
|
3687
3745
|
const tree = await readTree();
|
|
3688
3746
|
if (typeof tree === "string")
|
|
3689
3747
|
throw await treeRefusal(tree);
|
|
3690
|
-
|
|
3748
|
+
const keys = workflowClaimKeysOf(tree).keys;
|
|
3749
|
+
if (heldKey !== undefined ? keys[0] !== heldKey : !sameClaimKeys(keys, firstKeys))
|
|
3691
3750
|
throw otherRoot();
|
|
3751
|
+
await takeRunClaim(keys, `resume from "${clampRunIdText(named)}"`, claimThrew);
|
|
3692
3752
|
admissionTree = Promise.resolve(tree);
|
|
3693
3753
|
for (const e of parkedResume ?? []) {
|
|
3694
3754
|
const was = e.decisionId === undefined ? undefined : workflowParkDecisionOf(e.token, e.decisionId, tree);
|
|
@@ -4008,7 +4068,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
4008
4068
|
answer();
|
|
4009
4069
|
}
|
|
4010
4070
|
awaitedAppends.clear();
|
|
4011
|
-
|
|
4071
|
+
for (const resumeClaim of resumeClaims) {
|
|
4012
4072
|
const granted = await finalizeWithin(timers, resumeClaim.verdict.then((v) => v.granted, () => false), false);
|
|
4013
4073
|
if (granted) {
|
|
4014
4074
|
if (resumeClaim.fallback) {
|
|
@@ -4025,6 +4085,7 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
4025
4085
|
}
|
|
4026
4086
|
}
|
|
4027
4087
|
}
|
|
4088
|
+
dropLocalClaimHolder(runId);
|
|
4028
4089
|
for (const row of [...bceLive.values()]) {
|
|
4029
4090
|
bceTerminal(row.callKey, "failed", "abandoned by run finalize", undefined);
|
|
4030
4091
|
}
|
|
@@ -4046,19 +4107,20 @@ export function startWorkflow(runner, fn, opts = {}, internals) {
|
|
|
4046
4107
|
}
|
|
4047
4108
|
})();
|
|
4048
4109
|
bindSettledRun(done, run);
|
|
4049
|
-
|
|
4110
|
+
const cancel = (reason) => cancelController.abort(reason ? new Error(reason) : undefined);
|
|
4111
|
+
const handle = {
|
|
4050
4112
|
runId,
|
|
4051
4113
|
done,
|
|
4052
|
-
cancel
|
|
4114
|
+
cancel,
|
|
4053
4115
|
parked: () => runParkedOf(run),
|
|
4054
|
-
stopAgent: async (callKey, o) =>
|
|
4055
|
-
|
|
4056
|
-
if (by !== undefined && (typeof by !== "string" || by.trim() === "" || by.length > MAX_MEMBER_STOPPER_CHARS))
|
|
4057
|
-
throw new TypeError(`WorkflowHandle.stopAgent: stoppedBy must be a non-empty string of at most ${MAX_MEMBER_STOPPER_CHARS} characters`);
|
|
4058
|
-
return stopMember(callKey, by ?? "parent");
|
|
4059
|
-
},
|
|
4116
|
+
stopAgent: async (callKey, o) => stopMember(callKey, readWorkflowStopper(o?.stoppedBy, "WorkflowHandle.stopAgent")),
|
|
4117
|
+
stop: async (o) => stopWorkflowTree(runId, scope, readWorkflowStopper(o?.stoppedBy, "WorkflowHandle.stop"), seats, { self: run, own: local, keysWithoutTree: resumeClaims.length > 0 ? resumeClaims.map((c) => c.sourceRunId) : [opts.resumeFromRunId ?? runId] }),
|
|
4060
4118
|
recordLanded: () => recordLanded.then((o) => o.ok),
|
|
4061
4119
|
};
|
|
4120
|
+
const seats = { ...(store !== undefined ? { runStore: store } : {}), ...(journalStore !== undefined ? { journalStore } : {}), ...(parkSeat !== undefined ? { checkpointStore: parkSeat } : {}) };
|
|
4121
|
+
const local = { runId, creationId: () => creationId, cancel: (reason) => cancel(reason), done, handle };
|
|
4122
|
+
holdLocalWorkflowRun(local);
|
|
4123
|
+
return handle;
|
|
4062
4124
|
}
|
|
4063
4125
|
export async function runWorkflow(runner, fn, opts = {}, internals) {
|
|
4064
4126
|
return startWorkflow(runner, fn, opts, internals).done;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE MANAGER RECIPE: data and text a host composes into its own spec and agent definitions, not an engine mode — the coordinator
|
|
3
|
+
* role text (unchanged), `ownHandsReadOnly` (the manager's own hands only), `runLedger` (the member ledger, the report tool, the
|
|
4
|
+
* actions section, the launch check), and the duties on `appendSystemPrompt`. A worker's definition carries no delegation tool
|
|
5
|
+
* ({@link managerWorkerDefinition}); no agent-to-agent peer tool is mounted (a peer call waits in the call; a manager must not).
|
|
6
|
+
*/
|
|
7
|
+
import type { AgentDefinition } from "../core/agent-definition.js";
|
|
8
|
+
/** The duties the manager reads after its role text. */
|
|
9
|
+
export declare const MANAGER_DUTIES_ADDENDUM = "# Your duties as the manager of this work\n\nThe work you direct can be of any kind \u2014 code, research, analysis, operations, writing. Where the coordinator text above speaks of software engineering, read it for whatever this work is.\n\nYou do not change the work yourself. Your own hands read: files, searches, read-only commands, and your workers' full records (AgentTranscript). Every change goes through a worker. A manager who edits becomes a party to the work, with nobody left to check it.\n\nVerifying is your duty, not a suggestion. A worker's report says what it meant to do, not necessarily what it did. Before you tell the person that a result holds:\n- read what the worker actually did \u2014 the <actions> section of its notification, its record (AgentTranscript), the files it says it changed;\n- where checking needs something run, send a fresh verification worker (never the worker that did the work) and read its result;\n- when what a worker said and what it did disagree, say so plainly.\n\nReport to the person with SendUserMessage: when you start (the plan, and what it will cost), when a result is overturned, when you are blocked or need a decision, and at the end. For each conclusion about a worker, say what it rests on: \"verified\" only for a check made after that worker reported (cite your call id, or the verification worker's task id); \"relayed\" for what the worker said that you did not check; \"inferred\" for your own judgment. Beside every message the engine delivers its own ledger of the workers \u2014 how each ended, what each did, which ones nobody checked \u2014 so a report that claims more than was checked shows it.\n\nNever tell the person that everything passed while a worker failed, is still running, or was never checked.";
|
|
10
|
+
/** The manager's own task seats (spread into the host's spec; the host adds its objective, model, delegation tool and workers). */
|
|
11
|
+
export declare const MANAGER_RECIPE: Readonly<{
|
|
12
|
+
readonly promptRole: "coordinator";
|
|
13
|
+
readonly ownHandsReadOnly: true;
|
|
14
|
+
readonly runLedger: true;
|
|
15
|
+
readonly appendSystemPrompt: "# Your duties as the manager of this work\n\nThe work you direct can be of any kind — code, research, analysis, operations, writing. Where the coordinator text above speaks of software engineering, read it for whatever this work is.\n\nYou do not change the work yourself. Your own hands read: files, searches, read-only commands, and your workers' full records (AgentTranscript). Every change goes through a worker. A manager who edits becomes a party to the work, with nobody left to check it.\n\nVerifying is your duty, not a suggestion. A worker's report says what it meant to do, not necessarily what it did. Before you tell the person that a result holds:\n- read what the worker actually did — the <actions> section of its notification, its record (AgentTranscript), the files it says it changed;\n- where checking needs something run, send a fresh verification worker (never the worker that did the work) and read its result;\n- when what a worker said and what it did disagree, say so plainly.\n\nReport to the person with SendUserMessage: when you start (the plan, and what it will cost), when a result is overturned, when you are blocked or need a decision, and at the end. For each conclusion about a worker, say what it rests on: \"verified\" only for a check made after that worker reported (cite your call id, or the verification worker's task id); \"relayed\" for what the worker said that you did not check; \"inferred\" for your own judgment. Beside every message the engine delivers its own ledger of the workers — how each ended, what each did, which ones nobody checked — so a report that claims more than was checked shows it.\n\nNever tell the person that everything passed while a worker failed, is still running, or was never checked.";
|
|
16
|
+
}>;
|
|
17
|
+
/** A worker's definition under the recipe: the host's, with the delegation tool (mounted as `delegationToolName`) denied. */
|
|
18
|
+
export declare function managerWorkerDefinition(def: AgentDefinition, delegationToolName?: string): AgentDefinition;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const MANAGER_DUTIES_ADDENDUM = `# Your duties as the manager of this work
|
|
2
|
+
|
|
3
|
+
The work you direct can be of any kind — code, research, analysis, operations, writing. Where the coordinator text above speaks of software engineering, read it for whatever this work is.
|
|
4
|
+
|
|
5
|
+
You do not change the work yourself. Your own hands read: files, searches, read-only commands, and your workers' full records (AgentTranscript). Every change goes through a worker. A manager who edits becomes a party to the work, with nobody left to check it.
|
|
6
|
+
|
|
7
|
+
Verifying is your duty, not a suggestion. A worker's report says what it meant to do, not necessarily what it did. Before you tell the person that a result holds:
|
|
8
|
+
- read what the worker actually did — the <actions> section of its notification, its record (AgentTranscript), the files it says it changed;
|
|
9
|
+
- where checking needs something run, send a fresh verification worker (never the worker that did the work) and read its result;
|
|
10
|
+
- when what a worker said and what it did disagree, say so plainly.
|
|
11
|
+
|
|
12
|
+
Report to the person with SendUserMessage: when you start (the plan, and what it will cost), when a result is overturned, when you are blocked or need a decision, and at the end. For each conclusion about a worker, say what it rests on: "verified" only for a check made after that worker reported (cite your call id, or the verification worker's task id); "relayed" for what the worker said that you did not check; "inferred" for your own judgment. Beside every message the engine delivers its own ledger of the workers — how each ended, what each did, which ones nobody checked — so a report that claims more than was checked shows it.
|
|
13
|
+
|
|
14
|
+
Never tell the person that everything passed while a worker failed, is still running, or was never checked.`;
|
|
15
|
+
export const MANAGER_RECIPE = Object.freeze({
|
|
16
|
+
promptRole: "coordinator",
|
|
17
|
+
ownHandsReadOnly: true,
|
|
18
|
+
runLedger: true,
|
|
19
|
+
appendSystemPrompt: MANAGER_DUTIES_ADDENDUM,
|
|
20
|
+
});
|
|
21
|
+
export function managerWorkerDefinition(def, delegationToolName = "Agent") {
|
|
22
|
+
const denied = def.denyTools ?? [];
|
|
23
|
+
return denied.includes(delegationToolName) ? { ...def } : { ...def, denyTools: [...denied, delegationToolName] };
|
|
24
|
+
}
|
|
@@ -57,7 +57,9 @@
|
|
|
57
57
|
* A file that does not parse, or whose checksum does not match its contents, yields ZERO rules and a loud
|
|
58
58
|
* disclosure — never a partial load. Half a rule set is a set nobody reviewed. Note what the checksum is
|
|
59
59
|
* and is not: it detects corruption, and it does not detect an editor, because an editor recomputes it.
|
|
60
|
-
* For this backend the trust is host = user, exactly as for the settings file it mirrors.
|
|
60
|
+
* For this backend the trust is host = user, exactly as for the settings file it mirrors. So a RULE row
|
|
61
|
+
* in bytes that passed the check is what someone wrote: one that is no data is that row's fault alone,
|
|
62
|
+
* named by the one row reader every backend's rows go through — never a reason to drop the rows beside it.
|
|
61
63
|
*/
|
|
62
64
|
import type { PersistedRule, RuleTombstone } from "../../core/permission-rule-model.js";
|
|
63
65
|
import type { DurableRulePartition, DurableRulePartitionProvider, PermissionRuleWriter, QuarantinedRuleAdd, RuleSyncFrontier, StoredRules, WritableDurableRulePartition } from "../../core/permission-rule-store.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type WorkflowJournalEntry, type WorkflowJournalStore, type WorkflowLaunchRecord, type ResumeClaimArgs, type ResumeClaimAnswer } from "../../core/workflow-journal-store.js";
|
|
1
|
+
import { type WorkflowJournalEntry, type WorkflowJournalStore, type WorkflowLaunchRecord, type ResumeClaimArgs, type ResumeClaimAnswer, type StopResumeClaimArgs, type StopResumeClaimAnswer } from "../../core/workflow-journal-store.js";
|
|
2
2
|
import { type CorruptReadInfo } from "./corrupt-read-sink.js";
|
|
3
3
|
/**
|
|
4
4
|
* RB-242 — how long a resume claim survives WITHOUT an engine release. This is the backstop for an engine that
|
|
@@ -149,6 +149,12 @@ export declare class FileWorkflowJournalStore implements WorkflowJournalStore {
|
|
|
149
149
|
* and a release that could not create one must not leave the claim standing for its lease.
|
|
150
150
|
*/
|
|
151
151
|
private removeIfUnchanged;
|
|
152
|
+
/**
|
|
153
|
+
* Atomically replace a claim file IN PLACE with `payload` ONLY if the bytes on disk are still `judged`, under the same
|
|
154
|
+
* removal gate {@link removeIfUnchanged} uses. Unlike unlink + link, `rename` leaves no empty-file window where a concurrent
|
|
155
|
+
* `resumeClaim` could acquire the slot while arm (c)'s local holder is still running before cancel.
|
|
156
|
+
*/
|
|
157
|
+
private replaceIfUnchanged;
|
|
152
158
|
/**
|
|
153
159
|
* The removal gate of the claim at `path` judged as `judged` — or, given a gate file's own path, that gate. Its name is a fixed
|
|
154
160
|
* length (a digest of the claim file's name and the bytes, `<digest>.takeover`), never the claim's name with more appended: a
|
|
@@ -187,9 +193,16 @@ export declare class FileWorkflowJournalStore implements WorkflowJournalStore {
|
|
|
187
193
|
*/
|
|
188
194
|
resumeClaim(input: ResumeClaimArgs): Promise<ResumeClaimAnswer>;
|
|
189
195
|
/** RB-242 — release ONLY a claim this `newRunId` still holds in this process ({@link heldHere}). A claim that is already gone
|
|
190
|
-
* (TTL-reaped and possibly taken over), or one the same run id holds from another process, is a no-op: unlinking
|
|
191
|
-
* claim would re-open the very fork this prevents. */
|
|
196
|
+
* (TTL-reaped and possibly taken over), a tombstone, or one the same run id holds from another process, is a no-op: unlinking
|
|
197
|
+
* a successor's claim would re-open the very fork this prevents. */
|
|
192
198
|
releaseResumeClaim(input: ResumeClaimArgs): Promise<void>;
|
|
199
|
+
/**
|
|
200
|
+
* #5156 R1 — compare-and-write a permanent stop tombstone on `(sourceRunId, scope)`.
|
|
201
|
+
* Writes no `holderProcess` and sets finite `expiresAt = Number.MAX_SAFE_INTEGER` (never `Infinity`, which serializes to
|
|
202
|
+
* `null`), so pre-tombstone (v7.71.x) readers also refuse, never take over and never reap the tombstone. Arms (b) and (c)
|
|
203
|
+
* replace the existing claim atomically in place under its removal gate, dropping any old `holderProcess` with no empty window.
|
|
204
|
+
*/
|
|
205
|
+
stopResumeClaim(input: StopResumeClaimArgs): Promise<StopResumeClaimAnswer>;
|
|
193
206
|
/** Release ledger fds (graceful shutdown; parity with the other file stores' dispose).
|
|
194
207
|
* Refcounted: the fds are shared with any other instance on the same directory, so the LAST holder
|
|
195
208
|
* closes them. Idempotent — a second dispose() on the same instance must not decrement twice and pull
|
|
@@ -6,10 +6,11 @@ import { callKeyOrdinal, readWorkflowJournalEntry, launchRecordToKeepOrThrow, re
|
|
|
6
6
|
import { processCensus, processFingerprint } from "../../core/process-identity.js";
|
|
7
7
|
import { AppendLog, readJsonlRecords } from "./fs-atomic.js";
|
|
8
8
|
import { guardCorruptSink } from "./corrupt-read-sink.js";
|
|
9
|
-
import { BootLock, canonicalStoreKey, FileStoreLockError, sanitizePathComponent, writeThenLink } from "./fs-atomic.js";
|
|
9
|
+
import { atomicWriteFile, BootLock, canonicalStoreKey, FileStoreLockError, sanitizePathComponent, writeThenLink } from "./fs-atomic.js";
|
|
10
10
|
import { assertAdoptionBootGate } from "./adoption/marker.js";
|
|
11
11
|
import { optionKeys, receiveOptions } from "../../core/own-property-receipt.js";
|
|
12
12
|
import { assertJournalEntryFits } from "../../core/workflow-journal-store.js";
|
|
13
|
+
const TOMBSTONE_CLAIM_HOLDER = "workflow:stopped";
|
|
13
14
|
function holderProcessOf(v) {
|
|
14
15
|
if (v === null || typeof v !== "object" || Array.isArray(v))
|
|
15
16
|
return undefined;
|
|
@@ -26,12 +27,14 @@ function holderProcessOf(v) {
|
|
|
26
27
|
return { pid: r.pid, startedAtMs, startedSinceBootMs, host: r.host, ...(typeof r.pidNs === "string" ? { pidNs: r.pidNs } : {}) };
|
|
27
28
|
}
|
|
28
29
|
function claimBinds(claim, now) {
|
|
30
|
+
if (claim.stopped !== undefined)
|
|
31
|
+
return true;
|
|
29
32
|
if (claim.rec.expiresAt <= now)
|
|
30
33
|
return false;
|
|
31
34
|
return claim.process === undefined || processCensus().verdict(claim.process).state !== "gone";
|
|
32
35
|
}
|
|
33
36
|
function heldHere(claim, newRunId) {
|
|
34
|
-
if (claim.rec.holder !== newRunId || claim.process === undefined)
|
|
37
|
+
if (claim.stopped !== undefined || claim.rec.holder !== newRunId || claim.process === undefined)
|
|
35
38
|
return false;
|
|
36
39
|
const me = processFingerprint();
|
|
37
40
|
return claim.process.pid === me.pid && claim.process.host === me.host && claim.process.pidNs === me.pidNs;
|
|
@@ -298,7 +301,8 @@ export class FileWorkflowJournalStore {
|
|
|
298
301
|
if (typeof rec.holder !== "string" || typeof rec.expiresAt !== "number" || !Number.isFinite(rec.expiresAt)) {
|
|
299
302
|
return { raw, claim: undefined };
|
|
300
303
|
}
|
|
301
|
-
|
|
304
|
+
const stopped = typeof rec.stoppedBy === "string" && rec.stoppedBy.length > 0 ? { by: rec.stoppedBy } : undefined;
|
|
305
|
+
return { raw, claim: { rec, process: holderProcessOf(rec.holderProcess), stopped } };
|
|
302
306
|
}
|
|
303
307
|
catch {
|
|
304
308
|
return { raw, claim: undefined };
|
|
@@ -335,6 +339,35 @@ export class FileWorkflowJournalStore {
|
|
|
335
339
|
gate.release();
|
|
336
340
|
}
|
|
337
341
|
}
|
|
342
|
+
replaceIfUnchanged(path, judged, payload) {
|
|
343
|
+
const gate = this.gateAt(path, judged);
|
|
344
|
+
try {
|
|
345
|
+
gate.acquire();
|
|
346
|
+
}
|
|
347
|
+
catch (err) {
|
|
348
|
+
if (err instanceof FileStoreLockError && (err.code === "store.dir_in_use" || err.code === "store.dir_claiming"))
|
|
349
|
+
return "contended";
|
|
350
|
+
throw err;
|
|
351
|
+
}
|
|
352
|
+
try {
|
|
353
|
+
let now;
|
|
354
|
+
try {
|
|
355
|
+
now = readFileSync(path, "utf8");
|
|
356
|
+
}
|
|
357
|
+
catch (err) {
|
|
358
|
+
if (err.code === "ENOENT")
|
|
359
|
+
return "changed";
|
|
360
|
+
throw err;
|
|
361
|
+
}
|
|
362
|
+
if (now !== judged)
|
|
363
|
+
return "changed";
|
|
364
|
+
atomicWriteFile(this.claimsDir, path, payload);
|
|
365
|
+
return "replaced";
|
|
366
|
+
}
|
|
367
|
+
finally {
|
|
368
|
+
gate.release();
|
|
369
|
+
}
|
|
370
|
+
}
|
|
338
371
|
gateAt(path, judged) {
|
|
339
372
|
const gatePath = judged === undefined ? path : join(this.claimsDir, `${createHash("sha256").update(`${basename(path)}\n${judged}`).digest("hex").slice(0, 32)}.takeover`);
|
|
340
373
|
return new BootLock(gatePath, RESUME_CLAIM_TTL_MS);
|
|
@@ -358,7 +391,9 @@ export class FileWorkflowJournalStore {
|
|
|
358
391
|
const read = this.readClaimAt(path);
|
|
359
392
|
if (read === undefined)
|
|
360
393
|
continue;
|
|
361
|
-
if (read.claim !== undefined
|
|
394
|
+
if (read.claim !== undefined
|
|
395
|
+
? read.claim.stopped !== undefined || read.claim.rec.expiresAt + RESUME_CLAIM_REAP_GRACE_MS > now
|
|
396
|
+
: now - statSync(path).mtimeMs <= RESUME_CLAIM_TTL_MS) {
|
|
362
397
|
continue;
|
|
363
398
|
}
|
|
364
399
|
this.removeIfUnchanged(path, read.raw);
|
|
@@ -399,6 +434,9 @@ export class FileWorkflowJournalStore {
|
|
|
399
434
|
if (read === undefined)
|
|
400
435
|
continue;
|
|
401
436
|
const existing = read.claim;
|
|
437
|
+
if (existing !== undefined && existing.stopped !== undefined) {
|
|
438
|
+
return { granted: false, stopped: existing.stopped };
|
|
439
|
+
}
|
|
402
440
|
const now = Date.now();
|
|
403
441
|
if (existing !== undefined && claimBinds(existing, now)) {
|
|
404
442
|
const left = resumeClaimRemainingMember(existing.rec.expiresAt, now);
|
|
@@ -409,6 +447,9 @@ export class FileWorkflowJournalStore {
|
|
|
409
447
|
this.removeIfUnchanged(path, read.raw);
|
|
410
448
|
}
|
|
411
449
|
const winner = this.readClaimAt(path)?.claim;
|
|
450
|
+
if (winner !== undefined && winner.stopped !== undefined) {
|
|
451
|
+
return { granted: false, stopped: winner.stopped };
|
|
452
|
+
}
|
|
412
453
|
const lastLook = Date.now();
|
|
413
454
|
const bound = winner !== undefined && claimBinds(winner, lastLook) ? winner : undefined;
|
|
414
455
|
if (bound !== undefined && heldHere(bound, newRunId))
|
|
@@ -425,7 +466,7 @@ export class FileWorkflowJournalStore {
|
|
|
425
466
|
return;
|
|
426
467
|
}
|
|
427
468
|
const existing = read?.claim;
|
|
428
|
-
if (read === undefined || existing === undefined || !heldHere(existing, input.newRunId))
|
|
469
|
+
if (read === undefined || existing === undefined || existing.stopped !== undefined || !heldHere(existing, input.newRunId))
|
|
429
470
|
return;
|
|
430
471
|
if (existing.rec.expiresAt - Date.now() <= RESUME_CLAIM_RELEASE_GRACE_MS)
|
|
431
472
|
return;
|
|
@@ -435,6 +476,53 @@ export class FileWorkflowJournalStore {
|
|
|
435
476
|
catch {
|
|
436
477
|
}
|
|
437
478
|
}
|
|
479
|
+
async stopResumeClaim(input) {
|
|
480
|
+
if (typeof input.stoppedBy !== "string" || input.stoppedBy === "") {
|
|
481
|
+
throw new TypeError("workflow journal: stopResumeClaim requires a non-empty stoppedBy string");
|
|
482
|
+
}
|
|
483
|
+
const { sourceRunId, scope, stoppedBy, holder } = input;
|
|
484
|
+
const path = this.claimPathFor(sourceRunId, scope);
|
|
485
|
+
mkdirSync(this.claimsDir, { recursive: true, mode: 0o700 });
|
|
486
|
+
const record = {
|
|
487
|
+
sourceRunId,
|
|
488
|
+
holder: TOMBSTONE_CLAIM_HOLDER,
|
|
489
|
+
expiresAt: Number.MAX_SAFE_INTEGER,
|
|
490
|
+
stoppedBy,
|
|
491
|
+
stoppedAt: Date.now(),
|
|
492
|
+
};
|
|
493
|
+
const payload = JSON.stringify(record);
|
|
494
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
495
|
+
try {
|
|
496
|
+
writeThenLink(path, payload);
|
|
497
|
+
return { stopped: true };
|
|
498
|
+
}
|
|
499
|
+
catch (err) {
|
|
500
|
+
if (err.code !== "EEXIST")
|
|
501
|
+
throw err;
|
|
502
|
+
}
|
|
503
|
+
const read = this.readClaimAt(path);
|
|
504
|
+
if (read === undefined)
|
|
505
|
+
continue;
|
|
506
|
+
const existing = read.claim;
|
|
507
|
+
if (existing !== undefined && existing.stopped !== undefined) {
|
|
508
|
+
return { stopped: true };
|
|
509
|
+
}
|
|
510
|
+
const now = Date.now();
|
|
511
|
+
const binds = existing !== undefined && claimBinds(existing, now);
|
|
512
|
+
if (binds && (holder === undefined || existing.rec.holder !== holder)) {
|
|
513
|
+
return { stopped: false, holder: existing.rec.holder };
|
|
514
|
+
}
|
|
515
|
+
const replaced = this.replaceIfUnchanged(path, read.raw, payload);
|
|
516
|
+
if (replaced === "replaced")
|
|
517
|
+
return { stopped: true };
|
|
518
|
+
}
|
|
519
|
+
const winner = this.readClaimAt(path)?.claim;
|
|
520
|
+
if (winner !== undefined && winner.stopped !== undefined)
|
|
521
|
+
return { stopped: true };
|
|
522
|
+
const lastLook = Date.now();
|
|
523
|
+
const bound = winner !== undefined && claimBinds(winner, lastLook) ? winner : undefined;
|
|
524
|
+
return { stopped: false, ...(bound !== undefined ? { holder: bound.rec.holder } : {}) };
|
|
525
|
+
}
|
|
438
526
|
dispose() {
|
|
439
527
|
if (this.closed)
|
|
440
528
|
return;
|
|
@@ -95,7 +95,7 @@ export declare class FileWorkflowRunStore implements WorkflowRunStore {
|
|
|
95
95
|
/** The end of a batch of {@link deleteRun} calls (interface: {@link WorkflowRunStore.settleErasure}): the ledger compacted once. */
|
|
96
96
|
settleErasure(): Promise<void>;
|
|
97
97
|
/** The session's terminal runs, deleted each under its own id lock with the selection re-checked against the live row (interface:
|
|
98
|
-
* {@link WorkflowRunStore.deleteBySession}) — a run
|
|
98
|
+
* {@link WorkflowRunStore.deleteBySession}) — a run removed or replaced by a new running run is skipped, as `reap` skips one. */
|
|
99
99
|
deleteBySession(sessionId: string, scope: string): Promise<string[]>;
|
|
100
100
|
/** Force a compaction now (test/inspection): rewrite the snapshot from the authoritative map and
|
|
101
101
|
* truncate the live ledger (RB-167's closeForSwap recipe lives in the base). */
|