@herbertgao/pi-extensions 2026.11.3 → 2026.11.4
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 +9 -0
- package/README.md +7 -7
- package/THIRD_PARTY_NOTICES.md +2 -2
- package/node_modules/@herbertgao/pi-cc-extensions/CHANGELOG.md +6 -0
- package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +2 -2
- package/node_modules/@herbertgao/pi-cc-extensions/README.md +2 -2
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/interaction.ts +33 -5
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/ccstyle-tool.ts +72 -17
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/grouping.ts +10 -2
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/tool-io.ts +16 -7
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +7 -5
- package/node_modules/@herbertgao/pi-cc-extensions/themes/cc-dark-hc.json +92 -0
- package/node_modules/@herbertgao/pi-cc-extensions/themes/cc-light-hc.json +92 -0
- package/node_modules/pi-commandcode-provider/CHANGELOG.md +27 -0
- package/node_modules/pi-commandcode-provider/CONTRIBUTING.md +64 -5
- package/node_modules/pi-commandcode-provider/README.md +40 -26
- package/node_modules/pi-commandcode-provider/RELEASE.md +25 -0
- package/node_modules/pi-commandcode-provider/index.ts +212 -38
- package/node_modules/pi-commandcode-provider/package.json +9 -8
- package/node_modules/pi-commandcode-provider/scripts/live-e2e-profile.mjs +6 -13
- package/node_modules/pi-commandcode-provider/scripts/typecheck-entrypoint.mjs +88 -0
- package/node_modules/pi-commandcode-provider/src/api-key.ts +43 -2
- package/node_modules/pi-commandcode-provider/src/commandcode-catalog-overrides.ts +1 -1
- package/node_modules/pi-commandcode-provider/src/commandcode-catalog.ts +9 -2
- package/node_modules/pi-commandcode-provider/src/cost.ts +3 -37
- package/node_modules/pi-commandcode-provider/src/diagnostics.ts +215 -0
- package/node_modules/pi-commandcode-provider/src/oauth.ts +1 -1
- package/node_modules/pi-commandcode-provider/src/quota-command.ts +1 -1
- package/node_modules/pi-commandcode-provider/src/routing.ts +166 -0
- package/node_modules/pi-commandcode-provider/src/runtime.ts +15 -9
- package/node_modules/pi-commandcode-provider/src/transport.ts +79 -85
- package/node_modules/pi-commandcode-provider/src/types.ts +20 -39
- package/node_modules/pi-commandcode-provider/src/usage.ts +1 -1
- package/node_modules/pi-lens/CHANGELOG-USER.md +31 -0
- package/node_modules/pi-lens/CHANGELOG.md +178 -0
- package/node_modules/pi-lens/README.md +2 -1
- package/node_modules/pi-lens/config/dependency-cruiser-eager-allowlist.json +1 -1
- package/node_modules/pi-lens/dist/{chunk-3O5EII3W.js → chunk-2VZ3VN3N.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-SDFKOLSF.js → chunk-3HTZDY3C.js} +8 -6
- package/node_modules/pi-lens/dist/{chunk-A5GRLYPZ.js → chunk-3NPWO5UO.js} +7 -13
- package/node_modules/pi-lens/dist/{chunk-AGGUWKRK.js → chunk-47UCC4MM.js} +1 -1
- package/node_modules/pi-lens/dist/chunk-4ENEJHF4.js +198 -0
- package/node_modules/pi-lens/dist/{chunk-WXUDRAG6.js → chunk-5GEYJJHG.js} +10 -12
- package/node_modules/pi-lens/dist/{chunk-HHR7WGCI.js → chunk-5YSEQHJN.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-L3CLUGDY.js → chunk-6GPB3JLL.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-5F3XF3SX.js → chunk-7R5GZIA6.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-CUDD35TW.js → chunk-7UTSNTWM.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-DYRZGUMA.js → chunk-7YTRG6YW.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-JZRP4DGP.js → chunk-AACN5GNE.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-7ANZ7XDD.js → chunk-ACRJ2GZ5.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-6FIRFP6A.js → chunk-C3YRO3EU.js} +10 -12
- package/node_modules/pi-lens/dist/{chunk-GMROJJRN.js → chunk-CB7PEVOJ.js} +9 -1
- package/node_modules/pi-lens/dist/{chunk-BBET6HD6.js → chunk-CDFJF5YD.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-NSPVR3FN.js → chunk-CJS6WE66.js} +17 -19
- package/node_modules/pi-lens/dist/{chunk-6YUNI7B5.js → chunk-CM6BDY4E.js} +14 -60
- package/node_modules/pi-lens/dist/{chunk-G5GV2Q7K.js → chunk-CZCAZVTD.js} +16 -2
- package/node_modules/pi-lens/dist/chunk-DGKFWQK4.js +23 -0
- package/node_modules/pi-lens/dist/{chunk-VOP4PJKA.js → chunk-E65WJVI5.js} +7 -9
- package/node_modules/pi-lens/dist/{chunk-TV6RXRYH.js → chunk-EKNYSXFB.js} +8 -10
- package/node_modules/pi-lens/dist/{chunk-4LL2VRNY.js → chunk-EY6LY2HO.js} +16 -18
- package/node_modules/pi-lens/dist/{chunk-MC6VB2E5.js → chunk-F6BEQWAK.js} +17 -5
- package/node_modules/pi-lens/dist/{chunk-R2QQC33W.js → chunk-FGNSESAC.js} +12 -14
- package/node_modules/pi-lens/dist/{chunk-OC7VWJBZ.js → chunk-FRUBVFXV.js} +35 -37
- package/node_modules/pi-lens/dist/{chunk-7CGIDRIK.js → chunk-G22UNQID.js} +14 -16
- package/node_modules/pi-lens/dist/{chunk-L4NEVZ4T.js → chunk-GQTQUNCG.js} +25 -27
- package/node_modules/pi-lens/dist/{chunk-ZKLTNLAW.js → chunk-H3BVMK47.js} +6 -6
- package/node_modules/pi-lens/dist/chunk-H6FLQ5NW.js +28 -0
- package/node_modules/pi-lens/dist/{chunk-2ZE3AUJQ.js → chunk-HEA3EM23.js} +13 -15
- package/node_modules/pi-lens/dist/{chunk-CZL44WFN.js → chunk-HSOBIN22.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-PKSUMEPT.js → chunk-HYSKJMZK.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-VN3L2JWZ.js → chunk-IICERRFF.js} +5 -5
- package/node_modules/pi-lens/dist/{chunk-O4N5BQ3T.js → chunk-IILEH3ZC.js} +8 -10
- package/node_modules/pi-lens/dist/{chunk-WC6WRNQT.js → chunk-J3Q2NYJR.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-SFLHSL5R.js → chunk-JUZ67QZQ.js} +18 -7
- package/node_modules/pi-lens/dist/chunk-KR5VGMVT.js +25 -0
- package/node_modules/pi-lens/dist/{chunk-UHHLR2VY.js → chunk-KV6GQOGN.js} +38 -41
- package/node_modules/pi-lens/dist/{chunk-HUAM7QG3.js → chunk-KXMJLOZF.js} +25 -23
- package/node_modules/pi-lens/dist/{chunk-BUZIQDFS.js → chunk-L4Y3ROKQ.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-JBP7KESM.js → chunk-L6WBJGQS.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-35WKJWO5.js → chunk-L7O774U7.js} +14 -14
- package/node_modules/pi-lens/dist/{chunk-BOPDQ7AZ.js → chunk-LAHHGNAY.js} +19 -21
- package/node_modules/pi-lens/dist/{chunk-RGGH6M34.js → chunk-LT62P654.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-5T5A6YAJ.js → chunk-LWOM6LVS.js} +33 -34
- package/node_modules/pi-lens/dist/{chunk-JYLOYTZD.js → chunk-MKPDIAZH.js} +5 -1
- package/node_modules/pi-lens/dist/{chunk-CM73PPGD.js → chunk-MN635QYA.js} +3 -4
- package/node_modules/pi-lens/dist/{chunk-BQG2QFVO.js → chunk-MQ4PPCJB.js} +21 -29
- package/node_modules/pi-lens/dist/{chunk-HXFUTMX2.js → chunk-MRLH4MYU.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-XOMGO63G.js → chunk-N56BNAA6.js} +19 -21
- package/node_modules/pi-lens/dist/{chunk-7MAD5ZAY.js → chunk-N5CEGQPG.js} +14 -16
- package/node_modules/pi-lens/dist/{chunk-ZFORSIED.js → chunk-NCLO6E6N.js} +13 -33
- package/node_modules/pi-lens/dist/{chunk-SQC7K3SP.js → chunk-NL5LSKVD.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-I22THIHI.js → chunk-NMUSOZ2D.js} +10 -12
- package/node_modules/pi-lens/dist/{chunk-4NBWFYWW.js → chunk-NOWH2VA2.js} +8 -33
- package/node_modules/pi-lens/dist/{chunk-NM2NWH55.js → chunk-NUSXS6YB.js} +6 -5
- package/node_modules/pi-lens/dist/{chunk-OZWXLJMX.js → chunk-OSEKJEUU.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-2BKUFQKR.js → chunk-OUYAUXAT.js} +405 -181
- package/node_modules/pi-lens/dist/{chunk-JPRDTY5S.js → chunk-PBZNYHMM.js} +8 -10
- package/node_modules/pi-lens/dist/{chunk-JE6HKLC7.js → chunk-PIIUNJIT.js} +2 -4
- package/node_modules/pi-lens/dist/{chunk-ZZDIOAAJ.js → chunk-PRHYIA6X.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-4W52ZKZX.js → chunk-PXQ45SGD.js} +2 -2
- package/node_modules/pi-lens/dist/chunk-Q6JQKWPK.js +25 -0
- package/node_modules/pi-lens/dist/{chunk-PIQQM32Y.js → chunk-QB7T2PHK.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-HKIL6DCL.js → chunk-QGITU23N.js} +1 -1
- package/node_modules/pi-lens/dist/chunk-QJJKOHLH.js +57 -0
- package/node_modules/pi-lens/dist/{chunk-6LJOJ6EO.js → chunk-QP33NKYC.js} +14 -16
- package/node_modules/pi-lens/dist/{chunk-DIWK3LBC.js → chunk-QVBOXT3L.js} +8 -10
- package/node_modules/pi-lens/dist/{chunk-IYVYZQRL.js → chunk-RNJFRXEN.js} +5 -7
- package/node_modules/pi-lens/dist/{chunk-G6JKM4O7.js → chunk-RNXOWDM6.js} +10 -10
- package/node_modules/pi-lens/dist/{chunk-5RNB4HVK.js → chunk-RTFMDIKV.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-XWIME22V.js → chunk-SIQHOB6P.js} +11 -13
- package/node_modules/pi-lens/dist/{chunk-T2S3FNNJ.js → chunk-SLSMJPEF.js} +41 -42
- package/node_modules/pi-lens/dist/chunk-T5QSLSMM.js +50 -0
- package/node_modules/pi-lens/dist/chunk-TGQDAG4B.js +88 -0
- package/node_modules/pi-lens/dist/{chunk-6GMGEKQN.js → chunk-THYHUIDR.js} +39 -12
- package/node_modules/pi-lens/dist/{chunk-WMDUT4KH.js → chunk-TMNUTMT5.js} +72 -89
- package/node_modules/pi-lens/dist/{chunk-7TNILKGY.js → chunk-TOE2RRCS.js} +1 -1
- package/node_modules/pi-lens/dist/chunk-TYHPVE5H.js +25 -0
- package/node_modules/pi-lens/dist/chunk-UAKO2M6B.js +73 -0
- package/node_modules/pi-lens/dist/chunk-UC5AXW5Z.js +20 -0
- package/node_modules/pi-lens/dist/chunk-UTJP6WOS.js +28 -0
- package/node_modules/pi-lens/dist/{chunk-FRLAUP2B.js → chunk-UXTQ3QPD.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-4QG55RRC.js → chunk-V2WDBOLZ.js} +10 -12
- package/node_modules/pi-lens/dist/{chunk-FHEV6T4L.js → chunk-V67D6TMU.js} +8 -10
- package/node_modules/pi-lens/dist/{chunk-VLQ7UKZH.js → chunk-VCRVNLE7.js} +135 -2
- package/node_modules/pi-lens/dist/{chunk-KZ4ALBCH.js → chunk-VO4JFPTV.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-GIRBSBGL.js → chunk-VWLSU3XV.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-2453RRJ2.js → chunk-W5E72HJA.js} +59 -22
- package/node_modules/pi-lens/dist/{chunk-VPLBLWFO.js → chunk-W7TY6HYX.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-SP4TFY5F.js → chunk-WSSLVMDA.js} +11 -13
- package/node_modules/pi-lens/dist/{chunk-PPKECBPP.js → chunk-WTB4GKMH.js} +10 -1
- package/node_modules/pi-lens/dist/{chunk-X35S7HSB.js → chunk-X5BJ3G2P.js} +41 -30
- package/node_modules/pi-lens/dist/{chunk-X66YJ2SS.js → chunk-XKFO2SZV.js} +33 -34
- package/node_modules/pi-lens/dist/{chunk-OWTG6UMO.js → chunk-XLAI7UYY.js} +75 -22
- package/node_modules/pi-lens/dist/{chunk-4B2YFN4U.js → chunk-XO756WE5.js} +45 -33
- package/node_modules/pi-lens/dist/{chunk-VOXTCULR.js → chunk-XVB3Q2PG.js} +2 -4
- package/node_modules/pi-lens/dist/{chunk-XYLC35E4.js → chunk-YOXCCJDF.js} +517 -308
- package/node_modules/pi-lens/dist/{chunk-O2ARHQKF.js → chunk-ZCQBNPRH.js} +2 -2
- package/node_modules/pi-lens/dist/chunk-ZD4KVFXI.js +234 -0
- package/node_modules/pi-lens/dist/{chunk-LSFXZLPW.js → chunk-ZDMFGACN.js} +184 -235
- package/node_modules/pi-lens/dist/{chunk-4BKU7PV3.js → chunk-ZMMHHXSW.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-OY7WZI7Q.js → chunk-ZPM7ZIFL.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-R4QWJQ2H.js → chunk-ZVCDHYWZ.js} +9 -11
- package/node_modules/pi-lens/dist/{chunk-RZG472YW.js → chunk-ZZN74OGD.js} +83 -46
- package/node_modules/pi-lens/dist/{chunk-BHWW6FAX.js → chunk-ZZSJAR76.js} +37 -19
- package/node_modules/pi-lens/dist/index.js +4910 -4218
- package/node_modules/pi-lens/dist/mcp/analyze-cli.js +12 -17
- package/node_modules/pi-lens/dist/mcp/cli.js +41 -42
- package/node_modules/pi-lens/dist/mcp/server.js +1451 -648
- package/node_modules/pi-lens/dist/mcp/worker.js +59 -60
- package/node_modules/pi-lens/dist/probes/installer.js +17 -19
- package/node_modules/pi-lens/docs/agent-tools.md +40 -8
- package/node_modules/pi-lens/docs/analysisall.md +1 -1
- package/node_modules/pi-lens/docs/ci-bot-pr-checks.md +7 -5
- package/node_modules/pi-lens/docs/configuration.md +51 -9
- package/node_modules/pi-lens/docs/defect-shapes.md +52 -3
- package/node_modules/pi-lens/docs/environment-variables.md +18 -1
- package/node_modules/pi-lens/docs/features.md +12 -5
- package/node_modules/pi-lens/docs/globalconfig.md +11 -3
- package/node_modules/pi-lens/docs/invariants/lsp-trust-exec.md +9 -2
- package/node_modules/pi-lens/docs/invariants/session-telemetry.md +2 -2
- package/node_modules/pi-lens/docs/language-coverage.md +1 -0
- package/node_modules/pi-lens/docs/lsp-capability-matrix.md +57 -35
- package/node_modules/pi-lens/docs/lsp-idle-eviction.md +4 -1
- package/node_modules/pi-lens/docs/merge-queue-rollout.md +10 -8
- package/node_modules/pi-lens/docs/module-report-read-symbol.md +34 -23
- package/node_modules/pi-lens/docs/pi-lens-fixer.md +11 -1
- package/node_modules/pi-lens/docs/pi-lens-investigator.md +3 -0
- package/node_modules/pi-lens/docs/pi-lens-merge-policy.md +15 -7
- package/node_modules/pi-lens/docs/pi-lens-reviewer.md +1 -1
- package/node_modules/pi-lens/docs/pi-lens-subagent.md +13 -0
- package/node_modules/pi-lens/docs/public-api-stability.md +39 -5
- package/node_modules/pi-lens/docs/release-qa-baseline.md +7 -4
- package/node_modules/pi-lens/docs/schema/pi-lens-config-v1.json +11 -2
- package/node_modules/pi-lens/docs/servercapabilities.md +3 -1
- package/node_modules/pi-lens/docs/settings.md +2 -2
- package/node_modules/pi-lens/docs/word-index.md +3 -2
- package/node_modules/pi-lens/package.json +8 -3
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-sql-in-code-execute-js.yml +1 -2
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-sql-in-code-execute.yml +1 -2
- package/node_modules/pi-lens/scripts/download-grammars.js +3 -2
- package/node_modules/pi-lens/skills/pi-lens-lsp-navigation/SKILL.md +5 -1
- package/node_modules/pi-provider-qoder/dist/index.js +473 -62
- package/node_modules/pi-provider-qoder/package.json +1 -1
- package/package.json +10 -8
- package/node_modules/pi-commandcode-provider/src/converters.ts +0 -419
- package/node_modules/pi-commandcode-provider/src/core.ts +0 -861
- package/node_modules/pi-commandcode-provider/src/json-schema.ts +0 -417
- package/node_modules/pi-commandcode-provider/src/transcript.ts +0 -56
- package/node_modules/pi-lens/dist/chunk-2TS4GLOJ.js +0 -31
- package/node_modules/pi-lens/dist/chunk-3JAHQBSY.js +0 -27
- package/node_modules/pi-lens/dist/chunk-447YZL4S.js +0 -25
- package/node_modules/pi-lens/dist/chunk-565VRUP4.js +0 -136
- package/node_modules/pi-lens/dist/chunk-57X2CDRX.js +0 -49
- package/node_modules/pi-lens/dist/chunk-GGYOZWHW.js +0 -27
- package/node_modules/pi-lens/dist/chunk-IE5D3RA5.js +0 -58
- package/node_modules/pi-lens/dist/chunk-LPYTPNOJ.js +0 -22
- package/node_modules/pi-lens/dist/chunk-OFNMHPBT.js +0 -89
- package/node_modules/pi-lens/dist/chunk-U3AS2FR6.js +0 -106
- package/node_modules/pi-lens/dist/chunk-W3BGKBBK.js +0 -27
- package/node_modules/pi-lens/dist/chunk-WQV6BI4Q.js +0 -48
- package/node_modules/pi-lens/dist/chunk-YHGYAEFH.js +0 -443
- package/node_modules/pi-lens/dist/chunk-ZONZ6YY3.js +0 -74
- package/node_modules/pi-lens/dist/chunk-ZSM35JF4.js +0 -30
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const COMMAND_CODE_CLI_VERSION = "1.88.
|
|
1
|
+
export const COMMAND_CODE_CLI_VERSION = "1.88.3"
|
|
2
2
|
|
|
3
3
|
export type CommandCodeInputType = "text" | "image"
|
|
4
4
|
export type CommandCodeReasoningEffort =
|
|
@@ -11,7 +11,7 @@ export type CommandCodeReasoningEffort =
|
|
|
11
11
|
| "max"
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* Generated from command-code@1.88.
|
|
14
|
+
* Generated from command-code@1.88.3 by `npm run sync:commandcode-catalog`.
|
|
15
15
|
* Do not edit manually.
|
|
16
16
|
*/
|
|
17
17
|
export const MODEL_INPUT_MODALITIES: Readonly<Record<string, readonly CommandCodeInputType[]>> = {
|
|
@@ -76,6 +76,7 @@ export const MODEL_INPUT_MODALITIES: Readonly<Record<string, readonly CommandCod
|
|
|
76
76
|
"Qwen/Qwen3.8-Max-Prime": ["text", "image"],
|
|
77
77
|
"Qwen/Qwen3.8-Omni-Flash": ["text", "image"],
|
|
78
78
|
"sakana/fugu-ultra": ["text", "image"],
|
|
79
|
+
"stealth/crouton-alpha": ["text", "image"],
|
|
79
80
|
"stepfun/Step-3.7-Flash": ["text", "image"],
|
|
80
81
|
"stepfun/Step-5-Preview": ["text", "image"],
|
|
81
82
|
"thinkingmachines/inkling": ["text", "image"],
|
|
@@ -127,6 +128,7 @@ export const MODEL_REASONING: Readonly<Record<string, true>> = {
|
|
|
127
128
|
"gpt-6.1-sol": true,
|
|
128
129
|
"gpt-6.1-terra": true,
|
|
129
130
|
"inclusionai/ling-3.1-flash": true,
|
|
131
|
+
"inclusionai/ling-3.1-flash-1019": true,
|
|
130
132
|
"meituan/LongCat-2.0": true,
|
|
131
133
|
"meta/muse-spark-1.1": true,
|
|
132
134
|
"meta/muse-spark-1.2": true,
|
|
@@ -159,6 +161,7 @@ export const MODEL_REASONING: Readonly<Record<string, true>> = {
|
|
|
159
161
|
"Qwen/Qwen3.8-Omni-Flash": true,
|
|
160
162
|
"reflection/beam:free": true,
|
|
161
163
|
"sakana/fugu-ultra": true,
|
|
164
|
+
"stealth/crouton-alpha": true,
|
|
162
165
|
"stealth/glyph-cluster:free": true,
|
|
163
166
|
"stepfun/Step-3.5-Flash": true,
|
|
164
167
|
"stepfun/Step-3.7-Flash": true,
|
|
@@ -213,6 +216,7 @@ export const MODEL_EFFORTS: Readonly<Record<string, readonly CommandCodeReasonin
|
|
|
213
216
|
"gpt-6.1-sol": ["low", "medium", "high", "xhigh", "max"],
|
|
214
217
|
"gpt-6.1-terra": ["low", "medium", "high", "xhigh", "max"],
|
|
215
218
|
"inclusionai/ling-3.1-flash": ["low", "medium", "high"],
|
|
219
|
+
"inclusionai/ling-3.1-flash-1019": ["low", "medium", "high"],
|
|
216
220
|
"meta/muse-spark-1.1": ["low", "medium", "high", "xhigh"],
|
|
217
221
|
"meta/muse-spark-1.2": ["low", "medium", "high", "xhigh"],
|
|
218
222
|
"meta/muse-spark-1.2-contributor": ["low", "medium", "high", "xhigh"],
|
|
@@ -234,6 +238,7 @@ export const MODEL_EFFORTS: Readonly<Record<string, readonly CommandCodeReasonin
|
|
|
234
238
|
"Qwen/Qwen3.8-Omni-Flash": ["low", "medium", "xhigh"],
|
|
235
239
|
"reflection/beam:free": ["low", "medium", "high", "xhigh", "max"],
|
|
236
240
|
"sakana/fugu-ultra": ["high", "xhigh"],
|
|
241
|
+
"stealth/crouton-alpha": ["low", "medium", "high", "xhigh", "max"],
|
|
237
242
|
"stealth/glyph-cluster:free": ["low", "medium", "high", "xhigh"],
|
|
238
243
|
"stepfun/Step-5-Preview": ["low", "medium", "high"],
|
|
239
244
|
"tencent/hy4-preview": ["low", "medium", "high"],
|
|
@@ -248,12 +253,14 @@ export const MODEL_EFFORTS: Readonly<Record<string, readonly CommandCodeReasonin
|
|
|
248
253
|
|
|
249
254
|
export const MODEL_MAX_OUTPUT_TOKENS: Readonly<Record<string, number>> = {
|
|
250
255
|
"inclusionai/ling-3.1-flash": 32_768,
|
|
256
|
+
"inclusionai/ling-3.1-flash-1019": 262_144,
|
|
251
257
|
"mistral/mistral-large-4": 262_144,
|
|
252
258
|
"poolside/laguna-s-2.1-free": 32_768,
|
|
253
259
|
"Qwen/Qwen3.8-27B": 32_768,
|
|
254
260
|
"Qwen/Qwen3.8-Max-Prime": 131_072,
|
|
255
261
|
"Qwen/Qwen3.8-Omni-Flash": 131_072,
|
|
256
262
|
"reflection/beam:free": 131_072,
|
|
263
|
+
"stealth/crouton-alpha": 943_718,
|
|
257
264
|
"stealth/glyph-cluster:free": 256_000,
|
|
258
265
|
"z-ai/glm-5.3-flash": 131_072,
|
|
259
266
|
"z-ai/glm-5.3-flashx": 131_072,
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Local cost calculation for Command Code usage.
|
|
3
|
-
*
|
|
4
|
-
* Mirrors pi-ai's `calculateCost` arithmetic exactly. The provider ships its
|
|
5
|
-
* own copy because Oh My Pi's legacy pi-ai shim does not export
|
|
6
|
-
* `calculateCost`, which broke extension installation there (issue #24).
|
|
7
|
-
* `tests/test-cost.ts` locks this implementation to the pi-ai original.
|
|
8
|
-
*/
|
|
1
|
+
/** Request-time Provider API rates; the native host calculates usage costs. */
|
|
9
2
|
|
|
10
|
-
import type { ModelCost, ModelCostRates, ModelCostTier
|
|
3
|
+
import type { ModelCost, ModelCostRates, ModelCostTier } from "./types.ts"
|
|
11
4
|
|
|
12
5
|
const DEEPSEEK_V4_TIME_PRICED_MODELS = new Set([
|
|
13
6
|
"deepseek/deepseek-v4-pro",
|
|
@@ -41,8 +34,7 @@ function doubledRates<T extends ModelCostRates>(rates: T): T {
|
|
|
41
34
|
}
|
|
42
35
|
|
|
43
36
|
/**
|
|
44
|
-
* Select request-time rates for
|
|
45
|
-
* local generate fallback. DeepSeek V4 peak rates are exactly 2x off-peak.
|
|
37
|
+
* Select request-time rates for the native provider transport. DeepSeek V4 peak rates are exactly 2x off-peak.
|
|
46
38
|
* Context tiers on a full model cost table are kept and doubled alongside
|
|
47
39
|
* the base rates so the host's tier selection still applies during peak.
|
|
48
40
|
*/
|
|
@@ -68,29 +60,3 @@ export function commandCodeNativeCostRatesAt(
|
|
|
68
60
|
const selected = commandCodeCostRatesAt(modelId, rates, atMs)
|
|
69
61
|
return { ...selected, tiers: selected.tiers?.map((tier) => ({ ...tier })) }
|
|
70
62
|
}
|
|
71
|
-
|
|
72
|
-
export function calculateCommandCodeCost(
|
|
73
|
-
model: ModelLike,
|
|
74
|
-
usage: Usage,
|
|
75
|
-
atMs: number = Date.now(),
|
|
76
|
-
): void {
|
|
77
|
-
const inputTokens = usage.input + usage.cacheRead + usage.cacheWrite
|
|
78
|
-
let rates: ModelCostRates = model.cost
|
|
79
|
-
let matchedThreshold = -1
|
|
80
|
-
for (const tier of model.cost.tiers ?? []) {
|
|
81
|
-
if (inputTokens > tier.inputTokensAbove && tier.inputTokensAbove > matchedThreshold) {
|
|
82
|
-
rates = tier
|
|
83
|
-
matchedThreshold = tier.inputTokensAbove
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
rates = commandCodeCostRatesAt(model.id, rates, atMs)
|
|
87
|
-
|
|
88
|
-
const longWrite = usage.cacheWrite1h ?? 0
|
|
89
|
-
const shortWrite = usage.cacheWrite - longWrite
|
|
90
|
-
usage.cost.input = (rates.input / 1_000_000) * usage.input
|
|
91
|
-
usage.cost.output = (rates.output / 1_000_000) * usage.output
|
|
92
|
-
usage.cost.cacheRead = (rates.cacheRead / 1_000_000) * usage.cacheRead
|
|
93
|
-
usage.cost.cacheWrite = (rates.cacheWrite * shortWrite + rates.input * 2 * longWrite) / 1_000_000
|
|
94
|
-
usage.cost.total =
|
|
95
|
-
usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite
|
|
96
|
-
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MODEL_INPUT_MODALITIES,
|
|
3
|
+
MODEL_REASONING,
|
|
4
|
+
MODEL_EFFORTS,
|
|
5
|
+
COMMAND_CODE_CLI_VERSION,
|
|
6
|
+
} from "./commandcode-catalog.ts"
|
|
7
|
+
import { MODEL_COSTS, PRICING_LAST_VERIFIED, TEMPORARY_PRICING } from "./pricing.ts"
|
|
8
|
+
import { redactCommandCodeErrorText } from "./overflow.ts"
|
|
9
|
+
import type {
|
|
10
|
+
AssistantMessageEventStreamLike,
|
|
11
|
+
ContextLike,
|
|
12
|
+
ModelLike,
|
|
13
|
+
StreamOptions,
|
|
14
|
+
} from "./types.ts"
|
|
15
|
+
|
|
16
|
+
export interface RequestDiagnostic {
|
|
17
|
+
model: string
|
|
18
|
+
endpoint?: string
|
|
19
|
+
status?: number
|
|
20
|
+
requestId?: string
|
|
21
|
+
attempts: number
|
|
22
|
+
firstChunkMs?: number
|
|
23
|
+
longestChunkGapMs: number
|
|
24
|
+
durationMs?: number
|
|
25
|
+
outcome: "pending" | "done" | "error" | "aborted"
|
|
26
|
+
error?:
|
|
27
|
+
| "authentication"
|
|
28
|
+
| "permission"
|
|
29
|
+
| "rate_limit"
|
|
30
|
+
| "server"
|
|
31
|
+
| "context_length"
|
|
32
|
+
| "timeout"
|
|
33
|
+
| "request_failed"
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function priceStatus(
|
|
37
|
+
modelId: string,
|
|
38
|
+
now = Date.now(),
|
|
39
|
+
): "known" | "unknown" | "review-required" {
|
|
40
|
+
if (!Object.hasOwn(MODEL_COSTS, modelId)) return "unknown"
|
|
41
|
+
const day = new Date(now).toISOString().slice(0, 10)
|
|
42
|
+
return TEMPORARY_PRICING.some(
|
|
43
|
+
(promotion) => promotion.models.includes(modelId) && promotion.expiresOn < day,
|
|
44
|
+
)
|
|
45
|
+
? "review-required"
|
|
46
|
+
: "known"
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function safeIdentifier(value: string): string {
|
|
50
|
+
if (!/^[a-zA-Z0-9_./:+-]{1,160}$/.test(value)) return "[redacted]"
|
|
51
|
+
// Model IDs can come from host overrides: a slug's alphabet alone is not a trust boundary.
|
|
52
|
+
if (/^\/|(?:^|\/)\.{1,2}(?:\/|$)|^[a-z][a-z0-9+.-]*:/i.test(value)) return "[redacted]"
|
|
53
|
+
return redactCommandCodeErrorText(value) === value ? value : "[redacted]"
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function classify(status: number | undefined, message: string): RequestDiagnostic["error"] {
|
|
57
|
+
if (status === 401) return "authentication"
|
|
58
|
+
if (status === 403) return "permission"
|
|
59
|
+
if (status === 429) return "rate_limit"
|
|
60
|
+
if (status && status >= 500) return "server"
|
|
61
|
+
if (/context_length_exceeded/.test(message)) return "context_length"
|
|
62
|
+
if (/timed?\s*out/i.test(message)) return "timeout"
|
|
63
|
+
return "request_failed"
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const ENDPOINTS = [
|
|
67
|
+
"/provider/v1/responses",
|
|
68
|
+
"/provider/v1/chat/completions",
|
|
69
|
+
"/provider/v1/messages",
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
/** Memory-only, content-free measurements. Never retain URLs, headers, bodies or credentials. */
|
|
73
|
+
export function createRequestDiagnostics(now: () => number = Date.now) {
|
|
74
|
+
let latest: RequestDiagnostic | undefined
|
|
75
|
+
return {
|
|
76
|
+
snapshot: () => (latest ? { ...latest } : undefined),
|
|
77
|
+
stream<
|
|
78
|
+
TModel extends ModelLike,
|
|
79
|
+
TContext extends ContextLike,
|
|
80
|
+
TReasoning extends string,
|
|
81
|
+
TStream extends AssistantMessageEventStreamLike,
|
|
82
|
+
>(
|
|
83
|
+
source: (
|
|
84
|
+
model: TModel,
|
|
85
|
+
context: TContext,
|
|
86
|
+
options?: StreamOptions<TModel, TReasoning>,
|
|
87
|
+
) => AssistantMessageEventStreamLike,
|
|
88
|
+
createStream: () => TStream,
|
|
89
|
+
model: TModel,
|
|
90
|
+
context: TContext,
|
|
91
|
+
options?: StreamOptions<TModel, TReasoning>,
|
|
92
|
+
): TStream {
|
|
93
|
+
const started = now()
|
|
94
|
+
const record: RequestDiagnostic = {
|
|
95
|
+
model: safeIdentifier(model.id),
|
|
96
|
+
attempts: 0,
|
|
97
|
+
longestChunkGapMs: 0,
|
|
98
|
+
outcome: "pending",
|
|
99
|
+
}
|
|
100
|
+
latest = record
|
|
101
|
+
const output = createStream()
|
|
102
|
+
let lastChunk: number | undefined
|
|
103
|
+
const instrumented: StreamOptions<TModel, TReasoning> = {
|
|
104
|
+
...options,
|
|
105
|
+
fetch: async (input, init) => {
|
|
106
|
+
record.attempts += 1
|
|
107
|
+
lastChunk = undefined
|
|
108
|
+
try {
|
|
109
|
+
const pathname = new URL(
|
|
110
|
+
typeof input === "string" ? input : input instanceof URL ? input.href : input.url,
|
|
111
|
+
).pathname
|
|
112
|
+
record.endpoint = ENDPOINTS.find((path) => pathname === path) ?? "custom endpoint"
|
|
113
|
+
} catch {
|
|
114
|
+
record.endpoint = "custom endpoint"
|
|
115
|
+
}
|
|
116
|
+
const response = await (options?.fetch ?? fetch)(input, init)
|
|
117
|
+
record.status = response.status
|
|
118
|
+
const requestId =
|
|
119
|
+
response.headers.get("x-request-id") ?? response.headers.get("request-id")
|
|
120
|
+
record.requestId =
|
|
121
|
+
requestId && /^[a-f0-9-]{16,64}$/i.test(requestId) ? requestId : undefined
|
|
122
|
+
if (!response.body) return response
|
|
123
|
+
return new Response(
|
|
124
|
+
response.body.pipeThrough(
|
|
125
|
+
new TransformStream<Uint8Array, Uint8Array>({
|
|
126
|
+
transform(chunk, controller) {
|
|
127
|
+
const at = now()
|
|
128
|
+
if (record.firstChunkMs === undefined) record.firstChunkMs = at - started
|
|
129
|
+
if (lastChunk !== undefined)
|
|
130
|
+
record.longestChunkGapMs = Math.max(record.longestChunkGapMs, at - lastChunk)
|
|
131
|
+
lastChunk = at
|
|
132
|
+
controller.enqueue(chunk)
|
|
133
|
+
},
|
|
134
|
+
}),
|
|
135
|
+
),
|
|
136
|
+
{ status: response.status, statusText: response.statusText, headers: response.headers },
|
|
137
|
+
)
|
|
138
|
+
},
|
|
139
|
+
}
|
|
140
|
+
const run = async () => {
|
|
141
|
+
try {
|
|
142
|
+
for await (const event of source(model, context, instrumented)) {
|
|
143
|
+
if (event.type === "done") record.outcome = "done"
|
|
144
|
+
if (event.type === "error") {
|
|
145
|
+
record.outcome = event.reason === "aborted" ? "aborted" : "error"
|
|
146
|
+
if (record.outcome !== "aborted")
|
|
147
|
+
record.error = classify(record.status, event.error.errorMessage ?? "")
|
|
148
|
+
}
|
|
149
|
+
output.push(event)
|
|
150
|
+
}
|
|
151
|
+
} catch (error) {
|
|
152
|
+
record.outcome = options?.signal?.aborted ? "aborted" : "error"
|
|
153
|
+
if (record.outcome !== "aborted")
|
|
154
|
+
record.error = classify(record.status, error instanceof Error ? error.message : "")
|
|
155
|
+
output.push({
|
|
156
|
+
type: "error",
|
|
157
|
+
reason: record.outcome === "aborted" ? "aborted" : "error",
|
|
158
|
+
error: {
|
|
159
|
+
role: "assistant",
|
|
160
|
+
content: [],
|
|
161
|
+
api: model.api,
|
|
162
|
+
provider: model.provider,
|
|
163
|
+
model: model.id,
|
|
164
|
+
timestamp: now(),
|
|
165
|
+
stopReason: record.outcome === "aborted" ? "aborted" : "error",
|
|
166
|
+
errorMessage:
|
|
167
|
+
"Command Code request failed before completing the stream; see /commandcode-diagnostics",
|
|
168
|
+
usage: {
|
|
169
|
+
input: 0,
|
|
170
|
+
output: 0,
|
|
171
|
+
cacheRead: 0,
|
|
172
|
+
cacheWrite: 0,
|
|
173
|
+
totalTokens: 0,
|
|
174
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
})
|
|
178
|
+
} finally {
|
|
179
|
+
record.durationMs = now() - started
|
|
180
|
+
output.end()
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
run().catch(() => output.end())
|
|
184
|
+
return output
|
|
185
|
+
},
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function formatDiagnostics(input: {
|
|
190
|
+
pluginVersion: string
|
|
191
|
+
host: string
|
|
192
|
+
hostVersion: string
|
|
193
|
+
modelId?: string
|
|
194
|
+
route: string
|
|
195
|
+
request?: RequestDiagnostic
|
|
196
|
+
}): string {
|
|
197
|
+
const modelId = input.modelId
|
|
198
|
+
const known =
|
|
199
|
+
modelId &&
|
|
200
|
+
(Object.hasOwn(MODEL_INPUT_MODALITIES, modelId) ||
|
|
201
|
+
Object.hasOwn(MODEL_REASONING, modelId) ||
|
|
202
|
+
Object.hasOwn(MODEL_EFFORTS, modelId))
|
|
203
|
+
return [
|
|
204
|
+
`plugin: ${safeIdentifier(input.pluginVersion)}`,
|
|
205
|
+
`host: ${safeIdentifier(input.host)} ${safeIdentifier(input.hostVersion)}`,
|
|
206
|
+
`catalog CLI: ${COMMAND_CODE_CLI_VERSION}`,
|
|
207
|
+
`model: ${modelId ? safeIdentifier(modelId) : "none"}`,
|
|
208
|
+
// Caller supplies only a normalized routing description, never an error body.
|
|
209
|
+
`route: ${input.route}`,
|
|
210
|
+
`capabilities: ${known ? "bundled snapshot; host overrides may apply" : "not explicitly catalogued; conservative defaults"}`,
|
|
211
|
+
`price: ${modelId ? priceStatus(modelId) : "unknown"} (verified ${PRICING_LAST_VERIFIED}; estimate, not billing)`,
|
|
212
|
+
input.request ? `last request: ${JSON.stringify(input.request)}` : "last request: none",
|
|
213
|
+
"Timing measures received body chunks, not tokens. No prompts, tool content, credentials, account data or configured local paths are collected. Model IDs come from the host; review custom names before sharing.",
|
|
214
|
+
].join("\n")
|
|
215
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getConfiguredApiKey } from "./api-key.ts"
|
|
2
|
-
import { pickCommandCodeApiKey } from "./
|
|
2
|
+
import { pickCommandCodeApiKey } from "./api-key.ts"
|
|
3
3
|
import { fetchCommandCodeQuota, redactValue } from "./quota.ts"
|
|
4
4
|
import { formatQuota } from "./quota-format.ts"
|
|
5
5
|
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// Persistent endpoint choices carried forward from #158 by @patlux.
|
|
2
|
+
import { randomUUID } from "node:crypto"
|
|
3
|
+
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises"
|
|
4
|
+
import { basename, dirname } from "node:path"
|
|
5
|
+
import type { CommandCodeApi, CommandCodeModel } from "./models.ts"
|
|
6
|
+
|
|
7
|
+
export type EndpointChoice = "auto" | "responses" | "chat-completions"
|
|
8
|
+
export type EndpointOverrides = Readonly<Record<string, EndpointChoice>>
|
|
9
|
+
|
|
10
|
+
export function isEndpointChoice(value: unknown): value is EndpointChoice {
|
|
11
|
+
return value === "auto" || value === "responses" || value === "chat-completions"
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function parseEndpointOverrides(value: unknown): EndpointOverrides {
|
|
15
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
16
|
+
throw new Error("Routing configuration must be an object with version: 1 and models")
|
|
17
|
+
}
|
|
18
|
+
if (
|
|
19
|
+
!Object.hasOwn(value, "version") ||
|
|
20
|
+
!("version" in value) ||
|
|
21
|
+
value.version !== 1 ||
|
|
22
|
+
!Object.hasOwn(value, "models") ||
|
|
23
|
+
!("models" in value)
|
|
24
|
+
) {
|
|
25
|
+
throw new Error("Unsupported routing configuration version")
|
|
26
|
+
}
|
|
27
|
+
const models = value.models
|
|
28
|
+
if (typeof models !== "object" || models === null || Array.isArray(models)) {
|
|
29
|
+
throw new Error("Routing models must be an object")
|
|
30
|
+
}
|
|
31
|
+
const entries = Object.entries(models)
|
|
32
|
+
if (entries.some(([id, choice]) => !id || id !== id.trim() || !isEndpointChoice(choice))) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
"Routing choices must be auto, responses, or chat-completions with exact model IDs",
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
// fromEntries defines own properties, including __proto__, without mutating the prototype.
|
|
38
|
+
// Explicit auto and an absent entry must have the same status and persistence semantics.
|
|
39
|
+
return Object.fromEntries(
|
|
40
|
+
entries.filter(
|
|
41
|
+
(entry): entry is [string, EndpointChoice] =>
|
|
42
|
+
isEndpointChoice(entry[1]) && entry[1] !== "auto",
|
|
43
|
+
),
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function readRoutingFile(path: string): Promise<Buffer | undefined> {
|
|
48
|
+
try {
|
|
49
|
+
return await readFile(path)
|
|
50
|
+
} catch (error) {
|
|
51
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") return undefined
|
|
52
|
+
// Never surface OS errors, local paths, JSON excerpts, or arbitrary file contents.
|
|
53
|
+
throw new Error("Could not read commandcode-routing.json in the agent directory")
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function loadEndpointOverrides(path: string): Promise<EndpointOverrides> {
|
|
58
|
+
const raw = await readRoutingFile(path)
|
|
59
|
+
if (raw === undefined) return {}
|
|
60
|
+
try {
|
|
61
|
+
return parseEndpointOverrides(JSON.parse(raw.toString("utf8")))
|
|
62
|
+
} catch {
|
|
63
|
+
throw new Error("Invalid commandcode-routing.json in the agent directory")
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function endpointChoiceForModel(
|
|
68
|
+
modelId: string,
|
|
69
|
+
overrides: EndpointOverrides,
|
|
70
|
+
): EndpointChoice {
|
|
71
|
+
return Object.hasOwn(overrides, modelId) ? overrides[modelId] : "auto"
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function resolveEndpoint(
|
|
75
|
+
model: CommandCodeModel,
|
|
76
|
+
overrides: EndpointOverrides,
|
|
77
|
+
): CommandCodeApi {
|
|
78
|
+
const choice = endpointChoiceForModel(model.id, overrides)
|
|
79
|
+
if (choice === "auto") return model.api
|
|
80
|
+
if (model.api === "anthropic-messages") {
|
|
81
|
+
throw new Error("Claude models require Anthropic Messages; use auto")
|
|
82
|
+
}
|
|
83
|
+
if (choice === "responses" && model.api !== "openai-responses") {
|
|
84
|
+
throw new Error(
|
|
85
|
+
"The current catalog does not advertise Responses for this model; refresh the catalog or use auto",
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
return choice === "responses" ? "openai-responses" : "openai-completions"
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Preserve host/user compatibility only when it is tagged for the actual wire.
|
|
92
|
+
* Unknown or stale wire metadata must be replaced, never merged across wires.
|
|
93
|
+
*/
|
|
94
|
+
export function compatForEndpoint<T>(
|
|
95
|
+
model: CommandCodeModel | undefined,
|
|
96
|
+
wire: CommandCodeApi,
|
|
97
|
+
fallback: T,
|
|
98
|
+
forModel: (model: CommandCodeModel) => T,
|
|
99
|
+
): T {
|
|
100
|
+
if (!model) return fallback
|
|
101
|
+
if (
|
|
102
|
+
fallback !== null &&
|
|
103
|
+
typeof fallback === "object" &&
|
|
104
|
+
Object.hasOwn(fallback, "commandCodeWire") &&
|
|
105
|
+
"commandCodeWire" in fallback &&
|
|
106
|
+
fallback.commandCodeWire === wire
|
|
107
|
+
)
|
|
108
|
+
return fallback
|
|
109
|
+
return forModel({ ...model, api: wire })
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Explicit command write only. Startup reads never rewrite or back up the file.
|
|
113
|
+
* A malformed file is preserved before replacement; unreadable files are not overwritten.
|
|
114
|
+
* Writes within one host are serialized by the command; separate hosts are not coordinated.
|
|
115
|
+
*/
|
|
116
|
+
export async function saveEndpointChoice(
|
|
117
|
+
path: string,
|
|
118
|
+
modelId: string,
|
|
119
|
+
choice: EndpointChoice,
|
|
120
|
+
): Promise<{
|
|
121
|
+
overrides: EndpointOverrides
|
|
122
|
+
backupFile?: string
|
|
123
|
+
}> {
|
|
124
|
+
if (!modelId || modelId !== modelId.trim() || !isEndpointChoice(choice)) {
|
|
125
|
+
throw new Error("Invalid endpoint choice or model ID")
|
|
126
|
+
}
|
|
127
|
+
const raw = await readRoutingFile(path)
|
|
128
|
+
let overrides: Record<string, EndpointChoice> = {}
|
|
129
|
+
let invalid = false
|
|
130
|
+
if (raw !== undefined) {
|
|
131
|
+
try {
|
|
132
|
+
overrides = { ...parseEndpointOverrides(JSON.parse(raw.toString("utf8"))) }
|
|
133
|
+
} catch {
|
|
134
|
+
invalid = true
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (choice === "auto") delete overrides[modelId]
|
|
138
|
+
else
|
|
139
|
+
Object.defineProperty(overrides, modelId, {
|
|
140
|
+
value: choice,
|
|
141
|
+
enumerable: true,
|
|
142
|
+
configurable: true,
|
|
143
|
+
writable: true,
|
|
144
|
+
})
|
|
145
|
+
const temporary = `${path}.${randomUUID()}.tmp`
|
|
146
|
+
const backup = invalid ? `${path}.invalid-${randomUUID()}.bak` : undefined
|
|
147
|
+
try {
|
|
148
|
+
await mkdir(dirname(path), { recursive: true })
|
|
149
|
+
await writeFile(temporary, JSON.stringify({ version: 1, models: overrides }, null, 2) + "\n", {
|
|
150
|
+
encoding: "utf8",
|
|
151
|
+
mode: 0o600,
|
|
152
|
+
flag: "wx",
|
|
153
|
+
})
|
|
154
|
+
// If the backup fails, leave the original file untouched and do not install the new one.
|
|
155
|
+
if (backup && raw !== undefined) await writeFile(backup, raw, { mode: 0o600, flag: "wx" })
|
|
156
|
+
await rename(temporary, path)
|
|
157
|
+
return { overrides, ...(backup ? { backupFile: basename(backup) } : {}) }
|
|
158
|
+
} catch {
|
|
159
|
+
throw new Error(
|
|
160
|
+
"Could not save commandcode-routing.json in the agent directory; check file permissions",
|
|
161
|
+
)
|
|
162
|
+
} finally {
|
|
163
|
+
// Cleanup must not replace the sanitized error with an OS message containing local paths.
|
|
164
|
+
await rm(temporary, { force: true }).catch(() => {})
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -8,6 +8,8 @@ export interface CommandCodeUi {
|
|
|
8
8
|
export interface CommandCodeCommandContext {
|
|
9
9
|
ui: CommandCodeUi
|
|
10
10
|
waitForIdle?: () => Promise<void>
|
|
11
|
+
/** Currently selected model, when the host exposes one to command handlers. */
|
|
12
|
+
model?: { provider: string; id: string }
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
export interface CommandCodeRuntimeApi<
|
|
@@ -31,21 +33,17 @@ export interface CommandCodeRuntimeOptions<TProviderConfig> {
|
|
|
31
33
|
/** Cached catalog only; resolves to an empty list when no valid cache exists. */
|
|
32
34
|
loadCachedModels: () => Promise<readonly CommandCodeModel[]>
|
|
33
35
|
createProviderConfig: (models: readonly CommandCodeModel[]) => TProviderConfig
|
|
34
|
-
getTransport?: () => "unknown" | "provider"
|
|
35
|
-
/**
|
|
36
|
-
* Forget the probed transport so the next request re-tries the Provider API.
|
|
37
|
-
* Called by `/commandcode-refresh`, the user's explicit "re-check my
|
|
38
|
-
* account" action, since an account upgraded from Go stays on the generate
|
|
39
|
-
* fallback until the key changes or the host restarts.
|
|
40
|
-
*/
|
|
36
|
+
getTransport?: () => "unknown" | "provider"
|
|
37
|
+
/** Reset the latest transport status on an explicit catalog refresh. */
|
|
41
38
|
resetTransport?: () => void
|
|
39
|
+
getDiagnostics?: (model: CommandCodeCommandContext["model"]) => string
|
|
42
40
|
getStreamWarning?: () => string | undefined
|
|
43
41
|
now?: () => number
|
|
44
42
|
logWarning?: (message: string) => void
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
export interface CommandCodeRuntimeStatus {
|
|
48
|
-
transport: "unknown" | "provider"
|
|
46
|
+
transport: "unknown" | "provider"
|
|
49
47
|
source: LoadCommandCodeModelsResult["source"]
|
|
50
48
|
modelCount: number
|
|
51
49
|
lastSuccess?: number
|
|
@@ -293,6 +291,12 @@ export class CommandCodeRuntime<TProviderConfig, TContext extends CommandCodeCom
|
|
|
293
291
|
}
|
|
294
292
|
|
|
295
293
|
private registerCommands(): void {
|
|
294
|
+
this.pi.registerCommand("commandcode-diagnostics", {
|
|
295
|
+
description: "Show a content-free support report (no prompts, keys or local paths)",
|
|
296
|
+
handler: async (_args, ctx) => {
|
|
297
|
+
ctx.ui.notify(this.options.getDiagnostics?.(ctx.model) ?? "Diagnostics unavailable", "info")
|
|
298
|
+
},
|
|
299
|
+
})
|
|
296
300
|
this.pi.registerCommand("commandcode-refresh", {
|
|
297
301
|
description: "Refresh the Command Code model catalog",
|
|
298
302
|
handler: async (_args, ctx) => {
|
|
@@ -318,7 +322,9 @@ export class CommandCodeRuntime<TProviderConfig, TContext extends CommandCodeCom
|
|
|
318
322
|
handler: async (_args, ctx) => {
|
|
319
323
|
const status = this.getStatus()
|
|
320
324
|
ctx.ui.notify(
|
|
321
|
-
formatCommandCodeStatus(status),
|
|
325
|
+
[formatCommandCodeStatus(status), this.options.getDiagnostics?.(ctx.model)]
|
|
326
|
+
.filter(Boolean)
|
|
327
|
+
.join("\n"),
|
|
322
328
|
status.warning || status.streamWarning ? "warning" : "info",
|
|
323
329
|
)
|
|
324
330
|
},
|