@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,3 +1,8 @@
1
+ import { type KbToolProfile } from '../kb-tool-profile.js';
2
+ /** Bounds and default for request_timeout_ms, shared by kb_setup (write) and the reader. */
3
+ export declare const MIN_REQUEST_TIMEOUT_MS = 1000;
4
+ export declare const MAX_REQUEST_TIMEOUT_MS = 120000;
5
+ export declare const DEFAULT_REQUEST_TIMEOUT_MS = 5000;
1
6
  /**
2
7
  * Result of reading FLEET_DIR/knowledge/config.json (the file src/tools/kb-setup.ts
3
8
  * writes). Deliberately a standalone shape, NOT ProviderConfig from ./types.js --
@@ -6,7 +11,15 @@
6
11
  export interface KbConfigResult {
7
12
  provider: 'sqlite' | 'http';
8
13
  url?: string;
14
+ /** Literal token (decrypted token_encrypted). Absent when tokenSecretName is set. */
9
15
  token?: string;
16
+ /**
17
+ * Name of the fleet secret the token is read from on each request (from the
18
+ * token_ref placeholder). Absent for a literal-token config.
19
+ */
20
+ tokenSecretName?: string;
21
+ /** Socket idle timeout per request for the http provider; absent means the provider default. */
22
+ requestTimeoutMs?: number;
10
23
  }
11
24
  /**
12
25
  * On-disk shape of FLEET_DIR/knowledge/config.json. One file, several owners:
@@ -18,20 +31,71 @@ export interface KbConfigFile {
18
31
  provider?: 'sqlite' | 'http';
19
32
  url?: string;
20
33
  token_encrypted?: string;
34
+ /** Canonical {{secret.NAME}} placeholder written by kb_setup instead of token_encrypted. */
35
+ token_ref?: string;
36
+ request_timeout_ms?: number;
21
37
  bible?: {
22
38
  autoCommit?: boolean;
23
39
  };
40
+ /**
41
+ * Install-wide KB tool profile for FULL sessions (src/services/kb-tool-profile.ts):
42
+ * "full" (default when absent), "developer", or "custom" with the kb_* names
43
+ * in tool_profile_tools. Read by readKbToolProfileFromDisk.
44
+ */
45
+ tool_profile?: 'full' | 'developer' | 'custom';
46
+ /** The kb_* tool names a "custom" tool_profile serves; ignored otherwise. */
47
+ tool_profile_tools?: string[];
24
48
  [key: string]: unknown;
25
49
  }
26
50
  export declare const KB_CONFIG_PATH: string;
