chainlesschain 0.166.160 → 0.166.162

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.
Files changed (219) hide show
  1. package/README.md +15 -3
  2. package/package.json +1 -1
  3. package/src/assets/linux-subreaper/linux-arm64/manifest.json +1 -1
  4. package/src/assets/linux-subreaper/linux-x64/manifest.json +1 -1
  5. package/src/assets/web-panel/.build-hash +1 -1
  6. package/src/assets/web-panel/assets/{AIOps-CraNGNgc.js → AIOps-CNhLuFiB.js} +1 -1
  7. package/src/assets/web-panel/assets/{ActionButton-C0jn6sgg.js → ActionButton-BVPZKoT-.js} +1 -1
  8. package/src/assets/web-panel/assets/{Analytics-DVrR_wjl.js → Analytics-Ct2gNxKd.js} +1 -1
  9. package/src/assets/web-panel/assets/{AppLayout-CeKP8mgC.js → AppLayout-BnaA21bl.js} +1 -1
  10. package/src/assets/web-panel/assets/{Artifacts-OHCS9wLN.js → Artifacts-C5_NWBGG.js} +1 -1
  11. package/src/assets/web-panel/assets/{Audit-C77b6pDl.js → Audit-y_MUbjLt.js} +1 -1
  12. package/src/assets/web-panel/assets/{BackgroundAgents-CefiwCgM.js → BackgroundAgents-C63koq2N.js} +1 -1
  13. package/src/assets/web-panel/assets/{Backup-B-5KmWNA.js → Backup-Yo9hJesU.js} +1 -1
  14. package/src/assets/web-panel/assets/{BaseInput-C3bJ1Qlc.js → BaseInput-uAsHWcNC.js} +1 -1
  15. package/src/assets/web-panel/assets/{Chat-DBahPz9B.js → Chat-B9zs3I4L.js} +1 -1
  16. package/src/assets/web-panel/assets/{ChatBubbleRenderer-J4BVVrXZ.js → ChatBubbleRenderer-fzKRaTLd.js} +1 -1
  17. package/src/assets/web-panel/assets/{Checkbox-w856fzfY.js → Checkbox-BKHInWqb.js} +1 -1
  18. package/src/assets/web-panel/assets/{Codegen-XKmsL_C3.js → Codegen-gB60liCi.js} +1 -1
  19. package/src/assets/web-panel/assets/{Col-B37-gr7d.js → Col-B_iw_PIR.js} +1 -1
  20. package/src/assets/web-panel/assets/{Community-DdahlN0f.js → Community-BTwbiBFd.js} +1 -1
  21. package/src/assets/web-panel/assets/{Compact-oKnoE-9_.js → Compact-D851uR8p.js} +1 -1
  22. package/src/assets/web-panel/assets/{Compliance-CnCRlOB_.js → Compliance-DQOQgtbc.js} +1 -1
  23. package/src/assets/web-panel/assets/{Cowork-D3Vr5R3E.js → Cowork-DzaEZbbm.js} +1 -1
  24. package/src/assets/web-panel/assets/{Cron-X46CdLRQ.js → Cron-Df2xjxzZ.js} +1 -1
  25. package/src/assets/web-panel/assets/{Crosschain-CV3_6jVw.js → Crosschain-D7eewpJM.js} +1 -1
  26. package/src/assets/web-panel/assets/{DID-Kr6H4WKr.js → DID-Dg9OtFGl.js} +1 -1
  27. package/src/assets/web-panel/assets/{Dashboard-Bj4usrhx.js → Dashboard-B3dt4SYd.js} +1 -1
  28. package/src/assets/web-panel/assets/{Dropdown-V3DPV21D.js → Dropdown-C0vEIluP.js} +1 -1
  29. package/src/assets/web-panel/assets/{EmailListRenderer-8MCX0Y4b.js → EmailListRenderer-BLe81BHF.js} +1 -1
  30. package/src/assets/web-panel/assets/{EvolutionSettings-SUoykpjc.js → EvolutionSettings-CvN_ORvk.js} +1 -1
  31. package/src/assets/web-panel/assets/{FamilyGuardDashboard-C0iE0T9x.js → FamilyGuardDashboard-xFaUcq6i.js} +1 -1
  32. package/src/assets/web-panel/assets/{Federation-CSU3kpK2.js → Federation-DqGa6L60.js} +1 -1
  33. package/src/assets/web-panel/assets/{FormItemContext-Bcv2XJNw.js → FormItemContext-DumZjtkF.js} +1 -1
  34. package/src/assets/web-panel/assets/{GenericCardRenderer-PdEqwQZd.js → GenericCardRenderer-CXxweSPC.js} +1 -1
  35. package/src/assets/web-panel/assets/{Git-CVZ0MSRN.js → Git-CF3OyEuV.js} +1 -1
  36. package/src/assets/web-panel/assets/{Governance-CF64-eGc.js → Governance-DGBoeFcm.js} +1 -1
  37. package/src/assets/web-panel/assets/{Inference-DJ1J40Th.js → Inference-CveIk_lk.js} +1 -1
  38. package/src/assets/web-panel/assets/{KnowledgeGraph-Cf3ULXmf.js → KnowledgeGraph-msqPEvc0.js} +1 -1
  39. package/src/assets/web-panel/assets/{Logs-DM_RbXG_.js → Logs-zAhceodz.js} +1 -1
  40. package/src/assets/web-panel/assets/{MarkdownRenderer-B2wey_j8.js → MarkdownRenderer-DwP1jZr3.js} +1 -1
  41. package/src/assets/web-panel/assets/{Marketplace-tqdANxLa.js → Marketplace-CIOc62w1.js} +1 -1
  42. package/src/assets/web-panel/assets/{McpTools-BiSYAtKB.js → McpTools-Ye1FSjo-.js} +1 -1
  43. package/src/assets/web-panel/assets/{Memory-hOvA-Tqp.js → Memory-COGlkLtO.js} +1 -1
  44. package/src/assets/web-panel/assets/{MobileBridge-CIpwBK6G.js → MobileBridge-BVkRPQSG.js} +1 -1
  45. package/src/assets/web-panel/assets/{MobileProjects-DMpV98oD.js → MobileProjects-AtAH5Uoo.js} +1 -1
  46. package/src/assets/web-panel/assets/{Mtc-CVoJZMuY.js → Mtc-CqiDh60D.js} +1 -1
  47. package/src/assets/web-panel/assets/{MtcAudit-Dz9YsrvV.js → MtcAudit-CruLSC3f.js} +1 -1
  48. package/src/assets/web-panel/assets/{Multisig-CamW3sTK.js → Multisig-YH7hDXe7.js} +1 -1
  49. package/src/assets/web-panel/assets/{NLProgramming-DlZo8q6W.js → NLProgramming-DT6rmEY_.js} +1 -1
  50. package/src/assets/web-panel/assets/{Notes-DZJSYibx.js → Notes-Cjp991_L.js} +1 -1
  51. package/src/assets/web-panel/assets/{NotificationSettings-BSlIIGOM.js → NotificationSettings-CMv9uHtV.js} +1 -1
  52. package/src/assets/web-panel/assets/{OrderTableRenderer-Bo9vImgU.js → OrderTableRenderer-wp1zrUZe.js} +1 -1
  53. package/src/assets/web-panel/assets/{Organization-B1sBf0Kk.js → Organization-CZGBH2f-.js} +1 -1
  54. package/src/assets/web-panel/assets/{Overflow-CD8GUNOV.js → Overflow-C5yb6LcI.js} +1 -1
  55. package/src/assets/web-panel/assets/{P2P-CeaIuSa9.js → P2P-C-3smRsS.js} +1 -1
  56. package/src/assets/web-panel/assets/{PdhVaultBrowser-DCOkcRse.js → PdhVaultBrowser-D9e1lYe_.js} +2 -2
  57. package/src/assets/web-panel/assets/{Permissions-DQCZnN_y.js → Permissions-YrtBFosR.js} +1 -1
  58. package/src/assets/web-panel/assets/{PersonalDataHub-D_9PtVvT.js → PersonalDataHub-CPIlHXmG.js} +1 -1
  59. package/src/assets/web-panel/assets/{Pipeline-BawUxj0i.js → Pipeline-BAUQ4UL0.js} +1 -1
  60. package/src/assets/web-panel/assets/{Privacy-CPyw19Ai.js → Privacy-Du1mfYpr.js} +1 -1
  61. package/src/assets/web-panel/assets/{ProjectInit-GDtYLbL6.js → ProjectInit-DTZZPmI6.js} +1 -1
  62. package/src/assets/web-panel/assets/{ProjectSettings-DhmGKXVL.js → ProjectSettings-D5vGoWmg.js} +1 -1
  63. package/src/assets/web-panel/assets/{Projects-O2spSrud.js → Projects-CPyfgipD.js} +1 -1
  64. package/src/assets/web-panel/assets/Providers-BCo_GB4k.css +1 -0
  65. package/src/assets/web-panel/assets/Providers-DoJDphwe.js +1 -0
  66. package/src/assets/web-panel/assets/{QrScannerModal-Dcqm-i6j.js → QrScannerModal-DKezd77c.js} +1 -1
  67. package/src/assets/web-panel/assets/{QuickAsk-C6uPAeAE.js → QuickAsk-Dj5x0jA3.js} +1 -1
  68. package/src/assets/web-panel/assets/{Recommend-ClVlhga7.js → Recommend-D_Bk2N6M.js} +1 -1
  69. package/src/assets/web-panel/assets/{RemoteSession-2raJDKUb.js → RemoteSession-DoACu1j-.js} +1 -1
  70. package/src/assets/web-panel/assets/{Reputation-BYWC8k3t.js → Reputation-CHY48udA.js} +1 -1
  71. package/src/assets/web-panel/assets/{Row-Bv7Y68ai.js → Row-B2ji1NaC.js} +1 -1
  72. package/src/assets/web-panel/assets/{RssFeed-Ba54MKvz.js → RssFeed-Cko4TT8o.js} +1 -1
  73. package/src/assets/web-panel/assets/{Search-B9EkRkZK.js → Search-D4Jq_y26.js} +1 -1
  74. package/src/assets/web-panel/assets/{Security-DuXQGU4o.js → Security-CRj9UHDB.js} +1 -1
  75. package/src/assets/web-panel/assets/{Services-DJnCtY8x.js → Services-fZPfKCJD.js} +1 -1
  76. package/src/assets/web-panel/assets/{Skeleton-BVDdtf_S.js → Skeleton-C_H68DxY.js} +1 -1
  77. package/src/assets/web-panel/assets/{Skills-DGkYCesm.js → Skills-Bm4nTGzx.js} +1 -1
  78. package/src/assets/web-panel/assets/{Sla-CHND6lwC.js → Sla-BBhY5p8N.js} +1 -1
  79. package/src/assets/web-panel/assets/{SpeechSettings-Bg0Bgy9c.js → SpeechSettings-B0fvb--L.js} +1 -1
  80. package/src/assets/web-panel/assets/{SyncSettings-DwtcZ2Ml.js → SyncSettings-0HlhIGJ-.js} +1 -1
  81. package/src/assets/web-panel/assets/{Tasks-BoHc0cP2.js → Tasks-Bo-k7A9g.js} +1 -1
  82. package/src/assets/web-panel/assets/{Templates-DAMs4m8X.js → Templates-BRTC7AUC.js} +1 -1
  83. package/src/assets/web-panel/assets/{Tenant-DkVQbOzT.js → Tenant-BpIv9shV.js} +1 -1
  84. package/src/assets/web-panel/assets/{Terminal-BTOLM8Yu.js → Terminal-Bt147VT7.js} +1 -1
  85. package/src/assets/web-panel/assets/{TimelineRenderer-BO5ZyxUU.js → TimelineRenderer-CBSVcKf5.js} +1 -1
  86. package/src/assets/web-panel/assets/{Tokens-D0LjCtSA.js → Tokens-JCGWdOyZ.js} +1 -1
  87. package/src/assets/web-panel/assets/{Trigger-DgGXg9VB.js → Trigger-D2GaPoYt.js} +1 -1
  88. package/src/assets/web-panel/assets/{Trust-BAEQrND-.js → Trust-BGicfDbx.js} +1 -1
  89. package/src/assets/web-panel/assets/{UkeySign-TtBclFRw.js → UkeySign-DJLwi-VO.js} +1 -1
  90. package/src/assets/web-panel/assets/{VideoEditing-ByxvpIpS.js → VideoEditing-JdhxB9I3.js} +1 -1
  91. package/src/assets/web-panel/assets/{Wallet-CTa7jqur.js → Wallet-B8OqhQC-.js} +1 -1
  92. package/src/assets/web-panel/assets/{WebAuthn-oHbCSjrD.js → WebAuthn-0qeF3jwV.js} +1 -1
  93. package/src/assets/web-panel/assets/{WorkflowEditor-DQKQAdUS.js → WorkflowEditor-Br7NIU4X.js} +1 -1
  94. package/src/assets/web-panel/assets/{chat-BcCU2FuK.js → chat-CdI93Uj-.js} +1 -1
  95. package/src/assets/web-panel/assets/{colors-BcXAFjHT.js → colors-hE8M4e8h.js} +1 -1
  96. package/src/assets/web-panel/assets/{compact-item-GhZzQppm.js → compact-item-BUhXh46K.js} +1 -1
  97. package/src/assets/web-panel/assets/{createContext-Bc6nwTUy.js → createContext-B5ccktpR.js} +1 -1
  98. package/src/assets/web-panel/assets/{hasIn-DRH8Xt0Y.js → hasIn-CptjIqui.js} +1 -1
  99. package/src/assets/web-panel/assets/{index-BDIN9KWp.js → index-0aHON-dJ.js} +1 -1
  100. package/src/assets/web-panel/assets/{index-mqlLcSgP.js → index-0dLpjWdQ.js} +1 -1
  101. package/src/assets/web-panel/assets/{index-gvsatTPZ.js → index-B2gEgzUF.js} +1 -1
  102. package/src/assets/web-panel/assets/{index-CB1Thk9t.js → index-B4h7Yyll.js} +1 -1
  103. package/src/assets/web-panel/assets/{index-lEDZUWRO.js → index-B6aiDNJf.js} +1 -1
  104. package/src/assets/web-panel/assets/{index-DQnXn3vs.js → index-BB4StyBV.js} +1 -1
  105. package/src/assets/web-panel/assets/{index-60aCmptm.js → index-BBnyQBDE.js} +1 -1
  106. package/src/assets/web-panel/assets/{index-DCgr2bDL.js → index-BCmJolrc.js} +1 -1
  107. package/src/assets/web-panel/assets/{index-BaUmYzDB.js → index-Bb2rTuMK.js} +1 -1
  108. package/src/assets/web-panel/assets/{index-Bebe5WYu.js → index-BktXJbRU.js} +1 -1
  109. package/src/assets/web-panel/assets/{index-wnmY4P7_.js → index-BsaY5ENn.js} +1 -1
  110. package/src/assets/web-panel/assets/{index-B7hScRVB.js → index-Bw1sj494.js} +1 -1
  111. package/src/assets/web-panel/assets/{index-DOBzu5UO.js → index-BzOVaC2t.js} +1 -1
  112. package/src/assets/web-panel/assets/{index-D6B_ELy6.js → index-C7sbKKIt.js} +1 -1
  113. package/src/assets/web-panel/assets/{index-BOquBdmK.js → index-CE7uX7n3.js} +1 -1
  114. package/src/assets/web-panel/assets/{index-DCCEt-pU.js → index-CGgx5Z0d.js} +1 -1
  115. package/src/assets/web-panel/assets/{index-DoRIPzwv.js → index-CNSnbjTb.js} +1 -1
  116. package/src/assets/web-panel/assets/{index-BQ6b5kJR.js → index-CV50XvUJ.js} +1 -1
  117. package/src/assets/web-panel/assets/{index-D08s-CJ_.js → index-Ca1U3jvV.js} +1 -1
  118. package/src/assets/web-panel/assets/{index-DXip1xUj.js → index-CgPmwwdZ.js} +1 -1
  119. package/src/assets/web-panel/assets/{index-WrMfehhj.js → index-CiQ8T-Wj.js} +1 -1
  120. package/src/assets/web-panel/assets/{index-owU4npmQ.js → index-CmEKreTW.js} +1 -1
  121. package/src/assets/web-panel/assets/index-CwLYWliJ.js +1 -0
  122. package/src/assets/web-panel/assets/{index-Dzh9Ud2R.js → index-Cwf0XTa8.js} +3 -3
  123. package/src/assets/web-panel/assets/{index-Cexk6Y1r.js → index-D5i229Gh.js} +1 -1
  124. package/src/assets/web-panel/assets/{index-BdOccG1D.js → index-DG40DMAk.js} +1 -1
  125. package/src/assets/web-panel/assets/{index-CtC-B6Zy.js → index-DG7-sHcw.js} +1 -1
  126. package/src/assets/web-panel/assets/{index-BFFyqn3k.js → index-DLmj9zeI.js} +1 -1
  127. package/src/assets/web-panel/assets/index-DMF7BcWf.js +1 -0
  128. package/src/assets/web-panel/assets/{index-DzhMohzV.js → index-DO3kRQnh.js} +1 -1
  129. package/src/assets/web-panel/assets/{index-Bb5XCEKT.js → index-DRr1ldeO.js} +1 -1
  130. package/src/assets/web-panel/assets/{index-IW9dUJK_.js → index-DUWmPd0O.js} +1 -1
  131. package/src/assets/web-panel/assets/{index-D9QfJDQg.js → index-Dc8ZP-rA.js} +1 -1
  132. package/src/assets/web-panel/assets/{index-BsRmNZCk.js → index-DhdxOKQ4.js} +1 -1
  133. package/src/assets/web-panel/assets/{index-CSHz8UnK.js → index-Dxmu8cZG.js} +1 -1
  134. package/src/assets/web-panel/assets/{index-DNi_t23H.js → index-LQEMp44F.js} +1 -1
  135. package/src/assets/web-panel/assets/{index-DOtNt1m7.js → index-WVQ05cSo.js} +1 -1
  136. package/src/assets/web-panel/assets/{index-D6pWvvp-.js → index-f3OaRY6m.js} +1 -1
  137. package/src/assets/web-panel/assets/{index-BEQha9Ur.js → index-ri-ZBdPd.js} +1 -1
  138. package/src/assets/web-panel/assets/{initDefaultProps-DfHPrIA5.js → initDefaultProps-DTj0zdLt.js} +1 -1
  139. package/src/assets/web-panel/assets/{motion-CCzrK3c5.js → motion-DnsNb0QQ.js} +1 -1
  140. package/src/assets/web-panel/assets/{move-B2uu6I9f.js → move-Bf_g7tYL.js} +1 -1
  141. package/src/assets/web-panel/assets/{mtc-parser-DtFu2-C_.js → mtc-parser-D2gv6Yis.js} +1 -1
  142. package/src/assets/web-panel/assets/{omit-BFjLuAHb.js → omit-BCRtdA1N.js} +1 -1
  143. package/src/assets/web-panel/assets/{pickAttrs-DfsjYq45.js → pickAttrs-COqVNaT6.js} +1 -1
  144. package/src/assets/web-panel/assets/{placementArrow-CDdYIVXw.js → placementArrow--K1Q_0hw.js} +1 -1
  145. package/src/assets/web-panel/assets/{responsiveObserve-CfrplFjn.js → responsiveObserve-BrMnRoWy.js} +1 -1
  146. package/src/assets/web-panel/assets/{slide-DHNX5Xwt.js → slide-DPlpqM13.js} +1 -1
  147. package/src/assets/web-panel/assets/{statusUtils-BI-C3SSk.js → statusUtils-Ddby7oUh.js} +1 -1
  148. package/src/assets/web-panel/assets/{styleChecker-C5Y3Oyy2.js → styleChecker-BV5JCSKe.js} +1 -1
  149. package/src/assets/web-panel/assets/{useFlexGapSupport-atF45w0U.js → useFlexGapSupport-DeLyWVJE.js} +1 -1
  150. package/src/assets/web-panel/assets/{useFs-C4M8-xm9.js → useFs-DIXerI3H.js} +1 -1
  151. package/src/assets/web-panel/assets/{usePersonalDataHub-jjZdnfs_.js → usePersonalDataHub-BvhJbBzh.js} +1 -1
  152. package/src/assets/web-panel/assets/{vnode-BRTSCmU3.js → vnode-DGQZc27k.js} +1 -1
  153. package/src/assets/web-panel/assets/{zoom-BaS5ZYRC.js → zoom-BcHWSA8z.js} +1 -1
  154. package/src/assets/web-panel/index.html +1 -1
  155. package/src/command-help-index.json +3 -3
  156. package/src/commands/agenda.js +23 -2
  157. package/src/commands/agent.js +56 -21
  158. package/src/commands/ccron.js +1 -0
  159. package/src/commands/llm.js +13 -0
  160. package/src/commands/loop.js +34 -1
  161. package/src/commands/mcp.js +13 -3
  162. package/src/commands/plugin.js +48 -25
  163. package/src/commands/session.js +104 -87
  164. package/src/commands/setup.js +25 -16
  165. package/src/commands/skill.js +31 -6
  166. package/src/commands/status.js +19 -0
  167. package/src/commands/tasks.js +98 -2
  168. package/src/data/changelog.json +26 -0
  169. package/src/gateways/ws/message-dispatcher.js +5 -0
  170. package/src/harness/background-task-command-runner.js +23 -25
  171. package/src/harness/background-task-manager.js +63 -30
  172. package/src/harness/mcp-client.js +61 -22
  173. package/src/lib/background-agent-supervisor.js +3 -0
  174. package/src/lib/cowork-cron.js +115 -31
  175. package/src/lib/doctor-checkup.js +21 -0
  176. package/src/lib/execution-location-runner-lifecycle.js +81 -2
  177. package/src/lib/install-command-policy.js +23 -0
  178. package/src/lib/json-schema-output.js +12 -31
  179. package/src/lib/lk-catalog.js +4 -0
  180. package/src/lib/lk-model-catalog.json +36 -15
  181. package/src/lib/lk-public-catalog.cjs +92 -0
  182. package/src/lib/llm-channel-presets.js +2 -2
  183. package/src/lib/loop.js +30 -11
  184. package/src/lib/lsp/__tests__/code-intelligence.integration.test.js +17 -15
  185. package/src/lib/mcp-server-handle.js +24 -8
  186. package/src/lib/mcp-stateless-protocol.js +37 -8
  187. package/src/lib/mcp-task-journal.js +32 -2
  188. package/src/lib/mcp-task-runtime.js +0 -11
  189. package/src/lib/mcp-tool-metadata.js +1 -0
  190. package/src/lib/model-decision.js +43 -0
  191. package/src/lib/plan-mode.js +16 -0
  192. package/src/lib/plugin-runtime/install.js +111 -67
  193. package/src/lib/plugin-runtime/marketplace-command-source.js +53 -12
  194. package/src/lib/plugin-runtime/remote-source.js +9 -5
  195. package/src/lib/process-execution-broker/index.js +19 -9
  196. package/src/lib/public-ide-capability-manifest.js +88 -0
  197. package/src/lib/public-ide-capability-validation.js +24 -0
  198. package/src/lib/repl-denials.js +11 -0
  199. package/src/lib/runnable-provider.js +15 -4
  200. package/src/lib/runner-lifecycle-metrics.js +20 -18
  201. package/src/lib/search-command.js +13 -2
  202. package/src/lib/session-persistence-failure.js +7 -1
  203. package/src/lib/session-plan-approval.js +86 -0
  204. package/src/lib/session-transcript-history.js +48 -0
  205. package/src/lib/status-line.cjs +32 -5
  206. package/src/lib/status-line.js +31 -11
  207. package/src/lib/sub-agent-context.js +16 -0
  208. package/src/lib/sub-agent-registry.js +1 -0
  209. package/src/lib/task-record.js +76 -30
  210. package/src/repl/agent-repl.js +211 -35
  211. package/src/runtime/agent-core.js +118 -19
  212. package/src/runtime/fallback-model.js +11 -1
  213. package/src/runtime/headless-runner.js +95 -3
  214. package/src/runtime/headless-stream.js +151 -11
  215. package/src/workers/background-agent-worker.js +11 -10
  216. package/src/assets/web-panel/assets/Providers-CNKCrJbY.css +0 -1
  217. package/src/assets/web-panel/assets/Providers-lEDu4Qdj.js +0 -1
  218. package/src/assets/web-panel/assets/index-BlS3EjXM.js +0 -1
  219. package/src/assets/web-panel/assets/index-DwIMwROa.js +0 -1
