@orquentra/codebuddy 2.9.0 → 2.15.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/ARCHITECTURE.md +98 -0
- package/CLAUDE_CODEX.md +33 -0
- package/README.md +114 -9
- package/dist/{adapters-S4HHTWJW.js → adapters-OJRSVFV3.js} +2 -2
- package/dist/{chunk-GXOML4UZ.js → chunk-4BSO3HST.js} +126 -18
- package/dist/chunk-4BSO3HST.js.map +1 -0
- package/dist/{chunk-CAEPHLHC.js → chunk-57642NGU.js} +2 -44
- package/dist/chunk-57642NGU.js.map +1 -0
- package/dist/{chunk-ESZXCZIN.js → chunk-6YI2D5F5.js} +33 -5
- package/dist/chunk-6YI2D5F5.js.map +1 -0
- package/dist/{chunk-GKNYMNFM.js → chunk-7IPSDDO5.js} +10 -3
- package/dist/chunk-7IPSDDO5.js.map +1 -0
- package/dist/chunk-BTTQWSDS.js +372 -0
- package/dist/chunk-BTTQWSDS.js.map +1 -0
- package/dist/{chunk-2WH2Q4TA.js → chunk-D5E7SGI5.js} +304 -77
- package/dist/chunk-D5E7SGI5.js.map +1 -0
- package/dist/chunk-EMWGLKPR.js +45 -0
- package/dist/chunk-EMWGLKPR.js.map +1 -0
- package/dist/chunk-GQKWUHMA.js +20 -0
- package/dist/chunk-GQKWUHMA.js.map +1 -0
- package/dist/chunk-ITXE27SZ.js +358 -0
- package/dist/chunk-ITXE27SZ.js.map +1 -0
- package/dist/{chunk-UK6XTS2Y.js → chunk-JJQDVGF7.js} +23 -23
- package/dist/chunk-JJQDVGF7.js.map +1 -0
- package/dist/{chunk-F4BJ3DXW.js → chunk-KQCP3ZYH.js} +1273 -331
- package/dist/chunk-KQCP3ZYH.js.map +1 -0
- package/dist/{chunk-QN76UJP7.js → chunk-KYRM3HPP.js} +89 -21
- package/dist/chunk-KYRM3HPP.js.map +1 -0
- package/dist/{chunk-KNR2P2UY.js → chunk-M75SN4D4.js} +19 -4
- package/dist/chunk-M75SN4D4.js.map +1 -0
- package/dist/{chunk-J4T6HHI4.js → chunk-RZ266NHE.js} +538 -317
- package/dist/chunk-RZ266NHE.js.map +1 -0
- package/dist/chunk-U7KDM62P.js +43 -0
- package/dist/chunk-U7KDM62P.js.map +1 -0
- package/dist/chunk-UATJCD2T.js +368 -0
- package/dist/chunk-UATJCD2T.js.map +1 -0
- package/dist/{chunk-ENKDFLOO.js → chunk-UOTKHSQ5.js} +25 -8
- package/dist/chunk-UOTKHSQ5.js.map +1 -0
- package/dist/{chunk-TLWGZVPC.js → chunk-UR3DF74I.js} +1007 -132
- package/dist/chunk-UR3DF74I.js.map +1 -0
- package/dist/chunk-UTPC66MV.js +128 -0
- package/dist/chunk-UTPC66MV.js.map +1 -0
- package/dist/{chunk-W7GAXL6C.js → chunk-V7PT6ER5.js} +6 -5
- package/dist/chunk-V7PT6ER5.js.map +1 -0
- package/dist/chunk-WHKXUXHE.js +156 -0
- package/dist/chunk-WHKXUXHE.js.map +1 -0
- package/dist/{chunk-SRA4MDVG.js → chunk-YMXFSHXT.js} +978 -950
- package/dist/chunk-YMXFSHXT.js.map +1 -0
- package/dist/cli/index.js +23 -9
- package/dist/cli/index.js.map +1 -1
- package/dist/{codebuddy-DO7ZhoWn.d.ts → codebuddy-CHqMptZB.d.ts} +35 -0
- package/dist/config-TXQJCCVI.js +15 -0
- package/dist/expand-KWYGNCKZ.js +98 -0
- package/dist/expand-KWYGNCKZ.js.map +1 -0
- package/dist/file-vectors-MKXTSGGH.js +19 -0
- package/dist/index-facts-4MTEHKMN.js +38 -0
- package/dist/index-pass-TBDUEZCB.js +14 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.js +25 -23
- package/dist/install-E3JWINTN.js +31 -0
- package/dist/langgraph/index.d.ts +1 -1
- package/dist/lean-MLTAFS5L.js +29 -0
- package/dist/local-75DJECVR.js +48 -0
- package/dist/local-llm-MECVJTVU.js +19 -0
- package/dist/{main-YJKSYFPT.js → main-RLMKQZW4.js} +999 -328
- package/dist/main-RLMKQZW4.js.map +1 -0
- package/dist/{memory-TGHVTBME.js → memory-PFFVMTCH.js} +9 -6
- package/dist/{memory-TGHVTBME.js.map → memory-PFFVMTCH.js.map} +1 -1
- package/dist/{operations-OG4ISWIM.js → operations-STR7S5UO.js} +8 -7
- package/dist/operations-STR7S5UO.js.map +1 -0
- package/dist/{pretool-command-PRFOIHMW.js → pretool-command-B5GY5T6E.js} +2 -2
- package/dist/pretool-command-B5GY5T6E.js.map +1 -0
- package/dist/prompt-gate-TDTFFQW2.js +8 -0
- package/dist/prompt-gate-TDTFFQW2.js.map +1 -0
- package/dist/{rerank-IQAEWLQR.js → rerank-XXKWDI5Q.js} +7 -4
- package/dist/{rerank-IQAEWLQR.js.map → rerank-XXKWDI5Q.js.map} +1 -1
- package/dist/{runtime-GCSEIAVD.js → runtime-SWFWGTQ4.js} +18 -9
- package/dist/runtime-SWFWGTQ4.js.map +1 -0
- package/dist/summaries-QXWFFDUZ.js +31 -0
- package/dist/summaries-QXWFFDUZ.js.map +1 -0
- package/dist/{zvec-XDZNZ2OL.js → zvec-F73IBWO5.js} +13 -6
- package/dist/zvec-F73IBWO5.js.map +1 -0
- package/package.json +13 -3
- package/dist/chunk-2WH2Q4TA.js.map +0 -1
- package/dist/chunk-6NZEZJYD.js +0 -206
- package/dist/chunk-6NZEZJYD.js.map +0 -1
- package/dist/chunk-CAEPHLHC.js.map +0 -1
- package/dist/chunk-ENKDFLOO.js.map +0 -1
- package/dist/chunk-ESZXCZIN.js.map +0 -1
- package/dist/chunk-F4BJ3DXW.js.map +0 -1
- package/dist/chunk-GKNYMNFM.js.map +0 -1
- package/dist/chunk-GXOML4UZ.js.map +0 -1
- package/dist/chunk-ITQO632W.js +0 -673
- package/dist/chunk-ITQO632W.js.map +0 -1
- package/dist/chunk-J4T6HHI4.js.map +0 -1
- package/dist/chunk-KNR2P2UY.js.map +0 -1
- package/dist/chunk-QN76UJP7.js.map +0 -1
- package/dist/chunk-SFMIMLXR.js +0 -63
- package/dist/chunk-SFMIMLXR.js.map +0 -1
- package/dist/chunk-SRA4MDVG.js.map +0 -1
- package/dist/chunk-TLWGZVPC.js.map +0 -1
- package/dist/chunk-UK6XTS2Y.js.map +0 -1
- package/dist/chunk-W7GAXL6C.js.map +0 -1
- package/dist/config-GEZFLXK6.js +0 -12
- package/dist/install-BXM56QCD.js +0 -19
- package/dist/lean-command-7DFW32MA.js +0 -19
- package/dist/main-YJKSYFPT.js.map +0 -1
- package/dist/summaries-ML53R7EL.js +0 -21
- /package/dist/{adapters-S4HHTWJW.js.map → adapters-OJRSVFV3.js.map} +0 -0
- /package/dist/{config-GEZFLXK6.js.map → config-TXQJCCVI.js.map} +0 -0
- /package/dist/{install-BXM56QCD.js.map → file-vectors-MKXTSGGH.js.map} +0 -0
- /package/dist/{lean-command-7DFW32MA.js.map → index-facts-4MTEHKMN.js.map} +0 -0
- /package/dist/{operations-OG4ISWIM.js.map → index-pass-TBDUEZCB.js.map} +0 -0
- /package/dist/{pretool-command-PRFOIHMW.js.map → install-E3JWINTN.js.map} +0 -0
- /package/dist/{runtime-GCSEIAVD.js.map → lean-MLTAFS5L.js.map} +0 -0
- /package/dist/{summaries-ML53R7EL.js.map → local-75DJECVR.js.map} +0 -0
- /package/dist/{zvec-XDZNZ2OL.js.map → local-llm-MECVJTVU.js.map} +0 -0
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import {
|
|
2
|
+
chatJson
|
|
3
|
+
} from "./chunk-6YI2D5F5.js";
|
|
4
|
+
import {
|
|
5
|
+
MemoryFileStore,
|
|
6
|
+
termOverlap
|
|
7
|
+
} from "./chunk-YMXFSHXT.js";
|
|
8
|
+
import {
|
|
9
|
+
generateEntityId
|
|
10
|
+
} from "./chunk-EMWGLKPR.js";
|
|
11
|
+
import {
|
|
12
|
+
redactSensitive,
|
|
13
|
+
scanSensitive
|
|
14
|
+
} from "./chunk-AL6VBTNA.js";
|
|
15
|
+
import {
|
|
16
|
+
resolveLlmConfig
|
|
17
|
+
} from "./chunk-WHKXUXHE.js";
|
|
18
|
+
import {
|
|
19
|
+
resolveNamespaceFrom
|
|
20
|
+
} from "./chunk-M75SN4D4.js";
|
|
21
|
+
import {
|
|
22
|
+
writeAtomic
|
|
23
|
+
} from "./chunk-CG5B3LYG.js";
|
|
24
|
+
import {
|
|
25
|
+
waitForForeground
|
|
26
|
+
} from "./chunk-BTTQWSDS.js";
|
|
27
|
+
|
|
28
|
+
// src/llm/index-facts.ts
|
|
29
|
+
import { createHash } from "crypto";
|
|
30
|
+
import { mkdir, readdir, readFile } from "fs/promises";
|
|
31
|
+
import { dirname, join } from "path";
|
|
32
|
+
import { parse as parseYaml } from "yaml";
|
|
33
|
+
import { z } from "zod";
|
|
34
|
+
var INDEX_FACT_AGENT = "codebuddy-index";
|
|
35
|
+
var MAX_FACTS = 40;
|
|
36
|
+
var PER_SOURCE = 8;
|
|
37
|
+
var SECTION_CHARS = 1600;
|
|
38
|
+
var DUPLICATE_OVERLAP = 0.8;
|
|
39
|
+
var TIMEOUT_MS = { local: 6e4, hosted: 2e4 };
|
|
40
|
+
var PROSE_SOURCES = /^(README|CONTRIBUTING|AGENTS|CLAUDE)(\.[a-z]+)?$/i;
|
|
41
|
+
var POLICY_DOC = /(deprecat|release[-_ ]?(policy|process)|versioning|support[-_ ]?policy|compatib)/i;
|
|
42
|
+
async function factSources(root) {
|
|
43
|
+
const top = await readdir(root).catch(() => []);
|
|
44
|
+
const docs = await readdir(join(root, "docs"), { recursive: true }).catch(() => []);
|
|
45
|
+
const workflows = await readdir(join(root, ".github", "workflows")).catch(() => []);
|
|
46
|
+
return [
|
|
47
|
+
...["package.json", "pyproject.toml"].filter((name) => top.includes(name)),
|
|
48
|
+
...top.filter((name) => PROSE_SOURCES.test(name)).sort(),
|
|
49
|
+
...workflows.filter((name) => /\.ya?ml$/.test(name)).sort().map((name) => `.github/workflows/${name}`),
|
|
50
|
+
...docs.map((name) => name.split("\\").join("/")).filter((name) => /\.(md|rst|txt)$/i.test(name) && POLICY_DOC.test(name)).sort().slice(0, 4).map((name) => `docs/${name}`)
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
async function extractIndexFacts(root, options = {}) {
|
|
54
|
+
const resolved = options.config ?? await resolveLlmConfig(root);
|
|
55
|
+
if (!resolved.enabled || resolved.features.facts === false) {
|
|
56
|
+
return { written: 0, removed: 0, skippedSources: 0, stoppedBy: "disabled" };
|
|
57
|
+
}
|
|
58
|
+
const config = resolved;
|
|
59
|
+
const namespace = options.namespace ?? await resolveNamespaceFrom(root);
|
|
60
|
+
const store = new MemoryFileStore(root);
|
|
61
|
+
const ledger = await readLedger(root);
|
|
62
|
+
const sources = await factSources(root);
|
|
63
|
+
let facts = await store.listFacts();
|
|
64
|
+
let removed = 0;
|
|
65
|
+
const removeFrom = async (path) => {
|
|
66
|
+
for (const fact of facts) {
|
|
67
|
+
if (fact.createdByAgent === INDEX_FACT_AGENT && fact.paths[0] === path) {
|
|
68
|
+
await store.deleteFact(fact.id);
|
|
69
|
+
removed++;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
facts = await store.listFacts();
|
|
73
|
+
};
|
|
74
|
+
for (const path of Object.keys(ledger.sources)) {
|
|
75
|
+
if (!sources.includes(path)) {
|
|
76
|
+
await removeFrom(path);
|
|
77
|
+
delete ledger.sources[path];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
let written = 0;
|
|
81
|
+
let skippedSources = 0;
|
|
82
|
+
let stoppedBy = "done";
|
|
83
|
+
const indexFacts = () => facts.filter((fact) => fact.createdByAgent === INDEX_FACT_AGENT).length;
|
|
84
|
+
for (const path of sources) {
|
|
85
|
+
if (options.signal?.aborted) {
|
|
86
|
+
stoppedBy = "aborted";
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
const text = await readFile(join(root, path), "utf8").catch(() => null);
|
|
90
|
+
if (text === null) continue;
|
|
91
|
+
const hash = sha(text);
|
|
92
|
+
if (ledger.sources[path] === hash) {
|
|
93
|
+
skippedSources++;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
await removeFrom(path);
|
|
97
|
+
if (indexFacts() >= MAX_FACTS) {
|
|
98
|
+
stoppedBy = "cap";
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
const candidates = await candidatesFor(root, path, text, config, options.signal);
|
|
102
|
+
let fromSource = 0;
|
|
103
|
+
for (const candidate of candidates) {
|
|
104
|
+
if (fromSource >= PER_SOURCE || indexFacts() >= MAX_FACTS) break;
|
|
105
|
+
if (scanSensitive(candidate.text).sensitive) continue;
|
|
106
|
+
if (facts.some(
|
|
107
|
+
(fact) => Math.max(
|
|
108
|
+
termOverlap(candidate.text, fact.object),
|
|
109
|
+
termOverlap(candidate.text, fact.content)
|
|
110
|
+
) >= DUPLICATE_OVERLAP
|
|
111
|
+
)) {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const id = generateEntityId("fact");
|
|
115
|
+
const content = `${candidate.text} (source: ${path}:L${candidate.line})`;
|
|
116
|
+
await store.writeFact({
|
|
117
|
+
id,
|
|
118
|
+
namespace,
|
|
119
|
+
subject: path,
|
|
120
|
+
predicate: "project-fact",
|
|
121
|
+
object: candidate.text,
|
|
122
|
+
confidence: 0.8,
|
|
123
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
124
|
+
createdByAgent: INDEX_FACT_AGENT,
|
|
125
|
+
sourceInteractionId: null,
|
|
126
|
+
sourceDeleted: false,
|
|
127
|
+
content,
|
|
128
|
+
paths: [path],
|
|
129
|
+
verification: [`${path}:L${candidate.line}`],
|
|
130
|
+
idempotencyKey: `index:${path}:${sha(candidate.text).slice(0, 16)}`.slice(0, 200),
|
|
131
|
+
fingerprint: sha(`${namespace}
|
|
132
|
+
${content}`)
|
|
133
|
+
});
|
|
134
|
+
facts = await store.listFacts();
|
|
135
|
+
written++;
|
|
136
|
+
fromSource++;
|
|
137
|
+
}
|
|
138
|
+
ledger.sources[path] = hash;
|
|
139
|
+
await writeLedger(root, ledger);
|
|
140
|
+
}
|
|
141
|
+
await writeLedger(root, ledger);
|
|
142
|
+
return { written, removed, skippedSources, stoppedBy };
|
|
143
|
+
}
|
|
144
|
+
async function listIndexFacts(root) {
|
|
145
|
+
return (await new MemoryFileStore(root).listFacts()).filter(
|
|
146
|
+
(fact) => fact.createdByAgent === INDEX_FACT_AGENT
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
async function pruneIndexFacts(root) {
|
|
150
|
+
const store = new MemoryFileStore(root);
|
|
151
|
+
const facts = await listIndexFacts(root);
|
|
152
|
+
for (const fact of facts) await store.deleteFact(fact.id);
|
|
153
|
+
await writeLedger(root, { version: 1, sources: {} });
|
|
154
|
+
return facts.length;
|
|
155
|
+
}
|
|
156
|
+
async function candidatesFor(root, path, text, config, signal) {
|
|
157
|
+
if (path === "package.json") return packageFacts(path, text);
|
|
158
|
+
if (path === "pyproject.toml") return pyprojectFacts(path, text);
|
|
159
|
+
if (path.startsWith(".github/workflows/")) return workflowFacts(path, text);
|
|
160
|
+
return proseFacts(root, path, stripManagedBlocks(text), config, signal);
|
|
161
|
+
}
|
|
162
|
+
function packageFacts(path, text) {
|
|
163
|
+
let manifest;
|
|
164
|
+
try {
|
|
165
|
+
manifest = JSON.parse(text);
|
|
166
|
+
} catch {
|
|
167
|
+
return [];
|
|
168
|
+
}
|
|
169
|
+
const out = [];
|
|
170
|
+
const node = manifest.engines?.node;
|
|
171
|
+
if (node)
|
|
172
|
+
out.push({ path, line: lineOf(text, '"node"'), text: `The project requires Node.js ${node}.` });
|
|
173
|
+
for (const name of ["test", "lint", "typecheck", "build", "format"]) {
|
|
174
|
+
const script = manifest.scripts?.[name];
|
|
175
|
+
if (script) {
|
|
176
|
+
out.push({
|
|
177
|
+
path,
|
|
178
|
+
line: lineOf(text, `"${name}"`),
|
|
179
|
+
text: `Run \`npm run ${name}\` to ${VERB[name]} (it runs \`${script.slice(0, 120)}\`).`
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return out;
|
|
184
|
+
}
|
|
185
|
+
var VERB = {
|
|
186
|
+
test: "run the tests",
|
|
187
|
+
lint: "lint the code",
|
|
188
|
+
typecheck: "type-check the code",
|
|
189
|
+
build: "build the project",
|
|
190
|
+
format: "format the code"
|
|
191
|
+
};
|
|
192
|
+
function pyprojectFacts(path, text) {
|
|
193
|
+
const out = [];
|
|
194
|
+
const python = text.match(/^\s*requires-python\s*=\s*["']([^"']+)["']/m)?.[1];
|
|
195
|
+
if (python) {
|
|
196
|
+
out.push({
|
|
197
|
+
path,
|
|
198
|
+
line: lineOf(text, "requires-python"),
|
|
199
|
+
text: `The project supports Python ${python}.`
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
for (const [tool, what] of [
|
|
203
|
+
["ruff", "Ruff is the linter/formatter"],
|
|
204
|
+
["mypy", "mypy type-checks the code"],
|
|
205
|
+
["pyright", "Pyright type-checks the code"],
|
|
206
|
+
["pytest", "Tests run with pytest"]
|
|
207
|
+
]) {
|
|
208
|
+
const header = `[tool.${tool}`;
|
|
209
|
+
if (text.includes(header)) {
|
|
210
|
+
out.push({
|
|
211
|
+
path,
|
|
212
|
+
line: lineOf(text, header),
|
|
213
|
+
text: `${what} (configured in pyproject.toml).`
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return out;
|
|
218
|
+
}
|
|
219
|
+
var CHECK_COMMAND = /\b(test|tests|pytest|lint|ruff|mypy|pyright|tsc|typecheck|vitest|jest|biome|eslint|go vet|cargo (test|clippy)|coverage)\b/i;
|
|
220
|
+
function workflowFacts(path, text) {
|
|
221
|
+
let workflow;
|
|
222
|
+
try {
|
|
223
|
+
workflow = parseYaml(text) ?? {};
|
|
224
|
+
} catch {
|
|
225
|
+
return [];
|
|
226
|
+
}
|
|
227
|
+
const commands = /* @__PURE__ */ new Set();
|
|
228
|
+
for (const job of Object.values(workflow.jobs ?? {})) {
|
|
229
|
+
for (const step of job?.steps ?? []) {
|
|
230
|
+
const run = typeof step?.run === "string" ? step.run.split("\n")[0]?.trim() : void 0;
|
|
231
|
+
if (run && CHECK_COMMAND.test(run) && run.length <= 120) commands.add(run);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const triggers = JSON.stringify(workflow.on ?? workflow.true ?? "");
|
|
235
|
+
const gates = triggers.includes("pull_request");
|
|
236
|
+
return [...commands].slice(0, 4).map((command) => ({
|
|
237
|
+
path,
|
|
238
|
+
line: lineOf(text, command),
|
|
239
|
+
text: `CI (${workflow.name ?? path}) runs \`${command}\`${gates ? " on pull requests; it must pass before merging" : ""}.`
|
|
240
|
+
}));
|
|
241
|
+
}
|
|
242
|
+
var proseSchema = z.object({
|
|
243
|
+
facts: z.array(z.object({ line: z.number().int(), fact: z.string() })).default([])
|
|
244
|
+
});
|
|
245
|
+
var FACT_GRAMMAR = {
|
|
246
|
+
type: "object",
|
|
247
|
+
properties: {
|
|
248
|
+
facts: {
|
|
249
|
+
type: "array",
|
|
250
|
+
maxItems: 6,
|
|
251
|
+
items: {
|
|
252
|
+
type: "object",
|
|
253
|
+
properties: { line: { type: "integer" }, fact: { type: "string", maxLength: 240 } }
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
var SYSTEM = [
|
|
259
|
+
"You extract durable project facts from a repository document for a team memory.",
|
|
260
|
+
'Answer with JSON only: {"facts":[{"line":12,"fact":"..."}]}.',
|
|
261
|
+
"Keep only lasting rules and facts a developer must know: conventions, required checks, supported versions, deprecation and release policy, how to run or test the project.",
|
|
262
|
+
"Each fact is one short sentence in the document's own words; line is the number of the line it comes from.",
|
|
263
|
+
"Skip marketing, installation steps for end users, links, badges and anything temporary. Give at most 6 facts; none is fine."
|
|
264
|
+
].join(" ");
|
|
265
|
+
async function proseFacts(root, path, text, config, signal) {
|
|
266
|
+
const lines = text.split(/\r?\n/);
|
|
267
|
+
const out = [];
|
|
268
|
+
for (const section of sections(lines)) {
|
|
269
|
+
if (signal?.aborted || out.length >= PER_SOURCE) break;
|
|
270
|
+
if (config.local) await waitForForeground(root, signal);
|
|
271
|
+
const numbered = section.map(({ line, text: text2 }) => `${line}: ${redactSensitive(text2)}`).join("\n");
|
|
272
|
+
const result = await chatJson(config, {
|
|
273
|
+
system: SYSTEM,
|
|
274
|
+
user: `File: ${path}
|
|
275
|
+
|
|
276
|
+
${numbered}`,
|
|
277
|
+
schema: proseSchema,
|
|
278
|
+
jsonSchema: FACT_GRAMMAR,
|
|
279
|
+
maxTokens: 500,
|
|
280
|
+
deadlineMs: config.local ? TIMEOUT_MS.local : TIMEOUT_MS.hosted,
|
|
281
|
+
purpose: "background",
|
|
282
|
+
repositoryRoot: root
|
|
283
|
+
});
|
|
284
|
+
if (!result.ok) continue;
|
|
285
|
+
for (const fact of result.value.facts) {
|
|
286
|
+
const sentence = fact.fact.trim().replace(/\s+/g, " ").slice(0, 240);
|
|
287
|
+
if (isStatement(sentence) && hasLineEvidence(lines, fact.line, sentence)) {
|
|
288
|
+
out.push({ path, line: fact.line, text: sentence });
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return out;
|
|
293
|
+
}
|
|
294
|
+
function isStatement(text) {
|
|
295
|
+
if (/```|^\$\s|^(cd|npm|npx|pip|git|make|curl)\s/i.test(text)) return false;
|
|
296
|
+
return (text.match(new RegExp("\\p{L}{2,}", "gu")) ?? []).length >= 5;
|
|
297
|
+
}
|
|
298
|
+
function hasLineEvidence(lines, line, fact) {
|
|
299
|
+
if (line < 1 || line > lines.length) return false;
|
|
300
|
+
const nearby = new Set(
|
|
301
|
+
lines.slice(Math.max(0, line - 3), line + 2).join(" ").toLowerCase().match(/[\p{L}\p{N}_]{4,}/gu) ?? []
|
|
302
|
+
);
|
|
303
|
+
const words = [...new Set(fact.toLowerCase().match(/[\p{L}\p{N}_]{4,}/gu) ?? [])];
|
|
304
|
+
const shared = words.filter((word) => nearby.has(word)).length;
|
|
305
|
+
return shared >= Math.min(2, words.length) && shared > 0;
|
|
306
|
+
}
|
|
307
|
+
function sections(lines) {
|
|
308
|
+
const out = [];
|
|
309
|
+
let current = [];
|
|
310
|
+
let size = 0;
|
|
311
|
+
lines.forEach((text, index) => {
|
|
312
|
+
const heading = /^#{1,3}\s/.test(text);
|
|
313
|
+
if (current.length > 0 && (heading || size + text.length > SECTION_CHARS)) {
|
|
314
|
+
out.push(current);
|
|
315
|
+
current = [];
|
|
316
|
+
size = 0;
|
|
317
|
+
}
|
|
318
|
+
if (text.trim()) {
|
|
319
|
+
current.push({ line: index + 1, text: text.slice(0, 400) });
|
|
320
|
+
size += Math.min(text.length, 400) + 6;
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
if (current.length > 0) out.push(current);
|
|
324
|
+
return out.slice(0, 12);
|
|
325
|
+
}
|
|
326
|
+
function stripManagedBlocks(text) {
|
|
327
|
+
return text.replace(
|
|
328
|
+
/<!-- codebuddy:[\w-]+:start -->[\s\S]*?<!-- codebuddy:[\w-]+:end -->/g,
|
|
329
|
+
(block) => block.replace(/[^\n]/g, "")
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
function lineOf(text, needle) {
|
|
333
|
+
const index = text.indexOf(needle);
|
|
334
|
+
return index < 0 ? 1 : text.slice(0, index).split("\n").length;
|
|
335
|
+
}
|
|
336
|
+
function sha(text) {
|
|
337
|
+
return createHash("sha256").update(text).digest("hex");
|
|
338
|
+
}
|
|
339
|
+
function ledgerPath(root) {
|
|
340
|
+
return join(root, ".codebuddy", "cache", "index-facts.json");
|
|
341
|
+
}
|
|
342
|
+
async function readLedger(root) {
|
|
343
|
+
try {
|
|
344
|
+
const parsed = JSON.parse(await readFile(ledgerPath(root), "utf8"));
|
|
345
|
+
if (parsed.version === 1 && parsed.sources) return parsed;
|
|
346
|
+
} catch {
|
|
347
|
+
}
|
|
348
|
+
return { version: 1, sources: {} };
|
|
349
|
+
}
|
|
350
|
+
async function writeLedger(root, ledger) {
|
|
351
|
+
await mkdir(dirname(ledgerPath(root)), { recursive: true });
|
|
352
|
+
await writeAtomic(ledgerPath(root), JSON.stringify(ledger));
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export {
|
|
356
|
+
INDEX_FACT_AGENT,
|
|
357
|
+
MAX_FACTS,
|
|
358
|
+
factSources,
|
|
359
|
+
extractIndexFacts,
|
|
360
|
+
listIndexFacts,
|
|
361
|
+
pruneIndexFacts,
|
|
362
|
+
packageFacts,
|
|
363
|
+
pyprojectFacts,
|
|
364
|
+
workflowFacts,
|
|
365
|
+
isStatement,
|
|
366
|
+
hasLineEvidence
|
|
367
|
+
};
|
|
368
|
+
//# sourceMappingURL=chunk-UATJCD2T.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/llm/index-facts.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport { mkdir, readdir, readFile } from \"node:fs/promises\";\nimport { dirname, join } from \"node:path\";\nimport { parse as parseYaml } from \"yaml\";\nimport { z } from \"zod\";\nimport { resolveNamespaceFrom } from \"../core/config-file.js\";\nimport { generateEntityId } from \"../core/ids.js\";\nimport { writeAtomic } from \"../core/markdown-store-fs.js\";\nimport { MemoryFileStore } from \"../core/memory-file-store.js\";\nimport { termOverlap } from \"../core/memory-search.js\";\nimport { redactSensitive, scanSensitive } from \"../core/sensitive.js\";\nimport { chatJson } from \"./client.js\";\nimport { type EnabledLlmConfig, resolveLlmConfig } from \"./config.js\";\nimport { waitForForeground } from \"./local.js\";\n\n/**\n * Project facts drawn from the repository at index time, so a fresh project\n * does not start with empty memory: supported versions and the test/lint\n * commands from manifests (read deterministically), required CI checks from\n * workflows, and rules from README / CONTRIBUTING / AGENTS.md / CLAUDE.md and\n * deprecation or release policies (read by the small model, local or BYOK).\n *\n * Every fact keeps its source: `paths: [file]`, `verification: [\"file:Lline\"]`,\n * and a line the fact's words must actually appear near. They are ordinary\n * Markdown facts (the durable store `remember` writes too), marked\n * `createdByAgent: \"codebuddy-index\"`; re-extraction only ever replaces facts\n * with that origin whose source file changed, never a human or agent fact.\n * Sensitive text is dropped, not redacted. At most `MAX_FACTS` per repository.\n */\nexport const INDEX_FACT_AGENT = \"codebuddy-index\";\nexport const MAX_FACTS = 40;\nconst PER_SOURCE = 8;\nconst SECTION_CHARS = 1_600;\n/** A fact this close to an existing one (Jaccard of content words) is a duplicate. */\nconst DUPLICATE_OVERLAP = 0.8;\nconst TIMEOUT_MS = { local: 60_000, hosted: 20_000 } as const;\n\nexport type IndexFactsResult = {\n written: number;\n removed: number;\n skippedSources: number;\n stoppedBy: \"done\" | \"disabled\" | \"cap\" | \"aborted\";\n};\n\ntype Candidate = { path: string; line: number; text: string };\ntype Ledger = { version: 1; sources: Record<string, string> };\n\nconst PROSE_SOURCES = /^(README|CONTRIBUTING|AGENTS|CLAUDE)(\\.[a-z]+)?$/i;\nconst POLICY_DOC =\n /(deprecat|release[-_ ]?(policy|process)|versioning|support[-_ ]?policy|compatib)/i;\n\n/** Files facts are read from, relative to the root, in priority order. */\nexport async function factSources(root: string): Promise<string[]> {\n const top = await readdir(root).catch(() => [] as string[]);\n const docs = await readdir(join(root, \"docs\"), { recursive: true }).catch(() => [] as string[]);\n const workflows = await readdir(join(root, \".github\", \"workflows\")).catch(() => [] as string[]);\n return [\n ...[\"package.json\", \"pyproject.toml\"].filter((name) => top.includes(name)),\n ...top.filter((name) => PROSE_SOURCES.test(name)).sort(),\n ...workflows\n .filter((name) => /\\.ya?ml$/.test(name))\n .sort()\n .map((name) => `.github/workflows/${name}`),\n ...docs\n .map((name) => name.split(\"\\\\\").join(\"/\"))\n .filter((name) => /\\.(md|rst|txt)$/i.test(name) && POLICY_DOC.test(name))\n .sort()\n .slice(0, 4)\n .map((name) => `docs/${name}`),\n ];\n}\n\n/**\n * Extract (or refresh) index facts. Sources whose content hash is unchanged\n * are skipped; a changed or deleted source has its old index facts removed\n * first. Without an enabled model layer nothing happens (2.14 behaviour).\n */\nexport async function extractIndexFacts(\n root: string,\n options: { config?: EnabledLlmConfig; signal?: AbortSignal; namespace?: string } = {},\n): Promise<IndexFactsResult> {\n const resolved = options.config ?? (await resolveLlmConfig(root));\n if (!resolved.enabled || resolved.features.facts === false) {\n return { written: 0, removed: 0, skippedSources: 0, stoppedBy: \"disabled\" };\n }\n const config = resolved;\n const namespace = options.namespace ?? (await resolveNamespaceFrom(root));\n const store = new MemoryFileStore(root);\n const ledger = await readLedger(root);\n const sources = await factSources(root);\n let facts = await store.listFacts();\n let removed = 0;\n const removeFrom = async (path: string) => {\n for (const fact of facts) {\n if (fact.createdByAgent === INDEX_FACT_AGENT && fact.paths[0] === path) {\n await store.deleteFact(fact.id);\n removed++;\n }\n }\n facts = await store.listFacts();\n };\n for (const path of Object.keys(ledger.sources)) {\n if (!sources.includes(path)) {\n await removeFrom(path);\n delete ledger.sources[path];\n }\n }\n\n let written = 0;\n let skippedSources = 0;\n let stoppedBy: IndexFactsResult[\"stoppedBy\"] = \"done\";\n const indexFacts = () => facts.filter((fact) => fact.createdByAgent === INDEX_FACT_AGENT).length;\n for (const path of sources) {\n if (options.signal?.aborted) {\n stoppedBy = \"aborted\";\n break;\n }\n const text = await readFile(join(root, path), \"utf8\").catch(() => null);\n if (text === null) continue;\n const hash = sha(text);\n if (ledger.sources[path] === hash) {\n skippedSources++;\n continue;\n }\n await removeFrom(path);\n if (indexFacts() >= MAX_FACTS) {\n stoppedBy = \"cap\";\n break;\n }\n const candidates = await candidatesFor(root, path, text, config, options.signal);\n let fromSource = 0;\n for (const candidate of candidates) {\n if (fromSource >= PER_SOURCE || indexFacts() >= MAX_FACTS) break;\n if (scanSensitive(candidate.text).sensitive) continue;\n // Never a second copy of what a human, agent or earlier source already said.\n if (\n facts.some(\n (fact) =>\n Math.max(\n termOverlap(candidate.text, fact.object),\n termOverlap(candidate.text, fact.content),\n ) >= DUPLICATE_OVERLAP,\n )\n ) {\n continue;\n }\n const id = generateEntityId(\"fact\");\n const content = `${candidate.text} (source: ${path}:L${candidate.line})`;\n await store.writeFact({\n id,\n namespace,\n subject: path,\n predicate: \"project-fact\",\n object: candidate.text,\n confidence: 0.8,\n createdAt: new Date().toISOString(),\n createdByAgent: INDEX_FACT_AGENT,\n sourceInteractionId: null,\n sourceDeleted: false,\n content,\n paths: [path],\n verification: [`${path}:L${candidate.line}`],\n idempotencyKey: `index:${path}:${sha(candidate.text).slice(0, 16)}`.slice(0, 200),\n fingerprint: sha(`${namespace}\\n${content}`),\n });\n facts = await store.listFacts();\n written++;\n fromSource++;\n }\n ledger.sources[path] = hash;\n await writeLedger(root, ledger);\n }\n await writeLedger(root, ledger);\n return { written, removed, skippedSources, stoppedBy };\n}\n\n/** Index facts currently stored (for `memory list|prune --origin index`). */\nexport async function listIndexFacts(root: string) {\n return (await new MemoryFileStore(root).listFacts()).filter(\n (fact) => fact.createdByAgent === INDEX_FACT_AGENT,\n );\n}\n\n/** Delete every index fact and forget the source hashes, so the next pass re-extracts. */\nexport async function pruneIndexFacts(root: string): Promise<number> {\n const store = new MemoryFileStore(root);\n const facts = await listIndexFacts(root);\n for (const fact of facts) await store.deleteFact(fact.id);\n await writeLedger(root, { version: 1, sources: {} });\n return facts.length;\n}\n\nasync function candidatesFor(\n root: string,\n path: string,\n text: string,\n config: EnabledLlmConfig,\n signal: AbortSignal | undefined,\n): Promise<Candidate[]> {\n if (path === \"package.json\") return packageFacts(path, text);\n if (path === \"pyproject.toml\") return pyprojectFacts(path, text);\n if (path.startsWith(\".github/workflows/\")) return workflowFacts(path, text);\n return proseFacts(root, path, stripManagedBlocks(text), config, signal);\n}\n\n/** Supported Node version and the project's own check commands. */\nexport function packageFacts(path: string, text: string): Candidate[] {\n let manifest: { engines?: Record<string, string>; scripts?: Record<string, string> };\n try {\n manifest = JSON.parse(text);\n } catch {\n return [];\n }\n const out: Candidate[] = [];\n const node = manifest.engines?.node;\n if (node)\n out.push({ path, line: lineOf(text, '\"node\"'), text: `The project requires Node.js ${node}.` });\n for (const name of [\"test\", \"lint\", \"typecheck\", \"build\", \"format\"]) {\n const script = manifest.scripts?.[name];\n if (script) {\n out.push({\n path,\n line: lineOf(text, `\"${name}\"`),\n text: `Run \\`npm run ${name}\\` to ${VERB[name]} (it runs \\`${script.slice(0, 120)}\\`).`,\n });\n }\n }\n return out;\n}\nconst VERB: Record<string, string> = {\n test: \"run the tests\",\n lint: \"lint the code\",\n typecheck: \"type-check the code\",\n build: \"build the project\",\n format: \"format the code\",\n};\n\n/** Supported Python versions and the configured tools. */\nexport function pyprojectFacts(path: string, text: string): Candidate[] {\n const out: Candidate[] = [];\n const python = text.match(/^\\s*requires-python\\s*=\\s*[\"']([^\"']+)[\"']/m)?.[1];\n if (python) {\n out.push({\n path,\n line: lineOf(text, \"requires-python\"),\n text: `The project supports Python ${python}.`,\n });\n }\n for (const [tool, what] of [\n [\"ruff\", \"Ruff is the linter/formatter\"],\n [\"mypy\", \"mypy type-checks the code\"],\n [\"pyright\", \"Pyright type-checks the code\"],\n [\"pytest\", \"Tests run with pytest\"],\n ] as const) {\n const header = `[tool.${tool}`;\n if (text.includes(header)) {\n out.push({\n path,\n line: lineOf(text, header),\n text: `${what} (configured in pyproject.toml).`,\n });\n }\n }\n return out;\n}\n\nconst CHECK_COMMAND =\n /\\b(test|tests|pytest|lint|ruff|mypy|pyright|tsc|typecheck|vitest|jest|biome|eslint|go vet|cargo (test|clippy)|coverage)\\b/i;\n\n/** CI's required checks: the run steps that test, lint or type-check. */\nexport function workflowFacts(path: string, text: string): Candidate[] {\n let workflow: {\n name?: string;\n on?: unknown;\n jobs?: Record<string, { steps?: Array<{ run?: string }> }>;\n };\n try {\n workflow = parseYaml(text) ?? {};\n } catch {\n return [];\n }\n const commands = new Set<string>();\n for (const job of Object.values(workflow.jobs ?? {})) {\n for (const step of job?.steps ?? []) {\n const run = typeof step?.run === \"string\" ? step.run.split(\"\\n\")[0]?.trim() : undefined;\n if (run && CHECK_COMMAND.test(run) && run.length <= 120) commands.add(run);\n }\n }\n // Only a workflow that runs on pull requests gates merging (a release job does not).\n // YAML 1.1 readers may parse the `on:` key as boolean true.\n const triggers = JSON.stringify(workflow.on ?? (workflow as Record<string, unknown>).true ?? \"\");\n const gates = triggers.includes(\"pull_request\");\n return [...commands].slice(0, 4).map((command) => ({\n path,\n line: lineOf(text, command),\n text: `CI (${workflow.name ?? path}) runs \\`${command}\\`${gates ? \" on pull requests; it must pass before merging\" : \"\"}.`,\n }));\n}\n\nconst proseSchema = z.object({\n facts: z.array(z.object({ line: z.number().int(), fact: z.string() })).default([]),\n});\n\n/** Grammar bounds for the local model (see summaries.ts CARD_GRAMMAR). */\nconst FACT_GRAMMAR = {\n type: \"object\",\n properties: {\n facts: {\n type: \"array\",\n maxItems: 6,\n items: {\n type: \"object\",\n properties: { line: { type: \"integer\" }, fact: { type: \"string\", maxLength: 240 } },\n },\n },\n },\n};\n\nconst SYSTEM = [\n \"You extract durable project facts from a repository document for a team memory.\",\n 'Answer with JSON only: {\"facts\":[{\"line\":12,\"fact\":\"...\"}]}.',\n \"Keep only lasting rules and facts a developer must know: conventions, required checks, supported versions, deprecation and release policy, how to run or test the project.\",\n \"Each fact is one short sentence in the document's own words; line is the number of the line it comes from.\",\n \"Skip marketing, installation steps for end users, links, badges and anything temporary. Give at most 6 facts; none is fine.\",\n].join(\" \");\n\nasync function proseFacts(\n root: string,\n path: string,\n text: string,\n config: EnabledLlmConfig,\n signal: AbortSignal | undefined,\n): Promise<Candidate[]> {\n const lines = text.split(/\\r?\\n/);\n const out: Candidate[] = [];\n for (const section of sections(lines)) {\n if (signal?.aborted || out.length >= PER_SOURCE) break;\n if (config.local) await waitForForeground(root, signal);\n const numbered = section\n .map(({ line, text }) => `${line}: ${redactSensitive(text)}`)\n .join(\"\\n\");\n const result = await chatJson(config, {\n system: SYSTEM,\n user: `File: ${path}\\n\\n${numbered}`,\n schema: proseSchema,\n jsonSchema: FACT_GRAMMAR,\n maxTokens: 500,\n deadlineMs: config.local ? TIMEOUT_MS.local : TIMEOUT_MS.hosted,\n purpose: \"background\",\n repositoryRoot: root,\n });\n if (!result.ok) continue;\n for (const fact of result.value.facts) {\n const sentence = fact.fact.trim().replace(/\\s+/g, \" \").slice(0, 240);\n if (isStatement(sentence) && hasLineEvidence(lines, fact.line, sentence)) {\n out.push({ path, line: fact.line, text: sentence });\n }\n }\n }\n return out;\n}\n\n/**\n * A fact is a statement: at least five words of prose, not a shell line, a\n * code fence or a bare heading the small model copied out of a README.\n */\nexport function isStatement(text: string): boolean {\n if (/```|^\\$\\s|^(cd|npm|npx|pip|git|make|curl)\\s/i.test(text)) return false;\n return (text.match(/\\p{L}{2,}/gu) ?? []).length >= 5;\n}\n\n/**\n * The model's fact must be supported by its cited line (± 2): at least two of\n * its content words (≥ 4 letters) appear there, or all of them for a short fact.\n */\nexport function hasLineEvidence(lines: string[], line: number, fact: string): boolean {\n if (line < 1 || line > lines.length) return false;\n const nearby = new Set(\n lines\n .slice(Math.max(0, line - 3), line + 2)\n .join(\" \")\n .toLowerCase()\n .match(/[\\p{L}\\p{N}_]{4,}/gu) ?? [],\n );\n const words = [...new Set(fact.toLowerCase().match(/[\\p{L}\\p{N}_]{4,}/gu) ?? [])];\n const shared = words.filter((word) => nearby.has(word)).length;\n return shared >= Math.min(2, words.length) && shared > 0;\n}\n\n/** Heading-delimited chunks of at most `SECTION_CHARS`, with 1-based line numbers. */\nfunction sections(lines: string[]): Array<Array<{ line: number; text: string }>> {\n const out: Array<Array<{ line: number; text: string }>> = [];\n let current: Array<{ line: number; text: string }> = [];\n let size = 0;\n lines.forEach((text, index) => {\n const heading = /^#{1,3}\\s/.test(text);\n if (current.length > 0 && (heading || size + text.length > SECTION_CHARS)) {\n out.push(current);\n current = [];\n size = 0;\n }\n if (text.trim()) {\n current.push({ line: index + 1, text: text.slice(0, 400) });\n size += Math.min(text.length, 400) + 6;\n }\n });\n if (current.length > 0) out.push(current);\n // A long README: the first sections carry the rules that matter.\n return out.slice(0, 12);\n}\n\n/** CodeBuddy's own managed blocks in CLAUDE.md / AGENTS.md are not project facts. */\nfunction stripManagedBlocks(text: string): string {\n // Blank the block (keeping its line breaks) so cited line numbers stay true.\n return text.replace(\n /<!-- codebuddy:[\\w-]+:start -->[\\s\\S]*?<!-- codebuddy:[\\w-]+:end -->/g,\n (block) => block.replace(/[^\\n]/g, \"\"),\n );\n}\n\nfunction lineOf(text: string, needle: string): number {\n const index = text.indexOf(needle);\n return index < 0 ? 1 : text.slice(0, index).split(\"\\n\").length;\n}\n\nfunction sha(text: string): string {\n return createHash(\"sha256\").update(text).digest(\"hex\");\n}\n\nfunction ledgerPath(root: string): string {\n return join(root, \".codebuddy\", \"cache\", \"index-facts.json\");\n}\n\nasync function readLedger(root: string): Promise<Ledger> {\n try {\n const parsed = JSON.parse(await readFile(ledgerPath(root), \"utf8\")) as Ledger;\n if (parsed.version === 1 && parsed.sources) return parsed;\n } catch {\n // Missing: every source is new.\n }\n return { version: 1, sources: {} };\n}\n\nasync function writeLedger(root: string, ledger: Ledger): Promise<void> {\n await mkdir(dirname(ledgerPath(root)), { recursive: true });\n await writeAtomic(ledgerPath(root), JSON.stringify(ledger));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,kBAAkB;AAC3B,SAAS,OAAO,SAAS,gBAAgB;AACzC,SAAS,SAAS,YAAY;AAC9B,SAAS,SAAS,iBAAiB;AACnC,SAAS,SAAS;AAyBX,IAAM,mBAAmB;AACzB,IAAM,YAAY;AACzB,IAAM,aAAa;AACnB,IAAM,gBAAgB;AAEtB,IAAM,oBAAoB;AAC1B,IAAM,aAAa,EAAE,OAAO,KAAQ,QAAQ,IAAO;AAYnD,IAAM,gBAAgB;AACtB,IAAM,aACJ;AAGF,eAAsB,YAAY,MAAiC;AACjE,QAAM,MAAM,MAAM,QAAQ,IAAI,EAAE,MAAM,MAAM,CAAC,CAAa;AAC1D,QAAM,OAAO,MAAM,QAAQ,KAAK,MAAM,MAAM,GAAG,EAAE,WAAW,KAAK,CAAC,E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27
27
|
outlineEntries: 40,
|
|
28
28
|
blockLines: 100,
|
|
29
|
-
grepHeadLimit: 100
|
|
29
|
+
grepHeadLimit: 100,
|
|
30
|
+
initialReadLines: 200
|
|
30
31
|
};
|
|
31
32
|
var SPECIAL_READ = /* @__PURE__ */ new Set([
|
|
32
33
|
".png",
|
|
@@ -44,8 +45,11 @@ async function decidePreTool(input, env = process.env) {
|
|
|
44
45
|
if (env.CODEBUDDY_TOOL_GUARD === "0") return null;
|
|
45
46
|
const toolInput = input.tool_input ?? {};
|
|
46
47
|
if (input.tool_name === "Grep") return capGrep(toolInput);
|
|
47
|
-
|
|
48
|
-
if (input.tool_name === "
|
|
48
|
+
const strict = env.CODEBUDDY_TOOL_GUARD === "strict";
|
|
49
|
+
if (input.tool_name === "Read")
|
|
50
|
+
return guardRead(resolve(input.cwd ?? process.cwd()), toolInput, strict);
|
|
51
|
+
if (input.tool_name === "Bash" && strict)
|
|
52
|
+
return guardBash(resolve(input.cwd ?? process.cwd()), toolInput);
|
|
49
53
|
return null;
|
|
50
54
|
}
|
|
51
55
|
function capGrep(toolInput) {
|
|
@@ -57,7 +61,7 @@ function capGrep(toolInput) {
|
|
|
57
61
|
}
|
|
58
62
|
};
|
|
59
63
|
}
|
|
60
|
-
async function largeFile(root, filePath) {
|
|
64
|
+
async function largeFile(root, filePath, includeOutline = true) {
|
|
61
65
|
const absolute = isAbsolute(filePath) ? resolve(filePath) : resolve(root, filePath);
|
|
62
66
|
const rel = relative(root, absolute);
|
|
63
67
|
if (rel === "" || rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel)) return null;
|
|
@@ -77,14 +81,27 @@ async function largeFile(root, filePath) {
|
|
|
77
81
|
if (lines.at(-1) === "") lines.pop();
|
|
78
82
|
if (lines.length <= TOOL_GUARD.readLines && size <= TOOL_GUARD.readBytes) return null;
|
|
79
83
|
const path = rel.replace(/\\/g, "/");
|
|
80
|
-
return {
|
|
84
|
+
return {
|
|
85
|
+
path,
|
|
86
|
+
lines: lines.length,
|
|
87
|
+
size,
|
|
88
|
+
outline: includeOutline ? outlineOf(path, text, lines) : []
|
|
89
|
+
};
|
|
81
90
|
}
|
|
82
|
-
async function guardRead(root, toolInput) {
|
|
91
|
+
async function guardRead(root, toolInput, strict) {
|
|
83
92
|
if (toolInput.offset !== void 0 || toolInput.limit !== void 0) return null;
|
|
84
93
|
const filePath = toolInput.file_path;
|
|
85
94
|
if (typeof filePath !== "string" || !filePath) return null;
|
|
86
|
-
const file = await largeFile(root, filePath);
|
|
95
|
+
const file = await largeFile(root, filePath, strict);
|
|
87
96
|
if (!file) return null;
|
|
97
|
+
if (!strict)
|
|
98
|
+
return {
|
|
99
|
+
hookSpecificOutput: {
|
|
100
|
+
hookEventName: "PreToolUse",
|
|
101
|
+
updatedInput: { ...toolInput, offset: 1, limit: TOOL_GUARD.initialReadLines },
|
|
102
|
+
additionalContext: `CodeBuddy bounded this unranged Read to lines 1-${TOOL_GUARD.initialReadLines} of ${file.lines}. Continue with an explicit offset/limit or request the full ${file.lines} lines if needed.`
|
|
103
|
+
}
|
|
104
|
+
};
|
|
88
105
|
return deny(file, [
|
|
89
106
|
"Read only the part you need with offset and limit (offset = first line, limit = line count).",
|
|
90
107
|
"To find specific text, use Grep with output_mode content and -n instead of reading the file.",
|
|
@@ -212,4 +229,4 @@ async function runPreToolHookCommand() {
|
|
|
212
229
|
export {
|
|
213
230
|
runPreToolHookCommand
|
|
214
231
|
};
|
|
215
|
-
//# sourceMappingURL=chunk-
|
|
232
|
+
//# sourceMappingURL=chunk-UOTKHSQ5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/pretool.ts","../src/hooks/pretool-command.ts"],"sourcesContent":["import { open, stat } from \"node:fs/promises\";\nimport { extname, isAbsolute, relative, resolve, sep } from \"node:path\";\nimport { extractSymbolTable, supportsSymbols } from \"../indexer/symbols.js\";\nimport type { HookInput } from \"./runtime.js\";\n\n/**\n * PreToolUse tool guard (Claude Code): cut tool output that would otherwise\n * stay in context for the rest of the session, without touching permissions.\n *\n * - Large unranged Read → bounded first read, with an explicit continuation hint.\n * Any requested offset/limit passes unchanged. Legacy denial is opt-in strict.\n * - Grep in content mode with no head_limit → the same input plus a limit.\n * - Bash passes unchanged by default; strict mode retains the legacy guard.\n * Shell pipelines are never rewritten, so check exit status is preserved.\n *\n * Never emits `permissionDecision: \"allow\"`: Claude Code checks permissions on\n * the (possibly rewritten) input as usual. Verified on Claude Code 2.1.287.\n */\n/**\n * Only files whose full read is clearly expensive: below this, an agent that\n * re-reads the whole file after the outline (observed live) costs a turn for\n * nothing.\n */\nexport const TOOL_GUARD = {\n readLines: 1_000,\n readBytes: 80_000,\n /** Symbols shorter than this are noise in an outline (one-line constants). */\n outlineMinSymbolLines: 3,\n /** Fewer top-level symbols than this: list class methods too. */\n minTopLevelEntries: 10,\n outlineEntries: 40,\n blockLines: 100,\n grepHeadLimit: 100,\n initialReadLines: 200,\n} as const;\n\n/** Read renders these itself (images, PDFs, notebooks); never guard them. */\nconst SPECIAL_READ = new Set([\n \".png\",\n \".jpg\",\n \".jpeg\",\n \".gif\",\n \".webp\",\n \".bmp\",\n \".svg\",\n \".pdf\",\n \".ipynb\",\n]);\nconst MAX_GUARD_BYTES = 2_000_000;\n\nexport type PreToolDecision = {\n hookSpecificOutput: {\n hookEventName: \"PreToolUse\";\n permissionDecision?: \"deny\";\n permissionDecisionReason?: string;\n updatedInput?: Record<string, unknown>;\n additionalContext?: string;\n };\n} | null;\n\nexport async function decidePreTool(\n input: HookInput,\n env: NodeJS.ProcessEnv = process.env,\n): Promise<PreToolDecision> {\n if (env.CODEBUDDY_TOOL_GUARD === \"0\") return null;\n const toolInput = input.tool_input ?? {};\n if (input.tool_name === \"Grep\") return capGrep(toolInput);\n const strict = env.CODEBUDDY_TOOL_GUARD === \"strict\";\n if (input.tool_name === \"Read\")\n return guardRead(resolve(input.cwd ?? process.cwd()), toolInput, strict);\n if (input.tool_name === \"Bash\" && strict)\n return guardBash(resolve(input.cwd ?? process.cwd()), toolInput);\n return null;\n}\n\nfunction capGrep(toolInput: Record<string, unknown>): PreToolDecision {\n if (toolInput.output_mode !== \"content\" || toolInput.head_limit !== undefined) return null;\n return {\n hookSpecificOutput: {\n hookEventName: \"PreToolUse\",\n updatedInput: { ...toolInput, head_limit: TOOL_GUARD.grepHeadLimit },\n },\n };\n}\n\n/** A file inside the repository too large to read whole, with its outline; else null. */\nexport async function largeFile(\n root: string,\n filePath: string,\n includeOutline = true,\n): Promise<{ path: string; lines: number; size: number; outline: string[] } | null> {\n const absolute = isAbsolute(filePath) ? resolve(filePath) : resolve(root, filePath);\n const rel = relative(root, absolute);\n if (rel === \"\" || rel === \"..\" || rel.startsWith(`..${sep}`) || isAbsolute(rel)) return null;\n if (SPECIAL_READ.has(extname(absolute).toLowerCase())) return null;\n let size: number;\n try {\n const info = await stat(absolute);\n if (!info.isFile()) return null;\n size = info.size;\n } catch {\n return null;\n }\n if (size > MAX_GUARD_BYTES) return null; // Read refuses huge files itself.\n const text = await readText(absolute);\n if (text === null) return null;\n const lines = text.split(/\\r?\\n/);\n if (lines.at(-1) === \"\") lines.pop();\n if (lines.length <= TOOL_GUARD.readLines && size <= TOOL_GUARD.readBytes) return null;\n const path = rel.replace(/\\\\/g, \"/\");\n return {\n path,\n lines: lines.length,\n size,\n outline: includeOutline ? outlineOf(path, text, lines) : [],\n };\n}\n\nasync function guardRead(\n root: string,\n toolInput: Record<string, unknown>,\n strict: boolean,\n): Promise<PreToolDecision> {\n if (toolInput.offset !== undefined || toolInput.limit !== undefined) return null;\n const filePath = toolInput.file_path;\n if (typeof filePath !== \"string\" || !filePath) return null;\n const file = await largeFile(root, filePath, strict);\n if (!file) return null;\n if (!strict)\n return {\n hookSpecificOutput: {\n hookEventName: \"PreToolUse\",\n updatedInput: { ...toolInput, offset: 1, limit: TOOL_GUARD.initialReadLines },\n additionalContext: `CodeBuddy bounded this unranged Read to lines 1-${TOOL_GUARD.initialReadLines} of ${file.lines}. Continue with an explicit offset/limit or request the full ${file.lines} lines if needed.`,\n },\n };\n return deny(file, [\n \"Read only the part you need with offset and limit (offset = first line, limit = line count).\",\n \"To find specific text, use Grep with output_mode content and -n instead of reading the file.\",\n `To read the whole file anyway, call Read again with limit: ${file.lines}.`,\n ]);\n}\n\nfunction deny(\n file: { path: string; lines: number; size: number; outline: string[] },\n advice: string[],\n): PreToolDecision {\n return {\n hookSpecificOutput: {\n hookEventName: \"PreToolUse\",\n permissionDecision: \"deny\",\n permissionDecisionReason: [\n `CodeBuddy read guard: ${file.path} is ${file.lines} lines (~${Math.ceil(file.size / 4)} tokens), too large to read whole.`,\n `Outline: ${file.outline.join(\"; \")}`,\n ...advice,\n ].join(\"\\n\"),\n },\n };\n}\n\n/** Programs that print whole files; `head`/`tail` only when asked for more lines than the guard. */\nconst WHOLE_FILE_PRINTERS = new Set([\"cat\", \"less\", \"more\", \"nl\", \"bat\", \"batcat\"]);\n/**\n * Anything that makes a command more than one plain read: pipes, lists,\n * redirection, substitution, globbing over many files. Such commands are never\n * touched, so builds, tests, pipelines and scripts behave exactly as before.\n */\nconst SHELL_SYNTAX = /[|;&<>`$(){}*?[\\]\\n\\\\]/;\n\n/**\n * Bash that would print a large file whole (`cat src/big.ts`, `head -n 5000 x`).\n * Claude reads files through Bash to get around the Read guard; the output then\n * stays in context for the rest of the session. Only a single plain read\n * command of a file over the Read guard's size is denied, with the same outline\n * and how to read a range; every other command passes untouched.\n */\nasync function guardBash(\n root: string,\n toolInput: Record<string, unknown>,\n): Promise<PreToolDecision> {\n const command = typeof toolInput.command === \"string\" ? toolInput.command.trim() : \"\";\n if (!command || SHELL_SYNTAX.test(command)) return null;\n const tokens = (command.match(/\"[^\"]*\"|'[^']*'|\\S+/g) ?? []).map((token) =>\n token.replace(/^([\"'])(.*)\\1$/, \"$2\"),\n );\n // Leading `VAR=value` assignments do not change what runs.\n while (tokens[0] && /^[A-Za-z_][A-Za-z0-9_]*=/.test(tokens[0])) tokens.shift();\n const program = (tokens.shift() ?? \"\").split(\"/\").at(-1) ?? \"\";\n const files: string[] = [];\n if (WHOLE_FILE_PRINTERS.has(program)) {\n for (const token of tokens) if (!token.startsWith(\"-\")) files.push(token);\n } else if (program === \"head\" || program === \"tail\") {\n let lines = 10;\n for (let index = 0; index < tokens.length; index += 1) {\n const token = tokens[index] ?? \"\";\n const count = /^-n$|^--lines$/.test(token)\n ? tokens[++index]\n : (token.match(/^(?:-n|--lines=)\\+?(\\d+)$/)?.[1] ?? token.match(/^-(\\d+)$/)?.[1]);\n if (count !== undefined && /^\\+?\\d+$/.test(count)) lines = Number(count.replace(\"+\", \"\"));\n else if (token === \"-f\" || token === \"-F\" || token === \"--follow\") return null;\n else if (!token.startsWith(\"-\")) files.push(token);\n }\n if (lines <= TOOL_GUARD.readLines) return null;\n } else {\n return null;\n }\n for (const filePath of files) {\n const file = await largeFile(root, filePath);\n if (file) {\n return deny(file, [\n \"Read only the part you need with the Read tool (offset = first line, limit = line count) or `sed -n 'START,ENDp' FILE`.\",\n \"To find specific text, use Grep with output_mode content and -n instead of printing the file.\",\n `To read the whole file anyway, use Read with limit: ${file.lines}.`,\n ]);\n }\n }\n return null;\n}\n\n/** Whole file as UTF-8 text, or null when it looks binary. */\nasync function readText(path: string): Promise<string | null> {\n const handle = await open(path, \"r\");\n try {\n const content = await handle.readFile();\n if (content.includes(0)) return null;\n return content.toString(\"utf8\");\n } finally {\n await handle.close();\n }\n}\n\nfunction outlineOf(path: string, text: string, lines: string[]): string[] {\n const cap = (entries: string[]) =>\n entries.length > TOOL_GUARD.outlineEntries\n ? [\n ...entries.slice(0, TOOL_GUARD.outlineEntries),\n `… ${entries.length - TOOL_GUARD.outlineEntries} more`,\n ]\n : entries;\n const all = supportsSymbols(path) ? extractSymbolTable(text, path) : [];\n if (all[0]?.kind === \"heading\") {\n return cap(all.map((heading) => `${heading.signature.slice(0, 80)} L${heading.startLine}`));\n }\n if (all.length > 0) {\n const table = all.filter(\n (symbol) => symbol.endLine - symbol.startLine + 1 >= TOOL_GUARD.outlineMinSymbolLines,\n );\n const topLevel = table.filter((symbol) => symbol.kind !== \"method\");\n // One big class says little on its own; then list its methods (`Class.method`).\n const symbols = topLevel.length >= TOOL_GUARD.minTopLevelEntries ? topLevel : table;\n if (symbols.length > 0) {\n // The symbol table is capped, so say where the outline stops covering the file.\n const covered = Math.max(...symbols.map((symbol) => symbol.endLine));\n return [\n ...cap(symbols.map((s) => `${s.name} L${s.startLine}-${s.endLine}`)),\n ...(covered < lines.length ? [`not outlined L${covered + 1}-${lines.length}`] : []),\n ];\n }\n }\n const blocks: string[] = [];\n for (let start = 1; start <= lines.length; start += TOOL_GUARD.blockLines) {\n blocks.push(`L${start}-${Math.min(lines.length, start + TOOL_GUARD.blockLines - 1)}`);\n }\n return cap(blocks);\n}\n","import { recordTrace } from \"../tracing/log.js\";\nimport { decidePreTool } from \"./pretool.js\";\nimport { hookRoot } from \"./root.js\";\nimport { failSoft, readHookInput, writeStdout } from \"./stdio.js\";\n\n/** `codebuddy hooks pretool`: runs on every Read/Grep, so it loads only its own module. */\nexport async function runPreToolHookCommand(): Promise<void> {\n await failSoft(async () => {\n const input = await readHookInput();\n const decision = await decidePreTool(input);\n if (!decision) return;\n await writeStdout(JSON.stringify(decision));\n const reason = decision.hookSpecificOutput.permissionDecisionReason;\n if (decision.hookSpecificOutput.permissionDecision === \"deny\" && reason) {\n // Measured, not modelled: the file the agent did not load whole, minus the\n // outline it got instead. Shown by `codebuddy dashboard`.\n const full = Number(reason.match(/\\(~(\\d+) tokens\\)/)?.[1] ?? 0);\n const outline = Math.ceil(reason.length / 4);\n await recordTrace(hookRoot(input.cwd), {\n kind: \"guard\",\n name: input.tool_name ?? \"tool\",\n ms: 0,\n ok: true,\n tokensOut: outline,\n ...(input.session_id ? { session: input.session_id } : {}),\n detail: {\n file: reason.match(/read guard: (\\S+) is/)?.[1] ?? \"\",\n avoided: Math.max(0, full - outline),\n },\n });\n }\n });\n}\n"],"mappings":";;;;;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