@sema-agent/core 7.65.0 → 7.66.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 +254 -0
- package/dist/agents/delegation-registry-seat.d.ts +15 -0
- package/dist/agents/delegation-registry-seat.js +13 -0
- package/dist/agents/org-delivery-gate.d.ts +8 -1
- package/dist/agents/org-delivery-gate.js +9 -3
- package/dist/agents/peer-session-drain.d.ts +51 -12
- package/dist/agents/peer-session-drain.js +44 -31
- package/dist/agents/read-inbox-tool.d.ts +6 -2
- package/dist/agents/read-inbox-tool.js +18 -5
- package/dist/agents/subagent.d.ts +3 -1
- package/dist/agents/subagent.js +79 -75
- package/dist/brain/reasoning.d.ts +2 -0
- package/dist/brain/reasoning.js +1 -0
- package/dist/core/allow-entry.d.ts +9 -0
- package/dist/core/allow-entry.js +7 -1
- package/dist/core/ask-origin.d.ts +23 -3
- package/dist/core/ask-origin.js +11 -1
- package/dist/core/engine-notice.d.ts +3 -3
- package/dist/core/governance-codes.js +1 -0
- package/dist/core/human-input-projection.d.ts +9 -0
- package/dist/core/human-input-projection.js +13 -0
- package/dist/core/input-author.d.ts +66 -6
- package/dist/core/input-author.js +21 -3
- package/dist/core/memory-engine/consolidation.d.ts +23 -9
- package/dist/core/memory-engine/consolidation.js +30 -5
- package/dist/core/memory-engine/control-plane-adoption.d.ts +11 -10
- package/dist/core/memory-engine/control-plane-adoption.js +54 -29
- package/dist/core/memory-engine/delegation-settlement.d.ts +18 -12
- package/dist/core/memory-engine/delegation-settlement.js +36 -26
- package/dist/core/memory-engine/engine.d.ts +17 -6
- package/dist/core/memory-engine/engine.js +78 -35
- package/dist/core/memory-engine/file-backend.d.ts +4 -1
- package/dist/core/memory-engine/file-backend.js +5 -1
- package/dist/core/memory-engine/index.d.ts +2 -2
- package/dist/core/memory-engine/index.js +2 -2
- package/dist/core/memory-engine/layout.d.ts +57 -36
- package/dist/core/memory-engine/layout.js +109 -134
- package/dist/core/memory-engine/memory-backend-contract.js +7 -7
- package/dist/core/memory-engine/memory-deployment.d.ts +3 -2
- package/dist/core/memory-engine/memory-deployment.js +6 -3
- package/dist/core/memory-engine/origin-clearance.d.ts +43 -15
- package/dist/core/memory-engine/origin-clearance.js +143 -55
- package/dist/core/model-receipt.d.ts +2 -1
- package/dist/core/model-receipt.js +5 -0
- package/dist/core/mods/dollar.d.ts +12 -0
- package/dist/core/mods/kernel/dispatch.d.ts +3 -1
- package/dist/core/mods/kernel/dispatch.js +5 -2
- package/dist/core/mods/kernel/events.d.ts +3 -1
- package/dist/core/mods/kernel/events.js +2 -2
- package/dist/core/mods/prompt-submit.d.ts +4 -0
- package/dist/core/mods/prompt-submit.js +24 -0
- package/dist/core/mods/stations.d.ts +23 -4
- package/dist/core/mods/stations.js +14 -7
- package/dist/core/retired-host-table-account.d.ts +19 -0
- package/dist/core/retired-host-table-account.js +28 -0
- package/dist/core/retired-tool-name-account.d.ts +60 -0
- package/dist/core/retired-tool-name-account.js +32 -0
- package/dist/core/roles.d.ts +3 -1
- package/dist/core/roles.js +5 -2
- package/dist/core/runner/compact-session.js +2 -1
- package/dist/core/runner/contracts.d.ts +1 -1
- package/dist/core/runner/gate-exit.js +9 -2
- package/dist/core/runner/memory-consolidation-driver.js +2 -2
- package/dist/core/runner/prepare-config-doors.js +1 -1
- package/dist/core/runner/prepare-delegation-surface.d.ts +1 -1
- package/dist/core/runner/prepare-delegation-surface.js +5 -3
- package/dist/core/runner/prepare-inherited-gate.js +2 -0
- package/dist/core/runner/prepare-memory.js +26 -5
- package/dist/core/runner/prepare-policy-chain.js +2 -1
- package/dist/core/runner/prepare-project-context.js +2 -2
- package/dist/core/runner/prepare-task.d.ts +5 -1
- package/dist/core/runner/prepare-task.js +4 -3
- package/dist/core/runner/prepare-wiring-manifest.js +5 -4
- package/dist/core/runner/prompt-suggestions.js +1 -1
- package/dist/core/runner/run-identity-wiring.js +2 -2
- package/dist/core/runner/run-leg.js +3 -3
- package/dist/core/runner/run-notification-lane.d.ts +3 -0
- package/dist/core/runner/run-notification-lane.js +2 -2
- package/dist/core/runner/runtask.js +6 -3
- package/dist/core/runner/steer-admission.d.ts +11 -2
- package/dist/core/runner/stream-steer-verb.d.ts +5 -2
- package/dist/core/runner/stream-steer-verb.js +67 -14
- package/dist/core/runner/sub-agent-deny-lists.d.ts +8 -27
- package/dist/core/runner/sub-agent-deny-lists.js +22 -33
- package/dist/core/runner-deps.d.ts +4 -4
- package/dist/core/shell-run-candidates.js +3 -3
- package/dist/core/side-query.js +1 -1
- package/dist/core/skill-grant.d.ts +7 -0
- package/dist/core/skill-grant.js +14 -5
- package/dist/core/task-event.d.ts +14 -0
- package/dist/core/tool-policy.js +2 -3
- package/dist/core/tool-spec.d.ts +13 -3
- package/dist/core/user-attachment.d.ts +5 -1
- package/dist/core/user-attachment.js +11 -5
- package/dist/engine/harness/agent-harness.d.ts +19 -11
- package/dist/engine/harness/agent-harness.js +7 -4
- package/dist/engine/llm/types.d.ts +22 -10
- package/dist/index.d.ts +4 -2
- package/dist/index.js +3 -1
- package/dist/shell/lex.d.ts +50 -15
- package/dist/shell/lex.js +43 -9
- package/dist/tools/fs/fs-bash.js +3 -3
- package/dist/tools/fs/removal-targets.d.ts +8 -2
- package/dist/tools/fs/removal-targets.js +31 -4
- package/dist/tools/fs/shell-read-argv.js +7 -1
- package/dist/tools/fs/shell-read-bindings.d.ts +21 -5
- package/dist/tools/fs/shell-read-bindings.js +130 -44
- package/dist/tools/fs/shell-read-plan.js +95 -29
- package/dist/tools/fs/shell-read-sourced.d.ts +25 -0
- package/dist/tools/fs/shell-read-sourced.js +119 -0
- package/dist/tools/fs/shell-read-word.d.ts +2 -2
- package/dist/tools/fs/shell-read-word.js +4 -5
- package/dist/tools/fs/shell-read-workdir.d.ts +19 -3
- package/dist/tools/fs/shell-read-workdir.js +60 -15
- package/dist/tools/fs/shell-reentry-text.d.ts +10 -2
- package/dist/tools/fs/shell-reentry-text.js +11 -4
- package/package.json +2 -2
- package/test/export-surface.snapshot.json +13 -7
- package/wire-changes/core-stores-sql@7.66.0.json +30 -0
- package/wire-changes/core@7.66.0.json +1218 -0
- package/wire-changes/mods-kernel@7.66.0.json +65 -0
- package/wire-changes/primitives@7.66.0.json +30 -0
|
@@ -4,13 +4,13 @@ export { MEMORY_EXPOSURE_BANNER, MEMORY_EXPOSURE_HANDLE_TAG, MEMORY_PROVENANCE_R
|
|
|
4
4
|
export { scanMemoryWrite, scanMemoryFileName, scanRemediation, MEMORY_FILENAME_SEGMENT_RE } from "./scan.js";
|
|
5
5
|
export { FileMemoryEngineBackend, readMemoryLedgerForm, scanEntryFiles, MEMORY_INDEX_FILENAME, DEFAULT_MAX_ENTRY_DEPTH, erasureSelectHash, } from "./file-backend.js";
|
|
6
6
|
export { computeBundleSectionHashes, computeMemoryBundleHash, memoryBundleInvalid, } from "./export-bundle.js";
|
|
7
|
-
export { ControlPlaneCorruptError, deriveControlPlaneDir, deriveRepoControlPlaneDir, deriveRepoKey, deriveRepoMemoryDir, deriveProjectMemoryDir, deriveProjectControlDir, recordProjectIdHint, lookupProjectIdHint, PROJECT_ID_HINTS_FILE, resolveMemoryEngineRoot, scopeDirFor, scopeDirName, scopeRegistryShape, layoutNeedsAdoption, adoptRootScopeLayout, v1MemoryPathKeyResolver, unresolvedProjectionDebts, scanFuseKey, enqueueMemoryAnnouncement, drainMemoryAnnouncements, peekMemoryAnnouncements, bumpScanFuse, scanFuseCount, clearScanFuse, ANNOUNCEMENTS_FILE, MEMORY_ANNOUNCEMENTS_MAX, SCAN_FUSE_FILE, SCAN_FUSE_THRESHOLD, LINEAGE_FILE, CHALLENGES_FILE, CHALLENGED_HISTORY_FILE, CHALLENGE_LEDGER_MAX_EVENTS, rebuildStrictControlPlaneLedger, SESSION_CAPTURE_OPTOUT_DIR,
|
|
7
|
+
export { ControlPlaneCorruptError, deriveControlPlaneDir, deriveRepoControlPlaneDir, deriveRepoKey, deriveRepoMemoryDir, deriveProjectMemoryDir, deriveProjectControlDir, recordProjectIdHint, lookupProjectIdHint, PROJECT_ID_HINTS_FILE, resolveMemoryEngineRoot, scopeDirFor, scopeDirName, scopeRegistryShape, layoutNeedsAdoption, adoptRootScopeLayout, v1MemoryPathKeyResolver, unresolvedProjectionDebts, scanFuseKey, enqueueMemoryAnnouncement, drainMemoryAnnouncements, peekMemoryAnnouncements, bumpScanFuse, scanFuseCount, clearScanFuse, ANNOUNCEMENTS_FILE, MEMORY_ANNOUNCEMENTS_MAX, SCAN_FUSE_FILE, SCAN_FUSE_THRESHOLD, LINEAGE_FILE, CHALLENGES_FILE, CHALLENGED_HISTORY_FILE, CHALLENGE_LEDGER_MAX_EVENTS, rebuildStrictControlPlaneLedger, SESSION_CAPTURE_OPTOUT_DIR, } from "./layout.js";
|
|
8
8
|
export { readV2HeaderHints, isInstructionEntry } from "./header-hints.js";
|
|
9
9
|
export { parseEntryFile, serializeEntryFile, computeEntryRev, entryFromFile, committedOriginOf, originEquals, ambiguousOriginRepresentation } from "./frontmatter.js";
|
|
10
10
|
export { consolidationExposedFrontmatter } from "./frontmatter.js";
|
|
11
11
|
export { committedDistilledOf, distilledEquals } from "./frontmatter.js";
|
|
12
12
|
export { deriveShadowedSet } from "./shadowing.js";
|
|
13
|
-
export { CONSOLIDATION_DEFAULTS, ConsolidationRefusedError, MEMORY_SEARCH_SUPERSEDED_TAG, consolidationTypeEligible, deriveSupersededSet, memorySupersededNote, supersessionFuseCeiling, DELETION_FUSE_FLOOR, fileGovernanceStore, memoryGovernanceDurability, CONSOLIDATION_RUN_STOP_REASONS, } from "./consolidation.js";
|
|
13
|
+
export { CONSOLIDATION_DEFAULTS, ConsolidationRefusedError, MEMORY_SEARCH_SUPERSEDED_TAG, consolidationTypeEligible, deriveSupersededSet, memorySupersededNote, supersessionFuseCeiling, DELETION_FUSE_FLOOR, fileGovernanceStore, fileSessionCaptureRecordStore, memoryGovernanceDurability, CONSOLIDATION_RUN_STOP_REASONS, } from "./consolidation.js";
|
|
14
14
|
export { DISTILLER_DEFAULT_MAX_INPUTS_PER_PRODUCT, LLM_DISTILLER_CONTRACT, LLM_DISTILLER_CONTRACT_DL2, LLM_DISTILLER_CONTRACT_DL3, LLM_DISTILLER_CONTRACTS, MEMORY_DISTILLER_CONTRACT_V1, contractGroupingDiff, driveConsolidationToFixpoint, isAliasModelId, llmPlanDistiller, mintExposurePartitionedPlan, mintLlmConsolidationPlan, MEMORY_DISTILLER_PURITY_CONTRACT_V1, detectCleanArmVerbatimLeak, openAiCompatChatSeat, parseJsonAnswer, planParseRepairs, sanitizeLlmGroups, scheduleUnderFuse, } from "./distiller.js";
|
|
15
15
|
export { CONSOLIDATION_WRITE_REFUSED_CODE, runMemoryConsolidationDriver, } from "./consolidation-driver.js";
|
|
16
16
|
export { MEMORY_CONTROL_OBJECT_KINDS, MEMORY_GOVERNANCE_DOC_NAMES, MEMORY_ORIGIN_CAUSES, writableRootOf } from "./types.js";
|
|
@@ -279,9 +279,9 @@ export declare const canonicalize: typeof physicalPathOfExisting;
|
|
|
279
279
|
/** True iff `child` (canonicalized) is `root` or inside it. */
|
|
280
280
|
export declare function isContainedIn(root: string, child: string): boolean;
|
|
281
281
|
/** The codes the store's physical form refuses an act with — the whole family, one closed set: {@link TARGET_OUTSIDE_STORE},
|
|
282
|
-
* {@link SCOPE_HOME_NOT_DIRECTORY} and {@link
|
|
282
|
+
* {@link SCOPE_HOME_NOT_DIRECTORY}, {@link CONTROL_PLANE_LINKS_UNSUPPORTED} and {@link CONTROL_PLANE_STRAYS}. Each is a plain `Error` carrying `code` and a
|
|
283
283
|
* `detail` ({@link StoreFormRefusalDetail}). */
|
|
284
|
-
export declare const STORE_FORM_REFUSAL_CODES: readonly ["memory.target_outside_store", "memory.scope_home_not_directory", "memory.control_plane_links_unsupported"];
|
|
284
|
+
export declare const STORE_FORM_REFUSAL_CODES: readonly ["memory.target_outside_store", "memory.scope_home_not_directory", "memory.control_plane_links_unsupported", "memory.control_plane_strays"];
|
|
285
285
|
export type StoreFormRefusalCode = (typeof STORE_FORM_REFUSAL_CODES)[number];
|
|
286
286
|
/** The code an act on a store path is refused with when it would land outside the store ({@link landsOutsideStore}). */
|
|
287
287
|
export declare const TARGET_OUTSIDE_STORE = "memory.target_outside_store";
|
|
@@ -290,6 +290,10 @@ export declare const SCOPE_HOME_NOT_DIRECTORY = "memory.scope_home_not_directory
|
|
|
290
290
|
/** The code a File governance store's open is refused with when its control plane's file system cannot make a hard link
|
|
291
291
|
* (`probeControlPlaneLinks`, `control-objects.ts`; #3512). */
|
|
292
292
|
export declare const CONTROL_PLANE_LINKS_UNSUPPORTED = "memory.control_plane_links_unsupported";
|
|
293
|
+
/** The code an engine's construction is refused with when its backend carries a governance store that is not the File
|
|
294
|
+
* store over the engine's own control plane, and that control plane still holds carrier records (`controlPlaneStraysRefusal`;
|
|
295
|
+
* #3484, C-R1119 HB-5): records nobody reads would launder what they recorded, so they are adopted first. */
|
|
296
|
+
export declare const CONTROL_PLANE_STRAYS = "memory.control_plane_strays";
|
|
293
297
|
/** What a scope home can be besides a real directory (an `lstat` verdict). */
|
|
294
298
|
export declare const SCOPE_HOME_FORMS: readonly ["symlink", "file", "other"];
|
|
295
299
|
export type ScopeHomeForm = (typeof SCOPE_HOME_FORMS)[number];
|
|
@@ -344,6 +348,14 @@ export declare function scopeHomeRefusal(form: ScopeHomeForm, path: string): Sto
|
|
|
344
348
|
/** Seat 4 — the control plane at `path` is on a file system that refused a hard link (`fault`: the error code `link`
|
|
345
349
|
* answered, when it named one). The store publishes every control object with `link`, so it is not opened there. */
|
|
346
350
|
export declare function controlPlaneLinksRefusal(path: string, fault: string | undefined): StoreFormRefusal;
|
|
351
|
+
/** Seat 5 — an engine whose backend carries a governance store of its own over a control plane (`path`) that still holds
|
|
352
|
+
* that carrier's records from before (`strays`: the documents, and the count of entries per object kind): the engine
|
|
353
|
+
* reads its records through the carrier, so these would be read by nobody — a pollution marker, a hold, a capture
|
|
354
|
+
* opt-out nobody reads launders what it recorded. Not opened; the remedy is the explicit adoption. */
|
|
355
|
+
export declare function controlPlaneStraysRefusal(path: string, strays: {
|
|
356
|
+
readonly docs: readonly string[];
|
|
357
|
+
readonly objects: Readonly<Record<string, number>>;
|
|
358
|
+
}): StoreFormRefusal;
|
|
347
359
|
/** Where an act at `p` lands: the physical path of its normalized spelling (the spelling a child path
|
|
348
360
|
* joined under it carries), a MISSING tail rejoined under the deepest existing directory (what the act
|
|
349
361
|
* creates) — a dangling link on that tail followed to where it points (what the act would create through
|
|
@@ -729,7 +741,7 @@ export declare const LOCK_TOMB_INFIX = ".stale-";
|
|
|
729
741
|
* Nothing is matched at another depth or by another pattern: a record's name may begin with these spellings (a
|
|
730
742
|
* capture opt-out record is named after its session id, and `.tmp-x` is a session id), so a pattern below the top
|
|
731
743
|
* level would hide it. The anchor, the registry and its journal are artifacts as an open or a read leaves them, whole
|
|
732
|
-
* ({@link
|
|
744
|
+
* ({@link namedArtifactFault}). The list is a promise a host's assertions read: a change to it carries its reason with it.
|
|
733
745
|
*/
|
|
734
746
|
export declare const STORE_OPEN_ARTIFACTS: Readonly<{
|
|
735
747
|
files: readonly string[];
|
|
@@ -748,10 +760,18 @@ export declare function isStoreOpenArtifact(where: "control" | "memory", rel: re
|
|
|
748
760
|
* be read — any failure but absence; a link that leads nowhere, at it or above it, is no absence — counts as holding
|
|
749
761
|
* one: a store may be there, and opening it says what is; so does a named artifact that stands but cannot be read as
|
|
750
762
|
* what it is (the root anchor, the scope registry or its journal that is a link, not a regular file, unreadable, not
|
|
751
|
-
* JSON or out of shape — an open or a read leaves them whole; see {@link
|
|
763
|
+
* JSON or out of shape — an open or a read leaves them whole; see {@link namedArtifactFault}). Read from the disk at each call. This answers "does a store live on this mount"; whether a root must stay guarded
|
|
752
764
|
* by its anchor is {@link controlPlaneHoldsStore}'s question.
|
|
753
765
|
*/
|
|
754
766
|
export declare function storeHoldsRecord(memoryDir: string, controlDir: string): boolean;
|
|
767
|
+
/**
|
|
768
|
+
* The first fault among a File store's named artifacts ({@link STORE_OPEN_ARTIFACTS}`.files`), or `undefined`: the one answer
|
|
769
|
+
* {@link storeHoldsRecord} counts a mount as holding a store by and an open of that mount refuses by. A mount in a deployment's
|
|
770
|
+
* store set because its anchor, registry or journal cannot be read is opened as one fault — the same for the anchor (which the
|
|
771
|
+
* store's constructor already refuses) and for the registry (which only a first read refuses): one reading of "damaged", one
|
|
772
|
+
* loudness.
|
|
773
|
+
*/
|
|
774
|
+
export declare function storeOpenArtifactFault(memoryDir: string, controlDir: string): ControlPlaneCorruptError | undefined;
|
|
755
775
|
/** S2-B — the File governance store's file for the `announcements` document (the queued memory-change
|
|
756
776
|
* announcements, drained at session-first inject): one file, one bounded queue PER SCOPE inside it (see
|
|
757
777
|
* {@link enqueueMemoryAnnouncement}). */
|
|
@@ -904,6 +924,8 @@ export declare function scanFuseCount(controlDir: string, key: string): number;
|
|
|
904
924
|
export declare function sessionRecordBindsIncarnation(recorded: string | undefined, asking: string | undefined): boolean;
|
|
905
925
|
/** The incarnation this layer ACTS on: an unusable token is the unnamed occupant, never a throw. */
|
|
906
926
|
export declare function usableSessionIncarnation(raw: string | undefined): string | undefined;
|
|
927
|
+
/** The control objects one session record kind is kept through (`pollution`, `capture`). */
|
|
928
|
+
type SessionRecordObjects = Pick<import("./types.js").MemoryGovernanceObjects, "putObject" | "getObject" | "listObjects">;
|
|
907
929
|
/** How a per-session record read names the identity reading; absent ⇒ every record binds. */
|
|
908
930
|
export interface SessionIdentityRead {
|
|
909
931
|
incarnation?: string;
|
|
@@ -977,39 +999,44 @@ export interface SessionCaptureOptOutRecord {
|
|
|
977
999
|
* ADDITIVE: absent ⇒ binds every occupant, which is also where a carrier that drops it lands. */
|
|
978
1000
|
incarnation?: string;
|
|
979
1001
|
}
|
|
980
|
-
/** Outcome vocabulary shared with the pollution marker (same
|
|
1002
|
+
/** Outcome vocabulary shared with the pollution marker (the same one-way form, written once): `"created"` ⇔ THIS
|
|
981
1003
|
* call minted the record; `"existed"` ⇔ already recorded (a resumed session / an idempotent
|
|
982
1004
|
* re-declaration); `"unpersisted"` ⇔ the record could not be written — the CALLER must refuse to
|
|
983
1005
|
* run (design/383 §2.8: an opt-out that only holds in-process is broken by the first resume, so
|
|
984
1006
|
* "could not persist" is a named refusal, never a silent in-process-only degrade — the deliberate
|
|
985
1007
|
* divergence from the pollution marker's best-effort arm). */
|
|
986
1008
|
export type SessionCaptureOptOutMarkOutcome = "created" | "existed" | "unpersisted";
|
|
987
|
-
/**
|
|
988
|
-
*
|
|
989
|
-
*
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
*
|
|
994
|
-
*
|
|
995
|
-
*
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
1009
|
+
/** The part of a governance store the capture opt-out records are kept through: its control objects of kind `capture`,
|
|
1010
|
+
* one per record slot ({@link sessionRecordName}). A reader that must tell a record that stands unreadable from a store
|
|
1011
|
+
* that cannot answer hands in the store's damage-visible view (`standingControlObjectsOf`, `consolidation.ts`): its
|
|
1012
|
+
* listing names every entry standing where a record belongs. */
|
|
1013
|
+
export type SessionCaptureObjects = SessionRecordObjects;
|
|
1014
|
+
/** Mark `sessionId` capture-opted-out (idempotent; the FIRST record wins — the object is written once, never replaced).
|
|
1015
|
+
* Incarnation law: first-record-wins is per IDENTITY — a new occupant whose declaration meets a stranger's standing
|
|
1016
|
+
* record mints its own slot instead of answering `"existed"` ({@link sessionRecordName}). Never throws: a record that
|
|
1017
|
+
* cannot be written, or a slot that stands as no readable object, answers `"unpersisted"` (the caller refuses to run). */
|
|
1018
|
+
export declare function markSessionCaptureObjects(objects: SessionCaptureObjects, sessionId: string, record: SessionCaptureOptOutRecord): Promise<SessionCaptureOptOutMarkOutcome>;
|
|
1019
|
+
/** Read the durable capture opt-out record for `sessionId` (undefined = capture is on). Fail-closed exactly like the
|
|
1020
|
+
* pollution read: a record that STANDS but cannot be read or parsed answers opted-out (a synthesized record stands in).
|
|
1021
|
+
* Only ABSENCE reads as "capture on". A store that cannot establish whether a record exists THROWS — the engine's
|
|
1022
|
+
* `sessionCaptureOptOutOrFault` catch turns it into the INDETERMINATE fault axis (the same fail-closed suppression,
|
|
1023
|
+
* honestly attributed: an outage is never reported as a user request). `objects` is the damage-visible view. */
|
|
1024
|
+
export declare function readSessionCaptureObjects(objects: SessionCaptureObjects, sessionId: string, identity?: SessionIdentityRead): Promise<SessionCaptureOptOutRecord | undefined>;
|
|
999
1025
|
/**
|
|
1000
|
-
* Enumerate EVERY durable capture opt-out record (the consolidation eligibility arm's roster read —
|
|
1001
|
-
*
|
|
1002
|
-
*
|
|
1003
|
-
*
|
|
1004
|
-
* dropped records would let the distiller amplify content its author asked to withhold.
|
|
1026
|
+
* Enumerate EVERY durable capture opt-out record (the consolidation eligibility arm's roster read — design/383 §2.4).
|
|
1027
|
+
* Same fail-closed posture as {@link listSessionPollution}: a record that stands but cannot be read answers synthesized
|
|
1028
|
+
* (never silently omitted); a kind with no objects is the genuine empty state; an enumeration failure THROWS — a listing
|
|
1029
|
+
* that silently dropped records would let the distiller amplify content its author asked to withhold.
|
|
1005
1030
|
*/
|
|
1006
|
-
export declare function
|
|
1031
|
+
export declare function listSessionCaptureObjects(objects: SessionCaptureObjects): Promise<Record<string, SessionCaptureOptOutRecord>>;
|
|
1007
1032
|
/**
|
|
1008
1033
|
* design/383 §2.1b — the control-plane carrier a HOST may substitute for the capture opt-out
|
|
1009
1034
|
* record's read/write/list (server F1: on a stateless multi-replica deployment the file form is
|
|
1010
1035
|
* invisible to the resume replica — "record not found" would break exactly toward capture). The
|
|
1011
|
-
* core default is the
|
|
1012
|
-
*
|
|
1036
|
+
* core default (#3484) is the `capture` objects of the governance store the engine keeps its documents
|
|
1037
|
+
* in (`governanceCaptureRecordStore`, `consolidation.ts`): the File store's directory — byte-identical
|
|
1038
|
+
* names and bytes — or the store the backend carries, the same for every replica that opens it.
|
|
1039
|
+
* CONTRACT (each leg mirrors the objects' law above):
|
|
1013
1040
|
* - `mark` is create-only/first-record-wins and must answer `"unpersisted"` (never throw) when the
|
|
1014
1041
|
* carrier cannot durably land the record;
|
|
1015
1042
|
* - `read` is fail-closed: a record that exists but cannot be decoded answers a synthesized
|
|
@@ -1019,20 +1046,12 @@ export declare function listSessionCaptureOptOut(controlDir: string): Record<str
|
|
|
1019
1046
|
* record ("a user request that never happened") and must not answer `undefined` ("no record"
|
|
1020
1047
|
* breaks exactly toward capture);
|
|
1021
1048
|
* - `list` throws on an enumeration failure (an unreadable roster is not an empty one).
|
|
1022
|
-
* REGISTERED COMPANION (named, not silently absent): the session-POLLUTION marker has the same
|
|
1023
|
-
* cloud-form invisibility (server F1 names both). It is NOT routed through this seat in this
|
|
1024
|
-
* slice because the delegation-settlement lane's consumers are contractually PURE-DATA
|
|
1025
|
-
* (`controlDir` + `sessionId` coordinates that outlive any live object — see the settlement handle
|
|
1026
|
-
* doc in prepare-task.ts), and a live store object cannot ride that lane; its migration needs its
|
|
1027
|
-
* own seam design and is registered here rather than half-built.
|
|
1028
|
-
*
|
|
1029
1049
|
* DUAL FORM (#511 件2, additive): each leg may answer `T` OR `Promise<T>` — a SQL/remote carrier is
|
|
1030
1050
|
* async by nature and could not implement the sync-only trio at all. Every core consumption point
|
|
1031
1051
|
* awaits (or `.then`-chains where a sync public seat must stay sync-transparent), so a sync store's
|
|
1032
1052
|
* behavior is unchanged and an async store's Promise legs keep the exact same contract per leg:
|
|
1033
1053
|
* a rejected `mark` promise is held to the `"unpersisted"` refusal arm, a rejected `read` promise
|
|
1034
1054
|
* is the INDETERMINATE fault axis, a rejected `list` promise propagates as the enumeration failure.
|
|
1035
|
-
* The File trio below keeps its synchronous signatures byte-identical.
|
|
1036
1055
|
*/
|
|
1037
1056
|
export interface SessionCaptureRecordStore {
|
|
1038
1057
|
mark(sessionId: string, record: SessionCaptureOptOutRecord): SessionCaptureOptOutMarkOutcome | Promise<SessionCaptureOptOutMarkOutcome>;
|
|
@@ -1042,9 +1061,6 @@ export interface SessionCaptureRecordStore {
|
|
|
1042
1061
|
read(sessionId: string, identity?: SessionIdentityRead): SessionCaptureOptOutRecord | undefined | Promise<SessionCaptureOptOutRecord | undefined>;
|
|
1043
1062
|
list(): Record<string, SessionCaptureOptOutRecord> | Promise<Record<string, SessionCaptureOptOutRecord>>;
|
|
1044
1063
|
}
|
|
1045
|
-
/** The core-default {@link SessionCaptureRecordStore}: the file trio over `controlDir` (single-
|
|
1046
|
-
* process / single-host deployments keep today's carrier byte-identical). */
|
|
1047
|
-
export declare function fileSessionCaptureRecordStore(controlDir: string): SessionCaptureRecordStore;
|
|
1048
1064
|
/** The retrieved-account sidecar (control plane): entry id → { count, lastAt }. */
|
|
1049
1065
|
export declare const USAGE_RETRIEVED_FILE = "usage-retrieved.json";
|
|
1050
1066
|
/** Bound on tracked ids — over the cap, the entries with the OLDEST `lastAt` are evicted first
|
|
@@ -1095,6 +1111,11 @@ export declare function lockedStrictUpdate<S, T>(controlDir: string, fileName: s
|
|
|
1095
1111
|
next?: S;
|
|
1096
1112
|
result: T;
|
|
1097
1113
|
}): T;
|
|
1114
|
+
/** Remove a fail-closed sidecar under its lock (a journal rolls forward first) when `removable` answers `true` for its
|
|
1115
|
+
* committed value — the delete half of handing a document over to another store (#3484: the control-plane adoption
|
|
1116
|
+
* removes the replica's copy once the carrier holds the same value). Answers `"removed"`, `"absent"` (nothing stood)
|
|
1117
|
+
* or `"kept"` (`removable` refused the value). Same lock and ownership fence as {@link lockedStrictUpdate}. */
|
|
1118
|
+
export declare function lockedStrictRemove(controlDir: string, fileName: string, what: string, removable: (committed: unknown) => boolean): "removed" | "absent" | "kept";
|
|
1098
1119
|
/** Lock-less strict READ (journal-aware): a parseable journal wins (committed next state); an
|
|
1099
1120
|
* unparseable journal, or an unreadable/unparseable file, is corrupt. Exported module-level for
|
|
1100
1121
|
* the strict-account family's siblings (see {@link lockedStrictUpdate}). */
|
|
@@ -749,10 +749,11 @@ export function isContainedIn(root, child) {
|
|
|
749
749
|
const c = canonicalize(child);
|
|
750
750
|
return c === r || c.startsWith(`${r}${sep}`);
|
|
751
751
|
}
|
|
752
|
-
export const STORE_FORM_REFUSAL_CODES = Object.freeze(["memory.target_outside_store", "memory.scope_home_not_directory", "memory.control_plane_links_unsupported"]);
|
|
752
|
+
export const STORE_FORM_REFUSAL_CODES = Object.freeze(["memory.target_outside_store", "memory.scope_home_not_directory", "memory.control_plane_links_unsupported", "memory.control_plane_strays"]);
|
|
753
753
|
export const TARGET_OUTSIDE_STORE = "memory.target_outside_store";
|
|
754
754
|
export const SCOPE_HOME_NOT_DIRECTORY = "memory.scope_home_not_directory";
|
|
755
755
|
export const CONTROL_PLANE_LINKS_UNSUPPORTED = "memory.control_plane_links_unsupported";
|
|
756
|
+
export const CONTROL_PLANE_STRAYS = "memory.control_plane_strays";
|
|
756
757
|
export const SCOPE_HOME_FORMS = Object.freeze(["symlink", "file", "other"]);
|
|
757
758
|
const SCOPE_HOME_FORM_PHRASE = {
|
|
758
759
|
symlink: "a symbolic link",
|
|
@@ -780,6 +781,10 @@ export function scopeHomeRefusal(form, path) {
|
|
|
780
781
|
export function controlPlaneLinksRefusal(path, fault) {
|
|
781
782
|
return storeFormRefusal(CONTROL_PLANE_LINKS_UNSUPPORTED, `the memory control plane is on a file system that cannot make hard links (link answered ${fault ?? "an error with no code"}) — the store publishes its control objects (quarantine copies, held files, pollution markers) with link, so it is not opened and no entry or control object was written; move the control plane (controlDir, or the memory engine root) to a volume that supports hard links`, { path });
|
|
782
783
|
}
|
|
784
|
+
export function controlPlaneStraysRefusal(path, strays) {
|
|
785
|
+
const named = [...strays.docs.map((d) => `the ${d} document`), ...Object.entries(strays.objects).map(([kind, n]) => `${n} ${kind} entr${n === 1 ? "y" : "ies"}`)];
|
|
786
|
+
return storeFormRefusal(CONTROL_PLANE_STRAYS, `the memory backend carries its own governance store, and the engine's control plane still holds that store's records from before (${named.join(", ")}) — they would be read by nobody, so the engine is not opened and nothing was written; adopt them into the carrier first (adoptReplicaControlPlane(detail.path, <the backend's governance store>), which removes each one it hands over), then reopen`, { path });
|
|
787
|
+
}
|
|
783
788
|
export function landingPathOf(p) {
|
|
784
789
|
return landingPathWithin(resolve(p), 0);
|
|
785
790
|
}
|
|
@@ -1491,24 +1496,33 @@ function isLockTreeName(name) {
|
|
|
1491
1496
|
return STORE_OPEN_ARTIFACTS.lockDirs.some((lock) => name === lock || name.startsWith(`${lock}${LOCK_TOMB_INFIX}`));
|
|
1492
1497
|
}
|
|
1493
1498
|
export function storeHoldsRecord(memoryDir, controlDir) {
|
|
1494
|
-
return treeHoldsRecord(controlDir, "control", (name) =>
|
|
1499
|
+
return treeHoldsRecord(controlDir, "control", (name) => namedArtifactFault(memoryDir, controlDir, name) !== undefined) || treeHoldsRecord(memoryDir, "memory");
|
|
1495
1500
|
}
|
|
1496
|
-
function
|
|
1501
|
+
function namedArtifactFault(memoryDir, controlDir, name) {
|
|
1497
1502
|
try {
|
|
1498
1503
|
if (name === ROOT_ANCHOR_FILE)
|
|
1499
1504
|
readStoreRootAnchor(controlDir, memoryDir);
|
|
1500
1505
|
else if (name === SCOPES_FILE || name === `${SCOPES_FILE}.journal`) {
|
|
1501
|
-
for (const file of [`${SCOPES_FILE}.journal`, SCOPES_FILE])
|
|
1506
|
+
for (const file of [`${SCOPES_FILE}.journal`, SCOPES_FILE]) {
|
|
1502
1507
|
if (!absentOrRegularFile(join(controlDir, file)))
|
|
1503
|
-
return
|
|
1508
|
+
return new ControlPlaneCorruptError(`memory store file ${join(controlDir, file)} is no regular file the scope registry can be read from (a pipe, a device, a directory, or a link that leads nowhere) — the store's registry cannot be checked, so nothing in the store was opened`);
|
|
1509
|
+
}
|
|
1504
1510
|
readScopesRecord(controlDir);
|
|
1505
1511
|
}
|
|
1506
|
-
return
|
|
1512
|
+
return undefined;
|
|
1507
1513
|
}
|
|
1508
|
-
catch {
|
|
1509
|
-
return
|
|
1514
|
+
catch (err) {
|
|
1515
|
+
return err instanceof ControlPlaneCorruptError ? err : new ControlPlaneCorruptError(`memory store artifact ${name} could not be read (${err.code ?? thrownLabel(err)}): ${thrownText(err)}`, { cause: err });
|
|
1510
1516
|
}
|
|
1511
1517
|
}
|
|
1518
|
+
export function storeOpenArtifactFault(memoryDir, controlDir) {
|
|
1519
|
+
for (const name of STORE_OPEN_ARTIFACTS.files) {
|
|
1520
|
+
const fault = namedArtifactFault(memoryDir, controlDir, name);
|
|
1521
|
+
if (fault !== undefined)
|
|
1522
|
+
return fault;
|
|
1523
|
+
}
|
|
1524
|
+
return undefined;
|
|
1525
|
+
}
|
|
1512
1526
|
function absentOrRegularFile(path) {
|
|
1513
1527
|
const entry = lstatOrAbsent(path);
|
|
1514
1528
|
if (entry === undefined)
|
|
@@ -2017,63 +2031,48 @@ function isIncarnationSeat(raw) {
|
|
|
2017
2031
|
export function usableSessionIncarnation(raw) {
|
|
2018
2032
|
return isIncarnationSeat(raw) ? raw : undefined;
|
|
2019
2033
|
}
|
|
2020
|
-
function sessionRecordPath(controlDir, dir, sessionId, incarnation) {
|
|
2021
|
-
return join(controlDir, dir, sessionRecordName(sessionId, incarnation));
|
|
2022
|
-
}
|
|
2023
2034
|
function sessionRecordName(sessionId, incarnation) {
|
|
2024
2035
|
return incarnation === undefined ? `${encodeURIComponent(sessionId)}.json` : `${encodeURIComponent(sessionId)}@${encodeURIComponent(incarnation)}.json`;
|
|
2025
2036
|
}
|
|
2026
|
-
function
|
|
2027
|
-
let raw;
|
|
2037
|
+
async function mintSessionRecordObjects(objects, kind, sessionId, incarnation, bytes) {
|
|
2028
2038
|
try {
|
|
2029
|
-
|
|
2039
|
+
if ((await putControlObjectOnce(objects, kind, sessionRecordName(sessionId), bytes)) === "created")
|
|
2040
|
+
return "created";
|
|
2030
2041
|
}
|
|
2031
|
-
catch
|
|
2032
|
-
|
|
2033
|
-
return "unattributable";
|
|
2034
|
-
try {
|
|
2035
|
-
lstatSync(path);
|
|
2036
|
-
}
|
|
2037
|
-
catch {
|
|
2038
|
-
return "unattributable";
|
|
2039
|
-
}
|
|
2040
|
-
return { owner: undefined };
|
|
2042
|
+
catch {
|
|
2043
|
+
return "unpersisted";
|
|
2041
2044
|
}
|
|
2045
|
+
const own = usableSessionIncarnation(incarnation);
|
|
2046
|
+
const standing = await sessionRecordOwnerOf(objects, kind, sessionRecordName(sessionId));
|
|
2047
|
+
const vouches = standing !== "unattributable" && (standing.owner === undefined || standing.owner === own);
|
|
2048
|
+
const unnamed = vouches || own === undefined ? undefined : await sessionRecordOwnerOf(objects, kind, sessionRecordName(sessionId, ""));
|
|
2049
|
+
if (vouches || (unnamed !== undefined && unnamed !== "unattributable" && unnamed.owner === undefined))
|
|
2050
|
+
return "existed";
|
|
2042
2051
|
try {
|
|
2043
|
-
|
|
2044
|
-
if (parsed !== null && typeof parsed === "object")
|
|
2045
|
-
return { owner: readIncarnationSeat(parsed) };
|
|
2052
|
+
return (await putControlObjectOnce(objects, kind, sessionRecordName(sessionId, own ?? ""), bytes)) === "created" ? "created" : "existed";
|
|
2046
2053
|
}
|
|
2047
2054
|
catch {
|
|
2055
|
+
return "unpersisted";
|
|
2048
2056
|
}
|
|
2049
|
-
return "unattributable";
|
|
2050
2057
|
}
|
|
2051
|
-
function
|
|
2052
|
-
|
|
2058
|
+
async function sessionRecordOwnerOf(objects, kind, name) {
|
|
2059
|
+
let bytes;
|
|
2053
2060
|
try {
|
|
2054
|
-
|
|
2055
|
-
writeFileSync(idSlot, text, { encoding: "utf8", flag: "wx" });
|
|
2056
|
-
return "created";
|
|
2061
|
+
bytes = await objects.getObject(kind, name);
|
|
2057
2062
|
}
|
|
2058
|
-
catch
|
|
2059
|
-
|
|
2060
|
-
return "unpersisted";
|
|
2063
|
+
catch {
|
|
2064
|
+
return "unattributable";
|
|
2061
2065
|
}
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
const vouches = standing !== "unattributable" && (standing.owner === undefined || standing.owner === own);
|
|
2065
|
-
const unnamed = vouches || own === undefined ? undefined : standingOwnerAt(sessionRecordPath(controlDir, dir, sessionId, ""));
|
|
2066
|
-
if (vouches || (unnamed !== undefined && unnamed !== "unattributable" && unnamed.owner === undefined))
|
|
2067
|
-
return "existed";
|
|
2066
|
+
if (bytes === undefined)
|
|
2067
|
+
return "unattributable";
|
|
2068
2068
|
try {
|
|
2069
|
-
|
|
2070
|
-
|
|
2069
|
+
const parsed = JSON.parse(new TextDecoder().decode(bytes));
|
|
2070
|
+
if (parsed !== null && typeof parsed === "object")
|
|
2071
|
+
return { owner: readIncarnationSeat(parsed) };
|
|
2071
2072
|
}
|
|
2072
|
-
catch
|
|
2073
|
-
if (err instanceof Error && "code" in err && err.code === "EEXIST")
|
|
2074
|
-
return "existed";
|
|
2075
|
-
return "unpersisted";
|
|
2073
|
+
catch {
|
|
2076
2074
|
}
|
|
2075
|
+
return "unattributable";
|
|
2077
2076
|
}
|
|
2078
2077
|
function bindOrSeparate(record, identity, asking, unknownSlot) {
|
|
2079
2078
|
if (sessionRecordBindsIncarnation(record.incarnation, asking))
|
|
@@ -2100,47 +2099,7 @@ function sessionIdOfRecordName(name) {
|
|
|
2100
2099
|
export const SESSION_POLLUTION_DIR = "session-pollution";
|
|
2101
2100
|
export async function markSessionPolluted(objects, sessionId, reason, now, cause, incarnation) {
|
|
2102
2101
|
const record = { at: now(), reason, ...(cause !== undefined ? { cause } : {}), ...(incarnation !== undefined ? { incarnation } : {}) };
|
|
2103
|
-
return
|
|
2104
|
-
}
|
|
2105
|
-
async function mintPollutionSlots(objects, sessionId, incarnation, bytes) {
|
|
2106
|
-
try {
|
|
2107
|
-
if ((await putControlObjectOnce(objects, "pollution", sessionRecordName(sessionId), bytes)) === "created")
|
|
2108
|
-
return "created";
|
|
2109
|
-
}
|
|
2110
|
-
catch {
|
|
2111
|
-
return "unpersisted";
|
|
2112
|
-
}
|
|
2113
|
-
const own = usableSessionIncarnation(incarnation);
|
|
2114
|
-
const standing = await pollutionOwnerOf(objects, sessionRecordName(sessionId));
|
|
2115
|
-
const vouches = standing !== "unattributable" && (standing.owner === undefined || standing.owner === own);
|
|
2116
|
-
const unnamed = vouches || own === undefined ? undefined : await pollutionOwnerOf(objects, sessionRecordName(sessionId, ""));
|
|
2117
|
-
if (vouches || (unnamed !== undefined && unnamed !== "unattributable" && unnamed.owner === undefined))
|
|
2118
|
-
return "existed";
|
|
2119
|
-
try {
|
|
2120
|
-
return (await putControlObjectOnce(objects, "pollution", sessionRecordName(sessionId, own ?? ""), bytes)) === "created" ? "created" : "existed";
|
|
2121
|
-
}
|
|
2122
|
-
catch {
|
|
2123
|
-
return "unpersisted";
|
|
2124
|
-
}
|
|
2125
|
-
}
|
|
2126
|
-
async function pollutionOwnerOf(objects, name) {
|
|
2127
|
-
let bytes;
|
|
2128
|
-
try {
|
|
2129
|
-
bytes = await objects.getObject("pollution", name);
|
|
2130
|
-
}
|
|
2131
|
-
catch {
|
|
2132
|
-
return "unattributable";
|
|
2133
|
-
}
|
|
2134
|
-
if (bytes === undefined)
|
|
2135
|
-
return "unattributable";
|
|
2136
|
-
try {
|
|
2137
|
-
const parsed = JSON.parse(new TextDecoder().decode(bytes));
|
|
2138
|
-
if (parsed !== null && typeof parsed === "object")
|
|
2139
|
-
return { owner: readIncarnationSeat(parsed) };
|
|
2140
|
-
}
|
|
2141
|
-
catch {
|
|
2142
|
-
}
|
|
2143
|
-
return "unattributable";
|
|
2102
|
+
return mintSessionRecordObjects(objects, "pollution", sessionId, incarnation, new TextEncoder().encode(`${JSON.stringify(record, null, 2)}\n`));
|
|
2144
2103
|
}
|
|
2145
2104
|
export async function readSessionPollution(objects, sessionId, identity) {
|
|
2146
2105
|
const asking = usableSessionIncarnation(identity?.incarnation);
|
|
@@ -2201,51 +2160,53 @@ export async function importSessionPollution(objects, sessionId, record) {
|
|
|
2201
2160
|
return standing !== undefined && standing.at === record.at && standing.reason === record.reason ? "already" : "divergent";
|
|
2202
2161
|
}
|
|
2203
2162
|
export const SESSION_CAPTURE_OPTOUT_DIR = "session-capture-optout";
|
|
2204
|
-
|
|
2205
|
-
|
|
2163
|
+
const UNREADABLE_CAPTURE_RECORD = Object.freeze({ at: 0, reason: "capture opt-out record present but unreadable (kept fail-closed)" });
|
|
2164
|
+
function captureIndeterminate(name, err) {
|
|
2165
|
+
return new ControlPlaneCorruptError(`session capture opt-out record state is INDETERMINATE for ${JSON.stringify(name)} (${thrownText(err)}) — the store cannot establish whether a record exists; consumers must suppress on the fault axis (an outage is never reported as a user request)`, { cause: err });
|
|
2206
2166
|
}
|
|
2207
|
-
export function
|
|
2208
|
-
|
|
2209
|
-
|
|
2167
|
+
export async function markSessionCaptureObjects(objects, sessionId, record) {
|
|
2168
|
+
try {
|
|
2169
|
+
const stored = { at: record.at, reason: record.reason, ...(record.incarnation !== undefined ? { incarnation: record.incarnation } : {}) };
|
|
2170
|
+
return await mintSessionRecordObjects(objects, "capture", sessionId, record.incarnation, new TextEncoder().encode(`${JSON.stringify(stored, null, 2)}\n`));
|
|
2171
|
+
}
|
|
2172
|
+
catch {
|
|
2173
|
+
return "unpersisted";
|
|
2174
|
+
}
|
|
2210
2175
|
}
|
|
2211
|
-
export function
|
|
2176
|
+
export async function readSessionCaptureObjects(objects, sessionId, identity) {
|
|
2212
2177
|
const asking = usableSessionIncarnation(identity?.incarnation);
|
|
2213
2178
|
if (asking !== undefined) {
|
|
2214
|
-
const own =
|
|
2179
|
+
const own = await readCaptureObject(objects, sessionRecordName(sessionId, asking));
|
|
2215
2180
|
if (own !== undefined)
|
|
2216
2181
|
return own;
|
|
2217
2182
|
}
|
|
2218
|
-
const
|
|
2219
|
-
|
|
2220
|
-
|
|
2183
|
+
const standing = await readCaptureObject(objects, sessionRecordName(sessionId));
|
|
2184
|
+
if (standing === undefined)
|
|
2185
|
+
return readCaptureObject(objects, sessionRecordName(sessionId, ""));
|
|
2186
|
+
const unnamed = sessionRecordBindsIncarnation(standing.incarnation, asking) ? undefined : await readCaptureObject(objects, sessionRecordName(sessionId, ""));
|
|
2187
|
+
return bindOrSeparate(standing, identity, asking, () => unnamed);
|
|
2221
2188
|
}
|
|
2222
|
-
function
|
|
2223
|
-
let
|
|
2189
|
+
async function readCaptureObject(objects, name) {
|
|
2190
|
+
let bytes;
|
|
2224
2191
|
try {
|
|
2225
|
-
|
|
2192
|
+
bytes = await objects.getObject("capture", name);
|
|
2226
2193
|
}
|
|
2227
2194
|
catch (err) {
|
|
2228
|
-
|
|
2229
|
-
try {
|
|
2230
|
-
lstatSync(path);
|
|
2231
|
-
}
|
|
2232
|
-
catch (lerr) {
|
|
2233
|
-
if (lerr.code === "ENOENT")
|
|
2234
|
-
return undefined;
|
|
2235
|
-
throw new ControlPlaneCorruptError(`session capture opt-out record state is INDETERMINATE (${lerr.code ?? "io error"}) at ${path} — the store cannot establish whether a record exists; consumers must suppress on the fault axis (an outage is never reported as a user request)`, { cause: lerr });
|
|
2236
|
-
}
|
|
2237
|
-
return { at: 0, reason: "capture opt-out record present but unreadable (kept fail-closed)" };
|
|
2238
|
-
}
|
|
2195
|
+
let standing;
|
|
2239
2196
|
try {
|
|
2240
|
-
|
|
2197
|
+
standing = await objects.listObjects("capture");
|
|
2241
2198
|
}
|
|
2242
|
-
catch {
|
|
2243
|
-
throw
|
|
2199
|
+
catch (lerr) {
|
|
2200
|
+
throw captureIndeterminate(name, lerr);
|
|
2244
2201
|
}
|
|
2245
|
-
|
|
2202
|
+
if (Array.isArray(standing) && standing.includes(name))
|
|
2203
|
+
return UNREADABLE_CAPTURE_RECORD;
|
|
2204
|
+
throw captureIndeterminate(name, err);
|
|
2246
2205
|
}
|
|
2206
|
+
if (bytes === undefined)
|
|
2207
|
+
return undefined;
|
|
2247
2208
|
try {
|
|
2248
|
-
const parsed = JSON.parse(
|
|
2209
|
+
const parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
|
|
2249
2210
|
if (parsed !== null && typeof parsed === "object") {
|
|
2250
2211
|
const at = parsed.at;
|
|
2251
2212
|
const reason = parsed.reason;
|
|
@@ -2256,37 +2217,30 @@ function readCaptureOptOutAt(path) {
|
|
|
2256
2217
|
}
|
|
2257
2218
|
catch {
|
|
2258
2219
|
}
|
|
2259
|
-
return
|
|
2220
|
+
return UNREADABLE_CAPTURE_RECORD;
|
|
2260
2221
|
}
|
|
2261
|
-
export function
|
|
2262
|
-
const dir = join(controlDir, SESSION_CAPTURE_OPTOUT_DIR);
|
|
2222
|
+
export async function listSessionCaptureObjects(objects) {
|
|
2263
2223
|
let names;
|
|
2264
2224
|
try {
|
|
2265
|
-
names =
|
|
2225
|
+
names = await objects.listObjects("capture");
|
|
2266
2226
|
}
|
|
2267
2227
|
catch (err) {
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2228
|
+
throw new ControlPlaneCorruptError(`session capture opt-out records could not be enumerated (${thrownText(err)}) — an enumeration failure is not an empty set (fail-closed)`, { cause: err });
|
|
2229
|
+
}
|
|
2230
|
+
if (!Array.isArray(names) || !Array.from(names).every((n) => typeof n === "string")) {
|
|
2231
|
+
throw new ControlPlaneCorruptError("session capture opt-out records: the store's listing is not a list of names — an enumeration failure is not an empty set (fail-closed)");
|
|
2271
2232
|
}
|
|
2272
2233
|
const out = Object.create(null);
|
|
2273
|
-
for (const name of names.sort()) {
|
|
2234
|
+
for (const name of [...names].sort()) {
|
|
2274
2235
|
const sessionId = sessionIdOfRecordName(name);
|
|
2275
2236
|
if (sessionId === undefined || Object.prototype.hasOwnProperty.call(out, sessionId))
|
|
2276
2237
|
continue;
|
|
2277
|
-
const rec =
|
|
2238
|
+
const rec = await readCaptureObject(objects, name);
|
|
2278
2239
|
if (rec !== undefined)
|
|
2279
2240
|
out[sessionId] = rec;
|
|
2280
2241
|
}
|
|
2281
2242
|
return out;
|
|
2282
2243
|
}
|
|
2283
|
-
export function fileSessionCaptureRecordStore(controlDir) {
|
|
2284
|
-
return {
|
|
2285
|
-
mark: (sessionId, record) => markSessionCaptureOptOut(controlDir, sessionId, record.reason, () => record.at, record.incarnation),
|
|
2286
|
-
read: (sessionId, identity) => readSessionCaptureOptOut(controlDir, sessionId, identity),
|
|
2287
|
-
list: () => listSessionCaptureOptOut(controlDir),
|
|
2288
|
-
};
|
|
2289
|
-
}
|
|
2290
2244
|
export const USAGE_RETRIEVED_FILE = "usage-retrieved.json";
|
|
2291
2245
|
export const USAGE_RETRIEVED_MAX_IDS = 4096;
|
|
2292
2246
|
function coerceRetrievedAccount(raw) {
|
|
@@ -2411,6 +2365,27 @@ export function lockedStrictUpdate(controlDir, fileName, what, coerce, fn) {
|
|
|
2411
2365
|
releaseSidecarLock(lock, token);
|
|
2412
2366
|
}
|
|
2413
2367
|
}
|
|
2368
|
+
export function lockedStrictRemove(controlDir, fileName, what, removable) {
|
|
2369
|
+
const file = join(controlDir, fileName);
|
|
2370
|
+
const journal = `${file}.journal`;
|
|
2371
|
+
const lock = `${file}.lock`;
|
|
2372
|
+
const token = acquireSidecarLock(lock, { onDeadline: "throw" });
|
|
2373
|
+
try {
|
|
2374
|
+
const fence = () => assertSidecarLockOwnership(lock, token, what, "strict");
|
|
2375
|
+
rollForwardStrictSidecar(file, journal, fence);
|
|
2376
|
+
const committed = readStrictSidecarRaw(file, what);
|
|
2377
|
+
if (committed === undefined)
|
|
2378
|
+
return "absent";
|
|
2379
|
+
if (!removable(committed))
|
|
2380
|
+
return "kept";
|
|
2381
|
+
fence();
|
|
2382
|
+
rmSync(file);
|
|
2383
|
+
return "removed";
|
|
2384
|
+
}
|
|
2385
|
+
finally {
|
|
2386
|
+
releaseSidecarLock(lock, token);
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2414
2389
|
function readStrictSidecarRaw(file, what) {
|
|
2415
2390
|
let raw;
|
|
2416
2391
|
try {
|