viewable-one 0.12.2 → 0.12.4

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 (61) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/README.md +2 -2
  3. package/SPAWN.md +107 -53
  4. package/glytch.mjs +49 -12
  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 +80 -45
  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 +52 -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 +33 -12
  42. package/lib/runnerApi.mjs +28 -12
  43. package/lib/runnerBeat.mjs +398 -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 +226 -0
  50. package/lib/runnerPace.mjs +10 -6
  51. package/lib/runnerRecovery.mjs +457 -0
  52. package/lib/runnerRegister.mjs +29 -8
  53. package/lib/runnerSettlement.mjs +29 -9
  54. package/lib/selfUninstall.mjs +239 -0
  55. package/lib/spawn.mjs +0 -5
  56. package/lib/sync.mjs +26 -14
  57. package/lib/update.mjs +184 -0
  58. package/lib/viewableFolder.mjs +8 -2
  59. package/lib/worktree.mjs +66 -13
  60. package/lib/writePolicy.mjs +90 -10
  61. package/package.json +1 -1
@@ -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.4",
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",