code-graph-llm 2.0.0 → 2.1.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/AGENT_RULES.md CHANGED
@@ -1,16 +1,12 @@
1
1
  # AGENT OPERATIONAL PROTOCOL (STRICT)
2
2
  > This protocol is MANDATORY for all LLM agents. Failure to update memory is a failure of the task.
3
-
4
3
  ## 🧠 THE REFLECTION CYCLE
5
- Every execution MUST follow this cycle:
6
- 1. **PRE-TASK:** Read `PROJECT_REFLECTIONS.md` to identify existing pitfalls (OS, Deps, Logic).
7
- 2. **EXECUTION:** Monitor for any "Learned Moments":
8
- - **Task Failures:** Identify the root cause (e.g., "Win32 shell restrictions").
9
- - **Sub-optimal Logic:** Identify better abstractions (e.g., "Prefer fsp over fs").
10
- - **Environment Issues:** Identify missing dependencies or OS incompatibilities.
11
- 3. **POST-TASK:** Immediately run `code-graph reflect <CAT> <LESSON>` for any discovery.
12
- - **DO NOT** wait for the user to ask.
13
- - **DO NOT** commit until `llm-code-graph.md` is regenerated.
4
+ Every execution SHOULD follow this cycle:
5
+ 1. **PRE-TASK:** Read \`PROJECT_REFLECTIONS.md\` to identify existing pitfalls.
6
+ 2. **EXECUTION:** Monitor for "Learned Moments" (failures, unexpected behaviors, or non-obvious fixes).
7
+ 3. **POST-TASK:** If a significant lesson was learned, run \`code-graph reflect <CAT> <LESSON>\`.
8
+ - **NOTE:** Routine, expected changes do not require reflections. Focus on high-signal context.
9
+
14
10
 
15
11
  ## âš ī¸ CRITICAL MANDATES
16
12
  - **OS [win32]:** Always prefix npm commands with `cmd /c`.
package/README.md CHANGED
@@ -27,6 +27,9 @@ npm install --save-dev code-graph-llm
27
27
 
28
28
  ### 2. Core Commands
29
29
  ```bash
30
+ # Initialize Agent Rules and Reflection files (Scaffolding)
31
+ code-graph init
32
+
30
33
  # Generate the llm-code-graph.md map
31
34
  code-graph generate
32
35
 
package/index.js CHANGED
@@ -273,6 +273,46 @@ class ReflectionManager {
273
273
  }
274
274
  }
275
275
 
276
+ /**
277
+ * Scaffolds the initial agent-agnostic rule and reflection files.
278
+ */
279
+ class ProjectInitializer {
280
+ static async init(cwd) {
281
+ const rulesPath = path.join(cwd, CONFIG.RULES_FILE);
282
+ const reflectPath = path.join(cwd, CONFIG.REFLECTIONS_FILE);
283
+
284
+ const rulesContent = `# AGENT OPERATIONAL PROTOCOL (STRICT)
285
+ > This protocol is MANDATORY for all LLM agents. Failure to update memory is a failure of the task.
286
+
287
+ ## 🧠 THE REFLECTION CYCLE
288
+ 1. **PRE-TASK:** Read \`${CONFIG.REFLECTIONS_FILE}\` to identify existing pitfalls.
289
+ 2. **EXECUTION:** Monitor for "Learned Moments" (failures, corrections, or discoveries).
290
+ 3. **POST-TASK:** Immediately run \`code-graph reflect <CAT> <LESSON>\` for any discovery.
291
+
292
+ ## 📝 REFLECTION CATEGORIES
293
+ - \`LOGIC\`: Code bugs or complex regex pitfalls.
294
+ - \`ENV\`: OS compatibility or shell behaviors.
295
+ - \`DEP\`: Library bugs or version deprecations.
296
+ - \`STYLE\`: Project-specific architectural rules.
297
+ `;
298
+
299
+ const reflectContent = `# PROJECT_REFLECTIONS & LESSONS LEARNED\n> LLM AGENT MEMORY: READ BEFORE STARTING TASKS. UPDATE ON FAILURES.\n`;
300
+
301
+ try {
302
+ if (!fs.existsSync(rulesPath)) {
303
+ await fsp.writeFile(rulesPath, rulesContent);
304
+ console.log(`[Code-Graph] Initialized ${CONFIG.RULES_FILE}`);
305
+ }
306
+ if (!fs.existsSync(reflectPath)) {
307
+ await fsp.writeFile(reflectPath, reflectContent);
308
+ console.log(`[Code-Graph] Initialized ${CONFIG.REFLECTIONS_FILE}`);
309
+ }
310
+ } catch (err) {
311
+ console.error(`[Code-Graph] Initialization failed: ${err.message}`);
312
+ }
313
+ }
314
+ }
315
+
276
316
  // --- CLI Entry Point ---
277
317
 
