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,56 @@
|
|
|
1
|
+
# conscious-feed.jsonl 数据格式规范
|
|
2
|
+
|
|
3
|
+
> 写入:subconscious/index.ts message_end
|
|
4
|
+
> 读取:tools.ts read_conscious
|
|
5
|
+
> 消费者:潜意识(通过 read_conscious 读历史,用 aware 发送反思)
|
|
6
|
+
|
|
7
|
+
## 铁律
|
|
8
|
+
|
|
9
|
+
- 每行一条 JSON,`role` + `type` 唯一确定一种记录
|
|
10
|
+
- **role** = 谁产生的:`user` | `assistant` | `system`
|
|
11
|
+
- **type** = 具体干什么:见下表
|
|
12
|
+
- 所有记录必有 `ts` (unix ms)
|
|
13
|
+
- **主意识和潜意识共用同一个 feed**,但 type 体系各自独立——潜意识的 type(如 aware)只由潜意识写入,主意识的 type 只由主意识写入。写入时按 role 区分来源,读取时按 role 过滤。
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## role 枚举
|
|
18
|
+
|
|
19
|
+
| role | 含义 | 写入者 |
|
|
20
|
+
|------|------|--------|
|
|
21
|
+
| `user` | 用户输入 | 主意识 session (input 事件) |
|
|
22
|
+
| `assistant` | 模型产出 | 主意识 session (message_end 事件) |
|
|
23
|
+
| `system` | 系统消息 | 主意识 + 潜意识 |
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## type 枚举(主意识侧)
|
|
28
|
+
|
|
29
|
+
| type | role | 内容字段 | 示例 |
|
|
30
|
+
|------|------|---------|------|
|
|
31
|
+
| `user_msg` | `user` | `content: string` | `{"role":"user","type":"user_msg","content":"你好","ts":...}` |
|
|
32
|
+
| `think` | `assistant` | `think: string` | `{"role":"assistant","type":"think","think":"内部推理","ts":...}` |
|
|
33
|
+
| `text` | `assistant` | `text: string` | `{"role":"assistant","type":"text","text":"回复内容","ts":...}` |
|
|
34
|
+
| `mouth` | `assistant` | `content: string` | `{"role":"assistant","type":"mouth","content":"朗读文本","ts":...}` |
|
|
35
|
+
| `toolCall` | `assistant` | `tool: {name, args}` | `{"role":"assistant","type":"toolCall","tool":{"name":"bash","args":"ls"},"ts":...}` |
|
|
36
|
+
| `toolResult` | `system` | `content: string` | `{"role":"system","type":"toolResult","content":"file1 file2","ts":...}` |
|
|
37
|
+
| `start_msg` | `system` | `content: string` | `{"role":"system","type":"start_msg","content":"系统提示词/date","ts":...}` |
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## type 枚举(潜意识侧——独立体系,待设计)
|
|
42
|
+
|
|
43
|
+
| type | role | 内容字段 | 示例 |
|
|
44
|
+
|------|------|---------|------|
|
|
45
|
+
| `aware` | `system` | `title, thought, strength` | `{"role":"system","type":"aware","title":"...","thought":"...","strength":0.8,"ts":...}` |
|
|
46
|
+
|
|
47
|
+
⚠️ 潜意识目前有自己的 feed 写入逻辑,**不要用主意识的 type 去框它**。潜意识需要另外设计 role 和 type。当前只确保主意识侧的格式正确,潜意识侧不改动。
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## 设计约束
|
|
52
|
+
|
|
53
|
+
1. **不用 `content` 数组**:不再嵌套 `[{type:"thinking"}, {type:"text"}]`。一条 feed entry = 一个 think 或一个 text 或一个 toolCall。
|
|
54
|
+
2. **`text` 和 `think` 分两条写**:模型一次产出包含 think+text 时,拆成两条独立 entry。
|
|
55
|
+
3. **纯 think(无 text)不丢弃**:think 需要进入 feed,供潜意识反思主意识的思考过程。
|
|
56
|
+
4. **mouth 保留 `content` 字段**:mouth 是 TTS 朗读文本,不需要拆分 text/think。
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
[2026-06-12 15:14:18] edited (auto-logged, no messageDescription)
|
|
2
|
+
[2026-06-12 15:14:18] fix: register read_conscious tool in RPC subprocess (was missing after refactor, subconscious could only speak via aware but couldn't read main session history)
|
|
3
|
+
[2026-06-12 16:22:37] edited (auto-logged, no messageDescription)
|
|
4
|
+
[2026-06-12 16:22:42] edited (auto-logged, no messageDescription)
|
|
5
|
+
[2026-06-12 16:22:50] edited (auto-logged, no messageDescription)
|
|
6
|
+
[2026-06-15] fix: aware 显示不全/丢失(by Claude Code)
|
|
7
|
+
① 渲染器正则 /^\[(...)\]\s*(.*)/ → /^\[(...)\]\s*([\s\S]*)$/
|
|
8
|
+
—— .* 不匹配换行,多行 thought 被截成只剩第一行(这是"aware 没显示全"的根因)。
|
|
9
|
+
② aware watcher 只消费"完整行"(以 \n 结尾),末尾写了一半的 JSON 行留到下次事件再处理;
|
|
10
|
+
原来半截行 parse 失败被跳过、offset 却已推过 → 那条 aware 彻底丢失。现已防住。
|
|
11
|
+
也内联了 getPrompt("subconscious.observe")(去掉 prompt.ts 中间层)+ 级联看门狗(见 subconscious.ts.CHANGELOG)。
|
|
12
|
+
[2026-06-19] 消息包裹转义:thought 内容中的 ---[/ 闭合标签被转义,防止包裹提前闭合
|
|
13
|
+
[2026-06-19] 潜意识消息缩进对齐:paddingX 0→1,和工具调用卡片的缩进一致
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
2
|
+
import { execSync } from "node:child_process";
|
|
3
|
+
import { writeFile, mkdir } from "node:fs/promises";
|
|
4
|
+
import { appendFileSync } from "node:fs";
|
|
5
|
+
import { getPrompt } from "#runtime";
|
|
6
|
+
|
|
7
|
+
export interface SubconsciousHandle {
|
|
8
|
+
start(): void;
|
|
9
|
+
stop(): void;
|
|
10
|
+
isRunning(): boolean;
|
|
11
|
+
getMessages(): any[];
|
|
12
|
+
getSessionId(): string;
|
|
13
|
+
getSessionDir(): string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function createSubconscious(
|
|
17
|
+
pi: ExtensionAPI,
|
|
18
|
+
getTranscriptPath: () => string | undefined,
|
|
19
|
+
onError: (msg: string) => void,
|
|
20
|
+
onMessage: (msg: any) => void,
|
|
21
|
+
personDir: string,
|
|
22
|
+
): SubconsciousHandle {
|
|
23
|
+
const personId = personDir.match(/([a-f0-9]+)$/)?.[1] ?? "x";
|
|
24
|
+
const tmuxName = `sc-${personId}`;
|
|
25
|
+
const sessionDir = `${personDir}/.data/conscious-sessions`;
|
|
26
|
+
let running = false;
|
|
27
|
+
|
|
28
|
+
function tmuxHas(): boolean {
|
|
29
|
+
try {
|
|
30
|
+
execSync(`tmux has-session -t ${tmuxName} 2>/dev/null`);
|
|
31
|
+
return true;
|
|
32
|
+
} catch { return false; }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const self: SubconsciousHandle = {
|
|
36
|
+
async start() {
|
|
37
|
+
running = true;
|
|
38
|
+
try { appendFileSync("/tmp/sc-spawn.log", `[${new Date().toISOString()}] start() called, tmuxHas=${tmuxHas()}\n`); } catch {}
|
|
39
|
+
if (tmuxHas()) {
|
|
40
|
+
// tmux session 在但进程可能死了(空壳)——检查 pane 是否有活进程
|
|
41
|
+
try {
|
|
42
|
+
const pid = execSync(`tmux list-panes -t ${tmuxName} -F '#{pane_pid}' 2>/dev/null`).toString().trim();
|
|
43
|
+
if (pid) {
|
|
44
|
+
const children = execSync(`pgrep -P ${pid} 2>/dev/null`).toString().trim();
|
|
45
|
+
if (children) return; // 有子进程在跑,真的活着
|
|
46
|
+
}
|
|
47
|
+
} catch {}
|
|
48
|
+
// 空壳,杀掉重建
|
|
49
|
+
try { execSync(`tmux kill-session -t ${tmuxName} 2>/dev/null`); } catch {}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
await mkdir(sessionDir, { recursive: true });
|
|
53
|
+
|
|
54
|
+
const feedPath = getTranscriptPath() ?? `${personDir}/.data/conscious-feed.jsonl`;
|
|
55
|
+
const promptFile = `${personDir}/.data/conscious-prompt.md`;
|
|
56
|
+
await writeFile(promptFile, `${getPrompt("subconscious.observe")}
|
|
57
|
+
|
|
58
|
+
Main session history (read it regularly for new content): ${feedPath}
|
|
59
|
+
Send thoughts to the main session with the aware tool.`);
|
|
60
|
+
|
|
61
|
+
// Subconscious = a real pi running inside tmux (real TTY, native rendering).
|
|
62
|
+
// continuous extension inside keeps it alive during a run; this launcher keeps it
|
|
63
|
+
// alive ACROSS runs — if pi crashes/exits (e.g. insufficient balance exits the
|
|
64
|
+
// process outright), wait with backoff and restart. When the condition clears
|
|
65
|
+
// (balance topped up), it auto-recovers. Killed when the conscious session ends.
|
|
66
|
+
// User watches it with: tmux attach -t sc-<id> -r (read-only)
|
|
67
|
+
try {
|
|
68
|
+
const initialPrompt = "开始你的工作:持续阅读主意识的历史记录,反思,发现问题就用 aware 告诉主意识。";
|
|
69
|
+
const launchScript = `${personDir}/.data/conscious-launch.sh`;
|
|
70
|
+
await writeFile(launchScript, `#!/bin/bash
|
|
71
|
+
# Self-healing subconscious launcher (auto-generated). Restarts pi with backoff on exit.
|
|
72
|
+
export NODE_OPTIONS="\${NODE_OPTIONS:+\$NODE_OPTIONS }--experimental-transform-types"
|
|
73
|
+
SESSION_DIR=${JSON.stringify(sessionDir)}
|
|
74
|
+
PROMPT_FILE=${JSON.stringify(promptFile)}
|
|
75
|
+
INITIAL=${JSON.stringify(initialPrompt)}
|
|
76
|
+
MAIN_PID=${process.pid}
|
|
77
|
+
FEED_FILE=${JSON.stringify(feedPath)}
|
|
78
|
+
# 级联看门狗:主意识进程一退出,就连本 tmux 一起关掉(防孤儿常驻烧钱)。
|
|
79
|
+
( while kill -0 "$MAIN_PID" 2>/dev/null; do sleep 5; done; echo "[sc] 主意识已退出,自动关闭本实例。"; tmux kill-session -t ${tmuxName} 2>/dev/null ) &
|
|
80
|
+
BACKOFF=15
|
|
81
|
+
PREV_SIZE=0
|
|
82
|
+
while true; do
|
|
83
|
+
kill -0 "$MAIN_PID" 2>/dev/null || { echo "[sc] 主意识没了,退出。"; break; }
|
|
84
|
+
# 只有 feed 有新内容(主意识有活动)才启动
|
|
85
|
+
CURR_SIZE=$(stat -f%z "$FEED_FILE" 2>/dev/null || echo 0)
|
|
86
|
+
if [ "$CURR_SIZE" -le "$PREV_SIZE" ]; then sleep 30; continue; fi
|
|
87
|
+
PREV_SIZE=$CURR_SIZE
|
|
88
|
+
START=$(date +%s)
|
|
89
|
+
mkdir -p "$SESSION_DIR"
|
|
90
|
+
python3 -c "import json; open('$SESSION_DIR/conv.json','w').write(json.dumps({'messages':[{'role':'system','content':open('$PROMPT_FILE').read()}]}))" 2>/dev/null
|
|
91
|
+
# 初始消息作为位置参数传入,stdin 保持 tmux TTY(让 TUI 正常渲染)
|
|
92
|
+
BLACKBOX="$HOME/smart-pi/pi-coding-master.DEV/Codebase/debug/god.pi.blackbox/blackbox.sh"
|
|
93
|
+
if [ -x "$BLACKBOX" ]; then
|
|
94
|
+
"$BLACKBOX" "${personId}" "sc-${personId}" "subconscious" -- /opt/homebrew/bin/pi --session-dir "$SESSION_DIR" "$INITIAL"
|
|
95
|
+
else
|
|
96
|
+
/opt/homebrew/bin/pi --session-dir "$SESSION_DIR" "$INITIAL"
|
|
97
|
+
fi
|
|
98
|
+
CODE=$?
|
|
99
|
+
RAN=$(( $(date +%s) - START ))
|
|
100
|
+
if [ "$RAN" -ge 120 ]; then BACKOFF=15; else BACKOFF=$(( BACKOFF * 2 )); [ "$BACKOFF" -gt 300 ] && BACKOFF=300; fi
|
|
101
|
+
echo "[$(date '+%F %T')] subconscious pi exited (code=$CODE, ran $RAN s) — restart in $BACKOFF s"
|
|
102
|
+
sleep "$BACKOFF"
|
|
103
|
+
done
|
|
104
|
+
`);
|
|
105
|
+
execSync(`chmod +x "${launchScript}"`, { stdio: "ignore" });
|
|
106
|
+
try { execSync(`tmux kill-session -t ${tmuxName} 2>/dev/null`); } catch {} // 先清掉同名僵尸 session(spawn failed 的根)
|
|
107
|
+
execSync(
|
|
108
|
+
`tmux new-session -d -s ${tmuxName} -c "${personDir}" 'bash "${launchScript}"'`,
|
|
109
|
+
{ stdio: "ignore" }
|
|
110
|
+
);
|
|
111
|
+
} catch (err: any) {
|
|
112
|
+
try { appendFileSync("/tmp/sc-spawn.log", `[${new Date().toISOString()}] SPAWN FAILED: ${err?.stack ?? err}\n`); } catch {}
|
|
113
|
+
onError(`Subconscious tmux spawn failed: ${err?.message ?? err}`);
|
|
114
|
+
running = false;
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
stop() {
|
|
119
|
+
running = false;
|
|
120
|
+
try { execSync(`tmux kill-session -t ${tmuxName} 2>/dev/null`); } catch {}
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
isRunning() { return tmuxHas(); },
|
|
124
|
+
getMessages() { return []; },
|
|
125
|
+
getSessionId() { return tmuxName; },
|
|
126
|
+
getSessionDir() { return sessionDir; },
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
return self;
|
|
130
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
source: spawner.ts @ 443d6408
|
|
2
|
+
|
|
3
|
+
潜意识扩展入口。
|
|
4
|
+
|
|
5
|
+
用户原话:"应该是潜意识激活的,潜意识是另一个 pi session,这个始终内部自动运行,
|
|
6
|
+
并且能看到明窗口的内容,在有的时候可以往明窗口说话。"
|
|
7
|
+
"模型不是表演给人看的,一定是做给自己的。"
|
|
8
|
+
|
|
9
|
+
启动时在进程内创建一个潜意识 AgentSession,只有 read_conscious 和 aware 两个工具。
|
|
10
|
+
潜意识和明 session 共享同一个生命周期——明 session 启动时启动,关闭时关闭。
|
|
11
|
+
潜意识也是活的,用 wait 歇一会然后自动醒。
|
|
12
|
+
|
|
13
|
+
详细设计见 Smart Claude/pi/CONSCIOUS_SPEC.md
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { getMarkdownTheme } from "@mariozechner/pi-coding-agent";
|
|
2
|
+
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
3
|
+
import { Type } from "@sinclair/typebox";
|
|
4
|
+
import { appendFile, mkdir, readFile } from "node:fs/promises";
|
|
5
|
+
import { watch, readFileSync, writeFileSync, appendFileSync } from "node:fs";
|
|
6
|
+
import { createSubconscious, type SubconsciousHandle } from "./spawner.ts";
|
|
7
|
+
import { createReadConscious } from "./tools.ts";
|
|
8
|
+
import { GUTTER } from "#blockrender"; // 统一块渲染引擎:内容列常量
|
|
9
|
+
import { createRequire } from "node:module";
|
|
10
|
+
const _require = createRequire(import.meta.url);
|
|
11
|
+
import { personDir as getPersonDir } from "#paths";
|
|
12
|
+
|
|
13
|
+
// 潜意识开关:每人持久化(JSON 布尔,不删文件、避开删除禁令)。off=不再启动潜意识;记忆不受影响。
|
|
14
|
+
function scFlag(personDir: string): string { return `${personDir}/.data/subconscious.json`; }
|
|
15
|
+
function scDisabled(personDir: string): boolean {
|
|
16
|
+
try { return !!JSON.parse(readFileSync(scFlag(personDir), "utf8")).disabled; } catch { return false; }
|
|
17
|
+
}
|
|
18
|
+
function setScDisabled(personDir: string, disabled: boolean): void {
|
|
19
|
+
try { writeFileSync(scFlag(personDir), JSON.stringify({ disabled, ts: new Date().toISOString() })); } catch {}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function isSubconsciousSession(sessionFile: string | undefined): boolean {
|
|
23
|
+
return !!sessionFile?.includes("conscious-sessions");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default function (pi: ExtensionAPI) {
|
|
27
|
+
const _cmds: any[] = [];
|
|
28
|
+
let lastError = "";
|
|
29
|
+
let sub: SubconsciousHandle | null = null;
|
|
30
|
+
let feedFile = "";
|
|
31
|
+
let awareFile = "";
|
|
32
|
+
let awareWatcher: ReturnType<typeof watch> | null = null;
|
|
33
|
+
let awareOffset = 0;
|
|
34
|
+
let isSubconscious = false;
|
|
35
|
+
let curPersonDir: string | null = null;
|
|
36
|
+
|
|
37
|
+
// ── /subconscious 开关:禁用/启用潜意识(每人持久,重启仍生效;不影响记忆)──
|
|
38
|
+
_cmds.push({
|
|
39
|
+
name: "brain-subconscious",
|
|
40
|
+
desc: "潜意识开关:/brain-subconscious [on|off]。off=不再启动潜意识(记忆不受影响),持久、重启仍生效。",
|
|
41
|
+
handler: async (args: any, ctx: any) => {
|
|
42
|
+
const pd = curPersonDir;
|
|
43
|
+
if (!pd) { ctx.ui.notify("当前无 person 目录(主意识 session 才能切)。", "warning"); return; }
|
|
44
|
+
const a = (args ?? "").trim().toLowerCase();
|
|
45
|
+
if (a === "off") {
|
|
46
|
+
setScDisabled(pd, true);
|
|
47
|
+
try { sub?.stop(); } catch {}
|
|
48
|
+
ctx.ui.notify("潜意识已禁用(持久,重启仍生效)。记忆不受影响。/subconscious on 恢复。", "info");
|
|
49
|
+
} else if (a === "on") {
|
|
50
|
+
setScDisabled(pd, false);
|
|
51
|
+
try { sub?.start(); } catch {}
|
|
52
|
+
ctx.ui.notify("潜意识已启用。", "info");
|
|
53
|
+
} else {
|
|
54
|
+
ctx.ui.notify(`潜意识当前:${scDisabled(pd) ? "禁用" : "启用"}。用 /subconscious [on|off] 切换。`, "info");
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// ── aware renderer: header line + content below ───────────────────
|
|
60
|
+
pi.registerMessageRenderer("conscious-aware", (message, _opts, theme) => {
|
|
61
|
+
const { Markdown } = _require("@earendil-works/pi-tui");
|
|
62
|
+
const raw = (message.content ?? "").toString();
|
|
63
|
+
let title = "潜意识";
|
|
64
|
+
let body = raw;
|
|
65
|
+
const wrapped = raw.match(/^---\[subconscious(?:::([^\]]*))?\]---\r?\n?([\s\S]*?)\r?\n?---\[\/subconscious\]---\s*$/);
|
|
66
|
+
if (wrapped) {
|
|
67
|
+
title = (wrapped[1] || "潜意识").trim();
|
|
68
|
+
body = wrapped[2].trim();
|
|
69
|
+
} else {
|
|
70
|
+
const m = raw.match(/^\[([^\]]+)\]\s*([\s\S]*)$/);
|
|
71
|
+
if (m) { title = m[1]; body = m[2]; }
|
|
72
|
+
}
|
|
73
|
+
// 红● + 白粗 Subconscious + 红色细体内容
|
|
74
|
+
const { Container, Spacer, Text } = _require("@earendil-works/pi-tui");
|
|
75
|
+
const head = theme.fg("error", "●") + " " + theme.bold("Subconscious")
|
|
76
|
+
+ (title && title !== "潜意识" ? " " + theme.fg("error", title) : "");
|
|
77
|
+
const c = new Container();
|
|
78
|
+
c.addChild(new Text(head, 0, 0));
|
|
79
|
+
c.addChild(new Text(theme.fg("error", body), GUTTER, 0));
|
|
80
|
+
return c;
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// ── feed writer (main session only) ──────────────────────────────
|
|
84
|
+
async function feed(type: string, data: any) {
|
|
85
|
+
if (!feedFile || isSubconscious) return;
|
|
86
|
+
try { await appendFile(feedFile, JSON.stringify({ type, ts: Date.now(), ...data }) + "\n"); } catch {}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// ── feed writer — conscious-feed.jsonl 统一格式见 feed-format.SPEC ──
|
|
90
|
+
// role: user|assistant|system type: 见 SPEC
|
|
91
|
+
function feedEntry(entry: Record<string, any>) {
|
|
92
|
+
if (!feedFile || isSubconscious) return;
|
|
93
|
+
try { appendFileSync(feedFile, JSON.stringify({ ...entry, ts: Date.now() }) + "\n"); } catch {}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
pi.on("message_end", async (event) => {
|
|
97
|
+
const msg = event.message as any;
|
|
98
|
+
if (!msg) return;
|
|
99
|
+
const ct = msg.messageType;
|
|
100
|
+
// 系统包裹消息 → type=start_msg
|
|
101
|
+
if (ct === "continuous-date") { feedEntry({ role: "system", type: "start_msg", content: msg.content }); return; }
|
|
102
|
+
if (ct === "memory-snapshot" || ct === "memory-capacity" || ct === "sleep-done") return; // 不写 feed
|
|
103
|
+
if (ct) return; // 其他 messageType 跳过
|
|
104
|
+
|
|
105
|
+
// message_end: content 是数组 [{type:"thinking",thinking:"..."}, {type:"text",text:"..."}, ...]
|
|
106
|
+
const parts = Array.isArray(msg.content) ? msg.content : [];
|
|
107
|
+
for (const p of parts) {
|
|
108
|
+
if (p.type === "thinking" && p.thinking) {
|
|
109
|
+
feedEntry({ role: "assistant", type: "think", think: p.thinking });
|
|
110
|
+
} else if (p.type === "text" && p.text?.trim()) {
|
|
111
|
+
feedEntry({ role: "assistant", type: "text", text: p.text.trim() });
|
|
112
|
+
} else if (p.type === "toolCall") {
|
|
113
|
+
feedEntry({ role: "assistant", type: "toolCall", tool: { name: p.name, args: p.arguments } });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
pi.on("tool_execution_end", async (event) => {
|
|
119
|
+
feedEntry({ role: "system", type: "toolResult", content: (event as any).result?.content?.[0]?.text || "" });
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
pi.on("input", async (event) => {
|
|
123
|
+
feedEntry({ role: "user", type: "user_msg", content: (event as any).text });
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// ── lifecycle ────────────────────────────────────────────────────
|
|
127
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
128
|
+
const sessionFile = ctx.sessionManager.getSessionFile();
|
|
129
|
+
|
|
130
|
+
// 海马体 / 睡眠小号也加载了本扩展,但它们既不是主意识也不是潜意识——什么都别做:
|
|
131
|
+
// 不喂 feed、不 spawn 潜意识、不监听 aware。否则它们会把自己的活动写进共享的 conscious-feed.jsonl,
|
|
132
|
+
// 污染真潜意识读的那份历史(feed 里混入海马体工具调用,正是之前的污染源之一)。
|
|
133
|
+
if (sessionFile && (sessionFile.includes("hippocampus-sessions") || sessionFile.includes("sleep-sessions"))) {
|
|
134
|
+
isSubconscious = false;
|
|
135
|
+
feedFile = "";
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
isSubconscious = isSubconsciousSession(sessionFile);
|
|
140
|
+
|
|
141
|
+
if (isSubconscious) {
|
|
142
|
+
// ── I AM the subconscious. Register read_conscious + aware, don't spawn. ──
|
|
143
|
+
const personDir = sessionFile!.match(/(.*\.pi\/memory\/[a-f0-9]+)\//)?.[1] ?? "";
|
|
144
|
+
const feedPath = `${personDir}/.data/conscious-feed.jsonl`;
|
|
145
|
+
awareFile = `${personDir}/.data/conscious-aware.jsonl`;
|
|
146
|
+
|
|
147
|
+
// read_conscious: read the main session's history
|
|
148
|
+
const rc = createReadConscious(pi, () => feedPath);
|
|
149
|
+
pi.registerTool({
|
|
150
|
+
name: rc.name,
|
|
151
|
+
label: rc.label,
|
|
152
|
+
messageDescription: rc.messageDescription,
|
|
153
|
+
promptSnippet: "Read main session history (recent/search/range)",
|
|
154
|
+
parameters: rc.parameters,
|
|
155
|
+
renderCall(_args: any, theme: any) {
|
|
156
|
+
const { Text } = _require("@earendil-works/pi-tui");
|
|
157
|
+
return new Text(theme.fg("toolTitle", "● " + theme.bold("Read_conscious ")) + theme.fg("dim", "reading main session..."), 0, 0); // ● 顶格 + paddingX0(统一管线)
|
|
158
|
+
},
|
|
159
|
+
async execute(id: string, params: any) { return rc.execute(id, params); },
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
pi.registerTool({
|
|
163
|
+
name: "aware",
|
|
164
|
+
label: "Aware",
|
|
165
|
+
messageDescription: "Send a structured event to the main consciousness. Each event has title, preview, strength, and can interrupt streaming.",
|
|
166
|
+
promptSnippet: "Send a thought to the main session",
|
|
167
|
+
parameters: Type.Object({
|
|
168
|
+
title: Type.String({ messageDescription: "Short event title (≤50 chars)" }),
|
|
169
|
+
preview: Type.String({ messageDescription: "Brief summary (≤100 chars)" }),
|
|
170
|
+
thought: Type.String({ messageDescription: "Full observation or reminder" }),
|
|
171
|
+
strength: Type.Optional(Type.Number({ messageDescription: "0.0–1.0: low (0.1), normal (0.5), high (0.8), critical (1.0). High+ interrupts streaming.", minimum: 0, maximum: 1 })),
|
|
172
|
+
}),
|
|
173
|
+
async execute(_id, params) {
|
|
174
|
+
const event = {
|
|
175
|
+
type: "subconscious",
|
|
176
|
+
title: params.title,
|
|
177
|
+
preview: params.preview,
|
|
178
|
+
thought: params.thought,
|
|
179
|
+
strength: params.strength ?? 0.5,
|
|
180
|
+
ts: Date.now(),
|
|
181
|
+
};
|
|
182
|
+
await appendFile(awareFile, JSON.stringify(event) + "\n");
|
|
183
|
+
return { content: [{ type: "text", text: `Event sent: [${event.title}] (strength=${event.strength})` }], details: {} };
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// ── I am the MAIN session. Spawn subconscious + watch aware. ──
|
|
190
|
+
sub?.stop();
|
|
191
|
+
if (awareWatcher) { awareWatcher.close(); awareWatcher = null; }
|
|
192
|
+
|
|
193
|
+
const personDir = getPersonDir(sessionFile);
|
|
194
|
+
if (!personDir) { feedFile = ""; return; }
|
|
195
|
+
curPersonDir = personDir;
|
|
196
|
+
|
|
197
|
+
feedFile = `${personDir}/.data/conscious-feed.jsonl`;
|
|
198
|
+
awareFile = `${personDir}/.data/conscious-aware.jsonl`;
|
|
199
|
+
try { await mkdir(`${personDir}/.data`, { recursive: true }); } catch {}
|
|
200
|
+
try { await appendFile(awareFile, "", { flag: "a" }); } catch {}
|
|
201
|
+
|
|
202
|
+
// Track current offset so we only inject NEW thoughts
|
|
203
|
+
try { awareOffset = (await readFile(awareFile, "utf8")).length; } catch { awareOffset = 0; }
|
|
204
|
+
|
|
205
|
+
// Watch aware file → inject new thoughts into main session
|
|
206
|
+
const eventStore = `${personDir}/.data/events.jsonl`;
|
|
207
|
+
let awareProcessing = false;
|
|
208
|
+
awareWatcher = watch(awareFile, async () => {
|
|
209
|
+
if (awareProcessing) return;
|
|
210
|
+
awareProcessing = true;
|
|
211
|
+
try {
|
|
212
|
+
const content = await readFile(awareFile, "utf8");
|
|
213
|
+
if (content.length <= awareOffset) return;
|
|
214
|
+
const newPart = content.slice(awareOffset);
|
|
215
|
+
// 只消费"完整行"(以 \n 结尾);末尾写了一半的行留到下次事件,
|
|
216
|
+
// 否则半截 JSON 会 parse 失败被跳过、offset 又推过去 → 那条 aware 彻底丢失。
|
|
217
|
+
const lastNL = newPart.lastIndexOf("\n");
|
|
218
|
+
if (lastNL < 0) return;
|
|
219
|
+
const complete = newPart.slice(0, lastNL + 1);
|
|
220
|
+
awareOffset += complete.length;
|
|
221
|
+
|
|
222
|
+
for (const line of complete.split("\n").filter(Boolean)) {
|
|
223
|
+
try {
|
|
224
|
+
const entry = JSON.parse(line);
|
|
225
|
+
// Support both old format {thought, urgency} and new {type, title, preview, thought, strength}
|
|
226
|
+
const title = entry.title || "潜意识";
|
|
227
|
+
const thought = entry.thought || "";
|
|
228
|
+
const preview = entry.preview || thought.slice(0, 80);
|
|
229
|
+
const strength = entry.strength ?? (entry.urgency === "high" ? 0.8 : entry.urgency === "low" ? 0.2 : 0.5);
|
|
230
|
+
const interrupt = strength >= 0.8; // high+ strength interrupts streaming
|
|
231
|
+
|
|
232
|
+
// Also write to event store for event list
|
|
233
|
+
const ev = JSON.stringify({
|
|
234
|
+
type: "aware", title, preview, strength,
|
|
235
|
+
ts: new Date().toISOString()
|
|
236
|
+
}) + "\n";
|
|
237
|
+
try { await appendFile(eventStore, ev, { flag: "a" }); } catch {}
|
|
238
|
+
// 默认全送达:每条 aware 都 isTriggerNewTurn=true,确保进主意识上下文(哪怕它在歇/hibernate)。
|
|
239
|
+
// 不再用强度阈值丢弃普通 aware——潜意识那么多好反思,丢了太可怕。发不发由潜意识自己判断
|
|
240
|
+
// (它的提示词管"没事就闭嘴"),一旦发出就一定送到。strength 只决定要不要【打断当前流】:
|
|
241
|
+
// 高(≥0.8)=主意识可能正在犯错,steer 立刻插进去;否则 followUp 在 turn 边界送达,不打断它当前的活。
|
|
242
|
+
pi.sendMessage(
|
|
243
|
+
{
|
|
244
|
+
messageType: "conscious-aware",
|
|
245
|
+
content: `[${title}] ${thought}`,
|
|
246
|
+
isDisplayedInTUI: true,
|
|
247
|
+
},
|
|
248
|
+
{ deliverAs: interrupt ? "steer" : "followUp", isTriggerNewTurn: true }
|
|
249
|
+
);
|
|
250
|
+
} catch {}
|
|
251
|
+
}
|
|
252
|
+
} catch {} finally { awareProcessing = false; }
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
sub = createSubconscious(
|
|
256
|
+
pi,
|
|
257
|
+
() => feedFile,
|
|
258
|
+
(msg: string) => { lastError = msg; },
|
|
259
|
+
() => {},
|
|
260
|
+
personDir,
|
|
261
|
+
);
|
|
262
|
+
if (scDisabled(personDir)) {
|
|
263
|
+
// 手动禁用(/subconscious off):不启动潜意识,重启仍生效,并提示。
|
|
264
|
+
// 记忆不受影响——主意识的记忆注入(memory.ts)与潜意识无关。
|
|
265
|
+
pi.sendMessage(
|
|
266
|
+
{ messageType: "memory-subconscious-disabled", content: "潜意识已禁用(/subconscious on 恢复)", isDisplayedInTUI: false },
|
|
267
|
+
{ deliverAs: "nextTurn" }
|
|
268
|
+
);
|
|
269
|
+
} else {
|
|
270
|
+
sub.start().catch((e: any) => { lastError = String(e?.message ?? e); });
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
pi.on("session_shutdown", async () => {
|
|
275
|
+
sub?.stop();
|
|
276
|
+
if (awareWatcher) { awareWatcher.close(); awareWatcher = null; }
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
return _cmds;
|
|
280
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
[2026-06-15] by Claude Code
|
|
2
|
+
- prompt 内联:createSubconscious 里 SUBCONSCIOUS_PROMPT 改成 getPrompt("subconscious.observe"),
|
|
3
|
+
删掉中间层 prompt.ts。
|
|
4
|
+
- 加级联看门狗:sc 启动脚本加 MAIN_PID=主意识 pid + 后台子进程轮询 kill -0;主意识进程一退出 →
|
|
5
|
+
自动 tmux kill-session 把本 sc 实例连 tmux 一起关掉(循环顶也查一次)。
|
|
6
|
+
解决"主程序死了 sc 还自启自跑、孤儿常驻烧钱"。
|
|
7
|
+
- ⚠️ 当前正在跑的旧孤儿用的是没看门狗的旧脚本,需手动 tmux kill-session 清掉;之后新 main spawn 的才带看门狗。
|