chainlesschain 0.162.124 → 0.162.125
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/package.json +1 -1
- package/src/assets/web-panel/.build-hash +1 -1
- package/src/assets/web-panel/assets/AIOps-DcqNhZhA.js +1 -0
- package/src/assets/web-panel/assets/{ActionButton-COjZZKWG.js → ActionButton-BigtmPoq.js} +1 -1
- package/src/assets/web-panel/assets/{Analytics-4ZDZE7lc.js → Analytics-1J_X_HF4.js} +3 -3
- package/src/assets/web-panel/assets/{AppLayout-CYH5k2Rp.js → AppLayout-DlcDG_a_.js} +5 -5
- package/src/assets/web-panel/assets/Audit-Do-y8_3w.js +1 -0
- package/src/assets/web-panel/assets/{Backup-CiX61Qc2.js → Backup-S2Df-50Y.js} +1 -1
- package/src/assets/web-panel/assets/{BaseInput-CDxIQokd.js → BaseInput-D5kgWJfk.js} +1 -1
- package/src/assets/web-panel/assets/{Chat-CaKgdRab.js → Chat-aUcp3kN1.js} +5 -5
- package/src/assets/web-panel/assets/ChatBubbleRenderer-Pg7dIsiE.js +1 -0
- package/src/assets/web-panel/assets/{Checkbox-CjiWfu4s.js → Checkbox-DTg1U7Xs.js} +1 -1
- package/src/assets/web-panel/assets/Codegen-YO9ZZ4Ky.js +1 -0
- package/src/assets/web-panel/assets/{Col-ZKWREyNs.js → Col-BHonE9fU.js} +1 -1
- package/src/assets/web-panel/assets/Community-DA2AlEFh.js +1 -0
- package/src/assets/web-panel/assets/{Compact-DqknM98n.js → Compact-DULxLRNg.js} +1 -1
- package/src/assets/web-panel/assets/Compliance-BZqfuuZL.js +1 -0
- package/src/assets/web-panel/assets/{Cowork-Dp29kHsC.js → Cowork-CJe3vyMS.js} +2 -2
- package/src/assets/web-panel/assets/{Cron-zmEJAetz.js → Cron-CeV8AtRu.js} +2 -2
- package/src/assets/web-panel/assets/Crosschain-CAg66zS5.js +1 -0
- package/src/assets/web-panel/assets/{DID-D_UFNzJ5.js → DID-Dtup5JZm.js} +2 -2
- package/src/assets/web-panel/assets/Dashboard-DAR_8PNy.js +3 -0
- package/src/assets/web-panel/assets/{Dropdown-CH7l3KCs.js → Dropdown-K5bTaCYN.js} +1 -1
- package/src/assets/web-panel/assets/{EmailListRenderer-Bud2M3XX.js → EmailListRenderer-C890uErx.js} +1 -1
- package/src/assets/web-panel/assets/{FamilyGuardDashboard-Bd2_8uME.js → FamilyGuardDashboard-B-Tj_8yM.js} +1 -1
- package/src/assets/web-panel/assets/Federation-C6WZ98ni.js +1 -0
- package/src/assets/web-panel/assets/{FormItemContext-CpSH464Y.js → FormItemContext-D-LTfGWd.js} +1 -1
- package/src/assets/web-panel/assets/{GenericCardRenderer-CANo8O-y.js → GenericCardRenderer-C80DK4W7.js} +1 -1
- package/src/assets/web-panel/assets/{Git-hvuZVoD3.js → Git-Cjvvv3zW.js} +2 -2
- package/src/assets/web-panel/assets/Governance-C0BND77H.js +1 -0
- package/src/assets/web-panel/assets/Inference-BL9kTtSu.js +1 -0
- package/src/assets/web-panel/assets/KnowledgeGraph-CnVTBmJf.js +1 -0
- package/src/assets/web-panel/assets/{Logs-DDkTnedu.js → Logs-CbCbg7K6.js} +2 -2
- package/src/assets/web-panel/assets/Marketplace-CG5On-fH.js +1 -0
- package/src/assets/web-panel/assets/{McpTools-Qx78XyOT.js → McpTools-AYYDZZK7.js} +5 -5
- package/src/assets/web-panel/assets/{Memory-CXYDO1oT.js → Memory-tMWbMDQq.js} +2 -2
- package/src/assets/web-panel/assets/MobileBridge-BAOsf4wB.js +1 -0
- package/src/assets/web-panel/assets/{MobileProjects-DEDbWNIk.js → MobileProjects-BT-2komQ.js} +1 -1
- package/src/assets/web-panel/assets/{Mtc-Dwa_vlR8.js → Mtc-BFwfC63n.js} +5 -5
- package/src/assets/web-panel/assets/{MtcAudit-DAVkxhJv.js → MtcAudit-DYG3CWdH.js} +4 -4
- package/src/assets/web-panel/assets/{Multisig-C3upmgPN.js → Multisig-KJwd0yWT.js} +3 -3
- package/src/assets/web-panel/assets/NLProgramming-BmL5dNWm.js +1 -0
- package/src/assets/web-panel/assets/{Notes-B1Oy3FbC.js → Notes-DmkaVaMc.js} +4 -4
- package/src/assets/web-panel/assets/{NotificationSettings-Bs4-Fc6b.js → NotificationSettings-tmVQszDZ.js} +1 -1
- package/src/assets/web-panel/assets/{OrderTableRenderer-CEy1pIeq.js → OrderTableRenderer-BtrR7anf.js} +1 -1
- package/src/assets/web-panel/assets/{Organization-D4cJ1UNo.js → Organization-pppktQyW.js} +4 -4
- package/src/assets/web-panel/assets/{Overflow-fdzvlF7x.js → Overflow-D3lBoQDA.js} +1 -1
- package/src/assets/web-panel/assets/{P2P-Y13PwXBA.js → P2P-BgE2qGlZ.js} +2 -2
- package/src/assets/web-panel/assets/PdhVaultBrowser-D26Bz5gS.js +7 -0
- package/src/assets/web-panel/assets/{Permissions-CvEXP6LC.js → Permissions-BR8no2Xe.js} +3 -3
- package/src/assets/web-panel/assets/{PersonalDataHub-JeP7IWMW.js → PersonalDataHub-DabbyQEF.js} +3 -3
- package/src/assets/web-panel/assets/Pipeline-n4sNpEz8.js +1 -0
- package/src/assets/web-panel/assets/Privacy-CGNp4n8M.js +1 -0
- package/src/assets/web-panel/assets/{ProjectInit-DeWd9UcS.js → ProjectInit-CAVA5VsX.js} +2 -2
- package/src/assets/web-panel/assets/{ProjectSettings-DUpVuU9F.js → ProjectSettings-GCgkfM7A.js} +2 -2
- package/src/assets/web-panel/assets/Projects-BYK17p52.js +1 -0
- package/src/assets/web-panel/assets/{Providers-DECW00ek.js → Providers-DpUT5W-d.js} +1 -1
- package/src/assets/web-panel/assets/{QuickAsk-Dl-pK9Io.js → QuickAsk-ZJxTb7vi.js} +1 -1
- package/src/assets/web-panel/assets/Recommend-CIzFRDk1.js +1 -0
- package/src/assets/web-panel/assets/Reputation-lQ_WDNZn.js +1 -0
- package/src/assets/web-panel/assets/Row-1MEtrgtF.js +1 -0
- package/src/assets/web-panel/assets/{RssFeed-iyQT5q9l.js → RssFeed-SSgcPPl4.js} +3 -3
- package/src/assets/web-panel/assets/Search-CcTMOGNY.js +1 -0
- package/src/assets/web-panel/assets/{Security-c4Jxf5Ih.js → Security-BA1KMaDx.js} +4 -4
- package/src/assets/web-panel/assets/{Services-CRuisolj.js → Services-_aj7czZn.js} +2 -2
- package/src/assets/web-panel/assets/{Skeleton-CCnzJkb-.js → Skeleton-BWgg_0Zr.js} +1 -1
- package/src/assets/web-panel/assets/{Skills-CZURCwZg.js → Skills-C2ZIziYM.js} +1 -1
- package/src/assets/web-panel/assets/Sla-CYxp4axY.js +1 -0
- package/src/assets/web-panel/assets/SpeechSettings-C7Csp1jV.js +1 -0
- package/src/assets/web-panel/assets/{SyncSettings-CJWVtd87.js → SyncSettings-svGeswiw.js} +2 -2
- package/src/assets/web-panel/assets/{Tasks-61lrQ_lS.js → Tasks-ClISj6oK.js} +1 -1
- package/src/assets/web-panel/assets/Templates-CmO-Fp7r.js +1 -0
- package/src/assets/web-panel/assets/Tenant-a3Ac3lxz.js +1 -0
- package/src/assets/web-panel/assets/{Terminal-CP15hcNS.js → Terminal-DyJIRh81.js} +2 -2
- package/src/assets/web-panel/assets/TimelineRenderer-acXS5N5h.js +1 -0
- package/src/assets/web-panel/assets/Tokens-DJW0KqV4.js +1 -0
- package/src/assets/web-panel/assets/{Trigger-BLCQEOF2.js → Trigger-0HeTi4r6.js} +1 -1
- package/src/assets/web-panel/assets/Trust-aFym34eo.js +1 -0
- package/src/assets/web-panel/assets/{UkeySign-Dwp0zXQ6.js → UkeySign-CYhszHJv.js} +1 -1
- package/src/assets/web-panel/assets/{VideoEditing-CIHA55Sx.js → VideoEditing-BbJxPF9X.js} +1 -1
- package/src/assets/web-panel/assets/{Wallet-Hjajvnto.js → Wallet-DDthEwiu.js} +3 -3
- package/src/assets/web-panel/assets/{WebAuthn-DqSURUvI.js → WebAuthn-DQ6McYPg.js} +4 -4
- package/src/assets/web-panel/assets/{WorkflowEditor-B5bHRwUG.js → WorkflowEditor-CnF8zRsi.js} +1 -1
- package/src/assets/web-panel/assets/{chat-DsheLKkG.js → chat-Dzkx2gTP.js} +1 -1
- package/src/assets/web-panel/assets/{colors-CST2UkgL.js → colors-35T51Oo5.js} +1 -1
- package/src/assets/web-panel/assets/{compact-item-yqEoy1L7.js → compact-item-TtzNrlu1.js} +1 -1
- package/src/assets/web-panel/assets/{createContext-Jwp78HFY.js → createContext-Y1LkWrYb.js} +1 -1
- package/src/assets/web-panel/assets/devWarning-D_lwLZ6O.js +1 -0
- package/src/assets/web-panel/assets/{hasIn-CVS5mFEP.js → hasIn-BOYw1BgS.js} +1 -1
- package/src/assets/web-panel/assets/{index-Crk4KWLW.js → index-8jffdb6b.js} +1 -1
- package/src/assets/web-panel/assets/{index-CDAPnZUs.js → index-B7aKAZzS.js} +1 -1
- package/src/assets/web-panel/assets/index-BGPEaeB1.js +1 -0
- package/src/assets/web-panel/assets/index-BKRlWHUp.js +1 -0
- package/src/assets/web-panel/assets/{index-BCHAUdel.js → index-BSpFe6j5.js} +1 -1
- package/src/assets/web-panel/assets/{index-Cjig5i3a.js → index-BWgNn9As.js} +28 -26
- package/src/assets/web-panel/assets/{index-Dxljh9Fu.js → index-Bs69SI96.js} +2 -2
- package/src/assets/web-panel/assets/{index-BLTUVd0V.js → index-BtlJWaSP.js} +2 -2
- package/src/assets/web-panel/assets/index-Bw1iOGhM.js +1 -0
- package/src/assets/web-panel/assets/{index-CjfN2CpJ.js → index-BxWUEFKy.js} +1 -1
- package/src/assets/web-panel/assets/index-C7Wt5feN.js +1 -0
- package/src/assets/web-panel/assets/index-CEwuCM44.js +1 -0
- package/src/assets/web-panel/assets/index-CLqC2sRT.js +3 -0
- package/src/assets/web-panel/assets/{index-Dgyn8-wN.js → index-CPGNc2tF.js} +2 -2
- package/src/assets/web-panel/assets/{index-AnW25bEq.js → index-CVrUs6rf.js} +1 -1
- package/src/assets/web-panel/assets/index-CZ16GlOs.js +1 -0
- package/src/assets/web-panel/assets/{index-Cy0dNzkp.js → index-CdyFg4FI.js} +1 -1
- package/src/assets/web-panel/assets/{index-C0FZScMe.js → index-CqhwG1ox.js} +4 -4
- package/src/assets/web-panel/assets/index-Cs82BHAj.js +1 -0
- package/src/assets/web-panel/assets/{index-CRBbVS43.js → index-D2od7Bgx.js} +1 -1
- package/src/assets/web-panel/assets/{index-DxaU_lza.js → index-D47robkX.js} +1 -1
- package/src/assets/web-panel/assets/{index-CSBPc-sI.js → index-D4BgCBa3.js} +2 -2
- package/src/assets/web-panel/assets/index-D6tG4B25.js +55 -0
- package/src/assets/web-panel/assets/index-D7dCBw_M.js +1 -0
- package/src/assets/web-panel/assets/index-DAizH273.js +21 -0
- package/src/assets/web-panel/assets/{index-CzsKK0tQ.js → index-DFhlelzN.js} +2 -2
- package/src/assets/web-panel/assets/index-DhMSOd_2.js +1 -0
- package/src/assets/web-panel/assets/index-Dhfw-BXs.js +12 -0
- package/src/assets/web-panel/assets/index-DjeUZxE5.js +1 -0
- package/src/assets/web-panel/assets/{index-DDAigsel.js → index-DmkG479D.js} +2 -2
- package/src/assets/web-panel/assets/index-Dof7lWA_.js +13 -0
- package/src/assets/web-panel/assets/{index-De600Jjm.js → index-Dx0hIfC-.js} +1 -1
- package/src/assets/web-panel/assets/index-DzzgU4IU.js +1 -0
- package/src/assets/web-panel/assets/index-G4ClSmJc.js +1 -0
- package/src/assets/web-panel/assets/{index-CtyEOGuj.js → index-KgXrlfNF.js} +1 -1
- package/src/assets/web-panel/assets/{index-SjxCCf5h.js → index-NM9Oke2k.js} +2 -2
- package/src/assets/web-panel/assets/{index-R-VGFpi6.js → index-XIuZV9by.js} +3 -3
- package/src/assets/web-panel/assets/{index-BzetOasL.js → index-hyqEKkBT.js} +1 -1
- package/src/assets/web-panel/assets/{index-BuI27WSx.js → index-zF77jnI2.js} +2 -2
- package/src/assets/web-panel/assets/{initDefaultProps-ClAjrsQ-.js → initDefaultProps-DD5y5msp.js} +1 -1
- package/src/assets/web-panel/assets/motion-BuoutMia.js +11 -0
- package/src/assets/web-panel/assets/{move-DMelzIW-.js → move-DkpjqOXg.js} +1 -1
- package/src/assets/web-panel/assets/mtc-parser-BmGJD-v-.js +1 -0
- package/src/assets/web-panel/assets/{omit-oxecfU3b.js → omit-DftUE0Sz.js} +1 -1
- package/src/assets/web-panel/assets/{pickAttrs-DJ5F5M6x.js → pickAttrs-DDRb9FIu.js} +1 -1
- package/src/assets/web-panel/assets/{placementArrow-DdbKsant.js → placementArrow-DPgtxOOD.js} +1 -1
- package/src/assets/web-panel/assets/{responsiveObserve-BUuM5cmS.js → responsiveObserve-BQFRzFeZ.js} +1 -1
- package/src/assets/web-panel/assets/{slide-DSV0ccvR.js → slide-DQ4lmUSz.js} +1 -1
- package/src/assets/web-panel/assets/{statusUtils-B-6oLAXf.js → statusUtils-C1TR4ZiQ.js} +1 -1
- package/src/assets/web-panel/assets/{styleChecker-DdCAHtsZ.js → styleChecker-B-Suj978.js} +1 -1
- package/src/assets/web-panel/assets/{useFlexGapSupport-ZORkcoZd.js → useFlexGapSupport-Q7bDZ3EI.js} +1 -1
- package/src/assets/web-panel/assets/{useFs-BFp46LoP.js → useFs-DHjRLyQH.js} +1 -1
- package/src/assets/web-panel/assets/{usePersonalDataHub-H7rxgbdW.js → usePersonalDataHub-lQOvCvCr.js} +1 -1
- package/src/assets/web-panel/assets/{vnode-eIq4Tk0J.js → vnode-Ie0g4-p3.js} +1 -1
- package/src/assets/web-panel/assets/{zoom-CTNrv8-H.js → zoom-CHP0YEoH.js} +1 -1
- package/src/assets/web-panel/index.html +1 -1
- package/src/commands/agent.js +10 -0
- package/src/commands/ide.js +60 -5
- package/src/commands/incentive.js +22 -22
- package/src/commands/mtc.js +5 -1
- package/src/gateways/ws/message-dispatcher.js +4 -1
- package/src/gateways/ws/ws-session-gateway.js +56 -4
- package/src/harness/background-task-manager.js +5 -1
- package/src/harness/jsonl-session-store.js +51 -0
- package/src/harness/mcp-client.js +62 -21
- package/src/harness/prompt-compressor.js +24 -5
- package/src/harness/worktree-isolator.js +5 -1
- package/src/lib/agent-core.js +1 -0
- package/src/lib/autonomous-agent.js +29 -0
- package/src/lib/chat-intent-service.js +14 -2
- package/src/lib/checkpoint-store.js +31 -4
- package/src/lib/claude-code-bridge.js +48 -3
- package/src/lib/cost-budget.js +13 -2
- package/src/lib/credential-guard.js +38 -0
- package/src/lib/git-integration.js +11 -2
- package/src/lib/goal-store.js +11 -0
- package/src/lib/hook-manager.js +4 -0
- package/src/lib/jetbrains-bridge.js +147 -0
- package/src/lib/jsonl-session-store.js +1 -0
- package/src/lib/llm-pricing.js +11 -4
- package/src/lib/llm-providers.js +11 -1
- package/src/lib/mcp-oauth.js +12 -0
- package/src/lib/mcp-serve.js +29 -0
- package/src/lib/orchestrator.js +38 -2
- package/src/lib/repl-bang-memorize.js +9 -1
- package/src/lib/runnable-provider.js +7 -1
- package/src/lib/session-insights.js +13 -6
- package/src/lib/session-usage.js +21 -3
- package/src/lib/status-line.cjs +4 -1
- package/src/lib/sub-agent-context.js +9 -0
- package/src/repl/agent-repl.js +29 -0
- package/src/runtime/agent-core.js +4 -2
- package/src/runtime/headless-runner.js +13 -0
- package/src/runtime/headless-stream.js +9 -0
- package/src/runtime/mcp-config.js +72 -3
- package/src/runtime/pipe-safety.js +51 -0
- package/src/runtime/policies/agent-policy.js +3 -0
- package/src/assets/web-panel/assets/AIOps-BsDJlD_l.js +0 -1
- package/src/assets/web-panel/assets/Audit-BKlFbLdl.js +0 -1
- package/src/assets/web-panel/assets/ChatBubbleRenderer-DgvpwU5o.js +0 -1
- package/src/assets/web-panel/assets/Codegen-tKWGzajw.js +0 -1
- package/src/assets/web-panel/assets/Community-CmLuPBUU.js +0 -1
- package/src/assets/web-panel/assets/Compliance-PZw0aBLI.js +0 -1
- package/src/assets/web-panel/assets/Crosschain-Sb-uM7Ty.js +0 -1
- package/src/assets/web-panel/assets/Dashboard-Btag698v.js +0 -3
- package/src/assets/web-panel/assets/Federation-1jhstF5P.js +0 -1
- package/src/assets/web-panel/assets/Governance-BQrWksKt.js +0 -1
- package/src/assets/web-panel/assets/Inference-jEBTp12v.js +0 -1
- package/src/assets/web-panel/assets/KnowledgeGraph-tDiV2taf.js +0 -1
- package/src/assets/web-panel/assets/Marketplace-9Yi32avt.js +0 -1
- package/src/assets/web-panel/assets/MobileBridge-MfUfkHA0.js +0 -1
- package/src/assets/web-panel/assets/NLProgramming-DO3CZ0_z.js +0 -1
- package/src/assets/web-panel/assets/PdhVaultBrowser-Ck1zCLe6.js +0 -7
- package/src/assets/web-panel/assets/Pipeline-BZ7wRzG1.js +0 -1
- package/src/assets/web-panel/assets/Privacy-BJ6qj9Hv.js +0 -1
- package/src/assets/web-panel/assets/Projects-y1WbI337.js +0 -1
- package/src/assets/web-panel/assets/Recommend-Bju04wTd.js +0 -1
- package/src/assets/web-panel/assets/Reputation-BUPa3nEk.js +0 -1
- package/src/assets/web-panel/assets/Row-WYqqaq_5.js +0 -1
- package/src/assets/web-panel/assets/Search-CrfwJF0R.js +0 -1
- package/src/assets/web-panel/assets/Sla-CrMzaEi2.js +0 -1
- package/src/assets/web-panel/assets/SpeechSettings-jTDOM5eY.js +0 -1
- package/src/assets/web-panel/assets/Templates-Cg-iF2g1.js +0 -1
- package/src/assets/web-panel/assets/Tenant-DrDv1FFc.js +0 -1
- package/src/assets/web-panel/assets/TimelineRenderer-Sl5uXrkN.js +0 -1
- package/src/assets/web-panel/assets/Tokens-yRIZTVsR.js +0 -1
- package/src/assets/web-panel/assets/Trust-D5xq8z6s.js +0 -1
- package/src/assets/web-panel/assets/community-parser-Cuyslaku.js +0 -3
- package/src/assets/web-panel/assets/devWarning-C8to6gQk.js +0 -1
- package/src/assets/web-panel/assets/index-BeblNJDH.js +0 -1
- package/src/assets/web-panel/assets/index-C130LLPq.js +0 -1
- package/src/assets/web-panel/assets/index-C8rq85gu.js +0 -1
- package/src/assets/web-panel/assets/index-CIE2n8k_.js +0 -1
- package/src/assets/web-panel/assets/index-CTd3lDxp.js +0 -13
- package/src/assets/web-panel/assets/index-CUWj5L2s.js +0 -1
- package/src/assets/web-panel/assets/index-ChRL6rgA.js +0 -3
- package/src/assets/web-panel/assets/index-CrlRa054.js +0 -1
- package/src/assets/web-panel/assets/index-Cu6Ql64n.js +0 -1
- package/src/assets/web-panel/assets/index-Cx_t5rWw.js +0 -12
- package/src/assets/web-panel/assets/index-DZfnYE6e.js +0 -1
- package/src/assets/web-panel/assets/index-D_1b7uh6.js +0 -55
- package/src/assets/web-panel/assets/index-D_e9gwfn.js +0 -1
- package/src/assets/web-panel/assets/index-DbxAlpPC.js +0 -21
- package/src/assets/web-panel/assets/index-DiK4vSZa.js +0 -1
- package/src/assets/web-panel/assets/index-DpYn5v2k.js +0 -1
- package/src/assets/web-panel/assets/index-diWkx2Wq.js +0 -1
- package/src/assets/web-panel/assets/motion-BalXv_60.js +0 -11
- package/src/assets/web-panel/assets/mtc-parser-CEQffxds.js +0 -1
|
@@ -76,9 +76,19 @@ function gitDir(root) {
|
|
|
76
76
|
return path.resolve(root, git(["rev-parse", "--git-dir"], { cwd: root }));
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
/**
|
|
79
|
+
/**
|
|
80
|
+
* Ref-safe session segment. Beyond the charset filter, enforce git's per-
|
|
81
|
+
* component ref rules so a legit-looking name never makes every checkpoint op
|
|
82
|
+
* throw: a component may not begin with `.`, contain `..`, or end with `.lock`
|
|
83
|
+
* (`/` is already collapsed to `-`, so the session is always a single segment
|
|
84
|
+
* and cannot traverse the ref namespace).
|
|
85
|
+
*/
|
|
80
86
|
function sanitizeSession(session) {
|
|
81
|
-
|
|
87
|
+
let s = String(session || "default").replace(/[^A-Za-z0-9._-]/g, "-");
|
|
88
|
+
s = s.replace(/\.{2,}/g, "."); // git forbids ".." in a refname
|
|
89
|
+
s = s.replace(/^\.+/, ""); // a component may not begin with "."
|
|
90
|
+
s = s.replace(/\.lock$/i, "-lock"); // nor end with ".lock"
|
|
91
|
+
s = s.replace(/\.+$/, ""); // nor end with a dot
|
|
82
92
|
return s || "default";
|
|
83
93
|
}
|
|
84
94
|
|
|
@@ -86,9 +96,20 @@ function sessionPrefix(session) {
|
|
|
86
96
|
return `${REF_NS}/${sanitizeSession(session)}`;
|
|
87
97
|
}
|
|
88
98
|
|
|
99
|
+
// Monotonic per-process counter so two temp-index paths minted in the same
|
|
100
|
+
// millisecond never collide. pid disambiguates across processes; Date.now() +
|
|
101
|
+
// this counter disambiguate within one. A collision would mean two operations
|
|
102
|
+
// sharing one GIT_INDEX_FILE (corrupt snapshot) or one's cleanup deleting the
|
|
103
|
+
// other's live index.
|
|
104
|
+
let _indexSeq = 0;
|
|
105
|
+
|
|
89
106
|
/** Unique temp index path inside .git (never the real index). */
|
|
90
107
|
function tempIndexPath(dir) {
|
|
91
|
-
|
|
108
|
+
_indexSeq = (_indexSeq + 1) >>> 0;
|
|
109
|
+
return path.join(
|
|
110
|
+
dir,
|
|
111
|
+
`cc-checkpoint-index-${process.pid}-${Date.now()}-${_indexSeq}`,
|
|
112
|
+
);
|
|
92
113
|
}
|
|
93
114
|
|
|
94
115
|
/**
|
|
@@ -580,4 +601,10 @@ export function clearCheckpoints(cwd = process.cwd(), opts = {}) {
|
|
|
580
601
|
}
|
|
581
602
|
|
|
582
603
|
// Exposed for unit tests / advanced callers.
|
|
583
|
-
export const _internals = {
|
|
604
|
+
export const _internals = {
|
|
605
|
+
git,
|
|
606
|
+
repoRoot,
|
|
607
|
+
sanitizeSession,
|
|
608
|
+
snapshotTree,
|
|
609
|
+
tempIndexPath,
|
|
610
|
+
};
|
|
@@ -29,6 +29,13 @@ export const AGENT_STATUS = {
|
|
|
29
29
|
TIMEOUT: "timeout",
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
+
// Bound how much of a child's stdout/stderr we retain in memory. A verbose or
|
|
33
|
+
// runaway `claude -p` can stream unbounded stream-json; without a cap,
|
|
34
|
+
// outputChunks.join("") OOMs the orchestrator. We keep the TAIL (oldest chunks
|
|
35
|
+
// dropped) because stream-json's terminal `result` / last-assistant line — the
|
|
36
|
+
// only thing _parseStreamJson needs — is at the end.
|
|
37
|
+
export const MAX_AGENT_OUTPUT_BYTES = 32 * 1024 * 1024;
|
|
38
|
+
|
|
32
39
|
// ─── Detection ───────────────────────────────────────────────────
|
|
33
40
|
|
|
34
41
|
/**
|
|
@@ -98,6 +105,7 @@ export class ClaudeCodeAgent extends EventEmitter {
|
|
|
98
105
|
context = "",
|
|
99
106
|
allowedTools = null,
|
|
100
107
|
killGraceMs = 3000,
|
|
108
|
+
maxOutputBytes = MAX_AGENT_OUTPUT_BYTES,
|
|
101
109
|
} = options;
|
|
102
110
|
|
|
103
111
|
const fullPrompt = context
|
|
@@ -126,6 +134,19 @@ export class ClaudeCodeAgent extends EventEmitter {
|
|
|
126
134
|
const outDecoder = new TextDecoder("utf-8");
|
|
127
135
|
const errDecoder = new TextDecoder("utf-8");
|
|
128
136
|
let timedOut = false;
|
|
137
|
+
// Tail-bounded byte counters for the two buffers (see MAX_AGENT_OUTPUT_BYTES).
|
|
138
|
+
let outBytes = 0;
|
|
139
|
+
let errBytes = 0;
|
|
140
|
+
let outputTruncated = false;
|
|
141
|
+
// Drop oldest chunks until the buffer is back under the cap, keeping ≥1
|
|
142
|
+
// chunk (the most recent, where the result line lives).
|
|
143
|
+
const trim = (chunks, bytesRef) => {
|
|
144
|
+
let bytes = bytesRef;
|
|
145
|
+
while (bytes > maxOutputBytes && chunks.length > 1) {
|
|
146
|
+
bytes -= Buffer.byteLength(chunks.shift());
|
|
147
|
+
}
|
|
148
|
+
return bytes;
|
|
149
|
+
};
|
|
129
150
|
|
|
130
151
|
const proc = _deps.spawn(this.cliCommand, args, {
|
|
131
152
|
cwd,
|
|
@@ -155,15 +176,26 @@ export class ClaudeCodeAgent extends EventEmitter {
|
|
|
155
176
|
? data
|
|
156
177
|
: outDecoder.decode(data, { stream: true });
|
|
157
178
|
outputChunks.push(chunk);
|
|
179
|
+
outBytes += Buffer.byteLength(chunk);
|
|
180
|
+
if (outBytes > maxOutputBytes) {
|
|
181
|
+
outputTruncated = true;
|
|
182
|
+
outBytes = trim(outputChunks, outBytes);
|
|
183
|
+
}
|
|
184
|
+
// The live `output` event still streams every chunk verbatim — the cap
|
|
185
|
+
// only bounds what we RETAIN for the final rawOutput.
|
|
158
186
|
this.emit("output", { agentId: this.id, chunk });
|
|
159
187
|
});
|
|
160
188
|
|
|
161
189
|
proc.stderr.on("data", (data) => {
|
|
162
|
-
|
|
190
|
+
const chunk =
|
|
163
191
|
typeof data === "string"
|
|
164
192
|
? data
|
|
165
|
-
: errDecoder.decode(data, { stream: true })
|
|
166
|
-
);
|
|
193
|
+
: errDecoder.decode(data, { stream: true });
|
|
194
|
+
errorChunks.push(chunk);
|
|
195
|
+
errBytes += Buffer.byteLength(chunk);
|
|
196
|
+
if (errBytes > maxOutputBytes) {
|
|
197
|
+
errBytes = trim(errorChunks, errBytes);
|
|
198
|
+
}
|
|
167
199
|
});
|
|
168
200
|
|
|
169
201
|
proc.on("close", (code) => {
|
|
@@ -188,6 +220,7 @@ export class ClaudeCodeAgent extends EventEmitter {
|
|
|
188
220
|
success: code === 0 && !timedOut,
|
|
189
221
|
output: parsedOutput || rawOutput.slice(-4000), // last 4K chars fallback
|
|
190
222
|
rawOutput,
|
|
223
|
+
outputTruncated, // true when the child exceeded maxOutputBytes
|
|
191
224
|
exitCode: code,
|
|
192
225
|
duration,
|
|
193
226
|
timedOut,
|
|
@@ -257,6 +290,15 @@ export class ClaudeCodePool extends EventEmitter {
|
|
|
257
290
|
this.model = options.model || null;
|
|
258
291
|
this.agentTimeout = options.agentTimeout || 300_000;
|
|
259
292
|
|
|
293
|
+
// Bound retained completion history. dispatch() returns results directly,
|
|
294
|
+
// so _completed is only a recent-history buffer — but it was an unbounded
|
|
295
|
+
// array, so a long-lived pool dispatching many tasks leaked memory forever.
|
|
296
|
+
// Keep a recent window (FIFO). Default 1000; 0/invalid → 1000.
|
|
297
|
+
this.maxCompleted =
|
|
298
|
+
Number.isFinite(options.maxCompleted) && options.maxCompleted > 0
|
|
299
|
+
? options.maxCompleted
|
|
300
|
+
: 1000;
|
|
301
|
+
|
|
260
302
|
/** @type {Map<string, ClaudeCodeAgent>} */
|
|
261
303
|
this._agents = new Map();
|
|
262
304
|
this._completed = [];
|
|
@@ -315,6 +357,9 @@ export class ClaudeCodePool extends EventEmitter {
|
|
|
315
357
|
|
|
316
358
|
this._agents.delete(agent.id);
|
|
317
359
|
this._completed.push({ ...result, taskId: task.id });
|
|
360
|
+
if (this._completed.length > this.maxCompleted) {
|
|
361
|
+
this._completed.splice(0, this._completed.length - this.maxCompleted);
|
|
362
|
+
}
|
|
318
363
|
|
|
319
364
|
this.emit("agent:complete", { taskId: task.id, ...result });
|
|
320
365
|
return { taskId: task.id, ...result };
|
package/src/lib/cost-budget.js
CHANGED
|
@@ -86,8 +86,19 @@ export class CostBudget {
|
|
|
86
86
|
if (est.free) {
|
|
87
87
|
this.sawFree = true;
|
|
88
88
|
} else if (est.matched) {
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
// Defense-in-depth for a SAFETY control: a non-finite/negative cost (e.g.
|
|
90
|
+
// a malformed price table entry, or a non-numeric token count in a
|
|
91
|
+
// provider's usage event) must NOT poison spentUsd into NaN — `NaN >=
|
|
92
|
+
// limit` is always false, which would silently DISABLE the hard cap and
|
|
93
|
+
// allow unbounded spend on an unattended run. Only fold a clean cost;
|
|
94
|
+
// otherwise treat the record as unpriced.
|
|
95
|
+
const cost = Number(est.totalCost);
|
|
96
|
+
if (Number.isFinite(cost) && cost >= 0) {
|
|
97
|
+
this.spentUsd = round(this.spentUsd + cost);
|
|
98
|
+
this.priced = true;
|
|
99
|
+
} else {
|
|
100
|
+
this.sawUnpriced = true;
|
|
101
|
+
}
|
|
91
102
|
} else if (tokens > 0) {
|
|
92
103
|
this.sawUnpriced = true;
|
|
93
104
|
}
|
|
@@ -25,8 +25,16 @@
|
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
import { createRequire } from "node:module";
|
|
28
|
+
import fsDefault from "node:fs";
|
|
29
|
+
import pathDefault from "node:path";
|
|
28
30
|
|
|
29
31
|
const require_ = createRequire(import.meta.url);
|
|
32
|
+
|
|
33
|
+
// Injectable for tests (realpath of a symlink without touching the real fs).
|
|
34
|
+
export const _deps = {
|
|
35
|
+
realpathSync: fsDefault.realpathSync,
|
|
36
|
+
resolve: pathDefault.resolve,
|
|
37
|
+
};
|
|
30
38
|
// Reuse the shell policy's compound-command splitter (separators + $()/backtick
|
|
31
39
|
// extraction). It is regex-based on separators and leaves backslashes intact,
|
|
32
40
|
// so Windows paths survive (unlike the escaping tokenizer, which strips `\`).
|
|
@@ -108,6 +116,36 @@ export function credentialFileReason(targetPath) {
|
|
|
108
116
|
return null;
|
|
109
117
|
}
|
|
110
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Like credentialFileReason, but also follows a symlink to its real target and
|
|
121
|
+
* re-checks. The name-only guard is bypassable: `read_file({path:"notes.txt"})`
|
|
122
|
+
* where notes.txt → ~/.ssh/id_rsa reads the key while the guard sees only the
|
|
123
|
+
* innocent name. fs.readFileSync follows symlinks, so the guard must too —
|
|
124
|
+
* resolve the real path and re-check its basename/patterns. Falls back to the
|
|
125
|
+
* literal check when the path can't be resolved (non-existent → the read fails
|
|
126
|
+
* anyway, nothing to gate). `cwd` anchors a relative target before realpath.
|
|
127
|
+
*
|
|
128
|
+
* @param {string} targetPath
|
|
129
|
+
* @param {object} [opts] { cwd, deps }
|
|
130
|
+
* @returns {string|null}
|
|
131
|
+
*/
|
|
132
|
+
export function credentialFileReasonResolved(targetPath, opts = {}) {
|
|
133
|
+
const direct = credentialFileReason(targetPath);
|
|
134
|
+
if (direct) return direct;
|
|
135
|
+
const deps = opts.deps || _deps;
|
|
136
|
+
const cwd = opts.cwd || process.cwd();
|
|
137
|
+
try {
|
|
138
|
+
const real = deps.realpathSync(
|
|
139
|
+
deps.resolve(cwd, String(targetPath || ".")),
|
|
140
|
+
);
|
|
141
|
+
const viaLink = credentialFileReason(real);
|
|
142
|
+
if (viaLink) return `${viaLink} (via symlink)`;
|
|
143
|
+
} catch {
|
|
144
|
+
// Unresolvable / non-existent — the read itself would fail; nothing to gate.
|
|
145
|
+
}
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
|
|
111
149
|
// ── secret ENV-VAR + command detection ──────────────────────────────────────
|
|
112
150
|
|
|
113
151
|
// Content-reader commands: when one of these is aimed at a credential file, the
|
|
@@ -188,7 +188,11 @@ export function gitAutoCommit(dir, message) {
|
|
|
188
188
|
message ||
|
|
189
189
|
`auto: ${status.files.length} file(s) changed — ${new Date().toISOString().slice(0, 16)}`;
|
|
190
190
|
|
|
191
|
-
|
|
191
|
+
// Free-text message → argv (no shell) so `$()` / backticks / `;` in a
|
|
192
|
+
// caller-supplied message (e.g. `cc git auto-commit --message …`) can't
|
|
193
|
+
// inject a command. The prior `-m "${msg.replace(/"/g,'\\"')}"` only escaped
|
|
194
|
+
// double quotes — same gap fixed in worktree-isolator / mergeWorktree.
|
|
195
|
+
gitExecArgs(["commit", "-m", commitMsg], dir);
|
|
192
196
|
|
|
193
197
|
const hash = gitExec("rev-parse --short HEAD", dir);
|
|
194
198
|
|
|
@@ -209,12 +213,17 @@ export function gitLog(dir, limit = 10) {
|
|
|
209
213
|
}
|
|
210
214
|
|
|
211
215
|
try {
|
|
216
|
+
// Coerce `limit` to a bounded positive integer before it is interpolated
|
|
217
|
+
// into the shell string — a non-numeric value (`5; rm -rf ~`) would
|
|
218
|
+
// otherwise inject. The only in-tree caller already passes an int; this is
|
|
219
|
+
// defense-in-depth at the exported boundary.
|
|
220
|
+
const n = Math.min(10000, Math.max(1, Number.parseInt(limit, 10) || 10));
|
|
212
221
|
// Subject (%s) is free text that often contains "|"; keep it LAST so a
|
|
213
222
|
// pipe in the subject can't shift the date/author fields, then re-join the
|
|
214
223
|
// remainder. (Field order kept as %X|%X — Windows cmd.exe expands adjacent
|
|
215
224
|
// %VAR% pairs, so a control-char separator like %x1f is not portable here.)
|
|
216
225
|
const output = gitExec(
|
|
217
|
-
`log --oneline --no-decorate -${
|
|
226
|
+
`log --oneline --no-decorate -${n} --format="%H|%h|%ai|%an|%s"`,
|
|
218
227
|
dir,
|
|
219
228
|
);
|
|
220
229
|
return output
|
package/src/lib/goal-store.js
CHANGED
|
@@ -124,6 +124,13 @@ export function createGoal(input = {}, opts = {}) {
|
|
|
124
124
|
throw new Error("createGoal requires an objective");
|
|
125
125
|
}
|
|
126
126
|
const id = input.id || newId("goal");
|
|
127
|
+
// Generated ids are always safe, but `input.id` is caller-supplied — guard it
|
|
128
|
+
// like every other op (getGoal/saveGoal/deleteGoal) so a crafted id such as
|
|
129
|
+
// `../../etc/x` can't make atomicWriteFileSync write a .json OUTSIDE the
|
|
130
|
+
// goals dir. createGoal was the one mutation missing this check.
|
|
131
|
+
if (isUnsafeGoalId(id)) {
|
|
132
|
+
throw new Error(`非法 goal id: ${String(id).slice(0, 60)}`);
|
|
133
|
+
}
|
|
127
134
|
const keyResults = (input.keyResults || []).map((kr) => normalizeKr(kr));
|
|
128
135
|
const goal = {
|
|
129
136
|
id,
|
|
@@ -207,6 +214,10 @@ function mutate(id, fn, opts = {}) {
|
|
|
207
214
|
// sharing the goals dir) so concurrent goal edits don't lose an update.
|
|
208
215
|
// Best-effort lock (with-file-lock): on contention timeout it proceeds anyway,
|
|
209
216
|
// so the CLI never hangs.
|
|
217
|
+
// Guard before deriving the lock path: an unsafe id would otherwise place the
|
|
218
|
+
// lock file at a traversal path (`<root>/../../x.json.lock`) before getGoal
|
|
219
|
+
// even runs. getGoal/saveGoal also guard, but keep the lock inside the dir.
|
|
220
|
+
if (isUnsafeGoalId(id)) throw new Error(`no such goal: ${id}`);
|
|
210
221
|
const root = opts.root || defaultRoot();
|
|
211
222
|
return withFileLock(goalFile(root, id), () => {
|
|
212
223
|
const goal = getGoal(id, opts);
|
package/src/lib/hook-manager.js
CHANGED
|
@@ -285,6 +285,10 @@ export async function executeHook(hook, context = {}) {
|
|
|
285
285
|
const output = execSync(cmd, {
|
|
286
286
|
encoding: "utf-8",
|
|
287
287
|
timeout: hook.timeout || 5000,
|
|
288
|
+
// execSync defaults maxBuffer to 1 MB; a hook that prints more (a
|
|
289
|
+
// linter/build dumping output) would throw ENOBUFS and be reported as a
|
|
290
|
+
// FAILURE even though it succeeded. Give hook output generous headroom.
|
|
291
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
288
292
|
env,
|
|
289
293
|
});
|
|
290
294
|
const executionTime = Date.now() - start;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JetBrains / IntelliJ IDEA built-in MCP discovery (cc-side).
|
|
3
|
+
*
|
|
4
|
+
* IntelliJ IDEA 2025.2+ ships a built-in MCP server (Settings | Tools | MCP
|
|
5
|
+
* Server) exposing the IDE's own indexed operations (find usages, file-by-path,
|
|
6
|
+
* search, run configs, VCS, …). Letting the agent call those instead of reading
|
|
7
|
+
* and grepping files itself is cheaper (fewer tokens) and faster (rides the IDE
|
|
8
|
+
* index) — that is the whole point of this bridge.
|
|
9
|
+
*
|
|
10
|
+
* Unlike our own ide/pdh bridges (ide-bridge.js / pdh-bridge.js), IDEA writes NO
|
|
11
|
+
* discovery lockfile, so cc cannot scan for it. Instead the ChainlessChain
|
|
12
|
+
* JetBrains plugin — which runs INSIDE the IDE and therefore knows whether MCP
|
|
13
|
+
* is supported (IDE >= 2025.2) and enabled, and on which endpoint — injects the
|
|
14
|
+
* exact endpoint into the env of the `cc agent` it spawns:
|
|
15
|
+
*
|
|
16
|
+
* CHAINLESSCHAIN_JETBRAINS_MCP_URL http://127.0.0.1:<port>/<path>
|
|
17
|
+
* CHAINLESSCHAIN_JETBRAINS_TOKEN optional bearer token
|
|
18
|
+
* CHAINLESSCHAIN_JETBRAINS_TRANSPORT optional: http | https | sse (else inferred)
|
|
19
|
+
*
|
|
20
|
+
* When the IDE does NOT support MCP (older than 2025.2) or it is disabled, the
|
|
21
|
+
* plugin injects nothing -> cc connects nothing. This is the product decision:
|
|
22
|
+
* if the IDE's MCP is unsupported, do not try to connect (no port scan, no
|
|
23
|
+
* external proxy fallback). Reserved server name `idea` -> tools `mcp__idea__*`.
|
|
24
|
+
*
|
|
25
|
+
* Pure CLI, no network scan, no external dependency: a deterministic
|
|
26
|
+
* env -> MCP-config mapping, fully unit-testable. The connect path reuses the
|
|
27
|
+
* existing MCP client (Streamable-HTTP) via mcp-config.js `loadJetbrainsMcp`.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/** Transports the CLI's MCP client can actually talk (see mcp-client.js). */
|
|
31
|
+
const SUPPORTED_TRANSPORTS = new Set(["http", "https", "sse"]);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Only ever connect to a loopback endpoint. IDEA's built-in server binds
|
|
35
|
+
* localhost; refusing anything else keeps an injected env var from pointing cc
|
|
36
|
+
* at an arbitrary host. `new URL(...).hostname` strips the brackets from an
|
|
37
|
+
* IPv6 literal on most Node builds but keeps them on some — accept both forms.
|
|
38
|
+
*/
|
|
39
|
+
function isLoopbackUrl(url) {
|
|
40
|
+
try {
|
|
41
|
+
const h = new URL(url).hostname.toLowerCase();
|
|
42
|
+
return (
|
|
43
|
+
h === "127.0.0.1" || h === "::1" || h === "[::1]" || h === "localhost"
|
|
44
|
+
);
|
|
45
|
+
} catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function inferTransportFromUrl(url) {
|
|
51
|
+
if (/\/sse(\b|\/|$)/i.test(url)) return "sse";
|
|
52
|
+
if (/^https:/i.test(url)) return "https";
|
|
53
|
+
if (/^http:/i.test(url)) return "http";
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Are we running under the ChainlessChain JetBrains plugin with IDE MCP
|
|
59
|
+
* available? True iff the plugin injected an MCP URL — which it only does when
|
|
60
|
+
* the IDE is >= 2025.2 and the MCP server is enabled. No URL = treat as
|
|
61
|
+
* unsupported and stay out of the way.
|
|
62
|
+
*/
|
|
63
|
+
export function isInJetbrainsContext(env = process.env) {
|
|
64
|
+
return !!(env && env.CHAINLESSCHAIN_JETBRAINS_MCP_URL);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Resolve the IDEA built-in MCP server to connect to, or null.
|
|
69
|
+
*
|
|
70
|
+
* Deterministic: the plugin-injected `CHAINLESSCHAIN_JETBRAINS_MCP_URL` (a
|
|
71
|
+
* loopback http/https/sse endpoint) is the single source of truth. A missing,
|
|
72
|
+
* non-loopback, or unsupported-transport URL yields null (don't connect).
|
|
73
|
+
*
|
|
74
|
+
* @param {object} opts { env? }
|
|
75
|
+
* @returns {{url:string, transport:string, token:(string|null)}|null}
|
|
76
|
+
*/
|
|
77
|
+
export function discoverJetbrainsServer({ env = process.env } = {}) {
|
|
78
|
+
const url = env && env.CHAINLESSCHAIN_JETBRAINS_MCP_URL;
|
|
79
|
+
if (!url || !isLoopbackUrl(url)) return null;
|
|
80
|
+
|
|
81
|
+
const transport = String(
|
|
82
|
+
env.CHAINLESSCHAIN_JETBRAINS_TRANSPORT || inferTransportFromUrl(url) || "",
|
|
83
|
+
).toLowerCase();
|
|
84
|
+
if (!SUPPORTED_TRANSPORTS.has(transport)) return null;
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
url,
|
|
88
|
+
transport,
|
|
89
|
+
token:
|
|
90
|
+
typeof env.CHAINLESSCHAIN_JETBRAINS_TOKEN === "string"
|
|
91
|
+
? env.CHAINLESSCHAIN_JETBRAINS_TOKEN
|
|
92
|
+
: null,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* A discovered server -> an MCP server config row for `setupMcpFromConfig`.
|
|
98
|
+
* `longRunning` exempts it from the agent loop's per-call timeout (some IDE
|
|
99
|
+
* operations — e.g. an indexing-gated search — can take a while), matching the
|
|
100
|
+
* ide/pdh bridges.
|
|
101
|
+
*/
|
|
102
|
+
export function jetbrainsServerToMcpConfig(found) {
|
|
103
|
+
if (!found || !found.url) return null;
|
|
104
|
+
const headers = {};
|
|
105
|
+
if (found.token) headers.Authorization = `Bearer ${found.token}`;
|
|
106
|
+
return {
|
|
107
|
+
url: found.url,
|
|
108
|
+
transport: found.transport,
|
|
109
|
+
headers,
|
|
110
|
+
longRunning: true,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Human-readable explanation of why discovery did / didn't pick a server —
|
|
116
|
+
* backs `cc ide jetbrains`. Never surfaces the raw token.
|
|
117
|
+
*/
|
|
118
|
+
export function diagnoseJetbrains({ env = process.env } = {}) {
|
|
119
|
+
const rawUrl = (env && env.CHAINLESSCHAIN_JETBRAINS_MCP_URL) || null;
|
|
120
|
+
const chosen = discoverJetbrainsServer({ env });
|
|
121
|
+
|
|
122
|
+
let reason;
|
|
123
|
+
if (chosen) {
|
|
124
|
+
reason = "CHAINLESSCHAIN_JETBRAINS_MCP_URL injected by the IDE plugin";
|
|
125
|
+
} else if (!rawUrl) {
|
|
126
|
+
reason =
|
|
127
|
+
"no CHAINLESSCHAIN_JETBRAINS_MCP_URL — IDE MCP is unsupported (IDEA < " +
|
|
128
|
+
"2025.2) / disabled, or cc was not launched from the JetBrains plugin";
|
|
129
|
+
} else if (!isLoopbackUrl(rawUrl)) {
|
|
130
|
+
reason =
|
|
131
|
+
"injected URL is not a loopback (127.0.0.1/::1/localhost) endpoint";
|
|
132
|
+
} else {
|
|
133
|
+
reason = "injected URL is not a supported transport (http/https/sse)";
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
supported: !!rawUrl,
|
|
138
|
+
chosen: chosen
|
|
139
|
+
? {
|
|
140
|
+
url: chosen.url,
|
|
141
|
+
transport: chosen.transport,
|
|
142
|
+
hasToken: !!chosen.token,
|
|
143
|
+
}
|
|
144
|
+
: null,
|
|
145
|
+
reason,
|
|
146
|
+
};
|
|
147
|
+
}
|
package/src/lib/llm-pricing.js
CHANGED
|
@@ -96,9 +96,10 @@ const round = (n, dp = 6) => {
|
|
|
96
96
|
*
|
|
97
97
|
* Per provider, a user entry whose `match` equals a built-in pattern REPLACES
|
|
98
98
|
* it; brand-new patterns are prepended so they win ties; unknown providers are
|
|
99
|
-
* added. Malformed entries (missing match / non-numeric
|
|
100
|
-
* bad config line can't crash cost reporting
|
|
101
|
-
*
|
|
99
|
+
* added. Malformed entries (missing match / non-numeric / negative / Infinity
|
|
100
|
+
* rate) are skipped so a bad config line can't crash cost reporting or produce a
|
|
101
|
+
* negative cost that undercounts spend. Returns a new table; never mutates
|
|
102
|
+
* PRICE_TABLE or the input.
|
|
102
103
|
*
|
|
103
104
|
* @param {object} [overrides]
|
|
104
105
|
* @param {object} [base=PRICE_TABLE]
|
|
@@ -123,8 +124,14 @@ export function mergePricing(overrides, base = PRICE_TABLE) {
|
|
|
123
124
|
e &&
|
|
124
125
|
typeof e.match === "string" &&
|
|
125
126
|
e.match.trim() &&
|
|
127
|
+
// Rates must be finite AND non-negative — a negative price would
|
|
128
|
+
// produce a negative cost that undercounts spend (and could keep a
|
|
129
|
+
// CostBudget under its cap). `>= 0` also rejects NaN (NaN >= 0 is
|
|
130
|
+
// false); isFinite additionally rejects Infinity.
|
|
126
131
|
Number.isFinite(Number(e.in)) &&
|
|
127
|
-
Number
|
|
132
|
+
Number(e.in) >= 0 &&
|
|
133
|
+
Number.isFinite(Number(e.out)) &&
|
|
134
|
+
Number(e.out) >= 0,
|
|
128
135
|
)
|
|
129
136
|
.map((e) => ({
|
|
130
137
|
match: e.match.toLowerCase(),
|
package/src/lib/llm-providers.js
CHANGED
|
@@ -181,12 +181,22 @@ export class LLMProviderRegistry {
|
|
|
181
181
|
.prepare("SELECT * FROM llm_providers WHERE custom = 1")
|
|
182
182
|
.all();
|
|
183
183
|
for (const row of rows) {
|
|
184
|
+
// Tolerate a corrupt `models` TEXT column: `|| "[]"` only covers null,
|
|
185
|
+
// not malformed JSON, and an unguarded throw here would abort the whole
|
|
186
|
+
// custom-provider load (and the registry constructor) over one bad row.
|
|
187
|
+
let models = [];
|
|
188
|
+
try {
|
|
189
|
+
const parsed = JSON.parse(row.models || "[]");
|
|
190
|
+
if (Array.isArray(parsed)) models = parsed;
|
|
191
|
+
} catch {
|
|
192
|
+
/* corrupt models column — fall back to no models for this provider */
|
|
193
|
+
}
|
|
184
194
|
this.providers.set(row.name, {
|
|
185
195
|
name: row.name,
|
|
186
196
|
displayName: row.display_name,
|
|
187
197
|
baseUrl: row.base_url,
|
|
188
198
|
apiKeyEnv: row.api_key_env,
|
|
189
|
-
models
|
|
199
|
+
models,
|
|
190
200
|
custom: true,
|
|
191
201
|
free: false,
|
|
192
202
|
});
|
package/src/lib/mcp-oauth.js
CHANGED
|
@@ -194,6 +194,12 @@ export async function discoverAuthMetadata(
|
|
|
194
194
|
{ resourceMetadataUrl } = {},
|
|
195
195
|
) {
|
|
196
196
|
const origin = new URL(serverUrl).origin;
|
|
197
|
+
// Discovery itself carries no secrets, but its responses dictate the
|
|
198
|
+
// authorization/token endpoints — so a cleartext-remote discovery is a
|
|
199
|
+
// downgrade vector (a MITM could inject endpoints). Refuse a non-loopback
|
|
200
|
+
// http MCP URL up front (loopback http stays allowed for local dev), matching
|
|
201
|
+
// the endpoint enforcement below.
|
|
202
|
+
assertSecureEndpoint(origin, "MCP server URL");
|
|
197
203
|
// 1. protected-resource metadata (RFC 9728) → authorization_servers[]
|
|
198
204
|
let authServer = origin;
|
|
199
205
|
try {
|
|
@@ -209,6 +215,12 @@ export async function discoverAuthMetadata(
|
|
|
209
215
|
} catch {
|
|
210
216
|
// no protected-resource doc → assume the origin is its own auth server
|
|
211
217
|
}
|
|
218
|
+
// The authorization-server location can come from the REMOTE protected-
|
|
219
|
+
// resource doc, so a malicious/MITM'd doc could point discovery at a
|
|
220
|
+
// cleartext host. Refuse a non-loopback http authServer before fetching its
|
|
221
|
+
// metadata (the discovered endpoints are HTTPS-checked too, but this fails
|
|
222
|
+
// closed earlier and blocks the downgrade).
|
|
223
|
+
assertSecureEndpoint(authServer, "authorization server");
|
|
212
224
|
// 2. authorization-server metadata (RFC 8414)
|
|
213
225
|
const candidates = [
|
|
214
226
|
`${authServer}/.well-known/oauth-authorization-server`,
|
package/src/lib/mcp-serve.js
CHANGED
|
@@ -108,6 +108,35 @@ export function buildTools({ root, readOnly = false, deps = _deps }) {
|
|
|
108
108
|
},
|
|
109
109
|
handler: ({ path: rel }) => {
|
|
110
110
|
const abs = confine(root, rel, deps);
|
|
111
|
+
// Bounded read: pull at most MAX_READ_BYTES+1 bytes into memory. The
|
|
112
|
+
// old `readFileSync(abs)` loaded the WHOLE file before truncating, so
|
|
113
|
+
// MAX_READ_BYTES only capped the RESPONSE — a multi-GB file under the
|
|
114
|
+
// serve root would OOM the process. The +1 byte detects "longer than
|
|
115
|
+
// the cap" without reading the rest. Fall back to readFileSync only
|
|
116
|
+
// when the fd API isn't available on an injected fs.
|
|
117
|
+
if (typeof fs.openSync === "function") {
|
|
118
|
+
const fd = fs.openSync(abs, "r");
|
|
119
|
+
try {
|
|
120
|
+
const buf = Buffer.alloc(MAX_READ_BYTES + 1);
|
|
121
|
+
const n = fs.readSync(fd, buf, 0, MAX_READ_BYTES + 1, 0);
|
|
122
|
+
const truncated = n > MAX_READ_BYTES;
|
|
123
|
+
const text = buf
|
|
124
|
+
.slice(0, truncated ? MAX_READ_BYTES : n)
|
|
125
|
+
.toString("utf-8");
|
|
126
|
+
if (!truncated) return ok(text);
|
|
127
|
+
let total = null;
|
|
128
|
+
try {
|
|
129
|
+
total = fs.statSync(abs).size;
|
|
130
|
+
} catch {
|
|
131
|
+
/* size is best-effort for the message */
|
|
132
|
+
}
|
|
133
|
+
return ok(
|
|
134
|
+
`${text}\n… [truncated${total != null ? ` ${total} bytes` : ""}]`,
|
|
135
|
+
);
|
|
136
|
+
} finally {
|
|
137
|
+
fs.closeSync(fd);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
111
140
|
const buf = fs.readFileSync(abs);
|
|
112
141
|
const truncated = buf.length > MAX_READ_BYTES;
|
|
113
142
|
const text = (truncated ? buf.slice(0, MAX_READ_BYTES) : buf).toString(
|
package/src/lib/orchestrator.js
CHANGED
|
@@ -82,6 +82,16 @@ export class Orchestrator extends EventEmitter {
|
|
|
82
82
|
this.ciCommand = options.ciCommand || "npm test";
|
|
83
83
|
this.verbose = options.verbose || false;
|
|
84
84
|
|
|
85
|
+
// Cap retained task history. Every addTask stores a record in _tasks and
|
|
86
|
+
// nothing ever removes it, so a long-running orchestrator (cron-watch /
|
|
87
|
+
// daemon) accumulates tasks without bound. Prune the oldest TERMINAL tasks
|
|
88
|
+
// beyond this cap (in-flight tasks are never dropped). Generous default;
|
|
89
|
+
// 0/invalid → 500.
|
|
90
|
+
this.maxTasks =
|
|
91
|
+
Number.isFinite(options.maxTasks) && options.maxTasks > 0
|
|
92
|
+
? options.maxTasks
|
|
93
|
+
: 500;
|
|
94
|
+
|
|
85
95
|
/** @type {Map<string, object>} taskId → task */
|
|
86
96
|
this._tasks = new Map();
|
|
87
97
|
|
|
@@ -151,6 +161,7 @@ export class Orchestrator extends EventEmitter {
|
|
|
151
161
|
};
|
|
152
162
|
|
|
153
163
|
this._tasks.set(task.id, task);
|
|
164
|
+
this._pruneTasks();
|
|
154
165
|
this.emit("task:added", task);
|
|
155
166
|
|
|
156
167
|
if (this.notifier.isConfigured && task.notify) {
|
|
@@ -183,7 +194,7 @@ export class Orchestrator extends EventEmitter {
|
|
|
183
194
|
return {
|
|
184
195
|
tasks,
|
|
185
196
|
pool: this._router.summary(),
|
|
186
|
-
|
|
197
|
+
ciCommand: this.ciCommand,
|
|
187
198
|
cronActive: this._cronTimer !== null,
|
|
188
199
|
};
|
|
189
200
|
}
|
|
@@ -278,7 +289,7 @@ export class Orchestrator extends EventEmitter {
|
|
|
278
289
|
async _dispatch(task) {
|
|
279
290
|
this.emit("agents:dispatched", { task, count: task.subtasks.length });
|
|
280
291
|
this._log(
|
|
281
|
-
`Dispatching ${task.subtasks.length} subtask(s) to ${this.
|
|
292
|
+
`Dispatching ${task.subtasks.length} subtask(s) to ${this._router.summary().length} agent backend(s)`,
|
|
282
293
|
);
|
|
283
294
|
|
|
284
295
|
const results = await this._router.dispatch(task.subtasks, {
|
|
@@ -372,6 +383,11 @@ export class Orchestrator extends EventEmitter {
|
|
|
372
383
|
cwd,
|
|
373
384
|
encoding: "utf-8",
|
|
374
385
|
timeout: 180_000,
|
|
386
|
+
// execSync defaults maxBuffer to 1 MB; a verbose-but-PASSING test run
|
|
387
|
+
// that prints more than that throws ENOBUFS, which the catch below
|
|
388
|
+
// would misreport as a CI failure (triggering needless retries +
|
|
389
|
+
// re-dispatch). Give CI output generous headroom.
|
|
390
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
375
391
|
stdio: "pipe",
|
|
376
392
|
});
|
|
377
393
|
return {
|
|
@@ -387,6 +403,26 @@ export class Orchestrator extends EventEmitter {
|
|
|
387
403
|
}
|
|
388
404
|
}
|
|
389
405
|
|
|
406
|
+
/**
|
|
407
|
+
* Bound retained task history to maxTasks. Evicts the oldest TERMINAL tasks
|
|
408
|
+
* first (Map preserves insertion order = FIFO); an in-flight task is never
|
|
409
|
+
* dropped, so a burst of concurrent runs can briefly exceed the cap rather
|
|
410
|
+
* than losing live work. The dropped records are completed/failed history
|
|
411
|
+
* the caller has already seen via task:complete / task:failed events.
|
|
412
|
+
*/
|
|
413
|
+
_pruneTasks() {
|
|
414
|
+
if (this._tasks.size <= this.maxTasks) return;
|
|
415
|
+
for (const [id, t] of this._tasks) {
|
|
416
|
+
if (this._tasks.size <= this.maxTasks) break;
|
|
417
|
+
if (
|
|
418
|
+
t.status === TASK_STATUS.COMPLETED ||
|
|
419
|
+
t.status === TASK_STATUS.FAILED
|
|
420
|
+
) {
|
|
421
|
+
this._tasks.delete(id);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
390
426
|
async _cronTick() {
|
|
391
427
|
this.emit("cron:tick", { at: new Date().toISOString() });
|
|
392
428
|
// Override this method or listen to the event to add input source polling
|