gestalt-mobile 0.75.0 → 0.75.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.
@@ -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-CpcdImYc.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>
@@ -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',
@@ -104,8 +104,7 @@ import { planAttachmentSupervision } from './features/plans/application/plan-att
104
104
  import { prepareOrgPlanSupervision } from './features/plans/application/prepare-org-plan-supervision.js';
105
105
  import { startOrgPlanSupervision, OrgPlanSessionNotPublished, } from './features/plans/application/start-org-plan-supervision.js';
106
106
  import { SqliteOrgPlanLaunchStore } from './platform/persistence/sqlite-org-plan-launch-store.js';
107
- import { resolveSessionSkillSelection } from './features/sessions/application/resolve-session-skills.js';
108
- import { prepareOrgPlanSettings } from './features/plans/application/prepare-org-plan-settings.js';
107
+ import { prepareOrgPlanSettings, resolveSupervisorSkillSelection, } from './features/plans/application/prepare-org-plan-settings.js';
109
108
  import { FilesystemPlanStatusSource } from './platform/plans/filesystem-plan-status-source.js';
110
109
  import { FilesystemWorkspacePlanCatalog } from './platform/plans/filesystem-workspace-plan-catalog.js';
111
110
  import { FilesystemOrgPlanContext } from './platform/plans/filesystem-org-plan-context.js';
@@ -1649,7 +1648,9 @@ export async function composeRelayApp(options) {
1649
1648
  },
1650
1649
  clean: (session, operationId) => workspaceForget.clean(session, operationId, () => {
1651
1650
  const operation = forgetOperations.find(session.id);
1652
- return operation?.operationId === operationId && operation.phase === 'cleaning';
1651
+ return (operation?.operationId === operationId &&
1652
+ operation.phase === 'cleaning' &&
1653
+ !operation.keepFilesRequested);
1653
1654
  }, () => sessions.list()),
1654
1655
  changed: (operation) => {
1655
1656
  if (sessions.find(operation.sessionId))
@@ -2068,7 +2069,6 @@ export async function composeRelayApp(options) {
2068
2069
  profiles: options.profiles,
2069
2070
  skillProfiles,
2070
2071
  skillCatalog,
2071
- defaultSkillProfile: options.explicitSkillProfile,
2072
2072
  }, selectedProfile),
2073
2073
  owner: async (canonicalPath, workspacePath) => {
2074
2074
  const pending = orgPlanLaunches.owner(canonicalPath) ?? orgPlanLaunches.workspaceOwner(workspacePath);
@@ -2127,14 +2127,10 @@ export async function composeRelayApp(options) {
2127
2127
  return false;
2128
2128
  }
2129
2129
  },
2130
- captureSkills: (context) => resolveSessionSkillSelection({
2131
- workspacePath: context.workspace.path,
2132
- provider: 'codex',
2133
- profile: 'default',
2134
- ...(context.settings.skillProfile
2135
- ? { skillProfile: context.settings.skillProfile }
2136
- : {}),
2137
- }, { skillProfiles, skillCatalog, defaultSkillProfile: options.explicitSkillProfile }),
2130
+ captureSkills: (context) => resolveSupervisorSkillSelection(context.workspace.path, context.settings.skillProfile, {
2131
+ skillProfiles,
2132
+ skillCatalog,
2133
+ }),
2138
2134
  sessions: {
2139
2135
  create: async (id, context, selection, publication) => {
2140
2136
  orgPlanStarting.set(id, (orgPlanStarting.get(id) ?? 0) + 1);
@@ -2402,7 +2398,7 @@ export async function composeRelayApp(options) {
2402
2398
  : undefined,
2403
2399
  sessionRoutes: {
2404
2400
  ...ordinarySessionLifecycle,
2405
- forget: (id) => forgetSessions.execute(id),
2401
+ forget: (id, keepFilesFor) => forgetSessions.execute(id, keepFilesFor),
2406
2402
  forgetOperation: (id) => forgetOperations.find(id),
2407
2403
  createId: randomUUID,
2408
2404
  now: () => new Date().toISOString(),
@@ -6,6 +6,15 @@
6
6
  import { sessionDefaultsSchema, resolveNewSessionDefaults, } from '../../../../shared/contracts/session-defaults.js';
7
7
  import { readGlobalSkillProfiles } from '../../skills/application/read-global-profiles.js';
8
8
  import { resolveSessionSkillSelection } from '../../sessions/application/resolve-session-skills.js';
9
+ /** Resolve the same supervisor skills during preparation and launch. */
10
+ export function resolveSupervisorSkillSelection(workspacePath, skillProfile, deps) {
11
+ return resolveSessionSkillSelection({
12
+ workspacePath,
13
+ provider: 'codex',
14
+ profile: 'default',
15
+ ...(skillProfile ? { skillProfile } : { mandatorySkillsOnly: true }),
16
+ }, deps);
17
+ }
9
18
  /** Read-only counterpart of the ordinary New session form and skill snapshot. */
10
19
  export async function prepareOrgPlanSettings(workspacePath, deps, skillProfile) {
11
20
  const unavailable = (code, reason) => ({ kind: 'unavailable', code, reason });
@@ -36,15 +45,10 @@ export async function prepareOrgPlanSettings(workspacePath, deps, skillProfile)
36
45
  if (selected && !valid(selected)) {
37
46
  if (skillProfile !== undefined)
38
47
  return unavailable('SKILL_PROFILE_UNAVAILABLE', 'The selected supervisor skill profile disappeared or is invalid. Refresh and choose again.');
39
- warnings.push('The saved skill profile is unavailable. Default is selected; choose a supervisor profile before confirming.');
48
+ warnings.push('The saved skill profile is unavailable. None is selected, so only mandatory Gestalt skills will load.');
40
49
  selected = '';
41
50
  }
42
- const effectiveSkillSelection = await resolveSessionSkillSelection({
43
- workspacePath,
44
- provider: 'codex',
45
- profile: 'default',
46
- ...(selected ? { skillProfile: selected } : {}),
47
- }, deps);
51
+ const effectiveSkillSelection = await resolveSupervisorSkillSelection(workspacePath, selected, deps);
48
52
  if (!effectiveSkillSelection.skills.some((skill) => skill.name === 'gestalt:org-plan' && skill.enabled))
49
53
  return unavailable('GESTALT_CAPABILITIES_UNAVAILABLE', 'The Org-plan skill is unavailable in the ordinary Codex session catalog. Restore Gestalt capabilities and retry.');
50
54
  const { workspaceId: _workspaceId, ...settings } = defaults;
@@ -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;
@@ -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.0",
3
+ "version": "0.75.2",
4
4
  "description": "Mobile-first web relay for durable Codex development sessions",
5
5
  "keywords": [
6
6
  "codex",