gitnexus 1.4.1 → 1.4.5

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 (169) hide show
  1. package/README.md +215 -194
  2. package/dist/cli/ai-context.d.ts +2 -1
  3. package/dist/cli/ai-context.js +117 -90
  4. package/dist/cli/analyze.d.ts +2 -0
  5. package/dist/cli/analyze.js +57 -30
  6. package/dist/cli/augment.js +1 -1
  7. package/dist/cli/eval-server.d.ts +1 -1
  8. package/dist/cli/eval-server.js +1 -1
  9. package/dist/cli/index.js +18 -25
  10. package/dist/cli/lazy-action.d.ts +6 -0
  11. package/dist/cli/lazy-action.js +18 -0
  12. package/dist/cli/mcp.js +1 -1
  13. package/dist/cli/setup.js +42 -32
  14. package/dist/cli/skill-gen.d.ts +26 -0
  15. package/dist/cli/skill-gen.js +549 -0
  16. package/dist/cli/status.js +13 -4
  17. package/dist/cli/tool.d.ts +1 -1
  18. package/dist/cli/tool.js +2 -2
  19. package/dist/cli/wiki.js +2 -2
  20. package/dist/config/ignore-service.d.ts +25 -0
  21. package/dist/config/ignore-service.js +76 -0
  22. package/dist/config/supported-languages.d.ts +1 -0
  23. package/dist/config/supported-languages.js +1 -1
  24. package/dist/core/augmentation/engine.js +99 -72
  25. package/dist/core/embeddings/embedder.d.ts +1 -1
  26. package/dist/core/embeddings/embedder.js +1 -1
  27. package/dist/core/embeddings/embedding-pipeline.d.ts +3 -3
  28. package/dist/core/embeddings/embedding-pipeline.js +74 -47
  29. package/dist/core/embeddings/types.d.ts +1 -1
  30. package/dist/core/graph/types.d.ts +5 -2
  31. package/dist/core/ingestion/ast-cache.js +3 -2
  32. package/dist/core/ingestion/call-processor.d.ts +6 -7
  33. package/dist/core/ingestion/call-processor.js +560 -282
  34. package/dist/core/ingestion/call-routing.d.ts +53 -0
  35. package/dist/core/ingestion/call-routing.js +108 -0
  36. package/dist/core/ingestion/cluster-enricher.js +16 -16
  37. package/dist/core/ingestion/constants.d.ts +16 -0
  38. package/dist/core/ingestion/constants.js +16 -0
  39. package/dist/core/ingestion/entry-point-scoring.d.ts +2 -1
  40. package/dist/core/ingestion/entry-point-scoring.js +94 -24
  41. package/dist/core/ingestion/export-detection.d.ts +18 -0
  42. package/dist/core/ingestion/export-detection.js +231 -0
  43. package/dist/core/ingestion/filesystem-walker.js +4 -3
  44. package/dist/core/ingestion/framework-detection.d.ts +5 -1
  45. package/dist/core/ingestion/framework-detection.js +48 -8
  46. package/dist/core/ingestion/heritage-processor.d.ts +13 -5
  47. package/dist/core/ingestion/heritage-processor.js +109 -55
  48. package/dist/core/ingestion/import-processor.d.ts +16 -20
  49. package/dist/core/ingestion/import-processor.js +202 -696
  50. package/dist/core/ingestion/language-config.d.ts +46 -0
  51. package/dist/core/ingestion/language-config.js +167 -0
  52. package/dist/core/ingestion/mro-processor.d.ts +45 -0
  53. package/dist/core/ingestion/mro-processor.js +369 -0
  54. package/dist/core/ingestion/named-binding-extraction.d.ts +61 -0
  55. package/dist/core/ingestion/named-binding-extraction.js +363 -0
  56. package/dist/core/ingestion/parsing-processor.d.ts +3 -11
  57. package/dist/core/ingestion/parsing-processor.js +82 -181
  58. package/dist/core/ingestion/pipeline.d.ts +5 -1
  59. package/dist/core/ingestion/pipeline.js +192 -116
  60. package/dist/core/ingestion/process-processor.js +2 -1
  61. package/dist/core/ingestion/resolution-context.d.ts +53 -0
  62. package/dist/core/ingestion/resolution-context.js +132 -0
  63. package/dist/core/ingestion/resolvers/csharp.d.ts +22 -0
  64. package/dist/core/ingestion/resolvers/csharp.js +109 -0
  65. package/dist/core/ingestion/resolvers/go.d.ts +19 -0
  66. package/dist/core/ingestion/resolvers/go.js +42 -0
  67. package/dist/core/ingestion/resolvers/index.d.ts +18 -0
  68. package/dist/core/ingestion/resolvers/index.js +13 -0
  69. package/dist/core/ingestion/resolvers/jvm.d.ts +23 -0
  70. package/dist/core/ingestion/resolvers/jvm.js +87 -0
  71. package/dist/core/ingestion/resolvers/php.d.ts +15 -0
  72. package/dist/core/ingestion/resolvers/php.js +35 -0
  73. package/dist/core/ingestion/resolvers/python.d.ts +19 -0
  74. package/dist/core/ingestion/resolvers/python.js +52 -0
  75. package/dist/core/ingestion/resolvers/ruby.d.ts +12 -0
  76. package/dist/core/ingestion/resolvers/ruby.js +15 -0
  77. package/dist/core/ingestion/resolvers/rust.d.ts +15 -0
  78. package/dist/core/ingestion/resolvers/rust.js +73 -0
  79. package/dist/core/ingestion/resolvers/standard.d.ts +28 -0
  80. package/dist/core/ingestion/resolvers/standard.js +123 -0
  81. package/dist/core/ingestion/resolvers/utils.d.ts +33 -0
  82. package/dist/core/ingestion/resolvers/utils.js +122 -0
  83. package/dist/core/ingestion/symbol-table.d.ts +15 -1
  84. package/dist/core/ingestion/symbol-table.js +20 -12
  85. package/dist/core/ingestion/tree-sitter-queries.d.ts +12 -11
  86. package/dist/core/ingestion/tree-sitter-queries.js +642 -485
  87. package/dist/core/ingestion/type-env.d.ts +49 -0
  88. package/dist/core/ingestion/type-env.js +559 -0
  89. package/dist/core/ingestion/type-extractors/c-cpp.d.ts +2 -0
  90. package/dist/core/ingestion/type-extractors/c-cpp.js +385 -0
  91. package/dist/core/ingestion/type-extractors/csharp.d.ts +2 -0
  92. package/dist/core/ingestion/type-extractors/csharp.js +369 -0
  93. package/dist/core/ingestion/type-extractors/go.d.ts +2 -0
  94. package/dist/core/ingestion/type-extractors/go.js +436 -0
  95. package/dist/core/ingestion/type-extractors/index.d.ts +22 -0
  96. package/dist/core/ingestion/type-extractors/index.js +31 -0
  97. package/dist/core/ingestion/type-extractors/jvm.d.ts +3 -0
  98. package/dist/core/ingestion/type-extractors/jvm.js +654 -0
  99. package/dist/core/ingestion/type-extractors/php.d.ts +2 -0
  100. package/dist/core/ingestion/type-extractors/php.js +411 -0
  101. package/dist/core/ingestion/type-extractors/python.d.ts +2 -0
  102. package/dist/core/ingestion/type-extractors/python.js +392 -0
  103. package/dist/core/ingestion/type-extractors/ruby.d.ts +2 -0
  104. package/dist/core/ingestion/type-extractors/ruby.js +389 -0
  105. package/dist/core/ingestion/type-extractors/rust.d.ts +2 -0
  106. package/dist/core/ingestion/type-extractors/rust.js +436 -0
  107. package/dist/core/ingestion/type-extractors/shared.d.ts +132 -0
  108. package/dist/core/ingestion/type-extractors/shared.js +571 -0
  109. package/dist/core/ingestion/type-extractors/swift.d.ts +2 -0
  110. package/dist/core/ingestion/type-extractors/swift.js +137 -0
  111. package/dist/core/ingestion/type-extractors/types.d.ts +95 -0
  112. package/dist/core/ingestion/type-extractors/types.js +1 -0
  113. package/dist/core/ingestion/type-extractors/typescript.d.ts +2 -0
  114. package/dist/core/ingestion/type-extractors/typescript.js +480 -0
  115. package/dist/core/ingestion/utils.d.ts +98 -0
  116. package/dist/core/ingestion/utils.js +1064 -9
  117. package/dist/core/ingestion/workers/parse-worker.d.ts +38 -4
  118. package/dist/core/ingestion/workers/parse-worker.js +248 -359
  119. package/dist/core/ingestion/workers/worker-pool.js +8 -0
  120. package/dist/core/{kuzu → lbug}/csv-generator.d.ts +1 -1
  121. package/dist/core/{kuzu → lbug}/csv-generator.js +20 -4
  122. package/dist/core/{kuzu/kuzu-adapter.d.ts → lbug/lbug-adapter.d.ts} +19 -19
  123. package/dist/core/{kuzu/kuzu-adapter.js → lbug/lbug-adapter.js} +82 -82
  124. package/dist/core/{kuzu → lbug}/schema.d.ts +4 -4
  125. package/dist/core/{kuzu → lbug}/schema.js +304 -289
  126. package/dist/core/search/bm25-index.d.ts +4 -4
  127. package/dist/core/search/bm25-index.js +17 -16
  128. package/dist/core/search/hybrid-search.d.ts +2 -2
  129. package/dist/core/search/hybrid-search.js +9 -9
  130. package/dist/core/tree-sitter/parser-loader.js +9 -2
  131. package/dist/core/wiki/generator.d.ts +4 -52
  132. package/dist/core/wiki/generator.js +53 -552
  133. package/dist/core/wiki/graph-queries.d.ts +4 -46
  134. package/dist/core/wiki/graph-queries.js +103 -282
  135. package/dist/core/wiki/html-viewer.js +192 -192
  136. package/dist/core/wiki/llm-client.js +11 -73
  137. package/dist/core/wiki/prompts.d.ts +8 -52
  138. package/dist/core/wiki/prompts.js +86 -200
  139. package/dist/mcp/compatible-stdio-transport.d.ts +25 -0
  140. package/dist/mcp/compatible-stdio-transport.js +200 -0
  141. package/dist/mcp/core/{kuzu-adapter.d.ts → lbug-adapter.d.ts} +7 -9
  142. package/dist/mcp/core/{kuzu-adapter.js → lbug-adapter.js} +77 -79
  143. package/dist/mcp/local/local-backend.d.ts +6 -6
  144. package/dist/mcp/local/local-backend.js +153 -146
  145. package/dist/mcp/resources.js +42 -42
  146. package/dist/mcp/server.js +18 -19
  147. package/dist/mcp/tools.js +103 -104
  148. package/dist/server/api.js +12 -12
  149. package/dist/server/mcp-http.d.ts +1 -1
  150. package/dist/server/mcp-http.js +1 -1
  151. package/dist/storage/repo-manager.d.ts +20 -2
  152. package/dist/storage/repo-manager.js +55 -1
  153. package/dist/types/pipeline.d.ts +1 -1
  154. package/hooks/claude/gitnexus-hook.cjs +238 -155
  155. package/hooks/claude/pre-tool-use.sh +79 -79
  156. package/hooks/claude/session-start.sh +42 -42
  157. package/package.json +98 -96
  158. package/scripts/patch-tree-sitter-swift.cjs +74 -74
  159. package/skills/gitnexus-cli.md +82 -82
  160. package/skills/gitnexus-debugging.md +89 -89
  161. package/skills/gitnexus-exploring.md +78 -78
  162. package/skills/gitnexus-guide.md +64 -64
  163. package/skills/gitnexus-impact-analysis.md +97 -97
  164. package/skills/gitnexus-pr-review.md +163 -163
  165. package/skills/gitnexus-refactoring.md +121 -121
  166. package/vendor/leiden/index.cjs +355 -355
  167. package/vendor/leiden/utils.cjs +392 -392
  168. package/dist/core/wiki/diagrams.d.ts +0 -27
  169. package/dist/core/wiki/diagrams.js +0 -163
