@synap-core/cli 1.13.0 → 1.13.1-next.20261102.ec3d166

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 (221) hide show
  1. package/README.md +13 -3
  2. package/dist/build-info.json +2 -3
  3. package/dist/commands/agents.js +12 -2
  4. package/dist/commands/agents.js.map +1 -1
  5. package/dist/commands/capability.d.ts +86 -0
  6. package/dist/commands/capability.js +117 -30
  7. package/dist/commands/capability.js.map +1 -1
  8. package/dist/commands/data-extra.d.ts +13 -0
  9. package/dist/commands/data-extra.js +23 -2
  10. package/dist/commands/data-extra.js.map +1 -1
  11. package/dist/commands/doctor.d.ts +18 -0
  12. package/dist/commands/doctor.js +28 -1
  13. package/dist/commands/doctor.js.map +1 -1
  14. package/dist/commands/init.js +4 -2
  15. package/dist/commands/init.js.map +1 -1
  16. package/dist/commands/keys-request.d.ts +48 -0
  17. package/dist/commands/keys-request.js +236 -0
  18. package/dist/commands/keys-request.js.map +1 -0
  19. package/dist/commands/keys-request.test.d.ts +1 -0
  20. package/dist/commands/keys-request.test.js +176 -0
  21. package/dist/commands/keys-request.test.js.map +1 -0
  22. package/dist/commands/knowledge.d.ts +6 -0
  23. package/dist/commands/knowledge.js +9 -1
  24. package/dist/commands/knowledge.js.map +1 -1
  25. package/dist/commands/market.d.ts +61 -4
  26. package/dist/commands/market.js +106 -48
  27. package/dist/commands/market.js.map +1 -1
  28. package/dist/commands/mcp.d.ts +1 -1
  29. package/dist/commands/mcp.js +14 -9
  30. package/dist/commands/mcp.js.map +1 -1
  31. package/dist/commands/pods.js +6 -2
  32. package/dist/commands/pods.js.map +1 -1
  33. package/dist/commands/proposals-actions.js +7 -1
  34. package/dist/commands/proposals-actions.js.map +1 -1
  35. package/dist/commands/providers.d.ts +22 -6
  36. package/dist/commands/providers.js +39 -32
  37. package/dist/commands/providers.js.map +1 -1
  38. package/dist/commands/raycast.d.ts +15 -0
  39. package/dist/commands/raycast.js +36 -10
  40. package/dist/commands/raycast.js.map +1 -1
  41. package/dist/commands/status.js +12 -6
  42. package/dist/commands/status.js.map +1 -1
  43. package/dist/commands/statusline.backoff.test.js +13 -3
  44. package/dist/commands/statusline.backoff.test.js.map +1 -1
  45. package/dist/commands/statusline.d.ts +104 -9
  46. package/dist/commands/statusline.js +392 -148
  47. package/dist/commands/statusline.js.map +1 -1
  48. package/dist/commands/statusline.line2.test.d.ts +15 -0
  49. package/dist/commands/statusline.line2.test.js +226 -0
  50. package/dist/commands/statusline.line2.test.js.map +1 -0
  51. package/dist/commands/statusline.needs-you.test.d.ts +1 -0
  52. package/dist/commands/statusline.needs-you.test.js +17 -0
  53. package/dist/commands/statusline.needs-you.test.js.map +1 -0
  54. package/dist/commands/statusline.now.test.d.ts +10 -0
  55. package/dist/commands/statusline.now.test.js +250 -0
  56. package/dist/commands/statusline.now.test.js.map +1 -0
  57. package/dist/commands/tracks.d.ts +1 -0
  58. package/dist/commands/tracks.js +4 -0
  59. package/dist/commands/tracks.js.map +1 -1
  60. package/dist/commands/upload.js +12 -0
  61. package/dist/commands/upload.js.map +1 -1
  62. package/dist/commands/wait.d.ts +124 -0
  63. package/dist/commands/wait.js +384 -0
  64. package/dist/commands/wait.js.map +1 -0
  65. package/dist/commands/wait.test.d.ts +8 -0
  66. package/dist/commands/wait.test.js +308 -0
  67. package/dist/commands/wait.test.js.map +1 -0
  68. package/dist/commands/worker-github-app.d.ts +63 -0
  69. package/dist/commands/worker-github-app.js +161 -0
  70. package/dist/commands/worker-github-app.js.map +1 -0
  71. package/dist/commands/worker-github-app.test.d.ts +1 -0
  72. package/dist/commands/worker-github-app.test.js +102 -0
  73. package/dist/commands/worker-github-app.test.js.map +1 -0
  74. package/dist/commands/worker-github-broker.d.ts +39 -0
  75. package/dist/commands/worker-github-broker.js +106 -0
  76. package/dist/commands/worker-github-broker.js.map +1 -0
  77. package/dist/commands/worker-github-broker.test.d.ts +1 -0
  78. package/dist/commands/worker-github-broker.test.js +90 -0
  79. package/dist/commands/worker-github-broker.test.js.map +1 -0
  80. package/dist/commands/worker-runs.test.d.ts +1 -0
  81. package/dist/commands/worker-runs.test.js +150 -0
  82. package/dist/commands/worker-runs.test.js.map +1 -0
  83. package/dist/commands/worker-worktrees.d.ts +34 -0
  84. package/dist/commands/worker-worktrees.js +87 -0
  85. package/dist/commands/worker-worktrees.js.map +1 -0
  86. package/dist/commands/worker.d.ts +192 -5
  87. package/dist/commands/worker.js +467 -45
  88. package/dist/commands/worker.js.map +1 -1
  89. package/dist/commands/worker.test.js +269 -3
  90. package/dist/commands/worker.test.js.map +1 -1
  91. package/dist/index.js +59 -4
  92. package/dist/index.js.map +1 -1
  93. package/dist/lib/agents-config.d.ts +9 -0
  94. package/dist/lib/agents-config.js +20 -0
  95. package/dist/lib/agents-config.js.map +1 -1
  96. package/dist/lib/atomic-file.d.ts +20 -1
  97. package/dist/lib/atomic-file.js +100 -2
  98. package/dist/lib/atomic-file.js.map +1 -1
  99. package/dist/lib/auth.d.ts +25 -0
  100. package/dist/lib/auth.js +49 -9
  101. package/dist/lib/auth.js.map +1 -1
  102. package/dist/lib/box/job-server.js +4 -0
  103. package/dist/lib/box/job-server.js.map +1 -1
  104. package/dist/lib/bridge-invocation.test.d.ts +1 -0
  105. package/dist/lib/bridge-invocation.test.js +75 -0
  106. package/dist/lib/bridge-invocation.test.js.map +1 -0
  107. package/dist/lib/bridge-status.d.ts +144 -0
  108. package/dist/lib/bridge-status.js +227 -0
  109. package/dist/lib/bridge-status.js.map +1 -0
  110. package/dist/lib/bridge-status.test.d.ts +6 -0
  111. package/dist/lib/bridge-status.test.js +197 -0
  112. package/dist/lib/bridge-status.test.js.map +1 -0
  113. package/dist/lib/client-header.test.js +19 -1
  114. package/dist/lib/client-header.test.js.map +1 -1
  115. package/dist/lib/conversation-headers.d.ts +67 -2
  116. package/dist/lib/conversation-headers.js +122 -6
  117. package/dist/lib/conversation-headers.js.map +1 -1
  118. package/dist/lib/conversation-headers.test.d.ts +1 -0
  119. package/dist/lib/conversation-headers.test.js +78 -0
  120. package/dist/lib/conversation-headers.test.js.map +1 -0
  121. package/dist/lib/credential-class.d.ts +12 -1
  122. package/dist/lib/credential-class.js +20 -0
  123. package/dist/lib/credential-class.js.map +1 -1
  124. package/dist/lib/device-connect.d.ts +45 -0
  125. package/dist/lib/device-connect.js +60 -0
  126. package/dist/lib/device-connect.js.map +1 -1
  127. package/dist/lib/goal-words.js +6 -3
  128. package/dist/lib/goal-words.js.map +1 -1
  129. package/dist/lib/hub-client.d.ts +59 -1
  130. package/dist/lib/hub-client.js +130 -36
  131. package/dist/lib/hub-client.js.map +1 -1
  132. package/dist/lib/key-locations.d.ts +3 -3
  133. package/dist/lib/key-locations.js +3 -39
  134. package/dist/lib/key-locations.js.map +1 -1
  135. package/dist/lib/machine-instance.d.ts +7 -5
  136. package/dist/lib/machine-instance.js +7 -5
  137. package/dist/lib/machine-instance.js.map +1 -1
  138. package/dist/lib/mcp-bridge.d.ts +43 -0
  139. package/dist/lib/mcp-bridge.js +199 -11
  140. package/dist/lib/mcp-bridge.js.map +1 -1
  141. package/dist/lib/mcp-bridge.test.js +194 -2
  142. package/dist/lib/mcp-bridge.test.js.map +1 -1
  143. package/dist/lib/mcp-call.d.ts +5 -1
  144. package/dist/lib/mcp-call.js +7 -6
  145. package/dist/lib/mcp-call.js.map +1 -1
  146. package/dist/lib/mcp-connector-url.test.d.ts +1 -0
  147. package/dist/lib/mcp-connector-url.test.js +13 -0
  148. package/dist/lib/mcp-connector-url.test.js.map +1 -0
  149. package/dist/lib/mcp-snippets.d.ts +16 -0
  150. package/dist/lib/mcp-snippets.js +20 -2
  151. package/dist/lib/mcp-snippets.js.map +1 -1
  152. package/dist/lib/now-line.d.ts +66 -0
  153. package/dist/lib/now-line.js +193 -0
  154. package/dist/lib/now-line.js.map +1 -0
  155. package/dist/lib/now-line.test.d.ts +5 -0
  156. package/dist/lib/now-line.test.js +177 -0
  157. package/dist/lib/now-line.test.js.map +1 -0
  158. package/dist/lib/package-updates.d.ts +66 -0
  159. package/dist/lib/package-updates.js +76 -0
  160. package/dist/lib/package-updates.js.map +1 -0
  161. package/dist/lib/pod.d.ts +0 -4
  162. package/dist/lib/pod.js +0 -7
  163. package/dist/lib/pod.js.map +1 -1
  164. package/dist/lib/register-claude-code-mcp.test.js +19 -0
  165. package/dist/lib/register-claude-code-mcp.test.js.map +1 -1
  166. package/dist/lib/safe-open.d.ts +5 -3
  167. package/dist/lib/safe-open.js +9 -8
  168. package/dist/lib/safe-open.js.map +1 -1
  169. package/dist/lib/self-host.d.ts +17 -0
  170. package/dist/lib/self-host.js +24 -0
  171. package/dist/lib/self-host.js.map +1 -0
  172. package/dist/lib/targets.d.ts +31 -0
  173. package/dist/lib/targets.js +100 -104
  174. package/dist/lib/targets.js.map +1 -1
  175. package/dist/lib/term.d.ts +24 -0
  176. package/dist/lib/term.js +52 -0
  177. package/dist/lib/term.js.map +1 -0
  178. package/dist/lib/term.test.d.ts +1 -0
  179. package/dist/lib/term.test.js +29 -0
  180. package/dist/lib/term.test.js.map +1 -0
  181. package/dist/lib/transcript-index.d.ts +94 -0
  182. package/dist/lib/transcript-index.js +321 -0
  183. package/dist/lib/transcript-index.js.map +1 -0
  184. package/dist/lib/transcript-index.test.d.ts +10 -0
  185. package/dist/lib/transcript-index.test.js +200 -0
  186. package/dist/lib/transcript-index.test.js.map +1 -0
  187. package/dist/lib/wait-help.d.ts +11 -0
  188. package/dist/lib/wait-help.js +25 -0
  189. package/dist/lib/wait-help.js.map +1 -0
  190. package/dist/lib/wait-state.d.ts +57 -0
  191. package/dist/lib/wait-state.js +114 -0
  192. package/dist/lib/wait-state.js.map +1 -0
  193. package/package.json +2 -2
  194. package/skills/synap/SKILL.md +71 -38
  195. package/skills/synap/code-skills.md +15 -1
  196. package/skills/synap/concepts.md +36 -26
  197. package/skills/synap/document-embeds.md +15 -1
  198. package/skills/synap/focus-sessions.md +4 -4
  199. package/skills/synap/from-intent.md +2 -2
  200. package/skills/synap/governance-rules.md +2 -0
  201. package/skills/synap/reflexes.md +4 -4
  202. package/skills/synap/work-model.md +1 -1
  203. package/skills/synap/writing-titles.md +7 -0
  204. package/skills/synap-app/SKILL.md +2 -2
  205. package/skills/synap-app/overview.md +2 -2
  206. package/skills/synap-market/SKILL.md +1 -1
  207. package/skills/synap-market/governance-and-catalog.md +1 -1
  208. package/skills/synap-schema/SKILL.md +4 -1
  209. package/skills/synap-schema/intent-vocabulary-ssot.md +4 -1
  210. package/dist/commands/template.d.ts +0 -42
  211. package/dist/commands/template.js +0 -191
  212. package/dist/commands/template.js.map +0 -1
  213. package/dist/lib/browser-auth.d.ts +0 -35
  214. package/dist/lib/browser-auth.js +0 -170
  215. package/dist/lib/browser-auth.js.map +0 -1
  216. package/dist/lib/openclaw.d.ts +0 -32
  217. package/dist/lib/openclaw.js +0 -165
  218. package/dist/lib/openclaw.js.map +0 -1
  219. package/dist/lib/seed.d.ts +0 -13
  220. package/dist/lib/seed.js +0 -135
  221. package/dist/lib/seed.js.map +0 -1
