moi-computer 0.13.1-next.4 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/moi.mjs +10 -6
- package/dist/{chunk-k32585ne.js → chunk-828s864r.js} +61 -61
- package/dist/chunk-9ffaaaw3.css +1 -0
- package/dist/chunk-gh11h6dc.js +2 -0
- package/dist/chunk-hhgsmxsq.js +1 -0
- package/dist/chunk-ht9zmff2.js +5 -0
- package/dist/{chunk-0t8m1ehd.js → chunk-jqa4c92z.js} +2 -2
- package/dist/{chunk-qtkv7hp8.js → chunk-kkhswjz8.js} +2 -2
- package/dist/{chunk-wjbejzek.js → chunk-nqh3kx2x.js} +1 -1
- package/dist/chunk-rb2vsqvb.js +1 -0
- package/dist/{chunk-c8g5x288.js → chunk-t22yw8s6.js} +1 -1
- package/dist/chunk-yv6n9e3z.js +72 -0
- package/dist/dot-2bdkpg3k.png +0 -0
- package/dist/duet-3ab8xyzd.png +0 -0
- package/dist/grok-bot-yv07qj9f.png +0 -0
- package/dist/index.html +1 -1
- package/dist/instinct-ypmq6t0w.png +0 -0
- package/dist/muse-qr7zwsvf.png +0 -0
- package/package.json +39 -40
- package/runtime/applets/chunk-bzxakh65.js +2 -0
- package/runtime/applets/chunk-qhjskz2m.js +2 -0
- package/runtime/applets/collab.js +1 -0
- package/runtime/applets/moi.js +1 -0
- package/runtime/applets/rpc.js +2 -0
- package/runtime/assets/shadcn.css +629 -0
- package/runtime/assets/tw-animate.css +1 -0
- package/runtime/build-worker-entry.js +2 -0
- package/runtime/chunk-00rk365r.js +83 -0
- package/runtime/chunk-4wj1jzhr.js +3 -0
- package/runtime/chunk-5egvk1rz.js +3 -0
- package/runtime/chunk-7c0zbz74.js +3 -0
- package/runtime/chunk-8fvgvm56.js +2 -0
- package/runtime/chunk-c3qyet60.js +128 -0
- package/runtime/chunk-ewc55jga.js +32623 -0
- package/runtime/chunk-gbkjshyt.js +26 -0
- package/runtime/chunk-ggphq7nk.js +66 -0
- package/runtime/chunk-h2bwhk81.js +3 -0
- package/runtime/chunk-hjzfk1cr.js +3 -0
- package/runtime/chunk-j0nd7kw0.js +52 -0
- package/runtime/chunk-jb63ns1z.js +2 -0
- package/runtime/chunk-k049dtaq.js +3 -0
- package/runtime/chunk-kjp60rqs.js +3 -0
- package/runtime/chunk-q06m17nb.js +3 -0
- package/runtime/chunk-r5s8rm8n.js +3 -0
- package/runtime/chunk-sdyqhxe1.js +10 -0
- package/runtime/chunk-w1fx9tsc.js +3 -0
- package/runtime/chunk-w6ksnv8y.js +2 -0
- package/runtime/chunk-wvarpvem.js +78 -0
- package/runtime/chunk-zm7k0v1c.js +3 -0
- package/runtime/chunk-zwvtkb81.js +139 -0
- package/runtime/cli.js +246 -0
- package/runtime/functions-worker.js +2 -0
- package/runtime/gateway-client.js +2 -0
- package/runtime/third-party-notices.txt +6830 -0
- package/runtime/worker.js +2 -0
- package/runtime/xdg-open +1267 -0
- package/bunfig.toml +0 -7
- package/client/AGENTS.md +0 -40
- package/client/api/app-config.ts +0 -58
- package/client/api/http.ts +0 -44
- package/client/api/query-client.ts +0 -5
- package/client/api/query-options.ts +0 -6
- package/client/api/workspace-keys.ts +0 -18
- package/client/app/app-provider.tsx +0 -39
- package/client/app/app-router.tsx +0 -57
- package/client/app/routes/home-route.tsx +0 -27
- package/client/app/routes/onboarding-route.tsx +0 -11
- package/client/app/routes/settings-route.tsx +0 -10
- package/client/app/routes/workspace-registration.tsx +0 -68
- package/client/app/routes/workspace-route.tsx +0 -127
- package/client/app/shell/sidebar-layout.tsx +0 -247
- package/client/assets/claude.svg +0 -3
- package/client/assets/favicon.png +0 -0
- package/client/assets/floppy-disk.webp +0 -0
- package/client/assets/hermes.png +0 -0
- package/client/assets/mcp/.gitkeep +0 -0
- package/client/assets/mcp/airtable.png +0 -0
- package/client/assets/mcp/apollo.png +0 -0
- package/client/assets/mcp/asana.png +0 -0
- package/client/assets/mcp/atlassian.png +0 -0
- package/client/assets/mcp/box.png +0 -0
- package/client/assets/mcp/chrome.svg +0 -33
- package/client/assets/mcp/clickup.png +0 -0
- package/client/assets/mcp/cloudflare.png +0 -0
- package/client/assets/mcp/context7.png +0 -0
- package/client/assets/mcp/datadog.png +0 -0
- package/client/assets/mcp/discord.png +0 -0
- package/client/assets/mcp/dropbox.png +0 -0
- package/client/assets/mcp/elevenlabs.png +0 -0
- package/client/assets/mcp/exa.png +0 -0
- package/client/assets/mcp/figma.png +0 -0
- package/client/assets/mcp/firecrawl.png +0 -0
- package/client/assets/mcp/github.png +0 -0
- package/client/assets/mcp/gitlab.png +0 -0
- package/client/assets/mcp/gmail.png +0 -0
- package/client/assets/mcp/googlecalendar.png +0 -0
- package/client/assets/mcp/googledrive.png +0 -0
- package/client/assets/mcp/grafana.png +0 -0
- package/client/assets/mcp/granola.png +0 -0
- package/client/assets/mcp/hubspot.png +0 -0
- package/client/assets/mcp/huggingface.png +0 -0
- package/client/assets/mcp/intercom.png +0 -0
- package/client/assets/mcp/linear.png +0 -0
- package/client/assets/mcp/monday.png +0 -0
- package/client/assets/mcp/mongodb.png +0 -0
- package/client/assets/mcp/neon.png +0 -0
- package/client/assets/mcp/notion.png +0 -0
- package/client/assets/mcp/paper.png +0 -0
- package/client/assets/mcp/paypal.png +0 -0
- package/client/assets/mcp/perplexity.png +0 -0
- package/client/assets/mcp/postgresql.png +0 -0
- package/client/assets/mcp/posthog.png +0 -0
- package/client/assets/mcp/puppeteer.png +0 -0
- package/client/assets/mcp/railway.png +0 -0
- package/client/assets/mcp/redis.png +0 -0
- package/client/assets/mcp/salesforce.png +0 -0
- package/client/assets/mcp/sentry.png +0 -0
- package/client/assets/mcp/shopify.png +0 -0
- package/client/assets/mcp/slack.png +0 -0
- package/client/assets/mcp/snowflake.png +0 -0
- package/client/assets/mcp/stripe.png +0 -0
- package/client/assets/mcp/supabase.png +0 -0
- package/client/assets/mcp/telegram.png +0 -0
- package/client/assets/mcp/twilio.png +0 -0
- package/client/assets/mcp/vercel.png +0 -0
- package/client/assets/mcp/zapier.png +0 -0
- package/client/assets/moi-logo.svg +0 -11
- package/client/assets/openai.svg +0 -1
- package/client/assets/openclaw.svg +0 -22
- package/client/assets.d.ts +0 -14
- package/client/components/shared/agent-blobatar.tsx +0 -93
- package/client/components/shared/bottom-panel.tsx +0 -65
- package/client/components/shared/composer.tsx +0 -125
- package/client/components/shared/led-logo.tsx +0 -181
- package/client/components/shared/panel-header.tsx +0 -16
- package/client/components/shared/reorderable-list.tsx +0 -204
- package/client/components/shared/screen-shell.tsx +0 -23
- package/client/components/shared/ultrafast-icon.tsx +0 -61
- package/client/components/shared/workspace-icon.tsx +0 -83
- package/client/components/ui/alert-dialog.tsx +0 -1
- package/client/components/ui/button.tsx +0 -1
- package/client/components/ui/checkbox.tsx +0 -1
- package/client/components/ui/collapsible.tsx +0 -1
- package/client/components/ui/dialog.tsx +0 -1
- package/client/components/ui/dropdown-menu.tsx +0 -1
- package/client/components/ui/hover-card.tsx +0 -1
- package/client/components/ui/inline-input.tsx +0 -84
- package/client/components/ui/input.tsx +0 -1
- package/client/components/ui/popover.tsx +0 -1
- package/client/components/ui/resizable.tsx +0 -1
- package/client/components/ui/skeleton.tsx +0 -1
- package/client/components/ui/slider.tsx +0 -1
- package/client/components/ui/spinner.tsx +0 -1
- package/client/components/ui/switch.tsx +0 -1
- package/client/components/ui/tabs.tsx +0 -1
- package/client/components/ui/textarea.tsx +0 -1
- package/client/components/ui/toast.tsx +0 -220
- package/client/components/ui/tooltip.tsx +0 -1
- package/client/dev/index.html +0 -43
- package/client/dev/index.ts +0 -15
- package/client/externalize-react.ts +0 -41
- package/client/features/account/account-menu.tsx +0 -96
- package/client/features/account/account-provider.tsx +0 -93
- package/client/features/account/account-test-utils.tsx +0 -310
- package/client/features/account/api.ts +0 -67
- package/client/features/account/profile-actions.ts +0 -29
- package/client/features/app-settings/api.ts +0 -33
- package/client/features/app-settings/avatar-upload.tsx +0 -62
- package/client/features/app-settings/general-settings.tsx +0 -39
- package/client/features/app-settings/profile-settings.tsx +0 -105
- package/client/features/app-settings/settings-page.tsx +0 -45
- package/client/features/app-settings/settings-section.tsx +0 -26
- package/client/features/applets/api.ts +0 -38
- package/client/features/applets/applet-cache.ts +0 -95
- package/client/features/applets/applet-container.tsx +0 -33
- package/client/features/applets/applet-log.ts +0 -81
- package/client/features/applets/applet-runtime.ts +0 -325
- package/client/features/applets/applet-styles.ts +0 -81
- package/client/features/applets/applet-thumbnail.ts +0 -294
- package/client/features/applets/use-applet.ts +0 -210
- package/client/features/applets/widget-error-boundary.tsx +0 -62
- package/client/features/applets/widget-shell.tsx +0 -56
- package/client/features/chat/applet-chat-intents.ts +0 -173
- package/client/features/chat/chat-panel.tsx +0 -326
- package/client/features/chat/chat-popup.tsx +0 -175
- package/client/features/chat/chat-send.ts +0 -259
- package/client/features/chat/chat-store.ts +0 -328
- package/client/features/chat/composer/attachments/attachment-chip.tsx +0 -99
- package/client/features/chat/composer/attachments/draft-attachments.ts +0 -185
- package/client/features/chat/composer/attachments/drawing-attachment-chip.tsx +0 -37
- package/client/features/chat/composer/attachments/file-attachment-chip.tsx +0 -22
- package/client/features/chat/composer/attachments/text-attachment-chip.tsx +0 -11
- package/client/features/chat/composer/attachments/types.ts +0 -25
- package/client/features/chat/composer/attachments/uploads.ts +0 -26
- package/client/features/chat/composer/banners/composer-banner.tsx +0 -16
- package/client/features/chat/composer/banners/error-banner.tsx +0 -36
- package/client/features/chat/composer/banners/skill-update-banner.tsx +0 -93
- package/client/features/chat/composer/chat-composer.tsx +0 -290
- package/client/features/chat/composer/model-order.ts +0 -110
- package/client/features/chat/composer/model-picker.tsx +0 -408
- package/client/features/chat/composer/use-workspace-composer-state.tsx +0 -69
- package/client/features/chat/composer/use-workspace-skill-updates.ts +0 -160
- package/client/features/chat/connection/chat-connection.ts +0 -64
- package/client/features/chat/connection/chat-frames.ts +0 -153
- package/client/features/chat/messages/chat-empty-state.tsx +0 -294
- package/client/features/chat/messages/chat-prompt-bubbles.tsx +0 -72
- package/client/features/chat/messages/fork-history.ts +0 -14
- package/client/features/chat/messages/group-turns.ts +0 -74
- package/client/features/chat/messages/interleave-notices.ts +0 -80
- package/client/features/chat/messages/markdown-content.tsx +0 -89
- package/client/features/chat/messages/preview-turn.ts +0 -37
- package/client/features/chat/messages/shimmer-text.tsx +0 -20
- package/client/features/chat/messages/tool-group/code-block.tsx +0 -41
- package/client/features/chat/messages/tool-group/collapse.tsx +0 -28
- package/client/features/chat/messages/tool-group/detect.ts +0 -93
- package/client/features/chat/messages/tool-group/fixtures.ts +0 -309
- package/client/features/chat/messages/tool-group/format/claude.ts +0 -49
- package/client/features/chat/messages/tool-group/format/codex.ts +0 -130
- package/client/features/chat/messages/tool-group/format/hermes.ts +0 -69
- package/client/features/chat/messages/tool-group/format/index.ts +0 -34
- package/client/features/chat/messages/tool-group/format/mcp.ts +0 -68
- package/client/features/chat/messages/tool-group/format/openclaw.ts +0 -120
- package/client/features/chat/messages/tool-group/format/shared.ts +0 -49
- package/client/features/chat/messages/tool-group/format/shell.ts +0 -162
- package/client/features/chat/messages/tool-group/index.ts +0 -9
- package/client/features/chat/messages/tool-group/read-image-preview.tsx +0 -46
- package/client/features/chat/messages/tool-group/subagent-card.tsx +0 -138
- package/client/features/chat/messages/tool-group/timeline-row.tsx +0 -159
- package/client/features/chat/messages/tool-group/tool-call-group.tsx +0 -279
- package/client/features/chat/messages/tool-group/tool-output.tsx +0 -125
- package/client/features/chat/messages/turn-view.tsx +0 -270
- package/client/features/chat/messages/use-stick-to-bottom.ts +0 -96
- package/client/features/chat/messages/user-message-bubble.tsx +0 -63
- package/client/features/chat/sessions/api.ts +0 -193
- package/client/features/chat/sessions/chat-selector.tsx +0 -399
- package/client/features/chat/sessions/session-view.ts +0 -53
- package/client/features/chat/sessions/use-selected-session.ts +0 -171
- package/client/features/chat/use-chat.ts +0 -229
- package/client/features/collab/applet-api.ts +0 -35
- package/client/features/collab/components/cursors.tsx +0 -241
- package/client/features/collab/components/presence-avatars.tsx +0 -74
- package/client/features/collab/components/presence-frame.tsx +0 -122
- package/client/features/collab/components/presence-group.tsx +0 -31
- package/client/features/collab/components/presence-helpers.ts +0 -50
- package/client/features/collab/components/user-avatar-group.tsx +0 -35
- package/client/features/collab/components/user-avatar.tsx +0 -65
- package/client/features/collab/components/user.tsx +0 -69
- package/client/features/collab/host-state.ts +0 -160
- package/client/features/collab/index.ts +0 -5
- package/client/features/collab/local-user.ts +0 -46
- package/client/features/collab/members/api.ts +0 -17
- package/client/features/collab/members/hooks.ts +0 -97
- package/client/features/collab/members/store.ts +0 -148
- package/client/features/collab/members/types.ts +0 -55
- package/client/features/collab/presence/client.ts +0 -242
- package/client/features/collab/presence/hooks.tsx +0 -160
- package/client/features/collab/presence/presence-publisher.ts +0 -30
- package/client/features/collab/presence/presence-target.ts +0 -8
- package/client/features/collab/presence/provider.tsx +0 -74
- package/client/features/collab/presence/store.ts +0 -156
- package/client/features/collab/presence/users.ts +0 -87
- package/client/features/collab/proxy-user.ts +0 -28
- package/client/features/collab/sharing/agent-invite.tsx +0 -30
- package/client/features/collab/sharing/workspace-members.tsx +0 -269
- package/client/features/collab/sharing/workspace-sharing-menu.tsx +0 -179
- package/client/features/collab/testing/component-fixtures.tsx +0 -54
- package/client/features/collab/testing/fake-engine.ts +0 -120
- package/client/features/connectors/api.ts +0 -25
- package/client/features/connectors/icon-mcp.tsx +0 -21
- package/client/features/connectors/mcp-icons.ts +0 -183
- package/client/features/connectors/mcp-server-cards.tsx +0 -105
- package/client/features/connectors/read-connectors.ts +0 -35
- package/client/features/demo/demo-dialog.tsx +0 -194
- package/client/features/dev/blobatar-shapes-page.tsx +0 -344
- package/client/features/dev/chat-states-fixtures.ts +0 -755
- package/client/features/dev/chat-states-page.tsx +0 -476
- package/client/features/dev/collab/collab-page.tsx +0 -24
- package/client/features/dev/collab/collab-playground.tsx +0 -614
- package/client/features/dev/collab/local-user-settings.tsx +0 -120
- package/client/features/dev/collab/playground-room.ts +0 -33
- package/client/features/dev/dev-index-page.tsx +0 -83
- package/client/features/dev/dev-routes.tsx +0 -43
- package/client/features/dev/harness-debug-page.tsx +0 -607
- package/client/features/dev/onboarding-preview-page.tsx +0 -76
- package/client/features/dev/texture-lab-page.tsx +0 -149
- package/client/features/dev/tool-calls-page.tsx +0 -79
- package/client/features/dev/ui-components/ui-component-previews.tsx +0 -855
- package/client/features/dev/ui-components/ui-components-page.tsx +0 -60
- package/client/features/dev/workspace-setup-mocks.ts +0 -103
- package/client/features/dev/workspace-setup-page.tsx +0 -11
- package/client/features/dev/workspace-setup-preview.tsx +0 -249
- package/client/features/drawings/capture-element.ts +0 -57
- package/client/features/drawings/drawing-layer.tsx +0 -49
- package/client/features/drawings/drawing-toolbar.tsx +0 -95
- package/client/features/drawings/use-chat-annotation.ts +0 -228
- package/client/features/drawings/use-drawing-layer.ts +0 -756
- package/client/features/drawings/use-view-sketch.ts +0 -154
- package/client/features/harness/api.ts +0 -69
- package/client/features/harness/device-login-steps.tsx +0 -103
- package/client/features/harness/harness-login-panel.tsx +0 -232
- package/client/features/harness/harness-presentation.ts +0 -15
- package/client/features/harness/harness-selector.tsx +0 -119
- package/client/features/harness/use-harness-login.ts +0 -77
- package/client/features/home/api.ts +0 -135
- package/client/features/home/home-logo.tsx +0 -344
- package/client/features/home/home-page.tsx +0 -305
- package/client/features/home/shared-workspaces.tsx +0 -70
- package/client/features/home/workspace-invitations.tsx +0 -101
- package/client/features/home/workspace-preview.tsx +0 -213
- package/client/features/identity/host-api.ts +0 -35
- package/client/features/identity/store.ts +0 -26
- package/client/features/identity/types.ts +0 -41
- package/client/features/identity/use-identity.ts +0 -6
- package/client/features/onboarding/agent-setup-step.tsx +0 -57
- package/client/features/onboarding/api.ts +0 -42
- package/client/features/onboarding/onboarding-idea-disk.tsx +0 -129
- package/client/features/onboarding/onboarding-page.tsx +0 -33
- package/client/features/onboarding/onboarding-screen.tsx +0 -20
- package/client/features/onboarding/onboarding-status.tsx +0 -24
- package/client/features/onboarding/workspace-setup-step.tsx +0 -239
- package/client/features/overview/api.ts +0 -28
- package/client/features/overview/default/registry.tsx +0 -34
- package/client/features/overview/default/views-widget.tsx +0 -246
- package/client/features/overview/grid.ts +0 -77
- package/client/features/overview/hidden-panel.tsx +0 -111
- package/client/features/overview/overview.tsx +0 -299
- package/client/features/overview/use-grid-reconcile.ts +0 -94
- package/client/features/overview/widget-canvas.tsx +0 -166
- package/client/features/overview/widget-frame.tsx +0 -77
- package/client/features/overview/workspace-name.tsx +0 -55
- package/client/features/scratchpad/scratch-session.ts +0 -71
- package/client/features/scratchpad/scratchpad-controls.tsx +0 -516
- package/client/features/scratchpad/scratchpad.tsx +0 -360
- package/client/features/scratchpad/use-scratchpad-snapshot.tsx +0 -133
- package/client/features/update/api.ts +0 -35
- package/client/features/update/update-control.tsx +0 -102
- package/client/features/views/api.ts +0 -188
- package/client/features/views/pending-view-screen.tsx +0 -303
- package/client/features/views/use-view-actions.ts +0 -119
- package/client/features/views/use-view-drafts.ts +0 -88
- package/client/features/views/view-manager.tsx +0 -293
- package/client/features/views/view-presentation.ts +0 -12
- package/client/features/views/view-residency.ts +0 -77
- package/client/features/views/view-submission.ts +0 -56
- package/client/features/workspace/add/api.ts +0 -61
- package/client/features/workspace/add/create-workspace-dialog.tsx +0 -230
- package/client/features/workspace/add/import-workspace-dialog.tsx +0 -81
- package/client/features/workspace/add/use-workspace-import.ts +0 -61
- package/client/features/workspace/add/workspace-agent-options.ts +0 -53
- package/client/features/workspace/add/workspace-agent-selector.tsx +0 -96
- package/client/features/workspace/add/workspace-dialog-content.tsx +0 -22
- package/client/features/workspace/api.ts +0 -180
- package/client/features/workspace/harness-transition.ts +0 -81
- package/client/features/workspace/moi-context.ts +0 -129
- package/client/features/workspace/remote.ts +0 -34
- package/client/features/workspace/settings/api.ts +0 -112
- package/client/features/workspace/settings/connectors-settings.tsx +0 -110
- package/client/features/workspace/settings/environment-settings.tsx +0 -149
- package/client/features/workspace/settings/general-settings.tsx +0 -180
- package/client/features/workspace/settings/icon-picker-options.ts +0 -30
- package/client/features/workspace/settings/settings-layout.tsx +0 -53
- package/client/features/workspace/settings/use-env-vars.ts +0 -20
- package/client/features/workspace/settings/workspace-icon-picker.tsx +0 -318
- package/client/features/workspace/settings/workspace-settings-dialog.tsx +0 -65
- package/client/features/workspace/setup/workspace-login-state.tsx +0 -56
- package/client/features/workspace/setup/workspace-recovery-states.tsx +0 -142
- package/client/features/workspace/setup/workspace-setup.tsx +0 -98
- package/client/features/workspace/setup/workspace-welcome-state.tsx +0 -81
- package/client/features/workspace/tab-resolution.ts +0 -32
- package/client/features/workspace/theme-panel.tsx +0 -191
- package/client/features/workspace/unavailable-page.tsx +0 -21
- package/client/features/workspace/use-fits-split-layout.ts +0 -69
- package/client/features/workspace/use-workspace-navigation.ts +0 -265
- package/client/features/workspace/use-workspace-socket.ts +0 -51
- package/client/features/workspace/workspace-content.tsx +0 -597
- package/client/features/workspace/workspace-context.tsx +0 -21
- package/client/features/workspace/workspace-frame.tsx +0 -64
- package/client/features/workspace/workspace-identity.tsx +0 -40
- package/client/features/workspace/workspace-layout-context.tsx +0 -156
- package/client/features/workspace/workspace-menu.tsx +0 -67
- package/client/features/workspace/workspace-pane.tsx +0 -22
- package/client/features/workspace/workspace-pending-screen.tsx +0 -26
- package/client/features/workspace/workspace-preferences.ts +0 -91
- package/client/features/workspace/workspace-presentation.tsx +0 -35
- package/client/features/workspace/workspace-screen.tsx +0 -28
- package/client/features/workspace/workspace-split-layout.tsx +0 -116
- package/client/features/workspace/workspace-state.ts +0 -206
- package/client/features/workspace/workspace-tabs.tsx +0 -233
- package/client/features/workspace/workspace-test-utils.ts +0 -23
- package/client/global.d.ts +0 -5
- package/client/index.css +0 -247
- package/client/index.html +0 -81
- package/client/index.tsx +0 -45
- package/client/lib/agent-availability.ts +0 -14
- package/client/lib/browser-tab-id.ts +0 -4
- package/client/lib/cn.ts +0 -6
- package/client/lib/flags.ts +0 -11
- package/client/lib/identity-icon-registry.ts +0 -150
- package/client/lib/rate-limit.ts +0 -77
- package/client/lib/use-latest-ref.ts +0 -11
- package/client/lib/user-display-name.ts +0 -6
- package/client/lib/ws-url.ts +0 -10
- package/client/main.tsx +0 -43
- package/client/runtime/app-context.ts +0 -20
- package/client/runtime/app-events.ts +0 -75
- package/client/runtime/hmr-watchdog.ts +0 -39
- package/client/runtime/reconnecting-socket.ts +0 -115
- package/client/runtime/use-client-events.ts +0 -69
- package/client/runtime/workspace-theme.ts +0 -175
- package/client/store/ui.ts +0 -94
- package/client/store/workspace-session.ts +0 -30
- package/client/structured-clone-shim.ts +0 -14
- package/client/tailwind-config.ts +0 -43
- package/dist/chunk-851bx8ss.js +0 -72
- package/dist/chunk-cty37f3v.js +0 -1
- package/dist/chunk-dy6f6h3e.js +0 -5
- package/dist/chunk-j6928pwm.js +0 -1
- package/dist/chunk-kffcah9w.css +0 -1
- package/dist/chunk-rh58dc0y.js +0 -2
- package/lib/applet-selector.ts +0 -24
- package/lib/attachment-note.ts +0 -66
- package/lib/chat-title.ts +0 -11
- package/lib/collab/colors.ts +0 -30
- package/lib/collab/protocol.ts +0 -84
- package/lib/collab/types.ts +0 -52
- package/lib/default-widgets.ts +0 -32
- package/lib/events.ts +0 -61
- package/lib/format.ts +0 -348
- package/lib/harness-instructions.ts +0 -30
- package/lib/harness-types.ts +0 -13
- package/lib/identity-icons.ts +0 -73
- package/lib/ids.ts +0 -33
- package/lib/message-attachments.ts +0 -40
- package/lib/moi-attachments.ts +0 -204
- package/lib/moi-context.ts +0 -305
- package/lib/navigation.ts +0 -65
- package/lib/onboarding.ts +0 -41
- package/lib/scratchpad-skew.ts +0 -64
- package/lib/session-drafts.ts +0 -10
- package/lib/speed-mode.ts +0 -5
- package/lib/system-messages.ts +0 -241
- package/lib/themes.ts +0 -241
- package/lib/types.ts +0 -776
- package/lib/update.ts +0 -2
- package/lib/view-build-directives.ts +0 -11
- package/lib/workspace-config.ts +0 -48
- package/lib/workspace-icon.ts +0 -20
- package/lib/workspace-layout.ts +0 -15
- package/lib/workspace-name.ts +0 -17
- package/lib/workspace-tabs.ts +0 -29
- package/server/AGENTS.md +0 -17
- package/server/README.md +0 -123
- package/server/agent-caller.ts +0 -16
- package/server/agent-launcher.ts +0 -27
- package/server/api/harnesses.ts +0 -79
- package/server/api/index.ts +0 -1351
- package/server/api/onboarding.ts +0 -46
- package/server/app-config.ts +0 -264
- package/server/app-settings.ts +0 -69
- package/server/applets/api-base.ts +0 -4
- package/server/applets/applet-css.ts +0 -55
- package/server/applets/build-applet.ts +0 -475
- package/server/applets/build-worker.ts +0 -179
- package/server/applets/bundle-queue.ts +0 -19
- package/server/applets/config.ts +0 -226
- package/server/applets/declarations.ts +0 -45
- package/server/applets/dependencies.ts +0 -206
- package/server/applets/functions-worker.ts +0 -121
- package/server/applets/functions.ts +0 -392
- package/server/applets/index.ts +0 -504
- package/server/applets/log.ts +0 -149
- package/server/applets/runtime/collab.ts +0 -94
- package/server/applets/runtime/moi.ts +0 -35
- package/server/applets/runtime/rpc.ts +0 -15
- package/server/applets/thumbnails.ts +0 -200
- package/server/applets/typecheck.ts +0 -100
- package/server/applets/ui-components.ts +0 -241
- package/server/applets/view-source.ts +0 -73
- package/server/applets/views.ts +0 -323
- package/server/applets/widgets.ts +0 -181
- package/server/cli/applet-selector.ts +0 -19
- package/server/cli/args.ts +0 -5
- package/server/cli/colors.ts +0 -20
- package/server/cli/commands/bundle.ts +0 -119
- package/server/cli/commands/call-server-fn.ts +0 -42
- package/server/cli/commands/check.ts +0 -53
- package/server/cli/commands/config.ts +0 -120
- package/server/cli/commands/debug.ts +0 -119
- package/server/cli/commands/env.ts +0 -162
- package/server/cli/commands/hermes.ts +0 -149
- package/server/cli/commands/init.ts +0 -323
- package/server/cli/commands/navigate.ts +0 -35
- package/server/cli/commands/openclaw.ts +0 -168
- package/server/cli/commands/refresh.ts +0 -45
- package/server/cli/commands/remote.ts +0 -330
- package/server/cli/commands/scratch.ts +0 -496
- package/server/cli/commands/service.ts +0 -298
- package/server/cli/commands/skill.ts +0 -121
- package/server/cli/commands/start.ts +0 -112
- package/server/cli/commands/status.ts +0 -80
- package/server/cli/commands/tabs.ts +0 -36
- package/server/cli/commands/theme.ts +0 -192
- package/server/cli/commands/ui-components.ts +0 -15
- package/server/cli/commands/update.ts +0 -192
- package/server/cli/commands/version.ts +0 -9
- package/server/cli/commands/views.ts +0 -87
- package/server/cli/control.ts +0 -120
- package/server/cli/env.ts +0 -259
- package/server/cli/index.ts +0 -175
- package/server/cli/pc.ts +0 -20
- package/server/cli/provider.ts +0 -25
- package/server/cli/remote-command.ts +0 -77
- package/server/cli/remote-control.ts +0 -73
- package/server/cli/remote-operations.ts +0 -247
- package/server/cli/server-version.ts +0 -16
- package/server/cli/server.ts +0 -93
- package/server/cli/ui-components.ts +0 -294
- package/server/cli/ui.ts +0 -52
- package/server/cli.ts +0 -3
- package/server/collab/cloudflare-access.ts +0 -78
- package/server/collab/config.ts +0 -13
- package/server/collab/manager.ts +0 -413
- package/server/collab/service.ts +0 -136
- package/server/collab/skill/index.ts +0 -7
- package/server/collab/worker-messages.ts +0 -10
- package/server/collab/worker.ts +0 -52
- package/server/constants.ts +0 -13
- package/server/control-client.ts +0 -124
- package/server/control.ts +0 -572
- package/server/data-dir.ts +0 -22
- package/server/debug.ts +0 -10
- package/server/events.ts +0 -25
- package/server/harness/README.md +0 -381
- package/server/harness/acp/NOTES.md +0 -426
- package/server/harness/acp/adapter.ts +0 -206
- package/server/harness/acp/archived.ts +0 -88
- package/server/harness/acp/client.ts +0 -329
- package/server/harness/acp/discovery.ts +0 -127
- package/server/harness/acp/model-state.ts +0 -57
- package/server/harness/acp/run-durations.ts +0 -68
- package/server/harness/acp/session.ts +0 -786
- package/server/harness/acp/wire.ts +0 -132
- package/server/harness/auth.ts +0 -272
- package/server/harness/claude-code/NOTES.md +0 -651
- package/server/harness/claude-code/adapter.ts +0 -876
- package/server/harness/claude-code/auth.ts +0 -178
- package/server/harness/claude-code/cli.ts +0 -42
- package/server/harness/claude-code/git-worktree.ts +0 -35
- package/server/harness/claude-code/index.ts +0 -171
- package/server/harness/claude-code/mcp.ts +0 -152
- package/server/harness/claude-code/models.ts +0 -102
- package/server/harness/claude-code/permissions.ts +0 -34
- package/server/harness/claude-code/run-action.ts +0 -123
- package/server/harness/claude-code/session-title.ts +0 -104
- package/server/harness/claude-code/session.ts +0 -969
- package/server/harness/claude-code/sessions.ts +0 -153
- package/server/harness/codex/NOTES.md +0 -259
- package/server/harness/codex/adapter.ts +0 -633
- package/server/harness/codex/auth.ts +0 -140
- package/server/harness/codex/client.ts +0 -439
- package/server/harness/codex/connectors.ts +0 -92
- package/server/harness/codex/discovery.ts +0 -106
- package/server/harness/codex/index.ts +0 -107
- package/server/harness/codex/pagination.ts +0 -27
- package/server/harness/codex/permissions.ts +0 -80
- package/server/harness/codex/probe.ts +0 -183
- package/server/harness/codex/run-action.ts +0 -93
- package/server/harness/codex/session-title.ts +0 -147
- package/server/harness/codex/session.ts +0 -1196
- package/server/harness/codex/status.ts +0 -31
- package/server/harness/codex/thread-list.ts +0 -78
- package/server/harness/codex/transport.ts +0 -191
- package/server/harness/command.ts +0 -45
- package/server/harness/debug.ts +0 -57
- package/server/harness/detect.ts +0 -164
- package/server/harness/executable.ts +0 -125
- package/server/harness/fork.ts +0 -14
- package/server/harness/hermes/NOTES.md +0 -833
- package/server/harness/hermes/discovery.ts +0 -175
- package/server/harness/hermes/index.ts +0 -167
- package/server/harness/hermes/models.ts +0 -99
- package/server/harness/install.ts +0 -49
- package/server/harness/openclaw/NOTES.md +0 -749
- package/server/harness/openclaw/adapter.ts +0 -336
- package/server/harness/openclaw/compat.ts +0 -95
- package/server/harness/openclaw/cron-view.ts +0 -78
- package/server/harness/openclaw/discovery.ts +0 -456
- package/server/harness/openclaw/gateway.ts +0 -467
- package/server/harness/openclaw/index.ts +0 -125
- package/server/harness/openclaw/session.ts +0 -1512
- package/server/harness/openclaw/strip.ts +0 -184
- package/server/harness/openclaw/thinking.ts +0 -150
- package/server/harness/registry.ts +0 -39
- package/server/harness/run-action.ts +0 -85
- package/server/harness/session-title.ts +0 -59
- package/server/harness/shell-path.ts +0 -89
- package/server/harness/types.ts +0 -170
- package/server/navigation-relay.ts +0 -110
- package/server/onboarding/brief.ts +0 -29
- package/server/onboarding/ideas.ts +0 -48
- package/server/onboarding/jobs.ts +0 -291
- package/server/open-browser.ts +0 -7
- package/server/operations/commands.ts +0 -46
- package/server/operations/files.ts +0 -148
- package/server/operations/server.ts +0 -206
- package/server/remote/agent.ts +0 -103
- package/server/remote/broker-client.ts +0 -76
- package/server/remote/broker.ts +0 -81
- package/server/remote/client.ts +0 -725
- package/server/remote/errors.ts +0 -2
- package/server/remote/routes.ts +0 -121
- package/server/remote/workspace.ts +0 -34
- package/server/scratchpad/assets.ts +0 -258
- package/server/scratchpad/document.ts +0 -312
- package/server/scratchpad/executor.ts +0 -499
- package/server/scratchpad/relay.ts +0 -44
- package/server/scratchpad/shape-defaults.ts +0 -82
- package/server/server-cwd.ts +0 -23
- package/server/service.ts +0 -800
- package/server/sessions/archive.ts +0 -23
- package/server/sessions/attachment-message.ts +0 -95
- package/server/sessions/config.ts +0 -45
- package/server/sessions/lifecycle.ts +0 -19
- package/server/sessions/pending-views.ts +0 -158
- package/server/sessions/selected.ts +0 -113
- package/server/sessions/send-message.ts +0 -102
- package/server/sessions/store.ts +0 -54
- package/server/sessions/view-sessions.ts +0 -192
- package/server/skills/locations.ts +0 -82
- package/server/skills/lock.ts +0 -29
- package/server/skills/template.ts +0 -94
- package/server/skills/update.ts +0 -94
- package/server/skills/version.ts +0 -129
- package/server/skills/workspace.ts +0 -121
- package/server/state.ts +0 -40
- package/server/static.ts +0 -25
- package/server/status.ts +0 -110
- package/server/tldraw-package.d.ts +0 -4
- package/server/update.ts +0 -429
- package/server/uploads.ts +0 -290
- package/server/vendor.ts +0 -63
- package/server/version.ts +0 -41
- package/server/web.ts +0 -350
- package/server/workspace-state/file.ts +0 -181
- package/server/workspace-state/index.ts +0 -169
- package/server/workspace-state/lock.ts +0 -42
- package/server/workspace-state/types.ts +0 -16
- package/server/workspaces/api.ts +0 -24
- package/server/workspaces/change-harness.ts +0 -77
- package/server/workspaces/config.ts +0 -42
- package/server/workspaces/env-apply.ts +0 -20
- package/server/workspaces/env.ts +0 -424
- package/server/workspaces/harness-transition.ts +0 -29
- package/server/workspaces/icon.ts +0 -13
- package/server/workspaces/import.ts +0 -74
- package/server/workspaces/init.ts +0 -74
- package/server/workspaces/layout.ts +0 -190
- package/server/workspaces/preview.ts +0 -72
- package/server/workspaces/registry.ts +0 -330
- package/server/workspaces/required-env.ts +0 -19
- package/server/workspaces/scaffold.ts +0 -189
- package/server/workspaces/shared.ts +0 -74
- package/server/workspaces/tabs.ts +0 -35
- package/server/workspaces/theme.ts +0 -58
- package/tsconfig.json +0 -20
|
@@ -1,969 +0,0 @@
|
|
|
1
|
-
// One long-lived SDK query per session, with follow-ups queued in Moi.
|
|
2
|
-
//
|
|
3
|
-
// Dispatch waits for the preceding user turn to finish before applying the next
|
|
4
|
-
// message's settings. Pending messages survive subprocess replacement; running
|
|
5
|
-
// background tasks retain their process until they finish.
|
|
6
|
-
//
|
|
7
|
-
// The SDK persists history to disk. After eviction or a server restart, the
|
|
8
|
-
// next message resumes that history in a new process.
|
|
9
|
-
import {
|
|
10
|
-
prepareAttachmentMessage,
|
|
11
|
-
type PreparedAttachmentMessage
|
|
12
|
-
} from '../../sessions/attachment-message'
|
|
13
|
-
import { attachmentLabel } from '@/lib/moi-attachments'
|
|
14
|
-
import {
|
|
15
|
-
type Options,
|
|
16
|
-
type Query,
|
|
17
|
-
type SDKUserMessage,
|
|
18
|
-
query
|
|
19
|
-
} from '@anthropic-ai/claude-agent-sdk'
|
|
20
|
-
|
|
21
|
-
import { buildSessionTitleSource } from '../session-title'
|
|
22
|
-
import { ClaudeAdapter } from './adapter'
|
|
23
|
-
import { CLAUDE_APPROVAL_HOOKS } from './permissions'
|
|
24
|
-
import { claudeSessionExists } from './sessions'
|
|
25
|
-
import { generateClaudeSessionTitle, renameClaudeSessionIfUnchanged } from './session-title'
|
|
26
|
-
import type { Part } from '@/lib/format'
|
|
27
|
-
import type { SessionActivity } from '@/lib/types'
|
|
28
|
-
import { moiContextSystemReminder, renderMoiContext } from '@/lib/moi-context'
|
|
29
|
-
|
|
30
|
-
import { debug } from '../../debug'
|
|
31
|
-
import { tapWire } from '../debug'
|
|
32
|
-
import { broadcast } from '../../state'
|
|
33
|
-
import { hasSessionConfig, saveSessionConfig } from '../../sessions/config'
|
|
34
|
-
import { renameSessionReferences } from '../../sessions/lifecycle'
|
|
35
|
-
import { claudeCodeSpawn } from '../../agent-launcher'
|
|
36
|
-
import { resolveWorkspaceEnv } from '../../workspaces/env'
|
|
37
|
-
import { requireHarnessExecutable } from '../executable'
|
|
38
|
-
import type { SendMessageInput } from '../types'
|
|
39
|
-
|
|
40
|
-
// Claude supports only the original two speed modes.
|
|
41
|
-
type ClaudeSendMessageInput = Omit<SendMessageInput, 'speedMode'> & { fastMode: boolean }
|
|
42
|
-
|
|
43
|
-
// Media types Claude vision accepts; uploads.ts guarantees every image upload is
|
|
44
|
-
// normalized to one of these, so the cast on `media_type` below is sound.
|
|
45
|
-
type ImageMediaType = 'image/jpeg' | 'image/png' | 'image/gif' | 'image/webp'
|
|
46
|
-
|
|
47
|
-
type MessageContent = SDKUserMessage['message']['content']
|
|
48
|
-
|
|
49
|
-
// Only the native SDK block shape belongs to this harness.
|
|
50
|
-
export function buildUserMessage(message: PreparedAttachmentMessage): {
|
|
51
|
-
content: MessageContent
|
|
52
|
-
parts: Part[]
|
|
53
|
-
} {
|
|
54
|
-
const images = message.attachments.filter(
|
|
55
|
-
attachment => attachment.type === 'image' && 'data' in attachment
|
|
56
|
-
)
|
|
57
|
-
if (!images.length) return { content: message.text, parts: message.parts }
|
|
58
|
-
const blocks: Exclude<MessageContent, string> = images.map(image => ({
|
|
59
|
-
type: 'image',
|
|
60
|
-
source: {
|
|
61
|
-
type: 'base64',
|
|
62
|
-
media_type: image.mediaType as ImageMediaType,
|
|
63
|
-
data: image.data.toString('base64')
|
|
64
|
-
}
|
|
65
|
-
}))
|
|
66
|
-
blocks.push({ type: 'text', text: message.text })
|
|
67
|
-
return { content: blocks, parts: message.parts }
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Each live session owns a subprocess. Only idle sessions can be evicted.
|
|
71
|
-
const MAX_LIVE_SESSIONS = 8
|
|
72
|
-
const IDLE_TTL_MS = 5 * 60_000
|
|
73
|
-
|
|
74
|
-
// Older CLIs lack background-task snapshots. These task types outlive the turn;
|
|
75
|
-
// other types count only when their event explicitly marks them backgrounded.
|
|
76
|
-
const LEGACY_BG_TASK_TYPES = new Set(['local_bash', 'local_workflow'])
|
|
77
|
-
|
|
78
|
-
type InputQueue = {
|
|
79
|
-
iterator: AsyncGenerator<SDKUserMessage>
|
|
80
|
-
push: (content: MessageContent, uuid: NonNullable<SDKUserMessage['uuid']>) => void
|
|
81
|
-
clear: () => void
|
|
82
|
-
close: () => void
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
type PendingMessage = {
|
|
86
|
-
input: ClaudeSendMessageInput
|
|
87
|
-
content: MessageContent
|
|
88
|
-
titleSource: string
|
|
89
|
-
turnId: string
|
|
90
|
-
wireId: NonNullable<SDKUserMessage['uuid']>
|
|
91
|
-
label: string
|
|
92
|
-
resolve: () => void
|
|
93
|
-
reject: (error: Error) => void
|
|
94
|
-
completed: Promise<void>
|
|
95
|
-
complete: () => void
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// This queue outlives its subprocess. Register it before any async setup so
|
|
99
|
-
// concurrent first sends share one session, including across temp-id renames.
|
|
100
|
-
type SessionMessages = {
|
|
101
|
-
workspaceId: string
|
|
102
|
-
workspacePath: string
|
|
103
|
-
sessionId: string
|
|
104
|
-
isNew: boolean
|
|
105
|
-
pending: PendingMessage[]
|
|
106
|
-
active: PendingMessage | null
|
|
107
|
-
dispatching: boolean
|
|
108
|
-
stopping: boolean
|
|
109
|
-
publishedActivity: SessionActivity
|
|
110
|
-
live?: LiveSession
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
type LiveSession = {
|
|
114
|
-
messages: SessionMessages
|
|
115
|
-
workspaceId: string
|
|
116
|
-
workspacePath: string
|
|
117
|
-
workspaceEnv: Record<string, string>
|
|
118
|
-
sessionId: string // current real id (rekeyed on rename)
|
|
119
|
-
q: Query
|
|
120
|
-
adapter: ClaudeAdapter
|
|
121
|
-
input: InputQueue
|
|
122
|
-
abort: AbortController
|
|
123
|
-
// SDK activity, set optimistically to running when a prompt is dispatched.
|
|
124
|
-
activity: SessionActivity
|
|
125
|
-
// Without state events, the matching result is the turn-completion signal.
|
|
126
|
-
sawStateEvents: boolean
|
|
127
|
-
turnEnded: boolean
|
|
128
|
-
// The SDK's full set of background tasks, including subagents and ambient
|
|
129
|
-
// watchers. All retain their process; none alone makes the chat busy.
|
|
130
|
-
bgTasks: Set<string>
|
|
131
|
-
// Once this process emits a snapshot, task edges must never mutate its set:
|
|
132
|
-
// the SDK does not guarantee their ordering relative to snapshots.
|
|
133
|
-
sawBackgroundSnapshot: boolean
|
|
134
|
-
model: string | undefined
|
|
135
|
-
// Live flag settings; undefined effort inherits the provider default.
|
|
136
|
-
fastMode: boolean
|
|
137
|
-
effort: string | undefined
|
|
138
|
-
// `includePartialMessages` is fixed at creation, so changes require resume.
|
|
139
|
-
stream: boolean
|
|
140
|
-
// Rebuild before the next send, once this turn and background tasks finish.
|
|
141
|
-
staleCli: boolean
|
|
142
|
-
idleTimer: ReturnType<typeof setTimeout> | null
|
|
143
|
-
closed: boolean
|
|
144
|
-
// Introspection only (surfaced by /status) — not load-bearing.
|
|
145
|
-
createdAt: number
|
|
146
|
-
lastActivityAt: number
|
|
147
|
-
lastUserText: string | undefined
|
|
148
|
-
refreshSessionsOnResult: boolean
|
|
149
|
-
sessionTitleSource: string | undefined
|
|
150
|
-
sessionTitleAbort: AbortController | null
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const sessions = new Map<string, LiveSession>()
|
|
154
|
-
const messageQueues = new Map<string, SessionMessages>()
|
|
155
|
-
// `${workspaceId}:${tempId}` -> real session id. Follow-ups may still use the
|
|
156
|
-
// client's temporary id after the SDK has assigned the real one.
|
|
157
|
-
const aliases = new Map<string, string>()
|
|
158
|
-
|
|
159
|
-
function recKey(workspaceId: string, sessionId: string): string {
|
|
160
|
-
return `${workspaceId}:${sessionId}`
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Resolve the live-session key for a (workspaceId, sessionId), following a
|
|
164
|
-
// temp->real alias when the direct key isn't live.
|
|
165
|
-
function liveKey(workspaceId: string, sessionId: string): string {
|
|
166
|
-
const direct = recKey(workspaceId, sessionId)
|
|
167
|
-
if (sessions.has(direct)) return direct
|
|
168
|
-
const real = aliases.get(direct)
|
|
169
|
-
return real ? recKey(workspaceId, real) : direct
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Non-idle sessions across all workspaces, for the status snapshot.
|
|
173
|
-
export function getCCActiveSessions(): {
|
|
174
|
-
workspaceId: string
|
|
175
|
-
sessionId: string
|
|
176
|
-
activity: SessionActivity
|
|
177
|
-
}[] {
|
|
178
|
-
const out: { workspaceId: string; sessionId: string; activity: SessionActivity }[] = []
|
|
179
|
-
for (const messages of messageQueues.values()) {
|
|
180
|
-
const activity = messageActivity(messages)
|
|
181
|
-
if (activity !== 'idle') {
|
|
182
|
-
out.push({ workspaceId: messages.workspaceId, sessionId: messages.sessionId, activity })
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return out
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// Caps surfaced in /status so the numbers there are self-explanatory.
|
|
189
|
-
export const SESSION_LIMITS = { maxLive: MAX_LIVE_SESSIONS, idleTtlMs: IDLE_TTL_MS }
|
|
190
|
-
|
|
191
|
-
export type CCDebugSession = {
|
|
192
|
-
workspaceId: string
|
|
193
|
-
sessionId: string
|
|
194
|
-
model: string | undefined
|
|
195
|
-
fastMode: boolean
|
|
196
|
-
effort: string | undefined
|
|
197
|
-
stream: boolean
|
|
198
|
-
queuedMessages: number
|
|
199
|
-
staleCli: boolean
|
|
200
|
-
activity: SessionActivity
|
|
201
|
-
bgTasks: number
|
|
202
|
-
closed: boolean
|
|
203
|
-
hasIdleTimer: boolean
|
|
204
|
-
createdAt: number
|
|
205
|
-
lastActivityAt: number
|
|
206
|
-
lastUserText: string | undefined
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// Session diagnostics for /status.
|
|
210
|
-
export function getCCDebugSnapshot(): { sessions: CCDebugSession[]; aliases: number } {
|
|
211
|
-
return {
|
|
212
|
-
sessions: [...sessions.values()].map(s => ({
|
|
213
|
-
workspaceId: s.workspaceId,
|
|
214
|
-
sessionId: s.sessionId,
|
|
215
|
-
model: s.model,
|
|
216
|
-
fastMode: s.fastMode,
|
|
217
|
-
effort: s.effort,
|
|
218
|
-
stream: s.stream,
|
|
219
|
-
queuedMessages: s.messages.pending.length,
|
|
220
|
-
staleCli: s.staleCli,
|
|
221
|
-
activity: s.activity,
|
|
222
|
-
bgTasks: s.bgTasks.size,
|
|
223
|
-
closed: s.closed,
|
|
224
|
-
hasIdleTimer: s.idleTimer !== null,
|
|
225
|
-
createdAt: s.createdAt,
|
|
226
|
-
lastActivityAt: s.lastActivityAt,
|
|
227
|
-
lastUserText: s.lastUserText
|
|
228
|
-
})),
|
|
229
|
-
aliases: aliases.size
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// Waiting when empty keeps the SDK session open between prompts.
|
|
234
|
-
function createInputQueue(): InputQueue {
|
|
235
|
-
const buffer: SDKUserMessage[] = []
|
|
236
|
-
let wake: (() => void) | null = null
|
|
237
|
-
let closed = false
|
|
238
|
-
|
|
239
|
-
async function* gen(): AsyncGenerator<SDKUserMessage> {
|
|
240
|
-
while (true) {
|
|
241
|
-
if (buffer.length === 0) {
|
|
242
|
-
if (closed) return
|
|
243
|
-
await new Promise<void>(resolve => {
|
|
244
|
-
wake = resolve
|
|
245
|
-
})
|
|
246
|
-
if (closed && buffer.length === 0) return
|
|
247
|
-
}
|
|
248
|
-
while (buffer.length) yield buffer.shift()!
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
return {
|
|
253
|
-
iterator: gen(),
|
|
254
|
-
push(content: MessageContent, uuid: NonNullable<SDKUserMessage['uuid']>) {
|
|
255
|
-
buffer.push({
|
|
256
|
-
type: 'user',
|
|
257
|
-
uuid,
|
|
258
|
-
message: { role: 'user', content },
|
|
259
|
-
parent_tool_use_id: null
|
|
260
|
-
})
|
|
261
|
-
wake?.()
|
|
262
|
-
wake = null
|
|
263
|
-
},
|
|
264
|
-
clear() {
|
|
265
|
-
buffer.length = 0
|
|
266
|
-
},
|
|
267
|
-
close() {
|
|
268
|
-
closed = true
|
|
269
|
-
wake?.()
|
|
270
|
-
wake = null
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
function setActivity(s: LiveSession, activity: SessionActivity) {
|
|
276
|
-
s.activity = activity
|
|
277
|
-
publishMessageActivity(s.messages)
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
function messageActivity(messages: SessionMessages): SessionActivity {
|
|
281
|
-
const activity = messages.live?.activity ?? 'idle'
|
|
282
|
-
if (activity !== 'idle') return activity
|
|
283
|
-
return messages.active || messages.pending.length || messages.dispatching ? 'running' : 'idle'
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
function publishMessageActivity(messages: SessionMessages) {
|
|
287
|
-
const activity = messageActivity(messages)
|
|
288
|
-
if (messages.publishedActivity === activity) return
|
|
289
|
-
messages.publishedActivity = activity
|
|
290
|
-
broadcast(messages.workspaceId, {
|
|
291
|
-
type: 'session:status',
|
|
292
|
-
sessionId: messages.sessionId,
|
|
293
|
-
activity
|
|
294
|
-
})
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
function clearIdle(s: LiveSession) {
|
|
298
|
-
if (s.idleTimer) {
|
|
299
|
-
clearTimeout(s.idleTimer)
|
|
300
|
-
s.idleTimer = null
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
function armIdle(s: LiveSession) {
|
|
305
|
-
clearIdle(s)
|
|
306
|
-
s.idleTimer = setTimeout(() => {
|
|
307
|
-
if (s.activity !== 'idle' || s.messages.active || s.messages.dispatching) return
|
|
308
|
-
if (s.bgTasks.size > 0) {
|
|
309
|
-
// Eviction would kill the background tasks too.
|
|
310
|
-
debug(
|
|
311
|
-
`cc idle-keepalive ws=${s.workspaceId} session=${s.sessionId} bgTasks=${s.bgTasks.size}`
|
|
312
|
-
)
|
|
313
|
-
armIdle(s)
|
|
314
|
-
return
|
|
315
|
-
}
|
|
316
|
-
teardown(s)
|
|
317
|
-
}, IDLE_TTL_MS)
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
function teardown(s: LiveSession) {
|
|
321
|
-
if (s.closed) return
|
|
322
|
-
debug(`cc teardown ws=${s.workspaceId} session=${s.sessionId} activity=${s.activity}`)
|
|
323
|
-
// Terminal status first, while the session is still registered — the consume
|
|
324
|
-
// finally can't be relied on (a hung SDK iterator never reaches it).
|
|
325
|
-
setActivity(s, 'idle')
|
|
326
|
-
s.closed = true
|
|
327
|
-
clearIdle(s)
|
|
328
|
-
s.sessionTitleAbort?.abort()
|
|
329
|
-
s.sessionTitleAbort = null
|
|
330
|
-
s.input.close()
|
|
331
|
-
try {
|
|
332
|
-
s.q.close?.()
|
|
333
|
-
} catch {}
|
|
334
|
-
try {
|
|
335
|
-
s.abort.abort()
|
|
336
|
-
} catch {}
|
|
337
|
-
if (sessions.get(recKey(s.workspaceId, s.sessionId)) === s) {
|
|
338
|
-
sessions.delete(recKey(s.workspaceId, s.sessionId))
|
|
339
|
-
}
|
|
340
|
-
if (s.messages.live === s) s.messages.live = undefined
|
|
341
|
-
publishMessageActivity(s.messages)
|
|
342
|
-
forgetEmptyQueue(s.messages)
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
function forgetEmptyQueue(messages: SessionMessages) {
|
|
346
|
-
if (messages.live || messages.dispatching || messages.active || messages.pending.length) return
|
|
347
|
-
const key = recKey(messages.workspaceId, messages.sessionId)
|
|
348
|
-
if (messageQueues.get(key) === messages) messageQueues.delete(key)
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
function isCurrentLiveSession(s: LiveSession, abort: AbortController): boolean {
|
|
352
|
-
return (
|
|
353
|
-
!s.closed && !abort.signal.aborted && sessions.get(recKey(s.workspaceId, s.sessionId)) === s
|
|
354
|
-
)
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
function startClaudeSessionTitleJob(s: LiveSession) {
|
|
358
|
-
if (!s.sessionTitleSource || s.closed) return
|
|
359
|
-
const source = s.sessionTitleSource
|
|
360
|
-
s.sessionTitleSource = undefined
|
|
361
|
-
const abort = new AbortController()
|
|
362
|
-
s.sessionTitleAbort = abort
|
|
363
|
-
|
|
364
|
-
void (async () => {
|
|
365
|
-
try {
|
|
366
|
-
const title = await generateClaudeSessionTitle({
|
|
367
|
-
source,
|
|
368
|
-
abortController: abort
|
|
369
|
-
})
|
|
370
|
-
if (!title || !isCurrentLiveSession(s, abort)) return
|
|
371
|
-
|
|
372
|
-
const renamed = await renameClaudeSessionIfUnchanged({
|
|
373
|
-
sessionId: s.sessionId,
|
|
374
|
-
workspacePath: s.workspacePath,
|
|
375
|
-
title,
|
|
376
|
-
isCurrent: () => isCurrentLiveSession(s, abort)
|
|
377
|
-
})
|
|
378
|
-
if (!renamed || !isCurrentLiveSession(s, abort)) return
|
|
379
|
-
broadcast(s.workspaceId, { type: 'sessions:changed', sessionId: s.sessionId })
|
|
380
|
-
debug(
|
|
381
|
-
`cc session title ws=${s.workspaceId} session=${s.sessionId} title=${JSON.stringify(title)}`
|
|
382
|
-
)
|
|
383
|
-
} catch (err) {
|
|
384
|
-
debug(
|
|
385
|
-
`cc session title failed ws=${s.workspaceId} session=${s.sessionId}: ${err instanceof Error ? err.message : String(err)}`
|
|
386
|
-
)
|
|
387
|
-
} finally {
|
|
388
|
-
if (s.sessionTitleAbort === abort) s.sessionTitleAbort = null
|
|
389
|
-
}
|
|
390
|
-
})()
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
// Move both registries to the SDK's real id, preserving the temporary alias.
|
|
394
|
-
function renameSession(s: LiveSession, realId: string): string {
|
|
395
|
-
const from = s.sessionId
|
|
396
|
-
sessions.delete(recKey(s.workspaceId, from))
|
|
397
|
-
s.sessionId = realId
|
|
398
|
-
sessions.set(recKey(s.workspaceId, realId), s)
|
|
399
|
-
aliases.set(recKey(s.workspaceId, from), realId)
|
|
400
|
-
messageQueues.delete(recKey(s.workspaceId, from))
|
|
401
|
-
s.messages.sessionId = realId
|
|
402
|
-
s.messages.isNew = false
|
|
403
|
-
messageQueues.set(recKey(s.workspaceId, realId), s.messages)
|
|
404
|
-
return from
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
// Keep the active message reserved across async bookkeeping. Sends arriving
|
|
408
|
-
// here join Moi's queue; they cannot race a teardown or change the live model.
|
|
409
|
-
async function onSessionIdle(s: LiveSession) {
|
|
410
|
-
const active = s.messages.active
|
|
411
|
-
if (s.messages.dispatching || (active && !s.turnEnded)) return
|
|
412
|
-
if (s.closed || s.messages.dispatching || s.messages.active !== active) return
|
|
413
|
-
active?.complete()
|
|
414
|
-
s.messages.active = null
|
|
415
|
-
setActivity(s, 'idle')
|
|
416
|
-
armIdle(s)
|
|
417
|
-
void dispatchNextMessage(s.messages)
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
async function consume(s: LiveSession) {
|
|
421
|
-
try {
|
|
422
|
-
for await (const msg of s.q) {
|
|
423
|
-
if (s.closed) break
|
|
424
|
-
tapWire(s.workspaceId, 'recv', msg)
|
|
425
|
-
if (msg.type === 'system' && msg.subtype === 'init') {
|
|
426
|
-
s.messages.isNew = false
|
|
427
|
-
const realId = msg.session_id
|
|
428
|
-
if (realId && realId !== s.sessionId) {
|
|
429
|
-
const from = renameSession(s, realId)
|
|
430
|
-
await renameSessionReferences(
|
|
431
|
-
{ id: s.workspaceId, path: s.workspacePath },
|
|
432
|
-
from,
|
|
433
|
-
s.sessionId
|
|
434
|
-
)
|
|
435
|
-
}
|
|
436
|
-
startClaudeSessionTitleJob(s)
|
|
437
|
-
// Seed explicit startup settings only when no saved picker choice exists.
|
|
438
|
-
if (!(await hasSessionConfig({ id: s.workspaceId, path: s.workspacePath }, s.sessionId))) {
|
|
439
|
-
await saveSessionConfig({ id: s.workspaceId, path: s.workspacePath }, s.sessionId, {
|
|
440
|
-
model: s.model,
|
|
441
|
-
effort: s.effort,
|
|
442
|
-
speedMode: s.fastMode ? 'fast' : 'normal'
|
|
443
|
-
})
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
for (const ev of s.adapter.ingest(msg)) {
|
|
447
|
-
if (ev.kind === 'preview') {
|
|
448
|
-
// Token previews are transient and stay outside transcript history.
|
|
449
|
-
broadcast(s.workspaceId, {
|
|
450
|
-
type: 'session:preview',
|
|
451
|
-
sessionId: s.sessionId,
|
|
452
|
-
messageId: ev.preview.messageId,
|
|
453
|
-
parentToolUseId: ev.preview.parentToolUseId,
|
|
454
|
-
blocks: ev.preview.blocks
|
|
455
|
-
})
|
|
456
|
-
} else {
|
|
457
|
-
broadcast(s.workspaceId, { ...ev, sessionId: s.sessionId })
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
if (msg.type === 'system' && msg.subtype === 'init') {
|
|
461
|
-
debug(`cc init ws=${s.workspaceId} session=${s.sessionId}`)
|
|
462
|
-
}
|
|
463
|
-
// Background notifications can start an SDK turn without a user send.
|
|
464
|
-
if ((msg.type === 'assistant' || msg.type === 'stream_event') && s.activity === 'idle') {
|
|
465
|
-
setActivity(s, 'running')
|
|
466
|
-
}
|
|
467
|
-
// Prefer explicit idle events when available; otherwise use the result
|
|
468
|
-
// fallback below. Some CLIs omit these events in streaming-input mode.
|
|
469
|
-
if (msg.type === 'system' && msg.subtype === 'session_state_changed') {
|
|
470
|
-
s.sawStateEvents = true
|
|
471
|
-
s.lastActivityAt = Date.now()
|
|
472
|
-
debug(`cc state ws=${s.workspaceId} session=${s.sessionId} state=${msg.state}`)
|
|
473
|
-
if (msg.state === 'running') setActivity(s, 'running')
|
|
474
|
-
else if (msg.state === 'requires_action') setActivity(s, 'requires-action')
|
|
475
|
-
else if (msg.state === 'idle') {
|
|
476
|
-
await onSessionIdle(s)
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
// Snapshots replace the entire set, healing missed starts/completions.
|
|
480
|
-
// Keep the edge-based fallback only until this process sends a snapshot.
|
|
481
|
-
if (msg.type === 'system') {
|
|
482
|
-
let tasksChanged = false
|
|
483
|
-
if (msg.subtype === 'background_tasks_changed') {
|
|
484
|
-
s.sawBackgroundSnapshot = true
|
|
485
|
-
s.bgTasks = new Set(msg.tasks.map(task => task.task_id))
|
|
486
|
-
tasksChanged = true
|
|
487
|
-
} else if (!s.sawBackgroundSnapshot) {
|
|
488
|
-
if (
|
|
489
|
-
msg.subtype === 'task_started' &&
|
|
490
|
-
(msg.is_backgrounded || LEGACY_BG_TASK_TYPES.has(msg.task_type ?? ''))
|
|
491
|
-
) {
|
|
492
|
-
s.bgTasks.add(msg.task_id)
|
|
493
|
-
} else if (msg.subtype === 'task_notification') {
|
|
494
|
-
tasksChanged = s.bgTasks.delete(msg.task_id)
|
|
495
|
-
} else if (msg.subtype === 'task_updated') {
|
|
496
|
-
const status = msg.patch.status
|
|
497
|
-
if (
|
|
498
|
-
status === 'completed' ||
|
|
499
|
-
status === 'failed' ||
|
|
500
|
-
status === 'killed' ||
|
|
501
|
-
msg.patch.is_backgrounded === false
|
|
502
|
-
) {
|
|
503
|
-
tasksChanged = s.bgTasks.delete(msg.task_id)
|
|
504
|
-
} else if (msg.patch.is_backgrounded) {
|
|
505
|
-
s.bgTasks.add(msg.task_id)
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
if (tasksChanged) {
|
|
510
|
-
debug(`cc bg-tasks ws=${s.workspaceId} session=${s.sessionId} live=${s.bgTasks.size}`)
|
|
511
|
-
void dispatchNextMessage(s.messages)
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
if (msg.type === 'result') {
|
|
515
|
-
// Newer CLIs identify the user messages consumed by a result. An
|
|
516
|
-
// autonomous background turn can finish while our prompt is still
|
|
517
|
-
// waiting inside the CLI; its result must not release that prompt.
|
|
518
|
-
const active = s.messages.active
|
|
519
|
-
const consumed =
|
|
520
|
-
msg.user_message_uuids ?? (msg.user_message_uuid ? [msg.user_message_uuid] : undefined)
|
|
521
|
-
const turnFinished =
|
|
522
|
-
!active || (!msg.queued_turn_count && (!consumed || consumed.includes(active.wireId)))
|
|
523
|
-
if (turnFinished) s.turnEnded = true
|
|
524
|
-
s.lastActivityAt = Date.now()
|
|
525
|
-
debug(`cc result ws=${s.workspaceId} session=${s.sessionId} subtype=${msg.subtype}`)
|
|
526
|
-
if (s.refreshSessionsOnResult) {
|
|
527
|
-
s.refreshSessionsOnResult = false
|
|
528
|
-
broadcast(s.workspaceId, { type: 'sessions:changed', sessionId: s.sessionId })
|
|
529
|
-
}
|
|
530
|
-
// Without state events, only a result that finishes the active prompt
|
|
531
|
-
// (or an autonomous turn when none is active) can release the queue.
|
|
532
|
-
if (!s.sawStateEvents && turnFinished) {
|
|
533
|
-
await onSessionIdle(s)
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
} catch (err) {
|
|
538
|
-
debug(
|
|
539
|
-
`cc consume error ws=${s.workspaceId} session=${s.sessionId}: ${err instanceof Error ? `${err.name}: ${err.message}` : String(err)}`
|
|
540
|
-
)
|
|
541
|
-
if (!(err instanceof Error && err.name === 'AbortError')) {
|
|
542
|
-
const message = err instanceof Error ? err.message : 'Unknown error'
|
|
543
|
-
broadcast(s.workspaceId, {
|
|
544
|
-
kind: 'error',
|
|
545
|
-
sessionId: s.sessionId,
|
|
546
|
-
content: message
|
|
547
|
-
})
|
|
548
|
-
}
|
|
549
|
-
} finally {
|
|
550
|
-
// An expected restart only replaces the subprocess. An unexpected exit
|
|
551
|
-
// cancels pending sends visibly rather than leaving their promises hanging.
|
|
552
|
-
if (!s.closed) {
|
|
553
|
-
const error = new Error('Agent session closed before queued messages were sent')
|
|
554
|
-
if (s.messages.pending.length)
|
|
555
|
-
broadcast(s.workspaceId, { kind: 'error', sessionId: s.sessionId, content: error.message })
|
|
556
|
-
cancelPendingMessages(s.messages, error)
|
|
557
|
-
s.messages.active?.complete()
|
|
558
|
-
s.messages.active = null
|
|
559
|
-
}
|
|
560
|
-
teardown(s)
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
function cancelPendingMessages(messages: SessionMessages, error: Error) {
|
|
565
|
-
for (const message of messages.pending.splice(0)) {
|
|
566
|
-
message.reject(error)
|
|
567
|
-
message.complete()
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
// Close one idle session to stay under the cap. A running session — or one
|
|
572
|
-
// with live background tasks — is never evicted; if everything is busy we allow
|
|
573
|
-
// a temporary overflow rather than killing a run.
|
|
574
|
-
function evictIfNeeded() {
|
|
575
|
-
if (sessions.size < MAX_LIVE_SESSIONS) return
|
|
576
|
-
for (const s of sessions.values()) {
|
|
577
|
-
if (
|
|
578
|
-
s.activity === 'idle' &&
|
|
579
|
-
s.bgTasks.size === 0 &&
|
|
580
|
-
!s.messages.dispatching &&
|
|
581
|
-
!s.messages.active &&
|
|
582
|
-
s.messages.pending.length === 0
|
|
583
|
-
) {
|
|
584
|
-
teardown(s)
|
|
585
|
-
return
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
function createLiveSession(input: {
|
|
591
|
-
messages: SessionMessages
|
|
592
|
-
workspaceId: string
|
|
593
|
-
workspacePath: string
|
|
594
|
-
sessionId: string
|
|
595
|
-
isNew: boolean
|
|
596
|
-
model: string | undefined
|
|
597
|
-
effort: string | undefined
|
|
598
|
-
fastMode: boolean
|
|
599
|
-
stream: boolean
|
|
600
|
-
// Resolved workspace env, fixed for the lifetime of the subprocess.
|
|
601
|
-
workspaceEnv: Record<string, string>
|
|
602
|
-
sessionTitleSource: string | undefined
|
|
603
|
-
}): LiveSession {
|
|
604
|
-
evictIfNeeded()
|
|
605
|
-
|
|
606
|
-
const queue = createInputQueue()
|
|
607
|
-
const abort = new AbortController()
|
|
608
|
-
const options: Options = {
|
|
609
|
-
abortController: abort,
|
|
610
|
-
pathToClaudeCodeExecutable: requireHarnessExecutable('claude-code'),
|
|
611
|
-
spawnClaudeCodeProcess: claudeCodeSpawn(),
|
|
612
|
-
// One query spans many user messages.
|
|
613
|
-
maxTurns: 1000,
|
|
614
|
-
cwd: input.workspacePath,
|
|
615
|
-
// Request summaries explicitly; some models otherwise omit thinking text.
|
|
616
|
-
thinking: { type: 'adaptive', display: 'summarized' },
|
|
617
|
-
...(input.model ? { model: input.model } : {}),
|
|
618
|
-
// Harness-neutral settings are strings; the picker supplies this model's
|
|
619
|
-
// supported effort levels from the SDK catalog.
|
|
620
|
-
...(input.effort ? { effort: input.effort as Options['effort'] } : {}),
|
|
621
|
-
settings: { fastMode: input.fastMode },
|
|
622
|
-
// Partial frames enable the opt-in live preview.
|
|
623
|
-
includePartialMessages: input.stream,
|
|
624
|
-
permissionMode: 'auto',
|
|
625
|
-
// Every tool call is approved before the permission system runs — see
|
|
626
|
-
// `permissions.ts`. `canUseTool` stays as the fallback for anything that
|
|
627
|
-
// reaches a prompt without passing through `PreToolUse`.
|
|
628
|
-
hooks: CLAUDE_APPROVAL_HOOKS,
|
|
629
|
-
canUseTool: async (_toolName, toolInput) => ({ behavior: 'allow', updatedInput: toolInput }),
|
|
630
|
-
settingSources: ['user', 'project'],
|
|
631
|
-
// MOI_AGENT marks every shell this session spawns as agent-driven (the
|
|
632
|
-
// moi CLI reads it — see agent-caller.ts), surviving the CLAUDECODE strip.
|
|
633
|
-
env: { ...process.env, ...input.workspaceEnv, CLAUDECODE: undefined, MOI_AGENT: '1' },
|
|
634
|
-
stderr: (data: string) => console.error('[SDK stderr]', data)
|
|
635
|
-
}
|
|
636
|
-
if (!input.isNew) options.resume = input.sessionId
|
|
637
|
-
|
|
638
|
-
const session: LiveSession = {
|
|
639
|
-
messages: input.messages,
|
|
640
|
-
workspaceId: input.workspaceId,
|
|
641
|
-
workspacePath: input.workspacePath,
|
|
642
|
-
workspaceEnv: input.workspaceEnv,
|
|
643
|
-
sessionId: input.sessionId,
|
|
644
|
-
q: query({ prompt: queue.iterator, options }),
|
|
645
|
-
adapter: new ClaudeAdapter(),
|
|
646
|
-
input: queue,
|
|
647
|
-
abort,
|
|
648
|
-
activity: 'idle',
|
|
649
|
-
sawStateEvents: false,
|
|
650
|
-
turnEnded: false,
|
|
651
|
-
bgTasks: new Set(),
|
|
652
|
-
sawBackgroundSnapshot: false,
|
|
653
|
-
model: input.model,
|
|
654
|
-
fastMode: input.fastMode,
|
|
655
|
-
effort: input.effort,
|
|
656
|
-
stream: input.stream,
|
|
657
|
-
staleCli: false,
|
|
658
|
-
idleTimer: null,
|
|
659
|
-
closed: false,
|
|
660
|
-
createdAt: Date.now(),
|
|
661
|
-
lastActivityAt: Date.now(),
|
|
662
|
-
lastUserText: undefined,
|
|
663
|
-
refreshSessionsOnResult: input.isNew,
|
|
664
|
-
sessionTitleSource: input.sessionTitleSource,
|
|
665
|
-
sessionTitleAbort: null
|
|
666
|
-
}
|
|
667
|
-
sessions.set(recKey(session.workspaceId, session.sessionId), session)
|
|
668
|
-
input.messages.live = session
|
|
669
|
-
debug(
|
|
670
|
-
`cc create ${input.isNew ? 'new' : 'resume'} ws=${input.workspaceId} session=${input.sessionId} model=${input.model ?? 'default'} effort=${input.effort ?? 'default'} fast=${input.fastMode} live=${sessions.size}`
|
|
671
|
-
)
|
|
672
|
-
void consume(session)
|
|
673
|
-
return session
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
// Accept immediately, but keep the prompt and its settings in Moi until its
|
|
677
|
-
// turn starts. The returned promise settles when the message reaches the SDK.
|
|
678
|
-
export async function sendCCMessage(incoming: SendMessageInput): Promise<void> {
|
|
679
|
-
const input: ClaudeSendMessageInput = {
|
|
680
|
-
...incoming,
|
|
681
|
-
fastMode: incoming.speedMode === 'fast'
|
|
682
|
-
}
|
|
683
|
-
const prepared = prepareAttachmentMessage(input.workspaceId, input.content, input.attachments)
|
|
684
|
-
if (!prepared.text) return
|
|
685
|
-
const { content: userContent, parts } = buildUserMessage(prepared)
|
|
686
|
-
// Keep context in its own block: the SDK skips tag-leading blocks when
|
|
687
|
-
// extracting titles and previews, and the adapter strips them on replay.
|
|
688
|
-
const content: MessageContent = input.context
|
|
689
|
-
? [
|
|
690
|
-
{ type: 'text', text: moiContextSystemReminder(renderMoiContext(input.context)) },
|
|
691
|
-
...(typeof userContent === 'string'
|
|
692
|
-
? [{ type: 'text' as const, text: userContent }]
|
|
693
|
-
: userContent)
|
|
694
|
-
]
|
|
695
|
-
: userContent
|
|
696
|
-
|
|
697
|
-
const key = liveKey(input.workspaceId, input.sessionId)
|
|
698
|
-
let messages = messageQueues.get(key)
|
|
699
|
-
if (!messages) {
|
|
700
|
-
messages = {
|
|
701
|
-
workspaceId: input.workspaceId,
|
|
702
|
-
workspacePath: input.workspacePath,
|
|
703
|
-
sessionId: aliases.get(recKey(input.workspaceId, input.sessionId)) ?? input.sessionId,
|
|
704
|
-
isNew: input.isNew && !aliases.has(recKey(input.workspaceId, input.sessionId)),
|
|
705
|
-
pending: [],
|
|
706
|
-
active: null,
|
|
707
|
-
dispatching: false,
|
|
708
|
-
stopping: false,
|
|
709
|
-
publishedActivity: 'idle'
|
|
710
|
-
}
|
|
711
|
-
messageQueues.set(key, messages)
|
|
712
|
-
}
|
|
713
|
-
const turnId = input.optimisticId ?? crypto.randomUUID()
|
|
714
|
-
broadcast(messages.workspaceId, {
|
|
715
|
-
kind: 'turn',
|
|
716
|
-
sessionId: messages.sessionId,
|
|
717
|
-
turn: {
|
|
718
|
-
id: turnId,
|
|
719
|
-
role: 'user',
|
|
720
|
-
origin: { kind: 'user-input' },
|
|
721
|
-
parts,
|
|
722
|
-
timestamp: new Date().toISOString()
|
|
723
|
-
}
|
|
724
|
-
})
|
|
725
|
-
const label = input.content || prepared.attachments.map(attachmentLabel).join(', ')
|
|
726
|
-
const completion = Promise.withResolvers<void>()
|
|
727
|
-
const accepted = new Promise<void>((resolve, reject) => {
|
|
728
|
-
messages.pending.push({
|
|
729
|
-
input,
|
|
730
|
-
content,
|
|
731
|
-
titleSource: buildSessionTitleSource(
|
|
732
|
-
input.content,
|
|
733
|
-
prepared.attachments.map(attachmentLabel)
|
|
734
|
-
),
|
|
735
|
-
turnId,
|
|
736
|
-
wireId: crypto.randomUUID(),
|
|
737
|
-
label: label.replace(/\s+/g, ' ').slice(0, 120),
|
|
738
|
-
resolve,
|
|
739
|
-
reject,
|
|
740
|
-
completed: completion.promise,
|
|
741
|
-
complete: completion.resolve
|
|
742
|
-
})
|
|
743
|
-
})
|
|
744
|
-
publishMessageActivity(messages)
|
|
745
|
-
void dispatchNextMessage(messages)
|
|
746
|
-
return accepted
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
// Serialize session creation, per-message settings, and prompt writes.
|
|
750
|
-
// Recheck cancellation and replacement after awaits before sending the prompt.
|
|
751
|
-
async function dispatchNextMessage(messages: SessionMessages): Promise<void> {
|
|
752
|
-
if (messages.dispatching || messages.stopping || messages.active) return
|
|
753
|
-
const message = messages.pending[0]
|
|
754
|
-
if (!message) {
|
|
755
|
-
forgetEmptyQueue(messages)
|
|
756
|
-
return
|
|
757
|
-
}
|
|
758
|
-
let s = messages.live
|
|
759
|
-
if (s && s.activity !== 'idle') return
|
|
760
|
-
const { input } = message
|
|
761
|
-
const stream = input.stream === true
|
|
762
|
-
const rebuild = s && (s.staleCli || stream !== s.stream)
|
|
763
|
-
// Background jobs belong to their subprocess. Retain both the job and the
|
|
764
|
-
// queued prompt until it is safe to resume with the requested configuration.
|
|
765
|
-
if (s && rebuild && s.bgTasks.size > 0) return
|
|
766
|
-
|
|
767
|
-
messages.dispatching = true
|
|
768
|
-
const cancelled = () => messages.stopping || messages.pending[0] !== message
|
|
769
|
-
try {
|
|
770
|
-
if (s && rebuild) {
|
|
771
|
-
teardown(s)
|
|
772
|
-
s = undefined
|
|
773
|
-
}
|
|
774
|
-
if (!s) {
|
|
775
|
-
const workspaceEnv = await resolveWorkspaceEnv(messages.workspacePath)
|
|
776
|
-
if (cancelled()) return
|
|
777
|
-
const isNew =
|
|
778
|
-
messages.isNew ||
|
|
779
|
-
!(await claudeSessionExists(messages.sessionId, messages.workspacePath, workspaceEnv))
|
|
780
|
-
if (cancelled()) return
|
|
781
|
-
s = createLiveSession({
|
|
782
|
-
messages,
|
|
783
|
-
workspaceId: messages.workspaceId,
|
|
784
|
-
workspacePath: messages.workspacePath,
|
|
785
|
-
sessionId: messages.sessionId,
|
|
786
|
-
isNew,
|
|
787
|
-
model: input.model,
|
|
788
|
-
effort: input.effort,
|
|
789
|
-
fastMode: input.fastMode,
|
|
790
|
-
stream,
|
|
791
|
-
workspaceEnv,
|
|
792
|
-
sessionTitleSource: isNew ? message.titleSource : undefined
|
|
793
|
-
})
|
|
794
|
-
} else {
|
|
795
|
-
clearIdle(s)
|
|
796
|
-
// A failed setter must reject this send, never silently use the previous
|
|
797
|
-
// model or flags. Later queued messages can still use the healthy query.
|
|
798
|
-
if (input.model !== s.model) {
|
|
799
|
-
await s.q.setModel(input.model)
|
|
800
|
-
// Stop cancels the prompt, not a control request already acknowledged
|
|
801
|
-
// by the CLI. Remember the applied value so the next send can reset it.
|
|
802
|
-
if (!s.closed) s.model = input.model
|
|
803
|
-
if (cancelled()) return
|
|
804
|
-
if (s.closed) throw new Error('Agent session closed before the message was sent')
|
|
805
|
-
}
|
|
806
|
-
if (input.effort !== s.effort || input.fastMode !== s.fastMode) {
|
|
807
|
-
await s.q.applyFlagSettings({
|
|
808
|
-
...(input.effort !== s.effort
|
|
809
|
-
? { effortLevel: (input.effort as Options['effort']) ?? null }
|
|
810
|
-
: {}),
|
|
811
|
-
...(input.fastMode !== s.fastMode ? { fastMode: input.fastMode } : {})
|
|
812
|
-
})
|
|
813
|
-
if (!s.closed) {
|
|
814
|
-
s.effort = input.effort
|
|
815
|
-
s.fastMode = input.fastMode
|
|
816
|
-
}
|
|
817
|
-
if (cancelled()) return
|
|
818
|
-
if (s.closed) throw new Error('Agent session closed before the message was sent')
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
if (cancelled()) return
|
|
822
|
-
if (s.closed) throw new Error('Agent session closed before the message was sent')
|
|
823
|
-
// A catalog refresh can arrive during any of the awaits above. Retry
|
|
824
|
-
// before handing off the prompt; the queue still owns it at this point.
|
|
825
|
-
if (s.staleCli) {
|
|
826
|
-
if (s.bgTasks.size === 0) teardown(s)
|
|
827
|
-
return
|
|
828
|
-
}
|
|
829
|
-
messages.pending.shift()
|
|
830
|
-
messages.active = message
|
|
831
|
-
s.turnEnded = false
|
|
832
|
-
s.lastActivityAt = Date.now()
|
|
833
|
-
s.lastUserText = message.label
|
|
834
|
-
s.adapter.expectUserEcho(message.turnId, input.content)
|
|
835
|
-
setActivity(s, 'running')
|
|
836
|
-
clearIdle(s)
|
|
837
|
-
s.input.push(message.content, message.wireId)
|
|
838
|
-
tapWire(s.workspaceId, 'send', { type: 'user', content: message.content })
|
|
839
|
-
message.resolve()
|
|
840
|
-
} catch (error) {
|
|
841
|
-
if (!cancelled() && s?.staleCli) {
|
|
842
|
-
if (!s.closed && s.bgTasks.size === 0) teardown(s)
|
|
843
|
-
return
|
|
844
|
-
}
|
|
845
|
-
if (!cancelled()) {
|
|
846
|
-
messages.pending.shift()
|
|
847
|
-
const err = error instanceof Error ? error : new Error(String(error))
|
|
848
|
-
broadcast(messages.workspaceId, {
|
|
849
|
-
kind: 'error',
|
|
850
|
-
sessionId: messages.sessionId,
|
|
851
|
-
content: err.message
|
|
852
|
-
})
|
|
853
|
-
message.reject(err)
|
|
854
|
-
message.complete()
|
|
855
|
-
}
|
|
856
|
-
} finally {
|
|
857
|
-
messages.dispatching = false
|
|
858
|
-
publishMessageActivity(messages)
|
|
859
|
-
if (s && !s.closed && s.activity === 'idle') armIdle(s)
|
|
860
|
-
void dispatchNextMessage(messages)
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
// Bound both interrupt acknowledgement and turn completion.
|
|
865
|
-
const INTERRUPT_TIMEOUT_MS = 5_000
|
|
866
|
-
|
|
867
|
-
// Cancel queued sends and interrupt the active turn. A failed or timed-out
|
|
868
|
-
// interrupt closes the process so the next send can resume in a fresh one.
|
|
869
|
-
export async function interruptCCSession(workspaceId: string, sessionId: string): Promise<void> {
|
|
870
|
-
const messages = messageQueues.get(liveKey(workspaceId, sessionId))
|
|
871
|
-
if (!messages) return
|
|
872
|
-
messages.stopping = true
|
|
873
|
-
cancelPendingMessages(messages, new Error('Message cancelled'))
|
|
874
|
-
const s = messages.live
|
|
875
|
-
if (!s) {
|
|
876
|
-
messages.stopping = false
|
|
877
|
-
publishMessageActivity(messages)
|
|
878
|
-
forgetEmptyQueue(messages)
|
|
879
|
-
broadcast(workspaceId, { kind: 'stopped', sessionId: messages.sessionId })
|
|
880
|
-
return
|
|
881
|
-
}
|
|
882
|
-
debug(`cc interrupt ws=${workspaceId} session=${sessionId} activity=${s.activity}`)
|
|
883
|
-
s.input.clear()
|
|
884
|
-
let timer: ReturnType<typeof setTimeout> | undefined
|
|
885
|
-
const timedOut = Symbol('interrupt-timeout')
|
|
886
|
-
const active = messages.active
|
|
887
|
-
try {
|
|
888
|
-
const outcome = await Promise.race([
|
|
889
|
-
(async () => {
|
|
890
|
-
await s.q.interrupt()
|
|
891
|
-
// Receipt and result are separate protocol messages. Bound both so a
|
|
892
|
-
// CLI that acknowledges Stop but never finishes cannot wedge the chat.
|
|
893
|
-
await active?.completed
|
|
894
|
-
})(),
|
|
895
|
-
new Promise(resolve => {
|
|
896
|
-
timer = setTimeout(() => resolve(timedOut), INTERRUPT_TIMEOUT_MS)
|
|
897
|
-
})
|
|
898
|
-
])
|
|
899
|
-
if (outcome === timedOut) {
|
|
900
|
-
debug(`cc interrupt timeout ws=${workspaceId} session=${sessionId} — tearing down`)
|
|
901
|
-
teardown(s)
|
|
902
|
-
}
|
|
903
|
-
} catch (err) {
|
|
904
|
-
console.error('[cc-session] interrupt failed', err)
|
|
905
|
-
teardown(s)
|
|
906
|
-
} finally {
|
|
907
|
-
clearTimeout(timer)
|
|
908
|
-
if (s.closed) {
|
|
909
|
-
active?.complete()
|
|
910
|
-
messages.active = null
|
|
911
|
-
}
|
|
912
|
-
messages.stopping = false
|
|
913
|
-
}
|
|
914
|
-
broadcast(s.workspaceId, { kind: 'stopped', sessionId: s.sessionId })
|
|
915
|
-
if (!messages.active) setActivity(s, 'idle')
|
|
916
|
-
if (!s.closed && !messages.active) armIdle(s)
|
|
917
|
-
void dispatchNextMessage(messages)
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
// Evict idle sessions so their next send picks up fresh workspace env. Busy
|
|
921
|
-
// sessions retain their environment until a later teardown.
|
|
922
|
-
export function restartWorkspaceSessions(workspacePath: string): void {
|
|
923
|
-
for (const s of [...sessions.values()]) {
|
|
924
|
-
if (
|
|
925
|
-
s.workspacePath === workspacePath &&
|
|
926
|
-
s.activity === 'idle' &&
|
|
927
|
-
s.bgTasks.size === 0 &&
|
|
928
|
-
!s.messages.dispatching &&
|
|
929
|
-
!s.messages.active &&
|
|
930
|
-
s.messages.pending.length === 0
|
|
931
|
-
)
|
|
932
|
-
teardown(s)
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
// Stop every queued message and subprocess for a workspace being removed.
|
|
937
|
-
export function killWorkspaceSessions(workspacePath: string): void {
|
|
938
|
-
for (const messages of messageQueues.values()) {
|
|
939
|
-
if (messages.workspacePath !== workspacePath) continue
|
|
940
|
-
messages.stopping = true
|
|
941
|
-
cancelPendingMessages(messages, new Error('Workspace removed'))
|
|
942
|
-
messages.active?.complete()
|
|
943
|
-
messages.active = null
|
|
944
|
-
}
|
|
945
|
-
for (const s of [...sessions.values()]) {
|
|
946
|
-
if (s.workspacePath === workspacePath) teardown(s)
|
|
947
|
-
}
|
|
948
|
-
for (const [key, messages] of messageQueues) {
|
|
949
|
-
if (messages.workspacePath === workspacePath) messageQueues.delete(key)
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
// A CLI update may introduce models the current process cannot use. Mark it
|
|
954
|
-
// for replacement at the next safe dispatch boundary.
|
|
955
|
-
export function retireCCSessionsOnCliChange(): void {
|
|
956
|
-
for (const s of sessions.values()) s.staleCli = true
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
// Server shutdown must settle pending sends and close every subprocess.
|
|
960
|
-
export function killAllCCSessions(): void {
|
|
961
|
-
for (const messages of messageQueues.values()) {
|
|
962
|
-
messages.stopping = true
|
|
963
|
-
cancelPendingMessages(messages, new Error('Agent sessions stopped'))
|
|
964
|
-
messages.active?.complete()
|
|
965
|
-
messages.active = null
|
|
966
|
-
}
|
|
967
|
-
for (const s of [...sessions.values()]) teardown(s)
|
|
968
|
-
messageQueues.clear()
|
|
969
|
-
}
|