@mindistryx/pi-arabic-runtime 0.0.0-stage → 1.0.0-beta.1

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 (450) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +26 -2
  3. package/THIRD-PARTY-NOTICES.md +17 -0
  4. package/arguments.mjs +20 -0
  5. package/extension/command.mjs +31 -0
  6. package/extension/extension.mjs +20 -0
  7. package/extension/mode.mjs +48 -0
  8. package/launcher.mjs +34 -0
  9. package/licenses/Apache-2.0.txt +201 -0
  10. package/licenses/Unicode-3.0.txt +39 -0
  11. package/licenses/_anthropic-ai_sdk-0.129.0-LICENSE +8 -0
  12. package/licenses/_aws-sdk_client-bedrock-runtime-3.1127.0-LICENSE +201 -0
  13. package/licenses/_aws-sdk_core-3.977.9-LICENSE +201 -0
  14. package/licenses/_aws-sdk_credential-provider-env-3.972.70-LICENSE +201 -0
  15. package/licenses/_aws-sdk_credential-provider-ini-3.973.15-LICENSE +201 -0
  16. package/licenses/_aws-sdk_credential-provider-node-3.972.82-LICENSE +201 -0
  17. package/licenses/_aws-sdk_credential-provider-process-3.972.70-LICENSE +201 -0
  18. package/licenses/_aws-sdk_credential-provider-sso-3.973.14-LICENSE +201 -0
  19. package/licenses/_aws-sdk_credential-provider-web-identity-3.972.76-LICENSE +201 -0
  20. package/licenses/_aws-sdk_eventstream-handler-node-3.972.34-LICENSE +201 -0
  21. package/licenses/_aws-sdk_middleware-eventstream-3.972.29-LICENSE +201 -0
  22. package/licenses/_aws-sdk_middleware-websocket-3.972.52-LICENSE +201 -0
  23. package/licenses/_aws-sdk_signature-v4-multi-region-3.996.46-LICENSE +201 -0
  24. package/licenses/_aws-sdk_token-providers-3.1116.0-LICENSE +201 -0
  25. package/licenses/_aws-sdk_token-providers-3.1127.0-LICENSE +201 -0
  26. package/licenses/_aws-sdk_types-3.974.5-LICENSE +201 -0
  27. package/licenses/_aws-sdk_xml-builder-3.972.40-LICENSE +201 -0
  28. package/licenses/_aws_lambda-invoke-store-0.3.0-LICENSE +175 -0
  29. package/licenses/_babel_runtime-7.29.10-LICENSE +22 -0
  30. package/licenses/_google_genai-3.6.1-LICENSE +202 -0
  31. package/licenses/_isaacs_nonrecursive-glob-match-1.1.0-LICENSE.md +55 -0
  32. package/licenses/_protobufjs_aspromise-1.1.2-LICENSE +26 -0
  33. package/licenses/_protobufjs_base64-1.1.2-LICENSE +26 -0
  34. package/licenses/_protobufjs_codegen-2.0.5-LICENSE +26 -0
  35. package/licenses/_protobufjs_eventemitter-1.1.1-LICENSE +26 -0
  36. package/licenses/_protobufjs_fetch-1.1.1-LICENSE +26 -0
  37. package/licenses/_protobufjs_float-1.0.2-LICENSE +26 -0
  38. package/licenses/_protobufjs_path-1.1.2-LICENSE +26 -0
  39. package/licenses/_protobufjs_pool-1.1.0-LICENSE +26 -0
  40. package/licenses/_protobufjs_utf8-1.1.1-LICENSE +26 -0
  41. package/licenses/_silvia-odwyer_photon-node-0.3.4-LICENSE.md +201 -0
  42. package/licenses/_smithy_core-3.33.3-LICENSE +201 -0
  43. package/licenses/_smithy_credential-provider-imds-4.5.2-LICENSE +201 -0
  44. package/licenses/_smithy_fetch-http-handler-5.8.0-LICENSE +201 -0
  45. package/licenses/_smithy_node-http-handler-4.12.1-LICENSE +201 -0
  46. package/licenses/_smithy_signature-v4-5.7.3-LICENSE +201 -0
  47. package/licenses/_smithy_types-4.18.0-LICENSE +201 -0
  48. package/licenses/_stablelib_base64-1.0.1-LICENSE +21 -0
  49. package/licenses/_types_node-22.19.19-LICENSE +21 -0
  50. package/licenses/_types_retry-0.12.0-LICENSE +21 -0
  51. package/licenses/agent-base-7.1.4-LICENSE +22 -0
  52. package/licenses/agent-base-9.0.0-LICENSE +22 -0
  53. package/licenses/balanced-match-4.0.4-LICENSE.md +23 -0
  54. package/licenses/base64-js-1.5.1-LICENSE +21 -0
  55. package/licenses/bidi-js-1.1.0-LICENSE.txt +22 -0
  56. package/licenses/bignumber.js-9.3.1-LICENCE.md +26 -0
  57. package/licenses/bowser-2.14.1-LICENSE +39 -0
  58. package/licenses/brace-expansion-5.0.12-LICENSE +23 -0
  59. package/licenses/buffer-equal-constant-time-1.0.1-LICENSE.txt +12 -0
  60. package/licenses/chalk-6.0.0-license +9 -0
  61. package/licenses/cross-spawn-7.1.2-LICENSE +21 -0
  62. package/licenses/data-uri-to-buffer-4.0.1-LICENSE.generated.txt +22 -0
  63. package/licenses/debug-4.4.3-LICENSE +20 -0
  64. package/licenses/dependency-index.json +994 -0
  65. package/licenses/diff-8.0.4-LICENSE +29 -0
  66. package/licenses/ecdsa-sig-formatter-1.0.11-LICENSE +201 -0
  67. package/licenses/extend-3.0.2-LICENSE +23 -0
  68. package/licenses/fast-sha256-1.3.0-LICENSE +24 -0
  69. package/licenses/fetch-blob-3.2.0-LICENSE +21 -0
  70. package/licenses/formdata-polyfill-4.0.10-LICENSE +21 -0
  71. package/licenses/gaxios-7.1.4-LICENSE +202 -0
  72. package/licenses/gcp-metadata-8.1.2-LICENSE +202 -0
  73. package/licenses/get-east-asian-width-1.6.0-license +9 -0
  74. package/licenses/google-auth-library-10.6.2-LICENSE +202 -0
  75. package/licenses/google-logging-utils-1.1.3-LICENSE +202 -0
  76. package/licenses/graceful-fs-4.2.11-LICENSE +15 -0
  77. package/licenses/highlight.js-10.7.3-LICENSE +29 -0
  78. package/licenses/hosted-git-info-9.0.3-LICENSE +13 -0
  79. package/licenses/http-proxy-agent-9.1.0-LICENSE +22 -0
  80. package/licenses/https-proxy-agent-7.0.6-LICENSE +22 -0
  81. package/licenses/https-proxy-agent-9.1.0-LICENSE +22 -0
  82. package/licenses/ignore-7.0.8-LICENSE-MIT +21 -0
  83. package/licenses/isexe-2.0.0-LICENSE +15 -0
  84. package/licenses/jiti-2.7.0-LICENSE +21 -0
  85. package/licenses/json-bigint-1.0.0-LICENSE +20 -0
  86. package/licenses/json-schema-to-ts-3.1.1-LICENSE +21 -0
  87. package/licenses/jwa-2.0.1-LICENSE +17 -0
  88. package/licenses/jws-4.0.1-LICENSE +17 -0
  89. package/licenses/long-5.3.2-LICENSE +202 -0
  90. package/licenses/lovely-mermaid-0.3.3-LICENSE +205 -0
  91. package/licenses/lru-cache-11.4.0-LICENSE.md +55 -0
  92. package/licenses/marked-18.0.11-LICENSE +44 -0
  93. package/licenses/marked-cjk-friendly-0.1.2-LICENSE +22 -0
  94. package/licenses/mcp/modelcontextprotocol-typescript-sdk.txt +21 -0
  95. package/licenses/minimatch-11.0.9-LICENSE.md +55 -0
  96. package/licenses/ms-2.1.3-license.md +21 -0
  97. package/licenses/node-domexception-1.0.0-LICENSE +21 -0
  98. package/licenses/node-fetch-3.3.2-LICENSE.md +22 -0
  99. package/licenses/openai-7.59.0-LICENSE +201 -0
  100. package/licenses/p-retry-4.6.2-license +9 -0
  101. package/licenses/partial-json-0.1.7-LICENSE +21 -0
  102. package/licenses/path-key-3.1.1-license +9 -0
  103. package/licenses/proper-lockfile-4.1.2-LICENSE +21 -0
  104. package/licenses/protobufjs-7.6.6-LICENSE +39 -0
  105. package/licenses/proxy-agent-negotiate-1.1.0-LICENSE.generated.txt +22 -0
  106. package/licenses/quickjs-wasi-3.6.2-LICENSE +21 -0
  107. package/licenses/require-from-string-2.0.2-license +21 -0
  108. package/licenses/retry-0.12.0-License +21 -0
  109. package/licenses/retry-0.13.1-License +21 -0
  110. package/licenses/safe-buffer-5.2.1-LICENSE +21 -0
  111. package/licenses/schema/typebox-LICENSE +23 -0
  112. package/licenses/semver-7.8.5-LICENSE +15 -0
  113. package/licenses/shebang-command-2.0.0-license +9 -0
  114. package/licenses/shebang-regex-3.0.0-license +9 -0
  115. package/licenses/signal-exit-3.0.7-LICENSE.txt +16 -0
  116. package/licenses/standardwebhooks-1.1.1-LICENSE.generated.txt +22 -0
  117. package/licenses/ts-algebra-2.0.0-LICENSE +21 -0
  118. package/licenses/tslib-2.8.1-LICENSE.txt +12 -0
  119. package/licenses/typebox-1.3.27-license +23 -0
  120. package/licenses/undici-8.12.4-LICENSE +21 -0
  121. package/licenses/undici-types-6.21.0-LICENSE +21 -0
  122. package/licenses/upstream-pi.MIT.txt +21 -0
  123. package/licenses/web-streams-polyfill-3.3.3-LICENSE +22 -0
  124. package/licenses/which-2.0.2-LICENSE +15 -0
  125. package/licenses/ws-8.23.1-LICENSE +20 -0
  126. package/licenses/yaml-2.9.0-LICENSE +13 -0
  127. package/package.json +46 -4
  128. package/pi/CHANGELOG.md +6869 -0
  129. package/pi/README.md +95 -0
  130. package/pi/dist/bundle/chunks/anthropic-messages-TZF4LOZ3.js +3 -0
  131. package/pi/dist/bundle/chunks/anthropic.js +75 -0
  132. package/pi/dist/bundle/chunks/azure-openai-responses-OPCDWPFL.js +2 -0
  133. package/pi/dist/bundle/chunks/bedrock-converse-stream.js +89 -0
  134. package/pi/dist/bundle/chunks/chunk-2BKJ4UF2.js +6 -0
  135. package/pi/dist/bundle/chunks/chunk-2C4T37KE.js +2 -0
  136. package/pi/dist/bundle/chunks/chunk-3TDGKLEK.js +4 -0
  137. package/pi/dist/bundle/chunks/chunk-4L3MQGA6.js +2 -0
  138. package/pi/dist/bundle/chunks/chunk-5AGIVGSV.js +6 -0
  139. package/pi/dist/bundle/chunks/chunk-6MVVCNIJ.js +2 -0
  140. package/pi/dist/bundle/chunks/chunk-6QGV3IWD.js +6 -0
  141. package/pi/dist/bundle/chunks/chunk-7CBJINYJ.js +20 -0
  142. package/pi/dist/bundle/chunks/chunk-7DDKXS2Q.js +2 -0
  143. package/pi/dist/bundle/chunks/chunk-7ZC4UXSL.js +2 -0
  144. package/pi/dist/bundle/chunks/chunk-BSRKXBKS.js +2 -0
  145. package/pi/dist/bundle/chunks/chunk-BXIXP3HJ.js +16 -0
  146. package/pi/dist/bundle/chunks/chunk-E3JXGAHC.js +2 -0
  147. package/pi/dist/bundle/chunks/chunk-EANOEWGP.js +2 -0
  148. package/pi/dist/bundle/chunks/chunk-FFMDRXC4.js +10 -0
  149. package/pi/dist/bundle/chunks/chunk-H5S7TE7A.js +20 -0
  150. package/pi/dist/bundle/chunks/chunk-IEBK4HQA.js +2 -0
  151. package/pi/dist/bundle/chunks/chunk-IKKTFUAW.js +82 -0
  152. package/pi/dist/bundle/chunks/chunk-INODY4DR.js +2 -0
  153. package/pi/dist/bundle/chunks/chunk-JXWJOIH4.js +2 -0
  154. package/pi/dist/bundle/chunks/chunk-KBNQNV33.js +8 -0
  155. package/pi/dist/bundle/chunks/chunk-L2ZPNLYD.js +2 -0
  156. package/pi/dist/bundle/chunks/chunk-L6EYYEJG.js +2 -0
  157. package/pi/dist/bundle/chunks/chunk-LPXNMA2W.js +2 -0
  158. package/pi/dist/bundle/chunks/chunk-LVVZS2NO.js +12 -0
  159. package/pi/dist/bundle/chunks/chunk-LWG2CUTI.js +31 -0
  160. package/pi/dist/bundle/chunks/chunk-OVXT2WQH.js +2 -0
  161. package/pi/dist/bundle/chunks/chunk-P7FPUEYA.js +2 -0
  162. package/pi/dist/bundle/chunks/chunk-PGXDEOVV.js +2 -0
  163. package/pi/dist/bundle/chunks/chunk-PHM5C7IG.js +9 -0
  164. package/pi/dist/bundle/chunks/chunk-PJACZCIR.js +2 -0
  165. package/pi/dist/bundle/chunks/chunk-PKIAAV4P.js +1237 -0
  166. package/pi/dist/bundle/chunks/chunk-PRRNXB7S.js +2 -0
  167. package/pi/dist/bundle/chunks/chunk-PW6LDSKD.js +131 -0
  168. package/pi/dist/bundle/chunks/chunk-Q257PLDE.js +55 -0
  169. package/pi/dist/bundle/chunks/chunk-QGY2QT6O.js +30 -0
  170. package/pi/dist/bundle/chunks/chunk-RDZVAGPR.js +2 -0
  171. package/pi/dist/bundle/chunks/chunk-SSLDNFEJ.js +2 -0
  172. package/pi/dist/bundle/chunks/chunk-TMTOQ7H7.js +2 -0
  173. package/pi/dist/bundle/chunks/chunk-UTB4DTYQ.js +2 -0
  174. package/pi/dist/bundle/chunks/chunk-WHLWHMLX.js +14 -0
  175. package/pi/dist/bundle/chunks/chunk-YMIUSQL3.js +44 -0
  176. package/pi/dist/bundle/chunks/chunk-ZFO73KYQ.js +2 -0
  177. package/pi/dist/bundle/chunks/chunk-ZG74NES2.js +2 -0
  178. package/pi/dist/bundle/chunks/chunk-ZLIZPVRW.js +2 -0
  179. package/pi/dist/bundle/chunks/cli-66VDVHXA.js +53 -0
  180. package/pi/dist/bundle/chunks/cloudflare-workers-ai-system-one-BCB6I5BD.js +2 -0
  181. package/pi/dist/bundle/chunks/codemode-worker.js +480 -0
  182. package/pi/dist/bundle/chunks/easter-egg-3d-GLZSE5PF.js +2 -0
  183. package/pi/dist/bundle/chunks/execute-B7SPJZ6B.js +507 -0
  184. package/pi/dist/bundle/chunks/github-copilot.js +2 -0
  185. package/pi/dist/bundle/chunks/google-generative-ai-YXFPI4IA.js +2 -0
  186. package/pi/dist/bundle/chunks/google-vertex-SI54R6EC.js +2 -0
  187. package/pi/dist/bundle/chunks/https-proxy-agent-LVOO5TPL.js +13 -0
  188. package/pi/dist/bundle/chunks/image-resize-worker.js +2 -0
  189. package/pi/dist/bundle/chunks/jiti-loader-GL4HJFAD.js +21 -0
  190. package/pi/dist/bundle/chunks/jiti-static-loader-2RCDI6B4.js +2 -0
  191. package/pi/dist/bundle/chunks/kimi-coding.js +2 -0
  192. package/pi/dist/bundle/chunks/lib-4AVRLBHM.js +9 -0
  193. package/pi/dist/bundle/chunks/llama-cpp-classify-PRGRPOMM.js +22 -0
  194. package/pi/dist/bundle/chunks/meta.js +2 -0
  195. package/pi/dist/bundle/chunks/mistral-conversations-D5VW6GSS.js +4 -0
  196. package/pi/dist/bundle/chunks/multipart-parser-FMGQ7342.js +3 -0
  197. package/pi/dist/bundle/chunks/node-AUOGOBCN.js +2 -0
  198. package/pi/dist/bundle/chunks/node-KCMANYC2.js +16 -0
  199. package/pi/dist/bundle/chunks/openai-chatgpt.js +75 -0
  200. package/pi/dist/bundle/chunks/openai-codex-responses-NM5HSETG.js +2 -0
  201. package/pi/dist/bundle/chunks/openai-codex.js +75 -0
  202. package/pi/dist/bundle/chunks/openai-completions-QZF567FN.js +7 -0
  203. package/pi/dist/bundle/chunks/openai-decisions-YJYDQHYN.js +5 -0
  204. package/pi/dist/bundle/chunks/openai-responses-AVMLOXIQ.js +4 -0
  205. package/pi/dist/bundle/chunks/openrouter-chat-images-3V4TR7TT.js +2 -0
  206. package/pi/dist/bundle/chunks/openrouter-images-UBTJFBR6.js +4 -0
  207. package/pi/dist/bundle/chunks/openrouter.js +75 -0
  208. package/pi/dist/bundle/chunks/pi-decision-XC3CEYXE.js +2 -0
  209. package/pi/dist/bundle/chunks/pi-image-GRYH565R.js +2 -0
  210. package/pi/dist/bundle/chunks/pi-messages-5Z2U3PEK.js +2 -0
  211. package/pi/dist/bundle/chunks/radius.js +75 -0
  212. package/pi/dist/bundle/chunks/runtime-PSL6AEOU.js +2 -0
  213. package/pi/dist/bundle/chunks/src-QKGKDFSU.js +4 -0
  214. package/pi/dist/bundle/chunks/typesafe-system-one-3JC45JJT.js +2 -0
  215. package/pi/dist/bundle/chunks/virtual-modules-QM3JD34I.js +2 -0
  216. package/pi/dist/bundle/chunks/xai.js +2 -0
  217. package/pi/dist/bundle/cli-runtime.js +3 -0
  218. package/pi/dist/bundle/cli.js +5 -0
  219. package/pi/dist/bundle/index.js +2 -0
  220. package/pi/dist/bundle/native/darwin/prebuilds/darwin-arm64/darwin-platform.node +0 -0
  221. package/pi/dist/bundle/native/darwin/prebuilds/darwin-x64/darwin-platform.node +0 -0
  222. package/pi/dist/bundle/native/linux/prebuilds/linux-arm64/linux-platform-x11.node +0 -0
  223. package/pi/dist/bundle/native/linux/prebuilds/linux-x64/linux-platform-x11.node +0 -0
  224. package/pi/dist/bundle/native/win32/prebuilds/win32-arm64/win32-platform.node +0 -0
  225. package/pi/dist/bundle/native/win32/prebuilds/win32-x64/win32-platform.node +0 -0
  226. package/pi/dist/bundle/rpc-entry.js +3 -0
  227. package/pi/dist/core/export-html/ansi-to-html.d.ts +27 -0
  228. package/pi/dist/core/export-html/ansi-to-html.d.ts.map +1 -0
  229. package/pi/dist/core/export-html/ansi-to-html.js +286 -0
  230. package/pi/dist/core/export-html/ansi-to-html.js.map +1 -0
  231. package/pi/dist/core/export-html/index.d.ts +37 -0
  232. package/pi/dist/core/export-html/index.d.ts.map +1 -0
  233. package/pi/dist/core/export-html/index.js +230 -0
  234. package/pi/dist/core/export-html/index.js.map +1 -0
  235. package/pi/dist/core/export-html/template.css +1085 -0
  236. package/pi/dist/core/export-html/template.html +56 -0
  237. package/pi/dist/core/export-html/template.js +2044 -0
  238. package/pi/dist/core/export-html/tool-renderer.d.ts +34 -0
  239. package/pi/dist/core/export-html/tool-renderer.d.ts.map +1 -0
  240. package/pi/dist/core/export-html/tool-renderer.js +112 -0
  241. package/pi/dist/core/export-html/tool-renderer.js.map +1 -0
  242. package/pi/dist/core/export-html/vendor/highlight.min.js +1213 -0
  243. package/pi/dist/core/export-html/vendor/marked-cjk-friendly.min.js +6 -0
  244. package/pi/dist/core/export-html/vendor/marked.min.js +79 -0
  245. package/pi/dist/modes/interactive/assets/clankolas.png +0 -0
  246. package/pi/dist/modes/interactive/theme/dark.json +78 -0
  247. package/pi/dist/modes/interactive/theme/light.json +78 -0
  248. package/pi/dist/modes/interactive/theme/system-theme.d.ts +55 -0
  249. package/pi/dist/modes/interactive/theme/system-theme.d.ts.map +1 -0
  250. package/pi/dist/modes/interactive/theme/system-theme.js +546 -0
  251. package/pi/dist/modes/interactive/theme/system-theme.js.map +1 -0
  252. package/pi/dist/modes/interactive/theme/theme-controller.d.ts +81 -0
  253. package/pi/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -0
  254. package/pi/dist/modes/interactive/theme/theme-controller.js +210 -0
  255. package/pi/dist/modes/interactive/theme/theme-controller.js.map +1 -0
  256. package/pi/dist/modes/interactive/theme/theme-schema.d.ts +28 -0
  257. package/pi/dist/modes/interactive/theme/theme-schema.d.ts.map +1 -0
  258. package/pi/dist/modes/interactive/theme/theme-schema.js +105 -0
  259. package/pi/dist/modes/interactive/theme/theme-schema.js.map +1 -0
  260. package/pi/dist/modes/interactive/theme/theme-tokens.d.ts +257 -0
  261. package/pi/dist/modes/interactive/theme/theme-tokens.d.ts.map +1 -0
  262. package/pi/dist/modes/interactive/theme/theme-tokens.js +94 -0
  263. package/pi/dist/modes/interactive/theme/theme-tokens.js.map +1 -0
  264. package/pi/dist/modes/interactive/theme/theme.d.ts +165 -0
  265. package/pi/dist/modes/interactive/theme/theme.d.ts.map +1 -0
  266. package/pi/dist/modes/interactive/theme/theme.js +918 -0
  267. package/pi/dist/modes/interactive/theme/theme.js.map +1 -0
  268. package/pi/docs/cli-integration.md +106 -0
  269. package/pi/docs/cli.md +358 -0
  270. package/pi/docs/codemode.md +241 -0
  271. package/pi/docs/compaction.md +463 -0
  272. package/pi/docs/configuration.md +47 -0
  273. package/pi/docs/containerization.md +183 -0
  274. package/pi/docs/custom-provider.md +227 -0
  275. package/pi/docs/docs.json +224 -0
  276. package/pi/docs/environment-variables.md +104 -0
  277. package/pi/docs/extensions.md +3394 -0
  278. package/pi/docs/how-pi-works.md +49 -0
  279. package/pi/docs/images/doom-extension.png +0 -0
  280. package/pi/docs/images/exy.png +0 -0
  281. package/pi/docs/images/interactive-mode.png +0 -0
  282. package/pi/docs/images/tree-view.png +0 -0
  283. package/pi/docs/index.md +39 -0
  284. package/pi/docs/json.md +226 -0
  285. package/pi/docs/keybindings.md +195 -0
  286. package/pi/docs/llama-cpp.md +138 -0
  287. package/pi/docs/mcp.md +301 -0
  288. package/pi/docs/message-types.md +280 -0
  289. package/pi/docs/models-configuration.md +213 -0
  290. package/pi/docs/models.md +248 -0
  291. package/pi/docs/nvidia-rtx-llama-cpp.md +96 -0
  292. package/pi/docs/packages.md +153 -0
  293. package/pi/docs/prompt-templates.md +59 -0
  294. package/pi/docs/providers.md +251 -0
  295. package/pi/docs/quickstart.md +140 -0
  296. package/pi/docs/rpc-commands.md +860 -0
  297. package/pi/docs/rpc-extension-ui.md +200 -0
  298. package/pi/docs/rpc.md +195 -0
  299. package/pi/docs/sdk.md +147 -0
  300. package/pi/docs/security.md +99 -0
  301. package/pi/docs/session-format.md +293 -0
  302. package/pi/docs/sessions.md +82 -0
  303. package/pi/docs/settings.md +175 -0
  304. package/pi/docs/shell-aliases.md +93 -0
  305. package/pi/docs/skills.md +93 -0
  306. package/pi/docs/slash-commands.md +61 -0
  307. package/pi/docs/subscriptions.md +96 -0
  308. package/pi/docs/terminal-setup.md +298 -0
  309. package/pi/docs/termux.md +117 -0
  310. package/pi/docs/themes.md +138 -0
  311. package/pi/docs/tmux.md +61 -0
  312. package/pi/docs/tui.md +199 -0
  313. package/pi/docs/usage.md +94 -0
  314. package/pi/docs/virtual-models.md +114 -0
  315. package/pi/docs/windows.md +109 -0
  316. package/pi/examples/README.md +36 -0
  317. package/pi/examples/extensions/README.md +215 -0
  318. package/pi/examples/extensions/auto-commit-on-exit.ts +49 -0
  319. package/pi/examples/extensions/bash-spawn-hook.ts +30 -0
  320. package/pi/examples/extensions/bookmark.ts +50 -0
  321. package/pi/examples/extensions/border-status-editor.ts +150 -0
  322. package/pi/examples/extensions/built-in-tool-renderer.ts +225 -0
  323. package/pi/examples/extensions/claude-rules.ts +86 -0
  324. package/pi/examples/extensions/commands.ts +72 -0
  325. package/pi/examples/extensions/confirm-destructive.ts +59 -0
  326. package/pi/examples/extensions/custom-compaction.ts +117 -0
  327. package/pi/examples/extensions/custom-footer.ts +64 -0
  328. package/pi/examples/extensions/custom-header.ts +73 -0
  329. package/pi/examples/extensions/custom-provider-anthropic/index.ts +613 -0
  330. package/pi/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
  331. package/pi/examples/extensions/custom-provider-anthropic/package.json +19 -0
  332. package/pi/examples/extensions/custom-provider-gitlab-duo/index.ts +405 -0
  333. package/pi/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
  334. package/pi/examples/extensions/custom-provider-gitlab-duo/test.ts +82 -0
  335. package/pi/examples/extensions/debug-provider.ts +90 -0
  336. package/pi/examples/extensions/dirty-repo-guard.ts +56 -0
  337. package/pi/examples/extensions/doom-overlay/README.md +46 -0
  338. package/pi/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
  339. package/pi/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
  340. package/pi/examples/extensions/doom-overlay/doom/build.sh +152 -0
  341. package/pi/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
  342. package/pi/examples/extensions/doom-overlay/doom-component.ts +132 -0
  343. package/pi/examples/extensions/doom-overlay/doom-engine.ts +173 -0
  344. package/pi/examples/extensions/doom-overlay/doom-keys.ts +104 -0
  345. package/pi/examples/extensions/doom-overlay/index.ts +74 -0
  346. package/pi/examples/extensions/doom-overlay/wad-finder.ts +55 -0
  347. package/pi/examples/extensions/dynamic-resources/SKILL.md +8 -0
  348. package/pi/examples/extensions/dynamic-resources/dynamic.json +81 -0
  349. package/pi/examples/extensions/dynamic-resources/dynamic.md +5 -0
  350. package/pi/examples/extensions/dynamic-resources/index.ts +15 -0
  351. package/pi/examples/extensions/dynamic-tools.ts +74 -0
  352. package/pi/examples/extensions/entry-renderer.ts +41 -0
  353. package/pi/examples/extensions/event-bus.ts +43 -0
  354. package/pi/examples/extensions/file-trigger.ts +41 -0
  355. package/pi/examples/extensions/git-checkpoint.ts +53 -0
  356. package/pi/examples/extensions/git-merge-and-resolve.ts +115 -0
  357. package/pi/examples/extensions/github-issue-autocomplete.ts +185 -0
  358. package/pi/examples/extensions/gondolin/index.ts +528 -0
  359. package/pi/examples/extensions/gondolin/package-lock.json +175 -0
  360. package/pi/examples/extensions/gondolin/package.json +19 -0
  361. package/pi/examples/extensions/handoff.ts +190 -0
  362. package/pi/examples/extensions/hello.ts +26 -0
  363. package/pi/examples/extensions/hidden-thinking-label.ts +53 -0
  364. package/pi/examples/extensions/inline-bash.ts +94 -0
  365. package/pi/examples/extensions/input-transform-streaming.ts +39 -0
  366. package/pi/examples/extensions/input-transform.ts +43 -0
  367. package/pi/examples/extensions/interactive-shell.ts +196 -0
  368. package/pi/examples/extensions/jev-router.ts +113 -0
  369. package/pi/examples/extensions/mac-system-theme.ts +47 -0
  370. package/pi/examples/extensions/message-renderer.ts +59 -0
  371. package/pi/examples/extensions/minimal-mode.ts +353 -0
  372. package/pi/examples/extensions/modal-editor.ts +85 -0
  373. package/pi/examples/extensions/model-status.ts +31 -0
  374. package/pi/examples/extensions/notify.ts +57 -0
  375. package/pi/examples/extensions/overlay-qa-tests.ts +1456 -0
  376. package/pi/examples/extensions/overlay-test.ts +165 -0
  377. package/pi/examples/extensions/permission-gate.ts +34 -0
  378. package/pi/examples/extensions/pirate.ts +47 -0
  379. package/pi/examples/extensions/plan-mode/README.md +66 -0
  380. package/pi/examples/extensions/plan-mode/index.ts +404 -0
  381. package/pi/examples/extensions/plan-mode/utils.ts +194 -0
  382. package/pi/examples/extensions/preset.ts +438 -0
  383. package/pi/examples/extensions/project-trust.ts +64 -0
  384. package/pi/examples/extensions/prompt-customizer.ts +49 -0
  385. package/pi/examples/extensions/protected-paths.ts +30 -0
  386. package/pi/examples/extensions/provider-payload.ts +18 -0
  387. package/pi/examples/extensions/qna.ts +118 -0
  388. package/pi/examples/extensions/question.ts +286 -0
  389. package/pi/examples/extensions/questionnaire.ts +448 -0
  390. package/pi/examples/extensions/rainbow-editor.ts +88 -0
  391. package/pi/examples/extensions/reload-runtime.ts +49 -0
  392. package/pi/examples/extensions/rpc-demo.ts +118 -0
  393. package/pi/examples/extensions/send-user-message.ts +97 -0
  394. package/pi/examples/extensions/session-name.ts +27 -0
  395. package/pi/examples/extensions/shutdown-command.ts +63 -0
  396. package/pi/examples/extensions/snake.ts +343 -0
  397. package/pi/examples/extensions/space-invaders.ts +560 -0
  398. package/pi/examples/extensions/ssh.ts +220 -0
  399. package/pi/examples/extensions/status-line.ts +32 -0
  400. package/pi/examples/extensions/structured-output.ts +65 -0
  401. package/pi/examples/extensions/subagent/README.md +180 -0
  402. package/pi/examples/extensions/subagent/agents/planner.md +37 -0
  403. package/pi/examples/extensions/subagent/agents/reviewer.md +35 -0
  404. package/pi/examples/extensions/subagent/agents/scout.md +50 -0
  405. package/pi/examples/extensions/subagent/agents/worker.md +24 -0
  406. package/pi/examples/extensions/subagent/agents.ts +157 -0
  407. package/pi/examples/extensions/subagent/index.ts +1258 -0
  408. package/pi/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
  409. package/pi/examples/extensions/subagent/prompts/implement.md +10 -0
  410. package/pi/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
  411. package/pi/examples/extensions/summarize.ts +199 -0
  412. package/pi/examples/extensions/system-prompt-header.ts +17 -0
  413. package/pi/examples/extensions/tic-tac-toe.ts +1008 -0
  414. package/pi/examples/extensions/timed-confirm.ts +70 -0
  415. package/pi/examples/extensions/titlebar-spinner.ts +58 -0
  416. package/pi/examples/extensions/todo.ts +304 -0
  417. package/pi/examples/extensions/tool-override.ts +144 -0
  418. package/pi/examples/extensions/tools.ts +148 -0
  419. package/pi/examples/extensions/trigger-compact.ts +50 -0
  420. package/pi/examples/extensions/truncated-tool.ts +195 -0
  421. package/pi/examples/extensions/widget-placement.ts +9 -0
  422. package/pi/examples/extensions/with-deps/index.ts +32 -0
  423. package/pi/examples/extensions/with-deps/package-lock.json +31 -0
  424. package/pi/examples/extensions/with-deps/package.json +22 -0
  425. package/pi/examples/extensions/working-indicator.ts +123 -0
  426. package/pi/examples/extensions/working-message-test.ts +25 -0
  427. package/pi/examples/rpc-client.ts +35 -0
  428. package/pi/examples/rpc-extension-ui.ts +662 -0
  429. package/pi/examples/sdk/01-minimal.ts +26 -0
  430. package/pi/examples/sdk/02-custom-model.ts +49 -0
  431. package/pi/examples/sdk/03-custom-prompt.ts +75 -0
  432. package/pi/examples/sdk/04-skills.ts +55 -0
  433. package/pi/examples/sdk/05-tools.ts +48 -0
  434. package/pi/examples/sdk/06-extensions.ts +99 -0
  435. package/pi/examples/sdk/07-context-files.ts +47 -0
  436. package/pi/examples/sdk/08-prompt-templates.ts +51 -0
  437. package/pi/examples/sdk/09-api-keys-and-oauth.ts +34 -0
  438. package/pi/examples/sdk/10-settings.ts +53 -0
  439. package/pi/examples/sdk/11-sessions.ts +52 -0
  440. package/pi/examples/sdk/12-full-control.ts +74 -0
  441. package/pi/examples/sdk/13-session-runtime.ts +67 -0
  442. package/pi/examples/sdk/14-codemode-mcp.ts +61 -0
  443. package/pi/examples/sdk/README.md +141 -0
  444. package/pi/examples/tsconfig.json +208 -0
  445. package/pi/package.json +5 -0
  446. package/pi/schemas/keybindings.schema.json +393 -0
  447. package/pi/schemas/mcp.schema.json +306 -0
  448. package/pi/schemas/models.schema.json +1253 -0
  449. package/pi/schemas/settings.schema.json +820 -0
  450. package/pi/schemas/theme.schema.json +365 -0
