@ngockhoale/ukit 3.5.2 → 3.5.4
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/CHANGELOG.md +38 -90
- package/README.md +1 -0
- package/manifests/documentation.yaml +12 -1
- package/manifests/platform.full.yaml +12 -0
- package/package.json +34 -1
- package/src/cli/commands/doctor.js +55 -2
- package/src/cli/commands/indexTools.js +10 -4
- package/src/cli/commands/memory.js +107 -8
- package/src/core/memory/episodes.js +106 -7
- package/src/core/memory/memoryCheck.js +241 -0
- package/src/core/memory/memoryCheckRun.js +27 -0
- package/src/core/memory/memoryHit.js +2 -0
- package/src/core/memory/mutateMemory.js +46 -1
- package/src/core/memory/observations.js +192 -0
- package/src/core/memory/projectIdentity.js +9 -2
- package/src/core/memory/recallEngine.js +204 -9
- package/src/core/memory/records.js +23 -0
- package/src/core/memory/registryPrune.js +230 -0
- package/src/core/memory/retrieval.js +12 -3
- package/src/core/memory/writeGate.js +137 -0
- package/src/core/runtimeConfig.js +12 -2
- package/src/index/buildIndex.js +26 -0
- package/src/index/paths.js +3 -1
- package/src/index/queryIndex.js +372 -26
- package/src/index/resolveContext.js +1 -1
- package/template_project/.claude/hooks/edit-hint.mjs +64 -17
- package/template_project/.claude/hooks/session-episode-start.mjs +35 -0
- package/template_project/.claude/hooks/session-episode.sh +9 -4
- package/template_project/.claude/settings.json +2 -2
- package/template_project/.claude/ukit/index/edit-graph.mjs +141 -11
- package/template_project/.claude/ukit/index/lib/index-core.mjs +400 -27
- package/template_project/.claude/ukit/index/query-index.mjs +14 -3
- package/template_project/.claude/ukit/index/resolve-context.mjs +1 -1
- package/template_project/.claude/ukit/index/route-task.mjs +8 -2
- package/template_project/.claude/ukit/runtime/memory-check.mjs +241 -0
- package/template_project/.claude/ukit/runtime/memory-lanes.mjs +44 -22
- package/template_project/.claude/ukit/runtime/memory-recall.mjs +204 -9
- package/template_project/.claude/ukit/runtime/memory-validity.mjs +259 -0
- package/template_project/.claude/ukit/runtime/reinject-context.mjs +4 -2
- package/template_project/.claude/ukit/runtime/self-improve-trigger.mjs +212 -5
- package/template_project/.omp/hooks/pre/ukit-bridge.js +2 -1
- package/template_project/ukit/storage/config.json +4 -2
- package/src/core/agentRuntime/completionGate.js +0 -179
- package/src/core/agentRuntime/context.js +0 -571
- package/src/core/agentRuntime/qualityComparison.js +0 -112
- package/src/core/agentRuntime/resourcePolicy.js +0 -78
- package/src/core/agentRuntime/runtimeSupport.js +0 -255
- package/src/core/codeintel/manifest.js +0 -176
- package/src/core/experiments/deliberation.js +0 -327
- package/src/core/experiments/dynamicWorkflow.js +0 -507
- package/src/core/handoffDocValidator.js +0 -154
- package/src/core/memory/deltaOverlays.js +0 -493
- package/src/core/memory/learningCandidates.js +0 -347
- package/src/core/observability/emit/sessionBoot.js +0 -407
- package/src/core/observability/evaluation/experimentPlan.js +0 -95
- package/src/core/observability/evaluation/perturbation.js +0 -273
- package/src/core/observability/evaluation/replay.js +0 -149
- package/src/core/observability/evaluation/scorecard.js +0 -465
- package/src/core/observability/schema/compatibility.js +0 -180
- package/src/core/observability/support/renderer.js +0 -130
- package/src/core/reviewPanelAggregate.js +0 -204
- package/src/core/taskBudgetValidator.js +0 -251
- package/src/core/taskProgressGuard.js +0 -227
- package/src/decision/reviewVerdict.js +0 -339
- package/src/decision/runtimeFilter.js +0 -150
- package/src/decision/runtimeScheduler.js +0 -239
- package/src/diagnostics/classifyHang.js +0 -246
- package/src/diagnostics/ompStallSnapshot.js +0 -199
- package/src/index/contextPack.js +0 -285
- package/src/index/impactContext.js +0 -360
- package/src/index/reviewPolicy.js +0 -368
- package/src/index/sensitivePath.js +0 -21
- package/src/render/instructionRenderer.js +0 -290
- package/src/skill/auditSkill.js +0 -140
- package/template_project/instructions/overlays/repo.md +0 -9
|
@@ -23,7 +23,12 @@ import fsp from 'node:fs/promises';
|
|
|
23
23
|
import path from 'node:path';
|
|
24
24
|
|
|
25
25
|
export const RECALL_ENGINE_VERSION = 'bm25-1';
|
|
26
|
-
|
|
26
|
+
// Capped core + every detail file of docs/memory/ (3.5.4). An entry ending in
|
|
27
|
+
// `/*.md` names one directory level, expanded by expandMemorySources; a missing
|
|
28
|
+
// file or directory contributes nothing.
|
|
29
|
+
export const DEFAULT_MEMORY_SOURCES = Object.freeze(['docs/MEMORY.md', 'docs/memory/*.md']);
|
|
30
|
+
const DIR_GLOB_RE = /^[^*?[\]{}]+\/\*\.md$/;
|
|
31
|
+
const MAX_DIR_FILES = 32;
|
|
27
32
|
|
|
28
33
|
const K1 = 1.2;
|
|
29
34
|
const B = 0.75;
|
|
@@ -37,6 +42,8 @@ const isCuratedDoc = (doc) => doc?.type !== 'markdown' && !isTemplateText(doc);
|
|
|
37
42
|
// ... and the IDF mass of the matched tokens reaches this fraction of the
|
|
38
43
|
// largest IDF the corpus can produce (a token present in exactly one doc).
|
|
39
44
|
const MIN_IDF_MASS_RATIO = 0.5;
|
|
45
|
+
// Episodes only: matched IDF mass must reach this fraction of the whole query's.
|
|
46
|
+
const EPISODE_MIN_COVERAGE = 0.5;
|
|
40
47
|
// Results scoring below this fraction of the best hit are noise tail.
|
|
41
48
|
const RELATIVE_CUTOFF = 0.35;
|
|
42
49
|
// Query-dependent type prior: multiplies the lexical score, so it can only
|
|
@@ -46,6 +53,37 @@ const RELATIVE_CUTOFF = 0.35;
|
|
|
46
53
|
const TYPE_PRIOR = Object.freeze({
|
|
47
54
|
project_rule: 1.2, procedure: 1.1, derived_fact: 1.1, markdown: 1.1,
|
|
48
55
|
});
|
|
56
|
+
// Core/detail twins (3.5.4): a capped-core one-liner ends in "Detail: <file>" and
|
|
57
|
+
// its verbatim note sits in that file. Both score on the same words, so one fact
|
|
58
|
+
// would spend two result slots. collapseTwins keeps one of each pair that is
|
|
59
|
+
// present in the same ranked list: `keep` 'detail' (default: the full note) or 'core'.
|
|
60
|
+
const DETAIL_POINTER_RE = /\bDetail:\s+(\S+?\.md)\b/;
|
|
61
|
+
const TWIN_MIN_OVERLAP = 0.5;
|
|
62
|
+
export function collapseTwins(entries, keep = 'detail') {
|
|
63
|
+
if (keep === 'off' || !Array.isArray(entries) || entries.length < 2) return entries;
|
|
64
|
+
const drop = new Set();
|
|
65
|
+
for (const core of entries) {
|
|
66
|
+
const doc = core.doc;
|
|
67
|
+
if (doc?.type !== 'markdown' || drop.has(core)) continue;
|
|
68
|
+
const m = DETAIL_POINTER_RE.exec(doc.text ?? '');
|
|
69
|
+
if (!m) continue;
|
|
70
|
+
const coreTokens = new Set(tokenize(doc.text));
|
|
71
|
+
if (coreTokens.size === 0) continue;
|
|
72
|
+
let best = null;
|
|
73
|
+
let bestOverlap = 0;
|
|
74
|
+
for (const other of entries) {
|
|
75
|
+
if (other === core || drop.has(other) || other.doc?.type !== 'markdown') continue;
|
|
76
|
+
if (!String(other.doc.provenance ?? '').startsWith(`${m[1]}:`)) continue;
|
|
77
|
+
const otherTokens = new Set(tokenize(other.doc.text));
|
|
78
|
+
let shared = 0;
|
|
79
|
+
for (const t of coreTokens) if (otherTokens.has(t)) shared += 1;
|
|
80
|
+
const overlap = shared / coreTokens.size;
|
|
81
|
+
if (overlap > bestOverlap) { bestOverlap = overlap; best = other; }
|
|
82
|
+
}
|
|
83
|
+
if (best && bestOverlap >= TWIN_MIN_OVERLAP) drop.add(keep === 'core' ? best : core);
|
|
84
|
+
}
|
|
85
|
+
return drop.size === 0 ? entries : entries.filter((e) => !drop.has(e));
|
|
86
|
+
}
|
|
49
87
|
const MAX_SOURCES = 8;
|
|
50
88
|
const MAX_SOURCE_BYTES = 512 * 1024;
|
|
51
89
|
const MIN_BULLET_CHARS = 12;
|
|
@@ -161,6 +199,69 @@ export function docTokens(doc) {
|
|
|
161
199
|
return tokenize(text.replace(EPISODE_LABEL_RE, ' '));
|
|
162
200
|
}
|
|
163
201
|
|
|
202
|
+
// Source-validity marker shown next to an item whose anchored file changed or
|
|
203
|
+
// vanished (set on docs as `validity` by memory-validity.mjs).
|
|
204
|
+
export const STALE_MARKER = '[source changed since noted — verify]';
|
|
205
|
+
export const RRF_K = 60;
|
|
206
|
+
export const validityRank = (doc) => (doc?.validity === 'missing' ? 2 : doc?.validity === 'changed' ? 1 : 0);
|
|
207
|
+
const bareId = (id) => String(id ?? '').replace(/^record:/, '');
|
|
208
|
+
|
|
209
|
+
// A doc is superseded when it says so (`superseded_by`) or another candidate
|
|
210
|
+
// lists it in `supersedes`: the superseding doc wins even if the old text
|
|
211
|
+
// scores higher, so the old one never reaches the ranking.
|
|
212
|
+
export function dropSuperseded(docs) {
|
|
213
|
+
const replaced = new Set();
|
|
214
|
+
for (const doc of docs) {
|
|
215
|
+
if (!doc || !Array.isArray(doc.supersedes)) continue;
|
|
216
|
+
for (const id of doc.supersedes) replaced.add(bareId(id));
|
|
217
|
+
}
|
|
218
|
+
return docs.filter((doc) => doc != null && !doc.superseded_by && !replaced.has(bareId(doc.id)));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Reciprocal rank fusion over ordered id lists (best first); lists are lanes.
|
|
222
|
+
// Score = sum weight/(k + rank). Ties break on id, never on a timestamp.
|
|
223
|
+
export function fuseRanked(lanes, { k = RRF_K, weights = [] } = {}) {
|
|
224
|
+
const scores = new Map();
|
|
225
|
+
(Array.isArray(lanes) ? lanes : []).forEach((lane, idx) => {
|
|
226
|
+
const weight = Number.isFinite(weights[idx]) ? weights[idx] : 1;
|
|
227
|
+
const seen = new Set();
|
|
228
|
+
let rank = 0;
|
|
229
|
+
for (const id of lane ?? []) {
|
|
230
|
+
if (seen.has(id)) continue;
|
|
231
|
+
seen.add(id);
|
|
232
|
+
rank += 1;
|
|
233
|
+
scores.set(id, (scores.get(id) ?? 0) + weight / (k + rank));
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
return [...scores].map(([id, score]) => ({ id, score }))
|
|
237
|
+
.sort((a, b) => b.score - a.score || String(a.id).localeCompare(String(b.id)));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Validity as one more fusion lane (3.5.3). `changed` (an anchored source was
|
|
241
|
+
// edited) is always labelled but only mildly demoted: lane 1 is the incoming
|
|
242
|
+
// relevance order, lane 2 the same items valid-first, fused with a small weight,
|
|
243
|
+
// so a clearly more relevant changed note still beats a weakly relevant valid
|
|
244
|
+
// one. `missing` (file gone) is labelled and ranked last. Nothing is dropped.
|
|
245
|
+
// Measurement knob UKIT_MEMORY_VALIDITY_RANK: `hard` (every changed below every
|
|
246
|
+
// valid), `label` (marker only, no rank change), `mild[:<weight>]` (default).
|
|
247
|
+
export const VALIDITY_WEIGHT = 0.35;
|
|
248
|
+
const pad = (i) => String(i).padStart(6, '0');
|
|
249
|
+
export function demoteByValidity(items, docOf = (item) => item?.doc ?? item) {
|
|
250
|
+
const list = Array.isArray(items) ? [...items] : [];
|
|
251
|
+
if (!list.some((item) => validityRank(docOf(item)) > 0)) return list;
|
|
252
|
+
const [mode, raw] = String(process.env.UKIT_MEMORY_VALIDITY_RANK ?? 'mild').split(':');
|
|
253
|
+
if (mode === 'label') return list;
|
|
254
|
+
const rank = (item) => validityRank(docOf(item));
|
|
255
|
+
if (mode === 'hard') return list.sort((a, b) => rank(a) - rank(b));
|
|
256
|
+
const weight = Number.isFinite(Number(raw)) && raw !== undefined && raw !== '' ? Number(raw) : VALIDITY_WEIGHT;
|
|
257
|
+
const byIndex = list.map((item, i) => ({ item, i }));
|
|
258
|
+
const lane1 = byIndex.map((e) => pad(e.i));
|
|
259
|
+
const lane2 = [...byIndex].sort((a, b) => rank(a.item) - rank(b.item)).map((e) => pad(e.i));
|
|
260
|
+
return fuseRanked([lane1, lane2], { weights: [1, weight] })
|
|
261
|
+
.map((e) => list[Number(e.id)])
|
|
262
|
+
.sort((a, b) => Number(rank(a) === 2) - Number(rank(b) === 2));
|
|
263
|
+
}
|
|
264
|
+
|
|
164
265
|
function idf(totalDocs, docFreq) {
|
|
165
266
|
return Math.log(1 + (totalDocs - docFreq + 0.5) / (docFreq + 0.5));
|
|
166
267
|
}
|
|
@@ -170,12 +271,14 @@ function idf(totalDocs, docFreq) {
|
|
|
170
271
|
// abstained }
|
|
171
272
|
// `docs` is the ELIGIBLE set (IDF is computed over exactly this set);
|
|
172
273
|
// `query` is a string or a pre-tokenized array. Never throws.
|
|
173
|
-
export function rankDocs(docs, query, { limit = 10 } = {}) {
|
|
274
|
+
export function rankDocs(docs, query, { limit = 10, twins = 'detail' } = {}) {
|
|
174
275
|
const queryTokens = [...new Set(Array.isArray(query) ? query : tokenize(query))];
|
|
175
276
|
const empty = {
|
|
176
277
|
ranked: [], candidateCount: 0, queryTokenCount: queryTokens.length, topScore: 0, abstained: true,
|
|
177
278
|
};
|
|
178
279
|
if (!Array.isArray(docs) || docs.length === 0 || queryTokens.length === 0) return empty;
|
|
280
|
+
docs = dropSuperseded(docs);
|
|
281
|
+
if (docs.length === 0) return empty;
|
|
179
282
|
|
|
180
283
|
const stats = [];
|
|
181
284
|
const docFreq = new Map();
|
|
@@ -196,6 +299,8 @@ export function rankDocs(docs, query, { limit = 10 } = {}) {
|
|
|
196
299
|
// IDF cannot discriminate in a tiny corpus, so the multi-token requirement
|
|
197
300
|
// only applies once there are enough documents for it to mean something.
|
|
198
301
|
const wantMatched = total < SMALL_CORPUS_DOCS ? 1 : Math.min(MIN_MATCHED_TOKENS, queryTokens.length);
|
|
302
|
+
let queryMass = 0;
|
|
303
|
+
for (const token of queryTokens) queryMass += idf(total, docFreq.get(token) ?? 0);
|
|
199
304
|
|
|
200
305
|
const scored = [];
|
|
201
306
|
let candidateCount = 0;
|
|
@@ -215,6 +320,10 @@ export function rankDocs(docs, query, { limit = 10 } = {}) {
|
|
|
215
320
|
candidateCount += 1;
|
|
216
321
|
if (total >= SMALL_CORPUS_DOCS && idfMass < MIN_IDF_MASS_RATIO * idfMax) continue;
|
|
217
322
|
if (total >= SMALL_CORPUS_DOCS && matched < wantMatched && !isCuratedDoc(doc)) continue;
|
|
323
|
+
// An episode is a long raw prompt: it holds many common words, so two of them
|
|
324
|
+
// clear the absolute floor above while the query's real subject is absent.
|
|
325
|
+
// It must also cover a fraction of the query's own IDF mass.
|
|
326
|
+
if (total >= SMALL_CORPUS_DOCS && doc?.type === 'episode' && idfMass < EPISODE_MIN_COVERAGE * queryMass) continue;
|
|
218
327
|
scored.push({ doc, score: score * (TYPE_PRIOR[doc.type] ?? 1), matched });
|
|
219
328
|
}
|
|
220
329
|
// Ties break on the stable logical id, never on a timestamp (CTX-01): a re-saved
|
|
@@ -222,7 +331,12 @@ export function rankDocs(docs, query, { limit = 10 } = {}) {
|
|
|
222
331
|
scored.sort((a, b) => b.score - a.score
|
|
223
332
|
|| String(a.doc.id ?? '').localeCompare(String(b.doc.id ?? '')));
|
|
224
333
|
const top = scored.length > 0 ? scored[0].score : 0;
|
|
225
|
-
|
|
334
|
+
// Temporal lane (3.5.3): validity is one more fusion lane over the docs that
|
|
335
|
+
// cleared the floor and cutoff (see demoteByValidity); nothing is dropped.
|
|
336
|
+
const ranked = collapseTwins(
|
|
337
|
+
demoteByValidity(scored.filter((entry) => entry.score >= RELATIVE_CUTOFF * top), (entry) => entry.doc),
|
|
338
|
+
twins,
|
|
339
|
+
).slice(0, limit);
|
|
226
340
|
return {
|
|
227
341
|
ranked,
|
|
228
342
|
candidateCount,
|
|
@@ -244,6 +358,7 @@ export function normalizeMemorySources(config) {
|
|
|
244
358
|
const rel = entry.trim().replace(/\\/g, '/');
|
|
245
359
|
if (!rel || path.isAbsolute(rel) || rel.split('/').includes('..')) continue;
|
|
246
360
|
if (!/\.md$/i.test(rel) || seen.has(rel)) continue;
|
|
361
|
+
if (rel.includes('*') && !DIR_GLOB_RE.test(rel)) continue;
|
|
247
362
|
seen.add(rel);
|
|
248
363
|
out.push(rel);
|
|
249
364
|
if (out.length >= MAX_SOURCES) break;
|
|
@@ -251,6 +366,44 @@ export function normalizeMemorySources(config) {
|
|
|
251
366
|
return out;
|
|
252
367
|
}
|
|
253
368
|
|
|
369
|
+
// matchesMemorySource(sources, rel) -> boolean. Sync, no I/O: is `rel` one of the
|
|
370
|
+
// (possibly `dir/*.md`) entries? Lets a hook skip the directory listing for edits
|
|
371
|
+
// that are nowhere near a memory source.
|
|
372
|
+
export function matchesMemorySource(sources, rel) {
|
|
373
|
+
for (const entry of sources) {
|
|
374
|
+
if (entry === rel) return true;
|
|
375
|
+
if (entry.endsWith('/*.md') && DIR_GLOB_RE.test(entry)) {
|
|
376
|
+
const dir = entry.slice(0, -4);
|
|
377
|
+
if (rel.startsWith(dir) && !rel.slice(dir.length).includes('/') && /\.md$/i.test(rel)) return true;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// expandMemorySources(projectRoot, sources) -> concrete rel .md paths. `dir/*.md`
|
|
384
|
+
// lists that one directory level (async, sorted, at most MAX_DIR_FILES, dot-files
|
|
385
|
+
// skipped); a missing directory yields nothing. Explicit entries keep their order.
|
|
386
|
+
export async function expandMemorySources(projectRoot, sources) {
|
|
387
|
+
const out = [];
|
|
388
|
+
const seen = new Set();
|
|
389
|
+
const push = (rel) => { if (!seen.has(rel)) { seen.add(rel); out.push(rel); } };
|
|
390
|
+
for (const entry of sources) {
|
|
391
|
+
if (!entry.includes('*')) { push(entry); continue; }
|
|
392
|
+
if (!DIR_GLOB_RE.test(entry)) continue;
|
|
393
|
+
const dir = entry.slice(0, -4);
|
|
394
|
+
let names = [];
|
|
395
|
+
try {
|
|
396
|
+
const items = await fsp.readdir(path.resolve(projectRoot, dir), { withFileTypes: true });
|
|
397
|
+
names = items.filter((d) => (d.isFile() || d.isSymbolicLink()) && /\.md$/i.test(d.name) && !d.name.startsWith('.')).map((d) => d.name);
|
|
398
|
+
} catch {
|
|
399
|
+
names = [];
|
|
400
|
+
}
|
|
401
|
+
names.sort();
|
|
402
|
+
for (const name of names.slice(0, MAX_DIR_FILES)) push(`${dir}${name}`);
|
|
403
|
+
}
|
|
404
|
+
return out;
|
|
405
|
+
}
|
|
406
|
+
|
|
254
407
|
function cleanMarkdown(text) {
|
|
255
408
|
return text.replace(/<!--[\s\S]*?-->/g, ' ').replace(/\*\*|__/g, '').replace(/`/g, '').replace(/\s+/g, ' ').trim();
|
|
256
409
|
}
|
|
@@ -260,6 +413,22 @@ function cleanMarkdown(text) {
|
|
|
260
413
|
// indexing it too would return the same rule twice (record + bullet).
|
|
261
414
|
const LEARNED_START_RE = /^\s*<!--\s*ukit-learned:start\s*-->/;
|
|
262
415
|
const LEARNED_END_RE = /^\s*<!--\s*ukit-learned:end\s*-->/;
|
|
416
|
+
const MD_ID_TAG_RE = /\[id:\s*([a-z0-9][a-z0-9._-]*)\s*\]/gi;
|
|
417
|
+
const MD_SUPERSEDES_TAG_RE = /\[supersedes:\s*([a-z0-9][a-z0-9._,\s-]*)\]/gi;
|
|
418
|
+
|
|
419
|
+
// Resolve slug tags to doc ids across every loaded source: the replacing doc
|
|
420
|
+
// gets `supersedes: [md:<rel>:<line>]` so dropSuperseded() removes the old one.
|
|
421
|
+
// Returns copies only for docs that carry tags; cached docs are never mutated.
|
|
422
|
+
function resolveMarkdownSupersession(docs) {
|
|
423
|
+
const bySlug = new Map();
|
|
424
|
+
for (const doc of docs) if (doc.slug && !bySlug.has(doc.slug)) bySlug.set(doc.slug, doc.id);
|
|
425
|
+
if (bySlug.size === 0) return docs;
|
|
426
|
+
return docs.map((doc) => {
|
|
427
|
+
if (!doc.supersedesSlugs) return doc;
|
|
428
|
+
const ids = doc.supersedesSlugs.map((s) => bySlug.get(s)).filter((id) => id && id !== doc.id);
|
|
429
|
+
return ids.length > 0 ? { ...doc, supersedes: ids } : doc;
|
|
430
|
+
});
|
|
431
|
+
}
|
|
263
432
|
|
|
264
433
|
// Top-level bullets ("- " / "* ") with their indented continuation lines.
|
|
265
434
|
export function parseMarkdownBullets(content, relPath) {
|
|
@@ -271,9 +440,21 @@ export function parseMarkdownBullets(content, relPath) {
|
|
|
271
440
|
let current = null;
|
|
272
441
|
const flush = () => {
|
|
273
442
|
if (!current) return;
|
|
274
|
-
|
|
443
|
+
// Supersession tags (3.5.4): `[id: slug]` names a bullet, `[supersedes: a, b]`
|
|
444
|
+
// says it replaces the bullets so named. Tags are stripped from the text.
|
|
445
|
+
let slug = null;
|
|
446
|
+
const replacesSlugs = [];
|
|
447
|
+
const raw = current.parts.join(' ')
|
|
448
|
+
.replace(MD_ID_TAG_RE, (_m, s) => { slug ??= s.toLowerCase(); return ' '; })
|
|
449
|
+
.replace(MD_SUPERSEDES_TAG_RE, (_m, list) => {
|
|
450
|
+
for (const s of list.split(/[\s,]+/)) if (s) replacesSlugs.push(s.toLowerCase());
|
|
451
|
+
return ' ';
|
|
452
|
+
});
|
|
453
|
+
const text = cleanMarkdown(raw);
|
|
275
454
|
if (text.length >= MIN_BULLET_CHARS) {
|
|
276
455
|
docs.push({
|
|
456
|
+
...(slug ? { slug } : {}),
|
|
457
|
+
...(replacesSlugs.length > 0 ? { supersedesSlugs: replacesSlugs } : {}),
|
|
277
458
|
id: `md:${relPath}:${current.line}`,
|
|
278
459
|
type: 'markdown',
|
|
279
460
|
source: 'markdown',
|
|
@@ -330,7 +511,7 @@ export async function loadMarkdownDocs(projectRoot, sources = DEFAULT_MEMORY_SOU
|
|
|
330
511
|
const root = path.resolve(projectRoot);
|
|
331
512
|
const docs = [];
|
|
332
513
|
let realRoot = null;
|
|
333
|
-
for (const rel of sources) {
|
|
514
|
+
for (const rel of await expandMemorySources(root, sources)) {
|
|
334
515
|
const abs = path.resolve(root, rel);
|
|
335
516
|
if (abs !== root && !abs.startsWith(root + path.sep)) continue;
|
|
336
517
|
try {
|
|
@@ -352,23 +533,37 @@ export async function loadMarkdownDocs(projectRoot, sources = DEFAULT_MEMORY_SOU
|
|
|
352
533
|
markdownCache.delete(abs);
|
|
353
534
|
}
|
|
354
535
|
}
|
|
355
|
-
return docs;
|
|
536
|
+
return resolveMarkdownSupersession(docs);
|
|
356
537
|
}
|
|
357
538
|
|
|
358
539
|
const SNIPPET_CHARS = 160;
|
|
359
540
|
|
|
360
541
|
// Shared hook lane: score ALL eligible docs (no newest-N pre-filter) together
|
|
361
542
|
// with the markdown source bullets, then cut. Async I/O only; never throws.
|
|
362
|
-
|
|
543
|
+
// `annotate(docs) -> Promise<docs>` is an optional caller-injected async step
|
|
544
|
+
// (source validity, 3.5.3); this file stays free of non-node imports. A failing
|
|
545
|
+
// or slow-to-throw annotate never affects recall.
|
|
546
|
+
export async function recallForHook({
|
|
547
|
+
projectRoot, query, docs = [], config = null, limit = 2, annotate = null,
|
|
548
|
+
} = {}) {
|
|
363
549
|
let markdown = [];
|
|
364
550
|
try {
|
|
365
551
|
markdown = await loadMarkdownDocs(projectRoot, normalizeMemorySources(config));
|
|
366
552
|
} catch {
|
|
367
553
|
markdown = [];
|
|
368
554
|
}
|
|
555
|
+
let pool = [...docs, ...markdown];
|
|
556
|
+
if (typeof annotate === 'function') {
|
|
557
|
+
try {
|
|
558
|
+
const annotated = await annotate(pool);
|
|
559
|
+
if (Array.isArray(annotated) && annotated.length === pool.length) pool = annotated;
|
|
560
|
+
} catch {
|
|
561
|
+
// keep the unannotated pool
|
|
562
|
+
}
|
|
563
|
+
}
|
|
369
564
|
let result;
|
|
370
565
|
try {
|
|
371
|
-
result = rankDocs(
|
|
566
|
+
result = rankDocs(pool, query, { limit });
|
|
372
567
|
} catch {
|
|
373
568
|
result = rankDocs([], '', { limit });
|
|
374
569
|
}
|
|
@@ -419,5 +614,5 @@ async function emitRecallTelemetry(projectRoot, config, result) {
|
|
|
419
614
|
export function renderMarkdownDoc(doc, maxChars = SNIPPET_CHARS) {
|
|
420
615
|
const text = String(doc?.text ?? '');
|
|
421
616
|
const body = text.length > maxChars ? `${text.slice(0, maxChars - 3)}...` : text;
|
|
422
|
-
return `[${doc?.provenance ?? 'markdown'}] ${body}`;
|
|
617
|
+
return `[${doc?.provenance ?? 'markdown'}] ${body}${doc?.validity ? ` ${STALE_MARKER}` : ''}`;
|
|
423
618
|
}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
// memory-validity.mjs (3.5.3) - source anchors for memory items. A note that names
|
|
2
|
+
// an existing file is anchored to that file's state (sha1 + size + mtime, plus the
|
|
3
|
+
// git commit when known) in the sidecar .ukit/storage/memory/v2/anchors.json, so
|
|
4
|
+
// docs/MEMORY.md and records are never rewritten. Standalone ESM, async fs only.
|
|
5
|
+
// Reads (withValidity) are hook-safe; capture is CLI/write-time only.
|
|
6
|
+
// Env switches (read per call; unset = on):
|
|
7
|
+
// UKIT_MEMORY_VALIDITY=0 kill switch: no anchors, no marker, no rank change.
|
|
8
|
+
// UKIT_MEMORY_VALIDITY_RANK=<mode> measurement knob read by demoteByValidity in
|
|
9
|
+
// memory-recall.mjs: `mild[:<weight>]` (default), `label` (marker only), `hard`
|
|
10
|
+
// (changed below valid; measured worse, 36/38 vs 37/38). Unknown values mean mild.
|
|
11
|
+
// Not a user setting: used by scripts/bench/memory-gold-validity.mjs and tests.
|
|
12
|
+
import crypto from 'node:crypto';
|
|
13
|
+
import { execFile } from 'node:child_process';
|
|
14
|
+
import fsp from 'node:fs/promises';
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
|
|
17
|
+
import { STALE_MARKER, validityRank } from './memory-recall.mjs';
|
|
18
|
+
|
|
19
|
+
export { STALE_MARKER, validityRank };
|
|
20
|
+
const MAX_FILES = 6;
|
|
21
|
+
const MAX_HASH_BYTES = 2 * 1024 * 1024;
|
|
22
|
+
const MAX_STORE_BYTES = 1024 * 1024;
|
|
23
|
+
const MAX_ENTRIES = 2000;
|
|
24
|
+
const KNOWN_ROOTS = new Set(['src', 'tests', 'test', 'docs', 'scripts', 'lib', 'app', 'template_project', 'packages', 'bin']);
|
|
25
|
+
const EXT_RE = /\.[A-Za-z][A-Za-z0-9]{0,7}$/;
|
|
26
|
+
|
|
27
|
+
export function normalizePath(raw, { needSlash = true } = {}) {
|
|
28
|
+
let t = String(raw ?? '').trim().replace(/`/g, '').replace(/\\/g, '/');
|
|
29
|
+
t = t.replace(/^(\.\/)+/, '').replace(/:\d+(?::\d+)?$/, '').replace(/[.,;:!?)\]}>"'*]+$/, '').replace(/^[("'[{<]+/, '');
|
|
30
|
+
t = t.replace(/:\d+(?::\d+)?$/, '');
|
|
31
|
+
if (!t || t.includes('://') || t.startsWith('/') || /^[A-Za-z]:/.test(t) || t.startsWith('~')) return null;
|
|
32
|
+
const segs = t.split('/');
|
|
33
|
+
if (segs.some((s) => s === '..' || s === '')) {
|
|
34
|
+
if (!(t.endsWith('/') && segs.slice(0, -1).every((s) => s && s !== '..'))) return null;
|
|
35
|
+
segs.pop();
|
|
36
|
+
}
|
|
37
|
+
const clean = segs.join('/');
|
|
38
|
+
const last = segs[segs.length - 1];
|
|
39
|
+
if (EXT_RE.test(last) && last.length > 2) return needSlash && segs.length < 2 ? null : clean;
|
|
40
|
+
if (segs.length >= 2 && (t.endsWith('/') || KNOWN_ROOTS.has(segs[0]))) return clean;
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const isFilePath = (p) => EXT_RE.test(String(p).split('/').pop());
|
|
45
|
+
|
|
46
|
+
export function extractAnchors(doc) {
|
|
47
|
+
const out = new Set();
|
|
48
|
+
for (const tok of String(doc?.text ?? '').split(/\s+/)) {
|
|
49
|
+
const hit = /[/\\]/.test(tok) ? normalizePath(tok) : null;
|
|
50
|
+
if (hit) out.add(hit);
|
|
51
|
+
}
|
|
52
|
+
for (const ev of Array.isArray(doc?.evidence) ? doc.evidence : []) {
|
|
53
|
+
if (typeof ev === 'string') { const p = normalizePath(ev, { needSlash: false }); if (p) out.add(p); continue; }
|
|
54
|
+
if (ev?.kind && ev.kind !== 'file') continue;
|
|
55
|
+
const p = normalizePath(ev?.locator, { needSlash: false });
|
|
56
|
+
if (p) out.add(p);
|
|
57
|
+
}
|
|
58
|
+
return [...out].sort();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Episodes and exec-ledger stubs describe a session, not a claim about a file.
|
|
62
|
+
const anchorable = (doc) => doc && doc.type !== 'episode' && doc.provenance !== 'exec-ledger';
|
|
63
|
+
|
|
64
|
+
// Stable identity: records by id, markdown bullets by path + text hash (a line
|
|
65
|
+
// shift keeps the anchor; an edited bullet is a new, unanchored item).
|
|
66
|
+
export function anchorKey(doc) {
|
|
67
|
+
if (doc?.type === 'markdown') {
|
|
68
|
+
const rel = String(doc.provenance ?? '').replace(/:\d+$/, '');
|
|
69
|
+
return `md:${rel}:${crypto.createHash('sha1').update(String(doc.text ?? '')).digest('hex').slice(0, 12)}`;
|
|
70
|
+
}
|
|
71
|
+
return `rec:${String(doc?.id ?? '').replace(/^record:/, '')}`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const storePath = (root) => path.join(root, '.ukit', 'storage', 'memory', 'v2', 'anchors.json');
|
|
75
|
+
|
|
76
|
+
export async function loadAnchors(root) {
|
|
77
|
+
try {
|
|
78
|
+
const file = storePath(root);
|
|
79
|
+
const st = await fsp.stat(file);
|
|
80
|
+
if (!st.isFile() || st.size > MAX_STORE_BYTES) return { version: 1, anchors: {} };
|
|
81
|
+
const doc = JSON.parse(await fsp.readFile(file, 'utf8'));
|
|
82
|
+
return { version: 1, anchors: doc && typeof doc.anchors === 'object' && doc.anchors ? doc.anchors : {} };
|
|
83
|
+
} catch {
|
|
84
|
+
return { version: 1, anchors: {} };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function saveAnchors(root, store) {
|
|
89
|
+
const keys = Object.keys(store.anchors);
|
|
90
|
+
if (keys.length > MAX_ENTRIES) {
|
|
91
|
+
keys.sort((a, b) => (store.anchors[a].at ?? 0) - (store.anchors[b].at ?? 0));
|
|
92
|
+
for (const k of keys.slice(0, keys.length - MAX_ENTRIES)) delete store.anchors[k];
|
|
93
|
+
}
|
|
94
|
+
const file = storePath(root);
|
|
95
|
+
await fsp.mkdir(path.dirname(file), { recursive: true });
|
|
96
|
+
const tmp = `${file}.${process.pid}.${crypto.randomBytes(4).toString('hex')}.tmp`;
|
|
97
|
+
await fsp.writeFile(tmp, `${JSON.stringify(store)}\n`, 'utf8');
|
|
98
|
+
await fsp.rename(tmp, file);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function fileState(root, rel) {
|
|
102
|
+
const st = await fsp.stat(path.resolve(root, rel));
|
|
103
|
+
if (!st.isFile()) throw Object.assign(new Error('not a file'), { code: 'ENOENT' });
|
|
104
|
+
const sha1 = st.size <= MAX_HASH_BYTES
|
|
105
|
+
? crypto.createHash('sha1').update(await fsp.readFile(path.resolve(root, rel))).digest('hex') : null;
|
|
106
|
+
return { sha1, size: st.size, mtimeMs: st.mtimeMs };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function headCommit(root) {
|
|
110
|
+
return new Promise((resolve) => {
|
|
111
|
+
try {
|
|
112
|
+
execFile('git', ['rev-parse', 'HEAD'], { cwd: root, timeout: 1500 }, (err, out) => {
|
|
113
|
+
const sha = String(out ?? '').trim();
|
|
114
|
+
resolve(!err && /^[0-9a-f]{40}$/i.test(sha) ? sha.toLowerCase() : null);
|
|
115
|
+
});
|
|
116
|
+
} catch { resolve(null); }
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async function buildEntry(root, doc, commit) {
|
|
121
|
+
const files = {};
|
|
122
|
+
for (const rel of extractAnchors(doc).filter(isFilePath).slice(0, MAX_FILES)) {
|
|
123
|
+
try { files[rel] = await fileState(root, rel); } catch { /* names a path that does not exist: not anchored */ }
|
|
124
|
+
}
|
|
125
|
+
return Object.keys(files).length ? { at: Date.now(), commit: commit ?? null, files } : null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// 'valid' | 'changed' | 'missing'. A deleted file outranks a changed one.
|
|
129
|
+
// `memo` is per withValidity call: each distinct file is stat-ed / hashed once
|
|
130
|
+
// however many notes name it.
|
|
131
|
+
const memoStat = (root, rel, memo) => {
|
|
132
|
+
if (!memo.stat.has(rel)) {
|
|
133
|
+
memo.stat.set(rel, fsp.stat(path.resolve(root, rel)).then((st) => ({ st }), (err) => ({ err })));
|
|
134
|
+
}
|
|
135
|
+
return memo.stat.get(rel);
|
|
136
|
+
};
|
|
137
|
+
const memoSha1 = (root, rel, memo) => {
|
|
138
|
+
// The caller already stat-ed (and size-matched) the file: only read it here.
|
|
139
|
+
if (!memo.sha1.has(rel)) {
|
|
140
|
+
memo.sha1.set(rel, fsp.readFile(path.resolve(root, rel))
|
|
141
|
+
.then((buf) => crypto.createHash('sha1').update(buf).digest('hex'), () => undefined));
|
|
142
|
+
}
|
|
143
|
+
return memo.sha1.get(rel);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
async function evaluateEntry(root, entry, memo = { stat: new Map(), sha1: new Map() }) {
|
|
147
|
+
let changed = false;
|
|
148
|
+
for (const [rel, was] of Object.entries(entry?.files ?? {}).slice(0, MAX_FILES)) {
|
|
149
|
+
const { st, err } = await memoStat(root, rel, memo);
|
|
150
|
+
if (err) {
|
|
151
|
+
if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return 'missing';
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (!st.isFile()) return 'missing';
|
|
155
|
+
if (st.size === was.size && st.mtimeMs === was.mtimeMs) continue;
|
|
156
|
+
// A different size already proves a different content: no read, no hash.
|
|
157
|
+
if (!was.sha1 || st.size !== was.size) { changed = true; continue; }
|
|
158
|
+
const sha1 = await memoSha1(root, rel, memo);
|
|
159
|
+
if (sha1 !== undefined && sha1 !== was.sha1) changed = true; // unreadable (undefined): do not claim a change
|
|
160
|
+
}
|
|
161
|
+
return changed ? 'changed' : 'valid';
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const FILE_WORK_CONCURRENCY = 4;
|
|
165
|
+
|
|
166
|
+
async function mapLimited(items, limit, fn) {
|
|
167
|
+
const out = new Array(items.length);
|
|
168
|
+
let next = 0;
|
|
169
|
+
const worker = async () => {
|
|
170
|
+
while (next < items.length) { const i = next++; out[i] = await fn(items[i]); }
|
|
171
|
+
};
|
|
172
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
|
|
173
|
+
return out;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Observations (3.5.4) are backed by episodes (meta.evidence.episodes), not a file:
|
|
177
|
+
// labelled with the live evidence count; with every evidence episode gone they are
|
|
178
|
+
// marked validity 'missing' (STALE_MARKER, ranked last) - the same mechanism.
|
|
179
|
+
const OBS_MAX_BYTES = 8 * 1024 * 1024;
|
|
180
|
+
const readJsonSmall = async (file) => {
|
|
181
|
+
try {
|
|
182
|
+
const st = await fsp.stat(file);
|
|
183
|
+
return st.isFile() && st.size <= OBS_MAX_BYTES ? JSON.parse(await fsp.readFile(file, 'utf8')) : null;
|
|
184
|
+
} catch { return null; }
|
|
185
|
+
};
|
|
186
|
+
async function annotateObservations(root, docs) {
|
|
187
|
+
if (!docs.some((d) => d?.type === 'observation')) return docs;
|
|
188
|
+
const dir = path.join(root, '.ukit', 'storage', 'memory', 'v2');
|
|
189
|
+
const [store, archive] = await Promise.all([readJsonSmall(path.join(dir, 'records.json')), readJsonSmall(path.join(dir, 'episodes-archive.json'))]);
|
|
190
|
+
const all = [...(Array.isArray(store?.records) ? store.records : []), ...(Array.isArray(archive?.records) ? archive.records : [])];
|
|
191
|
+
const known = new Set(all.filter((r) => r?.type === 'episode').map((r) => r.id));
|
|
192
|
+
const byId = new Map(all.map((r) => [r?.id, r]));
|
|
193
|
+
return docs.map((doc) => {
|
|
194
|
+
if (doc?.type !== 'observation') return doc;
|
|
195
|
+
const rec = byId.get(String(doc.id ?? '').replace(/^record:/, ''));
|
|
196
|
+
const ids = rec?.meta?.evidence?.episodes ?? doc.meta?.evidence?.episodes;
|
|
197
|
+
const live = Array.isArray(ids) ? ids.filter((id) => known.has(id)).length : 0;
|
|
198
|
+
const label = ` (observation, seen in ${live} episode${live === 1 ? '' : 's'})`;
|
|
199
|
+
return { ...doc, text: `${doc.text ?? ''}${label}`, ...(live === 0 ? { validity: 'missing' } : {}) };
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Adds `validity: 'changed'|'missing'` to docs whose anchored source moved on;
|
|
204
|
+
// every other doc is returned untouched (same object). `capture` also anchors
|
|
205
|
+
// docs that have no anchor yet (CLI/write time only, never inside a hook).
|
|
206
|
+
export async function withValidity(root, docs, { capture = false } = {}) {
|
|
207
|
+
const list = Array.isArray(docs) ? docs : [];
|
|
208
|
+
if (!root || process.env.UKIT_MEMORY_VALIDITY === '0') return list;
|
|
209
|
+
try {
|
|
210
|
+
const store = await loadAnchors(root);
|
|
211
|
+
let dirty = false;
|
|
212
|
+
let commit;
|
|
213
|
+
const memo = { stat: new Map(), sha1: new Map() };
|
|
214
|
+
const out = await mapLimited(list, FILE_WORK_CONCURRENCY, async (doc) => {
|
|
215
|
+
if (!anchorable(doc)) return doc;
|
|
216
|
+
const key = anchorKey(doc);
|
|
217
|
+
const entry = store.anchors[key];
|
|
218
|
+
if (entry) {
|
|
219
|
+
const verdict = await evaluateEntry(root, entry, memo);
|
|
220
|
+
return verdict === 'valid' ? doc : { ...doc, validity: verdict };
|
|
221
|
+
}
|
|
222
|
+
if (capture && extractAnchors(doc).some(isFilePath)) {
|
|
223
|
+
commit ??= headCommit(root);
|
|
224
|
+
const built = await buildEntry(root, doc, await commit);
|
|
225
|
+
if (built) { store.anchors[key] = built; dirty = true; }
|
|
226
|
+
}
|
|
227
|
+
return doc;
|
|
228
|
+
});
|
|
229
|
+
if (dirty) await saveAnchors(root, store);
|
|
230
|
+
return await annotateObservations(root, out);
|
|
231
|
+
} catch {
|
|
232
|
+
return list;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Write-time / `ukit memory v2 confirm`: (re)anchor docs to the files' state now.
|
|
237
|
+
export async function captureAnchors(root, docs) {
|
|
238
|
+
try {
|
|
239
|
+
if (!root || process.env.UKIT_MEMORY_VALIDITY === '0') return 0;
|
|
240
|
+
// No git spawn / store read unless a doc actually names a file.
|
|
241
|
+
const todo = (Array.isArray(docs) ? docs : []).filter((d) => anchorable(d) && extractAnchors(d).some(isFilePath));
|
|
242
|
+
if (todo.length === 0) return 0;
|
|
243
|
+
const store = await loadAnchors(root);
|
|
244
|
+
const commit = await headCommit(root);
|
|
245
|
+
let n = 0;
|
|
246
|
+
for (const doc of todo) {
|
|
247
|
+
const built = await buildEntry(root, doc, commit);
|
|
248
|
+
if (!built) continue;
|
|
249
|
+
store.anchors[anchorKey(doc)] = built;
|
|
250
|
+
n += 1;
|
|
251
|
+
}
|
|
252
|
+
if (n) await saveAnchors(root, store);
|
|
253
|
+
return n;
|
|
254
|
+
} catch {
|
|
255
|
+
return 0;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export const staleSuffix = (doc) => (doc?.validity ? ` ${STALE_MARKER}` : '');
|
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
import { resolveRecordFreshness } from './memory-freshness.mjs';
|
|
32
32
|
import { resolveMemoryStage } from './memory-flags.mjs';
|
|
33
33
|
import { recallForHook, renderMarkdownDoc } from './memory-recall.mjs';
|
|
34
|
-
|
|
34
|
+
import { withValidity, staleSuffix } from './memory-validity.mjs';
|
|
35
35
|
// Hook-context self-deadline (2.4.1 orphan-leak class): the reinject-context hook passes
|
|
36
36
|
// UKIT_HOOK_DEADLINE_MS so a wedged read can never orphan this process past the hook
|
|
37
37
|
// budget. Non-hook usage never sets it and is never self-killed.
|
|
@@ -1253,7 +1253,9 @@ async function buildPreviousContextLines(projectRoot, state, config) {
|
|
|
1253
1253
|
});
|
|
1254
1254
|
const recalled = await recallForHook({
|
|
1255
1255
|
projectRoot, query: taskQuery, docs, config, limit: 2,
|
|
1256
|
+
annotate: (pool) => withValidity(projectRoot, pool),
|
|
1256
1257
|
});
|
|
1258
|
+
const validityById = new Map(recalled.ranked.map((entry) => [entry.doc.id, entry.doc]));
|
|
1257
1259
|
const rankedItems = recalled.ranked.map((entry) => (entry.doc.type === 'markdown'
|
|
1258
1260
|
? { id: entry.doc.id, type: 'markdown', doc: entry.doc }
|
|
1259
1261
|
: itemById.get(entry.doc.id))).filter(Boolean);
|
|
@@ -1273,7 +1275,7 @@ async function buildPreviousContextLines(projectRoot, state, config) {
|
|
|
1273
1275
|
|
|
1274
1276
|
return [`- Previous context: ${rankedItems.map((item) => (item.type === 'markdown'
|
|
1275
1277
|
? renderMarkdownDoc(item.doc, 120)
|
|
1276
|
-
: buildPreviousContextSnippet(item, freshnessById.get(item.id)))).join(' | ')}`];
|
|
1278
|
+
: `${buildPreviousContextSnippet(item, freshnessById.get(item.id))}${staleSuffix(validityById.get(item.id))}`)).join(' | ')}`];
|
|
1277
1279
|
}
|
|
1278
1280
|
|
|
1279
1281
|
// BUG-C23-13: only run main() on direct CLI invocation — an unguarded bottom
|