nexus-agents 8.122.3 → 8.123.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 (138) hide show
  1. package/dist/{ast-rule-runner-D63SEZBA.js → ast-rule-runner-2WH3SFLU.js} +3 -4
  2. package/dist/{child-mcp-config-SYKZPE4K.js → child-mcp-config-OUJEI5O4.js} +2 -2
  3. package/dist/{chunk-ELTV6L22.js → chunk-2G2OJ3EJ.js} +4 -6
  4. package/dist/{chunk-ELTV6L22.js.map → chunk-2G2OJ3EJ.js.map} +1 -1
  5. package/dist/{chunk-G6C4CB2P.js → chunk-3JHGB5IP.js} +2 -2
  6. package/dist/{chunk-62T7LI7Y.js → chunk-3VQO3MWD.js} +2 -2
  7. package/dist/{chunk-LDKIDJQM.js → chunk-4HERVQZO.js} +5 -7
  8. package/dist/{chunk-LDKIDJQM.js.map → chunk-4HERVQZO.js.map} +1 -1
  9. package/dist/{chunk-BSB4FOLG.js → chunk-4SRYQKHC.js} +3 -3
  10. package/dist/{chunk-DRNW3QRY.js → chunk-4VJRMPKJ.js} +2 -2
  11. package/dist/{chunk-TXXXWVPX.js → chunk-5DLH4IWK.js} +6 -6
  12. package/dist/{chunk-XO7OU6FK.js → chunk-72R6FRHP.js} +2 -2
  13. package/dist/{chunk-XJGVR65R.js → chunk-7ILEOJQS.js} +6 -8
  14. package/dist/{chunk-XJGVR65R.js.map → chunk-7ILEOJQS.js.map} +1 -1
  15. package/dist/{chunk-YCTJNJKU.js → chunk-AIV2CDC4.js} +4 -4
  16. package/dist/{chunk-V4GLPTHB.js → chunk-AP3CNPUI.js} +5 -5
  17. package/dist/{chunk-SAFMMDQJ.js → chunk-AQAI7WFP.js} +2 -2
  18. package/dist/{chunk-W4VWFQRC.js → chunk-AXHI5SNH.js} +2 -2
  19. package/dist/{chunk-WBIO7WHW.js → chunk-DQEJSFE2.js} +2 -2
  20. package/dist/{chunk-IL3ES3J6.js → chunk-DYVN3FKX.js} +2 -2
  21. package/dist/{chunk-2FCB5UBG.js → chunk-GFFALPZC.js} +2 -2
  22. package/dist/{chunk-LTYFP4MJ.js → chunk-GSS3XJNZ.js} +9 -9
  23. package/dist/{chunk-3XW3QNOW.js → chunk-HX4RXRH6.js} +7 -7
  24. package/dist/{chunk-XXOLRZRQ.js → chunk-IGK42Y72.js} +5 -5
  25. package/dist/{chunk-DKJITSJK.js → chunk-J5KIXEEX.js} +5 -5
  26. package/dist/{chunk-3NQVZQCT.js → chunk-LNN5BYNY.js} +4 -6
  27. package/dist/{chunk-3NQVZQCT.js.map → chunk-LNN5BYNY.js.map} +1 -1
  28. package/dist/{chunk-NGVBCGM6.js → chunk-LT6Q6MC5.js} +12 -12
  29. package/dist/{chunk-WW2MBD5I.js → chunk-MFCX7UQQ.js} +2 -2
  30. package/dist/{chunk-PM2ECWCL.js → chunk-MPXBYDWO.js} +375 -144
  31. package/dist/chunk-MPXBYDWO.js.map +1 -0
  32. package/dist/{chunk-UA35ZBK5.js → chunk-MTN4E7MO.js} +45 -50
  33. package/dist/chunk-MTN4E7MO.js.map +1 -0
  34. package/dist/{chunk-UCSIPEJK.js → chunk-PHNSPPHO.js} +3 -3
  35. package/dist/{chunk-7IMCFFHH.js → chunk-PK7YUG4G.js} +11 -11
  36. package/dist/{chunk-4SZQYMMO.js → chunk-QLHNL5Z6.js} +3 -3
  37. package/dist/{chunk-7IXILU76.js → chunk-RLJMTC6K.js} +2 -2
  38. package/dist/{chunk-MVFKTFMM.js → chunk-UAWN3QHN.js} +2 -2
  39. package/dist/{chunk-BJUIPCJ5.js → chunk-VVH4Y6TK.js} +2 -2
  40. package/dist/{chunk-5UD62EYQ.js → chunk-WNFBRK6I.js} +4 -4
  41. package/dist/{chunk-CTE55G3Y.js → chunk-WZ5IJTL3.js} +3 -3
  42. package/dist/{chunk-KMPEC7MU.js → chunk-Z5MLGY3X.js} +3 -3
  43. package/dist/{chunk-EEXUKXZQ.js → chunk-ZMH3XMMV.js} +2 -2
  44. package/dist/{cli-circuit-breaker-2NCL4BJG.js → cli-circuit-breaker-E5OBGVGC.js} +3 -3
  45. package/dist/cli.js +58 -49
  46. package/dist/cli.js.map +1 -1
  47. package/dist/{composite-router-FMSFSUY4.js → composite-router-QLG6RKP6.js} +2 -2
  48. package/dist/{consensus-vote-SSA6HZOI.js → consensus-vote-QBAM4C23.js} +17 -18
  49. package/dist/{context-retriever-JQVOCYWB.js → context-retriever-2LLQLCRD.js} +8 -9
  50. package/dist/{doctor-deep-TI74R6WM.js → doctor-deep-67UPM3HJ.js} +3 -3
  51. package/dist/doctor-gateway-report-ILD3OIJA.js +19 -0
  52. package/dist/{doctor-live-ESPDY2UT.js → doctor-live-SRUI2MAC.js} +11 -11
  53. package/dist/{expert-bridge-SLDH3I4Q.js → expert-bridge-VD6VU2WT.js} +4 -4
  54. package/dist/{factory-T5Z4H7I4.js → factory-34ODVPTS.js} +10 -10
  55. package/dist/{factory-UO4YVMT4.js → factory-RSAFHZ5J.js} +5 -5
  56. package/dist/{improvement-review-CQVAUN26.js → improvement-review-7IWMROEL.js} +6 -7
  57. package/dist/index.d.ts +19 -1
  58. package/dist/index.js +32 -70
  59. package/dist/index.js.map +1 -1
  60. package/dist/{init-opencode-4FK75Q4I.js → init-opencode-QOONWORC.js} +6 -6
  61. package/dist/{issue-triage-UM2N433F.js → issue-triage-QALNALO5.js} +6 -6
  62. package/dist/{openai-compat-adapter-EHKDFXNR.js → openai-compat-adapter-6WQVOAYK.js} +6 -6
  63. package/dist/{pr-reviewer-helpers-TOSTLTWB.js → pr-reviewer-helpers-CUZCDNY3.js} +4 -4
  64. package/dist/{registry-command-YZSKM2GA.js → registry-command-BO4DITBE.js} +2 -2
  65. package/dist/{repo-security-plan-C66VWEOJ.js → repo-security-plan-3XV35U2U.js} +3 -3
  66. package/dist/{research-helpers-synthesize-CWN7TZPP.js → research-helpers-synthesize-CFAJGQPG.js} +4 -5
  67. package/dist/{routing-memory-IYLRTH55.js → routing-memory-Y57AQSY6.js} +2 -2
  68. package/dist/{session-memory-LC2KINJU.js → session-memory-I2WNQT2R.js} +3 -3
  69. package/dist/{setup-config-TLKV6TBJ.js → setup-config-SCQFOX5P.js} +3 -3
  70. package/dist/{setup-custom-api-CPJ6OX4O.js → setup-custom-api-P5WRVVQ2.js} +4 -4
  71. package/dist/setup-data-dir-ZWMGEWWH.js +33 -0
  72. package/dist/{tool-memory-OQMZREAX.js → tool-memory-FBIFXGNR.js} +5 -5
  73. package/dist/{unified-registry-QA2DYYO6.js → unified-registry-EP2XEMN5.js} +11 -11
  74. package/dist/{weather-report-C4TRZMJZ.js → weather-report-EOX3CKTI.js} +2 -2
  75. package/package.json +1 -1
  76. package/dist/chunk-PM2ECWCL.js.map +0 -1
  77. package/dist/chunk-UA35ZBK5.js.map +0 -1
  78. package/dist/chunk-XEPZSDN5.js +0 -91
  79. package/dist/chunk-XEPZSDN5.js.map +0 -1
  80. package/dist/doctor-gateway-report-QQVWP3P5.js +0 -19
  81. package/dist/setup-data-dir-46AJGMKK.js +0 -33
  82. /package/dist/{ast-rule-runner-D63SEZBA.js.map → ast-rule-runner-2WH3SFLU.js.map} +0 -0
  83. /package/dist/{child-mcp-config-SYKZPE4K.js.map → child-mcp-config-OUJEI5O4.js.map} +0 -0
  84. /package/dist/{chunk-G6C4CB2P.js.map → chunk-3JHGB5IP.js.map} +0 -0
  85. /package/dist/{chunk-62T7LI7Y.js.map → chunk-3VQO3MWD.js.map} +0 -0
  86. /package/dist/{chunk-BSB4FOLG.js.map → chunk-4SRYQKHC.js.map} +0 -0
  87. /package/dist/{chunk-DRNW3QRY.js.map → chunk-4VJRMPKJ.js.map} +0 -0
  88. /package/dist/{chunk-TXXXWVPX.js.map → chunk-5DLH4IWK.js.map} +0 -0
  89. /package/dist/{chunk-XO7OU6FK.js.map → chunk-72R6FRHP.js.map} +0 -0
  90. /package/dist/{chunk-YCTJNJKU.js.map → chunk-AIV2CDC4.js.map} +0 -0
  91. /package/dist/{chunk-V4GLPTHB.js.map → chunk-AP3CNPUI.js.map} +0 -0
  92. /package/dist/{chunk-SAFMMDQJ.js.map → chunk-AQAI7WFP.js.map} +0 -0
  93. /package/dist/{chunk-W4VWFQRC.js.map → chunk-AXHI5SNH.js.map} +0 -0
  94. /package/dist/{chunk-WBIO7WHW.js.map → chunk-DQEJSFE2.js.map} +0 -0
  95. /package/dist/{chunk-IL3ES3J6.js.map → chunk-DYVN3FKX.js.map} +0 -0
  96. /package/dist/{chunk-2FCB5UBG.js.map → chunk-GFFALPZC.js.map} +0 -0
  97. /package/dist/{chunk-LTYFP4MJ.js.map → chunk-GSS3XJNZ.js.map} +0 -0
  98. /package/dist/{chunk-3XW3QNOW.js.map → chunk-HX4RXRH6.js.map} +0 -0
  99. /package/dist/{chunk-XXOLRZRQ.js.map → chunk-IGK42Y72.js.map} +0 -0
  100. /package/dist/{chunk-DKJITSJK.js.map → chunk-J5KIXEEX.js.map} +0 -0
  101. /package/dist/{chunk-NGVBCGM6.js.map → chunk-LT6Q6MC5.js.map} +0 -0
  102. /package/dist/{chunk-WW2MBD5I.js.map → chunk-MFCX7UQQ.js.map} +0 -0
  103. /package/dist/{chunk-UCSIPEJK.js.map → chunk-PHNSPPHO.js.map} +0 -0
  104. /package/dist/{chunk-7IMCFFHH.js.map → chunk-PK7YUG4G.js.map} +0 -0
  105. /package/dist/{chunk-4SZQYMMO.js.map → chunk-QLHNL5Z6.js.map} +0 -0
  106. /package/dist/{chunk-7IXILU76.js.map → chunk-RLJMTC6K.js.map} +0 -0
  107. /package/dist/{chunk-MVFKTFMM.js.map → chunk-UAWN3QHN.js.map} +0 -0
  108. /package/dist/{chunk-BJUIPCJ5.js.map → chunk-VVH4Y6TK.js.map} +0 -0
  109. /package/dist/{chunk-5UD62EYQ.js.map → chunk-WNFBRK6I.js.map} +0 -0
  110. /package/dist/{chunk-CTE55G3Y.js.map → chunk-WZ5IJTL3.js.map} +0 -0
  111. /package/dist/{chunk-KMPEC7MU.js.map → chunk-Z5MLGY3X.js.map} +0 -0
  112. /package/dist/{chunk-EEXUKXZQ.js.map → chunk-ZMH3XMMV.js.map} +0 -0
  113. /package/dist/{cli-circuit-breaker-2NCL4BJG.js.map → cli-circuit-breaker-E5OBGVGC.js.map} +0 -0
  114. /package/dist/{composite-router-FMSFSUY4.js.map → composite-router-QLG6RKP6.js.map} +0 -0
  115. /package/dist/{consensus-vote-SSA6HZOI.js.map → consensus-vote-QBAM4C23.js.map} +0 -0
  116. /package/dist/{context-retriever-JQVOCYWB.js.map → context-retriever-2LLQLCRD.js.map} +0 -0
  117. /package/dist/{doctor-deep-TI74R6WM.js.map → doctor-deep-67UPM3HJ.js.map} +0 -0
  118. /package/dist/{doctor-gateway-report-QQVWP3P5.js.map → doctor-gateway-report-ILD3OIJA.js.map} +0 -0
  119. /package/dist/{doctor-live-ESPDY2UT.js.map → doctor-live-SRUI2MAC.js.map} +0 -0
  120. /package/dist/{expert-bridge-SLDH3I4Q.js.map → expert-bridge-VD6VU2WT.js.map} +0 -0
  121. /package/dist/{factory-T5Z4H7I4.js.map → factory-34ODVPTS.js.map} +0 -0
  122. /package/dist/{factory-UO4YVMT4.js.map → factory-RSAFHZ5J.js.map} +0 -0
  123. /package/dist/{improvement-review-CQVAUN26.js.map → improvement-review-7IWMROEL.js.map} +0 -0
  124. /package/dist/{init-opencode-4FK75Q4I.js.map → init-opencode-QOONWORC.js.map} +0 -0
  125. /package/dist/{issue-triage-UM2N433F.js.map → issue-triage-QALNALO5.js.map} +0 -0
  126. /package/dist/{openai-compat-adapter-EHKDFXNR.js.map → openai-compat-adapter-6WQVOAYK.js.map} +0 -0
  127. /package/dist/{pr-reviewer-helpers-TOSTLTWB.js.map → pr-reviewer-helpers-CUZCDNY3.js.map} +0 -0
  128. /package/dist/{registry-command-YZSKM2GA.js.map → registry-command-BO4DITBE.js.map} +0 -0
  129. /package/dist/{repo-security-plan-C66VWEOJ.js.map → repo-security-plan-3XV35U2U.js.map} +0 -0
  130. /package/dist/{research-helpers-synthesize-CWN7TZPP.js.map → research-helpers-synthesize-CFAJGQPG.js.map} +0 -0
  131. /package/dist/{routing-memory-IYLRTH55.js.map → routing-memory-Y57AQSY6.js.map} +0 -0
  132. /package/dist/{session-memory-LC2KINJU.js.map → session-memory-I2WNQT2R.js.map} +0 -0
  133. /package/dist/{setup-config-TLKV6TBJ.js.map → setup-config-SCQFOX5P.js.map} +0 -0
  134. /package/dist/{setup-custom-api-CPJ6OX4O.js.map → setup-custom-api-P5WRVVQ2.js.map} +0 -0
  135. /package/dist/{setup-data-dir-46AJGMKK.js.map → setup-data-dir-ZWMGEWWH.js.map} +0 -0
  136. /package/dist/{tool-memory-OQMZREAX.js.map → tool-memory-FBIFXGNR.js.map} +0 -0
  137. /package/dist/{unified-registry-QA2DYYO6.js.map → unified-registry-EP2XEMN5.js.map} +0 -0
  138. /package/dist/{weather-report-C4TRZMJZ.js.map → weather-report-EOX3CKTI.js.map} +0 -0
