gestalt-mobile 0.65.8 → 0.66.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +22 -0
  2. package/dist/client/assets/index-BDsGojoG.js +128 -0
  3. package/dist/client/assets/{index-VDRT2Esv.css → index-DxsD-jG4.css} +1 -1
  4. package/dist/client/index.html +2 -2
  5. package/dist/server/server/cli.js +2 -1
  6. package/dist/server/server/composition.contracts.js +179 -84
  7. package/dist/server/server/composition.js +65 -5
  8. package/dist/server/server/features/sessions/application/session-scratch.js +6 -0
  9. package/dist/server/server/features/sessions/clean-tmp/endpoint.js +68 -0
  10. package/dist/server/server/features/sessions/clean-tmp/use-case.js +82 -0
  11. package/dist/server/server/features/sessions/forget-session/endpoint.js +10 -2
  12. package/dist/server/server/features/sessions/forget-session/use-case.js +75 -0
  13. package/dist/server/server/features/sessions/get-session/endpoint.js +2 -1
  14. package/dist/server/server/features/sessions/list-sessions/endpoint.js +3 -0
  15. package/dist/server/server/features/sessions/promote-recent-thread/use-case.js +4 -1
  16. package/dist/server/server/features/sessions/register-routes.js +29 -2
  17. package/dist/server/server/features/sessions/start-session/endpoint.js +7 -0
  18. package/dist/server/server/features/sessions/start-session/use-case.js +4 -1
  19. package/dist/server/server/platform/catalog/filesystem-workspace-catalog.js +19 -1
  20. package/dist/server/server/platform/codex/codex-playwright.js +41 -3
  21. package/dist/server/server/platform/codex/codex-process-launcher.js +24 -2
  22. package/dist/server/server/platform/codex/codex-serena.js +2 -1
  23. package/dist/server/server/platform/codex/managed-playwright.js +48 -36
  24. package/dist/server/server/platform/codex/session-runtime.js +134 -4
  25. package/dist/server/server/platform/git/command.js +7 -1
  26. package/dist/server/server/platform/host-tests/runner.js +47 -6
  27. package/dist/server/server/platform/kimi/kimi-session-runtime.js +41 -0
  28. package/dist/server/server/platform/kimi/kimi-web-server-manager.js +13 -17
  29. package/dist/server/server/platform/maintenance/managed-upgrade.js +2 -1
  30. package/dist/server/server/platform/persistence/migrate.js +24 -0
  31. package/dist/server/server/platform/persistence/sqlite-forget-operation-store.js +67 -0
  32. package/dist/server/server/platform/persistence/sqlite-session-repository.js +4 -0
  33. package/dist/server/server/platform/plans/org-plan-discovery.js +2 -0
  34. package/dist/server/server/platform/plans/plan-measurement-command.js +5 -1
  35. package/dist/server/server/platform/retrieval/codex-xerj.js +8 -1
  36. package/dist/server/server/platform/retrieval/managed-xerj.js +2 -1
  37. package/dist/server/server/platform/retrieval/repository-readiness.js +2 -1
  38. package/dist/server/server/platform/retrieval/xerj-indexer.js +21 -11
  39. package/dist/server/server/platform/scratch/child-environment.js +21 -0
  40. package/dist/server/server/platform/scratch/containment-fence.js +262 -0
  41. package/dist/server/server/platform/scratch/filesystem-scratch-cleanup.js +245 -0
  42. package/dist/server/server/platform/scratch/filesystem-session-scratch.js +360 -0
  43. package/dist/server/server/platform/scratch/legacy-scratch-layouts.js +22 -0
  44. package/dist/server/server/platform/scratch/managed-scratch-owner.js +148 -0
  45. package/dist/server/server/platform/scratch/owned-process-group.js +53 -0
  46. package/dist/server/server/platform/scratch/owner-fence.js +27 -0
  47. package/dist/server/server/platform/scratch/scratch-filesystem.js +53 -0
  48. package/dist/server/server/platform/self-debug/workspace.js +3 -0
  49. package/dist/server/shared/contracts/session-forget.js +6 -0
  50. package/dist/server/shared/contracts/tmp-cleanup.js +6 -0
  51. package/package.json +1 -1
  52. package/dist/client/assets/index-CKJWzSwH.js +0 -128
@@ -5,11 +5,13 @@
5
5
  */
6
6
  import { execFile } from 'node:child_process';
7
7
  import { promisify } from 'node:util';
