@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
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { type SessionRoots } from '../tool-scope.js';
|
|
1
2
|
import type { Agent } from '../../types.js';
|
|
2
3
|
import { type KbProviders } from './kb-providers.js';
|
|
4
|
+
import { HttpKbProvider } from './http-provider.js';
|
|
5
|
+
import type { SqliteProvider } from './sqlite-provider.js';
|
|
3
6
|
/** Explicit KB anchor for in-process callers. Not exposed on any tool schema. */
|
|
4
7
|
export interface KbAnchor {
|
|
5
8
|
/** Repo root the KB is about (anchors relative source_files). */
|
|
@@ -31,16 +34,40 @@ export interface SelfSession {
|
|
|
31
34
|
memberId?: string;
|
|
32
35
|
/** Member friendly name (or id) used in error text; undefined for FULL. */
|
|
33
36
|
memberLabel?: string;
|
|
34
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* The member's registered work folder; for a FULL session the selected
|
|
39
|
+
* client root, else the server working folder.
|
|
40
|
+
*/
|
|
35
41
|
folder: string;
|
|
36
42
|
/** The registered member (MEMBER session only). */
|
|
37
43
|
agent?: Agent;
|
|
44
|
+
/**
|
|
45
|
+
* FULL session only: where `folder` came from -- 'root' (the top level of
|
|
46
|
+
* the git repository an MCP client root sits in, already verified) or 'cwd'
|
|
47
|
+
* (the server working folder, not yet validated).
|
|
48
|
+
*/
|
|
49
|
+
source?: 'root' | 'cwd';
|
|
50
|
+
/**
|
|
51
|
+
* FULL session only, with source 'root': true when NO offered root is in a
|
|
52
|
+
* git repository with an origin remote and `folder` is the first offered
|
|
53
|
+
* git repository instead. code_* tools may use it (they need no origin);
|
|
54
|
+
* kb_* tools refuse it (resolveSelfAnchor), so kb and code never resolve to
|
|
55
|
+
* two different repositories.
|
|
56
|
+
*/
|
|
57
|
+
rootWithoutOrigin?: boolean;
|
|
58
|
+
/** FULL session only: the client roots this resolution saw. */
|
|
59
|
+
roots?: SessionRoots;
|
|
38
60
|
}
|
|
39
61
|
/**
|
|
40
62
|
* Resolve WHICH folder the calling session means by (self): a MEMBER session's
|
|
41
|
-
* registered work folder
|
|
42
|
-
*
|
|
43
|
-
*
|
|
63
|
+
* registered work folder; a FULL session's selected client root, else the
|
|
64
|
+
* server working folder (selectFullSessionFolder). A MEMBER session whose
|
|
65
|
+
* member is unregistered or has no work folder is refused with
|
|
66
|
+
* E-SELF-NO-WORKFOLDER -- it never falls back to the server folder, and never
|
|
67
|
+
* reads client roots.
|
|
68
|
+
*
|
|
69
|
+
* Inside a tool call the FULL selection is memoized for the rest of that call,
|
|
70
|
+
* so kb (self) and code (self) share one answer and cannot diverge.
|
|
44
71
|
*/
|
|
45
72
|
export declare function resolveSelfSession(): SelfSession;
|
|
46
73
|
/**
|
|
@@ -80,12 +107,98 @@ export interface SelfReadKb {
|
|
|
80
107
|
* checkout bible through the in-memory view (member-bible-view.ts); the
|
|
81
108
|
* per-repo DB is shared by every member of the repo, whichever branch each is
|
|
82
109
|
* on. Everything else keeps the per-repo DB: FULL sessions, in-process callers
|
|
83
|
-
* passing an explicit KbAnchor,
|
|
110
|
+
* passing an explicit KbAnchor, a MEMBER request that explicitly names the
|
|
84
111
|
* INFERRED or UNVERIFIED tier (a bible carries the CONFIRMED set, so those
|
|
85
|
-
* tiers are not the view's to answer)
|
|
86
|
-
*
|
|
112
|
+
* tiers are not the view's to answer), and a MEMBER request that opts into
|
|
113
|
+
* `opts.ownScope` (see below). The global KB is unchanged either way. Both of
|
|
114
|
+
* those last two MEMBER cases carry `ownerTag`: the caller sees only its own
|
|
115
|
+
* captures.
|
|
116
|
+
*
|
|
117
|
+
* `opts.ownScope` is the opt-in escape hatch from the bible view for a
|
|
118
|
+
* CONFIRMED read: the bible view is built by importBibleEntries, which stamps
|
|
119
|
+
* every row `tags: []` (bible-import.ts), so a bible-view read can never
|
|
120
|
+
* satisfy a `tag: 'member:<uuid>'` filter -- there is no row in that view
|
|
121
|
+
* carrying any member tag to match. A caller that needs to read back its OWN
|
|
122
|
+
* promoted CONFIRMED rows (e.g. kb_demote's candidate list, which must only
|
|
123
|
+
* ever offer ids kb_demote's ownerTag check can actually act on) sets
|
|
124
|
+
* `ownScope: true` to route to the per-repo KB instead, same as an explicit
|
|
125
|
+
* INFERRED/UNVERIFIED request. Default false/omitted: the routing above is
|
|
126
|
+
* unchanged, so no existing caller's result shape moves.
|
|
127
|
+
*
|
|
128
|
+
* Under an http project provider (decided from the KB config) the bible is
|
|
129
|
+
* not used at all: the KB server is the source of truth. A MEMBER session
|
|
130
|
+
* reads the server for every tier and every read tool, CONFIRMED included; a
|
|
131
|
+
* request naming INFERRED/UNVERIFIED, or opting into ownScope, carries
|
|
132
|
+
* ownerTag exactly as on SQLite, and the http provider enforces it fleet-side
|
|
133
|
+
* on the entries' tags. A server that cannot be reached is a typed error
|
|
134
|
+
* (E-KB-HTTP-UNREACHABLE), never an answer from the checkout bible or the
|
|
135
|
+
* per-repo database.
|
|
136
|
+
*/
|
|
137
|
+
export interface SelfReadKbOptions {
|
|
138
|
+
ownScope?: boolean;
|
|
139
|
+
}
|
|
140
|
+
export declare function getSelfReadKb(anchor?: KbAnchor, confidence?: readonly string[], opts?: SelfReadKbOptions): Promise<SelfReadKb>;
|
|
141
|
+
export type KbTier = 'CONFIRMED' | 'INFERRED' | 'UNVERIFIED';
|
|
142
|
+
/** A split-read project provider: both implement list() for kb_list. */
|
|
143
|
+
export type SplitProjectProvider = SqliteProvider | HttpKbProvider;
|
|
144
|
+
/**
|
|
145
|
+
* The two halves of a MEMBER mixed-tier read (see getMemberSplitRead).
|
|
146
|
+
*
|
|
147
|
+
* `bible` answers the CONFIRMED tier from exactly the source a CONFIRMED-only
|
|
148
|
+
* member read of the same tool uses, plus the global KB, with NO owner tag:
|
|
149
|
+
* the member's checkout bible view over a SQLite project, the KB server under
|
|
150
|
+
* http (the bible is never read then). `own`
|
|
151
|
+
* answers EVERY requested tier (CONFIRMED included) from the per-repo KB --
|
|
152
|
+
* the per-repo DB, or the KB server under http -- and the global KB, both
|
|
153
|
+
* restricted to `ownerTag`, so a member never sees another member's
|
|
154
|
+
* unconfirmed captures at any tier, while its own capture promoted to
|
|
155
|
+
* CONFIRMED stays visible before it reaches the bible (the bible copy wins on
|
|
156
|
+
* a shared id).
|
|
157
|
+
*/
|
|
158
|
+
export interface MemberSplitRead {
|
|
159
|
+
anchor: KbAnchor;
|
|
160
|
+
projectSlug: string;
|
|
161
|
+
bible: {
|
|
162
|
+
project: SplitProjectProvider;
|
|
163
|
+
global: SqliteProvider;
|
|
164
|
+
tiers: KbTier[];
|
|
165
|
+
};
|
|
166
|
+
own: {
|
|
167
|
+
project: SplitProjectProvider;
|
|
168
|
+
global: SqliteProvider;
|
|
169
|
+
tiers: KbTier[];
|
|
170
|
+
ownerTag: string;
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* The shared split read for a MEMBER session whose explicit tier list names
|
|
175
|
+
* CONFIRMED together with at least one other tier. Returns null for every other
|
|
176
|
+
* request, which then keeps its existing path through getSelfReadKb: a FULL
|
|
177
|
+
* session, an explicit-KbAnchor caller, a CONFIRMED-only (or omitted) tier list
|
|
178
|
+
* (bible view), and a list naming only non-CONFIRMED tiers (own captures only).
|
|
179
|
+
*
|
|
180
|
+
* Callers query each half with its own tiers and owner tag, then merge with
|
|
181
|
+
* mergeSplitById (bible copy wins) and apply their limit after the merge.
|
|
182
|
+
*
|
|
183
|
+
* HTTP per-repo provider: the own half is the KB server, owner-tagged (the
|
|
184
|
+
* http provider re-checks the tag on every entry it returns), and the
|
|
185
|
+
* CONFIRMED half is the KB server too, with no owner tag, so the mixed read is
|
|
186
|
+
* a superset of the CONFIRMED-only read, which the server also answers. Any other non-sqlite provider is refused with requireSqliteProject's
|
|
187
|
+
* error naming `callerLabel`: answering with the bible half alone would
|
|
188
|
+
* silently drop tiers the caller asked for.
|
|
189
|
+
*/
|
|
190
|
+
export declare function getMemberSplitRead(anchor: KbAnchor | undefined, confidence: readonly string[] | undefined, callerLabel: string): Promise<MemberSplitRead | null>;
|
|
191
|
+
/**
|
|
192
|
+
* Merge the two halves of a split read: every `bible` row, then each `own` row
|
|
193
|
+
* whose id the bible half did not already return (the bible copy wins). An
|
|
194
|
+
* optional `order` re-sorts the merged list; `limit` is applied last.
|
|
87
195
|
*/
|
|
88
|
-
export declare function
|
|
196
|
+
export declare function mergeSplitById<T extends {
|
|
197
|
+
id: string;
|
|
198
|
+
}>(bible: readonly T[], own: readonly T[], opts?: {
|
|
199
|
+
limit?: number;
|
|
200
|
+
order?: (a: T, b: T) => number;
|
|
201
|
+
}): T[];
|
|
89
202
|
/** Appended to every kb_* tool description so callers know there is no scope argument. */
|
|
90
|
-
export declare const KB_SELF_NOTE = " Scope: always the calling session's own KB -- a member session uses its registered work folder
|
|
203
|
+
export declare const KB_SELF_NOTE = " Scope: always the calling session's own KB -- a member session uses its registered work folder; any other session uses the first MCP client root (roots/list) inside a git repository with an origin remote, as that repository's top level, or the fleet server's working folder when the client offers no roots; there is no repo/path scope argument (the removed repo_path, repo and repo_remote_url keys fail with E-SCOPE-KEY-REMOVED). Fails with E-SELF-NO-WORKFOLDER, E-SELF-NOT-A-REPO or E-SELF-NO-REMOTE (each with a one-line remediation) when that folder cannot carry a KB identity (it must be a git repository with an origin remote).";
|
|
91
204
|
//# sourceMappingURL=kb-self.d.ts.map
|
|
@@ -5,10 +5,13 @@
|
|
|
5
5
|
//
|
|
6
6
|
// MEMBER session (?member=<uuid> or a member JWT) -- the member's registered
|
|
7
7
|
// work folder (getSessionMemberId() from the tool-scope lane).
|
|
8
|
-
// FULL session (no member identity) -- the
|
|
8
|
+
// FULL session (no member identity) -- the MCP client's roots (roots/list,
|
|
9
|
+
// cached per session by src/services/session-roots.ts): the first offered
|
|
10
|
+
// root that is a git repository with an origin remote wins. The server's
|
|
11
|
+
// own working folder is used only when the client offers no roots.
|
|
9
12
|
//
|
|
10
|
-
// An HTTP server cannot see a client's cwd, so
|
|
11
|
-
//
|
|
13
|
+
// An HTTP server cannot see a client's cwd, so a FULL session whose client
|
|
14
|
+
// offers no roots gets the server's folder.
|
|
12
15
|
//
|
|
13
16
|
// KB identity comes from the resolved folder's origin remote, so a folder that
|
|
14
17
|
// is missing, is not a git repository, or has no origin remote is refused with
|
|
@@ -22,11 +25,14 @@
|
|
|
22
25
|
import fs from 'node:fs';
|
|
23
26
|
import path from 'node:path';
|
|
24
27
|
import { execFileSync } from 'node:child_process';
|
|
25
|
-
import { getSessionMemberId } from '../tool-scope.js';
|
|
28
|
+
import { getSelfMemoSlot, getSessionMemberId, getSessionRoots } from '../tool-scope.js';
|
|
26
29
|
import { getAgent } from '../registry.js';
|
|
27
30
|
import { knownRepoRemoteUrl } from '../member-remote-url.js';
|
|
28
|
-
import { getKbProviders, getGlobalKbProvider, getProjectSlug } from './kb-providers.js';
|
|
31
|
+
import { getKbProviders, getGlobalKbProvider, getProjectSlug, kbConfigSelectsHttp } from './kb-providers.js';
|
|
29
32
|
import { getMemberBibleView } from './member-bible-view.js';
|
|
33
|
+
import { isSqliteProject, requireSqliteProject } from './require-sqlite-project.js';
|
|
34
|
+
import { HttpKbProvider } from './http-provider.js';
|
|
35
|
+
import { gitExecutable } from '../../os/git-executable.js';
|
|
30
36
|
export class KbSelfError extends Error {
|
|
31
37
|
code;
|
|
32
38
|
folder;
|
|
@@ -42,24 +48,32 @@ export class KbSelfError extends Error {
|
|
|
42
48
|
function whose(memberLabel) {
|
|
43
49
|
return memberLabel ? `member '${memberLabel}' work folder` : 'server working folder';
|
|
44
50
|
}
|
|
45
|
-
// A FULL session (no member identity) resolves
|
|
46
|
-
//
|
|
47
|
-
//
|
|
48
|
-
//
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
// A FULL session (no member identity) resolves from the MCP client's roots
|
|
52
|
+
// when the client offers any (see resolveSelfSession), else from the fleet
|
|
53
|
+
// SERVER's working folder -- never the client's cwd, which an HTTP server
|
|
54
|
+
// cannot see. A caller hitting a self error on the server-folder path usually
|
|
55
|
+
// expected its own directory, so the error names that cause (including
|
|
56
|
+
// whether the client offered roots) and every fix explicitly.
|
|
57
|
+
function fullSessionCause() {
|
|
58
|
+
return "This is a FULL session (no member identity) and the client offered no MCP roots, so its scope is the fleet server's own working folder, not the calling client's directory";
|
|
59
|
+
}
|
|
60
|
+
const FULL_SESSION_FIX = "Open the client in the repository (a client that offers MCP roots is scoped to its first root inside a git repository with an origin remote), restart the fleet server with its working folder set to that repository, or call from a member session (?member=<id>) of a member registered on it.";
|
|
61
|
+
function listForError(items) {
|
|
62
|
+
const shown = items.slice(0, 5).map(i => `'${i}'`).join(', ');
|
|
63
|
+
return items.length > 5 ? `${shown}, and ${items.length - 5} more` : shown;
|
|
64
|
+
}
|
|
51
65
|
function noWorkFolder(folder, memberLabel) {
|
|
52
66
|
return new KbSelfError('E-SELF-NO-WORKFOLDER', folder, `The ${whose(memberLabel)} ${folder ? `'${folder}' does not exist or is not a directory.` : 'is not set.'}`, memberLabel
|
|
53
67
|
? 'Create the folder or re-register the member with an existing work folder (register_member / update_member).'
|
|
54
68
|
: FULL_SESSION_FIX);
|
|
55
69
|
}
|
|
56
|
-
function gitOut(folder, args) {
|
|
70
|
+
function gitOut(folder, args, opts = {}) {
|
|
57
71
|
// Same ceiling as resolveProjectSlug: the folder itself must be the repo, so a
|
|
58
72
|
// temp folder that merely sits inside some other checkout is not mistaken
|
|
59
73
|
// for that checkout.
|
|
60
|
-
const env = { ...process.env, GIT_CEILING_DIRECTORIES: path.dirname(folder) };
|
|
74
|
+
const env = opts.ceiling === false ? process.env : { ...process.env, GIT_CEILING_DIRECTORIES: path.dirname(folder) };
|
|
61
75
|
try {
|
|
62
|
-
return execFileSync(
|
|
76
|
+
return execFileSync(gitExecutable(), args, {
|
|
63
77
|
cwd: folder, env, encoding: 'utf-8', timeout: 3000, stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true,
|
|
64
78
|
}).trim();
|
|
65
79
|
}
|
|
@@ -86,7 +100,7 @@ export function validateSelfRepoFolder(folder, memberLabel) {
|
|
|
86
100
|
if (gitOut(folder, ['rev-parse', '--git-dir']) === null) {
|
|
87
101
|
throw new KbSelfError('E-SELF-NOT-A-REPO', folder, memberLabel
|
|
88
102
|
? `The ${whose(memberLabel)} '${folder}' is not a git repository.`
|
|
89
|
-
: `${
|
|
103
|
+
: `${fullSessionCause()}; '${folder}' is not a git repository.`, memberLabel
|
|
90
104
|
? `Run 'git init' (or clone the project) in '${folder}' and add an origin remote.`
|
|
91
105
|
: `${FULL_SESSION_FIX} Or make '${folder}' itself a git repository with an origin remote.`);
|
|
92
106
|
}
|
|
@@ -98,22 +112,110 @@ export function validateSelfFolder(folder, memberLabel) {
|
|
|
98
112
|
if (!remote) {
|
|
99
113
|
throw new KbSelfError('E-SELF-NO-REMOTE', folder, memberLabel
|
|
100
114
|
? `The ${whose(memberLabel)} '${folder}' has no origin remote, so it has no KB identity.`
|
|
101
|
-
: `${
|
|
115
|
+
: `${fullSessionCause()}; '${folder}' has no origin remote, so it has no KB identity.`, memberLabel
|
|
102
116
|
? `Run 'git remote add origin <url>' in '${folder}'.`
|
|
103
117
|
: `${FULL_SESSION_FIX} Or run 'git remote add origin <url>' in '${folder}'.`);
|
|
104
118
|
}
|
|
105
119
|
return { folder };
|
|
106
120
|
}
|
|
121
|
+
function hasOriginRemote(folder) {
|
|
122
|
+
return !!gitOut(folder, ['remote', 'get-url', 'origin']);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The top level of the git repository a client root sits in, or null when it
|
|
126
|
+
* is in none. Unlike a member's registered work folder, a root is wherever the
|
|
127
|
+
* client was opened, often a subfolder, so there is no ceiling here. A root
|
|
128
|
+
* that already is the top level keeps its spelling (git answers with resolved
|
|
129
|
+
* symlinks, short names expanded and forward slashes), so it names the same
|
|
130
|
+
* index and KB folder as before.
|
|
131
|
+
*/
|
|
132
|
+
function rootRepoTopLevel(root) {
|
|
133
|
+
const top = gitOut(root, ['rev-parse', '--show-toplevel'], { ceiling: false });
|
|
134
|
+
if (!top)
|
|
135
|
+
return null;
|
|
136
|
+
try {
|
|
137
|
+
if (fs.realpathSync.native(root) === fs.realpathSync.native(top))
|
|
138
|
+
return root;
|
|
139
|
+
}
|
|
140
|
+
catch { /* fall through to git's answer */ }
|
|
141
|
+
return path.resolve(top);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* FULL session (self) selection (owner decision: client roots first, server
|
|
145
|
+
* working folder only when the client offers no roots). A root inside a git
|
|
146
|
+
* repository stands for that repository's top level, so a client opened in a
|
|
147
|
+
* subfolder scopes to the repository:
|
|
148
|
+
*
|
|
149
|
+
* 1. The first offered root in a git repository with an origin remote.
|
|
150
|
+
* 2. Extension for code_* only: when roots are offered and none has an
|
|
151
|
+
* origin, the first offered root in a git repository
|
|
152
|
+
* (rootWithoutOrigin: kb_* refuses it).
|
|
153
|
+
* 3. No roots offered (no roots capability or an empty list): the server
|
|
154
|
+
* working folder.
|
|
155
|
+
*
|
|
156
|
+
* Everything else is refused, never answered from the server folder: it may be
|
|
157
|
+
* an unrelated repository, and the caller could not tell.
|
|
158
|
+
* - Asking the client failed: E-SELF-NO-WORKFOLDER naming the failure; the
|
|
159
|
+
* next call asks again.
|
|
160
|
+
* - No offered root is a folder on this host (a remote client's path, a
|
|
161
|
+
* deleted folder, a non-file URI): E-SELF-NO-WORKFOLDER.
|
|
162
|
+
* - Roots on this host but none in a git repository: E-SELF-NOT-A-REPO.
|
|
163
|
+
*/
|
|
164
|
+
function selectFullSessionFolder() {
|
|
165
|
+
const roots = getSessionRoots();
|
|
166
|
+
if (roots?.fetchError !== undefined) {
|
|
167
|
+
throw new KbSelfError('E-SELF-NO-WORKFOLDER', '', `This is a FULL session (no member identity) and asking the client for its MCP roots failed (${roots.fetchError}), so the session's scope is unknown; the call was not run and the server's working folder was not used in its place.`, 'Retry the same call: each call asks the client again. If it keeps failing, restart the client or check that it answers roots/list.');
|
|
168
|
+
}
|
|
169
|
+
if (!roots || roots.offered.length === 0) {
|
|
170
|
+
return { folder: process.cwd(), source: 'cwd', ...(roots ? { roots } : {}) };
|
|
171
|
+
}
|
|
172
|
+
if (roots.folders.length === 0) {
|
|
173
|
+
throw new KbSelfError('E-SELF-NO-WORKFOLDER', roots.offered[0], `This is a FULL session (no member identity) and the client offered MCP roots, but none of them (${listForError(roots.offered)}) is a folder on this host, so the session has no KB or code scope; the server's working folder was not used in its place.`, 'Open the client on this host in a git repository with an origin remote, or call from a member session (?member=<id>) of a member registered on that folder.');
|
|
174
|
+
}
|
|
175
|
+
let firstRepo;
|
|
176
|
+
for (const root of roots.folders) {
|
|
177
|
+
const folder = rootRepoTopLevel(root);
|
|
178
|
+
if (folder === null)
|
|
179
|
+
continue;
|
|
180
|
+
if (hasOriginRemote(folder))
|
|
181
|
+
return { folder, source: 'root', roots };
|
|
182
|
+
if (firstRepo === undefined)
|
|
183
|
+
firstRepo = folder;
|
|
184
|
+
}
|
|
185
|
+
if (firstRepo !== undefined)
|
|
186
|
+
return { folder: firstRepo, source: 'root', rootWithoutOrigin: true, roots };
|
|
187
|
+
throw new KbSelfError('E-SELF-NOT-A-REPO', roots.folders[0], `This is a FULL session (no member identity) and the client offered MCP roots, but none of them (${listForError(roots.folders)}) is in a git repository, so the session has no KB or code scope.`, `Open the client in a git repository with an origin remote (or add one as a root), or run 'git init' and 'git remote add origin <url>' in '${roots.folders[0]}'.`);
|
|
188
|
+
}
|
|
107
189
|
/**
|
|
108
190
|
* Resolve WHICH folder the calling session means by (self): a MEMBER session's
|
|
109
|
-
* registered work folder
|
|
110
|
-
*
|
|
111
|
-
*
|
|
191
|
+
* registered work folder; a FULL session's selected client root, else the
|
|
192
|
+
* server working folder (selectFullSessionFolder). A MEMBER session whose
|
|
193
|
+
* member is unregistered or has no work folder is refused with
|
|
194
|
+
* E-SELF-NO-WORKFOLDER -- it never falls back to the server folder, and never
|
|
195
|
+
* reads client roots.
|
|
196
|
+
*
|
|
197
|
+
* Inside a tool call the FULL selection is memoized for the rest of that call,
|
|
198
|
+
* so kb (self) and code (self) share one answer and cannot diverge.
|
|
112
199
|
*/
|
|
113
200
|
export function resolveSelfSession() {
|
|
114
201
|
const memberId = getSessionMemberId();
|
|
115
|
-
if (memberId === undefined)
|
|
116
|
-
|
|
202
|
+
if (memberId === undefined) {
|
|
203
|
+
const memo = getSelfMemoSlot();
|
|
204
|
+
if (!memo)
|
|
205
|
+
return selectFullSessionFolder();
|
|
206
|
+
if (memo.error !== undefined)
|
|
207
|
+
throw memo.error;
|
|
208
|
+
if (memo.value !== undefined)
|
|
209
|
+
return memo.value;
|
|
210
|
+
try {
|
|
211
|
+
memo.value = selectFullSessionFolder();
|
|
212
|
+
return memo.value;
|
|
213
|
+
}
|
|
214
|
+
catch (e) {
|
|
215
|
+
memo.error = e;
|
|
216
|
+
throw e;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
117
219
|
const agent = getAgent(memberId);
|
|
118
220
|
const label = agent?.friendlyName ?? memberId;
|
|
119
221
|
const folder = agent?.workFolder ?? '';
|
|
@@ -128,8 +230,12 @@ export function resolveSelfSession() {
|
|
|
128
230
|
export function resolveSelfAnchor() {
|
|
129
231
|
const self = resolveSelfSession();
|
|
130
232
|
const { agent, folder, memberLabel: label, memberId } = self;
|
|
131
|
-
if (!agent)
|
|
233
|
+
if (!agent) {
|
|
234
|
+
if (self.rootWithoutOrigin) {
|
|
235
|
+
throw new KbSelfError('E-SELF-NO-REMOTE', folder, `This is a FULL session (no member identity) and none of the client's MCP roots (${listForError(self.roots?.folders ?? [folder])}) is in a git repository with an origin remote, so the session has no KB identity (code tools use the first offered git repository, '${folder}').`, `Run 'git remote add origin <url>' in '${folder}', or open the client in a repository that has an origin remote.`);
|
|
236
|
+
}
|
|
132
237
|
return validateSelfFolder(folder);
|
|
238
|
+
}
|
|
133
239
|
if (agent.agentType !== 'local') {
|
|
134
240
|
// The work folder lives on another host: git cannot be shelled out there,
|
|
135
241
|
// so the KB identity is the member's single known origin remote.
|
|
@@ -163,21 +269,19 @@ export function memberOwnerTag(anchor) {
|
|
|
163
269
|
const memberId = getSessionMemberId();
|
|
164
270
|
return memberId === undefined ? undefined : `member:${memberId}`;
|
|
165
271
|
}
|
|
166
|
-
|
|
167
|
-
* Providers for the read tools (kb_query, kb_session_prime, kb_list,
|
|
168
|
-
* kb_context, kb_stats). A MEMBER session (no explicit anchor) reads its own
|
|
169
|
-
* checkout bible through the in-memory view (member-bible-view.ts); the
|
|
170
|
-
* per-repo DB is shared by every member of the repo, whichever branch each is
|
|
171
|
-
* on. Everything else keeps the per-repo DB: FULL sessions, in-process callers
|
|
172
|
-
* passing an explicit KbAnchor, and a MEMBER request that explicitly names the
|
|
173
|
-
* INFERRED or UNVERIFIED tier (a bible carries the CONFIRMED set, so those
|
|
174
|
-
* tiers are not the view's to answer). The global KB is unchanged either way.
|
|
175
|
-
* That last MEMBER case carries `ownerTag`: it sees only its own captures.
|
|
176
|
-
*/
|
|
177
|
-
export async function getSelfReadKb(anchor, confidence) {
|
|
272
|
+
export async function getSelfReadKb(anchor, confidence, opts = {}) {
|
|
178
273
|
const resolved = resolveKbAnchor(anchor);
|
|
274
|
+
const isMemberSelf = anchor === undefined && getSessionMemberId() !== undefined;
|
|
179
275
|
const namesUnconfirmedTier = (confidence ?? []).some(c => c !== 'CONFIRMED');
|
|
180
|
-
|
|
276
|
+
// Decided from the config, so the default (SQLite) path opens no store here.
|
|
277
|
+
if (isMemberSelf && kbConfigSelectsHttp()) {
|
|
278
|
+
const providers = await getKbProviders(resolved.folder, resolved.remoteUrl);
|
|
279
|
+
if (!isSqliteProject(providers.project)) {
|
|
280
|
+
const ownerTag = namesUnconfirmedTier || opts.ownScope ? memberOwnerTag(anchor) : undefined;
|
|
281
|
+
return { providers, anchor: resolved, memberView: false, ...(ownerTag !== undefined ? { ownerTag } : {}) };
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
if (isMemberSelf && !namesUnconfirmedTier && !opts.ownScope) {
|
|
181
285
|
const [project, global] = await Promise.all([getMemberBibleView(resolved), getGlobalKbProvider()]);
|
|
182
286
|
return {
|
|
183
287
|
providers: { project, global, projectSlug: getProjectSlug(resolved.folder, resolved.remoteUrl) },
|
|
@@ -193,6 +297,62 @@ export async function getSelfReadKb(anchor, confidence) {
|
|
|
193
297
|
...(ownerTag !== undefined ? { ownerTag } : {}),
|
|
194
298
|
};
|
|
195
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* The shared split read for a MEMBER session whose explicit tier list names
|
|
302
|
+
* CONFIRMED together with at least one other tier. Returns null for every other
|
|
303
|
+
* request, which then keeps its existing path through getSelfReadKb: a FULL
|
|
304
|
+
* session, an explicit-KbAnchor caller, a CONFIRMED-only (or omitted) tier list
|
|
305
|
+
* (bible view), and a list naming only non-CONFIRMED tiers (own captures only).
|
|
306
|
+
*
|
|
307
|
+
* Callers query each half with its own tiers and owner tag, then merge with
|
|
308
|
+
* mergeSplitById (bible copy wins) and apply their limit after the merge.
|
|
309
|
+
*
|
|
310
|
+
* HTTP per-repo provider: the own half is the KB server, owner-tagged (the
|
|
311
|
+
* http provider re-checks the tag on every entry it returns), and the
|
|
312
|
+
* CONFIRMED half is the KB server too, with no owner tag, so the mixed read is
|
|
313
|
+
* a superset of the CONFIRMED-only read, which the server also answers. Any other non-sqlite provider is refused with requireSqliteProject's
|
|
314
|
+
* error naming `callerLabel`: answering with the bible half alone would
|
|
315
|
+
* silently drop tiers the caller asked for.
|
|
316
|
+
*/
|
|
317
|
+
export async function getMemberSplitRead(anchor, confidence, callerLabel) {
|
|
318
|
+
if (anchor !== undefined || getSessionMemberId() === undefined)
|
|
319
|
+
return null;
|
|
320
|
+
const tiers = [...new Set(confidence ?? [])];
|
|
321
|
+
if (!tiers.includes('CONFIRMED') || tiers.every(t => t === 'CONFIRMED'))
|
|
322
|
+
return null;
|
|
323
|
+
const ownerTag = memberOwnerTag(anchor);
|
|
324
|
+
if (ownerTag === undefined)
|
|
325
|
+
return null;
|
|
326
|
+
const resolved = resolveKbAnchor(anchor);
|
|
327
|
+
const repo = await getKbProviders(resolved.folder, resolved.remoteUrl);
|
|
328
|
+
const ownProject = repo.project instanceof HttpKbProvider
|
|
329
|
+
? repo.project
|
|
330
|
+
: requireSqliteProject(repo.project, callerLabel);
|
|
331
|
+
// Under http the server answers the CONFIRMED half as well: the bible is
|
|
332
|
+
// never loaded (on a remote member that load would also be an SSH round trip).
|
|
333
|
+
const confirmedProject = ownProject instanceof HttpKbProvider
|
|
334
|
+
? Promise.resolve(ownProject)
|
|
335
|
+
: getMemberBibleView(resolved);
|
|
336
|
+
const [bibleProject, global] = await Promise.all([confirmedProject, getGlobalKbProvider()]);
|
|
337
|
+
return {
|
|
338
|
+
anchor: resolved,
|
|
339
|
+
projectSlug: repo.projectSlug,
|
|
340
|
+
bible: { project: bibleProject, global, tiers: ['CONFIRMED'] },
|
|
341
|
+
own: { project: ownProject, global: repo.global, tiers, ownerTag },
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Merge the two halves of a split read: every `bible` row, then each `own` row
|
|
346
|
+
* whose id the bible half did not already return (the bible copy wins). An
|
|
347
|
+
* optional `order` re-sorts the merged list; `limit` is applied last.
|
|
348
|
+
*/
|
|
349
|
+
export function mergeSplitById(bible, own, opts = {}) {
|
|
350
|
+
const seen = new Set(bible.map(e => e.id));
|
|
351
|
+
let merged = [...bible, ...own.filter(e => !seen.has(e.id))];
|
|
352
|
+
if (opts.order)
|
|
353
|
+
merged = merged.sort(opts.order);
|
|
354
|
+
return opts.limit !== undefined ? merged.slice(0, opts.limit) : merged;
|
|
355
|
+
}
|
|
196
356
|
/** Appended to every kb_* tool description so callers know there is no scope argument. */
|
|
197
|
-
export const KB_SELF_NOTE = ' Scope: always the calling session\'s own KB -- a member session uses its registered work folder
|
|
357
|
+
export const KB_SELF_NOTE = ' Scope: always the calling session\'s own KB -- a member session uses its registered work folder; any other session uses the first MCP client root (roots/list) inside a git repository with an origin remote, as that repository\'s top level, or the fleet server\'s working folder when the client offers no roots; there is no repo/path scope argument (the removed repo_path, repo and repo_remote_url keys fail with E-SCOPE-KEY-REMOVED). Fails with E-SELF-NO-WORKFOLDER, E-SELF-NOT-A-REPO or E-SELF-NO-REMOTE (each with a one-line remediation) when that folder cannot carry a KB identity (it must be a git repository with an origin remote).';
|
|
198
358
|
//# sourceMappingURL=kb-self.js.map
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
import fs from 'node:fs';
|
|
32
32
|
import path from 'node:path';
|
|
33
33
|
import { SqliteProvider } from './sqlite-provider.js';
|
|
34
|
-
import {
|
|
34
|
+
import { readBibleDocument, parseBibleDocument, excludeTombstonedEntries, importBibleEntries, } from './bible-import.js';
|
|
35
35
|
import { getAgent } from '../registry.js';
|
|
36
36
|
import { getStrategy } from '../strategy.js';
|
|
37
37
|
import { getAgentOS, getAgentShell, isPosixShell } from '../../utils/agent-helpers.js';
|
|
@@ -68,7 +68,15 @@ function statOrMissing(biblePath) {
|
|
|
68
68
|
async function buildView(biblePath, repoRoot, missing) {
|
|
69
69
|
_loadCounts.set(biblePath, (_loadCounts.get(biblePath) ?? 0) + 1);
|
|
70
70
|
// Parse BEFORE opening the database, so a malformed bible costs nothing.
|
|
71
|
-
|
|
71
|
+
// DOCUMENT reader: the view must honour the bible's demotion tombstones, and
|
|
72
|
+
// the only way it can is by not listing the tombstoned entry. The provider
|
|
73
|
+
// below starts EMPTY, so there is no local row for a tombstone to demote --
|
|
74
|
+
// the import-side demotion branch is the wrong tool here and is deliberately
|
|
75
|
+
// not used.
|
|
76
|
+
const doc = missing
|
|
77
|
+
? { entries: [], demotions: [] }
|
|
78
|
+
: readBibleDocument(biblePath, 'member bible view');
|
|
79
|
+
const entries = excludeTombstonedEntries(doc.entries, doc.demotions);
|
|
72
80
|
// repoRoot anchors relative source_files exactly as the per-repo provider
|
|
73
81
|
// does, so the capture basis check and prime()'s freshness check judge the
|
|
74
82
|
// bible against the member's own checkout.
|
|
@@ -138,7 +146,12 @@ async function getRemoteMemberBibleView(anchor) {
|
|
|
138
146
|
return current.provider;
|
|
139
147
|
const build = async () => {
|
|
140
148
|
_loadCounts.set(key, (_loadCounts.get(key) ?? 0) + 1);
|
|
141
|
-
|
|
149
|
+
// Same tombstone rule as the local path above -- a demotion must not be
|
|
150
|
+
// visible on one transport and invisible on the other.
|
|
151
|
+
const remoteDoc = mtimeMs === -1
|
|
152
|
+
? { entries: [], demotions: [] }
|
|
153
|
+
: parseBibleDocument(await run(catCommand(agent, biblePath)), biblePath, 'member bible view');
|
|
154
|
+
const entries = excludeTombstonedEntries(remoteDoc.entries, remoteDoc.demotions);
|
|
142
155
|
// The member's checkout is on another host: nothing here can verify its
|
|
143
156
|
// source files, so import unanchored, then bind the remote folder so
|
|
144
157
|
// freshness issues no verdict (see SqliteProvider.bindRepoPath).
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* True when `file` cannot be repo-relative on ANY platform: absolute in POSIX
|
|
3
|
+
* or Windows form (leading / or \, or a drive letter), or with a '..' segment
|
|
4
|
+
* under either separator. Independent of the host OS, so a path checked here
|
|
5
|
+
* means the same on the KB server as on this machine.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isAbsoluteOrTraversing(file: string): boolean;
|
|
1
8
|
export declare function validateFilePaths(files: string[]): void;
|
|
2
9
|
//# sourceMappingURL=path-validation.d.ts.map
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
/**
|
|
3
|
+
* True when `file` cannot be repo-relative on ANY platform: absolute in POSIX
|
|
4
|
+
* or Windows form (leading / or \, or a drive letter), or with a '..' segment
|
|
5
|
+
* under either separator. Independent of the host OS, so a path checked here
|
|
6
|
+
* means the same on the KB server as on this machine.
|
|
7
|
+
*/
|
|
8
|
+
export function isAbsoluteOrTraversing(file) {
|
|
9
|
+
if (/^[\\/]/.test(file) || /^[A-Za-z]:/.test(file))
|
|
10
|
+
return true;
|
|
11
|
+
return file.split(/[\\/]/).includes('..');
|
|
12
|
+
}
|
|
2
13
|
export function validateFilePaths(files) {
|
|
3
14
|
for (const file of files) {
|
|
4
15
|
if (path.isAbsolute(file)) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { execFileSync } from 'child_process';
|
|
2
2
|
import path from 'path';
|
|
3
|
+
import { gitExecutable } from '../../os/git-executable.js';
|
|
3
4
|
export function resolveProjectSlug(cwd, remoteUrl) {
|
|
4
5
|
if (remoteUrl && remoteUrl.trim()) {
|
|
5
6
|
const slug = slugify(remoteUrl);
|
|
@@ -10,7 +11,7 @@ export function resolveProjectSlug(cwd, remoteUrl) {
|
|
|
10
11
|
const env = { ...process.env, GIT_CEILING_DIRECTORIES: path.dirname(dir) };
|
|
11
12
|
// 1. git remote URL
|
|
12
13
|
try {
|
|
13
|
-
const remote = execFileSync(
|
|
14
|
+
const remote = execFileSync(gitExecutable(), ['remote', 'get-url', 'origin'], {
|
|
14
15
|
cwd: dir, env, encoding: 'utf-8', timeout: 3000, stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true,
|
|
15
16
|
}).trim();
|
|
16
17
|
const slug = slugify(remote);
|
|
@@ -20,7 +21,7 @@ export function resolveProjectSlug(cwd, remoteUrl) {
|
|
|
20
21
|
catch { }
|
|
21
22
|
// 2. git repo root dir name
|
|
22
23
|
try {
|
|
23
|
-
const root = execFileSync(
|
|
24
|
+
const root = execFileSync(gitExecutable(), ['rev-parse', '--show-toplevel'], {
|
|
24
25
|
cwd: dir, env, encoding: 'utf-8', timeout: 3000, stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true,
|
|
25
26
|
}).trim();
|
|
26
27
|
const slug = slugify(path.basename(root));
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export declare const REPOSITORY_HEADER = "X-Repository";
|
|
2
|
+
export declare const REPOSITORY_COMMIT_HEADER = "X-Repository-Commit";
|
|
3
|
+
export declare const REPOSITORY_BRANCH_HEADER = "X-Repository-Branch";
|
|
4
|
+
/** Longest X-Repository-Branch value (after percent-encoding) that is sent. */
|
|
5
|
+
export declare const MAX_BRANCH_LENGTH = 255;
|
|
6
|
+
/** Longest X-Repository value a receiving server accepts. */
|
|
7
|
+
export declare const MAX_REPOSITORY_LENGTH = 512;
|
|
8
|
+
/** The repository a provider sends with every request. */
|
|
9
|
+
export interface RepositoryIdentity {
|
|
10
|
+
/** Normalised origin remote, `host/path` (see normaliseRepositoryRemote). */
|
|
11
|
+
remote: string;
|
|
12
|
+
/** HEAD sha of the local folder; undefined when unknown. Must not throw. */
|
|
13
|
+
commitOf?: () => string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Checked-out branch of the local folder, percent-encoded; undefined when
|
|
16
|
+
* unknown or HEAD is detached. Must not throw.
|
|
17
|
+
*/
|
|
18
|
+
branchOf?: () => string | undefined;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Normalise a git remote URL to `host/path`: no scheme, no user info or
|
|
22
|
+
* credentials, no port, no query or fragment, no trailing `.git` or `/`. The
|
|
23
|
+
* host is lowercased; the path keeps its case. ssh forms (`git@host:org/repo`,
|
|
24
|
+
* `ssh://git@host/org/repo`) map to the same value as https. Azure DevOps
|
|
25
|
+
* spellings fold to `dev.azure.com/<org>/<project>/_git/<repo>` (org
|
|
26
|
+
* lowercased), as the receiving server canonicalises them. Characters outside
|
|
27
|
+
* printable ASCII (space, non-ASCII) are percent-encoded.
|
|
28
|
+
*
|
|
29
|
+
* Returns undefined for anything that is not a network remote (a local path, a
|
|
30
|
+
* file:// URL) or that would not be a valid header value.
|
|
31
|
+
*/
|
|
32
|
+
export declare function normaliseRepositoryRemote(remoteUrl: string): string | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* True when `value` is a header value a receiving server accepts: at most 512
|
|
35
|
+
* printable ASCII characters, no spaces, no scheme, no '@' before the first '/'.
|
|
36
|
+
*/
|
|
37
|
+
export declare function isValidRepositoryValue(value: string): boolean;
|
|
38
|
+
/** A full SHA-1 or SHA-256 commit id, lowercase. */
|
|
39
|
+
export declare const COMMIT_SHA: RegExp;
|
|
40
|
+
/** How long a read HEAD sha is reused before git is asked again. */
|
|
41
|
+
export declare const HEAD_COMMIT_TTL_MS = 5000;
|
|
42
|
+
/**
|
|
43
|
+
* A reader for the HEAD sha of a local folder, cached for `ttlMs` so it is not
|
|
44
|
+
* re-read on every request. Returns undefined (never throws) when the folder
|
|
45
|
+
* is not a git repository or HEAD cannot be resolved (unborn branch).
|
|
46
|
+
*/
|
|
47
|
+
export declare function headCommitReader(folder: string, ttlMs?: number): () => string | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* True when `value` is an X-Repository-Branch value that may be sent: 1-255
|
|
50
|
+
* printable ASCII characters, no spaces.
|
|
51
|
+
*/
|
|
52
|
+
export declare function isValidBranchValue(value: string): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* The header value for a branch name: characters outside printable ASCII
|
|
55
|
+
* (non-ASCII, control, space) percent-encoded as UTF-8. Undefined when the
|
|
56
|
+
* result is empty or longer than MAX_BRANCH_LENGTH.
|
|
57
|
+
*/
|
|
58
|
+
export declare function branchHeaderValue(branch: string): string | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* A reader for the checked-out branch of a local folder (`git symbolic-ref
|
|
61
|
+
* --quiet HEAD`, with `refs/heads/` stripped), cached for `ttlMs` like
|
|
62
|
+
* headCommitReader so a branch switch shows within one TTL. `--short` is not
|
|
63
|
+
* used: it prints `heads/x` when a tag `x` also exists. Returns the header value
|
|
64
|
+
* (see branchHeaderValue), or undefined (never throws) on a detached HEAD, a HEAD
|
|
65
|
+
* not under refs/heads/, a folder that is not a git repository, a git failure or
|
|
66
|
+
* timeout, or an invalid value.
|
|
67
|
+
*/
|
|
68
|
+
export declare function headBranchReader(folder: string, ttlMs?: number): () => string | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* The repository identity for a resolved KB anchor, or undefined when there is
|
|
71
|
+
* none. `remoteUrl` is set only when the folder lives on another host: then
|
|
72
|
+
* the identity is that remote and the commit and branch are unknown (git
|
|
73
|
+
* cannot run there). Otherwise the identity is the local folder's origin
|
|
74
|
+
* remote, the commit is its HEAD and the branch its checked-out branch.
|
|
75
|
+
*/
|
|
76
|
+
export declare function resolveRepositoryIdentity(folder: string, remoteUrl?: string): RepositoryIdentity | undefined;
|
|
77
|
+
//# sourceMappingURL=repository-header.d.ts.map
|