@intent-systems/nexus 2026.1.5-11
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 +222 -0
- package/LICENSE +21 -0
- package/README-header.png +0 -0
- package/README.md +462 -0
- package/dist/agents/agent-id.js +41 -0
- package/dist/agents/agent-paths.js +16 -0
- package/dist/agents/agent-scope.js +44 -0
- package/dist/agents/auth-profiles.js +715 -0
- package/dist/agents/bash-process-registry.js +126 -0
- package/dist/agents/bash-tools.js +838 -0
- package/dist/agents/chutes-oauth.js +47 -0
- package/dist/agents/clawdbot-tools.js +62 -0
- package/dist/agents/context.js +34 -0
- package/dist/agents/defaults.js +6 -0
- package/dist/agents/identity-state.js +101 -0
- package/dist/agents/memory-search.js +80 -0
- package/dist/agents/model-auth.js +116 -0
- package/dist/agents/model-catalog.js +55 -0
- package/dist/agents/model-fallback.js +216 -0
- package/dist/agents/model-scan.js +263 -0
- package/dist/agents/model-selection.js +152 -0
- package/dist/agents/models-config.js +177 -0
- package/dist/agents/nexus-tools.js +46 -0
- package/dist/agents/pi-embedded-block-chunker.js +188 -0
- package/dist/agents/pi-embedded-helpers.js +139 -0
- package/dist/agents/pi-embedded-runner.js +1024 -0
- package/dist/agents/pi-embedded-subscribe.js +541 -0
- package/dist/agents/pi-embedded-utils.js +20 -0
- package/dist/agents/pi-embedded.js +1 -0
- package/dist/agents/pi-extensions/compaction-safeguard.js +140 -0
- package/dist/agents/pi-tool-definition-adapter.js +17 -0
- package/dist/agents/pi-tools.js +510 -0
- package/dist/agents/pi-tools.schema.js +358 -0
- package/dist/agents/sandbox-paths.js +68 -0
- package/dist/agents/sandbox.js +676 -0
- package/dist/agents/shell-utils.js +53 -0
- package/dist/agents/skill-runner.js +256 -0
- package/dist/agents/skill-state.js +164 -0
- package/dist/agents/skill-tools.js +191 -0
- package/dist/agents/skill-usage.js +143 -0
- package/dist/agents/skills-install.js +244 -0
- package/dist/agents/skills-status.js +154 -0
- package/dist/agents/skills.js +476 -0
- package/dist/agents/subagent-registry.js +335 -0
- package/dist/agents/subagent-registry.store.js +47 -0
- package/dist/agents/system-prompt.js +195 -0
- package/dist/agents/timeout.js +26 -0
- package/dist/agents/tool-display.js +155 -0
- package/dist/agents/tool-display.json +236 -0
- package/dist/agents/tool-images.js +138 -0
- package/dist/agents/tool-policy.js +103 -0
- package/dist/agents/tools/agent-step.js +41 -0
- package/dist/agents/tools/browser-tool.js +298 -0
- package/dist/agents/tools/canvas-tool.js +193 -0
- package/dist/agents/tools/common.js +88 -0
- package/dist/agents/tools/cron-tool.js +141 -0
- package/dist/agents/tools/discord-actions-guild.js +186 -0
- package/dist/agents/tools/discord-actions-messaging.js +313 -0
- package/dist/agents/tools/discord-actions-moderation.js +70 -0
- package/dist/agents/tools/discord-actions.js +56 -0
- package/dist/agents/tools/discord-schema.js +199 -0
- package/dist/agents/tools/discord-tool.js +16 -0
- package/dist/agents/tools/gateway-tool.js +46 -0
- package/dist/agents/tools/gateway.js +28 -0
- package/dist/agents/tools/image-tool.js +225 -0
- package/dist/agents/tools/memory-tool.js +92 -0
- package/dist/agents/tools/nodes-tool.js +413 -0
- package/dist/agents/tools/nodes-utils.js +92 -0
- package/dist/agents/tools/sessions-announce-target.js +39 -0
- package/dist/agents/tools/sessions-helpers.js +88 -0
- package/dist/agents/tools/sessions-history-tool.js +137 -0
- package/dist/agents/tools/sessions-list-tool.js +196 -0
- package/dist/agents/tools/sessions-send-helpers.js +103 -0
- package/dist/agents/tools/sessions-send-tool.js +371 -0
- package/dist/agents/tools/sessions-spawn-tool.js +319 -0
- package/dist/agents/tools/slack-actions.js +129 -0
- package/dist/agents/tools/slack-schema.js +59 -0
- package/dist/agents/tools/slack-tool.js +16 -0
- package/dist/agents/tools/telegram-actions.js +159 -0
- package/dist/agents/tools/telegram-schema.js +28 -0
- package/dist/agents/tools/telegram-tool.js +16 -0
- package/dist/agents/tools/whatsapp-login-tool.js +63 -0
- package/dist/agents/usage.js +58 -0
- package/dist/agents/workspace.js +286 -0
- package/dist/auto-reply/chunk.js +177 -0
- package/dist/auto-reply/command-auth.js +44 -0
- package/dist/auto-reply/command-detection.js +23 -0
- package/dist/auto-reply/envelope.js +30 -0
- package/dist/auto-reply/group-activation.js +20 -0
- package/dist/auto-reply/heartbeat.js +58 -0
- package/dist/auto-reply/model.js +22 -0
- package/dist/auto-reply/reply/abort.js +14 -0
- package/dist/auto-reply/reply/agent-runner.js +426 -0
- package/dist/auto-reply/reply/bash-command.js +314 -0
- package/dist/auto-reply/reply/block-streaming.js +34 -0
- package/dist/auto-reply/reply/body.js +29 -0
- package/dist/auto-reply/reply/commands.js +332 -0
- package/dist/auto-reply/reply/directive-handling.js +751 -0
- package/dist/auto-reply/reply/directives.js +74 -0
- package/dist/auto-reply/reply/dispatch-from-config.js +23 -0
- package/dist/auto-reply/reply/followup-runner.js +181 -0
- package/dist/auto-reply/reply/groups.js +152 -0
- package/dist/auto-reply/reply/mentions.js +64 -0
- package/dist/auto-reply/reply/model-selection.js +214 -0
- package/dist/auto-reply/reply/queue.js +399 -0
- package/dist/auto-reply/reply/reply-dispatcher.js +68 -0
- package/dist/auto-reply/reply/reply-tags.js +26 -0
- package/dist/auto-reply/reply/session-updates.js +103 -0
- package/dist/auto-reply/reply/session.js +169 -0
- package/dist/auto-reply/reply/typing.js +125 -0
- package/dist/auto-reply/reply.js +655 -0
- package/dist/auto-reply/send-policy.js +28 -0
- package/dist/auto-reply/status.js +197 -0
- package/dist/auto-reply/templating.js +9 -0
- package/dist/auto-reply/thinking.js +64 -0
- package/dist/auto-reply/tokens.js +2 -0
- package/dist/auto-reply/tool-meta.js +74 -0
- package/dist/auto-reply/transcription.js +57 -0
- package/dist/auto-reply/types.js +1 -0
- package/dist/browser/bridge-server.js +37 -0
- package/dist/browser/cdp.js +382 -0
- package/dist/browser/chrome.js +432 -0
- package/dist/browser/client-actions-core.js +67 -0
- package/dist/browser/client-actions-observe.js +24 -0
- package/dist/browser/client-actions-types.js +1 -0
- package/dist/browser/client-actions.js +3 -0
- package/dist/browser/client-fetch.js +43 -0
- package/dist/browser/client.js +107 -0
- package/dist/browser/config.js +159 -0
- package/dist/browser/constants.js +5 -0
- package/dist/browser/profiles-service.js +124 -0
- package/dist/browser/profiles.js +96 -0
- package/dist/browser/pw-ai.js +2 -0
- package/dist/browser/pw-session.js +144 -0
- package/dist/browser/pw-tools-core.js +366 -0
- package/dist/browser/routes/agent.js +549 -0
- package/dist/browser/routes/basic.js +155 -0
- package/dist/browser/routes/index.js +8 -0
- package/dist/browser/routes/tabs.js +105 -0
- package/dist/browser/routes/utils.js +62 -0
- package/dist/browser/screenshot.js +40 -0
- package/dist/browser/server-context.js +377 -0
- package/dist/browser/server.js +81 -0
- package/dist/browser/target-id.js +18 -0
- package/dist/browser/trash.js +21 -0
- package/dist/canvas-host/a2ui/a2ui.bundle.js +17768 -0
- package/dist/canvas-host/a2ui/index.html +246 -0
- package/dist/canvas-host/a2ui.js +187 -0
- package/dist/canvas-host/server.js +382 -0
- package/dist/capabilities/detector.js +245 -0
- package/dist/capabilities/registry.js +99 -0
- package/dist/channel-web.js +8 -0
- package/dist/channels/location.js +44 -0
- package/dist/channels/web/index.js +2 -0
- package/dist/cli/browser-cli-actions-input.js +459 -0
- package/dist/cli/browser-cli-actions-observe.js +56 -0
- package/dist/cli/browser-cli-examples.js +31 -0
- package/dist/cli/browser-cli-inspect.js +97 -0
- package/dist/cli/browser-cli-manage.js +286 -0
- package/dist/cli/browser-cli-shared.js +1 -0
- package/dist/cli/browser-cli.js +26 -0
- package/dist/cli/canvas-cli.js +416 -0
- package/dist/cli/cloud-cli.js +399 -0
- package/dist/cli/credential-cli.js +418 -0
- package/dist/cli/cron-cli.js +454 -0
- package/dist/cli/deps.js +17 -0
- package/dist/cli/dns-cli.js +180 -0
- package/dist/cli/gateway-cli.js +665 -0
- package/dist/cli/gateway-rpc.js +20 -0
- package/dist/cli/hooks-cli.js +135 -0
- package/dist/cli/log-cli.js +25 -0
- package/dist/cli/memory-cli.js +101 -0
- package/dist/cli/models-cli.js +248 -0
- package/dist/cli/nodes-camera.js +57 -0
- package/dist/cli/nodes-canvas.js +26 -0
- package/dist/cli/nodes-cli.js +946 -0
- package/dist/cli/nodes-screen.js +37 -0
- package/dist/cli/pairing-cli.js +100 -0
- package/dist/cli/parse-duration.js +20 -0
- package/dist/cli/plugins-cli.js +158 -0
- package/dist/cli/ports.js +97 -0
- package/dist/cli/profile.js +81 -0
- package/dist/cli/program.js +236 -0
- package/dist/cli/prompt.js +19 -0
- package/dist/cli/run-main.js +48 -0
- package/dist/cli/skills-cli.js +290 -0
- package/dist/cli/skills-hub-cli.js +1465 -0
- package/dist/cli/telegram-cli.js +56 -0
- package/dist/cli/tool-connector-cli.js +193 -0
- package/dist/cli/tui-cli.js +35 -0
- package/dist/cli/upstream-sync-cli.js +2990 -0
- package/dist/cli/usage-cli.js +38 -0
- package/dist/cli/wait.js +8 -0
- package/dist/commands/agent-via-gateway.js +115 -0
- package/dist/commands/agent.js +665 -0
- package/dist/commands/antigravity-oauth.js +327 -0
- package/dist/commands/auth-choice-options.js +85 -0
- package/dist/commands/auth-choice.js +286 -0
- package/dist/commands/auth-token.js +31 -0
- package/dist/commands/bootstrap-preset.js +228 -0
- package/dist/commands/capabilities.js +63 -0
- package/dist/commands/chutes-oauth.js +144 -0
- package/dist/commands/claude-md.js +138 -0
- package/dist/commands/config-view.js +11 -0
- package/dist/commands/config.js +85 -0
- package/dist/commands/configure.js +648 -0
- package/dist/commands/credential.js +697 -0
- package/dist/commands/cursor-hooks.js +240 -0
- package/dist/commands/cursor-rules.js +56 -0
- package/dist/commands/doctor-state-migrations.js +358 -0
- package/dist/commands/doctor-ui.js +113 -0
- package/dist/commands/doctor.js +674 -0
- package/dist/commands/health.js +112 -0
- package/dist/commands/identity.js +51 -0
- package/dist/commands/init.js +450 -0
- package/dist/commands/log.js +134 -0
- package/dist/commands/models/aliases.js +85 -0
- package/dist/commands/models/fallbacks.js +123 -0
- package/dist/commands/models/image-fallbacks.js +123 -0
- package/dist/commands/models/list.js +347 -0
- package/dist/commands/models/scan.js +271 -0
- package/dist/commands/models/set-image.js +27 -0
- package/dist/commands/models/set.js +27 -0
- package/dist/commands/models/shared.js +73 -0
- package/dist/commands/models.js +7 -0
- package/dist/commands/onboard-auth.js +126 -0
- package/dist/commands/onboard-channels.js +814 -0
- package/dist/commands/onboard-eve-identity.js +97 -0
- package/dist/commands/onboard-github.js +153 -0
- package/dist/commands/onboard-helpers.js +303 -0
- package/dist/commands/onboard-interactive.js +17 -0
- package/dist/commands/onboard-non-interactive.js +230 -0
- package/dist/commands/onboard-providers.js +829 -0
- package/dist/commands/onboard-quickstart.js +192 -0
- package/dist/commands/onboard-remote.js +120 -0
- package/dist/commands/onboard-skills.js +148 -0
- package/dist/commands/onboard-types.js +1 -0
- package/dist/commands/onboard.js +19 -0
- package/dist/commands/openai-codex-model-default.js +38 -0
- package/dist/commands/poll.js +64 -0
- package/dist/commands/quest-state.js +271 -0
- package/dist/commands/quest.js +67 -0
- package/dist/commands/reset.js +61 -0
- package/dist/commands/send.js +124 -0
- package/dist/commands/sessions-ingest.js +360 -0
- package/dist/commands/sessions.js +212 -0
- package/dist/commands/setup.js +61 -0
- package/dist/commands/signal-install.js +135 -0
- package/dist/commands/skills-manifest.js +514 -0
- package/dist/commands/status.js +259 -0
- package/dist/commands/suggestions.js +54 -0
- package/dist/commands/systemd-linger.js +71 -0
- package/dist/commands/update.js +16 -0
- package/dist/commands/usage-tracking.js +32 -0
- package/dist/commands/usage-upload.js +32 -0
- package/dist/config/config.js +6 -0
- package/dist/config/defaults.js +138 -0
- package/dist/config/group-policy.js +49 -0
- package/dist/config/includes.js +181 -0
- package/dist/config/io.js +260 -0
- package/dist/config/legacy-migrate.js +13 -0
- package/dist/config/legacy.js +427 -0
- package/dist/config/paths.js +98 -0
- package/dist/config/port-defaults.js +32 -0
- package/dist/config/schema.js +173 -0
- package/dist/config/sessions.js +615 -0
- package/dist/config/talk.js +31 -0
- package/dist/config/types.js +1 -0
- package/dist/config/validation.js +29 -0
- package/dist/config/zod-schema.js +1111 -0
- package/dist/control-plane/broker/broker.js +1022 -0
- package/dist/control-plane/compaction.js +282 -0
- package/dist/control-plane/factory.js +31 -0
- package/dist/control-plane/index.js +10 -0
- package/dist/control-plane/odu/agents.js +192 -0
- package/dist/control-plane/odu/interaction-tools.js +208 -0
- package/dist/control-plane/odu/prompt-loader.js +95 -0
- package/dist/control-plane/odu/runtime.js +479 -0
- package/dist/control-plane/odu/types.js +6 -0
- package/dist/control-plane/odu-control-plane.js +316 -0
- package/dist/control-plane/single-agent.js +249 -0
- package/dist/control-plane/types.js +11 -0
- package/dist/control-ui/assets/index-D8Q5AI4D.js +2393 -0
- package/dist/control-ui/assets/index-D8Q5AI4D.js.map +1 -0
- package/dist/control-ui/assets/index-g06q5Xc3.css +1 -0
- package/dist/control-ui/favicon.ico +0 -0
- package/dist/control-ui/index.html +16 -0
- package/dist/credentials/store.js +449 -0
- package/dist/cron/isolated-agent.js +529 -0
- package/dist/cron/normalize.js +73 -0
- package/dist/cron/parse.js +24 -0
- package/dist/cron/run-log.js +72 -0
- package/dist/cron/schedule.js +24 -0
- package/dist/cron/service.js +471 -0
- package/dist/cron/store.js +43 -0
- package/dist/cron/types.js +1 -0
- package/dist/daemon/constants.js +10 -0
- package/dist/daemon/launchd.js +309 -0
- package/dist/daemon/legacy.js +63 -0
- package/dist/daemon/program-args.js +141 -0
- package/dist/daemon/schtasks.js +269 -0
- package/dist/daemon/service.js +69 -0
- package/dist/daemon/systemd.js +332 -0
- package/dist/discord/index.js +2 -0
- package/dist/discord/monitor.js +1089 -0
- package/dist/discord/probe.js +54 -0
- package/dist/discord/send.js +652 -0
- package/dist/discord/token.js +8 -0
- package/dist/entry.js +16 -0
- package/dist/gateway/auth.js +121 -0
- package/dist/gateway/call.js +103 -0
- package/dist/gateway/chat-attachments.js +41 -0
- package/dist/gateway/client.js +180 -0
- package/dist/gateway/config-reload.js +279 -0
- package/dist/gateway/control-ui.js +184 -0
- package/dist/gateway/hooks-mapping.js +282 -0
- package/dist/gateway/hooks.js +168 -0
- package/dist/gateway/net.js +29 -0
- package/dist/gateway/protocol/index.js +62 -0
- package/dist/gateway/protocol/schema.js +577 -0
- package/dist/gateway/server-bridge-subscriptions.js +93 -0
- package/dist/gateway/server-bridge.js +1066 -0
- package/dist/gateway/server-browser.js +12 -0
- package/dist/gateway/server-channels.js +680 -0
- package/dist/gateway/server-chat.js +159 -0
- package/dist/gateway/server-constants.js +8 -0
- package/dist/gateway/server-discovery.js +62 -0
- package/dist/gateway/server-http.js +165 -0
- package/dist/gateway/server-methods/agent-job.js +114 -0
- package/dist/gateway/server-methods/agent.js +254 -0
- package/dist/gateway/server-methods/channels.js +239 -0
- package/dist/gateway/server-methods/chat.js +207 -0
- package/dist/gateway/server-methods/config.js +50 -0
- package/dist/gateway/server-methods/connect.js +6 -0
- package/dist/gateway/server-methods/cron.js +99 -0
- package/dist/gateway/server-methods/health.js +28 -0
- package/dist/gateway/server-methods/models.js +16 -0
- package/dist/gateway/server-methods/nodes.js +294 -0
- package/dist/gateway/server-methods/providers.js +257 -0
- package/dist/gateway/server-methods/send.js +254 -0
- package/dist/gateway/server-methods/sessions.js +382 -0
- package/dist/gateway/server-methods/skills.js +83 -0
- package/dist/gateway/server-methods/system.js +118 -0
- package/dist/gateway/server-methods/talk.js +22 -0
- package/dist/gateway/server-methods/types.js +1 -0
- package/dist/gateway/server-methods/voicewake.js +30 -0
- package/dist/gateway/server-methods/web.js +81 -0
- package/dist/gateway/server-methods/wizard.js +100 -0
- package/dist/gateway/server-methods.js +53 -0
- package/dist/gateway/server-providers.js +687 -0
- package/dist/gateway/server-shared.js +1 -0
- package/dist/gateway/server-utils.js +35 -0
- package/dist/gateway/server.js +1492 -0
- package/dist/gateway/session-utils.js +355 -0
- package/dist/gateway/ws-log.js +343 -0
- package/dist/gateway/ws-logging.js +8 -0
- package/dist/globals.js +41 -0
- package/dist/hooks/gmail-ops.js +236 -0
- package/dist/hooks/gmail-setup-utils.js +278 -0
- package/dist/hooks/gmail-watcher.js +190 -0
- package/dist/hooks/gmail.js +177 -0
- package/dist/imessage/client.js +165 -0
- package/dist/imessage/index.js +3 -0
- package/dist/imessage/monitor.js +365 -0
- package/dist/imessage/probe.js +26 -0
- package/dist/imessage/send.js +83 -0
- package/dist/imessage/targets.js +176 -0
- package/dist/index.js +55 -0
- package/dist/infra/agent-events.js +46 -0
- package/dist/infra/binaries.js +9 -0
- package/dist/infra/bonjour-discovery.js +163 -0
- package/dist/infra/bonjour.js +200 -0
- package/dist/infra/bridge/server.js +564 -0
- package/dist/infra/canvas-host-url.js +54 -0
- package/dist/infra/channel-summary.js +78 -0
- package/dist/infra/control-ui-assets.js +112 -0
- package/dist/infra/dotenv.js +15 -0
- package/dist/infra/env.js +8 -0
- package/dist/infra/errors.js +28 -0
- package/dist/infra/event-log.js +257 -0
- package/dist/infra/gateway-lock.js +8 -0
- package/dist/infra/git-commit.js +91 -0
- package/dist/infra/heartbeat-events.js +21 -0
- package/dist/infra/heartbeat-runner.js +458 -0
- package/dist/infra/heartbeat-wake.js +61 -0
- package/dist/infra/is-main.js +37 -0
- package/dist/infra/json-file.js +21 -0
- package/dist/infra/machine-name.js +40 -0
- package/dist/infra/nexus-root.js +56 -0
- package/dist/infra/node-pairing.js +212 -0
- package/dist/infra/path-env.js +92 -0
- package/dist/infra/ports.js +87 -0
- package/dist/infra/provider-summary.js +80 -0
- package/dist/infra/provider-usage.auth.js +191 -0
- package/dist/infra/provider-usage.fetch.claude.js +139 -0
- package/dist/infra/provider-usage.fetch.codex.js +62 -0
- package/dist/infra/provider-usage.fetch.copilot.js +42 -0
- package/dist/infra/provider-usage.fetch.gemini.js +57 -0
- package/dist/infra/provider-usage.fetch.js +6 -0
- package/dist/infra/provider-usage.fetch.minimax.js +219 -0
- package/dist/infra/provider-usage.fetch.shared.js +11 -0
- package/dist/infra/provider-usage.fetch.zai.js +62 -0
- package/dist/infra/provider-usage.format.js +77 -0
- package/dist/infra/provider-usage.js +149 -0
- package/dist/infra/provider-usage.load.js +54 -0
- package/dist/infra/provider-usage.shared.js +19 -0
- package/dist/infra/provider-usage.types.js +1 -0
- package/dist/infra/restart.js +29 -0
- package/dist/infra/retry.js +16 -0
- package/dist/infra/runtime-guard.js +59 -0
- package/dist/infra/shell-env.js +88 -0
- package/dist/infra/system-events.js +71 -0
- package/dist/infra/system-presence.js +217 -0
- package/dist/infra/tailnet.js +46 -0
- package/dist/infra/tailscale.js +149 -0
- package/dist/infra/unhandled-rejections.js +19 -0
- package/dist/infra/usage-settings.js +78 -0
- package/dist/infra/usage-suggestions.js +253 -0
- package/dist/infra/usage-upload.js +327 -0
- package/dist/infra/voicewake.js +78 -0
- package/dist/infra/widearea-dns.js +123 -0
- package/dist/infra/ws.js +13 -0
- package/dist/logger.js +52 -0
- package/dist/logging/redact.js +109 -0
- package/dist/logging.js +506 -0
- package/dist/macos/gateway-daemon.js +145 -0
- package/dist/macos/relay.js +49 -0
- package/dist/markdown/fences.js +58 -0
- package/dist/media/constants.js +33 -0
- package/dist/media/host.js +42 -0
- package/dist/media/image-ops.js +121 -0
- package/dist/media/mime.js +123 -0
- package/dist/media/parse.js +83 -0
- package/dist/media/server.js +64 -0
- package/dist/media/store.js +139 -0
- package/dist/memory/embeddings.js +146 -0
- package/dist/memory/index.js +3 -0
- package/dist/memory/internal.js +163 -0
- package/dist/native/nexus-cloud/darwin-arm64/nexus-cloud +0 -0
- package/dist/native/nexus-cloud/darwin-arm64/nexus-cloud-rs +0 -0
- package/dist/native/nexus-cloud/darwin-x64/nexus-cloud-rs +0 -0
- package/dist/native/nexus-cloud/linux-arm64/nexus-cloud-rs +0 -0
- package/dist/native/nexus-cloud/linux-x64/nexus-cloud-rs +0 -0
- package/dist/native/nexus-cloud/win32-x64/nexus-cloud-rs.exe +0 -0
- package/dist/pairing/pairing-store.js +218 -0
- package/dist/plugins/cli.js +42 -0
- package/dist/plugins/discovery.js +253 -0
- package/dist/plugins/install.js +181 -0
- package/dist/plugins/loader.js +290 -0
- package/dist/plugins/registry.js +105 -0
- package/dist/plugins/status.js +29 -0
- package/dist/plugins/tools.js +39 -0
- package/dist/plugins/types.js +1 -0
- package/dist/polls.js +43 -0
- package/dist/process/command-queue.js +97 -0
- package/dist/process/exec.js +75 -0
- package/dist/provider-web.js +8 -0
- package/dist/providers/github-copilot-auth.js +123 -0
- package/dist/providers/github-copilot-models.js +35 -0
- package/dist/providers/github-copilot-token.js +11 -0
- package/dist/providers/location.js +48 -0
- package/dist/providers/web/index.js +2 -0
- package/dist/routing/resolve-route.js +144 -0
- package/dist/routing/session-key.js +65 -0
- package/dist/runtime.js +8 -0
- package/dist/sessions/level-overrides.js +9 -0
- package/dist/sessions/send-policy.js +68 -0
- package/dist/signal/client.js +134 -0
- package/dist/signal/daemon.js +69 -0
- package/dist/signal/index.js +3 -0
- package/dist/signal/monitor.js +411 -0
- package/dist/signal/probe.js +46 -0
- package/dist/signal/send.js +91 -0
- package/dist/skills/scan-runner.js +204 -0
- package/dist/slack/actions.js +97 -0
- package/dist/slack/index.js +5 -0
- package/dist/slack/monitor.js +1291 -0
- package/dist/slack/probe.js +47 -0
- package/dist/slack/send.js +131 -0
- package/dist/slack/token.js +10 -0
- package/dist/telegram/allowed-updates.js +8 -0
- package/dist/telegram/bot.js +724 -0
- package/dist/telegram/download.js +34 -0
- package/dist/telegram/index.js +4 -0
- package/dist/telegram/monitor.js +47 -0
- package/dist/telegram/pairing-store.js +77 -0
- package/dist/telegram/probe.js +63 -0
- package/dist/telegram/proxy.js +9 -0
- package/dist/telegram/reaction-level.js +46 -0
- package/dist/telegram/send.js +151 -0
- package/dist/telegram/sent-message-cache.js +65 -0
- package/dist/telegram/token.js +30 -0
- package/dist/telegram/update-offset-store.js +61 -0
- package/dist/telegram/webhook-set.js +12 -0
- package/dist/telegram/webhook.js +56 -0
- package/dist/tui/commands.js +87 -0
- package/dist/tui/components/assistant-message.js +16 -0
- package/dist/tui/components/chat-log.js +92 -0
- package/dist/tui/components/custom-editor.js +55 -0
- package/dist/tui/components/selectors.js +8 -0
- package/dist/tui/components/tool-execution.js +111 -0
- package/dist/tui/components/user-message.js +17 -0
- package/dist/tui/gateway-chat.js +140 -0
- package/dist/tui/theme/theme.js +80 -0
- package/dist/tui/tui.js +708 -0
- package/dist/utils/provider-utils.js +28 -0
- package/dist/utils.js +158 -0
- package/dist/version.js +18 -0
- package/dist/web/accounts.js +86 -0
- package/dist/web/active-listener.js +25 -0
- package/dist/web/auto-reply.js +1256 -0
- package/dist/web/inbound.js +649 -0
- package/dist/web/login-qr.js +230 -0
- package/dist/web/login.js +71 -0
- package/dist/web/media.js +175 -0
- package/dist/web/outbound.js +102 -0
- package/dist/web/qr-image.js +97 -0
- package/dist/web/reconnect.js +60 -0
- package/dist/web/session.js +370 -0
- package/dist/wizard/clack-prompter.js +56 -0
- package/dist/wizard/onboarding.js +642 -0
- package/dist/wizard/prompts.js +6 -0
- package/dist/wizard/session.js +203 -0
- package/docs/AGENTS.default.md +116 -0
- package/docs/CAPABILITIES.md +444 -0
- package/docs/CNAME +1 -0
- package/docs/NEXUS_CORE_REWRITE_SPEC.md +226 -0
- package/docs/RELEASING.md +69 -0
- package/docs/_config.yml +53 -0
- package/docs/_layouts/default.html +145 -0
- package/docs/agent-assisted-install.md +95 -0
- package/docs/agent-loop.md +61 -0
- package/docs/agent-send.md +21 -0
- package/docs/agent.md +108 -0
- package/docs/android.md +133 -0
- package/docs/architecture.md +114 -0
- package/docs/assets/markdown.css +133 -0
- package/docs/assets/pixel-lobster.svg +60 -0
- package/docs/assets/terminal.css +470 -0
- package/docs/assets/theme.js +55 -0
- package/docs/audio.md +48 -0
- package/docs/automation/nexus-sync.md +371 -0
- package/docs/background-process.md +74 -0
- package/docs/bash.md +32 -0
- package/docs/bedrock.md +71 -0
- package/docs/bonjour.md +159 -0
- package/docs/browser-linux-troubleshooting.md +114 -0
- package/docs/browser.md +293 -0
- package/docs/bun.md +56 -0
- package/docs/camera.md +152 -0
- package/docs/clawd.md +212 -0
- package/docs/concepts/usage-tracking.md +29 -0
- package/docs/configuration.md +1666 -0
- package/docs/control-ui.md +83 -0
- package/docs/cron.md +385 -0
- package/docs/dashboard.md +17 -0
- package/docs/device-models.md +46 -0
- package/docs/discord.md +308 -0
- package/docs/discovery.md +112 -0
- package/docs/docker.md +258 -0
- package/docs/docs.json +105 -0
- package/docs/doctor.md +68 -0
- package/docs/elevated.md +31 -0
- package/docs/faq.md +736 -0
- package/docs/feature-inventory/overview.md +141 -0
- package/docs/feature-inventory/rollout-checklist.md +53 -0
- package/docs/feature-inventory/test-matrix.md +87 -0
- package/docs/feature-inventory.md +9 -0
- package/docs/gateway/configuration-examples.md +221 -0
- package/docs/gateway/configuration.md +172 -0
- package/docs/gateway/cron.md +61 -0
- package/docs/gateway/heartbeat.md +207 -0
- package/docs/gateway/pairing.md +109 -0
- package/docs/gateway-lock.md +28 -0
- package/docs/gateway.md +227 -0
- package/docs/gmail-pubsub.md +191 -0
- package/docs/grammy.md +27 -0
- package/docs/group-messages.md +73 -0
- package/docs/groups.md +130 -0
- package/docs/health.md +28 -0
- package/docs/heartbeat.md +73 -0
- package/docs/home-userspace.md +277 -0
- package/docs/hubs.md +148 -0
- package/docs/images.md +51 -0
- package/docs/imessage.md +94 -0
- package/docs/index.md +196 -0
- package/docs/ios.md +372 -0
- package/docs/linux.md +11 -0
- package/docs/location-command.md +95 -0
- package/docs/location.md +46 -0
- package/docs/logging.md +110 -0
- package/docs/lore.md +131 -0
- package/docs/mac/bun.md +133 -0
- package/docs/mac/canvas.md +161 -0
- package/docs/mac/child-process.md +72 -0
- package/docs/mac/dev-setup.md +81 -0
- package/docs/mac/health.md +28 -0
- package/docs/mac/icon.md +26 -0
- package/docs/mac/logging.md +51 -0
- package/docs/mac/menu-bar.md +69 -0
- package/docs/mac/peekaboo.md +170 -0
- package/docs/mac/permissions.md +40 -0
- package/docs/mac/release.md +76 -0
- package/docs/mac/remote.md +57 -0
- package/docs/mac/signing.md +41 -0
- package/docs/mac/skills.md +27 -0
- package/docs/mac/voice-overlay.md +52 -0
- package/docs/mac/voicewake.md +56 -0
- package/docs/mac/webchat.md +27 -0
- package/docs/mac/xpc.md +40 -0
- package/docs/macos.md +104 -0
- package/docs/model-failover.md +75 -0
- package/docs/models.md +91 -0
- package/docs/multi-agent.md +74 -0
- package/docs/nix.md +95 -0
- package/docs/nodes.md +157 -0
- package/docs/onboarding-config-protocol.md +34 -0
- package/docs/onboarding.md +189 -0
- package/docs/pairing.md +85 -0
- package/docs/plans/cron-add-hardening.md +72 -0
- package/docs/plans/group-policy-hardening.md +121 -0
- package/docs/poll.md +52 -0
- package/docs/prereqs.md +67 -0
- package/docs/presence.md +133 -0
- package/docs/proposals/model-config.md +147 -0
- package/docs/provider-routing.md +25 -0
- package/docs/queue.md +78 -0
- package/docs/reference/templates/AGENTS.md +226 -0
- package/docs/remote-gateway-readme.md +153 -0
- package/docs/remote.md +61 -0
- package/docs/research/memory.md +227 -0
- package/docs/rpc.md +35 -0
- package/docs/security.md +200 -0
- package/docs/session-ingestion.md +119 -0
- package/docs/session-tool.md +154 -0
- package/docs/session.md +85 -0
- package/docs/sessions.md +8 -0
- package/docs/setup.md +131 -0
- package/docs/showcase.md +37 -0
- package/docs/signal.md +122 -0
- package/docs/skills-config.md +68 -0
- package/docs/skills-scan.md +81 -0
- package/docs/skills-updates.md +113 -0
- package/docs/skills.md +166 -0
- package/docs/slack.md +221 -0
- package/docs/subagents.md +72 -0
- package/docs/tailscale.md +71 -0
- package/docs/talk.md +79 -0
- package/docs/telegram.md +96 -0
- package/docs/templates/AGENTS.md +226 -0
- package/docs/templates/BOOTSTRAP.md +55 -0
- package/docs/templates/IDENTITY.md +23 -0
- package/docs/templates/SOUL.md +41 -0
- package/docs/templates/TOOLS.md +41 -0
- package/docs/templates/USER.md +28 -0
- package/docs/test.md +43 -0
- package/docs/testing-onboarding-quickstart.md +76 -0
- package/docs/testing-philosophy.md +211 -0
- package/docs/thinking.md +46 -0
- package/docs/timezone.md +40 -0
- package/docs/tools.md +346 -0
- package/docs/troubleshooting.md +257 -0
- package/docs/tui.md +71 -0
- package/docs/typebox.md +42 -0
- package/docs/updating.md +138 -0
- package/docs/usage-cloud-aggregation-spec.md +133 -0
- package/docs/usage-suggestions-pipeline.md +126 -0
- package/docs/voicewake.md +61 -0
- package/docs/web.md +115 -0
- package/docs/webchat.md +34 -0
- package/docs/webhook.md +132 -0
- package/docs/whatsapp-clawd.jpg +0 -0
- package/docs/whatsapp.md +170 -0
- package/docs/windows.md +11 -0
- package/docs/wizard.md +167 -0
- package/package.json +186 -0
- package/patches/@mariozechner__pi-ai.patch +215 -0
- package/patches/playwright-core@1.57.0.patch +13 -0
- package/patches/qrcode-terminal.patch +12 -0
- package/scripts/postinstall.js +202 -0
- package/skills/connectors/brave-search/SKILL.md +36 -0
- package/skills/connectors/brave-search/docs/setup.md +40 -0
- package/skills/connectors/brave-search/docs/troubleshooting.md +37 -0
- package/skills/connectors/brave-search/docs/usage.md +28 -0
- package/skills/connectors/brave-search/scripts/content.mjs +53 -0
- package/skills/connectors/brave-search/scripts/search.mjs +79 -0
- package/skills/connectors/discord/SKILL.md +370 -0
- package/skills/connectors/gemini/SKILL.md +23 -0
- package/skills/connectors/github/SKILL.md +26 -0
- package/skills/connectors/github/docs/setup.md +21 -0
- package/skills/connectors/github/docs/troubleshooting.md +24 -0
- package/skills/connectors/google-oauth/SKILL.md +94 -0
- package/skills/connectors/notion/SKILL.md +156 -0
- package/skills/connectors/slack/SKILL.md +144 -0
- package/skills/connectors/telegram/SKILL.md +20 -0
- package/skills/connectors/telegram/docs/pairing.md +30 -0
- package/skills/connectors/telegram/docs/setup.md +41 -0
- package/skills/connectors/telegram/docs/webhook.md +17 -0
- package/skills/connectors/wacli/SKILL.md +48 -0
- package/skills/connectors/wacli/docs/auth.md +21 -0
- package/skills/connectors/wacli/docs/backup.md +9 -0
- package/skills/connectors/wacli/docs/troubleshooting.md +21 -0
- package/skills/guides/browser-use-agent-sdk/SKILL.md +90 -0
- package/skills/guides/filesystem/SKILL.md +217 -0
- package/skills/guides/json-render/SKILL.md +154 -0
- package/skills/guides/json-render/assets/components/README.md +21 -0
- package/skills/guides/json-render/assets/components/catalog.ts +78 -0
- package/skills/guides/json-render/assets/components/registry.tsx +172 -0
- package/skills/guides/json-render/assets/demo/App.css +397 -0
- package/skills/guides/json-render/assets/demo/App.tsx +897 -0
- package/skills/guides/json-render/assets/demo/README.md +22 -0
- package/skills/guides/json-render/assets/demo/catalog.ts +78 -0
- package/skills/guides/json-render/assets/demo/data/nexus-core.json +31 -0
- package/skills/guides/json-render/assets/demo/index.css +27 -0
- package/skills/guides/json-render/assets/demo/registry.tsx +150 -0
- package/skills/guides/json-render/docs/nexus-state-demo.md +84 -0
- package/skills/guides/json-render/docs/shadcn-preset.md +33 -0
- package/skills/guides/json-render/scripts/create-vite-demo.sh +45 -0
- package/skills/guides/json-render/scripts/llm-server/README.md +33 -0
- package/skills/guides/json-render/scripts/llm-server/catalog.ts +78 -0
- package/skills/guides/json-render/scripts/llm-server/package-lock.json +702 -0
- package/skills/guides/json-render/scripts/llm-server/package.json +18 -0
- package/skills/guides/json-render/scripts/llm-server/server.ts +285 -0
- package/skills/skill-creator/scripts/__pycache__/quick_validate.cpython-311.pyc +0 -0
- package/skills/tools/1password/SKILL.md +54 -0
- package/skills/tools/1password/docs/setup.md +85 -0
- package/skills/tools/1password/docs/troubleshooting.md +63 -0
- package/skills/tools/1password/references/cli-examples.md +29 -0
- package/skills/tools/1password/references/get-started.md +17 -0
- package/skills/tools/agent-browser/SKILL.md +450 -0
- package/skills/tools/agent-browser/docs/browser-use-eval.md +95 -0
- package/skills/tools/agent-browser/docs/first-tests.md +261 -0
- package/skills/tools/agent-browser/docs/wordle-nyt-eval.js +32 -0
- package/skills/tools/aix/SKILL.md +93 -0
- package/skills/tools/aix/docs/embeddings.md +40 -0
- package/skills/tools/aix/docs/setup.md +58 -0
- package/skills/tools/aix/docs/troubleshooting.md +41 -0
- package/skills/tools/aix/references/sql.md +48 -0
- package/skills/tools/apple-notes/SKILL.md +50 -0
- package/skills/tools/apple-reminders/SKILL.md +67 -0
- package/skills/tools/bear-notes/SKILL.md +79 -0
- package/skills/tools/bird/SKILL.md +32 -0
- package/skills/tools/bird/docs/auth.md +31 -0
- package/skills/tools/bird/docs/troubleshooting.md +31 -0
- package/skills/tools/blogwatcher/SKILL.md +46 -0
- package/skills/tools/blucli/SKILL.md +27 -0
- package/skills/tools/camsnap/SKILL.md +25 -0
- package/skills/tools/clawdhub/SKILL.md +53 -0
- package/skills/tools/coding-agent/SKILL.md +274 -0
- package/skills/tools/comms/SKILL.md +249 -0
- package/skills/tools/comms/docs/adapters.md +54 -0
- package/skills/tools/comms/docs/setup.md +56 -0
- package/skills/tools/comms/docs/troubleshooting.md +44 -0
- package/skills/tools/comms/references/schema.md +49 -0
- package/skills/tools/computer-use/SKILL.md +204 -0
- package/skills/tools/computer-use/docs/open-interpreter.md +26 -0
- package/skills/tools/computer-use/docs/peekaboo.md +26 -0
- package/skills/tools/computer-use/docs/setup.md +47 -0
- package/skills/tools/computer-use/docs/troubleshooting.md +33 -0
- package/skills/tools/eightctl/SKILL.md +29 -0
- package/skills/tools/eve/SKILL.md +215 -0
- package/skills/tools/eve/docs/dual-account.md +84 -0
- package/skills/tools/eve/docs/intelligence.md +58 -0
- package/skills/tools/eve/docs/setup.md +60 -0
- package/skills/tools/eve/docs/troubleshooting.md +54 -0
- package/skills/tools/eve/scripts/setup-dual-account.sh +125 -0
- package/skills/tools/food-order/SKILL.md +41 -0
- package/skills/tools/gh/SKILL.md +22 -0
- package/skills/tools/gh/docs/usage.md +41 -0
- package/skills/tools/gifgrep/SKILL.md +47 -0
- package/skills/tools/gog/SKILL.md +104 -0
- package/skills/tools/gog/docs/portability.md +94 -0
- package/skills/tools/gog/docs/setup.md +76 -0
- package/skills/tools/gog/docs/troubleshooting.md +94 -0
- package/skills/tools/gog/scripts/cdp/README.md +90 -0
- package/skills/tools/gog/scripts/cdp/add_test_users.py +69 -0
- package/skills/tools/gog/scripts/cdp/auth_add_accounts.py +209 -0
- package/skills/tools/gog/scripts/cdp/auth_add_accounts_manual.py +206 -0
- package/skills/tools/gog/scripts/cdp/create_oauth_client.py +165 -0
- package/skills/tools/gog/scripts/cdp/launch_cdp_chrome.sh +58 -0
- package/skills/tools/goplaces/SKILL.md +30 -0
- package/skills/tools/imsg/SKILL.md +25 -0
- package/skills/tools/local-places/SERVER_README.md +101 -0
- package/skills/tools/local-places/SKILL.md +91 -0
- package/skills/tools/local-places/pyproject.toml +27 -0
- package/skills/tools/local-places/src/local_places/__init__.py +2 -0
- package/skills/tools/local-places/src/local_places/__pycache__/__init__.cpython-314.pyc +0 -0
- package/skills/tools/local-places/src/local_places/__pycache__/google_places.cpython-314.pyc +0 -0
- package/skills/tools/local-places/src/local_places/__pycache__/main.cpython-314.pyc +0 -0
- package/skills/tools/local-places/src/local_places/__pycache__/schemas.cpython-314.pyc +0 -0
- package/skills/tools/local-places/src/local_places/google_places.py +314 -0
- package/skills/tools/local-places/src/local_places/main.py +65 -0
- package/skills/tools/local-places/src/local_places/schemas.py +107 -0
- package/skills/tools/mcporter/SKILL.md +38 -0
- package/skills/tools/model-usage/SKILL.md +45 -0
- package/skills/tools/model-usage/references/codexbar-cli.md +28 -0
- package/skills/tools/model-usage/scripts/model_usage.py +310 -0
- package/skills/tools/nano-banana-pro/SKILL.md +30 -0
- package/skills/tools/nano-banana-pro/scripts/generate_image.py +169 -0
- package/skills/tools/nano-pdf/SKILL.md +20 -0
- package/skills/tools/nexus-cloud/SKILL.md +54 -0
- package/skills/tools/nexus-cloud/docs/security.md +24 -0
- package/skills/tools/nexus-cloud/docs/setup.md +51 -0
- package/skills/tools/nexus-cloud/docs/troubleshooting.md +28 -0
- package/skills/tools/obsidian/SKILL.md +55 -0
- package/skills/tools/openai-image-gen/SKILL.md +31 -0
- package/skills/tools/openai-image-gen/scripts/gen.py +173 -0
- package/skills/tools/openai-whisper/SKILL.md +19 -0
- package/skills/tools/openai-whisper-api/SKILL.md +43 -0
- package/skills/tools/openai-whisper-api/scripts/transcribe.sh +85 -0
- package/skills/tools/openhue/SKILL.md +30 -0
- package/skills/tools/oracle/SKILL.md +105 -0
- package/skills/tools/ordercli/SKILL.md +47 -0
- package/skills/tools/peekaboo/SKILL.md +153 -0
- package/skills/tools/qmd/SKILL.md +32 -0
- package/skills/tools/qmd/docs/mcp.md +30 -0
- package/skills/tools/qmd/docs/ollama.md +42 -0
- package/skills/tools/qmd/docs/setup.md +44 -0
- package/skills/tools/sag/SKILL.md +62 -0
- package/skills/tools/skill-cli-template/SKILL.md +109 -0
- package/skills/tools/songsee/SKILL.md +29 -0
- package/skills/tools/sonoscli/SKILL.md +26 -0
- package/skills/tools/spotify-player/SKILL.md +34 -0
- package/skills/tools/summarize/SKILL.md +49 -0
- package/skills/tools/things-mac/SKILL.md +61 -0
- package/skills/tools/tmux/SKILL.md +121 -0
- package/skills/tools/tmux/scripts/find-sessions.sh +112 -0
- package/skills/tools/tmux/scripts/wait-for-text.sh +83 -0
- package/skills/tools/trello/SKILL.md +84 -0
- package/skills/tools/upstream-sync/SKILL.md +151 -0
- package/skills/tools/upstream-sync/scripts/auto-port.sh +227 -0
- package/skills/tools/upstream-sync/scripts/check-all.sh +88 -0
- package/skills/tools/upstream-sync/scripts/check-nexus.sh +146 -0
- package/skills/tools/upstream-sync/scripts/check-pi-ai.sh +129 -0
- package/skills/tools/video-frames/SKILL.md +29 -0
- package/skills/tools/video-frames/scripts/frame.sh +81 -0
- package/skills/tools/weather/SKILL.md +53 -0
- package/skills/tools/weather/docs/usage.md +40 -0
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import fsp from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { resolveUserPath } from "../utils.js";
|
|
4
|
+
const DEFAULT_SCRIPT_NAME = "nexus-session-start.js";
|
|
5
|
+
const HOOK_SCRIPT = `#!/usr/bin/env node
|
|
6
|
+
const { execFile } = require("child_process");
|
|
7
|
+
const fs = require("fs");
|
|
8
|
+
const fsp = require("fs/promises");
|
|
9
|
+
const os = require("os");
|
|
10
|
+
const path = require("path");
|
|
11
|
+
|
|
12
|
+
const MAX_IDENTITY_CHARS = 120000;
|
|
13
|
+
const MAX_MEMORY_CHARS = 120000;
|
|
14
|
+
const MAX_DAILY_CHARS = 40000;
|
|
15
|
+
const MAX_BOOTSTRAP_CHARS = 80000;
|
|
16
|
+
|
|
17
|
+
function readStdin() {
|
|
18
|
+
return new Promise((resolve) => {
|
|
19
|
+
let data = "";
|
|
20
|
+
process.stdin.setEncoding("utf8");
|
|
21
|
+
process.stdin.on("data", (chunk) => {
|
|
22
|
+
data += chunk;
|
|
23
|
+
});
|
|
24
|
+
process.stdin.on("end", () => resolve(data));
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function safeJsonParse(raw) {
|
|
29
|
+
if (!raw || !raw.trim()) return null;
|
|
30
|
+
try {
|
|
31
|
+
return JSON.parse(raw);
|
|
32
|
+
} catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function formatDate(date) {
|
|
38
|
+
const year = date.getFullYear();
|
|
39
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
40
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
41
|
+
return \`\${year}-\${month}-\${day}\`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function resolveWorkspaceRoot(payload) {
|
|
45
|
+
const roots = payload?.workspace_roots;
|
|
46
|
+
if (Array.isArray(roots) && roots.length > 0 && roots[0]) {
|
|
47
|
+
return roots[0];
|
|
48
|
+
}
|
|
49
|
+
if (process.env.NEXUS_ROOT?.trim()) return process.env.NEXUS_ROOT.trim();
|
|
50
|
+
const home = os.homedir();
|
|
51
|
+
if (home) return path.join(home, "nexus");
|
|
52
|
+
return process.cwd();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function resolveStateDir(workspaceRoot) {
|
|
56
|
+
if (process.env.NEXUS_STATE_DIR?.trim()) {
|
|
57
|
+
return process.env.NEXUS_STATE_DIR.trim();
|
|
58
|
+
}
|
|
59
|
+
return path.join(workspaceRoot, "state");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function execFileAsync(command, args, options) {
|
|
63
|
+
return new Promise((resolve) => {
|
|
64
|
+
execFile(command, args, options, (error, stdout, stderr) => {
|
|
65
|
+
resolve({ error, stdout, stderr });
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function runStatus(env, cwd) {
|
|
71
|
+
const result = await execFileAsync("nexus", ["status", "--json"], {
|
|
72
|
+
env,
|
|
73
|
+
cwd,
|
|
74
|
+
});
|
|
75
|
+
const parsed = safeJsonParse(result.stdout);
|
|
76
|
+
if (parsed) return parsed;
|
|
77
|
+
if (result.error && result.error.stdout) {
|
|
78
|
+
const fallback = safeJsonParse(result.error.stdout.toString());
|
|
79
|
+
if (fallback) return fallback;
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async function readFileSnippet(filePath, limit) {
|
|
85
|
+
if (!filePath) return null;
|
|
86
|
+
try {
|
|
87
|
+
const content = await fsp.readFile(filePath, "utf8");
|
|
88
|
+
if (!content.trim()) return null;
|
|
89
|
+
if (content.length <= limit) return content.trim();
|
|
90
|
+
const slice = content.slice(-limit).trimStart();
|
|
91
|
+
return \`\${slice}\\n\\n[truncated]\`;
|
|
92
|
+
} catch {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function addSection(sections, title, body) {
|
|
98
|
+
if (!body) return;
|
|
99
|
+
sections.push(\`## \${title}\\n\${body}\`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function main() {
|
|
103
|
+
const input = await readStdin();
|
|
104
|
+
const payload = safeJsonParse(input) || {};
|
|
105
|
+
const workspaceRoot = resolveWorkspaceRoot(payload);
|
|
106
|
+
const stateDir = resolveStateDir(workspaceRoot);
|
|
107
|
+
const env = {
|
|
108
|
+
...process.env,
|
|
109
|
+
NEXUS_ROOT: workspaceRoot,
|
|
110
|
+
NEXUS_STATE_DIR: stateDir,
|
|
111
|
+
};
|
|
112
|
+
const status = await runStatus(env, workspaceRoot);
|
|
113
|
+
const identity = status?.identity || null;
|
|
114
|
+
const agentId = identity?.agentId || process.env.NEXUS_AGENT_ID || "default";
|
|
115
|
+
const agentIdentityPath =
|
|
116
|
+
identity?.agentIdentityPath ||
|
|
117
|
+
path.join(stateDir, "agents", agentId, "IDENTITY.md");
|
|
118
|
+
const agentSoulPath =
|
|
119
|
+
identity?.agentSoulPath || path.join(stateDir, "agents", agentId, "SOUL.md");
|
|
120
|
+
const agentMemoryPath =
|
|
121
|
+
identity?.agentMemoryPath ||
|
|
122
|
+
path.join(stateDir, "agents", agentId, "MEMORY.md");
|
|
123
|
+
const userIdentityPath =
|
|
124
|
+
identity?.userIdentityPath || path.join(stateDir, "user", "IDENTITY.md");
|
|
125
|
+
const userProfilePath = path.join(stateDir, "user", "PROFILE.md");
|
|
126
|
+
const resolvedUserPath = fs.existsSync(userIdentityPath)
|
|
127
|
+
? userIdentityPath
|
|
128
|
+
: fs.existsSync(userProfilePath)
|
|
129
|
+
? userProfilePath
|
|
130
|
+
: userIdentityPath;
|
|
131
|
+
|
|
132
|
+
const sections = ["# Nexus Session Bootstrap"];
|
|
133
|
+
if (identity) {
|
|
134
|
+
const summary = [
|
|
135
|
+
\`Agent: \${identity.agentName || "(unknown)"} (\${identity.agentId})\`,
|
|
136
|
+
\`User: \${identity.userName || "(unknown)"}\`,
|
|
137
|
+
\`Agent ID: \${identity.agentId}\`,
|
|
138
|
+
];
|
|
139
|
+
addSection(sections, "Status", summary.join("\\n"));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const bootstrapPath =
|
|
143
|
+
status?.identity?.bootstrapPath ||
|
|
144
|
+
path.join(stateDir, "agents", "BOOTSTRAP.md");
|
|
145
|
+
const hasIdentity =
|
|
146
|
+
typeof identity?.hasIdentity === "boolean"
|
|
147
|
+
? identity.hasIdentity
|
|
148
|
+
: fs.existsSync(agentIdentityPath) && fs.existsSync(resolvedUserPath);
|
|
149
|
+
let bootstrapPrompt = status?.bootstrap?.prompt || null;
|
|
150
|
+
if (!bootstrapPrompt && !hasIdentity) {
|
|
151
|
+
bootstrapPrompt = await readFileSnippet(
|
|
152
|
+
bootstrapPath,
|
|
153
|
+
MAX_BOOTSTRAP_CHARS,
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
if (bootstrapPrompt) {
|
|
157
|
+
addSection(sections, "Bootstrap Prompt", bootstrapPrompt.trim());
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const agentIdentity = await readFileSnippet(
|
|
161
|
+
agentIdentityPath,
|
|
162
|
+
MAX_IDENTITY_CHARS,
|
|
163
|
+
);
|
|
164
|
+
const agentSoul = await readFileSnippet(agentSoulPath, MAX_IDENTITY_CHARS);
|
|
165
|
+
const agentMemory = await readFileSnippet(agentMemoryPath, MAX_MEMORY_CHARS);
|
|
166
|
+
const userIdentity = await readFileSnippet(
|
|
167
|
+
resolvedUserPath,
|
|
168
|
+
MAX_IDENTITY_CHARS,
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
addSection(sections, "Agent Identity", agentIdentity);
|
|
172
|
+
addSection(sections, "Agent Soul", agentSoul);
|
|
173
|
+
addSection(sections, "Agent Memory", agentMemory);
|
|
174
|
+
addSection(sections, "User Identity", userIdentity);
|
|
175
|
+
|
|
176
|
+
const memoryDir = path.join(workspaceRoot, "home", "memory");
|
|
177
|
+
const today = formatDate(new Date());
|
|
178
|
+
const yesterday = formatDate(new Date(Date.now() - 86400000));
|
|
179
|
+
const todayLog = await readFileSnippet(
|
|
180
|
+
path.join(memoryDir, \`\${today}.md\`),
|
|
181
|
+
MAX_DAILY_CHARS,
|
|
182
|
+
);
|
|
183
|
+
const yesterdayLog = await readFileSnippet(
|
|
184
|
+
path.join(memoryDir, \`\${yesterday}.md\`),
|
|
185
|
+
MAX_DAILY_CHARS,
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
addSection(sections, \`Daily Memory (\${today})\`, todayLog);
|
|
189
|
+
addSection(sections, \`Daily Memory (\${yesterday})\`, yesterdayLog);
|
|
190
|
+
|
|
191
|
+
const additional = sections.join("\\n\\n").trim();
|
|
192
|
+
const output = { continue: true, additional_context: additional };
|
|
193
|
+
const envOut = {};
|
|
194
|
+
if (!process.env.NEXUS_ROOT?.trim() && workspaceRoot) {
|
|
195
|
+
envOut.NEXUS_ROOT = workspaceRoot;
|
|
196
|
+
}
|
|
197
|
+
if (!process.env.NEXUS_STATE_DIR?.trim() && stateDir) {
|
|
198
|
+
envOut.NEXUS_STATE_DIR = stateDir;
|
|
199
|
+
}
|
|
200
|
+
if (Object.keys(envOut).length > 0) {
|
|
201
|
+
output.env = envOut;
|
|
202
|
+
}
|
|
203
|
+
process.stdout.write(JSON.stringify(output) + "\\n");
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
main().catch(() => {
|
|
207
|
+
process.stdout.write(JSON.stringify({ continue: true }) + "\\n");
|
|
208
|
+
});
|
|
209
|
+
`;
|
|
210
|
+
async function writeFileIfMissing(filePath, content) {
|
|
211
|
+
try {
|
|
212
|
+
await fsp.writeFile(filePath, content, { encoding: "utf-8", flag: "wx" });
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
catch (err) {
|
|
216
|
+
const anyErr = err;
|
|
217
|
+
if (anyErr.code === "EEXIST")
|
|
218
|
+
return false;
|
|
219
|
+
throw err;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
export async function writeCursorHooks(options = {}) {
|
|
223
|
+
const workspaceDir = resolveUserPath(options.workspaceDir ?? process.cwd());
|
|
224
|
+
const hooksPath = options.hooksPath ?? path.join(workspaceDir, ".cursor", "hooks.json");
|
|
225
|
+
const scriptPath = options.scriptPath ??
|
|
226
|
+
path.join(workspaceDir, ".cursor", "hooks", DEFAULT_SCRIPT_NAME);
|
|
227
|
+
await fsp.mkdir(path.dirname(hooksPath), { recursive: true });
|
|
228
|
+
await fsp.mkdir(path.dirname(scriptPath), { recursive: true });
|
|
229
|
+
const hooksConfig = JSON.stringify({
|
|
230
|
+
version: 1,
|
|
231
|
+
hooks: {
|
|
232
|
+
sessionStart: [
|
|
233
|
+
{ command: `node .cursor/hooks/${DEFAULT_SCRIPT_NAME}` },
|
|
234
|
+
],
|
|
235
|
+
},
|
|
236
|
+
}, null, 2);
|
|
237
|
+
const hooksCreated = await writeFileIfMissing(hooksPath, `${hooksConfig}\n`);
|
|
238
|
+
const scriptCreated = await writeFileIfMissing(scriptPath, HOOK_SCRIPT);
|
|
239
|
+
return { hooksPath, scriptPath, hooksCreated, scriptCreated };
|
|
240
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import fsp from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { defaultRuntime } from "../runtime.js";
|
|
4
|
+
import { NEXUS_ROOT, SKILLS_STATE_DIR, WORKSPACE_SKILLS_DIR, resolveUserPath, } from "../utils.js";
|
|
5
|
+
/**
|
|
6
|
+
* Generate and write `.cursor/rules` for a given workspace.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* nexus cursor-rules [--workspace <path>]
|
|
10
|
+
*/
|
|
11
|
+
export async function cursorRulesCommand(opts, runtime = defaultRuntime) {
|
|
12
|
+
const workspaceDir = opts?.workspace?.trim() || NEXUS_ROOT;
|
|
13
|
+
const resolvedWorkspace = resolveUserPath(workspaceDir);
|
|
14
|
+
runtime.log(`Generating .cursor/rules for workspace: ${resolvedWorkspace}`);
|
|
15
|
+
const outputPath = await writeCursorRules({
|
|
16
|
+
workspaceDir: resolvedWorkspace,
|
|
17
|
+
outputPath: path.join(resolvedWorkspace, ".cursor", "rules"),
|
|
18
|
+
includeAgentsMd: true,
|
|
19
|
+
includeBootstrap: true,
|
|
20
|
+
});
|
|
21
|
+
runtime.log(`✓ Wrote ${outputPath}`);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Generate .cursor/rules content from Nexus skills and config
|
|
25
|
+
*/
|
|
26
|
+
export async function generateCursorRules(options = {}) {
|
|
27
|
+
const skillsDir = options.skillsDir || WORKSPACE_SKILLS_DIR;
|
|
28
|
+
const agentsPath = path.join(NEXUS_ROOT, "AGENTS.md");
|
|
29
|
+
const rules = `# Nexus Workspace - Cursor Configuration
|
|
30
|
+
|
|
31
|
+
This workspace uses Nexus. Follow the root \`AGENTS.md\` file for all protocols.
|
|
32
|
+
|
|
33
|
+
## Cursor-Specific
|
|
34
|
+
|
|
35
|
+
- Run \`nexus status\` first
|
|
36
|
+
- Cursor sessionStart hook injects identity context (see \`.cursor/hooks.json\`)
|
|
37
|
+
- Use the Shell tool for \`nexus\` commands
|
|
38
|
+
- Skill definitions live in \`${skillsDir}\`
|
|
39
|
+
- Skill state and usage logs live in \`${SKILLS_STATE_DIR}\`
|
|
40
|
+
- Read \`${agentsPath}\` for full instructions
|
|
41
|
+
`;
|
|
42
|
+
return `${rules.trim()}\n`;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Write cursor rules to the specified output path
|
|
46
|
+
*/
|
|
47
|
+
export async function writeCursorRules(options = {}) {
|
|
48
|
+
const workspaceDir = options.workspaceDir || process.cwd();
|
|
49
|
+
const outputPath = options.outputPath || path.join(workspaceDir, ".cursor", "rules");
|
|
50
|
+
const rules = await generateCursorRules(options);
|
|
51
|
+
// Ensure .cursor directory exists
|
|
52
|
+
const cursorDir = path.dirname(outputPath);
|
|
53
|
+
await fsp.mkdir(cursorDir, { recursive: true });
|
|
54
|
+
await fsp.writeFile(outputPath, rules, "utf-8");
|
|
55
|
+
return outputPath;
|
|
56
|
+
}
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import JSON5 from "json5";
|
|
5
|
+
import { resolveOAuthDir, resolveStateDir } from "../config/paths.js";
|
|
6
|
+
import { saveSessionStore } from "../config/sessions.js";
|
|
7
|
+
import { buildAgentMainSessionKey, DEFAULT_ACCOUNT_ID, DEFAULT_AGENT_ID, DEFAULT_MAIN_KEY, normalizeAgentId, } from "../routing/session-key.js";
|
|
8
|
+
function safeReadDir(dir) {
|
|
9
|
+
try {
|
|
10
|
+
return fs.readdirSync(dir, { withFileTypes: true });
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function existsDir(dir) {
|
|
17
|
+
try {
|
|
18
|
+
return fs.existsSync(dir) && fs.statSync(dir).isDirectory();
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function ensureDir(dir) {
|
|
25
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
26
|
+
}
|
|
27
|
+
function fileExists(p) {
|
|
28
|
+
try {
|
|
29
|
+
return fs.existsSync(p) && fs.statSync(p).isFile();
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function isLegacyWhatsAppAuthFile(name) {
|
|
36
|
+
if (name === "creds.json" || name === "creds.json.bak")
|
|
37
|
+
return true;
|
|
38
|
+
if (!name.endsWith(".json"))
|
|
39
|
+
return false;
|
|
40
|
+
return /^(app-state-sync|session|sender-key|pre-key)-/.test(name);
|
|
41
|
+
}
|
|
42
|
+
function readSessionStoreJson5(storePath) {
|
|
43
|
+
try {
|
|
44
|
+
const raw = fs.readFileSync(storePath, "utf-8");
|
|
45
|
+
const parsed = JSON5.parse(raw);
|
|
46
|
+
if (parsed && typeof parsed === "object") {
|
|
47
|
+
return { store: parsed, ok: true };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// ignore
|
|
52
|
+
}
|
|
53
|
+
return { store: {}, ok: false };
|
|
54
|
+
}
|
|
55
|
+
function isSurfaceGroupKey(key) {
|
|
56
|
+
return key.includes(":group:") || key.includes(":channel:");
|
|
57
|
+
}
|
|
58
|
+
function isLegacyGroupKey(key) {
|
|
59
|
+
return key.startsWith("group:") || key.includes("@g.us");
|
|
60
|
+
}
|
|
61
|
+
function normalizeSessionKeyForAgent(key, agentId) {
|
|
62
|
+
const raw = key.trim();
|
|
63
|
+
if (!raw)
|
|
64
|
+
return raw;
|
|
65
|
+
if (raw.startsWith("agent:"))
|
|
66
|
+
return raw;
|
|
67
|
+
if (raw.toLowerCase().startsWith("subagent:")) {
|
|
68
|
+
const rest = raw.slice("subagent:".length);
|
|
69
|
+
return `agent:${normalizeAgentId(agentId)}:subagent:${rest}`;
|
|
70
|
+
}
|
|
71
|
+
if (isSurfaceGroupKey(raw)) {
|
|
72
|
+
return `agent:${normalizeAgentId(agentId)}:${raw}`;
|
|
73
|
+
}
|
|
74
|
+
return raw;
|
|
75
|
+
}
|
|
76
|
+
function pickLatestLegacyDirectEntry(store) {
|
|
77
|
+
let best = null;
|
|
78
|
+
let bestUpdated = -1;
|
|
79
|
+
for (const [key, entry] of Object.entries(store)) {
|
|
80
|
+
if (!entry || typeof entry !== "object")
|
|
81
|
+
continue;
|
|
82
|
+
const normalized = key.trim();
|
|
83
|
+
if (!normalized)
|
|
84
|
+
continue;
|
|
85
|
+
if (normalized === "global")
|
|
86
|
+
continue;
|
|
87
|
+
if (normalized.startsWith("agent:"))
|
|
88
|
+
continue;
|
|
89
|
+
if (normalized.toLowerCase().startsWith("subagent:"))
|
|
90
|
+
continue;
|
|
91
|
+
if (isLegacyGroupKey(normalized) || isSurfaceGroupKey(normalized))
|
|
92
|
+
continue;
|
|
93
|
+
const updatedAt = typeof entry.updatedAt === "number" ? entry.updatedAt : 0;
|
|
94
|
+
if (updatedAt > bestUpdated) {
|
|
95
|
+
bestUpdated = updatedAt;
|
|
96
|
+
best = entry;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return best;
|
|
100
|
+
}
|
|
101
|
+
function normalizeSessionEntry(entry) {
|
|
102
|
+
const sessionId = typeof entry.sessionId === "string" ? entry.sessionId : null;
|
|
103
|
+
if (!sessionId)
|
|
104
|
+
return null;
|
|
105
|
+
const updatedAt = typeof entry.updatedAt === "number" && Number.isFinite(entry.updatedAt)
|
|
106
|
+
? entry.updatedAt
|
|
107
|
+
: Date.now();
|
|
108
|
+
return { ...entry, sessionId, updatedAt };
|
|
109
|
+
}
|
|
110
|
+
function emptyDirOrMissing(dir) {
|
|
111
|
+
if (!existsDir(dir))
|
|
112
|
+
return true;
|
|
113
|
+
return safeReadDir(dir).length === 0;
|
|
114
|
+
}
|
|
115
|
+
function removeDirIfEmpty(dir) {
|
|
116
|
+
if (!existsDir(dir))
|
|
117
|
+
return;
|
|
118
|
+
if (!emptyDirOrMissing(dir))
|
|
119
|
+
return;
|
|
120
|
+
try {
|
|
121
|
+
fs.rmdirSync(dir);
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
// ignore
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
export async function detectLegacyStateMigrations(params) {
|
|
128
|
+
const env = params.env ?? process.env;
|
|
129
|
+
const homedir = params.homedir ?? os.homedir;
|
|
130
|
+
const stateDir = resolveStateDir(env, homedir);
|
|
131
|
+
const oauthDir = resolveOAuthDir(env, stateDir);
|
|
132
|
+
const targetAgentId = normalizeAgentId(params.cfg.routing?.defaultAgentId ?? DEFAULT_AGENT_ID);
|
|
133
|
+
const rawMainKey = params.cfg.session?.mainKey;
|
|
134
|
+
const targetMainKey = typeof rawMainKey === "string" && rawMainKey.trim().length > 0
|
|
135
|
+
? rawMainKey.trim()
|
|
136
|
+
: DEFAULT_MAIN_KEY;
|
|
137
|
+
const sessionsLegacyDir = path.join(stateDir, "sessions");
|
|
138
|
+
const sessionsLegacyStorePath = path.join(sessionsLegacyDir, "sessions.json");
|
|
139
|
+
const sessionsTargetDir = path.join(stateDir, "agents", targetAgentId, "sessions");
|
|
140
|
+
const sessionsTargetStorePath = path.join(sessionsTargetDir, "sessions.json");
|
|
141
|
+
const legacySessionEntries = safeReadDir(sessionsLegacyDir);
|
|
142
|
+
const hasLegacySessions = fileExists(sessionsLegacyStorePath) ||
|
|
143
|
+
legacySessionEntries.some((e) => e.isFile() && e.name.endsWith(".jsonl"));
|
|
144
|
+
const legacyAgentDir = path.join(stateDir, "agent");
|
|
145
|
+
const targetAgentDir = path.join(stateDir, "agents", targetAgentId, "agent");
|
|
146
|
+
const hasLegacyAgentDir = existsDir(legacyAgentDir);
|
|
147
|
+
const targetWhatsAppAuthDir = path.join(oauthDir, "whatsapp", DEFAULT_ACCOUNT_ID);
|
|
148
|
+
const hasLegacyWhatsAppAuth = fileExists(path.join(oauthDir, "creds.json")) &&
|
|
149
|
+
!fileExists(path.join(targetWhatsAppAuthDir, "creds.json"));
|
|
150
|
+
const preview = [];
|
|
151
|
+
if (hasLegacySessions) {
|
|
152
|
+
preview.push(`- Sessions: ${sessionsLegacyDir} → ${sessionsTargetDir}`);
|
|
153
|
+
}
|
|
154
|
+
if (hasLegacyAgentDir) {
|
|
155
|
+
preview.push(`- Agent dir: ${legacyAgentDir} → ${targetAgentDir}`);
|
|
156
|
+
}
|
|
157
|
+
if (hasLegacyWhatsAppAuth) {
|
|
158
|
+
preview.push(`- WhatsApp auth: ${oauthDir} → ${targetWhatsAppAuthDir} (keep oauth.json)`);
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
targetAgentId,
|
|
162
|
+
targetMainKey,
|
|
163
|
+
stateDir,
|
|
164
|
+
oauthDir,
|
|
165
|
+
sessions: {
|
|
166
|
+
legacyDir: sessionsLegacyDir,
|
|
167
|
+
legacyStorePath: sessionsLegacyStorePath,
|
|
168
|
+
targetDir: sessionsTargetDir,
|
|
169
|
+
targetStorePath: sessionsTargetStorePath,
|
|
170
|
+
hasLegacy: hasLegacySessions,
|
|
171
|
+
},
|
|
172
|
+
agentDir: {
|
|
173
|
+
legacyDir: legacyAgentDir,
|
|
174
|
+
targetDir: targetAgentDir,
|
|
175
|
+
hasLegacy: hasLegacyAgentDir,
|
|
176
|
+
},
|
|
177
|
+
whatsappAuth: {
|
|
178
|
+
legacyDir: oauthDir,
|
|
179
|
+
targetDir: targetWhatsAppAuthDir,
|
|
180
|
+
hasLegacy: hasLegacyWhatsAppAuth,
|
|
181
|
+
},
|
|
182
|
+
preview,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
async function migrateLegacySessions(detected, now) {
|
|
186
|
+
const changes = [];
|
|
187
|
+
const warnings = [];
|
|
188
|
+
if (!detected.sessions.hasLegacy)
|
|
189
|
+
return { changes, warnings };
|
|
190
|
+
ensureDir(detected.sessions.targetDir);
|
|
191
|
+
const legacyParsed = fileExists(detected.sessions.legacyStorePath)
|
|
192
|
+
? readSessionStoreJson5(detected.sessions.legacyStorePath)
|
|
193
|
+
: { store: {}, ok: true };
|
|
194
|
+
const targetParsed = fileExists(detected.sessions.targetStorePath)
|
|
195
|
+
? readSessionStoreJson5(detected.sessions.targetStorePath)
|
|
196
|
+
: { store: {}, ok: true };
|
|
197
|
+
const legacyStore = legacyParsed.store;
|
|
198
|
+
const targetStore = targetParsed.store;
|
|
199
|
+
const normalizedLegacy = {};
|
|
200
|
+
for (const [key, entry] of Object.entries(legacyStore)) {
|
|
201
|
+
const nextKey = normalizeSessionKeyForAgent(key, detected.targetAgentId);
|
|
202
|
+
if (!nextKey)
|
|
203
|
+
continue;
|
|
204
|
+
if (!normalizedLegacy[nextKey])
|
|
205
|
+
normalizedLegacy[nextKey] = entry;
|
|
206
|
+
}
|
|
207
|
+
const merged = {
|
|
208
|
+
...normalizedLegacy,
|
|
209
|
+
...targetStore,
|
|
210
|
+
};
|
|
211
|
+
const mainKey = buildAgentMainSessionKey({
|
|
212
|
+
agentId: detected.targetAgentId,
|
|
213
|
+
mainKey: detected.targetMainKey,
|
|
214
|
+
});
|
|
215
|
+
if (!merged[mainKey]) {
|
|
216
|
+
const latest = pickLatestLegacyDirectEntry(legacyStore);
|
|
217
|
+
if (latest?.sessionId) {
|
|
218
|
+
merged[mainKey] = latest;
|
|
219
|
+
changes.push(`Migrated latest direct-chat session → ${mainKey}`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (!legacyParsed.ok) {
|
|
223
|
+
warnings.push(`Legacy sessions store unreadable; left in place at ${detected.sessions.legacyStorePath}`);
|
|
224
|
+
}
|
|
225
|
+
if (legacyParsed.ok &&
|
|
226
|
+
(Object.keys(legacyStore).length > 0 || Object.keys(targetStore).length > 0)) {
|
|
227
|
+
const normalized = {};
|
|
228
|
+
for (const [key, entry] of Object.entries(merged)) {
|
|
229
|
+
const normalizedEntry = normalizeSessionEntry(entry);
|
|
230
|
+
if (!normalizedEntry)
|
|
231
|
+
continue;
|
|
232
|
+
normalized[key] = normalizedEntry;
|
|
233
|
+
}
|
|
234
|
+
await saveSessionStore(detected.sessions.targetStorePath, normalized);
|
|
235
|
+
changes.push(`Merged sessions store → ${detected.sessions.targetStorePath}`);
|
|
236
|
+
}
|
|
237
|
+
const entries = safeReadDir(detected.sessions.legacyDir);
|
|
238
|
+
for (const entry of entries) {
|
|
239
|
+
if (!entry.isFile())
|
|
240
|
+
continue;
|
|
241
|
+
if (entry.name === "sessions.json")
|
|
242
|
+
continue;
|
|
243
|
+
const from = path.join(detected.sessions.legacyDir, entry.name);
|
|
244
|
+
const to = path.join(detected.sessions.targetDir, entry.name);
|
|
245
|
+
if (fileExists(to))
|
|
246
|
+
continue;
|
|
247
|
+
try {
|
|
248
|
+
fs.renameSync(from, to);
|
|
249
|
+
changes.push(`Moved ${entry.name} → agents/${detected.targetAgentId}/sessions`);
|
|
250
|
+
}
|
|
251
|
+
catch (err) {
|
|
252
|
+
warnings.push(`Failed moving ${from}: ${String(err)}`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (legacyParsed.ok) {
|
|
256
|
+
try {
|
|
257
|
+
if (fileExists(detected.sessions.legacyStorePath)) {
|
|
258
|
+
fs.rmSync(detected.sessions.legacyStorePath, { force: true });
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
catch {
|
|
262
|
+
// ignore
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
removeDirIfEmpty(detected.sessions.legacyDir);
|
|
266
|
+
const legacyLeft = safeReadDir(detected.sessions.legacyDir).filter((e) => e.isFile());
|
|
267
|
+
if (legacyLeft.length > 0) {
|
|
268
|
+
const backupDir = `${detected.sessions.legacyDir}.legacy-${now()}`;
|
|
269
|
+
try {
|
|
270
|
+
fs.renameSync(detected.sessions.legacyDir, backupDir);
|
|
271
|
+
warnings.push(`Left legacy sessions at ${backupDir}`);
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
// ignore
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return { changes, warnings };
|
|
278
|
+
}
|
|
279
|
+
async function migrateLegacyAgentDir(detected, now) {
|
|
280
|
+
const changes = [];
|
|
281
|
+
const warnings = [];
|
|
282
|
+
if (!detected.agentDir.hasLegacy)
|
|
283
|
+
return { changes, warnings };
|
|
284
|
+
ensureDir(detected.agentDir.targetDir);
|
|
285
|
+
const entries = safeReadDir(detected.agentDir.legacyDir);
|
|
286
|
+
for (const entry of entries) {
|
|
287
|
+
const from = path.join(detected.agentDir.legacyDir, entry.name);
|
|
288
|
+
const to = path.join(detected.agentDir.targetDir, entry.name);
|
|
289
|
+
if (fs.existsSync(to))
|
|
290
|
+
continue;
|
|
291
|
+
try {
|
|
292
|
+
fs.renameSync(from, to);
|
|
293
|
+
changes.push(`Moved agent file ${entry.name} → agents/${detected.targetAgentId}/agent`);
|
|
294
|
+
}
|
|
295
|
+
catch (err) {
|
|
296
|
+
warnings.push(`Failed moving ${from}: ${String(err)}`);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
removeDirIfEmpty(detected.agentDir.legacyDir);
|
|
300
|
+
if (!emptyDirOrMissing(detected.agentDir.legacyDir)) {
|
|
301
|
+
const backupDir = path.join(detected.stateDir, "agents", detected.targetAgentId, `agent.legacy-${now()}`);
|
|
302
|
+
try {
|
|
303
|
+
fs.renameSync(detected.agentDir.legacyDir, backupDir);
|
|
304
|
+
warnings.push(`Left legacy agent dir at ${backupDir}`);
|
|
305
|
+
}
|
|
306
|
+
catch (err) {
|
|
307
|
+
warnings.push(`Failed relocating legacy agent dir: ${String(err)}`);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return { changes, warnings };
|
|
311
|
+
}
|
|
312
|
+
async function migrateLegacyWhatsAppAuth(detected) {
|
|
313
|
+
const changes = [];
|
|
314
|
+
const warnings = [];
|
|
315
|
+
if (!detected.whatsappAuth.hasLegacy)
|
|
316
|
+
return { changes, warnings };
|
|
317
|
+
ensureDir(detected.whatsappAuth.targetDir);
|
|
318
|
+
const entries = safeReadDir(detected.whatsappAuth.legacyDir);
|
|
319
|
+
for (const entry of entries) {
|
|
320
|
+
if (!entry.isFile())
|
|
321
|
+
continue;
|
|
322
|
+
if (entry.name === "oauth.json")
|
|
323
|
+
continue;
|
|
324
|
+
if (!isLegacyWhatsAppAuthFile(entry.name))
|
|
325
|
+
continue;
|
|
326
|
+
const from = path.join(detected.whatsappAuth.legacyDir, entry.name);
|
|
327
|
+
const to = path.join(detected.whatsappAuth.targetDir, entry.name);
|
|
328
|
+
if (fileExists(to))
|
|
329
|
+
continue;
|
|
330
|
+
try {
|
|
331
|
+
fs.renameSync(from, to);
|
|
332
|
+
changes.push(`Moved WhatsApp auth ${entry.name} → whatsapp/default`);
|
|
333
|
+
}
|
|
334
|
+
catch (err) {
|
|
335
|
+
warnings.push(`Failed moving ${from}: ${String(err)}`);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return { changes, warnings };
|
|
339
|
+
}
|
|
340
|
+
export async function runLegacyStateMigrations(params) {
|
|
341
|
+
const now = params.now ?? (() => Date.now());
|
|
342
|
+
const detected = params.detected;
|
|
343
|
+
const sessions = await migrateLegacySessions(detected, now);
|
|
344
|
+
const agentDir = await migrateLegacyAgentDir(detected, now);
|
|
345
|
+
const whatsappAuth = await migrateLegacyWhatsAppAuth(detected);
|
|
346
|
+
return {
|
|
347
|
+
changes: [
|
|
348
|
+
...sessions.changes,
|
|
349
|
+
...agentDir.changes,
|
|
350
|
+
...whatsappAuth.changes,
|
|
351
|
+
],
|
|
352
|
+
warnings: [
|
|
353
|
+
...sessions.warnings,
|
|
354
|
+
...agentDir.warnings,
|
|
355
|
+
...whatsappAuth.warnings,
|
|
356
|
+
],
|
|
357
|
+
};
|
|
358
|
+
}
|