@@ -0,0 +1,87 @@
1
+ /**
2
+ * One tree folder per code run, so two runs at once never share a checkout
3
+ * (finding f94c0287: both worked in the one clone under `--cwd`).
4
+ *
5
+ * The worker's `--cwd` is usually a folder OF repos, not a repo, so the worker
6
+ * cannot create the worktree itself: it gives the run an empty folder
7
+ * (`<state>/trees/<short id>`) as its cwd, the prompt tells the run to make its
8
+ * worktrees there (`git -C <cwd>/<repo> worktree add <folder>/<repo> …`), and
9
+ * when the run ends the worker sweeps the folder: a worktree with no
10
+ * uncommitted change and no commit that is not on a remote is removed; any
11
+ * other is KEPT, and named in the run's result.
12
+ */
13
+ import { execFile } from "node:child_process";
14
+ import fs from "node:fs";
15
+ import path from "node:path";
16
+ export const defaultGit = (cwd, args) => new Promise((resolve) => {
17
+ execFile("git", args, { cwd, timeout: 60_000, maxBuffer: 16 * 1024 * 1024 }, (err, stdout) => {
18
+ const code = err ? (typeof err.code === "number" ? err.code : 1) : 0;
19
+ resolve({ code, stdout: String(stdout ?? "") });
20
+ });
21
+ });
22
+ export function treeFolderFor(treesRoot, sessionId) {
23
+ return path.join(treesRoot, sessionId.slice(0, 8));
24
+ }
25
+ /** The run's own folder under the trees root; created owner-only. */
26
+ export function ensureTreeFolder(folder) {
27
+ fs.mkdirSync(folder, { recursive: true, mode: 0o700 });
28
+ }
29
+ /**
30
+ * Removes the run's clean worktrees. A failed check is a reason to KEEP, never
31
+ * "clean": an unreadable status must not delete work.
32
+ */
33
+ export async function sweepTreeFolder(folder, git = defaultGit) {
34
+ const out = { removed: [], kept: [] };
35
+ let entries;
36
+ try {
37
+ entries = fs.readdirSync(folder, { withFileTypes: true });
38
+ }
39
+ catch {
40
+ return out;
41
+ }
42
+ for (const e of entries) {
43
+ const dir = path.join(folder, e.name);
44
+ if (!e.isDirectory())
45
+ continue;
46
+ if (!fs.existsSync(path.join(dir, ".git"))) {
47
+ out.kept.push({ dir, why: "not a git worktree" });
48
+ continue;
49
+ }
50
+ const status = await git(dir, ["status", "--porcelain"]);
51
+ if (status.code !== 0) {
52
+ out.kept.push({ dir, why: "git status failed" });
53
+ continue;
54
+ }
55
+ if (status.stdout.trim()) {
56
+ out.kept.push({ dir, why: "uncommitted changes" });
57
+ continue;
58
+ }
59
+ // Commits reachable from HEAD that no remote-tracking ref has: unpushed work.
60
+ const unpushed = await git(dir, ["rev-list", "--count", "HEAD", "--not", "--remotes"]);
61
+ if (unpushed.code !== 0 || Number(unpushed.stdout.trim()) !== 0) {
62
+ out.kept.push({ dir, why: unpushed.code !== 0 ? "git rev-list failed" : "unpushed commits" });
63
+ continue;
64
+ }
65
+ const common = await git(dir, ["rev-parse", "--path-format=absolute", "--git-common-dir"]);
66
+ if (common.code !== 0) {
67
+ out.kept.push({ dir, why: "git-common-dir failed" });
68
+ continue;
69
+ }
70
+ // Run from the main repo: git refuses to remove the worktree it is run in.
71
+ const removed = await git(path.dirname(common.stdout.trim()), ["worktree", "remove", dir]);
72
+ if (removed.code !== 0)
73
+ out.kept.push({ dir, why: "git worktree remove refused" });
74
+ else
75
+ out.removed.push(dir);
76
+ }
77
+ if (!out.kept.length) {
78
+ try {
79
+ fs.rmdirSync(folder);
80
+ }
81
+ catch {
82
+ /* not empty: something else is in it, leave it */
83
+ }
84
+ }
85
+ return out;
86
+ }
87
+ //# sourceMappingURL=worker-worktrees.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-worktrees.js","sourceRoot":"","sources":["../../src/commands/worker-worktrees.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAQ7B,MAAM,CAAC,MAAM,UAAU,GAAU,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAC7C,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;IACtB,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI,EAAE,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;QAC3F,MAAM,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,OAAQ,GAA0B,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAE,GAAwB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACnH,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEL,MAAM,UAAU,aAAa,CAAC,SAAiB,EAAE,SAAiB;IAChE,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,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IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,6BAA6B,EAAE,CAAC,CAAC;;YAC9E,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QACrB,IAAI,CAAC;YACH,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACvB,CAAC;QAAC,MAAM,CAAC;YACP,kDAAkD;QACpD,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -41,8 +41,13 @@
41
41
  * State (which sessions were launched, their Claude session ids and outcome)
