@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
@@ -6,10 +6,11 @@ import { getKbProviders } from '../services/knowledge/kb-providers.js';
6
6
  import { resolveKbAnchor } from '../services/knowledge/kb-self.js';
7
7
  import { filterProjectBibleCandidates, hasCarriedBasis, selectLegacyBibleBackfill } from '../services/knowledge/bible-basis-filter.js';
8
8
  import { logWarn } from '../utils/log-helpers.js';
9
- import { requireSqliteProject } from '../services/knowledge/require-sqlite-project.js';
9
+ import { isSqliteProject } from '../services/knowledge/require-sqlite-project.js';
10
+ import { TOMBSTONE_DEMOTED, standingAgainstTombstone } from '../services/knowledge/bible-import.js';
10
11
  import { bibleBytesBlobId } from '../services/knowledge/bible-blob-id.js';
11
12
  import { memberLacksKbMaintainer } from '../services/knowledge/kb-maintainer-grant.js';
12
- import { asciiSafeStringify, assertNoDuplicateBibleIds, BIBLE_FORMAT_VERSION, bibleContentChanged, commitBiblePath, compareById, isGitRepo, readBibleEntries, requireLocalFolder, toCanonicalEntry, withSourceFileHashes, } from './kb-export.js';
13
+ import { asciiSafeStringify, assertNoDuplicateBibleIds, BIBLE_FORMAT_VERSION, bibleContentChanged, commitBiblePath, compareById, isGitRepo, readBibleDocument, requireLocalFolder, toCanonicalEntry, withSourceFileHashes, } from './kb-export.js';
13
14
  // kb_bible_commit: the kb_maintainer commits one review round's confirmations
14
15
  // to the bible, merging at ENTRY level: the given ids are added or replaced,
15
16
  // and every entry already in <self>/.fleet/kb-canonical.json is kept UNLESS
