viewable-one 0.12.1 → 0.12.3

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 (71) hide show
  1. package/CHANGELOG.md +71 -1
  2. package/README.md +31 -48
  3. package/SPAWN.md +136 -79
  4. package/glytch.mjs +41 -10
  5. package/lib/acp.mjs +152 -150
  6. package/lib/admission.mjs +25 -5
  7. package/lib/agent-selection.mjs +5 -4
  8. package/lib/agents.mjs +68 -24
  9. package/lib/answerTag.mjs +47 -0
  10. package/lib/atomic.mjs +1 -16
  11. package/lib/auth.mjs +172 -52
  12. package/lib/authenticatedHttp.mjs +10 -3
  13. package/lib/boardside.mjs +28 -12
  14. package/lib/child.mjs +129 -116
  15. package/lib/claudeModels.mjs +168 -0
  16. package/lib/codex-rpc.mjs +2 -2
  17. package/lib/codex.mjs +50 -50
  18. package/lib/codexApps.mjs +17 -3
  19. package/lib/codexToolInputs.mjs +98 -22
  20. package/lib/codingChecks.mjs +8 -4
  21. package/lib/conversationRules.mjs +47 -7
  22. package/lib/detect.mjs +39 -24
  23. package/lib/devserver.mjs +30 -19
  24. package/lib/doctor.mjs +10 -8
  25. package/lib/folderReads.mjs +96 -0
  26. package/lib/followUps.mjs +170 -0
  27. package/lib/hosted.mjs +13 -4
  28. package/lib/init-connect.mjs +29 -10
  29. package/lib/lateResume.mjs +135 -0
  30. package/lib/logindaemon.mjs +129 -49
  31. package/lib/logs.mjs +2 -2
  32. package/lib/mcpjson.mjs +35 -2
  33. package/lib/memberPreview.mjs +22 -14
  34. package/lib/multiwatch.mjs +28 -41
  35. package/lib/pagePictures.mjs +15 -12
  36. package/lib/pageRoutes.mjs +5 -2
  37. package/lib/paths.mjs +3 -3
  38. package/lib/permissionAsk.mjs +344 -61
  39. package/lib/previewGateway.mjs +4 -3
  40. package/lib/procs.mjs +73 -2
  41. package/lib/refusal.mjs +0 -2
  42. package/lib/registry.mjs +7 -7
  43. package/lib/repomap.mjs +4 -3
  44. package/lib/restartPass.mjs +39 -11
  45. package/lib/rowsAnswers.mjs +52 -69
  46. package/lib/rowsEvents.mjs +20 -2
  47. package/lib/runner-health.mjs +29 -5
  48. package/lib/runner.mjs +161 -1347
  49. package/lib/runnerAdmission.mjs +6 -12
  50. package/lib/runnerApi.mjs +20 -11
  51. package/lib/runnerBeat.mjs +384 -0
  52. package/lib/runnerCompletion.mjs +5 -2
  53. package/lib/runnerExecute.mjs +227 -0
  54. package/lib/runnerGates.mjs +338 -0
  55. package/lib/runnerLaunch.mjs +351 -0
  56. package/lib/runnerLease.mjs +31 -9
  57. package/lib/runnerOps.mjs +217 -0
  58. package/lib/runnerPace.mjs +10 -6
  59. package/lib/runnerRecovery.mjs +457 -0
  60. package/lib/runnerRegister.mjs +29 -8
  61. package/lib/runnerSettlement.mjs +43 -16
  62. package/lib/runnerWorkspace.mjs +19 -4
  63. package/lib/spawn.mjs +0 -5
  64. package/lib/sync.mjs +28 -16
  65. package/lib/uninstall-project.mjs +12 -11
  66. package/lib/uninstall.mjs +32 -25
  67. package/lib/update.mjs +4 -4
  68. package/lib/{glytchFolder.mjs → viewableFolder.mjs} +22 -16
  69. package/lib/worktree.mjs +83 -26
  70. package/lib/writePolicy.mjs +90 -10
  71. package/package.json +2 -2
package/lib/agents.mjs CHANGED
@@ -94,6 +94,7 @@ import { PLAN_MODE_AGENTS } from "./spawn.mjs";
94
94
  // SERVER_KEY, so this imports that one spelling rather than adding a fourth
95
95
  // copy of the literal.
