@ashx-j/lunr-dev 0.2.13-dev.7.1 → 0.2.16-dev.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -1
- package/dist/builtin-extensions/ashxj-tui.d.ts +14 -0
- package/dist/builtin-extensions/ashxj-tui.d.ts.map +1 -1
- package/dist/builtin-extensions/ashxj-tui.js +37 -3
- package/dist/builtin-extensions/ashxj-tui.js.map +1 -1
- package/dist/builtin-extensions/index.d.ts +1 -15
- package/dist/builtin-extensions/index.d.ts.map +1 -1
- package/dist/builtin-extensions/index.js +7 -21
- package/dist/builtin-extensions/index.js.map +1 -1
- package/dist/builtin-extensions/narumiruna-pi-goal/src/goal.d.ts.map +1 -1
- package/dist/builtin-extensions/narumiruna-pi-goal/src/goal.js +6 -2
- package/dist/builtin-extensions/narumiruna-pi-goal/src/goal.js.map +1 -1
- package/dist/builtin-extensions/pi-lsp-extension/src/index.d.ts +4 -0
- package/dist/builtin-extensions/pi-lsp-extension/src/index.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-lsp-extension/src/index.js +163 -169
- package/dist/builtin-extensions/pi-lsp-extension/src/index.js.map +1 -1
- package/dist/builtin-extensions/pi-lsp-extension/src/runtime.d.ts +46 -0
- package/dist/builtin-extensions/pi-lsp-extension/src/runtime.d.ts.map +1 -0
- package/dist/builtin-extensions/pi-lsp-extension/src/runtime.js +109 -0
- package/dist/builtin-extensions/pi-lsp-extension/src/runtime.js.map +1 -0
- package/dist/builtin-extensions/pi-mcp-adapter/direct-tool-executor.d.ts +7 -0
- package/dist/builtin-extensions/pi-mcp-adapter/direct-tool-executor.d.ts.map +1 -0
- package/dist/builtin-extensions/pi-mcp-adapter/direct-tool-executor.js +211 -0
- package/dist/builtin-extensions/pi-mcp-adapter/direct-tool-executor.js.map +1 -0
- package/dist/builtin-extensions/pi-mcp-adapter/direct-tools.d.ts +0 -5
- package/dist/builtin-extensions/pi-mcp-adapter/direct-tools.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-mcp-adapter/direct-tools.js +0 -202
- package/dist/builtin-extensions/pi-mcp-adapter/direct-tools.js.map +1 -1
- package/dist/builtin-extensions/pi-mcp-adapter/index.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-mcp-adapter/index.js +251 -94
- package/dist/builtin-extensions/pi-mcp-adapter/index.js.map +1 -1
- package/dist/builtin-extensions/pi-mcp-adapter/init.d.ts +4 -1
- package/dist/builtin-extensions/pi-mcp-adapter/init.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-mcp-adapter/init.js +10 -3
- package/dist/builtin-extensions/pi-mcp-adapter/init.js.map +1 -1
- package/dist/builtin-extensions/pi-mcp-adapter/metadata-cache.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-mcp-adapter/metadata-cache.js +6 -1
- package/dist/builtin-extensions/pi-mcp-adapter/metadata-cache.js.map +1 -1
- package/dist/builtin-extensions/pi-prompt-template-model/prompt-loader.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-prompt-template-model/prompt-loader.js +2 -1
- package/dist/builtin-extensions/pi-prompt-template-model/prompt-loader.js.map +1 -1
- package/dist/builtin-extensions/pi-prompt-template-model/tool-manager.d.ts +1 -1
- package/dist/builtin-extensions/pi-prompt-template-model/tool-manager.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-prompt-template-model/tool-manager.js +1 -1
- package/dist/builtin-extensions/pi-prompt-template-model/tool-manager.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/index.d.ts +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/index.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/index.js +38 -14
- package/dist/builtin-extensions/pi-subagents/src/extension/index.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/fork-context.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/fork-context.js +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/fork-context.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/slash/slash-commands.d.ts +1 -1
- package/dist/builtin-extensions/pi-subagents/src/slash/slash-commands.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/slash/slash-commands.js +1 -1
- package/dist/builtin-extensions/pi-subagents/src/slash/slash-commands.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/tui/render.d.ts +1 -1
- package/dist/builtin-extensions/pi-subagents/src/tui/render.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/tui/render.js +2 -1
- package/dist/builtin-extensions/pi-subagents/src/tui/render.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/watchdog/review.d.ts +1 -1
- package/dist/builtin-extensions/pi-subagents/src/watchdog/review.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/watchdog/review.js +2 -1
- package/dist/builtin-extensions/pi-subagents/src/watchdog/review.js.map +1 -1
- package/dist/builtin-extensions/pi-web-access/extract.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-web-access/extract.js +105 -54
- package/dist/builtin-extensions/pi-web-access/extract.js.map +1 -1
- package/dist/builtin-extensions/pi-web-access/gemini-search.d.ts +1 -1
- package/dist/builtin-extensions/pi-web-access/gemini-search.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-web-access/gemini-search.js +82 -65
- package/dist/builtin-extensions/pi-web-access/gemini-search.js.map +1 -1
- package/dist/builtin-extensions/pi-web-access/github-extract.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-web-access/github-extract.js +2 -0
- package/dist/builtin-extensions/pi-web-access/github-extract.js.map +1 -1
- package/dist/builtin-extensions/pi-web-access/index.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-web-access/index.js +167 -77
- package/dist/builtin-extensions/pi-web-access/index.js.map +1 -1
- package/dist/builtin-extensions/pi-web-access/lazy.d.ts +18 -0
- package/dist/builtin-extensions/pi-web-access/lazy.d.ts.map +1 -0
- package/dist/builtin-extensions/pi-web-access/lazy.js +19 -0
- package/dist/builtin-extensions/pi-web-access/lazy.js.map +1 -0
- package/dist/builtin-extensions/pi-web-access/session-cleanup.d.ts +6 -0
- package/dist/builtin-extensions/pi-web-access/session-cleanup.d.ts.map +1 -0
- package/dist/builtin-extensions/pi-web-access/session-cleanup.js +17 -0
- package/dist/builtin-extensions/pi-web-access/session-cleanup.js.map +1 -0
- package/dist/catalog/models.json +1 -1
- package/dist/catalog/providers/amazon-bedrock.json +1 -1
- package/dist/catalog/providers/azure-openai-responses.json +1 -1
- package/dist/catalog/providers/fireworks.json +1 -1
- package/dist/catalog/providers/github-copilot.json +1 -1
- package/dist/catalog/providers/openai-codex.json +1 -1
- package/dist/catalog/providers/openai.json +1 -1
- package/dist/catalog/providers/opencode.json +1 -1
- package/dist/catalog/providers/openrouter.json +1 -1
- package/dist/catalog/providers/vercel-ai-gateway.json +1 -1
- package/dist/catalog/publication.json +131 -3
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js +1 -0
- package/dist/cli/list-models.js.map +1 -1
- package/dist/cli-runtime.d.ts +3 -0
- package/dist/cli-runtime.d.ts.map +1 -0
- package/dist/cli-runtime.js +73 -0
- package/dist/cli-runtime.js.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +14 -53
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -0
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session.d.ts +3 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +56 -12
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/catalog-cache-scope.d.ts +3 -0
- package/dist/core/catalog-cache-scope.d.ts.map +1 -0
- package/dist/core/catalog-cache-scope.js +12 -0
- package/dist/core/catalog-cache-scope.js.map +1 -0
- package/dist/core/catalog-merge.d.ts +2 -0
- package/dist/core/catalog-merge.d.ts.map +1 -1
- package/dist/core/catalog-merge.js +29 -2
- package/dist/core/catalog-merge.js.map +1 -1
- package/dist/core/catalog-refresh-polling.d.ts +8 -0
- package/dist/core/catalog-refresh-polling.d.ts.map +1 -0
- package/dist/core/catalog-refresh-polling.js +30 -0
- package/dist/core/catalog-refresh-polling.js.map +1 -0
- package/dist/core/codex-catalog.d.ts +3 -0
- package/dist/core/codex-catalog.d.ts.map +1 -0
- package/dist/core/codex-catalog.js +15 -0
- package/dist/core/codex-catalog.js.map +1 -0
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +10 -5
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/extensions/host-static.d.ts.map +1 -1
- package/dist/core/extensions/host-static.js +34 -12
- package/dist/core/extensions/host-static.js.map +1 -1
- package/dist/core/extensions/loader.d.ts +1 -2
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +10 -64
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/types.d.ts +2 -2
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/footer-data-provider.d.ts.map +1 -1
- package/dist/core/footer-data-provider.js +2 -0
- package/dist/core/footer-data-provider.js.map +1 -1
- package/dist/core/live-catalog.d.ts +5 -2
- package/dist/core/live-catalog.d.ts.map +1 -1
- package/dist/core/live-catalog.js +108 -27
- package/dist/core/live-catalog.js.map +1 -1
- package/dist/core/model-runtime.d.ts +8 -0
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +64 -12
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/official-catalog.d.ts +4 -0
- package/dist/core/official-catalog.d.ts.map +1 -1
- package/dist/core/official-catalog.js +86 -21
- package/dist/core/official-catalog.js.map +1 -1
- package/dist/core/permissions.d.ts +0 -2
- package/dist/core/permissions.d.ts.map +1 -1
- package/dist/core/permissions.js +10 -18
- package/dist/core/permissions.js.map +1 -1
- package/dist/core/sdk.d.ts +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +1 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +0 -1
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/timings.d.ts +2 -1
- package/dist/core/timings.d.ts.map +1 -1
- package/dist/core/timings.js +17 -2
- package/dist/core/timings.js.map +1 -1
- package/dist/gateway/commands.d.ts +1 -1
- package/dist/gateway/commands.d.ts.map +1 -1
- package/dist/gateway/commands.js +1 -18
- package/dist/gateway/commands.js.map +1 -1
- package/dist/main.d.ts +2 -2
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +66 -48
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +4 -1
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +13 -22
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +141 -207
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +95 -84
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/node-runtime/agent-session-services-IFJMSX7Z.js +36 -0
- package/dist/node-runtime/benchmark-request-UC7PD3V3.js +57 -0
- package/dist/node-runtime/brave-UWDA3I22.js +143 -0
- package/dist/node-runtime/builtin-extensions-LYZ3BFWQ.js +28 -0
- package/dist/node-runtime/chunk-2QKLKMKC.js +173 -0
- package/dist/node-runtime/chunk-3GHXVUAK.js +21 -0
- package/dist/node-runtime/chunk-3RCWXWAY.js +466 -0
- package/dist/node-runtime/chunk-3WFAEVKS.js +115 -0
- package/dist/node-runtime/chunk-3X3KZKMI.js +49 -0
- package/dist/node-runtime/chunk-4HXHDDCF.js +16 -0
- package/dist/node-runtime/chunk-4TLO4PO2.js +3427 -0
- package/dist/node-runtime/chunk-4ZWGEEAS.js +69 -0
- package/dist/node-runtime/chunk-53YJI7JU.js +137 -0
- package/dist/node-runtime/chunk-5P7PZMRU.js +610 -0
- package/dist/node-runtime/chunk-7N3YHTYF.js +26 -0
- package/dist/node-runtime/chunk-7NBZ5P7I.js +24 -0
- package/dist/node-runtime/chunk-A2KQXUJD.js +105 -0
- package/dist/node-runtime/chunk-AD6VXAO7.js +342 -0
- package/dist/node-runtime/chunk-AHSTJBIB.js +64 -0
- package/dist/node-runtime/chunk-AJX357CL.js +20211 -0
- package/dist/node-runtime/chunk-ARC4KOTI.js +11178 -0
- package/dist/node-runtime/chunk-AUXVGBO4.js +19 -0
- package/dist/node-runtime/chunk-AY6CAJSL.js +30 -0
- package/dist/node-runtime/chunk-BHO7O6E5.js +296 -0
- package/dist/node-runtime/chunk-BI3DHYCN.js +8845 -0
- package/dist/node-runtime/chunk-BR7YDUKA.js +109 -0
- package/dist/node-runtime/chunk-BRJX2PRC.js +53 -0
- package/dist/node-runtime/chunk-C4O2RSQQ.js +37 -0
- package/dist/node-runtime/chunk-CCZJ3PYY.js +17 -0
- package/dist/node-runtime/chunk-CDFZEWPU.js +8388 -0
- package/dist/node-runtime/chunk-CGBXPL3E.js +1171 -0
- package/dist/node-runtime/chunk-CJECDQKP.js +19 -0
- package/dist/node-runtime/chunk-DAPBPCBP.js +53 -0
- package/dist/node-runtime/chunk-DDGMHUOW.js +305 -0
- package/dist/node-runtime/chunk-DMMTJQMQ.js +43 -0
- package/dist/node-runtime/chunk-DVGWF6A2.js +1180 -0
- package/dist/node-runtime/chunk-ECD5L7YI.js +1369 -0
- package/dist/node-runtime/chunk-EDBJNRSM.js +46 -0
- package/dist/node-runtime/chunk-F4VQFJI2.js +1269 -0
- package/dist/node-runtime/chunk-FVDOXRUD.js +96 -0
- package/dist/node-runtime/chunk-GZQHMEWL.js +126 -0
- package/dist/node-runtime/chunk-H2EOZYMP.js +57 -0
- package/dist/node-runtime/chunk-HQCKFM2O.js +56 -0
- package/dist/node-runtime/chunk-HYHJIRDW.js +19 -0
- package/dist/node-runtime/chunk-I6R76AG7.js +22 -0
- package/dist/node-runtime/chunk-IPA627GP.js +296 -0
- package/dist/node-runtime/chunk-JHYKXIMM.js +378 -0
- package/dist/node-runtime/chunk-KKSIVROT.js +88 -0
- package/dist/node-runtime/chunk-LZAW4ZX3.js +633 -0
- package/dist/node-runtime/chunk-M3LZLQW2.js +98 -0
- package/dist/node-runtime/chunk-MGWCVY6Y.js +47 -0
- package/dist/node-runtime/chunk-MJQDX3BA.js +72 -0
- package/dist/node-runtime/chunk-MKKH27PH.js +8956 -0
- package/dist/node-runtime/chunk-MX3GJNXJ.js +986 -0
- package/dist/node-runtime/chunk-N77MY65L.js +966 -0
- package/dist/node-runtime/chunk-NUIFPZWX.js +209 -0
- package/dist/node-runtime/chunk-OBMWP3I5.js +68 -0
- package/dist/node-runtime/chunk-OR4L3IB2.js +42 -0
- package/dist/node-runtime/chunk-PBC2Y6GS.js +903 -0
- package/dist/node-runtime/chunk-PCGNAY2O.js +1324 -0
- package/dist/node-runtime/chunk-PCIGF2XK.js +250 -0
- package/dist/node-runtime/chunk-PGAJ5MO5.js +7558 -0
- package/dist/node-runtime/chunk-PL6JKXWI.js +3622 -0
- package/dist/node-runtime/chunk-PVCDKGR6.js +55 -0
- package/dist/node-runtime/chunk-Q4Q6D4IY.js +364 -0
- package/dist/node-runtime/chunk-Q5ZU2VRT.js +83 -0
- package/dist/node-runtime/chunk-QFWG2RVL.js +5477 -0
- package/dist/node-runtime/chunk-QH42CDX3.js +9451 -0
- package/dist/node-runtime/chunk-RQ2Q5IYR.js +72 -0
- package/dist/node-runtime/chunk-RQ5DNUNG.js +429 -0
- package/dist/node-runtime/chunk-RRIZE6QQ.js +17 -0
- package/dist/node-runtime/chunk-SN6G4OU6.js +4753 -0
- package/dist/node-runtime/chunk-SWSN6HAB.js +53 -0
- package/dist/node-runtime/chunk-TQNSPERU.js +949 -0
- package/dist/node-runtime/chunk-VRB2IYGG.js +53 -0
- package/dist/node-runtime/chunk-VSELYKWU.js +772 -0
- package/dist/node-runtime/chunk-W3CVH5RX.js +62 -0
- package/dist/node-runtime/chunk-WJVFOIB5.js +24921 -0
- package/dist/node-runtime/chunk-WOVTOV5P.js +5653 -0
- package/dist/node-runtime/chunk-XBWPBZBN.js +125 -0
- package/dist/node-runtime/chunk-XTHQ7XR7.js +509 -0
- package/dist/node-runtime/chunk-YF63P5ZT.js +864 -0
- package/dist/node-runtime/chunk-YSKSB3BJ.js +295 -0
- package/dist/node-runtime/chunk-ZCHMJ34K.js +130 -0
- package/dist/node-runtime/chunk-ZKMFUD3Q.js +2834 -0
- package/dist/node-runtime/cli-runtime.js +81 -0
- package/dist/node-runtime/clipboard-OZ63BBC6.js +12 -0
- package/dist/node-runtime/clipboard-image-7QR6GXVA.js +13 -0
- package/dist/node-runtime/command-L3LAHDIH.js +13 -0
- package/dist/node-runtime/commands-RL5YBW5I.js +291 -0
- package/dist/node-runtime/config-FMEOZSWE.js +77 -0
- package/dist/node-runtime/curator-server-XCM43VEF.js +3816 -0
- package/dist/node-runtime/customize-XEXL2DGQ.js +12 -0
- package/dist/node-runtime/direct-tool-executor-JVDXTO7A.js +188 -0
- package/dist/node-runtime/exa-LL64QZR2.js +329 -0
- package/dist/node-runtime/export-html-KR26FOUZ.js +150 -0
- package/dist/node-runtime/extension-input-RV5N6APL.js +14 -0
- package/dist/node-runtime/extension-selector-CPD5LWDD.js +14 -0
- package/dist/node-runtime/extract-XLQSJN4V.js +17 -0
- package/dist/node-runtime/file-sync-HCOP2QVF.js +117 -0
- package/dist/node-runtime/gateway-X2TI5X7F.js +2484 -0
- package/dist/node-runtime/gemini-api-QE7ANVDZ.js +29 -0
- package/dist/node-runtime/gemini-search-U7SUMPQA.js +330 -0
- package/dist/node-runtime/gemini-url-context-PXWCBQHK.js +103 -0
- package/dist/node-runtime/gemini-web-MM446SEH.js +14 -0
- package/dist/node-runtime/github-extract-F64RZOEA.js +619 -0
- package/dist/node-runtime/goal-CZQ7FFQJ.js +1831 -0
- package/dist/node-runtime/index.js +859 -0
- package/dist/node-runtime/init-NJV2T55N.js +28 -0
- package/dist/node-runtime/install-cli-TH7IJJQQ.js +308 -0
- package/dist/node-runtime/interactive-mode-KOM35YF2.js +56 -0
- package/dist/node-runtime/interactive-view-U6OILKF3.js +249 -0
- package/dist/node-runtime/lsp-manager-3ASUSO4T.js +1104 -0
- package/dist/node-runtime/lunr-cron-YJ5UHYRD.js +268 -0
- package/dist/node-runtime/main.js +54 -0
- package/dist/node-runtime/mcp-auth-flow-QIXHW6QN.js +32 -0
- package/dist/node-runtime/mcp-panel-IIGMXQGP.js +501 -0
- package/dist/node-runtime/mcp-setup-panel-FEK7663I.js +355 -0
- package/dist/node-runtime/memory-cap-3S4XRLNP.js +20 -0
- package/dist/node-runtime/model-tiers-NJLHUEGK.js +20 -0
- package/dist/node-runtime/openai-search-B3MSNCQA.js +288 -0
- package/dist/node-runtime/package-manager-cli-TZZHJCVI.js +749 -0
- package/dist/node-runtime/parallel-AI2MNSCU.js +265 -0
- package/dist/node-runtime/parser-manager-TQHWYDH7.js +152 -0
- package/dist/node-runtime/pdf-extract-IPE6H4HP.js +57 -0
- package/dist/node-runtime/perplexity-QVJW3I35.js +12 -0
- package/dist/node-runtime/pi-intercom-EEMBGQID.js +2215 -0
- package/dist/node-runtime/pi-mcp-adapter-QFB37AVN.js +422 -0
- package/dist/node-runtime/pi-ollama-cloud-4VZRMULP.js +1440 -0
- package/dist/node-runtime/pi-prompt-template-model-4QT4LLXF.js +3946 -0
- package/dist/node-runtime/pi-subagents-7XJ4H53P.js +6023 -0
- package/dist/node-runtime/pi-web-access-DPGAVKOA.js +1864 -0
- package/dist/node-runtime/print-mode-VWIRFDAC.js +12 -0
- package/dist/node-runtime/proxy-modes-HEEFK4KC.js +685 -0
- package/dist/node-runtime/rpc-entry.js +62 -0
- package/dist/node-runtime/rpc-mode-SJNSOA4G.js +13 -0
- package/dist/node-runtime/runtime-bridges-PPHNBFWL.js +14 -0
- package/dist/node-runtime/session-manager-MQNBYACL.js +35 -0
- package/dist/node-runtime/session-selector-5AZLJS6U.js +14 -0
- package/dist/node-runtime/settings-manager-5LF2VQWC.js +21 -0
- package/dist/node-runtime/src-Y7JSCK64.js +2407 -0
- package/dist/node-runtime/subagent-executor-5RNDEPIJ.js +8483 -0
- package/dist/node-runtime/summary-review-YSMXKITO.js +228 -0
- package/dist/node-runtime/tavily-WEZFVFP7.js +154 -0
- package/dist/node-runtime/timings-UAD5BEAS.js +16 -0
- package/dist/node-runtime/tool-renderer-MV5O452K.js +204 -0
- package/dist/node-runtime/update-cli-A253SZ7P.js +73 -0
- package/dist/node-runtime/v4-5MNC3H7G.js +424 -0
- package/dist/node-runtime/video-extract-OYT5WKS5.js +304 -0
- package/dist/node-runtime/workspace-index-6DBXSTJ6.js +163 -0
- package/dist/node-runtime/youtube-extract-TQYKGFGS.js +264 -0
- package/dist/startup/benchmark-request.d.ts +3 -0
- package/dist/startup/benchmark-request.d.ts.map +1 -0
- package/dist/startup/benchmark-request.js +65 -0
- package/dist/startup/benchmark-request.js.map +1 -0
- package/dist/startup/interactive-view.d.ts +55 -0
- package/dist/startup/interactive-view.d.ts.map +1 -0
- package/dist/startup/interactive-view.js +332 -0
- package/dist/startup/interactive-view.js.map +1 -0
- package/dist/startup/launch-routing.d.ts.map +1 -1
- package/dist/startup/launch-routing.js +9 -10
- package/dist/startup/launch-routing.js.map +1 -1
- package/dist/startup/startup-milestones.d.ts +1 -1
- package/dist/startup/startup-milestones.d.ts.map +1 -1
- package/dist/startup/startup-milestones.js +3 -2
- package/dist/startup/startup-milestones.js.map +1 -1
- package/dist/utils/await-with-abort.d.ts +2 -0
- package/dist/utils/await-with-abort.d.ts.map +1 -0
- package/dist/utils/await-with-abort.js +19 -0
- package/dist/utils/await-with-abort.js.map +1 -0
- package/dist/utils/syntax-highlight.d.ts.map +1 -1
- package/dist/utils/syntax-highlight.js +10 -4
- package/dist/utils/syntax-highlight.js.map +1 -1
- package/docs/compaction.md +5 -3
- package/docs/development.md +5 -1
- package/docs/features.md +0 -1
- package/docs/interactive-startup.md +98 -0
- package/docs/model-catalog.md +29 -0
- package/docs/usage.md +0 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/package.json +20 -20
- package/dist/core/swarm.d.ts +0 -23
- package/dist/core/swarm.d.ts.map +0 -1
- package/dist/core/swarm.js +0 -45
- package/dist/core/swarm.js.map +0 -1
|
@@ -0,0 +1,864 @@
|
|
|
1
|
+
import { createRequire as __lunrRequire } from "node:module"; const require = __lunrRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
CONFIG_DIR_NAME,
|
|
4
|
+
getAgentDir
|
|
5
|
+
} from "./chunk-PCIGF2XK.js";
|
|
6
|
+
|
|
7
|
+
// packages/coding-agent/dist/core/usage-adapters/shared.js
|
|
8
|
+
async function fetchWithTimeout(url, init, timeoutMs = 1e4) {
|
|
9
|
+
let controller = new AbortController(), timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
10
|
+
try {
|
|
11
|
+
return await fetch(url, { ...init, signal: controller.signal });
|
|
12
|
+
} finally {
|
|
13
|
+
clearTimeout(timeout);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function asObject(value) {
|
|
17
|
+
if (!(!value || typeof value != "object" || Array.isArray(value)))
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
function asString(value) {
|
|
21
|
+
return typeof value == "string" && value.trim() ? value : void 0;
|
|
22
|
+
}
|
|
23
|
+
function asNumber(value) {
|
|
24
|
+
if (typeof value == "number" && Number.isFinite(value))
|
|
25
|
+
return value;
|
|
26
|
+
if (typeof value == "string" && value.trim()) {
|
|
27
|
+
let parsed = Number(value);
|
|
28
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function clampPercent(value) {
|
|
32
|
+
return Math.max(0, Math.min(100, value));
|
|
33
|
+
}
|
|
34
|
+
function toEpochMs(value) {
|
|
35
|
+
let asNumberValue = asNumber(value);
|
|
36
|
+
if (asNumberValue !== void 0)
|
|
37
|
+
return asNumberValue < 1e12 ? Math.round(asNumberValue * 1e3) : Math.round(asNumberValue);
|
|
38
|
+
let asStringValue = asString(value);
|
|
39
|
+
if (asStringValue) {
|
|
40
|
+
let parsed = Date.parse(asStringValue);
|
|
41
|
+
if (Number.isFinite(parsed))
|
|
42
|
+
return parsed;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function unwrapVal(value) {
|
|
46
|
+
let object = asObject(value);
|
|
47
|
+
return object && "val" in object ? asNumber(object.val) : asNumber(value);
|
|
48
|
+
}
|
|
49
|
+
function usedPercentFromRemaining(limit, remaining) {
|
|
50
|
+
let total = asNumber(limit), left = asNumber(remaining);
|
|
51
|
+
if (!(total === void 0 || left === void 0 || total <= 0))
|
|
52
|
+
return clampPercent(100 - left / total * 100);
|
|
53
|
+
}
|
|
54
|
+
function usedPercentFromUsed(total, used) {
|
|
55
|
+
let cap = asNumber(total), spent = asNumber(used);
|
|
56
|
+
if (!(cap === void 0 || spent === void 0 || cap <= 0))
|
|
57
|
+
return clampPercent(spent / cap * 100);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// packages/coding-agent/dist/core/usage-adapters/kimi-coding.js
|
|
61
|
+
var KIMI_PROVIDER_ID = "kimi-coding", KIMI_USAGE_URL = "https://api.kimi.com/coding/v1/usages", TIME_UNIT_SECONDS = {
|
|
62
|
+
seconds: 1,
|
|
63
|
+
second: 1,
|
|
64
|
+
minutes: 60,
|
|
65
|
+
minute: 60,
|
|
66
|
+
hours: 3600,
|
|
67
|
+
hour: 3600,
|
|
68
|
+
days: 86400,
|
|
69
|
+
day: 86400,
|
|
70
|
+
weeks: 604800,
|
|
71
|
+
week: 604800
|
|
72
|
+
};
|
|
73
|
+
function durationLabel(duration, timeUnit) {
|
|
74
|
+
let amount = asNumber(duration), unit = typeof timeUnit == "string" ? timeUnit.toLowerCase() : void 0, seconds = amount !== void 0 && unit ? TIME_UNIT_SECONDS[unit] : void 0;
|
|
75
|
+
if (amount === void 0 || seconds === void 0)
|
|
76
|
+
return "Limit";
|
|
77
|
+
let totalSeconds = amount * seconds;
|
|
78
|
+
return totalSeconds >= 604800 ? "Weekly" : totalSeconds >= 86400 ? `${Math.round(totalSeconds / 86400)}d` : totalSeconds >= 3600 ? `${Math.round(totalSeconds / 3600)}h` : `${Math.max(1, Math.round(totalSeconds / 60))}m`;
|
|
79
|
+
}
|
|
80
|
+
function detailWindow(label, detail) {
|
|
81
|
+
let object = asObject(detail);
|
|
82
|
+
if (!object)
|
|
83
|
+
return;
|
|
84
|
+
let usedPercent = usedPercentFromRemaining(object.limit, object.remaining);
|
|
85
|
+
if (usedPercent !== void 0)
|
|
86
|
+
return { label, usedPercent, resetsAt: toEpochMs(object.resetTime) };
|
|
87
|
+
}
|
|
88
|
+
async function fetchKimiPlanUsage(runtime) {
|
|
89
|
+
let apiKey = (await runtime.getAuth(KIMI_PROVIDER_ID))?.auth.apiKey;
|
|
90
|
+
if (!apiKey)
|
|
91
|
+
return;
|
|
92
|
+
let response = await fetchWithTimeout(KIMI_USAGE_URL, {
|
|
93
|
+
headers: { Authorization: `Bearer ${apiKey}`, Accept: "application/json" }
|
|
94
|
+
});
|
|
95
|
+
if (!response.ok)
|
|
96
|
+
return;
|
|
97
|
+
let payload = asObject(await response.json());
|
|
98
|
+
if (!payload)
|
|
99
|
+
return;
|
|
100
|
+
let windows = [], weekly = detailWindow("Weekly", payload.usage);
|
|
101
|
+
weekly && windows.push(weekly);
|
|
102
|
+
let limits = Array.isArray(payload.limits) ? payload.limits : [];
|
|
103
|
+
for (let item of limits) {
|
|
104
|
+
let limit = asObject(item);
|
|
105
|
+
if (!limit)
|
|
106
|
+
continue;
|
|
107
|
+
let window = detailWindow(durationLabel(asObject(limit.window)?.duration, asObject(limit.window)?.timeUnit), limit.detail);
|
|
108
|
+
window && windows.push(window);
|
|
109
|
+
}
|
|
110
|
+
if (windows.length !== 0)
|
|
111
|
+
return { provider: KIMI_PROVIDER_ID, windows };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// packages/coding-agent/dist/core/usage-adapters/openai-codex.js
|
|
115
|
+
var CODEX_PROVIDER_ID = "openai-codex", CODEX_USAGE_URL = "https://chatgpt.com/backend-api/wham/usage", MAX_ERROR_BODY_CHARS = 600;
|
|
116
|
+
function normalizeBackendPayload(payload) {
|
|
117
|
+
let snapshots = [], planType = asString(payload.plan_type), primary = normalizeBackendSnapshot("codex", void 0, payload.rate_limit, payload.credits);
|
|
118
|
+
primary && snapshots.push(primary);
|
|
119
|
+
let additional = Array.isArray(payload.additional_rate_limits) ? payload.additional_rate_limits : [];
|
|
120
|
+
for (let item of additional) {
|
|
121
|
+
let additionalLimit = asObject(item);
|
|
122
|
+
if (!additionalLimit)
|
|
123
|
+
continue;
|
|
124
|
+
let limitId = asString(additionalLimit.metered_feature) ?? asString(additionalLimit.limit_name);
|
|
125
|
+
if (limitId)
|
|
126
|
+
try {
|
|
127
|
+
let snapshot = normalizeBackendSnapshot(limitId, asString(additionalLimit.limit_name), additionalLimit.rate_limit, void 0);
|
|
128
|
+
snapshot && snapshots.push(snapshot);
|
|
129
|
+
} catch {
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (snapshots.length === 0)
|
|
133
|
+
throw new Error("Codex usage endpoint returned no displayable usage data.");
|
|
134
|
+
return { planType, snapshots };
|
|
135
|
+
}
|
|
136
|
+
function normalizeBackendSnapshot(limitId, limitName, rateLimit, credits) {
|
|
137
|
+
if (rateLimit == null)
|
|
138
|
+
return normalizeBackendCredits(credits) ? { limitId, limitName } : void 0;
|
|
139
|
+
let details = asObject(rateLimit);
|
|
140
|
+
if (!details)
|
|
141
|
+
throw new Error("rate limit was not an object.");
|
|
142
|
+
let primary = normalizeBackendWindow(details.primary_window), secondary = normalizeBackendWindow(details.secondary_window);
|
|
143
|
+
if (!(!primary && !secondary && !normalizeBackendCredits(credits)))
|
|
144
|
+
return { limitId, limitName, primary, secondary };
|
|
145
|
+
}
|
|
146
|
+
function normalizeBackendWindow(value) {
|
|
147
|
+
if (value == null)
|
|
148
|
+
return;
|
|
149
|
+
let window = asObject(value);
|
|
150
|
+
if (!window)
|
|
151
|
+
throw new Error("rate-limit window was not an object.");
|
|
152
|
+
let usedPercent = asNumber(window.used_percent);
|
|
153
|
+
if (usedPercent === void 0)
|
|
154
|
+
return;
|
|
155
|
+
let limitSeconds = asNumber(window.limit_window_seconds);
|
|
156
|
+
return {
|
|
157
|
+
usedPercent,
|
|
158
|
+
windowMinutes: limitSeconds && limitSeconds > 0 ? Math.ceil(limitSeconds / 60) : void 0,
|
|
159
|
+
resetsAt: toEpochMs(window.reset_at)
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function normalizeBackendCredits(value) {
|
|
163
|
+
let credits = asObject(value);
|
|
164
|
+
return credits ? credits.has_credits !== void 0 && credits.unlimited !== void 0 : !1;
|
|
165
|
+
}
|
|
166
|
+
async function resolveCodexHeaders(runtime) {
|
|
167
|
+
let candidates = [], seen = /* @__PURE__ */ new Set(), add = (model) => {
|
|
168
|
+
if (!model || model.provider !== CODEX_PROVIDER_ID)
|
|
169
|
+
return;
|
|
170
|
+
let key = `${model.provider}/${model.id}`;
|
|
171
|
+
seen.has(key) || (seen.add(key), candidates.push(model));
|
|
172
|
+
};
|
|
173
|
+
for (let model of runtime.getAvailableSnapshot())
|
|
174
|
+
add(model);
|
|
175
|
+
for (let model of runtime.getModels())
|
|
176
|
+
add(model);
|
|
177
|
+
for (let model of candidates) {
|
|
178
|
+
let resolution;
|
|
179
|
+
try {
|
|
180
|
+
resolution = await runtime.getAuth(model);
|
|
181
|
+
} catch {
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (!resolution)
|
|
185
|
+
continue;
|
|
186
|
+
let headers = {};
|
|
187
|
+
for (let [name, value] of Object.entries(resolution.auth.headers ?? {}))
|
|
188
|
+
value != null && (headers[name] = String(value));
|
|
189
|
+
if (!hasHeader(headers, "Authorization") && resolution.auth.apiKey && (headers.Authorization = `Bearer ${resolution.auth.apiKey}`), hasHeader(headers, "User-Agent") || (headers["User-Agent"] = "lunr-usage-service"), hasHeader(headers, "Authorization"))
|
|
190
|
+
return headers;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function hasHeader(headers, name) {
|
|
194
|
+
return Object.keys(headers).some((key) => key.toLowerCase() === name.toLowerCase());
|
|
195
|
+
}
|
|
196
|
+
function redactErrorBody(body) {
|
|
197
|
+
let redacted = body.replace(/Bearer\s+[A-Za-z0-9._~+/=-]+/gi, "Bearer <redacted>").replace(/"access_token"\s*:\s*"[^"]+"/gi, '"access_token":"<redacted>"').trim();
|
|
198
|
+
return redacted.length > MAX_ERROR_BODY_CHARS ? `${redacted.slice(0, MAX_ERROR_BODY_CHARS - 1)}\u2026` : redacted;
|
|
199
|
+
}
|
|
200
|
+
function windowLabel(window, fallback) {
|
|
201
|
+
let minutes = window.windowMinutes;
|
|
202
|
+
return minutes === void 0 ? fallback ?? "Limit" : minutes >= 10080 ? "Weekly" : minutes >= 1440 ? `${Math.round(minutes / 1440)}d` : minutes >= 60 ? `${Math.round(minutes / 60)}h` : `${minutes}m`;
|
|
203
|
+
}
|
|
204
|
+
function toPlanUsage(report) {
|
|
205
|
+
return report.snapshots.flatMap((snapshot, index) => {
|
|
206
|
+
let windows = [];
|
|
207
|
+
for (let window of [snapshot.secondary, snapshot.primary])
|
|
208
|
+
window && windows.push({
|
|
209
|
+
label: windowLabel(window, snapshot.limitName),
|
|
210
|
+
usedPercent: window.usedPercent,
|
|
211
|
+
resetsAt: window.resetsAt
|
|
212
|
+
});
|
|
213
|
+
return windows.length === 0 ? [] : [
|
|
214
|
+
{
|
|
215
|
+
provider: CODEX_PROVIDER_ID,
|
|
216
|
+
planLabel: index === 0 ? report.planType : snapshot.limitName ?? snapshot.limitId,
|
|
217
|
+
windows
|
|
218
|
+
}
|
|
219
|
+
];
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
async function fetchCodexPlanUsage(runtime) {
|
|
223
|
+
let headers = await resolveCodexHeaders(runtime);
|
|
224
|
+
if (!headers)
|
|
225
|
+
return;
|
|
226
|
+
let response = await fetchWithTimeout(CODEX_USAGE_URL, { headers }), text = await response.text();
|
|
227
|
+
if (!response.ok)
|
|
228
|
+
throw new Error(`Codex usage endpoint returned ${response.status}: ${redactErrorBody(text)}`);
|
|
229
|
+
let payload = asObject(JSON.parse(text));
|
|
230
|
+
if (payload)
|
|
231
|
+
return toPlanUsage(normalizeBackendPayload(payload));
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// packages/coding-agent/dist/core/usage-adapters/xai.js
|
|
235
|
+
import { ModelsError } from "@ashx-j/lunr-ai";
|
|
236
|
+
var XAI_PROVIDER_ID = "xai", XAI_BILLING_URL = "https://cli-chat-proxy.grok.com/v1/billing?format=credits";
|
|
237
|
+
function currentPeriod(config) {
|
|
238
|
+
return asObject(config.currentPeriod) ?? asObject(config.current_period);
|
|
239
|
+
}
|
|
240
|
+
function weeklyWindow(config) {
|
|
241
|
+
let period = currentPeriod(config), raw = unwrapVal(config.creditUsagePercent ?? config.credit_usage_percent);
|
|
242
|
+
return raw === void 0 && !period ? void 0 : {
|
|
243
|
+
label: "Weekly",
|
|
244
|
+
usedPercent: raw === void 0 ? 0 : clampPercent(raw),
|
|
245
|
+
resetsAt: toEpochMs(period?.end)
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
async function fetchXaiPlanUsage(runtime) {
|
|
249
|
+
if (!runtime.isUsingOAuth(XAI_PROVIDER_ID))
|
|
250
|
+
return;
|
|
251
|
+
let accessToken = (await runtime.getAuth(XAI_PROVIDER_ID))?.auth.apiKey;
|
|
252
|
+
if (!accessToken)
|
|
253
|
+
return;
|
|
254
|
+
let response = await fetchWithTimeout(XAI_BILLING_URL, {
|
|
255
|
+
headers: {
|
|
256
|
+
Authorization: `Bearer ${accessToken}`,
|
|
257
|
+
Accept: "application/json",
|
|
258
|
+
"x-xai-token-auth": "xai-grok-cli"
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
if (response.status === 401 || response.status === 403)
|
|
262
|
+
throw new ModelsError("oauth", `xAI billing rejected the session (HTTP ${response.status})`);
|
|
263
|
+
if (!response.ok)
|
|
264
|
+
return;
|
|
265
|
+
let payload = asObject(await response.json());
|
|
266
|
+
if (!payload)
|
|
267
|
+
return;
|
|
268
|
+
let config = asObject(payload.config) ?? payload, windows = [], weekly = weeklyWindow(config);
|
|
269
|
+
weekly && windows.push(weekly);
|
|
270
|
+
let onDemandCap = unwrapVal(config.onDemandCap);
|
|
271
|
+
if (onDemandCap !== void 0 && onDemandCap > 0) {
|
|
272
|
+
let usedPercent = usedPercentFromUsed(onDemandCap, unwrapVal(config.onDemandUsed) ?? 0);
|
|
273
|
+
usedPercent !== void 0 && windows.push({
|
|
274
|
+
label: "Extra",
|
|
275
|
+
usedPercent,
|
|
276
|
+
resetsAt: weekly?.resetsAt
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
if (windows.length === 0)
|
|
280
|
+
return;
|
|
281
|
+
let planLabel = asString(config.subscriptionTier) ?? asString(config.subscription_tier);
|
|
282
|
+
return { provider: XAI_PROVIDER_ID, planLabel, windows };
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// packages/coding-agent/dist/core/usage-adapters/zai.js
|
|
286
|
+
var ZAI_PROVIDER_ID = "zai", ZAI_QUOTA_URL = "https://api.z.ai/api/monitor/usage/quota/limit";
|
|
287
|
+
function limitLabel(limit) {
|
|
288
|
+
let type = asString(limit.type);
|
|
289
|
+
if (type === "TIME_LIMIT")
|
|
290
|
+
return "Monthly";
|
|
291
|
+
if (type !== "TOKENS_LIMIT")
|
|
292
|
+
return;
|
|
293
|
+
let unit = asNumber(limit.unit), number = asNumber(limit.number);
|
|
294
|
+
return unit === 1 && number !== void 0 ? `${number}d` : unit === 3 && number !== void 0 ? `${number}h` : unit === 5 && number !== void 0 ? `${number}m` : unit === 6 ? "Weekly" : "Limit";
|
|
295
|
+
}
|
|
296
|
+
async function fetchZaiPlanUsage(runtime) {
|
|
297
|
+
let apiKey = (await runtime.getAuth(ZAI_PROVIDER_ID))?.auth.apiKey;
|
|
298
|
+
if (!apiKey)
|
|
299
|
+
return;
|
|
300
|
+
let response = await fetchWithTimeout(ZAI_QUOTA_URL, {
|
|
301
|
+
headers: {
|
|
302
|
+
Authorization: `Bearer ${apiKey}`,
|
|
303
|
+
Accept: "application/json",
|
|
304
|
+
"Accept-Language": "en-US,en"
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
if (!response.ok)
|
|
308
|
+
return;
|
|
309
|
+
let payload = asObject(await response.json());
|
|
310
|
+
if (!payload || payload.success !== !0 || asNumber(payload.code) !== 200)
|
|
311
|
+
return;
|
|
312
|
+
let data = asObject(payload.data), limits = Array.isArray(data?.limits) ? data.limits : [], windows = [];
|
|
313
|
+
for (let item of limits) {
|
|
314
|
+
let limit = asObject(item);
|
|
315
|
+
if (!limit)
|
|
316
|
+
continue;
|
|
317
|
+
let label = limitLabel(limit), percentage = asNumber(limit.percentage);
|
|
318
|
+
!label || percentage === void 0 || windows.push({ label, usedPercent: clampPercent(percentage), resetsAt: toEpochMs(limit.nextResetTime) });
|
|
319
|
+
}
|
|
320
|
+
if (windows.length === 0)
|
|
321
|
+
return;
|
|
322
|
+
let planLabel = asString(data?.planName) ?? asString(data?.plan) ?? asString(data?.level);
|
|
323
|
+
return { provider: ZAI_PROVIDER_ID, planLabel, windows };
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// packages/coding-agent/dist/core/usage-service.js
|
|
327
|
+
var XAI_RELOGIN = "xAI login expired. Run /login xai.";
|
|
328
|
+
function errorChain(error) {
|
|
329
|
+
let parts = [], current = error, seen = /* @__PURE__ */ new Set();
|
|
330
|
+
for (; current && typeof current == "object" && !seen.has(current); ) {
|
|
331
|
+
if (seen.add(current), current instanceof Error) {
|
|
332
|
+
parts.push(current.message), current = current.cause;
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
return parts.join(" ");
|
|
338
|
+
}
|
|
339
|
+
function planUsageAuthError(error) {
|
|
340
|
+
let chain = errorChain(error);
|
|
341
|
+
if (!/timed out|aborted|cancelled|ECONN|ENOTFOUND|network/i.test(chain) && (/xai billing rejected the session \(HTTP 401\)/i.test(chain) || /invalid_grant|refresh token revoked/i.test(chain)))
|
|
342
|
+
return XAI_RELOGIN;
|
|
343
|
+
}
|
|
344
|
+
var ADAPTERS = {
|
|
345
|
+
"openai-codex": fetchCodexPlanUsage,
|
|
346
|
+
"kimi-coding": fetchKimiPlanUsage,
|
|
347
|
+
zai: fetchZaiPlanUsage,
|
|
348
|
+
xai: fetchXaiPlanUsage
|
|
349
|
+
}, PLAN_USAGE_CACHE_TTL_MS = 60 * 1e3;
|
|
350
|
+
function isWeeklyPlanWindow(window) {
|
|
351
|
+
return /week/i.test(window.label);
|
|
352
|
+
}
|
|
353
|
+
function isFiveHourPlanWindow(window) {
|
|
354
|
+
return /5h/i.test(window.label) || window.label === "5h";
|
|
355
|
+
}
|
|
356
|
+
function pickPlanWindow(usage, preferred) {
|
|
357
|
+
if (!usage?.windows.length)
|
|
358
|
+
return;
|
|
359
|
+
let usable = usage.windows.filter((w) => !/extra/i.test(w.label)), weekly = usable.find(isWeeklyPlanWindow), fiveH = usable.find(isFiveHourPlanWindow);
|
|
360
|
+
return preferred === "5h" ? fiveH ?? weekly ?? usable[0] ?? usage.windows[0] : weekly ?? fiveH ?? usable[0] ?? usage.windows[0];
|
|
361
|
+
}
|
|
362
|
+
function footerPlanLabel(window) {
|
|
363
|
+
return isFiveHourPlanWindow(window) ? "5h" : isWeeklyPlanWindow(window) ? "wk" : window.label.length <= 4 ? window.label : window.label.slice(0, 4);
|
|
364
|
+
}
|
|
365
|
+
var cache = /* @__PURE__ */ new Map(), inflight = /* @__PURE__ */ new Map();
|
|
366
|
+
function hasPlanUsageAdapter(providerId) {
|
|
367
|
+
return providerId in ADAPTERS;
|
|
368
|
+
}
|
|
369
|
+
async function getPlanUsage(providerId, runtime) {
|
|
370
|
+
return (await getPlanUsageResult(providerId, runtime)).usage;
|
|
371
|
+
}
|
|
372
|
+
async function getPlanUsageResult(providerId, runtime) {
|
|
373
|
+
let adapter = ADAPTERS[providerId];
|
|
374
|
+
if (!adapter)
|
|
375
|
+
return {};
|
|
376
|
+
let now = Date.now(), cached = cache.get(providerId);
|
|
377
|
+
if (cached && cached.expiresAt > now)
|
|
378
|
+
return { usage: cached.value[0], usages: cached.value };
|
|
379
|
+
let pending = inflight.get(providerId);
|
|
380
|
+
if (pending)
|
|
381
|
+
return pending;
|
|
382
|
+
let task = (async () => {
|
|
383
|
+
try {
|
|
384
|
+
let value = await adapter(runtime), usages = value === void 0 ? [] : Array.isArray(value) ? value : [value];
|
|
385
|
+
return cache.set(providerId, { expiresAt: Date.now() + PLAN_USAGE_CACHE_TTL_MS, value: usages }), { usage: usages[0], usages };
|
|
386
|
+
} catch (error) {
|
|
387
|
+
let authError = planUsageAuthError(error);
|
|
388
|
+
return authError ? { error: authError } : (cache.set(providerId, { expiresAt: Date.now() + PLAN_USAGE_CACHE_TTL_MS, value: [] }), {});
|
|
389
|
+
} finally {
|
|
390
|
+
inflight.delete(providerId);
|
|
391
|
+
}
|
|
392
|
+
})();
|
|
393
|
+
return inflight.set(providerId, task), task;
|
|
394
|
+
}
|
|
395
|
+
async function getAllPlanUsageResults(currentProvider, runtime) {
|
|
396
|
+
let stored = new Set((await runtime.listCredentials()).map((credential) => credential.providerId)), providers = Object.keys(ADAPTERS).filter((providerId) => stored.has(providerId) || providerId === currentProvider), results = await Promise.all(providers.map((providerId) => getPlanUsageResult(providerId, runtime)));
|
|
397
|
+
return {
|
|
398
|
+
usages: results.flatMap((result) => result.usages ?? []),
|
|
399
|
+
errors: results.flatMap((result) => result.error ? [`${result.error}`] : [])
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
function peekPlanUsage(providerId) {
|
|
403
|
+
return cache.get(providerId)?.value[0];
|
|
404
|
+
}
|
|
405
|
+
function clearPlanUsageCache() {
|
|
406
|
+
cache.clear(), inflight.clear();
|
|
407
|
+
}
|
|
408
|
+
var USAGE_SERVICE_BRIDGE_SYMBOL = /* @__PURE__ */ Symbol.for("@lunr/usage-service"), activeRuntime, activeUsageSettings, onUsageUpdate;
|
|
409
|
+
function preferredWindow() {
|
|
410
|
+
return activeUsageSettings?.getPlanUsageWindow() ?? "weekly";
|
|
411
|
+
}
|
|
412
|
+
var usageBridge = {
|
|
413
|
+
peek(providerId) {
|
|
414
|
+
return peekPlanUsage(providerId);
|
|
415
|
+
},
|
|
416
|
+
prefetch(providerId) {
|
|
417
|
+
!activeRuntime || !hasPlanUsageAdapter(providerId) || getPlanUsage(providerId, activeRuntime).then(() => onUsageUpdate?.());
|
|
418
|
+
},
|
|
419
|
+
setOnUpdate(fn) {
|
|
420
|
+
onUsageUpdate = fn;
|
|
421
|
+
},
|
|
422
|
+
getPreferredWindow() {
|
|
423
|
+
return preferredWindow();
|
|
424
|
+
},
|
|
425
|
+
pickForFooter(providerId) {
|
|
426
|
+
let window = pickPlanWindow(peekPlanUsage(providerId), preferredWindow());
|
|
427
|
+
if (window)
|
|
428
|
+
return { label: footerPlanLabel(window), usedPercent: window.usedPercent };
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
function registerUsageServiceBridge(runtime, settingsManager) {
|
|
432
|
+
activeRuntime = runtime, activeUsageSettings = settingsManager, globalThis[USAGE_SERVICE_BRIDGE_SYMBOL] = usageBridge;
|
|
433
|
+
}
|
|
434
|
+
function getUsageServiceBridge() {
|
|
435
|
+
return globalThis[USAGE_SERVICE_BRIDGE_SYMBOL];
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// packages/coding-agent/dist/core/rollback.js
|
|
439
|
+
import { spawnSync } from "node:child_process";
|
|
440
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
441
|
+
import { closeSync, cpSync, existsSync, fsyncSync, lstatSync, mkdirSync, openSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
|
|
442
|
+
import { homedir } from "node:os";
|
|
443
|
+
import { dirname, join, normalize, relative, resolve } from "node:path";
|
|
444
|
+
var ROLLBACK_BASE = join(homedir(), ".lunr", "rollback"), contexts = /* @__PURE__ */ new Map(), lastSessionId, globalSettingsManager, warningHandler;
|
|
445
|
+
function setRollbackWarningHandler(handler) {
|
|
446
|
+
warningHandler = handler;
|
|
447
|
+
}
|
|
448
|
+
function createContext(sessionId) {
|
|
449
|
+
return {
|
|
450
|
+
sessionId,
|
|
451
|
+
settingsManager: globalSettingsManager,
|
|
452
|
+
sessionForceEnabled: !1,
|
|
453
|
+
turns: [],
|
|
454
|
+
currentTurnIndex: -1,
|
|
455
|
+
repoWarningShown: !1,
|
|
456
|
+
externalModWarningShown: !1
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
function getContext(sessionId) {
|
|
460
|
+
let sid = sessionId ?? lastSessionId ?? "default", ctx = contexts.get(sid);
|
|
461
|
+
return ctx || (ctx = createContext(sid), contexts.set(sid, ctx)), ctx;
|
|
462
|
+
}
|
|
463
|
+
function initRollback(sm, sid) {
|
|
464
|
+
globalSettingsManager = sm, lastSessionId = sid, contexts.set(sid, createContext(sid));
|
|
465
|
+
let ctx = contexts.get(sid);
|
|
466
|
+
ctx.settingsManager = sm, loadPersistedTurns(ctx);
|
|
467
|
+
}
|
|
468
|
+
function isRollbackEnabled(sessionId) {
|
|
469
|
+
let ctx = getContext(sessionId);
|
|
470
|
+
return (ctx.settingsManager?.getRollbackEnabled() ?? !1) || ctx.sessionForceEnabled;
|
|
471
|
+
}
|
|
472
|
+
function isRollbackSessionForceEnabled(sessionId) {
|
|
473
|
+
return getContext(sessionId).sessionForceEnabled;
|
|
474
|
+
}
|
|
475
|
+
function enableRollbackForSession(sessionId) {
|
|
476
|
+
getContext(sessionId).sessionForceEnabled = !0;
|
|
477
|
+
}
|
|
478
|
+
function disableRollbackForSession(sessionId) {
|
|
479
|
+
getContext(sessionId).sessionForceEnabled = !1;
|
|
480
|
+
}
|
|
481
|
+
function pruneTurns(ctx) {
|
|
482
|
+
let maxTurns = ctx.settingsManager?.getRollbackTurns() ?? 2;
|
|
483
|
+
for (; ctx.turns.length > maxTurns; ) {
|
|
484
|
+
let old = ctx.turns.shift();
|
|
485
|
+
old && cleanupTurnFiles(ctx, old);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
function beginTurn(cwd, sessionId) {
|
|
489
|
+
let ctx = getContext(sessionId);
|
|
490
|
+
if (!isRollbackEnabled(ctx.sessionId))
|
|
491
|
+
return;
|
|
492
|
+
cwd && (ctx.lastCwd = cwd), ctx.currentTurnIndex++;
|
|
493
|
+
let turn = { turnIndex: ctx.currentTurnIndex, cwd, files: /* @__PURE__ */ new Map() };
|
|
494
|
+
ctx.turns.push(turn), pruneTurns(ctx), cwd && ctx.settingsManager?.getRollbackScope() === "tree" && captureTreeBaseline(ctx, cwd);
|
|
495
|
+
}
|
|
496
|
+
function rollbackSnapshotBeforeWrite(absPath, sessionId) {
|
|
497
|
+
let ctx = getContext(sessionId);
|
|
498
|
+
if (!isRollbackEnabled(ctx.sessionId))
|
|
499
|
+
return;
|
|
500
|
+
(ctx.currentTurnIndex < 0 || ctx.turns.length === 0) && beginTurn(ctx.lastCwd, ctx.sessionId);
|
|
501
|
+
let turn = ctx.turns[ctx.turns.length - 1];
|
|
502
|
+
if (turn && !turn.files.has(absPath))
|
|
503
|
+
try {
|
|
504
|
+
let existed = existsSync(absPath), content;
|
|
505
|
+
existed && (content = readFileSync(absPath)), turn.files.set(absPath, {
|
|
506
|
+
existed,
|
|
507
|
+
content,
|
|
508
|
+
createdByTool: !0
|
|
509
|
+
}), persistSnapshot(ctx, turn, absPath);
|
|
510
|
+
} catch {
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
function captureTreeBaseline(ctx, cwd) {
|
|
514
|
+
let turn = ctx.turns[ctx.turns.length - 1];
|
|
515
|
+
if (!turn)
|
|
516
|
+
return;
|
|
517
|
+
let entries = gitPorcelain(ctx, cwd);
|
|
518
|
+
if (entries)
|
|
519
|
+
for (let { path } of entries) {
|
|
520
|
+
if (!path)
|
|
521
|
+
continue;
|
|
522
|
+
let abs = join(cwd, path);
|
|
523
|
+
if (!turn.files.has(abs))
|
|
524
|
+
try {
|
|
525
|
+
let existed = existsSync(abs);
|
|
526
|
+
turn.files.set(abs, {
|
|
527
|
+
existed,
|
|
528
|
+
content: existed ? readFileSync(abs) : void 0,
|
|
529
|
+
createdByTool: !1
|
|
530
|
+
}), persistSnapshot(ctx, turn, abs);
|
|
531
|
+
} catch {
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
function captureTreeChanges(cwd, sessionId) {
|
|
536
|
+
let ctx = getContext(sessionId);
|
|
537
|
+
if (!isRollbackEnabled(ctx.sessionId) || ctx.settingsManager?.getRollbackScope() !== "tree" || ctx.currentTurnIndex < 0 || ctx.turns.length === 0)
|
|
538
|
+
return;
|
|
539
|
+
let turn = ctx.turns[ctx.turns.length - 1];
|
|
540
|
+
if (!turn)
|
|
541
|
+
return;
|
|
542
|
+
let entries = gitPorcelain(ctx, cwd);
|
|
543
|
+
if (entries)
|
|
544
|
+
for (let { status, path, source } of entries) {
|
|
545
|
+
if (!path)
|
|
546
|
+
continue;
|
|
547
|
+
let abs = join(cwd, path);
|
|
548
|
+
if (!turn.files.has(abs))
|
|
549
|
+
try {
|
|
550
|
+
if (status === "??" || status.includes("R")) {
|
|
551
|
+
if (turn.files.set(abs, { existed: !1, createdByTool: !1 }), persistSnapshot(ctx, turn, abs), status.includes("R") && source) {
|
|
552
|
+
let sourceAbs = join(cwd, source);
|
|
553
|
+
if (!turn.files.has(sourceAbs)) {
|
|
554
|
+
let headSrc = spawnSync("git", ["show", `HEAD:${source}`], {
|
|
555
|
+
cwd,
|
|
556
|
+
timeout: 5e3,
|
|
557
|
+
maxBuffer: 33554432
|
|
558
|
+
});
|
|
559
|
+
!headSrc.error && headSrc.status === 0 && headSrc.stdout && (turn.files.set(sourceAbs, {
|
|
560
|
+
existed: !0,
|
|
561
|
+
content: headSrc.stdout,
|
|
562
|
+
createdByTool: !1
|
|
563
|
+
}), persistSnapshot(ctx, turn, sourceAbs));
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
} else {
|
|
567
|
+
let head = spawnSync("git", ["show", `HEAD:${path}`], {
|
|
568
|
+
cwd,
|
|
569
|
+
timeout: 5e3,
|
|
570
|
+
maxBuffer: 33554432
|
|
571
|
+
});
|
|
572
|
+
if (head.error || head.status !== 0 || !head.stdout)
|
|
573
|
+
continue;
|
|
574
|
+
turn.files.set(abs, {
|
|
575
|
+
existed: !0,
|
|
576
|
+
content: head.stdout,
|
|
577
|
+
createdByTool: !1
|
|
578
|
+
}), persistSnapshot(ctx, turn, abs);
|
|
579
|
+
}
|
|
580
|
+
} catch {
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
function gitPorcelain(ctx, cwd) {
|
|
585
|
+
try {
|
|
586
|
+
let result = spawnSync("git", ["status", "--porcelain", "-z"], { cwd, encoding: "utf8", timeout: 5e3 });
|
|
587
|
+
if (result.error || result.status !== 0) {
|
|
588
|
+
warnOnce(ctx, "Rollback tree scope: not a git repository (or git failed) \u2014 bash side-effects won't be captured.");
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
let fields = (result.stdout ?? "").split("\0").filter((f) => f.length > 0), entries = [];
|
|
592
|
+
for (let i = 0; i < fields.length; i++) {
|
|
593
|
+
let field = fields[i], status = field.slice(0, 2), path = field.slice(3), source;
|
|
594
|
+
(status.includes("R") || status.includes("C")) && (source = fields[i + 1], i++), entries.push({ status, path, source });
|
|
595
|
+
}
|
|
596
|
+
return entries;
|
|
597
|
+
} catch {
|
|
598
|
+
warnOnce(ctx, "Rollback tree scope: not a git repository (or git failed) \u2014 bash side-effects won't be captured.");
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
function warnOnce(ctx, message) {
|
|
603
|
+
if (!ctx.repoWarningShown) {
|
|
604
|
+
ctx.repoWarningShown = !0;
|
|
605
|
+
try {
|
|
606
|
+
warningHandler?.(message);
|
|
607
|
+
} catch {
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
function persistSnapshot(ctx, turn, absPath) {
|
|
612
|
+
try {
|
|
613
|
+
let snap = turn.files.get(absPath);
|
|
614
|
+
if (!snap)
|
|
615
|
+
return;
|
|
616
|
+
let turnDir = getTurnDir(ctx, turn.turnIndex);
|
|
617
|
+
mkdirSync(turnDir, { recursive: !0 });
|
|
618
|
+
let manifestPath = join(turnDir, "manifest.json"), manifest = readManifest(manifestPath), entry = { existed: snap.existed, createdByTool: snap.createdByTool };
|
|
619
|
+
if (snap.content) {
|
|
620
|
+
let snapFile = snapFileName(absPath);
|
|
621
|
+
writeFileSync(join(turnDir, snapFile), snap.content), entry.snapFile = snapFile;
|
|
622
|
+
}
|
|
623
|
+
manifest.files[absPath] = entry, turn.cwd && (manifest.cwd = turn.cwd), writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
|
|
624
|
+
} catch {
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
function readManifest(path) {
|
|
628
|
+
if (!existsSync(path))
|
|
629
|
+
return { files: {} };
|
|
630
|
+
try {
|
|
631
|
+
let parsed = JSON.parse(readFileSync(path, "utf-8"));
|
|
632
|
+
if (parsed && typeof parsed == "object" && !Array.isArray(parsed)) {
|
|
633
|
+
let files = parsed.files;
|
|
634
|
+
return {
|
|
635
|
+
cwd: typeof parsed.cwd == "string" ? parsed.cwd : void 0,
|
|
636
|
+
files: files && typeof files == "object" && !Array.isArray(files) ? files : {}
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
return { files: {} };
|
|
640
|
+
} catch {
|
|
641
|
+
return { files: {} };
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
function loadPersistedTurns(ctx) {
|
|
645
|
+
try {
|
|
646
|
+
let sessionDir = join(ROLLBACK_BASE, ctx.sessionId);
|
|
647
|
+
if (!existsSync(sessionDir))
|
|
648
|
+
return;
|
|
649
|
+
let loaded = [];
|
|
650
|
+
for (let dirName of readdirSync(sessionDir)) {
|
|
651
|
+
let match = /^turn-(\d+)$/.exec(dirName);
|
|
652
|
+
if (!match)
|
|
653
|
+
continue;
|
|
654
|
+
let turnIndex = Number(match[1]), turnDir = join(sessionDir, dirName), manifest = readManifest(join(turnDir, "manifest.json")), files = /* @__PURE__ */ new Map();
|
|
655
|
+
for (let [absPath, meta] of Object.entries(manifest.files)) {
|
|
656
|
+
let content;
|
|
657
|
+
if (meta.snapFile)
|
|
658
|
+
try {
|
|
659
|
+
content = readFileSync(join(turnDir, meta.snapFile));
|
|
660
|
+
} catch {
|
|
661
|
+
content = void 0;
|
|
662
|
+
}
|
|
663
|
+
files.set(absPath, { existed: meta.existed, content, createdByTool: meta.createdByTool });
|
|
664
|
+
}
|
|
665
|
+
loaded.push({ turnIndex, cwd: manifest.cwd, files });
|
|
666
|
+
}
|
|
667
|
+
loaded.sort((a, b) => a.turnIndex - b.turnIndex), ctx.turns = loaded, ctx.currentTurnIndex = loaded.length > 0 ? loaded[loaded.length - 1].turnIndex : -1, pruneTurns(ctx);
|
|
668
|
+
} catch {
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
function getTurnDir(ctx, turnIndex) {
|
|
672
|
+
return join(ROLLBACK_BASE, ctx.sessionId, `turn-${turnIndex}`);
|
|
673
|
+
}
|
|
674
|
+
function cleanupTurnFiles(ctx, turn) {
|
|
675
|
+
try {
|
|
676
|
+
let dir = getTurnDir(ctx, turn.turnIndex);
|
|
677
|
+
existsSync(dir) && rmSync(dir, { recursive: !0, force: !0 });
|
|
678
|
+
} catch {
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
function isPathUnderRoot(absPath, root) {
|
|
682
|
+
let normRoot = normalize(root).replace(/\\$/g, ""), normPath = normalize(absPath).replace(/\\$/g, "");
|
|
683
|
+
return process.platform === "win32" && (normRoot = normRoot.toLowerCase(), normPath = normPath.toLowerCase()), normPath === normRoot || normPath.startsWith(`${normRoot}/`) || normPath.startsWith(`${normRoot}\\`);
|
|
684
|
+
}
|
|
685
|
+
function getAllowedRoots(turn) {
|
|
686
|
+
return turn.cwd ? [
|
|
687
|
+
ROLLBACK_BASE,
|
|
688
|
+
join(homedir(), CONFIG_DIR_NAME),
|
|
689
|
+
join(dirname(getAgentDir()), "simple-memory"),
|
|
690
|
+
resolve(turn.cwd)
|
|
691
|
+
] : [];
|
|
692
|
+
}
|
|
693
|
+
function findAllowedRoot(absPath, turn) {
|
|
694
|
+
return getAllowedRoots(turn).filter((root) => isPathUnderRoot(absPath, root)).sort((a, b) => b.length - a.length)[0];
|
|
695
|
+
}
|
|
696
|
+
function lstatIfPresent(path) {
|
|
697
|
+
try {
|
|
698
|
+
return lstatSync(path);
|
|
699
|
+
} catch (error) {
|
|
700
|
+
if (error.code === "ENOENT")
|
|
701
|
+
return;
|
|
702
|
+
throw error;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
function safeRestoreParent(absPath, turn) {
|
|
706
|
+
let allowedRoot = findAllowedRoot(absPath, turn);
|
|
707
|
+
if (turn.cwd && !allowedRoot || lstatIfPresent(absPath)?.isSymbolicLink())
|
|
708
|
+
return;
|
|
709
|
+
if (!allowedRoot)
|
|
710
|
+
return dirname(absPath);
|
|
711
|
+
let rootEntry = lstatIfPresent(allowedRoot);
|
|
712
|
+
if (!rootEntry || !rootEntry.isDirectory() || rootEntry.isSymbolicLink())
|
|
713
|
+
return;
|
|
714
|
+
let parent = dirname(absPath), relativeParent = relative(allowedRoot, parent);
|
|
715
|
+
if (relativeParent.startsWith("..") || !isPathUnderRoot(parent, allowedRoot))
|
|
716
|
+
return;
|
|
717
|
+
let current = allowedRoot;
|
|
718
|
+
for (let segment of relativeParent.split(/[\\/]/).filter(Boolean)) {
|
|
719
|
+
current = join(current, segment);
|
|
720
|
+
let entry = lstatIfPresent(current);
|
|
721
|
+
if (entry) {
|
|
722
|
+
if (entry.isSymbolicLink() || !entry.isDirectory())
|
|
723
|
+
return;
|
|
724
|
+
} else
|
|
725
|
+
mkdirSync(current);
|
|
726
|
+
}
|
|
727
|
+
let realRoot = realpathSync.native(allowedRoot), realParent = realpathSync.native(parent);
|
|
728
|
+
if (isPathUnderRoot(realParent, realRoot) && !lstatIfPresent(absPath)?.isSymbolicLink())
|
|
729
|
+
return parent;
|
|
730
|
+
}
|
|
731
|
+
function restoreFileAtomically(absPath, content, turn) {
|
|
732
|
+
let parent = safeRestoreParent(absPath, turn);
|
|
733
|
+
if (!parent)
|
|
734
|
+
return !1;
|
|
735
|
+
let tempPath = join(parent, `.lunr-rollback-${randomUUID()}.tmp`), fd;
|
|
736
|
+
try {
|
|
737
|
+
return fd = openSync(tempPath, "wx", 384), writeFileSync(fd, content), fsyncSync(fd), closeSync(fd), fd = void 0, safeRestoreParent(absPath, turn) ? (renameSync(tempPath, absPath), !0) : !1;
|
|
738
|
+
} finally {
|
|
739
|
+
fd !== void 0 && closeSync(fd), rmSync(tempPath, { force: !0 });
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
function warnExternalModification(ctx, message) {
|
|
743
|
+
if (!(ctx.externalModWarningShown || !warningHandler)) {
|
|
744
|
+
ctx.externalModWarningShown = !0;
|
|
745
|
+
try {
|
|
746
|
+
warningHandler(message);
|
|
747
|
+
} catch {
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
function peekRollbackTurnsConsumed(sessionId) {
|
|
752
|
+
let ctx = getContext(sessionId);
|
|
753
|
+
if (!isRollbackEnabled(ctx.sessionId) || ctx.turns.length === 0)
|
|
754
|
+
return 0;
|
|
755
|
+
let consumed = 0;
|
|
756
|
+
for (let i = ctx.turns.length - 1; i >= 0 && (consumed++, !(ctx.turns[i].files.size > 0)); i--)
|
|
757
|
+
;
|
|
758
|
+
return consumed;
|
|
759
|
+
}
|
|
760
|
+
function rollbackLastTurn(sessionId) {
|
|
761
|
+
let ctx = getContext(sessionId), empty = { restored: [], deleted: [], turnsConsumed: 0 };
|
|
762
|
+
if (!isRollbackEnabled(ctx.sessionId))
|
|
763
|
+
return empty;
|
|
764
|
+
let turnsConsumed = 0;
|
|
765
|
+
for (; ctx.turns.length > 0 && ctx.turns[ctx.turns.length - 1].files.size === 0; ) {
|
|
766
|
+
let skipped = ctx.turns.pop();
|
|
767
|
+
skipped && (cleanupTurnFiles(ctx, skipped), turnsConsumed++);
|
|
768
|
+
}
|
|
769
|
+
if (ctx.turns.length === 0)
|
|
770
|
+
return empty;
|
|
771
|
+
turnsConsumed++;
|
|
772
|
+
let turn = ctx.turns[ctx.turns.length - 1], capture = ctx.settingsManager?.getRollbackCapture() ?? "copies", restored = [], deleted = [];
|
|
773
|
+
for (let [absPath, snap] of turn.files)
|
|
774
|
+
try {
|
|
775
|
+
if (turn.cwd && !findAllowedRoot(absPath, turn)) {
|
|
776
|
+
warnExternalModification(ctx, `Rollback skipped ${absPath}: outside the session working directory or lunR config dir.`);
|
|
777
|
+
continue;
|
|
778
|
+
}
|
|
779
|
+
if (snap.existed && snap.content) {
|
|
780
|
+
if (!snap.createdByTool && existsSync(absPath) && readFileSync(absPath).equals(snap.content))
|
|
781
|
+
continue;
|
|
782
|
+
if (!restoreFileAtomically(absPath, snap.content, turn)) {
|
|
783
|
+
warnExternalModification(ctx, `Rollback skipped ${absPath}: a symlink or junction made the path unsafe.`);
|
|
784
|
+
continue;
|
|
785
|
+
}
|
|
786
|
+
restored.push(absPath);
|
|
787
|
+
} else if (!snap.existed && (snap.createdByTool || capture === "hybrid" || capture === "shadow-git") && lstatIfPresent(absPath)) {
|
|
788
|
+
if (!safeRestoreParent(absPath, turn)) {
|
|
789
|
+
warnExternalModification(ctx, `Rollback skipped ${absPath}: a symlink or junction made the path unsafe.`);
|
|
790
|
+
continue;
|
|
791
|
+
}
|
|
792
|
+
unlinkSync(absPath), deleted.push(absPath);
|
|
793
|
+
}
|
|
794
|
+
} catch {
|
|
795
|
+
}
|
|
796
|
+
return cleanupTurnFiles(ctx, turn), ctx.turns.pop(), { restored, deleted, turnsConsumed };
|
|
797
|
+
}
|
|
798
|
+
function migrateRollbackSession(oldSessionId, newSessionId) {
|
|
799
|
+
if (oldSessionId === newSessionId)
|
|
800
|
+
return;
|
|
801
|
+
let ctx = contexts.get(oldSessionId);
|
|
802
|
+
ctx && (contexts.delete(oldSessionId), ctx.sessionId = newSessionId, contexts.set(newSessionId, ctx));
|
|
803
|
+
try {
|
|
804
|
+
let oldDir = join(ROLLBACK_BASE, oldSessionId), newDir = join(ROLLBACK_BASE, newSessionId);
|
|
805
|
+
if (existsSync(oldDir)) {
|
|
806
|
+
existsSync(newDir) && rmSync(newDir, { recursive: !0, force: !0 });
|
|
807
|
+
try {
|
|
808
|
+
renameSync(oldDir, newDir);
|
|
809
|
+
} catch {
|
|
810
|
+
cpSync(oldDir, newDir, { recursive: !0 }), rmSync(oldDir, { recursive: !0, force: !0 });
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
} catch {
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
function clearRollback(sessionId) {
|
|
817
|
+
if (sessionId === void 0) {
|
|
818
|
+
for (let ctx2 of contexts.values()) {
|
|
819
|
+
for (let turn of ctx2.turns)
|
|
820
|
+
cleanupTurnFiles(ctx2, turn);
|
|
821
|
+
try {
|
|
822
|
+
let sessionDir = join(ROLLBACK_BASE, ctx2.sessionId);
|
|
823
|
+
existsSync(sessionDir) && rmSync(sessionDir, { recursive: !0, force: !0 });
|
|
824
|
+
} catch {
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
contexts.clear();
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
let ctx = contexts.get(sessionId);
|
|
831
|
+
if (ctx) {
|
|
832
|
+
for (let turn of ctx.turns)
|
|
833
|
+
cleanupTurnFiles(ctx, turn);
|
|
834
|
+
try {
|
|
835
|
+
let sessionDir = join(ROLLBACK_BASE, sessionId);
|
|
836
|
+
existsSync(sessionDir) && rmSync(sessionDir, { recursive: !0, force: !0 });
|
|
837
|
+
} catch {
|
|
838
|
+
}
|
|
839
|
+
contexts.delete(sessionId);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
function snapFileName(absPath) {
|
|
843
|
+
return `${createHash("sha1").update(absPath).digest("hex")}.snap`;
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
export {
|
|
847
|
+
getAllPlanUsageResults,
|
|
848
|
+
clearPlanUsageCache,
|
|
849
|
+
registerUsageServiceBridge,
|
|
850
|
+
getUsageServiceBridge,
|
|
851
|
+
setRollbackWarningHandler,
|
|
852
|
+
initRollback,
|
|
853
|
+
isRollbackEnabled,
|
|
854
|
+
isRollbackSessionForceEnabled,
|
|
855
|
+
enableRollbackForSession,
|
|
856
|
+
disableRollbackForSession,
|
|
857
|
+
beginTurn,
|
|
858
|
+
rollbackSnapshotBeforeWrite,
|
|
859
|
+
captureTreeChanges,
|
|
860
|
+
peekRollbackTurnsConsumed,
|
|
861
|
+
rollbackLastTurn,
|
|
862
|
+
migrateRollbackSession,
|
|
863
|
+
clearRollback
|
|
864
|
+
};
|