42
42
  * lives in ~/.synap/worker/<agent>/state.json; each run's stream-json goes to
43
43
  * ~/.synap/worker/<agent>/runs/<sessionId>.jsonl. Neither ever holds a token.
44
+ * A run's verdict is ALSO recorded on its session (`settle`), and the worker's
45
+ * orient poll carries its served stamp (`X-Synap-Runner`): the pod's proof
46
+ * that a process serves this agent.
44
47
  */
45
48
  import { type McpCallClient } from "../lib/mcp-call.js";
49
+ import { type GithubRunEnv, type InstallationTokenSource } from "./worker-github-app.js";
50
+ import { type GitFn } from "./worker-worktrees.js";
46
51
  export interface WorkerOptions {
47
52
  agent: string;
48
53
  interval?: string;
@@ -56,12 +61,21 @@ export interface WorkerOptions {
56
61
  dryRun?: boolean;
57
62
  /** The Claude accounts file (default ~/.config/synap-worker/accounts.json, used when it exists). */
58
63
  accounts?: string;
64
+ /** The GitHub App env file ({GITHUB_APP_ID, GITHUB_APP_PRIVATE_KEY_FILE}; default ~/.config/synap-agent-app.env when it exists). */
65
+ githubApp?: string;
59
66
  /** Where work-folder runs get their folder, one per session (default ~/synap-work). */
60
67
  workRoot?: string;
61
68
  }
62
69
  export interface HandedItem {
63
70
  id: string;
64
71
  goal: string | null;
72
+ /**
73
+ * A session that went quiet (stale) while handed to this agent, handed back
74
+ * to be RESUMED: it never launches fresh. Absent from an older pod's items.
75
+ */
76
+ resume?: true;
77
+ /** When it went quiet (ISO), with `resume`. */
78
+ quietSince?: string;
65
79
  }
66
80
  /** `limited`: cut off by a usage limit, waiting to be resumed on another account. */
67
81
  export type RunStatus = "running" | "done" | "failed" | "limited";
@@ -94,6 +108,40 @@ export interface RunRecord {
94
108
  protocol?: WorkerProtocol;
95
109
  /** A work-folder run's folder: its cwd, which every resume reuses (Claude finds a conversation by its cwd). */
96
110
  workDir?: string;
111
+ /** A code run's own folder for its worktrees: its cwd, which every resume reuses. */
112
+ treeDir?: string;
113
+ /** Worktrees a finished run left because they hold unpushed or uncommitted work. */
114
+ keptTrees?: string[];
115
+ /** The latest launch's process identity (`X-Synap-Process`), what its runner row is keyed by. */
116
+ process?: string;
117
+ /** The model the run's Claude Code said it runs (its stream's `init`), reported as `X-Synap-Model`. */
118
+ model?: string;
119
+ /** The quiet period (its `quietSince`, "" when the pod gave none) this run was last resumed for. */
120
+ resumedQuietSince?: string;
121
+ /** The latest launch's end, not yet recorded on the pod (`settle`): retried each tick until it lands. */
122
+ unsettled?: PendingSettle;
123
+ /** When the latest end was recorded on the pod. */
124
+ settledAt?: string;
125
+ }
126
+ /**
127
+ * A run's end the pod has not heard yet, saved before the first try so that a
128
+ * crash or an MCP blip between the local save and the pod write loses nothing:
129
+ * the next tick (of this worker, or of the next one after a restart) retries it.
130
+ * It names its own launch, so a later resume of the same session never changes
131
+ * which runner it ends or which Result post it is.
132
+ */
133
+ export interface PendingSettle {
134
+ /** The launch's process identity and conversation: what the pod's runner row is keyed by. */
135
+ process?: string;
136
+ claudeSessionId?: string;
137
+ /** The verdict to record; absent: the pod only hears the runner ended. */
138
+ verdict?: {
139
+ status: VerdictStatus;
140
+ sentence: string;
141
+ };
142
+ /** The Result post's `idempotencyKey`: a retry returns the post that already landed. */
143
+ key: string;
144
+ attempts: number;
97
145
  }
98
146
  interface WorkerState {
99
147
  runs: Record<string, RunRecord>;
@@ -129,7 +177,11 @@ export declare function parseHandedToYou(orientText: string): HandedItem[];
129
177
  */
130
178
  export declare const LAUNCH_RETRY_BASE_MS: number;
131
179
  export declare const MAX_LAUNCH_RETRIES = 4;
132
- /** Sessions to launch now: never launched, or due a relaunch (see above). */
180
+ /**
181
+ * Sessions to launch now: never launched, or due a relaunch (see above). A
182
+ * `resume` item is never one of them: it continues its conversation or waits
183
+ * (see `tick`), so an empty state file never relaunches every quiet session.
184
+ */
133
185
  export declare function pickNew(items: HandedItem[], state: WorkerState, slots: number, now?: number): HandedItem[];
134
186
  /**
135
187
  * The pod MCP server every run gets, under this name, carrying the WORKER
@@ -139,11 +191,36 @@ export declare function pickNew(items: HandedItem[], state: WorkerState, slots:
139
191
  * then read its own posts as follow-ups (2026-10-20).
140
192
  */
141
193
  export declare const RUN_MCP_SERVER = "synap-worker";
194
+ /**
195
+ * The provider every run's model is served by: Anthropic, on the account's
196
+ * subscription. By construction of the run's environment (`workerEnv`): no
197
+ * `ANTHROPIC_*` (key, token, base URL) and no provider switch
198
+ * (`RUN_ENV_BLOCKLIST`) reaches it. Reported as `X-Synap-Model-Provider`.
199
+ */
200
+ export declare const WORKER_MODEL_PROVIDER = "anthropic";
142
201
  export declare function runMcpConfig(podUrl: string, apiKey: string,
143
202
  /** The run's Claude session id: names the conversation to the pod, one id across resumes. */
144
- claudeSessionId?: string): {
203
+ claudeSessionId?: string,
204
+ /** The launch's process identity (`runProcessIdentity`): the pod keeps one runner row per process. */
205
+ processIdentity?: string,
206
+ /** The model the run is known to use (a resume: what its first launch said), when known. */
207
+ model?: string): {
145
208
  mcpServers: Record<string, unknown>;
146
209
  };
210
+ /**
211
+ * A launch's process identity, `<host>:<pid>:<startedAtMs>` (the pod's
212
+ * `X-Synap-Process`). The config is written before `claude` exists, so the pid
213
+ * is the worker's and the time is the launch's: a resume is a new launch and
214
+ * reads as a new process, never a twin of the one that ended.
215
+ */
216
+ export declare function runProcessIdentity(launchedAtMs: number, hostname?: string, pid?: number): string;
217
+ /**
218
+ * The headers of the worker's calls once a run's process exited: the run's
219
+ * conversation and process, state `ended`, so the pod ends that runner at once
220
+ * rather than when its live window runs out. None for a run that never named
221
+ * its conversation or process.
222
+ */
223
+ export declare function runEndHeaders(rec: Pick<RunRecord, "claudeSessionId" | "process" | "model">): Record<string, string> | undefined;
147
224
  /** Writes the run config owner-only (it holds the key) and returns its path. */
148
225
  export declare function writeRunMcpConfig(dir: string, config: {
149
226
  mcpServers: Record<string, unknown>;
@@ -162,6 +239,8 @@ export declare function buildWorkerPrompt(p: {
162
239
  mcpServer: string;
163
240
  /** A design run: the deliverable is a claude.ai Design artifact. */
164
241
  design?: boolean;
242
+ /** A code run's own folder: where its worktrees go, so two runs never share a checkout. */
243
+ treeDir?: string;
165
244
  }): string;
166
245
  /** How long a work-folder run waits for an answer to its ask before it ends `blocked`. */
167
246
  export declare const ASK_WAIT_MINUTES = 30;
@@ -179,10 +258,24 @@ export declare function buildWorkFolderPrompt(p: {
179
258
  mcpServer: string;
180
259
  }): string;
181
260
  /**
182
- * The launched environment: the subscription, never a stray API key. With an
183
- * account picked, its token REPLACES any token the worker inherited.
261
+ * What the allowlist's `CLAUDE_*` must NOT pass: the variables that switch
262
+ * Claude Code off the subscription to another provider (Bedrock, Vertex,
263
+ * Foundry, Bedrock Mantle, Claude Platform on AWS — `CLAUDE_CODE_USE_*`), skip
264
+ * that provider's own auth for a gateway (`CLAUDE_CODE_SKIP_*_AUTH`), or hand
265
+ * routing to a host platform (`CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST`). Any
266
+ * future `CLAUDE_CODE_USE_*` provider is blocked too; the one `USE_` flag that
267
+ * is not a provider (the Windows PowerShell tool) passes. Without this a run
268
+ * would report `anthropic` while another provider served it.
269
+ */
270
+ export declare const RUN_ENV_BLOCKLIST: RegExp[];
271
+ export declare const RUN_ENV_ALLOWLIST: RegExp[];
272
+ /**
273
+ * The launched environment, built from an ALLOWLIST: a secret in the worker's
274
+ * own environment (its env file holds deploy tokens) never reaches a run's
275
+ * Bash. The subscription, never a stray API key. With an account picked, its
276
+ * token REPLACES any token the worker inherited. GitHub: only the App's.
184
277
  */
185
- export declare function workerEnv(base: NodeJS.ProcessEnv, claudeConfigDir?: string, oauthToken?: string): NodeJS.ProcessEnv;
278
+ export declare function workerEnv(base: NodeJS.ProcessEnv, claudeConfigDir?: string, oauthToken?: string, github?: GithubRunEnv): NodeJS.ProcessEnv;
186
279
  export interface LimitHit {
187
280
  error: string;
188
281
  /** When the limit lifts (ms), when Claude Code said. */
@@ -191,6 +284,8 @@ export interface LimitHit {
191
284
  /** What one run's events say about how it ended. */
192
285
  export interface RunEnd {
193
286
  claudeSessionId?: string;
287
+ /** The model the stream's `init` names, when it is an id the pod keeps. */
288
+ model?: string;
194
289
  /** The `result` text (stream) or the last main assistant text (transcript). */
195
290
  text?: string;
196
291
  /** Set when the run's LAST main-thread turn was refused by a usage limit. */
@@ -275,6 +370,83 @@ export declare const BG_BLOCKED_MAX_MS: number;
275
370
  export declare const BG_SETTLE_MS: number;
276
371
  /** The final `WORKER-RESULT:` line of a run's result text, if present. */
277
372
  export declare function workerVerdict(resultText: string | undefined): string | undefined;
373
+ export type VerdictStatus = "done" | "blocked" | "failed";
374
+ /**
375
+ * `done — <sentence>` (a `workerVerdict`) → its status and sentence; anything
376
+ * else is no verdict. The prompt's own template echoed back
377
+ * (`done | blocked | failed — …`) names no status: it is no verdict either.
378
+ */
379
+ export declare function parseVerdict(verdict: string | undefined): {
380
+ status: VerdictStatus;
381
+ sentence: string;
382
+ } | undefined;
383
+ /**
384
+ * The verdict the session hears, given how the process ended: `done` only from
385
+ * a run that exited cleanly; a run that said `done` and then exited non-zero is
386
+ * `failed`, with what it said kept. `blocked` and `failed` stand as they are.
387
+ */
388
+ export declare function verdictForExit(v: {
389
+ status: VerdictStatus;
390
+ sentence: string;
391
+ }, exitedOk: boolean, exitCode?: number | null): {
392
+ status: VerdictStatus;
393
+ sentence: string;
394
+ };
395
+ /** The one room line a verdict becomes. */
396
+ export declare function verdictRoomLine(v: {
397
+ status: VerdictStatus;
398
+ sentence: string;
399
+ }): string;
400
+ /**
401
+ * What the room hears from a run that FAILED without a verdict (it crashed,
402
+ * exited non-zero without `WORKER-RESULT:`, sat blocked, vanished, ran out of
403
+ * usage-limit resumes, or the worker restarted under it): how it ended and the
404
+ * reason the record keeps, on one line.
405
+ */
406
+ export declare function deadRunSentence(rec: Pick<RunRecord, "result" | "exitCode">): string;
407
+ /**
408
+ * At most this many tries to record one run's end on the pod. A retry runs
409
+ * only after the tick's orient read answered, so a pod outage does not use them up.
410
+ */
411
+ export declare const MAX_SETTLE_ATTEMPTS = 10;
412
+ /**
413
+ * The end a run owes the pod, given what it said and how its process ended:
414
+ * its verdict (`verdictForExit`), or for a run that failed without one a
415
+ * synthesised `failed` (`deadRunSentence`), so a dead run is never silent.
416
+ * `undefined` when there is nothing to tell (no verdict, not failed, and no
417
+ * runner to end).
418
+ */
419
+ export declare function pendingSettle(rec: RunRecord, verdictLine: string | undefined, exitedOk: boolean): PendingSettle | undefined;
420
+ /**
421
+ * Outcome kinds a verdict never claims: a pull request is delivered only when
422
+ * it merges (rule work-units), and the merge sweeper marks it met then; a
423
+ * branch or a commit is a step toward that PR, not a deliverable of its own.
424
+ */
425
+ export declare const UNCLAIMABLE_OUTCOME_KINDS: ReadonlySet<string>;
426
+ /** What the session read says a `done` verdict may claim. */
427
+ export type VerdictClaim = {
428
+ kind: "one";
429
+ key: string;
430
+ } | {
431
+ kind: "none";
432
+ } | {
433
+ kind: "several";
434
+ keys: string[];
435
+ }
436
+ /** The outcomes list could not be read: nothing is claimed, and that is said. */
437
+ | {
438
+ kind: "unreadable";
439
+ why: string;
440
+ };
441
+ /**
442
+ * The outcome a `done` verdict claims, from the `synap_get_session` read: the
443
+ * session's ONE open deliverable the agent owns (not a fact, not the person's,
444
+ * not met, not withdrawn, never a PR, branch or commit). None, or several, and
445
+ * nothing is claimed: which of several the run finished is the run's to say
446
+ * (it claims each as it records it). An outcomes list that could not be read is
447
+ * `unreadable`, never "none open".
448
+ */
449
+ export declare function verdictClaim(getSessionText: string): VerdictClaim;
278
450
  export interface RoomMessage {
279
451
  id?: string;
280
452
  content?: string;
@@ -290,6 +462,17 @@ export declare const MAX_RESUMES = 20;
290
462
  * run. The worker's own posts carry its agent id and never resume it.
291
463
  */
292
464
  export declare function followUpsSince(messages: RoomMessage[], since: string, selfAgentId: string): RoomMessage[];
465
+ /**
466
+ * Whether a session's quiet period began with THIS worker's own run: the pod's
467
+ * `quietSince` is the session's newest activity, and the run's own room posts
468
+ * (its claim, its "Look at first:", the worker's `Result:` line) count. Quiet
469
+ * since then means the run ended and nothing happened after it; resuming it
470
+ * would only re-run it (up to MAX_RESUMES paid runs). Someone else's message
471
+ * after the run resumes it through the follow-up path instead.
472
+ */
473
+ export declare function quietIsOwnRun(item: Pick<HandedItem, "quietSince">, rec: Pick<RunRecord, "launchedAt">): boolean;
474
+ /** The prompt that resumes a run whose session went quiet and was handed back (`resume`). */
475
+ export declare function buildQuietResumePrompt(quietSince: string | undefined): string;
293
476
  /** The prompt that resumes a finished run with the room's new messages. */
294
477
  export declare function buildFollowUpPrompt(messages: RoomMessage[]): string;
295
478
  export interface ExecResult {
@@ -313,6 +496,10 @@ export interface WorkerDeps {
313
496
  fetchImpl?: typeof fetch;
314
497
  now?: () => number;
315
498
  say?: (line: string) => void;
499
+ /** The App's installation token (tests stub it); default: from the GitHub App file, when there is one. */
500
+ githubToken?: InstallationTokenSource;
501
+ /** `git` for the worktree sweep (tests stub it). */
502
+ git?: GitFn;
316
503
  }
317
504
  export interface Worker {
318
505
  tick(): Promise<{