96
96
  import { SERVER_KEY } from "./init-connect.mjs";
97
+ import { randomBytes } from "node:crypto";
97
98
 
98
99
  /** What a spawned session may do under Claude Code.
99
100
  *
@@ -165,6 +166,19 @@ export const CLAUDE_TOOLS = [
165
166
  "Bash(grep:*)",
166
167
  ];
167
168
 
169
+ /** Commands that click, type into or look at another app's window (#4204,
170
+ * #4273). Barred for Claude Code so the Mac never asks it for Accessibility or
171
+ * Screen Recording, and so "Allow for this run" (#4105) cannot let them
172
+ * through: a deny rule is checked before any permission prompt. `open -a
173
+ * <App>` is not here and stays allowed. Only a command that STARTS with one of
174
+ * these is caught: `node -e` can still spawn one, which the rule in
175
+ * conversationRules.mjs covers in words only. */
176
+ export const CLAUDE_CLICK_AND_SCREEN_TOOLS = [
177
+ "Bash(osascript:*)",
178
+ "Bash(screencapture:*)",
179
+ "Bash(cliclick:*)",
180
+ ];
181
+
168
182
  /** Tools a headless session must never be OFFERED, because they open an
169
183
  * interactive prompt no one is there to answer.
170
184
  *
@@ -180,7 +194,10 @@ export const CLAUDE_TOOLS = [
180
194
  * terminal nobody is watching. The preamble already points every session at
181
195
  * the board's ask_user instead; taking the dead tool away means the model
182
196
  * reaches for the live one first rather than after a failed call. */
183
- export const CLAUDE_DISALLOWED_TOOLS = ["EnterPlanMode", "AskUserQuestion"];
197
+ export const CLAUDE_DISALLOWED_TOOLS = [
198
+ "EnterPlanMode", "AskUserQuestion",
199
+ ...CLAUDE_CLICK_AND_SCREEN_TOOLS,
200
+ ];
184
201
 
185
202
  /** The two tools that reach the web. Allowed up front only when the person
186
203
  * turned web search on for this run (`webSearch: true` on the spawn request);
@@ -191,8 +208,12 @@ export const CLAUDE_WEB_TOOLS = ["WebSearch", "WebFetch"];
191
208
  /** The allowlist for one run: the standing list, plus the web tools when the
192
209
  * request switched web search on. A plain function of the request, so the
193
210
  * one-shot and streaming command lines cannot disagree. */
194
- export const claudeToolsFor = (wants = {}) =>
195
- wants.webSearch === true ? [...CLAUDE_TOOLS, ...CLAUDE_WEB_TOOLS] : CLAUDE_TOOLS;
211
+ export const claudeToolsFor = (wants = {}) => {
212
+ const tools = wants.boardServerKey
213
+ ? CLAUDE_TOOLS.map(tool => tool === `mcp__${SERVER_KEY}` ? `mcp__${wants.boardServerKey}` : tool)
214
+ : CLAUDE_TOOLS;
215
+ return wants.webSearch === true ? [...tools, ...CLAUDE_WEB_TOOLS] : tools;
216
+ };
196
217
 
