gestalt-mobile 0.75.1 → 0.75.3

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.
@@ -16,8 +16,8 @@ SPDX-License-Identifier: AGPL-3.0-or-later
16
16
  <link rel="icon" href="/icons/gestalt-mobile-192.png" />
17
17
  <link rel="apple-touch-icon" href="/icons/gestalt-mobile-180.png" />
18
18
  <title>Gestalt Mobile</title>
19
- <script type="module" crossorigin src="/assets/index-CBBThxjT.js"></script>
20
- <link rel="stylesheet" crossorigin href="/assets/index-B7ZFxnEl.css">
19
+ <script type="module" crossorigin src="/assets/index-CzzHxwsz.js"></script>
20
+ <link rel="stylesheet" crossorigin href="/assets/index-C0ie_n0o.css">
21
21
  </head>
22
22
  <body>
23
23
  <div id="app"></div>
@@ -4,8 +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 './platform/scratch/child-environment.js';
8
- import { probePlaywrightComponent } from './platform/codex/playwright-component.js';
7
+ import { readPlaywrightComponent } from './platform/codex/playwright-component.js';
9
8
  import { existsSync } from 'node:fs';
10
9
  import { readFile } from 'node:fs/promises';
11
10
  import { homedir } from 'node:os';
@@ -78,26 +77,6 @@ export function componentVersions(mobileVersion, codexVersion, environment = pro
78
77
  },
79
78
  ];
80
79
  }
