clawdbot 2026.1.4-1
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 +120 -0
- package/LICENSE +21 -0
- package/README-header.png +0 -0
- package/README.md +297 -0
- package/dist/agents/agent-paths.js +17 -0
- package/dist/agents/bash-process-registry.js +126 -0
- package/dist/agents/bash-tools.js +837 -0
- package/dist/agents/clawdbot-tools.js +30 -0
- package/dist/agents/clawdis-tools.js +27 -0
- package/dist/agents/context.js +34 -0
- package/dist/agents/defaults.js +6 -0
- package/dist/agents/model-auth.js +112 -0
- package/dist/agents/model-catalog.js +55 -0
- package/dist/agents/model-fallback.js +191 -0
- package/dist/agents/model-scan.js +263 -0
- package/dist/agents/model-selection.js +116 -0
- package/dist/agents/models-config.js +49 -0
- package/dist/agents/pi-embedded-helpers.js +74 -0
- package/dist/agents/pi-embedded-runner.js +407 -0
- package/dist/agents/pi-embedded-subscribe.js +568 -0
- package/dist/agents/pi-embedded-utils.js +20 -0
- package/dist/agents/pi-embedded.js +1 -0
- package/dist/agents/pi-oauth.js +88 -0
- package/dist/agents/pi-tools.js +433 -0
- package/dist/agents/sandbox-paths.js +68 -0
- package/dist/agents/sandbox.js +644 -0
- package/dist/agents/shell-utils.js +53 -0
- package/dist/agents/skills-install.js +244 -0
- package/dist/agents/skills-status.js +157 -0
- package/dist/agents/skills.js +470 -0
- package/dist/agents/steerable-agent-loop.js +338 -0
- package/dist/agents/steerable-provider-transport.js +48 -0
- package/dist/agents/system-prompt.js +104 -0
- package/dist/agents/tool-display.js +162 -0
- package/dist/agents/tool-images.js +138 -0
- package/dist/agents/tools/browser-tool.js +339 -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 +124 -0
- package/dist/agents/tools/discord-actions-guild.js +186 -0
- package/dist/agents/tools/discord-actions-messaging.js +285 -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 +27 -0
- package/dist/agents/tools/image-tool.js +132 -0
- package/dist/agents/tools/nodes-tool.js +413 -0
- package/dist/agents/tools/nodes-utils.js +92 -0
- package/dist/agents/tools/sessions-helpers.js +88 -0
- package/dist/agents/tools/sessions-history-tool.js +53 -0
- package/dist/agents/tools/sessions-list-tool.js +143 -0
- package/dist/agents/tools/sessions-send-helpers.js +100 -0
- package/dist/agents/tools/sessions-send-tool.js +347 -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/usage.js +39 -0
- package/dist/agents/workspace.js +241 -0
- package/dist/auto-reply/chunk.js +76 -0
- package/dist/auto-reply/envelope.js +38 -0
- package/dist/auto-reply/group-activation.js +20 -0
- package/dist/auto-reply/heartbeat.js +57 -0
- package/dist/auto-reply/model.js +14 -0
- package/dist/auto-reply/reply/abort.js +14 -0
- package/dist/auto-reply/reply/agent-runner.js +371 -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 +207 -0
- package/dist/auto-reply/reply/directive-handling.js +361 -0
- package/dist/auto-reply/reply/directives.js +47 -0
- package/dist/auto-reply/reply/followup-runner.js +149 -0
- package/dist/auto-reply/reply/groups.js +91 -0
- package/dist/auto-reply/reply/mentions.js +38 -0
- package/dist/auto-reply/reply/model-selection.js +114 -0
- package/dist/auto-reply/reply/queue.js +399 -0
- package/dist/auto-reply/reply/reply-tags.js +26 -0
- package/dist/auto-reply/reply/session-updates.js +87 -0
- package/dist/auto-reply/reply/session.js +160 -0
- package/dist/auto-reply/reply/typing.js +75 -0
- package/dist/auto-reply/reply.js +535 -0
- package/dist/auto-reply/send-policy.js +28 -0
- package/dist/auto-reply/status.js +158 -0
- package/dist/auto-reply/templating.js +9 -0
- package/dist/auto-reply/thinking.js +49 -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 +105 -0
- package/dist/browser/config.js +140 -0
- package/dist/browser/constants.js +4 -0
- package/dist/browser/profiles-service.js +122 -0
- package/dist/browser/profiles.js +85 -0
- package/dist/browser/pw-ai.js +2 -0
- package/dist/browser/pw-session.js +144 -0
- package/dist/browser/pw-tools-core.js +363 -0
- package/dist/browser/routes/agent.js +535 -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/.bundle.hash +1 -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/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/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 +489 -0
- package/dist/cli/gateway-rpc.js +20 -0
- package/dist/cli/hooks-cli.js +135 -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/parse-duration.js +20 -0
- package/dist/cli/ports.js +97 -0
- package/dist/cli/program.js +406 -0
- package/dist/cli/prompt.js +19 -0
- package/dist/cli/tui-cli.js +35 -0
- package/dist/cli/wait.js +8 -0
- package/dist/commands/agent.js +645 -0
- package/dist/commands/antigravity-oauth.js +327 -0
- package/dist/commands/configure.js +480 -0
- package/dist/commands/doctor.js +484 -0
- package/dist/commands/health.js +108 -0
- package/dist/commands/models/aliases.js +64 -0
- package/dist/commands/models/fallbacks.js +99 -0
- package/dist/commands/models/image-fallbacks.js +99 -0
- package/dist/commands/models/list.js +323 -0
- package/dist/commands/models/scan.js +266 -0
- package/dist/commands/models/set-image.js +23 -0
- package/dist/commands/models/set.js +23 -0
- package/dist/commands/models/shared.js +72 -0
- package/dist/commands/models.js +7 -0
- package/dist/commands/onboard-auth.js +70 -0
- package/dist/commands/onboard-helpers.js +295 -0
- package/dist/commands/onboard-interactive.js +17 -0
- package/dist/commands/onboard-non-interactive.js +202 -0
- package/dist/commands/onboard-providers.js +634 -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 +12 -0
- package/dist/commands/send.js +124 -0
- package/dist/commands/sessions.js +212 -0
- package/dist/commands/setup.js +58 -0
- package/dist/commands/signal-install.js +135 -0
- package/dist/commands/status.js +207 -0
- package/dist/commands/update.js +16 -0
- package/dist/config/config.js +6 -0
- package/dist/config/defaults.js +61 -0
- package/dist/config/io.js +147 -0
- package/dist/config/legacy-migrate.js +13 -0
- package/dist/config/legacy.js +159 -0
- package/dist/config/paths.js +71 -0
- package/dist/config/schema.js +150 -0
- package/dist/config/sessions.js +282 -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 +831 -0
- package/dist/control-ui/assets/index-BFID3yAA.css +1 -0
- package/dist/control-ui/assets/index-CE_axlTS.js +2235 -0
- package/dist/control-ui/assets/index-CE_axlTS.js.map +1 -0
- package/dist/control-ui/index.html +15 -0
- package/dist/cron/isolated-agent.js +499 -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 +276 -0
- package/dist/daemon/legacy.js +63 -0
- package/dist/daemon/program-args.js +76 -0
- package/dist/daemon/schtasks.js +257 -0
- package/dist/daemon/service.js +60 -0
- package/dist/daemon/systemd.js +266 -0
- package/dist/discord/index.js +2 -0
- package/dist/discord/monitor.js +1188 -0
- package/dist/discord/probe.js +54 -0
- package/dist/discord/send.js +577 -0
- package/dist/discord/token.js +8 -0
- package/dist/gateway/auth.js +121 -0
- package/dist/gateway/call.js +94 -0
- package/dist/gateway/chat-attachments.js +41 -0
- package/dist/gateway/client.js +180 -0
- package/dist/gateway/config-reload.js +274 -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 +61 -0
- package/dist/gateway/protocol/schema.js +560 -0
- package/dist/gateway/server-bridge-subscriptions.js +93 -0
- package/dist/gateway/server-bridge.js +1013 -0
- package/dist/gateway/server-browser.js +12 -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 +125 -0
- package/dist/gateway/server-methods/agent.js +250 -0
- package/dist/gateway/server-methods/chat.js +200 -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 +83 -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 +217 -0
- package/dist/gateway/server-methods/send.js +166 -0
- package/dist/gateway/server-methods/sessions.js +305 -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 +58 -0
- package/dist/gateway/server-methods/wizard.js +100 -0
- package/dist/gateway/server-methods.js +53 -0
- package/dist/gateway/server-providers.js +644 -0
- package/dist/gateway/server-shared.js +1 -0
- package/dist/gateway/server-utils.js +35 -0
- package/dist/gateway/server.js +1437 -0
- package/dist/gateway/session-utils.js +216 -0
- package/dist/gateway/ws-log.js +349 -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 +175 -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 +272 -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 +50 -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 +562 -0
- package/dist/infra/canvas-host-url.js +54 -0
- package/dist/infra/env.js +8 -0
- package/dist/infra/errors.js +28 -0
- package/dist/infra/gateway-lock.js +8 -0
- package/dist/infra/heartbeat-events.js +21 -0
- package/dist/infra/heartbeat-runner.js +453 -0
- package/dist/infra/heartbeat-wake.js +61 -0
- package/dist/infra/is-main.js +37 -0
- package/dist/infra/machine-name.js +40 -0
- package/dist/infra/node-pairing.js +211 -0
- package/dist/infra/pam.js +42 -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/restart.js +29 -0
- package/dist/infra/retry.js +16 -0
- package/dist/infra/runtime-guard.js +59 -0
- package/dist/infra/system-events.js +44 -0
- package/dist/infra/system-presence.js +216 -0
- package/dist/infra/tailnet.js +46 -0
- package/dist/infra/tailscale.js +149 -0
- package/dist/infra/voicewake.js +77 -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.js +490 -0
- package/dist/macos/gateway-daemon.js +141 -0
- package/dist/macos/relay.js +46 -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 +115 -0
- package/dist/media/parse.js +81 -0
- package/dist/media/server.js +64 -0
- package/dist/media/store.js +139 -0
- package/dist/process/command-queue.js +97 -0
- package/dist/process/exec.js +75 -0
- package/dist/protocol.schema.json +2918 -0
- package/dist/provider-web.js +8 -0
- package/dist/providers/web/index.js +2 -0
- package/dist/runtime.js +8 -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 +336 -0
- package/dist/signal/probe.js +46 -0
- package/dist/signal/send.js +91 -0
- package/dist/slack/actions.js +97 -0
- package/dist/slack/index.js +5 -0
- package/dist/slack/monitor.js +1029 -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/bot.js +394 -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/probe.js +63 -0
- package/dist/telegram/proxy.js +9 -0
- package/dist/telegram/send.js +138 -0
- package/dist/telegram/token.js +30 -0
- package/dist/telegram/webhook-set.js +12 -0
- package/dist/telegram/webhook.js +56 -0
- package/dist/tui/commands.js +74 -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 +53 -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/layout.js +41 -0
- package/dist/tui/message-list.js +57 -0
- package/dist/tui/theme/theme.js +80 -0
- package/dist/tui/theme.js +25 -0
- package/dist/tui/tui.js +708 -0
- package/dist/utils.js +133 -0
- package/dist/version.js +18 -0
- package/dist/web/active-listener.js +7 -0
- package/dist/web/auto-reply.js +1203 -0
- package/dist/web/inbound.js +481 -0
- package/dist/web/login-qr.js +204 -0
- package/dist/web/login.js +59 -0
- package/dist/web/media.js +148 -0
- package/dist/web/outbound.js +67 -0
- package/dist/web/qr-image.js +97 -0
- package/dist/web/reconnect.js +60 -0
- package/dist/web/reply-heartbeat-wake.js +61 -0
- package/dist/web/session.js +346 -0
- package/dist/wizard/clack-prompter.js +56 -0
- package/dist/wizard/onboarding.js +452 -0
- package/dist/wizard/prompts.js +6 -0
- package/dist/wizard/session.js +203 -0
- package/docs/AGENTS.default.md +116 -0
- package/docs/CNAME +1 -0
- package/docs/RELEASING.md +64 -0
- package/docs/_config.yml +51 -0
- package/docs/_layouts/default.html +145 -0
- package/docs/agent-send.md +21 -0
- package/docs/agent.md +104 -0
- package/docs/android/connect.md +131 -0
- package/docs/architecture.md +89 -0
- package/docs/assets/markdown.css +130 -0
- package/docs/assets/pixel-lobster.svg +60 -0
- package/docs/assets/terminal.css +497 -0
- package/docs/assets/theme.js +55 -0
- package/docs/audio.md +50 -0
- package/docs/background-process.md +74 -0
- package/docs/bash.md +32 -0
- package/docs/bonjour.md +159 -0
- package/docs/browser.md +289 -0
- package/docs/camera.md +152 -0
- package/docs/clawd.md +199 -0
- package/docs/clawdbot-mac.md +104 -0
- package/docs/configuration.md +1177 -0
- package/docs/control-api.md +49 -0
- package/docs/control-ui.md +83 -0
- package/docs/cron.md +374 -0
- package/docs/dashboard.md +17 -0
- package/docs/device-models.md +46 -0
- package/docs/discord.md +293 -0
- package/docs/discovery.md +112 -0
- package/docs/docker.md +251 -0
- package/docs/docs.json +86 -0
- package/docs/doctor.md +47 -0
- package/docs/elevated.md +31 -0
- package/docs/faq.md +640 -0
- package/docs/gateway/pairing.md +109 -0
- package/docs/gateway-lock.md +28 -0
- package/docs/gateway.md +174 -0
- package/docs/gmail-pubsub.md +191 -0
- package/docs/grammy.md +27 -0
- package/docs/group-messages.md +71 -0
- package/docs/groups.md +78 -0
- package/docs/health.md +28 -0
- package/docs/heartbeat.md +64 -0
- package/docs/images.md +52 -0
- package/docs/imessage.md +63 -0
- package/docs/index.md +182 -0
- package/docs/ios/connect.md +177 -0
- package/docs/ios/spec.md +236 -0
- package/docs/location-command.md +95 -0
- package/docs/logging.md +99 -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/models.md +90 -0
- package/docs/nix.md +49 -0
- package/docs/nodes.md +157 -0
- package/docs/onboarding-config-protocol.md +29 -0
- package/docs/onboarding.md +185 -0
- package/docs/presence.md +133 -0
- package/docs/queue.md +78 -0
- package/docs/refactor/browser-control-simplification.md +58 -0
- package/docs/refactor/canvas-a2ui.md +93 -0
- package/docs/refactor/cli-unification.md +64 -0
- package/docs/refactor/gateway-client.md +31 -0
- package/docs/refactor/gateway.md +99 -0
- package/docs/refactor/new-arch.md +171 -0
- package/docs/refactor/tui.md +26 -0
- package/docs/refactor/web-gateway-troubleshooting.md +37 -0
- package/docs/refactor/webagent-session.md +46 -0
- package/docs/remote-gateway-readme.md +148 -0
- package/docs/remote.md +66 -0
- package/docs/research/memory.md +227 -0
- package/docs/rpc.md +35 -0
- package/docs/security.md +168 -0
- package/docs/session-tool.md +119 -0
- package/docs/session.md +84 -0
- package/docs/sessions.md +8 -0
- package/docs/setup.md +118 -0
- package/docs/signal.md +113 -0
- package/docs/skills-config.md +58 -0
- package/docs/skills.md +149 -0
- package/docs/slack.md +158 -0
- package/docs/surface.md +20 -0
- package/docs/tailscale.md +71 -0
- package/docs/talk.md +79 -0
- package/docs/telegram.md +90 -0
- package/docs/templates/AGENTS.md +126 -0
- package/docs/templates/BOOTSTRAP.md +53 -0
- package/docs/templates/IDENTITY.md +17 -0
- package/docs/templates/SOUL.md +41 -0
- package/docs/templates/TOOLS.md +41 -0
- package/docs/templates/USER.md +22 -0
- package/docs/test.md +35 -0
- package/docs/thinking.md +46 -0
- package/docs/tools.md +248 -0
- package/docs/troubleshooting.md +227 -0
- package/docs/tui.md +69 -0
- package/docs/typebox.md +42 -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 +142 -0
- package/docs/wizard.md +158 -0
- package/package.json +186 -0
- package/skills/apple-notes/SKILL.md +50 -0
- package/skills/apple-reminders/SKILL.md +67 -0
- package/skills/bear-notes/SKILL.md +79 -0
- package/skills/bird/SKILL.md +25 -0
- package/skills/blogwatcher/SKILL.md +46 -0
- package/skills/blucli/SKILL.md +27 -0
- package/skills/brave-search/SKILL.md +30 -0
- package/skills/brave-search/scripts/content.mjs +53 -0
- package/skills/brave-search/scripts/search.mjs +79 -0
- package/skills/camsnap/SKILL.md +25 -0
- package/skills/clawdhub/SKILL.md +53 -0
- package/skills/coding-agent/SKILL.md +275 -0
- package/skills/discord/SKILL.md +369 -0
- package/skills/eightctl/SKILL.md +29 -0
- package/skills/food-order/SKILL.md +41 -0
- package/skills/gemini/SKILL.md +23 -0
- package/skills/gifgrep/SKILL.md +47 -0
- package/skills/github/SKILL.md +47 -0
- package/skills/gog/SKILL.md +36 -0
- package/skills/goplaces/SKILL.md +30 -0
- package/skills/imsg/SKILL.md +25 -0
- package/skills/local-places/SERVER_README.md +101 -0
- package/skills/local-places/SKILL.md +91 -0
- package/skills/local-places/pyproject.toml +27 -0
- package/skills/local-places/src/local_places/__init__.py +2 -0
- package/skills/local-places/src/local_places/__pycache__/__init__.cpython-314.pyc +0 -0
- package/skills/local-places/src/local_places/__pycache__/google_places.cpython-314.pyc +0 -0
- package/skills/local-places/src/local_places/__pycache__/main.cpython-314.pyc +0 -0
- package/skills/local-places/src/local_places/__pycache__/schemas.cpython-314.pyc +0 -0
- package/skills/local-places/src/local_places/google_places.py +314 -0
- package/skills/local-places/src/local_places/main.py +65 -0
- package/skills/local-places/src/local_places/schemas.py +107 -0
- package/skills/mcporter/SKILL.md +38 -0
- package/skills/nano-banana-pro/SKILL.md +29 -0
- package/skills/nano-banana-pro/scripts/generate_image.py +167 -0
- package/skills/nano-pdf/SKILL.md +20 -0
- package/skills/notion/SKILL.md +156 -0
- package/skills/obsidian/SKILL.md +55 -0
- package/skills/openai-image-gen/SKILL.md +31 -0
- package/skills/openai-image-gen/scripts/gen.py +173 -0
- package/skills/openai-whisper/SKILL.md +19 -0
- package/skills/openai-whisper-api/SKILL.md +43 -0
- package/skills/openai-whisper-api/scripts/transcribe.sh +85 -0
- package/skills/openhue/SKILL.md +30 -0
- package/skills/oracle/SKILL.md +105 -0
- package/skills/ordercli/SKILL.md +47 -0
- package/skills/peekaboo/SKILL.md +153 -0
- package/skills/qmd/SKILL.md +26 -0
- package/skills/sag/SKILL.md +62 -0
- package/skills/slack/SKILL.md +143 -0
- package/skills/songsee/SKILL.md +29 -0
- package/skills/sonoscli/SKILL.md +26 -0
- package/skills/spotify-player/SKILL.md +34 -0
- package/skills/summarize/SKILL.md +49 -0
- package/skills/things-mac/SKILL.md +61 -0
- package/skills/tmux/SKILL.md +121 -0
- package/skills/tmux/scripts/find-sessions.sh +112 -0
- package/skills/tmux/scripts/wait-for-text.sh +83 -0
- package/skills/trello/SKILL.md +84 -0
- package/skills/video-frames/SKILL.md +29 -0
- package/skills/video-frames/scripts/frame.sh +81 -0
- package/skills/wacli/SKILL.md +42 -0
- package/skills/weather/SKILL.md +49 -0
|
@@ -0,0 +1,837 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { existsSync, statSync } from "node:fs";
|
|
4
|
+
import fs from "node:fs/promises";
|
|
5
|
+
import { homedir } from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { Type } from "@sinclair/typebox";
|
|
8
|
+
import { logInfo } from "../logger.js";
|
|
9
|
+
import { addSession, appendOutput, deleteSession, drainSession, getFinishedSession, getSession, listFinishedSessions, listRunningSessions, markBackgrounded, markExited, setJobTtlMs, } from "./bash-process-registry.js";
|
|
10
|
+
import { assertSandboxPath } from "./sandbox-paths.js";
|
|
11
|
+
import { getShellConfig, killProcessTree, sanitizeBinaryOutput, } from "./shell-utils.js";
|
|
12
|
+
const CHUNK_LIMIT = 8 * 1024;
|
|
13
|
+
const DEFAULT_MAX_OUTPUT = clampNumber(readEnvInt("PI_BASH_MAX_OUTPUT_CHARS"), 30_000, 1_000, 150_000);
|
|
14
|
+
const DEFAULT_PATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";
|
|
15
|
+
const stringEnum = (values, options) => Type.Union(values.map((value) => Type.Literal(value)), options);
|
|
16
|
+
const bashSchema = Type.Object({
|
|
17
|
+
command: Type.String({ description: "Bash command to execute" }),
|
|
18
|
+
workdir: Type.Optional(Type.String({ description: "Working directory (defaults to cwd)" })),
|
|
19
|
+
env: Type.Optional(Type.Record(Type.String(), Type.String())),
|
|
20
|
+
yieldMs: Type.Optional(Type.Number({
|
|
21
|
+
description: "Milliseconds to wait before backgrounding (default 10000)",
|
|
22
|
+
})),
|
|
23
|
+
background: Type.Optional(Type.Boolean({ description: "Run in background immediately" })),
|
|
24
|
+
timeout: Type.Optional(Type.Number({
|
|
25
|
+
description: "Timeout in seconds (optional, kills process on expiry)",
|
|
26
|
+
})),
|
|
27
|
+
elevated: Type.Optional(Type.Boolean({
|
|
28
|
+
description: "Run on the host with elevated permissions (if allowed)",
|
|
29
|
+
})),
|
|
30
|
+
});
|
|
31
|
+
export function createBashTool(defaults) {
|
|
32
|
+
const defaultBackgroundMs = clampNumber(defaults?.backgroundMs ?? readEnvInt("PI_BASH_YIELD_MS"), 10_000, 10, 120_000);
|
|
33
|
+
const defaultTimeoutSec = typeof defaults?.timeoutSec === "number" && defaults.timeoutSec > 0
|
|
34
|
+
? defaults.timeoutSec
|
|
35
|
+
: 1800;
|
|
36
|
+
return {
|
|
37
|
+
name: "bash",
|
|
38
|
+
label: "bash",
|
|
39
|
+
description: "Execute bash with background continuation. Use yieldMs/background to continue later via process tool. For real TTY mode, use the tmux skill.",
|
|
40
|
+
parameters: bashSchema,
|
|
41
|
+
execute: async (_toolCallId, args, signal, onUpdate) => {
|
|
42
|
+
const params = args;
|
|
43
|
+
if (!params.command) {
|
|
44
|
+
throw new Error("Provide a command to start.");
|
|
45
|
+
}
|
|
46
|
+
const yieldWindow = params.background
|
|
47
|
+
? 0
|
|
48
|
+
: clampNumber(params.yieldMs ?? defaultBackgroundMs, defaultBackgroundMs, 10, 120_000);
|
|
49
|
+
const maxOutput = DEFAULT_MAX_OUTPUT;
|
|
50
|
+
const startedAt = Date.now();
|
|
51
|
+
const sessionId = randomUUID();
|
|
52
|
+
const warnings = [];
|
|
53
|
+
const elevatedDefaults = defaults?.elevated;
|
|
54
|
+
const elevatedRequested = typeof params.elevated === "boolean"
|
|
55
|
+
? params.elevated
|
|
56
|
+
: elevatedDefaults?.defaultLevel === "on";
|
|
57
|
+
if (elevatedRequested) {
|
|
58
|
+
if (!elevatedDefaults?.enabled || !elevatedDefaults.allowed) {
|
|
59
|
+
throw new Error("elevated is not available right now.");
|
|
60
|
+
}
|
|
61
|
+
logInfo(`bash: elevated command (${sessionId.slice(0, 8)}) ${truncateMiddle(params.command, 120)}`);
|
|
62
|
+
}
|
|
63
|
+
const sandbox = elevatedRequested ? undefined : defaults?.sandbox;
|
|
64
|
+
const rawWorkdir = params.workdir?.trim() || process.cwd();
|
|
65
|
+
let workdir = rawWorkdir;
|
|
66
|
+
let containerWorkdir = sandbox?.containerWorkdir;
|
|
67
|
+
if (sandbox) {
|
|
68
|
+
const resolved = await resolveSandboxWorkdir({
|
|
69
|
+
workdir: rawWorkdir,
|
|
70
|
+
sandbox,
|
|
71
|
+
warnings,
|
|
72
|
+
});
|
|
73
|
+
workdir = resolved.hostWorkdir;
|
|
74
|
+
containerWorkdir = resolved.containerWorkdir;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
workdir = resolveWorkdir(rawWorkdir, warnings);
|
|
78
|
+
}
|
|
79
|
+
const { shell, args: shellArgs } = getShellConfig();
|
|
80
|
+
const baseEnv = coerceEnv(process.env);
|
|
81
|
+
const mergedEnv = params.env ? { ...baseEnv, ...params.env } : baseEnv;
|
|
82
|
+
const env = sandbox
|
|
83
|
+
? buildSandboxEnv({
|
|
84
|
+
paramsEnv: params.env,
|
|
85
|
+
sandboxEnv: sandbox.env,
|
|
86
|
+
containerWorkdir: containerWorkdir ?? sandbox.containerWorkdir,
|
|
87
|
+
})
|
|
88
|
+
: mergedEnv;
|
|
89
|
+
const child = sandbox
|
|
90
|
+
? spawn("docker", buildDockerExecArgs({
|
|
91
|
+
containerName: sandbox.containerName,
|
|
92
|
+
command: params.command,
|
|
93
|
+
workdir: containerWorkdir ?? sandbox.containerWorkdir,
|
|
94
|
+
env,
|
|
95
|
+
tty: false,
|
|
96
|
+
}), {
|
|
97
|
+
cwd: workdir,
|
|
98
|
+
env: process.env,
|
|
99
|
+
detached: true,
|
|
100
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
101
|
+
})
|
|
102
|
+
: spawn(shell, [...shellArgs, params.command], {
|
|
103
|
+
cwd: workdir,
|
|
104
|
+
env,
|
|
105
|
+
detached: true,
|
|
106
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
107
|
+
});
|
|
108
|
+
const session = {
|
|
109
|
+
id: sessionId,
|
|
110
|
+
command: params.command,
|
|
111
|
+
child,
|
|
112
|
+
pid: child?.pid,
|
|
113
|
+
startedAt,
|
|
114
|
+
cwd: workdir,
|
|
115
|
+
maxOutputChars: maxOutput,
|
|
116
|
+
totalOutputChars: 0,
|
|
117
|
+
pendingStdout: [],
|
|
118
|
+
pendingStderr: [],
|
|
119
|
+
aggregated: "",
|
|
120
|
+
tail: "",
|
|
121
|
+
exited: false,
|
|
122
|
+
exitCode: undefined,
|
|
123
|
+
exitSignal: undefined,
|
|
124
|
+
truncated: false,
|
|
125
|
+
backgrounded: false,
|
|
126
|
+
};
|
|
127
|
+
addSession(session);
|
|
128
|
+
let settled = false;
|
|
129
|
+
let yielded = false;
|
|
130
|
+
let yieldTimer = null;
|
|
131
|
+
let timeoutTimer = null;
|
|
132
|
+
let timedOut = false;
|
|
133
|
+
const settle = (fn) => {
|
|
134
|
+
if (settled)
|
|
135
|
+
return;
|
|
136
|
+
settled = true;
|
|
137
|
+
fn();
|
|
138
|
+
};
|
|
139
|
+
const onAbort = () => {
|
|
140
|
+
killSession(session);
|
|
141
|
+
};
|
|
142
|
+
if (signal?.aborted)
|
|
143
|
+
onAbort();
|
|
144
|
+
else if (signal) {
|
|
145
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
146
|
+
}
|
|
147
|
+
const effectiveTimeout = typeof params.timeout === "number" ? params.timeout : defaultTimeoutSec;
|
|
148
|
+
if (effectiveTimeout > 0) {
|
|
149
|
+
timeoutTimer = setTimeout(() => {
|
|
150
|
+
timedOut = true;
|
|
151
|
+
onAbort();
|
|
152
|
+
}, effectiveTimeout * 1000);
|
|
153
|
+
}
|
|
154
|
+
const emitUpdate = () => {
|
|
155
|
+
if (!onUpdate)
|
|
156
|
+
return;
|
|
157
|
+
const tailText = session.tail || session.aggregated;
|
|
158
|
+
const warningText = warnings.length ? `${warnings.join("\n")}\n\n` : "";
|
|
159
|
+
onUpdate({
|
|
160
|
+
content: [{ type: "text", text: warningText + (tailText || "") }],
|
|
161
|
+
details: {
|
|
162
|
+
status: "running",
|
|
163
|
+
sessionId,
|
|
164
|
+
pid: session.pid ?? undefined,
|
|
165
|
+
startedAt,
|
|
166
|
+
tail: session.tail,
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
child.stdout.on("data", (data) => {
|
|
171
|
+
const str = sanitizeBinaryOutput(data.toString());
|
|
172
|
+
for (const chunk of chunkString(str)) {
|
|
173
|
+
appendOutput(session, "stdout", chunk);
|
|
174
|
+
emitUpdate();
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
child.stderr.on("data", (data) => {
|
|
178
|
+
const str = sanitizeBinaryOutput(data.toString());
|
|
179
|
+
for (const chunk of chunkString(str)) {
|
|
180
|
+
appendOutput(session, "stderr", chunk);
|
|
181
|
+
emitUpdate();
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
return new Promise((resolve, reject) => {
|
|
185
|
+
const resolveRunning = () => {
|
|
186
|
+
settle(() => resolve({
|
|
187
|
+
content: [
|
|
188
|
+
{
|
|
189
|
+
type: "text",
|
|
190
|
+
text: `${warnings.length ? `${warnings.join("\n")}\n\n` : ""}` +
|
|
191
|
+
`Command still running (session ${sessionId}, pid ${session.pid ?? "n/a"}). ` +
|
|
192
|
+
"Use process (list/poll/log/write/kill/clear/remove) for follow-up.",
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
details: {
|
|
196
|
+
status: "running",
|
|
197
|
+
sessionId,
|
|
198
|
+
pid: session.pid ?? undefined,
|
|
199
|
+
startedAt,
|
|
200
|
+
tail: session.tail,
|
|
201
|
+
},
|
|
202
|
+
}));
|
|
203
|
+
};
|
|
204
|
+
const onYieldNow = () => {
|
|
205
|
+
if (yieldTimer)
|
|
206
|
+
clearTimeout(yieldTimer);
|
|
207
|
+
if (settled)
|
|
208
|
+
return;
|
|
209
|
+
yielded = true;
|
|
210
|
+
markBackgrounded(session);
|
|
211
|
+
resolveRunning();
|
|
212
|
+
};
|
|
213
|
+
if (yieldWindow === 0) {
|
|
214
|
+
onYieldNow();
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
yieldTimer = setTimeout(() => {
|
|
218
|
+
if (settled)
|
|
219
|
+
return;
|
|
220
|
+
yielded = true;
|
|
221
|
+
markBackgrounded(session);
|
|
222
|
+
resolveRunning();
|
|
223
|
+
}, yieldWindow);
|
|
224
|
+
}
|
|
225
|
+
const handleExit = (code, exitSignal) => {
|
|
226
|
+
if (yieldTimer)
|
|
227
|
+
clearTimeout(yieldTimer);
|
|
228
|
+
if (timeoutTimer)
|
|
229
|
+
clearTimeout(timeoutTimer);
|
|
230
|
+
const durationMs = Date.now() - startedAt;
|
|
231
|
+
const wasSignal = exitSignal != null;
|
|
232
|
+
const isSuccess = code === 0 && !wasSignal && !signal?.aborted && !timedOut;
|
|
233
|
+
const status = isSuccess
|
|
234
|
+
? "completed"
|
|
235
|
+
: "failed";
|
|
236
|
+
markExited(session, code, exitSignal, status);
|
|
237
|
+
if (yielded || session.backgrounded)
|
|
238
|
+
return;
|
|
239
|
+
const aggregated = session.aggregated.trim();
|
|
240
|
+
if (!isSuccess) {
|
|
241
|
+
const reason = timedOut
|
|
242
|
+
? `Command timed out after ${effectiveTimeout} seconds`
|
|
243
|
+
: wasSignal && exitSignal
|
|
244
|
+
? `Command aborted by signal ${exitSignal}`
|
|
245
|
+
: code === null
|
|
246
|
+
? "Command aborted before exit code was captured"
|
|
247
|
+
: `Command exited with code ${code}`;
|
|
248
|
+
const message = aggregated
|
|
249
|
+
? `${aggregated}\n\n${reason}`
|
|
250
|
+
: reason;
|
|
251
|
+
settle(() => reject(new Error(message)));
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
settle(() => resolve({
|
|
255
|
+
content: [
|
|
256
|
+
{
|
|
257
|
+
type: "text",
|
|
258
|
+
text: `${warnings.length ? `${warnings.join("\n")}\n\n` : ""}` +
|
|
259
|
+
(aggregated || "(no output)"),
|
|
260
|
+
},
|
|
261
|
+
],
|
|
262
|
+
details: {
|
|
263
|
+
status: "completed",
|
|
264
|
+
exitCode: code ?? 0,
|
|
265
|
+
durationMs,
|
|
266
|
+
aggregated,
|
|
267
|
+
},
|
|
268
|
+
}));
|
|
269
|
+
};
|
|
270
|
+
child.once("exit", (code, exitSignal) => {
|
|
271
|
+
handleExit(code, exitSignal);
|
|
272
|
+
});
|
|
273
|
+
child.once("error", (err) => {
|
|
274
|
+
if (yieldTimer)
|
|
275
|
+
clearTimeout(yieldTimer);
|
|
276
|
+
if (timeoutTimer)
|
|
277
|
+
clearTimeout(timeoutTimer);
|
|
278
|
+
markExited(session, null, null, "failed");
|
|
279
|
+
settle(() => reject(err));
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
},
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
export const bashTool = createBashTool();
|
|
286
|
+
const processSchema = Type.Object({
|
|
287
|
+
action: stringEnum(["list", "poll", "log", "write", "kill", "clear", "remove"], {
|
|
288
|
+
description: "Process action",
|
|
289
|
+
}),
|
|
290
|
+
sessionId: Type.Optional(Type.String({ description: "Session id for actions other than list" })),
|
|
291
|
+
data: Type.Optional(Type.String({ description: "Data to write for write" })),
|
|
292
|
+
eof: Type.Optional(Type.Boolean({ description: "Close stdin after write" })),
|
|
293
|
+
offset: Type.Optional(Type.Number({ description: "Log offset" })),
|
|
294
|
+
limit: Type.Optional(Type.Number({ description: "Log length" })),
|
|
295
|
+
});
|
|
296
|
+
export function createProcessTool(defaults) {
|
|
297
|
+
if (defaults?.cleanupMs !== undefined) {
|
|
298
|
+
setJobTtlMs(defaults.cleanupMs);
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
name: "process",
|
|
302
|
+
label: "process",
|
|
303
|
+
description: "Manage running bash sessions: list, poll, log, write, kill.",
|
|
304
|
+
parameters: processSchema,
|
|
305
|
+
execute: async (_toolCallId, args) => {
|
|
306
|
+
const params = args;
|
|
307
|
+
if (params.action === "list") {
|
|
308
|
+
const running = listRunningSessions().map((s) => ({
|
|
309
|
+
sessionId: s.id,
|
|
310
|
+
status: "running",
|
|
311
|
+
pid: s.pid ?? undefined,
|
|
312
|
+
startedAt: s.startedAt,
|
|
313
|
+
runtimeMs: Date.now() - s.startedAt,
|
|
314
|
+
cwd: s.cwd,
|
|
315
|
+
command: s.command,
|
|
316
|
+
name: deriveSessionName(s.command),
|
|
317
|
+
tail: s.tail,
|
|
318
|
+
truncated: s.truncated,
|
|
319
|
+
}));
|
|
320
|
+
const finished = listFinishedSessions().map((s) => ({
|
|
321
|
+
sessionId: s.id,
|
|
322
|
+
status: s.status,
|
|
323
|
+
startedAt: s.startedAt,
|
|
324
|
+
endedAt: s.endedAt,
|
|
325
|
+
runtimeMs: s.endedAt - s.startedAt,
|
|
326
|
+
cwd: s.cwd,
|
|
327
|
+
command: s.command,
|
|
328
|
+
name: deriveSessionName(s.command),
|
|
329
|
+
tail: s.tail,
|
|
330
|
+
truncated: s.truncated,
|
|
331
|
+
exitCode: s.exitCode ?? undefined,
|
|
332
|
+
exitSignal: s.exitSignal ?? undefined,
|
|
333
|
+
}));
|
|
334
|
+
const lines = [...running, ...finished]
|
|
335
|
+
.sort((a, b) => b.startedAt - a.startedAt)
|
|
336
|
+
.map((s) => {
|
|
337
|
+
const label = s.name
|
|
338
|
+
? truncateMiddle(s.name, 80)
|
|
339
|
+
: truncateMiddle(s.command, 120);
|
|
340
|
+
return `${s.sessionId.slice(0, 8)} ${pad(s.status, 9)} ${formatDuration(s.runtimeMs)} :: ${label}`;
|
|
341
|
+
});
|
|
342
|
+
return {
|
|
343
|
+
content: [
|
|
344
|
+
{
|
|
345
|
+
type: "text",
|
|
346
|
+
text: lines.join("\n") || "No running or recent sessions.",
|
|
347
|
+
},
|
|
348
|
+
],
|
|
349
|
+
details: { status: "completed", sessions: [...running, ...finished] },
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
if (!params.sessionId) {
|
|
353
|
+
return {
|
|
354
|
+
content: [
|
|
355
|
+
{ type: "text", text: "sessionId is required for this action." },
|
|
356
|
+
],
|
|
357
|
+
details: { status: "failed" },
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
const session = getSession(params.sessionId);
|
|
361
|
+
const finished = getFinishedSession(params.sessionId);
|
|
362
|
+
switch (params.action) {
|
|
363
|
+
case "poll": {
|
|
364
|
+
if (!session) {
|
|
365
|
+
if (finished) {
|
|
366
|
+
return {
|
|
367
|
+
content: [
|
|
368
|
+
{
|
|
369
|
+
type: "text",
|
|
370
|
+
text: (finished.tail ||
|
|
371
|
+
`(no output recorded${finished.truncated ? " — truncated to cap" : ""})`) +
|
|
372
|
+
`\n\nProcess exited with ${finished.exitSignal
|
|
373
|
+
? `signal ${finished.exitSignal}`
|
|
374
|
+
: `code ${finished.exitCode ?? 0}`}.`,
|
|
375
|
+
},
|
|
376
|
+
],
|
|
377
|
+
details: {
|
|
378
|
+
status: finished.status === "completed" ? "completed" : "failed",
|
|
379
|
+
sessionId: params.sessionId,
|
|
380
|
+
exitCode: finished.exitCode ?? undefined,
|
|
381
|
+
aggregated: finished.aggregated,
|
|
382
|
+
name: deriveSessionName(finished.command),
|
|
383
|
+
},
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
return {
|
|
387
|
+
content: [
|
|
388
|
+
{
|
|
389
|
+
type: "text",
|
|
390
|
+
text: `No session found for ${params.sessionId}`,
|
|
391
|
+
},
|
|
392
|
+
],
|
|
393
|
+
details: { status: "failed" },
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
if (!session.backgrounded) {
|
|
397
|
+
return {
|
|
398
|
+
content: [
|
|
399
|
+
{
|
|
400
|
+
type: "text",
|
|
401
|
+
text: `Session ${params.sessionId} is not backgrounded.`,
|
|
402
|
+
},
|
|
403
|
+
],
|
|
404
|
+
details: { status: "failed" },
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
const { stdout, stderr } = drainSession(session);
|
|
408
|
+
const exited = session.exited;
|
|
409
|
+
const exitCode = session.exitCode ?? 0;
|
|
410
|
+
const exitSignal = session.exitSignal ?? undefined;
|
|
411
|
+
if (exited) {
|
|
412
|
+
const status = exitCode === 0 && exitSignal == null ? "completed" : "failed";
|
|
413
|
+
markExited(session, session.exitCode ?? null, session.exitSignal ?? null, status);
|
|
414
|
+
}
|
|
415
|
+
const status = exited
|
|
416
|
+
? exitCode === 0 && exitSignal == null
|
|
417
|
+
? "completed"
|
|
418
|
+
: "failed"
|
|
419
|
+
: "running";
|
|
420
|
+
const output = [stdout.trimEnd(), stderr.trimEnd()]
|
|
421
|
+
.filter(Boolean)
|
|
422
|
+
.join("\n")
|
|
423
|
+
.trim();
|
|
424
|
+
return {
|
|
425
|
+
content: [
|
|
426
|
+
{
|
|
427
|
+
type: "text",
|
|
428
|
+
text: (output || "(no new output)") +
|
|
429
|
+
(exited
|
|
430
|
+
? `\n\nProcess exited with ${exitSignal ? `signal ${exitSignal}` : `code ${exitCode}`}.`
|
|
431
|
+
: "\n\nProcess still running."),
|
|
432
|
+
},
|
|
433
|
+
],
|
|
434
|
+
details: {
|
|
435
|
+
status,
|
|
436
|
+
sessionId: params.sessionId,
|
|
437
|
+
exitCode: exited ? exitCode : undefined,
|
|
438
|
+
aggregated: session.aggregated,
|
|
439
|
+
name: deriveSessionName(session.command),
|
|
440
|
+
},
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
case "log": {
|
|
444
|
+
if (session) {
|
|
445
|
+
if (!session.backgrounded) {
|
|
446
|
+
return {
|
|
447
|
+
content: [
|
|
448
|
+
{
|
|
449
|
+
type: "text",
|
|
450
|
+
text: `Session ${params.sessionId} is not backgrounded.`,
|
|
451
|
+
},
|
|
452
|
+
],
|
|
453
|
+
details: { status: "failed" },
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
const { slice, totalLines, totalChars } = sliceLogLines(session.aggregated, params.offset, params.limit);
|
|
457
|
+
return {
|
|
458
|
+
content: [{ type: "text", text: slice || "(no output yet)" }],
|
|
459
|
+
details: {
|
|
460
|
+
status: session.exited ? "completed" : "running",
|
|
461
|
+
sessionId: params.sessionId,
|
|
462
|
+
total: totalLines,
|
|
463
|
+
totalLines,
|
|
464
|
+
totalChars,
|
|
465
|
+
truncated: session.truncated,
|
|
466
|
+
name: deriveSessionName(session.command),
|
|
467
|
+
},
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
if (finished) {
|
|
471
|
+
const { slice, totalLines, totalChars } = sliceLogLines(finished.aggregated, params.offset, params.limit);
|
|
472
|
+
const status = finished.status === "completed" ? "completed" : "failed";
|
|
473
|
+
return {
|
|
474
|
+
content: [
|
|
475
|
+
{ type: "text", text: slice || "(no output recorded)" },
|
|
476
|
+
],
|
|
477
|
+
details: {
|
|
478
|
+
status,
|
|
479
|
+
sessionId: params.sessionId,
|
|
480
|
+
total: totalLines,
|
|
481
|
+
totalLines,
|
|
482
|
+
totalChars,
|
|
483
|
+
truncated: finished.truncated,
|
|
484
|
+
exitCode: finished.exitCode ?? undefined,
|
|
485
|
+
exitSignal: finished.exitSignal ?? undefined,
|
|
486
|
+
name: deriveSessionName(finished.command),
|
|
487
|
+
},
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
return {
|
|
491
|
+
content: [
|
|
492
|
+
{
|
|
493
|
+
type: "text",
|
|
494
|
+
text: `No session found for ${params.sessionId}`,
|
|
495
|
+
},
|
|
496
|
+
],
|
|
497
|
+
details: { status: "failed" },
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
case "write": {
|
|
501
|
+
if (!session) {
|
|
502
|
+
return {
|
|
503
|
+
content: [
|
|
504
|
+
{
|
|
505
|
+
type: "text",
|
|
506
|
+
text: `No active session found for ${params.sessionId}`,
|
|
507
|
+
},
|
|
508
|
+
],
|
|
509
|
+
details: { status: "failed" },
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
if (!session.backgrounded) {
|
|
513
|
+
return {
|
|
514
|
+
content: [
|
|
515
|
+
{
|
|
516
|
+
type: "text",
|
|
517
|
+
text: `Session ${params.sessionId} is not backgrounded.`,
|
|
518
|
+
},
|
|
519
|
+
],
|
|
520
|
+
details: { status: "failed" },
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
if (!session.child?.stdin || session.child.stdin.destroyed) {
|
|
524
|
+
return {
|
|
525
|
+
content: [
|
|
526
|
+
{
|
|
527
|
+
type: "text",
|
|
528
|
+
text: `Session ${params.sessionId} stdin is not writable.`,
|
|
529
|
+
},
|
|
530
|
+
],
|
|
531
|
+
details: { status: "failed" },
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
await new Promise((resolve, reject) => {
|
|
535
|
+
session.child?.stdin.write(params.data ?? "", (err) => {
|
|
536
|
+
if (err)
|
|
537
|
+
reject(err);
|
|
538
|
+
else
|
|
539
|
+
resolve();
|
|
540
|
+
});
|
|
541
|
+
});
|
|
542
|
+
if (params.eof) {
|
|
543
|
+
session.child.stdin.end();
|
|
544
|
+
}
|
|
545
|
+
return {
|
|
546
|
+
content: [
|
|
547
|
+
{
|
|
548
|
+
type: "text",
|
|
549
|
+
text: `Wrote ${(params.data ?? "").length} bytes to session ${params.sessionId}${params.eof ? " (stdin closed)" : ""}.`,
|
|
550
|
+
},
|
|
551
|
+
],
|
|
552
|
+
details: {
|
|
553
|
+
status: "running",
|
|
554
|
+
sessionId: params.sessionId,
|
|
555
|
+
name: session ? deriveSessionName(session.command) : undefined,
|
|
556
|
+
},
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
case "kill": {
|
|
560
|
+
if (!session) {
|
|
561
|
+
return {
|
|
562
|
+
content: [
|
|
563
|
+
{
|
|
564
|
+
type: "text",
|
|
565
|
+
text: `No active session found for ${params.sessionId}`,
|
|
566
|
+
},
|
|
567
|
+
],
|
|
568
|
+
details: { status: "failed" },
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
if (!session.backgrounded) {
|
|
572
|
+
return {
|
|
573
|
+
content: [
|
|
574
|
+
{
|
|
575
|
+
type: "text",
|
|
576
|
+
text: `Session ${params.sessionId} is not backgrounded.`,
|
|
577
|
+
},
|
|
578
|
+
],
|
|
579
|
+
details: { status: "failed" },
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
killSession(session);
|
|
583
|
+
markExited(session, null, "SIGKILL", "failed");
|
|
584
|
+
return {
|
|
585
|
+
content: [
|
|
586
|
+
{ type: "text", text: `Killed session ${params.sessionId}.` },
|
|
587
|
+
],
|
|
588
|
+
details: {
|
|
589
|
+
status: "failed",
|
|
590
|
+
name: session ? deriveSessionName(session.command) : undefined,
|
|
591
|
+
},
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
case "clear": {
|
|
595
|
+
if (finished) {
|
|
596
|
+
deleteSession(params.sessionId);
|
|
597
|
+
return {
|
|
598
|
+
content: [
|
|
599
|
+
{ type: "text", text: `Cleared session ${params.sessionId}.` },
|
|
600
|
+
],
|
|
601
|
+
details: { status: "completed" },
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
return {
|
|
605
|
+
content: [
|
|
606
|
+
{
|
|
607
|
+
type: "text",
|
|
608
|
+
text: `No finished session found for ${params.sessionId}`,
|
|
609
|
+
},
|
|
610
|
+
],
|
|
611
|
+
details: { status: "failed" },
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
case "remove": {
|
|
615
|
+
if (session) {
|
|
616
|
+
killSession(session);
|
|
617
|
+
markExited(session, null, "SIGKILL", "failed");
|
|
618
|
+
return {
|
|
619
|
+
content: [
|
|
620
|
+
{ type: "text", text: `Removed session ${params.sessionId}.` },
|
|
621
|
+
],
|
|
622
|
+
details: {
|
|
623
|
+
status: "failed",
|
|
624
|
+
name: session ? deriveSessionName(session.command) : undefined,
|
|
625
|
+
},
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
if (finished) {
|
|
629
|
+
deleteSession(params.sessionId);
|
|
630
|
+
return {
|
|
631
|
+
content: [
|
|
632
|
+
{ type: "text", text: `Removed session ${params.sessionId}.` },
|
|
633
|
+
],
|
|
634
|
+
details: { status: "completed" },
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
return {
|
|
638
|
+
content: [
|
|
639
|
+
{
|
|
640
|
+
type: "text",
|
|
641
|
+
text: `No session found for ${params.sessionId}`,
|
|
642
|
+
},
|
|
643
|
+
],
|
|
644
|
+
details: { status: "failed" },
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
return {
|
|
649
|
+
content: [
|
|
650
|
+
{ type: "text", text: `Unknown action ${params.action}` },
|
|
651
|
+
],
|
|
652
|
+
details: { status: "failed" },
|
|
653
|
+
};
|
|
654
|
+
},
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
export const processTool = createProcessTool();
|
|
658
|
+
function buildSandboxEnv(params) {
|
|
659
|
+
const env = {
|
|
660
|
+
PATH: DEFAULT_PATH,
|
|
661
|
+
HOME: params.containerWorkdir,
|
|
662
|
+
};
|
|
663
|
+
for (const [key, value] of Object.entries(params.sandboxEnv ?? {})) {
|
|
664
|
+
env[key] = value;
|
|
665
|
+
}
|
|
666
|
+
for (const [key, value] of Object.entries(params.paramsEnv ?? {})) {
|
|
667
|
+
env[key] = value;
|
|
668
|
+
}
|
|
669
|
+
return env;
|
|
670
|
+
}
|
|
671
|
+
function coerceEnv(env) {
|
|
672
|
+
const record = {};
|
|
673
|
+
if (!env)
|
|
674
|
+
return record;
|
|
675
|
+
for (const [key, value] of Object.entries(env)) {
|
|
676
|
+
if (typeof value === "string")
|
|
677
|
+
record[key] = value;
|
|
678
|
+
}
|
|
679
|
+
return record;
|
|
680
|
+
}
|
|
681
|
+
function buildDockerExecArgs(params) {
|
|
682
|
+
const args = ["exec", "-i"];
|
|
683
|
+
if (params.tty)
|
|
684
|
+
args.push("-t");
|
|
685
|
+
if (params.workdir) {
|
|
686
|
+
args.push("-w", params.workdir);
|
|
687
|
+
}
|
|
688
|
+
for (const [key, value] of Object.entries(params.env)) {
|
|
689
|
+
args.push("-e", `${key}=${value}`);
|
|
690
|
+
}
|
|
691
|
+
args.push(params.containerName, "sh", "-lc", params.command);
|
|
692
|
+
return args;
|
|
693
|
+
}
|
|
694
|
+
async function resolveSandboxWorkdir(params) {
|
|
695
|
+
const fallback = params.sandbox.workspaceDir;
|
|
696
|
+
try {
|
|
697
|
+
const resolved = await assertSandboxPath({
|
|
698
|
+
filePath: params.workdir,
|
|
699
|
+
cwd: process.cwd(),
|
|
700
|
+
root: params.sandbox.workspaceDir,
|
|
701
|
+
});
|
|
702
|
+
const stats = await fs.stat(resolved.resolved);
|
|
703
|
+
if (!stats.isDirectory()) {
|
|
704
|
+
throw new Error("workdir is not a directory");
|
|
705
|
+
}
|
|
706
|
+
const relative = resolved.relative
|
|
707
|
+
? resolved.relative.split(path.sep).join(path.posix.sep)
|
|
708
|
+
: "";
|
|
709
|
+
const containerWorkdir = relative
|
|
710
|
+
? path.posix.join(params.sandbox.containerWorkdir, relative)
|
|
711
|
+
: params.sandbox.containerWorkdir;
|
|
712
|
+
return { hostWorkdir: resolved.resolved, containerWorkdir };
|
|
713
|
+
}
|
|
714
|
+
catch {
|
|
715
|
+
params.warnings.push(`Warning: workdir "${params.workdir}" is unavailable; using "${fallback}".`);
|
|
716
|
+
return {
|
|
717
|
+
hostWorkdir: fallback,
|
|
718
|
+
containerWorkdir: params.sandbox.containerWorkdir,
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
function killSession(session) {
|
|
723
|
+
const pid = session.pid ?? session.child?.pid;
|
|
724
|
+
if (pid) {
|
|
725
|
+
killProcessTree(pid);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
function resolveWorkdir(workdir, warnings) {
|
|
729
|
+
const current = safeCwd();
|
|
730
|
+
const fallback = current ?? homedir();
|
|
731
|
+
try {
|
|
732
|
+
const stats = statSync(workdir);
|
|
733
|
+
if (stats.isDirectory())
|
|
734
|
+
return workdir;
|
|
735
|
+
}
|
|
736
|
+
catch {
|
|
737
|
+
// ignore, fallback below
|
|
738
|
+
}
|
|
739
|
+
warnings.push(`Warning: workdir "${workdir}" is unavailable; using "${fallback}".`);
|
|
740
|
+
return fallback;
|
|
741
|
+
}
|
|
742
|
+
function safeCwd() {
|
|
743
|
+
try {
|
|
744
|
+
const cwd = process.cwd();
|
|
745
|
+
return existsSync(cwd) ? cwd : null;
|
|
746
|
+
}
|
|
747
|
+
catch {
|
|
748
|
+
return null;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
function clampNumber(value, defaultValue, min, max) {
|
|
752
|
+
if (value === undefined || Number.isNaN(value))
|
|
753
|
+
return defaultValue;
|
|
754
|
+
return Math.min(Math.max(value, min), max);
|
|
755
|
+
}
|
|
756
|
+
function readEnvInt(key) {
|
|
757
|
+
const raw = process.env[key];
|
|
758
|
+
if (!raw)
|
|
759
|
+
return undefined;
|
|
760
|
+
const parsed = Number.parseInt(raw, 10);
|
|
761
|
+
return Number.isFinite(parsed) ? parsed : undefined;
|
|
762
|
+
}
|
|
763
|
+
function chunkString(input, limit = CHUNK_LIMIT) {
|
|
764
|
+
const chunks = [];
|
|
765
|
+
for (let i = 0; i < input.length; i += limit) {
|
|
766
|
+
chunks.push(input.slice(i, i + limit));
|
|
767
|
+
}
|
|
768
|
+
return chunks;
|
|
769
|
+
}
|
|
770
|
+
function truncateMiddle(str, max) {
|
|
771
|
+
if (str.length <= max)
|
|
772
|
+
return str;
|
|
773
|
+
const half = Math.floor((max - 3) / 2);
|
|
774
|
+
return `${str.slice(0, half)}...${str.slice(str.length - half)}`;
|
|
775
|
+
}
|
|
776
|
+
function sliceLogLines(text, offset, limit) {
|
|
777
|
+
if (!text)
|
|
778
|
+
return { slice: "", totalLines: 0, totalChars: 0 };
|
|
779
|
+
const normalized = text.replace(/\r\n/g, "\n");
|
|
780
|
+
const lines = normalized.split("\n");
|
|
781
|
+
if (lines.length > 0 && lines[lines.length - 1] === "") {
|
|
782
|
+
lines.pop();
|
|
783
|
+
}
|
|
784
|
+
const totalLines = lines.length;
|
|
785
|
+
const totalChars = text.length;
|
|
786
|
+
let start = typeof offset === "number" && Number.isFinite(offset)
|
|
787
|
+
? Math.max(0, Math.floor(offset))
|
|
788
|
+
: 0;
|
|
789
|
+
if (limit !== undefined && offset === undefined) {
|
|
790
|
+
const tailCount = Math.max(0, Math.floor(limit));
|
|
791
|
+
start = Math.max(totalLines - tailCount, 0);
|
|
792
|
+
}
|
|
793
|
+
const end = typeof limit === "number" && Number.isFinite(limit)
|
|
794
|
+
? start + Math.max(0, Math.floor(limit))
|
|
795
|
+
: undefined;
|
|
796
|
+
return { slice: lines.slice(start, end).join("\n"), totalLines, totalChars };
|
|
797
|
+
}
|
|
798
|
+
function deriveSessionName(command) {
|
|
799
|
+
const tokens = tokenizeCommand(command);
|
|
800
|
+
if (tokens.length === 0)
|
|
801
|
+
return undefined;
|
|
802
|
+
const verb = tokens[0];
|
|
803
|
+
let target = tokens.slice(1).find((t) => !t.startsWith("-"));
|
|
804
|
+
if (!target)
|
|
805
|
+
target = tokens[1];
|
|
806
|
+
if (!target)
|
|
807
|
+
return verb;
|
|
808
|
+
const cleaned = truncateMiddle(stripQuotes(target), 48);
|
|
809
|
+
return `${stripQuotes(verb)} ${cleaned}`;
|
|
810
|
+
}
|
|
811
|
+
function tokenizeCommand(command) {
|
|
812
|
+
const matches = command.match(/(?:[^\s"']+|"(?:\\.|[^"])*"|'(?:\\.|[^'])*')+/g) ?? [];
|
|
813
|
+
return matches.map((token) => stripQuotes(token)).filter(Boolean);
|
|
814
|
+
}
|
|
815
|
+
function stripQuotes(value) {
|
|
816
|
+
const trimmed = value.trim();
|
|
817
|
+
if ((trimmed.startsWith('"') && trimmed.endsWith('"')) ||
|
|
818
|
+
(trimmed.startsWith("'") && trimmed.endsWith("'"))) {
|
|
819
|
+
return trimmed.slice(1, -1);
|
|
820
|
+
}
|
|
821
|
+
return trimmed;
|
|
822
|
+
}
|
|
823
|
+
function formatDuration(ms) {
|
|
824
|
+
if (ms < 1000)
|
|
825
|
+
return `${ms}ms`;
|
|
826
|
+
const seconds = Math.floor(ms / 1000);
|
|
827
|
+
if (seconds < 60)
|
|
828
|
+
return `${seconds}s`;
|
|
829
|
+
const minutes = Math.floor(seconds / 60);
|
|
830
|
+
const rem = seconds % 60;
|
|
831
|
+
return `${minutes}m${rem.toString().padStart(2, "0")}s`;
|
|
832
|
+
}
|
|
833
|
+
function pad(str, width) {
|
|
834
|
+
if (str.length >= width)
|
|
835
|
+
return str;
|
|
836
|
+
return str + " ".repeat(width - str.length);
|
|
837
|
+
}
|