@apralabs/apra-fleet 0.4.4 → 0.4.5

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 (268) hide show
  1. package/README.md +49 -4
  2. package/dist/agents/backlog-groomer.md +5 -0
  3. package/dist/agents/ci-watcher.md +5 -0
  4. package/dist/agents/deployer.md +20 -2
  5. package/dist/agents/doer.md +38 -2
  6. package/dist/agents/harvester.md +12 -9
  7. package/dist/agents/integ-test-runner.md +5 -0
  8. package/dist/agents/kb-reconciler.md +6 -0
  9. package/dist/agents/plan-reviewer.md +5 -0
  10. package/dist/agents/planner.md +5 -0
  11. package/dist/agents/regression-test-runner.md +5 -0
  12. package/dist/agents/reviewer.md +67 -15
  13. package/dist/agents/schemas/deployer-output.json +5 -0
  14. package/dist/agents/schemas/doer-output.json +78 -2
  15. package/dist/agents/schemas/reviewer-output.json +104 -2
  16. package/dist/cli/auth.js +5 -1
  17. package/dist/cli/beads-pin.js +6 -7
  18. package/dist/cli/claude-mod.d.ts +75 -0
  19. package/dist/cli/claude-mod.js +288 -0
  20. package/dist/cli/dolt-install.d.ts +1 -1
  21. package/dist/cli/dolt-install.js +5 -1
  22. package/dist/cli/fleet-se-guard.d.ts +8 -0
  23. package/dist/cli/fleet-se-guard.js +19 -3
  24. package/dist/cli/install-guard.d.ts +9 -0
  25. package/dist/cli/install-guard.js +24 -0
  26. package/dist/cli/install.d.ts +12 -0
  27. package/dist/cli/install.js +180 -20
  28. package/dist/cli/kb-profile.d.ts +16 -0
  29. package/dist/cli/kb-profile.js +81 -0
  30. package/dist/cli/start.js +3 -0
  31. package/dist/cli/uninstall.js +13 -3
  32. package/dist/cli/update.d.ts +4 -0
  33. package/dist/cli/update.js +19 -3
  34. package/dist/commands/kb-server.d.ts +10 -1
  35. package/dist/commands/kb-server.js +285 -11
  36. package/dist/index.js +22 -1
  37. package/dist/os/git-executable.d.ts +57 -0
  38. package/dist/os/git-executable.js +85 -0
  39. package/dist/os/go-concurrency.d.ts +44 -0
  40. package/dist/os/go-concurrency.js +53 -0
  41. package/dist/os/index.d.ts +1 -0
  42. package/dist/os/index.js +1 -0
  43. package/dist/os/linux.d.ts +2 -0
  44. package/dist/os/linux.js +10 -1
  45. package/dist/os/os-commands.d.ts +25 -0
  46. package/dist/os/os-commands.js +2 -0
  47. package/dist/os/windows-executable.d.ts +53 -0
  48. package/dist/os/windows-executable.js +185 -0
  49. package/dist/os/windows-gitbash.d.ts +23 -14
  50. package/dist/os/windows-gitbash.js +40 -16
  51. package/dist/os/windows.d.ts +2 -0
  52. package/dist/os/windows.js +37 -6
  53. package/dist/paths.d.ts +10 -1
  54. package/dist/paths.js +19 -2
  55. package/dist/services/agy-project.d.ts +7 -1
  56. package/dist/services/agy-project.js +7 -2
  57. package/dist/services/auth-socket.d.ts +18 -0
  58. package/dist/services/auth-socket.js +30 -4
  59. package/dist/services/credential-store.d.ts +33 -0
  60. package/dist/services/credential-store.js +79 -2
  61. package/dist/services/http-transport.d.ts +29 -0
  62. package/dist/services/http-transport.js +166 -37
  63. package/dist/services/kb-tool-profile.d.ts +36 -0
  64. package/dist/services/kb-tool-profile.js +88 -0
  65. package/dist/services/knowledge/bible-blob-id.js +10 -1
  66. package/dist/services/knowledge/bible-import.d.ts +108 -0
  67. package/dist/services/knowledge/bible-import.js +137 -4
  68. package/dist/services/knowledge/file-hash.js +6 -5
  69. package/dist/services/knowledge/http-provider.d.ts +303 -20
  70. package/dist/services/knowledge/http-provider.js +795 -125
  71. package/dist/services/knowledge/kb-config.d.ts +65 -1
  72. package/dist/services/knowledge/kb-config.js +143 -3
  73. package/dist/services/knowledge/kb-http-auth-state.d.ts +26 -0
  74. package/dist/services/knowledge/kb-http-auth-state.js +40 -0
  75. package/dist/services/knowledge/kb-providers.d.ts +9 -2
  76. package/dist/services/knowledge/kb-providers.js +67 -37
  77. package/dist/services/knowledge/kb-removed-scope-keys.js +1 -1
  78. package/dist/services/knowledge/kb-self.d.ts +122 -9
  79. package/dist/services/knowledge/kb-self.js +196 -36
  80. package/dist/services/knowledge/member-bible-view.js +16 -3
  81. package/dist/services/knowledge/path-validation.d.ts +7 -0
  82. package/dist/services/knowledge/path-validation.js +11 -0
  83. package/dist/services/knowledge/project-slug.js +3 -2
  84. package/dist/services/knowledge/repository-header.d.ts +77 -0
  85. package/dist/services/knowledge/repository-header.js +233 -0
  86. package/dist/services/knowledge/require-sqlite-project.d.ts +1 -1
  87. package/dist/services/knowledge/require-sqlite-project.js +1 -1
  88. package/dist/services/knowledge/sqlite-provider.d.ts +169 -0
  89. package/dist/services/knowledge/sqlite-provider.js +416 -4
  90. package/dist/services/knowledge/types.d.ts +15 -2
  91. package/dist/services/member-busy.d.ts +12 -0
  92. package/dist/services/member-busy.js +20 -0
  93. package/dist/services/member-config-io.d.ts +3 -2
  94. package/dist/services/member-config-io.js +7 -4
  95. package/dist/services/member-fleet-install.js +1 -0
  96. package/dist/services/member-tool-allowlist.d.ts +1 -1
  97. package/dist/services/member-tool-allowlist.js +8 -4
  98. package/dist/services/port-holder.js +2 -1
  99. package/dist/services/service-manager/types.d.ts +17 -1
  100. package/dist/services/service-manager/windows.d.ts +7 -2
  101. package/dist/services/service-manager/windows.js +28 -11
  102. package/dist/services/service-notice.d.ts +7 -0
  103. package/dist/services/service-notice.js +19 -0
  104. package/dist/services/session-registry.d.ts +13 -0
  105. package/dist/services/session-registry.js +13 -0
  106. package/dist/services/session-roots.d.ts +67 -0
  107. package/dist/services/session-roots.js +126 -0
  108. package/dist/services/statusline.d.ts +21 -0
  109. package/dist/services/statusline.js +97 -1
  110. package/dist/services/supervisor-service-cleanup.js +2 -1
  111. package/dist/services/tool-registry.js +108 -20
  112. package/dist/services/tool-scope.d.ts +34 -1
  113. package/dist/services/tool-scope.js +27 -2
  114. package/dist/services/vcs/azure-devops.js +10 -0
  115. package/dist/services/vcs/bitbucket.d.ts +22 -1
  116. package/dist/services/vcs/bitbucket.js +163 -17
  117. package/dist/services/vcs/types.d.ts +25 -2
  118. package/dist/services/watch/project-resolver.js +2 -1
  119. package/dist/skills/pm/cost.md +5 -1
  120. package/dist/skills/pm/index.md +9 -9
  121. package/dist/skills/pm/sprint.md +2 -1
  122. package/dist/tools/check-status.d.ts +51 -0
  123. package/dist/tools/check-status.js +124 -12
  124. package/dist/tools/code-intelligence-freshness.js +1 -1
  125. package/dist/tools/code-intelligence-gitnexus.d.ts +19 -0
  126. package/dist/tools/code-intelligence-gitnexus.js +166 -9
  127. package/dist/tools/code-intelligence-readiness.d.ts +58 -1
  128. package/dist/tools/code-intelligence-readiness.js +93 -8
  129. package/dist/tools/code-intelligence-reindex.d.ts +25 -1
  130. package/dist/tools/code-intelligence-reindex.js +76 -4
  131. package/dist/tools/code-intelligence.d.ts +1 -1
  132. package/dist/tools/code-intelligence.js +1 -1
  133. package/dist/tools/execute-command.js +14 -8
  134. package/dist/tools/execute-prompt.js +6 -2
  135. package/dist/tools/fleet-snapshot.d.ts +21 -0
  136. package/dist/tools/fleet-snapshot.js +78 -0
  137. package/dist/tools/kb-bible-commit.d.ts +25 -11
  138. package/dist/tools/kb-bible-commit.js +142 -33
  139. package/dist/tools/kb-capture.d.ts +2 -2
  140. package/dist/tools/kb-context.js +47 -27
  141. package/dist/tools/kb-demote.d.ts +27 -0
  142. package/dist/tools/kb-demote.js +37 -0
  143. package/dist/tools/kb-export.d.ts +35 -3
  144. package/dist/tools/kb-export.js +56 -13
  145. package/dist/tools/kb-feedback.d.ts +2 -0
  146. package/dist/tools/kb-feedback.js +17 -7
  147. package/dist/tools/kb-harvest.js +28 -9
  148. package/dist/tools/kb-import.d.ts +18 -2
  149. package/dist/tools/kb-import.js +24 -9
  150. package/dist/tools/kb-invalidate.d.ts +11 -3
  151. package/dist/tools/kb-invalidate.js +80 -7
  152. package/dist/tools/kb-list.js +38 -10
  153. package/dist/tools/kb-promote.js +6 -4
  154. package/dist/tools/kb-query.d.ts +3 -0
  155. package/dist/tools/kb-query.js +181 -37
  156. package/dist/tools/kb-session-prime.d.ts +4 -4
  157. package/dist/tools/kb-session-prime.js +89 -9
  158. package/dist/tools/kb-setup.d.ts +20 -0
  159. package/dist/tools/kb-setup.js +149 -11
  160. package/dist/tools/list-members.js +1 -1
  161. package/dist/tools/member-detail.js +7 -3
  162. package/dist/tools/provision-vcs-auth.d.ts +28 -3
  163. package/dist/tools/provision-vcs-auth.js +53 -7
  164. package/dist/tools/receive-files.js +7 -4
  165. package/dist/tools/send-files.js +5 -4
  166. package/dist/tools/send-message.d.ts +3 -0
  167. package/dist/tools/send-message.js +15 -2
  168. package/dist/tools/stop-prompt.js +3 -1
  169. package/dist/tools/vcs-credential-exec.d.ts +45 -3
  170. package/dist/tools/vcs-credential-exec.js +90 -11
  171. package/dist/utils/process-utils.js +5 -1
  172. package/dist/utils/redact-known-secrets.d.ts +17 -0
  173. package/dist/utils/redact-known-secrets.js +70 -0
  174. package/dist/utils/skill-matrix.js +1 -1
  175. package/dist/utils/vcs-provider-detect.js +2 -2
  176. package/dist/workflows/auto-sprint.js +245 -9
  177. package/package.json +10 -7
  178. package/packages/apra-fleet-client/package.json +1 -1
  179. package/packages/apra-fleet-client/src/client/api.mjs +172 -19
  180. package/packages/apra-fleet-client/src/client/reconnecting-transport.mjs +35 -2
  181. package/packages/apra-fleet-client/src/client/transport.mjs +6 -0
  182. package/packages/apra-fleet-se/apra-pm/agents/backlog-groomer.md +5 -0
  183. package/packages/apra-fleet-se/apra-pm/agents/ci-watcher.md +5 -0
  184. package/packages/apra-fleet-se/apra-pm/agents/deployer.md +20 -2
  185. package/packages/apra-fleet-se/apra-pm/agents/doer.md +38 -2
  186. package/packages/apra-fleet-se/apra-pm/agents/harvester.md +12 -9
  187. package/packages/apra-fleet-se/apra-pm/agents/integ-test-runner.md +5 -0
  188. package/packages/apra-fleet-se/apra-pm/agents/kb-reconciler.md +6 -0
  189. package/packages/apra-fleet-se/apra-pm/agents/plan-reviewer.md +5 -0
  190. package/packages/apra-fleet-se/apra-pm/agents/planner.md +5 -0
  191. package/packages/apra-fleet-se/apra-pm/agents/regression-test-runner.md +5 -0
  192. package/packages/apra-fleet-se/apra-pm/agents/reviewer.md +67 -15
  193. package/packages/apra-fleet-se/apra-pm/agents/schemas/deployer-output.json +5 -0
  194. package/packages/apra-fleet-se/apra-pm/agents/schemas/doer-output.json +78 -2
  195. package/packages/apra-fleet-se/apra-pm/agents/schemas/reviewer-output.json +104 -2
  196. package/packages/apra-fleet-se/apra-pm/skills/pm/cost.md +5 -1
  197. package/packages/apra-fleet-se/apra-pm/skills/pm/index.md +9 -9
  198. package/packages/apra-fleet-se/apra-pm/skills/pm/sprint.md +2 -1
  199. package/packages/apra-fleet-se/bin/cli.mjs +104 -31
  200. package/packages/apra-fleet-se/bin/serve.mjs +46 -8
  201. package/packages/apra-fleet-se/fleet-sprint/abort.mjs +184 -32
  202. package/packages/apra-fleet-se/fleet-sprint/bd-sync-command.mjs +69 -0
  203. package/packages/apra-fleet-se/fleet-sprint/beads-children.mjs +21 -0
  204. package/packages/apra-fleet-se/fleet-sprint/beads-lock-probe.mjs +176 -0
  205. package/packages/apra-fleet-se/fleet-sprint/beads-reachability.mjs +126 -0
  206. package/packages/apra-fleet-se/fleet-sprint/beads-scope.mjs +158 -1
  207. package/packages/apra-fleet-se/fleet-sprint/contracts.mjs +82 -2
  208. package/packages/apra-fleet-se/fleet-sprint/coordination.mjs +23 -6
  209. package/packages/apra-fleet-se/fleet-sprint/decision-notify.mjs +338 -0
  210. package/packages/apra-fleet-se/fleet-sprint/decision-wait.mjs +731 -0
  211. package/packages/apra-fleet-se/fleet-sprint/decisions.mjs +372 -0
  212. package/packages/apra-fleet-se/fleet-sprint/dispatch-role.mjs +44 -11
  213. package/packages/apra-fleet-se/fleet-sprint/docs/README.md +4 -1
  214. package/packages/apra-fleet-se/fleet-sprint/dolt-settle.mjs +9 -3
  215. package/packages/apra-fleet-se/fleet-sprint/dolt-sync.mjs +314 -19
  216. package/packages/apra-fleet-se/fleet-sprint/errors.mjs +72 -4
  217. package/packages/apra-fleet-se/fleet-sprint/git-sync.mjs +7 -1
  218. package/packages/apra-fleet-se/fleet-sprint/git-topology.mjs +112 -1
  219. package/packages/apra-fleet-se/fleet-sprint/guarded-modules.mjs +36 -2
  220. package/packages/apra-fleet-se/fleet-sprint/kb.mjs +736 -101
  221. package/packages/apra-fleet-se/fleet-sprint/member-init-probe.mjs +1 -1
  222. package/packages/apra-fleet-se/fleet-sprint/member-provisioning.mjs +7 -1
  223. package/packages/apra-fleet-se/fleet-sprint/phases/deploy.mjs +49 -2
  224. package/packages/apra-fleet-se/fleet-sprint/phases/develop.mjs +206 -3
  225. package/packages/apra-fleet-se/fleet-sprint/phases/final-review.mjs +61 -3
  226. package/packages/apra-fleet-se/fleet-sprint/phases/harvest.mjs +81 -31
  227. package/packages/apra-fleet-se/fleet-sprint/phases/plan.mjs +7 -3
  228. package/packages/apra-fleet-se/fleet-sprint/phases/publish-pr.mjs +39 -14
  229. package/packages/apra-fleet-se/fleet-sprint/phases/re-review.mjs +17 -1
  230. package/packages/apra-fleet-se/fleet-sprint/phases/review.mjs +18 -3
  231. package/packages/apra-fleet-se/fleet-sprint/pr-body.mjs +14 -1
  232. package/packages/apra-fleet-se/fleet-sprint/prompts.mjs +32 -5
  233. package/packages/apra-fleet-se/fleet-sprint/runner.js +824 -98
  234. package/packages/apra-fleet-se/fleet-sprint/se-os-commands.mjs +4 -2
  235. package/packages/apra-fleet-se/fleet-sprint/se-posix.mjs +54 -1
  236. package/packages/apra-fleet-se/fleet-sprint/se-windows.mjs +29 -2
  237. package/packages/apra-fleet-se/fleet-sprint/set-aside.mjs +288 -0
  238. package/packages/apra-fleet-se/fleet-sprint/skills/fleet-supervisor/SKILL.md +3 -2
  239. package/packages/apra-fleet-se/fleet-sprint/sprint-args.mjs +20 -0
  240. package/packages/apra-fleet-se/fleet-sprint/sprint-report.mjs +21 -0
  241. package/packages/apra-fleet-se/fleet-sprint/sprint-state.mjs +9 -0
  242. package/packages/apra-fleet-se/fleet-sprint/vcs-auth.mjs +605 -32
  243. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/bitbucket.mjs +811 -17
  244. package/packages/apra-fleet-se/fleet-sprint/vcs-providers/index.mjs +89 -1
  245. package/packages/apra-fleet-se/fleet-sprint/viewer-extensions.mjs +225 -2
  246. package/packages/apra-fleet-se/fleet-sprint/worklists.mjs +59 -3
  247. package/packages/apra-fleet-se/src/supervisor/api.mjs +148 -8
  248. package/packages/apra-fleet-se/src/supervisor/dashboard.mjs +6 -3
  249. package/packages/apra-fleet-se/src/supervisor/dolt-mutex.mjs +30 -10
  250. package/packages/apra-fleet-se/src/supervisor/fleet-members.mjs +17 -4
  251. package/packages/apra-fleet-se/src/supervisor/history.mjs +8 -1
  252. package/packages/apra-fleet-se/src/supervisor/id-allocator.mjs +92 -2
  253. package/packages/apra-fleet-se/src/supervisor/proxy.mjs +26 -1
  254. package/packages/apra-fleet-se/src/supervisor/server.mjs +151 -8
  255. package/packages/apra-fleet-se/src/supervisor/spawner.mjs +11 -9
  256. package/packages/apra-fleet-se/src/supervisor/watchdog.mjs +7 -1
  257. package/packages/apra-fleet-workflow/package.json +2 -1
  258. package/packages/apra-fleet-workflow/src/viewer/index.mjs +86 -5
  259. package/packages/apra-fleet-workflow/src/viewer/request-guard.mjs +222 -0
  260. package/packages/apra-fleet-workflow/src/workflow/index.mjs +34 -2
  261. package/plugins/claude-code/fleet-status/.claude-plugin/plugin.json +7 -0
  262. package/plugins/claude-code/fleet-status/hooks/hooks.json +1 -0
  263. package/plugins/claude-code/fleet-status/hooks/register.tsx +906 -0
  264. package/plugins/claude-code/fleet-status/types/index.d.ts +88 -0
  265. package/skills/fleet/auth-bitbucket.md +47 -20
  266. package/skills/fleet/onboarding.md +1 -1
  267. package/skills/fleet/skill-matrix.md +3 -3
  268. package/version.json +1 -1
