viewable-one 0.12.8 → 0.12.9
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 +85 -0
- package/README.md +8 -3
- package/SPAWN.md +24 -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/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 +30 -3
- 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
package/lib/runnerExecute.mjs
CHANGED
|
@@ -15,7 +15,11 @@ import * as runnerApiModule from "./runnerApi.mjs";
|
|
|
15
15
|
import { callTool as hostedCallToolDefault } from "./hosted.mjs";
|
|
16
16
|
import { runnerMcpUrlFrom } from "./mcpjson.mjs";
|
|
17
17
|
import { hostedConfig, hostedToken } from "./auth.mjs";
|
|
18
|
-
import { acceptsMessages, agentFor, chatRulesFor, commandFor, isPersistentRequest, preambleFor } from "./agents.mjs";
|
|
18
|
+
import { acceptsMessages, agentFor, boardRunKey, chatRulesFor, commandFor, isPersistentRequest, preambleFor } from "./agents.mjs";
|
|
19
|
+
import { claudeAppServers } from "./computerApps.mjs";
|
|
20
|
+
import { mkdtemp, writeFile } from "node:fs/promises";
|
|
21
|
+
import { tmpdir } from "node:os";
|
|
22
|
+
import { join } from "node:path";
|
|
19
23
|
import { getRepoMap, formatRepoPrimer } from "./repomap.mjs";
|
|
20
24
|
import { buildAttemptsSectionFromRows } from "./compose.mjs";
|
|
21
25
|
import { imageInspectionInstruction } from "./imageAttachments.mjs";
|
|
@@ -91,23 +95,35 @@ export async function executeRequest(project, run, settings, log, timing, receip
|
|
|
91
95
|
const prepared = await prepareRun(ctx, admitted, receipt, preparation);
|
|
92
96
|
if ("patch" in prepared) return finish(prepared.patch);
|
|
93
97
|
const state = { ...admitted, ...prepared };
|
|
98
|
+
// Folders this run made for its MCP config files; startRun removes them.
|
|
99
|
+
state.tempDirs = [];
|
|
94
100
|
state.planRun = makePlanRun(ctx, state);
|
|
95
101
|
return startRun(ctx, state, { timing, receipt, preparation, finish });
|
|
96
102
|
}
|
|
97
103
|
|
|
98
104
|
/** The hosted board this run reports to, and the worktree it runs in. `{
|
|
99
105
|
* patch }` when the workspace refused; otherwise what `startRun` needs. */
|
|
100
|
-
async function prepareRun({ project, root, id, request, isChat, runnerApi, hostedEnv, rowsOpts, session, claimedAt, settings, log }, { chatCwd, isResume, from, ownTreePath }, receipt, preparation) {
|
|
106
|
+
async function prepareRun({ project, root, id, request, isChat, runnerApi, hostedEnv, rowsOpts, session, claimedAt, boardId, settings, log }, { chatCwd, chatInFolder, isResume, from, ownTreePath, ownTreeRemoved }, receipt, preparation) {
|
|
101
107
|
const hostedBoard = await hostedConfig({ env: hostedEnv });
|
|
102
108
|
const childMcpUrl = runnerMcpUrlFrom(hostedBoard, hostedEnv, (message) => log(`[${id}] ${message}`));
|
|
103
109
|
// The runner's permission checks and collect_session (including the final
|
|
104
110
|
// sweep) use the same direct endpoint as its child. Keep the hosted
|
|
105
111
|
// transport's refresh/deadline/cancellation logic; only reroute MCP posts,
|
|
106
112
|
// never OAuth discovery or refresh requests made through the same fetch.
|
|
107
|
-
const
|
|
113
|
+
const transport = settings.hostedCallTool ?? ((name, args, options) => hostedCallToolDefault(name, args, {
|
|
108
114
|
...options,
|
|
109
115
|
mcpUrl: childMcpUrl, fetchImpl: settings.fetchImpl,
|
|
110
116
|
}));
|
|
117
|
+
// EVERY HOSTED CALL THE RUNNER MAKES FOR THIS RUN NAMES THE RUN'S BOARD
|
|
118
|
+
// (#7489). The closing reply, the answer poll, the late-row sweep and a
|
|
119
|
+
// refusal note send no board_id, and since #5149 the server refuses such a
|
|
120
|
+
// write inside a 200 when the account has two or more open boards, so the
|
|
121
|
+
// run's answer never landed. The child already gets the same id as
|
|
122
|
+
// X-Glytch-Board; permission asks pinned it on their own. A row with no
|
|
123
|
+
// board id sends no header, as before.
|
|
124
|
+
const hostedCallTool = boardId
|
|
125
|
+
? (name, args, options) => transport(name, args, { sessionBoardId: boardId, ...options })
|
|
126
|
+
: transport;
|
|
111
127
|
const boardToken = await hostedToken({ env: hostedEnv, fetchImpl: settings.fetchImpl, log });
|
|
112
128
|
preparation.check();
|
|
113
129
|
if (!boardToken) {
|
|
@@ -129,8 +145,8 @@ async function prepareRun({ project, root, id, request, isChat, runnerApi, hoste
|
|
|
129
145
|
}
|
|
130
146
|
};
|
|
131
147
|
const workspace = await prepareRequestWorkspace({
|
|
132
|
-
root, id, request, isResume, session, from, log, isChat, chatCwd, claimedAt, ownTreePath,
|
|
133
|
-
otherRunningCount, preparation, retainSidecar,
|
|
148
|
+
root, id, request, isResume, session, from, log, isChat, chatCwd, chatInFolder, claimedAt, ownTreePath, ownTreeRemoved,
|
|
149
|
+
otherRunningCount, preparation, retainSidecar, callTool: hostedCallTool,
|
|
134
150
|
updateSidecarEarly: (sidecar) => {
|
|
135
151
|
preparation.check();
|
|
136
152
|
retainSidecar(sidecar);
|
|
@@ -157,9 +173,36 @@ async function prepareRun({ project, root, id, request, isChat, runnerApi, hoste
|
|
|
157
173
|
|
|
158
174
|
/** The prompt, the command and its arguments for one try of this run: the
|
|
159
175
|
* first, a fresh retry when the resume was not found, or the one fix. */
|
|
160
|
-
function makePlanRun({ project, root, id, request, isChat, runnerApi, hostedEnv, session, boardId, settings, log }, { referenceImages, from, agent, resolvedBinPath, made, useStreaming, boardToken, childMcpUrl }) {
|
|
176
|
+
function makePlanRun({ project, root, id, request, isChat, runnerApi, hostedEnv, session, boardId, settings, log }, { referenceImages, from, agent, resolvedBinPath, made, useStreaming, boardToken, childMcpUrl, tempDirs }) {
|
|
161
177
|
return async ({ resumeId, note, fixing = false }) => {
|
|
162
178
|
const fresh = resumeId === "";
|
|
179
|
+
// ONE BOARD SERVER PER RUN (#7550). Claude's per-launch board key is made
|
|
180
|
+
// here, so the prompt names the run's own tools by it, and with the
|
|
181
|
+
// person's apps on, their own servers are read now: every Viewable board
|
|
182
|
+
// server is left out (computerApps.mjs claudeAppServers). A list that
|
|
183
|
+
// cannot be read runs this launch with the apps off, and says so.
|
|
184
|
+
const isClaude = agentFor(agent) === "claude";
|
|
185
|
+
const boardServerKey = isClaude ? boardRunKey() : undefined;
|
|
186
|
+
// A run that only reads (#8261) never loads the person's own apps.
|
|
187
|
+
let computerApps = request.computerApps === true && request.readOnly !== true;
|
|
188
|
+
let appServers;
|
|
189
|
+
const notices = [];
|
|
190
|
+
if (isClaude && computerApps && request.planMode !== "draft") {
|
|
191
|
+
try {
|
|
192
|
+
const read = await claudeAppServers({ cwd: made.cwd, root, env: settings.env ?? process.env });
|
|
193
|
+
appServers = read.servers;
|
|
194
|
+
if (read.dropped.length) {
|
|
195
|
+
log(`[${id}] left out of this run, another Viewable board server: ${read.dropped.join(", ")}`);
|
|
196
|
+
// The person's own app named `board` or `viewable` would vanish with
|
|
197
|
+
// no visible reason (#7591), as Codex's (codexApps.mjs notice) does not.
|
|
198
|
+
notices.push(`${read.dropped.join(", ")} ${read.dropped.length === 1 ? "was" : "were"} turned off for this run because a run uses only its own Viewable board.`);
|
|
199
|
+
}
|
|
200
|
+
} catch {
|
|
201
|
+
computerApps = false;
|
|
202
|
+
log(`[${id}] could not read the apps set up in Claude Code; this run goes with them off`);
|
|
203
|
+
notices.push("Couldn't read the apps set up in Claude Code, so this run went without them. Check your apps in Claude Code, then try again.");
|
|
204
|
+
}
|
|
205
|
+
}
|
|
163
206
|
// chat turn, difference 3: NEITHER, EVER. Both the primer and the
|
|
164
207
|
// attempts log exist to save a FRESH session from rediscovering what an
|
|
165
208
|
// earlier one already learned; a chat turn is either the first message
|
|
@@ -178,9 +221,9 @@ function makePlanRun({ project, root, id, request, isChat, runnerApi, hostedEnv,
|
|
|
178
221
|
// needed, the apps-off rule, so the reply can offer Manage agent.
|
|
179
222
|
let text = request.planMode === "draft"
|
|
180
223
|
? `Investigate the request using read-only research, then return an actionable implementation plan in your final response. Structure the response as a report: keep resolved or contextual findings in their own sections; put actionable work under a \`## Implementation plan\` heading with one \`### Step N: ...\` or \`### Issue X: ...\` heading per top-level item; put numbered substeps under a \`**Steps:**\` label; and label checks and open decisions clearly. Do not implement anything, use tools to modify files, or ask for permission to implement. The human will edit and approve or reject your final plan on the board.\n\n${String(request.prompt)}`
|
|
181
|
-
: `${isChat ? "" : preambleFor(agent, { ...(made.isolated ? {} : { workplace: IN_PLACE_WORKPLACE }), computerApps: request.
|
|
224
|
+
: `${isChat ? "" : preambleFor(agent, { ...(made.isolated ? {} : { workplace: IN_PLACE_WORKPLACE }), computerApps, boardServerKey, readApps: request.readApps, readOnly: request.readOnly === true })}${String(request.prompt)}`;
|
|
182
225
|
if (isChat && request.planMode !== "draft") {
|
|
183
|
-
text = `${chatRulesFor(agent, { computerApps
|
|
226
|
+
text = `${chatRulesFor(agent, { computerApps, boardServerKey })}${text}`;
|
|
184
227
|
}
|
|
185
228
|
if (request.planMode === "execute") text += `\n\nHUMAN-APPROVED IMPLEMENTATION PLAN\nFollow this exact plan, including the human's edits. Ask the human about any material scope change before implementing it.\n\n${request.approvedPlan}`;
|
|
186
229
|
if (note) text = `${text}\n\n${note}`;
|
|
@@ -194,6 +237,8 @@ function makePlanRun({ project, root, id, request, isChat, runnerApi, hostedEnv,
|
|
|
194
237
|
: [];
|
|
195
238
|
const resolved = commandFor(agent, settings.env ?? process.env, {
|
|
196
239
|
planMode: request.planMode,
|
|
240
|
+
// An ask that only reads apps (#8261): the read-only tool set.
|
|
241
|
+
readOnly: request.readOnly === true,
|
|
197
242
|
model: request.model,
|
|
198
243
|
effort: request.effort,
|
|
199
244
|
claudeEfforts: Array.isArray(claudeEfforts) ? claudeEfforts : [],
|
|
@@ -210,9 +255,15 @@ function makePlanRun({ project, root, id, request, isChat, runnerApi, hostedEnv,
|
|
|
210
255
|
sessionKey: session.key,
|
|
211
256
|
boardId,
|
|
212
257
|
// The person's own apps (#481): only an explicit true from the app,
|
|
213
|
-
// which sends it when this person turned the switch on for this agent
|
|
214
|
-
|
|
258
|
+
// which sends it when this person turned the switch on for this agent,
|
|
259
|
+
// and only when their list could be read (#7550).
|
|
260
|
+
computerApps,
|
|
261
|
+
boardServerKey,
|
|
262
|
+
appServers,
|
|
263
|
+
mcpConfigPath: appServers ? join(await makeTempDir(tempDirs), "mcp.json") : undefined,
|
|
215
264
|
});
|
|
265
|
+
// Written before the spawn, readable by this user only.
|
|
266
|
+
if (resolved.mcpConfigFile) await writeFile(resolved.mcpConfigFile.path, resolved.mcpConfigFile.text, { mode: 0o600 });
|
|
216
267
|
const chosen = settings.claudeBin !== undefined
|
|
217
268
|
? { ...resolved, bin: settings.claudeBin, args: request.planMode === "draft" ? resolved.args : settings.claudeArgs ?? resolved.args }
|
|
218
269
|
// THE RESOLVED PATH, NOT THE BARE NAME: the check above already found
|
|
@@ -225,6 +276,14 @@ function makePlanRun({ project, root, id, request, isChat, runnerApi, hostedEnv,
|
|
|
225
276
|
for (const what of chosen.ignored ?? []) log(`[${id}] ignoring ${what}`);
|
|
226
277
|
// `brief` is what the person typed, on its own - the adapters echo it
|
|
227
278
|
// into the transcript instead of the preamble-wrapped `prompt`.
|
|
228
|
-
return { prompt: text, brief: String(request.prompt), chosen, args: chosen.args.map((a) => a.replaceAll("{prompt}", () => text)) };
|
|
279
|
+
return { prompt: text, brief: String(request.prompt), chosen, notices, args: chosen.args.map((a) => a.replaceAll("{prompt}", () => text)) };
|
|
229
280
|
};
|
|
230
281
|
}
|
|
282
|
+
|
|
283
|
+
/** A private folder (0700) for one launch's MCP config, recorded so the run
|
|
284
|
+
* removes it when it ends. */
|
|
285
|
+
async function makeTempDir(tempDirs) {
|
|
286
|
+
const dir = await mkdtemp(join(tmpdir(), "viewable-mcp-"));
|
|
287
|
+
tempDirs?.push(dir);
|
|
288
|
+
return dir;
|
|
289
|
+
}
|
package/lib/runnerGates.mjs
CHANGED
|
@@ -45,12 +45,22 @@ export function samePath(a, b) {
|
|
|
45
45
|
* may reuse one of ITS OWN trees only (round 3 item 67). */
|
|
46
46
|
export async function activeWorktreeForPromptRows(root, projectId, promptNodeId, settings, log = () => {}) {
|
|
47
47
|
const trees = [];
|
|
48
|
-
|
|
48
|
+
// The trees this prompt's runs LEFT NO WORK IN and the runner removed when
|
|
49
|
+
// they ended (`sidecar.worktreeRemoved`, the path, #8266), with the sessions that lived in
|
|
50
|
+
// each: a reply that continues one gets the tree made again at that path; a tree merged, thrown away or pruned is not here.
|
|
51
|
+
const removedTrees = [];
|
|
52
|
+
if (!promptNodeId) return { locked: false, trees, removedTrees };
|
|
49
53
|
const runnerApi = settings.runnerApi ?? runnerApiModule;
|
|
50
54
|
const listed = await runnerApi.runs({ projectIds: [projectId] }, { env: settings.env, fetchImpl: settings.fetchImpl });
|
|
51
55
|
if (!listed.ok) throw new Error(`Cannot verify prompt ownership: ${listed.error}`);
|
|
52
56
|
for (const run of listed.runs ?? []) {
|
|
53
57
|
if (fromIdOf(run.request) !== promptNodeId) continue;
|
|
58
|
+
// The path itself, not this run's own: a follow-up that reused an earlier
|
|
59
|
+
// run's tree and left it unchanged removed THAT path.
|
|
60
|
+
const removedPath = run.sidecar?.worktreeRemoved;
|
|
61
|
+
if (typeof removedPath === "string" && removedPath !== "" && !(await exists(removedPath))) {
|
|
62
|
+
removedTrees.push({ path: removedPath, sessions: [run.sidecar.claudeSessionId, run.sidecar.codexThreadId].filter((v) => typeof v === "string" && v !== "") });
|
|
63
|
+
}
|
|
54
64
|
const title = titleFor(run.request);
|
|
55
65
|
const expectedPath = worktreePath(root, run.id, title);
|
|
56
66
|
if (!(await exists(expectedPath))) continue;
|
|
@@ -86,9 +96,9 @@ export async function activeWorktreeForPromptRows(root, projectId, promptNodeId,
|
|
|
86
96
|
const mainInBranch = await git(["merge-base", "--is-ancestor", mainBranch, branch], root);
|
|
87
97
|
if (branchInMain.ok && !mainInBranch.ok) continue; // merged into the default branch
|
|
88
98
|
log(`[lock] prompt ${promptNodeId} is held by worktree ${expectedPath} on branch ${branch}`);
|
|
89
|
-
return { locked: true, worktreePath: expectedPath, branch, requestId: run.id, trees };
|
|
99
|
+
return { locked: true, worktreePath: expectedPath, branch, requestId: run.id, trees, removedTrees };
|
|
90
100
|
}
|
|
91
|
-
return { locked: false, trees };
|
|
101
|
+
return { locked: false, trees, removedTrees };
|
|
92
102
|
}
|
|
93
103
|
|
|
94
104
|
/** ROWS VERSION of the file-based `activeChatTurnForRoom` (`spawn.mjs`,
|
|
@@ -202,6 +212,11 @@ export async function admitRequest({ project, root, id, request, isChat, runnerA
|
|
|
202
212
|
// checkRequest (pure) has said `cwd` and `roomId` are there. Each check
|
|
203
213
|
// here refuses in words a person reads in the run's result, never throws.
|
|
204
214
|
let chatCwd = null;
|
|
215
|
+
// True when the chat runs in the folder itself (a repo with no commit, or a
|
|
216
|
+
// later turn that hands the folder back): there is no copy of its own, so
|
|
217
|
+
// prepareRequestWorkspace holds it to the same "no second agent in one
|
|
218
|
+
// tree" gate a session gets.
|
|
219
|
+
let chatInFolder = false;
|
|
205
220
|
if (isChat) {
|
|
206
221
|
// WHERE IT RUNS: refused if it escapes the folder (Write, Edit and Bash).
|
|
207
222
|
const resolvedCwd = resolveChatCwd(root, request.cwd);
|
|
@@ -216,6 +231,7 @@ export async function admitRequest({ project, root, id, request, isChat, runnerA
|
|
|
216
231
|
// A BOARD'S SUBFOLDER (viewableFolder.mjs) is made inside the chat tree.
|
|
217
232
|
const board = request.boardFolder === undefined ? null : chatBoardOf(root, resolvedCwd.path, request.boardFolder);
|
|
218
233
|
chatCwd = board?.tree ?? resolvedCwd.path;
|
|
234
|
+
if (samePath(chatCwd, root)) chatInFolder = true;
|
|
219
235
|
// THE DIRECTORY IS THE CONVERSATION (brief 25 difference 2): no worktree
|
|
220
236
|
// PER MESSAGE and no fallback to the linked checkout. `mintIfMissing`
|
|
221
237
|
// (ruling 1) cuts the folder's one long-lived chat worktree, once.
|
|
@@ -226,10 +242,13 @@ export async function admitRequest({ project, root, id, request, isChat, runnerA
|
|
|
226
242
|
preparation.check();
|
|
227
243
|
if (!minted.ok) {
|
|
228
244
|
const detail = `NOTHING WAS SPAWNED AND NOTHING WAS BILLED.\n\n${minted.reason}`;
|
|
229
|
-
log(`[${id}] refused: the chat
|
|
245
|
+
log(`[${id}] refused: the chat copy ${chatCwd} could not be made`);
|
|
230
246
|
return { patch: { status: "error", result: `ERROR\n\n${detail}\n`, finished_at: new Date().toISOString() } };
|
|
231
247
|
}
|
|
232
248
|
log(`[${id}] ${minted.detail}`);
|
|
249
|
+
// A folder with no commit has nothing to cut a copy from: the chat runs
|
|
250
|
+
// in the folder itself (and a board's subfolder is made there).
|
|
251
|
+
if (minted.folder === true) { chatCwd = minted.path; chatInFolder = true; }
|
|
233
252
|
isDir = true;
|
|
234
253
|
}
|
|
235
254
|
if (!isDir) {
|
|
@@ -282,11 +301,17 @@ export async function admitRequest({ project, root, id, request, isChat, runnerA
|
|
|
282
301
|
const from = isChat ? undefined : fromIdOf(request);
|
|
283
302
|
// THE ONE TREE A REQUEST MAY NAME: one of this idea's own (round 3 item 67).
|
|
284
303
|
let ownTreePath = null;
|
|
304
|
+
let ownTreeRemoved = null;
|
|
285
305
|
if (from) {
|
|
286
306
|
const lock = await activeWorktreeForPromptRows(root, project.id, from, settings, log);
|
|
287
307
|
// The tree's own spelling goes down (round 4 item 70): reuseWorktree
|
|
288
308
|
// compares text, and the request may say /var for a /private/var tree.
|
|
289
309
|
ownTreePath = lock.trees.find((tree) => samePath(tree, request.worktreePath)) ?? null;
|
|
310
|
+
// The removed tree this request continues: the one it names, or (the
|
|
311
|
+
// resume op names none once the sidecar dropped the path) the one its
|
|
312
|
+
// session lived in.
|
|
313
|
+
const wantedSession = typeof request.resumeSessionId === "string" ? request.resumeSessionId.trim() : "";
|
|
314
|
+
ownTreeRemoved = lock.removedTrees.find((tree) => samePath(tree.path, request.worktreePath) || (wantedSession !== "" && tree.sessions.includes(wantedSession)))?.path ?? null;
|
|
290
315
|
if (lock.locked) {
|
|
291
316
|
// A resume, or a new session (Codex, opencode) naming the kept tree
|
|
292
317
|
// (review 2026-10-04, D7): both run IN that tree, so neither is a second one.
|
|
@@ -335,5 +360,5 @@ export async function admitRequest({ project, root, id, request, isChat, runnerA
|
|
|
335
360
|
resolvedBinPath = resolvedBin.path;
|
|
336
361
|
}
|
|
337
362
|
|
|
338
|
-
return { referenceImages, chatCwd, isResume, from, ownTreePath, agent, resolvedBinPath };
|
|
363
|
+
return { referenceImages, chatCwd, chatInFolder, isResume, from, ownTreePath, ownTreeRemoved, agent, resolvedBinPath };
|
|
339
364
|
}
|
package/lib/runnerLaunch.mjs
CHANGED
|
@@ -36,8 +36,15 @@ export function resumeNotes(request) {
|
|
|
36
36
|
return { TREE_GONE_NOTE, NOT_FOUND_NOTE };
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
/** Spawn the run's process and see it through to its receipt.
|
|
40
|
-
|
|
39
|
+
/** Spawn the run's process and see it through to its receipt. The folders the
|
|
40
|
+
* run's MCP config files were written in go whichever way it ends, a failure
|
|
41
|
+
* before the engine starts included (#7591: they were made in `planRun`, ahead
|
|
42
|
+
* of the first `try`). */
|
|
43
|
+
export async function startRun(ctx, state, options) {
|
|
44
|
+
try { return await runStarted(ctx, state, options); } finally { await removeTempDirs(state.tempDirs); }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function runStarted(ctx, state, { timing, receipt, preparation, finish }) {
|
|
41
48
|
const { root, id, request, isChat, fromAutomation, runnerApi, rowsOpts, hostedEnv, session, boardId, settings, log } = ctx;
|
|
42
49
|
const { referenceImages, from, agent, made, useStreaming, boardToken, childMcpUrl, hostedCallTool, isPersistent, maxMs, resumeTreeGone, resumeSessionId, planRun } = state;
|
|
43
50
|
const { TREE_GONE_NOTE, NOT_FOUND_NOTE } = resumeNotes(request);
|
|
@@ -46,8 +53,14 @@ export async function startRun(ctx, state, { timing, receipt, preparation, finis
|
|
|
46
53
|
|
|
47
54
|
let prepared = { wrote: null };
|
|
48
55
|
try {
|
|
49
|
-
prepared = await prepareWorkspace(agent, { mcpUrl: childMcpUrl, token: boardToken, sessionKey: session.key, boardId });
|
|
56
|
+
prepared = await prepareWorkspace(agent, { mcpUrl: childMcpUrl, token: boardToken, sessionKey: session.key, boardId, cwd: made.cwd, env: settings.env ?? process.env });
|
|
50
57
|
} catch (error) {
|
|
58
|
+
// opencode with another board server it cannot switch off (#7550): the
|
|
59
|
+
// run does not start, and says what to do.
|
|
60
|
+
if (error?.refused) {
|
|
61
|
+
log(`[${id}] ${error.message}`);
|
|
62
|
+
return finish({ status: "error", result: `ERROR\n\n${error.message}\n`, finished_at: new Date().toISOString() });
|
|
63
|
+
}
|
|
51
64
|
log(`[${id}] could not prepare the board config: ${error?.message ?? error}`);
|
|
52
65
|
}
|
|
53
66
|
|
|
@@ -69,6 +82,8 @@ export async function startRun(ctx, state, { timing, receipt, preparation, finis
|
|
|
69
82
|
const childEnvObj = childEnv(settings.baseEnv ?? process.env, { root, session, depth: settings.depth, fromId: from });
|
|
70
83
|
if (boardToken) childEnvObj.PM_BOARD_TOKEN = boardToken;
|
|
71
84
|
Object.assign(childEnvObj, prepared.env ?? {});
|
|
85
|
+
// Claude: claude.ai connectors off in every run (#7550, agents.mjs).
|
|
86
|
+
Object.assign(childEnvObj, chosen.env ?? {});
|
|
72
87
|
// npm agents use /usr/bin/env node. Discovery alone is not enough after
|
|
73
88
|
// nvm/fnm removes the old Node: every spawn and retry needs its new bin dir.
|
|
74
89
|
const windows = (settings.platform ?? process.platform) === "win32";
|
|
@@ -190,6 +205,11 @@ export async function startRun(ctx, state, { timing, receipt, preparation, finis
|
|
|
190
205
|
}
|
|
191
206
|
}
|
|
192
207
|
|
|
208
|
+
/** The private folders the run's MCP config files were written in (#7550). */
|
|
209
|
+
async function removeTempDirs(dirs) {
|
|
210
|
+
for (const dir of dirs ?? []) await rm(dir, { recursive: true, force: true }).catch(() => {});
|
|
211
|
+
}
|
|
212
|
+
|
|
193
213
|
/** The options one try of the engine runs with, for a plan from `planRun`.
|
|
194
214
|
* `extra` overrides the defaults (a retry's shorter `maxMs`). */
|
|
195
215
|
function runOptionsFor({ id, request, runnerApi, rowsOpts, settings, log }, { agent, made, useStreaming, maxMs }, { imageSuffix, onChunk, childEnvObj, stopCheck, answerPoll, askPermission, receipt }) {
|
|
@@ -235,7 +255,14 @@ function runOptionsFor({ id, request, runnerApi, rowsOpts, settings, log }, { ag
|
|
|
235
255
|
...(promptOnStdin ? { input: renderedPrompt } : {}),
|
|
236
256
|
acp: p.chosen.acp ?? null,
|
|
237
257
|
codex: p.chosen.codex ?? null,
|
|
258
|
+
// Where this run's board is, read the way the runner's own checks read
|
|
259
|
+
// it (claudeAppServers); the child's env is an allowlist without it (#7591).
|
|
260
|
+
boardEnv: settings.env ?? process.env,
|
|
238
261
|
askPermission,
|
|
262
|
+
// The run's own board server, exempt from the other-board refusal, and
|
|
263
|
+
// what the runner tells the person before the agent starts (#7550).
|
|
264
|
+
boardServerKey: p.chosen.boardServerKey,
|
|
265
|
+
notices: p.notices ?? [],
|
|
239
266
|
log: (message) => log(`[${id}] ${message}`),
|
|
240
267
|
};
|
|
241
268
|
return useStreaming
|
package/lib/runnerOps.mjs
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { serviceComputerApps, flushComputerApps } from "./computerApps.mjs";
|
|
8
8
|
import { serviceFolderRead } from "./folderReads.mjs";
|
|
9
9
|
import * as runnerApiModule from "./runnerApi.mjs";
|
|
10
|
-
import { folderRestoreGeneration,
|
|
10
|
+
import { folderRestoreGeneration, removeFolderHoldingLock, withRegistryLock } from "./registry.mjs";
|
|
11
11
|
import { deleteWorktree, mergeWorktree } from "./worktree.mjs";
|
|
12
12
|
import { relaunchServer, readWorktreeRecord } from "./devserver.mjs";
|
|
13
13
|
|
|
@@ -66,7 +66,7 @@ export async function serviceForgetOps(root, project, ops, settings, log = () =>
|
|
|
66
66
|
// The compare, local removal and acknowledgement share init's restore lock:
|
|
67
67
|
// no restore can slip between this check and either destructive operation.
|
|
68
68
|
if (await folderRestoreGeneration(root, env) !== generation) return false;
|
|
69
|
-
const { removed } = await
|
|
69
|
+
const { removed } = await removeFolderHoldingLock(root, env);
|
|
70
70
|
log(
|
|
71
71
|
removed
|
|
72
72
|
? `forget: the board asked for ${root} to be removed - dropped it from the folder registry`
|
package/lib/runnerRegister.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { statSync } from "node:fs";
|
|
|
7
7
|
import { basename } from "node:path";
|
|
8
8
|
|
|
9
9
|
import * as runnerApiModule from "./runnerApi.mjs";
|
|
10
|
-
import {
|
|
10
|
+
import { addFolderHoldingLock, foldersWithoutGit, isScratchFolder, markFolderRestore, readRegistry, readRegistryChecked, withRegistryLock, withoutRemoved } from "./registry.mjs";
|
|
11
11
|
import { platformMark } from "./platform.mjs";
|
|
12
12
|
import { SIGN_IN_AGENTS } from "./signIn.mjs";
|
|
13
13
|
|
|
@@ -60,7 +60,7 @@ export const presenceBody = (settings, { goodbye } = {}) => {
|
|
|
60
60
|
* keeps the last good list. */
|
|
61
61
|
export async function refreshProjectPaths(root, settings) {
|
|
62
62
|
const { folders, ok } = await readRegistryChecked(settings.env ?? process.env);
|
|
63
|
-
if (ok) settings.projectPaths = [...new Set([...folders, root])];
|
|
63
|
+
if (ok) settings.projectPaths = [...new Set([...await withoutRemoved(folders, settings.env ?? process.env), root])];
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
export async function registerAndFindProject(root, settings, { readd = false, onlyRoot = false } = {}) {
|
|
@@ -71,7 +71,7 @@ export async function registerAndFindProject(root, settings, { readd = false, on
|
|
|
71
71
|
const out = await registerProject(root, settings, { readd: true });
|
|
72
72
|
// Publish the local entry before releasing the restore lock. syncRegistry
|
|
73
73
|
// in init remains idempotent, including when Remove won the lock first.
|
|
74
|
-
if (out.ok) await
|
|
74
|
+
if (out.ok) await addFolderHoldingLock(root, env);
|
|
75
75
|
return out;
|
|
76
76
|
}, env);
|
|
77
77
|
}
|
|
@@ -81,7 +81,8 @@ export async function registerAndFindProject(root, settings, { readd = false, on
|
|
|
81
81
|
async function registerProject(root, settings, { readd = false, onlyRoot = false } = {}) {
|
|
82
82
|
const runnerApi = settings.runnerApi ?? runnerApiModule;
|
|
83
83
|
const env = settings.env ?? process.env;
|
|
84
|
-
|
|
84
|
+
// A removed folder is not advertised even when a stray write listed it (#8325).
|
|
85
|
+
const folders = await withoutRemoved(await readRegistry(env), env);
|
|
85
86
|
// Init only owns this folder; a routine daemon register owns the full list.
|
|
86
87
|
settings.projectPaths = [...new Set([...folders, root])];
|
|
87
88
|
const paths = readd || onlyRoot ? [root] : folders.length > 0 ? folders : [root];
|
package/lib/runnerWorkspace.mjs
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// here has nothing to "close" that was not already open - it writes a
|
|
10
10
|
// comment (when the run has an idea at all) and hands the caller a result
|
|
11
11
|
// whose `patch` flips the row straight to `status:'error'`.
|
|
12
|
-
import { makeWorktree, reuseWorktree, resolveContainedCwd } from "./worktree.mjs";
|
|
12
|
+
import { branchOfTreePath, makeWorktree, reuseWorktree, resolveContainedCwd } from "./worktree.mjs";
|
|
13
13
|
import { commentOnAnchor } from "./boardside.mjs";
|
|
14
14
|
import { titleFor } from "./spawn.mjs";
|
|
15
15
|
|
|
@@ -44,7 +44,7 @@ export const IN_PLACE_WORKPLACE =
|
|
|
44
44
|
* made, resumeTreeGone, resumeSessionId}` or `{ok:false, patch}` - the
|
|
45
45
|
* caller writes `patch` through `runnerApi.update`. */
|
|
46
46
|
export async function prepareRequestWorkspace(context, services = defaultServices) {
|
|
47
|
-
const { root, id, request, isResume, session, from, log, otherRunningCount, updateSidecarEarly, isChat, chatCwd, claimedAt, ownTreePath } = context;
|
|
47
|
+
const { root, id, request, isResume, session, from, log, otherRunningCount, updateSidecarEarly, isChat, chatCwd, chatInFolder, claimedAt, ownTreePath, ownTreeRemoved, callTool } = context;
|
|
48
48
|
const { makeWorktree, reuseWorktree, commentOnAnchor: comment, titleFor: title } = services;
|
|
49
49
|
const { preparation, retainSidecar } = context;
|
|
50
50
|
// Only an operation that has acquired the repo lock can own a mutation.
|
|
@@ -91,7 +91,10 @@ export async function prepareRequestWorkspace(context, services = defaultService
|
|
|
91
91
|
// a run of the request's idea made that resolves to the named path, in
|
|
92
92
|
// the tree's own spelling (runner.mjs, round 4 item 70); null when the
|
|
93
93
|
// request names another idea's tree or a path no row of this idea made.
|
|
94
|
-
|
|
94
|
+
// AN ASK THAT ONLY READS APPS (#8261) runs in the folder with tools that only
|
|
95
|
+
// read (agents.mjs), so it needs no copy and leaves none behind.
|
|
96
|
+
const readOnly = !isChat && request.readOnly === true;
|
|
97
|
+
const wantedRecordedTree = !isChat && !readOnly && !request.cwd && request.useWorktree !== false && Boolean(request.worktreePath);
|
|
95
98
|
const isOwnTree = wantedRecordedTree && typeof ownTreePath === "string" && ownTreePath !== "";
|
|
96
99
|
if (wantedRecordedTree && !isOwnTree) log(`[${id}] the named worktree ${request.worktreePath} is not this idea's own; not reused`);
|
|
97
100
|
const reusedTree = isOwnTree ? await reuseWorktree(root, ownTreePath, log, lifecycle) : null;
|
|
@@ -103,7 +106,17 @@ export async function prepareRequestWorkspace(context, services = defaultService
|
|
|
103
106
|
return { ok: false, patch: { status: "error", result: `ERROR\n\nNOTHING WAS SPAWNED AND NOTHING WAS BILLED.\n\n${detail}\n\nRun again once the other repository change has finished.\n`, finished_at: new Date().toISOString() } };
|
|
104
107
|
};
|
|
105
108
|
if (reusedTree?.lockRefused) return lockRefusal(reusedTree.detail);
|
|
106
|
-
|
|
109
|
+
// A COPY THE RUNNER REMOVED BECAUSE THE ASK CHANGED NOTHING is not a copy
|
|
110
|
+
// that went missing (#8266). `ownTreeRemoved` is its path, found by the path
|
|
111
|
+
// the request names or by the session it resumes. The reply gets the tree
|
|
112
|
+
// MADE AGAIN AT THAT PATH, so Claude Code (which keeps a conversation per
|
|
113
|
+
// working directory) resumes the whole conversation, not a fresh one told
|
|
114
|
+
// only the new message. Recovery still refuses (it carries on a run that was
|
|
115
|
+
// cut off mid-way), and so does a continuation whose tree vanished any other
|
|
116
|
+
// way (#2446).
|
|
117
|
+
const removedUnchanged = typeof ownTreeRemoved === "string" && ownTreeRemoved !== "" && request.recovery !== true
|
|
118
|
+
&& !isChat && !request.cwd && request.useWorktree !== false && isResume && !reusedTree;
|
|
119
|
+
if ((request.recovery === true || (request.continues && isResume)) && wantedRecordedTree && !reusedTree && !removedUnchanged) {
|
|
107
120
|
return { ok: false, patch: { status: "error", result: "ERROR\n\nThis session cannot continue because its separate copy is gone. Run again to start a new session.\n", finished_at: new Date().toISOString(), sidecar: { ...(request.recovery === true ? { recoveryFailed: true } : {}) } } };
|
|
108
121
|
}
|
|
109
122
|
if (wantedRecordedTree && !isResume && !reusedTree) log(`[${id}] the kept worktree ${request.worktreePath} is gone; this session gets a new one`);
|
|
@@ -116,25 +129,37 @@ export async function prepareRequestWorkspace(context, services = defaultService
|
|
|
116
129
|
// directory.
|
|
117
130
|
cwd: chatCwd,
|
|
118
131
|
isolated: false,
|
|
119
|
-
detail:
|
|
132
|
+
detail: chatInFolder === true
|
|
133
|
+
? `Chat turn: ran in the folder itself, ${chatCwd}, because it has no commit to make a separate copy from. Anything it changed, it changed there.`
|
|
134
|
+
: `Chat turn: ran in ${chatCwd}, the agent's own chat copy. No copy was made for this message and none was reused.`,
|
|
120
135
|
}
|
|
121
136
|
: reusedTree
|
|
122
137
|
? reusedTree
|
|
123
138
|
: namedCwd
|
|
124
139
|
? { cwd: namedCwd, isolated: false, detail: `Ran in the cwd the request named, ${namedCwd}.` }
|
|
140
|
+
: readOnly
|
|
141
|
+
? { cwd: root, isolated: false, detail: "Read-only app reads in the linked folder. No worktree created." }
|
|
125
142
|
: request.useWorktree === false
|
|
126
143
|
? { cwd: root, isolated: false, detail: `Ran in the linked folder per idea setting (worktree off).` }
|
|
127
|
-
: await makeWorktree(root, id, log, title(request), lifecycle);
|
|
144
|
+
: await makeWorktree(root, id, log, title(request), lifecycle, removedUnchanged ? { path: ownTreeRemoved, branch: branchOfTreePath(ownTreeRemoved) } : undefined);
|
|
128
145
|
preparation?.check();
|
|
129
146
|
if (made.lockRefused) return lockRefusal(made.detail);
|
|
130
147
|
|
|
131
|
-
const wantedIsolation = !isChat && !request.cwd && request.useWorktree !== false;
|
|
132
|
-
|
|
148
|
+
const wantedIsolation = !isChat && !readOnly && !request.cwd && request.useWorktree !== false;
|
|
149
|
+
// A chat that fell back to the folder has the same collision a session does
|
|
150
|
+
// (#7959): a second agent in the same tree, with no branch between them.
|
|
151
|
+
const chatSharesFolder = isChat && chatInFolder === true;
|
|
152
|
+
if ((wantedIsolation && !made.isolated) || chatSharesFolder) {
|
|
133
153
|
const others = typeof otherRunningCount === "function" ? await otherRunningCount() : 0;
|
|
134
154
|
preparation?.check();
|
|
135
155
|
if (others > 0) {
|
|
136
|
-
const detail =
|
|
137
|
-
`NOTHING WAS SPAWNED AND NOTHING WAS BILLED.\n\n` +
|
|
156
|
+
const detail = chatSharesFolder
|
|
157
|
+
? `NOTHING WAS SPAWNED AND NOTHING WAS BILLED.\n\n` +
|
|
158
|
+
`This folder has no commit yet, so this chat has no copy of its own, and ${others} other ` +
|
|
159
|
+
`session${others === 1 ? " is" : "s are"} running. Running here would have put two agents in one ` +
|
|
160
|
+
`folder, editing the same files with no branch between them.\n\n` +
|
|
161
|
+
`Send the message again once they are done, or make a first commit in the folder.`
|
|
162
|
+
: `NOTHING WAS SPAWNED AND NOTHING WAS BILLED.\n\n` +
|
|
138
163
|
`This session could not get its own worktree, and ${others} other ` +
|
|
139
164
|
`session${others === 1 ? " is" : "s are"} running. Falling back to the linked ` +
|
|
140
165
|
`folder would have put two agents in one working tree, editing the same files ` +
|
|
@@ -142,7 +167,7 @@ export async function prepareRequestWorkspace(context, services = defaultService
|
|
|
142
167
|
`File the request again once they are done, or fix what stopped the worktree.`;
|
|
143
168
|
const frameId = typeof from === "string" ? from : undefined;
|
|
144
169
|
if (frameId) {
|
|
145
|
-
await comment(session, frameId, `Refused before spawning: no worktree, and another session is running\nNothing was spawned and nothing was billed. ${made.detail}
|
|
170
|
+
await comment(session, frameId, `Refused before spawning: no worktree, and another session is running\nNothing was spawned and nothing was billed. ${made.detail}`, callTool ? { callTool } : {});
|
|
146
171
|
}
|
|
147
172
|
log(`[${id}] refused: no worktree while ${others} other session(s) run`);
|
|
148
173
|
return { ok: false, patch: { status: "error", result: `ERROR\n\n${detail}\n`, finished_at: new Date().toISOString() } };
|
|
@@ -180,7 +205,9 @@ export async function prepareRequestWorkspace(context, services = defaultService
|
|
|
180
205
|
// "the recorded tree is gone" and the conversation would restart on every
|
|
181
206
|
// turn. Its directory was checked at the top of `runRequest`, which IS the
|
|
182
207
|
// "can this conversation be reached" question this line exists to ask.
|
|
183
|
-
|
|
208
|
+
// A tree made again at its old path is the same working directory: nothing is gone.
|
|
209
|
+
const remade = removedUnchanged && made.isolated && made.path === ownTreeRemoved;
|
|
210
|
+
const resumeTreeGone = isResume && wantedRecordedTree && !reusedTree && !remade;
|
|
184
211
|
const resumeSessionId = isResume && !resumeTreeGone ? String(request.resumeSessionId).trim() : "";
|
|
185
212
|
return { ok: true, made, resumeTreeGone, resumeSessionId };
|
|
186
213
|
}
|
package/lib/selfUninstall.mjs
CHANGED
|
@@ -18,14 +18,12 @@
|
|
|
18
18
|
// an older board, odd JSON, `removed: false`) for any key leaves the
|
|
19
19
|
// computer exactly as it is.
|
|
20
20
|
//
|
|
21
|
-
// Every key, not the first yes:
|
|
22
|
-
// older OAuth pair beside it
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
// back to the old pair and sends its access token, and a refused refresh
|
|
28
|
-
// sends no key at all.
|
|
21
|
+
// Every key, not the first yes: an older bridge's sign-in with a personal
|
|
22
|
+
// key kept the older OAuth pair beside it, and such records are still on
|
|
23
|
+
// some disks (auth.mjs no longer uses them, #8324). If that older pair was
|
|
24
|
+
// taken away by an earlier Remove and the new personal key is refused for
|
|
25
|
+
// another reason, the pair's yes alone would uninstall a computer nobody
|
|
26
|
+
// removed.
|
|
29
27
|
//
|
|
30
28
|
// `viewable uninstall` stops the background app, revokes the key and deletes
|
|
31
29
|
// ~/.glytch. It never touches the Viewable folder or its files: the folder
|
package/lib/spawn.mjs
CHANGED
|
@@ -285,6 +285,15 @@ export function checkRequest(request) {
|
|
|
285
285
|
"computerApps, when present, must be a boolean. True lets this run use the apps the person set up in Claude Code or Codex.",
|
|
286
286
|
);
|
|
287
287
|
}
|
|
288
|
+
// AN ASK THAT ONLY READS APPS (#8261): the read-only tool set, no worktree,
|
|
289
|
+
// and the apps its plan named, which board-mcp's app_read reads (#8254).
|
|
290
|
+
if (request.readOnly !== undefined && typeof request.readOnly !== "boolean") {
|
|
291
|
+
found.note("readOnly, when present, must be a boolean. True runs the session with tools that only read, in the linked folder.");
|
|
292
|
+
}
|
|
293
|
+
if (request.readApps !== undefined && (!Array.isArray(request.readApps) || request.readApps.length > 50
|
|
294
|
+
|| !request.readApps.every((app) => typeof app === "string" && app.trim() !== "" && app.length <= 100))) {
|
|
295
|
+
found.note("readApps, when present, must be a list of app ids: the apps connected in Viewable that this ask's plan reads.");
|
|
296
|
+
}
|
|
288
297
|
// PERSISTENT SESSIONS: session id fields are UUIDs, worktreePath is an
|
|
289
298
|
// absolute path. All are optional. Validated as strings when present.
|
|
290
299
|
for (const field of ["sessionId", "resumeSessionId"]) {
|
package/lib/sync.mjs
CHANGED
|
@@ -43,7 +43,7 @@ import {
|
|
|
43
43
|
noDaemonInstall,
|
|
44
44
|
} from "./logindaemon.mjs";
|
|
45
45
|
import { BOARD_MCP_URL, mergeBoardServer } from "./mcpjson.mjs";
|
|
46
|
-
import { viewableDisplayPath, addFolder, readRegistry } from "./registry.mjs";
|
|
46
|
+
import { viewableDisplayPath, addFolder, addFolderUnlessRemoved, readRegistry } from "./registry.mjs";
|
|
47
47
|
import { readAgentSelection, parseAgentSelection } from "./agent-selection.mjs";
|
|
48
48
|
import { syncProjectMcp } from "./project-mcp.mjs";
|
|
49
49
|
import { packageVersion } from "./update.mjs";
|
|
@@ -139,12 +139,18 @@ export async function syncOpencode(root, { exec = execProbe, found, write = true
|
|
|
139
139
|
* became "a runner project" because nothing here ever told the person why. A
|
|
140
140
|
* write failure is now the same shape every other row in this file uses -
|
|
141
141
|
* red, with the OS's own reason and something to try - never a crash. */
|
|
142
|
-
export async function syncRegistry(root, { env = process.env, write = true } = {}) {
|
|
142
|
+
export async function syncRegistry(root, { env = process.env, write = true, automatic = false } = {}) {
|
|
143
143
|
const folders = await readRegistry(env);
|
|
144
144
|
if (folders.includes(root)) return row("registry", "folder registered", true, "present", "your computer watches this folder");
|
|
145
145
|
if (!write) return row("registry", "folder registered", false, "missing", `this folder is not in ${viewableDisplayPath(env, "folders.json")}`);
|
|
146
146
|
try {
|
|
147
|
-
|
|
147
|
+
// The daemon's own sync is not the person asking for the folder back:
|
|
148
|
+
// it leaves a removed folder removed (#8325). init and doctor still add.
|
|
149
|
+
if (automatic) {
|
|
150
|
+
if (await addFolderUnlessRemoved(root, env) === null) {
|
|
151
|
+
return row("registry", "folder registered", true, "removed", "this folder was removed; run `viewable init` in it to watch it again");
|
|
152
|
+
}
|
|
153
|
+
} else await addFolder(root, env);
|
|
148
154
|
} catch (error) {
|
|
149
155
|
const why = error instanceof Error ? error.message : String(error);
|
|
150
156
|
return row(
|
|
@@ -480,7 +486,7 @@ export async function syncFolder(
|
|
|
480
486
|
? []
|
|
481
487
|
: parseAgentSelection(selectedAgents);
|
|
482
488
|
const found = agents ?? (await detectAgents({ env }));
|
|
483
|
-
const rows = deferRegistry ? [] : [await syncRegistry(root, { env, write })];
|
|
489
|
+
const rows = deferRegistry ? [] : [await syncRegistry(root, { env, write, automatic: daemon })];
|
|
484
490
|
if (selected === null) {
|
|
485
491
|
rows.push(await syncMcpJson(root, { write, platform, env }));
|
|
486
492
|
rows.push(await syncOpencode(root, { exec, found: found?.opencode?.found === true, write }));
|
package/lib/update.mjs
CHANGED
|
@@ -66,12 +66,15 @@ export function compareVersions(a, b) {
|
|
|
66
66
|
* env node started it with another Node. See npm-command.mjs for manager
|
|
67
67
|
* fallbacks; CLI, board Update and daily checks share this resolution. */
|
|
68
68
|
export { npmPathFor } from "./npm-command.mjs";
|
|
69
|
-
export const execNpm = (args, { timeoutMs = NPM_TIMEOUT_MS, execImpl = execFile, ...options } = {}) =>
|
|
69
|
+
export const execNpm = (args, { timeoutMs = NPM_TIMEOUT_MS, execImpl = execFile, signal, ...options } = {}) =>
|
|
70
70
|
new Promise((resolve) => {
|
|
71
71
|
let command;
|
|
72
72
|
try { command = npmCommand(args, options); }
|
|
73
73
|
catch { resolve({ ok: false, stdout: "", stderr: "" }); return; }
|
|
74
|
-
|
|
74
|
+
// `signal` kills npm when the caller stops, so a background lookup never
|
|
75
|
+
// outlives the process that asked for it (#7557).
|
|
76
|
+
if (signal?.aborted) { resolve({ ok: false, stdout: "", stderr: "" }); return; }
|
|
77
|
+
execImpl(command.file, command.args, { timeout: timeoutMs, windowsHide: true, env: command.env, shell: command.shell, ...(signal ? { signal } : {}) }, (error, stdout, stderr) =>
|
|
75
78
|
resolve({ ok: !error, stdout: String(stdout ?? ""), stderr: String(stderr ?? ""), ...(error?.killed ? { timedOut: true } : {}) }),
|
|
76
79
|
);
|
|
77
80
|
});
|
|
@@ -98,8 +101,8 @@ export function installFailureReason(result, where = "") {
|
|
|
98
101
|
return line ? `npm said: ${line.slice(0, 200)}` : "npm did not say why.";
|
|
99
102
|
}
|
|
100
103
|
|
|
101
|
-
export async function latestFromNpm({ exec = execNpm, name = PACKAGE_NAME, timeoutMs = NPM_TIMEOUT_MS } = {}) {
|
|
102
|
-
const result = await exec(["view", name, "version"], { timeoutMs });
|
|
104
|
+
export async function latestFromNpm({ exec = execNpm, name = PACKAGE_NAME, timeoutMs = NPM_TIMEOUT_MS, signal } = {}) {
|
|
105
|
+
const result = await exec(["view", name, "version"], { timeoutMs, ...(signal ? { signal } : {}) });
|
|
103
106
|
if (!result?.ok) return null;
|
|
104
107
|
const version = String(result.stdout).trim().split(/\s+/)[0];
|
|
105
108
|
return /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(version) ? version : null;
|
|
@@ -118,6 +121,9 @@ export function makeUpdateChecker({
|
|
|
118
121
|
intervalMs = DAY_MS,
|
|
119
122
|
now = () => Date.now(),
|
|
120
123
|
log = () => {},
|
|
124
|
+
// Stops the lookup in flight: the runner's stop signal, so Ctrl-C does not
|
|
125
|
+
// leave an `npm view` writing its cache after the runner has exited (#7557).
|
|
126
|
+
signal,
|
|
121
127
|
} = {}) {
|
|
122
128
|
// null rather than 0, so the FIRST beat always asks. With Date.now() a zero
|
|
123
129
|
// would happen to work; with an injected clock starting at zero it silently
|
|
@@ -135,7 +141,7 @@ export function makeUpdateChecker({
|
|
|
135
141
|
running = true;
|
|
136
142
|
checkedAt = now();
|
|
137
143
|
try {
|
|
138
|
-
const found = await latest();
|
|
144
|
+
const found = await latest(signal ? { signal } : undefined);
|
|
139
145
|
if (found) {
|
|
140
146
|
known = found;
|
|
141
147
|
if (compareVersions(found, version) > 0) log(`update available: ${version} -> ${found} (npm i -g ${PACKAGE_NAME})`);
|
|
@@ -150,7 +156,7 @@ export function makeUpdateChecker({
|
|
|
150
156
|
state,
|
|
151
157
|
/** What goes into the mark file, and a check kicked off when one is due. */
|
|
152
158
|
mark() {
|
|
153
|
-
if (!running && (checkedAt === null || now() - checkedAt >= intervalMs)) void run();
|
|
159
|
+
if (!running && !signal?.aborted && (checkedAt === null || now() - checkedAt >= intervalMs)) void run();
|
|
154
160
|
return { version: state().version, updateAvailable: state().updateAvailable };
|
|
155
161
|
},
|
|
156
162
|
/** Await one check. `doctor` and the tests use this. */
|