@@ -4,16 +4,14 @@
4
4
  * All prompts produce deterministic, source-grounded documentation.
5
5
  * Templates use {{PLACEHOLDER}} substitution.
6
6
  */
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.";
7
+ export declare const GROUPING_SYSTEM_PROMPT = "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 = "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 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";
10
+ 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---\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.";
11
+ 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";
12
+ 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---\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.";
13
+ 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";
14
+ 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---\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.";
17
15
  /**
18
16
  * Replace {{PLACEHOLDER}} tokens in a template string.
19
17
  */
@@ -53,45 +51,3 @@ export declare function formatProcesses(processes: Array<{
53
51
  filePath: string;
54
52
  }>;
55
53
  }>): 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,154 +5,98 @@
5
5
  * Templates use {{PLACEHOLDER}} substitution.
6
6
  */
7
7
  // ─── Grouping Prompt ──────────────────────────────────────────────────
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
8
+ export const GROUPING_SYSTEM_PROMPT = `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 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"]
17
+ export const GROUPING_USER_PROMPT = `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"]
63
30
  }`;
64
31
  // ─── Leaf Module Prompt ───────────────────────────────────────────────
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
-
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
+ export const MODULE_USER_PROMPT = `Write documentation for the **{{MODULE_NAME}}** module.
41
+
42
+ ## Source Code
43
+
44
+ {{SOURCE_CODE}}
45
+
46
+ ## Call Graph & Execution Flows (reference for accuracy)
47
+
48
+ Internal calls: {{INTRA_CALLS}}
49
+ Outgoing calls: {{OUTGOING_CALLS}}
50
+ Incoming calls: {{INCOMING_CALLS}}
51
+ Execution flows: {{PROCESSES}}
52
+
53
+ ---
54
+
96
55
  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.`;
97
56
  // ─── Parent Module Prompt ─────────────────────────────────────────────
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
-
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
+ export const PARENT_USER_PROMPT = `Write documentation for the **{{MODULE_NAME}}** module, which contains these sub-modules:
65
+
66
+ {{CHILDREN_DOCS}}
67
+
68
+ Cross-module calls: {{CROSS_MODULE_CALLS}}
69
+ Shared execution flows: {{CROSS_PROCESSES}}
70
+
71
+ ---
72
+
122
73
  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.`;
123
74
  // ─── Overview Prompt ──────────────────────────────────────────────────
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
-
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
+ export const OVERVIEW_USER_PROMPT = `Write the overview page for this repository's wiki.
84
+
85
+ ## Project Info
86
+
87
+ {{PROJECT_INFO}}
88
+
89
+ ## Module Summaries
90
+
91
+ {{MODULE_SUMMARIES}}
92
+
93
+ ## Reference Data (for accuracy — do not reproduce verbatim)
94
+
95
+ Inter-module call edges: {{MODULE_EDGES}}
96
+ Key system flows: {{TOP_PROCESSES}}
97
+
98
+ ---
99
+
156
100
  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.`;
157
101
  // ─── Template Substitution Helper ─────────────────────────────────────
158
102
  /**
@@ -224,65 +168,7 @@ export function formatProcesses(processes) {
224
168
  /**
225
169
  * Shorten a file path for readability.
226
170
  */
227
- export function shortPath(fp) {
171
+ function shortPath(fp) {
228
172
  const parts = fp.replace(/\\/g, '/').split('/');
229
173
  return parts.length > 3 ? parts.slice(-3).join('/') : fp;
230
174
  }
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
- }
@@ -0,0 +1,25 @@
1
+ import type { Transport, TransportSendOptions } from '@modelcontextprotocol/sdk/shared/transport.js';
2
+ import { type JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js';
3
+ export type StdioFraming = 'content-length' | 'newline';
4
+ export declare class CompatibleStdioServerTransport implements Transport {
5
+ private readonly _stdin;
6
+ private readonly _stdout;
7
+ private _readBuffer;
8
+ private _started;
9
+ private _framing;
10
+ onmessage?: (message: JSONRPCMessage) => void;
11
+ onerror?: (error: Error) => void;
12
+ onclose?: () => void;
13
+ constructor(_stdin?: NodeJS.ReadableStream, _stdout?: NodeJS.WritableStream);
14
+ private readonly _ondata;
15
+ private readonly _onerror;
16
+ start(): Promise<void>;
17
+ private detectFraming;
18
+ private discardBufferedInput;
19
+ private readContentLengthMessage;
20
+ private readNewlineMessage;
21
+ private readMessage;
22
+ private processReadBuffer;
23
+ close(): Promise<void>;
24
+ send(message: JSONRPCMessage, _options?: TransportSendOptions): Promise<void>;
25
+ }
@@ -0,0 +1,200 @@
1
+ import process from 'node:process';
2
+ import { JSONRPCMessageSchema } from '@modelcontextprotocol/sdk/types.js';
3
+ function deserializeMessage(raw) {
4
+ return JSONRPCMessageSchema.parse(JSON.parse(raw));
5
+ }
6
+ function serializeNewlineMessage(message) {
7
+ return `${JSON.stringify(message)}\n`;
8
+ }
9
+ function serializeContentLengthMessage(message) {
10
+ const body = JSON.stringify(message);
11
+ return `Content-Length: ${Buffer.byteLength(body, 'utf8')}\r\n\r\n${body}`;
12
+ }
13
+ function findHeaderEnd(buffer) {
14
+ const crlfEnd = buffer.indexOf('\r\n\r\n');
15
+ if (crlfEnd !== -1) {
16
+ return { index: crlfEnd, separatorLength: 4 };
17
+ }
18
+ const lfEnd = buffer.indexOf('\n\n');
19
+ if (lfEnd !== -1) {
20
+ return { index: lfEnd, separatorLength: 2 };
21
+ }
22
+ return null;
23
+ }
24
+ function looksLikeContentLength(buffer) {
25
+ if (buffer.length < 14) {
26
+ return false;
27
+ }
28
+ const probe = buffer.toString('utf8', 0, Math.min(buffer.length, 32));
29
+ return /^content-length\s*:/i.test(probe);
30
+ }
31
+ const MAX_BUFFER_SIZE = 10 * 1024 * 1024; // 10 MB — generous for JSON-RPC
32
+ export class CompatibleStdioServerTransport {
33
+ _stdin;
34
+ _stdout;
35
+ _readBuffer;
36
+ _started = false;
37
+ _framing = null;
38
+ onmessage;
39
+ onerror;
40
+ onclose;
41
+ constructor(_stdin = process.stdin, _stdout = process.stdout) {
42
+ this._stdin = _stdin;
43
+ this._stdout = _stdout;
44
+ }
45
+ _ondata = (chunk) => {
46
+ this._readBuffer = this._readBuffer ? Buffer.concat([this._readBuffer, chunk]) : chunk;
47
+ if (this._readBuffer.length > MAX_BUFFER_SIZE) {
48
+ this.onerror?.(new Error(`Read buffer exceeded maximum size (${MAX_BUFFER_SIZE} bytes)`));
49
+ this.discardBufferedInput();
50
+ return;
51
+ }
52
+ this.processReadBuffer();
53
+ };
54
+ _onerror = (error) => {
55
+ this.onerror?.(error);
56
+ };
57
+ async start() {
58
+ if (this._started) {
59
+ throw new Error('CompatibleStdioServerTransport already started!');
60
+ }
61
+ this._started = true;
62
+ this._stdin.on('data', this._ondata);
63
+ this._stdin.on('error', this._onerror);
64
+ }
65
+ detectFraming() {
66
+ if (!this._readBuffer || this._readBuffer.length === 0) {
67
+ return null;
68
+ }
69
+ const firstByte = this._readBuffer[0];
70
+ if (firstByte === 0x7b || firstByte === 0x5b) {
71
+ return 'newline';
72
+ }
73
+ if (looksLikeContentLength(this._readBuffer)) {
74
+ return 'content-length';
75
+ }
76
+ return null;
77
+ }
78
+ discardBufferedInput() {
79
+ this._readBuffer = undefined;
80
+ this._framing = null;
81
+ }
82
+ readContentLengthMessage() {
83
+ if (!this._readBuffer) {
84
+ return null;
85
+ }
86
+ const header = findHeaderEnd(this._readBuffer);
87
+ if (header === null) {
88
+ return null;
89
+ }
90
+ const headerText = this._readBuffer
91
+ .toString('utf8', 0, header.index)
92
+ .replace(/\r\n/g, '\n')
93
+ .replace(/\r/g, '\n');
94
+ const match = headerText.match(/(?:^|\n)content-length\s*:\s*(\d+)/i);
95
+ if (!match) {
96
+ this.discardBufferedInput();
97
+ throw new Error('Missing Content-Length header from MCP client');
98
+ }
99
+ const contentLength = Number.parseInt(match[1], 10);
100
+ if (!Number.isFinite(contentLength) || contentLength < 0) {
101
+ this.discardBufferedInput();
102
+ throw new Error('Invalid Content-Length header from MCP client');
103
+ }
104
+ if (contentLength > MAX_BUFFER_SIZE) {
105
+ this.discardBufferedInput();
106
+ throw new Error(`Content-Length ${contentLength} exceeds maximum allowed size (${MAX_BUFFER_SIZE} bytes)`);
107
+ }
108
+ const bodyStart = header.index + header.separatorLength;
109
+ const bodyEnd = bodyStart + contentLength;
110
+ if (this._readBuffer.length < bodyEnd) {
111
+ return null;
112
+ }
113
+ const body = this._readBuffer.toString('utf8', bodyStart, bodyEnd);
114
+ this._readBuffer = this._readBuffer.subarray(bodyEnd);
115
+ return deserializeMessage(body);
116
+ }
117
+ readNewlineMessage() {
118
+ if (!this._readBuffer) {
119
+ return null;
120
+ }
121
+ while (true) {
122
+ const newlineIndex = this._readBuffer.indexOf('\n');
123
+ if (newlineIndex === -1) {
124
+ return null;
125
+ }
126
+ const line = this._readBuffer.toString('utf8', 0, newlineIndex).replace(/\r$/, '');
127
+ this._readBuffer = this._readBuffer.subarray(newlineIndex + 1);
128
+ if (line.trim().length === 0) {
129
+ continue;
130
+ }
131
+ return deserializeMessage(line);
132
+ }
133
+ }
134
+ readMessage() {
135
+ if (!this._readBuffer || this._readBuffer.length === 0) {
136
+ return null;
137
+ }
138
+ if (this._framing === null) {
139
+ this._framing = this.detectFraming();
140
+ if (this._framing === null) {
141
+ return null;
142
+ }
143
+ }
144
+ return this._framing === 'content-length'
145
+ ? this.readContentLengthMessage()
146
+ : this.readNewlineMessage();
147
+ }
148
+ processReadBuffer() {
149
+ while (true) {
150
+ try {
151
+ const message = this.readMessage();
152
+ if (message === null) {
153
+ break;
154
+ }
155
+ this.onmessage?.(message);
156
+ }
157
+ catch (error) {
158
+ this.onerror?.(error);
159
+ break;
160
+ }
161
+ }
162
+ }
163
+ async close() {
164
+ this._stdin.off('data', this._ondata);
165
+ this._stdin.off('error', this._onerror);
166
+ const remainingDataListeners = this._stdin.listenerCount('data');
167
+ if (remainingDataListeners === 0) {
168
+ this._stdin.pause();
169
+ }
170
+ this._started = false;
171
+ this._readBuffer = undefined;
172
+ this.onclose?.();
173
+ }
174
+ send(message, _options) {
175
+ return new Promise((resolve, reject) => {
176
+ if (!this._started) {
177
+ reject(new Error('Transport is closed'));
178
+ return;
179
+ }
180
+ const payload = this._framing === 'newline'
181
+ ? serializeNewlineMessage(message)
182
+ : serializeContentLengthMessage(message);
183
+ const onError = (error) => {
184
+ this._stdout.removeListener('error', onError);
185
+ reject(error);
186
+ };
187
+ this._stdout.on('error', onError);
188
+ if (this._stdout.write(payload)) {
189
+ this._stdout.removeListener('error', onError);
190
+ resolve();
191
+ }
192
+ else {
193
+ this._stdout.once('drain', () => {
194
+ this._stdout.removeListener('error', onError);
195
+ resolve();
196
+ });
197
+ }
198
+ });
199
+ }
200
+ }