@minionry/minion 0.7.36

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 (476) hide show
  1. package/LICENSE +14 -0
  2. package/PRIVACY.md +357 -0
  3. package/README.md +57 -0
  4. package/THIRD_PARTY_NOTICES.md +245 -0
  5. package/bin/branding.js +4 -0
  6. package/bin/commands/browser-install.js +483 -0
  7. package/bin/commands/create-sandbox.js +542 -0
  8. package/bin/commands/fingerprint.js +101 -0
  9. package/bin/commands/login.js +400 -0
  10. package/bin/commands/logout.js +93 -0
  11. package/bin/commands/minions.js +211 -0
  12. package/bin/commands/sandboxes.js +309 -0
  13. package/bin/commands/status.js +298 -0
  14. package/bin/commands/whoami.js +153 -0
  15. package/bin/launch-env.js +35 -0
  16. package/bin/machine-identity.js +221 -0
  17. package/bin/machine-layout.js +200 -0
  18. package/bin/minion.js +839 -0
  19. package/bin/platform-endpoints.js +8 -0
  20. package/bin/postinstall.js +52 -0
  21. package/bin/pty-doctor.js +326 -0
  22. package/bin/pty-locator.js +110 -0
  23. package/bin/pty-provision.js +186 -0
  24. package/bin/sandbox/Dockerfile +78 -0
  25. package/bin/sandbox/entrypoint.sh +14 -0
  26. package/bin/sandbox/install-repo.sh +53 -0
  27. package/bin/sandbox/seccomp-userns.json +883 -0
  28. package/bin/sandbox-config.js +306 -0
  29. package/dist/bin/machine-identity.js +221 -0
  30. package/dist/bin/machine-layout.js +200 -0
  31. package/dist/electron-host/agent-lease.js +141 -0
  32. package/dist/electron-host/dom-driver.js +642 -0
  33. package/dist/electron-host/ipc-protocol.js +89 -0
  34. package/dist/electron-host/js-driver.js +216 -0
  35. package/dist/electron-host/view-manager.js +254 -0
  36. package/dist/server/cli/engine-resume.js +49 -0
  37. package/dist/server/cli/eta-estimator.js +278 -0
  38. package/dist/server/cli/headless/background-activity.js +109 -0
  39. package/dist/server/cli/headless/claude-invoker-process.js +614 -0
  40. package/dist/server/cli/headless/claude-invoker-stall.js +150 -0
  41. package/dist/server/cli/headless/claude-invoker-stream.js +555 -0
  42. package/dist/server/cli/headless/claude-invoker-tools.js +148 -0
  43. package/dist/server/cli/headless/claude-invoker.js +151 -0
  44. package/dist/server/cli/headless/engine-availability.js +92 -0
  45. package/dist/server/cli/headless/engine-notice.js +185 -0
  46. package/dist/server/cli/headless/haiku-assessments.js +293 -0
  47. package/dist/server/cli/headless/headless-logger.js +75 -0
  48. package/dist/server/cli/headless/index.js +9 -0
  49. package/dist/server/cli/headless/mcp-config.js +314 -0
  50. package/dist/server/cli/headless/native-timeout-detector.js +72 -0
  51. package/dist/server/cli/headless/output-utils.js +71 -0
  52. package/dist/server/cli/headless/prompt-utils.js +82 -0
  53. package/dist/server/cli/headless/resilient-runner.js +326 -0
  54. package/dist/server/cli/headless/retry-strategies.js +292 -0
  55. package/dist/server/cli/headless/runner.js +245 -0
  56. package/dist/server/cli/headless/stall-assessor.js +295 -0
  57. package/dist/server/cli/headless/tool-watchdog.js +447 -0
  58. package/dist/server/cli/headless/types.js +18 -0
  59. package/dist/server/cli/history-portability.js +85 -0
  60. package/dist/server/cli/improvisation-attachments.js +99 -0
  61. package/dist/server/cli/improvisation-history-store.js +121 -0
  62. package/dist/server/cli/improvisation-movements.js +137 -0
  63. package/dist/server/cli/improvisation-output-queue.js +34 -0
  64. package/dist/server/cli/improvisation-retry.js +8 -0
  65. package/dist/server/cli/improvisation-session-manager.js +1016 -0
  66. package/dist/server/cli/improvisation-types.js +31 -0
  67. package/dist/server/cli/plan-lifecycle.js +72 -0
  68. package/dist/server/cli/prompt-builders.js +371 -0
  69. package/dist/server/cli/retry/retry-best-result.js +28 -0
  70. package/dist/server/cli/retry/retry-context-loss.js +75 -0
  71. package/dist/server/cli/retry/retry-recovery-strategies.js +213 -0
  72. package/dist/server/cli/retry/retry-resume-strategy.js +20 -0
  73. package/dist/server/cli/retry/retry-runner-factory.js +92 -0
  74. package/dist/server/cli/retry/retry-tool-results.js +22 -0
  75. package/dist/server/cli/retry/retry-types.js +3 -0
  76. package/dist/server/engines/EngineEvent.js +57 -0
  77. package/dist/server/engines/claude/ClaudeCodeEngine.js +316 -0
  78. package/dist/server/engines/claude/claude-command.js +32 -0
  79. package/dist/server/engines/codex/CodexEngine.js +469 -0
  80. package/dist/server/engines/codex/codex-auth.js +203 -0
  81. package/dist/server/engines/codex/codex-invoker.js +205 -0
  82. package/dist/server/engines/codex/codex-provision.js +215 -0
  83. package/dist/server/engines/credentials/credential-probe.js +88 -0
  84. package/dist/server/engines/credentials/model-profiles.js +249 -0
  85. package/dist/server/engines/credentials/provider-credentials.js +146 -0
  86. package/dist/server/engines/engine-event-stream.js +52 -0
  87. package/dist/server/engines/execution/engine-session.js +380 -0
  88. package/dist/server/engines/factory.js +42 -0
  89. package/dist/server/engines/hermes/HermesEngine.js +628 -0
  90. package/dist/server/engines/hermes/hermes-auth.js +159 -0
  91. package/dist/server/engines/hermes/hermes-gateway-home.js +271 -0
  92. package/dist/server/engines/hermes/hermes-invoker.js +350 -0
  93. package/dist/server/engines/hermes/hermes-provision.js +318 -0
  94. package/dist/server/engines/read-only.js +20 -0
  95. package/dist/server/engines/types.js +27 -0
  96. package/dist/server/handlers/company-execution-registry.js +67 -0
  97. package/dist/server/handlers/company-handlers.js +514 -0
  98. package/dist/server/handlers/company-triggers.js +189 -0
  99. package/dist/server/handlers/company-types.js +3 -0
  100. package/dist/server/index.js +244 -0
  101. package/dist/server/mcp/app-tools-bridge.js +110 -0
  102. package/dist/server/mcp/app-tools-mcp-server.js +99 -0
  103. package/dist/server/mcp/bouncer-integration.js +744 -0
  104. package/dist/server/mcp/browser-mcp-server.js +915 -0
  105. package/dist/server/mcp/browser-redaction.js +103 -0
  106. package/dist/server/mcp/classifier/BouncerClassifier.js +3 -0
  107. package/dist/server/mcp/classifier/ClaudeBouncerClassifier.js +212 -0
  108. package/dist/server/mcp/classifier/factory.js +124 -0
  109. package/dist/server/mcp/classifier/health.js +54 -0
  110. package/dist/server/mcp/classifier/telemetry.js +0 -0
  111. package/dist/server/mcp/company-patterns.js +104 -0
  112. package/dist/server/mcp/department-profiles.js +133 -0
  113. package/dist/server/mcp/quality-bridge.js +153 -0
  114. package/dist/server/mcp/quality-mcp-server.js +105 -0
  115. package/dist/server/mcp/security-analysis.js +384 -0
  116. package/dist/server/mcp/security-audit.js +152 -0
  117. package/dist/server/mcp/security-patterns.js +314 -0
  118. package/dist/server/mcp/server.js +194 -0
  119. package/dist/server/mcp/test-utils/agent-simulator.js +301 -0
  120. package/dist/server/mcp/test-utils/e2e-agent.js +103 -0
  121. package/dist/server/mcp/test-utils/e2e-capture.js +92 -0
  122. package/dist/server/mcp/test-utils/e2e-client.js +116 -0
  123. package/dist/server/mcp/test-utils/e2e-fixtures.js +87 -0
  124. package/dist/server/mcp/test-utils/e2e-gating.js +8 -0
  125. package/dist/server/mcp/test-utils/e2e-harness.js +8 -0
  126. package/dist/server/mcp/test-utils/e2e-scenarios.js +105 -0
  127. package/dist/server/routes/files.js +18 -0
  128. package/dist/server/routes/improvise.js +64 -0
  129. package/dist/server/routes/index.js +7 -0
  130. package/dist/server/routes/instances.js +41 -0
  131. package/dist/server/routes/internal.js +900 -0
  132. package/dist/server/routes/notifications.js +110 -0
  133. package/dist/server/server-setup.js +282 -0
  134. package/dist/server/services/agent-push.js +148 -0
  135. package/dist/server/services/analytics.js +197 -0
  136. package/dist/server/services/apps/build.js +249 -0
  137. package/dist/server/services/apps/greenlight.js +199 -0
  138. package/dist/server/services/apps/install.js +101 -0
  139. package/dist/server/services/apps/layout.js +35 -0
  140. package/dist/server/services/apps/serve.js +665 -0
  141. package/dist/server/services/apps/space-apps.js +248 -0
  142. package/dist/server/services/auth.js +48 -0
  143. package/dist/server/services/browser/chrome-sandbox.js +245 -0
  144. package/dist/server/services/browser/chromium-launch-spec.js +51 -0
  145. package/dist/server/services/browser/claude-reasoner.js +669 -0
  146. package/dist/server/services/browser/debug-log.js +3 -0
  147. package/dist/server/services/browser/driver-state.js +546 -0
  148. package/dist/server/services/browser/electron-provision.js +256 -0
  149. package/dist/server/services/browser/host-internal.js +245 -0
  150. package/dist/server/services/browser/host-mock.js +334 -0
  151. package/dist/server/services/browser/host-types.js +3 -0
  152. package/dist/server/services/browser/host.js +1067 -0
  153. package/dist/server/services/browser/index.js +4 -0
  154. package/dist/server/services/browser/ipc-client.js +354 -0
  155. package/dist/server/services/browser/pipewire-sink.js +199 -0
  156. package/dist/server/services/browser/preflight.js +590 -0
  157. package/dist/server/services/browser/reasoning-agent.js +659 -0
  158. package/dist/server/services/browser/sandbox-policy.js +169 -0
  159. package/dist/server/services/browser/stderr-noise-filter.js +26 -0
  160. package/dist/server/services/browser/telemetry.js +107 -0
  161. package/dist/server/services/browser/xvfb-supervisor.js +139 -0
  162. package/dist/server/services/browser-frame-policy.js +56 -0
  163. package/dist/server/services/client-id.js +32 -0
  164. package/dist/server/services/collab/registry.js +408 -0
  165. package/dist/server/services/collab/session.js +489 -0
  166. package/dist/server/services/collab/text-diff.js +28 -0
  167. package/dist/server/services/collab/types.js +19 -0
  168. package/dist/server/services/e2ee-group-key.js +197 -0
  169. package/dist/server/services/e2ee-identity.js +203 -0
  170. package/dist/server/services/file-explorer-ops.js +328 -0
  171. package/dist/server/services/file-transfer-zip.js +188 -0
  172. package/dist/server/services/files.js +111 -0
  173. package/dist/server/services/git/branch-ops.js +62 -0
  174. package/dist/server/services/git/command.js +68 -0
  175. package/dist/server/services/git/commit-message.js +74 -0
  176. package/dist/server/services/git/diff-ops.js +56 -0
  177. package/dist/server/services/git/haiku.js +76 -0
  178. package/dist/server/services/git/head-watcher.js +226 -0
  179. package/dist/server/services/git/index.js +17 -0
  180. package/dist/server/services/git/log-ops.js +98 -0
  181. package/dist/server/services/git/merge-ops.js +314 -0
  182. package/dist/server/services/git/parsers.js +401 -0
  183. package/dist/server/services/git/remote-ops.js +192 -0
  184. package/dist/server/services/git/status-ops.js +105 -0
  185. package/dist/server/services/git/suggestion-ops.js +80 -0
  186. package/dist/server/services/git/tag-ops.js +36 -0
  187. package/dist/server/services/git/types.js +4 -0
  188. package/dist/server/services/git/worktree-ops.js +114 -0
  189. package/dist/server/services/instances.js +337 -0
  190. package/dist/server/services/model-catalog.js +247 -0
  191. package/dist/server/services/observability/posthog.js +153 -0
  192. package/dist/server/services/pathUtils.js +114 -0
  193. package/dist/server/services/plan/agent-loader.js +97 -0
  194. package/dist/server/services/plan/agent-manager.js +363 -0
  195. package/dist/server/services/plan/agent-resolver.js +74 -0
  196. package/dist/server/services/plan/agents/assess-stall.md +33 -0
  197. package/dist/server/services/plan/agents/browser-planner.md +53 -0
  198. package/dist/server/services/plan/agents/browser-reasoner.md +114 -0
  199. package/dist/server/services/plan/agents/check-injection.md +95 -0
  200. package/dist/server/services/plan/agents/classify-error.md +30 -0
  201. package/dist/server/services/plan/agents/code-review.md +142 -0
  202. package/dist/server/services/plan/agents/commit-message.md +28 -0
  203. package/dist/server/services/plan/agents/detect-context-loss.md +30 -0
  204. package/dist/server/services/plan/agents/execute-issue.md +58 -0
  205. package/dist/server/services/plan/agents/fix-quality.md +25 -0
  206. package/dist/server/services/plan/agents/plan-coordinator.md +72 -0
  207. package/dist/server/services/plan/agents/pr-description.md +29 -0
  208. package/dist/server/services/plan/agents/retry-task.md +27 -0
  209. package/dist/server/services/plan/agents/review-code.md +38 -0
  210. package/dist/server/services/plan/agents/review-quality.md +45 -0
  211. package/dist/server/services/plan/agents/triage-findings.md +78 -0
  212. package/dist/server/services/plan/agents/verify-review.md +57 -0
  213. package/dist/server/services/plan/approval-evaluator.js +143 -0
  214. package/dist/server/services/plan/board-archive.js +102 -0
  215. package/dist/server/services/plan/board-config.js +108 -0
  216. package/dist/server/services/plan/board-export.js +214 -0
  217. package/dist/server/services/plan/composer-prompt.js +115 -0
  218. package/dist/server/services/plan/composer.js +664 -0
  219. package/dist/server/services/plan/config-installer.js +103 -0
  220. package/dist/server/services/plan/dependency-resolver.js +137 -0
  221. package/dist/server/services/plan/executor.js +696 -0
  222. package/dist/server/services/plan/front-matter.js +43 -0
  223. package/dist/server/services/plan/issue-classification.js +10 -0
  224. package/dist/server/services/plan/issue-effort.js +182 -0
  225. package/dist/server/services/plan/issue-loader.js +35 -0
  226. package/dist/server/services/plan/issue-prompt-builder.js +152 -0
  227. package/dist/server/services/plan/issue-retry.js +42 -0
  228. package/dist/server/services/plan/issue-writer.js +102 -0
  229. package/dist/server/services/plan/metrics-collector.js +272 -0
  230. package/dist/server/services/plan/output-manager.js +77 -0
  231. package/dist/server/services/plan/parser-core.js +435 -0
  232. package/dist/server/services/plan/parser-migration.js +108 -0
  233. package/dist/server/services/plan/parser.js +258 -0
  234. package/dist/server/services/plan/plan-runner-factory.js +68 -0
  235. package/dist/server/services/plan/pm-timeline.js +320 -0
  236. package/dist/server/services/plan/progress-log.js +101 -0
  237. package/dist/server/services/plan/prompt-builder.js +142 -0
  238. package/dist/server/services/plan/quality-delta.js +274 -0
  239. package/dist/server/services/plan/readiness-planner.js +34 -0
  240. package/dist/server/services/plan/review-gate.js +409 -0
  241. package/dist/server/services/plan/review-report.js +134 -0
  242. package/dist/server/services/plan/review-verdict-stream.js +161 -0
  243. package/dist/server/services/plan/state-reconciler.js +238 -0
  244. package/dist/server/services/plan/template-diff.js +175 -0
  245. package/dist/server/services/plan/template-instantiator.js +516 -0
  246. package/dist/server/services/plan/template-manifest.js +56 -0
  247. package/dist/server/services/plan/template-types.js +3 -0
  248. package/dist/server/services/plan/trigger-evaluator.js +211 -0
  249. package/dist/server/services/plan/types.js +3 -0
  250. package/dist/server/services/plan/watcher.js +73 -0
  251. package/dist/server/services/platform-credentials.js +56 -0
  252. package/dist/server/services/platform-e2ee.js +421 -0
  253. package/dist/server/services/platform-envelope.js +102 -0
  254. package/dist/server/services/platform-heartbeat.js +88 -0
  255. package/dist/server/services/platform-reconnect.js +60 -0
  256. package/dist/server/services/platform-token-lifecycle.js +95 -0
  257. package/dist/server/services/platform-url.js +17 -0
  258. package/dist/server/services/platform.js +656 -0
  259. package/dist/server/services/runtime-info.js +9 -0
  260. package/dist/server/services/schedule/agent-schedule-store.js +232 -0
  261. package/dist/server/services/schedule/agent-scheduler.js +323 -0
  262. package/dist/server/services/schedule/daily-timing.js +105 -0
  263. package/dist/server/services/schedule/quality-schedule-launch.js +11 -0
  264. package/dist/server/services/schedule/quality-schedule-store.js +211 -0
  265. package/dist/server/services/schedule/quality-scheduler.js +215 -0
  266. package/dist/server/services/schedule/run-bootstrap.js +329 -0
  267. package/dist/server/services/schedule/schedule-store.js +238 -0
  268. package/dist/server/services/schedule/schedule-wire.js +77 -0
  269. package/dist/server/services/schedule/scheduler.js +310 -0
  270. package/dist/server/services/schedule/template-source.js +97 -0
  271. package/dist/server/services/sdk/agent-sessions.js +264 -0
  272. package/dist/server/services/sdk/agents.js +557 -0
  273. package/dist/server/services/sdk/app-endpoints.js +48 -0
  274. package/dist/server/services/sdk/app-tools.js +303 -0
  275. package/dist/server/services/sdk/audit.js +48 -0
  276. package/dist/server/services/sdk/browser-transport.js +188 -0
  277. package/dist/server/services/sdk/browser.js +605 -0
  278. package/dist/server/services/sdk/composer.js +129 -0
  279. package/dist/server/services/sdk/connect.js +273 -0
  280. package/dist/server/services/sdk/consent-cooldown.js +31 -0
  281. package/dist/server/services/sdk/endpoint-url.js +141 -0
  282. package/dist/server/services/sdk/endpoints.js +314 -0
  283. package/dist/server/services/sdk/file-change-notify.js +36 -0
  284. package/dist/server/services/sdk/files-app.js +163 -0
  285. package/dist/server/services/sdk/files-search.js +131 -0
  286. package/dist/server/services/sdk/files-transfer.js +279 -0
  287. package/dist/server/services/sdk/files-workspace.js +233 -0
  288. package/dist/server/services/sdk/git.js +520 -0
  289. package/dist/server/services/sdk/grant-store.js +318 -0
  290. package/dist/server/services/sdk/host-ops.js +84 -0
  291. package/dist/server/services/sdk/inference-claude.js +214 -0
  292. package/dist/server/services/sdk/inference.js +247 -0
  293. package/dist/server/services/sdk/live-registry.js +42 -0
  294. package/dist/server/services/sdk/local-app-bindings.js +71 -0
  295. package/dist/server/services/sdk/pipeline.js +190 -0
  296. package/dist/server/services/sdk/pm-execute.js +228 -0
  297. package/dist/server/services/sdk/pm-planning-tap.js +29 -0
  298. package/dist/server/services/sdk/pm-schedule.js +165 -0
  299. package/dist/server/services/sdk/pm.js +634 -0
  300. package/dist/server/services/sdk/quality-change-notify.js +20 -0
  301. package/dist/server/services/sdk/quality-schedule.js +165 -0
  302. package/dist/server/services/sdk/quality.js +602 -0
  303. package/dist/server/services/sdk/rate-limits.js +198 -0
  304. package/dist/server/services/sdk/registry.js +597 -0
  305. package/dist/server/services/sdk/revoke.js +86 -0
  306. package/dist/server/services/sdk/run-profile.js +41 -0
  307. package/dist/server/services/sdk/sandbox.js +89 -0
  308. package/dist/server/services/sdk/storage.js +110 -0
  309. package/dist/server/services/sdk/streams.js +147 -0
  310. package/dist/server/services/sdk/terminal.js +201 -0
  311. package/dist/server/services/sdk/test-utils/workshop-browser-app.js +466 -0
  312. package/dist/server/services/sentry.js +99 -0
  313. package/dist/server/services/settings.js +374 -0
  314. package/dist/server/services/snippets/expander.js +87 -0
  315. package/dist/server/services/snippets/index.js +6 -0
  316. package/dist/server/services/snippets/loader.js +119 -0
  317. package/dist/server/services/snippets/parser.js +52 -0
  318. package/dist/server/services/snippets/types.js +3 -0
  319. package/dist/server/services/snippets/watcher.js +60 -0
  320. package/dist/server/services/space-layout.js +80 -0
  321. package/dist/server/services/system-prompts.js +219 -0
  322. package/dist/server/services/terminal/pty-manager.js +206 -0
  323. package/dist/server/services/terminal/pty-utils.js +150 -0
  324. package/dist/server/services/timeline/assembler.js +890 -0
  325. package/dist/server/services/timeline/contract.js +196 -0
  326. package/dist/server/services/timeline/index.js +4 -0
  327. package/dist/server/services/websocket/agent-schedule-handlers.js +217 -0
  328. package/dist/server/services/websocket/apps-handlers.js +399 -0
  329. package/dist/server/services/websocket/ask-user-question-bridge.js +112 -0
  330. package/dist/server/services/websocket/autocomplete-index.js +415 -0
  331. package/dist/server/services/websocket/autocomplete-match.js +243 -0
  332. package/dist/server/services/websocket/autocomplete.js +407 -0
  333. package/dist/server/services/websocket/browser-agent-runtime.js +208 -0
  334. package/dist/server/services/websocket/browser-device-profile.js +46 -0
  335. package/dist/server/services/websocket/browser-handlers.js +377 -0
  336. package/dist/server/services/websocket/browser-host-broadcast.js +179 -0
  337. package/dist/server/services/websocket/browser-ice-config.js +121 -0
  338. package/dist/server/services/websocket/browser-payloads.js +222 -0
  339. package/dist/server/services/websocket/browser-viewer-lifecycle.js +84 -0
  340. package/dist/server/services/websocket/browser-viewer-registry.js +118 -0
  341. package/dist/server/services/websocket/collab-broadcast.js +11 -0
  342. package/dist/server/services/websocket/collab-handlers.js +116 -0
  343. package/dist/server/services/websocket/commit-suggestion-service.js +132 -0
  344. package/dist/server/services/websocket/debug-log.js +38 -0
  345. package/dist/server/services/websocket/dispatch-util.js +10 -0
  346. package/dist/server/services/websocket/engine-auth-handlers.js +323 -0
  347. package/dist/server/services/websocket/engine-credential-watcher.js +83 -0
  348. package/dist/server/services/websocket/engine-profile-handlers.js +92 -0
  349. package/dist/server/services/websocket/file-definition-handlers.js +180 -0
  350. package/dist/server/services/websocket/file-download-handler.js +291 -0
  351. package/dist/server/services/websocket/file-explorer-handlers.js +291 -0
  352. package/dist/server/services/websocket/file-search-handlers.js +267 -0
  353. package/dist/server/services/websocket/file-share-handlers.js +328 -0
  354. package/dist/server/services/websocket/file-transfer-http.js +361 -0
  355. package/dist/server/services/websocket/file-upload-handler.js +267 -0
  356. package/dist/server/services/websocket/file-utils.js +346 -0
  357. package/dist/server/services/websocket/git-branch-handlers.js +90 -0
  358. package/dist/server/services/websocket/git-diff-handlers.js +59 -0
  359. package/dist/server/services/websocket/git-handlers.js +212 -0
  360. package/dist/server/services/websocket/git-head-watcher.js +85 -0
  361. package/dist/server/services/websocket/git-log-handlers.js +104 -0
  362. package/dist/server/services/websocket/git-pr-handlers.js +56 -0
  363. package/dist/server/services/websocket/git-tag-handlers.js +53 -0
  364. package/dist/server/services/websocket/git-utils.js +11 -0
  365. package/dist/server/services/websocket/git-worktree-handlers.js +521 -0
  366. package/dist/server/services/websocket/handler-context.js +113 -0
  367. package/dist/server/services/websocket/handler.js +1197 -0
  368. package/dist/server/services/websocket/index.js +5 -0
  369. package/dist/server/services/websocket/movement-written-files.js +26 -0
  370. package/dist/server/services/websocket/msg-id-tracker.js +48 -0
  371. package/dist/server/services/websocket/plan-board-handlers.js +410 -0
  372. package/dist/server/services/websocket/plan-execution-handlers.js +244 -0
  373. package/dist/server/services/websocket/plan-handlers.js +67 -0
  374. package/dist/server/services/websocket/plan-helpers.js +161 -0
  375. package/dist/server/services/websocket/plan-issue-handlers.js +168 -0
  376. package/dist/server/services/websocket/plan-sprint-handlers.js +190 -0
  377. package/dist/server/services/websocket/plan-transfer-handlers.js +310 -0
  378. package/dist/server/services/websocket/pm-timeline-broadcast.js +28 -0
  379. package/dist/server/services/websocket/post-session-scan.js +132 -0
  380. package/dist/server/services/websocket/prompt-queue-handlers.js +96 -0
  381. package/dist/server/services/websocket/quality-agent-cost.js +229 -0
  382. package/dist/server/services/websocket/quality-agent-notes.js +113 -0
  383. package/dist/server/services/websocket/quality-change-activity.js +187 -0
  384. package/dist/server/services/websocket/quality-complexity.js +345 -0
  385. package/dist/server/services/websocket/quality-dependencies.js +445 -0
  386. package/dist/server/services/websocket/quality-duplication.js +162 -0
  387. package/dist/server/services/websocket/quality-eta.js +65 -0
  388. package/dist/server/services/websocket/quality-fingerprint.js +104 -0
  389. package/dist/server/services/websocket/quality-grading.js +575 -0
  390. package/dist/server/services/websocket/quality-handlers.js +48 -0
  391. package/dist/server/services/websocket/quality-linting.js +270 -0
  392. package/dist/server/services/websocket/quality-operations.js +54 -0
  393. package/dist/server/services/websocket/quality-persistence.js +410 -0
  394. package/dist/server/services/websocket/quality-review-agent.js +526 -0
  395. package/dist/server/services/websocket/quality-run.js +220 -0
  396. package/dist/server/services/websocket/quality-secrets.js +0 -0
  397. package/dist/server/services/websocket/quality-service.js +775 -0
  398. package/dist/server/services/websocket/quality-tools.js +383 -0
  399. package/dist/server/services/websocket/quality-triage-agent.js +101 -0
  400. package/dist/server/services/websocket/quality-types.js +149 -0
  401. package/dist/server/services/websocket/recommended-answers.js +28 -0
  402. package/dist/server/services/websocket/schedule-handlers.js +197 -0
  403. package/dist/server/services/websocket/sdk-agent-host.js +569 -0
  404. package/dist/server/services/websocket/sdk-browser-host.js +459 -0
  405. package/dist/server/services/websocket/sdk-composer-host.js +10 -0
  406. package/dist/server/services/websocket/sdk-git-host.js +115 -0
  407. package/dist/server/services/websocket/sdk-handlers.js +242 -0
  408. package/dist/server/services/websocket/sdk-pm-execution-host.js +63 -0
  409. package/dist/server/services/websocket/sdk-pm-schedule-host.js +21 -0
  410. package/dist/server/services/websocket/sdk-quality-schedule-host.js +34 -0
  411. package/dist/server/services/websocket/sdk-terminal-host.js +140 -0
  412. package/dist/server/services/websocket/session-handlers.js +565 -0
  413. package/dist/server/services/websocket/session-history.js +335 -0
  414. package/dist/server/services/websocket/session-initialization.js +315 -0
  415. package/dist/server/services/websocket/session-registry.js +340 -0
  416. package/dist/server/services/websocket/session-role-directory.js +39 -0
  417. package/dist/server/services/websocket/settings-handlers.js +276 -0
  418. package/dist/server/services/websocket/skill-handlers.js +324 -0
  419. package/dist/server/services/websocket/skill-watcher.js +83 -0
  420. package/dist/server/services/websocket/snippet-handlers.js +261 -0
  421. package/dist/server/services/websocket/tab-broadcast.js +35 -0
  422. package/dist/server/services/websocket/tab-event-buffer.js +110 -0
  423. package/dist/server/services/websocket/tab-event-replay.js +47 -0
  424. package/dist/server/services/websocket/tab-handlers.js +211 -0
  425. package/dist/server/services/websocket/terminal-handlers.js +268 -0
  426. package/dist/server/services/websocket/types.js +96 -0
  427. package/dist/server/types/company-messages.js +102 -0
  428. package/dist/server/utils/agent-manager.js +202 -0
  429. package/dist/server/utils/console-timestamps.js +24 -0
  430. package/dist/server/utils/file-store.js +112 -0
  431. package/dist/server/utils/paths.js +28 -0
  432. package/dist/server/utils/port-manager.js +43 -0
  433. package/dist/server/utils/port.js +204 -0
  434. package/electron-host/dist/agent-lease.js +141 -0
  435. package/electron-host/dist/capture-recovery.js +77 -0
  436. package/electron-host/dist/codec-policy.js +37 -0
  437. package/electron-host/dist/controller-channel.js +60 -0
  438. package/electron-host/dist/controller-handlers.js +153 -0
  439. package/electron-host/dist/device-emulator.js +106 -0
  440. package/electron-host/dist/dom-driver.js +642 -0
  441. package/electron-host/dist/domain-registry.js +159 -0
  442. package/electron-host/dist/domain-validators.js +308 -0
  443. package/electron-host/dist/editable-focus-reporter.js +143 -0
  444. package/electron-host/dist/fake-peer.test-util.js +105 -0
  445. package/electron-host/dist/host-log.js +31 -0
  446. package/electron-host/dist/host-wire.js +11 -0
  447. package/electron-host/dist/input-router.js +421 -0
  448. package/electron-host/dist/ipc-protocol.js +89 -0
  449. package/electron-host/dist/ipc-server.js +193 -0
  450. package/electron-host/dist/js-driver.js +216 -0
  451. package/electron-host/dist/main-guards.js +70 -0
  452. package/electron-host/dist/main.js +716 -0
  453. package/electron-host/dist/roster-sync.js +87 -0
  454. package/electron-host/dist/rpc-context.js +1 -0
  455. package/electron-host/dist/rpc-tab-methods.js +138 -0
  456. package/electron-host/dist/rpc-webrtc-methods.js +121 -0
  457. package/electron-host/dist/screen-capture-cache.js +147 -0
  458. package/electron-host/dist/sdk-injector.js +166 -0
  459. package/electron-host/dist/sdp.js +102 -0
  460. package/electron-host/dist/session-surface.js +78 -0
  461. package/electron-host/dist/surface-sizing.js +59 -0
  462. package/electron-host/dist/view-manager.js +254 -0
  463. package/electron-host/dist/viewer-registry.js +46 -0
  464. package/electron-host/dist/viewer-session.js +288 -0
  465. package/electron-host/dist/webrtc-channels.js +14 -0
  466. package/electron-host/dist/webrtc-controller.js +57 -0
  467. package/electron-host/dist/webrtc-ice-filter.js +13 -0
  468. package/electron-host/dist/webrtc-peer.js +45 -0
  469. package/electron-host/package.json +12 -0
  470. package/electron-host/tsconfig.json +23 -0
  471. package/electron-host/webrtc-controller-preload.cjs +3 -0
  472. package/electron-host/webrtc-controller.html +14 -0
  473. package/package.json +85 -0
  474. package/vendor/e2ee/LICENSE +14 -0
  475. package/vendor/e2ee/package.json +14 -0
  476. package/vendor/e2ee/src/index.js +310 -0
