neuroplex 0.0.1 → 0.2.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 (112) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +11 -11
  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 +24 -0
  13. package/dist/brain/status.js +30 -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 +269 -0
  17. package/dist/cli/index.js.map +1 -0
  18. package/dist/config/config.d.ts +64 -0
  19. package/dist/config/config.js +147 -0
  20. package/dist/config/config.js.map +1 -0
  21. package/dist/config/edit.d.ts +9 -0
  22. package/dist/config/edit.js +45 -0
  23. package/dist/config/edit.js.map +1 -0
  24. package/dist/enrich/index.d.ts +8 -0
  25. package/dist/enrich/index.js +13 -0
  26. package/dist/enrich/index.js.map +1 -0
  27. package/dist/enrich/tasks.d.ts +52 -0
  28. package/dist/enrich/tasks.js +339 -0
  29. package/dist/enrich/tasks.js.map +1 -0
  30. package/dist/enrich/write.d.ts +45 -0
  31. package/dist/enrich/write.js +228 -0
  32. package/dist/enrich/write.js.map +1 -0
  33. package/dist/graph/graph.d.ts +42 -0
  34. package/dist/graph/graph.js +174 -0
  35. package/dist/graph/graph.js.map +1 -0
  36. package/dist/graph/ids.d.ts +42 -0
  37. package/dist/graph/ids.js +104 -0
  38. package/dist/graph/ids.js.map +1 -0
  39. package/dist/graph/jsonl.d.ts +31 -0
  40. package/dist/graph/jsonl.js +121 -0
  41. package/dist/graph/jsonl.js.map +1 -0
  42. package/dist/graph/schema.d.ts +89 -0
  43. package/dist/graph/schema.js +73 -0
  44. package/dist/graph/schema.js.map +1 -0
  45. package/dist/index.d.ts +22 -0
  46. package/dist/index.js +22 -0
  47. package/dist/index.js.map +1 -0
  48. package/dist/install/claude.d.ts +37 -0
  49. package/dist/install/claude.js +104 -0
  50. package/dist/install/claude.js.map +1 -0
  51. package/dist/mcp/config.d.ts +20 -0
  52. package/dist/mcp/config.js +51 -0
  53. package/dist/mcp/config.js.map +1 -0
  54. package/dist/mcp/serve.d.ts +6 -0
  55. package/dist/mcp/serve.js +29 -0
  56. package/dist/mcp/serve.js.map +1 -0
  57. package/dist/mcp/server.d.ts +9 -0
  58. package/dist/mcp/server.js +248 -0
  59. package/dist/mcp/server.js.map +1 -0
  60. package/dist/query/brain.d.ts +21 -0
  61. package/dist/query/brain.js +51 -0
  62. package/dist/query/brain.js.map +1 -0
  63. package/dist/query/queries.d.ts +116 -0
  64. package/dist/query/queries.js +224 -0
  65. package/dist/query/queries.js.map +1 -0
  66. package/dist/query/search.d.ts +43 -0
  67. package/dist/query/search.js +329 -0
  68. package/dist/query/search.js.map +1 -0
  69. package/dist/scan/assemble.d.ts +20 -0
  70. package/dist/scan/assemble.js +255 -0
  71. package/dist/scan/assemble.js.map +1 -0
  72. package/dist/scan/discover.d.ts +21 -0
  73. package/dist/scan/discover.js +119 -0
  74. package/dist/scan/discover.js.map +1 -0
  75. package/dist/scan/extract.d.ts +3 -0
  76. package/dist/scan/extract.js +11 -0
  77. package/dist/scan/extract.js.map +1 -0
  78. package/dist/scan/extractors/python.d.ts +4 -0
  79. package/dist/scan/extractors/python.js +303 -0
  80. package/dist/scan/extractors/python.js.map +1 -0
  81. package/dist/scan/extractors/typescript.d.ts +6 -0
  82. package/dist/scan/extractors/typescript.js +509 -0
  83. package/dist/scan/extractors/typescript.js.map +1 -0
  84. package/dist/scan/git.d.ts +17 -0
  85. package/dist/scan/git.js +45 -0
  86. package/dist/scan/git.js.map +1 -0
  87. package/dist/scan/merge.d.ts +14 -0
  88. package/dist/scan/merge.js +57 -0
  89. package/dist/scan/merge.js.map +1 -0
  90. package/dist/scan/parser.d.ts +23 -0
  91. package/dist/scan/parser.js +57 -0
  92. package/dist/scan/parser.js.map +1 -0
  93. package/dist/scan/resolve.d.ts +23 -0
  94. package/dist/scan/resolve.js +131 -0
  95. package/dist/scan/resolve.js.map +1 -0
  96. package/dist/scan/scan.d.ts +41 -0
  97. package/dist/scan/scan.js +104 -0
  98. package/dist/scan/scan.js.map +1 -0
  99. package/dist/scan/types.d.ts +86 -0
  100. package/dist/scan/types.js +20 -0
  101. package/dist/scan/types.js.map +1 -0
  102. package/dist/sync/sync.d.ts +57 -0
  103. package/dist/sync/sync.js +192 -0
  104. package/dist/sync/sync.js.map +1 -0
  105. package/dist/version.d.ts +2 -0
  106. package/dist/version.js +5 -0
  107. package/dist/version.js.map +1 -0
  108. package/package.json +40 -6
  109. package/skills/neuroplex/SKILL.md +95 -0
  110. package/skills/neuroplex-update/SKILL.md +37 -0
  111. package/bin/neuroplex.js +0 -8
  112. package/index.js +0 -7
