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.
Files changed (25) hide show
  1. package/README.md +52 -5
  2. package/dist/client/assets/{index-Cp-JfcNd.css → index-CRnoGk06.css} +1 -1
  3. package/dist/client/assets/{index-DeNYHfGR.js → index-DehRk2EQ.js} +7 -3
  4. package/dist/client/index.html +2 -2
  5. package/dist/server/server/composition.contracts.js +106 -1
  6. package/dist/server/server/composition.js +126 -8
  7. package/dist/server/server/features/autopilot/application/service.js +7 -6
  8. package/dist/server/server/features/control-plane-trace/export-trace.js +2 -2
  9. package/dist/server/server/features/plans/application/parse-supervised-plan.js +5 -0
  10. package/dist/server/server/features/plans/application/supervised-plan-registry.js +11 -2
  11. package/dist/server/server/features/sessions/application/provider-recovery.js +109 -0
  12. package/dist/server/server/features/sessions/model/relay-session.js +17 -2
  13. package/dist/server/server/features/sessions/start-session/use-case.js +1 -0
  14. package/dist/server/server/features/skills/list-available/endpoint.js +1 -0
  15. package/dist/server/server/features/skills/list-profiles/endpoint.js +1 -0
  16. package/dist/server/server/features/skills/model/skill-profile.js +20 -7
  17. package/dist/server/server/features/skills/replace-profile/endpoint.js +6 -1
  18. package/dist/server/server/platform/codex/codex-playwright.js +399 -0
  19. package/dist/server/server/platform/codex/managed-playwright.js +150 -0
  20. package/dist/server/server/platform/codex/session-runtime.js +37 -2
  21. package/dist/server/server/platform/skills/codex-skill-catalog.js +1 -1
  22. package/dist/server/shared/contracts/managed-playwright.js +34 -0
  23. package/dist/server/shared/contracts/profile-capabilities.js +13 -0
  24. package/dist/server/shared/contracts/provider-failure.js +7 -0
  25. package/package.json +1 -1
@@ -4,6 +4,7 @@
4
4
  * SPDX-License-Identifier: AGPL-3.0-or-later
5
5
  */
6
6
  import { DomainError } from './errors.js';
7
+ import { profileCapabilitiesSchema, } from '../../../../shared/contracts/profile-capabilities.js';
7
8
  import { createSkillSelection, normalizeSkillProfileName, } from '../../skills/model/skill-profile.js';
8
9
  import { interactionId, profileName, sessionId, threadId, turnId, workspaceId, workspacePath, } from './value-objects.js';
9
10
  /** A durable thread can be read even when this relay has no live writer. */