@@ -0,0 +1,31 @@
1
+ // Copyright (c) 2025-present Minionry, Inc.
2
+ // SPDX-License-Identifier: LicenseRef-Minionry-Software
3
+ export const SESSION_HISTORY_FORMAT_VERSION = 2;
4
+ export function createRetryLoopState(promptWithAttachments, maxRetries) {
5
+ return {
6
+ promptWithAttachments,
7
+ maxRetries,
8
+ currentPrompt: promptWithAttachments,
9
+ retryNumber: 0,
10
+ checkpointRef: { value: null },
11
+ contextRecoverySessionId: undefined,
12
+ freshRecoveryMode: false,
13
+ accumulatedToolResults: [],
14
+ contextLost: false,
15
+ lastWatchdogCheckpoint: null,
16
+ timedOutTools: [],
17
+ bestResult: null,
18
+ retryLog: [],
19
+ lastUseResume: false,
20
+ lastNativeTimeouts: 0,
21
+ assessments: [],
22
+ assessorFailed: false,
23
+ serverErrorRetries: 0,
24
+ };
25
+ }
26
+ export function scoreRunResult(r) {
27
+ const toolCount = r.toolUseHistory?.filter(t => t.result !== undefined && !t.isError).length ?? 0;
28
+ const responseLen = Math.min((r.assistantResponse?.length ?? 0) / 50, 100);
29
+ const hasThinking = r.thinkingOutput ? 20 : 0;
30
+ return toolCount * 10 + responseLen + hasThinking;
31
+ }
@@ -0,0 +1,72 @@
1
+ // Copyright (c) 2025-present Minionry, Inc.
2
+ // SPDX-License-Identifier: LicenseRef-Minionry-Software
3
+ export async function abortPlan(planId, deps, opts = {}) {
4
+ if (!planId)
5
+ return { releasedTabs: [], closedTabs: [] };
6
+ const { host, driverState } = deps;
7
+ const leases = await host.listLeases({ planId });
8
+ const tabIds = leases.map((l) => l.tabId);
9
+ const { released } = await host.releasePlan(planId);
10
+ for (const tabId of released) {
11
+ try {
12
+ driverState.clearOwner(tabId);
13
+ }
14
+ catch {
15
+ }
16
+ }
17
+ const closed = [];
18
+ if (opts.closeTabs) {
19
+ const toClose = new Set([...tabIds, ...released]);
20
+ for (const tabId of toClose) {
21
+ try {
22
+ await host.closeTab(tabId);
23
+ closed.push(tabId);
24
+ }
25
+ catch {
26
+ }
27
+ }
28
+ }
29
+ return { releasedTabs: released, closedTabs: closed };
30
+ }
31
+ export async function pausePlan(planId, deps) {
32
+ if (!planId)
33
+ return { pausedTabs: [] };
34
+ const { host, driverState } = deps;
35
+ const leases = await host.listLeases({ planId });
36
+ const paused = [];
37
+ for (const lease of leases) {
38
+ if (driverState.getState(lease.tabId) === 'automation' &&
39
+ driverState.getMode(lease.tabId) === 'parked') {
40
+ continue;
41
+ }
42
+ driverState.park(lease.tabId, 'plan-paused');
43
+ paused.push(lease.tabId);
44
+ }
45
+ return { pausedTabs: paused };
46
+ }
47
+ export async function resumePlan(planId, deps) {
48
+ if (!planId)
49
+ return { resumedTabs: [] };
50
+ const { host, driverState } = deps;
51
+ const leases = await host.listLeases({ planId });
52
+ const resumed = [];
53
+ for (const lease of leases) {
54
+ if (driverState.resume(lease.tabId))
55
+ resumed.push(lease.tabId);
56
+ }
57
+ return { resumedTabs: resumed };
58
+ }
59
+ export async function completePlan(planId, deps) {
60
+ if (!planId)
61
+ return { releasedTabs: [] };
62
+ const { host, driverState } = deps;
63
+ const { released } = await host.releasePlan(planId);
64
+ for (const tabId of released) {
65
+ try {
66
+ driverState.clearOwner(tabId);
67
+ }
68
+ catch {
69
+ }
70
+ }
71
+ return { releasedTabs: released };
72
+ }
@@ -0,0 +1,371 @@
1
+ import { loadSkillPrompt } from '../services/plan/agent-loader.js';
2
+ export function summarizeToolInput(input) {
3
+ if (input.url)
4
+ return String(input.url).slice(0, 100);
5
+ if (input.query)
6
+ return String(input.query).slice(0, 100);
7
+ if (input.command)
8
+ return String(input.command).slice(0, 100);
9
+ if (input.prompt)
10
+ return String(input.prompt).slice(0, 100);
11
+ return JSON.stringify(input).slice(0, 100);
12
+ }
13
+ const NETWORK_TOOLS = new Set(['WebFetch', 'WebSearch']);
14
+ export function formatTimedOutTools(tools) {
15
+ const lines = [];
16
+ const networkTools = tools.filter(t => NETWORK_TOOLS.has(t.toolName));
17
+ const localTools = tools.filter(t => !NETWORK_TOOLS.has(t.toolName));
18
+ if (networkTools.length > 0) {
19
+ lines.push('### Network resources that timed out (DO NOT retry these URLs):');
20
+ for (const t of networkTools) {
21
+ const inputSummary = summarizeToolInput(t.input);
22
+ lines.push(`- **${t.toolName}**(${inputSummary}) — timed out after ${Math.round(t.timeoutMs / 1000)}s`);
23
+ }
24
+ }
25
+ if (localTools.length > 0) {
26
+ lines.push('### Tools that previously timed out (OK to retry with same or smaller content):');
27
+ for (const t of localTools) {
28
+ const inputSummary = summarizeToolInput(t.input);
29
+ lines.push(`- **${t.toolName}**(${inputSummary}) — timed out after ${Math.round(t.timeoutMs / 1000)}s`);
30
+ }
31
+ }
32
+ return lines;
33
+ }
34
+ export function formatCompletedTools(tools, maxLen = 2000) {
35
+ const lines = [];
36
+ lines.push('### Results already obtained:');
37
+ for (const tool of tools) {
38
+ const inputSummary = summarizeToolInput(tool.input);
39
+ const preview = tool.result.length > maxLen ? `${tool.result.slice(0, maxLen)}...` : tool.result;
40
+ lines.push(`- **${tool.toolName}**(${inputSummary}): ${preview}`);
41
+ }
42
+ return lines;
43
+ }
44
+ export function formatInProgressTools(tools) {
45
+ const lines = [];
46
+ lines.push('### Tools that were still running (lost when process was killed):');
47
+ for (const tool of tools) {
48
+ const inputSummary = summarizeToolInput(tool.input);
49
+ lines.push(`- **${tool.toolName}**(${inputSummary}) — was in progress, may need re-running`);
50
+ }
51
+ return lines;
52
+ }
53
+ export function formatToolResults(toolResults, maxLen = 3000) {
54
+ const completed = toolResults.filter(t => t.result !== undefined && !t.isError);
55
+ if (completed.length === 0)
56
+ return [];
57
+ const lines = [`### ${completed.length} preserved results from prior work:`, ''];
58
+ for (const tool of completed) {
59
+ const inputSummary = summarizeToolInput(tool.toolInput);
60
+ const preview = tool.result && tool.result.length > maxLen
61
+ ? `${tool.result.slice(0, maxLen)}...\n(truncated, ${tool.result.length} chars total)`
62
+ : tool.result || '';
63
+ lines.push(`**${tool.toolName}**(${inputSummary}):`);
64
+ lines.push(preview);
65
+ lines.push('');
66
+ }
67
+ return lines;
68
+ }
69
+ export function formatConversationHistory(movements, maxMovements = 5) {
70
+ const recent = movements.slice(-maxMovements);
71
+ if (recent.length === 0)
72
+ return [];
73
+ const lines = ['### Conversation so far:'];
74
+ for (const movement of recent) {
75
+ const promptText = movement.userPrompt.length > 300 ? `${movement.userPrompt.slice(0, 300)}...` : movement.userPrompt;
76
+ lines.push(`**User (prompt ${movement.sequenceNumber}):** ${promptText}`);
77
+ if (movement.assistantResponse) {
78
+ const response = movement.assistantResponse.length > 1000
79
+ ? `${movement.assistantResponse.slice(0, 1000)}...\n(truncated, ${movement.assistantResponse.length} chars)`
80
+ : movement.assistantResponse;
81
+ lines.push(`**Your response:** ${response}`);
82
+ }
83
+ lines.push('');
84
+ }
85
+ return lines;
86
+ }
87
+ export function buildHistoricalContext(movements) {
88
+ if (movements.length === 0) {
89
+ return '';
90
+ }
91
+ const contextParts = [
92
+ '--- CONVERSATION HISTORY (for context, do not repeat these responses) ---',
93
+ ''
94
+ ];
95
+ for (const movement of movements) {
96
+ contextParts.push(`[User Prompt ${movement.sequenceNumber}]:`);
97
+ const promptText = movement.userPrompt.length > 2000
98
+ ? `${movement.userPrompt.slice(0, 2000)}\n... (prompt truncated for context)`
99
+ : movement.userPrompt;
100
+ contextParts.push(promptText);
101
+ contextParts.push('');
102
+ if (movement.assistantResponse) {
103
+ contextParts.push(`[Your Response ${movement.sequenceNumber}]:`);
104
+ const response = movement.assistantResponse.length > 2000
105
+ ? `${movement.assistantResponse.slice(0, 2000)}\n... (response truncated for context)`
106
+ : movement.assistantResponse;
107
+ contextParts.push(response);
108
+ contextParts.push('');
109
+ }
110
+ if (movement.toolUseHistory && movement.toolUseHistory.length > 0) {
111
+ contextParts.push(`[Tools Used in Prompt ${movement.sequenceNumber}]:`);
112
+ for (const tool of movement.toolUseHistory) {
113
+ contextParts.push(`- ${tool.toolName}`);
114
+ }
115
+ contextParts.push('');
116
+ }
117
+ }
118
+ contextParts.push('--- END OF CONVERSATION HISTORY ---');
119
+ contextParts.push('');
120
+ contextParts.push('Continue the conversation from where we left off. The user is now asking:');
121
+ contextParts.push('');
122
+ return contextParts.join('\n');
123
+ }
124
+ export function buildRetryPrompt(checkpoint, originalPrompt, allTimedOut) {
125
+ const urlSuffix = checkpoint.hungTool.url ? ` while fetching: ${checkpoint.hungTool.url}` : '';
126
+ const hungToolTimeoutSec = String(Math.round(checkpoint.hungTool.timeoutMs / 1000));
127
+ const timedOutToolsSection = allTimedOut && allTimedOut.length > 0
128
+ ? formatTimedOutTools(allTimedOut).join('\n')
129
+ : 'This URL/resource is unreachable. DO NOT retry the same URL or query.';
130
+ const completedToolsSection = checkpoint.completedTools.length > 0
131
+ ? formatCompletedTools(checkpoint.completedTools).join('\n')
132
+ : '';
133
+ const inProgressToolsSection = checkpoint.inProgressTools && checkpoint.inProgressTools.length > 0
134
+ ? formatInProgressTools(checkpoint.inProgressTools).join('\n')
135
+ : '';
136
+ const assistantTextSection = checkpoint.assistantText
137
+ ? `### Your response before interruption:\n${checkpoint.assistantText.length > 8000 ? `${checkpoint.assistantText.slice(0, 8000)}...\n(truncated — full response was ${checkpoint.assistantText.length} chars)` : checkpoint.assistantText}`
138
+ : '';
139
+ const fromSkill = loadSkillPrompt('retry-task', {
140
+ hungToolName: checkpoint.hungTool.toolName,
141
+ hungToolTimeoutSec,
142
+ urlSuffix,
143
+ timedOutToolsSection,
144
+ completedToolsSection,
145
+ inProgressToolsSection,
146
+ assistantTextSection,
147
+ originalPrompt,
148
+ });
149
+ if (fromSkill)
150
+ return fromSkill;
151
+ const parts = [
152
+ '## AUTOMATIC RETRY -- Previous Execution Interrupted',
153
+ '',
154
+ `The previous execution was interrupted because ${checkpoint.hungTool.toolName} timed out after ${hungToolTimeoutSec}s${urlSuffix}.`,
155
+ '',
156
+ timedOutToolsSection,
157
+ '',
158
+ ];
159
+ if (completedToolsSection)
160
+ parts.push(completedToolsSection, '');
161
+ if (inProgressToolsSection)
162
+ parts.push(inProgressToolsSection, '');
163
+ if (assistantTextSection)
164
+ parts.push(assistantTextSection, '');
165
+ parts.push('### Original task (continue from where you left off):');
166
+ parts.push(originalPrompt);
167
+ parts.push('');
168
+ parts.push('INSTRUCTIONS:');
169
+ parts.push('1. Use the results above -- do not re-fetch content you already have');
170
+ parts.push('2. Find ALTERNATIVE sources for the content that timed out (different URL, different approach)');
171
+ parts.push('3. Re-run any in-progress tools that were lost (listed above) if their results are needed');
172
+ parts.push('4. If no alternative exists, proceed with the results you have and note what was unavailable');
173
+ return parts.join('\n');
174
+ }
175
+ const WRITE_TOOLS = new Set(['Write', 'Edit', 'MultiEdit', 'NotebookEdit']);
176
+ export function buildResumeRetryPrompt(checkpoint, allTimedOut) {
177
+ const parts = [];
178
+ parts.push(`Your previous ${checkpoint.hungTool.toolName} call timed out after ${Math.round(checkpoint.hungTool.timeoutMs / 1000)}s${checkpoint.hungTool.url ? ` fetching: ${checkpoint.hungTool.url}` : ''}.`);
179
+ parts.push(...formatTimedOutForResume(allTimedOut));
180
+ parts.push(...formatInFlightForResume(checkpoint.inProgressTools));
181
+ parts.push('Continue your task — find alternative sources for network failures, or proceed with the results you already have.');
182
+ return parts.join('\n');
183
+ }
184
+ function formatTimedOutForResume(allTimedOut) {
185
+ if (!allTimedOut || allTimedOut.length === 0)
186
+ return [];
187
+ const lines = [''];
188
+ const networkTools = allTimedOut.filter(t => NETWORK_TOOLS.has(t.toolName));
189
+ const localTools = allTimedOut.filter(t => !NETWORK_TOOLS.has(t.toolName));
190
+ if (networkTools.length > 0) {
191
+ lines.push('Network resources that timed out (DO NOT retry these URLs):');
192
+ for (const t of networkTools)
193
+ lines.push(`- ${t.toolName}(${summarizeToolInput(t.input)})`);
194
+ }
195
+ if (localTools.length > 0) {
196
+ lines.push('Tools that previously timed out (OK to retry):');
197
+ for (const t of localTools)
198
+ lines.push(`- ${t.toolName}(${summarizeToolInput(t.input)})`);
199
+ }
200
+ return lines;
201
+ }
202
+ function formatInFlightForResume(inProgress) {
203
+ if (!inProgress || inProgress.length === 0)
204
+ return [];
205
+ const lines = ['', 'These tool calls were still running when the process was stopped, so you never saw their results:'];
206
+ for (const t of inProgress) {
207
+ const verifyHint = WRITE_TOOLS.has(t.toolName)
208
+ ? ' — check the file on disk first; re-run only if the change is not there'
209
+ : ' — re-run it if you still need its result';
210
+ lines.push(`- ${t.toolName}(${summarizeToolInput(t.input)})${verifyHint}`);
211
+ }
212
+ return lines;
213
+ }
214
+ export function buildPendingBackgroundContinuePrompt(tasks) {
215
+ const parts = [
216
+ 'Your previous turn ended while these background tasks were still pending:',
217
+ ];
218
+ for (const t of tasks.slice(0, 10)) {
219
+ parts.push(`- ${t.description || t.taskType || t.taskId}${t.taskType && t.description ? ` (${t.taskType})` : ''}`);
220
+ }
221
+ if (tasks.length > 10)
222
+ parts.push(`- … and ${tasks.length - 10} more`);
223
+ parts.push('');
224
+ parts.push('This is a headless run: the process exits when you end your turn, so their completion notifications will NEVER wake you. Do not wait for a callback.');
225
+ parts.push('Check each task\'s status and output directly (TaskOutput, the files it writes, the command it ran), re-launch anything that did not finish, and complete the original task in THIS turn.');
226
+ return parts.join('\n');
227
+ }
228
+ export function buildServerErrorRetryPrompt(originalPrompt, isResume, toolResults) {
229
+ if (isResume) {
230
+ return [
231
+ 'Your previous turn was cut short by a temporary API error on the server side (not by anything you did).',
232
+ 'Your conversation history and every completed tool result are preserved. Review where you left off and continue the task.',
233
+ ].join('\n');
234
+ }
235
+ const parts = [
236
+ '## AUTOMATIC RETRY — Temporary API Error',
237
+ '',
238
+ 'The previous execution was cut short by a temporary API error (server side). The task itself did not fail.',
239
+ ];
240
+ if (toolResults && toolResults.length > 0) {
241
+ parts.push('', ...formatToolResults(toolResults));
242
+ }
243
+ parts.push('### Original task:', originalPrompt, '', 'Continue from where the previous attempt left off, using the preserved results above.');
244
+ return parts.join('\n');
245
+ }
246
+ export function buildContextRecoveryPrompt(originalPrompt) {
247
+ const parts = [];
248
+ parts.push('Your previous response indicated you lost context due to tool timeouts, but your full conversation history is preserved — including all successful tool results.');
249
+ parts.push('');
250
+ parts.push('Review your conversation history above. You already have results from many successful tool calls. Use those results to continue the task.');
251
+ parts.push('');
252
+ parts.push('Original task:');
253
+ parts.push(originalPrompt);
254
+ parts.push('');
255
+ parts.push('INSTRUCTIONS:');
256
+ parts.push('1. Review your conversation history — all your previous tool results are still available');
257
+ parts.push('2. Continue from where you left off using the results you already gathered');
258
+ parts.push('3. If specific tool calls timed out, skip those and work with what you have');
259
+ parts.push('4. Do NOT start over — build on the work already done');
260
+ parts.push('5. Do NOT spawn Task subagents for work that previously timed out — do it inline instead');
261
+ parts.push('6. Prefer multiple small, focused tool calls over single large ones to avoid further timeouts');
262
+ return parts.join('\n');
263
+ }
264
+ export function buildFreshRecoveryPrompt(originalPrompt, toolResults, timedOutTools) {
265
+ const parts = [
266
+ '## CONTINUING LONG-RUNNING TASK',
267
+ '',
268
+ 'The previous execution encountered tool timeouts and lost context.',
269
+ 'Below are all results gathered before the interruption. Continue the task using these results.',
270
+ '',
271
+ ];
272
+ if (timedOutTools && timedOutTools.length > 0) {
273
+ parts.push(...formatTimedOutTools(timedOutTools), '');
274
+ }
275
+ parts.push(...formatToolResults(toolResults));
276
+ parts.push('### Original task:');
277
+ parts.push(originalPrompt);
278
+ parts.push('');
279
+ parts.push('INSTRUCTIONS:');
280
+ parts.push('1. Use the preserved results above — do NOT re-fetch data you already have');
281
+ parts.push('2. Continue the task from where it was interrupted');
282
+ parts.push('3. If you need additional data, fetch it (but try alternative sources if the original timed out)');
283
+ parts.push('4. Complete the original task fully');
284
+ parts.push('5. Do NOT spawn Task subagents for work that previously timed out — do it inline instead');
285
+ parts.push('6. Prefer multiple small, focused tool calls over single large ones to avoid further timeouts');
286
+ return parts.join('\n');
287
+ }
288
+ export function buildInterMovementRecoveryPrompt(originalPrompt, toolResults, movements) {
289
+ const parts = [
290
+ '## SESSION RECOVERY — Prior Session Expired',
291
+ '',
292
+ 'Your previous session expired between prompts. Below is a summary of the conversation so far and all preserved tool results.',
293
+ '',
294
+ ];
295
+ parts.push(...formatConversationHistory(movements));
296
+ parts.push(...formatToolResults(toolResults));
297
+ parts.push('### Current user prompt:');
298
+ parts.push(originalPrompt);
299
+ parts.push('');
300
+ parts.push('INSTRUCTIONS:');
301
+ parts.push('1. Use the preserved results above — do NOT re-fetch data you already have');
302
+ parts.push('2. Continue the conversation naturally based on the history above');
303
+ parts.push('3. If you need additional data, fetch it with small focused tool calls');
304
+ parts.push('4. Do NOT spawn Task subagents — do work inline to avoid further timeouts');
305
+ parts.push('5. Prefer multiple small, focused tool calls over single large ones');
306
+ return parts.join('\n');
307
+ }
308
+ export function buildSignalCrashRecoveryPrompt(originalPrompt, isResume, toolResults, backgroundWorkLost = false) {
309
+ const parts = [];
310
+ if (isResume) {
311
+ parts.push('Your previous execution was interrupted by a system signal (the process was killed externally).');
312
+ parts.push('Your full conversation history is preserved — including all successful tool results.');
313
+ if (backgroundWorkLost) {
314
+ parts.push('');
315
+ parts.push('IMPORTANT: Background agents/workflows you launched were terminated with the process. Their completion notifications will NEVER arrive — do not wait for them and do not schedule wakeups to check on them. Re-launch the background work you still need, or do it directly, and drive the task to completion.');
316
+ }
317
+ parts.push('');
318
+ parts.push('Review your conversation history above and continue from where you left off.');
319
+ }
320
+ else {
321
+ parts.push('## AUTOMATIC RETRY — Previous Execution Interrupted');
322
+ parts.push('');
323
+ parts.push('The previous execution was interrupted by a system signal (process killed).');
324
+ if (backgroundWorkLost) {
325
+ parts.push('Background agents/workflows from that run were terminated with it — their notifications will never arrive. Re-launch any background work you still need instead of waiting.');
326
+ }
327
+ if (toolResults && toolResults.length > 0) {
328
+ parts.push(`${toolResults.length} tool results were preserved from prior work.`);
329
+ parts.push('');
330
+ parts.push('### Preserved results:');
331
+ for (const t of toolResults.slice(-20)) {
332
+ const inputSummary = JSON.stringify(t.toolInput).slice(0, 120);
333
+ const resultPreview = (t.result ?? '').slice(0, 200);
334
+ parts.push(`- **${t.toolName}**(${inputSummary}): ${resultPreview}`);
335
+ }
336
+ }
337
+ }
338
+ parts.push('');
339
+ parts.push('### Original task:');
340
+ parts.push(originalPrompt);
341
+ parts.push('');
342
+ parts.push('INSTRUCTIONS:');
343
+ parts.push('1. Use the results above -- do not re-fetch content you already have');
344
+ parts.push('2. Continue from where you left off');
345
+ parts.push('3. Prefer multiple small, focused tool calls over single large ones');
346
+ parts.push(backgroundWorkLost
347
+ ? '4. Re-launch the background agents/workflows the task still needs promptly — the old ones are gone and will never report back'
348
+ : '4. Do NOT spawn Task subagents — do work inline to avoid further interruptions');
349
+ return parts.join('\n');
350
+ }
351
+ export function extractHistoricalToolResults(movements, maxMovements = 3) {
352
+ const results = [];
353
+ const recentMovements = movements.slice(-maxMovements);
354
+ for (const movement of recentMovements) {
355
+ if (!movement.toolUseHistory)
356
+ continue;
357
+ for (const tool of movement.toolUseHistory) {
358
+ if (tool.result !== undefined && !tool.isError) {
359
+ results.push({
360
+ toolName: tool.toolName,
361
+ toolId: tool.toolId,
362
+ toolInput: tool.toolInput,
363
+ result: tool.result,
364
+ isError: tool.isError,
365
+ duration: tool.duration,
366
+ });
367
+ }
368
+ }
369
+ }
370
+ return results;
371
+ }
@@ -0,0 +1,28 @@
1
+ // Copyright (c) 2025-present Minionry, Inc.
2
+ // SPDX-License-Identifier: LicenseRef-Minionry-Software
3
+ import { resolveClaudeCommand } from '../../engines/claude/claude-command.js';
4
+ import { hlog } from '../headless/headless-logger.js';
5
+ import { chooseBestAttempt } from '../headless/retry-strategies.js';
6
+ export async function selectBestResult(state, result, userPrompt, verbose) {
7
+ if (!state.bestResult || state.bestResult === result || state.retryNumber === 0) {
8
+ return result;
9
+ }
10
+ const claudeCmd = resolveClaudeCommand();
11
+ const { chosen, assessment } = await chooseBestAttempt(state.bestResult, result, userPrompt, claudeCmd, verbose);
12
+ state.assessments.push(assessment);
13
+ if (!assessment.assessed)
14
+ state.assessorFailed = true;
15
+ if (chosen === result) {
16
+ if (verbose)
17
+ hlog(`[BEST-RESULT] Final attempt kept: ${assessment.reason}`);
18
+ return result;
19
+ }
20
+ if (verbose)
21
+ hlog(`[BEST-RESULT] Earlier attempt kept: ${assessment.reason}`);
22
+ return mergeResultSessionId(state.bestResult, result.claudeSessionId);
23
+ }
24
+ function mergeResultSessionId(result, sessionId) {
25
+ if (sessionId)
26
+ return { ...result, claudeSessionId: sessionId };
27
+ return result;
28
+ }
@@ -0,0 +1,75 @@
1
+ // Copyright (c) 2025-present Minionry, Inc.
2
+ // SPDX-License-Identifier: LicenseRef-Minionry-Software
3
+ import { resolveClaudeCommand } from '../../engines/claude/claude-command.js';
4
+ import { hlog } from '../headless/headless-logger.js';
5
+ import { assessContextLoss } from '../headless/stall-assessor.js';
6
+ const WRITE_TOOL_NAMES = new Set(['Edit', 'Write', 'MultiEdit', 'NotebookEdit']);
7
+ export function detectResumeContextLoss(result, state, verbose) {
8
+ if (!state.lastUseResume || state.checkpointRef.value || state.retryNumber >= state.maxRetries || state.lastNativeTimeouts > 0) {
9
+ return;
10
+ }
11
+ if (result.engineNotice || result.startupTimedOut)
12
+ return;
13
+ if (!result.assistantResponse || result.assistantResponse.trim().length === 0) {
14
+ state.contextLost = true;
15
+ if (verbose)
16
+ hlog('[CONTEXT-RECOVERY] Resume context loss: null/empty response');
17
+ }
18
+ else if (result.resumeBufferedOutput !== undefined) {
19
+ state.contextLost = true;
20
+ if (verbose)
21
+ hlog('[CONTEXT-RECOVERY] Resume context loss: buffer never flushed (no thinking/tools)');
22
+ }
23
+ else if ((!result.toolUseHistory || result.toolUseHistory.length === 0) &&
24
+ !result.thinkingOutput &&
25
+ result.assistantResponse.length < 500) {
26
+ state.contextLost = true;
27
+ if (verbose)
28
+ hlog('[CONTEXT-RECOVERY] Resume context loss: no tools, no thinking, short response');
29
+ }
30
+ }
31
+ export async function detectNativeTimeoutContextLoss(result, state, verbose) {
32
+ if (state.contextLost)
33
+ return;
34
+ const nativeTimeouts = state.lastNativeTimeouts;
35
+ const { effectiveTimeouts } = computeEffectiveTimeouts(result, nativeTimeouts);
36
+ if (effectiveTimeouts === 0 || !result.assistantResponse || state.checkpointRef.value || state.retryNumber >= state.maxRetries) {
37
+ return;
38
+ }
39
+ if (result.engineNotice)
40
+ return;
41
+ const contextLossCtx = {
42
+ assistantResponse: result.assistantResponse,
43
+ effectiveTimeouts,
44
+ nativeTimeoutCount: nativeTimeouts,
45
+ successfulToolCalls: result.toolUseHistory?.filter(t => t.result !== undefined && !t.isError).length ?? 0,
46
+ thinkingOutputLength: result.thinkingOutput?.length ?? 0,
47
+ hasSuccessfulWrite: result.toolUseHistory?.some(t => WRITE_TOOL_NAMES.has(t.toolName) && t.result !== undefined && !t.isError) ?? false,
48
+ };
49
+ const claudeCmd = resolveClaudeCommand();
50
+ const verdict = await assessContextLoss(contextLossCtx, claudeCmd, verbose);
51
+ state.assessments.push({
52
+ kind: 'context-loss',
53
+ verdict: verdict.assessed ? (verdict.contextLost ? 'LOST' : 'OK') : 'UNAVAILABLE',
54
+ reason: verdict.reason,
55
+ assessed: verdict.assessed,
56
+ at: Date.now(),
57
+ });
58
+ if (!verdict.assessed)
59
+ state.assessorFailed = true;
60
+ state.contextLost = verdict.contextLost;
61
+ if (verbose) {
62
+ hlog(`[CONTEXT-RECOVERY] Haiku verdict: ${state.contextLost ? 'LOST' : 'OK'} — ${verdict.reason}`);
63
+ }
64
+ }
65
+ function computeEffectiveTimeouts(result, nativeTimeouts) {
66
+ const succeededIds = new Set();
67
+ const allIds = new Set();
68
+ for (const t of result.toolUseHistory ?? []) {
69
+ allIds.add(t.toolId);
70
+ if (t.result !== undefined)
71
+ succeededIds.add(t.toolId);
72
+ }
73
+ const toolsWithoutResult = [...allIds].filter(id => !succeededIds.has(id)).length;
74
+ return { effectiveTimeouts: Math.max(nativeTimeouts, toolsWithoutResult) };
75
+ }