openclaw-node-harness 2.0.0
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/LICENSE +21 -0
- package/README.md +184 -0
- package/bin/discord-read.js +228 -0
- package/bin/fleet-deploy.js +365 -0
- package/bin/lane-watchdog.js +232 -0
- package/bin/mesh-agent.js +714 -0
- package/bin/mesh-bridge.js +535 -0
- package/bin/mesh-deploy-listener.js +322 -0
- package/bin/mesh-deploy.js +1048 -0
- package/bin/mesh-health-publisher.js +247 -0
- package/bin/mesh-task-daemon.js +451 -0
- package/bin/mesh-tool-discord.js +293 -0
- package/bin/mesh.js +649 -0
- package/boot/manifest.yaml +187 -0
- package/cli.js +35 -0
- package/config/daemon.json.template +16 -0
- package/config/obsidian-sync.json.template +39 -0
- package/config/openclaw.json.template +124 -0
- package/config/transcript-sources.json.template +22 -0
- package/identity/AGENTS.md +201 -0
- package/identity/CLAUDE.md +64 -0
- package/identity/DELEGATION.md +304 -0
- package/identity/HEARTBEAT.md +163 -0
- package/identity/MEMORY_SPEC.md +368 -0
- package/identity/PRINCIPLES.md +81 -0
- package/identity/SOUL.md +48 -0
- package/identity/TOOLS.md +47 -0
- package/install.sh +895 -0
- package/lib/agent-activity.js +390 -0
- package/lib/kanban-io.js +352 -0
- package/lib/mesh-registry.js +194 -0
- package/lib/mesh-roles.js +13 -0
- package/lib/mesh-tasks.js +306 -0
- package/lib/nats-resolve.js +108 -0
- package/mission-control/README.md +36 -0
- package/mission-control/drizzle/0000_simple_silhouette.sql +62 -0
- package/mission-control/drizzle/meta/0000_snapshot.json +413 -0
- package/mission-control/drizzle/meta/_journal.json +13 -0
- package/mission-control/drizzle.config.ts +13 -0
- package/mission-control/eslint.config.mjs +18 -0
- package/mission-control/next.config.ts +7 -0
- package/mission-control/package-lock.json +10518 -0
- package/mission-control/package.json +49 -0
- package/mission-control/postcss.config.mjs +7 -0
- package/mission-control/public/file.svg +1 -0
- package/mission-control/public/globe.svg +1 -0
- package/mission-control/public/next.svg +1 -0
- package/mission-control/public/vercel.svg +1 -0
- package/mission-control/public/window.svg +1 -0
- package/mission-control/scripts/enrich-descriptions.js +193 -0
- package/mission-control/scripts/gen-chronology.js +102 -0
- package/mission-control/scripts/import-pipeline-v2.js +523 -0
- package/mission-control/scripts/import-pipeline.js +295 -0
- package/mission-control/src/app/api/activity/live/route.ts +27 -0
- package/mission-control/src/app/api/activity/route.ts +47 -0
- package/mission-control/src/app/api/burndown/route.ts +112 -0
- package/mission-control/src/app/api/critical-path/route.ts +159 -0
- package/mission-control/src/app/api/dependencies/route.ts +176 -0
- package/mission-control/src/app/api/memory/categories/route.ts +93 -0
- package/mission-control/src/app/api/memory/consolidate/route.ts +107 -0
- package/mission-control/src/app/api/memory/doc/route.ts +89 -0
- package/mission-control/src/app/api/memory/flush/route.ts +129 -0
- package/mission-control/src/app/api/memory/graph/route.ts +105 -0
- package/mission-control/src/app/api/memory/items/route.ts +86 -0
- package/mission-control/src/app/api/memory/list/route.ts +48 -0
- package/mission-control/src/app/api/memory/retrieve/route.ts +51 -0
- package/mission-control/src/app/api/memory/search/route.ts +143 -0
- package/mission-control/src/app/api/memory/sync/route.ts +23 -0
- package/mission-control/src/app/api/memory/wikilinks/route.ts +75 -0
- package/mission-control/src/app/api/mesh/events/route.ts +67 -0
- package/mission-control/src/app/api/mesh/nodes/route.ts +221 -0
- package/mission-control/src/app/api/mesh/tokens/route.ts +133 -0
- package/mission-control/src/app/api/projects/route.ts +102 -0
- package/mission-control/src/app/api/resolve-path/route.ts +92 -0
- package/mission-control/src/app/api/scheduler/tick/route.ts +38 -0
- package/mission-control/src/app/api/scheduler/waves/route.ts +54 -0
- package/mission-control/src/app/api/screenshot/route.ts +127 -0
- package/mission-control/src/app/api/settings/gateway/route.ts +92 -0
- package/mission-control/src/app/api/skills/[id]/health/route.ts +57 -0
- package/mission-control/src/app/api/skills/list/route.ts +41 -0
- package/mission-control/src/app/api/souls/[id]/evolution/route.ts +253 -0
- package/mission-control/src/app/api/souls/[id]/prompt/route.ts +205 -0
- package/mission-control/src/app/api/souls/[id]/propagate/route.ts +146 -0
- package/mission-control/src/app/api/souls/route.ts +174 -0
- package/mission-control/src/app/api/tasks/[id]/handoff/route.ts +115 -0
- package/mission-control/src/app/api/tasks/[id]/route.ts +266 -0
- package/mission-control/src/app/api/tasks/[id]/tree/route.ts +94 -0
- package/mission-control/src/app/api/tasks/route.ts +253 -0
- package/mission-control/src/app/api/tts/route.ts +47 -0
- package/mission-control/src/app/api/workspace/files/route.ts +88 -0
- package/mission-control/src/app/api/workspace/read/route.ts +73 -0
- package/mission-control/src/app/burndown/page.tsx +309 -0
- package/mission-control/src/app/calendar/page.tsx +839 -0
- package/mission-control/src/app/favicon.ico +0 -0
- package/mission-control/src/app/globals.css +67 -0
- package/mission-control/src/app/graph/page.tsx +352 -0
- package/mission-control/src/app/layout.tsx +35 -0
- package/mission-control/src/app/live/page.tsx +232 -0
- package/mission-control/src/app/memory/page.tsx +154 -0
- package/mission-control/src/app/mesh/page.tsx +457 -0
- package/mission-control/src/app/obsidian/page.tsx +252 -0
- package/mission-control/src/app/page.tsx +70 -0
- package/mission-control/src/app/roadmap/page.tsx +1757 -0
- package/mission-control/src/app/settings/page.tsx +260 -0
- package/mission-control/src/app/souls/page.tsx +573 -0
- package/mission-control/src/components/board/activity-timeline.tsx +96 -0
- package/mission-control/src/components/board/daily-board.tsx +373 -0
- package/mission-control/src/components/board/kanban-board.tsx +364 -0
- package/mission-control/src/components/board/kanban-column.tsx +105 -0
- package/mission-control/src/components/board/live-stream.tsx +116 -0
- package/mission-control/src/components/board/skill-health-card.tsx +128 -0
- package/mission-control/src/components/board/status-banner.tsx +124 -0
- package/mission-control/src/components/board/task-card.tsx +454 -0
- package/mission-control/src/components/board/unified-task-dialog.tsx +1043 -0
- package/mission-control/src/components/layout/resizable-layout.tsx +68 -0
- package/mission-control/src/components/layout/sidebar.tsx +90 -0
- package/mission-control/src/components/live/audio-spectrum.tsx +106 -0
- package/mission-control/src/components/live/chat-bubble.tsx +52 -0
- package/mission-control/src/components/live/chat-input.tsx +92 -0
- package/mission-control/src/components/memory/doc-reader.tsx +172 -0
- package/mission-control/src/components/memory/memory-list.tsx +169 -0
- package/mission-control/src/components/memory/search-bar.tsx +67 -0
- package/mission-control/src/components/memory/search-results.tsx +149 -0
- package/mission-control/src/components/obsidian/backlinks-panel.tsx +52 -0
- package/mission-control/src/components/obsidian/file-tree.tsx +186 -0
- package/mission-control/src/components/obsidian/local-graph.tsx +107 -0
- package/mission-control/src/components/obsidian/obsidian-graph.tsx +192 -0
- package/mission-control/src/components/obsidian/obsidian-reader.tsx +246 -0
- package/mission-control/src/lib/activity.ts +29 -0
- package/mission-control/src/lib/config.ts +21 -0
- package/mission-control/src/lib/db/index.ts +429 -0
- package/mission-control/src/lib/db/schema.ts +218 -0
- package/mission-control/src/lib/gateway-notify.ts +113 -0
- package/mission-control/src/lib/hooks.ts +536 -0
- package/mission-control/src/lib/memory/categories.ts +125 -0
- package/mission-control/src/lib/memory/entities.ts +482 -0
- package/mission-control/src/lib/memory/extract.ts +369 -0
- package/mission-control/src/lib/memory/retrieval.ts +281 -0
- package/mission-control/src/lib/memory/wikilinks.ts +147 -0
- package/mission-control/src/lib/nats.ts +126 -0
- package/mission-control/src/lib/parsers/clawvault-doc.ts +98 -0
- package/mission-control/src/lib/parsers/daily-log.ts +73 -0
- package/mission-control/src/lib/parsers/memory-md.ts +81 -0
- package/mission-control/src/lib/parsers/task-markdown.ts +459 -0
- package/mission-control/src/lib/parsers/transcript.ts +209 -0
- package/mission-control/src/lib/scheduler.ts +394 -0
- package/mission-control/src/lib/speech/use-speech-pipeline.ts +176 -0
- package/mission-control/src/lib/sync/memory.ts +224 -0
- package/mission-control/src/lib/sync/tasks.ts +271 -0
- package/mission-control/src/lib/tts/edge.ts +31 -0
- package/mission-control/src/lib/tts/google.ts +78 -0
- package/mission-control/src/lib/tts/index.ts +39 -0
- package/mission-control/src/lib/tts/types.ts +18 -0
- package/mission-control/tsconfig.json +42 -0
- package/obsidian-vault/.obsidian/app.json +10 -0
- package/obsidian-vault/.obsidian/community-plugins.json +8 -0
- package/obsidian-vault/.obsidian/graph.json +40 -0
- package/obsidian-vault/.obsidian/plugins/obsidian-local-rest-api/main.js +58769 -0
- package/obsidian-vault/.obsidian/plugins/obsidian-local-rest-api/manifest.json +10 -0
- package/obsidian-vault/.obsidian/plugins/obsidian-local-rest-api/styles.css +47 -0
- package/obsidian-vault/00-meta/.gitkeep +0 -0
- package/obsidian-vault/01-architecture/.gitkeep +0 -0
- package/obsidian-vault/02-smart-contracts/.gitkeep +0 -0
- package/obsidian-vault/03-backend/.gitkeep +0 -0
- package/obsidian-vault/04-mobile/.gitkeep +0 -0
- package/obsidian-vault/05-ar-mapping/.gitkeep +0 -0
- package/obsidian-vault/06-3d-assets/.gitkeep +0 -0
- package/obsidian-vault/07-sound-music/.gitkeep +0 -0
- package/obsidian-vault/08-lore/.gitkeep +0 -0
- package/obsidian-vault/09-quests-playthrough/.gitkeep +0 -0
- package/obsidian-vault/10-economy/.gitkeep +0 -0
- package/obsidian-vault/11-nft-assets/.gitkeep +0 -0
- package/obsidian-vault/12-nft-mechanics/.gitkeep +0 -0
- package/obsidian-vault/13-dao-guild-social/.gitkeep +0 -0
- package/obsidian-vault/14-game-progression/.gitkeep +0 -0
- package/obsidian-vault/15-analytics/.gitkeep +0 -0
- package/obsidian-vault/16-security/.gitkeep +0 -0
- package/obsidian-vault/17-devops/.gitkeep +0 -0
- package/obsidian-vault/18-marketplace/.gitkeep +0 -0
- package/obsidian-vault/19-decisions/.gitkeep +0 -0
- package/obsidian-vault/20-business-strategy/.gitkeep +0 -0
- package/obsidian-vault/21-legal-regulatory/.gitkeep +0 -0
- package/obsidian-vault/nodes/.gitkeep +0 -0
- package/openclaw.env.example +17 -0
- package/package.json +45 -0
- package/services/launchd/ai.openclaw.gateway.plist +59 -0
- package/services/launchd/ai.openclaw.lane-watchdog.plist +32 -0
- package/services/launchd/ai.openclaw.log-rotate.plist +28 -0
- package/services/launchd/ai.openclaw.memory-daemon.plist +36 -0
- package/services/launchd/ai.openclaw.mesh-agent.plist +38 -0
- package/services/launchd/ai.openclaw.mesh-bridge.plist +36 -0
- package/services/launchd/ai.openclaw.mesh-deploy-listener.plist +33 -0
- package/services/launchd/ai.openclaw.mesh-health-publisher.plist +29 -0
- package/services/launchd/ai.openclaw.mesh-task-daemon.plist +36 -0
- package/services/launchd/ai.openclaw.mesh-tool-discord.plist +36 -0
- package/services/launchd/ai.openclaw.mission-control.plist +41 -0
- package/services/service-manifest.json +13 -0
- package/services/systemd/openclaw-gateway.service +21 -0
- package/services/systemd/openclaw-lane-watchdog.service +21 -0
- package/services/systemd/openclaw-log-rotate.service +13 -0
- package/services/systemd/openclaw-log-rotate.timer +9 -0
- package/services/systemd/openclaw-memory-daemon.service +21 -0
- package/services/systemd/openclaw-mesh-agent.service +19 -0
- package/services/systemd/openclaw-mesh-bridge.service +21 -0
- package/services/systemd/openclaw-mesh-deploy-listener.service +23 -0
- package/services/systemd/openclaw-mesh-health-publisher.service +21 -0
- package/services/systemd/openclaw-mesh-task-daemon.service +21 -0
- package/services/systemd/openclaw-mesh-tool-discord.service +21 -0
- package/services/systemd/openclaw-mission-control.service +22 -0
- package/skills/1password/.clawhub/origin.json +7 -0
- package/skills/1password/SKILL.md +63 -0
- package/skills/1password/references/cli-examples.md +29 -0
- package/skills/1password/references/get-started.md +17 -0
- package/skills/acquisition-channel-advisor/SKILL.md +643 -0
- package/skills/acquisition-channel-advisor/examples/conversation-flow.md +531 -0
- package/skills/agent-browser/.clawhub/origin.json +7 -0
- package/skills/agent-browser/CONTRIBUTING.md +63 -0
- package/skills/agent-browser/SKILL.md +338 -0
- package/skills/agentic-compass/.clawhub/origin.json +7 -0
- package/skills/agentic-compass/README.md +96 -0
- package/skills/agentic-compass/SKILL.md +112 -0
- package/skills/agentic-compass/references/README.md +5 -0
- package/skills/agentic-compass/scripts/agentic-compass.py +196 -0
- package/skills/arcane-dev-ops/SKILL.md +61 -0
- package/skills/arcane-dev-ops/references/checklist.md +22 -0
- package/skills/arcane-dev-ops/references/validation-cases.md +11 -0
- package/skills/arcane-dev-ops/scripts/prepush_check.sh +41 -0
- package/skills/auto-updater/.clawhub/origin.json +7 -0
- package/skills/auto-updater/SKILL.md +158 -0
- package/skills/auto-updater/references/agent-guide.md +152 -0
- package/skills/auto-updater/references/summary-examples.md +109 -0
- package/skills/business-health-diagnostic/SKILL.md +782 -0
- package/skills/byterover/.clawhub/origin.json +7 -0
- package/skills/byterover/SKILL.md +105 -0
- package/skills/byterover/TROUBLESHOOTING.md +50 -0
- package/skills/byterover/WORKFLOWS.md +229 -0
- package/skills/capability-evolver/.clawhub/origin.json +7 -0
- package/skills/capability-evolver/CONTRIBUTING.md +11 -0
- package/skills/capability-evolver/README.md +157 -0
- package/skills/capability-evolver/README.zh-CN.md +112 -0
- package/skills/capability-evolver/SKILL.md +93 -0
- package/skills/capability-evolver/assets/gep/capsules.json +5 -0
- package/skills/capability-evolver/assets/gep/genes.json +104 -0
- package/skills/capability-evolver/index.js +59 -0
- package/skills/capability-evolver/package.json +22 -0
- package/skills/capability-evolver/scripts/analyze_by_skill.js +121 -0
- package/skills/capability-evolver/scripts/build_public.js +350 -0
- package/skills/capability-evolver/scripts/export_history.js +98 -0
- package/skills/capability-evolver/scripts/extract_log.js +85 -0
- package/skills/capability-evolver/scripts/generate_history.js +75 -0
- package/skills/capability-evolver/scripts/human_report.js +147 -0
- package/skills/capability-evolver/scripts/publish_public.js +516 -0
- package/skills/capability-evolver/scripts/suggest_version.js +89 -0
- package/skills/capability-evolver/src/evolve.js +594 -0
- package/skills/capability-evolver/src/gep/assetStore.js +204 -0
- package/skills/capability-evolver/src/gep/candidates.js +134 -0
- package/skills/capability-evolver/src/gep/paths.js +23 -0
- package/skills/capability-evolver/src/gep/prompt.js +254 -0
- package/skills/capability-evolver/src/gep/selector.js +89 -0
- package/skills/capability-evolver/src/gep/signals.js +27 -0
- package/skills/cc-godmode/.clawhub/origin.json +7 -0
- package/skills/cc-godmode/CHANGELOG.md +66 -0
- package/skills/cc-godmode/README.md +293 -0
- package/skills/cc-godmode/SKILL.md +242 -0
- package/skills/cc-godmode/docs/AGENTS.md +332 -0
- package/skills/cc-godmode/docs/MIGRATION.md +206 -0
- package/skills/cc-godmode/docs/TROUBLESHOOTING.md +357 -0
- package/skills/cc-godmode/docs/WORKFLOWS.md +329 -0
- package/skills/cc-godmode/references/agents.md +433 -0
- package/skills/cc-godmode/scripts/build-skill.js +232 -0
- package/skills/clawdbot-filesystem/.clawhub/origin.json +7 -0
- package/skills/clawdbot-filesystem/LICENSE.md +21 -0
- package/skills/clawdbot-filesystem/README.md +322 -0
- package/skills/clawdbot-filesystem/SKILL.md +219 -0
- package/skills/clawdbot-filesystem/config.json +41 -0
- package/skills/clawdbot-filesystem/package.json +69 -0
- package/skills/clawdbot-security-check/.clawhub/origin.json +7 -0
- package/skills/clawdbot-security-check/README.md +168 -0
- package/skills/clawdbot-security-check/SKILL.md +145 -0
- package/skills/clawdbot-security-check/references/audit-checks.md +521 -0
- package/skills/clawdbot-security-check/skill.json +42 -0
- package/skills/clawddocs/.clawhub/origin.json +7 -0
- package/skills/clawddocs/SKILL.md +176 -0
- package/skills/clawddocs/package.json +9 -0
- package/skills/clawddocs/scripts/build-index.sh +17 -0
- package/skills/clawddocs/scripts/cache.sh +13 -0
- package/skills/clawddocs/scripts/fetch-doc.sh +7 -0
- package/skills/clawddocs/scripts/recent.sh +5 -0
- package/skills/clawddocs/scripts/search.sh +8 -0
- package/skills/clawddocs/scripts/sitemap.sh +23 -0
- package/skills/clawddocs/scripts/track-changes.sh +16 -0
- package/skills/clawddocs/snippets/common-configs.md +69 -0
- package/skills/clawguard/.clawhub/origin.json +7 -0
- package/skills/clawguard/SKILL.md +137 -0
- package/skills/company-research/SKILL.md +393 -0
- package/skills/company-research/examples/sample.md +164 -0
- package/skills/company-research/template.md +60 -0
- package/skills/crypto-price/.clawhub/origin.json +7 -0
- package/skills/crypto-price/ARCHITECTURE.md +437 -0
- package/skills/crypto-price/README.md +194 -0
- package/skills/crypto-price/SKILL.md +61 -0
- package/skills/crypto-price/requirements.txt +1 -0
- package/skills/crypto-price/scripts/get_price_chart.py +988 -0
- package/skills/customer-journey-map/SKILL.md +343 -0
- package/skills/customer-journey-map/examples/sample.md +33 -0
- package/skills/customer-journey-map/template.md +28 -0
- package/skills/customer-journey-mapping-workshop/SKILL.md +522 -0
- package/skills/deep-research/.clawhub/origin.json +7 -0
- package/skills/deep-research/SKILL.md +93 -0
- package/skills/deep-research/rules/logic.md +32 -0
- package/skills/discord-telegram-triage/SKILL.md +59 -0
- package/skills/discord-telegram-triage/references/discord-runbook.md +28 -0
- package/skills/discord-telegram-triage/references/validation-cases.md +11 -0
- package/skills/discord-telegram-triage/scripts/triage_snapshot.sh +23 -0
- package/skills/discovery-interview-prep/SKILL.md +408 -0
- package/skills/discovery-process/SKILL.md +503 -0
- package/skills/discovery-process/examples/sample.md +60 -0
- package/skills/discovery-process/template.md +39 -0
- package/skills/dist/arcane-dev-ops.skill +0 -0
- package/skills/dist/discord-telegram-triage.skill +0 -0
- package/skills/dist/founder-brief-summarizer.skill +0 -0
- package/skills/epic-breakdown-advisor/SKILL.md +664 -0
- package/skills/epic-hypothesis/SKILL.md +285 -0
- package/skills/epic-hypothesis/examples/sample.md +104 -0
- package/skills/epic-hypothesis/template.md +30 -0
- package/skills/excel/.clawhub/origin.json +7 -0
- package/skills/excel/SKILL.md +332 -0
- package/skills/excel/scripts/excel.py +1120 -0
- package/skills/fast-browser-use/.clawhub/origin.json +7 -0
- package/skills/fast-browser-use/CODEBUDDY.md +142 -0
- package/skills/fast-browser-use/Cargo.toml +77 -0
- package/skills/fast-browser-use/README.md +62 -0
- package/skills/fast-browser-use/SKILL.md +217 -0
- package/skills/fast-browser-use/package-lock.json +28 -0
- package/skills/fast-browser-use/package.json +8 -0
- package/skills/fast-browser-use/rustfmt.toml +10 -0
- package/skills/fast-browser-use/src/bin/cli.rs +373 -0
- package/skills/fast-browser-use/src/bin/mcp_server.rs +203 -0
- package/skills/fast-browser-use/src/browser/config.rs +136 -0
- package/skills/fast-browser-use/src/browser/debug.rs +16 -0
- package/skills/fast-browser-use/src/browser/mod.rs +61 -0
- package/skills/fast-browser-use/src/browser/session.rs +478 -0
- package/skills/fast-browser-use/src/dom/element.rs +442 -0
- package/skills/fast-browser-use/src/dom/extract_dom.js +849 -0
- package/skills/fast-browser-use/src/dom/mod.rs +14 -0
- package/skills/fast-browser-use/src/dom/tree.rs +296 -0
- package/skills/fast-browser-use/src/dom/yaml.rs +149 -0
- package/skills/fast-browser-use/src/error.rs +115 -0
- package/skills/fast-browser-use/src/lib.rs +17 -0
- package/skills/fast-browser-use/src/mcp/handler.rs +63 -0
- package/skills/fast-browser-use/src/mcp/mod.rs +81 -0
- package/skills/fast-browser-use/src/tools/Readability.min.js +1480 -0
- package/skills/fast-browser-use/src/tools/annotate.rs +165 -0
- package/skills/fast-browser-use/src/tools/click.rs +84 -0
- package/skills/fast-browser-use/src/tools/close.rs +35 -0
- package/skills/fast-browser-use/src/tools/close_tab.rs +45 -0
- package/skills/fast-browser-use/src/tools/convert_to_markdown.js +117 -0
- package/skills/fast-browser-use/src/tools/cookies.rs +58 -0
- package/skills/fast-browser-use/src/tools/debug.rs +44 -0
- package/skills/fast-browser-use/src/tools/evaluate.rs +40 -0
- package/skills/fast-browser-use/src/tools/extract.rs +66 -0
- package/skills/fast-browser-use/src/tools/go_back.rs +35 -0
- package/skills/fast-browser-use/src/tools/go_forward.rs +35 -0
- package/skills/fast-browser-use/src/tools/hover.js +33 -0
- package/skills/fast-browser-use/src/tools/hover.rs +97 -0
- package/skills/fast-browser-use/src/tools/html_to_markdown.rs +99 -0
- package/skills/fast-browser-use/src/tools/input.rs +93 -0
- package/skills/fast-browser-use/src/tools/local_storage.rs +159 -0
- package/skills/fast-browser-use/src/tools/markdown.rs +181 -0
- package/skills/fast-browser-use/src/tools/mod.rs +326 -0
- package/skills/fast-browser-use/src/tools/navigate.rs +55 -0
- package/skills/fast-browser-use/src/tools/new_tab.rs +60 -0
- package/skills/fast-browser-use/src/tools/press_key.rs +78 -0
- package/skills/fast-browser-use/src/tools/read_links.rs +59 -0
- package/skills/fast-browser-use/src/tools/readability_script.rs +8 -0
- package/skills/fast-browser-use/src/tools/screenshot.rs +47 -0
- package/skills/fast-browser-use/src/tools/scroll.js +22 -0
- package/skills/fast-browser-use/src/tools/scroll.rs +95 -0
- package/skills/fast-browser-use/src/tools/select.js +23 -0
- package/skills/fast-browser-use/src/tools/select.rs +129 -0
- package/skills/fast-browser-use/src/tools/sitemap.rs +426 -0
- package/skills/fast-browser-use/src/tools/snapshot.rs +324 -0
- package/skills/fast-browser-use/src/tools/switch_tab.rs +69 -0
- package/skills/fast-browser-use/src/tools/tab_list.rs +76 -0
- package/skills/fast-browser-use/src/tools/utils.rs +92 -0
- package/skills/fast-browser-use/src/tools/wait.rs +53 -0
- package/skills/fast-browser-use/test_auth.json +3 -0
- package/skills/fast-browser-use/test_state.json +6 -0
- package/skills/fast-browser-use/tests/browser_tools_integration.rs +233 -0
- package/skills/fast-browser-use/tests/cli_recipes_integration.rs +112 -0
- package/skills/fast-browser-use/tests/cookies_integration.rs +56 -0
- package/skills/fast-browser-use/tests/debug_integration.rs +83 -0
- package/skills/fast-browser-use/tests/dom_integration.rs +170 -0
- package/skills/fast-browser-use/tests/local_storage_integration.rs +75 -0
- package/skills/fast-browser-use/tests/markdown_integration.rs +448 -0
- package/skills/fast-browser-use/tests/navigation_integration.rs +241 -0
- package/skills/fast-browser-use/tests/sitemap_integration.rs +326 -0
- package/skills/fast-browser-use/tests/tab_management_integration.rs +300 -0
- package/skills/feature-investment-advisor/SKILL.md +639 -0
- package/skills/feature-investment-advisor/examples/conversation-flow.md +538 -0
- package/skills/finance-based-pricing-advisor/SKILL.md +763 -0
- package/skills/finance-metrics-quickref/SKILL.md +309 -0
- package/skills/find-skills/.clawhub/origin.json +7 -0
- package/skills/find-skills/SKILL.md +143 -0
- package/skills/flavor-text-writer/SKILL.md +27 -0
- package/skills/founder-brief-summarizer/SKILL.md +52 -0
- package/skills/founder-brief-summarizer/references/response-templates.md +15 -0
- package/skills/founder-brief-summarizer/references/validation-cases.md +11 -0
- package/skills/founder-brief-summarizer/scripts/brief_template.sh +28 -0
- package/skills/frontend-design/.clawhub/origin.json +7 -0
- package/skills/frontend-design/LICENSE.txt +190 -0
- package/skills/frontend-design/SKILL.md +53 -0
- package/skills/gemini/.clawhub/origin.json +7 -0
- package/skills/gemini/SKILL.md +33 -0
- package/skills/gemini-deep-research/.clawhub/origin.json +7 -0
- package/skills/gemini-deep-research/SKILL.md +78 -0
- package/skills/gemini-deep-research/scripts/deep_research.py +176 -0
- package/skills/git-essentials/.clawhub/origin.json +7 -0
- package/skills/git-essentials/SKILL.md +239 -0
- package/skills/git-essentials/references/advanced.md +211 -0
- package/skills/github/.clawhub/origin.json +7 -0
- package/skills/github/SKILL.md +57 -0
- package/skills/google-drive/.clawhub/origin.json +7 -0
- package/skills/google-drive/LICENSE.txt +21 -0
- package/skills/google-drive/SKILL.md +320 -0
- package/skills/growth-loop/SKILL.md +270 -0
- package/skills/growth-loop/_meta.json +9 -0
- package/skills/growth-loop/references/diagnosis-framework.md +84 -0
- package/skills/growth-loop/references/platform-benchmarks.md +79 -0
- package/skills/growth-loop/scripts/init-campaign.sh +274 -0
- package/skills/humanize-ai-text/.clawhub/origin.json +7 -0
- package/skills/humanize-ai-text/SKILL.md +192 -0
- package/skills/humanize-ai-text/scripts/compare.py +58 -0
- package/skills/humanize-ai-text/scripts/detect.py +160 -0
- package/skills/humanize-ai-text/scripts/patterns.json +191 -0
- package/skills/humanize-ai-text/scripts/transform.py +127 -0
- package/skills/humanizer/.clawhub/origin.json +7 -0
- package/skills/humanizer/README.md +82 -0
- package/skills/humanizer/SKILL.md +443 -0
- package/skills/jobs-to-be-done/SKILL.md +378 -0
- package/skills/jobs-to-be-done/examples/sample.md +80 -0
- package/skills/jobs-to-be-done/template.md +65 -0
- package/skills/lean-ux-canvas/SKILL.md +561 -0
- package/skills/lean-ux-canvas/examples/sample.md +88 -0
- package/skills/lean-ux-canvas/template.md +32 -0
- package/skills/markdown-formatter/.clawhub/origin.json +7 -0
- package/skills/markdown-formatter/README.md +137 -0
- package/skills/markdown-formatter/SKILL.md +369 -0
- package/skills/markdown-formatter/config.json +20 -0
- package/skills/markdown-formatter/index.js +439 -0
- package/skills/markdown-formatter/package.json +23 -0
- package/skills/markdown-formatter/test.js +23 -0
- package/skills/marketing-mode/.clawhub/origin.json +7 -0
- package/skills/marketing-mode/README.md +49 -0
- package/skills/marketing-mode/SKILL.md +703 -0
- package/skills/marketing-mode/mode-prompt.md +39 -0
- package/skills/marketing-mode/skill.json +51 -0
- package/skills/memory-hygiene/.clawhub/origin.json +7 -0
- package/skills/memory-hygiene/SKILL.md +91 -0
- package/skills/memory-setup/.clawhub/origin.json +7 -0
- package/skills/memory-setup/SKILL.md +180 -0
- package/skills/memorylayer/.clawhub/origin.json +7 -0
- package/skills/memorylayer/README.md +197 -0
- package/skills/memorylayer/SKILL.md +227 -0
- package/skills/memorylayer/examples/agent-integration.js +145 -0
- package/skills/memorylayer/examples/basic-usage.js +87 -0
- package/skills/memorylayer/examples/token-savings-demo.js +183 -0
- package/skills/memorylayer/index.js +115 -0
- package/skills/memorylayer/package-lock.json +295 -0
- package/skills/memorylayer/package.json +27 -0
- package/skills/memorylayer/python/memorylayer_skill.py +230 -0
- package/skills/memorylayer/python/requirements.txt +7 -0
- package/skills/mesh/SKILL.md +184 -0
- package/skills/model-usage/.clawhub/origin.json +7 -0
- package/skills/model-usage/SKILL.md +54 -0
- package/skills/model-usage/references/codexbar-cli.md +28 -0
- package/skills/model-usage/scripts/model_usage.py +310 -0
- package/skills/moltbook-interact/.clawhub/origin.json +7 -0
- package/skills/moltbook-interact/INSTALL.md +139 -0
- package/skills/moltbook-interact/README.md +198 -0
- package/skills/moltbook-interact/SKILL.md +72 -0
- package/skills/moltbook-interact/references/api.md +106 -0
- package/skills/moltbook-interact/scripts/moltbook.sh +142 -0
- package/skills/moltbook-registry/.clawhub/origin.json +7 -0
- package/skills/moltbook-registry/README.md +26 -0
- package/skills/moltbook-registry/SKILL.md +82 -0
- package/skills/moltbook-registry/index.js +180 -0
- package/skills/moltbook-registry/package.json +11 -0
- package/skills/mythril-scanner/SKILL.md +27 -0
- package/skills/n8n/.clawhub/origin.json +7 -0
- package/skills/n8n/SKILL.md +141 -0
- package/skills/n8n/references/api.md +156 -0
- package/skills/n8n/scripts/n8n_api.py +158 -0
- package/skills/n8n-workflow-automation/.clawhub/origin.json +7 -0
- package/skills/n8n-workflow-automation/SKILL.md +103 -0
- package/skills/n8n-workflow-automation/assets/runbook-template.md +32 -0
- package/skills/narrative-designer/SKILL.md +27 -0
- package/skills/ontology/.clawhub/origin.json +7 -0
- package/skills/ontology/SKILL.md +236 -0
- package/skills/ontology/references/queries.md +211 -0
- package/skills/ontology/references/schema.md +322 -0
- package/skills/ontology/scripts/ontology.py +374 -0
- package/skills/openai-image-gen/.clawhub/origin.json +7 -0
- package/skills/openai-image-gen/SKILL.md +45 -0
- package/skills/openai-image-gen/scripts/gen.py +227 -0
- package/skills/openclaw-agent-optimize/.clawhub/origin.json +7 -0
- package/skills/openclaw-agent-optimize/SKILL.md +33 -0
- package/skills/openclaw-agent-optimize/references/agent-orchestration.md +20 -0
- package/skills/openclaw-agent-optimize/references/context-management.md +15 -0
- package/skills/openclaw-agent-optimize/references/continuous-learning.md +14 -0
- package/skills/openclaw-agent-optimize/references/cron-optimization.md +16 -0
- package/skills/openclaw-agent-optimize/references/memory-patterns.md +14 -0
- package/skills/openclaw-agent-optimize/references/model-selection.md +18 -0
- package/skills/openclaw-skill-scanner/.clawhub/origin.json +7 -0
- package/skills/openclaw-skill-scanner/SKILL.md +88 -0
- package/skills/openclaw-skill-scanner/install-hook.sh +294 -0
- package/skills/openclaw-skill-scanner/report-template.md +53 -0
- package/skills/openclaw-skill-scanner/scanner.py +929 -0
- package/skills/openclaw-skill-scanner/whitelist.json +18 -0
- package/skills/opportunity-solution-tree/SKILL.md +428 -0
- package/skills/opportunity-solution-tree/examples/sample.md +104 -0
- package/skills/opportunity-solution-tree/template.md +33 -0
- package/skills/pdf/.clawhub/origin.json +7 -0
- package/skills/pdf/SKILL.md +304 -0
- package/skills/pestel-analysis/SKILL.md +384 -0
- package/skills/pestel-analysis/examples/sample.md +143 -0
- package/skills/pestel-analysis/template.md +53 -0
- package/skills/pol-probe/SKILL.md +217 -0
- package/skills/pol-probe/examples/sample.md +136 -0
- package/skills/pol-probe/template.md +59 -0
- package/skills/pol-probe-advisor/SKILL.md +492 -0
- package/skills/positioning-statement/SKILL.md +229 -0
- package/skills/positioning-statement/examples/sample.md +51 -0
- package/skills/positioning-statement/template.md +25 -0
- package/skills/positioning-workshop/SKILL.md +424 -0
- package/skills/prd-development/SKILL.md +654 -0
- package/skills/prd-development/examples/sample.md +43 -0
- package/skills/prd-development/template.md +55 -0
- package/skills/press-release/SKILL.md +277 -0
- package/skills/press-release/examples/sample.md +73 -0
- package/skills/press-release/template.md +39 -0
- package/skills/prioritization-advisor/SKILL.md +451 -0
- package/skills/proactive-messages/.clawhub/origin.json +7 -0
- package/skills/proactive-messages/SKILL.md +91 -0
- package/skills/problem-framing-canvas/SKILL.md +466 -0
- package/skills/problem-framing-canvas/examples/sample.md +58 -0
- package/skills/problem-framing-canvas/template.md +22 -0
- package/skills/problem-statement/SKILL.md +255 -0
- package/skills/problem-statement/examples/sample.md +82 -0
- package/skills/problem-statement/template.md +37 -0
- package/skills/product-strategy-session/SKILL.md +434 -0
- package/skills/product-strategy-session/examples/sample.md +67 -0
- package/skills/product-strategy-session/template.md +38 -0
- package/skills/prompt-guard/.clawhub/origin.json +7 -0
- package/skills/prompt-guard/ARCHITECTURE.md +364 -0
- package/skills/prompt-guard/CHANGELOG.md +200 -0
- package/skills/prompt-guard/README.md +215 -0
- package/skills/prompt-guard/SECURITY.md +66 -0
- package/skills/prompt-guard/SKILL.md +174 -0
- package/skills/prompt-guard/blog/how-i-secured-my-ai-agent.md +185 -0
- package/skills/prompt-guard/config.example.yaml +56 -0
- package/skills/prompt-guard/references/detection-patterns.md +298 -0
- package/skills/prompt-guard/requirements.txt +1 -0
- package/skills/prompt-guard/scripts/analyze_log.py +224 -0
- package/skills/prompt-guard/scripts/audit.py +344 -0
- package/skills/prompt-guard/scripts/detect.py +1587 -0
- package/skills/prompt-guard/scripts/hivefence.py +345 -0
- package/skills/proto-persona/SKILL.md +336 -0
- package/skills/proto-persona/examples/sample.md +97 -0
- package/skills/proto-persona/template.md +45 -0
- package/skills/recommendation-canvas/SKILL.md +382 -0
- package/skills/recommendation-canvas/examples/sample.md +94 -0
- package/skills/recommendation-canvas/template.md +86 -0
- package/skills/refactor-suggest/.clawhub/origin.json +7 -0
- package/skills/refactor-suggest/SKILL.md +94 -0
- package/skills/roadmap-planning/SKILL.md +506 -0
- package/skills/roadmap-planning/examples/sample.md +62 -0
- package/skills/roadmap-planning/template.md +30 -0
- package/skills/saas-economics-efficiency-metrics/SKILL.md +694 -0
- package/skills/saas-economics-efficiency-metrics/examples/cash-trap.md +365 -0
- package/skills/saas-economics-efficiency-metrics/examples/healthy-unit-economics.md +279 -0
- package/skills/saas-economics-efficiency-metrics/template.md +263 -0
- package/skills/saas-revenue-growth-metrics/SKILL.md +629 -0
- package/skills/saas-revenue-growth-metrics/examples/healthy-saas.md +131 -0
- package/skills/saas-revenue-growth-metrics/examples/warning-signs.md +229 -0
- package/skills/saas-revenue-growth-metrics/template.md +192 -0
- package/skills/save-money/.clawhub/origin.json +7 -0
- package/skills/save-money/SKILL.md +173 -0
- package/skills/scripts/golden_skills_v3.sh +32 -0
- package/skills/search/.clawhub/origin.json +7 -0
- package/skills/search/SKILL.md +18 -0
- package/skills/search/skill.json +1 -0
- package/skills/second-brain/.clawhub/origin.json +7 -0
- package/skills/second-brain/SKILL.md +278 -0
- package/skills/second-brain/scripts/ensue-api.sh +37 -0
- package/skills/self-improving-agent/.clawhub/origin.json +7 -0
- package/skills/self-improving-agent/.learnings/ERRORS.md +5 -0
- package/skills/self-improving-agent/.learnings/FEATURE_REQUESTS.md +5 -0
- package/skills/self-improving-agent/.learnings/LEARNINGS.md +5 -0
- package/skills/self-improving-agent/SKILL.md +130 -0
- package/skills/self-improving-agent/assets/LEARNINGS.md +45 -0
- package/skills/self-improving-agent/assets/SKILL-TEMPLATE.md +177 -0
- package/skills/self-improving-agent/hooks/openclaw/HOOK.md +23 -0
- package/skills/self-improving-agent/hooks/openclaw/handler.js +56 -0
- package/skills/self-improving-agent/hooks/openclaw/handler.ts +62 -0
- package/skills/self-improving-agent/references/examples.md +374 -0
- package/skills/self-improving-agent/references/hooks-setup.md +223 -0
- package/skills/self-improving-agent/references/openclaw-integration.md +248 -0
- package/skills/self-improving-agent/references/templates.md +480 -0
- package/skills/self-improving-agent/scripts/activator.sh +20 -0
- package/skills/self-improving-agent/scripts/error-detector.sh +55 -0
- package/skills/self-improving-agent/scripts/extract-skill.sh +203 -0
- package/skills/self-improving-agent-1-0-2/.clawhub/origin.json +7 -0
- package/skills/self-improving-agent-1-0-2/SKILL.md +562 -0
- package/skills/self-improving-agent-1-0-2/assets/LEARNINGS.md +45 -0
- package/skills/self-improving-agent-1-0-2/assets/SKILL-TEMPLATE.md +182 -0
- package/skills/self-improving-agent-1-0-2/references/clawdbot-integration.md +311 -0
- package/skills/self-improving-agent-1-0-2/references/examples.md +374 -0
- package/skills/self-improving-agent-1-0-2/references/hooks-setup.md +223 -0
- package/skills/self-improving-agent-1-0-2/scripts/activator.sh +20 -0
- package/skills/self-improving-agent-1-0-2/scripts/error-detector.sh +55 -0
- package/skills/self-improving-agent-1-0-2/scripts/extract-skill.sh +203 -0
- package/skills/self-love-confidence/.clawhub/origin.json +7 -0
- package/skills/self-love-confidence/SKILL.md +79 -0
- package/skills/self-reflection/.clawhub/origin.json +7 -0
- package/skills/self-reflection/README.md +292 -0
- package/skills/self-reflection/SKILL.md +110 -0
- package/skills/self-reflection/self-reflection.example.json +6 -0
- package/skills/slither-analyzer/SKILL.md +27 -0
- package/skills/solidity-audit/SKILL.md +27 -0
- package/skills/soulcraft/.clawhub/origin.json +7 -0
- package/skills/soulcraft/README.md +123 -0
- package/skills/soulcraft/SKILL.md +340 -0
- package/skills/soulcraft/references/question-bank.md +154 -0
- package/skills/soulcraft/references/soul-examples.md +207 -0
- package/skills/soulcraft/research/RESEARCH_REPORT.md +317 -0
- package/skills/spotify-player/.clawhub/origin.json +7 -0
- package/skills/spotify-player/SKILL.md +44 -0
- package/skills/storyboard/SKILL.md +259 -0
- package/skills/storyboard/examples/sample.md +71 -0
- package/skills/storyboard/template.md +41 -0
- package/skills/summarize/.clawhub/origin.json +7 -0
- package/skills/summarize/SKILL.md +59 -0
- package/skills/superdesign/.clawhub/origin.json +7 -0
- package/skills/superdesign/SKILL.md +224 -0
- package/skills/tam-sam-som-calculator/SKILL.md +399 -0
- package/skills/tam-sam-som-calculator/examples/sample.md +142 -0
- package/skills/tam-sam-som-calculator/scripts/market-sizing.py +95 -0
- package/skills/tam-sam-som-calculator/template.md +35 -0
- package/skills/tavily-search/.clawhub/origin.json +7 -0
- package/skills/tavily-search/SKILL.md +49 -0
- package/skills/tavily-search/scripts/extract.mjs +59 -0
- package/skills/tavily-search/scripts/search.mjs +101 -0
- package/skills/twitter/SKILL.md +74 -0
- package/skills/twitter/_meta.json +9 -0
- package/skills/twitter/references/validation-cases.md +53 -0
- package/skills/twitter/scripts/twitter.sh +421 -0
- package/skills/ui-ux-pro-max/.clawhub/origin.json +7 -0
- package/skills/ui-ux-pro-max/SKILL.md +54 -0
- package/skills/ui-ux-pro-max/assets/data/charts.csv +26 -0
- package/skills/ui-ux-pro-max/assets/data/colors.csv +97 -0
- package/skills/ui-ux-pro-max/assets/data/icons.csv +101 -0
- package/skills/ui-ux-pro-max/assets/data/landing.csv +31 -0
- package/skills/ui-ux-pro-max/assets/data/products.csv +97 -0
- package/skills/ui-ux-pro-max/assets/data/react-performance.csv +45 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/astro.csv +54 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/flutter.csv +53 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/html-tailwind.csv +56 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/jetpack-compose.csv +53 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/nextjs.csv +53 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/nuxt-ui.csv +51 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/nuxtjs.csv +59 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/react-native.csv +52 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/react.csv +54 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/shadcn.csv +61 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/svelte.csv +54 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/swiftui.csv +51 -0
- package/skills/ui-ux-pro-max/assets/data/stacks/vue.csv +50 -0
- package/skills/ui-ux-pro-max/assets/data/styles.csv +68 -0
- package/skills/ui-ux-pro-max/assets/data/typography.csv +58 -0
- package/skills/ui-ux-pro-max/assets/data/ui-reasoning.csv +101 -0
- package/skills/ui-ux-pro-max/assets/data/ux-guidelines.csv +100 -0
- package/skills/ui-ux-pro-max/assets/data/web-interface.csv +31 -0
- package/skills/ui-ux-pro-max/references/upstream-README.md +488 -0
- package/skills/ui-ux-pro-max/references/upstream-skill-content.md +288 -0
- package/skills/ui-ux-pro-max/scripts/__init__.py +0 -0
- package/skills/ui-ux-pro-max/scripts/core.py +253 -0
- package/skills/ui-ux-pro-max/scripts/design_system.py +1071 -0
- package/skills/ui-ux-pro-max/scripts/search.py +111 -0
- package/skills/user-story/SKILL.md +272 -0
- package/skills/user-story/examples/sample.md +110 -0
- package/skills/user-story/scripts/user-story-template.py +65 -0
- package/skills/user-story/template.md +32 -0
- package/skills/user-story-mapping/SKILL.md +296 -0
- package/skills/user-story-mapping/examples/sample.md +77 -0
- package/skills/user-story-mapping/template.md +41 -0
- package/skills/user-story-mapping-workshop/SKILL.md +485 -0
- package/skills/user-story-mapping-workshop/template.md +28 -0
- package/skills/user-story-splitting/SKILL.md +313 -0
- package/skills/user-story-splitting/examples/sample.md +147 -0
- package/skills/user-story-splitting/template.md +37 -0
- package/skills/wacli/.clawhub/origin.json +7 -0
- package/skills/wacli/SKILL.md +53 -0
- package/skills/web-search/.clawhub/origin.json +7 -0
- package/skills/web-search/SKILL.md +151 -0
- package/skills/web-search/references/api-details.md +207 -0
- package/skills/web-search/scripts/search.py +576 -0
- package/skills/workshop-facilitation/SKILL.md +88 -0
- package/skills/world-builder/SKILL.md +27 -0
- package/souls/blockchain-auditor/PRINCIPLES.md +75 -0
- package/souls/blockchain-auditor/SOUL.md +56 -0
- package/souls/blockchain-auditor/capabilities.json +33 -0
- package/souls/blockchain-auditor/evolution/capsules.json +4 -0
- package/souls/blockchain-auditor/evolution/events.jsonl +1 -0
- package/souls/blockchain-auditor/evolution/genes.json +62 -0
- package/souls/daedalus/PRINCIPLES.md +78 -0
- package/souls/daedalus/SOUL.md +48 -0
- package/souls/daedalus/capabilities.json +46 -0
- package/souls/identity-architect/PRINCIPLES.md +83 -0
- package/souls/identity-architect/SOUL.md +66 -0
- package/souls/identity-architect/capabilities.json +38 -0
- package/souls/identity-architect/evolution/capsules.json +4 -0
- package/souls/identity-architect/evolution/events.jsonl +0 -0
- package/souls/identity-architect/evolution/genes.json +4 -0
- package/souls/infra-ops/PRINCIPLES.md +77 -0
- package/souls/infra-ops/SOUL.md +56 -0
- package/souls/infra-ops/capabilities.json +33 -0
- package/souls/infra-ops/evolution/capsules.json +4 -0
- package/souls/infra-ops/evolution/events.jsonl +0 -0
- package/souls/infra-ops/evolution/genes.json +4 -0
- package/souls/lore-writer/PRINCIPLES.md +74 -0
- package/souls/lore-writer/SOUL.md +54 -0
- package/souls/lore-writer/capabilities.json +37 -0
- package/souls/lore-writer/evolution/capsules.json +4 -0
- package/souls/lore-writer/evolution/events.jsonl +0 -0
- package/souls/lore-writer/evolution/genes.json +4 -0
- package/souls/qa-evidence/PRINCIPLES.md +97 -0
- package/souls/qa-evidence/SOUL.md +66 -0
- package/souls/qa-evidence/capabilities.json +32 -0
- package/souls/qa-evidence/evolution/capsules.json +4 -0
- package/souls/qa-evidence/evolution/events.jsonl +0 -0
- package/souls/qa-evidence/evolution/genes.json +4 -0
- package/souls/registry.json +211 -0
- package/souls/sync-registry.js +65 -0
- package/uninstall.sh +102 -0
- package/workspace-bin/auto-checkpoint +60 -0
- package/workspace-bin/clawvault-access-control +65 -0
- package/workspace-bin/clawvault-local +28 -0
- package/workspace-bin/compile-boot +494 -0
- package/workspace-bin/daily-log-writer.mjs +251 -0
- package/workspace-bin/evolve +540 -0
- package/workspace-bin/fitness_score.py +395 -0
- package/workspace-bin/hooks/pre-commit +80 -0
- package/workspace-bin/install-daemon +299 -0
- package/workspace-bin/lane-watchdog.js +232 -0
- package/workspace-bin/lib/__init__.py +0 -0
- package/workspace-bin/lib/frontmatter.py +114 -0
- package/workspace-bin/memory-daemon.mjs +879 -0
- package/workspace-bin/memory-maintenance.mjs +531 -0
- package/workspace-bin/mesh-bridge.mjs +154 -0
- package/workspace-bin/multi-review +130 -0
- package/workspace-bin/obsidian +125 -0
- package/workspace-bin/obsidian-sync.mjs +888 -0
- package/workspace-bin/openclaw-register-source +102 -0
- package/workspace-bin/proactive-scan +147 -0
- package/workspace-bin/quality-gate +175 -0
- package/workspace-bin/screenshot +96 -0
- package/workspace-bin/session-recap +453 -0
- package/workspace-bin/skill-audit +494 -0
- package/workspace-bin/skill-quality-check +134 -0
- package/workspace-bin/skill-routing-eval +599 -0
- package/workspace-bin/soul-prompt +251 -0
- package/workspace-bin/subagent-audit.mjs +267 -0
- package/workspace-bin/test-multi-soul-workflow +130 -0
- package/workspace-bin/trust-registry +465 -0
- package/workspace-docs/AGENTS.md +201 -0
- package/workspace-docs/CLAUDE.md +64 -0
- package/workspace-docs/PRINCIPLES.md +81 -0
- package/workspace-docs/SOUL.md +48 -0
|
@@ -0,0 +1,879 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* memory-daemon.mjs — OpenClaw platform-level memory lifecycle daemon (v2)
|
|
4
|
+
*
|
|
5
|
+
* Long-running Node.js process that detects activity from ANY frontend
|
|
6
|
+
* by polling JSONL transcript mtimes. No touchfiles. No hooks required.
|
|
7
|
+
*
|
|
8
|
+
* Session lifecycle: ENDED → BOOT → ACTIVE → IDLE → ENDED
|
|
9
|
+
*
|
|
10
|
+
* Phases:
|
|
11
|
+
* 0. Session-start bootstrap (once per new session)
|
|
12
|
+
* 1. Status sync (every tick when active, ~5ms)
|
|
13
|
+
* 2. Throttled background work (recap 10min, maintenance 30min,
|
|
14
|
+
* obsidian-sync 30min, trust-health 30min)
|
|
15
|
+
*
|
|
16
|
+
* Install: bin/install-daemon (detects OS, sets up launchd/systemd/pm2)
|
|
17
|
+
* Manual: node bin/memory-daemon.mjs [--test] [--verbose]
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { fileURLToPath } from 'url';
|
|
21
|
+
import fs from 'fs';
|
|
22
|
+
import path from 'path';
|
|
23
|
+
import os from 'os';
|
|
24
|
+
import { execFile, spawn } from 'child_process';
|
|
25
|
+
import { promisify } from 'util';
|
|
26
|
+
|
|
27
|
+
const execFileAsync = promisify(execFile);
|
|
28
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
29
|
+
const __dirname = path.dirname(__filename);
|
|
30
|
+
|
|
31
|
+
// ============================================================
|
|
32
|
+
// CONFIGURATION
|
|
33
|
+
// ============================================================
|
|
34
|
+
|
|
35
|
+
const WORKSPACE = process.env.OPENCLAW_WORKSPACE || path.dirname(__dirname);
|
|
36
|
+
const HOME = os.homedir();
|
|
37
|
+
const CONFIG_PATH = path.join(HOME, '.openclaw/config/daemon.json');
|
|
38
|
+
const TRANSCRIPT_REGISTRY = path.join(HOME, '.openclaw/config/transcript-sources.json');
|
|
39
|
+
|
|
40
|
+
function loadConfig() {
|
|
41
|
+
const defaults = {
|
|
42
|
+
nodeId: 'daedalus',
|
|
43
|
+
workspace: WORKSPACE,
|
|
44
|
+
timezone: 'America/Montreal',
|
|
45
|
+
intervals: {
|
|
46
|
+
pollMs: 30000,
|
|
47
|
+
activityWindowMs: 900000, // 15 min
|
|
48
|
+
activeThresholdMs: 300000, // 5 min
|
|
49
|
+
idleThresholdMs: 900000, // 15 min
|
|
50
|
+
sessionRecapMs: 600000, // 10 min
|
|
51
|
+
maintenanceMs: 1800000, // 30 min
|
|
52
|
+
obsidianSyncMs: 1800000, // 30 min
|
|
53
|
+
},
|
|
54
|
+
clawvaultBin: 'bin/clawvault-local',
|
|
55
|
+
obsidianVault: 'projects/arcane-vault',
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
if (fs.existsSync(CONFIG_PATH)) {
|
|
59
|
+
try {
|
|
60
|
+
const loaded = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf-8'));
|
|
61
|
+
return {
|
|
62
|
+
...defaults,
|
|
63
|
+
...loaded,
|
|
64
|
+
intervals: { ...defaults.intervals, ...loaded.intervals },
|
|
65
|
+
};
|
|
66
|
+
} catch { /* use defaults */ }
|
|
67
|
+
}
|
|
68
|
+
return defaults;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function resolvePath(p) {
|
|
72
|
+
if (p.startsWith('~')) return path.join(HOME, p.slice(1));
|
|
73
|
+
return p;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ============================================================
|
|
77
|
+
// LOGGING
|
|
78
|
+
// ============================================================
|
|
79
|
+
|
|
80
|
+
const STATE_DIR = path.join(WORKSPACE, '.tmp');
|
|
81
|
+
const LOG_FILE = path.join(STATE_DIR, 'memory-daemon.log');
|
|
82
|
+
const VERBOSE = process.argv.includes('--verbose');
|
|
83
|
+
const TEST_MODE = process.argv.includes('--test');
|
|
84
|
+
|
|
85
|
+
function ensureDirs() {
|
|
86
|
+
fs.mkdirSync(STATE_DIR, { recursive: true });
|
|
87
|
+
fs.mkdirSync(path.join(STATE_DIR, 'active-sessions'), { recursive: true });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function timestamp() {
|
|
91
|
+
return new Date().toLocaleString('en-CA', {
|
|
92
|
+
timeZone: 'America/Montreal',
|
|
93
|
+
year: 'numeric', month: '2-digit', day: '2-digit',
|
|
94
|
+
hour: '2-digit', minute: '2-digit', second: '2-digit',
|
|
95
|
+
hour12: false,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function log(msg) {
|
|
100
|
+
const line = `[${timestamp()}] ${msg}`;
|
|
101
|
+
try {
|
|
102
|
+
fs.appendFileSync(LOG_FILE, line + '\n');
|
|
103
|
+
} catch { /* ignore log write failures */ }
|
|
104
|
+
if (VERBOSE) console.log(line);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ============================================================
|
|
108
|
+
// TRANSCRIPT SOURCE REGISTRY
|
|
109
|
+
// ============================================================
|
|
110
|
+
|
|
111
|
+
function loadTranscriptSources() {
|
|
112
|
+
if (fs.existsSync(TRANSCRIPT_REGISTRY)) {
|
|
113
|
+
try {
|
|
114
|
+
const reg = JSON.parse(fs.readFileSync(TRANSCRIPT_REGISTRY, 'utf-8'));
|
|
115
|
+
return (reg.sources || [])
|
|
116
|
+
.filter(s => s.enabled !== false)
|
|
117
|
+
.map(s => ({ ...s, path: resolvePath(s.path) }));
|
|
118
|
+
} catch { /* fall through */ }
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Legacy fallback: derive Claude Code paths from workspace
|
|
122
|
+
const workspaceAbs = fs.realpathSync(WORKSPACE);
|
|
123
|
+
const slug = workspaceAbs.replace(/[/.]/g, '-');
|
|
124
|
+
return [
|
|
125
|
+
{ name: 'claude-code', path: path.join(HOME, '.claude/projects', slug), format: 'claude-code' },
|
|
126
|
+
{ name: 'claude-home', path: path.join(HOME, '.claude/projects', '-' + path.basename(HOME)), format: 'claude-code' },
|
|
127
|
+
{ name: 'gateway', path: path.join(HOME, '.openclaw/agents/main/sessions'), format: 'openclaw-gateway' },
|
|
128
|
+
];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ============================================================
|
|
132
|
+
// ACTIVITY DETECTION
|
|
133
|
+
// Polls JSONL mtimes from registered transcript sources.
|
|
134
|
+
// No touchfiles. No hooks. The JSONL write IS the heartbeat.
|
|
135
|
+
// ============================================================
|
|
136
|
+
|
|
137
|
+
function detectActivity(sources, activityWindowMs) {
|
|
138
|
+
const now = Date.now();
|
|
139
|
+
const cutoff = now - activityWindowMs;
|
|
140
|
+
let active = false;
|
|
141
|
+
let newestSession = null;
|
|
142
|
+
let newestMtime = 0;
|
|
143
|
+
let newestSource = null;
|
|
144
|
+
|
|
145
|
+
for (const source of sources) {
|
|
146
|
+
if (!fs.existsSync(source.path)) continue;
|
|
147
|
+
|
|
148
|
+
let files;
|
|
149
|
+
try {
|
|
150
|
+
files = fs.readdirSync(source.path).filter(f => f.endsWith('.jsonl'));
|
|
151
|
+
} catch { continue; }
|
|
152
|
+
|
|
153
|
+
for (const f of files) {
|
|
154
|
+
const full = path.join(source.path, f);
|
|
155
|
+
try {
|
|
156
|
+
const stat = fs.statSync(full);
|
|
157
|
+
const mtime = stat.mtimeMs;
|
|
158
|
+
if (mtime > cutoff) active = true;
|
|
159
|
+
if (mtime > newestMtime) {
|
|
160
|
+
newestMtime = mtime;
|
|
161
|
+
newestSession = path.basename(f, '.jsonl');
|
|
162
|
+
newestSource = source.name;
|
|
163
|
+
}
|
|
164
|
+
} catch { continue; }
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return { active, newestSession, newestMtime, newestSource };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// ============================================================
|
|
172
|
+
// SESSION STATE MACHINE
|
|
173
|
+
// ENDED → BOOT → ACTIVE → IDLE → ENDED
|
|
174
|
+
// ============================================================
|
|
175
|
+
|
|
176
|
+
const STATES = { ENDED: 'ENDED', BOOT: 'BOOT', ACTIVE: 'ACTIVE', IDLE: 'IDLE' };
|
|
177
|
+
|
|
178
|
+
class SessionStateMachine {
|
|
179
|
+
#state = STATES.ENDED;
|
|
180
|
+
#sessionId = null;
|
|
181
|
+
#lastActivityTime = 0;
|
|
182
|
+
#bootStartTime = 0;
|
|
183
|
+
#config;
|
|
184
|
+
|
|
185
|
+
constructor(config) {
|
|
186
|
+
this.#config = config;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
get state() { return this.#state; }
|
|
190
|
+
get sessionId() { return this.#sessionId; }
|
|
191
|
+
get lastActivityTime() { return this.#lastActivityTime; }
|
|
192
|
+
|
|
193
|
+
tick(activity) {
|
|
194
|
+
const now = Date.now();
|
|
195
|
+
const transitions = [];
|
|
196
|
+
|
|
197
|
+
if (activity.active) {
|
|
198
|
+
this.#lastActivityTime = now;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const timeSinceActivity = now - this.#lastActivityTime;
|
|
202
|
+
const isNewSession = activity.newestSession
|
|
203
|
+
&& activity.newestSession !== this.#sessionId
|
|
204
|
+
&& activity.active;
|
|
205
|
+
|
|
206
|
+
switch (this.#state) {
|
|
207
|
+
case STATES.ENDED:
|
|
208
|
+
if (activity.active) {
|
|
209
|
+
this.#sessionId = activity.newestSession;
|
|
210
|
+
this.#state = STATES.BOOT;
|
|
211
|
+
this.#bootStartTime = now;
|
|
212
|
+
transitions.push({ from: STATES.ENDED, to: STATES.BOOT, sessionId: this.#sessionId });
|
|
213
|
+
}
|
|
214
|
+
break;
|
|
215
|
+
|
|
216
|
+
case STATES.BOOT:
|
|
217
|
+
// Boot is transient — completeBoot() transitions to ACTIVE
|
|
218
|
+
// Safety: force to ACTIVE if boot takes >60s
|
|
219
|
+
if (now - this.#bootStartTime > 60000) {
|
|
220
|
+
this.#state = STATES.ACTIVE;
|
|
221
|
+
transitions.push({ from: STATES.BOOT, to: STATES.ACTIVE, sessionId: this.#sessionId });
|
|
222
|
+
}
|
|
223
|
+
break;
|
|
224
|
+
|
|
225
|
+
case STATES.ACTIVE:
|
|
226
|
+
if (isNewSession) {
|
|
227
|
+
// New session while active — end current, boot new
|
|
228
|
+
transitions.push({ from: STATES.ACTIVE, to: STATES.ENDED, sessionId: this.#sessionId });
|
|
229
|
+
this.#sessionId = activity.newestSession;
|
|
230
|
+
this.#state = STATES.BOOT;
|
|
231
|
+
this.#bootStartTime = now;
|
|
232
|
+
transitions.push({ from: STATES.ENDED, to: STATES.BOOT, sessionId: this.#sessionId });
|
|
233
|
+
} else if (timeSinceActivity > this.#config.intervals.activeThresholdMs) {
|
|
234
|
+
this.#state = STATES.IDLE;
|
|
235
|
+
transitions.push({ from: STATES.ACTIVE, to: STATES.IDLE, sessionId: this.#sessionId });
|
|
236
|
+
}
|
|
237
|
+
break;
|
|
238
|
+
|
|
239
|
+
case STATES.IDLE:
|
|
240
|
+
if (isNewSession) {
|
|
241
|
+
transitions.push({ from: STATES.IDLE, to: STATES.ENDED, sessionId: this.#sessionId });
|
|
242
|
+
this.#sessionId = activity.newestSession;
|
|
243
|
+
this.#state = STATES.BOOT;
|
|
244
|
+
this.#bootStartTime = now;
|
|
245
|
+
transitions.push({ from: STATES.ENDED, to: STATES.BOOT, sessionId: this.#sessionId });
|
|
246
|
+
} else if (activity.active && timeSinceActivity < this.#config.intervals.activeThresholdMs) {
|
|
247
|
+
this.#state = STATES.ACTIVE;
|
|
248
|
+
transitions.push({ from: STATES.IDLE, to: STATES.ACTIVE, sessionId: this.#sessionId });
|
|
249
|
+
} else if (timeSinceActivity > this.#config.intervals.idleThresholdMs) {
|
|
250
|
+
this.#state = STATES.ENDED;
|
|
251
|
+
transitions.push({ from: STATES.IDLE, to: STATES.ENDED, sessionId: this.#sessionId });
|
|
252
|
+
this.#sessionId = null;
|
|
253
|
+
}
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return transitions;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
completeBoot() {
|
|
261
|
+
if (this.#state === STATES.BOOT) {
|
|
262
|
+
this.#state = STATES.ACTIVE;
|
|
263
|
+
return { from: STATES.BOOT, to: STATES.ACTIVE, sessionId: this.#sessionId };
|
|
264
|
+
}
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Restore state from daemon-state.json after crash/restart
|
|
269
|
+
restore(saved) {
|
|
270
|
+
if (saved && saved.state && STATES[saved.state]) {
|
|
271
|
+
this.#state = saved.state;
|
|
272
|
+
this.#sessionId = saved.sessionId || null;
|
|
273
|
+
this.#lastActivityTime = saved.lastActivityTime || 0;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// ============================================================
|
|
279
|
+
// PHASE 0: SESSION-START BOOTSTRAP
|
|
280
|
+
// ============================================================
|
|
281
|
+
|
|
282
|
+
async function runPhase0Bootstrap(sessionId, config) {
|
|
283
|
+
log(`Phase 0: Bootstrap for session ${sessionId?.slice(0, 8) || 'unknown'}`);
|
|
284
|
+
|
|
285
|
+
const recap = path.join(WORKSPACE, 'bin/session-recap');
|
|
286
|
+
const clawvault = path.join(WORKSPACE, config.clawvaultBin);
|
|
287
|
+
const compileBoot = path.join(WORKSPACE, 'bin/compile-boot');
|
|
288
|
+
const maintenance = path.join(WORKSPACE, 'bin/memory-maintenance.mjs');
|
|
289
|
+
const subagentAudit = path.join(WORKSPACE, 'bin/subagent-audit.mjs');
|
|
290
|
+
const memoryDir = path.join(WORKSPACE, 'memory');
|
|
291
|
+
|
|
292
|
+
// 1. Session recap of previous session
|
|
293
|
+
if (fs.existsSync(recap)) {
|
|
294
|
+
try {
|
|
295
|
+
await runSubprocess('node', [recap, '--previous'], 30000);
|
|
296
|
+
log(' session-recap --previous done');
|
|
297
|
+
} catch (e) { log(` session-recap --previous failed: ${e.message}`); }
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// 2. ClawVault wake
|
|
301
|
+
if (fs.existsSync(clawvault)) {
|
|
302
|
+
try {
|
|
303
|
+
await runSubprocess(clawvault, ['wake'], 15000);
|
|
304
|
+
log(' clawvault wake done');
|
|
305
|
+
} catch (e) { log(` clawvault wake failed: ${e.message}`); }
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// 3. Ensure today's daily file exists
|
|
309
|
+
const today = new Date().toLocaleDateString('en-CA', { timeZone: config.timezone });
|
|
310
|
+
const todayFile = path.join(memoryDir, `${today}.md`);
|
|
311
|
+
if (!fs.existsSync(todayFile)) {
|
|
312
|
+
fs.mkdirSync(memoryDir, { recursive: true });
|
|
313
|
+
fs.writeFileSync(todayFile, `# ${today} — Daily Log\n\n`);
|
|
314
|
+
log(` created daily file: ${today}.md`);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// 4. Run maintenance (force)
|
|
318
|
+
if (fs.existsSync(maintenance)) {
|
|
319
|
+
try {
|
|
320
|
+
await runSubprocess('node', [maintenance, '--force'], 60000);
|
|
321
|
+
log(' memory-maintenance --force done');
|
|
322
|
+
} catch (e) { log(` memory-maintenance failed: ${e.message}`); }
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// 5. Compile boot artifacts
|
|
326
|
+
if (fs.existsSync(compileBoot)) {
|
|
327
|
+
try {
|
|
328
|
+
// Use /usr/bin/python3 explicitly — Homebrew python lacks pyyaml
|
|
329
|
+
const py = fs.existsSync('/usr/bin/python3') ? '/usr/bin/python3' : 'python3';
|
|
330
|
+
await runSubprocess(py, [compileBoot, '--all'], 30000);
|
|
331
|
+
log(' compile-boot done');
|
|
332
|
+
} catch (e) { log(` compile-boot failed: ${e.message}`); }
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// 6. Sub-agent audit of previous session
|
|
336
|
+
if (fs.existsSync(subagentAudit)) {
|
|
337
|
+
try {
|
|
338
|
+
// Find the previous session's JSONL
|
|
339
|
+
const sources = loadTranscriptSources();
|
|
340
|
+
const prevJsonl = findPreviousJsonl(sources);
|
|
341
|
+
if (prevJsonl) {
|
|
342
|
+
await runSubprocess('node', [subagentAudit, prevJsonl], 30000);
|
|
343
|
+
log(` subagent-audit done on ${path.basename(prevJsonl).slice(0, 8)}`);
|
|
344
|
+
}
|
|
345
|
+
} catch (e) { log(` subagent-audit failed: ${e.message}`); }
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// 7. ClawVault observe — compress recent sessions into observational memory
|
|
349
|
+
if (fs.existsSync(clawvault)) {
|
|
350
|
+
try {
|
|
351
|
+
await runSubprocess(clawvault, ['observe', '--cron'], 60000);
|
|
352
|
+
log(' clawvault observe done');
|
|
353
|
+
} catch (e) { log(` clawvault observe failed: ${e.message}`); }
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// 8. ClawVault doctor — vault health check + auto-fix
|
|
357
|
+
if (fs.existsSync(clawvault)) {
|
|
358
|
+
try {
|
|
359
|
+
await runSubprocess(clawvault, ['doctor', '--fix'], 30000);
|
|
360
|
+
log(' clawvault doctor done');
|
|
361
|
+
} catch (e) { log(` clawvault doctor failed: ${e.message}`); }
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
log('Phase 0: Bootstrap complete');
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function findPreviousJsonl(sources) {
|
|
368
|
+
const all = [];
|
|
369
|
+
for (const source of sources) {
|
|
370
|
+
if (!fs.existsSync(source.path)) continue;
|
|
371
|
+
try {
|
|
372
|
+
const files = fs.readdirSync(source.path).filter(f => f.endsWith('.jsonl'));
|
|
373
|
+
for (const f of files) {
|
|
374
|
+
const full = path.join(source.path, f);
|
|
375
|
+
try {
|
|
376
|
+
const stat = fs.statSync(full);
|
|
377
|
+
if (stat.size < 50 * 1024) continue; // skip tiny
|
|
378
|
+
all.push({ path: full, mtime: stat.mtimeMs });
|
|
379
|
+
} catch { continue; }
|
|
380
|
+
}
|
|
381
|
+
} catch { continue; }
|
|
382
|
+
}
|
|
383
|
+
all.sort((a, b) => b.mtime - a.mtime);
|
|
384
|
+
return all.length > 1 ? all[1].path : null; // second most recent = previous
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function findCurrentJsonl(sources) {
|
|
388
|
+
const all = [];
|
|
389
|
+
for (const source of sources) {
|
|
390
|
+
if (!fs.existsSync(source.path)) continue;
|
|
391
|
+
try {
|
|
392
|
+
const files = fs.readdirSync(source.path).filter(f => f.endsWith('.jsonl'));
|
|
393
|
+
for (const f of files) {
|
|
394
|
+
const full = path.join(source.path, f);
|
|
395
|
+
try {
|
|
396
|
+
const stat = fs.statSync(full);
|
|
397
|
+
if (stat.size < 50 * 1024) continue;
|
|
398
|
+
all.push({ path: full, mtime: stat.mtimeMs });
|
|
399
|
+
} catch { continue; }
|
|
400
|
+
}
|
|
401
|
+
} catch { continue; }
|
|
402
|
+
}
|
|
403
|
+
all.sort((a, b) => b.mtime - a.mtime);
|
|
404
|
+
return all.length > 0 ? all[0].path : null; // most recent = current
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// ============================================================
|
|
408
|
+
// PHASE 1: STATUS SYNC
|
|
409
|
+
// Updates .companion-state.md from active-tasks.md (~5ms)
|
|
410
|
+
// ============================================================
|
|
411
|
+
|
|
412
|
+
function runPhase1StatusSync(config) {
|
|
413
|
+
const activeTasks = path.join(WORKSPACE, 'memory/active-tasks.md');
|
|
414
|
+
const companion = path.join(WORKSPACE, '.companion-state.md');
|
|
415
|
+
|
|
416
|
+
let runningTasks = 'Standing by';
|
|
417
|
+
let runningCount = 0;
|
|
418
|
+
let doneCount = 0;
|
|
419
|
+
|
|
420
|
+
if (fs.existsSync(activeTasks)) {
|
|
421
|
+
try {
|
|
422
|
+
const content = fs.readFileSync(activeTasks, 'utf-8');
|
|
423
|
+
const lines = content.split('\n');
|
|
424
|
+
|
|
425
|
+
// Extract running task titles
|
|
426
|
+
const running = [];
|
|
427
|
+
for (let i = 0; i < lines.length; i++) {
|
|
428
|
+
if (lines[i].includes('status: running')) {
|
|
429
|
+
// Look backwards for the title
|
|
430
|
+
for (let j = i - 1; j >= Math.max(0, i - 5); j--) {
|
|
431
|
+
const titleMatch = lines[j].match(/title:\s*"?(.+?)"?\s*$/);
|
|
432
|
+
if (titleMatch) {
|
|
433
|
+
running.push(titleMatch[1]);
|
|
434
|
+
break;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
runningCount = (content.match(/status: running/g) || []).length;
|
|
441
|
+
doneCount = (content.match(/status: done/g) || []).length;
|
|
442
|
+
|
|
443
|
+
if (running.length > 0) {
|
|
444
|
+
runningTasks = running.slice(0, 3).join('\n');
|
|
445
|
+
}
|
|
446
|
+
} catch { /* use defaults */ }
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
const now = new Date().toLocaleString('en-CA', {
|
|
450
|
+
timeZone: config.timezone,
|
|
451
|
+
year: 'numeric', month: '2-digit', day: '2-digit',
|
|
452
|
+
hour: '2-digit', minute: '2-digit', second: '2-digit',
|
|
453
|
+
hour12: false,
|
|
454
|
+
}).replace(', ', 'T').replace(/\//g, '-');
|
|
455
|
+
|
|
456
|
+
// Preserve started_at from existing companion state
|
|
457
|
+
let startedAt = now;
|
|
458
|
+
if (fs.existsSync(companion)) {
|
|
459
|
+
try {
|
|
460
|
+
const existing = fs.readFileSync(companion, 'utf-8');
|
|
461
|
+
const match = existing.match(/started_at:\s*(.+)/);
|
|
462
|
+
if (match) startedAt = match[1].trim();
|
|
463
|
+
} catch { /* use current time */ }
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
const output = `## Session Status
|
|
467
|
+
status: active
|
|
468
|
+
started_at: ${startedAt}
|
|
469
|
+
last_flush: ${now}
|
|
470
|
+
|
|
471
|
+
## Active Task
|
|
472
|
+
${runningTasks}
|
|
473
|
+
|
|
474
|
+
## Current State
|
|
475
|
+
${runningCount} running, ${doneCount} done
|
|
476
|
+
|
|
477
|
+
## Crash Recovery
|
|
478
|
+
If this file says \`status: active\` but the session is dead:
|
|
479
|
+
1. The session crashed before flush
|
|
480
|
+
2. Read memory/active-tasks.md for last known work state
|
|
481
|
+
3. Resume from the active task listed above
|
|
482
|
+
`;
|
|
483
|
+
|
|
484
|
+
fs.writeFileSync(companion, output);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// ============================================================
|
|
488
|
+
// PHASE 2: THROTTLED BACKGROUND WORK
|
|
489
|
+
// ============================================================
|
|
490
|
+
|
|
491
|
+
const THROTTLE_STATE_FILE = path.join(STATE_DIR, 'daemon-throttle.json');
|
|
492
|
+
|
|
493
|
+
function loadThrottleState() {
|
|
494
|
+
if (fs.existsSync(THROTTLE_STATE_FILE)) {
|
|
495
|
+
try {
|
|
496
|
+
return JSON.parse(fs.readFileSync(THROTTLE_STATE_FILE, 'utf-8'));
|
|
497
|
+
} catch { /* use defaults */ }
|
|
498
|
+
}
|
|
499
|
+
return {
|
|
500
|
+
lastRecap: 0, lastMaintenance: 0, lastObsidianSync: 0, lastTrustHealth: 0,
|
|
501
|
+
lastClawvaultReflect: 0, lastClawvaultArchive: 0, lastClawvaultObserve: 0,
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
function saveThrottleState(state) {
|
|
506
|
+
fs.writeFileSync(THROTTLE_STATE_FILE, JSON.stringify(state, null, 2));
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
async function runPhase2ThrottledWork(config) {
|
|
510
|
+
const now = Date.now();
|
|
511
|
+
const throttle = loadThrottleState();
|
|
512
|
+
|
|
513
|
+
// Stage 1: Parallel — recap, maintenance, trust-health, ClawVault observe/reflect/archive
|
|
514
|
+
// These produce data. They run before Obsidian sync so fresh data gets pushed.
|
|
515
|
+
const stage1 = [];
|
|
516
|
+
|
|
517
|
+
// Session recap (every 10min)
|
|
518
|
+
if (now - throttle.lastRecap >= config.intervals.sessionRecapMs) {
|
|
519
|
+
throttle.lastRecap = now;
|
|
520
|
+
const recap = path.join(WORKSPACE, 'bin/session-recap');
|
|
521
|
+
if (fs.existsSync(recap)) {
|
|
522
|
+
stage1.push(
|
|
523
|
+
runSubprocess('node', [recap], 30000)
|
|
524
|
+
.then(() => log(' Phase 2: session-recap done'))
|
|
525
|
+
.catch(e => log(` Phase 2: session-recap failed: ${e.message}`))
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
// Memory maintenance (every 30min)
|
|
531
|
+
if (now - throttle.lastMaintenance >= config.intervals.maintenanceMs) {
|
|
532
|
+
throttle.lastMaintenance = now;
|
|
533
|
+
const maint = path.join(WORKSPACE, 'bin/memory-maintenance.mjs');
|
|
534
|
+
if (fs.existsSync(maint)) {
|
|
535
|
+
stage1.push(
|
|
536
|
+
runSubprocess('node', [maint], 60000)
|
|
537
|
+
.then(() => log(' Phase 2: memory-maintenance done'))
|
|
538
|
+
.catch(e => log(` Phase 2: memory-maintenance failed: ${e.message}`))
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
// Trust registry health check (every 30min)
|
|
544
|
+
if (now - throttle.lastTrustHealth >= config.intervals.maintenanceMs) {
|
|
545
|
+
throttle.lastTrustHealth = now;
|
|
546
|
+
const audit = path.join(WORKSPACE, 'bin/subagent-audit.mjs');
|
|
547
|
+
if (fs.existsSync(audit)) {
|
|
548
|
+
stage1.push(
|
|
549
|
+
runSubprocess('node', [audit, '--health-check'], 15000)
|
|
550
|
+
.then(() => log(' Phase 2: trust-health done'))
|
|
551
|
+
.catch(e => log(` Phase 2: trust-health failed: ${e.message}`))
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
const clawvault = path.join(WORKSPACE, config.clawvaultBin);
|
|
557
|
+
if (fs.existsSync(clawvault)) {
|
|
558
|
+
// ClawVault observe — incremental session compression (every 10min)
|
|
559
|
+
if (now - throttle.lastClawvaultObserve >= config.intervals.sessionRecapMs) {
|
|
560
|
+
throttle.lastClawvaultObserve = now;
|
|
561
|
+
stage1.push(
|
|
562
|
+
runSubprocess(clawvault, ['observe', '--cron'], 60000)
|
|
563
|
+
.then(() => log(' Phase 2: clawvault observe done'))
|
|
564
|
+
.catch(e => log(` Phase 2: clawvault observe failed: ${e.message}`))
|
|
565
|
+
);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// ClawVault reflect — promote stable observations to reflections (every 30min)
|
|
569
|
+
if (now - throttle.lastClawvaultReflect >= config.intervals.maintenanceMs) {
|
|
570
|
+
throttle.lastClawvaultReflect = now;
|
|
571
|
+
stage1.push(
|
|
572
|
+
runSubprocess(clawvault, ['reflect'], 60000)
|
|
573
|
+
.then(() => log(' Phase 2: clawvault reflect done'))
|
|
574
|
+
.catch(e => log(` Phase 2: clawvault reflect failed: ${e.message}`))
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
// ClawVault archive — move old observations to ledger (every 30min)
|
|
579
|
+
if (now - throttle.lastClawvaultArchive >= config.intervals.maintenanceMs) {
|
|
580
|
+
throttle.lastClawvaultArchive = now;
|
|
581
|
+
stage1.push(
|
|
582
|
+
runSubprocess(clawvault, ['archive'], 30000)
|
|
583
|
+
.then(() => log(' Phase 2: clawvault archive done'))
|
|
584
|
+
.catch(e => log(` Phase 2: clawvault archive failed: ${e.message}`))
|
|
585
|
+
);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
// Daily log writer — clock-aligned hourly (runs after recap so recap is fresh)
|
|
590
|
+
const dailyLogWriter = path.join(WORKSPACE, 'bin/daily-log-writer.mjs');
|
|
591
|
+
if (fs.existsSync(dailyLogWriter)) {
|
|
592
|
+
const currentHour = new Date().getHours();
|
|
593
|
+
if (currentHour !== throttle.lastDailyLogHour) {
|
|
594
|
+
throttle.lastDailyLogHour = currentHour;
|
|
595
|
+
stage1.push(
|
|
596
|
+
runSubprocess('node', [dailyLogWriter], 15000)
|
|
597
|
+
.then(() => log(' Phase 2: daily-log-writer done'))
|
|
598
|
+
.catch(e => log(` Phase 2: daily-log-writer failed: ${e.message}`))
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
if (stage1.length > 0) {
|
|
604
|
+
await Promise.allSettled(stage1);
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
// Stage 2: Obsidian sync — runs AFTER stage 1 so fresh ClawVault data,
|
|
608
|
+
// trust-registry updates, and recaps are all picked up and pushed to vault.
|
|
609
|
+
if (now - throttle.lastObsidianSync >= config.intervals.obsidianSyncMs) {
|
|
610
|
+
throttle.lastObsidianSync = now;
|
|
611
|
+
const obsSync = path.join(WORKSPACE, 'bin/obsidian-sync.mjs');
|
|
612
|
+
if (fs.existsSync(obsSync)) {
|
|
613
|
+
await runSubprocess('node', [obsSync], 60000)
|
|
614
|
+
.then(() => log(' Phase 2: obsidian-sync done'))
|
|
615
|
+
.catch(e => log(` Phase 2: obsidian-sync failed: ${e.message}`));
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
// Always persist throttle timestamps (Obsidian sync updates outside stage1)
|
|
620
|
+
saveThrottleState(throttle);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
// ============================================================
|
|
624
|
+
// TRANSITION HANDLERS
|
|
625
|
+
// Actions triggered by state machine transitions
|
|
626
|
+
// ============================================================
|
|
627
|
+
|
|
628
|
+
async function handleTransitions(transitions, config) {
|
|
629
|
+
for (const t of transitions) {
|
|
630
|
+
log(`State: ${t.from} → ${t.to} (session: ${t.sessionId?.slice(0, 8) || '?'})`);
|
|
631
|
+
|
|
632
|
+
// ACTIVE → ENDED: Quick cleanup before session switch
|
|
633
|
+
if (t.from === STATES.ACTIVE && t.to === STATES.ENDED) {
|
|
634
|
+
log('Session switched while active — running quick cleanup');
|
|
635
|
+
const recap = path.join(WORKSPACE, 'bin/session-recap');
|
|
636
|
+
const clawvault = path.join(WORKSPACE, config.clawvaultBin);
|
|
637
|
+
const tasks = [];
|
|
638
|
+
if (fs.existsSync(recap)) {
|
|
639
|
+
tasks.push(runSubprocess('node', [recap], 15000).catch(() => {}));
|
|
640
|
+
}
|
|
641
|
+
if (fs.existsSync(clawvault)) {
|
|
642
|
+
tasks.push(runSubprocess(clawvault, ['observe', '--cron'], 30000).catch(() => {}));
|
|
643
|
+
}
|
|
644
|
+
if (tasks.length > 0) await Promise.allSettled(tasks);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
// ENDED → BOOT: Full bootstrap
|
|
648
|
+
if (t.from === STATES.ENDED && t.to === STATES.BOOT) {
|
|
649
|
+
await runPhase0Bootstrap(t.sessionId, config);
|
|
650
|
+
return STATES.ACTIVE; // signal to complete boot
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
// ACTIVE → IDLE: Observe + recap + checkpoint
|
|
654
|
+
if (t.from === STATES.ACTIVE && t.to === STATES.IDLE) {
|
|
655
|
+
log('Entering idle — running observe + recap + checkpoint');
|
|
656
|
+
const recap = path.join(WORKSPACE, 'bin/session-recap');
|
|
657
|
+
const clawvault = path.join(WORKSPACE, config.clawvaultBin);
|
|
658
|
+
|
|
659
|
+
const tasks = [];
|
|
660
|
+
if (fs.existsSync(recap)) {
|
|
661
|
+
tasks.push(runSubprocess('node', [recap], 30000).catch(() => {}));
|
|
662
|
+
}
|
|
663
|
+
if (fs.existsSync(clawvault)) {
|
|
664
|
+
tasks.push(runSubprocess(clawvault, ['observe', '--cron'], 60000).catch(() => {}));
|
|
665
|
+
tasks.push(runSubprocess(clawvault, ['checkpoint', '--working-on', 'idle'], 15000).catch(() => {}));
|
|
666
|
+
}
|
|
667
|
+
await Promise.allSettled(tasks);
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
// IDLE → ENDED: Full cleanup pipeline
|
|
671
|
+
if (t.from === STATES.IDLE && t.to === STATES.ENDED) {
|
|
672
|
+
log('Session ended — running full cleanup pipeline');
|
|
673
|
+
const clawvault = path.join(WORKSPACE, config.clawvaultBin);
|
|
674
|
+
const obsSync = path.join(WORKSPACE, 'bin/obsidian-sync.mjs');
|
|
675
|
+
const subagentAudit = path.join(WORKSPACE, 'bin/subagent-audit.mjs');
|
|
676
|
+
|
|
677
|
+
// 1. ClawVault: final observe + reflect + archive → persist all learnings
|
|
678
|
+
if (fs.existsSync(clawvault)) {
|
|
679
|
+
await runSubprocess(clawvault, ['observe', '--cron'], 60000).catch(() => {});
|
|
680
|
+
await runSubprocess(clawvault, ['reflect'], 60000).catch(() => {});
|
|
681
|
+
await runSubprocess(clawvault, ['archive'], 30000).catch(() => {});
|
|
682
|
+
log(' clawvault observe+reflect+archive done');
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
// 2. Sub-agent audit — extract trust data from this session
|
|
686
|
+
if (fs.existsSync(subagentAudit)) {
|
|
687
|
+
const sources = loadTranscriptSources();
|
|
688
|
+
const currentJsonl = findCurrentJsonl(sources);
|
|
689
|
+
if (currentJsonl) {
|
|
690
|
+
await runSubprocess('node', [subagentAudit, currentJsonl], 30000).catch(() => {});
|
|
691
|
+
log(' subagent-audit (end-of-session) done');
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
// 3. Final Obsidian sync — push all changes including new ClawVault data
|
|
696
|
+
if (fs.existsSync(obsSync)) {
|
|
697
|
+
await runSubprocess('node', [obsSync], 60000).catch(() => {});
|
|
698
|
+
log(' final obsidian-sync done');
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
// 4. ClawVault sleep — handoff + clean exit
|
|
702
|
+
if (fs.existsSync(clawvault)) {
|
|
703
|
+
await runSubprocess(clawvault, ['sleep', 'session ended'], 15000).catch(() => {});
|
|
704
|
+
log(' clawvault sleep done');
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
return null;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// ============================================================
|
|
712
|
+
// SUBPROCESS RUNNER
|
|
713
|
+
// ============================================================
|
|
714
|
+
|
|
715
|
+
function runSubprocess(cmd, args, timeoutMs = 30000) {
|
|
716
|
+
return new Promise((resolve, reject) => {
|
|
717
|
+
const proc = spawn(cmd, args, {
|
|
718
|
+
cwd: WORKSPACE,
|
|
719
|
+
env: {
|
|
720
|
+
...process.env,
|
|
721
|
+
OPENCLAW_WORKSPACE: WORKSPACE,
|
|
722
|
+
TZ: 'America/Montreal',
|
|
723
|
+
},
|
|
724
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
let stdout = '';
|
|
728
|
+
let stderr = '';
|
|
729
|
+
proc.stdout.on('data', d => { stdout += d; });
|
|
730
|
+
proc.stderr.on('data', d => { stderr += d; });
|
|
731
|
+
|
|
732
|
+
const timer = setTimeout(() => {
|
|
733
|
+
proc.kill('SIGTERM');
|
|
734
|
+
reject(new Error(`timeout after ${timeoutMs}ms`));
|
|
735
|
+
}, timeoutMs);
|
|
736
|
+
|
|
737
|
+
proc.on('close', code => {
|
|
738
|
+
clearTimeout(timer);
|
|
739
|
+
if (code === 0) resolve(stdout.trim());
|
|
740
|
+
else reject(new Error(`exit ${code}: ${stderr.trim().slice(0, 200)}`));
|
|
741
|
+
});
|
|
742
|
+
|
|
743
|
+
proc.on('error', err => {
|
|
744
|
+
clearTimeout(timer);
|
|
745
|
+
reject(err);
|
|
746
|
+
});
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
// ============================================================
|
|
751
|
+
// DAEMON STATE PERSISTENCE
|
|
752
|
+
// ============================================================
|
|
753
|
+
|
|
754
|
+
const DAEMON_STATE_FILE = path.join(STATE_DIR, 'daemon-state.json');
|
|
755
|
+
|
|
756
|
+
function saveDaemonState(sm, throttle) {
|
|
757
|
+
const state = {
|
|
758
|
+
state: sm.state,
|
|
759
|
+
sessionId: sm.sessionId,
|
|
760
|
+
lastActivityTime: sm.lastActivityTime,
|
|
761
|
+
pid: process.pid,
|
|
762
|
+
updatedAt: Date.now(),
|
|
763
|
+
};
|
|
764
|
+
try {
|
|
765
|
+
fs.writeFileSync(DAEMON_STATE_FILE, JSON.stringify(state, null, 2));
|
|
766
|
+
} catch { /* ignore */ }
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
function loadDaemonState() {
|
|
770
|
+
if (fs.existsSync(DAEMON_STATE_FILE)) {
|
|
771
|
+
try {
|
|
772
|
+
const state = JSON.parse(fs.readFileSync(DAEMON_STATE_FILE, 'utf-8'));
|
|
773
|
+
// Check if previous daemon process is still alive
|
|
774
|
+
if (state.pid) {
|
|
775
|
+
try {
|
|
776
|
+
process.kill(state.pid, 0); // check if alive
|
|
777
|
+
// PID exists — but might be reused by a different process
|
|
778
|
+
const staleSec = (Date.now() - (state.updatedAt || 0)) / 1000;
|
|
779
|
+
if (staleSec > 300) {
|
|
780
|
+
// >5 min since last update — PID was likely reused
|
|
781
|
+
log('Stale PID detected (>5 min since last update) — resetting state');
|
|
782
|
+
state.state = STATES.ENDED;
|
|
783
|
+
}
|
|
784
|
+
} catch { state.state = STATES.ENDED; } // not alive, reset
|
|
785
|
+
}
|
|
786
|
+
return state;
|
|
787
|
+
} catch { /* ignore */ }
|
|
788
|
+
}
|
|
789
|
+
return null;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
// ============================================================
|
|
793
|
+
// MAIN LOOP
|
|
794
|
+
// ============================================================
|
|
795
|
+
|
|
796
|
+
async function main() {
|
|
797
|
+
ensureDirs();
|
|
798
|
+
const config = loadConfig();
|
|
799
|
+
const sources = loadTranscriptSources();
|
|
800
|
+
|
|
801
|
+
log(`Daemon starting (pid: ${process.pid}, workspace: ${WORKSPACE})`);
|
|
802
|
+
log(`Transcript sources: ${sources.map(s => s.name).join(', ')}`);
|
|
803
|
+
|
|
804
|
+
const sm = new SessionStateMachine(config);
|
|
805
|
+
|
|
806
|
+
// Restore state from previous run (crash recovery)
|
|
807
|
+
const savedState = loadDaemonState();
|
|
808
|
+
if (savedState) {
|
|
809
|
+
sm.restore(savedState);
|
|
810
|
+
log(`Restored state: ${sm.state} (session: ${sm.sessionId?.slice(0, 8) || 'none'})`);
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
// Graceful shutdown
|
|
814
|
+
let running = true;
|
|
815
|
+
const shutdown = (signal) => {
|
|
816
|
+
log(`Received ${signal} — shutting down`);
|
|
817
|
+
running = false;
|
|
818
|
+
saveDaemonState(sm);
|
|
819
|
+
};
|
|
820
|
+
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
|
821
|
+
process.on('SIGINT', () => shutdown('SIGINT'));
|
|
822
|
+
|
|
823
|
+
// Main tick loop
|
|
824
|
+
async function tick() {
|
|
825
|
+
if (!running) return;
|
|
826
|
+
|
|
827
|
+
try {
|
|
828
|
+
// 1. Detect activity
|
|
829
|
+
const activity = detectActivity(sources, config.intervals.activityWindowMs);
|
|
830
|
+
|
|
831
|
+
// 2. State machine tick
|
|
832
|
+
const transitions = sm.tick(activity);
|
|
833
|
+
|
|
834
|
+
// 3. Handle transitions
|
|
835
|
+
if (transitions.length > 0) {
|
|
836
|
+
const bootResult = await handleTransitions(transitions, config);
|
|
837
|
+
if (bootResult === STATES.ACTIVE) {
|
|
838
|
+
sm.completeBoot();
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
// 4. Phase 1: Status sync (when ACTIVE or IDLE)
|
|
843
|
+
if (sm.state === STATES.ACTIVE || sm.state === STATES.IDLE) {
|
|
844
|
+
runPhase1StatusSync(config);
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
// 5. Phase 2: Throttled work (when ACTIVE or IDLE)
|
|
848
|
+
if (sm.state === STATES.ACTIVE || sm.state === STATES.IDLE) {
|
|
849
|
+
await runPhase2ThrottledWork(config);
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
// 6. Persist state
|
|
853
|
+
saveDaemonState(sm);
|
|
854
|
+
|
|
855
|
+
} catch (err) {
|
|
856
|
+
log(`Tick error: ${err.message}`);
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
// Run first tick immediately
|
|
861
|
+
await tick();
|
|
862
|
+
|
|
863
|
+
// Schedule recurring ticks
|
|
864
|
+
const interval = setInterval(async () => {
|
|
865
|
+
if (!running) {
|
|
866
|
+
clearInterval(interval);
|
|
867
|
+
log('Daemon stopped');
|
|
868
|
+
process.exit(0);
|
|
869
|
+
}
|
|
870
|
+
await tick();
|
|
871
|
+
}, config.intervals.pollMs);
|
|
872
|
+
|
|
873
|
+
// setInterval handle above prevents Node from exiting
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
main().catch(err => {
|
|
877
|
+
console.error(`Fatal: ${err.message}`);
|
|
878
|
+
process.exit(1);
|
|
879
|
+
});
|