51
+ /**
52
+ * The KB config file cannot be read or parsed, as opposed to holding a bad
53
+ * value. The way out is a hand edit: anything that rewrites the file would
54
+ * lose what it holds (url, token_ref, ...). The message never quotes the file:
55
+ * a JSON parser's message can repeat part of it, including the encrypted token.
56
+ */
57
+ export declare class KbConfigUnreadableError extends Error {
58
+ constructor(problem: string);
59
+ }
60
+ /** What to do about a KbConfigUnreadableError. */
61
+ export declare const KB_CONFIG_HAND_FIX = "Fix that file by hand (other settings in it, such as the remote url and token, are still there).";
62
+ /**
63
+ * The KB config as an object to merge into and write back: {} when absent.
64
+ * Throws KbConfigUnreadableError when the file cannot be read, is not valid
65
+ * JSON or is not a JSON object, so a writer never overwrites what it could not
66
+ * parse.
67
+ */
68
+ export declare function readKbConfigForMerge(): KbConfigFile;
69
+ /**
70
+ * Read the install-wide KB tool profile from the KB config.
71
+ *
72
+ * - Absent file, or no tool_profile key -> full, silently (the stock path is
73
+ * never broken by this reader; it does not look at provider/token keys).
74
+ * - A known profile -> that profile; "custom" validates tool_profile_tools
75
+ * against the registered kb_* tool names.
76
+ * - An unreadable or malformed file throws KbConfigUnreadableError; an unknown
77
+ * profile name or an invalid custom list throws an Error naming this config
78
+ * path and the problem (for a custom list: the unknown names and the valid
79
+ * ones).
80
+ */
81
+ export declare function readKbToolProfileFromDisk(): KbToolProfile;
82
+ /**
83
+ * The line fleet_status shows when the configured KB tool profile is invalid,
84
+ * or undefined when it is fine. An invalid profile never stops anything: FULL
85
+ * sessions fall back to every kb_* tool (tool-registry.ts), and this line is
86
+ * how a user or agent learns the setting they made is not applied. Never throws.
87
+ */
88
+ export declare function kbToolProfileWarning(): string | undefined;
27
89
  /**
28
90
  * Read the KB provider config kb_setup wrote (provider/url/token_encrypted). Nothing
29
91
  * currently reads this file back -- this restores that capability as a pure reader with
30
- * no side effects, so a later task can wire it into getKbProviders.
92
+ * no side effects other than a logged warning (see readRequestTimeout), so a later task can wire it into getKbProviders.
31
93
  *
32
94
  * - Absent file, or provider missing/"sqlite" -> { provider: 'sqlite' }, silently,
33
95
  * without ever touching token_encrypted (a corrupt token must never break the
34
96
  * stock sqlite path).
97
+ * - provider "http" with token_ref ({{secret.NAME}}) -> { provider: 'http', url, tokenSecretName }.
98
+ * The secret itself is NOT read here: HttpKbProvider looks it up per request.
35
99
  * - provider "http" -> decrypts token_encrypted and returns { provider: 'http', url, token }.
36
100
  * Missing url, missing token_encrypted, or a decryption failure all throw a
37
101
  * descriptive Error naming this config path and the failing key -- never a silent
@@ -2,15 +2,115 @@ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { FLEET_DIR } from '../../paths.js';
4
4
  import { decryptPassword } from '../../utils/crypto.js';
5
+ import { logWarn } from '../../utils/log-helpers.js';
6
+ import { findSecretTokens } from '../secret-token.js';
7
+ import { FULL_KB_TOOL_PROFILE, makeKbToolProfile } from '../kb-tool-profile.js';
8
+ /** Bounds and default for request_timeout_ms, shared by kb_setup (write) and the reader. */
9
+ export const MIN_REQUEST_TIMEOUT_MS = 1000;
10
+ export const MAX_REQUEST_TIMEOUT_MS = 120000;
11
+ export const DEFAULT_REQUEST_TIMEOUT_MS = 5000;
5
12
  export const KB_CONFIG_PATH = path.join(FLEET_DIR, 'knowledge', 'config.json');
