synabun 1.3.0 → 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/CHANGELOG.md +205 -662
- package/LICENSE-COMMERCIAL.md +33 -0
- package/NOTICE +17 -0
- package/README.md +175 -853
- package/THIRD-PARTY-LICENSES.md +136 -0
- package/benchmarks/browser-live-results.json +79 -0
- package/benchmarks/browser-v2-results.json +258 -0
- package/benchmarks/fixtures/browser/README.md +57 -0
- package/benchmarks/fixtures/browser/page-state.json +132 -0
- package/benchmarks/fixtures/browser/social.json +92 -0
- package/benchmarks/fixtures/browser/target.json +319 -0
- package/benchmarks/fixtures/desktop/README.md +58 -0
- package/benchmarks/fixtures/desktop/abstention.json +59 -0
- package/benchmarks/fixtures/desktop/adversarial.json +22 -0
- package/benchmarks/fixtures/desktop/forbidden.json +93 -0
- package/benchmarks/fixtures/desktop/generate.mjs +1023 -0
- package/benchmarks/fixtures/desktop/target.json +136 -0
- package/bin/synabun.js +30 -0
- package/docs/whatsapp.md +325 -0
- package/hooks/claude-code/post-plan.mjs +613 -391
- package/hooks/claude-code/post-remember.mjs +246 -122
- package/hooks/claude-code/pre-compact.mjs +171 -110
- package/hooks/claude-code/pre-task.mjs +133 -0
- package/hooks/claude-code/pre-websearch.mjs +15 -4
- package/hooks/claude-code/prompt-origin.mjs +94 -0
- package/hooks/claude-code/prompt-submit.mjs +1244 -861
- package/hooks/claude-code/session-start.mjs +114 -156
- package/hooks/claude-code/shared.mjs +1228 -368
- package/hooks/claude-code/state.mjs +167 -0
- package/hooks/claude-code/stop.mjs +515 -140
- package/hooks/claude-code/subagent-start.mjs +154 -0
- package/hooks/claude-code/subagent-stop.mjs +102 -0
- package/hooks/claude-code/task-gate.mjs +150 -0
- package/launcher.mjs +40 -0
- package/lib/claude-hooks.js +137 -0
- package/lib/claude-usage-audit.js +141 -0
- package/lib/client-config-repair.js +145 -0
- package/lib/data-home-migration.js +502 -0
- package/lib/desktop-pwa.js +206 -0
- package/lib/external-tools.js +221 -0
- package/lib/first-launch-protection.js +245 -0
- package/lib/packaged-runtime.js +110 -0
- package/lib/paths.d.ts +21 -0
- package/lib/paths.js +103 -0
- package/lib/start-launcher.js +1309 -0
- package/mcp-server/dist/config.d.ts +22 -0
- package/mcp-server/dist/config.d.ts.map +1 -0
- package/mcp-server/dist/config.js +109 -0
- package/mcp-server/dist/config.js.map +1 -0
- package/mcp-server/dist/http.d.ts +30 -0
- package/mcp-server/dist/http.d.ts.map +1 -0
- package/mcp-server/dist/http.js +276 -0
- package/mcp-server/dist/http.js.map +1 -0
- package/mcp-server/dist/index.d.ts +48 -0
- package/mcp-server/dist/index.d.ts.map +1 -0
- package/mcp-server/dist/index.js +538 -0
- package/mcp-server/dist/index.js.map +1 -0
- package/mcp-server/dist/preload-http.d.ts +3 -0
- package/mcp-server/dist/preload-http.d.ts.map +1 -0
- package/mcp-server/dist/preload-http.js +28 -0
- package/mcp-server/dist/preload-http.js.map +1 -0
- package/mcp-server/dist/preload.d.ts +3 -0
- package/mcp-server/dist/preload.d.ts.map +1 -0
- package/mcp-server/dist/preload.js +32 -0
- package/mcp-server/dist/preload.js.map +1 -0
- package/mcp-server/dist/scripts/migrate-qdrant-to-sqlite.d.ts +19 -0
- package/mcp-server/dist/scripts/migrate-qdrant-to-sqlite.d.ts.map +1 -0
- package/mcp-server/dist/scripts/migrate-qdrant-to-sqlite.js +403 -0
- package/mcp-server/dist/scripts/migrate-qdrant-to-sqlite.js.map +1 -0
- package/mcp-server/dist/scripts/setup-embeddings.d.ts +3 -0
- package/mcp-server/dist/scripts/setup-embeddings.d.ts.map +1 -0
- package/mcp-server/dist/scripts/setup-embeddings.js +15 -0
- package/mcp-server/dist/scripts/setup-embeddings.js.map +1 -0
- package/mcp-server/dist/services/assistant-judgments.d.ts +79 -0
- package/mcp-server/dist/services/assistant-judgments.d.ts.map +1 -0
- package/mcp-server/dist/services/assistant-judgments.js +128 -0
- package/mcp-server/dist/services/assistant-judgments.js.map +1 -0
- package/mcp-server/dist/services/browser-assist-gate.d.ts +314 -0
- package/mcp-server/dist/services/browser-assist-gate.d.ts.map +1 -0
- package/mcp-server/dist/services/browser-assist-gate.js +344 -0
- package/mcp-server/dist/services/browser-assist-gate.js.map +1 -0
- package/mcp-server/dist/services/browser-assist.d.ts +104 -0
- package/mcp-server/dist/services/browser-assist.d.ts.map +1 -0
- package/mcp-server/dist/services/browser-assist.js +282 -0
- package/mcp-server/dist/services/browser-assist.js.map +1 -0
- package/mcp-server/dist/services/browser-bench.d.ts +772 -0
- package/mcp-server/dist/services/browser-bench.d.ts.map +1 -0
- package/mcp-server/dist/services/browser-bench.js +424 -0
- package/mcp-server/dist/services/browser-bench.js.map +1 -0
- package/mcp-server/dist/services/browser-judgments.d.ts +196 -0
- package/mcp-server/dist/services/browser-judgments.d.ts.map +1 -0
- package/mcp-server/dist/services/browser-judgments.js +363 -0
- package/mcp-server/dist/services/browser-judgments.js.map +1 -0
- package/mcp-server/dist/services/browser-risk.d.ts +166 -0
- package/mcp-server/dist/services/browser-risk.d.ts.map +1 -0
- package/mcp-server/dist/services/browser-risk.js +458 -0
- package/mcp-server/dist/services/browser-risk.js.map +1 -0
- package/mcp-server/dist/services/categories.d.ts +61 -0
- package/mcp-server/dist/services/categories.d.ts.map +1 -0
- package/mcp-server/dist/services/categories.js +377 -0
- package/mcp-server/dist/services/categories.js.map +1 -0
- package/mcp-server/dist/services/codex-config-heal.d.ts +49 -0
- package/mcp-server/dist/services/codex-config-heal.d.ts.map +1 -0
- package/mcp-server/dist/services/codex-config-heal.js +346 -0
- package/mcp-server/dist/services/codex-config-heal.js.map +1 -0
- package/mcp-server/dist/services/desktop-assist-gate.d.ts +198 -0
- package/mcp-server/dist/services/desktop-assist-gate.d.ts.map +1 -0
- package/mcp-server/dist/services/desktop-assist-gate.js +202 -0
- package/mcp-server/dist/services/desktop-assist-gate.js.map +1 -0
- package/mcp-server/dist/services/desktop-assist.d.ts +104 -0
- package/mcp-server/dist/services/desktop-assist.d.ts.map +1 -0
- package/mcp-server/dist/services/desktop-assist.js +266 -0
- package/mcp-server/dist/services/desktop-assist.js.map +1 -0
- package/mcp-server/dist/services/desktop-bench.d.ts +553 -0
- package/mcp-server/dist/services/desktop-bench.d.ts.map +1 -0
- package/mcp-server/dist/services/desktop-bench.js +311 -0
- package/mcp-server/dist/services/desktop-bench.js.map +1 -0
- package/mcp-server/dist/services/desktop-client.d.ts +23 -0
- package/mcp-server/dist/services/desktop-client.d.ts.map +1 -0
- package/mcp-server/dist/services/desktop-client.js +79 -0
- package/mcp-server/dist/services/desktop-client.js.map +1 -0
- package/mcp-server/dist/services/desktop-judgments.d.ts +125 -0
- package/mcp-server/dist/services/desktop-judgments.d.ts.map +1 -0
- package/mcp-server/dist/services/desktop-judgments.js +177 -0
- package/mcp-server/dist/services/desktop-judgments.js.map +1 -0
- package/mcp-server/dist/services/desktop-risk.d.ts +283 -0
- package/mcp-server/dist/services/desktop-risk.d.ts.map +1 -0
- package/mcp-server/dist/services/desktop-risk.js +605 -0
- package/mcp-server/dist/services/desktop-risk.js.map +1 -0
- package/mcp-server/dist/services/discord.d.ts +112 -0
- package/mcp-server/dist/services/discord.d.ts.map +1 -0
- package/mcp-server/dist/services/discord.js +477 -0
- package/mcp-server/dist/services/discord.js.map +1 -0
- package/mcp-server/dist/services/edit-stale.d.ts +81 -0
- package/mcp-server/dist/services/edit-stale.d.ts.map +1 -0
- package/mcp-server/dist/services/edit-stale.js +358 -0
- package/mcp-server/dist/services/edit-stale.js.map +1 -0
- package/mcp-server/dist/services/embedding-service.d.ts +16 -0
- package/mcp-server/dist/services/embedding-service.d.ts.map +1 -0
- package/mcp-server/dist/services/embedding-service.js +126 -0
- package/mcp-server/dist/services/embedding-service.js.map +1 -0
- package/mcp-server/dist/services/embedding-worker.d.ts +2 -0
- package/mcp-server/dist/services/embedding-worker.d.ts.map +1 -0
- package/mcp-server/dist/services/embedding-worker.js +52 -0
- package/mcp-server/dist/services/embedding-worker.js.map +1 -0
- package/mcp-server/dist/services/fb-regions.d.ts +71 -0
- package/mcp-server/dist/services/fb-regions.d.ts.map +1 -0
- package/mcp-server/dist/services/fb-regions.js +211 -0
- package/mcp-server/dist/services/fb-regions.js.map +1 -0
- package/mcp-server/dist/services/file-checksums.d.ts +22 -0
- package/mcp-server/dist/services/file-checksums.d.ts.map +1 -0
- package/mcp-server/dist/services/file-checksums.js +55 -0
- package/mcp-server/dist/services/file-checksums.js.map +1 -0
- package/mcp-server/dist/services/file-excerpt.d.ts +24 -0
- package/mcp-server/dist/services/file-excerpt.d.ts.map +1 -0
- package/mcp-server/dist/services/file-excerpt.js +65 -0
- package/mcp-server/dist/services/file-excerpt.js.map +1 -0
- package/mcp-server/dist/services/identity.d.ts +124 -0
- package/mcp-server/dist/services/identity.d.ts.map +1 -0
- package/mcp-server/dist/services/identity.js +241 -0
- package/mcp-server/dist/services/identity.js.map +1 -0
- package/mcp-server/dist/services/local-embeddings.d.ts +2 -0
- package/mcp-server/dist/services/local-embeddings.d.ts.map +1 -0
- package/mcp-server/dist/services/local-embeddings.js +3 -0
- package/mcp-server/dist/services/local-embeddings.js.map +1 -0
- package/mcp-server/dist/services/memory-client.d.ts +4 -0
- package/mcp-server/dist/services/memory-client.d.ts.map +1 -0
- package/mcp-server/dist/services/memory-client.js +27 -0
- package/mcp-server/dist/services/memory-client.js.map +1 -0
- package/mcp-server/dist/services/memory-judge-backfill.d.ts +135 -0
- package/mcp-server/dist/services/memory-judge-backfill.d.ts.map +1 -0
- package/mcp-server/dist/services/memory-judge-backfill.js +510 -0
- package/mcp-server/dist/services/memory-judge-backfill.js.map +1 -0
- package/mcp-server/dist/services/memory-judgments.d.ts +362 -0
- package/mcp-server/dist/services/memory-judgments.d.ts.map +1 -0
- package/mcp-server/dist/services/memory-judgments.js +674 -0
- package/mcp-server/dist/services/memory-judgments.js.map +1 -0
- package/mcp-server/dist/services/memory-maintenance.d.ts +108 -0
- package/mcp-server/dist/services/memory-maintenance.d.ts.map +1 -0
- package/mcp-server/dist/services/memory-maintenance.js +403 -0
- package/mcp-server/dist/services/memory-maintenance.js.map +1 -0
- package/mcp-server/dist/services/memory-retrieval.d.ts +66 -0
- package/mcp-server/dist/services/memory-retrieval.d.ts.map +1 -0
- package/mcp-server/dist/services/memory-retrieval.js +412 -0
- package/mcp-server/dist/services/memory-retrieval.js.map +1 -0
- package/mcp-server/dist/services/memory-schema.d.ts +16 -0
- package/mcp-server/dist/services/memory-schema.d.ts.map +1 -0
- package/mcp-server/dist/services/memory-schema.js +282 -0
- package/mcp-server/dist/services/memory-schema.js.map +1 -0
- package/mcp-server/dist/services/memory-sessions.d.ts +24 -0
- package/mcp-server/dist/services/memory-sessions.d.ts.map +1 -0
- package/mcp-server/dist/services/memory-sessions.js +110 -0
- package/mcp-server/dist/services/memory-sessions.js.map +1 -0
- package/mcp-server/dist/services/memory-triage.d.ts +60 -0
- package/mcp-server/dist/services/memory-triage.d.ts.map +1 -0
- package/mcp-server/dist/services/memory-triage.js +189 -0
- package/mcp-server/dist/services/memory-triage.js.map +1 -0
- package/mcp-server/dist/services/memory-verification.d.ts +24 -0
- package/mcp-server/dist/services/memory-verification.d.ts.map +1 -0
- package/mcp-server/dist/services/memory-verification.js +92 -0
- package/mcp-server/dist/services/memory-verification.js.map +1 -0
- package/mcp-server/dist/services/memory-writer.d.ts +26 -0
- package/mcp-server/dist/services/memory-writer.d.ts.map +1 -0
- package/mcp-server/dist/services/memory-writer.js +126 -0
- package/mcp-server/dist/services/memory-writer.js.map +1 -0
- package/mcp-server/dist/services/neural-interface.d.ts +439 -0
- package/mcp-server/dist/services/neural-interface.d.ts.map +1 -0
- package/mcp-server/dist/services/neural-interface.js +1135 -0
- package/mcp-server/dist/services/neural-interface.js.map +1 -0
- package/mcp-server/dist/services/profiles.d.ts +120 -0
- package/mcp-server/dist/services/profiles.d.ts.map +1 -0
- package/mcp-server/dist/services/profiles.js +387 -0
- package/mcp-server/dist/services/profiles.js.map +1 -0
- package/mcp-server/dist/services/secret-gate.d.ts +29 -0
- package/mcp-server/dist/services/secret-gate.d.ts.map +1 -0
- package/mcp-server/dist/services/secret-gate.js +43 -0
- package/mcp-server/dist/services/secret-gate.js.map +1 -0
- package/mcp-server/dist/services/server-instructions.d.ts +10 -0
- package/mcp-server/dist/services/server-instructions.d.ts.map +1 -0
- package/mcp-server/dist/services/server-instructions.js +101 -0
- package/mcp-server/dist/services/server-instructions.js.map +1 -0
- package/mcp-server/dist/services/sqlite.d.ts +235 -0
- package/mcp-server/dist/services/sqlite.d.ts.map +1 -0
- package/mcp-server/dist/services/sqlite.js +1185 -0
- package/mcp-server/dist/services/sqlite.js.map +1 -0
- package/mcp-server/dist/services/typesafe-bench.d.ts +99 -0
- package/mcp-server/dist/services/typesafe-bench.d.ts.map +1 -0
- package/mcp-server/dist/services/typesafe-bench.js +218 -0
- package/mcp-server/dist/services/typesafe-bench.js.map +1 -0
- package/mcp-server/dist/services/typesafe-config.d.ts +342 -0
- package/mcp-server/dist/services/typesafe-config.d.ts.map +1 -0
- package/mcp-server/dist/services/typesafe-config.js +746 -0
- package/mcp-server/dist/services/typesafe-config.js.map +1 -0
- package/mcp-server/dist/services/typesafe.d.ts +213 -0
- package/mcp-server/dist/services/typesafe.d.ts.map +1 -0
- package/mcp-server/dist/services/typesafe.js +330 -0
- package/mcp-server/dist/services/typesafe.js.map +1 -0
- package/mcp-server/dist/services/vector-cache.d.ts +68 -0
- package/mcp-server/dist/services/vector-cache.d.ts.map +1 -0
- package/mcp-server/dist/services/vector-cache.js +271 -0
- package/mcp-server/dist/services/vector-cache.js.map +1 -0
- package/mcp-server/dist/services/whiteboard-geometry.d.ts +305 -0
- package/mcp-server/dist/services/whiteboard-geometry.d.ts.map +1 -0
- package/mcp-server/dist/services/whiteboard-geometry.js +666 -0
- package/mcp-server/dist/services/whiteboard-geometry.js.map +1 -0
- package/mcp-server/dist/tools/agents.d.ts +212 -0
- package/mcp-server/dist/tools/agents.d.ts.map +1 -0
- package/mcp-server/dist/tools/agents.js +407 -0
- package/mcp-server/dist/tools/agents.js.map +1 -0
- package/mcp-server/dist/tools/bluesky.d.ts +39 -0
- package/mcp-server/dist/tools/bluesky.d.ts.map +1 -0
- package/mcp-server/dist/tools/bluesky.js +1144 -0
- package/mcp-server/dist/tools/bluesky.js.map +1 -0
- package/mcp-server/dist/tools/browser-advanced.d.ts +58 -0
- package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -0
- package/mcp-server/dist/tools/browser-advanced.js +106 -0
- package/mcp-server/dist/tools/browser-advanced.js.map +1 -0
- package/mcp-server/dist/tools/browser-batch.d.ts +99 -0
- package/mcp-server/dist/tools/browser-batch.d.ts.map +1 -0
- package/mcp-server/dist/tools/browser-batch.js +187 -0
- package/mcp-server/dist/tools/browser-batch.js.map +1 -0
- package/mcp-server/dist/tools/browser-cheatsheet.d.ts +21 -0
- package/mcp-server/dist/tools/browser-cheatsheet.d.ts.map +1 -0
- package/mcp-server/dist/tools/browser-cheatsheet.js +144 -0
- package/mcp-server/dist/tools/browser-cheatsheet.js.map +1 -0
- package/mcp-server/dist/tools/browser-interact.d.ts +239 -0
- package/mcp-server/dist/tools/browser-interact.d.ts.map +1 -0
- package/mcp-server/dist/tools/browser-interact.js +300 -0
- package/mcp-server/dist/tools/browser-interact.js.map +1 -0
- package/mcp-server/dist/tools/browser-navigate.d.ts +90 -0
- package/mcp-server/dist/tools/browser-navigate.d.ts.map +1 -0
- package/mcp-server/dist/tools/browser-navigate.js +142 -0
- package/mcp-server/dist/tools/browser-navigate.js.map +1 -0
- package/mcp-server/dist/tools/browser-observe.d.ts +561 -0
- package/mcp-server/dist/tools/browser-observe.d.ts.map +1 -0
- package/mcp-server/dist/tools/browser-observe.js +2009 -0
- package/mcp-server/dist/tools/browser-observe.js.map +1 -0
- package/mcp-server/dist/tools/browser.d.ts +34 -0
- package/mcp-server/dist/tools/browser.d.ts.map +1 -0
- package/mcp-server/dist/tools/browser.js +112 -0
- package/mcp-server/dist/tools/browser.js.map +1 -0
- package/mcp-server/dist/tools/card-tools.d.ts +82 -0
- package/mcp-server/dist/tools/card-tools.d.ts.map +1 -0
- package/mcp-server/dist/tools/card-tools.js +137 -0
- package/mcp-server/dist/tools/card-tools.js.map +1 -0
- package/mcp-server/dist/tools/card.d.ts +8 -0
- package/mcp-server/dist/tools/card.d.ts.map +1 -0
- package/mcp-server/dist/tools/card.js +16 -0
- package/mcp-server/dist/tools/card.js.map +1 -0
- package/mcp-server/dist/tools/category.d.ts +32 -0
- package/mcp-server/dist/tools/category.d.ts.map +1 -0
- package/mcp-server/dist/tools/category.js +290 -0
- package/mcp-server/dist/tools/category.js.map +1 -0
- package/mcp-server/dist/tools/choice.d.ts +160 -0
- package/mcp-server/dist/tools/choice.d.ts.map +1 -0
- package/mcp-server/dist/tools/choice.js +80 -0
- package/mcp-server/dist/tools/choice.js.map +1 -0
- package/mcp-server/dist/tools/computer.d.ts +71 -0
- package/mcp-server/dist/tools/computer.d.ts.map +1 -0
- package/mcp-server/dist/tools/computer.js +174 -0
- package/mcp-server/dist/tools/computer.js.map +1 -0
- package/mcp-server/dist/tools/discord-channel.d.ts +44 -0
- package/mcp-server/dist/tools/discord-channel.d.ts.map +1 -0
- package/mcp-server/dist/tools/discord-channel.js +236 -0
- package/mcp-server/dist/tools/discord-channel.js.map +1 -0
- package/mcp-server/dist/tools/discord-guild.d.ts +20 -0
- package/mcp-server/dist/tools/discord-guild.d.ts.map +1 -0
- package/mcp-server/dist/tools/discord-guild.js +138 -0
- package/mcp-server/dist/tools/discord-guild.js.map +1 -0
- package/mcp-server/dist/tools/discord-member.d.ts +26 -0
- package/mcp-server/dist/tools/discord-member.d.ts.map +1 -0
- package/mcp-server/dist/tools/discord-member.js +122 -0
- package/mcp-server/dist/tools/discord-member.js.map +1 -0
- package/mcp-server/dist/tools/discord-message.d.ts +36 -0
- package/mcp-server/dist/tools/discord-message.d.ts.map +1 -0
- package/mcp-server/dist/tools/discord-message.js +184 -0
- package/mcp-server/dist/tools/discord-message.js.map +1 -0
- package/mcp-server/dist/tools/discord-onboarding.d.ts +32 -0
- package/mcp-server/dist/tools/discord-onboarding.d.ts.map +1 -0
- package/mcp-server/dist/tools/discord-onboarding.js +179 -0
- package/mcp-server/dist/tools/discord-onboarding.js.map +1 -0
- package/mcp-server/dist/tools/discord-role.d.ts +34 -0
- package/mcp-server/dist/tools/discord-role.d.ts.map +1 -0
- package/mcp-server/dist/tools/discord-role.js +178 -0
- package/mcp-server/dist/tools/discord-role.js.map +1 -0
- package/mcp-server/dist/tools/discord-thread.d.ts +28 -0
- package/mcp-server/dist/tools/discord-thread.d.ts.map +1 -0
- package/mcp-server/dist/tools/discord-thread.js +88 -0
- package/mcp-server/dist/tools/discord-thread.js.map +1 -0
- package/mcp-server/dist/tools/discord-webhook.d.ts +32 -0
- package/mcp-server/dist/tools/discord-webhook.d.ts.map +1 -0
- package/mcp-server/dist/tools/discord-webhook.js +154 -0
- package/mcp-server/dist/tools/discord-webhook.js.map +1 -0
- package/mcp-server/dist/tools/discord.d.ts +7 -0
- package/mcp-server/dist/tools/discord.d.ts.map +1 -0
- package/mcp-server/dist/tools/discord.js +25 -0
- package/mcp-server/dist/tools/discord.js.map +1 -0
- package/mcp-server/dist/tools/fb-groups.d.ts +98 -0
- package/mcp-server/dist/tools/fb-groups.d.ts.map +1 -0
- package/mcp-server/dist/tools/fb-groups.js +369 -0
- package/mcp-server/dist/tools/fb-groups.js.map +1 -0
- package/mcp-server/dist/tools/forget.d.ts +14 -0
- package/mcp-server/dist/tools/forget.d.ts.map +1 -0
- package/mcp-server/dist/tools/forget.js +26 -0
- package/mcp-server/dist/tools/forget.js.map +1 -0
- package/mcp-server/dist/tools/git-tools.d.ts +24 -0
- package/mcp-server/dist/tools/git-tools.d.ts.map +1 -0
- package/mcp-server/dist/tools/git-tools.js +107 -0
- package/mcp-server/dist/tools/git-tools.js.map +1 -0
- package/mcp-server/dist/tools/git.d.ts +7 -0
- package/mcp-server/dist/tools/git.d.ts.map +1 -0
- package/mcp-server/dist/tools/git.js +11 -0
- package/mcp-server/dist/tools/git.js.map +1 -0
- package/mcp-server/dist/tools/gsc/experience.d.ts +135 -0
- package/mcp-server/dist/tools/gsc/experience.d.ts.map +1 -0
- package/mcp-server/dist/tools/gsc/experience.js +351 -0
- package/mcp-server/dist/tools/gsc/experience.js.map +1 -0
- package/mcp-server/dist/tools/gsc/helpers.d.ts +78 -0
- package/mcp-server/dist/tools/gsc/helpers.d.ts.map +1 -0
- package/mcp-server/dist/tools/gsc/helpers.js +258 -0
- package/mcp-server/dist/tools/gsc/helpers.js.map +1 -0
- package/mcp-server/dist/tools/gsc/indexing.d.ts +121 -0
- package/mcp-server/dist/tools/gsc/indexing.d.ts.map +1 -0
- package/mcp-server/dist/tools/gsc/indexing.js +357 -0
- package/mcp-server/dist/tools/gsc/indexing.js.map +1 -0
- package/mcp-server/dist/tools/gsc/inspect.d.ts +78 -0
- package/mcp-server/dist/tools/gsc/inspect.d.ts.map +1 -0
- package/mcp-server/dist/tools/gsc/inspect.js +321 -0
- package/mcp-server/dist/tools/gsc/inspect.js.map +1 -0
- package/mcp-server/dist/tools/gsc/navigate.d.ts +44 -0
- package/mcp-server/dist/tools/gsc/navigate.d.ts.map +1 -0
- package/mcp-server/dist/tools/gsc/navigate.js +197 -0
- package/mcp-server/dist/tools/gsc/navigate.js.map +1 -0
- package/mcp-server/dist/tools/gsc/performance.d.ts +84 -0
- package/mcp-server/dist/tools/gsc/performance.d.ts.map +1 -0
- package/mcp-server/dist/tools/gsc/performance.js +274 -0
- package/mcp-server/dist/tools/gsc/performance.js.map +1 -0
- package/mcp-server/dist/tools/gsc/settings.d.ts +153 -0
- package/mcp-server/dist/tools/gsc/settings.d.ts.map +1 -0
- package/mcp-server/dist/tools/gsc/settings.js +425 -0
- package/mcp-server/dist/tools/gsc/settings.js.map +1 -0
- package/mcp-server/dist/tools/gsc.d.ts +7 -0
- package/mcp-server/dist/tools/gsc.d.ts.map +1 -0
- package/mcp-server/dist/tools/gsc.js +51 -0
- package/mcp-server/dist/tools/gsc.js.map +1 -0
- package/mcp-server/dist/tools/image-tools.d.ts +24 -0
- package/mcp-server/dist/tools/image-tools.d.ts.map +1 -0
- package/mcp-server/dist/tools/image-tools.js +80 -0
- package/mcp-server/dist/tools/image-tools.js.map +1 -0
- package/mcp-server/dist/tools/image.d.ts +10 -0
- package/mcp-server/dist/tools/image.d.ts.map +1 -0
- package/mcp-server/dist/tools/image.js +14 -0
- package/mcp-server/dist/tools/image.js.map +1 -0
- package/mcp-server/dist/tools/leonardo-browser-tools.d.ts +97 -0
- package/mcp-server/dist/tools/leonardo-browser-tools.d.ts.map +1 -0
- package/mcp-server/dist/tools/leonardo-browser-tools.js +228 -0
- package/mcp-server/dist/tools/leonardo-browser-tools.js.map +1 -0
- package/mcp-server/dist/tools/leonardo.d.ts +13 -0
- package/mcp-server/dist/tools/leonardo.d.ts.map +1 -0
- package/mcp-server/dist/tools/leonardo.js +21 -0
- package/mcp-server/dist/tools/leonardo.js.map +1 -0
- package/mcp-server/dist/tools/loop.d.ts +30 -0
- package/mcp-server/dist/tools/loop.d.ts.map +1 -0
- package/mcp-server/dist/tools/loop.js +401 -0
- package/mcp-server/dist/tools/loop.js.map +1 -0
- package/mcp-server/dist/tools/memories.d.ts +56 -0
- package/mcp-server/dist/tools/memories.d.ts.map +1 -0
- package/mcp-server/dist/tools/memories.js +171 -0
- package/mcp-server/dist/tools/memories.js.map +1 -0
- package/mcp-server/dist/tools/morelogin.d.ts +24 -0
- package/mcp-server/dist/tools/morelogin.d.ts.map +1 -0
- package/mcp-server/dist/tools/morelogin.js +79 -0
- package/mcp-server/dist/tools/morelogin.js.map +1 -0
- package/mcp-server/dist/tools/profile.d.ts +17 -0
- package/mcp-server/dist/tools/profile.d.ts.map +1 -0
- package/mcp-server/dist/tools/profile.js +114 -0
- package/mcp-server/dist/tools/profile.js.map +1 -0
- package/mcp-server/dist/tools/recall.d.ts +71 -0
- package/mcp-server/dist/tools/recall.d.ts.map +1 -0
- package/mcp-server/dist/tools/recall.js +147 -0
- package/mcp-server/dist/tools/recall.js.map +1 -0
- package/mcp-server/dist/tools/reflect.d.ts +56 -0
- package/mcp-server/dist/tools/reflect.d.ts.map +1 -0
- package/mcp-server/dist/tools/reflect.js +157 -0
- package/mcp-server/dist/tools/reflect.js.map +1 -0
- package/mcp-server/dist/tools/remember.d.ts +62 -0
- package/mcp-server/dist/tools/remember.d.ts.map +1 -0
- package/mcp-server/dist/tools/remember.js +201 -0
- package/mcp-server/dist/tools/remember.js.map +1 -0
- package/mcp-server/dist/tools/response.d.ts +23 -0
- package/mcp-server/dist/tools/response.d.ts.map +1 -0
- package/mcp-server/dist/tools/response.js +24 -0
- package/mcp-server/dist/tools/response.js.map +1 -0
- package/mcp-server/dist/tools/restore.d.ts +14 -0
- package/mcp-server/dist/tools/restore.d.ts.map +1 -0
- package/mcp-server/dist/tools/restore.js +23 -0
- package/mcp-server/dist/tools/restore.js.map +1 -0
- package/mcp-server/dist/tools/style-guide-tools.d.ts +51 -0
- package/mcp-server/dist/tools/style-guide-tools.d.ts.map +1 -0
- package/mcp-server/dist/tools/style-guide-tools.js +231 -0
- package/mcp-server/dist/tools/style-guide-tools.js.map +1 -0
- package/mcp-server/dist/tools/style-guide.d.ts +8 -0
- package/mcp-server/dist/tools/style-guide.d.ts.map +1 -0
- package/mcp-server/dist/tools/style-guide.js +12 -0
- package/mcp-server/dist/tools/style-guide.js.map +1 -0
- package/mcp-server/dist/tools/sync.d.ts +20 -0
- package/mcp-server/dist/tools/sync.d.ts.map +1 -0
- package/mcp-server/dist/tools/sync.js +156 -0
- package/mcp-server/dist/tools/sync.js.map +1 -0
- package/mcp-server/dist/tools/tictactoe-tools.d.ts +18 -0
- package/mcp-server/dist/tools/tictactoe-tools.d.ts.map +1 -0
- package/mcp-server/dist/tools/tictactoe-tools.js +78 -0
- package/mcp-server/dist/tools/tictactoe-tools.js.map +1 -0
- package/mcp-server/dist/tools/tictactoe.d.ts +7 -0
- package/mcp-server/dist/tools/tictactoe.d.ts.map +1 -0
- package/mcp-server/dist/tools/tictactoe.js +11 -0
- package/mcp-server/dist/tools/tictactoe.js.map +1 -0
- package/mcp-server/dist/tools/utils.d.ts +19 -0
- package/mcp-server/dist/tools/utils.d.ts.map +1 -0
- package/mcp-server/dist/tools/utils.js +54 -0
- package/mcp-server/dist/tools/utils.js.map +1 -0
- package/mcp-server/dist/tools/whiteboard-format.d.ts +88 -0
- package/mcp-server/dist/tools/whiteboard-format.d.ts.map +1 -0
- package/mcp-server/dist/tools/whiteboard-format.js +337 -0
- package/mcp-server/dist/tools/whiteboard-format.js.map +1 -0
- package/mcp-server/dist/tools/whiteboard-tools.d.ts +326 -0
- package/mcp-server/dist/tools/whiteboard-tools.d.ts.map +1 -0
- package/mcp-server/dist/tools/whiteboard-tools.js +222 -0
- package/mcp-server/dist/tools/whiteboard-tools.js.map +1 -0
- package/mcp-server/dist/tools/whiteboard.d.ts +8 -0
- package/mcp-server/dist/tools/whiteboard.d.ts.map +1 -0
- package/mcp-server/dist/tools/whiteboard.js +16 -0
- package/mcp-server/dist/tools/whiteboard.js.map +1 -0
- package/mcp-server/dist/tools/youtube/analytics.d.ts +46 -0
- package/mcp-server/dist/tools/youtube/analytics.d.ts.map +1 -0
- package/mcp-server/dist/tools/youtube/analytics.js +83 -0
- package/mcp-server/dist/tools/youtube/analytics.js.map +1 -0
- package/mcp-server/dist/tools/youtube/dedup.d.ts +35 -0
- package/mcp-server/dist/tools/youtube/dedup.d.ts.map +1 -0
- package/mcp-server/dist/tools/youtube/dedup.js +56 -0
- package/mcp-server/dist/tools/youtube/dedup.js.map +1 -0
- package/mcp-server/dist/tools/youtube/download.d.ts +31 -0
- package/mcp-server/dist/tools/youtube/download.d.ts.map +1 -0
- package/mcp-server/dist/tools/youtube/download.js +30 -0
- package/mcp-server/dist/tools/youtube/download.js.map +1 -0
- package/mcp-server/dist/tools/youtube/helpers.d.ts +66 -0
- package/mcp-server/dist/tools/youtube/helpers.d.ts.map +1 -0
- package/mcp-server/dist/tools/youtube/helpers.js +143 -0
- package/mcp-server/dist/tools/youtube/helpers.js.map +1 -0
- package/mcp-server/dist/tools/youtube/media.d.ts +43 -0
- package/mcp-server/dist/tools/youtube/media.d.ts.map +1 -0
- package/mcp-server/dist/tools/youtube/media.js +97 -0
- package/mcp-server/dist/tools/youtube/media.js.map +1 -0
- package/mcp-server/dist/tools/youtube/metadata.d.ts +33 -0
- package/mcp-server/dist/tools/youtube/metadata.d.ts.map +1 -0
- package/mcp-server/dist/tools/youtube/metadata.js +106 -0
- package/mcp-server/dist/tools/youtube/metadata.js.map +1 -0
- package/mcp-server/dist/tools/youtube/navigate.d.ts +30 -0
- package/mcp-server/dist/tools/youtube/navigate.d.ts.map +1 -0
- package/mcp-server/dist/tools/youtube/navigate.js +71 -0
- package/mcp-server/dist/tools/youtube/navigate.js.map +1 -0
- package/mcp-server/dist/tools/youtube/playlist.d.ts +29 -0
- package/mcp-server/dist/tools/youtube/playlist.d.ts.map +1 -0
- package/mcp-server/dist/tools/youtube/playlist.js +128 -0
- package/mcp-server/dist/tools/youtube/playlist.js.map +1 -0
- package/mcp-server/dist/tools/youtube/schedule.d.ts +31 -0
- package/mcp-server/dist/tools/youtube/schedule.d.ts.map +1 -0
- package/mcp-server/dist/tools/youtube/schedule.js +147 -0
- package/mcp-server/dist/tools/youtube/schedule.js.map +1 -0
- package/mcp-server/dist/tools/youtube/source.d.ts +36 -0
- package/mcp-server/dist/tools/youtube/source.d.ts.map +1 -0
- package/mcp-server/dist/tools/youtube/source.js +85 -0
- package/mcp-server/dist/tools/youtube/source.js.map +1 -0
- package/mcp-server/dist/tools/youtube/upload.d.ts +53 -0
- package/mcp-server/dist/tools/youtube/upload.d.ts.map +1 -0
- package/mcp-server/dist/tools/youtube/upload.js +255 -0
- package/mcp-server/dist/tools/youtube/upload.js.map +1 -0
- package/mcp-server/dist/tools/youtube.d.ts +12 -0
- package/mcp-server/dist/tools/youtube.d.ts.map +1 -0
- package/mcp-server/dist/tools/youtube.js +38 -0
- package/mcp-server/dist/tools/youtube.js.map +1 -0
- package/mcp-server/dist/tui.d.ts +3 -0
- package/mcp-server/dist/tui.d.ts.map +1 -0
- package/mcp-server/dist/tui.js +806 -0
- package/mcp-server/dist/tui.js.map +1 -0
- package/mcp-server/dist/types.d.ts +77 -0
- package/mcp-server/dist/types.d.ts.map +1 -0
- package/mcp-server/dist/types.js +2 -0
- package/mcp-server/dist/types.js.map +1 -0
- package/mcp-server/package-lock.json +4798 -0
- package/mcp-server/package.json +55 -38
- package/mcp-server/run.mjs +12 -2
- package/mcp-server/src/config.ts +48 -3
- package/mcp-server/src/http.ts +296 -93
- package/mcp-server/src/index.ts +546 -203
- package/mcp-server/src/preload-http.ts +19 -18
- package/mcp-server/src/preload.ts +19 -18
- package/mcp-server/src/scripts/setup-embeddings.ts +9 -0
- package/mcp-server/src/services/assistant-judgments.ts +157 -0
- package/mcp-server/src/services/browser-assist-gate.ts +383 -0
- package/mcp-server/src/services/browser-assist.ts +267 -0
- package/mcp-server/src/services/browser-bench.ts +477 -0
- package/mcp-server/src/services/browser-judgments.ts +414 -0
- package/mcp-server/src/services/browser-risk.ts +484 -0
- package/mcp-server/src/services/categories.ts +36 -19
- package/mcp-server/src/services/codex-config-heal.ts +403 -0
- package/mcp-server/src/services/desktop-assist-gate.ts +251 -0
- package/mcp-server/src/services/desktop-assist.ts +308 -0
- package/mcp-server/src/services/desktop-bench.ts +372 -0
- package/mcp-server/src/services/desktop-client.ts +76 -0
- package/mcp-server/src/services/desktop-judgments.ts +218 -0
- package/mcp-server/src/services/desktop-risk.ts +743 -0
- package/mcp-server/src/services/edit-stale.ts +299 -0
- package/mcp-server/src/services/embedding-service.ts +108 -0
- package/mcp-server/src/services/embedding-worker.ts +46 -0
- package/mcp-server/src/services/fb-regions.ts +221 -0
- package/mcp-server/src/services/file-checksums.ts +26 -9
- package/mcp-server/src/services/file-excerpt.ts +59 -0
- package/mcp-server/src/services/identity.ts +291 -0
- package/mcp-server/src/services/local-embeddings.ts +2 -77
- package/mcp-server/src/services/memory-client.ts +23 -0
- package/mcp-server/src/services/memory-judge-backfill.ts +462 -0
- package/mcp-server/src/services/memory-judgments.ts +901 -0
- package/mcp-server/src/services/memory-maintenance.ts +360 -0
- package/mcp-server/src/services/memory-retrieval.ts +349 -0
- package/mcp-server/src/services/memory-schema.ts +280 -0
- package/mcp-server/src/services/memory-sessions.ts +87 -0
- package/mcp-server/src/services/memory-triage.ts +182 -0
- package/mcp-server/src/services/memory-verification.ts +68 -0
- package/mcp-server/src/services/memory-writer.ts +125 -0
- package/mcp-server/src/services/neural-interface.ts +1217 -73
- package/mcp-server/src/services/profiles.ts +428 -0
- package/mcp-server/src/services/secret-gate.ts +52 -0
- package/mcp-server/src/services/server-instructions.ts +122 -0
- package/mcp-server/src/services/sqlite.ts +1456 -823
- package/mcp-server/src/services/typesafe-bench.ts +247 -0
- package/mcp-server/src/services/typesafe-config.ts +790 -0
- package/mcp-server/src/services/typesafe.ts +390 -0
- package/mcp-server/src/services/vector-cache.ts +255 -0
- package/mcp-server/src/services/whiteboard-geometry.ts +711 -0
- package/mcp-server/src/tools/agents.ts +539 -0
- package/mcp-server/src/tools/bluesky.ts +1186 -0
- package/mcp-server/src/tools/browser-advanced.ts +15 -6
- package/mcp-server/src/tools/browser-batch.ts +178 -0
- package/mcp-server/src/tools/browser-cheatsheet.ts +155 -0
- package/mcp-server/src/tools/browser-interact.ts +362 -255
- package/mcp-server/src/tools/browser-navigate.ts +164 -77
- package/mcp-server/src/tools/browser-observe.ts +2222 -1330
- package/mcp-server/src/tools/browser.ts +181 -107
- package/mcp-server/src/tools/card.ts +7 -5
- package/mcp-server/src/tools/choice.ts +103 -0
- package/mcp-server/src/tools/computer.ts +190 -0
- package/mcp-server/src/tools/discord.ts +10 -23
- package/mcp-server/src/tools/fb-groups.ts +387 -0
- package/mcp-server/src/tools/forget.ts +1 -1
- package/mcp-server/src/tools/git.ts +3 -1
- package/mcp-server/src/tools/gsc/experience.ts +440 -0
- package/mcp-server/src/tools/gsc/helpers.ts +288 -0
- package/mcp-server/src/tools/gsc/indexing.ts +495 -0
- package/mcp-server/src/tools/gsc/inspect.ts +391 -0
- package/mcp-server/src/tools/gsc/navigate.ts +236 -0
- package/mcp-server/src/tools/gsc/performance.ts +352 -0
- package/mcp-server/src/tools/gsc/settings.ts +564 -0
- package/mcp-server/src/tools/gsc.ts +95 -0
- package/mcp-server/src/tools/image.ts +3 -1
- package/mcp-server/src/tools/leonardo-browser-tools.ts +47 -37
- package/mcp-server/src/tools/leonardo.ts +7 -5
- package/mcp-server/src/tools/loop.ts +118 -25
- package/mcp-server/src/tools/memories.ts +65 -5
- package/mcp-server/src/tools/morelogin.ts +81 -0
- package/mcp-server/src/tools/profile.ts +122 -0
- package/mcp-server/src/tools/recall.ts +105 -261
- package/mcp-server/src/tools/reflect.ts +171 -145
- package/mcp-server/src/tools/remember.ts +223 -115
- package/mcp-server/src/tools/style-guide-tools.ts +250 -0
- package/mcp-server/src/tools/style-guide.ts +16 -0
- package/mcp-server/src/tools/sync.ts +66 -9
- package/mcp-server/src/tools/tictactoe.ts +3 -1
- package/mcp-server/src/tools/utils.ts +22 -0
- package/mcp-server/src/tools/whiteboard-format.ts +394 -0
- package/mcp-server/src/tools/whiteboard-tools.ts +191 -183
- package/mcp-server/src/tools/whiteboard.ts +7 -5
- package/mcp-server/src/tools/youtube/analytics.ts +106 -0
- package/mcp-server/src/tools/youtube/dedup.ts +57 -0
- package/mcp-server/src/tools/youtube/download.ts +41 -0
- package/mcp-server/src/tools/youtube/helpers.ts +183 -0
- package/mcp-server/src/tools/youtube/media.ts +109 -0
- package/mcp-server/src/tools/youtube/metadata.ts +112 -0
- package/mcp-server/src/tools/youtube/navigate.ts +81 -0
- package/mcp-server/src/tools/youtube/playlist.ts +134 -0
- package/mcp-server/src/tools/youtube/schedule.ts +158 -0
- package/mcp-server/src/tools/youtube/source.ts +101 -0
- package/mcp-server/src/tools/youtube/upload.ts +296 -0
- package/mcp-server/src/tools/youtube.ts +47 -0
- package/mcp-server/src/tui.ts +8 -9
- package/neural-interface/games/TicTacToe/1.svg +1 -0
- package/neural-interface/games/TicTacToe/2.svg +1 -0
- package/neural-interface/games/TicTacToe/3.svg +1 -0
- package/neural-interface/games/TicTacToe/4.svg +1 -0
- package/neural-interface/games/TicTacToe/5.svg +1 -0
- package/neural-interface/games/TicTacToe/6.svg +1 -0
- package/neural-interface/games/TicTacToe/7.svg +1 -0
- package/neural-interface/games/TicTacToe/8.svg +1 -0
- package/neural-interface/games/TicTacToe/9.svg +1 -0
- package/neural-interface/games/TicTacToe/Board.svg +1 -0
- package/neural-interface/games/TicTacToe/Circle.svg +1 -0
- package/neural-interface/games/TicTacToe/Cross.svg +1 -0
- package/neural-interface/i18n/en.json +7022 -0
- package/neural-interface/i18n/pt-BR.json +7026 -0
- package/neural-interface/lib/assistant-api.js +1005 -0
- package/neural-interface/lib/assistant-attachments.js +121 -0
- package/neural-interface/lib/assistant-brains/claude.js +207 -0
- package/neural-interface/lib/assistant-brains/codex-browser-policy-hook.mjs +43 -0
- package/neural-interface/lib/assistant-brains/codex-route-gate-hook.mjs +56 -0
- package/neural-interface/lib/assistant-brains/codex.js +213 -0
- package/neural-interface/lib/assistant-brains/opencode-browser-policy.js +47 -0
- package/neural-interface/lib/assistant-brains/opencode-route-gate.js +62 -0
- package/neural-interface/lib/assistant-brains/opencode.js +320 -0
- package/neural-interface/lib/assistant-budget.js +318 -0
- package/neural-interface/lib/assistant-catalog.js +731 -0
- package/neural-interface/lib/assistant-clarify.js +664 -0
- package/neural-interface/lib/assistant-config.js +232 -0
- package/neural-interface/lib/assistant-dispatch.js +2744 -0
- package/neural-interface/lib/assistant-envelope.js +582 -0
- package/neural-interface/lib/assistant-evidence.js +236 -0
- package/neural-interface/lib/assistant-hidden-models.js +272 -0
- package/neural-interface/lib/assistant-jev.js +117 -0
- package/neural-interface/lib/assistant-judgments.js +111 -0
- package/neural-interface/lib/assistant-media.js +335 -0
- package/neural-interface/lib/assistant-memory.js +398 -0
- package/neural-interface/lib/assistant-persona.js +444 -0
- package/neural-interface/lib/assistant-plan-permissions.js +448 -0
- package/neural-interface/lib/assistant-playbooks/design.md +87 -0
- package/neural-interface/lib/assistant-playbooks.js +72 -0
- package/neural-interface/lib/assistant-pricing.js +159 -0
- package/neural-interface/lib/assistant-route-gate-codex.js +163 -0
- package/neural-interface/lib/assistant-route-gate.js +212 -0
- package/neural-interface/lib/assistant-router.js +1324 -0
- package/neural-interface/lib/assistant-runtime.js +3337 -0
- package/neural-interface/lib/assistant-task-prompt.js +472 -0
- package/neural-interface/lib/assistant-usage.js +1688 -0
- package/neural-interface/lib/augmented-path.js +70 -0
- package/neural-interface/lib/automation-storage-migration.js +54 -0
- package/neural-interface/lib/backup-service.js +851 -0
- package/neural-interface/lib/backup-zip-reader.js +262 -0
- package/neural-interface/lib/browser-assist-api.js +41 -0
- package/neural-interface/lib/browser-console.js +176 -0
- package/neural-interface/lib/browser-execution.js +241 -0
- package/neural-interface/lib/browser-extraction.js +191 -0
- package/neural-interface/lib/browser-language.js +83 -0
- package/neural-interface/lib/browser-screenshot.js +399 -0
- package/neural-interface/lib/browser-semantic-context.js +639 -0
- package/neural-interface/lib/browser-snapshots.js +192 -0
- package/neural-interface/lib/browser-tab-recovery.js +119 -0
- package/neural-interface/lib/browser-targets.js +70 -0
- package/neural-interface/lib/browser-tool-policy.js +926 -0
- package/neural-interface/lib/claude-accounts.js +230 -0
- package/neural-interface/lib/claude-agent-bridge.js +3203 -0
- package/neural-interface/lib/claude-bypass-policy.js +99 -0
- package/neural-interface/lib/claude-executable.js +241 -0
- package/neural-interface/lib/claude-history.js +429 -0
- package/neural-interface/lib/claude-model-catalog.js +444 -0
- package/neural-interface/lib/claude-panel-requests.js +165 -0
- package/neural-interface/lib/claude-panel-session.js +272 -0
- package/neural-interface/lib/claude-permission-rules.js +153 -0
- package/neural-interface/lib/claude-session-cleanup.js +71 -0
- package/neural-interface/lib/claude-session-list.js +82 -0
- package/neural-interface/lib/claude-session-ops.js +140 -0
- package/neural-interface/lib/claude-settings-view.js +51 -0
- package/neural-interface/lib/claude-skin-connect.js +79 -0
- package/neural-interface/lib/claude-stall-policy.js +7 -0
- package/neural-interface/lib/claude-temporary.js +435 -0
- package/neural-interface/lib/cli-update-planner.js +312 -0
- package/neural-interface/lib/codex-capabilities.d.ts +41 -0
- package/neural-interface/lib/codex-capabilities.js +148 -0
- package/neural-interface/lib/codex-collaboration-mode.js +17 -0
- package/neural-interface/lib/codex-compat-rpc.js +241 -0
- package/neural-interface/lib/codex-mcp-approvals.js +56 -0
- package/neural-interface/lib/codex-mcp-apps.js +47 -0
- package/neural-interface/lib/codex-model-context.js +202 -0
- package/neural-interface/lib/codex-plan-store.js +71 -0
- package/neural-interface/lib/codex-request-journal.js +242 -0
- package/neural-interface/lib/codex-runtime-path.js +213 -0
- package/neural-interface/lib/codex-session-catalog.js +231 -0
- package/neural-interface/lib/codex-session-settings.js +46 -0
- package/neural-interface/lib/codex-sidepanel-permissions.js +110 -0
- package/neural-interface/lib/codex-thread-history.js +165 -0
- package/neural-interface/lib/codex-user-verification.js +34 -0
- package/neural-interface/lib/codex-writer-lifecycle.js +152 -0
- package/neural-interface/lib/confined-fs.js +256 -0
- package/neural-interface/lib/db.js +922 -0
- package/neural-interface/lib/design-md.js +9 -0
- package/neural-interface/lib/desktop/api.js +92 -0
- package/neural-interface/lib/desktop/audit.js +62 -0
- package/neural-interface/lib/desktop/build.js +423 -0
- package/neural-interface/lib/desktop/config.js +606 -0
- package/neural-interface/lib/desktop/coords.js +76 -0
- package/neural-interface/lib/desktop/fake-helper.js +1192 -0
- package/neural-interface/lib/desktop/frames.js +77 -0
- package/neural-interface/lib/desktop/grants.js +84 -0
- package/neural-interface/lib/desktop/guards.js +170 -0
- package/neural-interface/lib/desktop/helper/SynabunDesktop.swift +3056 -0
- package/neural-interface/lib/desktop/lease.js +51 -0
- package/neural-interface/lib/desktop/manager.js +545 -0
- package/neural-interface/lib/desktop/press-contexts.js +103 -0
- package/neural-interface/lib/desktop/protocol.js +495 -0
- package/neural-interface/lib/desktop/service.js +1202 -0
- package/neural-interface/lib/effort-levels.js +148 -0
- package/neural-interface/lib/event-loop-monitor.js +67 -0
- package/neural-interface/lib/exec-loop-command.js +209 -0
- package/neural-interface/lib/folder-picker.ps1 +77 -0
- package/neural-interface/lib/http-guards.js +287 -0
- package/neural-interface/lib/jsonl-lines.js +94 -0
- package/neural-interface/lib/loop-logger.js +127 -0
- package/neural-interface/lib/mcp-client-config.js +133 -0
- package/neural-interface/lib/mcp-installer.js +487 -0
- package/neural-interface/lib/mcp-profile-refresh-coordinator.js +78 -0
- package/neural-interface/lib/mcp-profile-servers.js +120 -0
- package/neural-interface/lib/memo-cache.js +84 -0
- package/neural-interface/lib/memory-api.js +758 -0
- package/neural-interface/lib/memory-map-api.js +1150 -0
- package/neural-interface/lib/memory-map-layout.js +872 -0
- package/neural-interface/lib/memory-map-worker.js +165 -0
- package/neural-interface/lib/memory-session-capture.js +81 -0
- package/neural-interface/lib/memory-timers.js +62 -0
- package/neural-interface/lib/morelogin.js +301 -0
- package/neural-interface/lib/native-binary-runtime.js +382 -0
- package/neural-interface/lib/native-loop-goal.js +33 -0
- package/neural-interface/lib/native-loop-providers.js +1002 -0
- package/neural-interface/lib/native-loop-runtime.js +747 -0
- package/neural-interface/lib/offline-page.js +54 -0
- package/neural-interface/lib/opencode-hidden-models.js +113 -0
- package/neural-interface/lib/opencode-history.js +253 -0
- package/neural-interface/lib/opencode-runtime-config.js +58 -0
- package/neural-interface/lib/opencode-v2-client.js +486 -0
- package/neural-interface/lib/opencode-v2-ws-requests.js +955 -0
- package/neural-interface/lib/path-confine.js +213 -0
- package/neural-interface/lib/plugin-installer.js +264 -0
- package/neural-interface/lib/project-storage.js +766 -0
- package/neural-interface/lib/pty-host/core.js +603 -0
- package/neural-interface/lib/pty-host/flow.js +43 -0
- package/neural-interface/lib/pty-host/host.js +47 -0
- package/neural-interface/lib/pty-host/manager.js +360 -0
- package/neural-interface/lib/pty-host/protocol.js +81 -0
- package/neural-interface/lib/pty-host/snapshot.js +133 -0
- package/neural-interface/lib/remote-policy.js +582 -0
- package/neural-interface/lib/rulesets/api.js +175 -0
- package/neural-interface/lib/rulesets/fs-safe.js +245 -0
- package/neural-interface/lib/rulesets/installer.js +1453 -0
- package/neural-interface/lib/rulesets/json-edit.js +186 -0
- package/neural-interface/lib/rulesets/lock.js +170 -0
- package/neural-interface/lib/rulesets/managed-text.js +314 -0
- package/neural-interface/lib/rulesets/normalise.js +24 -0
- package/neural-interface/lib/rulesets/render.js +84 -0
- package/neural-interface/lib/schedule-launch-intent.js +40 -0
- package/neural-interface/lib/session-cache-builder.js +524 -0
- package/neural-interface/lib/session-chunker.js +344 -0
- package/neural-interface/lib/session-indexer.js +327 -0
- package/neural-interface/lib/session-title-generator.js +232 -0
- package/neural-interface/lib/skill-prompt-bridge.js +11 -0
- package/neural-interface/lib/style-guide/api.js +375 -0
- package/neural-interface/lib/style-guide/color.js +352 -0
- package/neural-interface/lib/style-guide/export-css.js +99 -0
- package/neural-interface/lib/style-guide/export-dtcg.js +209 -0
- package/neural-interface/lib/style-guide/export-tailwind.js +102 -0
- package/neural-interface/lib/style-guide/fonts.json +227 -0
- package/neural-interface/lib/style-guide/import.js +1268 -0
- package/neural-interface/lib/style-guide/pointers.js +103 -0
- package/neural-interface/lib/style-guide/presets.js +232 -0
- package/neural-interface/lib/style-guide/render-design-md.js +319 -0
- package/neural-interface/lib/style-guide/schema.js +848 -0
- package/neural-interface/lib/style-guide/security.js +43 -0
- package/neural-interface/lib/style-guide/store.js +491 -0
- package/neural-interface/lib/style-guide/summary.js +106 -0
- package/neural-interface/lib/style-guide/tokens.js +170 -0
- package/neural-interface/lib/synabun-update-plan.js +324 -0
- package/neural-interface/lib/synabun-version.js +179 -0
- package/neural-interface/lib/system-restore.js +99 -0
- package/neural-interface/lib/terminal-env.js +86 -0
- package/neural-interface/lib/ui-blob-store.js +106 -0
- package/neural-interface/lib/vector-cache.js +2 -0
- package/neural-interface/lib/virtual-socket.js +60 -0
- package/neural-interface/lib/whatsapp/api.js +146 -0
- package/neural-interface/lib/whatsapp/auth-store.js +389 -0
- package/neural-interface/lib/whatsapp/baileys-adapter.js +457 -0
- package/neural-interface/lib/whatsapp/brain.js +128 -0
- package/neural-interface/lib/whatsapp/bridge.js +1499 -0
- package/neural-interface/lib/whatsapp/cards.js +519 -0
- package/neural-interface/lib/whatsapp/commands.js +92 -0
- package/neural-interface/lib/whatsapp/config.js +291 -0
- package/neural-interface/lib/whatsapp/connector/entry.mjs +25 -0
- package/neural-interface/lib/whatsapp/connector/manifest.json +6 -0
- package/neural-interface/lib/whatsapp/connector/npm-shrinkwrap.json +717 -0
- package/neural-interface/lib/whatsapp/connector/package.json +8 -0
- package/neural-interface/lib/whatsapp/fake-baileys.js +444 -0
- package/neural-interface/lib/whatsapp/format.js +552 -0
- package/neural-interface/lib/whatsapp/host-core.js +1225 -0
- package/neural-interface/lib/whatsapp/host.js +119 -0
- package/neural-interface/lib/whatsapp/identity.js +288 -0
- package/neural-interface/lib/whatsapp/inbound.js +149 -0
- package/neural-interface/lib/whatsapp/installer.js +562 -0
- package/neural-interface/lib/whatsapp/manager.js +638 -0
- package/neural-interface/lib/whatsapp/paths.js +81 -0
- package/neural-interface/lib/whatsapp/protocol.js +327 -0
- package/neural-interface/lib/whatsapp/qr-svg.js +57 -0
- package/neural-interface/lib/whatsapp/redact.js +130 -0
- package/neural-interface/lib/whatsapp/service.js +1305 -0
- package/neural-interface/lib/whatsapp/vendor/qrcodegen.js +848 -0
- package/neural-interface/package-lock.json +4431 -0
- package/neural-interface/package.json +58 -27
- package/neural-interface/public/apple-touch-icon.png +0 -0
- package/neural-interface/public/category-logos/synabun.png +0 -0
- package/neural-interface/public/claude.svg +1 -0
- package/neural-interface/public/favicon-16x16.png +0 -0
- package/neural-interface/public/favicon-32x32.png +0 -0
- package/neural-interface/public/icon-192.png +0 -0
- package/neural-interface/public/icon-512.png +0 -0
- package/neural-interface/public/index.html +32 -182
- package/neural-interface/public/index2d.html +2 -2
- package/neural-interface/public/install-app.html +31 -0
- package/neural-interface/public/logo-synabun.png +0 -0
- package/neural-interface/public/logoHD.png +0 -0
- package/neural-interface/public/manifest.json +2 -0
- package/neural-interface/public/mcp.svg +4 -0
- package/neural-interface/public/offline.html +670 -299
- package/neural-interface/public/onboarding.html +804 -161
- package/neural-interface/public/opencode-logo-dark-square.svg +1 -0
- package/neural-interface/public/shared/agent-runtime-options.js +596 -0
- package/neural-interface/public/shared/api.js +339 -28
- package/neural-interface/public/shared/assistant/asst-accounts.js +318 -0
- package/neural-interface/public/shared/assistant/asst-agents-dock.js +296 -0
- package/neural-interface/public/shared/assistant/asst-api.js +270 -0
- package/neural-interface/public/shared/assistant/asst-brain-picker.js +744 -0
- package/neural-interface/public/shared/assistant/asst-budget.js +333 -0
- package/neural-interface/public/shared/assistant/asst-composer.js +656 -0
- package/neural-interface/public/shared/assistant/asst-computer.js +803 -0
- package/neural-interface/public/shared/assistant/asst-control.js +1018 -0
- package/neural-interface/public/shared/assistant/asst-hosts.js +262 -0
- package/neural-interface/public/shared/assistant/asst-mascot.js +313 -0
- package/neural-interface/public/shared/assistant/asst-menu.js +375 -0
- package/neural-interface/public/shared/assistant/asst-panel.js +1845 -0
- package/neural-interface/public/shared/assistant/asst-rack-styles.js +586 -0
- package/neural-interface/public/shared/assistant/asst-render.js +3305 -0
- package/neural-interface/public/shared/assistant/asst-route.js +1653 -0
- package/neural-interface/public/shared/assistant/asst-roving.js +75 -0
- package/neural-interface/public/shared/assistant/asst-sanitize.js +117 -0
- package/neural-interface/public/shared/assistant/asst-sidepanel-styles.js +488 -0
- package/neural-interface/public/shared/assistant/asst-sidepanel.js +675 -0
- package/neural-interface/public/shared/assistant/asst-slash.js +258 -0
- package/neural-interface/public/shared/assistant/asst-state.js +727 -0
- package/neural-interface/public/shared/assistant/asst-styles.js +1686 -0
- package/neural-interface/public/shared/assistant/asst-tool-kinds.js +1017 -0
- package/neural-interface/public/shared/assistant/asst-usage.js +444 -0
- package/neural-interface/public/shared/assistant/asst-ws.js +175 -0
- package/neural-interface/public/shared/automation-context.js +75 -0
- package/neural-interface/public/shared/blob-store.js +99 -0
- package/neural-interface/public/shared/cdx/cdx-capabilities.js +118 -0
- package/neural-interface/public/shared/cdx/cdx-cards.js +37 -0
- package/neural-interface/public/shared/cdx/cdx-commands.js +171 -0
- package/neural-interface/public/shared/cdx/cdx-context-menu.js +402 -0
- package/neural-interface/public/shared/cdx/cdx-context-model.js +220 -0
- package/neural-interface/public/shared/cdx/cdx-features.js +408 -0
- package/neural-interface/public/shared/cdx/cdx-icons.js +89 -0
- package/neural-interface/public/shared/cdx/cdx-mcp-app-host.js +414 -0
- package/neural-interface/public/shared/cdx/cdx-mcp-app-proxy.html +6 -0
- package/neural-interface/public/shared/cdx/cdx-mcp-app-proxy.js +56 -0
- package/neural-interface/public/shared/cdx/cdx-mcp-app.js +178 -0
- package/neural-interface/public/shared/cdx/cdx-model-catalog.js +120 -0
- package/neural-interface/public/shared/cdx/cdx-output-model.js +261 -0
- package/neural-interface/public/shared/cdx/cdx-output.js +382 -0
- package/neural-interface/public/shared/cdx/cdx-panel.js +1372 -0
- package/neural-interface/public/shared/cdx/cdx-plan.js +266 -0
- package/neural-interface/public/shared/cdx/cdx-protocol.js +682 -0
- package/neural-interface/public/shared/cdx/cdx-render.js +3381 -0
- package/neural-interface/public/shared/cdx/cdx-requests.js +1136 -0
- package/neural-interface/public/shared/cdx/cdx-styles.js +3251 -0
- package/neural-interface/public/shared/cdx/cdx-tabs.js +7992 -0
- package/neural-interface/public/shared/cdx/cdx-ws.js +363 -0
- package/neural-interface/public/shared/cli-status.js +169 -0
- package/neural-interface/public/shared/command-runner-model.js +30 -0
- package/neural-interface/public/shared/constants.js +22 -5
- package/neural-interface/public/shared/cp/cp-agents.js +186 -0
- package/neural-interface/public/shared/cp/cp-bash.js +252 -0
- package/neural-interface/public/shared/cp/cp-compose.js +159 -0
- package/neural-interface/public/shared/cp/cp-context-menu.js +309 -0
- package/neural-interface/public/shared/cp/cp-context-model.js +157 -0
- package/neural-interface/public/shared/cp/cp-context-window.js +80 -0
- package/neural-interface/public/shared/cp/cp-ctx.js +11 -0
- package/neural-interface/public/shared/cp/cp-diff.js +255 -0
- package/neural-interface/public/shared/cp/cp-event-rows.js +637 -0
- package/neural-interface/public/shared/cp/cp-events.js +846 -0
- package/neural-interface/public/shared/cp/cp-markdown.js +104 -0
- package/neural-interface/public/shared/cp/cp-permission-model.js +905 -0
- package/neural-interface/public/shared/cp/cp-permissions.js +626 -0
- package/neural-interface/public/shared/cp/cp-rehydrate.js +113 -0
- package/neural-interface/public/shared/cp/cp-restore.js +224 -0
- package/neural-interface/public/shared/cp/cp-session-model.js +338 -0
- package/neural-interface/public/shared/cp/cp-session-settings.js +254 -0
- package/neural-interface/public/shared/cp/cp-sessions.js +227 -0
- package/neural-interface/public/shared/cp/cp-statusline.js +153 -0
- package/neural-interface/public/shared/cp/cp-styles.js +349 -0
- package/neural-interface/public/shared/cp/cp-tasks-model.js +282 -0
- package/neural-interface/public/shared/cp/cp-tasks.js +107 -0
- package/neural-interface/public/shared/cp/cp-temporary-view.js +56 -0
- package/neural-interface/public/shared/cp/cp-temporary.js +231 -0
- package/neural-interface/public/shared/cp/cp-tool-cards.js +326 -0
- package/neural-interface/public/shared/cp/cp-tool-results.js +618 -0
- package/neural-interface/public/shared/cp/cp-usage-model.js +124 -0
- package/neural-interface/public/shared/graph-activity.js +68 -0
- package/neural-interface/public/shared/html-shell.js +116 -17
- package/neural-interface/public/shared/i18n.js +132 -34
- package/neural-interface/public/shared/node-positions-store.js +44 -0
- package/neural-interface/public/shared/ocp-hidden-models.js +116 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-approvals.js +355 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-autoaccept-button.js +35 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-automation-ownership.js +72 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-binding.js +280 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-caps.js +67 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-changes-logic.js +179 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-changes.js +164 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-childpanel.js +725 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-compact-button.js +75 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-composer-logic.js +1204 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-confirm-logic.js +117 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-confirm.js +59 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-context-gauge.js +252 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-context-menu.js +478 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-context-model.js +179 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-events.js +233 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-icons.js +30 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-manager.js +1065 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-mention-hints.js +182 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-modelpicker.js +655 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +2636 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-plan.js +601 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-profile-inheritance.js +78 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-projectbar.js +649 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-providers.js +35 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-rehydrate.js +357 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-render-logic.js +189 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +1869 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-select.js +42 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-send-logic.js +117 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-send.js +1714 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-session-actions.js +468 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-session-widgets.js +63 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-sessions-logic.js +366 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-settings-link.js +19 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-slash-hints.js +343 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-state.js +746 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-status-logic.js +347 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-status.js +338 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +3543 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-subagents-logic.js +482 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-tools-logic.js +351 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-tools.js +168 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-variantpicker.js +315 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +545 -0
- package/neural-interface/public/shared/provider-icons.js +30 -0
- package/neural-interface/public/shared/pwa-install-page.js +34 -0
- package/neural-interface/public/shared/pwa-install.css +12 -0
- package/neural-interface/public/shared/pwa-install.js +28 -0
- package/neural-interface/public/shared/session-title.js +100 -0
- package/neural-interface/public/shared/settings/settings-ia.js +389 -0
- package/neural-interface/public/shared/settings/settings-kit.js +234 -0
- package/neural-interface/public/shared/settings/settings-rules.js +160 -0
- package/neural-interface/public/shared/settings/settings-search.js +463 -0
- package/neural-interface/public/shared/settings/settings-shell.js +570 -0
- package/neural-interface/public/shared/start-bridge.js +583 -0
- package/neural-interface/public/shared/state.js +5 -0
- package/neural-interface/public/shared/storage.js +50 -7
- package/neural-interface/public/shared/styleguide/sg-agents.js +42 -0
- package/neural-interface/public/shared/styleguide/sg-brand.js +4 -0
- package/neural-interface/public/shared/styleguide/sg-color-client.js +388 -0
- package/neural-interface/public/shared/styleguide/sg-colors.js +151 -0
- package/neural-interface/public/shared/styleguide/sg-components.js +35 -0
- package/neural-interface/public/shared/styleguide/sg-history.js +41 -0
- package/neural-interface/public/shared/styleguide/sg-icons-logo.js +38 -0
- package/neural-interface/public/shared/styleguide/sg-imagery.js +4 -0
- package/neural-interface/public/shared/styleguide/sg-import-export.js +48 -0
- package/neural-interface/public/shared/styleguide/sg-kit.js +284 -0
- package/neural-interface/public/shared/styleguide/sg-labels.js +318 -0
- package/neural-interface/public/shared/styleguide/sg-layout.js +4 -0
- package/neural-interface/public/shared/styleguide/sg-motion.js +5 -0
- package/neural-interface/public/shared/styleguide/sg-panel.js +237 -0
- package/neural-interface/public/shared/styleguide/sg-preview.js +138 -0
- package/neural-interface/public/shared/styleguide/sg-rules.js +9 -0
- package/neural-interface/public/shared/styleguide/sg-shape.js +24 -0
- package/neural-interface/public/shared/styleguide/sg-state.js +132 -0
- package/neural-interface/public/shared/styleguide/sg-typography.js +125 -0
- package/neural-interface/public/shared/styles.css +8614 -1477
- package/neural-interface/public/shared/synabun-mascot.js +1625 -0
- package/neural-interface/public/shared/synabun-ticker.js +376 -0
- package/neural-interface/public/shared/term-ready.js +307 -0
- package/neural-interface/public/shared/term-renderer.js +343 -0
- package/neural-interface/public/shared/ui-assistant-panel.js +10 -0
- package/neural-interface/public/shared/ui-assistant.js +77 -0
- package/neural-interface/public/shared/ui-automation-studio.js +5105 -3573
- package/neural-interface/public/shared/ui-claude-panel.js +11685 -6333
- package/neural-interface/public/shared/ui-codex-panel.js +12 -0
- package/neural-interface/public/shared/ui-command-runner.js +251 -468
- package/neural-interface/public/shared/ui-cost-widget.js +55 -34
- package/neural-interface/public/shared/ui-detail.js +77 -14
- package/neural-interface/public/shared/ui-explorer.js +360 -181
- package/neural-interface/public/shared/ui-file-explorer.js +485 -107
- package/neural-interface/public/shared/ui-help.js +2 -2
- package/neural-interface/public/shared/ui-image-gallery.js +45 -21
- package/neural-interface/public/shared/ui-judgments.js +1346 -0
- package/neural-interface/public/shared/ui-keybinds.js +3 -2
- package/neural-interface/public/shared/ui-link.js +105 -51
- package/neural-interface/public/shared/ui-loading.js +222 -11
- package/neural-interface/public/shared/ui-memory-maintenance.js +111 -0
- package/neural-interface/public/shared/ui-menubar.js +100 -31
- package/neural-interface/public/shared/ui-native-loop-router-state.js +94 -0
- package/neural-interface/public/shared/ui-native-loop-router.js +493 -0
- package/neural-interface/public/shared/ui-native-window-id.js +7 -0
- package/neural-interface/public/shared/ui-navbar.js +357 -222
- package/neural-interface/public/shared/ui-notifications.js +58 -12
- package/neural-interface/public/shared/ui-opencode-panel-v2.js +17 -0
- package/neural-interface/public/shared/ui-panels.js +15 -7
- package/neural-interface/public/shared/ui-resume.js +823 -653
- package/neural-interface/public/shared/ui-schedule-queue.js +172 -0
- package/neural-interface/public/shared/ui-schedules-studio.js +1882 -0
- package/neural-interface/public/shared/ui-scroll-follow.js +194 -0
- package/neural-interface/public/shared/ui-sessions.js +789 -34
- package/neural-interface/public/shared/ui-settings.js +5774 -2194
- package/neural-interface/public/shared/ui-sidepanel-layout.js +109 -0
- package/neural-interface/public/shared/ui-sidepanel-runtime.js +19 -0
- package/neural-interface/public/shared/ui-sidepanel-session-entry.js +40 -0
- package/neural-interface/public/shared/ui-sidepanel-sessions.js +221 -0
- package/neural-interface/public/shared/ui-sidepanel-state.js +131 -0
- package/neural-interface/public/shared/ui-sidepanel-tray.js +547 -0
- package/neural-interface/public/shared/ui-sidepanel-windows.js +387 -0
- package/neural-interface/public/shared/ui-skills.js +18 -32
- package/neural-interface/public/shared/ui-styleguide.js +35 -0
- package/neural-interface/public/shared/ui-sync.js +87 -0
- package/neural-interface/public/shared/ui-terminal.js +7863 -6385
- package/neural-interface/public/shared/ui-tool-updates.js +292 -0
- package/neural-interface/public/shared/ui-tooltip.js +156 -15
- package/neural-interface/public/shared/ui-tutorial-draw.js +119 -683
- package/neural-interface/public/shared/ui-tutorial-layout.js +135 -0
- package/neural-interface/public/shared/ui-tutorial-steps.js +59 -2209
- package/neural-interface/public/shared/ui-tutorial.css +102 -0
- package/neural-interface/public/shared/ui-tutorial.js +557 -1076
- package/neural-interface/public/shared/ui-update.js +420 -68
- package/neural-interface/public/shared/ui-whatsapp.js +941 -0
- package/neural-interface/public/shared/ui-whiteboard.js +1076 -233
- package/neural-interface/public/shared/ui-workspaces.js +2 -1
- package/neural-interface/public/shared/utils.js +58 -0
- package/neural-interface/public/shared/vterm-buffer.js +15 -5
- package/neural-interface/public/shared/whatsapp/wa-phone.js +65 -0
- package/neural-interface/public/shared/whatsapp/wa-view.js +411 -0
- package/neural-interface/public/sidepanel-session.html +18 -0
- package/neural-interface/public/sw.js +10 -2
- package/neural-interface/public/synabun.png +0 -0
- package/neural-interface/public/variant/2d/graph.js +1707 -1635
- package/neural-interface/public/variant/2d/lasso.js +2 -1
- package/neural-interface/public/variant/2d/layout.js +595 -594
- package/neural-interface/public/variant/2d/main.js +557 -521
- package/neural-interface/public/variant/2d/settings-gfx.js +18 -24
- package/neural-interface/public/variant/3d/main.js +517 -500
- package/neural-interface/public/variant/3d/map-controls.js +144 -0
- package/neural-interface/public/variant/3d/map-data.js +251 -0
- package/neural-interface/public/variant/3d/map-labels.js +241 -0
- package/neural-interface/public/variant/3d/map-pick.js +90 -0
- package/neural-interface/public/variant/3d/map-renderer.js +521 -0
- package/neural-interface/public/variant/3d/map-shaders.js +158 -0
- package/neural-interface/public/variant/3d/map-view.js +618 -0
- package/neural-interface/public/vendor/three/manifest.json +3 -0
- package/neural-interface/public/vendor/three/three-0.169.0.min.js +3844 -0
- package/neural-interface/public/vendor/xterm/manifest.json +3 -0
- package/neural-interface/public/vendor/xterm/xterm-6.0.0.css +285 -0
- package/neural-interface/public/vendor/xterm/xterm-6.0.0.min.js +192 -0
- package/neural-interface/scripts/build-vendor.mjs +64 -0
- package/neural-interface/scripts/codex-protocol-fixture.mjs +83 -0
- package/neural-interface/scripts/rebuild-pty.js +39 -22
- package/neural-interface/scripts/vendor-three-entry.js +24 -0
- package/neural-interface/scripts/vendor-xterm-entry.js +8 -0
- package/neural-interface/server.js +33983 -15000
- package/neural-interface/skins/default/skin.css +90 -0
- package/neural-interface/skins/default/skin.json +8 -0
- package/neural-interface/templates/rulesets/README.md +9 -0
- package/neural-interface/templates/rulesets/claude.md +3 -0
- package/neural-interface/templates/rulesets/codex.md +2 -0
- package/neural-interface/templates/rulesets/coexistence.md +6 -0
- package/neural-interface/templates/rulesets/core.md +26 -0
- package/neural-interface/templates/rulesets/cursor.md +2 -0
- package/neural-interface/templates/rulesets/gemini.md +2 -0
- package/neural-interface/templates/rulesets/legacy-hashes.json +227 -0
- package/neural-interface/templates/rulesets/manifest.json +12 -0
- package/neural-interface/templates/rulesets/opencode.md +2 -0
- package/package.json +131 -53
- package/postinstall.js +55 -26
- package/preuninstall.js +187 -0
- package/scripts/restore-data-home-from-backup.mjs +239 -0
- package/setup.js +872 -260
- package/skills/leonardo/SKILL.md +19 -10
- package/skills/leonardo/modules/image-prompter.md +18 -12
- package/skills/leonardo/modules/video-prompter.md +19 -13
- package/skills/synabun/SKILL.md +209 -185
- package/skills/synabun/icon.png +0 -0
- package/skills/synabun/modules/audit.md +380 -374
- package/skills/synabun/modules/changelog.md +15 -6
- package/skills/synabun/modules/idea.md +148 -144
- package/skills/synabun/modules/memorize.md +13 -4
- package/skills/synabun/modules/schedule.md +198 -0
- package/skills/synabun/synabunicon.png +0 -0
- package/updater.cmd +31 -0
- package/updater.mjs +382 -0
- package/updater.sh +29 -0
- package/hooks/claude-code/test-user-learning.mjs +0 -531
- package/neural-interface/public/claude-chat.css +0 -878
- package/neural-interface/public/claude-chat.html +0 -92
- package/neural-interface/public/claude-chat.js +0 -1168
- package/neural-interface/public/index-legacy.html +0 -14677
- package/neural-interface/public/index2d-legacy.html +0 -8193
- package/neural-interface/public/shared/html-term-renderer.js +0 -1022
- package/neural-interface/public/variant/3d/background.js +0 -884
- package/neural-interface/public/variant/3d/camera.js +0 -661
- package/neural-interface/public/variant/3d/gfx.js +0 -116
- package/neural-interface/public/variant/3d/graph.js +0 -2399
- package/neural-interface/public/variant/3d/settings-gfx.js +0 -228
- package/neural-interface/templates/CLAUDE-template.md +0 -211
|
@@ -0,0 +1,1225 @@
|
|
|
1
|
+
// WhatsApp Link host core. Runs inside the forked host (host.js) — or, for
|
|
2
|
+
// tests and the SYNABUN_WHATSAPP_HOST=inproc kill switch, inside the main
|
|
3
|
+
// process (manager.js). It owns the Baileys socket, the credentials, the
|
|
4
|
+
// owner, and sendToOwner: the only place anything is sent to WhatsApp.
|
|
5
|
+
//
|
|
6
|
+
// Inbound pipeline (messages.upsert):
|
|
7
|
+
// type 'notify', or 'append' for what WhatsApp held while this device was
|
|
8
|
+
// offline (its <message offline> stanza; history sync and own echoes are
|
|
9
|
+
// off in the socket config), no requestId (placeholder resends are how
|
|
10
|
+
// CVE-2026-48063 spoofed messages) → drop stubs, edits, revokes, reactions,
|
|
11
|
+
// poll votes, protocol and call messages → dedicated claim attempt (live
|
|
12
|
+
// messages only) → awaiting_confirm drops everything → classifyInbound
|
|
13
|
+
// (owner + the raw stanza that carried it) → a backlog message must come
|
|
14
|
+
// from an offline stanza and be younger than 24 h → dedupe (seen) →
|
|
15
|
+
// extract → 'inbound' event (`backlog: true` on offline ones; the bridge
|
|
16
|
+
// skips those older than 10 minutes), which never carries a JID or a phone
|
|
17
|
+
// number.
|
|
18
|
+
//
|
|
19
|
+
// Self mode after a fresh link sits in awaiting_confirm: nothing is accepted
|
|
20
|
+
// and nothing is sent until the desktop confirms the linked account
|
|
21
|
+
// (confirmOwner). Declining, or 10 minutes without an answer, logs the device
|
|
22
|
+
// out and wipes it — a stranger who scans the QR never gets a session.
|
|
23
|
+
|
|
24
|
+
import {
|
|
25
|
+
CONN, DEFAULT_PREFIX, ERR, EV, LIMITS, OP, PROTOCOL_VERSION, REACTIONS, pickPrefs, validateEvent, validateOp,
|
|
26
|
+
} from './protocol.js';
|
|
27
|
+
import { openAuthStore } from './auth-store.js';
|
|
28
|
+
import * as adapter from './baileys-adapter.js';
|
|
29
|
+
import { classifyInbound, createClaim, createOwnerState, maskJid, normalizeUserJid, parseJid, sameAccount } from './identity.js';
|
|
30
|
+
import { redactWa, setRedactionContext } from './redact.js';
|
|
31
|
+
|
|
32
|
+
const CONFIRM_WINDOW_MS = 10 * 60_000;
|
|
33
|
+
const PRESENCE_REFRESH_MS = 10_000;
|
|
34
|
+
const PRESENCE_MAX_MS = 10 * 60_000;
|
|
35
|
+
const PACE_MIN_MS = 900;
|
|
36
|
+
const PACE_JITTER_MS = 600;
|
|
37
|
+
export const SEND_CAPS = Object.freeze([
|
|
38
|
+
Object.freeze({ windowMs: 60_000, max: 10 }),
|
|
39
|
+
Object.freeze({ windowMs: 3_600_000, max: 120 }),
|
|
40
|
+
Object.freeze({ windowMs: 86_400_000, max: 500 }),
|
|
41
|
+
]);
|
|
42
|
+
// Status reactions (👀 ✅ ⏳ …) are cosmetic: they stop this many sends short of
|
|
43
|
+
// every cap, so they never push a reply into THROTTLED.
|
|
44
|
+
export const REACTION_RESERVE = 3;
|
|
45
|
+
const STABLE_OPEN_MS = 10 * 60_000;
|
|
46
|
+
const QR_FIRST_TTL_MS = 60_000;
|
|
47
|
+
const QR_NEXT_TTL_MS = 20_000;
|
|
48
|
+
const PAIRING_CODE_TTL_MS = 3 * 60_000;
|
|
49
|
+
const RESTART_BURST_MAX = 5;
|
|
50
|
+
const RESTART_BURST_WINDOW_MS = 10 * 60_000;
|
|
51
|
+
const TAP_TTL_MS = 10 * 60_000;
|
|
52
|
+
const BACKLOG_MAX_AGE_MS = 24 * 3_600_000;
|
|
53
|
+
const TAP_MAX = 1000;
|
|
54
|
+
const TAP_PER_SENDER = 50;
|
|
55
|
+
const RECENT_OWNER_MAX = 200;
|
|
56
|
+
const SENT_IDS_MAX = 2000;
|
|
57
|
+
const STATE_FLUSH_MS = 2000;
|
|
58
|
+
const IGNORED_FLUSH_MS = 2000;
|
|
59
|
+
const PRUNE_EVERY_MS = 3_600_000;
|
|
60
|
+
const LOGOUT_TIMEOUT_MS = 5000;
|
|
61
|
+
const LOG_BURST = 30;
|
|
62
|
+
const LOG_WINDOW_MS = 60_000;
|
|
63
|
+
const JID_IN_TEXT = /@(?:s\.whatsapp\.net|c\.us|lid|g\.us|broadcast|newsletter|hosted(?:\.lid)?)\b/;
|
|
64
|
+
|
|
65
|
+
export const WELCOME_TEXT = '✅ SynaBun is linked. Messages you send in this chat now reach your SynaBun Assistant.';
|
|
66
|
+
const LOCKED_REASON = 'another SynaBun process is using this WhatsApp session';
|
|
67
|
+
// conn.lastError (≤ 200 characters); the fatal event carries the store's own message (path, mode, errno).
|
|
68
|
+
const AUTH_PERMS_REASON = 'the WhatsApp session files could not be made private; fix the folder permissions, then reconnect';
|
|
69
|
+
|
|
70
|
+
const defaultTimers = {
|
|
71
|
+
setTimeout: (fn, ms) => setTimeout(fn, ms),
|
|
72
|
+
clearTimeout: (t) => clearTimeout(t),
|
|
73
|
+
setInterval: (fn, ms) => setInterval(fn, ms),
|
|
74
|
+
clearInterval: (t) => clearInterval(t),
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
function hostError(code, message, extra) {
|
|
78
|
+
const err = new Error(message);
|
|
79
|
+
err.code = code;
|
|
80
|
+
if (extra) Object.assign(err, extra);
|
|
81
|
+
return err;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const STOP_FATAL = {
|
|
85
|
+
[CONN.LOGGED_OUT]: 'LOGGED_OUT',
|
|
86
|
+
[CONN.REPLACED]: 'REPLACED',
|
|
87
|
+
[CONN.FORBIDDEN]: 'FORBIDDEN',
|
|
88
|
+
[CONN.ERROR]: 'SESSION_ERROR',
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @param {object} o
|
|
93
|
+
* @param {(msg:object) => void} o.send deliver one event to the main process
|
|
94
|
+
* @param {{authDir:string, runtimeDir:string}} o.paths
|
|
95
|
+
*/
|
|
96
|
+
export function createHostCore({
|
|
97
|
+
send,
|
|
98
|
+
paths,
|
|
99
|
+
env = process.env,
|
|
100
|
+
platform = process.platform,
|
|
101
|
+
now = () => Date.now(),
|
|
102
|
+
timers = defaultTimers,
|
|
103
|
+
rng = Math.random,
|
|
104
|
+
loadRuntime = adapter.loadRuntime,
|
|
105
|
+
openStore = openAuthStore,
|
|
106
|
+
reconnect = {},
|
|
107
|
+
sendCaps = SEND_CAPS,
|
|
108
|
+
} = {}) {
|
|
109
|
+
if (typeof send !== 'function') throw new TypeError('createHostCore: send is required');
|
|
110
|
+
if (!paths?.authDir) throw new TypeError('createHostCore: paths.authDir is required');
|
|
111
|
+
|
|
112
|
+
let runtime = null;
|
|
113
|
+
let runtimeInfo = { loaded: false, version: null, fake: false, error: null };
|
|
114
|
+
let store = null;
|
|
115
|
+
let storeFailure = null; // why init could not open the store: {code: ERR.LOCKED | ERR.AUTH_PERMS | ERR.INTERNAL, reason, message?}
|
|
116
|
+
let creds = null;
|
|
117
|
+
let prefs = { mode: 'self', selfTrigger: 'all', prefix: DEFAULT_PREFIX };
|
|
118
|
+
let connState = CONN.IDLE;
|
|
119
|
+
let lastError = null;
|
|
120
|
+
let lastDisconnect = null;
|
|
121
|
+
let retryAt = null;
|
|
122
|
+
let sock = null;
|
|
123
|
+
let gen = 0;
|
|
124
|
+
let session = null; // {purpose, mode, method, phone, qrCount, pairingRequested}
|
|
125
|
+
let owner = createOwnerState({ mode: 'self' });
|
|
126
|
+
let awaitingConfirmUntil = null;
|
|
127
|
+
let claim = null;
|
|
128
|
+
let paused = false;
|
|
129
|
+
let shuttingDown = false;
|
|
130
|
+
let initialized = false;
|
|
131
|
+
const sentIds = new Set();
|
|
132
|
+
const taps = new Map();
|
|
133
|
+
const tapsBySender = new Map(); // sender account → its tapped ids, oldest first
|
|
134
|
+
const recentOwner = new Map();
|
|
135
|
+
const restartBurst = [];
|
|
136
|
+
let sendLog = [];
|
|
137
|
+
let nextSendAt = 0;
|
|
138
|
+
let sendChain = Promise.resolve();
|
|
139
|
+
let inboundChain = Promise.resolve();
|
|
140
|
+
let presenceActive = false;
|
|
141
|
+
const counters = { inbound: 0, accepted: 0, ignored: 0, sent: 0, reactions: 0, throttled: 0, anomalies: 0, reconnects: 0 };
|
|
142
|
+
const ignoredCounts = {};
|
|
143
|
+
const logTimes = [];
|
|
144
|
+
const timerIds = {};
|
|
145
|
+
|
|
146
|
+
const policy = adapter.createReconnectPolicy({ now, rng, ...reconnect });
|
|
147
|
+
const logger = adapter.createSilentLogger({ sink: (level, message) => say(level, message) });
|
|
148
|
+
|
|
149
|
+
// ── Plumbing ──
|
|
150
|
+
|
|
151
|
+
function setTimer(name, fn, ms) {
|
|
152
|
+
clearTimer(name);
|
|
153
|
+
timerIds[name] = { kind: 'timeout', id: timers.setTimeout(() => { delete timerIds[name]; fn(); }, ms) };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function setRepeat(name, fn, ms) {
|
|
157
|
+
clearTimer(name);
|
|
158
|
+
timerIds[name] = { kind: 'interval', id: timers.setInterval(fn, ms) };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function clearTimer(name) {
|
|
162
|
+
const t = timerIds[name];
|
|
163
|
+
if (!t) return;
|
|
164
|
+
if (t.kind === 'interval') timers.clearInterval(t.id);
|
|
165
|
+
else timers.clearTimeout(t.id);
|
|
166
|
+
delete timerIds[name];
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function sleep(ms) {
|
|
170
|
+
return new Promise((resolve) => timers.setTimeout(resolve, ms));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function emit(ev) {
|
|
174
|
+
const v = validateEvent(ev);
|
|
175
|
+
if (!v.ok) {
|
|
176
|
+
if (ev?.t !== EV.LOG) say('warn', `[whatsapp] dropped an invalid '${ev?.t}' event: ${v.message}`);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
try { send(ev); } catch {}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function say(level, message) {
|
|
183
|
+
const t = now();
|
|
184
|
+
while (logTimes.length && t - logTimes[0] > LOG_WINDOW_MS) logTimes.shift();
|
|
185
|
+
if (logTimes.length >= LOG_BURST) return;
|
|
186
|
+
logTimes.push(t);
|
|
187
|
+
const lvl = ['debug', 'info', 'warn', 'error'].includes(level) ? level : 'warn';
|
|
188
|
+
emit({ t: EV.LOG, level: lvl, message: redactWa(String(message ?? '')).slice(0, 4000) });
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function isLinked() {
|
|
192
|
+
return adapter.isLinkedCreds(creds);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function storedMode() {
|
|
196
|
+
const m = store?.meta.get('mode');
|
|
197
|
+
return m === 'self' || m === 'dedicated' ? m : null;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function currentMode() {
|
|
201
|
+
return (isLinked() && storedMode()) || session?.mode || prefs.mode || 'self';
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function selfIds() {
|
|
205
|
+
if (!creds?.me?.id) return { pn: null, lid: null };
|
|
206
|
+
return { pn: normalizeUserJid(creds.me.id), lid: creds.me.lid ? normalizeUserJid(creds.me.lid) : null };
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function refreshIdentity() {
|
|
210
|
+
const self = isLinked() ? selfIds() : { pn: null, lid: null };
|
|
211
|
+
if (currentMode() === 'self') {
|
|
212
|
+
if (owner.mode !== 'self') owner = createOwnerState({ mode: 'self' });
|
|
213
|
+
owner.setSelf(self);
|
|
214
|
+
}
|
|
215
|
+
setRedactionContext({
|
|
216
|
+
self: [self.pn, self.lid].filter(Boolean),
|
|
217
|
+
owner: owner.mode === 'dedicated' ? [owner.pn, owner.lid].filter(Boolean) : [],
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function loadOwner() {
|
|
222
|
+
if (currentMode() === 'dedicated') {
|
|
223
|
+
const row = store?.owner.get();
|
|
224
|
+
owner = createOwnerState({ mode: 'dedicated', bound: row || null });
|
|
225
|
+
} else {
|
|
226
|
+
owner = createOwnerState({ mode: 'self' });
|
|
227
|
+
}
|
|
228
|
+
refreshIdentity();
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function ownerConfirmed() {
|
|
232
|
+
return !!store?.meta.get('owner_confirmed');
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function connStatus() {
|
|
236
|
+
const linked = isLinked();
|
|
237
|
+
const mode = linked || session ? currentMode() : (prefs.mode || null);
|
|
238
|
+
let ownerInfo = null;
|
|
239
|
+
if (linked && mode === 'dedicated') ownerInfo = { bound: owner.bound, masked: owner.masked() };
|
|
240
|
+
else if (linked && mode === 'self') ownerInfo = { bound: ownerConfirmed(), masked: maskJid(creds.me.id) };
|
|
241
|
+
return {
|
|
242
|
+
state: connState,
|
|
243
|
+
mode: mode === 'self' || mode === 'dedicated' ? mode : null,
|
|
244
|
+
registered: linked,
|
|
245
|
+
me: linked ? { masked: maskJid(creds.me.id), name: typeof creds.me.name === 'string' && creds.me.name !== '~' ? creds.me.name.slice(0, 100) : null } : null,
|
|
246
|
+
owner: ownerInfo,
|
|
247
|
+
lastDisconnect: lastDisconnect ? { ...lastDisconnect } : null,
|
|
248
|
+
retryInMs: retryAt ? Math.max(0, retryAt - now()) : null,
|
|
249
|
+
counters: { ...counters },
|
|
250
|
+
paused,
|
|
251
|
+
awaitingConfirmUntil,
|
|
252
|
+
claim: claim ? { active: claim.active, expiresAt: claim.expiresAt, attemptsLeft: claim.attemptsLeft } : null,
|
|
253
|
+
lastError,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function emitState() {
|
|
258
|
+
clearTimer('stateFlush');
|
|
259
|
+
emit({ t: EV.STATE, conn: connStatus() });
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** Counters moved: publish them soon, not on every message. */
|
|
263
|
+
function touch() {
|
|
264
|
+
if (!timerIds.stateFlush) setTimer('stateFlush', () => emitState(), STATE_FLUSH_MS);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function setState(next, { error } = {}) {
|
|
268
|
+
connState = next;
|
|
269
|
+
if (error !== undefined) lastError = error;
|
|
270
|
+
emitState();
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function bump(reason, n = 1) {
|
|
274
|
+
ignoredCounts[reason] = (ignoredCounts[reason] || 0) + n;
|
|
275
|
+
counters.ignored += n;
|
|
276
|
+
if (!timerIds.ignoredFlush) {
|
|
277
|
+
setTimer('ignoredFlush', () => emit({ t: EV.IGNORED, counts: { ...ignoredCounts } }), IGNORED_FLUSH_MS);
|
|
278
|
+
}
|
|
279
|
+
touch();
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function anomaly(reason) {
|
|
283
|
+
counters.anomalies += 1;
|
|
284
|
+
paused = true;
|
|
285
|
+
lastError = reason;
|
|
286
|
+
say('warn', `[whatsapp] owner anomaly: ${reason}; sending paused`);
|
|
287
|
+
emit({ t: EV.FATAL, code: 'OWNER_ANOMALY', message: reason });
|
|
288
|
+
emitState();
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function rememberSent(id, jid, message) {
|
|
292
|
+
if (!id) return;
|
|
293
|
+
sentIds.add(id);
|
|
294
|
+
if (sentIds.size > SENT_IDS_MAX) sentIds.delete(sentIds.values().next().value);
|
|
295
|
+
try { store?.sent.add(id, jid, adapter.encodeSentMessage(runtime.mod, message)); } catch (err) { say('warn', `[whatsapp] could not record a sent id: ${err?.message}`); }
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function isOwnSent(id) {
|
|
299
|
+
return sentIds.has(id) || !!store?.sent.has(id);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// ── Stanza tap ──
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Only senders who could be the owner are recorded, so a flood from
|
|
306
|
+
* strangers cannot evict the owner's entry before its message is processed
|
|
307
|
+
* (the tap runs before Baileys' own shouldIgnoreJid check).
|
|
308
|
+
*/
|
|
309
|
+
function tapWanted(from, alt) {
|
|
310
|
+
if (currentMode() === 'self') {
|
|
311
|
+
const self = selfIds();
|
|
312
|
+
return (!!self.pn && sameAccount(from, self.pn)) || (!!self.lid && sameAccount(from, self.lid));
|
|
313
|
+
}
|
|
314
|
+
if (owner.bound) return owner.isOwnerJid(from) || (!!alt && owner.isOwnerJid(alt));
|
|
315
|
+
const p = parseJid(from);
|
|
316
|
+
return !!claim && !!p && (p.kind === 'pn' || p.kind === 'lid'); // the claim window
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function tapStanza(node) {
|
|
320
|
+
const attrs = node?.attrs;
|
|
321
|
+
if (!attrs || typeof attrs.id !== 'string') return;
|
|
322
|
+
const sender = attrs.participant || attrs.from;
|
|
323
|
+
const p = parseJid(sender);
|
|
324
|
+
if (!p) return;
|
|
325
|
+
const lidAddressed = attrs.addressing_mode ? attrs.addressing_mode === 'lid' : p.kind === 'lid';
|
|
326
|
+
const altRaw = lidAddressed
|
|
327
|
+
? attrs.participant_pn || attrs.sender_pn || attrs.peer_recipient_pn
|
|
328
|
+
: attrs.participant_lid || attrs.sender_lid || attrs.peer_recipient_lid;
|
|
329
|
+
const from = normalizeUserJid(sender);
|
|
330
|
+
const alt = altRaw ? normalizeUserJid(altRaw) : null;
|
|
331
|
+
if (!tapWanted(from, alt)) return;
|
|
332
|
+
taps.set(attrs.id, { from, alt, device: p.device ?? 0, offline: attrs.offline !== undefined, at: now() });
|
|
333
|
+
// Per sender first: during a claim window one noisy account can only
|
|
334
|
+
// evict its own entries, never the claimant's.
|
|
335
|
+
let ids = tapsBySender.get(from);
|
|
336
|
+
if (!ids) tapsBySender.set(from, (ids = []));
|
|
337
|
+
ids.push(attrs.id);
|
|
338
|
+
while (ids.length > TAP_PER_SENDER) {
|
|
339
|
+
const old = ids.shift();
|
|
340
|
+
if (taps.get(old)?.from === from) taps.delete(old);
|
|
341
|
+
}
|
|
342
|
+
if (taps.size > TAP_MAX) taps.delete(taps.keys().next().value);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function stanzaFor(id) {
|
|
346
|
+
const tap = taps.get(id);
|
|
347
|
+
if (!tap) return null;
|
|
348
|
+
if (now() - tap.at > TAP_TTL_MS) {
|
|
349
|
+
taps.delete(id);
|
|
350
|
+
return null;
|
|
351
|
+
}
|
|
352
|
+
return tap;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// ── Socket lifecycle ──
|
|
356
|
+
|
|
357
|
+
function openSocket() {
|
|
358
|
+
clearTimer('reconnect');
|
|
359
|
+
retryAt = null;
|
|
360
|
+
const g = ++gen;
|
|
361
|
+
const mode = session.mode;
|
|
362
|
+
let s;
|
|
363
|
+
try {
|
|
364
|
+
s = adapter.createWaSocket({
|
|
365
|
+
runtime,
|
|
366
|
+
store,
|
|
367
|
+
creds,
|
|
368
|
+
mode,
|
|
369
|
+
method: session.purpose === 'link' ? session.method : null,
|
|
370
|
+
logger,
|
|
371
|
+
version: adapter.cachedVersion(store),
|
|
372
|
+
getSelfJids: selfIds,
|
|
373
|
+
onStanza: tapStanza,
|
|
374
|
+
platform,
|
|
375
|
+
});
|
|
376
|
+
} catch (err) {
|
|
377
|
+
sock = null;
|
|
378
|
+
session = null;
|
|
379
|
+
say('error', `[whatsapp] could not create the socket: ${err?.message}`);
|
|
380
|
+
setState(CONN.ERROR, { error: 'socket_failed' });
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
sock = s;
|
|
384
|
+
s.ev.on('connection.update', (u) => { if (g === gen) onConnectionUpdate(u); });
|
|
385
|
+
s.ev.on('creds.update', (u) => { if (g === gen) onCredsUpdate(u); });
|
|
386
|
+
s.ev.on('messages.upsert', (u) => {
|
|
387
|
+
if (g !== gen) return;
|
|
388
|
+
// One at a time: a slow image download must not let a later text overtake it.
|
|
389
|
+
inboundChain = inboundChain
|
|
390
|
+
.then(() => onUpsert(u))
|
|
391
|
+
.catch((err) => say('warn', `[whatsapp] inbound processing failed: ${err?.message}`));
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/** Close the current socket ourselves (never a logout); its close event is ignored. */
|
|
396
|
+
function closeSocket() {
|
|
397
|
+
const s = sock;
|
|
398
|
+
sock = null;
|
|
399
|
+
gen += 1;
|
|
400
|
+
clearTimer('stable');
|
|
401
|
+
stopPresence({ notify: false });
|
|
402
|
+
if (s) {
|
|
403
|
+
try { s.end(undefined); } catch {}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
async function logoutSocket() {
|
|
408
|
+
const s = sock;
|
|
409
|
+
sock = null;
|
|
410
|
+
gen += 1;
|
|
411
|
+
clearTimer('stable');
|
|
412
|
+
stopPresence({ notify: false });
|
|
413
|
+
if (!s) return;
|
|
414
|
+
let timer;
|
|
415
|
+
try {
|
|
416
|
+
await Promise.race([
|
|
417
|
+
Promise.resolve().then(() => s.logout()),
|
|
418
|
+
new Promise((resolve) => { timer = timers.setTimeout(resolve, LOGOUT_TIMEOUT_MS); }),
|
|
419
|
+
]);
|
|
420
|
+
} catch {} finally {
|
|
421
|
+
timers.clearTimeout(timer);
|
|
422
|
+
}
|
|
423
|
+
try { s.end(undefined); } catch {}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function onCredsUpdate(update) {
|
|
427
|
+
if (!creds || !update || typeof update !== 'object') return;
|
|
428
|
+
if (update !== creds) Object.assign(creds, update);
|
|
429
|
+
try { store.saveCreds(creds); } catch (err) { say('error', `[whatsapp] could not save credentials: ${err?.message}`); }
|
|
430
|
+
refreshIdentity();
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function onConnectionUpdate(u) {
|
|
434
|
+
if (!u || typeof u !== 'object') return;
|
|
435
|
+
if (typeof u.qr === 'string' && u.qr) onQr(u.qr);
|
|
436
|
+
// The phone accepted the QR / code: the server restarts the stream next.
|
|
437
|
+
if (u.isNewLogin === true && session && [CONN.QR, CONN.PAIRING].includes(connState)) setState(CONN.CONNECTING);
|
|
438
|
+
if (u.connection === 'connecting' && ![CONN.QR, CONN.PAIRING].includes(connState)) {
|
|
439
|
+
if (connState !== CONN.RECONNECTING && connState !== CONN.CONNECTING) setState(CONN.CONNECTING);
|
|
440
|
+
}
|
|
441
|
+
if (u.connection === 'open') onOpen();
|
|
442
|
+
if (u.connection === 'close') onClose(u.lastDisconnect?.error);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
function onQr(qr) {
|
|
446
|
+
if (!session || session.purpose !== 'link' || isLinked()) {
|
|
447
|
+
// A QR while running means the server no longer knows these creds.
|
|
448
|
+
closeSocket();
|
|
449
|
+
session = null;
|
|
450
|
+
stopWith(CONN.LOGGED_OUT, 'session_rejected', { wipe: true, fatal: 'LOGGED_OUT' });
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
session.qrCount += 1;
|
|
454
|
+
if (session.method === 'code') {
|
|
455
|
+
if (session.pairingRequested) return;
|
|
456
|
+
session.pairingRequested = true;
|
|
457
|
+
const s = sock;
|
|
458
|
+
const g = gen;
|
|
459
|
+
Promise.resolve()
|
|
460
|
+
.then(() => s.requestPairingCode(session.phone))
|
|
461
|
+
.then((code) => {
|
|
462
|
+
if (g !== gen) return;
|
|
463
|
+
const clean = String(code || '').replace(/[^A-Za-z0-9]/g, '').toUpperCase().slice(0, 16);
|
|
464
|
+
if (!clean) throw new Error('empty pairing code');
|
|
465
|
+
emit({ t: EV.PAIRING_CODE, code: clean, expiresAt: now() + PAIRING_CODE_TTL_MS });
|
|
466
|
+
setState(CONN.PAIRING);
|
|
467
|
+
})
|
|
468
|
+
.catch((err) => {
|
|
469
|
+
if (g !== gen) return;
|
|
470
|
+
say('warn', `[whatsapp] pairing code request failed: ${err?.message}`);
|
|
471
|
+
closeSocket();
|
|
472
|
+
stopWith(CONN.ERROR, 'pairing_code_failed', { wipe: true });
|
|
473
|
+
});
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
const ttl = session.qrCount === 1 ? QR_FIRST_TTL_MS : QR_NEXT_TTL_MS;
|
|
477
|
+
emit({ t: EV.QR, qr, expiresAt: now() + ttl });
|
|
478
|
+
if (connState !== CONN.QR) setState(CONN.QR);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
function onOpen() {
|
|
482
|
+
retryAt = null;
|
|
483
|
+
clearTimer('reconnect');
|
|
484
|
+
setTimer('stable', () => policy.noteStable(), STABLE_OPEN_MS);
|
|
485
|
+
const fresh = session?.purpose === 'link';
|
|
486
|
+
if (fresh) {
|
|
487
|
+
store.meta.set('mode', session.mode);
|
|
488
|
+
store.meta.set('linked_at', now());
|
|
489
|
+
store.meta.delete('owner_confirmed');
|
|
490
|
+
store.meta.delete('awaiting_confirm_until');
|
|
491
|
+
if (session.mode === 'dedicated') store.owner.clear();
|
|
492
|
+
session = { purpose: 'run', mode: session.mode };
|
|
493
|
+
loadOwner();
|
|
494
|
+
emit({ t: EV.LINKED, mode: currentMode(), me: connStatus().me });
|
|
495
|
+
} else {
|
|
496
|
+
refreshIdentity();
|
|
497
|
+
}
|
|
498
|
+
lastError = null;
|
|
499
|
+
if (currentMode() === 'self' && !ownerConfirmed()) {
|
|
500
|
+
enterAwaitingConfirm();
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
setState(CONN.OPEN);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
function enterAwaitingConfirm() {
|
|
507
|
+
let until = store.meta.get('awaiting_confirm_until');
|
|
508
|
+
if (!Number.isFinite(until)) {
|
|
509
|
+
until = now() + CONFIRM_WINDOW_MS;
|
|
510
|
+
store.meta.set('awaiting_confirm_until', until);
|
|
511
|
+
}
|
|
512
|
+
awaitingConfirmUntil = until;
|
|
513
|
+
const left = until - now();
|
|
514
|
+
if (left <= 0) {
|
|
515
|
+
confirmTimeout().catch(() => {});
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
setTimer('confirm', () => { confirmTimeout().catch(() => {}); }, left);
|
|
519
|
+
setState(CONN.AWAITING_CONFIRM);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
async function confirmTimeout() {
|
|
523
|
+
if (connState !== CONN.AWAITING_CONFIRM && !(awaitingConfirmUntil && now() >= awaitingConfirmUntil)) return;
|
|
524
|
+
say('warn', '[whatsapp] the linked account was not confirmed within 10 minutes; logging it out');
|
|
525
|
+
await forgetDevice();
|
|
526
|
+
setState(CONN.UNLINKED, { error: 'confirm_timeout' });
|
|
527
|
+
emit({ t: EV.FATAL, code: 'CONFIRM_TIMEOUT', message: 'the linked account was not confirmed in time' });
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function onClose(error) {
|
|
531
|
+
sock = null;
|
|
532
|
+
gen += 1;
|
|
533
|
+
clearTimer('stable');
|
|
534
|
+
stopPresence({ notify: false });
|
|
535
|
+
const linking = session?.purpose === 'link' && !isLinked();
|
|
536
|
+
const c = adapter.classifyDisconnect(error, { linking, DisconnectReason: runtime.mod.DisconnectReason });
|
|
537
|
+
lastDisconnect = { reason: c.reason, code: c.code, at: now() };
|
|
538
|
+
if (shuttingDown) return;
|
|
539
|
+
if (!session) {
|
|
540
|
+
setState(isLinked() ? CONN.IDLE : CONN.UNLINKED);
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
switch (c.action) {
|
|
544
|
+
case 'reconnect_now': {
|
|
545
|
+
const t = now();
|
|
546
|
+
while (restartBurst.length && t - restartBurst[0] > RESTART_BURST_WINDOW_MS) restartBurst.shift();
|
|
547
|
+
if (restartBurst.length >= RESTART_BURST_MAX) {
|
|
548
|
+
scheduleReconnect();
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
restartBurst.push(t);
|
|
552
|
+
counters.reconnects += 1;
|
|
553
|
+
openSocket();
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
case 'refresh_version': {
|
|
557
|
+
const g = gen;
|
|
558
|
+
adapter.refreshVersion({ runtime, store, now }).then((refreshed) => {
|
|
559
|
+
if (g !== gen || shuttingDown || !session) return;
|
|
560
|
+
if (refreshed) {
|
|
561
|
+
counters.reconnects += 1;
|
|
562
|
+
openSocket();
|
|
563
|
+
} else if (session.purpose === 'link' && !isLinked()) {
|
|
564
|
+
stopWith(CONN.LINK_EXPIRED, 'outdated_version', { wipe: true });
|
|
565
|
+
} else {
|
|
566
|
+
scheduleReconnect();
|
|
567
|
+
}
|
|
568
|
+
}, () => scheduleReconnect());
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
case 'backoff':
|
|
572
|
+
scheduleReconnect();
|
|
573
|
+
return;
|
|
574
|
+
default:
|
|
575
|
+
stopWith(c.state, c.reason, { wipe: c.wipe, fatal: STOP_FATAL[c.state] });
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
function scheduleReconnect() {
|
|
580
|
+
const next = policy.next();
|
|
581
|
+
if (next.giveUp) {
|
|
582
|
+
stopWith(CONN.ERROR, 'reconnect_limit', { fatal: 'RECONNECT_LIMIT' });
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
retryAt = now() + next.delayMs;
|
|
586
|
+
setTimer('reconnect', () => {
|
|
587
|
+
retryAt = null;
|
|
588
|
+
if (shuttingDown || !session) return;
|
|
589
|
+
counters.reconnects += 1;
|
|
590
|
+
openSocket();
|
|
591
|
+
}, next.delayMs);
|
|
592
|
+
setState(CONN.RECONNECTING);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
function stopWith(state, reason, { wipe = false, fatal = null } = {}) {
|
|
596
|
+
clearTimer('reconnect');
|
|
597
|
+
clearTimer('confirm');
|
|
598
|
+
retryAt = null;
|
|
599
|
+
session = null;
|
|
600
|
+
if (wipe) wipeLocal();
|
|
601
|
+
setState(state, { error: reason });
|
|
602
|
+
if (fatal) emit({ t: EV.FATAL, code: fatal, message: reason });
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/** Forget everything about the linked device (files included); keeps the lock. */
|
|
606
|
+
function wipeLocal() {
|
|
607
|
+
try { store?.wipe(); } catch (err) { say('error', `[whatsapp] wipe failed: ${err?.message}`); }
|
|
608
|
+
creds = null;
|
|
609
|
+
owner = createOwnerState({ mode: prefs.mode || 'self' });
|
|
610
|
+
sentIds.clear();
|
|
611
|
+
recentOwner.clear();
|
|
612
|
+
taps.clear();
|
|
613
|
+
tapsBySender.clear();
|
|
614
|
+
claim = null;
|
|
615
|
+
clearTimer('claim');
|
|
616
|
+
clearTimer('confirm');
|
|
617
|
+
awaitingConfirmUntil = null;
|
|
618
|
+
paused = false;
|
|
619
|
+
setRedactionContext({});
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
/** Log the device out (best effort) and wipe it. */
|
|
623
|
+
async function forgetDevice() {
|
|
624
|
+
session = null;
|
|
625
|
+
clearTimer('reconnect');
|
|
626
|
+
retryAt = null;
|
|
627
|
+
await logoutSocket();
|
|
628
|
+
wipeLocal();
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
// ── Inbound ──
|
|
632
|
+
|
|
633
|
+
async function onUpsert(u) {
|
|
634
|
+
const messages = Array.isArray(u?.messages) ? u.messages : [];
|
|
635
|
+
if (u && typeof u === 'object' && Object.hasOwn(u, 'requestId')) {
|
|
636
|
+
bump('placeholder_resend', messages.length || 1);
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
if (u?.type !== 'notify' && u?.type !== 'append') {
|
|
640
|
+
bump('not_notify', messages.length || 1);
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
const backlog = u.type === 'append';
|
|
644
|
+
for (const msg of messages) {
|
|
645
|
+
try {
|
|
646
|
+
await processIncoming(msg, { backlog });
|
|
647
|
+
} catch (err) {
|
|
648
|
+
bump('error');
|
|
649
|
+
say('warn', `[whatsapp] could not process a message: ${err?.message}`);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
async function processIncoming(msg, { backlog = false } = {}) {
|
|
655
|
+
counters.inbound += 1;
|
|
656
|
+
const d = adapter.describeContent(msg, runtime.mod);
|
|
657
|
+
if (d.drop) {
|
|
658
|
+
bump(d.drop);
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
const stanza = stanzaFor(msg.key.id);
|
|
662
|
+
const mode = currentMode();
|
|
663
|
+
// A claim is a live handshake: a held code (maybe an earlier claim's) never burns an attempt.
|
|
664
|
+
if (!backlog && mode === 'dedicated' && claim && connState === CONN.OPEN && !owner.bound) {
|
|
665
|
+
if (await tryClaim(msg, d, stanza)) return;
|
|
666
|
+
}
|
|
667
|
+
if (connState === CONN.AWAITING_CONFIRM) {
|
|
668
|
+
bump('awaiting_confirm');
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
if (connState !== CONN.OPEN) {
|
|
672
|
+
bump('not_open');
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
const verdict = classifyInbound(msg, owner, {
|
|
676
|
+
mode,
|
|
677
|
+
sentIds: { has: isOwnSent },
|
|
678
|
+
prefix: mode === 'self' && prefs.selfTrigger === 'prefix' ? prefs.prefix || DEFAULT_PREFIX : null,
|
|
679
|
+
stanza,
|
|
680
|
+
text: d.text,
|
|
681
|
+
});
|
|
682
|
+
if (!verdict.accept) {
|
|
683
|
+
bump(verdict.reason);
|
|
684
|
+
if (verdict.reason === 'owner_conflict') anomaly('a message claimed the owner through a mismatching id');
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
687
|
+
if (backlog) {
|
|
688
|
+
// The owner's, held for this device while it was offline: its stanza says so, and a day is the limit.
|
|
689
|
+
if (stanza?.offline !== true) {
|
|
690
|
+
bump('append_not_offline');
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
const sentAt = Number(msg.messageTimestamp) * 1000;
|
|
694
|
+
if (!(sentAt > 0) || now() - sentAt > BACKLOG_MAX_AGE_MS) {
|
|
695
|
+
bump('backlog_expired');
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
const id = msg.key.id;
|
|
700
|
+
if (store.seen.has(id)) {
|
|
701
|
+
bump('duplicate');
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
store.seen.add(id, normalizeUserJid(msg.key.remoteJid) || '');
|
|
705
|
+
if (mode === 'dedicated' && owner.learnAlternate(msg.key.remoteJid, msg.key.remoteJidAlt)) {
|
|
706
|
+
store.owner.set(owner.snapshot());
|
|
707
|
+
refreshIdentity();
|
|
708
|
+
}
|
|
709
|
+
owner.noteChat(msg.key.remoteJid);
|
|
710
|
+
recentOwner.set(id, { copy: adapter.quotableCopy(msg, d), at: now() });
|
|
711
|
+
if (recentOwner.size > RECENT_OWNER_MAX) recentOwner.delete(recentOwner.keys().next().value);
|
|
712
|
+
const ex = await adapter.extractInbound(msg, { mod: runtime.mod, sock, logger, sentIds: { has: isOwnSent }, described: d, text: verdict.text });
|
|
713
|
+
const ts = Number(msg.messageTimestamp);
|
|
714
|
+
counters.accepted += 1;
|
|
715
|
+
touch();
|
|
716
|
+
emit({
|
|
717
|
+
t: EV.INBOUND,
|
|
718
|
+
message: {
|
|
719
|
+
id,
|
|
720
|
+
ts: Number.isFinite(ts) && ts > 0 ? ts * 1000 : now(),
|
|
721
|
+
chat: verdict.chat,
|
|
722
|
+
text: ex.text,
|
|
723
|
+
images: ex.images,
|
|
724
|
+
unsupported: ex.unsupported,
|
|
725
|
+
forwarded: ex.forwarded,
|
|
726
|
+
quoted: ex.quoted,
|
|
727
|
+
owner: true,
|
|
728
|
+
...(backlog ? { backlog: true } : {}),
|
|
729
|
+
},
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
/** @returns {Promise<boolean>} true when the message was a claim attempt (consumed, never answered unless it matched) */
|
|
734
|
+
async function tryClaim(msg, d, stanza) {
|
|
735
|
+
if (msg.key.fromMe === true || d.kind !== 'text') return false;
|
|
736
|
+
const chat = parseJid(msg.key.remoteJid);
|
|
737
|
+
if (!chat || (chat.kind !== 'pn' && chat.kind !== 'lid')) return false;
|
|
738
|
+
if (!stanza?.from || !sameAccount(stanza.from, msg.key.remoteJid)) return false;
|
|
739
|
+
const result = claim.check(d.text);
|
|
740
|
+
if (result === 'ignored' || result === 'inactive') return false;
|
|
741
|
+
if (result === 'expired') {
|
|
742
|
+
claim = null;
|
|
743
|
+
clearTimer('claim');
|
|
744
|
+
emitState();
|
|
745
|
+
return false;
|
|
746
|
+
}
|
|
747
|
+
try { store.seen.add(msg.key.id, normalizeUserJid(msg.key.remoteJid) || ''); } catch {}
|
|
748
|
+
if (result === 'mismatch' || result === 'exhausted') {
|
|
749
|
+
bump('claim_mismatch');
|
|
750
|
+
if (result === 'exhausted') {
|
|
751
|
+
claim = null;
|
|
752
|
+
clearTimer('claim');
|
|
753
|
+
}
|
|
754
|
+
emitState();
|
|
755
|
+
return true; // silent: a wrong code never gets a reply
|
|
756
|
+
}
|
|
757
|
+
// match
|
|
758
|
+
const ids = { pn: null, lid: null };
|
|
759
|
+
for (const j of [msg.key.remoteJid, msg.key.remoteJidAlt]) {
|
|
760
|
+
const p = parseJid(j);
|
|
761
|
+
if (p?.kind === 'pn' && !ids.pn) ids.pn = normalizeUserJid(j);
|
|
762
|
+
if (p?.kind === 'lid' && !ids.lid) ids.lid = normalizeUserJid(j);
|
|
763
|
+
}
|
|
764
|
+
try {
|
|
765
|
+
const map = sock?.signalRepository?.lidMapping;
|
|
766
|
+
if (ids.lid && !ids.pn && map?.getPNForLID) {
|
|
767
|
+
const pn = normalizeUserJid(await map.getPNForLID(ids.lid));
|
|
768
|
+
if (pn && parseJid(pn).kind === 'pn') ids.pn = pn;
|
|
769
|
+
}
|
|
770
|
+
if (ids.pn && !ids.lid && map?.getLIDForPN) {
|
|
771
|
+
const lid = normalizeUserJid(await map.getLIDForPN(ids.pn));
|
|
772
|
+
if (lid && parseJid(lid).kind === 'lid') ids.lid = lid;
|
|
773
|
+
}
|
|
774
|
+
} catch {}
|
|
775
|
+
claim = null;
|
|
776
|
+
clearTimer('claim');
|
|
777
|
+
owner.bind({ ...ids, via: 'claim', boundAt: now() });
|
|
778
|
+
owner.noteChat(msg.key.remoteJid);
|
|
779
|
+
store.owner.set(owner.snapshot());
|
|
780
|
+
paused = false;
|
|
781
|
+
refreshIdentity();
|
|
782
|
+
emit({ t: EV.OWNER_BOUND, masked: owner.masked() || '••••', via: 'claim' });
|
|
783
|
+
emitState();
|
|
784
|
+
sendToOwner({ text: WELCOME_TEXT }).catch((err) => say('warn', `[whatsapp] welcome message failed: ${err?.message}`));
|
|
785
|
+
return true;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
// ── Outbound: the only way out ──
|
|
789
|
+
|
|
790
|
+
/** How long until one more send fits every cap, `reserve` sends short of each (0 = now). */
|
|
791
|
+
function capWait(reserve = 0) {
|
|
792
|
+
const t = now();
|
|
793
|
+
sendLog = sendLog.filter((ts) => t - ts < sendCaps[sendCaps.length - 1].windowMs);
|
|
794
|
+
let wait = 0;
|
|
795
|
+
for (const cap of sendCaps) {
|
|
796
|
+
const max = Math.max(1, cap.max - reserve);
|
|
797
|
+
const inWindow = sendLog.filter((ts) => t - ts < cap.windowMs);
|
|
798
|
+
if (inWindow.length >= max) {
|
|
799
|
+
const oldest = inWindow[inWindow.length - max];
|
|
800
|
+
wait = Math.max(wait, cap.windowMs - (t - oldest));
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
return wait;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
/**
|
|
807
|
+
* The owner's chat, or NO_OWNER. Every miss is counted as an anomaly; only a
|
|
808
|
+
* real mismatch (an owner is bound yet the target is not theirs) also pauses
|
|
809
|
+
* sending and raises OWNER_ANOMALY — a send racing a deliberate owner reset
|
|
810
|
+
* is not an attack.
|
|
811
|
+
*/
|
|
812
|
+
function assertOwnerTarget() {
|
|
813
|
+
const jid = owner.replyJid();
|
|
814
|
+
if (jid && owner.isOwnerJid(jid)) return jid;
|
|
815
|
+
if (owner.bound) {
|
|
816
|
+
anomaly('the reply target is not the owner');
|
|
817
|
+
throw hostError(ERR.NO_OWNER, 'the reply target is not the owner');
|
|
818
|
+
}
|
|
819
|
+
counters.anomalies += 1;
|
|
820
|
+
touch();
|
|
821
|
+
throw hostError(ERR.NO_OWNER, 'no owner is bound');
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
/**
|
|
825
|
+
* Send `content` ({text} or {react}) to the owner — the ONLY socket send in
|
|
826
|
+
* the WhatsApp Link. The target is always resolved here, from the owner
|
|
827
|
+
* state; callers cannot name one.
|
|
828
|
+
*/
|
|
829
|
+
async function sendToOwner(content, { replyTo = null } = {}) {
|
|
830
|
+
if (!sock || connState !== CONN.OPEN) throw hostError(ERR.NOT_CONNECTED, 'WhatsApp is not connected');
|
|
831
|
+
if (paused) throw hostError(ERR.PAUSED, 'sending is paused after an owner anomaly');
|
|
832
|
+
assertOwnerTarget();
|
|
833
|
+
if (typeof content?.text === 'string') {
|
|
834
|
+
if (!content.text.trim()) throw hostError(ERR.BAD_REQUEST, 'text is empty');
|
|
835
|
+
if (content.text.length > LIMITS.MAX_TEXT) throw hostError(ERR.TOO_LONG, `text is longer than ${LIMITS.MAX_TEXT} characters`);
|
|
836
|
+
}
|
|
837
|
+
const reaction = !!content?.react;
|
|
838
|
+
const wait = capWait(reaction ? REACTION_RESERVE : 0);
|
|
839
|
+
if (wait > 0 && reaction) throw hostError(ERR.THROTTLED, 'a status reaction yields to replies near the send limit', { retryAfterMs: wait });
|
|
840
|
+
if (wait > 0) {
|
|
841
|
+
counters.throttled += 1;
|
|
842
|
+
emit({ t: EV.THROTTLED, retryAfterMs: wait });
|
|
843
|
+
touch();
|
|
844
|
+
throw hostError(ERR.THROTTLED, 'the WhatsApp send limit was reached', { retryAfterMs: wait });
|
|
845
|
+
}
|
|
846
|
+
sendLog.push(now());
|
|
847
|
+
const run = async () => {
|
|
848
|
+
const delay = nextSendAt - now();
|
|
849
|
+
if (delay > 0) await sleep(delay);
|
|
850
|
+
if (!sock || connState !== CONN.OPEN) throw hostError(ERR.NOT_CONNECTED, 'WhatsApp is not connected');
|
|
851
|
+
if (paused) throw hostError(ERR.PAUSED, 'sending is paused after an owner anomaly');
|
|
852
|
+
const target = assertOwnerTarget();
|
|
853
|
+
const quoted = replyTo ? recentOwner.get(replyTo)?.copy : undefined;
|
|
854
|
+
const payload = typeof content.text === 'string' ? { text: content.text, linkPreview: null } : content;
|
|
855
|
+
let res;
|
|
856
|
+
try {
|
|
857
|
+
res = await sock.sendMessage(target, payload, quoted ? { quoted } : undefined);
|
|
858
|
+
} catch (err) {
|
|
859
|
+
throw hostError(ERR.SEND_FAILED, `WhatsApp send failed: ${redactWa(err?.message || err).slice(0, 200)}`);
|
|
860
|
+
} finally {
|
|
861
|
+
nextSendAt = now() + PACE_MIN_MS + Math.floor(rng() * PACE_JITTER_MS);
|
|
862
|
+
}
|
|
863
|
+
const id = res?.key?.id || null;
|
|
864
|
+
rememberSent(id, target, res?.message);
|
|
865
|
+
if (payload.react) counters.reactions += 1;
|
|
866
|
+
else counters.sent += 1;
|
|
867
|
+
touch();
|
|
868
|
+
return { id };
|
|
869
|
+
};
|
|
870
|
+
const p = sendChain.then(run, run);
|
|
871
|
+
sendChain = p.catch(() => {});
|
|
872
|
+
return p;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
// ── Presence ──
|
|
876
|
+
|
|
877
|
+
function stopPresence({ notify = true } = {}) {
|
|
878
|
+
const wasActive = presenceActive;
|
|
879
|
+
presenceActive = false;
|
|
880
|
+
clearTimer('presenceRefresh');
|
|
881
|
+
clearTimer('presenceStop');
|
|
882
|
+
if (notify && wasActive && sock && connState === CONN.OPEN) {
|
|
883
|
+
const jid = owner.replyJid();
|
|
884
|
+
if (jid && owner.isOwnerJid(jid)) Promise.resolve().then(() => sock?.sendPresenceUpdate('paused', jid)).catch(() => {});
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
async function presence(stateName) {
|
|
889
|
+
if (currentMode() === 'self') return { skipped: 'self' };
|
|
890
|
+
if (!sock || connState !== CONN.OPEN) throw hostError(ERR.NOT_CONNECTED, 'WhatsApp is not connected');
|
|
891
|
+
if (paused) throw hostError(ERR.PAUSED, 'sending is paused after an owner anomaly');
|
|
892
|
+
const jid = assertOwnerTarget();
|
|
893
|
+
if (stateName === 'paused') {
|
|
894
|
+
stopPresence({ notify: false });
|
|
895
|
+
await sock.sendPresenceUpdate('paused', jid);
|
|
896
|
+
return { state: 'paused' };
|
|
897
|
+
}
|
|
898
|
+
await sock.sendPresenceUpdate('composing', jid);
|
|
899
|
+
if (!presenceActive) {
|
|
900
|
+
presenceActive = true;
|
|
901
|
+
setRepeat('presenceRefresh', () => {
|
|
902
|
+
const target = owner.replyJid();
|
|
903
|
+
if (!sock || connState !== CONN.OPEN || !target || !owner.isOwnerJid(target)) {
|
|
904
|
+
stopPresence({ notify: false });
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
Promise.resolve().then(() => sock.sendPresenceUpdate('composing', target)).catch(() => {});
|
|
908
|
+
}, PRESENCE_REFRESH_MS);
|
|
909
|
+
setTimer('presenceStop', () => stopPresence({ notify: true }), PRESENCE_MAX_MS);
|
|
910
|
+
}
|
|
911
|
+
return { state: 'composing' };
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
// ── Ops ──
|
|
915
|
+
|
|
916
|
+
function requireRuntime() {
|
|
917
|
+
if (!runtime) throw hostError(runtimeInfo.error === ERR.RUNTIME_ERROR ? ERR.RUNTIME_ERROR : ERR.RUNTIME_MISSING, 'the WhatsApp connector is not installed');
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
/** Nothing that needs the store runs without it; the refusal keeps init's code (LOCKED, AUTH_PERMS). */
|
|
921
|
+
function requireStore() {
|
|
922
|
+
if (!store) throw hostError(storeFailure?.code || ERR.INTERNAL, storeFailure?.reason || lastError || 'the WhatsApp session store is not available');
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
async function opConnect({ purpose, mode, link }) {
|
|
926
|
+
requireRuntime();
|
|
927
|
+
requireStore();
|
|
928
|
+
if (purpose === 'run') {
|
|
929
|
+
if (!isLinked()) throw hostError(ERR.NOT_LINKED, 'no WhatsApp account is linked');
|
|
930
|
+
const stored = storedMode();
|
|
931
|
+
if (mode && stored && mode !== stored) throw hostError(ERR.MODE_MISMATCH, `this device was linked in ${stored} mode`);
|
|
932
|
+
if (sock && session?.purpose === 'run') return connStatus();
|
|
933
|
+
if (timerIds.reconnect && session) {
|
|
934
|
+
openSocket();
|
|
935
|
+
return connStatus();
|
|
936
|
+
}
|
|
937
|
+
closeSocket();
|
|
938
|
+
session = { purpose: 'run', mode: stored || mode || prefs.mode || 'self' };
|
|
939
|
+
policy.reset();
|
|
940
|
+
lastError = null;
|
|
941
|
+
loadOwner();
|
|
942
|
+
setState(CONN.CONNECTING);
|
|
943
|
+
openSocket();
|
|
944
|
+
return connStatus();
|
|
945
|
+
}
|
|
946
|
+
// purpose === 'link'
|
|
947
|
+
if (isLinked()) throw hostError(ERR.ALREADY_LINKED, 'a WhatsApp account is already linked; log it out first');
|
|
948
|
+
const method = link?.method || 'qr';
|
|
949
|
+
let phone = null;
|
|
950
|
+
if (method === 'code') {
|
|
951
|
+
phone = String(link?.phone || '').replace(/[\s()+.-]/g, '');
|
|
952
|
+
if (!/^\d{7,15}$/.test(phone)) throw hostError(ERR.BAD_PHONE, 'the phone number must be 7-15 digits, country code first');
|
|
953
|
+
}
|
|
954
|
+
closeSocket();
|
|
955
|
+
wipeLocal();
|
|
956
|
+
creds = runtime.mod.initAuthCreds();
|
|
957
|
+
const linkMode = mode || prefs.mode || 'self';
|
|
958
|
+
session = { purpose: 'link', mode: linkMode, method, phone, qrCount: 0, pairingRequested: false };
|
|
959
|
+
policy.reset();
|
|
960
|
+
lastError = null;
|
|
961
|
+
lastDisconnect = null;
|
|
962
|
+
owner = createOwnerState({ mode: linkMode });
|
|
963
|
+
setState(CONN.CONNECTING);
|
|
964
|
+
openSocket();
|
|
965
|
+
return connStatus();
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
async function opDisconnect() {
|
|
969
|
+
session = null;
|
|
970
|
+
closeSocket();
|
|
971
|
+
clearTimer('reconnect');
|
|
972
|
+
clearTimer('confirm');
|
|
973
|
+
retryAt = null;
|
|
974
|
+
policy.reset();
|
|
975
|
+
// Without a store (locked, or refused for its permissions) there is no idle to go back to.
|
|
976
|
+
setState(!store ? connState : isLinked() ? CONN.IDLE : CONN.UNLINKED);
|
|
977
|
+
return connStatus();
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
async function opLogout() {
|
|
981
|
+
requireStore();
|
|
982
|
+
await forgetDevice();
|
|
983
|
+
setState(CONN.UNLINKED, { error: null });
|
|
984
|
+
return connStatus();
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
async function opConfirmOwner({ accept }) {
|
|
988
|
+
if (connState !== CONN.AWAITING_CONFIRM) throw hostError(ERR.NOT_AWAITING, 'nothing is waiting for confirmation');
|
|
989
|
+
clearTimer('confirm');
|
|
990
|
+
if (!accept) {
|
|
991
|
+
await forgetDevice();
|
|
992
|
+
setState(CONN.UNLINKED, { error: 'owner_rejected' });
|
|
993
|
+
return connStatus();
|
|
994
|
+
}
|
|
995
|
+
store.meta.set('owner_confirmed', { at: now() });
|
|
996
|
+
store.meta.delete('awaiting_confirm_until');
|
|
997
|
+
awaitingConfirmUntil = null;
|
|
998
|
+
paused = false;
|
|
999
|
+
emit({ t: EV.OWNER_BOUND, masked: maskJid(creds.me.id), via: 'self_confirm' });
|
|
1000
|
+
setState(CONN.OPEN, { error: null });
|
|
1001
|
+
return connStatus();
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
function opClaimStart({ ttlMs }) {
|
|
1005
|
+
if (currentMode() !== 'dedicated') throw hostError(ERR.BAD_REQUEST, 'claim codes are for dedicated mode');
|
|
1006
|
+
if (connState !== CONN.OPEN) throw hostError(ERR.NOT_CONNECTED, 'WhatsApp is not connected');
|
|
1007
|
+
if (owner.bound) throw hostError(ERR.OWNER_BOUND, 'an owner is already bound; reset it first');
|
|
1008
|
+
claim?.cancel();
|
|
1009
|
+
claim = createClaim({ now, ttlMs: Number.isFinite(ttlMs) ? ttlMs : undefined });
|
|
1010
|
+
setTimer('claim', () => {
|
|
1011
|
+
claim = null;
|
|
1012
|
+
emitState();
|
|
1013
|
+
}, Math.max(0, claim.expiresAt - now()));
|
|
1014
|
+
const digits = parseJid(creds.me.id)?.user;
|
|
1015
|
+
emitState();
|
|
1016
|
+
return {
|
|
1017
|
+
code: claim.code,
|
|
1018
|
+
link: digits ? `https://wa.me/${digits}?text=${encodeURIComponent(claim.code)}` : null,
|
|
1019
|
+
expiresAt: claim.expiresAt,
|
|
1020
|
+
};
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
function opClaimCancel() {
|
|
1024
|
+
claim?.cancel();
|
|
1025
|
+
claim = null;
|
|
1026
|
+
clearTimer('claim');
|
|
1027
|
+
emitState();
|
|
1028
|
+
return connStatus();
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
function opOwnerReset() {
|
|
1032
|
+
requireStore();
|
|
1033
|
+
if (currentMode() === 'dedicated') {
|
|
1034
|
+
owner.clear();
|
|
1035
|
+
store.owner.clear();
|
|
1036
|
+
claim = null;
|
|
1037
|
+
clearTimer('claim');
|
|
1038
|
+
paused = false;
|
|
1039
|
+
stopPresence({ notify: false });
|
|
1040
|
+
refreshIdentity();
|
|
1041
|
+
emitState();
|
|
1042
|
+
return connStatus();
|
|
1043
|
+
}
|
|
1044
|
+
// Self mode: the owner IS the linked account. Re-confirming could end in
|
|
1045
|
+
// a timeout logout, so a reset is refused; logging out changes accounts.
|
|
1046
|
+
throw hostError(ERR.BAD_REQUEST, 'in self mode the owner is the linked account; log out to link another one');
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
async function opReact({ id, reaction }) {
|
|
1050
|
+
const text = reaction === null ? '' : REACTIONS[reaction];
|
|
1051
|
+
const own = recentOwner.get(id);
|
|
1052
|
+
let key;
|
|
1053
|
+
if (own) key = { ...own.copy.key };
|
|
1054
|
+
else if (isOwnSent(id)) {
|
|
1055
|
+
const jid = owner.replyJid();
|
|
1056
|
+
if (!jid || !owner.isOwnerJid(jid)) throw hostError(ERR.NO_OWNER, 'no owner is bound');
|
|
1057
|
+
key = { remoteJid: jid, fromMe: true, id };
|
|
1058
|
+
} else throw hostError(ERR.BAD_TARGET, 'can only react to owner messages or SynaBun replies');
|
|
1059
|
+
return sendToOwner({ react: { text, key } });
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
async function opRead({ ids }) {
|
|
1063
|
+
if (currentMode() === 'self') return { skipped: 'self', read: 0 };
|
|
1064
|
+
if (!sock || connState !== CONN.OPEN) throw hostError(ERR.NOT_CONNECTED, 'WhatsApp is not connected');
|
|
1065
|
+
const keys = [];
|
|
1066
|
+
for (const id of ids.slice(0, LIMITS.MAX_READ_IDS)) {
|
|
1067
|
+
const own = recentOwner.get(id);
|
|
1068
|
+
if (own && owner.isOwnerJid(own.copy.key.remoteJid)) keys.push({ ...own.copy.key });
|
|
1069
|
+
}
|
|
1070
|
+
if (keys.length) await sock.readMessages(keys);
|
|
1071
|
+
return { read: keys.length };
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
async function dispatch(msg) {
|
|
1075
|
+
switch (msg.op) {
|
|
1076
|
+
case OP.CONFIGURE:
|
|
1077
|
+
prefs = { ...prefs, ...pickPrefs(msg.prefs) };
|
|
1078
|
+
if (!isLinked() && !session) owner = createOwnerState({ mode: prefs.mode || 'self' });
|
|
1079
|
+
emitState();
|
|
1080
|
+
return { prefs: { ...prefs } };
|
|
1081
|
+
case OP.CONNECT: return opConnect(msg);
|
|
1082
|
+
case OP.DISCONNECT: return opDisconnect();
|
|
1083
|
+
case OP.LOGOUT: return opLogout();
|
|
1084
|
+
case OP.CONFIRM_OWNER: return opConfirmOwner(msg);
|
|
1085
|
+
case OP.CLAIM_START: return opClaimStart(msg);
|
|
1086
|
+
case OP.CLAIM_CANCEL: return opClaimCancel();
|
|
1087
|
+
case OP.OWNER_RESET: return opOwnerReset();
|
|
1088
|
+
case OP.SEND: return sendToOwner({ text: msg.text }, { replyTo: msg.replyTo ?? null });
|
|
1089
|
+
case OP.REACT: return opReact(msg);
|
|
1090
|
+
case OP.PRESENCE: return presence(msg.state);
|
|
1091
|
+
case OP.READ: return opRead(msg);
|
|
1092
|
+
case OP.STATUS: return { conn: connStatus(), runtime: { ...runtimeInfo } };
|
|
1093
|
+
case OP.SHUTDOWN:
|
|
1094
|
+
await shutdown();
|
|
1095
|
+
return { ok: true };
|
|
1096
|
+
case OP.FAKE: {
|
|
1097
|
+
if (!runtime?.fake) throw hostError(ERR.NOT_FAKE, 'the fake runtime is not loaded');
|
|
1098
|
+
return runtime.mod.fake.control(msg.action, msg.args || {});
|
|
1099
|
+
}
|
|
1100
|
+
default:
|
|
1101
|
+
throw hostError(ERR.UNKNOWN_OP, `unknown op '${msg.op}'`);
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
/** Replies are not schema-checked like events: redact any JID-bearing string as a backstop. */
|
|
1106
|
+
function scrubReply(v, depth = 0) {
|
|
1107
|
+
if (typeof v === 'string') return JID_IN_TEXT.test(v) ? redactWa(v) : v;
|
|
1108
|
+
if (v === null || typeof v !== 'object' || depth > 6) return v;
|
|
1109
|
+
if (Array.isArray(v)) return v.map((x) => scrubReply(x, depth + 1));
|
|
1110
|
+
const out = {};
|
|
1111
|
+
for (const [k, x] of Object.entries(v)) out[k] = scrubReply(x, depth + 1);
|
|
1112
|
+
return out;
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
function reply(reqId, ok, data, error) {
|
|
1116
|
+
if (!reqId) return;
|
|
1117
|
+
const ev = ok ? { t: EV.REPLY, reqId, ok: true, data: data ?? null } : { t: EV.REPLY, reqId, ok: false, error };
|
|
1118
|
+
emit(ev);
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
async function handleMessage(msg) {
|
|
1122
|
+
const v = validateOp(msg);
|
|
1123
|
+
if (!v.ok) {
|
|
1124
|
+
reply(msg?.reqId, false, null, { code: v.code, message: v.message });
|
|
1125
|
+
return;
|
|
1126
|
+
}
|
|
1127
|
+
if (!initialized && msg.op !== OP.SHUTDOWN) {
|
|
1128
|
+
reply(msg.reqId, false, null, { code: ERR.HOST_UNAVAILABLE, message: 'the WhatsApp host is still starting' });
|
|
1129
|
+
return;
|
|
1130
|
+
}
|
|
1131
|
+
try {
|
|
1132
|
+
const data = await dispatch(msg);
|
|
1133
|
+
// claim_start's wa.me link carries the dedicated account's own number by design.
|
|
1134
|
+
reply(msg.reqId, true, msg.op === OP.CLAIM_START || msg.op === OP.FAKE ? data : scrubReply(data));
|
|
1135
|
+
} catch (err) {
|
|
1136
|
+
const code = typeof err?.code === 'string' && ERR[err.code] ? err.code : ERR.INTERNAL;
|
|
1137
|
+
if (code === ERR.INTERNAL) say('warn', `[whatsapp] ${msg.op} failed: ${err?.message}`);
|
|
1138
|
+
const error = { code, message: redactWa(err?.message || String(err)).slice(0, 300) };
|
|
1139
|
+
if (Number.isFinite(err?.retryAfterMs)) {
|
|
1140
|
+
error.message = `${error.message} (retry in ${Math.ceil(err.retryAfterMs / 1000)} s)`;
|
|
1141
|
+
error.retryAfterMs = Math.max(0, Math.round(err.retryAfterMs));
|
|
1142
|
+
}
|
|
1143
|
+
reply(msg.reqId, false, null, error);
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
// ── Lifecycle ──
|
|
1148
|
+
|
|
1149
|
+
async function init() {
|
|
1150
|
+
try {
|
|
1151
|
+
runtime = await loadRuntime({ runtimeDir: paths.runtimeDir, env });
|
|
1152
|
+
runtimeInfo = { loaded: true, version: runtime.version ?? null, fake: !!runtime.fake, error: null };
|
|
1153
|
+
} catch (err) {
|
|
1154
|
+
runtime = null;
|
|
1155
|
+
runtimeInfo = { loaded: false, version: null, fake: false, error: err?.code === ERR.RUNTIME_ERROR ? ERR.RUNTIME_ERROR : ERR.RUNTIME_MISSING };
|
|
1156
|
+
if (err?.code === ERR.RUNTIME_ERROR) say('warn', `[whatsapp] ${err.message}`);
|
|
1157
|
+
}
|
|
1158
|
+
try {
|
|
1159
|
+
store = openStore({
|
|
1160
|
+
authDir: paths.authDir,
|
|
1161
|
+
...(runtime ? { codec: runtime.codec, reviveKey: runtime.reviveKey } : {}),
|
|
1162
|
+
platform,
|
|
1163
|
+
now,
|
|
1164
|
+
log: (m, level) => say(level || 'warn', m),
|
|
1165
|
+
});
|
|
1166
|
+
} catch (err) {
|
|
1167
|
+
store = null;
|
|
1168
|
+
if (err?.code === 'LOCKED') {
|
|
1169
|
+
connState = CONN.LOCKED;
|
|
1170
|
+
lastError = LOCKED_REASON;
|
|
1171
|
+
storeFailure = { code: ERR.LOCKED, reason: LOCKED_REASON };
|
|
1172
|
+
} else if (err?.code === ERR.AUTH_PERMS) {
|
|
1173
|
+
// The linked-device keys would open readable by others (or owned by someone else): refused.
|
|
1174
|
+
connState = CONN.ERROR;
|
|
1175
|
+
lastError = AUTH_PERMS_REASON;
|
|
1176
|
+
storeFailure = { code: ERR.AUTH_PERMS, reason: AUTH_PERMS_REASON, message: redactWa(err.message || AUTH_PERMS_REASON).slice(0, 400) };
|
|
1177
|
+
say('error', `[whatsapp] ${storeFailure.message}`);
|
|
1178
|
+
} else {
|
|
1179
|
+
connState = CONN.ERROR;
|
|
1180
|
+
lastError = `auth store: ${redactWa(err?.message || err).slice(0, 150)}`;
|
|
1181
|
+
storeFailure = { code: ERR.INTERNAL, reason: lastError };
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
if (store) {
|
|
1185
|
+
try { creds = store.loadCreds(); } catch (err) { say('error', `[whatsapp] could not read credentials: ${err?.message}`); creds = null; }
|
|
1186
|
+
for (const id of store.sent.recentIds()) sentIds.add(id);
|
|
1187
|
+
loadOwner();
|
|
1188
|
+
connState = isLinked() ? CONN.IDLE : CONN.UNLINKED;
|
|
1189
|
+
const pending = store.meta.get('awaiting_confirm_until');
|
|
1190
|
+
if (isLinked() && currentMode() === 'self' && !ownerConfirmed() && Number.isFinite(pending)) awaitingConfirmUntil = pending;
|
|
1191
|
+
setRepeat('prune', () => {
|
|
1192
|
+
try { store?.prune(); } catch {}
|
|
1193
|
+
const t = now();
|
|
1194
|
+
for (const [id, tap] of taps) if (t - tap.at > TAP_TTL_MS) taps.delete(id);
|
|
1195
|
+
tapsBySender.clear();
|
|
1196
|
+
for (const [id, tap] of taps) {
|
|
1197
|
+
if (!tapsBySender.has(tap.from)) tapsBySender.set(tap.from, []);
|
|
1198
|
+
tapsBySender.get(tap.from).push(id);
|
|
1199
|
+
}
|
|
1200
|
+
}, PRUNE_EVERY_MS);
|
|
1201
|
+
try { store.prune(); } catch {}
|
|
1202
|
+
}
|
|
1203
|
+
initialized = true;
|
|
1204
|
+
if (connState === CONN.LOCKED) emit({ t: EV.FATAL, code: 'LOCKED', message: lastError });
|
|
1205
|
+
if (storeFailure?.code === ERR.AUTH_PERMS) emit({ t: EV.FATAL, code: ERR.AUTH_PERMS, message: storeFailure.message });
|
|
1206
|
+
return { runtime: { ...runtimeInfo }, conn: connStatus() };
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
async function shutdown() {
|
|
1210
|
+
if (shuttingDown) return;
|
|
1211
|
+
shuttingDown = true;
|
|
1212
|
+
session = null;
|
|
1213
|
+
closeSocket();
|
|
1214
|
+
for (const name of Object.keys(timerIds)) clearTimer(name);
|
|
1215
|
+
try { store?.close(); } catch {}
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
return {
|
|
1219
|
+
init,
|
|
1220
|
+
handleMessage,
|
|
1221
|
+
shutdown,
|
|
1222
|
+
status: () => ({ conn: connStatus(), runtime: { ...runtimeInfo } }),
|
|
1223
|
+
get protocol() { return PROTOCOL_VERSION; },
|
|
1224
|
+
};
|
|
1225
|
+
}
|