278
318
  async function main() {
@@ -284,17 +324,21 @@ async function main() {
284
324
  case 'generate':
285
325
  await new ProjectMapper(cwd).generate();
286
326
  break;
327
+ case 'init':
328
+ await ProjectInitializer.init(cwd);
329
+ break;
287
330
  case 'reflect':
288
331
  await ReflectionManager.add(args[0], args.slice(1).join(' '));
289
332
  break;
290
333
  case 'install-hook':
334
+ await ProjectInitializer.init(cwd);
291
335
  await installGitHook(cwd);
292
336
  break;
293
337
  case 'watch':
294
338
  startWatcher(cwd);
295
339
  break;
296
340
  default:
297
- console.log('Usage: code-graph [generate|reflect|install-hook|watch]');
341
+ console.log('Usage: code-graph [generate|init|reflect|install-hook|watch]');
298
342
  }
299
343
  } catch (err) {
300
344
  console.error(`[Code-Graph] Critical Error: ${err.message}`);
@@ -306,9 +350,30 @@ async function installGitHook(cwd) {
306
350
  const hookPath = path.join(cwd, '.git', 'hooks', 'pre-commit');
307
351
  if (!fs.existsSync(path.dirname(hookPath))) return console.error('[Code-Graph] No .git directory found.');
308
352
 
309
- const content = `#!/bin/sh\n# Code-Graph Sync\necho "[Code-Graph] Validating..."\nnode "${__filename}" generate\ngit add "${CONFIG.MAP_FILE}"\nif [ ! -z "$(git diff --cached --shortstat)" ]; then\n echo "[Code-Graph] Reminder: Run 'code-graph reflect' if this fix resolves a non-obvious bug."\nfi`;
353
+ const content = `#!/bin/sh
354
+ # Code-Graph Advisory: Map Sync & Reflection Reminder
355
+ echo "[Code-Graph] Validating commit..."
356
+
357
+ # 1. Regenerate Map
358
+ node "${__filename}" generate
359
+ git add "${CONFIG.MAP_FILE}"
360
+
361
+ # 2. Reflection Advisory
362
+ # Notify if code changed but reflections didn't (Soft Nudge)
363
+ CODE_CHANGES=$(git diff --cached --name-only | grep -E "\\.(${CONFIG.SUPPORTED_EXTENSIONS.map(e => e.slice(1)).join('|')})$")
364
+ REFLECT_CHANGES=$(git diff --cached --name-only | grep "${CONFIG.REFLECTIONS_FILE}")
365
+
366
+ if [ ! -z "$CODE_CHANGES" ] && [ -z "$REFLECT_CHANGES" ]; then
367
+ echo "--------------------------------------------------------"
368
+ echo "â„šī¸ [Code-Graph] ADVISORY: Reflection Check"
369
+ echo "Significant code changes detected without a reflection."
370
+ echo "If you learned something new or fixed a non-obvious bug,"
371
+ echo "run 'code-graph reflect LOGIC <lesson>' before committing."
372
+ echo "--------------------------------------------------------"
373
+ fi
374
+ `;
310
375
  await fsp.writeFile(hookPath, content, { mode: 0o755 });
311
- console.log('[Code-Graph] Pre-commit hook installed.');
376
+ console.log('[Code-Graph] Pre-commit Advisory installed (Soft Enforcement).');
312
377
  }
313
378
 
314
379
  function startWatcher(cwd) {
package/llm-code-graph.md CHANGED
@@ -4,8 +4,8 @@
4
4
  > Legend: [CORE] Entry Point, (↑N) Outgoing Deps, (↓M) Incoming Dependents
5
5
  > Notation: syms: [Name [Signature/Context]], desc: File Summary, [TAG: Context]
6
6
 
7
- - [CORE] index.js (↑6 ↓1) [TODO: |FIXME|BUG|DEPRECATED):?\s*(.*)/i,, bug: ."\nfi`;] | desc: !usrbinenv node
8
- - syms: [CONFIG [=], CodeParser [--- Core Services --- Handles extraction of symbols, edges, and metadata from source code.], ProjectMapper [Manages the project mapping and file generation.], ReflectionManager [Manages project reflections and lessons learned.], SUPPORTED_EXTENSIONS [: [], add [(context ? `${display} [${context}]` : display)], extract [(content)], installGitHook [(cwd)], main [|app|server|cli)\./i.test(path.basename(relPath))], processFile [(fullPath, relPath)], startWatcher [(cwd)], walk [(dir, ig)]]
7
+ - [CORE] index.js (↑6 ↓1) [TODO: |FIXME|BUG|DEPRECATED):?\s*(.*)/i,, bug: s or complex regex pitfalls., bug: s or version deprecations., bug: ,"] | desc: !usrbinenv node
8
+ - syms: [CONFIG [=], CodeParser [--- Core Services --- Handles extraction of symbols, edges, and metadata from source code.], ProjectInitializer [Scaffolds the initial agent-agnostic rule and reflection files.], ProjectMapper [Manages the project mapping and file generation.], ReflectionManager [Manages project reflections and lessons learned.], SUPPORTED_EXTENSIONS [: [], add [(context ? `${display} [${context}]` : display)], extract [(content)], init [(cwd)], installGitHook [(cwd)], main [|app|server|cli)\./i.test(path.basename(relPath))], processFile [(fullPath, relPath)], walk [(dir, ig)]]
9
9
  - [CORE] test/index.test.js (↑10 ↓0) | desc:
10
10
  - syms: []
11
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "code-graph-llm",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Compact, language-agnostic codebase mapper for LLM token efficiency.",
5
5
  "main": "index.js",
6
6
  "bin": {