@vpxa/kb 0.1.11 → 0.1.13
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 +48 -37
- package/package.json +1 -1
- package/packages/analyzers/dist/entry-point-analyzer.d.ts +18 -0
- package/packages/analyzers/dist/entry-point-analyzer.js +6 -5
- package/packages/analyzers/dist/pattern-analyzer.js +1 -1
- package/packages/analyzers/dist/types.d.ts +1 -1
- package/packages/cli/dist/commands/init.d.ts +2 -1
- package/packages/cli/dist/commands/init.js +242 -183
- package/packages/cli/dist/commands/knowledge.js +1 -1
- package/packages/cli/dist/commands/system.js +6 -3
- package/packages/cli/dist/helpers.js +5 -3
- package/packages/core/dist/content-detector.d.ts +5 -1
- package/packages/core/dist/content-detector.js +1 -1
- package/packages/core/dist/index.d.ts +1 -1
- package/packages/core/dist/index.js +1 -1
- package/packages/core/dist/types.d.ts +2 -0
- package/packages/server/dist/index.js +1 -1
- package/packages/server/dist/server.d.ts +0 -13
- package/packages/server/dist/server.js +1 -1
- package/packages/server/dist/tools/analyze.tools.js +3 -1
- package/packages/server/dist/tools/audit.tool.d.ts +5 -0
- package/packages/server/dist/tools/audit.tool.js +4 -0
- package/packages/server/dist/tools/replay.tool.js +4 -4
- package/packages/server/dist/tools/search.tool.js +18 -14
- package/packages/server/dist/tools/status.tool.js +3 -3
- package/packages/server/dist/tools/toolkit.tools.d.ts +1 -1
- package/packages/server/dist/tools/toolkit.tools.js +23 -20
- package/packages/server/dist/version-check.d.ts +10 -0
- package/packages/server/dist/version-check.js +1 -0
- package/packages/store/dist/lance-store.js +1 -1
- package/packages/store/dist/store.interface.d.ts +2 -0
- package/packages/tools/dist/audit.d.ts +66 -0
- package/packages/tools/dist/audit.js +7 -0
- package/packages/tools/dist/check.d.ts +19 -0
- package/packages/tools/dist/check.js +2 -2
- package/packages/tools/dist/compact.d.ts +4 -2
- package/packages/tools/dist/compact.js +2 -2
- package/packages/tools/dist/dead-symbols.d.ts +9 -1
- package/packages/tools/dist/dead-symbols.js +2 -2
- package/packages/tools/dist/forge-classify.js +1 -1
- package/packages/tools/dist/guide.d.ts +23 -0
- package/packages/tools/dist/guide.js +1 -0
- package/packages/tools/dist/health.js +2 -1
- package/packages/tools/dist/index.d.ts +6 -2
- package/packages/tools/dist/index.js +1 -1
- package/packages/tools/dist/path-resolver.d.ts +12 -0
- package/packages/tools/dist/path-resolver.js +1 -0
- package/packages/tools/dist/replay.d.ts +1 -1
- package/packages/tools/dist/response-envelope.d.ts +41 -0
- package/packages/tools/dist/response-envelope.js +1 -0
- package/packages/tools/dist/scope-map.d.ts +2 -0
- package/packages/tools/dist/scope-map.js +1 -1
- package/packages/tools/dist/truncation.d.ts +9 -0
- package/packages/tools/dist/truncation.js +8 -8
- package/packages/tui/dist/App.js +109 -109
- package/packages/tui/dist/index.js +116 -116
- package/packages/tui/dist/panels/LogPanel.js +100 -100
- package/skills/knowledge-base/SKILL.md +19 -19
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import{existsSync as
|
|
1
|
+
import{existsSync as m,readdirSync as $,readFileSync as d,statSync as j}from"node:fs";import{extname as v,join as c,relative as M,resolve as S}from"node:path";function D(p){const e=S(p??process.cwd()),s=[],r=c(e,"package.json");if(m(r)){s.push({name:"package.json",status:"pass",message:"Found"});try{const t=JSON.parse(d(r,"utf-8"));t.name?s.push({name:"package.name",status:"pass",message:t.name}):s.push({name:"package.name",status:"warn",message:"Missing package name"});const u=t.scripts??{};for(const g of["build","test","lint"])u[g]?s.push({name:`script:${g}`,status:"pass",message:u[g]}):s.push({name:`script:${g}`,status:"warn",message:`No "${g}" script defined`});t.type==="module"?s.push({name:"esm",status:"pass",message:'ESM ("type": "module")'}):t.type==="commonjs"?s.push({name:"esm",status:"pass",message:'CJS ("type": "commonjs")'}):s.push({name:"esm",status:"warn",message:'No "type" field \u2014 defaults to CJS'}),t.engines?.node?s.push({name:"engines.node",status:"pass",message:t.engines.node}):s.push({name:"engines.node",status:"warn",message:"No Node.js engine constraint"})}catch{s.push({name:"package.json",status:"fail",message:"Failed to parse package.json"})}}else s.push({name:"package.json",status:"fail",message:"Missing \u2014 not a Node.js project"});const i=c(e,"tsconfig.json");m(i)?s.push({name:"tsconfig.json",status:"pass",message:"Found"}):s.push({name:"tsconfig.json",status:"warn",message:"Missing"});const n=c(e,".gitignore");if(m(n)){const t=d(n,"utf-8"),u=t.includes("node_modules"),g=t.includes("dist");u&&g?s.push({name:".gitignore",status:"pass",message:"Includes node_modules and dist"}):s.push({name:".gitignore",status:"warn",message:`Missing: ${u?"":"node_modules "}${g?"":"dist"}`.trim()})}else s.push({name:".gitignore",status:"warn",message:"Missing"});const o=["pnpm-lock.yaml","package-lock.json","yarn.lock","bun.lock"].find(t=>m(c(e,t)));o?s.push({name:"lockfile",status:"pass",message:o}):s.push({name:"lockfile",status:"warn",message:"No lock file found"});const l=c(e,"README.md");if(m(l)){const t=d(l,"utf-8").length;s.push({name:"README.md",status:t>100?"pass":"warn",message:t>100?`Found (${t} chars)`:"Found but very short"})}else s.push({name:"README.md",status:"warn",message:"Missing"});if(m(c(e,"LICENSE"))||m(c(e,"LICENSE.md"))?s.push({name:"LICENSE",status:"pass",message:"Found"}):s.push({name:"LICENSE",status:"warn",message:"Missing"}),m(i))try{const u=d(i,"utf-8").replace(/\/\/.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"");JSON.parse(u).compilerOptions?.strict===!0?s.push({name:"typescript.strict",status:"pass",message:"strict: true"}):s.push({name:"typescript.strict",status:"warn",message:"strict mode not enabled in tsconfig.json"})}catch{}if(m(r))try{const t=JSON.parse(d(r,"utf-8"));t.exports?s.push({name:"package.exports",status:"pass",message:"Has exports field"}):t.workspaces||m(c(e,"pnpm-workspace.yaml"))||s.push({name:"package.exports",status:"warn",message:"Missing \u2014 consider adding exports field for explicit public API"});const u=P(e,t);u.length>0&&_(e,u,s)}catch{}const f=c(e,"dist"),h=c(e,"src");if(m(f)&&m(h))try{const t=j(f).mtimeMs;x(h)>t?s.push({name:"build.freshness",status:"warn",message:"Source files are newer than dist/ \u2014 rebuild may be needed"}):s.push({name:"build.freshness",status:"pass",message:"Build output is fresh"})}catch{}if(m(h)){const t=F(h);if(t.length===0)s.push({name:"circular_deps",status:"pass",message:"No circular imports detected"});else{const u=t.slice(0,3).map(g=>g.join(" \u2192 "));s.push({name:"circular_deps",status:"warn",message:`${t.length} circular import(s): ${u.join("; ")}${t.length>3?` (+${t.length-3} more)`:""}`})}}const w=s.length,k=s.filter(t=>t.status==="pass").length,y=s.filter(t=>t.status==="fail").length,N=Math.round(k/w*100),b=y>0?`${y} critical issue(s), ${w-k-y} warning(s)`:w-k>0?`${w-k} warning(s)`:"All checks passed";return{path:e,checks:s,score:N,summary:b}}function P(p,e){const s=[];Array.isArray(e.workspaces)?s.push(...e.workspaces):e.workspaces&&typeof e.workspaces=="object"&&Array.isArray(e.workspaces.packages)&&s.push(...e.workspaces.packages);const r=c(p,"pnpm-workspace.yaml");if(m(r)){const n=d(r,"utf-8");for(const a of n.split(`
|
|
2
|
+
`)){const o=a.match(/^\s*-\s+['"]?([^'"#\s]+)['"]?\s*$/);o&&s.push(o[1])}}const i=[];for(const n of s)if(n.endsWith("/*")||n.endsWith("/**")){const a=c(p,n.replace(/\/\*+$/,""));if(m(a))try{for(const o of $(a,{withFileTypes:!0}))o.isDirectory()&&m(c(a,o.name,"package.json"))&&i.push(c(a,o.name))}catch{}}else{const a=c(p,n);m(c(a,"package.json"))&&i.push(a)}return i}function _(p,e,s){let r=0,i=0;const n=new Map;for(const a of e)try{const o=JSON.parse(d(c(a,"package.json"),"utf-8"));o.scripts?.test||r++,!o.exports&&!o.main&&i++;const l={...o.dependencies,...o.devDependencies};for(const f of Object.values(l))if(typeof f=="string"&&f.startsWith("workspace:")){const h=f.startsWith("workspace:*")?"workspace:*":f.startsWith("workspace:^")?"workspace:^":"workspace:~";n.set(h,(n.get(h)??0)+1)}}catch{}if(r>0?s.push({name:"workspace.test-scripts",status:"warn",message:`${r}/${e.length} workspace packages missing test script`}):s.push({name:"workspace.test-scripts",status:"pass",message:`All ${e.length} workspace packages have test scripts`}),i>0?s.push({name:"workspace.exports",status:"warn",message:`${i}/${e.length} packages missing exports field`}):e.length>0&&s.push({name:"workspace.exports",status:"pass",message:`All ${e.length} packages have exports or main field`}),n.size>1){const a=[...n.entries()].map(([o,l])=>`${o} (${l})`).join(", ");s.push({name:"workspace.protocol",status:"warn",message:`Mixed workspace protocols: ${a} \u2014 consider standardizing`})}else if(n.size===1){const[a]=n.keys();s.push({name:"workspace.protocol",status:"pass",message:`Consistent workspace protocol: ${a}`})}}function x(p){let e=0;try{for(const s of $(p,{withFileTypes:!0})){if(s.name.startsWith(".")||s.name==="node_modules")continue;const r=c(p,s.name);s.isDirectory()?e=Math.max(e,x(r)):e=Math.max(e,j(r).mtimeMs)}}catch{}return e}const A=/(?:import|export)\s+.*?from\s+['"](\.[^'"]+)['"]/g,C=new Set([".ts",".tsx",".mts"]);function F(p){const e=new Map;E(p,p,e);const s=[],r=new Set,i=new Set;function n(a,o){if(i.has(a)){const l=o.indexOf(a);l>=0&&s.push(o.slice(l).concat(a));return}if(!r.has(a)){r.add(a),i.add(a),o.push(a);for(const l of e.get(a)??[])n(l,o);o.pop(),i.delete(a)}}for(const a of e.keys())n(a,[]);return s}function E(p,e,s){let r;try{r=$(p)}catch{return}for(const i of r){if(i.startsWith(".")||i==="node_modules"||i==="__tests__")continue;const n=c(p,i);try{if(j(n).isDirectory())E(n,e,s);else if(C.has(v(i))){const o=M(e,n).replace(/\\/g,"/"),l=d(n,"utf-8"),f=[];for(const h of l.matchAll(A)){const w=h[1],k=I(p,w,e);k&&f.push(k)}s.set(o,f)}}catch{}}}function I(p,e,s){const r=S(p,e);for(const i of[".ts",".tsx",".mts",".js",".mjs",""]){const n=i?r.replace(/\.[^.]+$/,"")+i:r;return M(s,n).replace(/\\/g,"/").replace(/\.js$/,".ts").replace(/\.mjs$/,".mts")}return null}export{D as health};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
export { type AuditCheck, type AuditData, type AuditOptions, type AuditRecommendation, audit, } from './audit.js';
|
|
1
2
|
export { type BatchOperation, type BatchOptions, type BatchResult, batch, } from './batch.js';
|
|
2
3
|
export { type ChangelogEntry, type ChangelogFormat, type ChangelogOptions, type ChangelogResult, changelog, formatChangelog, } from './changelog.js';
|
|
3
|
-
export { type CheckOptions, type CheckResult, check } from './check.js';
|
|
4
|
+
export { type CheckOptions, type CheckResult, type CheckSummaryResult, check, summarizeCheckResult, } from './check.js';
|
|
4
5
|
export { type Checkpoint, checkpointLatest, checkpointList, checkpointLoad, checkpointSave, } from './checkpoint.js';
|
|
5
6
|
export { type CodemodChange, type CodemodOptions, type CodemodResult, type CodemodRule, codemod, } from './codemod.js';
|
|
6
7
|
export { type CompactOptions, type CompactResult, compact } from './compact.js';
|
|
@@ -20,17 +21,20 @@ export { type ClassifyTrigger, type ForgeClassifyCeremony, type ForgeClassifyOpt
|
|
|
20
21
|
export { type ConstraintRef, type ForgeGroundOptions, type ForgeGroundResult, forgeGround, } from './forge-ground.js';
|
|
21
22
|
export { type GitContextOptions, type GitContextResult, gitContext, } from './git-context.js';
|
|
22
23
|
export { type GraphAugmentedResult, type GraphAugmentOptions, type GraphQueryOptions, type GraphQueryResult, graphAugmentSearch, graphQuery, } from './graph-query.js';
|
|
24
|
+
export { type GuideRecommendation, type GuideResult, guide } from './guide.js';
|
|
23
25
|
export { type HealthCheck, type HealthResult, health, } from './health.js';
|
|
24
26
|
export { type HttpMethod, type HttpRequestOptions, type HttpRequestResult, httpRequest, } from './http-request.js';
|
|
25
27
|
export { type LaneDiffEntry, type LaneDiffResult, type LaneMergeResult, type LaneMeta, laneCreate, laneDiff, laneDiscard, laneList, laneMerge, laneStatus, } from './lane.js';
|
|
26
28
|
export { analyzeFile, type FileMetrics, type MeasureOptions, type MeasureResult, measure, } from './measure.js';
|
|
27
29
|
export { type OnboardMode, type OnboardOptions, type OnboardResult, type OnboardStepResult, onboard, } from './onboard.js';
|
|
28
30
|
export { type ParsedError, type ParsedGitStatus, type ParsedOutput, type ParsedTestResult, type ParsedTestSummary, parseBiome, parseGitStatus, parseOutput, parseTsc, parseVitest, } from './parse-output.js';
|
|
31
|
+
export { resolvePath } from './path-resolver.js';
|
|
29
32
|
export { type ManagedProcess, processList, processLogs, processStart, processStatus, processStop, } from './process-manager.js';
|
|
30
33
|
export { type QueueItem, type QueueState, queueClear, queueCreate, queueDelete, queueDone, queueFail, queueGet, queueList, queueNext, queuePush, } from './queue.js';
|
|
31
34
|
export { type RegexTestOptions, type RegexTestResult, regexTest, } from './regex-test.js';
|
|
32
35
|
export { type RenameChange, type RenameOptions, type RenameResult, rename, } from './rename.js';
|
|
33
36
|
export { type ReplayEntry, type ReplayOptions, replayAppend, replayCapture, replayClear, replayList, replayTrim, } from './replay.js';
|
|
37
|
+
export { errorResponse, type KBError, type KBErrorCode, type KBNextHint, type KBResponse, type KBResponseMeta, okResponse, } from './response-envelope.js';
|
|
34
38
|
export { type SchemaValidateOptions, type SchemaValidateResult, schemaValidate, type ValidationError, } from './schema-validate.js';
|
|
35
39
|
export { type ScopeMapEntry, type ScopeMapOptions, type ScopeMapResult, scopeMap, } from './scope-map.js';
|
|
36
40
|
export { type Snippet, type SnippetAction, type SnippetOptions, type SnippetResult, snippet, } from './snippet.js';
|
|
@@ -41,7 +45,7 @@ export { classifyExitCode, type TestRunOptions, type TestRunResult, testRun } fr
|
|
|
41
45
|
export { cosineSimilarity, estimateTokens, segment, } from './text-utils.js';
|
|
42
46
|
export { type TimeOptions, type TimeResult, timeUtils, } from './time-utils.js';
|
|
43
47
|
export { type TraceNode, type TraceOptions, type TraceResult, trace } from './trace.js';
|
|
44
|
-
export { headTailTruncate, paragraphTruncate } from './truncation.js';
|
|
48
|
+
export { headTailTruncate, paragraphTruncate, truncateToTokenBudget } from './truncation.js';
|
|
45
49
|
export { type WatchEvent, type WatchHandle, type WatchOptions, watchList, watchStart, watchStop, } from './watch.js';
|
|
46
50
|
export { type WebFetchMode, type WebFetchOptions, type WebFetchResult, webFetch, } from './web-fetch.js';
|
|
47
51
|
export { parseSearchResults, type WebSearchOptions, type WebSearchResult, type WebSearchResultItem, webSearch, } from './web-search.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{audit as p}from"./audit.js";import{batch as r}from"./batch.js";import{changelog as a,formatChangelog as y}from"./changelog.js";import{check as i,summarizeCheckResult as u}from"./check.js";import{checkpointLatest as m,checkpointList as d,checkpointLoad as f,checkpointSave as c}from"./checkpoint.js";import{codemod as h}from"./codemod.js";import{compact as g}from"./compact.js";import{dataTransform as S}from"./data-transform.js";import{findDeadSymbols as E}from"./dead-symbols.js";import{delegate as k,delegateListModels as F}from"./delegate.js";import{diffParse as b}from"./diff-parse.js";import{digest as v}from"./digest.js";import{encode as W}from"./encode.js";import{envInfo as q}from"./env-info.js";import{evaluate as B}from"./eval.js";import{evidenceMap as H}from"./evidence-map.js";import{fileSummary as I}from"./file-summary.js";import{find as Q}from"./find.js";import{findExamples as N}from"./find-examples.js";import{forgeClassify as z}from"./forge-classify.js";import{forgeGround as J}from"./forge-ground.js";import{gitContext as Y}from"./git-context.js";import{graphAugmentSearch as _,graphQuery as $}from"./graph-query.js";import{guide as te}from"./guide.js";import{health as oe}from"./health.js";import{httpRequest as se}from"./http-request.js";import{laneCreate as ye,laneDiff as ne,laneDiscard as ie,laneList as ue,laneMerge as le,laneStatus as me}from"./lane.js";import{analyzeFile as fe,measure as ce}from"./measure.js";import{onboard as he}from"./onboard.js";import{parseBiome as ge,parseGitStatus as Oe,parseOutput as Se,parseTsc as Ce,parseVitest as Ee}from"./parse-output.js";import{resolvePath as ke}from"./path-resolver.js";import{processList as De,processLogs as be,processStart as Me,processStatus as ve,processStop as Ge}from"./process-manager.js";import{queueClear as Le,queueCreate as qe,queueDelete as Ae,queueDone as Be,queueFail as Pe,queueGet as He,queueList as we,queueNext as Ie,queuePush as Ke}from"./queue.js";import{regexTest as Ve}from"./regex-test.js";import{rename as Ue}from"./rename.js";import{replayAppend as je,replayCapture as Je,replayClear as Xe,replayList as Ye,replayTrim as Ze}from"./replay.js";import{errorResponse as $e,okResponse as et}from"./response-envelope.js";import{schemaValidate as pt}from"./schema-validate.js";import{scopeMap as rt}from"./scope-map.js";import{snippet as at}from"./snippet.js";import{stashClear as nt,stashDelete as it,stashGet as ut,stashList as lt,stashSet as mt}from"./stash.js";import{stratumCard as ft}from"./stratum-card.js";import{symbol as Rt}from"./symbol.js";import{classifyExitCode as xt,testRun as gt}from"./test-run.js";import{cosineSimilarity as St,estimateTokens as Ct,segment as Et}from"./text-utils.js";import{timeUtils as kt}from"./time-utils.js";import{trace as Dt}from"./trace.js";import{headTailTruncate as Mt,paragraphTruncate as vt,truncateToTokenBudget as Gt}from"./truncation.js";import{watchList as Lt,watchStart as qt,watchStop as At}from"./watch.js";import{webFetch as Pt}from"./web-fetch.js";import{parseSearchResults as wt,webSearch as It}from"./web-search.js";import{addToWorkset as Qt,deleteWorkset as Vt,getWorkset as Nt,listWorksets as Ut,removeFromWorkset as zt,saveWorkset as jt}from"./workset.js";export{Qt as addToWorkset,fe as analyzeFile,p as audit,r as batch,a as changelog,i as check,m as checkpointLatest,d as checkpointList,f as checkpointLoad,c as checkpointSave,xt as classifyExitCode,h as codemod,g as compact,St as cosineSimilarity,S as dataTransform,k as delegate,F as delegateListModels,Vt as deleteWorkset,b as diffParse,v as digest,W as encode,q as envInfo,$e as errorResponse,Ct as estimateTokens,B as evaluate,H as evidenceMap,I as fileSummary,Q as find,E as findDeadSymbols,N as findExamples,z as forgeClassify,J as forgeGround,y as formatChangelog,Nt as getWorkset,Y as gitContext,_ as graphAugmentSearch,$ as graphQuery,te as guide,Mt as headTailTruncate,oe as health,se as httpRequest,ye as laneCreate,ne as laneDiff,ie as laneDiscard,ue as laneList,le as laneMerge,me as laneStatus,Ut as listWorksets,ce as measure,et as okResponse,he as onboard,vt as paragraphTruncate,ge as parseBiome,Oe as parseGitStatus,Se as parseOutput,wt as parseSearchResults,Ce as parseTsc,Ee as parseVitest,De as processList,be as processLogs,Me as processStart,ve as processStatus,Ge as processStop,Le as queueClear,qe as queueCreate,Ae as queueDelete,Be as queueDone,Pe as queueFail,He as queueGet,we as queueList,Ie as queueNext,Ke as queuePush,Ve as regexTest,zt as removeFromWorkset,Ue as rename,je as replayAppend,Je as replayCapture,Xe as replayClear,Ye as replayList,Ze as replayTrim,ke as resolvePath,jt as saveWorkset,pt as schemaValidate,rt as scopeMap,Et as segment,at as snippet,nt as stashClear,it as stashDelete,ut as stashGet,lt as stashList,mt as stashSet,ft as stratumCard,u as summarizeCheckResult,Rt as symbol,gt as testRun,kt as timeUtils,Dt as trace,Gt as truncateToTokenBudget,Lt as watchList,qt as watchStart,At as watchStop,Pt as webFetch,It as webSearch};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared path resolver for MCP tools (E-014).
|
|
3
|
+
* Provides consistent path resolution across all tools.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Resolve a user-supplied path to an absolute path.
|
|
7
|
+
* - Absolute paths are returned as-is
|
|
8
|
+
* - Relative paths are resolved against the server's cwd
|
|
9
|
+
* - '.' and empty/undefined default to cwd
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolvePath(input?: string): string;
|
|
12
|
+
//# sourceMappingURL=path-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isAbsolute as e,resolve as s}from"node:path";function t(r){return!r||r==="."?process.cwd():e(r)?r:s(process.cwd(),r)}export{t as resolvePath};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Replay — append-only audit trail of tool/CLI invocations.
|
|
3
3
|
*
|
|
4
4
|
* Captures tool name, arguments (redacted), duration, and result summary
|
|
5
|
-
* to `.kb-state/replay.jsonl`. Used by `kb replay` CLI, `
|
|
5
|
+
* to `.kb-state/replay.jsonl`. Used by `kb replay` CLI, `kb_replay` MCP tool,
|
|
6
6
|
* and the TUI log panel.
|
|
7
7
|
*/
|
|
8
8
|
export interface ReplayEntry {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standardized response envelope for KB tools (E-009).
|
|
3
|
+
* New tools should return KBResponse<T>. Existing tools can adopt gradually.
|
|
4
|
+
*/
|
|
5
|
+
export interface KBNextHint {
|
|
6
|
+
tool: string;
|
|
7
|
+
reason: string;
|
|
8
|
+
suggested_args?: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
export interface KBError {
|
|
11
|
+
code: KBErrorCode;
|
|
12
|
+
category: 'input' | 'runtime' | 'dependency' | 'timeout' | 'not_found';
|
|
13
|
+
retryable: boolean;
|
|
14
|
+
message: string;
|
|
15
|
+
suggestion?: string;
|
|
16
|
+
}
|
|
17
|
+
export type KBErrorCode = 'SYMBOL_NOT_FOUND' | 'INDEX_STALE' | 'TREE_SITTER_UNAVAILABLE' | 'PARSE_FAILED' | 'BUDGET_EXCEEDED' | 'PATH_NOT_FOUND' | 'EMBEDDING_COLD_START' | 'ANALYSIS_FAILED';
|
|
18
|
+
export interface KBResponseMeta {
|
|
19
|
+
durationMs: number;
|
|
20
|
+
tokensEstimate: number;
|
|
21
|
+
detail: 'summary' | 'errors' | 'full';
|
|
22
|
+
cached: boolean;
|
|
23
|
+
truncated: boolean;
|
|
24
|
+
caveats?: string[];
|
|
25
|
+
}
|
|
26
|
+
export interface KBResponse<T> {
|
|
27
|
+
ok: boolean;
|
|
28
|
+
tool: string;
|
|
29
|
+
summary: string;
|
|
30
|
+
data?: T;
|
|
31
|
+
meta: KBResponseMeta;
|
|
32
|
+
next?: KBNextHint[];
|
|
33
|
+
error?: KBError;
|
|
34
|
+
}
|
|
35
|
+
/** Create a success response. */
|
|
36
|
+
export declare function okResponse<T>(tool: string, summary: string, data: T, meta: Partial<KBResponseMeta> & {
|
|
37
|
+
durationMs: number;
|
|
38
|
+
}, next?: KBNextHint[]): KBResponse<T>;
|
|
39
|
+
/** Create an error response. */
|
|
40
|
+
export declare function errorResponse(tool: string, error: KBError, durationMs: number): KBResponse<never>;
|
|
41
|
+
//# sourceMappingURL=response-envelope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{estimateTokens as n}from"./text-utils.js";function u(s,r,t,e,o){const a=typeof t=="string"?t:JSON.stringify(t);return{ok:!0,tool:s,summary:r,data:t,meta:{durationMs:e.durationMs,tokensEstimate:e.tokensEstimate??n(a),detail:e.detail??"summary",cached:e.cached??!1,truncated:e.truncated??!1,...e.caveats?.length?{caveats:e.caveats}:{}},next:o}}function c(s,r,t){return{ok:!1,tool:s,summary:r.message,meta:{durationMs:t,tokensEstimate:n(r.message),detail:"summary",cached:!1,truncated:!1},error:r}}export{c as errorResponse,u as okResponse};
|
|
@@ -44,6 +44,8 @@ export interface ScopeMapResult {
|
|
|
44
44
|
totalEstimatedTokens: number;
|
|
45
45
|
/** Suggested reading order (file paths) */
|
|
46
46
|
readingOrder: string[];
|
|
47
|
+
/** Suggested compact/file_summary commands to reduce context */
|
|
48
|
+
compactCommands: string[];
|
|
47
49
|
}
|
|
48
50
|
/**
|
|
49
51
|
* Generate a task-scoped reading plan.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function C(c){return Math.ceil(c.length/4)}async function E(c,u,l){const{task:i,maxFiles:h=15,contentType:g,origin:f}=l,k=await c.embed(i),S={limit:h*3,contentType:g,origin:f},y=await u.search(k,S),o=new Map;for(const e of y){const t=e.record.sourcePath,n=o.get(t);n?(n.chunks.push(e),n.totalChars+=e.record.content.length,n.maxScore=Math.max(n.maxScore,e.score)):o.set(t,{chunks:[e],totalChars:e.record.content.length,maxScore:e.score})}const s=[...o.entries()].sort(([,e],[,t])=>t.maxScore-e.maxScore).slice(0,h).map(([e,{chunks:t,maxScore:n}])=>{const a=t.sort((r,m)=>r.record.startLine-m.record.startLine).map(r=>({start:r.record.startLine,end:r.record.endLine,heading:r.record.headingPath})),d=t.sort((r,m)=>m.score-r.score)[0],T=d.record.headingPath?`Matches: ${d.record.headingPath}`:`Contains relevant ${d.record.contentType} content`;return{path:e,reason:T,estimatedTokens:0,relevance:n,focusRanges:a}});for(const e of s){const t=o.get(e.path);t&&(e.estimatedTokens=C(t.chunks.map(n=>n.record.content).join("")))}const x=s.reduce((e,t)=>e+t.estimatedTokens,0),b=[...s].sort((e,t)=>{const n=e.path.includes("config")||e.path.includes("types")?-1:0,a=t.path.includes("config")||t.path.includes("types")?-1:0;return n!==a?n-a:t.relevance-e.relevance}).map(e=>e.path),M=100,p=[];for(const e of s)e.estimatedTokens<=M?p.push(`kb_file_summary({ path: "${e.path}" }) \u2192 ~${e.estimatedTokens} tokens`):p.push(`kb_compact({ path: "${e.path}", query: "${i}" }) \u2192 ~${Math.ceil(e.estimatedTokens/5)} tokens`);return{task:i,files:s,totalEstimatedTokens:x,readingOrder:b,compactCommands:p}}export{E as scopeMap};
|
|
@@ -19,4 +19,13 @@ export declare function headTailTruncate(text: string, maxLen: number, headRatio
|
|
|
19
19
|
* Best for web content and markdown where structure is at the top.
|
|
20
20
|
*/
|
|
21
21
|
export declare function paragraphTruncate(text: string, maxLen: number): string;
|
|
22
|
+
/**
|
|
23
|
+
* Truncate text to fit within a token budget.
|
|
24
|
+
* Uses ~4 chars/token approximation. Snaps to line boundaries.
|
|
25
|
+
*
|
|
26
|
+
* @param text - Full text to truncate
|
|
27
|
+
* @param maxTokens - Maximum token count
|
|
28
|
+
* @returns Original text if within budget, or truncated with notice
|
|
29
|
+
*/
|
|
30
|
+
export declare function truncateToTokenBudget(text: string, maxTokens: number): string;
|
|
22
31
|
//# sourceMappingURL=truncation.d.ts.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
const
|
|
2
|
-
`),i=h>0?s.slice(0,h):s,p=
|
|
3
|
-
`),
|
|
1
|
+
const R=.6;function m(n,t,e=.6){if(n.length<=t)return n;const r=Math.max(0,t-120),o=Math.floor(r*e),a=r-o,s=n.slice(0,o),h=s.lastIndexOf(`
|
|
2
|
+
`),i=h>0?s.slice(0,h):s,p=n.length-a,l=n.slice(p),u=l.indexOf(`
|
|
3
|
+
`),c=u>=0?l.slice(u+1):l,$=n.length-i.length-c.length;let d=1;const B=i.length,T=n.length-c.length;for(let g=B;g<T;g++)n.charCodeAt(g)===10&&d++;return`${i}
|
|
4
4
|
|
|
5
|
-
[\u2026 ${
|
|
6
|
-
`).length} + last ${
|
|
5
|
+
[\u2026 ${d} lines / ${($/1024).toFixed(1)}KB truncated \u2014 showing first ${i.split(`
|
|
6
|
+
`).length} + last ${c.split(`
|
|
7
7
|
`).length} lines]
|
|
8
8
|
|
|
9
|
-
${
|
|
9
|
+
${c}`}function A(n,t){if(n.length<=t)return n;const e=Math.max(0,t-200),r=n.slice(e,t).lastIndexOf(`
|
|
10
10
|
|
|
11
|
-
`),
|
|
11
|
+
`),o=r>=0?e+r:t,a=n.slice(0,o).trimEnd(),s=Math.round(o/n.length*100);return`${a}
|
|
12
12
|
|
|
13
13
|
---
|
|
14
|
-
*[Truncated at ${
|
|
14
|
+
*[Truncated at ${o.toLocaleString()} chars \u2014 ${s}% of original content]*`}function C(n,t){const e=t*4;return n.length<=e?n:m(n,e)}export{m as headTailTruncate,A as paragraphTruncate,C as truncateToTokenBudget};
|