@vpxa/kb 0.1.17 → 0.1.19
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 +17 -17
- package/package.json +1 -1
- package/packages/cli/dist/commands/init/constants.d.ts +2 -1
- package/packages/cli/dist/commands/init/constants.js +1 -1
- package/packages/cli/dist/commands/init/index.d.ts +1 -1
- package/packages/cli/dist/commands/init/index.js +4 -4
- package/packages/cli/dist/commands/init/scaffold.js +1 -1
- package/packages/cli/dist/commands/init/user.d.ts +56 -0
- package/packages/cli/dist/commands/init/user.js +6 -0
- package/packages/cli/dist/commands/system.js +2 -2
- package/packages/core/dist/global-registry.d.ts +3 -3
- package/packages/core/dist/global-registry.js +1 -1
- package/packages/core/dist/index.d.ts +2 -2
- package/packages/core/dist/index.js +1 -1
- package/packages/server/dist/config.js +1 -1
- package/packages/server/dist/cross-workspace.js +1 -1
- package/packages/server/dist/tools/search.tool.js +1 -1
- package/packages/server/dist/tools/toolkit.tools.js +2 -2
- package/packages/tools/dist/dead-symbols.d.ts +0 -4
- package/packages/tools/dist/dead-symbols.js +1 -1
- package/scaffold/adapters/copilot.mjs +9 -4
- package/scaffold/definitions/agents.mjs +12 -0
- package/scaffold/definitions/bodies.mjs +35 -4
- package/scaffold/definitions/tools.mjs +4 -0
- package/scaffold/general/agents/Architect-Reviewer-Alpha.agent.md +1 -1
- package/scaffold/general/agents/Architect-Reviewer-Beta.agent.md +1 -1
- package/scaffold/general/agents/Code-Reviewer-Alpha.agent.md +1 -1
- package/scaffold/general/agents/Code-Reviewer-Beta.agent.md +1 -1
- package/scaffold/general/agents/Debugger.agent.md +1 -1
- package/scaffold/general/agents/Documenter.agent.md +8 -8
- package/scaffold/general/agents/Explorer.agent.md +1 -1
- package/scaffold/general/agents/Frontend.agent.md +1 -1
- package/scaffold/general/agents/Implementer.agent.md +1 -1
- package/scaffold/general/agents/Orchestrator.agent.md +9 -9
- package/scaffold/general/agents/Planner.agent.md +11 -11
- package/scaffold/general/agents/Refactor.agent.md +7 -7
- package/scaffold/general/agents/Researcher-Alpha.agent.md +1 -1
- package/scaffold/general/agents/Researcher-Beta.agent.md +1 -1
- package/scaffold/general/agents/Researcher-Delta.agent.md +1 -1
- package/scaffold/general/agents/Researcher-Gamma.agent.md +1 -1
- package/scaffold/general/agents/Security.agent.md +1 -1
- package/scaffold/general/agents/_shared/code-agent-base.md +0 -18
- package/scaffold/generate.mjs +13 -5
- package/packages/cli/dist/commands/init/global.d.ts +0 -34
- package/packages/cli/dist/commands/init/global.js +0 -5
- package/scaffold/copilot/agents/Architect-Reviewer-Alpha.agent.md +0 -21
- package/scaffold/copilot/agents/Architect-Reviewer-Beta.agent.md +0 -21
- package/scaffold/copilot/agents/Documenter.agent.md +0 -42
- package/scaffold/copilot/agents/Orchestrator.agent.md +0 -104
- package/scaffold/copilot/agents/Planner.agent.md +0 -54
- package/scaffold/copilot/agents/Refactor.agent.md +0 -36
- package/scaffold/copilot/agents/Researcher-Alpha.agent.md +0 -20
- package/scaffold/copilot/agents/Researcher-Beta.agent.md +0 -20
- package/scaffold/copilot/agents/Researcher-Delta.agent.md +0 -20
- package/scaffold/copilot/agents/Researcher-Gamma.agent.md +0 -20
- package/scaffold/general/agents/_shared/adr-protocol.md +0 -91
package/README.md
CHANGED
|
@@ -29,21 +29,21 @@ The KB auto-indexes configured source directories on startup, stores embeddings
|
|
|
29
29
|
|
|
30
30
|
## Quick Start
|
|
31
31
|
|
|
32
|
-
###
|
|
32
|
+
### User-Level Install (recommended for multi-project setups)
|
|
33
33
|
|
|
34
34
|
```bash
|
|
35
35
|
# Install once, works across all your projects
|
|
36
|
-
npx @vpxa/kb init --
|
|
36
|
+
npx @vpxa/kb init --user
|
|
37
37
|
|
|
38
38
|
# Then in any workspace, scaffold instructions only
|
|
39
39
|
npx @vpxa/kb init
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
###
|
|
42
|
+
### Workspace Install (per-project, self-contained)
|
|
43
43
|
|
|
44
44
|
```bash
|
|
45
|
-
# Full
|
|
46
|
-
npx @vpxa/kb init --
|
|
45
|
+
# Full workspace initialization
|
|
46
|
+
npx @vpxa/kb init --workspace
|
|
47
47
|
|
|
48
48
|
# Index and search
|
|
49
49
|
npx @vpxa/kb reindex
|
|
@@ -58,15 +58,15 @@ npx @vpxa/kb init --force # Overwrite all scaffold/skill files
|
|
|
58
58
|
npx @vpxa/kb init --guide # Check which files are outdated
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
-
> **Note:** In
|
|
61
|
+
> **Note:** In workspace mode, once `@vpxa/kb` is installed locally, you can use the short `kb` command (e.g. `kb search`, `kb serve`) since the local binary takes precedence.
|
|
62
62
|
|
|
63
|
-
##
|
|
63
|
+
## User-Level vs Workspace Mode
|
|
64
64
|
|
|
65
65
|
KB supports two installation modes:
|
|
66
66
|
|
|
67
|
-
| |
|
|
67
|
+
| | User-Level | Workspace |
|
|
68
68
|
|---|---|---|
|
|
69
|
-
| **Install** | `kb init --
|
|
69
|
+
| **Install** | `kb init --user` (once) | `kb init --workspace` (per project) |
|
|
70
70
|
| **MCP config** | User-level (IDE-wide) | `.vscode/mcp.json` (workspace) |
|
|
71
71
|
| **Data store** | `~/.kb-data/<partition>/` | `.kb-data/store/` (in project) |
|
|
72
72
|
| **Skills** | `~/.kb-data/skills/` | `.github/skills/` (in project) |
|
|
@@ -74,20 +74,20 @@ KB supports two installation modes:
|
|
|
74
74
|
|
|
75
75
|
### How it works
|
|
76
76
|
|
|
77
|
-
- **`kb init --
|
|
78
|
-
- **`kb init`** (smart default) — If
|
|
79
|
-
- **`kb init --
|
|
77
|
+
- **`kb init --user`** — Installs the MCP server in your user-level IDE config (VS Code, Cursor, Claude Code, Windsurf). Creates `~/.kb-data/` for data. Skills are shared. The server auto-indexes each workspace it's opened in.
|
|
78
|
+
- **`kb init`** (smart default) — If user-level is installed, scaffolds workspace-only files (AGENTS.md, instructions, curated directories). If not, does a full workspace install.
|
|
79
|
+
- **`kb init --workspace`** — Traditional per-project install with full local config and data store.
|
|
80
80
|
|
|
81
81
|
### Checking your mode
|
|
82
82
|
|
|
83
83
|
```bash
|
|
84
84
|
kb status
|
|
85
|
-
# Mode:
|
|
85
|
+
# Mode: user (workspace scaffolded)
|
|
86
86
|
# Data: ~/.kb-data/my-project-a1b2c3d4/
|
|
87
87
|
# Registry: 3 workspace(s) enrolled
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
-
### Cross-workspace search (
|
|
90
|
+
### Cross-workspace search (user-level mode only)
|
|
91
91
|
|
|
92
92
|
```
|
|
93
93
|
search({ query: "error handling", workspaces: ["*"] }) # All workspaces
|
|
@@ -241,7 +241,7 @@ After `kb init`, your `.vscode/mcp.json` is configured automatically:
|
|
|
241
241
|
}
|
|
242
242
|
```
|
|
243
243
|
|
|
244
|
-
> **
|
|
244
|
+
> **User-level mode:** When installed with `kb init --user`, the MCP server is configured at the user level — no per-project `mcp.json` needed. The server auto-detects and indexes each workspace.
|
|
245
245
|
|
|
246
246
|
## CLI Usage
|
|
247
247
|
|
|
@@ -313,7 +313,7 @@ kb status
|
|
|
313
313
|
kb reindex [--full]
|
|
314
314
|
kb onboard <path> [--generate] [--out-dir <dir>]
|
|
315
315
|
kb serve [--transport stdio|http] [--port N]
|
|
316
|
-
kb init [--
|
|
316
|
+
kb init [--user|--workspace] [--force] [--guide]
|
|
317
317
|
```
|
|
318
318
|
|
|
319
319
|
## Configuration
|
|
@@ -387,7 +387,7 @@ Find relevant code, docs, patterns, and curated knowledge using hybrid (vector +
|
|
|
387
387
|
| `origin` | enum | no | — | Filter: `indexed` (from files), `curated` (agent memory), `produced` (auto-generated) |
|
|
388
388
|
| `category` | string | no | — | Filter by curated category (e.g., `decisions`, `patterns`) |
|
|
389
389
|
| `tags` | string[] | no | — | Filter by tags (OR matching) |
|
|
390
|
-
| `workspaces` | string[] | no | — | Cross-workspace search: partition names, folder basenames, or `["*"]` for all.
|
|
390
|
+
| `workspaces` | string[] | no | — | Cross-workspace search: partition names, folder basenames, or `["*"]` for all. User-level mode only. |
|
|
391
391
|
| `min_score` | number (0–1) | no | 0.25 | Minimum similarity score threshold |
|
|
392
392
|
|
|
393
393
|
**Returns**: Ranked results with score, source path, content type, line range, heading path, origin, tags, and full content text. Each response includes a `_Next:` hint suggesting logical follow-up tools.
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Init module — shared constants.
|
|
4
4
|
*
|
|
5
|
-
* Single source of truth for lists used by both
|
|
5
|
+
* Single source of truth for lists used by both workspace and user-level init.
|
|
6
6
|
*/
|
|
7
7
|
/** The MCP server name used in all IDE configs. */
|
|
8
8
|
declare const SERVER_NAME = "knowledge-base";
|
|
@@ -11,6 +11,7 @@ declare const MCP_SERVER_ENTRY: {
|
|
|
11
11
|
readonly type: "stdio";
|
|
12
12
|
readonly command: "npx";
|
|
13
13
|
readonly args: readonly ["-y", "@vpxa/kb", "serve"];
|
|
14
|
+
readonly cwd: "${workspaceFolder}";
|
|
14
15
|
};
|
|
15
16
|
/** Skills shipped with the KB package and installed during init. */
|
|
16
17
|
declare const SKILL_NAMES: readonly ["knowledge-base", "brainstorming", "session-handoff", "requirements-clarity", "lesson-learned", "c4-architecture", "adr-skill"];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=`knowledge-base`,t={type:`stdio`,command:`npx`,args:[`-y`,`@vpxa/kb`,`serve`]},n=[`knowledge-base`,`brainstorming`,`session-handoff`,`requirements-clarity`,`lesson-learned`,`c4-architecture`,`adr-skill`];export{t as MCP_SERVER_ENTRY,e as SERVER_NAME,n as SKILL_NAMES};
|
|
1
|
+
const e=`knowledge-base`,t={type:`stdio`,command:`npx`,args:[`-y`,`@vpxa/kb`,`serve`],cwd:"${workspaceFolder}"},n=[`knowledge-base`,`brainstorming`,`session-handoff`,`requirements-clarity`,`lesson-learned`,`c4-architecture`,`adr-skill`];export{t as MCP_SERVER_ENTRY,e as SERVER_NAME,n as SKILL_NAMES};
|
|
@@ -17,7 +17,7 @@ declare function initProject(options: {
|
|
|
17
17
|
force: boolean;
|
|
18
18
|
}): Promise<void>;
|
|
19
19
|
/**
|
|
20
|
-
* Smart init — scaffold-only if
|
|
20
|
+
* Smart init — scaffold-only if user-level detected, full workspace otherwise.
|
|
21
21
|
*/
|
|
22
22
|
declare function initSmart(options: {
|
|
23
23
|
force: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{SKILL_NAMES as e}from"./constants.js";import{detectIde as t,getAdapter as n}from"./adapters.js";import{ensureGitignore as r,getServerName as i,writeKbConfig as a}from"./config.js";import{createCuratedDirs as o}from"./curated.js";import{copyScaffold as s,copySkills as c,guideScaffold as l,guideSkills as u}from"./scaffold.js";import{dirname as d,resolve as f}from"node:path";import{fileURLToPath as p}from"node:url";import{
|
|
1
|
+
import{SKILL_NAMES as e}from"./constants.js";import{detectIde as t,getAdapter as n}from"./adapters.js";import{ensureGitignore as r,getServerName as i,writeKbConfig as a}from"./config.js";import{createCuratedDirs as o}from"./curated.js";import{copyScaffold as s,copySkills as c,guideScaffold as l,guideSkills as u}from"./scaffold.js";import{dirname as d,resolve as f}from"node:path";import{fileURLToPath as p}from"node:url";import{isUserInstalled as m}from"../../../../core/dist/index.js";async function h(l){let u=process.cwd();if(!a(u,l.force))return;r(u);let h=i(),g=n(t(u));g.writeMcpConfig(u,h),g.writeInstructions(u,h),g.writeAgentsMd(u,h);let _=f(d(p(import.meta.url)),`..`,`..`,`..`,`..`,`..`);c(u,_,[...e],l.force),s(u,_,g.scaffoldDir,l.force),o(u),console.log(`
|
|
2
2
|
Knowledge base initialized! Next steps:`),console.log(` kb reindex Index your codebase`),console.log(` kb search Search indexed content`),console.log(` kb serve Start MCP server for IDE integration`),m()&&console.log(`
|
|
3
|
-
Note:
|
|
4
|
-
Workspace scaffolded for
|
|
5
|
-
The
|
|
3
|
+
Note: User-level KB is also installed. This workspace uses its own local data store.`)}async function g(e){m()?await _(e):await h(e)}async function _(e){let a=process.cwd(),c=i(),l=n(t(a));l.writeInstructions(a,c),l.writeAgentsMd(a,c),s(a,f(d(p(import.meta.url)),`..`,`..`,`..`,`..`,`..`),l.scaffoldDir,e.force),o(a),r(a),console.log(`
|
|
4
|
+
Workspace scaffolded for user-level KB! Files added:`),console.log(` Instruction files (AGENTS.md, copilot-instructions.md, etc.)`),console.log(` .ai/curated/ directories`),console.log(` .github/agents/ & .github/prompts/`),console.log(`
|
|
5
|
+
The user-level KB server will auto-index this workspace when opened in your IDE.`)}async function v(){let r=process.cwd(),i=n(t(r)),a=f(d(p(import.meta.url)),`..`,`..`,`..`,`..`,`..`),o=[...u(r,a,[...e]),...l(r,a,i.scaffoldDir)],s={summary:{total:o.length,new:o.filter(e=>e.status===`new`).length,outdated:o.filter(e=>e.status===`outdated`).length,current:o.filter(e=>e.status===`current`).length},files:o};console.log(JSON.stringify(s,null,2))}export{v as guideProject,h as initProject,g as initSmart};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{copyFileSync as e,existsSync as t,mkdirSync as n,readFileSync as r,readdirSync as i,statSync as a}from"node:fs";import{resolve as o}from"node:path";function s(r,c,l=``,u=!1){n(c,{recursive:!0});for(let n of i(r)){let i=o(r,n),d=o(c,n),f=l?`${l}/${n}`:n;
|
|
1
|
+
import{copyFileSync as e,existsSync as t,mkdirSync as n,readFileSync as r,readdirSync as i,statSync as a}from"node:fs";import{resolve as o}from"node:path";function s(r,c,l=``,u=!1){n(c,{recursive:!0});for(let n of i(r)){let i=o(r,n),d=o(c,n),f=l?`${l}/${n}`:n;a(i).isDirectory()?s(i,d,f,u):(u||!t(d))&&e(i,d)}}function c(e,n,s,l){if(t(e))for(let u of i(e)){let i=o(e,u),d=s?`${s}/${u}`:u;if(a(i).isDirectory())c(i,o(n,u),d,l);else{let e=o(n,u),a=r(i,`utf-8`);t(e)?a===r(e,`utf-8`)?l.push({status:`current`,relativePath:d,sourcePath:i}):l.push({status:`outdated`,relativePath:d,sourcePath:i,content:a}):l.push({status:`new`,relativePath:d,sourcePath:i,content:a})}}}function l(e,n,r,i=!1){let a=o(n,`scaffold`,r);for(let n of[`agents`,`prompts`]){let r=o(a,n),c=o(e,`.github`,n);t(r)&&s(r,c,``,i)}}function u(e,n,r,i=!1){for(let a of r){let r=o(n,`skills`,a);t(r)&&s(r,o(e,`.github`,`skills`,a),`skills/${a}`,i)}}function d(e,t,n){let r=[],i=o(t,`scaffold`,n);for(let t of[`agents`,`prompts`])c(o(i,t),o(e,`.github`,t),t,r);return r}function f(e,n,r){let i=[];for(let a of r){let r=o(n,`skills`,a);t(r)&&c(r,o(e,`.github`,`skills`,a),`skills/${a}`,i)}return i}export{s as copyDirectoryRecursive,l as copyScaffold,u as copySkills,d as guideScaffold,f as guideSkills};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
//#region packages/cli/src/commands/init/user.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* `kb init --user` — configure KB as a user-level MCP server.
|
|
4
|
+
*
|
|
5
|
+
* Auto-detects all installed IDEs, writes user-level mcp.json for each,
|
|
6
|
+
* installs skills to a user-level location, and creates the shared data store.
|
|
7
|
+
*/
|
|
8
|
+
/** Represents a user-level IDE config location. */
|
|
9
|
+
interface UserLevelIdePath {
|
|
10
|
+
ide: string;
|
|
11
|
+
configDir: string;
|
|
12
|
+
mcpConfigPath: string;
|
|
13
|
+
/**
|
|
14
|
+
* User-level scaffold root for agents/prompts/skills.
|
|
15
|
+
* VS Code: ~/.copilot, Claude Code: ~/.claude, Cursor: ~/.cursor, Windsurf: ~/.windsurf.
|
|
16
|
+
* Null if the IDE has no user-level scaffold support.
|
|
17
|
+
*/
|
|
18
|
+
globalScaffoldRoot: string | null;
|
|
19
|
+
/**
|
|
20
|
+
* User-level instruction file root (may differ from scaffold root).
|
|
21
|
+
* VS Code uses ~/.github for copilot-instructions.md but ~/.copilot for agents.
|
|
22
|
+
* When null, falls back to globalScaffoldRoot.
|
|
23
|
+
*/
|
|
24
|
+
instructionsRoot: string | null;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Detect all installed IDEs by checking if their user-level config directory exists.
|
|
28
|
+
*/
|
|
29
|
+
declare function detectInstalledIdes(): UserLevelIdePath[];
|
|
30
|
+
/**
|
|
31
|
+
* Write or merge the KB server entry into a user-level mcp.json.
|
|
32
|
+
* Preserves all existing non-KB entries. Backs up existing file before writing.
|
|
33
|
+
*/
|
|
34
|
+
declare function writeUserLevelMcpConfig(idePath: UserLevelIdePath, serverName: string, force?: boolean): void;
|
|
35
|
+
/**
|
|
36
|
+
* Install agents, prompts, skills, and instruction files to each detected IDE's
|
|
37
|
+
* global scaffold root.
|
|
38
|
+
*
|
|
39
|
+
* Each IDE has its own global discovery path:
|
|
40
|
+
* - VS Code / VSCodium: ~/.copilot/ (agents/, prompts/, skills/) + ~/.github/ (copilot-instructions.md)
|
|
41
|
+
* - Claude Code: ~/.claude/ (CLAUDE.md, agents/)
|
|
42
|
+
* - Cursor: ~/.cursor/ (rules/kb.mdc, agents/, prompts/, skills/)
|
|
43
|
+
* - Windsurf: ~/.windsurf/ (rules/kb.md, agents/, prompts/, skills/)
|
|
44
|
+
*
|
|
45
|
+
* Multiple IDEs may share the same root (e.g. VS Code + VSCodium both use ~/.copilot/).
|
|
46
|
+
* We deduplicate scaffold files but generate IDE-specific instruction files.
|
|
47
|
+
*/
|
|
48
|
+
declare function installGlobalScaffold(pkgRoot: string, ides: UserLevelIdePath[], serverName: string, force?: boolean): void;
|
|
49
|
+
/**
|
|
50
|
+
* Main orchestrator for `kb init --user`.
|
|
51
|
+
*/
|
|
52
|
+
declare function initUser(options: {
|
|
53
|
+
force: boolean;
|
|
54
|
+
}): Promise<void>;
|
|
55
|
+
//#endregion
|
|
56
|
+
export { UserLevelIdePath, detectInstalledIdes, initUser, installGlobalScaffold, writeUserLevelMcpConfig };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{MCP_SERVER_ENTRY as e,SERVER_NAME as t,SKILL_NAMES as n}from"./constants.js";import{buildAgentsMd as r,buildCopilotInstructions as i}from"./templates.js";import{copyDirectoryRecursive as a}from"./scaffold.js";import{copyFileSync as o,existsSync as s,mkdirSync as c,readFileSync as l,readdirSync as u,statSync as d,writeFileSync as f}from"node:fs";import{dirname as p,resolve as m}from"node:path";import{fileURLToPath as h}from"node:url";import{getGlobalDataDir as g,saveRegistry as _}from"../../../../core/dist/index.js";import{homedir as v}from"node:os";function y(){let e=v(),t=process.platform,n=[],r=m(e,`.copilot`),i=m(e,`.github`),a=m(e,`.claude`),o=m(e,`.cursor`),c=m(e,`.windsurf`);if(t===`win32`){let t=process.env.APPDATA??m(e,`AppData`,`Roaming`);n.push({ide:`VS Code`,configDir:m(t,`Code`,`User`),mcpConfigPath:m(t,`Code`,`User`,`mcp.json`),globalScaffoldRoot:r,instructionsRoot:i},{ide:`VS Code Insiders`,configDir:m(t,`Code - Insiders`,`User`),mcpConfigPath:m(t,`Code - Insiders`,`User`,`mcp.json`),globalScaffoldRoot:r,instructionsRoot:i},{ide:`VSCodium`,configDir:m(t,`VSCodium`,`User`),mcpConfigPath:m(t,`VSCodium`,`User`,`mcp.json`),globalScaffoldRoot:r,instructionsRoot:i},{ide:`Cursor`,configDir:m(t,`Cursor`,`User`),mcpConfigPath:m(t,`Cursor`,`User`,`mcp.json`),globalScaffoldRoot:o,instructionsRoot:null},{ide:`Cursor Nightly`,configDir:m(t,`Cursor Nightly`,`User`),mcpConfigPath:m(t,`Cursor Nightly`,`User`,`mcp.json`),globalScaffoldRoot:o,instructionsRoot:null},{ide:`Windsurf`,configDir:m(t,`Windsurf`,`User`),mcpConfigPath:m(t,`Windsurf`,`User`,`mcp.json`),globalScaffoldRoot:c,instructionsRoot:null})}else if(t===`darwin`){let t=m(e,`Library`,`Application Support`);n.push({ide:`VS Code`,configDir:m(t,`Code`,`User`),mcpConfigPath:m(t,`Code`,`User`,`mcp.json`),globalScaffoldRoot:r,instructionsRoot:i},{ide:`VS Code Insiders`,configDir:m(t,`Code - Insiders`,`User`),mcpConfigPath:m(t,`Code - Insiders`,`User`,`mcp.json`),globalScaffoldRoot:r,instructionsRoot:i},{ide:`VSCodium`,configDir:m(t,`VSCodium`,`User`),mcpConfigPath:m(t,`VSCodium`,`User`,`mcp.json`),globalScaffoldRoot:r,instructionsRoot:i},{ide:`Cursor`,configDir:m(t,`Cursor`,`User`),mcpConfigPath:m(t,`Cursor`,`User`,`mcp.json`),globalScaffoldRoot:o,instructionsRoot:null},{ide:`Cursor Nightly`,configDir:m(t,`Cursor Nightly`,`User`),mcpConfigPath:m(t,`Cursor Nightly`,`User`,`mcp.json`),globalScaffoldRoot:o,instructionsRoot:null},{ide:`Windsurf`,configDir:m(t,`Windsurf`,`User`),mcpConfigPath:m(t,`Windsurf`,`User`,`mcp.json`),globalScaffoldRoot:c,instructionsRoot:null})}else{let t=process.env.XDG_CONFIG_HOME??m(e,`.config`);n.push({ide:`VS Code`,configDir:m(t,`Code`,`User`),mcpConfigPath:m(t,`Code`,`User`,`mcp.json`),globalScaffoldRoot:r,instructionsRoot:i},{ide:`VS Code Insiders`,configDir:m(t,`Code - Insiders`,`User`),mcpConfigPath:m(t,`Code - Insiders`,`User`,`mcp.json`),globalScaffoldRoot:r,instructionsRoot:i},{ide:`VSCodium`,configDir:m(t,`VSCodium`,`User`),mcpConfigPath:m(t,`VSCodium`,`User`,`mcp.json`),globalScaffoldRoot:r,instructionsRoot:i},{ide:`Cursor`,configDir:m(t,`Cursor`,`User`),mcpConfigPath:m(t,`Cursor`,`User`,`mcp.json`),globalScaffoldRoot:o,instructionsRoot:null},{ide:`Cursor Nightly`,configDir:m(t,`Cursor Nightly`,`User`),mcpConfigPath:m(t,`Cursor Nightly`,`User`,`mcp.json`),globalScaffoldRoot:o,instructionsRoot:null},{ide:`Windsurf`,configDir:m(t,`Windsurf`,`User`),mcpConfigPath:m(t,`Windsurf`,`User`,`mcp.json`),globalScaffoldRoot:c,instructionsRoot:null})}return n.push({ide:`Claude Code`,configDir:m(e,`.claude`),mcpConfigPath:m(e,`.claude`,`mcp.json`),globalScaffoldRoot:a,instructionsRoot:null}),n.filter(e=>s(e.configDir))}function b(t,n,r=!1){let{mcpConfigPath:i,configDir:a}=t,o={...e},u={};if(s(i)){try{let e=l(i,`utf-8`);u=JSON.parse(e)}catch{let e=`${i}.bak`;f(e,l(i,`utf-8`),`utf-8`),console.log(` Backed up invalid ${i} to ${e}`),u={}}if((u.servers??u.mcpServers??{})[n]&&!r){console.log(` ${t.ide}: ${n} already configured (use --force to update)`);return}}let d=new Set([`VS Code`,`VS Code Insiders`,`VSCodium`,`Windsurf`]).has(t.ide)?`servers`:`mcpServers`,p=u[d]??{};p[n]=o,u[d]=p,c(a,{recursive:!0}),f(i,`${JSON.stringify(u,null,2)}\n`,`utf-8`),console.log(` ${t.ide}: configured ${n} in ${i}`)}function x(e,t,n,r){let i=m(t,n);c(i,{recursive:!0});let l=m(e,`scaffold`,`general`,n);if(!s(l))return 0;let f=0;for(let e of u(l)){let t=m(l,e),c=m(i,e);d(t).isDirectory()?a(t,c,`${n}/${e}`,r):(r||!s(c))&&(o(t,c),f++)}return f}function S(e,t,o,l=!1){let u=new Set;for(let e of t)e.globalScaffoldRoot&&u.add(e.globalScaffoldRoot);if(u.size===0){console.log(` No IDEs with global scaffold support detected.`);return}for(let t of u){let r=x(e,t,`agents`,l),i=x(e,t,`prompts`,l),o=m(t,`skills`),c=0;for(let t of n){let n=m(e,`skills`,t);s(n)&&(a(n,m(o,t),`skills/${t}`,l),c++)}console.log(` ${t}: ${r} agents, ${i} prompts, ${c} skills`)}let d=new Set,p=i(`kb`,o),h=r(`kb`,o);for(let e of t){if(!e.globalScaffoldRoot)continue;let t=e.globalScaffoldRoot;if(e.ide===`Claude Code`){let e=m(t,`CLAUDE.md`);(l||!s(e))&&(f(e,`${p}\n---\n\n${h}`,`utf-8`),d.add(e))}else if(e.ide===`VS Code`||e.ide===`VS Code Insiders`||e.ide===`VSCodium`){let n=e.instructionsRoot??t;c(n,{recursive:!0});let r=m(n,`copilot-instructions.md`);d.has(r)||(l||!s(r))&&(f(r,`${p}\n---\n\n${h}`,`utf-8`),d.add(r))}else if(e.ide===`Cursor`||e.ide===`Cursor Nightly`){let e=m(t,`rules`);c(e,{recursive:!0});let n=m(e,`kb.mdc`);d.has(n)||(l||!s(n))&&(f(n,`${p}\n---\n\n${h}`,`utf-8`),d.add(n))}else if(e.ide===`Windsurf`){let e=m(t,`rules`);c(e,{recursive:!0});let n=m(e,`kb.md`);d.has(n)||(l||!s(n))&&(f(n,`${p}\n---\n\n${h}`,`utf-8`),d.add(n))}}d.size>0&&console.log(` Instruction files: ${[...d].join(`, `)}`)}async function C(e){let n=t;console.log(`Initializing user-level KB installation...
|
|
2
|
+
`);let r=g();c(r,{recursive:!0}),console.log(` Global data store: ${r}`),_({version:1,workspaces:{}}),console.log(` Created registry.json`);let i=y();if(i.length===0)console.log(`
|
|
3
|
+
No supported IDEs detected. You can manually add the MCP server config.`);else{console.log(`\n Detected ${i.length} IDE(s):`);for(let t of i)b(t,n,e.force)}let a=m(p(h(import.meta.url)),`..`,`..`,`..`,`..`,`..`);console.log(`
|
|
4
|
+
Installing scaffold files:`),S(a,i,n,e.force),console.log(`
|
|
5
|
+
User-level KB installation complete!`),console.log(`
|
|
6
|
+
Next steps:`),console.log(` 1. Open any workspace in your IDE`),console.log(` 2. The KB server will auto-start and index the workspace`),console.log(` 3. Agents, prompts, skills & instructions are available globally`),console.log(` 4. No per-workspace init needed — just open a project and start coding`)}export{y as detectInstalledIdes,C as initUser,S as installGlobalScaffold,b as writeUserLevelMcpConfig};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{ctx as e}from"../context.js";import{executeCliBatchOperation as t,extractStrFlag as n,parseBatchPayload as r,printCheckResult as i,readInput as a}from"../helpers.js";import{dirname as o,resolve as s}from"node:path";import{fileURLToPath as c}from"node:url";import{audit as l,batch as u,check as d,guide as f,health as p,replayClear as m,replayList as h,replayTrim as g}from"../../../tools/dist/index.js";import{fork as _}from"node:child_process";const v=o(c(import.meta.url)),y=[{name:`status`,description:`Show knowledge base index status and statistics`,run:async()=>{let{
|
|
2
|
-
`)},c;n?(console.log(`Dropping existing index for full reindex...`),c=await i.reindexAll(o,s)):c=await i.index(o,s),console.log(`Done: ${c.filesProcessed} files, ${c.chunksCreated} chunks in ${(c.durationMs/1e3).toFixed(1)}s`),console.log(`Building FTS index...`),await r.createFtsIndex(),console.log(`Re-indexing curated entries...`);let l=await a.reindexAll();console.log(`Curated: ${l.indexed} entries restored`)}},{name:`serve`,description:`Start the MCP server (stdio or HTTP)`,usage:`kb serve [--transport stdio|http] [--port N]`,run:async e=>{let t=s(v,`..`,`..`,`..`,`server`,`dist`,`index.js`),r=n(e,`--transport`,`stdio`),i=n(e,`--port`,`3210`),a=_(t,[],{stdio:r===`stdio`?[`pipe`,`pipe`,`inherit`,`ipc`]:`inherit`,env:{...process.env,KB_TRANSPORT:r,KB_PORT:i}});r===`stdio`&&a.stdin&&a.stdout&&(process.stdin.pipe(a.stdin),a.stdout.pipe(process.stdout)),a.on(`exit`,e=>process.exit(e??0)),process.on(`SIGINT`,()=>a.kill(`SIGINT`)),process.on(`SIGTERM`,()=>a.kill(`SIGTERM`)),await new Promise(()=>{})}},{name:`init`,description:`Initialize a knowledge base in the current directory`,usage:`kb init [--
|
|
1
|
+
import{ctx as e}from"../context.js";import{executeCliBatchOperation as t,extractStrFlag as n,parseBatchPayload as r,printCheckResult as i,readInput as a}from"../helpers.js";import{dirname as o,resolve as s}from"node:path";import{fileURLToPath as c}from"node:url";import{audit as l,batch as u,check as d,guide as f,health as p,replayClear as m,replayList as h,replayTrim as g}from"../../../tools/dist/index.js";import{fork as _}from"node:child_process";const v=o(c(import.meta.url)),y=[{name:`status`,description:`Show knowledge base index status and statistics`,run:async()=>{let{isUserInstalled:t,getGlobalDataDir:n,computePartitionKey:r,listWorkspaces:i}=await import(`../../../core/dist/index.js`),{existsSync:a}=await import(`node:fs`),o=process.cwd(),c=t(),l=a(s(o,`.vscode`,`mcp.json`)),u,d;if(c&&l)u=`workspace (overrides user-level for this workspace)`,d=s(o,`.kb-data`);else if(c){let e=r(o);u=a(s(o,`AGENTS.md`))?`user (workspace scaffolded)`:`user (workspace not scaffolded)`,d=s(n(),e)}else u=`workspace`,d=s(o,`.kb-data`);if(console.log(`Knowledge Base Status`),console.log(`─`.repeat(40)),console.log(` Mode: ${u}`),console.log(` Data: ${d}`),c&&!l){let e=i();console.log(` Registry: ${e.length} workspace(s) enrolled`)}try{let{store:t}=await e(),n=await t.getStats(),r=await t.listSourcePaths();console.log(` Records: ${n.totalRecords}`),console.log(` Files: ${n.totalFiles}`),console.log(` Indexed: ${n.lastIndexedAt??`Never`}`),console.log(` Backend: ${n.storeBackend}`),console.log(` Model: ${n.embeddingModel}`),console.log(``),console.log(`Content Types:`);for(let[e,t]of Object.entries(n.contentTypeBreakdown))console.log(` ${e}: ${t}`);if(r.length>0){console.log(``),console.log(`Files (${r.length} total):`);for(let e of r.slice(0,20))console.log(` ${e}`);r.length>20&&console.log(` ... and ${r.length-20} more`)}}catch{console.log(``),console.log(" Index not available — run `kb reindex` to index this workspace.")}c&&!l&&!a(s(o,`AGENTS.md`))&&(console.log(``),console.log(" Action: Run `npx @vpxa/kb init` to add AGENTS.md and copilot-instructions.md"))}},{name:`reindex`,description:`Re-index the knowledge base from configured sources`,usage:`kb reindex [--full]`,run:async t=>{let n=t.includes(`--full`),{store:r,indexer:i,curated:a,config:o}=await e();console.log(`Indexing sources...`);let s=e=>{e.phase===`chunking`&&e.currentFile&&process.stdout.write(`\r [${e.filesProcessed+1}/${e.filesTotal}] ${e.currentFile}`),e.phase===`done`&&process.stdout.write(`
|
|
2
|
+
`)},c;n?(console.log(`Dropping existing index for full reindex...`),c=await i.reindexAll(o,s)):c=await i.index(o,s),console.log(`Done: ${c.filesProcessed} files, ${c.chunksCreated} chunks in ${(c.durationMs/1e3).toFixed(1)}s`),console.log(`Building FTS index...`),await r.createFtsIndex(),console.log(`Re-indexing curated entries...`);let l=await a.reindexAll();console.log(`Curated: ${l.indexed} entries restored`)}},{name:`serve`,description:`Start the MCP server (stdio or HTTP)`,usage:`kb serve [--transport stdio|http] [--port N]`,run:async e=>{let t=s(v,`..`,`..`,`..`,`server`,`dist`,`index.js`),r=n(e,`--transport`,`stdio`),i=n(e,`--port`,`3210`),a=_(t,[],{stdio:r===`stdio`?[`pipe`,`pipe`,`inherit`,`ipc`]:`inherit`,env:{...process.env,KB_TRANSPORT:r,KB_PORT:i}});r===`stdio`&&a.stdin&&a.stdout&&(process.stdin.pipe(a.stdin),a.stdout.pipe(process.stdout)),a.on(`exit`,e=>process.exit(e??0)),process.on(`SIGINT`,()=>a.kill(`SIGINT`)),process.on(`SIGTERM`,()=>a.kill(`SIGTERM`)),await new Promise(()=>{})}},{name:`init`,description:`Initialize a knowledge base in the current directory`,usage:`kb init [--user|--workspace] [--force] [--guide]`,run:async e=>{let t=e.includes(`--user`),n=e.includes(`--workspace`),r=e.includes(`--guide`),i=e.includes(`--force`);if(t&&n&&(console.error(`Cannot use --user and --workspace together.`),process.exit(1)),r){let{guideProject:e}=await import(`./init/index.js`);await e();return}if(t){let{initUser:e}=await import(`./init/user.js`);await e({force:i})}else if(n){let{initProject:e}=await import(`./init/index.js`);await e({force:i})}else{let{initSmart:e}=await import(`./init/index.js`);await e({force:i})}}},{name:`check`,description:`Run incremental typecheck and lint`,usage:`kb check [--cwd <dir>] [--files f1,f2] [--skip-types] [--skip-lint] [--detail summary|errors|full]`,run:async e=>{let t=n(e,`--cwd`,``).trim()||void 0,r=n(e,`--files`,``),a=n(e,`--detail`,`full`)||`full`,o=r.split(`,`).map(e=>e.trim()).filter(Boolean),s=!1;e.includes(`--skip-types`)&&(e.splice(e.indexOf(`--skip-types`),1),s=!0);let c=!1;e.includes(`--skip-lint`)&&(e.splice(e.indexOf(`--skip-lint`),1),c=!0);let l=await d({cwd:t,files:o.length>0?o:void 0,skipTypes:s,skipLint:c,detail:a});i(l),l.passed||(process.exitCode=1)}},{name:`batch`,description:`Execute built-in operations from JSON input`,usage:`kb batch [--file path] [--concurrency N]`,run:async i=>{let o=n(i,`--file`,``).trim()||void 0,s=(()=>{let e=i.indexOf(`--concurrency`);if(e===-1||e+1>=i.length)return 0;let t=Number.parseInt(i.splice(e,2)[1],10);return Number.isNaN(t)?0:t})(),c=await a(o);c.trim()||(console.error(`Usage: kb batch [--file path] [--concurrency N]`),process.exit(1));let l=r(c),d=s>0?s:l.concurrency,f=l.operations.some(e=>e.type!==`check`)?await e():null,p=await u(l.operations,async e=>t(e,f),{concurrency:d});console.log(JSON.stringify(p,null,2)),p.some(e=>e.status===`error`)&&(process.exitCode=1)}},{name:`health`,description:`Run project health checks on the current directory`,usage:`kb health [path]`,run:async e=>{let t=p(e.shift());console.log(`Project Health: ${t.path}`),console.log(`─`.repeat(50));for(let e of t.checks){let t=e.status===`pass`?`+`:e.status===`warn`?`~`:`X`;console.log(` [${t}] ${e.name}: ${e.message}`)}console.log(`─`.repeat(50)),console.log(`Score: ${t.score}% — ${t.summary}`)}},{name:`audit`,description:`Run a unified project audit (structure, deps, patterns, health, dead symbols, check)`,usage:`kb audit [path] [--checks structure,dependencies,patterns,health,dead_symbols,check,entry_points] [--detail summary|full]`,run:async t=>{let{store:r,embedder:i}=await e(),a=n(t,`--detail`,`summary`)||`summary`,o=n(t,`--checks`,``),s=o?o.split(`,`).map(e=>e.trim()):void 0,c=await l(r,i,{path:t.shift()||`.`,checks:s,detail:a});if(c.ok){if(console.log(c.summary),c.next&&c.next.length>0){console.log(`
|
|
3
3
|
Suggested next steps:`);for(let e of c.next)console.log(` → ${e.tool}: ${e.reason}`)}}else console.error(c.error?.message??`Audit failed`),process.exitCode=1}},{name:`guide`,description:`Tool discovery — recommend KB tools for a given goal`,usage:`kb guide <goal> [--max N]`,run:async e=>{let t=e.indexOf(`--max`),n=5;t!==-1&&t+1<e.length&&(n=Number.parseInt(e.splice(t,2)[1],10)||5);let r=e.join(` `).trim();r||(console.error(`Usage: kb guide <goal> [--max N]`),console.error(`Example: kb guide "audit this project"`),process.exit(1));let i=f(r,n);console.log(`Workflow: ${i.workflow}`),console.log(` ${i.description}\n`),console.log(`Recommended tools:`);for(let e of i.tools){let t=e.suggestedArgs?` ${JSON.stringify(e.suggestedArgs)}`:``;console.log(` ${e.order}. ${e.tool} — ${e.reason}${t}`)}i.alternativeWorkflows.length>0&&console.log(`\nAlternatives: ${i.alternativeWorkflows.join(`, `)}`)}},{name:`replay`,description:`Show recent tool invocation audit trail`,usage:`kb replay [--last N] [--tool <name>] [--source mcp|cli]`,run:async e=>{let t=h({last:Number.parseInt(e[e.indexOf(`--last`)+1],10)||20,tool:e.includes(`--tool`)?e[e.indexOf(`--tool`)+1]:void 0,source:e.includes(`--source`)?e[e.indexOf(`--source`)+1]:void 0});if(t.length===0){console.log(`No replay entries. Activity is logged when tools are invoked.`);return}console.log(`Replay Log (${t.length} entries)\n`);for(let e of t){let t=e.ts.split(`T`)[1]?.split(`.`)[0]??e.ts,n=e.status===`ok`?`✓`:`✗`;console.log(`${t} ${n} ${e.tool} (${e.durationMs}ms) [${e.source}]`),console.log(` in: ${e.input}`),console.log(` out: ${e.output}`)}g()}},{name:`replay-clear`,description:`Clear the replay audit trail`,run:async()=>{m(),console.log(`Replay log cleared.`)}},{name:`tui`,description:`Launch interactive terminal dashboard (human monitoring)`,run:async()=>{try{let{launch:t}=await import(`../../../tui/dist/index.js`),{store:n,embedder:r,config:i}=await e();t({store:n,embedder:r,config:i})}catch(e){throw e.code===`ERR_MODULE_NOT_FOUND`&&(console.error(`TUI requires ink and react. Install them with:
|
|
4
4
|
pnpm add -D ink react @types/react`),process.exit(1)),e}}}];export{y as systemCommands};
|
|
@@ -56,8 +56,8 @@ declare function listWorkspaces(): RegistryEntry[];
|
|
|
56
56
|
*/
|
|
57
57
|
declare function getPartitionDir(partition: string): string;
|
|
58
58
|
/**
|
|
59
|
-
* Check whether
|
|
59
|
+
* Check whether user-level mode is installed (registry.json exists in ~/.kb-data/).
|
|
60
60
|
*/
|
|
61
|
-
declare function
|
|
61
|
+
declare function isUserInstalled(): boolean;
|
|
62
62
|
//#endregion
|
|
63
|
-
export { GlobalRegistry, RegistryEntry, computePartitionKey, getGlobalDataDir, getPartitionDir,
|
|
63
|
+
export { GlobalRegistry, RegistryEntry, computePartitionKey, getGlobalDataDir, getPartitionDir, isUserInstalled, listWorkspaces, loadRegistry, lookupWorkspace, registerWorkspace, saveRegistry };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{KB_GLOBAL_PATHS as e}from"./constants.js";import{basename as t,resolve as n}from"node:path";import{createHash as r}from"node:crypto";import{closeSync as i,constants as a,existsSync as o,mkdirSync as s,openSync as c,readFileSync as l,renameSync as u,statSync as d,unlinkSync as f,writeFileSync as p}from"node:fs";import{homedir as m}from"node:os";function h(){return process.env.KB_GLOBAL_DATA_DIR??n(m(),e.root)}function g(e){let i=n(e);return`${t(i).toLowerCase().replace(/[^a-z0-9-]/g,`-`)||`workspace`}-${r(`sha256`).update(i).digest(`hex`).slice(0,8)}`}function _(){let t=n(h(),e.registry);if(!o(t))return{version:1,workspaces:{}};let r=l(t,`utf-8`);return JSON.parse(r)}function v(e,t=5e3){let n=`${e}.lock`,r=Date.now()+t,o=10;for(;Date.now()<r;)try{let e=c(n,a.O_CREAT|a.O_EXCL|a.O_WRONLY);return p(e,`${process.pid}\n`),i(e),n}catch(e){if(e.code!==`EEXIST`)throw e;try{let{mtimeMs:e}=d(n);if(Date.now()-e>3e4){f(n);continue}}catch{}let t=new SharedArrayBuffer(4);Atomics.wait(new Int32Array(t),0,0,o),o=Math.min(o*2,200)}throw Error(`Failed to acquire registry lock after ${t}ms`)}function y(e){try{f(e)}catch{}}function b(t){let r=h();s(r,{recursive:!0});let i=n(r,e.registry),a=v(i);try{let e=`${i}.tmp`;p(e,JSON.stringify(t,null,2),`utf-8`),u(e,i)}finally{y(a)}}function x(e){let t=_(),r=g(e),i=new Date().toISOString();return t.workspaces[r]?t.workspaces[r].lastAccessedAt=i:t.workspaces[r]={partition:r,workspacePath:n(e),registeredAt:i,lastAccessedAt:i},s(w(r),{recursive:!0}),b(t),t.workspaces[r]}function S(e){let t=_(),n=g(e);return t.workspaces[n]}function C(){let e=_();return Object.values(e.workspaces)}function w(e){return n(h(),e)}function T(){return o(n(h(),e.registry))}export{g as computePartitionKey,h as getGlobalDataDir,w as getPartitionDir,T as
|
|
1
|
+
import{KB_GLOBAL_PATHS as e}from"./constants.js";import{basename as t,resolve as n}from"node:path";import{createHash as r}from"node:crypto";import{closeSync as i,constants as a,existsSync as o,mkdirSync as s,openSync as c,readFileSync as l,renameSync as u,statSync as d,unlinkSync as f,writeFileSync as p}from"node:fs";import{homedir as m}from"node:os";function h(){return process.env.KB_GLOBAL_DATA_DIR??n(m(),e.root)}function g(e){let i=n(e);return`${t(i).toLowerCase().replace(/[^a-z0-9-]/g,`-`)||`workspace`}-${r(`sha256`).update(i).digest(`hex`).slice(0,8)}`}function _(){let t=n(h(),e.registry);if(!o(t))return{version:1,workspaces:{}};let r=l(t,`utf-8`);return JSON.parse(r)}function v(e,t=5e3){let n=`${e}.lock`,r=Date.now()+t,o=10;for(;Date.now()<r;)try{let e=c(n,a.O_CREAT|a.O_EXCL|a.O_WRONLY);return p(e,`${process.pid}\n`),i(e),n}catch(e){if(e.code!==`EEXIST`)throw e;try{let{mtimeMs:e}=d(n);if(Date.now()-e>3e4){f(n);continue}}catch{}let t=new SharedArrayBuffer(4);Atomics.wait(new Int32Array(t),0,0,o),o=Math.min(o*2,200)}throw Error(`Failed to acquire registry lock after ${t}ms`)}function y(e){try{f(e)}catch{}}function b(t){let r=h();s(r,{recursive:!0});let i=n(r,e.registry),a=v(i);try{let e=`${i}.tmp`;p(e,JSON.stringify(t,null,2),`utf-8`),u(e,i)}finally{y(a)}}function x(e){let t=_(),r=g(e),i=new Date().toISOString();return t.workspaces[r]?t.workspaces[r].lastAccessedAt=i:t.workspaces[r]={partition:r,workspacePath:n(e),registeredAt:i,lastAccessedAt:i},s(w(r),{recursive:!0}),b(t),t.workspaces[r]}function S(e){let t=_(),n=g(e);return t.workspaces[n]}function C(){let e=_();return Object.values(e.workspaces)}function w(e){return n(h(),e)}function T(){return o(n(h(),e.registry))}export{g as computePartitionKey,h as getGlobalDataDir,w as getPartitionDir,T as isUserInstalled,C as listWorkspaces,_ as loadRegistry,S as lookupWorkspace,x as registerWorkspace,b as saveRegistry};
|
|
@@ -2,6 +2,6 @@ import { CATEGORY_PATTERN, CHUNK_SIZES, DEFAULT_CATEGORIES, EMBEDDING_DEFAULTS,
|
|
|
2
2
|
import { CONTENT_TYPES, ChunkMetadata, ContentType, IndexStats, KBConfig, KNOWLEDGE_ORIGINS, KnowledgeOrigin, KnowledgeRecord, RawChunk, SOURCE_TYPES, SearchResult, SourceType } from "./types.js";
|
|
3
3
|
import { contentTypeToSourceType, detectContentType, sourceTypeContentTypes } from "./content-detector.js";
|
|
4
4
|
import { ConfigError, EmbeddingError, IndexError, KBError, StoreError } from "./errors.js";
|
|
5
|
-
import { GlobalRegistry, RegistryEntry, computePartitionKey, getGlobalDataDir, getPartitionDir,
|
|
5
|
+
import { GlobalRegistry, RegistryEntry, computePartitionKey, getGlobalDataDir, getPartitionDir, isUserInstalled, listWorkspaces, loadRegistry, lookupWorkspace, registerWorkspace, saveRegistry } from "./global-registry.js";
|
|
6
6
|
import { LogLevel, createLogger, getLogLevel, resetLogDir, serializeError, setFileSinkEnabled, setLogLevel } from "./logger.js";
|
|
7
|
-
export { CATEGORY_PATTERN, CHUNK_SIZES, CONTENT_TYPES, ChunkMetadata, ConfigError, ContentType, DEFAULT_CATEGORIES, EMBEDDING_DEFAULTS, EmbeddingError, FILE_LIMITS, GlobalRegistry, IndexError, IndexStats, KBConfig, KBError, KB_GLOBAL_PATHS, KB_PATHS, KNOWLEDGE_ORIGINS, KnowledgeOrigin, KnowledgeRecord, LogLevel, RawChunk, RegistryEntry, SEARCH_DEFAULTS, SOURCE_TYPES, STORE_DEFAULTS, SearchResult, SourceType, StoreError, computePartitionKey, contentTypeToSourceType, createLogger, detectContentType, getGlobalDataDir, getLogLevel, getPartitionDir,
|
|
7
|
+
export { CATEGORY_PATTERN, CHUNK_SIZES, CONTENT_TYPES, ChunkMetadata, ConfigError, ContentType, DEFAULT_CATEGORIES, EMBEDDING_DEFAULTS, EmbeddingError, FILE_LIMITS, GlobalRegistry, IndexError, IndexStats, KBConfig, KBError, KB_GLOBAL_PATHS, KB_PATHS, KNOWLEDGE_ORIGINS, KnowledgeOrigin, KnowledgeRecord, LogLevel, RawChunk, RegistryEntry, SEARCH_DEFAULTS, SOURCE_TYPES, STORE_DEFAULTS, SearchResult, SourceType, StoreError, computePartitionKey, contentTypeToSourceType, createLogger, detectContentType, getGlobalDataDir, getLogLevel, getPartitionDir, isUserInstalled, listWorkspaces, loadRegistry, lookupWorkspace, registerWorkspace, resetLogDir, saveRegistry, serializeError, setFileSinkEnabled, setLogLevel, sourceTypeContentTypes };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{CATEGORY_PATTERN as e,CHUNK_SIZES as t,DEFAULT_CATEGORIES as n,EMBEDDING_DEFAULTS as r,FILE_LIMITS as i,KB_GLOBAL_PATHS as a,KB_PATHS as o,SEARCH_DEFAULTS as s,STORE_DEFAULTS as c}from"./constants.js";import{contentTypeToSourceType as l,detectContentType as u,sourceTypeContentTypes as d}from"./content-detector.js";import{ConfigError as f,EmbeddingError as p,IndexError as m,KBError as h,StoreError as g}from"./errors.js";import{computePartitionKey as _,getGlobalDataDir as v,getPartitionDir as y,
|
|
1
|
+
import{CATEGORY_PATTERN as e,CHUNK_SIZES as t,DEFAULT_CATEGORIES as n,EMBEDDING_DEFAULTS as r,FILE_LIMITS as i,KB_GLOBAL_PATHS as a,KB_PATHS as o,SEARCH_DEFAULTS as s,STORE_DEFAULTS as c}from"./constants.js";import{contentTypeToSourceType as l,detectContentType as u,sourceTypeContentTypes as d}from"./content-detector.js";import{ConfigError as f,EmbeddingError as p,IndexError as m,KBError as h,StoreError as g}from"./errors.js";import{computePartitionKey as _,getGlobalDataDir as v,getPartitionDir as y,isUserInstalled as b,listWorkspaces as x,loadRegistry as S,lookupWorkspace as C,registerWorkspace as w,saveRegistry as T}from"./global-registry.js";import{createLogger as E,getLogLevel as D,resetLogDir as O,serializeError as k,setFileSinkEnabled as A,setLogLevel as j}from"./logger.js";import{CONTENT_TYPES as M,KNOWLEDGE_ORIGINS as N,SOURCE_TYPES as P}from"./types.js";export{e as CATEGORY_PATTERN,t as CHUNK_SIZES,M as CONTENT_TYPES,f as ConfigError,n as DEFAULT_CATEGORIES,r as EMBEDDING_DEFAULTS,p as EmbeddingError,i as FILE_LIMITS,m as IndexError,h as KBError,a as KB_GLOBAL_PATHS,o as KB_PATHS,N as KNOWLEDGE_ORIGINS,s as SEARCH_DEFAULTS,P as SOURCE_TYPES,c as STORE_DEFAULTS,g as StoreError,_ as computePartitionKey,l as contentTypeToSourceType,E as createLogger,u as detectContentType,v as getGlobalDataDir,D as getLogLevel,y as getPartitionDir,b as isUserInstalled,x as listWorkspaces,S as loadRegistry,C as lookupWorkspace,w as registerWorkspace,O as resetLogDir,T as saveRegistry,k as serializeError,A as setFileSinkEnabled,j as setLogLevel,d as sourceTypeContentTypes};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as e,readFileSync as t}from"node:fs";import{dirname as n,resolve as r}from"node:path";import{fileURLToPath as i}from"node:url";import{KB_PATHS as a,createLogger as o,getPartitionDir as s,
|
|
1
|
+
import{existsSync as e,readFileSync as t}from"node:fs";import{dirname as n,resolve as r}from"node:path";import{fileURLToPath as i}from"node:url";import{KB_PATHS as a,createLogger as o,getPartitionDir as s,isUserInstalled as c,registerWorkspace as l,serializeError as u}from"../../core/dist/index.js";const d=n(i(import.meta.url)),f=o(`server`);function p(e,t,n){let i=r(e),a=r(t);if(!i.startsWith(a))throw Error(`Config ${n} path escapes workspace root: ${e} is not under ${t}`);return i}function m(){let i=process.env.KB_CONFIG_PATH??(e(r(process.cwd(),`kb.config.json`))?r(process.cwd(),`kb.config.json`):r(d,`..`,`..`,`..`,`kb.config.json`));try{let e=t(i,`utf-8`),o=JSON.parse(e);if(!o.sources||!Array.isArray(o.sources)||o.sources.length===0)throw Error(`Config must have at least one source`);if(!o.store?.path)throw Error(`Config must specify store.path`);let s=n(i);return o.sources=o.sources.map(e=>({...e,path:p(r(s,e.path),s,`source`)})),o.store.path=p(r(s,o.store.path),s,`store`),o.curated=o.curated??{path:a.aiCurated},o.curated.path=p(r(s,o.curated.path),s,`curated`),g(o,s),o}catch(e){return f.error(`Failed to load config`,{configPath:i,...u(e)}),f.warn(`Falling back to default configuration`,{configPath:i}),h()}}function h(){let e=process.env.KB_WORKSPACE_ROOT??process.cwd(),t={sources:[{path:e,excludePatterns:[`node_modules/**`,`dist/**`,`.git/**`,`coverage/**`,`*.lock`,`pnpm-lock.yaml`]}],serverName:`knowledge-base`,indexing:{chunkSize:1500,chunkOverlap:200,minChunkSize:100},embedding:{model:`mixedbread-ai/mxbai-embed-large-v1`,dimensions:1024},store:{backend:`lancedb`,path:r(e,a.data)},curated:{path:r(e,a.aiCurated)}};return g(t,e),t}function g(e,t){if(!c())return;let n=t,i=l(n);e.store.path=r(s(i.partition)),e.curated||={path:r(n,a.aiCurated)}}export{m as loadConfig};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createLogger as e,getPartitionDir as t,
|
|
1
|
+
import{createLogger as e,getPartitionDir as t,isUserInstalled as n,listWorkspaces as r}from"../../core/dist/index.js";import{createStore as i}from"../../store/dist/index.js";const a=e(`cross-workspace`);function o(e,t){if(!n())return[];let i=r();if(i.length===0)return[];if(e.includes(`*`))return t?i.filter(e=>e.partition!==t):i;let a=[];for(let n of e){let e=i.find(e=>e.partition===n);if(e){e.partition!==t&&a.push(e);continue}let r=i.filter(e=>e.partition!==t&&e.partition.replace(/-[a-f0-9]{8}$/,``)===n.toLowerCase());a.push(...r)}let o=new Set;return a.filter(e=>o.has(e.partition)?!1:(o.add(e.partition),!0))}async function s(e){let n=new Map;for(let r of e)try{let e=await i({backend:`lancedb`,path:t(r.partition)});await e.initialize(),n.set(r.partition,e)}catch(e){a.warn(`Failed to open workspace store`,{partition:r.partition,err:e})}return{stores:n,closeAll:async()=>{for(let[,e]of n)try{await e.close()}catch{}}}}async function c(e,t,n){let r=[...e.entries()].map(async([e,r])=>{try{return(await r.search(t,n)).map(t=>({...t,workspace:e}))}catch(t){return a.warn(`Cross-workspace search failed for partition`,{partition:e,err:t}),[]}});return(await Promise.all(r)).flat().sort((e,t)=>t.score-e.score).slice(0,n.limit)}async function l(e,t,n){let r=[...e.entries()].map(async([e,r])=>{try{return(await r.ftsSearch(t,n)).map(t=>({...t,workspace:e}))}catch(t){return a.warn(`Cross-workspace FTS search failed for partition`,{partition:e,err:t}),[]}});return(await Promise.all(r)).flat().sort((e,t)=>t.score-e.score).slice(0,n.limit)}export{l as fanOutFtsSearch,c as fanOutSearch,s as openWorkspaceStores,o as resolveWorkspaces};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{fanOutFtsSearch as e,fanOutSearch as t,openWorkspaceStores as n,resolveWorkspaces as r}from"../cross-workspace.js";import{stat as i}from"node:fs/promises";import{CONTENT_TYPES as a,KNOWLEDGE_ORIGINS as o,SOURCE_TYPES as s,computePartitionKey as c,createLogger as l,serializeError as u}from"../../../core/dist/index.js";import{graphAugmentSearch as d,truncateToTokenBudget as f}from"../../../tools/dist/index.js";import{z as p}from"zod";import{mergeResults as m}from"../../../enterprise-bridge/dist/index.js";const h=l(`tools`);async function g(e,t,n,r,i){if(!e||t>=e.config.fallbackThreshold&&n.length>0)return{results:n,triggered:!1,cacheHit:!1};let a=!1;try{let t=e.cache.get(r);return t?a=!0:(t=await e.client.search(r,i),t.length>0&&e.cache.set(r,t)),t.length>0?{results:m(n,t,i).map(e=>({record:{id:`er:${e.sourcePath}`,content:e.content,sourcePath:e.source===`er`?`[ER] ${e.sourcePath}`:e.sourcePath,startLine:e.startLine??0,endLine:e.endLine??0,contentType:e.contentType??`documentation`,headingPath:e.headingPath,origin:e.source===`er`?`curated`:e.origin??`indexed`,category:e.category,tags:e.tags??[],chunkIndex:0,totalChunks:1,fileHash:``,indexedAt:new Date().toISOString(),version:1},score:e.score})),triggered:!0,cacheHit:a}:{results:n,triggered:!0,cacheHit:a}}catch(e){return h.warn(`ER fallback failed`,u(e)),{results:n,triggered:!0,cacheHit:a}}}function _(e,t,n=60){let r=new Map;for(let t=0;t<e.length;t++){let i=e[t];r.set(i.record.id,{record:i.record,score:1/(n+t+1)})}for(let e=0;e<t.length;e++){let i=t[e],a=r.get(i.record.id);a?a.score+=1/(n+e+1):r.set(i.record.id,{record:i.record,score:1/(n+e+1)})}return[...r.values()].sort((e,t)=>t.score-e.score).map(({record:e,score:t})=>({record:e,score:t}))}function v(e,t){let n=t.toLowerCase().split(/\s+/).filter(e=>e.length>=2);return n.length<2?e:e.map(e=>{let t=e.record.content.toLowerCase(),r=n.map(e=>{let n=[],r=t.indexOf(e);for(;r!==-1;)n.push(r),r=t.indexOf(e,r+1);return n});if(r.some(e=>e.length===0))return e;let i=t.length;for(let e of r[0]){let t=e,a=e+n[0].length;for(let i=1;i<r.length;i++){let o=r[i][0],s=Math.abs(o-e);for(let t=1;t<r[i].length;t++){let n=Math.abs(r[i][t]-e);n<s&&(s=n,o=r[i][t])}t=Math.min(t,o),a=Math.max(a,o+n[i].length)}i=Math.min(i,a-t)}let a=1+.25/(1+i/200);return{record:e.record,score:e.score*a}}).sort((e,t)=>t.score-e.score)}function y(e,t,n=8){let r=new Set(t.toLowerCase().split(/\s+/).filter(e=>e.length>=2)),i=new Map,a=e.length;for(let t of e){let e=new Set(t.record.content.split(/[^a-zA-Z0-9_]+/).filter(e=>e.length>=3&&!b.has(e.toLowerCase())));for(let t of e){let e=t.toLowerCase();/[_A-Z]/.test(t)&&i.set(`__id__${e}`,1)}let n=new Set(t.record.content.toLowerCase().split(/[^a-zA-Z0-9_]+/).filter(e=>e.length>=3&&!b.has(e)));for(let e of n)i.set(e,(i.get(e)??0)+1)}let o=[];for(let[e,t]of i){if(e.startsWith(`__id__`)||r.has(e)||t>a*.8)continue;let n=Math.log(a/t),s=i.has(`__id__${e}`)?1:0,c=e.length>8?.5:0;o.push({term:e,score:n+s+c})}return o.sort((e,t)=>t.score-e.score).slice(0,n).map(e=>e.term)}const b=new Set(`the.and.for.are.but.not.you.all.can.had.her.was.one.our.out.has.have.from.this.that.with.they.been.said.each.which.their.will.other.about.many.then.them.these.some.would.make.like.into.could.time.very.when.come.just.know.take.people.also.back.after.only.more.than.over.such.import.export.const.function.return.true.false.null.undefined.string.number.boolean.void.type.interface`.split(`.`));async function x(e,t){try{let n=await e.getStats();if(!n.lastIndexedAt)return;let r=new Date(n.lastIndexedAt).getTime(),a=Date.now(),o=[...new Set(t.map(e=>e.record.sourcePath))].filter(e=>!e.startsWith(`[ER]`)).slice(0,5);if(o.length===0)return;let s=0;for(let e of o)try{(await i(e)).mtimeMs>r&&s++}catch{s++}if(s>0){let e=a-r,t=Math.floor(e/6e4),n=t<1?`<1 min`:`${t} min`;return`> ⚠️ **Index may be stale** — ${s} file(s) modified since last index (${n} ago). Use \`reindex\` to refresh.`}}catch{}}function S(i,l,m,b,S,C){i.registerTool(`search`,{description:`Search the knowledge base with hybrid vector + keyword matching (BM25 + RRF fusion). Best for finding code, docs, and prior decisions. Supports semantic, keyword, and hybrid modes.`,inputSchema:{query:p.string().max(5e3).describe(`Natural language search query`),limit:p.number().min(1).max(20).default(5).describe(`Maximum results to return`),search_mode:p.enum([`hybrid`,`semantic`,`keyword`]).default(`hybrid`).describe(`Search strategy: hybrid (vector + FTS + RRF fusion, default), semantic (vector only), keyword (FTS only)`),content_type:p.enum(a).optional().describe(`Filter by content type`),source_type:p.enum(s).optional().describe(`Coarse filter: "source" (code only), "documentation" (md, curated), "test", "config". Overrides content_type if both set.`),origin:p.enum(o).optional().describe(`Filter by knowledge origin`),category:p.string().optional().describe(`Filter by category (e.g., decisions, patterns, conventions)`),tags:p.array(p.string()).optional().describe(`Filter by tags (returns results matching ANY of the specified tags)`),min_score:p.number().min(0).max(1).default(.25).describe(`Minimum similarity score`),graph_hops:p.number().min(0).max(3).default(1).describe(`Number of graph hops to augment results with connected entities (0 = disabled, 1 = direct connections, 2-3 = deeper traversal). Default 1 provides module/symbol context automatically.`),max_tokens:p.number().min(100).max(5e4).optional().describe(`Maximum token budget for the response. When set, output is truncated to fit.`),dedup:p.enum([`file`,`chunk`]).default(`chunk`).describe(`Deduplication mode: "chunk" (default, show all matching chunks) or "file" (collapse chunks from same file into single result with merged line ranges)`),workspaces:p.array(p.string()).optional().describe(`Cross-workspace search: partition names or folder basenames to include. Use ["*"] for all registered workspaces. Only works in
|
|
1
|
+
import{fanOutFtsSearch as e,fanOutSearch as t,openWorkspaceStores as n,resolveWorkspaces as r}from"../cross-workspace.js";import{stat as i}from"node:fs/promises";import{CONTENT_TYPES as a,KNOWLEDGE_ORIGINS as o,SOURCE_TYPES as s,computePartitionKey as c,createLogger as l,serializeError as u}from"../../../core/dist/index.js";import{graphAugmentSearch as d,truncateToTokenBudget as f}from"../../../tools/dist/index.js";import{z as p}from"zod";import{mergeResults as m}from"../../../enterprise-bridge/dist/index.js";const h=l(`tools`);async function g(e,t,n,r,i){if(!e||t>=e.config.fallbackThreshold&&n.length>0)return{results:n,triggered:!1,cacheHit:!1};let a=!1;try{let t=e.cache.get(r);return t?a=!0:(t=await e.client.search(r,i),t.length>0&&e.cache.set(r,t)),t.length>0?{results:m(n,t,i).map(e=>({record:{id:`er:${e.sourcePath}`,content:e.content,sourcePath:e.source===`er`?`[ER] ${e.sourcePath}`:e.sourcePath,startLine:e.startLine??0,endLine:e.endLine??0,contentType:e.contentType??`documentation`,headingPath:e.headingPath,origin:e.source===`er`?`curated`:e.origin??`indexed`,category:e.category,tags:e.tags??[],chunkIndex:0,totalChunks:1,fileHash:``,indexedAt:new Date().toISOString(),version:1},score:e.score})),triggered:!0,cacheHit:a}:{results:n,triggered:!0,cacheHit:a}}catch(e){return h.warn(`ER fallback failed`,u(e)),{results:n,triggered:!0,cacheHit:a}}}function _(e,t,n=60){let r=new Map;for(let t=0;t<e.length;t++){let i=e[t];r.set(i.record.id,{record:i.record,score:1/(n+t+1)})}for(let e=0;e<t.length;e++){let i=t[e],a=r.get(i.record.id);a?a.score+=1/(n+e+1):r.set(i.record.id,{record:i.record,score:1/(n+e+1)})}return[...r.values()].sort((e,t)=>t.score-e.score).map(({record:e,score:t})=>({record:e,score:t}))}function v(e,t){let n=t.toLowerCase().split(/\s+/).filter(e=>e.length>=2);return n.length<2?e:e.map(e=>{let t=e.record.content.toLowerCase(),r=n.map(e=>{let n=[],r=t.indexOf(e);for(;r!==-1;)n.push(r),r=t.indexOf(e,r+1);return n});if(r.some(e=>e.length===0))return e;let i=t.length;for(let e of r[0]){let t=e,a=e+n[0].length;for(let i=1;i<r.length;i++){let o=r[i][0],s=Math.abs(o-e);for(let t=1;t<r[i].length;t++){let n=Math.abs(r[i][t]-e);n<s&&(s=n,o=r[i][t])}t=Math.min(t,o),a=Math.max(a,o+n[i].length)}i=Math.min(i,a-t)}let a=1+.25/(1+i/200);return{record:e.record,score:e.score*a}}).sort((e,t)=>t.score-e.score)}function y(e,t,n=8){let r=new Set(t.toLowerCase().split(/\s+/).filter(e=>e.length>=2)),i=new Map,a=e.length;for(let t of e){let e=new Set(t.record.content.split(/[^a-zA-Z0-9_]+/).filter(e=>e.length>=3&&!b.has(e.toLowerCase())));for(let t of e){let e=t.toLowerCase();/[_A-Z]/.test(t)&&i.set(`__id__${e}`,1)}let n=new Set(t.record.content.toLowerCase().split(/[^a-zA-Z0-9_]+/).filter(e=>e.length>=3&&!b.has(e)));for(let e of n)i.set(e,(i.get(e)??0)+1)}let o=[];for(let[e,t]of i){if(e.startsWith(`__id__`)||r.has(e)||t>a*.8)continue;let n=Math.log(a/t),s=i.has(`__id__${e}`)?1:0,c=e.length>8?.5:0;o.push({term:e,score:n+s+c})}return o.sort((e,t)=>t.score-e.score).slice(0,n).map(e=>e.term)}const b=new Set(`the.and.for.are.but.not.you.all.can.had.her.was.one.our.out.has.have.from.this.that.with.they.been.said.each.which.their.will.other.about.many.then.them.these.some.would.make.like.into.could.time.very.when.come.just.know.take.people.also.back.after.only.more.than.over.such.import.export.const.function.return.true.false.null.undefined.string.number.boolean.void.type.interface`.split(`.`));async function x(e,t){try{let n=await e.getStats();if(!n.lastIndexedAt)return;let r=new Date(n.lastIndexedAt).getTime(),a=Date.now(),o=[...new Set(t.map(e=>e.record.sourcePath))].filter(e=>!e.startsWith(`[ER]`)).slice(0,5);if(o.length===0)return;let s=0;for(let e of o)try{(await i(e)).mtimeMs>r&&s++}catch{s++}if(s>0){let e=a-r,t=Math.floor(e/6e4),n=t<1?`<1 min`:`${t} min`;return`> ⚠️ **Index may be stale** — ${s} file(s) modified since last index (${n} ago). Use \`reindex\` to refresh.`}}catch{}}function S(i,l,m,b,S,C){i.registerTool(`search`,{description:`Search the knowledge base with hybrid vector + keyword matching (BM25 + RRF fusion). Best for finding code, docs, and prior decisions. Supports semantic, keyword, and hybrid modes.`,inputSchema:{query:p.string().max(5e3).describe(`Natural language search query`),limit:p.number().min(1).max(20).default(5).describe(`Maximum results to return`),search_mode:p.enum([`hybrid`,`semantic`,`keyword`]).default(`hybrid`).describe(`Search strategy: hybrid (vector + FTS + RRF fusion, default), semantic (vector only), keyword (FTS only)`),content_type:p.enum(a).optional().describe(`Filter by content type`),source_type:p.enum(s).optional().describe(`Coarse filter: "source" (code only), "documentation" (md, curated), "test", "config". Overrides content_type if both set.`),origin:p.enum(o).optional().describe(`Filter by knowledge origin`),category:p.string().optional().describe(`Filter by category (e.g., decisions, patterns, conventions)`),tags:p.array(p.string()).optional().describe(`Filter by tags (returns results matching ANY of the specified tags)`),min_score:p.number().min(0).max(1).default(.25).describe(`Minimum similarity score`),graph_hops:p.number().min(0).max(3).default(1).describe(`Number of graph hops to augment results with connected entities (0 = disabled, 1 = direct connections, 2-3 = deeper traversal). Default 1 provides module/symbol context automatically.`),max_tokens:p.number().min(100).max(5e4).optional().describe(`Maximum token budget for the response. When set, output is truncated to fit.`),dedup:p.enum([`file`,`chunk`]).default(`chunk`).describe(`Deduplication mode: "chunk" (default, show all matching chunks) or "file" (collapse chunks from same file into single result with merged line ranges)`),workspaces:p.array(p.string()).optional().describe(`Cross-workspace search: partition names or folder basenames to include. Use ["*"] for all registered workspaces. Only works in user-level install mode.`)}},async({query:i,limit:a,search_mode:o,content_type:s,source_type:p,origin:w,category:T,tags:E,min_score:D,graph_hops:O,max_tokens:k,dedup:A,workspaces:j})=>{try{let M={limit:a,minScore:D,contentType:s,sourceType:p,origin:w,category:T,tags:E},N,P=!1,F=!1;if(o===`keyword`)N=await m.ftsSearch(i,M),N=N.slice(0,a);else if(o===`semantic`){let e=await l.embedQuery(i);N=await m.search(e,M);let t=await g(S,N[0]?.score??0,N,i,a);N=t.results,P=t.triggered,F=t.cacheHit}else{let e=await l.embedQuery(i),[t,n]=await Promise.all([m.search(e,{...M,limit:a*2}),m.ftsSearch(i,{...M,limit:a*2}).catch(()=>[])]);N=_(t,n).slice(0,a);let r=await g(S,t[0]?.score??0,N,i,a);N=r.results,P=r.triggered,F=r.cacheHit}C&&C.recordSearch(i,P,F),N.length>1&&(N=v(N,i));let I=``;if(j&&j.length>0){let s=r(j,c(process.cwd()));if(s.length>0){let{stores:r,closeAll:c}=await n(s);try{let n;n=o===`keyword`?await e(r,i,{...M,limit:a}):await t(r,await l.embedQuery(i),{...M,limit:a});for(let e of n)N.push({record:{...e.record,sourcePath:`[${e.workspace}] ${e.record.sourcePath}`},score:e.score});N=N.sort((e,t)=>t.score-e.score).slice(0,a),I=` + ${s.length} workspace(s)`}finally{await c()}}}if(A===`file`&&N.length>1){let e=new Map;for(let t of N){let n=t.record.sourcePath,r=e.get(n);r?(t.score>r.best.score&&(r.best=t),r.ranges.push({start:t.record.startLine,end:t.record.endLine})):e.set(n,{best:t,ranges:[{start:t.record.startLine,end:t.record.endLine}]})}N=[...e.values()].sort((e,t)=>t.best.score-e.best.score).map(({best:e,ranges:t})=>({record:{...e.record,content:t.length>1?`${e.record.content}\n\n_Matched ${t.length} sections: ${t.sort((e,t)=>e.start-t.start).map(e=>`L${e.start}-${e.end}`).join(`, `)}_`:e.record.content},score:e.score}))}if(N.length===0)return{content:[{type:`text`,text:`No results found for the given query.`}]};let L,R;if(O>0&&!b&&(R="> **Note:** `graph_hops` was set but no graph store is available. Graph augmentation skipped."),O>0&&b)try{let e=await d(b,N.map(e=>({recordId:e.record.id,score:e.score,sourcePath:e.record.sourcePath})),{hops:O,maxPerHit:5});L=new Map;for(let t of e)if(t.graphContext.nodes.length>0){let e=t.graphContext.nodes.slice(0,5).map(e=>` - **${e.name}** (${e.type})`).join(`
|
|
2
2
|
`),n=t.graphContext.edges.slice(0,5).map(e=>` - ${e.fromId} —[${e.type}]→ ${e.toId}`).join(`
|
|
3
3
|
`),r=[`- **Graph Context** (${O} hop${O>1?`s`:``}):`];e&&r.push(` Entities:\n${e}`),n&&r.push(` Relationships:\n${n}`),L.set(t.recordId,r.join(`
|
|
4
4
|
`))}}catch(e){h.warn(`Graph augmentation failed`,u(e)),R=`> **Note:** Graph augmentation failed. Results shown without graph context.`}let z=N.map((e,t)=>{let n=e.record;return`${`### Result ${t+1} (score: ${e.score.toFixed(3)})`}\n${[`- **Source**: ${n.sourcePath}`,n.headingPath?`- **Section**: ${n.headingPath}`:null,`- **Type**: ${n.contentType}`,n.startLine?`- **Lines**: ${n.startLine}-${n.endLine}`:null,n.origin===`indexed`?null:`- **Origin**: ${n.origin}`,n.category?`- **Category**: ${n.category}`:null,n.tags?.length?`- **Tags**: ${n.tags.join(`, `)}`:null,L?.get(n.id)??null].filter(Boolean).join(`
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import{fanOutSearch as e,openWorkspaceStores as t,resolveWorkspaces as n}from"../cross-workspace.js";import{CONTENT_TYPES as r,computePartitionKey as i,createLogger as a,serializeError as o}from"../../../core/dist/index.js";import{addToWorkset as s,batch as c,check as l,checkpointLatest as u,checkpointList as d,checkpointLoad as f,checkpointSave as p,codemod as m,compact as h,dataTransform as g,delegate as ee,delegateListModels as te,deleteWorkset as ne,diffParse as re,evaluate as ie,fileSummary as ae,find as _,findDeadSymbols as oe,findExamples as se,getWorkset as v,gitContext as y,guide as b,health as x,laneCreate as S,laneDiff as C,laneDiscard as w,laneList as T,laneMerge as E,laneStatus as D,listWorksets as O,parseOutput as k,processList as A,processLogs as j,processStart as M,processStatus as N,processStop as P,queueClear as F,queueCreate as I,queueDelete as L,queueDone as R,queueFail as z,queueGet as B,queueList as V,queueNext as H,queuePush as U,removeFromWorkset as W,rename as G,saveWorkset as K,scopeMap as ce,stashClear as le,stashDelete as ue,stashGet as de,stashList as fe,stashSet as pe,summarizeCheckResult as me,symbol as q,testRun as he,trace as ge,truncateToTokenBudget as J,watchList as _e,watchStart as ve,watchStop as ye,webFetch as be}from"../../../tools/dist/index.js";import{z as Y}from"zod";const X=a(`tools`);function xe(e,t,n){e.registerTool(`compact`,{description:"Compress text to relevant sections using embedding similarity (no LLM). Provide either `text` or `path` (server reads the file — saves a round-trip). Segments by paragraph/sentence/line.",inputSchema:{text:Y.string().optional().describe(`The text to compress (provide this OR path, not both)`),path:Y.string().optional().describe(`File path to read server-side — avoids read_file round-trip + token doubling (provide this OR text)`),query:Y.string().describe(`Focus query — what are you trying to understand?`),max_chars:Y.number().min(100).max(5e4).default(3e3).describe(`Target output size in characters`),segmentation:Y.enum([`paragraph`,`sentence`,`line`]).default(`paragraph`).describe(`How to split the text for scoring`)}},async({text:e,path:r,query:i,max_chars:a,segmentation:s})=>{try{if(!e&&!r)return{content:[{type:`text`,text:`Error: Either "text" or "path" must be provided.`}],isError:!0};let o=await h(t,{text:e,path:r,query:i,maxChars:a,segmentation:s,cache:n});return{content:[{type:`text`,text:[`Compressed ${o.originalChars} → ${o.compressedChars} chars (${(o.ratio*100).toFixed(0)}%)`,`Kept ${o.segmentsKept}/${o.segmentsTotal} segments`,``,o.text].join(`
|
|
2
2
|
`)}]}}catch(e){return X.error(`Compact failed`,o(e)),{content:[{type:`text`,text:`Compact failed: ${e instanceof Error?e.message:String(e)}`}],isError:!0}}})}function Se(e,t,n){e.registerTool(`scope_map`,{description:`Generate a task-scoped reading plan. Given a task description, identifies which files and sections are relevant, with estimated token counts and suggested reading order.`,inputSchema:{task:Y.string().describe(`Description of the task to scope`),max_files:Y.number().min(1).max(50).default(15).describe(`Maximum files to include`),content_type:Y.enum(r).optional().describe(`Filter by content type`),max_tokens:Y.number().min(100).max(5e4).optional().describe(`Maximum token budget for the response. When set, output is truncated to fit.`)}},async({task:e,max_files:r,content_type:i,max_tokens:a})=>{try{let o=await ce(t,n,{task:e,maxFiles:r,contentType:i}),s=[`## Scope Map: ${e}`,`Total estimated tokens: ~${o.totalEstimatedTokens}`,``,`### Files (by relevance)`,...o.files.map((e,t)=>`${t+1}. **${e.path}** (~${e.estimatedTokens} tokens, ${(e.relevance*100).toFixed(0)}% relevant)\n ${e.reason}\n Focus: ${e.focusRanges.map(e=>`L${e.start}-${e.end}`).join(`, `)}`),``,`### Suggested Reading Order`,...o.readingOrder.map((e,t)=>`${t+1}. ${e}`),``,`### Suggested Compact Calls`,`_Estimated compressed total: ~${Math.ceil(o.totalEstimatedTokens/5)} tokens_`,...o.compactCommands.map((e,t)=>`${t+1}. ${e}`)].join(`
|
|
3
|
-
`)+"\n\n---\n_Next: Use `search` to dive into specific files, or `compact` to compress file contents for context._";return{content:[{type:`text`,text:a?J(s,a):s}]}}catch(e){return X.error(`Scope map failed`,o(e)),{content:[{type:`text`,text:`Scope map failed: ${e instanceof Error?e.message:String(e)}`}],isError:!0}}})}function Ce(a,s,c){a.registerTool(`find`,{description:`Federated search across vector similarity, keyword (FTS), file glob, and regex pattern. Combines strategies, deduplicates, and returns unified results. Use mode "examples" to find real usage examples of a symbol or pattern.`,inputSchema:{query:Y.string().optional().describe(`Semantic/keyword search query (required for mode "examples")`),glob:Y.string().optional().describe(`File glob pattern (search mode only)`),pattern:Y.string().optional().describe(`Regex pattern to match in content (search mode only)`),limit:Y.number().min(1).max(50).default(10).describe(`Max results`),content_type:Y.enum(r).optional().describe(`Filter by content type`),mode:Y.enum([`search`,`examples`]).default(`search`).describe(`Mode: "search" (default) for federated search, "examples" to find usage examples of a symbol/pattern`),max_tokens:Y.number().min(100).max(5e4).optional().describe(`Maximum token budget for the response. When set, output is truncated to fit.`),workspaces:Y.array(Y.string()).optional().describe(`Cross-workspace search: partition names or folder basenames to include. Use ["*"] for all.
|
|
3
|
+
`)+"\n\n---\n_Next: Use `search` to dive into specific files, or `compact` to compress file contents for context._";return{content:[{type:`text`,text:a?J(s,a):s}]}}catch(e){return X.error(`Scope map failed`,o(e)),{content:[{type:`text`,text:`Scope map failed: ${e instanceof Error?e.message:String(e)}`}],isError:!0}}})}function Ce(a,s,c){a.registerTool(`find`,{description:`Federated search across vector similarity, keyword (FTS), file glob, and regex pattern. Combines strategies, deduplicates, and returns unified results. Use mode "examples" to find real usage examples of a symbol or pattern.`,inputSchema:{query:Y.string().optional().describe(`Semantic/keyword search query (required for mode "examples")`),glob:Y.string().optional().describe(`File glob pattern (search mode only)`),pattern:Y.string().optional().describe(`Regex pattern to match in content (search mode only)`),limit:Y.number().min(1).max(50).default(10).describe(`Max results`),content_type:Y.enum(r).optional().describe(`Filter by content type`),mode:Y.enum([`search`,`examples`]).default(`search`).describe(`Mode: "search" (default) for federated search, "examples" to find usage examples of a symbol/pattern`),max_tokens:Y.number().min(100).max(5e4).optional().describe(`Maximum token budget for the response. When set, output is truncated to fit.`),workspaces:Y.array(Y.string()).optional().describe(`Cross-workspace search: partition names or folder basenames to include. Use ["*"] for all. User-level mode only.`)}},async({query:r,glob:a,pattern:l,limit:u,content_type:d,mode:f,max_tokens:p,workspaces:m})=>{try{if(f===`examples`){if(!r)return{content:[{type:`text`,text:`Error: "query" is required for mode "examples".`}],isError:!0};let e=await se(s,c,{query:r,limit:u,contentType:d}),t=JSON.stringify(e,null,2);return{content:[{type:`text`,text:p?J(t,p):t}]}}let o=await _(s,c,{query:r,glob:a,pattern:l,limit:u,contentType:d}),h=``;if(m&&m.length>0&&r){let a=n(m,i(process.cwd()));if(a.length>0){let{stores:n,closeAll:i}=await t(a);try{let t=await e(n,await s.embedQuery(r),{limit:u,contentType:d});for(let e of t)o.results.push({path:`[${e.workspace}] ${e.record.sourcePath}`,score:e.score,source:`cross-workspace`,lineRange:e.record.startLine?{start:e.record.startLine,end:e.record.endLine}:void 0,preview:e.record.content.slice(0,200)});o.results.sort((e,t)=>t.score-e.score),o.results=o.results.slice(0,u),o.totalFound=o.results.length,h=` + ${a.length} workspace(s)`}finally{await i()}}}if(o.results.length===0)return{content:[{type:`text`,text:`No results found.`}]};let g=[`Found ${o.totalFound} results via ${o.strategies.join(` + `)}${h}`,``,...o.results.map(e=>{let t=e.lineRange?`:${e.lineRange.start}-${e.lineRange.end}`:``,n=e.preview?`\n ${e.preview.slice(0,100)}...`:``;return`- [${e.source}] ${e.path}${t} (${(e.score*100).toFixed(0)}%)${n}`})];return{content:[{type:`text`,text:p?J(g.join(`
|
|
4
4
|
`),p):g.join(`
|
|
5
5
|
`)}]}}catch(e){return X.error(`Find failed`,o(e)),{content:[{type:`text`,text:`Find failed. Check server logs for details.`}],isError:!0}}})}function we(e){e.registerTool(`parse_output`,{description:`Parse structured data from build tool output. Supports tsc, vitest, biome, and git status. Auto-detects the tool or specify explicitly.`,inputSchema:{output:Y.string().max(5e5).describe(`Raw output text from a build tool`),tool:Y.enum([`tsc`,`vitest`,`biome`,`git-status`]).optional().describe(`Tool to parse as (auto-detects if omitted)`)}},async({output:e,tool:t})=>{try{let n=k(e.replace(/\\n/g,`
|
|
6
6
|
`).replace(/\\t/g,` `),t);return{content:[{type:`text`,text:JSON.stringify(n,null,2)}]}}catch(e){return X.error(`Parse failed`,o(e)),{content:[{type:`text`,text:`Parse failed. Check server logs for details.`}],isError:!0}}})}function Te(e){e.registerTool(`workset`,{description:`Manage named file sets (worksets). Save, load, list, add/remove files. Worksets persist across sessions in .kb-state/worksets.json.`,inputSchema:{action:Y.enum([`save`,`get`,`list`,`delete`,`add`,`remove`]).describe(`Operation to perform`),name:Y.string().optional().describe(`Workset name (required for all except list)`),files:Y.array(Y.string()).optional().describe(`File paths (required for save, add, remove)`),description:Y.string().optional().describe(`Description (for save)`)}},async({action:e,name:t,files:n,description:r})=>{try{switch(e){case`save`:{if(!t||!n)throw Error(`name and files required for save`);let e=K(t,n,{description:r});return{content:[{type:`text`,text:`Saved workset "${e.name}" with ${e.files.length} files.`}]}}case`get`:{if(!t)throw Error(`name required for get`);let e=v(t);return e?{content:[{type:`text`,text:JSON.stringify(e,null,2)}]}:{content:[{type:`text`,text:`Workset "${t}" not found.`}]}}case`list`:{let e=O();return e.length===0?{content:[{type:`text`,text:`No worksets.`}]}:{content:[{type:`text`,text:e.map(e=>`- **${e.name}** (${e.files.length} files) — ${e.description??`no description`}`).join(`
|
|
7
|
-
`)}]}}case`delete`:if(!t)throw Error(`name required for delete`);return{content:[{type:`text`,text:ne(t)?`Deleted workset "${t}".`:`Workset "${t}" not found.`}]};case`add`:{if(!t||!n)throw Error(`name and files required for add`);let e=s(t,n);return{content:[{type:`text`,text:`Added to workset "${e.name}": now ${e.files.length} files.`}]}}case`remove`:{if(!t||!n)throw Error(`name and files required for remove`);let e=W(t,n);return e?{content:[{type:`text`,text:`Removed from workset "${e.name}": now ${e.files.length} files.`}]}:{content:[{type:`text`,text:`Workset "${t}" not found.`}]}}}}catch(e){return X.error(`Workset operation failed`,o(e)),{content:[{type:`text`,text:`Workset operation failed. Check server logs for details.`}],isError:!0}}})}function Ee(e){e.registerTool(`check`,{description:`Run incremental typecheck (tsc) and lint (biome) on the project or specific files. Returns structured error and warning lists. Default detail level is "summary" (~300 tokens).`,inputSchema:{files:Y.array(Y.string()).optional().describe(`Specific files to check (if omitted, checks all)`),cwd:Y.string().optional().describe(`Working directory`),skip_types:Y.boolean().default(!1).describe(`Skip TypeScript typecheck`),skip_lint:Y.boolean().default(!1).describe(`Skip Biome lint`),detail:Y.enum([`summary`,`errors`,`full`]).default(`summary`).describe(`Output detail level: summary (default, ~300 tokens — pass/fail + counts + top errors), errors (parsed error objects), full (includes raw terminal output)`)}},async({files:e,cwd:t,skip_types:n,skip_lint:r,detail:i})=>{try{let a=await l({files:e,cwd:t,skipTypes:n,skipLint:r,detail:i===`summary`?`errors`:i});if(i===`summary`){let e=me(a),t=[];if(a.passed)t.push({tool:`test_run`,reason:`Types and lint clean — run tests next`});else{let e=a.tsc.errors[0]?.file??a.biome.errors[0]?.file;e&&t.push({tool:`symbol`,reason:`Resolve failing symbol in ${e}`,suggested_args:{name:e}}),t.push({tool:`check`,reason:`Re-check after fixing errors`,suggested_args:{detail:`errors`}})}return{content:[{type:`text`,text:JSON.stringify({...e,_next:t},null,2)}]}}return{content:[{type:`text`,text:JSON.stringify(a,null,2)}]}}catch(e){return X.error(`Check failed`,o(e)),{content:[{type:`text`,text:`Check failed. Check server logs for details.`}],isError:!0}}})}function De(e,t,n){e.registerTool(`batch`,{description:`Execute multiple built-in operations in parallel with concurrency control. Supported operation types: search, find, and check.`,inputSchema:{operations:Y.array(Y.object({id:Y.string().describe(`Unique ID for this operation`),type:Y.enum([`search`,`find`,`check`]).describe(`Built-in operation type`),args:Y.record(Y.string(),Y.unknown()).describe(`Arguments for the operation`)})).min(1).max(100).describe(`Operations to execute`),concurrency:Y.number().min(1).max(20).default(4).describe(`Max concurrent operations`)}},async({operations:e,concurrency:r})=>{try{let i=await c(e,async e=>Xe(e,t,n),{concurrency:r});return{content:[{type:`text`,text:JSON.stringify(i,null,2)}]}}catch(e){return X.error(`Batch failed`,o(e)),{content:[{type:`text`,text:`Batch failed. Check server logs for details.`}],isError:!0}}})}function Oe(e,r,a,s){e.registerTool(`symbol`,{description:`Resolve a symbol: find where it is defined, who imports it, and where it is referenced. Works on TypeScript and JavaScript codebases.`,inputSchema:{name:Y.string().describe(`Symbol name to look up (function, class, type, etc.)`),limit:Y.number().min(1).max(50).default(20).describe(`Max results per category`),workspaces:Y.array(Y.string()).optional().describe(`Cross-workspace search: partition names or folder basenames to include. Use ["*"] for all.
|
|
7
|
+
`)}]}}case`delete`:if(!t)throw Error(`name required for delete`);return{content:[{type:`text`,text:ne(t)?`Deleted workset "${t}".`:`Workset "${t}" not found.`}]};case`add`:{if(!t||!n)throw Error(`name and files required for add`);let e=s(t,n);return{content:[{type:`text`,text:`Added to workset "${e.name}": now ${e.files.length} files.`}]}}case`remove`:{if(!t||!n)throw Error(`name and files required for remove`);let e=W(t,n);return e?{content:[{type:`text`,text:`Removed from workset "${e.name}": now ${e.files.length} files.`}]}:{content:[{type:`text`,text:`Workset "${t}" not found.`}]}}}}catch(e){return X.error(`Workset operation failed`,o(e)),{content:[{type:`text`,text:`Workset operation failed. Check server logs for details.`}],isError:!0}}})}function Ee(e){e.registerTool(`check`,{description:`Run incremental typecheck (tsc) and lint (biome) on the project or specific files. Returns structured error and warning lists. Default detail level is "summary" (~300 tokens).`,inputSchema:{files:Y.array(Y.string()).optional().describe(`Specific files to check (if omitted, checks all)`),cwd:Y.string().optional().describe(`Working directory`),skip_types:Y.boolean().default(!1).describe(`Skip TypeScript typecheck`),skip_lint:Y.boolean().default(!1).describe(`Skip Biome lint`),detail:Y.enum([`summary`,`errors`,`full`]).default(`summary`).describe(`Output detail level: summary (default, ~300 tokens — pass/fail + counts + top errors), errors (parsed error objects), full (includes raw terminal output)`)}},async({files:e,cwd:t,skip_types:n,skip_lint:r,detail:i})=>{try{let a=await l({files:e,cwd:t,skipTypes:n,skipLint:r,detail:i===`summary`?`errors`:i});if(i===`summary`){let e=me(a),t=[];if(a.passed)t.push({tool:`test_run`,reason:`Types and lint clean — run tests next`});else{let e=a.tsc.errors[0]?.file??a.biome.errors[0]?.file;e&&t.push({tool:`symbol`,reason:`Resolve failing symbol in ${e}`,suggested_args:{name:e}}),t.push({tool:`check`,reason:`Re-check after fixing errors`,suggested_args:{detail:`errors`}})}return{content:[{type:`text`,text:JSON.stringify({...e,_next:t},null,2)}]}}return{content:[{type:`text`,text:JSON.stringify(a,null,2)}]}}catch(e){return X.error(`Check failed`,o(e)),{content:[{type:`text`,text:`Check failed. Check server logs for details.`}],isError:!0}}})}function De(e,t,n){e.registerTool(`batch`,{description:`Execute multiple built-in operations in parallel with concurrency control. Supported operation types: search, find, and check.`,inputSchema:{operations:Y.array(Y.object({id:Y.string().describe(`Unique ID for this operation`),type:Y.enum([`search`,`find`,`check`]).describe(`Built-in operation type`),args:Y.record(Y.string(),Y.unknown()).describe(`Arguments for the operation`)})).min(1).max(100).describe(`Operations to execute`),concurrency:Y.number().min(1).max(20).default(4).describe(`Max concurrent operations`)}},async({operations:e,concurrency:r})=>{try{let i=await c(e,async e=>Xe(e,t,n),{concurrency:r});return{content:[{type:`text`,text:JSON.stringify(i,null,2)}]}}catch(e){return X.error(`Batch failed`,o(e)),{content:[{type:`text`,text:`Batch failed. Check server logs for details.`}],isError:!0}}})}function Oe(e,r,a,s){e.registerTool(`symbol`,{description:`Resolve a symbol: find where it is defined, who imports it, and where it is referenced. Works on TypeScript and JavaScript codebases.`,inputSchema:{name:Y.string().describe(`Symbol name to look up (function, class, type, etc.)`),limit:Y.number().min(1).max(50).default(20).describe(`Max results per category`),workspaces:Y.array(Y.string()).optional().describe(`Cross-workspace search: partition names or folder basenames to include. Use ["*"] for all. User-level mode only.`)}},async({name:e,limit:c,workspaces:l})=>{try{let o=await q(r,a,{name:e,limit:c,graphStore:s});if(l&&l.length>0){let a=n(l,i(process.cwd()));if(a.length>0){let{stores:n,closeAll:i}=await t(a);try{for(let[t,i]of n){let n=await q(r,i,{name:e,limit:c});n.definedIn&&!o.definedIn&&(o.definedIn={...n.definedIn,path:`[${t}] ${n.definedIn.path}`});for(let e of n.referencedIn)o.referencedIn.push({...e,path:`[${t}] ${e.path}`});if(n.importedBy){o.importedBy=o.importedBy??[];for(let e of n.importedBy)o.importedBy.push({...e,path:`[${t}] ${e.path}`})}}}finally{await i()}}}return{content:[{type:`text`,text:Qe(o)}]}}catch(e){return X.error(`Symbol lookup failed`,o(e)),{content:[{type:`text`,text:`Symbol lookup failed. Check server logs for details.`}],isError:!0}}})}function ke(e){e.registerTool(`eval`,{description:`Execute a JavaScript or TypeScript snippet in a constrained VM sandbox with a timeout. Captures console output and returned values.`,inputSchema:{code:Y.string().max(1e5).describe(`Code snippet to execute`),lang:Y.enum([`js`,`ts`]).default(`js`).optional().describe(`Language mode: js executes directly, ts strips common type syntax first`),timeout:Y.number().min(1).max(6e4).default(5e3).optional().describe(`Execution timeout in milliseconds`)}},async({code:e,lang:t,timeout:n})=>{try{let r=ie({code:e,lang:t,timeout:n});return r.success?{content:[{type:`text`,text:`Eval succeeded in ${r.durationMs}ms\n\n${r.output}`}]}:{content:[{type:`text`,text:`Eval failed in ${r.durationMs}ms: ${r.error??`Unknown error`}`}],isError:!0}}catch(e){return X.error(`Eval failed`,o(e)),{content:[{type:`text`,text:`Eval failed. Check server logs for details.`}],isError:!0}}})}function Ae(e){e.registerTool(`test_run`,{description:`Run Vitest for the current project or a subset of files, then return a structured summary of passing and failing tests.`,inputSchema:{files:Y.array(Y.string()).optional().describe(`Specific test files or patterns to run`),grep:Y.string().optional().describe(`Only run tests whose names match this pattern`),cwd:Y.string().optional().describe(`Working directory for the test run`)}},async({files:e,grep:t,cwd:n})=>{try{let r=await he({files:e,grep:t,cwd:n});return{content:[{type:`text`,text:$e(r)}],isError:!r.passed}}catch(e){return X.error(`Test run failed`,o(e)),{content:[{type:`text`,text:`Test run failed. Check server logs for details.`}],isError:!0}}})}function je(e){e.registerTool(`stash`,{description:`Persist and retrieve named values in .kb-state/stash.json for intermediate results between tool calls.`,inputSchema:{action:Y.enum([`set`,`get`,`list`,`delete`,`clear`]).describe(`Operation to perform on the stash`),key:Y.string().optional().describe(`Entry key for set/get/delete operations`),value:Y.string().optional().describe(`String or JSON value for set operations`)}},async({action:e,key:t,value:n})=>{try{switch(e){case`set`:{if(!t)throw Error(`key required for set`);let e=pe(t,rt(n??``));return{content:[{type:`text`,text:`Stored stash entry "${e.key}" (${e.type}) at ${e.storedAt}.`}]}}case`get`:{if(!t)throw Error(`key required for get`);let e=de(t);return{content:[{type:`text`,text:e?JSON.stringify(e,null,2):`Stash entry "${t}" not found.`}]}}case`list`:{let e=fe();return{content:[{type:`text`,text:e.length===0?`Stash is empty.`:e.map(e=>`- ${e.key} (${e.type}) — ${e.storedAt}`).join(`
|
|
8
8
|
`)}]}}case`delete`:if(!t)throw Error(`key required for delete`);return{content:[{type:`text`,text:ue(t)?`Deleted stash entry "${t}".`:`Stash entry "${t}" not found.`}]};case`clear`:{let e=le();return{content:[{type:`text`,text:`Cleared ${e} stash entr${e===1?`y`:`ies`}.`}]}}}}catch(e){return X.error(`Stash operation failed`,o(e)),{content:[{type:`text`,text:`Stash operation failed. Check server logs for details.`}],isError:!0}}})}function Me(e){e.registerTool(`git_context`,{description:`Summarize the current Git branch, working tree state, recent commits, and optional diff statistics for the repository.`,inputSchema:{cwd:Y.string().optional().describe(`Repository root or working directory`),commit_count:Y.number().min(1).max(50).default(5).optional().describe(`How many recent commits to include`),include_diff:Y.boolean().default(!1).optional().describe(`Include diff stat for working tree changes`)}},async({cwd:e,commit_count:t,include_diff:n})=>{try{return{content:[{type:`text`,text:et(await y({cwd:e,commitCount:t,includeDiff:n}))}]}}catch(e){return X.error(`Git context failed`,o(e)),{content:[{type:`text`,text:`Git context failed. Check server logs for details.`}],isError:!0}}})}function Ne(e){e.registerTool(`diff_parse`,{description:`Parse raw unified diff text into file-level and hunk-level structural changes.`,inputSchema:{diff:Y.string().max(1e6).describe(`Raw unified diff text`)}},async({diff:e})=>{try{return{content:[{type:`text`,text:tt(re({diff:e.replace(/\\n/g,`
|
|
9
9
|
`).replace(/\\t/g,` `)}))}]}}catch(e){return X.error(`Diff parse failed`,o(e)),{content:[{type:`text`,text:`Diff parse failed. Check server logs for details.`}],isError:!0}}})}function Pe(e){e.registerTool(`rename`,{description:`Rename a symbol across files using whole-word regex matching for exports, imports, and general usage references.`,inputSchema:{old_name:Y.string().describe(`Existing symbol name to replace`),new_name:Y.string().describe(`New symbol name to use`),root_path:Y.string().describe(`Root directory to search within`),extensions:Y.array(Y.string()).optional().describe(`Optional file extensions to include, such as .ts,.tsx,.js,.jsx`),dry_run:Y.boolean().default(!0).describe(`Preview changes without writing files`)}},async({old_name:e,new_name:t,root_path:n,extensions:r,dry_run:i})=>{try{let a=await G({oldName:e,newName:t,rootPath:n,extensions:r,dryRun:i});return{content:[{type:`text`,text:JSON.stringify(a,null,2)}]}}catch(e){return X.error(`Rename failed`,o(e)),{content:[{type:`text`,text:`Rename failed. Check server logs for details.`}],isError:!0}}})}function Fe(e){e.registerTool(`codemod`,{description:`Apply regex-based codemod rules across files and return structured before/after changes for each affected line.`,inputSchema:{root_path:Y.string().describe(`Root directory to transform within`),rules:Y.array(Y.object({description:Y.string().describe(`What the codemod rule does`),pattern:Y.string().describe(`Regex pattern in string form`),replacement:Y.string().describe(`Replacement string with optional capture groups`)})).min(1).describe(`Codemod rules to apply`),dry_run:Y.boolean().default(!0).describe(`Preview changes without writing files`)}},async({root_path:e,rules:t,dry_run:n})=>{try{let r=await m({rootPath:e,rules:t,dryRun:n});return{content:[{type:`text`,text:JSON.stringify(r,null,2)}]}}catch(e){return X.error(`Codemod failed`,o(e)),{content:[{type:`text`,text:`Codemod failed. Check server logs for details.`}],isError:!0}}})}function Ie(e,t){e.registerTool(`file_summary`,{description:`Create a concise structural summary of a source file: imports, exports, functions, classes, interfaces, and types.`,inputSchema:{path:Y.string().describe(`Absolute path to the file to summarize`)}},async({path:e})=>{try{return{content:[{type:`text`,text:nt(await ae({path:e,content:(await t.get(e)).content}))}]}}catch(e){return X.error(`File summary failed`,o(e)),{content:[{type:`text`,text:`File summary failed. Check server logs for details.`}],isError:!0}}})}function Le(e){e.registerTool(`checkpoint`,{description:`Save and restore lightweight session checkpoints in .kb-state/checkpoints for cross-session continuity.`,inputSchema:{action:Y.enum([`save`,`load`,`list`,`latest`]).describe(`Checkpoint action to perform`),label:Y.string().optional().describe(`Checkpoint label for save, or checkpoint id for load`),data:Y.string().max(5e5).optional().describe(`JSON object string for save actions`),notes:Y.string().max(1e4).optional().describe(`Optional notes for save actions`)}},async({action:e,label:t,data:n,notes:r})=>{try{switch(e){case`save`:if(!t)throw Error(`label required for save`);return{content:[{type:`text`,text:Q(p(t,it(n),{notes:r}))}]};case`load`:{if(!t)throw Error(`label required for load`);let e=f(t);return{content:[{type:`text`,text:e?Q(e):`Checkpoint "${t}" not found.`}]}}case`list`:{let e=d();return{content:[{type:`text`,text:e.length===0?`No checkpoints saved.`:e.map(e=>`- ${e.id} — ${e.label} (${e.createdAt})`).join(`
|
|
10
10
|
`)}]}}case`latest`:{let e=u();return{content:[{type:`text`,text:e?Q(e):`No checkpoints saved.`}]}}}}catch(e){return X.error(`Checkpoint failed`,o(e)),{content:[{type:`text`,text:`Checkpoint failed. Check server logs for details.`}],isError:!0}}})}function Re(e){e.registerTool(`data_transform`,{description:`Apply small jq-like transforms to JSON input for filtering, projection, grouping, and path extraction.`,inputSchema:{input:Y.string().max(5e5).describe(`Input JSON string`),expression:Y.string().max(1e4).describe(`Transform expression to apply`)}},async({input:e,expression:t})=>{try{return{content:[{type:`text`,text:g({input:e,expression:t}).outputString}]}}catch(e){return X.error(`Data transform failed`,o(e)),{content:[{type:`text`,text:`Data transform failed. Check server logs for details.`}],isError:!0}}})}function ze(e,t,n){e.registerTool(`trace`,{description:`Trace data flow through a codebase by following imports, call sites, and references from a starting symbol or file location.`,inputSchema:{start:Y.string().describe(`Starting point — symbol name or file:line reference`),direction:Y.enum([`forward`,`backward`,`both`]).describe(`Which direction to trace relationships`),max_depth:Y.number().min(1).max(10).default(3).optional().describe(`Maximum trace depth`)}},async({start:e,direction:r,max_depth:i})=>{try{let a=await ge(t,n,{start:e,direction:r,maxDepth:i}),o=[`## Trace: ${a.start}`,`Direction: ${a.direction} | Depth: ${a.depth}`,``];if(a.nodes.length===0)o.push(`No connections found.`);else{let e=a.nodes.filter(e=>e.relationship===`calls`),t=a.nodes.filter(e=>e.relationship===`called-by`),n=a.nodes.filter(e=>e.relationship===`imports`),r=a.nodes.filter(e=>e.relationship===`imported-by`),i=a.nodes.filter(e=>e.relationship===`references`);if(e.length>0){o.push(`### Calls (${e.length})`);for(let t of e){let e=t.scope?` (from ${t.scope}())`:``;o.push(`- ${t.symbol}() — ${t.path}:${t.line}${e}`)}o.push(``)}if(t.length>0){o.push(`### Called by (${t.length})`);for(let e of t){let t=e.scope?` in ${e.scope}()`:``;o.push(`- ${e.symbol}()${t} — ${e.path}:${e.line}`)}o.push(``)}if(n.length>0){o.push(`### Imports (${n.length})`);for(let e of n)o.push(`- ${e.symbol} — ${e.path}:${e.line}`);o.push(``)}if(r.length>0){o.push(`### Imported by (${r.length})`);for(let e of r)o.push(`- ${e.path}:${e.line}`);o.push(``)}if(i.length>0){o.push(`### References (${i.length})`);for(let e of i)o.push(`- ${e.path}:${e.line}`);o.push(``)}}return o.push(`---`,"_Next: `symbol` for definition details | `compact` to read a referenced file | `blast_radius` for impact analysis_"),{content:[{type:`text`,text:o.join(`
|
|
@@ -22,10 +22,6 @@ interface DeadSymbolResult {
|
|
|
22
22
|
totalExports: number;
|
|
23
23
|
totalDeadSource: number;
|
|
24
24
|
totalDeadDocs: number;
|
|
25
|
-
/** @deprecated Use deadInSource instead */
|
|
26
|
-
deadSymbols: DeadSymbol[];
|
|
27
|
-
/** @deprecated Use totalDeadSource + totalDeadDocs instead */
|
|
28
|
-
totalDead: number;
|
|
29
25
|
}
|
|
30
26
|
declare function findDeadSymbols(embedder: IEmbedder, store: IKnowledgeStore, options?: DeadSymbolOptions): Promise<DeadSymbolResult>;
|
|
31
27
|
//#endregion
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import{readFile as e}from"node:fs/promises";import{extname as t}from"node:path";import{SUPPORTED_EXTENSIONS as n,WasmRuntime as r,extractSymbols as i}from"../../chunker/dist/index.js";const a=new Set([`.md`,`.mdx`]);async function o(o,l,u={}){let{rootPath:d,limit:f=100}=u,p=await o.embed(`export function class const type interface enum`),m=await l.search(p,{limit:f*3}),h=/^export\s+(?:async\s+)?(?:function|class|const|let|interface|type|enum)\s+(\w+)/gm,g=[],_=new Map;for(let e of m){if(!c(e.record.sourcePath,d))continue;let t=_.get(e.record.sourcePath)??[];t.push(e),_.set(e.record.sourcePath,t)}let v=new Set;if(r.get())for(let[r]of _){let a=t(r);if(n.has(a))try{let t=await i(await e(r,`utf-8`),a,r);for(let e of t)e.exported&&g.push({name:e.name,path:r,line:e.line,kind:e.kind});v.add(r)}catch{}}for(let[e,t]of _)if(!v.has(e))for(let e of t){let t=e.record.content;h.lastIndex=0;for(let n of t.matchAll(h)){let r=n.index??0,i=t.slice(0,r).split(`
|
|
2
|
-
`).length-1,a=t.slice(r).match(/export\s+(?:async\s+)?(\w+)/);g.push({name:n[1],path:e.record.sourcePath,line:e.record.startLine+i,kind:a?.[1]??`unknown`})}}let y=new Map;for(let e of g){let t=`${e.path}:${e.name}`;y.has(t)||y.set(t,e)}let b=[];for(let e of y.values()){let t=s(e.name),n=RegExp(`import\\s+.*\\b${t}\\b.*from`,`m`),r=RegExp(`export\\s+\\{[^}]*\\b${t}\\b`,`m`),i=await l.ftsSearch(`import ${e.name}`,{limit:10}),a=i.some(t=>t.record.sourcePath!==e.path&&n.test(t.record.content)),o=i.some(t=>t.record.sourcePath!==e.path&&r.test(t.record.content));!a&&!o&&b.push(e)}let x=(e,t)=>e.path===t.path?e.line-t.line:e.path.localeCompare(t.path),S=[],C=[];for(let e of b){let n=t(e.path).toLowerCase();a.has(n)?C.push(e):S.push(e)}return S.sort(x),C.sort(x),{deadInSource:S,deadInDocs:C,totalExports:y.size,totalDeadSource:S.length,totalDeadDocs:C.length
|
|
2
|
+
`).length-1,a=t.slice(r).match(/export\s+(?:async\s+)?(\w+)/);g.push({name:n[1],path:e.record.sourcePath,line:e.record.startLine+i,kind:a?.[1]??`unknown`})}}let y=new Map;for(let e of g){let t=`${e.path}:${e.name}`;y.has(t)||y.set(t,e)}let b=[];for(let e of y.values()){let t=s(e.name),n=RegExp(`import\\s+.*\\b${t}\\b.*from`,`m`),r=RegExp(`export\\s+\\{[^}]*\\b${t}\\b`,`m`),i=await l.ftsSearch(`import ${e.name}`,{limit:10}),a=i.some(t=>t.record.sourcePath!==e.path&&n.test(t.record.content)),o=i.some(t=>t.record.sourcePath!==e.path&&r.test(t.record.content));!a&&!o&&b.push(e)}let x=(e,t)=>e.path===t.path?e.line-t.line:e.path.localeCompare(t.path),S=[],C=[];for(let e of b){let n=t(e.path).toLowerCase();a.has(n)?C.push(e):S.push(e)}return S.sort(x),C.sort(x),{deadInSource:S,deadInDocs:C,totalExports:y.size,totalDeadSource:S.length,totalDeadDocs:C.length}}function s(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function c(e,t){if(!t)return!0;let n=l(t).replace(/\/+$/,``),r=l(e);return r===n||r.startsWith(`${n}/`)}function l(e){return e.replace(/\\/g,`/`).replace(/^\.\//,``)}export{o as findDeadSymbols};
|
|
@@ -21,7 +21,7 @@ import { AGENT_BODIES } from '../definitions/bodies.mjs';
|
|
|
21
21
|
import { MODELS, VARIANT_GROUPS } from '../definitions/models.mjs';
|
|
22
22
|
import { PROMPTS } from '../definitions/prompts.mjs';
|
|
23
23
|
import { PROTOCOLS } from '../definitions/protocols.mjs';
|
|
24
|
-
import { IDE_CAPABILITIES
|
|
24
|
+
import { IDE_CAPABILITIES } from '../definitions/tools.mjs';
|
|
25
25
|
|
|
26
26
|
// ─── Copilot tool mapping ─────────────────────────────────────────────────
|
|
27
27
|
|
|
@@ -52,8 +52,9 @@ const COPILOT_TOOL_MAP = {
|
|
|
52
52
|
function buildToolsYaml(toolRole) {
|
|
53
53
|
const capabilities = IDE_CAPABILITIES[toolRole] || [];
|
|
54
54
|
const copilotTools = capabilities.map((cap) => COPILOT_TOOL_MAP[cap]).filter(Boolean);
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
// Use server wildcard instead of listing all 64 tools individually.
|
|
56
|
+
// VS Code expands `<server-name>/*` to all tools from that MCP server.
|
|
57
|
+
return `[${[...copilotTools, 'knowledge-base/*'].join(', ')}]`;
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
function copilotModel(agentName) {
|
|
@@ -99,6 +100,10 @@ function generateVariantAgent(roleName, suffix, def) {
|
|
|
99
100
|
|
|
100
101
|
const extra = def.extraBody ? `\n\n${def.extraBody}` : '';
|
|
101
102
|
|
|
103
|
+
const skillsSection = def.skills?.length
|
|
104
|
+
? `\n\n## Skills (load on demand)\n\n| Skill | When to load |\n|-------|--------------|\n${def.skills.map(([s, w]) => `| ${s} | ${w} |`).join('\n')}`
|
|
105
|
+
: '';
|
|
106
|
+
|
|
102
107
|
const titleMap = {
|
|
103
108
|
Researcher: 'The Context Gatherer',
|
|
104
109
|
'Code-Reviewer': 'The Quality Guardian',
|
|
@@ -115,7 +120,7 @@ model: ${model}
|
|
|
115
120
|
# ${fullName} - ${title}
|
|
116
121
|
|
|
117
122
|
You are **${fullName}**${identity}${extra}
|
|
118
|
-
${sharedRef}
|
|
123
|
+
${sharedRef}${skillsSection}
|
|
119
124
|
`;
|
|
120
125
|
}
|
|
121
126
|
|
|
@@ -106,6 +106,11 @@ export const AGENTS = {
|
|
|
106
106
|
toolRole: 'researcher',
|
|
107
107
|
sharedBase: 'researcher-base',
|
|
108
108
|
category: 'research',
|
|
109
|
+
skills: [
|
|
110
|
+
['`lesson-learned`', 'When analyzing past changes to extract engineering principles'],
|
|
111
|
+
['`c4-architecture`', 'When researching system architecture \u2014 produce C4 diagrams'],
|
|
112
|
+
['`adr-skill`', 'When the research involves a technical decision \u2014 draft an ADR'],
|
|
113
|
+
],
|
|
109
114
|
variants: {
|
|
110
115
|
Alpha: {
|
|
111
116
|
description: 'Primary deep research agent — also serves as default Researcher',
|
|
@@ -153,6 +158,13 @@ export const AGENTS = {
|
|
|
153
158
|
toolRole: 'reviewer',
|
|
154
159
|
sharedBase: 'architect-reviewer-base',
|
|
155
160
|
category: 'review',
|
|
161
|
+
skills: [
|
|
162
|
+
['`c4-architecture`', 'When reviewing architectural diagrams or boundary changes'],
|
|
163
|
+
[
|
|
164
|
+
'`adr-skill`',
|
|
165
|
+
'When the review involves architecture decisions \u2014 reference or create ADRs',
|
|
166
|
+
],
|
|
167
|
+
],
|
|
156
168
|
extraBody:
|
|
157
169
|
'You are **not** the Code-Reviewer agent. Code-Reviewer handles correctness, testing, security, and code quality. You handle the big picture: service boundaries, dependency direction, pattern adherence, and structural health.',
|
|
158
170
|
variants: {
|