@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.
- package/README.md +49 -4
- package/dist/agents/backlog-groomer.md +5 -0
- package/dist/agents/ci-watcher.md +5 -0
- package/dist/agents/deployer.md +20 -2
- package/dist/agents/doer.md +38 -2
- package/dist/agents/harvester.md +12 -9
- package/dist/agents/integ-test-runner.md +5 -0
- package/dist/agents/kb-reconciler.md +6 -0
- package/dist/agents/plan-reviewer.md +5 -0
- package/dist/agents/planner.md +5 -0
- package/dist/agents/regression-test-runner.md +5 -0
- package/dist/agents/reviewer.md +67 -15
- package/dist/agents/schemas/deployer-output.json +5 -0
- package/dist/agents/schemas/doer-output.json +78 -2
- package/dist/agents/schemas/reviewer-output.json +104 -2
- package/dist/cli/auth.js +5 -1
- package/dist/cli/beads-pin.js +6 -7
- package/dist/cli/claude-mod.d.ts +75 -0
- package/dist/cli/claude-mod.js +288 -0
- package/dist/cli/dolt-install.d.ts +1 -1
- package/dist/cli/dolt-install.js +5 -1
- package/dist/cli/fleet-se-guard.d.ts +8 -0
- package/dist/cli/fleet-se-guard.js +19 -3
- package/dist/cli/install-guard.d.ts +9 -0
- package/dist/cli/install-guard.js +24 -0
- package/dist/cli/install.d.ts +12 -0
- package/dist/cli/install.js +180 -20
- package/dist/cli/kb-profile.d.ts +16 -0
- package/dist/cli/kb-profile.js +81 -0
- package/dist/cli/start.js +3 -0
- package/dist/cli/uninstall.js +13 -3
- package/dist/cli/update.d.ts +4 -0
- package/dist/cli/update.js +19 -3
- package/dist/commands/kb-server.d.ts +10 -1
- package/dist/commands/kb-server.js +285 -11
- package/dist/index.js +22 -1
- package/dist/os/git-executable.d.ts +57 -0
- package/dist/os/git-executable.js +85 -0
- package/dist/os/go-concurrency.d.ts +44 -0
- package/dist/os/go-concurrency.js +53 -0
- package/dist/os/index.d.ts +1 -0
- package/dist/os/index.js +1 -0
- package/dist/os/linux.d.ts +2 -0
- package/dist/os/linux.js +10 -1
- package/dist/os/os-commands.d.ts +25 -0
- package/dist/os/os-commands.js +2 -0
- package/dist/os/windows-executable.d.ts +53 -0
- package/dist/os/windows-executable.js +185 -0
- package/dist/os/windows-gitbash.d.ts +23 -14
- package/dist/os/windows-gitbash.js +40 -16
- package/dist/os/windows.d.ts +2 -0
- package/dist/os/windows.js +37 -6
- package/dist/paths.d.ts +10 -1
- package/dist/paths.js +19 -2
- package/dist/services/agy-project.d.ts +7 -1
- package/dist/services/agy-project.js +7 -2
- package/dist/services/auth-socket.d.ts +18 -0
- package/dist/services/auth-socket.js +30 -4
- package/dist/services/credential-store.d.ts +33 -0
- package/dist/services/credential-store.js +79 -2
- package/dist/services/http-transport.d.ts +29 -0
- package/dist/services/http-transport.js +166 -37
- package/dist/services/kb-tool-profile.d.ts +36 -0
- package/dist/services/kb-tool-profile.js +88 -0
- package/dist/services/knowledge/bible-blob-id.js +10 -1
- package/dist/services/knowledge/bible-import.d.ts +108 -0
- package/dist/services/knowledge/bible-import.js +137 -4
- package/dist/services/knowledge/file-hash.js +6 -5
- package/dist/services/knowledge/http-provider.d.ts +303 -20
- package/dist/services/knowledge/http-provider.js +795 -125
- package/dist/services/knowledge/kb-config.d.ts +65 -1
- package/dist/services/knowledge/kb-config.js +143 -3
- package/dist/services/knowledge/kb-http-auth-state.d.ts +26 -0
- package/dist/services/knowledge/kb-http-auth-state.js +40 -0
- package/dist/services/knowledge/kb-providers.d.ts +9 -2
- package/dist/services/knowledge/kb-providers.js +67 -37
- package/dist/services/knowledge/kb-removed-scope-keys.js +1 -1
- package/dist/services/knowledge/kb-self.d.ts +122 -9
- package/dist/services/knowledge/kb-self.js +196 -36
- package/dist/services/knowledge/member-bible-view.js +16 -3
- package/dist/services/knowledge/path-validation.d.ts +7 -0
- package/dist/services/knowledge/path-validation.js +11 -0
- package/dist/services/knowledge/project-slug.js +3 -2
- package/dist/services/knowledge/repository-header.d.ts +77 -0
- package/dist/services/knowledge/repository-header.js +233 -0
- package/dist/services/knowledge/require-sqlite-project.d.ts +1 -1
- package/dist/services/knowledge/require-sqlite-project.js +1 -1
- package/dist/services/knowledge/sqlite-provider.d.ts +169 -0
- package/dist/services/knowledge/sqlite-provider.js +416 -4
- package/dist/services/knowledge/types.d.ts +15 -2
- package/dist/services/member-busy.d.ts +12 -0
- package/dist/services/member-busy.js +20 -0
- package/dist/services/member-config-io.d.ts +3 -2
- package/dist/services/member-config-io.js +7 -4
- package/dist/services/member-fleet-install.js +1 -0
- package/dist/services/member-tool-allowlist.d.ts +1 -1
- package/dist/services/member-tool-allowlist.js +8 -4
- package/dist/services/port-holder.js +2 -1
- package/dist/services/service-manager/types.d.ts +17 -1
- package/dist/services/service-manager/windows.d.ts +7 -2
- package/dist/services/service-manager/windows.js +28 -11
- package/dist/services/service-notice.d.ts +7 -0
- package/dist/services/service-notice.js +19 -0
- package/dist/services/session-registry.d.ts +13 -0
- package/dist/services/session-registry.js +13 -0
- package/dist/services/session-roots.d.ts +67 -0
- package/dist/services/session-roots.js +126 -0
- package/dist/services/statusline.d.ts +21 -0
- package/dist/services/statusline.js +97 -1
- package/dist/services/supervisor-service-cleanup.js +2 -1
- package/dist/services/tool-registry.js +108 -20
- package/dist/services/tool-scope.d.ts +34 -1
- package/dist/services/tool-scope.js +27 -2
- package/dist/services/vcs/azure-devops.js +10 -0
- package/dist/services/vcs/bitbucket.d.ts +22 -1
- package/dist/services/vcs/bitbucket.js +163 -17
- package/dist/services/vcs/types.d.ts +25 -2
- package/dist/services/watch/project-resolver.js +2 -1
- package/dist/skills/pm/cost.md +5 -1
- package/dist/skills/pm/index.md +9 -9
- package/dist/skills/pm/sprint.md +2 -1
- package/dist/tools/check-status.d.ts +51 -0
- package/dist/tools/check-status.js +124 -12
- package/dist/tools/code-intelligence-freshness.js +1 -1
- package/dist/tools/code-intelligence-gitnexus.d.ts +19 -0
- package/dist/tools/code-intelligence-gitnexus.js +166 -9
- package/dist/tools/code-intelligence-readiness.d.ts +58 -1
- package/dist/tools/code-intelligence-readiness.js +93 -8
- package/dist/tools/code-intelligence-reindex.d.ts +25 -1
- package/dist/tools/code-intelligence-reindex.js +76 -4
- package/dist/tools/code-intelligence.d.ts +1 -1
- package/dist/tools/code-intelligence.js +1 -1
- package/dist/tools/execute-command.js +14 -8
- package/dist/tools/execute-prompt.js +6 -2
- package/dist/tools/fleet-snapshot.d.ts +21 -0
- package/dist/tools/fleet-snapshot.js +78 -0
- package/dist/tools/kb-bible-commit.d.ts +25 -11
- package/dist/tools/kb-bible-commit.js +142 -33
- package/dist/tools/kb-capture.d.ts +2 -2
- package/dist/tools/kb-context.js +47 -27
- package/dist/tools/kb-demote.d.ts +27 -0
- package/dist/tools/kb-demote.js +37 -0
- package/dist/tools/kb-export.d.ts +35 -3
- package/dist/tools/kb-export.js +56 -13
- package/dist/tools/kb-feedback.d.ts +2 -0
- package/dist/tools/kb-feedback.js +17 -7
- package/dist/tools/kb-harvest.js +28 -9
- package/dist/tools/kb-import.d.ts +18 -2
- package/dist/tools/kb-import.js +24 -9
- package/dist/tools/kb-invalidate.d.ts +11 -3
- package/dist/tools/kb-invalidate.js +80 -7
- package/dist/tools/kb-list.js +38 -10
- package/dist/tools/kb-promote.js +6 -4
- package/dist/tools/kb-query.d.ts +3 -0
- package/dist/tools/kb-query.js +181 -37
- package/dist/tools/kb-session-prime.d.ts +4 -4
- package/dist/tools/kb-session-prime.js +89 -9
- package/dist/tools/kb-setup.d.ts +20 -0
- package/dist/tools/kb-setup.js +149 -11
- package/dist/tools/list-members.js +1 -1
- package/dist/tools/member-detail.js +7 -3
- package/dist/tools/provision-vcs-auth.d.ts +28 -3
- package/dist/tools/provision-vcs-auth.js +53 -7
- package/dist/tools/receive-files.js +7 -4
- package/dist/tools/send-files.js +5 -4
- package/dist/tools/send-message.d.ts +3 -0
- package/dist/tools/send-message.js +15 -2
- package/dist/tools/stop-prompt.js +3 -1
- package/dist/tools/vcs-credential-exec.d.ts +45 -3
- package/dist/tools/vcs-credential-exec.js +90 -11
- package/dist/utils/process-utils.js +5 -1
- package/dist/utils/redact-known-secrets.d.ts +17 -0
- package/dist/utils/redact-known-secrets.js +70 -0
- package/dist/utils/skill-matrix.js +1 -1
- package/dist/utils/vcs-provider-detect.js +2 -2
- package/dist/workflows/auto-sprint.js +245 -9
- package/package.json +10 -7
- package/packages/apra-fleet-client/package.json +1 -1
- package/packages/apra-fleet-client/src/client/api.mjs +172 -19
- package/packages/apra-fleet-client/src/client/reconnecting-transport.mjs +35 -2
- package/packages/apra-fleet-client/src/client/transport.mjs +6 -0
- package/packages/apra-fleet-se/apra-pm/agents/backlog-groomer.md +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/ci-watcher.md +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/deployer.md +20 -2
- package/packages/apra-fleet-se/apra-pm/agents/doer.md +38 -2
- package/packages/apra-fleet-se/apra-pm/agents/harvester.md +12 -9
- package/packages/apra-fleet-se/apra-pm/agents/integ-test-runner.md +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/kb-reconciler.md +6 -0
- package/packages/apra-fleet-se/apra-pm/agents/plan-reviewer.md +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/planner.md +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/regression-test-runner.md +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/reviewer.md +67 -15
- package/packages/apra-fleet-se/apra-pm/agents/schemas/deployer-output.json +5 -0
- package/packages/apra-fleet-se/apra-pm/agents/schemas/doer-output.json +78 -2
- package/packages/apra-fleet-se/apra-pm/agents/schemas/reviewer-output.json +104 -2
- package/packages/apra-fleet-se/apra-pm/skills/pm/cost.md +5 -1
- package/packages/apra-fleet-se/apra-pm/skills/pm/index.md +9 -9
- package/packages/apra-fleet-se/apra-pm/skills/pm/sprint.md +2 -1
- package/packages/apra-fleet-se/bin/cli.mjs +104 -31
- package/packages/apra-fleet-se/bin/serve.mjs +46 -8
- package/packages/apra-fleet-se/fleet-sprint/abort.mjs +184 -32
- package/packages/apra-fleet-se/fleet-sprint/bd-sync-command.mjs +69 -0
- package/packages/apra-fleet-se/fleet-sprint/beads-children.mjs +21 -0
- package/packages/apra-fleet-se/fleet-sprint/beads-lock-probe.mjs +176 -0
- package/packages/apra-fleet-se/fleet-sprint/beads-reachability.mjs +126 -0
- package/packages/apra-fleet-se/fleet-sprint/beads-scope.mjs +158 -1
- package/packages/apra-fleet-se/fleet-sprint/contracts.mjs +82 -2
- package/packages/apra-fleet-se/fleet-sprint/coordination.mjs +23 -6
- package/packages/apra-fleet-se/fleet-sprint/decision-notify.mjs +338 -0
- package/packages/apra-fleet-se/fleet-sprint/decision-wait.mjs +731 -0
- package/packages/apra-fleet-se/fleet-sprint/decisions.mjs +372 -0
- package/packages/apra-fleet-se/fleet-sprint/dispatch-role.mjs +44 -11
- package/packages/apra-fleet-se/fleet-sprint/docs/README.md +4 -1
- package/packages/apra-fleet-se/fleet-sprint/dolt-settle.mjs +9 -3
- package/packages/apra-fleet-se/fleet-sprint/dolt-sync.mjs +314 -19
- package/packages/apra-fleet-se/fleet-sprint/errors.mjs +72 -4
- package/packages/apra-fleet-se/fleet-sprint/git-sync.mjs +7 -1
- package/packages/apra-fleet-se/fleet-sprint/git-topology.mjs +112 -1
- package/packages/apra-fleet-se/fleet-sprint/guarded-modules.mjs +36 -2
- package/packages/apra-fleet-se/fleet-sprint/kb.mjs +736 -101
- package/packages/apra-fleet-se/fleet-sprint/member-init-probe.mjs +1 -1
- package/packages/apra-fleet-se/fleet-sprint/member-provisioning.mjs +7 -1
- package/packages/apra-fleet-se/fleet-sprint/phases/deploy.mjs +49 -2
- package/packages/apra-fleet-se/fleet-sprint/phases/develop.mjs +206 -3
- package/packages/apra-fleet-se/fleet-sprint/phases/final-review.mjs +61 -3
- package/packages/apra-fleet-se/fleet-sprint/phases/harvest.mjs +81 -31
- package/packages/apra-fleet-se/fleet-sprint/phases/plan.mjs +7 -3
- package/packages/apra-fleet-se/fleet-sprint/phases/publish-pr.mjs +39 -14
- package/packages/apra-fleet-se/fleet-sprint/phases/re-review.mjs +17 -1
- package/packages/apra-fleet-se/fleet-sprint/phases/review.mjs +18 -3
- package/packages/apra-fleet-se/fleet-sprint/pr-body.mjs +14 -1
- package/packages/apra-fleet-se/fleet-sprint/prompts.mjs +32 -5
- package/packages/apra-fleet-se/fleet-sprint/runner.js +824 -98
- package/packages/apra-fleet-se/fleet-sprint/se-os-commands.mjs +4 -2
- package/packages/apra-fleet-se/fleet-sprint/se-posix.mjs +54 -1
- package/packages/apra-fleet-se/fleet-sprint/se-windows.mjs +29 -2
- package/packages/apra-fleet-se/fleet-sprint/set-aside.mjs +288 -0
- package/packages/apra-fleet-se/fleet-sprint/skills/fleet-supervisor/SKILL.md +3 -2
- package/packages/apra-fleet-se/fleet-sprint/sprint-args.mjs +20 -0
- package/packages/apra-fleet-se/fleet-sprint/sprint-report.mjs +21 -0
- package/packages/apra-fleet-se/fleet-sprint/sprint-state.mjs +9 -0
- package/packages/apra-fleet-se/fleet-sprint/vcs-auth.mjs +605 -32
- package/packages/apra-fleet-se/fleet-sprint/vcs-providers/bitbucket.mjs +811 -17
- package/packages/apra-fleet-se/fleet-sprint/vcs-providers/index.mjs +89 -1
- package/packages/apra-fleet-se/fleet-sprint/viewer-extensions.mjs +225 -2
- package/packages/apra-fleet-se/fleet-sprint/worklists.mjs +59 -3
- package/packages/apra-fleet-se/src/supervisor/api.mjs +148 -8
- package/packages/apra-fleet-se/src/supervisor/dashboard.mjs +6 -3
- package/packages/apra-fleet-se/src/supervisor/dolt-mutex.mjs +30 -10
- package/packages/apra-fleet-se/src/supervisor/fleet-members.mjs +17 -4
- package/packages/apra-fleet-se/src/supervisor/history.mjs +8 -1
- package/packages/apra-fleet-se/src/supervisor/id-allocator.mjs +92 -2
- package/packages/apra-fleet-se/src/supervisor/proxy.mjs +26 -1
- package/packages/apra-fleet-se/src/supervisor/server.mjs +151 -8
- package/packages/apra-fleet-se/src/supervisor/spawner.mjs +11 -9
- package/packages/apra-fleet-se/src/supervisor/watchdog.mjs +7 -1
- package/packages/apra-fleet-workflow/package.json +2 -1
- package/packages/apra-fleet-workflow/src/viewer/index.mjs +86 -5
- package/packages/apra-fleet-workflow/src/viewer/request-guard.mjs +222 -0
- package/packages/apra-fleet-workflow/src/workflow/index.mjs +34 -2
- package/plugins/claude-code/fleet-status/.claude-plugin/plugin.json +7 -0
- package/plugins/claude-code/fleet-status/hooks/hooks.json +1 -0
- package/plugins/claude-code/fleet-status/hooks/register.tsx +906 -0
- package/plugins/claude-code/fleet-status/types/index.d.ts +88 -0
- package/skills/fleet/auth-bitbucket.md +47 -20
- package/skills/fleet/onboarding.md +1 -1
- package/skills/fleet/skill-matrix.md +3 -3
- 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 {
|
|
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,
|
|
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
|
|
69
|
-
// KB is not opened.
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
-
//
|
|
162
|
-
//
|
|
163
|
-
|
|
164
|
-
|
|
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
|
|
207
|
-
* when entries were removed, the body lists each one as
|
|
208
|
-
* With no removals and no backfill the message is the
|
|
209
|
-
* subject line. A legacy backfill (existing entries that
|
|
210
|
-
* source_file_hashes) adds a body line 'Backfilled source_file_hashes on
|
|
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
|
|
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
|
-
|
|
324
|
+
head = 'chore(kb): backfill source_file_hashes on ' + backfilled + ' knowledge bible entries';
|
|
217
325
|
}
|
|
218
326
|
else if (removed.length === 0) {
|
|
219
|
-
|
|
327
|
+
head = 'chore(kb): commit ' + mergedCount + ' confirmed entries to the knowledge bible';
|
|
220
328
|
}
|
|
221
329
|
else if (mergedCount === 0) {
|
|
222
|
-
|
|
223
|
-
+ total + ' total';
|
|
330
|
+
head = 'chore(kb): remove ' + removed.length + ' superseded/invalidated entries from the knowledge bible';
|
|
224
331
|
}
|
|
225
332
|
else {
|
|
226
|
-
|
|
227
|
-
+ removed.length + ' superseded/invalidated
|
|
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;
|
package/dist/tools/kb-context.js
CHANGED
|
@@ -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
|
|
41
|
-
//
|
|
42
|
-
//
|
|
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 (
|
|
47
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
|
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
|
-
|
|
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
|