@@ -9,9 +9,8 @@ import {
9
9
  getBuiltInAstRulesPath,
10
10
  loadRules,
11
11
  runAstQaRules
12
- } from "./chunk-ELTV6L22.js";
13
- import "./chunk-XEPZSDN5.js";
14
- import "./chunk-PM2ECWCL.js";
12
+ } from "./chunk-2G2OJ3EJ.js";
13
+ import "./chunk-MPXBYDWO.js";
15
14
  import "./chunk-UE7A2XHM.js";
16
15
  import "./chunk-LWOX65CP.js";
17
16
  import "./chunk-PX6F3LHL.js";
@@ -27,4 +26,4 @@ export {
27
26
  loadRules,
28
27
  runAstQaRules
29
28
  };
30
- //# sourceMappingURL=ast-rule-runner-D63SEZBA.js.map
29
+ //# sourceMappingURL=ast-rule-runner-2WH3SFLU.js.map
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-OITVVSWO.js";
4
4
  import {
5
5
  createLogger
6
- } from "./chunk-PM2ECWCL.js";
6
+ } from "./chunk-MPXBYDWO.js";
7
7
  import "./chunk-UE7A2XHM.js";
8
8
  import "./chunk-LWOX65CP.js";
9
9
  import "./chunk-PX6F3LHL.js";