@@ -0,0 +1,404 @@
1
+ /**
2
+ * Plan Mode Extension
3
+ *
4
+ * Read-only exploration mode for safe code analysis.
5
+ * When enabled, built-in write tools are disabled.
6
+ *
7
+ * Features:
8
+ * - /plan command or Ctrl+Alt+P to toggle
9
+ * - Bash restricted to allowlisted read-only commands
10
+ * - Extracts numbered plan steps from "Plan:" sections
11
+ * - [DONE:n] markers to complete steps during execution
12
+ * - Progress tracking widget during execution
13
+ */
14
+
15
+ import type { AgentMessage } from "@earendil-works/pi-agent-core";
16
+ import type { AssistantMessage, TextContent } from "@earendil-works/pi-ai";
17
+ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
18
+ import { Key } from "@earendil-works/pi-tui";
19
+ import { allStepsComplete, extractTodoItems, isSafeCommand, markCompletedSteps, type TodoItem } from "./utils.ts";
20
+
21
+ // Tools
22
+ const PLAN_MODE_TOOLS = ["read", "bash", "grep", "find", "ls", "questionnaire"];
23
+ const NORMAL_MODE_TOOLS = ["read", "bash", "edit", "write"];
24
+ const PLAN_MODE_DISABLED_TOOLS = new Set<string>(["edit", "write"]);
25
+ const PLAN_MANAGED_TOOLS = new Set<string>([...PLAN_MODE_TOOLS, ...NORMAL_MODE_TOOLS]);
26
+
27
+ interface PlanModeState {
28
+ enabled: boolean;
29
+ todos?: TodoItem[];
30
+ executing?: boolean;
31
+ toolsBeforePlanMode?: string[];
32
+ }
33
+
34
+ // Type guard for assistant messages
35
+ function isAssistantMessage(m: AgentMessage): m is AssistantMessage {
36
+ return m.role === "assistant" && Array.isArray(m.content);
37
+ }
38
+
39
+ // Extract text content from an assistant message.
40
+ // Includes thinking blocks: with reasoning-max models the [DONE:n] tags and
41
+ // plan drafts usually land in thinking, not the visible text.
42
+ function getTextContent(message: AssistantMessage): string {
43
+ return message.content
44
+ .map((block) => {
45
+ if (block.type === "text") return block.text;
46
+ if (block.type === "thinking") return (block as { thinking?: string }).thinking ?? "";
47
+ return "";
48
+ })
49
+ .join("\n");
50
+ }
51
+
52
+ export default function planModeExtension(pi: ExtensionAPI): void {
53
+ let planModeEnabled = false;
54
+ let executionMode = false;
55
+ let todoItems: TodoItem[] = [];
56
+ let toolsBeforePlanMode: string[] | undefined;
57
+
58
+ pi.registerFlag("plan", {
59
+ description: "Start in plan mode (read-only exploration)",
60
+ type: "boolean",
61
+ default: false,
62
+ });
63
+
64
+ function updateStatus(ctx: ExtensionContext): void {
65
+ // Footer status
66
+ if (executionMode && todoItems.length > 0) {
67
+ const completed = todoItems.filter((t) => t.completed).length;
68
+ ctx.ui.setStatus("plan-mode", ctx.ui.theme.fg("accent", `📋 ${completed}/${todoItems.length}`));
69
+ } else if (planModeEnabled) {
70
+ ctx.ui.setStatus("plan-mode", ctx.ui.theme.fg("warning", "⏸ plan"));
71
+ } else {
72
+ ctx.ui.setStatus("plan-mode", undefined);
73
+ }
74
+
75
+ // Widget showing todo list
76
+ if (executionMode && todoItems.length > 0) {
77
+ const lines = todoItems.map((item) => {
78
+ const text = item.text.length > 60 ? `${item.text.slice(0, 57)}...` : item.text;
79
+ if (item.completed) {
80
+ return ctx.ui.theme.fg("success", "☑ ") + ctx.ui.theme.fg("muted", ctx.ui.theme.strikethrough(text));
81
+ }
82
+ return `${ctx.ui.theme.fg("muted", "☐ ")}${text}`;
83
+ });
84
+ ctx.ui.setWidget("plan-todos", lines);
85
+ } else {
86
+ ctx.ui.setWidget("plan-todos", undefined);
87
+ }
88
+ }
89
+
90
+ function uniqueToolNames(toolNames: string[]): string[] {
91
+ return [...new Set(toolNames)];
92
+ }
93
+
94
+ function getPlanModeTools(activeToolNames: string[]): string[] {
95
+ return uniqueToolNames([
96
+ ...activeToolNames.filter((name) => !PLAN_MODE_DISABLED_TOOLS.has(name)),
97
+ ...PLAN_MODE_TOOLS,
98
+ ]);
99
+ }
100
+
101
+ function getNormalModeTools(activeToolNames: string[]): string[] {
102
+ return uniqueToolNames([
103
+ ...NORMAL_MODE_TOOLS,
104
+ ...activeToolNames.filter((name) => !PLAN_MANAGED_TOOLS.has(name)),
105
+ ]);
106
+ }
107
+
108
+ function enablePlanModeTools(): void {
109
+ if (toolsBeforePlanMode === undefined) {
110
+ toolsBeforePlanMode = pi.getActiveTools();
111
+ }
112
+ pi.setActiveTools(getPlanModeTools(toolsBeforePlanMode));
113
+ }
114
+
115
+ function restoreNormalModeTools(): void {
116
+ pi.setActiveTools(toolsBeforePlanMode ?? getNormalModeTools(pi.getActiveTools()));
117
+ toolsBeforePlanMode = undefined;
118
+ }
119
+
120
+ function persistState(): void {
121
+ pi.appendEntry("plan-mode", {
122
+ enabled: planModeEnabled,
123
+ todos: todoItems,
124
+ executing: executionMode,
125
+ toolsBeforePlanMode,
126
+ });
127
+ }
128
+
129
+ function togglePlanMode(ctx: ExtensionContext): void {
130
+ planModeEnabled = !planModeEnabled;
131
+ executionMode = false;
132
+ todoItems = [];
133
+
134
+ if (planModeEnabled) {
135
+ enablePlanModeTools();
136
+ ctx.ui.notify("Plan mode enabled. Built-in write tools disabled.");
137
+ } else {
138
+ restoreNormalModeTools();
139
+ ctx.ui.notify("Plan mode disabled. Full access restored.");
140
+ }
141
+ updateStatus(ctx);
142
+ persistState();
143
+ }
144
+
145
+ pi.registerCommand("plan", {
146
+ description: "Toggle plan mode (read-only exploration)",
147
+ handler: async (_args, ctx) => togglePlanMode(ctx),
148
+ });
149
+
150
+ pi.registerCommand("todos", {
151
+ description: "Show current plan todo list",
152
+ handler: async (_args, ctx) => {
153
+ if (todoItems.length === 0) {
154
+ ctx.ui.notify("No todos. Create a plan first with /plan", "info");
155
+ return;
156
+ }
157
+ const list = todoItems.map((item, i) => `${i + 1}. ${item.completed ? "✓" : "○"} ${item.text}`).join("\n");
158
+ ctx.ui.notify(`Plan Progress:\n${list}`, "info");
159
+ },
160
+ });
161
+
162
+ pi.registerShortcut(Key.ctrlAlt("p"), {
163
+ description: "Toggle plan mode",
164
+ handler: async (ctx) => togglePlanMode(ctx),
165
+ });
166
+
167
+ // Block destructive bash commands in plan mode
168
+ pi.on("tool_call", async (event) => {
169
+ if (!planModeEnabled || event.toolName !== "bash") return;
170
+
171
+ const command = event.input.command as string;
172
+ if (!isSafeCommand(command)) {
173
+ return {
174
+ block: true,
175
+ reason: `Plan mode: command blocked (not allowlisted). Use /plan to disable plan mode first.\nCommand: ${command}`,
176
+ };
177
+ }
178
+ });
179
+
180
+ // Filter out stale plan mode context when not in plan mode
181
+ pi.on("context", async (event) => {
182
+ if (planModeEnabled) return;
183
+
184
+ return {
185
+ messages: event.messages.filter((m) => {
186
+ const msg = m as AgentMessage & { customType?: string };
187
+ if (msg.customType === "plan-mode-context") return false;
188
+ if (msg.role !== "user") return true;
189
+
190
+ const content = msg.content;
191
+ if (typeof content === "string") {
192
+ return !content.includes("[PLAN MODE ACTIVE]");
193
+ }
194
+ if (Array.isArray(content)) {
195
+ return !content.some(
196
+ (c) => c.type === "text" && (c as TextContent).text?.includes("[PLAN MODE ACTIVE]"),
197
+ );
198
+ }
199
+ return true;
200
+ }),
201
+ };
202
+ });
203
+
204
+ // Inject plan/execution context before a user prompt. Runs started by custom messages, such as
205
+ // background task notifications, skip it: the context from the last prompt is still in the
206
+ // conversation, and adding it again on every notification would only repeat it.
207
+ pi.on("before_agent_start", async (event) => {
208
+ if (event.messageType !== "user") return;
209
+
210
+ if (planModeEnabled) {
211
+ return {
212
+ message: {
213
+ customType: "plan-mode-context",
214
+ content: `[PLAN MODE ACTIVE]
215
+ You are in plan mode - a read-only exploration mode for safe code analysis.
216
+
217
+ Restrictions:
218
+ - Built-in edit and write tools are disabled
219
+ - Other currently active tools remain available
220
+ - Bash is restricted to an allowlist of read-only commands
221
+
222
+ Ask clarifying questions using the questionnaire tool.
223
+ Use brave-search skill via bash for web research.
224
+
225
+ Create a detailed numbered plan under a "Plan:" header:
226
+
227
+ Plan:
228
+ 1. First step description
229
+ 2. Second step description
230
+ ...
231
+
232
+ Do NOT attempt to make changes - just describe what you would do.`,
233
+ display: false,
234
+ },
235
+ };
236
+ }
237
+
238
+ if (executionMode && todoItems.length > 0) {
239
+ const remaining = todoItems.filter((t) => !t.completed);
240
+ const todoList = remaining.map((t) => `${t.step}. ${t.text}`).join("\n");
241
+ return {
242
+ message: {
243
+ customType: "plan-execution-context",
244
+ content: `[EXECUTING PLAN - Full tool access enabled]
245
+
246
+ Remaining steps:
247
+ ${todoList}
248
+
249
+ Execute each step in order.
250
+ After completing a step, include a [DONE:n] tag in your response.`,
251
+ display: false,
252
+ },
253
+ };
254
+ }
255
+ });
256
+
257
+ // Track progress after each turn
258
+ pi.on("turn_end", async (event, ctx) => {
259
+ if (!executionMode || todoItems.length === 0) return;
260
+ if (!isAssistantMessage(event.message)) return;
261
+
262
+ markCompletedSteps(getTextContent(event.message), todoItems);
263
+ // Always refresh: cheap, keeps the widget consistent even when nothing matched.
264
+ updateStatus(ctx);
265
+ persistState();
266
+ });
267
+
268
+ // Handle plan completion and plan mode UI
269
+ pi.on("agent_end", async (event, ctx) => {
270
+ // Check if execution is complete
271
+ if (executionMode && todoItems.length > 0) {
272
+ // Fallback: the model wrapped up without [DONE:n] tags ("All steps complete").
273
+ const lastAssistant = [...event.messages].reverse().find(isAssistantMessage);
274
+ if (lastAssistant && allStepsComplete(getTextContent(lastAssistant))) {
275
+ for (const t of todoItems) t.completed = true;
276
+ }
277
+ if (todoItems.every((t) => t.completed)) {
278
+ const completedList = todoItems.map((t) => `~~${t.text}~~`).join("\n");
279
+ pi.sendMessage(
280
+ { customType: "plan-complete", content: `**Plan Complete!** ✓\n\n${completedList}`, display: true },
281
+ // nextTurn: delivered with the next user prompt instead of triggering an
282
+ // extra (expensive, reasoning-max) LLM turn to acknowledge the card.
283
+ { deliverAs: "nextTurn" },
284
+ );
285
+ executionMode = false;
286
+ todoItems = [];
287
+ updateStatus(ctx);
288
+ persistState(); // Save cleared state so resume doesn't restore old execution mode
289
+ }
290
+ return;
291
+ }
292
+
293
+ if (!planModeEnabled || !ctx.hasUI) return;
294
+
295
+ // Extract todos from last assistant message
296
+ const lastAssistant = [...event.messages].reverse().find(isAssistantMessage);
297
+ if (lastAssistant) {
298
+ const extracted = extractTodoItems(getTextContent(lastAssistant));
299
+ if (extracted.length > 0) {
300
+ todoItems = extracted;
301
+ }
302
+ }
303
+
304
+ if (todoItems.length === 0) return;
305
+ persistState();
306
+
307
+ // Show plan steps and prompt for next action
308
+ const todoListText = todoItems.map((t, i) => `${i + 1}. ☐ ${t.text}`).join("\n");
309
+ const planTodoListMessage = {
310
+ customType: "plan-todo-list",
311
+ content: `**Plan Steps (${todoItems.length}):**\n\n${todoListText}`,
312
+ display: true,
313
+ };
314
+
315
+ const choice = await ctx.ui.select("Plan mode - what next?", [
316
+ "Execute the plan (track progress)",
317
+ "Stay in plan mode",
318
+ "Refine the plan",
319
+ ]);
320
+
321
+ if (choice?.startsWith("Execute")) {
322
+ const firstTodoItem = todoItems[0];
323
+ if (!firstTodoItem) return;
324
+
325
+ planModeEnabled = false;
326
+ executionMode = true;
327
+ restoreNormalModeTools();
328
+ updateStatus(ctx);
329
+ persistState();
330
+
331
+ const remainingList = todoItems.map((t) => `${t.step}. ${t.text}`).join("\n");
332
+ const execMessage = `Execute the plan.
333
+
334
+ Remaining steps:
335
+ ${remainingList}
336
+
337
+ Start with: ${firstTodoItem.text}
338
+ After completing a step, include a [DONE:n] tag in your response.`;
339
+ pi.sendMessage(planTodoListMessage, { deliverAs: "followUp" });
340
+ pi.sendMessage(
341
+ { customType: "plan-mode-execute", content: execMessage, display: true },
342
+ { triggerTurn: true, deliverAs: "followUp" },
343
+ );
344
+ } else if (choice === "Refine the plan") {
345
+ const refinement = await ctx.ui.editor("Refine the plan:", "");
346
+ if (refinement?.trim()) {
347
+ pi.sendMessage(planTodoListMessage, { deliverAs: "followUp" });
348
+ pi.sendUserMessage(refinement.trim(), { deliverAs: "followUp" });
349
+ }
350
+ }
351
+ });
352
+
353
+ // Restore state on session start/resume
354
+ pi.on("session_start", async (_event, ctx) => {
355
+ if (pi.getFlag("plan") === true) {
356
+ planModeEnabled = true;
357
+ }
358
+
359
+ const entries = ctx.sessionManager.getEntries();
360
+
361
+ // Restore persisted state
362
+ const planModeEntry = entries
363
+ .filter((e: { type: string; customType?: string }) => e.type === "custom" && e.customType === "plan-mode")
364
+ .pop() as { data?: PlanModeState } | undefined;
365
+
366
+ if (planModeEntry?.data) {
367
+ planModeEnabled = planModeEntry.data.enabled ?? planModeEnabled;
368
+ todoItems = planModeEntry.data.todos ?? todoItems;
369
+ executionMode = planModeEntry.data.executing ?? executionMode;
370
+ toolsBeforePlanMode = planModeEntry.data.toolsBeforePlanMode ?? toolsBeforePlanMode;
371
+ }
372
+
373
+ // On resume: re-scan messages to rebuild completion state
374
+ // Only scan messages AFTER the last "plan-mode-execute" to avoid picking up [DONE:n] from previous plans
375
+ const isResume = planModeEntry !== undefined;
376
+ if (isResume && executionMode && todoItems.length > 0) {
377
+ // Find the index of the last plan-mode-execute entry (marks when current execution started)
378
+ let executeIndex = -1;
379
+ for (let i = entries.length - 1; i >= 0; i--) {
380
+ const entry = entries[i] as { type: string; customType?: string };
381
+ if (entry.customType === "plan-mode-execute") {
382
+ executeIndex = i;
383
+ break;
384
+ }
385
+ }
386
+
387
+ // Only scan messages after the execute marker
388
+ const messages: AssistantMessage[] = [];
389
+ for (let i = executeIndex + 1; i < entries.length; i++) {
390
+ const entry = entries[i];
391
+ if (entry.type === "message" && "message" in entry && isAssistantMessage(entry.message as AgentMessage)) {
392
+ messages.push(entry.message as AssistantMessage);
393
+ }
394
+ }
395
+ const allText = messages.map(getTextContent).join("\n");
396
+ markCompletedSteps(allText, todoItems);
397
+ }
398
+
399
+ if (planModeEnabled) {
400
+ enablePlanModeTools();
401
+ }
402
+ updateStatus(ctx);
403
+ });
404
+ }
@@ -0,0 +1,194 @@
1
+ /**
2
+ * Pure utility functions for plan mode.
3
+ * Extracted for testability.
4
+ */
5
+
6
+ // Destructive commands blocked in plan mode
7
+ const DESTRUCTIVE_PATTERNS = [
8
+ /\brm\b/i,
9
+ /\brmdir\b/i,
10
+ /\bmv\b/i,
11
+ /\bcp\b/i,
12
+ /\bmkdir\b/i,
13
+ /\btouch\b/i,
14
+ /\bchmod\b/i,
15
+ /\bchown\b/i,
16
+ /\bchgrp\b/i,
17
+ /\bln\b/i,
18
+ /\btee\b/i,
19
+ /\btruncate\b/i,
20
+ /\bdd\b/i,
21
+ /\bshred\b/i,
22
+ /(^|[^<])>(?!>)/,
23
+ />>/,
24
+ /\bnpm\s+(install|uninstall|update|ci|link|publish)/i,
25
+ /\byarn\s+(add|remove|install|publish)/i,
26
+ /\bpnpm\s+(add|remove|install|publish)/i,
27
+ /\bpip\s+(install|uninstall)/i,
28
+ /\bapt(-get)?\s+(install|remove|purge|update|upgrade)/i,
29
+ /\bbrew\s+(install|uninstall|upgrade)/i,
30
+ /\bgit\s+(add|commit|push|pull|merge|rebase|reset|checkout|branch\s+-[dD]|stash|cherry-pick|revert|tag|init|clone)/i,
31
+ /\bsudo\b/i,
32
+ /\bsu\b/i,
33
+ /\bkill\b/i,
34
+ /\bpkill\b/i,
35
+ /\bkillall\b/i,
36
+ /\breboot\b/i,
37
+ /\bshutdown\b/i,
38
+ /\bsystemctl\s+(start|stop|restart|enable|disable)/i,
39
+ /\bservice\s+\S+\s+(start|stop|restart)/i,
40
+ /\b(vim?|nano|emacs|code|subl)\b/i,
41
+ ];
42
+
43
+ // Safe read-only commands allowed in plan mode
44
+ const SAFE_PATTERNS = [
45
+ /^\s*cat\b/,
46
+ /^\s*head\b/,
47
+ /^\s*tail\b/,
48
+ /^\s*less\b/,
49
+ /^\s*more\b/,
50
+ /^\s*grep\b/,
51
+ /^\s*find\b/,
52
+ /^\s*ls\b/,
53
+ /^\s*pwd\b/,
54
+ /^\s*echo\b/,
55
+ /^\s*printf\b/,
56
+ /^\s*wc\b/,
57
+ /^\s*sort\b/,
58
+ /^\s*uniq\b/,
59
+ /^\s*diff\b/,
60
+ /^\s*file\b/,
61
+ /^\s*stat\b/,
62
+ /^\s*du\b/,
63
+ /^\s*df\b/,
64
+ /^\s*tree\b/,
65
+ /^\s*which\b/,
66
+ /^\s*whereis\b/,
67
+ /^\s*type\b/,
68
+ /^\s*env\b/,
69
+ /^\s*printenv\b/,
70
+ /^\s*uname\b/,
71
+ /^\s*whoami\b/,
72
+ /^\s*id\b/,
73
+ /^\s*date\b/,
74
+ /^\s*cal\b/,
75
+ /^\s*uptime\b/,
76
+ /^\s*ps\b/,
77
+ /^\s*top\b/,
78
+ /^\s*htop\b/,
79
+ /^\s*free\b/,
80
+ /^\s*git\s+(status|log|diff|show|branch|remote|config\s+--get)/i,
81
+ /^\s*git\s+ls-/i,
82
+ /^\s*npm\s+(list|ls|view|info|search|outdated|audit)/i,
83
+ /^\s*yarn\s+(list|info|why|audit)/i,
84
+ /^\s*node\s+--version/i,
85
+ /^\s*python\s+--version/i,
86
+ /^\s*curl\s/i,
87
+ /^\s*wget\s+-O\s*-/i,
88
+ /^\s*jq\b/,
89
+ /^\s*sed\s+-n/i,
90
+ /^\s*awk\b/,
91
+ /^\s*rg\b/,
92
+ /^\s*fd\b/,
93
+ /^\s*bat\b/,
94
+ /^\s*eza\b/,
95
+ ];
96
+
97
+ export function isSafeCommand(command: string): boolean {
98
+ const isDestructive = DESTRUCTIVE_PATTERNS.some((p) => p.test(command));
99
+ const isSafe = SAFE_PATTERNS.some((p) => p.test(command));
100
+ return !isDestructive && isSafe;
101
+ }
102
+
103
+ export interface TodoItem {
104
+ step: number;
105
+ text: string;
106
+ completed: boolean;
107
+ }
108
+
109
+ export function cleanStepText(text: string): string {
110
+ let cleaned = text
111
+ .replace(/\*{1,2}([^*]+)\*{1,2}/g, "$1") // Remove bold/italic
112
+ .replace(/`([^`]+)`/g, "$1") // Remove code
113
+ .replace(
114
+ /^(Use|Run|Execute|Create|Write|Read|Check|Verify|Update|Modify|Add|Remove|Delete|Install)\s+(the\s+)?/i,
115
+ "",
116
+ )
117
+ .replace(/\s+/g, " ")
118
+ .trim();
119
+
120
+ if (cleaned.length > 0) {
121
+ cleaned = cleaned.charAt(0).toUpperCase() + cleaned.slice(1);
122
+ }
123
+ // Keep full text: the exec message and widget display need the whole step.
124
+ // The widget truncates for display (see updateStatus in index.ts).
125
+ return cleaned;
126
+ }
127
+
128
+ export function extractTodoItems(message: string): TodoItem[] {
129
+ const items: TodoItem[] = [];
130
+ // Take the LAST "Plan:" section: since getTextContent includes thinking blocks,
131
+ // a draft in the reasoning block can precede the user-visible plan in the text
132
+ // block — the text block comes last in content order.
133
+ const headers = [...message.matchAll(/\*{0,2}Plan:\*{0,2}\s*\n/gi)];
134
+ if (headers.length === 0) return items;
135
+ const lastHeader = headers[headers.length - 1];
136
+ const planSection = message.slice((lastHeader.index ?? 0) + lastHeader[0].length);
137
+ // Full-line capture: step titles may contain bold/italic/backticks ("1. **Step** \`x\` …").
138
+ // cleanStepText strips the markdown; / and - items are still skipped below.
139
+ const numberedPattern = /^\s*(\d+)[.)]\s+(.+)$/gm;
140
+
141
+ for (const match of planSection.matchAll(numberedPattern)) {
142
+ const text = match[2]
143
+ .trim()
144
+ .replace(/\*{1,2}$/, "")
145
+ .trim();
146
+ if (text.length > 5 && !text.startsWith("/") && !text.startsWith("-")) {
147
+ const cleaned = cleanStepText(text);
148
+ if (cleaned.length > 3) {
149
+ items.push({ step: items.length + 1, text: cleaned, completed: false });
150
+ }
151
+ }
152
+ }
153
+ return items;
154
+ }
155
+
156
+ export function extractDoneSteps(message: string): number[] {
157
+ const steps: number[] = [];
158
+ // Canonical and bracket variants: [DONE:1], [DONE: 1], [DONE 1], [Done:1]
159
+ for (const match of message.matchAll(/\[DONE\s*:?\s*(\d+)\]/gi)) {
160
+ steps.push(Number(match[1]));
161
+ }
162
+ // "Done: 1" without brackets
163
+ for (const match of message.matchAll(/\bDone\s*:\s*(\d+)\b/gi)) {
164
+ steps.push(Number(match[1]));
165
+ }
166
+ // "Step 1 done", "Step 2 is complete", "Step 3 finished" — adjacency-anchored,
167
+ // so "Step 9 is not done" / "Step 9 incomplete" never match.
168
+ for (const match of message.matchAll(/\bStep\s*(\d+)\s+(?:is\s+)?(?:done|complete|completed|finished)\b/gi)) {
169
+ steps.push(Number(match[1]));
170
+ }
171
+ return [...new Set(steps)];
172
+ }
173
+
174
+ export function markCompletedSteps(text: string, items: TodoItem[]): number {
175
+ const doneSteps = extractDoneSteps(text);
176
+ let marked = 0;
177
+ for (const step of doneSteps) {
178
+ const item = items.find((t) => t.step === step && !t.completed);
179
+ if (item) {
180
+ item.completed = true;
181
+ marked++;
182
+ }
183
+ }
184
+ return marked;
185
+ }
186
+
187
+ // Whole-plan completion phrasing, used as a fallback when the model summarizes
188
+ // without [DONE:n] tags. Only consulted on the run's final message (agent_end).
189
+ export function allStepsComplete(message: string): boolean {
190
+ return (
191
+ /(?:all|every)\s+steps?\s+(?:are|is\s+)?(?:done|complete|completed|finished)/i.test(message) ||
192
+ /\b(?:the\s+)?plan\s+(?:is\s+)?(?:complete|completed|done)\b/i.test(message)
193
+ );
194
+ }