viewable-one 0.12.2 → 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 (59) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +2 -2
  3. package/SPAWN.md +107 -53
  4. package/glytch.mjs +41 -10
  5. package/lib/acp.mjs +110 -148
  6. package/lib/admission.mjs +25 -5
  7. package/lib/agents.mjs +59 -16
  8. package/lib/answerTag.mjs +47 -0
  9. package/lib/atomic.mjs +1 -16
  10. package/lib/auth.mjs +25 -9
  11. package/lib/boardside.mjs +28 -12
  12. package/lib/child.mjs +89 -116
  13. package/lib/claudeModels.mjs +168 -0
  14. package/lib/codex-rpc.mjs +2 -2
  15. package/lib/codex.mjs +43 -63
  16. package/lib/codexApps.mjs +5 -3
  17. package/lib/codexToolInputs.mjs +98 -22
  18. package/lib/codingChecks.mjs +8 -4
  19. package/lib/conversationRules.mjs +46 -6
  20. package/lib/detect.mjs +14 -23
  21. package/lib/devserver.mjs +6 -6
  22. package/lib/doctor.mjs +4 -2
  23. package/lib/folderReads.mjs +96 -0
  24. package/lib/followUps.mjs +170 -0
  25. package/lib/hosted.mjs +13 -4
  26. package/lib/init-connect.mjs +29 -10
  27. package/lib/lateResume.mjs +135 -0
  28. package/lib/logindaemon.mjs +113 -33
  29. package/lib/mcpjson.mjs +35 -2
  30. package/lib/multiwatch.mjs +25 -38
  31. package/lib/pagePictures.mjs +14 -11
  32. package/lib/paths.mjs +0 -1
  33. package/lib/permissionAsk.mjs +341 -58
  34. package/lib/procs.mjs +73 -2
  35. package/lib/refusal.mjs +0 -2
  36. package/lib/restartPass.mjs +39 -11
  37. package/lib/rowsAnswers.mjs +18 -34
  38. package/lib/rowsEvents.mjs +20 -2
  39. package/lib/runner-health.mjs +26 -2
  40. package/lib/runner.mjs +106 -1363
  41. package/lib/runnerAdmission.mjs +6 -12
  42. package/lib/runnerApi.mjs +20 -11
  43. package/lib/runnerBeat.mjs +384 -0
  44. package/lib/runnerCompletion.mjs +5 -2
  45. package/lib/runnerExecute.mjs +227 -0
  46. package/lib/runnerGates.mjs +338 -0
  47. package/lib/runnerLaunch.mjs +351 -0
  48. package/lib/runnerLease.mjs +31 -9
  49. package/lib/runnerOps.mjs +217 -0
  50. package/lib/runnerPace.mjs +10 -6
  51. package/lib/runnerRecovery.mjs +457 -0
  52. package/lib/runnerRegister.mjs +28 -7
  53. package/lib/runnerSettlement.mjs +29 -9
  54. package/lib/spawn.mjs +0 -5
  55. package/lib/sync.mjs +26 -14
  56. package/lib/viewableFolder.mjs +8 -2
  57. package/lib/worktree.mjs +66 -13
  58. package/lib/writePolicy.mjs +90 -10
  59. package/package.json +1 -1
package/lib/spawn.mjs CHANGED
@@ -19,11 +19,6 @@ import { SIGN_IN_AGENTS } from "./signIn.mjs";
19
19
  // runner's local scratch lives.
20
20
  export const SPAWN_DIR = join(...segmentsOf(SPAWN_PATH));
21
21
 
22
- /** THE SAME PLACE, SPELLED FOR A PERSON. `SPAWN_DIR` above is `join`ed, so
23
- * on Windows it is `.glytch\inbox\spawn`; this is the `/`-spelled form for
24
- * anything that prints the path to a human. */
25
- export const SPAWN_DIR_IN_WORDS = SPAWN_PATH;
26
-
27
22
  // A session left running all night bills all night, so there is a default and
