@ashx-j/lunr 0.2.17 → 0.2.19
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 +26 -1
- package/README.md +2 -1
- package/dist/builtin-extensions/ashxj-thinking.d.ts +1 -0
- package/dist/builtin-extensions/ashxj-thinking.d.ts.map +1 -1
- package/dist/builtin-extensions/ashxj-thinking.js +44 -19
- package/dist/builtin-extensions/ashxj-thinking.js.map +1 -1
- package/dist/builtin-extensions/index.d.ts.map +1 -1
- package/dist/builtin-extensions/index.js +2 -1
- package/dist/builtin-extensions/index.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 +172 -171
- package/dist/builtin-extensions/pi-lsp-extension/src/index.js.map +1 -1
- package/dist/builtin-extensions/pi-lsp-extension/src/runtime.d.ts +50 -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 +131 -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 +276 -109
- 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-mcp-adapter/server-manager.d.ts +6 -1
- package/dist/builtin-extensions/pi-mcp-adapter/server-manager.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-mcp-adapter/server-manager.js +33 -8
- package/dist/builtin-extensions/pi-mcp-adapter/server-manager.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 +68 -15
- package/dist/builtin-extensions/pi-subagents/src/extension/index.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/wait-tool.d.ts +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/wait-tool.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/wait-tool.js +5 -2
- package/dist/builtin-extensions/pi-subagents/src/runs/background/wait-tool.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 +2 -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 +72 -31
- 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 +259 -168
- 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/cli-runtime.d.ts +3 -0
- package/dist/cli-runtime.d.ts.map +1 -0
- package/dist/cli-runtime.js +72 -0
- package/dist/cli-runtime.js.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +11 -60
- 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.map +1 -1
- package/dist/core/agent-session.js +6 -3
- package/dist/core/agent-session.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/keybindings.d.ts +2 -2
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +2 -2
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +1 -1
- package/dist/core/package-manager.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/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/agent-bridge.d.ts +6 -1
- package/dist/gateway/agent-bridge.d.ts.map +1 -1
- package/dist/gateway/agent-bridge.js +23 -6
- package/dist/gateway/agent-bridge.js.map +1 -1
- package/dist/gateway/cron.d.ts +1 -1
- package/dist/gateway/cron.d.ts.map +1 -1
- package/dist/gateway/cron.js +3 -1
- package/dist/gateway/cron.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +20 -14
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +10 -8
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/thinking-level-slash.d.ts +4 -0
- package/dist/modes/interactive/thinking-level-slash.d.ts.map +1 -0
- package/dist/modes/interactive/thinking-level-slash.js +23 -0
- package/dist/modes/interactive/thinking-level-slash.js.map +1 -0
- package/dist/node-runtime/agent-session-services-35WNVGMR.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-322XDDEM.js +28 -0
- package/dist/node-runtime/chunk-2SJB2AWP.js +47 -0
- package/dist/node-runtime/chunk-3NMWLTPV.js +64 -0
- package/dist/node-runtime/chunk-3WFAEVKS.js +115 -0
- package/dist/node-runtime/chunk-3X3KZKMI.js +49 -0
- package/dist/node-runtime/chunk-4CSFRBCN.js +7558 -0
- package/dist/node-runtime/chunk-4DJ6HEGH.js +296 -0
- package/dist/node-runtime/chunk-4FX25LWP.js +1345 -0
- package/dist/node-runtime/chunk-4HXHDDCF.js +16 -0
- package/dist/node-runtime/chunk-4I23VTC4.js +429 -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-5EFIU3OM.js +295 -0
- package/dist/node-runtime/chunk-6BEIBLQ3.js +53 -0
- package/dist/node-runtime/chunk-6KDIOJL3.js +72 -0
- package/dist/node-runtime/chunk-7N3YHTYF.js +26 -0
- package/dist/node-runtime/chunk-7NBZ5P7I.js +24 -0
- package/dist/node-runtime/chunk-AD6VXAO7.js +342 -0
- package/dist/node-runtime/chunk-ARC4KOTI.js +11178 -0
- package/dist/node-runtime/chunk-AROOY4BB.js +173 -0
- package/dist/node-runtime/chunk-ATGA2WLC.js +5646 -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-BOHIDQT4.js +21 -0
- package/dist/node-runtime/chunk-BRJX2PRC.js +53 -0
- package/dist/node-runtime/chunk-CBGB57XT.js +20211 -0
- package/dist/node-runtime/chunk-CCZJ3PYY.js +17 -0
- package/dist/node-runtime/chunk-CGBXPL3E.js +1171 -0
- package/dist/node-runtime/chunk-CJECDQKP.js +19 -0
- package/dist/node-runtime/chunk-CSFI6YXL.js +130 -0
- package/dist/node-runtime/chunk-DAPBPCBP.js +53 -0
- package/dist/node-runtime/chunk-DDWHZ633.js +37 -0
- package/dist/node-runtime/chunk-DMMTJQMQ.js +43 -0
- package/dist/node-runtime/chunk-DVGWF6A2.js +1180 -0
- package/dist/node-runtime/chunk-FQMM2EZ2.js +248 -0
- package/dist/node-runtime/chunk-FVDOXRUD.js +96 -0
- package/dist/node-runtime/chunk-G6LRAP36.js +105 -0
- package/dist/node-runtime/chunk-GKLEQ3I4.js +860 -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-IRPJXI6U.js +1269 -0
- package/dist/node-runtime/chunk-J26TSGDL.js +633 -0
- package/dist/node-runtime/chunk-JHYKXIMM.js +378 -0
- package/dist/node-runtime/chunk-JZQ7F36T.js +610 -0
- package/dist/node-runtime/chunk-KBKMCJDU.js +126 -0
- package/dist/node-runtime/chunk-KWA4OC2J.js +100 -0
- package/dist/node-runtime/chunk-M3LZLQW2.js +98 -0
- package/dist/node-runtime/chunk-MCUNIRD5.js +8388 -0
- package/dist/node-runtime/chunk-NUIFPZWX.js +209 -0
- package/dist/node-runtime/chunk-OBMWP3I5.js +68 -0
- package/dist/node-runtime/chunk-OCVIXVTZ.js +88 -0
- package/dist/node-runtime/chunk-OPEK5RRY.js +466 -0
- package/dist/node-runtime/chunk-OR4L3IB2.js +42 -0
- package/dist/node-runtime/chunk-PL6JKXWI.js +3622 -0
- package/dist/node-runtime/chunk-PNJSG3IZ.js +807 -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-QZMODZQ2.js +305 -0
- package/dist/node-runtime/chunk-RNBHABBA.js +986 -0
- package/dist/node-runtime/chunk-RQ2Q5IYR.js +72 -0
- package/dist/node-runtime/chunk-RRIZE6QQ.js +17 -0
- package/dist/node-runtime/chunk-SN6G4OU6.js +4753 -0
- package/dist/node-runtime/chunk-STERBGUB.js +949 -0
- package/dist/node-runtime/chunk-TFBIJTM3.js +966 -0
- package/dist/node-runtime/chunk-TXHKBRHZ.js +9450 -0
- package/dist/node-runtime/chunk-UWQYRSYQ.js +8973 -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-WKDK4C5P.js +2834 -0
- package/dist/node-runtime/chunk-XATUM2HK.js +46 -0
- package/dist/node-runtime/chunk-XBWPBZBN.js +125 -0
- package/dist/node-runtime/chunk-XTHQ7XR7.js +509 -0
- package/dist/node-runtime/chunk-ZRCBN365.js +1734 -0
- package/dist/node-runtime/cli-runtime.js +80 -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-DWUM5X3U.js +13 -0
- package/dist/node-runtime/commands-MV5KOZ64.js +291 -0
- package/dist/node-runtime/config-QDD5PUE2.js +73 -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-BK7CLEBX.js +188 -0
- package/dist/node-runtime/exa-LL64QZR2.js +329 -0
- package/dist/node-runtime/export-html-TEXVV5RP.js +150 -0
- package/dist/node-runtime/extension-input-O4HSAEM4.js +14 -0
- package/dist/node-runtime/extension-selector-X5FCX43D.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-UZXMFGWY.js +2137 -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-NJEE5CTU.js +1831 -0
- package/dist/node-runtime/index.js +859 -0
- package/dist/node-runtime/init-3C7Z24OI.js +28 -0
- package/dist/node-runtime/install-cli-EXMJQESX.js +308 -0
- package/dist/node-runtime/interactive-mode-QT5IKGQ5.js +56 -0
- package/dist/node-runtime/interactive-view-ILS6TAN5.js +247 -0
- package/dist/node-runtime/lsp-manager-3ASUSO4T.js +1104 -0
- package/dist/node-runtime/lunr-cron-QPBTKBGI.js +272 -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-7RKSZGEN.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-GUFZWW54.js +428 -0
- package/dist/node-runtime/pi-ollama-cloud-2F3Y2QNM.js +1440 -0
- package/dist/node-runtime/pi-prompt-template-model-QWTCGLJU.js +3946 -0
- package/dist/node-runtime/pi-subagents-7YJ3I4VE.js +6048 -0
- package/dist/node-runtime/pi-web-access-2CQGFLT2.js +1867 -0
- package/dist/node-runtime/print-mode-XSFM26EL.js +12 -0
- package/dist/node-runtime/proxy-modes-V6YVFH3C.js +685 -0
- package/dist/node-runtime/rpc-entry.js +62 -0
- package/dist/node-runtime/rpc-mode-W5ZTLTMZ.js +13 -0
- package/dist/node-runtime/runtime-bridges-3RKBDLNA.js +14 -0
- package/dist/node-runtime/session-manager-E7AREDTV.js +33 -0
- package/dist/node-runtime/session-selector-FJ7M2AIX.js +14 -0
- package/dist/node-runtime/settings-manager-GHPTUN7R.js +21 -0
- package/dist/node-runtime/src-BPQFJR76.js +2427 -0
- package/dist/node-runtime/subagent-executor-5Q5A4HJ2.js +8499 -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-L3JIBH2U.js +70 -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/rpc.d.ts +3 -0
- package/dist/rpc.d.ts.map +1 -0
- package/dist/rpc.js +18 -0
- package/dist/rpc.js.map +1 -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.map +1 -1
- package/dist/startup/interactive-view.js +1 -2
- package/dist/startup/interactive-view.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.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/docs/development.md +5 -1
- package/docs/features.md +2 -2
- package/docs/interactive-startup.md +95 -48
- package/docs/keybindings.md +2 -2
- package/docs/terminal-setup.md +1 -1
- package/docs/usage.md +1 -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/hidden-thinking-label.ts +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 +8 -8
|
@@ -0,0 +1,949 @@
|
|
|
1
|
+
import { createRequire as __lunrRequire } from "node:module"; const require = __lunrRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
minimatch
|
|
4
|
+
} from "./chunk-CGBXPL3E.js";
|
|
5
|
+
import {
|
|
6
|
+
buildSessionContext,
|
|
7
|
+
sessionEntryToContextMessages
|
|
8
|
+
} from "./chunk-GKLEQ3I4.js";
|
|
9
|
+
import {
|
|
10
|
+
convertToLlm,
|
|
11
|
+
createBranchSummaryMessage,
|
|
12
|
+
createCompactionSummaryMessage,
|
|
13
|
+
createCustomMessage
|
|
14
|
+
} from "./chunk-FVDOXRUD.js";
|
|
15
|
+
import {
|
|
16
|
+
isValidThinkingLevel
|
|
17
|
+
} from "./chunk-QZMODZQ2.js";
|
|
18
|
+
|
|
19
|
+
// packages/coding-agent/dist/core/compaction/utils.js
|
|
20
|
+
function createFileOps() {
|
|
21
|
+
return {
|
|
22
|
+
read: /* @__PURE__ */ new Set(),
|
|
23
|
+
written: /* @__PURE__ */ new Set(),
|
|
24
|
+
edited: /* @__PURE__ */ new Set()
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function extractFileOpsFromMessage(message, fileOps) {
|
|
28
|
+
if (message.role === "assistant" && !(!("content" in message) || !Array.isArray(message.content)))
|
|
29
|
+
for (let block of message.content) {
|
|
30
|
+
if (typeof block != "object" || block === null || !("type" in block) || block.type !== "toolCall" || !("arguments" in block) || !("name" in block))
|
|
31
|
+
continue;
|
|
32
|
+
let args = block.arguments;
|
|
33
|
+
if (!args)
|
|
34
|
+
continue;
|
|
35
|
+
let path = typeof args.path == "string" ? args.path : void 0;
|
|
36
|
+
if (path)
|
|
37
|
+
switch (block.name) {
|
|
38
|
+
case "read":
|
|
39
|
+
fileOps.read.add(path);
|
|
40
|
+
break;
|
|
41
|
+
case "write":
|
|
42
|
+
fileOps.written.add(path);
|
|
43
|
+
break;
|
|
44
|
+
case "edit":
|
|
45
|
+
fileOps.edited.add(path);
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function computeFileLists(fileOps) {
|
|
51
|
+
let modified = /* @__PURE__ */ new Set([...fileOps.edited, ...fileOps.written]), readOnly = [...fileOps.read].filter((f) => !modified.has(f)).sort(), modifiedFiles = [...modified].sort();
|
|
52
|
+
return { readFiles: readOnly, modifiedFiles };
|
|
53
|
+
}
|
|
54
|
+
function formatFileOperations(readFiles, modifiedFiles) {
|
|
55
|
+
let sections = [];
|
|
56
|
+
return readFiles.length > 0 && sections.push(`<read-files>
|
|
57
|
+
${readFiles.join(`
|
|
58
|
+
`)}
|
|
59
|
+
</read-files>`), modifiedFiles.length > 0 && sections.push(`<modified-files>
|
|
60
|
+
${modifiedFiles.join(`
|
|
61
|
+
`)}
|
|
62
|
+
</modified-files>`), sections.length === 0 ? "" : `
|
|
63
|
+
|
|
64
|
+
${sections.join(`
|
|
65
|
+
|
|
66
|
+
`)}`;
|
|
67
|
+
}
|
|
68
|
+
var TOOL_RESULT_MAX_CHARS = 2e3;
|
|
69
|
+
function truncateForSummary(text, maxChars) {
|
|
70
|
+
if (text.length <= maxChars)
|
|
71
|
+
return text;
|
|
72
|
+
let truncatedChars = text.length - maxChars;
|
|
73
|
+
return `${text.slice(0, maxChars)}
|
|
74
|
+
|
|
75
|
+
[... ${truncatedChars} more characters truncated]`;
|
|
76
|
+
}
|
|
77
|
+
function serializeConversation(messages) {
|
|
78
|
+
let parts = [];
|
|
79
|
+
for (let msg of messages)
|
|
80
|
+
if (msg.role === "user") {
|
|
81
|
+
let content = typeof msg.content == "string" ? msg.content : msg.content.filter((c) => c.type === "text").map((c) => c.text).join("");
|
|
82
|
+
content && parts.push(`[User]: ${content}`);
|
|
83
|
+
} else if (msg.role === "assistant") {
|
|
84
|
+
let textParts = [], thinkingParts = [], toolCalls = [];
|
|
85
|
+
for (let block of msg.content)
|
|
86
|
+
if (block.type === "text")
|
|
87
|
+
textParts.push(block.text);
|
|
88
|
+
else if (block.type === "thinking")
|
|
89
|
+
thinkingParts.push(block.thinking);
|
|
90
|
+
else if (block.type === "toolCall") {
|
|
91
|
+
let args = block.arguments, argsStr = Object.entries(args).map(([k, v]) => `${k}=${JSON.stringify(v)}`).join(", ");
|
|
92
|
+
toolCalls.push(`${block.name}(${argsStr})`);
|
|
93
|
+
}
|
|
94
|
+
thinkingParts.length > 0 && parts.push(`[Assistant thinking]: ${thinkingParts.join(`
|
|
95
|
+
`)}`), textParts.length > 0 && parts.push(`[Assistant]: ${textParts.join(`
|
|
96
|
+
`)}`), toolCalls.length > 0 && parts.push(`[Assistant tool calls]: ${toolCalls.join("; ")}`);
|
|
97
|
+
} else if (msg.role === "toolResult") {
|
|
98
|
+
let content = msg.content.filter((c) => c.type === "text").map((c) => c.text).join("");
|
|
99
|
+
content && parts.push(`[Tool result]: ${truncateForSummary(content, TOOL_RESULT_MAX_CHARS)}`);
|
|
100
|
+
}
|
|
101
|
+
return parts.join(`
|
|
102
|
+
|
|
103
|
+
`);
|
|
104
|
+
}
|
|
105
|
+
var SUMMARIZATION_SYSTEM_PROMPT = `You are a context summarization assistant. Your task is to read a conversation between a user and an AI assistant, then produce a structured summary following the exact format specified.
|
|
106
|
+
|
|
107
|
+
Do NOT continue the conversation. Do NOT respond to any questions in the conversation. ONLY output the structured summary.`;
|
|
108
|
+
|
|
109
|
+
// packages/coding-agent/dist/core/compaction/compaction.js
|
|
110
|
+
import { completeSimple } from "@ashx-j/lunr-ai/compat";
|
|
111
|
+
function extractFileOperations(messages, entries, prevCompactionIndex) {
|
|
112
|
+
let fileOps = createFileOps();
|
|
113
|
+
if (prevCompactionIndex >= 0) {
|
|
114
|
+
let prevCompaction = entries[prevCompactionIndex];
|
|
115
|
+
if (!prevCompaction.fromHook && prevCompaction.details) {
|
|
116
|
+
let details = prevCompaction.details;
|
|
117
|
+
if (Array.isArray(details.readFiles))
|
|
118
|
+
for (let f of details.readFiles)
|
|
119
|
+
fileOps.read.add(f);
|
|
120
|
+
if (Array.isArray(details.modifiedFiles))
|
|
121
|
+
for (let f of details.modifiedFiles)
|
|
122
|
+
fileOps.edited.add(f);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
for (let msg of messages)
|
|
126
|
+
extractFileOpsFromMessage(msg, fileOps);
|
|
127
|
+
return fileOps;
|
|
128
|
+
}
|
|
129
|
+
function getMessageFromEntryForCompaction(entry) {
|
|
130
|
+
if (entry.type !== "compaction")
|
|
131
|
+
return sessionEntryToContextMessages(entry)[0];
|
|
132
|
+
}
|
|
133
|
+
var DEFAULT_COMPACTION_SETTINGS = {
|
|
134
|
+
enabled: !0,
|
|
135
|
+
reserveTokens: 16384,
|
|
136
|
+
keepRecentTokens: 2e4
|
|
137
|
+
};
|
|
138
|
+
function calculateContextTokens(usage) {
|
|
139
|
+
return usage.totalTokens || usage.input + usage.output + usage.cacheRead + usage.cacheWrite;
|
|
140
|
+
}
|
|
141
|
+
function getAssistantUsage(msg) {
|
|
142
|
+
if (msg.role === "assistant" && "usage" in msg) {
|
|
143
|
+
let assistantMsg = msg;
|
|
144
|
+
if (assistantMsg.stopReason !== "aborted" && assistantMsg.stopReason !== "error" && assistantMsg.usage && calculateContextTokens(assistantMsg.usage) > 0)
|
|
145
|
+
return assistantMsg.usage;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function getLastAssistantUsage(entries) {
|
|
149
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
150
|
+
let entry = entries[i];
|
|
151
|
+
if (entry.type === "message") {
|
|
152
|
+
let usage = getAssistantUsage(entry.message);
|
|
153
|
+
if (usage)
|
|
154
|
+
return usage;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function getLastAssistantUsageInfo(messages) {
|
|
159
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
160
|
+
let usage = getAssistantUsage(messages[i]);
|
|
161
|
+
if (usage)
|
|
162
|
+
return { usage, index: i };
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function estimateContextTokens(messages) {
|
|
166
|
+
let usageInfo = getLastAssistantUsageInfo(messages);
|
|
167
|
+
if (!usageInfo) {
|
|
168
|
+
let estimated = 0;
|
|
169
|
+
for (let message of messages)
|
|
170
|
+
estimated += estimateTokens(message);
|
|
171
|
+
return {
|
|
172
|
+
tokens: estimated,
|
|
173
|
+
usageTokens: 0,
|
|
174
|
+
trailingTokens: estimated,
|
|
175
|
+
lastUsageIndex: null
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
let usageTokens = calculateContextTokens(usageInfo.usage), trailingTokens = 0;
|
|
179
|
+
for (let i = usageInfo.index + 1; i < messages.length; i++)
|
|
180
|
+
trailingTokens += estimateTokens(messages[i]);
|
|
181
|
+
return {
|
|
182
|
+
tokens: usageTokens + trailingTokens,
|
|
183
|
+
usageTokens,
|
|
184
|
+
trailingTokens,
|
|
185
|
+
lastUsageIndex: usageInfo.index
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function shouldCompact(contextTokens, contextWindow, settings) {
|
|
189
|
+
return settings.enabled ? contextTokens > contextWindow - settings.reserveTokens : !1;
|
|
190
|
+
}
|
|
191
|
+
var ESTIMATED_IMAGE_CHARS = 4800;
|
|
192
|
+
function estimateTextAndImageContentChars(content) {
|
|
193
|
+
if (typeof content == "string")
|
|
194
|
+
return content.length;
|
|
195
|
+
let chars = 0;
|
|
196
|
+
for (let block of content)
|
|
197
|
+
block.type === "text" && block.text ? chars += block.text.length : block.type === "image" && (chars += ESTIMATED_IMAGE_CHARS);
|
|
198
|
+
return chars;
|
|
199
|
+
}
|
|
200
|
+
function estimateTokens(message) {
|
|
201
|
+
let chars = 0;
|
|
202
|
+
switch (message.role) {
|
|
203
|
+
case "user":
|
|
204
|
+
return chars = estimateTextAndImageContentChars(message.content), Math.ceil(chars / 4);
|
|
205
|
+
case "assistant": {
|
|
206
|
+
let assistant = message;
|
|
207
|
+
for (let block of assistant.content)
|
|
208
|
+
block.type === "text" ? chars += block.text.length : block.type === "thinking" ? chars += block.thinking.length : block.type === "toolCall" && (chars += block.name.length + JSON.stringify(block.arguments).length);
|
|
209
|
+
return Math.ceil(chars / 4);
|
|
210
|
+
}
|
|
211
|
+
case "custom":
|
|
212
|
+
case "toolResult":
|
|
213
|
+
return chars = estimateTextAndImageContentChars(message.content), Math.ceil(chars / 4);
|
|
214
|
+
case "bashExecution":
|
|
215
|
+
return chars = message.command.length + message.output.length, Math.ceil(chars / 4);
|
|
216
|
+
case "branchSummary":
|
|
217
|
+
case "compactionSummary":
|
|
218
|
+
return chars = message.summary.length, Math.ceil(chars / 4);
|
|
219
|
+
}
|
|
220
|
+
return 0;
|
|
221
|
+
}
|
|
222
|
+
function isCutPointMessage(message) {
|
|
223
|
+
switch (message.role) {
|
|
224
|
+
case "user":
|
|
225
|
+
case "assistant":
|
|
226
|
+
case "bashExecution":
|
|
227
|
+
case "custom":
|
|
228
|
+
case "branchSummary":
|
|
229
|
+
case "compactionSummary":
|
|
230
|
+
return !0;
|
|
231
|
+
case "toolResult":
|
|
232
|
+
return !1;
|
|
233
|
+
}
|
|
234
|
+
return !1;
|
|
235
|
+
}
|
|
236
|
+
function isTurnStartMessage(message) {
|
|
237
|
+
switch (message.role) {
|
|
238
|
+
case "user":
|
|
239
|
+
case "bashExecution":
|
|
240
|
+
case "custom":
|
|
241
|
+
case "branchSummary":
|
|
242
|
+
case "compactionSummary":
|
|
243
|
+
return !0;
|
|
244
|
+
case "assistant":
|
|
245
|
+
case "toolResult":
|
|
246
|
+
return !1;
|
|
247
|
+
}
|
|
248
|
+
return !1;
|
|
249
|
+
}
|
|
250
|
+
function isTurnStartEntry(entry) {
|
|
251
|
+
return entry.type === "compaction" ? !1 : sessionEntryToContextMessages(entry).some(isTurnStartMessage);
|
|
252
|
+
}
|
|
253
|
+
function findValidCutPoints(entries, startIndex, endIndex) {
|
|
254
|
+
let cutPoints = [];
|
|
255
|
+
for (let i = startIndex; i < endIndex; i++) {
|
|
256
|
+
let entry = entries[i];
|
|
257
|
+
entry.type !== "compaction" && sessionEntryToContextMessages(entry).some(isCutPointMessage) && cutPoints.push(i);
|
|
258
|
+
}
|
|
259
|
+
return cutPoints;
|
|
260
|
+
}
|
|
261
|
+
function findTurnStartIndex(entries, entryIndex, startIndex) {
|
|
262
|
+
for (let i = entryIndex; i >= startIndex; i--)
|
|
263
|
+
if (isTurnStartEntry(entries[i]))
|
|
264
|
+
return i;
|
|
265
|
+
return -1;
|
|
266
|
+
}
|
|
267
|
+
function findCutPoint(entries, startIndex, endIndex, keepRecentTokens) {
|
|
268
|
+
let cutPoints = findValidCutPoints(entries, startIndex, endIndex);
|
|
269
|
+
if (cutPoints.length === 0)
|
|
270
|
+
return { firstKeptEntryIndex: startIndex, turnStartIndex: -1, isSplitTurn: !1 };
|
|
271
|
+
let accumulatedTokens = 0, cutIndex = cutPoints[0];
|
|
272
|
+
for (let i = endIndex - 1; i >= startIndex; i--) {
|
|
273
|
+
let entry = entries[i], messageTokens = sessionEntryToContextMessages(entry).reduce((sum, message) => sum + estimateTokens(message), 0);
|
|
274
|
+
if (messageTokens !== 0 && (accumulatedTokens += messageTokens, accumulatedTokens >= keepRecentTokens)) {
|
|
275
|
+
let nextCutPoint = cutPoints.find((candidate) => candidate >= i);
|
|
276
|
+
if (nextCutPoint !== void 0)
|
|
277
|
+
cutIndex = nextCutPoint;
|
|
278
|
+
else
|
|
279
|
+
for (let c = cutPoints.length - 1; c >= 0; c--)
|
|
280
|
+
if (cutPoints[c] <= i) {
|
|
281
|
+
cutIndex = cutPoints[c];
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
for (; cutIndex > startIndex; ) {
|
|
288
|
+
let prevEntry = entries[cutIndex - 1];
|
|
289
|
+
if (prevEntry.type === "compaction" || sessionEntryToContextMessages(prevEntry).length > 0)
|
|
290
|
+
break;
|
|
291
|
+
cutIndex--;
|
|
292
|
+
}
|
|
293
|
+
let cutEntry = entries[cutIndex], startsTurn = isTurnStartEntry(cutEntry), turnStartIndex = startsTurn ? -1 : findTurnStartIndex(entries, cutIndex, startIndex);
|
|
294
|
+
return {
|
|
295
|
+
firstKeptEntryIndex: cutIndex,
|
|
296
|
+
turnStartIndex,
|
|
297
|
+
isSplitTurn: !startsTurn && turnStartIndex !== -1
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
var SUMMARIZATION_PROMPT = `The messages above are a conversation to summarize. Create a structured context checkpoint summary that another LLM will use to continue the work.
|
|
301
|
+
|
|
302
|
+
Use this EXACT format:
|
|
303
|
+
|
|
304
|
+
## Goal
|
|
305
|
+
[What is the user trying to accomplish? Can be multiple items if the session covers different tasks.]
|
|
306
|
+
|
|
307
|
+
## Constraints & Preferences
|
|
308
|
+
- [Any constraints, preferences, or requirements mentioned by user]
|
|
309
|
+
- [Or "(none)" if none were mentioned]
|
|
310
|
+
|
|
311
|
+
## Progress
|
|
312
|
+
### Done
|
|
313
|
+
- [x] [Completed tasks/changes]
|
|
314
|
+
|
|
315
|
+
### In Progress
|
|
316
|
+
- [ ] [Current work]
|
|
317
|
+
|
|
318
|
+
### Blocked
|
|
319
|
+
- [Issues preventing progress, if any]
|
|
320
|
+
|
|
321
|
+
## Key Decisions
|
|
322
|
+
- **[Decision]**: [Brief rationale]
|
|
323
|
+
|
|
324
|
+
## Next Steps
|
|
325
|
+
1. [Ordered list of what should happen next]
|
|
326
|
+
|
|
327
|
+
## Critical Context
|
|
328
|
+
- [Any data, examples, or references needed to continue]
|
|
329
|
+
- [Or "(none)" if not applicable]
|
|
330
|
+
|
|
331
|
+
Keep each section concise. Preserve exact file paths, function names, and error messages.`, UPDATE_SUMMARIZATION_PROMPT = `The messages above are NEW conversation messages to incorporate into the existing summary provided in <previous-summary> tags.
|
|
332
|
+
|
|
333
|
+
Update the existing structured summary with new information. RULES:
|
|
334
|
+
- PRESERVE all existing information from the previous summary
|
|
335
|
+
- ADD new progress, decisions, and context from the new messages
|
|
336
|
+
- UPDATE the Progress section: move items from "In Progress" to "Done" when completed
|
|
337
|
+
- UPDATE "Next Steps" based on what was accomplished
|
|
338
|
+
- PRESERVE exact file paths, function names, and error messages
|
|
339
|
+
- If something is no longer relevant, you may remove it
|
|
340
|
+
|
|
341
|
+
Use this EXACT format:
|
|
342
|
+
|
|
343
|
+
## Goal
|
|
344
|
+
[Preserve existing goals, add new ones if the task expanded]
|
|
345
|
+
|
|
346
|
+
## Constraints & Preferences
|
|
347
|
+
- [Preserve existing, add new ones discovered]
|
|
348
|
+
|
|
349
|
+
## Progress
|
|
350
|
+
### Done
|
|
351
|
+
- [x] [Include previously done items AND newly completed items]
|
|
352
|
+
|
|
353
|
+
### In Progress
|
|
354
|
+
- [ ] [Current work - update based on progress]
|
|
355
|
+
|
|
356
|
+
### Blocked
|
|
357
|
+
- [Current blockers - remove if resolved]
|
|
358
|
+
|
|
359
|
+
## Key Decisions
|
|
360
|
+
- **[Decision]**: [Brief rationale] (preserve all previous, add new)
|
|
361
|
+
|
|
362
|
+
## Next Steps
|
|
363
|
+
1. [Update based on current state]
|
|
364
|
+
|
|
365
|
+
## Critical Context
|
|
366
|
+
- [Preserve important context, add new if needed]
|
|
367
|
+
|
|
368
|
+
Keep each section concise. Preserve exact file paths, function names, and error messages.`;
|
|
369
|
+
function createSummarizationOptions(model, maxTokens, apiKey, headers, env, signal, thinkingLevel, cacheRetention) {
|
|
370
|
+
let options = { maxTokens, signal, apiKey, headers, env, cacheRetention };
|
|
371
|
+
return model.reasoning && thinkingLevel && thinkingLevel !== "off" && (options.reasoning = thinkingLevel), options;
|
|
372
|
+
}
|
|
373
|
+
async function completeSummarization(model, context, options, streamFn) {
|
|
374
|
+
return streamFn ? (await streamFn(model, context, options)).result() : completeSimple(model, context, options);
|
|
375
|
+
}
|
|
376
|
+
async function generateSummary(currentMessages, model, reserveTokens, apiKey, headers, signal, customInstructions, previousSummary, thinkingLevel, streamFn, env) {
|
|
377
|
+
let maxTokens = Math.min(Math.floor(0.8 * reserveTokens), model.maxTokens > 0 ? model.maxTokens : Number.POSITIVE_INFINITY), basePrompt = previousSummary ? UPDATE_SUMMARIZATION_PROMPT : SUMMARIZATION_PROMPT;
|
|
378
|
+
customInstructions && (basePrompt = `${basePrompt}
|
|
379
|
+
|
|
380
|
+
Additional focus: ${customInstructions}`);
|
|
381
|
+
let llmMessages = convertToLlm(currentMessages), promptText = `<conversation>
|
|
382
|
+
${serializeConversation(llmMessages)}
|
|
383
|
+
</conversation>
|
|
384
|
+
|
|
385
|
+
`;
|
|
386
|
+
previousSummary && (promptText += `<previous-summary>
|
|
387
|
+
${previousSummary}
|
|
388
|
+
</previous-summary>
|
|
389
|
+
|
|
390
|
+
`), promptText += basePrompt;
|
|
391
|
+
let summarizationMessages = [
|
|
392
|
+
{
|
|
393
|
+
role: "user",
|
|
394
|
+
content: [{ type: "text", text: promptText }],
|
|
395
|
+
timestamp: Date.now()
|
|
396
|
+
}
|
|
397
|
+
], completionOptions = createSummarizationOptions(model, maxTokens, apiKey, headers, env, signal, thinkingLevel), response = await completeSummarization(model, { systemPrompt: SUMMARIZATION_SYSTEM_PROMPT, messages: summarizationMessages }, completionOptions, streamFn);
|
|
398
|
+
if (response.stopReason === "error")
|
|
399
|
+
throw new Error(`Summarization failed: ${response.errorMessage || "Unknown error"}`);
|
|
400
|
+
return response.content.filter((c) => c.type === "text").map((c) => c.text).join(`
|
|
401
|
+
`);
|
|
402
|
+
}
|
|
403
|
+
function prepareCompaction(pathEntries, settings) {
|
|
404
|
+
if (pathEntries.length > 0 && pathEntries[pathEntries.length - 1].type === "compaction")
|
|
405
|
+
return;
|
|
406
|
+
let prevCompactionIndex = -1;
|
|
407
|
+
for (let i = pathEntries.length - 1; i >= 0; i--)
|
|
408
|
+
if (pathEntries[i].type === "compaction") {
|
|
409
|
+
prevCompactionIndex = i;
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
let previousSummary, boundaryStart = 0;
|
|
413
|
+
if (prevCompactionIndex >= 0) {
|
|
414
|
+
let prevCompaction = pathEntries[prevCompactionIndex];
|
|
415
|
+
previousSummary = prevCompaction.summary;
|
|
416
|
+
let firstKeptEntryIndex = pathEntries.findIndex((entry) => entry.id === prevCompaction.firstKeptEntryId);
|
|
417
|
+
boundaryStart = firstKeptEntryIndex >= 0 ? firstKeptEntryIndex : prevCompactionIndex + 1;
|
|
418
|
+
}
|
|
419
|
+
let boundaryEnd = pathEntries.length, tokensBefore = estimateContextTokens(buildSessionContext(pathEntries).messages).tokens, cutPoint = findCutPoint(pathEntries, boundaryStart, boundaryEnd, settings.keepRecentTokens), firstKeptEntry = pathEntries[cutPoint.firstKeptEntryIndex];
|
|
420
|
+
if (!firstKeptEntry?.id)
|
|
421
|
+
return;
|
|
422
|
+
let firstKeptEntryId = firstKeptEntry.id, historyEnd = cutPoint.isSplitTurn ? cutPoint.turnStartIndex : cutPoint.firstKeptEntryIndex, messagesToSummarize = [];
|
|
423
|
+
for (let i = boundaryStart; i < historyEnd; i++) {
|
|
424
|
+
let msg = getMessageFromEntryForCompaction(pathEntries[i]);
|
|
425
|
+
msg && messagesToSummarize.push(msg);
|
|
426
|
+
}
|
|
427
|
+
let turnPrefixMessages = [];
|
|
428
|
+
if (cutPoint.isSplitTurn)
|
|
429
|
+
for (let i = cutPoint.turnStartIndex; i < cutPoint.firstKeptEntryIndex; i++) {
|
|
430
|
+
let msg = getMessageFromEntryForCompaction(pathEntries[i]);
|
|
431
|
+
msg && turnPrefixMessages.push(msg);
|
|
432
|
+
}
|
|
433
|
+
if (messagesToSummarize.length === 0 && turnPrefixMessages.length === 0)
|
|
434
|
+
return;
|
|
435
|
+
let fileOps = extractFileOperations(messagesToSummarize, pathEntries, prevCompactionIndex);
|
|
436
|
+
if (cutPoint.isSplitTurn)
|
|
437
|
+
for (let msg of turnPrefixMessages)
|
|
438
|
+
extractFileOpsFromMessage(msg, fileOps);
|
|
439
|
+
return {
|
|
440
|
+
firstKeptEntryId,
|
|
441
|
+
messagesToSummarize,
|
|
442
|
+
turnPrefixMessages,
|
|
443
|
+
isSplitTurn: cutPoint.isSplitTurn,
|
|
444
|
+
tokensBefore,
|
|
445
|
+
previousSummary,
|
|
446
|
+
fileOps,
|
|
447
|
+
settings
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
var TURN_PREFIX_SUMMARIZATION_PROMPT = `This is the PREFIX of a turn that was too large to keep. The SUFFIX (recent work) is retained.
|
|
451
|
+
|
|
452
|
+
Summarize the prefix to provide context for the retained suffix:
|
|
453
|
+
|
|
454
|
+
## Original Request
|
|
455
|
+
[What did the user ask for in this turn?]
|
|
456
|
+
|
|
457
|
+
## Early Progress
|
|
458
|
+
- [Key decisions and work done in the prefix]
|
|
459
|
+
|
|
460
|
+
## Context for Suffix
|
|
461
|
+
- [Information needed to understand the retained recent work]
|
|
462
|
+
|
|
463
|
+
Be concise. Focus on what's needed to understand the kept suffix.`;
|
|
464
|
+
async function compact(preparation, model, apiKey, headers, customInstructions, signal, thinkingLevel, streamFn, env) {
|
|
465
|
+
let { firstKeptEntryId, messagesToSummarize, turnPrefixMessages, isSplitTurn, tokensBefore, previousSummary, fileOps, settings } = preparation, summary;
|
|
466
|
+
if (isSplitTurn && turnPrefixMessages.length > 0) {
|
|
467
|
+
let historyResult = messagesToSummarize.length > 0 ? await generateSummary(messagesToSummarize, model, settings.reserveTokens, apiKey, headers, signal, customInstructions, previousSummary, thinkingLevel, streamFn, env) : "No prior history.", turnPrefixResult = await generateTurnPrefixSummary(turnPrefixMessages, model, settings.reserveTokens, apiKey, headers, env, signal, thinkingLevel, streamFn);
|
|
468
|
+
summary = `${historyResult}
|
|
469
|
+
|
|
470
|
+
---
|
|
471
|
+
|
|
472
|
+
**Turn Context (split turn):**
|
|
473
|
+
|
|
474
|
+
${turnPrefixResult}`;
|
|
475
|
+
} else
|
|
476
|
+
summary = await generateSummary(messagesToSummarize, model, settings.reserveTokens, apiKey, headers, signal, customInstructions, previousSummary, thinkingLevel, streamFn, env);
|
|
477
|
+
let { readFiles, modifiedFiles } = computeFileLists(fileOps);
|
|
478
|
+
if (summary += formatFileOperations(readFiles, modifiedFiles), !firstKeptEntryId)
|
|
479
|
+
throw new Error("First kept entry has no UUID - session may need migration");
|
|
480
|
+
return {
|
|
481
|
+
summary,
|
|
482
|
+
firstKeptEntryId,
|
|
483
|
+
tokensBefore,
|
|
484
|
+
details: { readFiles, modifiedFiles }
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
async function generateTurnPrefixSummary(messages, model, reserveTokens, apiKey, headers, env, signal, thinkingLevel, streamFn) {
|
|
488
|
+
let maxTokens = Math.min(Math.floor(0.5 * reserveTokens), model.maxTokens > 0 ? model.maxTokens : Number.POSITIVE_INFINITY), llmMessages = convertToLlm(messages), summarizationMessages = [
|
|
489
|
+
{
|
|
490
|
+
role: "user",
|
|
491
|
+
content: [{ type: "text", text: `<conversation>
|
|
492
|
+
${serializeConversation(llmMessages)}
|
|
493
|
+
</conversation>
|
|
494
|
+
|
|
495
|
+
${TURN_PREFIX_SUMMARIZATION_PROMPT}` }],
|
|
496
|
+
timestamp: Date.now()
|
|
497
|
+
}
|
|
498
|
+
], response = await completeSummarization(model, { systemPrompt: SUMMARIZATION_SYSTEM_PROMPT, messages: summarizationMessages }, createSummarizationOptions(model, maxTokens, apiKey, headers, env, signal, thinkingLevel), streamFn);
|
|
499
|
+
if (response.stopReason === "error")
|
|
500
|
+
throw new Error(`Turn prefix summarization failed: ${response.errorMessage || "Unknown error"}`);
|
|
501
|
+
return response.content.filter((c) => c.type === "text").map((c) => c.text).join(`
|
|
502
|
+
`);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// packages/coding-agent/dist/core/compaction/branch-summarization.js
|
|
506
|
+
import { completeSimple as completeSimple2 } from "@ashx-j/lunr-ai/compat";
|
|
507
|
+
function collectEntriesForBranchSummary(session, oldLeafId, targetId) {
|
|
508
|
+
if (!oldLeafId)
|
|
509
|
+
return { entries: [], commonAncestorId: null };
|
|
510
|
+
let oldPath = new Set(session.getBranch(oldLeafId).map((e) => e.id)), targetPath = session.getBranch(targetId), commonAncestorId = null;
|
|
511
|
+
for (let i = targetPath.length - 1; i >= 0; i--)
|
|
512
|
+
if (oldPath.has(targetPath[i].id)) {
|
|
513
|
+
commonAncestorId = targetPath[i].id;
|
|
514
|
+
break;
|
|
515
|
+
}
|
|
516
|
+
let entries = [], current = oldLeafId;
|
|
517
|
+
for (; current && current !== commonAncestorId; ) {
|
|
518
|
+
let entry = session.getEntry(current);
|
|
519
|
+
if (!entry)
|
|
520
|
+
break;
|
|
521
|
+
entries.push(entry), current = entry.parentId;
|
|
522
|
+
}
|
|
523
|
+
return entries.reverse(), { entries, commonAncestorId };
|
|
524
|
+
}
|
|
525
|
+
function getMessageFromEntry(entry) {
|
|
526
|
+
switch (entry.type) {
|
|
527
|
+
case "message":
|
|
528
|
+
return entry.message.role === "toolResult" ? void 0 : entry.message;
|
|
529
|
+
case "custom_message":
|
|
530
|
+
return createCustomMessage(entry.customType, entry.content, entry.display, entry.details, entry.timestamp);
|
|
531
|
+
case "branch_summary":
|
|
532
|
+
return createBranchSummaryMessage(entry.summary, entry.fromId, entry.timestamp);
|
|
533
|
+
case "compaction":
|
|
534
|
+
return createCompactionSummaryMessage(entry.summary, entry.tokensBefore, entry.timestamp);
|
|
535
|
+
// These don't contribute to conversation content
|
|
536
|
+
case "thinking_level_change":
|
|
537
|
+
case "model_change":
|
|
538
|
+
case "custom":
|
|
539
|
+
case "label":
|
|
540
|
+
case "session_info":
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
function prepareBranchEntries(entries, tokenBudget = 0) {
|
|
545
|
+
let messages = [], fileOps = createFileOps(), totalTokens = 0;
|
|
546
|
+
for (let entry of entries)
|
|
547
|
+
if (entry.type === "branch_summary" && !entry.fromHook && entry.details) {
|
|
548
|
+
let details = entry.details;
|
|
549
|
+
if (Array.isArray(details.readFiles))
|
|
550
|
+
for (let f of details.readFiles)
|
|
551
|
+
fileOps.read.add(f);
|
|
552
|
+
if (Array.isArray(details.modifiedFiles))
|
|
553
|
+
for (let f of details.modifiedFiles)
|
|
554
|
+
fileOps.edited.add(f);
|
|
555
|
+
}
|
|
556
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
557
|
+
let entry = entries[i], message = getMessageFromEntry(entry);
|
|
558
|
+
if (!message)
|
|
559
|
+
continue;
|
|
560
|
+
extractFileOpsFromMessage(message, fileOps);
|
|
561
|
+
let tokens = estimateTokens(message);
|
|
562
|
+
if (tokenBudget > 0 && totalTokens + tokens > tokenBudget) {
|
|
563
|
+
(entry.type === "compaction" || entry.type === "branch_summary") && totalTokens < tokenBudget * 0.9 && (messages.unshift(message), totalTokens += tokens);
|
|
564
|
+
break;
|
|
565
|
+
}
|
|
566
|
+
messages.unshift(message), totalTokens += tokens;
|
|
567
|
+
}
|
|
568
|
+
return { messages, fileOps, totalTokens };
|
|
569
|
+
}
|
|
570
|
+
var BRANCH_SUMMARY_PREAMBLE = `The user explored a different conversation branch before returning here.
|
|
571
|
+
Summary of that exploration:
|
|
572
|
+
|
|
573
|
+
`, BRANCH_SUMMARY_PROMPT = `Create a structured summary of this conversation branch for context when returning later.
|
|
574
|
+
|
|
575
|
+
Use this EXACT format:
|
|
576
|
+
|
|
577
|
+
## Goal
|
|
578
|
+
[What was the user trying to accomplish in this branch?]
|
|
579
|
+
|
|
580
|
+
## Constraints & Preferences
|
|
581
|
+
- [Any constraints, preferences, or requirements mentioned]
|
|
582
|
+
- [Or "(none)" if none were mentioned]
|
|
583
|
+
|
|
584
|
+
## Progress
|
|
585
|
+
### Done
|
|
586
|
+
- [x] [Completed tasks/changes]
|
|
587
|
+
|
|
588
|
+
### In Progress
|
|
589
|
+
- [ ] [Work that was started but not finished]
|
|
590
|
+
|
|
591
|
+
### Blocked
|
|
592
|
+
- [Issues preventing progress, if any]
|
|
593
|
+
|
|
594
|
+
## Key Decisions
|
|
595
|
+
- **[Decision]**: [Brief rationale]
|
|
596
|
+
|
|
597
|
+
## Next Steps
|
|
598
|
+
1. [What should happen next to continue this work]
|
|
599
|
+
|
|
600
|
+
Keep each section concise. Preserve exact file paths, function names, and error messages.`;
|
|
601
|
+
async function generateBranchSummary(entries, options) {
|
|
602
|
+
let { model, apiKey, headers, env, signal, customInstructions, replaceInstructions, reserveTokens = 16384, streamFn } = options, tokenBudget = (model.contextWindow || 128e3) - reserveTokens, { messages, fileOps } = prepareBranchEntries(entries, tokenBudget);
|
|
603
|
+
if (messages.length === 0)
|
|
604
|
+
return { summary: "No content to summarize" };
|
|
605
|
+
let llmMessages = convertToLlm(messages), conversationText = serializeConversation(llmMessages), instructions;
|
|
606
|
+
replaceInstructions && customInstructions ? instructions = customInstructions : customInstructions ? instructions = `${BRANCH_SUMMARY_PROMPT}
|
|
607
|
+
|
|
608
|
+
Additional focus: ${customInstructions}` : instructions = BRANCH_SUMMARY_PROMPT;
|
|
609
|
+
let summarizationMessages = [
|
|
610
|
+
{
|
|
611
|
+
role: "user",
|
|
612
|
+
content: [{ type: "text", text: `<conversation>
|
|
613
|
+
${conversationText}
|
|
614
|
+
</conversation>
|
|
615
|
+
|
|
616
|
+
${instructions}` }],
|
|
617
|
+
timestamp: Date.now()
|
|
618
|
+
}
|
|
619
|
+
], context = { systemPrompt: SUMMARIZATION_SYSTEM_PROMPT, messages: summarizationMessages }, requestOptions = { apiKey, headers, env, signal, maxTokens: 2048 }, response = streamFn ? await (await streamFn(model, context, requestOptions)).result() : await completeSimple2(model, context, requestOptions);
|
|
620
|
+
if (response.stopReason === "aborted")
|
|
621
|
+
return { aborted: !0 };
|
|
622
|
+
if (response.stopReason === "error")
|
|
623
|
+
return { error: response.errorMessage || "Summarization failed" };
|
|
624
|
+
let summary = response.content.filter((c) => c.type === "text").map((c) => c.text).join(`
|
|
625
|
+
`);
|
|
626
|
+
summary = BRANCH_SUMMARY_PREAMBLE + summary;
|
|
627
|
+
let { readFiles, modifiedFiles } = computeFileLists(fileOps);
|
|
628
|
+
return summary += formatFileOperations(readFiles, modifiedFiles), {
|
|
629
|
+
summary: summary || "No summary generated",
|
|
630
|
+
readFiles,
|
|
631
|
+
modifiedFiles
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
// packages/coding-agent/dist/core/model-resolver.js
|
|
636
|
+
import { modelsAreEqual } from "@ashx-j/lunr-ai";
|
|
637
|
+
import chalk from "chalk";
|
|
638
|
+
|
|
639
|
+
// packages/coding-agent/dist/core/defaults.js
|
|
640
|
+
var DEFAULT_THINKING_LEVEL = "medium";
|
|
641
|
+
|
|
642
|
+
// packages/coding-agent/dist/core/model-resolver.js
|
|
643
|
+
var defaultModelPerProvider = {
|
|
644
|
+
"amazon-bedrock": "us.anthropic.claude-opus-4-6-v1",
|
|
645
|
+
"ant-ling": "Ring-2.6-1T",
|
|
646
|
+
anthropic: "claude-opus-4-8",
|
|
647
|
+
openai: "gpt-5.5",
|
|
648
|
+
"azure-openai-responses": "gpt-5.4",
|
|
649
|
+
"openai-codex": "gpt-5.5",
|
|
650
|
+
radius: "auto",
|
|
651
|
+
nvidia: "nvidia/nemotron-3-super-120b-a12b",
|
|
652
|
+
deepseek: "deepseek-v4-pro",
|
|
653
|
+
google: "gemini-3.1-pro-preview",
|
|
654
|
+
"google-vertex": "gemini-3.1-pro-preview",
|
|
655
|
+
"github-copilot": "gpt-5.4",
|
|
656
|
+
openrouter: "moonshotai/kimi-k2.6",
|
|
657
|
+
"vercel-ai-gateway": "zai/glm-5.1",
|
|
658
|
+
xai: "grok-4.5",
|
|
659
|
+
groq: "openai/gpt-oss-120b",
|
|
660
|
+
cerebras: "zai-glm-4.7",
|
|
661
|
+
zai: "glm-5.1",
|
|
662
|
+
"zai-coding-cn": "glm-5.1",
|
|
663
|
+
mistral: "devstral-medium-latest",
|
|
664
|
+
minimax: "MiniMax-M2.7",
|
|
665
|
+
"minimax-cn": "MiniMax-M2.7",
|
|
666
|
+
moonshotai: "kimi-k2.6",
|
|
667
|
+
"moonshotai-cn": "kimi-k2.6",
|
|
668
|
+
huggingface: "moonshotai/Kimi-K2.6",
|
|
669
|
+
fireworks: "accounts/fireworks/models/kimi-k2p6",
|
|
670
|
+
together: "moonshotai/Kimi-K2.6",
|
|
671
|
+
opencode: "kimi-k2.6",
|
|
672
|
+
"opencode-go": "kimi-k2.6",
|
|
673
|
+
"kimi-coding": "kimi-for-coding",
|
|
674
|
+
"cloudflare-workers-ai": "@cf/moonshotai/kimi-k2.6",
|
|
675
|
+
"cloudflare-ai-gateway": "workers-ai/@cf/moonshotai/kimi-k2.6",
|
|
676
|
+
xiaomi: "mimo-v2.5-pro",
|
|
677
|
+
"xiaomi-token-plan-cn": "mimo-v2.5-pro",
|
|
678
|
+
"xiaomi-token-plan-ams": "mimo-v2.5-pro",
|
|
679
|
+
"xiaomi-token-plan-sgp": "mimo-v2.5-pro",
|
|
680
|
+
"qwen-token-plan": "qwen3.8-max-preview",
|
|
681
|
+
"qwen-token-plan-cn": "qwen3.8-max-preview",
|
|
682
|
+
"qwen-cloud": "qwen3.8-max",
|
|
683
|
+
"qwen-cloud-cn": "qwen3.8-max"
|
|
684
|
+
};
|
|
685
|
+
function isAlias(id) {
|
|
686
|
+
return id.endsWith("-latest") ? !0 : !/-\d{8}$/.test(id);
|
|
687
|
+
}
|
|
688
|
+
function findExactModelReferenceMatch(modelReference, availableModels) {
|
|
689
|
+
let trimmedReference = modelReference.trim();
|
|
690
|
+
if (!trimmedReference)
|
|
691
|
+
return;
|
|
692
|
+
let normalizedReference = trimmedReference.toLowerCase(), canonicalMatches = availableModels.filter((model) => `${model.provider}/${model.id}`.toLowerCase() === normalizedReference);
|
|
693
|
+
if (canonicalMatches.length === 1)
|
|
694
|
+
return canonicalMatches[0];
|
|
695
|
+
if (canonicalMatches.length > 1)
|
|
696
|
+
return;
|
|
697
|
+
let slashIndex = trimmedReference.indexOf("/");
|
|
698
|
+
if (slashIndex !== -1) {
|
|
699
|
+
let provider = trimmedReference.substring(0, slashIndex).trim(), modelId = trimmedReference.substring(slashIndex + 1).trim();
|
|
700
|
+
if (provider && modelId) {
|
|
701
|
+
let providerMatches = availableModels.filter((model) => model.provider.toLowerCase() === provider.toLowerCase() && model.id.toLowerCase() === modelId.toLowerCase());
|
|
702
|
+
if (providerMatches.length === 1)
|
|
703
|
+
return providerMatches[0];
|
|
704
|
+
if (providerMatches.length > 1)
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
let idMatches = availableModels.filter((model) => model.id.toLowerCase() === normalizedReference);
|
|
709
|
+
return idMatches.length === 1 ? idMatches[0] : void 0;
|
|
710
|
+
}
|
|
711
|
+
function tryMatchModel(modelPattern, availableModels) {
|
|
712
|
+
let exactMatch = findExactModelReferenceMatch(modelPattern, availableModels);
|
|
713
|
+
if (exactMatch)
|
|
714
|
+
return exactMatch;
|
|
715
|
+
let matches = availableModels.filter((m) => m.id.toLowerCase().includes(modelPattern.toLowerCase()) || m.name?.toLowerCase().includes(modelPattern.toLowerCase()));
|
|
716
|
+
if (matches.length === 0)
|
|
717
|
+
return;
|
|
718
|
+
let aliases = matches.filter((m) => isAlias(m.id)), datedVersions = matches.filter((m) => !isAlias(m.id));
|
|
719
|
+
return aliases.length > 0 ? (aliases.sort((a, b) => b.id.localeCompare(a.id)), aliases[0]) : (datedVersions.sort((a, b) => b.id.localeCompare(a.id)), datedVersions[0]);
|
|
720
|
+
}
|
|
721
|
+
function buildFallbackModel(provider, modelId, availableModels) {
|
|
722
|
+
let providerModels = availableModels.filter((m) => m.provider === provider);
|
|
723
|
+
if (providerModels.length === 0)
|
|
724
|
+
return;
|
|
725
|
+
let defaultId = defaultModelPerProvider[provider];
|
|
726
|
+
return {
|
|
727
|
+
...defaultId ? providerModels.find((m) => m.id === defaultId) ?? providerModels[0] : providerModels[0],
|
|
728
|
+
id: modelId,
|
|
729
|
+
name: modelId
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
function parseModelPattern(pattern, availableModels, options) {
|
|
733
|
+
let exactMatch = tryMatchModel(pattern, availableModels);
|
|
734
|
+
if (exactMatch)
|
|
735
|
+
return { model: exactMatch, thinkingLevel: void 0, warning: void 0 };
|
|
736
|
+
let lastColonIndex = pattern.lastIndexOf(":");
|
|
737
|
+
if (lastColonIndex === -1)
|
|
738
|
+
return { model: void 0, thinkingLevel: void 0, warning: void 0 };
|
|
739
|
+
let prefix = pattern.substring(0, lastColonIndex), suffix = pattern.substring(lastColonIndex + 1);
|
|
740
|
+
if (isValidThinkingLevel(suffix)) {
|
|
741
|
+
let result = parseModelPattern(prefix, availableModels, options);
|
|
742
|
+
return result.model ? {
|
|
743
|
+
model: result.model,
|
|
744
|
+
thinkingLevel: result.warning ? void 0 : suffix,
|
|
745
|
+
warning: result.warning
|
|
746
|
+
} : result;
|
|
747
|
+
} else {
|
|
748
|
+
if (!(options?.allowInvalidThinkingLevelFallback ?? !0))
|
|
749
|
+
return { model: void 0, thinkingLevel: void 0, warning: void 0 };
|
|
750
|
+
let result = parseModelPattern(prefix, availableModels, options);
|
|
751
|
+
return result.model ? {
|
|
752
|
+
model: result.model,
|
|
753
|
+
thinkingLevel: void 0,
|
|
754
|
+
warning: `Invalid thinking level "${suffix}" in pattern "${pattern}". Using default instead.`
|
|
755
|
+
} : result;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
async function resolveModelScopeWithDiagnostics(patterns, modelRuntime) {
|
|
759
|
+
let availableModels = [...await modelRuntime.getAvailable()], scopedModels = [], diagnostics = [];
|
|
760
|
+
for (let pattern of patterns) {
|
|
761
|
+
if (pattern.includes("*") || pattern.includes("?") || pattern.includes("[")) {
|
|
762
|
+
let colonIdx = pattern.lastIndexOf(":"), globPattern = pattern, thinkingLevel2;
|
|
763
|
+
if (colonIdx !== -1) {
|
|
764
|
+
let suffix = pattern.substring(colonIdx + 1);
|
|
765
|
+
isValidThinkingLevel(suffix) && (thinkingLevel2 = suffix, globPattern = pattern.substring(0, colonIdx));
|
|
766
|
+
}
|
|
767
|
+
let matchingModels = availableModels.filter((m) => {
|
|
768
|
+
let fullId = `${m.provider}/${m.id}`;
|
|
769
|
+
return minimatch(fullId, globPattern, { nocase: !0 }) || minimatch(m.id, globPattern, { nocase: !0 });
|
|
770
|
+
});
|
|
771
|
+
if (matchingModels.length === 0) {
|
|
772
|
+
diagnostics.push({ type: "warning", message: `No models match pattern "${pattern}"`, pattern });
|
|
773
|
+
continue;
|
|
774
|
+
}
|
|
775
|
+
for (let model2 of matchingModels)
|
|
776
|
+
scopedModels.find((sm) => modelsAreEqual(sm.model, model2)) || scopedModels.push({ model: model2, thinkingLevel: thinkingLevel2 });
|
|
777
|
+
continue;
|
|
778
|
+
}
|
|
779
|
+
let { model, thinkingLevel, warning } = parseModelPattern(pattern, availableModels);
|
|
780
|
+
if (warning && diagnostics.push({ type: "warning", message: warning, pattern }), !model) {
|
|
781
|
+
diagnostics.push({ type: "warning", message: `No models match pattern "${pattern}"`, pattern });
|
|
782
|
+
continue;
|
|
783
|
+
}
|
|
784
|
+
scopedModels.find((sm) => modelsAreEqual(sm.model, model)) || scopedModels.push({ model, thinkingLevel });
|
|
785
|
+
}
|
|
786
|
+
return { scopedModels, diagnostics };
|
|
787
|
+
}
|
|
788
|
+
async function resolveModelScope(patterns, modelRuntime) {
|
|
789
|
+
let { scopedModels, diagnostics } = await resolveModelScopeWithDiagnostics(patterns, modelRuntime);
|
|
790
|
+
for (let diagnostic of diagnostics)
|
|
791
|
+
console.warn(chalk.yellow(`Warning: ${diagnostic.message}`));
|
|
792
|
+
return scopedModels;
|
|
793
|
+
}
|
|
794
|
+
function resolveCliModel(options) {
|
|
795
|
+
let { cliProvider, cliModel, cliThinking, modelRuntime } = options;
|
|
796
|
+
if (!cliModel)
|
|
797
|
+
return { model: void 0, warning: void 0, error: void 0 };
|
|
798
|
+
let availableModels = [...modelRuntime.getModels()];
|
|
799
|
+
if (availableModels.length === 0)
|
|
800
|
+
return {
|
|
801
|
+
model: void 0,
|
|
802
|
+
warning: void 0,
|
|
803
|
+
error: "No models available. Check your installation or add models to models.json."
|
|
804
|
+
};
|
|
805
|
+
let providerMap = /* @__PURE__ */ new Map();
|
|
806
|
+
for (let m of availableModels)
|
|
807
|
+
providerMap.set(m.provider.toLowerCase(), m.provider);
|
|
808
|
+
let provider = cliProvider ? providerMap.get(cliProvider.toLowerCase()) : void 0;
|
|
809
|
+
if (cliProvider && !provider)
|
|
810
|
+
return {
|
|
811
|
+
model: void 0,
|
|
812
|
+
warning: void 0,
|
|
813
|
+
error: `Unknown provider "${cliProvider}". Use --list-models to see available providers/models.`
|
|
814
|
+
};
|
|
815
|
+
let pattern = cliModel, inferredProvider = !1;
|
|
816
|
+
if (!provider) {
|
|
817
|
+
let slashIndex = cliModel.indexOf("/");
|
|
818
|
+
if (slashIndex !== -1) {
|
|
819
|
+
let maybeProvider = cliModel.substring(0, slashIndex), canonical = providerMap.get(maybeProvider.toLowerCase());
|
|
820
|
+
canonical && (provider = canonical, pattern = cliModel.substring(slashIndex + 1), inferredProvider = !0);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
if (!provider) {
|
|
824
|
+
let lower = cliModel.toLowerCase(), exact = availableModels.find((m) => m.id.toLowerCase() === lower || `${m.provider}/${m.id}`.toLowerCase() === lower);
|
|
825
|
+
if (exact)
|
|
826
|
+
return { model: exact, warning: void 0, thinkingLevel: void 0, error: void 0 };
|
|
827
|
+
}
|
|
828
|
+
if (cliProvider && provider) {
|
|
829
|
+
let prefix = `${provider}/`;
|
|
830
|
+
cliModel.toLowerCase().startsWith(prefix.toLowerCase()) && (pattern = cliModel.substring(prefix.length));
|
|
831
|
+
}
|
|
832
|
+
let candidates = provider ? availableModels.filter((m) => m.provider === provider) : availableModels, { model, thinkingLevel, warning } = parseModelPattern(pattern, candidates, {
|
|
833
|
+
allowInvalidThinkingLevelFallback: !1
|
|
834
|
+
});
|
|
835
|
+
if (model) {
|
|
836
|
+
if (inferredProvider) {
|
|
837
|
+
let rawExactMatches = availableModels.filter((m) => m.id.toLowerCase() === cliModel.toLowerCase() && !modelsAreEqual(m, model));
|
|
838
|
+
if (rawExactMatches.length > 0 && !modelRuntime.hasConfiguredAuth(model.provider)) {
|
|
839
|
+
let authenticatedRawMatches = rawExactMatches.filter((m) => modelRuntime.hasConfiguredAuth(m.provider));
|
|
840
|
+
if (authenticatedRawMatches.length === 1)
|
|
841
|
+
return {
|
|
842
|
+
model: authenticatedRawMatches[0],
|
|
843
|
+
thinkingLevel: void 0,
|
|
844
|
+
warning: void 0,
|
|
845
|
+
error: void 0
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
return { model, thinkingLevel, warning, error: void 0 };
|
|
850
|
+
}
|
|
851
|
+
if (inferredProvider) {
|
|
852
|
+
let lower = cliModel.toLowerCase(), exact = availableModels.find((m) => m.id.toLowerCase() === lower || `${m.provider}/${m.id}`.toLowerCase() === lower);
|
|
853
|
+
if (exact)
|
|
854
|
+
return { model: exact, warning: void 0, thinkingLevel: void 0, error: void 0 };
|
|
855
|
+
let fallback = parseModelPattern(cliModel, availableModels, {
|
|
856
|
+
allowInvalidThinkingLevelFallback: !1
|
|
857
|
+
});
|
|
858
|
+
if (fallback.model)
|
|
859
|
+
return {
|
|
860
|
+
model: fallback.model,
|
|
861
|
+
thinkingLevel: fallback.thinkingLevel,
|
|
862
|
+
warning: fallback.warning,
|
|
863
|
+
error: void 0
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
if (provider) {
|
|
867
|
+
let fallbackPattern = pattern, fallbackThinking;
|
|
868
|
+
if (!cliThinking) {
|
|
869
|
+
let lastColon = pattern.lastIndexOf(":");
|
|
870
|
+
if (lastColon !== -1) {
|
|
871
|
+
let suffix = pattern.substring(lastColon + 1);
|
|
872
|
+
isValidThinkingLevel(suffix) && (fallbackPattern = pattern.substring(0, lastColon), fallbackThinking = suffix);
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
let fallbackModel = buildFallbackModel(provider, fallbackPattern, availableModels);
|
|
876
|
+
if (fallbackModel) {
|
|
877
|
+
let requestedThinking = cliThinking ?? fallbackThinking, model2 = requestedThinking && requestedThinking !== "off" ? { ...fallbackModel, reasoning: !0 } : fallbackModel, fallbackWarning = warning ? `${warning} Model "${fallbackPattern}" not found for provider "${provider}". Using custom model id.` : `Model "${fallbackPattern}" not found for provider "${provider}". Using custom model id.`;
|
|
878
|
+
return { model: model2, thinkingLevel: fallbackThinking, warning: fallbackWarning, error: void 0 };
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
let display = provider ? `${provider}/${pattern}` : cliModel;
|
|
882
|
+
return {
|
|
883
|
+
model: void 0,
|
|
884
|
+
thinkingLevel: void 0,
|
|
885
|
+
warning,
|
|
886
|
+
error: `Model "${display}" not found. Use --list-models to see available models.`
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
async function findInitialModel(options) {
|
|
890
|
+
let { cliProvider, cliModel, scopedModels, isContinuing, defaultProvider, defaultModelId, defaultThinkingLevel, modelRuntime } = options, model, thinkingLevel = DEFAULT_THINKING_LEVEL;
|
|
891
|
+
if (cliProvider && cliModel) {
|
|
892
|
+
let resolved = resolveCliModel({
|
|
893
|
+
cliProvider,
|
|
894
|
+
cliModel,
|
|
895
|
+
modelRuntime
|
|
896
|
+
});
|
|
897
|
+
if (resolved.error && (console.error(chalk.red(resolved.error)), process.exit(1)), resolved.model)
|
|
898
|
+
return { model: resolved.model, thinkingLevel: DEFAULT_THINKING_LEVEL, fallbackMessage: void 0 };
|
|
899
|
+
}
|
|
900
|
+
if (scopedModels.length > 0 && !isContinuing)
|
|
901
|
+
return {
|
|
902
|
+
model: scopedModels[0].model,
|
|
903
|
+
thinkingLevel: scopedModels[0].thinkingLevel ?? defaultThinkingLevel ?? DEFAULT_THINKING_LEVEL,
|
|
904
|
+
fallbackMessage: void 0
|
|
905
|
+
};
|
|
906
|
+
if (defaultProvider && defaultModelId) {
|
|
907
|
+
let found = modelRuntime.getModel(defaultProvider, defaultModelId);
|
|
908
|
+
if (found && modelRuntime.hasConfiguredAuth(found.provider))
|
|
909
|
+
return model = found, defaultThinkingLevel && (thinkingLevel = defaultThinkingLevel), { model, thinkingLevel, fallbackMessage: void 0 };
|
|
910
|
+
}
|
|
911
|
+
let availableModels = [...await modelRuntime.getAvailable()];
|
|
912
|
+
if (availableModels.length > 0) {
|
|
913
|
+
for (let provider of Object.keys(defaultModelPerProvider)) {
|
|
914
|
+
let defaultId = defaultModelPerProvider[provider], match = availableModels.find((m) => m.provider === provider && m.id === defaultId);
|
|
915
|
+
if (match)
|
|
916
|
+
return { model: match, thinkingLevel: DEFAULT_THINKING_LEVEL, fallbackMessage: void 0 };
|
|
917
|
+
}
|
|
918
|
+
return { model: availableModels[0], thinkingLevel: DEFAULT_THINKING_LEVEL, fallbackMessage: void 0 };
|
|
919
|
+
}
|
|
920
|
+
return { model: void 0, thinkingLevel: DEFAULT_THINKING_LEVEL, fallbackMessage: void 0 };
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
export {
|
|
924
|
+
createFileOps,
|
|
925
|
+
extractFileOpsFromMessage,
|
|
926
|
+
computeFileLists,
|
|
927
|
+
serializeConversation,
|
|
928
|
+
DEFAULT_COMPACTION_SETTINGS,
|
|
929
|
+
calculateContextTokens,
|
|
930
|
+
getLastAssistantUsage,
|
|
931
|
+
estimateContextTokens,
|
|
932
|
+
shouldCompact,
|
|
933
|
+
estimateTokens,
|
|
934
|
+
findTurnStartIndex,
|
|
935
|
+
findCutPoint,
|
|
936
|
+
generateSummary,
|
|
937
|
+
prepareCompaction,
|
|
938
|
+
compact,
|
|
939
|
+
collectEntriesForBranchSummary,
|
|
940
|
+
prepareBranchEntries,
|
|
941
|
+
generateBranchSummary,
|
|
942
|
+
DEFAULT_THINKING_LEVEL,
|
|
943
|
+
defaultModelPerProvider,
|
|
944
|
+
findExactModelReferenceMatch,
|
|
945
|
+
resolveModelScopeWithDiagnostics,
|
|
946
|
+
resolveModelScope,
|
|
947
|
+
resolveCliModel,
|
|
948
|
+
findInitialModel
|
|
949
|
+
};
|