@sema-agent/core 7.61.0 → 7.63.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +840 -0
- package/dist/agents/cascade.d.ts +11 -3
- package/dist/agents/cascade.js +1 -1
- package/dist/agents/peer-held-queue.d.ts +27 -4
- package/dist/agents/peer-held-queue.js +81 -36
- package/dist/agents/peer-session-drain.js +13 -3
- package/dist/agents/subagent-transcript-placement.d.ts +23 -0
- package/dist/agents/subagent-transcript-placement.js +14 -0
- package/dist/agents/subagent.d.ts +6 -1
- package/dist/agents/subagent.js +143 -58
- package/dist/agents/suspend-guard.d.ts +38 -16
- package/dist/agents/suspend-guard.js +9 -4
- package/dist/agents/verify.js +4 -3
- package/dist/brain/route-adjudicator.js +9 -4
- package/dist/core/approval-object.js +1 -1
- package/dist/core/arg-summary.js +1 -1
- package/dist/core/ask-question.d.ts +2 -2
- package/dist/core/canonical-json.d.ts +23 -13
- package/dist/core/canonical-json.js +4 -4
- package/dist/core/checkpoint-features.d.ts +722 -0
- package/dist/core/checkpoint-features.js +98 -0
- package/dist/core/checkpoint-queries.d.ts +47 -4
- package/dist/core/checkpoint-queries.js +36 -16
- package/dist/core/checkpoint-requirements.d.ts +12 -5
- package/dist/core/checkpoint-requirements.js +11 -5
- package/dist/core/checkpoint-row-verdict.d.ts +110 -0
- package/dist/core/checkpoint-row-verdict.js +245 -0
- package/dist/core/checkpoint-store.d.ts +76 -753
- package/dist/core/checkpoint-store.js +83 -144
- package/dist/core/compliance.d.ts +6 -2
- package/dist/core/compliance.js +3 -3
- package/dist/core/engine-attestation.d.ts +1 -1
- package/dist/core/engine-notice.d.ts +38 -7
- package/dist/core/engine-notice.js +9 -2
- package/dist/core/gate-fold.js +2 -2
- package/dist/core/git-worktree-env.d.ts +62 -3
- package/dist/core/git-worktree-env.js +91 -30
- package/dist/core/governance-codes.d.ts +9 -3
- package/dist/core/governance-codes.js +16 -3
- package/dist/core/hooks.d.ts +13 -0
- package/dist/core/human-input-projection.d.ts +1 -0
- package/dist/core/human-input-projection.js +3 -0
- package/dist/core/image-admission.d.ts +1 -1
- package/dist/core/locked-config.d.ts +2 -2
- package/dist/core/mcp-host-seat.js +6 -1
- package/dist/core/memory-engine/consolidation-driver.d.ts +33 -18
- package/dist/core/memory-engine/consolidation-driver.js +99 -98
- package/dist/core/memory-engine/consolidation.d.ts +73 -10
- package/dist/core/memory-engine/consolidation.js +167 -11
- package/dist/core/memory-engine/data-plane.d.ts +8 -4
- package/dist/core/memory-engine/data-plane.js +11 -6
- package/dist/core/memory-engine/delegation-settlement.d.ts +37 -35
- package/dist/core/memory-engine/delegation-settlement.js +53 -59
- package/dist/core/memory-engine/dual-root.d.ts +12 -6
- package/dist/core/memory-engine/dual-root.js +9 -5
- package/dist/core/memory-engine/engine.d.ts +98 -35
- package/dist/core/memory-engine/engine.js +477 -380
- package/dist/core/memory-engine/entry-scan.d.ts +8 -0
- package/dist/core/memory-engine/entry-scan.js +3 -0
- package/dist/core/memory-engine/file-backend.d.ts +29 -3
- package/dist/core/memory-engine/file-backend.js +66 -35
- package/dist/core/memory-engine/index.d.ts +7 -7
- package/dist/core/memory-engine/index.js +6 -6
- package/dist/core/memory-engine/landing-admission.d.ts +5 -3
- package/dist/core/memory-engine/landing-admission.js +3 -3
- package/dist/core/memory-engine/layout.d.ts +121 -45
- package/dist/core/memory-engine/layout.js +252 -102
- package/dist/core/memory-engine/memory-backend-contract.d.ts +19 -1
- package/dist/core/memory-engine/memory-backend-contract.js +320 -0
- package/dist/core/memory-engine/memory-deployment.d.ts +31 -8
- package/dist/core/memory-engine/memory-deployment.js +26 -12
- package/dist/core/memory-engine/scope-contract.d.ts +52 -11
- package/dist/core/memory-engine/scope-contract.js +68 -19
- package/dist/core/memory-engine/session-write-home.d.ts +3 -1
- package/dist/core/memory-engine/session-write-home.js +1 -1
- package/dist/core/memory-engine/sync-client.d.ts +3 -1
- package/dist/core/memory-engine/sync-client.js +7 -0
- package/dist/core/memory-engine/sync-report.d.ts +3 -2
- package/dist/core/memory-engine/sync-report.js +6 -2
- package/dist/core/memory-engine/tools.d.ts +2 -2
- package/dist/core/memory-engine/tools.js +10 -10
- package/dist/core/memory-engine/types.d.ts +118 -19
- package/dist/core/memory-engine/types.js +1 -0
- package/dist/core/memory-vector.d.ts +1 -1
- package/dist/core/memory.d.ts +10 -10
- package/dist/core/memory.js +15 -6
- package/dist/core/mode-policy.js +1 -1
- package/dist/core/mods/classic-events.d.ts +9 -1
- package/dist/core/mods/dollar.d.ts +32 -1
- package/dist/core/mods/dollar.js +13 -1
- package/dist/core/mods/kernel/events.d.ts +11 -3
- package/dist/core/mods/kernel/events.js +13 -10
- package/dist/core/mods/lifecycle-stations.d.ts +36 -4
- package/dist/core/mods/lifecycle-stations.js +44 -9
- package/dist/core/mods/session-append.d.ts +4 -1
- package/dist/core/mods/session-append.js +7 -0
- package/dist/core/mods/session-receive.js +12 -15
- package/dist/core/mods/stations.d.ts +70 -6
- package/dist/core/mods/stations.js +144 -1
- package/dist/core/own-property-receipt.d.ts +7 -0
- package/dist/core/own-property-receipt.js +3 -0
- package/dist/core/park-selfcheck.js +2 -2
- package/dist/core/pause-registry.d.ts +2 -0
- package/dist/core/pause-registry.js +3 -0
- package/dist/core/permission-rule-consent.d.ts +10 -3
- package/dist/core/permission-rule-consent.js +37 -24
- package/dist/core/permission-rule-store.d.ts +35 -1
- package/dist/core/permission-rule-store.js +27 -8
- package/dist/core/read-only-shell.js +3 -2
- package/dist/core/read-root-candidate.js +1 -1
- package/dist/core/redaction-marks.d.ts +8 -0
- package/dist/core/redaction-marks.js +6 -0
- package/dist/core/remote-env.d.ts +12 -1
- package/dist/core/remote-env.js +3 -0
- package/dist/core/resume-startup-cause.d.ts +5 -4
- package/dist/core/runner/child-tree.d.ts +29 -3
- package/dist/core/runner/child-tree.js +39 -16
- package/dist/core/runner/compact-session.js +5 -2
- package/dist/core/runner/contracts.d.ts +36 -17
- package/dist/core/runner/delegation-owner.d.ts +43 -0
- package/dist/core/runner/delegation-owner.js +59 -0
- package/dist/core/runner/gate-exit.js +2 -2
- package/dist/core/runner/inherited-ask-grants.js +1 -1
- package/dist/core/runner/lineage-reroot-view.d.ts +56 -0
- package/dist/core/runner/lineage-reroot-view.js +108 -0
- package/dist/core/runner/memory-consolidation-driver.d.ts +6 -3
- package/dist/core/runner/memory-consolidation-driver.js +4 -4
- package/dist/core/runner/memory-consolidation-write-judge.d.ts +2 -1
- package/dist/core/runner/memory-consolidation-write-judge.js +3 -2
- package/dist/core/runner/permission-rule-lanes.d.ts +2 -1
- package/dist/core/runner/permission-rule-lanes.js +2 -2
- package/dist/core/runner/person-path-rows.d.ts +23 -3
- package/dist/core/runner/person-path-rows.js +31 -4
- package/dist/core/runner/placement-fence.d.ts +12 -0
- package/dist/core/runner/placement-fence.js +20 -6
- package/dist/core/runner/prepare-acquire-reconcile.d.ts +4 -1
- package/dist/core/runner/prepare-acquire-reconcile.js +7 -2
- package/dist/core/runner/prepare-ask-lane.js +2 -2
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +5 -1
- package/dist/core/runner/prepare-caps-and-workflow.js +6 -3
- package/dist/core/runner/prepare-config-doors.d.ts +6 -6
- package/dist/core/runner/prepare-config-doors.js +3 -4
- package/dist/core/runner/prepare-execution-env.js +17 -6
- package/dist/core/runner/prepare-hands-readface.d.ts +3 -2
- package/dist/core/runner/prepare-hands-readface.js +32 -10
- package/dist/core/runner/prepare-inherited-gate.d.ts +12 -8
- package/dist/core/runner/prepare-inherited-gate.js +14 -6
- package/dist/core/runner/prepare-memory-engine-session.d.ts +2 -4
- package/dist/core/runner/prepare-memory-engine-session.js +4 -4
- package/dist/core/runner/prepare-memory.d.ts +3 -2
- package/dist/core/runner/prepare-memory.js +28 -20
- package/dist/core/runner/prepare-park-ask.js +4 -3
- package/dist/core/runner/prepare-task.js +22 -16
- package/dist/core/runner/prepare-workspace-restore.js +3 -6
- package/dist/core/runner/resume-admission.d.ts +3 -3
- package/dist/core/runner/resume-admission.js +6 -3
- package/dist/core/runner/resume-apply.d.ts +4 -0
- package/dist/core/runner/resume-apply.js +11 -4
- package/dist/core/runner/resume-checkpoint-screen.d.ts +9 -0
- package/dist/core/runner/resume-checkpoint-screen.js +4 -84
- package/dist/core/runner/run-git-lane.d.ts +2 -0
- package/dist/core/runner/run-git-lane.js +4 -1
- package/dist/core/runner/run-harness-handlers.d.ts +2 -0
- package/dist/core/runner/run-harness-handlers.js +3 -2
- package/dist/core/runner/run-leg.js +25 -8
- package/dist/core/runner/run-settle-and-teardown.js +6 -4
- package/dist/core/runner/run-stop-and-final-verify.js +2 -1
- package/dist/core/runner/run-turn-boundary.js +7 -4
- package/dist/core/runner/runtask.js +6 -6
- package/dist/core/runner/steering-preview.d.ts +9 -0
- package/dist/core/runner/steering-preview.js +5 -0
- package/dist/core/runner/stream-steer-verb.js +8 -0
- package/dist/core/runner/terminal-account.js +1 -1
- package/dist/core/runner/tool-face-overlay.js +2 -0
- package/dist/core/runner/turn-attachments.d.ts +5 -0
- package/dist/core/runner/turn-attachments.js +1 -1
- package/dist/core/runner-deps.d.ts +8 -4
- package/dist/core/secret-env.d.ts +9 -6
- package/dist/core/secret-env.js +41 -22
- package/dist/core/session-checkout.d.ts +108 -0
- package/dist/core/session-checkout.js +485 -0
- package/dist/core/session-store.d.ts +13 -5
- package/dist/core/session-store.js +28 -4
- package/dist/core/session.d.ts +29 -5
- package/dist/core/session.js +3 -0
- package/dist/core/store-contracts/checkpoint-store-contract.d.ts +6 -12
- package/dist/core/store-contracts/checkpoint-store-contract.js +73 -6
- package/dist/core/store-contracts/session-store-contract.js +61 -8
- package/dist/core/task-event.d.ts +28 -1
- package/dist/core/task-notification.d.ts +9 -1
- package/dist/core/task-notification.js +8 -1
- package/dist/core/task-registry-agent.d.ts +40 -8
- package/dist/core/task-registry-agent.js +57 -24
- package/dist/core/task-registry-shared.d.ts +33 -11
- package/dist/core/task-registry-workflow.js +4 -3
- package/dist/core/task-registry.d.ts +27 -10
- package/dist/core/task-registry.js +19 -13
- package/dist/core/task-result.d.ts +5 -5
- package/dist/core/task-spec-members.js +1 -1
- package/dist/core/task-spec.d.ts +21 -1
- package/dist/core/terminal-cause.d.ts +6 -6
- package/dist/core/tool-face.d.ts +6 -2
- package/dist/core/tool-face.js +1 -1
- package/dist/core/tool-policy.d.ts +16 -13
- package/dist/core/tool-policy.js +11 -10
- package/dist/core/tool-roster.d.ts +4 -4
- package/dist/core/tool-spec.d.ts +42 -19
- package/dist/core/types.d.ts +2 -2
- package/dist/core/types.js +1 -1
- package/dist/core/untrusted-egress.d.ts +15 -4
- package/dist/core/untrusted-egress.js +23 -22
- package/dist/core/workspace-snapshot.d.ts +3 -1
- package/dist/core/workspace-snapshot.js +1 -0
- package/dist/engine/execution-env/node-execution-env.d.ts +3 -0
- package/dist/engine/execution-env/node-execution-env.js +12 -5
- package/dist/engine/harness/types.d.ts +77 -1
- package/dist/engine/harness/types.js +108 -0
- package/dist/engine/session/import-validate.js +6 -1
- package/dist/engine/session/parent-chain-guard.d.ts +3 -3
- package/dist/engine/session/parent-chain-guard.js +1 -1
- package/dist/engine/session/path-to-root.d.ts +18 -3
- package/dist/engine/session/path-to-root.js +15 -1
- package/dist/engine/session/repo-utils.d.ts +12 -1
- package/dist/engine/session/repo-utils.js +41 -0
- package/dist/engine/session/session.d.ts +24 -1
- package/dist/engine/session/session.js +46 -2
- package/dist/engine/session/storage-base.d.ts +20 -0
- package/dist/engine/session/storage-base.js +28 -9
- package/dist/index.d.ts +16 -12
- package/dist/index.js +11 -8
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/internal/harness.d.ts +4 -3
- package/dist/internal/harness.js +3 -2
- package/dist/orchestration/run-workflow-tool.d.ts +7 -1
- package/dist/orchestration/run-workflow-tool.js +28 -11
- package/dist/orchestration/workflow-governance.d.ts +1 -1
- package/dist/orchestration/workflow.d.ts +6 -0
- package/dist/orchestration/workflow.js +5 -8
- package/dist/stores/file/checkpoint-store.d.ts +2 -0
- package/dist/stores/file/checkpoint-store.js +7 -6
- package/dist/stores/file/fs-atomic.d.ts +0 -22
- package/dist/stores/file/fs-atomic.js +0 -17
- package/dist/stores/file/index.d.ts +2 -9
- package/dist/stores/file/index.js +2 -4
- package/dist/stores/file/session-store.d.ts +13 -7
- package/dist/stores/file/session-store.js +42 -18
- package/dist/tools/fs/bash-program-position.d.ts +3 -2
- package/dist/tools/fs/bash-program-position.js +10 -10
- package/dist/tools/fs/program-read-model.d.ts +34 -10
- package/dist/tools/fs/program-read-model.js +37 -7
- package/dist/tools/fs/program-read-model.rows.js +13 -2
- package/dist/tools/fs/read-deny.d.ts +13 -1
- package/dist/tools/fs/read-deny.js +10 -2
- package/dist/tools/fs/removal-targets.js +5 -5
- package/dist/tools/fs/safety.d.ts +2 -0
- package/dist/tools/fs/safety.js +1 -1
- package/dist/tools/fs/shell-read-argv.d.ts +11 -2
- package/dist/tools/fs/shell-read-argv.js +45 -29
- package/dist/tools/fs/shell-read-bindings.d.ts +20 -2
- package/dist/tools/fs/shell-read-bindings.js +153 -69
- package/dist/tools/fs/shell-read-brace.d.ts +18 -0
- package/dist/tools/fs/shell-read-brace.js +79 -0
- package/dist/tools/fs/shell-read-check.js +29 -11
- package/dist/tools/fs/shell-read-establish.js +43 -22
- package/dist/tools/fs/shell-read-functions.js +2 -2
- package/dist/tools/fs/shell-read-judge.d.ts +11 -0
- package/dist/tools/fs/shell-read-judge.js +3 -3
- package/dist/tools/fs/shell-read-object-path.d.ts +59 -0
- package/dist/tools/fs/shell-read-object-path.js +119 -0
- package/dist/tools/fs/shell-read-plan.d.ts +18 -0
- package/dist/tools/fs/shell-read-plan.js +217 -104
- package/dist/tools/fs/shell-read-start.d.ts +76 -13
- package/dist/tools/fs/shell-read-start.js +97 -17
- package/dist/tools/fs/shell-read-word.d.ts +10 -0
- package/dist/tools/fs/shell-read-word.js +9 -5
- package/dist/tools/fs/shell-read-workdir.d.ts +54 -14
- package/dist/tools/fs/shell-read-workdir.js +103 -19
- package/dist/tools/fs/shell-read-write-targets.js +13 -8
- package/dist/tools/worktree.d.ts +3 -2
- package/dist/tools/worktree.js +7 -35
- package/package.json +3 -2
- package/test/export-surface.snapshot.json +93 -43
- package/wire-changes/core-stores-sql@7.62.0.json +30 -0
- package/wire-changes/core-stores-sql@7.63.0.json +30 -0
- package/wire-changes/core@7.62.0.json +2181 -0
- package/wire-changes/core@7.63.0.json +3523 -0
- package/wire-changes/mods-kernel@7.62.0.json +42 -0
- package/wire-changes/mods-kernel@7.63.0.json +30 -0
- package/wire-changes/primitives@7.62.0.json +30 -0
- package/wire-changes/primitives@7.63.0.json +445 -0
- package/dist/core/consolidate-scope.d.ts +0 -93
- package/dist/core/consolidate-scope.js +0 -98
- package/dist/core/credential-vocabulary.d.ts +0 -176
- package/dist/core/credential-vocabulary.js +0 -190
- package/dist/core/redaction-passes.d.ts +0 -82
- package/dist/core/redaction-passes.js +0 -377
- package/dist/core/runner/memory-consolidation.d.ts +0 -109
- package/dist/core/runner/memory-consolidation.js +0 -251
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { MemoryOriginCause } from "./types.js";
|
|
2
|
-
export declare const DELEGATION_SETTLEMENT_FILE = "delegation-settlement.json";
|
|
1
|
+
import type { MemoryGovernanceDocs, MemoryOriginCause } from "./types.js";
|
|
3
2
|
/** A row's FIRST-WRITE status. Rows are immutable after their first write — every later transition
|
|
4
3
|
* is an append-only event ({@link SettlementEvent}); the effective status is the fold. */
|
|
5
4
|
export type SettlementRowStatus = "pending" | "unattestable";
|
|
@@ -45,12 +44,12 @@ export declare function syncSettleId(sessionId: string, toolCallId: string): str
|
|
|
45
44
|
* or corrupt ledger — the launch site fails the launch loudly (a delegation that cannot be
|
|
46
45
|
* accounted must not run: the whole point is that no child exists outside the account).
|
|
47
46
|
*/
|
|
48
|
-
export declare function registerDelegationLaunch(
|
|
47
|
+
export declare function registerDelegationLaunch(docs: MemoryGovernanceDocs, input: {
|
|
49
48
|
settleId: string;
|
|
50
49
|
sessionId: string;
|
|
51
50
|
now: () => number;
|
|
52
51
|
toolUseId?: string;
|
|
53
|
-
}): void
|
|
52
|
+
}): Promise<void>;
|
|
54
53
|
/**
|
|
55
54
|
* §3.5 (r5-3) — the SYNC lane's unattestable row: a synchronous delegation delivered with a
|
|
56
55
|
* missing/unknown attestation under the "attested-only" evidence standard. The row is a durable
|
|
@@ -59,11 +58,11 @@ export declare function registerDelegationLaunch(controlDir: string, input: {
|
|
|
59
58
|
* throw here as "deliver an error instead" (fail-closed — unattested content must not ride into
|
|
60
59
|
* the transcript of a session whose account could not record the fact).
|
|
61
60
|
*/
|
|
62
|
-
export declare function recordSyncUnattestable(
|
|
61
|
+
export declare function recordSyncUnattestable(docs: MemoryGovernanceDocs, input: {
|
|
63
62
|
sessionId: string;
|
|
64
63
|
toolCallId: string;
|
|
65
64
|
now: () => number;
|
|
66
|
-
}): void
|
|
65
|
+
}): Promise<void>;
|
|
67
66
|
/**
|
|
68
67
|
* §3.3 settle — append one observed terminal (idempotent per eventId; the default eventId keys on
|
|
69
68
|
* (settleId, status) so an at-least-once observer replays into one event). Transition legality is
|
|
@@ -71,13 +70,13 @@ export declare function recordSyncUnattestable(controlDir: string, input: {
|
|
|
71
70
|
* after `expired`) still lands — as an event row the fold reads as an annotation-grade fact — so
|
|
72
71
|
* the account never loses an observation (事件不丢), it just doesn't let it rewrite history.
|
|
73
72
|
*/
|
|
74
|
-
export declare function settleDelegation(
|
|
73
|
+
export declare function settleDelegation(docs: MemoryGovernanceDocs, input: {
|
|
75
74
|
settleId: string;
|
|
76
75
|
status: "clean" | "external" | "expired" | "void" | "unattestable";
|
|
77
76
|
now: () => number;
|
|
78
77
|
eventId?: string;
|
|
79
78
|
note?: string;
|
|
80
|
-
}): void
|
|
79
|
+
}): Promise<void>;
|
|
81
80
|
/**
|
|
82
81
|
* §3.3 host valve — `resolveSettlement(settleId, "clean"|"external", requestId)`. Advisory, same
|
|
83
82
|
* trust plane as the host API family; `requestId` is the audit anchor and is REQUIRED (a
|
|
@@ -85,12 +84,12 @@ export declare function settleDelegation(controlDir: string, input: {
|
|
|
85
84
|
* semantics live in the fold: an admin `clean` flips the EFFECTIVE state (releases post-expiry)
|
|
86
85
|
* but never the history bit, and a LATER observed `external` overrides it (观测证据>admin 裁决).
|
|
87
86
|
*/
|
|
88
|
-
export declare function resolveSettlementRecord(
|
|
87
|
+
export declare function resolveSettlementRecord(docs: MemoryGovernanceDocs, input: {
|
|
89
88
|
settleId: string;
|
|
90
89
|
to: "clean" | "external";
|
|
91
90
|
requestId: string;
|
|
92
91
|
now: () => number;
|
|
93
|
-
}): void
|
|
92
|
+
}): Promise<void>;
|
|
94
93
|
/** One settlement's folded (effective) view. */
|
|
95
94
|
export interface EffectiveSettlement {
|
|
96
95
|
row: DelegationSettlementRow;
|
|
@@ -104,9 +103,9 @@ export interface EffectiveSettlement {
|
|
|
104
103
|
terminalEventId?: string;
|
|
105
104
|
}
|
|
106
105
|
/** Lock-less folded read of the whole ledger (journal-aware, fail-closed on corruption). */
|
|
107
|
-
export declare function effectiveSettlements(
|
|
106
|
+
export declare function effectiveSettlements(docs: MemoryGovernanceDocs): Promise<EffectiveSettlement[]>;
|
|
108
107
|
/** One session's folded rows (the harvest classifier's input). */
|
|
109
|
-
export declare function sessionSettlements(
|
|
108
|
+
export declare function sessionSettlements(docs: MemoryGovernanceDocs, sessionId: string): Promise<EffectiveSettlement[]>;
|
|
110
109
|
/**
|
|
111
110
|
* §3.1 — the session exposure classifier over the settlement account (the durable pollution marker
|
|
112
111
|
* is the OTHER input; the caller ORs them). `exposed` ⇔ any {external, unattestable, expired}
|
|
@@ -123,10 +122,10 @@ export declare function classifySessionSettlements(rows: readonly EffectiveSettl
|
|
|
123
122
|
* §3.3-4 — expire overdue pending rows (reconciliation's first leg). Every expiry is an event
|
|
124
123
|
* (idempotent by (settleId, "expired") key); returns the settleIds newly expired this pass.
|
|
125
124
|
*/
|
|
126
|
-
export declare function expireOverdueSettlements(
|
|
125
|
+
export declare function expireOverdueSettlements(docs: MemoryGovernanceDocs, input: {
|
|
127
126
|
timeoutMs: number;
|
|
128
127
|
now: () => number;
|
|
129
|
-
}): string[]
|
|
128
|
+
}): Promise<string[]>;
|
|
130
129
|
/**
|
|
131
130
|
* §3.3-2 — replay the EXTERNAL rows' side effects (账先落、副作用可重放): ensure the durable
|
|
132
131
|
* pollution marker is in place (wx, first-write-wins) and the retroaction challenge sweep has
|
|
@@ -136,14 +135,13 @@ export declare function expireOverdueSettlements(controlDir: string, input: {
|
|
|
136
135
|
* `carry` scopes the sweep domain exactly like the engine's own sweeps (marked rows carry their
|
|
137
136
|
* account under "carry"; the "off" width challenges everything).
|
|
138
137
|
*/
|
|
139
|
-
export declare function replayExternalSettlementEffects(controlDir: string, input: {
|
|
138
|
+
export declare function replayExternalSettlementEffects(docs: MemoryGovernanceDocs, controlDir: string, input: {
|
|
140
139
|
carry: boolean;
|
|
141
140
|
now: () => number;
|
|
142
|
-
}): Array<{
|
|
141
|
+
}): Promise<Array<{
|
|
143
142
|
settleId: string;
|
|
144
143
|
sessionId: string;
|
|
145
|
-
}
|
|
146
|
-
export declare const SESSION_ACCOUNTS_FILE = "session-accounts.json";
|
|
144
|
+
}>>;
|
|
147
145
|
/** One member of the sticky set: the ledger form `(scope, rel)` — `rel` relative to the scope's
|
|
148
146
|
* home, `/`-separated. Location-free, so a home move never re-keys the membership. */
|
|
149
147
|
export interface UnattributedMember {
|
|
@@ -183,11 +181,14 @@ export interface SessionAccountRow {
|
|
|
183
181
|
}
|
|
184
182
|
/** The one-time v1 key-form conversions of the three engine sidecars, in one call (each in its own
|
|
185
183
|
* lock, each idempotent). The layout adoption runs this before any later scope registration can
|
|
186
|
-
* change what a v1 key's first segment names.
|
|
184
|
+
* change what a v1 key's first segment names. A step of the File layout's own upgrade: it converts
|
|
185
|
+
* the hold ledger (a control-plane file, beside its custody) and the session-account document the File
|
|
186
|
+
* store keeps under `controlDir`, in place (a store that keeps documents elsewhere never held the v1
|
|
187
|
+
* form); the reads below convert the same way on first touch. */
|
|
187
188
|
export declare function convertV1SidecarKeys(controlDir: string): void;
|
|
188
189
|
/** The dangling-trigger read: open rows (and unadjudicated closes) belonging to OTHER sessions.
|
|
189
190
|
* These are what arm the unattributed residue classification at a session's materialize. */
|
|
190
|
-
export declare function foreignDanglingSessionAccounts(controlDir: string, selfSessionId: string): SessionAccountRow[]
|
|
191
|
+
export declare function foreignDanglingSessionAccounts(docs: MemoryGovernanceDocs, controlDir: string, selfSessionId: string): Promise<SessionAccountRow[]>;
|
|
191
192
|
/** The live writers of the store's layers, as the account knows them: every row other than the one
|
|
192
193
|
* held by `selfLeg` (the asking mount's own leg — another leg of the same session is another
|
|
193
194
|
* writer) whose session's leg has not ended (no `terminatedAt` — running, or ended without
|
|
@@ -196,20 +197,20 @@ export declare function foreignDanglingSessionAccounts(controlDir: string, selfS
|
|
|
196
197
|
* whether the leg ended) reads as before: live while never closed, counted in `unscoped` — a
|
|
197
198
|
* writer of an unknown layer. Sessions that open no row (no session id, provenance "off", an
|
|
198
199
|
* adoption-restricted mount) are not visible here. */
|
|
199
|
-
export declare function openLayerWriters(controlDir: string, selfLeg: string | undefined): {
|
|
200
|
+
export declare function openLayerWriters(docs: MemoryGovernanceDocs, controlDir: string, selfLeg: string | undefined): Promise<{
|
|
200
201
|
scopes: Set<string>;
|
|
201
202
|
unscoped: number;
|
|
202
|
-
}
|
|
203
|
+
}>;
|
|
203
204
|
/** The leg that holds `sessionId`'s account row (undefined ⇔ no row, or a row without one). */
|
|
204
|
-
export declare function sessionAccountLeg(controlDir: string, sessionId: string): string | undefined
|
|
205
|
+
export declare function sessionAccountLeg(docs: MemoryGovernanceDocs, controlDir: string, sessionId: string): Promise<string | undefined>;
|
|
205
206
|
/** The write scope `sessionId`'s account row records — the scope its newest account-opening mount wrote
|
|
206
207
|
* under (the value that mount's handle carries as `writeScope`), whether that leg is still live or has
|
|
207
208
|
* ended. Undefined ⇔ no row, a row written before the field, or a v1 ledger (whose rows predate it —
|
|
208
209
|
* answered without the conversion, so this read writes nothing). Throws on a corrupt ledger. */
|
|
209
|
-
export declare function sessionAccountWriteHome(
|
|
210
|
+
export declare function sessionAccountWriteHome(docs: MemoryGovernanceDocs, sessionId: string): Promise<{
|
|
210
211
|
writeScope: string;
|
|
211
212
|
openedAt: number;
|
|
212
|
-
} | undefined
|
|
213
|
+
} | undefined>;
|
|
213
214
|
/** The membership question the harvest asks per file: is `(scope, rel)` in the session's sticky
|
|
214
215
|
* set? A session carrying members the conversion could not attribute answers yes for every seat. */
|
|
215
216
|
export interface SessionUnattributedSet {
|
|
@@ -220,15 +221,15 @@ export interface SessionUnattributedSet {
|
|
|
220
221
|
export declare function emptyUnattributedSet(): SessionUnattributedSet;
|
|
221
222
|
/** Open (or re-open, on a same-session resume) the session's account row, persisting the sticky
|
|
222
223
|
* unattributed classification frozen at THIS materialize. */
|
|
223
|
-
export declare function openSessionAccount(controlDir: string, input: {
|
|
224
|
+
export declare function openSessionAccount(docs: MemoryGovernanceDocs, controlDir: string, input: {
|
|
224
225
|
sessionId: string;
|
|
225
226
|
now: () => number;
|
|
226
227
|
unattributed: readonly UnattributedMember[];
|
|
227
228
|
writeScope?: string;
|
|
228
229
|
leg?: string;
|
|
229
|
-
}): void
|
|
230
|
+
}): Promise<void>;
|
|
230
231
|
/** The current session's sticky unattributed set (the harvest's residue-arm input). */
|
|
231
|
-
export declare function sessionUnattributedSet(controlDir: string, sessionId: string): SessionUnattributedSet
|
|
232
|
+
export declare function sessionUnattributedSet(docs: MemoryGovernanceDocs, controlDir: string, sessionId: string): Promise<SessionUnattributedSet>;
|
|
232
233
|
/** Close the session's account row — called ONLY after a FULL-domain harvest (zero BUDGET-deferred
|
|
233
234
|
* files, i.e. `HarvestReport.degraded` absent): a partial harvest's close would launder the deferred
|
|
234
235
|
* residue window (§3.6 序则②). A normal full close also clears every standing `unadjudicated` flag
|
|
@@ -243,30 +244,30 @@ export declare function sessionUnattributedSet(controlDir: string, sessionId: st
|
|
|
243
244
|
* Returns what happened ({@link SessionAccountWrite}): `"absent"` (a session that never opened an
|
|
244
245
|
* account — e.g. an adoption-restricted materialize — has no close, and the caller's disclosure
|
|
245
246
|
* must not claim one), or `"stale"` when `leg` names a mount that no longer holds the row. */
|
|
246
|
-
export declare function closeSessionAccount(controlDir: string, input: {
|
|
247
|
+
export declare function closeSessionAccount(docs: MemoryGovernanceDocs, controlDir: string, input: {
|
|
247
248
|
sessionId: string;
|
|
248
249
|
now: () => number;
|
|
249
250
|
leg?: string;
|
|
250
|
-
}): SessionAccountWrite
|
|
251
|
+
}): Promise<SessionAccountWrite>;
|
|
251
252
|
/** What a close / leg end did: wrote the row, found none, or found the row held by ANOTHER leg (the
|
|
252
253
|
* caller's leg is over — a resume re-opened the row — so nothing was written). */
|
|
253
254
|
export type SessionAccountWrite = "written" | "absent" | "stale";
|
|
254
255
|
/** Record that the session's leg ended ({@link SessionAccountRow.terminatedAt}). Touches nothing
|
|
255
256
|
* else — `closedAt` stays whatever the harvests made it. `leg` (the caller's mount) must hold the
|
|
256
257
|
* row: a leg that is over does not end the one that re-opened it. */
|
|
257
|
-
export declare function terminateSessionAccount(controlDir: string, input: {
|
|
258
|
+
export declare function terminateSessionAccount(docs: MemoryGovernanceDocs, controlDir: string, input: {
|
|
258
259
|
sessionId: string;
|
|
259
260
|
now: () => number;
|
|
260
261
|
leg?: string;
|
|
261
|
-
}): SessionAccountWrite
|
|
262
|
+
}): Promise<SessionAccountWrite>;
|
|
262
263
|
/** The host valve for a dangling row (advisory; §3.6 — dangling rows never auto-expire). The
|
|
263
264
|
* close is `closed-unadjudicated` (r7-3): it stops the row dangling but the residue arm keeps
|
|
264
265
|
* firing until a full-domain harvest closes normally. `requestId` required (audit, #123). */
|
|
265
|
-
export declare function resolveSessionAccountRecord(controlDir: string, input: {
|
|
266
|
+
export declare function resolveSessionAccountRecord(docs: MemoryGovernanceDocs, controlDir: string, input: {
|
|
266
267
|
sessionId: string;
|
|
267
268
|
requestId: string;
|
|
268
269
|
now: () => number;
|
|
269
|
-
}): void
|
|
270
|
+
}): Promise<void>;
|
|
270
271
|
export declare const HOLDS_FILE = "holds.json";
|
|
271
272
|
export declare const HOLD_DIR = "hold";
|
|
272
273
|
export type HoldStatus = "capturing" | "held" | "released" | "disposed";
|
|
@@ -388,6 +389,7 @@ export declare function openInstructionHold(controlDir: string, input: {
|
|
|
388
389
|
export declare function reconcileHolds(controlDir: string, input: {
|
|
389
390
|
homeOf: (scope: string) => string;
|
|
390
391
|
now: () => number;
|
|
392
|
+
onStranded: (scope: string, line: string) => void;
|
|
391
393
|
}): void;
|
|
392
394
|
/** Dispose one held row: custody bytes move to the quarantine directory (host-auditable), the row
|
|
393
395
|
* records its terminal + quarantineName (from-row-to-bytes addressing survives every terminal). */
|
|
@@ -444,4 +446,4 @@ export declare function clearHoldResolution(controlDir: string, input: {
|
|
|
444
446
|
export declare function readHoldCustody(controlDir: string, row: HoldRow): string | undefined;
|
|
445
447
|
/** True ⇔ the session's pollution marker or any non-clean settlement row blocks a clean release
|
|
446
448
|
* (§4.2-1: any non-clean row in the session's account keeps the hold held/disposed). */
|
|
447
|
-
export declare function sessionBlocksCleanRelease(controlDir: string, sessionId: string): boolean
|
|
449
|
+
export declare function sessionBlocksCleanRelease(docs: MemoryGovernanceDocs, controlDir: string, sessionId: string): Promise<boolean>;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { closeSync, existsSync, fsyncSync, linkSync, lstatSync, openSync, readFileSync, readdirSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { basename, dirname, join } from "node:path";
|
|
4
|
-
import { QUARANTINE_DIR, appendChallengeEvents, claimStaging,
|
|
4
|
+
import { QUARANTINE_DIR, appendChallengeEvents, claimStaging, ensureDirExists, fileGovernanceDocOf, isSameFile, lockedStrictUpdate, mintStagingName, readStrictSidecar, stagingNamePattern, v1MemoryPathKeyResolver, lineageContributionsOfSession, markSessionPolluted, readProjectionDebts, readSessionPollution, ControlPlaneCorruptError } from "./layout.js";
|
|
5
5
|
import { thrownText } from "../thrown-value.js";
|
|
6
|
-
export const DELEGATION_SETTLEMENT_FILE = "delegation-settlement.json";
|
|
7
6
|
function reqStr(v) {
|
|
8
7
|
return typeof v === "string" && v.length > 0;
|
|
9
8
|
}
|
|
@@ -48,33 +47,33 @@ function coerceSettlement(raw) {
|
|
|
48
47
|
export function syncSettleId(sessionId, toolCallId) {
|
|
49
48
|
return `sync:${encodeURIComponent(sessionId)}:${encodeURIComponent(toolCallId)}`;
|
|
50
49
|
}
|
|
51
|
-
export function registerDelegationLaunch(
|
|
52
|
-
|
|
50
|
+
export async function registerDelegationLaunch(docs, input) {
|
|
51
|
+
await docs.updateDoc("settlements", coerceSettlement, (rec) => {
|
|
53
52
|
if (rec.rows.some((r) => r.settleId === input.settleId))
|
|
54
53
|
return { result: undefined };
|
|
55
54
|
rec.rows.push({ settleId: input.settleId, sessionId: input.sessionId, launchedAt: input.now(), lane: "background", status: "pending", ...(input.toolUseId !== undefined ? { toolUseId: input.toolUseId } : {}) });
|
|
56
55
|
return { next: rec, result: undefined };
|
|
57
56
|
});
|
|
58
57
|
}
|
|
59
|
-
export function recordSyncUnattestable(
|
|
58
|
+
export async function recordSyncUnattestable(docs, input) {
|
|
60
59
|
const settleId = syncSettleId(input.sessionId, input.toolCallId);
|
|
61
|
-
|
|
60
|
+
await docs.updateDoc("settlements", coerceSettlement, (rec) => {
|
|
62
61
|
if (rec.rows.some((r) => r.settleId === settleId))
|
|
63
62
|
return { result: undefined };
|
|
64
63
|
rec.rows.push({ settleId, sessionId: input.sessionId, launchedAt: input.now(), lane: "sync", status: "unattestable" });
|
|
65
64
|
return { next: rec, result: undefined };
|
|
66
65
|
});
|
|
67
66
|
}
|
|
68
|
-
export function settleDelegation(
|
|
67
|
+
export async function settleDelegation(docs, input) {
|
|
69
68
|
const eventId = input.eventId ?? `settle:${input.settleId}:${input.status}`;
|
|
70
|
-
|
|
69
|
+
await docs.updateDoc("settlements", coerceSettlement, (rec) => {
|
|
71
70
|
if (rec.events.some((e) => e.eventId === eventId))
|
|
72
71
|
return { result: undefined };
|
|
73
72
|
rec.events.push({ settleId: input.settleId, eventId, at: input.now(), kind: "settle", status: input.status, ...(input.note !== undefined ? { note: input.note } : {}) });
|
|
74
73
|
return { next: rec, result: undefined };
|
|
75
74
|
});
|
|
76
75
|
}
|
|
77
|
-
export function resolveSettlementRecord(
|
|
76
|
+
export async function resolveSettlementRecord(docs, input) {
|
|
78
77
|
if (typeof input.requestId !== "string" || input.requestId.length === 0) {
|
|
79
78
|
const e = new Error("resolveSettlement requires a non-empty requestId (the audit attribution of who resolved) — refused, never defaulted.");
|
|
80
79
|
e.code = "memory.settlement_resolve_unattributed";
|
|
@@ -86,7 +85,7 @@ export function resolveSettlementRecord(controlDir, input) {
|
|
|
86
85
|
throw e;
|
|
87
86
|
}
|
|
88
87
|
const eventId = `admin:${input.requestId}:${input.settleId}:${input.to}`;
|
|
89
|
-
|
|
88
|
+
await docs.updateDoc("settlements", coerceSettlement, (rec) => {
|
|
90
89
|
if (!rec.rows.some((r) => r.settleId === input.settleId)) {
|
|
91
90
|
const e = new Error(`resolveSettlement: unknown settleId ${JSON.stringify(input.settleId)}`);
|
|
92
91
|
e.code = "memory.settlement_resolve_unknown";
|
|
@@ -143,8 +142,8 @@ function foldOne(row, events) {
|
|
|
143
142
|
}
|
|
144
143
|
return { row, effective, everExternal, ...(terminalEventId !== undefined ? { terminalEventId } : {}) };
|
|
145
144
|
}
|
|
146
|
-
export function effectiveSettlements(
|
|
147
|
-
const rec = coerceSettlement(
|
|
145
|
+
export async function effectiveSettlements(docs) {
|
|
146
|
+
const rec = coerceSettlement(await docs.readDoc("settlements"));
|
|
148
147
|
const bySettle = new Map();
|
|
149
148
|
for (const e of rec.events) {
|
|
150
149
|
const arr = bySettle.get(e.settleId);
|
|
@@ -155,8 +154,8 @@ export function effectiveSettlements(controlDir) {
|
|
|
155
154
|
}
|
|
156
155
|
return rec.rows.map((row) => foldOne(row, bySettle.get(row.settleId) ?? []));
|
|
157
156
|
}
|
|
158
|
-
export function sessionSettlements(
|
|
159
|
-
return effectiveSettlements(
|
|
157
|
+
export async function sessionSettlements(docs, sessionId) {
|
|
158
|
+
return (await effectiveSettlements(docs)).filter((s) => s.row.sessionId === sessionId);
|
|
160
159
|
}
|
|
161
160
|
export function classifySessionSettlements(rows) {
|
|
162
161
|
let sawPending = false;
|
|
@@ -184,18 +183,18 @@ export function classifySessionSettlements(rows) {
|
|
|
184
183
|
return { state: "pending" };
|
|
185
184
|
return { state: "clean" };
|
|
186
185
|
}
|
|
187
|
-
export function expireOverdueSettlements(
|
|
188
|
-
const overdue = effectiveSettlements(
|
|
186
|
+
export async function expireOverdueSettlements(docs, input) {
|
|
187
|
+
const overdue = (await effectiveSettlements(docs)).filter((s) => s.effective === "pending" && input.now() - s.row.launchedAt > input.timeoutMs);
|
|
189
188
|
for (const s of overdue)
|
|
190
|
-
settleDelegation(
|
|
189
|
+
await settleDelegation(docs, { settleId: s.row.settleId, status: "expired", now: input.now });
|
|
191
190
|
return overdue.map((s) => s.row.settleId);
|
|
192
191
|
}
|
|
193
|
-
export function replayExternalSettlementEffects(controlDir, input) {
|
|
192
|
+
export async function replayExternalSettlementEffects(docs, controlDir, input) {
|
|
194
193
|
const applied = [];
|
|
195
|
-
const folded = effectiveSettlements(
|
|
194
|
+
const folded = (await effectiveSettlements(docs)).filter((s) => s.effective === "external" && s.terminalEventId !== undefined);
|
|
196
195
|
if (folded.length === 0)
|
|
197
196
|
return applied;
|
|
198
|
-
const rec = coerceSettlement(
|
|
197
|
+
const rec = coerceSettlement(await docs.readDoc("settlements"));
|
|
199
198
|
for (const s of folded) {
|
|
200
199
|
if (rec.effects[s.row.settleId] === s.terminalEventId)
|
|
201
200
|
continue;
|
|
@@ -204,9 +203,9 @@ export function replayExternalSettlementEffects(controlDir, input) {
|
|
|
204
203
|
if (outcome === "unpersisted")
|
|
205
204
|
continue;
|
|
206
205
|
try {
|
|
207
|
-
const swept = lineageContributionsOfSession(
|
|
206
|
+
const swept = await lineageContributionsOfSession(docs, sessionId);
|
|
208
207
|
const contributions = input.carry ? swept.filter((c) => c.marked !== true) : swept;
|
|
209
|
-
appendChallengeEvents(
|
|
208
|
+
await appendChallengeEvents(docs, contributions.map((c) => ({
|
|
210
209
|
eventId: `settlement:${s.row.settleId}:${s.terminalEventId}:${c.entryId}`,
|
|
211
210
|
entryId: c.entryId,
|
|
212
211
|
reason: "challenged: the contributing session's delegation settled external",
|
|
@@ -217,7 +216,7 @@ export function replayExternalSettlementEffects(controlDir, input) {
|
|
|
217
216
|
continue;
|
|
218
217
|
}
|
|
219
218
|
console.warn(`[sema] delegation settlement: a background delegation of session ${JSON.stringify(sessionId)} settled EXTERNAL after launch — the session is marked and its unmarked committed contributions are challenged`);
|
|
220
|
-
|
|
219
|
+
await docs.updateDoc("settlements", coerceSettlement, (r) => {
|
|
221
220
|
r.effects[s.row.settleId] = s.terminalEventId;
|
|
222
221
|
return { next: r, result: undefined };
|
|
223
222
|
});
|
|
@@ -225,7 +224,6 @@ export function replayExternalSettlementEffects(controlDir, input) {
|
|
|
225
224
|
}
|
|
226
225
|
return applied;
|
|
227
226
|
}
|
|
228
|
-
export const SESSION_ACCOUNTS_FILE = "session-accounts.json";
|
|
229
227
|
function malformedAccountRow(row) {
|
|
230
228
|
return (typeof row !== "object" ||
|
|
231
229
|
row === null ||
|
|
@@ -301,30 +299,36 @@ function convertSessionAccounts(read, controlDir) {
|
|
|
301
299
|
export function convertV1SidecarKeys(controlDir) {
|
|
302
300
|
readProjectionDebts(controlDir);
|
|
303
301
|
readHolds(controlDir);
|
|
304
|
-
|
|
302
|
+
const accounts = fileGovernanceDocOf("session-accounts");
|
|
303
|
+
if (coerceSessionAccounts(readStrictSidecar(controlDir, accounts.file, accounts.what)).version !== 2) {
|
|
304
|
+
lockedStrictUpdate(controlDir, accounts.file, accounts.what, coerceSessionAccounts, (again) => {
|
|
305
|
+
const { rec, converted } = convertSessionAccounts(again, controlDir);
|
|
306
|
+
return converted ? { next: rec, result: undefined } : { result: undefined };
|
|
307
|
+
});
|
|
308
|
+
}
|
|
305
309
|
}
|
|
306
|
-
function readSessionAccountsConverted(controlDir) {
|
|
307
|
-
const read = coerceSessionAccounts(
|
|
310
|
+
async function readSessionAccountsConverted(docs, controlDir) {
|
|
311
|
+
const read = coerceSessionAccounts(await docs.readDoc("session-accounts"));
|
|
308
312
|
if (read.version === 2)
|
|
309
313
|
return read;
|
|
310
|
-
return
|
|
314
|
+
return docs.updateDoc("session-accounts", coerceSessionAccounts, (again) => {
|
|
311
315
|
const { rec, converted } = convertSessionAccounts(again, controlDir);
|
|
312
316
|
return converted ? { next: rec, result: rec } : { result: rec };
|
|
313
317
|
});
|
|
314
318
|
}
|
|
315
|
-
export function foreignDanglingSessionAccounts(controlDir, selfSessionId) {
|
|
316
|
-
const rec = readSessionAccountsConverted(controlDir);
|
|
319
|
+
export async function foreignDanglingSessionAccounts(docs, controlDir, selfSessionId) {
|
|
320
|
+
const rec = await readSessionAccountsConverted(docs, controlDir);
|
|
317
321
|
return rec.rows.filter((r) => r.sessionId !== selfSessionId && (r.closedAt === undefined || r.unadjudicated === true));
|
|
318
322
|
}
|
|
319
|
-
export function openLayerWriters(controlDir, selfLeg) {
|
|
320
|
-
const open = readSessionAccountsConverted(controlDir).rows.filter((r) => (selfLeg === undefined || r.leg !== selfLeg) && (r.writeScope !== undefined ? r.terminatedAt === undefined : r.closedAt === undefined));
|
|
323
|
+
export async function openLayerWriters(docs, controlDir, selfLeg) {
|
|
324
|
+
const open = (await readSessionAccountsConverted(docs, controlDir)).rows.filter((r) => (selfLeg === undefined || r.leg !== selfLeg) && (r.writeScope !== undefined ? r.terminatedAt === undefined : r.closedAt === undefined));
|
|
321
325
|
return { scopes: new Set(open.flatMap((r) => (r.writeScope !== undefined ? [r.writeScope] : []))), unscoped: open.filter((r) => r.writeScope === undefined).length };
|
|
322
326
|
}
|
|
323
|
-
export function sessionAccountLeg(controlDir, sessionId) {
|
|
324
|
-
return readSessionAccountsConverted(controlDir).rows.find((r) => r.sessionId === sessionId)?.leg;
|
|
327
|
+
export async function sessionAccountLeg(docs, controlDir, sessionId) {
|
|
328
|
+
return (await readSessionAccountsConverted(docs, controlDir)).rows.find((r) => r.sessionId === sessionId)?.leg;
|
|
325
329
|
}
|
|
326
|
-
export function sessionAccountWriteHome(
|
|
327
|
-
const read = coerceSessionAccounts(
|
|
330
|
+
export async function sessionAccountWriteHome(docs, sessionId) {
|
|
331
|
+
const read = coerceSessionAccounts(await docs.readDoc("session-accounts"));
|
|
328
332
|
if (read.version !== 2)
|
|
329
333
|
return undefined;
|
|
330
334
|
const row = read.rows.find((r) => r.sessionId === sessionId);
|
|
@@ -336,8 +340,8 @@ export function emptyUnattributedSet() {
|
|
|
336
340
|
function memberKey(scope, rel) {
|
|
337
341
|
return JSON.stringify([scope, rel]);
|
|
338
342
|
}
|
|
339
|
-
export function openSessionAccount(controlDir, input) {
|
|
340
|
-
|
|
343
|
+
export async function openSessionAccount(docs, controlDir, input) {
|
|
344
|
+
await docs.updateDoc("session-accounts", coerceSessionAccounts, (read) => {
|
|
341
345
|
const { rec } = convertSessionAccounts(read, controlDir);
|
|
342
346
|
const row = rec.rows.find((r) => r.sessionId === input.sessionId);
|
|
343
347
|
if (row !== undefined && input.writeScope !== undefined)
|
|
@@ -369,16 +373,16 @@ export function openSessionAccount(controlDir, input) {
|
|
|
369
373
|
return { next: rec, result: undefined };
|
|
370
374
|
});
|
|
371
375
|
}
|
|
372
|
-
export function sessionUnattributedSet(controlDir, sessionId) {
|
|
373
|
-
const row = readSessionAccountsConverted(controlDir).rows.find((r) => r.sessionId === sessionId);
|
|
376
|
+
export async function sessionUnattributedSet(docs, controlDir, sessionId) {
|
|
377
|
+
const row = (await readSessionAccountsConverted(docs, controlDir)).rows.find((r) => r.sessionId === sessionId);
|
|
374
378
|
if (row === undefined)
|
|
375
379
|
return emptyUnattributedSet();
|
|
376
380
|
const all = (row.unattributable?.length ?? 0) > 0;
|
|
377
381
|
const keys = new Set(row.unattributed.map((m) => memberKey(m.scope, m.rel)));
|
|
378
382
|
return { has: (scope, rel) => all || keys.has(memberKey(scope, rel.split("\\").join("/"))), empty: !all && keys.size === 0 };
|
|
379
383
|
}
|
|
380
|
-
export function closeSessionAccount(controlDir, input) {
|
|
381
|
-
return
|
|
384
|
+
export async function closeSessionAccount(docs, controlDir, input) {
|
|
385
|
+
return docs.updateDoc("session-accounts", coerceSessionAccounts, (read) => {
|
|
382
386
|
const { rec } = convertSessionAccounts(read, controlDir);
|
|
383
387
|
const row = rec.rows.find((r) => r.sessionId === input.sessionId);
|
|
384
388
|
if (row === undefined)
|
|
@@ -392,8 +396,8 @@ export function closeSessionAccount(controlDir, input) {
|
|
|
392
396
|
return { next: rec, result: "written" };
|
|
393
397
|
});
|
|
394
398
|
}
|
|
395
|
-
export function terminateSessionAccount(controlDir, input) {
|
|
396
|
-
return
|
|
399
|
+
export async function terminateSessionAccount(docs, controlDir, input) {
|
|
400
|
+
return docs.updateDoc("session-accounts", coerceSessionAccounts, (read) => {
|
|
397
401
|
const { rec } = convertSessionAccounts(read, controlDir);
|
|
398
402
|
const row = rec.rows.find((r) => r.sessionId === input.sessionId);
|
|
399
403
|
if (row === undefined)
|
|
@@ -404,13 +408,13 @@ export function terminateSessionAccount(controlDir, input) {
|
|
|
404
408
|
return { next: rec, result: "written" };
|
|
405
409
|
});
|
|
406
410
|
}
|
|
407
|
-
export function resolveSessionAccountRecord(controlDir, input) {
|
|
411
|
+
export async function resolveSessionAccountRecord(docs, controlDir, input) {
|
|
408
412
|
if (typeof input.requestId !== "string" || input.requestId.length === 0) {
|
|
409
413
|
const e = new Error("resolveSessionAccount requires a non-empty requestId (the audit attribution of who closed) — refused, never defaulted.");
|
|
410
414
|
e.code = "memory.session_account_resolve_unattributed";
|
|
411
415
|
throw e;
|
|
412
416
|
}
|
|
413
|
-
|
|
417
|
+
await docs.updateDoc("session-accounts", coerceSessionAccounts, (read) => {
|
|
414
418
|
const { rec } = convertSessionAccounts(read, controlDir);
|
|
415
419
|
const row = rec.rows.find((r) => r.sessionId === input.sessionId);
|
|
416
420
|
if (row === undefined) {
|
|
@@ -656,17 +660,7 @@ export function openInstructionHold(controlDir, input) {
|
|
|
656
660
|
export function reconcileHolds(controlDir, input) {
|
|
657
661
|
const holdDir = join(controlDir, HOLD_DIR);
|
|
658
662
|
const discloseStranded = (holdId, scope, rel, at) => {
|
|
659
|
-
|
|
660
|
-
enqueueMemoryAnnouncement(controlDir, {
|
|
661
|
-
kind: "gate",
|
|
662
|
-
scope,
|
|
663
|
-
at: input.now(),
|
|
664
|
-
items: [`instruction hold ${holdId}: a concurrent writer's bytes for ${JSON.stringify(rel)} could not be restored onto the plane — they are preserved at ${at} for host recovery`],
|
|
665
|
-
});
|
|
666
|
-
}
|
|
667
|
-
catch {
|
|
668
|
-
console.warn(`[sema] instruction hold ${holdId}: concurrent-writer bytes preserved at ${at} could not be restored or announced`);
|
|
669
|
-
}
|
|
663
|
+
input.onStranded(scope, `instruction hold ${holdId}: a concurrent writer's bytes for ${JSON.stringify(rel)} could not be restored onto the plane — they are preserved at ${at} for host recovery`);
|
|
670
664
|
};
|
|
671
665
|
const finishRemoval = (row, plane) => {
|
|
672
666
|
const stagingName = mintStagingName(row.holdId, input.now);
|
|
@@ -906,8 +900,8 @@ export function readHoldCustody(controlDir, row) {
|
|
|
906
900
|
}
|
|
907
901
|
return undefined;
|
|
908
902
|
}
|
|
909
|
-
export function sessionBlocksCleanRelease(controlDir, sessionId) {
|
|
903
|
+
export async function sessionBlocksCleanRelease(docs, controlDir, sessionId) {
|
|
910
904
|
if (readSessionPollution(controlDir, sessionId) !== undefined)
|
|
911
905
|
return true;
|
|
912
|
-
return sessionSettlements(
|
|
906
|
+
return (await sessionSettlements(docs, sessionId)).some((s) => s.effective !== "clean" && s.effective !== "void");
|
|
913
907
|
}
|
|
@@ -10,11 +10,12 @@ export declare function derivePersonalControlDir(configRoot: string): string;
|
|
|
10
10
|
export interface ScopePlanes {
|
|
11
11
|
/** proj:/legacy scopes — the repo/path-keyed plane (order preserved). */
|
|
12
12
|
project: string[];
|
|
13
|
-
/** user:/userproj:/org: scopes — the home-mount plane (order preserved). `org` is
|
|
13
|
+
/** user:/userlocal:/userproj:/org: scopes — the home-mount plane (order preserved). `org` is
|
|
14
14
|
* CENTRAL-authority (§2 表), so it routes with the personal keys — under a pinned in-repo File
|
|
15
15
|
* backend an org layer projected into the repo would leak tenant-shared memory into commit
|
|
16
16
|
* history. The mount is still the "personal" directory (one home plane; the plane is about
|
|
17
|
-
* WHERE-NOT-to-project, not about ownership — org's authority disk is the central DB anyway
|
|
17
|
+
* WHERE-NOT-to-project, not about ownership — org's authority disk is the central DB anyway, and a
|
|
18
|
+
* `userlocal:` layer's is the store it is written in: it is never replicated). */
|
|
18
19
|
personal: string[];
|
|
19
20
|
/** Which plane owns the write face (null = read-only layering everywhere). */
|
|
20
21
|
writePlane: "project" | "personal" | null;
|
|
@@ -67,7 +68,8 @@ export interface MemoryScopeStoreInput {
|
|
|
67
68
|
* non-empty string, and under v2 a typed key the scope contract cannot read.
|
|
68
69
|
* On a directory-pinned deployment a personal-plane answer is a File store opened over the
|
|
69
70
|
* personal mount (opening creates the mount's directories and finishes an interrupted transaction,
|
|
70
|
-
* as a session's opening does); resolve once per scope and keep it.
|
|
71
|
+
* as a session's opening does); resolve once per scope and keep it. Opening is not a write: a store
|
|
72
|
+
* only opened or read is not in a deployment's store set (`memory.deployment.store_set`).
|
|
71
73
|
*/
|
|
72
74
|
export declare function resolveMemoryScopeStore(input: MemoryScopeStoreInput): MemoryScopeStore;
|
|
73
75
|
/** The two deployment facts a store resolution reads besides the backend, judged as {@link resolveMemoryScopeStore}
|
|
@@ -76,9 +78,13 @@ export declare function judgeMemoryStoreSeat(face: string, input: {
|
|
|
76
78
|
scopeContract: "v2" | undefined;
|
|
77
79
|
memoryEngineDir: string | undefined;
|
|
78
80
|
}): void;
|
|
79
|
-
/** The plane carrying `scope
|
|
80
|
-
*
|
|
81
|
-
*
|
|
81
|
+
/** The plane carrying `scope`: the one reading of which plane a scope key belongs to, shared by the store resolution and the
|
|
82
|
+
* deployment face and exported for a host that needs the answer without a store — the Runner's own normalization
|
|
83
|
+
* (surrounding whitespace trimmed; under v2 the scope contract's parse), then {@link scopePlanesOf}. No store is opened and
|
|
84
|
+
* no disk is read. `face` is the caller's own name, written into every refusal (`<face>: …`); `scopeContract` is the
|
|
85
|
+
* session's `TaskSpec.memory.scopeContract`, `undefined` written out for the opt-in absent (anything but `"v2"` and
|
|
86
|
+
* `undefined` is refused). A key the contract cannot read, a blank or non-string one, and a bad contract are refused
|
|
87
|
+
* (`config.memory_scope_key`). */
|
|
82
88
|
export declare function memoryScopePlaneOf(face: string, scope: unknown, scopeContract: "v2" | undefined): "project" | "personal";
|
|
83
89
|
/** The store-resolution input refusal (`config.memory_scope_key`), named by the face that refused. */
|
|
84
90
|
export declare function refuseMemoryStoreInput(face: string, what: string, v: unknown, cause?: unknown): never;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isPersonalPlaneScope, parseScopeKey } from "./scope-contract.js";
|
|
2
2
|
import { CONTROL_PLANE_DIR, resolveMemoryEngineRoot } from "./layout.js";
|
|
3
3
|
import { ERASURE_CARRIER_CLASSES, FileMemoryEngineBackend } from "./file-backend.js";
|
|
4
4
|
import { thrownText } from "../thrown-value.js";
|
|
@@ -14,9 +14,9 @@ export function classifyScopePlanes(scopes, writeScope) {
|
|
|
14
14
|
const project = [];
|
|
15
15
|
const personal = [];
|
|
16
16
|
for (const s of scopes) {
|
|
17
|
-
(
|
|
17
|
+
(isPersonalPlaneScope(parseScopeKey(s)) ? personal : project).push(s);
|
|
18
18
|
}
|
|
19
|
-
const writePlane = writeScope === null ? null :
|
|
19
|
+
const writePlane = writeScope === null ? null : isPersonalPlaneScope(parseScopeKey(writeScope)) ? "personal" : "project";
|
|
20
20
|
return { project, personal, writePlane };
|
|
21
21
|
}
|
|
22
22
|
export function scopePlanesOf(scopes, writeScope, scopeContract) {
|
|
@@ -43,12 +43,16 @@ export function judgeMemoryStoreSeat(face, input) {
|
|
|
43
43
|
if (!Object.prototype.hasOwnProperty.call(input, key))
|
|
44
44
|
refuseMemoryStoreInput(face, `${key} is a required key (write undefined to state its absence)`, undefined);
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
refuseMemoryStoreInput(face, `scopeContract must be "v2" or undefined`, scopeContract);
|
|
46
|
+
judgeScopeContract(face, scopeContract);
|
|
48
47
|
if (memoryEngineDir !== undefined && (typeof memoryEngineDir !== "string" || memoryEngineDir === ""))
|
|
49
48
|
refuseMemoryStoreInput(face, "memoryEngineDir must be a non-empty string or undefined", memoryEngineDir);
|
|
50
49
|
}
|
|
50
|
+
function judgeScopeContract(face, scopeContract) {
|
|
51
|
+
if (scopeContract !== undefined && scopeContract !== "v2")
|
|
52
|
+
refuseMemoryStoreInput(face, `scopeContract must be "v2" or undefined`, scopeContract);
|
|
53
|
+
}
|
|
51
54
|
export function memoryScopePlaneOf(face, scope, scopeContract) {
|
|
55
|
+
judgeScopeContract(face, scopeContract);
|
|
52
56
|
let spec;
|
|
53
57
|
try {
|
|
54
58
|
spec = normalizeMemorySpec({ scopes: [scope], writeScope: scope, ...(scopeContract === "v2" ? { scopeContract } : {}) });
|