@sentropic/h2a-runtime 0.98.6 → 0.98.7-rc.2

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.
Files changed (130) hide show
  1. package/dist/agent-launch-args.d.ts.map +1 -1
  2. package/dist/agent-launch-args.js +5 -5
  3. package/dist/agent-launch-args.js.map +1 -1
  4. package/dist/agy-claude.d.ts +2 -0
  5. package/dist/agy-claude.d.ts.map +1 -0
  6. package/dist/agy-claude.js +3 -0
  7. package/dist/agy-claude.js.map +1 -0
  8. package/dist/agy-headless.d.ts +11 -0
  9. package/dist/agy-headless.d.ts.map +1 -0
  10. package/dist/agy-headless.js +104 -0
  11. package/dist/agy-headless.js.map +1 -0
  12. package/dist/attach.d.ts +2 -0
  13. package/dist/attach.d.ts.map +1 -1
  14. package/dist/attach.js +73 -6
  15. package/dist/attach.js.map +1 -1
  16. package/dist/auth-login.d.ts +24 -1
  17. package/dist/auth-login.d.ts.map +1 -1
  18. package/dist/auth-login.js +132 -4
  19. package/dist/auth-login.js.map +1 -1
  20. package/dist/central-mcp.d.ts +2 -0
  21. package/dist/central-mcp.d.ts.map +1 -1
  22. package/dist/central-mcp.js +90 -3
  23. package/dist/central-mcp.js.map +1 -1
  24. package/dist/claude-code-cli-isolation.d.ts +53 -0
  25. package/dist/claude-code-cli-isolation.d.ts.map +1 -0
  26. package/dist/claude-code-cli-isolation.js +277 -0
  27. package/dist/claude-code-cli-isolation.js.map +1 -0
  28. package/dist/claude-code-cli-lifecycle.d.ts +80 -0
  29. package/dist/claude-code-cli-lifecycle.d.ts.map +1 -0
  30. package/dist/claude-code-cli-lifecycle.js +402 -0
  31. package/dist/claude-code-cli-lifecycle.js.map +1 -0
  32. package/dist/claude-code-cli-runner.d.ts +89 -0
  33. package/dist/claude-code-cli-runner.d.ts.map +1 -0
  34. package/dist/claude-code-cli-runner.js +659 -0
  35. package/dist/claude-code-cli-runner.js.map +1 -0
  36. package/dist/claude-seat-input.d.ts +47 -0
  37. package/dist/claude-seat-input.d.ts.map +1 -0
  38. package/dist/claude-seat-input.js +272 -0
  39. package/dist/claude-seat-input.js.map +1 -0
  40. package/dist/claude-seat-mesh-contract.d.ts +88 -0
  41. package/dist/claude-seat-mesh-contract.d.ts.map +1 -0
  42. package/dist/claude-seat-mesh-contract.js +13 -0
  43. package/dist/claude-seat-mesh-contract.js.map +1 -0
  44. package/dist/cli-help-groups.js +1 -1
  45. package/dist/cli-help-groups.js.map +1 -1
  46. package/dist/crash-log.d.ts +112 -0
  47. package/dist/crash-log.d.ts.map +1 -0
  48. package/dist/crash-log.js +560 -0
  49. package/dist/crash-log.js.map +1 -0
  50. package/dist/delegate.d.ts +10 -0
  51. package/dist/delegate.d.ts.map +1 -1
  52. package/dist/delegate.js +29 -0
  53. package/dist/delegate.js.map +1 -1
  54. package/dist/gateway-host/claude-seat-client.d.ts +32 -0
  55. package/dist/gateway-host/claude-seat-client.d.ts.map +1 -0
  56. package/dist/gateway-host/claude-seat-client.js +38 -0
  57. package/dist/gateway-host/claude-seat-client.js.map +1 -0
  58. package/dist/gateway-host/host.d.ts +6 -0
  59. package/dist/gateway-host/host.d.ts.map +1 -1
  60. package/dist/gateway-host/host.js +24 -3
  61. package/dist/gateway-host/host.js.map +1 -1
  62. package/dist/gateway-host/live-declarations.d.ts +58 -0
  63. package/dist/gateway-host/live-declarations.d.ts.map +1 -0
  64. package/dist/gateway-host/live-declarations.js +429 -0
  65. package/dist/gateway-host/live-declarations.js.map +1 -0
  66. package/dist/gateway-host/live-github.d.ts +11 -0
  67. package/dist/gateway-host/live-github.d.ts.map +1 -0
  68. package/dist/gateway-host/live-github.js +374 -0
  69. package/dist/gateway-host/live-github.js.map +1 -0
  70. package/dist/gateway-host/live-object-store.d.ts +35 -0
  71. package/dist/gateway-host/live-object-store.d.ts.map +1 -0
  72. package/dist/gateway-host/live-object-store.js +447 -0
  73. package/dist/gateway-host/live-object-store.js.map +1 -0
  74. package/dist/gateway-host/live-registration.d.ts +162 -0
  75. package/dist/gateway-host/live-registration.d.ts.map +1 -0
  76. package/dist/gateway-host/live-registration.js +455 -0
  77. package/dist/gateway-host/live-registration.js.map +1 -0
  78. package/dist/index.d.ts.map +1 -1
  79. package/dist/index.js +290 -23
  80. package/dist/index.js.map +1 -1
  81. package/dist/llm-mesh-accounts.d.ts +70 -4
  82. package/dist/llm-mesh-accounts.d.ts.map +1 -1
  83. package/dist/llm-mesh-accounts.js +296 -9
  84. package/dist/llm-mesh-accounts.js.map +1 -1
  85. package/dist/native-host.d.ts +1 -1
  86. package/dist/native-host.d.ts.map +1 -1
  87. package/dist/native-host.js +30 -17
  88. package/dist/native-host.js.map +1 -1
  89. package/dist/native-terminal/host.d.ts +6 -1
  90. package/dist/native-terminal/host.d.ts.map +1 -1
  91. package/dist/native-terminal/host.js +6 -25
  92. package/dist/native-terminal/host.js.map +1 -1
  93. package/dist/native-terminal/journal.d.ts +5 -0
  94. package/dist/native-terminal/journal.d.ts.map +1 -1
  95. package/dist/native-terminal/journal.js +28 -16
  96. package/dist/native-terminal/journal.js.map +1 -1
  97. package/dist/native-terminal/op.d.ts +13 -0
  98. package/dist/native-terminal/op.d.ts.map +1 -1
  99. package/dist/native-terminal/op.js +64 -5
  100. package/dist/native-terminal/op.js.map +1 -1
  101. package/dist/proc-identity.d.ts +31 -0
  102. package/dist/proc-identity.d.ts.map +1 -1
  103. package/dist/proc-identity.js +54 -0
  104. package/dist/proc-identity.js.map +1 -1
  105. package/dist/prompt-delivery.d.ts +3 -0
  106. package/dist/prompt-delivery.d.ts.map +1 -1
  107. package/dist/prompt-delivery.js +8 -3
  108. package/dist/prompt-delivery.js.map +1 -1
  109. package/dist/run.d.ts.map +1 -1
  110. package/dist/run.js +79 -16
  111. package/dist/run.js.map +1 -1
  112. package/dist/terminal-reset.d.ts +104 -0
  113. package/dist/terminal-reset.d.ts.map +1 -0
  114. package/dist/terminal-reset.js +229 -0
  115. package/dist/terminal-reset.js.map +1 -0
  116. package/dist/tmux.d.ts +26 -4
  117. package/dist/tmux.d.ts.map +1 -1
  118. package/dist/tmux.js +60 -25
  119. package/dist/tmux.js.map +1 -1
  120. package/dist/vendor/engram-live/contracts.d.ts +825 -0
  121. package/dist/vendor/engram-live/contracts.js +1734 -0
  122. package/dist/vendor/engram-live/integration.d.ts +113 -0
  123. package/dist/vendor/engram-live/integration.js +254 -0
  124. package/dist/vendor/engram-live/pr-sync.d.ts +144 -0
  125. package/dist/vendor/engram-live/pr-sync.js +411 -0
  126. package/dist/vendor/engram-live/registration.d.ts +138 -0
  127. package/dist/vendor/engram-live/registration.js +358 -0
  128. package/dist/vendor/engram-live/retention.d.ts +56 -0
  129. package/dist/vendor/engram-live/retention.js +179 -0
  130. package/package.json +2 -2
