@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
@@ -1,19 +1,104 @@
1
1
  /**
2
- * Bitbucket VCS provider — deploys API token credentials via git credential helper.
2
+ * Bitbucket VCS provider -- deploys API token credentials via git credential helper.
3
+ *
4
+ * Auth model (owner decision 2026-11-02): a Bitbucket API token authenticates
5
+ * git over HTTPS with the FIXED username TOKEN_USERNAME, and the REST API with
6
+ * `Authorization: Bearer <token>`. The account email is never used for auth:
7
+ * Bitbucket accepts an email only for REST basic auth, and writing it as the
8
+ * git username (the 0.4.4 behaviour) made every git push/pull fail while the
9
+ * old unauthenticated REST probe still reported success.
3
10
  */
11
+ import { getOsCommands, GIT_LS_REMOTE_OK_MARKER } from '../../os/index.js';
12
+ import { getAgentOS, getAgentShell } from '../../utils/agent-helpers.js';
13
+ import { knownRepoRemoteUrl } from '../member-remote-url.js';
4
14
  const HOST = 'bitbucket.org';
15
+ /** The git username Bitbucket requires next to an API token. A constant, not
16
+ * a parameter: no caller can supply a username (and so never an email). */
17
+ export const BITBUCKET_TOKEN_USERNAME = 'x-bitbucket-api-token-auth';
18
+ /** bitbucket.org and its SSH hosts -- kept in step with
19
+ * src/utils/vcs-provider-detect.ts's BITBUCKET_HOST_RE. */
20
+ const BITBUCKET_HOST_RE = /^(?:www\.|altssh\.|ssh\.)?bitbucket\.org$/i;
21
+ /** A workspace or repository slug. Restricting the alphabet keeps every
22
+ * value interpolated into a member command free of shell metacharacters. */
23
+ const SLUG_RE = /^[A-Za-z0-9._-]+$/;
24
+ /**
25
+ * Parse a Bitbucket Cloud git remote (https, ssh:// or scp-like) into its
26
+ * { workspace, repo } slugs. NEVER throws; null for anything that is not a
27
+ * bitbucket.org two-segment repo path with safe slugs. Any user:password in
28
+ * an https remote is discarded, never returned.
29
+ */
30
+ export function parseBitbucketRemote(remoteUrl) {
31
+ if (typeof remoteUrl !== 'string')
32
+ return null;
33
+ const url = remoteUrl.trim();
34
+ if (!url)
35
+ return null;
36
+ let host;
37
+ let path;
38
+ if (/^[a-z][a-z0-9+.-]*:\/\//i.test(url)) {
39
+ let parsed;
40
+ try {
41
+ parsed = new URL(url);
42
+ }
43
+ catch {
44
+ return null;
45
+ }
46
+ host = parsed.hostname.toLowerCase();
47
+ path = parsed.pathname;
48
+ }
49
+ else {
50
+ const scp = /^(?:[^@\s/]+@)?([^:\s/]+):(.*)$/.exec(url);
51
+ if (!scp)
52
+ return null;
53
+ host = scp[1].toLowerCase();
54
+ path = scp[2];
55
+ }
56
+ if (!BITBUCKET_HOST_RE.test(host))
57
+ return null;
58
+ const parts = path.split('/').filter((p) => p !== '');
59
+ if (parts.length !== 2)
60
+ return null;
61
+ const workspace = parts[0];
62
+ const repo = parts[1].replace(/\.git$/i, '');
63
+ if (!SLUG_RE.test(workspace) || !SLUG_RE.test(repo))
64
+ return null;
65
+ return { workspace, repo };
66
+ }
67
+ /** git's own messages for a credential that is missing or rejected. */
68
+ const GIT_AUTH_FAILURE_RE = /authentication failed|could not read (?:username|password)|terminal prompts disabled|invalid credentials|\b40[13]\b|access denied/i;
69
+ /** Every way a member's origin can be learned: its registration record
70
+ * first (no round-trip), else the work folder's own `origin` remote. */
71
+ async function resolveOriginRef(agent, exec) {
72
+ const known = parseBitbucketRemote(knownRepoRemoteUrl(agent));
73
+ if (known)
74
+ return known;
75
+ if (!agent.workFolder)
76
+ return null;
77
+ const cmds = getOsCommands(getAgentOS(agent), getAgentShell(agent));
78
+ try {
79
+ const out = await exec(cmds.gitRemoteOrigin(agent.workFolder));
80
+ const line = out.split(/\r?\n/).map((l) => l.trim()).find((l) => l !== '');
81
+ return parseBitbucketRemote(line);
82
+ }
83
+ catch {
84
+ return null;
85
+ }
86
+ }
5
87
  export const bitbucketProvider = {
6
- // apra-fleet-5co8.3.1: moved VERBATIM out of the provider switch in
7
- // src/tools/provision-vcs-auth.ts -- same three required fields, same error
8
- // text, same returned shape. No auth-mode axis (one API-token form only).
88
+ // Required: api_token and workspace. email is OPTIONAL and ignored for auth;
89
+ // it is carried through only so deploy() can keep it as metadata.
9
90
  buildCredentials(input) {
10
- if (!input.email || !input.api_token || !input.workspace) {
11
- return 'Bitbucket requires "email", "api_token", and "workspace" fields.';
91
+ if (!input.api_token || !input.workspace) {
92
+ return 'Bitbucket requires "api_token" and "workspace" fields.';
12
93
  }
13
- return { email: input.email, api_token: input.api_token, workspace: input.workspace };
94
+ const creds = { api_token: input.api_token, workspace: input.workspace };
95
+ if (input.email)
96
+ creds.email = input.email;
97
+ return creds;
98
+ },
99
+ validateNonSecretFields(input) {
100
+ return input.workspace ? null : 'Bitbucket requires the "workspace" field.';
14
101
  },
15
- // apra-fleet-5co8.3.1: the former
16
- // `if (provider === 'bitbucket' && api_token === undefined)` block, verbatim.
17
102
  missingCredential: {
18
103
  field: 'api_token',
19
104
  isMissing: (input) => input.api_token === undefined,
@@ -21,27 +106,88 @@ export const bitbucketProvider = {
21
106
  },
22
107
  async deploy(_agent, cmds, exec, credentials, label, scopeUrl) {
23
108
  const creds = credentials;
24
- await exec(cmds.gitCredentialHelperWrite(HOST, creds.email, creds.api_token, label, scopeUrl));
109
+ // Always the fixed token username. A member provisioned by 0.4.4 carries
110
+ // username=<email> in this same helper file; the write below replaces the
111
+ // whole file, so a re-provision upgrades it, and nothing reads the old line.
112
+ await exec(cmds.gitCredentialHelperWrite(HOST, BITBUCKET_TOKEN_USERNAME, creds.api_token, label, scopeUrl));
25
113
  return {
26
114
  success: true,
27
115
  message: 'Bitbucket credentials deployed',
28
- metadata: { workspace: creds.workspace, email: creds.email },
116
+ metadata: {
117
+ workspace: creds.workspace,
118
+ ...(creds.email ? { email: creds.email } : {}),
119
+ },
29
120
  };
30
121
  },
31
122
  async revoke(_agent, cmds, exec, label, scopeUrl) {
32
123
  await exec(cmds.gitCredentialHelperRemove(HOST, label, scopeUrl));
33
124
  return { success: true, message: 'Bitbucket credentials revoked' };
34
125
  },
35
- async testConnectivity(_agent, exec) {
36
- // We need the workspace from the credentials, but testConnectivity only gets the agent.
37
- // Use a generic Bitbucket API check — the user endpoint works with any valid token.
126
+ // Two channels, both required for `verified`:
127
+ // 1. REST: authenticated GET /2.0/repositories/<workspace>/<repo> with
128
+ // Authorization: Bearer <token> -- a 401/403 is rest_unauthorized,
129
+ // anything else non-2xx (or no answer) is rest_failed.
130
+ // 2. git: ls-remote against the member's origin (as its https form, so the
131
+ // just-deployed helper is what authenticates) with prompts disabled --
132
+ // git_auth_failed for a rejected/missing credential, git_failed else.
133
+ // Commands are built for the member's own OS/shell. The token only ever
134
+ // lives in the executed command; no message or reason carries it.
135
+ async testConnectivity(agent, exec, _scopeUrl, credentials) {
136
+ const creds = credentials;
137
+ if (!creds?.api_token || !creds.workspace || !SLUG_RE.test(creds.workspace)) {
138
+ return {
139
+ success: true,
140
+ skipped: true,
141
+ message: 'Skipped (no Bitbucket API token and valid workspace to verify with)',
142
+ };
143
+ }
144
+ const origin = await resolveOriginRef(agent, exec);
145
+ if (!origin) {
146
+ return {
147
+ success: true,
148
+ skipped: true,
149
+ message: 'Skipped (no Bitbucket origin remote known for this member)',
150
+ };
151
+ }
152
+ const cmds = getOsCommands(getAgentOS(agent), getAgentShell(agent));
153
+ const target = `${creds.workspace}/${origin.repo}`;
154
+ const restUrl = `https://api.${HOST}/2.0/repositories/${creds.workspace}/${origin.repo}`;
155
+ let status = '';
38
156
  try {
39
- await exec('curl -sf https://api.bitbucket.org/2.0/user');
40
- return { success: true, message: 'Bitbucket API connectivity verified' };
157
+ const out = await exec(cmds.httpGetStatusWithBearer(restUrl, creds.api_token));
158
+ status = out.trim().split(/\s+/).pop() ?? '';
41
159
  }
42
160
  catch {
43
- return { success: false, message: 'Bitbucket API connectivity check failed' };
161
+ status = '';
162
+ }
163
+ if (status === '401' || status === '403') {
164
+ return fail('rest_unauthorized', `REST GET repositories/${target} was rejected (HTTP ${status})`);
165
+ }
166
+ if (!/^2\d\d$/.test(status)) {
167
+ const why = /^\d{3}$/.test(status) ? `HTTP ${status}` : 'no HTTP response';
168
+ return fail('rest_failed', `REST GET repositories/${target} failed (${why})`);
169
+ }
170
+ const gitUrl = `https://${HOST}/${origin.workspace}/${origin.repo}.git`;
171
+ try {
172
+ const out = await exec(cmds.gitLsRemoteNonInteractive(gitUrl));
173
+ if (!out.includes(GIT_LS_REMOTE_OK_MARKER)) {
174
+ return fail('git_failed', `git ls-remote ${gitUrl} did not complete`);
175
+ }
44
176
  }
177
+ catch (err) {
178
+ const text = err instanceof Error ? err.message : String(err);
179
+ return GIT_AUTH_FAILURE_RE.test(text)
180
+ ? fail('git_auth_failed', `git ls-remote ${gitUrl} was refused (authentication failed)`)
181
+ : fail('git_failed', `git ls-remote ${gitUrl} failed`);
182
+ }
183
+ return {
184
+ success: true,
185
+ reason: 'ok',
186
+ message: `Bitbucket verified: REST repositories/${target} and git ls-remote ${gitUrl} succeeded`,
187
+ };
45
188
  },
46
189
  };
190
+ function fail(reason, detail) {
191
+ return { success: false, reason, message: `Bitbucket verification failed: ${reason} -- ${detail}` };
192
+ }
47
193
  //# sourceMappingURL=bitbucket.js.map
@@ -18,7 +18,10 @@ export interface GitHubPatCredentials {
18
18
  }
19
19
  export type GitHubCredentials = GitHubAppCredentials | GitHubPatCredentials;
20
20
  export interface BitbucketCredentials {
21
- email: string;
21
+ /** OPTIONAL account email. Never used for auth (git or REST) -- kept only
22
+ * as deploy metadata when the caller supplied it. Git authenticates with
23
+ * the fixed token username (see src/services/vcs/bitbucket.ts). */
24
+ email?: string;
22
25
  api_token: string;
23
26
  workspace: string;
24
27
  }
@@ -64,6 +67,13 @@ export interface VcsDeployResult {
64
67
  * result that actually ran the check (success or failure).
65
68
  */
66
69
  skipped?: boolean;
70
+ /**
71
+ * OPTIONAL machine-readable cause a testConnectivity() result carries
72
+ * when it names which verification channel failed (e.g. Bitbucket's
73
+ * 'rest_unauthorized', 'rest_failed', 'git_auth_failed', 'git_failed'),
74
+ * or 'ok' when every channel passed. Never carries credential material.
75
+ */
76
+ reason?: string;
67
77
  }
68
78
  /**
69
79
  * The provider-agnostic view of a provision_vcs_auth payload that credential
@@ -119,6 +129,16 @@ export interface VcsProviderService {
119
129
  * the tool keeps its own switch for a provider that has not implemented it.
120
130
  */
121
131
  buildCredentials?(input: VcsCredentialInput): unknown | string;
132
+ /**
133
+ * Check every REQUIRED NON-secret field (e.g. Bitbucket's workspace, Azure
134
+ * DevOps' org_url) and return an error string naming the missing/invalid
135
+ * field, or null when they are all present. provision_vcs_auth runs this
136
+ * BEFORE any out-of-band credential collection, so an operator is never
137
+ * prompted for a secret the call would then reject for another reason.
138
+ * Pure, like buildCredentials. OPTIONAL: a provider with no required
139
+ * non-secret field (GitHub) omits it.
140
+ */
141
+ validateNonSecretFields?(input: VcsCredentialInput): string | null;
122
142
  /**
123
143
  * How this provider's credential is collected when the payload omits it.
124
144
  * OPTIONAL: a provider whose credential is always derived server-side (a
@@ -135,8 +155,11 @@ export interface VcsProviderService {
135
155
  * deploy/revoke -- optional because most providers derive what they need
136
156
  * from `agent` alone; Azure DevOps uses it as a repo-derivation fallback
137
157
  * when `agent.gitRepos` does not already carry a usable clone URL.
158
+ * `credentials` is the same object deploy() just received, for a provider
159
+ * whose check needs an authenticated REST call (Bitbucket's Bearer GET);
160
+ * an implementation must never echo it into `message` or `reason`.
138
161
  */
139
- testConnectivity(agent: Agent, exec: (cmd: string) => Promise<string>, scopeUrl?: string): Promise<VcsDeployResult>;
162
+ testConnectivity(agent: Agent, exec: (cmd: string) => Promise<string>, scopeUrl?: string, credentials?: unknown): Promise<VcsDeployResult>;
140
163
  }
141
164
  /** Fields needed to build a "raise a PR" REST call. */
142
165
  export interface VcsCreatePrRequest {
@@ -1,9 +1,10 @@
1
1
  import { execFileSync } from 'node:child_process';
2
2
  import path from 'node:path';
3
+ import { gitExecutable } from '../../os/git-executable.js';
3
4
  /** Run a git command in a folder, returning trimmed stdout or null on any error. */
4
5
  function git(folder, args) {
5
6
  try {
6
- const out = execFileSync('git', ['-C', folder, ...args], {
7
+ const out = execFileSync(gitExecutable(), ['-C', folder, ...args], {
7
8
  encoding: 'utf-8',
8
9
  timeout: 5000,
9
10
  stdio: ['ignore', 'pipe', 'ignore'],
@@ -111,7 +111,11 @@ At sprint close, after the harvester runs:
111
111
  2. **Build summary**: run `buildSprintSummary(analysis, quote, calibration, opts)`
112
112
  where `opts = { branch, goal, goalMet, cycleCount, tasksCompleted, tasksOpen,
113
113
  startedAt }`. Write the returned `summaryText` to
114
- `sprint-logs/<branch>-<startedAt>.analysis.md` and commit it.
114
+ `sprint-logs/<branch>-<startedAt>.analysis.md`. Do NOT `git add` or commit it: it is a
115
+ local record. Before writing it, make sure the line `sprint-logs/*.analysis.md` is in
116
+ the repo's local git exclude file (the path `git rev-parse --git-path info/exclude`
117
+ prints; add the line only if it is not already there) so no later `git add -A` or
118
+ `git add sprint-logs/` stages it.
115
119
  3. **Update calibration**: run `computeUpdatedCalibration(calibration, analysis,
116
120
  startedAt, taskAssignments, logEntries)` and write the result back to
117
121
  `sprint-logs/calibration.json`. Commit it. This blends the actual token counts
@@ -11,12 +11,14 @@ code_graph, code_impact, code_query, and code_context tools.
11
11
  the repo path.
12
12
  3. Run via `execute_command` (wrap in background Agent per fleet rules):
13
13
  ```
14
- npx gitnexus analyze --index-only --embeddings
14
+ npx gitnexus analyze --index-only --force --embeddings
15
15
  ```
16
16
  - `run_from`: project repo root
17
- - `timeout_s`: 300 (indexing large repos can take a minute)
17
+ - `timeout_s`: 900 (a full build of a large repo can take several minutes)
18
18
  - `--index-only` keeps the repo work tree clean: without it gitnexus
19
19
  writes an AGENTS.md/CLAUDE.md block and skills folders into the repo.
20
+ - `--force` is required: an incremental analyze can corrupt the index, so
21
+ symbols that exist answer "not found".
20
22
  4. Report the result: nodes indexed, edges, flows (gitnexus prints this on
21
23
  completion). If gitnexus is not installed, it will be fetched automatically
22
24
  via npx.
@@ -31,9 +33,8 @@ code_graph, code_impact, code_query, and code_context tools.
31
33
  - One-time cost: the first `--embeddings` run on a machine downloads the
32
34
  model (~87 MB) from HuggingFace and caches it at `~/.cache/huggingface`;
33
35
  every run after that is offline.
34
- - Embeddings are OFF by default and PRESERVED across a plain `analyze`
35
- (only `--drop-embeddings` removes them), so passing `--embeddings` here is
36
- additive and safe to run repeatedly.
36
+ - Embeddings are OFF by default, and passing `--embeddings` here is safe to
37
+ run repeatedly.
37
38
  - win32 caveat: on Windows, LadybugDB's VECTOR index is unavailable, so
38
39
  semantic search falls back to an exact scan (capped at 10000 chunks) --
39
40
  this still works, it is just brute-force rather than an ANN index. Not a
@@ -44,15 +45,14 @@ code_graph, code_impact, code_query, and code_context tools.
44
45
 
45
46
  - **Automatically inside `/pm init`** -- runs as the final step of project initialization.
46
47
  The worktree must exist before indexing (gitnexus needs files on disk to analyze).
47
- - **Automatically at VERIFY checkpoints** -- checkpoints re-run npx gitnexus analyze --index-only to keep
48
- mid-sprint symbols visible to later phases (incremental via fileHashes in .gitnexus/meta.json,
49
- takes seconds).
48
+ - **Automatically at VERIFY checkpoints** -- checkpoints re-run npx gitnexus analyze --index-only --force to keep
49
+ mid-sprint symbols visible to later phases (a full rebuild, minutes on a large repo).
50
50
  - After a large merge or rebase that changes many files
51
51
  - When `kb_session_prime` returns many stale entries
52
52
  - Any time the user asks to re-index (run `/pm index` explicitly)
53
53
 
54
54
  ## Notes
55
55
 
56
- - Indexing is per-repo and persists on disk -- subsequent runs are incremental.
56
+ - Indexing is per-repo and persists on disk. Always pass `--force`: never run an incremental analyze.
57
57
  - The index is used by the gitnexus provider behind code_graph/impact/query/context.
58
58
  - Fleet members never call gitnexus directly -- they use the fleet tools.
@@ -211,7 +211,8 @@ MANDATORY CHECKLIST -- verify each before exiting:
211
211
  from `<skillDir>/cost.js` (the extracted module installed alongside this skill on
212
212
  every provider -- see `cost.md`) to produce `sprint-logs/<branch>-<startedAt>.analysis.md` and
213
213
  update `sprint-logs/calibration.json` with actual token data from this sprint.
214
- Commit both. See `cost.md` Harvest.
214
+ Commit `calibration.json` only; the `.analysis.md` stays local and git-excluded,
215
+ never committed. See `cost.md` Harvest.
215
216
  5. **Close the sprint root and the delivered issues** -- `bd close <sprint-id>`; also close
216
217
  any source beads issues this sprint implemented -- the ready backlog items the
217
218
  requirement was drawn from -- with `bd close <issue-id> ...`. Closing the sprint root
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { type VersionMismatch } from '../services/version-check.js';
3
+ import { type KbConfigResult } from '../services/knowledge/kb-config.js';
3
4
  export declare const fleetStatusSchema: z.ZodObject<{
4
5
  format: z.ZodDefault<z.ZodEnum<["compact", "json"]>>;
5
6
  repo_path: z.ZodOptional<z.ZodString>;
@@ -67,9 +68,49 @@ export interface KbScopeError {
67
68
  scope: string;
68
69
  error: string;
69
70
  }
71
+ /**
72
+ * Health of the remote KB's credential (KB config provider http). The KB
73
+ * config is one file per host, so every project scope served by the http
74
+ * provider shares this one credential. This host only. Never carries the
75
+ * token, nor any JWT claim other than exp.
76
+ */
77
+ export type KbHttpCredentialHealth = {
78
+ kind: 'secret';
79
+ /** Remote KB URL the token is sent to. */
80
+ url: string;
81
+ /** Fleet secret named by the config's token_ref. */
82
+ secretName: string;
83
+ /**
84
+ * Metadata lookup: ok, missing, or expired (an expired record is kept, never
85
+ * deleted here). unreadable: the credential store could not be read, or the
86
+ * secret's value could not be decrypted; every KB call then fails with
87
+ * E-KB-HTTP-AUTH reason unreadable.
88
+ */
89
+ resolves: 'ok' | 'missing' | 'expired' | 'unreadable';
90
+ /** The secret record's created_at; null when the secret is missing or the store is unreadable. */
91
+ lastWritten: string | null;
92
+ /** exp of a JWT secret value, decoded locally, as ISO time; null for a non-JWT value or an unresolved secret. */
93
+ tokenExpiry: string | null;
94
+ /** Last KB call this process had accepted by the remote server; null when none yet. */
95
+ lastSuccessfulCall: string | null;
96
+ /** Last KB call the remote server rejected with HTTP 401; null when none yet. */
97
+ lastRejectedCall: string | null;
98
+ } | {
99
+ kind: 'literal';
100
+ url: string;
101
+ lastSuccessfulCall: string | null;
102
+ lastRejectedCall: string | null;
103
+ /** One-line note that a literal token cannot be refreshed, and how to switch to a named secret. */
104
+ hint: string;
105
+ };
106
+ export declare const KB_LITERAL_TOKEN_HINT: string;
70
107
  export interface KbHealth {
71
108
  /** Which provider the KB config selects for project scopes. With `http`, the local scopes below are the offline fallback copies. */
72
109
  projectProvider: 'sqlite' | 'http';
110
+ /** The remote KB credential; present only when the KB config selects the http provider. */
111
+ credential?: KbHttpCredentialHealth;
112
+ /** Present only when the configured KB tool profile is invalid: names the bad value and what to do. */
113
+ toolProfileWarning?: string;
73
114
  /** Every project scope found on disk (including `default`, the non-git scope), sorted by slug. */
74
115
  scopes: KbScopeHealth[];
75
116
  /** The single shared cross-project KB, or null when it does not exist yet. */
@@ -81,6 +122,14 @@ export interface KbHealth {
81
122
  }
82
123
  export declare const KB_BIBLE_NO_REPO_REASON = "bible drift needs a repo checkout; pass repo_path to fleet_status";
83
124
  export declare const KB_BIBLE_GLOBAL_REASON = "bible drift is not tracked for the global KB";
125
+ /**
126
+ * exp of a JWT, as an ISO time, decoded locally; null for anything that is not
127
+ * three base64url segments whose middle one is a JSON object with a numeric
128
+ * exp. Nothing else is read from the token.
129
+ */
130
+ export declare function jwtExpiry(token: string): string | null;
131
+ /** The credential block for an http KB config; undefined for any other provider. */
132
+ export declare function kbHttpCredentialHealth(config: KbConfigResult): KbHttpCredentialHealth | undefined;
84
133
  export interface KbHealthOptions {
85
134
  /** Knowledge root to enumerate; defaults to FLEET_DIR/knowledge. */
86
135
  knowledgeDir?: string;
@@ -102,6 +151,8 @@ export declare function kbHealthCompactLine(health: KbScopeStats, label?: string
102
151
  * scopes are collapsed into a single trailing line so an unused `default`
103
152
  * scope never reads as "the KB is empty".
104
153
  */
154
+ /** Render the one compact line for the remote KB credential. */
155
+ export declare function kbCredentialCompactLine(c: KbHttpCredentialHealth): string;
105
156
  export declare function kbHealthCompactLines(health: KbHealth): string;
106
157
  export declare function versionMismatchCompactLine(mismatch: VersionMismatch): string;
107
158
  export type FleetStatusInput = z.infer<typeof fleetStatusSchema>;
@@ -24,7 +24,10 @@ import { checkVersionMismatch } from '../services/version-check.js';
24
24
  import { SqliteProvider } from '../services/knowledge/sqlite-provider.js';
25
25
  import { listKbScopes, knowledgeRootDir, GLOBAL_KB_SCOPE } from '../services/knowledge/kb-scopes.js';
26
26
  import { resolveProjectSlug } from '../services/knowledge/project-slug.js';
27
- import { readKbConfigFromDisk } from '../services/knowledge/kb-config.js';
27
+ import { readKbConfigFromDisk, kbToolProfileWarning } from '../services/knowledge/kb-config.js';
28
+ import { getKbHttpAuthState } from '../services/knowledge/kb-http-auth-state.js';
29
+ import { lookupServerSecret, lookupServerSecretMeta } from '../services/credential-store.js';
30
+ import { gitExecutable } from '../os/git-executable.js';
28
31
  export const fleetStatusSchema = z.object({
29
32
  format: z.enum(['compact', 'json']).default('compact').describe('Output format: "compact" (default, few lines) or "json" (structured data for detailed rendering)'),
30
33
  // The fleet server is one long-lived process serving every project, so its
@@ -196,7 +199,7 @@ function readGitNexusMeta(repoDir) {
196
199
  }
197
200
  function currentHead(repoDir) {
198
201
  try {
199
- return execFileSync('git', ['rev-parse', 'HEAD'], {
202
+ return execFileSync(gitExecutable(), ['rev-parse', 'HEAD'], {
200
203
  cwd: repoDir, encoding: 'utf-8', timeout: 3000, stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true,
201
204
  }).trim();
202
205
  }
@@ -206,7 +209,7 @@ function currentHead(repoDir) {
206
209
  }
207
210
  function commitsBehindCount(repoDir, lastCommit, head) {
208
211
  try {
209
- const out = execFileSync('git', ['rev-list', '--count', `${lastCommit}..${head}`], {
212
+ const out = execFileSync(gitExecutable(), ['rev-list', '--count', `${lastCommit}..${head}`], {
210
213
  cwd: repoDir, encoding: 'utf-8', timeout: 3000, stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true,
211
214
  }).trim();
212
215
  const count = Number.parseInt(out, 10);
@@ -330,7 +333,7 @@ export function codeIntelligenceCompactLine(health) {
330
333
  return `code-intel: ${health.reason ?? CODE_INTEL_NO_REPO_REASON}` + topSymbolsFragment(health.topSymbols);
331
334
  }
332
335
  if (!health.present) {
333
- return "code-intel: no index (run 'npx gitnexus analyze --index-only' or /pm index)" + topSymbolsFragment(health.topSymbols);
336
+ return "code-intel: no index (run 'npx gitnexus analyze --index-only --force' or /pm index)" + topSymbolsFragment(health.topSymbols);
334
337
  }
335
338
  const nodes = health.nodes ?? 0;
336
339
  const edges = health.edges ?? 0;
@@ -338,6 +341,8 @@ export function codeIntelligenceCompactLine(health) {
338
341
  const indexedAt = health.indexedAt ?? 'unknown';
339
342
  return `code-intel: index present | ${nodes} nodes / ${edges} edges / ${files} files | indexed ${indexedAt} | ${headComparisonLabel(health)}${topSymbolsFragment(health.topSymbols)}`;
340
343
  }
344
+ export const KB_LITERAL_TOKEN_HINT = 'literal token stored in the KB config: it cannot be refreshed without re-running kb_setup. ' +
345
+ 'To use a refreshable fleet secret: apra-fleet secret --set NAME --persist -y, then kb_setup token {{secret.NAME}}';
341
346
  // Bible drift needs a repo checkout (.fleet/kb-canonical.json). A scope does
342
347
  // not record one and the server's cwd is not a repo, so drift is reported
343
348
  // only for the scope of an explicitly supplied repo_path.
@@ -369,13 +374,91 @@ async function bibleForRepo(repoPath) {
369
374
  return null;
370
375
  }
371
376
  }
372
- function configuredProjectProvider() {
377
+ function readKbConfigOrSqlite() {
373
378
  try {
374
- return readKbConfigFromDisk().provider === 'http' ? 'http' : 'sqlite';
379
+ return readKbConfigFromDisk();
375
380
  }
376
381
  catch {
377
382
  // kb-providers degrades a broken config to the local SqliteProvider.
378
- return 'sqlite';
383
+ return { provider: 'sqlite' };
384
+ }
385
+ }
386
+ const BASE64URL_SEGMENT = /^[A-Za-z0-9_-]+={0,2}$/;
387
+ /**
388
+ * exp of a JWT, as an ISO time, decoded locally; null for anything that is not
389
+ * three base64url segments whose middle one is a JSON object with a numeric
390
+ * exp. Nothing else is read from the token.
391
+ */
392
+ export function jwtExpiry(token) {
393
+ const parts = token.split('.');
394
+ if (parts.length !== 3 || !parts.every(p => BASE64URL_SEGMENT.test(p)))
395
+ return null;
396
+ try {
397
+ const payload = JSON.parse(Buffer.from(parts[1], 'base64url').toString('utf-8'));
398
+ if (!payload || typeof payload !== 'object' || Array.isArray(payload))
399
+ return null;
400
+ const exp = payload.exp;
401
+ if (typeof exp !== 'number' || !Number.isFinite(exp))
402
+ return null;
403
+ const at = new Date(exp * 1000);
404
+ return Number.isNaN(at.getTime()) ? null : at.toISOString();
405
+ }
406
+ catch {
407
+ return null;
408
+ }
409
+ }
410
+ /** The credential block for an http KB config; undefined for any other provider. */
411
+ export function kbHttpCredentialHealth(config) {
412
+ if (config.provider !== 'http' || !config.url)
413
+ return undefined;
414
+ const calls = getKbHttpAuthState(config.url);
415
+ const lastSuccessfulCall = calls.lastSuccessAt ?? null;
416
+ const lastRejectedCall = calls.lastRejectedAt ?? null;
417
+ if (config.tokenSecretName === undefined) {
418
+ return { kind: 'literal', url: config.url, lastSuccessfulCall, lastRejectedCall, hint: KB_LITERAL_TOKEN_HINT };
419
+ }
420
+ const secretName = config.tokenSecretName;
421
+ const block = { kind: 'secret', url: config.url, secretName, lastSuccessfulCall, lastRejectedCall };
422
+ // A store or decrypt failure is reported as resolves unreadable, never
423
+ // hidden; the error text is dropped because it can quote ciphertext.
424
+ let meta;
425
+ try {
426
+ meta = lookupServerSecretMeta(secretName);
427
+ }
428
+ catch {
429
+ return { ...block, resolves: 'unreadable', lastWritten: null, tokenExpiry: null };
430
+ }
431
+ const lastWritten = meta.status === 'missing' ? null : meta.meta.created_at;
432
+ let tokenExpiry = null;
433
+ if (meta.status === 'ok') {
434
+ let found;
435
+ try {
436
+ found = lookupServerSecret(secretName);
437
+ }
438
+ catch {
439
+ return { ...block, resolves: 'unreadable', lastWritten, tokenExpiry: null };
440
+ }
441
+ if (found.status === 'ok')
442
+ tokenExpiry = jwtExpiry(found.value);
443
+ }
444
+ return { ...block, resolves: meta.status, lastWritten, tokenExpiry };
445
+ }
446
+ function safeCredentialHealth(config) {
447
+ try {
448
+ return kbHttpCredentialHealth(config);
449
+ }
450
+ catch {
451
+ // Store errors are handled inside kbHttpCredentialHealth; anything else
452
+ // still renders the line rather than hiding it.
453
+ if (config.provider !== 'http' || !config.url)
454
+ return undefined;
455
+ if (config.tokenSecretName === undefined) {
456
+ return { kind: 'literal', url: config.url, lastSuccessfulCall: null, lastRejectedCall: null, hint: KB_LITERAL_TOKEN_HINT };
457
+ }
458
+ return {
459
+ kind: 'secret', url: config.url, secretName: config.tokenSecretName, resolves: 'unreadable',
460
+ lastWritten: null, tokenExpiry: null, lastSuccessfulCall: null, lastRejectedCall: null,
461
+ };
379
462
  }
380
463
  }
381
464
  /**
@@ -419,7 +502,19 @@ export async function kbHealthSummary(opts = {}) {
419
502
  scopes.push({ scope: loc.slug, ...stats, bible });
420
503
  }
421
504
  const totalEntries = scopes.reduce((n, s) => n + s.totals.total, 0) + (global?.totals.total ?? 0);
422
- return { projectProvider: configuredProjectProvider(), scopes, global, errors, totalEntries };
505
+ const config = readKbConfigOrSqlite();
506
+ const projectProvider = config.provider === 'http' ? 'http' : 'sqlite';
507
+ const credential = safeCredentialHealth(config);
508
+ const toolProfileWarning = kbToolProfileWarning();
509
+ return {
510
+ projectProvider,
511
+ ...(credential ? { credential } : {}),
512
+ ...(toolProfileWarning ? { toolProfileWarning } : {}),
513
+ scopes,
514
+ global,
515
+ errors,
516
+ totalEntries,
517
+ };
423
518
  }
424
519
  catch {
425
520
  return null;
@@ -450,9 +545,19 @@ export function kbHealthCompactLine(health, label) {
450
545
  * scopes are collapsed into a single trailing line so an unused `default`
451
546
  * scope never reads as "the KB is empty".
452
547
  */
548
+ /** Render the one compact line for the remote KB credential. */
549
+ export function kbCredentialCompactLine(c) {
550
+ const calls = `last ok call: ${c.lastSuccessfulCall ?? 'never'} | last rejected call: ${c.lastRejectedCall ?? 'never'}`;
551
+ if (c.kind === 'literal')
552
+ return `kb credential: ${c.hint} | ${calls}`;
553
+ return `kb credential: secret ${c.secretName} | resolves: ${c.resolves} | last written: ${c.lastWritten ?? 'never'} ` +
554
+ `| token expiry: ${c.tokenExpiry ?? 'none'} | ${calls}`;
555
+ }
453
556
  export function kbHealthCompactLines(health) {
557
+ const credentialLine = health.credential ? `\n ${kbCredentialCompactLine(health.credential)}` : '';
558
+ const toolProfileLine = health.toolProfileWarning ? `\n ${health.toolProfileWarning}` : '';
454
559
  if (health.scopes.length === 0 && !health.global && health.errors.length === 0) {
455
- return 'kb: no knowledge bases found yet (none captured on this server)';
560
+ return 'kb: no knowledge bases found yet (none captured on this server)' + credentialLine + toolProfileLine;
456
561
  }
457
562
  const nonEmpty = health.scopes.filter(s => s.totals.total > 0);
458
563
  const empty = health.scopes.filter(s => s.totals.total === 0).map(s => s.scope);
@@ -470,7 +575,9 @@ export function kbHealthCompactLines(health) {
470
575
  lines.push(` kb[${e.scope}]: unreadable (${e.error})`);
471
576
  if (empty.length > 0)
472
577
  lines.push(` kb: empty scope(s): ${empty.join(', ')}`);
473
- return lines.join('\n');
578
+ if (health.credential)
579
+ lines.push(` ${kbCredentialCompactLine(health.credential)}`);
580
+ return lines.join('\n') + toolProfileLine;
474
581
  }
475
582
  // ---------------------------------------------------------------------------
476
583
  // Server version handshake (T2.4, F7, D6). Compares the compiled-in
@@ -486,10 +593,15 @@ export async function fleetStatus(input) {
486
593
  const format = input?.format ?? 'compact';
487
594
  const agents = getAllAgents();
488
595
  if (agents.length === 0) {
596
+ // A KB tool profile matters without members too, so a bad one is reported
597
+ // here; otherwise this short form stays as it is, with no KB section.
598
+ const toolProfileWarning = kbToolProfileWarning();
489
599
  if (format === 'json') {
490
- return JSON.stringify({ version: serverVersion, summary: { total: 0, online: 0, offline: 0 }, members: [] });
600
+ const kbHealth = toolProfileWarning ? await kbHealthSummary() : null;
601
+ return JSON.stringify({ version: serverVersion, summary: { total: 0, online: 0, offline: 0 }, members: [], ...(kbHealth ? { kbHealth } : {}) });
491
602
  }
492
- return 'No members registered. Use register_member to add one.';
603
+ const noMembers = 'No members registered. Use register_member to add one.';
604
+ return toolProfileWarning ? `${noMembers}\n${toolProfileWarning}` : noMembers;
493
605
  }
494
606
  // Query all members in parallel
495
607
  const results = await Promise.allSettled(agents.map(a => checkAgent(a)));
@@ -20,7 +20,7 @@ export function freshnessNote(lastCommit, head, reindexScheduled = false) {
20
20
  return null;
21
21
  const shortLastCommit = lastCommit.slice(0, 8);
22
22
  const shortHead = head.slice(0, 8);
23
- const base = `[code-intelligence] index is behind repo HEAD (indexed ${shortLastCommit} vs HEAD ${shortHead}). Results may miss recent changes; run 'npx gitnexus analyze --index-only' to refresh.`;
23
+ const base = `[code-intelligence] index is behind repo HEAD (indexed ${shortLastCommit} vs HEAD ${shortHead}). Results may miss recent changes; run 'npx gitnexus analyze --index-only --force' to refresh.`;
24
24
  return reindexScheduled ? `${base} A background re-index has been started.` : base;
25
25
  }
26
26
  //# sourceMappingURL=code-intelligence-freshness.js.map