@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,85 @@
|
|
|
1
|
+
// Choices behind the new-agent composer: the model menu grouped by harness, the mode pill, the place pill.
|
|
2
|
+
// The harness is carried by the model choice, so nothing about it is typed into the prompt.
|
|
3
|
+
import { fuzzyRank } from "./fuzzy.js";
|
|
4
|
+
import { MODE_LABELS, startModes } from "./start-mode.js";
|
|
5
|
+
import { modelsOf } from "./start-default.js";
|
|
6
|
+
export const HARNESS_LABELS = { claude: "Claude Code", codex: "Codex", cursor: "Cursor", opencode: "OpenCode", pi: "pi" };
|
|
7
|
+
/** The place pill's short label, and the full name its menu and aria-label use. */
|
|
8
|
+
export const PLACE_LABELS = { folder: "Folder", worktree: "Worktree", openshell: "OpenShell" };
|
|
9
|
+
export const PLACE_NAMES = { folder: "Local folder", worktree: "New git worktree", openshell: "OpenShell sandbox" };
|
|
10
|
+
// Claude Agent starts use the runner when code mode is on.
|
|
11
|
+
const CODE_MODE_START_HARNESSES = ["claude", "codex"];
|
|
12
|
+
/** The start payload's codeMode field: the toggle's value for a harness that has one, else nothing. */
|
|
13
|
+
export function codeModeField(harness, on, mode = "agent", place = "folder") {
|
|
14
|
+
return CODE_MODE_START_HARNESSES.includes(harness) && (harness !== "claude" || (mode === "agent" && place !== "openshell")) ? { codeMode: on === true } : {};
|
|
15
|
+
}
|
|
16
|
+
/** After the harness changes: its listed model stays if it has one, else its first model. */
|
|
17
|
+
export function chooseHarness(choice, harness, models = {}) {
|
|
18
|
+
if (choice?.harness === harness)
|
|
19
|
+
return choice;
|
|
20
|
+
const listed = modelsOf(models, harness);
|
|
21
|
+
return { harness, model: listed.includes(choice?.model) ? choice.model : listed[0] || "" };
|
|
22
|
+
}
|
|
23
|
+
/** A mode the harness supports, or its first one; "agent" when the harness names none. */
|
|
24
|
+
export function modeChoice(mode, harness) {
|
|
25
|
+
const modes = startModes(harness);
|
|
26
|
+
return modes.includes(mode) ? mode : modes[0] || "agent";
|
|
27
|
+
}
|
|
28
|
+
/** The mode pill's menu: only modes the harness supports, labelled Agent / Ask / Plan. */
|
|
29
|
+
export function modeOptions(harness) {
|
|
30
|
+
return startModes(harness).map(id => ({ id, label: MODE_LABELS[id] || id }));
|
|
31
|
+
}
|
|
32
|
+
/** The place pill's menu: only the places the server says this project can start in. */
|
|
33
|
+
export function placeOptions(places = []) {
|
|
34
|
+
return places.map(id => ({ id, label: PLACE_LABELS[id] || id, name: PLACE_NAMES[id] || id }));
|
|
35
|
+
}
|
|
36
|
+
/** The places this harness may start in: OpenShell only for a harness the server lists as able to run there. */
|
|
37
|
+
export function harnessPlaces(places = [], harness = "", sandboxHarnesses = []) {
|
|
38
|
+
return places.filter(id => id !== "openshell" || sandboxHarnesses.includes(harness));
|
|
39
|
+
}
|
|
40
|
+
/** The place pill's choice: the current one while still offered, else the configured start place, else Folder, else the first. */
|
|
41
|
+
export function placeChoice(current, places = [], preferred = "folder") {
|
|
42
|
+
if (current && places.includes(current))
|
|
43
|
+
return current;
|
|
44
|
+
if (places.includes(preferred))
|
|
45
|
+
return preferred;
|
|
46
|
+
return places.includes("folder") ? "folder" : places[0] || "folder";
|
|
47
|
+
}
|
|
48
|
+
/** What the model pill shows: the model, or its harness name while no model has loaded. */
|
|
49
|
+
export function modelLabel(choice) {
|
|
50
|
+
return choice?.model || HARNESS_LABELS[choice?.harness] || "Model";
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The model menu, grouped by harness: every startable harness with a loaded model list, in the order given. A query
|
|
54
|
+
* filters across groups by the model name, its harness label and its harness id; an empty query lists everything.
|
|
55
|
+
*/
|
|
56
|
+
export function modelGroups({ startable = [], models = {}, query = "", limit = 300 } = {}) {
|
|
57
|
+
const all = startable.flatMap(harness => modelsOf(models, harness).map(model => ({ harness, model })));
|
|
58
|
+
const text = String(query || "").trim();
|
|
59
|
+
const ranked = text ? fuzzyRank(text, all, item => [item.model, HARNESS_LABELS[item.harness], item.harness], limit) : all.slice(0, limit);
|
|
60
|
+
const groups = [];
|
|
61
|
+
for (const item of ranked) {
|
|
62
|
+
const group = groups.find(entry => entry.harness === item.harness);
|
|
63
|
+
if (group)
|
|
64
|
+
group.models.push(item.model);
|
|
65
|
+
else
|
|
66
|
+
groups.push({ harness: item.harness, label: HARNESS_LABELS[item.harness] || item.harness, models: [item.model] });
|
|
67
|
+
}
|
|
68
|
+
return groups;
|
|
69
|
+
}
|
|
70
|
+
/** The groups flattened in menu order, for keyboard selection. */
|
|
71
|
+
export function flatModels(groups) {
|
|
72
|
+
return groups.flatMap(group => group.models.map(model => ({ harness: group.harness, model })));
|
|
73
|
+
}
|
|
74
|
+
/** The row a keyboard move lands on, wrapping past either end; 0 for an empty list. */
|
|
75
|
+
export function moveActive(active, delta, length) {
|
|
76
|
+
if (length <= 0)
|
|
77
|
+
return 0;
|
|
78
|
+
return (((active + delta) % length) + length) % length;
|
|
79
|
+
}
|
|
80
|
+
/** The model Enter picks at the keyboard position, or null when the menu lists nothing. */
|
|
81
|
+
export function activeModel(listed, active) {
|
|
82
|
+
if (!listed.length)
|
|
83
|
+
return null;
|
|
84
|
+
return listed[Math.min(Math.max(active, 0), listed.length - 1)];
|
|
85
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Operator chat messages for terminal prompts and for answers to agent questions.
|
|
2
|
+
// A typed prompt within this many seconds of an operator message with the same text is that message echoed back.
|
|
3
|
+
export const ECHO_WINDOW_S = 300;
|
|
4
|
+
const peerOf = address => String(address || "").split("#")[0];
|
|
5
|
+
// A sent message reaches the prompt's session: addressed to it, its peer, or all.
|
|
6
|
+
const reaches = (message, agent) => !message.to || message.to === agent || message.to === peerOf(agent) || message.to === "all";
|
|
7
|
+
/** Prompts as chat messages, with operator echoes removed. */
|
|
8
|
+
export function terminalMessages(prompts, sent) {
|
|
9
|
+
const operator = sent.filter(message => message.from === "operator");
|
|
10
|
+
return prompts
|
|
11
|
+
.filter(item => item.system || !operator.some(message => message.body.trim() === item.input.trim() && reaches(message, item.agent) && Math.abs(message.time - item.time) <= ECHO_WINDOW_S))
|
|
12
|
+
.map(item => {
|
|
13
|
+
const sender = item.system ? "system" : "operator";
|
|
14
|
+
return { id: item.id, time: item.time, kind: "Message", sender, from: sender, to: item.agent, body: item.input, ...(item.system ? { system: true } : { terminal: true }) };
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/** The text of an operator answer: the chosen labels, the decision, or the typed reply when no decision applies. */
|
|
18
|
+
export function answerText(decision, typed) {
|
|
19
|
+
if (!decision)
|
|
20
|
+
return typed;
|
|
21
|
+
if (decision.answers)
|
|
22
|
+
return Object.values(decision.answers).join(", ");
|
|
23
|
+
return decision.behavior;
|
|
24
|
+
}
|
|
25
|
+
/** An operator answer as a chat message to the asking session, linked to its question by replyTo. */
|
|
26
|
+
export function answerMessage({ id, time, asker, question, body, by }) {
|
|
27
|
+
return { id, time, kind: "Message", sender: "operator", from: "operator", to: asker, body, replyTo: question, ...(by ? { by } : {}) };
|
|
28
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// Pattern graphs: an adapter from a listed pattern to the wteam-shaped graph, its DOT text, and the SVG layout the renderer draws.
|
|
2
|
+
export const DONE_ID = "done";
|
|
3
|
+
export const DEFAULT_KIND = "pair";
|
|
4
|
+
export const NODE_W = 120;
|
|
5
|
+
export const NODE_H = 60;
|
|
6
|
+
export const SLOT_GAP = 176;
|
|
7
|
+
export const DEPTH_GAP = 100;
|
|
8
|
+
export const PAD = 16;
|
|
9
|
+
export const LABEL_MAX = 12;
|
|
10
|
+
export const LANE_GAP = 26;
|
|
11
|
+
const CHAR_W = 6.6;
|
|
12
|
+
/**
|
|
13
|
+
* A listed pattern as a graph: nodes with agent (harness:model), count, skill and fallback; edges with on, kind, required and cap.
|
|
14
|
+
* A handoff with no kind is pair, the team.dot default; a pattern with no count or skill shows one instance and none.
|
|
15
|
+
*/
|
|
16
|
+
export function toGraph(pattern) {
|
|
17
|
+
const nodes = (pattern.roles ?? []).map(role => ({
|
|
18
|
+
id: role.id, agent: role.model ? `${role.harness}:${role.model}` : role.harness ?? "", count: role.count ?? 1, skill: role.skill ?? "",
|
|
19
|
+
...(role.fallback ? { fallback: role.fallback } : {}),
|
|
20
|
+
}));
|
|
21
|
+
const edges = (pattern.handoffs ?? []).map(handoff => ({
|
|
22
|
+
from: handoff.from, to: handoff.to, on: handoff.on, kind: handoff.kind ?? DEFAULT_KIND, required: handoff.required,
|
|
23
|
+
...(handoff.cap !== undefined ? { cap: handoff.cap } : {}),
|
|
24
|
+
}));
|
|
25
|
+
return { description: pattern.description ?? "", nodes, edges, maxVisits: pattern.maxVisits ?? null };
|
|
26
|
+
}
|
|
27
|
+
const quote = text => `"${String(text).replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
28
|
+
/** The definition as DOT text, the form wteam reads. Read-only: the Raw view shows it, nothing parses it back yet. */
|
|
29
|
+
export function toDot(graph, name) {
|
|
30
|
+
const lines = [`digraph ${quote(name)} {`];
|
|
31
|
+
const attrs = [];
|
|
32
|
+
if (graph.description)
|
|
33
|
+
attrs.push(`description=${quote(graph.description)}`);
|
|
34
|
+
if (graph.maxVisits !== null && graph.maxVisits !== undefined)
|
|
35
|
+
attrs.push(`max_visits=${graph.maxVisits}`);
|
|
36
|
+
if (attrs.length)
|
|
37
|
+
lines.push(` graph [${attrs.join(", ")}];`);
|
|
38
|
+
for (const node of graph.nodes) {
|
|
39
|
+
const fields = [`agent=${quote(node.agent)}`, `count=${node.count}`];
|
|
40
|
+
if (node.skill)
|
|
41
|
+
fields.push(`skill=${quote(node.skill)}`);
|
|
42
|
+
if (node.fallback)
|
|
43
|
+
fields.push(`fallback=${quote(node.fallback)}`);
|
|
44
|
+
lines.push(` ${quote(node.id)} [${fields.join(", ")}];`);
|
|
45
|
+
}
|
|
46
|
+
for (const edge of graph.edges) {
|
|
47
|
+
const fields = [`on=${quote(edge.on)}`, `kind=${quote(edge.kind)}`, `required=${edge.required ? "true" : "false"}`];
|
|
48
|
+
if (edge.cap !== undefined)
|
|
49
|
+
fields.push(`cap=${edge.cap}`);
|
|
50
|
+
lines.push(` ${quote(edge.from)} -> ${quote(edge.to)} [${fields.join(", ")}];`);
|
|
51
|
+
}
|
|
52
|
+
lines.push("}");
|
|
53
|
+
return lines.join("\n");
|
|
54
|
+
}
|
|
55
|
+
/** Node depth from the first node over the edges; a node no edge reaches sits at depth 0. */
|
|
56
|
+
function depthsOf(graph) {
|
|
57
|
+
const depth = new Map([[graph.nodes[0].id, 0]]);
|
|
58
|
+
for (let grew = true; grew;) {
|
|
59
|
+
grew = false;
|
|
60
|
+
for (const edge of graph.edges) {
|
|
61
|
+
if (edge.to === DONE_ID || !depth.has(edge.from))
|
|
62
|
+
continue;
|
|
63
|
+
const next = depth.get(edge.from) + 1;
|
|
64
|
+
if (!depth.has(edge.to) || next < depth.get(edge.to)) {
|
|
65
|
+
depth.set(edge.to, next);
|
|
66
|
+
grew = true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
for (const node of graph.nodes)
|
|
71
|
+
if (!depth.has(node.id))
|
|
72
|
+
depth.set(node.id, 0);
|
|
73
|
+
return depth;
|
|
74
|
+
}
|
|
75
|
+
/** Width of an edge label's widest line at 11px mono, plus padding. */
|
|
76
|
+
function labelWidth(edge) {
|
|
77
|
+
return Math.max(...edgeLines(edge).map(line => line.length)) * CHAR_W + 14;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Vertical layout: the first node at the top, one row per depth, nodes side by side within a row, done last.
|
|
81
|
+
* An edge one row down runs straight; an edge that goes up, stays in its row, or skips rows loops out to the left,
|
|
82
|
+
* in its own lane. A skipping edge's label sits in the gap above its target, clear of the rows it passes.
|
|
83
|
+
*/
|
|
84
|
+
export function layoutGraph(graph) {
|
|
85
|
+
if (!graph.nodes.length)
|
|
86
|
+
return { nodes: [], edges: [], width: 2 * PAD, height: 2 * PAD };
|
|
87
|
+
const depth = depthsOf(graph);
|
|
88
|
+
const perDepth = new Map();
|
|
89
|
+
const nodes = graph.nodes.map(node => {
|
|
90
|
+
const d = depth.get(node.id);
|
|
91
|
+
const slot = perDepth.get(d) ?? 0;
|
|
92
|
+
perDepth.set(d, slot + 1);
|
|
93
|
+
return { ...node, depth: d, slot };
|
|
94
|
+
});
|
|
95
|
+
const doneDepth = Math.max(...nodes.map(node => node.depth)) + 1;
|
|
96
|
+
if (graph.edges.some(edge => edge.to === DONE_ID))
|
|
97
|
+
nodes.push({ id: DONE_ID, agent: "", count: 1, skill: "", depth: doneDepth, slot: 0, done: true });
|
|
98
|
+
const rowOf = new Map(nodes.map(node => [node.id, node.depth]));
|
|
99
|
+
const sideRoute = edge => rowOf.get(edge.to) - rowOf.get(edge.from) !== 1;
|
|
100
|
+
const unshifted = new Map(nodes.map(node => [node.id, PAD + node.slot * SLOT_GAP]));
|
|
101
|
+
let offset = 0;
|
|
102
|
+
let lanes = 0;
|
|
103
|
+
for (const edge of graph.edges) {
|
|
104
|
+
if (!sideRoute(edge))
|
|
105
|
+
continue;
|
|
106
|
+
const bulge = Math.min(unshifted.get(edge.from), unshifted.get(edge.to)) - 40 - lanes * LANE_GAP;
|
|
107
|
+
lanes += 1;
|
|
108
|
+
offset = Math.max(offset, PAD - (bulge - 4 - labelWidth(edge)));
|
|
109
|
+
}
|
|
110
|
+
const place = nodes.map(node => ({ ...node, x: offset + PAD + node.slot * SLOT_GAP, y: PAD + node.depth * DEPTH_GAP }));
|
|
111
|
+
const at = new Map(place.map(node => [node.id, node]));
|
|
112
|
+
lanes = 0;
|
|
113
|
+
let right = 0;
|
|
114
|
+
const edges = graph.edges.map((edge, index) => {
|
|
115
|
+
const src = at.get(edge.from);
|
|
116
|
+
const dst = at.get(edge.to);
|
|
117
|
+
const base = { ...edge, index };
|
|
118
|
+
if (!sideRoute(edge)) {
|
|
119
|
+
const x1 = src.x + NODE_W / 2;
|
|
120
|
+
const y1 = src.y + NODE_H;
|
|
121
|
+
const x2 = dst.x + NODE_W / 2;
|
|
122
|
+
const y2 = dst.y;
|
|
123
|
+
const c = (y2 - y1) / 2;
|
|
124
|
+
// The label sits centred on its arrow, in the gap between the rows; it adds no width.
|
|
125
|
+
const lx = (x1 + x2) / 2;
|
|
126
|
+
return { ...base, loop: false, path: `M${x1},${y1} C${x1},${y1 + c} ${x2},${y2 - c} ${x2},${y2}`, lx, ly: (y1 + y2) / 2, anchor: "middle" };
|
|
127
|
+
}
|
|
128
|
+
const x1 = src.x;
|
|
129
|
+
const y1 = src.y + NODE_H / 2;
|
|
130
|
+
const x2 = dst.x;
|
|
131
|
+
const y2 = dst.y + NODE_H / 2;
|
|
132
|
+
const bulge = Math.min(x1, x2) - 40 - lanes * LANE_GAP;
|
|
133
|
+
lanes += 1;
|
|
134
|
+
right = Math.max(right, src.x + NODE_W, dst.x + NODE_W);
|
|
135
|
+
const skips = rowOf.get(edge.to) - rowOf.get(edge.from) > 1;
|
|
136
|
+
return {
|
|
137
|
+
...base, loop: true, path: `M${x1},${y1} C${bulge},${y1} ${bulge},${y2} ${x2},${y2}`,
|
|
138
|
+
lx: 0.125 * x1 + 0.75 * bulge + 0.125 * x2 - 4, ly: skips ? dst.y - DEPTH_GAP / 2 : (y1 + y2) / 2, anchor: "end",
|
|
139
|
+
};
|
|
140
|
+
});
|
|
141
|
+
const maxSlots = Math.max(...place.map(node => node.slot)) + 1;
|
|
142
|
+
const nodeRight = offset + PAD + (maxSlots - 1) * SLOT_GAP + NODE_W;
|
|
143
|
+
const width = Math.max(nodeRight, right) + PAD;
|
|
144
|
+
const height = PAD + doneDepth * DEPTH_GAP + NODE_H + PAD;
|
|
145
|
+
return { nodes: place, edges, width, height };
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Edge label as two lines: the event (cut to LABEL_MAX), then the kind with the cap as "max N" or, in a run, "used/N".
|
|
149
|
+
* An uncapped edge fired in a run adds "×N". Long events are cut here and shown in full in the handoff list.
|
|
150
|
+
*/
|
|
151
|
+
export function edgeLines(edge, used = null) {
|
|
152
|
+
const on = edge.on.length > LABEL_MAX ? `${edge.on.slice(0, LABEL_MAX - 1)}…` : edge.on;
|
|
153
|
+
const meta = [edge.kind];
|
|
154
|
+
if (edge.cap === undefined) {
|
|
155
|
+
if (used)
|
|
156
|
+
meta.push(`×${used}`);
|
|
157
|
+
}
|
|
158
|
+
else
|
|
159
|
+
meta.push(used === null ? `max ${edge.cap}` : `${used}/${edge.cap}`);
|
|
160
|
+
return [on, meta.filter(Boolean).join(" · ")];
|
|
161
|
+
}
|
|
162
|
+
/** The node's first line: its id, with ×count when a role runs more than once. */
|
|
163
|
+
export function nodeTitle(node) {
|
|
164
|
+
return node.count > 1 ? `${node.id} ×${node.count}` : node.id;
|
|
165
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Pattern list, inspect and run views: which actions a listed entry allows, and what a run can take next.
|
|
2
|
+
export const SCOPE_LABELS = { "built-in": "built-in", global: "global", project: "project", team: "team", other: "other project" };
|
|
3
|
+
/** Delete is offered for the project's own patterns and teams: the server's removable flag (global teams live in teams.json). */
|
|
4
|
+
export function canDelete(pattern) {
|
|
5
|
+
return pattern.removable === true;
|
|
6
|
+
}
|
|
7
|
+
/** Built-in, global, and another project's team copy into this project. */
|
|
8
|
+
export function canCopy(source) {
|
|
9
|
+
return source === "built-in" || source === "global" || source === "other";
|
|
10
|
+
}
|
|
11
|
+
/** The events the active role of a run can send, in handoff order. Empty once the run is not running. */
|
|
12
|
+
export function pendingEvents(run) {
|
|
13
|
+
if (run?.status !== "running")
|
|
14
|
+
return [];
|
|
15
|
+
return (run.definition?.handoffs ?? []).filter(handoff => handoff.from === run.active).map(handoff => handoff.on);
|
|
16
|
+
}
|
|
17
|
+
/** Runs of one pattern, newest first (listRuns order is kept). */
|
|
18
|
+
export function runsOf(runs, name) {
|
|
19
|
+
return (runs ?? []).filter(run => run.pattern === name);
|
|
20
|
+
}
|
|
21
|
+
/** One line per handoff for the run log. */
|
|
22
|
+
export function handoffLine(handoff) {
|
|
23
|
+
return `${handoff.seq}. ${handoff.from} → ${handoff.to} "${handoff.on}"${handoff.override ? " (operator)" : ""}`;
|
|
24
|
+
}
|
|
25
|
+
/** How many times each handoff (from, to, on) fired in a run; returns a counter for one handoff. */
|
|
26
|
+
export function firedCounts(run) {
|
|
27
|
+
const counts = new Map();
|
|
28
|
+
for (const handoff of run?.handoffs ?? []) {
|
|
29
|
+
const key = `${handoff.from}\n${handoff.to}\n${handoff.on}`;
|
|
30
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
31
|
+
}
|
|
32
|
+
return (handoff) => counts.get(`${handoff.from}\n${handoff.to}\n${handoff.on}`) ?? 0;
|
|
33
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Pure counts for the Home session card's pending indicator.
|
|
2
|
+
/** Pending items as counts: choice cards and plain questions are questions, permission requests are approvals. */
|
|
3
|
+
export function pendingCounts(pending) {
|
|
4
|
+
const counts = { approvals: 0, questions: 0 };
|
|
5
|
+
for (const item of pending || []) {
|
|
6
|
+
if (item.kind === "Approval" && !item.approval?.questions)
|
|
7
|
+
counts.approvals += 1;
|
|
8
|
+
else
|
|
9
|
+
counts.questions += 1;
|
|
10
|
+
}
|
|
11
|
+
return counts;
|
|
12
|
+
}
|
|
13
|
+
/** "2 questions", "1 approval", or "1 approval · 1 question"; "" when nothing is pending. */
|
|
14
|
+
export function pendingLabel(pending) {
|
|
15
|
+
const { approvals, questions } = pendingCounts(pending);
|
|
16
|
+
const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
17
|
+
return [approvals && plural(approvals, "approval"), questions && plural(questions, "question")].filter(Boolean).join(" · ");
|
|
18
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Permission values the slash commands accept, mirrored for the browser: lib/harness.ts and runner/contract.ts pull in
|
|
2
|
+
// node modules. test/permission-modes.test.mjs fails when a mirror drifts from its source.
|
|
3
|
+
// lib/harness.ts CLAUDE_PERMISSION_VALUES, in that order: /permission and /team-permission accept these.
|
|
4
|
+
export const CLAUDE_PERMISSION_VALUES = ["auto-afk", "inherit", "acceptEdits", "auto", "bypassPermissions", "default", "dontAsk", "plan"];
|
|
5
|
+
// runner/contract.ts PERMISSION_TABLE keys per harness: the modes /mode can set on a runner-owned session.
|
|
6
|
+
export const RUNNER_PERMISSION_MODES = {
|
|
7
|
+
claude: ["supervised", "accept-edits", "auto", "full-access"],
|
|
8
|
+
codex: ["supervised", "accept-edits", "auto", "full-access"],
|
|
9
|
+
opencode: ["supervised", "accept-edits", "full-access"],
|
|
10
|
+
cursor: ["supervised", "full-access"],
|
|
11
|
+
pi: ["supervised", "accept-edits", "full-access"],
|
|
12
|
+
};
|
|
13
|
+
// runner/contract.ts CLAUDE_CLI_MODES: the Claude name the runner maps onto each runner mode.
|
|
14
|
+
export const CLAUDE_CLI_MODES = { default: "supervised", acceptEdits: "accept-edits", auto: "auto", bypassPermissions: "full-access" };
|
|
15
|
+
export const CLAUDE_PERMISSION_SUMMARIES = {
|
|
16
|
+
"auto-afk": "default while AFK is on; your own Claude settings otherwise",
|
|
17
|
+
inherit: "Pass no mode, so your own Claude settings apply",
|
|
18
|
+
acceptEdits: "Accept file edits without asking",
|
|
19
|
+
auto: "Claude's auto mode",
|
|
20
|
+
bypassPermissions: "No prompts; OpenShell only, unless the host allows it",
|
|
21
|
+
default: "Ask before each tool that needs permission",
|
|
22
|
+
dontAsk: "Deny any tool not already allowed, without asking",
|
|
23
|
+
plan: "Plan mode: read and plan, no edits",
|
|
24
|
+
};
|
|
25
|
+
export const RUNNER_MODE_SUMMARIES = {
|
|
26
|
+
supervised: "Ask before each action that needs approval",
|
|
27
|
+
"accept-edits": "Allow file edits, ask for the rest",
|
|
28
|
+
auto: "The harness's automatic reviewer answers approvals",
|
|
29
|
+
"full-access": "No approvals; OpenShell only unless the host allows it",
|
|
30
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// Project chat feed: a completion row per finished session turn and one live row per busy session, from grouped activity rows.
|
|
2
|
+
import { clipSummary, SLACK_S, splitTurns } from "./chat-turns.js";
|
|
3
|
+
import { interleave, readableText, runningSubagents, summarize } from "./activity-rows.js";
|
|
4
|
+
import { WORKING_MS } from "./session-state.js";
|
|
5
|
+
import { machinePrompt, operatorPrompt } from "../../lib/machine-prompt.js";
|
|
6
|
+
// A turn counts as finished only when its stop row says the turn ended; "session ended" and subagent stops do not.
|
|
7
|
+
const TURN_ENDED = /^turn ended/;
|
|
8
|
+
// The activity feed's tool label for harness and agent messages arriving as prompts; they are not the agent's reply.
|
|
9
|
+
const AGENT_MESSAGE = "Agent message";
|
|
10
|
+
// The browser has no environment; the wake flag is a server-side concern.
|
|
11
|
+
const NO_ENV = {};
|
|
12
|
+
const firstLine = text => String(text || "").trim().split("\n")[0].trim();
|
|
13
|
+
// Seconds of a turn's newest row, its prompt included.
|
|
14
|
+
const newestOf = turn => Math.max(turn.prompt?.time || 0, ...turn.rows.map(row => row.lastTime ?? row.time ?? 0));
|
|
15
|
+
/** Items grouped by key in one pass, each group in arrival order. */
|
|
16
|
+
function groupBy(items, keyOf) {
|
|
17
|
+
const groups = new Map();
|
|
18
|
+
for (const item of items) {
|
|
19
|
+
const key = keyOf(item);
|
|
20
|
+
const group = groups.get(key);
|
|
21
|
+
if (group)
|
|
22
|
+
group.push(item);
|
|
23
|
+
else
|
|
24
|
+
groups.set(key, [item]);
|
|
25
|
+
}
|
|
26
|
+
return groups;
|
|
27
|
+
}
|
|
28
|
+
/** The operator's typed prompt that opened a turn, or null for a machine or wake prompt. */
|
|
29
|
+
function typedPrompt(turn) {
|
|
30
|
+
return turn.prompt && operatorPrompt(turn.prompt.input, NO_ENV) ? turn.prompt : null;
|
|
31
|
+
}
|
|
32
|
+
/** The turn's final reply: its last text the agent wrote, not a harness or agent message; null when none. */
|
|
33
|
+
function finalReply(turn) {
|
|
34
|
+
return turn.rows.findLast(row => row.type === "text" && row.tool !== AGENT_MESSAGE && String(row.output || "").trim() && !machinePrompt(row.output)) || null;
|
|
35
|
+
}
|
|
36
|
+
/** Each session's turns (splitTurns) from grouped rows: session → turns. */
|
|
37
|
+
export function sessionTurns(rows) {
|
|
38
|
+
return new Map([...groupBy(rows, row => row.agent)].map(([agent, own]) => [agent, splitTurns(own)]));
|
|
39
|
+
}
|
|
40
|
+
/** Operator answers whose question or approval card is in the list; the card shows the answer, so its bubble goes. */
|
|
41
|
+
export function withoutAnswered(messages) {
|
|
42
|
+
const asks = new Set();
|
|
43
|
+
for (const message of messages) {
|
|
44
|
+
if (message.kind === "Question" && message.question)
|
|
45
|
+
asks.add(message.question);
|
|
46
|
+
if (message.kind === "Approval" && message.approval?.id)
|
|
47
|
+
asks.add(message.approval.id);
|
|
48
|
+
}
|
|
49
|
+
return messages.filter(message => !(message.replyTo && asks.has(message.replyTo)));
|
|
50
|
+
}
|
|
51
|
+
/** Consecutive completion rows of one session become one row: its turn count and the last text it had. */
|
|
52
|
+
function collapse(rows) {
|
|
53
|
+
const out = [];
|
|
54
|
+
for (const row of rows) {
|
|
55
|
+
const last = out.at(-1);
|
|
56
|
+
if (last && last.agent === row.agent)
|
|
57
|
+
out[out.length - 1] = { ...last, turns: last.turns + 1, time: row.time, text: row.text || last.text };
|
|
58
|
+
else
|
|
59
|
+
out.push(row);
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Finished turns as "completion" rows. A turn counts when it ends with a reply or the operator typed its prompt;
|
|
65
|
+
* its text is the final reply's first line, unless the session already posted that text nearby.
|
|
66
|
+
*/
|
|
67
|
+
export function completionRows(turnsByAgent, messages = []) {
|
|
68
|
+
const said = groupBy(messages, message => message.from);
|
|
69
|
+
const out = [];
|
|
70
|
+
for (const [agent, turns] of turnsByAgent) {
|
|
71
|
+
for (const turn of turns) {
|
|
72
|
+
if (!turn.stop || !TURN_ENDED.test(turn.stop.input || "") || !turn.rows.length)
|
|
73
|
+
continue;
|
|
74
|
+
const reply = finalReply(turn);
|
|
75
|
+
if (!reply && !typedPrompt(turn))
|
|
76
|
+
continue;
|
|
77
|
+
const time = turn.stop.time || reply?.time || 0;
|
|
78
|
+
const repeated = Boolean(reply) && (said.get(agent) || []).some(message => Math.abs((message.time || 0) - time) <= SLACK_S && String(message.body).trim() === String(reply.output).trim());
|
|
79
|
+
out.push({ id: "done:" + turn.stop.id, type: "completion", agent, time, text: reply && !repeated ? firstLine(reply.output) : "", turns: 1 });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return collapse(out.sort((a, b) => a.time - b.time));
|
|
83
|
+
}
|
|
84
|
+
/** Chat messages with the completion rows, in time order. */
|
|
85
|
+
export function projectThread(messages, turnsByAgent) {
|
|
86
|
+
return interleave(messages, completionRows(turnsByAgent, messages));
|
|
87
|
+
}
|
|
88
|
+
/** The typed prompt's first line, else the latest tool call's summary; "" when the turn has neither. */
|
|
89
|
+
function liveSummary(turn) {
|
|
90
|
+
if (!turn)
|
|
91
|
+
return "";
|
|
92
|
+
const asked = typedPrompt(turn);
|
|
93
|
+
if (asked)
|
|
94
|
+
return clipSummary(readableText(asked.input).text);
|
|
95
|
+
const latest = turn.rows.findLast(row => row.type === "tool_call");
|
|
96
|
+
return latest ? clipSummary(summarize(latest.input)) : "";
|
|
97
|
+
}
|
|
98
|
+
/** One live row per busy session: its last turn has no stop and a row within WORKING_MS, or it has a running subagent. */
|
|
99
|
+
export function liveRows(turnsByAgent, rows, now) {
|
|
100
|
+
const busy = new Set(runningSubagents(rows, now).keys());
|
|
101
|
+
for (const [agent, turns] of turnsByAgent) {
|
|
102
|
+
const current = turns.at(-1);
|
|
103
|
+
if (current && !current.stop && now - newestOf(current) * 1000 < WORKING_MS)
|
|
104
|
+
busy.add(agent);
|
|
105
|
+
}
|
|
106
|
+
return [...busy].sort().map(agent => ({ id: "live:" + agent, type: "live", agent, summary: liveSummary(turnsByAgent.get(agent)?.at(-1)) }));
|
|
107
|
+
}
|
package/web/lib/quote.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Quote text for a reply: the replied message's first line of words, clipped to QUOTE_CHARS.
|
|
2
|
+
export const QUOTE_CHARS = 80;
|
|
3
|
+
/** The body on one line, at most QUOTE_CHARS characters, ending in an ellipsis when clipped. */
|
|
4
|
+
export function quoteText(body) {
|
|
5
|
+
const line = String(body || "").replace(/\s+/g, " ").trim();
|
|
6
|
+
return line.length > QUOTE_CHARS ? line.slice(0, QUOTE_CHARS - 1).trimEnd() + "…" : line;
|
|
7
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// A reply whose message id the server cannot accept goes out as plain text quoting the original's ends.
|
|
2
|
+
export const REPLY_QUOTE_WORDS = 6;
|
|
3
|
+
// quotedReply's output: "Replying to <sender>: “<quote>”", or "Replying to <sender>:", then a blank line and the reply.
|
|
4
|
+
const QUOTED_REPLY = /^Replying to ([^\n]+?):(?: “([^\n]*)”)?\n\n([\s\S]*)$/;
|
|
5
|
+
/** The quoted original on one line: its first and last REPLY_QUOTE_WORDS words, joined by … when words were left out. */
|
|
6
|
+
export function quoteEnds(body, words = REPLY_QUOTE_WORDS) {
|
|
7
|
+
const list = String(body || "").replace(/\s+/g, " ").trim().split(" ").filter(Boolean);
|
|
8
|
+
if (list.length <= words * 2)
|
|
9
|
+
return list.join(" ");
|
|
10
|
+
return list.slice(0, words).join(" ") + " … " + list.slice(-words).join(" ");
|
|
11
|
+
}
|
|
12
|
+
/** True for a message id the server's replyTo check accepts: 1-64 letters, digits and dashes. */
|
|
13
|
+
export function usableReplyId(id) {
|
|
14
|
+
return typeof id === "string" && /^[a-zA-Z0-9-]{1,64}$/.test(id);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The text to send instead of a reply the server refuses: the reply body with the original quoted above it.
|
|
18
|
+
* The quote names the sender and keeps the original's first and last words, so the reader sees what it answers.
|
|
19
|
+
*/
|
|
20
|
+
export function quotedReply(body, { sender = "", body: original = "" } = {}) {
|
|
21
|
+
const text = String(body || "").trim();
|
|
22
|
+
const quote = quoteEnds(original);
|
|
23
|
+
if (!quote)
|
|
24
|
+
return sender ? "Replying to " + sender + ":\n\n" + text : text;
|
|
25
|
+
return "Replying to " + (sender || "the original") + ": “" + quote + "”\n\n" + text;
|
|
26
|
+
}
|
|
27
|
+
/** A body quotedReply wrote, split back into the quoted original {sender, body} and the reply text; null for any other body. */
|
|
28
|
+
export function splitQuotedReply(text) {
|
|
29
|
+
const found = QUOTED_REPLY.exec(String(text || ""));
|
|
30
|
+
return found ? { quote: { sender: found[1], body: found[2] || "" }, body: found[3] } : null;
|
|
31
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Detail rows for a scheduled job: one row per field the runner reports, none invented.
|
|
2
|
+
/** "every 30 min" for an interval in milliseconds. */
|
|
3
|
+
export function everyLabel(everyMs) {
|
|
4
|
+
return "every " + everyMs / 60_000 + " min";
|
|
5
|
+
}
|
|
6
|
+
/** The agent address a job's command resumes (`cursor#<16 hex>`), or "" when it resumes none. */
|
|
7
|
+
export function jobAgent(job) {
|
|
8
|
+
const resumed = job?.session;
|
|
9
|
+
return resumed?.harness && resumed?.session ? resumed.harness + "#" + resumed.session : "";
|
|
10
|
+
}
|
|
11
|
+
/** The job's command with each absolute path cut to its last part, for a one-line row; the detail sheet keeps it whole. */
|
|
12
|
+
export function commandLabel(command) {
|
|
13
|
+
return Array.isArray(command) ? command.map(arg => /^\/[^\s]*\/[^/\s]+$/.test(arg) ? arg.slice(arg.lastIndexOf("/") + 1) : arg).join(" ") : "";
|
|
14
|
+
}
|
|
15
|
+
/** [label, value] rows for the job's detail sheet; a field the runner did not send gets no row. */
|
|
16
|
+
export function jobDetail(job) {
|
|
17
|
+
const rows = [["Schedule", everyLabel(job.everyMs)]];
|
|
18
|
+
if (job.nextRun)
|
|
19
|
+
rows.push(["Next run", job.nextRun]);
|
|
20
|
+
if (Array.isArray(job.command) && job.command.length)
|
|
21
|
+
rows.push(["Command", job.command.join(" ")]);
|
|
22
|
+
if (job.cwd)
|
|
23
|
+
rows.push(["Folder", job.cwd]);
|
|
24
|
+
if (job.last?.status)
|
|
25
|
+
rows.push(["Last run", job.last.status]);
|
|
26
|
+
// The job is the schedule, not the agent: the agent it resumes is a separate entry in the sidebar.
|
|
27
|
+
if (jobAgent(job))
|
|
28
|
+
rows.push(["Resumes", jobAgent(job)]);
|
|
29
|
+
return rows;
|
|
30
|
+
}
|
|
31
|
+
// A quarter hour of slack on each side of a run: the session's hook rows and the run's clock are not the same clock.
|
|
32
|
+
export const RUN_WINDOW_SLACK_MS = 15 * 60_000;
|
|
33
|
+
/**
|
|
34
|
+
* The [from, to] window (epoch ms) of each run in a list, keyed by run id. The window is the run's own lifetime plus
|
|
35
|
+
* RUN_WINDOW_SLACK_MS either side, cut at the midpoint to the neighbouring run of the same schedule so two runs never
|
|
36
|
+
* show the same rows. A run with no start time gets no window.
|
|
37
|
+
*/
|
|
38
|
+
export function runWindows(runs = []) {
|
|
39
|
+
const ordered = runs.filter(run => Number.isSafeInteger(run?.startedAt)).slice().sort((a, b) => a.startedAt - b.startedAt);
|
|
40
|
+
const windows = new Map();
|
|
41
|
+
ordered.forEach((run, i) => {
|
|
42
|
+
const previous = ordered[i - 1];
|
|
43
|
+
const next = ordered[i + 1];
|
|
44
|
+
const end = run.finishedAt ?? run.updatedAt ?? run.startedAt;
|
|
45
|
+
// Never reach past the midpoint to a neighbour, so a 30-minute schedule's back-to-back runs stay apart.
|
|
46
|
+
const from = Math.max(run.startedAt - RUN_WINDOW_SLACK_MS, previous ? Math.ceil((previous.startedAt + run.startedAt) / 2) : -Infinity);
|
|
47
|
+
const to = Math.min(end + RUN_WINDOW_SLACK_MS, next ? Math.floor((run.startedAt + next.startedAt) / 2) : Infinity);
|
|
48
|
+
windows.set(run.id, { from, to });
|
|
49
|
+
});
|
|
50
|
+
return windows;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The session and time window one schedule run covers: {harness, session, project, from, to}, or null when the runner
|
|
54
|
+
* named no session or the run has no window. With the schedule's whole run list the window is clamped as runWindows does.
|
|
55
|
+
*/
|
|
56
|
+
export function runWindow(run, project = "", runs = []) {
|
|
57
|
+
const session = run?.session;
|
|
58
|
+
if (!session?.harness || !session.session || !Number.isSafeInteger(run.startedAt))
|
|
59
|
+
return null;
|
|
60
|
+
const window = runWindows(runs.length ? runs : [run]).get(run.id);
|
|
61
|
+
if (!window || window.to <= window.from)
|
|
62
|
+
return null;
|
|
63
|
+
return { project: run.project || project, harness: session.harness, session: session.harness + "#" + session.session, ...window };
|
|
64
|
+
}
|
|
65
|
+
/** The UI hash that opens one run's slice of its session's timeline, or "" when the runner named no session. */
|
|
66
|
+
export function runLink(run, project = "", runs = []) {
|
|
67
|
+
const found = runWindow(run, project, runs);
|
|
68
|
+
if (!found)
|
|
69
|
+
return "";
|
|
70
|
+
const params = new URLSearchParams({
|
|
71
|
+
project: found.project, level: "session", harness: found.harness, session: found.session,
|
|
72
|
+
tab: "activity", from: String(found.from), to: String(found.to),
|
|
73
|
+
});
|
|
74
|
+
return "#" + params;
|
|
75
|
+
}
|
|
76
|
+
/** "2:05 PM" for a run's start, "" when it has none. */
|
|
77
|
+
export function runLabel(run) {
|
|
78
|
+
return Number.isSafeInteger(run?.startedAt) ? new Date(run.startedAt).toLocaleTimeString(undefined, { hour: "2-digit", minute: "2-digit" }) : "";
|
|
79
|
+
}
|