28
23
  // a hard cap, and the cap is what a request may ask for.
29
24
  //
package/lib/sync.mjs CHANGED
@@ -35,13 +35,14 @@ import { join } from "node:path";
35
35
  import { detectAgents, execProbe } from "./detect.mjs";
36
36
  import {
37
37
  DAEMON_LABEL,
38
- RUNNER_BY_HAND,
38
+ launcherNeedsRepair,
39
+ COMPUTER_REPAIR,
39
40
  daemonPackageVersion,
40
41
  viewableScriptPath,
41
42
  loginDaemon,
42
43
  noDaemonInstall,
43
44
  } from "./logindaemon.mjs";
44
- import { BOARD_MCP_URL, DEFAULT_BOARD_MCP_URL, mergeBoardServer } from "./mcpjson.mjs";
45
+ import { BOARD_MCP_URL, mergeBoardServer } from "./mcpjson.mjs";
45
46
  import { addFolder, readRegistry } from "./registry.mjs";
46
47
  import { readAgentSelection, parseAgentSelection } from "./agent-selection.mjs";
47
48
  import { syncProjectMcp } from "./project-mcp.mjs";
@@ -95,12 +96,12 @@ export async function syncMcpJson(root, { write = true, platform = process.platf
95
96
  ".mcp.json",
96
97
  false,
97
98
  "unreadable",
98
- `${path} exists and is not JSON we can extend. It is someone's work, so nothing was written - open it and add {"mcpServers":{"viewable":{"type":"http","url":"${DEFAULT_BOARD_MCP_URL}"}}} by hand.`,
99
+ `${path} could not be read, so nothing was changed. ${COMPUTER_REPAIR}`,
99
100
  );
100
101
  }
101
102
  if (!write) {
102
103
  return merge.kind === "legacy"
103
- ? row("mcp", ".mcp.json", false, "legacy-command", `${path} still names the retired ${merge.moved ? "board address - run viewable init to move it to app.viewable.one" : "local MCP server - run viewable init to switch it to the hosted board URL"}`)
104
+ ? row("mcp", ".mcp.json", false, "legacy-command", `${path} still uses an old connection. ${COMPUTER_REPAIR}`)
104
105
  : row("mcp", ".mcp.json", false, merge.kind, "missing the Viewable server");
105
106
  }
106
107
  await writeFile(path, merge.text, "utf8");
@@ -152,7 +153,7 @@ export async function syncRegistry(root, { env = process.env, write = true } = {
152
153
  false,
153
154
  "could not write",
154
155
  `~/.glytch/folders.json could not be written: ${why}`,
155
- "Check that ~/.glytch is writable by this account (on Windows, a locked-down or OneDrive-redirected profile can refuse it), then rerun viewable init.",
156
+ COMPUTER_REPAIR,
156
157
  );
157
158
  }
158
159
  return row("registry", "folder registered", true, "added", "added to ~/.glytch/folders.json");