@@ -51,6 +52,8 @@ import { asciiSafeStringify, assertNoDuplicateBibleIds, BIBLE_FORMAT_VERSION, bi
51
52
  export const kbBibleCommitSchema = z.object({
52
53
  ids: z.array(z.string().min(1))
53
54
  .describe('Ids of the entries confirmed this round. Each must be a live (non-stale, non-superseded) CONFIRMED entry in this repository\'s KB whose recorded file basis still matches the cited files at the repo\'s HEAD commit (the same rule kb_export applies; uncommitted edits are ignored); any other id is skipped and reported in skipped (reason not_confirmed_or_unknown, no_source_files for a CONFIRMED entry citing no source file, or basis_mismatch). Independently of the ids, every bible entry this KB holds as superseded or invalidated is removed and reported in removed; an empty list with no such entry makes no commit.'),
55
+ demoted_ids: z.array(z.string().min(1)).optional()
56
+ .describe('Ids demoted this round (kb_demote). Each must name a local entry that HAS a demoted_at and is now below CONFIRMED; any other id is skipped and reported in skipped with reason not_demoted_or_unknown. An admitted id is REMOVED from entries and recorded as an explicit tombstone {id, at, reason: "demoted"} in the bible demotions array, so other clones can apply the demotion instead of inferring it from an absence. Independently, every call does the same for each bible entry this KB holds as demoted, unless that bible entry was promoted after the local demotion (another clone re-promoted it). Re-admitting the same id through ids (a re-promotion) clears its tombstone.'),
54
57
  baseBranch: z.string().min(1)
55
58
  .describe('The sprint\'s target base branch (the branch the work merges into). Written to provenance.branch.'),
56
59
  baseCommit: z.string().min(1)
@@ -59,20 +62,46 @@ export const kbBibleCommitSchema = z.object({
59
62
  // is refused with E-SCOPE-KEY-REMOVED instead of silently re-scoped.
60
63
  ...KB_REMOVED_SCOPE_KEYS_SHAPE,
61
64
  });
65
+ /** Reason reported when kb_bible_commit is skipped under the http KB provider. */
66
+ export const KB_BIBLE_COMMIT_HTTP_SKIP_REASON = 'bible commit is not supported over the http KB provider';
62
67
  export async function kbBibleCommit(input, anchor) {
63
68
  const resolved = resolveKbAnchor(anchor);
64
69
  const repoPath = requireLocalFolder(resolved.folder, 'kb_bible_commit');
65
70
  const outPath = path.join(repoPath, '.fleet', 'kb-canonical.json');
66
71
  const requested = Array.from(new Set(input.ids));
72
+ // An id named in BOTH lists is a caller bug, and admitting it twice would make
73
+ // the outcome depend on merge order. ids (a confirmation) wins: a re-promoted
74
+ // entry belongs in the bible, and the demotion half is reported as skipped by
75
+ // the normal not_demoted_or_unknown rule below (it is CONFIRMED, not demoted).
76
+ const requestedDemotions = Array.from(new Set(input.demoted_ids ?? []));
67
77
  const done = (r) => JSON.stringify({ path: outPath, ...r });
68
- // No ids and no bible entry that could be removed: nothing to do, and the
69
- // KB is not opened.
70
- const existingAtStart = readBibleEntries(outPath);
71
- if (requested.length === 0 && (existingAtStart === null || existingAtStart.length === 0)) {
72
- return done({ merged: [], skipped: [], removed: [], entry_count: existingAtStart?.length ?? 0, backfilled: 0, committed: false });
78
+ // No ids, no demotions and no bible entry that could be removed: nothing to
79
+ // do, and the KB is not opened.
80
+ const existingDoc = readBibleDocument(outPath);
81
+ const existingAtStart = existingDoc?.entries ?? null;
82
+ if (requested.length === 0 && requestedDemotions.length === 0
83
+ && (existingAtStart === null || existingAtStart.length === 0)) {
84
+ return done({
85
+ merged: [], demoted: [], skipped: [], removed: [],
86
+ entry_count: existingAtStart?.length ?? 0, backfilled: 0, committed: false,
87
+ });
73
88
  }
74
89
  const providers = await getKbProviders(repoPath, resolved.remoteUrl);
75
- const project = requireSqliteProject(providers.project, 'kb_bible_commit');
90
+ const project = providers.project;
91
+ if (!isSqliteProject(project)) {
92
+ // The bible is built from the local SQLite store; over http there is
93
+ // nothing to merge. Skip before any KB read, write, or git commit. The
94
+ // bible file was only read leniently above (readBibleEntries never
95
+ // throws): entry_count reports its size when parseable, and an unparseable
96
+ // file is logged, never thrown over -- the skip is provider-wide.
97
+ if (existingAtStart === null && fs.existsSync(outPath)) {
98
+ logWarn('kb_bible_commit', 'bible file is not readable, reporting entry_count 0 under the http KB provider: ' + outPath);
99
+ }
100
+ return done({
101
+ merged: [], demoted: [], skipped: [], removed: [], entry_count: existingAtStart?.length ?? 0, backfilled: 0, committed: false,
102
+ bible_skipped: true, reason: KB_BIBLE_COMMIT_HTTP_SKIP_REASON,
103
+ });
104
+ }
76
105
  const confirmedEntries = await project.list({ confidence: ['CONFIRMED'] });
77
106
  const requestedSet = new Set(requested);
78
107
  // ONE admission rule with kb_export (scope=project): a CONFIRMED id is
@@ -90,8 +119,9 @@ export async function kbBibleCommit(input, anchor) {
90
119
  const confirmed = new Map();
91
120
  // Format v3: each merged entry carries the exact stored basis it was just
92
121
  // admitted against (never re-hashed here).
122
+ const trustTimes = project.getBibleTrustTimes(qualifying.map(e => e.id));
93
123
  for (const e of qualifying)
94
- confirmed.set(e.id, toCanonicalEntry(e, bases.get(e.id)));
124
+ confirmed.set(e.id, toCanonicalEntry(e, bases.get(e.id), trustTimes.get(e.id)));
95
125
  const merged = [];
96
126
  const skipped = [];
97
127
  for (const id of requested) {
@@ -110,12 +140,53 @@ export async function kbBibleCommit(input, anchor) {
110
140
  else
111
141
  skipped.push({ id, reason: 'not_confirmed_or_unknown' });
112
142
  }
143
+ // DEMOTION ADMISSION. A tombstone asserts "this clone withdrew trust", so the
144
+ // local row must actually say so: it exists, it carries a demoted_at, and its
145
+ // confidence is now below CONFIRMED. The state is read straight from the row
146
+ // (not through list()) so a demoted entry that has since gone stale can still
147
+ // be tombstoned: other clones' bibles still carry it.
148
+ //
149
+ // Two sources, one rule. A demoted_ids id that does not qualify -- unknown,
150
+ // never demoted, or demoted and since re-promoted -- is skipped with a reason.
151
+ // And on EVERY call, each entry already in the bible that this KB holds as
152
+ // demoted is tombstoned too, named or not: that is what restores a demotion
153
+ // after an older writer (0.4.4) rewrote the bible without its tombstones.
154
+ // Except when the bible entry was promoted AFTER this clone's demotion (same
155
+ // standingAgainstTombstone rule; a bible time later than now never counts):
156
+ // another clone re-promoted it, and tombstoning it again would undo that
157
+ // re-promotion.
158
+ const bibleEntries = existingDoc?.entries ?? [];
159
+ const bibleIds = bibleEntries.map(e => e.id);
160
+ const demotionState = project.getDemotionState([...requestedDemotions, ...bibleIds]);
161
+ const tombstoneFor = (id) => {
162
+ const state = demotionState.get(id);
163
+ if (!state || !state.demoted_at || state.confidence === 'CONFIRMED' || qualifyingIds.has(id))
164
+ return null;
165
+ return { id, at: state.demoted_at, reason: TOMBSTONE_DEMOTED };
166
+ };
167
+ const admittedDemotions = [];
168
+ for (const id of requestedDemotions) {
169
+ const tombstone = tombstoneFor(id);
170
+ if (tombstone)
171
+ admittedDemotions.push(tombstone);
172
+ else
173
+ skipped.push({ id, reason: 'not_demoted_or_unknown' });
174
+ }
175
+ const requestedDemotionSet = new Set(requestedDemotions);
176
+ for (const entry of bibleEntries) {
177
+ if (requestedDemotionSet.has(entry.id))
178
+ continue;
179
+ const tombstone = tombstoneFor(entry.id);
180
+ if (tombstone && !repromotedAfter(entry, tombstone))
181
+ admittedDemotions.push(tombstone);
182
+ }
183
+ const demoted = admittedDemotions.map(d => d.id);
113
184
  // A bible file that exists but cannot be parsed must not be overwritten: its
114
185
  // entries are unknown, and writing over it would drop all of them.
115
- const existing = existingAtStart;
116
- if (existing === null && fs.existsSync(outPath)) {
186
+ if (existingDoc === null && fs.existsSync(outPath)) {
117
187
  throw new Error('kb_bible_commit: existing bible is not a readable bible file, refusing to overwrite it: ' + outPath);
118
188
  }
189
+ const existing = existingDoc?.entries ?? null;
119
190
  // Removals: a bible entry this KB holds as superseded or invalidated. An id
120
191
  // unknown to this KB, or known and not retired, is kept. A merged id is never
121
192
  // retired (merging requires a live CONFIRMED entry), so the two never clash.
@@ -140,8 +211,8 @@ export async function kbBibleCommit(input, anchor) {
140
211
  }
141
212
  }
142
213
  const backfilled = backfill.size;
143
- if (merged.length === 0 && removed.length === 0 && backfilled === 0) {
144
- return done({ merged, skipped, removed, entry_count: existing?.length ?? 0, backfilled, committed: false });
214
+ if (merged.length === 0 && removed.length === 0 && admittedDemotions.length === 0 && backfilled === 0) {
215
+ return done({ merged, demoted, skipped, removed, entry_count: existing?.length ?? 0, backfilled, committed: false });
145
216
  }
146
217
  // Duplicate-id guard: an existing file holding one id twice would otherwise
147
218
  // be silently collapsed by the id map below (dropping an entry). Refuse
@@ -156,28 +227,51 @@ export async function kbBibleCommit(input, anchor) {
156
227
  byId.delete(r.id);
157
228
  for (const id of merged)
158
229
  byId.set(id, confirmed.get(id));
230
+ // An admitted demotion REMOVES the entry.
231
+ for (const id of demoted)
232
+ byId.delete(id);
159
233
  const entries = Array.from(byId.values()).sort(compareById);
160
234
  assertNoDuplicateBibleIds(entries, 'kb_bible_commit');
161
- // Entries unchanged is a no-op: no rewrite, no commit (provenance alone never
162
- // counts as a change, matching kb_export).
163
- if (existing !== null && asciiSafeStringify(existing) === asciiSafeStringify(entries)) {
164
- return done({ merged, skipped, removed, entry_count: entries.length, backfilled, committed: false });
235
+ // TOMBSTONE MERGE. Tombstones already in the file are PRESERVED (a later
236
+ // commit carrying unrelated ids must not silently resurrect their entries on
237
+ // other clones), the admitted ones are upserted, and an id re-admitted as a
238
+ // CONFIRMED entry has its tombstone CLEARED -- it was re-promoted, so the
239
+ // demotion no longer holds.
240
+ const tombstones = new Map();
241
+ for (const d of existingDoc?.demotions ?? [])
242
+ tombstones.set(d.id, d);
243
+ for (const d of admittedDemotions)
244
+ tombstones.set(d.id, d);
245
+ for (const id of merged)
246
+ tombstones.delete(id);
247
+ const demotions = Array.from(tombstones.values()).sort(compareById);
248
+ // Unchanged content is a no-op: no rewrite, no commit (provenance alone never
249
+ // counts as a change, matching kb_export). Both halves count as content.
250
+ const demotionsUnchanged = asciiSafeStringify(existingDoc?.demotions ?? [])
251
+ === asciiSafeStringify(demotions);
252
+ if (existing !== null && demotionsUnchanged
253
+ && asciiSafeStringify(existing) === asciiSafeStringify(entries)) {
254
+ return done({ merged, demoted, skipped, removed, entry_count: entries.length, backfilled, committed: false });
165
255
  }
166
256
  const bible = {
167
257
  version: BIBLE_FORMAT_VERSION,
168
258
  provenance: {
169
259
  commit: input.baseCommit,
170
260
  branch: input.baseBranch,
261
+ // Entries only -- a tombstone is not an entry.
171
262
  entry_count: entries.length,
172
263
  },
173
264
  entries,
265
+ // Omitted entirely when there are none, so a bible that never saw a
266
+ // demotion stays byte-identical to one written before the field existed.
267
+ ...(demotions.length > 0 ? { demotions } : {}),
174
268
  };
175
269
  fs.mkdirSync(path.dirname(outPath), { recursive: true });
176
270
  const written = Buffer.from(asciiSafeStringify(bible) + '\n', 'utf-8');
177
271
  fs.writeFileSync(outPath, written);
178
272
  let committed = false;
179
273
  if (isGitRepo(repoPath) && bibleContentChanged(repoPath, outPath)) {
180
- const message = bibleCommitMessage(merged.length, removed, entries.length, backfilled);
274
+ const message = bibleCommitMessage(merged.length, removed, entries.length, backfilled, demoted.length);
181
275
  try {
182
276
  commitBiblePath(repoPath, outPath, message);
183
277
  }
@@ -200,32 +294,47 @@ export async function kbBibleCommit(input, anchor) {
200
294
  // run the checkout's member-configured clean filters.
201
295
  project.recordTrustedBibleBlob(await bibleBytesBlobId(repoPath, written), 'kb_bible_commit');
202
296
  }
203
- return done({ merged, skipped, removed, entry_count: entries.length, backfilled, committed });
297
+ return done({ merged, demoted, skipped, removed, entry_count: entries.length, backfilled, committed });
298
+ }
299
+ /**
300
+ * True when the bible entry's own updated_at postdates the local demotion. An
301
+ * updated_at later than now is NOT a re-promotion: clamping it to now would
302
+ * still put it after every past demoted_at, so a future-dated entry would block
303
+ * the tombstone forever.
304
+ */
305
+ function repromotedAfter(entry, tombstone, now = new Date()) {
306
+ if (typeof entry.updated_at !== 'string' || entry.updated_at.length === 0)
307
+ return false;
308
+ const updatedAt = Date.parse(entry.updated_at);
309
+ if (Number.isNaN(updatedAt) || updatedAt > now.getTime())
310
+ return false;
311
+ return standingAgainstTombstone(entry.updated_at, tombstone.at) === 'repromoted';
204
312
  }
205
313
  /**
206
- * The bible commit message. The subject counts merged and removed entries;
207
- * when entries were removed, the body lists each one as '- <id> (<reason>)'.
208
- * With no removals and no backfill the message is the single pre-existing
209
- * subject line. A legacy backfill (existing entries that gained
210
- * source_file_hashes) adds a body line 'Backfilled source_file_hashes on <n>
211
- * existing entries.'; a backfill-only commit names the count in its own subject.
314
+ * The bible commit message. The subject counts merged, removed and demoted
315
+ * entries; when entries were removed, the body lists each one as
316
+ * '- <id> (<reason>)'. With no removals and no backfill the message is the
317
+ * single pre-existing subject line. A legacy backfill (existing entries that
318
+ * gained source_file_hashes) adds a body line 'Backfilled source_file_hashes on
319
+ * <n> existing entries.'; a backfill-only commit names the count in its own subject.
212
320
  */
213
- export function bibleCommitMessage(mergedCount, removed, total, backfilled = 0) {
214
- let subject;
321
+ export function bibleCommitMessage(mergedCount, removed, total, backfilled = 0, demotedCount = 0) {
322
+ let head;
215
323
  if (mergedCount === 0 && removed.length === 0 && backfilled > 0) {
216
- subject = 'chore(kb): backfill source_file_hashes on ' + backfilled + ' knowledge bible entries -- ' + total + ' total';
324
+ head = 'chore(kb): backfill source_file_hashes on ' + backfilled + ' knowledge bible entries';
217
325
  }
218
326
  else if (removed.length === 0) {
219
- subject = 'chore(kb): commit ' + mergedCount + ' confirmed entries to the knowledge bible -- ' + total + ' total';
327
+ head = 'chore(kb): commit ' + mergedCount + ' confirmed entries to the knowledge bible';
220
328
  }
221
329
  else if (mergedCount === 0) {
222
- subject = 'chore(kb): remove ' + removed.length + ' superseded/invalidated entries from the knowledge bible -- '
223
- + total + ' total';
330
+ head = 'chore(kb): remove ' + removed.length + ' superseded/invalidated entries from the knowledge bible';
224
331
  }
225
332
  else {
226
- subject = 'chore(kb): commit ' + mergedCount + ' confirmed entries to the knowledge bible, remove '
227
- + removed.length + ' superseded/invalidated -- ' + total + ' total';
333
+ head = 'chore(kb): commit ' + mergedCount + ' confirmed entries to the knowledge bible, remove '
334
+ + removed.length + ' superseded/invalidated';
228
335
  }
336
+ const demotedClause = demotedCount > 0 ? ', ' + demotedCount + ' demoted' : '';
337
+ const subject = head + demotedClause + ' -- ' + total + ' total';
229
338
  const body = [];
230
339
  if (removed.length > 0)
231
340
  body.push('Removed:\n' + removed.map(r => '- ' + r.id + ' (' + r.reason + ')').join('\n'));
@@ -24,13 +24,13 @@ export declare const kbCaptureSchema: z.ZodObject<{
24
24
  summary: string;
25
25
  tags?: string[] | undefined;
26
26
  role?: string | undefined;
27
+ scope?: "project" | "global" | undefined;
27
28
  repo?: unknown;
28
29
  source_files?: string[] | undefined;
29
30
  symbols?: string[] | undefined;
30
31
  module?: string | undefined;
31
32
  supersedes?: string | undefined;
32
33
  confidence?: "CONFIRMED" | "INFERRED" | "UNVERIFIED" | undefined;
33
- scope?: "project" | "global" | undefined;
34
34
  repo_path?: unknown;
35
35
  repo_remote_url?: unknown;
36
36
  source_file?: string | undefined;
@@ -41,13 +41,13 @@ export declare const kbCaptureSchema: z.ZodObject<{
41
41
  summary: string;
42
42
  tags?: string[] | undefined;
43
43
  role?: string | undefined;
44
+ scope?: "project" | "global" | undefined;
44
45
  repo?: unknown;
45
46
  source_files?: string[] | undefined;
46
47
  symbols?: string[] | undefined;
47
48
  module?: string | undefined;
48
49
  supersedes?: string | undefined;
49
50
  confidence?: "CONFIRMED" | "INFERRED" | "UNVERIFIED" | undefined;
50
- scope?: "project" | "global" | undefined;
51
51
  repo_path?: unknown;
52
52
  repo_remote_url?: unknown;
53
53
  source_file?: string | undefined;
@@ -1,7 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { KB_REMOVED_SCOPE_KEYS_SHAPE } from '../services/knowledge/kb-removed-scope-keys.js';
3
- import { getSelfReadKb } from '../services/knowledge/kb-self.js';
4
- import { requireSqliteProject } from '../services/knowledge/require-sqlite-project.js';
3
+ import { getSelfReadKb, getMemberSplitRead, } from '../services/knowledge/kb-self.js';
5
4
  import { validateFilePaths } from '../services/knowledge/path-validation.js';
6
5
  export const kbContextSchema = z.object({
7
6
  confidence: z.array(z.enum(['CONFIRMED', 'INFERRED', 'UNVERIFIED'])).min(1).optional()
@@ -37,44 +36,65 @@ export async function kbContext(input, anchor) {
37
36
  const confidence = (explicit ?? [...KB_CONTEXT_DEFAULT_CONFIDENCE]);
38
37
  // Default-trusted read: undisputed unless a tier list is given.
39
38
  const excludeDisputed = explicit === undefined;
40
- // MEMBER session -> the checkout bible view (kb-self.ts getSelfReadKb) for
41
- // the CONFIRMED tier; an INFERRED/UNVERIFIED request goes to the per-repo DB,
42
- // own captures only (ownerTag).
39
+ // MEMBER session whose tier list (explicit, or the default above) names
40
+ // CONFIRMED plus another tier: the split read (kb-self.ts
41
+ // getMemberSplitRead). The checkout bible's CONFIRMED entries are merged per
42
+ // file (best status wins) with the member's OWN captures from the per-repo
43
+ // DB, so the other tiers never expose another member's captures and never
44
+ // hide the bible's. This is also the MEMBER default read. Under an http
45
+ // project provider both halves are the KB server: every
46
+ // CONFIRMED summary, plus the member's own.
47
+ const split = await getMemberSplitRead(anchor, confidence, 'kb_context');
48
+ if (split)
49
+ return JSON.stringify(partition(await splitContext(split, input.files, explicit, excludeDisputed)));
50
+ // Everything else (kb-self.ts getSelfReadKb): a MEMBER CONFIRMED-only
51
+ // request reads the checkout bible view; a MEMBER request naming only
52
+ // INFERRED/UNVERIFIED goes to the per-repo DB, own captures only (ownerTag).
53
+ // Under an http project provider every MEMBER read goes to the server; an INFERRED/UNVERIFIED request keeps ownerTag, enforced by
54
+ // either provider.
43
55
  const read = await getSelfReadKb(anchor, explicit);
44
56
  const { providers } = read;
45
57
  let results;
46
- if (explicit === undefined && read.memberView) {
47
- // MEMBER default: the checkout bible's CONFIRMED entries merged with the
48
- // member's OWN CONFIRMED/INFERRED captures from the per-repo DB, so the
49
- // INFERRED half of the default never exposes another member's captures and
50
- // never hides the bible's.
51
- const own = await getSelfReadKb(anchor, confidence);
52
- const fromBible = await providers.project.context(input.files, ['CONFIRMED'], excludeDisputed);
53
- const fromOwn = await requireSqliteProject(own.providers.project, 'kb_context')
54
- .context(input.files, confidence, excludeDisputed, own.ownerTag);
55
- results = mergeByFile(fromBible, fromOwn);
56
- }
57
- else if (read.ownerTag !== undefined) {
58
- results = await requireSqliteProject(providers.project, 'kb_context').context(input.files, confidence, excludeDisputed, read.ownerTag);
58
+ if (read.ownerTag !== undefined) {
59
+ results = await providers.project.context(input.files, confidence, excludeDisputed, read.ownerTag);
59
60
  }
60
61
  else {
61
62
  results = await providers.project.context(input.files, confidence, excludeDisputed);
62
63
  }
63
64
  // Fallback to global if project has no results
64
- const hasFresh = results.some(r => r.status === 'fresh');
65
- if (!hasFresh) {
66
- // A MEMBER default read keeps the global fallback CONFIRMED-only: the global
67
- // KB is machine-wide, so its INFERRED tier is not the member's own.
68
- const globalTiers = explicit === undefined && read.memberView ? ['CONFIRMED'] : confidence;
69
- const globalResults = await providers.global.context(input.files, globalTiers, excludeDisputed, read.ownerTag);
70
- const hasFreshGlobal = globalResults.some(r => r.status === 'fresh');
71
- if (hasFreshGlobal) {
65
+ if (!results.some(r => r.status === 'fresh')) {
66
+ const globalResults = await providers.global.context(input.files, confidence, excludeDisputed, read.ownerTag);
67
+ if (globalResults.some(r => r.status === 'fresh'))
72
68
  results = globalResults;
69
+ }
70
+ return JSON.stringify(partition(results));
71
+ }
72
+ async function splitContext(split, files, explicit, excludeDisputed) {
73
+ const { ownerTag } = split.own;
74
+ // The own half asks for every requested tier (CONFIRMED included),
75
+ // owner-tagged, so a cache entry the member promoted in the per-repo DB
76
+ // still counts, for the default and an explicit list alike.
77
+ const fromBible = await split.bible.project.context(files, split.bible.tiers, excludeDisputed);
78
+ const fromOwn = await split.own.project.context(files, split.own.tiers, excludeDisputed, ownerTag);
79
+ let results = mergeByFile(fromBible, fromOwn);
80
+ // Fallback to global if project has no results. The global KB is
81
+ // machine-wide, so its non-CONFIRMED tiers are not the member's own: the
82
+ // default read keeps the fallback CONFIRMED-only; an explicit list adds the
83
+ // member's own global captures for the other tiers.
84
+ if (!results.some(r => r.status === 'fresh')) {
85
+ let globalResults = await split.bible.global.context(files, split.bible.tiers, excludeDisputed);
86
+ if (explicit !== undefined) {
87
+ globalResults = mergeByFile(globalResults, await split.own.global.context(files, split.own.tiers, excludeDisputed, ownerTag));
73
88
  }
89
+ if (globalResults.some(r => r.status === 'fresh'))
90
+ results = globalResults;
74
91
  }
92
+ return results;
93
+ }
94
+ function partition(results) {
75
95
  const fresh = results.filter(r => r.status === 'fresh');
76
96
  const stale = results.filter(r => r.status === 'stale');
77
97
  const missing = results.filter(r => r.status === 'missing').map(r => r.file);
78
- return JSON.stringify({ fresh, stale, missing });
98
+ return { fresh, stale, missing };
79
99
  }
80
100
  //# sourceMappingURL=kb-context.js.map
@@ -0,0 +1,27 @@
1
+ import { z } from 'zod';
2
+ import { type KbAnchor } from '../services/knowledge/kb-self.js';
3
+ export declare const kbDemoteSchema: z.ZodObject<{
4
+ repo_path: z.ZodOptional<z.ZodUnknown>;
5
+ repo: z.ZodOptional<z.ZodUnknown>;
6
+ repo_remote_url: z.ZodOptional<z.ZodUnknown>;
7
+ id: z.ZodString;
8
+ reason: z.ZodString;
9
+ evidence_files: z.ZodArray<z.ZodString, "many">;
10
+ }, "strip", z.ZodTypeAny, {
11
+ id: string;
12
+ reason: string;
13
+ evidence_files: string[];
14
+ repo?: unknown;
15
+ repo_path?: unknown;
16
+ repo_remote_url?: unknown;
17
+ }, {
18
+ id: string;
19
+ reason: string;
20
+ evidence_files: string[];
21
+ repo?: unknown;
22
+ repo_path?: unknown;
23
+ repo_remote_url?: unknown;
24
+ }>;
25
+ export type KbDemoteInput = z.infer<typeof kbDemoteSchema>;
26
+ export declare function kbDemote(input: KbDemoteInput, anchor?: KbAnchor): Promise<string>;
27
+ //# sourceMappingURL=kb-demote.d.ts.map
@@ -0,0 +1,37 @@
1
+ import { z } from 'zod';
2
+ import { KB_REMOVED_SCOPE_KEYS_SHAPE } from '../services/knowledge/kb-removed-scope-keys.js';
3
+ import { getSelfKbProviders, memberOwnerTag } from '../services/knowledge/kb-self.js';
4
+ export const kbDemoteSchema = z.object({
5
+ id: z.string().min(1).describe('ID of the KB entry to demote'),
6
+ reason: z.string().min(1)
7
+ .describe('Why trust is being withdrawn -- at least 20 characters after newlines are collapsed to spaces and the result trimmed. Appended to the entry content as the audit trail; a reason made only of whitespace or newlines is refused.'),
8
+ evidence_files: z.array(z.string()).min(1)
9
+ .describe('At least one repo-relative file backing the demotion; an absent or empty list is refused by input validation before the tool runs. Each must resolve to a real file inside the calling session\'s repo; a path that does not resolve, names a directory, is ABSOLUTE, or contains a ".." segment is refused with E-DEMOTE-EVIDENCE-UNRESOLVED and nothing is written.'),
10
+ // Removed pre-redesign scope keys: declared only so a caller still passing one
11
+ // is refused with E-SCOPE-KEY-REMOVED instead of silently re-scoped.
12
+ ...KB_REMOVED_SCOPE_KEYS_SHAPE,
13
+ });
14
+ // The inverse of kb_promote: lower a CONFIRMED entry back to INFERRED when it
15
+ // turned out to be LESS CERTAIN than its CONFIRMED grade claims -- not when it
16
+ // turned out to be WRONG (that is kb_feedback / kb_resolve_contradiction).
17
+ //
18
+ // Mirrors kb-promote.ts exactly on scoping: in a MEMBER session over SQLite
19
+ // only the caller's own captures (member:<uuid>) are reachable, and any other
20
+ // id is the same not-found an unknown id gets, so an entry's existence is
21
+ // never disclosed. The provider enforces that; this layer only supplies the
22
+ // tag. Over http the demote is sent by id only when the KB server lists the
23
+ // optional demote route in its capabilities (E-KB-HTTP-UNSUPPORTED otherwise),
24
+ // and the server enforces which ids the caller may demote.
25
+ export async function kbDemote(input, anchor) {
26
+ const providers = await getSelfKbProviders(anchor);
27
+ const ownerTag = memberOwnerTag(anchor);
28
+ const result = ownerTag !== undefined
29
+ ? await providers.project.demote(input.id, input.reason, input.evidence_files, { ownerTag })
30
+ : await providers.project.demote(input.id, input.reason, input.evidence_files);
31
+ return JSON.stringify({
32
+ id: result.id,
33
+ previous_confidence: result.confidence_before,
34
+ new_confidence: result.confidence_after,
35
+ });
36
+ }
37
+ //# sourceMappingURL=kb-demote.js.map
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { type KbAnchor } from '../services/knowledge/kb-self.js';
3
+ import { type BibleTombstone } from '../services/knowledge/bible-import.js';
3
4
  import type { KBEntry } from '../services/knowledge/types.js';
4
5
  export declare const kbExportSchema: z.ZodObject<{
5
6
  repo_path: z.ZodOptional<z.ZodUnknown>;
@@ -9,15 +10,15 @@ export declare const kbExportSchema: z.ZodObject<{
9
10
  baseBranch: z.ZodOptional<z.ZodString>;
10
11
  baseCommit: z.ZodOptional<z.ZodString>;
11
12
  }, "strip", z.ZodTypeAny, {
12
- repo?: unknown;
13
13
  scope?: "project" | "global" | undefined;
14
+ repo?: unknown;
14
15
  repo_path?: unknown;
15
16
  repo_remote_url?: unknown;
16
17
  baseBranch?: string | undefined;
17
18
  baseCommit?: string | undefined;
18
19
  }, {
19
- repo?: unknown;
20
20
  scope?: "project" | "global" | undefined;
21
+ repo?: unknown;
21
22
  repo_path?: unknown;
22
23
  repo_remote_url?: unknown;
23
24
  baseBranch?: string | undefined;
@@ -55,9 +56,24 @@ export interface CanonicalBible {
55
56
  /** 40-char HEAD sha, or null when the repo has no commits or git is absent. */
56
57
  commit: string | null;
57
58
  branch: string | null;
59
+ /**
60
+ * ENTRIES ONLY. A tombstone is not an entry, so recording a demotion never
61
+ * moves this number -- it still names how many entries the file carries.
62
+ */
58
63
  entry_count: number;
59
64
  };
60
65
  entries: CanonicalEntry[];
66
+ /**
67
+ * OPTIONAL tombstones {id, at, reason}, sorted by id. v3 only. Absent when the
68
+ * bible carries none, so a reader that does not know the field (and every
69
+ * bible written before it existed) keeps working unchanged.
70
+ */
71
+ demotions?: BibleTombstone[];
72
+ }
73
+ /** Entries AND tombstones of a bible already on disk. */
74
+ export interface CanonicalBibleDocument {
75
+ entries: CanonicalEntry[];
76
+ demotions: BibleTombstone[];
61
77
  }
62
78
  /**
63
79
  * A bible entry with `basis` attached as its source_file_hashes (keys sorted,
@@ -71,7 +87,13 @@ export declare function withSourceFileHashes(entry: CanonicalEntry, basis: Recor
71
87
  * predicate admitted it against); when given and non-empty it is written as
72
88
  * source_file_hashes (format v3). Nothing is hashed here.
73
89
  */
74
- export declare function toCanonicalEntry(e: KBEntry, basis?: Record<string, string> | null): CanonicalEntry;
90
+ /**
91
+ * `trustTime` is the row's bible trust time (SqliteProvider.getBibleTrustTimes)
92
+ * when the caller has it, so an entry this clone imported keeps the updated_at
93
+ * its bible carried instead of taking the local import time. null/undefined
94
+ * falls back to promoted_at, then created_at.
95
+ */
96
+ export declare function toCanonicalEntry(e: KBEntry, basis?: Record<string, string> | null, trustTime?: string | null): CanonicalEntry;
75
97
  /**
76
98
  * Duplicate-id guard shared by every bible writer: a bible is keyed by id, so
77
99
  * one about to be written with two entries sharing an id is corrupt. Throws
@@ -89,8 +111,18 @@ export declare function compareById(a: {
89
111
  /**
90
112
  * The entries of the bible already on disk, in either shape (legacy bare array
91
113
  * or v2/v3 envelope). null when the file is absent or unparseable.
114
+ *
115
+ * Entries only, exactly as before: callers that do not care about tombstones are
116
+ * unchanged. readBibleDocument below is the sibling reader for callers that do.
92
117
  */
93
118
  export declare function readBibleEntries(outPath: string): CanonicalEntry[] | null;
119
+ /**
120
+ * The entries AND the demotion tombstones of the bible already on disk. Same
121
+ * acceptance as readBibleEntries (both shapes; null when absent or unparseable);
122
+ * a bible with no demotions field yields an empty tombstone list, never a
123
+ * failure.
124
+ */
125
+ export declare function readBibleDocument(outPath: string): CanonicalBibleDocument | null;
94
126
  /**
95
127
  * PATHSPEC-ONLY commit of the bible file with the dedicated pm-kb identity:
96
128
  * git add <path> then a commit scoped to -- <path>, so unrelated staged or