synabun 2.4.4 → 2.4.6

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 (129) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +1 -1
  3. package/docs/browser-extension-bridge.md +5 -4
  4. package/docs/whatsapp.md +19 -3
  5. package/hooks/claude-code/session-start.mjs +21 -18
  6. package/lib/claude-global-config.js +214 -0
  7. package/lib/client-config-repair.js +17 -3
  8. package/mcp-server/dist/index.d.ts.map +1 -1
  9. package/mcp-server/dist/index.js +6 -1
  10. package/mcp-server/dist/index.js.map +1 -1
  11. package/mcp-server/dist/services/neural-interface.d.ts +1 -0
  12. package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
  13. package/mcp-server/dist/services/neural-interface.js +1 -0
  14. package/mcp-server/dist/services/neural-interface.js.map +1 -1
  15. package/mcp-server/dist/services/tool-catalog.js +1 -1
  16. package/mcp-server/dist/services/tool-catalog.js.map +1 -1
  17. package/mcp-server/dist/tools/agents.d.ts +18 -3
  18. package/mcp-server/dist/tools/agents.d.ts.map +1 -1
  19. package/mcp-server/dist/tools/agents.js +85 -16
  20. package/mcp-server/dist/tools/agents.js.map +1 -1
  21. package/mcp-server/dist/tools/skill-tools.d.ts +24 -5
  22. package/mcp-server/dist/tools/skill-tools.d.ts.map +1 -1
  23. package/mcp-server/dist/tools/skill-tools.js +88 -8
  24. package/mcp-server/dist/tools/skill-tools.js.map +1 -1
  25. package/mcp-server/dist/tools/tool-groups.d.ts.map +1 -1
  26. package/mcp-server/dist/tools/tool-groups.js +19 -4
  27. package/mcp-server/dist/tools/tool-groups.js.map +1 -1
  28. package/mcp-server/package-lock.json +2 -2
  29. package/mcp-server/package.json +1 -1
  30. package/mcp-server/src/index.ts +6 -1
  31. package/mcp-server/src/services/neural-interface.ts +2 -1
  32. package/mcp-server/src/services/tool-catalog.ts +1 -1
  33. package/mcp-server/src/tools/agents.ts +78 -16
  34. package/mcp-server/src/tools/skill-tools.ts +82 -9
  35. package/mcp-server/src/tools/tool-groups.ts +19 -4
  36. package/neural-interface/i18n/en.json +484 -19
  37. package/neural-interface/i18n/pt-BR.json +484 -19
  38. package/neural-interface/lib/agents-studio-api.js +7 -2
  39. package/neural-interface/lib/antigravity/home.js +43 -8
  40. package/neural-interface/lib/antigravity/panel-bridge.js +7 -3
  41. package/neural-interface/lib/antigravity/tool-call.js +14 -0
  42. package/neural-interface/lib/assistant-brains/antigravity.js +4 -2
  43. package/neural-interface/lib/assistant-dispatch.js +15 -1
  44. package/neural-interface/lib/assistant-persona.js +8 -3
  45. package/neural-interface/lib/assistant-route-gate.js +11 -2
  46. package/neural-interface/lib/assistant-runtime.js +95 -13
  47. package/neural-interface/lib/assistant-spilled-output.js +53 -0
  48. package/neural-interface/lib/assistant-user-context.js +7 -3
  49. package/neural-interface/lib/browser-default.js +22 -2
  50. package/neural-interface/lib/browser-extension-bridge.js +50 -3
  51. package/neural-interface/lib/browser-extension-pin.json +7 -7
  52. package/neural-interface/lib/browser-extension-protocol.js +30 -1
  53. package/neural-interface/lib/browser-extension-setup.js +204 -36
  54. package/neural-interface/lib/claude-agent-bridge.js +13 -2
  55. package/neural-interface/lib/codex-thread-history.js +144 -7
  56. package/neural-interface/lib/codex-worker-app-server.js +84 -30
  57. package/neural-interface/lib/db.js +26 -0
  58. package/neural-interface/lib/greeting/sources.js +7 -3
  59. package/neural-interface/lib/jsonl-lines.js +10 -11
  60. package/neural-interface/lib/line-buffer.js +88 -0
  61. package/neural-interface/lib/loop-stall.js +15 -1
  62. package/neural-interface/lib/memory-list-read.js +105 -0
  63. package/neural-interface/lib/memory-timers.js +4 -1
  64. package/neural-interface/lib/native-loop-runtime.js +7 -3
  65. package/neural-interface/lib/provider-panel-api-key-auth.js +33 -6
  66. package/neural-interface/lib/remote-policy.js +24 -7
  67. package/neural-interface/lib/skills/api-v2.js +18 -3
  68. package/neural-interface/lib/skills/bundle.js +2 -2
  69. package/neural-interface/lib/skills/deploy.js +169 -34
  70. package/neural-interface/lib/skills/digest.js +57 -3
  71. package/neural-interface/lib/skills/health.js +55 -1
  72. package/neural-interface/lib/skills/known-bridge-digests.json +12 -0
  73. package/neural-interface/lib/skills/runtime-checks.js +7 -4
  74. package/neural-interface/lib/skills/scan-shell.js +56 -7
  75. package/neural-interface/lib/skills/scan.js +13 -12
  76. package/neural-interface/lib/skills/service.js +7 -2
  77. package/neural-interface/lib/skills/telemetry.js +2 -2
  78. package/neural-interface/lib/teams/README.md +34 -6
  79. package/neural-interface/lib/teams/api.js +94 -10
  80. package/neural-interface/lib/teams/index.js +4 -0
  81. package/neural-interface/lib/teams/landing.js +195 -75
  82. package/neural-interface/lib/teams/recovery.js +68 -0
  83. package/neural-interface/lib/teams/scheduler.js +380 -61
  84. package/neural-interface/lib/teams/worktrees.js +123 -30
  85. package/neural-interface/lib/terminal-token-redaction.js +228 -58
  86. package/neural-interface/lib/terminal-tokens.js +18 -0
  87. package/neural-interface/lib/whatsapp/brain.js +21 -0
  88. package/neural-interface/lib/whatsapp/bridge.js +40 -4
  89. package/neural-interface/package-lock.json +2 -2
  90. package/neural-interface/package.json +1 -1
  91. package/neural-interface/public/extension-setup.html +6 -2
  92. package/neural-interface/public/index.html +117 -37
  93. package/neural-interface/public/shared/agents/studio/ax-api.js +27 -0
  94. package/neural-interface/public/shared/agents/studio/ax-create-view.js +1 -1
  95. package/neural-interface/public/shared/agents/studio/ax-icons.js +1 -0
  96. package/neural-interface/public/shared/agents/studio/ax-library-view.js +3 -2
  97. package/neural-interface/public/shared/agents/studio/ax-main.js +127 -41
  98. package/neural-interface/public/shared/agents/studio/ax-review-view.js +3 -2
  99. package/neural-interface/public/shared/agents/studio/ax-teams-view.js +436 -33
  100. package/neural-interface/public/shared/agents/studio/ax-teams.js +357 -10
  101. package/neural-interface/public/shared/agents/studio/ax-ui.js +31 -0
  102. package/neural-interface/public/shared/agents/studio/ax-views.js +67 -69
  103. package/neural-interface/public/shared/agents/studio/ax-work-answer.js +86 -0
  104. package/neural-interface/public/shared/agents/studio/ax-work-view.js +305 -0
  105. package/neural-interface/public/shared/agents/studio/ax-work.css +74 -0
  106. package/neural-interface/public/shared/agents/studio/ax-work.js +300 -0
  107. package/neural-interface/public/shared/browser-extension-updates.js +3 -1
  108. package/neural-interface/public/shared/cdx/cdx-deferred.js +90 -0
  109. package/neural-interface/public/shared/cdx/cdx-render.js +18 -7
  110. package/neural-interface/public/shared/cdx/cdx-tabs.js +2 -1
  111. package/neural-interface/public/shared/extension-setup/es-page.js +23 -4
  112. package/neural-interface/public/shared/extension-setup/es-view.js +51 -11
  113. package/neural-interface/public/shared/extension-update-view.js +1 -1
  114. package/neural-interface/public/shared/loading-diagnostic-entry.js +16 -1
  115. package/neural-interface/public/shared/settings/settings-ai-browser.js +23 -3
  116. package/neural-interface/public/shared/settings/settings-browser-extension.js +575 -197
  117. package/neural-interface/public/shared/settings/settings-extension-diagrams.js +116 -0
  118. package/neural-interface/public/shared/settings/settings-extension-guide.js +222 -0
  119. package/neural-interface/public/shared/settings/settings-ia.js +2 -2
  120. package/neural-interface/public/shared/settings/settings-shell.js +5 -0
  121. package/neural-interface/public/shared/skills/studio/sx-operations-view.js +5 -0
  122. package/neural-interface/public/shared/skills/studio/sx-plan.js +42 -3
  123. package/neural-interface/public/shared/skills/studio/sx-publish-view.js +20 -4
  124. package/neural-interface/public/shared/styles.css +196 -13
  125. package/neural-interface/public/shared/ui-settings.js +48 -11
  126. package/neural-interface/server.js +336 -253
  127. package/npm-shrinkwrap.json +2 -2
  128. package/package.json +2 -1
  129. package/skills/skill-forge/SKILL.md +7 -3