@@ -49,4 +49,4 @@ async function generateMcpConfig(options) {
49
49
  export {
50
50
  generateMcpConfig
51
51
  };
52
- //# sourceMappingURL=child-mcp-config-SYKZPE4K.js.map
52
+ //# sourceMappingURL=child-mcp-config-OUJEI5O4.js.map
@@ -1,12 +1,10 @@
1
- import {
2
- resolveInsideRoot
3
- } from "./chunk-XEPZSDN5.js";
4
1
  import {
5
2
  SecurityError,
6
3
  ValidationError,
7
4
  createLogger,
8
- formatZodError
9
- } from "./chunk-PM2ECWCL.js";
5
+ formatZodError,
6
+ resolveInsideRoot
7
+ } from "./chunk-MPXBYDWO.js";
10
8
 
11
9
  // src/security/ast-rule-runner.ts
12
10
  import { existsSync } from "node:fs";
@@ -243,4 +241,4 @@ export {
243
241
  collectAstQaFindings,
244
242
  runAstQaRules
245
243
  };
246
- //# sourceMappingURL=chunk-ELTV6L22.js.map
244
+ //# sourceMappingURL=chunk-2G2OJ3EJ.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/security/ast-rule-runner.ts"],"sourcesContent":["/**\n * nexus-agents/security - Polyglot (Python/Go) AST QA/Security Rule Runner (#4249 child C)\n *\n * Runs YAML-defined `@ast-grep/napi` rules against Python/Go source, detecting\n * common QA/security anti-patterns (dynamic `eval`/`exec`, shell injection,\n * unchecked external command execution). Same engine already used by\n * `search_usages` (indexer/usage-ast.ts, #4265) and the ast-fixer rewrites\n * (agents/collaboration/ast-rewrites.ts, #4243/#4249 child B) — no new AST\n * dependency, just new language grammars for it.\n *\n * **Language support gap.** `Lang` in `@ast-grep/napi@0.44.1` ships only\n * Html/JavaScript/Tsx/Css/TypeScript — no Python, no Go. This module closes\n * that gap via napi's `@experimental registerDynamicLanguage` API, backed by\n * the `@ast-grep/lang-python`/`@ast-grep/lang-go` prebuilt tree-sitter\n * grammars. Both are EXACT-pinned in package.json (no caret): these are\n * early/experimental packages and a caret range could silently swap in an\n * incompatible native `.so` grammar build underneath a \"safe\" semver-minor\n * bump. `registerDynamicLanguage` throws if called more than once per\n * process (napi-rs's own documented constraint) — {@link ensurePolyglotLangs}\n * is a lazy, module-level, once-only guard so repeated calls (tests, repeat\n * runner invocations within one process) never trip it twice.\n *\n * **Read-only.** Reads rule YAML and target source files, walks their ASTs,\n * performs NO writes. ast-grep YAML rule files support a `fix:` key for\n * autofixing, but napi's `SgNode.findAll` (used here) never applies it —\n * only ast-grep's separate rewrite/CLI machinery does — so even a rule\n * author who adds `fix:` cannot turn this runner into a writer by accident.\n * MCP exposure is deliberately deferred (see the follow-up issue referenced\n * in the #4249 child C PR) to keep this surface a plain function until a\n * named consumer needs it wired through a tool.\n *\n * @module security/ast-rule-runner\n * @see Issue #4249 - epic: ast-grep adoption (Child C: polyglot QA/security rules)\n */\n\nimport { existsSync } from 'node:fs';\nimport { readdir, readFile, stat } from 'node:fs/promises';\nimport { dirname, extname, join, relative, sep } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { parse, registerDynamicLanguage } from '@ast-grep/napi';\nimport type { NapiConfig } from '@ast-grep/napi';\n// Both packages are CJS `export = <LanguageRegistration>` modules — the\n// default import is the whole registration object (`libraryPath` getter,\n// `extensions`, `languageSymbol`, `expandoChar`). See their `index.d.ts`.\nimport goLangRegistration from '@ast-grep/lang-go';\nimport pythonLangRegistration from '@ast-grep/lang-python';\nimport { parse as parseYaml } from 'yaml';\nimport { z } from 'zod';\nimport { createLogger, SecurityError, ValidationError, formatZodError } from '../core/index.js';\nimport { resolveInsideRoot } from './safe-path.js';\n\n// ============================================================================\n// Dynamic language registration (@experimental, call-once)\n// ============================================================================\n\nlet polyglotLangsRegistered = false;\n\n/**\n * Lazily register the Python/Go tree-sitter grammars with ast-grep's\n * `registerDynamicLanguage`. That API throws if called more than once in a\n * process; this guard makes every call after the first a no-op so repeated\n * runner invocations (or a test suite that constructs the runner many times)\n * never trip the constraint.\n */\nexport function ensurePolyglotLangs(): void {\n if (polyglotLangsRegistered) return;\n registerDynamicLanguage({ python: pythonLangRegistration, go: goLangRegistration });\n polyglotLangsRegistered = true;\n}\n\n// ============================================================================\n// Rule schema (fail-closed)\n// ============================================================================\n\n/** Languages a rule file may declare. Deliberately narrowed to the two this\n * runner actually SCANS (python/go): admitting `typescript`/`javascript` here\n * would let a TS/JS rule file validate at load time and then silently never\n * fire (there is no TS/JS extension in {@link POLYGLOT_EXT_TO_LANG}), which is\n * a fail-OPEN gap for a security scanner where \"no findings\" reads as \"clean\".\n * TS/JS structural analysis is already covered by `search_usages` (#4265) and\n * the ast-fixer rewrites (#4243); a TS/JS rule here would fail LOUD at load\n * (unknown-language Zod error) instead of loading dead. */\nexport const AST_RULE_LANGUAGES = ['python', 'go'] as const;\nexport type AstRuleLanguage = (typeof AST_RULE_LANGUAGES)[number];\n\nexport const AST_RULE_SEVERITIES = ['error', 'warning', 'info'] as const;\nexport type AstRuleSeverity = (typeof AST_RULE_SEVERITIES)[number];\n\n/** Schema for one `*.yml` rule file. `rule` is passed through as ast-grep's\n * own `Rule` object (napi already validates it structurally at match time);\n * Zod only pins down the envelope so an unknown `language` or a missing\n * field FAILS CLOSED instead of silently loading a partial/broken rule. */\nconst RuleFileSchema = z.object({\n id: z.string().min(1),\n language: z.enum(AST_RULE_LANGUAGES),\n severity: z.enum(AST_RULE_SEVERITIES),\n message: z.string().min(1),\n rule: z.record(z.string(), z.unknown()),\n});\n\nexport type AstQaRuleFile = z.infer<typeof RuleFileSchema>;\n\n/** Per-match snippet char cap (matches indexer/usage-ast.ts's discipline). */\nconst MAX_SNIPPET_CHARS = 200;\n\n/** Default cap on emitted findings. Excess is counted + reported, never silently dropped. */\nexport const DEFAULT_AST_QA_LIMIT = 200;\n/** Hard upper bound a caller may request for the finding cap. */\nexport const MAX_AST_QA_LIMIT = 2000;\n/** Directory walk depth for the target-dir scan (not caller-configurable — no\n * named consumer needs a deeper/shallower walk yet; YAGNI). */\nconst AST_QA_MAX_DEPTH = 24;\n/** Upper bound on files parsed in a single run, to bound worst-case cost.\n * Exceeding it makes the scan PARTIAL — surfaced via {@link AstQaCollectResult}'s\n * `filesTruncated`/`filesSkipped` + a warn, never silently dropped. */\nexport const MAX_FILES_SCANNED = 5000;\n\nconst logger = createLogger({ component: 'ast-rule-runner' });\n\n// ============================================================================\n// Rule loading\n// ============================================================================\n\n/**\n * Load and Zod-validate every `*.yml` rule file in `dir`. FAILS CLOSED: a\n * single malformed YAML file, or a file with an unrecognized `language` or\n * missing field, throws a {@link ValidationError} — there is no\n * \"load what parsed, skip the rest\" partial mode.\n */\nexport async function loadRules(dir: string): Promise<AstQaRuleFile[]> {\n let entries: string[];\n try {\n entries = (await readdir(dir)).filter((f) => f.endsWith('.yml') || f.endsWith('.yaml')).sort();\n } catch (caught: unknown) {\n const e = caught instanceof Error ? caught : new Error(String(caught));\n throw new ValidationError(`ast-rule-runner: cannot read rules dir ${dir}: ${e.message}`, {\n cause: e,\n });\n }\n\n const rules: AstQaRuleFile[] = [];\n for (const file of entries) {\n const path = join(dir, file);\n const raw = await readFile(path, 'utf8');\n\n let parsed: unknown;\n try {\n parsed = parseYaml(raw);\n } catch (caught: unknown) {\n const e = caught instanceof Error ? caught : new Error(String(caught));\n throw new ValidationError(`ast-rule-runner: malformed YAML in ${path}: ${e.message}`, {\n cause: e,\n });\n }\n\n const result = RuleFileSchema.safeParse(parsed);\n if (!result.success) {\n throw new ValidationError(\n `ast-rule-runner: invalid rule file ${path}: ${formatZodError(result.error)}`\n );\n }\n rules.push(result.data);\n }\n return rules;\n}\n\n// ============================================================================\n// Built-in rules dir resolution (mirrors workflows/template-loader.ts)\n// ============================================================================\n\n/**\n * Resolve the built-in `ast-rules/` directory, handling both dev (unbundled,\n * `src/security/ast-rule-runner.ts`) and published (bundled,\n * `dist/index.js` + `dist/security/ast-rules/*.yml` copied by tsup's\n * `onSuccess` step) layouts — the same two-layout problem\n * `getBuiltInTemplatesPath` solves for workflow templates.\n */\nexport function getBuiltInAstRulesPath(): string {\n const currentFile = fileURLToPath(import.meta.url);\n const currentDir = dirname(currentFile);\n\n if (currentFile.includes(`${sep}dist${sep}`) || currentFile.endsWith(`${sep}dist`)) {\n const distIndex = currentFile.lastIndexOf(`${sep}dist${sep}`);\n if (distIndex !== -1) {\n const distDir = currentFile.substring(0, distIndex + 5); // +5 for \"/dist\"\n const bundledPath = join(distDir, 'security', 'ast-rules');\n if (existsSync(bundledPath)) return bundledPath;\n }\n }\n\n const possiblePaths = [\n join(currentDir, 'ast-rules'), // Unbundled: sibling of this file in src/security/\n join(currentDir, 'security', 'ast-rules'), // Bundled chunk: dist/security sibling\n join(dirname(currentDir), 'security', 'ast-rules'),\n ];\n for (const path of possiblePaths) {\n if (existsSync(path)) return path;\n }\n return join(currentDir, 'ast-rules'); // Fallback (for error reporting)\n}\n\n// ============================================================================\n// Path-traversal guard (same shape as mcp/tools/search-usages-tool.ts)\n// ============================================================================\n\n/**\n * Resolve a caller path against a path-traversal guard (must stay within cwd).\n * Realpath-aware: a symlink inside cwd whose target is outside it is refused,\n * and the returned path is the canonical one the scan then walks.\n */\nfunction resolveWithinCwd(target: string): { resolved: string } | { error: string } {\n const resolved = resolveInsideRoot(target);\n if (resolved === null) {\n return { error: `Path traversal denied: scope must be within ${process.cwd()}` };\n }\n return { resolved };\n}\n\n// ============================================================================\n// File walk (LOCAL extension map — python/go only; does NOT reuse\n// indexer/usage-ast.ts's TS/JS inferLang or indexer/codebase-search.ts's\n// TS/JS-only findSourceFiles)\n// ============================================================================\n\nconst SKIP_DIRS = new Set(['node_modules', 'dist', '.git']);\n\n/** file-extension -> ast-rule language, for the two languages this runner scans. */\nconst POLYGLOT_EXT_TO_LANG: Readonly<Record<string, AstRuleLanguage>> = {\n '.py': 'python',\n '.go': 'go',\n};\n\n/** Infer the ast-rule language for a file from its extension, or `null` if unsupported. */\nfunction inferRuleLang(file: string): AstRuleLanguage | null {\n return POLYGLOT_EXT_TO_LANG[extname(file).toLowerCase()] ?? null;\n}\n\n/**\n * Recursively collect `.py`/`.go` files under `dir`, bounded by `maxDepth`.\n * A subdirectory whose `readdir` fails mid-walk (e.g. a `chmod 000` dir) is\n * WARNED about per-dir and skipped rather than silently swallowed — the scan\n * continues, but the partiality is surfaced in the log. The SCAN ROOT's own\n * readability is validated up front by {@link collectAstQaFindings} (fail\n * loud), so this soft-skip only ever applies to descendant dirs.\n */\nasync function findPolyglotFiles(dir: string, maxDepth: number): Promise<string[]> {\n if (maxDepth <= 0) return [];\n const out: string[] = [];\n let entries;\n try {\n entries = await readdir(dir, { withFileTypes: true });\n } catch (caught: unknown) {\n const e = caught instanceof Error ? caught : new Error(String(caught));\n logger.warn(`ast-rule-runner: skipped unreadable directory ${dir}: ${e.message}`);\n return out;\n }\n for (const entry of entries) {\n const fullPath = join(dir, entry.name);\n if (entry.isDirectory() && !SKIP_DIRS.has(entry.name)) {\n out.push(...(await findPolyglotFiles(fullPath, maxDepth - 1)));\n } else if (entry.isFile() && inferRuleLang(entry.name) !== null) {\n out.push(fullPath);\n }\n }\n return out;\n}\n\n/** Map a rule's declared language to the `parse()` first argument, registering\n * the dynamic grammars on first use. Both supported languages (python/go) are\n * dynamically-registered CustomLangs, so the language name string IS the\n * `parse()` key set up in {@link ensurePolyglotLangs}. */\nfunction langToParseArg(lang: AstRuleLanguage): AstRuleLanguage {\n ensurePolyglotLangs();\n return lang; // the CustomLang string keys used in registerDynamicLanguage()\n}\n\n// ============================================================================\n// Findings\n// ============================================================================\n\n/** One ast-grep rule match against a source file. */\nexport interface AstRuleFinding {\n ruleId: string;\n severity: AstRuleSeverity;\n message: string;\n /** Path relative to the resolved `targetDir`. */\n file: string;\n /** 1-based line number. */\n line: number;\n /** 1-based column number. */\n column: number;\n /** Trimmed, length-capped source line for the match. */\n snippet: string;\n}\n\nexport interface RunAstQaRulesOptions {\n /** Directory containing `*.yml` rule files (default: the built-in bundled rules). */\n rulesDir?: string;\n /** Directory to scan for `.py`/`.go` source files (must stay within cwd). */\n targetDir: string;\n /** Max findings emitted (default {@link DEFAULT_AST_QA_LIMIT}). Excess is counted + reported. */\n limit?: number;\n}\n\n/** {@link collectAstQaFindings}'s full result — findings plus the true total,\n * so overflow beyond `limit` is counted and reported, never silently dropped. */\nexport interface AstQaCollectResult {\n findings: AstRuleFinding[];\n /** True count of matches found, before the `limit` cap was applied. */\n total: number;\n limit: number;\n /** Number of `.py`/`.go` files actually scanned (after the file cap). */\n filesScanned: number;\n /** Number of discovered files DROPPED because the file cap ({@link MAX_FILES_SCANNED})\n * was exceeded. Non-zero means the scan was PARTIAL — a downstream consumer\n * must not treat empty/low findings as a clean bill of health. */\n filesSkipped: number;\n /** True iff `filesSkipped > 0` — the scan did not cover every candidate file. */\n filesTruncated: boolean;\n}\n\n/** Findings + true-match-count from scanning ONE already-read source file. */\ninterface FileScanResult {\n findings: AstRuleFinding[];\n total: number;\n}\n\n/** Bundles {@link scanFile}'s cap-tracking inputs (max-params discipline). */\ninterface FileScanBudget {\n /** Path emitted on each finding (relative to the resolved `targetDir`). */\n rel: string;\n /** Max TOTAL findings across the whole run. */\n limit: number;\n /** Findings already accepted by earlier files in this run. */\n alreadyFound: number;\n}\n\n/**\n * Scan one already-read source file against the rules applicable to its\n * language, pushing findings only while the running total (`budget.alreadyFound`\n * + findings pushed so far) stays under `budget.limit` — while still counting\n * every true match, so the caller can report overflow instead of silently\n * dropping it.\n */\nfunction scanFile(\n src: string,\n lang: AstRuleLanguage,\n applicable: readonly AstQaRuleFile[],\n budget: FileScanBudget\n): FileScanResult {\n const { rel, limit, alreadyFound } = budget;\n const root = parse(langToParseArg(lang), src).root();\n const lines = src.split('\\n');\n const findings: AstRuleFinding[] = [];\n let total = 0;\n\n for (const rule of applicable) {\n const config: NapiConfig = { rule: rule.rule };\n for (const node of root.findAll(config)) {\n total += 1;\n if (alreadyFound + findings.length < limit) {\n const { start } = node.range();\n const rawLine = lines[start.line] ?? node.text();\n findings.push({\n ruleId: rule.id,\n severity: rule.severity,\n message: rule.message,\n file: rel,\n line: start.line + 1,\n column: start.column + 1,\n snippet: rawLine.trim().slice(0, MAX_SNIPPET_CHARS),\n });\n }\n }\n }\n return { findings, total };\n}\n\n/**\n * Fail LOUD on an unreadable / non-directory scan root. `loadRules` already\n * throws on an unreadable RULES dir; the TARGET traversal must not fail OPEN —\n * a lone file path, a bad path, or a `000` root would otherwise return an empty\n * finding set that reads as \"clean\" for a security scanner.\n */\nasync function assertScanRootIsDirectory(resolved: string): Promise<void> {\n let rootStat;\n try {\n rootStat = await stat(resolved);\n } catch (caught: unknown) {\n const e = caught instanceof Error ? caught : new Error(String(caught));\n throw new ValidationError(`ast-rule-runner: cannot read targetDir ${resolved}: ${e.message}`, {\n cause: e,\n });\n }\n if (!rootStat.isDirectory()) {\n throw new ValidationError(\n `ast-rule-runner: targetDir must be a directory, got a non-directory path: ${resolved}`\n );\n }\n}\n\n/** Result of resolving the candidate file set under a scan root, with the\n * file-cap truncation signal surfaced (never a silent `.slice`). */\ninterface ScanFileSet {\n files: string[];\n filesSkipped: number;\n filesTruncated: boolean;\n}\n\n/** Discover candidate `.py`/`.go` files, applying + SURFACING the file cap. */\nasync function resolveScanFiles(root: string): Promise<ScanFileSet> {\n const discovered = await findPolyglotFiles(root, AST_QA_MAX_DEPTH);\n const files = discovered.slice(0, MAX_FILES_SCANNED);\n const filesSkipped = discovered.length - files.length;\n const filesTruncated = filesSkipped > 0;\n if (filesTruncated) {\n logger.warn(\n `ast-rule-runner: ${String(filesSkipped)} file(s) NOT scanned — file cap ` +\n `${String(MAX_FILES_SCANNED)} exceeded (discovered=${String(discovered.length)}). ` +\n `Scan is PARTIAL; do not treat findings as exhaustive.`\n );\n }\n return { files, filesSkipped, filesTruncated };\n}\n\n/**\n * Run every applicable rule in `rulesDir` against every `.py`/`.go` file under\n * `targetDir`, returning capped findings plus the true total (so callers that\n * need the overflow count — e.g. a future MCP tool wrapper — can report it).\n * {@link runAstQaRules} is the capped-array convenience wrapper over this.\n */\nexport async function collectAstQaFindings(\n opts: RunAstQaRulesOptions\n): Promise<AstQaCollectResult> {\n const guard = resolveWithinCwd(opts.targetDir);\n if ('error' in guard) {\n throw new SecurityError(guard.error);\n }\n await assertScanRootIsDirectory(guard.resolved);\n\n const rulesDir = opts.rulesDir ?? getBuiltInAstRulesPath();\n const rules = await loadRules(rulesDir);\n // Clamp into [1, MAX]: a limit <= 0 would report total > 0 with zero findings\n // (fail-open \"clean\" signal), so the floor is load-bearing, not cosmetic.\n const limit = Math.min(Math.max(opts.limit ?? DEFAULT_AST_QA_LIMIT, 1), MAX_AST_QA_LIMIT);\n\n const { files, filesSkipped, filesTruncated } = await resolveScanFiles(guard.resolved);\n\n const findings: AstRuleFinding[] = [];\n let total = 0;\n\n for (const file of files) {\n const lang = inferRuleLang(file);\n if (lang === null) continue;\n const applicable = rules.filter((r) => r.language === lang);\n if (applicable.length === 0) continue;\n\n let src: string;\n try {\n src = await readFile(file, 'utf8');\n } catch {\n logger.warn(`ast-rule-runner: skipped unreadable file ${file}`);\n continue;\n }\n\n const rel = relative(guard.resolved, file) || file;\n const scanned = scanFile(src, lang, applicable, { rel, limit, alreadyFound: findings.length });\n findings.push(...scanned.findings);\n total += scanned.total;\n }\n\n if (total > findings.length) {\n logger.warn(\n `ast-rule-runner: ${String(total - findings.length)} finding(s) omitted beyond ` +\n `limit=${String(limit)} (total=${String(total)})`\n );\n }\n\n return { findings, total, limit, filesScanned: files.length, filesSkipped, filesTruncated };\n}\n\n/**\n * Run the polyglot QA/security ast-grep rules and return the capped findings\n * array. Overflow beyond `limit` is counted and logged (never silently\n * dropped) — use {@link collectAstQaFindings} directly when the caller needs\n * the true total/overflow count programmatically.\n */\nexport async function runAstQaRules(opts: RunAstQaRulesOptions): Promise<AstRuleFinding[]> {\n const { findings } = await collectAstQaFindings(opts);\n return findings;\n}\n"],"mappings":";;;;;;;;;;;AAmCA,SAAS,kBAAkB;AAC3B,SAAS,SAAS,UAAU,YAAY;AACxC,SAAS,SAAS,SAAS,MAAM,UAAU,WAAW;AACtD,SAAS,qBAAqB;AAC9B,SAAS,OAAO,+BAA+B;AAK/C,OAAO,wBAAwB;AAC/B,OAA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AAM,CAAC,oCACxC,OAAO,KAAK,CAAC,WAAW,OAAO,KAAK,CAAC;AAAA,IAClD;AAAA,EACF;AAEA,SAAO,EAAE,UAAU,OAAO,OAAO,cAAc,MAAM,QAAQ,cAAc,eAAe;AAC5F;AAQA,eAAsB,cAAc,MAAuD;AACzF,QAAM,EAAE,SAAS,IAAI,MAAM,qBAAqB,IAAI;AACpD,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/security/ast-rule-runner.ts"],"sourcesContent":["/**\n * nexus-agents/security - Polyglot (Python/Go) AST QA/Security Rule Runner (#4249 child C)\n *\n * Runs YAML-defined `@ast-grep/napi` rules against Python/Go source, detecting\n * common QA/security anti-patterns (dynamic `eval`/`exec`, shell injection,\n * unchecked external command execution). Same engine already used by\n * `search_usages` (indexer/usage-ast.ts, #4265) and the ast-fixer rewrites\n * (agents/collaboration/ast-rewrites.ts, #4243/#4249 child B) — no new AST\n * dependency, just new language grammars for it.\n *\n * **Language support gap.** `Lang` in `@ast-grep/napi@0.44.1` ships only\n * Html/JavaScript/Tsx/Css/TypeScript — no Python, no Go. This module closes\n * that gap via napi's `@experimental registerDynamicLanguage` API, backed by\n * the `@ast-grep/lang-python`/`@ast-grep/lang-go` prebuilt tree-sitter\n * grammars. Both are EXACT-pinned in package.json (no caret): these are\n * early/experimental packages and a caret range could silently swap in an\n * incompatible native `.so` grammar build underneath a \"safe\" semver-minor\n * bump. `registerDynamicLanguage` throws if called more than once per\n * process (napi-rs's own documented constraint) — {@link ensurePolyglotLangs}\n * is a lazy, module-level, once-only guard so repeated calls (tests, repeat\n * runner invocations within one process) never trip it twice.\n *\n * **Read-only.** Reads rule YAML and target source files, walks their ASTs,\n * performs NO writes. ast-grep YAML rule files support a `fix:` key for\n * autofixing, but napi's `SgNode.findAll` (used here) never applies it —\n * only ast-grep's separate rewrite/CLI machinery does — so even a rule\n * author who adds `fix:` cannot turn this runner into a writer by accident.\n * MCP exposure is deliberately deferred (see the follow-up issue referenced\n * in the #4249 child C PR) to keep this surface a plain function until a\n * named consumer needs it wired through a tool.\n *\n * @module security/ast-rule-runner\n * @see Issue #4249 - epic: ast-grep adoption (Child C: polyglot QA/security rules)\n */\n\nimport { existsSync } from 'node:fs';\nimport { readdir, readFile, stat } from 'node:fs/promises';\nimport { dirname, extname, join, relative, sep } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { parse, registerDynamicLanguage } from '@ast-grep/napi';\nimport type { NapiConfig } from '@ast-grep/napi';\n// Both packages are CJS `export = <LanguageRegistration>` modules — the\n// default import is the whole registration object (`libraryPath` getter,\n// `extensions`, `languageSymbol`, `expandoChar`). See their `index.d.ts`.\nimport goLangRegistration from '@ast-grep/lang-go';\nimport pythonLangRegistration from '@ast-grep/lang-python';\nimport { parse as parseYaml } from 'yaml';\nimport { z } from 'zod';\nimport { createLogger, SecurityError, ValidationError, formatZodError } from '../core/index.js';\nimport { resolveInsideRoot } from './safe-path.js';\n\n// ============================================================================\n// Dynamic language registration (@experimental, call-once)\n// ============================================================================\n\nlet polyglotLangsRegistered = false;\n\n/**\n * Lazily register the Python/Go tree-sitter grammars with ast-grep's\n * `registerDynamicLanguage`. That API throws if called more than once in a\n * process; this guard makes every call after the first a no-op so repeated\n * runner invocations (or a test suite that constructs the runner many times)\n * never trip the constraint.\n */\nexport function ensurePolyglotLangs(): void {\n if (polyglotLangsRegistered) return;\n registerDynamicLanguage({ python: pythonLangRegistration, go: goLangRegistration });\n polyglotLangsRegistered = true;\n}\n\n// ============================================================================\n// Rule schema (fail-closed)\n// ============================================================================\n\n/** Languages a rule file may declare. Deliberately narrowed to the two this\n * runner actually SCANS (python/go): admitting `typescript`/`javascript` here\n * would let a TS/JS rule file validate at load time and then silently never\n * fire (there is no TS/JS extension in {@link POLYGLOT_EXT_TO_LANG}), which is\n * a fail-OPEN gap for a security scanner where \"no findings\" reads as \"clean\".\n * TS/JS structural analysis is already covered by `search_usages` (#4265) and\n * the ast-fixer rewrites (#4243); a TS/JS rule here would fail LOUD at load\n * (unknown-language Zod error) instead of loading dead. */\nexport const AST_RULE_LANGUAGES = ['python', 'go'] as const;\nexport type AstRuleLanguage = (typeof AST_RULE_LANGUAGES)[number];\n\nexport const AST_RULE_SEVERITIES = ['error', 'warning', 'info'] as const;\nexport type AstRuleSeverity = (typeof AST_RULE_SEVERITIES)[number];\n\n/** Schema for one `*.yml` rule file. `rule` is passed through as ast-grep's\n * own `Rule` object (napi already validates it structurally at match time);\n * Zod only pins down the envelope so an unknown `language` or a missing\n * field FAILS CLOSED instead of silently loading a partial/broken rule. */\nconst RuleFileSchema = z.object({\n id: z.string().min(1),\n language: z.enum(AST_RULE_LANGUAGES),\n severity: z.enum(AST_RULE_SEVERITIES),\n message: z.string().min(1),\n rule: z.record(z.string(), z.unknown()),\n});\n\nexport type AstQaRuleFile = z.infer<typeof RuleFileSchema>;\n\n/** Per-match snippet char cap (matches indexer/usage-ast.ts's discipline). */\nconst MAX_SNIPPET_CHARS = 200;\n\n/** Default cap on emitted findings. Excess is counted + reported, never silently dropped. */\nexport const DEFAULT_AST_QA_LIMIT = 200;\n/** Hard upper bound a caller may request for the finding cap. */\nexport const MAX_AST_QA_LIMIT = 2000;\n/** Directory walk depth for the target-dir scan (not caller-configurable — no\n * named consumer needs a deeper/shallower walk yet; YAGNI). */\nconst AST_QA_MAX_DEPTH = 24;\n/** Upper bound on files parsed in a single run, to bound worst-case cost.\n * Exceeding it makes the scan PARTIAL — surfaced via {@link AstQaCollectResult}'s\n * `filesTruncated`/`filesSkipped` + a warn, never silently dropped. */\nexport const MAX_FILES_SCANNED = 5000;\n\nconst logger = createLogger({ component: 'ast-rule-runner' });\n\n// ============================================================================\n// Rule loading\n// ============================================================================\n\n/**\n * Load and Zod-validate every `*.yml` rule file in `dir`. FAILS CLOSED: a\n * single malformed YAML file, or a file with an unrecognized `language` or\n * missing field, throws a {@link ValidationError} — there is no\n * \"load what parsed, skip the rest\" partial mode.\n */\nexport async function loadRules(dir: string): Promise<AstQaRuleFile[]> {\n let entries: string[];\n try {\n entries = (await readdir(dir)).filter((f) => f.endsWith('.yml') || f.endsWith('.yaml')).sort();\n } catch (caught: unknown) {\n const e = caught instanceof Error ? caught : new Error(String(caught));\n throw new ValidationError(`ast-rule-runner: cannot read rules dir ${dir}: ${e.message}`, {\n cause: e,\n });\n }\n\n const rules: AstQaRuleFile[] = [];\n for (const file of entries) {\n const path = join(dir, file);\n const raw = await readFile(path, 'utf8');\n\n let parsed: unknown;\n try {\n parsed = parseYaml(raw);\n } catch (caught: unknown) {\n const e = caught instanceof Error ? caught : new Error(String(caught));\n throw new ValidationError(`ast-rule-runner: malformed YAML in ${path}: ${e.message}`, {\n cause: e,\n });\n }\n\n const result = RuleFileSchema.safeParse(parsed);\n if (!result.success) {\n throw new ValidationError(\n `ast-rule-runner: invalid rule file ${path}: ${formatZodError(result.error)}`\n );\n }\n rules.push(result.data);\n }\n return rules;\n}\n\n// ============================================================================\n// Built-in rules dir resolution (mirrors workflows/template-loader.ts)\n// ============================================================================\n\n/**\n * Resolve the built-in `ast-rules/` directory, handling both dev (unbundled,\n * `src/security/ast-rule-runner.ts`) and published (bundled,\n * `dist/index.js` + `dist/security/ast-rules/*.yml` copied by tsup's\n * `onSuccess` step) layouts — the same two-layout problem\n * `getBuiltInTemplatesPath` solves for workflow templates.\n */\nexport function getBuiltInAstRulesPath(): string {\n const currentFile = fileURLToPath(import.meta.url);\n const currentDir = dirname(currentFile);\n\n if (currentFile.includes(`${sep}dist${sep}`) || currentFile.endsWith(`${sep}dist`)) {\n const distIndex = currentFile.lastIndexOf(`${sep}dist${sep}`);\n if (distIndex !== -1) {\n const distDir = currentFile.substring(0, distIndex + 5); // +5 for \"/dist\"\n const bundledPath = join(distDir, 'security', 'ast-rules');\n if (existsSync(bundledPath)) return bundledPath;\n }\n }\n\n const possiblePaths = [\n join(currentDir, 'ast-rules'), // Unbundled: sibling of this file in src/security/\n join(currentDir, 'security', 'ast-rules'), // Bundled chunk: dist/security sibling\n join(dirname(currentDir), 'security', 'ast-rules'),\n ];\n for (const path of possiblePaths) {\n if (existsSync(path)) return path;\n }\n return join(currentDir, 'ast-rules'); // Fallback (for error reporting)\n}\n\n// ============================================================================\n// Path-traversal guard (same shape as mcp/tools/search-usages-tool.ts)\n// ============================================================================\n\n/**\n * Resolve a caller path against a path-traversal guard (must stay within cwd).\n * Realpath-aware: a symlink inside cwd whose target is outside it is refused,\n * and the returned path is the canonical one the scan then walks.\n */\nfunction resolveWithinCwd(target: string): { resolved: string } | { error: string } {\n const resolved = resolveInsideRoot(target);\n if (resolved === null) {\n return { error: `Path traversal denied: scope must be within ${process.cwd()}` };\n }\n return { resolved };\n}\n\n// ============================================================================\n// File walk (LOCAL extension map — python/go only; does NOT reuse\n// indexer/usage-ast.ts's TS/JS inferLang or indexer/codebase-search.ts's\n// TS/JS-only findSourceFiles)\n// ============================================================================\n\nconst SKIP_DIRS = new Set(['node_modules', 'dist', '.git']);\n\n/** file-extension -> ast-rule language, for the two languages this runner scans. */\nconst POLYGLOT_EXT_TO_LANG: Readonly<Record<string, AstRuleLanguage>> = {\n '.py': 'python',\n '.go': 'go',\n};\n\n/** Infer the ast-rule language for a file from its extension, or `null` if unsupported. */\nfunction inferRuleLang(file: string): AstRuleLanguage | null {\n return POLYGLOT_EXT_TO_LANG[extname(file).toLowerCase()] ?? null;\n}\n\n/**\n * Recursively collect `.py`/`.go` files under `dir`, bounded by `maxDepth`.\n * A subdirectory whose `readdir` fails mid-walk (e.g. a `chmod 000` dir) is\n * WARNED about per-dir and skipped rather than silently swallowed — the scan\n * continues, but the partiality is surfaced in the log. The SCAN ROOT's own\n * readability is validated up front by {@link collectAstQaFindings} (fail\n * loud), so this soft-skip only ever applies to descendant dirs.\n */\nasync function findPolyglotFiles(dir: string, maxDepth: number): Promise<string[]> {\n if (maxDepth <= 0) return [];\n const out: string[] = [];\n let entries;\n try {\n entries = await readdir(dir, { withFileTypes: true });\n } catch (caught: unknown) {\n const e = caught instanceof Error ? caught : new Error(String(caught));\n logger.warn(`ast-rule-runner: skipped unreadable directory ${dir}: ${e.message}`);\n return out;\n }\n for (const entry of entries) {\n const fullPath = join(dir, entry.name);\n if (entry.isDirectory() && !SKIP_DIRS.has(entry.name)) {\n out.push(...(await findPolyglotFiles(fullPath, maxDepth - 1)));\n } else if (entry.isFile() && inferRuleLang(entry.name) !== null) {\n out.push(fullPath);\n }\n }\n return out;\n}\n\n/** Map a rule's declared language to the `parse()` first argument, registering\n * the dynamic grammars on first use. Both supported languages (python/go) are\n * dynamically-registered CustomLangs, so the language name string IS the\n * `parse()` key set up in {@link ensurePolyglotLangs}. */\nfunction langToParseArg(lang: AstRuleLanguage): AstRuleLanguage {\n ensurePolyglotLangs();\n return lang; // the CustomLang string keys used in registerDynamicLanguage()\n}\n\n// ============================================================================\n// Findings\n// ============================================================================\n\n/** One ast-grep rule match against a source file. */\nexport interface AstRuleFinding {\n ruleId: string;\n severity: AstRuleSeverity;\n message: string;\n /** Path relative to the resolved `targetDir`. */\n file: string;\n /** 1-based line number. */\n line: number;\n /** 1-based column number. */\n column: number;\n /** Trimmed, length-capped source line for the match. */\n snippet: string;\n}\n\nexport interface RunAstQaRulesOptions {\n /** Directory containing `*.yml` rule files (default: the built-in bundled rules). */\n rulesDir?: string;\n /** Directory to scan for `.py`/`.go` source files (must stay within cwd). */\n targetDir: string;\n /** Max findings emitted (default {@link DEFAULT_AST_QA_LIMIT}). Excess is counted + reported. */\n limit?: number;\n}\n\n/** {@link collectAstQaFindings}'s full result — findings plus the true total,\n * so overflow beyond `limit` is counted and reported, never silently dropped. */\nexport interface AstQaCollectResult {\n findings: AstRuleFinding[];\n /** True count of matches found, before the `limit` cap was applied. */\n total: number;\n limit: number;\n /** Number of `.py`/`.go` files actually scanned (after the file cap). */\n filesScanned: number;\n /** Number of discovered files DROPPED because the file cap ({@link MAX_FILES_SCANNED})\n * was exceeded. Non-zero means the scan was PARTIAL — a downstream consumer\n * must not treat empty/low findings as a clean bill of health. */\n filesSkipped: number;\n /** True iff `filesSkipped > 0` — the scan did not cover every candidate file. */\n filesTruncated: boolean;\n}\n\n/** Findings + true-match-count from scanning ONE already-read source file. */\ninterface FileScanResult {\n findings: AstRuleFinding[];\n total: number;\n}\n\n/** Bundles {@link scanFile}'s cap-tracking inputs (max-params discipline). */\ninterface FileScanBudget {\n /** Path emitted on each finding (relative to the resolved `targetDir`). */\n rel: string;\n /** Max TOTAL findings across the whole run. */\n limit: number;\n /** Findings already accepted by earlier files in this run. */\n alreadyFound: number;\n}\n\n/**\n * Scan one already-read source file against the rules applicable to its\n * language, pushing findings only while the running total (`budget.alreadyFound`\n * + findings pushed so far) stays under `budget.limit` — while still counting\n * every true match, so the caller can report overflow instead of silently\n * dropping it.\n */\nfunction scanFile(\n src: string,\n lang: AstRuleLanguage,\n applicable: readonly AstQaRuleFile[],\n budget: FileScanBudget\n): FileScanResult {\n const { rel, limit, alreadyFound } = budget;\n const root = parse(langToParseArg(lang), src).root();\n const lines = src.split('\\n');\n const findings: AstRuleFinding[] = [];\n let total = 0;\n\n for (const rule of applicable) {\n const config: NapiConfig = { rule: rule.rule };\n for (const node of root.findAll(config)) {\n total += 1;\n if (alreadyFound + findings.length < limit) {\n const { start } = node.range();\n const rawLine = lines[start.line] ?? node.text();\n findings.push({\n ruleId: rule.id,\n severity: rule.severity,\n message: rule.message,\n file: rel,\n line: start.line + 1,\n column: start.column + 1,\n snippet: rawLine.trim().slice(0, MAX_SNIPPET_CHARS),\n });\n }\n }\n }\n return { findings, total };\n}\n\n/**\n * Fail LOUD on an unreadable / non-directory scan root. `loadRules` already\n * throws on an unreadable RULES dir; the TARGET traversal must not fail OPEN —\n * a lone file path, a bad path, or a `000` root would otherwise return an empty\n * finding set that reads as \"clean\" for a security scanner.\n */\nasync function assertScanRootIsDirectory(resolved: string): Promise<void> {\n let rootStat;\n try {\n rootStat = await stat(resolved);\n } catch (caught: unknown) {\n const e = caught instanceof Error ? caught : new Error(String(caught));\n throw new ValidationError(`ast-rule-runner: cannot read targetDir ${resolved}: ${e.message}`, {\n cause: e,\n });\n }\n if (!rootStat.isDirectory()) {\n throw new ValidationError(\n `ast-rule-runner: targetDir must be a directory, got a non-directory path: ${resolved}`\n );\n }\n}\n\n/** Result of resolving the candidate file set under a scan root, with the\n * file-cap truncation signal surfaced (never a silent `.slice`). */\ninterface ScanFileSet {\n files: string[];\n filesSkipped: number;\n filesTruncated: boolean;\n}\n\n/** Discover candidate `.py`/`.go` files, applying + SURFACING the file cap. */\nasync function resolveScanFiles(root: string): Promise<ScanFileSet> {\n const discovered = await findPolyglotFiles(root, AST_QA_MAX_DEPTH);\n const files = discovered.slice(0, MAX_FILES_SCANNED);\n const filesSkipped = discovered.length - files.length;\n const filesTruncated = filesSkipped > 0;\n if (filesTruncated) {\n logger.warn(\n `ast-rule-runner: ${String(filesSkipped)} file(s) NOT scanned — file cap ` +\n `${String(MAX_FILES_SCANNED)} exceeded (discovered=${String(discovered.length)}). ` +\n `Scan is PARTIAL; do not treat findings as exhaustive.`\n );\n }\n return { files, filesSkipped, filesTruncated };\n}\n\n/**\n * Run every applicable rule in `rulesDir` against every `.py`/`.go` file under\n * `targetDir`, returning capped findings plus the true total (so callers that\n * need the overflow count — e.g. a future MCP tool wrapper — can report it).\n * {@link runAstQaRules} is the capped-array convenience wrapper over this.\n */\nexport async function collectAstQaFindings(\n opts: RunAstQaRulesOptions\n): Promise<AstQaCollectResult> {\n const guard = resolveWithinCwd(opts.targetDir);\n if ('error' in guard) {\n throw new SecurityError(guard.error);\n }\n await assertScanRootIsDirectory(guard.resolved);\n\n const rulesDir = opts.rulesDir ?? getBuiltInAstRulesPath();\n const rules = await loadRules(rulesDir);\n // Clamp into [1, MAX]: a limit <= 0 would report total > 0 with zero findings\n // (fail-open \"clean\" signal), so the floor is load-bearing, not cosmetic.\n const limit = Math.min(Math.max(opts.limit ?? DEFAULT_AST_QA_LIMIT, 1), MAX_AST_QA_LIMIT);\n\n const { files, filesSkipped, filesTruncated } = await resolveScanFiles(guard.resolved);\n\n const findings: AstRuleFinding[] = [];\n let total = 0;\n\n for (const file of files) {\n const lang = inferRuleLang(file);\n if (lang === null) continue;\n const applicable = rules.filter((r) => r.language === lang);\n if (applicable.length === 0) continue;\n\n let src: string;\n try {\n src = await readFile(file, 'utf8');\n } catch {\n logger.warn(`ast-rule-runner: skipped unreadable file ${file}`);\n continue;\n }\n\n const rel = relative(guard.resolved, file) || file;\n const scanned = scanFile(src, lang, applicable, { rel, limit, alreadyFound: findings.length });\n findings.push(...scanned.findings);\n total += scanned.total;\n }\n\n if (total > findings.length) {\n logger.warn(\n `ast-rule-runner: ${String(total - findings.length)} finding(s) omitted beyond ` +\n `limit=${String(limit)} (total=${String(total)})`\n );\n }\n\n return { findings, total, limit, filesScanned: files.length, filesSkipped, filesTruncated };\n}\n\n/**\n * Run the polyglot QA/security ast-grep rules and return the capped findings\n * array. Overflow beyond `limit` is counted and logged (never silently\n * dropped) — use {@link collectAstQaFindings} directly when the caller needs\n * the true total/overflow count programmatically.\n */\nexport async function runAstQaRules(opts: RunAstQaRulesOptions): Promise<AstRuleFinding[]> {\n const { findings } = await collectAstQaFindings(opts);\n return findings;\n}\n"],"mappings":";;;;;;;;;AAmCA,SAAS,kBAAkB;AAC3B,SAAS,SAAS,UAAU,YAAY;AACxC,SAAS,SAAS,SAAS,MAAM,UAAU,WAAW;AACtD,SAAS,qBAAqB;AAC9B,SAAS,OAAO,+BAA+B;AAK/C,OAAO,wBAAwB;AAC/B,OAAO,4BAA4B;AACnC,SAAS,SAAS,iBAAiB;AACnC,SAAS,SAAS;AAQlB,IAAI,0BAA0B;AASvB,SAAS,sBAA4B;AAC1C,MAAI,wBAAyB;AAC7B,0BAAwB,EAAE,QAAQ,wBAAwB,IAAI,mBAAmB,CAAC;AAClF,4BAA0B;AAC5B;AAcO,IAAM,qBAAqB,CAAC,UAAU,IAAI;AAG1C,IAAM,sBAAsB,CAAC,SAAS,WAAW,MAAM;AAO9D,IAAM,iBAAiB,EAAE,OAAO;AAAA,EAC9B,I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10
  WORKFLOW_TIMEOUTS
