gestalt-mobile 0.61.1 → 0.62.1
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.
- package/README.md +52 -5
- package/dist/client/assets/{index-Cp-JfcNd.css → index-CRnoGk06.css} +1 -1
- package/dist/client/assets/{index-DeNYHfGR.js → index-DehRk2EQ.js} +7 -3
- package/dist/client/index.html +2 -2
- package/dist/server/server/composition.contracts.js +106 -1
- package/dist/server/server/composition.js +126 -8
- package/dist/server/server/features/autopilot/application/service.js +7 -6
- package/dist/server/server/features/control-plane-trace/export-trace.js +2 -2
- package/dist/server/server/features/plans/application/parse-supervised-plan.js +5 -0
- package/dist/server/server/features/plans/application/supervised-plan-registry.js +11 -2
- package/dist/server/server/features/sessions/application/provider-recovery.js +109 -0
- package/dist/server/server/features/sessions/model/relay-session.js +17 -2
- package/dist/server/server/features/sessions/start-session/use-case.js +1 -0
- package/dist/server/server/features/skills/list-available/endpoint.js +1 -0
- package/dist/server/server/features/skills/list-profiles/endpoint.js +1 -0
- package/dist/server/server/features/skills/model/skill-profile.js +20 -7
- package/dist/server/server/features/skills/replace-profile/endpoint.js +6 -1
- package/dist/server/server/platform/codex/codex-playwright.js +399 -0
- package/dist/server/server/platform/codex/managed-playwright.js +150 -0
- package/dist/server/server/platform/codex/session-runtime.js +37 -2
- package/dist/server/server/platform/skills/codex-skill-catalog.js +1 -1
- package/dist/server/shared/contracts/managed-playwright.js +34 -0
- package/dist/server/shared/contracts/profile-capabilities.js +13 -0
- package/dist/server/shared/contracts/provider-failure.js +7 -0
- package/package.json +1 -1
|
@@ -0,0 +1,150 @@
|
|
|
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 { access, readFile, realpath, stat } from 'node:fs/promises';
|
|
8
|
+
import { homedir } from 'node:os';
|
|
9
|
+
import { basename, dirname, isAbsolute, join } from 'node:path';
|
|
10
|
+
import { spawn } from 'node:child_process';
|
|
11
|
+
export const playwrightServerName = 'gestalt-playwright';
|
|
12
|
+
export const playwrightTools = [
|
|
13
|
+
'browser_navigate',
|
|
14
|
+
'browser_snapshot',
|
|
15
|
+
'browser_fill_form',
|
|
16
|
+
'browser_take_screenshot',
|
|
17
|
+
'browser_close',
|
|
18
|
+
];
|
|
19
|
+
const unknownReadiness = () => ({
|
|
20
|
+
ready: false,
|
|
21
|
+
package: 'unknown',
|
|
22
|
+
chrome: 'unknown',
|
|
23
|
+
node: 'unknown',
|
|
24
|
+
chromeVersion: null,
|
|
25
|
+
});
|
|
26
|
+
/** Bounded reads only. Installation and Chrome ownership remain with the operator. */
|
|
27
|
+
export class ManagedPlaywright {
|
|
28
|
+
environment;
|
|
29
|
+
constructor(environment = process.env) {
|
|
30
|
+
this.environment = environment;
|
|
31
|
+
}
|
|
32
|
+
async check() {
|
|
33
|
+
const home = this.environment.GESTALT_HOME ?? join(this.environment.HOME ?? homedir(), '.gestalt');
|
|
34
|
+
try {
|
|
35
|
+
const root = await realpath(join(home, 'playwright'));
|
|
36
|
+
const path = join(root, 'active.json');
|
|
37
|
+
if ((await stat(path)).size > 262_144)
|
|
38
|
+
return { status: 'unavailable' };
|
|
39
|
+
const install = JSON.parse(await readFile(path, 'utf8'));
|
|
40
|
+
if (install.schemaVersion !== 1 ||
|
|
41
|
+
install.contractVersion !== 1 ||
|
|
42
|
+
typeof install.version !== 'string' ||
|
|
43
|
+
install.version.length > 32 ||
|
|
44
|
+
!/^\d+\.\d+\.\d+$/.test(install.version) ||
|
|
45
|
+
typeof install.release !== 'string' ||
|
|
46
|
+
!isAbsolute(install.release))
|
|
47
|
+
return { status: 'unavailable' };
|
|
48
|
+
const release = await realpath(install.release);
|
|
49
|
+
if (dirname(release) !== root || !basename(release).startsWith(`release-${install.version}-`))
|
|
50
|
+
return { status: 'unavailable' };
|
|
51
|
+
const candidates = this.environment.GESTALT_MANAGER_BIN
|
|
52
|
+
? [this.environment.GESTALT_MANAGER_BIN]
|
|
53
|
+
: (this.environment.PATH ?? '')
|
|
54
|
+
.split(':')
|
|
55
|
+
.filter(Boolean)
|
|
56
|
+
.map((path) => join(path, 'gestalt'));
|
|
57
|
+
for (const manager of candidates) {
|
|
58
|
+
if (!isAbsolute(manager))
|
|
59
|
+
continue;
|
|
60
|
+
try {
|
|
61
|
+
await access(manager, constants.X_OK);
|
|
62
|
+
return { status: 'installed', manager, version: install.version };
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
/* Try the next operator-owned executable. */
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return { status: 'unavailable' };
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
return {
|
|
72
|
+
status: error.code === 'ENOENT' ? 'absent' : 'unavailable',
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** Doctor performs no repair, installation or browser launch. Output never escapes this adapter. */
|
|
77
|
+
async ready(manager, cwd, deadline, options = []) {
|
|
78
|
+
if (Date.now() >= deadline)
|
|
79
|
+
return unknownReadiness();
|
|
80
|
+
const env = Object.fromEntries(['PATH', 'HOME', 'TMPDIR', 'GESTALT_HOME']
|
|
81
|
+
.filter((key) => this.environment[key] !== undefined)
|
|
82
|
+
.map((key) => [key, this.environment[key]]));
|
|
83
|
+
return new Promise((resolve) => {
|
|
84
|
+
const child = spawn(manager, ['playwright', 'doctor', '--json', '--cwd', cwd, ...options], {
|
|
85
|
+
cwd,
|
|
86
|
+
env,
|
|
87
|
+
shell: false,
|
|
88
|
+
detached: true,
|
|
89
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
90
|
+
});
|
|
91
|
+
let output = '', overflow = false;
|
|
92
|
+
const kill = () => {
|
|
93
|
+
if (child.pid)
|
|
94
|
+
try {
|
|
95
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
/* Only this owned group. */
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const timer = setTimeout(kill, Math.max(1, deadline - Date.now()));
|
|
102
|
+
child.stdout.on('data', (data) => {
|
|
103
|
+
if (output.length + data.length > 32768) {
|
|
104
|
+
overflow = true;
|
|
105
|
+
kill();
|
|
106
|
+
}
|
|
107
|
+
else
|
|
108
|
+
output += data;
|
|
109
|
+
});
|
|
110
|
+
child.once('error', () => {
|
|
111
|
+
clearTimeout(timer);
|
|
112
|
+
resolve(unknownReadiness());
|
|
113
|
+
});
|
|
114
|
+
child.once('close', (code) => {
|
|
115
|
+
clearTimeout(timer);
|
|
116
|
+
kill();
|
|
117
|
+
try {
|
|
118
|
+
const value = JSON.parse(output);
|
|
119
|
+
if (overflow || value.schemaVersion !== 1 || value.contractVersion !== 1) {
|
|
120
|
+
resolve(unknownReadiness());
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const status = (ready) => ready === true
|
|
124
|
+
? 'ready'
|
|
125
|
+
: ready === false
|
|
126
|
+
? 'unavailable'
|
|
127
|
+
: 'unknown';
|
|
128
|
+
resolve({
|
|
129
|
+
ready: code === 0 &&
|
|
130
|
+
value.ready === true &&
|
|
131
|
+
value.package?.ready === true &&
|
|
132
|
+
value.chrome?.ready === true &&
|
|
133
|
+
value.node?.ready === true,
|
|
134
|
+
package: status(value.package?.ready),
|
|
135
|
+
chrome: status(value.chrome?.ready),
|
|
136
|
+
node: status(value.node?.ready),
|
|
137
|
+
chromeVersion: typeof value.chrome?.version === 'string' &&
|
|
138
|
+
value.chrome.version.length <= 64 &&
|
|
139
|
+
/^\d+(?:\.\d+){1,3}$/.test(value.chrome.version)
|
|
140
|
+
? value.chrome.version
|
|
141
|
+
: null,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
resolve(unknownReadiness());
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -17,6 +17,7 @@ import { gestaltOrgPlanHealthDynamicTool } from '../../../shared/contracts/org-p
|
|
|
17
17
|
import { gestaltTestRunnerDynamicTool } from '../../../shared/contracts/host-tests.js';
|
|
18
18
|
import { gestaltAutopilotWaitLeaseDynamicTool } from '../../../shared/contracts/autopilot-wait-lease.js';
|
|
19
19
|
import { gestaltAgentCapacityRecoveryDynamicTool } from '../../../shared/contracts/agent-capacity-recovery.js';
|
|
20
|
+
import { gestaltManagedPlaywrightDynamicTool } from '../../../shared/contracts/managed-playwright.js';
|
|
20
21
|
import { countDiffLines } from '../../../shared/contracts/file-change.js';
|
|
21
22
|
import { threadPlanName } from './thread-plan-name.js';
|
|
22
23
|
import { WriterAcquisitionError, } from '../../features/sessions/application/writer-acquisition.js';
|
|
@@ -193,6 +194,8 @@ export class CodexSessionRuntime {
|
|
|
193
194
|
await this.prepareRetrieval(resource, session);
|
|
194
195
|
const startedThreadId = await this.startThread(resource.process, session, resource.skillsConfig, resource.modelConfig);
|
|
195
196
|
resource.threadId = startedThreadId;
|
|
197
|
+
if (resource.retrieval)
|
|
198
|
+
this.retrieval?.bound?.(resource.retrieval, startedThreadId);
|
|
196
199
|
await this.verifyRetrieval(resource, session, true);
|
|
197
200
|
this.sessions.set(session.id, resource);
|
|
198
201
|
await this.writePendingThreadName(session.id);
|
|
@@ -224,6 +227,7 @@ export class CodexSessionRuntime {
|
|
|
224
227
|
}
|
|
225
228
|
}
|
|
226
229
|
this.stop(sessionId);
|
|
230
|
+
this.retrieval?.release?.(sessionId);
|
|
227
231
|
}
|
|
228
232
|
/** Replaces only this session's app-server while retaining its durable root thread. */
|
|
229
233
|
async recycle(session, now) {
|
|
@@ -239,6 +243,8 @@ export class CodexSessionRuntime {
|
|
|
239
243
|
resource.beginExplicitShutdown();
|
|
240
244
|
for (const resource of resources)
|
|
241
245
|
resource.dispose();
|
|
246
|
+
for (const resource of resources)
|
|
247
|
+
this.retrieval?.release?.(resource.sessionId);
|
|
242
248
|
}
|
|
243
249
|
/** Keeps a detached session's supervised-plan status observable without launching Codex. */
|
|
244
250
|
async watchPlanStatus(session) {
|
|
@@ -284,13 +290,36 @@ export class CodexSessionRuntime {
|
|
|
284
290
|
const pending = resource.pendingRequests.get(requestId);
|
|
285
291
|
return pending && !pending.settling ? 'available' : 'cleared';
|
|
286
292
|
}
|
|
287
|
-
async startTurn(session, text, clientUserMessageId, now) {
|
|
293
|
+
async startTurn(session, text, clientUserMessageId, now, mayStart) {
|
|
294
|
+
const resumeRequested = this.retrieval?.needsResume?.(session);
|
|
295
|
+
if (resumeRequested === true || (resumeRequested && (await resumeRequested))) {
|
|
296
|
+
// The same root resumes only at an idle boundary. Never recycle a writer
|
|
297
|
+
// with outstanding child work or held host requests to attach a browser.
|
|
298
|
+
const current = this.sessions.get(session.id);
|
|
299
|
+
const topology = await this.readExecutorTopology(session);
|
|
300
|
+
if (current &&
|
|
301
|
+
!session.activeTurnId &&
|
|
302
|
+
current.pendingRequests.size === 0 &&
|
|
303
|
+
topology.kind === 'observed' &&
|
|
304
|
+
!topology.rootActive &&
|
|
305
|
+
topology.children.every((child) => child.qualified !== false &&
|
|
306
|
+
['idle', 'notLoaded', 'systemError'].includes(child.status ?? ''))) {
|
|
307
|
+
session = await this.recycle(session, now);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
288
310
|
const resource = this.sessions.get(session.id);
|
|
289
311
|
if (!resource || !session.threadId)
|
|
290
312
|
throw new Error('CODEX_SESSION_NOT_RUNNING');
|
|
313
|
+
if (mayStart && !mayStart())
|
|
314
|
+
throw new Error('CODEX_TURN_START_CANCELLED');
|
|
291
315
|
const result = decodeTurnStart(await resource.process.rpc.request('turn/start', {
|
|
292
316
|
threadId: session.threadId,
|
|
293
|
-
input: [
|
|
317
|
+
input: [
|
|
318
|
+
...(resource.retrieval?.turnInstructions
|
|
319
|
+
? [{ type: 'text', text: resource.retrieval.turnInstructions, text_elements: [] }]
|
|
320
|
+
: []),
|
|
321
|
+
{ type: 'text', text, text_elements: [] },
|
|
322
|
+
],
|
|
294
323
|
...(clientUserMessageId ? { clientUserMessageId } : {}),
|
|
295
324
|
...(session.model ? { model: session.model } : {}),
|
|
296
325
|
...(session.modelSettings?.reasoningEffort
|
|
@@ -986,6 +1015,7 @@ export class CodexSessionRuntime {
|
|
|
986
1015
|
gestaltTestRunnerDynamicTool,
|
|
987
1016
|
gestaltAutopilotWaitLeaseDynamicTool,
|
|
988
1017
|
gestaltAgentCapacityRecoveryDynamicTool,
|
|
1018
|
+
gestaltManagedPlaywrightDynamicTool,
|
|
989
1019
|
],
|
|
990
1020
|
});
|
|
991
1021
|
result = {
|
|
@@ -1002,6 +1032,8 @@ export class CodexSessionRuntime {
|
|
|
1002
1032
|
result = rebindMissingRollout(session, error, replacementThreadId, now);
|
|
1003
1033
|
}
|
|
1004
1034
|
resource.threadId = result.session.threadId;
|
|
1035
|
+
if (resource.retrieval)
|
|
1036
|
+
this.retrieval?.bound?.(resource.retrieval, resource.threadId);
|
|
1005
1037
|
await this.verifyRetrieval(resource, session, result.replacementCreated);
|
|
1006
1038
|
if (result.replacementCreated && resource.threadId !== result.session.threadId)
|
|
1007
1039
|
result = rebindMissingRollout(session, missingRollout, resource.threadId, now);
|
|
@@ -1090,6 +1122,7 @@ export class CodexSessionRuntime {
|
|
|
1090
1122
|
gestaltTestRunnerDynamicTool,
|
|
1091
1123
|
gestaltAutopilotWaitLeaseDynamicTool,
|
|
1092
1124
|
gestaltAgentCapacityRecoveryDynamicTool,
|
|
1125
|
+
gestaltManagedPlaywrightDynamicTool,
|
|
1093
1126
|
],
|
|
1094
1127
|
...(session.model ? { model: session.model } : {}),
|
|
1095
1128
|
...this.permissionParams(session),
|
|
@@ -1153,6 +1186,7 @@ export class CodexSessionRuntime {
|
|
|
1153
1186
|
const notificationUnsubscribe = process.rpc.onNotification((notification) => {
|
|
1154
1187
|
if (!resource.active)
|
|
1155
1188
|
return;
|
|
1189
|
+
this.retrieval?.observe?.(session.id, notification);
|
|
1156
1190
|
// Internal evidence may only be constructed by this resource's tracker.
|
|
1157
1191
|
if (notification.method === 'gestalt/mcpStartup')
|
|
1158
1192
|
return;
|
|
@@ -1367,6 +1401,7 @@ export class CodexSessionRuntime {
|
|
|
1367
1401
|
if (fresh) {
|
|
1368
1402
|
await resource.process.rpc.request('thread/unsubscribe', { threadId: resource.threadId });
|
|
1369
1403
|
resource.threadId = await this.startThread(resource.process, session, resource.skillsConfig, resource.modelConfig);
|
|
1404
|
+
this.retrieval.bound?.(state, resource.threadId);
|
|
1370
1405
|
return;
|
|
1371
1406
|
}
|
|
1372
1407
|
await resource.process.rpc.request('thread/resume', {
|
|
@@ -72,7 +72,7 @@ export class CodexSkillCatalog {
|
|
|
72
72
|
const stable = availableSkillSchema.safeParse(skill);
|
|
73
73
|
if (!stable.success)
|
|
74
74
|
throw new SkillProfileError('INVALID_SKILL_DISCOVERY', 'Invalid Codex skill metadata.');
|
|
75
|
-
return stable.data.name
|
|
75
|
+
return ['gestalt:xerj', 'gestalt:playwright'].includes(stable.data.name)
|
|
76
76
|
? { ...stable.data, enabled: false }
|
|
77
77
|
: stable.data;
|
|
78
78
|
});
|
|
@@ -0,0 +1,34 @@
|
|
|
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 { z } from 'zod';
|
|
7
|
+
export const managedPlaywrightRequestSchema = z
|
|
8
|
+
.object({
|
|
9
|
+
capability: z.literal('playwright'),
|
|
10
|
+
action: z.enum(['start', 'status', 'stop']),
|
|
11
|
+
planId: z.string().min(1).max(256).optional(),
|
|
12
|
+
})
|
|
13
|
+
.strict();
|
|
14
|
+
export const gestaltManagedPlaywrightDynamicTool = {
|
|
15
|
+
type: 'function',
|
|
16
|
+
name: 'gestalt_managed_playwright',
|
|
17
|
+
description: 'Request, inspect or release managed browser access for this root session. Profile consent is required. Start/stop may remain pending until a safe owned-runtime resume; tools and browser guidance are usable only after connected verification. Never starts a turn or clears Manual Off or attention. No commands, paths or environment accepted.',
|
|
18
|
+
inputSchema: {
|
|
19
|
+
type: 'object',
|
|
20
|
+
additionalProperties: false,
|
|
21
|
+
required: ['capability', 'action'],
|
|
22
|
+
properties: {
|
|
23
|
+
capability: { type: 'string', enum: ['playwright'] },
|
|
24
|
+
action: { type: 'string', enum: ['start', 'status', 'stop'] },
|
|
25
|
+
planId: { type: 'string', minLength: 1, maxLength: 256 },
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
export function isManagedPlaywrightCall(input) {
|
|
30
|
+
return (input.method === 'item/tool/call' &&
|
|
31
|
+
!!input.params &&
|
|
32
|
+
typeof input.params === 'object' &&
|
|
33
|
+
input.params.tool === gestaltManagedPlaywrightDynamicTool.name);
|
|
34
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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 { z } from 'zod';
|
|
7
|
+
/** Consent only. Runtime readiness and process ownership are separate concerns. */
|
|
8
|
+
export const profileCapabilitiesSchema = z
|
|
9
|
+
.object({ playwright: z.object({ enabled: z.boolean() }).strict() })
|
|
10
|
+
.strict();
|
|
11
|
+
export function disabledProfileCapabilities() {
|
|
12
|
+
return { playwright: { enabled: false } };
|
|
13
|
+
}
|
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
4
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
5
|
*/
|
|
6
|
+
export const providerRetryDelayMs = 60_000;
|
|
7
|
+
export const providerRetryLimit = 2;
|
|
8
|
+
export const providerContinuationPrompt = 'Continue.';
|
|
9
|
+
/** Capacity errors can clear quickly; account, context and policy limits require intervention. */
|
|
10
|
+
export function isTransientProviderFailure(failure) {
|
|
11
|
+
return failure.code === 'serverOverloaded' || failure.code === 'rateLimitExceeded';
|
|
12
|
+
}
|
|
6
13
|
const descriptions = {
|
|
7
14
|
contextWindowExceeded: 'The conversation exceeds the model context window. Compact it or start a new session.',
|
|
8
15
|
sessionBudgetExceeded: 'The Codex session budget is exhausted. Review its budget before continuing.',
|