@kenkaiiii/gg-engine 0.0.0-stage → 7.1.0

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 (853) hide show
  1. package/LICENSE +661 -0
  2. package/NOTICE +43 -0
  3. package/README.md +53 -2
  4. package/assets/skills/bulletproof/SKILL.md +132 -0
  5. package/assets/skills/bulletproof/references/agent-surface.md +113 -0
  6. package/assets/skills/bulletproof/references/attack-classes.md +226 -0
  7. package/assets/skills/bulletproof/references/audit-protocol.md +232 -0
  8. package/assets/skills/bulletproof/references/platform-playbooks.md +196 -0
  9. package/assets/skills/bulletproof/references/provenance.md +146 -0
  10. package/assets/skills/bulletproof/references/secure-defaults.md +137 -0
  11. package/assets/skills/bulletproof/references/supply-chain.md +84 -0
  12. package/assets/skills/bulletproof/references/threat-landscape.md +66 -0
  13. package/assets/skills/bulletproof/references/verification.md +74 -0
  14. package/assets/skills/compliance-guard/SKILL.md +115 -0
  15. package/assets/skills/compliance-guard/references/artifacts.md +199 -0
  16. package/assets/skills/compliance-guard/references/eu-uk.md +162 -0
  17. package/assets/skills/compliance-guard/references/exposure-triage.md +177 -0
  18. package/assets/skills/compliance-guard/references/full-review.md +155 -0
  19. package/assets/skills/compliance-guard/references/lawsuit-vectors.md +153 -0
  20. package/assets/skills/compliance-guard/references/provenance.md +135 -0
  21. package/assets/skills/compliance-guard/references/sector-gates.md +187 -0
  22. package/assets/skills/compliance-guard/references/security-baseline.md +117 -0
  23. package/assets/skills/compliance-guard/references/trigger-map.md +177 -0
  24. package/assets/skills/compliance-guard/references/us.md +194 -0
  25. package/assets/skills/durable/SKILL.md +114 -0
  26. package/assets/skills/durable/references/agent-db-safety.md +76 -0
  27. package/assets/skills/durable/references/backups-and-runtime.md +93 -0
  28. package/assets/skills/durable/references/migrations-and-schema.md +87 -0
  29. package/assets/skills/gg-guide/SKILL.md +43 -0
  30. package/assets/skills/gg-guide/references/chat-motion-goals.md +217 -0
  31. package/assets/skills/gg-guide/references/checklist-and-safety.md +177 -0
  32. package/assets/skills/gg-guide/references/code-mode.md +272 -0
  33. package/assets/skills/gg-guide/references/getting-started.md +295 -0
  34. package/assets/skills/gg-guide/references/ken-and-autopilot.md +172 -0
  35. package/assets/skills/gg-guide/references/mcp-and-skills.md +204 -0
  36. package/assets/skills/gg-guide/references/models-and-sign-in.md +200 -0
  37. package/assets/skills/gg-guide/references/sessions-and-history.md +213 -0
  38. package/assets/skills/gg-guide/references/settings.md +193 -0
  39. package/assets/skills/gg-guide/references/troubleshooting-and-data.md +186 -0
  40. package/assets/skills/lean/SKILL.md +117 -0
  41. package/assets/skills/lean/references/memory-and-processes.md +99 -0
  42. package/assets/skills/lean/references/playbooks.md +134 -0
  43. package/dist/app-error.d.ts +22 -0
  44. package/dist/app-error.js +41 -0
  45. package/dist/app-error.js.map +1 -0
  46. package/dist/config.d.ts +90 -0
  47. package/dist/config.js +240 -0
  48. package/dist/config.js.map +1 -0
  49. package/dist/core/acceptance-checks.d.ts +48 -0
  50. package/dist/core/acceptance-checks.js +151 -0
  51. package/dist/core/acceptance-checks.js.map +1 -0
  52. package/dist/core/action-threats.d.ts +68 -0
  53. package/dist/core/action-threats.js +894 -0
  54. package/dist/core/action-threats.js.map +1 -0
  55. package/dist/core/agent-notifications.d.ts +79 -0
  56. package/dist/core/agent-notifications.js +125 -0
  57. package/dist/core/agent-notifications.js.map +1 -0
  58. package/dist/core/agent-session/helpers.d.ts +26 -0
  59. package/dist/core/agent-session/helpers.js +47 -0
  60. package/dist/core/agent-session/helpers.js.map +1 -0
  61. package/dist/core/agent-session/mcp-tools.d.ts +87 -0
  62. package/dist/core/agent-session/mcp-tools.js +227 -0
  63. package/dist/core/agent-session/mcp-tools.js.map +1 -0
  64. package/dist/core/agent-session/run-loop-monitor.d.ts +63 -0
  65. package/dist/core/agent-session/run-loop-monitor.js +164 -0
  66. package/dist/core/agent-session/run-loop-monitor.js.map +1 -0
  67. package/dist/core/agent-session/transcript-markers.d.ts +57 -0
  68. package/dist/core/agent-session/transcript-markers.js +166 -0
  69. package/dist/core/agent-session/transcript-markers.js.map +1 -0
  70. package/dist/core/agent-session/verification-tracker.d.ts +71 -0
  71. package/dist/core/agent-session/verification-tracker.js +295 -0
  72. package/dist/core/agent-session/verification-tracker.js.map +1 -0
  73. package/dist/core/agent-session.d.ts +1401 -0
  74. package/dist/core/agent-session.js +5160 -0
  75. package/dist/core/agent-session.js.map +1 -0
  76. package/dist/core/agents.d.ts +63 -0
  77. package/dist/core/agents.js +160 -0
  78. package/dist/core/agents.js.map +1 -0
  79. package/dist/core/ask-user.d.ts +163 -0
  80. package/dist/core/ask-user.js +178 -0
  81. package/dist/core/ask-user.js.map +1 -0
  82. package/dist/core/auto-update.d.ts +32 -0
  83. package/dist/core/auto-update.js +218 -0
  84. package/dist/core/auto-update.js.map +1 -0
  85. package/dist/core/autopilot-cycle.d.ts +127 -0
  86. package/dist/core/autopilot-cycle.js +182 -0
  87. package/dist/core/autopilot-cycle.js.map +1 -0
  88. package/dist/core/autopilot-gate.d.ts +106 -0
  89. package/dist/core/autopilot-gate.js +192 -0
  90. package/dist/core/autopilot-gate.js.map +1 -0
  91. package/dist/core/autopilot-verdict.d.ts +55 -0
  92. package/dist/core/autopilot-verdict.js +226 -0
  93. package/dist/core/autopilot-verdict.js.map +1 -0
  94. package/dist/core/blocked-packages-file.d.ts +33 -0
  95. package/dist/core/blocked-packages-file.js +274 -0
  96. package/dist/core/blocked-packages-file.js.map +1 -0
  97. package/dist/core/bundled-agents.d.ts +2 -0
  98. package/dist/core/bundled-agents.js +253 -0
  99. package/dist/core/bundled-agents.js.map +1 -0
  100. package/dist/core/cache-diagnostics.d.ts +72 -0
  101. package/dist/core/cache-diagnostics.js +200 -0
  102. package/dist/core/cache-diagnostics.js.map +1 -0
  103. package/dist/core/cache-expiry.d.ts +89 -0
  104. package/dist/core/cache-expiry.js +117 -0
  105. package/dist/core/cache-expiry.js.map +1 -0
  106. package/dist/core/checklist-detection.d.ts +8 -0
  107. package/dist/core/checklist-detection.js +238 -0
  108. package/dist/core/checklist-detection.js.map +1 -0
  109. package/dist/core/checklist-git.d.ts +19 -0
  110. package/dist/core/checklist-git.js +54 -0
  111. package/dist/core/checklist-git.js.map +1 -0
  112. package/dist/core/checklist-items.d.ts +182 -0
  113. package/dist/core/checklist-items.js +228 -0
  114. package/dist/core/checklist-items.js.map +1 -0
  115. package/dist/core/checklist-prompt.d.ts +14 -0
  116. package/dist/core/checklist-prompt.js +64 -0
  117. package/dist/core/checklist-prompt.js.map +1 -0
  118. package/dist/core/checklist-snapshot.d.ts +7 -0
  119. package/dist/core/checklist-snapshot.js +46 -0
  120. package/dist/core/checklist-snapshot.js.map +1 -0
  121. package/dist/core/checklist-store.d.ts +45 -0
  122. package/dist/core/checklist-store.js +281 -0
  123. package/dist/core/checklist-store.js.map +1 -0
  124. package/dist/core/checkout-record.d.ts +22 -0
  125. package/dist/core/checkout-record.js +68 -0
  126. package/dist/core/checkout-record.js.map +1 -0
  127. package/dist/core/checkpoint-store.d.ts +109 -0
  128. package/dist/core/checkpoint-store.js +260 -0
  129. package/dist/core/checkpoint-store.js.map +1 -0
  130. package/dist/core/claude-code/complete.d.ts +35 -0
  131. package/dist/core/claude-code/complete.js +125 -0
  132. package/dist/core/claude-code/complete.js.map +1 -0
  133. package/dist/core/claude-code/events.d.ts +67 -0
  134. package/dist/core/claude-code/events.js +460 -0
  135. package/dist/core/claude-code/events.js.map +1 -0
  136. package/dist/core/claude-code/live-session.d.ts +94 -0
  137. package/dist/core/claude-code/live-session.js +525 -0
  138. package/dist/core/claude-code/live-session.js.map +1 -0
  139. package/dist/core/claude-code/loop.d.ts +9 -0
  140. package/dist/core/claude-code/loop.js +15 -0
  141. package/dist/core/claude-code/loop.js.map +1 -0
  142. package/dist/core/claude-code/session-sync.d.ts +28 -0
  143. package/dist/core/claude-code/session-sync.js +53 -0
  144. package/dist/core/claude-code/session-sync.js.map +1 -0
  145. package/dist/core/claude-code/tool-bridge.d.ts +49 -0
  146. package/dist/core/claude-code/tool-bridge.js +352 -0
  147. package/dist/core/claude-code/tool-bridge.js.map +1 -0
  148. package/dist/core/claude-code/transcripts.d.ts +39 -0
  149. package/dist/core/claude-code/transcripts.js +195 -0
  150. package/dist/core/claude-code/transcripts.js.map +1 -0
  151. package/dist/core/code-retrieval-chunkers.d.ts +26 -0
  152. package/dist/core/code-retrieval-chunkers.js +264 -0
  153. package/dist/core/code-retrieval-chunkers.js.map +1 -0
  154. package/dist/core/code-retrieval.d.ts +18 -0
  155. package/dist/core/code-retrieval.js +124 -0
  156. package/dist/core/code-retrieval.js.map +1 -0
  157. package/dist/core/codex-request-shape.d.ts +7 -0
  158. package/dist/core/codex-request-shape.js +19 -0
  159. package/dist/core/codex-request-shape.js.map +1 -0
  160. package/dist/core/compaction/active-context.d.ts +16 -0
  161. package/dist/core/compaction/active-context.js +20 -0
  162. package/dist/core/compaction/active-context.js.map +1 -0
  163. package/dist/core/compaction/compactor.d.ts +281 -0
  164. package/dist/core/compaction/compactor.js +1451 -0
  165. package/dist/core/compaction/compactor.js.map +1 -0
  166. package/dist/core/compaction/plan-step-policy.d.ts +46 -0
  167. package/dist/core/compaction/plan-step-policy.js +57 -0
  168. package/dist/core/compaction/plan-step-policy.js.map +1 -0
  169. package/dist/core/compaction/policy.d.ts +36 -0
  170. package/dist/core/compaction/policy.js +144 -0
  171. package/dist/core/compaction/policy.js.map +1 -0
  172. package/dist/core/compaction/query-aware-selector.d.ts +32 -0
  173. package/dist/core/compaction/query-aware-selector.js +202 -0
  174. package/dist/core/compaction/query-aware-selector.js.map +1 -0
  175. package/dist/core/compaction/token-estimator.d.ts +36 -0
  176. package/dist/core/compaction/token-estimator.js +180 -0
  177. package/dist/core/compaction/token-estimator.js.map +1 -0
  178. package/dist/core/compaction/tool-result-pruner.d.ts +90 -0
  179. package/dist/core/compaction/tool-result-pruner.js +238 -0
  180. package/dist/core/compaction/tool-result-pruner.js.map +1 -0
  181. package/dist/core/completion-review.d.ts +24 -0
  182. package/dist/core/completion-review.js +2 -0
  183. package/dist/core/completion-review.js.map +1 -0
  184. package/dist/core/context-files.d.ts +8 -0
  185. package/dist/core/context-files.js +46 -0
  186. package/dist/core/context-files.js.map +1 -0
  187. package/dist/core/context-limits.d.ts +40 -0
  188. package/dist/core/context-limits.js +43 -0
  189. package/dist/core/context-limits.js.map +1 -0
  190. package/dist/core/custom-commands.d.ts +18 -0
  191. package/dist/core/custom-commands.js +57 -0
  192. package/dist/core/custom-commands.js.map +1 -0
  193. package/dist/core/destructive-git-guard.d.ts +113 -0
  194. package/dist/core/destructive-git-guard.js +874 -0
  195. package/dist/core/destructive-git-guard.js.map +1 -0
  196. package/dist/core/display-items.d.ts +8 -0
  197. package/dist/core/display-items.js +2 -0
  198. package/dist/core/display-items.js.map +1 -0
  199. package/dist/core/encode-cwd.d.ts +41 -0
  200. package/dist/core/encode-cwd.js +53 -0
  201. package/dist/core/encode-cwd.js.map +1 -0
  202. package/dist/core/env-delta.d.ts +34 -0
  203. package/dist/core/env-delta.js +84 -0
  204. package/dist/core/env-delta.js.map +1 -0
  205. package/dist/core/event-bus.d.ts +178 -0
  206. package/dist/core/event-bus.js +171 -0
  207. package/dist/core/event-bus.js.map +1 -0
  208. package/dist/core/extensions/loader.d.ts +7 -0
  209. package/dist/core/extensions/loader.js +68 -0
  210. package/dist/core/extensions/loader.js.map +1 -0
  211. package/dist/core/extensions/plugin-bundles.d.ts +13 -0
  212. package/dist/core/extensions/plugin-bundles.js +45 -0
  213. package/dist/core/extensions/plugin-bundles.js.map +1 -0
  214. package/dist/core/extensions/types.d.ts +18 -0
  215. package/dist/core/extensions/types.js +2 -0
  216. package/dist/core/extensions/types.js.map +1 -0
  217. package/dist/core/foreign-session-import.d.ts +119 -0
  218. package/dist/core/foreign-session-import.js +598 -0
  219. package/dist/core/foreign-session-import.js.map +1 -0
  220. package/dist/core/foreign-transcript-blocks.d.ts +50 -0
  221. package/dist/core/foreign-transcript-blocks.js +151 -0
  222. package/dist/core/foreign-transcript-blocks.js.map +1 -0
  223. package/dist/core/frontmatter.d.ts +22 -0
  224. package/dist/core/frontmatter.js +90 -0
  225. package/dist/core/frontmatter.js.map +1 -0
  226. package/dist/core/goal-run-marker.d.ts +32 -0
  227. package/dist/core/goal-run-marker.js +178 -0
  228. package/dist/core/goal-run-marker.js.map +1 -0
  229. package/dist/core/goal-summary.d.ts +15 -0
  230. package/dist/core/goal-summary.js +110 -0
  231. package/dist/core/goal-summary.js.map +1 -0
  232. package/dist/core/goals-store.d.ts +208 -0
  233. package/dist/core/goals-store.js +577 -0
  234. package/dist/core/goals-store.js.map +1 -0
  235. package/dist/core/hashline.d.ts +51 -0
  236. package/dist/core/hashline.js +76 -0
  237. package/dist/core/hashline.js.map +1 -0
  238. package/dist/core/idle-wake.d.ts +62 -0
  239. package/dist/core/idle-wake.js +103 -0
  240. package/dist/core/idle-wake.js.map +1 -0
  241. package/dist/core/index.d.ts +15 -0
  242. package/dist/core/index.js +15 -0
  243. package/dist/core/index.js.map +1 -0
  244. package/dist/core/injection-detect.d.ts +39 -0
  245. package/dist/core/injection-detect.js +241 -0
  246. package/dist/core/injection-detect.js.map +1 -0
  247. package/dist/core/installed-threats.d.ts +23 -0
  248. package/dist/core/installed-threats.js +71 -0
  249. package/dist/core/installed-threats.js.map +1 -0
  250. package/dist/core/internal-diagnostics.d.ts +159 -0
  251. package/dist/core/internal-diagnostics.js +495 -0
  252. package/dist/core/internal-diagnostics.js.map +1 -0
  253. package/dist/core/keep-awake.d.ts +88 -0
  254. package/dist/core/keep-awake.js +251 -0
  255. package/dist/core/keep-awake.js.map +1 -0
  256. package/dist/core/ken-ask-answer.d.ts +24 -0
  257. package/dist/core/ken-ask-answer.js +96 -0
  258. package/dist/core/ken-ask-answer.js.map +1 -0
  259. package/dist/core/ken-context.d.ts +119 -0
  260. package/dist/core/ken-context.js +447 -0
  261. package/dist/core/ken-context.js.map +1 -0
  262. package/dist/core/ken-model.d.ts +45 -0
  263. package/dist/core/ken-model.js +26 -0
  264. package/dist/core/ken-model.js.map +1 -0
  265. package/dist/core/ken-prompt.d.ts +21 -0
  266. package/dist/core/ken-prompt.js +370 -0
  267. package/dist/core/ken-prompt.js.map +1 -0
  268. package/dist/core/language-detector.d.ts +41 -0
  269. package/dist/core/language-detector.js +293 -0
  270. package/dist/core/language-detector.js.map +1 -0
  271. package/dist/core/live-preview.d.ts +26 -0
  272. package/dist/core/live-preview.js +80 -0
  273. package/dist/core/live-preview.js.map +1 -0
  274. package/dist/core/local-endpoint-store.d.ts +53 -0
  275. package/dist/core/local-endpoint-store.js +221 -0
  276. package/dist/core/local-endpoint-store.js.map +1 -0
  277. package/dist/core/logger.d.ts +21 -0
  278. package/dist/core/logger.js +94 -0
  279. package/dist/core/logger.js.map +1 -0
  280. package/dist/core/loop-breaker.d.ts +89 -0
  281. package/dist/core/loop-breaker.js +204 -0
  282. package/dist/core/loop-breaker.js.map +1 -0
  283. package/dist/core/lsp/client.d.ts +206 -0
  284. package/dist/core/lsp/client.js +685 -0
  285. package/dist/core/lsp/client.js.map +1 -0
  286. package/dist/core/lsp/edit-telemetry.d.ts +26 -0
  287. package/dist/core/lsp/edit-telemetry.js +52 -0
  288. package/dist/core/lsp/edit-telemetry.js.map +1 -0
  289. package/dist/core/lsp/format.d.ts +11 -0
  290. package/dist/core/lsp/format.js +30 -0
  291. package/dist/core/lsp/format.js.map +1 -0
  292. package/dist/core/lsp/jsonrpc.d.ts +68 -0
  293. package/dist/core/lsp/jsonrpc.js +153 -0
  294. package/dist/core/lsp/jsonrpc.js.map +1 -0
  295. package/dist/core/lsp/manager.d.ts +188 -0
  296. package/dist/core/lsp/manager.js +576 -0
  297. package/dist/core/lsp/manager.js.map +1 -0
  298. package/dist/core/lsp/pool.d.ts +114 -0
  299. package/dist/core/lsp/pool.js +259 -0
  300. package/dist/core/lsp/pool.js.map +1 -0
  301. package/dist/core/lsp/project-root.d.ts +9 -0
  302. package/dist/core/lsp/project-root.js +75 -0
  303. package/dist/core/lsp/project-root.js.map +1 -0
  304. package/dist/core/lsp/reference-project.d.ts +6 -0
  305. package/dist/core/lsp/reference-project.js +110 -0
  306. package/dist/core/lsp/reference-project.js.map +1 -0
  307. package/dist/core/lsp/servers.d.ts +44 -0
  308. package/dist/core/lsp/servers.js +289 -0
  309. package/dist/core/lsp/servers.js.map +1 -0
  310. package/dist/core/lsp/test-support.d.ts +17 -0
  311. package/dist/core/lsp/test-support.js +27 -0
  312. package/dist/core/lsp/test-support.js.map +1 -0
  313. package/dist/core/mcp/catalog-cache.d.ts +64 -0
  314. package/dist/core/mcp/catalog-cache.js +166 -0
  315. package/dist/core/mcp/catalog-cache.js.map +1 -0
  316. package/dist/core/mcp/client.d.ts +317 -0
  317. package/dist/core/mcp/client.js +1168 -0
  318. package/dist/core/mcp/client.js.map +1 -0
  319. package/dist/core/mcp/content.d.ts +23 -0
  320. package/dist/core/mcp/content.js +194 -0
  321. package/dist/core/mcp/content.js.map +1 -0
  322. package/dist/core/mcp/defaults.d.ts +26 -0
  323. package/dist/core/mcp/defaults.js +81 -0
  324. package/dist/core/mcp/defaults.js.map +1 -0
  325. package/dist/core/mcp/deferred-catalog.d.ts +53 -0
  326. package/dist/core/mcp/deferred-catalog.js +117 -0
  327. package/dist/core/mcp/deferred-catalog.js.map +1 -0
  328. package/dist/core/mcp/elicitation-bridge.d.ts +40 -0
  329. package/dist/core/mcp/elicitation-bridge.js +36 -0
  330. package/dist/core/mcp/elicitation-bridge.js.map +1 -0
  331. package/dist/core/mcp/index.d.ts +16 -0
  332. package/dist/core/mcp/index.js +10 -0
  333. package/dist/core/mcp/index.js.map +1 -0
  334. package/dist/core/mcp/loopback.d.ts +26 -0
  335. package/dist/core/mcp/loopback.js +66 -0
  336. package/dist/core/mcp/loopback.js.map +1 -0
  337. package/dist/core/mcp/oauth-provider.d.ts +55 -0
  338. package/dist/core/mcp/oauth-provider.js +106 -0
  339. package/dist/core/mcp/oauth-provider.js.map +1 -0
  340. package/dist/core/mcp/oauth-store.d.ts +44 -0
  341. package/dist/core/mcp/oauth-store.js +76 -0
  342. package/dist/core/mcp/oauth-store.js.map +1 -0
  343. package/dist/core/mcp/parse-add-command.d.ts +50 -0
  344. package/dist/core/mcp/parse-add-command.js +391 -0
  345. package/dist/core/mcp/parse-add-command.js.map +1 -0
  346. package/dist/core/mcp/resolve-stdio.d.ts +77 -0
  347. package/dist/core/mcp/resolve-stdio.js +359 -0
  348. package/dist/core/mcp/resolve-stdio.js.map +1 -0
  349. package/dist/core/mcp/shared-pool.d.ts +157 -0
  350. package/dist/core/mcp/shared-pool.js +236 -0
  351. package/dist/core/mcp/shared-pool.js.map +1 -0
  352. package/dist/core/mcp/store.d.ts +100 -0
  353. package/dist/core/mcp/store.js +202 -0
  354. package/dist/core/mcp/store.js.map +1 -0
  355. package/dist/core/mcp/tool-guard.d.ts +58 -0
  356. package/dist/core/mcp/tool-guard.js +215 -0
  357. package/dist/core/mcp/tool-guard.js.map +1 -0
  358. package/dist/core/mcp/types.d.ts +57 -0
  359. package/dist/core/mcp/types.js +2 -0
  360. package/dist/core/mcp/types.js.map +1 -0
  361. package/dist/core/message-images.d.ts +11 -0
  362. package/dist/core/message-images.js +52 -0
  363. package/dist/core/message-images.js.map +1 -0
  364. package/dist/core/model-unavailable.d.ts +14 -0
  365. package/dist/core/model-unavailable.js +23 -0
  366. package/dist/core/model-unavailable.js.map +1 -0
  367. package/dist/core/network-guard.d.ts +28 -0
  368. package/dist/core/network-guard.js +251 -0
  369. package/dist/core/network-guard.js.map +1 -0
  370. package/dist/core/node-debugger.d.ts +148 -0
  371. package/dist/core/node-debugger.js +642 -0
  372. package/dist/core/node-debugger.js.map +1 -0
  373. package/dist/core/opencode-catalog-store.d.ts +20 -0
  374. package/dist/core/opencode-catalog-store.js +82 -0
  375. package/dist/core/opencode-catalog-store.js.map +1 -0
  376. package/dist/core/openrouter-catalog-store.d.ts +24 -0
  377. package/dist/core/openrouter-catalog-store.js +140 -0
  378. package/dist/core/openrouter-catalog-store.js.map +1 -0
  379. package/dist/core/package-cooldown.d.ts +69 -0
  380. package/dist/core/package-cooldown.js +297 -0
  381. package/dist/core/package-cooldown.js.map +1 -0
  382. package/dist/core/package-threats.d.ts +92 -0
  383. package/dist/core/package-threats.js +1339 -0
  384. package/dist/core/package-threats.js.map +1 -0
  385. package/dist/core/parked-requests.d.ts +43 -0
  386. package/dist/core/parked-requests.js +34 -0
  387. package/dist/core/parked-requests.js.map +1 -0
  388. package/dist/core/persistent-shell.d.ts +81 -0
  389. package/dist/core/persistent-shell.js +452 -0
  390. package/dist/core/persistent-shell.js.map +1 -0
  391. package/dist/core/plan-delta.d.ts +23 -0
  392. package/dist/core/plan-delta.js +36 -0
  393. package/dist/core/plan-delta.js.map +1 -0
  394. package/dist/core/plan-handoff.d.ts +38 -0
  395. package/dist/core/plan-handoff.js +21 -0
  396. package/dist/core/plan-handoff.js.map +1 -0
  397. package/dist/core/plan-submission-gate.d.ts +28 -0
  398. package/dist/core/plan-submission-gate.js +27 -0
  399. package/dist/core/plan-submission-gate.js.map +1 -0
  400. package/dist/core/platform-clis.d.ts +15 -0
  401. package/dist/core/platform-clis.js +299 -0
  402. package/dist/core/platform-clis.js.map +1 -0
  403. package/dist/core/process-gate.d.ts +61 -0
  404. package/dist/core/process-gate.js +103 -0
  405. package/dist/core/process-gate.js.map +1 -0
  406. package/dist/core/process-manager.d.ts +242 -0
  407. package/dist/core/process-manager.js +902 -0
  408. package/dist/core/process-manager.js.map +1 -0
  409. package/dist/core/progress/engine.d.ts +22 -0
  410. package/dist/core/progress/engine.js +131 -0
  411. package/dist/core/progress/engine.js.map +1 -0
  412. package/dist/core/progress/git-xp.d.ts +15 -0
  413. package/dist/core/progress/git-xp.js +100 -0
  414. package/dist/core/progress/git-xp.js.map +1 -0
  415. package/dist/core/progress/ranks.d.ts +31 -0
  416. package/dist/core/progress/ranks.js +310 -0
  417. package/dist/core/progress/ranks.js.map +1 -0
  418. package/dist/core/progress/rebuild.d.ts +8 -0
  419. package/dist/core/progress/rebuild.js +125 -0
  420. package/dist/core/progress/rebuild.js.map +1 -0
  421. package/dist/core/progress/store.d.ts +34 -0
  422. package/dist/core/progress/store.js +200 -0
  423. package/dist/core/progress/store.js.map +1 -0
  424. package/dist/core/progress/types.d.ts +56 -0
  425. package/dist/core/progress/types.js +2 -0
  426. package/dist/core/progress/types.js.map +1 -0
  427. package/dist/core/project-discovery.d.ts +64 -0
  428. package/dist/core/project-discovery.js +908 -0
  429. package/dist/core/project-discovery.js.map +1 -0
  430. package/dist/core/project-files.d.ts +15 -0
  431. package/dist/core/project-files.js +37 -0
  432. package/dist/core/project-files.js.map +1 -0
  433. package/dist/core/project-health-scan.d.ts +109 -0
  434. package/dist/core/project-health-scan.js +673 -0
  435. package/dist/core/project-health-scan.js.map +1 -0
  436. package/dist/core/project-health-score.d.ts +41 -0
  437. package/dist/core/project-health-score.js +257 -0
  438. package/dist/core/project-health-score.js.map +1 -0
  439. package/dist/core/prompt-command-expansion.d.ts +13 -0
  440. package/dist/core/prompt-command-expansion.js +48 -0
  441. package/dist/core/prompt-command-expansion.js.map +1 -0
  442. package/dist/core/prompt-commands.d.ts +13 -0
  443. package/dist/core/prompt-commands.js +370 -0
  444. package/dist/core/prompt-commands.js.map +1 -0
  445. package/dist/core/pull-requests.d.ts +18 -0
  446. package/dist/core/pull-requests.js +95 -0
  447. package/dist/core/pull-requests.js.map +1 -0
  448. package/dist/core/radio-players.d.ts +28 -0
  449. package/dist/core/radio-players.js +132 -0
  450. package/dist/core/radio-players.js.map +1 -0
  451. package/dist/core/radio.d.ts +42 -0
  452. package/dist/core/radio.js +499 -0
  453. package/dist/core/radio.js.map +1 -0
  454. package/dist/core/regrounding.d.ts +37 -0
  455. package/dist/core/regrounding.js +89 -0
  456. package/dist/core/regrounding.js.map +1 -0
  457. package/dist/core/resolve-start.d.ts +28 -0
  458. package/dist/core/resolve-start.js +35 -0
  459. package/dist/core/resolve-start.js.map +1 -0
  460. package/dist/core/run-claim.d.ts +36 -0
  461. package/dist/core/run-claim.js +46 -0
  462. package/dist/core/run-claim.js.map +1 -0
  463. package/dist/core/run-lifecycle.d.ts +58 -0
  464. package/dist/core/run-lifecycle.js +104 -0
  465. package/dist/core/run-lifecycle.js.map +1 -0
  466. package/dist/core/run-status.d.ts +17 -0
  467. package/dist/core/run-status.js +28 -0
  468. package/dist/core/run-status.js.map +1 -0
  469. package/dist/core/runtime-mode.d.ts +21 -0
  470. package/dist/core/runtime-mode.js +43 -0
  471. package/dist/core/runtime-mode.js.map +1 -0
  472. package/dist/core/sandbox-domains.d.ts +13 -0
  473. package/dist/core/sandbox-domains.js +76 -0
  474. package/dist/core/sandbox-domains.js.map +1 -0
  475. package/dist/core/sandbox-feedback.d.ts +21 -0
  476. package/dist/core/sandbox-feedback.js +69 -0
  477. package/dist/core/sandbox-feedback.js.map +1 -0
  478. package/dist/core/sandbox.d.ts +106 -0
  479. package/dist/core/sandbox.js +383 -0
  480. package/dist/core/sandbox.js.map +1 -0
  481. package/dist/core/semantic-loop-check.d.ts +58 -0
  482. package/dist/core/semantic-loop-check.js +103 -0
  483. package/dist/core/semantic-loop-check.js.map +1 -0
  484. package/dist/core/session-compaction.d.ts +23 -0
  485. package/dist/core/session-compaction.js +54 -0
  486. package/dist/core/session-compaction.js.map +1 -0
  487. package/dist/core/session-export.d.ts +97 -0
  488. package/dist/core/session-export.js +368 -0
  489. package/dist/core/session-export.js.map +1 -0
  490. package/dist/core/session-history.d.ts +160 -0
  491. package/dist/core/session-history.js +467 -0
  492. package/dist/core/session-history.js.map +1 -0
  493. package/dist/core/session-manager.d.ts +512 -0
  494. package/dist/core/session-manager.js +1370 -0
  495. package/dist/core/session-manager.js.map +1 -0
  496. package/dist/core/session-preview.d.ts +12 -0
  497. package/dist/core/session-preview.js +58 -0
  498. package/dist/core/session-preview.js.map +1 -0
  499. package/dist/core/session-storage.d.ts +78 -0
  500. package/dist/core/session-storage.js +659 -0
  501. package/dist/core/session-storage.js.map +1 -0
  502. package/dist/core/session-summary-index.d.ts +51 -0
  503. package/dist/core/session-summary-index.js +192 -0
  504. package/dist/core/session-summary-index.js.map +1 -0
  505. package/dist/core/settings-manager.d.ts +113 -0
  506. package/dist/core/settings-manager.js +281 -0
  507. package/dist/core/settings-manager.js.map +1 -0
  508. package/dist/core/shared-checkout-guard.d.ts +78 -0
  509. package/dist/core/shared-checkout-guard.js +219 -0
  510. package/dist/core/shared-checkout-guard.js.map +1 -0
  511. package/dist/core/shell-path.d.ts +13 -0
  512. package/dist/core/shell-path.js +175 -0
  513. package/dist/core/shell-path.js.map +1 -0
  514. package/dist/core/shell-threats-popular-packages.d.ts +11 -0
  515. package/dist/core/shell-threats-popular-packages.js +675 -0
  516. package/dist/core/shell-threats-popular-packages.js.map +1 -0
  517. package/dist/core/shell-threats.d.ts +21 -0
  518. package/dist/core/shell-threats.js +235 -0
  519. package/dist/core/shell-threats.js.map +1 -0
  520. package/dist/core/shell.d.ts +54 -0
  521. package/dist/core/shell.js +99 -0
  522. package/dist/core/shell.js.map +1 -0
  523. package/dist/core/shutdown.d.ts +70 -0
  524. package/dist/core/shutdown.js +144 -0
  525. package/dist/core/shutdown.js.map +1 -0
  526. package/dist/core/skill-scan.d.ts +112 -0
  527. package/dist/core/skill-scan.js +781 -0
  528. package/dist/core/skill-scan.js.map +1 -0
  529. package/dist/core/skills.d.ts +80 -0
  530. package/dist/core/skills.js +270 -0
  531. package/dist/core/skills.js.map +1 -0
  532. package/dist/core/slash-commands.d.ts +58 -0
  533. package/dist/core/slash-commands.js +242 -0
  534. package/dist/core/slash-commands.js.map +1 -0
  535. package/dist/core/steering.d.ts +47 -0
  536. package/dist/core/steering.js +65 -0
  537. package/dist/core/steering.js.map +1 -0
  538. package/dist/core/steroids.d.ts +66 -0
  539. package/dist/core/steroids.js +243 -0
  540. package/dist/core/steroids.js.map +1 -0
  541. package/dist/core/stream-diag-level.d.ts +3 -0
  542. package/dist/core/stream-diag-level.js +24 -0
  543. package/dist/core/stream-diag-level.js.map +1 -0
  544. package/dist/core/stream-rules.d.ts +30 -0
  545. package/dist/core/stream-rules.js +151 -0
  546. package/dist/core/stream-rules.js.map +1 -0
  547. package/dist/core/subagent-manager.d.ts +242 -0
  548. package/dist/core/subagent-manager.js +1075 -0
  549. package/dist/core/subagent-manager.js.map +1 -0
  550. package/dist/core/subagent-policy.d.ts +9 -0
  551. package/dist/core/subagent-policy.js +41 -0
  552. package/dist/core/subagent-policy.js.map +1 -0
  553. package/dist/core/subagent-receipt.d.ts +54 -0
  554. package/dist/core/subagent-receipt.js +274 -0
  555. package/dist/core/subagent-receipt.js.map +1 -0
  556. package/dist/core/subagent-store.d.ts +41 -0
  557. package/dist/core/subagent-store.js +284 -0
  558. package/dist/core/subagent-store.js.map +1 -0
  559. package/dist/core/subagent-turn-record.d.ts +18 -0
  560. package/dist/core/subagent-turn-record.js +82 -0
  561. package/dist/core/subagent-turn-record.js.map +1 -0
  562. package/dist/core/tasks-store.d.ts +31 -0
  563. package/dist/core/tasks-store.js +97 -0
  564. package/dist/core/tasks-store.js.map +1 -0
  565. package/dist/core/telegram-config.d.ts +20 -0
  566. package/dist/core/telegram-config.js +52 -0
  567. package/dist/core/telegram-config.js.map +1 -0
  568. package/dist/core/telegram.d.ts +114 -0
  569. package/dist/core/telegram.js +275 -0
  570. package/dist/core/telegram.js.map +1 -0
  571. package/dist/core/temp-paths.d.ts +5 -0
  572. package/dist/core/temp-paths.js +50 -0
  573. package/dist/core/temp-paths.js.map +1 -0
  574. package/dist/core/test-impact.d.ts +73 -0
  575. package/dist/core/test-impact.js +467 -0
  576. package/dist/core/test-impact.js.map +1 -0
  577. package/dist/core/threat-feed.d.ts +65 -0
  578. package/dist/core/threat-feed.js +334 -0
  579. package/dist/core/threat-feed.js.map +1 -0
  580. package/dist/core/trophies/catalog-more.d.ts +2 -0
  581. package/dist/core/trophies/catalog-more.js +837 -0
  582. package/dist/core/trophies/catalog-more.js.map +1 -0
  583. package/dist/core/trophies/catalog.d.ts +4 -0
  584. package/dist/core/trophies/catalog.js +649 -0
  585. package/dist/core/trophies/catalog.js.map +1 -0
  586. package/dist/core/trophies/engine.d.ts +70 -0
  587. package/dist/core/trophies/engine.js +347 -0
  588. package/dist/core/trophies/engine.js.map +1 -0
  589. package/dist/core/trophies/store.d.ts +17 -0
  590. package/dist/core/trophies/store.js +113 -0
  591. package/dist/core/trophies/store.js.map +1 -0
  592. package/dist/core/trophies/types.d.ts +87 -0
  593. package/dist/core/trophies/types.js +74 -0
  594. package/dist/core/trophies/types.js.map +1 -0
  595. package/dist/core/ui-adoption.d.ts +32 -0
  596. package/dist/core/ui-adoption.js +302 -0
  597. package/dist/core/ui-adoption.js.map +1 -0
  598. package/dist/core/ui-compatibility.d.ts +10 -0
  599. package/dist/core/ui-compatibility.js +51 -0
  600. package/dist/core/ui-compatibility.js.map +1 -0
  601. package/dist/core/ui-registry.d.ts +101 -0
  602. package/dist/core/ui-registry.js +292 -0
  603. package/dist/core/ui-registry.js.map +1 -0
  604. package/dist/core/user-shell-context.d.ts +8 -0
  605. package/dist/core/user-shell-context.js +12 -0
  606. package/dist/core/user-shell-context.js.map +1 -0
  607. package/dist/core/verification-evidence.d.ts +49 -0
  608. package/dist/core/verification-evidence.js +816 -0
  609. package/dist/core/verification-evidence.js.map +1 -0
  610. package/dist/core/verification-gate.d.ts +77 -0
  611. package/dist/core/verification-gate.js +504 -0
  612. package/dist/core/verification-gate.js.map +1 -0
  613. package/dist/core/verification-snapshot.d.ts +7 -0
  614. package/dist/core/verification-snapshot.js +109 -0
  615. package/dist/core/verification-snapshot.js.map +1 -0
  616. package/dist/core/verify-commands.d.ts +34 -0
  617. package/dist/core/verify-commands.js +203 -0
  618. package/dist/core/verify-commands.js.map +1 -0
  619. package/dist/core/voice-transcriber.d.ts +32 -0
  620. package/dist/core/voice-transcriber.js +114 -0
  621. package/dist/core/voice-transcriber.js.map +1 -0
  622. package/dist/core/workspace-guard.d.ts +56 -0
  623. package/dist/core/workspace-guard.js +334 -0
  624. package/dist/core/workspace-guard.js.map +1 -0
  625. package/dist/index.d.ts +15 -0
  626. package/dist/index.js +21 -0
  627. package/dist/index.js.map +1 -0
  628. package/dist/session.d.ts +44 -0
  629. package/dist/session.js +105 -0
  630. package/dist/session.js.map +1 -0
  631. package/dist/system-prompt.d.ts +104 -0
  632. package/dist/system-prompt.js +480 -0
  633. package/dist/system-prompt.js.map +1 -0
  634. package/dist/test-support/fake-home.d.ts +19 -0
  635. package/dist/test-support/fake-home.js +37 -0
  636. package/dist/test-support/fake-home.js.map +1 -0
  637. package/dist/test-support/keep-alive.d.ts +14 -0
  638. package/dist/test-support/keep-alive.js +17 -0
  639. package/dist/test-support/keep-alive.js.map +1 -0
  640. package/dist/test-support/slow-git.d.ts +1 -0
  641. package/dist/test-support/slow-git.js +21 -0
  642. package/dist/test-support/slow-git.js.map +1 -0
  643. package/dist/test-support/system-tools.d.ts +6 -0
  644. package/dist/test-support/system-tools.js +36 -0
  645. package/dist/test-support/system-tools.js.map +1 -0
  646. package/dist/tools/ask-user.d.ts +34 -0
  647. package/dist/tools/ask-user.js +99 -0
  648. package/dist/tools/ask-user.js.map +1 -0
  649. package/dist/tools/background-watch-lint.d.ts +18 -0
  650. package/dist/tools/background-watch-lint.js +102 -0
  651. package/dist/tools/background-watch-lint.js.map +1 -0
  652. package/dist/tools/bash-read-evidence.d.ts +23 -0
  653. package/dist/tools/bash-read-evidence.js +180 -0
  654. package/dist/tools/bash-read-evidence.js.map +1 -0
  655. package/dist/tools/bash.d.ts +64 -0
  656. package/dist/tools/bash.js +552 -0
  657. package/dist/tools/bash.js.map +1 -0
  658. package/dist/tools/browser-api.d.ts +27 -0
  659. package/dist/tools/browser-api.js +449 -0
  660. package/dist/tools/browser-api.js.map +1 -0
  661. package/dist/tools/browser-sandbox.d.ts +16 -0
  662. package/dist/tools/browser-sandbox.js +158 -0
  663. package/dist/tools/browser-sandbox.js.map +1 -0
  664. package/dist/tools/browser-session.d.ts +84 -0
  665. package/dist/tools/browser-session.js +304 -0
  666. package/dist/tools/browser-session.js.map +1 -0
  667. package/dist/tools/browser-snapshot.d.ts +19 -0
  668. package/dist/tools/browser-snapshot.js +109 -0
  669. package/dist/tools/browser-snapshot.js.map +1 -0
  670. package/dist/tools/browser.d.ts +11 -0
  671. package/dist/tools/browser.js +106 -0
  672. package/dist/tools/browser.js.map +1 -0
  673. package/dist/tools/checklist.d.ts +49 -0
  674. package/dist/tools/checklist.js +154 -0
  675. package/dist/tools/checklist.js.map +1 -0
  676. package/dist/tools/compress.d.ts +56 -0
  677. package/dist/tools/compress.js +226 -0
  678. package/dist/tools/compress.js.map +1 -0
  679. package/dist/tools/debug.d.ts +54 -0
  680. package/dist/tools/debug.js +230 -0
  681. package/dist/tools/debug.js.map +1 -0
  682. package/dist/tools/document-text.d.ts +6 -0
  683. package/dist/tools/document-text.js +154 -0
  684. package/dist/tools/document-text.js.map +1 -0
  685. package/dist/tools/edit-diff.d.ts +123 -0
  686. package/dist/tools/edit-diff.js +476 -0
  687. package/dist/tools/edit-diff.js.map +1 -0
  688. package/dist/tools/edit-targets.d.ts +10 -0
  689. package/dist/tools/edit-targets.js +31 -0
  690. package/dist/tools/edit-targets.js.map +1 -0
  691. package/dist/tools/edit.d.ts +38 -0
  692. package/dist/tools/edit.js +695 -0
  693. package/dist/tools/edit.js.map +1 -0
  694. package/dist/tools/enter-plan.d.ts +7 -0
  695. package/dist/tools/enter-plan.js +20 -0
  696. package/dist/tools/enter-plan.js.map +1 -0
  697. package/dist/tools/exit-plan.d.ts +7 -0
  698. package/dist/tools/exit-plan.js +51 -0
  699. package/dist/tools/exit-plan.js.map +1 -0
  700. package/dist/tools/find.d.ts +17 -0
  701. package/dist/tools/find.js +100 -0
  702. package/dist/tools/find.js.map +1 -0
  703. package/dist/tools/generate-image.d.ts +83 -0
  704. package/dist/tools/generate-image.js +625 -0
  705. package/dist/tools/generate-image.js.map +1 -0
  706. package/dist/tools/grep-scan.d.ts +96 -0
  707. package/dist/tools/grep-scan.js +283 -0
  708. package/dist/tools/grep-scan.js.map +1 -0
  709. package/dist/tools/grep.d.ts +48 -0
  710. package/dist/tools/grep.js +1013 -0
  711. package/dist/tools/grep.js.map +1 -0
  712. package/dist/tools/html-extract.d.ts +57 -0
  713. package/dist/tools/html-extract.js +130 -0
  714. package/dist/tools/html-extract.js.map +1 -0
  715. package/dist/tools/index.d.ts +198 -0
  716. package/dist/tools/index.js +216 -0
  717. package/dist/tools/index.js.map +1 -0
  718. package/dist/tools/live-preview.d.ts +23 -0
  719. package/dist/tools/live-preview.js +41 -0
  720. package/dist/tools/live-preview.js.map +1 -0
  721. package/dist/tools/ls.d.ts +9 -0
  722. package/dist/tools/ls.js +59 -0
  723. package/dist/tools/ls.js.map +1 -0
  724. package/dist/tools/operations.d.ts +86 -0
  725. package/dist/tools/operations.js +117 -0
  726. package/dist/tools/operations.js.map +1 -0
  727. package/dist/tools/overflow.d.ts +17 -0
  728. package/dist/tools/overflow.js +68 -0
  729. package/dist/tools/overflow.js.map +1 -0
  730. package/dist/tools/path-utils.d.ts +30 -0
  731. package/dist/tools/path-utils.js +74 -0
  732. package/dist/tools/path-utils.js.map +1 -0
  733. package/dist/tools/pdf-extract.d.ts +17 -0
  734. package/dist/tools/pdf-extract.js +43 -0
  735. package/dist/tools/pdf-extract.js.map +1 -0
  736. package/dist/tools/prompt-hints.d.ts +46 -0
  737. package/dist/tools/prompt-hints.js +171 -0
  738. package/dist/tools/prompt-hints.js.map +1 -0
  739. package/dist/tools/read-only-bash.d.ts +31 -0
  740. package/dist/tools/read-only-bash.js +338 -0
  741. package/dist/tools/read-only-bash.js.map +1 -0
  742. package/dist/tools/read-tracker.d.ts +43 -0
  743. package/dist/tools/read-tracker.js +120 -0
  744. package/dist/tools/read-tracker.js.map +1 -0
  745. package/dist/tools/read.d.ts +18 -0
  746. package/dist/tools/read.js +316 -0
  747. package/dist/tools/read.js.map +1 -0
  748. package/dist/tools/redaction-guard.d.ts +10 -0
  749. package/dist/tools/redaction-guard.js +55 -0
  750. package/dist/tools/redaction-guard.js.map +1 -0
  751. package/dist/tools/routine-output.d.ts +39 -0
  752. package/dist/tools/routine-output.js +281 -0
  753. package/dist/tools/routine-output.js.map +1 -0
  754. package/dist/tools/safe-env.d.ts +1 -0
  755. package/dist/tools/safe-env.js +79 -0
  756. package/dist/tools/safe-env.js.map +1 -0
  757. package/dist/tools/session-stats.d.ts +26 -0
  758. package/dist/tools/session-stats.js +51 -0
  759. package/dist/tools/session-stats.js.map +1 -0
  760. package/dist/tools/side-web-search.d.ts +34 -0
  761. package/dist/tools/side-web-search.js +146 -0
  762. package/dist/tools/side-web-search.js.map +1 -0
  763. package/dist/tools/skill.d.ts +12 -0
  764. package/dist/tools/skill.js +94 -0
  765. package/dist/tools/skill.js.map +1 -0
  766. package/dist/tools/source-path.d.ts +8 -0
  767. package/dist/tools/source-path.js +135 -0
  768. package/dist/tools/source-path.js.map +1 -0
  769. package/dist/tools/steroids.d.ts +44 -0
  770. package/dist/tools/steroids.js +356 -0
  771. package/dist/tools/steroids.js.map +1 -0
  772. package/dist/tools/subagent-control.d.ts +5 -0
  773. package/dist/tools/subagent-control.js +211 -0
  774. package/dist/tools/subagent-control.js.map +1 -0
  775. package/dist/tools/subagent-shared.d.ts +115 -0
  776. package/dist/tools/subagent-shared.js +182 -0
  777. package/dist/tools/subagent-shared.js.map +1 -0
  778. package/dist/tools/subagent.d.ts +39 -0
  779. package/dist/tools/subagent.js +412 -0
  780. package/dist/tools/subagent.js.map +1 -0
  781. package/dist/tools/task-output.d.ts +10 -0
  782. package/dist/tools/task-output.js +74 -0
  783. package/dist/tools/task-output.js.map +1 -0
  784. package/dist/tools/task-send.d.ts +11 -0
  785. package/dist/tools/task-send.js +36 -0
  786. package/dist/tools/task-send.js.map +1 -0
  787. package/dist/tools/task-stop.d.ts +8 -0
  788. package/dist/tools/task-stop.js +15 -0
  789. package/dist/tools/task-stop.js.map +1 -0
  790. package/dist/tools/tasks.d.ts +15 -0
  791. package/dist/tools/tasks.js +94 -0
  792. package/dist/tools/tasks.js.map +1 -0
  793. package/dist/tools/tool-search.d.ts +26 -0
  794. package/dist/tools/tool-search.js +81 -0
  795. package/dist/tools/tool-search.js.map +1 -0
  796. package/dist/tools/tool-tiers.d.ts +65 -0
  797. package/dist/tools/tool-tiers.js +121 -0
  798. package/dist/tools/tool-tiers.js.map +1 -0
  799. package/dist/tools/truncate.d.ts +39 -0
  800. package/dist/tools/truncate.js +242 -0
  801. package/dist/tools/truncate.js.map +1 -0
  802. package/dist/tools/ui-adopt.d.ts +16 -0
  803. package/dist/tools/ui-adopt.js +66 -0
  804. package/dist/tools/ui-adopt.js.map +1 -0
  805. package/dist/tools/ui-registry.d.ts +15 -0
  806. package/dist/tools/ui-registry.js +39 -0
  807. package/dist/tools/ui-registry.js.map +1 -0
  808. package/dist/tools/verification-review.d.ts +2 -0
  809. package/dist/tools/verification-review.js +41 -0
  810. package/dist/tools/verification-review.js.map +1 -0
  811. package/dist/tools/web-fetch.d.ts +52 -0
  812. package/dist/tools/web-fetch.js +986 -0
  813. package/dist/tools/web-fetch.js.map +1 -0
  814. package/dist/tools/web-search.d.ts +35 -0
  815. package/dist/tools/web-search.js +926 -0
  816. package/dist/tools/web-search.js.map +1 -0
  817. package/dist/tools/write.d.ts +16 -0
  818. package/dist/tools/write.js +196 -0
  819. package/dist/tools/write.js.map +1 -0
  820. package/dist/types.d.ts +44 -0
  821. package/dist/types.js +2 -0
  822. package/dist/types.js.map +1 -0
  823. package/dist/utils/commit-message.d.ts +25 -0
  824. package/dist/utils/commit-message.js +72 -0
  825. package/dist/utils/commit-message.js.map +1 -0
  826. package/dist/utils/git.d.ts +102 -0
  827. package/dist/utils/git.js +325 -0
  828. package/dist/utils/git.js.map +1 -0
  829. package/dist/utils/github-ci.d.ts +9 -0
  830. package/dist/utils/github-ci.js +138 -0
  831. package/dist/utils/github-ci.js.map +1 -0
  832. package/dist/utils/github.d.ts +19 -0
  833. package/dist/utils/github.js +67 -0
  834. package/dist/utils/github.js.map +1 -0
  835. package/dist/utils/image.d.ts +166 -0
  836. package/dist/utils/image.js +673 -0
  837. package/dist/utils/image.js.map +1 -0
  838. package/dist/utils/open-browser.d.ts +13 -0
  839. package/dist/utils/open-browser.js +31 -0
  840. package/dist/utils/open-browser.js.map +1 -0
  841. package/dist/utils/plan-steps.d.ts +90 -0
  842. package/dist/utils/plan-steps.js +209 -0
  843. package/dist/utils/plan-steps.js.map +1 -0
  844. package/dist/utils/process.d.ts +48 -0
  845. package/dist/utils/process.js +175 -0
  846. package/dist/utils/process.js.map +1 -0
  847. package/dist/utils/prompt-enhancer.d.ts +34 -0
  848. package/dist/utils/prompt-enhancer.js +178 -0
  849. package/dist/utils/prompt-enhancer.js.map +1 -0
  850. package/dist/utils/text.d.ts +61 -0
  851. package/dist/utils/text.js +68 -0
  852. package/dist/utils/text.js.map +1 -0
  853. package/package.json +87 -3