@@ -0,0 +1,192 @@
1
+ import { mkdir, open, readFile, rm, stat, writeFile } from 'node:fs/promises';
2
+ import { join, resolve } from 'node:path';
3
+ import { buildBrain } from '../brain/build.js';
4
+ import { LOCAL_DIR } from '../brain/local.js';
5
+ import { ConfigError, loadConfig } from '../config/config.js';
6
+ import { git } from '../scan/git.js';
7
+ import { scanProject } from '../scan/scan.js';
8
+ /**
9
+ * Auto-sync (docs/ARCHITECTURE.md §9): keeps a brain in step with the tracked
10
+ * branch of the source repository.
11
+ *
12
+ * - Works on a managed clone in `<brain>/.neuroplex/cache`, never on the user's
13
+ * working tree.
14
+ * - Updates the structural graph; AI knowledge on changed code is flagged stale
15
+ * (Neuroplex never calls an LLM by itself).
16
+ * - One writer at a time, through `<brain>/.neuroplex/sync.lock`.
17
+ */
18
+ export const CACHE_DIR = join(LOCAL_DIR, 'cache');
19
+ export const LOCK_FILE = join(LOCAL_DIR, 'sync.lock');
20
+ export const STATE_FILE = join(LOCAL_DIR, 'sync.json');
21
+ /** A lock older than this is assumed to belong to a crashed process. */
22
+ export const STALE_LOCK_MS = 30 * 60 * 1000;
23
+ export class SyncError extends Error {
24
+ name = 'SyncError';
25
+ }
26
+ export class SyncBusyError extends SyncError {
27
+ name = 'SyncBusyError';
28
+ }
29
+ /**
30
+ * Fetches the tracked branch and, if it moved, rescans the brain from it,
31
+ * rebuilds the brain files and commits/pushes them according to the config.
32
+ */
33
+ export async function syncOnce(brainDir, log = () => { }) {
34
+ const dir = resolve(brainDir);
35
+ const config = await loadConfig(dir);
36
+ const { remote, branch } = config.source;
37
+ if (!remote)
38
+ throw new ConfigError('Auto-sync needs source.remote in neuroplex.json (neuroplex config set source.remote <url>)');
39
+ const release = await acquireLock(dir);
40
+ const state = { ...(await readSyncState(dir)), lastCheck: new Date().toISOString() };
41
+ try {
42
+ const cache = join(dir, CACHE_DIR);
43
+ const head = await fetchBranch(cache, remote, branch);
44
+ const from = config.source.indexedCommit;
45
+ if (head === from) {
46
+ delete state.lastError;
47
+ return { changed: false, to: head };
48
+ }
49
+ log(`syncing ${branch} ${from?.slice(0, 7) ?? '(none)'} -> ${head.slice(0, 7)}`);
50
+ await mustGit(cache, 'checkout', '--force', '--detach', head);
51
+ await mustGit(cache, 'clean', '-fdx');
52
+ const projectDir = config.source.subdir ? join(cache, config.source.subdir) : cache;
53
+ const scan = await scanProject({ projectDir, brainDir: dir, recordSource: false });
54
+ const build = await buildBrain({ brainDir: dir, git: config.sync.autoCommit });
55
+ const result = { changed: true, to: head, stale: scan.semantic.stale };
56
+ if (from)
57
+ result.from = from;
58
+ if (build.commit)
59
+ result.commit = build.commit;
60
+ if (config.sync.autoCommit && build.gitNote && build.gitNote !== 'nothing to commit')
61
+ result.note = `commit: ${build.gitNote}`;
62
+ if (config.sync.autoPush && build.commit) {
63
+ const pushed = (await git(dir, 'push')) !== undefined;
64
+ result.pushed = pushed;
65
+ if (!pushed)
66
+ result.note = 'push failed (does the brain repository have an upstream remote?)';
67
+ }
68
+ state.lastChange = new Date().toISOString();
69
+ state.lastCommit = head;
70
+ delete state.lastError;
71
+ log(`synced to ${head.slice(0, 7)}: ${scan.graph.nodeCount} nodes, ${scan.semantic.stale} stale`);
72
+ return result;
73
+ }
74
+ catch (err) {
75
+ state.lastError = err.message;
76
+ throw err;
77
+ }
78
+ finally {
79
+ await writeSyncState(dir, state).catch(() => undefined);
80
+ await release();
81
+ }
82
+ }
83
+ /** Clones (first time) or fetches `branch` into the managed cache and returns its head commit. */
84
+ async function fetchBranch(cache, remote, branch) {
85
+ const isRepo = (await git(cache, 'rev-parse', '--is-inside-work-tree')) === 'true';
86
+ const root = isRepo ? await git(cache, 'rev-parse', '--show-toplevel') : undefined;
87
+ if (!isRepo || !root || resolve(root) !== resolve(cache)) {
88
+ await rm(cache, { recursive: true, force: true });
89
+ await mkdir(cache, { recursive: true });
90
+ await mustGit(cache, 'init', '-q');
91
+ await mustGit(cache, 'remote', 'add', 'origin', remote);
92
+ }
93
+ else {
94
+ await git(cache, 'remote', 'set-url', 'origin', remote);
95
+ }
96
+ await mustGit(cache, 'fetch', '--quiet', '--depth', '1', 'origin', `refs/heads/${branch}`);
97
+ const head = await git(cache, 'rev-parse', 'FETCH_HEAD');
98
+ if (!head)
99
+ throw new SyncError(`Could not read the head of ${branch} from ${remote}`);
100
+ return head;
101
+ }
102
+ async function mustGit(dir, ...args) {
103
+ const out = await git(dir, ...args);
104
+ if (out === undefined)
105
+ throw new SyncError(`git ${args.join(' ')} failed in ${dir}`);
106
+ return out;
107
+ }
108
+ // ── Lock ─────────────────────────────────────────────────────────────
109
+ /** Takes the sync lock or throws `SyncBusyError`. Returns the release function. */
110
+ export async function acquireLock(brainDir) {
111
+ const path = join(brainDir, LOCK_FILE);
112
+ await mkdir(join(brainDir, LOCAL_DIR), { recursive: true });
113
+ for (let attempt = 0; attempt < 2; attempt++) {
114
+ try {
115
+ const handle = await open(path, 'wx');
116
+ await handle.writeFile(JSON.stringify({ pid: process.pid, since: new Date().toISOString() }));
117
+ await handle.close();
118
+ return () => rm(path, { force: true });
119
+ }
120
+ catch (err) {
121
+ if (err.code !== 'EEXIST')
122
+ throw err;
123
+ const age = Date.now() - ((await stat(path).catch(() => undefined))?.mtimeMs ?? Date.now());
124
+ if (age < STALE_LOCK_MS)
125
+ throw new SyncBusyError('Another sync is already running for this brain');
126
+ await rm(path, { force: true }); // left behind by a crashed process
127
+ }
128
+ }
129
+ throw new SyncBusyError('Could not take the sync lock');
130
+ }
131
+ // ── State ────────────────────────────────────────────────────────────
132
+ export async function readSyncState(brainDir) {
133
+ try {
134
+ return JSON.parse(await readFile(join(brainDir, STATE_FILE), 'utf8'));
135
+ }
136
+ catch {
137
+ return {};
138
+ }
139
+ }
140
+ async function writeSyncState(brainDir, state) {
141
+ await mkdir(join(brainDir, LOCAL_DIR), { recursive: true });
142
+ await writeFile(join(brainDir, STATE_FILE), JSON.stringify(state, null, 2) + '\n', 'utf8');
143
+ }
144
+ /**
145
+ * Runs `syncOnce` now and then every `sync.intervalMinutes` (re-read from the
146
+ * config each time). Errors back off exponentially up to one hour; the MCP
147
+ * server keeps serving the last good brain meanwhile.
148
+ */
149
+ export function startAutoSync(brainDir, log) {
150
+ let timer;
151
+ let stopped = false;
152
+ let failures = 0;
153
+ const schedule = (ms) => {
154
+ if (stopped)
155
+ return;
156
+ timer = setTimeout(run, ms);
157
+ timer.unref(); // never keep the process alive just for syncing
158
+ };
159
+ const run = async () => {
160
+ let interval = 5;
161
+ try {
162
+ const config = await loadConfig(brainDir);
163
+ interval = config.sync.intervalMinutes;
164
+ if (!config.sync.autoSync) {
165
+ log('auto-sync disabled in neuroplex.json; stopping');
166
+ return;
167
+ }
168
+ await syncOnce(brainDir, log);
169
+ failures = 0;
170
+ }
171
+ catch (err) {
172
+ if (err instanceof SyncBusyError) {
173
+ log('another sync is running; will try again later');
174
+ }
175
+ else {
176
+ failures++;
177
+ log(`sync failed (${err.message}); retrying with backoff`);
178
+ }
179
+ }
180
+ const backoff = Math.min(60, interval * 2 ** failures);
181
+ schedule(backoff * 60 * 1000);
182
+ };
183
+ schedule(0);
184
+ return {
185
+ stop() {
186
+ stopped = true;
187
+ if (timer)
188
+ clearTimeout(timer);
189
+ },
190
+ };
191
+ }
192
+ //# sourceMappingURL=sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.js","sourceRoot":"","sources":["../../src/sync/sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C;;;;;;;;;GASG;AAEH,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AAClD,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;AACtD,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;AACvD,wEAAwE;AACxE,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAuB5C,MAAM,OAAO,SAAU,SAAQ,KAAK;IACzB,IAAI,GAAG,WAAW,CAAC;CAC7B;AAED,MAAM,OAAO,aAAc,SAAQ,SAAS;IACjC,IAAI,GAAG,eAAe,CAAC;CACjC;AAED;;;GAG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AC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,GAAG,YAAY,aAAa,EAAE,CAAC;gBACjC,GAAG,CAAC,+CAA+C,CAAC,CAAC;YACvD,CAAC;iBAAM,CAAC;gBACN,QAAQ,EAAE,CAAC;gBACX,GAAG,CAAC,gBAAiB,GAAa,CAAC,OAAO,0BAA0B,CAAC,CAAC;YACxE,CAAC;QACH,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,GAAG,CAAC,IAAI,QAAQ,CAAC,CAAC;QACvD,QAAQ,CAAC,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IAChC,CAAC,CAAC;IAEF,QAAQ,CAAC,CAAC,CAAC,CAAC;IACZ,OAAO;QACL,IAAI;YACF,OAAO,GAAG,IAAI,CAAC;YACf,IAAI,KAAK;gBAAE,YAAY,CAAC,KAAK,CAAC,CAAC;QACjC,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ /** The installed package version, read from package.json. */
2
+ export declare const VERSION: string;
@@ -0,0 +1,5 @@
1
+ import { createRequire } from 'node:module';
2
+ const require = createRequire(import.meta.url);
3
+ /** The installed package version, read from package.json. */
4
+ export const VERSION = require('../package.json').version;
5
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C,6DAA6D;AAC7D,MAAM,CAAC,MAAM,OAAO,GAAY,OAAO,CAAC,iBAAiB,CAAyB,CAAC,OAAO,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neuroplex",
3
- "version": "0.0.1",
3
+ "version": "0.2.0",
4
4
  "description": "A plug-and-play brain for your AI: turns any codebase into a knowledge graph served through a built-in MCP server. Work in progress.",
