spexcode 0.6.6 → 0.6.8
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/README.md +12 -7
- package/node_modules/@spexcode/session-application/dist/index.d.ts +17 -0
- package/node_modules/@spexcode/session-application/dist/index.js +35 -0
- package/node_modules/@spexcode/session-application/dist/migration.d.ts +51 -0
- package/node_modules/@spexcode/session-application/dist/migration.js +694 -0
- package/node_modules/@spexcode/session-application/dist/production.d.ts +109 -0
- package/node_modules/@spexcode/session-application/dist/production.js +438 -0
- package/node_modules/@spexcode/session-application/dist/schema.d.ts +2 -0
- package/node_modules/@spexcode/session-application/dist/schema.js +39 -0
- package/node_modules/@spexcode/session-application/package.json +29 -0
- package/node_modules/@spexcode/session-events/dist/errors.d.ts +6 -0
- package/node_modules/@spexcode/session-events/dist/errors.js +11 -0
- package/node_modules/@spexcode/session-events/dist/index.d.ts +46 -0
- package/node_modules/@spexcode/session-events/dist/index.js +245 -0
- package/node_modules/@spexcode/session-events/dist/schema.d.ts +3 -0
- package/node_modules/@spexcode/session-events/dist/schema.js +44 -0
- package/node_modules/@spexcode/session-events/package.json +24 -0
- package/node_modules/@spexcode/session-protocol/dist/canonical.d.ts +36 -0
- package/node_modules/@spexcode/session-protocol/dist/canonical.js +139 -0
- package/node_modules/@spexcode/session-protocol/dist/engine.d.ts +22 -0
- package/node_modules/@spexcode/session-protocol/dist/engine.js +478 -0
- package/node_modules/@spexcode/session-protocol/dist/errors.d.ts +8 -0
- package/node_modules/@spexcode/session-protocol/dist/errors.js +39 -0
- package/node_modules/@spexcode/session-protocol/dist/index.d.ts +60 -0
- package/node_modules/@spexcode/session-protocol/dist/index.js +4 -0
- package/node_modules/@spexcode/session-protocol/dist/schema.d.ts +36 -0
- package/node_modules/@spexcode/session-protocol/dist/schema.js +192 -0
- package/node_modules/@spexcode/{session-core → session-protocol}/package.json +4 -8
- package/node_modules/@spexcode/session-runtime/dist/errors.d.ts +6 -0
- package/node_modules/@spexcode/session-runtime/dist/errors.js +11 -0
- package/node_modules/@spexcode/session-runtime/dist/index.d.ts +33 -0
- package/node_modules/@spexcode/session-runtime/dist/index.js +193 -0
- package/node_modules/@spexcode/session-runtime/dist/schema.d.ts +2 -0
- package/node_modules/@spexcode/session-runtime/dist/schema.js +37 -0
- package/node_modules/@spexcode/session-runtime/package.json +24 -0
- package/node_modules/@spexcode/session-selflaunch/bin/spex-session.mjs +4 -0
- package/node_modules/@spexcode/session-selflaunch/dist/cli.d.ts +25 -0
- package/node_modules/@spexcode/session-selflaunch/dist/cli.js +156 -0
- package/node_modules/@spexcode/session-selflaunch/dist/index.d.ts +28 -0
- package/node_modules/@spexcode/session-selflaunch/dist/index.js +25 -0
- package/node_modules/@spexcode/session-selflaunch/dist/locality.d.ts +20 -0
- package/node_modules/@spexcode/session-selflaunch/dist/locality.js +83 -0
- package/node_modules/@spexcode/session-selflaunch/dist/path.d.ts +13 -0
- package/node_modules/@spexcode/session-selflaunch/dist/path.js +45 -0
- package/node_modules/@spexcode/session-selflaunch/package.json +35 -0
- package/node_modules/@spexcode/session-topology/dist/errors.d.ts +6 -0
- package/node_modules/@spexcode/session-topology/dist/errors.js +11 -0
- package/node_modules/@spexcode/session-topology/dist/index.d.ts +24 -0
- package/node_modules/@spexcode/session-topology/dist/index.js +173 -0
- package/node_modules/@spexcode/session-topology/dist/schema.d.ts +3 -0
- package/node_modules/@spexcode/session-topology/dist/schema.js +27 -0
- package/node_modules/@spexcode/session-topology/package.json +24 -0
- package/node_modules/@spexcode/spec-cli/bin/spex.mjs +56 -19
- package/node_modules/@spexcode/spec-cli/dist/cli.js +102 -59
- package/node_modules/@spexcode/spec-cli/dist/client.d.ts +1 -3
- package/node_modules/@spexcode/spec-cli/dist/client.js +49 -30
- package/node_modules/@spexcode/spec-cli/dist/codex-runtime-generations.d.ts +11 -0
- package/node_modules/@spexcode/spec-cli/dist/codex-runtime-generations.js +46 -9
- package/node_modules/@spexcode/spec-cli/dist/delivery-lock.d.ts +2 -0
- package/node_modules/@spexcode/spec-cli/dist/delivery-lock.js +58 -0
- package/node_modules/@spexcode/spec-cli/dist/doctor.js +53 -11
- package/node_modules/@spexcode/spec-cli/dist/execution-trace.d.ts +1 -0
- package/node_modules/@spexcode/spec-cli/dist/execution-trace.js +2 -2
- package/node_modules/@spexcode/spec-cli/dist/gateway-hub.js +2 -1
- package/node_modules/@spexcode/spec-cli/dist/gateway.js +6 -3
- package/node_modules/@spexcode/spec-cli/dist/graphCache.js +32 -2
- package/node_modules/@spexcode/spec-cli/dist/graphSnapshot.js +57 -2
- package/node_modules/@spexcode/spec-cli/dist/graphStream.d.ts +2 -0
- package/node_modules/@spexcode/spec-cli/dist/graphStream.js +83 -3
- package/node_modules/@spexcode/spec-cli/dist/guide.js +20 -7
- package/node_modules/@spexcode/spec-cli/dist/harness-select.js +16 -3
- package/node_modules/@spexcode/spec-cli/dist/harness.d.ts +15 -3
- package/node_modules/@spexcode/spec-cli/dist/harness.js +331 -50
- package/node_modules/@spexcode/spec-cli/dist/help.js +11 -8
- package/node_modules/@spexcode/spec-cli/dist/hook-prompts.js +8 -0
- package/node_modules/@spexcode/spec-cli/dist/host-resources.js +29 -8
- package/node_modules/@spexcode/spec-cli/dist/host.d.ts +7 -0
- package/node_modules/@spexcode/spec-cli/dist/host.js +93 -0
- package/node_modules/@spexcode/spec-cli/dist/index.js +324 -22
- package/node_modules/@spexcode/spec-cli/dist/init.js +1 -1
- package/node_modules/@spexcode/spec-cli/dist/lint.js +70 -35
- package/node_modules/@spexcode/spec-cli/dist/listen.d.ts +3 -2
- package/node_modules/@spexcode/spec-cli/dist/listen.js +14 -2
- package/node_modules/@spexcode/spec-cli/dist/machine-peer.js +1 -1
- package/node_modules/@spexcode/spec-cli/dist/materialize.d.ts +2 -2
- package/node_modules/@spexcode/spec-cli/dist/materialize.js +176 -35
- package/node_modules/@spexcode/spec-cli/dist/pty-bridge.js +14 -14
- package/node_modules/@spexcode/spec-cli/dist/reviews.js +12 -7
- package/node_modules/@spexcode/spec-cli/dist/runtime-ownership.d.ts +11 -0
- package/node_modules/@spexcode/spec-cli/dist/runtime-ownership.js +79 -1
- package/node_modules/@spexcode/spec-cli/dist/session-application.d.ts +23 -0
- package/node_modules/@spexcode/spec-cli/dist/session-application.js +189 -0
- package/node_modules/@spexcode/spec-cli/dist/session-declarations.js +13 -1
- package/node_modules/@spexcode/spec-cli/dist/session-files.d.ts +6 -0
- package/node_modules/@spexcode/spec-cli/dist/session-files.js +13 -1
- package/node_modules/@spexcode/spec-cli/dist/session-follow.js +39 -22
- package/node_modules/@spexcode/{session-core/dist/record-lock.d.ts → spec-cli/dist/session-record-lock.d.ts} +0 -4
- package/node_modules/@spexcode/spec-cli/dist/session-record-lock.js +94 -0
- package/node_modules/@spexcode/spec-cli/dist/session-runtime-adapter.d.ts +44 -0
- package/node_modules/@spexcode/spec-cli/dist/session-runtime-adapter.js +37 -0
- package/node_modules/@spexcode/spec-cli/dist/session-timeline.d.ts +25 -2
- package/node_modules/@spexcode/spec-cli/dist/session-timeline.js +68 -11
- package/node_modules/@spexcode/spec-cli/dist/session-web.js +4 -4
- package/node_modules/@spexcode/spec-cli/dist/sessions.d.ts +108 -15
- package/node_modules/@spexcode/spec-cli/dist/sessions.js +1465 -744
- package/node_modules/@spexcode/spec-cli/dist/source-list.d.ts +13 -0
- package/node_modules/@spexcode/spec-cli/dist/source-list.js +99 -0
- package/node_modules/@spexcode/spec-cli/dist/source-read.d.ts +16 -0
- package/node_modules/@spexcode/spec-cli/dist/source-read.js +84 -0
- package/node_modules/@spexcode/spec-cli/dist/spec-attachments.d.ts +7 -0
- package/node_modules/@spexcode/spec-cli/dist/spec-attachments.js +89 -0
- package/node_modules/@spexcode/spec-cli/dist/spec-body-edit.d.ts +23 -0
- package/node_modules/@spexcode/spec-cli/dist/spec-body-edit.js +138 -0
- package/node_modules/@spexcode/spec-cli/dist/supervise.js +15 -6
- package/node_modules/@spexcode/spec-cli/dist/transcript-reader.d.ts +36 -0
- package/node_modules/@spexcode/spec-cli/dist/transcript-reader.js +251 -0
- package/node_modules/@spexcode/spec-cli/hooks/dispatch.sh +19 -31
- package/node_modules/@spexcode/spec-cli/hooks/harness.sh +6 -6
- package/node_modules/@spexcode/spec-cli/package.json +6 -6
- package/node_modules/@spexcode/spec-cli/templates/hooks/post-checkout +4 -2
- package/node_modules/@spexcode/spec-cli/templates/hooks/post-merge +2 -1
- package/node_modules/@spexcode/spec-cli/templates/hooks/pre-commit +5 -3
- package/node_modules/@spexcode/spec-cli/templates/hooks/reference-transaction +5 -3
- package/node_modules/@spexcode/spec-cli/templates/spec/project/.plugins/commands/spec.md +2 -7
- package/node_modules/@spexcode/spec-cli/templates/spec/project/.plugins/core/idle/idle.sh +4 -10
- package/node_modules/@spexcode/spec-cli/templates/spec/project/.plugins/core/idle/spec.md +1 -1
- package/node_modules/@spexcode/spec-cli/templates/spec/project/.plugins/core/mark-active/mark-active.sh +22 -24
- package/node_modules/@spexcode/spec-cli/templates/spec/project/.plugins/core/mark-active/spec.md +10 -2
- package/node_modules/@spexcode/spec-cli/templates/spec/project/.plugins/core/session-fail/fail.sh +8 -7
- package/node_modules/@spexcode/spec-cli/templates/spec/project/.plugins/core/session-fail/spec.md +3 -1
- package/node_modules/@spexcode/spec-cli/templates/spec/project/.plugins/core/session-listen/session-listen.sh +133 -0
- package/node_modules/@spexcode/spec-cli/templates/spec/project/.plugins/core/session-listen/spec.md +36 -0
- package/node_modules/@spexcode/spec-cli/templates/spec/project/.plugins/core/spec.md +2 -0
- package/node_modules/@spexcode/spec-cli/templates/spec/project/.plugins/core/stop-gate/spec.md +1 -1
- package/node_modules/@spexcode/spec-cli/templates/spec/project/.plugins/core/stop-gate/stop-gate.sh +17 -20
- package/node_modules/@spexcode/spec-cli/templates/spec/project/.plugins/skills/merge/spec.md +33 -0
- package/node_modules/@spexcode/spec-cli/templates/spec/project/.plugins/skills/spec.md +2 -6
- package/node_modules/@spexcode/spec-cli/templates/spec/project/.plugins/spec.md +7 -0
- package/node_modules/@spexcode/spec-core/dist/anchors.d.ts +13 -2
- package/node_modules/@spexcode/spec-core/dist/anchors.js +311 -15
- package/node_modules/@spexcode/spec-core/dist/git.d.ts +4 -0
- package/node_modules/@spexcode/spec-core/dist/git.js +9 -9
- package/node_modules/@spexcode/spec-core/dist/layout.d.ts +12 -0
- package/node_modules/@spexcode/spec-core/dist/layout.js +4 -2
- package/node_modules/@spexcode/spec-core/dist/resilience.d.ts +1 -0
- package/node_modules/@spexcode/spec-core/dist/resilience.js +8 -0
- package/node_modules/@spexcode/spec-core/dist/review/reviewFilters.d.ts +1 -0
- package/node_modules/@spexcode/spec-core/dist/review/reviewFilters.js +7 -3
- package/node_modules/@spexcode/spec-core/dist/review/reviewQuery.d.ts +1 -0
- package/node_modules/@spexcode/spec-core/dist/review/reviewQuery.js +4 -0
- package/node_modules/@spexcode/spec-core/dist/specs.d.ts +2 -0
- package/node_modules/@spexcode/spec-core/dist/specs.js +30 -0
- package/node_modules/@spexcode/spec-core/package.json +4 -1
- package/node_modules/@spexcode/spec-eval/dist/cli.js +1 -1
- package/node_modules/@spexcode/spec-eval/dist/evaltab.d.ts +1 -0
- package/node_modules/@spexcode/spec-eval/dist/evaltab.js +6 -1
- package/node_modules/@spexcode/spec-eval/dist/freshness.d.ts +1 -1
- package/node_modules/@spexcode/spec-eval/dist/freshness.js +12 -12
- package/node_modules/@spexcode/spec-eval/dist/host.d.ts +2 -1
- package/node_modules/@spexcode/spec-eval/dist/sessioneval.d.ts +2 -1
- package/node_modules/@spexcode/spec-eval/dist/sessioneval.js +20 -3
- package/node_modules/@spexcode/spec-eval/package.json +2 -2
- package/node_modules/@spexcode/spec-forge/package.json +2 -2
- package/node_modules/@vscode/tree-sitter-wasm/LICENSE +21 -0
- package/node_modules/@vscode/tree-sitter-wasm/README.md +36 -0
- package/node_modules/@vscode/tree-sitter-wasm/SECURITY.md +41 -0
- package/node_modules/@vscode/tree-sitter-wasm/cgmanifest.json +16 -0
- package/node_modules/@vscode/tree-sitter-wasm/package.json +42 -0
- package/node_modules/@vscode/tree-sitter-wasm/wasm/tree-sitter-bash.wasm +0 -0
- package/node_modules/@vscode/tree-sitter-wasm/wasm/tree-sitter-c-sharp.wasm +0 -0
- package/node_modules/@vscode/tree-sitter-wasm/wasm/tree-sitter-cpp.wasm +0 -0
- package/node_modules/@vscode/tree-sitter-wasm/wasm/tree-sitter-css.wasm +0 -0
- package/node_modules/@vscode/tree-sitter-wasm/wasm/tree-sitter-go.wasm +0 -0
- package/node_modules/@vscode/tree-sitter-wasm/wasm/tree-sitter-ini.wasm +0 -0
- package/node_modules/@vscode/tree-sitter-wasm/wasm/tree-sitter-java.wasm +0 -0
- package/node_modules/@vscode/tree-sitter-wasm/wasm/tree-sitter-javascript.wasm +0 -0
- package/node_modules/@vscode/tree-sitter-wasm/wasm/tree-sitter-php.wasm +0 -0
- package/node_modules/@vscode/tree-sitter-wasm/wasm/tree-sitter-powershell.wasm +0 -0
- package/node_modules/@vscode/tree-sitter-wasm/wasm/tree-sitter-python.wasm +0 -0
- package/node_modules/@vscode/tree-sitter-wasm/wasm/tree-sitter-regex.wasm +0 -0
- package/node_modules/@vscode/tree-sitter-wasm/wasm/tree-sitter-ruby.wasm +0 -0
- package/node_modules/@vscode/tree-sitter-wasm/wasm/tree-sitter-rust.wasm +0 -0
- package/node_modules/@vscode/tree-sitter-wasm/wasm/tree-sitter-tsx.wasm +0 -0
- package/node_modules/@vscode/tree-sitter-wasm/wasm/tree-sitter-typescript.wasm +0 -0
- package/node_modules/@vscode/tree-sitter-wasm/wasm/tree-sitter.js +4075 -0
- package/node_modules/@vscode/tree-sitter-wasm/wasm/tree-sitter.wasm +0 -0
- package/node_modules/@vscode/tree-sitter-wasm/wasm/web-tree-sitter.d.ts +1027 -0
- package/package.json +9 -3
- package/node_modules/@spexcode/session-core/dist/delivery-queue.d.ts +0 -23
- package/node_modules/@spexcode/session-core/dist/delivery-queue.js +0 -195
- package/node_modules/@spexcode/session-core/dist/index.d.ts +0 -5
- package/node_modules/@spexcode/session-core/dist/index.js +0 -5
- package/node_modules/@spexcode/session-core/dist/internal.d.ts +0 -3
- package/node_modules/@spexcode/session-core/dist/internal.js +0 -3
- package/node_modules/@spexcode/session-core/dist/message.d.ts +0 -22
- package/node_modules/@spexcode/session-core/dist/message.js +0 -52
- package/node_modules/@spexcode/session-core/dist/record-lock.js +0 -152
- package/node_modules/@spexcode/session-core/dist/runtime-session.d.ts +0 -50
- package/node_modules/@spexcode/session-core/dist/runtime-session.js +0 -286
- package/node_modules/@spexcode/session-core/dist/session-cursors.d.ts +0 -14
- package/node_modules/@spexcode/session-core/dist/session-cursors.js +0 -82
- package/node_modules/@spexcode/session-core/dist/session-timeline.d.ts +0 -46
- package/node_modules/@spexcode/session-core/dist/session-timeline.js +0 -216
- package/node_modules/@spexcode/spec-cli/hooks/compat/mark-active-0.5.2-eef1.fixture +0 -53
- package/node_modules/@spexcode/spec-cli/hooks/compat/mark-active-sed-v0.fixture +0 -46
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spexcode",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "SpexCode — a spec-driven, self-developing dev tool. The `spex` CLI + spec server reads the .spec tree and its git history, and serves the dashboard.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,9 +21,15 @@
|
|
|
21
21
|
"node": ">=22"
|
|
22
22
|
},
|
|
23
23
|
"scripts": {
|
|
24
|
-
"build": "npm run build --workspace=@spexcode/
|
|
24
|
+
"build": "npm run build --workspace=@spexcode/session-protocol && npm run build --workspace=@spexcode/session-topology && npm run build --workspace=@spexcode/session-runtime && npm run build --workspace=@spexcode/session-events && npm run build --workspace=@spexcode/session-application && npm run build --workspace=@spexcode/session-selflaunch && npm run build --workspace=@spexcode/spec-core && npm run build --workspace=@spexcode/spec-eval && npm run build --workspace=@spexcode/spec-forge && npm run build --workspace=@spexcode/spec-cli",
|
|
25
|
+
"typecheck": "tsc --noEmit -p spec-cli/tsconfig.json",
|
|
26
|
+
"migrate:sessions": "npm run build && node scripts/migrate-session-json.mjs",
|
|
27
|
+
"test:session-cutover": "node --test scripts/session-live-cutover.test.mjs",
|
|
25
28
|
"api": "npm run build && node bin/spex.mjs serve",
|
|
26
29
|
"web": "cd spec-dashboard && npm run dev",
|
|
30
|
+
"desktop:install": "npm --prefix spec-desktop install",
|
|
31
|
+
"desktop:start": "npm --prefix spec-desktop start",
|
|
32
|
+
"desktop:check": "node --test scripts/desktop-contract.test.mjs",
|
|
27
33
|
"build:public": "node scripts/public-graph-build.mjs",
|
|
28
34
|
"test:public-graph": "npm run build:public && node spec-dashboard/test/public-graph-static.e2e.mjs",
|
|
29
35
|
"lint": "node scripts/sync-init-plugins.mjs --check && cd spec-cli && npm run -s lint",
|
|
@@ -38,7 +44,7 @@
|
|
|
38
44
|
"prepack": "node scripts/sync-init-plugins.mjs --check && node scripts/prepack.mjs"
|
|
39
45
|
},
|
|
40
46
|
"dependencies": {
|
|
41
|
-
"@spexcode/spec-cli": "0.6.
|
|
47
|
+
"@spexcode/spec-cli": "0.6.8"
|
|
42
48
|
},
|
|
43
49
|
"publishConfig": {
|
|
44
50
|
"access": "public"
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export type PendingMessage = {
|
|
2
|
-
mid: string;
|
|
3
|
-
text: string;
|
|
4
|
-
from: string | null;
|
|
5
|
-
dispatch?: {
|
|
6
|
-
operation: string;
|
|
7
|
-
requestDigest: string;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
export declare function revokeSenderDelivery(id: string): void;
|
|
11
|
-
export declare const senderDeliveryRevoked: (id: string) => boolean;
|
|
12
|
-
export declare function pendingSnapshot(id: string): PendingMessage[];
|
|
13
|
-
export declare function replacePendingWhileLocked(id: string, msgs: PendingMessage[]): void;
|
|
14
|
-
export declare function revokePendingFromWhileLocked(id: string, sender: string): number;
|
|
15
|
-
export declare function enqueue(id: string, msg: PendingMessage): void;
|
|
16
|
-
export declare function ensurePendingWhileLocked(id: string, msg: PendingMessage): boolean;
|
|
17
|
-
export declare const pendingMessages: (id: string) => PendingMessage[];
|
|
18
|
-
export declare const owesDelivery: (id: string) => boolean;
|
|
19
|
-
export declare function withDeliveryLocks<T>(rawIds: string[], body: () => Promise<T>, index?: number, ids?: string[]): Promise<T>;
|
|
20
|
-
export declare function drain(id: string, insert: (msg: PendingMessage) => Promise<boolean>, timeoutMs?: number): Promise<{
|
|
21
|
-
delivered: number;
|
|
22
|
-
remaining: number;
|
|
23
|
-
}>;
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, renameSync, unlinkSync, writeFileSync, writeSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { runtimeRoot, sessionArtifactPath, sessionStoreDir } from '@spexcode/spec-core';
|
|
4
|
-
import { sentDispatchReceipt, settleSentDispatch } from './session-timeline.js';
|
|
5
|
-
const queuePath = (id) => sessionArtifactPath(id, 'pending.json');
|
|
6
|
-
const revokedSenderRoot = () => join(runtimeRoot(), '.revoked-senders');
|
|
7
|
-
const revokedSenderPath = (id) => join(revokedSenderRoot(), id);
|
|
8
|
-
// @@@ its own lock, deliberately NOT the record lock - the drain holds this across the adapter insert, which
|
|
9
|
-
// is what makes "claim" real: two processes draining the same session cannot both hand over one message. The
|
|
10
|
-
// record lock could never span that call — a native turn runs lifecycle hooks that re-enter the record writer,
|
|
11
|
-
// and holding it there deadlocks the adapter's own confirmation. Nothing in the delivery path takes this one,
|
|
12
|
-
// so spanning the insert costs no contention. PID liveness reclaims a lock whose holder died mid-insert.
|
|
13
|
-
const lockRoot = () => join(runtimeRoot(), '.delivery-locks');
|
|
14
|
-
const lockPath = (id) => join(lockRoot(), `${id}.lock`);
|
|
15
|
-
const pause = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
16
|
-
async function acquire(id, timeoutMs) {
|
|
17
|
-
mkdirSync(lockRoot(), { recursive: true });
|
|
18
|
-
const path = lockPath(id), deadline = Date.now() + timeoutMs;
|
|
19
|
-
for (;;) {
|
|
20
|
-
try {
|
|
21
|
-
const fd = openSync(path, 'wx');
|
|
22
|
-
writeSync(fd, String(process.pid));
|
|
23
|
-
closeSync(fd);
|
|
24
|
-
return () => { try {
|
|
25
|
-
unlinkSync(path);
|
|
26
|
-
}
|
|
27
|
-
catch { /* a liveness reclaim already removed it */ } };
|
|
28
|
-
}
|
|
29
|
-
catch (e) {
|
|
30
|
-
if (e.code !== 'EEXIST')
|
|
31
|
-
throw e;
|
|
32
|
-
let owner = 0;
|
|
33
|
-
try {
|
|
34
|
-
owner = Number(readFileSync(path, 'utf8').trim()) || 0;
|
|
35
|
-
}
|
|
36
|
-
catch { /* race with creator/releaser */ }
|
|
37
|
-
if (owner && owner !== process.pid) {
|
|
38
|
-
try {
|
|
39
|
-
process.kill(owner, 0);
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
42
|
-
try {
|
|
43
|
-
unlinkSync(path);
|
|
44
|
-
}
|
|
45
|
-
catch { /* race */ }
|
|
46
|
-
;
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
// A drain is never urgent enough to fight for: whoever holds the lock is delivering these same messages,
|
|
51
|
-
// and the retry sweep will come back. Declining is not a lost message.
|
|
52
|
-
if (Date.now() >= deadline)
|
|
53
|
-
return null;
|
|
54
|
-
await pause(25);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
function read(id) {
|
|
59
|
-
try {
|
|
60
|
-
const raw = JSON.parse(readFileSync(queuePath(id), 'utf8'));
|
|
61
|
-
if (!Array.isArray(raw))
|
|
62
|
-
return [];
|
|
63
|
-
return raw.filter((m) => !!m && typeof m === 'object'
|
|
64
|
-
&& typeof m.mid === 'string'
|
|
65
|
-
&& typeof m.text === 'string'
|
|
66
|
-
&& (m.dispatch === undefined
|
|
67
|
-
|| (typeof m.dispatch?.operation === 'string'
|
|
68
|
-
&& typeof m.dispatch?.requestDigest === 'string')));
|
|
69
|
-
}
|
|
70
|
-
catch {
|
|
71
|
-
return [];
|
|
72
|
-
} // absent, empty, or unparseable all mean the honest thing: nothing owed
|
|
73
|
-
}
|
|
74
|
-
// Written whole and atomically; an empty queue is REMOVED rather than left as `[]`, so "is anything owed?" is
|
|
75
|
-
// one existsSync on the sweep's hot path.
|
|
76
|
-
function write(id, msgs) {
|
|
77
|
-
const path = queuePath(id);
|
|
78
|
-
if (!msgs.length) {
|
|
79
|
-
try {
|
|
80
|
-
unlinkSync(path);
|
|
81
|
-
}
|
|
82
|
-
catch { /* already gone */ }
|
|
83
|
-
;
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
mkdirSync(sessionStoreDir(id), { recursive: true });
|
|
87
|
-
const tmp = `${path}.${process.pid}.tmp`;
|
|
88
|
-
writeFileSync(tmp, JSON.stringify(msgs, null, 2) + '\n');
|
|
89
|
-
renameSync(tmp, path);
|
|
90
|
-
}
|
|
91
|
-
// A closed sender may have left debt in many other sessions' queues. The marker is deliberately outside its
|
|
92
|
-
// own store (which close removes) and is checked under the sender's record lock by dispatch: a close cannot
|
|
93
|
-
// return while an old process can still append, and a later sweep cannot hand over what it sees here.
|
|
94
|
-
export function revokeSenderDelivery(id) {
|
|
95
|
-
mkdirSync(revokedSenderRoot(), { recursive: true });
|
|
96
|
-
writeFileSync(revokedSenderPath(id), `${id}\n`);
|
|
97
|
-
}
|
|
98
|
-
export const senderDeliveryRevoked = (id) => existsSync(revokedSenderPath(id));
|
|
99
|
-
export function pendingSnapshot(id) { return read(id); }
|
|
100
|
-
// These two writes require the target's delivery lock. They are the queue half of a larger transaction
|
|
101
|
-
// (currently reparent), which must be able to restore the exact previous debt if a later record write fails.
|
|
102
|
-
export function replacePendingWhileLocked(id, msgs) { write(id, msgs); }
|
|
103
|
-
export function revokePendingFromWhileLocked(id, sender) {
|
|
104
|
-
const current = read(id);
|
|
105
|
-
const next = current.filter((msg) => msg.from !== sender);
|
|
106
|
-
write(id, next);
|
|
107
|
-
return current.length - next.length;
|
|
108
|
-
}
|
|
109
|
-
// The enqueue rides the timeline append ([[dispatch]]): the caller holds the session's RECORD lock across
|
|
110
|
-
// both, and the record is written first, so delivery is never unrecorded. A keyed dispatch also carries its
|
|
111
|
-
// exact delivery bytes in the timeline receipt, letting its retry restore a queue write lost to a crash.
|
|
112
|
-
export function enqueue(id, msg) {
|
|
113
|
-
write(id, [...read(id), msg]);
|
|
114
|
-
}
|
|
115
|
-
// Caller holds this target's delivery lock. A retry may reach this after either side of the receipt->queue
|
|
116
|
-
// crash boundary; exact mid identity makes reconstruction idempotent without inspecting message text.
|
|
117
|
-
export function ensurePendingWhileLocked(id, msg) {
|
|
118
|
-
const current = read(id);
|
|
119
|
-
if (current.some((pending) => pending.mid === msg.mid))
|
|
120
|
-
return false;
|
|
121
|
-
write(id, [...current, msg]);
|
|
122
|
-
return true;
|
|
123
|
-
}
|
|
124
|
-
export const pendingMessages = (id) => read(id);
|
|
125
|
-
export const owesDelivery = (id) => existsSync(queuePath(id));
|
|
126
|
-
// Record transitions and queue mutations take locks in the same direction: record locks first, then these
|
|
127
|
-
// target queue locks. A batch reparent needs all child queues held at once so its pointer/watch/debt change
|
|
128
|
-
// either commits together or restores together.
|
|
129
|
-
export async function withDeliveryLocks(rawIds, body, index = 0, ids = [...new Set(rawIds)].sort()) {
|
|
130
|
-
if (index >= ids.length)
|
|
131
|
-
return body();
|
|
132
|
-
const release = await acquire(ids[index], 30_000);
|
|
133
|
-
if (!release)
|
|
134
|
-
throw new Error(`delivery queue ${ids[index]}: timed out waiting for transaction lock`);
|
|
135
|
-
try {
|
|
136
|
-
return await withDeliveryLocks(ids, body, index + 1, ids);
|
|
137
|
-
}
|
|
138
|
-
finally {
|
|
139
|
-
release();
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
// Hand over what is owed, in order, exactly once. `insert` reports whether the adapter took the message: only
|
|
143
|
-
// then is the entry dropped. A refusal ENDS the pass with that entry still queued and everything behind it
|
|
144
|
-
// still behind it — order is a property of a conversation, so a message is never skipped to deliver a later
|
|
145
|
-
// one. Returns how many were handed over and how many are still owed.
|
|
146
|
-
export async function drain(id, insert, timeoutMs = 5_000) {
|
|
147
|
-
const release = await acquire(id, timeoutMs);
|
|
148
|
-
if (!release)
|
|
149
|
-
return { delivered: 0, remaining: read(id).length };
|
|
150
|
-
let delivered = 0;
|
|
151
|
-
try {
|
|
152
|
-
for (;;) {
|
|
153
|
-
const queued = read(id);
|
|
154
|
-
if (!queued.length)
|
|
155
|
-
return { delivered, remaining: 0 };
|
|
156
|
-
if (queued[0].from && senderDeliveryRevoked(queued[0].from)) {
|
|
157
|
-
// Closing a sender voids its undelivered output, not the recipient's immutable conversation history.
|
|
158
|
-
// Drop a revoked head and continue so it cannot permanently block the messages behind it.
|
|
159
|
-
write(id, read(id).filter((m) => m.mid !== queued[0].mid));
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
162
|
-
let ok = false;
|
|
163
|
-
try {
|
|
164
|
-
const head = queued[0];
|
|
165
|
-
if (head.dispatch) {
|
|
166
|
-
const receipt = sentDispatchReceipt(id, head.dispatch.operation, head.dispatch.requestDigest);
|
|
167
|
-
if (!receipt || receipt.mid !== head.mid || !receipt.delivery
|
|
168
|
-
|| receipt.delivery.text !== head.text || receipt.delivery.from !== head.from)
|
|
169
|
-
return { delivered, remaining: queued.length };
|
|
170
|
-
if (receipt.delivered)
|
|
171
|
-
ok = true;
|
|
172
|
-
else {
|
|
173
|
-
ok = await insert(head);
|
|
174
|
-
if (ok)
|
|
175
|
-
settleSentDispatch(id, head.mid);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
else
|
|
179
|
-
ok = await insert(head);
|
|
180
|
-
}
|
|
181
|
-
catch {
|
|
182
|
-
ok = false;
|
|
183
|
-
}
|
|
184
|
-
if (!ok)
|
|
185
|
-
return { delivered, remaining: queued.length };
|
|
186
|
-
// Re-read before removing: a send that landed while this pass ran appended to the tail, and rewriting a
|
|
187
|
-
// stale snapshot minus the head would silently drop it.
|
|
188
|
-
write(id, read(id).filter((m) => m.mid !== queued[0].mid));
|
|
189
|
-
delivered++;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
finally {
|
|
193
|
-
release();
|
|
194
|
-
}
|
|
195
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { acceptMessage, MessageKeyConflict, type AcceptMessageOptions, type MessageIdempotency, type PreparedMessage } from './message.js';
|
|
2
|
-
export { drain, owesDelivery, pendingMessages, type PendingMessage } from './delivery-queue.js';
|
|
3
|
-
export { publishRuntimeSessionState, readRuntimeSession, registerRuntimeSession, runtimeSessionChildren, RuntimeSessionConflict, type RuntimeSessionRecord, type RuntimeSessionRegistration, type RuntimeSessionState, } from './runtime-session.js';
|
|
4
|
-
export { advanceFollow, followedSessions, followCursor, readCursors, unreadSince, type Cursors } from './session-cursors.js';
|
|
5
|
-
export { currentHumanTurn, lastHumanSendVia, recordStatus, timelineEvents, timelineStamp, timelineTail, type SessionTurn, type TimelineEvent, } from './session-timeline.js';
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { acceptMessage, MessageKeyConflict } from './message.js';
|
|
2
|
-
export { drain, owesDelivery, pendingMessages } from './delivery-queue.js';
|
|
3
|
-
export { publishRuntimeSessionState, readRuntimeSession, registerRuntimeSession, runtimeSessionChildren, RuntimeSessionConflict, } from './runtime-session.js';
|
|
4
|
-
export { advanceFollow, followedSessions, followCursor, readCursors, unreadSince } from './session-cursors.js';
|
|
5
|
-
export { currentHumanTurn, lastHumanSendVia, recordStatus, timelineEvents, timelineStamp, timelineTail, } from './session-timeline.js';
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export { enqueue, ensurePendingWhileLocked, pendingSnapshot, replacePendingWhileLocked, revokePendingFromWhileLocked, revokeSenderDelivery, senderDeliveryRevoked, withDeliveryLocks, } from './delivery-queue.js';
|
|
2
|
-
export { appendSent, sentDispatchReceipt, settleSentDispatch, type SentDispatchReceipt, type SentDispatchState, } from './session-timeline.js';
|
|
3
|
-
export { trySessionRecordLockSync, withSessionRecordLock, withSessionRecordLocks, withSessionRecordLockSync, } from './record-lock.js';
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export { enqueue, ensurePendingWhileLocked, pendingSnapshot, replacePendingWhileLocked, revokePendingFromWhileLocked, revokeSenderDelivery, senderDeliveryRevoked, withDeliveryLocks, } from './delivery-queue.js';
|
|
2
|
-
export { appendSent, sentDispatchReceipt, settleSentDispatch, } from './session-timeline.js';
|
|
3
|
-
export { trySessionRecordLockSync, withSessionRecordLock, withSessionRecordLocks, withSessionRecordLockSync, } from './record-lock.js';
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { type SentDispatchReceipt } from './session-timeline.js';
|
|
2
|
-
export type MessageIdempotency = SentDispatchReceipt;
|
|
3
|
-
export type PreparedMessage = {
|
|
4
|
-
text: string;
|
|
5
|
-
replyVia?: 'note';
|
|
6
|
-
};
|
|
7
|
-
export type AcceptMessageOptions = {
|
|
8
|
-
target: string;
|
|
9
|
-
text: string;
|
|
10
|
-
from?: string;
|
|
11
|
-
idempotency?: MessageIdempotency;
|
|
12
|
-
validate?: () => Promise<void>;
|
|
13
|
-
prepare: () => Promise<PreparedMessage>;
|
|
14
|
-
};
|
|
15
|
-
export declare class MessageKeyConflict extends Error {
|
|
16
|
-
readonly code = "dispatch_key_reused";
|
|
17
|
-
constructor(operation: string);
|
|
18
|
-
}
|
|
19
|
-
export declare function acceptMessage(options: AcceptMessageOptions): Promise<{
|
|
20
|
-
mid: string;
|
|
21
|
-
replayed: boolean;
|
|
22
|
-
}>;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { ensurePendingWhileLocked, enqueue, senderDeliveryRevoked, withDeliveryLocks } from './delivery-queue.js';
|
|
2
|
-
import { appendSent, sentDispatchReceipt } from './session-timeline.js';
|
|
3
|
-
import { withSessionRecordLocks } from './record-lock.js';
|
|
4
|
-
export class MessageKeyConflict extends Error {
|
|
5
|
-
code = 'dispatch_key_reused';
|
|
6
|
-
constructor(operation) {
|
|
7
|
-
super(`idempotency key is already bound to another ${operation} payload`);
|
|
8
|
-
this.name = 'MessageKeyConflict';
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
const keyedPending = (receipt, mid, delivery) => ({
|
|
12
|
-
mid,
|
|
13
|
-
text: delivery.text,
|
|
14
|
-
from: delivery.from,
|
|
15
|
-
dispatch: { operation: receipt.operation, requestDigest: receipt.requestDigest },
|
|
16
|
-
});
|
|
17
|
-
// The durable acceptance boundary. Product validation and prompt composition run while the record fence is
|
|
18
|
-
// held, but the package alone owns append + debt publication and keyed crash recovery.
|
|
19
|
-
export async function acceptMessage(options) {
|
|
20
|
-
const from = options.from ?? null;
|
|
21
|
-
let result = null;
|
|
22
|
-
await withSessionRecordLocks([options.target, ...(from ? [from] : [])], async () => {
|
|
23
|
-
if (from && senderDeliveryRevoked(from))
|
|
24
|
-
throw new Error(`sender session ${from} is closed; prompt NOT delivered`);
|
|
25
|
-
await options.validate?.();
|
|
26
|
-
const accept = async () => {
|
|
27
|
-
if (options.idempotency) {
|
|
28
|
-
const prior = sentDispatchReceipt(options.target, options.idempotency.operation, options.idempotency.requestDigest);
|
|
29
|
-
if (prior) {
|
|
30
|
-
if (prior.payloadHash !== options.idempotency.payloadHash)
|
|
31
|
-
throw new MessageKeyConflict(options.idempotency.operation);
|
|
32
|
-
if (prior.delivery && !prior.delivered)
|
|
33
|
-
ensurePendingWhileLocked(options.target, keyedPending(options.idempotency, prior.mid, prior.delivery));
|
|
34
|
-
result = { mid: prior.mid, replayed: true };
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
const prepared = await options.prepare();
|
|
39
|
-
const receipt = options.idempotency
|
|
40
|
-
? { ...options.idempotency, delivery: { text: prepared.text, from } }
|
|
41
|
-
: undefined;
|
|
42
|
-
const { mid } = appendSent(options.target, options.text, from, prepared.replyVia, receipt);
|
|
43
|
-
enqueue(options.target, receipt ? keyedPending(receipt, mid, receipt.delivery) : { mid, text: prepared.text, from });
|
|
44
|
-
result = { mid, replayed: false };
|
|
45
|
-
};
|
|
46
|
-
if (options.idempotency)
|
|
47
|
-
await withDeliveryLocks([options.target], accept);
|
|
48
|
-
else
|
|
49
|
-
await accept();
|
|
50
|
-
});
|
|
51
|
-
return result;
|
|
52
|
-
}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { closeSync, mkdirSync, openSync, readFileSync, unlinkSync, writeSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { runtimeRoot } from '@spexcode/spec-core';
|
|
4
|
-
const lockRoot = () => join(runtimeRoot(), '.session-locks');
|
|
5
|
-
const lockPath = (id) => join(lockRoot(), `${id}.lock`);
|
|
6
|
-
const syncPause = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
7
|
-
export class SessionRecordLockTimeout extends Error {
|
|
8
|
-
constructor(id) {
|
|
9
|
-
super(`session ${id}: lifecycle transition lock timed out; refusing a stale write`);
|
|
10
|
-
this.name = 'SessionRecordLockTimeout';
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
function acquireSync(id, timeoutMs = 30_000) {
|
|
14
|
-
mkdirSync(lockRoot(), { recursive: true });
|
|
15
|
-
const path = lockPath(id), deadline = Date.now() + timeoutMs;
|
|
16
|
-
for (;;) {
|
|
17
|
-
try {
|
|
18
|
-
const fd = openSync(path, 'wx');
|
|
19
|
-
writeSync(fd, String(process.pid));
|
|
20
|
-
closeSync(fd);
|
|
21
|
-
return () => { try {
|
|
22
|
-
unlinkSync(path);
|
|
23
|
-
}
|
|
24
|
-
catch { /* another recovery already removed it */ } };
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
if (error.code !== 'EEXIST')
|
|
28
|
-
throw error;
|
|
29
|
-
let owner = 0;
|
|
30
|
-
try {
|
|
31
|
-
owner = Number(readFileSync(path, 'utf8').trim()) || 0;
|
|
32
|
-
}
|
|
33
|
-
catch { /* race */ }
|
|
34
|
-
if (owner && owner !== process.pid) {
|
|
35
|
-
try {
|
|
36
|
-
process.kill(owner, 0);
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
try {
|
|
40
|
-
unlinkSync(path);
|
|
41
|
-
}
|
|
42
|
-
catch { /* race */ }
|
|
43
|
-
;
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (Date.now() >= deadline)
|
|
48
|
-
throw new SessionRecordLockTimeout(id);
|
|
49
|
-
syncPause(10);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
const aborted = (signal) => signal.reason instanceof Error
|
|
54
|
-
? signal.reason
|
|
55
|
-
: Object.assign(new Error('The operation was aborted'), { name: 'AbortError', code: 'ABORT_ERR' });
|
|
56
|
-
async function pause(signal) {
|
|
57
|
-
if (!signal) {
|
|
58
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
if (signal.aborted)
|
|
62
|
-
throw aborted(signal);
|
|
63
|
-
await new Promise((resolve, reject) => {
|
|
64
|
-
const timer = setTimeout(done, 10);
|
|
65
|
-
const abort = () => { clearTimeout(timer); signal.removeEventListener('abort', abort); reject(aborted(signal)); };
|
|
66
|
-
function done() { signal.removeEventListener('abort', abort); resolve(); }
|
|
67
|
-
signal.addEventListener('abort', abort, { once: true });
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
async function acquire(id, timeoutMs = 30_000, signal) {
|
|
71
|
-
mkdirSync(lockRoot(), { recursive: true });
|
|
72
|
-
const path = lockPath(id), deadline = Date.now() + timeoutMs;
|
|
73
|
-
for (;;) {
|
|
74
|
-
if (signal?.aborted)
|
|
75
|
-
throw aborted(signal);
|
|
76
|
-
try {
|
|
77
|
-
const fd = openSync(path, 'wx');
|
|
78
|
-
writeSync(fd, String(process.pid));
|
|
79
|
-
closeSync(fd);
|
|
80
|
-
return () => { try {
|
|
81
|
-
unlinkSync(path);
|
|
82
|
-
}
|
|
83
|
-
catch { /* another recovery already removed it */ } };
|
|
84
|
-
}
|
|
85
|
-
catch (error) {
|
|
86
|
-
if (error.code !== 'EEXIST')
|
|
87
|
-
throw error;
|
|
88
|
-
let owner = 0;
|
|
89
|
-
try {
|
|
90
|
-
owner = Number(readFileSync(path, 'utf8').trim()) || 0;
|
|
91
|
-
}
|
|
92
|
-
catch { /* race */ }
|
|
93
|
-
if (owner && owner !== process.pid) {
|
|
94
|
-
try {
|
|
95
|
-
process.kill(owner, 0);
|
|
96
|
-
}
|
|
97
|
-
catch {
|
|
98
|
-
try {
|
|
99
|
-
unlinkSync(path);
|
|
100
|
-
}
|
|
101
|
-
catch { /* race */ }
|
|
102
|
-
;
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
if (Date.now() >= deadline)
|
|
107
|
-
throw new SessionRecordLockTimeout(id);
|
|
108
|
-
await pause(signal);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
export async function withSessionRecordLock(id, body, signal) {
|
|
113
|
-
const release = await acquire(id, 30_000, signal);
|
|
114
|
-
try {
|
|
115
|
-
return await body();
|
|
116
|
-
}
|
|
117
|
-
finally {
|
|
118
|
-
release();
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
export function withSessionRecordLockSync(id, body) {
|
|
122
|
-
const release = acquireSync(id);
|
|
123
|
-
try {
|
|
124
|
-
return body();
|
|
125
|
-
}
|
|
126
|
-
finally {
|
|
127
|
-
release();
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
export function trySessionRecordLockSync(id) {
|
|
131
|
-
mkdirSync(lockRoot(), { recursive: true });
|
|
132
|
-
const path = lockPath(id);
|
|
133
|
-
try {
|
|
134
|
-
const fd = openSync(path, 'wx');
|
|
135
|
-
writeSync(fd, String(process.pid));
|
|
136
|
-
closeSync(fd);
|
|
137
|
-
return () => { try {
|
|
138
|
-
unlinkSync(path);
|
|
139
|
-
}
|
|
140
|
-
catch { /* another recovery already removed it */ } };
|
|
141
|
-
}
|
|
142
|
-
catch (error) {
|
|
143
|
-
if (error.code === 'EEXIST')
|
|
144
|
-
return null;
|
|
145
|
-
throw error;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
export async function withSessionRecordLocks(rawIds, body, index = 0, ids = [...new Set(rawIds)].sort()) {
|
|
149
|
-
if (index >= ids.length)
|
|
150
|
-
return body();
|
|
151
|
-
return withSessionRecordLock(ids[index], () => withSessionRecordLocks(ids, body, index + 1, ids));
|
|
152
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { type SessionLifecycle, type SessionProposal } from '@spexcode/spec-core';
|
|
2
|
-
export type RuntimeSessionRegistration = {
|
|
3
|
-
sessionId: string;
|
|
4
|
-
runtimeOwner: string;
|
|
5
|
-
worktreePath: string;
|
|
6
|
-
branch: string | null;
|
|
7
|
-
parentSessionId?: string | null;
|
|
8
|
-
title?: string | null;
|
|
9
|
-
node?: string | null;
|
|
10
|
-
runtimeMetadata?: Record<string, string>;
|
|
11
|
-
createdAt?: number;
|
|
12
|
-
};
|
|
13
|
-
export type RuntimeSessionState = {
|
|
14
|
-
sessionId: string;
|
|
15
|
-
runtimeOwner: string;
|
|
16
|
-
revision: string;
|
|
17
|
-
runtimeState: string;
|
|
18
|
-
lifecycle: SessionLifecycle;
|
|
19
|
-
proposal?: SessionProposal | null;
|
|
20
|
-
note?: string | null;
|
|
21
|
-
};
|
|
22
|
-
export type RuntimeSessionRecord = {
|
|
23
|
-
sessionId: string;
|
|
24
|
-
runtimeOwner: string;
|
|
25
|
-
runtimeState: string | null;
|
|
26
|
-
revision: string | null;
|
|
27
|
-
worktreePath: string;
|
|
28
|
-
branch: string | null;
|
|
29
|
-
parentSessionId: string | null;
|
|
30
|
-
title: string | null;
|
|
31
|
-
node: string | null;
|
|
32
|
-
runtimeMetadata: Record<string, string>;
|
|
33
|
-
lifecycle: SessionLifecycle;
|
|
34
|
-
proposal: SessionProposal | null;
|
|
35
|
-
note: string | null;
|
|
36
|
-
createdAt: number;
|
|
37
|
-
};
|
|
38
|
-
export declare class RuntimeSessionConflict extends Error {
|
|
39
|
-
readonly code = "runtime_session_conflict";
|
|
40
|
-
constructor(message: string);
|
|
41
|
-
}
|
|
42
|
-
export declare function registerRuntimeSession(input: RuntimeSessionRegistration): Promise<{
|
|
43
|
-
replayed: boolean;
|
|
44
|
-
}>;
|
|
45
|
-
export declare function publishRuntimeSessionState(input: RuntimeSessionState): Promise<{
|
|
46
|
-
notified: string[];
|
|
47
|
-
replayed: boolean;
|
|
48
|
-
}>;
|
|
49
|
-
export declare function readRuntimeSession(sessionId: string): RuntimeSessionRecord | null;
|
|
50
|
-
export declare function runtimeSessionChildren(parentSessionId: string, runtimeOwner?: string): RuntimeSessionRecord[];
|