gitnexus 1.4.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +194 -214
- package/dist/cli/ai-context.d.ts +1 -2
- package/dist/cli/ai-context.js +90 -117
- package/dist/cli/analyze.d.ts +0 -2
- package/dist/cli/analyze.js +2 -20
- package/dist/cli/index.js +25 -17
- package/dist/cli/setup.js +19 -17
- package/dist/core/augmentation/engine.js +20 -20
- package/dist/core/embeddings/embedding-pipeline.js +26 -26
- package/dist/core/graph/types.d.ts +2 -5
- package/dist/core/ingestion/ast-cache.js +2 -3
- package/dist/core/ingestion/call-processor.d.ts +5 -5
- package/dist/core/ingestion/call-processor.js +258 -173
- package/dist/core/ingestion/cluster-enricher.js +16 -16
- package/dist/core/ingestion/entry-point-scoring.d.ts +1 -2
- package/dist/core/ingestion/entry-point-scoring.js +22 -81
- package/dist/core/ingestion/framework-detection.d.ts +1 -5
- package/dist/core/ingestion/framework-detection.js +8 -39
- package/dist/core/ingestion/heritage-processor.d.ts +4 -13
- package/dist/core/ingestion/heritage-processor.js +28 -92
- package/dist/core/ingestion/import-processor.d.ts +19 -17
- package/dist/core/ingestion/import-processor.js +695 -170
- package/dist/core/ingestion/parsing-processor.d.ts +10 -1
- package/dist/core/ingestion/parsing-processor.js +177 -41
- package/dist/core/ingestion/pipeline.js +26 -49
- package/dist/core/ingestion/process-processor.js +1 -2
- package/dist/core/ingestion/symbol-table.d.ts +1 -12
- package/dist/core/ingestion/symbol-table.js +12 -19
- package/dist/core/ingestion/tree-sitter-queries.d.ts +11 -11
- package/dist/core/ingestion/tree-sitter-queries.js +485 -590
- package/dist/core/ingestion/utils.d.ts +0 -67
- package/dist/core/ingestion/utils.js +9 -692
- package/dist/core/ingestion/workers/parse-worker.d.ts +3 -20
- package/dist/core/ingestion/workers/parse-worker.js +345 -84
- package/dist/core/ingestion/workers/worker-pool.js +0 -8
- package/dist/core/kuzu/csv-generator.js +3 -19
- package/dist/core/kuzu/kuzu-adapter.js +19 -14
- package/dist/core/kuzu/schema.d.ts +3 -3
- package/dist/core/kuzu/schema.js +288 -303
- package/dist/core/search/bm25-index.js +6 -7
- package/dist/core/search/hybrid-search.js +3 -3
- package/dist/core/wiki/diagrams.d.ts +27 -0
- package/dist/core/wiki/diagrams.js +163 -0
- package/dist/core/wiki/generator.d.ts +50 -2
- package/dist/core/wiki/generator.js +548 -49
- package/dist/core/wiki/graph-queries.d.ts +42 -0
- package/dist/core/wiki/graph-queries.js +276 -97
- package/dist/core/wiki/html-viewer.js +192 -192
- package/dist/core/wiki/llm-client.js +73 -11
- package/dist/core/wiki/prompts.d.ts +52 -8
- package/dist/core/wiki/prompts.js +200 -86
- package/dist/mcp/core/kuzu-adapter.d.ts +3 -1
- package/dist/mcp/core/kuzu-adapter.js +44 -13
- package/dist/mcp/local/local-backend.js +128 -128
- package/dist/mcp/resources.js +42 -42
- package/dist/mcp/server.js +19 -18
- package/dist/mcp/tools.js +104 -103
- package/hooks/claude/gitnexus-hook.cjs +155 -238
- package/hooks/claude/pre-tool-use.sh +79 -79
- package/hooks/claude/session-start.sh +42 -42
- package/package.json +96 -96
- package/scripts/patch-tree-sitter-swift.cjs +74 -74
- package/skills/gitnexus-cli.md +82 -82
- package/skills/gitnexus-debugging.md +89 -89
- package/skills/gitnexus-exploring.md +78 -78
- package/skills/gitnexus-guide.md +64 -64
- package/skills/gitnexus-impact-analysis.md +97 -97
- package/skills/gitnexus-pr-review.md +163 -163
- package/skills/gitnexus-refactoring.md +121 -121
- package/vendor/leiden/index.cjs +355 -355
- package/vendor/leiden/utils.cjs +392 -392
- package/dist/cli/lazy-action.d.ts +0 -6
- package/dist/cli/lazy-action.js +0 -18
- package/dist/cli/skill-gen.d.ts +0 -26
- package/dist/cli/skill-gen.js +0 -549
- package/dist/core/ingestion/constants.d.ts +0 -16
- package/dist/core/ingestion/constants.js +0 -16
- package/dist/core/ingestion/export-detection.d.ts +0 -18
- package/dist/core/ingestion/export-detection.js +0 -230
- package/dist/core/ingestion/language-config.d.ts +0 -46
- package/dist/core/ingestion/language-config.js +0 -167
- package/dist/core/ingestion/mro-processor.d.ts +0 -45
- package/dist/core/ingestion/mro-processor.js +0 -369
- package/dist/core/ingestion/named-binding-extraction.d.ts +0 -61
- package/dist/core/ingestion/named-binding-extraction.js +0 -363
- package/dist/core/ingestion/resolvers/csharp.d.ts +0 -22
- package/dist/core/ingestion/resolvers/csharp.js +0 -109
- package/dist/core/ingestion/resolvers/go.d.ts +0 -19
- package/dist/core/ingestion/resolvers/go.js +0 -42
- package/dist/core/ingestion/resolvers/index.d.ts +0 -16
- package/dist/core/ingestion/resolvers/index.js +0 -11
- package/dist/core/ingestion/resolvers/jvm.d.ts +0 -23
- package/dist/core/ingestion/resolvers/jvm.js +0 -87
- package/dist/core/ingestion/resolvers/php.d.ts +0 -15
- package/dist/core/ingestion/resolvers/php.js +0 -35
- package/dist/core/ingestion/resolvers/rust.d.ts +0 -15
- package/dist/core/ingestion/resolvers/rust.js +0 -73
- package/dist/core/ingestion/resolvers/standard.d.ts +0 -28
- package/dist/core/ingestion/resolvers/standard.js +0 -145
- package/dist/core/ingestion/resolvers/utils.d.ts +0 -33
- package/dist/core/ingestion/resolvers/utils.js +0 -120
- package/dist/core/ingestion/symbol-resolver.d.ts +0 -32
- package/dist/core/ingestion/symbol-resolver.js +0 -83
- package/dist/core/ingestion/type-env.d.ts +0 -27
- package/dist/core/ingestion/type-env.js +0 -86
- package/dist/core/ingestion/type-extractors/c-cpp.d.ts +0 -2
- package/dist/core/ingestion/type-extractors/c-cpp.js +0 -60
- package/dist/core/ingestion/type-extractors/csharp.d.ts +0 -2
- package/dist/core/ingestion/type-extractors/csharp.js +0 -89
- package/dist/core/ingestion/type-extractors/go.d.ts +0 -2
- package/dist/core/ingestion/type-extractors/go.js +0 -105
- package/dist/core/ingestion/type-extractors/index.d.ts +0 -21
- package/dist/core/ingestion/type-extractors/index.js +0 -29
- package/dist/core/ingestion/type-extractors/jvm.d.ts +0 -3
- package/dist/core/ingestion/type-extractors/jvm.js +0 -121
- package/dist/core/ingestion/type-extractors/php.d.ts +0 -2
- package/dist/core/ingestion/type-extractors/php.js +0 -31
- package/dist/core/ingestion/type-extractors/python.d.ts +0 -2
- package/dist/core/ingestion/type-extractors/python.js +0 -41
- package/dist/core/ingestion/type-extractors/rust.d.ts +0 -2
- package/dist/core/ingestion/type-extractors/rust.js +0 -39
- package/dist/core/ingestion/type-extractors/shared.d.ts +0 -17
- package/dist/core/ingestion/type-extractors/shared.js +0 -97
- package/dist/core/ingestion/type-extractors/swift.d.ts +0 -2
- package/dist/core/ingestion/type-extractors/swift.js +0 -43
- package/dist/core/ingestion/type-extractors/types.d.ts +0 -14
- package/dist/core/ingestion/type-extractors/types.js +0 -1
- package/dist/core/ingestion/type-extractors/typescript.d.ts +0 -2
- package/dist/core/ingestion/type-extractors/typescript.js +0 -46
- package/dist/mcp/compatible-stdio-transport.d.ts +0 -25
- package/dist/mcp/compatible-stdio-transport.js +0 -200
|
@@ -4,14 +4,16 @@
|
|
|
4
4
|
* All prompts produce deterministic, source-grounded documentation.
|
|
5
5
|
* Templates use {{PLACEHOLDER}} substitution.
|
|
6
6
|
*/
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
14
|
-
export declare const
|
|
7
|
+
export declare const GROUPING_SYSTEM_PROMPT_LEGACY = "You are a documentation architect. Given a list of source files with their exported symbols, group them into logical documentation modules.\n\nRules:\n- Each module should represent a cohesive feature, layer, or domain\n- Every file must appear in exactly one module\n- Module names should be human-readable (e.g. \"Authentication\", \"Database Layer\", \"API Routes\")\n- Aim for 5-15 modules for a typical project. Fewer for small projects, more for large ones\n- Group by functionality, not by file type or directory structure alone\n- Do NOT create modules for tests, configs, or non-source files";
|
|
8
|
+
export declare const GROUPING_USER_PROMPT_LEGACY = "Group these source files into documentation modules.\n\n**Files and their exports:**\n{{FILE_LIST}}\n\n**Directory structure:**\n{{DIRECTORY_TREE}}\n\nRespond with ONLY a JSON object mapping module names to file path arrays. No markdown, no explanation.\nExample format:\n{\n \"Authentication\": [\"src/auth/login.ts\", \"src/auth/session.ts\"],\n \"Database\": [\"src/db/connection.ts\", \"src/db/models.ts\"]\n}";
|
|
9
|
+
export declare const GROUPING_SYSTEM_PROMPT = "You are a documentation architect. Given a list of source files with their exported symbols AND graph-detected community clusters, group them into logical documentation modules.\n\nRules:\n- Use the graph-detected communities as your PRIMARY signal for grouping\n- You may merge small communities, split large ones, or rename them for clarity\n- Every file must appear in exactly one module\n- Module names should be human-readable (e.g. \"Authentication\", \"Database Layer\", \"API Routes\")\n- Aim for 5-15 modules for a typical project. Fewer for small projects, more for large ones\n- Consider inter-community coupling and cross-community processes when deciding merges\n- Do NOT create modules for tests, configs, or non-source files";
|
|
10
|
+
export declare const GROUPING_USER_PROMPT = "Group these source files into documentation modules.\n\n**Graph-detected communities (primary signal):**\n{{COMMUNITY_GROUPS}}\n\n**Inter-community coupling:**\n{{INTER_COMMUNITY_EDGES}}\n\n**Cross-community execution flows:**\n{{CROSS_COMMUNITY_PROCESSES}}\n\n**Files and their exports (supplementary):**\n{{FILE_LIST}}\n\n**Directory structure (supplementary):**\n{{DIRECTORY_TREE}}\n\nRespond with ONLY a JSON object mapping module names to file path arrays. No markdown, no explanation.\nExample format:\n{\n \"Authentication\": [\"src/auth/login.ts\", \"src/auth/session.ts\"],\n \"Database\": [\"src/db/connection.ts\", \"src/db/models.ts\"]\n}";
|
|
11
|
+
export declare const MODULE_SYSTEM_PROMPT = "You are a technical documentation writer. Write clear, developer-focused documentation for a code module.\n\nRules:\n- Reference actual function names, class names, and code patterns \u2014 do NOT invent APIs\n- Use the call graph and execution flow data for accuracy, but do NOT mechanically list every edge\n- Include Mermaid diagrams only when they genuinely help understanding. Keep them small (5-10 nodes max)\n- Structure the document however makes sense for this module \u2014 there is no mandatory format\n- Write for a developer who needs to understand and contribute to this code\n- Begin with a concise overview (2-4 sentences summarizing purpose). Place <!-- summary-end --> after this opening section.\n- Graph-derived call graphs and workflow diagrams are appended automatically -- do NOT replicate them\n- You may include additional conceptual Mermaid diagrams when they genuinely help understanding\n- When referencing other modules, use ONLY exact slugs from the module registry. Format: [Name](slug.md)";
|
|
12
|
+
export declare const MODULE_USER_PROMPT = "Write documentation for the **{{MODULE_NAME}}** module.\n\n## Source Code\n\n{{SOURCE_CODE}}\n\n## Call Graph & Execution Flows (reference for accuracy)\n\nInternal calls: {{INTRA_CALLS}}\nOutgoing calls: {{OUTGOING_CALLS}}\nIncoming calls: {{INCOMING_CALLS}}\nExecution flows: {{PROCESSES}}\n\n## Other Modules (for cross-references)\n\n{{MODULE_REGISTRY}}\n\n---\n\nWrite comprehensive documentation for this module. Cover its purpose, how it works, its key components, and how it connects to the rest of the codebase. Use whatever structure best fits this module \u2014 you decide the sections and headings. Include a Mermaid diagram only if it genuinely clarifies the architecture.";
|
|
13
|
+
export declare const PARENT_SYSTEM_PROMPT = "You are a technical documentation writer. Write a summary page for a module that contains sub-modules. Synthesize the children's documentation \u2014 do not re-read source code.\n\nRules:\n- Reference actual components from the child modules\n- Focus on how the sub-modules work together, not repeating their individual docs\n- Keep it concise \u2014 the reader can click through to child pages for detail\n- Include a Mermaid diagram only if it genuinely clarifies how the sub-modules relate\n- Begin with a concise overview (2-4 sentences summarizing purpose). Place <!-- summary-end --> after this opening section.\n- Cross-child call graphs are appended automatically -- do NOT replicate them\n- You may include additional conceptual Mermaid diagrams when they genuinely help understanding\n- When referencing other modules, use ONLY exact slugs from the module registry. Format: [Name](slug.md)";
|
|
14
|
+
export declare const PARENT_USER_PROMPT = "Write documentation for the **{{MODULE_NAME}}** module, which contains these sub-modules:\n\n{{CHILDREN_DOCS}}\n\nCross-module calls: {{CROSS_MODULE_CALLS}}\nShared execution flows: {{CROSS_PROCESSES}}\n\n## Other Modules (for cross-references)\n\n{{MODULE_REGISTRY}}\n\n---\n\nWrite a concise overview of this module group. Explain its purpose, how the sub-modules fit together, and the key workflows that span them. Link to sub-module pages (e.g. `[Sub-module Name](sub-module-slug.md)`) rather than repeating their content. Use whatever structure fits best.";
|
|
15
|
+
export declare const OVERVIEW_SYSTEM_PROMPT = "You are a technical documentation writer. Write the top-level overview page for a repository wiki. This is the first page a new developer sees.\n\nRules:\n- Be clear and welcoming \u2014 this is the entry point to the entire codebase\n- Reference actual module names so readers can navigate to their docs\n- Include a high-level Mermaid architecture diagram showing only the most important modules and their relationships (max 10 nodes). A new dev should grasp it in 10 seconds\n- Do NOT create module index tables or list every module with descriptions \u2014 just link to module pages naturally within the text\n- Use the inter-module edges and execution flow data for accuracy, but do NOT dump them raw\n- An architecture diagram is appended automatically -- do NOT replicate it\n- You may include additional conceptual Mermaid diagrams when they genuinely help understanding\n- When linking to modules, use ONLY exact slugs from the module registry. Format: [Name](slug.md)";
|
|
16
|
+
export declare const OVERVIEW_USER_PROMPT = "Write the overview page for this repository's wiki.\n\n## Project Info\n\n{{PROJECT_INFO}}\n\n## Module Summaries\n\n{{MODULE_SUMMARIES}}\n\n## Reference Data (for accuracy \u2014 do not reproduce verbatim)\n\nInter-module call edges: {{MODULE_EDGES}}\nKey system flows: {{TOP_PROCESSES}}\n\n## Module Registry\n\n{{MODULE_REGISTRY}}\n\n---\n\nWrite a clear overview of this project: what it does, how it's architected, and the key end-to-end flows. Include a simple Mermaid architecture diagram (max 10 nodes, big-picture only). Link to module pages (e.g. `[Module Name](module-slug.md)`) naturally in the text rather than listing them in a table. If project config was provided, include brief setup instructions. Structure the page however reads best.";
|
|
15
17
|
/**
|
|
16
18
|
* Replace {{PLACEHOLDER}} tokens in a template string.
|
|
17
19
|
*/
|
|
@@ -51,3 +53,45 @@ export declare function formatProcesses(processes: Array<{
|
|
|
51
53
|
filePath: string;
|
|
52
54
|
}>;
|
|
53
55
|
}>): string;
|
|
56
|
+
/**
|
|
57
|
+
* Shorten a file path for readability.
|
|
58
|
+
*/
|
|
59
|
+
export declare function shortPath(fp: string): string;
|
|
60
|
+
/**
|
|
61
|
+
* Format community groups for the grouping prompt.
|
|
62
|
+
*/
|
|
63
|
+
export declare function formatCommunityGroups(groups: Array<{
|
|
64
|
+
label: string;
|
|
65
|
+
cohesion: number;
|
|
66
|
+
files: string[];
|
|
67
|
+
keywords: string[];
|
|
68
|
+
}>): string;
|
|
69
|
+
/**
|
|
70
|
+
* Format inter-community call edges for the grouping prompt.
|
|
71
|
+
*/
|
|
72
|
+
export declare function formatInterCommunityEdges(edges: Array<{
|
|
73
|
+
fromLabel: string;
|
|
74
|
+
toLabel: string;
|
|
75
|
+
callCount: number;
|
|
76
|
+
sampleCalls: Array<{
|
|
77
|
+
fromName: string;
|
|
78
|
+
toName: string;
|
|
79
|
+
}>;
|
|
80
|
+
}>): string;
|
|
81
|
+
/**
|
|
82
|
+
* Format cross-community processes for the grouping prompt.
|
|
83
|
+
*/
|
|
84
|
+
export declare function formatCrossCommunityProcesses(procs: Array<{
|
|
85
|
+
label: string;
|
|
86
|
+
communities: string[];
|
|
87
|
+
stepCount: number;
|
|
88
|
+
}>): string;
|
|
89
|
+
/**
|
|
90
|
+
* Format the module registry for injection into prompts.
|
|
91
|
+
* Shows all modules with their slugs and top symbols.
|
|
92
|
+
*/
|
|
93
|
+
export declare function formatModuleRegistry(registry: Map<string, {
|
|
94
|
+
name: string;
|
|
95
|
+
slug: string;
|
|
96
|
+
symbols: string[];
|
|
97
|
+
}>, currentSlug?: string): string;
|
|
@@ -5,98 +5,154 @@
|
|
|
5
5
|
* Templates use {{PLACEHOLDER}} substitution.
|
|
6
6
|
*/
|
|
7
7
|
// ─── Grouping Prompt ──────────────────────────────────────────────────
|
|
8
|
-
export const
|
|
9
|
-
|
|
10
|
-
Rules:
|
|
11
|
-
- Each module should represent a cohesive feature, layer, or domain
|
|
12
|
-
- Every file must appear in exactly one module
|
|
13
|
-
- Module names should be human-readable (e.g. "Authentication", "Database Layer", "API Routes")
|
|
14
|
-
- Aim for 5-15 modules for a typical project. Fewer for small projects, more for large ones
|
|
15
|
-
- Group by functionality, not by file type or directory structure alone
|
|
8
|
+
export const GROUPING_SYSTEM_PROMPT_LEGACY = `You are a documentation architect. Given a list of source files with their exported symbols, group them into logical documentation modules.
|
|
9
|
+
|
|
10
|
+
Rules:
|
|
11
|
+
- Each module should represent a cohesive feature, layer, or domain
|
|
12
|
+
- Every file must appear in exactly one module
|
|
13
|
+
- Module names should be human-readable (e.g. "Authentication", "Database Layer", "API Routes")
|
|
14
|
+
- Aim for 5-15 modules for a typical project. Fewer for small projects, more for large ones
|
|
15
|
+
- Group by functionality, not by file type or directory structure alone
|
|
16
16
|
- Do NOT create modules for tests, configs, or non-source files`;
|
|
17
|
-
export const
|
|
18
|
-
|
|
19
|
-
**Files and their exports:**
|
|
20
|
-
{{FILE_LIST}}
|
|
21
|
-
|
|
22
|
-
**Directory structure:**
|
|
23
|
-
{{DIRECTORY_TREE}}
|
|
24
|
-
|
|
25
|
-
Respond with ONLY a JSON object mapping module names to file path arrays. No markdown, no explanation.
|
|
26
|
-
Example format:
|
|
27
|
-
{
|
|
28
|
-
"Authentication": ["src/auth/login.ts", "src/auth/session.ts"],
|
|
29
|
-
"Database": ["src/db/connection.ts", "src/db/models.ts"]
|
|
17
|
+
export const GROUPING_USER_PROMPT_LEGACY = `Group these source files into documentation modules.
|
|
18
|
+
|
|
19
|
+
**Files and their exports:**
|
|
20
|
+
{{FILE_LIST}}
|
|
21
|
+
|
|
22
|
+
**Directory structure:**
|
|
23
|
+
{{DIRECTORY_TREE}}
|
|
24
|
+
|
|
25
|
+
Respond with ONLY a JSON object mapping module names to file path arrays. No markdown, no explanation.
|
|
26
|
+
Example format:
|
|
27
|
+
{
|
|
28
|
+
"Authentication": ["src/auth/login.ts", "src/auth/session.ts"],
|
|
29
|
+
"Database": ["src/db/connection.ts", "src/db/models.ts"]
|
|
30
|
+
}`;
|
|
31
|
+
export const GROUPING_SYSTEM_PROMPT = `You are a documentation architect. Given a list of source files with their exported symbols AND graph-detected community clusters, group them into logical documentation modules.
|
|
32
|
+
|
|
33
|
+
Rules:
|
|
34
|
+
- Use the graph-detected communities as your PRIMARY signal for grouping
|
|
35
|
+
- You may merge small communities, split large ones, or rename them for clarity
|
|
36
|
+
- Every file must appear in exactly one module
|
|
37
|
+
- Module names should be human-readable (e.g. "Authentication", "Database Layer", "API Routes")
|
|
38
|
+
- Aim for 5-15 modules for a typical project. Fewer for small projects, more for large ones
|
|
39
|
+
- Consider inter-community coupling and cross-community processes when deciding merges
|
|
40
|
+
- Do NOT create modules for tests, configs, or non-source files`;
|
|
41
|
+
export const GROUPING_USER_PROMPT = `Group these source files into documentation modules.
|
|
42
|
+
|
|
43
|
+
**Graph-detected communities (primary signal):**
|
|
44
|
+
{{COMMUNITY_GROUPS}}
|
|
45
|
+
|
|
46
|
+
**Inter-community coupling:**
|
|
47
|
+
{{INTER_COMMUNITY_EDGES}}
|
|
48
|
+
|
|
49
|
+
**Cross-community execution flows:**
|
|
50
|
+
{{CROSS_COMMUNITY_PROCESSES}}
|
|
51
|
+
|
|
52
|
+
**Files and their exports (supplementary):**
|
|
53
|
+
{{FILE_LIST}}
|
|
54
|
+
|
|
55
|
+
**Directory structure (supplementary):**
|
|
56
|
+
{{DIRECTORY_TREE}}
|
|
57
|
+
|
|
58
|
+
Respond with ONLY a JSON object mapping module names to file path arrays. No markdown, no explanation.
|
|
59
|
+
Example format:
|
|
60
|
+
{
|
|
61
|
+
"Authentication": ["src/auth/login.ts", "src/auth/session.ts"],
|
|
62
|
+
"Database": ["src/db/connection.ts", "src/db/models.ts"]
|
|
30
63
|
}`;
|
|
31
64
|
// ─── Leaf Module Prompt ───────────────────────────────────────────────
|
|
32
|
-
export const MODULE_SYSTEM_PROMPT = `You are a technical documentation writer. Write clear, developer-focused documentation for a code module.
|
|
33
|
-
|
|
34
|
-
Rules:
|
|
35
|
-
- Reference actual function names, class names, and code patterns — do NOT invent APIs
|
|
36
|
-
- Use the call graph and execution flow data for accuracy, but do NOT mechanically list every edge
|
|
37
|
-
- Include Mermaid diagrams only when they genuinely help understanding. Keep them small (5-10 nodes max)
|
|
38
|
-
- Structure the document however makes sense for this module — there is no mandatory format
|
|
39
|
-
- Write for a developer who needs to understand and contribute to this code
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
{{
|
|
45
|
-
|
|
46
|
-
##
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
65
|
+
export const MODULE_SYSTEM_PROMPT = `You are a technical documentation writer. Write clear, developer-focused documentation for a code module.
|
|
66
|
+
|
|
67
|
+
Rules:
|
|
68
|
+
- Reference actual function names, class names, and code patterns — do NOT invent APIs
|
|
69
|
+
- Use the call graph and execution flow data for accuracy, but do NOT mechanically list every edge
|
|
70
|
+
- Include Mermaid diagrams only when they genuinely help understanding. Keep them small (5-10 nodes max)
|
|
71
|
+
- Structure the document however makes sense for this module — there is no mandatory format
|
|
72
|
+
- Write for a developer who needs to understand and contribute to this code
|
|
73
|
+
- Begin with a concise overview (2-4 sentences summarizing purpose). Place <!-- summary-end --> after this opening section.
|
|
74
|
+
- Graph-derived call graphs and workflow diagrams are appended automatically -- do NOT replicate them
|
|
75
|
+
- You may include additional conceptual Mermaid diagrams when they genuinely help understanding
|
|
76
|
+
- When referencing other modules, use ONLY exact slugs from the module registry. Format: [Name](slug.md)`;
|
|
77
|
+
export const MODULE_USER_PROMPT = `Write documentation for the **{{MODULE_NAME}}** module.
|
|
78
|
+
|
|
79
|
+
## Source Code
|
|
80
|
+
|
|
81
|
+
{{SOURCE_CODE}}
|
|
82
|
+
|
|
83
|
+
## Call Graph & Execution Flows (reference for accuracy)
|
|
84
|
+
|
|
85
|
+
Internal calls: {{INTRA_CALLS}}
|
|
86
|
+
Outgoing calls: {{OUTGOING_CALLS}}
|
|
87
|
+
Incoming calls: {{INCOMING_CALLS}}
|
|
88
|
+
Execution flows: {{PROCESSES}}
|
|
89
|
+
|
|
90
|
+
## Other Modules (for cross-references)
|
|
91
|
+
|
|
92
|
+
{{MODULE_REGISTRY}}
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
55
96
|
Write comprehensive documentation for this module. Cover its purpose, how it works, its key components, and how it connects to the rest of the codebase. Use whatever structure best fits this module — you decide the sections and headings. Include a Mermaid diagram only if it genuinely clarifies the architecture.`;
|
|
56
97
|
// ─── Parent Module Prompt ─────────────────────────────────────────────
|
|
57
|
-
export const PARENT_SYSTEM_PROMPT = `You are a technical documentation writer. Write a summary page for a module that contains sub-modules. Synthesize the children's documentation — do not re-read source code.
|
|
58
|
-
|
|
59
|
-
Rules:
|
|
60
|
-
- Reference actual components from the child modules
|
|
61
|
-
- Focus on how the sub-modules work together, not repeating their individual docs
|
|
62
|
-
- Keep it concise — the reader can click through to child pages for detail
|
|
63
|
-
- Include a Mermaid diagram only if it genuinely clarifies how the sub-modules relate
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
98
|
+
export const PARENT_SYSTEM_PROMPT = `You are a technical documentation writer. Write a summary page for a module that contains sub-modules. Synthesize the children's documentation — do not re-read source code.
|
|
99
|
+
|
|
100
|
+
Rules:
|
|
101
|
+
- Reference actual components from the child modules
|
|
102
|
+
- Focus on how the sub-modules work together, not repeating their individual docs
|
|
103
|
+
- Keep it concise — the reader can click through to child pages for detail
|
|
104
|
+
- Include a Mermaid diagram only if it genuinely clarifies how the sub-modules relate
|
|
105
|
+
- Begin with a concise overview (2-4 sentences summarizing purpose). Place <!-- summary-end --> after this opening section.
|
|
106
|
+
- Cross-child call graphs are appended automatically -- do NOT replicate them
|
|
107
|
+
- You may include additional conceptual Mermaid diagrams when they genuinely help understanding
|
|
108
|
+
- When referencing other modules, use ONLY exact slugs from the module registry. Format: [Name](slug.md)`;
|
|
109
|
+
export const PARENT_USER_PROMPT = `Write documentation for the **{{MODULE_NAME}}** module, which contains these sub-modules:
|
|
110
|
+
|
|
111
|
+
{{CHILDREN_DOCS}}
|
|
112
|
+
|
|
113
|
+
Cross-module calls: {{CROSS_MODULE_CALLS}}
|
|
114
|
+
Shared execution flows: {{CROSS_PROCESSES}}
|
|
115
|
+
|
|
116
|
+
## Other Modules (for cross-references)
|
|
117
|
+
|
|
118
|
+
{{MODULE_REGISTRY}}
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
73
122
|
Write a concise overview of this module group. Explain its purpose, how the sub-modules fit together, and the key workflows that span them. Link to sub-module pages (e.g. \`[Sub-module Name](sub-module-slug.md)\`) rather than repeating their content. Use whatever structure fits best.`;
|
|
74
123
|
// ─── Overview Prompt ──────────────────────────────────────────────────
|
|
75
|
-
export const OVERVIEW_SYSTEM_PROMPT = `You are a technical documentation writer. Write the top-level overview page for a repository wiki. This is the first page a new developer sees.
|
|
76
|
-
|
|
77
|
-
Rules:
|
|
78
|
-
- Be clear and welcoming — this is the entry point to the entire codebase
|
|
79
|
-
- Reference actual module names so readers can navigate to their docs
|
|
80
|
-
- Include a high-level Mermaid architecture diagram showing only the most important modules and their relationships (max 10 nodes). A new dev should grasp it in 10 seconds
|
|
81
|
-
- Do NOT create module index tables or list every module with descriptions — just link to module pages naturally within the text
|
|
82
|
-
- Use the inter-module edges and execution flow data for accuracy, but do NOT dump them raw
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
124
|
+
export const OVERVIEW_SYSTEM_PROMPT = `You are a technical documentation writer. Write the top-level overview page for a repository wiki. This is the first page a new developer sees.
|
|
125
|
+
|
|
126
|
+
Rules:
|
|
127
|
+
- Be clear and welcoming — this is the entry point to the entire codebase
|
|
128
|
+
- Reference actual module names so readers can navigate to their docs
|
|
129
|
+
- Include a high-level Mermaid architecture diagram showing only the most important modules and their relationships (max 10 nodes). A new dev should grasp it in 10 seconds
|
|
130
|
+
- Do NOT create module index tables or list every module with descriptions — just link to module pages naturally within the text
|
|
131
|
+
- Use the inter-module edges and execution flow data for accuracy, but do NOT dump them raw
|
|
132
|
+
- An architecture diagram is appended automatically -- do NOT replicate it
|
|
133
|
+
- You may include additional conceptual Mermaid diagrams when they genuinely help understanding
|
|
134
|
+
- When linking to modules, use ONLY exact slugs from the module registry. Format: [Name](slug.md)`;
|
|
135
|
+
export const OVERVIEW_USER_PROMPT = `Write the overview page for this repository's wiki.
|
|
136
|
+
|
|
137
|
+
## Project Info
|
|
138
|
+
|
|
139
|
+
{{PROJECT_INFO}}
|
|
140
|
+
|
|
141
|
+
## Module Summaries
|
|
142
|
+
|
|
143
|
+
{{MODULE_SUMMARIES}}
|
|
144
|
+
|
|
145
|
+
## Reference Data (for accuracy — do not reproduce verbatim)
|
|
146
|
+
|
|
147
|
+
Inter-module call edges: {{MODULE_EDGES}}
|
|
148
|
+
Key system flows: {{TOP_PROCESSES}}
|
|
149
|
+
|
|
150
|
+
## Module Registry
|
|
151
|
+
|
|
152
|
+
{{MODULE_REGISTRY}}
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
100
156
|
Write a clear overview of this project: what it does, how it's architected, and the key end-to-end flows. Include a simple Mermaid architecture diagram (max 10 nodes, big-picture only). Link to module pages (e.g. \`[Module Name](module-slug.md)\`) naturally in the text rather than listing them in a table. If project config was provided, include brief setup instructions. Structure the page however reads best.`;
|
|
101
157
|
// ─── Template Substitution Helper ─────────────────────────────────────
|
|
102
158
|
/**
|
|
@@ -168,7 +224,65 @@ export function formatProcesses(processes) {
|
|
|
168
224
|
/**
|
|
169
225
|
* Shorten a file path for readability.
|
|
170
226
|
*/
|
|
171
|
-
function shortPath(fp) {
|
|
227
|
+
export function shortPath(fp) {
|
|
172
228
|
const parts = fp.replace(/\\/g, '/').split('/');
|
|
173
229
|
return parts.length > 3 ? parts.slice(-3).join('/') : fp;
|
|
174
230
|
}
|
|
231
|
+
// ─── Community Formatting Helpers ────────────────────────────────────
|
|
232
|
+
/**
|
|
233
|
+
* Format community groups for the grouping prompt.
|
|
234
|
+
*/
|
|
235
|
+
export function formatCommunityGroups(groups) {
|
|
236
|
+
if (groups.length === 0)
|
|
237
|
+
return 'No community data available.';
|
|
238
|
+
return groups
|
|
239
|
+
.map(g => {
|
|
240
|
+
const kwText = g.keywords.length > 0 ? ` Keywords: ${g.keywords.join(', ')}` : '';
|
|
241
|
+
const fileList = g.files.slice(0, 20).map(f => ` - ${f}`).join('\n');
|
|
242
|
+
const more = g.files.length > 20 ? `\n ... and ${g.files.length - 20} more files` : '';
|
|
243
|
+
return `**${g.label}** (cohesion: ${g.cohesion.toFixed(2)}, ${g.files.length} files)\n${kwText}\n${fileList}${more}`;
|
|
244
|
+
})
|
|
245
|
+
.join('\n\n');
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Format inter-community call edges for the grouping prompt.
|
|
249
|
+
*/
|
|
250
|
+
export function formatInterCommunityEdges(edges) {
|
|
251
|
+
if (edges.length === 0)
|
|
252
|
+
return 'No inter-community coupling detected.';
|
|
253
|
+
return edges
|
|
254
|
+
.slice(0, 20)
|
|
255
|
+
.map(e => {
|
|
256
|
+
const samples = e.sampleCalls.map(s => `${s.fromName} -> ${s.toName}`).join(', ');
|
|
257
|
+
return `${e.fromLabel} -> ${e.toLabel}: ${e.callCount} calls (${samples})`;
|
|
258
|
+
})
|
|
259
|
+
.join('\n');
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Format cross-community processes for the grouping prompt.
|
|
263
|
+
*/
|
|
264
|
+
export function formatCrossCommunityProcesses(procs) {
|
|
265
|
+
if (procs.length === 0)
|
|
266
|
+
return 'No cross-community execution flows detected.';
|
|
267
|
+
return procs
|
|
268
|
+
.map(p => `"${p.label}" spans: ${p.communities.join(', ')} (${p.stepCount} steps)`)
|
|
269
|
+
.join('\n');
|
|
270
|
+
}
|
|
271
|
+
// ─── Module Registry Helper ──────────────────────────────────────────
|
|
272
|
+
/**
|
|
273
|
+
* Format the module registry for injection into prompts.
|
|
274
|
+
* Shows all modules with their slugs and top symbols.
|
|
275
|
+
*/
|
|
276
|
+
export function formatModuleRegistry(registry, currentSlug) {
|
|
277
|
+
if (registry.size === 0)
|
|
278
|
+
return 'No module registry available.';
|
|
279
|
+
const lines = [];
|
|
280
|
+
for (const [, entry] of registry) {
|
|
281
|
+
if (entry.slug === currentSlug)
|
|
282
|
+
continue;
|
|
283
|
+
const symbols = entry.symbols.slice(0, 10).join(', ');
|
|
284
|
+
const symbolText = symbols ? ` — exports: ${symbols}` : '';
|
|
285
|
+
lines.push(`- [${entry.name}](${entry.slug}.md)${symbolText}`);
|
|
286
|
+
}
|
|
287
|
+
return lines.join('\n');
|
|
288
|
+
}
|
|
@@ -16,7 +16,9 @@
|
|
|
16
16
|
* Initialize (or reuse) a Database + connection pool for a specific repo.
|
|
17
17
|
* Retries on lock errors (e.g., when `gitnexus analyze` is running).
|
|
18
18
|
*/
|
|
19
|
-
export declare const initKuzu: (repoId: string, dbPath: string
|
|
19
|
+
export declare const initKuzu: (repoId: string, dbPath: string, opts?: {
|
|
20
|
+
pinned?: boolean;
|
|
21
|
+
}) => Promise<void>;
|
|
20
22
|
export declare const executeQuery: (repoId: string, cypher: string) => Promise<any[]>;
|
|
21
23
|
/**
|
|
22
24
|
* Execute a parameterized query on a specific repo's connection pool.
|
|
@@ -16,7 +16,7 @@ import fs from 'fs/promises';
|
|
|
16
16
|
import kuzu from 'kuzu';
|
|
17
17
|
const pool = new Map();
|
|
18
18
|
/** Max repos in the pool (LRU eviction) */
|
|
19
|
-
const MAX_POOL_SIZE =
|
|
19
|
+
const MAX_POOL_SIZE = 15;
|
|
20
20
|
/** Idle timeout before closing a repo's connections */
|
|
21
21
|
const IDLE_TIMEOUT_MS = 5 * 60 * 1000; // 5 minutes
|
|
22
22
|
/** Max connections per repo (caps concurrent queries per repo) */
|
|
@@ -36,7 +36,7 @@ function ensureIdleTimer() {
|
|
|
36
36
|
idleTimer = setInterval(() => {
|
|
37
37
|
const now = Date.now();
|
|
38
38
|
for (const [repoId, entry] of pool) {
|
|
39
|
-
if (now - entry.lastUsed > IDLE_TIMEOUT_MS && entry.checkedOut === 0) {
|
|
39
|
+
if (!entry.pinned && now - entry.lastUsed > IDLE_TIMEOUT_MS && entry.checkedOut === 0) {
|
|
40
40
|
closeOne(repoId);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -54,7 +54,7 @@ function evictLRU() {
|
|
|
54
54
|
let oldestId = null;
|
|
55
55
|
let oldestTime = Infinity;
|
|
56
56
|
for (const [id, entry] of pool) {
|
|
57
|
-
if (entry.checkedOut === 0 && entry.lastUsed < oldestTime) {
|
|
57
|
+
if (!entry.pinned && entry.checkedOut === 0 && entry.lastUsed < oldestTime) {
|
|
58
58
|
oldestTime = entry.lastUsed;
|
|
59
59
|
oldestId = id;
|
|
60
60
|
}
|
|
@@ -64,14 +64,26 @@ function evictLRU() {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* KuzuDB's native .closeSync() triggers N-API destructor hooks that
|
|
70
|
-
* segfault on Linux/macOS. Pool databases are opened read-only, so
|
|
71
|
-
* there is no WAL to flush — just deleting the pool entry and letting
|
|
72
|
-
* the GC (or process exit) reclaim native resources is safe.
|
|
67
|
+
* Close all connections for a repo and remove it from the pool
|
|
73
68
|
*/
|
|
74
69
|
function closeOne(repoId) {
|
|
70
|
+
const entry = pool.get(repoId);
|
|
71
|
+
if (!entry)
|
|
72
|
+
return;
|
|
73
|
+
for (const conn of entry.available) {
|
|
74
|
+
try {
|
|
75
|
+
conn.close();
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
console.error('GitNexus [pool:close-conn]:', e instanceof Error ? e.message : e);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
entry.db.close();
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
console.error('GitNexus [pool:close-db]:', e instanceof Error ? e.message : e);
|
|
86
|
+
}
|
|
75
87
|
pool.delete(repoId);
|
|
76
88
|
}
|
|
77
89
|
/**
|
|
@@ -98,6 +110,20 @@ function createConnection(db) {
|
|
|
98
110
|
restoreStdout();
|
|
99
111
|
}
|
|
100
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Load the FTS extension on a connection (best-effort, idempotent).
|
|
115
|
+
* Required before using QUERY_FTS_INDEX in search queries.
|
|
116
|
+
*/
|
|
117
|
+
async function loadFTSOnConnection(conn) {
|
|
118
|
+
try {
|
|
119
|
+
await conn.query('INSTALL fts');
|
|
120
|
+
}
|
|
121
|
+
catch { /* already installed */ }
|
|
122
|
+
try {
|
|
123
|
+
await conn.query('LOAD EXTENSION fts');
|
|
124
|
+
}
|
|
125
|
+
catch { /* already loaded or unavailable */ }
|
|
126
|
+
}
|
|
101
127
|
/** Query timeout in milliseconds */
|
|
102
128
|
const QUERY_TIMEOUT_MS = 30_000;
|
|
103
129
|
/** Waiter queue timeout in milliseconds */
|
|
@@ -108,7 +134,7 @@ const LOCK_RETRY_DELAY_MS = 2000;
|
|
|
108
134
|
* Initialize (or reuse) a Database + connection pool for a specific repo.
|
|
109
135
|
* Retries on lock errors (e.g., when `gitnexus analyze` is running).
|
|
110
136
|
*/
|
|
111
|
-
export const initKuzu = async (repoId, dbPath) => {
|
|
137
|
+
export const initKuzu = async (repoId, dbPath, opts) => {
|
|
112
138
|
const existing = pool.get(repoId);
|
|
113
139
|
if (existing) {
|
|
114
140
|
existing.lastUsed = Date.now();
|
|
@@ -136,9 +162,11 @@ export const initKuzu = async (repoId, dbPath) => {
|
|
|
136
162
|
// Pre-create a small pool of connections
|
|
137
163
|
const available = [];
|
|
138
164
|
for (let i = 0; i < INITIAL_CONNS_PER_REPO; i++) {
|
|
139
|
-
|
|
165
|
+
const conn = createConnection(db);
|
|
166
|
+
await loadFTSOnConnection(conn);
|
|
167
|
+
available.push(conn);
|
|
140
168
|
}
|
|
141
|
-
pool.set(repoId, { db, available, checkedOut: 0, waiters: [], lastUsed: Date.now(), dbPath });
|
|
169
|
+
pool.set(repoId, { db, available, checkedOut: 0, waiters: [], lastUsed: Date.now(), dbPath, pinned: !!opts?.pinned });
|
|
142
170
|
ensureIdleTimer();
|
|
143
171
|
return;
|
|
144
172
|
}
|
|
@@ -170,7 +198,10 @@ function checkout(entry) {
|
|
|
170
198
|
const totalConns = entry.available.length + entry.checkedOut;
|
|
171
199
|
if (totalConns < MAX_CONNS_PER_REPO) {
|
|
172
200
|
entry.checkedOut++;
|
|
173
|
-
|
|
201
|
+
const conn = createConnection(entry.db);
|
|
202
|
+
// Load FTS on new connections (best-effort, don't block on failure)
|
|
203
|
+
loadFTSOnConnection(conn).catch(() => { });
|
|
204
|
+
return Promise.resolve(conn);
|
|
174
205
|
}
|
|
175
206
|
// At capacity — queue the caller with a timeout.
|
|
176
207
|
return new Promise((resolve, reject) => {
|