neuroplex 0.0.0-stage → 0.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.
Files changed (104) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -3
  3. package/dist/brain/build.d.ts +21 -0
  4. package/dist/brain/build.js +172 -0
  5. package/dist/brain/build.js.map +1 -0
  6. package/dist/brain/local.d.ts +12 -0
  7. package/dist/brain/local.js +23 -0
  8. package/dist/brain/local.js.map +1 -0
  9. package/dist/brain/stats.d.ts +23 -0
  10. package/dist/brain/stats.js +37 -0
  11. package/dist/brain/stats.js.map +1 -0
  12. package/dist/brain/status.d.ts +21 -0
  13. package/dist/brain/status.js +28 -0
  14. package/dist/brain/status.js.map +1 -0
  15. package/dist/cli/index.d.ts +2 -0
  16. package/dist/cli/index.js +208 -0
  17. package/dist/cli/index.js.map +1 -0
  18. package/dist/config/config.d.ts +62 -0
  19. package/dist/config/config.js +141 -0
  20. package/dist/config/config.js.map +1 -0
  21. package/dist/enrich/index.d.ts +8 -0
  22. package/dist/enrich/index.js +13 -0
  23. package/dist/enrich/index.js.map +1 -0
  24. package/dist/enrich/tasks.d.ts +52 -0
  25. package/dist/enrich/tasks.js +339 -0
  26. package/dist/enrich/tasks.js.map +1 -0
  27. package/dist/enrich/write.d.ts +45 -0
  28. package/dist/enrich/write.js +228 -0
  29. package/dist/enrich/write.js.map +1 -0
  30. package/dist/graph/graph.d.ts +42 -0
  31. package/dist/graph/graph.js +174 -0
  32. package/dist/graph/graph.js.map +1 -0
  33. package/dist/graph/ids.d.ts +42 -0
  34. package/dist/graph/ids.js +104 -0
  35. package/dist/graph/ids.js.map +1 -0
  36. package/dist/graph/jsonl.d.ts +31 -0
  37. package/dist/graph/jsonl.js +121 -0
  38. package/dist/graph/jsonl.js.map +1 -0
  39. package/dist/graph/schema.d.ts +89 -0
  40. package/dist/graph/schema.js +73 -0
  41. package/dist/graph/schema.js.map +1 -0
  42. package/dist/index.d.ts +22 -0
  43. package/dist/index.js +22 -0
  44. package/dist/index.js.map +1 -0
  45. package/dist/install/claude.d.ts +37 -0
  46. package/dist/install/claude.js +104 -0
  47. package/dist/install/claude.js.map +1 -0
  48. package/dist/mcp/config.d.ts +20 -0
  49. package/dist/mcp/config.js +51 -0
  50. package/dist/mcp/config.js.map +1 -0
  51. package/dist/mcp/serve.d.ts +5 -0
  52. package/dist/mcp/serve.js +12 -0
  53. package/dist/mcp/serve.js.map +1 -0
  54. package/dist/mcp/server.d.ts +9 -0
  55. package/dist/mcp/server.js +248 -0
  56. package/dist/mcp/server.js.map +1 -0
  57. package/dist/query/brain.d.ts +21 -0
  58. package/dist/query/brain.js +51 -0
  59. package/dist/query/brain.js.map +1 -0
  60. package/dist/query/queries.d.ts +116 -0
  61. package/dist/query/queries.js +224 -0
  62. package/dist/query/queries.js.map +1 -0
  63. package/dist/query/search.d.ts +43 -0
  64. package/dist/query/search.js +329 -0
  65. package/dist/query/search.js.map +1 -0
  66. package/dist/scan/assemble.d.ts +20 -0
  67. package/dist/scan/assemble.js +255 -0
  68. package/dist/scan/assemble.js.map +1 -0
  69. package/dist/scan/discover.d.ts +21 -0
  70. package/dist/scan/discover.js +119 -0
  71. package/dist/scan/discover.js.map +1 -0
  72. package/dist/scan/extract.d.ts +3 -0
  73. package/dist/scan/extract.js +11 -0
  74. package/dist/scan/extract.js.map +1 -0
  75. package/dist/scan/extractors/python.d.ts +4 -0
  76. package/dist/scan/extractors/python.js +303 -0
  77. package/dist/scan/extractors/python.js.map +1 -0
  78. package/dist/scan/extractors/typescript.d.ts +6 -0
  79. package/dist/scan/extractors/typescript.js +509 -0
  80. package/dist/scan/extractors/typescript.js.map +1 -0
  81. package/dist/scan/git.d.ts +15 -0
  82. package/dist/scan/git.js +42 -0
  83. package/dist/scan/git.js.map +1 -0
  84. package/dist/scan/merge.d.ts +14 -0
  85. package/dist/scan/merge.js +57 -0
  86. package/dist/scan/merge.js.map +1 -0
  87. package/dist/scan/parser.d.ts +23 -0
  88. package/dist/scan/parser.js +57 -0
  89. package/dist/scan/parser.js.map +1 -0
  90. package/dist/scan/resolve.d.ts +23 -0
  91. package/dist/scan/resolve.js +131 -0
  92. package/dist/scan/resolve.js.map +1 -0
  93. package/dist/scan/scan.d.ts +36 -0
  94. package/dist/scan/scan.js +74 -0
  95. package/dist/scan/scan.js.map +1 -0
  96. package/dist/scan/types.d.ts +86 -0
  97. package/dist/scan/types.js +20 -0
  98. package/dist/scan/types.js.map +1 -0
  99. package/dist/version.d.ts +2 -0
  100. package/dist/version.js +5 -0
  101. package/dist/version.js.map +1 -0
  102. package/package.json +68 -4
  103. package/skills/neuroplex/SKILL.md +94 -0
  104. package/skills/neuroplex-update/SKILL.md +37 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Murillo Yamamoto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,11 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # 🧠 Neuroplex