13
+ /**
14
+ * The KB config file cannot be read or parsed, as opposed to holding a bad
15
+ * value. The way out is a hand edit: anything that rewrites the file would
16
+ * lose what it holds (url, token_ref, ...). The message never quotes the file:
17
+ * a JSON parser's message can repeat part of it, including the encrypted token.
18
+ */
19
+ export class KbConfigUnreadableError extends Error {
20
+ constructor(problem) {
21
+ super(`KB config at ${KB_CONFIG_PATH} ${problem}`);
22
+ this.name = 'KbConfigUnreadableError';
23
+ }
24
+ }
25
+ /** What to do about a KbConfigUnreadableError. */
26
+ export const KB_CONFIG_HAND_FIX = 'Fix that file by hand (other settings in it, such as the remote url and token, are still there).';
27
+ /** Parse the KB config, or throw KbConfigUnreadableError. Undefined when the file is absent. */
28
+ function parseKbConfigFile() {
29
+ if (!fs.existsSync(KB_CONFIG_PATH))
30
+ return undefined;
31
+ let raw;
32
+ try {
33
+ raw = fs.readFileSync(KB_CONFIG_PATH, 'utf-8');
34
+ }
35
+ catch (err) {
36
+ throw new KbConfigUnreadableError(`cannot be read (${err.code ?? 'unknown error'})`);
37
+ }
38
+ try {
39
+ return JSON.parse(raw);
40
+ }
41
+ catch {
42
+ throw new KbConfigUnreadableError('is not valid JSON');
43
+ }
44
+ }
45
+ /**
46
+ * The KB config as an object to merge into and write back: {} when absent.
47
+ * Throws KbConfigUnreadableError when the file cannot be read, is not valid
48
+ * JSON or is not a JSON object, so a writer never overwrites what it could not
49
+ * parse.
50
+ */
51
+ export function readKbConfigForMerge() {
52
+ const parsed = parseKbConfigFile();
53
+ if (parsed === undefined)
54
+ return {};
55
+ if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
56
+ throw new KbConfigUnreadableError('is not a JSON object');
57
+ }
58
+ return parsed;
59
+ }
60
+ /**
61
+ * Read the install-wide KB tool profile from the KB config.
62
+ *
63
+ * - Absent file, or no tool_profile key -> full, silently (the stock path is
64
+ * never broken by this reader; it does not look at provider/token keys).
65
+ * - A known profile -> that profile; "custom" validates tool_profile_tools
66
+ * against the registered kb_* tool names.
67
+ * - An unreadable or malformed file throws KbConfigUnreadableError; an unknown
68
+ * profile name or an invalid custom list throws an Error naming this config
69
+ * path and the problem (for a custom list: the unknown names and the valid
70
+ * ones).
71
+ */
72
+ export function readKbToolProfileFromDisk() {
73
+ const parsed = parseKbConfigFile();
74
+ if (parsed === undefined || parsed === null || typeof parsed !== 'object' || Array.isArray(parsed))
75
+ return FULL_KB_TOOL_PROFILE;
76
+ const config = parsed;
77
+ if (config.tool_profile === undefined)
78
+ return FULL_KB_TOOL_PROFILE;
79
+ try {
80
+ return makeKbToolProfile(config.tool_profile, config.tool_profile_tools);
81
+ }
82
+ catch (err) {
83
+ throw new Error(`KB config at ${KB_CONFIG_PATH}: ${err.message}`);
84
+ }
85
+ }
86
+ /**
87
+ * The line fleet_status shows when the configured KB tool profile is invalid,
88
+ * or undefined when it is fine. An invalid profile never stops anything: FULL
89
+ * sessions fall back to every kb_* tool (tool-registry.ts), and this line is
90
+ * how a user or agent learns the setting they made is not applied. Never throws.
91
+ */
92
+ export function kbToolProfileWarning() {
93
+ try {
94
+ readKbToolProfileFromDisk();
95
+ return undefined;
96
+ }
97
+ catch (err) {
98
+ const fix = err instanceof KbConfigUnreadableError
99
+ ? KB_CONFIG_HAND_FIX
100
+ : 'Set a valid one with: apra-fleet kb profile <full | developer | custom tool1,tool2>.';
101
+ return `KB tool profile not applied, serving every kb_* tool. ${err.message}. ${fix} Reconnect to pick up the change.`;
102
+ }
103
+ }
6
104
  /**
7
105
  * Read the KB provider config kb_setup wrote (provider/url/token_encrypted). Nothing
8
106
  * currently reads this file back -- this restores that capability as a pure reader with
9
- * no side effects, so a later task can wire it into getKbProviders.
107
+ * no side effects other than a logged warning (see readRequestTimeout), so a later task can wire it into getKbProviders.
10
108
  *
11
109
  * - Absent file, or provider missing/"sqlite" -> { provider: 'sqlite' }, silently,
12
110
  * without ever touching token_encrypted (a corrupt token must never break the
13
111
  * stock sqlite path).
112
+ * - provider "http" with token_ref ({{secret.NAME}}) -> { provider: 'http', url, tokenSecretName }.
113
+ * The secret itself is NOT read here: HttpKbProvider looks it up per request.
14
114
  * - provider "http" -> decrypts token_encrypted and returns { provider: 'http', url, token }.
15
115
  * Missing url, missing token_encrypted, or a decryption failure all throw a
16
116
  * descriptive Error naming this config path and the failing key -- never a silent
@@ -38,9 +138,18 @@ export function readKbConfigFromDisk() {
38
138
  if (!url) {
39
139
  throw new Error(`KB config at ${KB_CONFIG_PATH} selects provider "http" but is missing required key "url"`);
40
140
  }
141
+ const requestTimeoutField = 'request_timeout_ms' in parsed
142
+ ? { requestTimeoutMs: readRequestTimeout(parsed.request_timeout_ms) }
143
+ : {};
144
+ // token_ref (a {{secret.NAME}} placeholder kb_setup stored instead of the
145
+ // value) wins over token_encrypted: kb_setup never writes both, and the
146
+ // reference is what the operator asked for most recently if a hand edit did.
147
+ if (typeof parsed.token_ref === 'string') {
148
+ return { provider: 'http', url, tokenSecretName: readTokenRef(parsed.token_ref), ...requestTimeoutField };
149
+ }
41
150
  const tokenEncrypted = typeof parsed.token_encrypted === 'string' ? parsed.token_encrypted : undefined;
42
151
  if (!tokenEncrypted) {
43
- throw new Error(`KB config at ${KB_CONFIG_PATH} selects provider "http" but is missing required key "token_encrypted"`);
152
+ throw new Error(`KB config at ${KB_CONFIG_PATH} selects provider "http" but is missing required key "token_encrypted" (or "token_ref")`);
44
153
  }
45
154
  let token;
46
155
  try {
@@ -49,6 +158,37 @@ export function readKbConfigFromDisk() {
49
158
  catch (err) {
50
159
  throw new Error(`KB config at ${KB_CONFIG_PATH} has an undecryptable "token_encrypted": ${err.message}`);
51
160
  }
52
- return { provider: 'http', url, token };
161
+ return { provider: 'http', url, token, ...requestTimeoutField };
162
+ }
163
+ /**
164
+ * The secret name inside a token_ref value. It must be exactly one placeholder
165
+ * ({{secret.NAME}}, or the legacy {{secure.NAME}}) and nothing else -- the
166
+ * same rule kb_setup applies on write, re-checked here for hand edits.
167
+ */
168
+ function readTokenRef(value) {
169
+ const matches = findSecretTokens(value);
170
+ if (matches.length !== 1 || matches[0].raw !== value) {
171
+ throw new Error(`KB config at ${KB_CONFIG_PATH} has a "token_ref" that is not exactly one secret placeholder of the form {{secret.NAME}}`);
172
+ }
173
+ return matches[0].name;
174
+ }
175
+ /** True when value is an integer within the request_timeout_ms bounds. */
176
+ function isValidRequestTimeout(value) {
177
+ return Number.isInteger(value)
178
+ && value >= MIN_REQUEST_TIMEOUT_MS
179
+ && value <= MAX_REQUEST_TIMEOUT_MS;
180
+ }
181
+ /**
182
+ * kb_setup refuses an out-of-range value on write, but the file can be edited
183
+ * by hand. Applying the same bounds on read keeps a value like 3e9 from
184
+ * effectively disabling the timeout; falling back (instead of throwing) keeps
185
+ * an existing config working.
186
+ */
187
+ function readRequestTimeout(value) {
188
+ if (isValidRequestTimeout(value))
189
+ return value;
190
+ logWarn('kb_config', `KB config at ${KB_CONFIG_PATH} has request_timeout_ms ${JSON.stringify(value)}, not an integer between ` +
191
+ `${MIN_REQUEST_TIMEOUT_MS} and ${MAX_REQUEST_TIMEOUT_MS}; using the default ${DEFAULT_REQUEST_TIMEOUT_MS}`);
192
+ return DEFAULT_REQUEST_TIMEOUT_MS;
53
193
  }
