@sema-agent/core 7.4.0 → 7.5.1
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 +69 -0
- package/dist/agents/cascade.d.ts +2 -1
- package/dist/agents/peer-notices.d.ts +11 -1
- package/dist/agents/peer-session-drain.js +2 -0
- package/dist/agents/verify.d.ts +2 -1
- package/dist/core/ask-origin.d.ts +130 -0
- package/dist/core/ask-origin.js +35 -0
- package/dist/core/auto-mode-arming.d.ts +40 -1
- package/dist/core/auto-mode-arming.js +51 -3
- package/dist/core/auto-mode.d.ts +87 -10
- package/dist/core/auto-mode.js +34 -6
- package/dist/core/checkpoint-store.d.ts +41 -6
- package/dist/core/checkpoint-store.js +8 -0
- package/dist/core/hooks.d.ts +63 -19
- package/dist/core/hooks.js +37 -16
- package/dist/core/mcp.d.ts +47 -55
- package/dist/core/mcp.js +89 -31
- package/dist/core/park-selfcheck.js +3 -0
- package/dist/core/permission-rule-consent.d.ts +2 -11
- package/dist/core/permission-rule-consent.js +13 -62
- package/dist/core/permission-rule-org.d.ts +70 -54
- package/dist/core/permission-rule-org.js +47 -61
- package/dist/core/permission-rule-provider.d.ts +162 -0
- package/dist/core/permission-rule-provider.js +148 -0
- package/dist/core/permission-rule-session.d.ts +23 -19
- package/dist/core/permission-rule-session.js +5 -5
- package/dist/core/permission-rule-store.d.ts +46 -21
- package/dist/core/permission-rule-store.js +13 -6
- package/dist/core/permission-rule-sync.d.ts +2 -1
- package/dist/core/permission-rule-sync.js +11 -0
- package/dist/core/runner/assemble-result.d.ts +3 -2
- package/dist/core/runner/checkpoint-scope.d.ts +32 -0
- package/dist/core/runner/checkpoint-scope.js +4 -0
- package/dist/core/runner/contracts.d.ts +1878 -0
- package/dist/core/runner/contracts.js +1 -0
- package/dist/core/runner/denial-limit-arms.d.ts +57 -31
- package/dist/core/runner/denial-limit-arms.js +42 -17
- package/dist/core/runner/derived-route-fallback.d.ts +34 -0
- package/dist/core/runner/derived-route-fallback.js +16 -0
- package/dist/core/runner/prepare-acquire-reconcile.d.ts +1 -1
- package/dist/core/runner/prepare-announce-once.d.ts +83 -0
- package/dist/core/runner/prepare-announce-once.js +105 -0
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +170 -0
- package/dist/core/runner/prepare-caps-and-workflow.js +255 -0
- package/dist/core/runner/prepare-config-doors.d.ts +2 -10
- package/dist/core/runner/prepare-defer-classify.d.ts +86 -0
- package/dist/core/runner/prepare-defer-classify.js +107 -0
- package/dist/core/runner/prepare-delegation-surface.d.ts +104 -0
- package/dist/core/runner/prepare-delegation-surface.js +144 -0
- package/dist/core/runner/prepare-execution-env.d.ts +54 -0
- package/dist/core/runner/prepare-execution-env.js +86 -0
- package/dist/core/runner/prepare-file-history.d.ts +95 -0
- package/dist/core/runner/prepare-file-history.js +383 -0
- package/dist/core/runner/prepare-hands-readface.d.ts +6 -8
- package/dist/core/runner/prepare-hands-readface.js +3 -3
- package/dist/core/runner/prepare-inherited-gate.d.ts +268 -0
- package/dist/core/runner/prepare-inherited-gate.js +266 -0
- package/dist/core/runner/prepare-listings.d.ts +77 -0
- package/dist/core/runner/prepare-listings.js +76 -0
- package/dist/core/runner/prepare-lsp.d.ts +55 -0
- package/dist/core/runner/prepare-lsp.js +27 -0
- package/dist/core/runner/prepare-memory.d.ts +1 -1
- package/dist/core/runner/prepare-offload-wrappers.d.ts +62 -0
- package/dist/core/runner/prepare-offload-wrappers.js +45 -0
- package/dist/core/runner/prepare-permission-rules.d.ts +132 -0
- package/dist/core/runner/prepare-permission-rules.js +140 -0
- package/dist/core/runner/prepare-project-context.d.ts +131 -0
- package/dist/core/runner/prepare-project-context.js +150 -0
- package/dist/core/runner/prepare-prompt-inputs.d.ts +138 -0
- package/dist/core/runner/prepare-prompt-inputs.js +141 -0
- package/dist/core/runner/prepare-protocol-tools.d.ts +91 -0
- package/dist/core/runner/prepare-protocol-tools.js +182 -0
- package/dist/core/runner/prepare-question-face.d.ts +119 -0
- package/dist/core/runner/prepare-question-face.js +83 -0
- package/dist/core/runner/prepare-run-refs.d.ts +89 -0
- package/dist/core/runner/prepare-run-refs.js +39 -0
- package/dist/core/runner/prepare-safety-scan.d.ts +3 -2
- package/dist/core/runner/prepare-task.d.ts +11 -1815
- package/dist/core/runner/prepare-task.js +138 -2542
- package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +111 -0
- package/dist/core/runner/prepare-tool-disclosure-mount.js +219 -0
- package/dist/core/runner/prepare-wiring-manifest.d.ts +184 -0
- package/dist/core/runner/prepare-wiring-manifest.js +240 -0
- package/dist/core/runner/prepare-workspace-restore.d.ts +1 -27
- package/dist/core/runner/prepare-workspace-restore.js +1 -22
- package/dist/core/runner/rollback-stack.d.ts +32 -0
- package/dist/core/runner/rollback-stack.js +30 -0
- package/dist/core/runner/runtask.d.ts +11 -2
- package/dist/core/runner/runtask.js +27 -9
- package/dist/core/runner/workspace-path.d.ts +33 -0
- package/dist/core/runner/workspace-path.js +22 -0
- package/dist/core/sensitive-path-policy.d.ts +16 -0
- package/dist/core/sensitive-path-policy.js +1 -1
- package/dist/core/tool-policy.d.ts +57 -9
- package/dist/core/tool-policy.js +11 -0
- package/dist/core/types.d.ts +63 -51
- package/dist/core/wiring-manifest.d.ts +40 -3
- package/dist/core/wiring-manifest.js +4 -3
- package/dist/core/write-protect.d.ts +13 -2
- package/dist/core/write-protect.js +58 -29
- package/dist/engine/harness/types.d.ts +38 -16
- package/dist/engine/harness/types.js +25 -1
- package/dist/engine/session/session.d.ts +3 -11
- package/dist/index.d.ts +10 -6
- package/dist/index.js +9 -5
- package/dist/internal/harness.d.ts +1 -0
- package/dist/stores/file/adoption/adopt.d.ts +1 -1
- package/dist/stores/file/adoption/marker.d.ts +1 -1
- package/dist/stores/file/permission-rule-adopt.js +4 -3
- package/dist/stores/file/permission-rule-store.d.ts +65 -25
- package/dist/stores/file/permission-rule-store.js +215 -37
- package/dist/stores/file/task-list-store.d.ts +1 -1
- package/dist/tools/fs/read-face.d.ts +1 -1
- package/package.json +8 -2
- package/test/export-surface.snapshot.json +76 -28
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* design/390 §1.2 M3b — prepareTask's INHERITED-GATE phase, verbatim from the driver: the live/seed fold of the
|
|
3
|
+
* chain this run inherits (ancestor rules rev-monotonic per (session, principal), shellGate by max rank, the
|
|
4
|
+
* re-supplied parent constraints with their rebuilt denial trackers, the auto-mode intent, the org-admission
|
|
5
|
+
* freeze with its tighten-only intersection and the monotonic governed bit), the effective shellGate against the
|
|
6
|
+
* spec, the three cells later phases fill for the children's chain (own session rules, own admitted org scopes,
|
|
7
|
+
* own org verdict), the checkpoint-section closures the suspend serializer reads (face / org / F-012 stamps), the
|
|
8
|
+
* FROZEN ask and question seats (spec over deps), the two delegation refs the memory phase binds late, the ONE
|
|
9
|
+
* child-chain assembly `inheritedGateForChildren`, the caller-tool ctx enrichment `enrichSpecToolCtx` shared by
|
|
10
|
+
* the roster wrap and the revival spawner, the denial-limit stop seat, and the full-shell reachability predicate.
|
|
11
|
+
* The interface is the dependency list the segment had implicitly (design/238 R-1).
|
|
12
|
+
*
|
|
13
|
+
* SYNCHRONOUS FUNCTION, SYNCHRONOUS CALL: the stretch has no await (the one `await` in it sits inside the
|
|
14
|
+
* `hostSessionFork` closure a tool calls later), so the phase adds no yield between the run-refs phase before it
|
|
15
|
+
* and the caps phase after it (design/390 §1.5: a stretch with no await is extracted as a sync function).
|
|
16
|
+
*
|
|
17
|
+
* LATE-BOUND SEATS. The closures minted here run long after this phase returns — at spawn time, at tool-call
|
|
18
|
+
* time, at suspend time — and several of the facts they read are resolved by LATER stations of the same prepare:
|
|
19
|
+
* the caps phase's `runtimeCaps` / fork verdict / observers grant / armed classifier trio, the hands mount's
|
|
20
|
+
* resolved face and deny additions, the policy-chain station's hook record and timeout, the wiring station's hook
|
|
21
|
+
* env face, the prompt-assembly station's center adoption, the memory phase's engine session. In the driver those
|
|
22
|
+
* were `let`s and later `const`s the closures captured by name; here each enters as a GETTER on the Input, and
|
|
23
|
+
* every closure reads it exactly where — and only when — the driver's closure read the variable (a head binding
|
|
24
|
+
* where the driver read a variable inside one synchronous evaluation; an in-place call where the driver's read
|
|
25
|
+
* sat behind a short-circuit). Read-stability of the host handles for the call: {@link RunInternals}
|
|
26
|
+
* (`@contract prepare.deps-read-stable`).
|
|
27
|
+
*
|
|
28
|
+
* Every cell that leaves here as `borrowed-mutable` carries its writer table on the Result member (design/238 R-3).
|
|
29
|
+
*/
|
|
30
|
+
import type { AgentHarness, ExecutionEnv } from "../../internal/harness.js";
|
|
31
|
+
import type { SubagentWorktreeIsolation } from "../../agents/subagent.js";
|
|
32
|
+
import { forkGovernanceDenial } from "../../agents/subagent.js";
|
|
33
|
+
import type { SubagentRetainLedger } from "../../agents/retain-ledger.js";
|
|
34
|
+
import type { PromptEpochArtifact } from "../../prompt-assembly/artifact.js";
|
|
35
|
+
import type { ReadFace } from "../../tools/fs/index.js";
|
|
36
|
+
import type { AutoModeArmingRecipe } from "../auto-mode-arming.js";
|
|
37
|
+
import type { AutoModeDecider, AutoModeDenialTracker } from "../auto-mode.js";
|
|
38
|
+
import { type OnQuestion } from "../ask-question.js";
|
|
39
|
+
import { type HookEnvCapabilities, type Hooks } from "../hooks.js";
|
|
40
|
+
import type { LockedPreflight } from "../locked-config.js";
|
|
41
|
+
import type { OwnOrgAdmissionVerdict } from "../memory-admission.js";
|
|
42
|
+
import type { DelegationContentSafety } from "../memory-engine/delegation-provenance.js";
|
|
43
|
+
import type { SessionPermissionRules } from "../session-policy-store.js";
|
|
44
|
+
import type { SessionStore } from "../session.js";
|
|
45
|
+
import { type OnAsk } from "../tool-policy.js";
|
|
46
|
+
import type { RunnerDeps, RuntimeCaps, TaskEvent, TaskSpec, ToolExecuteContext } from "../types.js";
|
|
47
|
+
import type { ActiveSkillScope } from "./active-skill-scope.js";
|
|
48
|
+
import type { InheritedGate, Prepared, PrepareResume, RunInternals, ToolFaceSnapshot } from "./contracts.js";
|
|
49
|
+
import { type StopForDenialLimit } from "./denial-limit-arms.js";
|
|
50
|
+
export interface PrepareInheritedGateInput {
|
|
51
|
+
/** borrowed-readonly — the REBOUND spec. Read: `shellGate` (the own doctrine the chain fold tightens), `durableApproval`
|
|
52
|
+
* (the mandate tests + the children's copy), `onAsk`/`onQuestion` (the frozen seats), `handsReadOnly` / `interactiveTools`
|
|
53
|
+
* / `oneShot` / `clientContext` / `principal` / `additionalDirectories` / `additionalReadDirectories` / `envFacts` /
|
|
54
|
+
* `memoryPersistenceCapable` / `getApiKeyAndHeaders` / `checkpointStore` / `backgroundScope` / `enablePlanMode` (the ctx
|
|
55
|
+
* enrichment's trusted seats). Never mutated. */
|
|
56
|
+
spec: Pick<TaskSpec, "shellGate" | "durableApproval" | "onAsk" | "onQuestion" | "handsReadOnly" | "interactiveTools" | "oneShot" | "clientContext" | "principal" | "additionalDirectories" | "additionalReadDirectories" | "envFacts" | "memoryPersistenceCapable" | "getApiKeyAndHeaders" | "checkpointStore" | "backgroundScope" | "enablePlanMode">;
|
|
57
|
+
/** borrowed-readonly — the deployment seats: `autoMode.denialLimit` (the rebuilt trackers' bounds), `memoryScopeAdmission` /
|
|
58
|
+
* `deploymentMemoryScopes` / `compliancePostureResolver` (the governed-provenance bit), `onError` (the screening-face crash
|
|
59
|
+
* lane), `onNotice` (the stop seat's notice), `executionEnv` (the hook-env identity predicate), `delegationEntryCaps` (resolved
|
|
60
|
+
* and validated once here), `rosterStore` / `onBackgroundChildEvent` (ctx seats), `onAsk` / `onQuestion` (the deps half of the
|
|
61
|
+
* frozen seats). */
|
|
62
|
+
deps: Pick<RunnerDeps, "autoMode" | "memoryScopeAdmission" | "deploymentMemoryScopes" | "compliancePostureResolver" | "onError" | "onNotice" | "executionEnv" | "delegationEntryCaps" | "rosterStore" | "onBackgroundChildEvent" | "onAsk" | "onQuestion">;
|
|
63
|
+
/** borrowed-readonly — the trusted spawn-side channel: `inheritedGate` (the LIVE half of the chain fold), `ownOrgAdmissionRef`
|
|
64
|
+
* (the same-session continuation's freeze), `delegationProvenance` (the F-012 stamp), and the identity / peer / notification
|
|
65
|
+
* seats the ctx enrichment forwards. Never mutated. */
|
|
66
|
+
internals: Pick<RunInternals, "inheritedGate" | "ownOrgAdmissionRef" | "delegationProvenance" | "memoryCaptureAncestors" | "parentTaskId" | "parentSessionId" | "rootSessionId" | "placementRoot" | "explicitAgentName" | "peerSelfRef" | "peerInboundChainRef" | "onTaskNotification" | "onSubagentSpawn" | "insideFork"> | undefined;
|
|
67
|
+
/** borrowed-readonly — the resume leg, or undefined on a fresh one: `seed.inheritedGate` is the CHECKPOINT half of the chain
|
|
68
|
+
* fold (the trust floor the live half may only tighten), `seed.readFace` the hands-less re-park's carried section. */
|
|
69
|
+
resume: Pick<PrepareResume, "seed"> | undefined;
|
|
70
|
+
/** borrowed-readonly — the session store's fork face: `fork` / `release` are bound into the ctx's `hostSessionFork` (present
|
|
71
|
+
* only when the store can fork). */
|
|
72
|
+
sessions: Pick<SessionStore, "fork" | "release">;
|
|
73
|
+
/** borrowed-readonly — the acquired session id (the crash lane's context, the ctx seat, the ancestor chain's own row). */
|
|
74
|
+
sessionId: string;
|
|
75
|
+
/** borrowed-readonly — the run's invocation id (the stop seat's notice names it). */
|
|
76
|
+
runId: string;
|
|
77
|
+
/** borrowed-readonly — the per-task identity (`ctx.taskId`, the same fallback the runner uses). */
|
|
78
|
+
hostTaskId: string;
|
|
79
|
+
/** borrowed-readonly — the SETTLED task root (`ctx.parentCwd`). */
|
|
80
|
+
taskRootFinal: string;
|
|
81
|
+
/** borrowed-readonly — the run's resolved env: the full-shell predicate's kind test and the hook-env identity value. */
|
|
82
|
+
executionEnv: ExecutionEnv;
|
|
83
|
+
/** borrowed-readonly — the per-task owned env when a factory minted one (the hook-env identity predicate reads presence). */
|
|
84
|
+
ownedEnv: ExecutionEnv | undefined;
|
|
85
|
+
/** borrowed-readonly — the frozen preflight; only `toolPolicy` (the RESOLVED caller policy the children's chain carries). */
|
|
86
|
+
lockedPreflight: Pick<LockedPreflight, "toolPolicy">;
|
|
87
|
+
/** borrowed-readonly — the frozen tool-face snapshot (the ctx forwards exclude / defer / alwaysLoad / restoreGated; the
|
|
88
|
+
* full-shell predicate reads the exclusion of Bash). */
|
|
89
|
+
toolFaceSnapshot: ToolFaceSnapshot;
|
|
90
|
+
/** borrowed-readonly — the resolved prompt profile (ctx seat). */
|
|
91
|
+
promptProfile: ToolExecuteContext["promptProfile"];
|
|
92
|
+
/** borrowed-readonly — the resolved interaction posture (ctx seat; absent ⇒ no key). */
|
|
93
|
+
resolvedInteractionPosture: ToolExecuteContext["interactionPosture"];
|
|
94
|
+
/** borrowed-readonly — the task's own auto-mode intent seat, screened and snapshotted before the first await. */
|
|
95
|
+
autoModeSeat: boolean;
|
|
96
|
+
/** borrowed-readonly — whether an execution env is wired at all (the full-shell predicate's first term). */
|
|
97
|
+
handsEnabled: boolean;
|
|
98
|
+
/** borrowed-readonly — the nested-usage sink the ctx forwards. */
|
|
99
|
+
reportUsage: ToolExecuteContext["reportUsage"];
|
|
100
|
+
/** borrowed-readonly — the harness seat (the ctx's model / thinking snapshots read it call-time). Not written here. */
|
|
101
|
+
harnessRef: {
|
|
102
|
+
current?: AgentHarness;
|
|
103
|
+
};
|
|
104
|
+
/** borrowed-readonly — the per-task skill scope (the ctx's `activeSkillScope` snapshot reads it call-time). Not written here. */
|
|
105
|
+
skillScope: ActiveSkillScope;
|
|
106
|
+
/** borrowed-readonly — the filtered display-forwarding wrapper (ctx seat; absent ⇒ no key). */
|
|
107
|
+
forwardEvent: ((e: TaskEvent) => void) | undefined;
|
|
108
|
+
/** borrowed-readonly — the retain ledger (ctx seat; absent ⇒ no key). */
|
|
109
|
+
subagentRetain: SubagentRetainLedger | undefined;
|
|
110
|
+
/** borrowed-readonly — the worktree-isolation helper (ctx seat; absent ⇒ no key). */
|
|
111
|
+
worktreeIsolation: SubagentWorktreeIsolation | undefined;
|
|
112
|
+
/** borrowed-readonly — the three run-ref primitives the ctx exposes (plan mode only under `enablePlanMode`). */
|
|
113
|
+
requestReview: (opts?: {
|
|
114
|
+
reason?: string;
|
|
115
|
+
}) => void;
|
|
116
|
+
/** borrowed-readonly — see `requestReview`. */
|
|
117
|
+
requestStopAfterTurn: () => void;
|
|
118
|
+
/** borrowed-readonly — see `requestReview`. */
|
|
119
|
+
enterPlanMode: () => void;
|
|
120
|
+
/** borrowed-readonly — the leg's reminder mark (ctx seat). */
|
|
121
|
+
reminderMark: string;
|
|
122
|
+
/** borrowed-readonly — the leg's disclosure counters (ctx seat; the outlets that bump them are not in this phase). */
|
|
123
|
+
reminderDisclosureCounts: Prepared["reminderDisclosureCounts"];
|
|
124
|
+
/** borrowed-readonly — the file-history fixed point the ctx threads to delegation tools (only when enabled). */
|
|
125
|
+
fileHistoryEnabled: boolean;
|
|
126
|
+
/** borrowed-readonly — see `fileHistoryEnabled`. */
|
|
127
|
+
historyScope: string;
|
|
128
|
+
/** borrowed-readonly — see `fileHistoryEnabled`. */
|
|
129
|
+
historyRoot: string;
|
|
130
|
+
/** borrowed-readonly — see `fileHistoryEnabled`. */
|
|
131
|
+
historyFs: string;
|
|
132
|
+
/** borrowed-readonly — the driver's composition of the run's abort (controller + harness), the stop seat's headless arm.
|
|
133
|
+
* Composed by the driver because the harness is built after this phase; the seat only ever fires at run time. */
|
|
134
|
+
abortRun: () => void;
|
|
135
|
+
/** borrowed-readonly — LATE-BOUND: the per-principal entitlements the caps phase resolves after this one; read only inside
|
|
136
|
+
* `inheritedGateForChildren` (the two mandate tests), at spawn time. */
|
|
137
|
+
runtimeCaps: () => RuntimeCaps | undefined;
|
|
138
|
+
/** borrowed-readonly — LATE-BOUND: the resolved hook record (`spec.hooks ?? deps.hooks`), read inside the chain assembly for
|
|
139
|
+
* this task's own screening face. */
|
|
140
|
+
hooks: () => Hooks | undefined;
|
|
141
|
+
/** borrowed-readonly — LATE-BOUND: whether the deployment declared its screening face observational (then it rides no entry). */
|
|
142
|
+
preToolUseObservational: () => boolean;
|
|
143
|
+
/** borrowed-readonly — LATE-BOUND: the validated per-invocation hook bound the screening-face entry's policy runs under. */
|
|
144
|
+
hookTimeoutMs: () => number;
|
|
145
|
+
/** borrowed-readonly — LATE-BOUND: the hook-env capability face the screening-face entry's policy resolves paths in. */
|
|
146
|
+
hookEnvFace: () => HookEnvCapabilities | undefined;
|
|
147
|
+
/** borrowed-readonly — LATE-BOUND: the armed classifier (undefined = not armed), read where the chain freezes it onto both
|
|
148
|
+
* entries and where the ctx exposes the spawn-review seat. */
|
|
149
|
+
autoModeDecider: () => AutoModeDecider | undefined;
|
|
150
|
+
/** borrowed-readonly — LATE-BOUND: the denial tracker built beside the decider; rides wherever the decider rides. */
|
|
151
|
+
autoModeDenialTracking: () => AutoModeDenialTracker | undefined;
|
|
152
|
+
/** borrowed-readonly — LATE-BOUND: the serializable arming recipe (persistArming opt-in only). */
|
|
153
|
+
autoModeArming: () => AutoModeArmingRecipe | undefined;
|
|
154
|
+
/** borrowed-readonly — LATE-BOUND: the fork-governance verdict (ctx `forkAccess`, present only when denied). */
|
|
155
|
+
agentForkDenial: () => ReturnType<typeof forkGovernanceDenial>;
|
|
156
|
+
/** borrowed-readonly — LATE-BOUND: the observers grant (ctx `observersAllowed`, present only when explicitly granted). */
|
|
157
|
+
observersActive: () => boolean;
|
|
158
|
+
/** borrowed-readonly — LATE-BOUND: the hands mount's resolved read face (undefined until/unless hands mount). */
|
|
159
|
+
resolvedReadFace: () => ReadFace | undefined;
|
|
160
|
+
/** borrowed-readonly — LATE-BOUND: the normalized deny additions in force (empty until the hands mount resolves them). */
|
|
161
|
+
readDenyAdditionsNormalized: () => ReadonlyArray<{
|
|
162
|
+
pattern: string;
|
|
163
|
+
caseSensitive: boolean;
|
|
164
|
+
}>;
|
|
165
|
+
/** borrowed-readonly — LATE-BOUND: the hands-less legs' resolved face (the carrier's second source). */
|
|
166
|
+
handsLessResolvedFace: () => ReadFace | undefined;
|
|
167
|
+
/** borrowed-readonly — LATE-BOUND: the adopted center artifact (ctx `centerArtifactDigest` / `centerSourceRevision`). */
|
|
168
|
+
centerAdoption: () => {
|
|
169
|
+
artifact: PromptEpochArtifact;
|
|
170
|
+
sourceRevision?: string;
|
|
171
|
+
} | undefined;
|
|
172
|
+
/** borrowed-readonly — LATE-BOUND: the memory-engine session (the ctx's capture-floor getters read it at THEIR call time). */
|
|
173
|
+
memoryEngineSession: () => Prepared["memoryEngineSession"];
|
|
174
|
+
}
|
|
175
|
+
export interface PrepareInheritedGateResult {
|
|
176
|
+
/** owned — the LIVE half of the inherited chain as supplied (`internals.inheritedGate`); the durable-gate notice reads it. */
|
|
177
|
+
liveInheritedGate: RunInternals["inheritedGate"];
|
|
178
|
+
/** owned — the CHECKPOINT half (`resume.seed.inheritedGate`); the suspend serializer re-reads its frozen chain. */
|
|
179
|
+
seedInheritedGate: PrepareResume["seed"]["inheritedGate"];
|
|
180
|
+
/** owned — the rev-monotonic fold of the two halves' ancestor rules (live replaces per (session, principal) only at ≥ rev). */
|
|
181
|
+
inheritedAncestorRules: InheritedGate["ancestorRules"];
|
|
182
|
+
/** owned — the max-rank fold of the two halves' shellGate doctrines (before the spec's own is applied). */
|
|
183
|
+
inheritedShellGate: InheritedGate["shellGate"];
|
|
184
|
+
/** owned — the live parent constraints with a fresh denial tracker attached per rebuilt decider. */
|
|
185
|
+
inheritedParentConstraints: NonNullable<InheritedGate["parentConstraints"]>[number][] | undefined;
|
|
186
|
+
/** owned — the auto-mode INTENT (own seat ∨ live chain ∨ checkpoint bit); the arming site judges the other two arms. */
|
|
187
|
+
autoModeIntent: boolean;
|
|
188
|
+
/** owned — the seed ∩ live admitted org scopes (one side absent ⇒ the other; both absent ⇒ undefined). */
|
|
189
|
+
inheritedAdmittedOrgScopes: readonly string[] | undefined;
|
|
190
|
+
/** owned — the prior own org verdict: checkpoint ∩ same-session ref (either alone stands; neither ⇒ undefined). */
|
|
191
|
+
priorOwnOrgVerdict: OwnOrgAdmissionVerdict | undefined;
|
|
192
|
+
/** owned — the monotonic governed-provenance bit for this leg. */
|
|
193
|
+
orgGovernedProvenance: boolean;
|
|
194
|
+
/** owned — the spec's own shellGate tightened by the inherited doctrine. */
|
|
195
|
+
effectiveShellGate: "off" | "classify" | "always";
|
|
196
|
+
/** borrowed-mutable — THIS task's own session-rule snapshot for its children's chain. Writers (R-3): the policy-chain
|
|
197
|
+
* station's session-policy read, once per leg, when a store is wired and the task carries its own sessionId. Read by
|
|
198
|
+
* `inheritedGateForChildren` at spawn time. */
|
|
199
|
+
ownSessionRulesRef: {
|
|
200
|
+
current?: {
|
|
201
|
+
sessionId: string;
|
|
202
|
+
principal?: string;
|
|
203
|
+
rev: number;
|
|
204
|
+
rules: SessionPermissionRules;
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
/** borrowed-mutable — THIS task's own frozen admitted org scopes for its children's chain. Writers: the memory phase's
|
|
208
|
+
* admission door, once per leg. Read by the chain assembly (always emitted, empty = no org plane). */
|
|
209
|
+
memoryAdmittedOrgScopesRef: {
|
|
210
|
+
current: readonly string[];
|
|
211
|
+
};
|
|
212
|
+
/** borrowed-mutable — the SESSION-freeze record for the suspend writer (present iff this leg adjudicated an org plane).
|
|
213
|
+
* Writers: the memory phase's admission door. Readers: the org stamp predicate here and the suspend serializer. */
|
|
214
|
+
ownOrgVerdictRef: {
|
|
215
|
+
current: OwnOrgAdmissionVerdict | undefined;
|
|
216
|
+
};
|
|
217
|
+
/** owned — the org-admission checkpoint stamp predicate (inherited set ∨ own verdict ∨ governed). */
|
|
218
|
+
orgAdmissionCheckpointState: () => boolean;
|
|
219
|
+
/** owned — the read-face checkpoint section builder (hands-less resume carries the seed; every other leg mints from the live
|
|
220
|
+
* resolution; undefined for the default posture). */
|
|
221
|
+
faceCheckpointSection: () => {
|
|
222
|
+
face: "open" | "roots";
|
|
223
|
+
denyEntries?: Array<{
|
|
224
|
+
pattern: string;
|
|
225
|
+
caseSensitive: boolean;
|
|
226
|
+
}>;
|
|
227
|
+
} | undefined;
|
|
228
|
+
/** owned — the face stamp predicate (`faceCheckpointSection() !== undefined`). */
|
|
229
|
+
faceCheckpointState: () => boolean;
|
|
230
|
+
/** owned — the F-012 stamp predicate (opaque constraints present ∨ seed frozen chain ∨ provenance-armed). */
|
|
231
|
+
f012CheckpointState: () => boolean;
|
|
232
|
+
/** owned — the FROZEN approver seat (spec over deps) every station of this leg and its children's chain resolve at. */
|
|
233
|
+
frozenOnAsk: OnAsk | undefined;
|
|
234
|
+
/** owned — the env the screening face sees through `ctx.env` (identity half of a chain entry's `hookEnv`); the policy-chain
|
|
235
|
+
* station's pass-through arm compares against it. */
|
|
236
|
+
hookEnvSource: unknown;
|
|
237
|
+
/** owned — the deployment lane for a screening face that crashes while screening a descendant's call (phase "hook"). */
|
|
238
|
+
notifyOwnHookCrash: (err: unknown) => void;
|
|
239
|
+
/** owned — the FROZEN question seat (spec over deps), the content-ask twin of `frozenOnAsk`. */
|
|
240
|
+
frozenOnQuestion: OnQuestion | undefined;
|
|
241
|
+
/** borrowed-mutable — the delegation runtime-provenance arming face. Writers: the memory phase's content-origin wrap section,
|
|
242
|
+
* once per leg when armed. Read lazily by delegation tools through the ctx. */
|
|
243
|
+
provenanceForChildrenRef: {
|
|
244
|
+
current?: DelegationContentSafety;
|
|
245
|
+
};
|
|
246
|
+
/** borrowed-mutable — the delegation-settlement coordinates. Writers: the memory phase, once per leg when a session exists.
|
|
247
|
+
* Read lazily by delegation tools through the ctx. */
|
|
248
|
+
delegationSettlementRef: {
|
|
249
|
+
current?: {
|
|
250
|
+
controlDir: string;
|
|
251
|
+
sessionId: string;
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
/** owned — chain assembly SINGLE SITE: upstream chain + this task's own contribution, called by delegation tools at spawn. */
|
|
255
|
+
inheritedGateForChildren: () => InheritedGate;
|
|
256
|
+
/** owned — the ONE carrier expression both delegation mounts consume (resolved face ?? hands-less face). */
|
|
257
|
+
carrierReadFace: () => ReadFace | undefined;
|
|
258
|
+
/** owned — the full shell's structural reachability from spec-time facts. */
|
|
259
|
+
fullShellReachable: boolean;
|
|
260
|
+
/** borrowed-mutable — the gate's typed stop seat (`Prepared.gateStopRef`). Writers: `stopForDenialLimit` only. */
|
|
261
|
+
gateStopRef: Prepared["gateStopRef"];
|
|
262
|
+
/** owned — the ONE closure that fills the stop seat (the denial-limit fallback's headless arm). */
|
|
263
|
+
stopForDenialLimit: StopForDenialLimit;
|
|
264
|
+
/** owned — the caller-tool ctx enrichment shared by the roster wrap and the revival spawner. */
|
|
265
|
+
enrichSpecToolCtx: (ctx: ToolExecuteContext) => ToolExecuteContext;
|
|
266
|
+
}
|
|
267
|
+
/** The M3b phase body — prepareTask's inherited-gate stretch, verbatim (see the module header). */
|
|
268
|
+
export declare function prepareInheritedGate(input: PrepareInheritedGateInput): PrepareInheritedGateResult;
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { forkGovernanceDenial, resolveDelegationEntryCaps } from "../../agents/subagent.js";
|
|
2
|
+
import { isLiveQuestionFace } from "../ask-question.js";
|
|
3
|
+
import { createPreToolUseConstraintPolicy } from "../hooks.js";
|
|
4
|
+
import { StubExecutionEnv } from "../stub-env.js";
|
|
5
|
+
import { askApproverIdentity, isLiveApproverSeat } from "../tool-policy.js";
|
|
6
|
+
import { attachRebuiltDenialTrackers, createDenialLimitStop } from "./denial-limit-arms.js";
|
|
7
|
+
export function prepareInheritedGate(input) {
|
|
8
|
+
const { spec, deps, internals, resume, sessions, sessionId, runId, hostTaskId, taskRootFinal, executionEnv, ownedEnv, lockedPreflight, toolFaceSnapshot, promptProfile, resolvedInteractionPosture, autoModeSeat, handsEnabled, reportUsage, harnessRef, skillScope, forwardEvent, subagentRetain, worktreeIsolation, requestReview, requestStopAfterTurn, enterPlanMode, reminderMark, reminderDisclosureCounts, fileHistoryEnabled, historyScope, historyRoot, historyFs, abortRun } = input;
|
|
9
|
+
const liveInheritedGate = internals?.inheritedGate;
|
|
10
|
+
const seedInheritedGate = resume?.seed.inheritedGate;
|
|
11
|
+
const inheritedAncestorRules = (() => {
|
|
12
|
+
const seedRules = seedInheritedGate?.ancestorRules;
|
|
13
|
+
const liveRules = liveInheritedGate?.ancestorRules;
|
|
14
|
+
if (seedRules === undefined || seedRules.length === 0)
|
|
15
|
+
return liveRules ?? seedRules;
|
|
16
|
+
if (liveRules === undefined || liveRules.length === 0)
|
|
17
|
+
return seedRules;
|
|
18
|
+
const merged = seedRules.map((s) => {
|
|
19
|
+
const live = liveRules.find((l) => l.sessionId === s.sessionId && l.principal === s.principal);
|
|
20
|
+
return live !== undefined && live.rev >= s.rev ? live : s;
|
|
21
|
+
});
|
|
22
|
+
const extras = liveRules.filter((l) => !seedRules.some((s) => s.sessionId === l.sessionId && s.principal === l.principal));
|
|
23
|
+
return [...merged, ...extras];
|
|
24
|
+
})();
|
|
25
|
+
const shellGateRank = { off: 0, classify: 1, always: 2 };
|
|
26
|
+
const liveShellGate = liveInheritedGate?.shellGate;
|
|
27
|
+
const seedShellGate = seedInheritedGate?.shellGate;
|
|
28
|
+
const inheritedShellGate = liveShellGate === undefined
|
|
29
|
+
? seedShellGate
|
|
30
|
+
: seedShellGate === undefined
|
|
31
|
+
? liveShellGate
|
|
32
|
+
: shellGateRank[liveShellGate] >= shellGateRank[seedShellGate]
|
|
33
|
+
? liveShellGate
|
|
34
|
+
: seedShellGate;
|
|
35
|
+
const inheritedParentConstraints = attachRebuiltDenialTrackers(liveInheritedGate?.parentConstraints, deps.autoMode?.denialLimit);
|
|
36
|
+
const autoModeIntent = autoModeSeat || liveInheritedGate?.autoModeRequested === true || seedInheritedGate?.autoModeRequested === true;
|
|
37
|
+
const liveAdmittedOrg = liveInheritedGate?.admittedOrgScopes;
|
|
38
|
+
const seedAdmittedOrg = seedInheritedGate?.admittedOrgScopes;
|
|
39
|
+
const inheritedAdmittedOrgScopes = liveAdmittedOrg === undefined ? seedAdmittedOrg : seedAdmittedOrg === undefined ? liveAdmittedOrg : liveAdmittedOrg.filter((s) => seedAdmittedOrg.includes(s));
|
|
40
|
+
const inheritedOrgGoverned = liveInheritedGate?.orgAdmissionGoverned === true || seedInheritedGate?.orgAdmissionGoverned === true;
|
|
41
|
+
const checkpointOwnOrgVerdict = resume?.seed.inheritedGate?.ownAdmittedOrgScopes !== undefined
|
|
42
|
+
? { scopes: resume.seed.inheritedGate.ownAdmittedOrgScopes, writeScope: resume.seed.inheritedGate.ownAdmittedOrgWriteScope ?? null }
|
|
43
|
+
: undefined;
|
|
44
|
+
const refOwnOrgVerdict = internals?.ownOrgAdmissionRef?.current;
|
|
45
|
+
const priorOwnOrgVerdict = checkpointOwnOrgVerdict === undefined
|
|
46
|
+
? refOwnOrgVerdict
|
|
47
|
+
: refOwnOrgVerdict === undefined
|
|
48
|
+
? checkpointOwnOrgVerdict
|
|
49
|
+
: {
|
|
50
|
+
scopes: checkpointOwnOrgVerdict.scopes.filter((sc) => refOwnOrgVerdict.scopes.includes(sc)),
|
|
51
|
+
writeScope: checkpointOwnOrgVerdict.writeScope !== null && checkpointOwnOrgVerdict.writeScope === refOwnOrgVerdict.writeScope
|
|
52
|
+
? checkpointOwnOrgVerdict.writeScope
|
|
53
|
+
: null,
|
|
54
|
+
};
|
|
55
|
+
const orgGovernedProvenance = deps.memoryScopeAdmission !== undefined ||
|
|
56
|
+
(deps.deploymentMemoryScopes !== undefined && deps.deploymentMemoryScopes.length > 0) ||
|
|
57
|
+
deps.compliancePostureResolver !== undefined ||
|
|
58
|
+
inheritedOrgGoverned ||
|
|
59
|
+
priorOwnOrgVerdict !== undefined;
|
|
60
|
+
const specShellGate = spec.shellGate ?? "off";
|
|
61
|
+
const effectiveShellGate = inheritedShellGate !== undefined && shellGateRank[inheritedShellGate] > shellGateRank[specShellGate] ? inheritedShellGate : specShellGate;
|
|
62
|
+
const ownSessionRulesRef = {};
|
|
63
|
+
const memoryAdmittedOrgScopesRef = { current: [] };
|
|
64
|
+
const ownOrgVerdictRef = { current: undefined };
|
|
65
|
+
const orgAdmissionCheckpointState = () => inheritedAdmittedOrgScopes !== undefined || ownOrgVerdictRef.current !== undefined || orgGovernedProvenance;
|
|
66
|
+
const faceCheckpointSection = () => {
|
|
67
|
+
const resolvedReadFace = input.resolvedReadFace();
|
|
68
|
+
const handsLessResolvedFace = input.handsLessResolvedFace();
|
|
69
|
+
const readDenyAdditionsNormalized = input.readDenyAdditionsNormalized();
|
|
70
|
+
if (resolvedReadFace === undefined && resume !== undefined) {
|
|
71
|
+
const seed = resume.seed.readFace;
|
|
72
|
+
return seed !== undefined ? { face: seed.face, ...(seed.denyEntries !== undefined ? { denyEntries: seed.denyEntries.map((e) => ({ ...e })) } : {}) } : undefined;
|
|
73
|
+
}
|
|
74
|
+
const face = resolvedReadFace ?? handsLessResolvedFace;
|
|
75
|
+
if (face === undefined)
|
|
76
|
+
return undefined;
|
|
77
|
+
if (face === "open" || readDenyAdditionsNormalized.length > 0) {
|
|
78
|
+
return { face, ...(readDenyAdditionsNormalized.length > 0 ? { denyEntries: readDenyAdditionsNormalized.map((e) => ({ ...e })) } : {}) };
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
};
|
|
82
|
+
const faceCheckpointState = () => faceCheckpointSection() !== undefined;
|
|
83
|
+
const f012CheckpointState = () => (inheritedParentConstraints?.length ?? 0) > 0 ||
|
|
84
|
+
seedInheritedGate?.constraintChain !== undefined ||
|
|
85
|
+
internals?.delegationProvenance !== undefined;
|
|
86
|
+
const frozenOnAsk = spec.onAsk ?? deps.onAsk;
|
|
87
|
+
const hookEnvSource = (ownedEnv ?? deps.executionEnv) != null ? executionEnv : undefined;
|
|
88
|
+
const notifyOwnHookCrash = (err) => {
|
|
89
|
+
try {
|
|
90
|
+
deps.onError?.(err instanceof Error ? err : new Error(String(err)), { phase: "hook", sessionId });
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const frozenOnQuestion = spec.onQuestion ?? deps.onQuestion;
|
|
96
|
+
const provenanceForChildrenRef = {};
|
|
97
|
+
const delegationProvenanceForChildren = () => provenanceForChildrenRef.current;
|
|
98
|
+
const delegationSettlementRef = {};
|
|
99
|
+
const delegationSettlementForChildren = () => delegationSettlementRef.current;
|
|
100
|
+
const inheritedGateForChildren = () => {
|
|
101
|
+
const autoModeDecider = input.autoModeDecider();
|
|
102
|
+
const autoModeDenialTracking = input.autoModeDenialTracking();
|
|
103
|
+
const autoModeArming = input.autoModeArming();
|
|
104
|
+
const ancestorRules = [
|
|
105
|
+
...(inheritedAncestorRules ?? []),
|
|
106
|
+
...(ownSessionRulesRef.current !== undefined ? [ownSessionRulesRef.current] : []),
|
|
107
|
+
];
|
|
108
|
+
const ownCallerPolicy = lockedPreflight.toolPolicy;
|
|
109
|
+
const durableMandate = input.runtimeCaps()?.forceDurableGate === true ||
|
|
110
|
+
(spec.durableApproval !== undefined && !isLiveApproverSeat(frozenOnAsk));
|
|
111
|
+
const contentMandate = input.runtimeCaps()?.forceDurableGate === true ||
|
|
112
|
+
(spec.durableApproval !== undefined && !isLiveQuestionFace(frozenOnQuestion));
|
|
113
|
+
const ownPreToolUse = input.preToolUseObservational() ? undefined : input.hooks()?.preToolUse;
|
|
114
|
+
const hookConstraint = ownPreToolUse !== undefined &&
|
|
115
|
+
!(inheritedParentConstraints ?? []).some((pc) => pc.preToolUse === ownPreToolUse &&
|
|
116
|
+
askApproverIdentity(pc.onAsk) === askApproverIdentity(frozenOnAsk) &&
|
|
117
|
+
(pc.durableMandate === true) === durableMandate &&
|
|
118
|
+
(pc.contentMandate === true) === contentMandate &&
|
|
119
|
+
pc.hookEnv === hookEnvSource &&
|
|
120
|
+
pc.autoMode?.decider === autoModeDecider)
|
|
121
|
+
? [
|
|
122
|
+
{
|
|
123
|
+
policy: createPreToolUseConstraintPolicy(ownPreToolUse, input.hookEnvFace(), notifyOwnHookCrash, input.hookTimeoutMs()),
|
|
124
|
+
preToolUse: ownPreToolUse,
|
|
125
|
+
...(hookEnvSource !== undefined ? { hookEnv: hookEnvSource } : {}),
|
|
126
|
+
...(frozenOnAsk !== undefined ? { onAsk: frozenOnAsk } : {}),
|
|
127
|
+
...(durableMandate ? { durableMandate: true } : {}),
|
|
128
|
+
...(contentMandate ? { contentMandate: true } : {}),
|
|
129
|
+
...(autoModeDecider !== undefined
|
|
130
|
+
? { autoMode: { decider: autoModeDecider, ...(autoModeDenialTracking !== undefined ? { denialTracking: autoModeDenialTracking } : {}), ...(autoModeArming !== undefined ? { arming: autoModeArming } : {}) } }
|
|
131
|
+
: {}),
|
|
132
|
+
},
|
|
133
|
+
]
|
|
134
|
+
: [];
|
|
135
|
+
const parentConstraints = [
|
|
136
|
+
...(inheritedParentConstraints ?? []),
|
|
137
|
+
...hookConstraint,
|
|
138
|
+
...(ownCallerPolicy !== undefined
|
|
139
|
+
? [
|
|
140
|
+
{
|
|
141
|
+
policy: ownCallerPolicy,
|
|
142
|
+
...(frozenOnAsk !== undefined ? { onAsk: frozenOnAsk } : {}),
|
|
143
|
+
...(durableMandate ? { durableMandate: true } : {}),
|
|
144
|
+
...(contentMandate ? { contentMandate: true } : {}),
|
|
145
|
+
...(autoModeDecider !== undefined
|
|
146
|
+
? { autoMode: { decider: autoModeDecider, ...(autoModeDenialTracking !== undefined ? { denialTracking: autoModeDenialTracking } : {}), ...(autoModeArming !== undefined ? { arming: autoModeArming } : {}) } }
|
|
147
|
+
: {}),
|
|
148
|
+
},
|
|
149
|
+
]
|
|
150
|
+
: []),
|
|
151
|
+
];
|
|
152
|
+
return {
|
|
153
|
+
...(ancestorRules.length > 0 ? { ancestorRules } : {}),
|
|
154
|
+
...(effectiveShellGate !== "off" ? { shellGate: effectiveShellGate } : {}),
|
|
155
|
+
...(autoModeIntent ? { autoModeRequested: true } : {}),
|
|
156
|
+
...(parentConstraints.length > 0 ? { parentConstraints } : {}),
|
|
157
|
+
admittedOrgScopes: memoryAdmittedOrgScopesRef.current,
|
|
158
|
+
...(orgGovernedProvenance ? { orgAdmissionGoverned: true } : {}),
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
const carrierReadFace = () => input.resolvedReadFace() ?? input.handsLessResolvedFace();
|
|
162
|
+
const fullShellReachable = handsEnabled &&
|
|
163
|
+
!(executionEnv instanceof StubExecutionEnv) &&
|
|
164
|
+
spec.handsReadOnly !== true &&
|
|
165
|
+
!(toolFaceSnapshot.exclude?.includes("Bash") ?? false);
|
|
166
|
+
const { gateStopRef, stopForDenialLimit } = createDenialLimitStop({ sessionId, runId, onNotice: deps.onNotice, abort: abortRun });
|
|
167
|
+
const delegationEntryCapsResolved = resolveDelegationEntryCaps(deps.delegationEntryCaps);
|
|
168
|
+
const enrichSpecToolCtx = (ctx) => {
|
|
169
|
+
const agentForkDenial = input.agentForkDenial();
|
|
170
|
+
const observersActive = input.observersActive();
|
|
171
|
+
const readDenyAdditionsNormalized = input.readDenyAdditionsNormalized();
|
|
172
|
+
const autoModeDecider = input.autoModeDecider();
|
|
173
|
+
const centerAdoption = input.centerAdoption();
|
|
174
|
+
return {
|
|
175
|
+
...ctx,
|
|
176
|
+
delegationEntryCaps: delegationEntryCapsResolved,
|
|
177
|
+
reportUsage,
|
|
178
|
+
model: harnessRef.current?.getModel(),
|
|
179
|
+
thinkingLevel: harnessRef.current?.getThinkingLevel(),
|
|
180
|
+
principal: spec.principal,
|
|
181
|
+
...(frozenOnAsk !== undefined ? { onAsk: frozenOnAsk } : {}),
|
|
182
|
+
...(frozenOnQuestion !== undefined ? { onQuestion: frozenOnQuestion } : {}),
|
|
183
|
+
...(spec.handsReadOnly === true ? { handsReadOnly: true } : {}),
|
|
184
|
+
...(carrierReadFace() === "roots" ? { readFace: "roots" } : {}),
|
|
185
|
+
...(readDenyAdditionsNormalized.length > 0 ? { readDenyPatterns: Object.freeze(readDenyAdditionsNormalized.map((e) => ({ ...e }))) } : {}),
|
|
186
|
+
...(spec.interactiveTools === false ? { interactiveTools: false } : {}),
|
|
187
|
+
oneShot: spec.oneShot,
|
|
188
|
+
clientContext: spec.clientContext,
|
|
189
|
+
excludeTools: toolFaceSnapshot.exclude,
|
|
190
|
+
deferTools: toolFaceSnapshot.defer,
|
|
191
|
+
alwaysLoadTools: toolFaceSnapshot.alwaysLoad,
|
|
192
|
+
...(toolFaceSnapshot.restoreGated !== undefined ? { restoreGatedTools: toolFaceSnapshot.restoreGated } : {}),
|
|
193
|
+
promptProfile,
|
|
194
|
+
...(spec.additionalDirectories !== undefined ? { additionalDirectories: Object.freeze([...spec.additionalDirectories]) } : {}),
|
|
195
|
+
...(spec.additionalReadDirectories !== undefined ? { additionalReadDirectories: Object.freeze([...spec.additionalReadDirectories]) } : {}),
|
|
196
|
+
...(spec.envFacts !== undefined ? { envFacts: { ...spec.envFacts } } : {}),
|
|
197
|
+
...(spec.memoryPersistenceCapable !== undefined ? { memoryPersistenceCapable: spec.memoryPersistenceCapable } : {}),
|
|
198
|
+
get memoryCaptureOptedOut() {
|
|
199
|
+
return input.memoryEngineSession()?.captureOptOut?.optedOut() ?? false;
|
|
200
|
+
},
|
|
201
|
+
get memoryCaptureIndeterminate() {
|
|
202
|
+
return input.memoryEngineSession()?.captureOptOut?.indeterminate() ?? false;
|
|
203
|
+
},
|
|
204
|
+
get memoryCaptureControlDir() {
|
|
205
|
+
return input.memoryEngineSession()?.engine.controlPlaneDir;
|
|
206
|
+
},
|
|
207
|
+
get memoryCaptureAncestors() {
|
|
208
|
+
const ctl = input.memoryEngineSession()?.engine.controlPlaneDir;
|
|
209
|
+
return [...(internals?.memoryCaptureAncestors ?? []), { sessionId, ...(ctl !== undefined ? { controlDir: ctl } : {}) }];
|
|
210
|
+
},
|
|
211
|
+
getApiKeyAndHeaders: spec.getApiKeyAndHeaders,
|
|
212
|
+
parentCwd: taskRootFinal,
|
|
213
|
+
...(fileHistoryEnabled ? { fileHistoryLineage: { scope: historyScope, root: historyRoot, fs: historyFs } } : {}),
|
|
214
|
+
reminderMark,
|
|
215
|
+
reminderDisclosureCounts,
|
|
216
|
+
...(centerAdoption !== undefined ? { centerArtifactDigest: centerAdoption.artifact.artifactDigest } : {}),
|
|
217
|
+
...(centerAdoption?.sourceRevision !== undefined ? { centerSourceRevision: centerAdoption.sourceRevision } : {}),
|
|
218
|
+
activeSkillScope: () => skillScope.active(),
|
|
219
|
+
inheritedGateForChildren,
|
|
220
|
+
delegationProvenanceForChildren,
|
|
221
|
+
delegationSettlement: delegationSettlementForChildren,
|
|
222
|
+
...(autoModeDecider ? { autoModeReview: { decider: autoModeDecider } } : {}),
|
|
223
|
+
...(spec.durableApproval !== undefined ? { durableApprovalForChildren: { ...spec.durableApproval } } : {}),
|
|
224
|
+
...(spec.checkpointStore === null ? { checkpointStoreDisabledForChildren: true } : {}),
|
|
225
|
+
taskId: hostTaskId,
|
|
226
|
+
...(internals?.parentTaskId !== undefined ? { parentTaskId: internals.parentTaskId } : {}),
|
|
227
|
+
...(internals?.parentSessionId !== undefined ? { parentSessionId: internals.parentSessionId } : {}),
|
|
228
|
+
...(internals?.rootSessionId !== undefined ? { rootSessionId: internals.rootSessionId } : {}), ...(internals?.placementRoot !== undefined ? { placementRoot: internals.placementRoot } : {}),
|
|
229
|
+
...(internals?.explicitAgentName !== undefined ? { spawnedAgentName: internals.explicitAgentName } : {}),
|
|
230
|
+
...(internals?.peerSelfRef !== undefined ? { peerSelfRef: internals.peerSelfRef } : {}),
|
|
231
|
+
...(internals?.peerInboundChainRef !== undefined ? { peerInboundChainRef: internals.peerInboundChainRef } : {}),
|
|
232
|
+
...(deps.rosterStore !== undefined ? { roster: deps.rosterStore } : {}),
|
|
233
|
+
...(sessions.fork !== undefined
|
|
234
|
+
? {
|
|
235
|
+
hostSessionFork: async () => {
|
|
236
|
+
const forked = (await sessions.fork(sessionId, spec.principal ?? null)) ?? null;
|
|
237
|
+
if (forked === null)
|
|
238
|
+
return null;
|
|
239
|
+
return {
|
|
240
|
+
sessionId: forked,
|
|
241
|
+
release: async () => {
|
|
242
|
+
await sessions.release?.(forked);
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
},
|
|
246
|
+
}
|
|
247
|
+
: {}),
|
|
248
|
+
sessionId,
|
|
249
|
+
...(spec.backgroundScope !== undefined ? { backgroundScope: spec.backgroundScope } : {}),
|
|
250
|
+
...(resolvedInteractionPosture !== undefined ? { interactionPosture: resolvedInteractionPosture } : {}),
|
|
251
|
+
...(deps.onBackgroundChildEvent ? { onBackgroundChildEvent: deps.onBackgroundChildEvent } : {}),
|
|
252
|
+
...(internals?.onTaskNotification ? { onTaskNotification: internals.onTaskNotification } : {}),
|
|
253
|
+
...(forwardEvent ? { forwardEvent } : {}),
|
|
254
|
+
...(internals?.onSubagentSpawn ? { onSubagentSpawn: internals.onSubagentSpawn } : {}),
|
|
255
|
+
...(subagentRetain ? { subagentRetain } : {}),
|
|
256
|
+
...(worktreeIsolation ? { worktreeIsolation } : {}),
|
|
257
|
+
...(internals?.insideFork === true ? { insideFork: true } : {}),
|
|
258
|
+
...(agentForkDenial !== undefined ? { forkAccess: { denied: agentForkDenial } } : {}),
|
|
259
|
+
...(observersActive ? { observersAllowed: true } : {}),
|
|
260
|
+
requestReview,
|
|
261
|
+
requestStopAfterTurn,
|
|
262
|
+
...(spec.enablePlanMode === true ? { enterPlanMode } : {}),
|
|
263
|
+
};
|
|
264
|
+
};
|
|
265
|
+
return { liveInheritedGate, seedInheritedGate, inheritedAncestorRules, inheritedShellGate, inheritedParentConstraints, autoModeIntent, inheritedAdmittedOrgScopes, priorOwnOrgVerdict, orgGovernedProvenance, effectiveShellGate, ownSessionRulesRef, memoryAdmittedOrgScopesRef, ownOrgVerdictRef, orgAdmissionCheckpointState, faceCheckpointSection, faceCheckpointState, f012CheckpointState, frozenOnAsk, hookEnvSource, notifyOwnHookCrash, frozenOnQuestion, provenanceForChildrenRef, delegationSettlementRef, inheritedGateForChildren, carrierReadFace, fullShellReachable, gateStopRef, stopForDenialLimit, enrichSpecToolCtx };
|
|
266
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* design/390 M15 — prepareTask's LISTINGS phase: the per-task agent definitions' tool-name audit
|
|
3
|
+
* (deny entries fail loud, allow entries advise), the agent-listing announce face read off the
|
|
4
|
+
* delegation tool's roster (with its deferred / excluded / removal-to-zero arms), the two listing
|
|
5
|
+
* opt-out advisories, the announced-listings mirror seeded from the once-per-session ledger, the
|
|
6
|
+
* deferred roster's ToolSearch ride, and the date_change seam. The body is the driver's stretch moved
|
|
7
|
+
* verbatim; the interface is the dependency list it had implicitly (design/238 R-1).
|
|
8
|
+
*
|
|
9
|
+
* SYNCHRONOUS FUNCTION, SYNCHRONOUS CALL: the stretch has no await, so the phase adds no yield between
|
|
10
|
+
* the disclosure mount before it and the context-lane seats after it (design/390 §1.5 S1: a stretch
|
|
11
|
+
* with no await is extracted as a sync function — an `async` wrapper would open a microtask window).
|
|
12
|
+
*
|
|
13
|
+
* Throws pass through unchanged: `config.agent.unknown_tool` (a deny entry naming a tool this
|
|
14
|
+
* deployment does not mount — a typo there would silently guard nothing).
|
|
15
|
+
*/
|
|
16
|
+
import type { AgentTool } from "../../internal/harness.js";
|
|
17
|
+
import type { TaskSpec } from "../types.js";
|
|
18
|
+
import type { AnnounceOnceSink, Prepared, PrepareResume, ToolFaceSnapshot } from "./contracts.js";
|
|
19
|
+
import type { AnnouncedListingSnapshot } from "../../internal/harness.js";
|
|
20
|
+
export interface PrepareListingsInput {
|
|
21
|
+
/** borrowed-readonly — the REBOUND spec (`spec′`). Read: `agents` (the audit's subject), `tools`
|
|
22
|
+
* (the roster-bearing delegation tool, by its `agentListing` marker), `sessionId` (continuation
|
|
23
|
+
* ⇒ seeded/removal projections), `attachments` (the two opt-outs). Never mutated. */
|
|
24
|
+
spec: Pick<TaskSpec, "agents" | "tools" | "sessionId" | "attachments">;
|
|
25
|
+
/** borrowed-readonly — the FULLY ASSEMBLED mount array (names + aliases = the audit's universe).
|
|
26
|
+
* Read only; this phase never mutates the roster. */
|
|
27
|
+
tools: ReadonlyArray<AgentTool>;
|
|
28
|
+
/** borrowed-readonly — the once-per-session ledger: its deduplicated operator sink (`onError`) and
|
|
29
|
+
* the whole announced snapshot (`arms()`) the mirror is seeded from. */
|
|
30
|
+
onceLedger: AnnounceOnceSink & {
|
|
31
|
+
arms(): AnnouncedListingSnapshot;
|
|
32
|
+
};
|
|
33
|
+
/** borrowed-readonly — the acquired session's id (operator-line context). */
|
|
34
|
+
sessionId: string;
|
|
35
|
+
/** borrowed-readonly — the frozen tool face: `exclude` / `defer` decide the roster face's arm. */
|
|
36
|
+
toolFaceSnapshot: Pick<ToolFaceSnapshot, "exclude" | "defer">;
|
|
37
|
+
/** borrowed-readonly — the activated deferred names as of prepare (transcript replay / checkpoint
|
|
38
|
+
* seed); only `has()` is read: an already-ACTIVE roster tool un-defers its listing face. The set
|
|
39
|
+
* keeps mutating mid-run (ToolSearch activations) — this phase reads it once, here. */
|
|
40
|
+
activeTools: ReadonlySet<string>;
|
|
41
|
+
/** borrowed-readonly — the durable-resume carrier: presence (seedAnnounced) and
|
|
42
|
+
* `seed.announcedListings.agents` (the removal-to-zero projection's gate). */
|
|
43
|
+
resume: Pick<PrepareResume, "seed"> | undefined;
|
|
44
|
+
/** borrowed-readonly — the project-context phase's skills-listing projection; read only for the
|
|
45
|
+
* skills opt-out advisory (entries.length). */
|
|
46
|
+
skillsListing: Prepared["skillsListing"];
|
|
47
|
+
/** borrowed-mutable — the deferred roster's ToolSearch RIDE seat (declared by the disclosure
|
|
48
|
+
* mount, read at activation time through `listingRideRef.current?.(newly)`). Written here, once,
|
|
49
|
+
* on a deferred roster face; no later writer. Identity is the contract (the mount's closures read
|
|
50
|
+
* this exact cell). */
|
|
51
|
+
listingRideRef: {
|
|
52
|
+
current?: (newly: readonly string[]) => string | undefined;
|
|
53
|
+
};
|
|
54
|
+
/** borrowed-readonly — the prompt assembly's date re-renderer; presence alone decides whether the
|
|
55
|
+
* date_change seam exists (a provider that owns the whole prompt has none). */
|
|
56
|
+
renderWithDate: ((date: string) => string) | undefined;
|
|
57
|
+
/** borrowed-readonly — the environment facts; only `date` is read (the leg's frozen date). */
|
|
58
|
+
envFacts: {
|
|
59
|
+
readonly date?: string;
|
|
60
|
+
};
|
|
61
|
+
/** borrowed-readonly — whether the client zone validated (the seam re-judges "today" in it). */
|
|
62
|
+
tzValid: boolean;
|
|
63
|
+
/** borrowed-readonly — the client's declared zone (used only when `tzValid`). */
|
|
64
|
+
userTz: string | undefined;
|
|
65
|
+
}
|
|
66
|
+
export interface PrepareListingsResult {
|
|
67
|
+
/** owned — the agent-listing announce projection (`Prepared.agentListing`): the roster off the
|
|
68
|
+
* delegation tool's effective face, the removal-to-zero projection, or undefined (silent). */
|
|
69
|
+
agentListing: Prepared["agentListing"];
|
|
70
|
+
/** owned — the announced-listings mirror seeded from the ledger's whole snapshot
|
|
71
|
+
* (`Prepared.announcedListingsRef`); the run loop and the checkpoint serializer write it from here on. */
|
|
72
|
+
announcedListingsRef: Prepared["announcedListingsRef"];
|
|
73
|
+
/** owned — the date_change seam (`Prepared.dateChange`), or undefined when the prompt has no date re-renderer. */
|
|
74
|
+
dateChange: Prepared["dateChange"];
|
|
75
|
+
}
|
|
76
|
+
/** The M15 phase body — prepareTask's listings stretch, verbatim (see the module header). */
|
|
77
|
+
export declare function prepareListings(input: PrepareListingsInput): PrepareListingsResult;
|