viewable-one 0.12.8 → 0.12.10
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/CHANGELOG.md +97 -0
- package/README.md +8 -3
- package/SPAWN.md +26 -4
- package/glytch.mjs +5 -4
- package/lib/agents.mjs +195 -33
- package/lib/auth.mjs +245 -276
- package/lib/authenticatedHttp.mjs +2 -2
- package/lib/boardside.mjs +3 -1
- package/lib/child.mjs +33 -2
- package/lib/codex.mjs +85 -11
- package/lib/codexApps.mjs +84 -24
- package/lib/computerApps.mjs +85 -10
- package/lib/conversationRules.mjs +19 -3
- package/lib/detect.mjs +20 -5
- package/lib/doctor.mjs +18 -2
- package/lib/folderReads.mjs +15 -4
- package/lib/folderState.mjs +43 -0
- package/lib/init-connect.mjs +11 -3
- package/lib/lateResume.mjs +4 -1
- package/lib/mcpjson.mjs +99 -1
- package/lib/multiwatch.mjs +12 -4
- package/lib/otherLoginHook.mjs +31 -0
- package/lib/otherLogins.mjs +107 -3
- package/lib/permissionAsk.mjs +30 -5
- package/lib/project-mcp.mjs +7 -27
- package/lib/registry.mjs +46 -2
- package/lib/runnerBeat.mjs +15 -0
- package/lib/runnerCompletion.mjs +28 -22
- package/lib/runnerExecute.mjs +70 -11
- package/lib/runnerGates.mjs +30 -5
- package/lib/runnerLaunch.mjs +50 -9
- package/lib/runnerOps.mjs +2 -2
- package/lib/runnerRegister.mjs +5 -4
- package/lib/runnerWorkspace.mjs +39 -12
- package/lib/selfUninstall.mjs +6 -8
- package/lib/spawn.mjs +9 -0
- package/lib/sync.mjs +10 -4
- package/lib/update.mjs +12 -6
- package/lib/worktree.mjs +75 -31
- package/lib/worktreeSweep.mjs +122 -0
- package/lib/writePolicy.mjs +112 -2
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Shared authenticated JSON transport for the MCP and runner endpoints.
|
|
2
2
|
// The deadline covers token refresh and response-body consumption, not just
|
|
3
3
|
// receiving headers. A stalled endpoint must not wedge runner settlement.
|
|
4
|
-
import {
|
|
4
|
+
import { hostedToken, noteCredentialRejected, reauthHint, reauthRequired } from './auth.mjs';
|
|
5
5
|
|
|
6
6
|
export const NOT_SIGNED_IN_HINT =
|
|
7
7
|
'Not signed in to the hosted board. Run `viewable login`, or for a script set ' +
|
|
@@ -52,7 +52,7 @@ export async function authenticatedJsonPost(url, body, options = {}) {
|
|
|
52
52
|
// waiting; it must not cancel another caller's rotating-token exchange.
|
|
53
53
|
const token = await hostedToken({ env, fetchImpl, forceRefresh });
|
|
54
54
|
controller.signal.throwIfAborted();
|
|
55
|
-
if (!token) return { authError: await reauthRequired(env) ?
|
|
55
|
+
if (!token) return { authError: await reauthRequired(env) ? await reauthHint(env) : NOT_SIGNED_IN_HINT };
|
|
56
56
|
let result = await post(token);
|
|
57
57
|
let lastBearer = token;
|
|
58
58
|
if (result.response.status === 401 && !forceRefresh) {
|
package/lib/boardside.mjs
CHANGED
|
@@ -237,5 +237,7 @@ export async function reportOutcomeOnBoard(session, outcome, frameId, options =
|
|
|
237
237
|
const lines = [text, outcome.result?.fixAttempted && "Coding tried one fix.", outcome.picturesNote].filter(Boolean);
|
|
238
238
|
const closing = lines.join("\n\n");
|
|
239
239
|
const receipt = await commentOnAnchor(session, frameId, closing, { ...rest, fields });
|
|
240
|
-
|
|
240
|
+
// A refused write rides inside a 200 (#7489): hand its words back so the
|
|
241
|
+
// runner can log why the answer did not land.
|
|
242
|
+
return { landed: receipt?.ok === true && Boolean(closingTextOf(outcome)), ...(receipt?.ok === false ? { refusal: receipt.detail } : {}) };
|
|
241
243
|
}
|
package/lib/child.mjs
CHANGED
|
@@ -24,6 +24,7 @@ import { makeAnswerTracker } from "./answerTag.mjs";
|
|
|
24
24
|
import { RUNNER_BEAT_MS } from "./spawn.mjs";
|
|
25
25
|
import { DELIVERED, SKIP, STOP, watchAnswers, watchReplyFiles } from "./followUps.mjs";
|
|
26
26
|
import { runnableCommand } from "./windows-command.mjs";
|
|
27
|
+
import { otherBoardCall } from "./mcpjson.mjs";
|
|
27
28
|
|
|
28
29
|
// Defaults, all overridable by env and all bounds rather than preferences.
|
|
29
30
|
export const DEFAULTS = {
|
|
@@ -710,7 +711,7 @@ export function attachChild(child, {
|
|
|
710
711
|
* The wall clock is not a progress protocol and does not put a third state on
|
|
711
712
|
* the board. It is the one bound between "a session hung" and "a session
|
|
712
713
|
* billed all night". */
|
|
713
|
-
export function runChild({ bin, args, cwd, env, input, recoveryGroup = false, onProcess, onSession, maxMs, maxLogBytes = DEFAULTS.maxLogBytes, killGraceMs = DEFAULTS.killGraceMs, onChunk, onStdout, stopCheck, stopPollMs = 2000, onSpend, platform = process.platform, transcriptDir, killProcessGroup = false, keepPids, claudeResult = false }) {
|
|
714
|
+
export function runChild({ bin, args, cwd, env, input, recoveryGroup = false, onProcess, onSession, maxMs, maxLogBytes = DEFAULTS.maxLogBytes, killGraceMs = DEFAULTS.killGraceMs, onChunk, onStdout, stopCheck, stopPollMs = 2000, onSpend, platform = process.platform, transcriptDir, killProcessGroup = false, keepPids, claudeResult = false, notices = [] }) {
|
|
714
715
|
// A private group is a group that is signalled: one flag, not two (#6557).
|
|
715
716
|
const ownGroup = (killProcessGroup || recoveryGroup) && platform !== "win32";
|
|
716
717
|
return new Promise((resolve) => {
|
|
@@ -757,6 +758,7 @@ export function runChild({ bin, args, cwd, env, input, recoveryGroup = false, on
|
|
|
757
758
|
okOf: (state, code) => !state.timedOut && !state.stoppedByUser && !(claudeResult && state.resultWasError) && code === 0,
|
|
758
759
|
extraFields: (state) => claudeResult ? { finishedWithError: state.resultWasError && !state.timedOut && !state.stoppedByUser } : {},
|
|
759
760
|
});
|
|
761
|
+
emitNotices(child, notices);
|
|
760
762
|
if (input !== undefined) {
|
|
761
763
|
// A child that dies during startup can close the pipe before end lands.
|
|
762
764
|
// Its process error/close event owns the outcome; stdin's EPIPE is not a
|
|
@@ -833,7 +835,7 @@ export function runChild({ bin, args, cwd, env, input, recoveryGroup = false, on
|
|
|
833
835
|
* whole new resume request - the watch loop's 5s poll, the app's receipt, the
|
|
834
836
|
* worktree, and a cold `claude --resume`. That is tens of seconds and it is a
|
|
835
837
|
* design decision, not a constant. */
|
|
836
|
-
export function runStreamingChild({ bin, args, cwd, env, recoveryGroup = false, onSpawn, onProcess, onSession, maxMs, maxLogBytes = DEFAULTS.maxLogBytes, killGraceMs = DEFAULTS.killGraceMs, stallMs = DEFAULTS.stallMs, onChunk, prompt, images, replyDir, replyPrefix, replyPollMs = 500, onUndeliveredReply, answerPoll, answerPollMs = 4000, askPermission, stopCheck, stopPollMs = 2000, onSpend, platform = process.platform, transcriptDir, keepPids }) {
|
|
838
|
+
export function runStreamingChild({ bin, args, cwd, env, recoveryGroup = false, onSpawn, onProcess, onSession, maxMs, maxLogBytes = DEFAULTS.maxLogBytes, killGraceMs = DEFAULTS.killGraceMs, stallMs = DEFAULTS.stallMs, onChunk, prompt, images, replyDir, replyPrefix, replyPollMs = 500, onUndeliveredReply, answerPoll, answerPollMs = 4000, askPermission, stopCheck, stopPollMs = 2000, onSpend, platform = process.platform, transcriptDir, keepPids, boardServerKey, notices = [], log }) {
|
|
837
839
|
// Its private group is signalled on Stop and timeout, not just created (#6557).
|
|
838
840
|
const ownGroup = recoveryGroup && platform !== "win32";
|
|
839
841
|
return new Promise((resolve) => {
|
|
@@ -1000,6 +1002,19 @@ export function runStreamingChild({ bin, args, cwd, env, recoveryGroup = false,
|
|
|
1000
1002
|
return;
|
|
1001
1003
|
}
|
|
1002
1004
|
const input = request.input && typeof request.input === "object" ? request.input : {};
|
|
1005
|
+
// ANOTHER BOARD SERVER IS REFUSED HERE, BEFORE ANY QUESTION (#7550).
|
|
1006
|
+
// The run loads only its own board server, so this is the second
|
|
1007
|
+
// line: a board server that got in anyway (a connector still
|
|
1008
|
+
// connecting, a renamed self-hosted one, a resource read naming one)
|
|
1009
|
+
// is never offered to the person as "Use report in glytch?", where
|
|
1010
|
+
// one Allow would write to another account's boards. Decided from the
|
|
1011
|
+
// call alone, never from the init list.
|
|
1012
|
+
const other = otherBoardCall(request.tool_name, input, { own: boardServerKey });
|
|
1013
|
+
if (other) {
|
|
1014
|
+
log?.(`permission: ${String(request.tool_name)} reaches another Viewable board server (${other.server}), refused (#7550)`);
|
|
1015
|
+
answerControl(requestId, { behavior: "deny", message: otherBoardDenied(other.server, boardServerKey) });
|
|
1016
|
+
return;
|
|
1017
|
+
}
|
|
1003
1018
|
if (!askPermission) {
|
|
1004
1019
|
answerControl(requestId, { behavior: "deny", message: "This run cannot ask the person for permission. Carry on without it." });
|
|
1005
1020
|
return;
|
|
@@ -1027,6 +1042,7 @@ export function runStreamingChild({ bin, args, cwd, env, recoveryGroup = false,
|
|
|
1027
1042
|
.finally(() => { pendingPermissions.delete(requestId); });
|
|
1028
1043
|
}
|
|
1029
1044
|
|
|
1045
|
+
emitNotices(child, notices);
|
|
1030
1046
|
sendToChild(userMessage(prompt, images));
|
|
1031
1047
|
|
|
1032
1048
|
// Reply files and board answers: the steps are shared by all three engines
|
|
@@ -1291,3 +1307,18 @@ export function childEnv(baseEnv, { root, session, depth, fromId, platform = pro
|
|
|
1291
1307
|
env.PM_SPAWN_DEPTH = String((depth ?? 0) + 1);
|
|
1292
1308
|
return env;
|
|
1293
1309
|
}
|
|
1310
|
+
|
|
1311
|
+
/** The refusal the model reads when it calls another board server (#7550);
|
|
1312
|
+
* `own` is the run's board server key, `glytch` on Codex. One sentence for
|
|
1313
|
+
* every engine (#7591). */
|
|
1314
|
+
export function otherBoardDenied(server, own) {
|
|
1315
|
+
return `${server} is not this run's board. Use your own board tools${own ? ` (mcp__${own}__ask_user, mcp__${own}__report and the rest)` : ""}; never another board server.`;
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
/** Lines the runner says to the person before the agent starts, in the
|
|
1319
|
+
* agent's own stream so the run's card shows them (#7550: apps left off). */
|
|
1320
|
+
function emitNotices(child, notices) {
|
|
1321
|
+
for (const message of Array.isArray(notices) ? notices : []) {
|
|
1322
|
+
if (typeof message === "string" && message) child.stdout.emit("data", Buffer.from(`${JSON.stringify({ type: "system", subtype: "info", message })}\n`));
|
|
1323
|
+
}
|
|
1324
|
+
}
|
package/lib/codex.mjs
CHANGED
|
@@ -1,17 +1,38 @@
|
|
|
1
1
|
import { writeRisk, riskReason } from "./writePolicy.mjs";
|
|
2
|
-
import { automationReadWords } from "./permissionAsk.mjs";
|
|
2
|
+
import { automationReadWords, isTypedNo, typedWords as typedWordsOf } from "./permissionAsk.mjs";
|
|
3
3
|
// Codex's native app-server protocol, translated to the board's session log.
|
|
4
4
|
// No SDK or API key is needed: this uses the user's installed, signed-in CLI.
|
|
5
5
|
import { PassThrough } from "node:stream";
|
|
6
6
|
import { writeFile } from "node:fs/promises";
|
|
7
|
-
import { attachChild, DEFAULTS } from "./child.mjs";
|
|
7
|
+
import { attachChild, DEFAULTS, otherBoardDenied } from "./child.mjs";
|
|
8
8
|
import { imageAttachments } from "./imageAttachments.mjs";
|
|
9
9
|
import { DELIVERED, SKIP, watchAnswers, watchReplyFiles } from "./followUps.mjs";
|
|
10
|
-
import { CODEX_TOOL_TIMEOUT_SEC } from "./mcpjson.mjs";
|
|
10
|
+
import { CODEX_TOOL_TIMEOUT_SEC, otherBoardCall } from "./mcpjson.mjs";
|
|
11
11
|
import { codexRpc, startCodex } from "./codex-rpc.mjs";
|
|
12
12
|
import { planWindowInfoMessage, readPlanWindow } from "./codexPlanWindow.mjs";
|
|
13
13
|
import { prepareCodexApps, verifyCodexApps } from "./codexApps.mjs";
|
|
14
14
|
import { secretLike, toolInputsText } from "./codexToolInputs.mjs";
|
|
15
|
+
import { CODEX_LOGIN_HOOK_KEY, codexLoginHookCommand, codexOtherLoginArgs } from "./otherLogins.mjs";
|
|
16
|
+
|
|
17
|
+
// ANOTHER LOGIN IS REFUSED BEFORE IT RUNS, ON CODEX TOO (#7466). The board's
|
|
18
|
+
// ask in Codex's words, for the refusal the hook hands back; it matches the
|
|
19
|
+
// `mcp_servers.glytch` key codexBoardArgs registers.
|
|
20
|
+
const CODEX_ASK = "mcp__glytch__ask_user";
|
|
21
|
+
const LOGIN_HOOK_MISSING = "Codex on this computer did not load the block on other logins, so this run did not start. " +
|
|
22
|
+
"Update Codex (`codex update`) and run again.";
|
|
23
|
+
|
|
24
|
+
/** Whether the running app server lists the other-login hook (otherLogins.mjs
|
|
25
|
+
* `codexOtherLoginArgs`) as trusted and on for this folder. Codex runs an
|
|
26
|
+
* untrusted or switched-off hook never, so a run without it is not started:
|
|
27
|
+
* an older Codex (no hooks/list), a hash Codex no longer accepts, or custom
|
|
28
|
+
* arguments that replaced the hook all fail closed. */
|
|
29
|
+
async function requireLoginHook(rpc, cwd, command = codexLoginHookCommand({ ask: CODEX_ASK })) {
|
|
30
|
+
let listed;
|
|
31
|
+
try { listed = await rpc.request("hooks/list", cwd ? { cwds: [cwd] } : {}); } catch { throw new Error(LOGIN_HOOK_MISSING); }
|
|
32
|
+
const hooks = (Array.isArray(listed?.data) ? listed.data : []).flatMap((entry) => (Array.isArray(entry?.hooks) ? entry.hooks : []));
|
|
33
|
+
const ours = hooks.find((hook) => hook?.key === CODEX_LOGIN_HOOK_KEY && hook.command === command);
|
|
34
|
+
if (!ours || ours.enabled !== true || ours.eventName !== "preToolUse" || !["trusted", "managed"].includes(ours.trustStatus)) throw new Error(LOGIN_HOOK_MISSING);
|
|
35
|
+
}
|
|
15
36
|
|
|
16
37
|
// MOVED ONTO THE HOSTED ENDPOINT, 2026-09-11 (brief 30, W2a): the local
|
|
17
38
|
// stdio server this used to spawn as `mcp_servers.board`'s
|
|
@@ -257,12 +278,28 @@ function protocolQuestions(method, params) {
|
|
|
257
278
|
return { questions };
|
|
258
279
|
}
|
|
259
280
|
|
|
281
|
+
// The other board server an app approval reaches, or null (#7550, #7591).
|
|
282
|
+
// The run's own board is `mcp_servers.glytch`, set to approve every tool
|
|
283
|
+
// (codexBoardArgs), so it never asks: exempting it here costs nothing, and a
|
|
284
|
+
// plugin's or an app's `glytch` is switched off by the apps check before it
|
|
285
|
+
// can. When Codex names the call only in words (an older input request whose
|
|
286
|
+
// started item was never seen), the words are read for this refusal alone: a
|
|
287
|
+
// wrong read can only refuse, never allow (#6955 keeps allowing off the words).
|
|
288
|
+
const otherBoardAsk = (called, method, params, question) => {
|
|
289
|
+
const own = { own: "glytch" };
|
|
290
|
+
if (called) return otherBoardCall(`mcp__${called.app}__${called.tool}`, {}, own);
|
|
291
|
+
if (method === ELICITATION) return otherBoardCall("ReadMcpResourceTool", { server: params.serverName }, own);
|
|
292
|
+
const named = /^Allow (\S+) (\S+?)\?$/.exec(String(question.question ?? "").trim());
|
|
293
|
+
return named ? otherBoardCall(`mcp__${named[1]}__${named[2]}`, {}, own) : null;
|
|
294
|
+
};
|
|
295
|
+
|
|
260
296
|
export async function runCodexChild(opts) {
|
|
261
297
|
const isDraft = opts.codex?.planMode === "draft";
|
|
298
|
+
const prepare = () => prepareCodexApps(opts, { on: opts.codex?.computerApps === true, isDraft });
|
|
262
299
|
let apps;
|
|
263
300
|
try {
|
|
264
301
|
imageAttachments(opts.images);
|
|
265
|
-
apps = await
|
|
302
|
+
apps = await prepare();
|
|
266
303
|
} catch (error) { return { ok: false, log: "", spawnError: error.message }; }
|
|
267
304
|
const startedAt = Date.now();
|
|
268
305
|
const maxMs = opts.maxMs ?? 60_000;
|
|
@@ -271,7 +308,15 @@ export async function runCodexChild(opts) {
|
|
|
271
308
|
if (remainingMs <= 0) return { ok: false, log: "", spawnError: "Codex ran out of time checking apps." };
|
|
272
309
|
const { appsRetry: retry, ...outcome } = await runCodexAttempt({ ...opts, maxMs: remainingMs }, apps);
|
|
273
310
|
if (!retry || outcome.timedOut || outcome.stoppedByUser || outcome.stalled) return outcome;
|
|
274
|
-
|
|
311
|
+
if (retry.unseen) {
|
|
312
|
+
// A new folder: Codex trusted it at thread/start and loaded its own
|
|
313
|
+
// servers after our read (#7529). Read the apps again, once, as Try
|
|
314
|
+
// again would; a server still unseen is then checked as usual. We
|
|
315
|
+
// never write the folder's trust ourselves.
|
|
316
|
+
try { apps = { ...(await prepare()), seen: undefined }; } catch (error) { return { ok: false, log: "", spawnError: error.message }; }
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
apps = { args: [...apps.args, ...retry.args], sources: retry.sources, notices: [...apps.notices, ...retry.notices], seen: apps.seen };
|
|
275
320
|
}
|
|
276
321
|
}
|
|
277
322
|
|
|
@@ -297,7 +342,10 @@ function runCodexAttempt(opts, apps) {
|
|
|
297
342
|
// here, server by server, before the app server starts.
|
|
298
343
|
const appSources = apps.sources;
|
|
299
344
|
let appsRetry;
|
|
300
|
-
|
|
345
|
+
// The other-login hook goes last, on every run, a draft included: a
|
|
346
|
+
// read-only sandbox still reads a token file (#7466).
|
|
347
|
+
const start = async () => [...(opts.args ?? ["app-server"]), ...(isDraft ? [] : codexBoardArgs(config).slice(1)), ...apps.args,
|
|
348
|
+
...codexOtherLoginArgs({ ask: CODEX_ASK })];
|
|
301
349
|
start().then((args) => {
|
|
302
350
|
try { child = startCodex({ ...opts, args }); } catch (error) { resolve({ ok: false, log: "", spawnError: error.message }); return; }
|
|
303
351
|
drive();
|
|
@@ -473,6 +521,19 @@ function runCodexAttempt(opts, apps) {
|
|
|
473
521
|
// the same rule the server runs, with the app's own labels from the inventory.
|
|
474
522
|
// An approval that names no tool, or one with no arguments to read, keeps asking.
|
|
475
523
|
const called = appApproval ? calledApp(method, params, question) : null;
|
|
524
|
+
// ANOTHER BOARD SERVER IS REFUSED BEFORE ANY QUESTION, ON CODEX TOO (#7550, #7591).
|
|
525
|
+
// The apps check switches off every board server it can name; this is the
|
|
526
|
+
// second line, as child.mjs is for Claude: a board server it missed (a
|
|
527
|
+
// renamed one, one that started late) is never offered to the person as
|
|
528
|
+
// "Allow?", where one Allow would write to another account's boards.
|
|
529
|
+
// Decided from the call alone: the server's name or a tool only the board
|
|
530
|
+
// has (otherBoardAsk).
|
|
531
|
+
const other = appApproval ? otherBoardAsk(called, method, params, question) : null;
|
|
532
|
+
if (other) {
|
|
533
|
+
opts.log?.(`permission: ${other.tool || "a request"} reaches another Viewable board server (${other.server}), refused (#7550)`);
|
|
534
|
+
emit({ type: "system", subtype: "permission", decision: "denied", message: otherBoardDenied(other.server, "glytch") });
|
|
535
|
+
return refused;
|
|
536
|
+
}
|
|
476
537
|
if (called && automationRead(called)) {
|
|
477
538
|
opts.log?.(`permission: ${called.tool} is a read in an automation, no question filed (#5495)`);
|
|
478
539
|
// The run's card says the automation was the yes, as a refusal says its no (#6955).
|
|
@@ -497,12 +558,16 @@ function runCodexAttempt(opts, apps) {
|
|
|
497
558
|
if (verdict.behavior === "answer" && verdict.answer === CANCEL) return cancelled;
|
|
498
559
|
if (verdict.behavior === "answer" && typeof verdict.answer === "string" && !verdict.answer.trim()) return refused;
|
|
499
560
|
if (appApproval && verdict.behavior === "answer" && verdict.answer === "Not this") return refused;
|
|
500
|
-
|
|
561
|
+
// WORDS NEVER GRANT (#8224): typed words are own words even when they
|
|
562
|
+
// spell an option ("Allow"), and so is the app's "Not this: <words>".
|
|
563
|
+
const typedWords = verdict.behavior === "answer" && typeof verdict.answer === "string" &&
|
|
564
|
+
(verdict.typed === true || isTypedNo(verdict.answer) || !question.options.includes(verdict.answer));
|
|
565
|
+
if ((method === ELICITATION || appApproval) && typedWords) {
|
|
501
566
|
// Declines have no protocol content. Use the incumbent live
|
|
502
567
|
// reply path so own words reach the agent, never grant a call.
|
|
503
568
|
ownWordsPending += 1;
|
|
504
569
|
try {
|
|
505
|
-
if (!(await deliver(`The person declined this app request: ${question.question}\nTheir answer: ${verdict.answer}`))) throw new Error("the turn is no longer active");
|
|
570
|
+
if (!(await deliver(`The person declined this app request: ${question.question}\nTheir answer: ${typedWordsOf(verdict.answer)}`))) throw new Error("the turn is no longer active");
|
|
506
571
|
} catch (error) {
|
|
507
572
|
// Completion may already have begun while steer was in
|
|
508
573
|
// flight. Preserve its delivery failure before closing.
|
|
@@ -664,6 +729,8 @@ function runCodexAttempt(opts, apps) {
|
|
|
664
729
|
}, Math.min(10_000, stallMs / 4));
|
|
665
730
|
void (async () => {
|
|
666
731
|
await rpc.initialize();
|
|
732
|
+
// Before anything that could run a command (#7466).
|
|
733
|
+
await requireLoginHook(rpc, opts.cwd);
|
|
667
734
|
// ONE EXTRA CALL, ON THE SAME CONNECTION, BEFORE ANY BILLABLE TURN
|
|
668
735
|
// (brief 46, Move 4). Codex reports no dollars; what it reports
|
|
669
736
|
// instead is how full its 5-hour and weekly windows are
|
|
@@ -708,7 +775,9 @@ function runCodexAttempt(opts, apps) {
|
|
|
708
775
|
// implementation thread's history or permissions.
|
|
709
776
|
const thread = await rpc.request(!isDraft && config.resumeSessionId ? "thread/resume" : "thread/start", {
|
|
710
777
|
...(!isDraft && config.resumeSessionId ? { threadId: config.resumeSessionId } : {}),
|
|
711
|
-
|
|
778
|
+
// An ask that only reads apps (#8261) takes the same read-only sandbox,
|
|
779
|
+
// and keeps its board server and its thread.
|
|
780
|
+
cwd: opts.cwd, approvalPolicy: asking ? "on-request" : "never", sandbox: isDraft || config.readOnly === true ? "read-only" : "workspace-write",
|
|
712
781
|
...(isDraft ? { ephemeral: true } : {}),
|
|
713
782
|
...(config.model ? { model: config.model } : {}),
|
|
714
783
|
// The extra writable root for `<boardRoot>/.glytch` retired with it
|
|
@@ -719,7 +788,7 @@ function runCodexAttempt(opts, apps) {
|
|
|
719
788
|
// rather than by a filesystem-writing subprocess, so there is nothing
|
|
720
789
|
// under `.glytch` for this sandbox to need write access to any more.
|
|
721
790
|
config: {
|
|
722
|
-
...(isDraft ? {} : { "sandbox_workspace_write.writable_roots": [opts.cwd].filter(Boolean) }),
|
|
791
|
+
...(isDraft || config.readOnly === true ? {} : { "sandbox_workspace_write.writable_roots": [opts.cwd].filter(Boolean) }),
|
|
723
792
|
...(config.effort ? { model_reasoning_effort: config.effort } : {}),
|
|
724
793
|
// THE PLAN TOOL, SWITCHED ON (2026-09-26, the same live run): the
|
|
725
794
|
// preamble tells a Codex session to plan with `update_plan`, and
|
|
@@ -753,7 +822,12 @@ function runCodexAttempt(opts, apps) {
|
|
|
753
822
|
threadId = thread.thread?.id;
|
|
754
823
|
if (!threadId) throw new Error("Codex did not return a thread id");
|
|
755
824
|
await opts.onSession?.(threadId);
|
|
756
|
-
const checkedApps = await verifyCodexApps(rpc, { cwd: opts.cwd, threadId, on: config.computerApps === true, isDraft, sources: appSources });
|
|
825
|
+
const checkedApps = await verifyCodexApps(rpc, { cwd: opts.cwd, threadId, on: config.computerApps === true, isDraft, sources: appSources, seen: apps.seen, env: opts.boardEnv });
|
|
826
|
+
if (checkedApps.unseen) {
|
|
827
|
+
appsRetry = checkedApps;
|
|
828
|
+
finish("Reading the apps again: Codex loaded this folder's apps after they were read.");
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
757
831
|
if (checkedApps.notices.length) {
|
|
758
832
|
appsRetry = checkedApps;
|
|
759
833
|
// Reap the child through the existing bounded shutdown before retrying.
|
package/lib/codexApps.mjs
CHANGED
|
@@ -3,6 +3,20 @@
|
|
|
3
3
|
import { codexRpc, startCodex } from "./codex-rpc.mjs";
|
|
4
4
|
import { killTree } from "./kill.mjs";
|
|
5
5
|
import { secretLike } from "./codexToolInputs.mjs";
|
|
6
|
+
import { isBoardServer } from "./mcpjson.mjs";
|
|
7
|
+
|
|
8
|
+
// ANOTHER VIEWABLE BOARD IS NEVER ONE OF THE PERSON'S APPS (#7550). With the
|
|
9
|
+
// apps on, a `viewable` entry from `viewable init`, a plugin's board server or
|
|
10
|
+
// a ChatGPT app with the board's tools loaded beside the run's own `glytch`
|
|
11
|
+
// and offered the same tools. Each is switched off for the run and named in
|
|
12
|
+
// one line; a ChatGPT app can only be switched off with all of them.
|
|
13
|
+
const OTHER_BOARD = "a run uses only its own Viewable board";
|
|
14
|
+
const OTHER_BOARD_APP = "one of them is a Viewable board, and a run uses only its own";
|
|
15
|
+
/** Is this server another board server than the run's own: the configured
|
|
16
|
+
* `glytch` that codexBoardArgs points at the run's board? A plugin's or an
|
|
17
|
+
* app's `glytch` is someone else's. */
|
|
18
|
+
const otherBoard = (name, server, tools, { configured = true, env } = {}) =>
|
|
19
|
+
!(configured && name === "glytch") && isBoardServer(name, server, { ...(env ? { env } : {}), ...(tools ? { tools } : {}) });
|
|
6
20
|
|
|
7
21
|
const unreadable = () => new Error("Couldn't read the apps set up in Codex, so this run did not start. Check your apps in Codex, then try again.");
|
|
8
22
|
// Codex did not answer in time (slow under load, #5271). Not the person's apps.
|
|
@@ -150,7 +164,9 @@ function notice(source, reason) {
|
|
|
150
164
|
// A source is never merely omitted from verification: apply its OFF policy
|
|
151
165
|
// and check the resulting process before a turn. Unknown built-in provenance
|
|
152
166
|
// can only be isolated at the built-in apps transport, as with the OFF switch.
|
|
153
|
-
|
|
167
|
+
// A configured server's OFF keeps its endpoint (endpointArgs): an OFF with no
|
|
168
|
+
// url is the policy-only override Codex 0.165 rejects (#3269, #7529).
|
|
169
|
+
function disableSource(plan, source, reason, servers = {}) {
|
|
154
170
|
const affected = source.kind === "apps" ? plan.sources.filter((entry) => entry.kind === "apps") : [source];
|
|
155
171
|
for (const entry of affected) {
|
|
156
172
|
if (!entry.enabled) continue;
|
|
@@ -158,7 +174,10 @@ function disableSource(plan, source, reason) {
|
|
|
158
174
|
if (!plan.notices.includes(notice(entry, reason))) plan.notices.push(notice(entry, reason));
|
|
159
175
|
}
|
|
160
176
|
if (source.kind === "apps") plan.args.push("-c", "features.apps=false");
|
|
161
|
-
else if (source.kind === "configured")
|
|
177
|
+
else if (source.kind === "configured") {
|
|
178
|
+
const name = pathPart(source.name);
|
|
179
|
+
plan.args.push(...endpointArgs(name, servers[name]), "-c", `mcp_servers.${name}.enabled=false`);
|
|
180
|
+
}
|
|
162
181
|
else plan.args.push("-c", `plugins.${pathPart(source.identity)}.mcp_servers.${pathPart(source.name)}.enabled=false`);
|
|
163
182
|
}
|
|
164
183
|
|
|
@@ -192,21 +211,36 @@ export async function prepareCodexApps(opts, { on, isDraft }) {
|
|
|
192
211
|
if (listed.some((entry) => entry.enabled !== false && !Object.hasOwn(servers, entry.name))) throw unsupported();
|
|
193
212
|
const tools = Object.fromEntries(Object.entries(servers).map(([name, server]) => [name, Object.keys(server.tools ?? {})]));
|
|
194
213
|
const plan = {
|
|
195
|
-
args: [...sourceArgs, ...appsArgs(Object.entries(servers).map(([name, server]) => ({ ...server, name })), { on: allowed, isDraft, tools })],
|
|
214
|
+
args: [...sourceArgs, ...appsArgs(Object.entries(servers).map(([name, server]) => ({ ...server, name })), { on: allowed, isDraft, tools, env: opts.boardEnv })],
|
|
196
215
|
sources: [], notices: [],
|
|
216
|
+
// The configured servers this read saw. A folder Codex trusts only at
|
|
217
|
+
// thread/start adds its own servers after it (#7529): verifyCodexApps
|
|
218
|
+
// names those, and the runner reads the apps again.
|
|
219
|
+
seen: Object.keys(servers),
|
|
197
220
|
};
|
|
198
221
|
if (!allowed) return plan;
|
|
199
222
|
plan.args.push("-c", 'approvals_reviewer="user"');
|
|
200
223
|
const apps = new Map(Object.entries(config.apps ?? {}).filter(([id]) => id !== "_default").map(([id, app]) => [pathPart(id), new Set(Object.keys(app?.tools ?? {}))]));
|
|
201
224
|
for (const [name, server] of Object.entries(servers)) {
|
|
202
225
|
const status = inventory.find((entry) => entry.name === name && !entry.pluginId);
|
|
203
|
-
|
|
226
|
+
const source = { name, kind: "configured", identity: "configured", enabled: server.enabled !== false, tools: Object.keys(status?.tools ?? {}), annotations: labelsOf(status) };
|
|
227
|
+
plan.sources.push(source);
|
|
228
|
+
// appsArgs already switched it off; say so.
|
|
229
|
+
if (otherBoard(name, server, source.tools.length ? source.tools : undefined, { env: opts.boardEnv })) {
|
|
230
|
+
source.board = true;
|
|
231
|
+
if (source.enabled) { source.enabled = false; plan.notices.push(notice(source, OTHER_BOARD)); }
|
|
232
|
+
}
|
|
204
233
|
}
|
|
205
234
|
for (const status of inventory) {
|
|
206
235
|
const names = Object.keys(status.tools);
|
|
207
236
|
if (Object.hasOwn(servers, status.name) && !status.pluginId) continue;
|
|
208
237
|
const source = { name: status.name, kind: status.pluginId ? "plugin" : "apps", identity: status.pluginId ?? "apps", enabled: true, tools: names, annotations: labelsOf(status) };
|
|
209
238
|
plan.sources.push(source);
|
|
239
|
+
if (otherBoard(status.name, null, names, { configured: false, env: opts.boardEnv })) {
|
|
240
|
+
source.board = true;
|
|
241
|
+
disableSource(plan, source, status.pluginId ? OTHER_BOARD : OTHER_BOARD_APP);
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
210
244
|
if (status.pluginId) {
|
|
211
245
|
const plugin = pathPart(status.pluginId);
|
|
212
246
|
const server = pathPart(status.name);
|
|
@@ -250,10 +284,18 @@ export async function prepareCodexApps(opts, { on, isDraft }) {
|
|
|
250
284
|
// Return a stricter plan when one source cannot be verified. The caller must
|
|
251
285
|
// reap this process and apply that plan to a new process before any model turn.
|
|
252
286
|
// Ignored OFF overrides still refuse: an unverified source must never stay on.
|
|
253
|
-
|
|
287
|
+
// With `seen` (the configured servers the read before the thread saw), a
|
|
288
|
+
// configured server outside it returns `unseen` and nothing else: the plan was
|
|
289
|
+
// built for another config, so the caller reads the apps again and starts a
|
|
290
|
+
// new process, apps on or off (#7529). Without `seen` it is checked as usual.
|
|
291
|
+
export async function verifyCodexApps(rpc, { cwd, threadId, on, isDraft, sources = [], seen, env }) {
|
|
254
292
|
const allowed = on && !isDraft;
|
|
255
293
|
try {
|
|
256
294
|
const config = await readAppsConfig(rpc, cwd);
|
|
295
|
+
if (seen) {
|
|
296
|
+
const unseen = Object.keys(config.mcp_servers).filter((name) => !seen.includes(name) && !(name === "glytch" && !isDraft));
|
|
297
|
+
if (unseen.length) return { args: [], sources: structuredClone(sources), notices: [], unseen };
|
|
298
|
+
}
|
|
257
299
|
if (!allowed && (config.features?.plugins !== false || config.features?.apps !== false)) throw unreadable();
|
|
258
300
|
if (allowed && config.approvals_reviewer !== "user") throw unsupported();
|
|
259
301
|
const prompt = (policy, names = []) => {
|
|
@@ -274,10 +316,16 @@ export async function verifyCodexApps(rpc, { cwd, threadId, on, isDraft, sources
|
|
|
274
316
|
continue;
|
|
275
317
|
}
|
|
276
318
|
if (status.name === "glytch" && kind === "configured" && !isDraft) continue;
|
|
319
|
+
if (otherBoard(status.name, kind === "configured" ? servers[status.name] : null, Object.keys(status.tools), { configured: kind === "configured", env }) && (!source || source.enabled)) {
|
|
320
|
+
source ??= plan.sources[plan.sources.push({ name: status.name, kind, identity, enabled: true, tools: Object.keys(status.tools) }) - 1];
|
|
321
|
+
source.board = true;
|
|
322
|
+
disableSource(plan, source, kind === "apps" ? OTHER_BOARD_APP : OTHER_BOARD, servers);
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
277
325
|
if (!source) {
|
|
278
326
|
source = { name: status.name, kind, identity, enabled: true, tools: Object.keys(status.tools) };
|
|
279
327
|
plan.sources.push(source);
|
|
280
|
-
disableSource(plan, source, "Codex could not check the app in this run");
|
|
328
|
+
disableSource(plan, source, "Codex could not check the app in this run", servers);
|
|
281
329
|
continue;
|
|
282
330
|
}
|
|
283
331
|
if (!source.enabled) {
|
|
@@ -303,18 +351,18 @@ export async function verifyCodexApps(rpc, { cwd, threadId, on, isDraft, sources
|
|
|
303
351
|
}
|
|
304
352
|
}
|
|
305
353
|
if (source.tools.some((name) => !Object.hasOwn(status.tools, name))) {
|
|
306
|
-
disableSource(plan, source, "Codex could not find all of its tools in this run");
|
|
354
|
+
disableSource(plan, source, "Codex could not find all of its tools in this run", servers);
|
|
307
355
|
}
|
|
308
356
|
// The labels this thread reports, not the ones read before it started (#6896).
|
|
309
357
|
source.annotations = labelsOf(status);
|
|
310
|
-
} catch { disableSource(plan, source, "Codex could not check approval for the app"); }
|
|
358
|
+
} catch { disableSource(plan, source, "Codex could not check approval for the app", servers); }
|
|
311
359
|
}
|
|
312
360
|
for (const source of plan.sources) {
|
|
313
361
|
if (!source.enabled || (source.name === "glytch" && !isDraft)) continue;
|
|
314
362
|
const status = inventory.find((entry) => entry.name === source.name);
|
|
315
363
|
const kind = status?.pluginId ? "plugin" : status && Object.hasOwn(servers, status.name) ? "configured" : "apps";
|
|
316
364
|
const identity = status?.pluginId ?? kind;
|
|
317
|
-
if (!status || kind !== source.kind || identity !== source.identity) disableSource(plan, source, "Codex could not find the app in this run");
|
|
365
|
+
if (!status || kind !== source.kind || identity !== source.identity) disableSource(plan, source, "Codex could not find the app in this run", servers);
|
|
318
366
|
}
|
|
319
367
|
// Disabled entries may disappear entirely, but their config must prove OFF.
|
|
320
368
|
for (const source of sources.filter((entry) => !entry.enabled)) {
|
|
@@ -325,16 +373,36 @@ export async function verifyCodexApps(rpc, { cwd, threadId, on, isDraft, sources
|
|
|
325
373
|
if (!allowed) throw unreadable();
|
|
326
374
|
if (sources.some((entry) => entry.name === name) || plan.sources.some((entry) => entry.name === name && entry.kind === "configured")) continue;
|
|
327
375
|
// Added after discovery: check it like a late inventory entry.
|
|
376
|
+
if (otherBoard(name, server, undefined, { env })) {
|
|
377
|
+
const source = { name, kind: "configured", identity: "configured", enabled: true, tools: [], board: true };
|
|
378
|
+
plan.sources.push(source);
|
|
379
|
+
disableSource(plan, source, OTHER_BOARD, servers);
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
328
382
|
try { prompt(server); } catch {
|
|
329
383
|
const source = { name, kind: "configured", identity: "configured", enabled: true, tools: [] };
|
|
330
384
|
plan.sources.push(source);
|
|
331
|
-
disableSource(plan, source, "Codex could not check approval for the app");
|
|
385
|
+
disableSource(plan, source, "Codex could not check approval for the app", servers);
|
|
332
386
|
}
|
|
333
387
|
}
|
|
334
388
|
return plan;
|
|
335
389
|
} catch { throw allowed ? unsupported() : unreadable(); }
|
|
336
390
|
}
|
|
337
391
|
|
|
392
|
+
// Codex 0.165 rejects policy-only CLI overrides for workspace-provided
|
|
393
|
+
// servers after account/read ("workspace requirements: invalid data").
|
|
394
|
+
// The same policy succeeds when its override table includes the endpoint.
|
|
395
|
+
// Reassert only the public endpoint; auth headers and tokens stay in their
|
|
396
|
+
// original source. Every override of a configured server starts with this:
|
|
397
|
+
// its prompt or OFF policy in appsArgs, and an OFF from disableSource (#7529).
|
|
398
|
+
function endpointArgs(name, server) {
|
|
399
|
+
if (!server?.environment_id || typeof server.url !== "string") return [];
|
|
400
|
+
let url;
|
|
401
|
+
try { url = new URL(server.url); } catch { throw unsupported(); }
|
|
402
|
+
if (!["https:", "http:"].includes(url.protocol) || url.username || url.password || url.search || url.hash || secretLike(server.url)) throw unsupported();
|
|
403
|
+
return ["-c", `mcp_servers.${name}.url=${JSON.stringify(server.url)}`];
|
|
404
|
+
}
|
|
405
|
+
|
|
338
406
|
// What the switch adds to the app server's command line (#481). Off, and in
|
|
339
407
|
// every draft: each server the person enabled is switched off for this run.
|
|
340
408
|
// On: each one stays, but every tool call asks first ("prompt" asks even for
|
|
@@ -343,29 +411,21 @@ export async function verifyCodexApps(rpc, { cwd, threadId, on, isDraft, sources
|
|
|
343
411
|
// draft switches it off too. Codex reads `mcp_servers.<name>` as a dotted
|
|
344
412
|
// path only when the name is plain (a quoted name makes a new, broken
|
|
345
413
|
// server), so any other server or tool name refuses the run.
|
|
346
|
-
export function appsArgs(servers, { on, isDraft, tools = {} }) {
|
|
414
|
+
export function appsArgs(servers, { on, isDraft, tools = {}, env }) {
|
|
347
415
|
const args = [];
|
|
348
416
|
for (const server of servers) {
|
|
349
417
|
if (server.enabled === false) continue;
|
|
350
418
|
if (server.name === "glytch" && !isDraft) continue;
|
|
351
|
-
|
|
419
|
+
// Another board server is switched off with the apps on too (#7550).
|
|
420
|
+
const board = otherBoard(server.name, server, tools[server.name]?.length ? tools[server.name] : undefined, { env });
|
|
421
|
+
const saved = on && !board && Object.hasOwn(tools, server.name) ? tools[server.name] : [];
|
|
352
422
|
const names = [server.name, ...saved];
|
|
353
423
|
const odd = names.find((name) => !/^[A-Za-z0-9_-]+$/.test(name));
|
|
354
424
|
if (odd !== undefined) {
|
|
355
425
|
throw new Error(`An app set up in Codex has a name this run can't switch off safely (${JSON.stringify(odd)}). Rename it in your Codex config, then try again.`);
|
|
356
426
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
// The same policy succeeds when its override table includes the endpoint.
|
|
360
|
-
// Reassert only the public endpoint; auth headers and tokens stay in their
|
|
361
|
-
// original source. Keep the same prompt/OFF policy below.
|
|
362
|
-
if (server.environment_id && typeof server.url === "string") {
|
|
363
|
-
let url;
|
|
364
|
-
try { url = new URL(server.url); } catch { throw unsupported(); }
|
|
365
|
-
if (!["https:", "http:"].includes(url.protocol) || url.username || url.password || url.search || url.hash || secretLike(server.url)) throw unsupported();
|
|
366
|
-
args.push("-c", `mcp_servers.${server.name}.url=${JSON.stringify(server.url)}`);
|
|
367
|
-
}
|
|
368
|
-
if (!on || isDraft) { args.push("-c", `mcp_servers.${server.name}.enabled=false`); continue; }
|
|
427
|
+
args.push(...endpointArgs(server.name, server));
|
|
428
|
+
if (!on || isDraft || board) { args.push("-c", `mcp_servers.${server.name}.enabled=false`); continue; }
|
|
369
429
|
args.push("-c", `mcp_servers.${server.name}.default_tools_approval_mode="prompt"`);
|
|
370
430
|
for (const tool of saved) args.push("-c", `mcp_servers.${server.name}.tools.${tool}.approval_mode="prompt"`);
|
|
371
431
|
}
|