2
+
3
+ > **A plug-and-play brain for your AI.** Turn any codebase into a living knowledge graph, served to your AI through a built-in MCP server. Free and open source.
4
+
5
+ **⚠️ Work in progress.** This package is a placeholder and does nothing useful yet. It will ship with the first usable release.
6
+
7
+ Follow the project on GitHub: https://github.com/MurilloY/Neuroplex
8
+
9
+ ## License
10
+
11
+ MIT © Murillo Yamamoto
@@ -0,0 +1,21 @@
1
+ export interface BuildOptions {
2
+ brainDir: string;
3
+ /** Initialize the brain as a git repository (if needed) and commit the result. */
4
+ git?: boolean;
5
+ }
6
+ export interface BuildResult {
7
+ written: string[];
8
+ /** `claude mcp add …` command that plugs this brain into Claude Code on this machine. */
9
+ mcpCommand: string;
10
+ /** Commit created in the brain repository, if any. */
11
+ commit?: string;
12
+ /** Why committing was skipped or failed, if `git` was requested. */
13
+ gitNote?: string;
14
+ }
15
+ export declare const OVERVIEW_PATH = "notes/overview.md";
16
+ /**
17
+ * Generates the brain repository files around the graph (docs/ARCHITECTURE.md §4.4):
18
+ * README, .gitignore and the structural overview note. Content outside the
19
+ * generated markers in the overview is preserved, so AI-written notes survive rebuilds.
20
+ */
21
+ export declare function buildBrain(options: BuildOptions): Promise<BuildResult>;
@@ -0,0 +1,172 @@
1
+ import { mkdir, readFile, writeFile } from 'node:fs/promises';
2
+ import { join, resolve } from 'node:path';
3
+ import { loadConfig } from '../config/config.js';
4
+ import { readGraph } from '../graph/jsonl.js';
5
+ import { git } from '../scan/git.js';
6
+ import { claudeAddCommand, mcpJson } from '../mcp/config.js';
7
+ import { VERSION } from '../version.js';
8
+ import { LOCAL_DIR } from './local.js';
9
+ import { graphStats } from './stats.js';
10
+ export const OVERVIEW_PATH = 'notes/overview.md';
11
+ const START = '<!-- neuroplex:structure:start -->';
12
+ const END = '<!-- neuroplex:structure:end -->';
13
+ /**
14
+ * Generates the brain repository files around the graph (docs/ARCHITECTURE.md §4.4):
15
+ * README, .gitignore and the structural overview note. Content outside the
16
+ * generated markers in the overview is preserved, so AI-written notes survive rebuilds.
17
+ */
18
+ export async function buildBrain(options) {
19
+ const brainDir = resolve(options.brainDir);
20
+ const config = await loadConfig(brainDir);
21
+ const graph = await readGraph(brainDir);
22
+ if (graph.nodeCount === 0) {
23
+ throw new Error(`The brain at ${brainDir} has no graph yet. Run \`neuroplex scan\` first.`);
24
+ }
25
+ const stats = graphStats(graph);
26
+ const written = [];
27
+ if (await writeIfMissing(join(brainDir, 'README.md'), renderReadme(config)))
28
+ written.push('README.md');
29
+ if (await ensureGitignore(brainDir))
30
+ written.push('.gitignore');
31
+ if (await writeIfMissing(join(brainDir, '.mcp.json'), mcpJson()))
32
+ written.push('.mcp.json');
33
+ await mkdir(join(brainDir, 'notes'), { recursive: true });
34
+ const overviewPath = join(brainDir, OVERVIEW_PATH);
35
+ const existing = await readFile(overviewPath, 'utf8').catch(() => undefined);
36
+ await writeFile(overviewPath, renderOverview(existing, config, graph, stats), 'utf8');
37
+ written.push(OVERVIEW_PATH);
38
+ const result = { written, mcpCommand: claudeAddCommand(brainDir, config.source.name) };
39
+ if (options.git)
40
+ Object.assign(result, await commitBrain(brainDir, config));
41
+ return result;
42
+ }
43
+ async function writeIfMissing(path, content) {
44
+ try {
45
+ await writeFile(path, content, { encoding: 'utf8', flag: 'wx' });
46
+ return true;
47
+ }
48
+ catch (err) {
49
+ if (err.code === 'EEXIST')
50
+ return false;
51
+ throw err;
52
+ }
53
+ }
54
+ async function ensureGitignore(brainDir) {
55
+ const path = join(brainDir, '.gitignore');
56
+ const current = await readFile(path, 'utf8').catch(() => '');
57
+ const entry = `${LOCAL_DIR}/`;
58
+ if (current.split(/\r?\n/).some((l) => l.trim() === entry))
59
+ return false;
60
+ const prefix = current && !current.endsWith('\n') ? '\n' : '';
61
+ await writeFile(path, `${current}${prefix}# Local Neuroplex state (machine-specific)\n${entry}\n`, 'utf8');
62
+ return true;
63
+ }
64
+ async function commitBrain(brainDir, config) {
65
+ const isRepo = (await git(brainDir, 'rev-parse', '--is-inside-work-tree')) === 'true';
66
+ const root = isRepo ? await git(brainDir, 'rev-parse', '--show-toplevel') : undefined;
67
+ if (isRepo && root && resolve(root) !== brainDir) {
68
+ return { gitNote: `the brain is inside another repository (${root}); not committing` };
69
+ }
70
+ if (!isRepo && (await git(brainDir, 'init', '-b', 'main')) === undefined) {
71
+ return { gitNote: 'git init failed' };
72
+ }
73
+ await git(brainDir, 'add', '-A');
74
+ if (!(await git(brainDir, 'status', '--porcelain')))
75
+ return { gitNote: 'nothing to commit' };
76
+ const sha = config.source.indexedCommit?.slice(0, 7) ?? 'worktree';
77
+ const message = `neuroplex: update brain for ${config.source.name}@${sha}`;
78
+ if ((await git(brainDir, 'commit', '-m', message)) === undefined) {
79
+ return { gitNote: 'git commit failed (is user.name/user.email configured?)' };
80
+ }
81
+ const commit = await git(brainDir, 'rev-parse', 'HEAD');
82
+ return commit ? { commit } : {};
83
+ }
84
+ // ── Rendering ──────────────────────────────────────────────────────────
85
+ function renderReadme(config) {
86
+ return `# ${config.source.name} brain
87
+
88
+ This repository is a **Neuroplex brain**: a knowledge graph of [${config.source.name}](${config.source.remote ?? '#'}) for AI assistants.
89
+
90
+ - \`graph/\`: nodes and edges (JSONL), regenerated by \`neuroplex scan\`
91
+ - \`notes/\`: human-readable notes; start with [notes/overview.md](notes/overview.md)
92
+ - \`neuroplex.json\`: brain configuration
93
+
94
+ Generated by [Neuroplex](https://github.com/MurilloY/Neuroplex). Refresh it with:
95
+
96
+ \`\`\`bash
97
+ npx neuroplex scan <path-to-${config.source.name}> --brain .
98
+ npx neuroplex build --brain .
99
+ \`\`\`
100
+ `;
101
+ }
102
+ function renderOverview(existing, config, graph, stats) {
103
+ const generated = `${START}\n${renderStructure(config, graph, stats)}\n${END}`;
104
+ if (existing?.includes(START) && existing.includes(END)) {
105
+ const before = existing.slice(0, existing.indexOf(START));
106
+ const after = existing.slice(existing.indexOf(END) + END.length);
107
+ return `${before}${generated}${after}`;
108
+ }
109
+ return `# ${config.source.name}\n\n${generated}\n`;
110
+ }
111
+ function renderStructure(config, graph, s) {
112
+ const project = graph.getNode('project');
113
+ const lines = [
114
+ `> Generated by Neuroplex ${VERSION} from \`${config.source.branch}\`` +
115
+ (config.source.indexedCommit ? ` at \`${config.source.indexedCommit.slice(0, 7)}\`` : '') +
116
+ '. Do not edit between the markers; it is rewritten on every build.',
117
+ '',
118
+ ];
119
+ if (project?.summary)
120
+ lines.push(project.summary, '');
121
+ lines.push('## At a glance', '', '| | Count |', '|---|---|');
122
+ const label = [
123
+ ['module', 'Modules'],
124
+ ['file', 'Files'],
125
+ ['symbol', 'Symbols'],
126
+ ['package', 'External packages'],
127
+ ['concept', 'Concepts'],
128
+ ['flow', 'Flows'],
129
+ ];
130
+ for (const [type, name] of label) {
131
+ if (s.nodes[type])
132
+ lines.push(`| ${name} | ${s.nodes[type]} |`);
133
+ }
134
+ lines.push(`| Relationships | ${s.totalEdges} |`);
135
+ const langs = Object.entries(s.languages).sort((a, b) => b[1] - a[1]);
136
+ if (langs.length)
137
+ lines.push(`| Languages | ${langs.map(([l, n]) => `${l} (${n})`).join(', ')} |`);
138
+ if (s.stale)
139
+ lines.push(`| Stale nodes | ${s.stale} |`);
140
+ const section = (title, ranked, unit, show) => {
141
+ if (!ranked.length)
142
+ return;
143
+ lines.push('', `## ${title}`, '', `| | ${unit} |`, '|---|---|');
144
+ for (const r of ranked)
145
+ lines.push(`| ${show(r.node)} | ${r.count} |`);
146
+ };
147
+ section('Core modules', s.coreModules, 'Modules depending on it', (n) => `\`${n.path ?? n.name}\``);
148
+ section('Most used symbols', s.hotSymbols, 'Callers', (n) => `\`${n.name}\` in \`${n.path}\``);
149
+ section('External packages', s.topPackages, 'Files importing it', (n) => `\`${n.name}\``);
150
+ const listSemantic = (title, type) => {
151
+ const nodes = [...graph.nodes()].filter((n) => n.type === type).sort((a, b) => (a.name < b.name ? -1 : 1));
152
+ if (!nodes.length)
153
+ return;
154
+ lines.push('', `## ${title}`, '');
155
+ for (const n of nodes) {
156
+ const name = n.note ? `[${n.name}](${n.note.replace(/^notes\//, '')})` : n.name;
157
+ lines.push(`- **${name}**${n.summary ? `: ${n.summary}` : ''}`);
158
+ }
159
+ };
160
+ listSemantic('Concepts', 'concept');
161
+ listSemantic('Flows', 'flow');
162
+ const modules = [...graph.nodes()].filter((n) => n.type === 'module' && n.summary);
163
+ if (modules.length) {
164
+ lines.push('', '## Modules', '');
165
+ for (const m of modules.sort((a, b) => (a.id < b.id ? -1 : 1))) {
166
+ const name = m.note ? `[\`${m.path}\`](${m.note.replace(/^notes\//, '')})` : `\`${m.path}\``;
167
+ lines.push(`- ${name}: ${m.summary}${m.stale ? ' *(may be outdated)*' : ''}`);
168
+ }
169
+ }
170
+ return lines.join('\n');
171
+ }
172
+ //# sourceMappingURL=build.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/brain/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAwB,MAAM,qBAAqB,CAAC;AAEvE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,UAAU,EAAgC,MAAM,YAAY,CAAC;AAkBtE,MAAM,CAAC,MAAM,aAAa,GAAG,mBAAmB,CAAC;AACjD,MAAM,KAAK,GAAG,oCA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plex.json` stays portable across machines and teammates.
4
+ */
5
+ export declare const LOCAL_DIR = ".neuroplex";
6
+ export declare const LOCAL_FILE = "local.json";
7
+ export interface LocalState {
8
+ /** Absolute path of the source project on this machine. */
9
+ sourcePath?: string;
10
+ }
11
+ export declare function readLocalState(brainDir: string): Promise<LocalState>;
12
+ export declare function writeLocalState(brainDir: string, patch: LocalState): Promise<LocalState>;
@@ -0,0 +1,23 @@
1
+ import { mkdir, readFile, writeFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ /**
4
+ * Machine-specific state in `<brain>/.neuroplex/local.json` (git-ignored), so the
5
+ * committed `neuroplex.json` stays portable across machines and teammates.
6
+ */
7
+ export const LOCAL_DIR = '.neuroplex';
8
+ export const LOCAL_FILE = 'local.json';
9
+ export async function readLocalState(brainDir) {
10
+ try {
11
+ return JSON.parse(await readFile(join(brainDir, LOCAL_DIR, LOCAL_FILE), 'utf8'));
12
+ }
13
+ catch {
14
+ return {};
15
+ }
16
+ }
17
+ export async function writeLocalState(brainDir, patch) {
18
+ const next = { ...(await readLocalState(brainDir)), ...patch };
19
+ await mkdir(join(brainDir, LOCAL_DIR), { recursive: true });
20
+ await writeFile(join(brainDir, LOCAL_DIR, LOCAL_FILE), JSON.stringify(next, null, 2) + '\n', 'utf8');
21
+ return next;
22
+ }
23
+ //# sourceMappingURL=local.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local.js","sourceRoot":"","sources":["../../src/brain/local.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC;;;GAGG;AAEH,MAAM,CAAC,MAAM,SAAS,GAAG,YAAY,CAAC;AACtC,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAC;AAOvC,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,QAAgB;IACnD,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,CAAe,CAAC;IACjG,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,QAAgB,EAAE,KAAiB;IACvE,MAAM,IAAI,GAAG,EAAE,GAAG,CAAC,MAAM,cAAc,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC;IAC/D,MAAM,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5D,MAAM,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,EAAE,UAAU,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,CAAC;IACrG,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,23 @@
1
+ import type { Graph } from '../graph/graph.js';
2
+ import type { EdgeType, GraphNode, NodeType } from '../graph/schema.js';
3
+ export interface Ranked {
4
+ node: GraphNode;
5
+ count: number;
6
+ }
7
+ export interface GraphStats {
8
+ nodes: Partial<Record<NodeType, number>>;
9
+ edges: Partial<Record<EdgeType, number>>;
10
+ totalNodes: number;
11
+ totalEdges: number;
12
+ stale: number;
13
+ /** Nodes with an AI-written summary. */
14
+ summarized: number;
15
+ languages: Record<string, number>;
16
+ /** Modules most depended on by other modules. */
17
+ coreModules: Ranked[];
18
+ /** External packages imported by the most files. */
19
+ topPackages: Ranked[];
20
+ /** Symbols called from the most places. */
21
+ hotSymbols: Ranked[];
22
+ }
23
+ export declare function graphStats(graph: Graph, top?: number): GraphStats;
@@ -0,0 +1,37 @@
1
+ export function graphStats(graph, top = 10) {
2
+ const nodes = {};
3
+ const edges = {};
4
+ const languages = {};
5
+ let stale = 0;
6
+ let summarized = 0;
7
+ for (const n of graph.nodes()) {
8
+ nodes[n.type] = (nodes[n.type] ?? 0) + 1;
9
+ if (n.stale)
10
+ stale++;
11
+ if (n.summary)
12
+ summarized++;
13
+ if (n.type === 'file' && n.language)
14
+ languages[n.language] = (languages[n.language] ?? 0) + 1;
15
+ }
16
+ for (const e of graph.edges())
17
+ edges[e.type] = (edges[e.type] ?? 0) + 1;
18
+ const rank = (type, edge) => [...graph.nodes()]
19
+ .filter((n) => n.type === type)
20
+ .map((node) => ({ node, count: graph.incoming(node.id, [edge]).length }))
21
+ .filter((r) => r.count > 0)
22
+ .sort((a, b) => b.count - a.count || (a.node.id < b.node.id ? -1 : 1))
23
+ .slice(0, top);
24
+ return {
25
+ nodes,
26
+ edges,
27
+ totalNodes: graph.nodeCount,
28
+ totalEdges: graph.edgeCount,
29
+ stale,
30
+ summarized,
31
+ languages,
32
+ coreModules: rank('module', 'depends_on'),
33
+ topPackages: rank('package', 'imports'),
34
+ hotSymbols: rank('symbol', 'calls'),
35
+ };
36
+ }
37
+ //# sourceMappingURL=stats.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stats.js","sourceRoot":"","sources":["../../src/brain/stats.ts"],"names":[],"mappings":"AAyBA,MAAM,UAAU,UAAU,CAAC,KAAY,EAAE,GAAG,GAAG,EAAE;IAC/C,MAAM,KAAK,GAAwB,EAAE,CAAC;IACtC,MAAM,KAAK,GAAwB,EAAE,CAAC;IACtC,MAAM,SAAS,GAA2B,EAAE,CAAC;IAC7C,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,UAAU,GAAG,CAAC,CAAC;IAEnB,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC;QAC9B,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,C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CAAC;SACrE,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAEnB,OAAO;QACL,KAAK;QACL,KAAK;QACL,UAAU,EAAE,KAAK,CAAC,SAAS;QAC3B,UAAU,EAAE,KAAK,CAAC,SAAS;QAC3B,KAAK;QACL,UAAU;QACV,SAAS;QACT,WAAW,EAAE,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC;QACzC,WAAW,EAAE,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC;QACvC,UAAU,EAAE,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC;KACpC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { type NeuroplexConfig } from '../config/config.js';
2
+ import { type Phase } from '../enrich/tasks.js';
3
+ import { type GraphStats } from './stats.js';
4
+ export interface BrainStatus {
5
+ brainDir: string;
6
+ config: NeuroplexConfig;
7
+ stats: GraphStats;
8
+ /** Pending AI enrichment tasks per phase. */
9
+ pendingTasks: Record<Phase, number>;
10
+ source: {
11
+ /** Local checkout of the source project, if known on this machine. */
12
+ path?: string;
13
+ /** Current HEAD of the local checkout. */
14
+ head?: string;
15
+ /** Commits in the local checkout that the brain has not indexed yet. */
16
+ behind?: number;
17
+ /** The local checkout has uncommitted changes. */
18
+ dirty?: true;
19
+ };
20
+ }
21
+ export declare function brainStatus(brainDir: string): Promise<BrainStatus>;
@@ -0,0 +1,28 @@
1
+ import { resolve } from 'node:path';
2
+ import { loadConfig } from '../config/config.js';
3
+ import { listTasks } from '../enrich/tasks.js';
4
+ import { readGraph } from '../graph/jsonl.js';
5
+ import { countCommits, gitInfo } from '../scan/git.js';
6
+ import { readLocalState } from './local.js';
7
+ import { graphStats } from './stats.js';
8
+ export async function brainStatus(brainDir) {
9
+ const dir = resolve(brainDir);
10
+ const [config, graph, local] = await Promise.all([loadConfig(dir), readGraph(dir), readLocalState(dir)]);
11
+ const source = {};
12
+ if (local.sourcePath) {
13
+ source.path = local.sourcePath;
14
+ const git = await gitInfo(local.sourcePath);
15
+ if (git?.dirty)
16
+ source.dirty = true;
17
+ if (git?.head) {
18
+ source.head = git.head;
19
+ const indexed = config.source.indexedCommit;
20
+ const behind = indexed ? await countCommits(local.sourcePath, indexed, git.head) : undefined;
21
+ if (behind !== undefined)
22
+ source.behind = behind;
23
+ }
24
+ }
25
+ const pendingTasks = listTasks(graph, { limit: 0 }).pending;
26
+ return { brainDir: dir, config, stats: graphStats(graph), pendingTasks, source };
27
+ }
28
+ //# sourceMappingURL=status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/brain/status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAwB,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,SAAS,EAAc,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAmB,MAAM,YAAY,CAAC;AAoBzD,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,QAAgB;IAChD,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC9B,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC,GAAG,CAAC,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACzG,MAAM,MAAM,GAA0B,EAAE,CAAC;IACzC,IAAI,KAAK,CAAC,UAAU,EAAE,CAAC;QACrB,MAAM,CAAC,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC;QAC/B,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC5C,IAAI,GAAG,EAAE,KAAK;YAAE,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC;QACpC,IAAI,GAAG,EAAE,IAAI,EAAE,CAAC;YACd,MAAM,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;YACvB,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC;YAC5C,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,MAAM,YAAY,CAAC,KAAK,CAAC,UAAU,EAAE,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YAC7F,IAAI,MAAM,KAAK,SAAS;gBAAE,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;QACnD,CAAC;IACH,CAAC;IACD,MAAM,YAAY,GAAG,SAAS,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC;IAC5D,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,KAAK,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC;AACnF,CAAC"}
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,208 @@
1
+ #!/usr/bin/env node
2
+ import { basename, dirname, join, resolve } from 'node:path';
3
+ import { readFile } from 'node:fs/promises';
4
+ import { Command, Option } from 'commander';
5
+ import { brainTasks, PHASES, writeResult } from '../enrich/index.js';
6
+ import { buildBrain } from '../brain/build.js';
7
+ import { brainStatus } from '../brain/status.js';
8
+ import { loadConfig } from '../config/config.js';
9
+ import { connectMcp, installSkills } from '../install/claude.js';
10
+ import { serveStdio } from '../mcp/serve.js';
11
+ import { scanProject } from '../scan/scan.js';
12
+ import { VERSION } from '../version.js';
13
+ const program = new Command()
14
+ .name('neuroplex')
15
+ .description('A plug-and-play brain for your AI: turns a codebase into a knowledge graph.')
16
+ .version(VERSION, '-v, --version');
17
+ /** Default brain location: a sibling folder named `<project>-brain`. */
18
+ const defaultBrain = (projectDir) => {
19
+ const abs = resolve(projectDir);
20
+ return join(dirname(abs), `${basename(abs)}-brain`);
21
+ };
22
+ program
23
+ .command('scan')
24
+ .description('Parse a project and write its structural graph into a brain')
25
+ .argument('[project]', 'path of the project to scan', '.')
26
+ .option('-b, --brain <dir>', 'brain directory (default: ../<project>-brain)')
27
+ .option('--json', 'print the result as JSON')
28
+ .action(async (project, opts) => {
29
+ const brainDir = resolve(opts.brain ?? defaultBrain(project));
30
+ const tty = process.stderr.isTTY && !opts.json;
31
+ const result = await scanProject({
32
+ projectDir: project,
33
+ brainDir,
34
+ ...(tty && {
35
+ onProgress: (done, total) => {
36
+ process.stderr.write(`\rScanning ${done}/${total} files…`);
37
+ if (done === total)
38
+ process.stderr.write('\n');
39
+ },
40
+ }),
41
+ });
42
+ const counts = Object.fromEntries(['module', 'file', 'symbol', 'package'].map((t) => [
43
+ t,
44
+ [...result.graph.nodes()].filter((n) => n.type === t).length,
45
+ ]));
46
+ if (opts.json) {
47
+ const { graph, config: _config, ...rest } = result;
48
+ console.log(JSON.stringify({ brainDir, ...rest, nodes: graph.nodeCount, edges: graph.edgeCount, counts }, null, 2));
49
+ return;
50
+ }
51
+ const langs = Object.entries(result.filesByLanguage).map(([l, n]) => `${l} ${n}`).join(', ');
52
+ console.log(`Scanned ${result.files} files (${langs || 'none'}) in ${(result.durationMs / 1000).toFixed(1)}s`);
53
+ console.log(`Graph: ${result.graph.nodeCount} nodes (${counts.module} modules, ${counts.file} files, ` +
54
+ `${counts.symbol} symbols, ${counts.package} packages), ${result.graph.edgeCount} edges`);
55
+ if (result.semantic.kept) {
56
+ console.log(`Kept AI knowledge on ${result.semantic.kept} nodes (${result.semantic.stale} now stale)`);
57
+ }
58
+ for (const f of result.failed)
59
+ console.warn(` ! could not parse ${f.path}: ${f.error}`);
60
+ if (result.dirty)
61
+ console.warn('Note: the project has uncommitted changes; they are included in this scan.');
62
+ console.log(`Brain: ${brainDir}`);
63
+ console.log(`Next: add AI knowledge with \`neuroplex tasks --brain "${brainDir}"\` (or the /neuroplex skill),`);
64
+ console.log(` then \`neuroplex build --brain "${brainDir}" --git\``);
65
+ });
66
+ program
67
+ .command('build')
68
+ .description('Generate the brain repository files (README, notes) from its graph')
69
+ .option('-b, --brain <dir>', 'brain directory', '.')
70
+ .option('--git', 'initialize the brain as a git repository and commit')
71
+ .action(async (opts) => {
72
+ const result = await buildBrain({ brainDir: opts.brain, git: opts.git ?? false });
73
+ console.log(`Wrote ${result.written.join(', ')}`);
74
+ if (result.commit)
75
+ console.log(`Committed ${result.commit.slice(0, 7)}`);
76
+ if (result.gitNote)
77
+ console.log(`Git: ${result.gitNote}`);
78
+ console.log(`\nPlug this brain into Claude Code: neuroplex connect --brain "${resolve(opts.brain)}"`);
79
+ console.log(` (runs: ${result.mcpCommand})`);
80
+ });
81
+ const scopeOption = () => new Option('--scope <scope>', 'user = all your projects, project = this project only').choices(['user', 'project']).default('user');
82
+ program
83
+ .command('init')
84
+ .description('Set up Neuroplex for a project: install the skills and run the structural scan')
85
+ .argument('[project]', 'path of the project', '.')
86
+ .option('-b, --brain <dir>', 'brain directory (default: ../<project>-brain)')
87
+ .addOption(scopeOption())
88
+ .option('--no-skills', 'do not install the Claude Code skills')
89
+ .action(async (project, opts) => {
90
+ const brainDir = resolve(opts.brain ?? defaultBrain(project));
91
+ if (opts.skills) {
92
+ const installed = await installSkills(opts.scope, project);
93
+ console.log(`Installed skills ${installed.skills.map((s) => `/${s}`).join(', ')} into ${installed.target}`);
94
+ }
95
+ const result = await scanProject({ projectDir: project, brainDir });
96
+ console.log(`Scanned ${result.files} files: ${result.graph.nodeCount} nodes, ${result.graph.edgeCount} edges -> ${brainDir}`);
97
+ console.log('\nNext steps:');
98
+ console.log(' 1. In Claude Code, run /neuroplex to add AI knowledge (summaries, concepts, flows),');
99
+ console.log(' build the brain and connect it. Other assistants: follow skills/neuroplex/SKILL.md.');
100
+ console.log(` 2. Or do it by hand: neuroplex tasks --brain "${brainDir}" ... then build and connect.`);
101
+ });
102
+ program
103
+ .command('install')
104
+ .description('Install the Neuroplex skills (/neuroplex, /neuroplex-update) into Claude Code')
105
+ .addOption(scopeOption())
106
+ .option('-p, --project <dir>', 'project folder (for --scope project)', '.')
107
+ .action(async (opts) => {
108
+ const installed = await installSkills(opts.scope, opts.project);
109
+ console.log(`Installed ${installed.skills.map((s) => `/${s}`).join(', ')} into ${installed.target}`);
110
+ });
111
+ program
112
+ .command('connect')
113
+ .description('Register the brain as an MCP server in Claude Code')
114
+ .option('-b, --brain <dir>', 'brain directory', '.')
115
+ .addOption(scopeOption())
116
+ .option('-p, --project <dir>', 'project whose .mcp.json gets the server (for --scope project)', '.')
117
+ .option('--dry-run', 'only print what would be done')
118
+ .action(async (opts) => {
119
+ const config = await loadConfig(resolve(opts.brain));
120
+ const result = await connectMcp({
121
+ brainDir: opts.brain,
122
+ projectName: config.source.name,
123
+ scope: opts.scope,
124
+ projectDir: opts.project,
125
+ dryRun: opts.dryRun ?? false,
126
+ });
127
+ if (result.done) {
128
+ console.log(`Connected MCP server "${result.name}" (${result.scope} scope): ${result.how}`);
129
+ console.log('Start a new Claude Code session to use it.');
130
+ }
131
+ else {
132
+ console.log(`Not connected (${result.note}). To connect, run:\n ${result.how}`);
133
+ }
134
+ });
135
+ program
136
+ .command('tasks')
137
+ .description('List pending AI enrichment tasks (JSON)')
138
+ .option('-b, --brain <dir>', 'brain directory', '.')
139
+ .option('-n, --limit <n>', 'maximum tasks to return', (v) => Number.parseInt(v, 10), 5)
140
+ .addOption(new Option('--phase <phase>', 'force a phase').choices([...PHASES]))
141
+ .option('--brief', 'only list task IDs, titles and targets counts')
142
+ .action(async (opts) => {
143
+ const list = await brainTasks(opts.brain, { limit: opts.limit, ...(opts.phase && { phase: opts.phase }) });
144
+ if (opts.brief) {
145
+ const pending = Object.entries(list.pending).map(([p, n]) => `${p} ${n}`).join(', ');
146
+ console.log(`Phase: ${list.phase ?? 'done'} (pending: ${pending})`);
147
+ for (const t of list.tasks)
148
+ console.log(`- ${t.id}: ${t.title} (${t.targets.length} targets)`);
149
+ return;
150
+ }
151
+ // Compact JSON: task context can be large, and indentation would double it.
152
+ console.log(JSON.stringify(list));
153
+ });
154
+ program
155
+ .command('write')
156
+ .description('Submit an AI enrichment result (JSON) for a task')
157
+ .argument('[task-id]', 'the task this result answers')
158
+ .option('-b, --brain <dir>', 'brain directory', '.')
159
+ .option('-f, --file <path>', 'read the result from a file instead of stdin')
160
+ .action(async (taskId, opts) => {
161
+ const raw = opts.file ? await readFile(opts.file, 'utf8') : await readStdin();
162
+ const report = await writeResult(opts.brain, raw, taskId);
163
+ console.log(JSON.stringify(report, null, 2));
164
+ });
165
+ program
166
+ .command('serve')
167
+ .description('Serve the brain to AI assistants over MCP (stdio)')
168
+ .option('-b, --brain <dir>', 'brain directory', '.')
169
+ .action(async (opts) => {
170
+ await serveStdio(resolve(opts.brain));
171
+ });
172
+ program
173
+ .command('status')
174
+ .description('Show what the brain contains and whether it is up to date')
175
+ .option('-b, --brain <dir>', 'brain directory', '.')
176
+ .option('--json', 'print the result as JSON')
177
+ .action(async (opts) => {
178
+ const s = await brainStatus(opts.brain);
179
+ if (opts.json) {
180
+ console.log(JSON.stringify(s, (_k, v) => (v instanceof Object && 'node' in v ? { id: v.node.id, count: v.count } : v), 2));
181
+ return;
182
+ }
183
+ const { config, stats, source } = s;
184
+ console.log(`Brain: ${s.brainDir}`);
185
+ console.log(`Project: ${config.source.name}${config.source.remote ? ` (${config.source.remote})` : ''}`);
186
+ console.log(`Indexed: ${config.source.branch}@${config.source.indexedCommit?.slice(0, 7) ?? '(not a git commit)'}` +
187
+ (source.behind === undefined ? '' : source.behind === 0 ? ', up to date' : `, ${source.behind} commit(s) behind`) +
188
+ (source.dirty ? ' (source has uncommitted changes)' : ''));
189
+ const types = Object.entries(stats.nodes).map(([t, n]) => `${n} ${t}`).join(', ');
190
+ console.log(`Graph: ${stats.totalNodes} nodes (${types}), ${stats.totalEdges} edges`);
191
+ console.log(`Semantic: ${stats.summarized} summarized, ${stats.stale} stale`);
192
+ const pending = Object.entries(s.pendingTasks).filter(([, n]) => n > 0);
193
+ console.log(`Tasks: ${pending.length ? pending.map(([p, n]) => `${n} ${p}`).join(', ') + ' pending (run `neuroplex tasks`)' : 'enrichment complete'}`);
194
+ console.log(`Sync: auto-sync ${config.sync.autoSync ? `on (every ${config.sync.intervalMinutes} min)` : 'off'}`);
195
+ });
196
+ async function readStdin() {
197
+ if (process.stdin.isTTY)
198
+ throw new Error('No input: pass --file <path> or pipe the result JSON into stdin.');
199
+ const chunks = [];
200
+ for await (const chunk of process.stdin)
201
+ chunks.push(chunk);
202
+ return Buffer.concat(chunks).toString('utf8');
203
+ }
204
+ program.parseAsync().catch((err) => {
205
+ console.error(`neuroplex: ${err instanceof Error ? err.message : String(err)}`);
206
+ process.exitCode = 1;
207
+ });
208
+ //# sourceMappingURL=index.js.map