5
5
  "keywords": [
6
6
  "mcp",
@@ -22,15 +22,49 @@
22
22
  },
23
23
  "license": "MIT",
24
24
  "author": "Murillo Yamamoto",
25
- "main": "index.js",
25
+ "type": "module",
26
+ "main": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "import": "./dist/index.js"
32
+ },
33
+ "./package.json": "./package.json"
34
+ },
26
35
  "bin": {
27
- "neuroplex": "bin/neuroplex.js"
36
+ "neuroplex": "dist/cli/index.js"
28
37
  },
29
38
  "files": [
30
- "index.js",
31
- "bin/"
39
+ "dist/",
40
+ "skills/"
32
41
  ],
42
+ "scripts": {
43
+ "build": "tsc -p tsconfig.build.json",
44
+ "typecheck": "tsc -p tsconfig.json",
45
+ "test": "vitest run",
46
+ "test:watch": "vitest",
47
+ "schema": "tsx scripts/generate-schema.ts",
48
+ "check": "npm run typecheck && npm test && npm run build",
49
+ "prepublishOnly": "npm run check",
50
+ "prepack": "node scripts/copy-skills.mjs"
51
+ },
33
52
  "engines": {
34
- "node": ">=18"
53
+ "node": ">=20"
54
+ },
55
+ "dependencies": {
56
+ "@modelcontextprotocol/sdk": "^1.32.2",
57
+ "@vscode/tree-sitter-wasm": "^0.3.1",
58
+ "commander": "^15.1.0",
59
+ "ignore": "^7.0.17",
60
+ "picomatch": "^4.0.7",
61
+ "zod": "^4.6.7"
62
+ },
63
+ "devDependencies": {
64
+ "@types/node": "^22.20.7",
65
+ "@types/picomatch": "^4.0.3",
66
+ "tsx": "^4.23.15",
67
+ "typescript": "^7.0.2",
68
+ "vitest": "^5.1.2"
35
69
  }
