@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
@@ -10,11 +10,13 @@
10
10
  import { DatabaseSync } from 'node:sqlite';
11
11
  import path from 'node:path';
12
12
  import fs from 'node:fs';
13
- import { randomUUID } from 'node:crypto';
13
+ import { createHash, randomUUID } from 'node:crypto';
14
14
  import { FLEET_DIR } from '../../paths.js';
15
15
  import { resolveProjectSlug } from './project-slug.js';
16
16
  import { makeFtsQuery, makeAudnDecision, orJoinFtsTerms, } from './audn.js';
17
17
  import { computeFileHashBatch } from './file-hash.js';
18
+ import { validateFilePaths } from './path-validation.js';
19
+ import { clampBibleTimeToNow, standingAgainstTombstone } from './bible-import.js';
18
20
  import { KbCaptureRejected } from './types.js';
19
21
  const CONTENT_CAP = 4000;
20
22
  const TRUNCATION_SUFFIX = '...[truncated]';
@@ -32,6 +34,46 @@ const MIN_PROMOTE_REASON_LENGTH = 20;
32
34
  function isNonTrivialPromoteReason(reason) {
33
35
  return (reason ?? '').trim().length >= MIN_PROMOTE_REASON_LENGTH;
34
36
  }
37
+ /**
38
+ * Minimum length of a kb_demote reason, measured AFTER newlines are collapsed
39
+ * to spaces and the result trimmed. Same floor as kb_promote: withdrawing
40
+ * trust must be as auditable as granting it, and a reason that is only
41
+ * whitespace/newlines collapses to the empty string and is refused.
42
+ */
43
+ const MIN_DEMOTE_REASON_LENGTH = 20;
44
+ /**
45
+ * The single normalisation applied to a demote reason, used for BOTH the
46
+ * length gate and the note written into content -- so what was validated is
47
+ * exactly what is recorded. Every newline becomes a space (the note must stay
48
+ * one line, and must never be able to grow a second leading newline and so
49
+ * collide with the kb_feedback marker, which is two newlines + "[feedback ").
50
+ */
51
+ function normalizeDemoteReason(reason) {
52
+ return (reason ?? '').replace(/[\r\n]/g, ' ').trim();
53
+ }
54
+ /**
55
+ * The ONE demotion-note format, shared by kb_demote (demote()) and the bible
56
+ * tombstone path (applyBibleDemotion()), so a demotion that crosses clones
57
+ * reads identically to one applied locally.
58
+ *
59
+ * String concatenation (not a template literal) per the ASCII pre-commit hook
60
+ * gotcha: backslash-n escapes inside JS template literals false-positive on the
61
+ * hook's non-ASCII scan (same convention as promote()'s promotionNote and
62
+ * feedback()'s note).
63
+ *
64
+ * EXACTLY ONE leading newline. feedback() writes TWO ('\n\n[feedback ...'), so
65
+ * a demote note can never be mistaken for a feedback marker by anything
66
+ * scanning content for one.
67
+ */
68
+ function buildDemotionNote(normalizedReason, evidence, author) {
69
+ const evidenceClause = evidence.length > 0 ? ' | evidence: ' + evidence.join(', ') : '';
70
+ return '\n[Demoted: ' + normalizedReason + evidenceClause + ' -- ' + (author || 'unknown') + ']';
71
+ }
72
+ /**
73
+ * The reason recorded when a demotion arrives through the committed project
74
+ * bible rather than a local kb_demote. Must clear MIN_DEMOTE_REASON_LENGTH.
75
+ */
76
+ export const BIBLE_DEMOTION_REASON = 'demoted in the project bible';
35
77
  class NotImplementedError extends Error {
36
78
  constructor(method) {
37
79
  super(`SqliteProvider.${method}() not yet implemented`);
@@ -208,6 +250,33 @@ export class SqliteProvider {
208
250
  this.db.exec('ALTER TABLE entries ADD COLUMN local_basis_only INTEGER NOT NULL DEFAULT 0');
209
251
  }
210
252
  catch { }
253
+ // kb_demote (CONFIRMED -> INFERRED): demoted_at records WHEN trust was
254
+ // withdrawn, demoted_basis_hashes the sha256 of each cited source file AS
255
+ // IT WAS ON DISK AT DEMOTE TIME. The second column is deliberately NOT a
256
+ // copy of source_file_hashes (which is the CAPTURE-time basis): the
257
+ // ping-pong guard built on top of it asks "has the tree moved on since we
258
+ // demoted?", and a capture-time copy answers the wrong question, so a file
259
+ // edited between capture and demote would look unchanged forever. Same
260
+ // guarded-ALTER pattern as scope/source_file_hashes above: it runs on a
261
+ // fresh DB (the columns are not in CREATE TABLE) and is a caught no-op on
262
+ // a DB that already has them.
263
+ try {
264
+ this.db.exec('ALTER TABLE entries ADD COLUMN demoted_at TEXT');
265
+ }
266
+ catch { }
267
+ try {
268
+ this.db.exec("ALTER TABLE entries ADD COLUMN demoted_basis_hashes TEXT NOT NULL DEFAULT '{}'");
269
+ }
270
+ catch { }
271
+ // The updated_at a bible carried for an entry this clone imported (capture
272
+ // opts.carriedUpdatedAt): when the exporting clone promoted it. Tombstones
273
+ // are judged against it (getBibleTrustTimes), never against the local
274
+ // import time. Internal only: never surfaced on KBEntry. NULL on every row
275
+ // that was not imported, and on rows imported before the column existed.
276
+ try {
277
+ this.db.exec('ALTER TABLE entries ADD COLUMN bible_updated_at TEXT');
278
+ }
279
+ catch { }
211
280
  // kb_import trust anchor: git blob ids of bibles the maintainer side wrote
212
281
  // or imported (kb_bible_commit and FULL / kb_maintainer kb_import). A
213
282
  // member session without the kb_maintainer grant imports its committed
@@ -269,6 +338,10 @@ export class SqliteProvider {
269
338
  created_at: row.created_at,
270
339
  superseded_at: row.superseded_at,
271
340
  promoted_at: row.promoted_at,
341
+ // kb_demote columns. Tolerant of a row read before the migration ran
342
+ // (undefined) and of a legacy NULL/'' in demoted_basis_hashes.
343
+ demoted_at: row.demoted_at ?? undefined,
344
+ demoted_basis_hashes: JSON.parse(row.demoted_basis_hashes || '{}'),
272
345
  use_count: row.use_count,
273
346
  last_accessed: row.last_accessed,
274
347
  };
@@ -497,6 +570,110 @@ export class SqliteProvider {
497
570
  }
498
571
  return out;
499
572
  }
573
+ /**
574
+ * The bible trust time of each given id that exists: when this clone's trust
575
+ * in the row dates from, as a bible records it. promoted_at when the row was
576
+ * promoted here; else the updated_at the bible carried when the row was
577
+ * imported (bible_updated_at); else null for an imported row from before that
578
+ * column existed -- its trust came from a bible, and the local import time
579
+ * says nothing about when it was promoted. Any other row falls back to
580
+ * created_at. An unknown id is absent from the map. Fed to
581
+ * standingAgainstTombstone (bible-import.ts) by kb_export, and used for the
582
+ * updated_at a bible writer records, so every clone compares the same value.
583
+ * Internal to this provider, not an MCP surface.
584
+ */
585
+ getBibleTrustTimes(ids) {
586
+ const out = new Map();
587
+ if (ids.length === 0)
588
+ return out;
589
+ const db = this.getDb();
590
+ // Chunk to stay well under SQLite's bound-parameter limit (as above).
591
+ const CHUNK = 500;
592
+ for (let i = 0; i < ids.length; i += CHUNK) {
593
+ const chunk = ids.slice(i, i + CHUNK);
594
+ const rows = db.prepare(`SELECT id, promoted_at, bible_updated_at, source, created_at FROM entries WHERE id IN (${chunk.map(() => '?').join(',')})`).all(...chunk);
595
+ for (const row of rows)
596
+ out.set(row.id, this.bibleTrustTimeOf(row));
597
+ }
598
+ return out;
599
+ }
600
+ /** getBibleTrustTimes' rule for one raw row (needs promoted_at, bible_updated_at, source, created_at). */
601
+ bibleTrustTimeOf(row) {
602
+ if (typeof row.promoted_at === 'string')
603
+ return row.promoted_at;
604
+ if (typeof row.bible_updated_at === 'string')
605
+ return row.bible_updated_at;
606
+ if (row.source === 'import')
607
+ return null;
608
+ return typeof row.created_at === 'string' ? row.created_at : null;
609
+ }
610
+ /**
611
+ * Read-only accessor for the demotion state of the given entry ids: the
612
+ * CURRENT confidence and demoted_at of each id that exists. An unknown id is
613
+ * simply absent from the map.
614
+ *
615
+ * Deliberately NOT routed through list(): list() excludes stale and superseded
616
+ * rows, and a demoted entry that later went stale is exactly the one whose
617
+ * tombstone other clones most need -- their bible still carries the entry.
618
+ * Policy (what counts as demoted enough to tombstone) lives in the caller
619
+ * (src/tools/kb-bible-commit.ts); this member only reports the two columns.
620
+ * Internal to this provider, not an MCP surface.
621
+ */
622
+ getDemotionState(ids) {
623
+ const out = new Map();
624
+ if (ids.length === 0)
625
+ return out;
626
+ const db = this.getDb();
627
+ // Chunk to stay well under SQLite's bound-parameter limit (as above).
628
+ const CHUNK = 500;
629
+ for (let i = 0; i < ids.length; i += CHUNK) {
630
+ const chunk = ids.slice(i, i + CHUNK);
631
+ const rows = db.prepare(`SELECT id, confidence, demoted_at FROM entries WHERE id IN (${chunk.map(() => '?').join(',')})`).all(...chunk);
632
+ for (const row of rows) {
633
+ out.set(row.id, {
634
+ confidence: row.confidence,
635
+ demoted_at: row.demoted_at ?? undefined,
636
+ });
637
+ }
638
+ }
639
+ return out;
640
+ }
641
+ /**
642
+ * For each of the given ids that EXISTS locally, whether that row is LIVE
643
+ * CONFIRMED: confidence is CONFIRMED and the row is not stale, not superseded
644
+ * and not flagged_for_review.
645
+ *
646
+ * An id with NO local row is simply ABSENT from the map -- the caller must be
647
+ * able to tell "I hold a row and it is no longer trustworthy" (do not surface
648
+ * the bible's version of it) from "I have never seen this id" (the cold-seed
649
+ * case the bible exists to serve). A boolean-only return would conflate them.
650
+ *
651
+ * ONE predicate, deliberately not a demoted_at check. A demotion is only one
652
+ * of the ways a row stops being live CONFIRMED; staleness, supersession and a
653
+ * review flag are the others, and a cold seed that re-surfaced the bible's
654
+ * CONFIRMED copy of any of them would be re-asserting knowledge this clone has
655
+ * already stopped trusting. Reads the rows DIRECTLY rather than through list(),
656
+ * which filters stale and superseded rows out and so cannot report them.
657
+ */
658
+ getLiveConfirmedState(ids) {
659
+ const out = new Map();
660
+ if (ids.length === 0)
661
+ return out;
662
+ const db = this.getDb();
663
+ // Chunk to stay well under SQLite's bound-parameter limit (as above).
664
+ const CHUNK = 500;
665
+ for (let i = 0; i < ids.length; i += CHUNK) {
666
+ const chunk = ids.slice(i, i + CHUNK);
667
+ const rows = db.prepare(`SELECT id, confidence, stale, superseded_at, flagged_for_review FROM entries WHERE id IN (${chunk.map(() => '?').join(',')})`).all(...chunk);
668
+ for (const row of rows) {
669
+ out.set(row.id, row.confidence === 'CONFIRMED'
670
+ && row.stale !== 1
671
+ && row.superseded_at === null
672
+ && row.flagged_for_review !== 1);
673
+ }
674
+ }
675
+ return out;
676
+ }
500
677
  // T1.3 (F2/D2 HARDENED): freshness check bounded to the primed set, now
501
678
  // BIDIRECTIONAL. Keyed off source_files with a per-file hash basis persisted
502
679
  // at capture time (source_file_hashes) -- NOT content_hash, which is only ever
@@ -923,6 +1100,9 @@ export class SqliteProvider {
923
1100
  // resolved by AUDN under a new id, never by overwriting the preserved id.
924
1101
  const id = opts?.preferredId ?? randomUUID();
925
1102
  this.insertEntry(db, id, input, content, now, sourceFileHashes, localBasisOnly);
1103
+ if (opts?.importMode === true && opts.carriedUpdatedAt !== undefined) {
1104
+ db.prepare('UPDATE entries SET bible_updated_at = ? WHERE id = ?').run(opts.carriedUpdatedAt, id);
1105
+ }
926
1106
  this.wireLinks(db, id, input);
927
1107
  return { id, audn_decision: 'add' };
928
1108
  }
@@ -1356,11 +1536,14 @@ export class SqliteProvider {
1356
1536
  // CONFIRMED set what we think it is") which should not perturb that
1357
1537
  // telemetry. A dedicated method keeps the two contracts textually distinct
1358
1538
  // instead of an easy-to-miss opt-out flag threaded through query(). Always
1359
- // excludes superseded and stale entries (no override -- this is an
1360
- // audit-the-live-set tool, not a full-history query).
1539
+ // excludes superseded entries, and stale ones unless include_stale is set
1540
+ // (kb_list never sets it -- it is an audit-the-live-set tool, not a
1541
+ // full-history query; the kb-server ownership lookup does).
1361
1542
  async list(opts) {
1362
1543
  const db = this.getDb();
1363
- const conditions = ['e.superseded_at IS NULL', 'e.stale = 0'];
1544
+ const conditions = ['e.superseded_at IS NULL'];
1545
+ if (!opts.include_stale)
1546
+ conditions.push('e.stale = 0');
1364
1547
  const params = [];
1365
1548
  if (opts.exclude_disputed) {
1366
1549
  conditions.push('e.flagged_for_review = 0 AND e.contradiction_of IS NULL');
@@ -1474,6 +1657,235 @@ export class SqliteProvider {
1474
1657
  .run(confidence_after, now, newContent, 'promotion', id);
1475
1658
  return { id, confidence_before, confidence_after };
1476
1659
  }
1660
+ /**
1661
+ * Evidence paths cited by a demote. Deliberately STRICTER than the basis
1662
+ * check promote() runs: a demote reason is an audit record, so a path that
1663
+ * cannot be pointed at inside this provider's anchor is refused rather than
1664
+ * recorded as an unverifiable string.
1665
+ *
1666
+ * Refuses, all with E-DEMOTE-EVIDENCE-UNRESOLVED:
1667
+ * - any path that is not anchor-relative -- an ABSOLUTE path, or one with
1668
+ * a '..' segment. Both are "out of the anchor": an absolute path names a
1669
+ * location the anchor does not contain, and was previously accepted and
1670
+ * recorded verbatim, which contradicted this very comment. The check is
1671
+ * delegated to validateFilePaths (path-validation.ts), the SAME guard
1672
+ * every other caller-supplied kb_* file list already runs (kb_capture,
1673
+ * kb_context, kb_invalidate, kb_session_prime and the HTTP routes), so
1674
+ * this is not a third hand-rolled path guard. It runs BEFORE existence,
1675
+ * so a path that happens to land on a real file outside the repo is
1676
+ * still refused, and it applies even on the shared-global no-anchor KB,
1677
+ * where nothing absolute could be verified against an anchor anyway;
1678
+ * - a path that does not resolve, via the SAME resolver promote uses
1679
+ * (unresolvableBasisFiles -> resolveBasisFile);
1680
+ * - a path that resolves to something that is not a regular file
1681
+ * (directories are not evidence).
1682
+ */
1683
+ assertResolvableDemoteEvidence(id, files) {
1684
+ const refuse = (why, offenders) => {
1685
+ throw new Error('E-DEMOTE-EVIDENCE-UNRESOLVED: kb_demote evidence ' + why + ': '
1686
+ + offenders.join(', ') + '. Entry: ' + id);
1687
+ };
1688
+ // Per-file so the message can name EVERY offender, not just the first one
1689
+ // validateFilePaths would throw on.
1690
+ const traversing = files.filter((f) => {
1691
+ try {
1692
+ validateFilePaths([f]);
1693
+ return false;
1694
+ }
1695
+ catch {
1696
+ return true;
1697
+ }
1698
+ });
1699
+ if (traversing.length > 0)
1700
+ refuse('is absolute or traverses out of the anchor', traversing);
1701
+ const unresolved = this.unresolvableBasisFiles(files);
1702
+ if (unresolved.length > 0)
1703
+ refuse('does not resolve', unresolved);
1704
+ const notFiles = files.filter((f) => {
1705
+ const resolved = this.resolveBasisFile(f);
1706
+ try {
1707
+ return !fs.statSync(resolved).isFile();
1708
+ }
1709
+ catch {
1710
+ // Unreadable here means unresolvableBasisFiles already cleared it (the
1711
+ // shared-global no-anchor case); nothing further to assert.
1712
+ return false;
1713
+ }
1714
+ });
1715
+ if (notFiles.length > 0)
1716
+ refuse('is not a file', notFiles);
1717
+ }
1718
+ /**
1719
+ * The demote-time basis snapshot: sha256 of each cited source file AS IT IS
1720
+ * ON DISK RIGHT NOW, keyed by the original (unresolved) path string, the
1721
+ * same key convention source_file_hashes uses.
1722
+ *
1723
+ * This MUST NOT be derived from the source_file_hashes column. That column
1724
+ * is the CAPTURE-time basis; copying it was the defect in the superseded
1725
+ * upstream attempt, and it silently breaks the ping-pong guard that asks
1726
+ * whether the tree has moved on SINCE the demotion. Files that cannot be
1727
+ * read are simply absent from the map (a demote is still allowed on an
1728
+ * entry whose basis has since disappeared -- unlike promote, which refuses).
1729
+ *
1730
+ * sha256 and not `git hash-object`: this snapshot is compared against a
1731
+ * later re-read of the same files by the same code, so it must not depend on
1732
+ * git being available or on the file being in a work tree.
1733
+ */
1734
+ demoteBasisHashes(files) {
1735
+ const hashes = {};
1736
+ for (const f of files) {
1737
+ try {
1738
+ hashes[f] = createHash('sha256').update(fs.readFileSync(this.resolveBasisFile(f))).digest('hex');
1739
+ }
1740
+ catch {
1741
+ // Unreadable/absent basis file: no entry, never a fabricated hash.
1742
+ }
1743
+ }
1744
+ return hashes;
1745
+ }
1746
+ /**
1747
+ * kb_demote: withdraw trust from a CONFIRMED entry, CONFIRMED -> INFERRED.
1748
+ *
1749
+ * The inverse of promote() in intent but NOT its mirror image in mechanics:
1750
+ *
1751
+ * - it is NOT a ladder. Only CONFIRMED is demotable; INFERRED/UNVERIFIED
1752
+ * are REFUSED (E-DEMOTE-NOT-CONFIRMED), never silently returned as a
1753
+ * no-op, so a caller can never believe it lowered trust that was already
1754
+ * at the floor;
1755
+ * - promoted_at and source are left untouched. promote() stamps
1756
+ * source='promotion'; a demotion must not erase the provenance of the
1757
+ * promotion it is reversing, and promoted_at stays as the record of when
1758
+ * the (now withdrawn) trust was granted;
1759
+ * - a STALE entry MAY be demoted. Staleness is a freshness verdict, trust
1760
+ * is a separate axis, and the entries most worth demoting are exactly the
1761
+ * ones the sweep has already flagged;
1762
+ * - evidence is REQUIRED, like promote's resolvable basis: at least one
1763
+ * evidence file, each of which must resolve inside the anchor
1764
+ * (E-DEMOTE-EVIDENCE-UNRESOLVED otherwise).
1765
+ *
1766
+ * EVERY refusal is checked BEFORE any write, in the order below, and the
1767
+ * order is load-bearing: the own-scope/unknown-id check comes first so a
1768
+ * member can never learn that an entry it does not own exists by probing for
1769
+ * a different refusal message.
1770
+ */
1771
+ async demote(id, reason, evidenceFiles, opts) {
1772
+ const db = this.getDb();
1773
+ const row = db.prepare('SELECT * FROM entries WHERE id = ?').get(id);
1774
+ // (1) Unknown id. MEMBER own-scope: an entry the caller did not capture is
1775
+ // indistinguishable from an unknown id -- the SAME message as promote(),
1776
+ // so its existence is not disclosed.
1777
+ if (!row)
1778
+ throw new Error('Entry not found: ' + id);
1779
+ const entry = this.rowToEntry(row);
1780
+ if (opts?.ownerTag && !entry.tags.includes(opts.ownerTag))
1781
+ throw new Error('Entry not found: ' + id);
1782
+ // (2) Superseded: the row is already out of every read path, so lowering
1783
+ // its confidence would be a write with no observable meaning.
1784
+ if (entry.superseded_at) {
1785
+ throw new Error('E-DEMOTE-SUPERSEDED: cannot demote a superseded entry. Entry: ' + id);
1786
+ }
1787
+ // (3) user-directive: directives are human-terminal in BOTH directions.
1788
+ // promote() refuses them so kb_promote cannot forge an active directive;
1789
+ // demote() refuses them so an agent cannot deactivate one the human set.
1790
+ if (entry.type === 'user-directive') {
1791
+ throw new Error('E-DEMOTE-REFUSED-DIRECTIVE: cannot demote a user-directive via kb_demote: directive state is '
1792
+ + 'human-terminal only. Run `apra-fleet kb reject-directive ' + id + '` to discard it. Entry: ' + id);
1793
+ }
1794
+ // (4) Not CONFIRMED. A REFUSAL, not a no-op return: see the method comment.
1795
+ if (entry.confidence !== 'CONFIRMED') {
1796
+ throw new Error('E-DEMOTE-NOT-CONFIRMED: kb_demote lowers CONFIRMED to INFERRED only; this entry is '
1797
+ + entry.confidence + '. Entry: ' + id);
1798
+ }
1799
+ // (5) Reason floor, measured on the normalised reason -- so a reason made
1800
+ // only of newlines collapses to empty and is refused here.
1801
+ const normalizedReason = normalizeDemoteReason(reason);
1802
+ if (normalizedReason.length < MIN_DEMOTE_REASON_LENGTH) {
1803
+ throw new Error('E-DEMOTE-REASON-REQUIRED: kb_demote requires a reason recording why trust is being withdrawn '
1804
+ + '(at least ' + MIN_DEMOTE_REASON_LENGTH + ' characters after collapsing newlines and trimming). Entry: ' + id);
1805
+ }
1806
+ // (6) Evidence: REQUIRED, like promote's basis. Withdrawing trust needs a
1807
+ // resolvable reason to believe less, not only a written one.
1808
+ const evidence = evidenceFiles ?? [];
1809
+ if (evidence.length === 0) {
1810
+ throw new Error('E-DEMOTE-EVIDENCE-UNRESOLVED: kb_demote requires at least one evidence file backing the demotion '
1811
+ + '(evidence_files). Entry: ' + id);
1812
+ }
1813
+ this.assertResolvableDemoteEvidence(id, evidence);
1814
+ // --- no refusal remains: everything below writes ---
1815
+ const now = new Date().toISOString();
1816
+ // The note format (one leading newline, ASCII-safe concatenation, the
1817
+ // feedback-marker collision rule) lives in buildDemotionNote, shared with
1818
+ // the bible tombstone path so both demotions read identically.
1819
+ const demotionNote = buildDemotionNote(normalizedReason, evidence, entry.author);
1820
+ const newContent = truncateContent(entry.content + demotionNote);
1821
+ const confidence_before = entry.confidence;
1822
+ const confidence_after = 'INFERRED';
1823
+ // ONE update. promoted_at and source are deliberately absent from the SET.
1824
+ db.prepare('UPDATE entries SET confidence = ?, demoted_at = ?, demoted_basis_hashes = ?, content = ? WHERE id = ?').run(confidence_after, now, JSON.stringify(this.demoteBasisHashes(entry.source_files)), newContent, id);
1825
+ return { id, confidence_before, confidence_after };
1826
+ }
1827
+ /**
1828
+ * Apply ONE explicit demotion tombstone from a committed project bible to the
1829
+ * local row, so a demotion recorded on another clone actually lands here.
1830
+ *
1831
+ * Returns true only when a row was written. Every "no" is a silent false, not
1832
+ * a throw: a bible carries tombstones for the whole project and most clones
1833
+ * hold only some of those ids, so an inapplicable tombstone is the normal
1834
+ * case, not an error.
1835
+ *
1836
+ * The rules, each of which silently corrupts another clone's KB if got wrong:
1837
+ *
1838
+ * - NEVER CREATE. A tombstoned id with no local row stays absent. A
1839
+ * tombstone withdraws trust in a row; it is not a way to author one.
1840
+ * - ONE RE-PROMOTION RULE. Demote only when standingAgainstTombstone
1841
+ * (bible-import.ts) says 'withdrawn' for the row's bible trust time
1842
+ * (getBibleTrustTimes): promoted_at, else the updated_at the bible carried
1843
+ * at import -- never the local import time. kb_export uses the same rule to
1844
+ * decide whether to re-add a tombstoned entry, so the two never disagree.
1845
+ * - demoted_at is stamped with the TOMBSTONE's value, not now(): it records
1846
+ * when trust was withdrawn, which happened on the other clone. That value
1847
+ * is clamped to now (clampBibleTimeToNow), so a future-dated tombstone
1848
+ * never stores a demoted_at that every later re-promotion falls before.
1849
+ * - NO ownerTag CHECK. Bible-imported rows carry no member tag (see
1850
+ * importBibleEntries, which builds its input with tags: [] and author
1851
+ * 'unknown'), so an owner check here would make every imported row
1852
+ * permanently undemotable. The trust boundary for this path is the
1853
+ * git-reviewed bible file, not entry ownership.
1854
+ *
1855
+ * ABSENCE IS NEVER A DEMOTION: this method is only ever called for an id that
1856
+ * carries an EXPLICIT tombstone. A local CONFIRMED row merely missing from the
1857
+ * bible (a local-only promotion, or one refused by the basis filter) is never
1858
+ * passed here and must stay untouched.
1859
+ *
1860
+ * Two refusals are inherited from demote() because they are invariants of the
1861
+ * store, not of the local/remote distinction: a superseded row is already out
1862
+ * of every read path (the write would have no observable meaning), and a
1863
+ * user-directive is human-terminal in both directions -- a bible must not be
1864
+ * able to deactivate a directive a human set here.
1865
+ */
1866
+ applyBibleDemotion(id, tombstoneAt) {
1867
+ const db = this.getDb();
1868
+ const row = db.prepare('SELECT * FROM entries WHERE id = ?').get(id);
1869
+ // NEVER CREATE.
1870
+ if (!row)
1871
+ return false;
1872
+ const entry = this.rowToEntry(row);
1873
+ if (entry.confidence !== 'CONFIRMED')
1874
+ return false;
1875
+ if (entry.superseded_at)
1876
+ return false;
1877
+ if (entry.type === 'user-directive')
1878
+ return false;
1879
+ const demotedAt = clampBibleTimeToNow(tombstoneAt);
1880
+ if (standingAgainstTombstone(this.bibleTrustTimeOf(row), demotedAt) !== 'withdrawn')
1881
+ return false;
1882
+ const demotionNote = buildDemotionNote(BIBLE_DEMOTION_REASON, [], entry.author);
1883
+ const newContent = truncateContent(entry.content + demotionNote);
1884
+ // Same SET as demote(): promoted_at and source stay untouched, so the
1885
+ // provenance of the promotion being reversed survives.
1886
+ db.prepare('UPDATE entries SET confidence = ?, demoted_at = ?, demoted_basis_hashes = ?, content = ? WHERE id = ?').run('INFERRED', demotedAt, JSON.stringify(this.demoteBasisHashes(entry.source_files)), newContent, id);
1887
+ return true;
1888
+ }
1477
1889
  // T3.1 (F8, D7): kb_feedback downvote path -- marks an entry stale=1 +
1478
1890
  // flagged_for_review=1 and appends an ASCII feedback note. NEVER deletes,
1479
1891
  // NEVER touches confidence: a downvoted CONFIRMED entry stays
@@ -42,6 +42,8 @@ export interface KBEntry {
42
42
  created_at: string;
43
43
  superseded_at?: string;
44
44
  promoted_at?: string;
45
+ demoted_at?: string;
46
+ demoted_basis_hashes?: Record<string, string>;
45
47
  use_count: number;
46
48
  last_accessed?: string;
47
49
  }
@@ -51,6 +53,7 @@ export interface CaptureOpts {
51
53
  preferredId?: string;
52
54
  verbatim?: boolean;
53
55
  carriedBasis?: Record<string, string> | null;
56
+ carriedUpdatedAt?: string;
54
57
  keepConfirmed?: boolean;
55
58
  }
56
59
  /** SqliteProvider.capture() result. */
@@ -184,14 +187,23 @@ export interface MemoryProvider {
184
187
  audn_decision: AudnDecision;
185
188
  }>;
186
189
  query(opts: QueryOptions): Promise<KBResult>;
187
- context(files: string[], confidence?: Confidence[], excludeDisputed?: boolean): Promise<FileContextResult[]>;
190
+ context(files: string[], confidence?: Confidence[], excludeDisputed?: boolean, ownerTag?: string): Promise<FileContextResult[]>;
188
191
  invalidate(files: string[]): Promise<{
189
192
  invalidated: number;
190
193
  }>;
191
194
  discard(ids: string[], opts?: RetireOptions): Promise<DiscardResult>;
192
195
  getLinked(id: string): Promise<KBEntry[]>;
193
196
  prime(opts: PrimeOptions): Promise<PrimedContext>;
194
- promote(id: string, reason?: string): Promise<{
197
+ promote(id: string, reason?: string, opts?: {
198
+ ownerTag?: string;
199
+ }): Promise<{
200
+ id: string;
201
+ confidence_before: Confidence;
202
+ confidence_after: Confidence;
203
+ }>;
204
+ demote(id: string, reason: string, evidenceFiles: string[], opts?: {
205
+ ownerTag?: string;
206
+ }): Promise<{
195
207
  id: string;
196
208
  confidence_before: Confidence;
197
209
  confidence_after: Confidence;
@@ -201,6 +213,7 @@ export interface MemoryProvider {
201
213
  symbols?: string[];
202
214
  }): Promise<ProviderStats>;
203
215
  touch(ids: string[]): Promise<number>;
216
+ getLiveConfirmedState(ids: string[]): Map<string, boolean>;
204
217
  relatedClaims(ids: string[], limit?: number, filter?: EntryTrustFilter): Promise<KBEntry[]>;
205
218
  }
206
219
  //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,12 @@
1
+ /** Ends a busy period. `status` defaults to 'idle'; only the first call writes. */
2
+ export type ReleaseBusy = (status?: string) => void;
3
+ /**
4
+ * Mark a member busy in the statusline and return its release. Call the
5
+ * release on every exit path -- typically `release(errStatus)` in catch and
6
+ * a bare `release()` in finally: the first call wins, so an error path's
7
+ * 'offline' is never clobbered by the finally's 'idle'. Kept out of
8
+ * statusline.ts so modules that mock statusline.js still get a working
9
+ * helper (its writes go through their mocked writeStatusline).
10
+ */
11
+ export declare function markBusy(memberId: string): ReleaseBusy;
12
+ //# sourceMappingURL=member-busy.d.ts.map
@@ -0,0 +1,20 @@
1
+ import { writeStatusline } from './statusline.js';
2
+ /**
3
+ * Mark a member busy in the statusline and return its release. Call the
4
+ * release on every exit path -- typically `release(errStatus)` in catch and
5
+ * a bare `release()` in finally: the first call wins, so an error path's
6
+ * 'offline' is never clobbered by the finally's 'idle'. Kept out of
7
+ * statusline.ts so modules that mock statusline.js still get a working
8
+ * helper (its writes go through their mocked writeStatusline).
9
+ */
10
+ export function markBusy(memberId) {
11
+ writeStatusline(new Map([[memberId, 'busy']]));
12
+ let released = false;
13
+ return (status = 'idle') => {
14
+ if (released)
15
+ return;
16
+ released = true;
17
+ writeStatusline(new Map([[memberId, status]]));
18
+ };
19
+ }
20
+ //# sourceMappingURL=member-busy.js.map
@@ -10,8 +10,9 @@ export declare const LEGACY_MEMBER_MCP_SERVER_NAME = "apra-fleet-member";
10
10
  * The URL a member session uses to reach the fleet MCP server on its OWN
11
11
  * machine. `?member=<uuid>` identifies the session as that member, which is
12
12
  * what reduces the served tool list to the member allowlist. A local member
13
- * shares this process's server, so it follows this process's port (honoring
14
- * an APRA_FLEET_PORT sandbox); a remote member talks to its OWN install, on
13
+ * shares this process's server, so it follows the port that server binds
14
+ * (resolveServerPort: an APRA_FLEET_PORT sandbox, else the recorded install
15
+ * port); a remote member talks to its OWN install, on
15
16
  * the port that install records in its member-install marker
16
17
  * (agent.memberMcpPort, resolved on the member by the fleetMcp probe), or the
17
18
  * built-in default when it recorded none (the probe reports that in fleetMcp
@@ -15,7 +15,7 @@
15
15
  // single member-filesystem test double serves both.
16
16
  import { isPosixShell } from '../utils/agent-helpers.js';
17
17
  import { escapePowerShellArgInner } from '../utils/shell-escape.js';
18
- import { BUILTIN_DEFAULT_PORT, DEFAULT_PORT } from '../paths.js';
18
+ import { BUILTIN_DEFAULT_PORT, resolveServerPort } from '../paths.js';
19
19
  import { MEMBER_ALLOWED_TOOLS, MEMBER_DENIED_TOOLS } from './member-tool-allowlist.js';
20
20
  /** Name of the per-folder member MCP entry every provider writes. */
21
21
  export const MEMBER_MCP_SERVER_NAME = 'apra-fleet';
@@ -26,8 +26,9 @@ const FS_OP_TIMEOUT_MS = 15000;
26
26
  * The URL a member session uses to reach the fleet MCP server on its OWN
27
27
  * machine. `?member=<uuid>` identifies the session as that member, which is
28
28
  * what reduces the served tool list to the member allowlist. A local member
29
- * shares this process's server, so it follows this process's port (honoring
30
- * an APRA_FLEET_PORT sandbox); a remote member talks to its OWN install, on
29
+ * shares this process's server, so it follows the port that server binds
30
+ * (resolveServerPort: an APRA_FLEET_PORT sandbox, else the recorded install
31
+ * port); a remote member talks to its OWN install, on
31
32
  * the port that install records in its member-install marker
32
33
  * (agent.memberMcpPort, resolved on the member by the fleetMcp probe), or the
33
34
  * built-in default when it recorded none (the probe reports that in fleetMcp
@@ -35,7 +36,9 @@ const FS_OP_TIMEOUT_MS = 15000;
35
36
  * get their own server, never the other user's.
36
37
  */
37
38
  export function memberMcpUrl(agent) {
38
- const port = agent.agentType === 'local' ? DEFAULT_PORT : (agent.memberMcpPort ?? BUILTIN_DEFAULT_PORT);
39
+ // Local: the port this server binds (env, else the recorded member/full
40
+ // install port, else the default) -- the same source http-transport uses.
41
+ const port = agent.agentType === 'local' ? resolveServerPort() : (agent.memberMcpPort ?? BUILTIN_DEFAULT_PORT);
39
42
  return `http://localhost:${port}/mcp?member=${encodeURIComponent(agent.id)}`;
40
43
  }
41
44
  /** Claude permission deny rules: every registered fleet tool outside the member
@@ -181,6 +181,7 @@ export function isMemberOutdated(memberVersion, orchestratorVersion, canSupplyOr
181
181
  /** Release asset names published by .github/workflows/ci.yml, by platform. */
182
182
  export const RELEASE_ASSETS = {
183
183
  'linux/x64': 'apra-fleet-installer-linux-x64',
184
+ 'linux/arm64': 'apra-fleet-installer-linux-arm64',
184
185
  'macos/arm64': 'apra-fleet-installer-darwin-arm64',
185
186
  'macos/x64': 'apra-fleet-installer-darwin-x64',
186
187
  'windows/x64': 'apra-fleet-installer-win-x64.exe',
@@ -17,7 +17,7 @@ export declare const MEMBER_TOOL_PREFIXES: readonly string[];
17
17
  export declare const MEMBER_BASE_TOOLS: readonly string[];
18
18
  /**
19
19
  * Tools served ONLY to a kb_maintainer member session (the engine's grant), on
20
- * top of the base allowlist. They mint CONFIRMED. Not part of
20
+ * top of the base allowlist. They mint CONFIRMED, or (kb_demote) withdraw it. Not part of
21
21
  * MEMBER_ALLOWED_TOOLS, so client-side deny rules keep them denied for every
22
22
  * agent session on a member.
23
23
  */