@@ -14,6 +14,7 @@ import { FLEET_DIR } from '../paths.js';
14
14
  import { resolveProjectSlug } from '../services/knowledge/project-slug.js';
15
15
  import { indexInconsistency, isPidAlive, readGitNexusIndexState } from './code-index-state.js';
16
16
  import { excludeLineFor } from '../services/member-config-io.js';
17
+ import { gitExecutable } from '../os/git-executable.js';
17
18
  // Module-level per-repo state (design D3): in-memory is acceptable -- the
18
19
  // server is long-lived, and a restart just means one extra reindex.
19
20
  const state = new Map();
@@ -148,7 +149,20 @@ export const GITNEXUS_MIN_VERSION = '1.6.5';
148
149
  export const GITNEXUS_PACKAGE_SPEC = `gitnexus@>=${GITNEXUS_MIN_VERSION}`;
149
150
  // -y is npx's own flag (before the package): the analyze child is hidden, so
150
151
  // npx's "Ok to proceed?" install prompt would hang it unseen.
151
- export const GITNEXUS_ANALYZE_ARGS = ['-y', GITNEXUS_PACKAGE_SPEC, 'analyze', '--index-only'];
152
+ //
153
+ // `--force` makes every fleet-initiated analyze a FULL rebuild of the graph
154
+ // DB (parser output is still replayed from gitnexus's parse cache for
155
+ // unchanged files, so it costs roughly 2x an incremental run, not a cold
156
+ // build). gitnexus 1.6.12's incremental writeback -- in place and with
157
+ // GITNEXUS_ATOMIC_INCREMENTAL=1 alike -- overwrites thousands of symbol rows of
158
+ // files it did not change on a large repo (reproduced: one run after a one-line
159
+ // edit left 7774, resp. 9334, blank rows, or 9287 rows duplicating another
160
+ // row's id, in an index a fresh build had left with one row per id). Lookups of those symbols answer "not
161
+ // found", and since every later incremental run keeps unchanged rows as they
162
+ // are, the index never recovers on its own. A full rebuild also skips
163
+ // gitnexus's "Already up to date" shortcut, so code_reindex can always
164
+ // repair a corrupt index at the same commit.
165
+ export const GITNEXUS_ANALYZE_ARGS = ['-y', GITNEXUS_PACKAGE_SPEC, 'analyze', '--index-only', '--force'];
152
166
  /**
153
167
  * An npx argv that is safe under a shell. On Windows spawn() runs through
154
168
  * cmd.exe (shell: true), where an unquoted `>=` is a redirection, so the
@@ -161,7 +175,7 @@ export function npxArgsForShell(args, shell) {
161
175
  const UNKNOWN_INDEX_ONLY = /unknown option\b.*--index-only|--index-only.*unknown option|unrecognized (?:option|argument)\b.*--index-only/i;
162
176
  /** One-line cause + fix reported wherever the too-old failure surfaces. */