@@ -287,7 +288,7 @@ export async function syncLaunchAgent({
287
288
  // Ruling 6C: an older WSL with no `systemctl --user` is told the truth and
288
289
  // given the fallback, rather than sent to `glytch init` for ever.
289
290
  if (result.unavailable) {
290
- return row("plist", label, true, "no systemd here", `wrote ${result.file}; systemctl --user is not available - run: ${RUNNER_BY_HAND}`);
291
+ return row("plist", label, true, "no systemd here", `wrote ${result.file}; the background connection is unavailable. ${COMPUTER_REPAIR}`);
291
292
  }
292
293
  return row(
293
294
  "plist",
@@ -317,6 +318,13 @@ export async function syncLaunchAgent({
317
318
  // unloaded branch is: the running daemon's own multiwatch loop must never
318
319
  // unload itself mid-sync, so it leaves this repair to `init` and `doctor`,
319
320
  // which both pass daemon:false.
321
+ const brokenLauncher = await launcherNeedsRepair(text, { env, impl });
322
+ if (daemon && brokenLauncher && write) {
323
+ const result = await impl.install({ env, ...call, path: mergePaths(captured, path, impl.pathDelimiter),
324
+ nodePath, scriptPath: impl.programScriptPath(text) ?? scriptPath, force: true, load: false });
325
+ if (!skipped && result.reloaded === false) return row("plist", label, false, "launcher not reloaded", result.why);
326
+ return row("plist", label, true, "launcher repaired", "Your computer will reconnect automatically on its next start.");
327
+ }
320
328
  if (!daemon) {
321
329
  const currentScriptPath = scriptPath ?? viewableScriptPath();
322
330
  const mismatch = await scriptMismatch({
@@ -324,7 +332,7 @@ export async function syncLaunchAgent({
324
332
  currentScriptPath,
325
333
  currentVersion: version,
326
334
  });
327
- if (mismatch || restart || replaceLoadedVersion) {
335
+ if (mismatch || restart || replaceLoadedVersion || brokenLauncher) {
328
336
  const change = mismatch ?? { oldPath: impl.programScriptPath(text), newPath: currentScriptPath, oldVersion: health?.version ?? null, newVersion: version };
329
337
  const oldVersionText = change.oldVersion ?? "unknown";
330
338
  if (!write) {
@@ -332,8 +340,8 @@ export async function syncLaunchAgent({
332
340
  "plist",
333
341
  label,
334
342
  false,
335
- "different script",
336
- `${file} runs ${change.oldPath} (${oldVersionText}); this install is ${change.newPath} (${change.newVersion})`,
343
+ brokenLauncher ? "broken launcher" : "different script",
344
+ brokenLauncher ? "The background connection needs repair." : `${file} runs ${change.oldPath} (${oldVersionText}); this install is ${change.newPath} (${change.newVersion})`,
337
345
  );
338
346
  }
339
347
  const merged = mergePaths(captured, path, impl.pathDelimiter);
@@ -348,7 +356,7 @@ export async function syncLaunchAgent({
348
356
  );
349
357
  }
350
358
  if (result.unavailable) {
351
- return row("plist", label, true, "no systemd here", `rewrote ${result.file}; systemctl --user is not available - run: ${RUNNER_BY_HAND}`);
359
+ return row("plist", label, true, "no systemd here", `rewrote ${result.file}; the background connection is unavailable. ${COMPUTER_REPAIR}`);
352
360
  }
353
361
  return row(
354
362
  "plist",
@@ -382,7 +390,7 @@ export async function syncLaunchAgent({
382
390
  return row("plist", label, false, "present, cannot be checked", `${file} is on disk; ${impl.tool} refused: ${state.why}`, state.action);
383
391
  }
384
392
  if (state.unavailable) {
385
- return row("plist", label, true, "no systemd here", `${file} is on disk; systemctl --user is not available - run: ${RUNNER_BY_HAND}`);
393
+ return row("plist", label, true, "no systemd here", `${file} is on disk; the background connection is unavailable. ${COMPUTER_REPAIR}`);
386
394
  }
387
395
  if (!write) {
388
396
  return row(
@@ -390,7 +398,7 @@ export async function syncLaunchAgent({
390
398
  label,
391
399
  false,
392
400
  "present, not loaded",
393
- `${file} is on disk but ${impl.holder} is not holding ${DAEMON_LABEL} - run: viewable init`,
401
+ `${file} is on disk but ${impl.holder} is not holding ${DAEMON_LABEL}. ${COMPUTER_REPAIR}`,
394
402
  );
395
403
  }
396
404
  const result = await impl.install({ env, ...call, path, nodePath, scriptPath, load: true });
@@ -411,12 +419,16 @@ export async function syncLaunchAgent({
411
419
  if (!write) {
412
420
  return row("plist", label, false, "stale PATH", "the captured PATH is missing entries this shell has");
413
421
  }
414
- const result = await impl.install({ env, ...call, path: merged, nodePath, scriptPath, force: true });
422
+ const result = await impl.install({ env, ...call, path: merged, nodePath, scriptPath, force: true, load: !daemon });
415
423
  if (skipped) {
416
424
  return row("plist", label, true, "PATH refreshed, not loaded", `rewrote ${result.file}; ${escape} is set, so ${impl.tool} was not run`);
417
425
  }
418
426
  if (result.unavailable) {
419
- return row("plist", label, true, "no systemd here", `rewrote ${result.file}; systemctl --user is not available - run: ${RUNNER_BY_HAND}`);
427
+ return row("plist", label, true, "no systemd here", `rewrote ${result.file}; the background connection is unavailable. ${COMPUTER_REPAIR}`);
428
+ }
429
+ if (daemon) {
430
+ if (result.reloaded === false) return row("plist", label, false, "PATH not reloaded", result.why);
431
+ return row("plist", label, true, "PATH refreshed on next start", "Your computer will use the updated connection on its next start.");
420
432
  }
421
433
  return row(
422
434
  "plist",
@@ -1,5 +1,7 @@
1
1
  // THE DEFAULT WORKING FOLDER. ~/.glytch remains the runner's private state.
2
- // Fresh installs use ~/Viewable; an existing ~/Glytch stays accessible in place.
2
+ // A fresh install uses Documents/Viewable (ruling #2884, the same folder
3
+ // public/setup-mac-linux.sh makes), creating Documents if needed.
4
+ // An existing ~/Viewable or ~/Glytch stays accessible in place.
3
5
  // The visible folder is a git repository, registered like any linked folder.
4
6
  // A chat with no folder picked works in a subfolder named after the board.
5
7
  // No existing folder is moved or rewritten by the rename (#2329).
@@ -23,9 +25,13 @@ export function viewableFolderPath(env = process.env, home = homedir()) {
23
25
  if (named === "off") return null;
24
26
  if (named) return resolve(named);
25
27
  if ((env.VIEWABLE_HOME ?? env.GLYTCH_HOME)?.trim()) return null;
28
+ const documents = join(home, "Documents", "Viewable");
26
29
  const current = join(home, "Viewable");
27
30
  const legacy = join(home, "Glytch");
28
- return existsSync(current) || !existsSync(legacy) ? current : legacy;
31
+ if (existsSync(documents)) return documents;
32
+ if (existsSync(current)) return current;
33
+ if (existsSync(legacy)) return legacy;
34
+ return documents;
29
35
  }
30
36
 
31
37
  const README =
package/lib/worktree.mjs CHANGED
@@ -620,10 +620,10 @@ async function cleanWorktreeImpl(root, made, log = () => {}, wroteFiles = []) {
620
620
  if (!(await registeredWorktree(root, made.path))) return { removed: false, detail: "KEPT: worktree ownership could not be verified." };
621
621
 
622
622
  const dirty = await git(["status", "--porcelain"], made.path);
623
- const base = await git(["merge-base", made.branch, "HEAD"], root);
624
- const commits = base.ok && base.stdout.trim()
625
- ? await git(["log", "--oneline", `${base.stdout.trim()}..HEAD`], made.path)
626
- : { ok: false, detail: base.detail || "Could not establish the worktree base." };
623
+ const start = await startOf(made.branch, root);
624
+ const commits = start
625
+ ? await git(["log", "--oneline", `${start}..HEAD`], made.path)
626
+ : { ok: false, detail: "Could not establish the worktree base." };
627
627
  // Failed inspection is not evidence that this tree contains no work.
628
628
  if (!dirty.ok || !commits.ok) {
629
629
  const detail = `KEPT: could not verify worktree changes: ${!dirty.ok ? dirty.detail : commits.detail}`;
@@ -761,10 +761,23 @@ async function reuseWorktreeImpl(root, existingPath, log = () => {}) {
761
761
  };
762
762
  }
763
763
 
764
+ /** The commit the worktree was cut from, or null when git cannot say.
765
+ *
766
+ * Against the repo's default branch, the ref every worktree is cut from
767
+ * (makeWorktreeImpl), never the folder's current HEAD: the folder's HEAD can
768
+ * be a detached commit far from where the run started, and the merge-base
769
+ * with it reached back past the run's start, so a run that changed nothing
770
+ * reported "Changed 270 files" (#3894). HEAD is the fallback only when
771
+ * neither main nor master exists. */
772
+ async function startOf(branch, root) {
773
+ const defaultBranch = await defaultBranchOf(root);
774
+ const merge = await git(["merge-base", branch, defaultBranch ?? "HEAD"], root);
775
+ return merge.ok && merge.stdout.trim() ? merge.stdout.trim() : null;
776
+ }
777
+
764
778
  /** The commit the worktree started from, for counting what the session added. */
765
779
  async function baseOf(made, root) {
766
- const merge = await git(["merge-base", made.branch, "HEAD"], root);
767
- return merge.ok && merge.stdout.trim() ? merge.stdout.trim() : "HEAD";
780
+ return (await startOf(made.branch, root)) ?? "HEAD";
768
781
  }
769
782
 
770
783
  // ---------- post-session worktree operations ----------
@@ -886,10 +899,13 @@ async function mergeWorktreeImpl(root, worktreePath, log = () => {}) {
886
899
  // record produces a deletion commit too.
887
900
  const untrack = await git(["rm", "--cached", "--force", "--ignore-unmatch", "--", ".viewable-server.json", ".viewable-page.json", ".glytch-server.json", ".glytch-page.json"], worktreePath);
888
901
  if (!untrack.ok) return { ok: false, detail: `Could not commit what the session left: ${untrack.detail}` };
889
- const leftovers = await git(["status", "--porcelain"], worktreePath);
902
+ const leftovers = await git(["status", "--porcelain", "-z", "--untracked-files=all"], worktreePath);
890
903
  if (!leftovers.ok) return { ok: false, detail: `Could not read the copy: ${leftovers.detail}` };
891
904
  if (leftovers.stdout.trim() !== "") {
892
- const add = await git(["add", "-A", "--", ".", ":(exclude)node_modules", ":(top,exclude,glob)[.]viewable-server.json", ":(top,exclude,glob)[.]viewable-page.json", ":(top,exclude,glob)[.]glytch-server.json", ":(top,exclude,glob)[.]glytch-page.json"], worktreePath);
905
+ // The same cache exclusion the "Changed N files" count uses (#3894), so Keep
906
+ // never commits what the screen did not count.
907
+ const cacheExcludes = cachePathspecs(statusEntries(leftovers.stdout));
908
+ const add = await git(["add", "-A", "--", ".", ":(exclude)node_modules", ...cacheExcludes, ":(top,exclude,glob)[.]viewable-server.json", ":(top,exclude,glob)[.]viewable-page.json", ":(top,exclude,glob)[.]glytch-server.json", ":(top,exclude,glob)[.]glytch-page.json"], worktreePath);
893
909
  const staged = add.ok ? await git(["diff", "--cached", "--quiet"], worktreePath) : add;
894
910
  if (!add.ok) return { ok: false, detail: `Could not commit what the session left: ${add.detail}` };
895
911
  if (staged.code === 1) {
@@ -1096,16 +1112,53 @@ export async function changedFiles(worktreePath, root) {
1096
1112
  async function uncommittedFiles(worktreePath) {
1097
1113
  const status = await git(["status", "--porcelain", "-z", "--untracked-files=all"], worktreePath);
1098
1114
  if (!status.ok) return [];
1099
- const parts = status.stdout.split("\0");
1100
- const paths = [];
1115
+ return statusEntries(status.stdout)
1116
+ .filter((e) => e.path !== "node_modules" && !isUntrackedCache(e))
1117
+ .map((e) => e.path);
1118
+ }
1119
+
1120
+ /** `git status --porcelain -z` as { code, path } entries. A rename or copy is
1121
+ * followed by its old path, which is not a second file. */
1122
+ function statusEntries(stdout) {
1123
+ const parts = stdout.split("\0");
1124
+ const entries = [];
1101
1125
  for (let i = 0; i < parts.length; i++) {
1102
1126
  const entry = parts[i];
1103
1127
  if (entry.length < 4) continue;
1104
- paths.push(entry.slice(3));
1105
- // A rename or copy is followed by its old path, which is not a second file.
1128
+ entries.push({ code: entry.slice(0, 2), path: entry.slice(3) });
1106
1129
  if (entry[0] === "R" || entry[0] === "C") i++;
1107
1130
  }
1108
- return paths.filter((p) => p !== "node_modules");
1131
+ return entries;
1132
+ }
1133
+
1134
+ /** Folders a download or a tool fills on its own: Python environments and
1135
+ * caches, package caches, notebook checkpoints. Untracked files in them are
1136
+ * not the session's changes, so they neither count toward "Changed N files"
1137
+ * nor go into Keep's commit (#3894). One list, one rule, for both. A file git
1138
+ * already tracks there is the session's, whatever the folder is called. */
1139
+ const CACHE_DIRS = new Set([
1140
+ ".venv", "venv", "__pycache__", ".cache", ".npm", ".pnpm-store", ".yarn",
1141
+ ".pytest_cache", ".mypy_cache", ".ruff_cache", ".ipynb_checkpoints", ".tox",
1142
+ "site-packages", "node_modules",
1143
+ ]);
1144
+ const isCachePath = (path) =>
1145
+ path.split("/").some((part, i, parts) => (i < parts.length - 1 && CACHE_DIRS.has(part)) || part === ".DS_Store");
1146
+ const isUntrackedCache = (entry) => entry.code === "??" && isCachePath(entry.path);
1147
+
1148
+ /** Pathspecs that keep `git add -A` away from the untracked cache files: one
1149
+ * per cache folder, or per file when git tracks a changed file inside that
1150
+ * folder (a folder exclude would hide that change too). */
1151
+ function cachePathspecs(entries) {
1152
+ const tracked = entries.filter((e) => e.code !== "??").map((e) => e.path);
1153
+ const specs = new Set();
1154
+ for (const entry of entries.filter(isUntrackedCache)) {
1155
+ const parts = entry.path.split("/");
1156
+ const at = parts.findIndex((part, i) => i < parts.length - 1 && CACHE_DIRS.has(part));
1157
+ const folder = at === -1 ? null : parts.slice(0, at + 1).join("/");
1158
+ const shared = folder !== null && tracked.some((t) => t.startsWith(`${folder}/`));
1159
+ specs.add(`:(top,exclude,literal)${folder === null || shared ? entry.path : folder}`);
1160
+ }
1161
+ return [...specs];
1109
1162
  }
1110
1163
 
1111
1164
  // LOCKED WRAPPERS for the five mutation functions. Git mutations on the same
@@ -7,21 +7,94 @@
7
7
  // no value imports of its own, so this is its transpile and nothing else: the
8
8
  // rule is written once, where it belongs, and both the app and this function
9
9
  // read the same one.
10
- export function writeRisk(provider, name, args = {}) {
11
- const words = `${name.replace(/([a-z])([A-Z])/g, "$1_$2")} ${String(args.method ?? args.action ?? args.command ?? "")}`.toLowerCase();
12
- if (provider === "stripe" || /refund|payment|charge|transfer|payout|invoice|subscription/.test(words))
10
+ // What a call does, read from its own words: the tool's name and every
11
+ // action it is given; the strictest verb in each decides it (verbOf below).
12
+ // A tool's own label is a claim, never a grant (#5111): it only adds an ask.
13
+ const READS = new Set(["get", "list", "search", "find", "fetch", "read", "query", "retrieve", "lookup", "describe", "view", "show", "count", "explore", "inspect", "preview", "browse"]);
14
+ // A plain create or edit: Always allow may cover it when the tool also says
15
+ // it is a write that is not destructive.
16
+ const PLAIN = new Set(["create", "add", "new", "update", "edit", "modify", "change", "insert", "append", "save", "set", "write", "put", "patch", "upsert",
17
+ "comment", "reply", "assign", "unassign", "rename", "label", "tag", "attach", "link", "unlink", "mark", "close", "reopen", "resolve", "complete", "transition",
18
+ "copy", "duplicate", "clone", "upload", "star", "unstar", "pin", "unpin", "react", "follow", "unfollow", "subscribe", "unsubscribe"]);
19
+ // Every other change: never a read, never covered by Always allow.
20
+ const CHANGES = new Set(["delete", "remove", "destroy", "erase", "send", "post", "publish", "merge", "deploy", "archive", "trash", "cancel", "refund", "charge", "pay",
21
+ "transfer", "invite", "share", "execute", "exec", "run", "invoke", "apply", "submit", "approve", "revoke", "grant", "enable", "disable", "start", "stop", "restart",
22
+ "trigger", "lock", "unlock", "install", "uninstall", "push", "fork", "move", "schedule", "buy", "purchase", "sell", "withdraw", "deposit", "void", "capture",
23
+ "finalize", "sync", "reset", "clear", "purge", "wipe", "drop", "truncate", "overwrite", "block", "unblock", "ban", "kick", "mutate", "import", "replace",
24
+ "dismiss", "convert", "restore", "accept", "decline", "reject", "generate", "make", "detach"]);
25
+ const STRICTNESS = ["change", "plain", "read"];
26
+ /** The strictest verb across every word of one text: a change anywhere wins,
27
+ * then a plain change, then a read ("get_or_create_board" is plain,
28
+ * "list_item_delete" a change). No verb at all is unknown. */
29
+ function verbOf(text) {
30
+ const words = new Set(text.replace(/([a-z0-9])([A-Z])/g, "$1 $2").toLowerCase().split(/[^a-z0-9]+/));
31
+ const found = new Set();
32
+ for (const word of words) {
33
+ if (CHANGES.has(word))
34
+ found.add("change");
35
+ else if (PLAIN.has(word))
36
+ found.add("plain");
37
+ else if (READS.has(word))
38
+ found.add("read");
39
+ }
40
+ return STRICTNESS.find((verb) => found.has(verb)) ?? "unknown";
41
+ }
42
+ // The words writeRisk reads as a risk.
43
+ const MONEY = /refund|payment|charge|transfer|payout|invoice|subscription/;
44
+ const SENDING = /send|email|message|slack.*post/;
45
+ const DELETING = /delet|remov|destroy|archive|cancel|\breplace_content\b/;
46
+ const PUBLISHING = /publish|release/;
47
+ const MERGING = /merge/;
48
+ const DEPLOYING = /deploy/;
49
+ /** Every action a call is given: each of method, action, command and
50
+ * operation, never just the first one set (#5111). */
51
+ function actionTexts(args) {
52
+ return [args.method, args.action, args.command, args.operation].filter((value) => typeof value === "string");
53
+ }
54
+ /** What each of the call's texts (its name, then every action) does. */
55
+ function callVerbs(name, args) {
56
+ return [name, ...actionTexts(args)].map(verbOf);
57
+ }
58
+ /** Whether this call only reads, so it runs with no ask. Only a tool that
59
+ * labels itself read-only can (MCP readOnlyHint; absent means "may write"),
60
+ * and the label never wins over what the call says it does: a name or
61
+ * action that names a change, a destructive flag, or an archive or trash
62
+ * flag makes it a write that asks like any other (#5111). Generic: no app
63
+ * is named (#4419). */
64
+ export function readsOnly(name, args = {}, hints) {
65
+ if (hints?.readOnlyHint !== true || hints.destructiveHint === true)
66
+ return false;
67
+ if (args.archived === true || args.in_trash === true)
68
+ return false;
69
+ return !callVerbs(name, args).some((verb) => verb !== "read");
70
+ }
71
+ export function writeRisk(provider, name, args = {}, hints) {
72
+ const words = `${name.replace(/([a-z])([A-Z])/g, "$1_$2")} ${actionTexts(args).join(" ")}`.toLowerCase();
73
+ if (provider === "stripe" || MONEY.test(words))
13
74
  return "money";
14
- if (/send|email|message|slack.*post/.test(words))
75
+ if (SENDING.test(words))
15
76
  return "sending";
16
- if (args.archived === true || args.in_trash === true || /delet|remov|destroy|archive|cancel|\breplace_content\b/.test(words))
77
+ if (args.archived === true || args.in_trash === true || DELETING.test(words))
17
78
  return "deleting";
18
- if (/publish|release/.test(words))
79
+ // The tool's own destructive flag adds an ask every time (Allow and Not
80
+ // this only), in any app. Its own flag is not "deleting": a create tool
81
+ // may carry it (#4571). A tool with no hints stays open-ended below (#4436).
82
+ if (hints?.destructiveHint === true)
83
+ return "destructive";
84
+ if (PUBLISHING.test(words))
19
85
  return "publishing";
20
- if (/merge/.test(words))
86
+ if (MERGING.test(words))
21
87
  return "merging";
22
- if (/deploy/.test(words))
88
+ if (DEPLOYING.test(words))
23
89
  return "deploying";
24
- // An explicit, small allowlist. A new tool is open-ended until reviewed.
90
+ // A write that says it is not destructive is ordinary only when its own
91
+ // words name a plain create or edit: the label alone never lets Always
92
+ // allow skip the ask (#5111).
93
+ if (hints?.readOnlyHint === false && hints.destructiveHint === false) {
94
+ if (callVerbs(name, args).every((verb) => verb === "plain"))
95
+ return null;
96
+ }
97
+ // A small reviewed list. Any other is open-ended.
25
98
  if (provider === "linear" && ["create_issue", "update_issue", "save_issue"].includes(name))
26
99
  return null;
27
100
  if (provider === "notion" && ["notion-create-pages", "create_pages"].includes(name))
@@ -35,11 +108,18 @@ export function writeRisk(provider, name, args = {}) {
35
108
  return null;
36
109
  return "open-ended";
37
110
  }
111
+ /** The one line under the ask that says why it asks every time, or "" when
112
+ * there is no plainer reason than the ask's own "Asks every time": a tool
113
+ * that only flags itself destructive names no act of its own (#4571). */
38
114
  export function riskReason(risk) {
39
115
  if (risk === "money")
40
116
  return "Money moves, so this asks every time.";
117
+ if (risk === "destructive")
118
+ return "";
41
119
  return `${risk === "open-ended" ? "Open-ended tools ask" : risk[0].toUpperCase() + risk.slice(1) + " asks"} every time.`;
42
120
  }
121
+ /** Every connected app may write, after the same approval; what asks every
122
+ * time comes from writeRisk (#4436). */
43
123
  export function writesSupported(provider) {
44
- return ["notion", "linear", "github", "jira", "atlassian", "sentry", "stripe"].includes(provider);
124
+ return provider.trim() !== "";
45
125
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "viewable-one",
3
- "version": "0.12.2",
3
+ "version": "0.12.3",
4
4
  "description": "Run coding agents from the Viewable board. Connects your machine to app.viewable.one, launches a session in its own worktree when you press Run, and streams what it does back to the canvas.",
5
5
  "keywords": [
6
6
  "mcp",