gestalt-mobile 0.72.0 → 0.72.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.
@@ -0,0 +1,147 @@
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 { randomBytes } from 'node:crypto';
7
+ import { lstat, mkdir, open, readdir, realpath } from 'node:fs/promises';
8
+ import { dirname, join } from 'node:path';
9
+ import { privateDirectory, readMarker } from './scratch-filesystem.js';
10
+ export const runtimeMarkerName = '.gestalt-runtime.json';
11
+ export const runtimeRootMaxBytes = 48;
12
+ function reject() {
13
+ throw new Error('SESSION_SCRATCH_RUNTIME_INVALID');
14
+ }
15
+ export async function runtimeContainer() {
16
+ if (!process.getuid)
17
+ reject();
18
+ // /tmp is deliberately independent of TMPDIR and workspace depth. On macOS
19
+ // resolve its system alias once; payload directories themselves are not links.
20
+ return join(await realpath('/tmp'), `gs-${process.getuid()}`);
21
+ }
22
+ export async function runtimeIdentity(directory) {
23
+ await privateDirectory(directory, false);
24
+ const info = await lstat(directory, { bigint: true });
25
+ return `${info.dev}:${info.ino}:${info.birthtimeNs}`;
26
+ }
27
+ export function runtimeRecord(owner, runtime) {
28
+ return {
29
+ schemaVersion: 2,
30
+ ownerId: owner.ownerId,
31
+ workspacePath: owner.workspacePath,
32
+ token: runtime.token,
33
+ identity: runtime.identity,
34
+ };
35
+ }
36
+ /** Only a fresh exclusive directory may become a runtime allocation. */
37
+ export async function allocateRuntime(owner) {
38
+ const container = await runtimeContainer();
39
+ await privateDirectory(container, true);
40
+ for (let attempt = 0; attempt < 16; attempt++) {
41
+ const directory = join(container, randomBytes(10).toString('hex'));
42
+ if (Buffer.byteLength(directory) > runtimeRootMaxBytes)
43
+ throw new Error('SESSION_SCRATCH_RUNTIME_ROOT_TOO_LONG');
44
+ try {
45
+ await mkdir(directory, { mode: 0o700 });
46
+ }
47
+ catch (error) {
48
+ if (error.code === 'EEXIST')
49
+ continue;
50
+ throw error;
51
+ }
52
+ const runtime = {
53
+ directory,
54
+ token: randomBytes(32).toString('hex'),
55
+ identity: await runtimeIdentity(directory),
56
+ };
57
+ const handle = await open(join(directory, runtimeMarkerName), 'wx', 0o600);
58
+ try {
59
+ await handle.writeFile(`${JSON.stringify(runtimeRecord(owner, runtime))}\n`);
60
+ await handle.sync();
61
+ }
62
+ finally {
63
+ await handle.close();
64
+ }
65
+ return runtime;
66
+ }
67
+ throw new Error('SESSION_SCRATCH_RUNTIME_COLLISION');
68
+ }
69
+ /** The workspace record and physical root must agree, including inode identity. */
70
+ export async function validateRuntime(owner, runtime, allowRetiring = false) {
71
+ const container = await runtimeContainer();
72
+ if (!runtime ||
73
+ typeof runtime.directory !== 'string' ||
74
+ dirname(runtime.directory) !== container ||
75
+ !/^[0-9a-f]{20}$/.test(runtime.directory.slice(container.length + 1)) ||
76
+ Buffer.byteLength(runtime.directory) > runtimeRootMaxBytes ||
77
+ typeof runtime.token !== 'string' ||
78
+ !/^[0-9a-f]{64}$/.test(runtime.token) ||
79
+ typeof runtime.identity !== 'string' ||
80
+ !/^\d+:\d+:\d+$/.test(runtime.identity) ||
81
+ (runtime.retiring !== undefined && (runtime.retiring !== true || !allowRetiring)))
82
+ reject();
83
+ await privateDirectory(container, false);
84
+ try {
85
+ if ((await runtimeIdentity(runtime.directory)) !== runtime.identity)
86
+ reject();
87
+ }
88
+ catch (error) {
89
+ // This flag belongs only to attribution/cleanup. Actual retirement still
90
+ // requires the authoritative roster, released leases and both owner fences.
91
+ if (allowRetiring && error.code === 'ENOENT')
92
+ return false;
93
+ throw error;
94
+ }
95
+ let actual;
96
+ try {
97
+ actual = await readMarker(join(runtime.directory, runtimeMarkerName));
98
+ }
99
+ catch (error) {
100
+ if (allowRetiring && runtime.retiring && error.code === 'ENOENT')
101
+ return true; // Cleanup may only rmdir this identity, never recursively delete it.
102
+ throw error;
103
+ }
104
+ if (JSON.stringify(actual) !== JSON.stringify(runtimeRecord(owner, runtime)))
105
+ reject();
106
+ return true;
107
+ }
108
+ /** A missing workspace does not authorize abandoning an external payload root. */
109
+ export async function hasRuntimeOwner(owner) {
110
+ const container = await runtimeContainer();
111
+ try {
112
+ await privateDirectory(container, false);
113
+ }
114
+ catch (error) {
115
+ if (error.code === 'ENOENT')
116
+ return false;
117
+ throw error;
118
+ }
119
+ const names = await readdir(container);
120
+ if (names.length > 10000)
121
+ reject();
122
+ for (const name of names) {
123
+ if (!/^[0-9a-f]{20}$/.test(name))
124
+ continue;
125
+ try {
126
+ await privateDirectory(join(container, name), false);
127
+ const record = (await readMarker(join(container, name, runtimeMarkerName)));
128
+ if (record.workspacePath === owner.workspacePath &&
129
+ (owner.ownerId === undefined || record.ownerId === owner.ownerId))
130
+ return true;
131
+ }
132
+ catch {
133
+ // Unattributable allocations stay untouched. They cannot establish
134
+ // ownership by this workspace or prevent unrelated sessions retiring.
135
+ continue;
136
+ }
137
+ }
138
+ return false;
139
+ }
140
+ /** Complete encoded endpoint, including its terminating NUL, must fit sun_path. */
141
+ export function requireSocketPath(path, capacity = { linux: 108, darwin: 104 }[process.platform]) {
142
+ if (!capacity)
143
+ throw new Error('UNIX_SOCKET_PLATFORM_UNSUPPORTED: no verified pathname capacity for this platform');
144
+ if (path.includes('\0') || Buffer.byteLength(path) + 1 > capacity)
145
+ throw new Error('UNIX_SOCKET_PATH_TOO_LONG: shorten the endpoint name or temporary root');
146
+ return path;
147
+ }
@@ -0,0 +1,67 @@
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, rmdir } from 'node:fs/promises';
8
+ import { dirname, join, parse, sep } from 'node:path';
9
+ import { canonicalScratchWorkspace } from './managed-scratch-owner.js';
10
+ import { privateDirectory } from './scratch-filesystem.js';
11
+ export const workspacePublicationName = '.gestalt-scratch-lock';
12
+ export async function assertParentPublications(workspace, logicalParents = []) {
13
+ const parents = new Set(logicalParents);
14
+ let current = parse(workspace).root;
15
+ for (const part of workspace.slice(current.length).split(sep).filter(Boolean)) {
16
+ current = join(current, part);
17
+ if (part === 'tmp')
18
+ parents.add(dirname(current));
19
+ }
20
+ parents.delete(workspace);
21
+ for (const parent of parents) {
22
+ try {
23
+ await lstat(join(parent, workspacePublicationName));
24
+ }
25
+ catch (error) {
26
+ if (error.code === 'ENOENT')
27
+ continue;
28
+ throw error;
29
+ }
30
+ throw new Error('SESSION_SCRATCH_BUSY');
31
+ }
32
+ }
33
+ /** Shared with Launcher/Agents. No timeout, timestamp or PID grants ownership. */
34
+ export async function claimWorkspacePublication(workspace) {
35
+ await canonicalScratchWorkspace(workspace);
36
+ const path = join(workspace, workspacePublicationName);
37
+ try {
38
+ await mkdir(path, { mode: 0o700 });
39
+ }
40
+ catch (error) {
41
+ if (error.code === 'EEXIST')
42
+ throw new Error('SESSION_SCRATCH_BUSY');
43
+ throw error;
44
+ }
45
+ await privateDirectory(path, false);
46
+ const handle = await open(path, constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
47
+ const held = await handle.stat({ bigint: true });
48
+ let released = false;
49
+ return async () => {
50
+ if (released)
51
+ return;
52
+ try {
53
+ const current = await lstat(path, { bigint: true });
54
+ if (!current.isDirectory() ||
55
+ current.isSymbolicLink() ||
56
+ current.dev !== held.dev ||
57
+ current.ino !== held.ino ||
58
+ current.birthtimeNs !== held.birthtimeNs)
59
+ throw new Error('SESSION_SCRATCH_FENCE_CHANGED');
60
+ await rmdir(path);
61
+ released = true;
62
+ }
63
+ finally {
64
+ await handle.close();
65
+ }
66
+ };
67
+ }
@@ -48,13 +48,8 @@ export const gestaltOrgPlanAttentionDynamicTool = {
48
48
  properties: { canonicalTaskName: { type: 'string', pattern: '^l[1-9][0-9]*$' } },
49
49
  },
50
50
  },