@@ -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 (value == null) return null;
81
- if (value instanceof Date) return value.toISOString();
82
- if (typeof value === "number" && Number.isFinite(value))
83
- return new Date(value).toISOString();
84
- if (typeof value === "string" && Number.isFinite(Date.parse(value)))
85
- return new Date(value).toISOString();
86
- return null;
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,42 @@ export function toTaskRecord(value, source = "unknown", options = {}) {
107
115
  ? "running"
108
116
  : "unknown",
109
117
  );
110
- const createdAt = timestamp(input.createdAt ?? input.created_at);
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 nextRunAt = timestamp(input.nextRunAt ?? input.nextAt ?? input.dueAt);
131
+ const scheduleHasClosed =
132
+ normalizedSource === "schedule" &&
133
+ (TERMINAL.has(state) ||
134
+ (endsAt != null &&
135
+ nextRunAt != null &&
136
+ Date.parse(nextRunAt) >= Date.parse(endsAt)));
137
+ const taskId = stableId(
138
+ input,
139
+ options.fallbackId || `${normalizedSource}-unknown`,
140
+ );
141
+ let stopPath = input.cancelPath ?? input.stop ?? null;
142
+ if (Object.hasOwn(input, "stopPath")) stopPath = input.stopPath;
143
+ else if (!stopPath && !TERMINAL.has(state)) {
144
+ if (normalizedSource === "background-shell")
145
+ stopPath = `check_shell --kill ${taskId}`;
146
+ if (normalizedSource === "schedule")
147
+ stopPath = `cc agenda cancel ${taskId}`;
148
+ }
119
149
  const record = {
120
- taskId: stableId(
121
- input,
122
- options.fallbackId || `${normalizedSource}-unknown`,
123
- ),
150
+ taskId,
124
151
  // Legacy aliases keep existing `/tasks` callers working while new
125
152
  // consumers use the explicit canonical names below.
126
- id: stableId(input, options.fallbackId || `${normalizedSource}-unknown`),
153
+ id: taskId,
127
154
  parentTaskId: first(input.parentTaskId ?? input.parentId, null),
128
155
  permissionProfileDigest: first(input.permissionProfileDigest, null),
129
156
  modelDecision: first(input.modelDecision, null),
@@ -137,29 +164,26 @@ export function toTaskRecord(value, source = "unknown", options = {}) {
137
164
  input.waitingFor ??
138
165
  (state === "input_required"
139
166
  ? "input"
140
- : state === "waiting"
167
+ : input.status === "waiting_permission"
141
168
  ? "approval"
142
169
  : null),
143
170
  null,
144
171
  ),
145
- stopPath: first(
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
- ),
172
+ stopPath: stopPath ?? null,
156
173
  label: first(
157
174
  input.label ?? input.description ?? input.command ?? input.prompt,
158
175
  null,
159
176
  ),
160
177
  createdAt,
161
- nextRunAt: timestamp(input.nextRunAt ?? input.nextAt ?? input.dueAt),
162
- expiresAction: first(input.expiresAction ?? input.onExpire ?? null, null),
178
+ nextRunAt: scheduleHasClosed ? null : nextRunAt,
179
+ expiresAction:
180
+ input.expiresAction ??
181
+ input.onExpire ??
182
+ (normalizedSource === "schedule" && endsAt ? "retire" : null),
183
+ ...(input.orphanRisk === true ? { orphanRisk: true } : {}),
184
+ ...(Array.isArray(input.stopEvents) && input.stopEvents.length > 0
185
+ ? { stopEvents: input.stopEvents }
186
+ : {}),
163
187
  terminal: TERMINAL.has(state),
164
188
  rawSource: normalizedSource === "unknown" ? input : undefined,
165
189
  };
