@aabadin/project-memory-context 0.2.4 → 0.2.5

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.
Files changed (2) hide show
  1. package/cli/context.mjs +38 -9
  2. package/package.json +1 -1
package/cli/context.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { access } from 'node:fs/promises';
2
+ import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
3
3
  import { dirname, join, resolve } from 'node:path';
4
4
  import { fileURLToPath } from 'node:url';
5
5
 
@@ -22,7 +22,7 @@ export async function findProjectRoot(startDir = process.cwd()) {
22
22
 
23
23
  while (true) {
24
24
  const installPath = join(currentDir, '.planning', 'project-memory-context', 'install.json');
25
- if (await fileExists(installPath)) {
25
+ if (existsSync(installPath)) {
26
26
  return currentDir;
27
27
  }
28
28
 
@@ -35,6 +35,23 @@ export async function findProjectRoot(startDir = process.cwd()) {
35
35
  }
36
36
  }
37
37
 
38
+ async function markContext(projectRoot, nodeIds) {
39
+ if (!nodeIds || nodeIds.length === 0) return;
40
+ const trackerPath = join(projectRoot, '.planning', 'project-memory-context', 'context-tracker.json');
41
+ let tracker = { activeNodeIds: [] };
42
+ try {
43
+ if (existsSync(trackerPath)) {
44
+ tracker = JSON.parse(readFileSync(trackerPath, 'utf-8'));
45
+ }
46
+ } catch {}
47
+ const existing = new Set(tracker.activeNodeIds || []);
48
+ nodeIds.forEach((id) => existing.add(id));
49
+ tracker.activeNodeIds = [...existing];
50
+ const dir = dirname(trackerPath);
51
+ if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
52
+ writeFileSync(trackerPath, JSON.stringify(tracker, null, 2));
53
+ }
54
+
38
55
  export function parseArgs(args) {
39
56
  const DEPTH_VALUES = ['compact', 'extended', 'deep', 'disk'];
40
57
  const FOCUS_VALUES = ['dependencies', 'callers', 'containment', 'impact', 'all'];
@@ -190,12 +207,12 @@ export function buildRenderInput(engine, resolved, { depth, focus }) {
190
207
  };
191
208
  }
192
209
 
193
- export async function runTargetContext({ projectRoot, target, explicitMode, depth, focus }) {
194
- const artifacts = await loadArtifacts(projectRoot);
210
+ export async function runTargetContext({ projectRoot, target, explicitMode, depth, focus, artifacts }) {
211
+ const artfs = artifacts ?? await loadArtifacts(projectRoot);
195
212
  const engine = createQueryEngine({
196
- graph: artifacts.graph,
197
- symbolIndex: artifacts.symbolIndex,
198
- worklist: artifacts.worklist,
213
+ graph: artfs.graph,
214
+ symbolIndex: artfs.symbolIndex,
215
+ worklist: artfs.worklist,
199
216
  enrichmentDir: join(projectRoot, '.planning', 'project-memory-context', 'enrichment'),
200
217
  projectSlug: 'project',
201
218
  });
@@ -205,7 +222,7 @@ export async function runTargetContext({ projectRoot, target, explicitMode, dept
205
222
  const input = buildRenderInput(engine, resolved, { depth, focus });
206
223
  const output = renderTargetContext(input);
207
224
 
208
- return { output, resolved, input };
225
+ return { output, resolved, input, artifacts: artfs };
209
226
  }
210
227
 
211
228
  export async function runProjectContext(projectRoot = process.cwd(), refresh = false) {
@@ -301,7 +318,8 @@ export async function main(args = process.argv.slice(2)) {
301
318
  return 1;
302
319
  }
303
320
 
304
- const { output } = await runTargetContext({
321
+ const artifacts = await loadArtifacts(projectRoot);
322
+ const { output, resolved } = await runTargetContext({
305
323
  projectRoot,
306
324
  target: parsed.target,
307
325
  explicitMode: parsed.explicitMode,
@@ -309,6 +327,17 @@ export async function main(args = process.argv.slice(2)) {
309
327
  focus: parsed.focus,
310
328
  });
311
329
 
330
+ const nodeIdsToMark = [];
331
+ if (resolved.symbolKey) {
332
+ const entry = artifacts.symbolIndex[resolved.symbolKey];
333
+ if (entry?.graphNodeId) nodeIdsToMark.push(entry.graphNodeId);
334
+ } else if (resolved.target && (resolved.mode === 'file' || resolved.mode === 'symbol-missing')) {
335
+ const fileNodeId = resolved.target.replace(/[/\\]/g, '_').replace(/[:.]/g, '_');
336
+ nodeIdsToMark.push(fileNodeId);
337
+ }
338
+
339
+ await markContext(projectRoot, nodeIdsToMark);
340
+
312
341
  console.log(output);
313
342
  return 0;
314
343
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aabadin/project-memory-context",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "Portable project memory context CLI — bootstraps semantic enrichment workflows for any AI coding agent.",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "type": "module",