81
- export async function runStartupDoctor(cwd) {
82
- if (process.env.GESTALT_STARTUP_DIAGNOSTICS_DONE === '1')
83
- return { ok: true, report: '' };
84
- try {
85
- const result = await runFile('gestalt', ['doctor'], {
86
- cwd,
87
- env: withoutSessionScratch(),
88
- timeout: 60_000,
89
- maxBuffer: 1024 * 1024,
90
- });
91
- return { ok: true, report: `${result.stdout}${result.stderr}` };
92
- }
93
- catch (error) {
94
- const failure = error;
95
- return {
96
- ok: false,
97
- report: `${failure.stdout ?? ''}${failure.stderr ?? ''}${failure.message ? `${failure.message}\n` : ''}`,
98
- };
99
- }
100
- }
101
80
  export function packageRoot(moduleUrl) {
102
81
  let directory = dirname(fileURLToPath(moduleUrl));
103
82
  while (true) {
@@ -299,11 +278,6 @@ export async function runCli(dependencies = {}) {
299
278
  stderr.write(`${error instanceof Error ? error.message : 'Invalid --icon file'}\n\n${usage}\n`);
300
279
  return 2;
301
280
  }
302
- const diagnosis = await (dependencies.runStartupDoctor ?? runStartupDoctor)(cwd);
303
- if (diagnosis.report)
304
- stderr.write(diagnosis.report);
305
- if (!diagnosis.ok)
306
- stderr.write('WARNING: Startup diagnostics reported a problem; Gestalt Mobile will continue so it can show recovery controls.\n');
307
281
  const installedCodexVersion = await (dependencies.probeCodexVersion ?? probeCodexVersion)();
308
282
  const installedKimiVersion = await (dependencies.probeKimiVersion ?? probeKimiVersion)();
309
283
  const mobileVersion = await packageVersion(moduleUrl);
@@ -318,7 +292,7 @@ export async function runCli(dependencies = {}) {
318
292
  profiles: new LauncherProfileCatalog(),
319
293
  installedCodexVersion,
320
294
  installedKimiVersion,
321
- componentVersions: componentVersions(mobileVersion, installedCodexVersion, dependencies.environment, await (dependencies.probePlaywrightComponent ?? probePlaywrightComponent)(config.root, dependencies.environment)),
295
+ componentVersions: componentVersions(mobileVersion, installedCodexVersion, dependencies.environment, await (dependencies.readPlaywrightComponent ?? readPlaywrightComponent)(dependencies.environment)),
322
296
  startAppServers: true,
323
297
  homeDirectory: dependencies.homeDirectory,
324
298
  explicitSkillProfile,
@@ -8152,6 +8152,12 @@ describe('production composition', () => {
8152
8152
  ['HEAD', '/api/sessions/recent-threads', '/api/sessions/recent-threads', 'protected'],
8153
8153
  ['GET', '/api/sessions/:id', '/api/sessions/session-1', 'protected'],
8154
8154
  ['DELETE', '/api/sessions/:id', '/api/sessions/session-1', 'protected'],
8155
+ [
8156
+ 'DELETE',
8157
+ '/api/sessions/:id/keep-temporary-files/:keepFilesFor',
8158
+ '/api/sessions/session-1/keep-temporary-files/operation-1',
8159
+ 'protected',
8160
+ ],
8155
8161
  ['GET', '/api/sessions/:id/attention', '/api/sessions/session-1/attention', 'protected'],
8156
8162
  [
8157
8163
  'POST',
@@ -1648,7 +1648,9 @@ export async function composeRelayApp(options) {
1648
1648
  },
1649
1649
  clean: (session, operationId) => workspaceForget.clean(session, operationId, () => {
1650
1650
  const operation = forgetOperations.find(session.id);
1651
- return operation?.operationId === operationId && operation.phase === 'cleaning';
1651
+ return (operation?.operationId === operationId &&
1652
+ operation.phase === 'cleaning' &&
1653
+ !operation.keepFilesRequested);
1652
1654
  }, () => sessions.list()),
1653
1655
  changed: (operation) => {
1654
1656
  if (sessions.find(operation.sessionId))
@@ -2396,7 +2398,7 @@ export async function composeRelayApp(options) {
2396
2398
  : undefined,
2397
2399
  sessionRoutes: {
2398
2400
  ...ordinarySessionLifecycle,
2399
- forget: (id) => forgetSessions.execute(id),
2401
+ forget: (id, keepFilesFor) => forgetSessions.execute(id, keepFilesFor),
2400
2402
  forgetOperation: (id) => forgetOperations.find(id),
2401
2403
  createId: randomUUID,
2402
2404
  now: () => new Date().toISOString(),
@@ -3,11 +3,21 @@
3
3
  * Designed by Denis Roio <jaromil@dyne.org>
4
4
  * SPDX-License-Identifier: AGPL-3.0-or-later
5
5
  */
6
+ import { ForgetRecoveryUnavailable } from './use-case.js';
7
+ export const keepTemporaryFilesRoute = '/api/sessions/:id/keep-temporary-files/:keepFilesFor';
6
8
  export function registerForgetSession(app, deps) {
7
- app.delete('/api/sessions/:id', async (request, reply) => {
8
- const id = request.params.id;
9
+ const remove = async (request, reply) => {
10
+ const { id, keepFilesFor } = request.params;
9
11
  if (deps.forget) {
10
- const operation = await deps.forget(id);
12
+ let operation;
13
+ try {
14
+ operation = await deps.forget(id, keepFilesFor);
15
+ }
16
+ catch (error) {
17
+ if (error instanceof ForgetRecoveryUnavailable)
18
+ return reply.code(409).send({ code: 'SESSION_FORGET_RECOVERY_UNAVAILABLE' });
19
+ throw error;
20
+ }
11
21
  if (!operation)
12
22
  return reply.code(404).send({ code: 'SESSION_NOT_FOUND' });
13
23
  if (operation.phase === 'failed' && operation.blockingSessionId)
@@ -26,5 +36,8 @@ export function registerForgetSession(app, deps) {
26
36
  await deps.close?.(id);
27
37
  deps.remove?.(id);
28
38
  return reply.code(204).send();
29
- });
39
+ };
40
+ app.delete('/api/sessions/:id', remove);
41
+ if (deps.forget)
42
+ app.delete(keepTemporaryFilesRoute, remove);
30
43
  }
@@ -5,6 +5,8 @@
5
5
  */
6
6
  import { isForgetCleanupFolder, } from '../../../../shared/contracts/session-forget.js';
7
7
  import { WorkspaceSessionConflict } from '../application/workspace-conflict.js';
8
+ export class ForgetRecoveryUnavailable extends Error {
9
+ }
8
10
  export class WorkspaceCleanupFailure extends Error {
9
11
  folders;
10
12
  constructor(folders, cause) {
@@ -18,11 +20,17 @@ export class ForgetSession {
18
20
  constructor(deps) {
19
21
  this.deps = deps;
20
22
  }
21
- execute(id) {
23
+ execute(id, keepFilesFor) {
22
24
  const prior = this.pending.get(id);
23
- if (prior)
25
+ if (prior) {
26
+ if (keepFilesFor !== undefined) {
27
+ const current = this.deps.operations.find(id);
28
+ if (current?.operationId !== keepFilesFor || !current.keepFilesRequested)
29
+ return Promise.reject(new ForgetRecoveryUnavailable());
30
+ }
24
31
  return prior;
25
- const operation = this.run(id);
32
+ }
33
+ const operation = this.run(id, keepFilesFor);
26
34
  this.pending.set(id, operation);
27
35
  void operation
28
36
  .finally(() => {
@@ -35,8 +43,8 @@ export class ForgetSession {
35
43
  async drain() {
36
44
  await Promise.allSettled([...this.pending.values()]);
37
45
  }
38
- async run(id) {
39
- const initial = this.deps.operations.begin(id);
46
+ async run(id, keepFilesFor) {
47
+ const initial = this.deps.operations.begin(id, keepFilesFor);
40
48
  if (!initial || initial.phase === 'completed')
41
49
  return initial;
42
50
  let operation = initial;
@@ -62,9 +70,12 @@ export class ForgetSession {
62
70
  return operation;
63
71
  await this.deps.release(session);
64
72
  failureCode = 'SESSION_CLEANUP_FAILED';
65
- if (advance('cleaning').phase === 'completed')
66
- return operation;
67
- const cleanup = await this.deps.clean(session, operation.operationId);
73
+ let cleanup = 'retained';
74
+ if (!initial.keepFilesRequested) {
75
+ if (advance('cleaning').phase === 'completed')
76
+ return operation;
77
+ cleanup = await this.deps.clean(session, operation.operationId);
78
+ }
68
79
  if (cleanup && typeof cleanup === 'object')
69
80
  releaseCleanup = () => cleanup.release();
70
81
  operation = {
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import { authorizationSessionDevice } from '../../platform/http/authorization-boundary.js';
7
7
  import { stopSession } from './lifecycle/use-case.js';
8
- import { registerForgetSession } from './forget-session/endpoint.js';
8
+ import { keepTemporaryFilesRoute, registerForgetSession } from './forget-session/endpoint.js';
9
9
  import { registerGetHistory } from './get-history/endpoint.js';
10
10
  import { registerGetSession } from './get-session/endpoint.js';
11
11
  import { registerInterruptTurn } from './interrupt-turn/endpoint.js';
@@ -56,7 +56,9 @@ export function registerSessionRoutes(app, deps) {
56
56
  return null;
57
57
  if (['GET', 'HEAD'].includes(request.method))
58
58
  return null;
59
- if (request.method === 'DELETE' && request.routeOptions.url === '/api/sessions/:id')
59
+ if (request.method === 'DELETE' &&
60
+ (request.routeOptions.url === '/api/sessions/:id' ||
61
+ request.routeOptions.url === keepTemporaryFilesRoute))
60
62
  return null;
61
63
  const id = request.params?.id;
62
64
  return id ? sessions.forgetOperation?.(id) : null;
@@ -4,9 +4,9 @@
4
4
  * SPDX-License-Identifier: AGPL-3.0-or-later
5
5
  */
6
6
  import { ManagedPlaywright } from './managed-playwright.js';
7
- /** Uses a disposable local page to test Chrome without acquiring a session lease. */
8
- export async function probePlaywrightComponent(cwd, environment = process.env, adapter = new ManagedPlaywright(environment)) {
9
- let component = {
7
+ /** Read the installed version for Mobile's component list without launching Chrome. */
8
+ export async function readPlaywrightComponent(environment = process.env, adapter = new ManagedPlaywright(environment)) {
9
+ const component = {
10
10
  id: 'playwright',
11
11
  label: 'Playwright MCP',
12
12
  version: null,
@@ -17,36 +17,18 @@ export async function probePlaywrightComponent(cwd, environment = process.env, a
17
17
  const installation = await adapter.check();
18
18
  if (installation.status !== 'installed')
19
19
  return component;
20
- component = { ...component, version: installation.version };
21
- let readiness = await adapter.ready(installation.manager, cwd, Date.now() + 15000, [
22
- '--launch',
23
- ]);
24
- // Older managers reject --launch. Preserve prerequisite reporting during
25
- // separate Mobile/manager upgrades, without claiming a browser was tested.
26
- if (readiness.package === 'unknown' && readiness.chrome === 'unknown') {
27
- readiness = await adapter.ready(installation.manager, cwd, Date.now() + 5000);
28
- }
29
- const engine = readiness.playwrightVersion ? `Playwright ${readiness.playwrightVersion}; ` : '';
30
20
  return {
31
21
  ...component,
32
22
  version: installation.version,
33
- status: readiness.ready
34
- ? readiness.browserTest === 'passed'
35
- ? 'working'
36
- : 'ready'
37
- : 'unavailable',
38
- detail: readiness.ready
39
- ? readiness.browserTest === 'passed'
40
- ? `${engine}Chrome ${readiness.chromeVersion ?? 'detected'}; browser page check passed at startup.`
41
- : `${engine}Chrome ${readiness.chromeVersion ?? 'detected'}; prerequisites ready. Browser session has not been tested.`
42
- : 'Playwright is installed; Chrome or runtime prerequisites are unavailable or unverified.',
23
+ status: 'unverified',
24
+ detail: 'Playwright is installed. Run gestalt update to check its prerequisites.',
43
25
  };
44
26
  }
45
27
  catch {
46
28
  return {
47
29
  ...component,
48
30
  status: 'unverified',
49
- detail: 'Playwright readiness could not be checked.',
31
+ detail: 'Playwright installation metadata could not be read.',
50
32
  };
51
33
  }
52
34
  }
@@ -57,6 +57,8 @@ export function migrate(database) {
57
57
  const forgetColumns = database
58
58
  .prepare('PRAGMA table_info(session_forget_operations)')
59
59
  .all();
60
+ if (!forgetColumns.some((column) => column.name === 'keep_files_requested'))
61
+ database.exec('ALTER TABLE session_forget_operations ADD COLUMN keep_files_requested INTEGER NOT NULL DEFAULT 0');
60
62
  if (!forgetColumns.some((column) => column.name === 'scratch_retained'))
61
63
  database.exec('ALTER TABLE session_forget_operations ADD COLUMN scratch_retained INTEGER NOT NULL DEFAULT 0');
62
64
  database.exec(`CREATE TABLE IF NOT EXISTS workspace_forget_locks (
@@ -4,6 +4,7 @@
4
4
  * SPDX-License-Identifier: AGPL-3.0-or-later
5
5
  */
6
6
  import { randomUUID } from 'node:crypto';
7
+ import { ForgetRecoveryUnavailable, } from '../../features/sessions/forget-session/use-case.js';
7
8
  import { isForgetCleanupFolder, } from '../../../shared/contracts/session-forget.js';
8
9
  import { canonicalSessionWorkspace } from './sqlite-workspace-lifecycle.js';
9
10
  import { WorkspaceSessionConflict } from '../../features/sessions/application/workspace-conflict.js';
@@ -27,6 +28,7 @@ export class SqliteForgetOperationStore {
27
28
  phase: row.phase,
28
29
  updatedAt: row.updated_at,
29
30
  ...(row.failure_code ? { failureCode: row.failure_code } : {}),
31
+ ...(row.keep_files_requested ? { keepFilesRequested: true } : {}),
30
32
  ...(row.scratch_retained ? { scratchRetained: true } : {}),
31
33
  ...(row.blocking_session_id ? { blockingSessionId: row.blocking_session_id } : {}),
32
34
  ...(cleanupFolders.length ? { cleanupFolders } : {}),
@@ -42,9 +44,21 @@ export class SqliteForgetOperationStore {
42
44
  .prepare("SELECT session_id FROM session_forget_operations WHERE phase != 'completed'")
43
45
  .all().map((row) => row.session_id);
44
46
  }
45
- begin(id) {
47
+ begin(id, keepFilesFor) {
46
48
  this.db.exec('SAVEPOINT begin_forget');
47
49
  try {
50
+ if (keepFilesFor !== undefined) {
51
+ const existing = this.find(id);
52
+ if (existing?.operationId !== keepFilesFor ||
53
+ (!existing.keepFilesRequested &&
54
+ !(existing.phase === 'failed' &&
55
+ existing.failureCode === 'SESSION_CLEANUP_FAILED' &&
56
+ !existing.blockingSessionId)))
57
+ throw new ForgetRecoveryUnavailable();
58
+ this.db
59
+ .prepare('UPDATE session_forget_operations SET keep_files_requested=1 WHERE session_id=? AND operation_id=?')
60
+ .run(id, keepFilesFor);
61
+ }
48
62
  this.db
49
63
  .prepare(`INSERT INTO session_forget_operations (session_id, operation_id, phase, updated_at)
50
64
  SELECT id, ?, 'stopping', ? FROM relay_sessions WHERE id = ?
@@ -4,6 +4,7 @@
4
4
  * SPDX-License-Identifier: AGPL-3.0-or-later
5
5
  */
6
6
  import { randomUUID } from 'node:crypto';
7
+ import { constants } from 'node:fs';
7
8
  import { lstat, mkdir, open, readdir, realpath, rename, rm, rmdir } from 'node:fs/promises';
8
9
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
9
10
  import { emptyScratchCounts, } from '../../features/sessions/clean-tmp/use-case.js';
@@ -21,6 +22,25 @@ function reject(reason) {
21
22
  function payloadPath(directory, name) {
22
23
  return Buffer.concat([Buffer.from(directory), Buffer.from(sep), name]);
23
24
  }
25
+ /** Restore owner write access only to the directories inspected before retirement. */
26
+ async function prepareReadOnlyDirectories(root, directories) {
27
+ for (const directory of directories) {
28
+ const path = payloadPath(root, directory.relativePath);
29
+ const handle = await open(path, constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
30
+ try {
31
+ const info = await handle.stat({ bigint: true });
32
+ if (info.uid !== BigInt(process.getuid()) ||
33
+ info.dev !== directory.dev ||
34
+ info.ino !== directory.ino ||
35
+ info.birthtimeNs !== directory.birthtimeNs)
36
+ reject('unsafe');
37
+ await handle.chmod(Number(info.mode & 4095n) | 0o300);
38
+ }
39
+ finally {
40
+ await handle.close();
41
+ }
42
+ }
43
+ }
24
44
  /** Only the managed namespace is traversed. There are no prefix/age/PID legacy recognizers. */
25
45
  export class FilesystemScratchCleanup {
26
46
  async cleanSession(session, authorized, protectedSessions) {
@@ -134,13 +154,14 @@ export class FilesystemScratchCleanup {
134
154
  // Manual Clean Tmp bounds opportunistic inspection. Explicit Forget
135
155
  // has to finish checking large owners before retiring the session.
136
156
  const inspectionBudget = () => (authorized ? undefined : { entries: 0 });
137
- await this.validatePayload(directory, inspectionBudget());
157
+ const readOnlyDirectories = await this.validatePayload(directory, inspectionBudget());
158
+ let readOnlyRuntimeDirectories = [];
138
159
  if (marker.runtime) {
139
160
  const present = await validateRuntime(marker, marker.runtime, true);
140
161
  if (present) {
141
162
  await this.assertProtection(directory, join(container, ownerId), marker, protectedSessions, authorized, onlyOwnerId ??
142
163
  (authorizedSessionId ? mobileScratchOwnerId(authorizedSessionId) : undefined));
143
- await this.validatePayload(marker.runtime.directory, inspectionBudget());
164
+ readOnlyRuntimeDirectories = await this.validatePayload(marker.runtime.directory, inspectionBudget());
144
165
  }
145
166
  }
146
167
  await privateDirectory(directory, false);
@@ -168,6 +189,7 @@ export class FilesystemScratchCleanup {
168
189
  await containment.revalidate();
169
190
  await this.assertProtection(directory, join(container, ownerId), marker, protectedSessions, authorized, onlyOwnerId ??
170
191
  (authorizedSessionId ? mobileScratchOwnerId(authorizedSessionId) : undefined));
192
+ await prepareReadOnlyDirectories(directory, readOnlyDirectories);
171
193
  // Keep authority metadata until disposable payload has been removed. A failed
172
194
  // payload deletion is retryable; an interrupted metadata retirement is unknown.
173
195
  for (const child of await readdir(directory, { encoding: 'buffer' })) {
@@ -175,7 +197,7 @@ export class FilesystemScratchCleanup {
175
197
  continue;
176
198
  await rm(payloadPath(directory, child), { recursive: true });
177
199
  }
178
- await this.retireRuntime(directory, marker);
200
+ await this.retireRuntime(directory, marker, readOnlyRuntimeDirectories);
179
201
  if ((await readdir(directory)).includes('leases'))
180
202
  await rm(join(directory, 'leases'), { recursive: true });
181
203
  await rm(join(directory, scratchMarkerName));
@@ -297,7 +319,7 @@ export class FilesystemScratchCleanup {
297
319
  await this.retireNestedNamespaces(path, protectedSessions, authorized, authorizedSessionId, inherited, name === 'tmp', depth + 1);
298
320
  }
299
321
  }
300
- async retireRuntime(directory, marker) {
322
+ async retireRuntime(directory, marker, readOnlyDirectories) {
301
323
  if (!marker.runtime)
302
324
  return;
303
325
  const runtime = marker.runtime;
@@ -325,6 +347,7 @@ export class FilesystemScratchCleanup {
325
347
  reject('unrecognized');
326
348
  if (attributed) {
327
349
  await validateRuntime(marker, marker.runtime, true);
350
+ await prepareReadOnlyDirectories(runtime.directory, readOnlyDirectories);
328
351
  for (const child of children) {
329
352
  if (child.toString() !== runtimeMarkerName)
330
353
  await rm(payloadPath(runtime.directory, child), { recursive: true });
@@ -369,41 +392,63 @@ export class FilesystemScratchCleanup {
369
392
  }
370
393
  }
371
394
  }
372
- async validatePayload(directory, budget, root = directory, depth = 0) {
373
- if (depth > 128)
374
- reject('unrecognized');
375
- // Even an empty nested namespace is not authority to retire a workspace's
376
- // contents recursively as another owner's payload.
377
- if (directory !== root &&
378
- basename(directory.toString()) === 'sessions' &&
379
- basename(dirname(directory.toString())) === 'tmp')
380
- reject('unrecognized');
381
- for (const entry of await readdir(directory, { encoding: 'buffer', withFileTypes: true })) {
382
- const child = entry.name;
383
- if (budget && ++budget.entries > 100_000)
395
+ async validatePayload(root, budget) {
396
+ const links = new Map();
397
+ const readOnlyDirectories = [];
398
+ const prefixLength = Buffer.byteLength(root) + 1;
399
+ async function visit(directory, depth) {
400
+ if (depth > 128)
384
401
  reject('unrecognized');
385
- if (child.toString() === workspacePublicationName)
386
- reject('busy');
402
+ // Even an empty nested namespace is not authority to retire a workspace's
403
+ // contents recursively as another owner's payload.
387
404
  if (directory !== root &&
388
- [
389
- scratchMarkerName,
390
- runtimeMarkerName,
391
- '.controller-lock',
392
- '.association-lock',
393
- containmentFenceName,
394
- ].includes(child.toString()))
405
+ basename(directory.toString()) === 'sessions' &&
406
+ basename(dirname(directory.toString())) === 'tmp')
395
407
  reject('unrecognized');
396
- const path = payloadPath(directory, child);
397
- const info = await lstat(path);
398
- if ((process.getuid && info.uid !== process.getuid()) ||
399
- (!info.isDirectory() && !info.isFile() && !info.isSymbolicLink() && !info.isSocket()) ||
400
- (info.isFile() && info.nlink !== 1))
401
- reject('unsafe');
402
- // Payload symlinks (for example npm's .bin entries) are disposable links.
403
- // lstat never follows them, and rm unlinks them without deleting their targets.
404
- // Owner paths and authority metadata retain their separate no-link checks.
405
- if (info.isDirectory())
406
- await this.validatePayload(path, budget, root, depth + 1);
408
+ for (const entry of await readdir(directory, { encoding: 'buffer', withFileTypes: true })) {
409
+ const child = entry.name;
410
+ if (budget && ++budget.entries > 100_000)
411
+ reject('unrecognized');
412
+ if (child.toString() === workspacePublicationName)
413
+ reject('busy');
414
+ if (directory !== root &&
415
+ [
416
+ scratchMarkerName,
417
+ runtimeMarkerName,
418
+ '.controller-lock',
419
+ '.association-lock',
420
+ containmentFenceName,
421
+ ].includes(child.toString()))
422
+ reject('unrecognized');
423
+ const path = payloadPath(directory, child);
424
+ const info = await lstat(path, { bigint: true });
425
+ if ((process.getuid && info.uid !== BigInt(process.getuid())) ||
426
+ (!info.isDirectory() && !info.isFile() && !info.isSymbolicLink() && !info.isSocket()))
427
+ reject('unsafe');
428
+ // Every name for a multiply-linked inode must be inside this validated root.
429
+ if (info.isFile() && info.nlink > 1n) {
430
+ const key = `${info.dev}:${info.ino}`;
431
+ links.set(key, (links.get(key) ?? info.nlink) - 1n);
432
+ }
433
+ // Payload symlinks (for example npm's .bin entries) are disposable links.
434
+ // lstat never follows them, and rm unlinks them without deleting their targets.
435
+ // Owner paths and authority metadata retain their separate no-link checks.
436
+ if (info.isDirectory()) {
437
+ if (process.getuid && (info.mode & 192n) !== 192n)
438
+ readOnlyDirectories.push({
439
+ relativePath: path.subarray(prefixLength),
440
+ dev: info.dev,
441
+ ino: info.ino,
442
+ birthtimeNs: info.birthtimeNs,
443
+ });
444
+ await visit(path, depth + 1);
445
+ }
446
+ }
407
447
  }
448
+ await visit(root, 0);
449
+ for (const remaining of links.values())
450
+ if (remaining !== 0n)
451
+ reject('unsafe');
452
+ return readOnlyDirectories;
408
453
  }
409
454
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gestalt-mobile",
3
- "version": "0.75.1",
3
+ "version": "0.75.3",
4
4
  "description": "Mobile-first web relay for durable Codex development sessions",
5
5
  "keywords": [
6
6
  "codex",