8
+ import { withoutSessionScratch } from '../scratch/child-environment.js';
8
9
  const execute = promisify(execFile);
9
10
  async function run(command, args, cwd) {
10
11
  try {
11
12
  const result = await execute(command, [...args], {
12
13
  cwd,
14
+ env: withoutSessionScratch(),
13
15
  encoding: 'utf8',
14
16
  maxBuffer: 64 * 1024 * 1024,
15
17
  timeout: 30_000,
@@ -5,13 +5,17 @@
5
5
  */
6
6
  import { execFile } from 'node:child_process';
7
7
  import { promisify } from 'node:util';
8
+ import { withoutSessionScratch } from '../scratch/child-environment.js';
8
9
  import { ORG_PLAN_CAPABILITIES } from './org-plan-capabilities.js';
9
10
  const execute = promisify(execFile);
10
11
  export const PLAN_MEASUREMENT_COMMAND_TIMEOUT_MS = 15_000;
11
12
  /** Invokes the explicitly configured Org Plan helper without a shell. */
12
13
  export async function checkpointPlanMeasurement(helperPath, planPath, stepId, snapshot) {
13
14
  await execute(helperPath, ['measure', 'checkpoint', planPath, stepId, JSON.stringify(snapshot)], {
14
- env: { ...process.env, GESTALT_MOBILE_ORG_PLAN_CAPABILITIES: ORG_PLAN_CAPABILITIES },
15
+ env: {
16
+ ...withoutSessionScratch(),
17
+ GESTALT_MOBILE_ORG_PLAN_CAPABILITIES: ORG_PLAN_CAPABILITIES,
18
+ },
15
19
  shell: false,
16
20
  timeout: PLAN_MEASUREMENT_COMMAND_TIMEOUT_MS,
17
21
  });
@@ -4,6 +4,7 @@
4
4
  * SPDX-License-Identifier: AGPL-3.0-or-later
5
5
  */
6
6
  import { readFile } from 'node:fs/promises';
7
+ import { sessionScratchEnvironmentKeys } from '../scratch/child-environment.js';
7
8
  import { parseXerjStartupReason, } from '../../../shared/contracts/xerj-startup.js';
8
9
  import { ReadinessEvidence } from './readiness-evidence.js';
9
10
  export const xerjServerName = 'gestalt-xerj';
@@ -115,7 +116,13 @@ export class CodexXerj {
115
116
  command: ready.manager,
116
117
  args: ['xerj', 'mcp', '--url', ready.endpoint],
117
118
  cwd: input.cwd,
118
- env_vars: ['CODEX_HOME', 'GESTALT_HOME', 'XERJ_API_KEY', 'XERJ_AUTH'],
119
+ env_vars: [
120
+ 'CODEX_HOME',
121
+ 'GESTALT_HOME',
122
+ 'XERJ_API_KEY',
123
+ 'XERJ_AUTH',
124
+ ...sessionScratchEnvironmentKeys,
125
+ ],
119
126
  enabled: true,
120
127
  required: false,
121
128
  startup_readiness: 'connection',
@@ -4,6 +4,7 @@
4
4
  * SPDX-License-Identifier: AGPL-3.0-or-later
5
5
  */
6
6
  import { spawn } from 'node:child_process';
7
+ import { withoutSessionScratch } from '../scratch/child-environment.js';
7
8
  import { access } from 'node:fs/promises';
8
9
  import { constants } from 'node:fs';
9
10
  import { isAbsolute, join } from 'node:path';
@@ -66,7 +67,7 @@ export class ManagedXerj {
66
67
  return new Promise((resolve) => {
67
68
  const child = spawn(manager, ['xerj', operation], {
68
69
  cwd,
69
- env: { ...this.environment, XERJ_READY_TIMEOUT_MS: String(timeout) },
70
+ env: { ...withoutSessionScratch(this.environment), XERJ_READY_TIMEOUT_MS: String(timeout) },
70
71
  shell: false,
71
72
  stdio: ['ignore', 'pipe', 'ignore'],
72
73
  });
@@ -4,6 +4,7 @@
4
4
  * SPDX-License-Identifier: AGPL-3.0-or-later
5
5
  */
6
6
  import { execFile } from 'node:child_process';
7
+ import { withoutSessionScratch } from '../scratch/child-environment.js';
7
8
  import { createHash, randomUUID } from 'node:crypto';
8
9
  import { readFile, realpath, stat } from 'node:fs/promises';
9
10
  import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
@@ -48,7 +49,7 @@ async function git(cwd, args) {
48
49
  cwd,
49
50
  timeout: 2000,
50
51
  maxBuffer: 262144,
51
- env: { ...process.env, GIT_OPTIONAL_LOCKS: '0' },
52
+ env: { ...withoutSessionScratch(), GIT_OPTIONAL_LOCKS: '0' },
52
53
  })).stdout;
53
54
  }
54
55
  /** Read only the requested source, known metadata and bounded dirty tracked inputs, on demand. */
@@ -4,6 +4,8 @@
4
4
  * SPDX-License-Identifier: AGPL-3.0-or-later
5
5
  */
6
6
  import { spawn } from 'node:child_process';
7
+ import { withoutSessionScratch } from '../scratch/child-environment.js';
8
+ import { stopOwnedProcessGroup } from '../scratch/owned-process-group.js';
7
9
  import { createHash } from 'node:crypto';
8
10
  import { realpath, writeFile } from 'node:fs/promises';
9
11
  import { join } from 'node:path';
@@ -60,9 +62,11 @@ export class XerjIndexer {
60
62
  capability;
61
63
  environment;
62
64
  report;
65
+ serviceScratch;
63
66
  value;
64
67
  evidence = new ReadinessEvidence();
65
68
  child;
69
+ scratch;
66
70
  task;
67
71
  closed = false;
68
72
  saveConfiguration;
@@ -72,10 +76,11 @@ export class XerjIndexer {
72
76
  diagnosticSaved;
73
77
  diskBudgetRefused = false;
74
78
  currentFailure;
75
- constructor(root, mode, capability, environment = process.env, report = console.warn) {
79
+ constructor(root, mode, capability, environment = process.env, report = console.warn, serviceScratch) {
76
80
  this.capability = capability;
77
81
  this.environment = environment;
78
82
  this.report = report;
83
+ this.serviceScratch = serviceScratch;
79
84
  this.value = { root, mode, state: mode === 'off' ? 'disabled' : 'starting' };
80
85
  }
81
86
  status() {
@@ -165,6 +170,11 @@ export class XerjIndexer {
165
170
  }
166
171
  if (this.closed)
167
172
  return;
173
+ this.scratch = await this.serviceScratch?.();
174
+ if (this.closed) {
175
+ await this.scratch?.release();
176
+ return;
177
+ }
168
178
  const child = spawn(ready.manager, [
169
179
  'xerj',
170
180
  'autoindex',
@@ -186,7 +196,13 @@ export class XerjIndexer {
186
196
  '2000',
187
197
  '--progress',
188
198
  'json',
189
- ], { cwd: root, env: this.environment, shell: false, stdio: ['ignore', 'pipe', 'pipe'] });
199
+ ], {
200
+ cwd: root,
201
+ env: { ...withoutSessionScratch(this.environment), ...this.scratch?.environment },
202
+ shell: false,
203
+ detached: true,
204
+ stdio: ['ignore', 'pipe', 'pipe'],
205
+ });
190
206
  this.child = child;
191
207
  this.value = { ...this.value, state: 'indexing' };
192
208
  // Retain only redacted error summaries and allowlisted counters/phases;
@@ -211,7 +227,7 @@ export class XerjIndexer {
211
227
  this.reportFailure(error);
212
228
  });
213
229
  child.once('close', (code) => {
214
- this.child = undefined;
230
+ // Retain the live-owned group handle: leader exit does not prove descendants stopped.
215
231
  if (this.closed)
216
232
  return;
217
233
  if (code === 75) {
@@ -372,14 +388,8 @@ export class XerjIndexer {
372
388
  await this.configurationSaved;
373
389
  await this.diagnosticSaved;
374
390
  const child = this.child;
375
- if (child && child.exitCode === null && child.signalCode === null) {
376
- await new Promise((resolve) => {
377
- child.once('close', resolve);
378
- child.kill('SIGTERM');
379
- const timer = setTimeout(() => child.kill('SIGKILL'), 2_000).unref();
380
- child.once('close', () => clearTimeout(timer));
381
- });
382
- }
391
+ if (child && (await stopOwnedProcessGroup(child)))
392
+ await this.scratch?.release();
383
393
  this.value = { ...this.value, state: this.value.mode === 'off' ? 'disabled' : 'stopped' };
384
394
  this.evidence.connection('unavailable');
385
395
  }
@@ -0,0 +1,21 @@
1
+ /*
2
+ * Copyright (C) 2026 Dyne.org foundation
3
+ * Designed by Denis Roio <jaromil@dyne.org>
4
+ * SPDX-License-Identifier: AGPL-3.0-or-later
5
+ */
6
+ /** Unrelated children must never borrow the relay's ambient owning session. */
7
+ export const sessionScratchEnvironmentKeys = [
8
+ 'TMPDIR',
9
+ 'TMP',
10
+ 'TEMP',
11
+ 'GESTALT_SESSION_TMP_CONTEXT',
12
+ ];
13
+ export function withoutSessionScratch(environment = process.env) {
14
+ const inherited = { ...environment };
15
+ // An ordinary operator TMPDIR may name the host's only executable scratch.
16
+ // Its presence alone is not evidence of owning-session context.
17
+ if (environment.GESTALT_SESSION_TMP_CONTEXT !== undefined)
18
+ for (const key of sessionScratchEnvironmentKeys)
19
+ delete inherited[key];
20
+ return inherited;
21
+ }
@@ -0,0 +1,262 @@
1
+ /*
2
+ * Copyright (C) 2026 Dyne.org foundation
3
+ * Designed by Denis Roio <jaromil@dyne.org>
4
+ * SPDX-License-Identifier: AGPL-3.0-or-later
5
+ */
6
+ import { constants } from 'node:fs';
7
+ import { lstat, mkdir, open, realpath, rmdir } from 'node:fs/promises';
8
+ import { dirname, isAbsolute, join, parse, resolve, sep } from 'node:path';
9
+ import { canonicalScratchWorkspace, readManagedScratchAttribution, readManagedScratchLeases, } from './managed-scratch-owner.js';
10
+ import { privateDirectory } from './scratch-filesystem.js';
11
+ export const containmentFenceName = '.containment-lock';
12
+ const same = (left, right) => left.dev === right.dev && left.ino === right.ino && left.birth === right.birth;
13
+ async function directoryIdentity(path) {
14
+ const info = await lstat(path, { bigint: true });
15
+ if (!info.isDirectory() || info.isSymbolicLink())
16
+ throw new Error('SESSION_SCRATCH_CONTAINMENT_INVALID');
17
+ return { dev: info.dev, ino: info.ino, birth: info.birthtimeNs };
18
+ }
19
+ async function ancestorIdentity(directory, allowRetired) {
20
+ let owner;
21
+ try {
22
+ owner = await readManagedScratchAttribution(directory, allowRetired);
23
+ await readManagedScratchLeases(directory, owner.marker);
24
+ }
25
+ catch (error) {
26
+ if (error instanceof Error &&
27
+ (error.message.startsWith('SESSION_SCRATCH_') || error.message.startsWith('SCRATCH_CLEANUP_')))
28
+ throw error;
29
+ throw new Error('SESSION_SCRATCH_CONTAINMENT_INVALID', { cause: error });
30
+ }
31
+ const marker = owner.marker;
32
+ return {
33
+ directory,
34
+ ownerId: owner.ownerId,
35
+ identity: await directoryIdentity(directory),
36
+ provenance: JSON.stringify([
37
+ marker.schemaVersion,
38
+ marker.ownerKind,
39
+ marker.ownerId,
40
+ marker.workspacePath,
41
+ marker.sessionId,
42
+ marker.createdAt,
43
+ marker.authority.kind,
44
+ marker.authority.sessionId ?? null,
45
+ marker.authority.leaseId ?? null,
46
+ ]),
47
+ };
48
+ }
49
+ async function assertClaimIdentity(claim) {
50
+ if (claim.handle) {
51
+ const held = await claim.handle.stat({ bigint: true });
52
+ if (!same(claim.identity, { dev: held.dev, ino: held.ino, birth: held.birthtimeNs }))
53
+ throw new Error('SESSION_SCRATCH_CONTAINMENT_FENCE_CHANGED');
54
+ }
55
+ if (!same(claim.identity, await directoryIdentity(claim.path)))
56
+ throw new Error('SESSION_SCRATCH_CONTAINMENT_FENCE_CHANGED');
57
+ }
58
+ async function releaseClaim(claim, retire) {
59
+ if (claim.attempted)
60
+ return;
61
+ claim.attempted = true;
62
+ try {
63
+ await assertClaimIdentity(claim);
64
+ await rmdir(claim.path);
65
+ // Cleanup has already retired the marker. Keep the acquired directory FD
66
+ // open through removal of the now-empty registered removal namespace.
67
+ await retire?.();
68
+ }
69
+ finally {
70
+ await claim.handle?.close();
71
+ }
72
+ }
73
+ async function releaseClaims(claims) {
74
+ let failure;
75
+ for (const claim of [...claims].reverse()) {
76
+ try {
77
+ await releaseClaim(claim);
78
+ }
79
+ catch (error) {
80
+ failure ??= error;
81
+ }
82
+ }
83
+ if (failure)
84
+ throw failure;
85
+ }
86
+ /** Interoperates with Launcher scratchWithContainment; no PID/age recovery. */
87
+ export async function claimScratchContainment(workspace, cleanupOwnerId) {
88
+ let selected = await canonicalScratchWorkspace(workspace);
89
+ const selectedIdentity = await directoryIdentity(selected);
90
+ const ancestors = [];
91
+ const parts = selected.slice(parse(selected).root.length).split(sep).filter(Boolean);
92
+ let directory = parse(selected).root;
93
+ for (let index = 0; index < parts.length; index++) {
94
+ directory = join(directory, parts[index]);
95
+ if (index >= 2 && parts[index - 1] === 'sessions' && parts[index - 2] === 'tmp') {
96
+ if (ancestors.length >= 64)
97
+ throw new Error('SESSION_SCRATCH_CONTAINMENT_INVALID');
98
+ const ancestor = await ancestorIdentity(directory, directory === selected && cleanupOwnerId !== undefined);
99
+ if (directory === selected &&
100
+ cleanupOwnerId !== undefined &&
101
+ ancestor.ownerId !== cleanupOwnerId)
102
+ throw new Error('SESSION_SCRATCH_CONTAINMENT_INVALID');
103
+ ancestors.push(ancestor);
104
+ }
105
+ }
106
+ const claims = [];
107
+ const revalidate = async () => {
108
+ await canonicalScratchWorkspace(selected);
109
+ if (!same(selectedIdentity, await directoryIdentity(selected)))
110
+ throw new Error('SESSION_SCRATCH_CONTAINMENT_CHANGED');
111
+ for (const ancestor of ancestors) {
112
+ const current = await ancestorIdentity(ancestor.directory, ancestor.directory === selected && cleanupOwnerId !== undefined);
113
+ if (!same(ancestor.identity, current.identity) || ancestor.provenance !== current.provenance)
114
+ throw new Error('SESSION_SCRATCH_CONTAINMENT_CHANGED');
115
+ }
116
+ for (const claim of claims)
117
+ if (!claim.attempted)
118
+ await assertClaimIdentity(claim);
119
+ };
120
+ try {
121
+ // Ancestors are discovered in path order. Containment always precedes the
122
+ // owner's controller/association operation, and never spans a service lifetime.
123
+ for (const ancestor of ancestors) {
124
+ const path = join(ancestor.directory, containmentFenceName);
125
+ try {
126
+ await mkdir(path, { mode: 0o700 });
127
+ }
128
+ catch (error) {
129
+ if (error.code === 'EEXIST')
130
+ throw new Error('SESSION_SCRATCH_CONTAINMENT_BUSY');
131
+ throw error;
132
+ }
133
+ const claim = {
134
+ directory: ancestor.directory,
135
+ path,
136
+ identity: await directoryIdentity(path),
137
+ attempted: false,
138
+ };
139
+ claims.push(claim);
140
+ await privateDirectory(path, false);
141
+ claim.handle = await open(path, constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
142
+ const held = await claim.handle.stat({ bigint: true });
143
+ if (!same(claim.identity, { dev: held.dev, ino: held.ino, birth: held.birthtimeNs }))
144
+ throw new Error('SESSION_SCRATCH_CONTAINMENT_FENCE_CHANGED');
145
+ const current = await ancestorIdentity(ancestor.directory, ancestor.directory === selected && cleanupOwnerId !== undefined);
146
+ if (!same(ancestor.identity, current.identity) || ancestor.provenance !== current.provenance)
147
+ throw new Error('SESSION_SCRATCH_CONTAINMENT_CHANGED');
148
+ }
149
+ await revalidate();
150
+ }
151
+ catch (error) {
152
+ await releaseClaims(claims);
153
+ throw error;
154
+ }
155
+ return {
156
+ revalidate,
157
+ async relocate(from, to) {
158
+ const ancestor = ancestors.find((value) => value.directory === from);
159
+ const claim = claims.find((value) => value.directory === from);
160
+ if (selected !== from || !cleanupOwnerId || !ancestor || !claim)
161
+ throw new Error('SESSION_SCRATCH_CONTAINMENT_CHANGED');
162
+ await privateDirectory(to, false);
163
+ if (!same(ancestor.identity, await directoryIdentity(to)))
164
+ throw new Error('SESSION_SCRATCH_CONTAINMENT_CHANGED');
165
+ selected = to;
166
+ ancestor.directory = to;
167
+ claim.directory = to;
168
+ claim.path = join(to, containmentFenceName);
169
+ },
170
+ async retireCurrent(at, remove) {
171
+ const claim = claims.at(-1);
172
+ const ancestor = ancestors.at(-1);
173
+ if (!cleanupOwnerId ||
174
+ !claim ||
175
+ !ancestor ||
176
+ claim.directory !== at ||
177
+ !same(ancestor.identity, await directoryIdentity(at)))
178
+ throw new Error('SESSION_SCRATCH_CONTAINMENT_CHANGED');
179
+ await releaseClaim(claim, remove);
180
+ },
181
+ release: () => releaseClaims(claims),
182
+ };
183
+ }
184
+ export async function withScratchContainment(workspace, publish) {
185
+ const guard = await claimScratchContainment(workspace);
186
+ try {
187
+ return await publish();
188
+ }
189
+ finally {
190
+ await guard.release();
191
+ }
192
+ }
193
+ /** Detached history may outlive its cwd; publishing it never allocates scratch. */
194
+ export async function withHistoryScratchContainment(workspace, publish) {
195
+ if (!isAbsolute(workspace))
196
+ throw new Error('SESSION_SCRATCH_UNSAFE_PATH');
197
+ try {
198
+ await directoryIdentity(workspace);
199
+ return withScratchContainment(workspace, publish);
200
+ }
201
+ catch (error) {
202
+ if (error.code !== 'ENOENT')
203
+ throw error;
204
+ }
205
+ if (workspace !== resolve(workspace))
206
+ throw new Error('SESSION_SCRATCH_UNSAFE_PATH');
207
+ let existing = workspace;
208
+ let missing = workspace;
209
+ let identity;
210
+ for (;;) {
211
+ try {
212
+ identity = await directoryIdentity(existing);
213
+ break;
214
+ }
215
+ catch (error) {
216
+ if (error.code !== 'ENOENT')
217
+ throw error;
218
+ missing = existing;
219
+ const parent = dirname(existing);
220
+ if (parent === existing)
221
+ throw error;
222
+ existing = parent;
223
+ }
224
+ }
225
+ // This prefix is only observed: system-owned ordinary ancestors (including /)
226
+ // do not acquire session ownership or become allocation/deletion targets.
227
+ const revalidate = async () => {
228
+ if ((await realpath(existing)) !== existing ||
229
+ !same(identity, await directoryIdentity(existing)))
230
+ throw new Error('SESSION_SCRATCH_CONTAINMENT_CHANGED');
231
+ const absent = await lstat(missing).then(() => false, (error) => {
232
+ if (error.code !== 'ENOENT')
233
+ throw error;
234
+ return true;
235
+ });
236
+ if (!absent)
237
+ throw new Error('SESSION_SCRATCH_CONTAINMENT_CHANGED');
238
+ };
239
+ await revalidate();
240
+ let deepestOwner;
241
+ let ownerCount = 0;
242
+ const parts = workspace.slice(parse(workspace).root.length).split(sep).filter(Boolean);
243
+ let directory = parse(workspace).root;
244
+ for (let index = 0; index < parts.length; index++) {
245
+ directory = join(directory, parts[index]);
246
+ if (index >= 2 && parts[index - 1] === 'sessions' && parts[index - 2] === 'tmp') {
247
+ if (++ownerCount > 64)
248
+ throw new Error('SESSION_SCRATCH_CONTAINMENT_INVALID');
249
+ deepestOwner = directory;
250
+ }
251
+ }
252
+ // Scan the full lexical target, even beyond the missing frontier. Claiming the
253
+ // deepest owner validates every reserved ancestor; absent/unknown owners fail.
254
+ const guard = deepestOwner ? await claimScratchContainment(deepestOwner) : undefined;
255
+ try {
256
+ await revalidate();
257
+ return await publish();
258
+ }
259
+ finally {
260
+ await guard?.release();
261
+ }
262
+ }