@herbertgao/pi-extensions 2026.10.0 → 2026.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -12
- package/THIRD_PARTY_NOTICES.md +3 -3
- package/node_modules/@dietrichgebert/ponytail/.opencode/command/ponytail-audit.md +2 -2
- package/node_modules/@dietrichgebert/ponytail/.opencode/command/ponytail-debt.md +2 -2
- package/node_modules/@dietrichgebert/ponytail/.opencode/command/ponytail-gain.md +1 -1
- package/node_modules/@dietrichgebert/ponytail/.opencode/command/ponytail-help.md +1 -1
- package/node_modules/@dietrichgebert/ponytail/.opencode/command/ponytail-review.md +2 -2
- package/node_modules/@dietrichgebert/ponytail/.opencode/command/ponytail.md +1 -1
- package/node_modules/@dietrichgebert/ponytail/.opencode/plugins/index.js +4 -0
- package/node_modules/@dietrichgebert/ponytail/.opencode/plugins/ponytail-frontmatter.cjs +43 -3
- package/node_modules/@dietrichgebert/ponytail/.opencode/plugins/ponytail.mjs +142 -59
- package/node_modules/@dietrichgebert/ponytail/.qoder/rules/ponytail.md +21 -21
- package/node_modules/@dietrichgebert/ponytail/.qoder-plugin/plugin.json +1 -1
- package/node_modules/@dietrichgebert/ponytail/AGENTS.md +21 -21
- package/node_modules/@dietrichgebert/ponytail/README.md +52 -242
- package/node_modules/@dietrichgebert/ponytail/hooks/claude-codex-hooks.json +3 -3
- package/node_modules/@dietrichgebert/ponytail/hooks/copilot-hooks.json +4 -4
- package/node_modules/@dietrichgebert/ponytail/hooks/ponytail-activate.js +70 -16
- package/node_modules/@dietrichgebert/ponytail/hooks/ponytail-config.js +8 -7
- package/node_modules/@dietrichgebert/ponytail/hooks/ponytail-instructions.js +30 -30
- package/node_modules/@dietrichgebert/ponytail/hooks/ponytail-map.js +103 -0
- package/node_modules/@dietrichgebert/ponytail/hooks/ponytail-mode-tracker.js +46 -23
- package/node_modules/@dietrichgebert/ponytail/hooks/ponytail-runtime.js +39 -7
- package/node_modules/@dietrichgebert/ponytail/hooks/ponytail-subagent.js +20 -3
- package/node_modules/@dietrichgebert/ponytail/hooks/qoder-hooks.json +3 -3
- package/node_modules/@dietrichgebert/ponytail/package.json +3 -3
- package/node_modules/@dietrichgebert/ponytail/pi-extension/index.js +47 -17
- package/node_modules/@dietrichgebert/ponytail/scripts/uninstall.js +21 -7
- package/node_modules/@dietrichgebert/ponytail/skills/plugin.json +5 -0
- package/node_modules/@dietrichgebert/ponytail/skills/ponytail/SKILL.md +33 -101
- package/node_modules/@dietrichgebert/ponytail/skills/ponytail-audit/SKILL.md +89 -27
- package/node_modules/@dietrichgebert/ponytail/skills/ponytail-debt/SKILL.md +13 -12
- package/node_modules/@dietrichgebert/ponytail/skills/ponytail-gain/SKILL.md +21 -18
- package/node_modules/@dietrichgebert/ponytail/skills/ponytail-help/SKILL.md +12 -13
- package/node_modules/@dietrichgebert/ponytail/skills/ponytail-review/SKILL.md +96 -52
- package/node_modules/@herbertgao/pi-agency/LICENSE +21 -0
- package/node_modules/@herbertgao/pi-agency/README.md +40 -0
- package/node_modules/@herbertgao/pi-agency/package.json +53 -0
- package/node_modules/@herbertgao/pi-agency/src/index.ts +441 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/compact-thinking.ts +12 -12
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/compact-mode.ts +30 -6
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/default-mode.ts +15 -9
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/interaction.ts +27 -9
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/codemode.ts +4 -1
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +2 -2
- package/node_modules/@narumitw/pi-caffeinate/package.json +4 -4
- package/node_modules/@tifan/pi-mermaid-open/package.json +5 -1
- package/node_modules/@tifan/pi-mermaid-open/src/index.ts +26 -9
- package/node_modules/@tifan/pi-recap/package.json +1 -1
- package/node_modules/@tifan/pi-recap/src/index.ts +104 -20
- package/node_modules/@tifan/pi-recap/src/models.ts +46 -4
- package/node_modules/pi-antigravity/README.md +23 -2
- package/node_modules/pi-antigravity/package.json +5 -3
- package/node_modules/pi-antigravity/src/diagnostics/diagnostics.ts +3 -2
- package/node_modules/pi-antigravity/src/features/generate-image.ts +72 -0
- package/node_modules/pi-antigravity/src/features/google-search.ts +71 -0
- package/node_modules/pi-antigravity/src/image/image.ts +86 -47
- package/node_modules/pi-antigravity/src/image/native.ts +69 -0
- package/node_modules/pi-antigravity/src/index.ts +52 -137
- package/node_modules/pi-antigravity/src/search/search.ts +130 -31
- package/node_modules/pi-antigravity/src/stream/stream.ts +162 -113
- package/node_modules/pi-antigravity/src/types/enums.ts +1 -0
- package/node_modules/pi-antigravity/src/types/types.ts +1 -1
- package/node_modules/pi-antigravity/src/utils/security.ts +47 -1
- package/node_modules/pi-antigravity/src/utils/util.ts +38 -6
- package/node_modules/pi-lens/CHANGELOG.md +1064 -0
- package/node_modules/pi-lens/README.md +115 -25
- package/node_modules/pi-lens/config/dependency-cruiser-eager-allowlist.json +6 -2
- package/node_modules/pi-lens/dist/chunk-22AVIGXS.js +560 -0
- package/node_modules/pi-lens/dist/chunk-27BBHSZC.js +106 -0
- package/node_modules/pi-lens/dist/chunk-2BEMIWEW.js +51 -0
- package/node_modules/pi-lens/dist/chunk-2EECBNC5.js +89 -0
- package/node_modules/pi-lens/dist/chunk-34U7PLGE.js +23 -0
- package/node_modules/pi-lens/dist/chunk-3I5QFT3N.js +181 -0
- package/node_modules/pi-lens/dist/chunk-3MED75HT.js +37 -0
- package/node_modules/pi-lens/dist/chunk-47D2BO4S.js +87 -0
- package/node_modules/pi-lens/dist/chunk-4RERDEXR.js +348 -0
- package/node_modules/pi-lens/dist/chunk-4W2PLC4J.js +27 -0
- package/node_modules/pi-lens/dist/chunk-52H5B5TC.js +202 -0
- package/node_modules/pi-lens/dist/chunk-54B42YRX.js +27 -0
- package/node_modules/pi-lens/dist/chunk-5RXBNSW2.js +266 -0
- package/node_modules/pi-lens/dist/chunk-5THXD6X5.js +201 -0
- package/node_modules/pi-lens/dist/chunk-5W3R6LFT.js +24 -0
- package/node_modules/pi-lens/dist/chunk-5ZEJHV35.js +341 -0
- package/node_modules/pi-lens/dist/chunk-6P62QVEA.js +118 -0
- package/node_modules/pi-lens/dist/chunk-6QIUX4EP.js +459 -0
- package/node_modules/pi-lens/dist/chunk-6VCD4VKZ.js +78 -0
- package/node_modules/pi-lens/dist/chunk-7F72PXY2.js +326 -0
- package/node_modules/pi-lens/dist/chunk-7FBF7NPR.js +998 -0
- package/node_modules/pi-lens/dist/chunk-7U2IDNXN.js +37 -0
- package/node_modules/pi-lens/dist/chunk-ABBOA7UD.js +157 -0
- package/node_modules/pi-lens/dist/chunk-AHDW3GPE.js +50 -0
- package/node_modules/pi-lens/dist/chunk-AJ3QXTRQ.js +756 -0
- package/node_modules/pi-lens/dist/chunk-AJVLWNFN.js +1610 -0
- package/node_modules/pi-lens/dist/chunk-AJXODZY6.js +112 -0
- package/node_modules/pi-lens/dist/chunk-ARFCXG7S.js +84 -0
- package/node_modules/pi-lens/dist/chunk-AS44CFQ4.js +708 -0
- package/node_modules/pi-lens/dist/chunk-AWE5TMPO.js +38 -0
- package/node_modules/pi-lens/dist/chunk-B3I2UUT4.js +4692 -0
- package/node_modules/pi-lens/dist/chunk-BRJKOBZP.js +331 -0
- package/node_modules/pi-lens/dist/chunk-BW5KFIQC.js +59 -0
- package/node_modules/pi-lens/dist/chunk-C2AUYXQH.js +149 -0
- package/node_modules/pi-lens/dist/chunk-CGGAIP7J.js +29 -0
- package/node_modules/pi-lens/dist/chunk-D6QS3U6M.js +30 -0
- package/node_modules/pi-lens/dist/chunk-DFVMIKMQ.js +349 -0
- package/node_modules/pi-lens/dist/chunk-DIULIWKU.js +169 -0
- package/node_modules/pi-lens/dist/chunk-DQ2NZ7C4.js +2317 -0
- package/node_modules/pi-lens/dist/chunk-E2WFBRHM.js +213 -0
- package/node_modules/pi-lens/dist/chunk-E4MAEDPM.js +50 -0
- package/node_modules/pi-lens/dist/chunk-EOKRQ3SA.js +30 -0
- package/node_modules/pi-lens/dist/chunk-F3AU2TMM.js +2626 -0
- package/node_modules/pi-lens/dist/chunk-F3P7VQ7H.js +170 -0
- package/node_modules/pi-lens/dist/chunk-FC4RP4I2.js +12 -0
- package/node_modules/pi-lens/dist/chunk-FJNKANOS.js +32 -0
- package/node_modules/pi-lens/dist/chunk-GUOGVTCQ.js +146 -0
- package/node_modules/pi-lens/dist/chunk-GVXA6CCE.js +18 -0
- package/node_modules/pi-lens/dist/chunk-HHYAELLJ.js +2334 -0
- package/node_modules/pi-lens/dist/chunk-HMFXILPV.js +83 -0
- package/node_modules/pi-lens/dist/chunk-HVUZXSWK.js +421 -0
- package/node_modules/pi-lens/dist/chunk-HWBZIGMJ.js +62 -0
- package/node_modules/pi-lens/dist/chunk-I3R7GKDR.js +17 -0
- package/node_modules/pi-lens/dist/chunk-I7SPGOWI.js +55 -0
- package/node_modules/pi-lens/dist/chunk-IIXOAGHR.js +38 -0
- package/node_modules/pi-lens/dist/chunk-IVP5KAB7.js +2250 -0
- package/node_modules/pi-lens/dist/chunk-IXEBJSUE.js +22 -0
- package/node_modules/pi-lens/dist/chunk-JOLITGCC.js +27 -0
- package/node_modules/pi-lens/dist/chunk-K6VYLB2U.js +145 -0
- package/node_modules/pi-lens/dist/chunk-LJDODBBZ.js +78 -0
- package/node_modules/pi-lens/dist/chunk-LNAKEO63.js +78 -0
- package/node_modules/pi-lens/dist/chunk-LSMJ6KBE.js +4139 -0
- package/node_modules/pi-lens/dist/chunk-LW6XKDZQ.js +5565 -0
- package/node_modules/pi-lens/dist/chunk-N3YQJI6O.js +899 -0
- package/node_modules/pi-lens/dist/chunk-NABLC7W3.js +148 -0
- package/node_modules/pi-lens/dist/chunk-NKOUFPQF.js +659 -0
- package/node_modules/pi-lens/dist/chunk-NL5GLMFI.js +211 -0
- package/node_modules/pi-lens/dist/chunk-NMABWBZN.js +327 -0
- package/node_modules/pi-lens/dist/chunk-NTHH2J74.js +27 -0
- package/node_modules/pi-lens/dist/chunk-NTUJEGDZ.js +59 -0
- package/node_modules/pi-lens/dist/chunk-NXL4FFQQ.js +47 -0
- package/node_modules/pi-lens/dist/chunk-NXPS2L6U.js +466 -0
- package/node_modules/pi-lens/dist/chunk-O5WILGMI.js +42 -0
- package/node_modules/pi-lens/dist/chunk-O6TQT6RI.js +48 -0
- package/node_modules/pi-lens/dist/chunk-OAXNDZJ7.js +323 -0
- package/node_modules/pi-lens/dist/chunk-ODEEOXPH.js +44 -0
- package/node_modules/pi-lens/dist/chunk-OQGFCZJ4.js +4533 -0
- package/node_modules/pi-lens/dist/chunk-ORTMY4Q4.js +282 -0
- package/node_modules/pi-lens/dist/chunk-OS32RNR2.js +442 -0
- package/node_modules/pi-lens/dist/chunk-PAK6IDME.js +189 -0
- package/node_modules/pi-lens/dist/chunk-PWFHBTSF.js +406 -0
- package/node_modules/pi-lens/dist/chunk-Q5U6FMDI.js +2352 -0
- package/node_modules/pi-lens/dist/chunk-QOZXJ4NA.js +3364 -0
- package/node_modules/pi-lens/dist/chunk-QYF5S6P6.js +45 -0
- package/node_modules/pi-lens/dist/chunk-RIISMHKN.js +36 -0
- package/node_modules/pi-lens/dist/chunk-RPD4ZSB7.js +25 -0
- package/node_modules/pi-lens/dist/chunk-RPD5K5NC.js +79 -0
- package/node_modules/pi-lens/dist/chunk-RUOG5D2C.js +262 -0
- package/node_modules/pi-lens/dist/chunk-T4ERT73Y.js +599 -0
- package/node_modules/pi-lens/dist/chunk-T6D4Q4AQ.js +54 -0
- package/node_modules/pi-lens/dist/chunk-TGPXLY2J.js +391 -0
- package/node_modules/pi-lens/dist/chunk-TLGFBM3F.js +12116 -0
- package/node_modules/pi-lens/dist/chunk-TO6WL3GM.js +88 -0
- package/node_modules/pi-lens/dist/chunk-TT22N74J.js +517 -0
- package/node_modules/pi-lens/dist/chunk-TVN5N6GY.js +21216 -0
- package/node_modules/pi-lens/dist/chunk-U3VGR4VU.js +308 -0
- package/node_modules/pi-lens/dist/chunk-UK3CMEAL.js +1250 -0
- package/node_modules/pi-lens/dist/chunk-UOPVJQ4N.js +103 -0
- package/node_modules/pi-lens/dist/chunk-UXVNL3D7.js +23 -0
- package/node_modules/pi-lens/dist/chunk-UY752QSN.js +45 -0
- package/node_modules/pi-lens/dist/chunk-V5PXFSZK.js +188 -0
- package/node_modules/pi-lens/dist/chunk-V7R425XG.js +398 -0
- package/node_modules/pi-lens/dist/chunk-VCSRSYLF.js +81 -0
- package/node_modules/pi-lens/dist/chunk-VD4JQCQC.js +162 -0
- package/node_modules/pi-lens/dist/chunk-VDBPVIKD.js +62 -0
- package/node_modules/pi-lens/dist/chunk-VHQLPIRJ.js +114 -0
- package/node_modules/pi-lens/dist/chunk-VN2AXLEX.js +5414 -0
- package/node_modules/pi-lens/dist/chunk-VNMT7C64.js +478 -0
- package/node_modules/pi-lens/dist/chunk-WONERJTP.js +309 -0
- package/node_modules/pi-lens/dist/chunk-XECLWQZN.js +85 -0
- package/node_modules/pi-lens/dist/chunk-XIMYZ3JA.js +27 -0
- package/node_modules/pi-lens/dist/chunk-XK4CIILI.js +144 -0
- package/node_modules/pi-lens/dist/chunk-Y4T27COV.js +562 -0
- package/node_modules/pi-lens/dist/chunk-YGVYKNSN.js +1860 -0
- package/node_modules/pi-lens/dist/chunk-YLF3PPT5.js +308 -0
- package/node_modules/pi-lens/dist/chunk-YSNFMJKN.js +14 -0
- package/node_modules/pi-lens/dist/chunk-Z3CCVDUB.js +76 -0
- package/node_modules/pi-lens/dist/chunk-Z54ZSOBZ.js +61 -0
- package/node_modules/pi-lens/dist/chunk-ZAWW3AF6.js +97 -0
- package/node_modules/pi-lens/dist/chunk-ZMOL6RQC.js +167 -0
- package/node_modules/pi-lens/dist/index.js +16456 -8335
- package/node_modules/pi-lens/dist/mcp/analyze-cli.js +186 -232
- package/node_modules/pi-lens/dist/mcp/cli.js +137 -98
- package/node_modules/pi-lens/dist/mcp/server.js +22589 -1573
- package/node_modules/pi-lens/dist/mcp/worker.js +97 -38
- package/node_modules/pi-lens/dist/probes/installer.js +135 -0
- package/node_modules/pi-lens/dist/workers/project-snapshot-persist-worker.js +22 -0
- package/node_modules/pi-lens/dist/workers/review-graph-persist-worker.js +15 -0
- package/node_modules/pi-lens/docs/agent-guide.md +13 -4
- package/node_modules/pi-lens/docs/agent-tools.md +42 -0
- package/node_modules/pi-lens/docs/ast-grep_rules_catalog.md +3 -2
- package/node_modules/pi-lens/docs/configuration.md +20 -1
- package/node_modules/pi-lens/docs/environment-variables.md +52 -2
- package/node_modules/pi-lens/docs/features.md +8 -4
- package/node_modules/pi-lens/docs/globalconfig.md +1 -0
- package/node_modules/pi-lens/docs/io-bridge-v2-migration.md +94 -0
- package/node_modules/pi-lens/docs/lsp-capability-matrix.md +36 -4
- package/node_modules/pi-lens/docs/lsp-idle-eviction.md +124 -0
- package/node_modules/pi-lens/docs/mcp.md +21 -5
- package/node_modules/pi-lens/docs/merge-queue-rollout.md +77 -0
- package/node_modules/pi-lens/docs/pi-lens-fixer.md +156 -88
- package/node_modules/pi-lens/docs/pi-lens-investigator.md +74 -26
- package/node_modules/pi-lens/docs/pi-lens-merge-policy.md +694 -0
- package/node_modules/pi-lens/docs/pi-lens-monitor.md +73 -7
- package/node_modules/pi-lens/docs/pi-lens-retro.md +6 -4
- package/node_modules/pi-lens/docs/pi-lens-reviewer.md +188 -48
- package/node_modules/pi-lens/docs/pi-lens-subagent.md +246 -45
- package/node_modules/pi-lens/docs/pi-lens-warden.md +18 -7
- package/node_modules/pi-lens/docs/public-api-stability.md +55 -0
- package/node_modules/pi-lens/docs/release-qa-baseline.md +84 -17
- package/node_modules/pi-lens/docs/rfcs/3654-unified-io-bridge-v2.md +316 -0
- package/node_modules/pi-lens/docs/servercapabilities.md +53 -49
- package/node_modules/pi-lens/docs/settings.md +1 -0
- package/node_modules/pi-lens/docs/usage.md +5 -1
- package/node_modules/pi-lens/grammars/tree-sitter-bash.wasm +0 -0
- package/node_modules/pi-lens/grammars/tree-sitter-bash.wasm.json +3 -3
- package/node_modules/pi-lens/package.json +18 -6
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/advisory-registry-subset-test.yml +41 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/advisory-registry-subset.yml +50 -0
- package/node_modules/pi-lens/scripts/analyze-pi-lens-logs.mjs +1275 -62
- package/node_modules/pi-lens/scripts/download-grammars.js +5 -0
- package/node_modules/pi-lens/scripts/grammars.lock.json +6 -1
- package/node_modules/pi-lens/scripts/install-selftest.mjs +33 -34
- package/node_modules/pi-lens/scripts/lib/host-provided-deps.mjs +13 -4
- package/node_modules/pi-lens/scripts/lib/web-tree-sitter-dir.mjs +18 -0
- package/node_modules/pi-typesafe/README.md +1 -1
- package/node_modules/pi-typesafe/dist/backends.d.ts +15 -5
- package/node_modules/pi-typesafe/dist/backends.js +18 -0
- package/node_modules/pi-typesafe/dist/client.d.ts +4 -3
- package/node_modules/pi-typesafe/dist/client.js +22 -7
- package/node_modules/pi-typesafe/dist/index.d.ts +2 -2
- package/node_modules/pi-typesafe/dist/index.js +1 -1
- package/node_modules/pi-typesafe/dist/usage.d.ts +14 -4
- package/node_modules/pi-typesafe/dist/usage.js +147 -42
- package/node_modules/pi-typesafe/package.json +1 -1
- package/node_modules/pi-web-access/CHANGELOG.md +48 -0
- package/node_modules/pi-web-access/README.md +57 -11
- package/node_modules/pi-web-access/brave-rate-limit.ts +8 -2
- package/node_modules/pi-web-access/curator-page.ts +5 -1
- package/node_modules/pi-web-access/curator-server.ts +2 -0
- package/node_modules/pi-web-access/declared-web-links.ts +2 -2
- package/node_modules/pi-web-access/degoog.ts +323 -0
- package/node_modules/pi-web-access/dist/index.js +3483 -2745
- package/node_modules/pi-web-access/dist/mcp-cli.js +27443 -0
- package/node_modules/pi-web-access/exa.ts +5 -1
- package/node_modules/pi-web-access/extract.ts +41 -3
- package/node_modules/pi-web-access/firecrawl.ts +35 -4
- package/node_modules/pi-web-access/gemini-search.ts +34 -11
- package/node_modules/pi-web-access/gemini-web.ts +14 -9
- package/node_modules/pi-web-access/index.ts +153 -1202
- package/node_modules/pi-web-access/keenable.ts +221 -0
- package/node_modules/pi-web-access/mcp-cli.ts +40 -0
- package/node_modules/pi-web-access/mcp-server.ts +81 -0
- package/node_modules/pi-web-access/mcp-tool-definitions.ts +117 -0
- package/node_modules/pi-web-access/openai-search.ts +34 -1
- package/node_modules/pi-web-access/package.json +23 -5
- package/node_modules/pi-web-access/perplexity.ts +64 -56
- package/node_modules/pi-web-access/tool-arguments.ts +20 -0
- package/node_modules/pi-web-access/video-extract.ts +1 -1
- package/node_modules/pi-web-access/web-tool-contract.ts +86 -0
- package/node_modules/pi-web-access/web-tool-core.ts +1502 -0
- package/node_modules/pi-web-access/youtube-extract.ts +2 -5
- package/package.json +17 -12
- package/node_modules/@dietrichgebert/ponytail/README.es.md +0 -329
- package/node_modules/@dietrichgebert/ponytail/README.ko.md +0 -346
- package/node_modules/@dietrichgebert/ponytail/assets/benchmark-3model.svg +0 -21
- package/node_modules/@dietrichgebert/ponytail/assets/benchmark-agentic.svg +0 -62
- package/node_modules/@dietrichgebert/ponytail/assets/logo-dark.png +0 -0
- package/node_modules/@dietrichgebert/ponytail/assets/logo-dark.svg +0 -115
- package/node_modules/@dietrichgebert/ponytail/assets/logo-greenpt-dark.svg +0 -27
- package/node_modules/@dietrichgebert/ponytail/assets/logo-greenpt.svg +0 -27
- package/node_modules/@dietrichgebert/ponytail/assets/logo.png +0 -0
- package/node_modules/@dietrichgebert/ponytail/assets/retriever-icon.png +0 -0
- package/node_modules/@dietrichgebert/ponytail/assets/retriever-logo-dark.svg +0 -4
- package/node_modules/@dietrichgebert/ponytail/assets/retriever-logo-light.svg +0 -4
- package/node_modules/@dietrichgebert/ponytail/assets/social-preview.png +0 -0
- package/node_modules/@dietrichgebert/ponytail/assets/waitlist-banner-es.png +0 -0
- package/node_modules/@dietrichgebert/ponytail/assets/waitlist-banner-ko.png +0 -0
- package/node_modules/@dietrichgebert/ponytail/assets/waitlist-banner.png +0 -0
- package/node_modules/pi-lens/dist/clients/actionable-warnings-logger.js +0 -35
- package/node_modules/pi-lens/dist/clients/actionable-warnings.js +0 -1610
- package/node_modules/pi-lens/dist/clients/advisory-provenance.js +0 -593
- package/node_modules/pi-lens/dist/clients/agent-behavior-client.js +0 -147
- package/node_modules/pi-lens/dist/clients/agent-nudge.js +0 -325
- package/node_modules/pi-lens/dist/clients/analysed-root.js +0 -1
- package/node_modules/pi-lens/dist/clients/ast-grep-client.js +0 -731
- package/node_modules/pi-lens/dist/clients/ast-grep-rule-manager.js +0 -146
- package/node_modules/pi-lens/dist/clients/ast-grep-tool-logger.js +0 -118
- package/node_modules/pi-lens/dist/clients/ast-grep-types.js +0 -10
- package/node_modules/pi-lens/dist/clients/ast-grep-yaml-synth.js +0 -154
- package/node_modules/pi-lens/dist/clients/atomic-write-staging.js +0 -75
- package/node_modules/pi-lens/dist/clients/atomic-write.js +0 -189
- package/node_modules/pi-lens/dist/clients/availability-probe-flight.js +0 -12
- package/node_modules/pi-lens/dist/clients/bash-file-access.js +0 -1056
- package/node_modules/pi-lens/dist/clients/biome-client.js +0 -357
- package/node_modules/pi-lens/dist/clients/blocker-freshness.js +0 -837
- package/node_modules/pi-lens/dist/clients/blocker-past-eof.js +0 -129
- package/node_modules/pi-lens/dist/clients/bootstrap.js +0 -569
- package/node_modules/pi-lens/dist/clients/bounded-cache.js +0 -190
- package/node_modules/pi-lens/dist/clients/bounded-pid-file-lock.js +0 -202
- package/node_modules/pi-lens/dist/clients/bounded-telemetry.js +0 -295
- package/node_modules/pi-lens/dist/clients/build-identity.js +0 -95
- package/node_modules/pi-lens/dist/clients/bundled-resource-health.js +0 -113
- package/node_modules/pi-lens/dist/clients/bus-events-logger.js +0 -105
- package/node_modules/pi-lens/dist/clients/bus-publish.js +0 -171
- package/node_modules/pi-lens/dist/clients/cache/rule-cache.js +0 -190
- package/node_modules/pi-lens/dist/clients/cache-manager.js +0 -524
- package/node_modules/pi-lens/dist/clients/cache-observability.js +0 -1313
- package/node_modules/pi-lens/dist/clients/call-graph.js +0 -852
- package/node_modules/pi-lens/dist/clients/cargo-manifest.js +0 -422
- package/node_modules/pi-lens/dist/clients/cascade-budget.js +0 -196
- package/node_modules/pi-lens/dist/clients/cascade-format.js +0 -315
- package/node_modules/pi-lens/dist/clients/cascade-logger.js +0 -31
- package/node_modules/pi-lens/dist/clients/cascade-types.js +0 -9
- package/node_modules/pi-lens/dist/clients/child-unref.js +0 -124
- package/node_modules/pi-lens/dist/clients/code-quality-warnings.js +0 -286
- package/node_modules/pi-lens/dist/clients/codebase-model.js +0 -173
- package/node_modules/pi-lens/dist/clients/collateral-test-role.js +0 -40
- package/node_modules/pi-lens/dist/clients/complexity-client.js +0 -462
- package/node_modules/pi-lens/dist/clients/config-core/deny.js +0 -221
- package/node_modules/pi-lens/dist/clients/config-core/index.js +0 -50
- package/node_modules/pi-lens/dist/clients/config-core/merge.js +0 -357
- package/node_modules/pi-lens/dist/clients/config-core/normalize.js +0 -340
- package/node_modules/pi-lens/dist/clients/config-core/process-spec.js +0 -248
- package/node_modules/pi-lens/dist/clients/config-core/provenance.js +0 -164
- package/node_modules/pi-lens/dist/clients/config-core/records.js +0 -218
- package/node_modules/pi-lens/dist/clients/config-core/resolve.js +0 -125
- package/node_modules/pi-lens/dist/clients/config-core/safe-object.js +0 -78
- package/node_modules/pi-lens/dist/clients/config-core/schema.js +0 -165
- package/node_modules/pi-lens/dist/clients/config-diagnostic-codes.js +0 -285
- package/node_modules/pi-lens/dist/clients/config-locations.js +0 -388
- package/node_modules/pi-lens/dist/clients/config-resolve.js +0 -798
- package/node_modules/pi-lens/dist/clients/config-schema.js +0 -251
- package/node_modules/pi-lens/dist/clients/config-warn.js +0 -407
- package/node_modules/pi-lens/dist/clients/console-guard-install.js +0 -26
- package/node_modules/pi-lens/dist/clients/cooperative-budget.js +0 -42
- package/node_modules/pi-lens/dist/clients/dead-code-client.js +0 -510
- package/node_modules/pi-lens/dist/clients/dead-code-logger.js +0 -30
- package/node_modules/pi-lens/dist/clients/deadline-utils.js +0 -280
- package/node_modules/pi-lens/dist/clients/debug-handles.js +0 -211
- package/node_modules/pi-lens/dist/clients/debug-heap.js +0 -174
- package/node_modules/pi-lens/dist/clients/deferred-lsp-work.js +0 -106
- package/node_modules/pi-lens/dist/clients/degradation-ledger.js +0 -426
- package/node_modules/pi-lens/dist/clients/demoted-finding-render.js +0 -169
- package/node_modules/pi-lens/dist/clients/dependency-checker.js +0 -885
- package/node_modules/pi-lens/dist/clients/deps/ast-grep-napi.js +0 -22
- package/node_modules/pi-lens/dist/clients/deps/js-yaml.js +0 -9
- package/node_modules/pi-lens/dist/clients/deps/minimatch.js +0 -4
- package/node_modules/pi-lens/dist/clients/deps/pi-tui.js +0 -14
- package/node_modules/pi-lens/dist/clients/deps/typebox.js +0 -14
- package/node_modules/pi-lens/dist/clients/deps/vscode-jsonrpc.js +0 -1
- package/node_modules/pi-lens/dist/clients/deps/web-tree-sitter.js +0 -24
- package/node_modules/pi-lens/dist/clients/diagnostic-dispositions.js +0 -630
- package/node_modules/pi-lens/dist/clients/diagnostic-line-freshness.js +0 -305
- package/node_modules/pi-lens/dist/clients/diagnostic-logger.js +0 -73
- package/node_modules/pi-lens/dist/clients/diagnostic-tracker.js +0 -105
- package/node_modules/pi-lens/dist/clients/diagnostics-publish.js +0 -230
- package/node_modules/pi-lens/dist/clients/dispatch/ast-grep-catalog.js +0 -65
- package/node_modules/pi-lens/dist/clients/dispatch/auxiliary-lsp.js +0 -343
- package/node_modules/pi-lens/dist/clients/dispatch/collect-later-tier.js +0 -35
- package/node_modules/pi-lens/dist/clients/dispatch/diagnostic-taxonomy.js +0 -66
- package/node_modules/pi-lens/dist/clients/dispatch/dispatcher.js +0 -1269
- package/node_modules/pi-lens/dist/clients/dispatch/fact-provider-types.js +0 -1
- package/node_modules/pi-lens/dist/clients/dispatch/fact-rule-runner.js +0 -17
- package/node_modules/pi-lens/dist/clients/dispatch/fact-runner.js +0 -30
- package/node_modules/pi-lens/dist/clients/dispatch/fact-scheduler.js +0 -68
- package/node_modules/pi-lens/dist/clients/dispatch/fact-store.js +0 -377
- package/node_modules/pi-lens/dist/clients/dispatch/facts/comment-facts.js +0 -22
- package/node_modules/pi-lens/dist/clients/dispatch/facts/file-content.js +0 -19
- package/node_modules/pi-lens/dist/clients/dispatch/facts/function-facts.js +0 -348
- package/node_modules/pi-lens/dist/clients/dispatch/facts/import-facts.js +0 -204
- package/node_modules/pi-lens/dist/clients/dispatch/facts/tree-sitter-facts.js +0 -34
- package/node_modules/pi-lens/dist/clients/dispatch/facts/try-catch-facts.js +0 -119
- package/node_modules/pi-lens/dist/clients/dispatch/finding-policy.js +0 -339
- package/node_modules/pi-lens/dist/clients/dispatch/indent-detect.js +0 -417
- package/node_modules/pi-lens/dist/clients/dispatch/inline-suppressions.js +0 -89
- package/node_modules/pi-lens/dist/clients/dispatch/integration.js +0 -2377
- package/node_modules/pi-lens/dist/clients/dispatch/lazy.js +0 -11
- package/node_modules/pi-lens/dist/clients/dispatch/pending-runner-findings.js +0 -87
- package/node_modules/pi-lens/dist/clients/dispatch/plan.js +0 -278
- package/node_modules/pi-lens/dist/clients/dispatch/priorities.js +0 -20
- package/node_modules/pi-lens/dist/clients/dispatch/rule-id-normalize.js +0 -50
- package/node_modules/pi-lens/dist/clients/dispatch/rule-ignores.js +0 -69
- package/node_modules/pi-lens/dist/clients/dispatch/rule-policy.js +0 -135
- package/node_modules/pi-lens/dist/clients/dispatch/rules/async-noise.js +0 -40
- package/node_modules/pi-lens/dist/clients/dispatch/rules/async-unnecessary-wrapper.js +0 -27
- package/node_modules/pi-lens/dist/clients/dispatch/rules/cors-wildcard.js +0 -54
- package/node_modules/pi-lens/dist/clients/dispatch/rules/error-obscuring.js +0 -32
- package/node_modules/pi-lens/dist/clients/dispatch/rules/error-swallowing.js +0 -31
- package/node_modules/pi-lens/dist/clients/dispatch/rules/framework-call-noise.js +0 -67
- package/node_modules/pi-lens/dist/clients/dispatch/rules/high-complexity.js +0 -72
- package/node_modules/pi-lens/dist/clients/dispatch/rules/high-fan-out.js +0 -74
- package/node_modules/pi-lens/dist/clients/dispatch/rules/high-import-coupling.js +0 -37
- package/node_modules/pi-lens/dist/clients/dispatch/rules/missing-error-propagation.js +0 -62
- package/node_modules/pi-lens/dist/clients/dispatch/rules/no-commented-credentials.js +0 -52
- package/node_modules/pi-lens/dist/clients/dispatch/rules/pass-through-wrappers.js +0 -42
- package/node_modules/pi-lens/dist/clients/dispatch/rules/placeholder-comments.js +0 -40
- package/node_modules/pi-lens/dist/clients/dispatch/rules/unsafe-boundary.js +0 -126
- package/node_modules/pi-lens/dist/clients/dispatch/runner-context.js +0 -52
- package/node_modules/pi-lens/dist/clients/dispatch/runners/actionlint.js +0 -111
- package/node_modules/pi-lens/dist/clients/dispatch/runners/ast-grep-napi.js +0 -1196
- package/node_modules/pi-lens/dist/clients/dispatch/runners/biome-check.js +0 -296
- package/node_modules/pi-lens/dist/clients/dispatch/runners/cpp-check.js +0 -219
- package/node_modules/pi-lens/dist/clients/dispatch/runners/credo.js +0 -82
- package/node_modules/pi-lens/dist/clients/dispatch/runners/cue-vet.js +0 -416
- package/node_modules/pi-lens/dist/clients/dispatch/runners/dart-analyze.js +0 -183
- package/node_modules/pi-lens/dist/clients/dispatch/runners/detekt.js +0 -176
- package/node_modules/pi-lens/dist/clients/dispatch/runners/dotnet-build.js +0 -164
- package/node_modules/pi-lens/dist/clients/dispatch/runners/elixir-check.js +0 -195
- package/node_modules/pi-lens/dist/clients/dispatch/runners/eslint.js +0 -137
- package/node_modules/pi-lens/dist/clients/dispatch/runners/fact-rules.js +0 -29
- package/node_modules/pi-lens/dist/clients/dispatch/runners/fish-indent.js +0 -69
- package/node_modules/pi-lens/dist/clients/dispatch/runners/gleam-check.js +0 -167
- package/node_modules/pi-lens/dist/clients/dispatch/runners/go-vet.js +0 -104
- package/node_modules/pi-lens/dist/clients/dispatch/runners/golangci-lint.js +0 -135
- package/node_modules/pi-lens/dist/clients/dispatch/runners/hadolint.js +0 -91
- package/node_modules/pi-lens/dist/clients/dispatch/runners/helm-lint.js +0 -171
- package/node_modules/pi-lens/dist/clients/dispatch/runners/helm-render.js +0 -940
- package/node_modules/pi-lens/dist/clients/dispatch/runners/htmlhint.js +0 -117
- package/node_modules/pi-lens/dist/clients/dispatch/runners/index.js +0 -108
- package/node_modules/pi-lens/dist/clients/dispatch/runners/javac.js +0 -99
- package/node_modules/pi-lens/dist/clients/dispatch/runners/ktlint.js +0 -110
- package/node_modules/pi-lens/dist/clients/dispatch/runners/lsp.js +0 -379
- package/node_modules/pi-lens/dist/clients/dispatch/runners/markdownlint.js +0 -167
- package/node_modules/pi-lens/dist/clients/dispatch/runners/mypy.js +0 -102
- package/node_modules/pi-lens/dist/clients/dispatch/runners/oxlint.js +0 -414
- package/node_modules/pi-lens/dist/clients/dispatch/runners/php-lint.js +0 -85
- package/node_modules/pi-lens/dist/clients/dispatch/runners/phpstan.js +0 -120
- package/node_modules/pi-lens/dist/clients/dispatch/runners/prisma-validate.js +0 -62
- package/node_modules/pi-lens/dist/clients/dispatch/runners/psscriptanalyzer.js +0 -445
- package/node_modules/pi-lens/dist/clients/dispatch/runners/pyright.js +0 -169
- package/node_modules/pi-lens/dist/clients/dispatch/runners/rubocop.js +0 -99
- package/node_modules/pi-lens/dist/clients/dispatch/runners/ruff.js +0 -88
- package/node_modules/pi-lens/dist/clients/dispatch/runners/rust-clippy.js +0 -256
- package/node_modules/pi-lens/dist/clients/dispatch/runners/shellcheck.js +0 -173
- package/node_modules/pi-lens/dist/clients/dispatch/runners/shfmt.js +0 -102
- package/node_modules/pi-lens/dist/clients/dispatch/runners/spellcheck.js +0 -128
- package/node_modules/pi-lens/dist/clients/dispatch/runners/spotbugs.js +0 -259
- package/node_modules/pi-lens/dist/clients/dispatch/runners/sqlfluff.js +0 -183
- package/node_modules/pi-lens/dist/clients/dispatch/runners/stylelint.js +0 -166
- package/node_modules/pi-lens/dist/clients/dispatch/runners/swiftlint.js +0 -163
- package/node_modules/pi-lens/dist/clients/dispatch/runners/taplo.js +0 -174
- package/node_modules/pi-lens/dist/clients/dispatch/runners/terragrunt.js +0 -168
- package/node_modules/pi-lens/dist/clients/dispatch/runners/tflint.js +0 -125
- package/node_modules/pi-lens/dist/clients/dispatch/runners/tree-sitter.js +0 -643
- package/node_modules/pi-lens/dist/clients/dispatch/runners/trivy-config.js +0 -253
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/availability-policy.js +0 -496
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/candidate-probe.js +0 -90
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/diagnostic-parsers.js +0 -95
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/lazy-installer.js +0 -274
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/runner-helpers.js +0 -1701
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/spawn-outcome.js +0 -101
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/tool-failure.js +0 -235
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/toolchain-availability.js +0 -169
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils.js +0 -15
- package/node_modules/pi-lens/dist/clients/dispatch/runners/vale.js +0 -128
- package/node_modules/pi-lens/dist/clients/dispatch/runners/yaml-rule-parser.js +0 -242
- package/node_modules/pi-lens/dist/clients/dispatch/runners/yamllint.js +0 -95
- package/node_modules/pi-lens/dist/clients/dispatch/runners/zig-check.js +0 -79
- package/node_modules/pi-lens/dist/clients/dispatch/suppress-writer.js +0 -79
- package/node_modules/pi-lens/dist/clients/dispatch/tool-profile.js +0 -30
- package/node_modules/pi-lens/dist/clients/dispatch/types.js +0 -21
- package/node_modules/pi-lens/dist/clients/dispatch/utils/format-utils.js +0 -45
- package/node_modules/pi-lens/dist/clients/dispatch/utils/lsp-diagnostics.js +0 -35
- package/node_modules/pi-lens/dist/clients/disposition-logger.js +0 -32
- package/node_modules/pi-lens/dist/clients/disposition-publish.js +0 -124
- package/node_modules/pi-lens/dist/clients/durable-store.js +0 -97
- package/node_modules/pi-lens/dist/clients/effective-config.js +0 -415
- package/node_modules/pi-lens/dist/clients/env-utils.js +0 -83
- package/node_modules/pi-lens/dist/clients/error-class.js +0 -23
- package/node_modules/pi-lens/dist/clients/eval-timestamp.js +0 -17
- package/node_modules/pi-lens/dist/clients/event-loop-hold.js +0 -274
- package/node_modules/pi-lens/dist/clients/event-loop-monitor.js +0 -250
- package/node_modules/pi-lens/dist/clients/extension-log.js +0 -504
- package/node_modules/pi-lens/dist/clients/extension-mode.js +0 -73
- package/node_modules/pi-lens/dist/clients/feature-hints.js +0 -103
- package/node_modules/pi-lens/dist/clients/file-kinds.js +0 -412
- package/node_modules/pi-lens/dist/clients/file-role.js +0 -134
- package/node_modules/pi-lens/dist/clients/file-time.js +0 -160
- package/node_modules/pi-lens/dist/clients/file-utils.js +0 -1032
- package/node_modules/pi-lens/dist/clients/finding-delivery-gate.js +0 -494
- package/node_modules/pi-lens/dist/clients/finding-identity.js +0 -88
- package/node_modules/pi-lens/dist/clients/fix-worklog.js +0 -103
- package/node_modules/pi-lens/dist/clients/format-events-publish.js +0 -343
- package/node_modules/pi-lens/dist/clients/format-service.js +0 -222
- package/node_modules/pi-lens/dist/clients/formatters-lazy.js +0 -9
- package/node_modules/pi-lens/dist/clients/formatters.js +0 -2032
- package/node_modules/pi-lens/dist/clients/freshness-cadence.js +0 -17
- package/node_modules/pi-lens/dist/clients/freshness.js +0 -38
- package/node_modules/pi-lens/dist/clients/generated-artifacts.js +0 -394
- package/node_modules/pi-lens/dist/clients/generation-guard.js +0 -215
- package/node_modules/pi-lens/dist/clients/git-guard.js +0 -1136
- package/node_modules/pi-lens/dist/clients/git-tracked-ignore.js +0 -243
- package/node_modules/pi-lens/dist/clients/gitleaks-client.js +0 -509
- package/node_modules/pi-lens/dist/clients/go-client.js +0 -104
- package/node_modules/pi-lens/dist/clients/govulncheck-client.js +0 -605
- package/node_modules/pi-lens/dist/clients/gradle-ktfmt-style.js +0 -348
- package/node_modules/pi-lens/dist/clients/grammar-source.js +0 -465
- package/node_modules/pi-lens/dist/clients/gzip-stage-write.js +0 -135
- package/node_modules/pi-lens/dist/clients/hashline-anchor.js +0 -424
- package/node_modules/pi-lens/dist/clients/hook-budgets.js +0 -76
- package/node_modules/pi-lens/dist/clients/host-edit-normalize.js +0 -140
- package/node_modules/pi-lens/dist/clients/host-ports.js +0 -39
- package/node_modules/pi-lens/dist/clients/indent-retarget.js +0 -154
- package/node_modules/pi-lens/dist/clients/inline-blocker-dispositions.js +0 -186
- package/node_modules/pi-lens/dist/clients/install-diagnostics.js +0 -156
- package/node_modules/pi-lens/dist/clients/installer/index.js +0 -5416
- package/node_modules/pi-lens/dist/clients/installer/managed-tool-refresh-session.js +0 -58
- package/node_modules/pi-lens/dist/clients/installer/managed-tool-refresh.js +0 -783
- package/node_modules/pi-lens/dist/clients/instance-reaper-state.js +0 -7
- package/node_modules/pi-lens/dist/clients/instance-reaper.js +0 -1137
- package/node_modules/pi-lens/dist/clients/instance-registry-lock.js +0 -145
- package/node_modules/pi-lens/dist/clients/instance-registry.js +0 -773
- package/node_modules/pi-lens/dist/clients/jscpd-client.js +0 -378
- package/node_modules/pi-lens/dist/clients/json-cache-read.js +0 -65
- package/node_modules/pi-lens/dist/clients/knip-client.js +0 -788
- package/node_modules/pi-lens/dist/clients/language-policy.js +0 -252
- package/node_modules/pi-lens/dist/clients/language-profile.js +0 -361
- package/node_modules/pi-lens/dist/clients/language-registry.js +0 -603
- package/node_modules/pi-lens/dist/clients/latency-logger.js +0 -727
- package/node_modules/pi-lens/dist/clients/lazy-import.js +0 -21
- package/node_modules/pi-lens/dist/clients/ledger-bounds.js +0 -54
- package/node_modules/pi-lens/dist/clients/lens-config.js +0 -404
- package/node_modules/pi-lens/dist/clients/lens-engine.js +0 -358
- package/node_modules/pi-lens/dist/clients/lens-events.js +0 -125
- package/node_modules/pi-lens/dist/clients/lens-flag-registry.js +0 -467
- package/node_modules/pi-lens/dist/clients/lens-map.js +0 -1156
- package/node_modules/pi-lens/dist/clients/live-bus-emitter.js +0 -74
- package/node_modules/pi-lens/dist/clients/log-cleanup.js +0 -222
- package/node_modules/pi-lens/dist/clients/lsp/aggregation.js +0 -178
- package/node_modules/pi-lens/dist/clients/lsp/cascade-tier.js +0 -421
- package/node_modules/pi-lens/dist/clients/lsp/client.js +0 -4593
- package/node_modules/pi-lens/dist/clients/lsp/config.js +0 -691
- package/node_modules/pi-lens/dist/clients/lsp/content-limits.js +0 -41
- package/node_modules/pi-lens/dist/clients/lsp/diagnostic-binding.js +0 -225
- package/node_modules/pi-lens/dist/clients/lsp/document-drift.js +0 -467
- package/node_modules/pi-lens/dist/clients/lsp/edits.js +0 -1219
- package/node_modules/pi-lens/dist/clients/lsp/index.js +0 -8305
- package/node_modules/pi-lens/dist/clients/lsp/inferred-project.js +0 -216
- package/node_modules/pi-lens/dist/clients/lsp/jvm-runtime.js +0 -298
- package/node_modules/pi-lens/dist/clients/lsp/language.js +0 -63
- package/node_modules/pi-lens/dist/clients/lsp/launch.js +0 -746
- package/node_modules/pi-lens/dist/clients/lsp/lombok.js +0 -158
- package/node_modules/pi-lens/dist/clients/lsp/path-utils.js +0 -5
- package/node_modules/pi-lens/dist/clients/lsp/pending-aux-coverage.js +0 -251
- package/node_modules/pi-lens/dist/clients/lsp/position-encoding.js +0 -61
- package/node_modules/pi-lens/dist/clients/lsp/ruby-drive-dirs.js +0 -83
- package/node_modules/pi-lens/dist/clients/lsp/server.js +0 -3290
- package/node_modules/pi-lens/dist/clients/lsp/session-roots.js +0 -192
- package/node_modules/pi-lens/dist/clients/lsp/spawn-history.js +0 -17
- package/node_modules/pi-lens/dist/clients/lsp/sync-kind.js +0 -56
- package/node_modules/pi-lens/dist/clients/lsp/tsserver-sync.js +0 -332
- package/node_modules/pi-lens/dist/clients/lsp/wait-policy/capability-snapshot.js +0 -1
- package/node_modules/pi-lens/dist/clients/lsp/wait-policy/classification.js +0 -85
- package/node_modules/pi-lens/dist/clients/lsp/wait-policy/index.js +0 -10
- package/node_modules/pi-lens/dist/clients/lsp/wait-policy/strategies.js +0 -392
- package/node_modules/pi-lens/dist/clients/lsp/watch-queue.js +0 -61
- package/node_modules/pi-lens/dist/clients/lsp/workspace-diagnostics-cache.js +0 -639
- package/node_modules/pi-lens/dist/clients/lsp/workspace-diagnostics-session.js +0 -30
- package/node_modules/pi-lens/dist/clients/lsp/workspace-sweep-hold.js +0 -184
- package/node_modules/pi-lens/dist/clients/lsp-budget.js +0 -186
- package/node_modules/pi-lens/dist/clients/lsp-document-symbols.js +0 -110
- package/node_modules/pi-lens/dist/clients/lsp-lazy.js +0 -9
- package/node_modules/pi-lens/dist/clients/lsp-mutation.js +0 -396
- package/node_modules/pi-lens/dist/clients/lsp-status.js +0 -59
- package/node_modules/pi-lens/dist/clients/map-with-concurrency.js +0 -40
- package/node_modules/pi-lens/dist/clients/mcp/analyze.js +0 -420
- package/node_modules/pi-lens/dist/clients/mcp/host-shim.js +0 -31
- package/node_modules/pi-lens/dist/clients/mcp/ipc.js +0 -523
- package/node_modules/pi-lens/dist/clients/mcp/review.js +0 -197
- package/node_modules/pi-lens/dist/clients/mcp/session.js +0 -412
- package/node_modules/pi-lens/dist/clients/memory-sampler.js +0 -208
- package/node_modules/pi-lens/dist/clients/message-end-attribution.js +0 -30
- package/node_modules/pi-lens/dist/clients/metrics-client.js +0 -107
- package/node_modules/pi-lens/dist/clients/metrics-history.js +0 -327
- package/node_modules/pi-lens/dist/clients/middle-man-analysis.js +0 -263
- package/node_modules/pi-lens/dist/clients/model-provider.js +0 -53
- package/node_modules/pi-lens/dist/clients/module-report-lsp.js +0 -189
- package/node_modules/pi-lens/dist/clients/module-report.js +0 -2150
- package/node_modules/pi-lens/dist/clients/mutating-tool.js +0 -651
- package/node_modules/pi-lens/dist/clients/mutation-attribution.js +0 -368
- package/node_modules/pi-lens/dist/clients/mutation-bridge.js +0 -240
- package/node_modules/pi-lens/dist/clients/ndjson-logger.js +0 -734
- package/node_modules/pi-lens/dist/clients/observed-mutation-sources.js +0 -101
- package/node_modules/pi-lens/dist/clients/observed-mutation.js +0 -1253
- package/node_modules/pi-lens/dist/clients/oldtext-autopatch.js +0 -128
- package/node_modules/pi-lens/dist/clients/opaque-mutation-scan.js +0 -496
- package/node_modules/pi-lens/dist/clients/opengrep-client.js +0 -333
- package/node_modules/pi-lens/dist/clients/opengrep-config.js +0 -76
- package/node_modules/pi-lens/dist/clients/package-manager.js +0 -607
- package/node_modules/pi-lens/dist/clients/package-root.js +0 -38
- package/node_modules/pi-lens/dist/clients/partial-edit-apply.js +0 -439
- package/node_modules/pi-lens/dist/clients/path-attribution-telemetry.js +0 -43
- package/node_modules/pi-lens/dist/clients/path-keyed-map.js +0 -108
- package/node_modules/pi-lens/dist/clients/path-utils.js +0 -1244
- package/node_modules/pi-lens/dist/clients/performance-report.js +0 -331
- package/node_modules/pi-lens/dist/clients/persist-debounce.js +0 -70
- package/node_modules/pi-lens/dist/clients/persistent-reverify.js +0 -271
- package/node_modules/pi-lens/dist/clients/php-cs-fixer-config.js +0 -119
- package/node_modules/pi-lens/dist/clients/pipeline.js +0 -1480
- package/node_modules/pi-lens/dist/clients/post-autofix-notice.js +0 -37
- package/node_modules/pi-lens/dist/clients/print-mode.js +0 -21
- package/node_modules/pi-lens/dist/clients/probe-home-state.js +0 -228
- package/node_modules/pi-lens/dist/clients/process-bridge.js +0 -66
- package/node_modules/pi-lens/dist/clients/process-singletons.js +0 -210
- package/node_modules/pi-lens/dist/clients/process-snapshot.js +0 -68
- package/node_modules/pi-lens/dist/clients/project-changes.js +0 -181
- package/node_modules/pi-lens/dist/clients/project-conventions.js +0 -171
- package/node_modules/pi-lens/dist/clients/project-diagnostics/cache.js +0 -137
- package/node_modules/pi-lens/dist/clients/project-diagnostics/extractors.js +0 -109
- package/node_modules/pi-lens/dist/clients/project-diagnostics/fresh-fetch.js +0 -668
- package/node_modules/pi-lens/dist/clients/project-diagnostics/runner-adapters/call-graph-impact.js +0 -118
- package/node_modules/pi-lens/dist/clients/project-diagnostics/runner-adapters/dead-code.js +0 -47
- package/node_modules/pi-lens/dist/clients/project-diagnostics/runner-adapters/gitleaks.js +0 -40
- package/node_modules/pi-lens/dist/clients/project-diagnostics/runner-adapters/govulncheck.js +0 -34
- package/node_modules/pi-lens/dist/clients/project-diagnostics/runner-adapters/jscpd.js +0 -38
- package/node_modules/pi-lens/dist/clients/project-diagnostics/runner-adapters/knip.js +0 -47
- package/node_modules/pi-lens/dist/clients/project-diagnostics/runner-adapters/madge.js +0 -48
- package/node_modules/pi-lens/dist/clients/project-diagnostics/runner-adapters/opengrep.js +0 -40
- package/node_modules/pi-lens/dist/clients/project-diagnostics/runner-adapters/runner-findings.js +0 -127
- package/node_modules/pi-lens/dist/clients/project-diagnostics/runner-adapters/trivy.js +0 -81
- package/node_modules/pi-lens/dist/clients/project-diagnostics/scanner.js +0 -520
- package/node_modules/pi-lens/dist/clients/project-diagnostics/types.js +0 -1
- package/node_modules/pi-lens/dist/clients/project-lens-config.js +0 -807
- package/node_modules/pi-lens/dist/clients/project-report.js +0 -701
- package/node_modules/pi-lens/dist/clients/project-scale.js +0 -237
- package/node_modules/pi-lens/dist/clients/project-scan-policy.js +0 -11
- package/node_modules/pi-lens/dist/clients/project-snapshot-fingerprint.js +0 -48
- package/node_modules/pi-lens/dist/clients/project-snapshot-persist-worker.js +0 -20
- package/node_modules/pi-lens/dist/clients/project-snapshot.js +0 -1653
- package/node_modules/pi-lens/dist/clients/project-trust.js +0 -181
- package/node_modules/pi-lens/dist/clients/python-environment.js +0 -217
- package/node_modules/pi-lens/dist/clients/python-provenance.js +0 -639
- package/node_modules/pi-lens/dist/clients/quiet-window-config.js +0 -47
- package/node_modules/pi-lens/dist/clients/quiet-window.js +0 -236
- package/node_modules/pi-lens/dist/clients/read-bridge.js +0 -139
- package/node_modules/pi-lens/dist/clients/read-expansion.js +0 -266
- package/node_modules/pi-lens/dist/clients/read-guard-logger.js +0 -251
- package/node_modules/pi-lens/dist/clients/read-guard-tool-lines.js +0 -1306
- package/node_modules/pi-lens/dist/clients/read-guard.js +0 -1561
- package/node_modules/pi-lens/dist/clients/recent-touches.js +0 -240
- package/node_modules/pi-lens/dist/clients/redact/secrets.js +0 -449
- package/node_modules/pi-lens/dist/clients/resource-sampler.js +0 -628
- package/node_modules/pi-lens/dist/clients/reverse-deps.js +0 -270
- package/node_modules/pi-lens/dist/clients/review-graph/builder.js +0 -5126
- package/node_modules/pi-lens/dist/clients/review-graph/format.js +0 -33
- package/node_modules/pi-lens/dist/clients/review-graph/git-identity.js +0 -163
- package/node_modules/pi-lens/dist/clients/review-graph/import-resolvers.js +0 -481
- package/node_modules/pi-lens/dist/clients/review-graph/persist-worker.js +0 -10
- package/node_modules/pi-lens/dist/clients/review-graph/query.js +0 -244
- package/node_modules/pi-lens/dist/clients/review-graph/revision-drift.js +0 -21
- package/node_modules/pi-lens/dist/clients/review-graph/service.js +0 -96
- package/node_modules/pi-lens/dist/clients/review-graph/shared-extraction-ir.js +0 -82
- package/node_modules/pi-lens/dist/clients/review-graph/symbol-id.js +0 -103
- package/node_modules/pi-lens/dist/clients/review-graph/tsconfig-paths.js +0 -299
- package/node_modules/pi-lens/dist/clients/review-graph/types.js +0 -1
- package/node_modules/pi-lens/dist/clients/review-graph/workspace-modules.js +0 -449
- package/node_modules/pi-lens/dist/clients/review-graph-logger.js +0 -81
- package/node_modules/pi-lens/dist/clients/ruff-client.js +0 -179
- package/node_modules/pi-lens/dist/clients/rules-scanner.js +0 -131
- package/node_modules/pi-lens/dist/clients/run-duration.js +0 -55
- package/node_modules/pi-lens/dist/clients/runtime-agent-end.js +0 -746
- package/node_modules/pi-lens/dist/clients/runtime-config.js +0 -77
- package/node_modules/pi-lens/dist/clients/runtime-context.js +0 -211
- package/node_modules/pi-lens/dist/clients/runtime-coordinator.js +0 -1324
- package/node_modules/pi-lens/dist/clients/runtime-session.js +0 -2485
- package/node_modules/pi-lens/dist/clients/runtime-tool-call.js +0 -1295
- package/node_modules/pi-lens/dist/clients/runtime-tool-result.js +0 -2049
- package/node_modules/pi-lens/dist/clients/runtime-turn.js +0 -3767
- package/node_modules/pi-lens/dist/clients/rust-client.js +0 -97
- package/node_modules/pi-lens/dist/clients/safe-spawn.js +0 -2357
- package/node_modules/pi-lens/dist/clients/sanitize.js +0 -286
- package/node_modules/pi-lens/dist/clients/scan-utils.js +0 -25
- package/node_modules/pi-lens/dist/clients/scratch-tree-policy.js +0 -165
- package/node_modules/pi-lens/dist/clients/search-read-registration.js +0 -94
- package/node_modules/pi-lens/dist/clients/secret-findings.js +0 -114
- package/node_modules/pi-lens/dist/clients/security-scan-client.js +0 -352
- package/node_modules/pi-lens/dist/clients/session-event-guard.js +0 -297
- package/node_modules/pi-lens/dist/clients/session-lifecycle.js +0 -484
- package/node_modules/pi-lens/dist/clients/session-start-observability.js +0 -94
- package/node_modules/pi-lens/dist/clients/session-state-store.js +0 -101
- package/node_modules/pi-lens/dist/clients/session-summary.js +0 -15
- package/node_modules/pi-lens/dist/clients/sessionstart-logger.js +0 -27
- package/node_modules/pi-lens/dist/clients/sg-runner.js +0 -876
- package/node_modules/pi-lens/dist/clients/sgconfig.js +0 -347
- package/node_modules/pi-lens/dist/clients/shared-checkout-guard.js +0 -338
- package/node_modules/pi-lens/dist/clients/single-flight.js +0 -158
- package/node_modules/pi-lens/dist/clients/situational-tool-telemetry.js +0 -108
- package/node_modules/pi-lens/dist/clients/skills-resolver.js +0 -141
- package/node_modules/pi-lens/dist/clients/slow-fs.js +0 -138
- package/node_modules/pi-lens/dist/clients/smells-rollup.js +0 -231
- package/node_modules/pi-lens/dist/clients/source-filter.js +0 -596
- package/node_modules/pi-lens/dist/clients/source-walker.js +0 -211
- package/node_modules/pi-lens/dist/clients/spawn-output-cap.js +0 -120
- package/node_modules/pi-lens/dist/clients/spawn-timeout-cooldown.js +0 -110
- package/node_modules/pi-lens/dist/clients/stale-marker.js +0 -17
- package/node_modules/pi-lens/dist/clients/startup-scan.js +0 -400
- package/node_modules/pi-lens/dist/clients/startup-timing.js +0 -130
- package/node_modules/pi-lens/dist/clients/string-utils.js +0 -33
- package/node_modules/pi-lens/dist/clients/subagent-mode.js +0 -111
- package/node_modules/pi-lens/dist/clients/symbol-containment.js +0 -24
- package/node_modules/pi-lens/dist/clients/symbol-types.js +0 -5
- package/node_modules/pi-lens/dist/clients/test-runner-client.js +0 -2507
- package/node_modules/pi-lens/dist/clients/test-runner-delivery.js +0 -287
- package/node_modules/pi-lens/dist/clients/todo-scanner.js +0 -229
- package/node_modules/pi-lens/dist/clients/tool-agreement.js +0 -423
- package/node_modules/pi-lens/dist/clients/tool-config.js +0 -249
- package/node_modules/pi-lens/dist/clients/tool-cwd.js +0 -270
- package/node_modules/pi-lens/dist/clients/tool-definition.js +0 -47
- package/node_modules/pi-lens/dist/clients/tool-event.js +0 -105
- package/node_modules/pi-lens/dist/clients/tool-policy.js +0 -2755
- package/node_modules/pi-lens/dist/clients/tool-probe.js +0 -53
- package/node_modules/pi-lens/dist/clients/tool-render.js +0 -156
- package/node_modules/pi-lens/dist/clients/tool-set-policy.js +0 -118
- package/node_modules/pi-lens/dist/clients/tree-sitter-cache.js +0 -364
- package/node_modules/pi-lens/dist/clients/tree-sitter-client.js +0 -4195
- package/node_modules/pi-lens/dist/clients/tree-sitter-logger.js +0 -100
- package/node_modules/pi-lens/dist/clients/tree-sitter-navigator.js +0 -269
- package/node_modules/pi-lens/dist/clients/tree-sitter-query-loader.js +0 -569
- package/node_modules/pi-lens/dist/clients/tree-sitter-shared.js +0 -158
- package/node_modules/pi-lens/dist/clients/tree-sitter-symbol-extractor.js +0 -1265
- package/node_modules/pi-lens/dist/clients/trivy-client.js +0 -467
- package/node_modules/pi-lens/dist/clients/tui-fit.js +0 -50
- package/node_modules/pi-lens/dist/clients/turn-context.js +0 -52
- package/node_modules/pi-lens/dist/clients/turn-end/lane.js +0 -51
- package/node_modules/pi-lens/dist/clients/turn-end/lanes/govulncheck.js +0 -112
- package/node_modules/pi-lens/dist/clients/turn-end/lanes/secrets.js +0 -204
- package/node_modules/pi-lens/dist/clients/turn-summary-render.js +0 -72
- package/node_modules/pi-lens/dist/clients/turn-summary.js +0 -132
- package/node_modules/pi-lens/dist/clients/typos-config.js +0 -29
- package/node_modules/pi-lens/dist/clients/user-notify.js +0 -51
- package/node_modules/pi-lens/dist/clients/vanished-instance-marker.js +0 -57
- package/node_modules/pi-lens/dist/clients/warm-attach.js +0 -305
- package/node_modules/pi-lens/dist/clients/widget-state.js +0 -1808
- package/node_modules/pi-lens/dist/clients/word-index-logger.js +0 -49
- package/node_modules/pi-lens/dist/clients/word-index-store.js +0 -459
- package/node_modules/pi-lens/dist/clients/word-index.js +0 -2080
- package/node_modules/pi-lens/dist/clients/workspace-topology.js +0 -443
- package/node_modules/pi-lens/dist/clients/write-ordering-guard.js +0 -65
- package/node_modules/pi-lens/dist/clients/zizmor-config.js +0 -340
- package/node_modules/pi-lens/dist/i18n.js +0 -69
- package/node_modules/pi-lens/dist/mcp/build-staleness.js +0 -124
- package/node_modules/pi-lens/dist/scripts/lib/process-scan.mjs +0 -583
- package/node_modules/pi-lens/dist/scripts/lib/skills-predicate.mjs +0 -129
- package/node_modules/pi-lens/dist/scripts/lib/web-tree-sitter-dir.mjs +0 -123
- package/node_modules/pi-lens/dist/tools/activate-tools.js +0 -87
- package/node_modules/pi-lens/dist/tools/ast-grep-outline.js +0 -137
- package/node_modules/pi-lens/dist/tools/ast-grep-replace.js +0 -244
- package/node_modules/pi-lens/dist/tools/ast-grep-search.js +0 -762
- package/node_modules/pi-lens/dist/tools/effective-config.js +0 -90
- package/node_modules/pi-lens/dist/tools/lens-diagnostic-mark.js +0 -375
- package/node_modules/pi-lens/dist/tools/lens-diagnostics.js +0 -2571
- package/node_modules/pi-lens/dist/tools/lsp-diagnostics.js +0 -1745
- package/node_modules/pi-lens/dist/tools/lsp-navigation.js +0 -1367
- package/node_modules/pi-lens/dist/tools/lsp-structured-output.js +0 -294
- package/node_modules/pi-lens/dist/tools/module-report.js +0 -382
- package/node_modules/pi-lens/dist/tools/project-report.js +0 -86
- package/node_modules/pi-lens/dist/tools/render-compact.js +0 -374
- package/node_modules/pi-lens/dist/tools/scan-progress.js +0 -53
- package/node_modules/pi-lens/dist/tools/shared.js +0 -29
- package/node_modules/pi-lens/dist/tools/symbol-search.js +0 -155
|
@@ -0,0 +1,4139 @@
|
|
|
1
|
+
import { createRequire as __pilensCreateRequire } from "node:module"; const require = __pilensCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
buildSymbolId
|
|
4
|
+
} from "./chunk-3MED75HT.js";
|
|
5
|
+
import {
|
|
6
|
+
createGitIdentityResolver,
|
|
7
|
+
resolveGitIdentity
|
|
8
|
+
} from "./chunk-3I5QFT3N.js";
|
|
9
|
+
import {
|
|
10
|
+
RUNTIME_CONFIG,
|
|
11
|
+
TreeSitterSymbolExtractor,
|
|
12
|
+
buildReverseDependencyIndexFromGraph,
|
|
13
|
+
getLSPService,
|
|
14
|
+
jsTsCandidatePaths,
|
|
15
|
+
rankFilesByReverseDependencyCentrality,
|
|
16
|
+
resolveAliasedImport,
|
|
17
|
+
resolveImportToFiles,
|
|
18
|
+
resolveProjectReferenceImport,
|
|
19
|
+
resolveWorkspacePackageImport,
|
|
20
|
+
symbolExtractionGrammar
|
|
21
|
+
} from "./chunk-TVN5N6GY.js";
|
|
22
|
+
import {
|
|
23
|
+
buildQualifiedName,
|
|
24
|
+
findOwnerName
|
|
25
|
+
} from "./chunk-5W3R6LFT.js";
|
|
26
|
+
import {
|
|
27
|
+
classifyTreeSitterWasmError,
|
|
28
|
+
getSharedTreeSitterClient,
|
|
29
|
+
logTreeSitterCacheStats,
|
|
30
|
+
withTreeSitterRoot
|
|
31
|
+
} from "./chunk-LW6XKDZQ.js";
|
|
32
|
+
import {
|
|
33
|
+
readWorkerHeapStatistics
|
|
34
|
+
} from "./chunk-AJVLWNFN.js";
|
|
35
|
+
import {
|
|
36
|
+
getReviewGraphMaxFilesDerived
|
|
37
|
+
} from "./chunk-LNAKEO63.js";
|
|
38
|
+
import {
|
|
39
|
+
collectSourceFilesWithBudgetAsync
|
|
40
|
+
} from "./chunk-6QIUX4EP.js";
|
|
41
|
+
import {
|
|
42
|
+
collectUntrackedIgnoredIds,
|
|
43
|
+
getProjectDataDir,
|
|
44
|
+
isStaleStageFile
|
|
45
|
+
} from "./chunk-VN2AXLEX.js";
|
|
46
|
+
import {
|
|
47
|
+
KIND_EXTENSIONS,
|
|
48
|
+
detectFileKind
|
|
49
|
+
} from "./chunk-5ZEJHV35.js";
|
|
50
|
+
import {
|
|
51
|
+
detectFileRole
|
|
52
|
+
} from "./chunk-DQ2NZ7C4.js";
|
|
53
|
+
import {
|
|
54
|
+
writeFileAtomic
|
|
55
|
+
} from "./chunk-2EECBNC5.js";
|
|
56
|
+
import {
|
|
57
|
+
compareOrdinal,
|
|
58
|
+
escapeRegExp,
|
|
59
|
+
incrementDegradationCount
|
|
60
|
+
} from "./chunk-N3YQJI6O.js";
|
|
61
|
+
import {
|
|
62
|
+
logLatency
|
|
63
|
+
} from "./chunk-5THXD6X5.js";
|
|
64
|
+
import {
|
|
65
|
+
createNdjsonLogger,
|
|
66
|
+
getGlobalPiLensLogDir,
|
|
67
|
+
getMaxLogSizeMB,
|
|
68
|
+
getTurnId,
|
|
69
|
+
isTestMode,
|
|
70
|
+
lazyEnvNumber
|
|
71
|
+
} from "./chunk-UK3CMEAL.js";
|
|
72
|
+
import {
|
|
73
|
+
FactStore
|
|
74
|
+
} from "./chunk-NMABWBZN.js";
|
|
75
|
+
import {
|
|
76
|
+
BoundedFifoMap,
|
|
77
|
+
BoundedLruCache
|
|
78
|
+
} from "./chunk-ABBOA7UD.js";
|
|
79
|
+
import {
|
|
80
|
+
isAtOrAboveHomeDir,
|
|
81
|
+
isUnderDir,
|
|
82
|
+
normalizeFilePath,
|
|
83
|
+
normalizeMapKey,
|
|
84
|
+
toProjectRelativePath
|
|
85
|
+
} from "./chunk-Q5U6FMDI.js";
|
|
86
|
+
|
|
87
|
+
// dist/clients/review-graph/builder.js
|
|
88
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
89
|
+
import * as fs2 from "node:fs";
|
|
90
|
+
import * as path2 from "node:path";
|
|
91
|
+
import { Worker } from "node:worker_threads";
|
|
92
|
+
import { constants as zlibConstants, gunzipSync, gzipSync } from "node:zlib";
|
|
93
|
+
import { fileURLToPath } from "node:url";
|
|
94
|
+
|
|
95
|
+
// dist/clients/dispatch/facts/file-content.js
|
|
96
|
+
import * as fs from "node:fs/promises";
|
|
97
|
+
var fileContentProvider = {
|
|
98
|
+
id: "fact.file.content",
|
|
99
|
+
provides: ["file.content"],
|
|
100
|
+
requires: [],
|
|
101
|
+
appliesTo(_ctx) {
|
|
102
|
+
return true;
|
|
103
|
+
},
|
|
104
|
+
async run(ctx, store) {
|
|
105
|
+
let content;
|
|
106
|
+
try {
|
|
107
|
+
content = await fs.readFile(ctx.filePath, "utf-8");
|
|
108
|
+
} catch {
|
|
109
|
+
content = null;
|
|
110
|
+
}
|
|
111
|
+
store.setFileFact(ctx.filePath, "file.content", content);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// dist/clients/feature-hints.js
|
|
116
|
+
function normalizeHintInput(value) {
|
|
117
|
+
return value.replace(/\\/g, "/");
|
|
118
|
+
}
|
|
119
|
+
function hasHintToken(value, tokens) {
|
|
120
|
+
const escaped = tokens.map((token) => escapeRegExp(token));
|
|
121
|
+
const alternatives = escaped.join("|");
|
|
122
|
+
return new RegExp(`(?:^|[/_.\\-\\s])(?:${alternatives})(?=[/_.\\-\\s]|$)`, "i").test(value) || new RegExp(`(?:^|(?<=[a-z0-9]))(?:${tokens.flatMap((token) => [
|
|
123
|
+
token[0].toUpperCase() + token.slice(1),
|
|
124
|
+
...token === "openai" ? ["OpenAI"] : [],
|
|
125
|
+
...token === "github" ? ["GitHub"] : [],
|
|
126
|
+
...token === "gitlab" ? ["GitLab"] : []
|
|
127
|
+
]).join("|")})(?=[A-Z]|[/_.\\-\\s]|$)`).test(value);
|
|
128
|
+
}
|
|
129
|
+
function inferFeatureKind(nameOrPath) {
|
|
130
|
+
const normalized = normalizeHintInput(nameOrPath);
|
|
131
|
+
if (hasHintToken(normalized, [
|
|
132
|
+
"config",
|
|
133
|
+
"store",
|
|
134
|
+
"db",
|
|
135
|
+
"database",
|
|
136
|
+
"github",
|
|
137
|
+
"openai",
|
|
138
|
+
"sync",
|
|
139
|
+
"service"
|
|
140
|
+
])) {
|
|
141
|
+
return "service";
|
|
142
|
+
}
|
|
143
|
+
if (/(^|[/_.\-\s])(cli|command|bin)([/_.\-\s]|$)/i.test(normalized)) {
|
|
144
|
+
return "cli-command";
|
|
145
|
+
}
|
|
146
|
+
return "library";
|
|
147
|
+
}
|
|
148
|
+
function inferTrustBoundaries(nameOrPath) {
|
|
149
|
+
const normalized = normalizeHintInput(nameOrPath);
|
|
150
|
+
const boundaries = /* @__PURE__ */ new Set();
|
|
151
|
+
if (hasHintToken(normalized, [
|
|
152
|
+
"config",
|
|
153
|
+
"store",
|
|
154
|
+
"db",
|
|
155
|
+
"database",
|
|
156
|
+
"repo",
|
|
157
|
+
"repository",
|
|
158
|
+
"model",
|
|
159
|
+
"migration"
|
|
160
|
+
])) {
|
|
161
|
+
boundaries.add("filesystem");
|
|
162
|
+
boundaries.add("database");
|
|
163
|
+
}
|
|
164
|
+
if (hasHintToken(normalized, [
|
|
165
|
+
"github",
|
|
166
|
+
"gitlab",
|
|
167
|
+
"openai",
|
|
168
|
+
"anthropic",
|
|
169
|
+
"stripe",
|
|
170
|
+
"slack",
|
|
171
|
+
"sync",
|
|
172
|
+
"webhook",
|
|
173
|
+
"api",
|
|
174
|
+
"client"
|
|
175
|
+
])) {
|
|
176
|
+
boundaries.add("network");
|
|
177
|
+
boundaries.add("external-api");
|
|
178
|
+
boundaries.add("serialization");
|
|
179
|
+
}
|
|
180
|
+
if (/(^|[/_.\-\s])(cli|command|bin|exec|spawn|process|shell)([/_.\-\s]|$)/i.test(normalized)) {
|
|
181
|
+
boundaries.add("user-input");
|
|
182
|
+
boundaries.add("process-exec");
|
|
183
|
+
}
|
|
184
|
+
if (hasHintToken(normalized, [
|
|
185
|
+
"auth",
|
|
186
|
+
"login",
|
|
187
|
+
"token",
|
|
188
|
+
"session",
|
|
189
|
+
"oauth",
|
|
190
|
+
"jwt"
|
|
191
|
+
])) {
|
|
192
|
+
boundaries.add("auth");
|
|
193
|
+
boundaries.add("user-input");
|
|
194
|
+
}
|
|
195
|
+
return [...boundaries];
|
|
196
|
+
}
|
|
197
|
+
function featureHintMetadata(nameOrPath) {
|
|
198
|
+
return {
|
|
199
|
+
featureKind: inferFeatureKind(nameOrPath),
|
|
200
|
+
trustBoundaries: inferTrustBoundaries(nameOrPath)
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// dist/clients/lsp-document-symbols.js
|
|
205
|
+
var LSP_DOCUMENT_SYMBOL_TIMEOUT_MS = 150;
|
|
206
|
+
var SYMBOL_KIND_NAMES = {
|
|
207
|
+
1: "file",
|
|
208
|
+
2: "module",
|
|
209
|
+
3: "namespace",
|
|
210
|
+
4: "package",
|
|
211
|
+
5: "class",
|
|
212
|
+
6: "method",
|
|
213
|
+
7: "property",
|
|
214
|
+
8: "field",
|
|
215
|
+
9: "constructor",
|
|
216
|
+
10: "enum",
|
|
217
|
+
11: "interface",
|
|
218
|
+
12: "function",
|
|
219
|
+
13: "variable",
|
|
220
|
+
14: "constant",
|
|
221
|
+
15: "string",
|
|
222
|
+
16: "number",
|
|
223
|
+
17: "boolean",
|
|
224
|
+
18: "array",
|
|
225
|
+
19: "object",
|
|
226
|
+
20: "key",
|
|
227
|
+
21: "null",
|
|
228
|
+
22: "enum-member",
|
|
229
|
+
23: "struct",
|
|
230
|
+
24: "event",
|
|
231
|
+
25: "operator",
|
|
232
|
+
26: "type-parameter"
|
|
233
|
+
};
|
|
234
|
+
function lspSymbolKindName(kind) {
|
|
235
|
+
return SYMBOL_KIND_NAMES[kind] ?? `lsp-symbol-${kind}`;
|
|
236
|
+
}
|
|
237
|
+
async function getOpenDocumentSymbols(filePath, timeoutMs = LSP_DOCUMENT_SYMBOL_TIMEOUT_MS) {
|
|
238
|
+
const spawned = await getLSPService().getWarmClientForFile(filePath);
|
|
239
|
+
if (!spawned || !spawned.client.isDocumentOpen(filePath) || !spawned.client.getOperationSupport().documentSymbol) {
|
|
240
|
+
return void 0;
|
|
241
|
+
}
|
|
242
|
+
let timer;
|
|
243
|
+
try {
|
|
244
|
+
return await Promise.race([
|
|
245
|
+
spawned.client.documentSymbol(filePath),
|
|
246
|
+
new Promise((resolve2) => {
|
|
247
|
+
timer = setTimeout(() => resolve2(void 0), timeoutMs);
|
|
248
|
+
})
|
|
249
|
+
]);
|
|
250
|
+
} catch {
|
|
251
|
+
return void 0;
|
|
252
|
+
} finally {
|
|
253
|
+
if (timer)
|
|
254
|
+
clearTimeout(timer);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
function containerNameChain(symbol, allSymbols) {
|
|
258
|
+
const chain = [];
|
|
259
|
+
const seen = /* @__PURE__ */ new Set();
|
|
260
|
+
let container = symbol.containerName;
|
|
261
|
+
while (container && !seen.has(container) && chain.length < 10) {
|
|
262
|
+
chain.unshift(container);
|
|
263
|
+
seen.add(container);
|
|
264
|
+
container = allSymbols?.find((candidate) => candidate.name === container)?.containerName;
|
|
265
|
+
}
|
|
266
|
+
return chain;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// dist/clients/project-scan-policy.js
|
|
270
|
+
function collectProjectSourceFilesWithBudgetAsync(rootDir, options) {
|
|
271
|
+
return collectSourceFilesWithBudgetAsync(rootDir, options);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// dist/clients/review-graph-logger.js
|
|
275
|
+
import * as path from "node:path";
|
|
276
|
+
var REVIEW_GRAPH_LOG_DIR = getGlobalPiLensLogDir();
|
|
277
|
+
var REVIEW_GRAPH_LOG_FILE = path.join(REVIEW_GRAPH_LOG_DIR, "review-graph.log");
|
|
278
|
+
var writer = createNdjsonLogger({
|
|
279
|
+
filePath: REVIEW_GRAPH_LOG_FILE,
|
|
280
|
+
maxBytes: getMaxLogSizeMB() * 1024 * 1024,
|
|
281
|
+
backupPath: `${REVIEW_GRAPH_LOG_FILE}.1`
|
|
282
|
+
});
|
|
283
|
+
function makeReviewGraphBuildMetadata(graph, options = {}) {
|
|
284
|
+
return {
|
|
285
|
+
...options.buildId === void 0 ? {} : { buildId: options.buildId },
|
|
286
|
+
...graph.buildGeneration === void 0 ? {} : { graphGeneration: graph.buildGeneration },
|
|
287
|
+
builtAt: graph.builtAt,
|
|
288
|
+
...options.projectSeq === void 0 ? {} : { projectSeq: options.projectSeq },
|
|
289
|
+
...options.seqHint === void 0 ? {} : { seqHint: options.seqHint },
|
|
290
|
+
...options.mode === void 0 ? {} : { mode: options.mode },
|
|
291
|
+
sourceFiles: options.sourceFileCount ?? graph.fileNodes.size,
|
|
292
|
+
...options.sourceFileCountTruncated || graph.persistCoverage?.sourceFilesTruncated ? { sourceFilesTruncated: true } : {},
|
|
293
|
+
...options.pathNormalizeCalls === void 0 ? {} : { pathNormalizeCalls: options.pathNormalizeCalls },
|
|
294
|
+
nodes: graph.nodes.size,
|
|
295
|
+
edges: graph.edges.length,
|
|
296
|
+
...graph.persistCoverage ? { persistCoverage: graph.persistCoverage } : {}
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
function logReviewGraph(entry) {
|
|
300
|
+
if (isTestMode()) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
writer.log({
|
|
304
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
305
|
+
...entry,
|
|
306
|
+
cwd: normalizeFilePath(entry.cwd),
|
|
307
|
+
pid: process.pid,
|
|
308
|
+
turnId: getTurnId()
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
function flushReviewGraphLogSync() {
|
|
312
|
+
writer.flushSync();
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// dist/clients/review-graph/revision-drift.js
|
|
316
|
+
function formatReviewGraphRevisionDriftNote(drift) {
|
|
317
|
+
return `Graph was built at commit ${drift.stampedHead.slice(0, 8)}; HEAD is now ${drift.currentHead.slice(0, 8)}. Results below reflect the earlier revision \u2014 run pilens_rebuild or re-analyze to refresh.`;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// dist/clients/review-graph/shared-extraction-ir.js
|
|
321
|
+
import { createHash } from "node:crypto";
|
|
322
|
+
function reviewGraphIrContentHash(content) {
|
|
323
|
+
return createHash("sha256").update(content).digest("hex");
|
|
324
|
+
}
|
|
325
|
+
var MAX_ROOTS = 8;
|
|
326
|
+
var MAX_FILES_PER_ROOT = 2e4;
|
|
327
|
+
var roots = new BoundedFifoMap(MAX_ROOTS);
|
|
328
|
+
var accepted = 0;
|
|
329
|
+
var rejected = 0;
|
|
330
|
+
function rootKey(cwd) {
|
|
331
|
+
return normalizeMapKey(cwd);
|
|
332
|
+
}
|
|
333
|
+
function publishReviewGraphFileIr(cwd, entry) {
|
|
334
|
+
if (!entry.complete || !entry.structural)
|
|
335
|
+
return;
|
|
336
|
+
const key = rootKey(cwd);
|
|
337
|
+
let files = roots.get(key);
|
|
338
|
+
if (!files) {
|
|
339
|
+
files = new BoundedFifoMap(MAX_FILES_PER_ROOT);
|
|
340
|
+
roots.set(key, files);
|
|
341
|
+
}
|
|
342
|
+
const fileKey = normalizeMapKey(entry.filePath);
|
|
343
|
+
files.delete(fileKey);
|
|
344
|
+
files.set(fileKey, { ...entry, filePath: fileKey });
|
|
345
|
+
}
|
|
346
|
+
function getFreshReviewGraphFileIr(cwd, filePath, contentHash) {
|
|
347
|
+
const files = roots.get(rootKey(cwd));
|
|
348
|
+
const fileKey = normalizeMapKey(filePath);
|
|
349
|
+
const entry = files?.get(fileKey);
|
|
350
|
+
if (!entry)
|
|
351
|
+
return void 0;
|
|
352
|
+
if (entry.contentHash !== contentHash) {
|
|
353
|
+
rejected++;
|
|
354
|
+
return void 0;
|
|
355
|
+
}
|
|
356
|
+
files?.delete(fileKey);
|
|
357
|
+
accepted++;
|
|
358
|
+
return entry;
|
|
359
|
+
}
|
|
360
|
+
function clearReviewGraphFileIr(cwd) {
|
|
361
|
+
if (cwd === void 0)
|
|
362
|
+
roots.clear();
|
|
363
|
+
else
|
|
364
|
+
roots.delete(rootKey(cwd));
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// dist/clients/review-graph/builder.js
|
|
368
|
+
var REVIEW_GRAPH_VERSION = "v8";
|
|
369
|
+
var MAIN_KINDS = /* @__PURE__ */ new Set([
|
|
370
|
+
"jsts",
|
|
371
|
+
"python",
|
|
372
|
+
"go",
|
|
373
|
+
"rust",
|
|
374
|
+
"ruby",
|
|
375
|
+
"cxx",
|
|
376
|
+
// Languages added in #152: WASMs + symbol queries now available
|
|
377
|
+
"java",
|
|
378
|
+
"kotlin",
|
|
379
|
+
"dart",
|
|
380
|
+
"elixir",
|
|
381
|
+
"csharp",
|
|
382
|
+
"php",
|
|
383
|
+
"swift",
|
|
384
|
+
"lua",
|
|
385
|
+
"ocaml",
|
|
386
|
+
"zig",
|
|
387
|
+
"shell"
|
|
388
|
+
]);
|
|
389
|
+
var MAIN_KIND_EXTENSIONS = Array.from(MAIN_KINDS).flatMap((kind) => KIND_EXTENSIONS[kind] ?? []);
|
|
390
|
+
var CHANGED_SYMBOLS_PREFIX = "session.reviewGraph.changedSymbols:";
|
|
391
|
+
var extractorCache = /* @__PURE__ */ new Map();
|
|
392
|
+
var REVIEW_GRAPH_MAX_WARM_WORKSPACES = 8;
|
|
393
|
+
var REVIEW_GRAPH_SOURCE_PATH_MEMO_ENTRIES = 16384;
|
|
394
|
+
var _sourcePathMemos = new BoundedLruCache(REVIEW_GRAPH_MAX_WARM_WORKSPACES);
|
|
395
|
+
function sourcePathMemo(cwd) {
|
|
396
|
+
const key = normalizeMapKey(path2.resolve(cwd));
|
|
397
|
+
const existing = _sourcePathMemos.get(key);
|
|
398
|
+
if (existing)
|
|
399
|
+
return existing;
|
|
400
|
+
const memo = {
|
|
401
|
+
cache: new BoundedLruCache(REVIEW_GRAPH_SOURCE_PATH_MEMO_ENTRIES),
|
|
402
|
+
normalizeCalls: { value: 0 }
|
|
403
|
+
};
|
|
404
|
+
_sourcePathMemos.set(key, memo);
|
|
405
|
+
return memo;
|
|
406
|
+
}
|
|
407
|
+
function normalizeGraphSourcePath(memo, raw) {
|
|
408
|
+
const cached = memo.cache.get(raw);
|
|
409
|
+
if (cached !== void 0)
|
|
410
|
+
return cached;
|
|
411
|
+
const normalized = normalizeMapKey(raw);
|
|
412
|
+
if (fs2.existsSync(raw))
|
|
413
|
+
memo.cache.set(raw, normalized);
|
|
414
|
+
memo.normalizeCalls.value++;
|
|
415
|
+
return normalized;
|
|
416
|
+
}
|
|
417
|
+
function _resetReviewGraphSourcePathMemoForTests() {
|
|
418
|
+
_sourcePathMemos.clear();
|
|
419
|
+
}
|
|
420
|
+
var _buildCache = /* @__PURE__ */ new Map();
|
|
421
|
+
var _workspaceGraphCache = /* @__PURE__ */ new Map();
|
|
422
|
+
var REVIEW_GRAPH_IDLE_EVICT_MS_DEFAULT = 20 * 6e4;
|
|
423
|
+
var _workspaceCacheEpoch = 0;
|
|
424
|
+
var _workspaceCacheEpochs = /* @__PURE__ */ new Map();
|
|
425
|
+
function workspaceCacheEpoch(key) {
|
|
426
|
+
return _workspaceCacheEpoch + (_workspaceCacheEpochs.get(key) ?? 0);
|
|
427
|
+
}
|
|
428
|
+
function reviewGraphIdleEvictMs() {
|
|
429
|
+
const value = Number.parseInt(process.env.PI_LENS_REVIEW_GRAPH_IDLE_EVICT_MS ?? "", 10);
|
|
430
|
+
return Number.isSafeInteger(value) && value > 0 ? value : REVIEW_GRAPH_IDLE_EVICT_MS_DEFAULT;
|
|
431
|
+
}
|
|
432
|
+
function clearWorkspaceGraphTimer(entry) {
|
|
433
|
+
if (entry.idleTimer)
|
|
434
|
+
clearTimeout(entry.idleTimer);
|
|
435
|
+
entry.idleTimer = void 0;
|
|
436
|
+
}
|
|
437
|
+
function buildCacheWorkspaceKey(cwd) {
|
|
438
|
+
return normalizeMapKey(path2.resolve(cwd));
|
|
439
|
+
}
|
|
440
|
+
function buildCacheKeyWorkspace(buildKey) {
|
|
441
|
+
const separator = buildKey.indexOf("|");
|
|
442
|
+
return separator >= 0 ? buildKey.slice(0, separator) : void 0;
|
|
443
|
+
}
|
|
444
|
+
function evictWorkspaceGraph(key, entry) {
|
|
445
|
+
if (_workspaceGraphCache.get(key) !== entry)
|
|
446
|
+
return;
|
|
447
|
+
clearWorkspaceGraphTimer(entry);
|
|
448
|
+
const buildWorkspace = buildCacheWorkspaceKey(key);
|
|
449
|
+
for (const buildKey of _buildCache.keys()) {
|
|
450
|
+
if (buildCacheKeyWorkspace(buildKey) === buildWorkspace) {
|
|
451
|
+
_buildCache.delete(buildKey);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
_sourcePathMemos.delete(key);
|
|
455
|
+
_workspaceCacheEpochs.set(key, (_workspaceCacheEpochs.get(key) ?? 0) + 1);
|
|
456
|
+
_workspaceGraphCache.delete(key);
|
|
457
|
+
}
|
|
458
|
+
function scheduleWorkspaceGraphEviction(key, entry) {
|
|
459
|
+
clearWorkspaceGraphTimer(entry);
|
|
460
|
+
const epoch = workspaceCacheEpoch(key);
|
|
461
|
+
entry.idleTimer = setTimeout(() => {
|
|
462
|
+
entry.idleTimer = void 0;
|
|
463
|
+
if (_workspaceGraphCache.get(key) !== entry || workspaceCacheEpoch(key) !== epoch)
|
|
464
|
+
return;
|
|
465
|
+
evictWorkspaceGraph(key, entry);
|
|
466
|
+
}, reviewGraphIdleEvictMs());
|
|
467
|
+
entry.idleTimer.unref?.();
|
|
468
|
+
}
|
|
469
|
+
function touchWorkspaceGraph(key) {
|
|
470
|
+
const entry = _workspaceGraphCache.get(key);
|
|
471
|
+
if (!entry)
|
|
472
|
+
return;
|
|
473
|
+
entry.lastUsedAt = Date.now();
|
|
474
|
+
scheduleWorkspaceGraphEviction(key, entry);
|
|
475
|
+
}
|
|
476
|
+
var _wasmTrappedFiles = /* @__PURE__ */ new Map();
|
|
477
|
+
function stampWasmTrapped(entries, includeCharged) {
|
|
478
|
+
let stamped;
|
|
479
|
+
for (const [file, state] of _wasmTrappedFiles) {
|
|
480
|
+
if ((includeCharged || state === "retry") && entries.has(file)) {
|
|
481
|
+
stamped ??= new Map(entries);
|
|
482
|
+
stamped.set(file, "wasm-trapped");
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
return stamped ?? entries;
|
|
486
|
+
}
|
|
487
|
+
function stampWasmTrappedFiles(stored, includeCharged) {
|
|
488
|
+
const fileSignatures = stampWasmTrapped(stored.fileSignatures, includeCharged);
|
|
489
|
+
if (fileSignatures === stored.fileSignatures)
|
|
490
|
+
return stored;
|
|
491
|
+
return {
|
|
492
|
+
...stored,
|
|
493
|
+
signature: sourceSignatureFromMap(fileSignatures),
|
|
494
|
+
fileSignatures,
|
|
495
|
+
fileHashes: stored.fileHashes && stampWasmTrapped(stored.fileHashes, includeCharged)
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
function wasmTrappedFileCount(graph) {
|
|
499
|
+
let count = 0;
|
|
500
|
+
for (const file of _wasmTrappedFiles.keys()) {
|
|
501
|
+
if (graph.fileNodes.has(file))
|
|
502
|
+
count++;
|
|
503
|
+
}
|
|
504
|
+
return count;
|
|
505
|
+
}
|
|
506
|
+
function graphWasmTrapDetail(wasmTrappedFiles) {
|
|
507
|
+
return `review graph degraded \u2014 tree-sitter wasm runtime failure in ${wasmTrappedFiles} file(s)`;
|
|
508
|
+
}
|
|
509
|
+
function setWorkspaceGraph(key, entry, epoch) {
|
|
510
|
+
if (epoch !== void 0 && workspaceCacheEpoch(key) !== epoch)
|
|
511
|
+
return false;
|
|
512
|
+
const previous = _workspaceGraphCache.get(key);
|
|
513
|
+
if (previous)
|
|
514
|
+
clearWorkspaceGraphTimer(previous);
|
|
515
|
+
const boundedGraph = retainedGraph(key, entry.graph);
|
|
516
|
+
const resident = {
|
|
517
|
+
...stampWasmTrappedFiles(entry, false),
|
|
518
|
+
graph: boundedGraph,
|
|
519
|
+
lastUsedAt: Date.now()
|
|
520
|
+
};
|
|
521
|
+
_workspaceGraphCache.set(key, resident);
|
|
522
|
+
scheduleWorkspaceGraphEviction(key, resident);
|
|
523
|
+
while (_workspaceGraphCache.size > REVIEW_GRAPH_MAX_WARM_WORKSPACES) {
|
|
524
|
+
const victim = [..._workspaceGraphCache.entries()].sort(([, a], [, b]) => a.lastUsedAt - b.lastUsedAt)[0];
|
|
525
|
+
if (!victim)
|
|
526
|
+
break;
|
|
527
|
+
evictWorkspaceGraph(victim[0], victim[1]);
|
|
528
|
+
}
|
|
529
|
+
return true;
|
|
530
|
+
}
|
|
531
|
+
var _graphGenerationCounter = 0;
|
|
532
|
+
var _buildIdCounter = 0;
|
|
533
|
+
var SEQ_FASTPATH_MAX_CHANGES = 32;
|
|
534
|
+
var SEQ_FASTPATH_REVERIFY_MS = 5 * 6e4;
|
|
535
|
+
var SEQ_FASTPATH_REVERIFY_EVERY = 20;
|
|
536
|
+
function graphLogMetadata(graph, options = {}) {
|
|
537
|
+
return makeReviewGraphBuildMetadata(graph, options);
|
|
538
|
+
}
|
|
539
|
+
function seqFastpathEnabled() {
|
|
540
|
+
const raw = process.env.PI_LENS_GRAPH_SEQ_FASTPATH;
|
|
541
|
+
return raw !== "0" && raw !== "false";
|
|
542
|
+
}
|
|
543
|
+
var _lastGraphBuildInfo = {
|
|
544
|
+
reused: false,
|
|
545
|
+
mode: "full",
|
|
546
|
+
graphChanged: true
|
|
547
|
+
};
|
|
548
|
+
var _graphBuildInfoByGraph = /* @__PURE__ */ new WeakMap();
|
|
549
|
+
var _anyGraphStamped = false;
|
|
550
|
+
function setGraphBuildInfo(graph, info) {
|
|
551
|
+
_lastGraphBuildInfo = info;
|
|
552
|
+
_graphBuildInfoByGraph.set(graph, info);
|
|
553
|
+
_anyGraphStamped = true;
|
|
554
|
+
}
|
|
555
|
+
function getGraphBuildInfoForGraph(graph) {
|
|
556
|
+
return _graphBuildInfoByGraph.get(graph) ?? _lastGraphBuildInfo;
|
|
557
|
+
}
|
|
558
|
+
function graphBuildInfoIsTrustworthy(graph) {
|
|
559
|
+
return _graphBuildInfoByGraph.has(graph) || !_anyGraphStamped;
|
|
560
|
+
}
|
|
561
|
+
function updateGraphBuildInfo(graph, patch) {
|
|
562
|
+
const info = { ...getGraphBuildInfoForGraph(graph), ...patch };
|
|
563
|
+
setGraphBuildInfo(graph, info);
|
|
564
|
+
return info;
|
|
565
|
+
}
|
|
566
|
+
function clearGraphCache() {
|
|
567
|
+
_buildCache.clear();
|
|
568
|
+
}
|
|
569
|
+
function clearReviewGraphWorkspaceCache(cwd) {
|
|
570
|
+
if (cwd === void 0) {
|
|
571
|
+
_buildCache.clear();
|
|
572
|
+
for (const entry of _workspaceGraphCache.values())
|
|
573
|
+
clearWorkspaceGraphTimer(entry);
|
|
574
|
+
_workspaceGraphCache.clear();
|
|
575
|
+
_sourcePathMemos.clear();
|
|
576
|
+
_workspaceCacheEpoch++;
|
|
577
|
+
_sizeSkipVerdicts.clear();
|
|
578
|
+
_retainedGraphSites.clear();
|
|
579
|
+
} else {
|
|
580
|
+
const normalized = normalizeMapKey(cwd);
|
|
581
|
+
const buildWorkspace = buildCacheWorkspaceKey(cwd);
|
|
582
|
+
for (const key of _buildCache.keys()) {
|
|
583
|
+
if (buildCacheKeyWorkspace(key) === buildWorkspace) {
|
|
584
|
+
_buildCache.delete(key);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
const entry = _workspaceGraphCache.get(normalized);
|
|
588
|
+
if (entry)
|
|
589
|
+
clearWorkspaceGraphTimer(entry);
|
|
590
|
+
_workspaceCacheEpochs.set(normalized, (_workspaceCacheEpochs.get(normalized) ?? 0) + 1);
|
|
591
|
+
_workspaceGraphCache.delete(normalized);
|
|
592
|
+
_sourcePathMemos.delete(normalized);
|
|
593
|
+
_sizeSkipVerdicts.delete(normalized);
|
|
594
|
+
}
|
|
595
|
+
_lastGraphBuildInfo = { reused: false, mode: "full", graphChanged: true };
|
|
596
|
+
_anyGraphStamped = false;
|
|
597
|
+
}
|
|
598
|
+
var _reviewGraphBuildGateForTests;
|
|
599
|
+
function _setReviewGraphBuildGateForTests(gate) {
|
|
600
|
+
_reviewGraphBuildGateForTests = gate;
|
|
601
|
+
}
|
|
602
|
+
var REVIEW_GRAPH_NODE_RESIDENT_BYTES = 450.5;
|
|
603
|
+
var REVIEW_GRAPH_EDGE_RESIDENT_BYTES = 243;
|
|
604
|
+
function estimateReviewGraphStoreBytes(totalNodes, totalEdges) {
|
|
605
|
+
return totalNodes * REVIEW_GRAPH_NODE_RESIDENT_BYTES + totalEdges * REVIEW_GRAPH_EDGE_RESIDENT_BYTES;
|
|
606
|
+
}
|
|
607
|
+
var GRAPH_MAX_IN_MEMORY_BYTES_DEFAULT = 512 * 1024 * 1024;
|
|
608
|
+
function graphMaxInMemoryBytes() {
|
|
609
|
+
const raw = Number(process.env.PI_LENS_GRAPH_MAX_IN_MEMORY_BYTES);
|
|
610
|
+
return Number.isFinite(raw) && raw > 0 ? raw : GRAPH_MAX_IN_MEMORY_BYTES_DEFAULT;
|
|
611
|
+
}
|
|
612
|
+
function retainedGraph(cwd, graph) {
|
|
613
|
+
const nodes = graph.nodes.size;
|
|
614
|
+
const edges = graph.edges.length;
|
|
615
|
+
const bytes = estimateReviewGraphStoreBytes(nodes, edges);
|
|
616
|
+
const budget = graphMaxInMemoryBytes();
|
|
617
|
+
if (bytes <= budget)
|
|
618
|
+
return graph;
|
|
619
|
+
const elementCap = Math.max(1, Math.floor((nodes + edges) * budget / bytes));
|
|
620
|
+
let capped = capGraphForPersist(cwd, graph, elementCap);
|
|
621
|
+
if (capped.nodes.size === 0 && nodes > 0) {
|
|
622
|
+
capped = headSliceGraph(graph, elementCap);
|
|
623
|
+
incrementDegradationCount({
|
|
624
|
+
kind: "review-graph-memory-cap-floor",
|
|
625
|
+
subject: cwd,
|
|
626
|
+
reason: `centrality selection retained 0 of ${nodes} nodes at cap ${elementCap}; fell back to a ${capped.nodes.size}-node head slice`
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
const cappedNodes = capped.nodes.size;
|
|
630
|
+
const cappedEdges = capped.edges.length;
|
|
631
|
+
capped.persistCoverage = {
|
|
632
|
+
...capped.persistCoverage ?? graphCoverage(capped, elementCap),
|
|
633
|
+
partial: true,
|
|
634
|
+
capTrimmed: true
|
|
635
|
+
};
|
|
636
|
+
incrementDegradationCount({
|
|
637
|
+
kind: "review-graph-memory-cap",
|
|
638
|
+
subject: cwd,
|
|
639
|
+
reason: `live graph ${nodes}n/${edges}e ~${Math.round(bytes / (1024 * 1024))}MiB over ${Math.round(budget / (1024 * 1024))}MiB budget; trimmed to ${cappedNodes}n/${cappedEdges}e ~${Math.round(estimateReviewGraphStoreBytes(cappedNodes, cappedEdges) / (1024 * 1024))}MiB`
|
|
640
|
+
});
|
|
641
|
+
return capped;
|
|
642
|
+
}
|
|
643
|
+
function headSliceGraph(graph, cap) {
|
|
644
|
+
const nodeBudget = Math.max(1, Math.floor(cap * graph.nodes.size / (graph.nodes.size + graph.edges.length)));
|
|
645
|
+
const keptIds = /* @__PURE__ */ new Set();
|
|
646
|
+
for (const [id] of graph.nodes) {
|
|
647
|
+
if (keptIds.size >= nodeBudget)
|
|
648
|
+
break;
|
|
649
|
+
keptIds.add(id);
|
|
650
|
+
}
|
|
651
|
+
const nodes = new Map([...graph.nodes].filter(([id]) => keptIds.has(id)));
|
|
652
|
+
const edgeBudget = Math.max(0, cap - nodes.size);
|
|
653
|
+
const edges = graph.edges.filter((edge) => keptIds.has(edge.from) && keptIds.has(edge.to)).slice(0, edgeBudget);
|
|
654
|
+
const sliced = {
|
|
655
|
+
...graph,
|
|
656
|
+
nodes,
|
|
657
|
+
edges,
|
|
658
|
+
edgesByFrom: /* @__PURE__ */ new Map(),
|
|
659
|
+
edgesByTo: /* @__PURE__ */ new Map(),
|
|
660
|
+
fileNodes: /* @__PURE__ */ new Map(),
|
|
661
|
+
symbolNodesByFile: /* @__PURE__ */ new Map(),
|
|
662
|
+
changedSymbolsByFile: /* @__PURE__ */ new Map(),
|
|
663
|
+
persistCoverage: void 0
|
|
664
|
+
};
|
|
665
|
+
rebuildIndexes(sliced);
|
|
666
|
+
return sliced;
|
|
667
|
+
}
|
|
668
|
+
function setSessionReviewGraphFact(cwd, facts, graph) {
|
|
669
|
+
const retained = retainedGraph(cwd, graph);
|
|
670
|
+
registerRetainedGraph(`fact:${cwd}`, retained);
|
|
671
|
+
facts.setSessionFact("session.reviewGraph", retained);
|
|
672
|
+
}
|
|
673
|
+
var _retainedGraphSites = /* @__PURE__ */ new Map();
|
|
674
|
+
function registerRetainedGraph(site, graph) {
|
|
675
|
+
for (const [key, ref] of _retainedGraphSites) {
|
|
676
|
+
if (ref.deref() === void 0)
|
|
677
|
+
_retainedGraphSites.delete(key);
|
|
678
|
+
}
|
|
679
|
+
_retainedGraphSites.set(site, new WeakRef(graph));
|
|
680
|
+
}
|
|
681
|
+
function getReviewGraphWorkspaceCacheSnapshot() {
|
|
682
|
+
let totalNodes = 0;
|
|
683
|
+
let totalEdges = 0;
|
|
684
|
+
const counted = /* @__PURE__ */ new Set();
|
|
685
|
+
const count = (graph) => {
|
|
686
|
+
if (counted.has(graph))
|
|
687
|
+
return;
|
|
688
|
+
counted.add(graph);
|
|
689
|
+
totalNodes += graph.nodes.size;
|
|
690
|
+
totalEdges += graph.edges.length;
|
|
691
|
+
};
|
|
692
|
+
for (const entry of _workspaceGraphCache.values())
|
|
693
|
+
count(entry.graph);
|
|
694
|
+
for (const [key, ref] of _retainedGraphSites) {
|
|
695
|
+
const graph = ref.deref();
|
|
696
|
+
if (graph === void 0) {
|
|
697
|
+
_retainedGraphSites.delete(key);
|
|
698
|
+
continue;
|
|
699
|
+
}
|
|
700
|
+
count(graph);
|
|
701
|
+
}
|
|
702
|
+
return {
|
|
703
|
+
cacheEntries: _workspaceGraphCache.size,
|
|
704
|
+
totalNodes,
|
|
705
|
+
totalEdges,
|
|
706
|
+
residentBytes: estimateReviewGraphStoreBytes(totalNodes, totalEdges)
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
function _getReviewGraphWorkspaceCacheKeysForTests() {
|
|
710
|
+
return [..._workspaceGraphCache.entries()].sort(([, a], [, b]) => a.lastUsedAt - b.lastUsedAt).map(([key]) => key);
|
|
711
|
+
}
|
|
712
|
+
function _setReviewGraphWorkspaceEntryForTests(key, graph) {
|
|
713
|
+
setWorkspaceGraph(key, {
|
|
714
|
+
signature: "test",
|
|
715
|
+
fileSignatures: /* @__PURE__ */ new Map(),
|
|
716
|
+
graph
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
function _setSessionReviewGraphFactForTests(cwd, facts, graph) {
|
|
720
|
+
setSessionReviewGraphFact(cwd, facts, graph);
|
|
721
|
+
}
|
|
722
|
+
function _persistedCoverageForTests(coverage) {
|
|
723
|
+
return stripProcessLocalCoverage(coverage);
|
|
724
|
+
}
|
|
725
|
+
function _getReviewGraphWorkspaceGraphForTests(key) {
|
|
726
|
+
return _workspaceGraphCache.get(key)?.graph;
|
|
727
|
+
}
|
|
728
|
+
function _getReviewGraphCacheStateForTests(cwd) {
|
|
729
|
+
const cached = _workspaceGraphCache.get(normalizeMapKey(cwd));
|
|
730
|
+
if (!cached)
|
|
731
|
+
return void 0;
|
|
732
|
+
touchWorkspaceGraph(normalizeMapKey(cwd));
|
|
733
|
+
return {
|
|
734
|
+
signature: cached.signature,
|
|
735
|
+
fileSignatures: new Map(cached.fileSignatures),
|
|
736
|
+
fileHashes: cached.fileHashes ? new Map(cached.fileHashes) : void 0
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
function getReviewGraphCacheIdentity(cwd, graph) {
|
|
740
|
+
const cached = _workspaceGraphCache.get(normalizeMapKey(cwd));
|
|
741
|
+
if (!cached)
|
|
742
|
+
return void 0;
|
|
743
|
+
touchWorkspaceGraph(normalizeMapKey(cwd));
|
|
744
|
+
if (graph) {
|
|
745
|
+
if (cached.buildGeneration === void 0 && graph.buildGeneration === void 0) {
|
|
746
|
+
if (cached.graph !== graph)
|
|
747
|
+
return void 0;
|
|
748
|
+
} else if (cached.buildGeneration !== graph.buildGeneration) {
|
|
749
|
+
return void 0;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
const version = graph?.version ?? cached.graph.version;
|
|
753
|
+
if (typeof version !== "string" || version.length === 0 || typeof cached.signature !== "string") {
|
|
754
|
+
return void 0;
|
|
755
|
+
}
|
|
756
|
+
return { version, signature: cached.signature };
|
|
757
|
+
}
|
|
758
|
+
var _cwdWorktreeCheckedCwds = /* @__PURE__ */ new Set();
|
|
759
|
+
function _resetCwdWorktreeMismatchLogForTests() {
|
|
760
|
+
_cwdWorktreeCheckedCwds.clear();
|
|
761
|
+
}
|
|
762
|
+
function logCwdWorktreeMismatchOnce(cwd, resolveIdentity = resolveGitIdentity) {
|
|
763
|
+
const key = normalizeMapKey(cwd);
|
|
764
|
+
if (_cwdWorktreeCheckedCwds.has(key))
|
|
765
|
+
return;
|
|
766
|
+
_cwdWorktreeCheckedCwds.add(key);
|
|
767
|
+
const identity = resolveIdentity(cwd);
|
|
768
|
+
if (!identity)
|
|
769
|
+
return;
|
|
770
|
+
if (identity.worktreeRoot === normalizeFilePath(path2.resolve(cwd)))
|
|
771
|
+
return;
|
|
772
|
+
logLatency({
|
|
773
|
+
type: "phase",
|
|
774
|
+
phase: "review_graph_cwd_worktree_mismatch",
|
|
775
|
+
filePath: cwd,
|
|
776
|
+
durationMs: 0,
|
|
777
|
+
metadata: { cwd, worktreeRoot: identity.worktreeRoot }
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
function getLastGraphBuildInfo() {
|
|
781
|
+
return _lastGraphBuildInfo;
|
|
782
|
+
}
|
|
783
|
+
function _setLastGraphBuildInfoForTests(info) {
|
|
784
|
+
_lastGraphBuildInfo = info;
|
|
785
|
+
}
|
|
786
|
+
function ensureIndexed(graph) {
|
|
787
|
+
if (graph.edges.length > 0 && graph.edgesByFrom.size === 0) {
|
|
788
|
+
rebuildIndexes(graph);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
function getCachedReviewGraph(cwd) {
|
|
792
|
+
const key = normalizeMapKey(cwd);
|
|
793
|
+
if (getReviewGraphSizeSkipVerdict(cwd))
|
|
794
|
+
return void 0;
|
|
795
|
+
const cached = _workspaceGraphCache.get(key);
|
|
796
|
+
if (cached) {
|
|
797
|
+
touchWorkspaceGraph(key);
|
|
798
|
+
ensureIndexed(cached.graph);
|
|
799
|
+
return cached.graph;
|
|
800
|
+
}
|
|
801
|
+
const disk = loadPersistedGraph(cwd, {
|
|
802
|
+
verifyWorktreeIdentity: true,
|
|
803
|
+
allowPartial: true
|
|
804
|
+
});
|
|
805
|
+
if (!disk)
|
|
806
|
+
return void 0;
|
|
807
|
+
setWorkspaceGraph(key, {
|
|
808
|
+
signature: disk.signature,
|
|
809
|
+
fileSignatures: disk.fileSignatures,
|
|
810
|
+
fileHashes: disk.fileHashes,
|
|
811
|
+
graph: disk.graph,
|
|
812
|
+
// Durable half of the drift fact. The current-HEAD half is never cached
|
|
813
|
+
// beside it — see getReviewGraphRevisionDrift (#1961 review F3).
|
|
814
|
+
...disk.stampedHead ? { snapshotStampedHead: disk.stampedHead } : {}
|
|
815
|
+
});
|
|
816
|
+
return disk.graph;
|
|
817
|
+
}
|
|
818
|
+
function getReviewGraphRevisionDrift(cwd) {
|
|
819
|
+
const entry = _workspaceGraphCache.get(normalizeMapKey(cwd));
|
|
820
|
+
const stampedHead = entry?.snapshotStampedHead;
|
|
821
|
+
if (!stampedHead)
|
|
822
|
+
return void 0;
|
|
823
|
+
const current = resolveGitIdentity(cwd);
|
|
824
|
+
if (!current || current.headCommit === stampedHead)
|
|
825
|
+
return void 0;
|
|
826
|
+
return { stampedHead, currentHead: current.headCommit };
|
|
827
|
+
}
|
|
828
|
+
function makeCtx(filePath, cwd, facts) {
|
|
829
|
+
return {
|
|
830
|
+
filePath,
|
|
831
|
+
cwd,
|
|
832
|
+
kind: detectFileKind(filePath),
|
|
833
|
+
fileRole: detectFileRole(filePath),
|
|
834
|
+
pi: { getFlag: () => void 0 },
|
|
835
|
+
autofix: false,
|
|
836
|
+
deltaMode: false,
|
|
837
|
+
facts,
|
|
838
|
+
blockingOnly: false,
|
|
839
|
+
modifiedRanges: void 0,
|
|
840
|
+
hasTool: async () => false,
|
|
841
|
+
log: () => {
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
function createEmptyGraph() {
|
|
846
|
+
return {
|
|
847
|
+
version: REVIEW_GRAPH_VERSION,
|
|
848
|
+
builtAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
849
|
+
nodes: /* @__PURE__ */ new Map(),
|
|
850
|
+
edges: [],
|
|
851
|
+
edgesByFrom: /* @__PURE__ */ new Map(),
|
|
852
|
+
edgesByTo: /* @__PURE__ */ new Map(),
|
|
853
|
+
fileNodes: /* @__PURE__ */ new Map(),
|
|
854
|
+
symbolNodesByFile: /* @__PURE__ */ new Map(),
|
|
855
|
+
changedSymbolsByFile: /* @__PURE__ */ new Map()
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
function cloneGraph(graph) {
|
|
859
|
+
return {
|
|
860
|
+
version: graph.version,
|
|
861
|
+
builtAt: graph.builtAt,
|
|
862
|
+
nodes: new Map(graph.nodes),
|
|
863
|
+
// Edges are immutable values: update paths replace/filter entries rather
|
|
864
|
+
// than mutating them, so copying the array is sufficient isolation.
|
|
865
|
+
edges: [...graph.edges],
|
|
866
|
+
edgesByFrom: /* @__PURE__ */ new Map(),
|
|
867
|
+
edgesByTo: /* @__PURE__ */ new Map(),
|
|
868
|
+
fileNodes: /* @__PURE__ */ new Map(),
|
|
869
|
+
symbolNodesByFile: /* @__PURE__ */ new Map(),
|
|
870
|
+
changedSymbolsByFile: new Map(graph.changedSymbolsByFile),
|
|
871
|
+
// Carry the partial-coverage marker so a clone can never silently pose as
|
|
872
|
+
// a complete graph (#936 review). The build path additionally refuses a
|
|
873
|
+
// partial base outright; this keeps any other cloner honest.
|
|
874
|
+
persistCoverage: graph.persistCoverage
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
function refreshGraphBuiltAt(graph) {
|
|
878
|
+
graph.builtAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
879
|
+
}
|
|
880
|
+
function sourceSignatureEntry(file) {
|
|
881
|
+
try {
|
|
882
|
+
const stat = fs2.statSync(file);
|
|
883
|
+
return `${stat.size}:${stat.mtimeMs}`;
|
|
884
|
+
} catch {
|
|
885
|
+
return "missing";
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
var STAT_YIELD_EVERY = 100;
|
|
889
|
+
var yieldToLoop = () => new Promise((resolve2) => setImmediate(resolve2));
|
|
890
|
+
async function sourceSignatureMapAsync(files) {
|
|
891
|
+
const signatures = /* @__PURE__ */ new Map();
|
|
892
|
+
let sinceYield = 0;
|
|
893
|
+
for (const file of files) {
|
|
894
|
+
signatures.set(file, sourceSignatureEntry(file));
|
|
895
|
+
if (++sinceYield >= STAT_YIELD_EVERY) {
|
|
896
|
+
sinceYield = 0;
|
|
897
|
+
await yieldToLoop();
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
return signatures;
|
|
901
|
+
}
|
|
902
|
+
function sourceSignatureFromMap(signatures) {
|
|
903
|
+
return [...signatures.entries()].sort(([a], [b]) => compareOrdinal(a, b)).map(([file, signature]) => `${file}:${signature}`).join("|");
|
|
904
|
+
}
|
|
905
|
+
function contentHashEntry(file) {
|
|
906
|
+
try {
|
|
907
|
+
return createHash2("sha256").update(fs2.readFileSync(file)).digest("hex");
|
|
908
|
+
} catch {
|
|
909
|
+
return "missing";
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
async function confirmContentChanged(candidates, previousHashes) {
|
|
913
|
+
const prior = previousHashes ?? /* @__PURE__ */ new Map();
|
|
914
|
+
const hashes = new Map(prior);
|
|
915
|
+
const trulyChanged = [];
|
|
916
|
+
let sinceYield = 0;
|
|
917
|
+
for (const file of candidates) {
|
|
918
|
+
const hash = contentHashEntry(file);
|
|
919
|
+
hashes.set(file, hash);
|
|
920
|
+
if (prior.get(file) !== hash)
|
|
921
|
+
trulyChanged.push(file);
|
|
922
|
+
if (++sinceYield >= STAT_YIELD_EVERY) {
|
|
923
|
+
sinceYield = 0;
|
|
924
|
+
await yieldToLoop();
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
return { trulyChanged, hashes };
|
|
928
|
+
}
|
|
929
|
+
function diffSignatureMaps(previous, next) {
|
|
930
|
+
const added = [];
|
|
931
|
+
const changed = [];
|
|
932
|
+
for (const [file, signature] of next) {
|
|
933
|
+
const oldSignature = previous.get(file);
|
|
934
|
+
if (oldSignature === void 0)
|
|
935
|
+
added.push(file);
|
|
936
|
+
else if (oldSignature !== signature)
|
|
937
|
+
changed.push(file);
|
|
938
|
+
}
|
|
939
|
+
const removed = [];
|
|
940
|
+
for (const file of previous.keys()) {
|
|
941
|
+
if (!next.has(file))
|
|
942
|
+
removed.push(file);
|
|
943
|
+
}
|
|
944
|
+
return { added, removed, changed };
|
|
945
|
+
}
|
|
946
|
+
function getReviewGraphMaxFiles(cwd) {
|
|
947
|
+
const override = Number.parseInt(process.env.PI_LENS_REVIEW_GRAPH_MAX_FILES ?? "", 10);
|
|
948
|
+
return Number.isFinite(override) && override > 0 ? override : getReviewGraphMaxFilesDerived(cwd);
|
|
949
|
+
}
|
|
950
|
+
function getReviewGraphMaxFileBytes() {
|
|
951
|
+
const override = Number.parseInt(process.env.PI_LENS_REVIEW_GRAPH_MAX_FILE_BYTES ?? "", 10);
|
|
952
|
+
return Number.isFinite(override) && override > 0 ? override : RUNTIME_CONFIG.reviewGraph.maxFileBytes;
|
|
953
|
+
}
|
|
954
|
+
function isWithinReviewGraphSizeLimit(file) {
|
|
955
|
+
try {
|
|
956
|
+
return fs2.statSync(file).size <= getReviewGraphMaxFileBytes();
|
|
957
|
+
} catch {
|
|
958
|
+
return false;
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
var DEFAULT_REVIEW_GRAPH_SIZE_SKIP_TTL_MS = 15 * 6e4;
|
|
962
|
+
var _sizeSkipTtl = lazyEnvNumber("PI_LENS_REVIEW_GRAPH_SIZE_SKIP_TTL_MS", DEFAULT_REVIEW_GRAPH_SIZE_SKIP_TTL_MS);
|
|
963
|
+
var _resetReviewGraphSizeSkipTtlForTests = _sizeSkipTtl._resetForTests;
|
|
964
|
+
var _buildAttempts = /* @__PURE__ */ new Map();
|
|
965
|
+
function getLastReviewGraphBuildAttempt(cwd) {
|
|
966
|
+
return _buildAttempts.get(normalizeMapKey(cwd));
|
|
967
|
+
}
|
|
968
|
+
function _resetReviewGraphBuildAttemptsForTests() {
|
|
969
|
+
_buildAttempts.clear();
|
|
970
|
+
}
|
|
971
|
+
function recordBuildAttempt(cwd, outcome, reason, buildId) {
|
|
972
|
+
const key = normalizeMapKey(cwd);
|
|
973
|
+
const prior = _buildAttempts.get(key);
|
|
974
|
+
if (prior?.buildId !== void 0 && (buildId === void 0 || buildId < prior.buildId)) {
|
|
975
|
+
return;
|
|
976
|
+
}
|
|
977
|
+
_buildAttempts.set(key, {
|
|
978
|
+
when: (/* @__PURE__ */ new Date()).toISOString(),
|
|
979
|
+
outcome,
|
|
980
|
+
...buildId === void 0 ? {} : { buildId },
|
|
981
|
+
...reason ? { reason } : {}
|
|
982
|
+
});
|
|
983
|
+
}
|
|
984
|
+
function recordPersistFailure(cwd, reason, error, pending, workerState) {
|
|
985
|
+
const prior = _buildAttempts.get(normalizeMapKey(cwd));
|
|
986
|
+
const pendingBuildId = pending?.graphMetadata.buildId;
|
|
987
|
+
const belongsToCurrentBuild = pendingBuildId === void 0 || prior?.buildId === pendingBuildId;
|
|
988
|
+
if (belongsToCurrentBuild && (prior === void 0 || prior.outcome === "succeeded")) {
|
|
989
|
+
recordBuildAttempt(cwd, "succeeded", `graph built but persistence failed: ${error}`, pendingBuildId);
|
|
990
|
+
}
|
|
991
|
+
logReviewGraph({
|
|
992
|
+
cwd,
|
|
993
|
+
phase: "persist_failed",
|
|
994
|
+
reason,
|
|
995
|
+
error,
|
|
996
|
+
...pending ? {
|
|
997
|
+
observability: persistObservability(pending, {
|
|
998
|
+
status: "failed",
|
|
999
|
+
reason: workerState?.fallbackReason ?? reason,
|
|
1000
|
+
workerStarted: workerState?.started,
|
|
1001
|
+
workerCompleted: workerState?.completed,
|
|
1002
|
+
...workerState?.fallbackReason ? { workerFallback: true } : {}
|
|
1003
|
+
})
|
|
1004
|
+
} : {}
|
|
1005
|
+
});
|
|
1006
|
+
}
|
|
1007
|
+
var _sizeSkipVerdicts = /* @__PURE__ */ new Map();
|
|
1008
|
+
function _resetReviewGraphSizeSkipVerdictsForTests() {
|
|
1009
|
+
_sizeSkipVerdicts.clear();
|
|
1010
|
+
}
|
|
1011
|
+
function recordReviewGraphSizeSkip(cwd, sourceFileCount, maxFileCount) {
|
|
1012
|
+
_sizeSkipVerdicts.set(normalizeMapKey(cwd), {
|
|
1013
|
+
sourceFileCount,
|
|
1014
|
+
maxFileCount,
|
|
1015
|
+
sourceFileCountTruncated: true,
|
|
1016
|
+
skippedAt: Date.now()
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
function clearReviewGraphSizeSkip(cwd) {
|
|
1020
|
+
_sizeSkipVerdicts.delete(normalizeMapKey(cwd));
|
|
1021
|
+
}
|
|
1022
|
+
var REVIEW_GRAPH_SIZE_NEAR_MISS_RATIO = 0.05;
|
|
1023
|
+
function isReviewGraphSizeNearMiss(sourceFileCount, maxFileCount) {
|
|
1024
|
+
return sourceFileCount > maxFileCount && sourceFileCount <= maxFileCount * (1 + REVIEW_GRAPH_SIZE_NEAR_MISS_RATIO);
|
|
1025
|
+
}
|
|
1026
|
+
function getReviewGraphSizeSkipVerdict(cwd, now = Date.now()) {
|
|
1027
|
+
const key = normalizeMapKey(cwd);
|
|
1028
|
+
const verdict = _sizeSkipVerdicts.get(key);
|
|
1029
|
+
if (!verdict)
|
|
1030
|
+
return void 0;
|
|
1031
|
+
if (now - verdict.skippedAt >= _sizeSkipTtl.get()) {
|
|
1032
|
+
_sizeSkipVerdicts.delete(key);
|
|
1033
|
+
return void 0;
|
|
1034
|
+
}
|
|
1035
|
+
return verdict;
|
|
1036
|
+
}
|
|
1037
|
+
var _reviewGraphEntryBudgetForTests;
|
|
1038
|
+
function _setReviewGraphEntryBudgetForTests(maxScanEntries) {
|
|
1039
|
+
_reviewGraphEntryBudgetForTests = maxScanEntries;
|
|
1040
|
+
}
|
|
1041
|
+
var _reviewGraphEntryCounterForTests;
|
|
1042
|
+
function _setReviewGraphEntryCounterForTests(counter) {
|
|
1043
|
+
_reviewGraphEntryCounterForTests = counter;
|
|
1044
|
+
}
|
|
1045
|
+
async function getGraphSourceFiles(cwd) {
|
|
1046
|
+
const sourceMemo = sourcePathMemo(cwd);
|
|
1047
|
+
const normalizeCallsBefore = sourceMemo.normalizeCalls.value;
|
|
1048
|
+
const maxGraphFiles = getReviewGraphMaxFiles(cwd);
|
|
1049
|
+
const { files: collected, entryBudgetExceeded } = await collectProjectSourceFilesWithBudgetAsync(cwd, {
|
|
1050
|
+
// Only walk graph-relevant extensions so the cap counts what the graph
|
|
1051
|
+
// keeps (post-filter), not JSON/YAML/MD noise it would discard anyway.
|
|
1052
|
+
extensions: MAIN_KIND_EXTENSIONS,
|
|
1053
|
+
maxFiles: maxGraphFiles + 1,
|
|
1054
|
+
..._reviewGraphEntryBudgetForTests === void 0 ? {} : { maxScanEntries: _reviewGraphEntryBudgetForTests },
|
|
1055
|
+
..._reviewGraphEntryCounterForTests === void 0 ? {} : { onEntryVisited: _reviewGraphEntryCounterForTests }
|
|
1056
|
+
});
|
|
1057
|
+
if (entryBudgetExceeded) {
|
|
1058
|
+
logLatency({
|
|
1059
|
+
type: "phase",
|
|
1060
|
+
phase: "review_graph_source_walk_entry_budget",
|
|
1061
|
+
filePath: cwd,
|
|
1062
|
+
durationMs: 0,
|
|
1063
|
+
metadata: { cwd, collectedFiles: collected.length }
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
if (collected.length > maxGraphFiles) {
|
|
1067
|
+
return {
|
|
1068
|
+
files: collected,
|
|
1069
|
+
pathNormalizeCalls: sourceMemo.normalizeCalls.value - normalizeCallsBefore,
|
|
1070
|
+
sourceFileCount: collected.length,
|
|
1071
|
+
maxFileCount: maxGraphFiles,
|
|
1072
|
+
entryBudgetExceeded
|
|
1073
|
+
};
|
|
1074
|
+
}
|
|
1075
|
+
const result = [];
|
|
1076
|
+
let sinceYield = 0;
|
|
1077
|
+
for (const raw of collected) {
|
|
1078
|
+
const file = normalizeGraphSourcePath(sourceMemo, raw);
|
|
1079
|
+
const kind = detectFileKind(file);
|
|
1080
|
+
if (!!kind && MAIN_KINDS.has(kind) && detectFileRole(file) !== "test" && isWithinReviewGraphSizeLimit(file)) {
|
|
1081
|
+
result.push(file);
|
|
1082
|
+
}
|
|
1083
|
+
if (++sinceYield >= STAT_YIELD_EVERY) {
|
|
1084
|
+
sinceYield = 0;
|
|
1085
|
+
await yieldToLoop();
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
return {
|
|
1089
|
+
files: result,
|
|
1090
|
+
pathNormalizeCalls: sourceMemo.normalizeCalls.value - normalizeCallsBefore,
|
|
1091
|
+
sourceFileCount: result.length,
|
|
1092
|
+
maxFileCount: maxGraphFiles,
|
|
1093
|
+
entryBudgetExceeded
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
function addNode(graph, node) {
|
|
1097
|
+
const isNew = !graph.nodes.has(node.id);
|
|
1098
|
+
graph.nodes.set(node.id, node);
|
|
1099
|
+
if (node.kind === "file" && node.filePath) {
|
|
1100
|
+
graph.fileNodes.set(node.filePath, node.id);
|
|
1101
|
+
return;
|
|
1102
|
+
}
|
|
1103
|
+
if (isNew && node.kind === "symbol" && node.filePath) {
|
|
1104
|
+
const ids = graph.symbolNodesByFile.get(node.filePath) ?? [];
|
|
1105
|
+
ids.push(node.id);
|
|
1106
|
+
graph.symbolNodesByFile.set(node.filePath, ids);
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
function indexEdge(graph, edge) {
|
|
1110
|
+
const from = graph.edgesByFrom.get(edge.from) ?? [];
|
|
1111
|
+
from.push(edge);
|
|
1112
|
+
graph.edgesByFrom.set(edge.from, from);
|
|
1113
|
+
const to = graph.edgesByTo.get(edge.to) ?? [];
|
|
1114
|
+
to.push(edge);
|
|
1115
|
+
graph.edgesByTo.set(edge.to, to);
|
|
1116
|
+
}
|
|
1117
|
+
function unindexEdge(graph, edge) {
|
|
1118
|
+
const from = graph.edgesByFrom.get(edge.from);
|
|
1119
|
+
if (from) {
|
|
1120
|
+
_rebuildCounters.removeOwnedEdgePositions += from.length;
|
|
1121
|
+
const at = from.indexOf(edge);
|
|
1122
|
+
if (at >= 0)
|
|
1123
|
+
from.splice(at, 1);
|
|
1124
|
+
if (from.length === 0)
|
|
1125
|
+
graph.edgesByFrom.delete(edge.from);
|
|
1126
|
+
}
|
|
1127
|
+
const to = graph.edgesByTo.get(edge.to);
|
|
1128
|
+
if (to) {
|
|
1129
|
+
_rebuildCounters.removeOwnedEdgePositions += to.length;
|
|
1130
|
+
const at = to.indexOf(edge);
|
|
1131
|
+
if (at >= 0)
|
|
1132
|
+
to.splice(at, 1);
|
|
1133
|
+
if (to.length === 0)
|
|
1134
|
+
graph.edgesByTo.delete(edge.to);
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
function unindexEdges(graph, removedEdges) {
|
|
1138
|
+
const fromIds = /* @__PURE__ */ new Set();
|
|
1139
|
+
const toIds = /* @__PURE__ */ new Set();
|
|
1140
|
+
for (const edge of removedEdges) {
|
|
1141
|
+
fromIds.add(edge.from);
|
|
1142
|
+
toIds.add(edge.to);
|
|
1143
|
+
}
|
|
1144
|
+
for (const fromId of fromIds) {
|
|
1145
|
+
const bucket = graph.edgesByFrom.get(fromId);
|
|
1146
|
+
if (!bucket)
|
|
1147
|
+
continue;
|
|
1148
|
+
const kept = [];
|
|
1149
|
+
for (const edge of bucket) {
|
|
1150
|
+
_rebuildCounters.removeOwnedEdgePositions++;
|
|
1151
|
+
if (!removedEdges.has(edge))
|
|
1152
|
+
kept.push(edge);
|
|
1153
|
+
}
|
|
1154
|
+
if (kept.length === 0)
|
|
1155
|
+
graph.edgesByFrom.delete(fromId);
|
|
1156
|
+
else
|
|
1157
|
+
graph.edgesByFrom.set(fromId, kept);
|
|
1158
|
+
}
|
|
1159
|
+
for (const toId of toIds) {
|
|
1160
|
+
const bucket = graph.edgesByTo.get(toId);
|
|
1161
|
+
if (!bucket)
|
|
1162
|
+
continue;
|
|
1163
|
+
const kept = [];
|
|
1164
|
+
for (const edge of bucket) {
|
|
1165
|
+
_rebuildCounters.removeOwnedEdgePositions++;
|
|
1166
|
+
if (!removedEdges.has(edge))
|
|
1167
|
+
kept.push(edge);
|
|
1168
|
+
}
|
|
1169
|
+
if (kept.length === 0)
|
|
1170
|
+
graph.edgesByTo.delete(toId);
|
|
1171
|
+
else
|
|
1172
|
+
graph.edgesByTo.set(toId, kept);
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
function addEdge(graph, edge) {
|
|
1176
|
+
graph.edges.push(edge);
|
|
1177
|
+
indexEdge(graph, edge);
|
|
1178
|
+
}
|
|
1179
|
+
function rebuildIndexes(graph) {
|
|
1180
|
+
graph.edgesByFrom = /* @__PURE__ */ new Map();
|
|
1181
|
+
graph.edgesByTo = /* @__PURE__ */ new Map();
|
|
1182
|
+
graph.fileNodes = /* @__PURE__ */ new Map();
|
|
1183
|
+
graph.symbolNodesByFile = /* @__PURE__ */ new Map();
|
|
1184
|
+
for (const node of graph.nodes.values()) {
|
|
1185
|
+
if (node.kind === "file" && node.filePath) {
|
|
1186
|
+
graph.fileNodes.set(node.filePath, node.id);
|
|
1187
|
+
}
|
|
1188
|
+
if (node.kind === "symbol" && node.filePath) {
|
|
1189
|
+
const ids = graph.symbolNodesByFile.get(node.filePath) ?? [];
|
|
1190
|
+
ids.push(node.id);
|
|
1191
|
+
graph.symbolNodesByFile.set(node.filePath, ids);
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
for (const edge of graph.edges) {
|
|
1195
|
+
const from = graph.edgesByFrom.get(edge.from) ?? [];
|
|
1196
|
+
from.push(edge);
|
|
1197
|
+
graph.edgesByFrom.set(edge.from, from);
|
|
1198
|
+
const to = graph.edgesByTo.get(edge.to) ?? [];
|
|
1199
|
+
to.push(edge);
|
|
1200
|
+
graph.edgesByTo.set(edge.to, to);
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
var GRAPH_CACHE_FILENAME = "review-graph.json.gz";
|
|
1204
|
+
var LEGACY_GRAPH_CACHE_FILENAME = "review-graph.json";
|
|
1205
|
+
var GRAPH_CHECKPOINT_FILENAME = "review-graph.checkpoint.json.gz";
|
|
1206
|
+
function logSnapshotReadVerdict(cwd, phase, reason) {
|
|
1207
|
+
const verdict = phase === "snapshot_read_dropped" ? "dropped" : "drifted";
|
|
1208
|
+
const isRisingEdge = incrementDegradationCount({
|
|
1209
|
+
kind: "review-graph-snapshot-read",
|
|
1210
|
+
// Subject keeps BOTH discriminators, so aggregation still answers which
|
|
1211
|
+
// workspace and which verdict after the detailed records stop.
|
|
1212
|
+
subject: `${verdict}:${normalizeMapKey(cwd)}`,
|
|
1213
|
+
reason
|
|
1214
|
+
});
|
|
1215
|
+
if (!isRisingEdge)
|
|
1216
|
+
return;
|
|
1217
|
+
logReviewGraph({ cwd, phase, reason });
|
|
1218
|
+
}
|
|
1219
|
+
function loadPersistedGraph(cwd, opts, resolveIdentity = resolveGitIdentity) {
|
|
1220
|
+
const cacheDir = path2.join(getProjectDataDir(cwd), "cache");
|
|
1221
|
+
const cachePath = path2.join(cacheDir, GRAPH_CACHE_FILENAME);
|
|
1222
|
+
const legacyPath = path2.join(cacheDir, LEGACY_GRAPH_CACHE_FILENAME);
|
|
1223
|
+
try {
|
|
1224
|
+
const raw = fs2.existsSync(cachePath) ? gunzipSync(fs2.readFileSync(cachePath)).toString("utf-8") : fs2.readFileSync(legacyPath, "utf-8");
|
|
1225
|
+
const data = JSON.parse(raw);
|
|
1226
|
+
if (data.version !== REVIEW_GRAPH_VERSION || typeof data.signature !== "string" || typeof data.builtAt !== "string" || !Array.isArray(data.nodes) || !Array.isArray(data.edges))
|
|
1227
|
+
return null;
|
|
1228
|
+
if (data.coverage?.partial && !opts?.allowPartial)
|
|
1229
|
+
return null;
|
|
1230
|
+
let stampedHead;
|
|
1231
|
+
if (opts?.verifyWorktreeIdentity && data.gitStamp) {
|
|
1232
|
+
const current = resolveIdentity(cwd);
|
|
1233
|
+
if (current && current.worktreeRoot !== data.gitStamp.worktreeRoot) {
|
|
1234
|
+
logSnapshotReadVerdict(cwd, "snapshot_read_dropped", "worktree_mismatch");
|
|
1235
|
+
return null;
|
|
1236
|
+
}
|
|
1237
|
+
if (current && current.headCommit !== data.gitStamp.headCommit) {
|
|
1238
|
+
stampedHead = data.gitStamp.headCommit;
|
|
1239
|
+
logSnapshotReadVerdict(cwd, "snapshot_read_drifted", "head_moved");
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
const graph = {
|
|
1243
|
+
version: data.version,
|
|
1244
|
+
builtAt: data.builtAt,
|
|
1245
|
+
nodes: new Map(data.nodes),
|
|
1246
|
+
edges: data.edges,
|
|
1247
|
+
edgesByFrom: /* @__PURE__ */ new Map(),
|
|
1248
|
+
edgesByTo: /* @__PURE__ */ new Map(),
|
|
1249
|
+
fileNodes: /* @__PURE__ */ new Map(),
|
|
1250
|
+
symbolNodesByFile: /* @__PURE__ */ new Map(),
|
|
1251
|
+
changedSymbolsByFile: /* @__PURE__ */ new Map(),
|
|
1252
|
+
persistCoverage: data.coverage
|
|
1253
|
+
};
|
|
1254
|
+
rebuildIndexes(graph);
|
|
1255
|
+
return {
|
|
1256
|
+
signature: data.signature,
|
|
1257
|
+
fileSignatures: new Map(data.fileSignatures ?? []),
|
|
1258
|
+
fileHashes: new Map(data.fileHashes ?? []),
|
|
1259
|
+
graph,
|
|
1260
|
+
...stampedHead ? { stampedHead } : {}
|
|
1261
|
+
};
|
|
1262
|
+
} catch {
|
|
1263
|
+
return null;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
function getPersistedReviewGraphVersion(cwd) {
|
|
1267
|
+
const cacheDir = path2.join(getProjectDataDir(cwd), "cache");
|
|
1268
|
+
const cachePath = path2.join(cacheDir, GRAPH_CACHE_FILENAME);
|
|
1269
|
+
const legacyPath = path2.join(cacheDir, LEGACY_GRAPH_CACHE_FILENAME);
|
|
1270
|
+
if (fs2.existsSync(cachePath)) {
|
|
1271
|
+
let fd2;
|
|
1272
|
+
try {
|
|
1273
|
+
fd2 = fs2.openSync(cachePath, "r");
|
|
1274
|
+
const compressed = Buffer.alloc(4096);
|
|
1275
|
+
const n = fs2.readSync(fd2, compressed, 0, compressed.length, 0);
|
|
1276
|
+
const head = gunzipSync(compressed.subarray(0, n), {
|
|
1277
|
+
finishFlush: zlibConstants.Z_SYNC_FLUSH
|
|
1278
|
+
}).toString("utf-8");
|
|
1279
|
+
const match = head.match(/"version"\s*:\s*"([^"]+)"/);
|
|
1280
|
+
return match ? match[1] : null;
|
|
1281
|
+
} catch {
|
|
1282
|
+
return null;
|
|
1283
|
+
} finally {
|
|
1284
|
+
if (fd2 !== void 0) {
|
|
1285
|
+
try {
|
|
1286
|
+
fs2.closeSync(fd2);
|
|
1287
|
+
} catch {
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
let fd;
|
|
1293
|
+
try {
|
|
1294
|
+
fd = fs2.openSync(legacyPath, "r");
|
|
1295
|
+
const buf = Buffer.alloc(200);
|
|
1296
|
+
const n = fs2.readSync(fd, buf, 0, 200, 0);
|
|
1297
|
+
const match = buf.toString("utf-8", 0, n).match(/"version"\s*:\s*"([^"]+)"/);
|
|
1298
|
+
return match ? match[1] : null;
|
|
1299
|
+
} catch {
|
|
1300
|
+
return null;
|
|
1301
|
+
} finally {
|
|
1302
|
+
if (fd !== void 0) {
|
|
1303
|
+
try {
|
|
1304
|
+
fs2.closeSync(fd);
|
|
1305
|
+
} catch {
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
function isReviewGraphMigrationNeeded(cwd) {
|
|
1311
|
+
const version = getPersistedReviewGraphVersion(cwd);
|
|
1312
|
+
return version !== null && version !== REVIEW_GRAPH_VERSION;
|
|
1313
|
+
}
|
|
1314
|
+
var GRAPH_PERSIST_DEBOUNCE_MS_DEFAULT = 1500;
|
|
1315
|
+
var GRAPH_PERSIST_MAX_ELEMENTS_DEFAULT = 5e5;
|
|
1316
|
+
function graphPersistDebounceMs() {
|
|
1317
|
+
const raw = Number(process.env.PI_LENS_GRAPH_PERSIST_DEBOUNCE_MS);
|
|
1318
|
+
return Number.isFinite(raw) && raw >= 0 ? raw : GRAPH_PERSIST_DEBOUNCE_MS_DEFAULT;
|
|
1319
|
+
}
|
|
1320
|
+
function graphPersistMaxElements() {
|
|
1321
|
+
const raw = Number(process.env.PI_LENS_GRAPH_PERSIST_MAX_ELEMENTS);
|
|
1322
|
+
return Number.isFinite(raw) && raw > 0 ? raw : GRAPH_PERSIST_MAX_ELEMENTS_DEFAULT;
|
|
1323
|
+
}
|
|
1324
|
+
var _pendingPersist = /* @__PURE__ */ new Map();
|
|
1325
|
+
var _persistTimers = /* @__PURE__ */ new Map();
|
|
1326
|
+
var _persistGenerations = /* @__PURE__ */ new Map();
|
|
1327
|
+
var _workerRequests = /* @__PURE__ */ new Map();
|
|
1328
|
+
var _persistWorker;
|
|
1329
|
+
var _persistWorkerRequestId = 0;
|
|
1330
|
+
var _persistAttemptId = 0;
|
|
1331
|
+
var _workerDisabled = false;
|
|
1332
|
+
var _persistWorkerUnavailableReason;
|
|
1333
|
+
var _lastWorkerFallbackReasonForTests;
|
|
1334
|
+
var _persistWorkerHeapStatistics = null;
|
|
1335
|
+
function refreshReviewGraphPersistWorkerHeapStatistics() {
|
|
1336
|
+
const worker = _persistWorker;
|
|
1337
|
+
if (!worker || typeof worker.getHeapStatistics !== "function") {
|
|
1338
|
+
return Promise.resolve();
|
|
1339
|
+
}
|
|
1340
|
+
return readWorkerHeapStatistics(worker).then((stats) => {
|
|
1341
|
+
if (_persistWorker === worker)
|
|
1342
|
+
_persistWorkerHeapStatistics = stats;
|
|
1343
|
+
}).catch(() => {
|
|
1344
|
+
});
|
|
1345
|
+
}
|
|
1346
|
+
function getReviewGraphPersistWorkerHeapStatistics() {
|
|
1347
|
+
return _persistWorkerHeapStatistics;
|
|
1348
|
+
}
|
|
1349
|
+
var _checkpointGenerations = /* @__PURE__ */ new Map();
|
|
1350
|
+
var _checkpointWorkerRequests = /* @__PURE__ */ new Map();
|
|
1351
|
+
var _checkpointOffloadCountForTests = 0;
|
|
1352
|
+
function persistedData(pending) {
|
|
1353
|
+
return {
|
|
1354
|
+
version: pending.graph.version,
|
|
1355
|
+
builtAt: pending.graph.builtAt,
|
|
1356
|
+
signature: pending.signature,
|
|
1357
|
+
fileSignatures: Array.from(pending.fileSignatures.entries()),
|
|
1358
|
+
fileHashes: pending.fileHashes ? Array.from(pending.fileHashes.entries()) : void 0,
|
|
1359
|
+
nodes: Array.from(pending.graph.nodes.entries()),
|
|
1360
|
+
edges: pending.graph.edges,
|
|
1361
|
+
coverage: stripProcessLocalCoverage(pending.graph.persistCoverage),
|
|
1362
|
+
gitStamp: pending.gitStamp
|
|
1363
|
+
};
|
|
1364
|
+
}
|
|
1365
|
+
function stripProcessLocalCoverage(coverage) {
|
|
1366
|
+
if (!coverage?.capTrimmed)
|
|
1367
|
+
return coverage;
|
|
1368
|
+
const { capTrimmed: _capTrimmed, ...persisted } = coverage;
|
|
1369
|
+
return persisted;
|
|
1370
|
+
}
|
|
1371
|
+
function countRetainedSourceFiles(graph, sourceFilePaths) {
|
|
1372
|
+
if (sourceFilePaths === void 0)
|
|
1373
|
+
return graph.fileNodes.size;
|
|
1374
|
+
const sourceKeys = new Set(sourceFilePaths);
|
|
1375
|
+
let retained = 0;
|
|
1376
|
+
for (const filePath of sourceKeys) {
|
|
1377
|
+
if (graph.fileNodes.has(filePath))
|
|
1378
|
+
retained++;
|
|
1379
|
+
}
|
|
1380
|
+
return retained;
|
|
1381
|
+
}
|
|
1382
|
+
function graphCoverage(graph, cap, sourceFileCount = graph.persistCoverage?.totalFiles ?? graph.fileNodes.size, sourceFilesTruncated = graph.persistCoverage?.sourceFilesTruncated === true, sourceFilePaths) {
|
|
1383
|
+
const inherited = graph.persistCoverage;
|
|
1384
|
+
return {
|
|
1385
|
+
partial: inherited?.partial === true || sourceFilesTruncated,
|
|
1386
|
+
cap,
|
|
1387
|
+
totalNodes: graph.nodes.size,
|
|
1388
|
+
totalEdges: graph.edges.length,
|
|
1389
|
+
persistedNodes: graph.nodes.size,
|
|
1390
|
+
persistedEdges: graph.edges.length,
|
|
1391
|
+
totalFiles: sourceFileCount,
|
|
1392
|
+
persistedFiles: countRetainedSourceFiles(graph, sourceFilePaths),
|
|
1393
|
+
...sourceFilesTruncated ? { sourceFilesTruncated: true } : {},
|
|
1394
|
+
...inherited?.inProgress ? { inProgress: true } : {}
|
|
1395
|
+
};
|
|
1396
|
+
}
|
|
1397
|
+
function capGraphForPersist(cwd, graph, cap, options = {}) {
|
|
1398
|
+
const totalElements = graph.nodes.size + graph.edges.length;
|
|
1399
|
+
const nodeBudget = Math.max(1, Math.floor(cap * graph.nodes.size / totalElements));
|
|
1400
|
+
const reverseDeps = buildReverseDependencyIndexFromGraph({ cwd, graph });
|
|
1401
|
+
const rankedFiles = rankFilesByReverseDependencyCentrality(reverseDeps);
|
|
1402
|
+
const indexNodesByFile = (fold) => {
|
|
1403
|
+
const byFile = /* @__PURE__ */ new Map();
|
|
1404
|
+
for (const [id, node] of graph.nodes) {
|
|
1405
|
+
if (!node.filePath)
|
|
1406
|
+
continue;
|
|
1407
|
+
const fileKey = fold ? normalizeMapKey(node.filePath) : node.filePath;
|
|
1408
|
+
const ids = byFile.get(fileKey) ?? [];
|
|
1409
|
+
ids.push(id);
|
|
1410
|
+
byFile.set(fileKey, ids);
|
|
1411
|
+
}
|
|
1412
|
+
return byFile;
|
|
1413
|
+
};
|
|
1414
|
+
const reachableNodes = (byFile) => {
|
|
1415
|
+
let reached = 0;
|
|
1416
|
+
for (const filePath of rankedFiles)
|
|
1417
|
+
reached += byFile.get(filePath)?.length ?? 0;
|
|
1418
|
+
return reached;
|
|
1419
|
+
};
|
|
1420
|
+
let placeableNodes = 0;
|
|
1421
|
+
for (const node of graph.nodes.values())
|
|
1422
|
+
if (node.filePath)
|
|
1423
|
+
placeableNodes++;
|
|
1424
|
+
let nodeIdsByFile = indexNodesByFile(false);
|
|
1425
|
+
if (reachableNodes(nodeIdsByFile) < placeableNodes) {
|
|
1426
|
+
const folded = indexNodesByFile(true);
|
|
1427
|
+
if (reachableNodes(folded) > reachableNodes(nodeIdsByFile)) {
|
|
1428
|
+
nodeIdsByFile = folded;
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
const keptIds = /* @__PURE__ */ new Set();
|
|
1432
|
+
for (const filePath of rankedFiles) {
|
|
1433
|
+
const ids = nodeIdsByFile.get(filePath) ?? [];
|
|
1434
|
+
if (ids.length === 0)
|
|
1435
|
+
continue;
|
|
1436
|
+
const effectiveNodeBudget = keptIds.size === 0 ? Math.max(nodeBudget, Math.min(cap, ids.length)) : nodeBudget;
|
|
1437
|
+
if (keptIds.size + ids.length > effectiveNodeBudget)
|
|
1438
|
+
continue;
|
|
1439
|
+
for (const id of ids)
|
|
1440
|
+
keptIds.add(id);
|
|
1441
|
+
}
|
|
1442
|
+
const nodes = new Map([...graph.nodes].filter(([id]) => keptIds.has(id)));
|
|
1443
|
+
const edgeBudget = Math.max(0, cap - nodes.size);
|
|
1444
|
+
const edges = graph.edges.filter((edge) => keptIds.has(edge.from) && keptIds.has(edge.to)).slice(0, edgeBudget);
|
|
1445
|
+
const coverage = {
|
|
1446
|
+
partial: true,
|
|
1447
|
+
cap,
|
|
1448
|
+
totalNodes: graph.nodes.size,
|
|
1449
|
+
totalEdges: graph.edges.length,
|
|
1450
|
+
persistedNodes: nodes.size,
|
|
1451
|
+
persistedEdges: edges.length,
|
|
1452
|
+
totalFiles: options.sourceFileCount ?? graph.persistCoverage?.totalFiles ?? graph.fileNodes.size,
|
|
1453
|
+
persistedFiles: 0,
|
|
1454
|
+
...options.sourceFilesTruncated || graph.persistCoverage?.sourceFilesTruncated ? { sourceFilesTruncated: true } : {},
|
|
1455
|
+
...graph.persistCoverage?.inProgress ? { inProgress: true } : {}
|
|
1456
|
+
};
|
|
1457
|
+
const capped = {
|
|
1458
|
+
...graph,
|
|
1459
|
+
nodes,
|
|
1460
|
+
edges,
|
|
1461
|
+
edgesByFrom: /* @__PURE__ */ new Map(),
|
|
1462
|
+
edgesByTo: /* @__PURE__ */ new Map(),
|
|
1463
|
+
fileNodes: /* @__PURE__ */ new Map(),
|
|
1464
|
+
symbolNodesByFile: /* @__PURE__ */ new Map(),
|
|
1465
|
+
changedSymbolsByFile: /* @__PURE__ */ new Map(),
|
|
1466
|
+
persistCoverage: void 0
|
|
1467
|
+
};
|
|
1468
|
+
rebuildIndexes(capped);
|
|
1469
|
+
coverage.persistedFiles = countRetainedSourceFiles(capped, options.sourceFilePaths);
|
|
1470
|
+
capped.persistCoverage = coverage;
|
|
1471
|
+
return capped;
|
|
1472
|
+
}
|
|
1473
|
+
function persistObservability(pending, patch) {
|
|
1474
|
+
return {
|
|
1475
|
+
graph: pending.graphMetadata,
|
|
1476
|
+
persistence: { ...pending.persistenceMetadata, ...patch }
|
|
1477
|
+
};
|
|
1478
|
+
}
|
|
1479
|
+
function logPersistSuccess(key, pending, stats, workerState = { started: false, completed: false }) {
|
|
1480
|
+
logLatency({
|
|
1481
|
+
type: "phase",
|
|
1482
|
+
phase: "review_graph_persist",
|
|
1483
|
+
filePath: pending.cachePath,
|
|
1484
|
+
durationMs: stats.durationMs,
|
|
1485
|
+
metadata: { elements: pending.elementCount, ...stats }
|
|
1486
|
+
});
|
|
1487
|
+
logReviewGraph({
|
|
1488
|
+
cwd: key,
|
|
1489
|
+
phase: "persist_succeeded",
|
|
1490
|
+
elements: pending.elementCount,
|
|
1491
|
+
...stats,
|
|
1492
|
+
durationMs: stats.durationMs,
|
|
1493
|
+
observability: persistObservability(pending, {
|
|
1494
|
+
status: "succeeded",
|
|
1495
|
+
workerStarted: workerState.started,
|
|
1496
|
+
workerCompleted: workerState.completed,
|
|
1497
|
+
...workerState.fallback ? { workerFallback: true } : {}
|
|
1498
|
+
})
|
|
1499
|
+
});
|
|
1500
|
+
}
|
|
1501
|
+
function writePendingOnMainThread(key, pending, reason, workerState = { started: false, completed: false }) {
|
|
1502
|
+
const persistStarted = performance.now();
|
|
1503
|
+
const serializeStarted = performance.now();
|
|
1504
|
+
try {
|
|
1505
|
+
const json = JSON.stringify(persistedData(pending));
|
|
1506
|
+
const serializeMs = performance.now() - serializeStarted;
|
|
1507
|
+
const rawBytes = Buffer.byteLength(json);
|
|
1508
|
+
const writeStarted = performance.now();
|
|
1509
|
+
const gzip = gzipSync(json);
|
|
1510
|
+
fs2.mkdirSync(pending.cacheDir, { recursive: true });
|
|
1511
|
+
writeFileAtomic(pending.cachePath, gzip, { bestEffort: false });
|
|
1512
|
+
fs2.rmSync(path2.join(pending.cacheDir, LEGACY_GRAPH_CACHE_FILENAME), {
|
|
1513
|
+
force: true
|
|
1514
|
+
});
|
|
1515
|
+
logPersistSuccess(key, pending, {
|
|
1516
|
+
rawBytes,
|
|
1517
|
+
gzBytes: gzip.byteLength,
|
|
1518
|
+
serializeMs,
|
|
1519
|
+
writeMs: performance.now() - writeStarted,
|
|
1520
|
+
durationMs: performance.now() - persistStarted,
|
|
1521
|
+
offloaded: false
|
|
1522
|
+
}, {
|
|
1523
|
+
started: workerState.started,
|
|
1524
|
+
completed: workerState.completed,
|
|
1525
|
+
fallback: Boolean(reason)
|
|
1526
|
+
});
|
|
1527
|
+
if (reason) {
|
|
1528
|
+
_lastWorkerFallbackReasonForTests = reason;
|
|
1529
|
+
logReviewGraph({
|
|
1530
|
+
cwd: key,
|
|
1531
|
+
phase: "worker_fallback",
|
|
1532
|
+
reason: "worker_fallback",
|
|
1533
|
+
error: reason,
|
|
1534
|
+
offloaded: false,
|
|
1535
|
+
observability: persistObservability(pending, {
|
|
1536
|
+
status: "fallback",
|
|
1537
|
+
workerStarted: workerState.started,
|
|
1538
|
+
workerCompleted: workerState.completed,
|
|
1539
|
+
workerFallback: true,
|
|
1540
|
+
reason: workerState.fallbackReason ?? "worker_fallback"
|
|
1541
|
+
})
|
|
1542
|
+
});
|
|
1543
|
+
}
|
|
1544
|
+
} catch (err) {
|
|
1545
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1546
|
+
recordPersistFailure(key, "cache_write_failed", message, pending, workerState);
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
function handleWorkerResult(result) {
|
|
1550
|
+
const checkpoint = _checkpointWorkerRequests.get(result.id);
|
|
1551
|
+
if (checkpoint) {
|
|
1552
|
+
handleCheckpointWorkerResult(checkpoint, result);
|
|
1553
|
+
return;
|
|
1554
|
+
}
|
|
1555
|
+
const request = _workerRequests.get(result.id);
|
|
1556
|
+
if (!request) {
|
|
1557
|
+
fs2.rm(result.stagePath, { force: true }, () => {
|
|
1558
|
+
});
|
|
1559
|
+
return;
|
|
1560
|
+
}
|
|
1561
|
+
_workerRequests.delete(result.id);
|
|
1562
|
+
const { key, pending } = request;
|
|
1563
|
+
const currentGeneration = _persistGenerations.get(key);
|
|
1564
|
+
if (currentGeneration !== result.generation) {
|
|
1565
|
+
try {
|
|
1566
|
+
fs2.rmSync(result.stagePath, { force: true });
|
|
1567
|
+
} catch (reapErr) {
|
|
1568
|
+
logReviewGraph({
|
|
1569
|
+
cwd: key,
|
|
1570
|
+
phase: "persist_failed",
|
|
1571
|
+
reason: `superseded-stage reap failed: ${String(reapErr)}`
|
|
1572
|
+
});
|
|
1573
|
+
}
|
|
1574
|
+
logReviewGraph({
|
|
1575
|
+
cwd: key,
|
|
1576
|
+
phase: "persist_skipped",
|
|
1577
|
+
reason: "superseded",
|
|
1578
|
+
observability: persistObservability(pending, {
|
|
1579
|
+
status: "superseded",
|
|
1580
|
+
supersededByGeneration: currentGeneration,
|
|
1581
|
+
reason: "newer_generation_scheduled",
|
|
1582
|
+
workerStarted: true,
|
|
1583
|
+
workerCompleted: true
|
|
1584
|
+
})
|
|
1585
|
+
});
|
|
1586
|
+
return;
|
|
1587
|
+
}
|
|
1588
|
+
if (result.error || result.rawBytes === void 0 || result.gzBytes === void 0 || result.serializeMs === void 0 || result.writeMs === void 0 || result.durationMs === void 0) {
|
|
1589
|
+
fs2.rm(result.stagePath, { force: true }, () => {
|
|
1590
|
+
});
|
|
1591
|
+
writePendingOnMainThread(key, pending, result.error ?? "invalid worker result", {
|
|
1592
|
+
started: true,
|
|
1593
|
+
completed: true,
|
|
1594
|
+
fallbackReason: result.error ? "worker_error" : "invalid_worker_result"
|
|
1595
|
+
});
|
|
1596
|
+
return;
|
|
1597
|
+
}
|
|
1598
|
+
try {
|
|
1599
|
+
fs2.renameSync(result.stagePath, pending.cachePath);
|
|
1600
|
+
fs2.rmSync(path2.join(pending.cacheDir, LEGACY_GRAPH_CACHE_FILENAME), {
|
|
1601
|
+
force: true
|
|
1602
|
+
});
|
|
1603
|
+
logPersistSuccess(key, pending, {
|
|
1604
|
+
rawBytes: result.rawBytes,
|
|
1605
|
+
gzBytes: result.gzBytes,
|
|
1606
|
+
serializeMs: result.serializeMs,
|
|
1607
|
+
writeMs: result.writeMs,
|
|
1608
|
+
durationMs: result.durationMs,
|
|
1609
|
+
offloaded: true
|
|
1610
|
+
}, { started: true, completed: true });
|
|
1611
|
+
} catch (err) {
|
|
1612
|
+
fs2.rm(result.stagePath, { force: true }, () => {
|
|
1613
|
+
});
|
|
1614
|
+
writePendingOnMainThread(key, pending, err instanceof Error ? err.message : String(err), {
|
|
1615
|
+
started: true,
|
|
1616
|
+
completed: true,
|
|
1617
|
+
fallbackReason: "promotion_failed"
|
|
1618
|
+
});
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
function handleCheckpointWorkerResult(cp, result) {
|
|
1622
|
+
_checkpointWorkerRequests.delete(result.id);
|
|
1623
|
+
if (result.error || result.gzBytes === void 0) {
|
|
1624
|
+
logReviewGraph({
|
|
1625
|
+
cwd: cp.cwd,
|
|
1626
|
+
phase: "checkpoint_write_failed",
|
|
1627
|
+
reason: "worker_error",
|
|
1628
|
+
error: result.error ?? "worker returned no gz metrics"
|
|
1629
|
+
});
|
|
1630
|
+
fs2.rm(result.stagePath, { force: true }, () => {
|
|
1631
|
+
});
|
|
1632
|
+
return;
|
|
1633
|
+
}
|
|
1634
|
+
if (_checkpointGenerations.get(cp.cwd) !== cp.generation) {
|
|
1635
|
+
fs2.rm(result.stagePath, { force: true }, () => {
|
|
1636
|
+
});
|
|
1637
|
+
return;
|
|
1638
|
+
}
|
|
1639
|
+
try {
|
|
1640
|
+
fs2.renameSync(result.stagePath, cp.checkpointPath);
|
|
1641
|
+
logReviewGraph({
|
|
1642
|
+
cwd: cp.cwd,
|
|
1643
|
+
phase: "checkpoint_written",
|
|
1644
|
+
nodes: cp.nodes,
|
|
1645
|
+
edges: cp.edges,
|
|
1646
|
+
processed: cp.processed,
|
|
1647
|
+
target: cp.target,
|
|
1648
|
+
offloaded: true
|
|
1649
|
+
});
|
|
1650
|
+
} catch (err) {
|
|
1651
|
+
logReviewGraph({
|
|
1652
|
+
cwd: cp.cwd,
|
|
1653
|
+
phase: "checkpoint_write_failed",
|
|
1654
|
+
reason: "promote_failed",
|
|
1655
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1656
|
+
});
|
|
1657
|
+
fs2.rm(result.stagePath, { force: true }, () => {
|
|
1658
|
+
});
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
function handleWorkerDeath(reason) {
|
|
1662
|
+
_persistWorkerUnavailableReason = reason;
|
|
1663
|
+
_persistWorker = void 0;
|
|
1664
|
+
_persistWorkerHeapStatistics = null;
|
|
1665
|
+
_workerDisabled = true;
|
|
1666
|
+
const requests = [..._workerRequests.values()];
|
|
1667
|
+
_workerRequests.clear();
|
|
1668
|
+
for (const { key, pending } of requests) {
|
|
1669
|
+
if (_persistGenerations.get(key) !== pending.generation) {
|
|
1670
|
+
logReviewGraph({
|
|
1671
|
+
cwd: key,
|
|
1672
|
+
phase: "persist_skipped",
|
|
1673
|
+
reason: "superseded",
|
|
1674
|
+
observability: persistObservability(pending, {
|
|
1675
|
+
status: "superseded",
|
|
1676
|
+
supersededByGeneration: _persistGenerations.get(key),
|
|
1677
|
+
reason: "worker_death_after_newer_generation",
|
|
1678
|
+
workerStarted: true,
|
|
1679
|
+
workerCompleted: false
|
|
1680
|
+
})
|
|
1681
|
+
});
|
|
1682
|
+
continue;
|
|
1683
|
+
}
|
|
1684
|
+
writePendingOnMainThread(key, pending, reason, {
|
|
1685
|
+
started: true,
|
|
1686
|
+
completed: false,
|
|
1687
|
+
fallbackReason: "worker_death"
|
|
1688
|
+
});
|
|
1689
|
+
}
|
|
1690
|
+
const checkpoints = [..._checkpointWorkerRequests.values()];
|
|
1691
|
+
_checkpointWorkerRequests.clear();
|
|
1692
|
+
for (const cp of checkpoints) {
|
|
1693
|
+
logReviewGraph({
|
|
1694
|
+
cwd: cp.cwd,
|
|
1695
|
+
phase: "checkpoint_write_failed",
|
|
1696
|
+
reason: "worker_death",
|
|
1697
|
+
error: reason
|
|
1698
|
+
});
|
|
1699
|
+
fs2.rm(cp.stagePath, { force: true }, () => {
|
|
1700
|
+
});
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
function resolvePersistWorkerPath() {
|
|
1704
|
+
const candidates = [
|
|
1705
|
+
new URL("./persist-worker.js", import.meta.url),
|
|
1706
|
+
new URL("./workers/review-graph-persist-worker.js", import.meta.url),
|
|
1707
|
+
new URL("../workers/review-graph-persist-worker.js", import.meta.url)
|
|
1708
|
+
];
|
|
1709
|
+
for (const url of candidates) {
|
|
1710
|
+
try {
|
|
1711
|
+
const resolved = fileURLToPath(url);
|
|
1712
|
+
if (fs2.existsSync(resolved))
|
|
1713
|
+
return resolved;
|
|
1714
|
+
} catch {
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
return void 0;
|
|
1718
|
+
}
|
|
1719
|
+
function getPersistWorker() {
|
|
1720
|
+
if (_workerDisabled)
|
|
1721
|
+
return void 0;
|
|
1722
|
+
if (_persistWorker)
|
|
1723
|
+
return _persistWorker;
|
|
1724
|
+
try {
|
|
1725
|
+
const workerPath = resolvePersistWorkerPath();
|
|
1726
|
+
if (workerPath === void 0) {
|
|
1727
|
+
handleWorkerDeath("persist worker script not found in any layout");
|
|
1728
|
+
return void 0;
|
|
1729
|
+
}
|
|
1730
|
+
const worker = new Worker(workerPath);
|
|
1731
|
+
worker.on("message", handleWorkerResult);
|
|
1732
|
+
worker.on("error", (err) => handleWorkerDeath(err.message));
|
|
1733
|
+
worker.on("exit", (code) => {
|
|
1734
|
+
if (_persistWorker !== worker)
|
|
1735
|
+
return;
|
|
1736
|
+
const hasPendingRequests = _workerRequests.size > 0 || _checkpointWorkerRequests.size > 0;
|
|
1737
|
+
if (code !== 0 || hasPendingRequests) {
|
|
1738
|
+
handleWorkerDeath(code !== 0 ? `persist worker exited with code ${code}` : "persist worker exited with pending requests");
|
|
1739
|
+
} else {
|
|
1740
|
+
_persistWorker = void 0;
|
|
1741
|
+
_persistWorkerHeapStatistics = null;
|
|
1742
|
+
}
|
|
1743
|
+
});
|
|
1744
|
+
worker.unref();
|
|
1745
|
+
_persistWorker = worker;
|
|
1746
|
+
return worker;
|
|
1747
|
+
} catch (err) {
|
|
1748
|
+
handleWorkerDeath(err instanceof Error ? err.message : String(err));
|
|
1749
|
+
return void 0;
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
function writePending(key) {
|
|
1753
|
+
const pending = _pendingPersist.get(key);
|
|
1754
|
+
if (!pending)
|
|
1755
|
+
return;
|
|
1756
|
+
_pendingPersist.delete(key);
|
|
1757
|
+
const timer = _persistTimers.get(key);
|
|
1758
|
+
if (timer) {
|
|
1759
|
+
clearTimeout(timer);
|
|
1760
|
+
_persistTimers.delete(key);
|
|
1761
|
+
}
|
|
1762
|
+
const worker = getPersistWorker();
|
|
1763
|
+
if (!worker) {
|
|
1764
|
+
const unavailableReason = _persistWorkerUnavailableReason ?? "persist worker unavailable";
|
|
1765
|
+
writePendingOnMainThread(key, pending, unavailableReason, {
|
|
1766
|
+
started: false,
|
|
1767
|
+
completed: false,
|
|
1768
|
+
fallbackReason: unavailableReason
|
|
1769
|
+
});
|
|
1770
|
+
return;
|
|
1771
|
+
}
|
|
1772
|
+
const id = ++_persistWorkerRequestId;
|
|
1773
|
+
const stagePath = `${pending.cachePath}.stage-${process.pid}-${pending.generation}`;
|
|
1774
|
+
const request = {
|
|
1775
|
+
id,
|
|
1776
|
+
cwd: key,
|
|
1777
|
+
generation: pending.generation,
|
|
1778
|
+
stagePath,
|
|
1779
|
+
data: persistedData(pending),
|
|
1780
|
+
elements: pending.elementCount,
|
|
1781
|
+
testDelayMs: process.env.NODE_ENV === "test" ? Number(process.env.PI_LENS_TEST_PERSIST_WORKER_DELAY_MS) || void 0 : void 0
|
|
1782
|
+
};
|
|
1783
|
+
_workerRequests.set(id, { key, pending });
|
|
1784
|
+
worker.postMessage(request);
|
|
1785
|
+
}
|
|
1786
|
+
var _persistExitHookInstalled = false;
|
|
1787
|
+
function flushPendingReviewGraphPersistsAtExit() {
|
|
1788
|
+
const keys = /* @__PURE__ */ new Set([
|
|
1789
|
+
..._pendingPersist.keys(),
|
|
1790
|
+
...[..._workerRequests.values()].map((request) => request.key)
|
|
1791
|
+
]);
|
|
1792
|
+
for (const key of keys) {
|
|
1793
|
+
flushReviewGraphPersist(key, "exit_hook");
|
|
1794
|
+
}
|
|
1795
|
+
flushReviewGraphLogSync();
|
|
1796
|
+
void _persistWorker?.terminate();
|
|
1797
|
+
}
|
|
1798
|
+
function flushReviewGraphPersistsForExitForTests() {
|
|
1799
|
+
flushPendingReviewGraphPersistsAtExit();
|
|
1800
|
+
}
|
|
1801
|
+
function ensurePersistExitHook() {
|
|
1802
|
+
if (_persistExitHookInstalled)
|
|
1803
|
+
return;
|
|
1804
|
+
_persistExitHookInstalled = true;
|
|
1805
|
+
process.once("exit", flushPendingReviewGraphPersistsAtExit);
|
|
1806
|
+
}
|
|
1807
|
+
var _sweptStageDirs = /* @__PURE__ */ new Set();
|
|
1808
|
+
var REVIEW_GRAPH_ARTIFACT_PREFIX = "review-graph.";
|
|
1809
|
+
function sweepStaleStageFiles(cacheDir) {
|
|
1810
|
+
if (_sweptStageDirs.has(cacheDir))
|
|
1811
|
+
return;
|
|
1812
|
+
_sweptStageDirs.add(cacheDir);
|
|
1813
|
+
fs2.readdir(cacheDir, (err, entries) => {
|
|
1814
|
+
if (err)
|
|
1815
|
+
return;
|
|
1816
|
+
for (const entry of entries) {
|
|
1817
|
+
if (!isStaleStageFile(entry, REVIEW_GRAPH_ARTIFACT_PREFIX))
|
|
1818
|
+
continue;
|
|
1819
|
+
fs2.rm(path2.join(cacheDir, entry), { force: true }, () => {
|
|
1820
|
+
});
|
|
1821
|
+
}
|
|
1822
|
+
});
|
|
1823
|
+
}
|
|
1824
|
+
function _resetReviewGraphStageSweepForTests() {
|
|
1825
|
+
_sweptStageDirs.clear();
|
|
1826
|
+
}
|
|
1827
|
+
function persistGraph(cwd, signature, fileSignatures, fileHashes, graph, options = {}) {
|
|
1828
|
+
const totalElementCount = graph.nodes.size + graph.edges.length;
|
|
1829
|
+
const cap = graphPersistMaxElements();
|
|
1830
|
+
const sourceFileCount = options.sourceFileCount ?? fileSignatures.size;
|
|
1831
|
+
const sourceFilePaths = options.sourceFilePaths ?? fileSignatures.keys();
|
|
1832
|
+
const persistedGraph = totalElementCount > cap ? capGraphForPersist(cwd, graph, cap, {
|
|
1833
|
+
sourceFileCount,
|
|
1834
|
+
sourceFilesTruncated: options.sourceFilesTruncated,
|
|
1835
|
+
sourceFilePaths
|
|
1836
|
+
}) : {
|
|
1837
|
+
...graph,
|
|
1838
|
+
persistCoverage: graphCoverage(graph, cap, sourceFileCount, options.sourceFilesTruncated, sourceFilePaths)
|
|
1839
|
+
};
|
|
1840
|
+
const elementCount = persistedGraph.nodes.size + persistedGraph.edges.length;
|
|
1841
|
+
const sourceWalkPartial = persistedGraph.persistCoverage?.sourceFilesTruncated === true;
|
|
1842
|
+
let persistReason;
|
|
1843
|
+
if (totalElementCount > cap) {
|
|
1844
|
+
const coverage = persistedGraph.persistCoverage;
|
|
1845
|
+
if (!coverage)
|
|
1846
|
+
return;
|
|
1847
|
+
logLatency({
|
|
1848
|
+
type: "phase",
|
|
1849
|
+
phase: "review_graph_persist",
|
|
1850
|
+
filePath: cwd,
|
|
1851
|
+
durationMs: 0,
|
|
1852
|
+
metadata: {
|
|
1853
|
+
partial: true,
|
|
1854
|
+
totalElements: totalElementCount,
|
|
1855
|
+
persistedElements: elementCount,
|
|
1856
|
+
cap
|
|
1857
|
+
}
|
|
1858
|
+
});
|
|
1859
|
+
persistReason = `persisted partial review graph (${elementCount}/${totalElementCount} elements; ${coverage.persistedNodes}/${coverage.totalNodes} nodes, ${coverage.persistedEdges}/${coverage.totalEdges} edges; ${cap} cap)`;
|
|
1860
|
+
} else if (sourceWalkPartial) {
|
|
1861
|
+
persistReason = "persisted partial review graph (source walk entry budget)";
|
|
1862
|
+
}
|
|
1863
|
+
const cacheDir = path2.join(getProjectDataDir(cwd), "cache");
|
|
1864
|
+
const cachePath = path2.join(cacheDir, GRAPH_CACHE_FILENAME);
|
|
1865
|
+
sweepStaleStageFiles(cacheDir);
|
|
1866
|
+
const gitStamp = (options.resolveIdentity ?? resolveGitIdentity)(cwd);
|
|
1867
|
+
const key = normalizeMapKey(cwd);
|
|
1868
|
+
const priorGeneration = _persistGenerations.get(key);
|
|
1869
|
+
const existingPending = _pendingPersist.get(key);
|
|
1870
|
+
const existingTimer = _persistTimers.get(key);
|
|
1871
|
+
const generation = (priorGeneration ?? 0) + 1;
|
|
1872
|
+
const attemptId = ++_persistAttemptId;
|
|
1873
|
+
const coalesced = Boolean(existingPending || existingTimer);
|
|
1874
|
+
_persistGenerations.set(key, generation);
|
|
1875
|
+
const graphMetadata = graphLogMetadata(persistedGraph, {
|
|
1876
|
+
...options,
|
|
1877
|
+
sourceFileCount,
|
|
1878
|
+
sourceFileCountTruncated: persistedGraph.persistCoverage?.sourceFilesTruncated === true
|
|
1879
|
+
});
|
|
1880
|
+
const persistenceMetadata = {
|
|
1881
|
+
generation,
|
|
1882
|
+
attemptId,
|
|
1883
|
+
status: "scheduled",
|
|
1884
|
+
...priorGeneration === void 0 ? {} : {
|
|
1885
|
+
supersededGeneration: priorGeneration,
|
|
1886
|
+
coalesced,
|
|
1887
|
+
reason: coalesced ? "debounced_coalescing" : "in_flight_supersession"
|
|
1888
|
+
}
|
|
1889
|
+
};
|
|
1890
|
+
const pending = {
|
|
1891
|
+
cacheDir,
|
|
1892
|
+
cachePath,
|
|
1893
|
+
// #3605: a restart re-extracts every trapped file.
|
|
1894
|
+
...stampWasmTrappedFiles({ signature, fileSignatures, fileHashes }, true),
|
|
1895
|
+
graph: persistedGraph,
|
|
1896
|
+
gitStamp,
|
|
1897
|
+
elementCount,
|
|
1898
|
+
generation,
|
|
1899
|
+
attemptId,
|
|
1900
|
+
graphMetadata,
|
|
1901
|
+
persistenceMetadata
|
|
1902
|
+
};
|
|
1903
|
+
if (existingPending) {
|
|
1904
|
+
logReviewGraph({
|
|
1905
|
+
cwd: key,
|
|
1906
|
+
phase: "persist_skipped",
|
|
1907
|
+
reason: "superseded",
|
|
1908
|
+
observability: persistObservability(existingPending, {
|
|
1909
|
+
status: "superseded",
|
|
1910
|
+
supersededByGeneration: generation,
|
|
1911
|
+
reason: "newer_generation_scheduled",
|
|
1912
|
+
workerStarted: false,
|
|
1913
|
+
workerCompleted: false
|
|
1914
|
+
})
|
|
1915
|
+
});
|
|
1916
|
+
}
|
|
1917
|
+
_pendingPersist.set(key, pending);
|
|
1918
|
+
if (totalElementCount > cap || sourceWalkPartial) {
|
|
1919
|
+
logReviewGraph({
|
|
1920
|
+
cwd,
|
|
1921
|
+
phase: "persist_partial",
|
|
1922
|
+
reason: totalElementCount > cap ? "element_cap_exceeded" : "source_walk_entry_budget",
|
|
1923
|
+
elements: totalElementCount,
|
|
1924
|
+
persistedElements: elementCount,
|
|
1925
|
+
cap,
|
|
1926
|
+
observability: {
|
|
1927
|
+
graph: graphMetadata,
|
|
1928
|
+
persistence: persistenceMetadata
|
|
1929
|
+
}
|
|
1930
|
+
});
|
|
1931
|
+
}
|
|
1932
|
+
logReviewGraph({
|
|
1933
|
+
cwd,
|
|
1934
|
+
phase: "persist_scheduled",
|
|
1935
|
+
elements: elementCount,
|
|
1936
|
+
cap,
|
|
1937
|
+
observability: {
|
|
1938
|
+
graph: graphMetadata,
|
|
1939
|
+
persistence: persistenceMetadata
|
|
1940
|
+
}
|
|
1941
|
+
});
|
|
1942
|
+
ensurePersistExitHook();
|
|
1943
|
+
const debounce = graphPersistDebounceMs();
|
|
1944
|
+
const existing = _persistTimers.get(key);
|
|
1945
|
+
if (existing)
|
|
1946
|
+
clearTimeout(existing);
|
|
1947
|
+
if (debounce === 0) {
|
|
1948
|
+
writePending(key);
|
|
1949
|
+
return persistReason;
|
|
1950
|
+
}
|
|
1951
|
+
const timer = setTimeout(() => writePending(key), debounce);
|
|
1952
|
+
if (typeof timer.unref === "function")
|
|
1953
|
+
timer.unref();
|
|
1954
|
+
_persistTimers.set(key, timer);
|
|
1955
|
+
return persistReason;
|
|
1956
|
+
}
|
|
1957
|
+
var GRAPH_CHECKPOINT_EVERY_FILES_DEFAULT = 250;
|
|
1958
|
+
var GRAPH_CHECKPOINT_MIN_INTERVAL_MS_DEFAULT = 5e3;
|
|
1959
|
+
function graphCheckpointEveryFiles() {
|
|
1960
|
+
const raw = Number(process.env.PI_LENS_GRAPH_CHECKPOINT_EVERY_FILES);
|
|
1961
|
+
return Number.isFinite(raw) && raw > 0 ? Math.floor(raw) : GRAPH_CHECKPOINT_EVERY_FILES_DEFAULT;
|
|
1962
|
+
}
|
|
1963
|
+
function graphCheckpointMinIntervalMs() {
|
|
1964
|
+
const raw = Number(process.env.PI_LENS_GRAPH_CHECKPOINT_MIN_INTERVAL_MS);
|
|
1965
|
+
return Number.isFinite(raw) && raw >= 0 ? raw : GRAPH_CHECKPOINT_MIN_INTERVAL_MS_DEFAULT;
|
|
1966
|
+
}
|
|
1967
|
+
function reviewGraphCheckpointPath(cwd) {
|
|
1968
|
+
return path2.join(getProjectDataDir(cwd), "cache", GRAPH_CHECKPOINT_FILENAME);
|
|
1969
|
+
}
|
|
1970
|
+
function hashIgnoredIds(ignoredIds) {
|
|
1971
|
+
if (ignoredIds === void 0)
|
|
1972
|
+
return "unavailable";
|
|
1973
|
+
const joined = [...ignoredIds].sort((a, b) => compareOrdinal(a, b)).join("\0");
|
|
1974
|
+
return createHash2("sha256").update(joined).digest("hex");
|
|
1975
|
+
}
|
|
1976
|
+
function buildReviewGraphCheckpointData(cwd, graph, processedHashes, targetFileCount, ignoredIds, resolveIdentity = resolveGitIdentity) {
|
|
1977
|
+
return {
|
|
1978
|
+
version: REVIEW_GRAPH_VERSION,
|
|
1979
|
+
builtAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1980
|
+
inProgress: true,
|
|
1981
|
+
targetFileCount,
|
|
1982
|
+
processedFiles: Array.from(stampWasmTrapped(processedHashes, true)),
|
|
1983
|
+
ignoredIdsHash: hashIgnoredIds(ignoredIds),
|
|
1984
|
+
nodes: Array.from(graph.nodes.entries()),
|
|
1985
|
+
edges: graph.edges,
|
|
1986
|
+
gitStamp: resolveIdentity(cwd)
|
|
1987
|
+
};
|
|
1988
|
+
}
|
|
1989
|
+
function writeReviewGraphCheckpoint(cwd, graph, processedHashes, targetFileCount, ignoredIds, resolveIdentity = resolveGitIdentity) {
|
|
1990
|
+
const generation = (_checkpointGenerations.get(cwd) ?? 0) + 1;
|
|
1991
|
+
_checkpointGenerations.set(cwd, generation);
|
|
1992
|
+
let data;
|
|
1993
|
+
try {
|
|
1994
|
+
data = buildReviewGraphCheckpointData(cwd, graph, processedHashes, targetFileCount, ignoredIds, resolveIdentity);
|
|
1995
|
+
} catch {
|
|
1996
|
+
return;
|
|
1997
|
+
}
|
|
1998
|
+
const worker = _workerDisabled ? void 0 : getPersistWorker();
|
|
1999
|
+
if (!worker) {
|
|
2000
|
+
writeReviewGraphCheckpointSync(cwd, data, {
|
|
2001
|
+
nodes: graph.nodes.size,
|
|
2002
|
+
edges: graph.edges.length,
|
|
2003
|
+
processed: processedHashes.size,
|
|
2004
|
+
target: targetFileCount
|
|
2005
|
+
});
|
|
2006
|
+
return;
|
|
2007
|
+
}
|
|
2008
|
+
const checkpointPath = reviewGraphCheckpointPath(cwd);
|
|
2009
|
+
const cacheDir = path2.dirname(checkpointPath);
|
|
2010
|
+
try {
|
|
2011
|
+
fs2.mkdirSync(cacheDir, { recursive: true });
|
|
2012
|
+
} catch (err) {
|
|
2013
|
+
logReviewGraph({
|
|
2014
|
+
cwd,
|
|
2015
|
+
phase: "checkpoint_write_failed",
|
|
2016
|
+
reason: "mkdir_failed",
|
|
2017
|
+
error: err instanceof Error ? err.message : String(err)
|
|
2018
|
+
});
|
|
2019
|
+
return;
|
|
2020
|
+
}
|
|
2021
|
+
sweepStaleStageFiles(cacheDir);
|
|
2022
|
+
ensurePersistExitHook();
|
|
2023
|
+
const id = ++_persistWorkerRequestId;
|
|
2024
|
+
const stagePath = `${checkpointPath}.stage-${process.pid}-${generation}`;
|
|
2025
|
+
_checkpointWorkerRequests.set(id, {
|
|
2026
|
+
cwd,
|
|
2027
|
+
generation,
|
|
2028
|
+
checkpointPath,
|
|
2029
|
+
stagePath,
|
|
2030
|
+
nodes: graph.nodes.size,
|
|
2031
|
+
edges: graph.edges.length,
|
|
2032
|
+
processed: processedHashes.size,
|
|
2033
|
+
target: targetFileCount
|
|
2034
|
+
});
|
|
2035
|
+
const request = {
|
|
2036
|
+
id,
|
|
2037
|
+
cwd,
|
|
2038
|
+
generation,
|
|
2039
|
+
stagePath,
|
|
2040
|
+
data,
|
|
2041
|
+
elements: graph.nodes.size + graph.edges.length,
|
|
2042
|
+
testDelayMs: process.env.NODE_ENV === "test" ? Number(process.env.PI_LENS_TEST_PERSIST_WORKER_DELAY_MS) || void 0 : void 0
|
|
2043
|
+
};
|
|
2044
|
+
worker.postMessage(request);
|
|
2045
|
+
_checkpointOffloadCountForTests++;
|
|
2046
|
+
}
|
|
2047
|
+
function writeReviewGraphCheckpointSync(cwd, data, counts) {
|
|
2048
|
+
try {
|
|
2049
|
+
const gzip = gzipSync(JSON.stringify(data));
|
|
2050
|
+
fs2.mkdirSync(path2.dirname(reviewGraphCheckpointPath(cwd)), {
|
|
2051
|
+
recursive: true
|
|
2052
|
+
});
|
|
2053
|
+
writeFileAtomic(reviewGraphCheckpointPath(cwd), gzip, { bestEffort: true });
|
|
2054
|
+
logReviewGraph({
|
|
2055
|
+
cwd,
|
|
2056
|
+
phase: "checkpoint_written",
|
|
2057
|
+
nodes: counts.nodes,
|
|
2058
|
+
edges: counts.edges,
|
|
2059
|
+
processed: counts.processed,
|
|
2060
|
+
target: counts.target
|
|
2061
|
+
});
|
|
2062
|
+
} catch (err) {
|
|
2063
|
+
logReviewGraph({
|
|
2064
|
+
cwd,
|
|
2065
|
+
phase: "checkpoint_write_failed",
|
|
2066
|
+
reason: "sync_write_failed",
|
|
2067
|
+
error: err instanceof Error ? err.message : String(err)
|
|
2068
|
+
});
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
function deleteReviewGraphCheckpoint(cwd) {
|
|
2072
|
+
_checkpointGenerations.set(cwd, (_checkpointGenerations.get(cwd) ?? 0) + 1);
|
|
2073
|
+
fs2.rm(reviewGraphCheckpointPath(cwd), { force: true }, () => {
|
|
2074
|
+
});
|
|
2075
|
+
}
|
|
2076
|
+
function loadReviewGraphCheckpoint(cwd, resolveIdentity = resolveGitIdentity) {
|
|
2077
|
+
const checkpointPath = reviewGraphCheckpointPath(cwd);
|
|
2078
|
+
let data;
|
|
2079
|
+
try {
|
|
2080
|
+
if (!fs2.existsSync(checkpointPath))
|
|
2081
|
+
return null;
|
|
2082
|
+
data = JSON.parse(gunzipSync(fs2.readFileSync(checkpointPath)).toString("utf-8"));
|
|
2083
|
+
} catch {
|
|
2084
|
+
logReviewGraph({ cwd, phase: "checkpoint_discarded", reason: "corrupt" });
|
|
2085
|
+
deleteReviewGraphCheckpoint(cwd);
|
|
2086
|
+
return null;
|
|
2087
|
+
}
|
|
2088
|
+
if (data.version !== REVIEW_GRAPH_VERSION || data.inProgress !== true) {
|
|
2089
|
+
logReviewGraph({
|
|
2090
|
+
cwd,
|
|
2091
|
+
phase: "checkpoint_discarded",
|
|
2092
|
+
reason: data.version !== REVIEW_GRAPH_VERSION ? "version_mismatch" : "not_in_progress"
|
|
2093
|
+
});
|
|
2094
|
+
deleteReviewGraphCheckpoint(cwd);
|
|
2095
|
+
return null;
|
|
2096
|
+
}
|
|
2097
|
+
if (data.gitStamp) {
|
|
2098
|
+
const current = resolveIdentity(cwd);
|
|
2099
|
+
if (current && current.worktreeRoot !== data.gitStamp.worktreeRoot) {
|
|
2100
|
+
logReviewGraph({
|
|
2101
|
+
cwd,
|
|
2102
|
+
phase: "checkpoint_discarded",
|
|
2103
|
+
reason: "worktree_mismatch"
|
|
2104
|
+
});
|
|
2105
|
+
deleteReviewGraphCheckpoint(cwd);
|
|
2106
|
+
return null;
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
2109
|
+
const totalNodes = data.nodes.length;
|
|
2110
|
+
const totalEdges = data.edges.length;
|
|
2111
|
+
const graph = {
|
|
2112
|
+
version: data.version,
|
|
2113
|
+
builtAt: data.builtAt,
|
|
2114
|
+
nodes: new Map(data.nodes),
|
|
2115
|
+
edges: data.edges,
|
|
2116
|
+
edgesByFrom: /* @__PURE__ */ new Map(),
|
|
2117
|
+
edgesByTo: /* @__PURE__ */ new Map(),
|
|
2118
|
+
fileNodes: /* @__PURE__ */ new Map(),
|
|
2119
|
+
symbolNodesByFile: /* @__PURE__ */ new Map(),
|
|
2120
|
+
changedSymbolsByFile: /* @__PURE__ */ new Map(),
|
|
2121
|
+
persistCoverage: {
|
|
2122
|
+
partial: true,
|
|
2123
|
+
inProgress: true,
|
|
2124
|
+
cap: 0,
|
|
2125
|
+
totalNodes,
|
|
2126
|
+
totalEdges,
|
|
2127
|
+
persistedNodes: totalNodes,
|
|
2128
|
+
persistedEdges: totalEdges,
|
|
2129
|
+
totalFiles: data.targetFileCount,
|
|
2130
|
+
persistedFiles: 0
|
|
2131
|
+
}
|
|
2132
|
+
};
|
|
2133
|
+
rebuildIndexes(graph);
|
|
2134
|
+
if (graph.persistCoverage) {
|
|
2135
|
+
graph.persistCoverage.persistedFiles = countRetainedSourceFiles(graph, data.processedFiles.map(([filePath]) => filePath));
|
|
2136
|
+
}
|
|
2137
|
+
return {
|
|
2138
|
+
graph,
|
|
2139
|
+
processedHashes: new Map(data.processedFiles),
|
|
2140
|
+
ignoredIdsHash: data.ignoredIdsHash,
|
|
2141
|
+
targetFileCount: data.targetFileCount
|
|
2142
|
+
};
|
|
2143
|
+
}
|
|
2144
|
+
function pruneOrphanNonFileNodes(graph) {
|
|
2145
|
+
const referenced = /* @__PURE__ */ new Set();
|
|
2146
|
+
for (const edge of graph.edges) {
|
|
2147
|
+
referenced.add(edge.from);
|
|
2148
|
+
referenced.add(edge.to);
|
|
2149
|
+
}
|
|
2150
|
+
for (const [id, node] of graph.nodes) {
|
|
2151
|
+
if (!node.filePath && !referenced.has(id))
|
|
2152
|
+
graph.nodes.delete(id);
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
async function tryResumeFromCheckpoint(cwd, filesToBuild, ignoredIds, resolveIdentity = resolveGitIdentity) {
|
|
2156
|
+
const loaded = loadReviewGraphCheckpoint(cwd, resolveIdentity);
|
|
2157
|
+
if (!loaded)
|
|
2158
|
+
return null;
|
|
2159
|
+
if (loaded.ignoredIdsHash !== hashIgnoredIds(ignoredIds)) {
|
|
2160
|
+
logReviewGraph({
|
|
2161
|
+
cwd,
|
|
2162
|
+
phase: "checkpoint_discarded",
|
|
2163
|
+
reason: "ignored_ids_mismatch",
|
|
2164
|
+
processed: loaded.processedHashes.size,
|
|
2165
|
+
target: filesToBuild.length
|
|
2166
|
+
});
|
|
2167
|
+
deleteReviewGraphCheckpoint(cwd);
|
|
2168
|
+
return null;
|
|
2169
|
+
}
|
|
2170
|
+
const targetSet = new Set(filesToBuild);
|
|
2171
|
+
for (const file of loaded.processedHashes.keys()) {
|
|
2172
|
+
if (!targetSet.has(file)) {
|
|
2173
|
+
logReviewGraph({
|
|
2174
|
+
cwd,
|
|
2175
|
+
phase: "checkpoint_discarded",
|
|
2176
|
+
reason: "removed_file",
|
|
2177
|
+
processed: loaded.processedHashes.size,
|
|
2178
|
+
target: filesToBuild.length
|
|
2179
|
+
});
|
|
2180
|
+
deleteReviewGraphCheckpoint(cwd);
|
|
2181
|
+
return null;
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
2184
|
+
const reusableHashes = /* @__PURE__ */ new Map();
|
|
2185
|
+
const stale = [];
|
|
2186
|
+
let sinceYield = 0;
|
|
2187
|
+
for (const [file, priorHash] of loaded.processedHashes) {
|
|
2188
|
+
const currentHash = contentHashEntry(file);
|
|
2189
|
+
if (currentHash === priorHash)
|
|
2190
|
+
reusableHashes.set(file, currentHash);
|
|
2191
|
+
else
|
|
2192
|
+
stale.push(file);
|
|
2193
|
+
if (++sinceYield >= STAT_YIELD_EVERY) {
|
|
2194
|
+
sinceYield = 0;
|
|
2195
|
+
await yieldToLoop();
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2198
|
+
if (reusableHashes.size === 0) {
|
|
2199
|
+
logReviewGraph({
|
|
2200
|
+
cwd,
|
|
2201
|
+
phase: "checkpoint_discarded",
|
|
2202
|
+
reason: "all_stale",
|
|
2203
|
+
stale: stale.length,
|
|
2204
|
+
target: filesToBuild.length
|
|
2205
|
+
});
|
|
2206
|
+
deleteReviewGraphCheckpoint(cwd);
|
|
2207
|
+
return null;
|
|
2208
|
+
}
|
|
2209
|
+
const graph = loaded.graph;
|
|
2210
|
+
const removedEdges = /* @__PURE__ */ new Set();
|
|
2211
|
+
for (const file of stale)
|
|
2212
|
+
removeFileOwnedGraphData(graph, file, removedEdges);
|
|
2213
|
+
if (removedEdges.size > 0) {
|
|
2214
|
+
unindexEdges(graph, removedEdges);
|
|
2215
|
+
graph.edges = graph.edges.filter((edge) => !removedEdges.has(edge));
|
|
2216
|
+
}
|
|
2217
|
+
pruneOrphanNonFileNodes(graph);
|
|
2218
|
+
graph.changedSymbolsByFile = /* @__PURE__ */ new Map();
|
|
2219
|
+
const remaining = filesToBuild.filter((file) => !reusableHashes.has(file));
|
|
2220
|
+
logReviewGraph({
|
|
2221
|
+
cwd,
|
|
2222
|
+
phase: "checkpoint_resumed",
|
|
2223
|
+
reused: reusableHashes.size,
|
|
2224
|
+
stale: stale.length,
|
|
2225
|
+
remaining: remaining.length,
|
|
2226
|
+
target: filesToBuild.length
|
|
2227
|
+
});
|
|
2228
|
+
return { graph, fileHashes: reusableHashes, remaining };
|
|
2229
|
+
}
|
|
2230
|
+
function _readReviewGraphCheckpointForTests(cwd) {
|
|
2231
|
+
const loaded = loadReviewGraphCheckpoint(cwd);
|
|
2232
|
+
if (!loaded)
|
|
2233
|
+
return null;
|
|
2234
|
+
return {
|
|
2235
|
+
inProgress: loaded.graph.persistCoverage?.inProgress === true,
|
|
2236
|
+
processedFiles: [...loaded.processedHashes.keys()],
|
|
2237
|
+
nodeCount: loaded.graph.nodes.size,
|
|
2238
|
+
edgeCount: loaded.graph.edges.length,
|
|
2239
|
+
persistCoverage: loaded.graph.persistCoverage
|
|
2240
|
+
};
|
|
2241
|
+
}
|
|
2242
|
+
function flushReviewGraphPersistsForTests() {
|
|
2243
|
+
for (const key of _pendingPersist.keys()) {
|
|
2244
|
+
const pending = _pendingPersist.get(key);
|
|
2245
|
+
if (!pending)
|
|
2246
|
+
continue;
|
|
2247
|
+
_pendingPersist.delete(key);
|
|
2248
|
+
const timer = _persistTimers.get(key);
|
|
2249
|
+
if (timer)
|
|
2250
|
+
clearTimeout(timer);
|
|
2251
|
+
_persistTimers.delete(key);
|
|
2252
|
+
writePendingOnMainThread(key, pending);
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
async function waitForReviewGraphPersistsForTests() {
|
|
2256
|
+
for (let attempts = 0; attempts < 200 && (_workerRequests.size > 0 || _checkpointWorkerRequests.size > 0); attempts++) {
|
|
2257
|
+
await new Promise((resolve2) => setTimeout(resolve2, 10));
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
async function terminateReviewGraphPersistWorkerForTests() {
|
|
2261
|
+
const worker = _persistWorker;
|
|
2262
|
+
if (worker)
|
|
2263
|
+
await worker.terminate();
|
|
2264
|
+
}
|
|
2265
|
+
function resetReviewGraphPersistWorkerForTests() {
|
|
2266
|
+
_workerDisabled = false;
|
|
2267
|
+
_persistWorker = void 0;
|
|
2268
|
+
_persistWorkerHeapStatistics = null;
|
|
2269
|
+
_persistWorkerUnavailableReason = void 0;
|
|
2270
|
+
_lastWorkerFallbackReasonForTests = void 0;
|
|
2271
|
+
_checkpointWorkerRequests.clear();
|
|
2272
|
+
_checkpointGenerations.clear();
|
|
2273
|
+
_checkpointOffloadCountForTests = 0;
|
|
2274
|
+
}
|
|
2275
|
+
function getCheckpointOffloadCountForTests() {
|
|
2276
|
+
return _checkpointOffloadCountForTests;
|
|
2277
|
+
}
|
|
2278
|
+
function getReviewGraphWorkerFallbackReasonForTests() {
|
|
2279
|
+
return _lastWorkerFallbackReasonForTests;
|
|
2280
|
+
}
|
|
2281
|
+
function reviewGraphCachePath(cwd) {
|
|
2282
|
+
return path2.join(getProjectDataDir(cwd), "cache", GRAPH_CACHE_FILENAME);
|
|
2283
|
+
}
|
|
2284
|
+
function flushReviewGraphPersist(cwd, source = "cli") {
|
|
2285
|
+
const key = normalizeMapKey(cwd);
|
|
2286
|
+
let pending = _pendingPersist.get(key);
|
|
2287
|
+
const removedWorkerRequests = [];
|
|
2288
|
+
let selectedWorkerRequest;
|
|
2289
|
+
for (const [id, request] of _workerRequests) {
|
|
2290
|
+
if (request.key !== key)
|
|
2291
|
+
continue;
|
|
2292
|
+
_workerRequests.delete(id);
|
|
2293
|
+
removedWorkerRequests.push(request.pending);
|
|
2294
|
+
if (!pending || request.pending.generation > pending.generation) {
|
|
2295
|
+
pending = request.pending;
|
|
2296
|
+
selectedWorkerRequest = request.pending;
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
for (const removed of removedWorkerRequests) {
|
|
2300
|
+
if (!pending || removed.generation === pending.generation)
|
|
2301
|
+
continue;
|
|
2302
|
+
logReviewGraph({
|
|
2303
|
+
cwd: key,
|
|
2304
|
+
phase: "persist_skipped",
|
|
2305
|
+
reason: "superseded",
|
|
2306
|
+
observability: persistObservability(removed, {
|
|
2307
|
+
status: "superseded",
|
|
2308
|
+
supersededByGeneration: pending.generation,
|
|
2309
|
+
reason: "forced_flush_newest_generation",
|
|
2310
|
+
workerStarted: true,
|
|
2311
|
+
workerCompleted: false
|
|
2312
|
+
})
|
|
2313
|
+
});
|
|
2314
|
+
}
|
|
2315
|
+
const currentGeneration = _persistGenerations.get(key);
|
|
2316
|
+
if (pending && pending.generation !== currentGeneration) {
|
|
2317
|
+
logReviewGraph({
|
|
2318
|
+
cwd: key,
|
|
2319
|
+
phase: "persist_skipped",
|
|
2320
|
+
reason: "superseded",
|
|
2321
|
+
observability: persistObservability(pending, {
|
|
2322
|
+
status: "superseded",
|
|
2323
|
+
supersededByGeneration: currentGeneration,
|
|
2324
|
+
reason: "forced_flush_superseded",
|
|
2325
|
+
workerStarted: true,
|
|
2326
|
+
workerCompleted: false
|
|
2327
|
+
})
|
|
2328
|
+
});
|
|
2329
|
+
return {
|
|
2330
|
+
ok: false,
|
|
2331
|
+
reason: `queued snapshot generation ${pending.generation} was superseded by generation ${currentGeneration}`
|
|
2332
|
+
};
|
|
2333
|
+
}
|
|
2334
|
+
if (!pending) {
|
|
2335
|
+
return {
|
|
2336
|
+
ok: false,
|
|
2337
|
+
reason: "no graph snapshot was queued for persistence"
|
|
2338
|
+
};
|
|
2339
|
+
}
|
|
2340
|
+
_persistGenerations.set(key, Math.max(_persistGenerations.get(key) ?? 0, pending.generation) + 1);
|
|
2341
|
+
_pendingPersist.delete(key);
|
|
2342
|
+
const timer = _persistTimers.get(key);
|
|
2343
|
+
if (timer) {
|
|
2344
|
+
clearTimeout(timer);
|
|
2345
|
+
_persistTimers.delete(key);
|
|
2346
|
+
}
|
|
2347
|
+
const startedAt = performance.now();
|
|
2348
|
+
try {
|
|
2349
|
+
const serializeStarted = performance.now();
|
|
2350
|
+
const json = JSON.stringify(persistedData(pending));
|
|
2351
|
+
const serializeMs = performance.now() - serializeStarted;
|
|
2352
|
+
const rawBytes = Buffer.byteLength(json);
|
|
2353
|
+
const writeStarted = performance.now();
|
|
2354
|
+
const gzip = gzipSync(json);
|
|
2355
|
+
fs2.mkdirSync(pending.cacheDir, { recursive: true });
|
|
2356
|
+
writeFileAtomic(pending.cachePath, gzip, { bestEffort: false });
|
|
2357
|
+
fs2.rmSync(path2.join(pending.cacheDir, LEGACY_GRAPH_CACHE_FILENAME), {
|
|
2358
|
+
force: true
|
|
2359
|
+
});
|
|
2360
|
+
const writeMs = performance.now() - writeStarted;
|
|
2361
|
+
logLatency({
|
|
2362
|
+
type: "phase",
|
|
2363
|
+
phase: "review_graph_persist",
|
|
2364
|
+
filePath: pending.cachePath,
|
|
2365
|
+
durationMs: performance.now() - startedAt,
|
|
2366
|
+
metadata: {
|
|
2367
|
+
elements: pending.elementCount,
|
|
2368
|
+
rawBytes,
|
|
2369
|
+
gzBytes: gzip.byteLength,
|
|
2370
|
+
serializeMs,
|
|
2371
|
+
writeMs,
|
|
2372
|
+
offloaded: false
|
|
2373
|
+
}
|
|
2374
|
+
});
|
|
2375
|
+
logReviewGraph({
|
|
2376
|
+
cwd,
|
|
2377
|
+
phase: "persist_succeeded",
|
|
2378
|
+
durationMs: performance.now() - startedAt,
|
|
2379
|
+
elements: pending.elementCount,
|
|
2380
|
+
rawBytes,
|
|
2381
|
+
gzBytes: gzip.byteLength,
|
|
2382
|
+
serializeMs,
|
|
2383
|
+
writeMs,
|
|
2384
|
+
offloaded: false,
|
|
2385
|
+
observability: persistObservability(pending, {
|
|
2386
|
+
status: "succeeded",
|
|
2387
|
+
reason: source === "exit_hook" ? "exit_flush" : "forced_flush",
|
|
2388
|
+
workerStarted: selectedWorkerRequest !== void 0,
|
|
2389
|
+
workerCompleted: false
|
|
2390
|
+
})
|
|
2391
|
+
});
|
|
2392
|
+
return {
|
|
2393
|
+
ok: true,
|
|
2394
|
+
path: pending.cachePath,
|
|
2395
|
+
bytes: gzip.byteLength,
|
|
2396
|
+
elements: pending.elementCount,
|
|
2397
|
+
coverage: pending.graph.persistCoverage
|
|
2398
|
+
};
|
|
2399
|
+
} catch (err) {
|
|
2400
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
2401
|
+
recordPersistFailure(cwd, source === "exit_hook" ? "exit_flush_failed" : "forced_flush_failed", reason, pending, selectedWorkerRequest ? {
|
|
2402
|
+
started: true,
|
|
2403
|
+
completed: false,
|
|
2404
|
+
fallbackReason: "forced_flush_write_failed"
|
|
2405
|
+
} : void 0);
|
|
2406
|
+
return { ok: false, reason };
|
|
2407
|
+
}
|
|
2408
|
+
}
|
|
2409
|
+
function localImportToFile(cwd, filePath, source, ignoredIds) {
|
|
2410
|
+
if (!source.startsWith(".")) {
|
|
2411
|
+
const aliased = resolveAliasedImport(cwd, source, path2.dirname(filePath));
|
|
2412
|
+
const referenced = aliased.length ? [] : resolveProjectReferenceImport(cwd, source, path2.dirname(filePath));
|
|
2413
|
+
const resolved = aliased.length ? aliased : referenced.length ? referenced : resolveWorkspacePackageImport(cwd, source);
|
|
2414
|
+
for (const normalized of resolved) {
|
|
2415
|
+
if (ignoredIds?.has(normalized))
|
|
2416
|
+
continue;
|
|
2417
|
+
return normalized;
|
|
2418
|
+
}
|
|
2419
|
+
return void 0;
|
|
2420
|
+
}
|
|
2421
|
+
const root = path2.resolve(cwd);
|
|
2422
|
+
for (const candidate of jsTsCandidatePaths(filePath, source)) {
|
|
2423
|
+
if (!fs2.existsSync(candidate))
|
|
2424
|
+
continue;
|
|
2425
|
+
const normalized = normalizeMapKey(candidate);
|
|
2426
|
+
if (!isUnderDir(normalized, root))
|
|
2427
|
+
continue;
|
|
2428
|
+
if (ignoredIds?.has(normalized))
|
|
2429
|
+
continue;
|
|
2430
|
+
return normalized;
|
|
2431
|
+
}
|
|
2432
|
+
return void 0;
|
|
2433
|
+
}
|
|
2434
|
+
function upsertChangedSymbols(graph, facts, filePath) {
|
|
2435
|
+
if (detectFileRole(filePath) === "test")
|
|
2436
|
+
return;
|
|
2437
|
+
const normalized = normalizeMapKey(filePath);
|
|
2438
|
+
const changed = facts.getBoundedSessionFact(`${CHANGED_SYMBOLS_PREFIX}${normalized}`);
|
|
2439
|
+
if (changed && changed.length > 0) {
|
|
2440
|
+
graph.changedSymbolsByFile.set(normalized, [...changed]);
|
|
2441
|
+
} else {
|
|
2442
|
+
graph.changedSymbolsByFile.delete(normalized);
|
|
2443
|
+
}
|
|
2444
|
+
}
|
|
2445
|
+
async function ensureReviewGraphFacts(filePath, cwd, facts, contentOverride) {
|
|
2446
|
+
const ctx = makeCtx(filePath, cwd, facts);
|
|
2447
|
+
if (contentOverride === void 0) {
|
|
2448
|
+
await fileContentProvider.run(ctx, facts);
|
|
2449
|
+
} else {
|
|
2450
|
+
facts.setFileFact(filePath, "file.content", contentOverride);
|
|
2451
|
+
}
|
|
2452
|
+
try {
|
|
2453
|
+
const [{ importFactProvider }, { functionFactProvider }] = await Promise.all([
|
|
2454
|
+
import("./chunk-CGGAIP7J.js"),
|
|
2455
|
+
import("./chunk-D6QS3U6M.js")
|
|
2456
|
+
]);
|
|
2457
|
+
await importFactProvider.run(ctx, facts);
|
|
2458
|
+
await functionFactProvider.run(ctx, facts);
|
|
2459
|
+
} catch (err) {
|
|
2460
|
+
logReviewGraph({
|
|
2461
|
+
cwd,
|
|
2462
|
+
phase: "build_skipped",
|
|
2463
|
+
reason: "structural_facts_disabled",
|
|
2464
|
+
error: err?.message ?? String(err)
|
|
2465
|
+
});
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
function addJsTsFile(graph, cwd, filePath, facts, ignoredIds) {
|
|
2469
|
+
const normalized = normalizeMapKey(filePath);
|
|
2470
|
+
const hintPath = toProjectRelativePath(normalized, cwd);
|
|
2471
|
+
const content = facts.getFileFact(normalized, "file.content") ?? "";
|
|
2472
|
+
const fileNodeId = `file:${normalized}`;
|
|
2473
|
+
const warmCallCoverage = facts.getFileFact(normalized, "file.functionFactsCoverage") ?? "unavailable";
|
|
2474
|
+
const importCoverage = facts.getFileFact(normalized, "file.importFactsCoverage") ?? "unavailable";
|
|
2475
|
+
addNode(graph, {
|
|
2476
|
+
id: fileNodeId,
|
|
2477
|
+
kind: "file",
|
|
2478
|
+
language: "jsts",
|
|
2479
|
+
filePath: normalized,
|
|
2480
|
+
metadata: {
|
|
2481
|
+
lineCount: content.split("\n").length,
|
|
2482
|
+
extractionCoverage: {
|
|
2483
|
+
definitions: warmCallCoverage,
|
|
2484
|
+
references: warmCallCoverage,
|
|
2485
|
+
imports: importCoverage,
|
|
2486
|
+
calls: warmCallCoverage
|
|
2487
|
+
},
|
|
2488
|
+
...featureHintMetadata(hintPath)
|
|
2489
|
+
}
|
|
2490
|
+
});
|
|
2491
|
+
const imports = facts.getFileFact(normalized, "file.imports") ?? [];
|
|
2492
|
+
const functions = facts.getFileFact(normalized, "file.functionSummaries") ?? [];
|
|
2493
|
+
for (const entry of imports) {
|
|
2494
|
+
const localFile = localImportToFile(cwd, normalized, entry.source, ignoredIds);
|
|
2495
|
+
if (localFile) {
|
|
2496
|
+
const targetId = `file:${localFile}`;
|
|
2497
|
+
if (!graph.nodes.has(targetId)) {
|
|
2498
|
+
addNode(graph, {
|
|
2499
|
+
id: targetId,
|
|
2500
|
+
kind: "file",
|
|
2501
|
+
language: detectFileKind(localFile) ?? "jsts",
|
|
2502
|
+
filePath: localFile
|
|
2503
|
+
});
|
|
2504
|
+
}
|
|
2505
|
+
addEdge(graph, { from: fileNodeId, to: targetId, kind: "imports" });
|
|
2506
|
+
} else {
|
|
2507
|
+
const targetId = `${entry.source.startsWith(".") ? "module" : "external"}:${entry.source}`;
|
|
2508
|
+
if (!graph.nodes.has(targetId)) {
|
|
2509
|
+
addNode(graph, {
|
|
2510
|
+
id: targetId,
|
|
2511
|
+
kind: entry.source.startsWith(".") ? "module" : "external",
|
|
2512
|
+
language: "jsts",
|
|
2513
|
+
metadata: { source: entry.source }
|
|
2514
|
+
});
|
|
2515
|
+
}
|
|
2516
|
+
addEdge(graph, { from: fileNodeId, to: targetId, kind: "imports" });
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
const importedNameToFile = /* @__PURE__ */ new Map();
|
|
2520
|
+
for (const entry of imports) {
|
|
2521
|
+
const localFile = localImportToFile(cwd, normalized, entry.source, ignoredIds);
|
|
2522
|
+
if (!localFile)
|
|
2523
|
+
continue;
|
|
2524
|
+
for (const name of entry.names)
|
|
2525
|
+
importedNameToFile.set(name, localFile);
|
|
2526
|
+
if (entry.defaultName)
|
|
2527
|
+
importedNameToFile.set(entry.defaultName, localFile);
|
|
2528
|
+
}
|
|
2529
|
+
const methodsByQualifiedName = /* @__PURE__ */ new Map();
|
|
2530
|
+
for (const fn of functions) {
|
|
2531
|
+
const symbolId = buildSymbolId(normalized, fn.name, "function", fn.line);
|
|
2532
|
+
const qualifiedName = buildQualifiedName(fn.owner, fn.name);
|
|
2533
|
+
if (qualifiedName) {
|
|
2534
|
+
const existing = methodsByQualifiedName.get(qualifiedName) ?? [];
|
|
2535
|
+
existing.push(symbolId);
|
|
2536
|
+
methodsByQualifiedName.set(qualifiedName, existing);
|
|
2537
|
+
}
|
|
2538
|
+
addNode(graph, {
|
|
2539
|
+
id: symbolId,
|
|
2540
|
+
kind: "symbol",
|
|
2541
|
+
language: "jsts",
|
|
2542
|
+
filePath: normalized,
|
|
2543
|
+
symbolName: fn.name,
|
|
2544
|
+
symbolKind: "function",
|
|
2545
|
+
...qualifiedName ? { qualifiedName } : {},
|
|
2546
|
+
exported: new RegExp(String.raw`export\s+(?:async\s+)?(?:function|const|let|var)\s+${escapeRegExp(fn.name)}\b`).test(content),
|
|
2547
|
+
metadata: {
|
|
2548
|
+
line: fn.line,
|
|
2549
|
+
endLine: fn.endLine,
|
|
2550
|
+
column: fn.column,
|
|
2551
|
+
cyclomaticComplexity: fn.cyclomaticComplexity,
|
|
2552
|
+
maxNestingDepth: fn.maxNestingDepth,
|
|
2553
|
+
isBoundaryWrapper: fn.isBoundaryWrapper,
|
|
2554
|
+
isPassThroughWrapper: fn.isPassThroughWrapper,
|
|
2555
|
+
...featureHintMetadata(`${fn.name} ${hintPath}`)
|
|
2556
|
+
}
|
|
2557
|
+
});
|
|
2558
|
+
addEdge(graph, { from: fileNodeId, to: symbolId, kind: "contains" });
|
|
2559
|
+
addEdge(graph, { from: fileNodeId, to: symbolId, kind: "defines" });
|
|
2560
|
+
}
|
|
2561
|
+
for (const fn of functions) {
|
|
2562
|
+
const symbolId = buildSymbolId(normalized, fn.name, "function", fn.line);
|
|
2563
|
+
const memberCallTexts = /* @__PURE__ */ new Set();
|
|
2564
|
+
for (const site of fn.memberCallSites ?? []) {
|
|
2565
|
+
const callText = `${site.receiver}.${site.method}`;
|
|
2566
|
+
memberCallTexts.add(callText);
|
|
2567
|
+
const receiverClass = fn.receiverTypes?.[site.receiver];
|
|
2568
|
+
const candidates = receiverClass ? methodsByQualifiedName.get(`${receiverClass}.${site.method}`) ?? [] : [];
|
|
2569
|
+
if (candidates.length === 1) {
|
|
2570
|
+
addEdge(graph, {
|
|
2571
|
+
from: symbolId,
|
|
2572
|
+
to: candidates[0],
|
|
2573
|
+
kind: "calls",
|
|
2574
|
+
metadata: {
|
|
2575
|
+
unresolvedName: callText,
|
|
2576
|
+
receiver: site.receiver,
|
|
2577
|
+
receiverType: receiverClass
|
|
2578
|
+
},
|
|
2579
|
+
resolution: "receiver-type"
|
|
2580
|
+
});
|
|
2581
|
+
continue;
|
|
2582
|
+
}
|
|
2583
|
+
if (candidates.length > 1) {
|
|
2584
|
+
const qualifiedPlaceholderId = `symbol-qualified-name:${receiverClass}.${site.method}`;
|
|
2585
|
+
if (!graph.nodes.has(qualifiedPlaceholderId)) {
|
|
2586
|
+
addNode(graph, {
|
|
2587
|
+
id: qualifiedPlaceholderId,
|
|
2588
|
+
kind: "symbol",
|
|
2589
|
+
language: "jsts",
|
|
2590
|
+
symbolName: site.method,
|
|
2591
|
+
qualifiedName: `${receiverClass}.${site.method}`,
|
|
2592
|
+
metadata: {
|
|
2593
|
+
unresolvedName: callText,
|
|
2594
|
+
ambiguousCandidates: candidates.length
|
|
2595
|
+
}
|
|
2596
|
+
});
|
|
2597
|
+
}
|
|
2598
|
+
addEdge(graph, {
|
|
2599
|
+
from: symbolId,
|
|
2600
|
+
to: qualifiedPlaceholderId,
|
|
2601
|
+
kind: "calls",
|
|
2602
|
+
metadata: {
|
|
2603
|
+
unresolvedName: callText,
|
|
2604
|
+
receiver: site.receiver,
|
|
2605
|
+
receiverType: receiverClass
|
|
2606
|
+
},
|
|
2607
|
+
resolution: "name-only"
|
|
2608
|
+
});
|
|
2609
|
+
continue;
|
|
2610
|
+
}
|
|
2611
|
+
const externalId = `external:${callText}`;
|
|
2612
|
+
if (!graph.nodes.has(externalId)) {
|
|
2613
|
+
addNode(graph, {
|
|
2614
|
+
id: externalId,
|
|
2615
|
+
kind: "external",
|
|
2616
|
+
language: "jsts",
|
|
2617
|
+
metadata: { unresolvedName: callText }
|
|
2618
|
+
});
|
|
2619
|
+
}
|
|
2620
|
+
addEdge(graph, {
|
|
2621
|
+
from: symbolId,
|
|
2622
|
+
to: externalId,
|
|
2623
|
+
kind: "calls",
|
|
2624
|
+
metadata: { unresolvedName: callText }
|
|
2625
|
+
});
|
|
2626
|
+
}
|
|
2627
|
+
for (const callee of fn.outgoingCalls) {
|
|
2628
|
+
if (memberCallTexts.has(callee))
|
|
2629
|
+
continue;
|
|
2630
|
+
const targetId = callee.includes(".") ? `external:${callee}` : `symbol-name:${callee}`;
|
|
2631
|
+
if (!graph.nodes.has(targetId)) {
|
|
2632
|
+
addNode(graph, {
|
|
2633
|
+
id: targetId,
|
|
2634
|
+
kind: callee.includes(".") ? "external" : "symbol",
|
|
2635
|
+
language: "jsts",
|
|
2636
|
+
symbolName: callee.includes(".") ? void 0 : callee,
|
|
2637
|
+
metadata: { unresolvedName: callee }
|
|
2638
|
+
});
|
|
2639
|
+
}
|
|
2640
|
+
const importHintFile = !callee.includes(".") ? importedNameToFile.get(callee) : void 0;
|
|
2641
|
+
addEdge(graph, {
|
|
2642
|
+
from: symbolId,
|
|
2643
|
+
to: targetId,
|
|
2644
|
+
kind: "calls",
|
|
2645
|
+
metadata: {
|
|
2646
|
+
unresolvedName: callee,
|
|
2647
|
+
...importHintFile ? { importHintFile } : {}
|
|
2648
|
+
},
|
|
2649
|
+
// A definite external call (`callee.includes(".")`) is never
|
|
2650
|
+
// ambiguous — no in-project candidate to collide with, so no
|
|
2651
|
+
// resolution marker. An in-project bare-name callee starts
|
|
2652
|
+
// "name-only" and resolveDeferredSymbolEdges below may upgrade it
|
|
2653
|
+
// to "import" (when importHintFile narrows it) or "exact" once
|
|
2654
|
+
// every file has been added.
|
|
2655
|
+
...callee.includes(".") ? {} : { resolution: "name-only" }
|
|
2656
|
+
});
|
|
2657
|
+
}
|
|
2658
|
+
}
|
|
2659
|
+
}
|
|
2660
|
+
function mapKindToTreeSitterLanguage(kind, filePath) {
|
|
2661
|
+
return symbolExtractionGrammar(kind, filePath);
|
|
2662
|
+
}
|
|
2663
|
+
async function getExtractor(languageId) {
|
|
2664
|
+
if (extractorCache.has(languageId))
|
|
2665
|
+
return extractorCache.get(languageId);
|
|
2666
|
+
const client = getSharedTreeSitterClient();
|
|
2667
|
+
if (!client)
|
|
2668
|
+
return null;
|
|
2669
|
+
const extractor = new TreeSitterSymbolExtractor(languageId, client);
|
|
2670
|
+
const ok = await extractor.init();
|
|
2671
|
+
if (!ok) {
|
|
2672
|
+
extractorCache.set(languageId, null);
|
|
2673
|
+
return null;
|
|
2674
|
+
}
|
|
2675
|
+
extractorCache.set(languageId, extractor);
|
|
2676
|
+
return extractor;
|
|
2677
|
+
}
|
|
2678
|
+
async function extractTreeSitterSymbols(filePath, languageId, contentOverride) {
|
|
2679
|
+
const empty = {
|
|
2680
|
+
symbols: [],
|
|
2681
|
+
refs: [],
|
|
2682
|
+
imports: [],
|
|
2683
|
+
coverage: {
|
|
2684
|
+
definitions: "unavailable",
|
|
2685
|
+
references: "unavailable",
|
|
2686
|
+
imports: "unavailable"
|
|
2687
|
+
}
|
|
2688
|
+
};
|
|
2689
|
+
if (contentOverride === null)
|
|
2690
|
+
return empty;
|
|
2691
|
+
const treeSitterClient = getSharedTreeSitterClient();
|
|
2692
|
+
if (!treeSitterClient)
|
|
2693
|
+
return empty;
|
|
2694
|
+
const initialized = await treeSitterClient.init();
|
|
2695
|
+
if (!initialized)
|
|
2696
|
+
return empty;
|
|
2697
|
+
const extractor = await getExtractor(languageId);
|
|
2698
|
+
if (!extractor)
|
|
2699
|
+
return empty;
|
|
2700
|
+
const content = contentOverride ?? fs2.readFileSync(filePath, "utf-8");
|
|
2701
|
+
const extracted = await treeSitterClient.withParsedTree(filePath, languageId, content, (tree) => extractor.extract(tree, filePath, content), "review-graph");
|
|
2702
|
+
return extracted.parsed ? extracted.value : { ...empty, wasmTrap: extracted.wasmTrap };
|
|
2703
|
+
}
|
|
2704
|
+
async function captureReviewGraphStructuralIr(filePath, cwd, content, borrowed) {
|
|
2705
|
+
const kind = detectFileKind(filePath);
|
|
2706
|
+
if (!kind || !MAIN_KINDS.has(kind) || detectFileRole(filePath) === "test") {
|
|
2707
|
+
return { complete: true };
|
|
2708
|
+
}
|
|
2709
|
+
if (kind === "jsts") {
|
|
2710
|
+
const borrowable = borrowed.hasFileFact(filePath, "file.imports") && borrowed.hasFileFact(filePath, "file.reexports") && borrowed.hasFileFact(filePath, "file.functionSummaries") && borrowed.getFileFact(filePath, "file.content") === content;
|
|
2711
|
+
let facts = borrowed;
|
|
2712
|
+
if (!borrowable) {
|
|
2713
|
+
const run = new FactStore("review-graph-run");
|
|
2714
|
+
await ensureReviewGraphFacts(filePath, cwd, run, content);
|
|
2715
|
+
facts = run;
|
|
2716
|
+
}
|
|
2717
|
+
const parsed = await withTreeSitterRoot(filePath, content, () => true, "review-graph-ir");
|
|
2718
|
+
if (!parsed.parsed)
|
|
2719
|
+
return { complete: false };
|
|
2720
|
+
const functionCoverage = facts.getFileFact(filePath, "file.functionFactsCoverage") ?? "unavailable";
|
|
2721
|
+
const importCoverage = facts.getFileFact(filePath, "file.importFactsCoverage") ?? "unavailable";
|
|
2722
|
+
const coverage = {
|
|
2723
|
+
definitions: functionCoverage,
|
|
2724
|
+
references: functionCoverage,
|
|
2725
|
+
imports: importCoverage,
|
|
2726
|
+
calls: functionCoverage
|
|
2727
|
+
};
|
|
2728
|
+
if (Object.values(coverage).some((status) => status !== "complete")) {
|
|
2729
|
+
return { complete: false };
|
|
2730
|
+
}
|
|
2731
|
+
return {
|
|
2732
|
+
complete: true,
|
|
2733
|
+
structural: {
|
|
2734
|
+
kind: "jsts",
|
|
2735
|
+
imports: facts.getFileFact(filePath, "file.imports") ?? [],
|
|
2736
|
+
reexports: facts.getFileFact(filePath, "file.reexports") ?? [],
|
|
2737
|
+
functionSummaries: facts.getFileFact(filePath, "file.functionSummaries") ?? [],
|
|
2738
|
+
coverage
|
|
2739
|
+
}
|
|
2740
|
+
};
|
|
2741
|
+
}
|
|
2742
|
+
const languageId = mapKindToTreeSitterLanguage(kind, filePath);
|
|
2743
|
+
if (!languageId)
|
|
2744
|
+
return { complete: false };
|
|
2745
|
+
const client = getSharedTreeSitterClient();
|
|
2746
|
+
if (!client || !await client.init())
|
|
2747
|
+
return { complete: false };
|
|
2748
|
+
const extractor = await getExtractor(languageId);
|
|
2749
|
+
if (!extractor)
|
|
2750
|
+
return { complete: false };
|
|
2751
|
+
const result = await client.withParsedTree(filePath, languageId, content, (tree) => extractor.extract(tree, filePath, content), "review-graph");
|
|
2752
|
+
if (!result.parsed)
|
|
2753
|
+
return { complete: false };
|
|
2754
|
+
return {
|
|
2755
|
+
complete: true,
|
|
2756
|
+
structural: {
|
|
2757
|
+
kind: "tree-sitter",
|
|
2758
|
+
languageId,
|
|
2759
|
+
extracted: result.value
|
|
2760
|
+
}
|
|
2761
|
+
};
|
|
2762
|
+
}
|
|
2763
|
+
var SYMBOL_KIND_SPECIFICITY = {
|
|
2764
|
+
method: 2,
|
|
2765
|
+
property: 2
|
|
2766
|
+
};
|
|
2767
|
+
function dedupeSamePositionSymbols(symbols) {
|
|
2768
|
+
const bestByKey = /* @__PURE__ */ new Map();
|
|
2769
|
+
for (const symbol of symbols) {
|
|
2770
|
+
const key = `${symbol.name}0000${symbol.line}0000${symbol.column}`;
|
|
2771
|
+
const existing = bestByKey.get(key);
|
|
2772
|
+
if (!existing) {
|
|
2773
|
+
bestByKey.set(key, symbol);
|
|
2774
|
+
continue;
|
|
2775
|
+
}
|
|
2776
|
+
const existingScore = SYMBOL_KIND_SPECIFICITY[existing.kind] ?? 0;
|
|
2777
|
+
const candidateScore = SYMBOL_KIND_SPECIFICITY[symbol.kind] ?? 0;
|
|
2778
|
+
if (candidateScore > existingScore)
|
|
2779
|
+
bestByKey.set(key, symbol);
|
|
2780
|
+
}
|
|
2781
|
+
return [...bestByKey.values()];
|
|
2782
|
+
}
|
|
2783
|
+
function addTreeSitterFile(graph, cwd, filePath, languageId, extracted, ignoredIds) {
|
|
2784
|
+
const normalized = normalizeMapKey(filePath);
|
|
2785
|
+
const hintPath = toProjectRelativePath(normalized, cwd);
|
|
2786
|
+
const fileNodeId = `file:${normalized}`;
|
|
2787
|
+
addNode(graph, {
|
|
2788
|
+
id: fileNodeId,
|
|
2789
|
+
kind: "file",
|
|
2790
|
+
language: languageId,
|
|
2791
|
+
filePath: normalized,
|
|
2792
|
+
metadata: {
|
|
2793
|
+
...featureHintMetadata(hintPath),
|
|
2794
|
+
extractionCoverage: extracted.coverage
|
|
2795
|
+
}
|
|
2796
|
+
});
|
|
2797
|
+
const dedupedSymbols = dedupeSamePositionSymbols(extracted.symbols);
|
|
2798
|
+
const containers = dedupedSymbols.map((s) => ({
|
|
2799
|
+
name: s.name,
|
|
2800
|
+
startLine: s.line,
|
|
2801
|
+
endLine: s.endLine ?? s.line
|
|
2802
|
+
}));
|
|
2803
|
+
for (const symbol of dedupedSymbols) {
|
|
2804
|
+
const symbolId = buildSymbolId(normalized, symbol.name, symbol.kind, symbol.line);
|
|
2805
|
+
const owner = findOwnerName(containers, symbol.line, symbol.endLine ?? symbol.line);
|
|
2806
|
+
const qualifiedName = buildQualifiedName(owner, symbol.name);
|
|
2807
|
+
addNode(graph, {
|
|
2808
|
+
id: symbolId,
|
|
2809
|
+
kind: "symbol",
|
|
2810
|
+
language: languageId,
|
|
2811
|
+
filePath: normalized,
|
|
2812
|
+
symbolName: symbol.name,
|
|
2813
|
+
symbolKind: symbol.kind,
|
|
2814
|
+
...qualifiedName ? { qualifiedName } : {},
|
|
2815
|
+
exported: symbol.isExported,
|
|
2816
|
+
metadata: {
|
|
2817
|
+
line: symbol.line,
|
|
2818
|
+
endLine: symbol.endLine,
|
|
2819
|
+
column: symbol.column,
|
|
2820
|
+
signature: symbol.signature,
|
|
2821
|
+
...featureHintMetadata(`${symbol.name} ${hintPath}`)
|
|
2822
|
+
}
|
|
2823
|
+
});
|
|
2824
|
+
addEdge(graph, { from: fileNodeId, to: symbolId, kind: "contains" });
|
|
2825
|
+
addEdge(graph, { from: fileNodeId, to: symbolId, kind: "defines" });
|
|
2826
|
+
}
|
|
2827
|
+
for (const ref of extracted.refs) {
|
|
2828
|
+
const refName = ref.symbolName ?? ref.symbolId;
|
|
2829
|
+
const targetId = `symbol-name:${refName}`;
|
|
2830
|
+
if (!graph.nodes.has(targetId)) {
|
|
2831
|
+
addNode(graph, {
|
|
2832
|
+
id: targetId,
|
|
2833
|
+
kind: "symbol",
|
|
2834
|
+
language: languageId,
|
|
2835
|
+
symbolName: refName,
|
|
2836
|
+
metadata: { unresolvedName: refName }
|
|
2837
|
+
});
|
|
2838
|
+
}
|
|
2839
|
+
addEdge(graph, {
|
|
2840
|
+
from: fileNodeId,
|
|
2841
|
+
to: targetId,
|
|
2842
|
+
kind: "references",
|
|
2843
|
+
metadata: {
|
|
2844
|
+
line: ref.line,
|
|
2845
|
+
column: ref.column,
|
|
2846
|
+
referenceKind: ref.referenceKind ?? "unknown"
|
|
2847
|
+
},
|
|
2848
|
+
// Always starts bare-name-only (the extractor has no scope/type info);
|
|
2849
|
+
// resolveDeferredSymbolEdges may upgrade this to "exact" below.
|
|
2850
|
+
resolution: "name-only"
|
|
2851
|
+
});
|
|
2852
|
+
}
|
|
2853
|
+
for (const imp of extracted.imports) {
|
|
2854
|
+
const resolved = resolveImportToFiles(cwd, filePath, languageId, imp.source).filter((target) => !ignoredIds?.has(target));
|
|
2855
|
+
if (resolved.length > 0) {
|
|
2856
|
+
for (const target of resolved) {
|
|
2857
|
+
const toNode = ensureFileNode(graph, target, cwd, mapKindToTreeSitterLanguage(detectFileKind(target), target) ?? languageId);
|
|
2858
|
+
addEdge(graph, {
|
|
2859
|
+
from: fileNodeId,
|
|
2860
|
+
to: toNode,
|
|
2861
|
+
kind: "imports",
|
|
2862
|
+
metadata: { line: imp.line, source: imp.source }
|
|
2863
|
+
});
|
|
2864
|
+
}
|
|
2865
|
+
continue;
|
|
2866
|
+
}
|
|
2867
|
+
const isRelative = imp.source.startsWith(".");
|
|
2868
|
+
const targetId = `${isRelative ? "module" : "external"}:${imp.source}`;
|
|
2869
|
+
if (!graph.nodes.has(targetId)) {
|
|
2870
|
+
addNode(graph, {
|
|
2871
|
+
id: targetId,
|
|
2872
|
+
kind: isRelative ? "module" : "external",
|
|
2873
|
+
language: languageId,
|
|
2874
|
+
metadata: { source: imp.source }
|
|
2875
|
+
});
|
|
2876
|
+
}
|
|
2877
|
+
addEdge(graph, {
|
|
2878
|
+
from: fileNodeId,
|
|
2879
|
+
to: targetId,
|
|
2880
|
+
kind: "imports",
|
|
2881
|
+
metadata: { line: imp.line }
|
|
2882
|
+
});
|
|
2883
|
+
}
|
|
2884
|
+
}
|
|
2885
|
+
function addLspFallbackSymbols(graph, filePath, languageId, symbols) {
|
|
2886
|
+
const normalized = normalizeMapKey(filePath);
|
|
2887
|
+
const fileNodeId = `file:${normalized}`;
|
|
2888
|
+
let added = 0;
|
|
2889
|
+
const flatOwnerIds = /* @__PURE__ */ new Map();
|
|
2890
|
+
for (const symbol of symbols) {
|
|
2891
|
+
const range = symbol.range ?? symbol.location?.range;
|
|
2892
|
+
if (!range)
|
|
2893
|
+
continue;
|
|
2894
|
+
const kind = lspSymbolKindName(symbol.kind);
|
|
2895
|
+
const id = buildSymbolId(normalized, symbol.name, kind, range.start.line + 1);
|
|
2896
|
+
flatOwnerIds.set(symbol.name, id);
|
|
2897
|
+
if (symbol.containerName) {
|
|
2898
|
+
flatOwnerIds.set(`${symbol.containerName}.${symbol.name}`, id);
|
|
2899
|
+
}
|
|
2900
|
+
}
|
|
2901
|
+
const visit = (items, parentId, ancestry) => {
|
|
2902
|
+
for (const symbol of items) {
|
|
2903
|
+
const range = symbol.range ?? symbol.location?.range;
|
|
2904
|
+
if (!range)
|
|
2905
|
+
continue;
|
|
2906
|
+
const line = range.start.line + 1;
|
|
2907
|
+
const kind = lspSymbolKindName(symbol.kind);
|
|
2908
|
+
const symbolId = buildSymbolId(normalized, symbol.name, kind, line);
|
|
2909
|
+
const owners = ancestry.length > 0 ? ancestry : containerNameChain(symbol, symbols);
|
|
2910
|
+
const qualifiedName = owners.length > 0 ? [...owners, symbol.name].join(".") : void 0;
|
|
2911
|
+
addNode(graph, {
|
|
2912
|
+
id: symbolId,
|
|
2913
|
+
kind: "symbol",
|
|
2914
|
+
language: languageId,
|
|
2915
|
+
filePath: normalized,
|
|
2916
|
+
symbolName: symbol.name,
|
|
2917
|
+
symbolKind: kind,
|
|
2918
|
+
...qualifiedName ? { qualifiedName } : {},
|
|
2919
|
+
provenance: "lsp",
|
|
2920
|
+
metadata: {
|
|
2921
|
+
line,
|
|
2922
|
+
column: range.start.character,
|
|
2923
|
+
endLine: range.end.line + 1,
|
|
2924
|
+
...featureHintMetadata(`${symbol.name} ${normalized}`)
|
|
2925
|
+
}
|
|
2926
|
+
});
|
|
2927
|
+
const resolvedParentId = ancestry.length === 0 && symbol.containerName ? flatOwnerIds.get(symbol.containerName) ?? parentId : parentId;
|
|
2928
|
+
addEdge(graph, {
|
|
2929
|
+
from: resolvedParentId,
|
|
2930
|
+
to: symbolId,
|
|
2931
|
+
kind: "contains"
|
|
2932
|
+
});
|
|
2933
|
+
addEdge(graph, { from: fileNodeId, to: symbolId, kind: "defines" });
|
|
2934
|
+
added++;
|
|
2935
|
+
if (symbol.children) {
|
|
2936
|
+
visit(symbol.children, symbolId, [...owners, symbol.name]);
|
|
2937
|
+
}
|
|
2938
|
+
}
|
|
2939
|
+
};
|
|
2940
|
+
visit(symbols, fileNodeId, []);
|
|
2941
|
+
return added;
|
|
2942
|
+
}
|
|
2943
|
+
function ensureFileNode(graph, filePath, cwd, languageId) {
|
|
2944
|
+
const normalized = normalizeMapKey(filePath);
|
|
2945
|
+
const hintPath = toProjectRelativePath(normalized, cwd);
|
|
2946
|
+
const existing = graph.fileNodes.get(normalized);
|
|
2947
|
+
if (existing)
|
|
2948
|
+
return existing;
|
|
2949
|
+
const fileNodeId = `file:${normalized}`;
|
|
2950
|
+
addNode(graph, {
|
|
2951
|
+
id: fileNodeId,
|
|
2952
|
+
kind: "file",
|
|
2953
|
+
language: languageId,
|
|
2954
|
+
filePath: normalized,
|
|
2955
|
+
metadata: featureHintMetadata(hintPath)
|
|
2956
|
+
});
|
|
2957
|
+
return fileNodeId;
|
|
2958
|
+
}
|
|
2959
|
+
function resolveCxxInclude(cwd, filePath, source) {
|
|
2960
|
+
const candidates = [
|
|
2961
|
+
path2.resolve(path2.dirname(filePath), source),
|
|
2962
|
+
path2.resolve(cwd, source),
|
|
2963
|
+
path2.resolve(cwd, "include", source),
|
|
2964
|
+
path2.resolve(cwd, "src", source)
|
|
2965
|
+
];
|
|
2966
|
+
const root = path2.resolve(cwd);
|
|
2967
|
+
for (const candidate of candidates) {
|
|
2968
|
+
if (!candidate.startsWith(root + path2.sep) && candidate !== root)
|
|
2969
|
+
continue;
|
|
2970
|
+
if (fs2.existsSync(candidate) && detectFileKind(candidate) === "cxx") {
|
|
2971
|
+
return normalizeMapKey(candidate);
|
|
2972
|
+
}
|
|
2973
|
+
}
|
|
2974
|
+
return void 0;
|
|
2975
|
+
}
|
|
2976
|
+
function parseLocalCxxInclude(line) {
|
|
2977
|
+
let i = 0;
|
|
2978
|
+
while (i < line.length && (line[i] === " " || line[i] === " "))
|
|
2979
|
+
i += 1;
|
|
2980
|
+
if (line[i] !== "#")
|
|
2981
|
+
return void 0;
|
|
2982
|
+
i += 1;
|
|
2983
|
+
while (i < line.length && (line[i] === " " || line[i] === " "))
|
|
2984
|
+
i += 1;
|
|
2985
|
+
if (!line.startsWith("include", i))
|
|
2986
|
+
return void 0;
|
|
2987
|
+
i += "include".length;
|
|
2988
|
+
if (i >= line.length || line[i] !== " " && line[i] !== " ") {
|
|
2989
|
+
return void 0;
|
|
2990
|
+
}
|
|
2991
|
+
while (i < line.length && (line[i] === " " || line[i] === " "))
|
|
2992
|
+
i += 1;
|
|
2993
|
+
if (line[i] !== '"')
|
|
2994
|
+
return void 0;
|
|
2995
|
+
i += 1;
|
|
2996
|
+
const start = i;
|
|
2997
|
+
while (i < line.length && line[i] !== '"')
|
|
2998
|
+
i += 1;
|
|
2999
|
+
if (i >= line.length || i === start)
|
|
3000
|
+
return void 0;
|
|
3001
|
+
return line.slice(start, i);
|
|
3002
|
+
}
|
|
3003
|
+
function addCxxIncludeEdges(graph, cwd, filePath, ignoredIds, contentOverride) {
|
|
3004
|
+
let content = contentOverride;
|
|
3005
|
+
if (content === void 0) {
|
|
3006
|
+
try {
|
|
3007
|
+
content = fs2.readFileSync(filePath, "utf-8");
|
|
3008
|
+
} catch {
|
|
3009
|
+
return;
|
|
3010
|
+
}
|
|
3011
|
+
}
|
|
3012
|
+
if (content === null)
|
|
3013
|
+
return;
|
|
3014
|
+
const fromNode = ensureFileNode(graph, filePath, cwd, "cpp");
|
|
3015
|
+
for (const line of content.split(/\r?\n/)) {
|
|
3016
|
+
const source = parseLocalCxxInclude(line);
|
|
3017
|
+
if (!source)
|
|
3018
|
+
continue;
|
|
3019
|
+
const target = resolveCxxInclude(cwd, filePath, source);
|
|
3020
|
+
if (!target || ignoredIds?.has(target))
|
|
3021
|
+
continue;
|
|
3022
|
+
const languageId = mapKindToTreeSitterLanguage("cxx", target) ?? "cpp";
|
|
3023
|
+
const toNode = ensureFileNode(graph, target, cwd, languageId);
|
|
3024
|
+
addEdge(graph, {
|
|
3025
|
+
from: fromNode,
|
|
3026
|
+
to: toNode,
|
|
3027
|
+
kind: "imports",
|
|
3028
|
+
metadata: { source }
|
|
3029
|
+
});
|
|
3030
|
+
}
|
|
3031
|
+
}
|
|
3032
|
+
function removeFileOwnedGraphData(graph, filePath, removedEdges) {
|
|
3033
|
+
const normalized = normalizeMapKey(filePath);
|
|
3034
|
+
const fileNodeId = graph.fileNodes.get(normalized) ?? `file:${normalized}`;
|
|
3035
|
+
const removedSymbolIds = new Set(graph.symbolNodesByFile.get(normalized));
|
|
3036
|
+
const removedIds = new Set(removedSymbolIds);
|
|
3037
|
+
if (graph.nodes.has(fileNodeId))
|
|
3038
|
+
removedIds.add(fileNodeId);
|
|
3039
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
3040
|
+
for (const id of removedIds) {
|
|
3041
|
+
for (const edge of graph.edgesByFrom.get(id) ?? []) {
|
|
3042
|
+
_rebuildCounters.removeOwnedEdgeVisits++;
|
|
3043
|
+
candidates.add(edge);
|
|
3044
|
+
}
|
|
3045
|
+
for (const edge of graph.edgesByTo.get(id) ?? []) {
|
|
3046
|
+
_rebuildCounters.removeOwnedEdgeVisits++;
|
|
3047
|
+
candidates.add(edge);
|
|
3048
|
+
}
|
|
3049
|
+
}
|
|
3050
|
+
const preservedIncomingSymbolEdges = [];
|
|
3051
|
+
for (const edge of candidates) {
|
|
3052
|
+
if (removedEdges.has(edge))
|
|
3053
|
+
continue;
|
|
3054
|
+
const fromRemoved = removedIds.has(edge.from);
|
|
3055
|
+
if (!fromRemoved && edge.to === fileNodeId)
|
|
3056
|
+
continue;
|
|
3057
|
+
if (!fromRemoved && removedSymbolIds.has(edge.to)) {
|
|
3058
|
+
preservedIncomingSymbolEdges.push({ ...edge });
|
|
3059
|
+
}
|
|
3060
|
+
removedEdges.add(edge);
|
|
3061
|
+
}
|
|
3062
|
+
for (const id of removedIds) {
|
|
3063
|
+
const node = graph.nodes.get(id);
|
|
3064
|
+
graph.nodes.delete(id);
|
|
3065
|
+
if (!node?.filePath)
|
|
3066
|
+
continue;
|
|
3067
|
+
if (node.kind === "file") {
|
|
3068
|
+
if (graph.fileNodes.get(node.filePath) === id) {
|
|
3069
|
+
graph.fileNodes.delete(node.filePath);
|
|
3070
|
+
}
|
|
3071
|
+
} else if (node.kind === "symbol") {
|
|
3072
|
+
const ids = graph.symbolNodesByFile.get(node.filePath);
|
|
3073
|
+
if (!ids)
|
|
3074
|
+
continue;
|
|
3075
|
+
const at = ids.indexOf(id);
|
|
3076
|
+
if (at >= 0)
|
|
3077
|
+
ids.splice(at, 1);
|
|
3078
|
+
if (ids.length === 0)
|
|
3079
|
+
graph.symbolNodesByFile.delete(node.filePath);
|
|
3080
|
+
}
|
|
3081
|
+
}
|
|
3082
|
+
return preservedIncomingSymbolEdges;
|
|
3083
|
+
}
|
|
3084
|
+
async function addFileToGraph(graph, cwd, file, ignoredIds, contentOverride) {
|
|
3085
|
+
const kind = detectFileKind(file);
|
|
3086
|
+
if (!kind || !MAIN_KINDS.has(kind))
|
|
3087
|
+
return;
|
|
3088
|
+
if (detectFileRole(file) === "test")
|
|
3089
|
+
return;
|
|
3090
|
+
const contentHash = typeof contentOverride === "string" ? reviewGraphIrContentHash(contentOverride) : void 0;
|
|
3091
|
+
const sharedIr = contentHash ? getFreshReviewGraphFileIr(cwd, file, contentHash)?.structural : void 0;
|
|
3092
|
+
if (kind === "jsts") {
|
|
3093
|
+
const run = new FactStore("review-graph-run");
|
|
3094
|
+
if (sharedIr?.kind === "jsts") {
|
|
3095
|
+
run.setFileFact(file, "file.content", contentOverride ?? "");
|
|
3096
|
+
run.setFileFact(file, "file.imports", sharedIr.imports);
|
|
3097
|
+
run.setFileFact(file, "file.functionSummaries", sharedIr.functionSummaries);
|
|
3098
|
+
run.setFileFact(file, "file.functionFactsCoverage", sharedIr.coverage.calls);
|
|
3099
|
+
run.setFileFact(file, "file.importFactsCoverage", sharedIr.coverage.imports);
|
|
3100
|
+
} else {
|
|
3101
|
+
await ensureReviewGraphFacts(file, cwd, run, contentOverride);
|
|
3102
|
+
}
|
|
3103
|
+
addJsTsFile(graph, cwd, file, run, ignoredIds);
|
|
3104
|
+
return;
|
|
3105
|
+
}
|
|
3106
|
+
const languageId = mapKindToTreeSitterLanguage(kind, file);
|
|
3107
|
+
if (!languageId)
|
|
3108
|
+
return;
|
|
3109
|
+
const irExtracted = sharedIr?.kind === "tree-sitter" && sharedIr.languageId === languageId ? sharedIr.extracted : void 0;
|
|
3110
|
+
const extracted = irExtracted ?? await extractTreeSitterSymbols(file, languageId, contentOverride);
|
|
3111
|
+
if (extracted.wasmTrap)
|
|
3112
|
+
_wasmTrappedFiles.set(file, extracted.wasmTrap);
|
|
3113
|
+
else
|
|
3114
|
+
_wasmTrappedFiles.delete(file);
|
|
3115
|
+
addTreeSitterFile(graph, cwd, file, languageId, extracted, ignoredIds);
|
|
3116
|
+
if (extracted.symbols.length === 0) {
|
|
3117
|
+
const lspSymbols = await getOpenDocumentSymbols(file);
|
|
3118
|
+
const added = lspSymbols ? addLspFallbackSymbols(graph, file, languageId, lspSymbols) : 0;
|
|
3119
|
+
logReviewGraph({
|
|
3120
|
+
phase: "lsp_symbol_fallback",
|
|
3121
|
+
cwd,
|
|
3122
|
+
reason: lspSymbols ? added > 0 ? "added" : "empty-response" : "unavailable-or-failed",
|
|
3123
|
+
nodes: added
|
|
3124
|
+
});
|
|
3125
|
+
}
|
|
3126
|
+
if (kind === "cxx") {
|
|
3127
|
+
addCxxIncludeEdges(graph, cwd, file, ignoredIds, contentOverride);
|
|
3128
|
+
}
|
|
3129
|
+
}
|
|
3130
|
+
var _rebuildCounters = {
|
|
3131
|
+
restoreComparisons: 0,
|
|
3132
|
+
importTargetEdgeScans: 0,
|
|
3133
|
+
removeOwnedEdgeVisits: 0,
|
|
3134
|
+
removeOwnedEdgePositions: 0
|
|
3135
|
+
};
|
|
3136
|
+
function _getReviewGraphRebuildCountersForTests() {
|
|
3137
|
+
return { ..._rebuildCounters };
|
|
3138
|
+
}
|
|
3139
|
+
function _resetReviewGraphRebuildCountersForTests() {
|
|
3140
|
+
_rebuildCounters.restoreComparisons = 0;
|
|
3141
|
+
_rebuildCounters.importTargetEdgeScans = 0;
|
|
3142
|
+
_rebuildCounters.removeOwnedEdgeVisits = 0;
|
|
3143
|
+
_rebuildCounters.removeOwnedEdgePositions = 0;
|
|
3144
|
+
}
|
|
3145
|
+
function edgeIdentityKey(edge) {
|
|
3146
|
+
_rebuildCounters.restoreComparisons++;
|
|
3147
|
+
return JSON.stringify([edge.from, edge.kind, edge.metadata ?? {}]);
|
|
3148
|
+
}
|
|
3149
|
+
function restoreValidIncomingEdges(graph, edges) {
|
|
3150
|
+
const seenByTarget = /* @__PURE__ */ new Map();
|
|
3151
|
+
for (const edge of edges) {
|
|
3152
|
+
if (!graph.nodes.has(edge.from) || !graph.nodes.has(edge.to))
|
|
3153
|
+
continue;
|
|
3154
|
+
let seen = seenByTarget.get(edge.to);
|
|
3155
|
+
if (!seen) {
|
|
3156
|
+
seen = /* @__PURE__ */ new Set();
|
|
3157
|
+
for (const candidate of graph.edgesByTo.get(edge.to) ?? []) {
|
|
3158
|
+
seen.add(edgeIdentityKey(candidate));
|
|
3159
|
+
}
|
|
3160
|
+
seenByTarget.set(edge.to, seen);
|
|
3161
|
+
}
|
|
3162
|
+
const key = edgeIdentityKey(edge);
|
|
3163
|
+
if (seen.has(key))
|
|
3164
|
+
continue;
|
|
3165
|
+
seen.add(key);
|
|
3166
|
+
addEdge(graph, edge);
|
|
3167
|
+
}
|
|
3168
|
+
}
|
|
3169
|
+
function dedupeResolvedEdges(graph, replacements) {
|
|
3170
|
+
const resolvedEdges = new Set(replacements.map(([, after]) => after));
|
|
3171
|
+
const seenByTarget = /* @__PURE__ */ new Map();
|
|
3172
|
+
const removed = /* @__PURE__ */ new Set();
|
|
3173
|
+
for (const [, edge] of replacements) {
|
|
3174
|
+
if (removed.has(edge))
|
|
3175
|
+
continue;
|
|
3176
|
+
let seen = seenByTarget.get(edge.to);
|
|
3177
|
+
if (!seen) {
|
|
3178
|
+
seen = /* @__PURE__ */ new Set();
|
|
3179
|
+
for (const candidate of graph.edgesByTo.get(edge.to) ?? []) {
|
|
3180
|
+
if (!resolvedEdges.has(candidate)) {
|
|
3181
|
+
seen.add(edgeIdentityKey(candidate));
|
|
3182
|
+
}
|
|
3183
|
+
}
|
|
3184
|
+
seenByTarget.set(edge.to, seen);
|
|
3185
|
+
}
|
|
3186
|
+
const key = edgeIdentityKey(edge);
|
|
3187
|
+
if (seen.has(key)) {
|
|
3188
|
+
removed.add(edge);
|
|
3189
|
+
unindexEdge(graph, edge);
|
|
3190
|
+
continue;
|
|
3191
|
+
}
|
|
3192
|
+
seen.add(key);
|
|
3193
|
+
}
|
|
3194
|
+
if (removed.size > 0) {
|
|
3195
|
+
graph.edges = graph.edges.filter((edge) => !removed.has(edge));
|
|
3196
|
+
}
|
|
3197
|
+
}
|
|
3198
|
+
var _graphImportChanges = /* @__PURE__ */ new WeakMap();
|
|
3199
|
+
function getGraphImportChanges(graph) {
|
|
3200
|
+
return _graphImportChanges.get(graph);
|
|
3201
|
+
}
|
|
3202
|
+
function importTargetsForFile(graph, filePath) {
|
|
3203
|
+
const normalized = normalizeMapKey(filePath);
|
|
3204
|
+
const fileNodeId = graph.fileNodes.get(normalized) ?? `file:${normalized}`;
|
|
3205
|
+
const targets = /* @__PURE__ */ new Set();
|
|
3206
|
+
for (const edge of graph.edgesByFrom.get(fileNodeId) ?? []) {
|
|
3207
|
+
_rebuildCounters.importTargetEdgeScans++;
|
|
3208
|
+
if (edge.kind !== "imports")
|
|
3209
|
+
continue;
|
|
3210
|
+
const target = graph.nodes.get(edge.to)?.filePath;
|
|
3211
|
+
if (target)
|
|
3212
|
+
targets.add(normalizeMapKey(target));
|
|
3213
|
+
}
|
|
3214
|
+
return [...targets].sort((a, b) => compareOrdinal(a, b));
|
|
3215
|
+
}
|
|
3216
|
+
async function updateGraphFiles(graph, cwd, files, facts, ignoredIds) {
|
|
3217
|
+
rebuildIndexes(graph);
|
|
3218
|
+
const prior = files.map((file) => ({
|
|
3219
|
+
filePath: normalizeMapKey(file),
|
|
3220
|
+
existedBefore: graph.fileNodes.has(normalizeMapKey(file)),
|
|
3221
|
+
priorTargets: importTargetsForFile(graph, file)
|
|
3222
|
+
}));
|
|
3223
|
+
const preservedIncoming = [];
|
|
3224
|
+
const removedEdges = /* @__PURE__ */ new Set();
|
|
3225
|
+
for (const file of files) {
|
|
3226
|
+
preservedIncoming.push(...removeFileOwnedGraphData(graph, file, removedEdges));
|
|
3227
|
+
await addFileToGraph(graph, cwd, file, ignoredIds);
|
|
3228
|
+
}
|
|
3229
|
+
if (removedEdges.size > 0) {
|
|
3230
|
+
unindexEdges(graph, removedEdges);
|
|
3231
|
+
graph.edges = graph.edges.filter((edge) => !removedEdges.has(edge));
|
|
3232
|
+
}
|
|
3233
|
+
restoreValidIncomingEdges(graph, preservedIncoming);
|
|
3234
|
+
resolveDeferredSymbolEdges(graph, false);
|
|
3235
|
+
graph.changedSymbolsByFile.clear();
|
|
3236
|
+
for (const file of files) {
|
|
3237
|
+
upsertChangedSymbols(graph, facts, file);
|
|
3238
|
+
}
|
|
3239
|
+
return prior.map(({ filePath, existedBefore, priorTargets }) => ({
|
|
3240
|
+
filePath,
|
|
3241
|
+
existedBefore,
|
|
3242
|
+
existsAfter: graph.fileNodes.has(filePath),
|
|
3243
|
+
priorTargets,
|
|
3244
|
+
newTargets: importTargetsForFile(graph, filePath)
|
|
3245
|
+
}));
|
|
3246
|
+
}
|
|
3247
|
+
function resolveDeferredSymbolEdges(graph, rebuild = true) {
|
|
3248
|
+
const symbolNameToIds = /* @__PURE__ */ new Map();
|
|
3249
|
+
for (const node of graph.nodes.values()) {
|
|
3250
|
+
if (node.kind !== "symbol" || !node.symbolName)
|
|
3251
|
+
continue;
|
|
3252
|
+
if (node.metadata?.unresolvedName)
|
|
3253
|
+
continue;
|
|
3254
|
+
const ids = symbolNameToIds.get(node.symbolName) ?? [];
|
|
3255
|
+
ids.push(node.id);
|
|
3256
|
+
symbolNameToIds.set(node.symbolName, ids);
|
|
3257
|
+
}
|
|
3258
|
+
const replacements = [];
|
|
3259
|
+
graph.edges = graph.edges.map((edge) => {
|
|
3260
|
+
const targetNode = graph.nodes.get(edge.to);
|
|
3261
|
+
if (!targetNode?.metadata?.unresolvedName)
|
|
3262
|
+
return edge;
|
|
3263
|
+
const candidates = symbolNameToIds.get(targetNode.symbolName ?? "") ?? [];
|
|
3264
|
+
const importHintFile = edge.metadata?.importHintFile;
|
|
3265
|
+
if (importHintFile) {
|
|
3266
|
+
const scoped = candidates.filter((id) => graph.nodes.get(id)?.filePath === importHintFile);
|
|
3267
|
+
if (scoped.length === 1) {
|
|
3268
|
+
const resolved = {
|
|
3269
|
+
...edge,
|
|
3270
|
+
to: scoped[0],
|
|
3271
|
+
resolution: "import"
|
|
3272
|
+
};
|
|
3273
|
+
replacements.push([edge, resolved]);
|
|
3274
|
+
return resolved;
|
|
3275
|
+
}
|
|
3276
|
+
}
|
|
3277
|
+
if (candidates.length === 1) {
|
|
3278
|
+
const resolved = {
|
|
3279
|
+
...edge,
|
|
3280
|
+
to: candidates[0],
|
|
3281
|
+
resolution: "exact"
|
|
3282
|
+
};
|
|
3283
|
+
replacements.push([edge, resolved]);
|
|
3284
|
+
return resolved;
|
|
3285
|
+
}
|
|
3286
|
+
return edge;
|
|
3287
|
+
});
|
|
3288
|
+
if (rebuild) {
|
|
3289
|
+
rebuildIndexes(graph);
|
|
3290
|
+
return;
|
|
3291
|
+
}
|
|
3292
|
+
if (replacements.length === 0)
|
|
3293
|
+
return;
|
|
3294
|
+
const affectedTargets = /* @__PURE__ */ new Set();
|
|
3295
|
+
for (const [before, after] of replacements) {
|
|
3296
|
+
const fromBucket = graph.edgesByFrom.get(before.from);
|
|
3297
|
+
if (fromBucket) {
|
|
3298
|
+
const at = fromBucket.indexOf(before);
|
|
3299
|
+
if (at >= 0)
|
|
3300
|
+
fromBucket[at] = after;
|
|
3301
|
+
}
|
|
3302
|
+
affectedTargets.add(before.to);
|
|
3303
|
+
affectedTargets.add(after.to);
|
|
3304
|
+
}
|
|
3305
|
+
for (const target of affectedTargets)
|
|
3306
|
+
graph.edgesByTo.set(target, []);
|
|
3307
|
+
for (const edge of graph.edges) {
|
|
3308
|
+
if (affectedTargets.has(edge.to))
|
|
3309
|
+
graph.edgesByTo.get(edge.to)?.push(edge);
|
|
3310
|
+
}
|
|
3311
|
+
for (const target of affectedTargets) {
|
|
3312
|
+
if (graph.edgesByTo.get(target)?.length === 0) {
|
|
3313
|
+
graph.edgesByTo.delete(target);
|
|
3314
|
+
}
|
|
3315
|
+
}
|
|
3316
|
+
dedupeResolvedEdges(graph, replacements);
|
|
3317
|
+
}
|
|
3318
|
+
function verifiedCacheFields(seqAtBuildStart) {
|
|
3319
|
+
return {
|
|
3320
|
+
builtAtProjectSeq: seqAtBuildStart,
|
|
3321
|
+
lastFullVerifyMs: Date.now(),
|
|
3322
|
+
fastPathSinceVerify: 0
|
|
3323
|
+
};
|
|
3324
|
+
}
|
|
3325
|
+
async function tryIncrementalFromCache(cached, ctx) {
|
|
3326
|
+
if (cached.fileSignatures.size === 0)
|
|
3327
|
+
return void 0;
|
|
3328
|
+
const { added, removed, changed } = diffSignatureMaps(cached.fileSignatures, ctx.fileSignatures);
|
|
3329
|
+
if (removed.length > 0)
|
|
3330
|
+
return void 0;
|
|
3331
|
+
if (added.length === 0 && changed.length === 0)
|
|
3332
|
+
return void 0;
|
|
3333
|
+
const { trulyChanged, hashes } = await confirmContentChanged(changed, cached.fileHashes);
|
|
3334
|
+
const filesToUpdate = [...added, ...trulyChanged];
|
|
3335
|
+
if (filesToUpdate.length === 0) {
|
|
3336
|
+
const generation2 = cached.buildGeneration ?? ++_graphGenerationCounter;
|
|
3337
|
+
const graph2 = cloneGraph(cached.graph);
|
|
3338
|
+
rebuildIndexes(graph2);
|
|
3339
|
+
graph2.changedSymbolsByFile.clear();
|
|
3340
|
+
for (const file of ctx.normalizedChanged) {
|
|
3341
|
+
upsertChangedSymbols(graph2, ctx.facts, file);
|
|
3342
|
+
}
|
|
3343
|
+
setWorkspaceGraph(ctx.normalizedCwd, {
|
|
3344
|
+
signature: ctx.signature,
|
|
3345
|
+
fileSignatures: new Map(ctx.fileSignatures),
|
|
3346
|
+
fileHashes: hashes,
|
|
3347
|
+
graph: cloneGraph(cached.graph),
|
|
3348
|
+
buildGeneration: generation2,
|
|
3349
|
+
...verifiedCacheFields(ctx.seqAtBuildStart)
|
|
3350
|
+
}, ctx.cacheEpoch);
|
|
3351
|
+
setGraphBuildInfo(graph2, {
|
|
3352
|
+
reused: true,
|
|
3353
|
+
mode: "cached",
|
|
3354
|
+
graphChanged: false
|
|
3355
|
+
});
|
|
3356
|
+
graph2.buildGeneration = generation2;
|
|
3357
|
+
setSessionReviewGraphFact(ctx.cwd, ctx.facts, graph2);
|
|
3358
|
+
return graph2;
|
|
3359
|
+
}
|
|
3360
|
+
for (const file of added) {
|
|
3361
|
+
hashes.set(file, contentHashEntry(file));
|
|
3362
|
+
}
|
|
3363
|
+
const priorGeneration = cached.graph.buildGeneration;
|
|
3364
|
+
const graph = cloneGraph(cached.graph);
|
|
3365
|
+
const importChanges = await updateGraphFiles(graph, ctx.cwd, filesToUpdate, ctx.facts, ctx.ignoredIds);
|
|
3366
|
+
refreshGraphBuiltAt(graph);
|
|
3367
|
+
const generation = ++_graphGenerationCounter;
|
|
3368
|
+
graph.buildGeneration = generation;
|
|
3369
|
+
setWorkspaceGraph(ctx.normalizedCwd, {
|
|
3370
|
+
signature: ctx.signature,
|
|
3371
|
+
fileSignatures: new Map(ctx.fileSignatures),
|
|
3372
|
+
fileHashes: hashes,
|
|
3373
|
+
graph,
|
|
3374
|
+
buildGeneration: generation,
|
|
3375
|
+
...verifiedCacheFields(ctx.seqAtBuildStart)
|
|
3376
|
+
}, ctx.cacheEpoch);
|
|
3377
|
+
const persistReason = persistGraph(ctx.cwd, ctx.signature, ctx.fileSignatures, hashes, graph, {
|
|
3378
|
+
buildId: ctx.buildId,
|
|
3379
|
+
projectSeq: ctx.seqAtBuildStart,
|
|
3380
|
+
seqHint: ctx.seqHint,
|
|
3381
|
+
mode: ctx.mode,
|
|
3382
|
+
resolveIdentity: ctx.resolveIdentity
|
|
3383
|
+
});
|
|
3384
|
+
setGraphBuildInfo(graph, {
|
|
3385
|
+
reused: true,
|
|
3386
|
+
mode: "incremental",
|
|
3387
|
+
...persistReason ? { persistReason } : {},
|
|
3388
|
+
graphChanged: true
|
|
3389
|
+
});
|
|
3390
|
+
_graphImportChanges.set(graph, {
|
|
3391
|
+
fromGeneration: priorGeneration,
|
|
3392
|
+
changes: importChanges
|
|
3393
|
+
});
|
|
3394
|
+
setSessionReviewGraphFact(ctx.cwd, ctx.facts, graph);
|
|
3395
|
+
return graph;
|
|
3396
|
+
}
|
|
3397
|
+
function hasGraphKindExtension(file) {
|
|
3398
|
+
const kind = detectFileKind(file);
|
|
3399
|
+
return !!kind && MAIN_KINDS.has(kind) && detectFileRole(file) !== "test";
|
|
3400
|
+
}
|
|
3401
|
+
async function trySeqFastpath(cwd, buildId, normalizedCwd, normalizedChanged, facts, seqHint, seqAtBuildStart, ignoredIds, cacheEpoch, resolveIdentity) {
|
|
3402
|
+
const cached = _workspaceGraphCache.get(normalizedCwd);
|
|
3403
|
+
const cachedCoverage = cached?.graph.persistCoverage;
|
|
3404
|
+
if (cachedCoverage?.partial && cachedCoverage.capTrimmed !== true) {
|
|
3405
|
+
return { fallback: "partial-base" };
|
|
3406
|
+
}
|
|
3407
|
+
if (!cached || cached.builtAtProjectSeq === void 0) {
|
|
3408
|
+
return { fallback: "no-seq" };
|
|
3409
|
+
}
|
|
3410
|
+
const now = Date.now();
|
|
3411
|
+
const ageMs = cached.lastFullVerifyMs === void 0 ? Number.POSITIVE_INFINITY : now - cached.lastFullVerifyMs;
|
|
3412
|
+
const sinceVerify = cached.fastPathSinceVerify ?? 0;
|
|
3413
|
+
if (ageMs > SEQ_FASTPATH_REVERIFY_MS || sinceVerify >= SEQ_FASTPATH_REVERIFY_EVERY) {
|
|
3414
|
+
return { fallback: "verify-due" };
|
|
3415
|
+
}
|
|
3416
|
+
const changedSet = new Set(seqHint.getFilesChangedSince(cached.builtAtProjectSeq).map((file) => normalizeMapKey(file)));
|
|
3417
|
+
for (const file of normalizedChanged)
|
|
3418
|
+
changedSet.add(file);
|
|
3419
|
+
for (const file of _wasmTrappedFiles.keys()) {
|
|
3420
|
+
if (cached.fileSignatures.has(file))
|
|
3421
|
+
changedSet.add(file);
|
|
3422
|
+
}
|
|
3423
|
+
const changed = [...changedSet];
|
|
3424
|
+
if (changed.length > SEQ_FASTPATH_MAX_CHANGES) {
|
|
3425
|
+
return { fallback: "too-many-changes" };
|
|
3426
|
+
}
|
|
3427
|
+
const candidateFiles = [];
|
|
3428
|
+
for (const file of changed) {
|
|
3429
|
+
const known = cached.fileSignatures.has(file);
|
|
3430
|
+
let existsOnDisk = false;
|
|
3431
|
+
try {
|
|
3432
|
+
existsOnDisk = fs2.statSync(file).isFile();
|
|
3433
|
+
} catch {
|
|
3434
|
+
existsOnDisk = false;
|
|
3435
|
+
}
|
|
3436
|
+
if (!existsOnDisk) {
|
|
3437
|
+
if (known) {
|
|
3438
|
+
return { fallback: "removed-file" };
|
|
3439
|
+
}
|
|
3440
|
+
continue;
|
|
3441
|
+
}
|
|
3442
|
+
if (!known) {
|
|
3443
|
+
if (!hasGraphKindExtension(file))
|
|
3444
|
+
continue;
|
|
3445
|
+
}
|
|
3446
|
+
candidateFiles.push(file);
|
|
3447
|
+
}
|
|
3448
|
+
const candidateStats = candidateFiles.map((file) => [file, sourceSignatureEntry(file)]);
|
|
3449
|
+
const { trulyChanged, hashes } = await confirmContentChanged(candidateFiles, cached.fileHashes);
|
|
3450
|
+
if (trulyChanged.length === 0) {
|
|
3451
|
+
const graph2 = cloneGraph(cached.graph);
|
|
3452
|
+
rebuildIndexes(graph2);
|
|
3453
|
+
graph2.changedSymbolsByFile.clear();
|
|
3454
|
+
for (const file of normalizedChanged) {
|
|
3455
|
+
upsertChangedSymbols(graph2, facts, file);
|
|
3456
|
+
}
|
|
3457
|
+
const nextSignatures2 = new Map(cached.fileSignatures);
|
|
3458
|
+
for (const [file, stat] of candidateStats) {
|
|
3459
|
+
nextSignatures2.set(file, stat);
|
|
3460
|
+
}
|
|
3461
|
+
cached.signature = sourceSignatureFromMap(nextSignatures2);
|
|
3462
|
+
cached.fileSignatures = nextSignatures2;
|
|
3463
|
+
cached.fileHashes = hashes;
|
|
3464
|
+
cached.builtAtProjectSeq = seqAtBuildStart;
|
|
3465
|
+
cached.fastPathSinceVerify = sinceVerify + 1;
|
|
3466
|
+
const generation2 = cached.buildGeneration ??= ++_graphGenerationCounter;
|
|
3467
|
+
setGraphBuildInfo(graph2, {
|
|
3468
|
+
reused: true,
|
|
3469
|
+
mode: "seq-fastpath",
|
|
3470
|
+
graphChanged: false
|
|
3471
|
+
});
|
|
3472
|
+
graph2.buildGeneration = generation2;
|
|
3473
|
+
setSessionReviewGraphFact(cwd, facts, graph2);
|
|
3474
|
+
return { graph: graph2 };
|
|
3475
|
+
}
|
|
3476
|
+
const filesToUpdate = trulyChanged;
|
|
3477
|
+
const priorGeneration = cached.graph.buildGeneration;
|
|
3478
|
+
const graph = cloneGraph(cached.graph);
|
|
3479
|
+
let importChanges;
|
|
3480
|
+
try {
|
|
3481
|
+
importChanges = await updateGraphFiles(graph, cwd, filesToUpdate, facts, ignoredIds);
|
|
3482
|
+
} catch {
|
|
3483
|
+
return { fallback: "stat-error" };
|
|
3484
|
+
}
|
|
3485
|
+
refreshGraphBuiltAt(graph);
|
|
3486
|
+
const nextSignatures = new Map(cached.fileSignatures);
|
|
3487
|
+
for (const [file, stat] of candidateStats) {
|
|
3488
|
+
nextSignatures.set(file, stat);
|
|
3489
|
+
}
|
|
3490
|
+
const nextSignature = sourceSignatureFromMap(nextSignatures);
|
|
3491
|
+
const generation = ++_graphGenerationCounter;
|
|
3492
|
+
graph.buildGeneration = generation;
|
|
3493
|
+
setWorkspaceGraph(normalizedCwd, {
|
|
3494
|
+
signature: nextSignature,
|
|
3495
|
+
fileSignatures: nextSignatures,
|
|
3496
|
+
fileHashes: hashes,
|
|
3497
|
+
graph,
|
|
3498
|
+
buildGeneration: generation,
|
|
3499
|
+
// Build-start seq, not stamp-time: see verifiedCacheFields — a bump that
|
|
3500
|
+
// interleaved during updateGraphFiles' awaits must be re-diffed next build.
|
|
3501
|
+
builtAtProjectSeq: seqAtBuildStart,
|
|
3502
|
+
lastFullVerifyMs: cached.lastFullVerifyMs,
|
|
3503
|
+
fastPathSinceVerify: sinceVerify + 1
|
|
3504
|
+
}, cacheEpoch);
|
|
3505
|
+
const persistReason = persistGraph(cwd, nextSignature, nextSignatures, hashes, graph, {
|
|
3506
|
+
buildId,
|
|
3507
|
+
projectSeq: seqAtBuildStart,
|
|
3508
|
+
seqHint: true,
|
|
3509
|
+
mode: "seq-fastpath",
|
|
3510
|
+
resolveIdentity
|
|
3511
|
+
});
|
|
3512
|
+
setGraphBuildInfo(graph, {
|
|
3513
|
+
reused: true,
|
|
3514
|
+
mode: "seq-fastpath",
|
|
3515
|
+
...persistReason ? { persistReason } : {},
|
|
3516
|
+
graphChanged: true
|
|
3517
|
+
});
|
|
3518
|
+
_graphImportChanges.set(graph, {
|
|
3519
|
+
fromGeneration: priorGeneration,
|
|
3520
|
+
changes: importChanges
|
|
3521
|
+
});
|
|
3522
|
+
setSessionReviewGraphFact(cwd, facts, graph);
|
|
3523
|
+
return { graph };
|
|
3524
|
+
}
|
|
3525
|
+
async function _doBuildGraph(cwd, changedFiles, facts, seqHint, buildId) {
|
|
3526
|
+
const resolveIdentity = createGitIdentityResolver();
|
|
3527
|
+
const normalizedCwd = normalizeMapKey(cwd);
|
|
3528
|
+
const cacheEpoch = workspaceCacheEpoch(normalizedCwd);
|
|
3529
|
+
if (_reviewGraphBuildGateForTests)
|
|
3530
|
+
await _reviewGraphBuildGateForTests();
|
|
3531
|
+
const normalizedChanged = changedFiles.map((file) => normalizeMapKey(file));
|
|
3532
|
+
const normalizedChangedSet = new Set(normalizedChanged);
|
|
3533
|
+
logCwdWorktreeMismatchOnce(cwd, resolveIdentity);
|
|
3534
|
+
if (isAtOrAboveHomeDir(path2.resolve(cwd))) {
|
|
3535
|
+
const graph2 = createEmptyGraph();
|
|
3536
|
+
for (const file of normalizedChanged) {
|
|
3537
|
+
upsertChangedSymbols(graph2, facts, file);
|
|
3538
|
+
}
|
|
3539
|
+
setGraphBuildInfo(graph2, {
|
|
3540
|
+
reused: false,
|
|
3541
|
+
mode: "skipped",
|
|
3542
|
+
skipReason: "unsafe_root",
|
|
3543
|
+
// #459: never persisted/reused, same as the too_many_files skip below —
|
|
3544
|
+
// treat as changed so dependents never trust stale derived state.
|
|
3545
|
+
graphChanged: true
|
|
3546
|
+
});
|
|
3547
|
+
setSessionReviewGraphFact(cwd, facts, graph2);
|
|
3548
|
+
return graph2;
|
|
3549
|
+
}
|
|
3550
|
+
const seqAtBuildStart = seqHint?.projectSeq();
|
|
3551
|
+
const ignoredIdsPromise = collectUntrackedIgnoredIds(cwd);
|
|
3552
|
+
let seqFastpathFallback;
|
|
3553
|
+
if (seqHint && seqAtBuildStart !== void 0 && seqFastpathEnabled()) {
|
|
3554
|
+
const fast = await trySeqFastpath(cwd, buildId, normalizedCwd, normalizedChanged, facts, seqHint, seqAtBuildStart, await ignoredIdsPromise, cacheEpoch, resolveIdentity);
|
|
3555
|
+
if ("graph" in fast)
|
|
3556
|
+
return fast.graph;
|
|
3557
|
+
seqFastpathFallback = fast.fallback;
|
|
3558
|
+
}
|
|
3559
|
+
const sourceCollection = await getGraphSourceFiles(cwd);
|
|
3560
|
+
const filesToBuild = sourceCollection.files;
|
|
3561
|
+
const sourceFileCount = sourceCollection.sourceFileCount;
|
|
3562
|
+
const pathNormalizeCalls = sourceCollection.pathNormalizeCalls;
|
|
3563
|
+
const sourceFilesTruncated = sourceCollection.entryBudgetExceeded;
|
|
3564
|
+
const ignoredIds = await ignoredIdsPromise;
|
|
3565
|
+
const maxGraphFiles = sourceCollection.maxFileCount;
|
|
3566
|
+
if (filesToBuild.length > maxGraphFiles) {
|
|
3567
|
+
const graph2 = createEmptyGraph();
|
|
3568
|
+
graph2.version = REVIEW_GRAPH_VERSION;
|
|
3569
|
+
graph2.builtAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
3570
|
+
for (const file of normalizedChanged) {
|
|
3571
|
+
upsertChangedSymbols(graph2, facts, file);
|
|
3572
|
+
}
|
|
3573
|
+
recordReviewGraphSizeSkip(cwd, sourceFileCount, maxGraphFiles);
|
|
3574
|
+
logLatency({
|
|
3575
|
+
type: "phase",
|
|
3576
|
+
phase: "review_graph_size_skip",
|
|
3577
|
+
filePath: cwd,
|
|
3578
|
+
durationMs: 0,
|
|
3579
|
+
metadata: {
|
|
3580
|
+
cwd,
|
|
3581
|
+
sourceFileCount,
|
|
3582
|
+
maxFileCount: maxGraphFiles,
|
|
3583
|
+
sourceFileCountLabel: `more than ${maxGraphFiles} files`,
|
|
3584
|
+
sourceFileCountTruncated: true
|
|
3585
|
+
}
|
|
3586
|
+
});
|
|
3587
|
+
if (isReviewGraphSizeNearMiss(sourceFileCount, maxGraphFiles)) {
|
|
3588
|
+
logLatency({
|
|
3589
|
+
type: "phase",
|
|
3590
|
+
phase: "review_graph_size_near_miss",
|
|
3591
|
+
filePath: cwd,
|
|
3592
|
+
durationMs: 0,
|
|
3593
|
+
metadata: {
|
|
3594
|
+
cwd,
|
|
3595
|
+
maxFileCount: maxGraphFiles,
|
|
3596
|
+
sourceFileCount,
|
|
3597
|
+
sourceFileCountLabel: `more than ${maxGraphFiles} files`,
|
|
3598
|
+
sourceFileCountTruncated: true
|
|
3599
|
+
}
|
|
3600
|
+
});
|
|
3601
|
+
}
|
|
3602
|
+
setGraphBuildInfo(graph2, {
|
|
3603
|
+
reused: false,
|
|
3604
|
+
mode: "skipped",
|
|
3605
|
+
skipReason: "too_many_files",
|
|
3606
|
+
sourceFileCount,
|
|
3607
|
+
sourceFileCountTruncated: sourceFilesTruncated || filesToBuild.length > maxGraphFiles,
|
|
3608
|
+
maxFileCount: maxGraphFiles,
|
|
3609
|
+
pathNormalizeCalls,
|
|
3610
|
+
seqFastpathFallback,
|
|
3611
|
+
// #459: a fresh empty graph is returned every call on this path (never
|
|
3612
|
+
// persisted/reused) — treat it as changed so dependents never trust stale
|
|
3613
|
+
// derived state across skip/unskip transitions. Deliberately NOT stamped
|
|
3614
|
+
// with a buildGeneration: absent ⇒ derived caches rebuild every time.
|
|
3615
|
+
graphChanged: true
|
|
3616
|
+
});
|
|
3617
|
+
setSessionReviewGraphFact(cwd, facts, graph2);
|
|
3618
|
+
return graph2;
|
|
3619
|
+
}
|
|
3620
|
+
if (!sourceFilesTruncated)
|
|
3621
|
+
clearReviewGraphSizeSkip(cwd);
|
|
3622
|
+
const fileSignatures = await sourceSignatureMapAsync(filesToBuild);
|
|
3623
|
+
const signature = sourceSignatureFromMap(fileSignatures);
|
|
3624
|
+
let memCached = sourceFilesTruncated ? void 0 : _workspaceGraphCache.get(normalizedCwd);
|
|
3625
|
+
const memCoverage = memCached?.graph.persistCoverage;
|
|
3626
|
+
if (memCoverage?.partial && memCoverage.capTrimmed !== true) {
|
|
3627
|
+
memCached = void 0;
|
|
3628
|
+
}
|
|
3629
|
+
if (memCached?.signature === signature) {
|
|
3630
|
+
touchWorkspaceGraph(normalizedCwd);
|
|
3631
|
+
const graph2 = cloneGraph(memCached.graph);
|
|
3632
|
+
rebuildIndexes(graph2);
|
|
3633
|
+
graph2.changedSymbolsByFile.clear();
|
|
3634
|
+
for (const file of normalizedChanged) {
|
|
3635
|
+
upsertChangedSymbols(graph2, facts, file);
|
|
3636
|
+
}
|
|
3637
|
+
Object.assign(memCached, verifiedCacheFields(seqAtBuildStart));
|
|
3638
|
+
const generation2 = memCached.buildGeneration ??= ++_graphGenerationCounter;
|
|
3639
|
+
setGraphBuildInfo(graph2, {
|
|
3640
|
+
reused: true,
|
|
3641
|
+
mode: "cached",
|
|
3642
|
+
seqFastpathFallback,
|
|
3643
|
+
graphChanged: false
|
|
3644
|
+
});
|
|
3645
|
+
graph2.buildGeneration = generation2;
|
|
3646
|
+
setSessionReviewGraphFact(cwd, facts, graph2);
|
|
3647
|
+
return graph2;
|
|
3648
|
+
}
|
|
3649
|
+
if (memCached) {
|
|
3650
|
+
const incremental = await tryIncrementalFromCache(memCached, {
|
|
3651
|
+
cwd,
|
|
3652
|
+
buildId,
|
|
3653
|
+
seqHint: seqHint !== void 0,
|
|
3654
|
+
mode: "incremental",
|
|
3655
|
+
normalizedCwd,
|
|
3656
|
+
normalizedChanged,
|
|
3657
|
+
fileSignatures,
|
|
3658
|
+
signature,
|
|
3659
|
+
facts,
|
|
3660
|
+
seqAtBuildStart,
|
|
3661
|
+
ignoredIds,
|
|
3662
|
+
cacheEpoch,
|
|
3663
|
+
resolveIdentity
|
|
3664
|
+
});
|
|
3665
|
+
if (incremental) {
|
|
3666
|
+
updateGraphBuildInfo(incremental, { seqFastpathFallback });
|
|
3667
|
+
return incremental;
|
|
3668
|
+
}
|
|
3669
|
+
}
|
|
3670
|
+
const diskCached = sourceFilesTruncated ? null : loadPersistedGraph(cwd, void 0, resolveIdentity);
|
|
3671
|
+
if (diskCached?.signature === signature) {
|
|
3672
|
+
const graph2 = cloneGraph(diskCached.graph);
|
|
3673
|
+
rebuildIndexes(graph2);
|
|
3674
|
+
graph2.changedSymbolsByFile.clear();
|
|
3675
|
+
for (const file of normalizedChanged) {
|
|
3676
|
+
upsertChangedSymbols(graph2, facts, file);
|
|
3677
|
+
}
|
|
3678
|
+
const generation2 = ++_graphGenerationCounter;
|
|
3679
|
+
setWorkspaceGraph(normalizedCwd, {
|
|
3680
|
+
signature,
|
|
3681
|
+
fileSignatures: new Map(fileSignatures),
|
|
3682
|
+
fileHashes: diskCached.fileHashes,
|
|
3683
|
+
graph: cloneGraph(diskCached.graph),
|
|
3684
|
+
buildGeneration: generation2,
|
|
3685
|
+
...verifiedCacheFields(seqAtBuildStart)
|
|
3686
|
+
}, cacheEpoch);
|
|
3687
|
+
setGraphBuildInfo(graph2, {
|
|
3688
|
+
reused: true,
|
|
3689
|
+
mode: "cached",
|
|
3690
|
+
seqFastpathFallback,
|
|
3691
|
+
graphChanged: false
|
|
3692
|
+
});
|
|
3693
|
+
graph2.buildGeneration = generation2;
|
|
3694
|
+
setSessionReviewGraphFact(cwd, facts, graph2);
|
|
3695
|
+
return graph2;
|
|
3696
|
+
}
|
|
3697
|
+
if (diskCached) {
|
|
3698
|
+
const incremental = await tryIncrementalFromCache({
|
|
3699
|
+
signature: diskCached.signature,
|
|
3700
|
+
fileSignatures: diskCached.fileSignatures,
|
|
3701
|
+
fileHashes: diskCached.fileHashes,
|
|
3702
|
+
graph: diskCached.graph
|
|
3703
|
+
}, {
|
|
3704
|
+
cwd,
|
|
3705
|
+
buildId,
|
|
3706
|
+
seqHint: seqHint !== void 0,
|
|
3707
|
+
mode: "incremental",
|
|
3708
|
+
normalizedCwd,
|
|
3709
|
+
normalizedChanged,
|
|
3710
|
+
fileSignatures,
|
|
3711
|
+
signature,
|
|
3712
|
+
facts,
|
|
3713
|
+
seqAtBuildStart,
|
|
3714
|
+
ignoredIds,
|
|
3715
|
+
resolveIdentity
|
|
3716
|
+
});
|
|
3717
|
+
if (incremental) {
|
|
3718
|
+
updateGraphBuildInfo(incremental, { seqFastpathFallback });
|
|
3719
|
+
return incremental;
|
|
3720
|
+
}
|
|
3721
|
+
}
|
|
3722
|
+
const resumed = sourceFilesTruncated ? null : await tryResumeFromCheckpoint(cwd, filesToBuild, ignoredIds, resolveIdentity);
|
|
3723
|
+
const graph = resumed?.graph ?? createEmptyGraph();
|
|
3724
|
+
const filesToExtract = resumed?.remaining ?? filesToBuild;
|
|
3725
|
+
const treeSitterClient = getSharedTreeSitterClient();
|
|
3726
|
+
treeSitterClient?.ensureTreeCacheCapacity(filesToExtract.length);
|
|
3727
|
+
const extractionStartedAt = Date.now();
|
|
3728
|
+
const fileHashes = resumed?.fileHashes ?? /* @__PURE__ */ new Map();
|
|
3729
|
+
const checkpointEvery = graphCheckpointEveryFiles();
|
|
3730
|
+
const checkpointMinIntervalMs = graphCheckpointMinIntervalMs();
|
|
3731
|
+
const testStopAfter = Number(process.env.PI_LENS_GRAPH_CHECKPOINT_TEST_STOP_AFTER);
|
|
3732
|
+
let filesSinceCheckpoint = 0;
|
|
3733
|
+
let lastCheckpointMs = Date.now();
|
|
3734
|
+
let extractedCount = 0;
|
|
3735
|
+
const extractFiles = async () => {
|
|
3736
|
+
for (const file of filesToExtract) {
|
|
3737
|
+
let content;
|
|
3738
|
+
try {
|
|
3739
|
+
const bytes = fs2.readFileSync(file);
|
|
3740
|
+
content = bytes.toString("utf-8");
|
|
3741
|
+
fileHashes.set(file, createHash2("sha256").update(bytes).digest("hex"));
|
|
3742
|
+
} catch {
|
|
3743
|
+
content = null;
|
|
3744
|
+
fileHashes.set(file, "missing");
|
|
3745
|
+
}
|
|
3746
|
+
await addFileToGraph(graph, cwd, file, ignoredIds, content);
|
|
3747
|
+
if (normalizedChangedSet.has(file)) {
|
|
3748
|
+
upsertChangedSymbols(graph, facts, file);
|
|
3749
|
+
}
|
|
3750
|
+
extractedCount++;
|
|
3751
|
+
filesSinceCheckpoint++;
|
|
3752
|
+
if (Number.isFinite(testStopAfter) && testStopAfter > 0 && extractedCount >= testStopAfter) {
|
|
3753
|
+
writeReviewGraphCheckpointSync(cwd, buildReviewGraphCheckpointData(cwd, graph, fileHashes, filesToBuild.length, ignoredIds, resolveIdentity), {
|
|
3754
|
+
nodes: graph.nodes.size,
|
|
3755
|
+
edges: graph.edges.length,
|
|
3756
|
+
processed: fileHashes.size,
|
|
3757
|
+
target: filesToBuild.length
|
|
3758
|
+
});
|
|
3759
|
+
throw new Error("__review_graph_checkpoint_test_abort__");
|
|
3760
|
+
}
|
|
3761
|
+
const remainingAfter = filesToExtract.length - extractedCount;
|
|
3762
|
+
if (filesSinceCheckpoint >= checkpointEvery && remainingAfter >= checkpointEvery && Date.now() - lastCheckpointMs >= checkpointMinIntervalMs) {
|
|
3763
|
+
writeReviewGraphCheckpoint(cwd, graph, fileHashes, filesToBuild.length, ignoredIds, resolveIdentity);
|
|
3764
|
+
filesSinceCheckpoint = 0;
|
|
3765
|
+
lastCheckpointMs = Date.now();
|
|
3766
|
+
}
|
|
3767
|
+
}
|
|
3768
|
+
};
|
|
3769
|
+
const extractAndDrainIr = async () => {
|
|
3770
|
+
try {
|
|
3771
|
+
await extractFiles();
|
|
3772
|
+
} finally {
|
|
3773
|
+
clearReviewGraphFileIr(cwd);
|
|
3774
|
+
}
|
|
3775
|
+
};
|
|
3776
|
+
if (treeSitterClient) {
|
|
3777
|
+
await treeSitterClient.withParseCacheMeasurement(extractAndDrainIr, (stats) => {
|
|
3778
|
+
logTreeSitterCacheStats({
|
|
3779
|
+
scope: "review_graph_full",
|
|
3780
|
+
filePath: cwd,
|
|
3781
|
+
fileCount: filesToBuild.length,
|
|
3782
|
+
durationMs: Date.now() - extractionStartedAt,
|
|
3783
|
+
stats,
|
|
3784
|
+
// #1982: this scope never runs an ast-grep pass (extraction is
|
|
3785
|
+
// tree-sitter only), so durationMs carries none and explicit
|
|
3786
|
+
// zeros keep every cache_stats record uniformly parseable.
|
|
3787
|
+
astGrep: { durationMs: 0, fileCount: 0 }
|
|
3788
|
+
});
|
|
3789
|
+
});
|
|
3790
|
+
} else {
|
|
3791
|
+
await extractAndDrainIr();
|
|
3792
|
+
}
|
|
3793
|
+
if (resumed) {
|
|
3794
|
+
for (const file of normalizedChangedSet) {
|
|
3795
|
+
if (resumed.fileHashes.has(file)) {
|
|
3796
|
+
upsertChangedSymbols(graph, facts, file);
|
|
3797
|
+
}
|
|
3798
|
+
}
|
|
3799
|
+
}
|
|
3800
|
+
resolveDeferredSymbolEdges(graph);
|
|
3801
|
+
graph.version = REVIEW_GRAPH_VERSION;
|
|
3802
|
+
graph.builtAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
3803
|
+
graph.persistCoverage = sourceFilesTruncated ? graphCoverage(graph, graphPersistMaxElements(), sourceFileCount, true, filesToBuild) : void 0;
|
|
3804
|
+
deleteReviewGraphCheckpoint(cwd);
|
|
3805
|
+
const generation = ++_graphGenerationCounter;
|
|
3806
|
+
const retained = retainedGraph(cwd, graph);
|
|
3807
|
+
const wasCapped = retained !== graph;
|
|
3808
|
+
const graphSnapshot = wasCapped ? retained : cloneGraph(graph);
|
|
3809
|
+
if (!wasCapped)
|
|
3810
|
+
rebuildIndexes(graphSnapshot);
|
|
3811
|
+
graphSnapshot.buildGeneration = generation;
|
|
3812
|
+
setWorkspaceGraph(normalizedCwd, {
|
|
3813
|
+
signature,
|
|
3814
|
+
fileSignatures: new Map(fileSignatures),
|
|
3815
|
+
fileHashes,
|
|
3816
|
+
graph: graphSnapshot,
|
|
3817
|
+
buildGeneration: generation,
|
|
3818
|
+
...verifiedCacheFields(seqAtBuildStart)
|
|
3819
|
+
}, cacheEpoch);
|
|
3820
|
+
const persistReason = persistGraph(cwd, signature, fileSignatures, fileHashes, graphSnapshot, {
|
|
3821
|
+
buildId,
|
|
3822
|
+
projectSeq: seqAtBuildStart,
|
|
3823
|
+
seqHint: seqHint !== void 0,
|
|
3824
|
+
mode: "full",
|
|
3825
|
+
sourceFileCount,
|
|
3826
|
+
sourceFilesTruncated,
|
|
3827
|
+
resolveIdentity
|
|
3828
|
+
});
|
|
3829
|
+
setGraphBuildInfo(graph, {
|
|
3830
|
+
reused: false,
|
|
3831
|
+
mode: "full",
|
|
3832
|
+
sourceFileCount,
|
|
3833
|
+
sourceFileCountTruncated: sourceFilesTruncated,
|
|
3834
|
+
pathNormalizeCalls,
|
|
3835
|
+
seqFastpathFallback,
|
|
3836
|
+
...persistReason ? { persistReason } : {},
|
|
3837
|
+
graphChanged: true
|
|
3838
|
+
});
|
|
3839
|
+
graph.buildGeneration = generation;
|
|
3840
|
+
setSessionReviewGraphFact(cwd, facts, graphSnapshot);
|
|
3841
|
+
return graph;
|
|
3842
|
+
}
|
|
3843
|
+
function buildCacheKey(cwd, changedFiles) {
|
|
3844
|
+
return `${buildCacheWorkspaceKey(cwd)}|${[...changedFiles].sort((a, b) => compareOrdinal(a, b)).join(",")}`;
|
|
3845
|
+
}
|
|
3846
|
+
function isGraphBuildInFlight(cwd, changedFiles = []) {
|
|
3847
|
+
return _buildCache.has(buildCacheKey(cwd, changedFiles));
|
|
3848
|
+
}
|
|
3849
|
+
function buildOrUpdateGraph(cwd, changedFiles, facts, seqHint) {
|
|
3850
|
+
const cacheKey = buildCacheKey(cwd, changedFiles);
|
|
3851
|
+
const cached = _buildCache.get(cacheKey);
|
|
3852
|
+
if (cached)
|
|
3853
|
+
return cached;
|
|
3854
|
+
const startedAt = Date.now();
|
|
3855
|
+
const buildId = ++_buildIdCounter;
|
|
3856
|
+
recordBuildAttempt(cwd, "running", void 0, buildId);
|
|
3857
|
+
const startedProjectSeq = seqHint?.projectSeq();
|
|
3858
|
+
logReviewGraph({
|
|
3859
|
+
cwd,
|
|
3860
|
+
phase: "build_started",
|
|
3861
|
+
observability: {
|
|
3862
|
+
graph: {
|
|
3863
|
+
buildId,
|
|
3864
|
+
...startedProjectSeq === void 0 ? {} : { projectSeq: startedProjectSeq },
|
|
3865
|
+
...seqHint === void 0 ? {} : { seqHint: true },
|
|
3866
|
+
nodes: 0,
|
|
3867
|
+
edges: 0
|
|
3868
|
+
}
|
|
3869
|
+
}
|
|
3870
|
+
});
|
|
3871
|
+
const promise = _doBuildGraph(cwd, changedFiles, facts, seqHint, buildId).then((graph) => {
|
|
3872
|
+
let buildInfo = getGraphBuildInfoForGraph(graph);
|
|
3873
|
+
const wasmTrappedFiles = wasmTrappedFileCount(graph);
|
|
3874
|
+
if (wasmTrappedFiles > 0) {
|
|
3875
|
+
buildInfo = updateGraphBuildInfo(graph, { wasmTrappedFiles });
|
|
3876
|
+
}
|
|
3877
|
+
if (buildInfo.mode === "skipped") {
|
|
3878
|
+
const reason = buildInfo.skipReason ?? "skipped";
|
|
3879
|
+
recordBuildAttempt(cwd, "skipped", reason, buildId);
|
|
3880
|
+
logReviewGraph({
|
|
3881
|
+
cwd,
|
|
3882
|
+
phase: "build_skipped",
|
|
3883
|
+
reason,
|
|
3884
|
+
durationMs: Date.now() - startedAt,
|
|
3885
|
+
observability: {
|
|
3886
|
+
graph: graphLogMetadata(graph, {
|
|
3887
|
+
buildId,
|
|
3888
|
+
projectSeq: startedProjectSeq,
|
|
3889
|
+
seqHint: seqHint !== void 0,
|
|
3890
|
+
mode: buildInfo.mode,
|
|
3891
|
+
sourceFileCount: buildInfo.sourceFileCount,
|
|
3892
|
+
sourceFileCountTruncated: buildInfo.sourceFileCountTruncated,
|
|
3893
|
+
pathNormalizeCalls: buildInfo.pathNormalizeCalls
|
|
3894
|
+
})
|
|
3895
|
+
}
|
|
3896
|
+
});
|
|
3897
|
+
} else {
|
|
3898
|
+
const reason = buildInfo.persistReason;
|
|
3899
|
+
recordBuildAttempt(cwd, "succeeded", reason, buildId);
|
|
3900
|
+
logReviewGraph({
|
|
3901
|
+
cwd,
|
|
3902
|
+
phase: "build_succeeded",
|
|
3903
|
+
durationMs: Date.now() - startedAt,
|
|
3904
|
+
nodes: graph.nodes.size,
|
|
3905
|
+
edges: graph.edges.length,
|
|
3906
|
+
...reason ? { reason } : {},
|
|
3907
|
+
observability: {
|
|
3908
|
+
graph: graphLogMetadata(graph, {
|
|
3909
|
+
buildId,
|
|
3910
|
+
projectSeq: startedProjectSeq,
|
|
3911
|
+
seqHint: seqHint !== void 0,
|
|
3912
|
+
mode: buildInfo.mode,
|
|
3913
|
+
sourceFileCount: buildInfo.sourceFileCount,
|
|
3914
|
+
sourceFileCountTruncated: buildInfo.sourceFileCountTruncated,
|
|
3915
|
+
pathNormalizeCalls: buildInfo.pathNormalizeCalls
|
|
3916
|
+
})
|
|
3917
|
+
}
|
|
3918
|
+
});
|
|
3919
|
+
}
|
|
3920
|
+
return graph;
|
|
3921
|
+
}).catch((err) => {
|
|
3922
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
3923
|
+
const wasmFailure = classifyTreeSitterWasmError(err);
|
|
3924
|
+
recordBuildAttempt(cwd, "failed", reason, buildId);
|
|
3925
|
+
logReviewGraph({
|
|
3926
|
+
cwd,
|
|
3927
|
+
phase: "build_failed",
|
|
3928
|
+
// #3605: an internal wasm failure, not a failed build.
|
|
3929
|
+
failureClass: wasmFailure ? `wasm-${wasmFailure}` : "error",
|
|
3930
|
+
reason,
|
|
3931
|
+
durationMs: Date.now() - startedAt,
|
|
3932
|
+
error: reason,
|
|
3933
|
+
observability: {
|
|
3934
|
+
graph: {
|
|
3935
|
+
buildId,
|
|
3936
|
+
...seqHint === void 0 ? {} : { seqHint: true },
|
|
3937
|
+
nodes: 0,
|
|
3938
|
+
edges: 0
|
|
3939
|
+
}
|
|
3940
|
+
}
|
|
3941
|
+
});
|
|
3942
|
+
throw err;
|
|
3943
|
+
});
|
|
3944
|
+
_buildCache.set(cacheKey, promise);
|
|
3945
|
+
const release = () => {
|
|
3946
|
+
if (_buildCache.get(cacheKey) === promise)
|
|
3947
|
+
_buildCache.delete(cacheKey);
|
|
3948
|
+
};
|
|
3949
|
+
promise.then(release, release);
|
|
3950
|
+
return promise;
|
|
3951
|
+
}
|
|
3952
|
+
function extractSymbolsAndRefsFromGraph(graph) {
|
|
3953
|
+
const allSymbols = /* @__PURE__ */ new Map();
|
|
3954
|
+
const allRefs = /* @__PURE__ */ new Map();
|
|
3955
|
+
const nodeSymbols = /* @__PURE__ */ new Map();
|
|
3956
|
+
const coverage = {
|
|
3957
|
+
totalEvidence: 0,
|
|
3958
|
+
callsEvidence: 0,
|
|
3959
|
+
referencesEvidence: 0,
|
|
3960
|
+
eligibleEvidence: 0,
|
|
3961
|
+
resolvedEvidence: 0,
|
|
3962
|
+
unresolvedEvidence: 0,
|
|
3963
|
+
typeOnlyEvidence: 0,
|
|
3964
|
+
unsupportedEvidence: 0,
|
|
3965
|
+
sameFileEvidence: 0,
|
|
3966
|
+
duplicateEvidence: 0,
|
|
3967
|
+
complete: graph.persistCoverage?.partial !== true && graph.persistCoverage?.inProgress !== true,
|
|
3968
|
+
languages: {}
|
|
3969
|
+
};
|
|
3970
|
+
const numberMetadata = (node, key) => {
|
|
3971
|
+
const value = node?.metadata?.[key];
|
|
3972
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
3973
|
+
};
|
|
3974
|
+
const symbolKind = (node) => {
|
|
3975
|
+
switch (node.symbolKind) {
|
|
3976
|
+
case "class":
|
|
3977
|
+
case "interface":
|
|
3978
|
+
case "type":
|
|
3979
|
+
case "variable":
|
|
3980
|
+
case "method":
|
|
3981
|
+
case "property":
|
|
3982
|
+
case "function":
|
|
3983
|
+
return node.symbolKind;
|
|
3984
|
+
default:
|
|
3985
|
+
return "function";
|
|
3986
|
+
}
|
|
3987
|
+
};
|
|
3988
|
+
for (const node of graph.nodes.values()) {
|
|
3989
|
+
if (node.kind !== "symbol" || !node.filePath || !node.symbolName)
|
|
3990
|
+
continue;
|
|
3991
|
+
const sym = {
|
|
3992
|
+
id: node.id,
|
|
3993
|
+
name: node.symbolName,
|
|
3994
|
+
kind: symbolKind(node),
|
|
3995
|
+
filePath: node.filePath,
|
|
3996
|
+
line: numberMetadata(node, "line") ?? 1,
|
|
3997
|
+
endLine: numberMetadata(node, "endLine"),
|
|
3998
|
+
column: numberMetadata(node, "column") ?? 1,
|
|
3999
|
+
isExported: node.exported === true
|
|
4000
|
+
};
|
|
4001
|
+
nodeSymbols.set(node.id, sym);
|
|
4002
|
+
const list = allSymbols.get(node.filePath) ?? [];
|
|
4003
|
+
list.push(sym);
|
|
4004
|
+
allSymbols.set(node.filePath, list);
|
|
4005
|
+
}
|
|
4006
|
+
const addRef = (ref) => {
|
|
4007
|
+
const list = allRefs.get(ref.filePath) ?? [];
|
|
4008
|
+
list.push(ref);
|
|
4009
|
+
allRefs.set(ref.filePath, list);
|
|
4010
|
+
};
|
|
4011
|
+
for (const edge of graph.edges) {
|
|
4012
|
+
if (edge.kind !== "calls" && edge.kind !== "references")
|
|
4013
|
+
continue;
|
|
4014
|
+
coverage.totalEvidence++;
|
|
4015
|
+
if (edge.kind === "calls")
|
|
4016
|
+
coverage.callsEvidence++;
|
|
4017
|
+
else
|
|
4018
|
+
coverage.referencesEvidence++;
|
|
4019
|
+
const fromNode = graph.nodes.get(edge.from);
|
|
4020
|
+
const targetNode = graph.nodes.get(edge.to);
|
|
4021
|
+
const callerFile = fromNode?.kind === "symbol" ? fromNode.filePath : fromNode?.kind === "file" ? fromNode.filePath : edge.from.startsWith("file:") ? edge.from.slice("file:".length) : void 0;
|
|
4022
|
+
if (!callerFile) {
|
|
4023
|
+
coverage.unsupportedEvidence++;
|
|
4024
|
+
continue;
|
|
4025
|
+
}
|
|
4026
|
+
const metadata = edge.metadata ?? {};
|
|
4027
|
+
const referenceKind = edge.kind === "calls" ? "call" : metadata.referenceKind === "call" ? "call" : metadata.referenceKind === "type" ? "type" : "unknown";
|
|
4028
|
+
const resolution = edge.resolution ?? (targetNode && !targetNode.metadata?.unresolvedName ? "exact" : "unresolved");
|
|
4029
|
+
const targetSymbol = nodeSymbols.get(edge.to);
|
|
4030
|
+
const targetName = targetNode?.symbolName ?? (edge.to.startsWith("symbol-name:") ? edge.to.slice("symbol-name:".length) : void 0);
|
|
4031
|
+
const line = typeof metadata.line === "number" ? metadata.line : numberMetadata(fromNode, "line") ?? 1;
|
|
4032
|
+
const column = typeof metadata.column === "number" ? metadata.column : numberMetadata(fromNode, "column") ?? 1;
|
|
4033
|
+
addRef({
|
|
4034
|
+
symbolId: targetName ? `${callerFile}:${targetName}` : edge.to,
|
|
4035
|
+
filePath: callerFile,
|
|
4036
|
+
line,
|
|
4037
|
+
column,
|
|
4038
|
+
evidenceKind: edge.kind,
|
|
4039
|
+
referenceKind,
|
|
4040
|
+
targetId: edge.to,
|
|
4041
|
+
callerSymbolId: fromNode?.kind === "symbol" ? fromNode.id : void 0,
|
|
4042
|
+
resolution,
|
|
4043
|
+
targetName,
|
|
4044
|
+
targetKind: targetNode?.symbolKind,
|
|
4045
|
+
targetFilePath: targetNode?.filePath,
|
|
4046
|
+
targetLine: numberMetadata(targetNode, "line"),
|
|
4047
|
+
targetColumn: numberMetadata(targetNode, "column")
|
|
4048
|
+
});
|
|
4049
|
+
if (referenceKind === "type")
|
|
4050
|
+
coverage.typeOnlyEvidence++;
|
|
4051
|
+
else if (referenceKind !== "call")
|
|
4052
|
+
coverage.unsupportedEvidence++;
|
|
4053
|
+
else if (!targetSymbol || resolution === "name-only" || resolution === "unresolved") {
|
|
4054
|
+
coverage.unresolvedEvidence++;
|
|
4055
|
+
} else {
|
|
4056
|
+
coverage.eligibleEvidence++;
|
|
4057
|
+
coverage.resolvedEvidence++;
|
|
4058
|
+
}
|
|
4059
|
+
}
|
|
4060
|
+
let sawRelevantFileNode = false;
|
|
4061
|
+
for (const node of graph.nodes.values()) {
|
|
4062
|
+
if (node.kind !== "file")
|
|
4063
|
+
continue;
|
|
4064
|
+
sawRelevantFileNode = true;
|
|
4065
|
+
const extraction = node.metadata?.extractionCoverage;
|
|
4066
|
+
const statuses = extraction ? Object.values(extraction) : [];
|
|
4067
|
+
const languageStatus = !extraction || statuses.length === 0 || statuses.includes("unavailable") ? "unavailable" : statuses.includes("partial") ? "partial" : "complete";
|
|
4068
|
+
if (languageStatus !== "complete")
|
|
4069
|
+
coverage.complete = false;
|
|
4070
|
+
if (node.language) {
|
|
4071
|
+
const prior = coverage.languages[node.language];
|
|
4072
|
+
coverage.languages[node.language] = prior === "unavailable" || languageStatus === "unavailable" ? "unavailable" : prior === "partial" || languageStatus === "partial" ? "partial" : languageStatus;
|
|
4073
|
+
}
|
|
4074
|
+
}
|
|
4075
|
+
if (!sawRelevantFileNode)
|
|
4076
|
+
coverage.complete = false;
|
|
4077
|
+
return { allSymbols, allRefs, coverage };
|
|
4078
|
+
}
|
|
4079
|
+
|
|
4080
|
+
export {
|
|
4081
|
+
fileContentProvider,
|
|
4082
|
+
SYMBOL_KIND_NAMES,
|
|
4083
|
+
formatReviewGraphRevisionDriftNote,
|
|
4084
|
+
reviewGraphIrContentHash,
|
|
4085
|
+
publishReviewGraphFileIr,
|
|
4086
|
+
REVIEW_GRAPH_VERSION,
|
|
4087
|
+
_resetReviewGraphSourcePathMemoForTests,
|
|
4088
|
+
graphWasmTrapDetail,
|
|
4089
|
+
getGraphBuildInfoForGraph,
|
|
4090
|
+
graphBuildInfoIsTrustworthy,
|
|
4091
|
+
clearGraphCache,
|
|
4092
|
+
clearReviewGraphWorkspaceCache,
|
|
4093
|
+
_setReviewGraphBuildGateForTests,
|
|
4094
|
+
estimateReviewGraphStoreBytes,
|
|
4095
|
+
getReviewGraphWorkspaceCacheSnapshot,
|
|
4096
|
+
_getReviewGraphWorkspaceCacheKeysForTests,
|
|
4097
|
+
_setReviewGraphWorkspaceEntryForTests,
|
|
4098
|
+
_setSessionReviewGraphFactForTests,
|
|
4099
|
+
_persistedCoverageForTests,
|
|
4100
|
+
_getReviewGraphWorkspaceGraphForTests,
|
|
4101
|
+
_getReviewGraphCacheStateForTests,
|
|
4102
|
+
getReviewGraphCacheIdentity,
|
|
4103
|
+
_resetCwdWorktreeMismatchLogForTests,
|
|
4104
|
+
getLastGraphBuildInfo,
|
|
4105
|
+
_setLastGraphBuildInfoForTests,
|
|
4106
|
+
getCachedReviewGraph,
|
|
4107
|
+
getReviewGraphRevisionDrift,
|
|
4108
|
+
_resetReviewGraphSizeSkipTtlForTests,
|
|
4109
|
+
getLastReviewGraphBuildAttempt,
|
|
4110
|
+
_resetReviewGraphBuildAttemptsForTests,
|
|
4111
|
+
_resetReviewGraphSizeSkipVerdictsForTests,
|
|
4112
|
+
getReviewGraphSizeSkipVerdict,
|
|
4113
|
+
_setReviewGraphEntryBudgetForTests,
|
|
4114
|
+
_setReviewGraphEntryCounterForTests,
|
|
4115
|
+
getGraphSourceFiles,
|
|
4116
|
+
isReviewGraphMigrationNeeded,
|
|
4117
|
+
GRAPH_PERSIST_MAX_ELEMENTS_DEFAULT,
|
|
4118
|
+
refreshReviewGraphPersistWorkerHeapStatistics,
|
|
4119
|
+
getReviewGraphPersistWorkerHeapStatistics,
|
|
4120
|
+
flushReviewGraphPersistsForExitForTests,
|
|
4121
|
+
_resetReviewGraphStageSweepForTests,
|
|
4122
|
+
_readReviewGraphCheckpointForTests,
|
|
4123
|
+
flushReviewGraphPersistsForTests,
|
|
4124
|
+
waitForReviewGraphPersistsForTests,
|
|
4125
|
+
terminateReviewGraphPersistWorkerForTests,
|
|
4126
|
+
resetReviewGraphPersistWorkerForTests,
|
|
4127
|
+
getCheckpointOffloadCountForTests,
|
|
4128
|
+
getReviewGraphWorkerFallbackReasonForTests,
|
|
4129
|
+
reviewGraphCachePath,
|
|
4130
|
+
flushReviewGraphPersist,
|
|
4131
|
+
mapKindToTreeSitterLanguage,
|
|
4132
|
+
captureReviewGraphStructuralIr,
|
|
4133
|
+
_getReviewGraphRebuildCountersForTests,
|
|
4134
|
+
_resetReviewGraphRebuildCountersForTests,
|
|
4135
|
+
getGraphImportChanges,
|
|
4136
|
+
isGraphBuildInFlight,
|
|
4137
|
+
buildOrUpdateGraph,
|
|
4138
|
+
extractSymbolsAndRefsFromGraph
|
|
4139
|
+
};
|