@sema-agent/core 7.63.0 → 7.65.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 +725 -0
- package/dist/agents/cc-peer-directory.js +1 -0
- package/dist/agents/cc-peer-wire.d.ts +4 -0
- package/dist/agents/cc-peer-wire.js +1 -0
- package/dist/agents/cc-uds-peer-channel.js +5 -0
- package/dist/agents/cross-session-judge.d.ts +3 -1
- package/dist/agents/cross-session-judge.js +4 -1
- package/dist/agents/peer-directory.d.ts +8 -0
- package/dist/agents/peer-directory.js +4 -0
- package/dist/agents/peer-held-queue.d.ts +9 -3
- package/dist/agents/peer-held-queue.js +12 -9
- package/dist/agents/peer-idle.d.ts +20 -1
- package/dist/agents/peer-idle.js +23 -12
- package/dist/agents/peer-notice-route.d.ts +16 -5
- package/dist/agents/peer-notice-route.js +11 -9
- package/dist/agents/peer-notices.d.ts +25 -8
- package/dist/agents/peer-notices.js +6 -1
- package/dist/agents/peer-session-drain.d.ts +32 -6
- package/dist/agents/peer-session-drain.js +100 -26
- package/dist/agents/send-message-tool.d.ts +7 -0
- package/dist/agents/send-message-tool.js +18 -6
- package/dist/agents/subagent.js +25 -5
- package/dist/core/allow-entry.d.ts +4 -0
- package/dist/core/ask-origin.d.ts +1 -1
- package/dist/core/ask-origin.js +2 -2
- package/dist/core/ask-unresolvable-notice.d.ts +13 -4
- package/dist/core/ask-unresolvable-notice.js +10 -3
- package/dist/core/auto-compaction.d.ts +7 -5
- package/dist/core/auto-promote.d.ts +3 -2
- package/dist/core/background-agent-store.d.ts +14 -0
- package/dist/core/background-agent-store.js +3 -0
- package/dist/core/checkpoint-queries.d.ts +9 -6
- package/dist/core/checkpoint-queries.js +8 -3
- package/dist/core/checkpoint-store.d.ts +7 -4
- package/dist/core/context-settings.d.ts +39 -9
- package/dist/core/context-settings.js +32 -10
- package/dist/core/engine-attestation.d.ts +26 -6
- package/dist/core/engine-attestation.js +5 -1
- package/dist/core/engine-notice.d.ts +37 -2
- package/dist/core/engine-notice.js +3 -1
- package/dist/core/extension-requester.d.ts +9 -0
- package/dist/core/extension-requester.js +7 -0
- package/dist/core/file-history-store.d.ts +30 -2
- package/dist/core/file-history-store.js +48 -9
- package/dist/core/fs-write-gate-policy.js +1 -1
- package/dist/core/gate-fold.js +5 -1
- package/dist/core/gate-lanes.js +2 -0
- package/dist/core/gate-outcome.d.ts +39 -2
- package/dist/core/gate-outcome.js +20 -1
- package/dist/core/governance-codes.d.ts +8 -4
- package/dist/core/governance-codes.js +8 -3
- package/dist/core/leg-identity.d.ts +35 -1
- package/dist/core/leg-identity.js +10 -0
- package/dist/core/mailbox-store.d.ts +39 -4
- package/dist/core/mailbox-store.js +14 -2
- package/dist/core/memory-engine/consolidation.d.ts +13 -6
- package/dist/core/memory-engine/consolidation.js +26 -0
- package/dist/core/memory-engine/control-objects.d.ts +58 -0
- package/dist/core/memory-engine/control-objects.js +273 -0
- package/dist/core/memory-engine/control-plane-adoption.d.ts +51 -0
- package/dist/core/memory-engine/control-plane-adoption.js +161 -0
- package/dist/core/memory-engine/delegation-settlement.d.ts +73 -40
- package/dist/core/memory-engine/delegation-settlement.js +271 -107
- package/dist/core/memory-engine/dual-root.d.ts +3 -2
- package/dist/core/memory-engine/dual-root.js +7 -3
- package/dist/core/memory-engine/engine.d.ts +54 -33
- package/dist/core/memory-engine/engine.js +150 -157
- package/dist/core/memory-engine/file-backend.d.ts +58 -76
- package/dist/core/memory-engine/file-backend.js +111 -268
- package/dist/core/memory-engine/index.d.ts +3 -2
- package/dist/core/memory-engine/index.js +2 -1
- package/dist/core/memory-engine/layout.d.ts +135 -50
- package/dist/core/memory-engine/layout.js +214 -89
- package/dist/core/memory-engine/memory-age.d.ts +12 -0
- package/dist/core/memory-engine/memory-age.js +17 -0
- package/dist/core/memory-engine/memory-backend-contract.d.ts +10 -3
- package/dist/core/memory-engine/memory-backend-contract.js +159 -2
- package/dist/core/memory-engine/memory-deployment.d.ts +12 -4
- package/dist/core/memory-engine/memory-deployment.js +31 -6
- package/dist/core/memory-engine/origin-clearance.d.ts +12 -3
- package/dist/core/memory-engine/origin-clearance.js +64 -9
- package/dist/core/memory-engine/session-write-home.d.ts +34 -1
- package/dist/core/memory-engine/session-write-home.js +37 -10
- package/dist/core/memory-engine/tools.d.ts +2 -2
- package/dist/core/memory-engine/tools.js +7 -7
- package/dist/core/memory-engine/types.d.ts +55 -12
- package/dist/core/memory-engine/types.js +2 -1
- package/dist/core/memory-vector.d.ts +6 -14
- package/dist/core/memory.d.ts +0 -462
- package/dist/core/memory.js +0 -333
- package/dist/core/mode-policy.js +3 -3
- package/dist/core/mods/agent-stations.d.ts +18 -0
- package/dist/core/mods/agent-stations.js +8 -6
- package/dist/core/mods/extension-call.d.ts +4 -0
- package/dist/core/mods/extension-call.js +8 -0
- package/dist/core/mods/tool-call.js +3 -4
- package/dist/core/parent-spec-seat.d.ts +2 -2
- package/dist/core/peer-channel.d.ts +5 -0
- package/dist/core/permission-rule-consent.d.ts +64 -22
- package/dist/core/permission-rule-consent.js +106 -58
- package/dist/core/permission-rule-store.d.ts +56 -21
- package/dist/core/permission-rule-store.js +2 -0
- package/dist/core/refusal-echo.d.ts +20 -0
- package/dist/core/refusal-echo.js +33 -0
- package/dist/core/retention.d.ts +175 -10
- package/dist/core/retention.js +44 -0
- package/dist/core/retired-keys.d.ts +5 -0
- package/dist/core/retired-keys.js +3 -0
- package/dist/core/rule-offer-read.d.ts +0 -4
- package/dist/core/rule-offer-read.js +2 -18
- package/dist/core/runner/classifier-ladder.d.ts +10 -2
- package/dist/core/runner/classifier-ladder.js +4 -2
- package/dist/core/runner/compact-session.js +10 -7
- package/dist/core/runner/compaction-call-options.d.ts +7 -7
- package/dist/core/runner/compaction-call-options.js +3 -2
- package/dist/core/runner/contracts.d.ts +28 -9
- package/dist/core/runner/delegation-owner.d.ts +2 -3
- package/dist/core/runner/delegation-owner.js +2 -1
- package/dist/core/runner/gate-exit.d.ts +6 -0
- package/dist/core/runner/gate-exit.js +11 -2
- package/dist/core/runner/memory-consolidation-driver.d.ts +4 -2
- package/dist/core/runner/memory-consolidation-driver.js +8 -5
- package/dist/core/runner/prepare-ask-lane.js +3 -3
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +3 -1
- package/dist/core/runner/prepare-caps-and-workflow.js +2 -2
- package/dist/core/runner/prepare-config-doors.js +4 -0
- package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
- package/dist/core/runner/prepare-delegation-surface.js +2 -2
- package/dist/core/runner/prepare-gate-stations.d.ts +8 -0
- package/dist/core/runner/prepare-gate-stations.js +15 -7
- package/dist/core/runner/prepare-hands-readface.js +1 -1
- package/dist/core/runner/prepare-inherited-gate.d.ts +3 -1
- package/dist/core/runner/prepare-inherited-gate.js +4 -2
- package/dist/core/runner/prepare-memory-engine-session.js +1 -1
- package/dist/core/runner/prepare-memory.d.ts +4 -0
- package/dist/core/runner/prepare-memory.js +22 -28
- package/dist/core/runner/prepare-policy-chain.js +18 -10
- package/dist/core/runner/prepare-prompt-inputs.js +1 -1
- package/dist/core/runner/prepare-task.d.ts +5 -1
- package/dist/core/runner/prepare-task.js +16 -11
- package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -1
- package/dist/core/runner/prepare-wiring-manifest.js +3 -2
- package/dist/core/runner/resume-admission.d.ts +2 -2
- package/dist/core/runner/resume-admission.js +2 -23
- package/dist/core/runner/role-resolution-table.d.ts +98 -0
- package/dist/core/runner/role-resolution-table.js +62 -0
- package/dist/core/runner/run-compaction-machinery.js +2 -2
- package/dist/core/runner/run-identity-wiring.js +12 -9
- package/dist/core/runner/run-leg.js +8 -4
- package/dist/core/runner/run-notification-lane.js +23 -23
- package/dist/core/runner/run-recovery-lanes.js +3 -3
- package/dist/core/runner/run-terminal-adoption.js +1 -1
- package/dist/core/runner/run-turn-boundary.js +14 -15
- package/dist/core/runner/runtask.js +1 -1
- package/dist/core/runner/sub-agent-deny-lists.d.ts +19 -0
- package/dist/core/runner/sub-agent-deny-lists.js +25 -0
- package/dist/core/runner/tool-occurrence.d.ts +4 -2
- package/dist/core/runner/tool-occurrence.js +2 -2
- package/dist/core/runner-deps.d.ts +1 -1
- package/dist/core/secret-env.d.ts +2 -2
- package/dist/core/secret-env.js +6 -20
- package/dist/core/session-checkout.d.ts +63 -3
- package/dist/core/session-checkout.js +152 -58
- package/dist/core/session-store.d.ts +6 -6
- package/dist/core/session-store.js +3 -3
- package/dist/core/shell-read-silence.js +8 -0
- package/dist/core/store-contracts/background-agent-store-contract.js +13 -0
- package/dist/core/store-contracts/peer-directory-contract.js +8 -1
- package/dist/core/task-event.d.ts +9 -5
- package/dist/core/task-notification.d.ts +137 -31
- package/dist/core/task-notification.js +198 -100
- package/dist/core/task-registry-agent.d.ts +11 -0
- package/dist/core/task-registry-agent.js +12 -3
- package/dist/core/task-registry-shared.d.ts +11 -0
- package/dist/core/task-registry.d.ts +18 -0
- package/dist/core/task-registry.js +27 -8
- package/dist/core/task-spec.d.ts +7 -2
- package/dist/core/tool-errors.d.ts +17 -9
- package/dist/core/tool-errors.js +1 -1
- package/dist/core/tool-policy.d.ts +18 -1
- package/dist/core/tool-policy.js +16 -7
- package/dist/core/tool-result-store.d.ts +20 -0
- package/dist/core/tool-spec.d.ts +10 -6
- package/dist/core/trace.d.ts +3 -2
- package/dist/core/workflow-journal-store.d.ts +11 -0
- package/dist/core/workflow-journal-store.js +7 -0
- package/dist/core/workflow-run-store.d.ts +9 -0
- package/dist/core/workflow-run-store.js +6 -0
- package/dist/core/write-protect.d.ts +16 -0
- package/dist/core/write-protect.js +10 -0
- package/dist/engine/compaction/compaction.d.ts +2 -1
- package/dist/engine/harness/types.d.ts +1 -0
- package/dist/engine/session/repo-utils.d.ts +14 -4
- package/dist/engine/session/repo-utils.js +5 -4
- package/dist/engine/session/session.d.ts +7 -1
- package/dist/engine/session/session.js +5 -2
- package/dist/index.d.ts +13 -11
- package/dist/index.js +13 -11
- package/dist/orchestration/run-workflow-tool.d.ts +4 -0
- package/dist/orchestration/run-workflow-tool.js +7 -0
- package/dist/orchestration/workflow-types.d.ts +2 -1
- package/dist/orchestration/workflow.d.ts +3 -0
- package/dist/orchestration/workflow.js +2 -1
- package/dist/prompts/default.d.ts +1 -2
- package/dist/scenarios/full-body.d.ts +1 -1
- package/dist/stores/file/adoption/adopt.d.ts +1 -1
- package/dist/stores/file/checkpoint-store.d.ts +6 -0
- package/dist/stores/file/checkpoint-store.js +4 -1
- package/dist/stores/file/file-history-store.d.ts +13 -0
- package/dist/stores/file/file-history-store.js +75 -13
- package/dist/stores/file/index.d.ts +12 -16
- package/dist/stores/file/index.js +7 -25
- package/dist/stores/file/permission-rule-store.d.ts +34 -0
- package/dist/stores/file/permission-rule-store.js +104 -9
- package/dist/stores/file/session-store.js +1 -1
- package/dist/stores/file/tool-result-store.d.ts +14 -0
- package/dist/stores/file/tool-result-store.js +39 -2
- package/dist/stores/file/workflow-journal-store.d.ts +4 -0
- package/dist/stores/file/workflow-journal-store.js +17 -0
- package/dist/stores/file/workflow-run-store.d.ts +3 -0
- package/dist/stores/file/workflow-run-store.js +15 -0
- package/dist/tools/fs/read-deny.d.ts +15 -2
- package/dist/tools/fs/read-deny.js +10 -2
- package/dist/tools/fs/shell-read-check.d.ts +8 -2
- package/dist/tools/fs/shell-read-check.js +7 -7
- package/package.json +2 -2
- package/test/export-surface.snapshot.json +71 -73
- package/wire-changes/core-stores-sql@7.64.0.json +30 -0
- package/wire-changes/core-stores-sql@7.65.0.json +30 -0
- package/wire-changes/core@7.64.0.json +2653 -0
- package/wire-changes/core@7.65.0.json +1650 -0
- package/wire-changes/mods-kernel@7.64.0.json +30 -0
- package/wire-changes/mods-kernel@7.65.0.json +30 -0
- package/wire-changes/primitives@7.64.0.json +30 -0
- package/wire-changes/primitives@7.65.0.json +337 -0
- package/dist/core/memory-recall.d.ts +0 -208
- package/dist/core/memory-recall.js +0 -136
- package/dist/stores/file/memory-store.d.ts +0 -124
- package/dist/stores/file/memory-store.js +0 -353
|
@@ -5,6 +5,7 @@ import type { BoundaryLegsGiven } from "./cross-boundary-taint.js";
|
|
|
5
5
|
import type { WorkflowRunStore } from "./workflow-run-store.js";
|
|
6
6
|
import { type BackgroundAgentStore } from "./background-agent-store.js";
|
|
7
7
|
import type { TaskNotificationPayload } from "./task-notification.js";
|
|
8
|
+
import type { ExtensionRequester } from "./task-event.js";
|
|
8
9
|
import { type TaskArtifactSeat } from "./tool-result-store.js";
|
|
9
10
|
import { type SemaTaskType, type StopSource, type SemaTaskStatus, type TaskRetrievalStatus, type UnifiedTaskOutput, type UnifiedTaskResult, type SemaTaskHandle, type TaskAccess, type BackgroundAgentTaskHandle, type MonitorTimers, type RegisterMonitorInput, type RegisterWorkflowInput, canAccessWorkflowRun, clipTaskOutput, MONITOR_BATCH_WINDOW_MS, MONITOR_DEFAULT_TIMEOUT_MS, MONITOR_MAX_TIMEOUT_MS, MONITOR_MAX_BATCHES_PER_MINUTE } from "./task-registry-shared.js";
|
|
10
11
|
export { normalizeAgentName, DURABLE_AGENT_HEARTBEAT_MS, DURABLE_AGENT_HANDLE_RE, BG_AGENT_REAP_STOP_ERROR, engineAgentName, chosenAgentName } from "./task-registry-shared.js";
|
|
@@ -116,6 +117,10 @@ export interface TaskListRow {
|
|
|
116
117
|
* session store still holds the session" — the session store answers that. Only this process's
|
|
117
118
|
* handles are listed: a row known only to the durable store of another process is not here. */
|
|
118
119
|
sessionId?: string;
|
|
120
|
+
/** The extension that started a `background_agent` row, when one did — its registration name, from the extension's own
|
|
121
|
+
* `$.agent.spawn` (`ExtensionRequester`); ABSENT on every other row (the model's own spawn, the host's, and every row an earlier
|
|
122
|
+
* release registered): the one reading, with no word for either. A display and audit fact only. */
|
|
123
|
+
requestedBy?: ExtensionRequester;
|
|
119
124
|
createdAt: number;
|
|
120
125
|
updatedAt: number;
|
|
121
126
|
}
|
|
@@ -588,6 +593,19 @@ export declare class TaskRegistry {
|
|
|
588
593
|
sessionId: string;
|
|
589
594
|
scope: string;
|
|
590
595
|
})): BackgroundShellHardKillReceipt[];
|
|
596
|
+
/** How many shell-lane rows (`background_bash` + `monitor`) the exit-boundary hard face would take down if it ran now: the
|
|
597
|
+
* registry's `running` shell rows, over the WHOLE registry — no owner, session, scope or env narrowing — with a retained row
|
|
598
|
+
* counted only under `includeRetained: true` (no default, as on {@link killAllBackgroundShellsNow}). The rows are chosen
|
|
599
|
+
* by the hard face's own reading ({@link hardFaceVisitOf}), so the count and the walk cannot drift. SYNCHRONOUS and READ-ONLY:
|
|
600
|
+
* the count calls no seat and changes no row; like the hard face it reads each row's env declaration of retention (host-provided
|
|
601
|
+
* data), so a host whose env makes that read throw makes the count throw. It counts registry rows, not process truth: a row whose seat later answers `already_gone`
|
|
602
|
+
* or `no_pgid` stays `running` and is counted until its watcher settles it. A row an earlier stop settled `killed` or
|
|
603
|
+
* `failed` is visited by the hard face but is not running, so it is not counted; `completed` rows are not visited.
|
|
604
|
+
* Not {@link list}'s length: `list(access)` is the caller's own reach, capped at `limit`, every task type and status;
|
|
605
|
+
* {@link countRunningBackgroundForOwner} is one owner key's running tasks, agents included. */
|
|
606
|
+
countRunningBackgroundShells(opts: {
|
|
607
|
+
includeRetained: boolean;
|
|
608
|
+
}): number;
|
|
591
609
|
/** subscribe to `reapSessionBackground` (the design/129 session terminal anchor).
|
|
592
610
|
* Returns an unsubscribe. Hooks are best-effort observers; a throwing hook is swallowed. */
|
|
593
611
|
onSessionReap(hook: (sessionId: string, scope?: string) => void): () => void;
|
|
@@ -6,6 +6,7 @@ import { canAccessAgentRecord, } from "./background-agent-store.js";
|
|
|
6
6
|
import { delimitUntrusted } from "./untrusted-text.js";
|
|
7
7
|
import { createSafeNotifier } from "./safe-notify.js";
|
|
8
8
|
import { stripCwdSentinel } from "../tools/fs/fs-shared.js";
|
|
9
|
+
import { readExtensionRequester } from "./extension-requester.js";
|
|
9
10
|
import { persistTaskArtifact, taskArtifactOriginOf } from "./tool-result-store.js";
|
|
10
11
|
import { registerMonitorLane, pollMonitorLane, stopMonitorLane } from "./task-registry-monitor.js";
|
|
11
12
|
import { registerWorkflowLane, pollWorkflowLane, stopWorkflowLane } from "./task-registry-workflow.js";
|
|
@@ -20,6 +21,17 @@ export { canAccessWorkflowRun, clipTaskOutput, MONITOR_BATCH_WINDOW_MS, MONITOR_
|
|
|
20
21
|
function shellRowRetained(h) {
|
|
21
22
|
return retainsBackgroundProcesses({ marked: h.retained === true, env: envDeclaresRetain(h.env) });
|
|
22
23
|
}
|
|
24
|
+
function hardFaceVisitOf(handle, includeRetained, access) {
|
|
25
|
+
if (handle.type !== "background_bash" && handle.type !== "monitor")
|
|
26
|
+
return undefined;
|
|
27
|
+
if (access !== undefined && !canAccess(handle, access))
|
|
28
|
+
return undefined;
|
|
29
|
+
if (handle.status === "completed")
|
|
30
|
+
return undefined;
|
|
31
|
+
const retained = shellRowRetained(handle);
|
|
32
|
+
const skipped = retained && !includeRetained && handle.status !== "killed";
|
|
33
|
+
return { handle, retained, skipped, reaps: !skipped && handle.status === "running" };
|
|
34
|
+
}
|
|
23
35
|
const BLOCK_DEFAULT_TIMEOUT_MS = 30_000;
|
|
24
36
|
const BLOCK_MAX_TIMEOUT_MS = 600_000;
|
|
25
37
|
function blockDeadline(timeoutMs, now) {
|
|
@@ -607,16 +619,13 @@ export class TaskRegistry {
|
|
|
607
619
|
const sessionAccess = opts.sessionId !== undefined ? { owner: opts.sessionId, sessionId: opts.sessionId, scope: opts.scope } : undefined;
|
|
608
620
|
const receipts = [];
|
|
609
621
|
const settledOwners = new Set();
|
|
610
|
-
for (const
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
if (sessionAccess !== undefined && !canAccess(handle, sessionAccess))
|
|
614
|
-
continue;
|
|
615
|
-
if (handle.status === "completed")
|
|
622
|
+
for (const row of this.handles.values()) {
|
|
623
|
+
const visit = hardFaceVisitOf(row, opts.includeRetained, sessionAccess);
|
|
624
|
+
if (visit === undefined)
|
|
616
625
|
continue;
|
|
617
|
-
const retained =
|
|
626
|
+
const { handle, retained } = visit;
|
|
618
627
|
const base = { taskId: handle.id, type: handle.type, ...(handle.owner !== undefined ? { owner: handle.owner } : {}), ...(retained ? { retained: true } : {}) };
|
|
619
|
-
if (
|
|
628
|
+
if (visit.skipped) {
|
|
620
629
|
receipts.push({ ...base, outcome: "retained_skipped" });
|
|
621
630
|
continue;
|
|
622
631
|
}
|
|
@@ -665,6 +674,14 @@ export class TaskRegistry {
|
|
|
665
674
|
this.pokeBgQuiescence(owner);
|
|
666
675
|
return receipts;
|
|
667
676
|
}
|
|
677
|
+
countRunningBackgroundShells(opts) {
|
|
678
|
+
let n = 0;
|
|
679
|
+
for (const row of this.handles.values()) {
|
|
680
|
+
if (hardFaceVisitOf(row, opts.includeRetained)?.reaps === true)
|
|
681
|
+
n++;
|
|
682
|
+
}
|
|
683
|
+
return n;
|
|
684
|
+
}
|
|
668
685
|
onSessionReap(hook) {
|
|
669
686
|
this.sessionReapHooks.add(hook);
|
|
670
687
|
return () => void this.sessionReapHooks.delete(hook);
|
|
@@ -1045,11 +1062,13 @@ The durable record is still marked running (last update ${new Date(row.updatedAt
|
|
|
1045
1062
|
if (!canAccess(h, access))
|
|
1046
1063
|
continue;
|
|
1047
1064
|
const childSession = childSessionAnchorOf(h);
|
|
1065
|
+
const requestedBy = h.type === "background_agent" ? readExtensionRequester(h.requestedBy) : undefined;
|
|
1048
1066
|
out.push({
|
|
1049
1067
|
task_id: h.id,
|
|
1050
1068
|
type: h.type,
|
|
1051
1069
|
status: h.status,
|
|
1052
1070
|
sessionScoped: h.sessionScoped === true,
|
|
1071
|
+
...(requestedBy !== undefined ? { requestedBy } : {}),
|
|
1053
1072
|
...((h.type === "background_bash" || h.type === "monitor") && shellRowRetained(h) ? { retained: true } : {}),
|
|
1054
1073
|
...(h.description !== undefined ? { description: h.description } : {}),
|
|
1055
1074
|
...(h.toolUseId !== undefined ? { toolUseId: h.toolUseId } : {}),
|
package/dist/core/task-spec.d.ts
CHANGED
|
@@ -1348,7 +1348,7 @@ export interface TaskSpec {
|
|
|
1348
1348
|
* Override auto-compaction thresholds for this task's session. Compaction (LLM summary, persisted
|
|
1349
1349
|
* to the session) runs in two places sharing these settings: at every within-task turn boundary
|
|
1350
1350
|
* (design/64 §25 (A) — the long-single-task case) and once at task end (the between-task case).
|
|
1351
|
-
* Defaults:
|
|
1351
|
+
* Defaults: both seats on (`autoCompact` / `manualCompact` below), reserveTokens 16384, keepRecentTokens 0 (design/169-C; 20000 was the
|
|
1352
1352
|
* pre-169 default). A zero budget is NOT "no verbatim tail": the cut-point search has a
|
|
1353
1353
|
* structural floor under the budget, so the default already leaves the last exchange verbatim
|
|
1354
1354
|
* after the summary (a trailing tool-result batch keeps its emitting assistant with it) — the
|
|
@@ -1386,7 +1386,12 @@ export interface TaskSpec {
|
|
|
1386
1386
|
* no-op when the task has no execution env (no hands, nothing to re-read).
|
|
1387
1387
|
*/
|
|
1388
1388
|
compaction?: {
|
|
1389
|
-
|
|
1389
|
+
/** The passes the engine starts by itself (the lanes: {@link compactionEnabled}); `false` switches them off. Absent ⇒
|
|
1390
|
+
* `RunnerDeps.contextSettings[word].autoCompact`, else on. A non-boolean refuses the run (`config.invalid_argument`). */
|
|
1391
|
+
autoCompact?: boolean;
|
|
1392
|
+
/** The passes a caller asks for; `false` answers each `"disabled"`, no summary call. Absent ⇒ the deployment's
|
|
1393
|
+
* `manualCompact`, else on. The retired `enabled` (both at once) is refused by name (`config.spec_retired_key`). */
|
|
1394
|
+
manualCompact?: boolean;
|
|
1390
1395
|
withinTask?: boolean;
|
|
1391
1396
|
reserveTokens?: number;
|
|
1392
1397
|
keepRecentTokens?: number;
|
|
@@ -92,12 +92,20 @@ export declare function formatToolError(error: unknown): string;
|
|
|
92
92
|
* `unknown` would UNDO the very audit finding this folder exists to fix (these ARE real
|
|
93
93
|
* terminal codes, not foreign ones); (c) pre-existing precedent (`config.compliance_required`,
|
|
94
94
|
* NOT part of this diff) already folds a transient/retryable governance code into `config`.
|
|
95
|
-
* `
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
95
|
+
* The whole `env.` namespace is `config` BY PREFIX: a terminal code there is a refusal or a
|
|
96
|
+
* limit of the execution environment — `env.lifetime_expired`, or the code a deployment's
|
|
97
|
+
* `executionEnvFactory` throws when it refuses to mint (the engine carries a factory's code
|
|
98
|
+
* to the terminal verbatim; the module registers none of them, so a code a later deployment
|
|
99
|
+
* mints still reads `config`) — and what a caller does about every one of them is the same:
|
|
100
|
+
* change the environment or the configuration, then retry. The other `env.`-spelled strings
|
|
101
|
+
* of the codebase (a prompt-assembly block id, mod-kernel event names) are never a terminal
|
|
102
|
+
* code, and this folder's domain is the terminal code alone.
|
|
103
|
+
* `memory.admission_required`/`_denied` are EXACT codes, not a broad `memory.` prefix —
|
|
104
|
+
* falsification review (A-005.3 follow-up) caught an
|
|
105
|
+
* earlier draft folding EVERY `memory.*` code here, which misclassified the
|
|
106
|
+
* memory-engine's non-governance incident codes (`memory.announce_failed` et al.,
|
|
107
|
+
* explicitly listed as NON-governance in `NON_GOVERNANCE_MEMORY_CODES` — engine incidents,
|
|
108
|
+
* not task-spec rejections) as configuration failures. `usage.*` STAYS
|
|
101
109
|
* a broad prefix: governance-codes.ts's own `governanceRetryClass` already treats every
|
|
102
110
|
* `usage.*` code (registered or not) as governance by prefix — a deliberate legacy-family
|
|
103
111
|
* rule this folder mirrors rather than re-deciding (questioned whether that
|
|
@@ -119,9 +127,9 @@ export type WorkerErrorClass = "budget" | "limit" | "output" | "suspend" | "revi
|
|
|
119
127
|
*
|
|
120
128
|
* SCOPE: this folds a TERMINAL `TaskResult.errorCode` only — i.e. every OUR dotted prefix that the runner can
|
|
121
129
|
* assemble into a failed task outcome (`limits.`/`output.`/`suspend.`/`review.`/`unexpected.`/
|
|
122
|
-
* `oracle.`/`resume.`/`config.`/`usage.`) as a broad PREFIX, plus `memory.admission_required` /
|
|
123
|
-
* `memory.admission_denied` /
|
|
124
|
-
* sibling `memory.*`/`
|
|
130
|
+
* `oracle.`/`resume.`/`config.`/`usage.`/`env.`) as a broad PREFIX, plus `memory.admission_required` /
|
|
131
|
+
* `memory.admission_denied` / the two `model.*_exhausted` loop terminals as EXACT codes (their
|
|
132
|
+
* sibling `memory.*`/`model.*` strings are NOT all terminal-errorCode-shaped — see {@link EXACT_CODE_CLASS}'s
|
|
125
133
|
* comment), plus the flat 1.36 codes.
|
|
126
134
|
* The `limits.` namespace splits into the `budget` and `limit` classes by exact code — see
|
|
127
135
|
* {@link EXACT_CODE_CLASS}. Operation-level dotted codes that are surfaced to a *caller* and never become a
|
package/dist/core/tool-errors.js
CHANGED
|
@@ -88,7 +88,6 @@ const EXACT_CODE_CLASS = new Map([
|
|
|
88
88
|
["memory.admission_required", "config"],
|
|
89
89
|
["memory.admission_denied", "config"],
|
|
90
90
|
["memory.capture_optout_denied", "config"],
|
|
91
|
-
["env.lifetime_expired", "config"],
|
|
92
91
|
["model.malformed_tool_use_exhausted", "output"],
|
|
93
92
|
["model.truncated_output_exhausted", "output"],
|
|
94
93
|
]);
|
|
@@ -102,6 +101,7 @@ const DOTTED_PREFIX_CLASS = [
|
|
|
102
101
|
["resume.", "resume"],
|
|
103
102
|
["config.", "config"],
|
|
104
103
|
["usage.", "config"],
|
|
104
|
+
["env.", "config"],
|
|
105
105
|
];
|
|
106
106
|
export function errorClassOf(errorCode) {
|
|
107
107
|
if (!errorCode)
|
|
@@ -2027,13 +2027,17 @@ export type ResolverArmResult = (Extract<ResolvedAsk, {
|
|
|
2027
2027
|
}> & {
|
|
2028
2028
|
settlement?: Settlement;
|
|
2029
2029
|
bindingRefusal?: undefined;
|
|
2030
|
+
quotesQuestion?: undefined;
|
|
2030
2031
|
})
|
|
2031
|
-
/** `bindingRefusal`: the arm refused arguments no approval can be bound to — the record carries the sentence.
|
|
2032
|
+
/** `bindingRefusal`: the arm refused arguments no approval can be bound to — the record carries the sentence. `quotesQuestion`:
|
|
2033
|
+
* the arm's sentence quotes the ask's question (`req.message`) whole, so the resolution may carry the literals that question
|
|
2034
|
+
* quotes ({@link quotingQuestion}; read by {@link resolveAskFor} alone, never on the resolution). */
|
|
2032
2035
|
| (Extract<ResolvedAsk, {
|
|
2033
2036
|
action: "deny";
|
|
2034
2037
|
}> & {
|
|
2035
2038
|
settlement: Settlement;
|
|
2036
2039
|
bindingRefusal?: string;
|
|
2040
|
+
quotesQuestion?: true;
|
|
2037
2041
|
});
|
|
2038
2042
|
/**
|
|
2039
2043
|
* The DIRECTIONAL format controls, as a closed set (see {@link AskRequest.hasBidiControls}):
|
|
@@ -2111,3 +2115,16 @@ onLateSettlement?: (late: {
|
|
|
2111
2115
|
kind: "error";
|
|
2112
2116
|
error: unknown;
|
|
2113
2117
|
}) => void): Promise<ResolvedAsk>;
|
|
2118
|
+
/**
|
|
2119
|
+
* {@link resolveAsk} at an engine mint station, which also hands over the decision it ASKED (`asked`): when the arm that ran
|
|
2120
|
+
* quotes the question ({@link quotingQuestion}) and the question the request puts to the approver IS the sentence the engine
|
|
2121
|
+
* composed for `asked` ({@link engineSentenceOf}, byte for byte — a card that appended to it, or a layer that rewrote it, puts
|
|
2122
|
+
* another sentence there), the refusal's record carries the literals that sentence quotes. The list's only source is the record
|
|
2123
|
+
* of the station that composed the question; the request carries none. Not re-exported from `src/index.ts`.
|
|
2124
|
+
*/
|
|
2125
|
+
export declare function resolveAskFor(req: AskRequest, onAsk: OnAsk | undefined, signal: AbortSignal | undefined, onLateSettlement: ((late: {
|
|
2126
|
+
kind: "approve";
|
|
2127
|
+
} | {
|
|
2128
|
+
kind: "error";
|
|
2129
|
+
error: unknown;
|
|
2130
|
+
}) => void) | undefined, asked: object | undefined): Promise<ResolvedAsk>;
|
package/dist/core/tool-policy.js
CHANGED
|
@@ -4,7 +4,7 @@ import { argsReadFrom, carryArgsReadFrom, withArgsReading } from "./effective-pa
|
|
|
4
4
|
import { editRewrittenSentence, readRejudge, rewriteChasedSentence } from "./rewrite-rejudge.js";
|
|
5
5
|
import { brandPolicyAskClass } from "./ask-class.js";
|
|
6
6
|
import { decisionAskClassesOf, headlessDenialMessage, joinAskReasons } from "./ask-origin.js";
|
|
7
|
-
import { attest, attestationOf, isEngineAttestation, mergeAttestation, mintAttestation, withAttestation } from "./engine-attestation.js";
|
|
7
|
+
import { attest, attestationOf, engineSentenceOf, isEngineAttestation, mergeAttestation, mintAttestation, withAttestation } from "./engine-attestation.js";
|
|
8
8
|
import { ownReadRootCandidate, readRootGrantSeat } from "./read-root-grant-screen.js";
|
|
9
9
|
import { DECIDED_VIA, decidersNote, isDecidedVia, policyDeciderOf, settledByDecider } from "./gate-outcome.js";
|
|
10
10
|
import { unjudgedAllowRefused } from "./real-approval.js";
|
|
@@ -1057,6 +1057,7 @@ export function policyRefusalMessage(toolName, askMessage, note, decidedVia) {
|
|
|
1057
1057
|
`was blocked and why you needed it, then continue with the parts of the task that do not require approval.`;
|
|
1058
1058
|
return note === undefined ? body : `${body}\nPolicy note:\n${delimitUntrusted("policy note", note, REVIEWER_NOTE_MAX_BODY)}`;
|
|
1059
1059
|
}
|
|
1060
|
+
const quotingQuestion = Object.freeze({ quotesQuestion: true });
|
|
1060
1061
|
export const BIDI_CONTROL_CHARS = "\\u061C\\u200E\\u200F\\u202A-\\u202E\\u2066-\\u2069";
|
|
1061
1062
|
const BIDI_CONTROL_RE = new RegExp(`[${BIDI_CONTROL_CHARS}]`, "u");
|
|
1062
1063
|
const BIDI_SCAN_MAX_NODES = 5_000;
|
|
@@ -1131,12 +1132,17 @@ export function carriesBidiControls(value, limits) {
|
|
|
1131
1132
|
}
|
|
1132
1133
|
}
|
|
1133
1134
|
export async function resolveAsk(req, onAsk, signal, onLateSettlement) {
|
|
1135
|
+
return resolveAskFor(req, onAsk, signal, onLateSettlement, undefined);
|
|
1136
|
+
}
|
|
1137
|
+
export async function resolveAskFor(req, onAsk, signal, onLateSettlement, asked) {
|
|
1134
1138
|
const askedDigest = exactBoundInputHashOf(req.toolName, req.args);
|
|
1135
|
-
const
|
|
1139
|
+
const question = asked !== undefined ? engineSentenceOf(asked, req) : undefined;
|
|
1140
|
+
const { settlement, bindingRefusal, quotesQuestion, ...r } = await resolveAskArms(req, onAsk, signal, onLateSettlement);
|
|
1136
1141
|
if (settlement === undefined)
|
|
1137
1142
|
return r;
|
|
1143
|
+
const echoed = quotesQuestion === true && question?.echoed !== undefined && req.message === question.text && r.message !== undefined ? question.echoed : undefined;
|
|
1138
1144
|
const licensedDigest = r.action === "allow" && r.updatedInput !== undefined ? exactBoundInputHashOf(req.toolName, r.updatedInput) : r.presentedInput !== undefined ? exactBoundInputHashOf(req.toolName, r.presentedInput) : askedDigest;
|
|
1139
|
-
return attest(r, req, { settlement, ...(req.origin !== undefined ? { origin: req.origin } : {}), ...(req.classes !== undefined ? { classes: req.classes } : {}), ...(licensedDigest !== undefined ? { inputDigest: licensedDigest } : {}), ...(bindingRefusal !== undefined ? { bindingRefusal } : {}) });
|
|
1145
|
+
return attest(r, req, { settlement, ...(req.origin !== undefined ? { origin: req.origin } : {}), ...(req.classes !== undefined ? { classes: req.classes } : {}), ...(licensedDigest !== undefined ? { inputDigest: licensedDigest } : {}), ...(bindingRefusal !== undefined ? { bindingRefusal } : {}), ...(echoed !== undefined ? { sentence: { text: r.message, echoed } } : {}) });
|
|
1140
1146
|
}
|
|
1141
1147
|
function raceAskWaitAgainstSignal(wait, signal) {
|
|
1142
1148
|
const settledWait = wait.then((value) => ({ tag: "value", value }), (error) => ({ tag: "threw", error }));
|
|
@@ -1267,7 +1273,7 @@ function readApproverOutcomeObject(ok, toolName, editLane) {
|
|
|
1267
1273
|
async function resolveAskArms(req, onAsk, signal, onLateSettlement) {
|
|
1268
1274
|
if (onAsk === "allow") {
|
|
1269
1275
|
if (req.requiresRealApproval === true)
|
|
1270
|
-
return unjudgedAllowRefused(req, "blanket");
|
|
1276
|
+
return { ...unjudgedAllowRefused(req, "blanket"), ...quotingQuestion };
|
|
1271
1277
|
return { action: "allow", decisionReason: "mode" };
|
|
1272
1278
|
}
|
|
1273
1279
|
if (onAsk === undefined || onAsk === "deny") {
|
|
@@ -1277,7 +1283,7 @@ async function resolveAskArms(req, onAsk, signal, onLateSettlement) {
|
|
|
1277
1283
|
message: bound.ok ? headlessDenialMessage(req.toolName, req.message) : bound.refusal,
|
|
1278
1284
|
decisionReason: "mode",
|
|
1279
1285
|
settlement: settledByNobody("no_approver"),
|
|
1280
|
-
...(bound.ok ?
|
|
1286
|
+
...(bound.ok ? quotingQuestion : { bindingRefusal: bound.refusal }),
|
|
1281
1287
|
};
|
|
1282
1288
|
}
|
|
1283
1289
|
if (signal?.aborted) {
|
|
@@ -1310,6 +1316,7 @@ async function resolveAskArms(req, onAsk, signal, onLateSettlement) {
|
|
|
1310
1316
|
`elapsed with no answer; auto-denied: ${req.message}`,
|
|
1311
1317
|
decisionReason: "mode",
|
|
1312
1318
|
settlement: { kind: "denial_limit_window_expired", who: { party: "engine", window: "denial_limit" }, when: Date.now() },
|
|
1319
|
+
...quotingQuestion,
|
|
1313
1320
|
};
|
|
1314
1321
|
}
|
|
1315
1322
|
if (raced.tag === "aborted") {
|
|
@@ -1339,6 +1346,7 @@ async function resolveAskArms(req, onAsk, signal, onLateSettlement) {
|
|
|
1339
1346
|
decisionReason: "mode",
|
|
1340
1347
|
settlement: settledByNobody("approver_unavailable"),
|
|
1341
1348
|
approverUnavailable: true,
|
|
1349
|
+
...quotingQuestion,
|
|
1342
1350
|
};
|
|
1343
1351
|
}
|
|
1344
1352
|
if (typeof ok === "object" && ok !== null) {
|
|
@@ -1346,7 +1354,7 @@ async function resolveAskArms(req, onAsk, signal, onLateSettlement) {
|
|
|
1346
1354
|
if (reading.kind === "refused")
|
|
1347
1355
|
return { action: "deny", message: reading.message, decisionReason: "mode", settlement: reading.settlement, ...(reading.binding === true ? { bindingRefusal: reading.message } : {}) };
|
|
1348
1356
|
if (reading.kind === "allow" && reading.settlement.who.party === "policy" && req.requiresRealApproval === true) {
|
|
1349
|
-
return { ...unjudgedAllowRefused(req, "policy"), ...readRootGrantSeat(reading.grant, offered, false) };
|
|
1357
|
+
return { ...unjudgedAllowRefused(req, "policy"), ...quotingQuestion, ...readRootGrantSeat(reading.grant, offered, false) };
|
|
1350
1358
|
}
|
|
1351
1359
|
const grantSeat = readRootGrantSeat(reading.grant, offered, reading.kind === "allow");
|
|
1352
1360
|
if (reading.kind === "deny") {
|
|
@@ -1359,6 +1367,7 @@ async function resolveAskArms(req, onAsk, signal, onLateSettlement) {
|
|
|
1359
1367
|
: humanRefusalMessage(req, reading.note),
|
|
1360
1368
|
decisionReason: "mode",
|
|
1361
1369
|
settlement: reading.settlement,
|
|
1370
|
+
...quotingQuestion,
|
|
1362
1371
|
...grantSeat,
|
|
1363
1372
|
};
|
|
1364
1373
|
}
|
|
@@ -1377,5 +1386,5 @@ async function resolveAskArms(req, onAsk, signal, onLateSettlement) {
|
|
|
1377
1386
|
settlement: settledByNobody("approver_contract"),
|
|
1378
1387
|
};
|
|
1379
1388
|
}
|
|
1380
|
-
return { action: "deny", message: humanRefusalMessage(req), decisionReason: "mode", settlement: settledByDecider("person", "refused", undefined) };
|
|
1389
|
+
return { action: "deny", message: humanRefusalMessage(req), decisionReason: "mode", settlement: settledByDecider("person", "refused", undefined), ...quotingQuestion };
|
|
1381
1390
|
}
|
|
@@ -141,6 +141,26 @@ export interface ToolResultStore {
|
|
|
141
141
|
reap?(now: number, opts?: {
|
|
142
142
|
maxAgeMs?: number;
|
|
143
143
|
}): Promise<number> | number;
|
|
144
|
+
/**
|
|
145
|
+
* Delete the entries stored with NO owner record that were stored before `cutoffMs` (epoch ms) — the orphan-tool-results domain's
|
|
146
|
+
* leg ({@link import("./retention.js").RETENTION_CASCADE}). No session can claim such an entry (written without provenance, or a
|
|
147
|
+
* winning write interrupted between its content and its owner record), so no session deletion ever reaches it; the cutoff is the
|
|
148
|
+
* one bound it has. Answers how many entries it removed.
|
|
149
|
+
*
|
|
150
|
+
* Rules every implementation follows:
|
|
151
|
+
* - **an owned entry is never this verb's**, however old — its session's deletion is its way out;
|
|
152
|
+
* - **an owner record that is present but unreadable is not "no owner"**: that entry is kept, because a guess would destroy
|
|
153
|
+
* another session's output (the same posture {@link deleteBySession} counts as `unattributable`);
|
|
154
|
+
* - **the bound is the call's**: a `cutoffMs` that is not a finite number is refused (`config.retention_policy_invalid`)
|
|
155
|
+
* before any entry is touched; no policy object is read;
|
|
156
|
+
* - whether a transcript still points at an unowned entry is the caller's to judge (it holds the transcripts); this verb
|
|
157
|
+
* judges the store's own two facts, the owner record and the write time;
|
|
158
|
+
* - **idempotent**, and an entry that disappears between enumeration and removal is honest absence.
|
|
159
|
+
*
|
|
160
|
+
* Optional: absent ⇒ unowned entries leave only through {@link reap}'s age bound, which does not consult ownership. A store
|
|
161
|
+
* that records no write time cannot age an entry and does not implement it (the in-memory store keeps none).
|
|
162
|
+
*/
|
|
163
|
+
deleteUnattributable?(cutoffMs: number): Promise<number> | number;
|
|
144
164
|
/**
|
|
145
165
|
* The READ half of the same ownership coordinate {@link deleteBySession} erases by: every entry this store recorded as belonging to
|
|
146
166
|
* `sessionId`, as the ref and the owner recorded at its winning write. Without it the offloaded results a session's transcript
|
package/dist/core/tool-spec.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ import type { TaskSpec } from "./task-spec.js";
|
|
|
16
16
|
import type { BackgroundChildEvent } from "./delegation-frames.js";
|
|
17
17
|
import type { ModelRef } from "./model-seat.js";
|
|
18
18
|
import type { ToolFamily, ToolHostTarget, ToolPathTarget, ToolRenderHints, ToolRuleFace } from "./tool-face.js";
|
|
19
|
-
import type {
|
|
19
|
+
import type { MemoryGovernanceStore } from "./memory-engine/types.js";
|
|
20
20
|
/**
|
|
21
21
|
* Side-effect class of a tool. Used by wake/resume reconciliation: when a call was interrupted
|
|
22
22
|
* before its result was recorded, the outcome is unknown, so core must decide whether re-doing it
|
|
@@ -673,12 +673,11 @@ export interface NestedUsageAccum {
|
|
|
673
673
|
* carry knownness alongside the number it qualifies. */
|
|
674
674
|
anyUnpriced: boolean;
|
|
675
675
|
}
|
|
676
|
-
/** {@link ToolExecuteContext.delegationSettlement}'s answer:
|
|
677
|
-
*
|
|
678
|
-
*
|
|
676
|
+
/** {@link ToolExecuteContext.delegationSettlement}'s answer: the WRITE plane's governance store — where a delegation's
|
|
677
|
+
* settlement rows are kept and where the effects a settled delegation reaches land (the session's pollution marker) —
|
|
678
|
+
* and the session whose rows they are. */
|
|
679
679
|
export interface DelegationSettlementSeat {
|
|
680
|
-
readonly governance:
|
|
681
|
-
readonly controlDir: string;
|
|
680
|
+
readonly governance: MemoryGovernanceStore;
|
|
682
681
|
readonly sessionId: string;
|
|
683
682
|
}
|
|
684
683
|
export interface ToolExecuteContext {
|
|
@@ -709,6 +708,11 @@ export interface ToolExecuteContext {
|
|
|
709
708
|
* fixed point `ctx.rootSessionId ?? ctx.sessionId` at every spawn). Absent for a top-level run
|
|
710
709
|
* (its OWN sessionId is the root). */
|
|
711
710
|
rootSessionId?: string;
|
|
711
|
+
/** The occupant (`SessionMetadata.incarnation`) of the session the fixed point above names (`rootSessionId ?? sessionId`)
|
|
712
|
+
* as this tree holds it — Runner-filled, trusted. A spawn hands it down beside the root anchor
|
|
713
|
+
* (`RunInternals.rootSessionIncarnation`) and a background spawn persists it on its row, where a revival reads it back;
|
|
714
|
+
* absent = unknown (a row minted before occupants, a revival of a row that recorded none). */
|
|
715
|
+
rootSessionIncarnation?: string;
|
|
712
716
|
/** The run's delegation tree owner seat (`RunInternals.delegationOwner`, Runner-filled): a delegation tool reads the tree's owner
|
|
713
717
|
* through it for the rows it creates for a child (a placed transcript, a fork, a park's durable row) and threads it into a spawned
|
|
714
718
|
* child's internals by reference — never into a revival's. */
|
package/dist/core/trace.d.ts
CHANGED
|
@@ -762,8 +762,9 @@ export type TraceEvent = {
|
|
|
762
762
|
taskId: string;
|
|
763
763
|
ts: number;
|
|
764
764
|
} | {
|
|
765
|
-
/** MF-18 修① — a manual /compact was processed while compaction is
|
|
766
|
-
*
|
|
765
|
+
/** MF-18 修① — a manual /compact was processed while requested compaction is switched OFF
|
|
766
|
+
* (the `manualCompact` seat is `false`, the task's or the deployment's): the request is answered
|
|
767
|
+
* without a pass; the `autoCompact` seat does not reach it. */
|
|
767
768
|
kind: "compaction.disabled";
|
|
768
769
|
version: 1;
|
|
769
770
|
taskId: string;
|
|
@@ -137,6 +137,16 @@ export interface WorkflowJournalStore {
|
|
|
137
137
|
* returns its API route (cloud form). `undefined`/absent ⇒ the completion notification's diagnostics
|
|
138
138
|
* line names no journal (the record behind its ref still carries every agent's row). Engine-facing string, never parsed. */
|
|
139
139
|
locator?(runId: string, scope: string): string | undefined;
|
|
140
|
+
/**
|
|
141
|
+
* Erase `runId`'s journal IF its recorded scope === `scope` (the {@link load} wall: a cross-scope call erases nothing) — the
|
|
142
|
+
* session-tree cascade's leg for a terminal run its session started ({@link import("./retention.js").RETENTION_CASCADE}).
|
|
143
|
+
* `true` = this call removed it; `false` = there was none under that scope. Idempotent; a store fault throws (a deletion
|
|
144
|
+
* face that cannot delete is loud). A later `load` of the id answers empty; the cascade deletes the run's record with it, and a
|
|
145
|
+
* resume from a run whose record is gone is refused before the load (`workflow.park_truth_unreadable`, `record_missing`). A resume
|
|
146
|
+
* claim naming the id holds ids only and is not this verb's (the claim's own release and sweep govern it). OPTIONAL: absent ⇒ this store's journals outlive their runs,
|
|
147
|
+
* and the deployment owns that gap.
|
|
148
|
+
*/
|
|
149
|
+
deleteRun?(runId: string, scope: string): Promise<boolean>;
|
|
140
150
|
/**
|
|
141
151
|
* ADMISSION for a resume, so two concurrent
|
|
142
152
|
* `resumeFromRunId` legs off ONE source run cannot fork its execution.
|
|
@@ -308,6 +318,7 @@ export declare class InMemoryWorkflowJournalStore implements WorkflowJournalStor
|
|
|
308
318
|
/** Release ONLY a claim `newRunId` still holds (a missing/foreign/already-taken-over claim is a
|
|
309
319
|
* no-op, never an error — matches the file store's contract). */
|
|
310
320
|
releaseResumeClaim(input: ResumeClaimArgs): Promise<void>;
|
|
321
|
+
deleteRun(runId: string, scope: string): Promise<boolean>;
|
|
311
322
|
load(runId: string, scope: string): Promise<WorkflowJournalEntry[]>;
|
|
312
323
|
append(runId: string, scope: string, entry: WorkflowJournalEntry): Promise<void>;
|
|
313
324
|
}
|
|
@@ -144,6 +144,13 @@ export class InMemoryWorkflowJournalStore {
|
|
|
144
144
|
if (existing !== undefined && existing.holder === input.newRunId)
|
|
145
145
|
table.delete(input.sourceRunId);
|
|
146
146
|
}
|
|
147
|
+
async deleteRun(runId, scope) {
|
|
148
|
+
const rec = this.runs.get(runId);
|
|
149
|
+
if (!rec || rec.scope !== scope)
|
|
150
|
+
return false;
|
|
151
|
+
this.runs.delete(runId);
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
147
154
|
async load(runId, scope) {
|
|
148
155
|
const rec = this.runs.get(runId);
|
|
149
156
|
if (!rec || rec.scope !== scope)
|
|
@@ -197,6 +197,14 @@ export interface WorkflowRunStore {
|
|
|
197
197
|
maxAgeMs?: number;
|
|
198
198
|
keep?: number;
|
|
199
199
|
}): Promise<number>;
|
|
200
|
+
/**
|
|
201
|
+
* Delete the TERMINAL runs in `scope` whose `originatingSessionId` is `sessionId` (strict equality, the
|
|
202
|
+
* {@link listByScope} `session` filter's) — the session-tree cascade's leg ({@link import("./retention.js").RETENTION_CASCADE}).
|
|
203
|
+
* A running run is never deleted (it is a live reference: the cascade does not delete its session's tree). Answers the ids it
|
|
204
|
+
* deleted; idempotent (a repeat answers `[]`); a store fault throws. OPTIONAL: absent ⇒ this store's runs outlive the session
|
|
205
|
+
* that started them, and the deployment owns that gap.
|
|
206
|
+
*/
|
|
207
|
+
deleteBySession?(sessionId: string, scope: string): Promise<string[]>;
|
|
200
208
|
}
|
|
201
209
|
/**
|
|
202
210
|
* REF-A5 — THE optimistic-concurrency guard for {@link WorkflowRunStore.update}, shared by every backend:
|
|
@@ -236,6 +244,7 @@ export declare class InMemoryWorkflowRunStore implements WorkflowRunStore {
|
|
|
236
244
|
maxAgeMs?: number;
|
|
237
245
|
keep?: number;
|
|
238
246
|
}): Promise<number>;
|
|
247
|
+
deleteBySession(sessionId: string, scope: string): Promise<string[]>;
|
|
239
248
|
/** Test/inspection helper: number of stored runs. */
|
|
240
249
|
get size(): number;
|
|
241
250
|
}
|
|
@@ -97,6 +97,12 @@ export class InMemoryWorkflowRunStore {
|
|
|
97
97
|
this.runs.delete(id);
|
|
98
98
|
return doomed.size;
|
|
99
99
|
}
|
|
100
|
+
async deleteBySession(sessionId, scope) {
|
|
101
|
+
const doomed = [...this.runs.values()].filter((r) => r.scope === scope && r.originatingSessionId === sessionId && isTerminalWorkflowStatus(r.status)).map((r) => r.id);
|
|
102
|
+
for (const id of doomed)
|
|
103
|
+
this.runs.delete(id);
|
|
104
|
+
return doomed;
|
|
105
|
+
}
|
|
100
106
|
get size() {
|
|
101
107
|
return this.runs.size;
|
|
102
108
|
}
|
|
@@ -295,6 +295,22 @@ export declare function compileLegWriteJudgment(entries: readonly WriteProtected
|
|
|
295
295
|
* · `clear` ⇒ `undefined`: the surviving decision stands.
|
|
296
296
|
*/
|
|
297
297
|
export declare function writeProtectionTightenDecision(toolName: string, verdict: WriteProtectionVerdict): PermissionResult | undefined;
|
|
298
|
+
/**
|
|
299
|
+
* The question a surviving ASK is said with when the table also meets its target: the standing ask — its action, provenance
|
|
300
|
+
* and disclosures — with {@link writeProtectionTightenDecision}'s own sentence after its message in parentheses (the form the
|
|
301
|
+
* persisted-rule tightening appends its account in), once; a standing ask without a message takes the sentence alone. One
|
|
302
|
+
* sentence is minted (beside the verdict); this only places it. A standing ask whose message IS the engine's own sentence
|
|
303
|
+
* (`engineSentenceOf`) keeps the account of it over the result: both halves are the engine's words, the literals the account
|
|
304
|
+
* lists are still quoted by the longer text, and this station composed the longer text — the account's only writer — so it
|
|
305
|
+
* restates the account for it (`generic` and `echoed` ride along, `text` is the result's message). Any other standing ask
|
|
306
|
+
* (a hook's, a deployment's) keeps its words and no account.
|
|
307
|
+
*/
|
|
308
|
+
export declare function askWithTableSentence<T extends {
|
|
309
|
+
readonly message?: string;
|
|
310
|
+
}>(standing: T, tightenSentence: string, call: {
|
|
311
|
+
toolCallId: string;
|
|
312
|
+
toolName: string;
|
|
313
|
+
}): T;
|
|
298
314
|
/**
|
|
299
315
|
* @contract write_protection.verdict_is_the_mandate — a MATCHED row is the one fact of the judge's verdict a standing
|
|
300
316
|
* allow rule may not retire (a live decider may still clear it), and `clear` is not it; this predicate is the one reading
|
|
@@ -7,6 +7,7 @@ import { chainHopsOrNone, symlinkChainHops } from "./path-identity.js";
|
|
|
7
7
|
import { readDenyPatternRun } from "../tools/fs/read-deny.js";
|
|
8
8
|
import { agentConfigDirSegments, agentConfigDirTail } from "./agent-config-dir.js";
|
|
9
9
|
import { thrownText } from "./thrown-value.js";
|
|
10
|
+
import { attest, engineSentenceOf } from "./engine-attestation.js";
|
|
10
11
|
import { fromSource, gateWaitFailureOf } from "./gate-bounded-await.js";
|
|
11
12
|
const freezeTable = (rows) => Object.freeze(rows.map((r) => Object.freeze(r)));
|
|
12
13
|
export const WRITE_PROTECTED_DEFAULT_TABLE = freezeTable([
|
|
@@ -463,6 +464,15 @@ export function writeProtectionTightenDecision(toolName, verdict) {
|
|
|
463
464
|
decisionReason: "safety",
|
|
464
465
|
};
|
|
465
466
|
}
|
|
467
|
+
export function askWithTableSentence(standing, tightenSentence, call) {
|
|
468
|
+
if (standing.message === undefined)
|
|
469
|
+
return { ...standing, message: tightenSentence };
|
|
470
|
+
if (standing.message.includes(tightenSentence))
|
|
471
|
+
return standing;
|
|
472
|
+
const merged = { ...standing, message: `${standing.message} (${tightenSentence})` };
|
|
473
|
+
const account = engineSentenceOf(standing, call);
|
|
474
|
+
return account === undefined ? merged : attest(merged, call, { sentence: { ...account, text: merged.message } });
|
|
475
|
+
}
|
|
466
476
|
export function writeProtectionMandated(verdict) {
|
|
467
477
|
return verdict.kind === "hit";
|
|
468
478
|
}
|
|
@@ -90,7 +90,8 @@ export interface CompactionResult<T = unknown> {
|
|
|
90
90
|
}
|
|
91
91
|
/** Compaction thresholds and retention settings. */
|
|
92
92
|
export interface CompactionSettings {
|
|
93
|
-
/**
|
|
93
|
+
/** This pass's own gate (`false` ⇒ the pass is disabled). A run resolves it for each pass from the seat of that pass —
|
|
94
|
+
* `TaskSpec.compaction.autoCompact` for the passes the engine starts, `manualCompact` for a requested one. */
|
|
94
95
|
enabled: boolean;
|
|
95
96
|
/** Tokens reserved below the context window for the TRIGGER threshold (threshold = window −
|
|
96
97
|
* reserve). Historically this single knob ALSO seeded the summary legs' output budget
|
|
@@ -1621,6 +1621,7 @@ export interface CompactResult {
|
|
|
1621
1621
|
}
|
|
1622
1622
|
/** Settings that control automatic context compaction. */
|
|
1623
1623
|
export interface CompactionSettings {
|
|
1624
|
+
/** This pass's own gate (`false` ⇒ the pass is disabled); a run resolves it per pass from the seat of that pass. */
|
|
1624
1625
|
enabled: boolean;
|
|
1625
1626
|
reserveTokens: number;
|
|
1626
1627
|
keepRecentTokens: number;
|
|
@@ -11,9 +11,19 @@ export declare function incarnationCell(existing: Pick<SessionMetadata, "incarna
|
|
|
11
11
|
* is told once with the cell's shape (never its value). The cell never makes this throw; a throw from `disclose` propagates. */
|
|
12
12
|
export declare function readIncarnationCell(raw: unknown, disclose: (detail: string) => void): string | undefined;
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* THE reading of "do two readings of one session id's occupant cell (`SessionMetadata.incarnation`) name one occupant": each side is
|
|
15
|
+
* decoded as {@link readIncarnationCell} decodes a stored cell — a non-empty string is the token, anything else (absent, `""`, a
|
|
16
|
+
* non-string) is no token — and the two are one occupant when they hold the same token, or no token on either side (a row written before
|
|
17
|
+
* occupants were minted, taken as it reads: every write that creates a row mints a token, so a row created again under the id never reads
|
|
18
|
+
* as the one before it). A token on one side only is another occupant. Every occupant question in the engine asks this one predicate:
|
|
19
|
+
* a run's own seats (the tree owner, the session address a frame or a notice is delivered to, a box record's addressee) directly, and a
|
|
20
|
+
* comparison of two heads through {@link compareOccupants}.
|
|
21
|
+
*/
|
|
22
|
+
export declare function sameOccupant(held: string | undefined, current: string | undefined): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Whether two heads of one session id name the same occupant (each side a {@link SessionHead}, or a row's {@link SessionMetadata}):
|
|
25
|
+
* `"unknown"` when either side has no row, otherwise {@link sameOccupant} of their occupant cells — `"same"` or `"different"`. Unknown
|
|
26
|
+
* is never `"same"`, so a caller that may only proceed on the same occupant refuses on it.
|
|
17
27
|
*/
|
|
18
28
|
export declare function compareOccupants(before: {
|
|
19
29
|
readonly incarnation?: SessionHead["incarnation"];
|
|
@@ -26,7 +36,7 @@ export declare function compareOccupants(before: {
|
|
|
26
36
|
* log binds: no expectation ⇒ no precondition; `row: null` ⇒ the row must be absent; otherwise the row must be there with the same owner
|
|
27
37
|
* and the same occupant cell and — when `log` is given — a log of the same mark ({@link sessionLogMarkOf}). The occupant cell is compared
|
|
28
38
|
* as written, an absent token equal to an absent one: this asks whether any write changed the row since the read the expectation came
|
|
29
|
-
* from, not whether two parties name one occupant ({@link
|
|
39
|
+
* from, not whether two parties name one occupant ({@link sameOccupant}, where an empty or non-string cell names nobody) — and since every write
|
|
30
40
|
* that creates a row mints a token, a row without one cannot be created again, so an absent cell is one generation. An expectation that
|
|
31
41
|
* is not of this shape is refused (a `TypeError` naming the member), never read as no precondition.
|
|
32
42
|
*/
|
|
@@ -26,12 +26,13 @@ function isOccupantToken(raw) {
|
|
|
26
26
|
function nonStringShape(raw) {
|
|
27
27
|
return Array.isArray(raw) ? "a non-string value (array)" : `a non-string value (${typeof raw})`;
|
|
28
28
|
}
|
|
29
|
+
export function sameOccupant(held, current) {
|
|
30
|
+
return (isOccupantToken(held) ? held : undefined) === (isOccupantToken(current) ? current : undefined);
|
|
31
|
+
}
|
|
29
32
|
export function compareOccupants(before, after) {
|
|
30
|
-
|
|
31
|
-
const b = after?.incarnation;
|
|
32
|
-
if (!isOccupantToken(a) || !isOccupantToken(b))
|
|
33
|
+
if (before === undefined || after === undefined)
|
|
33
34
|
return "unknown";
|
|
34
|
-
return
|
|
35
|
+
return sameOccupant(before.incarnation, after.incarnation) ? "same" : "different";
|
|
35
36
|
}
|
|
36
37
|
export function sessionRowMatches(expect, row, logNow) {
|
|
37
38
|
if (expect === undefined)
|