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.
- package/README.md +50 -0
- package/core/god.agent.capability/@ABANDONED.brain.prefrontal.monitor/gpu_monitor.py +80 -0
- package/core/god.agent.capability/@ABANDONED.brain.prefrontal.monitor/gpu_monitor.py.CHANGELOG +1 -0
- package/core/god.agent.capability/@ABANDONED.brain.prefrontal.monitor/gpu_monitor.py.SPEC +3 -0
- package/core/god.agent.capability/hands.dev.writeissue/issue.ts +209 -0
- package/core/god.agent.capability/hands.dev.writeissue/issue.ts.SPEC +26 -0
- package/core/god.agent.capability/hands.files.changewatcher/watcher.ts +44 -0
- package/core/god.agent.capability/hands.files.changewatcher/watcher.ts.SPEC +25 -0
- package/core/god.pi.mod/cli/pi-completion.zsh +21 -0
- package/core/god.pi.mod/cli/pi-completion.zsh.CHANGELOG +1 -0
- package/core/god.pi.mod/cli/pi-people.sh +264 -0
- package/core/god.pi.mod/cli/pi-people.sh.LESSON +10 -0
- package/core/god.pi.mod/cli/pi-people.sh.SPEC +31 -0
- package/core/god.pi.mod/paths.ts +47 -0
- package/core/god.pi.mod/tui.mods.blockrender/blockrender.js +90 -0
- package/core/god.pi.mod/tui.mods.blockrender/blockrender.js.SPEC +29 -0
- package/core/god.pi.mod/tui.mods.footer.budget/budget_guard.ts +154 -0
- package/core/god.pi.mod/tui.mods.footer.budget/budget_guard.ts.CHANGELOG +10 -0
- package/core/god.pi.mod/tui.mods.footer.budget/budget_guard.ts.LESSON +12 -0
- package/core/god.pi.mod/tui.mods.footer.budget/budget_guard.ts.SPEC +26 -0
- package/core/god.pi.mod/tui.mods.footer.budget/footer-cny.CHANGELOG +39 -0
- package/core/god.pi.mod/tui.mods.viewmode/view_mode-thinking.patch +55 -0
- package/core/god.pi.mod/tui.mods.viewmode/view_mode-tools.patch +19 -0
- package/core/god.pi.mod/tui.mods.viewmode/view_mode-tools.patch.CHANGELOG +1 -0
- package/core/god.pi.mod/tui.mods.viewmode/view_mode.ts +50 -0
- package/core/god.pi.mod/tui.mods.viewmode/view_mode.ts.SPEC +12 -0
- package/core/god.pi.mod/tui.variants.userterminal/user_terminal.CHANGELOG +10 -0
- package/core/god.pi.mod/tui.variants.userterminal/user_terminal.ts +66 -0
- package/core/god.pi.mod/tui.variants.userterminal/user_terminal.ts.SPEC +31 -0
- package/core/index.ts +3 -0
- package/core/individual.bio.gene/dna.coded/coded.dna +257 -0
- package/core/individual.bio.gene/dna.coded/coded.dna.CHANGELOG +12 -0
- package/core/individual.bio.gene/dna.coded/coded.dna.SPEC +11 -0
- package/core/individual.bio.gene/dna.coded/core.dna +110 -0
- package/core/individual.bio.gene/dna.promotor/promotor.dna +117 -0
- package/core/individual.bio.gene/dna.promotor/promotor.dna.CHANGELOG +4 -0
- package/core/individual.bio.gene/dna.promotor/promotor.dna.SPEC +7 -0
- package/core/individual.bio.gene/dna.transpiler/transpiler.ts +395 -0
- package/core/individual.bio.gene/dna.transpiler/transpiler.ts.CHANGELOG +7 -0
- package/core/individual.bio.gene/dna.transpiler/transpiler.ts.SPEC +28 -0
- package/core/individual.bio.gene/gene.README +19 -0
- package/core/individual.bio.gene/rna/rna.json +536 -0
- package/core/individual.bio.gene/rna/rna.json.CHANGELOG +2 -0
- package/core/individual.bio.gene/rna/rna.json.SPEC +8 -0
- package/core/individual.bio.organs/blood.runtime/messages.ts +236 -0
- package/core/individual.bio.organs/blood.runtime/runtime.ts +173 -0
- package/core/individual.bio.organs/blood.runtime/runtime.ts.CHANGELOG +5 -0
- package/core/individual.bio.organs/blood.runtime/runtime.ts.SPEC +32 -0
- package/core/individual.bio.organs/brain.amygdala/amygdala.ts +25 -0
- package/core/individual.bio.organs/brain.amygdala/amygdala.ts.COMMENT +3 -0
- package/core/individual.bio.organs/brain.amygdala/amygdala.ts.SPEC +9 -0
- package/core/individual.bio.organs/brain.hippocampus/hippocampus-launcher.sh.template +108 -0
- package/core/individual.bio.organs/brain.hippocampus/hippocampus.ts +166 -0
- package/core/individual.bio.organs/brain.hippocampus/hippocampus.ts.CHANGELOG +12 -0
- package/core/individual.bio.organs/brain.hippocampus/hippocampus.ts.LESSON +22 -0
- package/core/individual.bio.organs/brain.hippocampus/hippocampus.ts.SPEC +16 -0
- package/core/individual.bio.organs/brain.hippocampus/memory.ts +879 -0
- package/core/individual.bio.organs/brain.hippocampus/memory.ts.CHANGELOG +66 -0
- package/core/individual.bio.organs/brain.hippocampus/memory.ts.LESSON +25 -0
- package/core/individual.bio.organs/brain.hippocampus/memory.ts.SPEC +46 -0
- package/core/individual.bio.organs/brain.hippocampus/sleep.ts +139 -0
- package/core/individual.bio.organs/brain.hippocampus/sleep.ts.CHANGELOG +11 -0
- package/core/individual.bio.organs/brain.hippocampus/sleep.ts.SPEC +16 -0
- package/core/individual.bio.organs/brain.prefrontal.drafting/drafting.SPEC +44 -0
- package/core/individual.bio.organs/brain.prefrontal.drafting/drafting.ts +73 -0
- package/core/individual.bio.organs/brain.prefrontal.drafting/drafting.ts.CHANGELOG +3 -0
- package/core/individual.bio.organs/brain.prefrontal.drafting/drafting.ts.SPEC +24 -0
- package/core/individual.bio.organs/brain.prefrontal.drafting/index.ts.CHANGELOG +3 -0
- package/core/individual.bio.organs/brain.prefrontal.drafting/main.ts +13 -0
- package/core/individual.bio.organs/brain.prefrontal.drafting/main.ts.SPEC +17 -0
- package/core/individual.bio.organs/brain.senses.bioclock/bioclock.ts +94 -0
- package/core/individual.bio.organs/brain.senses.bioclock/bioclock.ts.LESSON +13 -0
- package/core/individual.bio.organs/brain.senses.bioclock/bioclock.ts.SPEC +20 -0
- package/core/individual.bio.organs/brain.senses.subconscious/feed-format.SPEC +56 -0
- package/core/individual.bio.organs/brain.senses.subconscious/index.ts.CHANGELOG +13 -0
- package/core/individual.bio.organs/brain.senses.subconscious/spawner.ts +130 -0
- package/core/individual.bio.organs/brain.senses.subconscious/spawner.ts.SPEC +13 -0
- package/core/individual.bio.organs/brain.senses.subconscious/subconscious.ts +280 -0
- package/core/individual.bio.organs/brain.senses.subconscious/subconscious.ts.CHANGELOG +7 -0
- package/core/individual.bio.organs/brain.senses.subconscious/tools.ts +180 -0
- package/core/individual.bio.organs/brain.senses.subconscious/tools.ts.SPEC +3 -0
- package/core/individual.bio.organs/ears.listen/config.json +9 -0
- package/core/individual.bio.organs/ears.listen/config.json.CHANGELOG +1 -0
- package/core/individual.bio.organs/ears.listen/config.json.SPEC +3 -0
- package/core/individual.bio.organs/ears.listen/ears.ts.CHANGELOG +48 -0
- package/core/individual.bio.organs/ears.listen/ears_recorder.py.CHANGELOG +6 -0
- package/core/individual.bio.organs/ears.listen/index.ts +1 -0
- package/core/individual.bio.organs/ears.listen/index.ts.SPEC +16 -0
- package/core/individual.bio.organs/ears.listen/listen.ts +208 -0
- package/core/individual.bio.organs/ears.listen/listen.ts.SPEC +3 -0
- package/core/individual.bio.organs/ears.listen/listen_recorder.py +445 -0
- package/core/individual.bio.organs/ears.listen/listen_recorder.py.SPEC +7 -0
- package/core/individual.bio.organs/ears.listen/python_protogen/__init__.py +0 -0
- package/core/individual.bio.organs/ears.listen/python_protogen/common/__init__.py +0 -0
- package/core/individual.bio.organs/ears.listen/python_protogen/common/events_pb2.py +38 -0
- package/core/individual.bio.organs/ears.listen/python_protogen/common/events_pb2_grpc.py +24 -0
- package/core/individual.bio.organs/ears.listen/python_protogen/common/rpcmeta_pb2.py +42 -0
- package/core/individual.bio.organs/ears.listen/python_protogen/common/rpcmeta_pb2_grpc.py +24 -0
- package/core/individual.bio.organs/ears.listen/python_protogen/products/__init__.py +0 -0
- package/core/individual.bio.organs/ears.listen/python_protogen/products/understanding/__init__.py +0 -0
- package/core/individual.bio.organs/ears.listen/python_protogen/products/understanding/ast/__init__.py +0 -0
- package/core/individual.bio.organs/ears.listen/python_protogen/products/understanding/ast/ast_service_pb2.py +45 -0
- package/core/individual.bio.organs/ears.listen/python_protogen/products/understanding/ast/ast_service_pb2_grpc.py +97 -0
- package/core/individual.bio.organs/ears.listen/python_protogen/products/understanding/base/__init__.py +0 -0
- package/core/individual.bio.organs/ears.listen/python_protogen/products/understanding/base/au_base_pb2.py +80 -0
- package/core/individual.bio.organs/ears.listen/python_protogen/products/understanding/base/au_base_pb2_grpc.py +24 -0
- package/core/individual.bio.organs/hands.fileactions/authorize.TRUST +1 -0
- package/core/individual.bio.organs/hands.fileactions/authorize.ts +70 -0
- package/core/individual.bio.organs/hands.fileactions/authorize.ts.CHANGELOG +1 -0
- package/core/individual.bio.organs/hands.fileactions/authorize.ts.SPEC +3 -0
- package/core/individual.bio.organs/hands.fileactions/dir.README +13 -0
- package/core/individual.bio.organs/hands.fileactions/file_rules.json +23 -0
- package/core/individual.bio.organs/hands.fileactions/fileactions.README +12 -0
- package/core/individual.bio.organs/hands.fileactions/fileactions.ts +540 -0
- package/core/individual.bio.organs/hands.fileactions/fileactions.ts.CHANGELOG +25 -0
- package/core/individual.bio.organs/hands.fileactions/fileactions.ts.SPEC +30 -0
- package/core/individual.bio.organs/hands.fileactions/filewatch.ts +66 -0
- package/core/individual.bio.organs/hands.fileactions/filewatch.ts.SPEC +3 -0
- package/core/individual.bio.organs/hands.main/main.ts +18 -0
- package/core/individual.bio.organs/hands.main/main.ts.SPEC +20 -0
- package/core/individual.bio.organs/hands.sensitive/sensitive.ts +24 -0
- package/core/individual.bio.organs/hands.sensitive/sensitive.ts.CHANGELOG +2 -0
- package/core/individual.bio.organs/hands.sensitive/sensitive.ts.SPEC +3 -0
- package/core/individual.bio.organs/heart.interrupt/agent_start-loader-flicker.patch +13 -0
- package/core/individual.bio.organs/heart.interrupt/interactive-mode-loader.patch +11 -0
- package/core/individual.bio.organs/heart.interrupt/runner_esc.patch +10 -0
- package/core/individual.bio.organs/heart.interrupt/runner_esc.patch.SPEC +9 -0
- package/core/individual.bio.organs/heart.kernel/kernel.ts +253 -0
- package/core/individual.bio.organs/heart.kernel/kernel.ts.CHANGELOG +13 -0
- package/core/individual.bio.organs/heart.kernel/kernel.ts.SPEC +23 -0
- package/core/individual.bio.organs/heart.main/heart.main.CHANGELOG +43 -0
- package/core/individual.bio.organs/heart.main/heartbeat.ts +494 -0
- package/core/individual.bio.organs/heart.main/heartbeat.ts.LESSON +43 -0
- package/core/individual.bio.organs/heart.main/main.ts +8 -0
- package/core/individual.bio.organs/heart.main/main.ts.SPEC +19 -0
- package/core/individual.bio.organs/heart.main/process.ts +122 -0
- package/core/individual.bio.organs/heart.main/process.ts.CHANGELOG +2 -0
- package/core/individual.bio.organs/heart.main/process.ts.SPEC +24 -0
- package/core/individual.bio.organs/heart.main/remove_timeout.patch +110 -0
- package/core/individual.bio.organs/heart.main/stop.ts.CHANGELOG +3 -0
- package/core/individual.bio.organs/heart.main/stop.ts.SPEC +28 -0
- package/core/individual.bio.organs/mouth.speak/index.ts +1 -0
- package/core/individual.bio.organs/mouth.speak/index.ts.CHANGELOG +1 -0
- package/core/individual.bio.organs/mouth.speak/index.ts.SPEC +6 -0
- package/core/individual.bio.organs/mouth.speak/mouth.ts.CHANGELOG +15 -0
- package/core/individual.bio.organs/mouth.speak/mouth_recorder.py.CHANGELOG +1 -0
- package/core/individual.bio.organs/mouth.speak/speak.ts +180 -0
- package/core/individual.bio.organs/mouth.speak/speak.ts.SPEC +3 -0
- package/core/individual.bio.organs/mouth.speak/speak_recorder.py +35 -0
- package/core/individual.bio.organs/mouth.speak/speak_recorder.py.SPEC +3 -0
- package/core/individual.bio.organs/organs.README +110 -0
- package/core/package-lock.json +18 -0
- package/core/package.json +35 -0
- package/core/prompts/prompts.json +77 -0
- package/core/prompts/prompts.ts +44 -0
- package/core/prompts/prompts.ts.SPEC +9 -0
- package/core/society.world/.gitkeep +0 -0
- package/core/society.world/accessibility.claudecode/message-service.cjs +217 -0
- package/core/society.world/accessibility.claudecode/message-service.cjs.SPEC +7 -0
- package/core/society.world/accessibility.claudecode/send.ts +34 -0
- package/core/society.world/dollar.distribution.ubi/ubi.ts +55 -0
- package/core/society.world/dollar.main/dollar-service.cjs +185 -0
- package/core/society.world/dollar.main/main.ts +116 -0
- package/core/society.world/dollar.transaction/transaction.ts +71 -0
- package/core/society.world/space/space.ts +206 -0
- package/core/society.world/space/space.ts.SPEC +30 -0
- package/core/technology.laptop/#agent.macos.BLUEPRINT +278 -0
- package/core/technology.phone/apps.preinstalled/albums.FUTURE/albums.ts +69 -0
- package/core/technology.phone/apps.preinstalled/albums.FUTURE/albums.ts.SPEC +15 -0
- package/core/technology.phone/apps.preinstalled/calendar/calendar.ts +406 -0
- package/core/technology.phone/apps.preinstalled/calendar/calendar.ts.SPEC +22 -0
- package/core/technology.phone/apps.preinstalled/calendar/holiday-calendar.ts +529 -0
- package/core/technology.phone/apps.preinstalled/clock/clock.ts +132 -0
- package/core/technology.phone/apps.preinstalled/clock/clock.ts.SPEC +11 -0
- package/core/technology.phone/apps.preinstalled/contacts.FUTURE/contacts.ts +300 -0
- package/core/technology.phone/apps.preinstalled/contacts.FUTURE/contacts.ts.SPEC +22 -0
- package/core/technology.phone/apps.preinstalled/developer.FUTURE/developer.ts +22 -0
- package/core/technology.phone/apps.preinstalled/developer.FUTURE/developer.ts.SPEC +15 -0
- package/core/technology.phone/apps.preinstalled/notes/notes.ts +239 -0
- package/core/technology.phone/apps.preinstalled/notes/notes.ts.SPEC +21 -0
- package/core/technology.phone/apps.preinstalled/polymarket/polymarket.ts +261 -0
- package/core/technology.phone/apps.preinstalled/polymarket/polymarket.ts.SPEC +7 -0
- package/core/technology.phone/apps.preinstalled/reminder/reminder.ts +404 -0
- package/core/technology.phone/apps.preinstalled/reminder/reminder.ts.SPEC +25 -0
- package/core/technology.phone/apps.preinstalled/siri.FUTURE/siri.ts +22 -0
- package/core/technology.phone/apps.preinstalled/siri.FUTURE/siri.ts.SPEC +15 -0
- package/core/technology.phone/apps.preinstalled/spotlight/spotlight.ts +29 -0
- package/core/technology.phone/apps.preinstalled/spotlight/spotlight.ts.SPEC +7 -0
- package/core/technology.phone/apps.preinstalled/steam/chess.ts +230 -0
- package/core/technology.phone/apps.preinstalled/steam/snake.ts +100 -0
- package/core/technology.phone/apps.preinstalled/steam/snake.ts.SPEC +7 -0
- package/core/technology.phone/apps.preinstalled/steam/spy-cmd.ts +4 -0
- package/core/technology.phone/apps.preinstalled/steam/spy-tool.ts +56 -0
- package/core/technology.phone/apps.preinstalled/steam/spy.ts +302 -0
- package/core/technology.phone/apps.preinstalled/steam/steam.ts +299 -0
- package/core/technology.phone/apps.preinstalled/weather/weather.ts +50 -0
- package/core/technology.phone/apps.preinstalled/weather/weather.ts.SPEC +9 -0
- package/core/technology.phone/apps.preinstalled/wechat/imessage.ts +423 -0
- package/core/technology.phone/apps.preinstalled/wechat/imessage.ts.SPEC +24 -0
- package/core/technology.phone/apps.system/appstore/appstore.ts +22 -0
- package/core/technology.phone/apps.system/appstore/appstore.ts.SPEC +15 -0
- package/core/technology.phone/apps.system/finder.FUTURE/finder.ts +64 -0
- package/core/technology.phone/apps.system/finder.FUTURE/finder.ts.SPEC +8 -0
- package/core/technology.phone/apps.system/safari/safari-app.ts +146 -0
- package/core/technology.phone/apps.system/safari/safari.ts.SPEC +24 -0
- package/core/technology.phone/apps.system/settings/settings.ts +126 -0
- package/core/technology.phone/apps.system/settings/settings.ts.SPEC +17 -0
- package/core/technology.phone/apps.system/tips/tips.ts +22 -0
- package/core/technology.phone/apps.system/tips/tips.ts.SPEC +15 -0
- package/core/technology.phone/apps.thirdparty/alipay/alipay.ts +148 -0
- package/core/technology.phone/apps.thirdparty/alipay/alipay.ts.SPEC +7 -0
- package/core/technology.phone/apps.thirdparty/bilibili/bilibili-app.ts +33 -0
- package/core/technology.phone/apps.thirdparty/bilibili/bilibili.ts +142 -0
- package/core/technology.phone/apps.thirdparty/bilibili/bilibili.ts.SPEC +22 -0
- package/core/technology.phone/apps.thirdparty/wechatread/wechatread.ts +80 -0
- package/core/technology.phone/apps.thirdparty/wechatread/wechatread.ts.SPEC +15 -0
- package/core/technology.phone/index.ts +1 -0
- package/core/technology.phone/package.json +2 -0
- package/core/technology.phone/system.homepage/homepage.ts +247 -0
- package/core/technology.phone/system.homepage/homepage.ts.SPEC +22 -0
- package/core/technology.phone/system.kernel/kernel.ts +264 -0
- package/core/technology.phone/system.kernel/kernel.ts.SPEC +7 -0
- package/core/technology.phone/system.notifications/notifications.ts +87 -0
- package/core/technology.phone/system.notifications/notifications.ts.SPEC +7 -0
- package/core/technology.phone/system.share/share.ts +46 -0
- package/core/technology.phone/system.share/share.ts.SPEC +7 -0
- package/core/technology.server/browser-service.cjs +152 -0
- package/core/technology.server/data/cookies/arxiv.json +30 -0
- package/core/technology.server/data/cookies/bili.json +184 -0
- package/core/technology.server/data/cookies/default.json +30 -0
- package/core/technology.server/data/cookies/news.json +113 -0
- package/core/technology.server/data/cookies/s1.json +45 -0
- package/core/technology.server/data/cookies/safari.json +184 -0
- package/core/technology.server/data/cookies/safari2.json +1 -0
- package/core/technology.server/data/cookies/safaridbg.json +1 -0
- package/core/technology.server/data/cookies/search.json +45 -0
- package/core/technology.server/data/cookies/sw.json +30 -0
- package/core/technology.server/data/cookies/t1.json +1 -0
- package/core/technology.server/data/cookies/testread.json +1 -0
- package/core/technology.server/data/cookies/video1.json +113 -0
- package/core/technology.server/data/cookies/yt.json +170 -0
- package/core/technology.server/data/cookies/yt2.json +113 -0
- package/core/technology.server/pikipedia/#pikipedia.BLUEPRINT +106 -0
- package/core/technology.server/playleft.cjs +247 -0
- package/core/technology.server/search-proxy.py +76 -0
- package/core/technology.server/server.README +59 -0
- package/deploy/dist-overrides/cli/cli.js +18 -0
- package/deploy/dist-overrides/core/extensions/loader.js +518 -0
- package/deploy/dist-overrides/core/package-manager.js +2081 -0
- package/deploy/dist-overrides/core/system-prompt.js +109 -0
- package/deploy/dist-overrides/core/system-prompt.js.LESSON +17 -0
- package/deploy/dist-overrides/core/tools/bash.js +353 -0
- package/deploy/dist-overrides/core/tools/bash.js.CHANGELOG +2 -0
- package/deploy/dist-overrides/core/tools/edit-diff.js +345 -0
- package/deploy/dist-overrides/core/tools/edit.js +315 -0
- package/deploy/dist-overrides/core/tools/edit.js.CHANGELOG +1 -0
- package/deploy/dist-overrides/core/tools/file-mutation-queue.js +52 -0
- package/deploy/dist-overrides/core/tools/find.js +298 -0
- package/deploy/dist-overrides/core/tools/find.js.CHANGELOG +1 -0
- package/deploy/dist-overrides/core/tools/grep.js +305 -0
- package/deploy/dist-overrides/core/tools/grep.js.CHANGELOG +1 -0
- package/deploy/dist-overrides/core/tools/index.js +112 -0
- package/deploy/dist-overrides/core/tools/ls-guard.js +4 -0
- package/deploy/dist-overrides/core/tools/ls.js +170 -0
- package/deploy/dist-overrides/core/tools/ls.js.CHANGELOG +1 -0
- package/deploy/dist-overrides/core/tools/output-accumulator.js +184 -0
- package/deploy/dist-overrides/core/tools/path-utils.js +99 -0
- package/deploy/dist-overrides/core/tools/prompts-reader.js +53 -0
- package/deploy/dist-overrides/core/tools/read.js +392 -0
- package/deploy/dist-overrides/core/tools/read.js.CHANGELOG +1 -0
- package/deploy/dist-overrides/core/tools/render-utils.js +65 -0
- package/deploy/dist-overrides/core/tools/tool-definition-wrapper.js +34 -0
- package/deploy/dist-overrides/core/tools/truncate.js +215 -0
- package/deploy/dist-overrides/core/tools/write.js +203 -0
- package/deploy/dist-overrides/core/tools/write.js.CHANGELOG +1 -0
- package/deploy/dist-overrides/dist-overrides.README +18 -0
- package/deploy/dist-overrides/main.js +665 -0
- package/deploy/dist-overrides/modes/interactive/components/assistant-message.js +139 -0
- package/deploy/dist-overrides/modes/interactive/components/footer.js +326 -0
- package/deploy/dist-overrides/modes/interactive/components/model-selector.js +285 -0
- package/deploy/dist-overrides/modes/interactive/components/tool-execution.js +383 -0
- package/deploy/dist-overrides/modes/interactive/components/tool-execution.js.CHANGELOG +3 -0
- package/deploy/dist-overrides/modes/interactive/interactive-mode.js +4781 -0
- package/deploy/dist-overrides/pi-ai/providers/anthropic.js +931 -0
- package/deploy/dist-overrides/pi-ai/providers/openai-completions.js +1007 -0
- package/deploy/dist-overrides/pi-ai/providers/openai-completions.js.LESSON +15 -0
- package/deploy/dist-overrides/pi-tui/components/loader.js +69 -0
- package/deploy/dist-overrides/pi-tui/components/markdown.js +646 -0
- package/deploy/dist-overrides/pi-tui/components/text.js +92 -0
- package/deploy/dist-overrides/pi-tui/custom-message.js +75 -0
- package/deploy/dist-overrides/pi-tui/tui.js +1266 -0
- package/deploy/dist-overrides/pi-tui/utils.js +1060 -0
- package/deploy/dist-overrides/vendor.REMOVED/jiti/lib/jiti.mjs +3 -0
- package/deploy/install.sh +186 -0
- package/deploy/install.sh.CHANGELOG +6 -0
- package/deploy/lint/lint-naming.ts +202 -0
- package/deploy/scripts/apply.js +18 -0
- package/deploy/scripts/build-github.sh +219 -0
- package/deploy/scripts/build-phone.sh +24 -0
- package/deploy/scripts/check-deploy.sh +42 -0
- package/deploy/scripts/migrate-context.sh +72 -0
- package/deploy/scripts/patch-pi-dist.js +39 -0
- package/deploy/scripts/uninstall.sh +34 -0
- package/package.json +18 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { modelsAreEqual } from "@earendil-works/pi-ai";
|
|
2
|
+
import { Container, fuzzyFilter, getKeybindings, Input, Spacer, Text, } from "@earendil-works/pi-tui";
|
|
3
|
+
import { theme } from "../theme/theme.js";
|
|
4
|
+
import { DynamicBorder } from "./dynamic-border.js";
|
|
5
|
+
import { keyHint } from "./keybinding-hints.js";
|
|
6
|
+
/**
|
|
7
|
+
* Component that renders a model selector with search
|
|
8
|
+
*/
|
|
9
|
+
export class ModelSelectorComponent extends Container {
|
|
10
|
+
searchInput;
|
|
11
|
+
// Focusable implementation - propagate to searchInput for IME cursor positioning
|
|
12
|
+
_focused = false;
|
|
13
|
+
get focused() {
|
|
14
|
+
return this._focused;
|
|
15
|
+
}
|
|
16
|
+
set focused(value) {
|
|
17
|
+
this._focused = value;
|
|
18
|
+
this.searchInput.focused = value;
|
|
19
|
+
}
|
|
20
|
+
listContainer;
|
|
21
|
+
allModels = [];
|
|
22
|
+
scopedModelItems = [];
|
|
23
|
+
activeModels = [];
|
|
24
|
+
filteredModels = [];
|
|
25
|
+
selectedIndex = 0;
|
|
26
|
+
currentModel;
|
|
27
|
+
settingsManager;
|
|
28
|
+
modelRegistry;
|
|
29
|
+
onSelectCallback;
|
|
30
|
+
onCancelCallback;
|
|
31
|
+
errorMessage;
|
|
32
|
+
tui;
|
|
33
|
+
scopedModels;
|
|
34
|
+
scope = "all";
|
|
35
|
+
scopeText;
|
|
36
|
+
scopeHintText;
|
|
37
|
+
constructor(tui, currentModel, settingsManager, modelRegistry, scopedModels, onSelect, onCancel, initialSearchInput) {
|
|
38
|
+
super();
|
|
39
|
+
this.tui = tui;
|
|
40
|
+
this.currentModel = currentModel;
|
|
41
|
+
this.settingsManager = settingsManager;
|
|
42
|
+
this.modelRegistry = modelRegistry;
|
|
43
|
+
this.scopedModels = scopedModels;
|
|
44
|
+
this.scope = scopedModels.length > 0 ? "scoped" : "all";
|
|
45
|
+
this.onSelectCallback = onSelect;
|
|
46
|
+
this.onCancelCallback = onCancel;
|
|
47
|
+
// Add top border
|
|
48
|
+
this.addChild(new DynamicBorder());
|
|
49
|
+
this.addChild(new Spacer(1));
|
|
50
|
+
// Add hint about model filtering
|
|
51
|
+
if (scopedModels.length > 0) {
|
|
52
|
+
this.scopeText = new Text(this.getScopeText(), 0, 0);
|
|
53
|
+
this.addChild(this.scopeText);
|
|
54
|
+
this.scopeHintText = new Text(this.getScopeHintText(), 0, 0);
|
|
55
|
+
this.addChild(this.scopeHintText);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
const hintText = "Only showing models from configured providers. Use /login to add providers.";
|
|
59
|
+
this.addChild(new Text(theme.fg("warning", hintText), 0, 0));
|
|
60
|
+
}
|
|
61
|
+
this.addChild(new Spacer(1));
|
|
62
|
+
// Create search input
|
|
63
|
+
this.searchInput = new Input();
|
|
64
|
+
if (initialSearchInput) {
|
|
65
|
+
this.searchInput.setValue(initialSearchInput);
|
|
66
|
+
}
|
|
67
|
+
this.searchInput.onSubmit = () => {
|
|
68
|
+
// Enter on search input selects the first filtered item
|
|
69
|
+
if (this.filteredModels[this.selectedIndex]) {
|
|
70
|
+
this.handleSelect(this.filteredModels[this.selectedIndex].model);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
this.addChild(this.searchInput);
|
|
74
|
+
this.addChild(new Spacer(1));
|
|
75
|
+
// Create list container
|
|
76
|
+
this.listContainer = new Container();
|
|
77
|
+
this.addChild(this.listContainer);
|
|
78
|
+
this.addChild(new Spacer(1));
|
|
79
|
+
// Add bottom border
|
|
80
|
+
this.addChild(new DynamicBorder());
|
|
81
|
+
// Load models and do initial render
|
|
82
|
+
this.loadModels().then(() => {
|
|
83
|
+
if (initialSearchInput) {
|
|
84
|
+
this.filterModels(initialSearchInput);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
this.updateList();
|
|
88
|
+
}
|
|
89
|
+
// Request re-render after models are loaded
|
|
90
|
+
this.tui.requestRender();
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
async loadModels() {
|
|
94
|
+
let models;
|
|
95
|
+
// Refresh to pick up any changes to models.json
|
|
96
|
+
this.modelRegistry.refresh();
|
|
97
|
+
// Check for models.json errors
|
|
98
|
+
const loadError = this.modelRegistry.getError();
|
|
99
|
+
if (loadError) {
|
|
100
|
+
this.errorMessage = loadError;
|
|
101
|
+
}
|
|
102
|
+
// Load available models (built-in models still work even if models.json failed)
|
|
103
|
+
try {
|
|
104
|
+
const availableModels = await this.modelRegistry.getAvailable();
|
|
105
|
+
models = availableModels.map((model) => ({
|
|
106
|
+
provider: model.provider,
|
|
107
|
+
id: model.id,
|
|
108
|
+
model,
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
this.allModels = [];
|
|
113
|
+
this.scopedModelItems = [];
|
|
114
|
+
this.activeModels = [];
|
|
115
|
+
this.filteredModels = [];
|
|
116
|
+
this.errorMessage = error instanceof Error ? error.message : String(error);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
this.allModels = this.sortModels(models);
|
|
120
|
+
this.scopedModels = this.scopedModels.map((scoped) => {
|
|
121
|
+
const refreshed = this.modelRegistry.find(scoped.model.provider, scoped.model.id);
|
|
122
|
+
return refreshed ? { ...scoped, model: refreshed } : scoped;
|
|
123
|
+
});
|
|
124
|
+
this.scopedModelItems = this.scopedModels.map((scoped) => ({
|
|
125
|
+
provider: scoped.model.provider,
|
|
126
|
+
id: scoped.model.id,
|
|
127
|
+
model: scoped.model,
|
|
128
|
+
}));
|
|
129
|
+
this.activeModels = this.scope === "scoped" ? this.scopedModelItems : this.allModels;
|
|
130
|
+
this.filteredModels = this.activeModels;
|
|
131
|
+
const currentIndex = this.filteredModels.findIndex((item) => modelsAreEqual(this.currentModel, item.model));
|
|
132
|
+
this.selectedIndex =
|
|
133
|
+
currentIndex >= 0 ? currentIndex : Math.min(this.selectedIndex, Math.max(0, this.filteredModels.length - 1));
|
|
134
|
+
}
|
|
135
|
+
sortModels(models) {
|
|
136
|
+
const sorted = [...models];
|
|
137
|
+
// Sort: current model first, then by provider
|
|
138
|
+
sorted.sort((a, b) => {
|
|
139
|
+
const aIsCurrent = modelsAreEqual(this.currentModel, a.model);
|
|
140
|
+
const bIsCurrent = modelsAreEqual(this.currentModel, b.model);
|
|
141
|
+
if (aIsCurrent && !bIsCurrent)
|
|
142
|
+
return -1;
|
|
143
|
+
if (!aIsCurrent && bIsCurrent)
|
|
144
|
+
return 1;
|
|
145
|
+
return a.provider.localeCompare(b.provider);
|
|
146
|
+
});
|
|
147
|
+
return sorted;
|
|
148
|
+
}
|
|
149
|
+
getScopeText() {
|
|
150
|
+
const allText = this.scope === "all" ? theme.fg("accent", "all") : theme.fg("muted", "all");
|
|
151
|
+
const scopedText = this.scope === "scoped" ? theme.fg("accent", "scoped") : theme.fg("muted", "scoped");
|
|
152
|
+
return `${theme.fg("muted", "Scope: ")}${allText}${theme.fg("muted", " | ")}${scopedText}`;
|
|
153
|
+
}
|
|
154
|
+
getScopeHintText() {
|
|
155
|
+
return keyHint("tui.input.tab", "scope") + theme.fg("muted", " (all/scoped)");
|
|
156
|
+
}
|
|
157
|
+
setScope(scope) {
|
|
158
|
+
if (this.scope === scope)
|
|
159
|
+
return;
|
|
160
|
+
this.scope = scope;
|
|
161
|
+
this.activeModels = this.scope === "scoped" ? this.scopedModelItems : this.allModels;
|
|
162
|
+
const currentIndex = this.activeModels.findIndex((item) => modelsAreEqual(this.currentModel, item.model));
|
|
163
|
+
this.selectedIndex = currentIndex >= 0 ? currentIndex : 0;
|
|
164
|
+
this.filterModels(this.searchInput.getValue());
|
|
165
|
+
if (this.scopeText) {
|
|
166
|
+
this.scopeText.setText(this.getScopeText());
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
filterModels(query) {
|
|
170
|
+
this.filteredModels = query
|
|
171
|
+
? fuzzyFilter(this.activeModels, query, ({ id, provider }) => `${id} ${provider} ${provider}/${id} ${provider} ${id}`)
|
|
172
|
+
: this.activeModels;
|
|
173
|
+
this.selectedIndex = Math.min(this.selectedIndex, Math.max(0, this.filteredModels.length - 1));
|
|
174
|
+
this.updateList();
|
|
175
|
+
}
|
|
176
|
+
updateList() {
|
|
177
|
+
this.listContainer.clear();
|
|
178
|
+
const maxVisible = 10;
|
|
179
|
+
const startIndex = Math.max(0, Math.min(this.selectedIndex - Math.floor(maxVisible / 2), this.filteredModels.length - maxVisible));
|
|
180
|
+
const endIndex = Math.min(startIndex + maxVisible, this.filteredModels.length);
|
|
181
|
+
// Show visible slice of filtered models
|
|
182
|
+
for (let i = startIndex; i < endIndex; i++) {
|
|
183
|
+
const item = this.filteredModels[i];
|
|
184
|
+
if (!item)
|
|
185
|
+
continue;
|
|
186
|
+
const isSelected = i === this.selectedIndex;
|
|
187
|
+
const isCurrent = modelsAreEqual(this.currentModel, item.model);
|
|
188
|
+
let line = "";
|
|
189
|
+
if (isSelected) {
|
|
190
|
+
const prefix = theme.fg("accent", "→ ");
|
|
191
|
+
const modelText = `${item.id}`;
|
|
192
|
+
const providerBadge = theme.fg("muted", `[${item.provider}]`);
|
|
193
|
+
const checkmark = isCurrent ? theme.fg("success", " ✓") : "";
|
|
194
|
+
line = `${prefix + theme.fg("accent", modelText)} ${providerBadge}${checkmark}`;
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
const modelText = ` ${item.id}`;
|
|
198
|
+
const providerBadge = theme.fg("muted", `[${item.provider}]`);
|
|
199
|
+
const checkmark = isCurrent ? theme.fg("success", " ✓") : "";
|
|
200
|
+
line = `${modelText} ${providerBadge}${checkmark}`;
|
|
201
|
+
}
|
|
202
|
+
this.listContainer.addChild(new Text(line, 0, 0));
|
|
203
|
+
}
|
|
204
|
+
// Add scroll indicator if needed
|
|
205
|
+
if (startIndex > 0 || endIndex < this.filteredModels.length) {
|
|
206
|
+
const scrollInfo = theme.fg("muted", ` (${this.selectedIndex + 1}/${this.filteredModels.length})`);
|
|
207
|
+
this.listContainer.addChild(new Text(scrollInfo, 0, 0));
|
|
208
|
+
}
|
|
209
|
+
// Show error message or "no results" if empty
|
|
210
|
+
if (this.errorMessage) {
|
|
211
|
+
// Show error in red
|
|
212
|
+
const errorLines = this.errorMessage.split("\n");
|
|
213
|
+
for (const line of errorLines) {
|
|
214
|
+
this.listContainer.addChild(new Text(theme.fg("error", line), 0, 0));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
else if (this.filteredModels.length === 0) {
|
|
218
|
+
this.listContainer.addChild(new Text(theme.fg("muted", " No matching models"), 0, 0));
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
const selected = this.filteredModels[this.selectedIndex];
|
|
222
|
+
this.listContainer.addChild(new Spacer(1));
|
|
223
|
+
this.listContainer.addChild(new Text(theme.fg("muted", ` Model Name: ${selected.model.name}`), 0, 0));
|
|
224
|
+
// pi-coding-master: 切换时直接看到窗口 + miss/hit/out 价格,方便对比选型
|
|
225
|
+
const m = selected.model;
|
|
226
|
+
const cw = m.contextWindow ? `${Math.round(m.contextWindow / 1000)}k` : "?";
|
|
227
|
+
const mx = m.maxTokens ? `${Math.round(m.maxTokens / 1000)}k` : "?";
|
|
228
|
+
const c = m.cost || {};
|
|
229
|
+
const f = (v) => (v === undefined || v === null ? "?" : `¥${v}`);
|
|
230
|
+
this.listContainer.addChild(new Text(theme.fg("muted", ` 窗口 ${cw} · 输出上限 ${mx} · miss ${f(c.input)}/M · hit ${f(c.cacheRead)}/M · out ${f(c.output)}/M`), 0, 0));
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
handleInput(keyData) {
|
|
234
|
+
const kb = getKeybindings();
|
|
235
|
+
if (kb.matches(keyData, "tui.input.tab")) {
|
|
236
|
+
if (this.scopedModelItems.length > 0) {
|
|
237
|
+
const nextScope = this.scope === "all" ? "scoped" : "all";
|
|
238
|
+
this.setScope(nextScope);
|
|
239
|
+
if (this.scopeHintText) {
|
|
240
|
+
this.scopeHintText.setText(this.getScopeHintText());
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
// Up arrow - wrap to bottom when at top
|
|
246
|
+
if (kb.matches(keyData, "tui.select.up")) {
|
|
247
|
+
if (this.filteredModels.length === 0)
|
|
248
|
+
return;
|
|
249
|
+
this.selectedIndex = this.selectedIndex === 0 ? this.filteredModels.length - 1 : this.selectedIndex - 1;
|
|
250
|
+
this.updateList();
|
|
251
|
+
}
|
|
252
|
+
// Down arrow - wrap to top when at bottom
|
|
253
|
+
else if (kb.matches(keyData, "tui.select.down")) {
|
|
254
|
+
if (this.filteredModels.length === 0)
|
|
255
|
+
return;
|
|
256
|
+
this.selectedIndex = this.selectedIndex === this.filteredModels.length - 1 ? 0 : this.selectedIndex + 1;
|
|
257
|
+
this.updateList();
|
|
258
|
+
}
|
|
259
|
+
// Enter
|
|
260
|
+
else if (kb.matches(keyData, "tui.select.confirm")) {
|
|
261
|
+
const selectedModel = this.filteredModels[this.selectedIndex];
|
|
262
|
+
if (selectedModel) {
|
|
263
|
+
this.handleSelect(selectedModel.model);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// Escape or Ctrl+C
|
|
267
|
+
else if (kb.matches(keyData, "tui.select.cancel")) {
|
|
268
|
+
this.onCancelCallback();
|
|
269
|
+
}
|
|
270
|
+
// Pass everything else to search input
|
|
271
|
+
else {
|
|
272
|
+
this.searchInput.handleInput(keyData);
|
|
273
|
+
this.filterModels(this.searchInput.getValue());
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
handleSelect(model) {
|
|
277
|
+
// Save as new default
|
|
278
|
+
this.settingsManager.setDefaultModelAndProvider(model.provider, model.id);
|
|
279
|
+
this.onSelectCallback(model);
|
|
280
|
+
}
|
|
281
|
+
getSearchInput() {
|
|
282
|
+
return this.searchInput;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
//# sourceMappingURL=model-selector.js.map
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import { Box, Container, getCapabilities, Image, Spacer, Text } from "@earendil-works/pi-tui";
|
|
2
|
+
import { createAllToolDefinitions } from "../../../core/tools/index.js";
|
|
3
|
+
import { getTextOutput as getRenderedTextOutput } from "../../../core/tools/render-utils.js";
|
|
4
|
+
import { convertToPng } from "../../../utils/image-convert.js";
|
|
5
|
+
import { theme } from "../theme/theme.js";
|
|
6
|
+
export class ToolExecutionComponent extends Container {
|
|
7
|
+
contentBox;
|
|
8
|
+
contentText;
|
|
9
|
+
selfRenderContainer;
|
|
10
|
+
callRendererComponent;
|
|
11
|
+
resultRendererComponent;
|
|
12
|
+
rendererState = {};
|
|
13
|
+
imageComponents = [];
|
|
14
|
+
imageSpacers = [];
|
|
15
|
+
toolName;
|
|
16
|
+
toolCallId;
|
|
17
|
+
args;
|
|
18
|
+
expanded = false;
|
|
19
|
+
showImages;
|
|
20
|
+
imageWidthCells;
|
|
21
|
+
isPartial = true;
|
|
22
|
+
toolDefinition;
|
|
23
|
+
builtInToolDefinition;
|
|
24
|
+
ui;
|
|
25
|
+
cwd;
|
|
26
|
+
executionStarted = false;
|
|
27
|
+
argsComplete = false;
|
|
28
|
+
result;
|
|
29
|
+
convertedImages = new Map();
|
|
30
|
+
hideComponent = false;
|
|
31
|
+
constructor(toolName, toolCallId, args, options = {}, toolDefinition, ui, cwd) {
|
|
32
|
+
super();
|
|
33
|
+
this.toolName = toolName;
|
|
34
|
+
this.toolCallId = toolCallId;
|
|
35
|
+
this.args = args;
|
|
36
|
+
this.toolDefinition = toolDefinition;
|
|
37
|
+
this.builtInToolDefinition = createAllToolDefinitions(cwd)[toolName];
|
|
38
|
+
this.showImages = options.showImages ?? true;
|
|
39
|
+
this.imageWidthCells = options.imageWidthCells ?? 60;
|
|
40
|
+
this.ui = ui;
|
|
41
|
+
this.cwd = cwd;
|
|
42
|
+
this.addChild(new Spacer(1));
|
|
43
|
+
// Always create all shell variants. contentBox is used for default renderer-based composition.
|
|
44
|
+
// selfRenderContainer is used when the tool renders its own framing.
|
|
45
|
+
// contentText is reserved for generic fallback rendering when no tool definition exists.
|
|
46
|
+
// pi-coding-master: paddingX/Y 都设 0 —— paddingX=1 会把 ● 推到第 1 列(和说话顶格 col0 不对齐);
|
|
47
|
+
// paddingY=1 会在工具块上下各加一个空行(配合 Spacer(1) 就是 2 个,光污染)。归 0 后:
|
|
48
|
+
// ● 顶格对齐说话,块间留白只靠那一个 Spacer(1)。
|
|
49
|
+
this.contentBox = new Box(0, 0, (text) => theme.bg("toolPendingBg", text));
|
|
50
|
+
this.contentText = new Text("", 1, 1, (text) => text); // 透明背景
|
|
51
|
+
this.selfRenderContainer = new Container();
|
|
52
|
+
if (this.hasRendererDefinition()) {
|
|
53
|
+
this.addChild(this.getRenderShell() === "self" ? this.selfRenderContainer : this.contentBox);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
this.addChild(this.contentText);
|
|
57
|
+
}
|
|
58
|
+
this.updateDisplay();
|
|
59
|
+
}
|
|
60
|
+
getCallRenderer() {
|
|
61
|
+
if (!this.builtInToolDefinition) {
|
|
62
|
+
return this.toolDefinition?.renderCall;
|
|
63
|
+
}
|
|
64
|
+
if (!this.toolDefinition) {
|
|
65
|
+
return this.builtInToolDefinition.renderCall;
|
|
66
|
+
}
|
|
67
|
+
return this.toolDefinition.renderCall ?? this.builtInToolDefinition.renderCall;
|
|
68
|
+
}
|
|
69
|
+
getResultRenderer() {
|
|
70
|
+
if (!this.builtInToolDefinition) {
|
|
71
|
+
return this.toolDefinition?.renderResult;
|
|
72
|
+
}
|
|
73
|
+
if (!this.toolDefinition) {
|
|
74
|
+
return this.builtInToolDefinition.renderResult;
|
|
75
|
+
}
|
|
76
|
+
return this.toolDefinition.renderResult ?? this.builtInToolDefinition.renderResult;
|
|
77
|
+
}
|
|
78
|
+
hasRendererDefinition() {
|
|
79
|
+
return this.builtInToolDefinition !== undefined || this.toolDefinition !== undefined;
|
|
80
|
+
}
|
|
81
|
+
getRenderShell() {
|
|
82
|
+
if (!this.builtInToolDefinition) {
|
|
83
|
+
return this.toolDefinition?.renderShell ?? "default";
|
|
84
|
+
}
|
|
85
|
+
if (!this.toolDefinition) {
|
|
86
|
+
return this.builtInToolDefinition.renderShell ?? "default";
|
|
87
|
+
}
|
|
88
|
+
return this.toolDefinition.renderShell ?? this.builtInToolDefinition.renderShell ?? "default";
|
|
89
|
+
}
|
|
90
|
+
getRenderContext(lastComponent) {
|
|
91
|
+
return {
|
|
92
|
+
args: this.args,
|
|
93
|
+
toolCallId: this.toolCallId,
|
|
94
|
+
invalidate: () => {
|
|
95
|
+
this.invalidate();
|
|
96
|
+
this.ui.requestRender();
|
|
97
|
+
},
|
|
98
|
+
lastComponent,
|
|
99
|
+
state: this.rendererState,
|
|
100
|
+
cwd: this.cwd,
|
|
101
|
+
executionStarted: this.executionStarted,
|
|
102
|
+
argsComplete: this.argsComplete,
|
|
103
|
+
isPartial: this.isPartial,
|
|
104
|
+
expanded: this.expanded,
|
|
105
|
+
showImages: this.showImages,
|
|
106
|
+
isError: this.result?.isError ?? false,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
getToolSubtitle(args) {
|
|
110
|
+
if (!args || typeof args !== 'object') return '';
|
|
111
|
+
// Try title, query, name, url in order.
|
|
112
|
+
// NOT 'summary' — that's for internal/logging, displaying it as subtitle
|
|
113
|
+
// duplicates the tool result (e.g. wait/hibernate show the same text twice).
|
|
114
|
+
for (const k of ['title', 'query', 'name', 'url']) {
|
|
115
|
+
const v = args[k];
|
|
116
|
+
if (typeof v === 'string' && v.length > 0 && v.length < 60) return ' ' + v;
|
|
117
|
+
}
|
|
118
|
+
return '';
|
|
119
|
+
}
|
|
120
|
+
createCallFallback() {
|
|
121
|
+
let dot;
|
|
122
|
+
if (this.isPartial) dot = theme.fg("accent", "\u25CB");
|
|
123
|
+
else if (this.result?.isError) dot = theme.fg("error", "\u25CF");
|
|
124
|
+
else dot = theme.fg("success", "\u25CF");
|
|
125
|
+
const displayName = this.toolName.charAt(0).toUpperCase() + this.toolName.slice(1);
|
|
126
|
+
let text = dot + " " + theme.fg("toolTitle", theme.bold(displayName));
|
|
127
|
+
this._resultInlined = false;
|
|
128
|
+
// 短 result 并到同一行(wait/hibernate/nap/sleep 一行就完的,当 subtitle)。
|
|
129
|
+
// bioclock 在结果尾部追加 \n[时:分:秒 +Xs],把它单独剥出来;正文若是单行短文本,就连同
|
|
130
|
+
// 时间戳一起并到标题行(之前直接判 includes('\n') 会因为时间戳那一行而判定多行,把整条挤到第二行或被吃掉)。
|
|
131
|
+
if (this.result && !this.isPartial) {
|
|
132
|
+
const out = this.getTextOutput();
|
|
133
|
+
if (out) {
|
|
134
|
+
const tsMatch = out.match(/\n(\[\d{2}:\d{2}:\d{2}[^\]]*\])\s*$/);
|
|
135
|
+
const ts = tsMatch ? tsMatch[1] : "";
|
|
136
|
+
const body = (tsMatch ? out.slice(0, tsMatch.index) : out).trimEnd();
|
|
137
|
+
if (body.length < 100 && !body.includes('\n')) {
|
|
138
|
+
text += " " + theme.fg("toolOutput", body) + (ts ? " " + theme.fg("muted", ts) : "");
|
|
139
|
+
this._resultInlined = true;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return new Text(text, 0, 0);
|
|
144
|
+
}
|
|
145
|
+
createResultFallback() {
|
|
146
|
+
const output = this.getTextOutput();
|
|
147
|
+
if (!output) {
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
// paddingX=2 让续行对齐 bullet "● " 的位置,而不是顶格(美观)
|
|
151
|
+
return new Text(theme.fg("toolOutput", output), 2, 0);
|
|
152
|
+
}
|
|
153
|
+
updateArgs(args) {
|
|
154
|
+
this.args = args;
|
|
155
|
+
this.updateDisplay();
|
|
156
|
+
}
|
|
157
|
+
markExecutionStarted() {
|
|
158
|
+
this.executionStarted = true;
|
|
159
|
+
this.updateDisplay();
|
|
160
|
+
this.ui.requestRender();
|
|
161
|
+
}
|
|
162
|
+
setArgsComplete() {
|
|
163
|
+
this.argsComplete = true;
|
|
164
|
+
this.updateDisplay();
|
|
165
|
+
this.ui.requestRender();
|
|
166
|
+
}
|
|
167
|
+
updateResult(result, isPartial = false) {
|
|
168
|
+
this.result = result;
|
|
169
|
+
this.isPartial = isPartial;
|
|
170
|
+
this.updateDisplay();
|
|
171
|
+
this.maybeConvertImagesForKitty();
|
|
172
|
+
}
|
|
173
|
+
maybeConvertImagesForKitty() {
|
|
174
|
+
const caps = getCapabilities();
|
|
175
|
+
if (caps.images !== "kitty")
|
|
176
|
+
return;
|
|
177
|
+
if (!this.result)
|
|
178
|
+
return;
|
|
179
|
+
const imageBlocks = this.result.content.filter((c) => c.type === "image");
|
|
180
|
+
for (let i = 0; i < imageBlocks.length; i++) {
|
|
181
|
+
const img = imageBlocks[i];
|
|
182
|
+
if (!img.data || !img.mimeType)
|
|
183
|
+
continue;
|
|
184
|
+
if (img.mimeType === "image/png")
|
|
185
|
+
continue;
|
|
186
|
+
if (this.convertedImages.has(i))
|
|
187
|
+
continue;
|
|
188
|
+
const index = i;
|
|
189
|
+
convertToPng(img.data, img.mimeType).then((converted) => {
|
|
190
|
+
if (converted) {
|
|
191
|
+
this.convertedImages.set(index, converted);
|
|
192
|
+
this.updateDisplay();
|
|
193
|
+
this.ui.requestRender();
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
setExpanded(expanded) {
|
|
199
|
+
this.expanded = expanded;
|
|
200
|
+
this.updateDisplay();
|
|
201
|
+
}
|
|
202
|
+
setShowImages(show) {
|
|
203
|
+
this.showImages = show;
|
|
204
|
+
this.updateDisplay();
|
|
205
|
+
}
|
|
206
|
+
setImageWidthCells(width) {
|
|
207
|
+
this.imageWidthCells = Math.max(1, Math.floor(width));
|
|
208
|
+
this.updateDisplay();
|
|
209
|
+
}
|
|
210
|
+
invalidate() {
|
|
211
|
+
super.invalidate();
|
|
212
|
+
this.updateDisplay();
|
|
213
|
+
}
|
|
214
|
+
render(width) {
|
|
215
|
+
const viewMode = globalThis.__piViewMode || "full";
|
|
216
|
+
if (viewMode === "clean") return [];
|
|
217
|
+
if (viewMode === "fold" && !this.expanded) {
|
|
218
|
+
const args = this.args || {};
|
|
219
|
+
let dot;
|
|
220
|
+
if (this.isPartial) dot = theme.fg("accent", "\u25CB");
|
|
221
|
+
else if (this.result?.isError) dot = theme.fg("error", "\u25CF");
|
|
222
|
+
else dot = theme.fg("success", "\u25CF");
|
|
223
|
+
const capName = this.toolName.charAt(0).toUpperCase() + this.toolName.slice(1);
|
|
224
|
+
let summary = dot + " " + capName;
|
|
225
|
+
if (args.command) summary += ' ' + String(args.command).split("\n")[0].slice(0, 80);
|
|
226
|
+
else if (args.path) summary += ' ' + args.path;
|
|
227
|
+
else if (args.query) summary += ' ' + args.query;
|
|
228
|
+
else if (args.url) summary += ' ' + args.url;
|
|
229
|
+
if (this.result && !this.isPartial) summary += this.result.isError ? " ✗" : " ✓";
|
|
230
|
+
else if (this.isPartial) summary += " …";
|
|
231
|
+
return [summary];
|
|
232
|
+
}
|
|
233
|
+
if (this.hideComponent) {
|
|
234
|
+
return [];
|
|
235
|
+
}
|
|
236
|
+
if (this.hasRendererDefinition() && this.getRenderShell() === "self") {
|
|
237
|
+
const contentLines = this.selfRenderContainer.render(width);
|
|
238
|
+
if (contentLines.length === 0 && this.imageComponents.length === 0) {
|
|
239
|
+
return [];
|
|
240
|
+
}
|
|
241
|
+
const lines = [];
|
|
242
|
+
if (contentLines.length > 0) {
|
|
243
|
+
lines.push("");
|
|
244
|
+
lines.push(...contentLines);
|
|
245
|
+
}
|
|
246
|
+
for (let i = 0; i < this.imageComponents.length; i++) {
|
|
247
|
+
const spacer = this.imageSpacers[i];
|
|
248
|
+
if (spacer) {
|
|
249
|
+
lines.push(...spacer.render(width));
|
|
250
|
+
}
|
|
251
|
+
const imageComponent = this.imageComponents[i];
|
|
252
|
+
if (imageComponent) {
|
|
253
|
+
lines.push(...imageComponent.render(width));
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return lines;
|
|
257
|
+
}
|
|
258
|
+
return super.render(width);
|
|
259
|
+
}
|
|
260
|
+
updateDisplay() {
|
|
261
|
+
const bgFn = (text) => text; // 透明背景(身份函数:原样返回文本,不加底色)。WARN: 不能写成 () => (text) => text,那会把函数本身当文本渲染出来(满屏 "(text) => text" + 渲染崩溃)。
|
|
262
|
+
let hasContent = false;
|
|
263
|
+
this.hideComponent = false;
|
|
264
|
+
if (this.hasRendererDefinition()) {
|
|
265
|
+
const renderContainer = this.getRenderShell() === "self" ? this.selfRenderContainer : this.contentBox;
|
|
266
|
+
if (renderContainer instanceof Box) {
|
|
267
|
+
renderContainer.setBgFn(bgFn);
|
|
268
|
+
}
|
|
269
|
+
renderContainer.clear();
|
|
270
|
+
const callRenderer = this.getCallRenderer();
|
|
271
|
+
if (!callRenderer) {
|
|
272
|
+
renderContainer.addChild(this.createCallFallback());
|
|
273
|
+
hasContent = true;
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
try {
|
|
277
|
+
const component = callRenderer(this.args, theme, this.getRenderContext(this.callRendererComponent));
|
|
278
|
+
this.callRendererComponent = component;
|
|
279
|
+
// 展开视图:把 ● 替换成带状态颜色的版本(递归处理 Text 和 Box 子节点)
|
|
280
|
+
let dot;
|
|
281
|
+
if (this.isPartial) dot = theme.fg('accent', '○');
|
|
282
|
+
else if (this.result?.isError) dot = theme.fg('error', '●');
|
|
283
|
+
else dot = theme.fg('success', '●');
|
|
284
|
+
(function replaceDot(node) {
|
|
285
|
+
if (node && typeof node.text === 'string' && (node.text.includes('●') || node.text.includes('○'))) {
|
|
286
|
+
node.text = node.text.replace(/[●○]/, dot);
|
|
287
|
+
}
|
|
288
|
+
if (node && typeof node.children !== 'undefined') {
|
|
289
|
+
for (const child of node.children) replaceDot(child);
|
|
290
|
+
}
|
|
291
|
+
})(component);
|
|
292
|
+
renderContainer.addChild(component);
|
|
293
|
+
hasContent = true;
|
|
294
|
+
}
|
|
295
|
+
catch {
|
|
296
|
+
this.callRendererComponent = undefined;
|
|
297
|
+
renderContainer.addChild(this.createCallFallback());
|
|
298
|
+
hasContent = true;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (this.result) {
|
|
302
|
+
const resultRenderer = this.getResultRenderer();
|
|
303
|
+
if (!resultRenderer) {
|
|
304
|
+
if (!this._resultInlined) {
|
|
305
|
+
const component = this.createResultFallback();
|
|
306
|
+
if (component) {
|
|
307
|
+
renderContainer.addChild(component);
|
|
308
|
+
hasContent = true;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
try {
|
|
314
|
+
const component = resultRenderer({ content: this.result.content, details: this.result.details }, { expanded: this.expanded, isPartial: this.isPartial }, theme, this.getRenderContext(this.resultRendererComponent));
|
|
315
|
+
this.resultRendererComponent = component;
|
|
316
|
+
renderContainer.addChild(component);
|
|
317
|
+
hasContent = true;
|
|
318
|
+
}
|
|
319
|
+
catch {
|
|
320
|
+
this.resultRendererComponent = undefined;
|
|
321
|
+
if (!this._resultInlined) {
|
|
322
|
+
const component = this.createResultFallback();
|
|
323
|
+
if (component) {
|
|
324
|
+
renderContainer.addChild(component);
|
|
325
|
+
hasContent = true;
|
|
326
|
+
}
|
|
327
|
+
} else { hasContent = true; }
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
this.contentText.setCustomBgFn(bgFn);
|
|
334
|
+
}
|
|
335
|
+
for (const img of this.imageComponents) {
|
|
336
|
+
this.removeChild(img);
|
|
337
|
+
}
|
|
338
|
+
this.imageComponents = [];
|
|
339
|
+
for (const spacer of this.imageSpacers) {
|
|
340
|
+
this.removeChild(spacer);
|
|
341
|
+
}
|
|
342
|
+
this.imageSpacers = [];
|
|
343
|
+
if (this.result) {
|
|
344
|
+
const imageBlocks = this.result.content.filter((c) => c.type === "image");
|
|
345
|
+
const caps = getCapabilities();
|
|
346
|
+
for (let i = 0; i < imageBlocks.length; i++) {
|
|
347
|
+
const img = imageBlocks[i];
|
|
348
|
+
if (caps.images && this.showImages && img.data && img.mimeType) {
|
|
349
|
+
const converted = this.convertedImages.get(i);
|
|
350
|
+
const imageData = converted?.data ?? img.data;
|
|
351
|
+
const imageMimeType = converted?.mimeType ?? img.mimeType;
|
|
352
|
+
if (caps.images === "kitty" && imageMimeType !== "image/png")
|
|
353
|
+
continue;
|
|
354
|
+
const spacer = new Spacer(1);
|
|
355
|
+
this.addChild(spacer);
|
|
356
|
+
this.imageSpacers.push(spacer);
|
|
357
|
+
const imageComponent = new Image(imageData, imageMimeType, { fallbackColor: (s) => theme.fg("toolOutput", s) }, { maxWidthCells: this.imageWidthCells });
|
|
358
|
+
this.imageComponents.push(imageComponent);
|
|
359
|
+
this.addChild(imageComponent);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
if (this.hasRendererDefinition() && !hasContent && this.imageComponents.length === 0) {
|
|
364
|
+
this.hideComponent = true;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
getTextOutput() {
|
|
368
|
+
return getRenderedTextOutput(this.result, this.showImages);
|
|
369
|
+
}
|
|
370
|
+
formatToolExecution() {
|
|
371
|
+
let text = theme.fg("toolTitle", theme.bold(this.toolName.charAt(0).toUpperCase() + this.toolName.slice(1)));
|
|
372
|
+
const content = JSON.stringify(this.args, null, 2);
|
|
373
|
+
if (content) {
|
|
374
|
+
text += `\n\n${content}`;
|
|
375
|
+
}
|
|
376
|
+
const output = this.getTextOutput();
|
|
377
|
+
if (output) {
|
|
378
|
+
text += `\n${output}`;
|
|
379
|
+
}
|
|
380
|
+
return text;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
//# sourceMappingURL=tool-execution.js.map
|