54
194
  //# sourceMappingURL=kb-config.js.map
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Per-remote-KB auth signals, recorded by HttpKbProvider and read by
3
+ * fleet_status (src/tools/check-status.ts): when this process last had a KB
4
+ * call accepted by the remote server, and when one was last rejected for auth
5
+ * (HTTP 401). Process memory only -- a restart starts with "never" for both,
6
+ * which is what fleet_status shows until the first call.
7
+ *
8
+ * Keyed by the remote KB URL (trailing slash dropped), not by provider object:
9
+ * a config change replaces the HttpKbProvider instance, but fleet_status only
10
+ * knows the URL from the config file. Nothing here ever holds a token.
11
+ */
12
+ export interface KbHttpAuthState {
13
+ /** ISO time of the last request the remote KB server answered with a success (status below 400). */
14
+ lastSuccessAt?: string;
15
+ /** ISO time of the last request the remote KB server rejected with HTTP 401. */
16
+ lastRejectedAt?: string;
17
+ }
18
+ /** The key a remote KB URL is recorded under. */
19
+ export declare function kbHttpAuthStateKey(url: string): string;
20
+ export declare function recordKbHttpSuccess(url: string, at?: Date): void;
21
+ export declare function recordKbHttpRejected(url: string, at?: Date): void;
22
+ /** A copy of the recorded signals for a remote KB URL; empty when none yet. */
23
+ export declare function getKbHttpAuthState(url: string): KbHttpAuthState;
24
+ /** Test helper: forget every recorded signal. */
25
+ export declare function resetKbHttpAuthState(): void;
26
+ //# sourceMappingURL=kb-http-auth-state.d.ts.map
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Per-remote-KB auth signals, recorded by HttpKbProvider and read by
3
+ * fleet_status (src/tools/check-status.ts): when this process last had a KB
4
+ * call accepted by the remote server, and when one was last rejected for auth
5
+ * (HTTP 401). Process memory only -- a restart starts with "never" for both,
6
+ * which is what fleet_status shows until the first call.
7
+ *
8
+ * Keyed by the remote KB URL (trailing slash dropped), not by provider object:
9
+ * a config change replaces the HttpKbProvider instance, but fleet_status only
10
+ * knows the URL from the config file. Nothing here ever holds a token.
11
+ */
12
+ const _states = new Map();
13
+ /** The key a remote KB URL is recorded under. */
14
+ export function kbHttpAuthStateKey(url) {
15
+ return url.replace(/\/+$/, '');
16
+ }
17
+ function slot(url) {
18
+ const key = kbHttpAuthStateKey(url);
19
+ let state = _states.get(key);
20
+ if (!state) {
21
+ state = {};
22
+ _states.set(key, state);
23
+ }
24
+ return state;
25
+ }
26
+ export function recordKbHttpSuccess(url, at = new Date()) {
27
+ slot(url).lastSuccessAt = at.toISOString();
28
+ }
29
+ export function recordKbHttpRejected(url, at = new Date()) {
30
+ slot(url).lastRejectedAt = at.toISOString();
31
+ }
32
+ /** A copy of the recorded signals for a remote KB URL; empty when none yet. */
33
+ export function getKbHttpAuthState(url) {
34
+ return { ..._states.get(kbHttpAuthStateKey(url)) };
35
+ }
36
+ /** Test helper: forget every recorded signal. */
37
+ export function resetKbHttpAuthState() {
38
+ _states.clear();
39
+ }
40
+ //# sourceMappingURL=kb-http-auth-state.js.map
@@ -8,6 +8,13 @@ export interface KbProviders {
8
8
  export declare function createKbProviders(cwd?: string, remoteUrl?: string): Promise<KbProviders>;
9
9
  /** The single shared global KB provider. */
10
10
  export declare function getGlobalKbProvider(): Promise<SqliteProvider>;
11
+ /**
12
+ * True when the KB config selects the http project provider, decided from the
13
+ * config file alone: no provider is built and no per-repo kb.sqlite is opened.
14
+ * A config that fails to read gives false, the same SQLite decision
15
+ * selectProjectProvider makes for it (and warns about on the next provider build).
16
+ */
17
+ export declare function kbConfigSelectsHttp(): boolean;
11
18
  /** The project slug (KB identity) for a repo folder, cached like getKbProviders'. */
12
19
  export declare function getProjectSlug(cwd?: string, remoteUrl?: string): string;
13
20
  /**
@@ -15,8 +22,8 @@ export declare function getProjectSlug(cwd?: string, remoteUrl?: string): string
15
22
  * about -- omitting it falls back to the calling process's cwd, which is only
16
23
  * correct for single-repo CLI invocations, never for server-handled tool calls.
17
24
  *
18
- * Returns the identical object for repeated calls on the same (slug, repoPath)
19
- * while the KB config is unchanged. Once the config content changes, the next
25
+ * Returns the identical object for repeated calls on the same (slug, repoPath,
26
+ * remoteUrl) while the KB config is unchanged. Once the config content changes, the next
20
27
  * call selects the project provider afresh; the SqliteProviders underneath are
21
28
  * reused, never reopened.
22
29
  */
@@ -5,10 +5,11 @@ import { SqliteProvider } from './sqlite-provider.js';
5
5
  import { HttpKbProvider } from './http-provider.js';
6
6
  import { readKbConfigFromDisk, KB_CONFIG_PATH } from './kb-config.js';
7
7
  import { resolveProjectSlug } from './project-slug.js';
8
+ import { resolveRepositoryIdentity } from './repository-header.js';
8
9
  import { FLEET_DIR } from '../../paths.js';
9
10
  import { logWarn } from '../../utils/log-helpers.js';
10
11
  export async function createKbProviders(cwd, remoteUrl) {
11
- return createKbProvidersForSlug(slugFor(cwd, remoteUrl), cwd ?? process.cwd());
12
+ return createKbProvidersForSlug(slugFor(cwd, remoteUrl), cwd ?? process.cwd(), remoteUrl);
12
13
  }
13
14
  // There is exactly ONE global KB, shared by every project. Now that providers
14
15
  // are cached per project slug, building it inside the per-slug factory would
@@ -43,12 +44,12 @@ async function createBaseProvidersForSlug(slug, repoPath) {
43
44
  const global = await getGlobalProvider();
44
45
  return { projectSqlite, global };
45
46
  }
46
- async function createKbProvidersForSlug(slug, repoPath) {
47
- return withSelectedProject(await createBaseProvidersForSlug(slug, repoPath), slug, kbConfigFingerprint());
47
+ async function createKbProvidersForSlug(slug, repoPath, remoteUrl) {
48
+ return withSelectedProject(await createBaseProvidersForSlug(slug, repoPath), slug, repoPath, remoteUrl, kbConfigFingerprint());
48
49
  }
49
- async function withSelectedProject(base, slug, configFingerprint) {
50
+ async function withSelectedProject(base, slug, repoPath, remoteUrl, configFingerprint) {
50
51
  return {
51
- project: await selectProjectProvider(base.projectSqlite, configFingerprint),
52
+ project: await selectProjectProvider(base.projectSqlite, repoPath, remoteUrl, configFingerprint, slug),
52
53
  global: base.global,
53
54
  projectSlug: slug,
54
55
  };
@@ -98,11 +99,14 @@ function kbConfigFingerprint() {
98
99
  * after a warning, once per distinct config content -- see the note above
99
100
  * _warnedKbConfigFailures.
100
101
  *
101
- * The HTTP branch passes that same SqliteProvider as the explicit fallback:
102
- * HttpKbProvider's default is a NO-ARG `new SqliteProvider()`, which resolves its
103
- * database from process.cwd() rather than this repo's path.
102
+ * The HTTP branch gives HttpKbProvider no local store: over http the KB
103
+ * server is the only source of truth. It passes the resolved repository (repoPath's origin remote and HEAD,
104
+ * or the remote member's remoteUrl), which HttpKbProvider sends as the
105
+ * X-Repository / X-Repository-Commit / X-Repository-Branch headers (commit and
106
+ * branch only for a local folder) so a shared remote KB can keep
107
+ * repositories apart. It comes only from the resolved anchor, never tool input.
104
108
  */
105
- async function selectProjectProvider(projectProvider, configFingerprint) {
109
+ async function selectProjectProvider(projectProvider, repoPath, remoteUrl, configFingerprint, slug) {
106
110
  let config;
107
111
  try {
108
112
  config = readKbConfigFromDisk();
@@ -118,25 +122,49 @@ async function selectProjectProvider(projectProvider, configFingerprint) {
118
122
  return projectProvider;
119
123
  }
120
124
  // my-beads-db-u00.4: the HTTP provider is init'd like any other provider,
121
- // rather than relying on HttpKbProvider.init() doing nothing beyond
122
- // re-init'ing its fallback. That fallback is the already-init'd
123
- // projectProvider, and SqliteProvider.init() returns early once its db is
124
- // open, so the double init is harmless (pinned in
125
- // tests/knowledge/kb-providers-http-selection.test.ts) -- and any setup
126
- // HttpKbProvider.init() grows later runs here instead of being skipped.
127
- // readKbConfigFromDisk throws on http-without-url/token, so both are present here.
128
- const httpProvider = new HttpKbProvider(config.url, config.token, projectProvider);
125
+ // so any setup HttpKbProvider.init() grows later runs here instead of being
126
+ // skipped.
127
+ // readKbConfigFromDisk throws on http-without-url/token, so the url and one
128
+ // token source are present here. A token_ref config hands the provider the
129
+ // secret NAME, never a value: the provider looks it up on every request, so a
130
+ // secret update (which does not change config.json, hence never re-selects
131
+ // here) still takes effect on the next call.
132
+ const tokenSource = config.tokenSecretName !== undefined
133
+ ? { secretName: config.tokenSecretName }
134
+ : config.token;
135
+ const repository = resolveRepositoryIdentity(repoPath, remoteUrl);
136
+ // The slug goes on every request (X-KB-Project) so a server for another
137
+ // project refuses it instead of answering with that project's KB.
138
+ const httpProvider = new HttpKbProvider(config.url, tokenSource, {
139
+ requestTimeoutMs: config.requestTimeoutMs,
140
+ projectSlug: slug,
141
+ ...(repository ? { repository } : {}),
142
+ });
129
143
  try {
130
144
  await httpProvider.init();
131
145
  }
132
146
  catch (err) {
133
- // Not yet tracked in _httpProviders, so release its beforeExit listener here.
147
+ // Not yet tracked in _httpProviders, so dispose it here.
134
148
  httpProvider.dispose();
135
149
  throw err;
136
150
  }
137
151
  _httpProviders.push(httpProvider);
138
152
  return httpProvider;
139
153
  }
154
+ /**
155
+ * True when the KB config selects the http project provider, decided from the
156
+ * config file alone: no provider is built and no per-repo kb.sqlite is opened.
157
+ * A config that fails to read gives false, the same SQLite decision
158
+ * selectProjectProvider makes for it (and warns about on the next provider build).
159
+ */
160
+ export function kbConfigSelectsHttp() {
161
+ try {
162
+ return readKbConfigFromDisk().provider === 'http';
163
+ }
164
+ catch {
165
+ return false;
166
+ }
167
+ }
140
168
  // Keyed by (slug, repoPath), NOT slug alone and NOT a single slot. The fleet
141
169
  // server is a long-lived process serving many members across many repos; a
142
170
  // single memoised provider meant the first kb_* call bound every later call
@@ -150,6 +178,15 @@ const _selections = new Map();
150
178
  function providerKey(slug, repoPath) {
151
179
  return `${slug}\0${repoPath}`;
152
180
  }
181
+ // A selection also carries the repository the HTTP provider sends, which is a
182
+ // function of (repoPath, remoteUrl): slugs are lossy, so two remotes can share
183
+ // a slug, and a remoteUrl means the folder is on another host (no commit). The
184
+ // remoteUrl is therefore part of the selection key, so a cached selection can
185
+ // never hand out a provider sending another repository. The base SqliteProviders
186
+ // stay keyed by (slug, repoPath) and are shared.
187
+ function selectionKey(slug, repoPath, remoteUrl) {
188
+ return `${providerKey(slug, repoPath)}\0${remoteUrl?.trim() ?? ''}`;
189
+ }
153
190
  // my-beads-db-0cd.12: do NOT cache a rejected promise. Without this, one
154
191
  // failed build (e.g. a disk error, not the config-read case above which no
155
192
  // longer throws) permanently poisons this cache key: every later call for
@@ -182,21 +219,14 @@ function getBaseProviders(slug, repoPath, key) {
182
219
  function disposeIfHttp(provider) {
183
220
  if (!(provider instanceof HttpKbProvider))
184
221
  return;
185
- // dispose() removes the beforeExit hook that would have reported unsent
186
- // captures at exit, so report them now instead of dropping them silently.
187
- if (provider.offlineQueue.length > 0) {
188
- logWarn('kb-providers', `KB config changed: the replaced remote KB provider still had ${provider.offlineQueue.length} ` +
189
- 'unsent captures in its offline queue. Run kb_harvest on the session transcript to recover them.');
190
- }
191
222
  provider.dispose();
192
223
  const index = _httpProviders.indexOf(provider);
193
224
  if (index !== -1)
194
225
  _httpProviders.splice(index, 1);
195
226
  }
196
- // A superseded selection's HttpKbProvider is disposed so its beforeExit
197
- // listener does not outlive it (the leak my-beads-db-u00.2 fixed in kb-server).
198
- // dispose() only removes that listener, so a caller still holding the old
199
- // provider mid-call keeps a working provider.
227
+ // A superseded selection's HttpKbProvider is disposed. dispose() releases
228
+ // nothing today (the provider holds no queue, listener or handle), so a caller
229
+ // still holding the old provider mid-call keeps a working provider.
200
230
  function retireSelection(selection) {
201
231
  selection.providers.then(providers => disposeIfHttp(providers.project), () => {
202
232
  // Nothing to dispose: every awaiter of this build already received its
@@ -204,8 +234,9 @@ function retireSelection(selection) {
204
234
  // init fails before rethrowing.
205
235
  });
206
236
  }
207
- async function selectProviders(slug, repoPath, key, configFingerprint) {
208
- return withSelectedProject(await getBaseProviders(slug, repoPath, key), slug, configFingerprint);
237
+ async function selectProviders(slug, repoPath, remoteUrl, configFingerprint) {
238
+ const base = await getBaseProviders(slug, repoPath, providerKey(slug, repoPath));
239
+ return withSelectedProject(base, slug, repoPath, remoteUrl, configFingerprint);
209
240
  }
210
241
  // resolveProjectSlug shells out to git, so cache per (cwd, remoteUrl) pair --
211
242
  // keying by cwd alone would let the first call for a directory pin its slug,
@@ -232,15 +263,15 @@ export function getProjectSlug(cwd, remoteUrl) {
232
263
  * about -- omitting it falls back to the calling process's cwd, which is only
233
264
  * correct for single-repo CLI invocations, never for server-handled tool calls.
234
265
  *
235
- * Returns the identical object for repeated calls on the same (slug, repoPath)
236
- * while the KB config is unchanged. Once the config content changes, the next
266
+ * Returns the identical object for repeated calls on the same (slug, repoPath,
267
+ * remoteUrl) while the KB config is unchanged. Once the config content changes, the next
237
268
  * call selects the project provider afresh; the SqliteProviders underneath are
238
269
  * reused, never reopened.
239
270
  */
240
271
  export async function getKbProviders(cwd, remoteUrl) {
241
272
  const slug = slugFor(cwd, remoteUrl);
242
273
  const repoPath = cwd ?? process.cwd();
243
- const key = providerKey(slug, repoPath);
274
+ const key = selectionKey(slug, repoPath, remoteUrl);
244
275
  const configFingerprint = kbConfigFingerprint();
245
276
  const current = _selections.get(key);
246
277
  if (current && current.configFingerprint === configFingerprint) {
@@ -251,16 +282,15 @@ export async function getKbProviders(cwd, remoteUrl) {
251
282
  }
252
283
  const selection = {
253
284
  configFingerprint,
254
- providers: selectProviders(slug, repoPath, key, configFingerprint),
285
+ providers: selectProviders(slug, repoPath, remoteUrl, configFingerprint),
255
286
  };
256
287
  _selections.set(key, selection);
257
288
  evictOnReject(_selections, key, selection, selection.providers);
258
289
  return selection.providers;
259
290
  }
260
291
  export function resetKbProviders() {
261
- // HttpKbProvider registers a process 'beforeExit' listener in its constructor;
262
- // clearing the maps alone leaks one listener per reset, and a suite that resets
263
- // repeatedly hits MaxListenersExceededWarning.
292
+ // Every tracked HttpKbProvider is disposed before the maps are cleared, so a
293
+ // provider that ever holds a resource releases it on reset.
264
294
  for (const httpProvider of _httpProviders) {
265
295
  httpProvider.dispose();
266
296
  }
@@ -15,7 +15,7 @@
15
15
  import { z } from 'zod';
16
16
  /** What replaces each removed key, phrased as the caller's fix. */
17
17
  export const KB_REMOVED_SCOPE_KEY_REPLACEMENTS = Object.freeze({
18
- repo_path: "nothing -- drop it: every kb_* call acts on the calling session's own KB (a member session's registered work folder; a FULL session's fleet server working folder). To act on another repository, call from a member session registered on that folder.",
18
+ repo_path: "nothing -- drop it: every kb_* call acts on the calling session's own KB (a member session's registered work folder; a FULL session's first MCP client root inside a git repository with an origin remote, or the fleet server working folder when the client offers no roots). To act on another repository, call from a member session registered on that folder.",
19
19
  repo: "nothing -- drop it: same as repo_path, the KB (and kb_stats' bible drift check) is the calling session's own repository. kb_import names a bible file with path, which is unchanged.",
20
20
  repo_remote_url: "nothing -- drop it: a remote member's KB identity is its registered origin remote (record it with update_member git_repos) and is resolved from the calling member session.",
21
21
  });