163
177
  export const GITNEXUS_TOO_OLD_DETAIL = `the installed gitnexus does not support --index-only (needs >= ${GITNEXUS_MIN_VERSION}): upgrade gitnexus ` +
164
- `(npx -y ${GITNEXUS_PACKAGE_SPEC} analyze --index-only) or clear the npx cache (npm cache clean --force), then rerun code_reindex`;
178
+ `(npx -y ${GITNEXUS_PACKAGE_SPEC} analyze --index-only --force) or clear the npx cache (npm cache clean --force), then rerun code_reindex`;
165
179
  function failureCauseOf(lines) {
166
180
  return lines.some((l) => UNKNOWN_INDEX_ONLY.test(l)) ? 'gitnexus-too-old' : undefined;
167
181
  }
@@ -177,7 +191,7 @@ export const GITNEXUS_REPO_ARTIFACTS = ['.gitnexus/'];
177
191
  */
178
192
  export function ensureLocalGitExcluded(repoPath, relPaths) {
179
193
  try {
180
- const out = execFileSync('git', ['rev-parse', '--git-path', 'info/exclude'], {
194
+ const out = execFileSync(gitExecutable(), ['rev-parse', '--git-path', 'info/exclude'], {
181
195
  cwd: repoPath, encoding: 'utf8', timeout: 5000, stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true,
182
196
  }).trim().split(/\r?\n/)[0]?.trim() ?? '';
183
197
  if (!out)
@@ -234,7 +248,7 @@ export function injectedBlockWarning(files) {
234
248
  '(--index-only never removes it): remove the block between <!-- gitnexus:start --> and <!-- gitnexus:end --> and commit.';
235
249
  }
236
250
  /**
237
- * Synchronously start `npx -y gitnexus analyze --index-only` in `repoPath` (detached off win32), with
251
+ * Synchronously start `npx -y gitnexus analyze --index-only --force` in `repoPath` (detached off win32), with
238
252
  * stdout+stderr going straight to analyze.log (a file descriptor, so the run
239
253
  * outlives this server) and status.json kept current until exit. Never
240
254
  * throws. Does NOT apply config/cooldown -- callers decide whether to start.
@@ -297,9 +311,11 @@ export function spawnAnalyze(repoPath, opts = {}) {
297
311
  }
298
312
  catch { /* the child holds its own copy */ }
299
313
  const startedIso = new Date().toISOString();
314
+ const previousBuildMs = lastBuildDurationMs(dir);
300
315
  const status = {
301
316
  repo: repoPath, pid: child.pid ?? null, started: startedIso, lockHeld: false,
302
317
  lastLine: '', lineCount: 0, phase: 'starting', result: null, exitCode: null,
318
+ ...(previousBuildMs !== null ? { previousBuildMs } : {}),
303
319
  };
304
320
  writeStatus(dir, status);
305
321
  state.set(repoPath, {
@@ -457,6 +473,62 @@ export function isRecordedAnalyzeAlive(repoPath, now = Date.now()) {
457
473
  return false;
458
474
  }
459
475
  }
476
+ export function analyzeProgress(repoPath, now = Date.now()) {
477
+ try {
478
+ const dir = codeIndexDir(repoPath);
479
+ const status = readStatusFile(dir);
480
+ if (!status || status.phase === 'done')
481
+ return null;
482
+ if (typeof status.repo === 'string' && status.repo !== repoPath)
483
+ return null;
484
+ const started = Date.parse(status.started);
485
+ const lines = readLogLines(dir);
486
+ return {
487
+ phase: status.phase,
488
+ elapsed_ms: Number.isFinite(started) ? Math.max(0, now - started) : null,
489
+ last_line: lines.length > 0 ? lines[lines.length - 1] : (status.lastLine ?? ''),
490
+ line_count: Math.max(logLineCount(dir), status.lineCount ?? 0),
491
+ };
492
+ }
493
+ catch {
494
+ return null;
495
+ }
496
+ }
497
+ /** Duration of the last run that built this folder's index, read before a new run overwrites status.json. */
498
+ function lastBuildDurationMs(dir) {
499
+ const status = readStatusFile(dir);
500
+ if (!status)
501
+ return null;
502
+ if (status.phase === 'done' && status.result === 'indexed' && status.finished) {
503
+ const ms = Date.parse(status.finished) - Date.parse(status.started);
504
+ if (Number.isFinite(ms) && ms > 0)
505
+ return ms;
506
+ }
507
+ return typeof status.previousBuildMs === 'number' ? status.previousBuildMs : null;
508
+ }
509
+ const MIN_BUILD_WAIT_MS = 15_000;
510
+ const MAX_BUILD_WAIT_MS = 600_000;
511
+ /**
512
+ * How long the live build of `repo` should still take, from the folder's last
513
+ * finished build (bounded, with a margin); null when nothing is running or no
514
+ * earlier build is recorded.
515
+ */
516
+ export function expectedBuildRemainingMs(repoPath, now = Date.now()) {
517
+ try {
518
+ const status = readStatusFile(codeIndexDir(repoPath));
519
+ if (!status || status.phase === 'done' || typeof status.previousBuildMs !== 'number')
520
+ return null;
521
+ if (typeof status.repo === 'string' && status.repo !== repoPath)
522
+ return null;
523
+ const started = Date.parse(status.started);
524
+ const elapsed = Number.isFinite(started) ? Math.max(0, now - started) : 0;
525
+ const remaining = Math.round(status.previousBuildMs * 1.2) - elapsed;
526
+ return Math.min(MAX_BUILD_WAIT_MS, Math.max(MIN_BUILD_WAIT_MS, remaining));
527
+ }
528
+ catch {
529
+ return null;
530
+ }
531
+ }
460
532
  // ---------------------------------------------------------------------------
461
533
  // code_reindex / code_status
462
534
  // ---------------------------------------------------------------------------
@@ -93,7 +93,7 @@ export interface CodeSelf {
93
93
  /** Resolve the calling session's own code-intelligence folder. Throws KbSelfError. */
94
94
  export declare function resolveCodeSelf(): CodeSelf;
95
95
  /** Appended to every code_* tool description so callers know there is no repo argument. */
96
- export declare const CODE_SELF_NOTE = " Scope: always the calling session's own repo -- a member session uses its registered work folder, any other session the fleet server's working folder; there is no repo/path scope argument. Fails with E-SELF-NO-WORKFOLDER or E-SELF-NOT-A-REPO when that folder is missing or is not a git repository, E-CODE-INDEX-NOT-READY when it has no usable code index yet (a missing or interrupted index gets a build requested automatically -- retry shortly) or the index is still building, and E-CODE-INTEL-DISABLED when code intelligence is off (each with a one-line remediation).";
96
+ export declare const CODE_SELF_NOTE = " Scope: always the calling session's own repo -- a member session uses its registered work folder; any other session uses the first MCP client root (roots/list) inside a git repository with an origin remote, as that repository's top level -- the same repository its kb_* tools use -- or the fleet server's working folder when the client offers no roots. Extension for code tools only: when roots are offered and none has an origin remote, the first offered git repository is used (kb_* tools then fail with E-SELF-NO-REMOTE). There is no repo/path scope argument. Fails with E-SELF-NO-WORKFOLDER or E-SELF-NOT-A-REPO when that folder is missing or is not a git repository, E-CODE-INDEX-NOT-READY when it has no usable code index yet (a missing or interrupted index gets a build requested automatically -- retry shortly) or the index is still building (that error's text and structuredContent carry retry_after_ms -- wait that long once, retry once, then fall back; never poll code_status in a loop -- plus retry_will_help and, while an analyze runs, its progress), and E-CODE-INTEL-DISABLED when code intelligence is off (each with a one-line remediation).";
97
97
  /**
98
98
  * Stamp the commit an answer was served from onto a code_* result. Providers
99
99
  * with no commit notion (codebase-memory, none) report null rather than omit
@@ -62,7 +62,7 @@ export function resolveCodeSelf() {
62
62
  return { repo: self.folder, memberId: self.memberId };
63
63
  }
64
64
  /** Appended to every code_* tool description so callers know there is no repo argument. */
65
- export const CODE_SELF_NOTE = ' Scope: always the calling session\'s own repo -- a member session uses its registered work folder, any other session the fleet server\'s working folder; there is no repo/path scope argument. Fails with E-SELF-NO-WORKFOLDER or E-SELF-NOT-A-REPO when that folder is missing or is not a git repository, E-CODE-INDEX-NOT-READY when it has no usable code index yet (a missing or interrupted index gets a build requested automatically -- retry shortly) or the index is still building, and E-CODE-INTEL-DISABLED when code intelligence is off (each with a one-line remediation).';
65
+ export const CODE_SELF_NOTE = ' Scope: always the calling session\'s own repo -- a member session uses its registered work folder; any other session uses the first MCP client root (roots/list) inside a git repository with an origin remote, as that repository\'s top level -- the same repository its kb_* tools use -- or the fleet server\'s working folder when the client offers no roots. Extension for code tools only: when roots are offered and none has an origin remote, the first offered git repository is used (kb_* tools then fail with E-SELF-NO-REMOTE). There is no repo/path scope argument. Fails with E-SELF-NO-WORKFOLDER or E-SELF-NOT-A-REPO when that folder is missing or is not a git repository, E-CODE-INDEX-NOT-READY when it has no usable code index yet (a missing or interrupted index gets a build requested automatically -- retry shortly) or the index is still building (that error\'s text and structuredContent carry retry_after_ms -- wait that long once, retry once, then fall back; never poll code_status in a loop -- plus retry_will_help and, while an analyze runs, its progress), and E-CODE-INTEL-DISABLED when code intelligence is off (each with a one-line remediation).';
66
66
  // ---------------------------------------------------------------------------
67
67
  // Handler functions -- resolve (self) (unless the caller already resolved it),
68
68
  // resolve the per-member provider, and delegate with the resolved folder as
@@ -5,7 +5,7 @@ import { getOsCommands } from '../os/index.js';
5
5
  import { getAgentOS, getAgentShell, isPosixShell, touchAgent } from '../utils/agent-helpers.js';
6
6
  import { memberIdentifier, resolveMember } from '../utils/resolve-member.js';
7
7
  import { stageAuthEnv, removeMemberSecretFile, SecretDeliveryError } from '../services/member-secret-env.js';
8
- import { writeStatusline } from '../services/statusline.js';
8
+ import { markBusy } from '../services/member-busy.js';
9
9
  import { ensureCloudReady } from '../services/cloud/lifecycle.js';
10
10
  import { generateTaskWrapper, generateTaskWrapperWindows } from '../services/cloud/task-wrapper.js';
11
11
  import { escapeShellArg, escapePowerShellArg, escapeWindowsArg } from '../utils/shell-escape.js';
@@ -305,12 +305,14 @@ export async function executeCommand(input, extra) {
305
305
  `chmod +x ~/.fleet-tasks/${taskId}/run.sh && ` +
306
306
  `nohup bash ~/.fleet-tasks/${taskId}/run.sh > /dev/null 2>&1 & echo $!`);
307
307
  }
308
- writeStatusline(new Map([[agent.id, 'busy']]));
308
+ // Busy only while launching: the detached task's own progress is
309
+ // monitor_task's to report, not the statusline's.
310
+ const releaseBusy = markBusy(agent.id);
309
311
  try {
310
312
  const timeoutMs = (input.timeout_s ?? 120) * 1000;
311
313
  const launchResult = await strategy.execCommand(launchCmd, timeoutMs, undefined, onPidCaptured);
312
314
  touchAgent(agent.id);
313
- writeStatusline();
315
+ releaseBusy();
314
316
  // Redact credential values from any output returned by the launch command (H2)
315
317
  const launchOutput = credentials.length > 0
316
318
  ? redactOutput(launchResult.stdout + launchResult.stderr, credentials)
@@ -321,9 +323,12 @@ export async function executeCommand(input, extra) {
321
323
  }
322
324
  catch (err) {
323
325
  const isOffline = agent.agentType !== 'local' && !!(err.message && /ssh|network|econnrefused|ehostunreach|connection timed out/i.test(err.message));
324
- writeStatusline(new Map([[agent.id, isOffline ? 'offline' : 'idle']]));
326
+ releaseBusy(isOffline ? 'offline' : 'idle');
325
327
  return execFailureResult(`Failed to launch task on "${agent.friendlyName}": ${err.message}`, classifyExecFailure(err), err.message);
326
328
  }
329
+ finally {
330
+ releaseBusy();
331
+ }
327
332
  }
328
333
  // -- Regular (synchronous) command path --
329
334
  // wrapPidCapture lets a timed-out ssh.ts/strategy.ts execCommand recover a
@@ -345,8 +350,8 @@ export async function executeCommand(input, extra) {
345
350
  ? 'eval ' + escapeShellArg(resolvedCommand)
346
351
  : resolvedCommand;
347
352
  const wrapped = cmds.wrapPidCapture(cmds.wrapInWorkFolder(folder, payload));
348
- // Mark agent as busy in statusline
349
- writeStatusline(new Map([[agent.id, 'busy']]));
353
+ // Mark agent as busy in statusline; released on every exit path below.
354
+ const releaseBusy = markBusy(agent.id);
350
355
  // Stored auth env vars travel in an owner-only file the command loads and
351
356
  // deletes -- never as inline values on the member's command line.
352
357
  let stagedEnvPath = null;
@@ -386,7 +391,7 @@ export async function executeCommand(input, extra) {
386
391
  const output = credentials.length > 0 ? redactOutput(rawOutput, credentials) : rawOutput;
387
392
  const redactedStdout = credentials.length > 0 ? redactOutput(result.stdout ?? '', credentials) : (result.stdout ?? '');
388
393
  const redactedStderr = credentials.length > 0 ? redactOutput(result.stderr ?? '', credentials) : (result.stderr ?? '');
389
- writeStatusline();
394
+ releaseBusy();
390
395
  // Log command output under a dedicated tag so `watch` can surface it (the
391
396
  // fleet log is watch's source; short-command stdout is otherwise not
392
397
  // persisted anywhere). Capped to protect the log from huge outputs.
@@ -411,11 +416,12 @@ export async function executeCommand(input, extra) {
411
416
  }
412
417
  catch (err) {
413
418
  const isOffline = agent.agentType !== 'local' && !!(err.message && /ssh|network|econnrefused|ehostunreach|connection timed out/i.test(err.message));
414
- writeStatusline(new Map([[agent.id, isOffline ? 'offline' : 'idle']]));
419
+ releaseBusy(isOffline ? 'offline' : 'idle');
415
420
  scope.abort(err.message);
416
421
  return execFailureResult(`Failed to execute command on "${agent.friendlyName}": ${err.message}`, classifyExecFailure(err), err.message);
417
422
  }
418
423
  finally {
424
+ releaseBusy();
419
425
  // The prefix deletes the file once loaded; a failed/aborted run may not
420
426
  // have reached it.
421
427
  if (stagedEnvPath && !stagedEnvConsumed)
@@ -2125,8 +2125,9 @@ session: ${parsed.sessionId}`;
2125
2125
  .then((raw) => {
2126
2126
  try {
2127
2127
  const r = JSON.parse(raw);
2128
- if (r.entries_captured || r.entries_updated || r.entries_skipped || r.entries_rejected) {
2129
- logLine('kb_harvest', `auto-harvest: captured=${r.entries_captured} updated=${r.entries_updated} skipped=${r.entries_skipped} rejected=${r.entries_rejected}`);
2128
+ const failed = r.entries_failed ?? 0;
2129
+ if (r.entries_captured || r.entries_updated || r.entries_skipped || r.entries_rejected || failed) {
2130
+ logLine('kb_harvest', `auto-harvest: captured=${r.entries_captured} updated=${r.entries_updated} skipped=${r.entries_skipped} rejected=${r.entries_rejected} failed=${failed}`);
2130
2131
  }
2131
2132
  }
2132
2133
  catch {
@@ -2209,6 +2210,9 @@ session: ${parsed.sessionId}`;
2209
2210
  if (claimGuardActive) {
2210
2211
  inFlightAgents.delete(agent.id);
2211
2212
  getStallDetector().remove(agent.id);
2213
+ // The stall detector writes busy(mm:ss) on every tick once its entry
2214
+ // exists; removing the entry alone would leave that busy persisted.
2215
+ writeStatusline(new Map([[agent.id, 'idle']]));
2212
2216
  }
2213
2217
  throw err;
2214
2218
  }
@@ -0,0 +1,21 @@
1
+ import { z } from 'zod';
2
+ export declare const fleetSnapshotSchema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
3
+ export type SnapshotStatus = 'busy' | 'idle' | 'offline' | 'unknown';
4
+ export interface SnapshotMember {
5
+ id: string;
6
+ name: string;
7
+ icon: string;
8
+ category: string | null;
9
+ status: SnapshotStatus;
10
+ /** While busy: seconds since the member's task last showed activity (the
11
+ * stall detector's clock -- the same figure as statusline's busy(mm:ss)). */
12
+ quietForS?: number;
13
+ reservedBy?: string;
14
+ }
15
+ export interface FleetSnapshot {
16
+ version: string;
17
+ members: SnapshotMember[];
18
+ }
19
+ export declare function buildFleetSnapshot(now?: number): FleetSnapshot;
20
+ export declare function fleetSnapshot(): Promise<string>;
21
+ //# sourceMappingURL=fleet-snapshot.d.ts.map
@@ -0,0 +1,78 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { z } from 'zod';
4
+ import { FLEET_DIR } from '../paths.js';
5
+ import { getAllAgents } from '../services/registry.js';
6
+ import { DEFAULT_ICON } from '../services/icons.js';
7
+ import { getStallDetector } from '../services/stall/index.js';
8
+ import { isOrphanedBusy } from '../services/statusline.js';
9
+ import { serverVersion } from '../version.js';
10
+ // fleet_snapshot: the cheap, read-only fleet view the Claude Code fleet-status
11
+ // mod polls (plugins/claude-code/fleet-status). Built only from what is already on
12
+ // this host -- the registry, the last-known per-member states the statusline
13
+ // writer persists, and this process's stall detector. It never probes a
14
+ // member over SSH and never writes anything, so polling it every few seconds
15
+ // costs a file read. fleet_status stays the live (probing) view.
16
+ export const fleetSnapshotSchema = z.object({});
17
+ const STATE_PATH = path.join(FLEET_DIR, 'statusline-state.json');
18
+ function readStates() {
19
+ try {
20
+ return JSON.parse(fs.readFileSync(STATE_PATH, 'utf-8'));
21
+ }
22
+ catch {
23
+ return {};
24
+ }
25
+ }
26
+ /** "busy(02:14)" -> busy; anything unrecognised -> unknown. */
27
+ function normalizeStatus(raw) {
28
+ const base = (raw ?? 'idle').replace(/\(.*\)$/, '').trim().toLowerCase();
29
+ if (base === 'busy' || base === 'idle' || base === 'offline' || base === 'unknown')
30
+ return base;
31
+ return 'unknown';
32
+ }
33
+ /** "busy(02:14)" -> 134, "busy(1:02:05)" -> 3725; undefined when absent. */
34
+ function parseClock(raw) {
35
+ const m = /\((\d+(?::\d{1,2}){1,2})\)$/.exec(raw ?? '');
36
+ if (!m)
37
+ return undefined;
38
+ return m[1].split(':').reduce((acc, part) => acc * 60 + Number(part), 0);
39
+ }
40
+ export function buildFleetSnapshot(now = Date.now()) {
41
+ const states = readStates();
42
+ const stall = getStallDetector();
43
+ const members = getAllAgents().map((a) => {
44
+ let status = normalizeStatus(states[a.id]);
45
+ const entry = stall.getEntry(a.id);
46
+ if (entry?.stallReported)
47
+ status = 'unknown';
48
+ // A persisted busy whose writing server process is dead can never be
49
+ // cleared by that process -- report it as idle, not busy forever.
50
+ if (status === 'busy' && !entry && isOrphanedBusy(a.id))
51
+ status = 'idle';
52
+ const m = {
53
+ id: a.id,
54
+ name: a.friendlyName,
55
+ icon: a.icon ?? DEFAULT_ICON,
56
+ category: a.category?.trim() || null,
57
+ status,
58
+ };
59
+ if (status === 'busy' && entry && !entry.provisional) {
60
+ m.quietForS = Math.max(0, Math.round((now - entry.lastActivityAt) / 1000));
61
+ }
62
+ else if (status === 'busy') {
63
+ // No live entry in this process (the task runs under another server
64
+ // process): fall back to the persisted busy(mm:ss) label.
65
+ const q = parseClock(states[a.id]);
66
+ if (q !== undefined)
67
+ m.quietForS = q;
68
+ }
69
+ if (a.reservedBy)
70
+ m.reservedBy = a.reservedBy;
71
+ return m;
72
+ });
73
+ return { version: serverVersion, members };
74
+ }
75
+ export async function fleetSnapshot() {
76
+ return JSON.stringify(buildFleetSnapshot());
77
+ }
78
+ //# sourceMappingURL=fleet-snapshot.js.map
@@ -5,22 +5,25 @@ export declare const kbBibleCommitSchema: z.ZodObject<{
5
5
  repo: z.ZodOptional<z.ZodUnknown>;
6
6
  repo_remote_url: z.ZodOptional<z.ZodUnknown>;
7
7
  ids: z.ZodArray<z.ZodString, "many">;
8
+ demoted_ids: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
8
9
  baseBranch: z.ZodString;
9
10
  baseCommit: z.ZodString;
10
11
  }, "strip", z.ZodTypeAny, {
12
+ ids: string[];
11
13
  baseBranch: string;
12
14
  baseCommit: string;
13
- ids: string[];
14
15
  repo?: unknown;
15
16
  repo_path?: unknown;
16
17
  repo_remote_url?: unknown;
18
+ demoted_ids?: string[] | undefined;
17
19
  }, {
20
+ ids: string[];
18
21
  baseBranch: string;
19
22
  baseCommit: string;
20
- ids: string[];
21
23
  repo?: unknown;
22
24
  repo_path?: unknown;
23
25
  repo_remote_url?: unknown;
26
+ demoted_ids?: string[] | undefined;
24
27
  }>;
25
28
  export type KbBibleCommitInput = z.infer<typeof kbBibleCommitSchema>;
26
29
  /**
@@ -29,9 +32,11 @@ export type KbBibleCommitInput = z.infer<typeof kbBibleCommitSchema>;
29
32
  * - no_source_files: CONFIRMED but cites no source file, so it has no basis
30
33
  * that could ever be checked (retrying cannot change this);
31
34
  * - basis_mismatch: CONFIRMED and cites files, but its recorded basis does not
32
- * match those files at HEAD (can clear once the files or the basis agree).
35
+ * match those files at HEAD (can clear once the files or the basis agree);
36
+ * - not_demoted_or_unknown: named in demoted_ids, but the local entry is
37
+ * unknown, was never demoted, or is CONFIRMED again.
33
38
  */
34
- export type KbBibleCommitSkipReason = 'not_confirmed_or_unknown' | 'no_source_files' | 'basis_mismatch';
39
+ export type KbBibleCommitSkipReason = 'not_confirmed_or_unknown' | 'no_source_files' | 'basis_mismatch' | 'not_demoted_or_unknown';
35
40
  export interface KbBibleCommitSkip {
36
41
  id: string;
37
42
  reason: KbBibleCommitSkipReason;
@@ -45,21 +50,30 @@ export interface KbBibleCommitRemoval {
45
50
  export interface KbBibleCommitResult {
46
51
  path: string;
47
52
  merged: string[];
53
+ /** Ids admitted from demoted_ids: removed from entries, tombstoned. */
54
+ demoted: string[];
48
55
  skipped: KbBibleCommitSkip[];
49
56
  removed: KbBibleCommitRemoval[];
57
+ /** ENTRIES only -- a tombstone is not an entry. */
50
58
  entry_count: number;
51
59
  /** How many existing bible entries gained source_file_hashes (legacy backfill). */
52
60
  backfilled: number;
53
61
  committed: boolean;
62
+ /** True when the call was skipped because the project KB is not SQLite-backed (http). */
63
+ bible_skipped?: true;
64
+ /** Why the call was skipped; present only with bible_skipped. */
65
+ reason?: string;
54
66
  }
67
+ /** Reason reported when kb_bible_commit is skipped under the http KB provider. */
68
+ export declare const KB_BIBLE_COMMIT_HTTP_SKIP_REASON = "bible commit is not supported over the http KB provider";
55
69
  export declare function kbBibleCommit(input: KbBibleCommitInput, anchor?: KbAnchor): Promise<string>;
56
70
  /**
57
- * The bible commit message. The subject counts merged and removed entries;
58
- * when entries were removed, the body lists each one as '- <id> (<reason>)'.
59
- * With no removals and no backfill the message is the single pre-existing
60
- * subject line. A legacy backfill (existing entries that gained
61
- * source_file_hashes) adds a body line 'Backfilled source_file_hashes on <n>
62
- * existing entries.'; a backfill-only commit names the count in its own subject.
71
+ * The bible commit message. The subject counts merged, removed and demoted
72
+ * entries; when entries were removed, the body lists each one as
73
+ * '- <id> (<reason>)'. With no removals and no backfill the message is the
74
+ * single pre-existing subject line. A legacy backfill (existing entries that
75
+ * gained source_file_hashes) adds a body line 'Backfilled source_file_hashes on
76
+ * <n> existing entries.'; a backfill-only commit names the count in its own subject.
63
77
  */
64
- export declare function bibleCommitMessage(mergedCount: number, removed: KbBibleCommitRemoval[], total: number, backfilled?: number): string;
78
+ export declare function bibleCommitMessage(mergedCount: number, removed: KbBibleCommitRemoval[], total: number, backfilled?: number, demotedCount?: number): string;
65
79
  //# sourceMappingURL=kb-bible-commit.d.ts.map