36
70
  }
@@ -0,0 +1,95 @@
1
+ ---
2
+ name: neuroplex
3
+ description: Build a Neuroplex brain for the current project - a knowledge graph of its modules, files, symbols, concepts and flows, saved in a separate "<project>-brain" folder and served to AI assistants over MCP. Use when the user asks to map, index, or "build a brain" for a codebase, or runs /neuroplex.
4
+ ---
5
+
6
+ # Neuroplex: build the project's brain
7
+
8
+ You are building a **brain** for the project in the current working directory: a knowledge graph that future AI sessions can query through MCP instead of re-reading the code. The `neuroplex` CLI does the mechanical work (parsing, graph, files). **You** add the understanding: summaries, concepts and flows.
9
+
10
+ Work through the steps in order. Keep the user informed with one short line per step.
11
+
12
+ ## 0. Set up the CLI
13
+
14
+ Use the first that works and call it `$NP` below:
15
+
16
+ 1. `neuroplex --version` (installed globally)
17
+ 2. `npx -y neuroplex@latest --version`
18
+
19
+ The version must be **0.1.0 or newer**. If it is `0.0.1` (the placeholder), stop and tell the user Neuroplex isn't published yet and they should install it from the repository (`packages/npm`: `npm install && npm run build && npm link`).
20
+
21
+ ## 1. Decide where the brain goes
22
+
23
+ Default: a sibling folder named `<project-folder>-brain` (for example `../shop-brain`). If the user named a location, use it. If the folder already contains a `neuroplex.json`, this is an update: keep going, existing knowledge is preserved.
24
+
25
+ ## 2. Structural scan
26
+
27
+ ```bash
28
+ $NP scan . --brain <brain>
29
+ ```
30
+
31
+ This parses the code and writes the graph. Report the one-line summary it prints (files, nodes, edges). If it says the project has uncommitted changes, mention that they are included.
32
+
33
+ ## 3. Enrichment loop
34
+
35
+ Repeat until `phase` is `null`:
36
+
37
+ ```bash
38
+ $NP tasks --brain <brain> --limit 3
39
+ ```
40
+
41
+ The output is compact JSON: `phase`, `tasks`, `pending` (counts per phase), `sourcePath` (where the code lives) and `resultFormat`. (`--brief` prints just the task list if you want an overview first.) For **each task**:
42
+
43
+ 1. Read `instructions`, `targets` and `context`.
44
+ 2. **Read the actual source files** listed in the context (paths are relative to `sourcePath`). Never write summaries from names alone.
45
+ 3. Write the result JSON to a temporary file outside both the project and the brain, preferably with your file-writing tool (shell heredocs break on quotes), and submit it:
46
+
47
+ ```bash
48
+ $NP write <task-id> --brain <brain> --file <tmp>/result.json
49
+ ```
50
+
51
+ 4. Check the report: fix any `warnings` (usually a mistyped node ID) and cover anything listed in `missing` with another `write`.
52
+
53
+ **Fetch again after each batch** (`--limit 3`), don't fetch everything up front: tasks change as you work. For example, a parent module's task only appears once its submodules are summarized.
54
+
55
+ Phases run in order: **modules → project → concepts → flows**. A big module is split into parts (`module:src/x@1`, `@2`…), and the module itself is summarized in the last part.
56
+
57
+ ### Writing good knowledge
58
+
59
+ - **Every ID must be copied exactly** from the task (`symbol:src/auth/login.ts#login`, `module:src/auth`, `file:src/a.ts`).
60
+ - **Summaries** explain *what it does and why it exists*, plus anything non-obvious: side effects, important constraints, surprising behavior. Don't restate the name ("`parseConfig` parses the config" is useless). Length: symbols and files 1-2 sentences; modules 2-4 sentences; project 3-6 sentences. Write in English unless the user asks otherwise.
61
+ - **Notes** (markdown) are for modules and the project: responsibilities, how the parts fit together, key decisions, gotchas. Aim for 5-20 lines; skip boilerplate headings.
62
+ - **Tags**: optional, a few lowercase words that help search (`auth`, `persistence`, `cli`).
63
+ - **Concepts**: 5-15 *domain* ideas (what the software is about), not technical layers like "utils" or "tests". Members implement each concept, most important first, at most 15; they can be IDs, paths or unique symbol names.
64
+ - **Flows**: 3-10 end-to-end journeys (a user action, a request, a command). Steps are **symbols in execution order**, ideally starting at the trigger: CLI commands (`command:scan`), HTTP routes (`GET /users`) and MCP tools (`tool:search`) are symbols too. The suggested entry points and call trees are hints: callees appear in source order and calls on local variables are missing, so read the code to confirm. Don't invent steps that aren't in the graph.
65
+ - Stale nodes (`"stale": true`) have an outdated summary: compare it to the current code and rewrite it.
66
+
67
+ ### Large projects
68
+
69
+ Each task is sized to fit in context, but a big project can have hundreds. After the first ~20 module tasks, tell the user how many remain (`pending`) and ask whether to continue, stop here (the brain is already useful), or skip ahead with `$NP tasks --brain <brain> --phase project`, and then `concepts` and `flows`.
70
+
71
+ ## 4. Build the brain repository
72
+
73
+ ```bash
74
+ $NP build --brain <brain> --git
75
+ ```
76
+
77
+ This writes the README, the overview note and `.mcp.json`, and commits everything in the brain folder (its own git repository, separate from the project).
78
+
79
+ ## 5. Plug it in
80
+
81
+ Registering the MCP server changes the user's Claude Code configuration, so **ask first** and offer the two options:
82
+
83
+ - **Just me, every project** (default): `$NP connect --brain <brain>` (runs `claude mcp add --scope user`).
84
+ - **Everyone working on this project**: `$NP connect --brain <brain> --scope project` adds the server to the project's `.mcp.json`, which they can commit.
85
+
86
+ `--dry-run` shows what would happen without changing anything. If the `claude` CLI is not available (another assistant), show the printed command and the `.mcp.json` snippet instead. Once connected, any **new** session can call `overview`, `search`, `explain`, `impact` and `path` on this project.
87
+
88
+ ## 6. Wrap up
89
+
90
+ Tell the user in a few lines:
91
+
92
+ - where the brain is and what it contains: `$NP status --brain <brain>`;
93
+ - how to refresh it after code changes: run `/neuroplex-update`, or `$NP update` followed by the enrichment loop for stale nodes;
94
+ - that **auto-sync** can keep it current with `main` automatically while the MCP server runs (`$NP config set sync.autoSync true --brain <brain>`, off by default). Offer it, but don't turn it on without a yes;
95
+ - that pushing the brain to its own remote lets teammates use it too.
@@ -0,0 +1,37 @@
1
+ ---
2
+ name: neuroplex-update
3
+ description: Refresh an existing Neuroplex brain after the code changed - rescan the project, then rewrite only the stale or missing AI knowledge. Use when the user asks to update or refresh the brain, or runs /neuroplex-update.
4
+ ---
5
+
6
+ # Neuroplex: refresh the brain
7
+
8
+ The project already has a brain (a folder with `neuroplex.json`, by default `../<project-folder>-brain`). Bring it up to date with the current code, spending effort only where the code changed.
9
+
10
+ Use the same CLI as `/neuroplex` (`neuroplex`, or `npx -y neuroplex@latest`, version 0.1.0 or newer), called `$NP` below.
11
+
12
+ 1. **Check how far behind it is:**
13
+
14
+ ```bash
15
+ $NP status --brain <brain>
16
+ ```
17
+
18
+ If it is up to date and no tasks are pending, say so and stop.
19
+
20
+ 2. **Rescan:**
21
+
22
+ ```bash
23
+ $NP update --brain <brain>
24
+ ```
25
+
26
+ `update` rescans this machine's checkout of the project (uncommitted changes included) and rebuilds the brain files. Existing summaries, notes, concepts and flows are kept; nodes whose code changed are flagged `stale`, and new code shows up as missing summaries. To follow the remote's tracked branch instead (what auto-sync does), use `$NP sync --brain <brain>`.
27
+
28
+ 3. **Enrich only what changed:** run the loop from `/neuroplex` step 3 (`$NP tasks` → read the code → `$NP write`) until `phase` is `null`. Tasks only include stale or missing nodes, so this is usually short.
29
+ - If many modules changed, the concepts and flows may be outdated too. Offer to refresh them with `$NP tasks --brain <brain> --phase concepts` (and `--phase flows`). A result for those tasks replaces the old set.
30
+
31
+ 4. **Rebuild and commit:**
32
+
33
+ ```bash
34
+ $NP build --brain <brain> --git
35
+ ```
36
+
37
+ 5. **Report** in one or two lines: what changed (nodes added/removed, summaries rewritten) and the new indexed commit. A running `neuroplex serve` picks up the new brain automatically, so no restart is needed.
package/bin/neuroplex.js DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- const { version } = require('../package.json');
5
-
6
- console.log(`🧠 Neuroplex v${version}`);
7
- console.log('A plug-and-play brain for your AI. Work in progress, not usable yet.');
8
- console.log('Follow along: https://github.com/MurilloY/Neuroplex');
package/index.js DELETED
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- // Placeholder: Neuroplex is in early development.
4
- // See https://github.com/MurilloY/Neuroplex
5
- module.exports = {
6
- version: require('./package.json').version,
7
- };