chainlesschain 0.166.160 → 0.166.161
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 +9 -3
- package/package.json +1 -1
- package/src/assets/linux-subreaper/linux-arm64/manifest.json +1 -1
- package/src/assets/linux-subreaper/linux-x64/manifest.json +1 -1
- package/src/assets/web-panel/.build-hash +1 -1
- package/src/assets/web-panel/assets/{AIOps-CraNGNgc.js → AIOps-CNhLuFiB.js} +1 -1
- package/src/assets/web-panel/assets/{ActionButton-C0jn6sgg.js → ActionButton-BVPZKoT-.js} +1 -1
- package/src/assets/web-panel/assets/{Analytics-DVrR_wjl.js → Analytics-Ct2gNxKd.js} +1 -1
- package/src/assets/web-panel/assets/{AppLayout-CeKP8mgC.js → AppLayout-BnaA21bl.js} +1 -1
- package/src/assets/web-panel/assets/{Artifacts-OHCS9wLN.js → Artifacts-C5_NWBGG.js} +1 -1
- package/src/assets/web-panel/assets/{Audit-C77b6pDl.js → Audit-y_MUbjLt.js} +1 -1
- package/src/assets/web-panel/assets/{BackgroundAgents-CefiwCgM.js → BackgroundAgents-C63koq2N.js} +1 -1
- package/src/assets/web-panel/assets/{Backup-B-5KmWNA.js → Backup-Yo9hJesU.js} +1 -1
- package/src/assets/web-panel/assets/{BaseInput-C3bJ1Qlc.js → BaseInput-uAsHWcNC.js} +1 -1
- package/src/assets/web-panel/assets/{Chat-DBahPz9B.js → Chat-B9zs3I4L.js} +1 -1
- package/src/assets/web-panel/assets/{ChatBubbleRenderer-J4BVVrXZ.js → ChatBubbleRenderer-fzKRaTLd.js} +1 -1
- package/src/assets/web-panel/assets/{Checkbox-w856fzfY.js → Checkbox-BKHInWqb.js} +1 -1
- package/src/assets/web-panel/assets/{Codegen-XKmsL_C3.js → Codegen-gB60liCi.js} +1 -1
- package/src/assets/web-panel/assets/{Col-B37-gr7d.js → Col-B_iw_PIR.js} +1 -1
- package/src/assets/web-panel/assets/{Community-DdahlN0f.js → Community-BTwbiBFd.js} +1 -1
- package/src/assets/web-panel/assets/{Compact-oKnoE-9_.js → Compact-D851uR8p.js} +1 -1
- package/src/assets/web-panel/assets/{Compliance-CnCRlOB_.js → Compliance-DQOQgtbc.js} +1 -1
- package/src/assets/web-panel/assets/{Cowork-D3Vr5R3E.js → Cowork-DzaEZbbm.js} +1 -1
- package/src/assets/web-panel/assets/{Cron-X46CdLRQ.js → Cron-Df2xjxzZ.js} +1 -1
- package/src/assets/web-panel/assets/{Crosschain-CV3_6jVw.js → Crosschain-D7eewpJM.js} +1 -1
- package/src/assets/web-panel/assets/{DID-Kr6H4WKr.js → DID-Dg9OtFGl.js} +1 -1
- package/src/assets/web-panel/assets/{Dashboard-Bj4usrhx.js → Dashboard-B3dt4SYd.js} +1 -1
- package/src/assets/web-panel/assets/{Dropdown-V3DPV21D.js → Dropdown-C0vEIluP.js} +1 -1
- package/src/assets/web-panel/assets/{EmailListRenderer-8MCX0Y4b.js → EmailListRenderer-BLe81BHF.js} +1 -1
- package/src/assets/web-panel/assets/{EvolutionSettings-SUoykpjc.js → EvolutionSettings-CvN_ORvk.js} +1 -1
- package/src/assets/web-panel/assets/{FamilyGuardDashboard-C0iE0T9x.js → FamilyGuardDashboard-xFaUcq6i.js} +1 -1
- package/src/assets/web-panel/assets/{Federation-CSU3kpK2.js → Federation-DqGa6L60.js} +1 -1
- package/src/assets/web-panel/assets/{FormItemContext-Bcv2XJNw.js → FormItemContext-DumZjtkF.js} +1 -1
- package/src/assets/web-panel/assets/{GenericCardRenderer-PdEqwQZd.js → GenericCardRenderer-CXxweSPC.js} +1 -1
- package/src/assets/web-panel/assets/{Git-CVZ0MSRN.js → Git-CF3OyEuV.js} +1 -1
- package/src/assets/web-panel/assets/{Governance-CF64-eGc.js → Governance-DGBoeFcm.js} +1 -1
- package/src/assets/web-panel/assets/{Inference-DJ1J40Th.js → Inference-CveIk_lk.js} +1 -1
- package/src/assets/web-panel/assets/{KnowledgeGraph-Cf3ULXmf.js → KnowledgeGraph-msqPEvc0.js} +1 -1
- package/src/assets/web-panel/assets/{Logs-DM_RbXG_.js → Logs-zAhceodz.js} +1 -1
- package/src/assets/web-panel/assets/{MarkdownRenderer-B2wey_j8.js → MarkdownRenderer-DwP1jZr3.js} +1 -1
- package/src/assets/web-panel/assets/{Marketplace-tqdANxLa.js → Marketplace-CIOc62w1.js} +1 -1
- package/src/assets/web-panel/assets/{McpTools-BiSYAtKB.js → McpTools-Ye1FSjo-.js} +1 -1
- package/src/assets/web-panel/assets/{Memory-hOvA-Tqp.js → Memory-COGlkLtO.js} +1 -1
- package/src/assets/web-panel/assets/{MobileBridge-CIpwBK6G.js → MobileBridge-BVkRPQSG.js} +1 -1
- package/src/assets/web-panel/assets/{MobileProjects-DMpV98oD.js → MobileProjects-AtAH5Uoo.js} +1 -1
- package/src/assets/web-panel/assets/{Mtc-CVoJZMuY.js → Mtc-CqiDh60D.js} +1 -1
- package/src/assets/web-panel/assets/{MtcAudit-Dz9YsrvV.js → MtcAudit-CruLSC3f.js} +1 -1
- package/src/assets/web-panel/assets/{Multisig-CamW3sTK.js → Multisig-YH7hDXe7.js} +1 -1
- package/src/assets/web-panel/assets/{NLProgramming-DlZo8q6W.js → NLProgramming-DT6rmEY_.js} +1 -1
- package/src/assets/web-panel/assets/{Notes-DZJSYibx.js → Notes-Cjp991_L.js} +1 -1
- package/src/assets/web-panel/assets/{NotificationSettings-BSlIIGOM.js → NotificationSettings-CMv9uHtV.js} +1 -1
- package/src/assets/web-panel/assets/{OrderTableRenderer-Bo9vImgU.js → OrderTableRenderer-wp1zrUZe.js} +1 -1
- package/src/assets/web-panel/assets/{Organization-B1sBf0Kk.js → Organization-CZGBH2f-.js} +1 -1
- package/src/assets/web-panel/assets/{Overflow-CD8GUNOV.js → Overflow-C5yb6LcI.js} +1 -1
- package/src/assets/web-panel/assets/{P2P-CeaIuSa9.js → P2P-C-3smRsS.js} +1 -1
- package/src/assets/web-panel/assets/{PdhVaultBrowser-DCOkcRse.js → PdhVaultBrowser-D9e1lYe_.js} +2 -2
- package/src/assets/web-panel/assets/{Permissions-DQCZnN_y.js → Permissions-YrtBFosR.js} +1 -1
- package/src/assets/web-panel/assets/{PersonalDataHub-D_9PtVvT.js → PersonalDataHub-CPIlHXmG.js} +1 -1
- package/src/assets/web-panel/assets/{Pipeline-BawUxj0i.js → Pipeline-BAUQ4UL0.js} +1 -1
- package/src/assets/web-panel/assets/{Privacy-CPyw19Ai.js → Privacy-Du1mfYpr.js} +1 -1
- package/src/assets/web-panel/assets/{ProjectInit-GDtYLbL6.js → ProjectInit-DTZZPmI6.js} +1 -1
- package/src/assets/web-panel/assets/{ProjectSettings-DhmGKXVL.js → ProjectSettings-D5vGoWmg.js} +1 -1
- package/src/assets/web-panel/assets/{Projects-O2spSrud.js → Projects-CPyfgipD.js} +1 -1
- package/src/assets/web-panel/assets/Providers-BCo_GB4k.css +1 -0
- package/src/assets/web-panel/assets/Providers-DoJDphwe.js +1 -0
- package/src/assets/web-panel/assets/{QrScannerModal-Dcqm-i6j.js → QrScannerModal-DKezd77c.js} +1 -1
- package/src/assets/web-panel/assets/{QuickAsk-C6uPAeAE.js → QuickAsk-Dj5x0jA3.js} +1 -1
- package/src/assets/web-panel/assets/{Recommend-ClVlhga7.js → Recommend-D_Bk2N6M.js} +1 -1
- package/src/assets/web-panel/assets/{RemoteSession-2raJDKUb.js → RemoteSession-DoACu1j-.js} +1 -1
- package/src/assets/web-panel/assets/{Reputation-BYWC8k3t.js → Reputation-CHY48udA.js} +1 -1
- package/src/assets/web-panel/assets/{Row-Bv7Y68ai.js → Row-B2ji1NaC.js} +1 -1
- package/src/assets/web-panel/assets/{RssFeed-Ba54MKvz.js → RssFeed-Cko4TT8o.js} +1 -1
- package/src/assets/web-panel/assets/{Search-B9EkRkZK.js → Search-D4Jq_y26.js} +1 -1
- package/src/assets/web-panel/assets/{Security-DuXQGU4o.js → Security-CRj9UHDB.js} +1 -1
- package/src/assets/web-panel/assets/{Services-DJnCtY8x.js → Services-fZPfKCJD.js} +1 -1
- package/src/assets/web-panel/assets/{Skeleton-BVDdtf_S.js → Skeleton-C_H68DxY.js} +1 -1
- package/src/assets/web-panel/assets/{Skills-DGkYCesm.js → Skills-Bm4nTGzx.js} +1 -1
- package/src/assets/web-panel/assets/{Sla-CHND6lwC.js → Sla-BBhY5p8N.js} +1 -1
- package/src/assets/web-panel/assets/{SpeechSettings-Bg0Bgy9c.js → SpeechSettings-B0fvb--L.js} +1 -1
- package/src/assets/web-panel/assets/{SyncSettings-DwtcZ2Ml.js → SyncSettings-0HlhIGJ-.js} +1 -1
- package/src/assets/web-panel/assets/{Tasks-BoHc0cP2.js → Tasks-Bo-k7A9g.js} +1 -1
- package/src/assets/web-panel/assets/{Templates-DAMs4m8X.js → Templates-BRTC7AUC.js} +1 -1
- package/src/assets/web-panel/assets/{Tenant-DkVQbOzT.js → Tenant-BpIv9shV.js} +1 -1
- package/src/assets/web-panel/assets/{Terminal-BTOLM8Yu.js → Terminal-Bt147VT7.js} +1 -1
- package/src/assets/web-panel/assets/{TimelineRenderer-BO5ZyxUU.js → TimelineRenderer-CBSVcKf5.js} +1 -1
- package/src/assets/web-panel/assets/{Tokens-D0LjCtSA.js → Tokens-JCGWdOyZ.js} +1 -1
- package/src/assets/web-panel/assets/{Trigger-DgGXg9VB.js → Trigger-D2GaPoYt.js} +1 -1
- package/src/assets/web-panel/assets/{Trust-BAEQrND-.js → Trust-BGicfDbx.js} +1 -1
- package/src/assets/web-panel/assets/{UkeySign-TtBclFRw.js → UkeySign-DJLwi-VO.js} +1 -1
- package/src/assets/web-panel/assets/{VideoEditing-ByxvpIpS.js → VideoEditing-JdhxB9I3.js} +1 -1
- package/src/assets/web-panel/assets/{Wallet-CTa7jqur.js → Wallet-B8OqhQC-.js} +1 -1
- package/src/assets/web-panel/assets/{WebAuthn-oHbCSjrD.js → WebAuthn-0qeF3jwV.js} +1 -1
- package/src/assets/web-panel/assets/{WorkflowEditor-DQKQAdUS.js → WorkflowEditor-Br7NIU4X.js} +1 -1
- package/src/assets/web-panel/assets/{chat-BcCU2FuK.js → chat-CdI93Uj-.js} +1 -1
- package/src/assets/web-panel/assets/{colors-BcXAFjHT.js → colors-hE8M4e8h.js} +1 -1
- package/src/assets/web-panel/assets/{compact-item-GhZzQppm.js → compact-item-BUhXh46K.js} +1 -1
- package/src/assets/web-panel/assets/{createContext-Bc6nwTUy.js → createContext-B5ccktpR.js} +1 -1
- package/src/assets/web-panel/assets/{hasIn-DRH8Xt0Y.js → hasIn-CptjIqui.js} +1 -1
- package/src/assets/web-panel/assets/{index-BDIN9KWp.js → index-0aHON-dJ.js} +1 -1
- package/src/assets/web-panel/assets/{index-mqlLcSgP.js → index-0dLpjWdQ.js} +1 -1
- package/src/assets/web-panel/assets/{index-gvsatTPZ.js → index-B2gEgzUF.js} +1 -1
- package/src/assets/web-panel/assets/{index-CB1Thk9t.js → index-B4h7Yyll.js} +1 -1
- package/src/assets/web-panel/assets/{index-lEDZUWRO.js → index-B6aiDNJf.js} +1 -1
- package/src/assets/web-panel/assets/{index-DQnXn3vs.js → index-BB4StyBV.js} +1 -1
- package/src/assets/web-panel/assets/{index-60aCmptm.js → index-BBnyQBDE.js} +1 -1
- package/src/assets/web-panel/assets/{index-DCgr2bDL.js → index-BCmJolrc.js} +1 -1
- package/src/assets/web-panel/assets/{index-BaUmYzDB.js → index-Bb2rTuMK.js} +1 -1
- package/src/assets/web-panel/assets/{index-Bebe5WYu.js → index-BktXJbRU.js} +1 -1
- package/src/assets/web-panel/assets/{index-wnmY4P7_.js → index-BsaY5ENn.js} +1 -1
- package/src/assets/web-panel/assets/{index-B7hScRVB.js → index-Bw1sj494.js} +1 -1
- package/src/assets/web-panel/assets/{index-DOBzu5UO.js → index-BzOVaC2t.js} +1 -1
- package/src/assets/web-panel/assets/{index-D6B_ELy6.js → index-C7sbKKIt.js} +1 -1
- package/src/assets/web-panel/assets/{index-BOquBdmK.js → index-CE7uX7n3.js} +1 -1
- package/src/assets/web-panel/assets/{index-DCCEt-pU.js → index-CGgx5Z0d.js} +1 -1
- package/src/assets/web-panel/assets/{index-DoRIPzwv.js → index-CNSnbjTb.js} +1 -1
- package/src/assets/web-panel/assets/{index-BQ6b5kJR.js → index-CV50XvUJ.js} +1 -1
- package/src/assets/web-panel/assets/{index-D08s-CJ_.js → index-Ca1U3jvV.js} +1 -1
- package/src/assets/web-panel/assets/{index-DXip1xUj.js → index-CgPmwwdZ.js} +1 -1
- package/src/assets/web-panel/assets/{index-WrMfehhj.js → index-CiQ8T-Wj.js} +1 -1
- package/src/assets/web-panel/assets/{index-owU4npmQ.js → index-CmEKreTW.js} +1 -1
- package/src/assets/web-panel/assets/index-CwLYWliJ.js +1 -0
- package/src/assets/web-panel/assets/{index-Dzh9Ud2R.js → index-Cwf0XTa8.js} +3 -3
- package/src/assets/web-panel/assets/{index-Cexk6Y1r.js → index-D5i229Gh.js} +1 -1
- package/src/assets/web-panel/assets/{index-BdOccG1D.js → index-DG40DMAk.js} +1 -1
- package/src/assets/web-panel/assets/{index-CtC-B6Zy.js → index-DG7-sHcw.js} +1 -1
- package/src/assets/web-panel/assets/{index-BFFyqn3k.js → index-DLmj9zeI.js} +1 -1
- package/src/assets/web-panel/assets/index-DMF7BcWf.js +1 -0
- package/src/assets/web-panel/assets/{index-DzhMohzV.js → index-DO3kRQnh.js} +1 -1
- package/src/assets/web-panel/assets/{index-Bb5XCEKT.js → index-DRr1ldeO.js} +1 -1
- package/src/assets/web-panel/assets/{index-IW9dUJK_.js → index-DUWmPd0O.js} +1 -1
- package/src/assets/web-panel/assets/{index-D9QfJDQg.js → index-Dc8ZP-rA.js} +1 -1
- package/src/assets/web-panel/assets/{index-BsRmNZCk.js → index-DhdxOKQ4.js} +1 -1
- package/src/assets/web-panel/assets/{index-CSHz8UnK.js → index-Dxmu8cZG.js} +1 -1
- package/src/assets/web-panel/assets/{index-DNi_t23H.js → index-LQEMp44F.js} +1 -1
- package/src/assets/web-panel/assets/{index-DOtNt1m7.js → index-WVQ05cSo.js} +1 -1
- package/src/assets/web-panel/assets/{index-D6pWvvp-.js → index-f3OaRY6m.js} +1 -1
- package/src/assets/web-panel/assets/{index-BEQha9Ur.js → index-ri-ZBdPd.js} +1 -1
- package/src/assets/web-panel/assets/{initDefaultProps-DfHPrIA5.js → initDefaultProps-DTj0zdLt.js} +1 -1
- package/src/assets/web-panel/assets/{motion-CCzrK3c5.js → motion-DnsNb0QQ.js} +1 -1
- package/src/assets/web-panel/assets/{move-B2uu6I9f.js → move-Bf_g7tYL.js} +1 -1
- package/src/assets/web-panel/assets/{mtc-parser-DtFu2-C_.js → mtc-parser-D2gv6Yis.js} +1 -1
- package/src/assets/web-panel/assets/{omit-BFjLuAHb.js → omit-BCRtdA1N.js} +1 -1
- package/src/assets/web-panel/assets/{pickAttrs-DfsjYq45.js → pickAttrs-COqVNaT6.js} +1 -1
- package/src/assets/web-panel/assets/{placementArrow-CDdYIVXw.js → placementArrow--K1Q_0hw.js} +1 -1
- package/src/assets/web-panel/assets/{responsiveObserve-CfrplFjn.js → responsiveObserve-BrMnRoWy.js} +1 -1
- package/src/assets/web-panel/assets/{slide-DHNX5Xwt.js → slide-DPlpqM13.js} +1 -1
- package/src/assets/web-panel/assets/{statusUtils-BI-C3SSk.js → statusUtils-Ddby7oUh.js} +1 -1
- package/src/assets/web-panel/assets/{styleChecker-C5Y3Oyy2.js → styleChecker-BV5JCSKe.js} +1 -1
- package/src/assets/web-panel/assets/{useFlexGapSupport-atF45w0U.js → useFlexGapSupport-DeLyWVJE.js} +1 -1
- package/src/assets/web-panel/assets/{useFs-C4M8-xm9.js → useFs-DIXerI3H.js} +1 -1
- package/src/assets/web-panel/assets/{usePersonalDataHub-jjZdnfs_.js → usePersonalDataHub-BvhJbBzh.js} +1 -1
- package/src/assets/web-panel/assets/{vnode-BRTSCmU3.js → vnode-DGQZc27k.js} +1 -1
- package/src/assets/web-panel/assets/{zoom-BaS5ZYRC.js → zoom-BcHWSA8z.js} +1 -1
- package/src/assets/web-panel/index.html +1 -1
- package/src/command-help-index.json +2 -2
- package/src/commands/llm.js +13 -0
- package/src/commands/plugin.js +46 -2
- package/src/commands/session.js +104 -87
- package/src/commands/setup.js +25 -16
- package/src/commands/status.js +19 -0
- package/src/commands/tasks.js +80 -2
- package/src/data/changelog.json +13 -0
- package/src/gateways/ws/message-dispatcher.js +5 -0
- package/src/harness/background-task-manager.js +63 -30
- package/src/harness/mcp-client.js +61 -22
- package/src/lib/doctor-checkup.js +21 -0
- package/src/lib/execution-location-runner-lifecycle.js +81 -2
- package/src/lib/lk-catalog.js +4 -0
- package/src/lib/lk-model-catalog.json +36 -15
- package/src/lib/lk-public-catalog.cjs +92 -0
- package/src/lib/llm-channel-presets.js +2 -2
- package/src/lib/mcp-server-handle.js +24 -8
- package/src/lib/mcp-stateless-protocol.js +37 -8
- package/src/lib/mcp-task-journal.js +32 -2
- package/src/lib/mcp-task-runtime.js +0 -11
- package/src/lib/mcp-tool-metadata.js +1 -0
- package/src/lib/model-decision.js +43 -0
- package/src/lib/plugin-runtime/marketplace-command-source.js +53 -12
- package/src/lib/plugin-runtime/remote-source.js +9 -5
- package/src/lib/runnable-provider.js +15 -4
- package/src/lib/runner-lifecycle-metrics.js +20 -18
- package/src/lib/session-persistence-failure.js +7 -1
- package/src/lib/session-plan-approval.js +77 -0
- package/src/lib/session-transcript-history.js +48 -0
- package/src/lib/status-line.cjs +29 -3
- package/src/lib/status-line.js +31 -11
- package/src/lib/sub-agent-context.js +16 -0
- package/src/lib/sub-agent-registry.js +1 -0
- package/src/lib/task-record.js +64 -29
- package/src/repl/agent-repl.js +16 -2
- package/src/runtime/agent-core.js +81 -2
- package/src/runtime/fallback-model.js +11 -1
- package/src/runtime/headless-runner.js +35 -0
- package/src/runtime/headless-stream.js +101 -9
- package/src/assets/web-panel/assets/Providers-CNKCrJbY.css +0 -1
- package/src/assets/web-panel/assets/Providers-lEDu4Qdj.js +0 -1
- package/src/assets/web-panel/assets/index-BlS3EjXM.js +0 -1
- package/src/assets/web-panel/assets/index-DwIMwROa.js +0 -1
|
@@ -248,6 +248,34 @@ export function createSessionTranscriptHistoryProjection(
|
|
|
248
248
|
if (ordinal !== count || source !== physical)
|
|
249
249
|
throw new Error("Transcript history replay did not match its selection");
|
|
250
250
|
}
|
|
251
|
+
|
|
252
|
+
function forkMessages(authority) {
|
|
253
|
+
const messages = [];
|
|
254
|
+
let bytes = 0;
|
|
255
|
+
let found = false;
|
|
256
|
+
visitSelected(authority, (message, event, index) => {
|
|
257
|
+
if (found) return;
|
|
258
|
+
const selected =
|
|
259
|
+
branch.afterMessage === `${sessionId}:${event.hash}:${index}`;
|
|
260
|
+
const reply =
|
|
261
|
+
message.role === "assistant" &&
|
|
262
|
+
transcriptTextParts(message.content).some((part) => part.trim());
|
|
263
|
+
if (selected && !reply)
|
|
264
|
+
throw new Error("A fork boundary must be an assistant reply");
|
|
265
|
+
if (message.role === "user" || reply) {
|
|
266
|
+
const copy = { role: message.role, content: message.content };
|
|
267
|
+
bytes += Buffer.byteLength(JSON.stringify(copy), "utf8");
|
|
268
|
+
if (bytes > 8 * 1024 * 1024 || messages.length >= 32768)
|
|
269
|
+
throw new Error("The selected history prefix exceeds the fork limit");
|
|
270
|
+
messages.push(copy);
|
|
271
|
+
}
|
|
272
|
+
found = selected;
|
|
273
|
+
});
|
|
274
|
+
if (!found)
|
|
275
|
+
throw new Error("The selected reply is unavailable in verified history");
|
|
276
|
+
return branch.consume(messages);
|
|
277
|
+
}
|
|
278
|
+
|
|
251
279
|
return {
|
|
252
280
|
accept(event) {
|
|
253
281
|
if (!HASH.test(event.hash))
|
|
@@ -329,6 +357,7 @@ export function createSessionTranscriptHistoryProjection(
|
|
|
329
357
|
},
|
|
330
358
|
finish(authority) {
|
|
331
359
|
branchImport.finish();
|
|
360
|
+
if (branch?.afterMessage) return forkMessages(authority);
|
|
332
361
|
if (branch) {
|
|
333
362
|
const prefix = origins.branchPrefix(
|
|
334
363
|
branch.messages,
|
|
@@ -469,3 +498,22 @@ export function readSessionTranscriptHistory(sessionId, options = {}) {
|
|
|
469
498
|
createSessionTranscriptHistoryProjection(sessionId, options),
|
|
470
499
|
);
|
|
471
500
|
}
|
|
501
|
+
|
|
502
|
+
export function withTranscriptForkMessages(sessionId, messageId, consume) {
|
|
503
|
+
const prefix = `${sessionId}:`;
|
|
504
|
+
if (
|
|
505
|
+
typeof messageId !== "string" ||
|
|
506
|
+
!messageId.startsWith(prefix) ||
|
|
507
|
+
!/^[a-f0-9]{64}:[0-9]{1,8}$/u.test(messageId.slice(prefix.length)) ||
|
|
508
|
+
typeof consume !== "function" ||
|
|
509
|
+
consume.constructor?.name === "AsyncFunction"
|
|
510
|
+
)
|
|
511
|
+
throw new Error("A verified transcript message id is required");
|
|
512
|
+
return readVerifiedProjection(sessionId, () =>
|
|
513
|
+
createSessionTranscriptHistoryProjection(
|
|
514
|
+
sessionId,
|
|
515
|
+
{},
|
|
516
|
+
{ afterMessage: messageId, consume },
|
|
517
|
+
),
|
|
518
|
+
);
|
|
519
|
+
}
|
package/src/lib/status-line.cjs
CHANGED
|
@@ -59,6 +59,19 @@ function loadStatusLineConfig({ cwd = process.cwd(), settingsFile } = {}) {
|
|
|
59
59
|
return cfg && cfg.command ? cfg : null;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
function loadStatusLineContextThreshold({
|
|
63
|
+
cwd = process.cwd(),
|
|
64
|
+
settingsFile,
|
|
65
|
+
} = {}) {
|
|
66
|
+
let threshold;
|
|
67
|
+
for (const data of _deps.readSettings(cwd, settingsFile)) {
|
|
68
|
+
const value = data?.statusLine?.contextUsageThreshold;
|
|
69
|
+
if (typeof value === "number" && value >= 0 && value <= 100)
|
|
70
|
+
threshold = value;
|
|
71
|
+
}
|
|
72
|
+
return threshold;
|
|
73
|
+
}
|
|
74
|
+
|
|
62
75
|
/**
|
|
63
76
|
* Build the JSON context handed to the status-line command on stdin (and used
|
|
64
77
|
* by the built-in renderer). Carries context-window usage so a custom command —
|
|
@@ -77,12 +90,16 @@ function buildContext({
|
|
|
77
90
|
taskState = null,
|
|
78
91
|
approvalsPending = 0,
|
|
79
92
|
mcpErrors = 0,
|
|
93
|
+
scheduleEndsAt,
|
|
80
94
|
contextUsageThreshold,
|
|
81
95
|
} = {}) {
|
|
82
96
|
const used = Math.max(0, Number(usedTokens) || 0);
|
|
83
97
|
const window = Math.max(0, Number(contextWindow) || 0);
|
|
84
98
|
const pct = window > 0 ? Math.min(100, Math.round((used / window) * 100)) : 0;
|
|
85
|
-
const threshold = Math.max(
|
|
99
|
+
const threshold = Math.max(
|
|
100
|
+
0,
|
|
101
|
+
Math.min(100, Number(contextUsageThreshold) || 0),
|
|
102
|
+
);
|
|
86
103
|
const context = { used_tokens: used, window, pct };
|
|
87
104
|
if (contextUsageThreshold !== undefined) {
|
|
88
105
|
context.visible = window > 0 && pct >= threshold;
|
|
@@ -101,11 +118,17 @@ function buildContext({
|
|
|
101
118
|
context,
|
|
102
119
|
turn: Math.max(0, Number(turn) || 0),
|
|
103
120
|
};
|
|
104
|
-
if (
|
|
121
|
+
if (
|
|
122
|
+
taskState ||
|
|
123
|
+
Number(approvalsPending) > 0 ||
|
|
124
|
+
Number(mcpErrors) > 0 ||
|
|
125
|
+
scheduleEndsAt
|
|
126
|
+
) {
|
|
105
127
|
result.task = {
|
|
106
128
|
state: taskState || null,
|
|
107
129
|
approvals_pending: Math.max(0, Number(approvalsPending) || 0),
|
|
108
130
|
mcp_errors: Math.max(0, Number(mcpErrors) || 0),
|
|
131
|
+
...(scheduleEndsAt ? { schedule_ends_at: scheduleEndsAt } : {}),
|
|
109
132
|
};
|
|
110
133
|
}
|
|
111
134
|
return result;
|
|
@@ -169,7 +192,7 @@ function renderDefaultStatusLine(context = {}) {
|
|
|
169
192
|
parts.push(
|
|
170
193
|
`⛁ ${formatTokens(c.used_tokens)}/${formatTokens(c.window)} (${c.pct}%)`,
|
|
171
194
|
);
|
|
172
|
-
} else if (c.used_tokens > 0) {
|
|
195
|
+
} else if (c.visible !== false && c.used_tokens > 0) {
|
|
173
196
|
parts.push(`⛁ ${formatTokens(c.used_tokens)}`);
|
|
174
197
|
}
|
|
175
198
|
const task = context.task || {};
|
|
@@ -177,6 +200,8 @@ function renderDefaultStatusLine(context = {}) {
|
|
|
177
200
|
if (task.approvals_pending > 0)
|
|
178
201
|
parts.push(`approvals ${task.approvals_pending}`);
|
|
179
202
|
if (task.mcp_errors > 0) parts.push(`mcp errors ${task.mcp_errors}`);
|
|
203
|
+
if (task.schedule_ends_at)
|
|
204
|
+
parts.push(`schedule ends ${task.schedule_ends_at}`);
|
|
180
205
|
if (context.cwd) parts.push(shortenPath(context.cwd));
|
|
181
206
|
if (context.turn) parts.push(`turn ${context.turn}`);
|
|
182
207
|
return parts.join(" · ");
|
|
@@ -283,6 +308,7 @@ function getStatusLine({
|
|
|
283
308
|
|
|
284
309
|
module.exports = {
|
|
285
310
|
loadStatusLineConfig,
|
|
311
|
+
loadStatusLineContextThreshold,
|
|
286
312
|
buildContext,
|
|
287
313
|
renderStatusLine,
|
|
288
314
|
getStatusLine,
|
package/src/lib/status-line.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import statusLine from "./status-line.cjs";
|
|
2
2
|
import executionBroker from "./process-execution-broker/index.js";
|
|
3
3
|
import { collectTaskRecords } from "./task-record.js";
|
|
4
|
+
import { listMcpTaskRecords } from "./mcp-task-journal.js";
|
|
4
5
|
|
|
5
6
|
const brokerRunner = executionBroker.spawnSync.bind(executionBroker);
|
|
6
7
|
|
|
@@ -12,14 +13,28 @@ export function renderStatusLine(config, context, options = {}) {
|
|
|
12
13
|
});
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
export function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
export function buildContext(options = {}) {
|
|
17
|
+
let mcpTasks = [];
|
|
18
|
+
if (options.sessionId) {
|
|
19
|
+
try {
|
|
20
|
+
mcpTasks = listMcpTaskRecords(options.sessionId);
|
|
21
|
+
} catch {
|
|
22
|
+
// A new session can render a prompt before its transcript is created.
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const records = collectTaskRecords({ mcpTasks });
|
|
26
|
+
const waiting =
|
|
27
|
+
records.find((task) => task.waitingOn) ??
|
|
28
|
+
records.find((task) => task.state === "paused");
|
|
29
|
+
const schedule = records
|
|
30
|
+
.filter(
|
|
31
|
+
(task) => task.source === "schedule" && task.endsAt && !task.terminal,
|
|
32
|
+
)
|
|
33
|
+
.sort((a, b) => a.endsAt.localeCompare(b.endsAt))[0];
|
|
34
|
+
return statusLine.buildContext({
|
|
21
35
|
...options,
|
|
22
|
-
taskState: options.taskState
|
|
36
|
+
taskState: options.taskState ?? waiting?.state ?? null,
|
|
37
|
+
scheduleEndsAt: options.scheduleEndsAt ?? schedule?.endsAt,
|
|
23
38
|
approvalsPending:
|
|
24
39
|
options.approvalsPending ??
|
|
25
40
|
records.filter((task) => task.waitingOn === "approval").length,
|
|
@@ -27,14 +42,19 @@ export function getStatusLine(options = {}) {
|
|
|
27
42
|
options.mcpErrors ??
|
|
28
43
|
records.filter((task) => task.source === "mcp" && task.state === "failed")
|
|
29
44
|
.length,
|
|
30
|
-
runProcess:
|
|
31
|
-
options.runProcess || statusLine._deps.runProcess || brokerRunner,
|
|
32
45
|
});
|
|
33
46
|
}
|
|
34
47
|
|
|
48
|
+
export function getStatusLine(options = {}) {
|
|
49
|
+
const config = options.config || statusLine.loadStatusLineConfig(options);
|
|
50
|
+
return config
|
|
51
|
+
? renderStatusLine(config, buildContext(options), options)
|
|
52
|
+
: null;
|
|
53
|
+
}
|
|
54
|
+
|
|
35
55
|
export const {
|
|
36
56
|
loadStatusLineConfig,
|
|
37
|
-
|
|
57
|
+
loadStatusLineContextThreshold,
|
|
38
58
|
formatTokens,
|
|
39
59
|
shortenPath,
|
|
40
60
|
renderDefaultStatusLine,
|
|
@@ -43,4 +63,4 @@ export const {
|
|
|
43
63
|
_deps,
|
|
44
64
|
} = statusLine;
|
|
45
65
|
|
|
46
|
-
export default { ...statusLine, renderStatusLine, getStatusLine };
|
|
66
|
+
export default { ...statusLine, buildContext, renderStatusLine, getStatusLine };
|
|
@@ -297,6 +297,7 @@ export class SubAgentContext {
|
|
|
297
297
|
|
|
298
298
|
// LLM options for chatWithTools
|
|
299
299
|
this._llmOptions = options.llmOptions || {};
|
|
300
|
+
this.modelDecision = this._llmOptions.modelDecision || null;
|
|
300
301
|
|
|
301
302
|
// Optional progress callback for streaming events to consumers
|
|
302
303
|
this._onProgress = options.onProgress || null;
|
|
@@ -448,7 +449,12 @@ export class SubAgentContext {
|
|
|
448
449
|
}
|
|
449
450
|
|
|
450
451
|
this._running = true;
|
|
452
|
+
const releaseTransports = [];
|
|
451
453
|
try {
|
|
454
|
+
for (const client of new Set([this._mcpHostClient, this._mcpClient])) {
|
|
455
|
+
if (typeof client?.retainSubagentTransport === "function")
|
|
456
|
+
releaseTransports.push(client.retainSubagentTransport());
|
|
457
|
+
}
|
|
452
458
|
this._activateAbortLinks(loopOptions.signal || null);
|
|
453
459
|
|
|
454
460
|
// If worktree isolation is enabled, wrap execution in isolated worktree.
|
|
@@ -477,6 +483,7 @@ export class SubAgentContext {
|
|
|
477
483
|
this._running = false;
|
|
478
484
|
this._deactivateAbortLinks();
|
|
479
485
|
this._releaseSessionBudget();
|
|
486
|
+
await Promise.all(releaseTransports.map((release) => release()));
|
|
480
487
|
}
|
|
481
488
|
}
|
|
482
489
|
|
|
@@ -690,6 +697,14 @@ export class SubAgentContext {
|
|
|
690
697
|
if (Array.isArray(toolSelection.enabledToolNames))
|
|
691
698
|
options.exactToolNames = true;
|
|
692
699
|
options.subAgentContract = this.subAgentContract;
|
|
700
|
+
options.agentId = this.id;
|
|
701
|
+
options.parentAgentId =
|
|
702
|
+
this._llmOptions.decisionParentTaskId || this.parentId || null;
|
|
703
|
+
const onModelDecision = options.onModelDecision;
|
|
704
|
+
options.onModelDecision = (event) => {
|
|
705
|
+
this.modelDecision = event.modelDecision;
|
|
706
|
+
onModelDecision?.(event);
|
|
707
|
+
};
|
|
693
708
|
if (!this._memoryEnabled || this.subAgentContract?.memory === false) {
|
|
694
709
|
// Apply the same tighten-only contract to canonical recall after overrides.
|
|
695
710
|
options.contextMemoryRecall = false;
|
|
@@ -1599,6 +1614,7 @@ export class SubAgentContext {
|
|
|
1599
1614
|
iterationCount: this._iterationCount,
|
|
1600
1615
|
createdAt: this.createdAt,
|
|
1601
1616
|
completedAt: this.completedAt,
|
|
1617
|
+
...(this.modelDecision ? { modelDecision: this.modelDecision } : {}),
|
|
1602
1618
|
recoveryBinding: this.recoveryBinding(),
|
|
1603
1619
|
worktree: this._worktreePath
|
|
1604
1620
|
? { path: this._worktreePath, branch: this._worktreeBranch }
|
|
@@ -104,6 +104,7 @@ export class SubAgentRegistry {
|
|
|
104
104
|
id: subCtx.id,
|
|
105
105
|
parentId: subCtx.parentId,
|
|
106
106
|
role: subCtx.role,
|
|
107
|
+
...(subCtx.modelDecision ? { modelDecision: subCtx.modelDecision } : {}),
|
|
107
108
|
task: subCtx.task,
|
|
108
109
|
status: subCtx.status,
|
|
109
110
|
summary: result?.summary || "(no summary)",
|
package/src/lib/task-record.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { listBackgroundShellTasks } from "../runtime/agent-core.js";
|
|
8
8
|
import { AgentScheduleStore } from "./agent-schedule-store.js";
|
|
9
|
+
import { SubAgentRegistry } from "./sub-agent-registry.js";
|
|
9
10
|
|
|
10
11
|
export const TASK_SOURCES = Object.freeze([
|
|
11
12
|
"background-shell",
|
|
@@ -48,6 +49,12 @@ function normalizeState(value, fallback = "unknown") {
|
|
|
48
49
|
.trim()
|
|
49
50
|
.toLowerCase();
|
|
50
51
|
if (TASK_STATES.includes(state)) return state;
|
|
52
|
+
if (["needs_input", "awaiting_input"].includes(state))
|
|
53
|
+
return "input_required";
|
|
54
|
+
if (["blocked", "waiting_permission"].includes(state)) return "waiting";
|
|
55
|
+
if (["aborted", "canceled", "stopped"].includes(state)) return "cancelled";
|
|
56
|
+
if (["created", "queued", "scheduled", "prepared"].includes(state))
|
|
57
|
+
return "pending";
|
|
51
58
|
if (
|
|
52
59
|
[
|
|
53
60
|
"active",
|
|
@@ -72,18 +79,19 @@ function normalizeState(value, fallback = "unknown") {
|
|
|
72
79
|
].includes(state)
|
|
73
80
|
)
|
|
74
81
|
return "completed";
|
|
75
|
-
if (["error", "timeout"].includes(state)) return "failed";
|
|
82
|
+
if (["error", "timeout", "lost"].includes(state)) return "failed";
|
|
76
83
|
return fallback;
|
|
77
84
|
}
|
|
78
85
|
|
|
79
86
|
function timestamp(value) {
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return
|
|
86
|
-
|
|
87
|
+
if (
|
|
88
|
+
!(value instanceof Date) &&
|
|
89
|
+
typeof value !== "number" &&
|
|
90
|
+
typeof value !== "string"
|
|
91
|
+
)
|
|
92
|
+
return null;
|
|
93
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
94
|
+
return Number.isFinite(date.getTime()) ? date.toISOString() : null;
|
|
87
95
|
}
|
|
88
96
|
|
|
89
97
|
function stableId(value, fallback) {
|
|
@@ -107,23 +115,35 @@ export function toTaskRecord(value, source = "unknown", options = {}) {
|
|
|
107
115
|
? "running"
|
|
108
116
|
: "unknown",
|
|
109
117
|
);
|
|
110
|
-
const createdAt = timestamp(
|
|
118
|
+
const createdAt = timestamp(
|
|
119
|
+
input.createdAt ?? input.created_at ?? input.startedAt,
|
|
120
|
+
);
|
|
111
121
|
const lastEventAt = timestamp(
|
|
112
122
|
input.lastEventAt ??
|
|
113
123
|
input.lastUpdatedAt ??
|
|
114
124
|
input.updatedAt ??
|
|
125
|
+
input.endedAt ??
|
|
115
126
|
input.lastHeartbeat ??
|
|
116
127
|
createdAt,
|
|
117
128
|
);
|
|
118
129
|
const endsAt = timestamp(input.endsAt ?? input.expiresAt ?? input.expiryAt);
|
|
130
|
+
const taskId = stableId(
|
|
131
|
+
input,
|
|
132
|
+
options.fallbackId || `${normalizedSource}-unknown`,
|
|
133
|
+
);
|
|
134
|
+
let stopPath = input.cancelPath ?? input.stop ?? null;
|
|
135
|
+
if (Object.hasOwn(input, "stopPath")) stopPath = input.stopPath;
|
|
136
|
+
else if (!stopPath && !TERMINAL.has(state)) {
|
|
137
|
+
if (normalizedSource === "background-shell")
|
|
138
|
+
stopPath = `check_shell --kill ${taskId}`;
|
|
139
|
+
if (normalizedSource === "schedule")
|
|
140
|
+
stopPath = `cc agenda cancel ${taskId}`;
|
|
141
|
+
}
|
|
119
142
|
const record = {
|
|
120
|
-
taskId
|
|
121
|
-
input,
|
|
122
|
-
options.fallbackId || `${normalizedSource}-unknown`,
|
|
123
|
-
),
|
|
143
|
+
taskId,
|
|
124
144
|
// Legacy aliases keep existing `/tasks` callers working while new
|
|
125
145
|
// consumers use the explicit canonical names below.
|
|
126
|
-
id:
|
|
146
|
+
id: taskId,
|
|
127
147
|
parentTaskId: first(input.parentTaskId ?? input.parentId, null),
|
|
128
148
|
permissionProfileDigest: first(input.permissionProfileDigest, null),
|
|
129
149
|
modelDecision: first(input.modelDecision, null),
|
|
@@ -137,29 +157,23 @@ export function toTaskRecord(value, source = "unknown", options = {}) {
|
|
|
137
157
|
input.waitingFor ??
|
|
138
158
|
(state === "input_required"
|
|
139
159
|
? "input"
|
|
140
|
-
:
|
|
160
|
+
: input.status === "waiting_permission"
|
|
141
161
|
? "approval"
|
|
142
162
|
: null),
|
|
143
163
|
null,
|
|
144
164
|
),
|
|
145
|
-
stopPath:
|
|
146
|
-
input.stopPath ??
|
|
147
|
-
input.cancelPath ??
|
|
148
|
-
input.stop ??
|
|
149
|
-
(normalizedSource === "background-shell"
|
|
150
|
-
? `check_shell --kill ${stableId(input, "unknown")}`
|
|
151
|
-
: normalizedSource === "schedule"
|
|
152
|
-
? `cc agenda cancel ${stableId(input, "unknown")}`
|
|
153
|
-
: null),
|
|
154
|
-
null,
|
|
155
|
-
),
|
|
165
|
+
stopPath: stopPath ?? null,
|
|
156
166
|
label: first(
|
|
157
167
|
input.label ?? input.description ?? input.command ?? input.prompt,
|
|
158
168
|
null,
|
|
159
169
|
),
|
|
160
170
|
createdAt,
|
|
161
171
|
nextRunAt: timestamp(input.nextRunAt ?? input.nextAt ?? input.dueAt),
|
|
162
|
-
expiresAction:
|
|
172
|
+
expiresAction:
|
|
173
|
+
input.expiresAction ??
|
|
174
|
+
input.onExpire ??
|
|
175
|
+
(normalizedSource === "schedule" && endsAt ? "retire" : null),
|
|
176
|
+
...(input.orphanRisk === true ? { orphanRisk: true } : {}),
|
|
163
177
|
terminal: TERMINAL.has(state),
|
|
164
178
|
rawSource: normalizedSource === "unknown" ? input : undefined,
|
|
165
179
|
};
|
|
@@ -214,11 +228,25 @@ export function collectTaskRecords(options = {}) {
|
|
|
214
228
|
options.sources && typeof options.sources === "object"
|
|
215
229
|
? options.sources
|
|
216
230
|
: {};
|
|
231
|
+
const agentTasks = options.agentTasks ?? sourceRows.agent;
|
|
232
|
+
const agents = agentTasks ?? read("agent", undefined);
|
|
233
|
+
const registry = SubAgentRegistry.getInstance();
|
|
234
|
+
const subAgents = [...registry.getActive(), ...registry.getHistory()].map(
|
|
235
|
+
(agent) => ({
|
|
236
|
+
id: agent.id,
|
|
237
|
+
parentTaskId: agent.parentId,
|
|
238
|
+
status: agent.status,
|
|
239
|
+
createdAt: agent.createdAt,
|
|
240
|
+
endedAt: agent.completedAt,
|
|
241
|
+
modelDecision: agent.modelDecision,
|
|
242
|
+
label: agent.role,
|
|
243
|
+
}),
|
|
244
|
+
);
|
|
217
245
|
const rows = [
|
|
218
246
|
...mapList(background, "background-shell", options),
|
|
219
247
|
...mapList(read("mcp", options.mcpTasks ?? sourceRows.mcp), "mcp", options),
|
|
220
248
|
...mapList(
|
|
221
|
-
|
|
249
|
+
[...(Array.isArray(agents) ? agents : []), ...subAgents],
|
|
222
250
|
"agent",
|
|
223
251
|
options,
|
|
224
252
|
),
|
|
@@ -242,7 +270,14 @@ export function collectTaskRecords(options = {}) {
|
|
|
242
270
|
}
|
|
243
271
|
const records = rows.map((record) => {
|
|
244
272
|
if (record.endsAt && Date.parse(record.endsAt) <= now && !record.terminal) {
|
|
245
|
-
return Object.freeze({
|
|
273
|
+
return Object.freeze({
|
|
274
|
+
...record,
|
|
275
|
+
state: "expired",
|
|
276
|
+
status: "expired",
|
|
277
|
+
waitingOn: null,
|
|
278
|
+
stopPath: null,
|
|
279
|
+
terminal: true,
|
|
280
|
+
});
|
|
246
281
|
}
|
|
247
282
|
return record;
|
|
248
283
|
});
|
package/src/repl/agent-repl.js
CHANGED
|
@@ -3756,6 +3756,7 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
3756
3756
|
// a readline confirm prompt. agent-core's run_shell branch gates
|
|
3757
3757
|
// MEDIUM/HIGH-risk commands against the session's policy tier
|
|
3758
3758
|
// (strict / trusted / autopilot).
|
|
3759
|
+
let _renderStatus = null;
|
|
3759
3760
|
try {
|
|
3760
3761
|
const { getApprovalGate } =
|
|
3761
3762
|
await import("../lib/session-core-singletons.js");
|
|
@@ -3802,6 +3803,11 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
3802
3803
|
const q = (p) => new Promise((res) => rlConfirm.question(p, res));
|
|
3803
3804
|
const cmd = args?.command ? ` ${args.command}` : "";
|
|
3804
3805
|
const promise = (async () => {
|
|
3806
|
+
const status = _renderStatus?.({
|
|
3807
|
+
taskState: "waiting",
|
|
3808
|
+
approvalsPending: 1,
|
|
3809
|
+
});
|
|
3810
|
+
if (status) process.stdout.write(status + "\n");
|
|
3805
3811
|
const res = await questionWithIdleTimeout(
|
|
3806
3812
|
q,
|
|
3807
3813
|
chalk.yellow(
|
|
@@ -5801,15 +5807,17 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
5801
5807
|
let _ctxRequestWindow = null;
|
|
5802
5808
|
let _turnCount = 0;
|
|
5803
5809
|
const _costStore = newCostStore(); // running token spend for `/cost`
|
|
5804
|
-
let _renderStatus = null;
|
|
5805
5810
|
try {
|
|
5806
5811
|
const slm = await import("../lib/status-line.js");
|
|
5807
5812
|
const _sl = slm.default || slm;
|
|
5808
5813
|
const _slCfg = _sl.loadStatusLineConfig({ cwd: process.cwd() });
|
|
5814
|
+
const _statusThreshold = _sl.loadStatusLineContextThreshold({
|
|
5815
|
+
cwd: process.cwd(),
|
|
5816
|
+
});
|
|
5809
5817
|
_customStatus = !!_slCfg;
|
|
5810
5818
|
const _slDisabled = _sl.isStatusLineDisabled({ cwd: process.cwd() });
|
|
5811
5819
|
if (_slDisabled) _statusLineEnabled = false;
|
|
5812
|
-
_renderStatus = () => {
|
|
5820
|
+
_renderStatus = (taskStatus = {}) => {
|
|
5813
5821
|
if (!_statusLineEnabled) return null;
|
|
5814
5822
|
try {
|
|
5815
5823
|
const context = _sl.buildContext({
|
|
@@ -5821,6 +5829,8 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
5821
5829
|
contextWindow:
|
|
5822
5830
|
_ctxRequestWindow ?? getContextWindow(_curModel, provider, options),
|
|
5823
5831
|
turn: _turnCount,
|
|
5832
|
+
contextUsageThreshold: _statusThreshold,
|
|
5833
|
+
...taskStatus,
|
|
5824
5834
|
});
|
|
5825
5835
|
// Custom command wins; otherwise the built-in context-usage render.
|
|
5826
5836
|
if (_slCfg) {
|
|
@@ -10165,6 +10175,10 @@ async function startAgentReplInWorkspaceOwned(
|
|
|
10165
10175
|
sideEffects: _replSideEffects,
|
|
10166
10176
|
denialLog: _recentDenials,
|
|
10167
10177
|
persistRecentDenials: true,
|
|
10178
|
+
onModelDecision:
|
|
10179
|
+
useJsonl && sessionId
|
|
10180
|
+
? (event) => appendEvent(sessionId, "model_decision", event)
|
|
10181
|
+
: undefined,
|
|
10168
10182
|
permissionMode: _sessionTier,
|
|
10169
10183
|
// Seed the subagent-contract CEILING with the interactive session's
|
|
10170
10184
|
// CURRENT approval tier (mapped back to a permission mode) so a spawned
|
|
@@ -276,6 +276,11 @@ import {
|
|
|
276
276
|
} from "../lib/provider-http-error.js";
|
|
277
277
|
import { buildPermissionDecision } from "../lib/permission-decision.js";
|
|
278
278
|
import { permissionProfileDigest } from "../lib/permission-profile.js";
|
|
279
|
+
import {
|
|
280
|
+
modelDecisionTaskEvent,
|
|
281
|
+
normalizeModelDecision,
|
|
282
|
+
readModelFallback,
|
|
283
|
+
} from "../lib/model-decision.js";
|
|
279
284
|
import { resolveSandboxPolicyPath } from "../lib/agent-sandbox.js";
|
|
280
285
|
import {
|
|
281
286
|
beginManagedToolCheckpoint,
|
|
@@ -11510,6 +11515,8 @@ async function _executeSpawnSubAgent(args, ctx) {
|
|
|
11510
11515
|
? { evolutionIngress: ctx.evolutionIngress }
|
|
11511
11516
|
: {}),
|
|
11512
11517
|
model: mdModel || parentLlm.model || undefined,
|
|
11518
|
+
modelDecision: mdModel ? null : parentLlm.modelDecision,
|
|
11519
|
+
decisionParentTaskId: parentLlm.decisionTaskId || parentSessionId,
|
|
11513
11520
|
// Preserve the host's optional event channel across every nesting level.
|
|
11514
11521
|
// It is observational only: child hooks/tools must never depend on a
|
|
11515
11522
|
// headless consumer being connected.
|
|
@@ -15533,6 +15540,9 @@ export async function* agentLoop(messages, options) {
|
|
|
15533
15540
|
model: options.model || null,
|
|
15534
15541
|
baseUrl: options.baseUrl || null,
|
|
15535
15542
|
apiKey: options.apiKey || null,
|
|
15543
|
+
modelDecision: options.modelDecision || null,
|
|
15544
|
+
onModelDecision: options.onModelDecision,
|
|
15545
|
+
decisionTaskId: options.agentId || options.sessionId || runId,
|
|
15536
15546
|
...(typeof options.onUsageBoundary === "function"
|
|
15537
15547
|
? { onUsageBoundary: options.onUsageBoundary }
|
|
15538
15548
|
: {}),
|
|
@@ -15719,6 +15729,31 @@ export async function* agentLoop(messages, options) {
|
|
|
15719
15729
|
// as unknown. A workflow-bound request does the same: a hidden fallback
|
|
15720
15730
|
// would be a second physical provider attempt under one durable effect.
|
|
15721
15731
|
// Legacy sessions keep the existing self-healing behavior.
|
|
15732
|
+
const configuredToolLlm = toolContext.llmOptions;
|
|
15733
|
+
const hasCustomCompaction =
|
|
15734
|
+
typeof options.compactionLlmQuery === "function" ||
|
|
15735
|
+
Object.hasOwn(options, "_autoCompactor");
|
|
15736
|
+
let compactionOptions = options;
|
|
15737
|
+
let lastModelDecision = null;
|
|
15738
|
+
const reportModelDecision = (decision) => {
|
|
15739
|
+
if (typeof options.onModelDecision !== "function" || !decision) return;
|
|
15740
|
+
const fingerprint = JSON.stringify(decision);
|
|
15741
|
+
if (lastModelDecision === fingerprint) return;
|
|
15742
|
+
lastModelDecision = fingerprint;
|
|
15743
|
+
try {
|
|
15744
|
+
options.onModelDecision(
|
|
15745
|
+
modelDecisionTaskEvent(
|
|
15746
|
+
options.agentId || options.sessionId || runId,
|
|
15747
|
+
decision,
|
|
15748
|
+
options.parentAgentId,
|
|
15749
|
+
),
|
|
15750
|
+
);
|
|
15751
|
+
} catch {
|
|
15752
|
+
// A model decision receipt is observational.
|
|
15753
|
+
}
|
|
15754
|
+
};
|
|
15755
|
+
reportModelDecision(options.modelDecision);
|
|
15756
|
+
|
|
15722
15757
|
if (
|
|
15723
15758
|
options.runnableProviderFallback !== false &&
|
|
15724
15759
|
options.strictUsageTelemetry !== true &&
|
|
@@ -16079,10 +16114,10 @@ export async function* agentLoop(messages, options) {
|
|
|
16079
16114
|
let compactionUsageCall = null;
|
|
16080
16115
|
let compactionObserverFailure = null;
|
|
16081
16116
|
try {
|
|
16082
|
-
const compactor = await _getAutoCompactor(
|
|
16117
|
+
const compactor = await _getAutoCompactor(compactionOptions);
|
|
16083
16118
|
if (compactor && compactor.shouldAutoCompact(messages)) {
|
|
16084
16119
|
options.onBeforeCompaction?.();
|
|
16085
|
-
compactionUsageState = _autoCompactionUsageState(
|
|
16120
|
+
compactionUsageState = _autoCompactionUsageState(compactionOptions);
|
|
16086
16121
|
compactionUsageState.calls = [];
|
|
16087
16122
|
compactionUsageState.callSequence = budget.consumed;
|
|
16088
16123
|
// This is the canonical pre-provider authority snapshot. A local
|
|
@@ -17307,6 +17342,50 @@ export async function* agentLoop(messages, options) {
|
|
|
17307
17342
|
throw error;
|
|
17308
17343
|
}
|
|
17309
17344
|
|
|
17345
|
+
const fallback = readModelFallback(result);
|
|
17346
|
+
toolContext.llmOptions = fallback
|
|
17347
|
+
? {
|
|
17348
|
+
...configuredToolLlm,
|
|
17349
|
+
...fallback.route,
|
|
17350
|
+
modelDecision: fallback.decision,
|
|
17351
|
+
}
|
|
17352
|
+
: configuredToolLlm;
|
|
17353
|
+
if (fallback) {
|
|
17354
|
+
reportModelDecision(fallback.decision);
|
|
17355
|
+
const needsCompactionRoute =
|
|
17356
|
+
compactionOptions === options ||
|
|
17357
|
+
Object.entries(fallback.route).some(
|
|
17358
|
+
([key, value]) => compactionOptions[key] !== value,
|
|
17359
|
+
);
|
|
17360
|
+
if (
|
|
17361
|
+
!hasCustomCompaction &&
|
|
17362
|
+
needsCompactionRoute &&
|
|
17363
|
+
(!configuredChatFn ||
|
|
17364
|
+
(await import("./fallback-model.js")).isCanonicalFallbackChatFn(
|
|
17365
|
+
configuredChatFn,
|
|
17366
|
+
))
|
|
17367
|
+
) {
|
|
17368
|
+
compactionOptions = {
|
|
17369
|
+
...options,
|
|
17370
|
+
...fallback.route,
|
|
17371
|
+
chatFn: undefined,
|
|
17372
|
+
};
|
|
17373
|
+
delete compactionOptions._autoCompactor;
|
|
17374
|
+
}
|
|
17375
|
+
} else {
|
|
17376
|
+
if (compactionOptions !== options || lastModelDecision !== null) {
|
|
17377
|
+
reportModelDecision(
|
|
17378
|
+
configuredToolLlm.modelDecision ||
|
|
17379
|
+
normalizeModelDecision({
|
|
17380
|
+
requestedModel: options.model,
|
|
17381
|
+
actualModel: result?.model || options.model,
|
|
17382
|
+
provider: options.provider,
|
|
17383
|
+
}),
|
|
17384
|
+
);
|
|
17385
|
+
}
|
|
17386
|
+
compactionOptions = options;
|
|
17387
|
+
}
|
|
17388
|
+
|
|
17310
17389
|
if (result?.finishReason === "length") {
|
|
17311
17390
|
// Settle the completed physical request above before any decision. Never
|
|
17312
17391
|
// execute even syntactically valid calls from an incomplete generation,
|
|
@@ -36,6 +36,7 @@ import { BUILT_IN_PROVIDERS } from "../lib/llm-providers.js";
|
|
|
36
36
|
import { throwIfAborted } from "../lib/abort-utils.js";
|
|
37
37
|
import { isTerminalModelFailure } from "../lib/model-failure-policy.js";
|
|
38
38
|
import { captureAgentEvolutionIngress } from "../lib/evolution/agent-evolution-ingress.js";
|
|
39
|
+
import { rememberModelFallback } from "../lib/model-decision.js";
|
|
39
40
|
|
|
40
41
|
// Only this module can register a canonical transport. Function properties,
|
|
41
42
|
// wrappers and proxies cannot confer this authority.
|
|
@@ -53,6 +54,10 @@ export function captureCanonicalFallbackChatFn(value, evolutionIngress) {
|
|
|
53
54
|
return owned.ingress === ingress ? value : owned.bind(ingress);
|
|
54
55
|
}
|
|
55
56
|
|
|
57
|
+
export function isCanonicalFallbackChatFn(value) {
|
|
58
|
+
return CANONICAL_FALLBACKS.has(value);
|
|
59
|
+
}
|
|
60
|
+
|
|
56
61
|
// Claude Code caps the fallback chain at 3 backups; mirror that here so a
|
|
57
62
|
// mis-configured comma list can't fan out into an unbounded retry storm.
|
|
58
63
|
const MAX_FALLBACK_MODELS = 3;
|
|
@@ -397,7 +402,12 @@ export function makeFallbackChatFn(opts = {}) {
|
|
|
397
402
|
: { ...options, model: target.model };
|
|
398
403
|
try {
|
|
399
404
|
throwIfAborted(signal);
|
|
400
|
-
return
|
|
405
|
+
return rememberModelFallback(
|
|
406
|
+
await baseChatFn(messages, hopOptions),
|
|
407
|
+
options,
|
|
408
|
+
hopOptions,
|
|
409
|
+
"configured-fallback",
|
|
410
|
+
);
|
|
401
411
|
} catch (nextErr) {
|
|
402
412
|
err = nextErr;
|
|
403
413
|
}
|