@temmo/cli 0.0.0 → 0.19.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/.claude-plugin/marketplace.json +14 -0
- package/.claude-plugin/plugin.json +16 -0
- package/.codex-plugin/plugin.json +30 -0
- package/.cursor-plugin/plugin.json +22 -0
- package/.mcp.json +18 -0
- package/LICENSE +202 -0
- package/README.md +82 -2
- package/THIRD_PARTY_NOTICES +32 -0
- package/commands/afk.md +17 -0
- package/deploy/build-ui.mjs +65 -0
- package/deploy/claude/README.md +16 -0
- package/deploy/claude/auto-mode.json +31 -0
- package/deploy/postgres/compose.yaml +26 -0
- package/deploy/temmo-runner.service +24 -0
- package/deploy/verify-ui.mjs +15 -0
- package/harness-core/README.md +27 -0
- package/harness-core/bin/harness.mjs +17 -0
- package/harness-core/package.json +10 -0
- package/harness-core/stage.mjs +108 -0
- package/harness-core/stages/commit.md +7 -0
- package/harness-core/stages/pr.md +7 -0
- package/harness-core/stages/push.md +7 -0
- package/hooks/codex-hooks.json +14 -0
- package/hooks/cursor-hooks.json +17 -0
- package/hooks/hooks.json +27 -0
- package/lib/acp/permission.js +72 -0
- package/lib/acp/sessionConfig.js +109 -0
- package/lib/activity.js +244 -0
- package/lib/agent-guard.js +72 -0
- package/lib/agents-route.js +55 -0
- package/lib/agents.js +213 -0
- package/lib/agui.js +255 -0
- package/lib/alerts.js +36 -0
- package/lib/analyze-otlp.js +46 -0
- package/lib/analyze-run-code.js +397 -0
- package/lib/analyze-sources.js +372 -0
- package/lib/approval-card.js +54 -0
- package/lib/approval-cli.js +53 -0
- package/lib/approval-request.js +81 -0
- package/lib/approval-signer.js +48 -0
- package/lib/approvals.js +295 -0
- package/lib/attachment-cache.js +236 -0
- package/lib/attachment.js +63 -0
- package/lib/blocked.js +20 -0
- package/lib/build-review.js +90 -0
- package/lib/builder/cli.js +90 -0
- package/lib/builder/policy.js +176 -0
- package/lib/builder/recover.js +189 -0
- package/lib/builder/run.js +240 -0
- package/lib/builder/settle.js +198 -0
- package/lib/builder/stage.js +240 -0
- package/lib/builder/state.js +73 -0
- package/lib/builder/supervisor.js +289 -0
- package/lib/builder-clean.js +223 -0
- package/lib/builder-code.cjs +67 -0
- package/lib/builder.js +9 -0
- package/lib/bus-postgres.js +281 -0
- package/lib/bus.js +349 -0
- package/lib/catalog/author.js +278 -0
- package/lib/catalog/dot.js +426 -0
- package/lib/catalog/pattern-model.js +193 -0
- package/lib/catalog/patterns.js +324 -0
- package/lib/catalog/projects.js +83 -0
- package/lib/catalog/records.js +2 -0
- package/lib/catalog/roster.js +70 -0
- package/lib/catalog/team-files.js +49 -0
- package/lib/catalog/teams.js +109 -0
- package/lib/claude-socket.js +333 -0
- package/lib/cli.js +741 -0
- package/lib/code-mode.js +45 -0
- package/lib/code-read-policy.yaml +9 -0
- package/lib/code-run.js +461 -0
- package/lib/codex-compact.js +141 -0
- package/lib/compaction.js +21 -0
- package/lib/config.js +424 -0
- package/lib/cursor-trace.js +248 -0
- package/lib/deep-link.js +20 -0
- package/lib/deliver-push.js +120 -0
- package/lib/delivery.js +28 -0
- package/lib/deploy-tree.js +227 -0
- package/lib/durable.js +404 -0
- package/lib/factory-tick.js +32 -0
- package/lib/family.js +63 -0
- package/lib/fetch-origin.js +53 -0
- package/lib/format.js +133 -0
- package/lib/harness-surface-cli.js +153 -0
- package/lib/harness-surface.js +486 -0
- package/lib/harness.js +271 -0
- package/lib/hook.mjs +291 -0
- package/lib/idle.js +40 -0
- package/lib/install-cursor.js +115 -0
- package/lib/install-opencode.js +105 -0
- package/lib/job.js +82 -0
- package/lib/land-cli.js +319 -0
- package/lib/land-member.js +64 -0
- package/lib/land.js +320 -0
- package/lib/lessons.js +223 -0
- package/lib/limit-alert.js +423 -0
- package/lib/limits.js +284 -0
- package/lib/machine-prompt.js +19 -0
- package/lib/merge-sweep.js +149 -0
- package/lib/messaging.js +1002 -0
- package/lib/mission-cli.js +103 -0
- package/lib/mission.js +241 -0
- package/lib/mode.js +215 -0
- package/lib/models.js +114 -0
- package/lib/names.js +86 -0
- package/lib/opencode-api.js +57 -0
- package/lib/opencode-plugin.mjs +313 -0
- package/lib/operator-token.js +78 -0
- package/lib/operator.js +187 -0
- package/lib/pad-activity.js +143 -0
- package/lib/pad-fresh.js +44 -0
- package/lib/pad.js +198 -0
- package/lib/pattern-cli.js +120 -0
- package/lib/pattern-compiler.js +68 -0
- package/lib/pattern-runs.js +795 -0
- package/lib/pattern-stall.js +58 -0
- package/lib/pattern-tick.js +45 -0
- package/lib/pattern-workflow.js +69 -0
- package/lib/pi-extension.mjs +98 -0
- package/lib/pi.js +57 -0
- package/lib/plugin-copy.js +76 -0
- package/lib/pm-review.js +32 -0
- package/lib/pm-workspace.js +87 -0
- package/lib/postgres.js +115 -0
- package/lib/pr-card.js +34 -0
- package/lib/probe.js +295 -0
- package/lib/process.js +67 -0
- package/lib/project-pause.js +23 -0
- package/lib/prune.js +793 -0
- package/lib/questions.js +250 -0
- package/lib/receipts.js +63 -0
- package/lib/reflect.js +962 -0
- package/lib/rename-migration.js +118 -0
- package/lib/run-terminal.js +437 -0
- package/lib/runner-request.js +33 -0
- package/lib/sandbox-app.js +120 -0
- package/lib/sandbox-claims.js +258 -0
- package/lib/sandbox-cli.js +188 -0
- package/lib/sandbox-hosts-cli.js +68 -0
- package/lib/sandbox-hosts.js +94 -0
- package/lib/sandbox-pr.js +102 -0
- package/lib/sandbox-proposal.js +367 -0
- package/lib/sandbox-tools.js +143 -0
- package/lib/sandbox.js +501 -0
- package/lib/schedule-session.js +68 -0
- package/lib/session-activity.js +67 -0
- package/lib/session-events.js +94 -0
- package/lib/sessions/control.js +244 -0
- package/lib/sessions/git-refs.js +265 -0
- package/lib/sessions/launch.js +359 -0
- package/lib/sessions/registry.js +450 -0
- package/lib/sessions/scope.js +111 -0
- package/lib/setup.js +377 -0
- package/lib/signed-approval.js +225 -0
- package/lib/slash.js +167 -0
- package/lib/spawn-cli.js +45 -0
- package/lib/spawn.js +107 -0
- package/lib/start-limit.js +58 -0
- package/lib/state.js +24 -0
- package/lib/stop.js +308 -0
- package/lib/store-read.js +62 -0
- package/lib/store.js +252 -0
- package/lib/subagent-guard.js +240 -0
- package/lib/surfaces/channel-post.js +43 -0
- package/lib/surfaces/instructions.js +15 -0
- package/lib/surfaces/mcp-reload.js +144 -0
- package/lib/surfaces/ops.js +629 -0
- package/lib/surfaces/render-mcp.js +33 -0
- package/lib/surfaces/run-terminal-ops.js +40 -0
- package/lib/surfaces/sandbox-ops.js +36 -0
- package/lib/surfaces/schema.js +7 -0
- package/lib/surfaces/task-view.js +90 -0
- package/lib/surfaces/types.js +4 -0
- package/lib/task-cli.js +274 -0
- package/lib/task-order.js +34 -0
- package/lib/task-order.mjs +2 -0
- package/lib/task-route.js +125 -0
- package/lib/tasks.js +631 -0
- package/lib/team-permission.js +34 -0
- package/lib/team-templates/blitz/team.dot +9 -0
- package/lib/team-templates/factory/team.dot +26 -0
- package/lib/team-templates/feature/team.dot +14 -0
- package/lib/team-templates/fix-and-review/team.dot +12 -0
- package/lib/team-templates/product/team.dot +16 -0
- package/lib/team-templates/release/team.dot +7 -0
- package/lib/team-templates/review/team.dot +6 -0
- package/lib/terminal-draft.js +42 -0
- package/lib/thread-branch.js +82 -0
- package/lib/thread-channel-store.js +181 -0
- package/lib/thread-channels.js +116 -0
- package/lib/thread-listening.js +20 -0
- package/lib/thread-routes.js +91 -0
- package/lib/threads.js +441 -0
- package/lib/tool-api.js +33 -0
- package/lib/transcript.js +98 -0
- package/lib/ui-build-output.js +19 -0
- package/lib/ui-capabilities.js +90 -0
- package/lib/usage.js +182 -0
- package/lib/vendor/mcp-sdk.d.mts +4 -0
- package/lib/vendor/mcp-sdk.mjs +17046 -0
- package/lib/waiter.js +127 -0
- package/lib/workflows.js +546 -0
- package/lib/worktree-setup.js +86 -0
- package/package.json +112 -1
- package/runner/adapters/claude.js +465 -0
- package/runner/adapters/cli-sandbox.js +277 -0
- package/runner/adapters/codex.js +675 -0
- package/runner/adapters/cursor.mjs +937 -0
- package/runner/adapters/fake.js +119 -0
- package/runner/adapters/opencode-sandbox.js +370 -0
- package/runner/adapters/opencode.js +486 -0
- package/runner/adapters/pi-sandbox.js +134 -0
- package/runner/adapters/pi.js +364 -0
- package/runner/client.js +40 -0
- package/runner/contract.js +129 -0
- package/runner/control.js +178 -0
- package/runner/delivery.js +184 -0
- package/runner/factory-tick.mjs +10 -0
- package/runner/lock.js +41 -0
- package/runner/main.mjs +118 -0
- package/runner/pattern-tick.mjs +16 -0
- package/runner/publish.js +113 -0
- package/runner/runner.js +2612 -0
- package/runner/sandbox-run.mjs +239 -0
- package/runner/schedules.js +294 -0
- package/runner/task-wake.js +59 -0
- package/scripts/ai-collab +3 -0
- package/scripts/ai-collab-bus.mjs +4 -0
- package/scripts/ai-collab-code-mcp.mjs +3 -0
- package/scripts/ai-collab-hook +3 -0
- package/scripts/ai-collab-hook.mjs +3 -0
- package/scripts/ai-collab-mcp-tools.mjs +2 -0
- package/scripts/ai-collab-mcp.mjs +3 -0
- package/scripts/ai-collab.mjs +3 -0
- package/scripts/install-cursor.mjs +11 -0
- package/scripts/install-opencode.mjs +10 -0
- package/scripts/temmo +3 -0
- package/scripts/temmo-bus.mjs +151 -0
- package/scripts/temmo-code-mcp.mjs +63 -0
- package/scripts/temmo-hook +3 -0
- package/scripts/temmo-hook.mjs +201 -0
- package/scripts/temmo-mcp-tools.mjs +22 -0
- package/scripts/temmo-mcp.mjs +27 -0
- package/scripts/temmo.mjs +4 -0
- package/skills/antislop/SKILL.md +701 -0
- package/skills/antislop/VERSION +1 -0
- package/skills/antislop-code/SKILL.md +128 -0
- package/skills/antislop-human/LICENSE-web-quality-skills +21 -0
- package/skills/antislop-human/SKILL.md +204 -0
- package/skills/antislop-human/contrast-check.py +168 -0
- package/skills/antislop-human/contrast-mcp.py +125 -0
- package/skills/antislop-human/references/A11Y-PATTERNS.md +249 -0
- package/skills/antislop-human/references/WCAG.md +127 -0
- package/skills/antislop-layoutmobile/SKILL.md +170 -0
- package/skills/antislop-ui/LICENSE-web-quality-skills +21 -0
- package/skills/antislop-ui/SKILL.md +351 -0
- package/skills/antislop-ui/references/CORE-WEB-VITALS.md +181 -0
- package/skills/antislop-ui/references/WEB-BASELINE.md +28 -0
- package/skills/harness-surface/SKILL.md +42 -0
- package/skills/land/SKILL.md +32 -0
- package/skills/memory-file/SKILL.md +39 -0
- package/skills/temmo/SKILL.md +101 -0
- package/skills/temmo/references/role-programs.md +47 -0
- package/skills/ui-sdk/SKILL.md +56 -0
- package/skills/ui-sdk/references/agent-ready.md +136 -0
- package/skills/ui-sdk/references/build-interface.md +187 -0
- package/skills/ui-sdk/references/create-component.md +88 -0
- package/skills/ui-sdk/references/patterns.md +246 -0
- package/skills/ui-sdk/references/styles.md +66 -0
- package/skills/ui-sdk/references/testing.md +172 -0
- package/skills/ui-sdk/references/web-components.md +78 -0
- package/tools/screen-state.mjs +119 -0
- package/tools/smoke-ui.mjs +540 -0
- package/web/app/activity.jsx +251 -0
- package/web/app/agent-mark.tsx +43 -0
- package/web/app/alert-level.jsx +16 -0
- package/web/app/api/[action]/route.js +8 -0
- package/web/app/api/auth/[step]/route.js +12 -0
- package/web/app/api/events/route.js +8 -0
- package/web/app/api/file/[name]/route.js +8 -0
- package/web/app/api/land/route.js +12 -0
- package/web/app/api/lessons/route.js +8 -0
- package/web/app/api/push/key/route.js +8 -0
- package/web/app/api/push/subscribe/route.js +12 -0
- package/web/app/api/push/test/route.js +8 -0
- package/web/app/api/refs/route.js +8 -0
- package/web/app/api/review-diff/route.js +8 -0
- package/web/app/api/schedules/route.js +8 -0
- package/web/app/api/thread-diff/route.js +8 -0
- package/web/app/api/version/route.js +6 -0
- package/web/app/cards.jsx +189 -0
- package/web/app/chat-api.js +82 -0
- package/web/app/chat-composer.jsx +313 -0
- package/web/app/chat-console.jsx +691 -0
- package/web/app/chat-image.tsx +61 -0
- package/web/app/chat-message.jsx +122 -0
- package/web/app/chat-shared.jsx +59 -0
- package/web/app/chat-sidebar.jsx +25 -0
- package/web/app/chat-stream.js +127 -0
- package/web/app/chat.jsx +31 -0
- package/web/app/compactions.jsx +57 -0
- package/web/app/composer-actions.tsx +87 -0
- package/web/app/decisions.jsx +53 -0
- package/web/app/fonts/OFL-hanken-grotesk.txt +93 -0
- package/web/app/fonts/OFL-ibm-plex-mono.txt +93 -0
- package/web/app/fonts/hanken-grotesk-latin-wght-normal.woff2 +0 -0
- package/web/app/fonts/ibm-plex-mono-latin-400-normal.woff2 +0 -0
- package/web/app/fonts/ibm-plex-mono-latin-500-normal.woff2 +0 -0
- package/web/app/globals.css +199 -0
- package/web/app/home.jsx +246 -0
- package/web/app/icon.svg +1 -0
- package/web/app/land-panel.jsx +63 -0
- package/web/app/land-reviews.jsx +20 -0
- package/web/app/layout.jsx +17 -0
- package/web/app/lessons.tsx +76 -0
- package/web/app/logo.tsx +13 -0
- package/web/app/logos.jsx +16 -0
- package/web/app/manifest.js +8 -0
- package/web/app/mode-menu.tsx +46 -0
- package/web/app/new-session.jsx +275 -0
- package/web/app/notify.jsx +180 -0
- package/web/app/outcomes.tsx +94 -0
- package/web/app/page.jsx +9 -0
- package/web/app/pattern-graph.jsx +75 -0
- package/web/app/patterns-page.jsx +293 -0
- package/web/app/phone-nav.tsx +36 -0
- package/web/app/progress-feed.tsx +33 -0
- package/web/app/providers.tsx +27 -0
- package/web/app/quote.jsx +15 -0
- package/web/app/run-card.tsx +200 -0
- package/web/app/run-requests.tsx +148 -0
- package/web/app/scheduled.jsx +105 -0
- package/web/app/session-panel.tsx +174 -0
- package/web/app/session-toolbar.tsx +180 -0
- package/web/app/shadcn.css +638 -0
- package/web/app/shipped.jsx +49 -0
- package/web/app/subagent-runs.jsx +31 -0
- package/web/app/task-graph.jsx +67 -0
- package/web/app/tasks-strip.tsx +36 -0
- package/web/app/tasks.jsx +375 -0
- package/web/app/team-author.jsx +145 -0
- package/web/app/team-editor.jsx +88 -0
- package/web/app/thread-agents.tsx +32 -0
- package/web/app/thread-place.tsx +9 -0
- package/web/app/thread-sessions.tsx +149 -0
- package/web/app/thread-sidebar.tsx +418 -0
- package/web/app/thread-switcher.tsx +27 -0
- package/web/app/tool-diff.jsx +94 -0
- package/web/components/a2ui/controls.jsx +36 -0
- package/web/components/a2ui/option-picker.jsx +23 -0
- package/web/components/a2ui/script.tsx +121 -0
- package/web/components/a2ui/surface.jsx +81 -0
- package/web/components/chat/thread.jsx +50 -0
- package/web/components/script-text.tsx +42 -0
- package/web/components/ui/avatar.jsx +115 -0
- package/web/components/ui/badge.jsx +47 -0
- package/web/components/ui/button.jsx +63 -0
- package/web/components/ui/chat-container.jsx +52 -0
- package/web/components/ui/choice-list.tsx +72 -0
- package/web/components/ui/code-block.jsx +60 -0
- package/web/components/ui/copy-button.tsx +41 -0
- package/web/components/ui/dropdown-menu.jsx +257 -0
- package/web/components/ui/markdown.jsx +84 -0
- package/web/components/ui/message.jsx +28 -0
- package/web/components/ui/popover.jsx +33 -0
- package/web/components/ui/scroll-button.jsx +34 -0
- package/web/components/ui/select.jsx +189 -0
- package/web/components/ui/sheet.jsx +152 -0
- package/web/components/ui/sonner.jsx +10 -0
- package/web/components/ui/tabs.jsx +88 -0
- package/web/components/ui/textarea.jsx +20 -0
- package/web/components/ui/tooltip.jsx +56 -0
- package/web/components.json +24 -0
- package/web/instrumentation.js +8 -0
- package/web/lib/a2ui-catalog.js +34 -0
- package/web/lib/a2ui-pr.js +76 -0
- package/web/lib/a2ui-run-catalog.js +18 -0
- package/web/lib/a2ui-run.js +93 -0
- package/web/lib/a2ui.js +262 -0
- package/web/lib/activity-rows.js +275 -0
- package/web/lib/agent-detail.js +5 -0
- package/web/lib/alert-level.js +44 -0
- package/web/lib/approval-mode.js +22 -0
- package/web/lib/chat-turns.js +174 -0
- package/web/lib/child-subagents.js +16 -0
- package/web/lib/compaction-view.js +48 -0
- package/web/lib/composer-actions.js +40 -0
- package/web/lib/context-view.js +57 -0
- package/web/lib/fuzzy.js +26 -0
- package/web/lib/highlight.js +44 -0
- package/web/lib/lessons-view.js +23 -0
- package/web/lib/mentions.js +16 -0
- package/web/lib/message-routing.js +105 -0
- package/web/lib/new-session.js +85 -0
- package/web/lib/operator-messages.js +28 -0
- package/web/lib/pattern-graph.js +165 -0
- package/web/lib/pattern-view.js +33 -0
- package/web/lib/pending-summary.js +18 -0
- package/web/lib/permission-modes.js +30 -0
- package/web/lib/project-feed.js +107 -0
- package/web/lib/quote.js +7 -0
- package/web/lib/reply-quote.js +31 -0
- package/web/lib/scheduled.js +79 -0
- package/web/lib/selection.js +110 -0
- package/web/lib/send-confirmation.js +22 -0
- package/web/lib/session-dead.js +10 -0
- package/web/lib/session-state.js +132 -0
- package/web/lib/sidebar.js +15 -0
- package/web/lib/slash-commands.js +164 -0
- package/web/lib/start-default.js +35 -0
- package/web/lib/start-mode.js +35 -0
- package/web/lib/stream-views.js +49 -0
- package/web/lib/subagent-state.js +20 -0
- package/web/lib/task-board.js +54 -0
- package/web/lib/task-graph.js +183 -0
- package/web/lib/task-tags.js +41 -0
- package/web/lib/team-editor.js +10 -0
- package/web/lib/thread-groups.js +86 -0
- package/web/lib/threads.js +28 -0
- package/web/lib/tool-diff.js +273 -0
- package/web/lib/ui-events.js +58 -0
- package/web/lib/utils.js +5 -0
- package/web/lib/view-memory.js +25 -0
- package/web/next.config.mjs +37 -0
- package/web/postcss.config.mjs +1 -0
- package/web/proxy.js +25 -0
- package/web/public/sw.js +39 -0
- package/web/server/auth.js +178 -0
- package/web/server/dispatch.js +293 -0
- package/web/server/history.js +56 -0
- package/web/server/hosted.js +58 -0
- package/web/server/hub.js +126 -0
- package/web/server/instance.js +5 -0
- package/web/server/land-reviews.js +64 -0
- package/web/server/push.js +148 -0
- package/web/server/run-terminal.js +79 -0
- package/web/server/schedules.js +38 -0
- package/web/server/shipped.js +51 -0
- package/web/server/task-board.js +71 -0
- package/web/server/threads.js +209 -0
- package/web/server/ui.js +2937 -0
- package/web/tsconfig.base.json +16 -0
- package/web/tsconfig.json +9 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useContext, useState } from "react";
|
|
3
|
+
import { Check, CheckCheck, CircleHelp, GitPullRequest, ShieldQuestion, SkipForward, SquareTerminal, X } from "lucide-react";
|
|
4
|
+
import { Badge } from "@/components/ui/badge";
|
|
5
|
+
import { Button } from "@/components/ui/button";
|
|
6
|
+
import { MessageContent } from "@/components/ui/message";
|
|
7
|
+
import { Textarea } from "@/components/ui/textarea";
|
|
8
|
+
import { ChoiceList, ChoiceSummary } from "@/components/ui/choice-list";
|
|
9
|
+
import { Input } from "@ui-sdk/react/input";
|
|
10
|
+
import { cn } from "@/lib/utils";
|
|
11
|
+
import { ALWAYS_LABEL, allowLabel, BLOCKING_LABEL, IN_TERMINAL, SKIPPED, approvalOutcome, offersSessionGrant, isBlocking, approvalSurfaceId, questionText, questionSurfaceId, terminalHint } from "@/lib/a2ui";
|
|
12
|
+
import { prOutcome, prSurfaceId } from "@/lib/a2ui-pr";
|
|
13
|
+
import { CARD, Surface, SurfaceContext } from "@/components/a2ui/surface";
|
|
14
|
+
import { ModeMenu } from "./mode-menu";
|
|
15
|
+
import { ConfirmButton } from "./pattern-graph";
|
|
16
|
+
|
|
17
|
+
export { approvalOutcome };
|
|
18
|
+
|
|
19
|
+
/** AskUserQuestion questions: options as buttons (checkboxes when multiSelect), an Other field, one Submit; read-only without onSubmit. */
|
|
20
|
+
export function ChoiceCard({ questions, answers, onSubmit, disabled, title }) {
|
|
21
|
+
const [picked, setPicked] = useState(() => questions.map(() => []));
|
|
22
|
+
const [other, setOther] = useState(() => questions.map(() => ""));
|
|
23
|
+
const readOnly = !onSubmit || Boolean(answers);
|
|
24
|
+
const value = i => [...picked[i], ...(other[i].trim() ? [other[i].trim()] : [])].join(", ");
|
|
25
|
+
const complete = questions.every((_, i) => value(i));
|
|
26
|
+
function pick(i, next, multi) {
|
|
27
|
+
setPicked(list => list.map((items, j) => j === i ? next : items));
|
|
28
|
+
if (!multi) setOther(list => list.map((text, j) => j === i ? "" : text));
|
|
29
|
+
}
|
|
30
|
+
return <div className={cn(CARD, "flex flex-col gap-3")} data-card="choice">
|
|
31
|
+
{title && <p className="flex items-center gap-1.5 text-xs font-medium text-muted-foreground"><CircleHelp className="size-3.5"/>{title}</p>}
|
|
32
|
+
{questions.map((q, i) => {
|
|
33
|
+
const chosen = String(answers?.[q.question] ?? "");
|
|
34
|
+
const labels = chosen ? chosen.split(", ") : [];
|
|
35
|
+
const typed = labels.some(label => !q.options.some(o => o.label === label));
|
|
36
|
+
return <section key={q.question} className={cn("flex min-w-0 flex-col gap-2", i > 0 && "border-t pt-3")}>
|
|
37
|
+
{(q.header || questions.length > 1) && <div className="flex min-w-0 items-center justify-between gap-2">
|
|
38
|
+
{q.header && <Badge variant="secondary" className="min-h-5 max-w-full px-2 text-xs wrap-anywhere whitespace-normal">{q.header}</Badge>}
|
|
39
|
+
{questions.length > 1 && <span className="text-xs text-muted-foreground">{i + 1} of {questions.length}</span>}
|
|
40
|
+
</div>}
|
|
41
|
+
{readOnly ? <>
|
|
42
|
+
<ChoiceSummary question={q.question} chosen={labels.filter(label => q.options.some(o => o.label === label))}/>
|
|
43
|
+
{typed && <p className="text-sm">Answer: <span className="font-medium">{chosen}</span></p>}
|
|
44
|
+
{!answers && <ul className="flex list-disc flex-col gap-0.5 pl-5 text-sm text-muted-foreground">
|
|
45
|
+
{q.options.map(o => <li key={o.label} className="wrap-anywhere"><span className="text-foreground">{o.label}</span>{o.description && " · " + o.description}</li>)}
|
|
46
|
+
</ul>}
|
|
47
|
+
</> : <ChoiceList question={q.question} options={q.options} multiSelect={q.multiSelect === true} value={picked[i]} disabled={disabled}
|
|
48
|
+
onValueChange={next => pick(i, next, q.multiSelect === true)}>
|
|
49
|
+
<label className="flex min-w-0 flex-col gap-1 pt-0.5">
|
|
50
|
+
<span className="text-xs text-muted-foreground">Or write your own answer</span>
|
|
51
|
+
<Input aria-label={"Other answer: " + q.question} placeholder="Other answer" value={other[i]} disabled={disabled}
|
|
52
|
+
onValueChange={text => { setOther(list => list.map((v, j) => j === i ? text : v)); if (!q.multiSelect && text) setPicked(list => list.map((v, j) => j === i ? [] : v)); }}
|
|
53
|
+
className="h-11 w-full min-w-0 rounded-lg border border-input bg-background px-3 text-base text-foreground placeholder:text-muted-foreground sm:h-9 sm:text-sm"/>
|
|
54
|
+
</label>
|
|
55
|
+
</ChoiceList>}
|
|
56
|
+
</section>;
|
|
57
|
+
})}
|
|
58
|
+
{!readOnly && <div className="flex justify-end">
|
|
59
|
+
<Button className="h-11 rounded-md px-4 sm:h-8 sm:px-3.5" disabled={disabled || !complete}
|
|
60
|
+
onClick={() => onSubmit(Object.fromEntries(questions.map((q, i) => [q.question, value(i)])))}>Submit</Button>
|
|
61
|
+
</div>}
|
|
62
|
+
</div>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Dismisses an open decision without answering it; a waiting hook then leaves the harness's own prompt in charge. */
|
|
66
|
+
export function SkipButton({ disabled, onSkip }) {
|
|
67
|
+
return <Button size="sm" variant="ghost" className="self-start rounded-md text-muted-foreground" disabled={disabled} onClick={onSkip}><SkipForward/>Skip</Button>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** A permission request or choice an agent waits on: the A2UI surface when the stream sent one, else the card below; Skip while open. */
|
|
71
|
+
export function ApprovalCard({ skip, ...props }) {
|
|
72
|
+
const open = !approvalOutcome(props.approval, props.now);
|
|
73
|
+
// The A2UI surface draws its own Allow / Deny, so the mode menu sits in the row under it; the legacy card holds it inline.
|
|
74
|
+
const { surfaces, submit } = useContext(SurfaceContext);
|
|
75
|
+
const surfaced = Boolean(surfaces[approvalSurfaceId(props.approval.id)] && submit);
|
|
76
|
+
const modeMenu = surfaced && open && <CardModeMenu {...props}/>;
|
|
77
|
+
// A view-only card closes in the terminal, and a runner session has no terminal prompt to fall back on.
|
|
78
|
+
const skippable = skip && open && !props.approval.terminal && !props.approval.owned;
|
|
79
|
+
// A choice reads as a question; the chat message header above it already names the agent.
|
|
80
|
+
const count = props.approval.questions?.length ?? 0;
|
|
81
|
+
const kind = count > 1 ? count + " questions" : count ? "Question" : "Approval";
|
|
82
|
+
return <>
|
|
83
|
+
<Surface id={approvalSurfaceId(props.approval.id)} head={count ? undefined : props.head} kind={kind} open={open} fallback={<LegacyApprovalCard {...props}/>}/>
|
|
84
|
+
{modeMenu && <div className="flex justify-end">{modeMenu}</div>}
|
|
85
|
+
{skippable && <SkipButton disabled={props.disabled} onSkip={() => skip({ id: props.approval.id })}/>}
|
|
86
|
+
</>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** A permission request or choice an agent waits on: Allow / Deny (or the choice card) until it closes, then the outcome. */
|
|
90
|
+
/** The mode menu for an open runner-owned permission request, or null; setMode posts /mode to the session. */
|
|
91
|
+
function CardModeMenu({ approval, disabled, act, setMode }) {
|
|
92
|
+
const control = approval.modeControl;
|
|
93
|
+
if (!setMode || !control || approval.questions || approval.terminal) return null;
|
|
94
|
+
return <ModeMenu harness={approval.harness} control={control} disabled={disabled}
|
|
95
|
+
setMode={mode => setMode({ target: control.address, mode })} allow={() => act({ id: approval.id, decision: "allow" })}/>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function LegacyApprovalCard({ approval, now, disabled, act, setMode }) {
|
|
99
|
+
const outcome = approvalOutcome(approval, now);
|
|
100
|
+
const open = !outcome;
|
|
101
|
+
// No answer buttons: the hook published this card while AFK was off, so the terminal prompt answers it.
|
|
102
|
+
// The hint follows the live mode, so the card never claims AFK is off after the operator turned it back on.
|
|
103
|
+
const terminal = approval.terminal === true;
|
|
104
|
+
if (approval.questions) {
|
|
105
|
+
return <div className="flex w-full flex-col gap-1.5" data-terminal={terminal || undefined}>
|
|
106
|
+
<ChoiceCard questions={approval.questions} answers={approval.answers} disabled={disabled || !open || terminal}
|
|
107
|
+
title={approval.harness + " asks · " + (!open ? "closed" : terminal ? IN_TERMINAL : "answer to continue")}
|
|
108
|
+
onSubmit={open && !terminal ? answers => act({ id: approval.id, answers }) : undefined}/>
|
|
109
|
+
{outcome && <p className="text-xs text-muted-foreground" data-outcome={approval.state}>{outcome}{approval.by && " · " + approval.by}</p>}
|
|
110
|
+
</div>;
|
|
111
|
+
}
|
|
112
|
+
return <div className={cn(CARD, "flex flex-col gap-2", open && "border-primary/50")} data-card="approval" data-terminal={terminal || undefined}>
|
|
113
|
+
<p className="flex items-center gap-1.5 text-xs font-medium text-muted-foreground"><ShieldQuestion className="size-3.5"/>{approval.harness} asks permission · {approval.tool}</p>
|
|
114
|
+
{approval.summary && <pre className="max-h-40 overflow-auto rounded-lg border bg-muted/50 px-2 py-1.5 font-mono text-xs whitespace-pre-wrap">{approval.summary}</pre>}
|
|
115
|
+
{open && terminal ? <p className="flex items-center gap-1.5 text-xs font-medium text-primary"><SquareTerminal className="size-3.5 shrink-0"/>{IN_TERMINAL}<span className="font-normal text-muted-foreground">· {terminalHint(approval.mode)}</span></p>
|
|
116
|
+
: open ? <div className="flex flex-wrap items-center gap-2">
|
|
117
|
+
<Button size="sm" className="rounded-md" disabled={disabled} onClick={() => act({ id: approval.id, decision: "allow" })}><Check/>{allowLabel(approval)}</Button>
|
|
118
|
+
{offersSessionGrant(approval) && <Button size="sm" variant="outline" className="rounded-md" disabled={disabled} onClick={() => act({ id: approval.id, decision: "always" })}><CheckCheck/>{ALWAYS_LABEL}</Button>}
|
|
119
|
+
<Button size="sm" variant="outline" className="rounded-md" disabled={disabled} onClick={() => act({ id: approval.id, decision: "deny" })}><X/>Deny</Button>
|
|
120
|
+
<span className="ms-auto"><CardModeMenu approval={approval} disabled={disabled} act={act} setMode={setMode}/></span>
|
|
121
|
+
</div> : <p className="text-xs text-muted-foreground" data-outcome={approval.state}>{outcome}{approval.by && " · " + approval.by}</p>}
|
|
122
|
+
</div>;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** An ask_question post: the A2UI surface when the stream sent one, else the card below; Skip while open. */
|
|
126
|
+
export function QuestionCard({ skip, ...props }) {
|
|
127
|
+
const open = !props.answer && !props.skipped;
|
|
128
|
+
return <>
|
|
129
|
+
<Surface id={questionSurfaceId(props.question)} head={props.head} kind="Question" open={open} fallback={<LegacyQuestionCard {...props}/>}/>
|
|
130
|
+
{skip && open && <SkipButton disabled={props.disabled} onSkip={() => skip({ id: props.question })}/>}
|
|
131
|
+
</>;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** A create-PR request from an agent (lib/pr-card.ts): the A2UI surface when the stream sent one, else the card below. */
|
|
135
|
+
export function PrCard({ createPr }) {
|
|
136
|
+
return <Surface id={prSurfaceId(createPr.id)} kind="Create PR" open={!prOutcome(createPr)} fallback={<LegacyPrCard createPr={createPr}/>}/>;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** The fallback when no surface arrived: the note, then Create PR and Dismiss while open, or the outcome once closed. */
|
|
140
|
+
function LegacyPrCard({ createPr }) {
|
|
141
|
+
const { submit, disabled } = useContext(SurfaceContext);
|
|
142
|
+
const outcome = prOutcome(createPr);
|
|
143
|
+
const send = name => submit?.({ forwardedProps: { a2uiAction: { userAction: { surfaceId: prSurfaceId(createPr.id), name, context: { id: createPr.id } } } } });
|
|
144
|
+
return <div className={cn(CARD, "flex flex-col gap-2", !outcome && "border-primary/50")} data-card="pr">
|
|
145
|
+
<p className="flex items-center gap-1.5 text-xs font-medium text-muted-foreground"><GitPullRequest className="size-3.5"/>Create PR · {createPr.harness}</p>
|
|
146
|
+
{createPr.note && <pre className="max-h-40 overflow-auto rounded-lg border bg-muted/50 px-2 py-1.5 font-mono text-xs whitespace-pre-wrap">{createPr.note}</pre>}
|
|
147
|
+
{outcome ? <p className="text-xs text-muted-foreground wrap-anywhere" data-outcome={createPr.state}>{outcome}</p>
|
|
148
|
+
: <div className="flex flex-wrap items-center gap-2">
|
|
149
|
+
<Button size="sm" variant="outline" className="rounded-md" disabled={disabled || !submit} onClick={() => send("dismiss")}>Dismiss</Button>
|
|
150
|
+
<Button size="sm" className="rounded-md" disabled={disabled || !submit} onClick={() => send("create-pr")}><GitPullRequest/>Create PR</Button>
|
|
151
|
+
</div>}
|
|
152
|
+
</div>;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** An ask_question post: the question, then its answer, Skipped, or an answer field. */
|
|
156
|
+
export function LegacyQuestionCard({ body, answer, by, skipped, disabled, onAnswer, taskLinks }) {
|
|
157
|
+
const [draft, setDraft] = useState("");
|
|
158
|
+
return <div className={cn(CARD, "flex flex-col gap-2", !answer && !skipped && "border-primary/50")} data-card="question">
|
|
159
|
+
<p className="flex items-center gap-1.5 text-xs font-medium text-muted-foreground"><CircleHelp className="size-3.5"/>Question</p>
|
|
160
|
+
{!answer && !skipped && isBlocking(body) && <Badge variant="secondary" className="h-5 border-primary/40 bg-primary/10 px-2 text-xs font-medium text-primary">{BLOCKING_LABEL}</Badge>}
|
|
161
|
+
<MessageContent markdown taskLinks={taskLinks} className="bubble max-w-full bg-transparent p-0 text-base leading-relaxed">{typeof body === "string" ? questionText(body) : body}</MessageContent>
|
|
162
|
+
{answer ? <p className="text-xs text-muted-foreground">Answered: <span className="font-medium text-foreground">{answer}</span>{by && " · " + by}</p>
|
|
163
|
+
: skipped ? <p className="text-xs text-muted-foreground" data-outcome="skipped">{SKIPPED}</p>
|
|
164
|
+
: <div className="flex flex-col gap-2">
|
|
165
|
+
<Textarea aria-label="Answer" placeholder="Your answer…" value={draft} disabled={disabled} onChange={event => setDraft(event.target.value)} className="min-h-9 text-sm"/>
|
|
166
|
+
<Button size="sm" className="self-start rounded-md" disabled={disabled || !draft.trim()} onClick={async () => { if (await onAnswer(draft.trim())) setDraft(""); }}>Submit</Button>
|
|
167
|
+
</div>}
|
|
168
|
+
</div>;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** AskUserQuestion questions from a tool call's JSON input, or null. */
|
|
172
|
+
export function askedQuestions(tool, input) {
|
|
173
|
+
if (tool !== "AskUserQuestion" || !input) return null;
|
|
174
|
+
try {
|
|
175
|
+
const questions = JSON.parse(input).questions;
|
|
176
|
+
return Array.isArray(questions) && questions.every(q => typeof q?.question === "string" && Array.isArray(q.options) && q.options.every(o => typeof o?.label === "string")) ? questions : null;
|
|
177
|
+
} catch {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function SuspensionCard({ suspension, disabled, resume }) {
|
|
183
|
+
return <div className="flex min-w-0 flex-col items-start gap-2 rounded-xl border p-3">
|
|
184
|
+
<p role="alert" className="text-xs">{suspension.reason}. Waiting for operator confirmation.</p>
|
|
185
|
+
<ConfirmButton label="Resume handoff" confirmLabel="Resume"
|
|
186
|
+
question={`Allow ${suspension.from} → ${suspension.to} on "${suspension.on}" to exceed the limit?`}
|
|
187
|
+
disabled={disabled} onConfirm={resume}/>
|
|
188
|
+
</div>;
|
|
189
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// The console's network layer: the POST helper, the build check, the auth ping, and what each hash selection streams.
|
|
2
|
+
import { toast } from "sonner";
|
|
3
|
+
import { parseSelection } from "@/lib/selection";
|
|
4
|
+
import { SEND_CONFIRMATION, readSendConfirmation } from "@/lib/send-confirmation";
|
|
5
|
+
|
|
6
|
+
export const initial = { projects: [], harnesses: [], agents: [], messages: [] };
|
|
7
|
+
export const CONNECTION_TOAST = "connection";
|
|
8
|
+
export const UPDATE_TOAST = "update";
|
|
9
|
+
export const BUILD = process.env.TEMMO_BUILD;
|
|
10
|
+
// Fired on a 401 or a closed stream; the sign-in gate asks /api/auth/me again.
|
|
11
|
+
export const AUTH_CHECK = "temmo:auth-check";
|
|
12
|
+
|
|
13
|
+
export function selection() {
|
|
14
|
+
return parseSelection(location.hash.slice(1));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The /api/events query for a selection, and which view it shows. */
|
|
18
|
+
export function streamOf(selected) {
|
|
19
|
+
const stream = new URLSearchParams();
|
|
20
|
+
// Home, the decision inbox and Recent progress read the cross-project home stream.
|
|
21
|
+
const home = selected.level === "home" || selected.level === "inbox" || selected.level === "progress";
|
|
22
|
+
const session = selected.level === "session" && Boolean(selected.session);
|
|
23
|
+
// The thread view streams its thread topic as the feed; the project's threads and agents ride along.
|
|
24
|
+
const threadView = selected.level === "thread" && Boolean(selected.thread);
|
|
25
|
+
if (selected.project && !home) stream.set("project", selected.project);
|
|
26
|
+
if (threadView) stream.set("thread", selected.thread);
|
|
27
|
+
if (session) stream.set("session", selected.session);
|
|
28
|
+
// The project chat reads activity for its completion and live rows; a session's chat and its side panels read it too.
|
|
29
|
+
const watching = selected.level === "project";
|
|
30
|
+
const subagents = session && selected.tab === "subagents";
|
|
31
|
+
// A session always shows its chat; the tab picks the panel beside it.
|
|
32
|
+
const inline = session;
|
|
33
|
+
const raw = session && selected.tab === "raw";
|
|
34
|
+
// Sessions with none picked lists the project's sessions under the selector.
|
|
35
|
+
const listing = selected.level === "session" && !selected.session;
|
|
36
|
+
// The task board: its own sidebar level, read from the same project stream as the chat.
|
|
37
|
+
const tasks = selected.level === "tasks";
|
|
38
|
+
// The compaction map reads each agent's compactions and context from the sessions view.
|
|
39
|
+
const compactions = selected.level === "compactions";
|
|
40
|
+
if (watching || inline || subagents || raw) stream.set("view", "activity");
|
|
41
|
+
else if (home) stream.set("view", "home");
|
|
42
|
+
else if (listing || compactions) stream.set("view", "sessions");
|
|
43
|
+
if (compactions) stream.set("history", "1");
|
|
44
|
+
if (selected.level === "progress") stream.set("progress", "1");
|
|
45
|
+
return { home, watching, subagents, inline, raw, listing, tasks, compactions, threadView, requested: stream.toString() };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function api(path, payload, image) {
|
|
49
|
+
if (image) {
|
|
50
|
+
const form = new FormData();
|
|
51
|
+
form.set("message", JSON.stringify(payload));
|
|
52
|
+
form.set("image", image);
|
|
53
|
+
payload = form;
|
|
54
|
+
}
|
|
55
|
+
const headers = new Headers();
|
|
56
|
+
if (path === "send") headers.set("Accept", SEND_CONFIRMATION);
|
|
57
|
+
if (!image) headers.set("Content-Type", "application/json");
|
|
58
|
+
const response = await fetch("/api/" + path, { method: "POST", headers, body: image ? payload : JSON.stringify(payload) });
|
|
59
|
+
if (response.status === 401) window.dispatchEvent(new Event(AUTH_CHECK));
|
|
60
|
+
if (response.ok && response.headers.get("content-type")?.split(";")[0] === SEND_CONFIRMATION) return readSendConfirmation(response);
|
|
61
|
+
const result = await response.json();
|
|
62
|
+
if (!response.ok) throw new Error(result.error || "Request failed");
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** After a deploy the server runs a newer build than this page; offer a reload until the operator takes it. */
|
|
67
|
+
export async function checkBuild() {
|
|
68
|
+
try {
|
|
69
|
+
const response = await fetch("/api/version", { cache: "no-store" });
|
|
70
|
+
const { build } = await response.json();
|
|
71
|
+
if (!build || build === BUILD) return toast.dismiss(UPDATE_TOAST);
|
|
72
|
+
toast.info("Update available", {
|
|
73
|
+
id: UPDATE_TOAST, duration: Infinity, description: "A new version of Temmo is deployed.",
|
|
74
|
+
action: { label: "Reload", onClick: () => window.location.reload() },
|
|
75
|
+
});
|
|
76
|
+
} catch {}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export async function signOut() {
|
|
80
|
+
await fetch("/api/auth/logout", { method: "POST" }).catch(() => {});
|
|
81
|
+
window.dispatchEvent(new Event(AUTH_CHECK));
|
|
82
|
+
}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
// The composer: assistant-ui's ComposerPrimitive over the console's external-store runtime, with
|
|
3
|
+
// draft memory per conversation, the @mention and /command pickers, image drafts,
|
|
4
|
+
// and the destination line that says where the message will go before it is sent.
|
|
5
|
+
import { useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
6
|
+
import { ComposerPrimitive, useAui, useAuiState } from "@assistant-ui/react";
|
|
7
|
+
import { ArrowUp, AtSign, Check, X, Zap } from "lucide-react";
|
|
8
|
+
import { Button } from "@/components/ui/button";
|
|
9
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
|
|
10
|
+
import { cn } from "@/lib/utils";
|
|
11
|
+
import { fuzzyRank } from "@/lib/fuzzy";
|
|
12
|
+
import { commandFor, matchArgs, matchCommands } from "@/lib/slash-commands";
|
|
13
|
+
import { composerDestination, composerRecipients } from "@/lib/message-routing";
|
|
14
|
+
import { quotedReply, usableReplyId } from "@/lib/reply-quote";
|
|
15
|
+
import { patternMentionTargets } from "@/lib/mentions";
|
|
16
|
+
import { quoteText } from "@/lib/quote";
|
|
17
|
+
import { isLive } from "@/lib/session-state";
|
|
18
|
+
import { drafts } from "@/lib/view-memory";
|
|
19
|
+
import { AttachImageButton, ImageDraft, ImagePicker } from "./chat-image";
|
|
20
|
+
import { ComposerActions } from "./composer-actions";
|
|
21
|
+
import { Avatar, Dot, HARNESS_NAMES, SessionName, seen, short } from "./chat-shared";
|
|
22
|
+
|
|
23
|
+
// Touch pointers insert a newline on Enter; the send button sends.
|
|
24
|
+
const COARSE_POINTER = "(pointer: coarse)";
|
|
25
|
+
|
|
26
|
+
// Model lists per harness from the models action; an empty object when it fails.
|
|
27
|
+
export function useModels(project) {
|
|
28
|
+
const [models, setModels] = useState({});
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
let live = true;
|
|
31
|
+
fetch("/api/models", { method: "POST", cache: "no-store", headers: { "content-type": "application/json" }, body: JSON.stringify({ project }) })
|
|
32
|
+
.then(response => response.ok ? response.json() : {}).catch(() => ({}))
|
|
33
|
+
.then(list => { if (live && list && typeof list === "object" && !Array.isArray(list)) setModels(list); });
|
|
34
|
+
return () => { live = false; };
|
|
35
|
+
}, [project]);
|
|
36
|
+
return models;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const modelsOf = (models, harness) => Array.isArray(models[harness]) ? models[harness].filter(id => typeof id === "string" && id) : [];
|
|
40
|
+
|
|
41
|
+
export function Composer({ conversation, agents, harnesses, teams = [], startable = [], models = {}, now, disabled, placeholder, routing, onSend, urgentable, replying, cancelReply, harness = "", initialDraft = "", sendBridgeRef }) {
|
|
42
|
+
// The draft lives in the runtime composer; the per-conversation store mirrors it so a view switch restores it.
|
|
43
|
+
const aui = useAui();
|
|
44
|
+
const draft = useAuiState(s => s.composer.text);
|
|
45
|
+
const [urgent, setUrgent] = useState(false);
|
|
46
|
+
const [showPicker, setShowPicker] = useState(false);
|
|
47
|
+
const [activeIndex, setActiveIndex] = useState(0);
|
|
48
|
+
const [commandsOpen, setCommandsOpen] = useState(false);
|
|
49
|
+
const [posting, setPosting] = useState(false);
|
|
50
|
+
const [held, setHeld] = useState(null);
|
|
51
|
+
const [images, setImages] = useState([]);
|
|
52
|
+
const [imageError, setImageError] = useState("");
|
|
53
|
+
// Command names the picker inserted in this draft; only these and known commands make the message a command.
|
|
54
|
+
const picked = useRef(new Set());
|
|
55
|
+
const prefillFocused = useRef(false);
|
|
56
|
+
const textarea = useRef(null);
|
|
57
|
+
// The flags the runtime's onNew must carry back to the console's send path (the primitive only knows the text).
|
|
58
|
+
const flags = useRef({});
|
|
59
|
+
// Blocks a second image-only send before the first one's posting state renders.
|
|
60
|
+
const pending = useRef(false);
|
|
61
|
+
const coarse = useSyncExternalStore(subscribeCoarse, () => window.matchMedia?.(COARSE_POINTER).matches ?? false, () => false);
|
|
62
|
+
// Seed the runtime composer from this conversation's stored draft once, before paint.
|
|
63
|
+
useLayoutEffect(() => {
|
|
64
|
+
const saved = drafts.get(conversation, "") || initialDraft;
|
|
65
|
+
if (saved && !aui.composer.getState().text) aui.composer.setText(saved);
|
|
66
|
+
}, []);
|
|
67
|
+
// Every edit is kept per conversation, so a tab or view switch that remounts the composer restores it.
|
|
68
|
+
const firstText = useRef(true);
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (firstText.current) { firstText.current = false; return; }
|
|
71
|
+
drafts.set(conversation, draft);
|
|
72
|
+
}, [draft]);
|
|
73
|
+
const mention = mentionAt(draft);
|
|
74
|
+
const options = [...agents.map(agent => ({ id: agent.id, name: agent.name, lastMessageAt: agent.lastMessageAt, activeAt: agent.activeAt, online: agent.online, live: isLive(agent, now) })),
|
|
75
|
+
...harnesses.map(harness => ({ id: harness.id, lastMessageAt: harness.lastMessageAt, activeAt: harness.activeAt, harness: true })),
|
|
76
|
+
...(teams || []).map(team => ({ id: team.id, team: true, members: team.members })),
|
|
77
|
+
...patternMentionTargets(routing.patterns).filter(option => !(teams || []).some(team => team.id === option.id)),
|
|
78
|
+
...startable.flatMap(harness => modelsOf(models, harness).map(model => ({ id: harness + ":" + model, harness, model }))),
|
|
79
|
+
// Open subagent runs of the project's sessions, tagged @session/run.
|
|
80
|
+
...agents.flatMap(agent => (agent.subagents || []).filter(run => run.open).map(run => ({ id: agent.id + "/" + run.run, owner: agent.id, run: true,
|
|
81
|
+
label: short(agent.id) + " › " + [run.kind || "agent", run.description].filter(Boolean).join(": ") })))];
|
|
82
|
+
// "@codex g5" narrows to codex's models; "@gpt" ranks every option.
|
|
83
|
+
const matches = fuzzyRank(mention ? mention[1] + (mention[2] ?? "") : "", mention?.[2] !== undefined ? options.filter(option => option.model && option.harness === mention[1]) : options,
|
|
84
|
+
option => [option.id, option.name, option.label, HARNESS_NAMES[option.harness === true ? option.id : option.harness], option.model, ...(option.team ? option.members || [] : [])]);
|
|
85
|
+
const picking = showPicker && matches.length > 0;
|
|
86
|
+
const chosen = Math.min(activeIndex, matches.length - 1);
|
|
87
|
+
// "/comp" while typing a command for the selected session: its names with support from web/lib/slash-commands.js.
|
|
88
|
+
const typedCommand = harness && /^\/[a-z0-9-]*$/i.test(draft) ? draft.slice(1) : null;
|
|
89
|
+
// "/permission a": the values the argument being typed takes; teams are team.dot teams, models the harness's list.
|
|
90
|
+
const argData = {
|
|
91
|
+
teams: (routing.patterns || []).filter(pattern => pattern.teamFile && !pattern.invalid).map(pattern => ({ name: pattern.name, description: pattern.description })),
|
|
92
|
+
models: modelsOf(models, harness),
|
|
93
|
+
mode: routing.session ? agents.find(agent => agent.id === routing.target)?.runnerMode : undefined,
|
|
94
|
+
};
|
|
95
|
+
const argMatch = harness && typedCommand === null ? matchArgs(harness, draft, argData) : null;
|
|
96
|
+
const values = argMatch?.options || [];
|
|
97
|
+
// An unsupported command keeps its disabled row while its arguments are typed.
|
|
98
|
+
const commands = typedCommand !== null ? matchCommands(harness, typedCommand) : argMatch?.command.status === "unsupported" ? [argMatch.command] : [];
|
|
99
|
+
const entries = values.length ? values : commands;
|
|
100
|
+
const commandPicking = entries.length > 0 && !picking && commandsOpen;
|
|
101
|
+
const commandChosen = Math.min(activeIndex, entries.length - 1);
|
|
102
|
+
const busy = disabled || posting;
|
|
103
|
+
const text = draft.trim();
|
|
104
|
+
const quoted = Boolean(replying?.id && !usableReplyId(replying.id));
|
|
105
|
+
const image = images[0];
|
|
106
|
+
const canSend = Boolean(text || image);
|
|
107
|
+
const command = !image && routing.session && commandFor(text, picked.current) !== null;
|
|
108
|
+
const route = { ...routing, agents, teams, startable, models, quoted, text: quoted ? quotedReply(text, replying) : text };
|
|
109
|
+
const destination = command ? "Command for " + short(routing.target) : composerDestination(route);
|
|
110
|
+
const recipients = command ? [routing.target] : composerRecipients(route);
|
|
111
|
+
const sendName = command ? destination
|
|
112
|
+
: "Send · " + destination;
|
|
113
|
+
|
|
114
|
+
// Every edit is kept per conversation, so a tab or view switch that remounts the composer restores it.
|
|
115
|
+
function setDraft(next) { setHeld(null); aui.composer.setText(next); }
|
|
116
|
+
function focus() { document.getElementById("composer")?.focus(); }
|
|
117
|
+
function selectImages(next) { setHeld(null); setImageError(""); setImages(next); }
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (!initialDraft || disabled || prefillFocused.current) return;
|
|
120
|
+
const input = document.getElementById("composer");
|
|
121
|
+
input.focus();
|
|
122
|
+
input.setSelectionRange(input.value.length, input.value.length);
|
|
123
|
+
prefillFocused.current = true;
|
|
124
|
+
}, [initialDraft, disabled]);
|
|
125
|
+
// A Reply click prefills the agent's @tag ahead of whatever the operator has typed.
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
if (!replying) return;
|
|
128
|
+
if (replying.prefill && !draft.startsWith(replying.prefill)) setDraft(replying.prefill + draft);
|
|
129
|
+
focus();
|
|
130
|
+
}, [replying]);
|
|
131
|
+
// The @tag being typed: [tag text, first word, second word when the first names a startable harness].
|
|
132
|
+
function mentionAt(text) {
|
|
133
|
+
const found = /(?:^|\s)@([\w#:./-]*)(?: ([\w.:/-]+))?$/.exec(text);
|
|
134
|
+
return found && (found[2] === undefined || startable.includes(found[1])) ? [found[0].replace(/^\s/, ""), found[1], found[2]] : null;
|
|
135
|
+
}
|
|
136
|
+
function change(next) { setDraft(next); setShowPicker(mentionAt(next) !== null); setCommandsOpen(true); setActiveIndex(0); }
|
|
137
|
+
function insert(option) {
|
|
138
|
+
const prefix = mention ? draft.slice(0, -mention[0].length) : draft + (draft && !/\s$/.test(draft) ? " " : "");
|
|
139
|
+
setDraft(prefix + "@" + option.id + " ");
|
|
140
|
+
setShowPicker(false);
|
|
141
|
+
focus();
|
|
142
|
+
}
|
|
143
|
+
function insertCommand(command) {
|
|
144
|
+
picked.current.add(command.name);
|
|
145
|
+
setDraft("/" + command.name + (command.args ? " " : ""));
|
|
146
|
+
setActiveIndex(0);
|
|
147
|
+
focus();
|
|
148
|
+
}
|
|
149
|
+
// A value ending in a space leaves the next argument to pick; the last one closes the list so Enter sends.
|
|
150
|
+
function insertValue(option) {
|
|
151
|
+
setDraft(option.text);
|
|
152
|
+
setActiveIndex(0);
|
|
153
|
+
if (!option.text.endsWith(" ")) setCommandsOpen(false);
|
|
154
|
+
focus();
|
|
155
|
+
}
|
|
156
|
+
// The runtime's onNew path: the console's send runs with the flags set at send time;
|
|
157
|
+
// a non-true result makes the provider throw MessageNotSentError, so the runtime hands the text back.
|
|
158
|
+
async function finish(raw) {
|
|
159
|
+
const body = raw.trim();
|
|
160
|
+
setPosting(true);
|
|
161
|
+
try {
|
|
162
|
+
const { urgent: now, command, sendAnyway, image } = flags.current;
|
|
163
|
+
// onSend returns true only when the message was sent (or a command ran or was requested); otherwise the draft stays.
|
|
164
|
+
const result = await onSend(body, urgentable && now, command, sendAnyway, image);
|
|
165
|
+
if (result === "draftHeld") setHeld({ text: body, replying, sendNow: now });
|
|
166
|
+
if (result === true) {
|
|
167
|
+
setShowPicker(false); setUrgent(false); picked.current.clear();
|
|
168
|
+
if (image) selectImages([]);
|
|
169
|
+
} else if (raw) drafts.set(conversation, raw);
|
|
170
|
+
return result;
|
|
171
|
+
} finally { setPosting(false); focus(); }
|
|
172
|
+
}
|
|
173
|
+
// The console's runtime bridge calls finish for every composer submission.
|
|
174
|
+
useEffect(() => {
|
|
175
|
+
sendBridgeRef.current = finish;
|
|
176
|
+
return () => { if (sendBridgeRef.current === finish) sendBridgeRef.current = null; };
|
|
177
|
+
});
|
|
178
|
+
// An Actions pick runs at once as a session command; the draft stays as typed.
|
|
179
|
+
async function runAction(body) {
|
|
180
|
+
if (busy) return;
|
|
181
|
+
setPosting(true);
|
|
182
|
+
try { await onSend(body, false, true, false, undefined); } finally { setPosting(false); }
|
|
183
|
+
}
|
|
184
|
+
function send(sendAnyway = false, sendNow = urgent) {
|
|
185
|
+
if (busy || !canSend) return;
|
|
186
|
+
flags.current = { urgent: urgentable && sendNow, command, sendAnyway, image };
|
|
187
|
+
// Text goes through the runtime (it owns clearing and draft-restoration); an image-only send has no text to hold.
|
|
188
|
+
if (text) aui.composer.send();
|
|
189
|
+
else if (!pending.current) {
|
|
190
|
+
pending.current = true;
|
|
191
|
+
void finish("").finally(() => { pending.current = false; });
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return <div className="relative mx-auto w-full max-w-3xl px-3 pb-[max(0.75rem,env(safe-area-inset-bottom))] pt-2 max-md:pb-2">
|
|
195
|
+
{held?.text === draft.trim() && held.replying === replying && <div className="mb-2 flex items-center justify-between gap-2 rounded-xl border border-primary/40 bg-primary/10 px-3 py-1.5 text-sm">
|
|
196
|
+
<span role="status">The terminal has an unsent draft.</span>
|
|
197
|
+
<Button type="button" variant="outline" size="sm" disabled={busy} onClick={() => send(true, held.sendNow)}>Send anyway</Button>
|
|
198
|
+
</div>}
|
|
199
|
+
{replying && <div className="mb-2 flex items-center justify-between gap-2 rounded-xl border bg-muted px-3 py-1.5 text-sm">
|
|
200
|
+
<span className="min-w-0 truncate">Replying to {short(replying.sender)}{replying.body && <span className="text-muted-foreground"> · {quoteText(replying.body)}</span>}</span>
|
|
201
|
+
<Button variant="ghost" size="icon" className="size-6" aria-label="Cancel reply" onClick={cancelReply}><X/></Button>
|
|
202
|
+
</div>}
|
|
203
|
+
{commandPicking && values.length > 0 && <div role="listbox" aria-label={"Values for /" + argMatch.command.name}
|
|
204
|
+
className="absolute inset-x-3 bottom-full mb-1 max-h-64 overflow-y-auto rounded-2xl border bg-popover p-1 text-popover-foreground shadow-lg">
|
|
205
|
+
{values.map((option, i) => <button type="button" role="option" aria-selected={i === commandChosen} aria-current={option.current || undefined} key={option.value}
|
|
206
|
+
title={argMatch.command.reason} onMouseDown={event => event.preventDefault()} onClick={() => insertValue(option)}
|
|
207
|
+
className={cn("flex w-full items-center gap-2 rounded-xl px-2 py-1.5 text-left text-sm", i === commandChosen && "bg-accent text-accent-foreground")}>
|
|
208
|
+
<span className="flex min-w-0 flex-1 flex-col"><span className="font-mono text-xs">{option.value}</span>
|
|
209
|
+
{option.summary && <span className="truncate text-xs text-muted-foreground">{option.summary}</span>}</span>
|
|
210
|
+
{option.current && <span className="flex shrink-0 items-center gap-1 text-xs text-muted-foreground"><Check aria-hidden className="size-4"/>now</span>}
|
|
211
|
+
</button>)}
|
|
212
|
+
</div>}
|
|
213
|
+
{commandPicking && !values.length && <div role="listbox" aria-label="Session commands"
|
|
214
|
+
className="absolute inset-x-3 bottom-full mb-1 max-h-64 overflow-y-auto rounded-2xl border bg-popover p-1 text-popover-foreground shadow-lg">
|
|
215
|
+
{commands.map((command, i) => <button type="button" role="option" aria-selected={i === commandChosen} aria-disabled={command.status === "unsupported"} key={command.name}
|
|
216
|
+
title={command.reason} onMouseDown={event => event.preventDefault()} onClick={() => command.status !== "unsupported" && insertCommand(command)}
|
|
217
|
+
className={cn("flex w-full items-center gap-2 rounded-xl px-2 py-1.5 text-left text-sm", i === commandChosen && "bg-accent text-accent-foreground", command.status === "unsupported" && "opacity-50")}>
|
|
218
|
+
<span className="flex min-w-0 flex-1 flex-col"><span className="font-mono text-xs">/{command.name}{command.args ? " " + command.args : ""}</span>
|
|
219
|
+
<span className="truncate text-xs text-muted-foreground">{command.summary}</span></span>
|
|
220
|
+
{command.status === "partial" && <span className="shrink-0 rounded-md border px-1.5 text-xs text-primary">partial</span>}
|
|
221
|
+
{command.status === "unverified" && <span className="shrink-0 rounded-md border px-1.5 text-xs text-primary">unverified</span>}
|
|
222
|
+
{command.status === "unsupported" && <span className="shrink-0 text-xs text-muted-foreground">unsupported</span>}
|
|
223
|
+
</button>)}
|
|
224
|
+
</div>}
|
|
225
|
+
{picking && <div role="listbox" aria-label="Mention an agent"
|
|
226
|
+
className="absolute inset-x-3 bottom-full mb-1 max-h-64 overflow-y-auto rounded-2xl border bg-popover p-1 text-popover-foreground shadow-lg">
|
|
227
|
+
{matches.map((option, i) => <button type="button" role="option" aria-selected={i === chosen} key={option.id}
|
|
228
|
+
onMouseDown={event => event.preventDefault()} onClick={() => insert(option)}
|
|
229
|
+
className={cn("flex w-full items-center gap-2 rounded-xl px-2 py-1.5 text-left text-sm", i === chosen && "bg-accent text-accent-foreground")}>
|
|
230
|
+
<Avatar address={option.run ? option.owner : option.model ? option.harness : option.team ? "operator" : option.id} className="size-6 text-xs"/>
|
|
231
|
+
<span className="flex min-w-0 flex-1 flex-col">{option.run ? <span className="truncate text-xs text-muted-foreground">{option.label}</span> : <span className="truncate font-mono text-xs">@{option.id}</span>}
|
|
232
|
+
{option.run ? null : option.model ? <span className="truncate text-xs text-muted-foreground">{(HARNESS_NAMES[option.harness] || option.harness) + " · " + option.model}</span> : option.team ? <span className="truncate text-xs text-muted-foreground">{(option.members || []).join(", ")}</span> : <SessionName agent={option}/>}</span>
|
|
233
|
+
{!option.harness && !option.run && !option.team && <Dot online={option.live === true}/>}
|
|
234
|
+
<span className="shrink-0 text-xs text-muted-foreground">{option.run ? "subagent" : option.pattern ? "pattern" : option.team ? "team" : option.model ? "new session" : (option.harness ? "harness · " : "") + seen(option, now)}</span>
|
|
235
|
+
</button>)}
|
|
236
|
+
</div>}
|
|
237
|
+
<div onKeyDownCapture={event => {
|
|
238
|
+
if (commandPicking) {
|
|
239
|
+
if (event.key === "Escape") setCommandsOpen(false);
|
|
240
|
+
else if (event.key === "ArrowDown") setActiveIndex((commandChosen + 1) % entries.length);
|
|
241
|
+
else if (event.key === "ArrowUp") setActiveIndex((commandChosen + entries.length - 1) % entries.length);
|
|
242
|
+
// A value list takes Enter too: "/permission " alone is no command to send.
|
|
243
|
+
else if (values.length && (event.key === "Tab" || (event.key === "Enter" && !event.shiftKey))) insertValue(values[commandChosen]);
|
|
244
|
+
else if (event.key === "Tab" && !values.length && commands[commandChosen].status !== "unsupported") insertCommand(commands[commandChosen]);
|
|
245
|
+
else return;
|
|
246
|
+
event.preventDefault(); event.stopPropagation();
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (!picking) return;
|
|
250
|
+
if (event.key === "Escape") setShowPicker(false);
|
|
251
|
+
else if (event.key === "ArrowDown") setActiveIndex((chosen + 1) % matches.length);
|
|
252
|
+
else if (event.key === "ArrowUp") setActiveIndex((chosen + matches.length - 1) % matches.length);
|
|
253
|
+
// In "@codex fix…" the second word may be prose: Enter sends, Tab or a click picks a model.
|
|
254
|
+
else if ((event.key === "Enter" && !event.shiftKey && mention?.[2] === undefined) || event.key === "Tab") insert(matches[chosen]);
|
|
255
|
+
else return;
|
|
256
|
+
event.preventDefault(); event.stopPropagation();
|
|
257
|
+
}}>
|
|
258
|
+
<ImagePicker files={images} onChange={selectImages} onError={setImageError} disabled={busy}>
|
|
259
|
+
<ComposerPrimitive.Root onSubmit={event => { event.preventDefault(); send(); }}
|
|
260
|
+
className={cn("cursor-text rounded-2xl bg-card p-2 shadow-raised focus-within:ring-2 focus-within:ring-ring", busy && "cursor-not-allowed opacity-60")}>
|
|
261
|
+
{image && <ImageDraft file={image} disabled={busy} remove={() => { selectImages([]); focus(); }}/>}
|
|
262
|
+
{imageError && <p role="alert" className="px-3 text-sm text-destructive">{imageError}</p>}
|
|
263
|
+
<div id="composer-destination" aria-live="polite" title={recipients.join(", ") || undefined} className="max-h-[20dvh] overflow-y-auto break-words px-3 pt-1 text-xs font-medium text-muted-foreground">
|
|
264
|
+
{destination}
|
|
265
|
+
</div>
|
|
266
|
+
<ComposerPrimitive.Input ref={textarea} id="composer" aria-label="Message" aria-describedby="composer-destination" placeholder={placeholder}
|
|
267
|
+
// readOnly, not disabled, while busy: a disabled textarea drops focus and closes the phone keyboard.
|
|
268
|
+
readOnly={busy} aria-disabled={disabled || undefined} aria-busy={posting || undefined}
|
|
269
|
+
submitMode={coarse ? "none" : "enter"} cancelOnEscape={false}
|
|
270
|
+
unstable_focusOnRunStart={false} unstable_focusOnScrollToBottom={false} unstable_focusOnThreadSwitched={false}
|
|
271
|
+
onChange={event => change(event.target.value)}
|
|
272
|
+
className="max-h-60 min-h-[44px] w-full resize-none border-none bg-transparent px-3 text-base text-foreground shadow-none outline-none focus-visible:ring-0 focus-visible:ring-offset-0"/>
|
|
273
|
+
<TooltipProvider>
|
|
274
|
+
<div className="flex items-center justify-between px-1 pt-1">
|
|
275
|
+
<div className="flex items-center gap-1">
|
|
276
|
+
<AttachImageButton replacing={Boolean(image)}/>
|
|
277
|
+
<Tooltip>
|
|
278
|
+
<TooltipTrigger asChild disabled={busy} onClick={event => event.stopPropagation()}>
|
|
279
|
+
<Button type="button" variant="ghost" size="sm" className="rounded-md" aria-expanded={picking} disabled={busy}
|
|
280
|
+
onClick={() => { setShowPicker(!showPicker); setActiveIndex(0); focus(); }}><AtSign/><span className="max-sm:sr-only">Mention</span></Button>
|
|
281
|
+
</TooltipTrigger>
|
|
282
|
+
<TooltipContent side="top">Mention an agent</TooltipContent>
|
|
283
|
+
</Tooltip>
|
|
284
|
+
{harness && routing.session && <ComposerActions harness={harness} data={argData} target={routing.target} disabled={busy} run={runAction}/>}
|
|
285
|
+
</div>
|
|
286
|
+
<div className="flex items-center gap-1">
|
|
287
|
+
{urgentable && !command && <Tooltip>
|
|
288
|
+
<TooltipTrigger asChild disabled={busy} onClick={event => event.stopPropagation()}>
|
|
289
|
+
<Button type="button" variant={urgent ? "secondary" : "ghost"} size="sm" className={cn("rounded-md", urgent && "text-primary")} aria-pressed={routing.session ? undefined : urgent} disabled={busy || (routing.session && !canSend)}
|
|
290
|
+
onClick={() => routing.session ? send(false, true) : setUrgent(!urgent)}><Zap/>Send now</Button>
|
|
291
|
+
</TooltipTrigger>
|
|
292
|
+
<TooltipContent side="top">Deliver at the agent's next tool call instead of its next turn</TooltipContent>
|
|
293
|
+
</Tooltip>}
|
|
294
|
+
<Tooltip>
|
|
295
|
+
<TooltipTrigger asChild disabled={busy} onClick={event => event.stopPropagation()}>
|
|
296
|
+
<Button type="submit" size="icon" className="rounded-md" aria-label={sendName} disabled={busy || !canSend}><ArrowUp/></Button>
|
|
297
|
+
</TooltipTrigger>
|
|
298
|
+
<TooltipContent side="top">{sendName}</TooltipContent>
|
|
299
|
+
</Tooltip>
|
|
300
|
+
</div>
|
|
301
|
+
</div>
|
|
302
|
+
</TooltipProvider>
|
|
303
|
+
</ComposerPrimitive.Root>
|
|
304
|
+
</ImagePicker>
|
|
305
|
+
</div>
|
|
306
|
+
</div>;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function subscribeCoarse(change) {
|
|
310
|
+
const query = window.matchMedia?.(COARSE_POINTER);
|
|
311
|
+
query?.addEventListener("change", change);
|
|
312
|
+
return () => query?.removeEventListener("change", change);
|
|
313
|
+
}
|