scip-query 0.23.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +491 -2
- package/README.md +111 -122
- package/dist/augment-vue-worker.js +1 -1
- package/dist/by-kind-PRVFAGTQ.js +2 -0
- package/dist/call-graph-DVPAQV2F.js +2 -0
- package/dist/call-graph-evidence-CUtj8V2I.d.ts +19 -0
- package/dist/chunk-2FSBGL5P.js +2 -0
- package/dist/chunk-2HLAFUCY.js +2 -0
- package/dist/chunk-2IWUT6CJ.js +3 -0
- package/dist/chunk-2KNN7GTQ.js +2 -0
- package/dist/chunk-2LHXRE2B.js +8 -0
- package/dist/{chunk-EG2CPZMJ.js → chunk-2YXE77TJ.js} +2 -2
- package/dist/chunk-36SGVCGX.js +2 -0
- package/dist/chunk-3ABBFPTP.js +2 -0
- package/dist/chunk-3IVFU4FD.js +3 -0
- package/dist/chunk-3JIQS44J.js +7 -0
- package/dist/chunk-3ZRB6DNK.js +7 -0
- package/dist/{chunk-6YTSKJJ3.js → chunk-42EOW5VI.js} +1 -1
- package/dist/{chunk-6I6L7Z62.js → chunk-4BHGBMNO.js} +2 -2
- package/dist/chunk-4BP3UBDG.js +2 -0
- package/dist/chunk-4D6RO7G4.js +2 -0
- package/dist/chunk-4FEWQ6RH.js +2 -0
- package/dist/chunk-4IGEOBG7.js +2 -0
- package/dist/chunk-4QZXBUKC.js +2 -0
- package/dist/chunk-4WBDEVX2.js +4 -0
- package/dist/chunk-4WCUBZU3.js +8 -0
- package/dist/chunk-4WTUBQ36.js +40 -0
- package/dist/chunk-4XQ4O6IM.js +3 -0
- package/dist/chunk-55UQAMZO.js +4 -0
- package/dist/chunk-5D2LVK7O.js +125 -0
- package/dist/chunk-5IYJ56TT.js +2 -0
- package/dist/chunk-5PLMJC7Q.js +2 -0
- package/dist/chunk-5TNQJUR2.js +5 -0
- package/dist/chunk-62BDNPMI.js +2 -0
- package/dist/chunk-64DZ5TXR.js +7 -0
- package/dist/chunk-65245JCM.js +2 -0
- package/dist/chunk-6FFVZZL4.js +2 -0
- package/dist/chunk-6KO5JHAR.js +2 -0
- package/dist/chunk-6LRXOOSX.js +2 -0
- package/dist/chunk-6LSEIIF7.js +2 -0
- package/dist/chunk-6YMNWD3H.js +6 -0
- package/dist/chunk-72AD6ZRR.js +5 -0
- package/dist/chunk-73AAKPUC.js +4 -0
- package/dist/chunk-76CZ77DF.js +2 -0
- package/dist/chunk-7VPEEAAG.js +2 -0
- package/dist/chunk-7WTPQ4NX.js +14 -0
- package/dist/chunk-7Y5T6XDP.js +2 -0
- package/dist/chunk-A2IIGFMJ.js +5 -0
- package/dist/chunk-AB5KCTEV.js +2 -0
- package/dist/chunk-AC566WBP.js +6 -0
- package/dist/chunk-AGWFSTXC.js +3 -0
- package/dist/chunk-AOSIYPTA.js +2 -0
- package/dist/chunk-AUVEWPIF.js +2 -0
- package/dist/chunk-B56T42J3.js +25 -0
- package/dist/chunk-BIQEF5NE.js +2 -0
- package/dist/chunk-BL6XJKTA.js +3 -0
- package/dist/chunk-BMKOQJRI.js +2 -0
- package/dist/chunk-BOZ4EXBB.js +3 -0
- package/dist/chunk-BUTWYEPH.js +2 -0
- package/dist/chunk-BZB4QPIP.js +2 -0
- package/dist/{chunk-ILTDAWEF.js → chunk-CE357GEE.js} +4 -4
- package/dist/chunk-CFN45HFP.js +2 -0
- package/dist/chunk-CFYMZFXT.js +368 -0
- package/dist/chunk-CN5EH7O3.js +2 -0
- package/dist/chunk-D254DNNQ.js +4 -0
- package/dist/chunk-D3FDISIC.js +2 -0
- package/dist/chunk-D3NX5XIE.js +3 -0
- package/dist/chunk-DA7RPPDF.js +3 -0
- package/dist/chunk-DDMC3FON.js +3 -0
- package/dist/chunk-DIO3FUSG.js +2 -0
- package/dist/chunk-DJ2NNSUK.js +3 -0
- package/dist/chunk-DKYQIM3C.js +18 -0
- package/dist/{chunk-JTQVMR42.js → chunk-DOOEL2IV.js} +2 -2
- package/dist/chunk-DVFP6PZI.js +2 -0
- package/dist/chunk-E3FDPXZK.js +2 -0
- package/dist/chunk-E7YNJLCB.js +2 -0
- package/dist/chunk-EFGW5JPH.js +2 -0
- package/dist/chunk-EJVTR244.js +13 -0
- package/dist/chunk-EOV7RTRZ.js +2 -0
- package/dist/chunk-ETOIKRHO.js +2 -0
- package/dist/chunk-EYK3ZAO2.js +3 -0
- package/dist/chunk-F2V2LPET.js +52 -0
- package/dist/chunk-F4LUHJTF.js +2 -0
- package/dist/chunk-F4PUT6IT.js +2 -0
- package/dist/chunk-F56GCXXS.js +5 -0
- package/dist/chunk-FC2EVQRM.js +2 -0
- package/dist/chunk-FL7NBMHP.js +3 -0
- package/dist/chunk-FMRN2TRL.js +3 -0
- package/dist/chunk-FVULPZDF.js +20 -0
- package/dist/chunk-GCKCF5FL.js +43 -0
- package/dist/chunk-GH2PYF46.js +2 -0
- package/dist/chunk-GHJAGXIP.js +2 -0
- package/dist/{chunk-WIWY3CRX.js → chunk-GMVSHUKZ.js} +2 -2
- package/dist/chunk-GS6KDO4R.js +2 -0
- package/dist/chunk-GUUBXNN7.js +2 -0
- package/dist/chunk-GVWX5T43.js +80 -0
- package/dist/chunk-GZKFETP5.js +2 -0
- package/dist/chunk-H4EQHO6J.js +9 -0
- package/dist/chunk-H73WY2RM.js +2 -0
- package/dist/chunk-H75GSPRV.js +60 -0
- package/dist/chunk-HDR3AHSV.js +61 -0
- package/dist/chunk-HQBSL74Y.js +2 -0
- package/dist/chunk-HRRFKWPZ.js +2 -0
- package/dist/chunk-HXENDJC6.js +2 -0
- package/dist/chunk-IIBAZNSW.js +21 -0
- package/dist/chunk-INLMWEUU.js +12 -0
- package/dist/chunk-IWQPAF4F.js +2 -0
- package/dist/chunk-IZJ6YUKP.js +35 -0
- package/dist/chunk-J2TMAIN5.js +60 -0
- package/dist/chunk-J5FJMODQ.js +142 -0
- package/dist/chunk-J7HZPIO3.js +2 -0
- package/dist/chunk-JEVRKFRL.js +2 -0
- package/dist/chunk-JFXSGAEB.js +30 -0
- package/dist/chunk-JVRTHGFS.js +3 -0
- package/dist/chunk-JYWEX7RR.js +360 -0
- package/dist/chunk-K3YL22N6.js +2 -0
- package/dist/chunk-K4CN7GXK.js +12 -0
- package/dist/chunk-K5TBVXU4.js +30 -0
- package/dist/chunk-KDDIE2DP.js +9 -0
- package/dist/chunk-KHWRRPV4.js +2 -0
- package/dist/chunk-KI6NBKDY.js +14 -0
- package/dist/chunk-KU3QRSTH.js +2 -0
- package/dist/chunk-KZBJWZJB.js +2 -0
- package/dist/chunk-L7GFM3NP.js +3 -0
- package/dist/chunk-LMO6PK3V.js +35 -0
- package/dist/chunk-LN4YXJJU.js +2 -0
- package/dist/chunk-LOVIZBJ4.js +43 -0
- package/dist/chunk-LPCRK4A2.js +11 -0
- package/dist/chunk-MMHZKBFA.js +2 -0
- package/dist/{chunk-M2O5NY6W.js → chunk-MOQQBQRD.js} +2 -2
- package/dist/chunk-N2WN6I3L.js +2 -0
- package/dist/chunk-N3ORQT7L.js +2 -0
- package/dist/chunk-NAZ3RAIW.js +2 -0
- package/dist/chunk-NDUNO5JQ.js +2 -0
- package/dist/chunk-NEIWRNAZ.js +4 -0
- package/dist/chunk-NJJMVD65.js +2 -0
- package/dist/chunk-NLOQOBXI.js +20 -0
- package/dist/chunk-NOLZOVCU.js +2 -0
- package/dist/chunk-NOWINRRN.js +2 -0
- package/dist/chunk-NZAXKGRL.js +16 -0
- package/dist/chunk-O2C4UILI.js +2 -0
- package/dist/chunk-O3RHA6ZT.js +3 -0
- package/dist/chunk-O4UZSPPI.js +3 -0
- package/dist/chunk-OGFV2BUX.js +2 -0
- package/dist/chunk-OZCJXZK6.js +499 -0
- package/dist/chunk-P6ODM7BY.js +2 -0
- package/dist/{chunk-XBGWL66K.js → chunk-PAVGPRHJ.js} +2 -2
- package/dist/chunk-PH52RA7D.js +2 -0
- package/dist/chunk-PKN354TH.js +3 -0
- package/dist/chunk-PWOASWEG.js +11 -0
- package/dist/chunk-QIWXRW72.js +2 -0
- package/dist/chunk-QJRMOK5N.js +2 -0
- package/dist/{chunk-YXPUP5G2.js → chunk-QOIXNWQR.js} +2 -2
- package/dist/chunk-QXEUDXBT.js +3 -0
- package/dist/chunk-QYUVVBMR.js +6 -0
- package/dist/chunk-QZ7KQZRN.js +2 -0
- package/dist/chunk-R6LQBUDH.js +2 -0
- package/dist/chunk-RBS42E55.js +20 -0
- package/dist/chunk-RSJKPCFX.js +26 -0
- package/dist/chunk-S6CZA3MV.js +2 -0
- package/dist/chunk-STMVAHJP.js +2 -0
- package/dist/chunk-SYVPTTVW.js +2 -0
- package/dist/chunk-T3I6NHBH.js +2 -0
- package/dist/chunk-T6DK3ZP7.js +2 -0
- package/dist/chunk-TKD34PHN.js +4 -0
- package/dist/chunk-TNNQFH7W.js +2 -0
- package/dist/chunk-TNV7SSUF.js +2 -0
- package/dist/chunk-TO7ZR3EH.js +8 -0
- package/dist/chunk-TOU3CHK4.js +2 -0
- package/dist/chunk-TRBI4UKT.js +2 -0
- package/dist/chunk-TZCVNCAN.js +4 -0
- package/dist/chunk-U4LZA5LL.js +3 -0
- package/dist/chunk-U5RIG3JP.js +3 -0
- package/dist/chunk-UP5KXN2I.js +2 -0
- package/dist/chunk-UQFR3NDH.js +5 -0
- package/dist/chunk-UXYXF7GV.js +2 -0
- package/dist/chunk-VB3GOKOS.js +2 -0
- package/dist/chunk-VF5JZICY.js +2 -0
- package/dist/chunk-VTY3VK6E.js +2 -0
- package/dist/chunk-VX2O4RIS.js +2 -0
- package/dist/chunk-WKPV2TDZ.js +2 -0
- package/dist/chunk-WOFQ5DTB.js +2 -0
- package/dist/chunk-WS4C6TCK.js +2 -0
- package/dist/chunk-WXU3DGPU.js +2 -0
- package/dist/chunk-X6RMKHJQ.js +81 -0
- package/dist/{chunk-4ILJCCXV.js → chunk-XHMN6ZX7.js} +2 -2
- package/dist/chunk-XHTVFLWW.js +2 -0
- package/dist/chunk-XKIDJCIK.js +2 -0
- package/dist/chunk-XTYTYZPT.js +2 -0
- package/dist/chunk-Y2JHHTTA.js +2 -0
- package/dist/chunk-YGVRMGYN.js +4 -0
- package/dist/chunk-YNQCGEQE.js +2 -0
- package/dist/chunk-YOQVEXVE.js +14 -0
- package/dist/chunk-YRT2WLYY.js +2 -0
- package/dist/chunk-YTAP5Y2G.js +2 -0
- package/dist/chunk-YTYWI7VB.js +2 -0
- package/dist/chunk-YULZRALL.js +2 -0
- package/dist/chunk-Z33WQG4Q.js +2 -0
- package/dist/chunk-ZGTYGDMF.js +16 -0
- package/dist/chunk-ZHMRSZFD.js +43 -0
- package/dist/chunk-ZHSP366W.js +10 -0
- package/dist/chunk-ZIBYCYKK.js +7 -0
- package/dist/{chunk-GAS2LJMP.js → chunk-ZLADLUE6.js} +3 -3
- package/dist/chunk-ZO4YXUT6.js +4 -0
- package/dist/{chunk-HYO3NP5Q.js → chunk-ZR4HBC2H.js} +2 -2
- package/dist/cli-main.js +6 -6
- package/dist/cli.js +1 -1
- package/dist/{code-B17qEMbt.d.ts → code-BNyrCF3_.d.ts} +3 -2
- package/dist/code-IL5WH3NZ.js +2 -0
- package/dist/code-result-json-ANTBEDFP.js +4 -0
- package/dist/command-descriptors-HEEMDHTU.js +222 -0
- package/dist/deps-EOWFC6FD.js +2 -0
- package/dist/direct-navigation-Y5B6OSIQ.js +3 -0
- package/dist/{exploration-topology-BG4v30HZ.d.ts → exploration-topology-CSgEyAz-.d.ts} +3 -1
- package/dist/files-K4AI3JUM.js +2 -0
- package/dist/frontend-profile-roles-D7eCum8P.d.ts +10 -0
- package/dist/{health-CPp2Jf1Z.d.ts → health-BtfmNrfa.d.ts} +58 -74
- package/dist/hierarchy-6W5NDIFI.js +2 -0
- package/dist/imports-WH365QY4.js +2 -0
- package/dist/index.d.ts +13 -1
- package/dist/index.js +1 -1
- package/dist/members-K3PHMF5S.js +2 -0
- package/dist/methods-E7KVMBX4.js +2 -0
- package/dist/output-continuation-command-BJSY67SN.js +3 -0
- package/dist/output-pagination-UZJ5ACIX.js +24 -0
- package/dist/postinstall.js +1 -1
- package/dist/project-reindex-EP24WT4X.js +3 -0
- package/dist/queries/affected.js +1 -1
- package/dist/queries/architecture.d.ts +15 -4
- package/dist/queries/architecture.js +1 -1
- package/dist/queries/bottlenecks.js +1 -1
- package/dist/queries/by-kind.js +1 -1
- package/dist/queries/call-graph.d.ts +3 -1
- package/dist/queries/call-graph.js +1 -1
- package/dist/queries/change-surface.d.ts +1 -0
- package/dist/queries/change-surface.js +1 -1
- package/dist/queries/cleanup-plan.d.ts +3 -3
- package/dist/queries/cleanup-plan.js +1 -1
- package/dist/queries/co-change.d.ts +20 -2
- package/dist/queries/co-change.js +1 -1
- package/dist/queries/code.d.ts +1 -1
- package/dist/queries/code.js +1 -1
- package/dist/queries/complexity.d.ts +6 -3
- package/dist/queries/complexity.js +1 -1
- package/dist/queries/context.d.ts +1 -7
- package/dist/queries/context.js +1 -1
- package/dist/queries/coupling.js +1 -1
- package/dist/queries/cycles.js +1 -1
- package/dist/queries/dead.d.ts +2 -0
- package/dist/queries/dead.js +1 -1
- package/dist/queries/decorative-checkers.js +1 -1
- package/dist/queries/dependence-slice.d.ts +46 -22
- package/dist/queries/dependence-slice.js +1 -1
- package/dist/queries/dependency-depth.d.ts +1 -7
- package/dist/queries/dependency-depth.js +1 -1
- package/dist/queries/deps.js +1 -1
- package/dist/queries/diff-impact.d.ts +3 -1
- package/dist/queries/diff-impact.js +1 -1
- package/dist/queries/doc-drift.js +1 -1
- package/dist/queries/drift.d.ts +1 -1
- package/dist/queries/drift.js +1 -1
- package/dist/queries/duplicate-bodies.d.ts +29 -2
- package/dist/queries/duplicate-bodies.js +1 -1
- package/dist/queries/entry-map.d.ts +2 -4
- package/dist/queries/entry-map.js +1 -1
- package/dist/queries/evidence.d.ts +121 -61
- package/dist/queries/evidence.js +1 -1
- package/dist/queries/fan.js +1 -1
- package/dist/queries/files.js +1 -1
- package/dist/queries/health.d.ts +1 -1
- package/dist/queries/health.js +1 -1
- package/dist/queries/hierarchy.d.ts +2 -2
- package/dist/queries/hierarchy.js +1 -1
- package/dist/queries/hotspots.d.ts +1 -1
- package/dist/queries/hotspots.js +1 -1
- package/dist/queries/imports.d.ts +1 -0
- package/dist/queries/imports.js +1 -1
- package/dist/queries/incomplete-migration.d.ts +3 -3
- package/dist/queries/incomplete-migration.js +1 -1
- package/dist/queries/index.d.ts +17 -65
- package/dist/queries/index.js +1 -1
- package/dist/queries/locality-candidates.d.ts +4 -4
- package/dist/queries/locality-candidates.js +1 -1
- package/dist/queries/members.d.ts +2 -2
- package/dist/queries/members.js +1 -1
- package/dist/queries/methods.js +1 -1
- package/dist/queries/not-implemented.d.ts +2 -6
- package/dist/queries/not-implemented.js +1 -1
- package/dist/queries/outline.js +1 -1
- package/dist/queries/passthrough-candidates.d.ts +9 -1
- package/dist/queries/passthrough-candidates.js +1 -1
- package/dist/queries/react-component-duplicates.d.ts +19 -3
- package/dist/queries/react-component-duplicates.js +1 -1
- package/dist/queries/react-hook-candidates.d.ts +22 -3
- package/dist/queries/react-hook-candidates.js +1 -1
- package/dist/queries/react-large-component-pressure.d.ts +17 -3
- package/dist/queries/react-large-component-pressure.js +1 -1
- package/dist/queries/recent-duplicates.js +1 -1
- package/dist/queries/redundant-reexports.d.ts +4 -14
- package/dist/queries/redundant-reexports.js +1 -1
- package/dist/queries/refs.d.ts +4 -1
- package/dist/queries/refs.js +1 -1
- package/dist/queries/review.d.ts +188 -0
- package/dist/queries/review.js +2 -0
- package/dist/queries/similar-files.d.ts +7 -10
- package/dist/queries/similar-files.js +1 -1
- package/dist/queries/similar-signatures.js +1 -1
- package/dist/queries/similar.d.ts +19 -1
- package/dist/queries/similar.js +1 -1
- package/dist/queries/slice-cohesion.d.ts +205 -0
- package/dist/queries/slice-cohesion.js +2 -0
- package/dist/queries/source-inspection.d.ts +6 -202
- package/dist/queries/source-inspection.js +1 -1
- package/dist/queries/source-search.d.ts +2 -3
- package/dist/queries/source-search.js +1 -1
- package/dist/queries/stats.d.ts +1 -0
- package/dist/queries/stats.js +1 -1
- package/dist/queries/surface.js +1 -1
- package/dist/queries/symbols.js +1 -1
- package/dist/queries/system.d.ts +4 -2
- package/dist/queries/system.js +1 -1
- package/dist/queries/test-quality.d.ts +1 -1
- package/dist/queries/test-quality.js +1 -1
- package/dist/queries/twin-drift.d.ts +23 -7
- package/dist/queries/twin-drift.js +1 -1
- package/dist/queries/unused-imports.js +1 -1
- package/dist/queries/unused-params.d.ts +3 -15
- package/dist/queries/unused-params.js +1 -1
- package/dist/queries/vue-component-duplicates.js +1 -1
- package/dist/queries/vue-composable-candidates.js +1 -1
- package/dist/queries/vue-large-view-pressure.js +1 -1
- package/dist/query-service-fastpath.js +5 -5
- package/dist/query-service-server.js +4 -4
- package/dist/refs-CCBJG7WK.js +2 -0
- package/dist/refs-pagination-DRNLVU4S.js +2 -0
- package/dist/reindex-worker.js +79 -29
- package/dist/reindex.js +45 -45
- package/dist/repository-cache-worker.js +2 -0
- package/dist/runtime.d.ts +8 -8
- package/dist/runtime.js +3 -4
- package/dist/rust-semantic-session-server.js +1 -1
- package/dist/rust-semantic-session-worker.js +1 -1
- package/dist/rust-semantic-worker.js +1 -1
- package/dist/service-queries-2WAJI7R6.js +6 -0
- package/dist/source-inspection-91U9zdO3.d.ts +341 -0
- package/dist/{source-search-types-Dwz8KeuW.d.ts → source-search-types-DWGYNg8M.d.ts} +15 -2
- package/dist/stats-G7DIV6VU.js +2 -0
- package/dist/surface-IO55UALI.js +2 -0
- package/dist/system-ZBMSHJXU.js +2 -0
- package/dist/{queries/trace.d.ts → trace-BMjw3prn.d.ts} +1 -18
- package/dist/typescript-indexer.js +2 -0
- package/dist/typescript-mailbox-worker.js +1 -1
- package/dist/watch-server.js +3 -3
- package/docs/AGENT_GUIDE.md +19 -128
- package/docs/CLI_JSON_OUTPUT.md +21 -17
- package/docs/COMMAND_REFERENCE.md +34 -49
- package/docs/CURRENT_COMMANDS.md +123 -0
- package/docs/DETECTOR_EVIDENCE_CONTRACTS.md +0 -40
- package/docs/DETECTOR_GUIDE.md +55 -12
- package/docs/PRODUCT_VISION.md +135 -0
- package/docs/PROPERTY_TESTING.md +73 -0
- package/docs/REVIEW.md +76 -0
- package/docs/SKILLS.md +51 -0
- package/docs/WINDOWS_SIDECAR_RELEASE.md +12 -3
- package/docs/accuracy-audit-checklist.md +70 -13
- package/docs/analyzer-inventory.md +2 -2
- package/docs/locality-analyzer-design.md +9 -9
- package/package.json +18 -80
- package/scripts/evidence-product-contract.mjs +7 -3
- package/scripts/record-review-coverage.mjs +118 -0
- package/scripts/scip-windows-provenance.mjs +29 -19
- package/skills/scip-architecture-review/SKILL.md +57 -0
- package/skills/scip-architecture-review/agents/openai.yaml +4 -0
- package/skills/scip-architecture-review/references/design-checks.md +17 -0
- package/skills/scip-explore/SKILL.md +15 -59
- package/skills/scip-explore/agents/openai.yaml +3 -3
- package/skills/scip-explore/references/external-evidence.md +2 -2
- package/skills/scip-explore/references/information-model.md +26 -29
- package/skills/scip-explore/scripts/capture-evidence.mjs +68 -34
- package/skills/scip-integrity-audit/SKILL.md +53 -181
- package/skills/scip-integrity-audit/agents/openai.yaml +3 -3
- package/skills/scip-integrity-audit/references/integrity-probes.md +27 -0
- package/skills/scip-plan/SKILL.md +39 -65
- package/skills/scip-plan/agents/openai.yaml +2 -2
- package/skills/scip-query/SKILL.md +28 -81
- package/skills/scip-query/agents/openai.yaml +2 -2
- package/skills/scip-query/references/command-guide.md +169 -0
- package/skills/scip-setup/SKILL.md +4 -2
- package/skills/scip-setup/agents/openai.yaml +3 -3
- package/dist/by-kind-XI2CSWEY.js +0 -2
- package/dist/call-graph-UONR6JR5.js +0 -2
- package/dist/call-graph-evidence-lZa2dwQA.d.ts +0 -11
- package/dist/chunk-26CT72HM.js +0 -2
- package/dist/chunk-2E7CX53V.js +0 -2
- package/dist/chunk-2GRUZAQF.js +0 -43
- package/dist/chunk-2LDBDR6J.js +0 -29
- package/dist/chunk-2OOY75BW.js +0 -2
- package/dist/chunk-2R3V3PSD.js +0 -4
- package/dist/chunk-2WC2OEDO.js +0 -4
- package/dist/chunk-35NLDRZC.js +0 -2
- package/dist/chunk-3AF4TUFK.js +0 -3
- package/dist/chunk-3D3QG236.js +0 -2
- package/dist/chunk-3FHOF22C.js +0 -21
- package/dist/chunk-3JKSW6LJ.js +0 -2
- package/dist/chunk-3L2ZBPEX.js +0 -133
- package/dist/chunk-3PJABJSU.js +0 -2
- package/dist/chunk-3SVF22I5.js +0 -2
- package/dist/chunk-3WR4E3A3.js +0 -3
- package/dist/chunk-4FTZ4P5G.js +0 -2
- package/dist/chunk-4UX2F3JX.js +0 -2
- package/dist/chunk-4WNW27SX.js +0 -2
- package/dist/chunk-5ENOG4VP.js +0 -61
- package/dist/chunk-64BFSI5I.js +0 -2
- package/dist/chunk-66DVSJQG.js +0 -455
- package/dist/chunk-6HFCYNYE.js +0 -9
- package/dist/chunk-6PQNKL3G.js +0 -3
- package/dist/chunk-6V5CNXL6.js +0 -2
- package/dist/chunk-6VVV4WRR.js +0 -4
- package/dist/chunk-7BWFZPPZ.js +0 -2
- package/dist/chunk-7CYG22FH.js +0 -2
- package/dist/chunk-7F45LJKI.js +0 -2
- package/dist/chunk-7IWV2EG3.js +0 -3
- package/dist/chunk-7KCZELVM.js +0 -2
- package/dist/chunk-AFHTBORT.js +0 -2
- package/dist/chunk-AVRYW5OZ.js +0 -2
- package/dist/chunk-B3X6KU75.js +0 -2
- package/dist/chunk-B5D7QPBE.js +0 -4
- package/dist/chunk-BBCIS4DX.js +0 -16
- package/dist/chunk-BDUVI7TO.js +0 -3
- package/dist/chunk-BE7ZZTMC.js +0 -2
- package/dist/chunk-BHVUJOCQ.js +0 -3
- package/dist/chunk-BJT7LSPK.js +0 -3
- package/dist/chunk-BKVWUP7Y.js +0 -2
- package/dist/chunk-BQGB4HBD.js +0 -2
- package/dist/chunk-BRV7PIFF.js +0 -2
- package/dist/chunk-CEEZJXEF.js +0 -2
- package/dist/chunk-CIYLO6SI.js +0 -7
- package/dist/chunk-CJZXN4NU.js +0 -2
- package/dist/chunk-CNO7TOKL.js +0 -2
- package/dist/chunk-COF23M5F.js +0 -2
- package/dist/chunk-CWFP7GM5.js +0 -2
- package/dist/chunk-D2DHWI3D.js +0 -2
- package/dist/chunk-D4N5SQ2M.js +0 -4
- package/dist/chunk-DBRSYFXR.js +0 -2
- package/dist/chunk-DHUIOLDT.js +0 -2
- package/dist/chunk-DIRJWYBM.js +0 -6
- package/dist/chunk-DIUFNHRJ.js +0 -35
- package/dist/chunk-DRENNWRG.js +0 -2
- package/dist/chunk-DTZCKZEU.js +0 -4
- package/dist/chunk-DULC3QFP.js +0 -5
- package/dist/chunk-DYGHBZ2N.js +0 -16
- package/dist/chunk-E5R6AQ73.js +0 -40
- package/dist/chunk-E73UNJTF.js +0 -38
- package/dist/chunk-EKV5HX33.js +0 -2
- package/dist/chunk-EQHFIL6T.js +0 -3
- package/dist/chunk-ESIQ66Z7.js +0 -2
- package/dist/chunk-EVFUMY4R.js +0 -3
- package/dist/chunk-F7DY272B.js +0 -2
- package/dist/chunk-FBN2FGXG.js +0 -2
- package/dist/chunk-FDLOBR6P.js +0 -4
- package/dist/chunk-FESCRNVV.js +0 -5
- package/dist/chunk-FFRKR4EQ.js +0 -2
- package/dist/chunk-FGA2U4OR.js +0 -8
- package/dist/chunk-FIQRSHVM.js +0 -2
- package/dist/chunk-FPYLNQPT.js +0 -2
- package/dist/chunk-FRUSVINH.js +0 -2
- package/dist/chunk-GSP44ENC.js +0 -2
- package/dist/chunk-GUFSG5TX.js +0 -2
- package/dist/chunk-GYIZ4NXB.js +0 -2
- package/dist/chunk-GZIUDL6G.js +0 -2
- package/dist/chunk-H5EXS3HM.js +0 -2
- package/dist/chunk-HCXEQRFF.js +0 -18
- package/dist/chunk-HEHOQQKH.js +0 -2
- package/dist/chunk-HKGFPJ4T.js +0 -4
- package/dist/chunk-HLZTEXRA.js +0 -2
- package/dist/chunk-HOENASQM.js +0 -3
- package/dist/chunk-HVF5VBG6.js +0 -2
- package/dist/chunk-I55I7XXP.js +0 -2
- package/dist/chunk-IDFEUFKS.js +0 -2
- package/dist/chunk-IHGQTTVW.js +0 -2
- package/dist/chunk-IICPE7B2.js +0 -20
- package/dist/chunk-IL676XCC.js +0 -18
- package/dist/chunk-IW5XQG5G.js +0 -2
- package/dist/chunk-IZDPJ2QI.js +0 -2
- package/dist/chunk-J66VOFW6.js +0 -5
- package/dist/chunk-JFMEXGFE.js +0 -2
- package/dist/chunk-JGKUET5J.js +0 -3
- package/dist/chunk-JS4PGXMV.js +0 -3
- package/dist/chunk-JWTGMPIT.js +0 -80
- package/dist/chunk-JYR66JN5.js +0 -5
- package/dist/chunk-KFOYCQAJ.js +0 -9
- package/dist/chunk-KLFEXGQA.js +0 -2
- package/dist/chunk-KMVGRIO2.js +0 -2
- package/dist/chunk-KYSDI3GE.js +0 -5
- package/dist/chunk-L6PJPETJ.js +0 -29
- package/dist/chunk-LDVT66YM.js +0 -2
- package/dist/chunk-LEECKFCJ.js +0 -2
- package/dist/chunk-LMZ5PRUV.js +0 -2
- package/dist/chunk-LQRQN2XA.js +0 -2
- package/dist/chunk-LXABEJX3.js +0 -2
- package/dist/chunk-MNV5FSBW.js +0 -3
- package/dist/chunk-MPQ4OTBM.js +0 -2
- package/dist/chunk-MTDBHTSF.js +0 -2
- package/dist/chunk-MV3CDXPI.js +0 -38
- package/dist/chunk-MWN53KRN.js +0 -60
- package/dist/chunk-MXNGIEPU.js +0 -3
- package/dist/chunk-N2ZSIIGR.js +0 -117
- package/dist/chunk-N5B2NILC.js +0 -5
- package/dist/chunk-NJITK2GP.js +0 -2
- package/dist/chunk-NOGJXYFO.js +0 -2
- package/dist/chunk-NOYBFVJA.js +0 -554
- package/dist/chunk-NWQXSFFU.js +0 -3
- package/dist/chunk-ODDUPDP7.js +0 -13
- package/dist/chunk-OLIWTZI3.js +0 -3
- package/dist/chunk-OLNV6I6U.js +0 -2
- package/dist/chunk-OR2E3AGZ.js +0 -2
- package/dist/chunk-OSR2GEHQ.js +0 -2
- package/dist/chunk-OSSESPDX.js +0 -3
- package/dist/chunk-OWOOWNJ5.js +0 -7
- package/dist/chunk-P42EIXTA.js +0 -2
- package/dist/chunk-PJFGPYTU.js +0 -2
- package/dist/chunk-PP7KNN7L.js +0 -2
- package/dist/chunk-PU7T5QYQ.js +0 -2
- package/dist/chunk-PWWAJSKV.js +0 -74
- package/dist/chunk-PZL5T7SU.js +0 -73
- package/dist/chunk-QBE3YX64.js +0 -23
- package/dist/chunk-QGVTFRY2.js +0 -7
- package/dist/chunk-QOJONDS7.js +0 -2
- package/dist/chunk-QU5XRYB5.js +0 -4
- package/dist/chunk-QUU5OBVK.js +0 -11
- package/dist/chunk-RBLQNW26.js +0 -20
- package/dist/chunk-RTQ7NEKG.js +0 -81
- package/dist/chunk-SQXRS7BG.js +0 -4
- package/dist/chunk-SSK6LDPC.js +0 -2
- package/dist/chunk-SZHGTCPP.js +0 -7
- package/dist/chunk-T4N4P2K5.js +0 -16
- package/dist/chunk-TA3QKLLU.js +0 -2
- package/dist/chunk-TEBQMNVI.js +0 -43
- package/dist/chunk-TPFHAQ2G.js +0 -2
- package/dist/chunk-TQPCBMWT.js +0 -5
- package/dist/chunk-TQZV7KV4.js +0 -2
- package/dist/chunk-TRNAEQ6P.js +0 -3
- package/dist/chunk-TY7CRN3Z.js +0 -2
- package/dist/chunk-UHFYCMZO.js +0 -35
- package/dist/chunk-UICY4GTQ.js +0 -7
- package/dist/chunk-UVGEWT4Y.js +0 -26
- package/dist/chunk-UXW33INU.js +0 -29
- package/dist/chunk-VMPRET3I.js +0 -5
- package/dist/chunk-VNLGKHS6.js +0 -6
- package/dist/chunk-VQILFTEH.js +0 -2
- package/dist/chunk-VUPHCS7Y.js +0 -57
- package/dist/chunk-VVZSBTSU.js +0 -23
- package/dist/chunk-VZRNID6A.js +0 -2
- package/dist/chunk-W5OXRYGE.js +0 -7
- package/dist/chunk-W6STWDQI.js +0 -57
- package/dist/chunk-W7CXK74K.js +0 -2
- package/dist/chunk-WB3WYIRE.js +0 -4
- package/dist/chunk-WDNVY4E7.js +0 -20
- package/dist/chunk-WK46TNUM.js +0 -3
- package/dist/chunk-WNTFFKAX.js +0 -12
- package/dist/chunk-WOIKCX6A.js +0 -2
- package/dist/chunk-WUN6KBHV.js +0 -2
- package/dist/chunk-WYCTJDVR.js +0 -2
- package/dist/chunk-WYPL7GF7.js +0 -2
- package/dist/chunk-XDAUYDFT.js +0 -2
- package/dist/chunk-XDQMU3BT.js +0 -2
- package/dist/chunk-XFA4SSO3.js +0 -3
- package/dist/chunk-XGZEP6GR.js +0 -8
- package/dist/chunk-XPDPNWTQ.js +0 -368
- package/dist/chunk-XRYABF57.js +0 -8
- package/dist/chunk-YBGKCQIS.js +0 -2
- package/dist/chunk-YEN6CYC7.js +0 -16
- package/dist/chunk-YF5IB2LF.js +0 -2
- package/dist/chunk-YI2AWIHC.js +0 -3
- package/dist/chunk-YPWBKGFU.js +0 -2
- package/dist/chunk-YPWHBBIS.js +0 -2
- package/dist/chunk-YSH6U3L4.js +0 -3
- package/dist/chunk-YU5DZUZI.js +0 -10
- package/dist/chunk-YWO5DDRC.js +0 -16
- package/dist/chunk-Z4CDXYNQ.js +0 -2
- package/dist/chunk-ZF5KHH7C.js +0 -2
- package/dist/chunk-ZOHS7AQV.js +0 -21
- package/dist/chunk-ZTI4SBFV.js +0 -3
- package/dist/code-MI6F2TTU.js +0 -2
- package/dist/code-result-json-FXALY4HE.js +0 -2
- package/dist/command-descriptors-P34VABY5.js +0 -343
- package/dist/dataflow-4KEMJPC6.js +0 -2
- package/dist/dependence-slice-R7FPWD5M.js +0 -2
- package/dist/deps-7EMQUYUT.js +0 -2
- package/dist/direct-navigation-6YO234F2.js +0 -3
- package/dist/entry-map-KOOLR26E.js +0 -2
- package/dist/files-OPIPJIGZ.js +0 -2
- package/dist/graph-evidence-Bjyky2V4.d.ts +0 -126
- package/dist/hierarchy-QPD2CAER.js +0 -2
- package/dist/imports-M6HUXRXC.js +0 -2
- package/dist/members-I5MEFOCT.js +0 -2
- package/dist/methods-5JYGGHXA.js +0 -2
- package/dist/next-anchor-candidates-BwMczMvX.d.ts +0 -90
- package/dist/output-continuation-command-UPQAAKBP.js +0 -3
- package/dist/output-pagination-3OFL2MJV.js +0 -19
- package/dist/project-reindex-UKKQ5PLS.js +0 -3
- package/dist/queries/anchors.d.ts +0 -123
- package/dist/queries/anchors.js +0 -2
- package/dist/queries/complexity-hotspots.d.ts +0 -40
- package/dist/queries/complexity-hotspots.js +0 -2
- package/dist/queries/convergence.d.ts +0 -33
- package/dist/queries/convergence.js +0 -2
- package/dist/queries/dataflow.d.ts +0 -77
- package/dist/queries/dataflow.js +0 -2
- package/dist/queries/deep-chains.d.ts +0 -5
- package/dist/queries/deep-chains.js +0 -2
- package/dist/queries/extract-candidates.d.ts +0 -52
- package/dist/queries/extract-candidates.js +0 -2
- package/dist/queries/isolated.d.ts +0 -24
- package/dist/queries/isolated.js +0 -2
- package/dist/queries/plan-context.d.ts +0 -33
- package/dist/queries/plan-context.js +0 -2
- package/dist/queries/reference-neighborhood.d.ts +0 -4
- package/dist/queries/reference-neighborhood.js +0 -2
- package/dist/queries/reference-reachability.d.ts +0 -48
- package/dist/queries/reference-reachability.js +0 -2
- package/dist/queries/self-audit.d.ts +0 -63
- package/dist/queries/self-audit.js +0 -2
- package/dist/queries/similar-chains.d.ts +0 -48
- package/dist/queries/similar-chains.js +0 -2
- package/dist/queries/slice.d.ts +0 -4
- package/dist/queries/slice.js +0 -2
- package/dist/queries/stale-abstractions.d.ts +0 -72
- package/dist/queries/stale-abstractions.js +0 -2
- package/dist/queries/system-map.d.ts +0 -449
- package/dist/queries/system-map.js +0 -2
- package/dist/queries/trace.js +0 -2
- package/dist/queries/twin-ab.d.ts +0 -66
- package/dist/queries/twin-ab.js +0 -2
- package/dist/queries/value-flow.d.ts +0 -43
- package/dist/queries/value-flow.js +0 -2
- package/dist/queries/wrapper-candidates.d.ts +0 -34
- package/dist/queries/wrapper-candidates.js +0 -2
- package/dist/refs-PSU4JZZW.js +0 -2
- package/dist/refs-pagination-JG6CJMRC.js +0 -2
- package/dist/slice-HYRATV64.js +0 -2
- package/dist/source-snippet-_wrcgmZc.d.ts +0 -15
- package/dist/stats-OOJ74B32.js +0 -2
- package/dist/surface-VTGDYWF5.js +0 -2
- package/dist/symbol-resolution-WD5EU5JE.js +0 -2
- package/dist/system-LRQNFOR2.js +0 -2
- package/dist/trace-F4B6OLL4.js +0 -2
- package/dist/value-flow-VRPZY72V.js +0 -2
- package/skills/concrete-plan/SKILL.md +0 -8
- package/skills/concrete-plan/agents/openai.yaml +0 -4
package/dist/watch-server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{b as Ve,c as He,g as ht,j as pt,k as K,l as ft,m as ke}from"./chunk-SZHGTCPP.js";import{a as Y,b as vt,c as Rt}from"./chunk-FIQRSHVM.js";import{a as Pe,b as Pt,c as Tt,d as Ct,e as Te,f as Et,g as Ce,h as Wt,i as Mt,j as At,k as Lt,l as jt,m as _t,n as Gt}from"./chunk-GYIZ4NXB.js";import{a as wt}from"./chunk-MXNGIEPU.js";import{a as bt,c as Q}from"./chunk-BE7ZZTMC.js";import"./chunk-2OOY75BW.js";import{d as B,e as Z,f as $,g as xt}from"./chunk-TY7CRN3Z.js";import"./chunk-DHEQMPLW.js";import{a as ee,b as It,c as kt}from"./chunk-NOGJXYFO.js";import{H as gt,c as j}from"./chunk-IZDPJ2QI.js";import{c as tt,d as ye}from"./chunk-WYPL7GF7.js";import{e as dt}from"./chunk-RTQ7NEKG.js";import{a as me,d as Ke}from"./chunk-GUFSG5TX.js";import{a as ut}from"./chunk-MWN53KRN.js";import"./chunk-IW5XQG5G.js";import"./chunk-3AF4TUFK.js";import{b as ve,g as Re,i as be,m as mt,n as yt,o as we,p as xe,q as Ie,r as St}from"./chunk-FGA2U4OR.js";import{a as M}from"./chunk-B3PYOSCX.js";import"./chunk-H5EXS3HM.js";import"./chunk-HGFDYOVB.js";import{c as T,d as C,e as Ye}from"./chunk-JFMEXGFE.js";import{A as q,E as rt,F as it,I as nt,J as st,K as Se,L as ot,P as at,S as ct,a as ge,c as Xe,ga as lt,t as Qe,u as O,v as Ze,x as et,y as N}from"./chunk-KYSDI3GE.js";import{h as R}from"./chunk-7F45LJKI.js";import v from"process";import{rmSync as yr}from"fs";import{resolve as Li}from"path";import{pathToFileURL as ji}from"url";import{lstatSync as wr}from"fs";function Ft(t,e){let r=te(t);if(r.kind!=="directory")throw new Error(`Watcher root is not a directory: ${t}`);if(!e)return{projectRoot:t,projectDirectory:r};let i=te(e);if(i.kind!=="directory")throw new Error(`Git control path is not a directory: ${e}`);return{projectRoot:t,projectDirectory:r,gitControlDirectory:{path:e,identity:i}}}function Ot(t){try{if(!Dt(t.projectDirectory,te(t.projectRoot)))return!1;let e=t.gitControlDirectory;return!e||Dt(e.identity,te(e.path))}catch{return!1}}function te(t){let e=wr(t,{bigint:!0}),r=e.isDirectory()?"directory":e.isFile()?"file":void 0;if(!r||e.isSymbolicLink())throw new Error(`Unsupported watcher identity path: ${t}`);return{device:e.dev,inode:e.ino,birthtimeNs:e.birthtimeNs,kind:r}}function Dt(t,e){return t.device===e.device&&t.inode===e.inode&&t.birthtimeNs===e.birthtimeNs&&t.kind===e.kind}import{existsSync as Le,lstatSync as Ir,statSync as Xt,watch as kr}from"fs";import{EventEmitter as Pr}from"events";import{basename as Tr,dirname as Kt,isAbsolute as je,join as b,relative as Yt,resolve as Qt}from"path";import{watch as Cr}from"chokidar";import Er from"ignore";var Zt=5e3,ne=class{projectRoot;config;watchConfig;outputDb;languages;pnpmWorkspaces;typescriptProjectMode;typescriptProjects;clojureConfigPath;indexerConcurrency;onStatus;onReindexComplete;onReindexError;onRefreshSuppressed;onError;reindexRunner;subscriptionFactory;budgetInspector;clock;activeOperation=null;stopPromise=null;stopInProgress=!1;status={state:"idle"};debounceTimer=null;cooldownTimer=null;budgetTimer=null;dirty=!1;changedFiles=0;pendingTrigger=null;pendingChanges=new Map;pendingChangesComplete=!0;pendingChangesIncompleteReason;reindexInFlight=!1;lastReindexEnd=0;lastObservedGeneration=null;publishedGeneration;indexFreshness;fsWatchers=[];sourcePollingFallbackStarted=!1;gitPollTimer=null;reconcileTimer=null;lastGitState=null;preferFilesystemGitState=!0;watchGitLayout=null;localCacheWatchPath;gitignoreFilter;extraIgnore;stopped=!1;constructor(e){this.projectRoot=e.projectRoot,this.config=e.config,this.watchConfig=Z(e.config),this.outputDb=e.outputDb??b(Qe(this.projectRoot,e.config),"index.db"),this.preferFilesystemGitState=e.gitReader===void 0,this.localCacheWatchPath=ei(this.projectRoot,Kt(this.outputDb)),this.languages=e.languages,this.pnpmWorkspaces=e.config.indexer?.typescript?.pnpmWorkspaces??!1,this.typescriptProjectMode=e.config.indexer?.typescript?.projectMode,this.typescriptProjects=e.config.indexer?.typescript?.projects,this.clojureConfigPath=e.config.indexer?.clojure?.configPath,this.indexerConcurrency=e.config.indexerConcurrency,this.onStatus=e.onStatus??(()=>{}),this.onReindexComplete=e.onReindexComplete??(()=>{}),this.onReindexError=e.onReindexError??(()=>{}),this.onRefreshSuppressed=e.onRefreshSuppressed??(()=>{}),this.onError=e.onError??(r=>console.error(r.message)),this.clock=e.clock??jr,er.set(this,ti(e.stopTimeoutMs??Zt,"watcher stop timeout")),this.reindexRunner=e.reindexRunner??Ur(),this.subscriptionFactory=e.subscriptionFactory??_r,this.budgetInspector=e.budgetInspector??ft,this.publishedGeneration=e.publishedGeneration??j,this.indexFreshness=e.indexFreshness??Zr,this.lastObservedGeneration=this.readPublishedGeneration(),tr.set(this,{projectRoot:e.projectRoot,config:e.config,gitReader:e.gitReader??rt,languages:ir(e.languages??e.config.languages),typeScriptInputPaths:null,stagedIndexEntries:null}),this.gitignoreFilter=ut(e.projectRoot),this.extraIgnore=Er(),this.watchConfig.ignore.length>0&&this.extraIgnore.add(this.watchConfig.ignore),We(this)}start(){if(this.stopInProgress)throw new Error("Cannot restart a watcher while its previous ownership is still draining.");this.stopped=!1,this.stopPromise=null,ie(this).errors=[],this.sourcePollingFallbackStarted=!1,this.setStatus({state:"idle"}),this.startGitStatePolling();try{this.startSourceWatcher()}catch(e){this.onError(new Error(`Failed to watch ${this.projectRoot}: ${String(e)}`))}}stop(){if(this.stopPromise)return this.stopPromise;this.stopped=!0,this.stopInProgress=!0;let e=this.fsWatchers;this.fsWatchers=[],this.clearDebounceTimer(),this.clearCooldownTimer(),this.clearBudgetTimer(),this.clearGitPollTimer(),this.clearReconcileTimer();let r=this.activeOperation;r&&this.setStatus({state:"draining",startedAt:this.wallNow(),reason:"waiting for the active reindex worker to exit"});let i=[...ie(this).closures],n=Mr(this),s=this.clock.now()+n;return this.stopPromise=this.finishStop(e,i,r,s,n).catch(a=>{throw this.stopInProgress=!1,a}),this.stopPromise}requestRefresh(e,r={}){if(!this.stopped){if(this.markPendingChangesIncomplete(`unstructured-trigger:${e.kind}`),!r.immediate||this.reindexInFlight||this.status.state==="cooldown"||this.status.state==="budget-paused"){this.scheduleReindex(e);return}this.pendingTrigger=Ee(this.pendingTrigger,e),this.changedFiles+=1,this.clearDebounceTimer(),this.triggerReindex()}}startSourceWatcher(e=!1){let r=this.subscriptionFactory(this.projectRoot,{ignoreInitial:!0,ignored:(i,n)=>this.isIgnoredWatchPath(i,n?.isDirectory()??!1),usePolling:e,ignorePermissionErrors:!0,...e?{interval:5e3,binaryInterval:1e4}:{}});r.on("all",(i,n)=>{!this.stopped&&i!=="addDir"&&i!=="unlinkDir"&&this.handleFileChange(i,n)}),r.on("error",i=>this.handleSourceWatcherError(r,i,e)),this.fsWatchers.push(r)}handleSourceWatcherError(e,r,i){if(this.markPendingChangesIncomplete("source-watcher-error"),i||this.sourcePollingFallbackStarted||!Hr(r)||this.stopped){this.onError(new Error(`Failed to watch ${this.projectRoot}: ${String(r)}`));return}this.sourcePollingFallbackStarted=!0,this.fsWatchers=this.fsWatchers.filter(n=>n!==e),Ar(ie(this),e,n=>this.onError(n));try{this.startSourceWatcher(!0)}catch(n){this.onError(new Error(`Failed to watch ${this.projectRoot}: ${String(n)}`))}}isIgnoredWatchPath(e,r){let i=this.relativeWatchPath(e);if(!i)return!1;if($t(i,this.localCacheWatchPath))return!0;let n=r?`${i}/`:i;return this.gitignoreFilter.isIgnored(n)||this.extraIgnore.ignores(n)}handleFileChange(e,r){let i=this.relativeWatchPath(r);if(!i||i===".."||i.startsWith("../")||$t(i,this.localCacheWatchPath)||this.gitignoreFilter.isIgnored(i)||this.extraIgnore.ignores(i)||i.endsWith("index.db")||i.endsWith("index.scip")||i.endsWith("index.db.tmp")||Tr(i).startsWith(ht))return;i===".scipquery.json"&&Jt(this,this.projectRoot);let n=Vt(this,e,i);n!==null&&(n||this.markPendingChangesIncomplete(`unsupported-source-event:${e}`),this.scheduleReindex({kind:"watch-source",detail:i},n?[{path:i,kind:n}]:void 0,n!==void 0))}relativeWatchPath(e){let r=je(e)?e:b(this.projectRoot,e);return Yt(this.projectRoot,r).replaceAll("\\","/")}scheduleReindex(e,r,i=!1){this.pendingTrigger=Ee(this.pendingTrigger,e),i||this.markPendingChangesIncomplete(`unstructured-trigger:${e.kind}`);for(let s of r??[])this.recordPendingChange(s);if(this.changedFiles++,this.reindexInFlight){this.dirty=!0,this.setStatus({state:"indexing",startedAt:this.status.startedAt});let s=this.activeOperation;s&&_.get(this)!==s&&(_.set(this,s),s.cancel().then(a=>{a.state==="degraded"&&!this.stopped&&this.onError(new Error(a.reason))},a=>{this.stopped||this.onError(a instanceof Error?a:new Error(String(a)))}));return}if(this.status.state==="cooldown"){this.dirty=!0,this.setStatus({state:"cooldown",until:this.status.until,dirty:!0});return}if(this.status.state==="budget-paused"){this.dirty=!0,this.setStatus({...this.status,dirty:!0});return}this.clearDebounceTimer();let n=this.wallNow()+this.watchConfig.debounceMs;this.setStatus({state:"waiting",changedFiles:this.changedFiles,reindexAt:n}),this.debounceTimer=this.clock.setTimeout(()=>{this.debounceTimer=null,this.triggerReindex()},this.watchConfig.debounceMs)}triggerReindex(){if(this.reindexInFlight||this.stopped||this.reconcileExternalPublication())return;let e=this.inspectBudget(),r=this.watchConfig.allowExpensiveRebuild&&e.state!=="paused";if(e.state==="paused"&&e.reason!=="rebuild-count"){this.dirty=!0;let c=Math.max(this.wallNow()+1,e.until);this.setStatus({state:"budget-paused",until:c,dirty:!0,reason:e.detail,rebuilt:e.rebuilt,estimatedWriteBytes:e.estimatedWriteBytes}),this.clearBudgetTimer(),this.budgetTimer=this.clock.setTimeout(()=>{this.budgetTimer=null,this.dirty&&!this.stopped&&(this.dirty=!1,this.triggerReindex())},Math.min(2147483647,Math.max(1,c-this.wallNow())));return}let i=this.clock.now()-this.lastReindexEnd;if(this.lastReindexEnd>0&&i<this.watchConfig.cooldownMs){let c=this.watchConfig.cooldownMs-i;this.dirty=!0;let l=this.wallNow()+c;this.setStatus({state:"cooldown",until:l,dirty:!0}),this.cooldownTimer=this.clock.setTimeout(()=>{this.cooldownTimer=null,this.dirty&&!this.stopped&&(this.dirty=!1,this.triggerReindex())},c);return}this.reindexInFlight=!0,this.dirty=!1,this.changedFiles=0;let n=this.pendingTrigger??{kind:"watch-source"};this.pendingTrigger=null;let s=this.consumePendingChangeJournal(),a=this.wallNow();this.setStatus({state:"indexing",startedAt:a});let o=this.reindexRunner.start(this.reindexRequest(n,r,s));this.activeOperation=o,o.completion.then(c=>{if(this.reindexInFlight=!1,this.lastReindexEnd=this.clock.now(),re.set(this,0),this.stopped)return;if(_.get(this)===o){if(this.restorePendingChangeJournal(s),this.dirty){let u=this.wallNow()+this.watchConfig.cooldownMs;this.setStatus({state:"cooldown",until:u,dirty:!0}),this.clearCooldownTimer(),this.cooldownTimer=this.clock.setTimeout(()=>{this.cooldownTimer=null,this.dirty&&!this.stopped?(this.dirty=!1,this.triggerReindex()):this.setStatus({state:"idle"})},this.watchConfig.cooldownMs)}else this.setStatus({state:"idle"});return}We(this),this.lastObservedGeneration=this.readPublishedGeneration();let l=!1;try{l=this.onReindexComplete(c,n,{pendingChanges:this.dirty})===!0}catch(u){this.onError(u instanceof Error?u:new Error(String(u)))}if(this.dirty&&!this.stopped){if(l){let d=this.pendingTrigger??{kind:"unknown"};this.dirty=!1,this.changedFiles=0,this.pendingTrigger=null,this.resetPendingChanges(),this.onRefreshSuppressed(d),this.setStatus({state:"idle"});return}let u=this.wallNow()+this.watchConfig.cooldownMs;this.setStatus({state:"cooldown",until:u,dirty:!0}),this.clearCooldownTimer(),this.cooldownTimer=this.clock.setTimeout(()=>{this.cooldownTimer=null,this.dirty&&!this.stopped?(this.dirty=!1,this.triggerReindex()):this.setStatus({state:"idle"})},this.watchConfig.cooldownMs)}else this.setStatus({state:"idle"})}).catch(c=>{if(this.reindexInFlight=!1,this.lastReindexEnd=this.clock.now(),this.stopped)return;let l=c instanceof Error?c:new Error(String(c));this.restorePendingChangeJournal(s);let u=rr(l),d=0;if(u?(d=(re.get(this)??0)+1,re.set(this,d),this.dirty=!0,this.pendingTrigger=Ee(this.pendingTrigger,n)):re.set(this,0),!u&&_.get(this)!==o&&(this.onReindexError(l,n),this.onError(l)),this.dirty){let h=u?$r(this.watchConfig.cooldownMs,d):this.watchConfig.cooldownMs,p=this.wallNow()+h;this.setStatus({state:"cooldown",until:p,dirty:!0}),this.clearCooldownTimer(),this.cooldownTimer=this.clock.setTimeout(()=>{this.cooldownTimer=null,this.dirty&&!this.stopped?(this.dirty=!1,this.triggerReindex()):this.setStatus({state:"idle"})},h);return}this.setStatus({state:"idle"})}).finally(()=>{this.activeOperation===o&&(this.activeOperation=null),_.get(this)===o&&_.delete(this)})}async finishStop(e,r,i,n,s){let a=[],o=e.map(async h=>{try{await h.close()}catch(p){a.push(`watch subscription close failed: ${String(p)}`)}});o.push(...r),i&&o.push((async()=>{try{let h=await i.cancel();h.state==="degraded"&&a.push(h.reason)}catch(h){a.push(`reindex cancellation failed: ${h instanceof Error?h.message:String(h)}`)}})());let c=o.length,l=o.map(h=>h.finally(()=>{c-=1})),u=await Wr(l,n,this.clock),d=ie(this);return a.push(...d.errors),d.errors=[],u?this.stopInProgress=!1:(a.push(`watch shutdown exceeded the ${s}ms deadline with ${c} operation(s) still pending`),Promise.all(l).then(()=>{this.stopInProgress=!1})),a.length>0?(this.setStatus({state:"draining",startedAt:this.wallNow(),reason:a.join("; ")}),{state:"degraded",reasons:a}):(this.setStatus({state:"idle"}),{state:"stopped"})}wallNow(){return this.clock.wallNow?.()??this.clock.now()}inspectBudget(){try{return this.budgetInspector(this.outputDb,this.watchConfig.resourceBudget,new Date(this.wallNow()))}catch(e){return{state:"paused",reason:"activity-evidence",until:this.wallNow()+this.watchConfig.resourceBudget.windowMs,rebuilt:0,estimatedWriteBytes:0,detail:`reindex activity evidence could not be read: ${e instanceof Error?e.message:String(e)}`}}}reindexRequest(e,r=!0,i){return{projectRoot:this.projectRoot,config:this.config,languages:this.languages,pnpmWorkspaces:this.pnpmWorkspaces,typescriptProjectMode:this.typescriptProjectMode,typescriptProjects:this.typescriptProjects,clojureConfigPath:this.clojureConfigPath,indexerConcurrency:this.indexerConcurrency,trigger:e,changeJournal:i,allowExpensiveRebuild:r}}setStatus(e){this.status=e,e.state==="cooldown"||e.state==="budget-paused"?this.armReconcileTimer(e.until):this.clearReconcileTimer(),this.onStatus(e)}recordPendingChange(e){if(this.pendingChanges.size>=1024&&!this.pendingChanges.has(e.path)){this.pendingChanges.clear(),this.markPendingChangesIncomplete("change-entry-limit");return}let r=this.pendingChanges.get(e.path),i=Jr(r,e.kind);i===null?this.pendingChanges.delete(e.path):this.pendingChanges.set(e.path,i)}markPendingChangesIncomplete(e){this.pendingChangesComplete=!1,this.pendingChangesIncompleteReason??=e}consumePendingChangeJournal(){let e=j(this.outputDb),r=[...this.pendingChanges.entries()].map(([a,o])=>({path:a,kind:o})).sort((a,o)=>a.path.localeCompare(o.path)),i=this.pendingChangesComplete,n=this.pendingChangesIncompleteReason;e||(i=!1,n??="accepted-generation-unavailable");let s={version:1,baseGeneration:e,complete:i,...n?{incompleteReason:n}:{},entries:r};return ke(s)||(s={version:1,baseGeneration:e,complete:!1,incompleteReason:"change-journal-byte-limit",entries:[]}),this.resetPendingChanges(),s}restorePendingChangeJournal(e){let r=[...this.pendingChanges.entries()].map(([s,a])=>({path:s,kind:a})),i=this.pendingChangesComplete,n=this.pendingChangesIncompleteReason;this.resetPendingChanges(),e.complete||this.markPendingChangesIncomplete(e.incompleteReason??"failed-reindex");for(let s of e.entries)this.recordPendingChange(s);i||this.markPendingChangesIncomplete(n??"failed-reindex");for(let s of r)this.recordPendingChange(s)}resetPendingChanges(){this.pendingChanges.clear(),this.pendingChangesComplete=!0,this.pendingChangesIncompleteReason=void 0}clearDebounceTimer(){this.debounceTimer&&(this.clock.clearTimeout(this.debounceTimer),this.debounceTimer=null)}clearCooldownTimer(){this.cooldownTimer&&(this.clock.clearTimeout(this.cooldownTimer),this.cooldownTimer=null)}clearBudgetTimer(){this.budgetTimer&&(this.clock.clearTimeout(this.budgetTimer),this.budgetTimer=null)}startGitStatePolling(){this.lastGitState=this.readGitState(),this.lastGitState&&(x(this).stagedIndexEntries=Ht(this.projectRoot,x(this).gitReader),this.gitPollTimer=this.clock.setInterval(()=>this.pollGitState(),this.watchConfig.gitPollMs),this.gitPollTimer.unref?.())}armReconcileTimer(e){this.clearReconcileTimer();let r=e-this.wallNow();if(r<=0||!(this.watchConfig.gitPollMs>0))return;let i=Math.min(this.watchConfig.gitPollMs,r);this.reconcileTimer=this.clock.setTimeout(()=>{this.reconcileTimer=null,!(this.stopped||this.reconcileExternalPublication())&&(this.status.state==="cooldown"||this.status.state==="budget-paused")&&this.armReconcileTimer(this.status.until)},i),this.reconcileTimer.unref?.()}clearReconcileTimer(){this.reconcileTimer&&(this.clock.clearTimeout(this.reconcileTimer),this.reconcileTimer=null)}readPublishedGeneration(){try{return this.publishedGeneration(this.outputDb)}catch{return null}}reconcileExternalPublication(){if(this.stopped||this.reindexInFlight||!(this.dirty||this.status.state==="budget-paused"||this.status.state==="cooldown"||this.status.state==="waiting"))return!1;let r=this.readPublishedGeneration();if(r===null||r===this.lastObservedGeneration)return!1;this.lastObservedGeneration=r;let i;try{i=this.indexFreshness(this.projectRoot,this.config,this.outputDb)}catch{return!1}if(i!=="fresh")return!1;let n=this.pendingTrigger??{kind:"unknown"};return this.clearDebounceTimer(),this.clearCooldownTimer(),this.clearBudgetTimer(),this.dirty=!1,this.changedFiles=0,this.pendingTrigger=null,this.resetPendingChanges(),We(this),this.onRefreshSuppressed({...n,detail:`a generation published outside the watcher is fresh${n.detail?` (${n.detail})`:""}`}),this.setStatus({state:"idle"}),!0}pollGitState(){if(this.reindexInFlight||this.stopped)return;let e=this.lastGitState,r=this.readGitState();if(!e||!r||this.stopped){this.lastGitState=r;return}this.lastGitState=r;let i=e.head!==r.head,n=e.indexPath!==r.indexPath||e.indexMtimeMs!==r.indexMtimeMs||e.indexSize!==r.indexSize;if(!i&&!n)return;let s=x(this),a=s.stagedIndexEntries,o=Ht(this.projectRoot,s.gitReader);s.stagedIndexEntries=o;let c=si(this.projectRoot,s.gitReader,e,r,a,o,i,n),l=null;if(c!==null&&(c.includes(".scipquery.json")&&Jt(this,this.projectRoot),l=c.filter(d=>Vt(this,"add",d)!==null),l.length===0))return;let u=l?.map(d=>({path:d,kind:Le(b(this.projectRoot,d))?"change":"delete"}));i&&n?this.scheduleReindex({kind:"watch-git-state",detail:Me("HEAD and index changed",l)},u,u!==void 0):i?this.scheduleReindex({kind:"watch-git-head",detail:Me("HEAD changed",l)},u,u!==void 0):n&&this.scheduleReindex({kind:"watch-git-index",detail:Me(r.indexPath??"index changed",l)},u,u!==void 0)}readGitState(){if(this.preferFilesystemGitState){let e=this.readFilesystemGitState();if(e)return e}return this.readGitStateFromGit()}readFilesystemGitState(){let e=this.watchGitLayout??Xr(this.projectRoot);if(!e)return null;this.watchGitLayout=e;let r=Kr(e.gitDir);return r?zt(r,e.indexPath):null}readGitStateFromGit(){let e=x(this).gitReader,r=Se(this.projectRoot,["rev-parse","--git-path","index"],e);if(!r)return null;let i=ot(this.projectRoot,r);return zt(Se(this.projectRoot,["rev-parse","--verify","HEAD"],e),i)}clearGitPollTimer(){this.gitPollTimer&&(this.clock.clearInterval(this.gitPollTimer),this.gitPollTimer=null)}};async function Wr(t,e,r){if(t.length===0)return!0;let i=Promise.all(t).then(()=>!0),n=Math.max(0,e-r.now()),s=null,a=new Promise(c=>{s=r.setTimeout(()=>c(!1),n)}),o=await Promise.race([i,a]);return o&&s&&r.clearTimeout(s),o}var qt=new WeakMap,er=new WeakMap,tr=new WeakMap,_=new WeakMap,re=new WeakMap;function ie(t){let e=qt.get(t);if(e)return e;let r={closures:new Set,errors:[]};return qt.set(t,r),r}function Mr(t){return er.get(t)??Zt}function x(t){let e=tr.get(t);if(!e)throw new Error("Watcher input state was not initialized.");return e}function Ar(t,e,r){let i=Promise.resolve().then(()=>e.close()).catch(n=>{let s=`watch subscription close failed during polling fallback: ${String(n)}`;t.errors.push(s),r(new Error(s))});t.closures.add(i),i.then(()=>t.closures.delete(i))}function Lr(t,e=T){let{projectRoot:r,config:i,languages:n,pnpmWorkspaces:s,typescriptProjectMode:a,typescriptProjects:o,clojureConfigPath:c,indexerConcurrency:l,trigger:u}=t,d=B(r),h=Object.keys(d).length>0?d:i,p=N(r,h),m=h.indexer?.typescript,f=h.indexer?.clojure,y=e(process.pid);if(!y)throw new Error(`Could not establish watcher process identity for reindex worker ownership (pid ${process.pid}).`);return{workerPath:new URL("./reindex-worker.js",import.meta.url).pathname,env:{...process.env,SCIP_REINDEX_PROJECT_ROOT:r,SCIP_REINDEX_OUTPUT_SCIP:p.indexPath,SCIP_REINDEX_OUTPUT_DB:p.dbPath,SCIP_REINDEX_LANGUAGES:(h.languages??n)?.join(",")??"",SCIP_REINDEX_INDEXER_CONCURRENCY:String(h.indexerConcurrency??l??""),SCIP_REINDEX_PNPM_WORKSPACES:m?.pnpmWorkspaces??s?"1":"",SCIP_REINDEX_TYPESCRIPT_CONFIG:JSON.stringify({projectMode:m?.projectMode??a,projects:m?.projects??o??[],maxHeapMb:m?.maxHeapMb}),SCIP_REINDEX_CLOJURE_CONFIG_PATH:f?.configPath??c??"",SCIP_REINDEX_TRIGGER_KIND:u.kind,SCIP_REINDEX_TRIGGER_DETAIL:u.detail??"",SCIP_REINDEX_CHANGE_JOURNAL:t.changeJournal?ke(t.changeJournal)??"":"",SCIP_REINDEX_ALLOW_EXPENSIVE:t.allowExpensiveRebuild===!1?"0":"1",SCIP_REINDEX_PROCESS_GROUP_LEADER:"1",SCIP_REINDEX_PARENT_IDENTITY:JSON.stringify(y)}}}var jr={now:C,wallNow:()=>Date.now(),setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t),setInterval:(t,e)=>setInterval(t,e),clearInterval:t=>clearInterval(t)},_r=(t,e)=>Gr(process.platform,e.usePolling)?new Ae(t):Cr(t,e);function Gr(t,e){return t==="darwin"&&e!==!0}var U=class extends Error{constructor(e,r){super(e,r===void 0?void 0:{cause:r}),this.name="RecursiveSourceWatchError"}},Ae=class{events=new Pr;watcher;constructor(e){this.watcher=kr(e,{recursive:!0},(r,i)=>{if(i===null){this.events.emit("error",new U("Recursive source watcher omitted the changed path."));return}let n=b(e,i.toString());this.events.emit("all",Dr(r,n),n)}),this.watcher.on("error",r=>{this.events.emit("error",new U(`Recursive source watcher failed: ${r.message}`,r))})}on=(e,r)=>(this.events.on(e,r),this);close(){this.watcher.close()}};function Dr(t,e){return t==="change"?"change":Le(e)?Xt(e).isDirectory()?"addDir":"add":"unlink"}var Fr=15*6e4,Or=1e3,Nr=64*1024;function qr(){return{stdoutTail:"",stderrTail:"",stdoutTruncated:!1,stderrTruncated:!1}}function Bt(t,e){let r=t instanceof Error?t.message:String(t),i=e.stderrTail.trim()||e.stdoutTail.trim();return i?`${r}
|
|
2
|
-
${i}`:r}function
|
|
3
|
-
`)){if(r.startsWith("#")||r.startsWith("^"))continue;let i=r.indexOf(" ");if(i===-1)continue;let n=r.slice(0,i);if(r.slice(i+1).trim()===e&&_e.test(n))return n.toLowerCase()}}catch{return}}function Zr(t,e,r){let i=Kt(r);return $(t,e,{dbPath:r,metaPath:b(i,"meta.json"),cacheDir:i}).state}function zt(t,e){let r={head:t,indexPath:e};try{let i=Xt(e);r.indexMtimeMs=i.mtimeMs,r.indexSize=i.size}catch{r.indexMtimeMs=void 0,r.indexSize=void 0}return r}function ei(t,e){let r=Yt(t,e).replaceAll("\\","/");if(!(!r||r===".."||r.startsWith("../")))return r}function ti(t,e){if(!Number.isSafeInteger(t)||t<=0)throw new Error(`${e} must be a positive integer.`);return t}function ir(t){return t&&t.length>0?[...t]:me}function Jt(t,e){try{let r=x(t);r.config=B(e),r.languages=ir(r.config.languages)}catch{x(t).languages=me}}function Vt(t,e,r){let i=x(t);if(ge(r,i.languages)==="other")return null;let s=zr(e);if(r===".scipquery.json"||at(r))return i.typeScriptInputPaths=null,s;if(!ri(r,i.languages))return s;let a=i.typeScriptInputPaths;if(!a)return s;let o=a.has(r);if(s!=="add")return o?s:null;if(o)return"change";let c=nr(t);return c?c.has(r)?"add":null:s}function We(t){let e=x(t);if(!e.languages.includes("typescript")){e.typeScriptInputPaths=null;return}let r=ii(e.projectRoot,e.config,e.languages);e.typeScriptInputPaths=r??nr(t)}function nr(t){let e=x(t);if(!e.languages.includes("typescript"))return e.typeScriptInputPaths=null,null;try{let r=e.config.indexer?.typescript,i=ct(e.projectRoot,r?.projectMode,r?.projects);return e.typeScriptInputPaths=i,i}catch{return e.typeScriptInputPaths=null,null}}function ri(t,e){if(!e.includes("typescript"))return!1;let r=ge(t,["typescript","javascript"]);return r==="source"||r==="ambient"}function ii(t,e,r){try{let i=Ke(R(N(t,e).metaPath,"reindex metadata"));if(i.kind!=="supported"&&i.kind!=="legacy")return null;let n=Xe(i.metadata.fingerprint);return!n||!ni(n,r,e)?null:new Set(n.files.map(s=>s.path))}catch{return null}}function ni(t,e,r){let i=lt(e,{pnpmWorkspaces:r.indexer?.typescript?.pnpmWorkspaces,typescriptProjectMode:r.indexer?.typescript?.projectMode,typescriptProjects:r.indexer?.typescript?.projects,clojureConfigPath:r.indexer?.clojure?.configPath});return t.version===i.version&&JSON.stringify([...t.languages].sort())===JSON.stringify(i.languages)&&t.pnpmWorkspaces===i.pnpmWorkspaces&&t.typescriptProjectMode===i.typescriptProjectMode&&JSON.stringify([...t.typescriptProjects].sort())===JSON.stringify(i.typescriptProjects)&&t.clojureConfigPath===i.clojureConfigPath}function si(t,e,r,i,n,s,a,o){let c=new Set;if(a){if(!r.head||!i.head)return null;let l=e.runResult(t,["diff","--name-only","-z","--no-renames","--relative",r.head,i.head,"--"]);if(l.kind!=="success")return null;for(let u of oi(l.output))c.add(u)}if(o){if(n===null||s===null)return null;for(let l of ci(n,s))c.add(l)}return[...c].sort()}function Ht(t,e){let r=e.runResult(t,["diff","--cached","--raw","-z","--no-renames","--relative","--"]);return r.kind==="success"?ai(r.output):null}function oi(t){return t.split("\0").filter(e=>e.length>0)}function ai(t){let e=t.split("\0");if(e.at(-1)===""&&e.pop(),e.length%2!==0)return null;let r=new Map;for(let i=0;i<e.length;i+=2){let n=e[i],s=e[i+1];if(!n.startsWith(":")||!s)return null;r.set(s,n)}return r}function ci(t,e){return[...new Set([...t.keys(),...e.keys()])].filter(i=>t.get(i)!==e.get(i))}function Me(t,e){return e===null?`${t}; changed paths unavailable`:e.length===0?t:e.length===1?e[0]:`${e.length} compiler inputs changed`}import{existsSync as se,lstatSync as z,readdirSync as ar,realpathSync as sr,rmSync as G,statSync as li}from"fs";import{join as S,resolve as J,sep as cr}from"path";var di=3600*1e3,ui=2*1024*1024*1024,oe=300*1e3,hi="gc-state.json",pi="gc.lock";function fi(t){let e=t.leases.filter(o=>o.managed&&!o.live&&!o.busy),r=gi(t.leases,t.locks),i={};for(let o of t.generations)r.has(o.generationId)||(i[o.generationId]=o.unreferencedAt??t.nowMs);let n=t.generations.filter(o=>!r.has(o.generationId)).sort((o,c)=>i[o.generationId]-i[c.generationId]||o.generationId.localeCompare(c.generationId)),s=new Set;for(let o of n)t.nowMs-i[o.generationId]>=t.policy.generationTtlMs&&s.add(o.generationId);let a=t.generations.filter(o=>!s.has(o.generationId)).reduce((o,c)=>o+c.size,0);for(let o of n){if(a<=t.policy.budgetBytes)break;s.has(o.generationId)||(s.add(o.generationId),a-=o.size)}for(let o of s)delete i[o];return{deleteWorktrees:e,deleteGenerations:t.generations.filter(o=>s.has(o.generationId)),deleteLocks:t.locks.filter(o=>!o.live),deleteTemporaries:t.temporaries.filter(o=>!o.live),protectedGenerationIds:[...r].sort(),unreferencedSince:i}}function gi(t,e){let r=new Set(t.filter(i=>i.managed&&(i.live||i.busy)).flatMap(i=>[i.lease.baseGenerationId,i.lease.activeGenerationId]).filter(i=>i!==void 0));for(let i of e)i.live&&r.add(i.generationId);return r}function lr(t,e,r={}){if(!et())return{kind:"disabled"};let i=r.repositoryId===void 0?it(t)?.repositoryId:r.repositoryId;if(!i)return{kind:"unavailable"};let n=S(O(),"repositories",i),s=(r.now??Date.now)(),a=se(n)?dr(t,n,i,e,s,r):{kind:"unavailable"};return mi(t,i,e,s,r),a}function dr(t,e,r,i,n,s){let a=S(e,"gc-state.json"),o=Ri(a);if(!s.force&&o&&n-Date.parse(o.lastSweepAt)<oe)return{kind:"throttled",sweptAt:o.lastSweepAt};let c=tt(e,{now:()=>n});if(!c)return{kind:"busy"};try{let l=yi(t,e,r,o?.unreferencedSince??{}),u=fi({nowMs:n,...l,policy:{generationTtlMs:s.policy?.generationTtlMs??di,budgetBytes:s.policy?.budgetBytes??ui}}),d=0,h=0;for(let f of u.deleteWorktrees){if(!Fe(f.lease))continue;if(!se(f.lease.localCacheDir)){G(f.leasePath,{force:!0}),h+=1;continue}if(!Si(f.lease))continue;let y=ye(S(f.lease.localCacheDir,"cache-lifecycle.lock"));if(y)try{if(Ge(f.lease,!0))continue;try{At({projectRoot:f.lease.projectRoot,cacheDir:f.lease.localCacheDir,cliVersion:i})}catch{continue}if(Ge(f.lease,!0))continue;G(f.lease.localCacheDir,{recursive:!0,force:!0}),G(f.leasePath,{force:!0}),h+=1}finally{y.release()}}for(let f of u.deleteLocks)G(f.path,{force:!0});for(let f of u.deleteTemporaries)G(f.path,{recursive:!0,force:!0});for(let f of u.deleteGenerations)G(f.path,{recursive:!0,force:!0}),d+=f.size;dt(S(e,"evidence.db"));let p={kind:"swept",sweptAt:new Date(n).toISOString(),deletedWorktrees:h,deletedGenerations:u.deleteGenerations.length,deletedBytes:d,protectedGenerations:u.protectedGenerationIds.length},m={version:1,lastSweepAt:p.sweptAt,unreferencedSince:u.unreferencedSince,lastResult:p};return ve(a,m,{spacing:2,trailingNewline:!0}),p}catch(l){return{kind:"failed",error:l instanceof Error?l.message:String(l)}}finally{c.release()}}function mi(t,e,r,i,n){let s=S(O(),"repositories");if(!se(s))return;let a=S(s,hi),o=bi(a);if(!n.force&&o!==void 0&&i-o<oe)return;let c=ye(S(s,pi));if(c)try{for(let l of V(s)){if(l===e||!/^[a-f0-9]{24}$/.test(l))continue;let u=S(s,l),d;try{d=z(u)}catch{continue}if(!d.isDirectory()||d.isSymbolicLink())continue;let h=vi(u)??t;dr(h,u,l,r,i,n)}ve(a,{version:1,lastSweepAt:new Date(i).toISOString()},{spacing:2,trailingNewline:!0})}finally{c.release()}}function yi(t,e,r,i){let n=new Set(st(t).map(l=>J(l.path))),s=[];for(let l of V(S(e,"worktrees"))){if(!l.endsWith(".json"))continue;let u=S(e,"worktrees",l),d=ur(u);if(!d)continue;let h=J(d.projectRoot);s.push({leasePath:u,lease:d,managed:d.repositoryId===r&&Fe(d),live:n.has(h)||se(h),busy:Ge(d)})}let a=[];for(let l of V(S(e,"locks"))){let u=/^([a-f0-9]{64})\.lock$/.exec(l);if(!u)continue;let d=S(e,"locks",l),h=De(d),p=h!==void 0&&M(h),m=u[1];a.push({generationId:m,path:d,live:p})}let o=[],c=[];for(let l of V(S(e,"generations"))){let u=/^\.tmp-(\d+)-/.exec(l);if(u){let p=S(e,"generations",l),m=Number(u[1]);try{c.push({path:p,size:or(p),live:Number.isSafeInteger(m)&&M(m)})}catch{}continue}if(!/^[a-f0-9]{64}$/.test(l))continue;let d=S(e,"generations",l),h;try{h=z(d)}catch{continue}!h.isDirectory()||h.isSymbolicLink()||o.push({generationId:l,path:d,size:or(d),...i[l]===void 0?{}:{unreferencedAt:i[l]}})}return{leases:s,generations:o,locks:a,temporaries:c}}function Fe(t){if(t.ownershipChecksum!==gt(t)||q(t.localCacheDir)!==q(Ze(t.projectRoot)))return!1;let e=q(S(O(),"projects"));return q(t.localCacheDir).startsWith(`${e}${cr}`)}function Si(t){if(!Fe(t))return!1;let e=J(O()),r=J(S(e,"projects")),i=J(t.localCacheDir);try{let n=z(e),s=z(r),a=z(i);if(!n.isDirectory()||n.isSymbolicLink()||!s.isDirectory()||s.isSymbolicLink()||!a.isDirectory()||a.isSymbolicLink())return!1;let o=sr(r);return sr(i).startsWith(`${o}${cr}`)}catch{return!1}}function vi(t){for(let e of V(S(t,"worktrees"))){if(!e.endsWith(".json"))continue;let r=ur(S(t,"worktrees",e));if(r)return r.projectRoot}}function Ge(t,e=!1){for(let i of e?["index.lock"]:["index.lock","cache-lifecycle.lock"]){let n=De(S(t.localCacheDir,i));if(n!==void 0&&M(n))return!0}let r=De(Q(t.localCacheDir).lockPath);return r!==void 0&&M(r)}function ur(t){try{let e=JSON.parse(R(t,"worktree cache lease"));return e.version!==1||typeof e.repositoryId!="string"||typeof e.worktreeId!="string"||typeof e.projectRoot!="string"||e.treeOid!==void 0&&typeof e.treeOid!="string"||typeof e.localCacheDir!="string"||e.baseGenerationId!==void 0&&typeof e.baseGenerationId!="string"||e.activeGenerationId!==void 0&&typeof e.activeGenerationId!="string"||typeof e.ownershipChecksum!="string"||!/^[a-f0-9]{64}$/.test(e.ownershipChecksum)||typeof e.lastAction!="string"||e.lastReason!==void 0&&typeof e.lastReason!="string"||typeof e.lastSeenAt!="string"?null:e}catch{return null}}function De(t){try{let e=JSON.parse(R(t,"watch lock record"));return typeof e.pid=="number"&&Number.isSafeInteger(e.pid)&&e.pid>0?e.pid:void 0}catch{return}}function Ri(t){try{let e=JSON.parse(R(t,"repository cache GC state"));return e.version!==1||typeof e.lastSweepAt!="string"||!Number.isFinite(Date.parse(e.lastSweepAt))||!e.unreferencedSince||typeof e.unreferencedSince!="object"||!e.lastResult?null:e}catch{return null}}function bi(t){try{let e=JSON.parse(R(t,"global repository cache GC state"));if(e.version!==1||typeof e.lastSweepAt!="string")return;let r=Date.parse(e.lastSweepAt);return Number.isFinite(r)?r:void 0}catch{return}}function V(t){try{return ar(t)}catch{return[]}}function or(t){let e=0,r=[t];for(;r.length>0;){let i=r.pop();for(let n of ar(i,{withFileTypes:!0})){let s=S(i,n.name);n.isDirectory()?r.push(s):n.isFile()&&(e+=li(s).size)}}return e}var ae=class{root;now;randomId;retryDelayMs;active;retryNotBeforeMs=0;currentStatus;constructor(e,r={}){this.root=e,this.now=r.now??Date.now,this.randomId=r.randomId,this.retryDelayMs=Math.max(1,Math.floor(r.retryDelayMs??1e3)),this.currentStatus=Ce(e)}initializeAfterOwnershipAcquired(){let e=Et(this.root),r=Wt(this.root,{now:()=>new Date(this.now())});return this.refreshStatus(),{recoveredClaims:e,prunedHistory:r}}observeLegacyRequest(e,r){Pt(this.root,r??"stale index observed by a legacy command",{idempotencyKey:`legacy-activity:${e}`,now:()=>new Date(e)}),this.refreshStatus()}poll(e,r){if(this.active||e.state!=="idle"||this.now()<this.retryNotBeforeMs)return!1;let i=Tt(this.root,{now:()=>new Date(this.now()),...this.randomId?{randomId:this.randomId}:{}});if(this.refreshStatus(),i.requests.length===0)return!1;this.active=i;try{return r(wi(i)),!0}catch(n){throw Te(this.root,i),this.active=void 0,this.retryNotBeforeMs=this.now()+this.retryDelayMs,this.refreshStatus(),n}}completeActive(){return this.active?(Ct(this.root,this.active,()=>new Date(this.now())),this.active=void 0,this.retryNotBeforeMs=0,this.refreshStatus(),!0):!1}failActive(){return this.active?(Te(this.root,this.active),this.active=void 0,this.retryNotBeforeMs=this.now()+this.retryDelayMs,this.refreshStatus(),!0):!1}status(){return{...this.currentStatus}}refreshStatus(){this.currentStatus=Ce(this.root)}};function wi(t){if(t.requests.length===1)return t.requests[0].detail;let r=[...new Set(t.requests.map(i=>i.detail))].slice(0,3).join("; ");return`${t.requests.length} coalesced refresh requests${r?`: ${r}`:""}`.slice(0,2048)}import{randomUUID as Ii}from"crypto";import{rmSync as ki}from"fs";import{Worker as Pi}from"worker_threads";var ce=class{constructor(e){this.options=e;if(this.now=e.now??Date.now,this.setTimer=e.setTimer??setTimeout,this.clearTimer=e.clearTimer??clearTimeout,e.maxWorkerFailureRetries!==void 0&&(!Number.isInteger(e.maxWorkerFailureRetries)||e.maxWorkerFailureRetries<0))throw new Error("Worker maxWorkerFailureRetries must be a non-negative integer.")}options;now;setTimer;clearTimer;worker=null;active=null;activeFailure=null;terminating=null;closed=!1;workerGeneration=0;idleTimer=null;canAccept(){return!this.closed&&this.active===null&&this.terminating===null}hasWorker(){return this.worker!==null}start(e){if(!this.canAccept())return!1;if(this.clearIdleTimer(),e.deadlineAtMs<this.now()){try{this.options.onReject(e,`${this.options.name} request expired before processing.`)}catch(n){this.closed=!0,this.options.onFatal(Oe(n))}return!0}let r=this.ensureWorker(),i=this.deadlineTimer(e);this.active={request:e,timer:i,workerFailureRetries:0,workerFailureReasons:[]};try{r.postMessage({kind:"request",...e})}catch(n){this.failActiveAfterTermination(Ne(n),!0)}return!0}async close(e=`${this.options.name} service is shutting down.`){if(this.closed=!0,this.clearIdleTimer(),this.active){await this.failActiveAfterTermination(e);return}await this.terminateWorker()}ensureWorker(){if(this.worker)return this.worker;let e=this.options.createWorker(),r=++this.workerGeneration;return e.on("message",i=>this.handleMessage(r,i)),e.on("error",i=>{r===this.workerGeneration&&this.failActiveAfterTermination(`${this.options.name} worker failed: ${i.message}`,!0)}),e.on("exit",i=>{r!==this.workerGeneration||this.terminating||(this.worker=null,this.active&&this.failActiveAfterTermination(`${this.options.name} worker exited unexpectedly with code ${i}.`,!0))}),this.worker=e,e}handleMessage(e,r){if(e!==this.workerGeneration||this.closed||!this.active)return;let i=xi(r);if(!i){this.failActiveAfterTermination(`${this.options.name} worker returned an invalid response.`);return}if(i.requestId!==this.active.request.requestId){this.failActiveAfterTermination(`${this.options.name} worker returned a mismatched request identity.`);return}if(this.now()>this.active.request.deadlineAtMs){this.failActiveAfterTermination(`${this.options.name} request expired while it was processing.`);return}let n=this.active,s;try{this.options.onStatus(i.status),i.ok?this.options.onComplete(n.request,i.result,i.status):this.options.onReject(n.request,i.error,i.status),s=this.options.retireAfterResponse?.(i.status)??!1}catch(a){this.closed=!0,this.clearTimer(n.timer),this.options.onFatal(Oe(a));return}this.releaseActive(n),s?this.terminateWorker():this.scheduleIdleTermination()}async failActiveAfterTermination(e,r=!1){if(this.activeFailure){await this.activeFailure;return}let i=this.active;if(!i){await this.terminateWorker();return}this.clearTimer(i.timer),r&&i.workerFailureReasons.push(e);let n=(async()=>{if(!await this.terminateWorker())return;let a=this.options.maxWorkerFailureRetries??0;if(r&&!this.closed&&i.workerFailureRetries<a&&this.now()<=i.request.deadlineAtMs){i.workerFailureRetries+=1;try{let c=this.ensureWorker();i.timer=this.deadlineTimer(i.request),c.postMessage({kind:"request",...i.request});return}catch(c){let l=`Cold Worker retry failed: ${Ne(c)}`;if(i.workerFailureReasons.push(l),e=`${e} ${l}`,!await this.terminateWorker())return}}let o=i.workerFailureReasons.length===0?e:[...new Set([...i.workerFailureReasons,e])].join(" Cold Worker retry: ");try{this.options.onReject(i.request,o)}catch(c){this.closed=!0,this.options.onFatal(Oe(c));return}this.releaseActive(i)})();this.activeFailure=n;try{await n}finally{this.activeFailure===n&&(this.activeFailure=null)}}deadlineTimer(e){let r=Math.max(1,Math.min(2147483647,e.deadlineAtMs-this.now()));return this.setTimer(()=>{this.failActiveAfterTermination(`${this.options.name} request exceeded its deadline.`)},r)}releaseActive(e){this.active===e&&(this.active=null,this.clearTimer(e.timer))}scheduleIdleTermination(){let e=this.options.idleTtlMs;!e||e<=0||this.closed||this.active||!this.worker||(this.clearIdleTimer(),this.idleTimer=this.setTimer(()=>{this.idleTimer=null,!(this.closed||this.active||!this.worker)&&this.terminateWorker()},e))}clearIdleTimer(){this.idleTimer&&(this.clearTimer(this.idleTimer),this.idleTimer=null)}async terminateWorker(){if(this.clearIdleTimer(),this.terminating)return this.terminating;let e=this.worker;if(!e)return!0;this.worker=null;let r=++this.workerGeneration;return this.terminating=(async()=>{try{return await e.terminate(),!0}catch(i){return this.closed=!0,this.options.onFatal(new Error(`${this.options.name} worker termination failed: ${Ne(i)}`,{cause:i})),!1}finally{r===this.workerGeneration&&(this.terminating=null)}})(),this.terminating}};function xi(t){if(!t||typeof t!="object")return null;let e=t;if(e.kind!=="response"||typeof e.requestId!="string"||!("status"in e))return null;if(e.ok===!0){if(!("result"in e)||"error"in e)return null}else if(e.ok===!1){if("result"in e||typeof e.error!="string")return null}else return null;return e}function Oe(t){return t instanceof Error?t:new Error(String(t))}function Ne(t){return t instanceof Error?t.message:String(t)}var Ti=6e4,Ci=10*6e4;function hr(t){let e=t.maxActiveSessions??8,r=t.workerSoftMemoryMb??Wi(t.workerHeapMb),i=()=>({protocolVersion:Y,state:"idle",requests:0,sessionsCreated:0,sessionsReplaced:0,sessionsEvicted:0,activeSessions:0,maxActiveSessions:e,softMemoryLimitBytes:r*1024*1024,retireRequested:!1,initializations:0,programUpdates:0,documentsEmitted:0,documentsRemoved:0});return fr({name:"TypeScript index",paths:t.paths,now:t.now,limits:t.limits,initialStatus:i,parseEnvelope:Rt,createWorker:()=>mr(t,{kind:"index",projectRoot:t.projectRoot,dbPath:t.dbPath,maxActiveSessions:e,softMemoryLimitMb:r}),complete(n,s,a,o){we(t.paths,n,{ok:!0,protocolVersion:Y,id:s.id,baseGeneration:s.baseGeneration,response:a},{nowMs:o,limits:t.limits})},reject(n,s,a,o){xe(t.paths,n,{ok:!1,protocolVersion:Y,id:s,error:a},a,{nowMs:o,limits:t.limits})},idleTtlMs:t.workerIdleMs??Ci,maxWorkerFailureRetries:1,retireAfterResponse:n=>n.retireRequested===!0,statusWhenWorkerAbsent:n=>({...n,state:"idle",activeSessions:0,heapUsedBytes:0,retireRequested:!1}),onBusy:t.onBusy,onFatal:t.onFatal})}function pr(t){let e=()=>({protocolVersion:ee,state:"idle",requests:0,sessionsCreated:0,sessionsReused:0,sessionsRefreshed:0,sessionsReplaced:0,projectsCreated:0});return fr({name:"TypeScript semantic",paths:t.paths,now:t.now,limits:t.limits,initialStatus:e,parseEnvelope:kt,createWorker:()=>mr(t,{kind:"semantic",projectRoot:t.projectRoot}),complete(r,i,n,s){we(t.paths,r,{ok:!0,protocolVersion:ee,id:i.id,generation:i.generation,response:n},{nowMs:s,limits:t.limits})},reject(r,i,n,s){xe(t.paths,r,{ok:!1,protocolVersion:ee,id:i,error:n},n,{nowMs:s,limits:t.limits})},idleTtlMs:Ti,onBusy:t.onBusy,onFatal:t.onFatal})}function fr(t){let e=t.now??Date.now,r=T(process.pid),i={pid:process.pid,...r?{processIdentity:r}:{}},n=`${t.name.toLowerCase().replaceAll(" ","-")}-${process.pid}-${Ii()}`,s={...t.limits,maxBatch:1},a=null,o=t.initialStatus(),c=!1,l=p=>{c=!0,t.onFatal(p)},u=new ce({name:t.name,createWorker:t.createWorker,now:e,idleTtlMs:t.idleTtlMs,maxWorkerFailureRetries:t.maxWorkerFailureRetries,retireAfterResponse:t.retireAfterResponse,onComplete(p,m,f){let y=d(p.requestId);o=f;let I=e();try{t.complete(y.claim,y.envelope,m,I)}catch(k){if(!(k instanceof Re))throw k;try{t.reject(y.claim,y.envelope.id,k.message,I)}catch(P){if(!(P instanceof Re))throw P;ki(y.claim.path,{force:!0})}}h(y)},onReject(p,m,f){let y=d(p.requestId);f!==void 0&&(o=f),t.reject(y.claim,y.envelope.id,m,e()),h(y)},onStatus(p){o=p},onFatal:l});return{poll(){if(c||!u.canAccept())return 0;let p=mt(t.paths,{ownerId:n,nowMs:e(),limits:s,owner:i,liveness:{isProcessAlive:M,readProcessIdentity:T}})[0];if(!p)return 0;let m=p.requestId;try{let f=t.parseEnvelope(yt(p,s));if(m=f.id,f.id!==p.requestId)throw new Error(`${t.name} request identity does not match its mailbox path.`);if(f.deadlineAtMs<e())throw new Error(`${t.name} request expired before processing.`);if(a={claim:p,envelope:f},t.onBusy?.(f.deadlineAtMs),!u.start({requestId:f.id,deadlineAtMs:f.deadlineAtMs,payload:f}))throw new Error(`${t.name} worker lane closed admission after claiming a request.`)}catch(f){let y=Ai(f);try{t.reject(p,m,y,e()),a?.claim===p&&h(a)}catch(I){l(Mi(I))}}return 1},status(){return{...u.hasWorker()||!t.statusWhenWorkerAbsent?o:t.statusWhenWorkerAbsent(o),mailbox:St(t.paths)}},async close(p){await u.close(p)}};function d(p){let m=a;if(!m||m.envelope.id!==p)throw new Error(`${t.name} parent lost the active mailbox claim.`);return m}function h(p){a===p&&(a=null,t.onBusy?.(void 0))}}var Ei=6144;function gr(){let t=Number.parseInt(process.env.SCIP_TS_WORKER_HEAP_MB??"",10);return Number.isFinite(t)&&t>0?t:Ei}function Wi(t){return Math.max(1,Math.floor((t??gr())*.9))}function mr(t,e){if(t.createWorker)return t.createWorker(e);let r=t.workerUrl??new URL("./typescript-mailbox-worker.js",import.meta.url);return new Pi(r,{workerData:e,resourceLimits:{maxOldGenerationSizeMb:t.workerHeapMb??gr()}})}function Mi(t){return t instanceof Error?t:new Error(String(t))}function Ai(t){return t instanceof Error?t.message:String(t)}var Sr=2e3,_i=5e3,Gi=5e3,Di=6e4,Fi=10,Oi=50,Ni=1e4;function qi(t,e=1){return Ye(t,e,Fi,Oi,Ni,8)}function Bi(t,e){let r;return{begin(){return r||(e.requestStop(),e.closeWake(),r=t.stop(),r.catch(()=>{})),r}}}async function $i(t,e){let r=e.processIndexRequests(),i=e.processSemanticRequests(),n=r+i,s=n>0?0:t+1;if(e.afterMailboxPoll({indexRequests:r,semanticRequests:i,processedRequests:n}),e.shouldStop())return{indexRequests:r,semanticRequests:i,processedRequests:n,consecutiveIdlePolls:s,stopped:!0};let a=qi(n,s);return await e.wait(a),{indexRequests:r,semanticRequests:i,processedRequests:n,consecutiveIdlePolls:s,stopped:!1,delayMs:a}}function Ui(t){return t==="fresh"?null:{kind:"watch-startup",detail:`index ${t} when watch service started`}}function zi(t){Lt(t.statePath,{version:1,protocolVersion:bt,pid:v.pid,...t.processIdentity?{processIdentity:t.processIdentity}:{},projectRoot:t.projectRoot,...t.worktreeId?{worktreeId:t.worktreeId}:{},cliVersion:t.cliVersion,startedAt:new Date(t.startedAtMs).toISOString(),heartbeatAt:new Date(t.nowMs).toISOString(),lastActivityAt:new Date(t.lastActivityAtMs).toISOString(),...t.idleTimeoutMs===0?{}:{idleDeadlineAt:new Date(t.lastActivityAtMs+t.idleTimeoutMs).toISOString()},watcher:t.watcherStatus,...t.watcherStatus.state==="idle"&&t.indexGeneration?{indexGeneration:t.indexGeneration}:{},...t.lastRefresh?{lastRefresh:t.lastRefresh}:{},...t.lastError?{lastError:t.lastError}:{},reindexActivity:t.reindexActivity,refreshRequests:t.refreshCoordinator.status(),typescriptSemantic:{...t.semanticLane.status(),...t.semanticBusyUntilMs===void 0?{}:{busyUntil:new Date(t.semanticBusyUntilMs).toISOString()}},typescriptIndex:{...t.indexLane.status(),...t.indexBusyUntilMs===void 0?{}:{busyUntil:new Date(t.indexBusyUntilMs).toISOString()}}},{durability:t.durability})}function Ji(t){let e=0,r=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY,n=Number.NEGATIVE_INFINITY,s=Number.NEGATIVE_INFINITY;return({processedRequests:a})=>{let o=C();if(o-i>=Gi&&(i=o,!Ot(t.worktreeLiveness))){t.requestStop();return}if(o-s>=Di&&(s=o,Ie(t.indexMailboxPaths),Ie(t.semanticMailboxPaths)),o-n>=oe&&(n=o,lr(t.projectRoot,t.cliVersion)),o-r>=_i){r=o;let c=jt(t.activityPath);c&&t.updateObservedActivity(c.atMs,o),c?.refreshRequestedAtMs!==void 0&&c.refreshRequestedAtMs>e&&(e=c.refreshRequestedAtMs,t.refreshCoordinator.observeLegacyRequest(c.refreshRequestedAtMs,c.refreshDetail??"stale index observed by a legacy command"))}t.refreshCoordinator.poll(t.watcherStatus(),c=>{t.recordActivity(),t.requestRefresh(c)}),a>0&&(t.recordActivity(),t.persistState(!0,"visibility")),t.persistState()}}async function Vi(t){let e,r=0,i=!1,n,s;v.once("SIGINT",t.stopSignal),v.once("SIGTERM",t.stopSignal);try{t.watcher.start();let o=t.initializeFreshness();for(t.recordActivity(),t.markReady(),t.persistState(!0),e=setInterval(()=>t.persistState(),Sr),e.unref?.(),o&&t.requestRefresh(o);!t.stopRequested();){let c=await $i(r,{processIndexRequests:t.processIndexRequests,processSemanticRequests:t.processSemanticRequests,afterMailboxPoll:t.afterMailboxPoll,shouldStop:t.shouldStop,wait:t.wait});if(r=c.consecutiveIdlePolls,c.stopped)break}}catch(o){i=!0,n=o}finally{v.off("SIGINT",t.stopSignal),v.off("SIGTERM",t.stopSignal),e!==void 0&&clearInterval(e);let o=t.shutdown.begin();await t.closeLanes();let c=await o;c.state==="stopped"?t.finalizeStopped():s=t.finalizeDegraded(c.reasons)}let a=t.mailboxFatalError();if(!i&&a&&(i=!0,n=a),i&&s)throw new AggregateError([n,s],"Watch service execution and shutdown both failed.");if(i)throw n;if(s)throw s}function Hi(t){let e=pr({paths:t.semanticPaths,projectRoot:t.projectRoot,onBusy:t.onSemanticBusy,onFatal:t.onFatal}),r=t.config.indexer?.typescript,i=hr({paths:t.indexPaths,projectRoot:t.projectRoot,dbPath:t.dbPath,...r?.maxWarmSessions===void 0?{}:{maxActiveSessions:r.maxWarmSessions},...r?.workerIdleMs===void 0?{}:{workerIdleMs:r.workerIdleMs},...r?.workerSoftMemoryMb===void 0?{}:{workerSoftMemoryMb:r.workerSoftMemoryMb},...r?.workerHeapMb===void 0?{}:{workerHeapMb:r.workerHeapMb},onBusy:t.onIndexBusy,onFatal:t.onFatal});return{semanticLane:e,indexLane:i}}async function Xi(t,e,r={}){let i=Mt(t,e),n=i.projectRoot,s=i.worktreeKind==="git"?Ki(n,i.worktreeId):void 0,a=Ft(n,s),o=B(n);o.watch={...o.watch,...r};let c=Z(o);if(!c.enabled)throw new Error('watch mode is disabled; set "watch.enabled": true before starting the service');let l=N(n,o),u=Q(l.cacheDir),d=T(v.pid),h=_t(u.lockPath,n,{readProcessIdentity:g=>g===v.pid?d:T(g)});if(!h.acquired)return;let p=new ae(u.refreshRequestsPath,{retryDelayMs:Math.max(1e3,c.cooldownMs)});p.initializeAfterOwnershipAcquired();let m=Date.now(),f=C(),y=m,I=f,k={state:"idle"},P,le,E,de,ue=K(l.dbPath),H=!1,qe=!1,Be=Number.NEGATIVE_INFINITY,$e,Ue,D=It(l.cacheDir),F=vt(l.cacheDir);be(D),be(F);let ze=Pe([F.pendingDir,F.legacyRequestDir,D.pendingDir,D.legacyRequestDir,u.refreshRequestsPath]),w=(g=!1,W=g?"durable":"visibility")=>{if(!qe)return;let fe=Date.now(),L=C();!g&&L-Be<Sr||(Be=L,zi({statePath:u.statePath,durability:W,processIdentity:d,projectRoot:n,worktreeId:i.worktreeId,cliVersion:e,startedAtMs:m,nowMs:fe,lastActivityAtMs:y,idleTimeoutMs:c.idleTimeoutMs,watcherStatus:k,indexGeneration:P,lastRefresh:le,lastError:E,reindexActivity:ue,refreshCoordinator:p,semanticLane:he,indexLane:pe,semanticBusyUntilMs:$e,indexBusyUntilMs:Ue}))},A=()=>{y=Date.now(),I=C()},vr=g=>{A(),de??=g,E={at:new Date().toISOString(),message:g.message},w(!0,"visibility")},{semanticLane:he,indexLane:pe}=Hi({semanticPaths:D,indexPaths:F,projectRoot:n,dbPath:l.dbPath,config:o,onSemanticBusy(g){$e=g===void 0?void 0:g+5e3,w(!0,"visibility")},onIndexBusy(g){Ue=g===void 0?void 0:g+5e3,w(!0,"visibility")},onFatal:vr}),X=new ne({projectRoot:n,config:{...o,watch:c},outputDb:l.dbPath,languages:o.languages,onStatus(g){k=g,g.state!=="idle"&&(P=void 0),g.state!=="idle"&&A(),w(!0)},onReindexComplete(g,W,fe){A();let L=fe?.pendingChanges!==!1?$(n,o,l):xt(l);return le=L.lastRefresh,P=L.state==="fresh"?j(l.dbPath)??void 0:void 0,ue=K(l.dbPath),p.completeActive(),E=void 0,w(!0),L.state==="fresh"},onReindexError(){p.failActive()},onRefreshSuppressed(g){let W=pt(l.dbPath,g);W.state==="failed"&&(E={at:new Date().toISOString(),message:`Suppressed-refresh telemetry was not recorded: ${W.reason}`},w(!0,"visibility")),ue=K(l.dbPath)},onError(g){A(),P=void 0,E={at:new Date().toISOString(),message:g.message},w(!0)}}),Je=Bi(X,{requestStop(){H=!0},closeWake(){ze.close()}}),Rr=()=>{Je.begin()},br=Ji({worktreeLiveness:a,indexMailboxPaths:F,semanticMailboxPaths:D,projectRoot:n,cliVersion:e,activityPath:u.activityPath,refreshCoordinator:p,watcherStatus:()=>k,requestRefresh:g=>X.requestRefresh({kind:"watch-demand",detail:g},{immediate:!0}),requestStop:()=>{H=!0},recordActivity:A,updateObservedActivity(g,W){g<=y||(y=g,I=W)},persistState:w});await Vi({watcher:X,shutdown:Je,stopSignal:Rr,initializeFreshness(){let g=$(n,o,l);return le=g.lastRefresh,P=g.state==="fresh"?j(l.dbPath)??void 0:void 0,Ui(g.state)},markReady:()=>{qe=!0},recordActivity:A,persistState:w,requestRefresh:g=>X.requestRefresh(g,{immediate:!0}),stopRequested:()=>H,processIndexRequests:()=>pe.poll(),processSemanticRequests:()=>he.poll(),afterMailboxPoll:br,shouldStop:()=>H||de!==void 0||Gt({watcher:k,lastActivityAtMs:I,nowMs:C(),idleTimeoutMs:c.idleTimeoutMs}),wait:g=>ze.wait(g),closeLanes:()=>Promise.all([he.close("TypeScript semantic service stopped before completing the request."),pe.close("TypeScript index service stopped before completing the request.")]).then(()=>{}),mailboxFatalError:()=>de,finalizeStopped(){yr(u.statePath,{force:!0}),yr(u.activityPath,{force:!0}),h.release()},finalizeDegraded(g){return E={at:new Date().toISOString(),message:`Watch service shutdown is degraded: ${g.join("; ")}`},w(!0),new Error(E.message)}})}function Ki(t,e){let r=nt(t);if(r.kind!=="worktree"||r.identity.worktreeId!==e)throw new Error(`Git worktree identity changed while starting the watch service for ${t}.`);return r.identity.gitDir}function Yi(t,e={report:r=>console.error(r),exit:r=>v.exit(r)}){return e.report(`watch-service: ${wt(t instanceof Error?t.message:String(t))}`),e.exit(1)}var Qi=v.argv[1]?ji(Li(v.argv[1])).href:null;if(Qi===import.meta.url){let t=v.argv[2],e=v.argv[3],r=Zi(v.argv[4]);if(!t||!e)console.error("watch-service: expected <project-root> <cli-version>"),v.exitCode=1;else try{await Xi(t,e,r)}catch(i){Yi(i)}}function Zi(t){if(!t)return{};try{let e=JSON.parse(t);return e&&typeof e=="object"?e:{}}catch{return{}}}export{Pe as createPathChangeWake,Bi as createWatchServiceShutdown,$i as runWatchServiceLoopIteration,Xi as runWatchServiceServer,Ui as startupRefreshTrigger,Yi as terminateWatchServiceProcess,qi as watchServiceLoopDelayMs};
|
|
1
|
+
import{a as xt}from"./chunk-76CZ77DF.js";import{a as Ke,b as U,c as H,g as Ze,j as et,k as V,l as tt,m as lt,n as Se}from"./chunk-2LHXRE2B.js";import{a as z,b as st,c as ot}from"./chunk-6LRXOOSX.js";import{a as ve}from"./chunk-F4PUT6IT.js";import{a as pt,b as mt,c as ft,d as Re,e as gt,f as be,g as yt,h as St,j as vt,k as Rt,l as bt,m as wt}from"./chunk-STMVAHJP.js";import{b as at,d as ct}from"./chunk-NJJMVD65.js";import"./chunk-6FFVZZL4.js";import{d as N,e as J,f as D,g as dt}from"./chunk-4IGEOBG7.js";import"./chunk-KU3QRSTH.js";import"./chunk-DHEQMPLW.js";import{a as K,b as ut,c as ht}from"./chunk-BZB4QPIP.js";import"./chunk-4FEWQ6RH.js";import{h as A}from"./chunk-BIQEF5NE.js";import"./chunk-YTAP5Y2G.js";import{a as Xe,b as Ye}from"./chunk-T3I6NHBH.js";import"./chunk-WOFQ5DTB.js";import"./chunk-NDUNO5JQ.js";import"./chunk-X6RMKHJQ.js";import{a as he,d as Ue}from"./chunk-JEVRKFRL.js";import{a as Qe}from"./chunk-H75GSPRV.js";import"./chunk-GZKFETP5.js";import"./chunk-BL6XJKTA.js";import{d as pe,f as me,j as rt,k as it,l as fe,m as ge,n as ye,o as nt}from"./chunk-3JIQS44J.js";import"./chunk-O4UZSPPI.js";import{a as ze}from"./chunk-B3PYOSCX.js";import"./chunk-HRRFKWPZ.js";import"./chunk-HGFDYOVB.js";import{c as P,d as T,e as Je}from"./chunk-QZ7KQZRN.js";import{C as Ve,f as He,k as O}from"./chunk-TKD34PHN.js";import"./chunk-2HLAFUCY.js";import{H as Be,K as $e,a as de,c as Fe,s as De,w as qe,y as ue,z as Ge}from"./chunk-U5RIG3JP.js";import{a as Oe,h as Ne,i as k}from"./chunk-62BDNPMI.js";import bi from"better-sqlite3";import S from"process";import{rmSync as er}from"fs";import{resolve as wi}from"path";import{pathToFileURL as xi}from"url";import{lstatSync as sr}from"fs";function Tt(e,t){let r=X(e);if(r.kind!=="directory")throw new Error(`Watcher root is not a directory: ${e}`);if(!t)return{projectRoot:e,projectDirectory:r};let i=X(t);if(i.kind!=="directory")throw new Error(`Git control path is not a directory: ${t}`);return{projectRoot:e,projectDirectory:r,gitControlDirectory:{path:t,identity:i}}}function It(e){try{if(!Pt(e.projectDirectory,X(e.projectRoot)))return!1;let t=e.gitControlDirectory;return!t||Pt(t.identity,X(t.path))}catch{return!1}}function X(e){let t=sr(e,{bigint:!0}),r=t.isDirectory()?"directory":t.isFile()?"file":void 0;if(!r||t.isSymbolicLink())throw new Error(`Unsupported watcher identity path: ${e}`);return{device:t.dev,inode:t.ino,birthtimeNs:t.birthtimeNs,kind:r}}function Pt(e,t){return e.device===t.device&&e.inode===t.inode&&e.birthtimeNs===t.birthtimeNs&&e.kind===t.kind}import{fileURLToPath as ar}from"url";import{existsSync as Te,lstatSync as cr,statSync as Lt,watch as lr}from"fs";import{EventEmitter as dr}from"events";import{basename as ur,dirname as jt,isAbsolute as Ie,join as R,relative as Ft,resolve as Ot}from"path";import{watch as hr}from"chokidar";import pr from"ignore";var Nt=5e3,Z=class{projectRoot;config;watchConfig;outputDb;languages;pnpmWorkspaces;typescriptProjectMode;typescriptProjects;clojureConfigPath;indexerConcurrency;onStatus;onReindexComplete;onReindexError;onRefreshSuppressed;onError;reindexRunner;subscriptionFactory;budgetInspector;clock;activeOperation=null;stopPromise=null;stopInProgress=!1;status={state:"idle"};debounceTimer=null;cooldownTimer=null;budgetTimer=null;dirty=!1;changedFiles=0;pendingTrigger=null;pendingChanges=new Map;pendingChangesComplete=!0;pendingChangesIncompleteReason;reindexInFlight=!1;lastReindexEnd=0;publicationObservationInvalidated=!1;lastObservedGeneration=null;publishedGeneration;indexFreshness;fsWatchers=[];sourcePollingFallbackStarted=!1;gitPollTimer=null;reconcileTimer=null;lastGitState=null;preferFilesystemGitState=!0;watchGitLayout=null;localCacheWatchPath;gitignoreFilter;extraIgnore;stopped=!1;constructor(t){this.projectRoot=t.projectRoot,this.config=t.config,this.watchConfig=J(t.config),this.outputDb=t.outputDb??R(He(this.projectRoot,t.config),"index.db"),this.preferFilesystemGitState=t.gitReader===void 0,this.localCacheWatchPath=Br(this.projectRoot,jt(this.outputDb)),this.languages=t.languages,this.pnpmWorkspaces=t.config.indexer?.typescript?.pnpmWorkspaces??!1,this.typescriptProjectMode=t.config.indexer?.typescript?.projectMode,this.typescriptProjects=t.config.indexer?.typescript?.projects,this.clojureConfigPath=t.config.indexer?.clojure?.configPath,this.indexerConcurrency=t.config.indexerConcurrency;let r=Sr(t);this.onStatus=r.onStatus,this.onReindexComplete=r.onReindexComplete,this.onReindexError=r.onReindexError,this.onRefreshSuppressed=r.onRefreshSuppressed,this.onError=r.onError,this.clock=r.clock,Dt.set(this,$r(t.stopTimeoutMs??Nt,"watcher stop timeout")),this.reindexRunner=t.reindexRunner??Ar(),this.subscriptionFactory=t.subscriptionFactory??xr,this.budgetInspector=t.budgetInspector??tt,this.publishedGeneration=t.publishedGeneration??A,this.indexFreshness=t.indexFreshness??Gr,this.lastObservedGeneration=this.readPublishedGeneration(),yr(this,t),this.gitignoreFilter=Qe(t.projectRoot),this.extraIgnore=pr(),this.watchConfig.ignore.length>0&&this.extraIgnore.add(this.watchConfig.ignore),xe(this)}start(){if(this.stopInProgress)throw new Error("Cannot restart a watcher while its previous ownership is still draining.");this.stopped=!1,this.stopPromise=null,Q(this).errors=[],this.sourcePollingFallbackStarted=!1,this.setStatus({state:"idle"}),this.startGitStatePolling();try{this.startSourceWatcher()}catch(t){this.onError(new Error(`Failed to watch ${this.projectRoot}: ${String(t)}`))}}stop(){if(this.stopPromise)return this.stopPromise;this.stopped=!0,this.stopInProgress=!0;let t=this.fsWatchers;this.fsWatchers=[],this.clearDebounceTimer(),this.clearCooldownTimer(),this.clearBudgetTimer(),this.clearGitPollTimer(),this.clearReconcileTimer();let r=this.activeOperation;r&&this.setStatus({state:"draining",startedAt:this.wallNow(),reason:"waiting for the active reindex worker to exit"});let i=[...Q(this).closures],n=fr(this),s=this.clock.now()+n;return this.stopPromise=this.finishStop(t,i,r,s,n).catch(o=>{throw this.stopInProgress=!1,o}),this.stopPromise}requestRefresh(t,r={}){if(!this.stopped){if(this.markPendingChangesIncomplete(`unstructured-trigger:${t.kind}`),!r.immediate||this.reindexInFlight||this.status.state==="cooldown"||this.status.state==="budget-paused"){this.scheduleReindex(t);return}this.pendingTrigger=we(this.pendingTrigger,t),this.changedFiles+=1,this.clearDebounceTimer(),this.triggerReindex()}}startSourceWatcher(t=!1){let r=this.subscriptionFactory(this.projectRoot,{ignoreInitial:!0,ignored:(i,n)=>this.isIgnoredWatchPath(i,n?.isDirectory()??!1),usePolling:t,ignorePermissionErrors:!0,...t?{interval:5e3,binaryInterval:1e4}:{}});r.on("all",(i,n)=>{!this.stopped&&i!=="addDir"&&i!=="unlinkDir"&&this.handleFileChange(i,n)}),r.on("error",i=>this.handleSourceWatcherError(r,i,t)),this.fsWatchers.push(r)}handleSourceWatcherError(t,r,i){if(this.markPendingChangesIncomplete("source-watcher-error"),i||this.sourcePollingFallbackStarted||!Fr(r)||this.stopped){this.onError(new Error(`Failed to watch ${this.projectRoot}: ${String(r)}`));return}this.sourcePollingFallbackStarted=!0,this.fsWatchers=this.fsWatchers.filter(n=>n!==t),gr(Q(this),t,n=>this.onError(n));try{this.startSourceWatcher(!0)}catch(n){this.onError(new Error(`Failed to watch ${this.projectRoot}: ${String(n)}`))}}isIgnoredWatchPath(t,r){let i=this.relativeWatchPath(t);if(!i)return!1;if(Wt(i,this.localCacheWatchPath))return!0;let n=r?`${i}/`:i;return this.gitignoreFilter.isIgnored(n)||this.extraIgnore.ignores(n)}handleFileChange(t,r){let i=this.relativeWatchPath(r);if(Zr(i)||Wt(i,this.localCacheWatchPath)||this.gitignoreFilter.isIgnored(i)||this.extraIgnore.ignores(i)||ei(i))return;i===".scipquery.json"&&$t(this,this.projectRoot);let n=Ut(this,t,i);n!==null&&(n||this.markPendingChangesIncomplete(`unsupported-source-event:${t}`),this.scheduleReindex({kind:"watch-source",detail:i},n?[{path:i,kind:n}]:void 0,n!==void 0))}relativeWatchPath(t){let r=Ie(t)?t:R(this.projectRoot,t);return Ft(this.projectRoot,r).replaceAll("\\","/")}scheduleReindex(t,r,i=!1){this.publicationObservationInvalidated=!0,this.pendingTrigger=we(this.pendingTrigger,t),i||this.markPendingChangesIncomplete(`unstructured-trigger:${t.kind}`);for(let s of r??[])this.recordPendingChange(s);if(this.changedFiles++,this.reindexInFlight){this.dirty=!0,this.setStatus({state:"indexing",startedAt:this.status.startedAt});let s=this.activeOperation;s&&_.get(this)!==s&&(_.set(this,s),s.cancel().then(o=>{o.state==="degraded"&&!this.stopped&&this.onError(new Error(o.reason))},o=>{this.stopped||this.onError(o instanceof Error?o:new Error(String(o)))}));return}if(this.status.state==="cooldown"){this.dirty=!0,this.setStatus({state:"cooldown",until:this.status.until,dirty:!0});return}if(this.status.state==="budget-paused"){this.dirty=!0,this.setStatus({...this.status,dirty:!0});return}this.clearDebounceTimer();let n=this.wallNow()+this.watchConfig.debounceMs;this.setStatus({state:"waiting",changedFiles:this.changedFiles,reindexAt:n}),this.debounceTimer=this.clock.setTimeout(()=>{this.debounceTimer=null,this.triggerReindex()},this.watchConfig.debounceMs)}triggerReindex(){if(this.reindexInFlight||this.stopped||this.reconcilePublishedIndex())return;let t=this.inspectBudget(),r=this.watchConfig.allowExpensiveRebuild&&t.state!=="paused";if(t.state==="paused"&&t.reason!=="rebuild-count"){this.dirty=!0;let a=Math.max(this.wallNow()+1,t.until);this.setStatus({state:"budget-paused",until:a,dirty:!0,reason:t.detail,rebuilt:t.rebuilt,estimatedWriteBytes:t.estimatedWriteBytes}),this.clearBudgetTimer(),this.budgetTimer=this.clock.setTimeout(()=>{this.budgetTimer=null,this.dirty&&!this.stopped&&(this.dirty=!1,this.triggerReindex())},Math.min(2147483647,Math.max(1,a-this.wallNow())));return}let i=this.clock.now()-this.lastReindexEnd;if(this.lastReindexEnd>0&&i<this.watchConfig.cooldownMs){let a=this.watchConfig.cooldownMs-i;this.dirty=!0;let l=this.wallNow()+a;this.setStatus({state:"cooldown",until:l,dirty:!0}),this.cooldownTimer=this.clock.setTimeout(()=>{this.cooldownTimer=null,this.dirty&&!this.stopped&&(this.dirty=!1,this.triggerReindex())},a);return}this.reindexInFlight=!0,this.dirty=!1,this.changedFiles=0;let n=this.pendingTrigger??{kind:"watch-source"};this.pendingTrigger=null;let s=this.consumePendingChangeJournal(),o=this.wallNow();this.setStatus({state:"indexing",startedAt:o});let c=this.reindexRunner.start(this.reindexRequest(n,r,s));this.activeOperation=c,c.completion.then(a=>{if(this.reindexInFlight=!1,this.lastReindexEnd=this.clock.now(),Y.set(this,0),this.stopped)return;if(_.get(this)===c){if(this.restorePendingChangeJournal(s),this.dirty){let u=this.wallNow()+this.watchConfig.cooldownMs;this.setStatus({state:"cooldown",until:u,dirty:!0}),this.clearCooldownTimer(),this.cooldownTimer=this.clock.setTimeout(()=>{this.cooldownTimer=null,this.dirty&&!this.stopped?(this.dirty=!1,this.triggerReindex()):this.setStatus({state:"idle"})},this.watchConfig.cooldownMs)}else this.setStatus({state:"idle"});return}xe(this),this.lastObservedGeneration=this.readPublishedGeneration();let l=!1;try{l=this.onReindexComplete(a,n,{pendingChanges:this.dirty})===!0}catch(u){this.onError(u instanceof Error?u:new Error(String(u)))}if(this.dirty&&!this.stopped){if(l){let d=this.pendingTrigger??{kind:"unknown"};this.dirty=!1,this.changedFiles=0,this.pendingTrigger=null,this.resetPendingChanges(),this.onRefreshSuppressed(d),this.setStatus({state:"idle"});return}let u=this.wallNow()+this.watchConfig.cooldownMs;this.setStatus({state:"cooldown",until:u,dirty:!0}),this.clearCooldownTimer(),this.cooldownTimer=this.clock.setTimeout(()=>{this.cooldownTimer=null,this.dirty&&!this.stopped?(this.dirty=!1,this.triggerReindex()):this.setStatus({state:"idle"})},this.watchConfig.cooldownMs)}else this.setStatus({state:"idle"})}).catch(a=>{if(this.reindexInFlight=!1,this.lastReindexEnd=this.clock.now(),this.stopped)return;let l=a instanceof Error?a:new Error(String(a));this.restorePendingChangeJournal(s);let u=Gt(l),d=0;if(u?(d=(Y.get(this)??0)+1,Y.set(this,d),this.dirty=!0,this.pendingTrigger=we(this.pendingTrigger,n)):Y.set(this,0),!u&&_.get(this)!==c&&(this.onReindexError(l,n),this.onError(l)),this.dirty){let p=u?Cr(this.watchConfig.cooldownMs,d):this.watchConfig.cooldownMs,m=this.wallNow()+p;this.setStatus({state:"cooldown",until:m,dirty:!0}),this.clearCooldownTimer(),this.cooldownTimer=this.clock.setTimeout(()=>{this.cooldownTimer=null,this.dirty&&!this.stopped?(this.dirty=!1,this.triggerReindex()):this.setStatus({state:"idle"})},p);return}this.setStatus({state:"idle"})}).finally(()=>{this.activeOperation===c&&(this.activeOperation=null),_.get(this)===c&&_.delete(this)})}async finishStop(t,r,i,n,s){let o=[],c=t.map(async p=>{try{await p.close()}catch(m){o.push(`watch subscription close failed: ${String(m)}`)}});c.push(...r),i&&c.push((async()=>{try{let p=await i.cancel();p.state==="degraded"&&o.push(p.reason)}catch(p){o.push(`reindex cancellation failed: ${p instanceof Error?p.message:String(p)}`)}})());let a=c.length,l=c.map(p=>p.finally(()=>{a-=1})),u=await mr(l,n,this.clock),d=Q(this);return o.push(...d.errors),d.errors=[],u?this.stopInProgress=!1:(o.push(`watch shutdown exceeded the ${s}ms deadline with ${a} operation(s) still pending`),Promise.all(l).then(()=>{this.stopInProgress=!1})),o.length>0?(this.setStatus({state:"draining",startedAt:this.wallNow(),reason:o.join("; ")}),{state:"degraded",reasons:o}):(this.setStatus({state:"idle"}),{state:"stopped"})}wallNow(){return this.clock.wallNow?.()??this.clock.now()}inspectBudget(){try{return this.budgetInspector(this.outputDb,this.watchConfig.resourceBudget,new Date(this.wallNow()))}catch(t){return{state:"paused",reason:"activity-evidence",until:this.wallNow()+this.watchConfig.resourceBudget.windowMs,rebuilt:0,estimatedWriteBytes:0,detail:`reindex activity evidence could not be read: ${t instanceof Error?t.message:String(t)}`}}}reindexRequest(t,r=!0,i){return{projectRoot:this.projectRoot,config:this.config,languages:this.languages,pnpmWorkspaces:this.pnpmWorkspaces,typescriptProjectMode:this.typescriptProjectMode,typescriptProjects:this.typescriptProjects,clojureConfigPath:this.clojureConfigPath,indexerConcurrency:this.indexerConcurrency,trigger:t,changeJournal:i,allowExpensiveRebuild:r}}setStatus(t){this.status=t,t.state==="cooldown"||t.state==="budget-paused"?this.armReconcileTimer(t.until):this.clearReconcileTimer(),this.onStatus(t)}recordPendingChange(t){if(this.pendingChanges.size>=1024&&!this.pendingChanges.has(t.path)){this.pendingChanges.clear(),this.markPendingChangesIncomplete("change-entry-limit");return}let r=this.pendingChanges.get(t.path),i=Lr(r,t.kind);i===null?this.pendingChanges.delete(t.path):this.pendingChanges.set(t.path,i)}markPendingChangesIncomplete(t){this.pendingChangesComplete=!1,this.pendingChangesIncompleteReason??=t}consumePendingChangeJournal(){let t=A(this.outputDb),r=[...this.pendingChanges.entries()].map(([o,c])=>({path:o,kind:c})).sort((o,c)=>o.path.localeCompare(c.path)),i=this.pendingChangesComplete,n=this.pendingChangesIncompleteReason;t||(i=!1,n??="accepted-generation-unavailable");let s={version:1,baseGeneration:t,complete:i,...n?{incompleteReason:n}:{},entries:r};return Se(s)||(s={version:1,baseGeneration:t,complete:!1,incompleteReason:"change-journal-byte-limit",entries:[]}),this.resetPendingChanges(),s}restorePendingChangeJournal(t){let r=[...this.pendingChanges.entries()].map(([s,o])=>({path:s,kind:o})),i=this.pendingChangesComplete,n=this.pendingChangesIncompleteReason;this.resetPendingChanges(),t.complete||this.markPendingChangesIncomplete(t.incompleteReason??"failed-reindex");for(let s of t.entries)this.recordPendingChange(s);i||this.markPendingChangesIncomplete(n??"failed-reindex");for(let s of r)this.recordPendingChange(s)}resetPendingChanges(){this.pendingChanges.clear(),this.pendingChangesComplete=!0,this.pendingChangesIncompleteReason=void 0}clearDebounceTimer(){this.debounceTimer&&(this.clock.clearTimeout(this.debounceTimer),this.debounceTimer=null)}clearCooldownTimer(){this.cooldownTimer&&(this.clock.clearTimeout(this.cooldownTimer),this.cooldownTimer=null)}clearBudgetTimer(){this.budgetTimer&&(this.clock.clearTimeout(this.budgetTimer),this.budgetTimer=null)}startGitStatePolling(){this.lastGitState=this.readGitState(),this.lastGitState&&(b(this).stagedIndexEntries=_t(this.projectRoot,b(this).gitReader),this.gitPollTimer=this.clock.setInterval(()=>this.pollGitState(),this.watchConfig.gitPollMs),this.gitPollTimer.unref?.())}armReconcileTimer(t){this.clearReconcileTimer();let r=t-this.wallNow();if(r<=0||!(this.watchConfig.gitPollMs>0))return;let i=Math.min(this.watchConfig.gitPollMs,r);this.reconcileTimer=this.clock.setTimeout(()=>{this.reconcileTimer=null,!(this.stopped||this.reconcilePublishedIndex())&&(this.status.state==="cooldown"||this.status.state==="budget-paused")&&this.armReconcileTimer(this.status.until)},i),this.reconcileTimer.unref?.()}clearReconcileTimer(){this.reconcileTimer&&(this.clock.clearTimeout(this.reconcileTimer),this.reconcileTimer=null)}readPublishedGeneration(){try{return this.publishedGeneration(this.outputDb)}catch{return null}}reconcilePublishedIndex(){if(this.stopped||this.reindexInFlight||!(this.dirty||this.status.state==="budget-paused"||this.status.state==="cooldown"||this.status.state==="waiting")||!this.hasFreshPublishedIndex())return!1;let r=this.pendingTrigger??{kind:"unknown"};return this.clearDebounceTimer(),this.clearCooldownTimer(),this.clearBudgetTimer(),this.dirty=!1,this.changedFiles=0,this.pendingTrigger=null,this.resetPendingChanges(),xe(this),this.onRefreshSuppressed({...r,detail:`the published index matches current source${r.detail?` (${r.detail})`:""}`}),this.setStatus({state:"idle"}),!0}hasFreshPublishedIndex(){let t=this.readPublishedGeneration();if(t===null||t===this.lastObservedGeneration&&!this.publicationObservationInvalidated)return!1;let r;try{r=this.indexFreshness(this.projectRoot,this.config,this.outputDb)}catch{return!1}return(r==="fresh"||r==="stale")&&(this.lastObservedGeneration=t,this.publicationObservationInvalidated=!1),r==="fresh"}pollGitState(){if(this.reindexInFlight||this.stopped)return;let t=this.lastGitState,r=this.readGitState();if(!r||this.stopped||(this.lastGitState=r,!t))return;let i=t.head!==r.head,n=ti(t,r);if(!i&&!n)return;let s=b(this),o=s.stagedIndexEntries,c=_t(this.projectRoot,s.gitReader);s.stagedIndexEntries=c;let a=zr(this.projectRoot,s.gitReader,t,r,o,c,i,n),l=null;if(a!==null&&(l=ri(this,this.projectRoot,a),l.length===0))return;let u=l?.map(p=>({path:p,kind:Te(R(this.projectRoot,p))?"change":"delete"})),d=Yr(i,n,r.indexPath);this.scheduleReindex({...d,detail:Qr(d.detail,l)},u,u!==void 0)}readGitState(){if(this.preferFilesystemGitState){let t=this.readFilesystemGitState();if(t)return t}return this.readGitStateFromGit()}readFilesystemGitState(){let t=this.watchGitLayout??Or(this.projectRoot);if(!t)return null;this.watchGitLayout=t;let r=Nr(t.gitDir);return r?At(r,t.indexPath):null}readGitStateFromGit(){let t=b(this).gitReader,r=ue(this.projectRoot,["rev-parse","--git-path","index"],t);if(!r)return null;let i=Ge(this.projectRoot,r);return At(ue(this.projectRoot,["rev-parse","--verify","HEAD"],t),i)}clearGitPollTimer(){this.gitPollTimer&&(this.clock.clearInterval(this.gitPollTimer),this.gitPollTimer=null)}};async function mr(e,t,r){if(e.length===0)return!0;let i=Promise.all(e).then(()=>!0),n=Math.max(0,t-r.now()),s=null,o=new Promise(a=>{s=r.setTimeout(()=>a(!1),n)}),c=await Promise.race([i,o]);return c&&s&&r.clearTimeout(s),c}var Et=new WeakMap,Dt=new WeakMap,qt=new WeakMap,_=new WeakMap,Y=new WeakMap;function Q(e){let t=Et.get(e);if(t)return t;let r={closures:new Set,errors:[]};return Et.set(e,r),r}function fr(e){return Dt.get(e)??Nt}function b(e){let t=qt.get(e);if(!t)throw new Error("Watcher input state was not initialized.");return t}function gr(e,t,r){let i=Promise.resolve().then(()=>t.close()).catch(n=>{let s=`watch subscription close failed during polling fallback: ${String(n)}`;e.errors.push(s),r(new Error(s))});e.closures.add(i),i.then(()=>e.closures.delete(i))}function yr(e,t){qt.set(e,{projectRoot:t.projectRoot,config:t.config,gitReader:t.gitReader??De,languages:Bt(t.languages??t.config.languages),typeScriptInputPaths:null,stagedIndexEntries:null})}function Sr(e){return{onStatus:e.onStatus??(()=>{}),onReindexComplete:e.onReindexComplete??(()=>{}),onReindexError:e.onReindexError??(()=>{}),onRefreshSuppressed:e.onRefreshSuppressed??(()=>{}),onError:e.onError??(t=>console.error(t.message)),clock:e.clock??wr}}function vr(e,t=P){let{projectRoot:r,config:i,languages:n,pnpmWorkspaces:s,typescriptProjectMode:o,typescriptProjects:c,clojureConfigPath:a,indexerConcurrency:l,trigger:u}=e,d=N(r),p=Object.keys(d).length>0?d:i,m=O(r,p),y=p.indexer?.typescript,f=p.indexer?.clojure,g=t(process.pid);if(!g)throw new Error(`Could not establish watcher process identity for reindex worker ownership (pid ${process.pid}).`);return{workerPath:ar(new URL("./reindex-worker.js",import.meta.url)),env:{...process.env,SCIP_REINDEX_PROJECT_ROOT:r,SCIP_REINDEX_OUTPUT_SCIP:m.indexPath,SCIP_REINDEX_OUTPUT_DB:m.dbPath,...Rr(p,y,f,{languages:n,indexerConcurrency:l,pnpmWorkspaces:s,typescriptProjectMode:o,typescriptProjects:c,clojureConfigPath:a}),SCIP_REINDEX_TRIGGER_KIND:u.kind,SCIP_REINDEX_TRIGGER_DETAIL:u.detail??"",SCIP_REINDEX_CHANGE_JOURNAL:e.changeJournal?Se(e.changeJournal)??"":"",SCIP_REINDEX_ALLOW_EXPENSIVE:e.allowExpensiveRebuild===!1?"0":"1",SCIP_REINDEX_PROCESS_GROUP_LEADER:"1",SCIP_REINDEX_PARENT_IDENTITY:JSON.stringify(g)}}}function Rr(e,t,r,i){let{languages:n,indexerConcurrency:s,pnpmWorkspaces:o,typescriptProjectMode:c,typescriptProjects:a,clojureConfigPath:l}=i;return{SCIP_REINDEX_LANGUAGES:(e.languages??n)?.join(",")??"",SCIP_REINDEX_INDEXER_CONCURRENCY:String(e.indexerConcurrency??s??""),SCIP_REINDEX_PNPM_WORKSPACES:t?.pnpmWorkspaces??o?"1":"",SCIP_REINDEX_TYPESCRIPT_CONFIG:br(t,c,a),SCIP_REINDEX_CLOJURE_CONFIG_PATH:r?.configPath??l??""}}function br(e,t,r){return JSON.stringify({projectMode:e?.projectMode??t,projects:e?.projects??r??[],maxHeapMb:e?.maxHeapMb})}var wr={now:T,wallNow:()=>Date.now(),setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e),setInterval:(e,t)=>setInterval(e,t),clearInterval:e=>clearInterval(e)},xr=(e,t)=>Pr(process.platform,t.usePolling)?new Pe(e):hr(e,t);function Pr(e,t){return e==="darwin"&&t!==!0}var q=class extends Error{constructor(t,r){super(t,r===void 0?void 0:{cause:r}),this.name="RecursiveSourceWatchError"}},Pe=class{events=new dr;watcher;constructor(t){this.watcher=lr(t,{recursive:!0},(r,i)=>{if(i===null){this.events.emit("error",new q("Recursive source watcher omitted the changed path."));return}let n=R(t,i.toString());this.events.emit("all",Tr(r,n),n)}),this.watcher.on("error",r=>{this.events.emit("error",new q(`Recursive source watcher failed: ${r.message}`,r))})}on=(t,r)=>(this.events.on(t,r),this);close(){this.watcher.close()}};function Tr(e,t){return e==="change"?"change":Te(t)?Lt(t).isDirectory()?"addDir":"add":"unlink"}var Ir=15*6e4,kr=1e3,Er=64*1024;function Mr(){return{stdoutTail:"",stderrTail:"",stdoutTruncated:!1,stderrTruncated:!1}}function Mt(e,t){let r=e instanceof Error?e.message:String(e),i=t.stderrTail.trim()||t.stdoutTail.trim();return i?`${r}
|
|
2
|
+
${i}`:r}function Wr(e,t){return Object.assign(new Error(e,t===void 0?void 0:{cause:t}),{retryable:!0})}function Gt(e){return e instanceof Error&&"retryable"in e&&e.retryable===!0}function Cr(e,t){let r=e*2**Math.min(5,Math.max(0,t-1));return Math.max(e,Math.min(3e4,r))}function Ar(e={}){let t=e.timeoutMs??Ir,r=e.terminationGraceMs??kr,i=e.maxOutputBytes??Er,n=e.resolveLaunch??vr;return{start(s){let o=n(s),c=new AbortController,a=Mr(),l=!1,u=H({command:process.execPath,args:[...process.execArgv,o.workerPath],label:"watch reindex worker",env:o.env,timeoutMs:t,terminationGraceMs:r,maxStdoutBytes:i,maxStderrBytes:i,outputLimitBehavior:"truncate-tail",signal:c.signal,detached:!0}).then(d=>{if(a={stdoutTail:d.stdout,stderrTail:d.stderr,stdoutTruncated:d.stdoutTruncated,stderrTruncated:d.stderrTruncated},d.status!==0){let p=Mt(new Error(`Reindex worker exited with ${d.signal?`signal ${d.signal}`:`code ${d.status}`}`),a);throw d.status===75?Wr(p):new Error(p)}return d.durationMs}).catch(d=>{throw Gt(d)?d:(d instanceof U&&(a={stdoutTail:d.stdout,stderrTail:d.stderr,stdoutTruncated:d.stdoutTruncated,stderrTruncated:d.stderrTruncated}),new Error(Mt(d,a),{cause:d}))}).finally(()=>{l=!0});return{completion:u,async cancel(){l||c.abort();try{await u}catch{}return{state:"exited",diagnostics:a}},diagnostics:()=>a}}}}function we(e,t){return e?e.kind===t.kind?e.detail===t.detail?e:{kind:e.kind,detail:"multiple changes"}:{kind:"watch-git-state",detail:`${e.kind}, ${t.kind}`}:t}function _r(e){if(e==="add")return"add";if(e==="change")return"change";if(e==="unlink")return"delete"}function Lr(e,t){return e?e==="add"?t==="delete"?null:"add":e==="delete"&&t==="add"?"change":t:t}function jr(e){return e instanceof Error&&"code"in e&&e.code==="EMFILE"||String(e).includes("EMFILE: too many open files")}function Fr(e){return e instanceof q||jr(e)}var ke=/^[0-9a-f]{40,64}$/i;function Wt(e,t){return e===".git"||e.startsWith(".git/")||e==="node_modules"||e.startsWith("node_modules/")||e.endsWith("/node_modules")||e.includes("/node_modules/")?!0:t!==void 0&&(e===t||e.startsWith(`${t}/`))}function Or(e){let t=R(e,".git");try{let r=cr(t),i;if(r.isDirectory())i=t;else if(r.isFile()){let n=/^gitdir:\s*(.+)\s*$/m.exec(k(t,"Git directory marker"));if(!n?.[1])return null;let s=n[1].trim();i=Ie(s)?s:Ot(e,s)}else return null;return Te(i)?{gitDir:i,indexPath:R(i,"index")}:null}catch{return null}}function Nr(e){let t;try{t=k(R(e,"HEAD"),"Git HEAD").trim()}catch{return}if(ke.test(t))return t.toLowerCase();let r=/^ref:\s*(.+)$/.exec(t)?.[1]?.trim();if(!r)return;let i=Dr(e);return Ct(e,r)??Ct(i,r)??qr(i,r)}function Dr(e){try{let t=k(R(e,"commondir"),"Git common-directory marker").trim();return t?Ie(t)?t:Ot(e,t):e}catch{return e}}function Ct(e,t){try{let r=k(R(e,t),"Git reference").trim();return ke.test(r)?r.toLowerCase():void 0}catch{return}}function qr(e,t){try{for(let r of k(R(e,"packed-refs"),"Git packed references").split(`
|
|
3
|
+
`)){if(r.startsWith("#")||r.startsWith("^"))continue;let i=r.indexOf(" ");if(i===-1)continue;let n=r.slice(0,i);if(r.slice(i+1).trim()===t&&ke.test(n))return n.toLowerCase()}}catch{return}}function Gr(e,t,r){let i=jt(r);return D(e,t,{dbPath:r,metaPath:R(i,"meta.json"),cacheDir:i}).state}function At(e,t){let r={head:e,indexPath:t};try{let i=Lt(t);r.indexMtimeMs=i.mtimeMs,r.indexSize=i.size}catch{r.indexMtimeMs=void 0,r.indexSize=void 0}return r}function Br(e,t){let r=Ft(e,t).replaceAll("\\","/");if(!(!r||r===".."||r.startsWith("../")))return r}function $r(e,t){if(!Number.isSafeInteger(e)||e<=0)throw new Error(`${t} must be a positive integer.`);return e}function Bt(e){return e&&e.length>0?[...e]:he}function $t(e,t){try{let r=b(e);r.config=N(t),r.languages=Bt(r.config.languages)}catch{b(e).languages=he}}function Ut(e,t,r){let i=b(e);if(de(r,i.languages)==="other")return null;let s=_r(t);return r===".scipquery.json"||Be(r)?(i.typeScriptInputPaths=null,s):Ur(r,i.languages)?ii(e,i.typeScriptInputPaths,r,s):s}function xe(e){let t=b(e);if(!t.languages.includes("typescript")){t.typeScriptInputPaths=null;return}let r=Hr(t.projectRoot,t.config,t.languages);t.typeScriptInputPaths=r??Ht(e)}function Ht(e){let t=b(e);if(!t.languages.includes("typescript"))return t.typeScriptInputPaths=null,null;try{let r=t.config.indexer?.typescript,i=$e(t.projectRoot,r?.projectMode,r?.projects);return t.typeScriptInputPaths=i,i}catch{return t.typeScriptInputPaths=null,null}}function Ur(e,t){if(!t.includes("typescript"))return!1;let r=de(e,["typescript","javascript"]);return r==="source"||r==="ambient"}function Hr(e,t,r){try{let i=Ue(k(O(e,t).metaPath,"reindex metadata"));if(i.kind!=="supported"&&i.kind!=="legacy")return null;let n=Fe(i.metadata.fingerprint);return!n||!Vr(n,r,t)?null:new Set(n.files.map(s=>s.path))}catch{return null}}function Vr(e,t,r){let i=Ve(t,{pnpmWorkspaces:r.indexer?.typescript?.pnpmWorkspaces,typescriptProjectMode:r.indexer?.typescript?.projectMode,typescriptProjects:r.indexer?.typescript?.projects,clojureConfigPath:r.indexer?.clojure?.configPath});return e.version===i.version&&JSON.stringify([...e.languages].sort())===JSON.stringify(i.languages)&&e.pnpmWorkspaces===i.pnpmWorkspaces&&e.typescriptProjectMode===i.typescriptProjectMode&&JSON.stringify([...e.typescriptProjects].sort())===JSON.stringify(i.typescriptProjects)&&e.clojureConfigPath===i.clojureConfigPath}function zr(e,t,r,i,n,s,o,c){let a=new Set;if(o){if(!r.head||!i.head)return null;let l=t.runResult(e,["diff","--name-only","-z","--no-renames","--relative",r.head,i.head,"--"]);if(l.kind!=="success")return null;for(let u of Jr(l.output))a.add(u)}if(c){if(n===null||s===null)return null;for(let l of Xr(n,s))a.add(l)}return[...a].sort()}function _t(e,t){let r=t.runResult(e,["diff","--cached","--raw","-z","--no-renames","--relative","--"]);return r.kind==="success"?Kr(r.output):null}function Jr(e){return e.split("\0").filter(t=>t.length>0)}function Kr(e){let t=e.split("\0");if(t.at(-1)===""&&t.pop(),t.length%2!==0)return null;let r=new Map;for(let i=0;i<t.length;i+=2){let n=t[i],s=t[i+1];if(!n.startsWith(":")||!s)return null;r.set(s,n)}return r}function Xr(e,t){return[...new Set([...e.keys(),...t.keys()])].filter(i=>e.get(i)!==t.get(i))}function Yr(e,t,r){return e&&t?{kind:"watch-git-state",detail:"HEAD and index changed"}:e?{kind:"watch-git-head",detail:"HEAD changed"}:{kind:"watch-git-index",detail:r??"index changed"}}function Qr(e,t){return t===null?`${e}; changed paths unavailable`:t.length===0?e:t.length===1?t[0]:`${t.length} compiler inputs changed`}function Zr(e){return!e||e===".."||e.startsWith("../")}function ei(e){return e.endsWith("index.db")||e.endsWith("index.scip")||e.endsWith("index.db.tmp")||ur(e).startsWith(Ze)}function ti(e,t){return e.indexPath!==t.indexPath||e.indexMtimeMs!==t.indexMtimeMs||e.indexSize!==t.indexSize}function ri(e,t,r){return r.includes(".scipquery.json")&&$t(e,t),r.filter(i=>Ut(e,"add",i)!==null)}function ii(e,t,r,i){if(!t)return i;let n=t.has(r);if(i!=="add")return n?i:null;if(n)return"change";let s=Ht(e);return s?s.has(r)?"add":null:i}import{fileURLToPath as ni}from"url";var ee=class{constructor(t){this.opts=t}opts;running;cancellation;closed=!1;cleanupFailure;start(){if(this.closed||this.running||this.cleanupFailure)return;let t=new AbortController;this.cancellation=t,this.running=this.sweep(t.signal).catch(r=>{let i=r instanceof Error?r:new Error(String(r));if(i instanceof U&&!i.reaped&&(this.cleanupFailure=i),!t.signal.aborted)try{this.opts.onError(i)}catch(n){this.cleanupFailure=n instanceof Error?n:new Error(String(n))}}).finally(()=>{this.running=void 0})}async close(){if(this.closed=!0,this.cancellation?.abort(),await this.running,this.cleanupFailure)throw this.cleanupFailure}async sweep(t){let r=await(this.opts.run??H)({command:process.execPath,args:["--max-old-space-size=512",ni(this.opts.workerUrl??new URL("./repository-cache-worker.js",import.meta.url)),this.opts.projectRoot,this.opts.cliVersion],label:"repository cache maintenance",timeoutMs:Ke.analysis,maxStdoutBytes:8192,maxStderrBytes:8192,signal:t});if(r.status!==0)throw new Error(`Repository cache maintenance exited with ${r.status??r.signal}: ${r.stderr.trim()}`)}};var te=class{root;now;randomId;retryDelayMs;active;retryNotBeforeMs=0;currentStatus;constructor(t,r={}){this.root=t,this.now=r.now??Date.now,this.randomId=r.randomId,this.retryDelayMs=Math.max(1,Math.floor(r.retryDelayMs??1e3)),this.currentStatus=be(t)}initializeAfterOwnershipAcquired(){let t=gt(this.root),r=yt(this.root,{now:()=>new Date(this.now())});return this.refreshStatus(),{recoveredClaims:t,prunedHistory:r}}observeLegacyRequest(t,r){pt(this.root,r??"stale index observed by a legacy command",{idempotencyKey:`legacy-activity:${t}`,now:()=>new Date(t)}),this.refreshStatus()}poll(t,r){if(this.active||t.state!=="idle"||this.now()<this.retryNotBeforeMs)return!1;let i=mt(this.root,{now:()=>new Date(this.now()),...this.randomId?{randomId:this.randomId}:{}});if(this.refreshStatus(),i.requests.length===0)return!1;this.active=i;try{return r(si(i)),!0}catch(n){throw Re(this.root,i),this.active=void 0,this.retryNotBeforeMs=this.now()+this.retryDelayMs,this.refreshStatus(),n}}completeActive(){return this.active?(ft(this.root,this.active,()=>new Date(this.now())),this.active=void 0,this.retryNotBeforeMs=0,this.refreshStatus(),!0):!1}failActive(){return this.active?(Re(this.root,this.active),this.active=void 0,this.retryNotBeforeMs=this.now()+this.retryDelayMs,this.refreshStatus(),!0):!1}status(){return{...this.currentStatus}}refreshStatus(){this.currentStatus=be(this.root)}};function si(e){if(e.requests.length===1)return e.requests[0].detail;let r=[...new Set(e.requests.map(i=>i.detail))].slice(0,3).join("; ");return`${e.requests.length} coalesced refresh requests${r?`: ${r}`:""}`.slice(0,2048)}import{totalmem as di}from"os";import{randomUUID as ui}from"crypto";import{rmSync as hi}from"fs";import{Worker as pi}from"worker_threads";var re=class{constructor(t){this.options=t;if(this.now=t.now??Date.now,this.setTimer=t.setTimer??setTimeout,this.clearTimer=t.clearTimer??clearTimeout,t.maxWorkerFailureRetries!==void 0&&(!Number.isInteger(t.maxWorkerFailureRetries)||t.maxWorkerFailureRetries<0))throw new Error("Worker maxWorkerFailureRetries must be a non-negative integer.")}options;now;setTimer;clearTimer;worker=null;active=null;activeFailure=null;terminating=null;closed=!1;workerGeneration=0;idleTimer=null;canAccept(){return!this.closed&&this.active===null&&this.terminating===null}hasWorker(){return this.worker!==null}start(t){if(!this.canAccept())return!1;if(this.clearIdleTimer(),t.deadlineAtMs<this.now()){try{this.options.onReject(t,`${this.options.name} request expired before processing.`)}catch(n){this.closed=!0,this.options.onFatal(Ee(n))}return!0}let r=this.ensureWorker(),i=this.deadlineTimer(t);this.active={request:t,timer:i,workerFailureRetries:0,workerFailureReasons:[]};try{r.postMessage({kind:"request",...t})}catch(n){this.failActiveAfterTermination(Me(n),!0)}return!0}async close(t=`${this.options.name} service is shutting down.`){if(this.closed=!0,this.clearIdleTimer(),this.active){await this.failActiveAfterTermination(t);return}await this.terminateWorker()}ensureWorker(){if(this.worker)return this.worker;let t=this.options.createWorker(),r=++this.workerGeneration;return t.on("message",i=>this.handleMessage(r,i)),t.on("error",i=>{r===this.workerGeneration&&this.failActiveAfterTermination(`${this.options.name} worker failed: ${i.message}`,!0)}),t.on("exit",i=>{r!==this.workerGeneration||this.terminating||(this.worker=null,this.active&&this.failActiveAfterTermination(`${this.options.name} worker exited unexpectedly with code ${i}.`,!0))}),this.worker=t,t}handleMessage(t,r){if(t!==this.workerGeneration||this.closed||!this.active)return;let i=oi(r);if(!i){this.failActiveAfterTermination(`${this.options.name} worker returned an invalid response.`);return}if(i.requestId!==this.active.request.requestId){this.failActiveAfterTermination(`${this.options.name} worker returned a mismatched request identity.`);return}if(this.now()>this.active.request.deadlineAtMs){this.failActiveAfterTermination(`${this.options.name} request expired while it was processing.`);return}let n=this.active,s;try{s=ci(this.options,n,i)}catch(o){this.closed=!0,this.clearTimer(n.timer),this.options.onFatal(Ee(o));return}this.releaseActive(n),s?this.terminateWorker():this.scheduleIdleTermination()}async failActiveAfterTermination(t,r=!1){if(this.activeFailure){await this.activeFailure;return}let i=this.active;if(!i){await this.terminateWorker();return}this.clearTimer(i.timer),r&&i.workerFailureReasons.push(t);let n=(async()=>{if(!await this.terminateWorker())return;let o=this.options.maxWorkerFailureRetries??0;if(r&&!this.closed&&i.workerFailureRetries<o&&this.now()<=i.request.deadlineAtMs){i.workerFailureRetries+=1;try{let a=this.ensureWorker();i.timer=this.deadlineTimer(i.request),a.postMessage({kind:"request",...i.request});return}catch(a){let l=`Cold Worker retry failed: ${Me(a)}`;if(i.workerFailureReasons.push(l),t=`${t} ${l}`,!await this.terminateWorker())return}}let c=li(i.workerFailureReasons,t);try{this.options.onReject(i.request,c)}catch(a){this.closed=!0,this.options.onFatal(Ee(a));return}this.releaseActive(i)})();this.activeFailure=n;try{await n}finally{this.activeFailure===n&&(this.activeFailure=null)}}deadlineTimer(t){let r=Math.max(1,Math.min(2147483647,t.deadlineAtMs-this.now()));return this.setTimer(()=>{this.failActiveAfterTermination(`${this.options.name} request exceeded its deadline.`)},r)}releaseActive(t){this.active===t&&(this.active=null,this.clearTimer(t.timer))}scheduleIdleTermination(){let t=this.options.idleTtlMs;!t||t<=0||this.closed||this.active||!this.worker||(this.clearIdleTimer(),this.idleTimer=this.setTimer(()=>{this.idleTimer=null,!(this.closed||this.active||!this.worker)&&this.terminateWorker()},t))}clearIdleTimer(){this.idleTimer&&(this.clearTimer(this.idleTimer),this.idleTimer=null)}async terminateWorker(){if(this.clearIdleTimer(),this.terminating)return this.terminating;let t=this.worker;if(!t)return!0;this.worker=null;let r=++this.workerGeneration;return this.terminating=(async()=>{try{return await t.terminate(),!0}catch(i){return this.closed=!0,this.options.onFatal(new Error(`${this.options.name} worker termination failed: ${Me(i)}`,{cause:i})),!1}finally{r===this.workerGeneration&&(this.terminating=null)}})(),this.terminating}};function oi(e){if(!e||typeof e!="object")return null;let t=e;return t.kind!=="response"||typeof t.requestId!="string"||!("status"in t)||!ai(t)?null:t}function Ee(e){return e instanceof Error?e:new Error(String(e))}function Me(e){return e instanceof Error?e.message:String(e)}function ai(e){if(e.ok===!0){if(!("result"in e)||"error"in e)return!1}else if(e.ok===!1){if("result"in e||typeof e.error!="string")return!1}else return!1;return!0}function ci(e,t,r){return e.onStatus(r.status),r.ok?e.onComplete(t.request,r.result,r.status):e.onReject(t.request,r.error,r.status),e.retireAfterResponse?.(r.status)??!1}function li(e,t){return e.length===0?t:[...new Set([...e,t])].join(" Cold Worker retry: ")}var mi=6e4,fi=10*6e4;function Vt(e){let t=e.maxActiveSessions??8,r=e.workerSoftMemoryMb??Qt(e.workerHeapMb),i=()=>({protocolVersion:z,state:"idle",requests:0,sessionsCreated:0,sessionsReplaced:0,sessionsEvicted:0,activeSessions:0,maxActiveSessions:t,softMemoryLimitBytes:r*1024*1024,retireRequested:!1,initializations:0,programUpdates:0,documentsEmitted:0,documentsRemoved:0});return Jt({name:"TypeScript index",paths:e.paths,now:e.now,limits:e.limits,initialStatus:i,parseEnvelope:ot,createWorker:()=>Zt(e,{kind:"index",projectRoot:e.projectRoot,dbPath:e.dbPath,maxActiveSessions:t,softMemoryLimitMb:r}),complete(n,s,o,c){fe(e.paths,n,{ok:!0,protocolVersion:z,id:s.id,baseGeneration:s.baseGeneration,response:o},{nowMs:c,limits:e.limits})},reject(n,s,o,c){ge(e.paths,n,{ok:!1,protocolVersion:z,id:s,error:o},o,{nowMs:c,limits:e.limits})},idleTtlMs:e.workerIdleMs??fi,maxWorkerFailureRetries:1,retireAfterResponse:n=>n.retireRequested===!0,statusWhenWorkerAbsent:n=>({...n,state:"idle",activeSessions:0,heapUsedBytes:0,retireRequested:!1}),onBusy:e.onBusy,onFatal:e.onFatal})}function zt(e){let t=e.workerSoftMemoryMb??Qt(e.workerHeapMb),r=()=>({protocolVersion:K,state:"idle",requests:0,sessionsCreated:0,sessionsReused:0,sessionsRefreshed:0,sessionsReplaced:0,projectsCreated:0,softMemoryLimitBytes:t*1024*1024,retireRequested:!1});return Jt({name:"TypeScript semantic",paths:e.paths,now:e.now,limits:e.limits,initialStatus:r,parseEnvelope:ht,createWorker:()=>Zt(e,{kind:"semantic",projectRoot:e.projectRoot,softMemoryLimitMb:t}),complete(i,n,s,o){fe(e.paths,i,{ok:!0,protocolVersion:K,id:n.id,generation:n.generation,response:s},{nowMs:o,limits:e.limits})},reject(i,n,s,o){ge(e.paths,i,{ok:!1,protocolVersion:K,id:n,error:s},s,{nowMs:o,limits:e.limits})},idleTtlMs:mi,maxWorkerFailureRetries:1,retireAfterResponse:i=>i.retireRequested===!0,statusWhenWorkerAbsent:i=>({...i,state:"idle",heapUsedBytes:0,retireRequested:!1}),onBusy:e.onBusy,onFatal:e.onFatal})}function Jt(e){let t=e.now??Date.now,r=P(process.pid),i={pid:process.pid,...r?{processIdentity:r}:{}},n=`${e.name.toLowerCase().replaceAll(" ","-")}-${process.pid}-${ui()}`,s={...e.limits,maxBatch:1},o=null,c=e.initialStatus(),a=!1,l=m=>{a=!0,e.onFatal(m)},u=new re({name:e.name,createWorker:e.createWorker,now:t,idleTtlMs:e.idleTtlMs,maxWorkerFailureRetries:e.maxWorkerFailureRetries,retireAfterResponse:e.retireAfterResponse,onComplete(m,y,f){let g=d(m.requestId);c=f;let E=t();try{e.complete(g.claim,g.envelope,y,E)}catch(w){if(!(w instanceof pe))throw w;try{e.reject(g.claim,g.envelope.id,w.message,E)}catch(M){if(!(M instanceof pe))throw M;hi(g.claim.path,{force:!0})}}p(g)},onReject(m,y,f){let g=d(m.requestId);f!==void 0&&(c=f),e.reject(g.claim,g.envelope.id,y,t()),p(g)},onStatus(m){c=m},onFatal:l});return{poll(){if(a||!u.canAccept())return 0;let m=rt(e.paths,{ownerId:n,nowMs:t(),limits:s,owner:i,liveness:{isProcessAlive:ze,readProcessIdentity:P}})[0];if(!m)return 0;let y=m.requestId;try{let f=e.parseEnvelope(it(m,s));if(y=f.id,f.id!==m.requestId)throw new Error(`${e.name} request identity does not match its mailbox path.`);if(f.deadlineAtMs<t())throw new Error(`${e.name} request expired before processing.`);if(o={claim:m,envelope:f},e.onBusy?.(f.deadlineAtMs),!u.start({requestId:f.id,deadlineAtMs:f.deadlineAtMs,payload:f}))throw new Error(`${e.name} worker lane closed admission after claiming a request.`)}catch(f){let g=Ri(f);try{e.reject(m,y,g,t()),o?.claim===m&&p(o)}catch(E){l(vi(E))}}return 1},status(){return{...u.hasWorker()||!e.statusWhenWorkerAbsent?c:e.statusWhenWorkerAbsent(c),mailbox:nt(e.paths)}},async close(m){await u.close(m)}};function d(m){let y=o;if(!y||y.envelope.id!==m)throw new Error(`${e.name} parent lost the active mailbox claim.`);return y}function p(m){o===m&&(o=null,e.onBusy?.(void 0))}}var Kt=6144;function Xt(){let e=Number.parseInt(process.env.SCIP_TS_WORKER_HEAP_MB??"",10);return Number.isFinite(e)&&e>0?e:Kt}var gi=.6;function Yt(e,t=yi()){let r=Number.parseInt(process.env.SCIP_TS_WORKER_HEAP_MB??"",10);if(Number.isFinite(r)&&r>0)return r;let i=Math.ceil(Xe+e*Ye),n=Math.floor(t*gi/(1024*1024));return Math.max(Kt,Math.min(i,n))}function yi(e=Si,t=di()){let r=[e("/sys/fs/cgroup/memory.max"),e("/sys/fs/cgroup/memory/memory.limit_in_bytes")].map(i=>i===null?Number.NaN:Number.parseInt(i.trim(),10)).filter(i=>Number.isFinite(i)&&i>0&&i<t);return r.length>0?Math.min(...r):t}function Si(e){try{return Ne(e,{maxBytes:Oe,inputKind:"cgroup memory limit"})}catch{return null}}function Qt(e){return Math.max(1,Math.floor((e??Xt())*.9))}function Zt(e,t){if(e.createWorker)return e.createWorker(t);let r=e.workerUrl??new URL("./typescript-mailbox-worker.js",import.meta.url);return new pi(r,{workerData:t,resourceLimits:{maxOldGenerationSizeMb:e.workerHeapMb??Xt()}})}function vi(e){return e instanceof Error?e:new Error(String(e))}function Ri(e){return e instanceof Error?e.message:String(e)}var tr=2e3,Pi=5e3,Ti=5e3,Ii=6e4,ki=10,Ei=50,Mi=1e4;function Wi(e,t=1){return Je(e,t,ki,Ei,Mi,8)}function Ci(e,t){let r;return{begin(){return r||(t.requestStop(),t.closeWake(),r=e.stop(),r.catch(()=>{})),r}}}async function Ai(e,t){let r=t.processIndexRequests(),i=t.processSemanticRequests(),n=r+i,s=n>0?0:e+1;if(t.afterMailboxPoll({indexRequests:r,semanticRequests:i,processedRequests:n}),t.shouldStop())return{indexRequests:r,semanticRequests:i,processedRequests:n,consecutiveIdlePolls:s,stopped:!0};let o=Wi(n,s);return await t.wait(o),{indexRequests:r,semanticRequests:i,processedRequests:n,consecutiveIdlePolls:s,stopped:!1,delayMs:o}}function _i(e){return e==="fresh"?null:{kind:"watch-startup",detail:`index ${e} when watch service started`}}function Li(e){vt(e.statePath,{version:1,protocolVersion:at,pid:S.pid,...e.processIdentity?{processIdentity:e.processIdentity}:{},projectRoot:e.projectRoot,...e.worktreeId?{worktreeId:e.worktreeId}:{},cliVersion:e.cliVersion,startedAt:new Date(e.startedAtMs).toISOString(),heartbeatAt:new Date(e.nowMs).toISOString(),lastActivityAt:new Date(e.lastActivityAtMs).toISOString(),...e.idleTimeoutMs===0?{}:{idleDeadlineAt:new Date(e.lastActivityAtMs+e.idleTimeoutMs).toISOString()},watcher:e.watcherStatus,...e.watcherStatus.state==="idle"&&e.indexGeneration?{indexGeneration:e.indexGeneration}:{},...e.lastRefresh?{lastRefresh:e.lastRefresh}:{},...e.lastError?{lastError:e.lastError}:{},reindexActivity:e.reindexActivity,refreshRequests:e.refreshCoordinator.status(),typescriptSemantic:{...e.semanticLane.status(),...e.semanticBusyUntilMs===void 0?{}:{busyUntil:new Date(e.semanticBusyUntilMs).toISOString()}},typescriptIndex:{...e.indexLane.status(),...e.indexBusyUntilMs===void 0?{}:{busyUntil:new Date(e.indexBusyUntilMs).toISOString()}}},{durability:e.durability})}function ji(e){let t=0,r=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY,n=Number.NEGATIVE_INFINITY,s=Number.NEGATIVE_INFINITY;function o(c){let a=Rt(e.activityPath);a&&e.updateObservedActivity(a.atMs,c),a?.refreshRequestedAtMs!==void 0&&a.refreshRequestedAtMs>t&&(t=a.refreshRequestedAtMs,e.refreshCoordinator.observeLegacyRequest(a.refreshRequestedAtMs,a.refreshDetail??"stale index observed by a legacy command"))}return({processedRequests:c})=>{let a=T();if(a-i>=Ti&&(i=a,!It(e.worktreeLiveness))){e.requestStop();return}a-s>=Ii&&(s=a,ye(e.indexMailboxPaths),ye(e.semanticMailboxPaths)),a-n>=xt&&(n=a,e.requestCacheSweep()),a-r>=Pi&&(r=a,o(a)),e.refreshCoordinator.poll(e.watcherStatus(),l=>{e.recordActivity(),e.requestRefresh(l)}),c>0&&(e.recordActivity(),e.persistState(!0,"visibility")),e.persistState()}}async function Fi(e){let t,r=0,i=!1,n,s;S.once("SIGINT",e.stopSignal),S.once("SIGTERM",e.stopSignal);try{e.watcher.start();let o=e.initializeFreshness();for(e.recordActivity(),e.markReady(),e.persistState(!0),t=setInterval(()=>{try{e.persistState()}catch(c){i=!0,n=c;try{e.stopSignal()}catch(a){n=new AggregateError([c,a],"Watch heartbeat and stop request both failed.")}}},tr),t.unref?.(),o&&e.requestRefresh(o);!i&&!e.stopRequested();){let c=await Ai(r,{processIndexRequests:e.processIndexRequests,processSemanticRequests:e.processSemanticRequests,afterMailboxPoll:e.afterMailboxPoll,shouldStop:e.shouldStop,wait:e.wait});if(r=c.consecutiveIdlePolls,c.stopped)break}}catch(o){i=!0,n=o}finally{S.off("SIGINT",e.stopSignal),S.off("SIGTERM",e.stopSignal),t!==void 0&&clearInterval(t),s=await Oi(e)}Vi(e,i,n,s)}async function Oi(e){let[t,r]=await Promise.allSettled([Promise.resolve().then(()=>e.shutdown.begin()),Promise.resolve().then(()=>e.closeLanes())]),i=[t,r].flatMap(n=>n.status==="rejected"?[n.reason instanceof Error?n.reason.message:String(n.reason)]:[]);try{return Ni(e,t.status==="fulfilled"?t.value:{state:"degraded",reasons:[]},i)}catch(n){return n instanceof Error?n:new Error(String(n))}}function Ni(e,t,r=[]){let i=[...r,...t.state==="stopped"?[]:t.reasons],n=e.mailboxFatalError();if(n&&i.push(n.message),i.length>0)return e.finalizeDegraded(i);e.finalizeStopped()}function Di(e){try{let t=new bi(e,{readonly:!0,fileMustExist:!0});try{return t.prepare("SELECT count(*) AS documents FROM documents").get().documents}finally{t.close()}}catch{return 0}}function qi(e){let t=e.config.indexer?.typescript,r=t?.workerHeapMb??Yt(Di(e.dbPath)),i=zt({paths:e.semanticPaths,projectRoot:e.projectRoot,workerHeapMb:r,onBusy:e.onSemanticBusy,onFatal:e.onFatal}),n=Vt({paths:e.indexPaths,projectRoot:e.projectRoot,dbPath:e.dbPath,...t?.maxWarmSessions===void 0?{}:{maxActiveSessions:t.maxWarmSessions},...t?.workerIdleMs===void 0?{}:{workerIdleMs:t.workerIdleMs},...t?.workerSoftMemoryMb===void 0?{}:{workerSoftMemoryMb:t.workerSoftMemoryMb},workerHeapMb:r,onBusy:e.onIndexBusy,onFatal:e.onFatal});return{semanticLane:i,indexLane:n}}async function Gi(e,t,r={}){let i=St(e,t),n=i.projectRoot,s=i.worktreeKind==="git"?Bi(n,i.worktreeId):void 0,o=Tt(n,s),c=N(n);c.watch={...c.watch,...r};let a=J(c);if(!a.enabled)throw new Error('watch mode is disabled; set "watch.enabled": true before starting the service');let l=O(n,c),u=ct(l.cacheDir),d=P(S.pid),p=bt(u.lockPath,n,{readProcessIdentity:f=>f===S.pid?d:P(f)});if(!p.acquired)return;let m=!1,y;try{let f=new te(u.refreshRequestsPath,{retryDelayMs:Math.max(1e3,a.cooldownMs)});f.initializeAfterOwnershipAcquired();let g=Date.now(),E=T(),w=g,M=E,G={state:"idle"},L,ie,x,ne,se=V(l.dbPath),B=!1,We=!1,Ce=Number.NEGATIVE_INFINITY,Ae,_e,j=ut(l.cacheDir),F=st(l.cacheDir);me(j),me(F);let oe=ve([F.pendingDir,F.legacyRequestDir,j.pendingDir,j.legacyRequestDir,u.refreshRequestsPath]);y=()=>oe.close();let v=(h=!1,I=h?"durable":"visibility")=>{if(!We)return;let le=Date.now(),C=T();!h&&C-Ce<tr||(Ce=C,Li({statePath:u.statePath,durability:I,processIdentity:d,projectRoot:n,worktreeId:i.worktreeId,cliVersion:t,startedAtMs:g,nowMs:le,lastActivityAtMs:w,idleTimeoutMs:a.idleTimeoutMs,watcherStatus:G,indexGeneration:L,lastRefresh:ie,lastError:x,reindexActivity:se,refreshCoordinator:f,semanticLane:ae,indexLane:ce,semanticBusyUntilMs:Ae,indexBusyUntilMs:_e}))},W=()=>{w=Date.now(),M=T()},Le=new ee({projectRoot:n,cliVersion:t,onError(h){x={at:new Date().toISOString(),message:h.message},v(!0,"visibility")}}),rr=h=>{W(),ne??=h,x={at:new Date().toISOString(),message:h.message},v(!0,"visibility")},{semanticLane:ae,indexLane:ce}=qi({semanticPaths:j,indexPaths:F,projectRoot:n,dbPath:l.dbPath,config:c,onSemanticBusy(h){Ae=h===void 0?void 0:h+5e3,v(!0,"visibility")},onIndexBusy(h){_e=h===void 0?void 0:h+5e3,v(!0,"visibility")},onFatal:rr}),$=new Z({projectRoot:n,config:{...c,watch:a},outputDb:l.dbPath,languages:c.languages,onStatus(h){G=h,h.state!=="idle"&&(L=void 0),h.state!=="idle"&&W(),v(!0)},onReindexComplete(h,I,le){W();let C=le?.pendingChanges!==!1?D(n,c,l):dt(l);return ie=C.lastRefresh,L=C.state==="fresh"?A(l.dbPath)??void 0:void 0,se=V(l.dbPath),f.completeActive(),x=void 0,v(!0),C.state==="fresh"},onReindexError(){f.failActive()},onRefreshSuppressed(h){let I=et(l.dbPath,h);I.state==="failed"&&(x={at:new Date().toISOString(),message:`Suppressed-refresh telemetry was not recorded: ${I.reason}`},v(!0,"visibility")),se=V(l.dbPath)},onError(h){W(),L=void 0,x={at:new Date().toISOString(),message:h.message},v(!0)}}),je=Ci($,{requestStop(){B=!0},closeWake(){oe.close()}}),ir=()=>{je.begin()},nr=ji({worktreeLiveness:o,indexMailboxPaths:F,semanticMailboxPaths:j,requestCacheSweep:()=>Le.start(),activityPath:u.activityPath,refreshCoordinator:f,watcherStatus:()=>G,requestRefresh:h=>$.requestRefresh({kind:"watch-demand",detail:h},{immediate:!0}),requestStop:()=>{B=!0},recordActivity:W,updateObservedActivity(h,I){h<=w||(w=h,M=I)},persistState:v});m=!0,await Fi({watcher:$,shutdown:je,stopSignal:ir,initializeFreshness(){let h=D(n,c,l);return ie=h.lastRefresh,L=h.state==="fresh"?A(l.dbPath)??void 0:void 0,_i(h.state)},markReady:()=>{We=!0},recordActivity:W,persistState:v,requestRefresh:h=>$.requestRefresh(h,{immediate:!0}),stopRequested:()=>B,processIndexRequests:()=>ce.poll(),processSemanticRequests:()=>ae.poll(),afterMailboxPoll:nr,shouldStop:()=>B||ne!==void 0||wt({watcher:G,lastActivityAtMs:M,nowMs:T(),idleTimeoutMs:a.idleTimeoutMs}),wait:h=>oe.wait(h),closeLanes:()=>Promise.all([ae.close("TypeScript semantic service stopped before completing the request."),ce.close("TypeScript index service stopped before completing the request."),Le.close()]).then(()=>{}),mailboxFatalError:()=>ne,finalizeStopped(){try{er(u.statePath,{force:!0})}finally{try{er(u.activityPath,{force:!0})}finally{p.release()}}},finalizeDegraded(h){return x={at:new Date().toISOString(),message:`Watch service shutdown is degraded: ${h.join("; ")}`},v(!0),new Error(x.message)}})}finally{if(!m)try{y?.()}finally{p.release()}}}function Bi(e,t){let r=qe(e);if(r.kind!=="worktree"||r.identity.worktreeId!==t)throw new Error(`Git worktree identity changed while starting the watch service for ${e}.`);return r.identity.gitDir}function $i(e,t={report:r=>console.error(r),exit:r=>S.exit(r)}){return t.report(`watch-service: ${lt(e instanceof Error?e.message:String(e))}`),t.exit(1)}var Ui=S.argv[1]?xi(wi(S.argv[1])).href:null;if(Ui===import.meta.url){let e=S.argv[2],t=S.argv[3],r=Hi(S.argv[4]);if(!e||!t)console.error("watch-service: expected <project-root> <cli-version>"),S.exitCode=1;else try{await Gi(e,t,r)}catch(i){$i(i)}}function Hi(e){if(!e)return{};try{let t=JSON.parse(e);return t&&typeof t=="object"?t:{}}catch{return{}}}function Vi(e,t,r,i){let n=e.mailboxFatalError();if(!t&&n&&(t=!0,r=n),t&&i)throw new AggregateError([r,i],"Watch service execution and shutdown both failed.");if(t)throw r;if(i)throw i}export{ve as createPathChangeWake,Ci as createWatchServiceShutdown,Fi as runWatchServiceLifecycle,Ai as runWatchServiceLoopIteration,Gi as runWatchServiceServer,_i as startupRefreshTrigger,$i as terminateWatchServiceProcess,Wi as watchServiceLoopDelayMs};
|
|
4
4
|
//# sourceMappingURL=watch-server.js.map
|
package/docs/AGENT_GUIDE.md
CHANGED
|
@@ -1,148 +1,39 @@
|
|
|
1
1
|
# Agent guide
|
|
2
2
|
|
|
3
|
-
scip-query
|
|
4
|
-
tests, and final decision.
|
|
3
|
+
Use ordinary search and file tools to read implementation details. Use scip-query to connect code locations through calls, value flow, runtime handoffs and dependencies, and to identify evidence of maintenance problems. The agent owns the plan, changes, tests and final judgment.
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
Load only the relevant [bundled skill](SKILLS.md). A local lookup needs no analysis ceremony.
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
construct ownership; navigate typed compiler and runtime relationships; account
|
|
10
|
-
for every omitted direction; read connected behavior for the selected path;
|
|
11
|
-
then retrieve exact current source only where full implementation detail can
|
|
12
|
-
change the decision.
|
|
7
|
+
## Explore and plan
|
|
13
8
|
|
|
14
|
-
For
|
|
15
|
-
material claims the answer must establish. Locate exact referents with `search`,
|
|
16
|
-
`outline`, or `entrypoints`, then choose the relationship families and directions
|
|
17
|
-
capable of establishing each claim. Use `--symbol` only for a printed compiler
|
|
18
|
-
identity and `--at` for an exact construct location. Batch independent roots:
|
|
9
|
+
For an unfamiliar repository, `scip-query system --source` shows current TS/JS module groups and their dependencies, including groups without findings. Select a printed group or exact path for its files, export declarations and import sites. Directory membership does not establish business responsibility.
|
|
19
10
|
|
|
20
|
-
|
|
21
|
-
scip-query evidence \
|
|
22
|
-
--symbol <symbol> \
|
|
23
|
-
--edge execution \
|
|
24
|
-
--edge runtime \
|
|
25
|
-
--direction both \
|
|
26
|
-
--depth 2 \
|
|
27
|
-
--max-edges 32
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
Read the returned facts, evidence strength, provider support, coverage, folds,
|
|
31
|
-
and recovery paths together. Query completion accounts for the requested bounded
|
|
32
|
-
projection; it does not mean the user's task is complete. If a material claim
|
|
33
|
-
still requires implementation behavior, resolve its exact constructs with one
|
|
34
|
-
batched `inspect --view behavior` call. Use `code` only when exact syntax can
|
|
35
|
-
change the decision. Do not enumerate unrelated helpers, examples, tests, or
|
|
36
|
-
frontiers. Query count measures efficiency but never makes a recoverable material
|
|
37
|
-
claim optional.
|
|
11
|
+
Before a substantial change, trace the existing operation from its initiating surface through the shared owner to the observable outcome. Find comparable features and conventions. Document reuse, extension points, affected consumers, preserved behavior and verification in the plan. Reading implementation details with ordinary tools remains part of this investigation.
|
|
38
12
|
|
|
39
|
-
|
|
40
|
-
Evidence seen but left implicit in the draft is not recovered. Copy returned
|
|
41
|
-
file and line identities exactly instead of reconstructing citation paths.
|
|
42
|
-
|
|
43
|
-
A broad literal is counted exactly and returned with recoverable structural
|
|
44
|
-
scopes. Narrow only when a named material claim requires one of those scopes.
|
|
45
|
-
Exact edges are facts within their reported coverage. Derived or candidate edges
|
|
46
|
-
and unsupported dynamic frontiers require the displayed source, another exact
|
|
47
|
-
referent, or an explicit limitation—not an absence claim.
|
|
48
|
-
|
|
49
|
-
When one known target is already the center of the change, run the aggregate
|
|
50
|
-
context query:
|
|
13
|
+
Use `scip-query context <target>` for reuse and impact candidates. For a concrete relationship question, use exact locations already found in source:
|
|
51
14
|
|
|
52
15
|
```bash
|
|
53
|
-
scip-query
|
|
16
|
+
scip-query evidence --at src/service.ts:42 --edge execution --direction incoming --depth 1 --max-edges 30
|
|
54
17
|
```
|
|
55
18
|
|
|
56
|
-
|
|
57
|
-
focused query only when a named uncertainty can change that plan.
|
|
19
|
+
Incoming execution finds callers; outgoing execution finds callees. Dataflow follows values, runtime follows handoffs, and dependencies show static reliance. Select other families only when they answer the question. Candidate relationships require source confirmation. Static relationships do not prove that an invocation occurred.
|
|
58
20
|
|
|
59
|
-
|
|
60
|
-
instead of native search or source reads. Native tools are for applying edits,
|
|
61
|
-
running checks, binary content, or a specific unsupported gap that scip-query
|
|
62
|
-
has explicitly reported.
|
|
21
|
+
`search`, `outline`, `entrypoints`, `code` and `inspect` remain optional when symbol identity, nesting, external roots or grouped source reads help. `code --bindings` and `inspect --bindings` explicitly add referenced literal values. Do not repeatedly read source that is already available.
|
|
63
22
|
|
|
64
|
-
##
|
|
23
|
+
## Review changes and maintenance findings
|
|
65
24
|
|
|
66
|
-
Run
|
|
67
|
-
change can propagate:
|
|
25
|
+
Run appropriate behavioral checks, then use `scip-query review --base HEAD` for changed-function quality and `scip-query diff-impact` for downstream consumers. Check `scip-query architecture` when dependencies or configured policy changed. Use `scip-query health` for current-source complexity, duplication and dependency findings; use `health --indexed` only for a relevant specialist question.
|
|
68
26
|
|
|
69
|
-
|
|
70
|
-
scip-query diff-impact
|
|
71
|
-
```
|
|
27
|
+
Findings identify possible work; they do not authorize automatic refactors. Confirm the defect and preserve authorization, decisions, errors, state identity, ordering, concurrency and cleanup. Missing test coverage is unavailable, never measured zero. Keep justified suppression records with the change; do not lower thresholds or widen rules to clear a report.
|
|
72
28
|
|
|
73
|
-
|
|
29
|
+
## Read only useful output
|
|
74
30
|
|
|
75
|
-
|
|
76
|
-
scip-query architecture
|
|
77
|
-
```
|
|
31
|
+
Ordinary oversized results are saved once to a temporary file with a short preview and exact path. Search/read the file selectively. Small results stay inline. Redirect output to a chosen file when it needs to persist; temporary saved previews expire or can be reclaimed under storage pressure.
|
|
78
32
|
|
|
79
|
-
|
|
80
|
-
detector command. Confirm heuristic candidates in source before editing them.
|
|
33
|
+
Use `--json --json-output <path>` for programmatic filtering. Explicit pagination remains a compatibility option; reconstruct explicit JSON pages before parsing them. There is no ordinary requirement to drain pages or read every saved byte. A saved result preserves the query's output, not proof of exhaustive analysis.
|
|
81
34
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
scip-query vue-composable-candidates --full
|
|
86
|
-
```
|
|
35
|
+
Respect actual omitted, stale, unsupported or unresolved evidence. An empty bounded result cannot establish absence. Use `evidence --detail` for full provider explanations when their limitations matter. Stop when the relevant facts are established or the remaining limitations are explicit.
|
|
36
|
+
|
|
37
|
+
## Tool problems
|
|
87
38
|
|
|
88
|
-
|
|
89
|
-
scip-query adds relationship and cleanup evidence.
|
|
90
|
-
|
|
91
|
-
## Efficient use
|
|
92
|
-
|
|
93
|
-
- Use `search` for an unknown literal anchor in indexed source.
|
|
94
|
-
- Use `system-map` before source drilldown when several layers or subsystems may
|
|
95
|
-
participate. Treat its connected behavior as source already read. Follow an
|
|
96
|
-
unresolved frontier only when it can answer a named material uncertainty.
|
|
97
|
-
- Use a behavior-view `inspect` packet for several related locations. Escalate
|
|
98
|
-
to `code` only for known exact definitions or ranges whose complete source
|
|
99
|
-
can change the decision. An exact
|
|
100
|
-
file path returns exported definitions (or top-level definitions when no
|
|
101
|
-
explicit export surface exists) plus same-file definitions they reference
|
|
102
|
-
and a complete ledger of omitted local definitions. Use
|
|
103
|
-
`--members all` only when the whole file matters. If the command refuses an
|
|
104
|
-
oversized packet, it emitted no partial source; narrow to the exact units
|
|
105
|
-
still needed before deciding whether every split remains necessary.
|
|
106
|
-
- After the map, put known text, symbol, and file-line gaps into one
|
|
107
|
-
`scip-query inspect --symbol <symbol> --at <file:line> --view behavior`
|
|
108
|
-
packet. Read its exact selector cardinality, per-channel evidence coverage,
|
|
109
|
-
omission ledger, and query completion. Stop when no named fact remains
|
|
110
|
-
unanswered. Otherwise drill into several relevant omission groups together;
|
|
111
|
-
omit the behavior view only for exact units whose full implementation can
|
|
112
|
-
change the decision, and use `--full` only when all omitted evidence can change it.
|
|
113
|
-
`--full` and `--limit` are mutually exclusive; never combine them.
|
|
114
|
-
- Treat returned, line-numbered source as citation-ready and already read.
|
|
115
|
-
Native tools are for applying edits, running checks, binary content, or a
|
|
116
|
-
specific unsupported gap that scip-query has explicitly reported.
|
|
117
|
-
- Do not repeat an unchanged query after context compaction.
|
|
118
|
-
- Do not claim that a caller, route, branch, poller, or consumer is absent from
|
|
119
|
-
a bounded result. Use `--full` only when complete coverage can change a
|
|
120
|
-
decision.
|
|
121
|
-
- Do not claim what every callsite passes unless the `trace` or `evidence`
|
|
122
|
-
claim-support section marks callsite-argument claims eligible. A complete
|
|
123
|
-
call expression contains the callee and every argument through the closing
|
|
124
|
-
delimiter; a bounded context window does not.
|
|
125
|
-
- Search always reports exact match cardinality. Small results list every
|
|
126
|
-
matching path-line identity and owner; broad results stop lower-ranked
|
|
127
|
-
identities before output transport and return a representative manifest plus
|
|
128
|
-
ranked scope commands. There is no transport cursor to drain. Narrow to a
|
|
129
|
-
distinctive literal or one relevant scope; use `search --full` only after
|
|
130
|
-
deliberately narrowing when every remaining source window matters.
|
|
131
|
-
- With an explicit `SCIP_QUERY_SESSION`, a complete source unit, a
|
|
132
|
-
byte-identical exact subset of a prior exact source read, or a graph unit/edge
|
|
133
|
-
may be replaced by a visible receipt from the same index generation. Preview
|
|
134
|
-
coverage never suppresses an exact unit; changed bytes, changed graph
|
|
135
|
-
content, a new generation, or `--reemit` force full evidence.
|
|
136
|
-
- Follow an emitted `Continue exactly:` command until transport is complete.
|
|
137
|
-
Coverage expansion commands are optional drilldowns, not transport pages.
|
|
138
|
-
- Use human output for model reading and `--json --result-only` for programs.
|
|
139
|
-
- Never rerun a successful human command as JSON. Before each drilldown, name
|
|
140
|
-
the still-unanswered fact and stop when none remains; every additional
|
|
141
|
-
reasoning step pays again for the accumulated context.
|
|
142
|
-
- Commit relevant suppression files, but do not create work-state records.
|
|
143
|
-
|
|
144
|
-
## Setup failures
|
|
145
|
-
|
|
146
|
-
Use `scip-query doctor` when a query reports that the tool or index is not
|
|
147
|
-
usable. Use `scip-query status --capabilities` to see which evidence providers
|
|
148
|
-
are available.
|
|
39
|
+
Start with `scip-query status` or `scip-query doctor` for a reported installation/index issue. Respect disabled watchers and configured rebuild policy. Use the setup skill only for tool operations.
|
package/docs/CLI_JSON_OUTPUT.md
CHANGED
|
@@ -243,21 +243,25 @@ Every command accepts these global options:
|
|
|
243
243
|
--output-cursor <cursor>
|
|
244
244
|
```
|
|
245
245
|
|
|
246
|
-
Run commands normally without choosing a page size. Human output
|
|
247
|
-
6,500 characters is
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
246
|
+
Run commands normally without choosing a page size. Human output exceeding
|
|
247
|
+
6,500 characters or UTF-8 bytes is saved once to a private temporary file. The
|
|
248
|
+
terminal receives its absolute path and a preview of at most 1,800 bytes and
|
|
249
|
+
24 lines. Read or search the file selectively with ordinary tools; no
|
|
250
|
+
`continue` request is required. The file contains the complete rendered output,
|
|
251
|
+
including any analysis limitations, and is never recomputed while reading.
|
|
252
|
+
Temporary results expire after one hour and the oldest saved previews may be
|
|
253
|
+
removed earlier under the shared 32-file/256-MiB storage quota. Redirect stdout
|
|
254
|
+
to your own file when the result needs to persist. Small results and ordinary
|
|
255
|
+
shell redirects remain unchanged. JSON pipelines retain their machine contract.
|
|
256
|
+
|
|
257
|
+
`--output-page-size` explicitly enables the compatibility pagination mode.
|
|
258
|
+
Each partial page prints a continuation command for retrieving another part
|
|
259
|
+
of the same immutable output. Its size is a character limit, additionally
|
|
260
|
+
bounded by UTF-8 bytes; it does not count rows, results or model tokens. Read
|
|
261
|
+
additional pages only when the omitted details matter. A preview or page cannot
|
|
262
|
+
establish a claim about omitted evidence. Pages prefer complete line boundaries;
|
|
263
|
+
long individual lines may be split. Explicit JSON pages must be reassembled
|
|
264
|
+
before parsing their complete JSON payload.
|
|
261
265
|
|
|
262
266
|
Default `--json` output remains the ordinary, additively extensible
|
|
263
267
|
`scip-query-result` envelope. When that envelope exceeds
|
|
@@ -302,8 +306,8 @@ same prefix that created it.
|
|
|
302
306
|
A genuinely partial JSON page must carry `content` as a string because an
|
|
303
307
|
arbitrary character boundary is not necessarily valid nested JSON. Run the
|
|
304
308
|
emitted continuation exactly until completion. Normal agent work should use
|
|
305
|
-
human output, where
|
|
306
|
-
|
|
309
|
+
human output, where oversized results are saved as readable files with short
|
|
310
|
+
previews. Model-facing JSON must use `--agent-output`; that mode selects the
|
|
307
311
|
command's bounded projection and automatically enables cursor transport even
|
|
308
312
|
when the caller did not provide `--output-page-size`.
|
|
309
313
|
|