11
- } from "./chunk-PM2ECWCL.js";
11
+ } from "./chunk-MPXBYDWO.js";
12
12
  import {
13
13
  createGetToolRateLimit
14
14
  } from "./chunk-LWOX65CP.js";
@@ -223,4 +223,4 @@ export {
223
223
  CUSTOM_API_DEFAULT_MODEL,
224
224
  DEFAULTS
225
225
  };
226
- //# sourceMappingURL=chunk-G6C4CB2P.js.map
226
+ //# sourceMappingURL=chunk-3JHGB5IP.js.map
@@ -7,7 +7,7 @@ import {
7
7
  CACHE_TIMEOUTS,
8
8
  createLogger,
9
9
  getTimeProvider
10
- } from "./chunk-PM2ECWCL.js";
10
+ } from "./chunk-MPXBYDWO.js";
11
11
 
12
12
  // src/security/input-sanitizer.ts
13
13
  var DANGEROUS_HTML_PATTERN = /<(picture|source|img)\b[^>]*>[\s\S]*?<\/\1>|<(picture|source|img)\b[^>]*\/?>/gi;
@@ -509,4 +509,4 @@ export {
509
509
  resolveReputationGatingMode,
510
510
  gateWithReputation
511
511
  };
512
- //# sourceMappingURL=chunk-62T7LI7Y.js.map
512
+ //# sourceMappingURL=chunk-3VQO3MWD.js.map
@@ -5,17 +5,14 @@ import {
5
5
  getCurrentRequestContext,
6
6
  runWithRequestContext,
7
7
  serverCallerInfo
8
- } from "./chunk-4SZQYMMO.js";
9
- import {
10
- resolveInsideRoot
11
- } from "./chunk-XEPZSDN5.js";
8
+ } from "./chunk-QLHNL5Z6.js";
12
9
  import {
13
10
  DEFAULT_EXECUTION_MODE
14
11
  } from "./chunk-ECJ52NSK.js";
15
12
  import {
16
13
  sanitizeErrorDetails,
17
14
  sanitizeStringLeaves
18
- } from "./chunk-BJUIPCJ5.js";
15
+ } from "./chunk-VVH4Y6TK.js";
19
16
  import {
20
17
  CACHE_TIMEOUTS,
21
18
  MCP_TIMEOUTS,
@@ -31,8 +28,9 @@ import {
31
28
  getErrorMessage,
32
29
  getTimeProvider,
33
30
  ok,
31
+ resolveInsideRoot,
34
32
  resolveToolClassGuardMs
35
- } from "./chunk-PM2ECWCL.js";
33
+ } from "./chunk-MPXBYDWO.js";
36
34
  import {
37
35
  getNexusDataDir,
38
36
  parseBoolValue
@@ -2258,4 +2256,4 @@ export {
2258
2256
  DEFAULT_CONSENSUS_CONFIG,
2259
2257
  ConsensusMetricsSchema
2260
2258
  };
2261
- //# sourceMappingURL=chunk-LDKIDJQM.js.map
2259
+ //# sourceMappingURL=chunk-4HERVQZO.js.map