@@ -1,4 +1,48 @@
1
1
  // Literal shell dataflow only. Tokens are never expanded or executed.
2
+
3
+ // Word edges of every script. JavaScript's \b knows only [A-Za-z0-9_] as word characters, so it reads "irm" in
4
+ // the Portuguese "irmã", or "node" in "nodeção", as a whole word. unicodeWords(re) keeps re's matches whose
5
+ // every \b (outside a character class, where \b is a backspace) is also an edge over letters, marks, digits and
6
+ // "_" of any script, and drops the others: it never matches where re did not. A letter of a script written
7
+ // without spaces between words, or whose particles attach to a borrowed word, still ends a word: "用curl下载",
8
+ // "curlで", "curl로" and "ใช้curl" name curl, as they did before.
9
+ const SPACELESS = String.raw`\p{scx=Han}\p{scx=Hira}\p{scx=Kana}\p{scx=Bopo}\p{scx=Hang}\p{scx=Thai}\p{scx=Laoo}\p{scx=Khmr}\p{scx=Mymr}`;
10
+ const WORD_CHAR = String.raw`(?:(?![${SPACELESS}])[\p{L}\p{M}\p{N}_])`;
11
+ const WORD_EDGE = `(?:(?<!${WORD_CHAR})(?=${WORD_CHAR})|(?<=${WORD_CHAR})(?!${WORD_CHAR}))`;
12
+ class UnicodeWordRegExp extends RegExp {
13
+ #ascii; #edges;
14
+ static get [Symbol.species]() { return RegExp; }
15
+ constructor(re, source) {
16
+ super(source, `${re.flags}u`);
17
+ this.#ascii = new RegExp(re.source, `${re.flags}g`);
18
+ this.#edges = new RegExp(source, `${re.flags}uy`);
19
+ }
20
+ // The edge pattern is tried only where the ASCII one matches: the cheap scan finds the candidates, and a
21
+ // match of the u-flag pattern alone (its Unicode case folding, a letter after a "/") is never added.
22
+ exec(input) {
23
+ const text = String(input);
24
+ this.#ascii.lastIndex = 0;
25
+ for (let m; (m = this.#ascii.exec(text));) {
26
+ this.#edges.lastIndex = m.index;
27
+ const hit = this.#edges.exec(text);
28
+ if (hit) return hit;
29
+ this.#ascii.lastIndex = m.index + 1;
30
+ }
31
+ return null;
32
+ }
33
+ }
34
+ export function unicodeWords(re) {
35
+ if (/[guyv]/.test(re.flags)) throw new TypeError(`unicodeWords: flags ${re.flags} are not supported`);
36
+ let source = '', inClass = false;
37
+ for (let i = 0; i < re.source.length; i++) {
38
+ const c = re.source[i];
39
+ if (c === '\\') { const next = re.source[++i]; source += !inClass && next === 'b' ? WORD_EDGE : c + next; continue; }
40
+ if (c === '[') inClass = true; else if (c === ']') inClass = false;
41
+ source += c;
42
+ }
43
+ return new UnicodeWordRegExp(re, source);
44
+ }
45
+
2
46
  const runner = /^(?:bash|sh|zsh|dash|ksh|fish|python[23]?|node|perl|ruby|php|lua|pwsh|powershell|deno|bun|osascript|tclsh|Rscript|source|\.)$/;
3
47
  // Arity belongs to the wrapper, never to a shared spelling: e.g. sudo -n
4
48
  // takes no value, while nice/xargs -n do. Optional values must be attached.
@@ -66,8 +110,9 @@ function commands(file, functions) {
66
110
  });
67
111
  return { ...file, text };
68
112
  }
