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,57 @@
1
+ import { Graph } from '../graph/graph.js';
2
+ /** Node and edge types produced by the AI (enrichment), never by the scanner. */
3
+ const SEMANTIC_NODE_TYPES = new Set(['concept', 'flow']);
4
+ const SEMANTIC_EDGE_TYPES = new Set(['implements_concept', 'step_of', 'related_to']);
5
+ /** Tags the scanner manages; every other tag came from enrichment. */
6
+ const STRUCTURAL_TAGS = new Set(['exported']);
7
+ const hasSemantic = (node) => node.summary !== undefined ||
8
+ node.note !== undefined ||
9
+ node.provenance?.semantic !== undefined ||
10
+ (node.tags ?? []).some((t) => !STRUCTURAL_TAGS.has(t));
11
+ /**
12
+ * Combines a fresh structural graph with the previous brain:
13
+ *
14
+ * - structural nodes and edges always come from `fresh`;
15
+ * - semantic fields (summary, note, extra tags, semantic provenance) carry over
16
+ * to nodes that still exist, and are flagged `stale` when the node's hash changed;
17
+ * - concept/flow nodes and semantic edges are kept when their endpoints still exist.
18
+ */
19
+ export function mergeSemantic(previous, fresh) {
20
+ const graph = Graph.fromRecords(fresh.nodes(), fresh.edges());
21
+ let kept = 0;
22
+ let stale = 0;
23
+ for (const old of previous.nodes()) {
24
+ if (SEMANTIC_NODE_TYPES.has(old.type)) {
25
+ graph.upsertNode(old);
26
+ kept++;
27
+ continue;
28
+ }
29
+ const current = graph.getNode(old.id);
30
+ if (!current || !hasSemantic(old))
31
+ continue;
32
+ const changed = old.hash !== undefined && old.hash !== current.hash;
33
+ const isStale = old.stale || changed;
34
+ const tags = [...new Set([...(current.tags ?? []), ...(old.tags ?? []).filter((t) => !STRUCTURAL_TAGS.has(t))])];
35
+ const patch = { stale: isStale };
36
+ if (old.summary !== undefined)
37
+ patch.summary = old.summary;
38
+ if (old.note !== undefined)
39
+ patch.note = old.note;
40
+ if (tags.length)
41
+ patch.tags = tags;
42
+ if (old.provenance?.semantic !== undefined) {
43
+ patch.provenance = { ...current.provenance, semantic: old.provenance.semantic };
44
+ }
45
+ graph.updateNode(old.id, patch);
46
+ kept++;
47
+ if (isStale)
48
+ stale++;
49
+ }
50
+ for (const edge of previous.edges()) {
51
+ if (SEMANTIC_EDGE_TYPES.has(edge.type) && graph.hasNode(edge.from) && graph.hasNode(edge.to)) {
52
+ graph.addEdge(edge);
53
+ }
54
+ }
55
+ return { graph, kept, stale };
56
+ }
57
+ //# sourceMappingURL=merge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge.js","sourceRoot":"","sources":["../../src/scan/merge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG1C,iFAAiF;AACjF,MAAM,mBAAmB,GAA0B,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;AAChF,MAAM,mBAAmB,GAA0B,IAAI,GAAG,CAAC,CAAC,oBAAoB,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC;AAE5G,sEAAsE;AACtE,MAAM,e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IACH,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAChC,CAAC"}
@@ -0,0 +1,23 @@
1
+ import type * as TreeSitter from '@vscode/tree-sitter-wasm';
2
+ import type { ParsedLanguage } from './types.js';
3
+ /**
4
+ * Loads tree-sitter (WASM, no native build) and the grammars for each language.
5
+ * Grammars come pre-built from `@vscode/tree-sitter-wasm`, which also ships the
6
+ * matching runtime, so ABI versions always agree.
7
+ */
8
+ export type SyntaxNode = TreeSitter.Node;
9
+ export type SyntaxTree = TreeSitter.Tree;
10
+ /** Returns a cached parser for `lang`. */
11
+ export declare function getParser(lang: ParsedLanguage): Promise<TreeSitter.Parser>;
12
+ /**
13
+ * Parses `source` and passes the tree to `fn`, freeing the tree afterwards
14
+ * (WASM memory is not garbage-collected).
15
+ */
16
+ export declare function withTree<T>(source: string, lang: ParsedLanguage, fn: (root: SyntaxNode, tree: SyntaxTree) => T): Promise<T>;
17
+ /** Non-null named children of a node (the typings allow nulls). */
18
+ export declare function namedChildren(node: SyntaxNode): SyntaxNode[];
19
+ /** 1-based inclusive line range of a node. */
20
+ export declare function lineRange(node: SyntaxNode): {
21
+ start: number;
22
+ end: number;
23
+ };
@@ -0,0 +1,57 @@
1
+ import { createRequire } from 'node:module';
2
+ import { dirname, join } from 'node:path';
3
+ const require = createRequire(import.meta.url);
4
+ const ts = require('@vscode/tree-sitter-wasm');
5
+ const WASM_DIR = dirname(require.resolve('@vscode/tree-sitter-wasm'));
6
+ const GRAMMAR_FILES = {
7
+ typescript: 'tree-sitter-typescript.wasm',
8
+ tsx: 'tree-sitter-tsx.wasm',
9
+ javascript: 'tree-sitter-javascript.wasm',
10
+ python: 'tree-sitter-python.wasm',
11
+ };
12
+ let initPromise;
13
+ const parsers = new Map();
14
+ function init() {
15
+ initPromise ??= ts.Parser.init({ locateFile: (file) => join(WASM_DIR, file) });
16
+ return initPromise;
17
+ }
18
+ /** Returns a cached parser for `lang`. */
19
+ export function getParser(lang) {
20
+ let parser = parsers.get(lang);
21
+ if (!parser) {
22
+ parser = (async () => {
23
+ await init();
24
+ const language = await ts.Language.load(join(WASM_DIR, GRAMMAR_FILES[lang]));
25
+ const p = new ts.Parser();
26
+ p.setLanguage(language);
27
+ return p;
28
+ })();
29
+ parsers.set(lang, parser);
30
+ }
31
+ return parser;
32
+ }
33
+ /**
34
+ * Parses `source` and passes the tree to `fn`, freeing the tree afterwards
35
+ * (WASM memory is not garbage-collected).
36
+ */
37
+ export async function withTree(source, lang, fn) {
38
+ const parser = await getParser(lang);
39
+ const tree = parser.parse(source);
40
+ if (!tree)
41
+ throw new Error(`tree-sitter failed to parse ${lang} source`);
42
+ try {
43
+ return fn(tree.rootNode, tree);
44
+ }
45
+ finally {
46
+ tree.delete();
47
+ }
48
+ }
49
+ /** Non-null named children of a node (the typings allow nulls). */
50
+ export function namedChildren(node) {
51
+ return node.namedChildren.filter((c) => c !== null);
52
+ }
53
+ /** 1-based inclusive line range of a node. */
54
+ export function lineRange(node) {
55
+ return { start: node.startPosition.row + 1, end: node.endPosition.row + 1 };
56
+ }
57
+ //# sourceMappingURL=parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/scan/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAa1C,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,EAAE,GAAG,OAAO,CAAC,0BAA0B,CAAsB,CAAC;AACpE,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC,CAAC;AAEtE,MAAM,aAAa,GAAmC;IACpD,UAAU,EAAE,6BAA6B;IACzC,GAAG,EAAE,sBAAsB;IAC3B,UAAU,EAAE,6BAA6B;IAC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A+B,IAAI,SAAS,CAAC,CAAC;IACzE,IAAI,CAAC;QACH,OAAO,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;YAAS,CAAC;QACT,IAAI,CAAC,MAAM,EAAE,CAAC;IAChB,CAAC;AACH,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,aAAa,CAAC,IAAgB;IAC5C,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,EAAmB,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;AACvE,CAAC;AAED,8CAA8C;AAC9C,MAAM,UAAU,SAAS,CAAC,IAAgB;IACxC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,aAAa,CAAC,GAAG,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC;AAC9E,CAAC"}
@@ -0,0 +1,23 @@
1
+ import type { LanguageId } from './types.js';
2
+ /**
3
+ * Resolves import specifiers to project files or external packages.
4
+ *
5
+ * Resolution is static and heuristic (no tsconfig `paths`, no Python
6
+ * `sys.path` manipulation). Anything that can't be matched to a project
7
+ * file is treated as an external package; unresolvable relative imports
8
+ * are dropped.
9
+ */
10
+ export type ImportTarget = {
11
+ kind: 'file';
12
+ path: string;
13
+ } | {
14
+ kind: 'package';
15
+ name: string;
16
+ };
17
+ export declare class ImportResolver {
18
+ #private;
19
+ constructor(files: Iterable<string>);
20
+ resolve(fromPath: string, language: LanguageId, specifier: string): ImportTarget | undefined;
21
+ }
22
+ /** `react-dom/client` → `react-dom`, `@scope/pkg/sub` → `@scope/pkg`, `node:fs/promises` → `node:fs`. */
23
+ export declare function packageName(spec: string): string;
@@ -0,0 +1,131 @@
1
+ import { posix } from 'node:path';
2
+ const TS_EXTENSIONS = ['.ts', '.tsx', '.mts', '.cts', '.js', '.jsx', '.mjs', '.cjs'];
3
+ /** NodeNext-style `./x.js` imports that point at `./x.ts` sources. */
4
+ const JS_TO_TS = {
5
+ '.js': ['.ts', '.tsx'],
6
+ '.jsx': ['.tsx'],
7
+ '.mjs': ['.mts'],
8
+ '.cjs': ['.cts'],
9
+ };
10
+ /** Common aliases (`@/x`, `~/x`) usually point at `src/`. */
11
+ const ALIAS_ROOTS = ['src', ''];
12
+ export class ImportResolver {
13
+ #files;
14
+ /** Directories that contain an `__init__.py`. */
15
+ #pyPackages = new Set();
16
+ constructor(files) {
17
+ this.#files = new Set(files);
18
+ for (const f of this.#files) {
19
+ if (f === '__init__.py' || f.endsWith('/__init__.py')) {
20
+ this.#pyPackages.add(posix.dirname(f));
21
+ }
22
+ }
23
+ }
24
+ resolve(fromPath, language, specifier) {
25
+ return language === 'python'
26
+ ? this.#resolvePython(fromPath, specifier)
27
+ : this.#resolveScript(fromPath, specifier);
28
+ }
29
+ // ── TypeScript / JavaScript ────────────────────────────────────────────
30
+ #resolveScript(fromPath, spec) {
31
+ if (spec.startsWith('.')) {
32
+ const path = this.#scriptFile(posix.join(posix.dirname(fromPath), spec));
33
+ return path ? { kind: 'file', path } : undefined;
34
+ }
35
+ if (spec.startsWith('@/') || spec.startsWith('~/')) {
36
+ for (const root of ALIAS_ROOTS) {
37
+ const path = this.#scriptFile(posix.join(root, spec.slice(2)));
38
+ if (path)
39
+ return { kind: 'file', path };
40
+ }
41
+ return undefined;
42
+ }
43
+ if (spec.startsWith('/') || /^[a-z]+:\/\//i.test(spec))
44
+ return undefined;
45
+ return { kind: 'package', name: packageName(spec) };
46
+ }
47
+ #scriptFile(base) {
48
+ const b = posix.normalize(base);
49
+ if (b.startsWith('..'))
50
+ return undefined;
51
+ const ext = posix.extname(b);
52
+ const candidates = [b];
53
+ for (const ts of JS_TO_TS[ext] ?? [])
54
+ candidates.push(b.slice(0, -ext.length) + ts);
55
+ for (const e of TS_EXTENSIONS)
56
+ candidates.push(b + e);
57
+ for (const e of TS_EXTENSIONS)
58
+ candidates.push(`${b}/index${e}`);
59
+ return candidates.find((c) => this.#files.has(c));
60
+ }
61
+ // ── Python ─────────────────────────────────────────────────────────────
62
+ #resolvePython(fromPath, spec) {
63
+ const dots = spec.length - spec.replace(/^\.+/, '').length;
64
+ const rest = spec.slice(dots);
65
+ if (dots > 0) {
66
+ // `.` is the package containing this file; each extra dot goes one level up.
67
+ let base = posix.dirname(fromPath);
68
+ for (let i = 1; i < dots; i++)
69
+ base = base === '.' ? '..' : posix.dirname(base);
70
+ if (base.startsWith('..'))
71
+ return undefined;
72
+ const path = this.#pythonModule(base === '.' ? '' : base, rest);
73
+ return path ? { kind: 'file', path } : undefined;
74
+ }
75
+ const path = this.#pythonAbsolute(rest);
76
+ if (path)
77
+ return { kind: 'file', path };
78
+ return { kind: 'package', name: rest.split('.')[0] };
79
+ }
80
+ /** `a.b` → `a/b.py`, `a/b/__init__.py` (or `.pyi`), relative to `root`. */
81
+ #pythonModule(root, dotted) {
82
+ const rel = dotted ? dotted.split('.').join('/') : '';
83
+ const base = root && rel ? `${root}/${rel}` : root || rel;
84
+ const candidates = base
85
+ ? [`${base}.py`, `${base}.pyi`, `${base}/__init__.py`, `${base}/__init__.pyi`]
86
+ : ['__init__.py'];
87
+ return candidates.find((c) => this.#files.has(c));
88
+ }
89
+ /**
90
+ * Absolute imports are tried against every source root: the project root
91
+ * and any directory that is not itself a package (e.g. `src/`, `backend/`).
92
+ * The shortest match wins.
93
+ */
94
+ #pythonAbsolute(dotted) {
95
+ const direct = this.#pythonModule('', dotted);
96
+ if (direct)
97
+ return direct;
98
+ const first = dotted.split('.')[0];
99
+ let best;
100
+ for (const pkg of this.#pyPackages) {
101
+ // A top-level package named `first` that lives under a source root.
102
+ if (posix.basename(pkg) !== first)
103
+ continue;
104
+ const root = posix.dirname(pkg);
105
+ if (root === '.' || this.#pyPackages.has(root))
106
+ continue;
107
+ const path = this.#pythonModule(root, dotted);
108
+ if (path && (!best || path.length < best.length))
109
+ best = path;
110
+ }
111
+ if (best)
112
+ return best;
113
+ // Single-file modules next to each other in a non-package directory (scripts).
114
+ for (const f of this.#files) {
115
+ if (!f.endsWith(`/${dotted.split('.').join('/')}.py`))
116
+ continue;
117
+ const root = f.slice(0, -(dotted.length + 3) - 1);
118
+ if (!this.#pyPackages.has(root) && (!best || f.length < best.length))
119
+ best = f;
120
+ }
121
+ return best;
122
+ }
123
+ }
124
+ /** `react-dom/client` → `react-dom`, `@scope/pkg/sub` → `@scope/pkg`, `node:fs/promises` → `node:fs`. */
125
+ export function packageName(spec) {
126
+ const parts = spec.split('/');
127
+ if (spec.startsWith('@') && parts.length > 1)
128
+ return `${parts[0]}/${parts[1]}`;
129
+ return parts[0];
130
+ }
131
+ //# sourceMappingURL=resolve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/scan/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAgBlC,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACrF,sEAAsE;AACtE,MAAM,QAAQ,GAA6B;IACzC,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,CAAC,MAAM,CAAC;IAChB,MAAM,EAAE,CAAC,MAAM,CAAC;IAChB,MAAM,EAAE,CAAC,MAAM,CAAC;CACjB,CAAC;AACF,6DAA6D;AAC7D,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAEhC,MAAM,OAAO,cAAc;IAChB,MAAM,CAAsB;IACrC,iDAAiD;IACxC,WAAW,GAAG,IAAI,GAAG,EAAU,CAAC;IAEzC,YAAY,KAAuB;QACjC,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;QAC7B,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YA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IAAI,CAAC;QAEtB,+EAA+E;QAC/E,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAC5B,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;gBAAE,SAAS;YAChE,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAClD,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;gBAAE,IAAI,GAAG,CAAC,CAAC;QACjF,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,yGAAyG;AACzG,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IAC/E,OAAO,KAAK,CAAC,CAAC,CAAE,CAAC;AACnB,CAAC"}
@@ -0,0 +1,41 @@
1
+ import { type NeuroplexConfig } from '../config/config.js';
2
+ import type { Graph } from '../graph/graph.js';
3
+ import type { LanguageId } from './types.js';
4
+ export interface ScanOptions {
5
+ /** Source project to scan. */
6
+ projectDir: string;
7
+ /** Brain directory to write. Created if missing. */
8
+ brainDir: string;
9
+ /** Called after each file is parsed. */
10
+ onProgress?: (done: number, total: number, path: string) => void;
11
+ /**
12
+ * Remember `projectDir` as this machine's source checkout (default true).
13
+ * Auto-sync scans a managed clone instead and passes false.
14
+ */
15
+ recordSource?: boolean;
16
+ }
17
+ export interface ScanResult {
18
+ config: NeuroplexConfig;
19
+ graph: Graph;
20
+ files: number;
21
+ filesByLanguage: Partial<Record<LanguageId, number>>;
22
+ /** Files that could not be read or parsed. */
23
+ failed: {
24
+ path: string;
25
+ error: string;
26
+ }[];
27
+ /** Existing semantic data kept from the previous scan, and how much of it is now stale. */
28
+ semantic: {
29
+ kept: number;
30
+ stale: number;
31
+ };
32
+ /** The source working tree had uncommitted changes. */
33
+ dirty: boolean;
34
+ durationMs: number;
35
+ }
36
+ /**
37
+ * Structural scan (docs/ARCHITECTURE.md §4.2): discovers source files, parses
38
+ * them, assembles the graph, keeps semantic data from any previous scan, and
39
+ * writes `graph/` and `neuroplex.json` into the brain.
40
+ */
41
+ export declare function scanProject(options: ScanOptions): Promise<ScanResult>;
@@ -0,0 +1,104 @@
1
+ import { realpathSync } from 'node:fs';
2
+ import { readFile } from 'node:fs/promises';
3
+ import { basename, join, relative, resolve } from 'node:path';
4
+ import { CONFIG_FILE, createConfig, loadConfig, writeConfig, } from '../config/config.js';
5
+ import { writeLocalState } from '../brain/local.js';
6
+ import { readGraph, writeGraph } from '../graph/jsonl.js';
7
+ import { assembleGraph } from './assemble.js';
8
+ import { discoverFiles } from './discover.js';
9
+ import { extractSource } from './extract.js';
10
+ import { gitInfo } from './git.js';
11
+ import { mergeSemantic } from './merge.js';
12
+ /**
13
+ * Structural scan (docs/ARCHITECTURE.md §4.2): discovers source files, parses
14
+ * them, assembles the graph, keeps semantic data from any previous scan, and
15
+ * writes `graph/` and `neuroplex.json` into the brain.
16
+ */
17
+ export async function scanProject(options) {
18
+ const started = Date.now();
19
+ const projectDir = resolve(options.projectDir);
20
+ const brainDir = resolve(options.brainDir);
21
+ const git = await gitInfo(projectDir);
22
+ const recordSource = options.recordSource ?? true;
23
+ const config = await loadOrCreateConfig(brainDir, projectDir, git);
24
+ const discovered = await discoverFiles(projectDir, config.scan);
25
+ const scanned = [];
26
+ const failed = [];
27
+ const filesByLanguage = {};
28
+ for (const [i, file] of discovered.entries()) {
29
+ try {
30
+ const source = await readFile(join(projectDir, file.path), 'utf8');
31
+ const extraction = await extractSource(source, file.language);
32
+ scanned.push({ ...file, source, extraction });
33
+ filesByLanguage[file.language] = (filesByLanguage[file.language] ?? 0) + 1;
34
+ }
35
+ catch (err) {
36
+ failed.push({ path: file.path, error: err.message });
37
+ }
38
+ options.onProgress?.(i + 1, discovered.length, file.path);
39
+ }
40
+ const provenance = `scan@${git?.head?.slice(0, 7) ?? 'worktree'}`;
41
+ const fresh = assembleGraph(scanned, { projectName: config.source.name, provenance });
42
+ const previous = await readGraph(brainDir);
43
+ const { graph, kept, stale } = mergeSemantic(previous, fresh);
44
+ await writeGraph(brainDir, graph);
45
+ const next = { ...config, source: { ...config.source } };
46
+ if (git?.head)
47
+ next.source.indexedCommit = git.head;
48
+ else
49
+ delete next.source.indexedCommit;
50
+ if (recordSource) {
51
+ const subdir = subdirOf(git, projectDir);
52
+ if (subdir)
53
+ next.source.subdir = subdir;
54
+ else
55
+ delete next.source.subdir;
56
+ }
57
+ const saved = await writeConfig(brainDir, next);
58
+ if (recordSource)
59
+ await writeLocalState(brainDir, { sourcePath: projectDir });
60
+ return {
61
+ config: saved,
62
+ graph,
63
+ files: scanned.length,
64
+ filesByLanguage,
65
+ failed,
66
+ semantic: { kept, stale },
67
+ dirty: git?.dirty ?? false,
68
+ durationMs: Date.now() - started,
69
+ };
70
+ }
71
+ async function loadOrCreateConfig(brainDir, projectDir, git) {
72
+ try {
73
+ return await loadConfig(brainDir);
74
+ }
75
+ catch (err) {
76
+ if (!err.message.startsWith(`No ${CONFIG_FILE}`))
77
+ throw err;
78
+ }
79
+ // Track the remote's default branch (usually main), not whatever feature branch is checked out.
80
+ const source = {
81
+ name: basename(projectDir),
82
+ branch: git?.defaultBranch ?? git?.branch ?? 'main',
83
+ };
84
+ if (git?.remote)
85
+ source.remote = git.remote;
86
+ return createConfig({ source });
87
+ }
88
+ /** Project folder relative to its repository root, or undefined when it is the root. */
89
+ function subdirOf(git, projectDir) {
90
+ if (!git)
91
+ return undefined;
92
+ // realpath expands Windows 8.3 short names (C:\Users\RUNNER~1), which git never returns.
93
+ const real = (p) => {
94
+ try {
95
+ return realpathSync.native(p);
96
+ }
97
+ catch {
98
+ return resolve(p);
99
+ }
100
+ };
101
+ const rel = relative(real(git.root), real(projectDir)).replace(/\\/g, '/');
102
+ return rel && !rel.startsWith('..') ? rel : undefined;
103
+ }
104
+ //# sourceMappingURL=scan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scan.js","sourceRoot":"","sources":["../../src/scan/scan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,EACL,WAAW,EACX,YAAY,EACZ,UAAU,EACV,WAAW,GAEZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAoB,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AA+B3C;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,OAAoB;IACpD,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC3B,MAAM,UAAU,GAAG,OAAO,CAAC,OA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AM,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC3E,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;AACxD,CAAC"}
@@ -0,0 +1,86 @@
1
+ import type { SymbolKind } from '../graph/schema.js';
2
+ /**
3
+ * Contract between language extractors and the graph assembler.
4
+ *
5
+ * Extractors are pure: they read one parsed file and report what they see,
6
+ * using names exactly as written in the source. They never resolve imports
7
+ * or touch the graph; `assemble.ts` does all cross-file resolution.
8
+ */
9
+ /**
10
+ * Languages Neuroplex reads. Every one except `markdown` is parsed with a
11
+ * tree-sitter grammar; markdown files become file nodes (for docs such as the
12
+ * README) without symbols.
13
+ */
14
+ export declare const LANGUAGE_IDS: readonly ['typescript', 'tsx', 'javascript', 'python', 'markdown'];
15
+ export type LanguageId = (typeof LANGUAGE_IDS)[number];
16
+ /** Languages with a tree-sitter grammar. */
17
+ export type ParsedLanguage = Exclude<LanguageId, 'markdown'>;
18
+ /** A 1-based, inclusive line range. */
19
+ export interface LineRange {
20
+ start: number;
21
+ end: number;
22
+ }
23
+ export interface ExtractedSymbol {
24
+ /**
25
+ * Qualified name inside the file, unique per file:
26
+ * `login`, `Session`, `Session.refresh`. Nested functions are not reported.
27
+ */
28
+ name: string;
29
+ kind: SymbolKind;
30
+ range: LineRange;
31
+ /** True when visible to other files (TS/JS `export`; Python: not `_`-prefixed at module level). */
32
+ exported: boolean;
33
+ }
34
+ /** One name brought into scope by an import. */
35
+ export interface ImportBinding {
36
+ /** Name used inside this file. */
37
+ local: string;
38
+ /**
39
+ * Name in the target module:
40
+ * - an exported name (`foo` in `import { foo as bar }`, `from x import foo`);
41
+ * - `default` for default imports;
42
+ * - `*` for namespace/module imports (`import * as x`, `import x` in Python).
43
+ */
44
+ imported: string;
45
+ }
46
+ export interface ExtractedImport {
47
+ /**
48
+ * Module specifier exactly as written:
49
+ * TS/JS: `./util.js`, `../a`, `react`, `@scope/pkg/sub`, `node:fs`;
50
+ * Python: `os.path`, `.models`, `..core.db`, `.` (for `from . import x`).
51
+ */
52
+ specifier: string;
53
+ bindings: ImportBinding[];
54
+ line: number;
55
+ /** `import type …` / `export type … from` (TS only). */
56
+ typeOnly?: boolean;
57
+ /** `export … from '…'` re-exports (TS/JS only). */
58
+ reexport?: boolean;
59
+ }
60
+ export interface ExtractedCall {
61
+ /** Qualified name of the enclosing symbol (`login`, `Session.refresh`). Calls at module top level are skipped. */
62
+ caller: string;
63
+ /** Called name: `foo` in `foo()`, `bar` in `obj.bar()`, `Foo` in `new Foo()`. */
64
+ callee: string;
65
+ /**
66
+ * Receiver for member calls, as written, only when it is a plain identifier,
67
+ * `this` or `self`: `this.save()` → `this`, `utils.parse()` → `utils`.
68
+ * Omitted for plain calls; calls on complex receivers (`a.b.c()`, `f().g()`) are skipped.
69
+ */
70
+ object?: string;
71
+ line: number;
72
+ }
73
+ export interface ExtractedHeritage {
74
+ /** Qualified name of the class or interface declaring the relationship. */
75
+ symbol: string;
76
+ relation: 'extends' | 'implements';
77
+ /** Base name as written, possibly dotted: `Base`, `models.Model`. Generic arguments are dropped. */
78
+ target: string;
79
+ }
80
+ export interface FileExtraction {
81
+ symbols: ExtractedSymbol[];
82
+ imports: ExtractedImport[];
83
+ calls: ExtractedCall[];
84
+ heritage: ExtractedHeritage[];
85
+ }
86
+ export declare const emptyExtraction: () => FileExtraction;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Contract between language extractors and the graph assembler.
3
+ *
4
+ * Extractors are pure: they read one parsed file and report what they see,
5
+ * using names exactly as written in the source. They never resolve imports
6
+ * or touch the graph; `assemble.ts` does all cross-file resolution.
7
+ */
8
+ /**
9
+ * Languages Neuroplex reads. Every one except `markdown` is parsed with a
10
+ * tree-sitter grammar; markdown files become file nodes (for docs such as the
11
+ * README) without symbols.
12
+ */
13
+ export const LANGUAGE_IDS = ['typescript', 'tsx', 'javascript', 'python', 'markdown'];
14
+ export const emptyExtraction = () => ({
15
+ symbols: [],
16
+ imports: [],
17
+ calls: [],
18
+ heritage: [],
19
+ });
20
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/scan/types.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,CAAU,CAAC;AAgF/F,MAAM,CAAC,MAAM,eAAe,GAAG,GAAmB,EAAE,CAAC,CAAC;IACpD,OAAO,EAAE,EAAE;IACX,OAAO,EAAE,EAAE;IACX,KAAK,EAAE,EAAE;IACT,QAAQ,EAAE,EAAE;CACb,CAAC,CAAC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Auto-sync (docs/ARCHITECTURE.md §9): keeps a brain in step with the tracked
3
+ * branch of the source repository.
4
+ *
5
+ * - Works on a managed clone in `<brain>/.neuroplex/cache`, never on the user's
6
+ * working tree.
7
+ * - Updates the structural graph; AI knowledge on changed code is flagged stale
8
+ * (Neuroplex never calls an LLM by itself).
9
+ * - One writer at a time, through `<brain>/.neuroplex/sync.lock`.
10
+ */
11
+ export declare const CACHE_DIR: string;
12
+ export declare const LOCK_FILE: string;
13
+ export declare const STATE_FILE: string;
14
+ /** A lock older than this is assumed to belong to a crashed process. */
15
+ export declare const STALE_LOCK_MS: number;
16
+ export interface SyncResult {
17
+ /** The tracked branch had new commits and the brain was updated. */
18
+ changed: boolean;
19
+ from?: string;
20
+ to?: string;
21
+ /** Nodes whose AI knowledge became stale in this sync. */
22
+ stale?: number;
23
+ /** Commit created in the brain repository. */
24
+ commit?: string;
25
+ pushed?: boolean;
26
+ /** Something worth telling the user that did not fail the sync (e.g. push failed). */
27
+ note?: string;
28
+ }
29
+ export interface SyncState {
30
+ lastCheck?: string;
31
+ lastChange?: string;
32
+ lastCommit?: string;
33
+ lastError?: string;
34
+ }
35
+ export declare class SyncError extends Error {
36
+ name: string;
37
+ }
38
+ export declare class SyncBusyError extends SyncError {
39
+ name: string;
40
+ }
41
+ /**
42
+ * Fetches the tracked branch and, if it moved, rescans the brain from it,
43
+ * rebuilds the brain files and commits/pushes them according to the config.
44
+ */
45
+ export declare function syncOnce(brainDir: string, log?: (msg: string) => void): Promise<SyncResult>;
46
+ /** Takes the sync lock or throws `SyncBusyError`. Returns the release function. */
47
+ export declare function acquireLock(brainDir: string): Promise<() => Promise<void>>;
48
+ export declare function readSyncState(brainDir: string): Promise<SyncState>;
49
+ export interface AutoSync {
50
+ stop(): void;
51
+ }
52
+ /**
53
+ * Runs `syncOnce` now and then every `sync.intervalMinutes` (re-read from the
54
+ * config each time). Errors back off exponentially up to one hour; the MCP
55
+ * server keeps serving the last good brain meanwhile.
56
+ */
57
+ export declare function startAutoSync(brainDir: string, log: (msg: string) => void): AutoSync;