pi-coding-master 0.2.7

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 (304) hide show
  1. package/README.md +50 -0
  2. package/core/god.agent.capability/@ABANDONED.brain.prefrontal.monitor/gpu_monitor.py +80 -0
  3. package/core/god.agent.capability/@ABANDONED.brain.prefrontal.monitor/gpu_monitor.py.CHANGELOG +1 -0
  4. package/core/god.agent.capability/@ABANDONED.brain.prefrontal.monitor/gpu_monitor.py.SPEC +3 -0
  5. package/core/god.agent.capability/hands.dev.writeissue/issue.ts +209 -0
  6. package/core/god.agent.capability/hands.dev.writeissue/issue.ts.SPEC +26 -0
  7. package/core/god.agent.capability/hands.files.changewatcher/watcher.ts +44 -0
  8. package/core/god.agent.capability/hands.files.changewatcher/watcher.ts.SPEC +25 -0
  9. package/core/god.pi.mod/cli/pi-completion.zsh +21 -0
  10. package/core/god.pi.mod/cli/pi-completion.zsh.CHANGELOG +1 -0
  11. package/core/god.pi.mod/cli/pi-people.sh +264 -0
  12. package/core/god.pi.mod/cli/pi-people.sh.LESSON +10 -0
  13. package/core/god.pi.mod/cli/pi-people.sh.SPEC +31 -0
  14. package/core/god.pi.mod/paths.ts +47 -0
  15. package/core/god.pi.mod/tui.mods.blockrender/blockrender.js +90 -0
  16. package/core/god.pi.mod/tui.mods.blockrender/blockrender.js.SPEC +29 -0
  17. package/core/god.pi.mod/tui.mods.footer.budget/budget_guard.ts +154 -0
  18. package/core/god.pi.mod/tui.mods.footer.budget/budget_guard.ts.CHANGELOG +10 -0
  19. package/core/god.pi.mod/tui.mods.footer.budget/budget_guard.ts.LESSON +12 -0
  20. package/core/god.pi.mod/tui.mods.footer.budget/budget_guard.ts.SPEC +26 -0
  21. package/core/god.pi.mod/tui.mods.footer.budget/footer-cny.CHANGELOG +39 -0
  22. package/core/god.pi.mod/tui.mods.viewmode/view_mode-thinking.patch +55 -0
  23. package/core/god.pi.mod/tui.mods.viewmode/view_mode-tools.patch +19 -0
  24. package/core/god.pi.mod/tui.mods.viewmode/view_mode-tools.patch.CHANGELOG +1 -0
  25. package/core/god.pi.mod/tui.mods.viewmode/view_mode.ts +50 -0
  26. package/core/god.pi.mod/tui.mods.viewmode/view_mode.ts.SPEC +12 -0
  27. package/core/god.pi.mod/tui.variants.userterminal/user_terminal.CHANGELOG +10 -0
  28. package/core/god.pi.mod/tui.variants.userterminal/user_terminal.ts +66 -0
  29. package/core/god.pi.mod/tui.variants.userterminal/user_terminal.ts.SPEC +31 -0
  30. package/core/index.ts +3 -0
  31. package/core/individual.bio.gene/dna.coded/coded.dna +257 -0
  32. package/core/individual.bio.gene/dna.coded/coded.dna.CHANGELOG +12 -0
  33. package/core/individual.bio.gene/dna.coded/coded.dna.SPEC +11 -0
  34. package/core/individual.bio.gene/dna.coded/core.dna +110 -0
  35. package/core/individual.bio.gene/dna.promotor/promotor.dna +117 -0
  36. package/core/individual.bio.gene/dna.promotor/promotor.dna.CHANGELOG +4 -0
  37. package/core/individual.bio.gene/dna.promotor/promotor.dna.SPEC +7 -0
  38. package/core/individual.bio.gene/dna.transpiler/transpiler.ts +395 -0
  39. package/core/individual.bio.gene/dna.transpiler/transpiler.ts.CHANGELOG +7 -0
  40. package/core/individual.bio.gene/dna.transpiler/transpiler.ts.SPEC +28 -0
  41. package/core/individual.bio.gene/gene.README +19 -0
  42. package/core/individual.bio.gene/rna/rna.json +536 -0
  43. package/core/individual.bio.gene/rna/rna.json.CHANGELOG +2 -0
  44. package/core/individual.bio.gene/rna/rna.json.SPEC +8 -0
  45. package/core/individual.bio.organs/blood.runtime/messages.ts +236 -0
  46. package/core/individual.bio.organs/blood.runtime/runtime.ts +173 -0
  47. package/core/individual.bio.organs/blood.runtime/runtime.ts.CHANGELOG +5 -0
  48. package/core/individual.bio.organs/blood.runtime/runtime.ts.SPEC +32 -0
  49. package/core/individual.bio.organs/brain.amygdala/amygdala.ts +25 -0
  50. package/core/individual.bio.organs/brain.amygdala/amygdala.ts.COMMENT +3 -0
  51. package/core/individual.bio.organs/brain.amygdala/amygdala.ts.SPEC +9 -0
  52. package/core/individual.bio.organs/brain.hippocampus/hippocampus-launcher.sh.template +108 -0
  53. package/core/individual.bio.organs/brain.hippocampus/hippocampus.ts +166 -0
  54. package/core/individual.bio.organs/brain.hippocampus/hippocampus.ts.CHANGELOG +12 -0
  55. package/core/individual.bio.organs/brain.hippocampus/hippocampus.ts.LESSON +22 -0
  56. package/core/individual.bio.organs/brain.hippocampus/hippocampus.ts.SPEC +16 -0
  57. package/core/individual.bio.organs/brain.hippocampus/memory.ts +879 -0
  58. package/core/individual.bio.organs/brain.hippocampus/memory.ts.CHANGELOG +66 -0
  59. package/core/individual.bio.organs/brain.hippocampus/memory.ts.LESSON +25 -0
  60. package/core/individual.bio.organs/brain.hippocampus/memory.ts.SPEC +46 -0
  61. package/core/individual.bio.organs/brain.hippocampus/sleep.ts +139 -0
  62. package/core/individual.bio.organs/brain.hippocampus/sleep.ts.CHANGELOG +11 -0
  63. package/core/individual.bio.organs/brain.hippocampus/sleep.ts.SPEC +16 -0
  64. package/core/individual.bio.organs/brain.prefrontal.drafting/drafting.SPEC +44 -0
  65. package/core/individual.bio.organs/brain.prefrontal.drafting/drafting.ts +73 -0
  66. package/core/individual.bio.organs/brain.prefrontal.drafting/drafting.ts.CHANGELOG +3 -0
  67. package/core/individual.bio.organs/brain.prefrontal.drafting/drafting.ts.SPEC +24 -0
  68. package/core/individual.bio.organs/brain.prefrontal.drafting/index.ts.CHANGELOG +3 -0
  69. package/core/individual.bio.organs/brain.prefrontal.drafting/main.ts +13 -0
  70. package/core/individual.bio.organs/brain.prefrontal.drafting/main.ts.SPEC +17 -0
  71. package/core/individual.bio.organs/brain.senses.bioclock/bioclock.ts +94 -0
  72. package/core/individual.bio.organs/brain.senses.bioclock/bioclock.ts.LESSON +13 -0
  73. package/core/individual.bio.organs/brain.senses.bioclock/bioclock.ts.SPEC +20 -0
  74. package/core/individual.bio.organs/brain.senses.subconscious/feed-format.SPEC +56 -0
  75. package/core/individual.bio.organs/brain.senses.subconscious/index.ts.CHANGELOG +13 -0
  76. package/core/individual.bio.organs/brain.senses.subconscious/spawner.ts +130 -0
  77. package/core/individual.bio.organs/brain.senses.subconscious/spawner.ts.SPEC +13 -0
  78. package/core/individual.bio.organs/brain.senses.subconscious/subconscious.ts +280 -0
  79. package/core/individual.bio.organs/brain.senses.subconscious/subconscious.ts.CHANGELOG +7 -0
  80. package/core/individual.bio.organs/brain.senses.subconscious/tools.ts +180 -0
  81. package/core/individual.bio.organs/brain.senses.subconscious/tools.ts.SPEC +3 -0
  82. package/core/individual.bio.organs/ears.listen/config.json +9 -0
  83. package/core/individual.bio.organs/ears.listen/config.json.CHANGELOG +1 -0
  84. package/core/individual.bio.organs/ears.listen/config.json.SPEC +3 -0
  85. package/core/individual.bio.organs/ears.listen/ears.ts.CHANGELOG +48 -0
  86. package/core/individual.bio.organs/ears.listen/ears_recorder.py.CHANGELOG +6 -0
  87. package/core/individual.bio.organs/ears.listen/index.ts +1 -0
  88. package/core/individual.bio.organs/ears.listen/index.ts.SPEC +16 -0
  89. package/core/individual.bio.organs/ears.listen/listen.ts +208 -0
  90. package/core/individual.bio.organs/ears.listen/listen.ts.SPEC +3 -0
  91. package/core/individual.bio.organs/ears.listen/listen_recorder.py +445 -0
  92. package/core/individual.bio.organs/ears.listen/listen_recorder.py.SPEC +7 -0
  93. package/core/individual.bio.organs/ears.listen/python_protogen/__init__.py +0 -0
  94. package/core/individual.bio.organs/ears.listen/python_protogen/common/__init__.py +0 -0
  95. package/core/individual.bio.organs/ears.listen/python_protogen/common/events_pb2.py +38 -0
  96. package/core/individual.bio.organs/ears.listen/python_protogen/common/events_pb2_grpc.py +24 -0
  97. package/core/individual.bio.organs/ears.listen/python_protogen/common/rpcmeta_pb2.py +42 -0
  98. package/core/individual.bio.organs/ears.listen/python_protogen/common/rpcmeta_pb2_grpc.py +24 -0
  99. package/core/individual.bio.organs/ears.listen/python_protogen/products/__init__.py +0 -0
  100. package/core/individual.bio.organs/ears.listen/python_protogen/products/understanding/__init__.py +0 -0
  101. package/core/individual.bio.organs/ears.listen/python_protogen/products/understanding/ast/__init__.py +0 -0
  102. package/core/individual.bio.organs/ears.listen/python_protogen/products/understanding/ast/ast_service_pb2.py +45 -0
  103. package/core/individual.bio.organs/ears.listen/python_protogen/products/understanding/ast/ast_service_pb2_grpc.py +97 -0
  104. package/core/individual.bio.organs/ears.listen/python_protogen/products/understanding/base/__init__.py +0 -0
  105. package/core/individual.bio.organs/ears.listen/python_protogen/products/understanding/base/au_base_pb2.py +80 -0
  106. package/core/individual.bio.organs/ears.listen/python_protogen/products/understanding/base/au_base_pb2_grpc.py +24 -0
  107. package/core/individual.bio.organs/hands.fileactions/authorize.TRUST +1 -0
  108. package/core/individual.bio.organs/hands.fileactions/authorize.ts +70 -0
  109. package/core/individual.bio.organs/hands.fileactions/authorize.ts.CHANGELOG +1 -0
  110. package/core/individual.bio.organs/hands.fileactions/authorize.ts.SPEC +3 -0
  111. package/core/individual.bio.organs/hands.fileactions/dir.README +13 -0
  112. package/core/individual.bio.organs/hands.fileactions/file_rules.json +23 -0
  113. package/core/individual.bio.organs/hands.fileactions/fileactions.README +12 -0
  114. package/core/individual.bio.organs/hands.fileactions/fileactions.ts +540 -0
  115. package/core/individual.bio.organs/hands.fileactions/fileactions.ts.CHANGELOG +25 -0
  116. package/core/individual.bio.organs/hands.fileactions/fileactions.ts.SPEC +30 -0
  117. package/core/individual.bio.organs/hands.fileactions/filewatch.ts +66 -0
  118. package/core/individual.bio.organs/hands.fileactions/filewatch.ts.SPEC +3 -0
  119. package/core/individual.bio.organs/hands.main/main.ts +18 -0
  120. package/core/individual.bio.organs/hands.main/main.ts.SPEC +20 -0
  121. package/core/individual.bio.organs/hands.sensitive/sensitive.ts +24 -0
  122. package/core/individual.bio.organs/hands.sensitive/sensitive.ts.CHANGELOG +2 -0
  123. package/core/individual.bio.organs/hands.sensitive/sensitive.ts.SPEC +3 -0
  124. package/core/individual.bio.organs/heart.interrupt/agent_start-loader-flicker.patch +13 -0
  125. package/core/individual.bio.organs/heart.interrupt/interactive-mode-loader.patch +11 -0
  126. package/core/individual.bio.organs/heart.interrupt/runner_esc.patch +10 -0
  127. package/core/individual.bio.organs/heart.interrupt/runner_esc.patch.SPEC +9 -0
  128. package/core/individual.bio.organs/heart.kernel/kernel.ts +253 -0
  129. package/core/individual.bio.organs/heart.kernel/kernel.ts.CHANGELOG +13 -0
  130. package/core/individual.bio.organs/heart.kernel/kernel.ts.SPEC +23 -0
  131. package/core/individual.bio.organs/heart.main/heart.main.CHANGELOG +43 -0
  132. package/core/individual.bio.organs/heart.main/heartbeat.ts +494 -0
  133. package/core/individual.bio.organs/heart.main/heartbeat.ts.LESSON +43 -0
  134. package/core/individual.bio.organs/heart.main/main.ts +8 -0
  135. package/core/individual.bio.organs/heart.main/main.ts.SPEC +19 -0
  136. package/core/individual.bio.organs/heart.main/process.ts +122 -0
  137. package/core/individual.bio.organs/heart.main/process.ts.CHANGELOG +2 -0
  138. package/core/individual.bio.organs/heart.main/process.ts.SPEC +24 -0
  139. package/core/individual.bio.organs/heart.main/remove_timeout.patch +110 -0
  140. package/core/individual.bio.organs/heart.main/stop.ts.CHANGELOG +3 -0
  141. package/core/individual.bio.organs/heart.main/stop.ts.SPEC +28 -0
  142. package/core/individual.bio.organs/mouth.speak/index.ts +1 -0
  143. package/core/individual.bio.organs/mouth.speak/index.ts.CHANGELOG +1 -0
  144. package/core/individual.bio.organs/mouth.speak/index.ts.SPEC +6 -0
  145. package/core/individual.bio.organs/mouth.speak/mouth.ts.CHANGELOG +15 -0
  146. package/core/individual.bio.organs/mouth.speak/mouth_recorder.py.CHANGELOG +1 -0
  147. package/core/individual.bio.organs/mouth.speak/speak.ts +180 -0
  148. package/core/individual.bio.organs/mouth.speak/speak.ts.SPEC +3 -0
  149. package/core/individual.bio.organs/mouth.speak/speak_recorder.py +35 -0
  150. package/core/individual.bio.organs/mouth.speak/speak_recorder.py.SPEC +3 -0
  151. package/core/individual.bio.organs/organs.README +110 -0
  152. package/core/package-lock.json +18 -0
  153. package/core/package.json +35 -0
  154. package/core/prompts/prompts.json +77 -0
  155. package/core/prompts/prompts.ts +44 -0
  156. package/core/prompts/prompts.ts.SPEC +9 -0
  157. package/core/society.world/.gitkeep +0 -0
  158. package/core/society.world/accessibility.claudecode/message-service.cjs +217 -0
  159. package/core/society.world/accessibility.claudecode/message-service.cjs.SPEC +7 -0
  160. package/core/society.world/accessibility.claudecode/send.ts +34 -0
  161. package/core/society.world/dollar.distribution.ubi/ubi.ts +55 -0
  162. package/core/society.world/dollar.main/dollar-service.cjs +185 -0
  163. package/core/society.world/dollar.main/main.ts +116 -0
  164. package/core/society.world/dollar.transaction/transaction.ts +71 -0
  165. package/core/society.world/space/space.ts +206 -0
  166. package/core/society.world/space/space.ts.SPEC +30 -0
  167. package/core/technology.laptop/#agent.macos.BLUEPRINT +278 -0
  168. package/core/technology.phone/apps.preinstalled/albums.FUTURE/albums.ts +69 -0
  169. package/core/technology.phone/apps.preinstalled/albums.FUTURE/albums.ts.SPEC +15 -0
  170. package/core/technology.phone/apps.preinstalled/calendar/calendar.ts +406 -0
  171. package/core/technology.phone/apps.preinstalled/calendar/calendar.ts.SPEC +22 -0
  172. package/core/technology.phone/apps.preinstalled/calendar/holiday-calendar.ts +529 -0
  173. package/core/technology.phone/apps.preinstalled/clock/clock.ts +132 -0
  174. package/core/technology.phone/apps.preinstalled/clock/clock.ts.SPEC +11 -0
  175. package/core/technology.phone/apps.preinstalled/contacts.FUTURE/contacts.ts +300 -0
  176. package/core/technology.phone/apps.preinstalled/contacts.FUTURE/contacts.ts.SPEC +22 -0
  177. package/core/technology.phone/apps.preinstalled/developer.FUTURE/developer.ts +22 -0
  178. package/core/technology.phone/apps.preinstalled/developer.FUTURE/developer.ts.SPEC +15 -0
  179. package/core/technology.phone/apps.preinstalled/notes/notes.ts +239 -0
  180. package/core/technology.phone/apps.preinstalled/notes/notes.ts.SPEC +21 -0
  181. package/core/technology.phone/apps.preinstalled/polymarket/polymarket.ts +261 -0
  182. package/core/technology.phone/apps.preinstalled/polymarket/polymarket.ts.SPEC +7 -0
  183. package/core/technology.phone/apps.preinstalled/reminder/reminder.ts +404 -0
  184. package/core/technology.phone/apps.preinstalled/reminder/reminder.ts.SPEC +25 -0
  185. package/core/technology.phone/apps.preinstalled/siri.FUTURE/siri.ts +22 -0
  186. package/core/technology.phone/apps.preinstalled/siri.FUTURE/siri.ts.SPEC +15 -0
  187. package/core/technology.phone/apps.preinstalled/spotlight/spotlight.ts +29 -0
  188. package/core/technology.phone/apps.preinstalled/spotlight/spotlight.ts.SPEC +7 -0
  189. package/core/technology.phone/apps.preinstalled/steam/chess.ts +230 -0
  190. package/core/technology.phone/apps.preinstalled/steam/snake.ts +100 -0
  191. package/core/technology.phone/apps.preinstalled/steam/snake.ts.SPEC +7 -0
  192. package/core/technology.phone/apps.preinstalled/steam/spy-cmd.ts +4 -0
  193. package/core/technology.phone/apps.preinstalled/steam/spy-tool.ts +56 -0
  194. package/core/technology.phone/apps.preinstalled/steam/spy.ts +302 -0
  195. package/core/technology.phone/apps.preinstalled/steam/steam.ts +299 -0
  196. package/core/technology.phone/apps.preinstalled/weather/weather.ts +50 -0
  197. package/core/technology.phone/apps.preinstalled/weather/weather.ts.SPEC +9 -0
  198. package/core/technology.phone/apps.preinstalled/wechat/imessage.ts +423 -0
  199. package/core/technology.phone/apps.preinstalled/wechat/imessage.ts.SPEC +24 -0
  200. package/core/technology.phone/apps.system/appstore/appstore.ts +22 -0
  201. package/core/technology.phone/apps.system/appstore/appstore.ts.SPEC +15 -0
  202. package/core/technology.phone/apps.system/finder.FUTURE/finder.ts +64 -0
  203. package/core/technology.phone/apps.system/finder.FUTURE/finder.ts.SPEC +8 -0
  204. package/core/technology.phone/apps.system/safari/safari-app.ts +146 -0
  205. package/core/technology.phone/apps.system/safari/safari.ts.SPEC +24 -0
  206. package/core/technology.phone/apps.system/settings/settings.ts +126 -0
  207. package/core/technology.phone/apps.system/settings/settings.ts.SPEC +17 -0
  208. package/core/technology.phone/apps.system/tips/tips.ts +22 -0
  209. package/core/technology.phone/apps.system/tips/tips.ts.SPEC +15 -0
  210. package/core/technology.phone/apps.thirdparty/alipay/alipay.ts +148 -0
  211. package/core/technology.phone/apps.thirdparty/alipay/alipay.ts.SPEC +7 -0
  212. package/core/technology.phone/apps.thirdparty/bilibili/bilibili-app.ts +33 -0
  213. package/core/technology.phone/apps.thirdparty/bilibili/bilibili.ts +142 -0
  214. package/core/technology.phone/apps.thirdparty/bilibili/bilibili.ts.SPEC +22 -0
  215. package/core/technology.phone/apps.thirdparty/wechatread/wechatread.ts +80 -0
  216. package/core/technology.phone/apps.thirdparty/wechatread/wechatread.ts.SPEC +15 -0
  217. package/core/technology.phone/index.ts +1 -0
  218. package/core/technology.phone/package.json +2 -0
  219. package/core/technology.phone/system.homepage/homepage.ts +247 -0
  220. package/core/technology.phone/system.homepage/homepage.ts.SPEC +22 -0
  221. package/core/technology.phone/system.kernel/kernel.ts +264 -0
  222. package/core/technology.phone/system.kernel/kernel.ts.SPEC +7 -0
  223. package/core/technology.phone/system.notifications/notifications.ts +87 -0
  224. package/core/technology.phone/system.notifications/notifications.ts.SPEC +7 -0
  225. package/core/technology.phone/system.share/share.ts +46 -0
  226. package/core/technology.phone/system.share/share.ts.SPEC +7 -0
  227. package/core/technology.server/browser-service.cjs +152 -0
  228. package/core/technology.server/data/cookies/arxiv.json +30 -0
  229. package/core/technology.server/data/cookies/bili.json +184 -0
  230. package/core/technology.server/data/cookies/default.json +30 -0
  231. package/core/technology.server/data/cookies/news.json +113 -0
  232. package/core/technology.server/data/cookies/s1.json +45 -0
  233. package/core/technology.server/data/cookies/safari.json +184 -0
  234. package/core/technology.server/data/cookies/safari2.json +1 -0
  235. package/core/technology.server/data/cookies/safaridbg.json +1 -0
  236. package/core/technology.server/data/cookies/search.json +45 -0
  237. package/core/technology.server/data/cookies/sw.json +30 -0
  238. package/core/technology.server/data/cookies/t1.json +1 -0
  239. package/core/technology.server/data/cookies/testread.json +1 -0
  240. package/core/technology.server/data/cookies/video1.json +113 -0
  241. package/core/technology.server/data/cookies/yt.json +170 -0
  242. package/core/technology.server/data/cookies/yt2.json +113 -0
  243. package/core/technology.server/pikipedia/#pikipedia.BLUEPRINT +106 -0
  244. package/core/technology.server/playleft.cjs +247 -0
  245. package/core/technology.server/search-proxy.py +76 -0
  246. package/core/technology.server/server.README +59 -0
  247. package/deploy/dist-overrides/cli/cli.js +18 -0
  248. package/deploy/dist-overrides/core/extensions/loader.js +518 -0
  249. package/deploy/dist-overrides/core/package-manager.js +2081 -0
  250. package/deploy/dist-overrides/core/system-prompt.js +109 -0
  251. package/deploy/dist-overrides/core/system-prompt.js.LESSON +17 -0
  252. package/deploy/dist-overrides/core/tools/bash.js +353 -0
  253. package/deploy/dist-overrides/core/tools/bash.js.CHANGELOG +2 -0
  254. package/deploy/dist-overrides/core/tools/edit-diff.js +345 -0
  255. package/deploy/dist-overrides/core/tools/edit.js +315 -0
  256. package/deploy/dist-overrides/core/tools/edit.js.CHANGELOG +1 -0
  257. package/deploy/dist-overrides/core/tools/file-mutation-queue.js +52 -0
  258. package/deploy/dist-overrides/core/tools/find.js +298 -0
  259. package/deploy/dist-overrides/core/tools/find.js.CHANGELOG +1 -0
  260. package/deploy/dist-overrides/core/tools/grep.js +305 -0
  261. package/deploy/dist-overrides/core/tools/grep.js.CHANGELOG +1 -0
  262. package/deploy/dist-overrides/core/tools/index.js +112 -0
  263. package/deploy/dist-overrides/core/tools/ls-guard.js +4 -0
  264. package/deploy/dist-overrides/core/tools/ls.js +170 -0
  265. package/deploy/dist-overrides/core/tools/ls.js.CHANGELOG +1 -0
  266. package/deploy/dist-overrides/core/tools/output-accumulator.js +184 -0
  267. package/deploy/dist-overrides/core/tools/path-utils.js +99 -0
  268. package/deploy/dist-overrides/core/tools/prompts-reader.js +53 -0
  269. package/deploy/dist-overrides/core/tools/read.js +392 -0
  270. package/deploy/dist-overrides/core/tools/read.js.CHANGELOG +1 -0
  271. package/deploy/dist-overrides/core/tools/render-utils.js +65 -0
  272. package/deploy/dist-overrides/core/tools/tool-definition-wrapper.js +34 -0
  273. package/deploy/dist-overrides/core/tools/truncate.js +215 -0
  274. package/deploy/dist-overrides/core/tools/write.js +203 -0
  275. package/deploy/dist-overrides/core/tools/write.js.CHANGELOG +1 -0
  276. package/deploy/dist-overrides/dist-overrides.README +18 -0
  277. package/deploy/dist-overrides/main.js +665 -0
  278. package/deploy/dist-overrides/modes/interactive/components/assistant-message.js +139 -0
  279. package/deploy/dist-overrides/modes/interactive/components/footer.js +326 -0
  280. package/deploy/dist-overrides/modes/interactive/components/model-selector.js +285 -0
  281. package/deploy/dist-overrides/modes/interactive/components/tool-execution.js +383 -0
  282. package/deploy/dist-overrides/modes/interactive/components/tool-execution.js.CHANGELOG +3 -0
  283. package/deploy/dist-overrides/modes/interactive/interactive-mode.js +4781 -0
  284. package/deploy/dist-overrides/pi-ai/providers/anthropic.js +931 -0
  285. package/deploy/dist-overrides/pi-ai/providers/openai-completions.js +1007 -0
  286. package/deploy/dist-overrides/pi-ai/providers/openai-completions.js.LESSON +15 -0
  287. package/deploy/dist-overrides/pi-tui/components/loader.js +69 -0
  288. package/deploy/dist-overrides/pi-tui/components/markdown.js +646 -0
  289. package/deploy/dist-overrides/pi-tui/components/text.js +92 -0
  290. package/deploy/dist-overrides/pi-tui/custom-message.js +75 -0
  291. package/deploy/dist-overrides/pi-tui/tui.js +1266 -0
  292. package/deploy/dist-overrides/pi-tui/utils.js +1060 -0
  293. package/deploy/dist-overrides/vendor.REMOVED/jiti/lib/jiti.mjs +3 -0
  294. package/deploy/install.sh +186 -0
  295. package/deploy/install.sh.CHANGELOG +6 -0
  296. package/deploy/lint/lint-naming.ts +202 -0
  297. package/deploy/scripts/apply.js +18 -0
  298. package/deploy/scripts/build-github.sh +219 -0
  299. package/deploy/scripts/build-phone.sh +24 -0
  300. package/deploy/scripts/check-deploy.sh +42 -0
  301. package/deploy/scripts/migrate-context.sh +72 -0
  302. package/deploy/scripts/patch-pi-dist.js +39 -0
  303. package/deploy/scripts/uninstall.sh +34 -0
  304. package/package.json +18 -0