113
+ const dataflowTools = unicodeWords(/\b(?:curl|wget|base64)\b/);
69
114
  export function shellFindings(files) {
70
- if (!files.some((f) => /\b(?:curl|wget|base64)\b/.test(f.text))) return { hits: [], complete: true };
115
+ if (!files.some((f) => dataflowTools.test(f.text))) return { hits: [], complete: true };
71
116
  const functions = new Map(), prepared = files.map((f) => commands(f, functions));
72
117
  const hits = new Map(); let remaining = 100000;
73
118
  function walk(file, outputs, collect, depth = 0, written = new Set()) {
@@ -151,8 +196,9 @@ export function looksLikeShell(text) {
151
196
 
152
197
  const passive = new Set('cp mv ln rm mkdir ls stat file du wc touch shasum sha256sum md5 md5sum open xdg-open qlmanage sips magick convert identify optipng pngcrush cwebp ffmpeg fc-list fc-cache'.split(' '));
153
198
  const readers = new Set(['cat', 'head', 'tail', 'xxd']);
199
+ const installMode = unicodeWords(/(?:-m\s*|--mode[=\s]+)0?7[0-7]{2}\b/);
154
200
  const executableMode = (cmd, raw) => cmd === 'chmod' && /(?:^|\s)(?:[ugoa]*\+[^\s]*x|[0-7]*[1357][0-7]{2})(?:\s|$)/.test(raw)
155
- || cmd === 'install' && /(?:-m\s*|--mode[=\s]+)0?7[0-7]{2}\b/.test(raw);
201
+ || cmd === 'install' && installMode.test(raw);
156
202
  function reviewParts(line) {
157
203
  const parts = []; let current = '', quote = null;
158
204
  for (let i = 0; i < line.length; i++) {
@@ -173,8 +219,11 @@ function reviewParts(line) {
173
219
 
174
220
  // Raw-text catch-alls: no token expansion, quoting or command position can hide these
175
221
  // capabilities. Vocabulary deliberately avoids English verbs such as plain "fetch"/"run".
176
- const downloadText = /\b(?:curl|wget|aria2c|iwr|irm|Invoke-WebRequest|Invoke-RestMethod|uudecode)\b|\bgit\s+clone\b|\b(?:fetch|https?)\s+(?:-[\w-]+\s+)*https?:\/\/|\b(?:fetch|urlopen|URI\.open|requests\.(?:get|request)|https?\.get)\s*\(|\b(?:python[23]?|node|ruby|perl)\b[^\n]*(?:get|request)[^\n]*https?:\/\/|\bbase64\b[^\n]*?(?:--decode\b|-[A-Za-z]*[dD][A-Za-z]*\b)|\bopenssl\s+(?:base64|enc)\b[^\n]*?\s-d\b|\bxxd\s+[^\n]*?-r\b/i;
177
- const runText = /\b(?:bash|sh|zsh|dash|ksh|fish|python[23]?|node|perl|ruby|php|lua|pwsh|powershell|deno|bun|osascript|tclsh|Rscript|npx|eval|Invoke-Expression|iex)\b|\bpnpm\s+dlx\b|\bexec\s+["'`$./\w]|(?:^|[;|&()"'`])\s*(?:(?:env|nohup|command|sudo|exec)\s+(?:-[\w-]+\s+)*)?(?:\.{1,2}\/|\/[\w.-]+\/)[\w./$-]+|\$\{?[A-Za-z_]\w*\}?["']?\s+["'./\w$]|\bchmod\s+[^\n]*?(?:\+\w*x|[0-7]*[1357][0-7]{2})\b|\binstall\s+[^\n]*?(?:-m\s*|--mode[=\s]+)0?7[0-7]{2}\b/i;
222
+ const downloadText = unicodeWords(/\b(?:curl|wget|aria2c|iwr|irm|Invoke-WebRequest|Invoke-RestMethod|uudecode)\b|\bgit\s+clone\b|\b(?:fetch|https?)\s+(?:-[\w-]+\s+)*https?:\/\/|\b(?:fetch|urlopen|URI\.open|requests\.(?:get|request)|https?\.get)\s*\(|\b(?:python[23]?|node|ruby|perl)\b[^\n]*(?:get|request)[^\n]*https?:\/\/|\bbase64\b[^\n]*?(?:--decode\b|-[A-Za-z]*[dD][A-Za-z]*\b)|\bopenssl\s+(?:base64|enc)\b[^\n]*?\s-d\b|\bxxd\s+[^\n]*?-r\b/i);
223
+ const runText = unicodeWords(/\b(?:bash|sh|zsh|dash|ksh|fish|python[23]?|node|perl|ruby|php|lua|pwsh|powershell|deno|bun|osascript|tclsh|Rscript|npx|eval|Invoke-Expression|iex)\b|\bpnpm\s+dlx\b|\bexec\s+["'`$./\w]|(?:^|[;|&()"'`])\s*(?:(?:env|nohup|command|sudo|exec)\s+(?:-[\w-]+\s+)*)?(?:\.{1,2}\/|\/[\w.-]+\/)[\w./$-]+|\$\{?[A-Za-z_]\w*\}?["']?\s+["'./\w$]|\bchmod\s+[^\n]*?(?:\+\w*x|[0-7]*[1357][0-7]{2})\b|\binstall\s+[^\n]*?(?:-m\s*|--mode[=\s]+)0?7[0-7]{2}\b/i);
224
+ const sourceRun = unicodeWords(/\bsource\s+(?:["'`$./]|[\w-]+\.[\w.-]+)/);
225
+ const readerPipe = unicodeWords(/\b(?:cat|head|tail|xxd|tee)\s+[^|]+\|/);
226
+ const readerText = unicodeWords(/\b(?:cat|head|tail|xxd)\b/);
178
227
  // Unlike interpreter names, "make" is common prose. Require command position
179
228
  // in code, or an unfenced command list starting with a known shell program.
180
229
  function makeCommand(line) {
@@ -190,11 +239,11 @@ function makeRun(line, code) {
190
239
  if ([...line.matchAll(/`([^`\n]+)`/g)].some((m) => makeCommand(m[1]))) return true;
191
240
  return /^\s*(?:curl|wget|base64|echo|printf)\s/.test(line) && makeCommand(line);
192
241
  }
193
- const rawRun = (line, code) => runText.test(line) || makeRun(line, code) || /(?:^|[;|&(`])\s*\.\s+(?:["'$./~]|[a-z_][\w.-]*)/.test(line) || /\bsource\s+(?:["'`$./]|[\w-]+\.[\w.-]+)/.test(line)
242
+ const rawRun = (line, code) => runText.test(line) || makeRun(line, code) || /(?:^|[;|&(`])\s*\.\s+(?:["'$./~]|[a-z_][\w.-]*)/.test(line) || sourceRun.test(line)
194
243
  // A substitution in command position runs its result, including $(<file) and
195
244
  // $(cat file). Assignment/echo arguments alone do not run the substituted data.
196
245
  || /(?:^|[;|&(`])\s*(?:[A-Za-z_]\w*=\S+\s+)*(?:(?:env|nohup|command|sudo|exec)\s+(?:(?:-[\w-]+|[A-Za-z_]\w*=\S+)\s+)*)?["']?\$\(/.test(line)
197
- || (downloadText.test(line) || /\b(?:cat|head|tail|xxd|tee)\s+[^|]+\|/.test(line)) && !/^\s*\|.*\|\s*$/.test(line) && [...line.matchAll(/\|\s*([\w$./\\-]+)(?=\s|["'`)]|$)/g)].some((m) => !passive.has(base(m[1])) && !readers.has(base(m[1])) && base(m[1]) !== 'tee');
246
+ || (downloadText.test(line) || readerPipe.test(line)) && !/^\s*\|.*\|\s*$/.test(line) && [...line.matchAll(/\|\s*([\w$./\\-]+)(?=\s|["'`)]|$)/g)].some((m) => !passive.has(base(m[1])) && !readers.has(base(m[1])) && base(m[1]) !== 'tee');
198
247
  const assetText = /(?:[\w$~./-]+|\$\{\w+\})\.(?:png|jpe?g|gif|webp|ico|svg|woff2?|ttf|otf|mp[34]|m4[av]|wav|ogg|flac|webm|mov|avi)(?=$|[^\w.-])/i;
199
248
  const instruction = /^(?:Use|Run|Fetch|Read|See|Open|Copy|Move|Install|Download|Put|Place|Add|Include|Embed|Display|Save|The|This|A|An)\b\s*/i;
200
249
  const article = /^(?:The|This|A|An|the|this|a|an)\b/;
@@ -264,7 +313,7 @@ function assetRun(line, markdown, fenced) {
264
313
  }
265
314
  // A reader redirecting into a program is command evidence even if the program is
266
315
  // unknown. Plain file output and ordinary cat/head/tail/xxd stay passive.
267
- if (/\b(?:cat|head|tail|xxd)\b/.test(candidate) && />\s*(?:>\(|\$\()/.test(candidate)) return true;
316
+ if (readerText.test(candidate) && />\s*(?:>\(|\$\()/.test(candidate)) return true;
268
317
  }
269
318
  return false;
270
319
  }
@@ -1,7 +1,7 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import { isEditableText } from '../../public/shared/skills/ss-doc.js';
3
3
  import { ASSET_EXT, inspectAsset, assetBudget, scriptMarkers } from './scan-assets.js';
4
- import { shellFindings, shellReviewFindings, looksLikeShell } from './scan-shell.js';
4
+ import { shellFindings, shellReviewFindings, looksLikeShell, unicodeWords } from './scan-shell.js';
5
5
  // ── What a skill can do, read without running anything ──
6
6
  // A local, deterministic look at every file of a skill before it is installed: what it would run and when
7
7
  // (scripts, Claude Code dynamic context, hooks that stay for the session, tool grants), what it reaches (URLs,
@@ -38,9 +38,10 @@ function colourSGR(text, at) {
38
38
  }
39
39
 
40
40
  export const SCAN_ENGINE = 'synabun-static';
41
- export const SCAN_ENGINE_VERSION = '1.7.5';
41
+ export const SCAN_ENGINE_VERSION = '1.7.6';
42
42
  // skills-p1: typosquats of a shipped skill's name (S-13), calibrated on tests/fixtures/skills-scan/corpus.json;
43
43
  // 1.2.0: a name that is exactly a shipped skill's, on something that is not that skill (S-13-shipped-name).
44
+ // 1.7.6: word edges of every script (unicodeWords): "irm" in "irmã" is no download, "node" in "nodeção" no run.
44
45
  export const SCAN_POLICY = 'skills-p5-review-2026-10-27';
45
46
  export const SCAN_LIMITS = Object.freeze({ maxFileChars: 2 * 1024 * 1024, maxTotalChars: 16 * 1024 * 1024, maxLineChars: 20000, maxFindings: 400 });
46
47
 
@@ -60,26 +61,26 @@ const MAGIC = [
60
61
  // Each rule: id, severity, a pattern tested on one line, the message, what to do. Patterns are linear (no nested
61
62
  // quantifiers over overlapping classes) and run on lines cut at maxLineChars.
62
63
  const LINE_RULES = [
63
- { id: 'S-08-remote-pipe', severity: 'high', re: /\b(?:curl|wget|fetch|iwr|irm|Invoke-WebRequest|Invoke-RestMethod)\b[^|\n]{0,400}\|\s*(?:sudo\s+)?(?:ba|z|da|k|fi)?sh\b|\b(?:curl|wget)\b[^|\n]{0,400}\|\s*(?:sudo\s+)?(?:python3?|node|perl|ruby|iex|Invoke-Expression)\b/i,
64
+ { id: 'S-08-remote-pipe', severity: 'high', re: unicodeWords(/\b(?:curl|wget|fetch|iwr|irm|Invoke-WebRequest|Invoke-RestMethod)\b[^|\n]{0,400}\|\s*(?:sudo\s+)?(?:ba|z|da|k|fi)?sh\b|\b(?:curl|wget)\b[^|\n]{0,400}\|\s*(?:sudo\s+)?(?:python3?|node|perl|ruby|iex|Invoke-Expression)\b/i),
64
65
  message: 'Downloads a script and runs it in one step.', remediation: 'Pin what is downloaded (a version, a checksum) and show it before it runs, or drop the step.' },
65
- { id: 'S-08-remote-subshell', severity: 'high', re: /\b(?:ba|z)?sh\s+(?:-c\s+)?["']?\$?\(\s*(?:curl|wget)\b|\bsource\s+<\(\s*(?:curl|wget)\b|\.\s+<\(\s*(?:curl|wget)\b/i,
66
+ { id: 'S-08-remote-subshell', severity: 'high', re: unicodeWords(/\b(?:ba|z)?sh\s+(?:-c\s+)?["']?\$?\(\s*(?:curl|wget)\b|\bsource\s+<\(\s*(?:curl|wget)\b|\.\s+<\(\s*(?:curl|wget)\b/i),
66
67
  message: 'Runs a script fetched from the network.', remediation: 'Ship the script with the skill, or pin and verify it.' },
67
- { id: 'S-08-installer', severity: 'medium', re: /\b(?:npm\s+(?:i|install)\s+(?:-g|--global)\b|npx\s+\S|pnpm\s+dlx\b|pip3?\s+install\b|pipx\s+install\b|brew\s+install\b|gem\s+install\b|cargo\s+install\b|go\s+install\b|apt(?:-get)?\s+install\b)/i,
68
+ { id: 'S-08-installer', severity: 'medium', re: unicodeWords(/\b(?:npm\s+(?:i|install)\s+(?:-g|--global)\b|npx\s+\S|pnpm\s+dlx\b|pip3?\s+install\b|pipx\s+install\b|brew\s+install\b|gem\s+install\b|cargo\s+install\b|go\s+install\b|apt(?:-get)?\s+install\b)/i),
68
69
  message: 'Installs software on the machine that runs it.', remediation: 'Say which package and version, and why; a reviewer decides.' },
69
- { id: 'S-09-decode-exec', severity: 'high', re: /\bbase64\s+(?:-d|--decode|-D)\b[^\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b|\becho\s+[A-Za-z0-9+/=]{24,}\s*\|\s*base64\b|\b(?:eval|exec)\s*\(\s*(?:atob|Buffer\.from|base64\.b64decode|bytes\.fromhex|codecs\.decode)\b|FromBase64String\s*\([^)]{0,200}\)[^\n]{0,200}(?:Invoke-Expression|iex)\b|powershell(?:\.exe)?\s+[^\n]{0,80}-(?:e|en|enc|encodedcommand)\s+[A-Za-z0-9+/=]{16,}/i,
70
+ { id: 'S-09-decode-exec', severity: 'high', re: unicodeWords(/\bbase64\s+(?:-d|--decode|-D)\b[^\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b|\becho\s+[A-Za-z0-9+/=]{24,}\s*\|\s*base64\b|\b(?:eval|exec)\s*\(\s*(?:atob|Buffer\.from|base64\.b64decode|bytes\.fromhex|codecs\.decode)\b|FromBase64String\s*\([^)]{0,200}\)[^\n]{0,200}(?:Invoke-Expression|iex)\b|powershell(?:\.exe)?\s+[^\n]{0,80}-(?:e|en|enc|encodedcommand)\s+[A-Za-z0-9+/=]{16,}/i),
70
71
  message: 'Decodes hidden text and runs it.', remediation: 'Write the command out in plain text, or remove it.' },
71
- { id: 'S-09-eval', severity: 'low', re: /\beval\s+["'`$(]|\beval\s*\(/,
72
+ { id: 'S-09-eval', severity: 'low', re: unicodeWords(/\beval\s+["'`$(]|\beval\s*\(/),
72
73
  message: 'Builds a command at run time and evaluates it.', remediation: 'Prefer fixed commands a reader can check.' },
73
- { id: 'S-10-sensitive-path', severity: 'medium', re: /(?:~|\$HOME|%USERPROFILE%|\/Users\/[^/\s]+|\/home\/[^/\s]+)\/(?:\.ssh|\.aws\/credentials|\.netrc|\.gnupg|\.kube\/config|\.docker\/config\.json|\.config\/gcloud|Library\/Keychains|Library\/Cookies|Library\/Application Support\/(?:Google\/Chrome|BraveSoftware|Firefox|Microsoft Edge|com\.apple\.TCC))|\bid_(?:rsa|ed25519|ecdsa)\b|\blogin\.keychain|\bsecurity\s+find-(?:generic|internet)-password\b|\/etc\/(?:shadow|sudoers)\b|\bLogin Data\b/i,
74
+ { id: 'S-10-sensitive-path', severity: 'medium', re: unicodeWords(/(?:~|\$HOME|%USERPROFILE%|\/Users\/[^/\s]+|\/home\/[^/\s]+)\/(?:\.ssh|\.aws\/credentials|\.netrc|\.gnupg|\.kube\/config|\.docker\/config\.json|\.config\/gcloud|Library\/Keychains|Library\/Cookies|Library\/Application Support\/(?:Google\/Chrome|BraveSoftware|Firefox|Microsoft Edge|com\.apple\.TCC))|\bid_(?:rsa|ed25519|ecdsa)\b|\blogin\.keychain|\bsecurity\s+find-(?:generic|internet)-password\b|\/etc\/(?:shadow|sudoers)\b|\bLogin Data\b/i),
74
75
  message: 'Reads credentials or other private data of the user.', remediation: 'Say why it needs them; a reviewer decides.' },
75
- { id: 'S-05-authority-spoof', severity: 'medium', re: /\bignore\s+(?:all\s+)?(?:the\s+)?(?:previous|prior|above|earlier)\s+(?:instructions|rules|prompts?)\b|\byou\s+are\s+now\s+(?:in\s+)?(?:developer|dan|god|jailbreak|unrestricted)\b|<\/?\s*system\s*>|\[\s*system\s*\]\s*:|\bdo\s+not\s+(?:tell|inform|show|mention\s+(?:this\s+)?to)\s+the\s+user\b|\bwithout\s+(?:asking|telling|informing)\s+the\s+user\b|\b(?:disable|bypass|turn\s+off|ignore)\s+(?:the\s+)?(?:safety|security|permission|sandbox|approval)\s+(?:checks?|prompts?|rules?|settings?|mode)\b/i,
76
+ { id: 'S-05-authority-spoof', severity: 'medium', re: unicodeWords(/\bignore\s+(?:all\s+)?(?:the\s+)?(?:previous|prior|above|earlier)\s+(?:instructions|rules|prompts?)\b|\byou\s+are\s+now\s+(?:in\s+)?(?:developer|dan|god|jailbreak|unrestricted)\b|<\/?\s*system\s*>|\[\s*system\s*\]\s*:|\bdo\s+not\s+(?:tell|inform|show|mention\s+(?:this\s+)?to)\s+the\s+user\b|\bwithout\s+(?:asking|telling|informing)\s+the\s+user\b|\b(?:disable|bypass|turn\s+off|ignore)\s+(?:the\s+)?(?:safety|security|permission|sandbox|approval)\s+(?:checks?|prompts?|rules?|settings?|mode)\b/i),
76
77
  message: 'Text that tries to override instructions, hide what it does, or switch off a safeguard.', remediation: 'Remove it, or make sure it is quoted as an example and not an instruction.' },
77
- { id: 'S-07-persistent-write', severity: 'high', re: /(?:>>?\s*|\btee\s+(?:-a\s+)?|\bcp\s+[^\n]{0,200}\s|\bmv\s+[^\n]{0,200}\s|\bwrite(?:File)?\w*\s*\([^)]{0,200})["']?(?:~|\$HOME)?\/?[^\s"']{0,300}(?:\.bashrc|\.zshrc|\.bash_profile|\.profile|\.zprofile|\.config\/fish\/config\.fish|crontab|LaunchAgents\/|\.claude\/settings(?:\.local)?\.json|\.claude\/CLAUDE\.md|CLAUDE\.md|AGENTS\.md|\.codex\/config\.toml|\.mcp\.json|\.gitconfig)\b|\bcrontab\s+-[^l\s]|\blaunchctl\s+(?:load|bootstrap)\b/i,
78
+ { id: 'S-07-persistent-write', severity: 'high', re: unicodeWords(/(?:>>?\s*|\btee\s+(?:-a\s+)?|\bcp\s+[^\n]{0,200}\s|\bmv\s+[^\n]{0,200}\s|\bwrite(?:File)?\w*\s*\([^)]{0,200})["']?(?:~|\$HOME)?\/?[^\s"']{0,300}(?:\.bashrc|\.zshrc|\.bash_profile|\.profile|\.zprofile|\.config\/fish\/config\.fish|crontab|LaunchAgents\/|\.claude\/settings(?:\.local)?\.json|\.claude\/CLAUDE\.md|CLAUDE\.md|AGENTS\.md|\.codex\/config\.toml|\.mcp\.json|\.gitconfig)\b|\bcrontab\s+-[^l\s]|\blaunchctl\s+(?:load|bootstrap)\b/i),
78
79
  message: 'Changes configuration that lasts beyond this task (shell start-up files, scheduled jobs, agent settings or instructions).', remediation: 'Say what it changes and why; a reviewer decides.' },
79
80
  ];
80
81
 
81
- const NETWORK_SINK = /\bcurl\b[^\n]{0,300}\s(?:-d|--data(?:-binary|-raw|-urlencode)?|-F|--form|-T|--upload-file)\b|\bwget\b[^\n]{0,300}--post-(?:data|file)\b|\b(?:nc|ncat|netcat)\s+[^\n]{0,100}\d+|\bscp\s+[^\n]{0,300}@|\brsync\s+[^\n]{0,300}@[^\s:]+:|Invoke-(?:WebRequest|RestMethod)\b[^\n]{0,300}-Method\s+(?:Post|Put)\b|\brequests\.(?:post|put)\s*\(|\bfetch\s*\([^)]{0,300}method\s*:\s*["'](?:POST|PUT)["']/i;
82
- const SECRET_ENV = /\$\{?(?:[A-Z0-9_]*(?:TOKEN|SECRET|PASSWORD|PASSWD|API_?KEY|PRIVATE_?KEY|ACCESS_?KEY|CREDENTIALS?)[A-Z0-9_]*)\}?|\bprocess\.env\.[A-Z0-9_]*(?:TOKEN|SECRET|KEY|PASSWORD)\b|\bos\.environ\b/;
82
+ const NETWORK_SINK = unicodeWords(/\bcurl\b[^\n]{0,300}\s(?:-d|--data(?:-binary|-raw|-urlencode)?|-F|--form|-T|--upload-file)\b|\bwget\b[^\n]{0,300}--post-(?:data|file)\b|\b(?:nc|ncat|netcat)\s+[^\n]{0,100}\d+|\bscp\s+[^\n]{0,300}@|\brsync\s+[^\n]{0,300}@[^\s:]+:|Invoke-(?:WebRequest|RestMethod)\b[^\n]{0,300}-Method\s+(?:Post|Put)\b|\brequests\.(?:post|put)\s*\(|\bfetch\s*\([^)]{0,300}method\s*:\s*["'](?:POST|PUT)["']/i);
83
+ const SECRET_ENV = unicodeWords(/\$\{?(?:[A-Z0-9_]*(?:TOKEN|SECRET|PASSWORD|PASSWD|API_?KEY|PRIVATE_?KEY|ACCESS_?KEY|CREDENTIALS?)[A-Z0-9_]*)\}?|\bprocess\.env\.[A-Z0-9_]*(?:TOKEN|SECRET|KEY|PASSWORD)\b|\bos\.environ\b/);
83
84
  const URL_RE = /\bhttps?:\/\/[^\s<>"'`)\]]{1,300}/gi;
84
85
 
85
86
  // Credentials written into a file: the value is never repeated in a finding.
@@ -48,6 +48,10 @@ export const SERVICE_CAPABILITIES = Object.freeze([
48
48
  // P4: evaluations from the Test tab (/evals, lib/skills/evals.js): task and trigger cases, the description
49
49
  // optimiser, results, history, export and the suite import.
50
50
  'evals', 'usage', 'health', 'discover', 'packages', 'external-scanner-status',
51
+ // 2026-11-28: every committed install is checked statically by itself (discoverable, eligibility per runtime in
52
+ // `state.eligibilityByRuntime`); the skill view's installation rows carry that `state`; owners and agents can run
53
+ // that check again (POST /installations/:id/check; a probe of Codex / OpenCode only when asked).
54
+ 'install-static-check',
51
55
  ]);
52
56
 
53
57
  export const ASSISTANT_RUNTIMES = Object.freeze(['claude', 'codex', 'opencode', 'antigravity']);
@@ -263,7 +267,7 @@ export function createSkillsService({ dataDir, roots, catalog, library, deployer
263
267
  description: latest ? revisionDescription(latest) : draftDescription(skill.pointers.draft),
264
268
  pointers: skill.pointers, revisions: skill.revisions.length,
265
269
  latest: latest ? { integrity: latest.integrity, error: latest.error || null, revisionId: latest.revisionId, contentDigest: latest.contentDigest, createdAt: latest.createdAt, author: latest.author } : null,
266
- installations: installs.map((i) => ({ installationId: i.installationId, runtime: i.target.runtime, scope: i.target.scope, accountId: i.target.accountId, projectPath: i.target.projectPath, destination: i.destination.path, sourceRevisionId: i.sourceRevisionId, updateAvailable: !!upstream && i.sourceRevisionId !== upstream && skill.origin?.kind === 'bundled' })),
270
+ installations: installs.map((i) => ({ installationId: i.installationId, runtime: i.target.runtime, scope: i.target.scope, accountId: i.target.accountId, projectPath: i.target.projectPath, destination: i.destination.path, sourceRevisionId: i.sourceRevisionId, updateAvailable: !!upstream && i.sourceRevisionId !== upstream && skill.origin?.kind === 'bundled', affectedRuntimes: i.destination.affectedRuntimes || [], state: i.state || null })),
267
271
  };
268
272
  }
269
273
 
@@ -506,7 +510,8 @@ export function createSkillsService({ dataDir, roots, catalog, library, deployer
506
510
  let nativeState = 'absent';
507
511
  if (root) {
508
512
  const inspected = ownership.inspect({ destination: join(root.path, name) });
509
- nativeState = inspected.state === 'absent' ? 'absent' : (native && inspected.current.digest === native.export.artifactDigest ? 'native' : (inspected.state === 'owned' ? 'native' : (inspected.state === 'modified' ? 'modified' : 'other')));
513
+ // The installation's own bytes (its executable bits taken from it where files keep none: deploy.js installedDigest).
514
+ nativeState = inspected.state === 'absent' ? 'absent' : (native && deployer.installedDigest(native, inspected.current) === native.export.artifactDigest ? 'native' : (inspected.state === 'owned' ? 'native' : (inspected.state === 'modified' ? 'modified' : 'other')));
510
515
  }
511
516
  out[runtime] = { native: nativeState, installationId: native?.installationId || null, destination: root ? join(root.path, name) : null };
512
517
  }
@@ -1,7 +1,6 @@
1
1
  // Minimal local evidence, from trusted runtime events only. No prompts, commands, paths, or outputs are stored.
2
2
  import { createHash } from 'node:crypto';
3
3
  import { join, resolve, sep } from 'node:path';
4
- import { readManifest } from './digest.js';
5
4
  import { toolCallsOf, initOf } from './eval-trace.js';
6
5
  import { localRecord } from './local-store.js';
7
6
 
@@ -32,7 +31,8 @@ export function createSkillTelemetry({ dataDir, deployer, settings, now = Date.n
32
31
  const events = read();
33
32
  if (events.some((e) => e.key === key)) return;
34
33
  // Only attribute bytes that still match the installed export. Drift is health evidence, not approved usage.
35
- if (readManifest(inst.destination.path).digest !== inst.export.artifactDigest) return;
34
+ // (deploy.js installedDigest: where files keep no executable bit, Windows, the bit is the installation's.)
35
+ if (deployer.installedDigest(inst) !== inst.export.artifactDigest) return;
36
36
  events.push({ key, at: now(), turn: turnOf(run), runRef: hash(String(run.runId)), installationId: inst.installationId,
37
37
  skillId: inst.skillId, revisionId: inst.sourceRevisionId, exportDigest: inst.export.artifactDigest,
38
38
  runtime, kind, method, strength, outcome: null, costUsd: null });
@@ -81,7 +81,7 @@ createTeams({ store, git, runTests, setup, identity, isIgnored, registry, now, l
81
81
  | `isIgnored` | `git check-ignore` | `(worktree, relPath) => boolean` |
82
82
  | `registry` | `lib/worker-confinement.js` | `{ register, unregister }`: where slices are registered for the worker guard |
83
83
 
84
- It returns: `create`, `get`, `plan`, `list`, `inspect`, `startSlice`, `finishSlice`, `integrate`, `integrateAll`, `testIntegration`, `resolveInSlice`, `acceptIntegrationHead`, `land`, `remove`, `prune`, `recover`, `checkWrite`, `verifyOwnership`, `context`, and `modules` (`state`, `worktrees`, `claims`, `integration`, `landing`, `recovery`) for a caller that needs one module's own functions.
84
+ It returns: `create`, `get`, `plan`, `list`, `inspect`, `startSlice`, `finishSlice`, `integrate`, `integrateAll`, `testIntegration`, `resolveInSlice`, `acceptIntegrationHead`, `land`, `landingPreview`, `remove`, `prune`, `recover`, `checkWrite`, `verifyOwnership`, `context`, and `modules` (`state`, `worktrees`, `claims`, `integration`, `landing`, `recovery`) for a caller that needs one module's own functions.
85
85
 
86
86
  ## Worktrees (`worktrees.js`)
87
87
 
@@ -222,17 +222,24 @@ When the last slice is joined the team is `ready` and an `integration.ready` eve
222
222
 
223
223
  ## Landing (`landing.js`)
224
224
 
225
- **`land(teamId, { targetBranch, mode, allowUntested, allowPartial })`** → `{ ok, landed, changed }`
225
+ **`land(teamId, { targetBranch, mode, allowUntested, allowPartial, unmovedOnly, expectedTargetHead, expectedIntegrationHead })`** → `{ ok, landed, changed }`
226
226
 
227
- - `targetBranch`: default, the branch the project was on when the team was created.
227
+ - `targetBranch`: default, the team's recorded base branch (the branch the project was on when the team was created). Never the branch that is checked out when somebody lands: the scheduler passes the same default, and a base branch that is gone is `TARGET_NOT_FOUND`, with no other branch in its place.
228
+ - `unmovedOnly`: land only while the target is at the commit the team was cut from (`OWNER_BRANCH_MOVED` otherwise). The scheduler asks it of an Assistant's landing.
229
+ - `expectedTargetHead`, `expectedIntegrationHead`: the full commit ids the two branches were at when the landing was confirmed (a preview's `targetHead` and `integrationHead`). Compared with git under the landing's own lock, before any other check; one that differs is `LANDING_PREVIEW_STALE`, with the landing as it stands in `preview`.
228
230
  - `mode: 'ff'` (default) moves the target forward to the integration branch. `mode: 'merge'` makes a merge commit of the two (always, also when a fast-forward would do), computed without a checkout (`git merge-tree`, git 2.38 or newer), and moves the target to it.
229
231
  - Where the target is checked out (the user's own checkout, usually), the branch, the index and the files are updated together by a fast-forward of that checkout. Every uncommitted change of a file the landing does not touch comes through unchanged, staged or not; nothing is stashed; no hook runs. Where the target is checked out nowhere, only the branch moves (compare-and-swap on its old commit).
230
232
  - The team is then `merged` (`landed: { targetBranch, mode, from, to, mergeCommit, checkout, files, tested, partial }`) and its claims are given back.
231
233
 
232
- A landing changes nothing, and answers with a `report`, for:
234
+ **`preview(teamId, { targetBranch, mode, unmovedOnly })`** (on the service: `teams.landingPreview`) → `{ targetBranch, targetHead, integrationHead, testCommand, testsPassedOnHead, canLand, code, reason }`. What a landing sent now, with no override, would be told: `canLand` is true exactly when it would be accepted; otherwise `code` is the refusal's and `reason` the first sentence of its message. `targetHead` and `integrationHead` are the two tips as git has them (null: not there). It takes no lock and moves nothing. `land` and `preview` run the same two functions (`admit`: the team, the mode, the target's name; `decide`: everything that needs the two heads), so they cannot disagree; a new check goes into one of those, never into `land` alone. The scheduler puts it into a team's status as `landing.preview`.
235
+
236
+ A landing changes nothing, and answers with a `report`, for the codes below. Once the team's own state and the target's name are accepted, they are asked in this order: `LANDING_PREVIEW_STALE`, `OWNER_BRANCH_MOVED`, `INTEGRATION_MOVED`, `TEAM_NOT_READY`, `TARGET_NOT_FOUND`, `NOTHING_TO_LAND`, `TESTS_NOT_PASSED`, `NOT_FAST_FORWARD` / `MERGE_CONFLICT`, then the checkout's (`CHECKOUT_BUSY`, `CHECKOUT_REFUSED`, `DIRTY_FILES_AFFECTED`).
233
237
 
234
238
  | Code | |
235
239
  |---|---|
240
+ | `LANDING_PREVIEW_STALE` | an expected head is not where the branch is now (`preview`, and in `report`: `expectedTargetHead`, `targetHead`, `expectedIntegrationHead`, `integrationHead`) |
241
+ | `OWNER_BRANCH_MOVED` | `unmovedOnly` and the target is not at the team's base commit (`cutFrom`, `head`) |
242
+ | `NOTHING_TO_LAND` | the target already has everything on the integration branch. Asked before the tests: joins that changed nothing leave nothing to test |
236
243
  | `NOT_FAST_FORWARD` | `mode: 'ff'` and the target has commits the integration branch lacks (`targetOnly`, `integrationOnly`) |
237
244
  | `MERGE_CONFLICT` | `mode: 'merge'` and the two do not merge cleanly (`files`). Never resolved |
238
245
  | `TESTS_NOT_PASSED` | the tests have not passed on the integration head: no test command, not run on this commit, or failed. `allowUntested: true` lands on the caller's word |
@@ -241,7 +248,7 @@ A landing changes nothing, and answers with a `report`, for:
241
248
  | `CHECKOUT_BUSY` | that checkout is in the middle of a merge, rebase, cherry-pick, revert or bisect |
242
249
  | `CHECKOUT_REFUSED` | git would not update that checkout (it checks again as it starts) |
243
250
  | `TARGET_MOVED` | the target moved while the landing was prepared |
244
- | `INTEGRATION_MOVED`, `TARGET_NOT_FOUND`, `TARGET_REQUIRED`, `TARGET_IS_TEAM_BRANCH`, `NOTHING_TO_LAND`, `ALREADY_LANDED`, `INVALID_MODE`, `MERGE_UNAVAILABLE` | |
251
+ | `INTEGRATION_MOVED`, `TARGET_NOT_FOUND`, `TARGET_REQUIRED`, `TARGET_IS_TEAM_BRANCH`, `ALREADY_LANDED`, `INVALID_MODE`, `MERGE_UNAVAILABLE` | |
245
252
 
246
253
  Where it applies, `report.userShouldRun` is what the user can run themselves (`git checkout <target>`, `git merge --ff-only synabun/<team>/integration`).
247
254
 
@@ -256,6 +263,10 @@ Where it applies, `report.userShouldRun` is what the user can run themselves (`g
256
263
  | `landing` | the target branch at the landing's commit: `merged`. Where it was: the team is as before. Anywhere else: reported |
257
264
  | a worktree's folder gone | put back from its branch (what was uncommitted in the folder went with the folder) |
258
265
  | a slice's branch and folder gone | the slice is `failed` |
266
+ | the integration branch and folder gone, every slice ended or gone, the integration head on the base branch already | the team is `merged` (merged outside `land`: `landed.external: true`, `landed.recovered: true`); nothing is made again |
267
+ | the integration branch and folder gone, every slice ended or gone, nothing joined (no slice `integrated`, the head still the base commit) | the team is `failed`; no empty integration branch is made |
268
+
269
+ A team closed that way gives its claims back, and `removed: true` is written when no branch or folder of it is left; a slice branch that is still there stays, for `remove` (after the landing) or a discard. The integration branch is still made again from its recorded head when any slice is at work or its branch is still there with its folder gone, when the head has commits the base branch does not have, or when the base branch is not there to compare with. Each closing is the action `team_closed` (`state`, `reason: 'merged_outside_landing' | 'nothing_integrated'`, `targetBranch`, `head`, `removed`).
259
270
 
260
271
  It also takes the claims of every team under way again and registers every slice with the worker guard again (the guard's registry is in memory).
261
272
 
@@ -301,7 +312,7 @@ They ask git under the rules of a read and change nothing. The tool has no actio
301
312
  `createTeamScheduler({ teams, coordination, dispatcher, density, router, session, git, dataDir, broadcast, limits })` (`scheduler.js`). `docs/agents.md` → Teams says what it does for the Assistant and the workers; this is what a caller of the library needs to know about it.
302
313
 
303
314
  - **It is the only caller of the library in the server.** `server.js` shares it (`shareTeamScheduler`); the Assistant's API and the Agents Studio routes ask `sharedTeamScheduler()` when a request arrives. A test passes its own.
304
- - **Its own record** is one JSON file per team in `<dataDir>/teams/<teamId>.json` (the session, the route, the dispatch settings, each slice's runs and retry counts, its status). Everything about git is read from the journal through the library, never kept twice.
315
+ - **Its own record** is one JSON file per team in `<dataDir>/teams/<teamId>.json` (the session, the route, the dispatch settings, each slice's runs and retry counts, its status). Everything about git is read from the journal through the library, never kept twice. `remove(teamId)` deletes that file (and `teams/sandbox/<teamId>.sb`) for a closed team once git and the disk show nothing of it and no worker lives; the journal entry stays (a closed team's journal state is terminal, so `recover()` skips it, and its id is never made again), and a removed record is never saved again (`docs/agents.md` → Teams, Removing a closed team).
305
316
  - **A team's steps never overlap**: every step of one team runs after the one before it (`inTurn`), and none runs before the library's `recover()` has.
306
317
  - **The run id comes first.** `dispatchSlice` makes the run id, calls `startSlice(teamId, sliceId, { runId })` (or `resolveInSlice`), and only then dispatches with that id (`dispatcher.dispatch(spec, { team, runId })`): the claims are in the run's name before the worker exists. The dispatcher takes `team` and `runId` from the scheduler alone; no request body reaches them.
307
318
  - **What it decides that the library leaves open** (the list below this section, as it was written for this phase): workers run with capability `workspace`; `STRAY_CHANGES` is answered with `allowStray: true` (the files stay out, the event names them); a conflict goes to the slice's own worker through `resolveInSlice`; `land` is never called because a team became ready; the workers are stopped before `remove`; the tests run through `test-sandbox.js`; the setup step is `cloneNodeModules()`; a team id is `<title>-<6 hex>`.
@@ -380,3 +391,20 @@ lastOwnerTurnAt: (sessionId) => _assistantRuntime?.lastOwnerTurnAt?.(sessionId)
380
391
  With that dependency present, absent, equal or earlier timestamps refuse cleanup. Without it,
381
392
  confirmation timing is explicitly reported as unverified. Git failures during removal throw;
382
393
  external concurrent filesystem changes cannot be made transactional across Git commands.
394
+
395
+ ### A ready team merged outside `land`
396
+
397
+ Somebody may merge a ready team's integration branch into its base branch by hand, leaving its worktrees and
398
+ branches on disk. `onTarget(teamId)` (read only, no lock: a list asks it) answers `null` unless the journal says
399
+ `ready` and git says the recorded integration head, and the live integration branch, are ancestors of
400
+ `refs/heads/<baseBranch>`; then `{ branch, head, targetHead, live, moved, clean, dirty, unmerged, other }`, where
401
+ `clean` is every guarded check above passing against the base branch (`guardedChecks`, the same code the removal
402
+ runs), `dirty` the uncommitted files per worktree, `unmerged` the branches with commits the base branch lacks, and
403
+ `other` git's words for anything else. Live workers are the scheduler's to count (`liveRuns`), not the library's.
404
+
405
+ `remove(teamId, { guarded: true, mergedOutside: true })` reads the team again under the repository's lock, refuses
406
+ (`TEAM_NOT_READY`, `NOT_ON_TARGET`, then the guarded codes) with nothing changed, and otherwise journals the landing
407
+ somebody else made (`merged`, `landed.external: true`) before it removes anything, then removes exactly as a guarded
408
+ cleanup does. The scheduler's `cleanupMerged(teamId, { by: { kind: 'owner' }, userConfirmed: true })` adds the live
409
+ worker check, records the landing on the team, emits `team_cleaned` and removes the team's record. Nothing does this
410
+ at start-up: recovery closes such a team only when its integration branch and worktree are already gone.
@@ -11,8 +11,11 @@
11
11
  // /api/assistant/team/* a worker's `team` tool: context, post, read, wait, ack, claims, request. Only a
12
12
  // run that proves its pin (its terminal token) AND works a team slice now. The
13
13
  // team is the run's own, read from the scheduler: no request names one.
14
- // /api/agents-studio/v1/teams* Agents Studio (the page): the list, one team in full, and the owner's two
15
- // decisions, land and discard.
14
+ // /api/agents-studio/v1/teams* Agents Studio (the page): the list, one team in full, and the owner's
15
+ // decisions: land, discard (with `force`, also the work a discard kept; with
16
+ // `remove`, the record too once nothing is left), clean up a landed team's
17
+ // worktrees, clean up and remove a ready team whose work is on its base branch
18
+ // already (cleanup-merged), remove a closed team's record, clear finished.
16
19
  //
17
20
  // Every refusal of the library (lib/teams/README.md) and of the scheduler comes back as it is: `{ ok: false, code,
18
21
  // message, … }`, with the HTTP status that fits.
@@ -20,6 +23,7 @@
20
23
  import { AGENT_DENSITIES, AGENT_DENSITY_WORKERS } from '../agents/density.js';
21
24
  import { LANDING_MODES } from './landing.js';
22
25
  import { TEAM_MESSAGE_KINDS } from './brief.js';
26
+ import { CLOSED_TEAM_STATUSES } from './scheduler.js';
23
27
 
24
28
  /** Codes that are about the request itself (400), about who asks (403), about something missing (404). The rest is a conflict (409). */
25
29
  const STATUS_BY_CODE = Object.freeze({
@@ -49,6 +53,15 @@ export function teamAnswerBody(answer) {
49
53
  }
50
54
 
51
55
  const send = (res, answer) => res.status(teamAnswerStatus(answer)).json(teamAnswerBody(answer));
56
+ /**
57
+ * Where the two branches were when a landing was confirmed (the `landing.preview` the caller read), as a land
58
+ * request names them: `expectedTargetHead`, `expectedIntegrationHead` (the tool: `expected_target_head`,
59
+ * `expected_integration_head`). Optional; the landing answers LANDING_PREVIEW_STALE when one is elsewhere now.
60
+ */
61
+ const expectedHeads = (body) => ({
62
+ expectedTargetHead: body.expectedTargetHead ?? body.expected_target_head ?? null,
63
+ expectedIntegrationHead: body.expectedIntegrationHead ?? body.expected_integration_head ?? null,
64
+ });
52
65
  const fail = (res, error) => {
53
66
  const status = Number.isInteger(error?.status) && error.status >= 400 && error.status < 600 ? error.status : 500;
54
67
  res.status(status).json({ ok: false, code: typeof error?.code === 'string' ? error.code : 'TEAM_FAILED', error: error?.message || String(error) });
@@ -121,13 +134,14 @@ export function registerAssistantTeamRoutes(router, { scheduler, orchestrationGu
121
134
  }));
122
135
  router.get('/teams/:id', orchestrationGuard, run(async (req, res, teams) => {
123
136
  if (refuseOthers(req, res, teams, req.params.id)) return;
124
- send(res, await teams.status(req.params.id));
137
+ // `landing.preview` is the landing as the one who asks would be told (an Assistant never lands on a branch that moved).
138
+ send(res, await teams.status(req.params.id, { by: by(req) }));
125
139
  }));
126
140
  router.post('/teams/:id/integrate', orchestrationGuard, run(async (req, res, teams) => {
127
141
  if (refuseOthers(req, res, teams, req.params.id)) return;
128
142
  if (refusePlanning(req, res, 'send the team back to work')) return;
129
143
  const body = req.body || {};
130
- send(res, await teams.integrate(req.params.id, { sliceId: body.sliceId || body.slice_id || body.slice || null }));
144
+ send(res, await teams.integrate(req.params.id, { sliceId: body.sliceId || body.slice_id || body.slice || null, by: by(req) }));
131
145
  }));
132
146
  router.post('/teams/:id/assign', orchestrationGuard, run(async (req, res, teams) => {
133
147
  if (refuseOthers(req, res, teams, req.params.id) || refusePlanning(req, res, 'assign paths to a slice')) return;
@@ -147,6 +161,7 @@ export function registerAssistantTeamRoutes(router, { scheduler, orchestrationGu
147
161
  const who = by(req);
148
162
  send(res, await teams.land(req.params.id, {
149
163
  targetBranch: body.targetBranch || body.target_branch || null, mode, by: who,
164
+ ...expectedHeads(body),
150
165
  // Landing untested or partial work is the owner's word, never an agent's.
151
166
  allowUntested: who.kind === 'owner' && body.allowUntested === true, allowPartial: who.kind === 'owner' && body.allowPartial === true,
152
167
  }));
@@ -210,11 +225,38 @@ export function registerAssistantTeamRoutes(router, { scheduler, orchestrationGu
210
225
  }));
211
226
  }
212
227
 
213
- /** A team as the Agents Studio list shows it: exactly these fields. */
228
+ /** `alreadyOnTarget` as a list row carries it: where the work is and whether the team could go now, or null. */
229
+ const onTargetRow = (value) => (value && typeof value === 'object' && typeof value.branch === 'string' && value.branch
230
+ ? { branch: value.branch, head: typeof value.head === 'string' ? value.head : null, clean: value.clean === true }
231
+ : null);
232
+ const count = (value) => (Number.isInteger(value) && value >= 0 ? value : null);
233
+
234
+ /**
235
+ * A team as the Agents Studio list shows it: exactly these fields. `removable`: a closed team whose record can go
236
+ * now (nothing of it left on disk or in git, no live run); false for every other team. For a team that waits on the
237
+ * owner (needs attention, ready): `liveRuns` (workers still alive), `left` (its worktrees and branches on disk and in
238
+ * git) and `alreadyOnTarget` (a ready team whose work is on its base branch already: `{ branch, head, clean }`);
239
+ * null when not asked or not known.
240
+ */
214
241
  export const teamListRow = (team) => ({
215
242
  id: team.id, project: team.project, title: team.title, status: team.status, density: team.density, slices: team.slices, createdAt: team.createdAt,
243
+ removable: team.removable === true,
244
+ alreadyOnTarget: onTargetRow(team.alreadyOnTarget),
245
+ liveRuns: count(team.liveRuns),
246
+ left: count(team.left),
216
247
  });
217
248
 
249
+ /** Run `fn` over `items`, at most `limit` at a time, the answers in the items' order. */
250
+ async function eachLimited(items, limit, fn) {
251
+ const out = new Array(items.length);
252
+ let next = 0;
253
+ const lane = async () => { while (next < items.length) { const at = next++; out[at] = await fn(items[at], at); } };
254
+ await Promise.all(Array.from({ length: Math.max(1, Math.min(limit, items.length)) }, lane));
255
+ return out;
256
+ }
257
+ /** How many teams the list asks git about at once. */
258
+ export const TEAM_LIST_CONCURRENCY = 4;
259
+
218
260
  /**
219
261
  * One team as Agents Studio reads it (GET /teams/:id): the plan, its slices, the claims, the integration branch and
220
262
  * its last test result, the landing, and the last 100 team events and messages.
@@ -223,7 +265,15 @@ export function teamDetail(answer) {
223
265
  const team = answer.team || {};
224
266
  return {
225
267
  ok: true,
226
- team: { ...teamListRow(team), state: team.state ?? null, attention: team.attention ?? null, sessionId: team.sessionId ?? null, workflowId: team.workflowId ?? null, baseCommit: team.baseCommit ?? null, baseBranch: team.baseBranch ?? null, cap: team.cap ?? null, updatedAt: team.updatedAt ?? null },
268
+ team: {
269
+ ...teamListRow({ ...team, removable: team.removal?.removable === true }), state: team.state ?? null, attention: team.attention ?? null, sessionId: team.sessionId ?? null, workflowId: team.workflowId ?? null,
270
+ baseCommit: team.baseCommit ?? null, baseBranch: team.baseBranch ?? null, cap: team.cap ?? null, updatedAt: team.updatedAt ?? null,
271
+ // A closed team: whether its record can go, and what is still on disk or in git when it cannot (null: open).
272
+ removal: team.removal ?? null,
273
+ // A ready team whose work is on its base branch already, in full: where, whether it is clean, and what is
274
+ // not (uncommitted files per worktree, branches with commits the base branch lacks, other blocks).
275
+ alreadyOnTarget: team.alreadyOnTarget ?? null,
276
+ },
227
277
  plan: answer.plan,
228
278
  slices: (answer.slices || []).map((slice) => ({
229
279
  id: slice.id, title: slice.title, status: slice.status, phase: slice.phase, runId: slice.runId, run: slice.run,
@@ -274,12 +324,23 @@ export function registerTeamStudioRoutes({ route, reader, owner, json, scheduler
274
324
 
275
325
  route('get', '/teams', reader, teamReader, run(async (req, res, teams) => {
276
326
  const q = req.query || {};
277
- res.json({ ok: true, teams: teams.list({ sessionId: sessionOf(req), projectPath: typeof q.project === 'string' && q.project ? q.project : null, open: q.open === '1' || q.open === 'true' }).map(teamListRow) });
327
+ const rows = teams.list({ sessionId: sessionOf(req), projectPath: typeof q.project === 'string' && q.project ? q.project : null, open: q.open === '1' || q.open === 'true' });
328
+ // A closed team, and one that waits on the owner, are asked of git and the disk, a few at a time (the page offers
329
+ // Remove, Clear finished and the cards' quick actions from it); a running team is not asked.
330
+ const out = await eachLimited(rows, TEAM_LIST_CONCURRENCY, async (row) => {
331
+ let facts = {};
332
+ try {
333
+ if (typeof teams.overview === 'function') facts = (await teams.overview(row.id)) || {};
334
+ else if (CLOSED_TEAM_STATUSES.includes(row.status) && typeof teams.removability === 'function') facts = { removable: (await teams.removability(row.id)).removable === true };
335
+ } catch { facts = {}; }
336
+ return teamListRow({ ...row, ...facts });
337
+ });
338
+ res.json({ ok: true, teams: out });
278
339
  }));
279
340
  route('get', '/teams/:id', reader, teamReader, idCheck, run(async (req, res, teams) => {
280
341
  const session = sessionOf(req);
281
342
  if (session !== null && teams.get(req.params.id) && !teams.ownedBy(req.params.id, session)) return send(res, { ok: false, code: 'TEAM_FORBIDDEN', message: 'That team belongs to another Assistant session.' });
282
- const answer = await teams.status(req.params.id, { timeline: 100 });
343
+ const answer = await teams.status(req.params.id, { timeline: 100, by: session !== null ? { kind: 'assistant', sessionId: session } : { kind: 'owner' } });
283
344
  if (!answer.ok) return send(res, answer);
284
345
  res.json(teamDetail(answer));
285
346
  }));
@@ -287,10 +348,33 @@ export function registerTeamStudioRoutes({ route, reader, owner, json, scheduler
287
348
  const body = req.body || {};
288
349
  const mode = String(body.mode || 'ff');
289
350
  if (!LANDING_MODES.includes(mode)) return send(res, { ok: false, code: 'INVALID_MODE', message: `mode is one of ${LANDING_MODES.join(', ')}.` });
290
- send(res, await teams.land(req.params.id, { targetBranch: body.targetBranch || body.target_branch || null, mode, by: { kind: 'owner' }, allowUntested: body.allowUntested === true, allowPartial: body.allowPartial === true }));
351
+ send(res, await teams.land(req.params.id, { targetBranch: body.targetBranch || body.target_branch || null, mode, by: { kind: 'owner' }, ...expectedHeads(body), allowUntested: body.allowUntested === true, allowPartial: body.allowPartial === true }));
291
352
  }));
292
353
  route('post', '/teams/:id/discard', json, owner, idCheck, run(async (req, res, teams) => {
293
354
  const body = req.body || {};
294
- send(res, await teams.discard(req.params.id, { by: { kind: 'owner' }, force: body.force === true, reason: typeof body.reason === 'string' ? body.reason : '' }));
355
+ // `remove: true` (Discard & remove): the record goes too, in the same step, once the discard left nothing.
356
+ send(res, await teams.discard(req.params.id, { by: { kind: 'owner' }, force: body.force === true, remove: body.remove === true, reason: typeof body.reason === 'string' ? body.reason : '' }));
357
+ }));
358
+ // A ready team whose work is on its base branch already: its worktrees, branches and record, in one step, once
359
+ // git says again that nothing would be lost (the owner's page, `userConfirmed: true`).
360
+ route('post', '/teams/:id/cleanup-merged', json, owner, idCheck, run(async (req, res, teams) => {
361
+ if (typeof teams.cleanupMerged !== 'function') return unavailable(res);
362
+ const body = req.body || {};
363
+ send(res, await teams.cleanupMerged(req.params.id, { by: { kind: 'owner' }, userConfirmed: body.userConfirmed === true || body.user_confirmed === true }));
364
+ }));
365
+ // The owner cleans up a landed team's worktrees and branches. The owner's page is the confirmation (with
366
+ // `userConfirmed: true`), so no Assistant turn is asked for; every other check of the scheduler's stays.
367
+ route('post', '/teams/:id/cleanup', json, owner, idCheck, run(async (req, res, teams) => {
368
+ const body = req.body || {};
369
+ send(res, await teams.cleanup(req.params.id, { by: { kind: 'owner' }, userConfirmed: body.userConfirmed === true || body.user_confirmed === true }));
370
+ }));
371
+ // Every closed team that can go; the rest are listed as skipped, with why.
372
+ route('post', '/teams/clear-finished', json, owner, run(async (req, res, teams) => {
373
+ const body = req.body || {};
374
+ send(res, await teams.clearFinished({ by: { kind: 'owner' }, projectPath: typeof body.project === 'string' && body.project ? body.project : null }));
375
+ }));
376
+ // A closed team's record, once nothing of it is left on disk or in git.
377
+ route('delete', '/teams/:id', json, owner, idCheck, run(async (req, res, teams) => {
378
+ send(res, await teams.remove(req.params.id, { by: { kind: 'owner' } }));
295
379
  }));
296
380
  }
@@ -86,6 +86,8 @@ export function createTeams({ store, git = createGitRunner(), runTests = createT
86
86
  plan: async (teamId) => (await worktrees.get(teamId))?.plan || null,
87
87
  list: worktrees.list,
88
88
  inspect: worktrees.inspect,
89
+ /** A ready team whose work is on its base branch already (merged outside land): where, and whether it is clean. Read only. */
90
+ onTarget: worktrees.onTarget,
89
91
  startSlice,
90
92
  finishSlice: integration.finishSlice,
91
93
  finishReadOnlySlice: async (teamId, sliceId, options) => {
@@ -102,6 +104,8 @@ export function createTeams({ store, git = createGitRunner(), runTests = createT
102
104
  resolveInSlice: integration.resolveInSlice,
103
105
  acceptIntegrationHead: integration.acceptIntegrationHead,
104
106
  land: landing.land,
107
+ /** What a landing sent now would be told, without moving anything: the checks of `land` itself. Read only. */
108
+ landingPreview: landing.preview,
105
109
  remove,
106
110
  prune: worktrees.prune,
107
111
  recover: recovery.recover,