@herbertgao/pi-extensions 2026.10.19 → 2026.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -4
- package/THIRD_PARTY_NOTICES.md +53 -2
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +6 -0
- package/node_modules/@herbertgao/pi-subagents/README.md +142 -45
- package/node_modules/@herbertgao/pi-subagents/docs/rpc.md +17 -7
- package/node_modules/@herbertgao/pi-subagents/package.json +4 -4
- package/node_modules/@herbertgao/pi-subagents/src/agent-manager.ts +111 -59
- package/node_modules/@herbertgao/pi-subagents/src/agent-runner.ts +135 -117
- package/node_modules/@herbertgao/pi-subagents/src/cross-extension-rpc.ts +41 -14
- package/node_modules/@herbertgao/pi-subagents/src/index.ts +110 -19
- package/node_modules/@herbertgao/pi-subagents/src/nested-tools.ts +8 -0
- package/node_modules/@herbertgao/pi-subagents/src/prompts.ts +31 -0
- package/node_modules/@tintinweb/pi-tasks/CHANGELOG.md +270 -0
- package/node_modules/@tintinweb/pi-tasks/CONTRIBUTING.md +67 -0
- package/node_modules/@tintinweb/pi-tasks/CUSTOMIZING.md +289 -0
- package/node_modules/@tintinweb/pi-tasks/LICENSE +21 -0
- package/node_modules/@tintinweb/pi-tasks/README.md +417 -0
- package/node_modules/@tintinweb/pi-tasks/SECURITY.md +107 -0
- package/node_modules/@tintinweb/pi-tasks/dist/auto-clear.d.ts +64 -0
- package/node_modules/@tintinweb/pi-tasks/dist/auto-clear.js +129 -0
- package/node_modules/@tintinweb/pi-tasks/dist/index.d.ts +17 -0
- package/node_modules/@tintinweb/pi-tasks/dist/index.js +1338 -0
- package/node_modules/@tintinweb/pi-tasks/dist/process-tracker.d.ts +29 -0
- package/node_modules/@tintinweb/pi-tasks/dist/process-tracker.js +121 -0
- package/node_modules/@tintinweb/pi-tasks/dist/reminder-cadence.d.ts +39 -0
- package/node_modules/@tintinweb/pi-tasks/dist/reminder-cadence.js +61 -0
- package/node_modules/@tintinweb/pi-tasks/dist/task-glyphs.d.ts +48 -0
- package/node_modules/@tintinweb/pi-tasks/dist/task-glyphs.js +68 -0
- package/node_modules/@tintinweb/pi-tasks/dist/task-paths.d.ts +44 -0
- package/node_modules/@tintinweb/pi-tasks/dist/task-paths.js +60 -0
- package/node_modules/@tintinweb/pi-tasks/dist/task-sort.d.ts +23 -0
- package/node_modules/@tintinweb/pi-tasks/dist/task-sort.js +69 -0
- package/node_modules/@tintinweb/pi-tasks/dist/task-store.d.ts +61 -0
- package/node_modules/@tintinweb/pi-tasks/dist/task-store.js +397 -0
- package/node_modules/@tintinweb/pi-tasks/dist/tasks-config.d.ts +16 -0
- package/node_modules/@tintinweb/pi-tasks/dist/tasks-config.js +51 -0
- package/node_modules/@tintinweb/pi-tasks/dist/types.d.ts +36 -0
- package/node_modules/@tintinweb/pi-tasks/dist/types.js +4 -0
- package/node_modules/@tintinweb/pi-tasks/dist/ui/settings-menu.d.ts +15 -0
- package/node_modules/@tintinweb/pi-tasks/dist/ui/settings-menu.js +140 -0
- package/node_modules/@tintinweb/pi-tasks/dist/ui/task-widget.d.ts +69 -0
- package/node_modules/@tintinweb/pi-tasks/dist/ui/task-widget.js +278 -0
- package/node_modules/@tintinweb/pi-tasks/package.json +57 -0
- package/node_modules/@tintinweb/pi-tasks/src/auto-clear.ts +134 -0
- package/node_modules/@tintinweb/pi-tasks/src/index.ts +1417 -0
- package/node_modules/@tintinweb/pi-tasks/src/process-tracker.ts +140 -0
- package/node_modules/@tintinweb/pi-tasks/src/reminder-cadence.ts +90 -0
- package/node_modules/@tintinweb/pi-tasks/src/task-glyphs.ts +110 -0
- package/node_modules/@tintinweb/pi-tasks/src/task-paths.ts +65 -0
- package/node_modules/@tintinweb/pi-tasks/src/task-sort.ts +90 -0
- package/node_modules/@tintinweb/pi-tasks/src/task-store.ts +402 -0
- package/node_modules/@tintinweb/pi-tasks/src/tasks-config.ts +77 -0
- package/node_modules/@tintinweb/pi-tasks/src/types.ts +40 -0
- package/node_modules/@tintinweb/pi-tasks/src/ui/settings-menu.ts +174 -0
- package/node_modules/@tintinweb/pi-tasks/src/ui/task-widget.ts +325 -0
- package/node_modules/pi-commandcode-provider/CHANGELOG.md +330 -0
- package/node_modules/pi-commandcode-provider/CONTRIBUTING.md +192 -0
- package/node_modules/pi-commandcode-provider/LICENSE +21 -0
- package/node_modules/pi-commandcode-provider/README.md +243 -0
- package/node_modules/pi-commandcode-provider/RELEASE.md +194 -0
- package/node_modules/pi-commandcode-provider/index.ts +309 -0
- package/node_modules/pi-commandcode-provider/package.json +91 -0
- package/node_modules/pi-commandcode-provider/scripts/live-e2e-profile.mjs +87 -0
- package/node_modules/pi-commandcode-provider/scripts/pi-authenticated.mjs +50 -0
- package/node_modules/pi-commandcode-provider/scripts/pi-isolated.mjs +79 -0
- package/node_modules/pi-commandcode-provider/src/api-key.ts +69 -0
- package/node_modules/pi-commandcode-provider/src/auth-server.ts +229 -0
- package/node_modules/pi-commandcode-provider/src/commandcode-catalog-overrides.ts +28 -0
- package/node_modules/pi-commandcode-provider/src/commandcode-catalog.ts +260 -0
- package/node_modules/pi-commandcode-provider/src/converters.ts +477 -0
- package/node_modules/pi-commandcode-provider/src/core.ts +836 -0
- package/node_modules/pi-commandcode-provider/src/cost.ts +76 -0
- package/node_modules/pi-commandcode-provider/src/json-schema.ts +417 -0
- package/node_modules/pi-commandcode-provider/src/models.ts +515 -0
- package/node_modules/pi-commandcode-provider/src/oauth.ts +229 -0
- package/node_modules/pi-commandcode-provider/src/overflow.ts +120 -0
- package/node_modules/pi-commandcode-provider/src/pricing.ts +370 -0
- package/node_modules/pi-commandcode-provider/src/quota-command.ts +66 -0
- package/node_modules/pi-commandcode-provider/src/quota-format.ts +143 -0
- package/node_modules/pi-commandcode-provider/src/quota-types.ts +47 -0
- package/node_modules/pi-commandcode-provider/src/quota.ts +357 -0
- package/node_modules/pi-commandcode-provider/src/responses-stream.ts +249 -0
- package/node_modules/pi-commandcode-provider/src/runtime.ts +330 -0
- package/node_modules/pi-commandcode-provider/src/transcript.ts +56 -0
- package/node_modules/pi-commandcode-provider/src/transport.ts +147 -0
- package/node_modules/pi-commandcode-provider/src/types.ts +212 -0
- package/node_modules/pi-commandcode-provider/src/usage.ts +261 -0
- package/node_modules/pi-lens/CHANGELOG.md +149 -0
- package/node_modules/pi-lens/README.md +12 -2
- package/node_modules/pi-lens/config/markdownlint/run-no-fix.mjs +36 -0
- package/node_modules/pi-lens/dist/{chunk-WME2OQST.js → chunk-2453RRJ2.js} +11 -6
- package/node_modules/pi-lens/dist/{chunk-FZKFVUEC.js → chunk-2BKUFQKR.js} +276 -208
- package/node_modules/pi-lens/dist/chunk-2TS4GLOJ.js +31 -0
- package/node_modules/pi-lens/dist/{chunk-QHSNL7B2.js → chunk-2ZE3AUJQ.js} +12 -14
- package/node_modules/pi-lens/dist/{chunk-MPKRJBPK.js → chunk-35WKJWO5.js} +28 -30
- package/node_modules/pi-lens/dist/chunk-3JAHQBSY.js +27 -0
- package/node_modules/pi-lens/dist/{chunk-4LM3VAZH.js → chunk-3O5EII3W.js} +2 -2
- package/node_modules/pi-lens/dist/chunk-447YZL4S.js +25 -0
- package/node_modules/pi-lens/dist/{chunk-H7OR7DFZ.js → chunk-4B2YFN4U.js} +25 -21
- package/node_modules/pi-lens/dist/{chunk-OSTKYB55.js → chunk-4BKU7PV3.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-RRV3FNNM.js → chunk-4LL2VRNY.js} +27 -28
- package/node_modules/pi-lens/dist/{chunk-BZARLRJW.js → chunk-4NBWFYWW.js} +9 -9
- package/node_modules/pi-lens/dist/{chunk-KKCK636N.js → chunk-4QG55RRC.js} +12 -12
- package/node_modules/pi-lens/dist/{chunk-RQS4QQSD.js → chunk-4W52ZKZX.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-Z2XAOKHK.js → chunk-565VRUP4.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-HWDAVBFU.js → chunk-57X2CDRX.js} +23 -23
- package/node_modules/pi-lens/dist/{chunk-MB6PXBUA.js → chunk-5F3XF3SX.js} +7 -15
- package/node_modules/pi-lens/dist/{chunk-O4BJFESU.js → chunk-5RNB4HVK.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-ZMAUPOMG.js → chunk-5T5A6YAJ.js} +35 -34
- package/node_modules/pi-lens/dist/{chunk-4ZYJHQMB.js → chunk-6FIRFP6A.js} +12 -12
- package/node_modules/pi-lens/dist/{chunk-4YHYPW2G.js → chunk-6GMGEKQN.js} +9 -5
- package/node_modules/pi-lens/dist/{chunk-4LOE5R5P.js → chunk-6LJOJ6EO.js} +20 -15
- package/node_modules/pi-lens/dist/{chunk-3YY7IXIL.js → chunk-6YUNI7B5.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-PKES3ISE.js → chunk-7ANZ7XDD.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-FB5SCCPT.js → chunk-7CGIDRIK.js} +16 -15
- package/node_modules/pi-lens/dist/{chunk-L3CMBQMH.js → chunk-7MAD5ZAY.js} +16 -17
- package/node_modules/pi-lens/dist/{chunk-WDBICWH3.js → chunk-7TNILKGY.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-RORGS5II.js → chunk-A5GRLYPZ.js} +9 -9
- package/node_modules/pi-lens/dist/{chunk-MNJIXFX4.js → chunk-AGGUWKRK.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-ABPKUVA4.js → chunk-BBET6HD6.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-L5JYIU47.js → chunk-BHWW6FAX.js} +14 -13
- package/node_modules/pi-lens/dist/{chunk-URCQWAQ4.js → chunk-BOPDQ7AZ.js} +23 -21
- package/node_modules/pi-lens/dist/{chunk-KDX35VXP.js → chunk-BQG2QFVO.js} +158 -133
- package/node_modules/pi-lens/dist/{chunk-CB4WHS4H.js → chunk-BUZIQDFS.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-2PHMIAKO.js → chunk-CM73PPGD.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-DH5JPM3K.js → chunk-CUDD35TW.js} +10 -9
- package/node_modules/pi-lens/dist/{chunk-AWDSEDER.js → chunk-CZL44WFN.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-N5WSK2K7.js → chunk-DIWK3LBC.js} +12 -15
- package/node_modules/pi-lens/dist/{chunk-24BILSZW.js → chunk-DYRZGUMA.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-PR6PO3ES.js → chunk-FHEV6T4L.js} +22 -18
- package/node_modules/pi-lens/dist/{chunk-DQZFQSR5.js → chunk-FRLAUP2B.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-RZOXUSPC.js → chunk-G5GV2Q7K.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-EKWX4WD3.js → chunk-G6JKM4O7.js} +7 -7
- package/node_modules/pi-lens/dist/chunk-GGYOZWHW.js +27 -0
- package/node_modules/pi-lens/dist/{chunk-XT2HTCJ5.js → chunk-GIRBSBGL.js} +6 -5
- package/node_modules/pi-lens/dist/{chunk-PQJFG24Z.js → chunk-GMROJJRN.js} +1292 -946
- package/node_modules/pi-lens/dist/{chunk-U6VN4NVL.js → chunk-HHR7WGCI.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-TIQJPRDD.js → chunk-HKIL6DCL.js} +3 -2
- package/node_modules/pi-lens/dist/{chunk-SNDXCFRS.js → chunk-HUAM7QG3.js} +11 -11
- package/node_modules/pi-lens/dist/{chunk-QOE342SU.js → chunk-HXFUTMX2.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-U7BD2QL7.js → chunk-I22THIHI.js} +12 -12
- package/node_modules/pi-lens/dist/chunk-IE5D3RA5.js +58 -0
- package/node_modules/pi-lens/dist/{chunk-DPGEAHZT.js → chunk-IYVYZQRL.js} +10 -16
- package/node_modules/pi-lens/dist/{chunk-3F6BMY53.js → chunk-JBP7KESM.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-U5HPROLA.js → chunk-JE6HKLC7.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-ZE3KXHS7.js → chunk-JPRDTY5S.js} +85 -3
- package/node_modules/pi-lens/dist/{chunk-HO6LWE2E.js → chunk-JYLOYTZD.js} +17 -1
- package/node_modules/pi-lens/dist/{chunk-KW5JQPO5.js → chunk-JZRP4DGP.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-CPSR3AVL.js → chunk-KZ4ALBCH.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-6IR3ZYIB.js → chunk-L3CLUGDY.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-LV4UMYVH.js → chunk-L4NEVZ4T.js} +28 -27
- package/node_modules/pi-lens/dist/chunk-LPYTPNOJ.js +22 -0
- package/node_modules/pi-lens/dist/{chunk-WGRJOXED.js → chunk-LSFXZLPW.js} +1016 -636
- package/node_modules/pi-lens/dist/{chunk-LBLBAFG3.js → chunk-MC6VB2E5.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-U2SDMG7C.js → chunk-NM2NWH55.js} +5 -5
- package/node_modules/pi-lens/dist/{chunk-T7A2HK2B.js → chunk-NSPVR3FN.js} +19 -18
- package/node_modules/pi-lens/dist/{chunk-ZGSJDWQU.js → chunk-O2ARHQKF.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-OXOI55RU.js → chunk-O4N5BQ3T.js} +10 -10
- package/node_modules/pi-lens/dist/{chunk-3FRLWYBG.js → chunk-OC7VWJBZ.js} +39 -40
- package/node_modules/pi-lens/dist/chunk-OFNMHPBT.js +89 -0
- package/node_modules/pi-lens/dist/{chunk-HR3OJ3TH.js → chunk-OWTG6UMO.js} +21 -21
- package/node_modules/pi-lens/dist/{chunk-75GAYVNO.js → chunk-OY7WZI7Q.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-ZJTT47IG.js → chunk-OZWXLJMX.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-F6X3YJWD.js → chunk-PIQQM32Y.js} +2 -2
- package/node_modules/pi-lens/dist/chunk-PKLB2XJL.js +8 -0
- package/node_modules/pi-lens/dist/{chunk-EAOK7MIZ.js → chunk-PKSUMEPT.js} +17 -4
- package/node_modules/pi-lens/dist/{chunk-YISME6ON.js → chunk-PPKECBPP.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-4L36HG27.js → chunk-R2QQC33W.js} +14 -14
- package/node_modules/pi-lens/dist/{chunk-LUBPZN36.js → chunk-R4QWJQ2H.js} +11 -11
- package/node_modules/pi-lens/dist/{chunk-V63BC55Q.js → chunk-RGGH6M34.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-Y7F7IEE3.js → chunk-RZG472YW.js} +65 -7
- package/node_modules/pi-lens/dist/{chunk-PUZ3E2J4.js → chunk-SDFKOLSF.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-YHC2O2WO.js → chunk-SFLHSL5R.js} +9 -9
- package/node_modules/pi-lens/dist/{chunk-CCV2EU7T.js → chunk-SP4TFY5F.js} +14 -13
- package/node_modules/pi-lens/dist/{chunk-J6JP25XU.js → chunk-SQC7K3SP.js} +4 -3
- package/node_modules/pi-lens/dist/{chunk-3K2F6UDZ.js → chunk-T2S3FNNJ.js} +44 -42
- package/node_modules/pi-lens/dist/{chunk-2TF6RXWB.js → chunk-TV6RXRYH.js} +10 -10
- package/node_modules/pi-lens/dist/{chunk-GNSIWBAT.js → chunk-U3AS2FR6.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-F7K5IBZG.js → chunk-UHHLR2VY.js} +40 -40
- package/node_modules/pi-lens/dist/chunk-UYXV5NIS.js +20 -0
- package/node_modules/pi-lens/dist/{chunk-VSFLRN5Y.js → chunk-VLQ7UKZH.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-VUZWQ7UG.js → chunk-VN3L2JWZ.js} +46 -72
- package/node_modules/pi-lens/dist/{chunk-NA7SEXHE.js → chunk-VOP4PJKA.js} +7 -7
- package/node_modules/pi-lens/dist/{chunk-F5Z6URKM.js → chunk-VOXTCULR.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-LLS45EWB.js → chunk-VPLBLWFO.js} +6 -8
- package/node_modules/pi-lens/dist/chunk-W3BGKBBK.js +27 -0
- package/node_modules/pi-lens/dist/{chunk-ZKXQKGWZ.js → chunk-WC6WRNQT.js} +4 -3
- package/node_modules/pi-lens/dist/{chunk-YVHBNSME.js → chunk-WMDUT4KH.js} +1148 -1132
- package/node_modules/pi-lens/dist/{chunk-KXF5R4UN.js → chunk-WQV6BI4Q.js} +1 -1
- package/node_modules/pi-lens/dist/chunk-WXUDRAG6.js +24 -0
- package/node_modules/pi-lens/dist/{chunk-KPPJTH44.js → chunk-X35S7HSB.js} +28 -10
- package/node_modules/pi-lens/dist/{chunk-JMEKXFOL.js → chunk-X66YJ2SS.js} +40 -34
- package/node_modules/pi-lens/dist/{chunk-CE6VMBCB.js → chunk-XOMGO63G.js} +22 -21
- package/node_modules/pi-lens/dist/{chunk-LS3QJRUB.js → chunk-XWIME22V.js} +13 -13
- package/node_modules/pi-lens/dist/{chunk-R5MOQM2H.js → chunk-XYLC35E4.js} +119 -87
- package/node_modules/pi-lens/dist/{chunk-OE5ZBP7F.js → chunk-YHGYAEFH.js} +18 -18
- package/node_modules/pi-lens/dist/{chunk-7E2563GA.js → chunk-ZFORSIED.js} +13 -13
- package/node_modules/pi-lens/dist/{chunk-E7HJ56Y7.js → chunk-ZKLTNLAW.js} +64 -73
- package/node_modules/pi-lens/dist/chunk-ZONZ6YY3.js +74 -0
- package/node_modules/pi-lens/dist/chunk-ZSM35JF4.js +30 -0
- package/node_modules/pi-lens/dist/{chunk-RC2Z6K47.js → chunk-ZZDIOAAJ.js} +15 -6
- package/node_modules/pi-lens/dist/index.js +6993 -5396
- package/node_modules/pi-lens/dist/mcp/analyze-cli.js +10 -10
- package/node_modules/pi-lens/dist/mcp/cli.js +44 -42
- package/node_modules/pi-lens/dist/mcp/server.js +1627 -504
- package/node_modules/pi-lens/dist/mcp/worker.js +62 -61
- package/node_modules/pi-lens/dist/probes/installer.js +20 -19
- package/node_modules/pi-lens/docs/adr/0003-git-guard-latch-writer.md +11 -6
- package/node_modules/pi-lens/docs/agent-tools.md +18 -8
- package/node_modules/pi-lens/docs/alignment-families.md +29 -0
- package/node_modules/pi-lens/docs/ast-grep_rules_catalog.md +6 -4
- package/node_modules/pi-lens/docs/ci-bot-pr-checks.md +126 -0
- package/node_modules/pi-lens/docs/configuration.md +99 -3
- package/node_modules/pi-lens/docs/defect-shapes.md +55 -12
- package/node_modules/pi-lens/docs/engineering-principles.md +27 -2
- package/node_modules/pi-lens/docs/features.md +2 -2
- package/node_modules/pi-lens/docs/invariants/git-guard-host.md +7 -3
- package/node_modules/pi-lens/docs/invariants/language-config.md +15 -4
- package/node_modules/pi-lens/docs/invariants/lsp-trust-exec.md +16 -2
- package/node_modules/pi-lens/docs/invariants/paths-os.md +4 -2
- package/node_modules/pi-lens/docs/lsp-capability-matrix.md +119 -39
- package/node_modules/pi-lens/docs/merge-queue-rollout.md +1 -1
- package/node_modules/pi-lens/docs/pi-lens-fixer.md +24 -17
- package/node_modules/pi-lens/docs/pi-lens-merge-policy.md +20 -11
- package/node_modules/pi-lens/docs/pi-lens-monitor.md +9 -0
- package/node_modules/pi-lens/docs/pi-lens-orchestration.md +4 -1
- package/node_modules/pi-lens/docs/pi-lens-reviewer.md +5 -5
- package/node_modules/pi-lens/docs/pi-lens-subagent.md +6 -3
- package/node_modules/pi-lens/docs/public-api-stability.md +18 -2
- package/node_modules/pi-lens/docs/schema/pi-lens-config-v1.json +10 -0
- package/node_modules/pi-lens/docs/settings.md +10 -6
- package/node_modules/pi-lens/docs/word-index.md +17 -5
- package/node_modules/pi-lens/package.json +5 -3
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-accumulating-spread-js-test.yml +37 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/ts-redundant-filter-map-test.yml +12 -1
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests-disabled/filter-then-map-js-test.yml +12 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests-disabled/filter-then-map-test.yml +25 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-accumulating-spread-js.yml +49 -1
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/ts-redundant-filter-map.yml +9 -1
- package/node_modules/pi-lens/rules/ast-grep-rules/rules-disabled/filter-then-map-js.yml +17 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules-disabled/filter-then-map.yml +36 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/self-scan-baseline.json +1 -1
- package/node_modules/pi-provider-qoder/README.md +22 -0
- package/node_modules/pi-provider-qoder/dist/index.js +370 -11
- package/node_modules/pi-provider-qoder/package.json +5 -2
- package/package.json +11 -8
- package/node_modules/@tifan/pi-preferred-thinking/README.md +0 -54
- package/node_modules/@tifan/pi-preferred-thinking/package.json +0 -43
- package/node_modules/@tifan/pi-preferred-thinking/src/index.ts +0 -236
- package/node_modules/pi-lens/dist/chunk-46TNM7XZ.js +0 -88
- package/node_modules/pi-lens/dist/chunk-72OKUXSD.js +0 -31
- package/node_modules/pi-lens/dist/chunk-7GLOLOSH.js +0 -57
- package/node_modules/pi-lens/dist/chunk-AKUUMGD5.js +0 -26
- package/node_modules/pi-lens/dist/chunk-ASUXV767.js +0 -22
- package/node_modules/pi-lens/dist/chunk-CTADOKYM.js +0 -25
- package/node_modules/pi-lens/dist/chunk-JJ2RRESP.js +0 -58
- package/node_modules/pi-lens/dist/chunk-LSC3VADM.js +0 -23
- package/node_modules/pi-lens/dist/chunk-SHLDT3OI.js +0 -27
- package/node_modules/pi-lens/dist/chunk-UF7RTZSO.js +0 -27
- package/node_modules/pi-lens/dist/chunk-W4WP2ERB.js +0 -30
- package/node_modules/pi-lens/dist/chunk-YES5CACN.js +0 -73
|
@@ -0,0 +1,836 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Testable Command Code provider core.
|
|
3
|
+
*
|
|
4
|
+
* The runtime imports live in index.ts; this module takes injected stream/cost
|
|
5
|
+
* dependencies so tests can exercise the real serialization and stream parser.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { randomUUID } from "node:crypto"
|
|
9
|
+
|
|
10
|
+
import { COMMAND_CODE_CLI_VERSION } from "./commandcode-catalog.ts"
|
|
11
|
+
import { commandCodeErrorMessage, redactCommandCodeErrorText } from "./overflow.ts"
|
|
12
|
+
import { modelSupportsImageInput } from "./models.ts"
|
|
13
|
+
import {
|
|
14
|
+
getApiKey,
|
|
15
|
+
getEnvironmentInfo,
|
|
16
|
+
isRecord,
|
|
17
|
+
assertTextOnlyMessages,
|
|
18
|
+
mapFinishReason,
|
|
19
|
+
messagesToCC,
|
|
20
|
+
numberValue,
|
|
21
|
+
parseStreamEventLine,
|
|
22
|
+
pickCommandCodeApiKey,
|
|
23
|
+
recordOrEmpty,
|
|
24
|
+
stringValue,
|
|
25
|
+
toolsToJson,
|
|
26
|
+
systemPromptToText,
|
|
27
|
+
} from "./converters.ts"
|
|
28
|
+
import type {
|
|
29
|
+
AssistantMessageEventStreamLike,
|
|
30
|
+
AssistantMessageLike,
|
|
31
|
+
ContextLike,
|
|
32
|
+
CoreDependencies,
|
|
33
|
+
ErrorReason,
|
|
34
|
+
ModelLike,
|
|
35
|
+
StopReason,
|
|
36
|
+
StreamOptions,
|
|
37
|
+
TerminalReason,
|
|
38
|
+
TextContent,
|
|
39
|
+
ToolCallContent,
|
|
40
|
+
Usage,
|
|
41
|
+
} from "./types.ts"
|
|
42
|
+
|
|
43
|
+
export * from "./converters.ts"
|
|
44
|
+
export * from "./overflow.ts"
|
|
45
|
+
export * from "./types.ts"
|
|
46
|
+
|
|
47
|
+
export const DEFAULT_API_BASE = "https://api.commandcode.ai"
|
|
48
|
+
export { COMMAND_CODE_CLI_VERSION }
|
|
49
|
+
|
|
50
|
+
const DEFAULT_GENERATE_MAX_TOKENS = 64_000
|
|
51
|
+
const DEFAULT_MAX_RETRIES = 0
|
|
52
|
+
const DEFAULT_MAX_RETRY_DELAY_MS = 60_000
|
|
53
|
+
const BASE_RETRY_DELAY_MS = 500
|
|
54
|
+
|
|
55
|
+
function isRetryableStatus(status: number): boolean {
|
|
56
|
+
return status === 429 || (status >= 500 && status < 600)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function parseRetryAfterSeconds(value: string | null): number | undefined {
|
|
60
|
+
if (!value) return undefined
|
|
61
|
+
const seconds = Number(value)
|
|
62
|
+
if (Number.isFinite(seconds) && seconds >= 0) return seconds
|
|
63
|
+
const date = Date.parse(value)
|
|
64
|
+
if (!Number.isNaN(date)) return Math.max(0, (date - Date.now()) / 1000)
|
|
65
|
+
return undefined
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function effectiveMaxRetryDelayMs(value: number | undefined): number {
|
|
69
|
+
if (value === undefined) return DEFAULT_MAX_RETRY_DELAY_MS
|
|
70
|
+
if (value === 0) return Number.POSITIVE_INFINITY
|
|
71
|
+
return value
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function retryDelayMs(
|
|
75
|
+
attempt: number,
|
|
76
|
+
retryAfterHeader: string | null,
|
|
77
|
+
maxDelayMs: number,
|
|
78
|
+
): number {
|
|
79
|
+
const retryAfterMs = parseRetryAfterSeconds(retryAfterHeader)
|
|
80
|
+
if (retryAfterMs !== undefined) {
|
|
81
|
+
if (retryAfterMs * 1000 > maxDelayMs) return -1
|
|
82
|
+
return retryAfterMs * 1000
|
|
83
|
+
}
|
|
84
|
+
const exponential = BASE_RETRY_DELAY_MS * 2 ** attempt
|
|
85
|
+
const jitter = exponential * 0.2 * Math.random()
|
|
86
|
+
return Math.min(exponential + jitter, maxDelayMs)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function defaultUsage(): Usage {
|
|
90
|
+
return {
|
|
91
|
+
input: 0,
|
|
92
|
+
output: 0,
|
|
93
|
+
cacheRead: 0,
|
|
94
|
+
cacheWrite: 0,
|
|
95
|
+
totalTokens: 0,
|
|
96
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function commandCodeUsage(event: Record<string, unknown>): Record<string, unknown> | undefined {
|
|
101
|
+
return isRecord(event.totalUsage) ? event.totalUsage : undefined
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function commandCodeInputTokenDetails(
|
|
105
|
+
usage: Record<string, unknown>,
|
|
106
|
+
): Record<string, unknown> | undefined {
|
|
107
|
+
return isRecord(usage.inputTokenDetails) ? usage.inputTokenDetails : undefined
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function headersToRecord(headers: Headers): Record<string, string> {
|
|
111
|
+
const out: Record<string, string> = {}
|
|
112
|
+
headers.forEach((value, key) => {
|
|
113
|
+
out[key] = value
|
|
114
|
+
})
|
|
115
|
+
return out
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function abortError(message = "The operation was aborted"): DOMException {
|
|
119
|
+
return new DOMException(message, "AbortError")
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function timeoutError(timeoutMs: number | undefined): Error {
|
|
123
|
+
return new Error(
|
|
124
|
+
timeoutMs === undefined
|
|
125
|
+
? "Command Code API request timed out"
|
|
126
|
+
: `Command Code API request timed out after ${timeoutMs}ms`,
|
|
127
|
+
)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function successStopReason(reason: TerminalReason): StopReason {
|
|
131
|
+
if (reason === "length" || reason === "toolUse") return reason
|
|
132
|
+
return "stop"
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function generateMaxTokens(model: ModelLike, options?: StreamOptions): number {
|
|
136
|
+
return Math.min(
|
|
137
|
+
options?.maxTokens ?? model.maxTokens,
|
|
138
|
+
model.maxTokens,
|
|
139
|
+
DEFAULT_GENERATE_MAX_TOKENS,
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function mappedReasoningEffort(model: ModelLike, options?: StreamOptions): string | undefined {
|
|
144
|
+
const level = options?.reasoning
|
|
145
|
+
if (!level || level === "off" || !model.reasoning) return undefined
|
|
146
|
+
|
|
147
|
+
const effortMap = model.thinking?.effortMap ?? model.thinkingLevelMap
|
|
148
|
+
const mapped = effortMap?.[level]
|
|
149
|
+
return typeof mapped === "string" && mapped !== "off" ? mapped : undefined
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function isUuid(value: string): boolean {
|
|
153
|
+
return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function projectSlugFromPath(pathName: string): string {
|
|
157
|
+
const slug = pathName
|
|
158
|
+
.toLowerCase()
|
|
159
|
+
.replace(/^[a-z]:/i, "")
|
|
160
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
161
|
+
.replace(/^-+|-+$/g, "")
|
|
162
|
+
return slug || "project"
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function createStreamCommandCode(deps: CoreDependencies) {
|
|
166
|
+
const apiBase = deps.apiBase ?? DEFAULT_API_BASE
|
|
167
|
+
const fetchImpl = deps.fetchImpl ?? fetch
|
|
168
|
+
const cwd = deps.cwd ?? (() => process.cwd())
|
|
169
|
+
const now = deps.now ?? (() => Date.now())
|
|
170
|
+
const uuid = deps.uuid ?? (() => randomUUID())
|
|
171
|
+
const delay =
|
|
172
|
+
deps.delay ??
|
|
173
|
+
((ms: number, signal: AbortSignal) => {
|
|
174
|
+
if (signal.aborted) return Promise.reject(abortError())
|
|
175
|
+
return new Promise<void>((resolve, reject) => {
|
|
176
|
+
const id = setTimeout(() => {
|
|
177
|
+
signal.removeEventListener("abort", onAbort)
|
|
178
|
+
resolve()
|
|
179
|
+
}, ms)
|
|
180
|
+
const onAbort = () => {
|
|
181
|
+
clearTimeout(id)
|
|
182
|
+
reject(abortError())
|
|
183
|
+
}
|
|
184
|
+
signal.addEventListener("abort", onAbort, { once: true })
|
|
185
|
+
})
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
function raceAbort<T>(promise: Promise<T>, signal: AbortSignal): Promise<T> {
|
|
189
|
+
if (signal.aborted) return Promise.reject(abortError())
|
|
190
|
+
|
|
191
|
+
return new Promise<T>((resolve, reject) => {
|
|
192
|
+
const onAbort = () => reject(abortError())
|
|
193
|
+
signal.addEventListener("abort", onAbort, { once: true })
|
|
194
|
+
promise.then(
|
|
195
|
+
(value) => {
|
|
196
|
+
signal.removeEventListener("abort", onAbort)
|
|
197
|
+
resolve(value)
|
|
198
|
+
},
|
|
199
|
+
(error: unknown) => {
|
|
200
|
+
signal.removeEventListener("abort", onAbort)
|
|
201
|
+
reject(error)
|
|
202
|
+
},
|
|
203
|
+
)
|
|
204
|
+
})
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function raceAbortWithTimeout<T>(
|
|
208
|
+
promise: Promise<T>,
|
|
209
|
+
controller: AbortController,
|
|
210
|
+
timeoutMs: number | undefined,
|
|
211
|
+
): Promise<T> {
|
|
212
|
+
if (timeoutMs === undefined) return raceAbort(promise, controller.signal)
|
|
213
|
+
|
|
214
|
+
return new Promise<T>((resolve, reject) => {
|
|
215
|
+
const timer = setTimeout(() => {
|
|
216
|
+
controller.abort()
|
|
217
|
+
reject(timeoutError(timeoutMs))
|
|
218
|
+
}, timeoutMs)
|
|
219
|
+
raceAbort(promise, controller.signal).then(
|
|
220
|
+
(value) => {
|
|
221
|
+
clearTimeout(timer)
|
|
222
|
+
resolve(value)
|
|
223
|
+
},
|
|
224
|
+
(error: unknown) => {
|
|
225
|
+
clearTimeout(timer)
|
|
226
|
+
reject(error)
|
|
227
|
+
},
|
|
228
|
+
)
|
|
229
|
+
})
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return function streamCommandCode(
|
|
233
|
+
model: ModelLike,
|
|
234
|
+
context: ContextLike,
|
|
235
|
+
options?: StreamOptions,
|
|
236
|
+
): AssistantMessageEventStreamLike {
|
|
237
|
+
const stream = deps.createStream()
|
|
238
|
+
|
|
239
|
+
async function run() {
|
|
240
|
+
// Some hosts pass a literal env-var reference instead of resolving it.
|
|
241
|
+
const apiKey = pickCommandCodeApiKey(
|
|
242
|
+
options?.apiKey,
|
|
243
|
+
getApiKey({
|
|
244
|
+
env: deps.env,
|
|
245
|
+
authPaths: deps.authPaths,
|
|
246
|
+
homeDir: deps.homeDir,
|
|
247
|
+
}),
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
if (!apiKey) {
|
|
251
|
+
const msg: AssistantMessageLike = {
|
|
252
|
+
role: "assistant",
|
|
253
|
+
content: [],
|
|
254
|
+
api: model.api,
|
|
255
|
+
provider: model.provider,
|
|
256
|
+
model: model.id,
|
|
257
|
+
usage: defaultUsage(),
|
|
258
|
+
stopReason: "error",
|
|
259
|
+
errorMessage:
|
|
260
|
+
"No Command Code API key. Run /login and select Command Code, set COMMAND_CODE_API_KEY (or legacy COMMANDCODE_API_KEY), or configure ~/.commandcode/auth.json, ~/.pi/agent/auth.json or ~/.omp/agent/auth.json",
|
|
261
|
+
timestamp: now(),
|
|
262
|
+
}
|
|
263
|
+
stream.push({ type: "error", reason: "error", error: msg })
|
|
264
|
+
stream.end()
|
|
265
|
+
return
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const output: AssistantMessageLike = {
|
|
269
|
+
role: "assistant",
|
|
270
|
+
content: [],
|
|
271
|
+
api: model.api,
|
|
272
|
+
provider: model.provider,
|
|
273
|
+
model: model.id,
|
|
274
|
+
usage: defaultUsage(),
|
|
275
|
+
stopReason: "stop",
|
|
276
|
+
timestamp: now(),
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const controller = new AbortController()
|
|
280
|
+
let reader: ReadableStreamDefaultReader<Uint8Array> | undefined
|
|
281
|
+
let textBlock: TextContent | undefined
|
|
282
|
+
let currentTextIdx = -1
|
|
283
|
+
let thinkingIdx = -1
|
|
284
|
+
const streamingToolCalls = new Map<
|
|
285
|
+
string,
|
|
286
|
+
{ contentIndex: number; toolCall: ToolCallContent; partialArgs: string }
|
|
287
|
+
>()
|
|
288
|
+
let finished = false
|
|
289
|
+
|
|
290
|
+
const abortUpstream = () => {
|
|
291
|
+
if (!controller.signal.aborted) controller.abort()
|
|
292
|
+
try {
|
|
293
|
+
reader?.cancel().catch(() => undefined)
|
|
294
|
+
} catch {
|
|
295
|
+
// Reader cancellation is best-effort.
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (options?.signal?.aborted) {
|
|
300
|
+
abortUpstream()
|
|
301
|
+
} else {
|
|
302
|
+
options?.signal?.addEventListener("abort", abortUpstream, {
|
|
303
|
+
once: true,
|
|
304
|
+
})
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const endTextBlock = () => {
|
|
308
|
+
if (!textBlock) return
|
|
309
|
+
stream.push({
|
|
310
|
+
type: "text_end",
|
|
311
|
+
contentIndex: currentTextIdx,
|
|
312
|
+
content: textBlock.text,
|
|
313
|
+
partial: output,
|
|
314
|
+
})
|
|
315
|
+
textBlock = undefined
|
|
316
|
+
currentTextIdx = -1
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const endThinking = () => {
|
|
320
|
+
if (thinkingIdx < 0) return
|
|
321
|
+
const tc = output.content[thinkingIdx]
|
|
322
|
+
if (tc && tc.type === "thinking") {
|
|
323
|
+
stream.push({
|
|
324
|
+
type: "thinking_end",
|
|
325
|
+
contentIndex: thinkingIdx,
|
|
326
|
+
content: (tc as { thinking: string }).thinking,
|
|
327
|
+
partial: output,
|
|
328
|
+
})
|
|
329
|
+
}
|
|
330
|
+
thinkingIdx = -1
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const handleEvent = (event: unknown) => {
|
|
334
|
+
if (!isRecord(event)) return
|
|
335
|
+
|
|
336
|
+
switch (event.type) {
|
|
337
|
+
case "text-delta": {
|
|
338
|
+
endThinking()
|
|
339
|
+
if (!textBlock) {
|
|
340
|
+
textBlock = { type: "text", text: "" }
|
|
341
|
+
output.content.push(textBlock)
|
|
342
|
+
currentTextIdx = output.content.length - 1
|
|
343
|
+
stream.push({
|
|
344
|
+
type: "text_start",
|
|
345
|
+
contentIndex: currentTextIdx,
|
|
346
|
+
partial: output,
|
|
347
|
+
})
|
|
348
|
+
}
|
|
349
|
+
const delta = stringValue(event.text) ?? ""
|
|
350
|
+
textBlock.text += delta
|
|
351
|
+
stream.push({
|
|
352
|
+
type: "text_delta",
|
|
353
|
+
contentIndex: currentTextIdx,
|
|
354
|
+
delta,
|
|
355
|
+
partial: output,
|
|
356
|
+
})
|
|
357
|
+
break
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
case "reasoning-start": {
|
|
361
|
+
endTextBlock()
|
|
362
|
+
break
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
case "reasoning-delta": {
|
|
366
|
+
endTextBlock()
|
|
367
|
+
const delta = stringValue(event.text) ?? ""
|
|
368
|
+
if (thinkingIdx < 0) {
|
|
369
|
+
output.content.push({ type: "thinking", thinking: delta })
|
|
370
|
+
thinkingIdx = output.content.length - 1
|
|
371
|
+
stream.push({
|
|
372
|
+
type: "thinking_start",
|
|
373
|
+
contentIndex: thinkingIdx,
|
|
374
|
+
partial: output,
|
|
375
|
+
})
|
|
376
|
+
} else {
|
|
377
|
+
const tc = output.content[thinkingIdx]
|
|
378
|
+
if (tc && tc.type === "thinking") {
|
|
379
|
+
;(tc as { thinking: string }).thinking += delta
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
stream.push({
|
|
383
|
+
type: "thinking_delta",
|
|
384
|
+
contentIndex: thinkingIdx,
|
|
385
|
+
delta,
|
|
386
|
+
partial: output,
|
|
387
|
+
})
|
|
388
|
+
break
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
case "reasoning-end": {
|
|
392
|
+
endThinking()
|
|
393
|
+
break
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
case "tool-result": {
|
|
397
|
+
break
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
case "tool-input-start": {
|
|
401
|
+
endTextBlock()
|
|
402
|
+
endThinking()
|
|
403
|
+
const id = stringValue(event.id)
|
|
404
|
+
if (!id || streamingToolCalls.has(id)) break
|
|
405
|
+
|
|
406
|
+
const toolCall: ToolCallContent = {
|
|
407
|
+
type: "toolCall",
|
|
408
|
+
id,
|
|
409
|
+
name: stringValue(event.toolName) ?? "",
|
|
410
|
+
arguments: {},
|
|
411
|
+
}
|
|
412
|
+
output.content.push(toolCall)
|
|
413
|
+
const contentIndex = output.content.length - 1
|
|
414
|
+
streamingToolCalls.set(id, { contentIndex, toolCall, partialArgs: "" })
|
|
415
|
+
stream.push({
|
|
416
|
+
type: "toolcall_start",
|
|
417
|
+
contentIndex,
|
|
418
|
+
partial: output,
|
|
419
|
+
})
|
|
420
|
+
break
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
case "tool-input-delta": {
|
|
424
|
+
const id = stringValue(event.id)
|
|
425
|
+
const delta = stringValue(event.delta)
|
|
426
|
+
if (!id || delta === undefined) break
|
|
427
|
+
const active = streamingToolCalls.get(id)
|
|
428
|
+
if (!active) break
|
|
429
|
+
|
|
430
|
+
active.partialArgs += delta
|
|
431
|
+
active.toolCall.arguments = recordOrEmpty(active.partialArgs)
|
|
432
|
+
stream.push({
|
|
433
|
+
type: "toolcall_delta",
|
|
434
|
+
contentIndex: active.contentIndex,
|
|
435
|
+
delta,
|
|
436
|
+
partial: output,
|
|
437
|
+
})
|
|
438
|
+
break
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
case "tool-input-end": {
|
|
442
|
+
break
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
case "tool-call": {
|
|
446
|
+
endTextBlock()
|
|
447
|
+
endThinking()
|
|
448
|
+
const id = stringValue(event.toolCallId) ?? ""
|
|
449
|
+
const active = streamingToolCalls.get(id)
|
|
450
|
+
const toolCall: ToolCallContent = active?.toolCall ?? {
|
|
451
|
+
type: "toolCall",
|
|
452
|
+
id,
|
|
453
|
+
name: stringValue(event.toolName) ?? "",
|
|
454
|
+
arguments: {},
|
|
455
|
+
}
|
|
456
|
+
toolCall.name = stringValue(event.toolName) ?? toolCall.name
|
|
457
|
+
toolCall.arguments = recordOrEmpty(event.input ?? event.args ?? event.arguments)
|
|
458
|
+
|
|
459
|
+
let contentIndex: number
|
|
460
|
+
if (active) {
|
|
461
|
+
contentIndex = active.contentIndex
|
|
462
|
+
streamingToolCalls.delete(id)
|
|
463
|
+
} else {
|
|
464
|
+
output.content.push(toolCall)
|
|
465
|
+
contentIndex = output.content.length - 1
|
|
466
|
+
stream.push({
|
|
467
|
+
type: "toolcall_start",
|
|
468
|
+
contentIndex,
|
|
469
|
+
partial: output,
|
|
470
|
+
})
|
|
471
|
+
}
|
|
472
|
+
stream.push({
|
|
473
|
+
type: "toolcall_end",
|
|
474
|
+
contentIndex,
|
|
475
|
+
toolCall,
|
|
476
|
+
partial: output,
|
|
477
|
+
})
|
|
478
|
+
break
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
case "finish": {
|
|
482
|
+
const rawFinishReason = stringValue(event.rawFinishReason)
|
|
483
|
+
if (
|
|
484
|
+
rawFinishReason &&
|
|
485
|
+
/^(?:network|connection|upstream)[-_\s]?error$/i.test(rawFinishReason)
|
|
486
|
+
) {
|
|
487
|
+
throw new Error(
|
|
488
|
+
`Provider finished with reason "${rawFinishReason}" — upstream connection failed mid-stream`,
|
|
489
|
+
)
|
|
490
|
+
}
|
|
491
|
+
const usage = commandCodeUsage(event)
|
|
492
|
+
if (usage) {
|
|
493
|
+
const details = commandCodeInputTokenDetails(usage)
|
|
494
|
+
const totalInput = numberValue(usage.inputTokens) ?? 0
|
|
495
|
+
const input = numberValue(details?.noCacheTokens)
|
|
496
|
+
const cacheRead = numberValue(details?.cacheReadTokens) ?? 0
|
|
497
|
+
const cacheWrite = numberValue(details?.cacheWriteTokens) ?? 0
|
|
498
|
+
output.usage.input = input ?? Math.max(0, totalInput - cacheRead - cacheWrite)
|
|
499
|
+
output.usage.output = numberValue(usage.outputTokens) ?? 0
|
|
500
|
+
output.usage.cacheRead = cacheRead
|
|
501
|
+
output.usage.cacheWrite = cacheWrite
|
|
502
|
+
output.usage.totalTokens =
|
|
503
|
+
output.usage.input +
|
|
504
|
+
output.usage.output +
|
|
505
|
+
output.usage.cacheRead +
|
|
506
|
+
output.usage.cacheWrite
|
|
507
|
+
deps.calculateCost(model, output.usage, output.timestamp)
|
|
508
|
+
}
|
|
509
|
+
output.stopReason = mapFinishReason(event.finishReason)
|
|
510
|
+
finished = true
|
|
511
|
+
break
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
case "abort": {
|
|
515
|
+
throw abortError("Request aborted")
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
case "error": {
|
|
519
|
+
const message =
|
|
520
|
+
commandCodeErrorMessage(event.error) ??
|
|
521
|
+
commandCodeErrorMessage(event.message) ??
|
|
522
|
+
"Stream error"
|
|
523
|
+
output.stopReason = "error"
|
|
524
|
+
output.errorMessage = message
|
|
525
|
+
throw new Error(message)
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
try {
|
|
531
|
+
stream.push({ type: "start", partial: output })
|
|
532
|
+
if (controller.signal.aborted) throw abortError("Aborted")
|
|
533
|
+
|
|
534
|
+
const workingDir = cwd()
|
|
535
|
+
const threadId = options?.sessionId
|
|
536
|
+
? isUuid(options.sessionId)
|
|
537
|
+
? options.sessionId
|
|
538
|
+
: undefined
|
|
539
|
+
: uuid()
|
|
540
|
+
const reasoningEffort = mappedReasoningEffort(model, options)
|
|
541
|
+
const timeoutMs = options?.timeoutMs
|
|
542
|
+
|
|
543
|
+
const allowImages = modelSupportsImageInput(model.id, model.input)
|
|
544
|
+
if (!allowImages) assertTextOnlyMessages(context.messages)
|
|
545
|
+
|
|
546
|
+
let body: unknown = {
|
|
547
|
+
config: {
|
|
548
|
+
workingDir,
|
|
549
|
+
date: new Date(now()).toISOString().split("T")[0],
|
|
550
|
+
environment: getEnvironmentInfo(),
|
|
551
|
+
structure: [],
|
|
552
|
+
isGitRepo: false,
|
|
553
|
+
currentBranch: "",
|
|
554
|
+
mainBranch: "",
|
|
555
|
+
gitStatus: "",
|
|
556
|
+
recentCommits: [],
|
|
557
|
+
},
|
|
558
|
+
memory: null,
|
|
559
|
+
taste: null,
|
|
560
|
+
skills: null,
|
|
561
|
+
params: {
|
|
562
|
+
model: model.id,
|
|
563
|
+
messages: messagesToCC(context.messages, { allowImages }),
|
|
564
|
+
tools: toolsToJson(context.tools, model.id),
|
|
565
|
+
system: systemPromptToText(context.systemPrompt),
|
|
566
|
+
max_tokens: generateMaxTokens(model, options),
|
|
567
|
+
stream: true,
|
|
568
|
+
...(options?.temperature !== undefined ? { temperature: options.temperature } : {}),
|
|
569
|
+
...(reasoningEffort ? { reasoning_effort: reasoningEffort } : {}),
|
|
570
|
+
},
|
|
571
|
+
threadId,
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
const payloadController = new AbortController()
|
|
575
|
+
const onPayloadAbort = () => payloadController.abort()
|
|
576
|
+
controller.signal.addEventListener("abort", onPayloadAbort, { once: true })
|
|
577
|
+
let nextBody: unknown
|
|
578
|
+
try {
|
|
579
|
+
nextBody = await raceAbortWithTimeout(
|
|
580
|
+
Promise.resolve(options?.onPayload?.(body, model)),
|
|
581
|
+
payloadController,
|
|
582
|
+
timeoutMs,
|
|
583
|
+
)
|
|
584
|
+
} finally {
|
|
585
|
+
controller.signal.removeEventListener("abort", onPayloadAbort)
|
|
586
|
+
}
|
|
587
|
+
if (nextBody !== undefined) body = nextBody
|
|
588
|
+
|
|
589
|
+
const maxRetries = options?.maxRetries ?? DEFAULT_MAX_RETRIES
|
|
590
|
+
const maxRetryDelayMs = effectiveMaxRetryDelayMs(options?.maxRetryDelayMs)
|
|
591
|
+
const requestHeaders = {
|
|
592
|
+
"Content-Type": "application/json",
|
|
593
|
+
Authorization: `Bearer ${apiKey}`,
|
|
594
|
+
"x-command-code-version": COMMAND_CODE_CLI_VERSION,
|
|
595
|
+
"x-cli-environment": "production",
|
|
596
|
+
"x-project-slug": projectSlugFromPath(workingDir),
|
|
597
|
+
"x-taste-learning": "true",
|
|
598
|
+
...(options?.sessionId ? { "x-session-id": options.sessionId } : {}),
|
|
599
|
+
"User-Agent": "cli",
|
|
600
|
+
...options?.headers,
|
|
601
|
+
}
|
|
602
|
+
const bodyStr = JSON.stringify(body)
|
|
603
|
+
|
|
604
|
+
let response!: Response
|
|
605
|
+
retryLoop: for (let attempt = 0; ; attempt++) {
|
|
606
|
+
const attemptController = new AbortController()
|
|
607
|
+
let attemptTimedOut = false
|
|
608
|
+
let attemptTimeoutId: ReturnType<typeof setTimeout> | undefined
|
|
609
|
+
|
|
610
|
+
const clearAttemptTimeout = () => {
|
|
611
|
+
if (attemptTimeoutId !== undefined) {
|
|
612
|
+
clearTimeout(attemptTimeoutId)
|
|
613
|
+
attemptTimeoutId = undefined
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
if (timeoutMs !== undefined) {
|
|
618
|
+
attemptTimeoutId = setTimeout(() => {
|
|
619
|
+
attemptTimedOut = true
|
|
620
|
+
attemptController.abort()
|
|
621
|
+
}, timeoutMs)
|
|
622
|
+
}
|
|
623
|
+
const onOuterAbort = () => attemptController.abort()
|
|
624
|
+
controller.signal.addEventListener("abort", onOuterAbort, { once: true })
|
|
625
|
+
const raceAttempt = <T>(promise: Promise<T>): Promise<T> =>
|
|
626
|
+
raceAbort(promise, attemptController.signal).catch((error: unknown) => {
|
|
627
|
+
if (attemptTimedOut) throw timeoutError(timeoutMs)
|
|
628
|
+
throw error
|
|
629
|
+
})
|
|
630
|
+
|
|
631
|
+
try {
|
|
632
|
+
try {
|
|
633
|
+
response = await fetchImpl(`${apiBase}/alpha/generate`, {
|
|
634
|
+
method: "POST",
|
|
635
|
+
headers: requestHeaders,
|
|
636
|
+
body: bodyStr,
|
|
637
|
+
signal: attemptController.signal,
|
|
638
|
+
})
|
|
639
|
+
} catch (fetchError: unknown) {
|
|
640
|
+
if (controller.signal.aborted) throw abortError("Aborted")
|
|
641
|
+
if (attemptTimedOut) {
|
|
642
|
+
if (attempt < maxRetries) continue retryLoop
|
|
643
|
+
throw timeoutError(timeoutMs)
|
|
644
|
+
}
|
|
645
|
+
throw fetchError
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
// --- HTTP-level retry ---
|
|
649
|
+
if (!response.ok && isRetryableStatus(response.status)) {
|
|
650
|
+
const retryAfter = response.headers.get("retry-after")
|
|
651
|
+
const waitMs = retryDelayMs(attempt, retryAfter, maxRetryDelayMs)
|
|
652
|
+
if (waitMs < 0) {
|
|
653
|
+
const requestedSeconds = parseRetryAfterSeconds(retryAfter) ?? 0
|
|
654
|
+
const capLabel =
|
|
655
|
+
maxRetryDelayMs === Number.POSITIVE_INFINITY ? "disabled" : `${maxRetryDelayMs}ms`
|
|
656
|
+
throw new Error(`Retry-After delay ${requestedSeconds}s exceeds max ${capLabel}`)
|
|
657
|
+
}
|
|
658
|
+
if (attempt < maxRetries) {
|
|
659
|
+
await response.text().catch(() => "")
|
|
660
|
+
if (waitMs > 0) await delay(waitMs, controller.signal)
|
|
661
|
+
continue retryLoop
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
try {
|
|
666
|
+
await raceAttempt(
|
|
667
|
+
Promise.resolve(
|
|
668
|
+
options?.onResponse?.(
|
|
669
|
+
{
|
|
670
|
+
status: response.status,
|
|
671
|
+
headers: headersToRecord(response.headers),
|
|
672
|
+
},
|
|
673
|
+
model,
|
|
674
|
+
),
|
|
675
|
+
),
|
|
676
|
+
)
|
|
677
|
+
} catch (error: unknown) {
|
|
678
|
+
if (attemptTimedOut && attempt < maxRetries) continue retryLoop
|
|
679
|
+
throw error
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
if (!response.ok) {
|
|
683
|
+
const errBody = await raceAttempt(response.text().catch(() => ""))
|
|
684
|
+
let errorDetail: string | undefined
|
|
685
|
+
try {
|
|
686
|
+
const parsedBody: unknown = JSON.parse(errBody)
|
|
687
|
+
errorDetail = commandCodeErrorMessage(parsedBody)
|
|
688
|
+
} catch {
|
|
689
|
+
// Preserve useful plain-text provider errors only after secret
|
|
690
|
+
// redaction; upstream/proxy bodies may echo credentials.
|
|
691
|
+
}
|
|
692
|
+
const safeBody = redactCommandCodeErrorText(errBody).slice(0, 500)
|
|
693
|
+
const detail = redactCommandCodeErrorText(
|
|
694
|
+
errorDetail ?? (safeBody || "Provider returned an error"),
|
|
695
|
+
)
|
|
696
|
+
throw new Error(`Command Code API error ${response.status}: ${detail}`)
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
// --- Read response stream ---
|
|
700
|
+
reader = response.body?.getReader()
|
|
701
|
+
if (!reader) throw new Error("No response body")
|
|
702
|
+
|
|
703
|
+
const decoder = new TextDecoder()
|
|
704
|
+
let buffer = ""
|
|
705
|
+
|
|
706
|
+
try {
|
|
707
|
+
readLoop: for (;;) {
|
|
708
|
+
if (controller.signal.aborted) throw abortError("Aborted")
|
|
709
|
+
const { done, value } = await raceAbort(reader.read(), attemptController.signal)
|
|
710
|
+
if (done) {
|
|
711
|
+
clearAttemptTimeout()
|
|
712
|
+
if (buffer.trim()) handleEvent(parseStreamEventLine(buffer))
|
|
713
|
+
if (!finished) {
|
|
714
|
+
throw new Error(
|
|
715
|
+
"Stream ended unexpectedly before completion (no finish event) — response was truncated",
|
|
716
|
+
)
|
|
717
|
+
}
|
|
718
|
+
break
|
|
719
|
+
}
|
|
720
|
+
if (timeoutMs !== undefined) {
|
|
721
|
+
clearAttemptTimeout()
|
|
722
|
+
attemptTimeoutId = setTimeout(() => {
|
|
723
|
+
attemptTimedOut = true
|
|
724
|
+
attemptController.abort()
|
|
725
|
+
}, timeoutMs)
|
|
726
|
+
}
|
|
727
|
+
if (controller.signal.aborted) throw abortError("Aborted")
|
|
728
|
+
|
|
729
|
+
buffer += decoder.decode(value, { stream: true })
|
|
730
|
+
const lines = buffer.split("\n")
|
|
731
|
+
buffer = lines.pop() ?? ""
|
|
732
|
+
|
|
733
|
+
for (const line of lines) {
|
|
734
|
+
if (controller.signal.aborted) throw abortError("Aborted")
|
|
735
|
+
handleEvent(parseStreamEventLine(line))
|
|
736
|
+
if (finished) break readLoop
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
} catch (streamError: unknown) {
|
|
740
|
+
// Stream-level error (e.g. API returned 200 OK but sent an error event)
|
|
741
|
+
// or per-attempt timeout during stream reading.
|
|
742
|
+
await reader.cancel().catch(() => {})
|
|
743
|
+
try {
|
|
744
|
+
reader.releaseLock()
|
|
745
|
+
} catch {}
|
|
746
|
+
reader = undefined
|
|
747
|
+
|
|
748
|
+
if (
|
|
749
|
+
controller.signal.aborted ||
|
|
750
|
+
(streamError instanceof Error && streamError.name === "AbortError")
|
|
751
|
+
) {
|
|
752
|
+
throw streamError
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
// Never retry after visible content was emitted (including timeout mid-stream).
|
|
756
|
+
const canRetry = output.content.length === 0 && attempt < maxRetries
|
|
757
|
+
if (canRetry) {
|
|
758
|
+
output.content.length = 0
|
|
759
|
+
textBlock = undefined
|
|
760
|
+
currentTextIdx = -1
|
|
761
|
+
thinkingIdx = -1
|
|
762
|
+
output.stopReason = "stop"
|
|
763
|
+
output.errorMessage = undefined
|
|
764
|
+
finished = false
|
|
765
|
+
const waitMs = attemptTimedOut ? 0 : retryDelayMs(attempt, null, maxRetryDelayMs)
|
|
766
|
+
if (waitMs > 0) await delay(waitMs, controller.signal)
|
|
767
|
+
continue retryLoop
|
|
768
|
+
}
|
|
769
|
+
if (attemptTimedOut) throw timeoutError(timeoutMs)
|
|
770
|
+
throw streamError
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
// Stream completed successfully.
|
|
774
|
+
endTextBlock()
|
|
775
|
+
endThinking()
|
|
776
|
+
|
|
777
|
+
stream.push({
|
|
778
|
+
type: "done",
|
|
779
|
+
reason: successStopReason(output.stopReason),
|
|
780
|
+
message: output,
|
|
781
|
+
})
|
|
782
|
+
stream.end()
|
|
783
|
+
break retryLoop
|
|
784
|
+
} finally {
|
|
785
|
+
controller.signal.removeEventListener("abort", onOuterAbort)
|
|
786
|
+
clearAttemptTimeout()
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
} catch (error: unknown) {
|
|
790
|
+
const reason: ErrorReason =
|
|
791
|
+
controller.signal.aborted || (error instanceof Error && error.name === "AbortError")
|
|
792
|
+
? "aborted"
|
|
793
|
+
: "error"
|
|
794
|
+
output.stopReason = reason
|
|
795
|
+
output.errorMessage =
|
|
796
|
+
reason === "aborted"
|
|
797
|
+
? "Request aborted"
|
|
798
|
+
: redactCommandCodeErrorText(error instanceof Error ? error.message : String(error))
|
|
799
|
+
stream.push({ type: "error", reason, error: output })
|
|
800
|
+
stream.end()
|
|
801
|
+
} finally {
|
|
802
|
+
options?.signal?.removeEventListener("abort", abortUpstream)
|
|
803
|
+
try {
|
|
804
|
+
await reader?.cancel()
|
|
805
|
+
} catch {
|
|
806
|
+
// Reader may already be closed/cancelled.
|
|
807
|
+
}
|
|
808
|
+
try {
|
|
809
|
+
reader?.releaseLock()
|
|
810
|
+
} catch {
|
|
811
|
+
// Reader may already be released/cancelled by the abort path.
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
run().catch((error: unknown) => {
|
|
817
|
+
const msg: AssistantMessageLike = {
|
|
818
|
+
role: "assistant",
|
|
819
|
+
content: [],
|
|
820
|
+
api: model.api,
|
|
821
|
+
provider: model.provider,
|
|
822
|
+
model: model.id,
|
|
823
|
+
usage: defaultUsage(),
|
|
824
|
+
stopReason: "error",
|
|
825
|
+
errorMessage: redactCommandCodeErrorText(
|
|
826
|
+
error instanceof Error ? error.message : String(error),
|
|
827
|
+
),
|
|
828
|
+
timestamp: now(),
|
|
829
|
+
}
|
|
830
|
+
stream.push({ type: "error", reason: "error", error: msg })
|
|
831
|
+
stream.end()
|
|
832
|
+
})
|
|
833
|
+
|
|
834
|
+
return stream
|
|
835
|
+
}
|
|
836
|
+
}
|