@scotthuang/agent-knock-knock 0.15.0 → 0.16.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 +9 -0
- package/connectors/deepseek-harness/README.md +36 -10
- package/connectors/pi/README.md +25 -9
- package/dist/src/claude-conversation-routing-cli-adapter.js +5 -1
- package/dist/src/claude-conversation-routing-cli-adapter.js.map +1 -1
- package/dist/src/claude-managed-send-route.js +6 -3
- package/dist/src/claude-managed-send-route.js.map +1 -1
- package/dist/src/cli-core.js +7 -4
- package/dist/src/cli-core.js.map +1 -1
- package/dist/src/cli-usage.js +1 -0
- package/dist/src/cli-usage.js.map +1 -1
- package/dist/src/conversation-list.js +16 -5
- package/dist/src/conversation-list.js.map +1 -1
- package/dist/src/conversation-routing-cli-adapter.js +49 -2
- package/dist/src/conversation-routing-cli-adapter.js.map +1 -1
- package/dist/src/host-adapter.js +3 -2
- package/dist/src/host-adapter.js.map +1 -1
- package/dist/src/managed-session.d.ts +11 -0
- package/dist/src/managed-session.js +24 -1
- package/dist/src/managed-session.js.map +1 -1
- package/dist/src/native-store-authority-cli-adapter.d.ts +20 -0
- package/dist/src/native-store-authority-cli-adapter.js +105 -0
- package/dist/src/native-store-authority-cli-adapter.js.map +1 -0
- package/dist/src/native-store-authority-ledger.d.ts +3 -0
- package/dist/src/native-store-authority-ledger.js +46 -0
- package/dist/src/native-store-authority-ledger.js.map +1 -0
- package/dist/src/native-store-authority-projection.d.ts +6 -0
- package/dist/src/native-store-authority-projection.js +68 -0
- package/dist/src/native-store-authority-projection.js.map +1 -0
- package/dist/src/native-store-authority-runtime.d.ts +9 -0
- package/dist/src/native-store-authority-runtime.js +77 -0
- package/dist/src/native-store-authority-runtime.js.map +1 -0
- package/dist/src/native-store-authority-transfer.d.ts +31 -0
- package/dist/src/native-store-authority-transfer.js +172 -0
- package/dist/src/native-store-authority-transfer.js.map +1 -0
- package/dist/src/native-store-authority-watch.d.ts +9 -0
- package/dist/src/native-store-authority-watch.js +43 -0
- package/dist/src/native-store-authority-watch.js.map +1 -0
- package/dist/src/native-store-authority.d.ts +29 -0
- package/dist/src/native-store-authority.js +181 -0
- package/dist/src/native-store-authority.js.map +1 -0
- package/dist/src/semantic-tool-descriptions.js +5 -5
- package/dist/src/semantic-tool-descriptions.js.map +1 -1
- package/dist/src/semantic-tool-list-projection.js +13 -3
- package/dist/src/semantic-tool-list-projection.js.map +1 -1
- package/dist/src/semantic-tool-private-authority.d.ts +5 -0
- package/dist/src/semantic-tool-private-authority.js +55 -3
- package/dist/src/semantic-tool-private-authority.js.map +1 -1
- package/dist/src/semantic-tool-relay.d.ts +1 -0
- package/dist/src/semantic-tool-relay.js +12 -5
- package/dist/src/semantic-tool-relay.js.map +1 -1
- package/dist/src/semantic-tool-runtime.js +5 -37
- package/dist/src/semantic-tool-runtime.js.map +1 -1
- package/dist/src/semantic-tool-schemas.d.ts +25 -0
- package/dist/src/semantic-tool-schemas.js +16 -4
- package/dist/src/semantic-tool-schemas.js.map +1 -1
- package/dist/src/session-store.js +5 -1
- package/dist/src/session-store.js.map +1 -1
- package/dist/src/store-owner-identity.d.ts +24 -0
- package/dist/src/store-owner-identity.js +127 -0
- package/dist/src/store-owner-identity.js.map +1 -0
- package/dist/src/store-owner-process.d.ts +24 -0
- package/dist/src/store-owner-process.js +104 -0
- package/dist/src/store-owner-process.js.map +1 -0
- package/dist/src/store-owner-registry.d.ts +13 -0
- package/dist/src/store-owner-registry.js +158 -0
- package/dist/src/store-owner-registry.js.map +1 -0
- package/dist/src/store.d.ts +3 -1
- package/dist/src/store.js +5 -2
- package/dist/src/store.js.map +1 -1
- package/dist/src/terminal-action-contracts.js +18 -2
- package/dist/src/terminal-action-contracts.js.map +1 -1
- package/dist/src/terminal-action-projection.d.ts +1 -1
- package/dist/src/terminal-action-projection.js.map +1 -1
- package/dist/src/terminal-dispatch-ledger-codec.js +1 -1
- package/dist/src/terminal-dispatch-ledger-codec.js.map +1 -1
- package/dist/src/terminal-dispatch-recovery-cli-adapter.js +2 -21
- package/dist/src/terminal-dispatch-recovery-cli-adapter.js.map +1 -1
- package/dist/src/terminal-dispatch-repository-cli-adapter.d.ts +3 -1
- package/dist/src/terminal-dispatch-repository-cli-adapter.js +3 -2
- package/dist/src/terminal-dispatch-repository-cli-adapter.js.map +1 -1
- package/dist/src/terminal-human-explicit-send-cli-adapter.js +3 -0
- package/dist/src/terminal-human-explicit-send-cli-adapter.js.map +1 -1
- package/dist/src/terminal-list-cli-adapter.js +8 -5
- package/dist/src/terminal-list-cli-adapter.js.map +1 -1
- package/dist/src/terminal-list-ownership-service.d.ts +1 -0
- package/dist/src/terminal-list-ownership-service.js +21 -0
- package/dist/src/terminal-list-ownership-service.js.map +1 -1
- package/dist/src/terminal-list-projection-service.js +2 -1
- package/dist/src/terminal-list-projection-service.js.map +1 -1
- package/dist/src/terminal-mutation-cli-runtime.d.ts +7 -2
- package/dist/src/terminal-mutation-cli-runtime.js +11 -3
- package/dist/src/terminal-mutation-cli-runtime.js.map +1 -1
- package/dist/src/terminal-permission-control-cli-adapter.js +7 -0
- package/dist/src/terminal-permission-control-cli-adapter.js.map +1 -1
- package/dist/src/terminal-permission-control-list-projection.d.ts +1 -1
- package/dist/src/terminal-status-cli-adapter.js +1 -0
- package/dist/src/terminal-status-cli-adapter.js.map +1 -1
- package/dist/src/terminal-status-facts.d.ts +1 -0
- package/dist/src/terminal-status-facts.js +8 -1
- package/dist/src/terminal-status-facts.js.map +1 -1
- package/dist/src/terminal-watch-cli-adapter.js +3 -2
- package/dist/src/terminal-watch-cli-adapter.js.map +1 -1
- package/dist/src/terminal-watch-response-cli-adapter.js +9 -0
- package/dist/src/terminal-watch-response-cli-adapter.js.map +1 -1
- package/docs/bidirectional-agent-protocol.md +1 -1
- package/docs/callback-compatibility.md +2 -1
- package/docs/claude-cli-direct.md +12 -0
- package/docs/operator-guide.md +56 -1
- package/docs/storage-and-logging.md +10 -5
- package/docs/testing.md +4 -2
- package/package.json +1 -1
- package/templates/openclaw-skills/agent-knock-knock/SKILL.md +6 -3
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { writeCliStdout } from "./cli-runtime-context.js";
|
|
2
|
+
import { assertNativeStoreAuthorityCurrent, canonicalAuthorityStore, inspectNativeStoreAuthority } from "./native-store-authority.js";
|
|
3
|
+
import { completedNativeStoreAuthorityReceipt, recoverNativeStoreAuthorityWhileLocked, transferNativeStoreAuthorityWhileLocked } from "./native-store-authority-transfer.js";
|
|
4
|
+
import { sameTerminalControlIncarnation } from "./terminal-control-ref.js";
|
|
5
|
+
import { nonBlankString, recordValue } from "./value-guards.js";
|
|
6
|
+
function assertLiveNativeIdentity(identity, inspected) {
|
|
7
|
+
const binding = inspected.session?.binding;
|
|
8
|
+
if (!nonBlankString(identity?.sessionId) || !nonBlankString(identity?.processUuid) ||
|
|
9
|
+
identity.sessionId !== binding?.native_thread_id ||
|
|
10
|
+
identity.processUuid !== binding?.native_process.process_uuid) {
|
|
11
|
+
throw new Error("native thread process incarnation cannot be verified; transfer refused; no input sent");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
async function proveLiveTransferTerminal(options, current, inspected, bridge, ports) {
|
|
15
|
+
if (current.agent !== inspected.session?.agent || current.pid !== inspected.session.binding?.native_process.pid) {
|
|
16
|
+
throw new Error("native thread process incarnation changed; transfer refused; no input sent");
|
|
17
|
+
}
|
|
18
|
+
const request = { options, agent: current.agent, pid: current.pid, cwd: current.terminalControl.currentPath };
|
|
19
|
+
assertLiveNativeIdentity(await ports.identity(request), inspected);
|
|
20
|
+
const status = await bridge.status(current.agent, current.terminalControl, { runtime: { pid: current.pid } });
|
|
21
|
+
if (!status.reachable || status.activity_state !== "idle" ||
|
|
22
|
+
!status.approval_state.scanned || status.approval_state.blocked) {
|
|
23
|
+
throw new Error("terminal must be reachable, idle and without a pending approval before authority transfer; no input sent");
|
|
24
|
+
}
|
|
25
|
+
// A human can change native context while the read-only screen capture awaits.
|
|
26
|
+
assertLiveNativeIdentity(await ports.identity(request), inspected);
|
|
27
|
+
}
|
|
28
|
+
async function observeLiveStoreAuthority(input, initial, ports) {
|
|
29
|
+
if (!initial.session?.binding) {
|
|
30
|
+
throw new Error(`Store authority cannot be verified: ${initial.reason ?? initial.state}; no input sent`);
|
|
31
|
+
}
|
|
32
|
+
const options = input.options ?? {};
|
|
33
|
+
const bridge = ports.createBridge(options);
|
|
34
|
+
const current = await bridge.resolveStoredTerminal(initial.session.agent, initial.session.binding.native_process.pid, input.terminalControl);
|
|
35
|
+
if (current.agent !== initial.session.agent || current.pid !== initial.session.binding.native_process.pid ||
|
|
36
|
+
!sameTerminalControlIncarnation(current.terminalControl, input.terminalControl)) {
|
|
37
|
+
throw new Error("terminal incarnation changed before Store authority verification; no input sent");
|
|
38
|
+
}
|
|
39
|
+
const identity = await ports.identity({ options, agent: current.agent, pid: current.pid,
|
|
40
|
+
cwd: current.terminalControl.currentPath });
|
|
41
|
+
if (!nonBlankString(identity?.sessionId) || !nonBlankString(identity?.processUuid)) {
|
|
42
|
+
throw new Error("native thread process incarnation cannot be verified; no input sent");
|
|
43
|
+
}
|
|
44
|
+
const freshInput = { ...input, nativeThreadId: identity.sessionId, ledger: ports.repository.load(input.terminalControl) };
|
|
45
|
+
return { bridge, current, freshInput };
|
|
46
|
+
}
|
|
47
|
+
/** The caller holds the physical terminal lock; stale action tokens cannot bypass Store ownership. */
|
|
48
|
+
export async function recoverNativeStoreAuthorityForCli(input, ports) {
|
|
49
|
+
const initial = inspectNativeStoreAuthority({ ...input, ledger: ports.repository.load(input.terminalControl) });
|
|
50
|
+
if (initial.state === "none" || initial.state === "current")
|
|
51
|
+
return;
|
|
52
|
+
const { bridge, current, freshInput } = await observeLiveStoreAuthority(input, initial, ports);
|
|
53
|
+
const inspected = inspectNativeStoreAuthority(freshInput);
|
|
54
|
+
if (inspected.state === "none" || inspected.state === "current")
|
|
55
|
+
return;
|
|
56
|
+
const journal = recordValue(freshInput.ledger?.store_authority_transfer);
|
|
57
|
+
const pendingAutomatic = journal?.automatic === true && journal.phase !== "committed" &&
|
|
58
|
+
journal.target_store_dir === canonicalAuthorityStore(input.storeDir);
|
|
59
|
+
if (!inspected.automaticEligible && !pendingAutomatic)
|
|
60
|
+
assertNativeStoreAuthorityCurrent(freshInput);
|
|
61
|
+
if (!inspected.transferEligible) {
|
|
62
|
+
throw new Error(`automatic Store authority recovery refused: ${inspected.reason ?? inspected.state}; no input sent`);
|
|
63
|
+
}
|
|
64
|
+
await proveLiveTransferTerminal(input.options ?? {}, current, inspected, bridge, ports);
|
|
65
|
+
recoverNativeStoreAuthorityWhileLocked(input, ports.repository);
|
|
66
|
+
assertNativeStoreAuthorityCurrent({ ...freshInput, ledger: ports.repository.load(input.terminalControl) });
|
|
67
|
+
}
|
|
68
|
+
export async function runNativeStoreAuthorityTransferCli(options, ports) {
|
|
69
|
+
const terminalId = nonBlankString(options.terminal ?? options.conversation);
|
|
70
|
+
const token = nonBlankString(options.expectedAuthorityToken);
|
|
71
|
+
if (!terminalId || !token)
|
|
72
|
+
throw new Error("transfer-store-authority requires --terminal and the fresh displayed --expected-authority-token");
|
|
73
|
+
const bridge = ports.createBridge(options);
|
|
74
|
+
const initial = await bridge.resolveConversationId(terminalId);
|
|
75
|
+
if (!initial || initial.conversationId !== terminalId)
|
|
76
|
+
throw new Error("use the exact terminal_id from AKK list");
|
|
77
|
+
const storeDir = ports.storeDir(options);
|
|
78
|
+
const release = ports.repository.acquire(storeDir, initial.terminalControl);
|
|
79
|
+
try {
|
|
80
|
+
const current = await bridge.resolveConversationId(terminalId);
|
|
81
|
+
if (!current || current.pid !== initial.pid ||
|
|
82
|
+
!sameTerminalControlIncarnation(current.terminalControl, initial.terminalControl)) {
|
|
83
|
+
throw new Error("terminal incarnation changed; refresh AKK list");
|
|
84
|
+
}
|
|
85
|
+
const request = { storeDir, terminalControl: current.terminalControl,
|
|
86
|
+
expectedAuthorityToken: token, maintenanceAcknowledgement: options.maintenanceAcknowledgement === true };
|
|
87
|
+
const ledger = ports.repository.load(current.terminalControl);
|
|
88
|
+
if (ledger && !ports.repository.matchesControl(ledger, current.terminalControl)) {
|
|
89
|
+
throw new Error("Store authority terminal incarnation changed; refresh AKK list; no input sent");
|
|
90
|
+
}
|
|
91
|
+
const completed = completedNativeStoreAuthorityReceipt(request, ledger);
|
|
92
|
+
if (completed) {
|
|
93
|
+
writeCliStdout(JSON.stringify({ ...completed, terminal_id: terminalId, terminal_input_sent: false }, null, 2) + "\n");
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const inspected = inspectNativeStoreAuthority({ ...request, ledger });
|
|
97
|
+
await proveLiveTransferTerminal(options, current, inspected, bridge, ports);
|
|
98
|
+
const result = transferNativeStoreAuthorityWhileLocked(request, ports.repository);
|
|
99
|
+
writeCliStdout(JSON.stringify({ ...result, terminal_id: terminalId, terminal_input_sent: false }, null, 2) + "\n");
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
release();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=native-store-authority-cli-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-store-authority-cli-adapter.js","sourceRoot":"","sources":["../../src/native-store-authority-cli-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAI1D,OAAO,EAAE,iCAAiC,EAAE,uBAAuB,EAAE,2BAA2B,EAAuC,MAAM,6BAA6B,CAAC;AAC3K,OAAO,EAAE,oCAAoC,EAAE,sCAAsC,EAAE,uCAAuC,EAAE,MAAM,sCAAsC,CAAC;AAC7K,OAAO,EAAE,8BAA8B,EAA2B,MAAM,2BAA2B,CAAC;AACpG,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAchE,SAAS,wBAAwB,CAAC,QAA4C,EAC5E,SAAyC;IACzC,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO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AG,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;QACtE,MAAM,yBAAyB,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QAC5E,MAAM,MAAM,GAAG,uCAAuC,CAAC,OAAO,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;QAClF,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,mBAAmB,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACrH,CAAC;YAAS,CAAC;QAAC,OAAO,EAAE,CAAC;IAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { TerminalDispatchLedgerDocument as Ledger } from "./terminal-dispatch-ledger-codec.js";
|
|
2
|
+
/** Repository-level fence also catches delayed writers that passed preflight earlier. */
|
|
3
|
+
export declare function stampNativeStoreAuthority(previous: Ledger | undefined, incoming: Ledger, transferWrite: boolean): Ledger;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { cliEnv } from "./cli-runtime-context.js";
|
|
2
|
+
import { canonicalAuthorityStore, nativeAuthorityStore, nativeAuthorityThreadIds } from "./native-store-authority.js";
|
|
3
|
+
import { captureStoreOwnerIdentity, isStoreOwnerIdentity } from "./store-owner-identity.js";
|
|
4
|
+
import { registerStoreOwnerIdentity } from "./store-owner-registry.js";
|
|
5
|
+
import { recordValue } from "./value-guards.js";
|
|
6
|
+
/** Repository-level fence also catches delayed writers that passed preflight earlier. */
|
|
7
|
+
export function stampNativeStoreAuthority(previous, incoming, transferWrite) {
|
|
8
|
+
const priorTransfer = recordValue(previous?.store_authority_transfer);
|
|
9
|
+
const store = nativeAuthorityStore(incoming);
|
|
10
|
+
const previousStore = previous && nativeAuthorityStore(previous);
|
|
11
|
+
const ids = nativeAuthorityThreadIds(incoming);
|
|
12
|
+
const priorIds = previous ? nativeAuthorityThreadIds(previous) : [];
|
|
13
|
+
const sameThread = ids.some(id => priorIds.includes(id));
|
|
14
|
+
if (!transferWrite)
|
|
15
|
+
assertAuthorityWriteAllowed({ priorTransfer, previousStore, store, sameThread, hasIds: ids.length > 0 });
|
|
16
|
+
if (!store || !ids.length)
|
|
17
|
+
return incoming;
|
|
18
|
+
const priorAuthority = recordValue(previous?.store_authority);
|
|
19
|
+
const sameStore = previousStore === canonicalAuthorityStore(store);
|
|
20
|
+
// A transfer journal retains the source owner until the destination commit.
|
|
21
|
+
if (transferWrite)
|
|
22
|
+
return incoming;
|
|
23
|
+
const owner = captureStoreOwnerIdentity(store, cliEnv());
|
|
24
|
+
registerStoreOwnerIdentity(owner);
|
|
25
|
+
return { ...incoming,
|
|
26
|
+
store_authority: sameStore && sameThread && isStoreOwnerIdentity(priorAuthority?.owner)
|
|
27
|
+
? priorAuthority
|
|
28
|
+
: { version: 1, generation: Number(priorAuthority?.generation ?? 0) + 1,
|
|
29
|
+
store_dir: store, owner,
|
|
30
|
+
...(sameStore && sameThread ? { legacy_owner_coverage: true } : {}) },
|
|
31
|
+
...(sameStore && sameThread && priorTransfer ? { store_authority_transfer: priorTransfer } : {})
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function assertAuthorityWriteAllowed(facts) {
|
|
35
|
+
const { priorTransfer, previousStore, store, sameThread, hasIds } = facts;
|
|
36
|
+
if (priorTransfer && priorTransfer.phase !== "committed") {
|
|
37
|
+
throw new Error("Store authority transfer is incomplete; refresh AKK list and resume transfer_store_authority; no terminal input is permitted");
|
|
38
|
+
}
|
|
39
|
+
if (previousStore && store !== previousStore && sameThread) {
|
|
40
|
+
throw new Error("native thread Store authority changed; refusing a stale writer; refresh AKK list");
|
|
41
|
+
}
|
|
42
|
+
if (priorTransfer && (!store || !hasIds)) {
|
|
43
|
+
throw new Error("a Store authority transfer cannot be erased by a stale ledger write");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=native-store-authority-ledger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-store-authority-ledger.js","sourceRoot":"","sources":["../../src/native-store-authority-ledger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AACtH,OAAO,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAC5F,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AAEvE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,yFAAyF;AACzF,MAAM,UAAU,yBAAyB,CAAC,QAA4B,EAAE,QAAgB,EACtF,aAAsB;IACtB,MAAM,aAAa,GAAG,WAAW,CAAC,QAAQ,EAAE,wBAAwB,CAAC,CAAC;IACtE,MAAM,KAAK,GAAG,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IAC7C,MAAM,aAAa,GAAG,QAAQ,IAAI,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IACjE,MAAM,GAAG,GAAG,wBAAwB,CAAC,QAAQ,CAAC,CAAC;IAC/C,MAAM,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,wBAAwB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACpE,MAAM,UAAU,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;IACzD,IAAI,CAAC,aAAa;QAAE,2BAA2B,CAAC,EAAE,aAAa,EAAE,aAAa,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,CAAC;IAC7H,IAAI,CAAC,KAAK,IAAI,CAAC,GAAG,CAA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,CAAC;QAC3D,MAAM,IAAI,KAAK,CAAC,kFAAkF,CAAC,CAAC;IACtG,CAAC;IACD,IAAI,aAAa,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACzC,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;IACzF,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type Row = Record<string, unknown>;
|
|
2
|
+
/** Apply a verified Store conflict after ordinary action selection, including physical Send overrides. */
|
|
3
|
+
export declare function withNativeStoreAuthorityConflict(row: Row, authorityValue: unknown, recoveryActions?: Row): Row;
|
|
4
|
+
/** Keep authority fingerprints private while publishing the independently authorized transfer offer. */
|
|
5
|
+
export declare function projectNativeStoreAuthority(terminal: Row, observationValue: unknown, mutationsAllowed: boolean): Row;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { nonBlankString, recordValue } from "./value-guards.js";
|
|
2
|
+
const readActions = new Set(["status", "watch", "list_resumable_threads"]);
|
|
3
|
+
const readCapabilities = new Set(["status", "watch", "list_resumable_threads", "interaction_notify"]);
|
|
4
|
+
function readOnlyActions(value) {
|
|
5
|
+
return Object.fromEntries(Object.entries(recordValue(value) ?? {}).filter(([name]) => readActions.has(name)));
|
|
6
|
+
}
|
|
7
|
+
function readOnlyManagedRecord(value) {
|
|
8
|
+
const record = recordValue(value);
|
|
9
|
+
if (!record)
|
|
10
|
+
return value;
|
|
11
|
+
return { ...record, ...(record.actionable !== undefined ? { actionable: false } : {}), ...(record.available_actions ? {
|
|
12
|
+
available_actions: readOnlyActions(record.available_actions)
|
|
13
|
+
} : {}) };
|
|
14
|
+
}
|
|
15
|
+
function readOnlyManagement(value) {
|
|
16
|
+
const managed = recordValue(value);
|
|
17
|
+
if (!managed)
|
|
18
|
+
return undefined;
|
|
19
|
+
return { ...managed,
|
|
20
|
+
...(managed.current_turn ? { current_turn: readOnlyManagedRecord(managed.current_turn) } : {}),
|
|
21
|
+
...(managed.recent_turn ? { recent_turn: readOnlyManagedRecord(managed.recent_turn) } : {}),
|
|
22
|
+
...(Array.isArray(managed.history) ? { history: managed.history.map(readOnlyManagedRecord) } : {}) };
|
|
23
|
+
}
|
|
24
|
+
/** Apply a verified Store conflict after ordinary action selection, including physical Send overrides. */
|
|
25
|
+
export function withNativeStoreAuthorityConflict(row, authorityValue, recoveryActions = {}) {
|
|
26
|
+
const authority = recordValue(authorityValue);
|
|
27
|
+
if (!authority || !["conflict", "transferring"].includes(String(authority.state)))
|
|
28
|
+
return row;
|
|
29
|
+
const send = authority.send_after_transfer === true ? recordValue(recordValue(row.available_actions)?.send) : undefined;
|
|
30
|
+
const capabilities = Object.fromEntries(Object.entries(recordValue(row.capabilities) ?? {})
|
|
31
|
+
.map(([key, value]) => [key, readCapabilities.has(key) ? value : false]));
|
|
32
|
+
const { handoff_decision: _handoff, send_blocked_reason: _sendBlocked, ...safe } = row;
|
|
33
|
+
const managed = readOnlyManagement(row.managed);
|
|
34
|
+
return { ...safe, management_state: "conflict", native_store_authority: authority,
|
|
35
|
+
management_conflict: { code: "native_thread_store_authority", ...authority },
|
|
36
|
+
next_action: recoveryActions.transfer_store_authority ? "transfer_store_authority" : send ? "send" : "inspect_store_authority",
|
|
37
|
+
...(recordValue(row.interaction_hint) ? { interaction_hint: { ...recordValue(row.interaction_hint), actionable: false } } : {}),
|
|
38
|
+
...(row.interaction_state ? { interaction_state: Array.isArray(row.interaction_state)
|
|
39
|
+
? row.interaction_state.map(readOnlyManagedRecord) : readOnlyManagedRecord(row.interaction_state) } : {}),
|
|
40
|
+
...(!send ? { send_blocked_reason: authority.reason ?? "native_thread_store_authority" } : {}),
|
|
41
|
+
capabilities: { ...capabilities, send: Boolean(send), transfer_store_authority: Boolean(recoveryActions.transfer_store_authority) },
|
|
42
|
+
available_actions: { ...readOnlyActions(row.available_actions), ...(send ? { send } : {}), ...recoveryActions },
|
|
43
|
+
...(managed ? { managed } : {}) };
|
|
44
|
+
}
|
|
45
|
+
/** Keep authority fingerprints private while publishing the independently authorized transfer offer. */
|
|
46
|
+
export function projectNativeStoreAuthority(terminal, observationValue, mutationsAllowed) {
|
|
47
|
+
const observation = recordValue(observationValue);
|
|
48
|
+
if (!observation || !["conflict", "transferring"].includes(String(observation.state)))
|
|
49
|
+
return terminal;
|
|
50
|
+
const authority = { state: observation.state, reason: observation.reason,
|
|
51
|
+
source_store_dir: observation.sourceStoreDir, session_id: observation.sessionId,
|
|
52
|
+
generation: observation.generation, owner_status: observation.ownerStatus,
|
|
53
|
+
transfer_eligible: observation.transferEligible === true,
|
|
54
|
+
automatic_eligible: observation.automaticEligible === true,
|
|
55
|
+
send_after_transfer: observation.automaticEligible === true && mutationsAllowed &&
|
|
56
|
+
!terminal.management_conflict && !terminal.management_unavailable &&
|
|
57
|
+
!["conflict", "unavailable"].includes(String(terminal.management_state)) &&
|
|
58
|
+
Boolean(recordValue(recordValue(terminal.available_actions)?.send)) };
|
|
59
|
+
const fingerprint = nonBlankString(observation.fingerprint);
|
|
60
|
+
const id = nonBlankString(terminal.id ?? terminal.conversation_id);
|
|
61
|
+
const recovery = mutationsAllowed && observation.transferEligible === true && fingerprint && id
|
|
62
|
+
? { transfer_store_authority: { tool: "agent_knock_knock_reconcile_binding", requires_user_intent: true,
|
|
63
|
+
...(observation.ownerStatus === "legacy" ? { missing_required: ["maintenance_acknowledgement"] } : {}),
|
|
64
|
+
arguments: { operation: "transfer_store_authority", terminal_id: id, expected_authority_token: fingerprint } } }
|
|
65
|
+
: {};
|
|
66
|
+
return withNativeStoreAuthorityConflict(terminal, authority, recovery);
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=native-store-authority-projection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-store-authority-projection.js","sourceRoot":"","sources":["../../src/native-store-authority-projection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAA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AC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC;IAC1E,MAAM,WAAW,GAAG,cAAc,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;IAC5D,MAAM,EAAE,GAAG,cAAc,CAAC,QAAQ,CAAC,EAAE,IAAI,QAAQ,CAAC,eAAe,CAAC,CAAC;IACnE,MAAM,QAAQ,GAAG,gBAAgB,IAAI,WAAW,CAAC,gBAAgB,KAAK,IAAI,IAAI,WAAW,IAAI,EAAE;QAC7F,CAAC,CAAC,EAAE,wBAAwB,EAAE,EAAE,IAAI,EAAE,qCAAqC,EAAE,oBAAoB,EAAE,IAAI;gBACnG,GAAG,CAAC,WAAW,CAAC,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAAC,6BAA6B,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACtG,SAAS,EAAE,EAAE,SAAS,EAAE,0BAA0B,EAAE,WAAW,EAAE,EAAE,EAAE,wBAAwB,EAAE,WAAW,EAAE,EAAE,EAAE;QACpH,CAAC,CAAC,EAAE,CAAC;IACP,OAAO,gCAAgC,CAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;AACzE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface RuntimeAuthorityRequest {
|
|
2
|
+
nativeThreadId: string;
|
|
3
|
+
storeDir: string;
|
|
4
|
+
runtimeDir: string;
|
|
5
|
+
}
|
|
6
|
+
/** Native backend access must not bypass an existing managed terminal authority. */
|
|
7
|
+
export declare function assertNativeRuntimeStoreAuthority(input: RuntimeAuthorityRequest): void;
|
|
8
|
+
export declare function withNativeRuntimeStoreAuthority<T>(input: RuntimeAuthorityRequest, action: () => Promise<T>): Promise<T>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { readJsonFileNoFollow } from "./durable-json-file.js";
|
|
4
|
+
import { nativeAuthorityStore, nativeAuthorityThreadIds, canonicalAuthorityStore } from "./native-store-authority.js";
|
|
5
|
+
import { associateTerminalEndpointEvidence } from "./terminal-control-ref.js";
|
|
6
|
+
import { createTerminalDispatchRepositoryCliAdapter } from "./terminal-dispatch-repository-cli-adapter.js";
|
|
7
|
+
import { captureStoreOwnerIdentity } from "./store-owner-identity.js";
|
|
8
|
+
import { registerStoreOwnerIdentity } from "./store-owner-registry.js";
|
|
9
|
+
import { withStoreWriterLease } from "./store.js";
|
|
10
|
+
import { cliEnv } from "./cli-runtime-context.js";
|
|
11
|
+
import { recordValue } from "./value-guards.js";
|
|
12
|
+
function matchingLedgers(input) {
|
|
13
|
+
const directory = path.join(input.runtimeDir, "terminal-dispatch");
|
|
14
|
+
let names;
|
|
15
|
+
try {
|
|
16
|
+
names = fs.readdirSync(directory);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
if (error.code === "ENOENT")
|
|
20
|
+
return [];
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
return names.filter(name => /^terminal-dispatch-[0-9a-f]+\.json$/u.test(name)).flatMap(name => {
|
|
24
|
+
const ledger = recordValue(readJsonFileNoFollow(path.join(directory, name), "terminal authority ledger"));
|
|
25
|
+
if (!ledger)
|
|
26
|
+
throw new Error("terminal authority ledger is unreadable; refusing native mutation");
|
|
27
|
+
return nativeAuthorityThreadIds(ledger).includes(input.nativeThreadId.toLowerCase()) ? [ledger] : [];
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/** Native backend access must not bypass an existing managed terminal authority. */
|
|
31
|
+
export function assertNativeRuntimeStoreAuthority(input) {
|
|
32
|
+
for (const ledger of matchingLedgers(input)) {
|
|
33
|
+
const transfer = recordValue(ledger.store_authority_transfer);
|
|
34
|
+
if (nativeAuthorityStore(ledger) !== canonicalAuthorityStore(input.storeDir) || transfer && transfer.phase !== "committed") {
|
|
35
|
+
throw new Error("native thread has conflicting or transferring Store authority; refresh AKK list and use " +
|
|
36
|
+
"transfer_store_authority (agent_knock_knock_reconcile_binding operation=transfer_store_authority); no native input sent");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function ledgerControl(ledger) {
|
|
41
|
+
const value = recordValue(ledger.terminal_control);
|
|
42
|
+
if (!value || !["herdr", "tmux"].includes(String(value.kind)))
|
|
43
|
+
throw new Error("unverified authority terminal control");
|
|
44
|
+
const common = { target: String(value.target), session: String(value.session ?? ""),
|
|
45
|
+
socketPath: typeof value.socket_path === "string" ? value.socket_path : undefined,
|
|
46
|
+
panePid: Number(value.pane_pid), capabilities: [] };
|
|
47
|
+
const control = value.kind === "herdr" ? { ...common, kind: "herdr",
|
|
48
|
+
workspaceId: String(value.workspace_id), tabId: String(value.tab_id), paneId: String(value.pane_id),
|
|
49
|
+
terminalId: String(value.terminal_id), sessionDir: typeof value.session_dir === "string" ? value.session_dir : undefined }
|
|
50
|
+
: { ...common, kind: "tmux", window: 0, pane: 0 };
|
|
51
|
+
return ledger.terminal_endpoint ? associateTerminalEndpointEvidence(control, ledger.terminal_endpoint) : control;
|
|
52
|
+
}
|
|
53
|
+
export async function withNativeRuntimeStoreAuthority(input, action) {
|
|
54
|
+
const repository = createTerminalDispatchRepositoryCliAdapter();
|
|
55
|
+
if (path.resolve(input.runtimeDir) !== path.resolve(repository.runtimeDir()))
|
|
56
|
+
throw new Error("native authority runtime namespace changed");
|
|
57
|
+
const controls = [...new Map(matchingLedgers(input).map(ledger => {
|
|
58
|
+
const control = ledgerControl(ledger);
|
|
59
|
+
return [repository.runtimeKey(control), control];
|
|
60
|
+
})).entries()].sort(([a], [b]) => a.localeCompare(b)).map(([, control]) => control);
|
|
61
|
+
const releases = [];
|
|
62
|
+
try {
|
|
63
|
+
for (const control of controls)
|
|
64
|
+
releases.push(repository.acquire(input.storeDir, control));
|
|
65
|
+
assertNativeRuntimeStoreAuthority(input);
|
|
66
|
+
if (controls.length)
|
|
67
|
+
withStoreWriterLease(input.storeDir, () => {
|
|
68
|
+
registerStoreOwnerIdentity(captureStoreOwnerIdentity(input.storeDir, cliEnv()));
|
|
69
|
+
});
|
|
70
|
+
return await action();
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
for (const release of releases.reverse())
|
|
74
|
+
release();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=native-store-authority-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-store-authority-runtime.js","sourceRoot":"","sources":["../../src/native-store-authority-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtH,OAAO,EAAE,iCAAiC,EAA2B,MAAM,2BAA2B,CAAC;AACvG,OAAO,EAAE,0CAA0C,EAAE,MAAM,+CAA+C,CAAC;AAC3G,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIhD,SAAS,eAAe,CAAC,KAA8B;IACrD,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,mBAAmB,CAAC,CAAC;IACnE,IAAI,KAAe,CAAC;IACpB,IAAI,CAAC;QAAC,KAAK,GAAG,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IAAC,CAAC;IAC1C,OA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C;QACH,OAAO,MAAM,MAAM,EAAE,CAAC;IACxB,CAAC;YAAS,CAAC;QAAC,KAAK,MAAM,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE;YAAE,OAAO,EAAE,CAAC;IAAC,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { TerminalControlRef } from "./terminal-control-ref.js";
|
|
2
|
+
import type { TerminalDispatchLedgerDocument as Ledger } from "./terminal-dispatch-ledger-codec.js";
|
|
3
|
+
import type { TerminalDispatchRepositoryCliAdapter } from "./terminal-dispatch-repository-cli-adapter.js";
|
|
4
|
+
export interface NativeStoreAuthorityTransferRequest {
|
|
5
|
+
storeDir: string;
|
|
6
|
+
terminalControl: TerminalControlRef;
|
|
7
|
+
expectedAuthorityToken?: string;
|
|
8
|
+
maintenanceAcknowledgement?: boolean;
|
|
9
|
+
automatic?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function completedNativeStoreAuthorityReceipt(input: NativeStoreAuthorityTransferRequest, ledger?: Ledger): {
|
|
12
|
+
transferred: true;
|
|
13
|
+
transfer_id: string;
|
|
14
|
+
session_id: string;
|
|
15
|
+
store_dir: string;
|
|
16
|
+
} | undefined;
|
|
17
|
+
/** Caller holds the shared terminal lock. Store leases are deliberately sequential. */
|
|
18
|
+
export declare function transferNativeStoreAuthorityWhileLocked(input: NativeStoreAuthorityTransferRequest, repository: TerminalDispatchRepositoryCliAdapter): {
|
|
19
|
+
transferred: true;
|
|
20
|
+
transfer_id: string;
|
|
21
|
+
session_id: string;
|
|
22
|
+
store_dir: string;
|
|
23
|
+
};
|
|
24
|
+
export declare function transferNativeStoreAuthority(input: NativeStoreAuthorityTransferRequest, repository: TerminalDispatchRepositoryCliAdapter): {
|
|
25
|
+
transferred: true;
|
|
26
|
+
transfer_id: string;
|
|
27
|
+
session_id: string;
|
|
28
|
+
store_dir: string;
|
|
29
|
+
};
|
|
30
|
+
/** Called after the terminal lock and before the destination Store lease. */
|
|
31
|
+
export declare function recoverNativeStoreAuthorityWhileLocked(input: Omit<NativeStoreAuthorityTransferRequest, "automatic">, repository: TerminalDispatchRepositoryCliAdapter): void;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { cliEnv } from "./cli-runtime-context.js";
|
|
3
|
+
import { canonicalJson } from "./canonical-json.js";
|
|
4
|
+
import { loadManagedSession, saveManagedSession, listManagedSessions, tryLoadManagedSession } from "./session-store.js";
|
|
5
|
+
import { withStoreWriterLease } from "./store.js";
|
|
6
|
+
import { captureStoreOwnerIdentity } from "./store-owner-identity.js";
|
|
7
|
+
import { readStoreOwnerInventory, registerStoreOwnerIdentity, probeStoreOwnerInventory } from "./store-owner-registry.js";
|
|
8
|
+
import { canonicalAuthorityStore, inspectNativeStoreAuthority, nativeAuthorityWorkSettled } from "./native-store-authority.js";
|
|
9
|
+
import { recordValue } from "./value-guards.js";
|
|
10
|
+
function readJournal(ledger) {
|
|
11
|
+
const journal = recordValue(ledger.store_authority_transfer);
|
|
12
|
+
if (!journal || journal.phase === "committed")
|
|
13
|
+
return undefined;
|
|
14
|
+
if (journal.version !== 1 || !journal.source_session || !journal.target_session ||
|
|
15
|
+
typeof journal.source_store_dir !== "string" || typeof journal.target_store_dir !== "string" ||
|
|
16
|
+
typeof journal.transfer_id !== "string" || !["prepared", "source_retired", "target_created"].includes(String(journal.phase))) {
|
|
17
|
+
throw new Error("Store authority transfer journal is invalid; preserve evidence and repair it before retrying");
|
|
18
|
+
}
|
|
19
|
+
return journal;
|
|
20
|
+
}
|
|
21
|
+
function verifySourceOwner(journal) {
|
|
22
|
+
const inventory = readStoreOwnerInventory(journal.source_store_dir);
|
|
23
|
+
if (inventory.fingerprint !== journal.source_inventory)
|
|
24
|
+
throw new Error("source Store owner registrations changed during transfer; no input sent");
|
|
25
|
+
if (journal.legacy_acknowledged && inventory.reason === "owner_inventory_absent")
|
|
26
|
+
return;
|
|
27
|
+
if (probeStoreOwnerInventory(inventory).state !== "dead")
|
|
28
|
+
throw new Error("source Store has an active or unverifiable owner; transfer refused; no input sent");
|
|
29
|
+
}
|
|
30
|
+
function prepareJournal(input, ledger) {
|
|
31
|
+
const inspection = inspectNativeStoreAuthority({ ...input, ledger });
|
|
32
|
+
if (!inspection.transferEligible || !inspection.session || !inspection.sourceStoreDir) {
|
|
33
|
+
throw new Error(`Store authority transfer refused: ${inspection.reason ?? inspection.state}; no input sent`);
|
|
34
|
+
}
|
|
35
|
+
if (input.automatic ? !inspection.automaticEligible : inspection.fingerprint !== input.expectedAuthorityToken) {
|
|
36
|
+
throw new Error("Store authority changed or is not automatically reclaimable; refresh AKK list; no input sent");
|
|
37
|
+
}
|
|
38
|
+
if (inspection.ownerStatus === "legacy" && input.maintenanceAcknowledgement !== true) {
|
|
39
|
+
throw new Error("legacy Store owner is unknown; stop all associated Hosts/writers, then explicitly supply maintenance_acknowledgement=true");
|
|
40
|
+
}
|
|
41
|
+
const source = inspection.session;
|
|
42
|
+
const now = new Date().toISOString();
|
|
43
|
+
const id = randomUUID();
|
|
44
|
+
const target = { ...source, revision: undefined, status: "bound",
|
|
45
|
+
binding: { ...source.binding, binding_id: randomUUID(), generation: source.binding.generation + 1,
|
|
46
|
+
bound_at: now, last_verified_at: now },
|
|
47
|
+
updated_at: now, detached_at: undefined, quarantine_reason: undefined,
|
|
48
|
+
authority_transfer: undefined,
|
|
49
|
+
authority_received: { transfer_id: id, source_store_dir: inspection.sourceStoreDir, received_at: now } };
|
|
50
|
+
return { version: 1, transfer_id: id, phase: "prepared", source_store_dir: inspection.sourceStoreDir,
|
|
51
|
+
target_store_dir: canonicalAuthorityStore(input.storeDir),
|
|
52
|
+
source_inventory: readStoreOwnerInventory(inspection.sourceStoreDir).fingerprint,
|
|
53
|
+
source_session: source, target_session: JSON.parse(JSON.stringify(target)),
|
|
54
|
+
generation: (inspection.generation ?? 1) + 1,
|
|
55
|
+
automatic: input.automatic === true, legacy_acknowledged: inspection.ownerStatus === "legacy",
|
|
56
|
+
started_at: now, initial_authority_token: input.expectedAuthorityToken };
|
|
57
|
+
}
|
|
58
|
+
export function completedNativeStoreAuthorityReceipt(input, ledger) {
|
|
59
|
+
const journal = recordValue(ledger?.store_authority_transfer);
|
|
60
|
+
if (!journal || journal.phase !== "committed" || journal.target_store_dir !== canonicalAuthorityStore(input.storeDir) ||
|
|
61
|
+
(input.automatic ? journal.automatic !== true : !input.expectedAuthorityToken || input.expectedAuthorityToken !== journal.initial_authority_token))
|
|
62
|
+
return undefined;
|
|
63
|
+
return { transferred: true, transfer_id: String(journal.transfer_id),
|
|
64
|
+
session_id: String(recordValue(journal.target_session)?.session_id), store_dir: String(journal.target_store_dir) };
|
|
65
|
+
}
|
|
66
|
+
function targetAvailable(journal) {
|
|
67
|
+
const existing = listManagedSessions(journal.target_store_dir);
|
|
68
|
+
for (const session of existing) {
|
|
69
|
+
if ((session.session_id === journal.target_session.session_id ||
|
|
70
|
+
session.binding?.native_thread_id === journal.target_session.binding?.native_thread_id) &&
|
|
71
|
+
session.authority_received?.transfer_id !== journal.transfer_id) {
|
|
72
|
+
throw new Error("destination Store already has a competing Session; transfer refused");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** Caller holds the shared terminal lock. Store leases are deliberately sequential. */
|
|
77
|
+
export function transferNativeStoreAuthorityWhileLocked(input, repository) {
|
|
78
|
+
let ledger = repository.load(input.terminalControl);
|
|
79
|
+
if (!ledger || !repository.matchesControl(ledger, input.terminalControl)) {
|
|
80
|
+
throw new Error("Store authority terminal incarnation changed; refresh AKK list; no input sent");
|
|
81
|
+
}
|
|
82
|
+
const completed = completedNativeStoreAuthorityReceipt(input, ledger);
|
|
83
|
+
if (completed)
|
|
84
|
+
return completed;
|
|
85
|
+
let journal = readJournal(ledger);
|
|
86
|
+
if (journal) {
|
|
87
|
+
const inspection = inspectNativeStoreAuthority({ ...input, ledger });
|
|
88
|
+
if (canonicalAuthorityStore(input.storeDir) !== journal.target_store_dir ||
|
|
89
|
+
(input.automatic ? !journal.automatic : inspection.fingerprint !== input.expectedAuthorityToken)) {
|
|
90
|
+
throw new Error("unfinished Store authority transfer belongs to another destination or snapshot");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else
|
|
94
|
+
journal = prepareJournal(input, ledger);
|
|
95
|
+
const transaction = journal;
|
|
96
|
+
const persist = (phase) => {
|
|
97
|
+
transaction.phase = phase;
|
|
98
|
+
ledger = { ...ledger, store_authority_transfer: { ...transaction } };
|
|
99
|
+
repository.save(input.terminalControl, ledger, { authorityTransfer: true });
|
|
100
|
+
};
|
|
101
|
+
// Upgrade/check destination before installing a durable fence. Once prepared,
|
|
102
|
+
// every crash point is resumed by this journal, without any terminal input.
|
|
103
|
+
withStoreWriterLease(transaction.target_store_dir, () => {
|
|
104
|
+
targetAvailable(transaction);
|
|
105
|
+
const owner = captureStoreOwnerIdentity(transaction.target_store_dir, cliEnv());
|
|
106
|
+
registerStoreOwnerIdentity(owner);
|
|
107
|
+
if (!readStoreOwnerInventory(transaction.target_store_dir).complete)
|
|
108
|
+
throw new Error("destination owner inventory is incomplete; source authority unchanged");
|
|
109
|
+
transaction.target_owner ??= owner;
|
|
110
|
+
});
|
|
111
|
+
withStoreWriterLease(transaction.source_store_dir, () => {
|
|
112
|
+
verifySourceOwner(transaction);
|
|
113
|
+
const source = loadManagedSession(transaction.source_store_dir, transaction.source_session.session_id);
|
|
114
|
+
if (source.authority_transfer?.transfer_id === transaction.transfer_id)
|
|
115
|
+
return;
|
|
116
|
+
if (canonicalJson(source) !== canonicalJson(transaction.source_session) ||
|
|
117
|
+
!nativeAuthorityWorkSettled(transaction.source_store_dir, source)) {
|
|
118
|
+
throw new Error("source Session/work changed during authority transfer; no input sent");
|
|
119
|
+
}
|
|
120
|
+
persist("prepared");
|
|
121
|
+
saveManagedSession(transaction.source_store_dir, { ...source, status: "quarantined",
|
|
122
|
+
quarantine_reason: "native Store authority transferred", updated_at: transaction.started_at,
|
|
123
|
+
authority_transfer: { transfer_id: transaction.transfer_id, target_store_dir: transaction.target_store_dir,
|
|
124
|
+
transferred_at: transaction.started_at } }, { expectedRevision: source.revision });
|
|
125
|
+
persist("source_retired");
|
|
126
|
+
});
|
|
127
|
+
withStoreWriterLease(transaction.target_store_dir, () => {
|
|
128
|
+
verifySourceOwner(transaction);
|
|
129
|
+
targetAvailable(transaction);
|
|
130
|
+
const present = tryLoadManagedSession(transaction.target_store_dir, transaction.target_session.session_id);
|
|
131
|
+
const { revision: _revision, ...presentBody } = present ?? {};
|
|
132
|
+
if (present && canonicalJson(presentBody) !== canonicalJson(transaction.target_session)) {
|
|
133
|
+
throw new Error("destination Session changed before authority transfer commit; preserve the journal and inspect the destination");
|
|
134
|
+
}
|
|
135
|
+
if (!present)
|
|
136
|
+
saveManagedSession(transaction.target_store_dir, transaction.target_session, { expectedRevision: null });
|
|
137
|
+
persist("target_created");
|
|
138
|
+
const owner = captureStoreOwnerIdentity(transaction.target_store_dir, cliEnv());
|
|
139
|
+
registerStoreOwnerIdentity(owner);
|
|
140
|
+
const session = loadManagedSession(transaction.target_store_dir, transaction.target_session.session_id);
|
|
141
|
+
// No old Turn is adopted or replayed. Its callback/history stay in source.
|
|
142
|
+
ledger = { status: "resolved", store_dir: transaction.target_store_dir,
|
|
143
|
+
native_thread_id: session.binding.native_thread_id, session_id: session.session_id,
|
|
144
|
+
binding: session.binding, resolved_at: new Date().toISOString(),
|
|
145
|
+
reason: "native Store authority transferred without terminal input",
|
|
146
|
+
store_authority: { version: 1, generation: transaction.generation,
|
|
147
|
+
store_dir: transaction.target_store_dir, owner },
|
|
148
|
+
store_authority_transfer: { ...transaction, phase: "committed" } };
|
|
149
|
+
repository.save(input.terminalControl, ledger, { authorityTransfer: true });
|
|
150
|
+
});
|
|
151
|
+
return { transferred: true, transfer_id: transaction.transfer_id,
|
|
152
|
+
session_id: transaction.target_session.session_id, store_dir: transaction.target_store_dir };
|
|
153
|
+
}
|
|
154
|
+
export function transferNativeStoreAuthority(input, repository) {
|
|
155
|
+
const release = repository.acquire(input.storeDir, input.terminalControl);
|
|
156
|
+
try {
|
|
157
|
+
return transferNativeStoreAuthorityWhileLocked(input, repository);
|
|
158
|
+
}
|
|
159
|
+
finally {
|
|
160
|
+
release();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/** Called after the terminal lock and before the destination Store lease. */
|
|
164
|
+
export function recoverNativeStoreAuthorityWhileLocked(input, repository) {
|
|
165
|
+
const ledger = repository.load(input.terminalControl);
|
|
166
|
+
const inspection = inspectNativeStoreAuthority({ ...input, ledger });
|
|
167
|
+
const journal = ledger && readJournal(ledger);
|
|
168
|
+
if (inspection.automaticEligible || journal?.automatic && journal.target_store_dir === canonicalAuthorityStore(input.storeDir)) {
|
|
169
|
+
transferNativeStoreAuthorityWhileLocked({ ...input, automatic: true }, repository);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=native-store-authority-transfer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-store-authority-transfer.js","sourceRoot":"","sources":["../../src/native-store-authority-transfer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AACxH,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,yBAAyB,EAA2B,MAAM,2BAA2B,CAAC;AAC/F,OAAO,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAC1H,OAAO,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,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AAC,CAAC;IAC9E,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,CAAC,WAAW;QAC9D,UAAU,EAAE,WAAW,CAAC,cAAc,CAAC,UAAU,EAAE,SAAS,EAAE,WAAW,CAAC,gBAAgB,EAAE,CAAC;AACjG,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,KAA0C,EACrF,UAAgD;IAChD,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC;IAC1E,IAAI,CAAC;QAAC,OAAO,uCAAuC,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IAAC,CAAC;YAClE,CAAC;QAAC,OAAO,EAAE,CAAC;IAAC,CAAC;AACxB,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,sCAAsC,CAAC,KAA6D,EAClH,UAAgD;IAChD,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;IACtD,MAAM,UAAU,GAAG,2BAA2B,CAAC,EAAE,GAAG,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;IACrE,MAAM,OAAO,GAAG,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;IAC9C,IAAI,UAAU,CAAC,iBAAiB,IAAI,OAAO,EAAE,SAAS,IAAI,OAAO,CAAC,gBAAgB,KAAK,uBAAuB,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC/H,uCAAuC,CAAC,EAAE,GAAG,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,UAAU,CAAC,CAAC;IACrF,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type TerminalControlRef } from "./terminal-control-ref.js";
|
|
2
|
+
/** Register the creating Host atomically with the Watch's durable authority. */
|
|
3
|
+
export declare function withNativeAuthorityWatchOwner<T>(storeDir: string, create: () => T): T;
|
|
4
|
+
/** Read only: a transfer must retain outstanding Watch observation/callback ownership. */
|
|
5
|
+
export declare function hasOutstandingNativeAuthorityWatch(input: {
|
|
6
|
+
storeDir: string;
|
|
7
|
+
terminalControl: TerminalControlRef;
|
|
8
|
+
nativeThreadId?: string;
|
|
9
|
+
}): boolean;
|