knodin 0.5.0
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/LICENSE +21 -0
- package/README.md +590 -0
- package/dist/bin/cli.js +1704 -0
- package/dist/src/agent-integration.js +250 -0
- package/dist/src/artifact-refresh.js +81 -0
- package/dist/src/cli-args.js +267 -0
- package/dist/src/cli-model.js +324 -0
- package/dist/src/compact-structural.js +96 -0
- package/dist/src/competitive-constraints.js +20 -0
- package/dist/src/competitive-manifest.js +330 -0
- package/dist/src/competitive-measurement.js +183 -0
- package/dist/src/competitive-runner.js +453 -0
- package/dist/src/competitive-sandbox.js +108 -0
- package/dist/src/context-export.js +422 -0
- package/dist/src/context.js +102 -0
- package/dist/src/docs-sections.js +141 -0
- package/dist/src/doctor.js +380 -0
- package/dist/src/engine/ann-hnsw.js +271 -0
- package/dist/src/engine/embeddings.js +193 -0
- package/dist/src/engine/file-walker.js +43 -0
- package/dist/src/engine/index.js +13030 -0
- package/dist/src/engine/perf.js +115 -0
- package/dist/src/engine/prune.js +112 -0
- package/dist/src/engine/source-policy.js +69 -0
- package/dist/src/engine/sqlite.js +71 -0
- package/dist/src/engine/symbol-delete.js +58 -0
- package/dist/src/failure-diagnosis.js +590 -0
- package/dist/src/fleet.js +7 -0
- package/dist/src/git-executable.js +31 -0
- package/dist/src/graph-query-health.js +115 -0
- package/dist/src/index-activity.js +125 -0
- package/dist/src/init-progress-worker.js +107 -0
- package/dist/src/init-progress.js +155 -0
- package/dist/src/init.js +985 -0
- package/dist/src/lifecycle-health.js +213 -0
- package/dist/src/lsp-readonly.js +217 -0
- package/dist/src/output-compression.js +629 -0
- package/dist/src/output-telemetry.js +359 -0
- package/dist/src/pr-triage.js +638 -0
- package/dist/src/relationship-adapters.js +370 -0
- package/dist/src/release-attestation.js +533 -0
- package/dist/src/repair-progress-worker.js +121 -0
- package/dist/src/repair-progress.js +262 -0
- package/dist/src/repository-init-process.js +173 -0
- package/dist/src/repository-management.js +1089 -0
- package/dist/src/response-budget.js +184 -0
- package/dist/src/server.js +53 -0
- package/dist/src/system-config.js +615 -0
- package/dist/src/terminal-help.js +83 -0
- package/dist/src/tools/knodin-tools.js +1438 -0
- package/dist/src/tools/reckon-tools.js +5 -0
- package/dist/src/update-policy.js +944 -0
- package/dist/src/update-trust.js +503 -0
- package/dist/src/version.js +13 -0
- package/dist/src/visualization.js +162 -0
- package/dist/src/wait-for-fresh.js +98 -0
- package/dist/src/worktree-lifecycle.js +231 -0
- package/docs/CLI.md +39 -0
- package/docs/COMMAND-OUTPUT-COMPRESSION.md +194 -0
- package/docs/DEAD-CODE-AND-IMPACT.md +27 -0
- package/docs/DOCTOR-AND-UPDATES.md +84 -0
- package/docs/INDEXING-POLICY-AND-PROVENANCE.md +37 -0
- package/docs/INSTALLATION.md +208 -0
- package/docs/MCP.md +100 -0
- package/docs/PT-ACCESS-RECOMMENDATION.md +91 -0
- package/docs/RELEASE-0.3-EVIDENCE.md +73 -0
- package/docs/REPOSITORIES-AND-WORKTREES.md +81 -0
- package/docs/SIGNED-UPDATES.md +146 -0
- package/docs/SYSTEMS-AND-RELATIONSHIPS.md +45 -0
- package/docs/TELEMETRY.md +42 -0
- package/docs/releases/0.3.0.md +46 -0
- package/docs/releases/0.4.0.md +68 -0
- package/docs/releases/0.4.1.md +28 -0
- package/docs/releases/0.4.2.md +27 -0
- package/docs/releases/0.4.3.md +23 -0
- package/docs/releases/0.5.0.md +29 -0
- package/package.json +110 -0
- package/schemas/release-attestation-v1.schema.json +210 -0
- package/tree-sitter-prisma.wasm +0 -0
- package/tree-sitter-sql.wasm +0 -0
- package/tree-sitter-xml.wasm +0 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
const encoder = new TextEncoder();
|
|
2
|
+
export const MIN_RESPONSE_BUDGET_BYTES = 256;
|
|
3
|
+
function bytes(value) {
|
|
4
|
+
return encoder.encode(JSON.stringify(value)).byteLength;
|
|
5
|
+
}
|
|
6
|
+
function positiveInt(value, fallback) {
|
|
7
|
+
return value == null || !Number.isFinite(value) ? fallback : Math.max(1, Math.trunc(value));
|
|
8
|
+
}
|
|
9
|
+
function collectArrays(value, path = "$") {
|
|
10
|
+
if (Array.isArray(value)) {
|
|
11
|
+
return [{ path, value }, ...value.flatMap((item, i) => collectArrays(item, `${path}/${i}`))];
|
|
12
|
+
}
|
|
13
|
+
if (!value || typeof value !== "object")
|
|
14
|
+
return [];
|
|
15
|
+
return Object.entries(value).flatMap(([key, child]) => collectArrays(child, `${path}/${key}`));
|
|
16
|
+
}
|
|
17
|
+
function collectStrings(value, path = "$") {
|
|
18
|
+
if (!value || typeof value !== "object")
|
|
19
|
+
return [];
|
|
20
|
+
const entries = Array.isArray(value) ? value.entries() : Object.entries(value);
|
|
21
|
+
const found = [];
|
|
22
|
+
for (const [key, child] of entries) {
|
|
23
|
+
const childPath = `${path}/${String(key)}`;
|
|
24
|
+
if (typeof child === "string") {
|
|
25
|
+
found.push({ parent: value, key, path: childPath, value: child });
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
found.push(...collectStrings(child, childPath));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return found;
|
|
32
|
+
}
|
|
33
|
+
const PROTECTED_CONTRACT_KEYS = new Set([
|
|
34
|
+
"identity",
|
|
35
|
+
"symbol",
|
|
36
|
+
"file",
|
|
37
|
+
"filePath",
|
|
38
|
+
"error",
|
|
39
|
+
"status",
|
|
40
|
+
"operation",
|
|
41
|
+
"kind",
|
|
42
|
+
"name",
|
|
43
|
+
"target",
|
|
44
|
+
"to",
|
|
45
|
+
]);
|
|
46
|
+
function isTruncatableDetail(entry) {
|
|
47
|
+
return typeof entry.key !== "string" || !PROTECTED_CONTRACT_KEYS.has(entry.key);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Applies limits to the value that is actually JSON-serialized. Token accounting
|
|
51
|
+
* intentionally uses the deterministic local estimate of four UTF-8 bytes/token;
|
|
52
|
+
* callers can therefore reproduce the ceiling without installing a tokenizer.
|
|
53
|
+
*/
|
|
54
|
+
export function applyResponseBudget(value, operation, request, defaults) {
|
|
55
|
+
const byteRequest = positiveInt(request.bytes, defaults.bytes);
|
|
56
|
+
const tokenLimit = positiveInt(request.tokens, defaults.tokens);
|
|
57
|
+
const byteLimit = Math.min(byteRequest, tokenLimit * 4);
|
|
58
|
+
if (byteLimit < MIN_RESPONSE_BUDGET_BYTES) {
|
|
59
|
+
throw new RangeError(`response budget must allow at least ${MIN_RESPONSE_BUDGET_BYTES} serialized bytes (64 estimated tokens)`);
|
|
60
|
+
}
|
|
61
|
+
const itemLimit = positiveInt(request.items, defaults.items);
|
|
62
|
+
const payload = structuredClone(value);
|
|
63
|
+
const root = Array.isArray(payload)
|
|
64
|
+
? { results: payload }
|
|
65
|
+
: payload && typeof payload === "object"
|
|
66
|
+
? payload
|
|
67
|
+
: { result: payload };
|
|
68
|
+
const totals = {};
|
|
69
|
+
let truncated = false;
|
|
70
|
+
for (const entry of collectArrays(root)) {
|
|
71
|
+
totals[entry.path] = entry.value.length;
|
|
72
|
+
if (entry.value.length > itemLimit) {
|
|
73
|
+
entry.value.splice(itemLimit);
|
|
74
|
+
truncated = true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const metadata = {
|
|
78
|
+
byteLimit,
|
|
79
|
+
tokenLimit,
|
|
80
|
+
itemLimit,
|
|
81
|
+
serializedBytes: 0,
|
|
82
|
+
estimatedTokens: 0,
|
|
83
|
+
truncated: false,
|
|
84
|
+
totals,
|
|
85
|
+
};
|
|
86
|
+
root.responseBudget = metadata;
|
|
87
|
+
// Preserve collection contracts and identifiers where possible: large source,
|
|
88
|
+
// artifact and diagnostic strings are the first expendable detail.
|
|
89
|
+
while (bytes(root) > byteLimit) {
|
|
90
|
+
const candidate = collectStrings(root)
|
|
91
|
+
.filter((entry) => !entry.path.startsWith("$/responseBudget") &&
|
|
92
|
+
entry.value.length > 0 &&
|
|
93
|
+
isTruncatableDetail(entry))
|
|
94
|
+
.sort((a, b) => b.value.length - a.value.length)[0];
|
|
95
|
+
if (!candidate)
|
|
96
|
+
break;
|
|
97
|
+
const marker = "\n… [truncated]";
|
|
98
|
+
if (candidate.value.length <= marker.length + 1) {
|
|
99
|
+
if (Array.isArray(candidate.parent))
|
|
100
|
+
candidate.parent.splice(candidate.key, 1);
|
|
101
|
+
else
|
|
102
|
+
delete candidate.parent[candidate.key];
|
|
103
|
+
truncated = true;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const keep = Math.max(0, Math.floor((candidate.value.length - marker.length) / 2));
|
|
107
|
+
candidate.parent[candidate.key] =
|
|
108
|
+
`${candidate.value.slice(0, keep)}${marker}`;
|
|
109
|
+
truncated = true;
|
|
110
|
+
}
|
|
111
|
+
// Only drop tail items after scalar detail has been exhausted.
|
|
112
|
+
while (bytes(root) > byteLimit) {
|
|
113
|
+
const candidate = collectArrays(root)
|
|
114
|
+
.filter((entry) => !entry.path.startsWith("$/responseBudget") && entry.value.length > 0)
|
|
115
|
+
.sort((a, b) => bytes(b.value) - bytes(a.value))[0];
|
|
116
|
+
if (!candidate)
|
|
117
|
+
break;
|
|
118
|
+
candidate.value.pop();
|
|
119
|
+
truncated = true;
|
|
120
|
+
}
|
|
121
|
+
metadata.truncated = truncated;
|
|
122
|
+
if (truncated) {
|
|
123
|
+
metadata.continuation = {
|
|
124
|
+
operation,
|
|
125
|
+
after: "returned-items",
|
|
126
|
+
instruction: `Repeat ${operation} with a narrower selector, larger budget, or query drill-down.`,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
// Metadata changes the byte count, so converge after setting it. The reserve
|
|
130
|
+
// above is normally enough; this final pass handles unusually long paths.
|
|
131
|
+
metadata.serializedBytes = bytes(root);
|
|
132
|
+
metadata.estimatedTokens = Math.ceil(metadata.serializedBytes / 4);
|
|
133
|
+
if (bytes(root) > byteLimit && metadata.continuation) {
|
|
134
|
+
metadata.continuation.instruction = "Narrow or increase budget.";
|
|
135
|
+
metadata.serializedBytes = bytes(root);
|
|
136
|
+
metadata.estimatedTokens = Math.ceil(metadata.serializedBytes / 4);
|
|
137
|
+
}
|
|
138
|
+
while (bytes(root) > byteLimit) {
|
|
139
|
+
const candidate = collectStrings(root)
|
|
140
|
+
.filter((entry) => !entry.path.startsWith("$/responseBudget") &&
|
|
141
|
+
entry.value.length > 0 &&
|
|
142
|
+
isTruncatableDetail(entry))
|
|
143
|
+
.sort((a, b) => b.value.length - a.value.length)[0];
|
|
144
|
+
if (!candidate)
|
|
145
|
+
break;
|
|
146
|
+
const marker = "\n… [truncated]";
|
|
147
|
+
if (candidate.value.length <= marker.length + 1) {
|
|
148
|
+
if (Array.isArray(candidate.parent))
|
|
149
|
+
candidate.parent.splice(candidate.key, 1);
|
|
150
|
+
else
|
|
151
|
+
delete candidate.parent[candidate.key];
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
const keep = Math.max(0, Math.floor((candidate.value.length - marker.length) / 2));
|
|
155
|
+
candidate.parent[candidate.key] =
|
|
156
|
+
`${candidate.value.slice(0, keep)}${marker}`;
|
|
157
|
+
}
|
|
158
|
+
metadata.truncated = true;
|
|
159
|
+
}
|
|
160
|
+
metadata.serializedBytes = bytes(root);
|
|
161
|
+
metadata.estimatedTokens = Math.ceil(metadata.serializedBytes / 4);
|
|
162
|
+
while (bytes(root) > byteLimit) {
|
|
163
|
+
const candidate = collectArrays(root)
|
|
164
|
+
.filter((entry) => !entry.path.startsWith("$/responseBudget") && entry.value.length > 0)
|
|
165
|
+
.sort((a, b) => bytes(b.value) - bytes(a.value))[0];
|
|
166
|
+
if (!candidate)
|
|
167
|
+
break;
|
|
168
|
+
candidate.value.pop();
|
|
169
|
+
metadata.truncated = true;
|
|
170
|
+
metadata.serializedBytes = bytes(root);
|
|
171
|
+
metadata.estimatedTokens = Math.ceil(metadata.serializedBytes / 4);
|
|
172
|
+
}
|
|
173
|
+
for (let iteration = 0; iteration < 8; iteration++) {
|
|
174
|
+
const actual = bytes(root);
|
|
175
|
+
const tokens = Math.ceil(actual / 4);
|
|
176
|
+
if (metadata.serializedBytes === actual && metadata.estimatedTokens === tokens)
|
|
177
|
+
break;
|
|
178
|
+
metadata.serializedBytes = actual;
|
|
179
|
+
metadata.estimatedTokens = tokens;
|
|
180
|
+
}
|
|
181
|
+
if (bytes(root) > byteLimit)
|
|
182
|
+
throw new RangeError(`response budget ${byteLimit} cannot preserve the ${operation} response contract; narrow the request or increase the budget`);
|
|
183
|
+
return root;
|
|
184
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knodin MCP server (stdio).
|
|
3
|
+
*
|
|
4
|
+
* Registration uses the low-level request-handler API — NOT the high-level
|
|
5
|
+
* `server.tool()` overload — so `tsc` never pays the Zod→handler-arg inference
|
|
6
|
+
* cost that OOMs large tool sets. Gateway `inputSchema`s are hand-written JSON
|
|
7
|
+
* Schema literals; handler args are narrowed manually inside each dispatcher.
|
|
8
|
+
*/
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
12
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
13
|
+
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
14
|
+
import { getKnodinTools, handleKnodinTool } from "./tools/knodin-tools.js";
|
|
15
|
+
import { KNODIN_VERSION } from "./version.js";
|
|
16
|
+
export function createServer() {
|
|
17
|
+
const server = new Server({ name: "knodin", version: KNODIN_VERSION }, {
|
|
18
|
+
capabilities: { tools: {} },
|
|
19
|
+
instructions: "Use knodin first for cold or unfamiliar codebase work: context to orient, explain for source-evidenced symbol context, query impact before meaningful edits, and review before handoff. Prefer direct reads for exact literals, non-code files, or files just edited this turn. If status reports repair-needed, repair before relying on graph evidence.",
|
|
20
|
+
});
|
|
21
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
22
|
+
tools: getKnodinTools(),
|
|
23
|
+
}));
|
|
24
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
25
|
+
const { name, arguments: args } = request.params;
|
|
26
|
+
if (name !== "knodin" && name !== "reckon") {
|
|
27
|
+
throw new Error(`unknown tool: ${name}`);
|
|
28
|
+
}
|
|
29
|
+
const result = await handleKnodinTool(args);
|
|
30
|
+
return {
|
|
31
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
return server;
|
|
35
|
+
}
|
|
36
|
+
async function main() {
|
|
37
|
+
const server = createServer();
|
|
38
|
+
const transport = new StdioServerTransport();
|
|
39
|
+
await server.connect(transport);
|
|
40
|
+
// stdio server: log to stderr so stdout stays a clean JSON-RPC channel.
|
|
41
|
+
console.error("knodin MCP server running on stdio");
|
|
42
|
+
}
|
|
43
|
+
/** Start the stdio gateway from either the direct server entry or the packaged CLI. */
|
|
44
|
+
export async function startServer() {
|
|
45
|
+
await main();
|
|
46
|
+
}
|
|
47
|
+
// Run only when invoked directly (not when imported by tests).
|
|
48
|
+
if (process.argv[1] && fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) {
|
|
49
|
+
startServer().catch((err) => {
|
|
50
|
+
console.error(err);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
});
|
|
53
|
+
}
|