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,646 @@
1
+ import { Marked, Tokenizer } from "marked";
2
+ import { getCapabilities, hyperlink, isImageLine } from "../terminal-image.js";
3
+ import { applyBackgroundToLine, visibleWidth, wrapTextWithAnsi } from "../utils.js";
4
+ const STRICT_STRIKETHROUGH_REGEX = /^(~~)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/;
5
+ class StrictStrikethroughTokenizer extends Tokenizer {
6
+ del(src) {
7
+ const match = STRICT_STRIKETHROUGH_REGEX.exec(src);
8
+ if (!match) {
9
+ return undefined;
10
+ }
11
+ const text = match[2];
12
+ return {
13
+ type: "del",
14
+ raw: match[0],
15
+ text,
16
+ tokens: this.lexer.inlineTokens(text),
17
+ };
18
+ }
19
+ }
20
+ const markdownParser = new Marked();
21
+ markdownParser.setOptions({
22
+ tokenizer: new StrictStrikethroughTokenizer(),
23
+ });
24
+ export class Markdown {
25
+ text;
26
+ paddingX; // Left/right padding
27
+ paddingY; // Top/bottom padding
28
+ defaultTextStyle;
29
+ theme;
30
+ options;
31
+ defaultStylePrefix;
32
+ // Cache for rendered output
33
+ cachedText;
34
+ cachedWidth;
35
+ cachedLines;
36
+ constructor(text, paddingX, paddingY, theme, defaultTextStyle, options) {
37
+ this.text = text;
38
+ this.paddingX = paddingX;
39
+ this.paddingY = paddingY;
40
+ this.theme = theme;
41
+ this.defaultTextStyle = defaultTextStyle;
42
+ this.options = options ? { ...options } : {};
43
+ }
44
+ setText(text) {
45
+ this.text = text;
46
+ this.invalidate();
47
+ }
48
+ invalidate() {
49
+ this.cachedText = undefined;
50
+ this.cachedWidth = undefined;
51
+ this.cachedLines = undefined;
52
+ }
53
+ render(width) {
54
+ // Check cache
55
+ if (this.cachedLines && this.cachedText === this.text && this.cachedWidth === width) {
56
+ return this.cachedLines;
57
+ }
58
+ // Calculate available width for content (subtract horizontal padding)
59
+ const contentWidth = Math.max(1, width - this.paddingX * 2);
60
+ // Don't render anything if there's no actual text
61
+ if (!this.text || this.text.trim() === "") {
62
+ const result = [];
63
+ // Update cache
64
+ this.cachedText = this.text;
65
+ this.cachedWidth = width;
66
+ this.cachedLines = result;
67
+ return result;
68
+ }
69
+ // Replace tabs with 3 spaces for consistent rendering
70
+ const normalizedText = this.text.replace(/\t/g, " ");
71
+ // Parse markdown to HTML-like tokens
72
+ const tokens = markdownParser.lexer(normalizedText);
73
+ // Convert tokens to styled terminal output
74
+ const renderedLines = [];
75
+ for (let i = 0; i < tokens.length; i++) {
76
+ const token = tokens[i];
77
+ const nextToken = tokens[i + 1];
78
+ const tokenLines = this.renderToken(token, contentWidth, nextToken?.type);
79
+ for (const tokenLine of tokenLines) {
80
+ renderedLines.push(tokenLine);
81
+ }
82
+ }
83
+ // Wrap lines (NO padding, NO background yet)
84
+ const wrappedLines = [];
85
+ for (const line of renderedLines) {
86
+ if (isImageLine(line)) {
87
+ wrappedLines.push(line);
88
+ }
89
+ else {
90
+ for (const wrappedLine of wrapTextWithAnsi(line, contentWidth)) {
91
+ wrappedLines.push(wrappedLine);
92
+ }
93
+ }
94
+ }
95
+ // Add margins and background to each wrapped line
96
+ const leftMargin = " ".repeat(this.paddingX);
97
+ const rightMargin = " ".repeat(this.paddingX);
98
+ const bgFn = this.defaultTextStyle?.bgColor;
99
+ const contentLines = [];
100
+ for (const line of wrappedLines) {
101
+ if (isImageLine(line)) {
102
+ contentLines.push(line);
103
+ continue;
104
+ }
105
+ const lineWithMargins = leftMargin + line + rightMargin;
106
+ if (bgFn) {
107
+ contentLines.push(applyBackgroundToLine(lineWithMargins, width, bgFn));
108
+ }
109
+ else {
110
+ // No background - just pad to width
111
+ const visibleLen = visibleWidth(lineWithMargins);
112
+ const paddingNeeded = Math.max(0, width - visibleLen);
113
+ contentLines.push(lineWithMargins + " ".repeat(paddingNeeded));
114
+ }
115
+ }
116
+ // Add top/bottom padding (empty lines)
117
+ const emptyLine = " ".repeat(width);
118
+ const emptyLines = [];
119
+ for (let i = 0; i < this.paddingY; i++) {
120
+ const line = bgFn ? applyBackgroundToLine(emptyLine, width, bgFn) : emptyLine;
121
+ emptyLines.push(line);
122
+ }
123
+ // Combine top padding, content, and bottom padding
124
+ const result = emptyLines.concat(contentLines, emptyLines);
125
+ // Update cache
126
+ this.cachedText = this.text;
127
+ this.cachedWidth = width;
128
+ this.cachedLines = result;
129
+ return result.length > 0 ? result : [""];
130
+ }
131
+ /**
132
+ * Apply default text style to a string.
133
+ * This is the base styling applied to all text content.
134
+ * NOTE: Background color is NOT applied here - it's applied at the padding stage
135
+ * to ensure it extends to the full line width.
136
+ */
137
+ applyDefaultStyle(text) {
138
+ if (!this.defaultTextStyle) {
139
+ return text;
140
+ }
141
+ let styled = text;
142
+ // Apply foreground color (NOT background - that's applied at padding stage)
143
+ if (this.defaultTextStyle.color) {
144
+ styled = this.defaultTextStyle.color(styled);
145
+ }
146
+ // Apply text decorations using this.theme
147
+ if (this.defaultTextStyle.bold) {
148
+ styled = this.theme.bold(styled);
149
+ }
150
+ if (this.defaultTextStyle.italic) {
151
+ styled = this.theme.italic(styled);
152
+ }
153
+ if (this.defaultTextStyle.strikethrough) {
154
+ styled = this.theme.strikethrough(styled);
155
+ }
156
+ if (this.defaultTextStyle.underline) {
157
+ styled = this.theme.underline(styled);
158
+ }
159
+ return styled;
160
+ }
161
+ getDefaultStylePrefix() {
162
+ if (!this.defaultTextStyle) {
163
+ return "";
164
+ }
165
+ if (this.defaultStylePrefix !== undefined) {
166
+ return this.defaultStylePrefix;
167
+ }
168
+ const sentinel = "\u0000";
169
+ let styled = sentinel;
170
+ if (this.defaultTextStyle.color) {
171
+ styled = this.defaultTextStyle.color(styled);
172
+ }
173
+ if (this.defaultTextStyle.bold) {
174
+ styled = this.theme.bold(styled);
175
+ }
176
+ if (this.defaultTextStyle.italic) {
177
+ styled = this.theme.italic(styled);
178
+ }
179
+ if (this.defaultTextStyle.strikethrough) {
180
+ styled = this.theme.strikethrough(styled);
181
+ }
182
+ if (this.defaultTextStyle.underline) {
183
+ styled = this.theme.underline(styled);
184
+ }
185
+ const sentinelIndex = styled.indexOf(sentinel);
186
+ this.defaultStylePrefix = sentinelIndex >= 0 ? styled.slice(0, sentinelIndex) : "";
187
+ return this.defaultStylePrefix;
188
+ }
189
+ getStylePrefix(styleFn) {
190
+ const sentinel = "\u0000";
191
+ const styled = styleFn(sentinel);
192
+ const sentinelIndex = styled.indexOf(sentinel);
193
+ return sentinelIndex >= 0 ? styled.slice(0, sentinelIndex) : "";
194
+ }
195
+ getDefaultInlineStyleContext() {
196
+ return {
197
+ applyText: (text) => this.applyDefaultStyle(text),
198
+ stylePrefix: this.getDefaultStylePrefix(),
199
+ };
200
+ }
201
+ renderToken(token, width, nextTokenType, styleContext) {
202
+ const lines = [];
203
+ switch (token.type) {
204
+ case "heading": {
205
+ const headingLevel = token.depth;
206
+ const headingPrefix = `${"#".repeat(headingLevel)} `;
207
+ // Build a heading-specific style context so inline tokens (codespan, bold, etc.)
208
+ // restore heading styling after their own ANSI resets instead of falling back to
209
+ // the default text style.
210
+ // pi-coding-master: 标题一律【粗体】,去掉 theme.heading 的黄色;h1 额外加下划线作层级区分。
211
+ let headingStyleFn;
212
+ if (headingLevel === 1) {
213
+ headingStyleFn = (text) => this.theme.bold(this.theme.underline(text));
214
+ }
215
+ else {
216
+ headingStyleFn = (text) => this.theme.bold(text);
217
+ }
218
+ const headingStyleContext = {
219
+ applyText: headingStyleFn,
220
+ stylePrefix: this.getStylePrefix(headingStyleFn),
221
+ };
222
+ const headingText = this.renderInlineTokens(token.tokens || [], headingStyleContext);
223
+ // pi-coding-master: 不再为 level>=3 打印字面 "### " 前缀(之前导致 ### 看着像没渲染)。
224
+ const styledHeading = headingText;
225
+ lines.push(styledHeading);
226
+ if (nextTokenType && nextTokenType !== "space") {
227
+ lines.push(""); // Add spacing after headings (unless space token follows)
228
+ }
229
+ break;
230
+ }
231
+ case "paragraph": {
232
+ const paragraphText = this.renderInlineTokens(token.tokens || [], styleContext);
233
+ lines.push(paragraphText);
234
+ // Don't add spacing if next token is space or list
235
+ if (nextTokenType && nextTokenType !== "list" && nextTokenType !== "space") {
236
+ lines.push("");
237
+ }
238
+ break;
239
+ }
240
+ case "text":
241
+ lines.push(this.renderInlineTokens([token], styleContext));
242
+ break;
243
+ case "code": {
244
+ const indent = this.theme.codeBlockIndent ?? " ";
245
+ lines.push(this.theme.codeBlockBorder(`\`\`\`${token.lang || ""}`));
246
+ if (this.theme.highlightCode) {
247
+ const highlightedLines = this.theme.highlightCode(token.text, token.lang);
248
+ for (const hlLine of highlightedLines) {
249
+ lines.push(`${indent}${hlLine}`);
250
+ }
251
+ }
252
+ else {
253
+ // Split code by newlines and style each line
254
+ const codeLines = token.text.split("\n");
255
+ for (const codeLine of codeLines) {
256
+ lines.push(`${indent}${this.theme.codeBlock(codeLine)}`);
257
+ }
258
+ }
259
+ lines.push(this.theme.codeBlockBorder("```"));
260
+ if (nextTokenType && nextTokenType !== "space") {
261
+ lines.push(""); // Add spacing after code blocks (unless space token follows)
262
+ }
263
+ break;
264
+ }
265
+ case "list": {
266
+ const listLines = this.renderList(token, 0, width, styleContext);
267
+ lines.push(...listLines);
268
+ // Don't add spacing after lists if a space token follows
269
+ // (the space token will handle it)
270
+ break;
271
+ }
272
+ case "table": {
273
+ const tableLines = this.renderTable(token, width, nextTokenType, styleContext);
274
+ lines.push(...tableLines);
275
+ break;
276
+ }
277
+ case "blockquote": {
278
+ const quoteStyle = (text) => this.theme.quote(this.theme.italic(text));
279
+ const quoteStylePrefix = this.getStylePrefix(quoteStyle);
280
+ const applyQuoteStyle = (line) => {
281
+ if (!quoteStylePrefix) {
282
+ return quoteStyle(line);
283
+ }
284
+ const lineWithReappliedStyle = line.replace(/\x1b\[0m/g, `\x1b[0m${quoteStylePrefix}`);
285
+ return quoteStyle(lineWithReappliedStyle);
286
+ };
287
+ // Calculate available width for quote content (subtract border "│ " = 2 chars)
288
+ const quoteContentWidth = Math.max(1, width - 2);
289
+ // Blockquotes contain block-level tokens (paragraph, list, code, etc.), so render
290
+ // children with renderToken() instead of renderInlineTokens().
291
+ // Default message style should not apply inside blockquotes.
292
+ const quoteInlineStyleContext = {
293
+ applyText: (text) => text,
294
+ stylePrefix: quoteStylePrefix,
295
+ };
296
+ const quoteTokens = token.tokens || [];
297
+ const renderedQuoteLines = [];
298
+ for (let i = 0; i < quoteTokens.length; i++) {
299
+ const quoteToken = quoteTokens[i];
300
+ const nextQuoteToken = quoteTokens[i + 1];
301
+ renderedQuoteLines.push(...this.renderToken(quoteToken, quoteContentWidth, nextQuoteToken?.type, quoteInlineStyleContext));
302
+ }
303
+ // Avoid rendering an extra empty quote line before the outer blockquote spacing.
304
+ while (renderedQuoteLines.length > 0 && renderedQuoteLines[renderedQuoteLines.length - 1] === "") {
305
+ renderedQuoteLines.pop();
306
+ }
307
+ for (const quoteLine of renderedQuoteLines) {
308
+ const styledLine = applyQuoteStyle(quoteLine);
309
+ const wrappedLines = wrapTextWithAnsi(styledLine, quoteContentWidth);
310
+ for (const wrappedLine of wrappedLines) {
311
+ lines.push(this.theme.quoteBorder("│ ") + wrappedLine);
312
+ }
313
+ }
314
+ if (nextTokenType && nextTokenType !== "space") {
315
+ lines.push(""); // Add spacing after blockquotes (unless space token follows)
316
+ }
317
+ break;
318
+ }
319
+ case "hr":
320
+ lines.push(this.theme.hr("─".repeat(Math.min(width, 80))));
321
+ if (nextTokenType && nextTokenType !== "space") {
322
+ lines.push(""); // Add spacing after horizontal rules (unless space token follows)
323
+ }
324
+ break;
325
+ case "html":
326
+ // Render HTML as plain text (escaped for terminal)
327
+ if ("raw" in token && typeof token.raw === "string") {
328
+ lines.push(this.applyDefaultStyle(token.raw.trim()));
329
+ }
330
+ break;
331
+ case "space":
332
+ // Space tokens represent blank lines in markdown
333
+ lines.push("");
334
+ break;
335
+ default:
336
+ // Handle any other token types as plain text
337
+ if ("text" in token && typeof token.text === "string") {
338
+ lines.push(token.text);
339
+ }
340
+ }
341
+ return lines;
342
+ }
343
+ renderInlineTokens(tokens, styleContext) {
344
+ let result = "";
345
+ const resolvedStyleContext = styleContext ?? this.getDefaultInlineStyleContext();
346
+ const { applyText, stylePrefix } = resolvedStyleContext;
347
+ const applyTextWithNewlines = (text) => {
348
+ const segments = text.split("\n");
349
+ return segments.map((segment) => applyText(segment)).join("\n");
350
+ };
351
+ for (const token of tokens) {
352
+ switch (token.type) {
353
+ case "text":
354
+ // Text tokens in list items can have nested tokens for inline formatting
355
+ if (token.tokens && token.tokens.length > 0) {
356
+ result += this.renderInlineTokens(token.tokens, resolvedStyleContext);
357
+ }
358
+ else {
359
+ result += applyTextWithNewlines(token.text);
360
+ }
361
+ break;
362
+ case "paragraph":
363
+ // Paragraph tokens contain nested inline tokens
364
+ result += this.renderInlineTokens(token.tokens || [], resolvedStyleContext);
365
+ break;
366
+ case "strong": {
367
+ const boldContent = this.renderInlineTokens(token.tokens || [], resolvedStyleContext);
368
+ result += this.theme.bold(boldContent) + stylePrefix;
369
+ break;
370
+ }
371
+ case "em": {
372
+ const italicContent = this.renderInlineTokens(token.tokens || [], resolvedStyleContext);
373
+ result += this.theme.italic(italicContent) + stylePrefix;
374
+ break;
375
+ }
376
+ case "codespan":
377
+ result += this.theme.code(token.text) + stylePrefix;
378
+ break;
379
+ case "link": {
380
+ const linkText = this.renderInlineTokens(token.tokens || [], resolvedStyleContext);
381
+ const styledLink = this.theme.link(this.theme.underline(linkText));
382
+ if (getCapabilities().hyperlinks) {
383
+ // OSC 8: render as a clickable hyperlink. The URL is not printed inline,
384
+ // so we always show only the link text regardless of whether it matches href.
385
+ result += hyperlink(styledLink, token.href) + stylePrefix;
386
+ }
387
+ else {
388
+ // Fallback: print URL in parentheses when text differs from href.
389
+ // Compare raw token.text (not styled) against href for the equality check.
390
+ // For mailto: links strip the prefix (autolinked emails use text="foo@bar.com"
391
+ // but href="mailto:foo@bar.com").
392
+ const hrefForComparison = token.href.startsWith("mailto:") ? token.href.slice(7) : token.href;
393
+ if (token.text === token.href || token.text === hrefForComparison) {
394
+ result += styledLink + stylePrefix;
395
+ }
396
+ else {
397
+ result += styledLink + this.theme.linkUrl(` (${token.href})`) + stylePrefix;
398
+ }
399
+ }
400
+ break;
401
+ }
402
+ case "br":
403
+ result += "\n";
404
+ break;
405
+ case "del": {
406
+ const delContent = this.renderInlineTokens(token.tokens || [], resolvedStyleContext);
407
+ result += this.theme.strikethrough(delContent) + stylePrefix;
408
+ break;
409
+ }
410
+ case "html":
411
+ // Render inline HTML as plain text
412
+ if ("raw" in token && typeof token.raw === "string") {
413
+ result += applyTextWithNewlines(token.raw);
414
+ }
415
+ break;
416
+ default:
417
+ // Handle any other inline token types as plain text
418
+ if ("text" in token && typeof token.text === "string") {
419
+ result += applyTextWithNewlines(token.text);
420
+ }
421
+ }
422
+ }
423
+ while (stylePrefix && result.endsWith(stylePrefix)) {
424
+ result = result.slice(0, -stylePrefix.length);
425
+ }
426
+ return result;
427
+ }
428
+ getOrderedListMarker(item) {
429
+ const match = /^(?: {0,3})(\d{1,9}[.)])[ \t]+/.exec(item.raw);
430
+ return match ? `${match[1]} ` : undefined;
431
+ }
432
+ /**
433
+ * Render a list with proper nesting support
434
+ */
435
+ renderList(token, depth, width, styleContext) {
436
+ const lines = [];
437
+ const indent = " ".repeat(depth);
438
+ // Use the list's start property (defaults to 1 for ordered lists)
439
+ const startNumber = typeof token.start === "number" ? token.start : 1;
440
+ for (let i = 0; i < token.items.length; i++) {
441
+ const item = token.items[i];
442
+ const bullet = token.ordered
443
+ ? this.options.preserveOrderedListMarkers
444
+ ? (this.getOrderedListMarker(item) ?? `${startNumber + i}. `)
445
+ : `${startNumber + i}. `
446
+ : "- ";
447
+ const taskMarker = item.task ? `[${item.checked ? "x" : " "}] ` : "";
448
+ const marker = bullet + taskMarker;
449
+ const firstPrefix = indent + this.theme.listBullet(marker);
450
+ const continuationPrefix = indent + " ".repeat(visibleWidth(marker));
451
+ const itemWidth = Math.max(1, width - visibleWidth(firstPrefix));
452
+ let renderedAnyLine = false;
453
+ for (const itemToken of item.tokens) {
454
+ if (itemToken.type === "list") {
455
+ lines.push(...this.renderList(itemToken, depth + 1, width, styleContext));
456
+ renderedAnyLine = true;
457
+ continue;
458
+ }
459
+ const itemLines = this.renderToken(itemToken, itemWidth, undefined, styleContext);
460
+ for (const line of itemLines) {
461
+ for (const wrappedLine of wrapTextWithAnsi(line, itemWidth)) {
462
+ const linePrefix = renderedAnyLine ? continuationPrefix : firstPrefix;
463
+ lines.push(linePrefix + wrappedLine);
464
+ renderedAnyLine = true;
465
+ }
466
+ }
467
+ }
468
+ if (!renderedAnyLine) {
469
+ lines.push(firstPrefix);
470
+ }
471
+ }
472
+ return lines;
473
+ }
474
+ /**
475
+ * Get the visible width of the longest word in a string.
476
+ */
477
+ getLongestWordWidth(text, maxWidth) {
478
+ const words = text.split(/\s+/).filter((word) => word.length > 0);
479
+ let longest = 0;
480
+ for (const word of words) {
481
+ longest = Math.max(longest, visibleWidth(word));
482
+ }
483
+ if (maxWidth === undefined) {
484
+ return longest;
485
+ }
486
+ return Math.min(longest, maxWidth);
487
+ }
488
+ /**
489
+ * Wrap a table cell to fit into a column.
490
+ *
491
+ * Delegates to wrapTextWithAnsi() so ANSI codes + long tokens are handled
492
+ * consistently with the rest of the renderer.
493
+ */
494
+ wrapCellText(text, maxWidth) {
495
+ return wrapTextWithAnsi(text, Math.max(1, maxWidth));
496
+ }
497
+ /**
498
+ * Render a table with width-aware cell wrapping.
499
+ * Cells that don't fit are wrapped to multiple lines.
500
+ */
501
+ renderTable(token, availableWidth, nextTokenType, styleContext) {
502
+ const lines = [];
503
+ const numCols = token.header.length;
504
+ if (numCols === 0) {
505
+ return lines;
506
+ }
507
+ // Calculate border overhead: "│ " + (n-1) * " │ " + " │"
508
+ // = 2 + (n-1) * 3 + 2 = 3n + 1
509
+ const borderOverhead = 3 * numCols + 1;
510
+ const availableForCells = availableWidth - borderOverhead;
511
+ if (availableForCells < numCols) {
512
+ // Too narrow to render a stable table. Fall back to raw markdown.
513
+ const fallbackLines = token.raw ? wrapTextWithAnsi(token.raw, availableWidth) : [];
514
+ if (nextTokenType && nextTokenType !== "space") {
515
+ fallbackLines.push("");
516
+ }
517
+ return fallbackLines;
518
+ }
519
+ const maxUnbrokenWordWidth = 30;
520
+ // Calculate natural column widths (what each column needs without constraints)
521
+ const naturalWidths = [];
522
+ const minWordWidths = [];
523
+ for (let i = 0; i < numCols; i++) {
524
+ const headerText = this.renderInlineTokens(token.header[i].tokens || [], styleContext);
525
+ naturalWidths[i] = visibleWidth(headerText);
526
+ minWordWidths[i] = Math.max(1, this.getLongestWordWidth(headerText, maxUnbrokenWordWidth));
527
+ }
528
+ for (const row of token.rows) {
529
+ for (let i = 0; i < row.length; i++) {
530
+ const cellText = this.renderInlineTokens(row[i].tokens || [], styleContext);
531
+ naturalWidths[i] = Math.max(naturalWidths[i] || 0, visibleWidth(cellText));
532
+ minWordWidths[i] = Math.max(minWordWidths[i] || 1, this.getLongestWordWidth(cellText, maxUnbrokenWordWidth));
533
+ }
534
+ }
535
+ let minColumnWidths = minWordWidths;
536
+ let minCellsWidth = minColumnWidths.reduce((a, b) => a + b, 0);
537
+ if (minCellsWidth > availableForCells) {
538
+ minColumnWidths = new Array(numCols).fill(1);
539
+ const remaining = availableForCells - numCols;
540
+ if (remaining > 0) {
541
+ const totalWeight = minWordWidths.reduce((total, width) => total + Math.max(0, width - 1), 0);
542
+ const growth = minWordWidths.map((width) => {
543
+ const weight = Math.max(0, width - 1);
544
+ return totalWeight > 0 ? Math.floor((weight / totalWeight) * remaining) : 0;
545
+ });
546
+ for (let i = 0; i < numCols; i++) {
547
+ minColumnWidths[i] += growth[i] ?? 0;
548
+ }
549
+ const allocated = growth.reduce((total, width) => total + width, 0);
550
+ let leftover = remaining - allocated;
551
+ for (let i = 0; leftover > 0 && i < numCols; i++) {
552
+ minColumnWidths[i]++;
553
+ leftover--;
554
+ }
555
+ }
556
+ minCellsWidth = minColumnWidths.reduce((a, b) => a + b, 0);
557
+ }
558
+ // Calculate column widths that fit within available width
559
+ const totalNaturalWidth = naturalWidths.reduce((a, b) => a + b, 0) + borderOverhead;
560
+ let columnWidths;
561
+ if (totalNaturalWidth <= availableWidth) {
562
+ // Everything fits naturally
563
+ columnWidths = naturalWidths.map((width, index) => Math.max(width, minColumnWidths[index]));
564
+ }
565
+ else {
566
+ // Need to shrink columns to fit
567
+ const totalGrowPotential = naturalWidths.reduce((total, width, index) => {
568
+ return total + Math.max(0, width - minColumnWidths[index]);
569
+ }, 0);
570
+ const extraWidth = Math.max(0, availableForCells - minCellsWidth);
571
+ columnWidths = minColumnWidths.map((minWidth, index) => {
572
+ const naturalWidth = naturalWidths[index];
573
+ const minWidthDelta = Math.max(0, naturalWidth - minWidth);
574
+ let grow = 0;
575
+ if (totalGrowPotential > 0) {
576
+ grow = Math.floor((minWidthDelta / totalGrowPotential) * extraWidth);
577
+ }
578
+ return minWidth + grow;
579
+ });
580
+ // Adjust for rounding errors - distribute remaining space
581
+ const allocated = columnWidths.reduce((a, b) => a + b, 0);
582
+ let remaining = availableForCells - allocated;
583
+ while (remaining > 0) {
584
+ let grew = false;
585
+ for (let i = 0; i < numCols && remaining > 0; i++) {
586
+ if (columnWidths[i] < naturalWidths[i]) {
587
+ columnWidths[i]++;
588
+ remaining--;
589
+ grew = true;
590
+ }
591
+ }
592
+ if (!grew) {
593
+ break;
594
+ }
595
+ }
596
+ }
597
+ // Render top border
598
+ const topBorderCells = columnWidths.map((w) => "─".repeat(w));
599
+ lines.push(`┌─${topBorderCells.join("─┬─")}─┐`);
600
+ // Render header with wrapping
601
+ const headerCellLines = token.header.map((cell, i) => {
602
+ const text = this.renderInlineTokens(cell.tokens || [], styleContext);
603
+ return this.wrapCellText(text, columnWidths[i]);
604
+ });
605
+ const headerLineCount = Math.max(...headerCellLines.map((c) => c.length));
606
+ for (let lineIdx = 0; lineIdx < headerLineCount; lineIdx++) {
607
+ const rowParts = headerCellLines.map((cellLines, colIdx) => {
608
+ const text = cellLines[lineIdx] || "";
609
+ const padded = text + " ".repeat(Math.max(0, columnWidths[colIdx] - visibleWidth(text)));
610
+ return this.theme.bold(padded);
611
+ });
612
+ lines.push(`│ ${rowParts.join(" │ ")} │`);
613
+ }
614
+ // Render separator
615
+ const separatorCells = columnWidths.map((w) => "─".repeat(w));
616
+ const separatorLine = `├─${separatorCells.join("─┼─")}─┤`;
617
+ lines.push(separatorLine);
618
+ // Render rows with wrapping
619
+ for (let rowIndex = 0; rowIndex < token.rows.length; rowIndex++) {
620
+ const row = token.rows[rowIndex];
621
+ const rowCellLines = row.map((cell, i) => {
622
+ const text = this.renderInlineTokens(cell.tokens || [], styleContext);
623
+ return this.wrapCellText(text, columnWidths[i]);
624
+ });
625
+ const rowLineCount = Math.max(...rowCellLines.map((c) => c.length));
626
+ for (let lineIdx = 0; lineIdx < rowLineCount; lineIdx++) {
627
+ const rowParts = rowCellLines.map((cellLines, colIdx) => {
628
+ const text = cellLines[lineIdx] || "";
629
+ return text + " ".repeat(Math.max(0, columnWidths[colIdx] - visibleWidth(text)));
630
+ });
631
+ lines.push(`│ ${rowParts.join(" │ ")} │`);
632
+ }
633
+ if (rowIndex < token.rows.length - 1) {
634
+ lines.push(separatorLine);
635
+ }
636
+ }
637
+ // Render bottom border
638
+ const bottomBorderCells = columnWidths.map((w) => "─".repeat(w));
639
+ lines.push(`└─${bottomBorderCells.join("─┴─")}─┘`);
640
+ if (nextTokenType && nextTokenType !== "space") {
641
+ lines.push(""); // Add spacing after table
642
+ }
643
+ return lines;
644
+ }
645
+ }
646
+ //# sourceMappingURL=markdown.js.map