@@ -37,6 +38,9 @@ export function createSessionExecutionPolicy(input) {
37
38
  export function createEffectiveSkillSelection(input) {
38
39
  const warnings = (input.warnings ?? []).filter((warning) => typeof warning === 'string' && warning.length > 0);
39
40
  return {
41
+ ...(input.capabilities === undefined
42
+ ? {}
43
+ : { capabilities: profileCapabilitiesSchema.parse(input.capabilities) }),
40
44
  ...(input.selectedProfileName === undefined
41
45
  ? {}
42
46
  : { selectedProfileName: normalizeSkillProfileName(input.selectedProfileName) }),
@@ -62,7 +66,12 @@ export class RelaySession {
62
66
  ...(input.model === undefined ? {} : { model: input.model }),
63
67
  ...(input.modelSettings === undefined ? {} : { modelSettings: { ...input.modelSettings } }),
64
68
  ...(input.branch === undefined ? {} : { branch: input.branch }),
65
- effectiveSkillSelection: createEffectiveSkillSelection(input.effectiveSkillSelection),
69
+ effectiveSkillSelection: createEffectiveSkillSelection({
70
+ ...input.effectiveSkillSelection,
71
+ ...(input.provider === 'kimi' && input.effectiveSkillSelection.capabilities !== undefined
72
+ ? { capabilities: { playwright: { enabled: false } } }
73
+ : {}),
74
+ }),
66
75
  executionPolicy: createSessionExecutionPolicy(input),
67
76
  threadId: null,
68
77
  state: 'starting',
@@ -180,7 +189,13 @@ function copy(snapshot) {
180
189
  ...(snapshot.effectiveSkillSelection === undefined
181
190
  ? {}
182
191
  : {
183
- effectiveSkillSelection: createEffectiveSkillSelection(snapshot.effectiveSkillSelection),
192
+ effectiveSkillSelection: createEffectiveSkillSelection({
193
+ ...snapshot.effectiveSkillSelection,
194
+ ...(snapshot.provider === 'kimi' &&
195
+ snapshot.effectiveSkillSelection.capabilities !== undefined
196
+ ? { capabilities: { playwright: { enabled: false } } }
197
+ : {}),
198
+ }),
184
199
  }),
185
200
  pendingInteractions: snapshot.pendingInteractions.map((item) => ({ ...item })),
186
201
  };
@@ -45,6 +45,7 @@ export async function startSession(input, deps) {
45
45
  const sourceProfile = selectedProfile ?? projectProfile;
46
46
  const reconciledSkills = reconcileSkillSelectionSnapshot(catalog.skills, sourceProfile?.skills);
47
47
  effectiveSkillSelection = {
48
+ ...(sourceProfile?.capabilities ? { capabilities: sourceProfile.capabilities } : {}),
48
49
  ...(selectedProfile ? { selectedProfileName: selectedProfile.name } : {}),
49
50
  skills: [
50
51
  ...reconciledSkills.skills.map((skill) => ({
@@ -39,6 +39,7 @@ export function registerListAvailableSkills(app, deps) {
39
39
  const skills = applySkillSelectionSnapshot(discovered.skills, project?.skills);
40
40
  return {
41
41
  source: project ? 'project' : 'native',
42
+ ...(project?.capabilities ? { capabilities: project.capabilities } : {}),
42
43
  errors: discovered.errors.map(({ message }) => ({ message })),
43
44
  skills: skills
44
45
  .filter((skill) => !isAlwaysAdvertisedSkill(skill) && skill.name !== 'gestalt:xerj')
@@ -19,6 +19,7 @@ export function registerListSkillProfiles(app, deps) {
19
19
  version: profile.version,
20
20
  path: deps.profilePath(name),
21
21
  skills: profile.skills,
22
+ ...(profile.capabilities ? { capabilities: profile.capabilities } : {}),
22
23
  }
23
24
  : {
24
25
  name,
@@ -7,6 +7,7 @@ import { isAbsolute, normalize } from 'node:path';
7
7
  import { parseDocument, stringify } from 'yaml';
8
8
  import { z } from 'zod';
9
9
  import { SkillProfileError } from './errors.js';
10
+ import { profileCapabilitiesSchema, } from '../../../../shared/contracts/profile-capabilities.js';
10
11
  const profileNamePattern = /^[a-z0-9](?:[a-z0-9-]{0,62})?$/;
11
12
  /**
12
13
  * A path-keyed skill record. `name` is display metadata only: a skill's path is
@@ -61,18 +62,26 @@ export const availableSkillSchema = z
61
62
  */
62
63
  export function isAlwaysAdvertisedSkill(skill) {
63
64
  return (isGestaltSkillName(skill.name) &&
64
- (!['gestalt:xerj', 'gestalt:serena'].includes(skill.name) || skill.enabled));
65
+ (!['gestalt:xerj', 'gestalt:serena', 'gestalt:playwright'].includes(skill.name) ||
66
+ skill.enabled));
65
67
  }
66
68
  export function isGestaltSkillName(name) {
67
69
  return name.startsWith('gestalt:');
68
70
  }
69
- const profileDocumentSchema = z
71
+ const legacyProfileDocumentSchema = z
70
72
  .object({
71
73
  version: z.literal(1),
72
74
  name: z.string().min(1),
73
75
  skills: z.array(skillSelectionEntrySchema),
74
76
  })
75
77
  .strict();
78
+ const profileDocumentSchema = z.discriminatedUnion('version', [
79
+ legacyProfileDocumentSchema,
80
+ legacyProfileDocumentSchema.extend({
81
+ version: z.literal(2),
82
+ capabilities: profileCapabilitiesSchema,
83
+ }),
84
+ ]);
76
85
  /**
77
86
  * Normalize a profile name before using it in its global filename. The output
78
87
  * is deliberately narrow so a profile name can never become a path traversal.
@@ -164,7 +173,7 @@ export function applySkillSelectionSnapshot(discovered, selection) {
164
173
  const enabledByPath = new Map(createSkillSelection(selection).map((entry) => [entry.path, entry.enabled]));
165
174
  return catalog.map((skill) => ({
166
175
  ...skill,
167
- enabled: ['gestalt:xerj', 'gestalt:serena'].includes(skill.name)
176
+ enabled: ['gestalt:xerj', 'gestalt:serena', 'gestalt:playwright'].includes(skill.name)
168
177
  ? skill.enabled
169
178
  : isAlwaysAdvertisedSkill(skill)
170
179
  ? true
@@ -218,16 +227,20 @@ export function compileSkillOverride(input) {
218
227
  }
219
228
  /** Construct the single profile contract shared by global and project YAML files. */
220
229
  export function createSkillProfile(input) {
230
+ const capabilities = input.capabilities === undefined
231
+ ? undefined
232
+ : profileCapabilitiesSchema.parse(input.capabilities);
221
233
  return {
222
- version: 1,
234
+ version: capabilities === undefined ? 1 : 2,
223
235
  name: normalizeSkillProfileName(input.name),
236
+ ...(capabilities === undefined ? {} : { capabilities }),
224
237
  // Gestalt skills are mandatory thread infrastructure. Legacy profiles are
225
238
  // normalized on read so they cannot pin a stale plugin-cache version or
226
239
  // expose a meaningless enable/disable control in the editor.
227
240
  skills: createSkillSelection(input.skills.filter((skill) => !isGestaltSkillName(skill.name))),
228
241
  };
229
242
  }
230
- /** Parse the version-1 YAML document without performing filesystem access. */
243
+ /** Import strict versioned YAML without silently dropping unknown fields. */
231
244
  export function parseSkillProfileYaml(source) {
232
245
  const document = parseDocument(source, { prettyErrors: false, strict: true, uniqueKeys: true });
233
246
  if (document.errors.length > 0) {
@@ -239,8 +252,8 @@ export function parseSkillProfileYaml(source) {
239
252
  }
240
253
  return createSkillProfile(parsed.data);
241
254
  }
242
- /** Serialize the canonical version-1 YAML document in deterministic path order. */
255
+ /** Export deterministic YAML, retaining explicit capability choices. */
243
256
  export function serializeSkillProfileYaml(profile) {
244
257
  const canonical = createSkillProfile(profile);
245
- return stringify({ version: 1, name: canonical.name, skills: canonical.skills });
258
+ return stringify(canonical);
246
259
  }
@@ -7,13 +7,18 @@ import { z } from 'zod';
7
7
  import { createSkillProfile, normalizeSkillProfileName } from '../model/skill-profile.js';
8
8
  import { SkillProfileError } from '../model/errors.js';
9
9
  import { problem } from '../../../platform/http/problem.js';
10
- const requestSchema = z
10
+ import { profileCapabilitiesSchema } from '../../../../shared/contracts/profile-capabilities.js';
11
+ const legacyRequestSchema = z
11
12
  .object({
12
13
  version: z.literal(1),
13
14
  name: z.string(),
14
15
  skills: z.array(z.object({ name: z.string(), path: z.string(), enabled: z.boolean() }).strict()),
15
16
  })
16
17
  .strict();
18
+ const requestSchema = z.discriminatedUnion('version', [
19
+ legacyRequestSchema,
20
+ legacyRequestSchema.extend({ version: z.literal(2), capabilities: profileCapabilitiesSchema }),
21
+ ]);
17
22
  export function registerReplaceSkillProfile(app, deps) {
18
23
  app.put('/api/skill-profiles/:name', { bodyLimit: 64 * 1024 }, async (request, reply) => {
19
24
  const body = requestSchema.safeParse(request.body);
@@ -0,0 +1,399 @@
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 { readFile, realpath } from 'node:fs/promises';
7
+ import { isAbsolute } from 'node:path';
8
+ import { managedPlaywrightRequestSchema } from '../../../shared/contracts/managed-playwright.js';
9
+ import { profileCapabilitiesSchema } from '../../../shared/contracts/profile-capabilities.js';
10
+ import { beforeDeadline } from '../retrieval/codex-xerj.js';
11
+ import { ManagedPlaywright, playwrightServerName, playwrightTools, } from './managed-playwright.js';
12
+ /** One browser owner per relay root. This is a capability adapter, not a global MCP registry. */
13
+ export class CodexPlaywright {
14
+ installation;
15
+ bindings = new Map();
16
+ prepared = new WeakMap();
17
+ constructor(installation) {
18
+ this.installation = installation;
19
+ }
20
+ async binding(authority) {
21
+ const workspace = await realpath(authority.session.workspacePath);
22
+ const old = this.bindings.get(authority.session.id);
23
+ if (old &&
24
+ old.workspace === workspace &&
25
+ old.root === (authority.session.threadId ?? null) &&
26
+ old.plan === authority.planIdentity &&
27
+ old.milestone === authority.activePlanId)
28
+ return old;
29
+ const binding = {
30
+ workspace,
31
+ root: authority.session.threadId ?? null,
32
+ plan: authority.planIdentity,
33
+ milestone: authority.activePlanId,
34
+ rebind: old?.applied === true,
35
+ requested: false,
36
+ released: false,
37
+ applied: old?.applied ?? false,
38
+ connected: false,
39
+ packageStatus: 'unknown',
40
+ chromeStatus: 'unknown',
41
+ nodeStatus: 'unknown',
42
+ chromeVersion: null,
43
+ readinessObservedAt: null,
44
+ };
45
+ this.bindings.set(authority.session.id, binding);
46
+ return binding;
47
+ }
48
+ consent(authority) {
49
+ const snapshot = profileCapabilitiesSchema.safeParse(authority.session.effectiveSkillSelection?.capabilities);
50
+ return (authority.session.provider === 'codex' &&
51
+ snapshot.success &&
52
+ snapshot.data.playwright.enabled === true);
53
+ }
54
+ async control(authority, arguments_, rootOwned) {
55
+ const parsed = managedPlaywrightRequestSchema.safeParse(arguments_);
56
+ if (!rootOwned || !parsed.success)
57
+ return {
58
+ capability: 'playwright',
59
+ status: 'unavailable',
60
+ reason: 'root-supervisor-required-or-invalid-request',
61
+ };
62
+ if (parsed.data.planId !== undefined && parsed.data.planId !== authority.activePlanId)
63
+ return { capability: 'playwright', status: 'unavailable', reason: 'unknown-plan-id' };
64
+ const binding = await this.binding(authority);
65
+ if (parsed.data.action === 'stop') {
66
+ binding.requested = false;
67
+ binding.released = true;
68
+ binding.reason = undefined;
69
+ }
70
+ if (!this.consent(authority)) {
71
+ binding.requested = false;
72
+ if (binding.applied)
73
+ return {
74
+ capability: 'playwright',
75
+ status: 'pending',
76
+ boundary: 'owned-runtime-resume',
77
+ reason: 'profile-disabled',
78
+ };
79
+ return { capability: 'playwright', status: 'off' };
80
+ }
81
+ if (parsed.data.action === 'start') {
82
+ if (authority.fenced)
83
+ return {
84
+ capability: 'playwright',
85
+ status: 'unavailable',
86
+ reason: 'manual-off-or-attention',
87
+ };
88
+ if (binding.reason)
89
+ binding.applied = false;
90
+ binding.requested = true;
91
+ binding.released = false;
92
+ binding.reason = undefined;
93
+ }
94
+ return this.status(binding, this.desired(authority, binding));
95
+ }
96
+ desired(authority, binding) {
97
+ return (this.consent(authority) &&
98
+ !authority.fenced &&
99
+ !binding.released &&
100
+ (binding.requested || authority.declared));
101
+ }
102
+ status(binding, desired) {
103
+ const pending = binding.rebind || desired !== binding.applied;
104
+ return {
105
+ capability: 'playwright',
106
+ status: pending
107
+ ? 'pending'
108
+ : binding.connected
109
+ ? 'connected'
110
+ : binding.reason
111
+ ? 'unavailable'
112
+ : 'idle',
113
+ ...(pending ? { boundary: 'owned-runtime-resume' } : {}),
114
+ ...(binding.reason ? { reason: binding.reason } : {}),
115
+ ...(binding.version ? { packageVersion: binding.version } : {}),
116
+ packageStatus: binding.packageStatus,
117
+ chrome: { status: binding.chromeStatus, version: binding.chromeVersion },
118
+ nodeStatus: binding.nodeStatus,
119
+ readinessObservedAt: binding.readinessObservedAt,
120
+ };
121
+ }
122
+ needsResume(authority) {
123
+ const existing = this.bindings.get(authority.session.id);
124
+ const desired = this.consent(authority) &&
125
+ !authority.fenced &&
126
+ !existing?.released &&
127
+ (existing?.requested || authority.declared);
128
+ // Browser-off chat must not acquire a filesystem/readiness dependency or
129
+ // an extra asynchronous boundary on every Autopilot root continuation.
130
+ if (!desired && !existing?.applied && !existing?.rebind)
131
+ return false;
132
+ if (existing &&
133
+ !existing.rebind &&
134
+ existing.workspace === authority.session.workspacePath &&
135
+ existing.root === authority.session.threadId &&
136
+ existing.plan === authority.planIdentity &&
137
+ existing.milestone === authority.activePlanId &&
138
+ desired === existing.applied)
139
+ return false;
140
+ return this.binding(authority).then((binding) => binding.rebind || this.desired(authority, binding) !== binding.applied);
141
+ }
142
+ /** Called only at thread start/resume. Native app-server owns the managed stdio child. */
143
+ async prepare(base, authority, input) {
144
+ const binding = await this.binding(authority);
145
+ const current = () => {
146
+ const now = input.current?.() ?? authority;
147
+ return (this.bindings.get(authority.session.id) === binding &&
148
+ now.session.id === authority.session.id &&
149
+ now.session.workspacePath === authority.session.workspacePath &&
150
+ ((now.session.threadId ?? null) === (authority.session.threadId ?? null) ||
151
+ now.session.threadId === binding.root) &&
152
+ now.planIdentity === authority.planIdentity &&
153
+ now.activePlanId === authority.activePlanId &&
154
+ this.consent(now) === this.consent(authority) &&
155
+ now.fenced === authority.fenced);
156
+ };
157
+ const skill = input.skills.find((entry) => entry.name === 'gestalt:playwright');
158
+ let native = {};
159
+ let compatible = false;
160
+ try {
161
+ const response = (await beforeDeadline(input.rpc.request('config/read', { includeLayers: false }), input.deadline));
162
+ native = response.config ?? {};
163
+ compatible = !!response.config;
164
+ }
165
+ catch {
166
+ /* Optional capability stays unavailable. */
167
+ }
168
+ const servers = omitUnset(native.mcp_servers ?? {});
169
+ const reserved = servers[playwrightServerName] ?? {};
170
+ const mcp = {};
171
+ for (const [name, server] of Object.entries(servers)) {
172
+ if (Array.isArray(server?.args) &&
173
+ server.args[0] === 'playwright' &&
174
+ server.args[1] === 'mcp')
175
+ mcp[name] = { ...server, enabled: false, required: false };
176
+ }
177
+ const rules = native.skills;
178
+ let enabled = false, guidance = '', manager = 'gestalt';
179
+ const options = [];
180
+ binding.connected = false;
181
+ binding.reason = undefined;
182
+ if (this.desired(authority, binding)) {
183
+ binding.reason = 'installation-or-runtime-unavailable';
184
+ binding.packageStatus = 'unknown';
185
+ binding.chromeStatus = 'unknown';
186
+ binding.nodeStatus = 'unknown';
187
+ binding.chromeVersion = null;
188
+ binding.readinessObservedAt = null;
189
+ try {
190
+ const install = await beforeDeadline(this.installation.check(), input.deadline);
191
+ binding.packageStatus = install.status;
192
+ binding.readinessObservedAt = new Date().toISOString();
193
+ if (install.status === 'installed') {
194
+ manager = install.manager;
195
+ binding.version = install.version;
196
+ let validArgs = true;
197
+ if (reserved.args !== undefined) {
198
+ const args = reserved.args;
199
+ validArgs = Array.isArray(args) && args[0] === 'playwright' && args[1] === 'mcp';
200
+ if (validArgs)
201
+ for (let i = 2; i < args.length; i += 2) {
202
+ const option = args[i], value = args[i + 1];
203
+ if (typeof value !== 'string' || /[\x00-\x1f\x7f]/.test(value)) {
204
+ validArgs = false;
205
+ break;
206
+ }
207
+ if (option === '--cwd' && (await realpath(value)) === binding.workspace)
208
+ continue;
209
+ if (option !== '--executable-path' || !isAbsolute(value) || options.length) {
210
+ validArgs = false;
211
+ break;
212
+ }
213
+ options.push(option, value);
214
+ }
215
+ }
216
+ const conflict = reserved.enabled === false ||
217
+ reserved.url !== undefined ||
218
+ (reserved.command !== undefined && reserved.command !== manager) ||
219
+ reserved.env !== undefined ||
220
+ (Array.isArray(reserved.env_vars) && reserved.env_vars.length > 0);
221
+ if (compatible &&
222
+ skill &&
223
+ rules?.include_instructions !== false &&
224
+ rules?.config
225
+ ?.filter((rule) => rule.name === skill.name || rule.path === skill.path)
226
+ .at(-1)?.enabled !== false &&
227
+ !conflict &&
228
+ validArgs) {
229
+ guidance = await beforeDeadline(readFile(skill.path, 'utf8'), input.deadline);
230
+ if (guidance.length <= 16_384) {
231
+ const readiness = await beforeDeadline(this.installation.ready(manager, binding.workspace, input.deadline, options), input.deadline);
232
+ enabled = readiness.ready;
233
+ binding.packageStatus =
234
+ readiness.package === 'unknown' ? 'installed' : readiness.package;
235
+ binding.chromeStatus = readiness.chrome;
236
+ binding.chromeVersion = readiness.chromeVersion;
237
+ binding.nodeStatus = readiness.node;
238
+ binding.readinessObservedAt = new Date().toISOString();
239
+ }
240
+ }
241
+ }
242
+ }
243
+ catch {
244
+ /* No installer, config repair or shell fallback. */
245
+ }
246
+ if (enabled)
247
+ binding.reason = undefined;
248
+ }
249
+ if (!current()) {
250
+ enabled = false;
251
+ binding.reason = 'authority-changed';
252
+ }
253
+ binding.applied = this.desired(authority, binding);
254
+ binding.rebind = false;
255
+ const disabled = {
256
+ command: manager,
257
+ args: ['playwright', 'mcp', '--cwd', binding.workspace, ...options],
258
+ cwd: binding.workspace,
259
+ enabled: false,
260
+ required: false,
261
+ };
262
+ let available = enabled;
263
+ const state = {
264
+ get ready() {
265
+ return base.ready || available;
266
+ },
267
+ deadline: Math.max(base.deadline, input.deadline),
268
+ repositories: base.repositories,
269
+ get capabilities() {
270
+ return [
271
+ ...(base.capabilities ?? []),
272
+ {
273
+ skillName: 'gestalt:playwright',
274
+ serverName: playwrightServerName,
275
+ ready: binding.connected && current(),
276
+ diagnostic: binding.reason,
277
+ },
278
+ ];
279
+ },
280
+ get skillsConfig() {
281
+ return base.skillsConfig.map((entry) => entry.path === skill?.path ? { ...entry, enabled: false } : entry);
282
+ },
283
+ get config() {
284
+ return {
285
+ ...base.config,
286
+ mcp_servers: {
287
+ ...base.config.mcp_servers,
288
+ ...mcp,
289
+ [playwrightServerName]: available
290
+ ? {
291
+ ...reserved,
292
+ ...disabled,
293
+ enabled: true,
294
+ env_vars: ['GESTALT_HOME'],
295
+ startup_readiness: 'connection',
296
+ startup_timeout_ms: Math.max(1, input.deadline - Date.now()),
297
+ }
298
+ : disabled,
299
+ },
300
+ skills: {
301
+ config: [
302
+ ...(base.config.skills?.config ?? []),
303
+ { name: 'gestalt:playwright', enabled: false },
304
+ ],
305
+ },
306
+ developer_instructions: `${base.config.developer_instructions ?? ''}\n<gestalt_playwright_unavailable>Browser guidance is inactive until this host verifies connected standard tools. Use gestalt_managed_playwright for session-scoped requests. Installation or a plan declaration never grants consent. Pending activation requires a safe owned-runtime resume.</gestalt_playwright_unavailable>`,
307
+ };
308
+ },
309
+ // Each verifier already disables only its failed connection. A shared
310
+ // fallback must not disable a healthy browser after an XERJ/Serena failure.
311
+ fallback() { },
312
+ get turnInstructions() {
313
+ return binding.connected && current()
314
+ ? `<gestalt_playwright_capability>Verified managed browser tools are connected. Host MCP approvals apply; shell sandbox roots do not confine this browser.\n${guidance}\n</gestalt_playwright_capability>`
315
+ : '';
316
+ },
317
+ };
318
+ this.prepared.set(state, {
319
+ binding,
320
+ base,
321
+ enabled,
322
+ deadline: input.deadline,
323
+ current,
324
+ fail() {
325
+ available = false;
326
+ binding.connected = false;
327
+ },
328
+ });
329
+ return state;
330
+ }
331
+ async verify(rpc, threadId, state) {
332
+ const prepared = this.prepared.get(state);
333
+ if (!prepared?.enabled)
334
+ return true;
335
+ try {
336
+ while (Date.now() < prepared.deadline) {
337
+ const result = (await beforeDeadline(rpc.request('mcpServerStatus/list', {
338
+ threadId,
339
+ serverName: playwrightServerName,
340
+ detail: 'full',
341
+ }), prepared.deadline));
342
+ const server = result.data?.find((entry) => entry.name === playwrightServerName);
343
+ if (prepared.current() &&
344
+ server?.runtimeStatus === 'connected' &&
345
+ !server.toolsError &&
346
+ playwrightTools.every((tool) => Object.hasOwn(server.tools ?? {}, tool))) {
347
+ prepared.binding.connected = true;
348
+ prepared.binding.root = threadId;
349
+ return true;
350
+ }
351
+ if (server?.runtimeStatus !== 'starting')
352
+ break;
353
+ await beforeDeadline(new Promise((resolve) => setTimeout(resolve, 25)), prepared.deadline);
354
+ }
355
+ }
356
+ catch {
357
+ /* Keep chat, XERJ and Serena usable. */
358
+ }
359
+ prepared.binding.reason = 'connection-or-tools-unavailable';
360
+ prepared.fail();
361
+ return false;
362
+ }
363
+ release(sessionId) {
364
+ this.bindings.delete(sessionId);
365
+ }
366
+ /** The runtime binds even an unavailable fresh capability to its actual root.
367
+ * Otherwise a failed fresh declaration looks like a fork at the first turn
368
+ * and requests a resume before Codex has created a durable rollout. */
369
+ bound(state, threadId) {
370
+ const prepared = this.prepared.get(state);
371
+ if (prepared)
372
+ prepared.binding.root = threadId;
373
+ }
374
+ observe(sessionId, notification) {
375
+ if (!['mcpServer/statusUpdated', 'mcpServer/startupStatus/updated'].includes(notification.method))
376
+ return;
377
+ const value = notification.params;
378
+ const binding = this.bindings.get(sessionId);
379
+ if (!binding ||
380
+ value?.name !== playwrightServerName ||
381
+ (value.threadId && value.threadId !== binding.root) ||
382
+ !['failed', 'cancelled', 'disconnected'].includes(String(value.status)))
383
+ return;
384
+ binding.connected = false;
385
+ binding.reason = 'connection-or-tools-unavailable';
386
+ }
387
+ base(state) {
388
+ return this.prepared.get(state)?.base ?? state;
389
+ }
390
+ }
391
+ function omitUnset(value) {
392
+ if (Array.isArray(value))
393
+ return value.map(omitUnset);
394
+ if (value !== null && typeof value === 'object')
395
+ return Object.fromEntries(Object.entries(value)
396
+ .filter(([, entry]) => entry !== null && entry !== undefined)
397
+ .map(([key, entry]) => [key, omitUnset(entry)]));
398
+ return value;
399
+ }