51
- oneOf: orgPlanAttentionReasons.map((reason) => ({
52
- properties: {
53
- reason: { const: reason },
54
- resumeCondition: { const: orgPlanAttentionResumeConditionByReason[reason] },
55
- },
56
- required: ['reason', 'resumeCondition'],
57
- })),
51
+ // Union rendering can drop sibling properties from the model-visible tool
52
+ // declaration. Keep it flat; parseOrgPlanAttention validates reason pairs.
58
53
  },
59
54
  };
60
55
  export function parseOrgPlanAttention(value) {
@@ -0,0 +1,37 @@
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
+ export const gestaltOrgPlanReplaceExecutorDynamicTool = {
7
+ type: 'function',
8
+ name: 'gestalt_org_plan_replace_executor',
9
+ description: 'Authorize one physical executor replacement in this supervisor session only when the user explicitly asked for that replacement. That instruction supplies permission; do not request it again. Pass the canonical task name (for example l3), never a generation. Mobile verifies the current plan and stopped writer, persists the replacement and returns its exact identity. Retries return the same pending identity. Resume that task if already present in this root; otherwise spawn it once. Refusal preserves the existing writer. Never use for routine continuation, a new-supervisor takeover, or to bypass attention, Manual Off, or review/model-policy gates.',
10
+ inputSchema: {
11
+ type: 'object',
12
+ additionalProperties: false,
13
+ required: ['version', 'reason', 'canonicalTaskName'],
14
+ properties: {
15
+ version: { const: 1 },
16
+ reason: { const: 'userDirectedReplacement' },
17
+ canonicalTaskName: { type: 'string', pattern: '^l[1-9][0-9]*$' },
18
+ },
19
+ },
20
+ };
21
+ export function parseOrgPlanReplaceExecutorCall(input) {
22
+ if (input.method !== 'item/tool/call' || !record(input.params))
23
+ return null;
24
+ const args = input.params.arguments;
25
+ if (input.params.tool !== gestaltOrgPlanReplaceExecutorDynamicTool.name ||
26
+ !record(args) ||
27
+ Object.keys(args).length !== 3 ||
28
+ args.version !== 1 ||
29
+ args.reason !== 'userDirectedReplacement' ||
30
+ typeof args.canonicalTaskName !== 'string' ||
31
+ !/^l[1-9][0-9]*$/.test(args.canonicalTaskName))
32
+ return null;
33
+ return { canonicalTaskName: args.canonicalTaskName };
34
+ }
35
+ function record(value) {
36
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
37
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gestalt-mobile",
3
- "version": "0.72.0",
3
+ "version": "0.72.2",
4
4
  "description": "Mobile-first web relay for durable Codex development sessions",
5
5
  "keywords": [
6
6
  "codex",