197
218
  export const AGENTS = {
198
219
  codex: {
@@ -219,9 +240,7 @@ export const AGENTS = {
219
240
  // itself up with no extra step.
220
241
  needsBoardSetup: false,
221
242
  // --model takes an alias (opus, sonnet) or a full name. There is NO
222
- // effort flag in Claude Code 2.1.34 - checked, not assumed - so an idea
223
- // asking for one gets its model honoured and its effort ignored, and the
224
- // picker does not offer what does not exist.
243
+ // unconditional effort flag: commandFor requires a fresh CLI capability probe.
225
244
  modelFlag: "--model",
226
245
  effortFlag: null,
227
246
  // Claude Code exposes an MCP server's tools under mcp__<server>__<tool>,
@@ -304,7 +323,7 @@ export const AGENTS = {
304
323
  // WHAT THIS ENGINE IS FOR, and it is not "replacing claude". It is the one
305
324
  // engine whose events arrive in a shape the live view of brief 15 wants
306
325
  // without inference: streamed text, tool open and close, an
307
- // auto-answerable permission door, a session that takes a second prompt,
326
+ // permission door the client answers, a session that takes a second prompt,
308
327
  // and a `session/cancel` for Stop. What it costs is the two things this
309
328
  // bridge learned the hard way and acp.mjs re-states: no ceiling to set, and
310
329
  // no dollar figure to report. Every receipt from here says "estimate".
@@ -313,9 +332,9 @@ export const AGENTS = {
313
332
  bin: process.execPath,
314
333
  binEnv: "PM_ACP_NODE_BIN",
315
334
  argsEnv: "PM_ACP_CLAUDE_ARGS",
316
- // The SAME allowlist as `claude`, enforced at a different door: there it
317
- // is `--allowedTools`, here it is the client answering
318
- // session/request_permission from CLAUDE_TOOLS. One list, two doors.
335
+ // The SAME allowlist as `claude`, handed to the adapter's Claude Code as
336
+ // `allowedTools` at session/new; anything off it reaches the client as
337
+ // session/request_permission and goes to the shared asker (#4615).
319
338
  fenced: true,
320
339
  // The board server is passed inline at session/new (acpServersFor), so
321
340
  // there is nothing to write into the worktree.
@@ -532,6 +551,9 @@ export function acpServersFor(agent, { mcpUrl, token, sessionKey, boardId }) {
532
551
  // server of the person's named `glytch_` or `glytch__x`, whose tools would
533
552
  // otherwise read as glytch's; no glytch tool starts with `_` or holds `__`.
534
553
  const TOOL_NAME_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-";
554
+ /** The per-launch board server name (#3612): `v` + five hex characters. */
555
+ export const boardRunKey = () => `v${randomBytes(3).toString("hex").slice(0, 5)}`;
556
+
535
557
  export function appAskRules(keep = `mcp__${SERVER_KEY}__`) {
536
558
  const rules = [];
537
559
  for (let i = "mcp__".length; i < keep.length; i += 1) {
@@ -540,6 +562,17 @@ export function appAskRules(keep = `mcp__${SERVER_KEY}__`) {
540
562
  return [...rules, `${keep}_*`, `${keep}*__*`];
541
563
  }
542
564
 
565
+ /** Claude Code takes its own names (opus, sonnet, haiku, fable, or a full
566
+ * claude-… id), never an OpenRouter id. The Board Agent keeps
567
+ * "anthropic/claude-haiku-5.5" when a person moves it to Claude Code, and
568
+ * `--model` refuses that (#3869). The family alias is the closest name the
569
+ * CLI always knows; any other id passes through unchanged. */
570
+ export function claudeModelName(model) {
571
+ const name = typeof model === "string" ? model.trim() : "";
572
+ const family = /^anthropic\/(?:[^/]*?-)?(fable|opus|sonnet|haiku)(?:-|$)/i.exec(name);
573
+ return family ? family[1].toLowerCase() : name;
574
+ }
575
+
543
576
  export function commandFor(agent, env = process.env, wants = {}) {
544
577
  const spec = AGENTS[agentFor(agent)];
545
578
  const bin = env[spec.binEnv]?.trim() || spec.bin;
@@ -595,8 +628,10 @@ export function commandFor(agent, env = process.env, wants = {}) {
595
628
  "--strict-mcp-config", "--mcp-config", '{"mcpServers":{}}',
596
629
  "--setting-sources", "", "--settings", '{"disableAllHooks":true}',
597
630
  "--disable-slash-commands", "--no-chrome", "--no-session-persistence"];
598
- if (typeof wants.model === "string" && wants.model.trim()) args.push("--model", wants.model.trim());
599
- return { bin, args, spec, ignored: [], acp: null };
631
+ if (typeof wants.model === "string" && wants.model.trim()) args.push("--model", claudeModelName(wants.model));
632
+ const effort = typeof wants.effort === "string" ? wants.effort.trim() : "";
633
+ if (effort && wants.claudeEfforts?.includes(effort)) args.push("--effort", effort);
634
+ return { bin, args, spec, ignored: effort && !wants.claudeEfforts?.includes(effort) ? ["effort (not supported by this model on this computer)"] : [], acp: null };
600
635
  }
601
636
  const raw = env[spec.argsEnv];
602
637
  // STREAMING MODE: when the caller asks for streaming and the engine supports
@@ -605,7 +640,16 @@ export function commandFor(agent, env = process.env, wants = {}) {
605
640
  // the environment can build it - `acp-claude` resolves its adapter's
606
641
  // entrypoint, and PM_ACP_ADAPTER overrides it. Every other engine ignores
607
642
  // the field.
608
- const asked = { ...wants, env };
643
+ // Claude caches OAuth failures by server name even when --mcp-config
644
+ // supplies a working bearer (#3612). A fresh, runner-owned name on each
645
+ // launch cannot inherit the person's connector state or a previous
646
+ // expired bearer. Keep config, allowlist and app ask rules on ONE name.
647
+ // SIX CHARACTERS, like `glytch`: appAskRules grows by 63 rules per
648
+ // character, and a longer name would push the computer-apps --settings
649
+ // past Windows' command-line limit. src/components/run/runWords.ts
650
+ // matches this `v` + five hex shape to read the calls as board work.
651
+ const asked = { ...wants, env, ...(agentFor(agent) === "claude"
652
+ ? { boardServerKey: boardRunKey() } : {}) };
609
653
  let args = asked.streaming && spec.streamingArgs ? spec.streamingArgs(asked) : spec.args(asked);
610
654
  let overridden = false;
611
655
  if (typeof raw === "string" && raw.trim() !== "") {
@@ -629,16 +673,18 @@ export function commandFor(agent, env = process.env, wants = {}) {
629
673
  // wrote their own arguments meant them, and appending to them is guessing.
630
674
  //
631
675
  // An engine with no effort flag DROPS the request rather than approximating
632
- // it. Claude Code 2.1.34 has none, and inventing a flag it does not take
633
- // would fail the whole run over a preference.
676
+ // it. Claude requires local capability evidence before adding --effort;
677
+ // an older CLI must not fail the whole run over a preference.
634
678
  const ignored = [];
635
679
  if (!overridden) {
636
- const model = typeof wants.model === "string" ? wants.model.trim() : "";
680
+ const rawModel = typeof wants.model === "string" ? wants.model.trim() : "";
681
+ const model = agentFor(agent) === "claude" ? claudeModelName(rawModel) : rawModel;
637
682
  if (model !== "" && spec.modelFlag) args = [...args, spec.modelFlag, model];
638
683
  const effort = typeof wants.effort === "string" ? wants.effort.trim() : "";
639
684
  if (effort !== "") {
640
- if (spec.effortFlag) args = [...args, spec.effortFlag, effort];
641
- else if (!spec.protocolEffort) ignored.push(`effort (${spec.label} has no such setting)`);
685
+ if (agentFor(agent) === "claude" && wants.claudeEfforts?.includes(effort)) args = [...args, "--effort", effort];
686
+ else if (spec.effortFlag) args = [...args, spec.effortFlag, effort];
687
+ else if (!spec.protocolEffort) ignored.push(agentFor(agent) === "claude" ? "effort (not supported by this model on this computer)" : `effort (${spec.label} has no such setting)`);
642
688
  }
643
689
  // SESSION PERSISTENCE: resume takes priority over sessionId. Both are
644
690
  // appended AFTER --allowedTools because they are not variadic, and they
@@ -669,10 +715,8 @@ export function commandFor(agent, env = process.env, wants = {}) {
669
715
  // into .mcp.json - `{"mcpServers":{"board":{"type":"http","url":...,
670
716
  // "headers":{...}}}}` - so this is the JSON `--mcp-config` is documented
671
717
  // to accept as a string, run against the real binary rather than assumed.
672
- // RENAMED 2026-09-12 (brief 31, Move 3b): the key WRITTEN below is
673
- // `glytch` (SERVER_KEY), not `board` - the verification above predates
674
- // the rename and is kept dated rather than rerun, since it was checking
675
- // the shape `--mcp-config` accepts, not the key name.
718
+ // The runtime key is launch-specific (#3612); saved connectors retain
719
+ // their names. The shape and authentication headers stay the same.
676
720
  //
677
721
  // --strict-mcp-config makes this the ONLY MCP config the session sees:
678
722
  // any committed .mcp.json (which may still name the retired local
@@ -692,7 +736,7 @@ export function commandFor(agent, env = process.env, wants = {}) {
692
736
  const mcpServers =
693
737
  boardUrl && boardToken
694
738
  ? {
695
- [SERVER_KEY]: {
739
+ [asked.boardServerKey]: {
696
740
  type: "http",
697
741
  url: boardUrl,
698
742
  headers: {
@@ -713,7 +757,7 @@ export function commandFor(agent, env = process.env, wants = {}) {
713
757
  // their own settings before still asks each time; in -p mode that
714
758
  // ask is refused until the permission ask (#478) reaches the person.
715
759
  const apps = wants.computerApps === true
716
- ? ["--settings", JSON.stringify({ permissions: { ask: appAskRules() } })]
760
+ ? ["--settings", JSON.stringify({ permissions: { ask: appAskRules(`mcp__${asked.boardServerKey}__`) } })]
717
761
  : ["--strict-mcp-config"];
718
762
  args = [...args, ...apps, "--mcp-config", JSON.stringify({ mcpServers })];
719
763
  }
@@ -0,0 +1,47 @@
1
+ // THE LEAD'S EXPLICIT ANSWER, read event by event (#3611, #3634).
2
+ //
3
+ // One reader for two places: boardside.mjs reads it out of a finished run's
4
+ // log, and child.mjs reads it as the events stream, so an answer still
5
+ // counts when later tool output pushes it out of the capped log.
6
+
7
+ const ANSWER_TAG = /<viewable-answer>\s*([\s\S]*?)\s*<\/viewable-answer>/g;
8
+
9
+ /** The last non-empty tagged answer in `text`, or "". */
10
+ export function lastAnswerIn(text) {
11
+ let answer = "";
12
+ for (const match of String(text ?? "").matchAll(ANSWER_TAG)) {
13
+ if (match[1].trim()) answer = match[1].trim();
14
+ }
15
+ return answer;
16
+ }
17
+
18
+ /** Fed parsed events in order; `answer()` is the last tagged answer so far.
19
+ * Engines share assistant events (Claude stream-json, normalised Codex/ACP).
20
+ * ACP sends one assistant event per message chunk, so a tag can split across
21
+ * events: consecutive lead text joins into one turn, and any other event
22
+ * (user, tool call, result) ends it. Subagent events are skipped, and a
23
+ * content-less assistant event (ACP usage_update) is neutral. */
24
+ export function makeAnswerTracker() {
25
+ let turn = "";
26
+ let answer = "";
27
+ const endTurn = () => {
28
+ if (turn) answer = lastAnswerIn(turn) || answer;
29
+ turn = "";
30
+ };
31
+ return {
32
+ push(event) {
33
+ if (event?.parent_tool_use_id) return;
34
+ if (event?.type === "assistant" && !Array.isArray(event.message?.content)) return;
35
+ const blocks = event?.type === "assistant" ? event.message.content : null;
36
+ if (!blocks) { endTurn(); return; }
37
+ // Reasoning is neither answer text nor a turn break: an ACP thought
38
+ // can arrive between two chunks of one message (#3644).
39
+ if (blocks.length > 0 && blocks.every(block => block?.type === "thinking")) return;
40
+ turn += blocks.filter(block => block?.type === "text" && typeof block.text === "string").map(block => block.text).join("");
41
+ if (blocks.some(block => block?.type !== "text")) endTurn();
42
+ },
43
+ answer() {
44
+ return lastAnswerIn(turn) || answer;
45
+ },
46
+ };
47
+ }
package/lib/atomic.mjs CHANGED
@@ -24,7 +24,7 @@
24
24
  // filesystem) and carries the pid plus a counter, so two processes writing
25
25
  // the same destination never share a scratch name.
26
26
 
27
- import { link, rename, writeFile, rm } from "node:fs/promises";
27
+ import { rename, writeFile, rm } from "node:fs/promises";
28
28
  import { dirname, join, basename } from "node:path";
29
29
 
30
30
  let seq = 0;
@@ -79,18 +79,3 @@ export async function writeFileAtomic(
79
79
  throw error;
80
80
  }
81
81
  }
82
-
83
- /** Publish a complete file only if the destination does not exist. The link
84
- * reserves the destination atomically across processes; a crash before it
85
- * leaves only an ignored temp file, and a crash after it leaves the full file.
86
- * EEXIST means another publisher already committed this identity. */
87
- export async function writeFileAtomicExclusive(path, data, encoding = "utf8") {
88
- seq += 1;
89
- const tmp = join(dirname(path), `.${basename(path)}.tmp-${process.pid}-${seq}`);
90
- try {
91
- await writeFile(tmp, data, encoding);
92
- await link(tmp, path);
93
- } finally {
94
- await rm(tmp, { force: true }).catch(() => {});
95
- }
96
- }