@@ -0,0 +1,447 @@
1
+ /** R1 (LIVE §4): host-owned committed objects, never an alternate or a checkout.
2
+ * The composition owner supplies an authorized clone/scope and local source.
3
+ * No source config, refs, hooks, transport or credentials are consulted here.
4
+ * Receipt publication follows pack verification, private pin and durable sync.
5
+ */
6
+ import { execFileSync, spawn } from "node:child_process";
7
+ import { createHash, randomUUID } from "node:crypto";
8
+ import { closeSync, createWriteStream, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, readdirSync, realpathSync, renameSync, rmdirSync, rmSync, statSync, writeFileSync, } from "node:fs";
9
+ import { isAbsolute, join, relative, resolve, sep } from "node:path";
10
+ import { Transform } from "node:stream";
11
+ import { pipeline } from "node:stream/promises";
12
+ import { validateLiveScope, validateRetentionReceipt, validateRetentionRequest, } from "../vendor/engram-live/contracts.js";
13
+ const snapshot = (value) => JSON.parse(JSON.stringify(value));
14
+ const canonicalPath = (path) => existsSync(path) ? realpathSync(path) : resolve(path);
15
+ const within = (parent, child) => {
16
+ const tail = relative(parent, child);
17
+ return tail === "" || (!isAbsolute(tail) && tail !== ".." && !tail.startsWith(`..${sep}`));
18
+ };
19
+ function syncPath(path) {
20
+ const fd = openSync(path, "r");
21
+ try {
22
+ fsyncSync(fd);
23
+ }
24
+ finally {
25
+ closeSync(fd);
26
+ }
27
+ }
28
+ function durableJson(path, value, generation) {
29
+ const tmp = generation ? join(generation, `${randomUUID()}.tmp`) : `${path}.${randomUUID()}.tmp`;
30
+ try {
31
+ writeFileSync(tmp, JSON.stringify(value) + "\n", { mode: 0o600, flag: "wx" });
32
+ syncPath(tmp);
33
+ renameSync(tmp, path);
34
+ syncPath(resolve(path, ".."));
35
+ }
36
+ finally {
37
+ rmSync(tmp, { force: true });
38
+ }
39
+ }
40
+ function syncTree(path) {
41
+ for (const name of readdirSync(path)) {
42
+ const file = join(path, name);
43
+ if (statSync(file).isDirectory())
44
+ syncTree(file);
45
+ else
46
+ syncPath(file);
47
+ }
48
+ syncPath(path);
49
+ }
50
+ function bytesIn(path) {
51
+ return readdirSync(path).reduce((sum, name) => {
52
+ const file = join(path, name);
53
+ const stat = statSync(file);
54
+ return sum + (stat.isDirectory() ? bytesIn(file) : stat.size);
55
+ }, 0);
56
+ }
57
+ // Only the observed generation is removed; age authorizes fencing, never
58
+ // concurrent shared writes. Publications consume sources in that generation.
59
+ function takeoverStaleLock(lockPath) {
60
+ let observed;
61
+ try {
62
+ observed = readdirSync(lockPath);
63
+ if (Date.now() - statSync(lockPath).mtimeMs <= 60_000)
64
+ throw new Error("store_busy");
65
+ }
66
+ catch (error) {
67
+ if (error.message === "store_busy")
68
+ throw error;
69
+ if (error.code === "ENOENT" || !existsSync(lockPath))
70
+ throw new Error("store_busy");
71
+ throw error;
72
+ }
73
+ for (const oldToken of observed)
74
+ rmSync(join(lockPath, oldToken), { recursive: true, force: true });
75
+ try {
76
+ rmdirSync(lockPath);
77
+ }
78
+ catch (error) {
79
+ if (error.code !== "ENOENT")
80
+ throw new Error("store_busy");
81
+ }
82
+ }
83
+ export function createLiveObjectStore(options) {
84
+ const scope = snapshot(options.scope);
85
+ const algorithm = options.algorithm;
86
+ if (!validateLiveScope(scope).ok || scope.worktree !== undefined)
87
+ throw new Error("invalid retention scope");
88
+ if (algorithm !== "sha1" && algorithm !== "sha256")
89
+ throw new Error("invalid retention algorithm");
90
+ if (!Number.isSafeInteger(options.quotaBytes) || options.quotaBytes < 0)
91
+ throw new Error("invalid object quota");
92
+ const quota = options.quotaBytes;
93
+ const root = realpathSync(options.root);
94
+ const commonDir = canonicalPath(options.source.commonDir);
95
+ for (const source of [commonDir, ...options.source.worktreeRoots.map(canonicalPath)]) {
96
+ if (within(source, root) || within(root, source))
97
+ throw new Error("private object store must be outside source roots");
98
+ }
99
+ const scopeKey = createHash("sha256").update(JSON.stringify([scope.tenant, scope.clone])).digest("hex");
100
+ const metadataDir = join(root, "live-object-store", scopeKey, algorithm);
101
+ const gitDir = join(metadataDir, "objects.git");
102
+ const requests = join(metadataDir, "requests");
103
+ const receipts = join(metadataDir, "receipts");
104
+ const gaps = join(metadataDir, "gaps");
105
+ const empty = join(metadataDir, "empty");
106
+ for (const dir of [join(root, "live-object-store"), join(root, "live-object-store", scopeKey), metadataDir, requests, receipts, gaps, empty]) {
107
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
108
+ }
109
+ const noConfig = join(metadataDir, "no-config");
110
+ if (!existsSync(noConfig))
111
+ writeFileSync(noConfig, "", { mode: 0o600, flag: "wx" });
112
+ // Whitelist the environment: inherited Git config, alternates, SSH commands,
113
+ // credentials, templates and exec-path overrides must never reach Git.
114
+ const env = {
115
+ PATH: process.env.PATH, HOME: metadataDir, XDG_CONFIG_HOME: metadataDir,
116
+ XDG_RUNTIME_DIR: metadataDir, TMPDIR: metadataDir,
117
+ GIT_CONFIG_NOSYSTEM: "1", GIT_CONFIG_SYSTEM: noConfig, GIT_CONFIG_GLOBAL: noConfig,
118
+ GIT_TERMINAL_PROMPT: "0", GIT_NO_REPLACE_OBJECTS: "1", GIT_NO_LAZY_FETCH: "1",
119
+ GIT_OPTIONAL_LOCKS: "0", GIT_ATTR_NOSYSTEM: "1", LC_ALL: "C",
120
+ };
121
+ const flags = ["--no-optional-locks", "-c", `core.hooksPath=${empty}`, "-c", "core.fsmonitor=false",
122
+ "-c", "protocol.allow=never", "-c", "gc.auto=0", "-c", "maintenance.auto=false"];
123
+ const git = (dir, args, extraEnv = {}) => execFileSync("git", [...flags, `--git-dir=${dir}`, ...args], {
124
+ cwd: metadataDir, env: { ...env, ...extraEnv }, encoding: "utf8",
125
+ stdio: ["ignore", "pipe", "pipe"], timeout: 30_000, maxBuffer: 1024 * 1024,
126
+ }).trim();
127
+ const init = (dir) => {
128
+ git(dir, ["init", "--bare", `--object-format=${algorithm}`, `--template=${empty}`, dir]);
129
+ // git init honors the caller's umask for its top directory. Create that
130
+ // directory ourselves before invoking it (all descendants stay protected).
131
+ };
132
+ if (!existsSync(join(gitDir, "HEAD"))) {
133
+ mkdirSync(gitDir, { mode: 0o700 });
134
+ init(gitDir);
135
+ }
136
+ mkdirSync(join(gitDir, "refs", "h2a", "retained"), { recursive: true, mode: 0o700 });
137
+ const acquisitionLockPath = join(metadataDir, "acquisition.lock");
138
+ const checkScope = (candidate, format) => {
139
+ if (!validateLiveScope(candidate).ok || candidate.worktree !== undefined ||
140
+ candidate.tenant !== scope.tenant || candidate.clone !== scope.clone)
141
+ throw new Error("retention scope mismatch");
142
+ if (format !== algorithm)
143
+ throw new Error("retention algorithm mismatch");
144
+ };
145
+ const pin = (oid) => `refs/h2a/retained/${oid}`;
146
+ const backupRef = (oid) => `h2a-live-object:${scopeKey}:${algorithm}:${oid}`;
147
+ const requestPath = (oid) => join(requests, `${oid}.json`);
148
+ const receiptPath = (oid) => join(receipts, `${oid}.json`);
149
+ const acknowledgePin = (oid, generation) => {
150
+ durableJson(receiptPath(oid), { scope, algorithm, oid,
151
+ receivedAt: (options.now ?? Date.now)(), backupRef: backupRef(oid) }, generation);
152
+ };
153
+ const readRequest = (oid) => {
154
+ const request = JSON.parse(readFileSync(requestPath(oid), "utf8"));
155
+ if (!validateRetentionRequest(request).ok || request.oid !== oid)
156
+ throw new Error("invalid durable retention request");
157
+ checkScope(request.scope, request.algorithm);
158
+ return request;
159
+ };
160
+ const verified = (dir, oid) => {
161
+ if (git(dir, ["cat-file", "-t", oid]) !== "commit")
162
+ throw new Error("retention root must be committed history");
163
+ // Includes parents, trees and blobs. A tip alone is never sufficient.
164
+ git(dir, ["fsck", "--strict", "--no-reflogs", "--no-dangling", oid]);
165
+ };
166
+ async function recordReceipt(candidate) {
167
+ const receipt = snapshot(candidate);
168
+ if (!validateRetentionReceipt(receipt).ok)
169
+ throw new Error("invalid retention receipt scope or fields");
170
+ checkScope(receipt.scope, receipt.algorithm);
171
+ if (!existsSync(requestPath(receipt.oid)))
172
+ throw new Error("retention receipt has no recorded request");
173
+ readRequest(receipt.oid);
174
+ if (receipt.backupRef !== backupRef(receipt.oid))
175
+ throw new Error("retention backup reference mismatch");
176
+ if (git(gitDir, ["rev-parse", "--verify", pin(receipt.oid)]) !== receipt.oid)
177
+ throw new Error("unprotected retention pin");
178
+ if (hasReceipt(receipt.oid))
179
+ return { received: true };
180
+ await withAcquisitionLock(async (generation) => {
181
+ verified(gitDir, receipt.oid);
182
+ syncTree(gitDir);
183
+ durableJson(receiptPath(receipt.oid), receipt, generation);
184
+ });
185
+ return { received: true };
186
+ }
187
+ // Single-receipt fast path: one file read plus one rev-parse, no full scan
188
+ // and no fsck. recordRequest uses this instead of a full load per request.
189
+ function hasReceipt(oid) {
190
+ try {
191
+ if (!existsSync(receiptPath(oid)))
192
+ return false;
193
+ const receipt = JSON.parse(readFileSync(receiptPath(oid), "utf8"));
194
+ if (!validateRetentionReceipt(receipt).ok || receipt.oid !== oid)
195
+ return false;
196
+ if (receipt.scope.tenant !== scope.tenant || receipt.scope.clone !== scope.clone ||
197
+ receipt.scope.worktree !== undefined || receipt.algorithm !== algorithm)
198
+ return false;
199
+ if (receipt.backupRef !== backupRef(oid))
200
+ return false;
201
+ readRequest(oid);
202
+ return git(gitDir, ["rev-parse", "--verify", pin(oid)]) === oid;
203
+ }
204
+ catch {
205
+ return false;
206
+ }
207
+ }
208
+ async function loadReceipts(query) {
209
+ checkScope(query.scope, query.algorithm);
210
+ const loaded = [];
211
+ for (const name of readdirSync(receipts).filter((name) => name.endsWith(".json")).sort()) {
212
+ // Quarantine: one corrupt receipt, foreign receipt, missing request or
213
+ // missing pin skips that entry instead of failing the whole pass. The
214
+ // skipped OID stays pending and is reacquired on retry.
215
+ try {
216
+ const receipt = JSON.parse(readFileSync(join(receipts, name), "utf8"));
217
+ if (!validateRetentionReceipt(receipt).ok || name !== `${receipt.oid}.json`)
218
+ continue;
219
+ if (receipt.scope.tenant !== scope.tenant || receipt.scope.clone !== scope.clone ||
220
+ receipt.scope.worktree !== undefined || receipt.algorithm !== algorithm)
221
+ continue;
222
+ try {
223
+ readRequest(receipt.oid);
224
+ }
225
+ catch {
226
+ continue;
227
+ }
228
+ if (receipt.backupRef !== backupRef(receipt.oid))
229
+ continue;
230
+ let pinned;
231
+ try {
232
+ pinned = git(gitDir, ["rev-parse", "--verify", pin(receipt.oid)]);
233
+ }
234
+ catch {
235
+ continue;
236
+ }
237
+ if (pinned !== receipt.oid)
238
+ continue;
239
+ loaded.push(receipt);
240
+ }
241
+ catch {
242
+ continue;
243
+ }
244
+ }
245
+ return { receipts: loaded };
246
+ }
247
+ async function acquire(request, stage) {
248
+ // This git-dir has only host-created config. Only immutable source objects
249
+ // are exposed to pack-objects; source refs/config/index are never loaded.
250
+ const sourceObjects = join(commonDir, "objects");
251
+ // Borrowing a source alternate would make both authority and availability
252
+ // ambiguous. Report a gap; never create an alternate in the private store.
253
+ if (existsSync(join(sourceObjects, "info", "alternates")))
254
+ throw new Error("source alternates not authorized");
255
+ const remaining = quota - bytesIn(join(gitDir, "objects"));
256
+ if (remaining <= 0)
257
+ throw new Error("quota_exhausted");
258
+ // Exclude retained history using only host-owned refs. The private store
259
+ // is a read-only, ephemeral alternate for this command, so exclusions
260
+ // also work after the corresponding root disappeared from the source.
261
+ const incoming = join(stage, "incoming.pack");
262
+ const child = spawn("git", [...flags, `--git-dir=${stage}`, "pack-objects", "--stdout", "--revs",
263
+ "--no-use-bitmap-index", "--no-reuse-delta", "--no-reuse-object"], {
264
+ cwd: metadataDir, env: { ...env, GIT_OBJECT_DIRECTORY: sourceObjects, GIT_ALTERNATE_OBJECT_DIRECTORIES: join(gitDir, "objects") }, stdio: ["pipe", "pipe", "pipe"],
265
+ });
266
+ const closed = new Promise((resolve, reject) => {
267
+ child.once("error", reject);
268
+ child.once("close", resolve);
269
+ });
270
+ // Stream exclusions with backpressure: the number of retained refs has no
271
+ // fixed ceiling and must never be limited by execFileSync's maxBuffer.
272
+ const retained = spawn("git", [...flags, `--git-dir=${gitDir}`, "for-each-ref",
273
+ "--format=^%(objectname)", "refs/h2a/retained"], {
274
+ cwd: metadataDir, env, stdio: ["ignore", "pipe", "pipe"],
275
+ });
276
+ const retainedClosed = new Promise((resolve, reject) => {
277
+ retained.once("error", reject);
278
+ retained.once("close", resolve);
279
+ });
280
+ // Drain errors, but never retain/log potentially sensitive source text.
281
+ child.stderr.resume();
282
+ retained.stderr.resume();
283
+ child.stdin.on("error", () => { });
284
+ child.stdin.write(`${request.oid}\n`);
285
+ let count = 0;
286
+ let timedOut = false;
287
+ const timer = setTimeout(() => { timedOut = true; child.kill("SIGKILL"); retained.kill("SIGKILL"); }, 30_000);
288
+ const transfers = [
289
+ pipeline(retained.stdout, child.stdin),
290
+ pipeline(child.stdout, new Transform({ transform(chunk, _encoding, callback) {
291
+ count += chunk.length;
292
+ callback(count > remaining ? new Error("quota_exhausted") : null, count > remaining ? undefined : chunk);
293
+ } }), createWriteStream(incoming, { flags: "wx", mode: 0o600 })),
294
+ ];
295
+ try {
296
+ const [code, retainedCode] = await Promise.all([closed, retainedClosed, ...transfers]);
297
+ if (code !== 0 || retainedCode !== 0 || timedOut)
298
+ throw new Error("objects_unavailable");
299
+ }
300
+ finally {
301
+ clearTimeout(timer);
302
+ if (child.exitCode === null && child.signalCode === null)
303
+ child.kill("SIGKILL");
304
+ if (retained.exitCode === null && retained.signalCode === null)
305
+ retained.kill("SIGKILL");
306
+ await Promise.allSettled([closed, retainedClosed, ...transfers]);
307
+ }
308
+ // index-pack writes alongside incoming; move the complete verified
309
+ // pair into staging's object db before connectivity verification.
310
+ writeFileSync(join(stage, "objects", "info", "alternates"), join(gitDir, "objects") + "\n", { flag: "wx", mode: 0o600 });
311
+ const hash = git(stage, ["index-pack", "--strict", incoming]);
312
+ const stagedPacks = join(stage, "objects", "pack");
313
+ renameSync(incoming, join(stagedPacks, `pack-${hash}.pack`));
314
+ renameSync(join(stage, "incoming.idx"), join(stagedPacks, `pack-${hash}.idx`));
315
+ // Closure is verified over the incoming objects plus retained objects;
316
+ // this alternate exists only inside the disposable acquisition generation.
317
+ verified(stage, request.oid);
318
+ if (bytesIn(join(gitDir, "objects")) + bytesIn(stagedPacks) > quota)
319
+ throw new Error("quota_exhausted");
320
+ // Install the pack before its index. A crash can leave an unindexed
321
+ // orphan pack, never an index referring to an absent pack.
322
+ for (const name of readdirSync(stagedPacks).sort((a, b) => Number(b.endsWith(".pack")) - Number(a.endsWith(".pack")))) {
323
+ renameSync(join(stagedPacks, name), join(gitDir, "objects", "pack", name));
324
+ }
325
+ syncTree(join(gitDir, "objects"));
326
+ // Every publication consumes a source in this generation. A takeover
327
+ // removes those sources before a successor is admitted; even a holder
328
+ // suspended inside rename cannot publish after being fenced.
329
+ const stagedPin = join(stage, "pin");
330
+ writeFileSync(stagedPin, request.oid + "\n", { flag: "wx", mode: 0o600 });
331
+ syncPath(stagedPin);
332
+ renameSync(stagedPin, join(gitDir, pin(request.oid)));
333
+ syncPath(join(gitDir, "refs", "h2a", "retained"));
334
+ syncPath(join(gitDir, "refs", "h2a"));
335
+ syncPath(join(gitDir, "refs"));
336
+ syncPath(gitDir);
337
+ syncPath(metadataDir);
338
+ acknowledgePin(request.oid, stage);
339
+ }
340
+ async function withAcquisitionLock(action) {
341
+ const token = randomUUID();
342
+ const candidate = `${acquisitionLockPath}.${token}.candidate`;
343
+ const generation = join(acquisitionLockPath, token);
344
+ let locked = false;
345
+ try {
346
+ mkdirSync(candidate, { mode: 0o700 });
347
+ mkdirSync(join(candidate, token), { mode: 0o700 });
348
+ init(join(candidate, token));
349
+ for (;;) {
350
+ try {
351
+ renameSync(candidate, acquisitionLockPath);
352
+ locked = true;
353
+ break;
354
+ }
355
+ catch (error) {
356
+ if (!["EEXIST", "ENOTEMPTY"].includes(error.code ?? ""))
357
+ throw error;
358
+ }
359
+ takeoverStaleLock(acquisitionLockPath);
360
+ }
361
+ await action(generation);
362
+ }
363
+ finally {
364
+ rmSync(candidate, { recursive: true, force: true });
365
+ if (locked) {
366
+ rmSync(generation, { recursive: true, force: true });
367
+ try {
368
+ rmdirSync(acquisitionLockPath);
369
+ }
370
+ catch (error) {
371
+ if (!["ENOENT", "ENOTEMPTY", "EEXIST"].includes(error.code ?? ""))
372
+ throw error;
373
+ }
374
+ }
375
+ }
376
+ }
377
+ async function recordRequest(input) {
378
+ const request = snapshot(input);
379
+ if (!validateRetentionRequest(request).ok)
380
+ throw new Error("invalid retention request scope or fields");
381
+ checkScope(request.scope, request.algorithm);
382
+ if (!existsSync(requestPath(request.oid)))
383
+ durableJson(requestPath(request.oid), request);
384
+ else
385
+ readRequest(request.oid);
386
+ if (hasReceipt(request.oid))
387
+ return { received: true };
388
+ try {
389
+ await withAcquisitionLock(async (generation) => {
390
+ try {
391
+ let pinned = false;
392
+ try {
393
+ pinned = git(gitDir, ["rev-parse", "--verify", pin(request.oid)]) === request.oid;
394
+ }
395
+ catch { /* not acquired */ }
396
+ if (pinned) {
397
+ // Recover a pin whose receipt was interrupted, without the source.
398
+ verified(gitDir, request.oid);
399
+ syncTree(gitDir);
400
+ acknowledgePin(request.oid, generation);
401
+ }
402
+ else
403
+ await acquire(request, generation);
404
+ }
405
+ catch (error) {
406
+ const code = error.code;
407
+ if (code && ["EACCES", "EROFS", "EIO", "ENOSPC"].includes(code))
408
+ throw error;
409
+ // A fenced holder cannot overwrite its successor's gap or receipt.
410
+ if (!existsSync(generation))
411
+ return;
412
+ const reason = error.message === "quota_exhausted" ? "quota_exhausted" : "objects_unavailable";
413
+ try {
414
+ durableJson(join(gaps, `${request.oid}.json`), { reason }, generation);
415
+ }
416
+ catch (failure) {
417
+ if (failure.code !== "ENOENT")
418
+ throw failure;
419
+ }
420
+ }
421
+ });
422
+ }
423
+ catch (error) {
424
+ if (error.message !== "store_busy")
425
+ throw error;
426
+ // Durable request remains pending; contention never writes a shared gap.
427
+ }
428
+ return { received: true };
429
+ }
430
+ async function pending() {
431
+ const acknowledged = new Set((await loadReceipts({ scope, algorithm })).receipts.map((receipt) => receipt.oid));
432
+ return readdirSync(requests).filter((name) => name.endsWith(".json")).sort().flatMap((name) => {
433
+ const request = readRequest(name.slice(0, -5));
434
+ if (acknowledged.has(request.oid))
435
+ return [];
436
+ const gapPath = join(gaps, name);
437
+ const reason = existsSync(gapPath) ? JSON.parse(readFileSync(gapPath, "utf8")).reason : "store_busy";
438
+ return [{ request, reason }];
439
+ });
440
+ }
441
+ return { gitDir, acquisitionLockPath, recordRequest, recordReceipt, loadReceipts, pending,
442
+ async retryPending() { for (const { request } of await pending())
443
+ await recordRequest(request); },
444
+ backupManifest: () => ({ gitDir, metadataDir, scope: snapshot(scope) }),
445
+ };
446
+ }
447
+ //# sourceMappingURL=live-object-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"live-object-store.js","sourceRoot":"","sources":["../../src/gateway-host/live-object-store.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EACL,SAAS,EAAE,iBAAiB,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EACxE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,GAChG,MAAM,SAAS,CAAC;AACjB,OAAO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,EAAE,mBAAmB,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,OAAO;QACvF,KAAK,CAAC,YAAY,KAAK,KAAK,MAAM,EAAE,OAAO,EAAE,IAAI,MAAM,OAAO,EAAE;YAAE,MAAM,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACjG,cAAc,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;KACxE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,162 @@
1
+ import { NON_ACTIVATING_LIFECYCLE_KINDS } from "../vendor/engram-live/contracts.js";
2
+ import type { DeclarationRevocationDto, IdentityUncertaintyState, NonActivatingLifecycleKind, OidAlgorithm, RevocationReason } from "../vendor/engram-live/contracts.js";
3
+ import { type LiveDeclarationRecord } from "./live-declarations.js";
4
+ export declare function normalizeRootCommits(shas: ReadonlyArray<string>): string;
5
+ export declare function computeDurableWorkspaceId(rootCommitSHA: string, worktreeRelPath: string): string;
6
+ export interface LiveWorkspaceProbe {
7
+ /** Authorized root: resolved real path of the observed worktree. */
8
+ readonly worktreeRealpath: string;
9
+ /** Resolved git-dir (`.git/worktrees/<name>` for a linked worktree). */
10
+ readonly gitDir: string;
11
+ /** Resolved common-dir real path, shared by linked worktrees. */
12
+ readonly commonDirRealpath: string;
13
+ /** "" for the main worktree, else the linked-worktree name. */
14
+ readonly worktreeName: string;
15
+ /** Repository object format; undefined when Git cannot report it. */
16
+ readonly oidAlgorithm?: OidAlgorithm;
17
+ /** Normalized root commits; undefined when history is missing. */
18
+ readonly rootCommits?: string;
19
+ /** Preserved public `ws:` fingerprint; absent with missing_history. */
20
+ readonly workspaceFingerprint?: string;
21
+ /** Project fingerprint (empty main-worktree component); may be absent. */
22
+ readonly projectFingerprint?: string;
23
+ /** A `shallow` graft file exists in the common dir. */
24
+ readonly shallow: boolean;
25
+ /** Explicit identity/coverage uncertainty labels, never silent. */
26
+ readonly identityUncertainty: readonly IdentityUncertaintyState[];
27
+ }
28
+ /**
29
+ * Probe a worktree's live identity with read-only Git plumbing. Every
30
+ * invocation disables optional locks (`--no-optional-locks`, LIVE §7) and
31
+ * never writes to the observed worktree, its index or its refs. Returns
32
+ * undefined when the path is not a Git worktree; missing (unborn HEAD) or
33
+ * shallow history is a successful probe with explicit uncertainty.
34
+ */
35
+ export declare function probeLiveWorkspace(cwd: string): LiveWorkspaceProbe | undefined;
36
+ /**
37
+ * Classify a host lifecycle event against live declarations. Bind, upload,
38
+ * code-workspace creation and session open/end never activate or remove a
39
+ * declaration: the only outcome is "no-activation-change". Unknown kinds
40
+ * are refused. Pinned to NON_ACTIVATING_LIFECYCLE_KINDS, never a copy.
41
+ */
42
+ export declare function classifyLifecycleEvent(kind: NonActivatingLifecycleKind): "no-activation-change";
43
+ export type LiveOperation = "activate" | "list" | "status" | "resolve" | "remove" | "remove-clone" | "rebind" | "replay";
44
+ export interface LiveAuthorizationRequest {
45
+ readonly operation: LiveOperation;
46
+ /** Stable local scope `local:<host-owner-id>`; never a sentropic tenant. */
47
+ readonly tenant: string;
48
+ readonly path?: string;
49
+ readonly declarationId?: string;
50
+ readonly hostFingerprint?: string;
51
+ }
52
+ export interface LiveAuthorizationDecision {
53
+ readonly ok: boolean;
54
+ readonly reason?: string;
55
+ readonly principal?: string;
56
+ }
57
+ export interface LiveAuthority {
58
+ authorize(request: LiveAuthorizationRequest): LiveAuthorizationDecision;
59
+ }
60
+ /**
61
+ * Default authority until L7a: deny everything explicitly. Local identity
62
+ * verification is L7a work; until it exists, no declaration API is usable,
63
+ * and denial is an error — never a successful empty result (A01).
64
+ */
65
+ export declare const unverifiedLocalLiveAuthority: LiveAuthority;
66
+ export interface LiveWorkScope {
67
+ readonly declarationId: string;
68
+ readonly cloneId: string;
69
+ }
70
+ /**
71
+ * Cancellation/purge seam. Removal stops scheduled (delayed) work and
72
+ * requests a purge of PRIVATE local snapshots and derived indexes only;
73
+ * authorized committed history is never deleted by live (LIVE §10).
74
+ */
75
+ export interface LiveWorkController {
76
+ cancelScheduledWork(scope: LiveWorkScope): boolean;
77
+ requestPrivatePurge(scope: LiveWorkScope): boolean;
78
+ hasInFlightWork(scope: LiveWorkScope): boolean;
79
+ }
80
+ export declare const inertLiveWorkController: LiveWorkController;
81
+ export declare class LiveAccessRefused extends Error {
82
+ readonly operation: LiveOperation;
83
+ readonly reason: string;
84
+ constructor(operation: LiveOperation, reason: string);
85
+ }
86
+ export interface LiveRegistrationOptions {
87
+ /** Durable h2a root (outside every observed worktree); injected, never a worktree. */
88
+ readonly root: string;
89
+ /**
90
+ * Stable local scope `local:<host-owner-id>`; defaults to the OS owner.
91
+ * PROVISIONAL until L7a supplies the verified owner scope — never a
92
+ * sentropic tenant inferred from a workspace id.
93
+ */
94
+ readonly tenant?: string;
95
+ /** Authority seam; defaults to {@link unverifiedLocalLiveAuthority} (L7a completes verification). */
96
+ readonly authority?: LiveAuthority;
97
+ /** Work-control seam; defaults to {@link inertLiveWorkController}. */
98
+ readonly workController?: LiveWorkController;
99
+ /** Injectable clock for deterministic timestamps. */
100
+ readonly now?: () => string;
101
+ }
102
+ export interface ActivateLiveRequest {
103
+ readonly path: string;
104
+ }
105
+ export interface RemoveLiveRequest {
106
+ readonly path: string;
107
+ /** Mandatory: every revocation names its reason (contract DTO). */
108
+ readonly reason: RevocationReason;
109
+ }
110
+ export interface RemoveCloneLiveRequest {
111
+ readonly cloneId: string;
112
+ /** Mandatory: every revocation names its reason (contract DTO). */
113
+ readonly reason: RevocationReason;
114
+ }
115
+ export interface RebindLiveRequest {
116
+ readonly path: string;
117
+ readonly sentropicWorkspaceId: string;
118
+ readonly issuer: string;
119
+ }
120
+ export interface RemoveLiveResult {
121
+ readonly removed: boolean;
122
+ readonly canceledWork: boolean;
123
+ readonly purgeRequested: boolean;
124
+ /** The contract revocation, present exactly when a declaration was removed. */
125
+ readonly revocation?: DeclarationRevocationDto;
126
+ }
127
+ export interface RemoveCloneLiveResult {
128
+ /** Number of declarations revoked. */
129
+ readonly removed: number;
130
+ /** One contract revocation per revoked declaration, in declarationId order. */
131
+ readonly revocations: readonly DeclarationRevocationDto[];
132
+ readonly canceledWork: boolean;
133
+ readonly purgeRequested: boolean;
134
+ }
135
+ export interface ResolvedLivePath {
136
+ readonly declaration: LiveDeclarationRecord;
137
+ readonly relativePath: string;
138
+ }
139
+ export interface LiveRegistration {
140
+ readonly authority: LiveAuthority;
141
+ probe(cwd: string): LiveWorkspaceProbe | undefined;
142
+ /** Explicit activation, once per worktree; idempotent re-activation replays the existing declaration. */
143
+ activate(request: ActivateLiveRequest): {
144
+ declaration: LiveDeclarationRecord;
145
+ created: boolean;
146
+ };
147
+ list(): readonly LiveDeclarationRecord[];
148
+ status(path: string): LiveDeclarationRecord | undefined;
149
+ /** Path-resolution seam: the declaration covering `path`, with its relative path. */
150
+ resolvePath(path: string): ResolvedLivePath | undefined;
151
+ /** Stop work, cancel delayed jobs, revoke the declaration with its reason, request a private purge, then unregister. */
152
+ remove(request: RemoveLiveRequest): RemoveLiveResult;
153
+ /** Withdraw a whole clone: revoke EACH of its declarations, one revocation each. */
154
+ removeClone(request: RemoveCloneLiveRequest): RemoveCloneLiveResult;
155
+ /** Server/issuer-bound product live intent; requires fresh revalidation, bumps the binding revision. */
156
+ rebind(request: RebindLiveRequest): LiveDeclarationRecord;
157
+ /** Host-startup replay of durable declarations, without renewed activation. */
158
+ replay(): readonly LiveDeclarationRecord[];
159
+ }
160
+ export declare function createLiveRegistration(options: LiveRegistrationOptions): LiveRegistration;
161
+ export { NON_ACTIVATING_LIFECYCLE_KINDS };
162
+ //# sourceMappingURL=live-registration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"live-registration.d.ts","sourceRoot":"","sources":["../../src/gateway-host/live-registration.ts"],"names":[],"mappings":"AA4CA,OAAO,EAGL,8BAA8B,EAM/B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EAEV,wBAAwB,EACx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