@@ -214,11 +238,25 @@ export function collectTaskRecords(options = {}) {
214
238
  options.sources && typeof options.sources === "object"
215
239
  ? options.sources
216
240
  : {};
241
+ const agentTasks = options.agentTasks ?? sourceRows.agent;
242
+ const agents = agentTasks ?? read("agent", undefined);
243
+ const registry = SubAgentRegistry.getInstance();
244
+ const subAgents = [...registry.getActive(), ...registry.getHistory()].map(
245
+ (agent) => ({
246
+ id: agent.id,
247
+ parentTaskId: agent.parentId,
248
+ status: agent.status,
249
+ createdAt: agent.createdAt,
250
+ endedAt: agent.completedAt,
251
+ modelDecision: agent.modelDecision,
252
+ label: agent.role,
253
+ }),
254
+ );
217
255
  const rows = [
218
256
  ...mapList(background, "background-shell", options),
219
257
  ...mapList(read("mcp", options.mcpTasks ?? sourceRows.mcp), "mcp", options),
220
258
  ...mapList(
221
- read("agent", options.agentTasks ?? sourceRows.agent),
259
+ [...(Array.isArray(agents) ? agents : []), ...subAgents],
222
260
  "agent",
223
261
  options,
224
262
  ),
@@ -242,7 +280,15 @@ export function collectTaskRecords(options = {}) {
242
280
  }
243
281
  const records = rows.map((record) => {
244
282
  if (record.endsAt && Date.parse(record.endsAt) <= now && !record.terminal) {
245
- return Object.freeze({ ...record, state: "expired", terminal: true });
283
+ return Object.freeze({
284
+ ...record,
285
+ state: "expired",
286
+ status: "expired",
287
+ waitingOn: null,
288
+ stopPath: null,
289
+ nextRunAt: null,
290
+ terminal: true,
291
+ });
246
292
  }
247
293
  return record;
248
294
  });
@@ -31,12 +31,17 @@ import fs from "fs";
31
31
  import os from "os";
32
32
  import path from "path";
33
33
  import { createHash, randomUUID } from "node:crypto";
34
+ import { isDeepStrictEqual } from "node:util";
34
35
  import { isPromise, isProxy } from "node:util/types";
35
36
  import { logger } from "../lib/logger.js";
36
37
  import { captureSkillRuntimeDependencies } from "../lib/evolution/skill-runtime-revalidation.js";
37
38
  import { captureAmbientExecutionLocation } from "../lib/execution-location-runtime.js";
38
39
  import { issueMcpStdioExecutionAuthority } from "../lib/mcp-stdio-execution-authority.js";
39
- import { getPlanModeManager, PlanState } from "../lib/plan-mode.js";
40
+ import { PlanModeManager, PlanState } from "../lib/plan-mode.js";
41
+ import {
42
+ openSessionPlan,
43
+ recordSessionPlanApproval,
44
+ } from "../lib/session-plan-approval.js";
40
45
  import { createVimState, feedNormalKey } from "../lib/repl-vim.js";
41
46
  import {
42
47
  analyzeContinuation,
@@ -839,9 +844,15 @@ export async function agentLoop(messages, options) {
839
844
  chalk.gray(` ⎌ checkpoint ${event.id} (before ${event.tool})\n`),
840
845
  );
841
846
  } else if (event.type === "tool-executing") {
847
+ const id = runtimeToolCallId(event.tool_use_id);
848
+ const planItem = options.planManager?.startPlanItemForTool(event.tool, {
849
+ toolUseId: id,
850
+ });
851
+ if (planItem?.error) throw new Error(planItem.error);
842
852
  const exec = {
843
- id: runtimeToolCallId(event.tool_use_id),
853
+ id,
844
854
  providerId: event.tool_use_id || null,
855
+ planItemId: planItem?.id,
845
856
  tool: event.tool,
846
857
  args: event.args,
847
858
  startedAt: options.now ? options.now() : Date.now(),
@@ -925,6 +936,14 @@ export async function agentLoop(messages, options) {
925
936
  options.sideEffects.persist();
926
937
  _currentSideEffectOpId = null;
927
938
  }
939
+ if (exec?.planItemId) {
940
+ const failed = Boolean(event.error || event.result?.error);
941
+ const settlement = options.planManager.settlePlanItem(exec.planItemId, {
942
+ success: !failed,
943
+ error: failed ? "Tool execution failed" : null,
944
+ });
945
+ if (settlement?.error) throw new Error(settlement.error);
946
+ }
928
947
  const durationMs =
929
948
  event.result?.toolTelemetryRecord?.durationMs ??
930
949
  (exec?.tool === event.tool
@@ -3229,6 +3248,7 @@ async function startAgentReplInWorkspaceOwned(
3229
3248
  let _replCleanupStarted = false;
3230
3249
  let _turnAbort = null;
3231
3250
  let _replOutputFailure = null;
3251
+ let _planApprovalFailure = null;
3232
3252
  const _requestReplOutputClose = (error) => {
3233
3253
  if (error && !_replOutputFailure) _replOutputFailure = error;
3234
3254
  if (error) {
@@ -3401,8 +3421,17 @@ async function startAgentReplInWorkspaceOwned(
3401
3421
  callModel,
3402
3422
  source: "model",
3403
3423
  });
3404
- const _runReplDirectTool = async (tool, args, { signal = null } = {}) => {
3424
+ const _runReplDirectTool = async (
3425
+ tool,
3426
+ args,
3427
+ { signal = null, approvedPlanExecution = false } = {},
3428
+ ) => {
3405
3429
  _runtimeLedgerTerminalLatch.assertOpen();
3430
+ if (planManager.executionLock && !approvedPlanExecution) {
3431
+ throw new Error(
3432
+ "Use the approved plan to run tools while its execution lock is active",
3433
+ );
3434
+ }
3406
3435
  try {
3407
3436
  const durableSessionId = resolveReplMeteredSessionId(useJsonl, sessionId);
3408
3437
  return await runReplDirectToolWithLedger({
@@ -3413,6 +3442,11 @@ async function startAgentReplInWorkspaceOwned(
3413
3442
  executeTool(name, toolArgs, {
3414
3443
  sessionId: durableSessionId,
3415
3444
  sessionBudget: _sessionBudget,
3445
+ planManager,
3446
+ approvalGate: _approvalGate,
3447
+ permissionRules: _permissionRules,
3448
+ permissionConfirm: _permissionConfirm,
3449
+ interactiveApproval: true,
3416
3450
  signal: combineReplSignals(signal, options.signal),
3417
3451
  }),
3418
3452
  now: options.now || Date.now,
@@ -3588,6 +3622,37 @@ async function startAgentReplInWorkspaceOwned(
3588
3622
  let db = null;
3589
3623
  let contextEngine = null;
3590
3624
  let sessionId = _startupJsonlResume?.sessionId || null;
3625
+ let planManager = new PlanModeManager();
3626
+ let planPermissionMode;
3627
+ const _recordPlanApproval = () => {
3628
+ if (planManager.memoryOnly) return true;
3629
+ try {
3630
+ recordSessionPlanApproval(planManager);
3631
+ return true;
3632
+ } catch (error) {
3633
+ _planApprovalFailure = error;
3634
+ logger.error("The plan approval receipt could not be persisted.");
3635
+ _replRl.close();
3636
+ return false;
3637
+ }
3638
+ };
3639
+ if (sessionId) {
3640
+ const plan = openSessionPlan(sessionId);
3641
+ if (
3642
+ plan.permissionMode &&
3643
+ options.permissionMode !== undefined &&
3644
+ !isDeepStrictEqual(
3645
+ parsePermissionModeArg(options.permissionMode),
3646
+ parsePermissionModeArg(plan.permissionMode),
3647
+ )
3648
+ ) {
3649
+ throw new Error(
3650
+ "Requested permission mode conflicts with the approved plan",
3651
+ );
3652
+ }
3653
+ planManager = plan.manager;
3654
+ planPermissionMode = plan.permissionMode;
3655
+ }
3591
3656
  const _replCompactPersistence = createReplCompactPersistence(
3592
3657
  _startupJsonlResume?.ok ? _startupJsonlResume.rebuiltMessages : [],
3593
3658
  );
@@ -3756,6 +3821,8 @@ async function startAgentReplInWorkspaceOwned(
3756
3821
  // a readline confirm prompt. agent-core's run_shell branch gates
3757
3822
  // MEDIUM/HIGH-risk commands against the session's policy tier
3758
3823
  // (strict / trusted / autopilot).
3824
+ let _renderStatus = null;
3825
+ let _managedSettings = null;
3759
3826
  try {
3760
3827
  const { getApprovalGate } =
3761
3828
  await import("../lib/session-core-singletons.js");
@@ -3802,6 +3869,11 @@ async function startAgentReplInWorkspaceOwned(
3802
3869
  const q = (p) => new Promise((res) => rlConfirm.question(p, res));
3803
3870
  const cmd = args?.command ? ` ${args.command}` : "";
3804
3871
  const promise = (async () => {
3872
+ const status = _renderStatus?.({
3873
+ taskState: "waiting",
3874
+ approvalsPending: 1,
3875
+ });
3876
+ if (status) process.stdout.write(status + "\n");
3805
3877
  const res = await questionWithIdleTimeout(
3806
3878
  q,
3807
3879
  chalk.yellow(
@@ -3902,6 +3974,7 @@ async function startAgentReplInWorkspaceOwned(
3902
3974
  await import("../lib/permission-authority.js");
3903
3975
  const permissionAuthorityOptions = { cwd: process.cwd() };
3904
3976
  const loaded = loadPermissionAuthority(permissionAuthorityOptions);
3977
+ _managedSettings = loaded.managed;
3905
3978
  _permissionRulesProvider = createPermissionRulesProvider(
3906
3979
  permissionAuthorityOptions,
3907
3980
  );
@@ -4145,6 +4218,9 @@ async function startAgentReplInWorkspaceOwned(
4145
4218
  }
4146
4219
  }
4147
4220
  }
4221
+ if (useJsonl && sessionId && planManager.memoryOnly) {
4222
+ planManager = new PlanModeManager({ sessionId });
4223
+ }
4148
4224
 
4149
4225
  // Phase H — register this session with session-core SessionManager so
4150
4226
  // `cc session lifecycle / park / unpark / end` can see and control it.
@@ -4876,7 +4952,16 @@ async function startAgentReplInWorkspaceOwned(
4876
4952
  }
4877
4953
 
4878
4954
  // Apply bundle approval policy to this session (after both gate and sessionId are ready)
4879
- if (_bundleResolved?.approvalPolicy?.default && _approvalGate && sessionId) {
4955
+ const { assertManagedPermissionMode } =
4956
+ await import("../lib/settings-loader.cjs");
4957
+ if (planPermissionMode)
4958
+ assertManagedPermissionMode(planPermissionMode, _managedSettings);
4959
+ if (
4960
+ !planManager.executionLock &&
4961
+ _bundleResolved?.approvalPolicy?.default &&
4962
+ _approvalGate &&
4963
+ sessionId
4964
+ ) {
4880
4965
  try {
4881
4966
  await _approvalGate.setSessionPolicy(
4882
4967
  sessionId,
@@ -4898,9 +4983,11 @@ async function startAgentReplInWorkspaceOwned(
4898
4983
  // trusted tier + the autoMode.decisions classifier. An explicit flag wins
4899
4984
  // over the bundle's approvalPolicy default. Unknown values are ignored here
4900
4985
  // (headless validates them; interactively we just keep the default tier).
4901
- if (options.permissionMode && _approvalGate && sessionId) {
4902
- const parsed = parsePermissionModeArg(options.permissionMode);
4903
- if (parsed && typeof _approvalGate.setSessionPolicy === "function") {
4986
+ if ((planPermissionMode || options.permissionMode) && sessionId) {
4987
+ const parsed = parsePermissionModeArg(
4988
+ planPermissionMode || options.permissionMode,
4989
+ );
4990
+ if (parsed && typeof _approvalGate?.setSessionPolicy === "function") {
4904
4991
  try {
4905
4992
  await _approvalGate.setSessionPolicy(sessionId, parsed.tier);
4906
4993
  await _approvalGate.awaitPersistence?.();
@@ -4908,9 +4995,17 @@ async function startAgentReplInWorkspaceOwned(
4908
4995
  parsed.auto ? "auto" : parsed.dontAsk ? "dontAsk" : parsed.tier,
4909
4996
  );
4910
4997
  } catch (error) {
4998
+ if (planManager.executionLock) throw error;
4911
4999
  logger.warn(`Approval policy was not persisted: ${error.message}`);
4912
5000
  }
5001
+ } else if (planManager.executionLock) {
5002
+ throw new Error("Cannot apply the approved plan's permission mode");
4913
5003
  }
5004
+ } else if (_approvalGate && sessionId) {
5005
+ const tier = parsePermissionTier(
5006
+ _approvalGate.getSessionPolicy?.(sessionId),
5007
+ );
5008
+ if (tier) setSessionTier(tier);
4914
5009
  }
4915
5010
 
4916
5011
  // Phase G #5 — inject top-K memory recall into system prompt for new sessions
@@ -5246,7 +5341,6 @@ async function startAgentReplInWorkspaceOwned(
5246
5341
  ? chalk.cyan("[N] ")
5247
5342
  : chalk.dim("[I] ")
5248
5343
  : "";
5249
- const planManager = getPlanModeManager();
5250
5344
  if (planManager.isActive()) {
5251
5345
  const state = planManager.state;
5252
5346
  if (state === PlanState.APPROVED || state === PlanState.EXECUTING) {
@@ -5627,6 +5721,7 @@ async function startAgentReplInWorkspaceOwned(
5627
5721
  if (isShiftTab) {
5628
5722
  _consumeReadlineKeypress(key);
5629
5723
  if (
5724
+ !planManager.executionLock &&
5630
5725
  _approvalGate &&
5631
5726
  sessionId &&
5632
5727
  typeof _approvalGate.setSessionPolicy === "function"
@@ -5801,15 +5896,17 @@ async function startAgentReplInWorkspaceOwned(
5801
5896
  let _ctxRequestWindow = null;
5802
5897
  let _turnCount = 0;
5803
5898
  const _costStore = newCostStore(); // running token spend for `/cost`
5804
- let _renderStatus = null;
5805
5899
  try {
5806
5900
  const slm = await import("../lib/status-line.js");
5807
5901
  const _sl = slm.default || slm;
5808
5902
  const _slCfg = _sl.loadStatusLineConfig({ cwd: process.cwd() });
5903
+ const _statusThreshold = _sl.loadStatusLineContextThreshold({
5904
+ cwd: process.cwd(),
5905
+ });
5809
5906
  _customStatus = !!_slCfg;
5810
5907
  const _slDisabled = _sl.isStatusLineDisabled({ cwd: process.cwd() });
5811
5908
  if (_slDisabled) _statusLineEnabled = false;
5812
- _renderStatus = () => {
5909
+ _renderStatus = (taskStatus = {}) => {
5813
5910
  if (!_statusLineEnabled) return null;
5814
5911
  try {
5815
5912
  const context = _sl.buildContext({
@@ -5821,6 +5918,8 @@ async function startAgentReplInWorkspaceOwned(
5821
5918
  contextWindow:
5822
5919
  _ctxRequestWindow ?? getContextWindow(_curModel, provider, options),
5823
5920
  turn: _turnCount,
5921
+ contextUsageThreshold: _statusThreshold,
5922
+ ...taskStatus,
5824
5923
  });
5825
5924
  // Custom command wins; otherwise the built-in context-usage render.
5826
5925
  if (_slCfg) {
@@ -7855,6 +7954,12 @@ async function startAgentReplInWorkspaceOwned(
7855
7954
  initialCandidate.sessionId,
7856
7955
  );
7857
7956
  if (!prepared.ok) throw prepared.error;
7957
+ const targetPlan = openSessionPlan(prepared.sessionId);
7958
+ if (targetPlan.permissionMode)
7959
+ assertManagedPermissionMode(
7960
+ targetPlan.permissionMode,
7961
+ _managedSettings,
7962
+ );
7858
7963
  const preparedSideEffects = _prepareReplSideEffects(
7859
7964
  prepared.sessionId,
7860
7965
  { recover: true },
@@ -7882,6 +7987,24 @@ async function startAgentReplInWorkspaceOwned(
7882
7987
  prepared.conversationMessages.at(-1)?.role === "user",
7883
7988
  logMessage: `Resumed JSONL session ${prepared.sessionId} (${prepared.rebuiltMessages.length} messages)`,
7884
7989
  });
7990
+ const targetMode = parsePermissionModeArg(
7991
+ targetPlan.permissionMode ||
7992
+ (reuseCurrentLease
7993
+ ? _sessionTier
7994
+ : _approvalGate?.getSessionPolicy?.(prepared.sessionId)) ||
7995
+ "strict",
7996
+ );
7997
+ if (typeof _approvalGate?.setSessionPolicy === "function") {
7998
+ await _approvalGate.setSessionPolicy(
7999
+ prepared.sessionId,
8000
+ targetMode.tier,
8001
+ );
8002
+ await _approvalGate.awaitPersistence?.();
8003
+ } else if (targetPlan.manager.executionLock) {
8004
+ throw new Error(
8005
+ "Cannot apply the approved plan's permission mode",
8006
+ );
8007
+ }
7885
8008
  const committed = commitPreparedReplJsonlResume(
7886
8009
  prepared,
7887
8010
  () => _applyPreparedResumeState(preparedState),
@@ -7896,6 +8019,14 @@ async function startAgentReplInWorkspaceOwned(
7896
8019
  }
7897
8020
  const previousLease = _replaceSessionHostLease(targetLease);
7898
8021
  adoptedTargetLease = true;
8022
+ planManager = targetPlan.manager;
8023
+ setSessionTier(
8024
+ targetMode.auto
8025
+ ? "auto"
8026
+ : targetMode.dontAsk
8027
+ ? "dontAsk"
8028
+ : targetMode.tier,
8029
+ );
7899
8030
  _replSideEffects = preparedSideEffects.sideEffects;
7900
8031
  if (preparedSideEffects.warning) {
7901
8032
  logger.warn(preparedSideEffects.warning);
@@ -8687,7 +8818,6 @@ async function startAgentReplInWorkspaceOwned(
8687
8818
 
8688
8819
  // Plan mode commands
8689
8820
  if (trimmed.startsWith("/plan")) {
8690
- const planManager = getPlanModeManager();
8691
8821
  const subCmd = trimmed.slice(5).trim();
8692
8822
 
8693
8823
  if (!subCmd || subCmd === "enter") {
@@ -8696,7 +8826,12 @@ async function startAgentReplInWorkspaceOwned(
8696
8826
  "Already in plan mode. Use /plan show, /plan approve, or /plan reject.",
8697
8827
  );
8698
8828
  } else {
8699
- planManager.enterPlanMode({ title: "Agent Plan" });
8829
+ const result = planManager.enterPlanMode({ title: "Agent Plan" });
8830
+ if (result.error) {
8831
+ logger.error(result.error);
8832
+ prompt();
8833
+ return;
8834
+ }
8700
8835
  logger.success(
8701
8836
  "Entered plan mode. Write tools are blocked until you approve the plan.",
8702
8837
  );
@@ -8762,24 +8897,36 @@ async function startAgentReplInWorkspaceOwned(
8762
8897
  logger.warn(`Advisor plan review skipped: ${error.message}`);
8763
8898
  }
8764
8899
  }
8765
- planManager.approvePlan();
8900
+ const approved = planManager.approvePlan({
8901
+ permissionMode: permissionModeForTier(_sessionTier),
8902
+ });
8903
+ if (approved.error) {
8904
+ logger.error(approved.error);
8905
+ prompt();
8906
+ return;
8907
+ }
8908
+ if (!_recordPlanApproval()) return;
8766
8909
  logger.success(
8767
8910
  `Plan approved! ${planManager.currentPlan.items.length} items ready for execution.`,
8768
8911
  );
8769
- logger.info(
8770
- "Write/execute tools are now unlocked. The AI can proceed.",
8771
- );
8912
+ logger.info("The AI can execute the approved plan items.");
8772
8913
  messages.push({
8773
8914
  role: "system",
8774
- content: `[PLAN APPROVED] The user has approved your plan with ${planManager.currentPlan.items.length} items. You can now use all tools including write_file, edit_file, run_shell, and run_skill. Execute the plan items in order.`,
8915
+ content:
8916
+ "[PLAN APPROVED] Execute the approved plan items in order. Request a plan revision before using a write or execution tool outside the approval.",
8775
8917
  });
8776
8918
  }
8777
8919
  } else if (subCmd === "reject" || subCmd === "no") {
8778
8920
  if (!planManager.isActive()) {
8779
8921
  logger.info("No plan to reject.");
8780
8922
  } else {
8781
- planManager.rejectPlan("User rejected");
8782
- logger.info("Plan rejected. Exited plan mode.");
8923
+ const wasApproved = Boolean(planManager.executionLock);
8924
+ const result = planManager.rejectPlan("User rejected");
8925
+ if (result.error) logger.error(result.error);
8926
+ else {
8927
+ if (wasApproved && !_recordPlanApproval()) return;
8928
+ logger.info("Plan rejected. Exited plan mode.");
8929
+ }
8783
8930
  }
8784
8931
  } else if (subCmd === "risk") {
8785
8932
  if (!planManager.isActive() || !planManager.currentPlan) {
@@ -8808,17 +8955,25 @@ async function startAgentReplInWorkspaceOwned(
8808
8955
  } else {
8809
8956
  logger.info("Executing plan items in DAG order...");
8810
8957
  try {
8811
- const { results, success } = await planManager.executePlan(
8812
- async (item) => {
8813
- if (item.tool && item.params) {
8814
- process.stdout.write(
8815
- chalk.gray(` [${item.tool}] ${item.title}\n`),
8816
- );
8817
- return await _runReplDirectTool(item.tool, item.params);
8818
- }
8819
- return { skipped: true };
8820
- },
8821
- );
8958
+ const execution = await planManager.executePlan(async (item) => {
8959
+ if (item.tool && item.params) {
8960
+ process.stdout.write(
8961
+ chalk.gray(` [${item.tool}] ${item.title}\n`),
8962
+ );
8963
+ const result = await _runReplDirectTool(
8964
+ item.tool,
8965
+ item.params,
8966
+ {
8967
+ approvedPlanExecution: true,
8968
+ },
8969
+ );
8970
+ if (result?.error) throw new Error(result.error);
8971
+ return result;
8972
+ }
8973
+ return { skipped: true };
8974
+ });
8975
+ if (execution.error) throw new Error(execution.error);
8976
+ const { results, success } = execution;
8822
8977
  for (const r of results) {
8823
8978
  const icon = r.success ? chalk.green("✓") : chalk.red("✗");
8824
8979
  logger.log(
@@ -8828,15 +8983,22 @@ async function startAgentReplInWorkspaceOwned(
8828
8983
  logger.info(
8829
8984
  `Plan execution ${success ? "completed" : "finished with errors"}.`,
8830
8985
  );
8831
- planManager.exitPlanMode({ savePlan: true });
8986
+ const exited = planManager.exitPlanMode({ savePlan: true });
8987
+ if (exited.error) throw new Error(exited.error);
8988
+ if (!_recordPlanApproval()) return;
8832
8989
  } catch (err) {
8833
8990
  logger.error(`Plan execution failed: ${err.message}`);
8834
8991
  }
8835
8992
  }
8836
8993
  } else if (subCmd === "exit") {
8837
8994
  if (planManager.isActive()) {
8838
- planManager.exitPlanMode({ savePlan: true });
8839
- logger.info("Exited plan mode.");
8995
+ const wasApproved = Boolean(planManager.executionLock);
8996
+ const result = planManager.exitPlanMode({ savePlan: true });
8997
+ if (result.error) logger.error(result.error);
8998
+ else {
8999
+ if (wasApproved && !_recordPlanApproval()) return;
9000
+ logger.info("Exited plan mode.");
9001
+ }
8840
9002
  } else {
8841
9003
  logger.info("Not in plan mode.");
8842
9004
  }
@@ -9239,6 +9401,10 @@ async function startAgentReplInWorkspaceOwned(
9239
9401
  "Usage: /permissions [strict|trusted|autopilot|auto|dontask] " +
9240
9402
  "(aliases: default · manual · accept-edits · bypass). No arg = show rules.",
9241
9403
  );
9404
+ } else if (planManager.executionLock) {
9405
+ logger.info(
9406
+ "The approved plan locks the current permission mode. Use /plan exit to release it.",
9407
+ );
9242
9408
  } else if (
9243
9409
  !_approvalGate ||
9244
9410
  !sessionId ||
@@ -10165,7 +10331,12 @@ async function startAgentReplInWorkspaceOwned(
10165
10331
  sideEffects: _replSideEffects,
10166
10332
  denialLog: _recentDenials,
10167
10333
  persistRecentDenials: true,
10334
+ onModelDecision:
10335
+ useJsonl && sessionId
10336
+ ? (event) => appendEvent(sessionId, "model_decision", event)
10337
+ : undefined,
10168
10338
  permissionMode: _sessionTier,
10339
+ planManager,
10169
10340
  // Seed the subagent-contract CEILING with the interactive session's
10170
10341
  // CURRENT approval tier (mapped back to a permission mode) so a spawned
10171
10342
  // sub-agent inherits/tightens from it (tighten-only), mirroring the
@@ -10954,7 +11125,10 @@ async function startAgentReplInWorkspaceOwned(
10954
11125
  if (_evolutionSession !== null) {
10955
11126
  try {
10956
11127
  await _evolutionSession.close(
10957
- _replOutputFailure || _runtimeLedgerTerminalLatch.error() || null,
11128
+ _replOutputFailure ||
11129
+ _planApprovalFailure ||
11130
+ _runtimeLedgerTerminalLatch.error() ||
11131
+ null,
10958
11132
  );
10959
11133
  } catch (error) {
10960
11134
  _replOutputFailure ||= error;
@@ -10964,7 +11138,9 @@ async function startAgentReplInWorkspaceOwned(
10964
11138
  ? _replOutputFailure.code === "EPIPE"
10965
11139
  ? 0
10966
11140
  : 1
10967
- : 0;
11141
+ : _planApprovalFailure
11142
+ ? 1
11143
+ : 0;
10968
11144
  outputScope.restore();
10969
11145
  process.exit(outputExitCode);
10970
11146
  });