@@ -0,0 +1,494 @@
1
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
2
+ import { Type } from "@sinclair/typebox";
3
+ import { createRequire } from "node:module";
4
+ const require = createRequire(import.meta.url);
5
+ import { appendFileSync, writeFileSync, readFileSync } from "node:fs";
6
+ import { homedir } from "node:os";
7
+ import { join } from "node:path";
8
+ import { getSessionRole, getFuncPrompts } from "#runtime";
9
+ import { sendCustomMessage } from "#messages";
10
+ declare global { var __piEscJustPressed: boolean | undefined; }
11
+
12
+ const DEBUG = true;
13
+ function dlog(msg: string) {
14
+ if (!DEBUG) return;
15
+ try { const d=new Date(); const ts=`${d.toLocaleString("zh-CN",{timeZone:"Asia/Shanghai",hour12:false})}.${String(d.getMilliseconds()).padStart(3,'0')}`; appendFileSync("/tmp/continuous-debug.log", `[${ts}] [${process.title}] ${msg}\n`); } catch {}
16
+ }
17
+
18
+ const PROMPT = getFuncPrompts("heart.main").join("\n\n").replace("{role}", getSessionRole());
19
+
20
+ // ── 状态机 ─────────────────────────────────────────────────────────────────
21
+ // 心脏有 5 个互斥状态。transition() 清理旧状态的 timer,再切到新状态。
22
+ // 不再用 5 个 bool flag 编码(enabled/disabledByUser/isResting/hasUserMessage/lastHibernateTs)。
23
+
24
+ type Timer = ReturnType<typeof setTimeout>;
25
+ type Interval = ReturnType<typeof setInterval>;
26
+
27
+ type Heart =
28
+ | { kind: "alive" }
29
+ | { kind: "resting"; resumeTimer: Timer; countdownTimer: Interval }
30
+ | { kind: "hibernating"; ts: number }
31
+ | { kind: "stopped" }
32
+ | { kind: "error-backoff"; retryTimer: Timer };
33
+
34
+ interface Limits {
35
+ maxCount: number;
36
+ timeLimitMs: number;
37
+ count: number;
38
+ startTime: number;
39
+ timeLimitTimer: Timer | null;
40
+ }
41
+
42
+ export function registerHeartbeat(pi: ExtensionAPI) {
43
+ const _cmds: any[] = [];
44
+ let heart: Heart = { kind: "alive" };
45
+ let limits: Limits = { maxCount: -1, timeLimitMs: -1, count: 0, startTime: 0, timeLimitTimer: null };
46
+ let errorBackoffMs = 0;
47
+ let hasUserMessage = false;
48
+ let lastHint = "";
49
+ let _ui: any = null;
50
+
51
+ function transition(to: Heart): void {
52
+ if (heart.kind === "resting") {
53
+ clearTimeout(heart.resumeTimer);
54
+ clearInterval(heart.countdownTimer);
55
+ try { _ui?.setWorkingMessage(); _ui?.setWorkingVisible(false); } catch {}
56
+ }
57
+ else if (heart.kind === "error-backoff") {
58
+ clearTimeout(heart.retryTimer);
59
+ try { _ui?.setWorkingMessage(); _ui?.setWorkingVisible(false); } catch {}
60
+ }
61
+ if (to.kind !== "alive" && limits.timeLimitTimer) { clearTimeout(limits.timeLimitTimer); limits.timeLimitTimer = null; }
62
+ dlog(`transition: ${heart.kind} → ${to.kind}`);
63
+ heart = to;
64
+ }
65
+
66
+ function resetLimits(): void {
67
+ if (limits.timeLimitTimer) { clearTimeout(limits.timeLimitTimer); limits.timeLimitTimer = null; }
68
+ limits = { maxCount: -1, timeLimitMs: -1, count: 0, startTime: Date.now(), timeLimitTimer: null };
69
+ }
70
+
71
+ // ── helpers ──
72
+ function wakeRestartFile(ctx: any): string | null {
73
+ try {
74
+ const sf = ctx?.sessionManager?.getSessionFile?.() || "";
75
+ const m = sf.match(/\.pi\/memory\/([a-f0-9]+)\//);
76
+ return m ? join(homedir(), ".pi/memory", m[1], ".data", ".wake-restart") : null;
77
+ } catch { return null; }
78
+ }
79
+ function isWorkerSession(ctx: any): boolean {
80
+ try {
81
+ const sf = ctx?.sessionManager?.getSessionFile?.() || "";
82
+ return /conscious-sessions|hippocampus-sessions|sleep-sessions/.test(sf);
83
+ } catch { return false; }
84
+ }
85
+ function isHibernateDisabled(): boolean { return process.env.PI_DISABLE_HIBERNATE === "1"; }
86
+ function isWaitDisabled(): boolean { return process.env.PI_DISABLE_WAIT === "1"; }
87
+
88
+ // ── /switches wait|hibernate [on|off] ──
89
+ _cmds.push({
90
+ name: "switches",
91
+ desc: "/switches <wait|hibernate> [on|off]",
92
+ handler: async (args: any, ctx: any) => {
93
+ const parts = (args ?? "").trim().toLowerCase().split(/\s+/);
94
+ const sub = parts[0];
95
+ const a = parts[1] ?? "";
96
+ if (sub === "hibernate") {
97
+ if (a === "off") { process.env.PI_DISABLE_HIBERNATE = "1"; ctx.ui.notify("hibernate 已禁用。", "info"); }
98
+ else if (a === "on") { delete process.env.PI_DISABLE_HIBERNATE; ctx.ui.notify("hibernate 已恢复。", "info"); }
99
+ else { ctx.ui.notify(`hibernate 当前:${isHibernateDisabled() ? "禁用" : "启用"}`, "info"); }
100
+ } else if (sub === "wait") {
101
+ if (a === "off") { process.env.PI_DISABLE_WAIT = "1"; ctx.ui.notify("wait 已禁用。", "info"); }
102
+ else if (a === "on") { delete process.env.PI_DISABLE_WAIT; ctx.ui.notify("wait 已恢复。", "info"); }
103
+ else { ctx.ui.notify(`wait 当前:${isWaitDisabled() ? "禁用" : "启用"}`, "info"); }
104
+ } else {
105
+ ctx.ui.notify(`/switches wait|hibernate [on|off]\n wait: ${isWaitDisabled() ? "禁用" : "启用"} hibernate: ${isHibernateDisabled() ? "禁用" : "启用"}`, "info");
106
+ }
107
+ },
108
+ });
109
+
110
+ // ── next tool ──────────────────────────────────────────────────────────────
111
+ pi.registerTool({
112
+ name: "next",
113
+ label: "Next",
114
+ messageDescription:
115
+ "Call this at the end of every turn. REQUIRED — turn will fail if omitted. " +
116
+ "Three modes — pick exactly one, cannot be empty: " +
117
+ "(1) next({hint:'plan'}) = continue immediately, show plan in title. " +
118
+ "(2) next({wait:N}) = pause N seconds then auto-resume. " +
119
+ "(3) next({hibernate:'summary'}) = rest until user returns.",
120
+ promptSnippet: "Turn end. Must call next() with one param: {hint:'plan'}, {wait:N}s, or {hibernate:'summary'}. Cannot be empty.",
121
+ parameters: Type.Object({
122
+ hint: Type.Optional(Type.String({ messageDescription: "(mode 1) What you will do next turn — displayed in title bar" })),
123
+ wait: Type.Optional(Type.Number({ messageDescription: "(mode 2) Seconds to pause before auto-resuming (1-86400)" })),
124
+ wait_for_user: Type.Optional(Type.Boolean({ messageDescription: "(mode 2) With wait: spend pause listening for user input" })),
125
+ next_steps: Type.Optional(Type.String({ messageDescription: "(mode 2) With wait: what to do when you wake up" })),
126
+ hibernate: Type.Optional(Type.String({ messageDescription: "(mode 3) Summary of what you accomplished — hibernate until user returns" })),
127
+ }),
128
+ renderCall(args: any, theme: any) {
129
+ const { Text } = require("@earendil-works/pi-tui");
130
+ const hb = args?.hibernate?.trim();
131
+ const wt = args?.wait;
132
+ const ht = args?.hint?.trim() || lastHint || "继续";
133
+ if (hb) return new Text(theme.fg("toolTitle", "● " + theme.bold("Hibernate")) + " " + theme.fg("dim", hb.slice(0, 50)), 0, 0);
134
+ if (wt != null) return new Text(theme.fg("toolTitle", "● " + theme.bold("Wait")) + " " + theme.fg("accent", `${wt}s`), 0, 0);
135
+ return new Text(theme.fg("success", theme.bold("● Next")) + " " + ht.slice(0, 60), 0, 0);
136
+ },
137
+ async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
138
+ if (!params.hint?.trim() && params.wait == null && !params.hibernate?.trim()) {
139
+ return { content: [{ type: "text", text: "ERR: next 不能为空。必须带参数: next({hint:'...'}), next({wait:N}), next({hibernate:'...'})" }], details: {}, isError: true };
140
+ }
141
+
142
+ // ── hint: 继续 ──
143
+ if (!params.hibernate?.trim() && params.wait == null) {
144
+ lastHint = params.hint?.trim() || "";
145
+ try { (globalThis as any).__piAbort?.(); } catch {}
146
+ return { content: [], details: { hint: lastHint || "continue" }, terminate: true };
147
+ }
148
+
149
+ // ── hibernate ──
150
+ if (params.hibernate?.trim()) {
151
+ if (isHibernateDisabled()) {
152
+ return { content: [{ type: "text", text: "ERR: hibernate 已被禁用(/hibernate off)。用 next({wait:N}) 代替。" }], details: {}, isError: true };
153
+ }
154
+ transition({ kind: "hibernating", ts: Date.now() });
155
+ hasUserMessage = false;
156
+ dlog("next:{hibernate}");
157
+ try { (globalThis as any).__piAbort?.(); } catch {}
158
+ try { ctx.ui.setWorkingVisible(false); } catch {}
159
+ return { content: [], details: { hibernate: params.hibernate }, terminate: true };
160
+ }
161
+
162
+ // ── wait ──
163
+ if (params.wait != null) {
164
+ if (isWaitDisabled()) {
165
+ return { content: [{ type: "text", text: "ERR: wait 已被禁用(/wait off)。用 next({hibernate:'...'}) 休息。" }], details: {}, isError: true };
166
+ }
167
+ const secs = Math.max(1, params.wait);
168
+ const waiting = params.wait_for_user === true;
169
+ hasUserMessage = false;
170
+
171
+ let remaining = secs;
172
+ const label = () => (waiting ? `Waiting for user ${remaining}s...` : `Resting ${remaining}s...`);
173
+
174
+ const countdownTimer: Interval = setInterval(() => {
175
+ if (heart.kind !== "resting") { clearInterval(countdownTimer); return; }
176
+ if (globalThis.__piEscJustPressed === true) {
177
+ globalThis.__piEscJustPressed = false;
178
+ dlog("countdown: ESC → stopped");
179
+ transition({ kind: "stopped" });
180
+ hasUserMessage = false;
181
+ return;
182
+ }
183
+ remaining--;
184
+ if (remaining <= 0) { clearInterval(countdownTimer); return; }
185
+ try { ctx.ui.setWorkingMessage(label()); } catch {}
186
+ }, 1000);
187
+
188
+ const resumeTimer: Timer = setTimeout(() => {
189
+ if (heart.kind !== "resting") return;
190
+ if (globalThis.__piEscJustPressed === true) {
191
+ globalThis.__piEscJustPressed = false;
192
+ dlog("resumeTimer: ESC → stopped");
193
+ transition({ kind: "stopped" });
194
+ return;
195
+ }
196
+ dlog("resumeTimer: FIRED → alive");
197
+ transition({ kind: "alive" });
198
+ try {
199
+ const wakeMsg = params.next_steps ? `Woke up after ${secs}s. Continue: ${params.next_steps}` : `Woke up after ${secs}s. Continue working.`;
200
+ sendCustomMessage(pi, "continuous-resume", wakeMsg);
201
+ } catch {}
202
+ }, secs * 1000);
203
+
204
+ transition({ kind: "resting", resumeTimer, countdownTimer });
205
+ setTimeout(() => { if (heart.kind !== "resting") return; try { ctx.ui.setWorkingMessage(label()); ctx.ui.setWorkingVisible(true); } catch {} }, 300);
206
+ dlog(`next:{wait:${secs}}`);
207
+ try { (globalThis as any).__piAbort?.(); } catch {}
208
+ return { content: [], details: { wait: secs, waiting }, terminate: true };
209
+ }
210
+
211
+ return { content: [{ type: "text", text: "未知操作" }], details: {} };
212
+ },
213
+ });
214
+
215
+ // ── prompt injection ──────────────────────────────────────────────────────
216
+ pi.on("before_agent_start", async (event) => {
217
+ if (heart.kind === "stopped" || heart.kind === "hibernating") return;
218
+ if (getSessionRole() !== "main") return;
219
+ return { systemPrompt: event.systemPrompt + "\n\n" + PROMPT };
220
+ });
221
+
222
+ // ── user typing ──────────────────────────────────────────────────────────
223
+ pi.on("input", async (event: any) => {
224
+ if (!event?.text?.trim() || event.text === "(see attached image)") return;
225
+ hasUserMessage = true;
226
+ errorBackoffMs = 0;
227
+ if (heart.kind === "error-backoff") transition({ kind: "alive" });
228
+ });
229
+
230
+ // ── 睡醒 / 用户唤醒 ─────────────────────────────────────────────────────
231
+ pi.on("message_start", async (event: any, ctx: any) => {
232
+ const msg = event?.message;
233
+
234
+ // sleep-done → 重启或原地唤醒
235
+ if (msg?.messageType === "sleep-done" && heart.kind !== "alive") {
236
+ const canRestart = process.env.PI_ALIVE_RESTART_LOOP === "1"
237
+ && !isWorkerSession(ctx) && !hasUserMessage && !ctx?.hasPendingMessages?.();
238
+ const wf = canRestart ? wakeRestartFile(ctx) : null;
239
+ if (wf) {
240
+ dlog("sleep-done → RESTART");
241
+ try { writeFileSync(wf, String(Date.now()), "utf-8"); } catch (e) { dlog("wake nonce write failed: " + e); }
242
+ setTimeout(() => { try { ctx.shutdown(); } catch (e) { dlog("shutdown failed: " + e); } }, 50);
243
+ return;
244
+ }
245
+ dlog("sleep-done → re-enable in place");
246
+ transition({ kind: "alive" });
247
+ resetLimits();
248
+ return;
249
+ }
250
+
251
+ // 用户消息 → 唤醒 hibernate(stopped 不自动唤醒——用户主动关的,要 /continuous 才开)
252
+ if (msg?.role === "user" && !msg?.messageType && heart.kind === "hibernating") {
253
+ const textContent = Array.isArray(msg.content)
254
+ ? msg.content.find((c: any) => c.type === "text")?.text?.trim() || ""
255
+ : (typeof msg.content === "string" ? msg.content.trim() : "");
256
+ if (!textContent) { dlog("WAKE: empty → skip"); return; }
257
+ dlog(`WAKE: text="${textContent.slice(0,80)}"`);
258
+ transition({ kind: "alive" });
259
+ resetLimits();
260
+ try { ctx.ui.setWorkingVisible(true); } catch {}
261
+ }
262
+ });
263
+
264
+ // ── session_start ────────────────────────────────────────────────────────
265
+ pi.on("session_start", async (_event: any, ctx: any) => {
266
+ if (isWorkerSession(ctx)) return;
267
+ _ui = ctx.ui;
268
+ transition({ kind: "alive" });
269
+ resetLimits();
270
+
271
+ // PID 锁:防同一 person 开多个主进程
272
+ const pidMatch = process.title.match(/pi-coding-master:main:([a-f0-9]+)/);
273
+ if (pidMatch) {
274
+ const personId = pidMatch[1];
275
+ const pidFile = join(homedir(), ".pi/memory", personId, ".data/.main.pid");
276
+ try {
277
+ const oldPid = parseInt(readFileSync(pidFile, "utf8").trim(), 10);
278
+ if (oldPid && oldPid !== process.pid) {
279
+ try { process.kill(oldPid, 0); dlog(`旧主进程 ${oldPid} 还在,杀掉`); process.kill(oldPid); } catch {}
280
+ }
281
+ } catch {}
282
+ try { writeFileSync(pidFile, String(process.pid), "utf8"); } catch {}
283
+ }
284
+
285
+ // 睡醒踢一脚
286
+ if (process.env.PI_ALIVE_WOKE === "1") {
287
+ dlog("session_start: PI_ALIVE_WOKE → kick");
288
+ setTimeout(() => {
289
+ try {
290
+ pi.sendMessage(
291
+ { messageType: "sleep-wake-resume", content: "睡醒了。记忆已巩固进 cortex,context 已压缩。", isDisplayedInTUI: false },
292
+ { deliverAs: "followUp", isTriggerNewTurn: true }
293
+ );
294
+ } catch {}
295
+ }, 800);
296
+ } else {
297
+ dlog("session_start: normal → 等用户");
298
+ }
299
+ });
300
+
301
+ // ── agent_end ─────────────────────────────────────────────────────────────
302
+ pi.on("agent_end", async (event, ctx) => {
303
+ dlog(`agent_end: kind=${heart.kind}`);
304
+
305
+ if (heart.kind === "stopped" || heart.kind === "hibernating") {
306
+ try { ctx.ui.setWorkingVisible(false); } catch {}
307
+ return;
308
+ }
309
+ // resting / error-backoff: 各自的 timer 管续命,这里不拦(让 next() 检查等逻辑正常走)
310
+
311
+ // 过滤假图片幻觉
312
+ if (hasUserMessage) {
313
+ const lastCustom = [...(event.messages ?? [])].reverse().find((m: any) => m.role === "custom");
314
+ if (lastCustom?.content === "(see attached image)") { hasUserMessage = false; dlog("agent_end: phantom image filtered"); }
315
+ }
316
+ if (hasUserMessage) {
317
+ dlog("agent_end: hasUserMessage (continuing)");
318
+ hasUserMessage = false;
319
+ }
320
+
321
+ const msgs = event.messages ?? [];
322
+ const last = [...msgs].reverse().find((m: any) => m.role === "assistant");
323
+ if (!last) {
324
+ dlog(`agent_end: NO assistant msg, roles=[${msgs.map((m: any) => m.role).join(",")}]`);
325
+ return;
326
+ }
327
+
328
+ const sr = (last as any).stopReason;
329
+ dlog(`agent_end: stopReason=${sr}`);
330
+
331
+ // Aborted(ESC → stopped;语音 steer → 只停本轮;next() abort → 放行到 auto-continue)
332
+ if (sr === "aborted") {
333
+ if (globalThis.__piEscJustPressed === true) {
334
+ globalThis.__piEscJustPressed = false;
335
+ transition({ kind: "stopped" });
336
+ hasUserMessage = false;
337
+ dlog("agent_end: ESC → stopped");
338
+ return;
339
+ }
340
+ const nextCalled = (last as any).content?.some?.((c: any) => c.type === "toolCall" && c.name === "next");
341
+ if (!nextCalled) {
342
+ if (heart.kind === "resting") {
343
+ dlog("agent_end: aborted (steer) during resting → alive");
344
+ transition({ kind: "alive" });
345
+ } else {
346
+ dlog(`agent_end: aborted (steer), kind=${heart.kind}`);
347
+ }
348
+ return;
349
+ }
350
+ dlog("agent_end: aborted by next() tool → fall through to auto-continue");
351
+ }
352
+
353
+ // Error → exponential backoff retry
354
+ if (sr === "error") {
355
+ const errObj = (last as any).error || (event as any).error;
356
+ const errMsg = (last as any).errorMessage || errObj?.message || errObj || "unknown";
357
+ const errStack = errObj?.stack || "";
358
+ dlog(`agent_end: ERROR: ${errMsg}`);
359
+ try { appendFileSync("/tmp/pi-coding-master-crash.log", `[${new Date().toISOString()}] [${process.title}] agent_end error:\nmsg: ${errMsg}\nstack: ${errStack}\n\n`); } catch {}
360
+
361
+ errorBackoffMs = errorBackoffMs ? Math.min(errorBackoffMs * 2, 300_000) : 20_000;
362
+ const waitMs = errorBackoffMs;
363
+ const retryTimer: Timer = setTimeout(() => {
364
+ if (heart.kind !== "error-backoff") return;
365
+ transition({ kind: "alive" });
366
+ try {
367
+ pi.sendMessage(
368
+ { messageType: "continuous-error-retry", content: `WARN: API 错误: ${String(errMsg).slice(0, 200)}。${Math.round(waitMs / 1000)}s 后重试。`, isDisplayedInTUI: true },
369
+ { deliverAs: "followUp", isTriggerNewTurn: true }
370
+ );
371
+ } catch {}
372
+ }, waitMs);
373
+ transition({ kind: "error-backoff", retryTimer });
374
+ try { ctx.ui.setWorkingMessage(`WARN: API 错误: ${String(errMsg).slice(0, 80)} — ${Math.round(waitMs / 1000)}s 后重试`); } catch {}
375
+ try { ctx.ui.setWorkingVisible(true); } catch {}
376
+ return;
377
+ }
378
+
379
+ // 成功 → 重置错误退避
380
+ errorBackoffMs = 0;
381
+
382
+ // 检查 next() 调用
383
+ const stopCall = (last as any).content?.find?.((c: any) => c.type === "toolCall" && c.name === "next");
384
+ if (stopCall) {
385
+ const args = (stopCall as any).arguments || {};
386
+ if (args.hibernate?.trim()) { dlog("agent_end: next:{hibernate}"); return; }
387
+ if (args.wait != null) { dlog("agent_end: next:{wait} → timer handles"); return; }
388
+ }
389
+
390
+ // 没调 next() → 注入提示重试
391
+ const hasNext = (last as any).content?.some?.((c: any) => c.type === "toolCall" && c.name === "next");
392
+ if (!hasNext) {
393
+ dlog("agent_end: NO next() → retry prompt");
394
+ setTimeout(() => {
395
+ pi.sendMessage(
396
+ { messageType: "continuous-retry", content: "You ended without calling next(). You must call next({hint:'...'}), next({wait:N}), or next({hibernate:'...'}) at the end of every turn.", isDisplayedInTUI: false },
397
+ { deliverAs: "followUp", isTriggerNewTurn: true }
398
+ );
399
+ }, 0);
400
+ return;
401
+ }
402
+
403
+ // 检查 continuous 限制
404
+ if (limits.maxCount > 0 && limits.count >= limits.maxCount) { dlog("agent_end: maxCount reached"); return; }
405
+ if (limits.timeLimitMs > 0 && Date.now() - limits.startTime >= limits.timeLimitMs) { dlog("agent_end: timeLimit reached"); return; }
406
+
407
+ // next({hint}) → 立即续命下一轮
408
+ if (heart.kind === "resting") transition({ kind: "alive" });
409
+ limits.count++;
410
+ dlog(`agent_end: auto-continue (count=${limits.count})`);
411
+ setTimeout(() => {
412
+ pi.sendMessage(
413
+ { messageType: "continuous-next", content: "Continue.", display: false },
414
+ { deliverAs: "followUp", isTriggerNewTurn: true }
415
+ );
416
+ }, 0);
417
+ });
418
+
419
+ // ── session_shutdown ──────────────────────────────────────────────────────
420
+ pi.on("session_shutdown", async () => {
421
+ transition({ kind: "stopped" });
422
+ hasUserMessage = false;
423
+ });
424
+
425
+ // ── agent_start ───────────────────────────────────────────────────────────
426
+ pi.on("agent_start", async (_event, ctx) => {
427
+ hasUserMessage = false;
428
+ if (heart.kind === "resting") {
429
+ dlog("agent_start: resting → alive (turn started)");
430
+ transition({ kind: "alive" });
431
+ }
432
+ if (heart.kind !== "alive") {
433
+ dlog(`agent_start: ${heart.kind} → preserving`);
434
+ return;
435
+ }
436
+ limits.count = 0;
437
+ limits.startTime = Date.now();
438
+ try { ctx.ui.setWorkingMessage(); ctx.ui.setWorkingVisible(true); } catch {}
439
+ });
440
+
441
+ // ── /continuous command ───────────────────────────────────────────────────
442
+ _cmds.push({
443
+ name: "continuous",
444
+ desc: "Toggle continuous mode. /continuous [on|off|<n>|<n>m|<n>s]",
445
+ handler: async (args: any, ctx: any) => {
446
+ const a = (args ?? "").trim().toLowerCase();
447
+
448
+ if (a === "off" || a === "0") {
449
+ transition({ kind: "stopped" });
450
+ } else if (a === "" || a === "toggle") {
451
+ if (heart.kind === "alive") transition({ kind: "stopped" });
452
+ else { transition({ kind: "alive" }); resetLimits(); }
453
+ } else if (a === "on" || a === "inf") {
454
+ transition({ kind: "alive" });
455
+ resetLimits();
456
+ } else if (/^\d+m$/.test(a)) {
457
+ transition({ kind: "alive" }); resetLimits();
458
+ limits.timeLimitMs = parseInt(a) * 60 * 1000;
459
+ } else if (/^\d+s$/.test(a)) {
460
+ transition({ kind: "alive" }); resetLimits();
461
+ limits.timeLimitMs = parseInt(a) * 1000;
462
+ } else if (/^\d+$/.test(a)) {
463
+ transition({ kind: "alive" }); resetLimits();
464
+ limits.maxCount = parseInt(a, 10);
465
+ } else {
466
+ ctx.ui.notify("/continuous [on|off|<n>|<n>m|<n>s]", "warning");
467
+ return;
468
+ }
469
+
470
+ dlog(`/continuous "${a}" → kind=${heart.kind}`);
471
+
472
+ if (heart.kind === "alive") {
473
+ const desc = limits.timeLimitMs > 0
474
+ ? (limits.timeLimitMs >= 60000 ? `${Math.round(limits.timeLimitMs / 60000)}分钟` : `${Math.round(limits.timeLimitMs / 1000)}秒`)
475
+ : limits.maxCount > 0 ? `最多 ${limits.maxCount} 次` : "∞";
476
+ ctx.ui.notify(`continuous ON — ${desc}`, "info");
477
+ if (limits.timeLimitMs > 0) {
478
+ limits.timeLimitTimer = setTimeout(() => {
479
+ try {
480
+ pi.sendMessage(
481
+ { messageType: "continuous-timeout", content: "Time limit reached. Call wait(seconds=30, wait_for_user=true) to wrap up.", isDisplayedInTUI: false },
482
+ { isTriggerNewTurn: true }
483
+ );
484
+ } catch {}
485
+ }, limits.timeLimitMs);
486
+ }
487
+ } else {
488
+ ctx.ui.notify("continuous OFF", "info");
489
+ }
490
+ },
491
+ });
492
+
493
+ return _cmds;
494
+ }
@@ -0,0 +1,43 @@
1
+ # heartbeat.ts 自唤醒 bug 复盘
2
+
3
+ ## 症状
4
+ - `next({hibernate})` 后 ~30 秒自动醒来
5
+ - 正常的 agent_end 后不自动续命
6
+
7
+ ## 根因
8
+
9
+ ### 1. 自唤醒
10
+ `convertToLlm`(messages.js)处理 `case "custom"` 时:
11
+ ```js
12
+ return { role: "user", content, timestamp }; // 丢了 messageType!
13
+ ```
14
+ 产出 `{role:"user", content:[...]}`,无 messageType,匹配 message_start 唤醒条件。
15
+
16
+ ### 2. 正常消息不续命
17
+ hibernate 设了 `lastHibernateTs`。用户叫醒后 `message_start` 重新点亮 continuous,但没清零 `lastHibernateTs`。下一轮 agent_end 被 5 秒背压窗口 (`lastHibernateTs > 0 && < 5000ms`) 拦死。
18
+
19
+ ## 修复
20
+
21
+ ### stop.ts
22
+ 1. **message_start 唤醒时**:`lastHibernateTs = 0`(防背压误杀)
23
+ 2. **dlog 时间**:`toISOString()` → `toLocaleString("zh-CN", {timeZone:"Asia/Shanghai"})`
24
+ 3. **日志格式**:`String(msg.content)` → `JSON.stringify(msg)`(抓完整消息结构)
25
+ 4. **hibernate handler**:删除 auto-sleep(`deliverAs:"followUp"` 可能 trigger new turn)
26
+
27
+ ### messages.js (dist patch → deploy/patch-pi-dist.js)
28
+ ```js
29
+ case "custom": {
30
+ return {
31
+ role: "user",
32
+ content,
33
+ timestamp: m.timestamp,
34
+ messageType: m.messageType, // ← 新增
35
+ };
36
+ }
37
+ ```
38
+
39
+ ## 教训
40
+ 1. jiti 缓存:改了 .ts 文件必须改 main.ts 注释强制重编译,否则永远加载旧版
41
+ 2. 背压窗口:状态标记不清零是 bug 温床
42
+ 3. dist patch 持久化:`npm update -g pi` 会覆盖;用 deploy/apply.js 管理
43
+ 4. 不要掩耳盗铃——过滤症状不如追源头
@@ -0,0 +1,8 @@
1
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
2
+ import { registerHeartbeat } from "./heartbeat.ts";
3
+ import { registerProcess } from "./process.ts";
4
+
5
+ export default function (pi: ExtensionAPI) {
6
+ registerHeartbeat(pi);
7
+ registerProcess(pi);
8
+ }
@@ -0,0 +1,19 @@
1
+ source: main.ts @ ebfe516f
2
+
3
+ # index.ts — Heart entry: wires stop + process
4
+
5
+ ## 职责
6
+ Entry point for the heart.main func. Creates default UnstopState and delegates to registerStop (continuous loop) and registerProcess (shell execution). Acts as the thin composition root for the heart organ.
7
+
8
+ ## 接口
9
+ - `default(pi: ExtensionAPI): void` — func entry called by kernel
10
+
11
+ ## 依赖
12
+ - `./stop.js` (registerStop, UnstopState)
13
+ - `./process.js` (registerProcess)
14
+ - `@mariozechner/pi-coding-agent` (ExtensionAPI)
15
+
16
+ ## 行为要点
17
+ - Initializes UnstopState with enabled=true, no count/time limits
18
+ - Each sub-module (stop, process) injects its own prompt via before_agent_start
19
+ - No prompt.ts — removed; prompt injection is per-module