MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / loadChangeSet

Function loadChangeSet

graph-ui/src/impact/change-set.ts:28–76  ·  view source on GitHub ↗
(project: string, base: string, signal?: AbortSignal,
    read: ChangeSetRequest = request)

Source from the content-addressed store, hash-verified

26
27/** Read file pages separately from graph impact so one cannot consume the other's budget. */
28export async function loadChangeSet(project: string, base: string, signal?: AbortSignal,
29 read: ChangeSetRequest = request): Promise<ChangeSetReading> {
30 if (!project || !validChangeRef(base)) throw new Error('Choose a project and a valid local Git revision.');
31 const files = new Set<string>();
32 let cursor: string | undefined;
33 const cursors = new Set<string>();
34 let mergeBase = '', total = -1, complete = false, pages = 0;
35 let budget = 12000;
36 const limitations: string[] = [];
37 while (pages < 8 && files.size < 4000) {
38 const payload = object(await read({ project, since: base, scope: 'files', direction: 'inbound',
39 changed_limit: 500, limit: 1, module_limit: 0, max_output_tokens: budget, format: 'json',
40 ...(cursor ? { changed_cursor: cursor } : {}) }, signal));
41 if (signal?.aborted) throw signal.reason;
42 if (payload.base !== base || typeof payload.merge_base !== 'string' || !Array.isArray(payload.changed_files)
43 || !Number.isSafeInteger(payload.changed_total) || Number(payload.changed_total) < 0
44 || typeof payload.changed_has_more !== 'boolean') {
45 throw new Error('The daemon returned an incomplete change-set response. No empty or safe result was inferred.');
46 }
47 if (total >= 0 && (total !== payload.changed_total || mergeBase !== payload.merge_base)) {
48 throw new Error('The Git change set moved while its pages were loading. Refresh to read one snapshot.');
49 }
50 total = Number(payload.changed_total); mergeBase = payload.merge_base;
51 const entries = payload.changed_files;
52 if (entries.some(file => typeof file !== 'string' || !file || file.startsWith('/') || file.split('/').includes('..'))) {
53 throw new Error('The daemon returned an invalid repository-relative changed path.');
54 }
55 if (entries.length === 0 && payload.changed_has_more && payload.changed_continuation_requires_higher_budget && budget < 24000) {
56 budget = 24000; continue;
57 }
58 pages += 1;
59 const previousSize = files.size;
60 for (const file of entries as string[]) files.add(file);
61 if (!payload.changed_has_more) {
62 complete = files.size === total;
63 if (!complete) limitations.push('The returned file pages do not account for the reported total.');
64 break;
65 }
66 const next = payload.changed_next_cursor;
67 if (typeof next !== 'string' || !next || cursors.has(next) || files.size === previousSize) {
68 limitations.push('The daemon could not provide a progressing snapshot cursor for the remaining changed files.');
69 break;
70 }
71 cursors.add(next); cursor = next;
72 }
73 if (!complete && limitations.length === 0) limitations.push('Changed-file reading reached its limit of 8 pages / 4,000 paths.');
74 return { project, base, mergeBase, checkedAt: new Date().toISOString(), files: [...files], totalFiles: total,
75 complete, pages, limitations };
76}
77
78export interface ChangedArea { path: string; files: string[] }
79/** Navigation groups from recorded paths; change volume is not a risk score. */

Callers 1

change-set.test.tsFile · 0.90

Calls 4

validChangeRefFunction · 0.85
objectFunction · 0.70
readFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected