@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,44 @@
|
|
|
1
|
+
// The phone alert level, as the header shows it. The server file is the truth; this browser keeps its last choice so a
|
|
2
|
+
// deploy (which reloads every tab) never renders a stored level as "all" before the first state frame arrives.
|
|
3
|
+
export const ALERT_LEVELS = [["all", "All"], ["questions-and-direct", "Questions and direct replies"], ["questions", "Questions only"], ["none", "None"]];
|
|
4
|
+
export const ALERT_LEVEL_DEFAULT = "all";
|
|
5
|
+
const REMEMBERED_KEY = "ai-collab.alertLevel";
|
|
6
|
+
const LEVEL_IDS = ALERT_LEVELS.map(([id]) => id);
|
|
7
|
+
export function isAlertLevel(value) {
|
|
8
|
+
return LEVEL_IDS.includes(value);
|
|
9
|
+
}
|
|
10
|
+
/** The level to show: the server's when it names one, else this browser's last choice, else the default. */
|
|
11
|
+
export function shownAlertLevel(server, remembered) {
|
|
12
|
+
if (isAlertLevel(server))
|
|
13
|
+
return server;
|
|
14
|
+
return isAlertLevel(remembered) ? remembered : ALERT_LEVEL_DEFAULT;
|
|
15
|
+
}
|
|
16
|
+
/** The browser's last chosen level, or undefined; a storage that throws (private mode, quota) reads as none. */
|
|
17
|
+
export function readRememberedAlertLevel(storage) {
|
|
18
|
+
try {
|
|
19
|
+
return storage?.getItem(REMEMBERED_KEY) ?? undefined;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** Keeps a level across reloads; an unknown level or an unavailable storage is ignored. */
|
|
26
|
+
export function rememberAlertLevel(storage, level) {
|
|
27
|
+
if (!isAlertLevel(level))
|
|
28
|
+
return;
|
|
29
|
+
try {
|
|
30
|
+
storage?.setItem(REMEMBERED_KEY, level);
|
|
31
|
+
}
|
|
32
|
+
catch { /* private mode or quota: the server still holds the level */ }
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Whether a push subscription was made with this VAPID key. A subscription from an older key can never be delivered to,
|
|
36
|
+
* so a reload must replace it instead of resending it and showing notifications as on.
|
|
37
|
+
*/
|
|
38
|
+
export function subscriptionUsesKey(subscription, key) {
|
|
39
|
+
const own = subscription?.options?.applicationServerKey;
|
|
40
|
+
if (!own)
|
|
41
|
+
return true; // some browsers hide the key; assume the subscription still matches
|
|
42
|
+
const current = new Uint8Array(own);
|
|
43
|
+
return current.length === key.length && current.every((byte, i) => byte === key[i]);
|
|
44
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// The permission modes an approval card offers for its runner-owned session, sent as /mode through the session command path.
|
|
2
|
+
import { RUNNER_MODE_SUMMARIES, RUNNER_PERMISSION_MODES } from "./permission-modes.js";
|
|
3
|
+
import { commandSupport } from "./slash-commands.js";
|
|
4
|
+
export const FULL_ACCESS = "full-access";
|
|
5
|
+
export const AUTO = "auto";
|
|
6
|
+
export const ALLOW_AND_AUTO_LABEL = "Allow and switch to auto";
|
|
7
|
+
/**
|
|
8
|
+
* {value, summary} per mode the card offers: the harness's runner modes (its adapter's capabilities.permissionModes), with
|
|
9
|
+
* full-access only in OpenShell, where the runner allows nothing else; the current mode stays listed. [] when /mode is unsupported.
|
|
10
|
+
*/
|
|
11
|
+
export function cardModes(harness, { current = "", place = "folder" } = {}) {
|
|
12
|
+
if (commandSupport(harness, "mode").status === "unsupported")
|
|
13
|
+
return [];
|
|
14
|
+
const modes = RUNNER_PERMISSION_MODES[harness] ?? [];
|
|
15
|
+
// The runner refuses full-access on the host without TEMMO_ALLOW_HOST_AGENT=1 (lib/agent-guard.ts).
|
|
16
|
+
const shown = modes.filter(mode => mode === current || (place === "openshell" ? mode === FULL_ACCESS : mode !== FULL_ACCESS));
|
|
17
|
+
return shown.map(value => ({ value, summary: RUNNER_MODE_SUMMARIES[value] }));
|
|
18
|
+
}
|
|
19
|
+
/** Whether the card offers "Allow and switch to auto": auto is offered and is not already the mode. */
|
|
20
|
+
export const offersAllowAndAuto = (modes, current) => current !== AUTO && modes.some(mode => mode.value === AUTO);
|
|
21
|
+
/** The session command that sets a mode. */
|
|
22
|
+
export const modeCommand = mode => "/mode " + mode;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// Pure grouping of a session's activity rows: the session timeline's flow of texts and tool groups, and the turns the project feed reads.
|
|
2
|
+
import { interleave, readableText, summarize } from "./activity-rows.js";
|
|
3
|
+
import { foldCompactionRestarts, pairCompactions } from "./compaction-view.js";
|
|
4
|
+
import { operatorPrompt } from "../../lib/machine-prompt.js";
|
|
5
|
+
const SUMMARY_CHARS = 60;
|
|
6
|
+
// Seconds around a turn in which a chat message from the agent counts as the same text as its final row.
|
|
7
|
+
export const SLACK_S = 30;
|
|
8
|
+
// The browser has no environment; the wake flag is a server-side concern.
|
|
9
|
+
const NO_ENV = {};
|
|
10
|
+
const isStep = row => row.type === "tool_call" || row.type === "subagent" || ((row.type === "tool_result" || row.type === "error") && Boolean(row.tool));
|
|
11
|
+
const oneLine = text => text.replace(/\s+/g, " ").trim();
|
|
12
|
+
const clip = text => text.length > SUMMARY_CHARS ? text.slice(0, SUMMARY_CHARS - 1).trimEnd() + "…" : text;
|
|
13
|
+
/** One line of text, clipped to the summary width. */
|
|
14
|
+
export function clipSummary(text) {
|
|
15
|
+
return clip(oneLine(String(text || "")));
|
|
16
|
+
}
|
|
17
|
+
/** Short subject of a turn: the operator's typed prompt's first line, else its first tool's summary, else "the task". */
|
|
18
|
+
export function turnSummary(prompt, body) {
|
|
19
|
+
const asked = prompt && operatorPrompt(prompt.input, NO_ENV) ? oneLine(readableText(prompt.input).text) : "";
|
|
20
|
+
if (asked)
|
|
21
|
+
return clip(asked);
|
|
22
|
+
const first = body.find(row => row.type === "tool_call");
|
|
23
|
+
return clip(oneLine(first ? summarize(first.input) : "")) || "the task";
|
|
24
|
+
}
|
|
25
|
+
/** Splits grouped rows into turns: rows from a prompt (or the start) to the next stop; a turn ended by a stop or a later prompt is done. */
|
|
26
|
+
export function splitTurns(rows) {
|
|
27
|
+
const turns = [];
|
|
28
|
+
let turn = null;
|
|
29
|
+
for (const row of rows) {
|
|
30
|
+
if (row.type === "prompt") {
|
|
31
|
+
turn = { prompt: row, rows: [], stop: null };
|
|
32
|
+
turns.push(turn);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (!turn) {
|
|
36
|
+
turn = { prompt: null, rows: [], stop: null };
|
|
37
|
+
turns.push(turn);
|
|
38
|
+
}
|
|
39
|
+
if (row.type === "stop") {
|
|
40
|
+
turn.stop = row;
|
|
41
|
+
turn = null;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
turn.rows.push(row);
|
|
45
|
+
}
|
|
46
|
+
turns.forEach((item, i) => { item.done = Boolean(item.stop) || i < turns.length - 1; });
|
|
47
|
+
return turns;
|
|
48
|
+
}
|
|
49
|
+
/** Removes a finished turn's last text from body; returns it as a chat message unless the session already posted it. */
|
|
50
|
+
function takeFinal(turn, body, own) {
|
|
51
|
+
const at = body.findLastIndex(row => row.type === "text");
|
|
52
|
+
if (at < 0)
|
|
53
|
+
return null;
|
|
54
|
+
const [final] = body.splice(at, 1);
|
|
55
|
+
const start = (turn.prompt?.time ?? turn.rows[0].time ?? final.time) - SLACK_S;
|
|
56
|
+
const end = Math.max(turn.stop?.time || 0, final.time || 0) + SLACK_S;
|
|
57
|
+
const text = String(final.output || "").trim();
|
|
58
|
+
const same = own.some(item => item.time >= start && item.time <= end && String(item.body).trim() === text);
|
|
59
|
+
// replyId is the text row's bus id, the id a reply to this message links.
|
|
60
|
+
return !same && text ? { id: "final:" + final.id, replyId: final.id, time: final.time, kind: "Message", sender: final.agent, from: final.agent, body: final.output } : null;
|
|
61
|
+
}
|
|
62
|
+
/** Rows for the session thread plus the final messages to merge into chat; a done turn becomes a "turn" row and its final text a message, a running turn stays flat. */
|
|
63
|
+
export function chatTurns(rows, messages = [], session = "") {
|
|
64
|
+
const own = messages.filter(item => item.from === session);
|
|
65
|
+
const out = [];
|
|
66
|
+
const finals = [];
|
|
67
|
+
for (const turn of splitTurns(rows)) {
|
|
68
|
+
if (!turn.done) {
|
|
69
|
+
out.push(...turn.rows);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const body = [...turn.rows];
|
|
73
|
+
const final = takeFinal(turn, body, own);
|
|
74
|
+
if (final)
|
|
75
|
+
finals.push(final);
|
|
76
|
+
if (!body.length)
|
|
77
|
+
continue;
|
|
78
|
+
const steps = body.filter(isStep).length;
|
|
79
|
+
out.push({ id: "turn:" + body[0].id, type: "turn", agent: body[0].agent, time: body[0].time, summary: turnSummary(turn.prompt, body), steps, rows: body, done: true });
|
|
80
|
+
}
|
|
81
|
+
return { rows: out, messages: finals };
|
|
82
|
+
}
|
|
83
|
+
const isToolUse = row => row.type === "tool_call" || ((row.type === "tool_result" || row.type === "error") && Boolean(row.tool));
|
|
84
|
+
/** A run of consecutive tool uses between two assistant messages, one row; live while its turn runs. */
|
|
85
|
+
function toolGroup(rows) {
|
|
86
|
+
return { id: "group:" + rows[0].id, type: "group", agent: rows[0].agent, time: rows[0].time, rows, steps: rows.length, tools: [...new Set(rows.map(row => row.tool || "tool"))], live: false };
|
|
87
|
+
}
|
|
88
|
+
/** A turn's rows in order: text stays a row, tool uses group between texts, subagent and other rows stand alone; a running turn's newest group is live until a text follows. */
|
|
89
|
+
function flowRows(body, done) {
|
|
90
|
+
const out = [];
|
|
91
|
+
let run = null;
|
|
92
|
+
for (const row of body) {
|
|
93
|
+
if (isToolUse(row)) {
|
|
94
|
+
run ||= [];
|
|
95
|
+
run.push(row);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (row.type === "text" && !String(row.output || "").trim())
|
|
99
|
+
continue;
|
|
100
|
+
if (run) {
|
|
101
|
+
out.push(toolGroup(run));
|
|
102
|
+
run = null;
|
|
103
|
+
}
|
|
104
|
+
out.push(row);
|
|
105
|
+
}
|
|
106
|
+
if (run)
|
|
107
|
+
out.push(toolGroup(run));
|
|
108
|
+
if (!done) {
|
|
109
|
+
const at = out.findLastIndex(row => row.type === "group");
|
|
110
|
+
if (at >= 0 && !out.slice(at + 1).some(row => row.type === "text"))
|
|
111
|
+
out[at] = { ...out[at], live: true };
|
|
112
|
+
}
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
/** Session timeline rows (texts, tool groups, subagent and other rows) plus the final messages to merge into chat. */
|
|
116
|
+
export function chatFlow(rows, messages = [], session = "") {
|
|
117
|
+
const own = messages.filter(item => item.from === session);
|
|
118
|
+
const out = [];
|
|
119
|
+
const finals = [];
|
|
120
|
+
for (const turn of splitTurns(foldCompactionRestarts(pairCompactions(rows)))) {
|
|
121
|
+
const body = [...turn.rows];
|
|
122
|
+
if (turn.done) {
|
|
123
|
+
const final = takeFinal(turn, body, own);
|
|
124
|
+
if (final)
|
|
125
|
+
finals.push(final);
|
|
126
|
+
}
|
|
127
|
+
out.push(...flowRows(body, turn.done));
|
|
128
|
+
}
|
|
129
|
+
return { rows: out, messages: finals };
|
|
130
|
+
}
|
|
131
|
+
/** Cuts each tool group at the chat messages that arrived during it, so its later tool uses sort after them; only the last piece of a live group stays live. */
|
|
132
|
+
function splitAtMessages(rows, times) {
|
|
133
|
+
return rows.flatMap(row => {
|
|
134
|
+
if (row.type !== "group")
|
|
135
|
+
return [row];
|
|
136
|
+
const span = row.rows.map(item => item.time || 0);
|
|
137
|
+
const inside = times.filter(time => time >= Math.min(...span) && time < Math.max(...span));
|
|
138
|
+
if (!inside.length)
|
|
139
|
+
return [row];
|
|
140
|
+
const pieces = [[]];
|
|
141
|
+
for (const item of row.rows) {
|
|
142
|
+
const piece = pieces.at(-1);
|
|
143
|
+
const last = piece.at(-1);
|
|
144
|
+
if (last && inside.some(time => time >= (last.time || 0) && time < (item.time || 0)))
|
|
145
|
+
pieces.push([item]);
|
|
146
|
+
else
|
|
147
|
+
piece.push(item);
|
|
148
|
+
}
|
|
149
|
+
if (pieces.length === 1)
|
|
150
|
+
return [row];
|
|
151
|
+
return pieces.map((piece, i) => ({ ...toolGroup(piece), live: row.live && i === pieces.length - 1 }));
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
/** The session thread: chat messages, assistant texts and tool groups interleaved by time. */
|
|
155
|
+
export function chatThread(messages, rows, session) {
|
|
156
|
+
const flow = chatFlow(rows, messages, session);
|
|
157
|
+
const merged = [...messages, ...flow.messages].sort((a, b) => (a.time || 0) - (b.time || 0));
|
|
158
|
+
return interleave(merged, splitAtMessages(flow.rows, merged.map(item => item.time || 0)));
|
|
159
|
+
}
|
|
160
|
+
/** A native subagent run's transcript as chat entries: its start, texts, tool groups and stop rows in order; live until the run is done. */
|
|
161
|
+
export function subagentThread(run) {
|
|
162
|
+
return flowRows(run.rows, Boolean(run.done)).map(activity => ({ activity }));
|
|
163
|
+
}
|
|
164
|
+
/** "Ran Bash · npm test" for one tool use, "Ran 2 tools · Bash, Read" for several. */
|
|
165
|
+
export function groupLabel(group) {
|
|
166
|
+
if (group.steps !== 1)
|
|
167
|
+
return "Ran " + group.steps + " tools · " + group.tools.join(", ");
|
|
168
|
+
const summary = clipSummary(summarize(group.rows[0].input));
|
|
169
|
+
return "Ran " + group.tools[0] + (summary ? " · " + summary : "");
|
|
170
|
+
}
|
|
171
|
+
/** "Working on <summary> · 3 steps" for a turn row. */
|
|
172
|
+
export function turnLabel(row) {
|
|
173
|
+
return "Working on " + row.summary + (row.steps ? " · " + row.steps + (row.steps === 1 ? " step" : " steps") : "");
|
|
174
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Child sessions (started by another session) as subagent entries on their parent.
|
|
2
|
+
/** Child entries per parent id: each card whose parent is also in cards, with its address, harness, model, name, online and activity time (seconds). */
|
|
3
|
+
export function childRuns(cards) {
|
|
4
|
+
const ids = new Set(cards.map(card => card.id));
|
|
5
|
+
const out = new Map();
|
|
6
|
+
for (const card of cards) {
|
|
7
|
+
if (!card.parent || card.parent === card.id || !ids.has(card.parent))
|
|
8
|
+
continue;
|
|
9
|
+
const time = Math.floor(Math.max(card.seenAt || 0, card.lastActivityAt || 0) / 1000);
|
|
10
|
+
const entry = { id: card.id, agent: card.parent, run: card.id, kind: card.harness || card.peer, ...(card.model ? { model: card.model } : {}), description: card.name || card.folder || "", online: card.online === true, time, lastTime: time, child: true };
|
|
11
|
+
if (!out.has(card.parent))
|
|
12
|
+
out.set(card.parent, []);
|
|
13
|
+
out.get(card.parent).push(entry);
|
|
14
|
+
}
|
|
15
|
+
return out;
|
|
16
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { pairCompactions } from "../../lib/session-events.js";
|
|
2
|
+
export { pairCompactions };
|
|
3
|
+
// Compaction rows as timeline text: "Compacted · auto · 182k → 31k · 4 files dropped".
|
|
4
|
+
const WORDS = { started: "Compacting", finished: "Compacted", failed: "Compaction failed" };
|
|
5
|
+
/** Tokens as "182k" from 1000 up; smaller counts stay exact. */
|
|
6
|
+
export function tokenCount(tokens) {
|
|
7
|
+
return tokens >= 1000 ? `${Math.round(tokens / 1000)}k` : String(tokens);
|
|
8
|
+
}
|
|
9
|
+
/** The timeline text of one compaction, or "" when its phase is unknown. */
|
|
10
|
+
export function compactionText(compaction) {
|
|
11
|
+
if (!WORDS[compaction?.phase])
|
|
12
|
+
return "";
|
|
13
|
+
const { trigger, tokensBefore, tokensAfter, filesDropped } = compaction;
|
|
14
|
+
const sizes = tokensBefore === undefined ? ""
|
|
15
|
+
: tokensAfter === undefined ? tokenCount(tokensBefore) : `${tokenCount(tokensBefore)} → ${tokenCount(tokensAfter)}`;
|
|
16
|
+
const files = filesDropped > 0 ? `${filesDropped} ${filesDropped === 1 ? "file" : "files"} dropped` : "";
|
|
17
|
+
return [WORDS[compaction.phase], trigger, sizes, files].filter(Boolean).join(" · ");
|
|
18
|
+
}
|
|
19
|
+
/** Each finished compaction takes its tokensBefore and filesDropped from the started row before it. */
|
|
20
|
+
// The start row SessionStart writes after a compaction (source "compact", activity.mjs); the compaction row already says it.
|
|
21
|
+
const RESTART_AFTER_COMPACT = "session started · compact";
|
|
22
|
+
/** Drops the start row a compaction's SessionStart leaves behind, so one compaction is one timeline row. */
|
|
23
|
+
export function foldCompactionRestarts(rows) {
|
|
24
|
+
return rows.filter(row => !(row.type === "start" && row.input === RESTART_AFTER_COMPACT));
|
|
25
|
+
}
|
|
26
|
+
/** Tokens left under the window, or null unless the harness reported both counts; the auto-compact point is never guessed. */
|
|
27
|
+
export function headroom({ tokens, window } = {}) {
|
|
28
|
+
if (!Number.isSafeInteger(tokens) || !Number.isSafeInteger(window) || window <= 0)
|
|
29
|
+
return null;
|
|
30
|
+
return { left: Math.max(0, window - tokens), window };
|
|
31
|
+
}
|
|
32
|
+
/** Where a time sits on the map axis from start to end, as a percent; 0 when the axis has no width. */
|
|
33
|
+
export function axisPercent(at, start, end) {
|
|
34
|
+
return end > start ? Math.min(100, Math.max(0, ((at - start) / (end - start)) * 100)) : 0;
|
|
35
|
+
}
|
|
36
|
+
/** The map axis: from the oldest compaction (or an hour before now) to now. */
|
|
37
|
+
export function mapAxis(histories, now) {
|
|
38
|
+
const times = histories.flat().map(item => item.at);
|
|
39
|
+
return { start: Math.min(now - 60 * 60_000, ...times), end: now };
|
|
40
|
+
}
|
|
41
|
+
/** "Cleared · 140k → 0", or "Cleared" when the count before is unknown. */
|
|
42
|
+
export function clearText({ tokensBefore, tokensAfter } = {}) {
|
|
43
|
+
return tokensBefore === undefined ? "Cleared" : `Cleared · ${tokenCount(tokensBefore)} → ${tokenCount(tokensAfter ?? 0)}`;
|
|
44
|
+
}
|
|
45
|
+
/** "Model claude-haiku-5-5 → claude-opus-5-5". */
|
|
46
|
+
export function modelText({ from, to }) {
|
|
47
|
+
return `Model ${from} → ${to}`;
|
|
48
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// The composer's Actions menu entries: a session's slash commands with their argument values as items.
|
|
2
|
+
import { COMMANDS, commandSupport, matchArgs } from "./slash-commands.js";
|
|
3
|
+
import { cardModes, modeCommand } from "./approval-mode.js";
|
|
4
|
+
// /afk's values; matchArgs completes none, since its argument is fixed.
|
|
5
|
+
export const AFK_VALUES = [
|
|
6
|
+
{ value: "on", summary: "Approvals and questions come to the phone" },
|
|
7
|
+
{ value: "quiet", summary: "AFK on, without progress posts" },
|
|
8
|
+
{ value: "off", summary: "The terminal prompts answer" },
|
|
9
|
+
];
|
|
10
|
+
// Values for the argument after prefix, nested for each argument still to pick; the last level carries the full command text.
|
|
11
|
+
function valuesAfter(harness, prefix, slots, data) {
|
|
12
|
+
const options = matchArgs(harness, prefix, data)?.options ?? [];
|
|
13
|
+
return options.map(option => slots > 1
|
|
14
|
+
? { value: option.value, summary: option.summary, values: valuesAfter(harness, option.text, slots - 1, data) }
|
|
15
|
+
: { value: option.value, summary: option.summary, command: option.text });
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* One entry per known command: {name, summary, args?, status, reason} with command (the text to run) for a command with no
|
|
19
|
+
* arguments, or values ({value, summary, command | values}) for one with arguments. An unsupported command carries neither.
|
|
20
|
+
* data holds the composer's teams and models, as matchArgs takes them, and mode ({current, place}) for the session's /mode.
|
|
21
|
+
*/
|
|
22
|
+
export function composerActions(harness, data = {}) {
|
|
23
|
+
return COMMANDS.map(known => {
|
|
24
|
+
const support = commandSupport(harness, known.name);
|
|
25
|
+
const entry = { name: known.name, summary: known.summary, ...(known.args ? { args: known.args } : {}), status: support.status, reason: support.reason };
|
|
26
|
+
if (support.status === "unsupported")
|
|
27
|
+
return entry;
|
|
28
|
+
if (!known.args)
|
|
29
|
+
return { ...entry, command: "/" + known.name };
|
|
30
|
+
if (known.name === "afk")
|
|
31
|
+
return { ...entry, values: AFK_VALUES.map(value => ({ ...value, command: "/afk " + value.value })) };
|
|
32
|
+
// /mode lists what the approval card's mode menu lists: the runner modes the harness and the session's place allow.
|
|
33
|
+
// The entry carries the session's live mode so the menu can show it; the matching value is tagged current.
|
|
34
|
+
if (known.name === "mode") {
|
|
35
|
+
const current = data.mode?.current || "";
|
|
36
|
+
return { ...entry, ...(current ? { current } : {}), values: cardModes(harness, data.mode).map(mode => ({ ...mode, command: modeCommand(mode.value), ...(mode.value === current ? { current: true } : {}) })) };
|
|
37
|
+
}
|
|
38
|
+
return { ...entry, values: valuesAfter(harness, "/" + known.name + " ", known.args.split(" ").length, data) };
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Context meter and "files read" for a session. Pure: used by the session header and tested in test/context-view.test.mjs.
|
|
2
|
+
const WARN_PERCENT = 80;
|
|
3
|
+
const FULL_PERCENT = 95;
|
|
4
|
+
const READ_TOOLS = /^(read|read_file)$/i;
|
|
5
|
+
const PATH_FIELDS = ["file_path", "filePath", "path"];
|
|
6
|
+
/** "842", "9.5k", "258k", "1.2M": one decimal under 10k and 10M, whole numbers above. */
|
|
7
|
+
export function formatTokens(n) {
|
|
8
|
+
if (n >= 1_000_000)
|
|
9
|
+
return (n / 1_000_000).toFixed(n >= 10_000_000 ? 0 : 1).replace(/\.0$/, "") + "M";
|
|
10
|
+
if (n >= 1_000)
|
|
11
|
+
return (n / 1_000).toFixed(n >= 10_000 ? 0 : 1).replace(/\.0$/, "") + "k";
|
|
12
|
+
return String(n);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* {text, percent, level} for {tokens, window}. percent and the level are set only when the harness reported a window;
|
|
16
|
+
* level is "ok", "warn" (80% or more) or "full" (95% or more).
|
|
17
|
+
*/
|
|
18
|
+
export function contextMeter({ tokens, window } = {}) {
|
|
19
|
+
if (!Number.isSafeInteger(tokens))
|
|
20
|
+
return { text: "", percent: null, level: "unknown" };
|
|
21
|
+
if (!Number.isSafeInteger(window) || window <= 0)
|
|
22
|
+
return { text: formatTokens(tokens) + " tokens", percent: null, level: "unknown" };
|
|
23
|
+
const percent = Math.min(100, Math.round((tokens / window) * 100));
|
|
24
|
+
const level = percent >= FULL_PERCENT ? "full" : percent >= WARN_PERCENT ? "warn" : "ok";
|
|
25
|
+
return { text: `${formatTokens(tokens)} of ${formatTokens(window)} · ${percent}%`, percent, level };
|
|
26
|
+
}
|
|
27
|
+
function pathOf(input) {
|
|
28
|
+
let value = input;
|
|
29
|
+
if (typeof input === "string") {
|
|
30
|
+
try {
|
|
31
|
+
value = JSON.parse(input);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return "";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (!value || typeof value !== "object")
|
|
38
|
+
return "";
|
|
39
|
+
const found = PATH_FIELDS.map(field => value[field]).find(path => typeof path === "string" && path.trim());
|
|
40
|
+
return found ? found.trim() : "";
|
|
41
|
+
}
|
|
42
|
+
/** Files the session read, from its tool-call rows: [{path, count}], most recently read first. */
|
|
43
|
+
export function filesRead(rows = []) {
|
|
44
|
+
const seen = new Map();
|
|
45
|
+
for (const row of rows) {
|
|
46
|
+
if (row?.type !== "tool_call" || !READ_TOOLS.test(row.tool || ""))
|
|
47
|
+
continue;
|
|
48
|
+
const path = pathOf(row.input);
|
|
49
|
+
if (!path)
|
|
50
|
+
continue;
|
|
51
|
+
const entry = seen.get(path) || { path, count: 0 };
|
|
52
|
+
entry.count += 1;
|
|
53
|
+
seen.delete(path);
|
|
54
|
+
seen.set(path, entry);
|
|
55
|
+
}
|
|
56
|
+
return [...seen.values()].reverse();
|
|
57
|
+
}
|
package/web/lib/fuzzy.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** 3 for a prefix, 2 for a word start, 1 for a subsequence, 0 for no match; whitespace in the query is ignored. */
|
|
2
|
+
export function fuzzyScore(query, text) {
|
|
3
|
+
const q = String(query).toLowerCase().replace(/\s+/g, "");
|
|
4
|
+
const t = String(text || "").toLowerCase();
|
|
5
|
+
if (!q)
|
|
6
|
+
return 1;
|
|
7
|
+
if (!t)
|
|
8
|
+
return 0;
|
|
9
|
+
if (t.startsWith(q))
|
|
10
|
+
return 3;
|
|
11
|
+
if (new RegExp("[^a-z0-9]" + q.replace(/[^a-z0-9]/g, "\\$&")).test(t))
|
|
12
|
+
return 2;
|
|
13
|
+
let at = 0;
|
|
14
|
+
for (const char of t)
|
|
15
|
+
if (char === q[at])
|
|
16
|
+
at++;
|
|
17
|
+
return at === q.length ? 1 : 0;
|
|
18
|
+
}
|
|
19
|
+
/** The best-scoring options for query (ties keep their order), scored by the best of fields(option). */
|
|
20
|
+
export function fuzzyRank(query, options, fields, limit = 8) {
|
|
21
|
+
return options.map((option, i) => ({ option, i, score: Math.max(0, ...fields(option).map(text => fuzzyScore(query, text))) }))
|
|
22
|
+
.filter(item => item.score > 0)
|
|
23
|
+
.sort((a, b) => b.score - a.score || a.i - b.i)
|
|
24
|
+
.slice(0, limit)
|
|
25
|
+
.map(item => item.option);
|
|
26
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Lazy shiki highlighter: the JavaScript regex engine (no WASM, so no 'wasm-unsafe-eval'), dual themes, languages on demand.
|
|
2
|
+
export const HIGHLIGHT_MAX_BYTES = 20 * 1024;
|
|
3
|
+
const LANGS = {
|
|
4
|
+
javascript: () => import("shiki/langs/javascript.mjs"), typescript: () => import("shiki/langs/typescript.mjs"),
|
|
5
|
+
jsx: () => import("shiki/langs/jsx.mjs"), tsx: () => import("shiki/langs/tsx.mjs"), json: () => import("shiki/langs/json.mjs"),
|
|
6
|
+
shellscript: () => import("shiki/langs/shellscript.mjs"), python: () => import("shiki/langs/python.mjs"),
|
|
7
|
+
diff: () => import("shiki/langs/diff.mjs"), markdown: () => import("shiki/langs/markdown.mjs"),
|
|
8
|
+
yaml: () => import("shiki/langs/yaml.mjs"), css: () => import("shiki/langs/css.mjs"), html: () => import("shiki/langs/html.mjs"),
|
|
9
|
+
};
|
|
10
|
+
const ALIASES = {
|
|
11
|
+
js: "javascript", mjs: "javascript", cjs: "javascript", ts: "typescript", mts: "typescript", cts: "typescript",
|
|
12
|
+
bash: "shellscript", sh: "shellscript", shell: "shellscript", zsh: "shellscript", console: "shellscript",
|
|
13
|
+
py: "python", patch: "diff", md: "markdown", yml: "yaml", htm: "html", jsonc: "json", json5: "json",
|
|
14
|
+
};
|
|
15
|
+
const THEMES = { light: "github-light", dark: "github-dark" };
|
|
16
|
+
const loaded = new Map();
|
|
17
|
+
let core;
|
|
18
|
+
/** Shiki's language id for a fence name or file extension, or "" when outside the bundled set. */
|
|
19
|
+
export function languageOf(name) {
|
|
20
|
+
const key = String(name || "").toLowerCase();
|
|
21
|
+
const id = ALIASES[key] || key;
|
|
22
|
+
return Object.hasOwn(LANGS, id) ? id : "";
|
|
23
|
+
}
|
|
24
|
+
function highlighter() {
|
|
25
|
+
core ??= Promise.all([import("shiki/core"), import("shiki/engine/javascript"), import("shiki/themes/github-light.mjs"), import("shiki/themes/github-dark.mjs")])
|
|
26
|
+
.then(([{ createHighlighterCore }, { createJavaScriptRegexEngine }, light, dark]) => createHighlighterCore({ themes: [light.default, dark.default], langs: [], engine: createJavaScriptRegexEngine() }));
|
|
27
|
+
return core;
|
|
28
|
+
}
|
|
29
|
+
/** HTML for code in a supported language, or null: unknown language, over HIGHLIGHT_MAX_BYTES, or a load failure. */
|
|
30
|
+
export async function highlight(code, name) {
|
|
31
|
+
const lang = languageOf(name);
|
|
32
|
+
if (!lang || !code || new Blob([code]).size > HIGHLIGHT_MAX_BYTES)
|
|
33
|
+
return null;
|
|
34
|
+
try {
|
|
35
|
+
const shiki = await highlighter();
|
|
36
|
+
if (!loaded.has(lang))
|
|
37
|
+
loaded.set(lang, LANGS[lang]().then(mod => shiki.loadLanguage(mod.default)));
|
|
38
|
+
await loaded.get(lang);
|
|
39
|
+
return shiki.codeToHtml(code, { lang, themes: THEMES, defaultColor: "light" });
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Labels for the Harness² lesson library sheet: each comes from a stored field, none invented.
|
|
2
|
+
/** "When the tests fail" from a stored cue, or "Any session" for a lesson stored before cues existed. */
|
|
3
|
+
export function cueLabel(lesson) {
|
|
4
|
+
const cue = typeof lesson?.cue === "string" ? lesson.cue.trim().replace(/^when\s+/i, "") : "";
|
|
5
|
+
// "Full test suite fails" reads "When full test suite fails"; an acronym such as "CI fails" keeps its case.
|
|
6
|
+
const lowered = /^[A-Z][a-z]/.test(cue) ? cue[0].toLowerCase() + cue.slice(1) : cue;
|
|
7
|
+
return cue ? "When " + lowered : "Any session";
|
|
8
|
+
}
|
|
9
|
+
/** How many sessions showed the lesson: an absent count is the one session it was learned from. */
|
|
10
|
+
export function seenLabel(lesson) {
|
|
11
|
+
const seen = Number.isSafeInteger(lesson?.seen) && lesson.seen > 1 ? lesson.seen : 1;
|
|
12
|
+
return seen === 1 ? "Seen in 1 session" : "Seen in " + seen + " sessions";
|
|
13
|
+
}
|
|
14
|
+
/** The newest time a session showed the lesson, in ms. */
|
|
15
|
+
export function lastSeen(lesson) {
|
|
16
|
+
return Number.isFinite(lesson?.lastAt) ? lesson.lastAt : Number.isFinite(lesson?.at) ? lesson.at : 0;
|
|
17
|
+
}
|
|
18
|
+
/** Each harness's lessons and the library's total, for the sheet's summary line. */
|
|
19
|
+
export function librarySummary(harnesses = []) {
|
|
20
|
+
const total = harnesses.reduce((sum, h) => sum + (h.lessons?.length || 0), 0);
|
|
21
|
+
const proposed = harnesses.reduce((sum, h) => sum + (h.lessons || []).filter((l) => l.promoted).length, 0);
|
|
22
|
+
return { total, proposed };
|
|
23
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// @peer, @peer#session, @harness:model and @peer#session/run tags; the run is a subagent run ID.
|
|
2
|
+
export const MENTION = /(^|[\s(])@([a-z][\w-]*(?:#[a-f0-9]{16}(?:\/[A-Za-z0-9_-]+)?|:[A-Za-z0-9._/-]*[A-Za-z0-9_/-])?)(?![\w#])/g;
|
|
3
|
+
/** Marks @tags as "#mention" links so Markdown colours only the tag. */
|
|
4
|
+
export function withMentions(body) {
|
|
5
|
+
return String(body).replace(MENTION, "$1[@$2](#mention)");
|
|
6
|
+
}
|
|
7
|
+
/** Non-legacy patterns the composer lists as @mentions. Legacy rosters stay on the team list. */
|
|
8
|
+
export function patternMentionTargets(patterns = []) {
|
|
9
|
+
return (patterns ?? []).filter((pattern) => pattern && pattern.legacy !== true && !pattern.invalid && pattern.name)
|
|
10
|
+
.map((pattern) => ({
|
|
11
|
+
id: pattern.name,
|
|
12
|
+
team: true,
|
|
13
|
+
pattern: true,
|
|
14
|
+
members: (pattern.roles ?? []).map((role) => role.id).filter(Boolean),
|
|
15
|
+
}));
|
|
16
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { taskTags } from "./task-tags.js";
|
|
2
|
+
import { shortName } from "./thread-groups.js";
|
|
3
|
+
const MENTION = /(^|[^\w#-])@([a-z0-9-]{1,24}(?:#[a-f0-9]{16}(?:\/[A-Za-z0-9_-]{1,64})?|:[A-Za-z0-9][A-Za-z0-9._/-]{0,119})?)(?![\w#-])/g;
|
|
4
|
+
/** Session addresses, subagent runs (@session/run), harness names and harness:model pairs tagged with @ in a post, limited to the project's peers. */
|
|
5
|
+
export function mentionedNames(body, peers = [], teams = []) {
|
|
6
|
+
// A full stop after @harness:model ends the sentence, not the model name.
|
|
7
|
+
const teamSet = new Set(teams);
|
|
8
|
+
const names = new Set([...String(body).matchAll(MENTION)].map(match => match[2].replace(/\.+$/, "")));
|
|
9
|
+
return [...names].filter(name => {
|
|
10
|
+
if (teamSet.has(name))
|
|
11
|
+
return false;
|
|
12
|
+
const peer = name.split(/[#:]/)[0];
|
|
13
|
+
return peer !== "operator" && peer !== "all" && (!peers.length || peers.includes(peer));
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* True when a post addresses only the sessions its tags start: at least one @harness:model tag, every tag a model start,
|
|
18
|
+
* and no team or pattern tagged. Such a post must not reach, or wake, a session that is already running.
|
|
19
|
+
*/
|
|
20
|
+
export function startOnlyMentions(body, peers = [], otherNames = []) {
|
|
21
|
+
const names = mentionedNames(body, peers, otherNames);
|
|
22
|
+
return names.length > 0 && names.every((name) => name.includes(":")) && !otherNames.some((name) => mentions(body, name));
|
|
23
|
+
}
|
|
24
|
+
/** Team names tagged with @ in a post. */
|
|
25
|
+
export function mentionedTeams(body, teams = []) {
|
|
26
|
+
return teams.filter((name) => mentions(body, name));
|
|
27
|
+
}
|
|
28
|
+
export const mentions = (body, name) => new RegExp(`(^|[^\\w#-])@${name}(?![\\w-])`).test(body);
|
|
29
|
+
export function messageDestinations(text, target, listTasks) {
|
|
30
|
+
const ids = new Set(taskTags(text).map(match => match[2]));
|
|
31
|
+
const tagged = ids.size && listTasks ? listTasks().filter(task => ids.has(task.id)) : [];
|
|
32
|
+
return { tagged, destinations: new Set(tagged.length ? tagged.map(task => task.owner || "all") : [target]) };
|
|
33
|
+
}
|
|
34
|
+
/** The composer's destination line: where a post goes, naming each direct session by its short name. */
|
|
35
|
+
export function composerDestination(routing) {
|
|
36
|
+
if (!routing.target)
|
|
37
|
+
return "Pick a session first";
|
|
38
|
+
const { project, agents } = routing;
|
|
39
|
+
const { destinations, direct, starts, invocations, startOnly, channel } = composerRoute(routing);
|
|
40
|
+
const shortAddress = address => address.replace(/(#[a-f0-9]{8})[a-f0-9]{8}(?=\/|$)/, "$1");
|
|
41
|
+
const named = address => (!address.includes("/") && shortName(agents.find(agent => agent.id === address))) || shortAddress(address);
|
|
42
|
+
const labels = [];
|
|
43
|
+
if (channel)
|
|
44
|
+
labels.push("Everyone listening in " + (routing.thread.title || "this thread"));
|
|
45
|
+
if (destinations.has("all"))
|
|
46
|
+
labels.push(startOnly ? "Project chat in " + project : "Everyone in " + project);
|
|
47
|
+
if (direct.size)
|
|
48
|
+
labels.push("Direct to " + [...direct].map(named).join(", "));
|
|
49
|
+
if (starts.length)
|
|
50
|
+
labels.push("Start " + starts.join(", "));
|
|
51
|
+
if (invocations.length)
|
|
52
|
+
labels.push("Run " + invocations.join(", "));
|
|
53
|
+
return labels.join(" · ");
|
|
54
|
+
}
|
|
55
|
+
/** True when the composer posts to the open thread's channel: a thread is open and no #task tag routes the post. */
|
|
56
|
+
export function composerChannel(routing) {
|
|
57
|
+
return Boolean(routing.target) && composerRoute(routing).channel;
|
|
58
|
+
}
|
|
59
|
+
/** The session addresses a post goes to directly, for the destination line's title. */
|
|
60
|
+
export function composerRecipients(routing) {
|
|
61
|
+
return routing.target ? [...composerRoute(routing).direct] : [];
|
|
62
|
+
}
|
|
63
|
+
function composerRoute({ target, text, tasks, peers, agents, teams, patterns, startable, models, hosted, quoted, thread, }) {
|
|
64
|
+
const { tagged, destinations } = messageDestinations(text, target, () => tasks.map(task => task.inferredOwner ? { ...task, owner: "" } : task));
|
|
65
|
+
// In an open thread the post goes to the thread channel; the selected session is a listener, not a direct target.
|
|
66
|
+
const channel = Boolean(thread?.id) && !hosted && !tagged.length;
|
|
67
|
+
const names = [...teams.map(team => team.id), ...patterns.map(pattern => pattern.name)];
|
|
68
|
+
const [primary] = destinations;
|
|
69
|
+
const startOnly = !hosted && !quoted && destinations.size === 1 && destinations.has("all")
|
|
70
|
+
&& startOnlyMentions(text, peers, names);
|
|
71
|
+
const direct = new Set(channel ? [] : [...destinations].filter(to => to !== "all"));
|
|
72
|
+
const starts = [];
|
|
73
|
+
if (!hosted) {
|
|
74
|
+
const sessions = agents.filter(agent => agent.registered);
|
|
75
|
+
for (const name of mentionedNames(text, peers, names)) {
|
|
76
|
+
if (name === primary)
|
|
77
|
+
continue;
|
|
78
|
+
if (name.includes(":")) {
|
|
79
|
+
const [harness, model] = name.split(":");
|
|
80
|
+
if (startable.includes(harness) && models[harness]?.includes(model))
|
|
81
|
+
starts.push(name);
|
|
82
|
+
}
|
|
83
|
+
else if (name.includes("#")) {
|
|
84
|
+
if (sessions.some(agent => agent.id === name.split("/")[0]))
|
|
85
|
+
direct.add(name);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
const running = sessions.filter(agent => agent.peer === name && agent.online);
|
|
89
|
+
for (const agent of running)
|
|
90
|
+
direct.add(agent.id);
|
|
91
|
+
if (!running.length && !sessions.some(agent => agent.peer === name && destinations.has(agent.id))
|
|
92
|
+
&& startable.includes(name))
|
|
93
|
+
starts.push(name);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const invocations = [];
|
|
98
|
+
if (!hosted) {
|
|
99
|
+
invocations.push(...mentionedTeams(text, patterns.filter(pattern => !pattern.legacy).map(pattern => pattern.name)));
|
|
100
|
+
if (primary === "all" && startable.includes("claude")) {
|
|
101
|
+
invocations.push(...mentionedTeams(text, teams.map(team => team.id)));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return { destinations, direct, starts, invocations: [...new Set(invocations)], startOnly, channel };
|
|
105
|
+
}
|