@@ -0,0 +1,902 @@
1
+ import { spawn } from "node:child_process";
2
+ import fs from "node:fs";
3
+ import fsp from "node:fs/promises";
4
+ import path from "node:path";
5
+ import os from "node:os";
6
+ import crypto from "node:crypto";
7
+ import { killProcessTree } from "../utils/process.js";
8
+ import { getSafeToolEnv } from "../tools/safe-env.js";
9
+ import { resolveShell } from "./shell.js";
10
+ const BG_DIR = path.join(os.homedir(), ".gg", "bg");
11
+ /**
12
+ * How long a background process log survives after its last write.
13
+ *
14
+ * Every `start()` opens a new `<id>.log` and nothing ever removed them, so the
15
+ * directory grew without bound for the lifetime of the install — measured at
16
+ * 14,358 files / 494MB on a single developer machine, with entries dating back
17
+ * five months. These are debugging aids for a process the agent started; once
18
+ * the run is long over, so is their value.
19
+ */
20
+ const BG_LOG_RETENTION_MS = 7 * 24 * 60 * 60 * 1000;
21
+ /** Throttle between prune sweeps, so a burst of `start()` calls scans once. */
22
+ const BG_PRUNE_INTERVAL_MS = 60 * 60 * 1000;
23
+ /** Delay before a running process may first report progress. */
24
+ const WATCH_INTERVAL_MS = 5_000;
25
+ /** Tick for model-declared wake rules (match/silence). Cheap: one stat + a
26
+ * bounded tail read, so a flat interval (no backoff) is fine. */
27
+ const WAKE_INTERVAL_MS = 500;
28
+ /** Ceiling on the progress interval as it backs off between reports. */
29
+ const WATCH_INTERVAL_MAX_MS = 120_000;
30
+ /**
31
+ * How many progress checkpoints one background process may push, ever.
32
+ *
33
+ * A progress checkpoint is worth most early ("the build is underway", "it died
34
+ * on startup") and approaches zero after that: a dev server the agent started
35
+ * itself, still logging an hour on, tells it nothing it doesn't already know
36
+ * and can always be inspected on demand with `task_output`.
37
+ *
38
+ * At a flat interval with no budget, such a server produced a fresh checkpoint
39
+ * for essentially every loop step — measured here at ~2k tokens per minute of
40
+ * overlap, i.e. a whole context window per hour spent restating "still
41
+ * running".
42
+ *
43
+ * Anthropic reached the same conclusion the hard way: Claude Code shipped
44
+ * periodic background status into the model's context as `task_progress` and
45
+ * `background_task_status` attachments, then REMOVED both (they survive only in
46
+ * a `LEGACY_ATTACHMENT_TYPES` list that drops them from resumed sessions).
47
+ * Their progress is now a host-side stream event for the UI, and the only thing
48
+ * pushed into context is the terminal completion notice.
49
+ *
50
+ * We keep a small early budget rather than going to zero: the first few reports
51
+ * are what let the agent notice a build that died on startup without blocking
52
+ * on it. Combined with the backoff those land at ~5s, ~15s and ~35s, after
53
+ * which the watcher retires and only the exit notification remains.
54
+ */
55
+ const WATCH_MAX_REPORTS = 3;
56
+ /** Chars of log tail carried in a progress checkpoint. */
57
+ const CHECKPOINT_TAIL_CHARS = 320;
58
+ /** Ceiling on a single blocking `waitForExitOrWake`, so one wedged process cannot
59
+ * hold the agent loop indefinitely; callers re-wait if they still want to. */
60
+ export const MAX_PROCESS_WAIT_MS = 300_000;
61
+ /** Output a foreground command produced before {@link ProcessManager.adopt} that
62
+ * is kept in its log; the rest was already shown to nobody and only costs disk. */
63
+ const ADOPTED_PRIOR_OUTPUT_BYTES = 1024 * 1024;
64
+ /** Chars of the matched log line carried in a pattern-wake notification. */
65
+ const WAKE_LINE_CHARS = 200;
66
+ /**
67
+ * Most new log bytes one wake tick scans. A process that floods its log faster
68
+ * than this between ticks only has its latest output checked — that is where a
69
+ * fresh failure or readiness line is.
70
+ */
71
+ const WAKE_SCAN_MAX_BYTES = 1024 * 1024;
72
+ /** ANSI escape sequences: SGR colours, cursor movement, OSC titles/links. */
73
+ // eslint-disable-next-line no-control-regex -- matching terminal escapes is the point
74
+ const ANSI_ESCAPE = /\u001b\[[0-?]*[ -/]*[@-~]|\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)/g;
75
+ /**
76
+ * Remove terminal colour and cursor codes. Test runners and CLIs colour their
77
+ * output, and a code can sit inside the very word a wake looks for:
78
+ * `\e[31mFAIL\e[0mED` never matches /FAILED/ until it is stripped.
79
+ */
80
+ export function stripAnsi(text) {
81
+ return text.replace(ANSI_ESCAPE, "");
82
+ }
83
+ /**
84
+ * Lines that mean "something failed" in the tools agents actually run in the
85
+ * background. Each one is anchored to a shape a tool prints, NOT a bare word:
86
+ * "error" or "failed" alone shows up in plenty of healthy output (file names,
87
+ * "0 failed", log levels), and a wake that cries wolf trains the agent to
88
+ * ignore it.
89
+ */
90
+ const FAILURE_LINE_PATTERNS = [
91
+ // vitest / jest file results, pytest FAILED lines, go "FAIL\tpkg".
92
+ /^\s*FAIL(?:ED)?\b(?!\s*[:=]?\s*0\b)/,
93
+ // go test.
94
+ /^\s*--- FAIL:/,
95
+ // Summaries: vitest "Tests 2 failed | 8 passed", jest "Tests: 2 failed",
96
+ // pytest "==== 2 failed, 8 passed ====", mocha "2 failing".
97
+ /^\s*(?:Tests?:?|Test Files|=+)\s.*\b[1-9]\d* failed\b/,
98
+ /^\s*[1-9]\d* failing\b/,
99
+ // vitest's failed-test marker, esbuild's "✘ [ERROR]", Playwright's list
100
+ // reporter (" ✘ 5 e2e/a.spec.ts:9:5 › …", several spaces).
101
+ /^\s*[✗✘×]\s+\S/,
102
+ // TypeScript.
103
+ /\berror TS\d{3,5}:/,
104
+ // rustc / cargo.
105
+ /^error(?:\[E\d{4}\])?: \S/,
106
+ // npm / pnpm / yarn.
107
+ /^npm ERR! /,
108
+ /\bERR_PNPM_[A-Z_]+\b/,
109
+ /\bELIFECYCLE\b.*\bfailed\b/i,
110
+ // Python, Rust panics.
111
+ /^Traceback \(most recent call last\):/,
112
+ /\bpanicked at\b/,
113
+ // Uncaught JS errors at the start of a line ("TypeError: x is undefined").
114
+ /^\s*(?:Uncaught |Unhandled )?[A-Z][A-Za-z]*Error: \S/,
115
+ // Bundlers and build tools.
116
+ /^\s*BUILD FAILED\b/,
117
+ /\bBuild failed with \d+ errors?\b/,
118
+ // GitHub Actions log lines, and `gh run watch`'s failed-job row:
119
+ // "X test (windows-latest) in 3m2s (ID 123)".
120
+ /^##\[error\]/,
121
+ /\bProcess completed with exit code [1-9]\d*\b/,
122
+ /^X .+ \(ID \d+\)\s*$/,
123
+ ];
124
+ /**
125
+ * The first line in `text` that looks like a tool reporting a failure, ANSI
126
+ * codes stripped, or undefined. Exported for tests.
127
+ */
128
+ export function findFailureLine(text) {
129
+ for (const raw of stripAnsi(text).split(/\r?\n|\r/)) {
130
+ if (raw.length > 4096)
131
+ continue; // A minified blob, not a status line.
132
+ if (FAILURE_LINE_PATTERNS.some((pattern) => pattern.test(raw)))
133
+ return raw;
134
+ }
135
+ return undefined;
136
+ }
137
+ /**
138
+ * The line holding the first match of `pattern` that ends inside `fresh`, where
139
+ * `seen` is overlap already scanned on an earlier tick. Matching across the
140
+ * boundary still counts (a line split between ticks), but a match lying wholly
141
+ * inside `seen` was already reported and must not fire again.
142
+ */
143
+ function findFreshMatchLine(pattern, seen, fresh) {
144
+ const text = seen + fresh;
145
+ const boundary = seen.length;
146
+ const flags = pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`;
147
+ for (const match of text.matchAll(new RegExp(pattern.source, flags))) {
148
+ const end = match.index + match[0].length;
149
+ if (end <= boundary && !(match[0].length === 0 && match.index >= boundary))
150
+ continue;
151
+ const lineStart = text.lastIndexOf("\n", match.index - 1) + 1;
152
+ const lineEnd = text.indexOf("\n", match.index);
153
+ return text.slice(lineStart, lineEnd === -1 ? undefined : lineEnd) || match[0];
154
+ }
155
+ return undefined;
156
+ }
157
+ /** One log line, whitespace-collapsed and tail-bounded — never the raw log. */
158
+ function boundedLine(text) {
159
+ const collapsed = text.replace(/\s+/g, " ").trim();
160
+ if (!collapsed)
161
+ return "";
162
+ return collapsed.length <= WAKE_LINE_CHARS
163
+ ? collapsed
164
+ : `\u2026${collapsed.slice(collapsed.length - WAKE_LINE_CHARS)}`;
165
+ }
166
+ /** Last line(s) of the log, collapsed and bounded — never the raw log. */
167
+ function tailDigest(text) {
168
+ const collapsed = text.replace(/\s+/g, " ").trim();
169
+ if (!collapsed)
170
+ return "";
171
+ return collapsed.length <= CHECKPOINT_TAIL_CHARS
172
+ ? collapsed
173
+ : `\u2026${collapsed.slice(collapsed.length - CHECKPOINT_TAIL_CHARS)}`;
174
+ }
175
+ function formatElapsed(ms) {
176
+ return ms >= 60_000 ? `${Math.round(ms / 6_000) / 10}m` : `${Math.round(ms / 1_000)}s`;
177
+ }
178
+ function stopProcessTree(pid, ops = {}) {
179
+ // pid 0 marks a child that never spawned. Signalling 0 (or -0) would hit
180
+ // this host's own process group.
181
+ if (pid <= 0)
182
+ return;
183
+ if (ops.killProcessTree) {
184
+ ops.killProcessTree(pid);
185
+ return;
186
+ }
187
+ // killProcessTree is itself platform-aware (taskkill /T /F on Windows).
188
+ killProcessTree(pid, { platform: ops.platform, kill: ops.kill, spawnSync: ops.spawnSync });
189
+ }
190
+ export class ProcessManager {
191
+ ops;
192
+ processes = new Map();
193
+ children = new Map();
194
+ /** Per-process progress timers. Cleared on exit, stop and shutdown. */
195
+ watchers = new Map();
196
+ /** Per-process wake-rule timers (model-declared match/silence conditions). */
197
+ wakeWatchers = new Map();
198
+ wakeStates = new Map();
199
+ /** Log size at the last emitted checkpoint, so a quiet process stays quiet. */
200
+ watchedSizes = new Map();
201
+ /** Processes the agent or host is deliberately stopping: their non-zero exit
202
+ * is the stop working, not news, so it must not raise an urgent alert. */
203
+ stopping = new Set();
204
+ /** Timestamp of the last retention sweep; 0 means "never swept". */
205
+ lastPruneAt = 0;
206
+ constructor(ops = {}) {
207
+ this.ops = ops;
208
+ }
209
+ get bgDir() {
210
+ return this.ops.bgDir ?? BG_DIR;
211
+ }
212
+ /**
213
+ * Delete background logs whose last write is older than the retention window.
214
+ *
215
+ * Deliberately best-effort and never awaited by `start()`: losing an old log
216
+ * is harmless, but failing to launch the user's process because a stale log
217
+ * couldn't be unlinked is not. Logs belonging to processes this manager still
218
+ * tracks are skipped regardless of age — a quiet long-running dev server can
219
+ * easily go a week without writing a line, and its log must stay readable.
220
+ */
221
+ async pruneOldLogs() {
222
+ const now = Date.now();
223
+ if (now - this.lastPruneAt < BG_PRUNE_INTERVAL_MS)
224
+ return;
225
+ this.lastPruneAt = now;
226
+ let entries;
227
+ try {
228
+ entries = await fsp.readdir(this.bgDir);
229
+ }
230
+ catch {
231
+ return; // Directory missing or unreadable; nothing to prune.
232
+ }
233
+ const live = new Set([...this.processes.keys()].map((id) => `${id}.log`));
234
+ const cutoff = now - BG_LOG_RETENTION_MS;
235
+ for (const entry of entries) {
236
+ if (!entry.endsWith(".log") || live.has(entry))
237
+ continue;
238
+ const file = path.join(this.bgDir, entry);
239
+ try {
240
+ const stat = await fsp.stat(file);
241
+ if (stat.mtimeMs >= cutoff)
242
+ continue;
243
+ await fsp.unlink(file);
244
+ }
245
+ catch {
246
+ // Raced with another sweep or held open elsewhere; try again next time.
247
+ }
248
+ }
249
+ }
250
+ async start(command, cwd, launch, wake,
251
+ /** Extra env for this process (e.g. the package release-age cooldown). */
252
+ extraEnv = {}) {
253
+ await fsp.mkdir(this.bgDir, { recursive: true });
254
+ void this.pruneOldLogs();
255
+ const id = crypto.randomUUID().slice(0, 8);
256
+ const logFile = path.join(this.bgDir, `${id}.log`);
257
+ const fd = fs.openSync(logFile, "w");
258
+ // Cross-platform shell (see core/shell.ts): bash on POSIX, Git Bash on
259
+ // Windows, cmd.exe fallback. Same resolution as the foreground bash tool.
260
+ const shell = launch ?? resolveShell(command);
261
+ const child = spawn(shell.file, shell.args, {
262
+ cwd,
263
+ detached: true,
264
+ // stdin is a pipe so callers can drive interactive processes (REPLs,
265
+ // scaffolders, [Y/n] prompts) via sendInput(); stdout/stderr go to the log.
266
+ stdio: ["pipe", fd, fd],
267
+ env: { ...getSafeToolEnv(), ...extraEnv },
268
+ });
269
+ fs.closeSync(fd);
270
+ // Swallow EPIPE: writing to a process that has already exited would
271
+ // otherwise emit an unhandled 'error' and crash the host.
272
+ child.stdin?.on("error", () => { });
273
+ // No pid means the spawn failed. 'error' then 'close' still fire, and track()
274
+ // records the exit, so register it with pid 0, which every kill path skips.
275
+ const pid = child.pid ?? 0;
276
+ child.unref();
277
+ const proc = {
278
+ id,
279
+ pid,
280
+ command,
281
+ logFile,
282
+ startedAt: Date.now(),
283
+ exitCode: null,
284
+ lastReadOffset: 0,
285
+ logSize: 0,
286
+ };
287
+ return this.track(child, proc, wake);
288
+ }
289
+ /**
290
+ * Take over a foreground command that is still running, so the caller can
291
+ * return without killing it. Output captured so far seeds the log (its last
292
+ * {@link ADOPTED_PRIOR_OUTPUT_BYTES} only); later stdout/stderr is appended
293
+ * as it arrives. The process keeps its cwd and environment because it is the
294
+ * same process. Its stdin was never a pipe, so `sendInput` reports it closed.
295
+ *
296
+ * Synchronous on purpose: the caller hands over a live child whose 'close'
297
+ * has not fired yet, and an `await` here could let it fire unobserved.
298
+ */
299
+ adopt(child, command, startedAt, priorOutput) {
300
+ fs.mkdirSync(this.bgDir, { recursive: true });
301
+ void this.pruneOldLogs();
302
+ const id = crypto.randomUUID().slice(0, 8);
303
+ const logFile = path.join(this.bgDir, `${id}.log`);
304
+ const prior = priorOutput.length > ADOPTED_PRIOR_OUTPUT_BYTES
305
+ ? Buffer.concat([
306
+ Buffer.from(`[earlier output dropped; last ${ADOPTED_PRIOR_OUTPUT_BYTES / 1024 / 1024} MiB kept]\n`),
307
+ priorOutput.subarray(priorOutput.length - ADOPTED_PRIOR_OUTPUT_BYTES),
308
+ ])
309
+ : priorOutput;
310
+ const fd = fs.openSync(logFile, "w");
311
+ fs.writeSync(fd, prior);
312
+ // Synchronous appends keep the log ordered and complete by the time
313
+ // 'close' fires, which the exit bookkeeping and waiters rely on.
314
+ const append = (data) => {
315
+ try {
316
+ fs.writeSync(fd, data);
317
+ }
318
+ catch {
319
+ // Disk full or log removed: drop output rather than crash the host.
320
+ }
321
+ };
322
+ child.stdout?.on("data", append);
323
+ child.stderr?.on("data", append);
324
+ child.once("close", () => fs.closeSync(fd));
325
+ // Never hold the host's event loop open for a process it no longer awaits.
326
+ child.unref();
327
+ for (const stream of [child.stdout, child.stderr]) {
328
+ stream?.unref?.();
329
+ }
330
+ const proc = {
331
+ id,
332
+ pid: child.pid ?? 0,
333
+ command,
334
+ logFile,
335
+ startedAt,
336
+ exitCode: null,
337
+ lastReadOffset: 0,
338
+ logSize: prior.length,
339
+ };
340
+ return this.track(child, proc);
341
+ }
342
+ /** Register a running child and arm its exit bookkeeping and watchers. */
343
+ track(child, proc, wake) {
344
+ const { id, pid, logFile } = proc;
345
+ this.processes.set(id, proc);
346
+ this.children.set(id, child);
347
+ // A child that fails to spawn emits 'error', and an 'error' with no listener
348
+ // is thrown as an uncaught exception that takes the whole CLI down. 'close'
349
+ // still fires afterwards (verified: ENOENT gives error then close -2), so
350
+ // exit bookkeeping below stays the single source of truth and this handler
351
+ // only has to keep the event from being fatal.
352
+ child.on("error", () => { });
353
+ child.on("close", (code) => {
354
+ proc.exitCode = code ?? 1;
355
+ this.children.delete(id);
356
+ this.disposeWatcher(id);
357
+ // Refresh unconditionally: the gate needs a final size even when no
358
+ // notification queue is wired and notifyExit is a no-op.
359
+ void this.refreshLogSize(proc).then(() => this.notifyExit(proc));
360
+ });
361
+ this.armWatcher(proc);
362
+ // Always armed: the built-in failure detector runs on every task, so a
363
+ // build or CI watcher that prints a failure but keeps running releases a
364
+ // waiting agent at once instead of at exit or the wait cap.
365
+ const wakeArmed = this.armWakeWatcher(proc, wake);
366
+ return { id, pid, logFile, wakeArmed };
367
+ }
368
+ /**
369
+ * Arm a backing-off, budgeted progress watcher for one background process.
370
+ * Emits at most one latest-only checkpoint per interval, only when the log
371
+ * actually grew, and at most {@link WATCH_MAX_REPORTS} times in total — so a
372
+ * build reports itself early without the agent ever calling `task_output`,
373
+ * while an idle or long-lived process stops costing context.
374
+ *
375
+ * Once the budget is spent the watcher retires completely (no timer, no
376
+ * further injections). The terminal exit notification is unaffected: it is
377
+ * produced by the exit handler, not this watcher, so "it finished" always
378
+ * still reaches the agent.
379
+ *
380
+ * Self-rescheduling rather than `setInterval` because the delay changes; a
381
+ * tick is only scheduled once the previous one has been handled.
382
+ *
383
+ * No-op when no notification queue is wired, so hosts that never drain
384
+ * notifications pay nothing.
385
+ */
386
+ armWatcher(proc) {
387
+ const queue = this.ops.notifications;
388
+ if (!queue)
389
+ return;
390
+ this.watchedSizes.set(proc.id, 0);
391
+ let delay = this.ops.watchIntervalMs ?? WATCH_INTERVAL_MS;
392
+ let reports = 0;
393
+ const schedule = () => {
394
+ const timer = setTimeout(() => {
395
+ // The process may have exited between ticks; the terminal checkpoint
396
+ // owns that case and must not be overwritten by a stale progress line.
397
+ if (proc.exitCode !== null) {
398
+ this.disposeWatcher(proc.id);
399
+ return;
400
+ }
401
+ void this.emitProgress(proc).then((emitted) => {
402
+ // Re-check: the process can exit while the tail read is in flight,
403
+ // and disposeWatcher may already have cleared this entry.
404
+ if (proc.exitCode !== null || !this.watchers.has(proc.id))
405
+ return;
406
+ if (emitted && ++reports >= WATCH_MAX_REPORTS) {
407
+ // Retire generic progress only; declared readiness must still fire
408
+ // if a slow server finishes starting after this budget is spent.
409
+ this.disposeProgressWatcher(proc.id);
410
+ return;
411
+ }
412
+ // Back off only on an actual report. A process that goes quiet must
413
+ // NOT drift towards the cap while emitting nothing — otherwise a dev
414
+ // server that idles and then fails a recompile is heard about minutes
415
+ // late. Silence is already free; only chattiness needs damping.
416
+ if (emitted)
417
+ delay = Math.min(delay * 2, WATCH_INTERVAL_MAX_MS);
418
+ schedule();
419
+ });
420
+ }, delay);
421
+ // Never hold the event loop open for a detached background process.
422
+ timer.unref?.();
423
+ this.watchers.set(proc.id, timer);
424
+ };
425
+ schedule();
426
+ }
427
+ /** Stat the log once and cache its size on the record. Returns 0 if unreadable. */
428
+ async refreshLogSize(proc) {
429
+ try {
430
+ proc.logSize = (await fsp.stat(proc.logFile)).size;
431
+ }
432
+ catch {
433
+ // Log may be gone (pruned, or never created); keep the last known size.
434
+ }
435
+ return proc.logSize;
436
+ }
437
+ /** Emit one progress checkpoint if the log grew. Returns whether it did. */
438
+ async emitProgress(proc) {
439
+ const queue = this.ops.notifications;
440
+ if (!queue)
441
+ return false;
442
+ const size = await this.refreshLogSize(proc);
443
+ const previous = this.watchedSizes.get(proc.id) ?? 0;
444
+ if (size <= previous)
445
+ return false;
446
+ if (proc.exitCode !== null)
447
+ return false;
448
+ const tail = await this.readTail(proc.logFile, size);
449
+ // The tail read can race a dispose: a wake rule firing (its declared
450
+ // signal outranks generic progress) or the process exiting (the terminal
451
+ // notification owns that case). An enqueue after that would supersede
452
+ // that notification in the latest-only queue, so a disposed watcher
453
+ // stays silent.
454
+ if (!this.watchers.has(proc.id))
455
+ return false;
456
+ this.watchedSizes.set(proc.id, size);
457
+ queue.enqueue("process", proc.id, `Background process ${proc.id} (${proc.command}) is still running after ` +
458
+ `${formatElapsed(Date.now() - proc.startedAt)}, ${size} bytes logged` +
459
+ `${tail ? `. Latest: ${tail}` : ""}`);
460
+ return true;
461
+ }
462
+ notifyExit(proc) {
463
+ const queue = this.ops.notifications;
464
+ if (!queue)
465
+ return;
466
+ // A failed exit is news the agent must act on; a deliberate stop is not.
467
+ const urgent = proc.exitCode !== 0 && !this.stopping.has(proc.id);
468
+ void (async () => {
469
+ const size = proc.logSize;
470
+ const tail = size > 0 ? await this.readTail(proc.logFile, size) : "";
471
+ queue.enqueue("process", proc.id, `Background process ${proc.id} (${proc.command}) exited with code ${proc.exitCode} ` +
472
+ `after ${formatElapsed(Date.now() - proc.startedAt)}` +
473
+ `${tail ? `. Last output: ${tail}` : ""}. ` +
474
+ `Read it with task_output id="${proc.id}".`, { terminal: true, urgent });
475
+ })();
476
+ }
477
+ /** Read the trailing bytes of a log without loading the whole file. */
478
+ async readTail(logFile, size) {
479
+ const start = Math.max(0, size - CHECKPOINT_TAIL_CHARS * 4);
480
+ try {
481
+ const fh = await fsp.open(logFile, "r");
482
+ try {
483
+ const buf = Buffer.alloc(size - start);
484
+ const { bytesRead } = await fh.read(buf, 0, buf.length, start);
485
+ return tailDigest(buf.subarray(0, bytesRead).toString("utf-8"));
486
+ }
487
+ finally {
488
+ await fh.close();
489
+ }
490
+ }
491
+ catch {
492
+ return "";
493
+ }
494
+ }
495
+ /** Read the bytes of a log in `[start, end)` without loading the file. */
496
+ async readBytes(logFile, start, end) {
497
+ try {
498
+ const fh = await fsp.open(logFile, "r");
499
+ try {
500
+ const buf = Buffer.alloc(Math.max(0, end - start));
501
+ const { bytesRead } = await fh.read(buf, 0, buf.length, start);
502
+ return buf.subarray(0, bytesRead);
503
+ }
504
+ finally {
505
+ await fh.close();
506
+ }
507
+ }
508
+ catch {
509
+ return Buffer.alloc(0);
510
+ }
511
+ }
512
+ /**
513
+ * Wake watcher, evaluated every {@link WAKE_INTERVAL_MS}. Always runs the
514
+ * built-in failure detector (one-shot), plus the model's declared rules when
515
+ * a notification queue can deliver them: `pattern` fires on every new match,
516
+ * `silenceMs` once. It retires on exit, or once nothing is left that could
517
+ * still fire. Unlike the progress watcher it never backs off — a late match
518
+ * on a quiet dev server is precisely the point.
519
+ *
520
+ * Returns whether the model's declared rules were armed. Without a queue they
521
+ * are not (nothing could deliver them), but failure detection still releases
522
+ * a blocking `task_output` wait directly.
523
+ */
524
+ armWakeWatcher(proc, requested) {
525
+ const wantsRules = Boolean(requested && (requested.pattern || requested.silenceMs));
526
+ const rulesArmed = wantsRules && this.ops.notifications !== undefined;
527
+ const state = {
528
+ rules: rulesArmed && requested ? requested : {},
529
+ scanOffset: 0,
530
+ failureOffset: 0,
531
+ lastSize: 0,
532
+ lastGrowthAt: proc.startedAt,
533
+ silenceFired: false,
534
+ failureFired: false,
535
+ };
536
+ this.wakeStates.set(proc.id, state);
537
+ const patternSource = state.rules.pattern?.source ?? "";
538
+ // Re-scan a little before the last offset so a match straddling the tick
539
+ // boundary is still seen; the offset only ever advances to full size.
540
+ const overlap = Math.min(256, patternSource.length + 16);
541
+ const tick = () => {
542
+ const timer = setTimeout(() => {
543
+ void this.evaluateWakeRules(proc, state, overlap).then(() => {
544
+ if (proc.exitCode !== null || !this.wakeStates.has(proc.id)) {
545
+ this.disposeWakeWatcher(proc.id);
546
+ return;
547
+ }
548
+ // A pattern can always match again, so it keeps the watcher alive.
549
+ const done = !state.rules.pattern &&
550
+ (!state.rules.silenceMs || state.silenceFired) &&
551
+ state.failureFired;
552
+ if (done) {
553
+ this.disposeWakeWatcher(proc.id);
554
+ return;
555
+ }
556
+ tick();
557
+ });
558
+ }, WAKE_INTERVAL_MS);
559
+ timer.unref?.();
560
+ this.wakeWatchers.set(proc.id, timer);
561
+ };
562
+ tick();
563
+ return rulesArmed;
564
+ }
565
+ /** Record a wake on the process and release anyone blocked waiting on it. */
566
+ fireWake(proc, reason, offset) {
567
+ proc.wakeReason = reason;
568
+ proc.wakeOffset = offset;
569
+ this.children.get(proc.id)?.emit("gg:wake", reason);
570
+ }
571
+ async evaluateWakeRules(proc, state, overlap) {
572
+ const queue = this.ops.notifications;
573
+ const size = await this.refreshLogSize(proc);
574
+ const gone = () => proc.exitCode !== null || !this.wakeStates.has(proc.id);
575
+ if (size > state.lastSize) {
576
+ state.lastSize = size;
577
+ state.lastGrowthAt = Date.now();
578
+ }
579
+ const { pattern, silenceMs } = state.rules;
580
+ if (pattern && queue && size > state.scanOffset) {
581
+ let start = Math.max(0, state.scanOffset - overlap);
582
+ if (size - start > WAKE_SCAN_MAX_BYTES)
583
+ start = size - WAKE_SCAN_MAX_BYTES;
584
+ const buf = await this.readBytes(proc.logFile, start, size);
585
+ if (gone())
586
+ return;
587
+ const boundary = Math.max(0, Math.min(buf.length, state.scanOffset - start));
588
+ state.scanOffset = Math.max(state.scanOffset, start + buf.length);
589
+ const line = findFreshMatchLine(pattern, stripAnsi(buf.subarray(0, boundary).toString("utf-8")), stripAnsi(buf.subarray(boundary).toString("utf-8")));
590
+ if (line !== undefined) {
591
+ state.lastPatternLine = boundedLine(line);
592
+ // The declared signal outranks generic progress: retire the progress
593
+ // watcher so its next tick cannot supersede this notification in the
594
+ // latest-only queue. Exit notifications come from the exit handler.
595
+ this.disposeProgressWatcher(proc.id);
596
+ queue.enqueue("process", proc.id, `Background process ${proc.id} (${proc.command}) produced output matching your wake ` +
597
+ `pattern /${pattern.source}/: ${boundedLine(line)}. Still running — ` +
598
+ `task_output id="${proc.id}" for full context.`);
599
+ this.fireWake(proc, "pattern", state.scanOffset);
600
+ }
601
+ }
602
+ if (!state.failureFired && size > state.failureOffset) {
603
+ let start = state.failureOffset;
604
+ if (size - start > WAKE_SCAN_MAX_BYTES)
605
+ start = size - WAKE_SCAN_MAX_BYTES;
606
+ const buf = await this.readBytes(proc.logFile, start, size);
607
+ if (gone())
608
+ return;
609
+ // Whole lines only: a line still being written is re-read next tick, so
610
+ // "FAI" + "LED" across two writes is still one failure line.
611
+ const lastNewline = buf.lastIndexOf(0x0a);
612
+ if (lastNewline >= 0) {
613
+ state.failureOffset = start + lastNewline + 1;
614
+ // Lines the agent has already read (task_output ran while this tick
615
+ // was reading) are not news; waking for them replays a seen failure.
616
+ const readTo = proc.lastReadOffset - start;
617
+ const unreadStart = readTo <= 0 ? 0 : buf.lastIndexOf(0x0a, readTo - 1) + 1;
618
+ const line = unreadStart >= lastNewline
619
+ ? undefined
620
+ : findFailureLine(buf.subarray(unreadStart, lastNewline).toString("utf-8"));
621
+ if (line !== undefined) {
622
+ state.failureFired = true;
623
+ this.disposeProgressWatcher(proc.id);
624
+ // The queue keeps one entry per task, so this notice replaces any
625
+ // pattern notice still pending. When both fired on the same line, say
626
+ // both: the agent asked for that pattern by name.
627
+ const shown = boundedLine(line);
628
+ const what = pattern && state.lastPatternLine === shown
629
+ ? `produced output matching your wake pattern /${pattern.source}/ that also looks like a failure`
630
+ : "printed what looks like a failure";
631
+ queue?.enqueue("process", proc.id, `Background process ${proc.id} (${proc.command}) ${what}: ` +
632
+ `${shown}. Still running — read it with task_output id="${proc.id}", ` +
633
+ `then fix the cause, stop it, or keep waiting if the failure is expected.`, { urgent: true });
634
+ this.fireWake(proc, "failure", state.failureOffset);
635
+ }
636
+ }
637
+ else if (buf.length >= WAKE_SCAN_MAX_BYTES) {
638
+ // One enormous unterminated line (a progress bar redrawn with \r):
639
+ // skip it rather than re-reading a megabyte every tick.
640
+ state.failureOffset = start + buf.length;
641
+ }
642
+ }
643
+ if (queue &&
644
+ silenceMs &&
645
+ !state.silenceFired &&
646
+ proc.exitCode === null &&
647
+ Date.now() - state.lastGrowthAt >= silenceMs) {
648
+ state.silenceFired = true;
649
+ this.disposeProgressWatcher(proc.id);
650
+ const tail = await this.readTail(proc.logFile, size);
651
+ if (gone())
652
+ return;
653
+ queue.enqueue("process", proc.id, `Background process ${proc.id} (${proc.command}) has produced no output for ` +
654
+ `${Math.round((Date.now() - state.lastGrowthAt) / 1000)}s — it may be stalled` +
655
+ `${tail ? `. Last output: ${tail}` : " (no output so far)"}. ` +
656
+ `Check task_output id="${proc.id}" and decide whether to wait, send input, or stop it.`);
657
+ this.fireWake(proc, "silence", size);
658
+ }
659
+ }
660
+ /** Stop and forget a process's wake watcher. */
661
+ disposeWakeWatcher(id) {
662
+ const timer = this.wakeWatchers.get(id);
663
+ if (timer)
664
+ clearTimeout(timer);
665
+ this.wakeWatchers.delete(id);
666
+ this.wakeStates.delete(id);
667
+ }
668
+ /** Live wake-watcher ids. Exposed for leak assertions in tests. */
669
+ activeWakeWatchers() {
670
+ return [...this.wakeWatchers.keys()];
671
+ }
672
+ /** Stop and forget a process's watcher. A finished process keeps no timer. */
673
+ disposeWatcher(id) {
674
+ this.disposeProgressWatcher(id);
675
+ this.disposeWakeWatcher(id);
676
+ }
677
+ /** Stop and forget a process's progress watcher only. */
678
+ disposeProgressWatcher(id) {
679
+ const timer = this.watchers.get(id);
680
+ if (timer)
681
+ clearTimeout(timer);
682
+ this.watchers.delete(id);
683
+ this.watchedSizes.delete(id);
684
+ }
685
+ /** Live watcher ids. Exposed for leak assertions in tests. */
686
+ activeWatchers() {
687
+ return [...this.watchers.keys()];
688
+ }
689
+ /**
690
+ * Block until a process exits or a declared wake fires, bounded by `timeoutMs`.
691
+ * Steering notifications cannot interrupt a tool call; the wake must also
692
+ * release this wait directly so a ready dev server doesn't wait for shutdown.
693
+ *
694
+ * Without this, "wait for the build" can only be expressed as a guessed
695
+ * `sleep N`: too short burns a turn, too long burns wall-clock, and neither
696
+ * knows when the process actually finished. The wake/exit notifications
697
+ * answer the same question but only on the steering path — they need a next
698
+ * loop step to be delivered, which is exactly what an agent with nothing
699
+ * else to do does not have.
700
+ */
701
+ async waitForExitOrWake(id, timeoutMs, signal) {
702
+ return (await this.waitForActivity(id, timeoutMs, signal)).reason;
703
+ }
704
+ /**
705
+ * {@link waitForExitOrWake}, plus what ended it. Besides this task exiting or
706
+ * waking, the wait also ends when ANOTHER task raises an urgent notification
707
+ * (a different build failed, a child agent finished): the agent blocked here
708
+ * has no other way to learn that before its wait runs out.
709
+ */
710
+ async waitForActivity(id, timeoutMs, signal) {
711
+ const proc = this.processes.get(id);
712
+ if (!proc)
713
+ return { reason: "unknown" };
714
+ const child = this.children.get(id);
715
+ // Already terminal (or no live child tracked): nothing to wait on.
716
+ if (!child || proc.exitCode !== null)
717
+ return { reason: "exited" };
718
+ if (signal?.aborted)
719
+ return { reason: "timeout" };
720
+ if (proc.wakeReason)
721
+ return { reason: proc.wakeReason };
722
+ const bounded = Math.min(Math.max(timeoutMs, 0), MAX_PROCESS_WAIT_MS);
723
+ return await new Promise((resolve) => {
724
+ const settle = (result) => {
725
+ clearTimeout(timer);
726
+ child.off("close", onClose);
727
+ child.off("gg:wake", onWake);
728
+ signal?.removeEventListener("abort", onAbort);
729
+ unsubscribe?.();
730
+ resolve(result);
731
+ };
732
+ // Registered after start()'s own 'close' handler, so `exitCode` is
733
+ // already set by the time this resolves.
734
+ const onClose = () => settle({ reason: "exited" });
735
+ const onWake = (reason) => settle({ reason });
736
+ // Give up the wait when the caller is cancelled; the process itself is
737
+ // left running — this only ends our observation of it.
738
+ const onAbort = () => settle({ reason: "timeout" });
739
+ const timer = setTimeout(() => settle({ reason: "timeout" }), bounded);
740
+ timer.unref?.();
741
+ child.once("close", onClose);
742
+ child.once("gg:wake", onWake);
743
+ signal?.addEventListener("abort", onAbort, { once: true });
744
+ // This task's own alerts arrive above as exit/wake; only others count here.
745
+ const unsubscribe = this.ops.notifications?.onUrgent((entry) => {
746
+ if (entry.kind === "process" && entry.id === id)
747
+ return;
748
+ settle({ reason: "other", detail: entry.text });
749
+ });
750
+ });
751
+ }
752
+ async readOutput(id, fromStart) {
753
+ const proc = this.processes.get(id);
754
+ if (!proc) {
755
+ return {
756
+ id,
757
+ isRunning: false,
758
+ exitCode: null,
759
+ output: `No background process with id "${id}"`,
760
+ };
761
+ }
762
+ const offset = fromStart ? 0 : proc.lastReadOffset;
763
+ let output = "";
764
+ try {
765
+ const stat = await fsp.stat(proc.logFile);
766
+ proc.logSize = stat.size;
767
+ if (stat.size > offset) {
768
+ const buf = Buffer.alloc(stat.size - offset);
769
+ const fh = await fsp.open(proc.logFile, "r");
770
+ const { bytesRead } = await fh.read(buf, 0, buf.length, offset);
771
+ await fh.close();
772
+ output = buf.subarray(0, bytesRead).toString("utf-8");
773
+ proc.lastReadOffset = offset + bytesRead;
774
+ }
775
+ // Consume the wake only once this read covers what it is about: a wake
776
+ // that fired while the read was in flight, for output past it, stays.
777
+ if ((proc.wakeOffset ?? 0) <= proc.lastReadOffset) {
778
+ delete proc.wakeReason;
779
+ delete proc.wakeOffset;
780
+ }
781
+ }
782
+ catch {
783
+ output = "(failed to read log file)";
784
+ // Unreadable log: a wake that can never be consumed would make every
785
+ // later wait return at once.
786
+ delete proc.wakeReason;
787
+ delete proc.wakeOffset;
788
+ }
789
+ const isRunning = this.children.has(id);
790
+ return { id, isRunning, exitCode: proc.exitCode, output };
791
+ }
792
+ /**
793
+ * Write input to a running background process's stdin, enabling interactive
794
+ * control (answer prompts, drive a REPL, feed a scaffolder). By default a
795
+ * newline is appended (as if the user pressed Enter). Set `eof` to close
796
+ * stdin afterwards, signalling end-of-input (Ctrl-D) to the program.
797
+ */
798
+ async sendInput(id, input, opts = {}) {
799
+ const proc = this.processes.get(id);
800
+ if (!proc)
801
+ return `No background process with id "${id}"`;
802
+ const child = this.children.get(id);
803
+ if (!child || proc.exitCode !== null) {
804
+ return `Process ${id} already exited (code ${proc.exitCode})`;
805
+ }
806
+ const stdin = child.stdin;
807
+ if (!stdin || stdin.destroyed || stdin.writableEnded) {
808
+ return `Process ${id} is not accepting input (stdin is closed).`;
809
+ }
810
+ const enter = opts.enter ?? true;
811
+ const text = input + (enter ? "\n" : "");
812
+ try {
813
+ if (text.length > 0) {
814
+ await new Promise((resolve, reject) => {
815
+ stdin.write(text, (err) => (err ? reject(err) : resolve()));
816
+ });
817
+ }
818
+ if (opts.eof)
819
+ stdin.end();
820
+ }
821
+ catch (err) {
822
+ return `Failed to send input to ${id}: ${err.message}`;
823
+ }
824
+ const summary = opts.eof
825
+ ? text.length > 0
826
+ ? `Sent input and closed stdin (EOF) for ${id}.`
827
+ : `Closed stdin (EOF) for ${id}.`
828
+ : `Sent input to ${id}.`;
829
+ return `${summary} Use task_output with id="${id}" to read the response.`;
830
+ }
831
+ async stop(id) {
832
+ const proc = this.processes.get(id);
833
+ if (!proc)
834
+ return `No background process with id "${id}"`;
835
+ const child = this.children.get(id);
836
+ if (!child || proc.exitCode !== null) {
837
+ return `Process ${id} already exited (code ${proc.exitCode})`;
838
+ }
839
+ if (proc.pid <= 0)
840
+ return `Process ${id} failed to start`;
841
+ this.stopping.add(id);
842
+ const isWindows = (this.ops.platform ?? process.platform) === "win32";
843
+ if (isWindows) {
844
+ // Windows has no process groups and no real SIGTERM: signalling the
845
+ // wrapper only orphans its descendants. Force-kill the PID tree up front.
846
+ stopProcessTree(proc.pid, this.ops);
847
+ }
848
+ else {
849
+ // SIGTERM the group first so POSIX children get a chance to clean up.
850
+ try {
851
+ (this.ops.kill ?? process.kill)(-proc.pid, "SIGTERM");
852
+ }
853
+ catch {
854
+ try {
855
+ (this.ops.kill ?? process.kill)(proc.pid, "SIGTERM");
856
+ }
857
+ catch {
858
+ return `Process ${id} already exited`;
859
+ }
860
+ }
861
+ }
862
+ // Wait up to 5s, then hard-kill a surviving tree.
863
+ const exited = await new Promise((resolve) => {
864
+ const timeout = setTimeout(() => resolve(false), 5000);
865
+ child.on("close", () => {
866
+ clearTimeout(timeout);
867
+ resolve(true);
868
+ });
869
+ });
870
+ if (!exited) {
871
+ if (isWindows) {
872
+ return `Failed to stop process ${id}: it did not exit within 5 seconds and may still be running.`;
873
+ }
874
+ stopProcessTree(proc.pid, this.ops);
875
+ }
876
+ return `Process ${id} stopped`;
877
+ }
878
+ list() {
879
+ // Prune completed processes older than 5 minutes to prevent Map growth
880
+ const cutoff = Date.now() - 5 * 60 * 1000;
881
+ for (const [id, proc] of this.processes) {
882
+ if (proc.exitCode !== null && !this.children.has(id) && proc.startedAt < cutoff) {
883
+ this.processes.delete(id);
884
+ this.stopping.delete(id);
885
+ this.disposeWatcher(id);
886
+ }
887
+ }
888
+ return Array.from(this.processes.values());
889
+ }
890
+ shutdownAll() {
891
+ for (const [id, proc] of this.processes) {
892
+ if (this.children.has(id)) {
893
+ this.stopping.add(id);
894
+ stopProcessTree(proc.pid, this.ops);
895
+ proc.exitCode = proc.exitCode ?? 1;
896
+ this.children.delete(id);
897
+ }
898
+ this.disposeWatcher(id);
899
+ }
900
+ }
901
+ }
902
+ //# sourceMappingURL=process-manager.js.map