@temmo/cli 0.0.0-stage → 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 +110 -4
- 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,148 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "@ui-sdk/react/collapsible";
|
|
3
|
+
import { Drawer, DrawerBackdrop, DrawerClose, DrawerContent, DrawerTitle } from "@ui-sdk/react/drawer";
|
|
4
|
+
import { ChevronRight, LoaderCircle, SquareTerminal, X } from "lucide-react";
|
|
5
|
+
import { type ReactNode, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
6
|
+
import { CARD, SurfaceContext } from "@/components/a2ui/surface";
|
|
7
|
+
import { runOutcome, runSurfaceId } from "@/lib/a2ui-run";
|
|
8
|
+
import { runSummary } from "@/lib/run-row";
|
|
9
|
+
import { cn } from "@/lib/utils";
|
|
10
|
+
import { type Decide, type Density, FULL, type Focus, DecidedCard, PendingCard, RunChip, type RunRequest, RunSheet } from "./run-card";
|
|
11
|
+
|
|
12
|
+
type Payload = { forwardedProps?: { a2uiAction?: { userAction?: unknown } } };
|
|
13
|
+
type Surfaces = { submit: ((payload: Payload) => Promise<boolean | string>) | null; disabled: boolean };
|
|
14
|
+
|
|
15
|
+
// The strip's cap: 35% of a tall phone, up to 40% of a short one so a waiting card still fits whole.
|
|
16
|
+
const CAP = "max-h-[max(35dvh,min(40dvh,16.5rem))]";
|
|
17
|
+
const ROW = cn(CARD, "flex min-h-11 items-center gap-2 py-2 text-left text-xs focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring");
|
|
18
|
+
// Each step shows less, in this order, until every card fits the strip whole: the script preview; the waiting card
|
|
19
|
+
// joins the open list; an open row hides its siblings; output previews shrink, then go with the reason's second line;
|
|
20
|
+
// Run and Reject move into the heading; then rows past the newest go behind an "earlier runs" row.
|
|
21
|
+
const STEPS: Partial<Density>[] = [{}, { preview: 0 }, {}, {}, { output: 3 }, { reasonLines: 1, output: 0 }, { actionsInHeader: true, cwd: false }];
|
|
22
|
+
const density = (level: number): Density => Object.assign({ ...FULL }, ...STEPS.slice(0, level + 1));
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Run-in-terminal requests above the chat. The newest waiting run shows as a card with Run and Reject; everything else
|
|
26
|
+
* folds into one summary line ("1 more waiting · Running 1 · 3 done") that opens to a row per run, each row opening to
|
|
27
|
+
* its card. Every card renders whole: the strip steps down to a more compact layout instead of clipping or scrolling.
|
|
28
|
+
* A Run or Reject click shows its outcome at once and reverts when the server refuses it. Nothing renders while the feature is off.
|
|
29
|
+
*/
|
|
30
|
+
export function RunRequests({ requests, now }: { requests?: RunRequest[]; now: number }) {
|
|
31
|
+
const context = useContext(SurfaceContext) as Surfaces;
|
|
32
|
+
const [clicked, setClicked] = useState<Record<string, string>>({});
|
|
33
|
+
const shown = useMemo(() => (requests || []).map(request => clicked[request.id] && request.status === "pending"
|
|
34
|
+
? { ...request, status: clicked[request.id] } : request), [requests, clicked]);
|
|
35
|
+
const [listOpen, setListOpen] = useState(false);
|
|
36
|
+
const [expanded, setExpanded] = useState("");
|
|
37
|
+
const [sheet, setSheet] = useState<{ id: string; focus: Focus } | null>(null);
|
|
38
|
+
const [allRuns, setAllRuns] = useState(false);
|
|
39
|
+
const [height, setHeight] = useState(0);
|
|
40
|
+
const strip = useRef<HTMLDivElement>(null);
|
|
41
|
+
const inner = useRef<HTMLDivElement>(null);
|
|
42
|
+
|
|
43
|
+
const upstream = context.submit;
|
|
44
|
+
const decide: Decide | undefined = useMemo(() => upstream ? async (request, decision, sha256) => {
|
|
45
|
+
setClicked(current => ({ ...current, [request.id]: decision === "run" ? "running" : "rejected" }));
|
|
46
|
+
const userAction = { surfaceId: runSurfaceId(request.id), name: decision, context: decision === "run" ? { id: request.id, sha256 } : { id: request.id } };
|
|
47
|
+
const ok = await upstream({ forwardedProps: { a2uiAction: { userAction } } });
|
|
48
|
+
if (ok === false) setClicked(current => Object.fromEntries(Object.entries(current).filter(([id]) => id !== request.id)));
|
|
49
|
+
} : undefined, [upstream]);
|
|
50
|
+
|
|
51
|
+
const open = (request: RunRequest) => request.status === "pending" && request.expiresAt > now;
|
|
52
|
+
const waiting = shown.filter(open);
|
|
53
|
+
const rest = shown.filter(request => !open(request));
|
|
54
|
+
// The fit level restarts whenever what the strip holds or the screen height changes.
|
|
55
|
+
const key = [listOpen, expanded, height, shown.map(request => request.id + request.status).join()].join("|");
|
|
56
|
+
const [fit, setFit] = useState({ key, level: 0 });
|
|
57
|
+
const level = fit.key === key ? fit.level : 0;
|
|
58
|
+
const max = STEPS.length - 1 + waiting.length + rest.length;
|
|
59
|
+
const check = useCallback(() => {
|
|
60
|
+
const node = strip.current;
|
|
61
|
+
if (!node || node.scrollHeight <= node.clientHeight + 1) return;
|
|
62
|
+
setFit(current => {
|
|
63
|
+
const at = current.key === key ? current.level : 0;
|
|
64
|
+
return at < max ? { key, level: at + 1 } : current;
|
|
65
|
+
});
|
|
66
|
+
}, [key, max]);
|
|
67
|
+
useLayoutEffect(check);
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
const resize = () => setHeight(window.innerHeight);
|
|
70
|
+
resize();
|
|
71
|
+
window.addEventListener("resize", resize);
|
|
72
|
+
const observer = new ResizeObserver(check);
|
|
73
|
+
if (inner.current) observer.observe(inner.current);
|
|
74
|
+
return () => { window.removeEventListener("resize", resize); observer.disconnect(); };
|
|
75
|
+
}, [check]);
|
|
76
|
+
|
|
77
|
+
if (!shown.length) return null;
|
|
78
|
+
const fitted = density(level);
|
|
79
|
+
const show = (request: RunRequest) => (focus: Focus) => setSheet({ id: request.id, focus });
|
|
80
|
+
// The newest waiting run is the card; with the list open at step 2 it joins the rows so they fit.
|
|
81
|
+
const card = listOpen && level >= 2 ? null : waiting[0];
|
|
82
|
+
const waitingRows = waiting.filter(request => request !== card);
|
|
83
|
+
const rows = [...waitingRows, ...rest];
|
|
84
|
+
// An open row hides its siblings instead, so the row limit never drops it.
|
|
85
|
+
const limit = level > STEPS.length - 1 && !expanded ? Math.max(0, rows.length - (level - (STEPS.length - 1))) : rows.length;
|
|
86
|
+
const hideSiblings = Boolean(expanded) && level >= 3;
|
|
87
|
+
const summary = [waiting.length > 1 && `${waiting.length - 1} more waiting`, runSummary(rest)].filter(Boolean).join(" · ");
|
|
88
|
+
const sheetRequest = sheet && shown.find(request => request.id === sheet.id);
|
|
89
|
+
const row = (request: RunRequest, density: Density) => <RunRow key={request.id} request={request} waiting={open(request)}
|
|
90
|
+
expanded={expanded === request.id} toggle={next => setExpanded(next ? request.id : "")} hidden={hideSiblings && expanded !== request.id}>
|
|
91
|
+
{open(request) ? <PendingCard request={request} density={density} decide={decide} disabled={context.disabled} open={show(request)} inRow/>
|
|
92
|
+
: <DecidedCard request={request} density={density} open={show(request)}/>}
|
|
93
|
+
</RunRow>;
|
|
94
|
+
|
|
95
|
+
return <>
|
|
96
|
+
<div ref={strip} data-run-requests data-fit={level} className={cn("mx-auto mt-2 flex w-full max-w-3xl shrink-0 flex-col overflow-y-auto overscroll-y-contain", CAP)}>
|
|
97
|
+
<div ref={inner} className="flex flex-col gap-1.5">
|
|
98
|
+
{rows.length > 0 && <Collapsible data-run-summary open={listOpen} onOpenChange={setListOpen} className="group/runs min-w-0">
|
|
99
|
+
<CollapsibleTrigger className={ROW}>
|
|
100
|
+
{rest.some(request => request.status === "running")
|
|
101
|
+
? <LoaderCircle aria-hidden className="size-3.5 shrink-0 animate-spin text-muted-foreground motion-reduce:animate-none"/>
|
|
102
|
+
: <SquareTerminal aria-hidden className="size-3.5 shrink-0 text-muted-foreground"/>}
|
|
103
|
+
<span className="min-w-0 flex-1 truncate font-medium">{summary}</span>
|
|
104
|
+
<ChevronRight aria-hidden className="size-3.5 shrink-0 text-muted-foreground transition-transform group-data-[open]/runs:rotate-90 motion-reduce:transition-none"/>
|
|
105
|
+
</CollapsibleTrigger>
|
|
106
|
+
<CollapsiblePanel className="mt-1.5 flex flex-col gap-1.5">
|
|
107
|
+
{rows.slice(0, limit).map(request => row(request, fitted))}
|
|
108
|
+
{limit < rows.length && <button type="button" className={ROW} onClick={() => setAllRuns(true)} hidden={hideSiblings}>
|
|
109
|
+
<span className="min-w-0 flex-1 truncate font-medium">{rows.length - limit} earlier {rows.length - limit === 1 ? "run" : "runs"}</span>
|
|
110
|
+
<ChevronRight aria-hidden className="size-3.5 shrink-0 text-muted-foreground"/>
|
|
111
|
+
</button>}
|
|
112
|
+
</CollapsiblePanel>
|
|
113
|
+
</Collapsible>}
|
|
114
|
+
{card && <PendingCard request={card} density={fitted} decide={decide} disabled={context.disabled} open={show(card)}/>}
|
|
115
|
+
</div>
|
|
116
|
+
</div>
|
|
117
|
+
{allRuns && <Drawer open onOpenChange={(next: boolean) => { if (!next) setAllRuns(false); }}>
|
|
118
|
+
<DrawerBackdrop className="bg-black/30"/>
|
|
119
|
+
<DrawerContent initialFocus="content" className="flex h-[92dvh] w-full flex-col rounded-t-3xl bg-card shadow-raised">
|
|
120
|
+
<div aria-hidden className="mx-auto mt-2 h-1.5 w-10 shrink-0 rounded-full bg-muted-foreground/30"/>
|
|
121
|
+
<header className="flex shrink-0 items-center gap-2 border-b px-4 pt-1 pb-2">
|
|
122
|
+
<DrawerTitle className="min-w-0 flex-1 truncate text-base font-medium">Runs in terminal</DrawerTitle>
|
|
123
|
+
<DrawerClose aria-label="Close" className="grid size-11 shrink-0 place-items-center rounded-md text-muted-foreground hover:bg-accent hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring">
|
|
124
|
+
<X aria-hidden className="size-4"/>
|
|
125
|
+
</DrawerClose>
|
|
126
|
+
</header>
|
|
127
|
+
<div className="flex min-h-0 flex-1 flex-col gap-1.5 overflow-y-auto overscroll-contain px-3 py-3">{rows.map(request => row(request, FULL))}</div>
|
|
128
|
+
</DrawerContent>
|
|
129
|
+
</Drawer>}
|
|
130
|
+
{sheet && sheetRequest && <RunSheet request={sheetRequest} waiting={open(sheetRequest)} focus={sheet.focus} close={() => setSheet(null)} decide={decide} disabled={context.disabled}/>}
|
|
131
|
+
</>;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** One run as a line (state chip, outcome, reason) that opens to its card. */
|
|
135
|
+
function RunRow({ request, waiting, expanded, toggle, hidden, children }: {
|
|
136
|
+
request: RunRequest; waiting: boolean; expanded: boolean; toggle: (open: boolean) => void; hidden: boolean; children: ReactNode;
|
|
137
|
+
}) {
|
|
138
|
+
const outcome = request.status === "pending" ? "Expired before anyone ran it" : runOutcome(request);
|
|
139
|
+
return <Collapsible {...(waiting ? { "data-run-waiting": request.id } : { "data-run-decided": request.id })} open={expanded} onOpenChange={toggle}
|
|
140
|
+
hidden={hidden} className="group/row min-w-0">
|
|
141
|
+
<CollapsibleTrigger className={ROW}>
|
|
142
|
+
<ChevronRight aria-hidden className="size-3.5 shrink-0 text-muted-foreground transition-transform group-data-[open]/row:rotate-90 motion-reduce:transition-none"/>
|
|
143
|
+
<RunChip request={request} waiting={waiting}/>
|
|
144
|
+
<span className="min-w-0 flex-1 truncate text-muted-foreground">{waiting ? request.reason : `${outcome} · ${request.reason}`}</span>
|
|
145
|
+
</CollapsibleTrigger>
|
|
146
|
+
<CollapsiblePanel className="mt-1.5">{children}</CollapsiblePanel>
|
|
147
|
+
</Collapsible>;
|
|
148
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { CalendarClock, SquareArrowOutUpRight } from "lucide-react";
|
|
3
|
+
import { Sheet, SheetContent, SheetDescription, SheetTitle } from "@/components/ui/sheet";
|
|
4
|
+
import { cn } from "@/lib/utils";
|
|
5
|
+
import { commandLabel, jobAgent, jobDetail, runLabel, runLink } from "@/lib/scheduled";
|
|
6
|
+
|
|
7
|
+
const POLL_MS = 60_000;
|
|
8
|
+
|
|
9
|
+
const when = (value) => value ? new Date(value).toLocaleString(undefined, { month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" }) : "";
|
|
10
|
+
|
|
11
|
+
async function getJson(path) {
|
|
12
|
+
try {
|
|
13
|
+
const response = await fetch(path, { cache: "no-store" });
|
|
14
|
+
return response.ok ? await response.json() : { status: "offline", error: "HTTP " + response.status };
|
|
15
|
+
} catch {
|
|
16
|
+
return { status: "offline" };
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** One run row: status, time and any error; a run whose command resumes a session opens that run's timeline. */
|
|
21
|
+
function RunRow({ run, link, open }) {
|
|
22
|
+
const body = <span className="flex min-w-0 items-baseline gap-2">
|
|
23
|
+
<span className="shrink-0 font-medium">{run.status}</span>
|
|
24
|
+
<span className="min-w-0 truncate text-muted-foreground">{when(run.scheduledTime)}</span>
|
|
25
|
+
{runLabel(run) && <span className="shrink-0 text-muted-foreground">{runLabel(run)}{run.finishedAt && Number.isSafeInteger(run.startedAt) ? " · " + Math.max(0, Math.round((run.finishedAt - run.startedAt) / 1000)) + "s" : ""}</span>}
|
|
26
|
+
{link && <SquareArrowOutUpRight aria-hidden className="ml-auto size-3.5 shrink-0 text-muted-foreground"/>}
|
|
27
|
+
</span>;
|
|
28
|
+
return <li className="flex min-w-0 flex-col gap-0.5 rounded-lg border px-2 py-1.5">
|
|
29
|
+
{link ? <a href={link} onClick={event => { event.preventDefault(); open(link); }}
|
|
30
|
+
aria-label={run.status + " run at " + when(run.scheduledTime) + ", open its session timeline"}
|
|
31
|
+
className="flex min-w-0 rounded-md text-xs underline-offset-2 hover:underline">{body}</a>
|
|
32
|
+
: <span className="flex min-w-0 text-xs">{body}</span>}
|
|
33
|
+
{run.error && <span className="break-words text-xs text-destructive">{run.error}</span>}
|
|
34
|
+
</li>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The job's recent tick rows, newest first: status, time and any error; a run links to its session timeline. */
|
|
38
|
+
function RunList({ runs, project, open }) {
|
|
39
|
+
if (!runs) return <p className="text-xs text-muted-foreground">Loading runs…</p>;
|
|
40
|
+
if (runs.error) return <p className="text-xs text-muted-foreground">{runs.error}</p>;
|
|
41
|
+
if (!runs.length) return <p className="text-xs text-muted-foreground">No runs yet.</p>;
|
|
42
|
+
// Each run's window is clamped against its neighbours, so the runs link to different slices of one timeline.
|
|
43
|
+
return <ul aria-label="Recent runs" className="flex flex-col gap-2">
|
|
44
|
+
{runs.map(run => <RunRow key={run.id} run={run} link={runLink(run, project, runs)} open={open}/>)}
|
|
45
|
+
</ul>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The runner's schedules in the sidebar; each is a job, not an agent. A run opens its session timeline. */
|
|
49
|
+
export function ScheduledJobs({ project = "", openRun }) {
|
|
50
|
+
const [list, setList] = useState(null);
|
|
51
|
+
const [open, setOpen] = useState("");
|
|
52
|
+
const [runs, setRuns] = useState({});
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
let alive = true;
|
|
55
|
+
const load = async () => { const next = await getJson("/api/schedules"); if (alive) setList(next); };
|
|
56
|
+
load();
|
|
57
|
+
const timer = setInterval(load, POLL_MS);
|
|
58
|
+
return () => { alive = false; clearInterval(timer); };
|
|
59
|
+
}, []);
|
|
60
|
+
async function show(name) {
|
|
61
|
+
setOpen(name);
|
|
62
|
+
if (runs[name]) return;
|
|
63
|
+
const next = await getJson("/api/schedules?runs=" + encodeURIComponent(name));
|
|
64
|
+
setRuns(prev => ({ ...prev, [name]: next.error ? { error: next.error } : next }));
|
|
65
|
+
}
|
|
66
|
+
const job = (list?.schedules || []).find(item => item.name === open);
|
|
67
|
+
// A run link is the console's own hash: close the sheets and hand it to the console, which parses it like any hash.
|
|
68
|
+
const openAt = hash => { setOpen(""); openRun?.(hash); };
|
|
69
|
+
return <section aria-label="Scheduled jobs" className="px-2 pb-2">
|
|
70
|
+
<h2 className="flex items-center gap-1.5 pb-2 text-xs font-medium text-muted-foreground"><CalendarClock className="size-3.5"/>Scheduled jobs</h2>
|
|
71
|
+
{!list ? <p className="px-1 text-sm text-muted-foreground">Loading schedules…</p>
|
|
72
|
+
: list.status !== "up" ? <p className="px-1 text-sm text-muted-foreground">runner offline</p>
|
|
73
|
+
: <>
|
|
74
|
+
{list.schedules?.length === 0 && <p className="px-1 text-sm text-muted-foreground">No schedules in schedules.json.</p>}
|
|
75
|
+
<ul className="flex flex-col gap-1">
|
|
76
|
+
{(list.schedules || []).map(item => <li key={item.name}>
|
|
77
|
+
<button type="button" aria-haspopup="dialog" aria-label={"Schedule " + item.name} onClick={() => show(item.name)}
|
|
78
|
+
className={cn("flex w-full min-w-0 flex-col gap-0.5 rounded-xl px-2 py-1.5 text-left text-sm transition-colors hover:bg-sidebar-accent", open === item.name && "bg-sidebar-accent")}>
|
|
79
|
+
<span className="truncate font-medium">{item.name} <span className="font-normal text-muted-foreground">· every {item.everyMs / 60_000} min</span></span>
|
|
80
|
+
{item.command && <span className="truncate font-mono text-xs text-muted-foreground" title={item.command.join(" ")}>{commandLabel(item.command)}</span>}
|
|
81
|
+
<span className="text-xs text-muted-foreground">last {item.last ? item.last.status + " " + when(item.last.scheduledTime) : "never"} · next {when(item.nextRun)}</span>
|
|
82
|
+
{jobAgent(item) && <span className="truncate text-xs text-muted-foreground">resumes <span className="font-mono">{jobAgent(item)}</span></span>}
|
|
83
|
+
</button>
|
|
84
|
+
</li>)}
|
|
85
|
+
</ul>
|
|
86
|
+
{list.configError?.length > 0 && <p className="px-1 pt-1 text-xs text-primary">{list.configError.length} schedule entries skipped</p>}
|
|
87
|
+
</>}
|
|
88
|
+
<Sheet open={Boolean(job)} onOpenChange={next => { if (!next) setOpen(""); }}>
|
|
89
|
+
<SheetContent side="bottom" className="max-h-[85vh] overflow-y-auto">
|
|
90
|
+
{job && <>
|
|
91
|
+
<div className="px-4 pt-4"><SheetTitle>{job.name}</SheetTitle>
|
|
92
|
+
<SheetDescription>Scheduled job, read-only</SheetDescription></div>
|
|
93
|
+
<dl className="grid grid-cols-[auto_1fr] gap-x-3 gap-y-2 px-4 text-sm">
|
|
94
|
+
{jobDetail(job).map(([label, value]) => <div key={label} className="contents">
|
|
95
|
+
<dt className="text-muted-foreground">{label}</dt>
|
|
96
|
+
<dd className="min-w-0 break-all font-mono text-xs">{value}</dd>
|
|
97
|
+
</div>)}
|
|
98
|
+
</dl>
|
|
99
|
+
<h3 className="px-4 pb-2 pt-4 text-xs font-medium text-muted-foreground">Recent runs</h3>
|
|
100
|
+
<div className="px-4 pb-6"><RunList runs={runs[job.name]} project={project} open={openAt}/></div>
|
|
101
|
+
</>}
|
|
102
|
+
</SheetContent>
|
|
103
|
+
</Sheet>
|
|
104
|
+
</section>;
|
|
105
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
// The panel beside a thread's chat: its diff, its pull requests, the session's subagent activity, the project's tasks and raw tool calls.
|
|
3
|
+
// A side column from md up; a bottom sheet on a phone.
|
|
4
|
+
import { Component, lazy, Suspense, useEffect, useMemo, useState, type ReactNode } from "react";
|
|
5
|
+
import { ChevronRight, ExternalLink, GitPullRequest, X } from "lucide-react";
|
|
6
|
+
import { useTheme } from "next-themes";
|
|
7
|
+
import { Tabs, TabsList, TabsPanel, TabsTab } from "@ui-sdk/react/tabs";
|
|
8
|
+
import { Drawer, DrawerBackdrop, DrawerContent, DrawerTitle } from "@ui-sdk/react/drawer";
|
|
9
|
+
import { cn } from "@/lib/utils";
|
|
10
|
+
import { Button } from "@/components/ui/button";
|
|
11
|
+
import type { Thread } from "@/lib/thread-groups";
|
|
12
|
+
import { api } from "./chat-api";
|
|
13
|
+
import { Counts } from "./tool-diff";
|
|
14
|
+
|
|
15
|
+
export const PANEL_TABS = [["diff", "Diff"], ["pr", "PR"], ["subagents", "Activity"], ["tasks", "Tasks"], ["raw", "Raw"]] as const;
|
|
16
|
+
export type PanelTab = (typeof PANEL_TABS)[number][0];
|
|
17
|
+
const PatchDiff = lazy(() => import("@pierre/diffs/react").then(mod => ({ default: mod.PatchDiff })));
|
|
18
|
+
const DIFF_OPTIONS = { overflow: "wrap", disableFileHeader: true, theme: { dark: "github-dark", light: "github-light" }, diffStyle: "unified" };
|
|
19
|
+
const FILE_START = /^diff --git /m;
|
|
20
|
+
const TAB = "inline-flex h-8 items-center rounded-sm px-2.5 text-sm text-muted-foreground hover:text-foreground data-selected:bg-primary/10 data-selected:text-primary data-selected:text-foreground max-md:h-11";
|
|
21
|
+
const PR_STATE = { open: "Open", draft: "Draft", merged: "Merged", closed: "Closed" } satisfies Record<string, string>;
|
|
22
|
+
|
|
23
|
+
type DiffFile = { path: string; text: string; added: number; removed: number };
|
|
24
|
+
type DiffState = { status: "idle" | "loading" | "done" | "error"; text?: string; error?: string };
|
|
25
|
+
|
|
26
|
+
// Shows the fallback when the lazy diff chunk fails to load or render.
|
|
27
|
+
class Boundary extends Component<{ fallback: ReactNode; children: ReactNode }, { failed: boolean }> {
|
|
28
|
+
state = { failed: false };
|
|
29
|
+
static getDerivedStateFromError() { return { failed: true }; }
|
|
30
|
+
render() { return this.state.failed ? this.props.fallback : this.props.children; }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** One file per `diff --git` header, with its path and line counts. */
|
|
34
|
+
export function splitPatch(text: string): DiffFile[] {
|
|
35
|
+
return text.split(FILE_START).filter(Boolean).map(chunk => {
|
|
36
|
+
const body = "diff --git " + chunk;
|
|
37
|
+
const lines = body.split("\n");
|
|
38
|
+
const target = lines.find(line => line.startsWith("+++ "))?.slice(4).replace(/^b\//, "");
|
|
39
|
+
const source = lines.find(line => line.startsWith("--- "))?.slice(4).replace(/^a\//, "");
|
|
40
|
+
const header = /^diff --git a\/(.+?) b\//.exec(lines[0])?.[1] || "";
|
|
41
|
+
const path = target && target !== "/dev/null" ? target : source && source !== "/dev/null" ? source : header;
|
|
42
|
+
const hunk = lines.findIndex(line => line.startsWith("@@"));
|
|
43
|
+
const changed = hunk < 0 ? [] : lines.slice(hunk);
|
|
44
|
+
return { path, text: body, added: changed.filter(line => line.startsWith("+")).length, removed: changed.filter(line => line.startsWith("-")).length };
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Opens the thread's branch as a ready-for-review PR into main; hidden when the thread already has an open PR.
|
|
49
|
+
function CreatePr({ project, thread }: { project: string; thread: Thread }) {
|
|
50
|
+
const [busy, setBusy] = useState(false);
|
|
51
|
+
const [opened, setOpened] = useState<{ status: string; url: string } | null>(null);
|
|
52
|
+
const [error, setError] = useState("");
|
|
53
|
+
if (!thread.branch || thread.prs?.some(pr => pr.state === "open" || pr.state === "draft")) return null;
|
|
54
|
+
async function create() {
|
|
55
|
+
setBusy(true);
|
|
56
|
+
setError("");
|
|
57
|
+
try {
|
|
58
|
+
const body = await api("create-pr", { project, thread: thread.id });
|
|
59
|
+
setOpened({ status: body.status, url: body.url });
|
|
60
|
+
} catch (err) {
|
|
61
|
+
setError((err as Error).message);
|
|
62
|
+
} finally {
|
|
63
|
+
setBusy(false);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return <div className="flex flex-wrap items-center gap-2 text-sm">
|
|
67
|
+
{opened
|
|
68
|
+
? <a href={opened.url} target="_blank" rel="noreferrer noopener" className="break-all underline">{opened.status}: {opened.url}</a>
|
|
69
|
+
: <Button type="button" variant="outline" className="max-md:min-h-11" disabled={busy} onClick={create}>{busy ? "Opening PR…" : "Create PR"}</Button>}
|
|
70
|
+
{error && <p role="alert" className="break-words text-destructive">{error}</p>}
|
|
71
|
+
</div>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function DiffView({ project, thread }: { project: string; thread?: Thread }) {
|
|
75
|
+
const [state, setState] = useState<DiffState>({ status: "idle" });
|
|
76
|
+
const { resolvedTheme } = useTheme();
|
|
77
|
+
const options = useMemo(() => ({ ...DIFF_OPTIONS, themeType: resolvedTheme === "light" ? "light" : "dark" }), [resolvedTheme]);
|
|
78
|
+
const id = thread?.id || "";
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (!id) return;
|
|
81
|
+
let live = true;
|
|
82
|
+
setState({ status: "loading" });
|
|
83
|
+
fetch("/api/thread-diff?" + new URLSearchParams({ project, thread: id }), { cache: "no-store" })
|
|
84
|
+
.then(async response => {
|
|
85
|
+
const text = await response.text();
|
|
86
|
+
if (!live) return;
|
|
87
|
+
if (response.ok) setState({ status: "done", text });
|
|
88
|
+
else setState({ status: "error", error: (() => { try { return JSON.parse(text).error; } catch { return text; } })() || "The diff is unavailable" });
|
|
89
|
+
})
|
|
90
|
+
.catch(error => { if (live) setState({ status: "error", error: error.message }); });
|
|
91
|
+
return () => { live = false; };
|
|
92
|
+
}, [project, id]);
|
|
93
|
+
if (!thread) return <Empty>This session belongs to no thread, so there is no branch to diff.</Empty>;
|
|
94
|
+
if (state.status === "loading" || state.status === "idle") return <Empty>Loading the diff…</Empty>;
|
|
95
|
+
if (state.status === "error") return <p role="alert" className="px-3 py-4 text-sm text-destructive">{state.error}</p>;
|
|
96
|
+
const files = splitPatch(state.text || "");
|
|
97
|
+
if (!files.length) return <Empty>No changes against {thread.baseRef || "the base branch"} yet.</Empty>;
|
|
98
|
+
return <div className="flex min-w-0 flex-col gap-2 p-3">
|
|
99
|
+
<p className="text-xs text-muted-foreground">{files.length} file{files.length === 1 ? "" : "s"} changed against <span className="font-mono">{thread.baseRef || "origin/HEAD"}</span></p>
|
|
100
|
+
<CreatePr project={project} thread={thread}/>
|
|
101
|
+
{files.map(file => {
|
|
102
|
+
const plain = <pre className="overflow-x-auto px-2.5 py-1.5 font-mono text-xs">{file.text}</pre>;
|
|
103
|
+
return <details key={file.path} open={files.length <= 8} className="group min-w-0 overflow-hidden rounded-md border bg-card text-xs">
|
|
104
|
+
<summary className="flex cursor-pointer list-none items-center gap-2 px-2.5 py-1.5 group-open:border-b [&::-webkit-details-marker]:hidden">
|
|
105
|
+
<ChevronRight aria-hidden className="size-3.5 shrink-0 text-muted-foreground transition-transform group-open:rotate-90 motion-reduce:transition-none"/>
|
|
106
|
+
<span className="min-w-0 flex-1 truncate font-mono" title={file.path}>{file.path}</span>
|
|
107
|
+
<Counts added={file.added} removed={file.removed} className=""/>
|
|
108
|
+
</summary>
|
|
109
|
+
<Boundary fallback={plain}>
|
|
110
|
+
<Suspense fallback={plain}>
|
|
111
|
+
<div className="min-w-0 [&_pre]:text-xs"><PatchDiff patch={file.text} options={options as never} disableWorkerPool/></div>
|
|
112
|
+
</Suspense>
|
|
113
|
+
</Boundary>
|
|
114
|
+
</details>;
|
|
115
|
+
})}
|
|
116
|
+
</div>;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function PrView({ thread }: { thread?: Thread }) {
|
|
120
|
+
if (!thread) return <Empty>This session belongs to no thread.</Empty>;
|
|
121
|
+
if (!thread.prs?.length) return <Empty>No pull request is attached to this thread.</Empty>;
|
|
122
|
+
return <ul className="flex flex-col divide-y">
|
|
123
|
+
{thread.prs.map(pr => <li key={pr.id || pr.number} className="flex min-w-0 items-center gap-3 px-3 py-2.5 text-sm">
|
|
124
|
+
<GitPullRequest aria-hidden className={cn("size-4 shrink-0", pr.state === "open" ? "text-foreground" : "text-muted-foreground")}/>
|
|
125
|
+
<span className="flex min-w-0 flex-1 flex-col">
|
|
126
|
+
<span className="font-medium">#{pr.number} · {PR_STATE[pr.state as keyof typeof PR_STATE] || pr.state}</span>
|
|
127
|
+
{(pr.head || pr.base) && <span className="truncate font-mono text-xs text-muted-foreground" title={pr.head + " into " + pr.base}>{pr.head} → {pr.base}</span>}
|
|
128
|
+
</span>
|
|
129
|
+
{pr.url && <a href={pr.url} target="_blank" rel="noreferrer noopener" className="inline-flex shrink-0 items-center gap-1 rounded-sm px-1.5 py-1 text-xs text-muted-foreground hover:bg-accent hover:text-foreground">
|
|
130
|
+
Open<ExternalLink aria-hidden className="size-3"/></a>}
|
|
131
|
+
</li>)}
|
|
132
|
+
</ul>;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function Empty({ children }: { children: ReactNode }) {
|
|
136
|
+
return <p className="px-3 py-8 text-center text-sm text-muted-foreground">{children}</p>;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
type PanelProps = {
|
|
140
|
+
tab: PanelTab; setTab: (tab: PanelTab) => void; close: () => void; project: string; thread?: Thread; activity?: ReactNode; raw?: ReactNode;
|
|
141
|
+
tasks: ReactNode; tabs?: PanelTab[];
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
function PanelBody({ tab, setTab, close, project, thread, activity, raw, tasks, tabs }: PanelProps) {
|
|
145
|
+
return <Tabs value={tab} onValueChange={(next: unknown) => setTab(next as PanelTab)} className="flex h-full min-h-0 flex-col">
|
|
146
|
+
<div className="flex shrink-0 items-center gap-1 border-b px-2 py-1.5">
|
|
147
|
+
<TabsList aria-label="Panel" className="flex flex-1 items-center gap-0.5">
|
|
148
|
+
{PANEL_TABS.filter(([id]) => !tabs || tabs.includes(id)).map(([id, label]) => <TabsTab key={id} value={id} className={TAB}>{label}</TabsTab>)}
|
|
149
|
+
</TabsList>
|
|
150
|
+
<button type="button" aria-label="Close panel" onClick={close}
|
|
151
|
+
className="grid size-8 shrink-0 place-items-center rounded-sm text-muted-foreground hover:bg-accent hover:text-foreground max-md:size-11"><X aria-hidden className="size-4"/></button>
|
|
152
|
+
</div>
|
|
153
|
+
<TabsPanel value="diff" className="min-h-0 flex-1 overflow-y-auto">{tab === "diff" && <DiffView project={project} thread={thread}/>}</TabsPanel>
|
|
154
|
+
<TabsPanel value="pr" className="min-h-0 flex-1 overflow-y-auto"><PrView thread={thread}/></TabsPanel>
|
|
155
|
+
<TabsPanel value="subagents" className="min-h-0 flex-1 overflow-y-auto px-3 py-3">{tab === "subagents" && activity}</TabsPanel>
|
|
156
|
+
<TabsPanel value="tasks" className="min-h-0 flex-1 overflow-y-auto px-3 py-3">{tab === "tasks" && tasks}</TabsPanel>
|
|
157
|
+
<TabsPanel value="raw" className="min-h-0 flex-1 overflow-y-auto px-3 py-3">{tab === "raw" && raw}</TabsPanel>
|
|
158
|
+
</Tabs>;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** The panel as a right column (wide) or a bottom sheet (phone); `wide` comes from the console's media query. */
|
|
162
|
+
export function SessionPanel({ wide, ...props }: PanelProps & { wide: boolean }) {
|
|
163
|
+
if (wide) return <aside aria-label="Thread panel" className="relative z-10 flex w-[min(34rem,40vw)] shrink-0 flex-col bg-card shadow-raised">
|
|
164
|
+
<PanelBody {...props}/>
|
|
165
|
+
</aside>;
|
|
166
|
+
return <Drawer open onOpenChange={(open: boolean) => { if (!open) props.close(); }}>
|
|
167
|
+
<DrawerBackdrop className="bg-black/30"/>
|
|
168
|
+
<DrawerContent className="flex h-[85dvh] w-full flex-col rounded-t-3xl bg-card shadow-raised">
|
|
169
|
+
<DrawerTitle className="sr-only">Thread panel</DrawerTitle>
|
|
170
|
+
<div aria-hidden className="mx-auto mt-2 h-1.5 w-10 shrink-0 rounded-full bg-muted-foreground/30"/>
|
|
171
|
+
<PanelBody {...props}/>
|
|
172
|
+
</DrawerContent>
|
|
173
|
+
</Drawer>;
|
|
174
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useState, type ReactNode } from "react";
|
|
3
|
+
import { Box, Check, ChevronDown, Folder, FolderGit2, FolderTree, GitBranch, GitPullRequest, Plus, type LucideIcon } from "lucide-react";
|
|
4
|
+
import { useAsyncOptions } from "@ui-sdk/react/async-options";
|
|
5
|
+
import { Combobox, ComboboxContent, ComboboxCreate, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxItemIndicator, ComboboxList, ComboboxStatus, ComboboxTrigger } from "@ui-sdk/react/combobox";
|
|
6
|
+
import { Select, SelectContent, SelectItem, SelectItemIndicator, SelectTrigger, SelectValue } from "@ui-sdk/react/select";
|
|
7
|
+
import { cn } from "@/lib/utils";
|
|
8
|
+
import { EMPTY_PICK, createOption, envOptions, markSegments, prNumber, shortSha, triggerLabel, worktreeMarks, type EnvId, type Pick, type Pr, type Ref, type Worktree } from "@/lib/branch-picker";
|
|
9
|
+
|
|
10
|
+
const ENV_ICONS: Record<EnvId, LucideIcon> = { folder: Folder, worktree: FolderGit2, existing: FolderTree, openshell: Box };
|
|
11
|
+
const CONTROL = "inline-flex h-11 items-center gap-1.5 rounded-lg border bg-background px-2.5 text-sm sm:h-8 focus-visible:outline-2 focus-visible:outline-ring disabled:opacity-50";
|
|
12
|
+
const POPUP = "z-50 rounded-xl border bg-popover p-1 text-popover-foreground shadow-md";
|
|
13
|
+
const ITEM = "flex min-h-11 cursor-pointer items-center gap-2 rounded-lg px-2 text-sm outline-none sm:min-h-9 data-highlighted:bg-accent data-highlighted:text-accent-foreground data-disabled:cursor-default data-disabled:opacity-60";
|
|
14
|
+
const MARK = "bg-transparent font-semibold text-foreground underline underline-offset-2";
|
|
15
|
+
|
|
16
|
+
type Option = { value: string; label: string; ref?: Ref; row?: Worktree };
|
|
17
|
+
type Listing = { current: string; truncated: boolean; gh: boolean; pr: Pr | null; branches: Ref[] };
|
|
18
|
+
type BranchesBody = { current: string; branches: Ref[]; truncated: boolean; gh: boolean; pr: Pr | null };
|
|
19
|
+
type WorktreesBody = { worktrees: Worktree[]; truncated: boolean };
|
|
20
|
+
type ToolbarProps = { project: string; places: string[]; env: EnvId; setEnv: (env: EnvId) => void; pick: Pick; setPick: (pick: Pick) => void; setCurrent: (current: string) => void; disabled?: boolean };
|
|
21
|
+
|
|
22
|
+
const EMPTY_LISTING: Listing = { current: "", truncated: false, gh: false, pr: null, branches: [] };
|
|
23
|
+
|
|
24
|
+
/** Where a new session starts: the environment select, then the branch or worktree it starts from. */
|
|
25
|
+
export function SessionToolbar({ project, places, env, setEnv, pick, setPick, setCurrent, disabled }: ToolbarProps) {
|
|
26
|
+
const [current, setLocalCurrent] = useState("");
|
|
27
|
+
const remember = (next: string) => { setLocalCurrent(next); setCurrent(next); };
|
|
28
|
+
return <div role="group" aria-label="Where the session starts" className="flex min-w-0 items-center gap-1.5 px-1 pt-1.5">
|
|
29
|
+
<EnvSelect places={places} env={env} setEnv={setEnv} disabled={disabled}/>
|
|
30
|
+
{env === "worktree" || env === "existing"
|
|
31
|
+
? <BranchPicker key={env} project={project} env={env} pick={pick} setPick={setPick} current={current} setCurrent={remember} disabled={disabled}/>
|
|
32
|
+
: <CurrentBranch project={project} env={env} current={current} setCurrent={remember}/>}
|
|
33
|
+
</div>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function EnvSelect({ places, env, setEnv, disabled }: { places: string[]; env: EnvId; setEnv: (env: EnvId) => void; disabled?: boolean }) {
|
|
37
|
+
const options = envOptions(places);
|
|
38
|
+
const Icon = ENV_ICONS[env];
|
|
39
|
+
const label = options.find(option => option.id === env)?.label ?? "";
|
|
40
|
+
// One place is not a choice, so it reads as text rather than a control.
|
|
41
|
+
if (options.length < 2) {
|
|
42
|
+
return <span className="inline-flex h-11 shrink-0 items-center gap-1.5 px-1 text-sm text-muted-foreground sm:h-8"><Icon aria-hidden="true" className="size-4"/>{label}</span>;
|
|
43
|
+
}
|
|
44
|
+
return <Select value={env} onValueChange={next => { if (next !== null) setEnv(next); }} items={options.map(option => ({ value: option.id, label: option.label }))} disabled={disabled}>
|
|
45
|
+
<SelectTrigger aria-label="Environment" className={cn(CONTROL, "shrink-0")}>
|
|
46
|
+
<Icon aria-hidden="true" className="size-4 shrink-0 text-muted-foreground"/>
|
|
47
|
+
<SelectValue/>
|
|
48
|
+
<ChevronDown aria-hidden="true" className="size-3.5 shrink-0 text-muted-foreground"/>
|
|
49
|
+
</SelectTrigger>
|
|
50
|
+
<SelectContent className={cn(POPUP, "min-w-52")}>
|
|
51
|
+
{options.map(option => {
|
|
52
|
+
const OptionIcon = ENV_ICONS[option.id];
|
|
53
|
+
return <SelectItem key={option.id} value={option.id} label={option.label} className={ITEM}>
|
|
54
|
+
<OptionIcon aria-hidden="true" className="size-4 shrink-0 text-muted-foreground"/>
|
|
55
|
+
<span className="min-w-0 flex-1 truncate">{option.label}</span>
|
|
56
|
+
<SelectItemIndicator><Check aria-hidden="true" className="size-3.5 text-primary"/></SelectItemIndicator>
|
|
57
|
+
</SelectItem>;
|
|
58
|
+
})}
|
|
59
|
+
</SelectContent>
|
|
60
|
+
</Select>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Folder and OpenShell start from the checked-out branch; there is nothing to pick, so it is plain text.
|
|
64
|
+
function CurrentBranch({ project, env, current, setCurrent }: { project: string; env: EnvId; current: string; setCurrent: (current: string) => void }) {
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
const controller = new AbortController();
|
|
67
|
+
fetch(refsUrl(project, "branches", ""), { signal: controller.signal })
|
|
68
|
+
.then(response => (response.ok ? response.json() as Promise<BranchesBody> : null))
|
|
69
|
+
.then(body => { if (body) setCurrent(body.current); })
|
|
70
|
+
.catch(() => {});
|
|
71
|
+
return () => controller.abort();
|
|
72
|
+
}, [project]);
|
|
73
|
+
const text = triggerLabel(env, EMPTY_PICK, current);
|
|
74
|
+
return <span className="inline-flex h-11 min-w-0 items-center gap-1.5 px-1 text-sm text-muted-foreground sm:h-8">
|
|
75
|
+
<GitBranch aria-hidden="true" className="size-4 shrink-0"/><span className="truncate"><span className="sr-only">Branch: </span>{text}</span>
|
|
76
|
+
</span>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function BranchPicker({ project, env, pick, setPick, current, setCurrent, disabled }: { project: string; env: "worktree" | "existing"; pick: Pick; setPick: (pick: Pick) => void; current: string; setCurrent: (current: string) => void; disabled?: boolean }) {
|
|
80
|
+
const [button, setButton] = useState<HTMLButtonElement | null>(null);
|
|
81
|
+
const [query, setQuery] = useState("");
|
|
82
|
+
const [listing, setListing] = useState<Listing>(EMPTY_LISTING);
|
|
83
|
+
const worktrees = env === "existing";
|
|
84
|
+
const options = useAsyncOptions<Option>(async (text, { signal }) => {
|
|
85
|
+
const response = await fetch(refsUrl(project, worktrees ? "worktrees" : "branches", text), { signal });
|
|
86
|
+
if (!response.ok) throw new Error("Could not load " + (worktrees ? "worktrees" : "branches"));
|
|
87
|
+
if (worktrees) {
|
|
88
|
+
const body = await response.json() as WorktreesBody;
|
|
89
|
+
setListing(last => ({ ...last, truncated: body.truncated }));
|
|
90
|
+
return body.worktrees.map(row => ({ value: row.path, label: row.branch ?? row.path, row }));
|
|
91
|
+
}
|
|
92
|
+
const body = await response.json() as BranchesBody;
|
|
93
|
+
setListing({ current: body.current, truncated: body.truncated, gh: body.gh, pr: body.pr, branches: body.branches });
|
|
94
|
+
setCurrent(body.current);
|
|
95
|
+
return body.branches.map(ref => ({ value: ref.name, label: ref.name, ref }));
|
|
96
|
+
}, { debounce: 150, immediate: true });
|
|
97
|
+
const base = pick.base || current || "HEAD";
|
|
98
|
+
const label = triggerLabel(env, pick, current);
|
|
99
|
+
const pr = !worktrees && listing.gh && listing.pr && prNumber(query) === listing.pr.number ? listing.pr : null;
|
|
100
|
+
const create = worktrees ? null : createOption(query, listing.branches, base);
|
|
101
|
+
const noun = worktrees ? "worktrees" : "branches";
|
|
102
|
+
|
|
103
|
+
function choose(value: string | null) {
|
|
104
|
+
if (value === null) return;
|
|
105
|
+
if (worktrees) setPick({ ...EMPTY_PICK, worktreePath: value });
|
|
106
|
+
else if (value.startsWith("pr:")) { if (listing.pr?.base) setPick({ ...EMPTY_PICK, base: listing.pr.base }); }
|
|
107
|
+
// Choosing a base drops a pending new branch name; the create row sets both.
|
|
108
|
+
else setPick({ ...EMPTY_PICK, base: value });
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return <Combobox<string> items={options.items} status={options.status} filter={false} disabled={disabled}
|
|
112
|
+
value={(worktrees ? pick.worktreePath : pick.base) || null} onValueChange={choose}
|
|
113
|
+
query={query} onQueryChange={text => { setQuery(text); options.setQuery(text); }}
|
|
114
|
+
onOpenChange={open => { if (open) { setQuery(""); options.setQuery(""); } }}
|
|
115
|
+
onOpenChangeComplete={open => { if (!open) button?.focus(); }}>
|
|
116
|
+
<ComboboxTrigger ref={setButton} aria-label={(worktrees ? "Worktree: " : "Branch: ") + label} className={cn(CONTROL, "min-w-0 flex-1 sm:max-w-80 sm:flex-none")}>
|
|
117
|
+
{worktrees ? <FolderTree aria-hidden="true" className="size-4 shrink-0 text-muted-foreground"/> : <GitBranch aria-hidden="true" className="size-4 shrink-0 text-muted-foreground"/>}
|
|
118
|
+
<span className="min-w-0 truncate text-foreground">{label}</span>
|
|
119
|
+
<ChevronDown aria-hidden="true" className="ml-auto size-3.5 shrink-0 text-muted-foreground"/>
|
|
120
|
+
</ComboboxTrigger>
|
|
121
|
+
<ComboboxContent anchor={button} align="start" className={cn(POPUP, "flex w-[min(24rem,calc(100vw-1.5rem))] flex-col")}>
|
|
122
|
+
<ComboboxInput autoFocus aria-label={worktrees ? "Search worktrees" : "Search branches"} placeholder={worktrees ? "Search worktrees" : "Search branches or type a new name"}
|
|
123
|
+
className="h-10 w-full rounded-lg border-b bg-transparent px-2 text-base outline-none placeholder:text-muted-foreground sm:text-sm"/>
|
|
124
|
+
<ComboboxStatus className="px-2 py-1 text-xs text-muted-foreground empty:hidden">
|
|
125
|
+
{state => state.status === "error" ? "Could not load " + noun
|
|
126
|
+
: state.loading ? "Loading " + noun
|
|
127
|
+
: listing.truncated ? "Showing the 50 most recent; type to narrow" : ""}
|
|
128
|
+
</ComboboxStatus>
|
|
129
|
+
<ComboboxEmpty className="px-2 py-2 text-sm text-muted-foreground empty:hidden">
|
|
130
|
+
{state => state.empty && !state.loading && !create && !pr ? (worktrees ? "No worktree matches" : "No branch matches") : null}
|
|
131
|
+
</ComboboxEmpty>
|
|
132
|
+
<ComboboxList className="max-h-[min(20rem,50dvh)] overflow-y-auto overscroll-contain">
|
|
133
|
+
{pr && <ComboboxItem value={"pr:" + pr.number} label={"#" + pr.number + " " + pr.title} disabled={pr.base === null} className={ITEM}>
|
|
134
|
+
<GitPullRequest aria-hidden="true" className="size-4 shrink-0 text-muted-foreground"/>
|
|
135
|
+
<span className="flex min-w-0 flex-1 flex-col py-1">
|
|
136
|
+
<span className="truncate">#{pr.number} {pr.title}</span>
|
|
137
|
+
<span className="truncate text-xs text-muted-foreground">{pr.base === null ? "Fetch this PR first" : "head " + pr.head}</span>
|
|
138
|
+
</span>
|
|
139
|
+
</ComboboxItem>}
|
|
140
|
+
{options.items.map(option => option.row ? <WorktreeItem key={option.value} option={option} row={option.row} query={query}/> : <BranchItem key={option.value} option={option} query={query}/>)}
|
|
141
|
+
{create && <ComboboxCreate onCreate={text => setPick({ ...EMPTY_PICK, base, branch: text.trim() })} className={ITEM}>
|
|
142
|
+
<Plus aria-hidden="true" className="size-4 shrink-0 text-muted-foreground"/>
|
|
143
|
+
<span className="min-w-0 flex-1 truncate">Create branch <b className="font-semibold">{create.name}</b> from <b className="font-semibold">{create.base}</b></span>
|
|
144
|
+
</ComboboxCreate>}
|
|
145
|
+
</ComboboxList>
|
|
146
|
+
</ComboboxContent>
|
|
147
|
+
</Combobox>;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function BranchItem({ option, query }: { option: Option; query: string }) {
|
|
151
|
+
return <ComboboxItem value={option.value} label={option.label} className={ITEM}>
|
|
152
|
+
<Marked label={option.label} query={query}/>
|
|
153
|
+
{option.ref?.remote && <span className="shrink-0 text-xs text-muted-foreground">remote</span>}
|
|
154
|
+
<span className="ml-auto shrink-0 font-mono text-xs text-muted-foreground">{shortSha(option.ref?.sha ?? "")}</span>
|
|
155
|
+
<ComboboxItemIndicator><Check aria-hidden="true" className="size-3.5 text-primary"/></ComboboxItemIndicator>
|
|
156
|
+
</ComboboxItem>;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function WorktreeItem({ option, row, query }: { option: Option; row: Worktree; query: string }) {
|
|
160
|
+
return <ComboboxItem value={option.value} label={option.label} className={ITEM}>
|
|
161
|
+
<span className="flex min-w-0 flex-1 flex-col py-1">
|
|
162
|
+
{row.branch === null ? <span className="truncate">detached at {shortSha(row.head)}</span> : <Marked label={option.label} query={query}/>}
|
|
163
|
+
{/* rtl moves the ellipsis to the front, so the distinctive end of a long path stays visible */}
|
|
164
|
+
<span title={row.path} dir="rtl" className="truncate text-left text-xs text-muted-foreground"><bdi>{row.path}</bdi></span>
|
|
165
|
+
</span>
|
|
166
|
+
{worktreeMarks(row).map(mark => <span key={mark} className="shrink-0 rounded border px-1 text-xs text-muted-foreground">{mark}</span>)}
|
|
167
|
+
<ComboboxItemIndicator><Check aria-hidden="true" className="size-3.5 text-primary"/></ComboboxItemIndicator>
|
|
168
|
+
</ComboboxItem>;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// The item's label with the typed text marked, so a match is visible at a glance.
|
|
172
|
+
function Marked({ label, query }: { label: string; query: string }): ReactNode {
|
|
173
|
+
return <span className="min-w-0 truncate">
|
|
174
|
+
{markSegments(label, query).map(segment => segment.match ? <mark key={segment.at} className={MARK}>{segment.text}</mark> : <span key={segment.at}>{segment.text}</span>)}
|
|
175
|
+
</span>;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function refsUrl(project: string, kind: "branches" | "worktrees", query: string) {
|
|
179
|
+
return `/api/refs?project=${encodeURIComponent(project)}&kind=${kind}&q=${encodeURIComponent(query)}`;
|
|
180
|
+
}
|