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,180 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
2
|
+
import { Type } from "@sinclair/typebox";
|
|
3
|
+
const StringEnum = <T extends string>(values: readonly T[]) => Type.Union(values.map(v => Type.Literal(v)));
|
|
4
|
+
import { readFile } from "node:fs/promises";
|
|
5
|
+
|
|
6
|
+
export function createReadConscious(pi: ExtensionAPI, getTranscriptPath: () => string | undefined) {
|
|
7
|
+
const derivePersonId = () => {
|
|
8
|
+
const p = getTranscriptPath();
|
|
9
|
+
if (!p) return "?";
|
|
10
|
+
const m = p.match(/memory\/([a-f0-9]+)\//);
|
|
11
|
+
return m ? m[1] : "?";
|
|
12
|
+
};
|
|
13
|
+
return {
|
|
14
|
+
name: "read_conscious",
|
|
15
|
+
label: "Read Conscious",
|
|
16
|
+
messageDescription: "Read the main session's history. Your only window into what the conscious agent is doing.",
|
|
17
|
+
parameters: Type.Object({
|
|
18
|
+
mode: StringEnum(["recent", "search", "range"] as const),
|
|
19
|
+
count: Type.Optional(Type.Number({ messageDescription: "Number of recent messages (for mode=recent, default 20)" })),
|
|
20
|
+
query: Type.Optional(Type.String({ messageDescription: "Search term (for mode=search)" })),
|
|
21
|
+
minutes: Type.Optional(Type.Number({ messageDescription: "Minutes of history (for mode=range)" })),
|
|
22
|
+
}),
|
|
23
|
+
async execute(_toolCallId: string, params: any) {
|
|
24
|
+
const path = getTranscriptPath();
|
|
25
|
+
if (!path) {
|
|
26
|
+
return { content: [{ type: "text" as const, text: "No transcript available." }], details: {} };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let raw: string;
|
|
30
|
+
try {
|
|
31
|
+
raw = await readFile(path, "utf8");
|
|
32
|
+
} catch (err: any) {
|
|
33
|
+
return { content: [{ type: "text" as const, text: `Cannot read transcript: ${err?.message ?? err} (path: ${path})` }], details: {} };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const lines = raw.trim().split("\n").filter(Boolean);
|
|
37
|
+
const entries: any[] = [];
|
|
38
|
+
for (const line of lines) {
|
|
39
|
+
try { entries.push(JSON.parse(line)); } catch { /* skip malformed */ }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Feed format 见 feed-format.SPEC: {role, type, content/think/text/tool, ts}
|
|
43
|
+
const selfId = derivePersonId();
|
|
44
|
+
const foreignPersonRe = /memory\/([a-f0-9]+)\//g;
|
|
45
|
+
const scrub = (t: string) => t.replace(foreignPersonRe, (_: string, id: string) =>
|
|
46
|
+
id === selfId ? `memory/${id}/` : `memory/[other-person-${id.slice(0,6)}]/`
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const messages = entries.map((e: any) => {
|
|
50
|
+
switch (e.type) {
|
|
51
|
+
case "user_msg": return { role: "user", content: e.content, timestamp: e.ts };
|
|
52
|
+
case "think": return { role: "think", content: (e.think || "").slice(0, 300), timestamp: e.ts };
|
|
53
|
+
case "text": return { role: "say", content: scrub(e.text || ""), timestamp: e.ts };
|
|
54
|
+
case "mouth": return { role: "mouth", content: e.content, timestamp: e.ts };
|
|
55
|
+
case "toolCall": return { role: "tool", content: `${e.tool?.name} ${typeof e.tool?.args === "object" ? JSON.stringify(e.tool.args) : e.tool?.args || ""}`.trim(), timestamp: e.ts };
|
|
56
|
+
case "toolResult":return { role: "result", content: scrub((e.content||"").slice(0, 500)), timestamp: e.ts };
|
|
57
|
+
case "start_msg":return { role: "system", content: e.content, timestamp: e.ts };
|
|
58
|
+
// 旧格式兼容(迁移完成前 feed 里仍存在大量旧条目)
|
|
59
|
+
case "message": {
|
|
60
|
+
const c = e.content;
|
|
61
|
+
const text = typeof c === "string" ? c : Array.isArray(c) ? c.map((x:any) => x.text||x.thinking||"").join(" ") : "";
|
|
62
|
+
return { role: e.role || "assistant", content: scrub(text.slice(0, 500)), timestamp: e.ts };
|
|
63
|
+
}
|
|
64
|
+
case "user_input": return { role: "user", content: e.text || "", timestamp: e.ts };
|
|
65
|
+
case "agent_start":return { role: "system", content: "[agent start]", timestamp: e.ts };
|
|
66
|
+
case "agent_end": return { role: "system", content: "[agent end]", timestamp: e.ts };
|
|
67
|
+
case "turn_end": return { role: "system", content: `[turn end ${e.toolResults??""}]`, timestamp: e.ts };
|
|
68
|
+
case "tool_done": return { role: "tool", content: `${e.tool}${e.error?" err":" ok"}`, timestamp: e.ts };
|
|
69
|
+
case "dream": return { role: "system", content: "[dream]", timestamp: e.ts };
|
|
70
|
+
default: return { role: e.type || "?", content: JSON.stringify(e).slice(0, 200), timestamp: e.ts };
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
if (params.mode === "recent") {
|
|
75
|
+
const n = params.count ?? 20;
|
|
76
|
+
const slice = messages.slice(-n);
|
|
77
|
+
return {
|
|
78
|
+
content: [{ type: "text" as const, text: `[仅当前person ${derivePersonId()} 的feed。内容中若出现其他 personId (如8cbde57b) —— 是主意识在引用/分析历史数据,非跨session污染。]
|
|
79
|
+
|
|
80
|
+
${formatMessages(slice)}` }],
|
|
81
|
+
details: { count: slice.length },
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (params.mode === "search" && params.query) {
|
|
86
|
+
const q = params.query.toLowerCase();
|
|
87
|
+
const matches = messages.filter((m: any) => {
|
|
88
|
+
const text = extractText(m);
|
|
89
|
+
return text.toLowerCase().includes(q);
|
|
90
|
+
});
|
|
91
|
+
const slice = matches.slice(-30);
|
|
92
|
+
return {
|
|
93
|
+
content: [{ type: "text" as const, text: `[仅当前person ${derivePersonId()} 的feed。内容中若出现其他 personId —— 是主意识在引用/分析历史数据,非跨session污染。]
|
|
94
|
+
|
|
95
|
+
Found ${matches.length} messages matching "${params.query}":
|
|
96
|
+
|
|
97
|
+
${formatMessages(slice)}` }],
|
|
98
|
+
details: { total: matches.length, shown: slice.length },
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (params.mode === "range" && params.minutes) {
|
|
103
|
+
const cutoff = Date.now() - params.minutes * 60 * 1000;
|
|
104
|
+
const inRange = messages.filter((m: any) => (m.timestamp ?? 0) >= cutoff);
|
|
105
|
+
return {
|
|
106
|
+
content: [{ type: "text" as const, text: `[仅当前person ${derivePersonId()} 的feed。内容中若出现其他 personId —— 是主意识在引用/分析历史数据,非跨session污染。]
|
|
107
|
+
|
|
108
|
+
Last ${params.minutes} minutes (${inRange.length} messages):
|
|
109
|
+
|
|
110
|
+
${formatMessages(inRange)}` }],
|
|
111
|
+
details: { count: inRange.length },
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return { content: [{ type: "text" as const, text: "Invalid mode. Use recent, search, or range." }], details: {} };
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function createAware(pi: ExtensionAPI) {
|
|
121
|
+
return {
|
|
122
|
+
name: "aware",
|
|
123
|
+
label: "Aware",
|
|
124
|
+
messageDescription: "Send a thought to the main session. Use when you have a genuine observation, doubt, or reminder.",
|
|
125
|
+
parameters: Type.Object({
|
|
126
|
+
thought: Type.String({ messageDescription: "Your observation, doubt, or reminder" }),
|
|
127
|
+
urgency: Type.Optional(StringEnum(["low", "normal", "high"] as const)),
|
|
128
|
+
}),
|
|
129
|
+
async execute(_toolCallId: string, params: any) {
|
|
130
|
+
const urgency = params.urgency ?? "normal";
|
|
131
|
+
const urgent = urgency === "high";
|
|
132
|
+
|
|
133
|
+
// Route through notification system if available
|
|
134
|
+
const push = (globalThis as any).__notificationPush;
|
|
135
|
+
if (push) {
|
|
136
|
+
push({ from: "subconscious", content: params.thought, urgent });
|
|
137
|
+
} else {
|
|
138
|
+
// Fallback: direct send
|
|
139
|
+
try {
|
|
140
|
+
const prefix = urgent ? "WARN: [subconscious]" : "[subconscious]";
|
|
141
|
+
pi.sendMessage(
|
|
142
|
+
{ messageType: "conscious-aware", content: `${prefix} ${params.thought}`, isisDisplayedInTUIedInTUI: true },
|
|
143
|
+
{ deliverAs: urgent ? "steer" : "followUp", isTriggerNewTurn: urgent }
|
|
144
|
+
);
|
|
145
|
+
} catch {
|
|
146
|
+
return {
|
|
147
|
+
content: [{ type: "text" as const, text: "Delivery failed." }],
|
|
148
|
+
details: { urgency, delivered: false },
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
content: [{ type: "text" as const, text: `Sent: "${params.thought}"` }],
|
|
155
|
+
details: { urgency, delivered: true },
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function extractText(msg: any): string {
|
|
162
|
+
if (typeof msg.content === "string") return msg.content;
|
|
163
|
+
if (Array.isArray(msg.content)) {
|
|
164
|
+
return msg.content
|
|
165
|
+
.filter((c: any) => c.type === "text")
|
|
166
|
+
.map((c: any) => c.text)
|
|
167
|
+
.join("\n");
|
|
168
|
+
}
|
|
169
|
+
return "";
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function formatMessages(msgs: any[]): string {
|
|
173
|
+
if (msgs.length === 0) return "(empty)";
|
|
174
|
+
return msgs.map((m: any) => {
|
|
175
|
+
const role = m.role ?? "?";
|
|
176
|
+
const ts = m.timestamp ? new Date(m.timestamp).toLocaleTimeString() : "";
|
|
177
|
+
const text = extractText(m).slice(0, 500);
|
|
178
|
+
return `[${ts}] ${role}: ${text}`;
|
|
179
|
+
}).join("\n\n");
|
|
180
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[2026-06-15 19:11:02] created
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
## 2026-06-15 19:10 CST — 重写:去掉 Local_24h_Note 依赖
|
|
2
|
+
|
|
3
|
+
- 删除 SERVER_CMD(旧:硬编码指向 Local_24h_Note 的服务启动命令)
|
|
4
|
+
- BRIDGE_SCRIPT → RECORDER_SCRIPT,指向新的 ear_recorder.py
|
|
5
|
+
- 移除所有 Local_24h_Note 引用(ear_bridge.py 不再使用)
|
|
6
|
+
- 状态栏从"转录服务器"改为"录音器"
|
|
7
|
+
- 消息注入去掉 app 标记([🎤] 不再带 app 名)
|
|
8
|
+
[2026-06-15 19:35:43] edited (auto-logged, no messageDescription)
|
|
9
|
+
19:35 - 修复命令解析优先级bug: (args?._?.[0] || args?.on ? ...) 三元嵌套问题
|
|
10
|
+
[2026-06-15 19:40:41] edited (auto-logged, no messageDescription)
|
|
11
|
+
19:40 - FIXED: pi passes args as string, not object with _. Changed command parsing to treat args directly as 'on'/'off' string
|
|
12
|
+
[2026-06-15 19:41:06] edited (auto-logged, no messageDescription)
|
|
13
|
+
[2026-06-15 19:42:03] edited (auto-logged, no messageDescription)
|
|
14
|
+
[2026-06-15 19:42:26] edited (auto-logged, no messageDescription)
|
|
15
|
+
[2026-06-15 19:43:59] edited (auto-logged, no messageDescription)
|
|
16
|
+
[2026-06-15 19:44:08] edited (auto-logged, no messageDescription)
|
|
17
|
+
[2026-06-15 19:44:20] edited (auto-logged, no messageDescription)
|
|
18
|
+
[2026-06-15 19:46:32] edited (auto-logged, no messageDescription)
|
|
19
|
+
[2026-06-15 19:49:54] edited (auto-logged, no messageDescription)
|
|
20
|
+
[2026-06-15 19:51:24] edited (auto-logged, no messageDescription)
|
|
21
|
+
[2026-06-15 20:04:15] edited (auto-logged, no messageDescription)
|
|
22
|
+
[2026-06-15 20:06:58] edited (auto-logged, no messageDescription)
|
|
23
|
+
[2026-06-15 20:18:46] edited (auto-logged, no messageDescription)
|
|
24
|
+
[2026-06-15 20:19:17] edited (auto-logged, no messageDescription)
|
|
25
|
+
[2026-06-15 20:20:28] edited (auto-logged, no messageDescription)
|
|
26
|
+
19:34 — display: true → false,防止转录文字出现在输入框
|
|
27
|
+
[2026-06-15 20:22:32] edited (auto-logged, no messageDescription)
|
|
28
|
+
[2026-06-15 20:25:33] edited (auto-logged, no messageDescription)
|
|
29
|
+
[2026-06-15 20:34:07] edited (auto-logged, no messageDescription)
|
|
30
|
+
[2026-06-15 20:38:33] edited (auto-logged, no messageDescription)
|
|
31
|
+
[2026-06-15 20:40:11] edited (auto-logged, no messageDescription)
|
|
32
|
+
[2026-06-15 20:41:27] edited (auto-logged, no messageDescription)
|
|
33
|
+
[2026-06-15 20:43:34] edited (auto-logged, no messageDescription)
|
|
34
|
+
[2026-06-15 20:44:31] edited (auto-logged, no messageDescription)
|
|
35
|
+
[2026-06-15 20:45:51] edited (auto-logged, no messageDescription)
|
|
36
|
+
[2026-06-15 20:46:20] edited (auto-logged, no messageDescription)
|
|
37
|
+
[2026-06-15 20:46:56] edited (auto-logged, no messageDescription)
|
|
38
|
+
[2026-06-15 20:49:15] edited (auto-logged, no messageDescription)
|
|
39
|
+
[2026-06-15 20:49:23] edited (auto-logged, no messageDescription)
|
|
40
|
+
[2026-06-15 21:00:56] edited (auto-logged, no messageDescription)
|
|
41
|
+
[2026-06-15 21:01:36] edited (auto-logged, no messageDescription)
|
|
42
|
+
[2026-06-15 21:01:57] edited (auto-logged, no messageDescription)
|
|
43
|
+
[2026-06-15 21:06:37] edited (auto-logged, no messageDescription)
|
|
44
|
+
[2026-06-15 21:06:56] edited (auto-logged, no messageDescription)
|
|
45
|
+
[2026-06-15 21:15:15] edited (auto-logged, no messageDescription)
|
|
46
|
+
[2026-06-15 21:16:11] edited (auto-logged, no messageDescription)
|
|
47
|
+
[2026-06-15 21:29:08] edited (auto-logged, no messageDescription)
|
|
48
|
+
[2026-06-16] 命令真正改名 /ear → /ears:registerCommand、messageDescription、状态栏 🎤 ears、顶部注释、ear.ts.SPEC 全部对齐。此前别处 changelog 声称已改名但代码仍是 /ear(只动了文档没动代码),本次把代码改齐,编译通过。
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
[2026-06-15 19:10:05] created
|
|
2
|
+
[2026-06-15 19:14:45] edited (auto-logged, no messageDescription)
|
|
3
|
+
[2026-06-15 20:36:36] edited (auto-logged, no messageDescription)
|
|
4
|
+
[2026-06-15 21:00:34] edited (auto-logged, no messageDescription)
|
|
5
|
+
[2026-06-15 21:07:10] edited (auto-logged, no messageDescription)
|
|
6
|
+
[2026-06-15 21:21:23] edited (auto-logged, no messageDescription)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./listen.ts";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
source: index.ts @ 5716a393
|
|
2
|
+
|
|
3
|
+
# index.ts — Ear entry: re-exports ears.ts
|
|
4
|
+
|
|
5
|
+
## 职责
|
|
6
|
+
Entry point for the ears.listen func. Pure re-export of the default export from ./ears.ts. Serves as the module boundary that kernel imports via #ear.
|
|
7
|
+
|
|
8
|
+
## 接口
|
|
9
|
+
- `default` — re-exported from `./ears.js`
|
|
10
|
+
|
|
11
|
+
## 依赖
|
|
12
|
+
- `./ears.js`
|
|
13
|
+
|
|
14
|
+
## 行为要点
|
|
15
|
+
- Single-line re-export, no additional logic
|
|
16
|
+
- Actual ear implementation lives in ears.ts (not read in this batch)
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// ears.listen — Voice input (bios func)
|
|
2
|
+
// /ears on → 启动录音+豆包ASR, 监听语音
|
|
3
|
+
// /ears off → 关闭录音, 停止监听
|
|
4
|
+
// /ears → 查看状态
|
|
5
|
+
//
|
|
6
|
+
// keep-alive: 每 5s 检测 recorder 进程是否活着,死了自动复活。
|
|
7
|
+
// session_shutdown: 主意识退出时自动清理所有 ear 进程。
|
|
8
|
+
|
|
9
|
+
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
10
|
+
import { watch } from "node:fs";
|
|
11
|
+
import { readFile } from "node:fs/promises";
|
|
12
|
+
import { execSync, spawn, type ChildProcess } from "node:child_process";
|
|
13
|
+
import { resolve, dirname } from "node:path";
|
|
14
|
+
import { getPrompt } from "#runtime";
|
|
15
|
+
|
|
16
|
+
const PROMPT = getPrompt("ear.listen");
|
|
17
|
+
const PYTHON = "/opt/homebrew/Caskroom/miniforge/base/bin/python3";
|
|
18
|
+
const RECORDER_SCRIPT = resolve(dirname(new URL(import.meta.url).pathname), "listen_recorder.py");
|
|
19
|
+
|
|
20
|
+
function isRecorderAlive(): boolean {
|
|
21
|
+
try { execSync("pgrep -f 'listen_recorder.py'", { stdio: "ignore" }); return true; }
|
|
22
|
+
catch { return false; }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default function (pi: ExtensionAPI) {
|
|
26
|
+
const _cmds: any[] = [];
|
|
27
|
+
let personDir: string | null = null;
|
|
28
|
+
let watcher: ReturnType<typeof watch> | null = null;
|
|
29
|
+
let offset = 0;
|
|
30
|
+
let listening = false;
|
|
31
|
+
let recorderProc: ChildProcess | null = null;
|
|
32
|
+
let keepAliveTimer: ReturnType<typeof setInterval> | null = null;
|
|
33
|
+
|
|
34
|
+
const earFile = () => `${personDir}/ear_output.jsonl`;
|
|
35
|
+
|
|
36
|
+
function startRecorder() {
|
|
37
|
+
if (isRecorderAlive()) return; // 已经活着就不杀
|
|
38
|
+
recorderProc = null;
|
|
39
|
+
|
|
40
|
+
const file = earFile();
|
|
41
|
+
const logFile = `${personDir}/ear_debug.log`;
|
|
42
|
+
const logFd = require("node:fs").openSync(logFile, "a");
|
|
43
|
+
require("node:fs").writeSync(logFd, `${new Date().toISOString()} [keep-alive] spawn ${RECORDER_SCRIPT} ${file}\n`);
|
|
44
|
+
recorderProc = spawn(PYTHON, ["-u", RECORDER_SCRIPT, file], {
|
|
45
|
+
detached: true,
|
|
46
|
+
stdio: ["ignore", logFd, logFd],
|
|
47
|
+
});
|
|
48
|
+
recorderProc.unref();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function stopRecorder() {
|
|
52
|
+
if (recorderProc) { recorderProc.kill(); recorderProc = null; }
|
|
53
|
+
try { execSync("pkill -f 'listen_recorder.py' 2>/dev/null"); } catch {}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function startKeepAlive() {
|
|
57
|
+
if (keepAliveTimer) return;
|
|
58
|
+
keepAliveTimer = setInterval(() => {
|
|
59
|
+
if (!listening || !personDir) return;
|
|
60
|
+
if (!isRecorderAlive()) {
|
|
61
|
+
startRecorder();
|
|
62
|
+
}
|
|
63
|
+
}, 5000);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function stopKeepAlive() {
|
|
67
|
+
if (keepAliveTimer) { clearInterval(keepAliveTimer); keepAliveTimer = null; }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ── 语音缓冲 ─────────────────────────────────────────
|
|
71
|
+
// 只用 final(整句) → 进缓冲,攒到 1.5s 无新输入后一起发送
|
|
72
|
+
// delta 太碎(豆包逐字返回),不展示中间态。
|
|
73
|
+
let speechBuffer: string[] = [];
|
|
74
|
+
let flushTimer: ReturnType<typeof setTimeout> | null = null;
|
|
75
|
+
const FLUSH_DELAY = 3000; // 3s 无新输入 → 说完了,一起发送
|
|
76
|
+
|
|
77
|
+
function flushBuffer() {
|
|
78
|
+
if (flushTimer) { clearTimeout(flushTimer); flushTimer = null; }
|
|
79
|
+
if (speechBuffer.length === 0) return;
|
|
80
|
+
const combined = speechBuffer.join(" ");
|
|
81
|
+
speechBuffer = [];
|
|
82
|
+
// 整句说完 → steer 打断模型,开始回复
|
|
83
|
+
pi.sendUserMessage(combined, { deliverAs: "steer" });
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function startWatch() {
|
|
87
|
+
if (watcher || !personDir) return;
|
|
88
|
+
try { execSync(`touch "${earFile()}"`); } catch {}
|
|
89
|
+
try {
|
|
90
|
+
const existing = require("node:fs").readFileSync(earFile(), "utf8");
|
|
91
|
+
offset = existing.length;
|
|
92
|
+
} catch {}
|
|
93
|
+
watcher = watch(earFile(), async () => {
|
|
94
|
+
if (!listening || !personDir) return;
|
|
95
|
+
// mouth 正在说话时静音,防止回声(带超时:文件超过30s没人更新就自动清除)
|
|
96
|
+
try {
|
|
97
|
+
const muteStat = require("node:fs").statSync("/tmp/pi_mouth_speaking");
|
|
98
|
+
if (Date.now() - muteStat.mtimeMs < 30000) return; // 30s内更新过 → 真在说话
|
|
99
|
+
require("node:fs").unlinkSync("/tmp/pi_mouth_speaking"); // 超时 → 清理僵尸文件
|
|
100
|
+
} catch { /* 文件不存在,正常 */ }
|
|
101
|
+
try {
|
|
102
|
+
const content = await readFile(earFile(), "utf8");
|
|
103
|
+
if (content.length <= offset) return;
|
|
104
|
+
const newPart = content.slice(offset);
|
|
105
|
+
offset = content.length;
|
|
106
|
+
for (const line of newPart.trim().split("\n").filter(Boolean)) {
|
|
107
|
+
try {
|
|
108
|
+
const entry = JSON.parse(line);
|
|
109
|
+
const text = entry.text || entry.translation || "";
|
|
110
|
+
if (!text.trim()) continue;
|
|
111
|
+
// 只用 final(整句),delta 太碎不展示
|
|
112
|
+
if (entry.is_final !== false && text.trim()) {
|
|
113
|
+
speechBuffer.push(text);
|
|
114
|
+
if (flushTimer) clearTimeout(flushTimer);
|
|
115
|
+
flushTimer = setTimeout(flushBuffer, FLUSH_DELAY);
|
|
116
|
+
}
|
|
117
|
+
} catch {}
|
|
118
|
+
}
|
|
119
|
+
} catch {}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function stopWatch() {
|
|
124
|
+
flushBuffer(); // 发送未发送的缓冲内容
|
|
125
|
+
if (watcher) { watcher.close(); watcher = null; }
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ── 语音路由:当前语音发给哪个 agent ───────────────────
|
|
129
|
+
let routeTarget: "main" | "auto" = "main";
|
|
130
|
+
|
|
131
|
+
// ── /ears 命令 ────────────────────────────────────────────
|
|
132
|
+
_cmds.push({
|
|
133
|
+
name: "body-ears",
|
|
134
|
+
desc: "语音输入控制 — /body-ears on|off|route main|auto",
|
|
135
|
+
handler: async (args: any, ctx: any) => {
|
|
136
|
+
const action = (typeof args === "string" && args.trim()) || "status";
|
|
137
|
+
const sub = (action.includes(" ") ? action.split(" ") : [action]) as string[];
|
|
138
|
+
|
|
139
|
+
if (sub[0] === "route") {
|
|
140
|
+
const target = sub[1];
|
|
141
|
+
if (target === "main" || target === "auto") {
|
|
142
|
+
routeTarget = target;
|
|
143
|
+
ctx.ui.notify(`ear route: ${target}`, "info");
|
|
144
|
+
} else {
|
|
145
|
+
ctx.ui.notify(`用法: /ears route main|auto`, "warning");
|
|
146
|
+
}
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (action === "on") {
|
|
151
|
+
if (!personDir) { ctx.ui.notify("person dir not found", "warning"); return; }
|
|
152
|
+
listening = true;
|
|
153
|
+
startRecorder();
|
|
154
|
+
startWatch();
|
|
155
|
+
startKeepAlive();
|
|
156
|
+
ctx.ui.notify("ear on", "info");
|
|
157
|
+
} else if (action === "off") {
|
|
158
|
+
listening = false;
|
|
159
|
+
stopRecorder();
|
|
160
|
+
stopWatch();
|
|
161
|
+
stopKeepAlive();
|
|
162
|
+
ctx.ui.notify("ear off", "info");
|
|
163
|
+
} else {
|
|
164
|
+
const alive = isRecorderAlive();
|
|
165
|
+
ctx.ui.notify(
|
|
166
|
+
`ear ${listening ? "on" : "off"}, recorder ${alive ? "running" : "stopped"}`,
|
|
167
|
+
"info"
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// ── 主意识 session 启动 → 默认打开耳朵 ─────────────────
|
|
174
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
175
|
+
const sf = ctx.sessionManager.getSessionFile();
|
|
176
|
+
if (!sf) return;
|
|
177
|
+
|
|
178
|
+
// 跳过子进程 session(潜意识/海马体/睡眠)
|
|
179
|
+
if (sf.includes("conscious-sessions") ||
|
|
180
|
+
sf.includes("hippocampus-sessions") ||
|
|
181
|
+
sf.includes("sleep-sessions")) return;
|
|
182
|
+
|
|
183
|
+
const match = sf.match(/\.pi\/memory\/([a-f0-9]+)\//);
|
|
184
|
+
if (!match) return;
|
|
185
|
+
personDir = `${process.env.HOME}/.pi/memory/${match[1]}/.data`;
|
|
186
|
+
|
|
187
|
+
// 默认关闭耳朵(需 /ears on 手动开启)
|
|
188
|
+
listening = false;
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
// ── 注入 prompt ─────────────────────────────────────────
|
|
192
|
+
pi.on("before_agent_start", async (event) => {
|
|
193
|
+
if (!listening) return;
|
|
194
|
+
return { systemPrompt: event.systemPrompt + "\n\n" + PROMPT };
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// 语音输入通过 sendUserMessage 发送,复用 pi 原生用户消息渲染。
|
|
198
|
+
|
|
199
|
+
// ── 清理 ─────────────────────────────────────────────────
|
|
200
|
+
pi.on("session_shutdown", () => {
|
|
201
|
+
listening = false;
|
|
202
|
+
stopRecorder();
|
|
203
|
+
stopWatch();
|
|
204
|
+
stopKeepAlive();
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
return _cmds;
|
|
208
|
+
}
|