Skip to content

Turbocharge Claude Code, Cursor, Codex, Gemini & every coding agent: faster, cheaper, with contextual understanding specific to your codebase.

feat(claude): computeStats + readWiring

Shrish Dwivedi5e3a7f745654
diff --git a/src/claude/stats.ts b/src/claude/stats.ts
new file mode 100644
index 00000000..6d85f1ac
--- /dev/null
+++ b/src/claude/stats.ts
@@ -0,0 +1,25 @@
+import { readFileSync } from 'node:fs';
+import { join } from 'node:path';
+import type { GraphV1 } from '../graph/types.js';
+import type { Stats } from './state.js';
+
+export function readWiring(projectDir: string): GraphV1 | null {
+ try {
+ return JSON.parse(readFileSync(join(projectDir, 'graft', '.graph', 'wiring.json'), 'utf8')) as GraphV1;
+ } catch { return null; }
+}
+
+export function computeStats(
+ w: GraphV1,
+): Pick<Stats, 'nodeCount' | 'edgeCount' | 'languages' | 'totalCount' | 'readyCount'> {
+ const nodes = w.nodes ?? [];
+ const edges = w.edges ?? [];
+ const readyCount = nodes.filter((n) => n.summary_state === 'ready').length;
+ return {
+ nodeCount: w.meta?.nodeCount ?? nodes.length,
+ edgeCount: w.meta?.edgeCount ?? edges.length,
+ languages: w.meta?.languages ?? [],
+ totalCount: nodes.length,
+ readyCount,
+ };
+}
diff --git a/test/claude-stats.test.ts b/test/claude-stats.test.ts
new file mode 100644
index 00000000..4122cd0a
--- /dev/null
+++ b/test/claude-stats.test.ts
@@ -0,0 +1,29 @@
+import { test } from 'node:test';
+import assert from 'node:assert/strict';
+import { computeStats } from '../src/claude/stats.js';
+
+const wiring = {
+ meta: { version: 1, nodeCount: 3, edgeCount: 2, languages: ['typescript'] },
+ nodes: [
+ { id: 'a', summary_state: 'ready' },
+ { id: 'b', summary_state: 'pending' },
+ { id: 'c', summary_state: 'ready' },
+ ],
+ edges: [{ from: 'a', to: 'b' }, { from: 'c', to: 'a' }],
+} as any;
+
+test('computeStats derives counts and readyCount', () => {
+ const s = computeStats(wiring);
+ assert.equal(s.nodeCount, 3);
+ assert.equal(s.edgeCount, 2);
+ assert.deepEqual(s.languages, ['typescript']);
+ assert.equal(s.totalCount, 3);
+ assert.equal(s.readyCount, 2);
+});
+
+test('computeStats tolerates missing meta by counting arrays', () => {
+ const s = computeStats({ nodes: [{ id: 'x', summary_state: 'pending' }], edges: [] } as any);
+ assert.equal(s.nodeCount, 1);
+ assert.equal(s.edgeCount, 0);
+ assert.equal(s.readyCount, 0);
+});