mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-03 11:47:42 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - A task thread shows an agent's runs, and each new run starts from the task's saved context > - A second hands-on check of Google Antigravity `/swarm` runs (after #22886) still found gaps > - The first ordinary follow-up after a swarm was slow: it spent minutes searching the instance's run logs to learn what the swarm did > - The thread also showed each file twice, lost the "Swarm" note after a reload, and read "Swarm Swarm started…" > - This pull request gives the next run the swarm's result in its opening context and removes the prompt's pointer to run records, and it fixes the four thread problems > - The benefit is a faster follow-up after a swarm and a thread that says each thing once ## Linked Issues or Issue Description Refs #22886 **What happened?** 1. After a finished `/swarm`, the ordinary follow-up "append three to v1.txt" took 4 min 6 s (an earlier one took 5.5 min). The agent read the server's raw run log of the swarm run with about 20 shell commands, searched the instance folder, and listed processes. Other follow-ups took 41 s and 105 s. 2. Each file showed twice: the run's file card, and a second card under the final reply (from the reply's "Download: v1.txt" link). This also happened on the ordinary follow-up. 3. The "Swarm" note on the user's message showed while live, but not after a page reload. 4. Swarm activity rows read "Swarm Swarm started in the task folder…", with the word twice. **Expected behavior** 1. The follow-up starts with what the swarm did, so it has no reason to search for it. 2. Each file shows once per run, as the run's file card. 3. The "Swarm" note shows after a reload. 4. A swarm row reads its sentence once. **Steps to reproduce** 1. Send `/swarm Create v1.txt containing "one" and v2.txt containing "two", one helper per file, then verify both.` to a Google Antigravity agent. 2. When it finishes, look at the files and the activity rows, then reload the page. 3. Send the ordinary follow-up `append three to v1.txt` and time it. 4. Put another task in Plan mode and send `/swarm do something`. ## What Changed - Follow-up context (cause of item 1). A swarm runs in the Antigravity CLI, and an ordinary turn runs on the registry route. The ordinary route cannot reopen the swarm's conversation, so the Runner refuses the saved session and the server starts a fresh one. That fresh session gets the same wake prompt as any other turn. Before this change, its only record of the swarm was the task continuation summary, and that summary listed no files ("No file or route paths were detected"; the path detector only knows repository folders such as `server/`). It also gave three run ids and said "Detailed shell/tool commands remain in the run log and transcript." The agent followed that line: its first searches matched the swarm's run id, and an earlier follow-up searched for `transcript*.jsonl` files. An ordinary follow-up after an ordinary turn gets the same prompt, but it resumes its own conversation, so it already knows what it did. - `issue-continuation-summary.ts` (shared by every harness): a new "Files Delivered" section lists, by name, the files the run handed in as deliverables (applied or duplicate receipts), newest first, and keeps earlier runs' names. These names are kept apart from "Files / Routes Touched", because a deliverable's name is not always its path. The run's own checks are listed, read through the shared accepted-result reader. The summary contains no run ids, adapter names or log locations. The "Commands Run" section is removed: it held only the run id and the log pointer. The summary reaches the next turn through the existing mechanism (the wake prompt's "Issue continuation summary" and the continuation evidence). - Server: `GET /issues/:id/recent-comments` and both chat bootstrap routes now add the swarm marker with the same shared rule (`withAntigravitySwarmMarkers`) as the comment list, the single comment and the POST response. A cold task page reads this recent window, so the marker was missing after a reload. - UI: a reply does not show a second card for a file that its own run already shows as a file card. The reply text and its links do not change. A later run's reply that links the same file still shows the file. - UI: a swarm progress row shows its sentence without the "Swarm" label. A failed or stopped row keeps its label and marker. Live and settled rows use the same rule. Not changed, by investigation: - "Check passed cat v1.txt one\nthree" and "verifier check on swarm board #6": the model wrote both strings in its `paperclip_finish` call. The Runner's first record of the result already holds the literal backslash and the board number, so this is model text, not Paperclip's presentation. - The inline "Download: v1.txt" links in the reply are the model's own words, so they stay. - No read-confinement policy is added. The agent finds the instance folder from its working directory, not from the prompt. - A refused send still shows its reason twice (inline under the composer and as a toast). Each attempt to remove the toast missed a send path, which could leave a refusal with no visible reason. A repeated reason is better than a missing one, so this PR does not change the toast. ## Verification - Red/green `server/src/__tests__/issue-continuation-summary.test.ts`: a swarm's accepted result (from a live run, with ids replaced) is built into the summary and rendered into the follow-up's wake prompt. The prompt contains the hand-in summary, `v1.txt` and `v2.txt` under "Files Delivered" (one with a different content reference and a duplicate receipt), and the verifier check. A later run lists its own delivered file first. A full path list still takes the latest run's path first. It contains no run id, "run log", "transcript", attachment path, digest or adapter name. A later run keeps the files listed. This failed before the change. - Red/green `server/src/__tests__/issue-chat-bootstrap-routes.test.ts` (embedded Postgres): for an ordinary task and a conversation, a recorded `/swarm` request carries `nativeCommand: "swarm"` on `GET /comments`, `GET /comments/:id`, `GET /recent-comments`, `GET /issues/:ref/chat-bootstrap` and the batch chat bootstrap. It failed on `recent-comments` before the change. - Red/green `ui/src/components/TaskChatThread.test.tsx`: a reply that links its run's file shows no second card; a later run's reply still shows it. It failed before the change. - Red/green `ui/src/components/task-chat/antigravity-thread.test.tsx`: the live swarm fixture's rows read "Swarm started in the task folder…" (no doubled word), and live rows equal settled rows. - Focused suites: UI `TaskChatThread.test.tsx` and `src/components/task-chat` (925 tests), server bootstrap routes (19 tests) and continuation summary (7 tests) pass. UI and server typechecks pass. - Not proved without a live run: that the next follow-up after a swarm is faster. The tests prove the opening input; the agent's behavior with that input needs a live Antigravity run. ## Risks - The continuation summary wording changes for every harness that runs on a task (every adapter whose finished run refreshes the summary, not only Antigravity): no run ids, no adapter name, no "Commands Run" section, and a new "Files Delivered" section when the run registered deliverables. Nothing in the code parses those lines. Older saved summaries keep their text until the next run refreshes them. - One extra indexed activity-log query for each recent-comments or chat-bootstrap read (the same query the comment list already runs). The bootstrap budget test still passes. - The second-card rule matches only a file whose card belongs to the same run as the reply. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use (shell, file edits, test runs). ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
469 lines
22 KiB
TypeScript
469 lines
22 KiB
TypeScript
/**
|
|
* Provider-neutral tool vocabulary shared by live status, transcript rows,
|
|
* and canonical provider activity. Exact semantic tools get purpose-specific
|
|
* copy; ACP kinds and normalized name prefixes cover future adapters.
|
|
*/
|
|
import {
|
|
BookOpen,
|
|
Brain,
|
|
ChevronsLeftRightEllipsis,
|
|
CircleHelp,
|
|
Clock3,
|
|
FilePenLine,
|
|
Image,
|
|
ListChecks,
|
|
MessageSquareReply,
|
|
Network,
|
|
Search,
|
|
SearchCode,
|
|
ShieldCheck,
|
|
Terminal,
|
|
Wrench,
|
|
} from "lucide-react";
|
|
import type { ComponentType, SVGProps } from "react";
|
|
import { McpIcon } from "./McpIcon";
|
|
|
|
/** Lucide icons and hand-rolled SVGs (the MCP logo) share this shape. */
|
|
export type ToolIcon = ComponentType<SVGProps<SVGSVGElement>>;
|
|
|
|
export type ToolFamily =
|
|
| "terminal"
|
|
| "grep"
|
|
| "search"
|
|
| "read"
|
|
| "edit"
|
|
| "web"
|
|
| "plan"
|
|
| "question"
|
|
| "agent"
|
|
| "safety"
|
|
| "image"
|
|
| "wait"
|
|
| "mcp"
|
|
| "other";
|
|
|
|
export interface ToolTaxonomyEntry {
|
|
family: ToolFamily;
|
|
icon: ToolIcon;
|
|
/** Progressive verb for the status pill, without the trailing ellipsis. */
|
|
verbLabel: string;
|
|
}
|
|
|
|
export type ToolClassificationConfidence = "exact" | "kind" | "inferred" | "fallback" | "unnamed";
|
|
|
|
export interface ToolActivityPresentationInput {
|
|
name?: string | null;
|
|
transport?: string | null;
|
|
namespace?: string | null;
|
|
/** ACP kind or canonical operation. */
|
|
operation?: string | null;
|
|
target?: string | null;
|
|
progress?: string | null;
|
|
}
|
|
|
|
export interface ToolSummaryGroup {
|
|
key: string;
|
|
singular: string;
|
|
plural: string;
|
|
}
|
|
|
|
export interface ToolActivityPresentation {
|
|
icon: ToolIcon;
|
|
family: ToolFamily;
|
|
runningLabel: string;
|
|
completedLabel: string;
|
|
failedLabel: string;
|
|
interruptedLabel: string;
|
|
displayName: string;
|
|
sourceLabel?: string;
|
|
technicalName?: string;
|
|
confidence: ToolClassificationConfidence;
|
|
summaryGroup: ToolSummaryGroup;
|
|
sentenceSubject?: boolean;
|
|
}
|
|
|
|
/** Families whose rows read as "<verb> <subject>", for example "Read README.md". */
|
|
export const SUBJECT_FAMILIES: ReadonlySet<ToolFamily> = new Set(["terminal", "read", "edit", "grep", "search", "web"]);
|
|
|
|
/**
|
|
* The label of a row that shows a concrete subject, for live and settled rows
|
|
* alike: only the verb and any outcome ("Read · failed" beside "u1.txt"), or
|
|
* nothing for a settled command, whose "$ " subject says it ran.
|
|
*/
|
|
export function subjectRowLabel(label: string, settledCommand: boolean): string {
|
|
if (settledCommand) return "";
|
|
const [action, marker] = label.split(" · ");
|
|
return `${action!.split(" ")[0]}${marker ? ` · ${marker}` : ""}`;
|
|
}
|
|
|
|
export function sentenceRowLabel(label: string): string {
|
|
return label.includes(" · ") ? label : "";
|
|
}
|
|
|
|
/** "Read · failed" → "Read · retried", for a failure a later call of the same tool recovered. */
|
|
export function retriedLabel(failedLabel: string): string {
|
|
return failedLabel.replace(/ · failed$/, " · retried");
|
|
}
|
|
|
|
/** ACPX's placeholder title must never displace real lifecycle identity. */
|
|
const GENERIC_TOOL_NAMES = new Set(["tool", "tool call", "tool_call", "acp_tool"]);
|
|
|
|
export function isGenericToolName(name: string | undefined | null): boolean {
|
|
const raw = (name ?? "")
|
|
.trim()
|
|
.toLowerCase()
|
|
.replace(/\s*\((?:pending|in[_ -]?progress|completed|failed|cancelled|canceled)\)$/, "");
|
|
return !raw || GENERIC_TOOL_NAMES.has(raw);
|
|
}
|
|
|
|
interface McpIdentity {
|
|
namespace: string;
|
|
name: string;
|
|
}
|
|
|
|
export function mcpToolIdentity(name: string): McpIdentity | null {
|
|
const doubleUnderscore = name.match(/^mcp__(.+?)__(.+)$/i);
|
|
if (doubleUnderscore) return { namespace: doubleUnderscore[1], name: doubleUnderscore[2] };
|
|
const dotted = name.match(/^mcp\.([^.]+)\.(.+)$/i);
|
|
return dotted ? { namespace: dotted[1], name: dotted[2] } : null;
|
|
}
|
|
|
|
function identifierWords(value: string): string[] {
|
|
return value
|
|
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
|
|
.replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2")
|
|
.replace(/[^A-Za-z0-9]+/g, " ")
|
|
.trim()
|
|
.toLowerCase()
|
|
.split(/\s+/)
|
|
.filter(Boolean);
|
|
}
|
|
|
|
function sentenceCase(words: readonly string[]): string {
|
|
if (words.length === 0) return "";
|
|
const text = words.map((word) => {
|
|
if (["api", "id", "lsp", "mcp", "pr", "url"].includes(word)) return word.toUpperCase();
|
|
return word;
|
|
}).join(" ");
|
|
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
}
|
|
|
|
export function humanizeToolName(name: string | undefined | null): string {
|
|
const raw = (name ?? "").trim();
|
|
if (isGenericToolName(raw)) return "Unnamed tool";
|
|
const mcp = mcpToolIdentity(raw);
|
|
return sentenceCase(identifierWords(mcp?.name ?? raw));
|
|
}
|
|
|
|
/** Humanized MCP tool segment for both mcp__server__tool and mcp.server.tool. */
|
|
export function mcpToolSegment(name: string): string | null {
|
|
const identity = mcpToolIdentity(name);
|
|
return identity ? humanizeToolName(identity.name) : null;
|
|
}
|
|
|
|
type Action =
|
|
| "read" | "list" | "search" | "fetch" | "open" | "update" | "create"
|
|
| "delete" | "move" | "run" | "request" | "post" | "start" | "stop"
|
|
| "wait" | "finish" | "block" | "think" | "switch" | "other";
|
|
|
|
interface ExactAction {
|
|
action: Action;
|
|
running?: string;
|
|
completed?: string;
|
|
group?: ToolSummaryGroup;
|
|
family?: ToolFamily;
|
|
sentence?: boolean;
|
|
}
|
|
|
|
const group =(key: string, singular: string, plural: string): ToolSummaryGroup => ({ key, singular, plural });
|
|
|
|
const EXACT_ACTIONS: Record<string, ExactAction> = {
|
|
bash: { action: "run" },
|
|
terminal: { action: "run" },
|
|
shell: { action: "run" },
|
|
command: { action: "run" },
|
|
run: { action: "run" },
|
|
execute: { action: "run" },
|
|
exec_command: { action: "run" },
|
|
apply_patch: { action: "update", running: "Applying a patch", completed: "Applied a patch" },
|
|
read: { action: "read", running: "Reading a file", completed: "Read a file" },
|
|
write: { action: "update", running: "Writing a file", completed: "Wrote a file" },
|
|
edit: { action: "update", running: "Editing a file", completed: "Edited a file" },
|
|
notebook_read: { action: "read", running: "Reading a notebook", completed: "Read a notebook" },
|
|
notebook_edit: { action: "update", running: "Editing a notebook", completed: "Edited a notebook" },
|
|
glob: { action: "search", running: "Searching files", completed: "Searched files" },
|
|
grep: { action: "search", running: "Searching file contents", completed: "Searched file contents", family: "grep" },
|
|
tool_search: { action: "search", running: "Searching available tools", completed: "Searched available tools", group: group("tool_search", "tool search", "tool searches") },
|
|
web_search: { action: "search", running: "Searching the web", completed: "Searched the web", family: "web" },
|
|
web_fetch: { action: "fetch", running: "Fetching a web page", completed: "Fetched a web page", family: "web" },
|
|
todo_write: { action: "update", running: "Updating the task list", completed: "Updated the task list", family: "plan", group: group("task_operation", "task operation", "task operations") },
|
|
task_create: { action: "create", running: "Creating a task", completed: "Created a task", family: "plan", group: group("task_operation", "task operation", "task operations") },
|
|
task_update: { action: "update", running: "Updating a task", completed: "Updated a task", family: "plan", group: group("task_operation", "task operation", "task operations") },
|
|
task_list: { action: "list", running: "Listing tasks", completed: "Listed tasks", family: "plan", group: group("task_operation", "task operation", "task operations") },
|
|
task_get: { action: "read", running: "Reading a task", completed: "Read a task", family: "plan", group: group("task_operation", "task operation", "task operations") },
|
|
enter_plan_mode: { action: "switch", running: "Entering plan mode", completed: "Entered plan mode", family: "plan" },
|
|
exit_plan_mode: { action: "switch", running: "Leaving plan mode", completed: "Left plan mode", family: "plan" },
|
|
skill: { action: "read", running: "Loading a skill", completed: "Loaded a skill" },
|
|
ask_user_question: { action: "request", running: "Requesting input", completed: "Requested input", family: "question" },
|
|
request_human_input: { action: "request", running: "Requesting input", completed: "Requested input", family: "question", group: group("task_operation", "task operation", "task operations") },
|
|
agent: { action: "start", running: "Starting a subagent", completed: "Started a subagent", family: "agent" },
|
|
task: { action: "start", running: "Starting a subagent", completed: "Started a subagent", family: "agent" },
|
|
task_output: { action: "read", running: "Checking subagent progress", completed: "Checked subagent progress", family: "agent" },
|
|
task_stop: { action: "stop", running: "Stopping a subagent", completed: "Stopped a subagent", family: "agent" },
|
|
send_message: { action: "post", running: "Messaging a subagent", completed: "Messaged a subagent", family: "agent" },
|
|
spawn_agent: { action: "start", running: "Starting a subagent", completed: "Started a subagent", family: "agent" },
|
|
wait_agent: { action: "wait", running: "Checking subagent progress", completed: "Checked subagent progress", family: "agent" },
|
|
wait_threads: { action: "wait", running: "Checking task progress", completed: "Checked task progress", family: "agent" },
|
|
interrupt_agent: { action: "stop", running: "Interrupting a subagent", completed: "Interrupted a subagent", family: "agent" },
|
|
report_findings: { action: "post", running: "Reporting findings", completed: "Reported findings", family: "safety" },
|
|
guardian_review: { action: "think", running: "Reviewing safety", completed: "Reviewed safety", family: "safety" },
|
|
lsp: { action: "read", running: "Inspecting code intelligence", completed: "Inspected code intelligence" },
|
|
compact_conversation: { action: "think", running: "Compacting context", completed: "Compacted context" },
|
|
image_generation: { action: "create", running: "Generating an image", completed: "Generated an image", family: "image" },
|
|
view_image: { action: "read", running: "Viewing an image", completed: "Viewed an image", family: "image" },
|
|
multi_tool_use_parallel: { action: "run", running: "Running tools in parallel", completed: "Ran tools in parallel" },
|
|
get_task_context: { action: "read", running: "Reading task context", completed: "Read task context" },
|
|
get_task_history: { action: "read", running: "Reading task history", completed: "Read task history" },
|
|
list_documents: { action: "list", running: "Listing documents", completed: "Listed documents" },
|
|
read_document: { action: "read", running: "Reading a document", completed: "Read a document" },
|
|
list_document_revisions: { action: "list", running: "Listing document revisions", completed: "Listed document revisions" },
|
|
report_progress: { action: "post", running: "Reporting progress", completed: "Reported progress" },
|
|
answer_status_question: { action: "post", running: "Answering a status question", completed: "Answered a status question" },
|
|
write_document: { action: "update", running: "Writing a document", completed: "Wrote a document" },
|
|
// With the file as its subject the row reads "Attached u1.txt".
|
|
register_deliverable: { action: "create", running: "Attaching a file", completed: "Attached a file" },
|
|
// Antigravity's swarm progress lines; the subject is the whole plain sentence.
|
|
swarm_update: { action: "other", running: "Swarm", completed: "Swarm", family: "agent", sentence: true, group: group("swarm_update", "swarm update", "swarm updates") },
|
|
finish_task: { action: "finish", running: "Reporting completion", completed: "Reported completion" },
|
|
paperclip_finish: { action: "finish", running: "Reporting completion", completed: "Reported completion" },
|
|
block_task: { action: "block", running: "Reporting a blocker", completed: "Reported a blocker" },
|
|
paperclip_block: { action: "block", running: "Reporting a blocker", completed: "Reported a blocker" },
|
|
request_review: { action: "request", running: "Requesting review", completed: "Requested review" },
|
|
list_agents: { action: "list", running: "Listing agents", completed: "Listed agents" },
|
|
get_agent: { action: "read", running: "Reading agent details", completed: "Read agent details" },
|
|
search_tasks: { action: "search", running: "Searching tasks", completed: "Searched tasks" },
|
|
list_approvals: { action: "list", running: "Listing approvals", completed: "Listed approvals" },
|
|
get_approval: { action: "read", running: "Reading an approval", completed: "Read an approval" },
|
|
get_approval_context: { action: "read", running: "Reading approval context", completed: "Read approval context" },
|
|
get_workspace_runtime: { action: "read", running: "Reading workspace status", completed: "Read workspace status" },
|
|
control_workspace_service: { action: "run", running: "Controlling a workspace service", completed: "Controlled a workspace service" },
|
|
set_dependencies: { action: "update", running: "Updating task dependencies", completed: "Updated task dependencies" },
|
|
set_task_title: { action: "update", running: "Naming the task", completed: "Named the task" },
|
|
create_task: { action: "create", running: "Creating a task", completed: "Created a task" },
|
|
request_approval: { action: "request", running: "Requesting approval", completed: "Requested approval" },
|
|
decide_approval: { action: "update", running: "Deciding an approval", completed: "Decided an approval" },
|
|
comment_on_approval: { action: "post", running: "Commenting on an approval", completed: "Commented on an approval" },
|
|
schedule_wake: { action: "create", running: "Scheduling a wake-up", completed: "Scheduled a wake-up", family: "wait" },
|
|
generic_api_request: { action: "request", running: "Calling the Paperclip API", completed: "Called the Paperclip API" },
|
|
};
|
|
|
|
const ACTION_PREFIXES: Record<Action, readonly string[]> = {
|
|
read: ["get", "read", "inspect", "view"],
|
|
list: ["list", "glob"],
|
|
search: ["find", "search", "grep", "query", "lookup"],
|
|
fetch: ["fetch", "browse"],
|
|
open: ["open"],
|
|
update: ["write", "edit", "update", "set", "patch", "upsert", "sync"],
|
|
create: ["create", "add", "register", "upload"],
|
|
delete: ["delete", "remove"],
|
|
move: ["move", "rename"],
|
|
run: ["run", "execute", "bash", "shell", "command"],
|
|
request: ["request", "ask", "prompt"],
|
|
post: ["send", "message", "comment", "report", "answer"],
|
|
start: ["start", "spawn", "delegate"],
|
|
stop: ["stop", "cancel", "interrupt"],
|
|
wait: ["wait", "sleep", "poll"],
|
|
finish: ["finish", "complete"],
|
|
block: ["block"],
|
|
think: ["think", "reason", "compact", "review"],
|
|
switch: ["switch", "enter", "exit"],
|
|
other: [],
|
|
};
|
|
|
|
const OPERATION_ACTIONS: Record<string, Action> = {
|
|
read: "read",
|
|
edit: "update",
|
|
delete: "delete",
|
|
move: "move",
|
|
search: "search",
|
|
list: "list",
|
|
execute: "run",
|
|
think: "think",
|
|
fetch: "fetch",
|
|
switch_mode: "switch",
|
|
};
|
|
|
|
function normalizedKey(name: string): string {
|
|
return identifierWords(name).join("_");
|
|
}
|
|
|
|
function inferredAction(words: readonly string[]): Action | null {
|
|
const first = words[0];
|
|
if (!first) return null;
|
|
for (const [action, prefixes] of Object.entries(ACTION_PREFIXES) as Array<[Action, readonly string[]]>) {
|
|
if (prefixes.includes(first)) return action;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function actionFamily(action: Action): ToolFamily {
|
|
if (action === "run") return "terminal";
|
|
if (action === "read" || action === "list") return "read";
|
|
if (action === "search") return "search";
|
|
if (action === "fetch" || action === "open") return "web";
|
|
if (["update", "create", "delete", "move"].includes(action)) return "edit";
|
|
if (action === "request") return "question";
|
|
if (action === "start" || action === "stop") return "agent";
|
|
if (action === "wait") return "wait";
|
|
return "other";
|
|
}
|
|
|
|
const FAMILY_ICONS: Record<ToolFamily, ToolIcon> = {
|
|
terminal: Terminal,
|
|
grep: SearchCode,
|
|
search: Search,
|
|
read: BookOpen,
|
|
edit: FilePenLine,
|
|
web: ChevronsLeftRightEllipsis,
|
|
plan: ListChecks,
|
|
question: CircleHelp,
|
|
agent: Network,
|
|
safety: ShieldCheck,
|
|
image: Image,
|
|
wait: Clock3,
|
|
mcp: McpIcon,
|
|
other: Wrench,
|
|
};
|
|
|
|
function actionCopy(action: Action, object: string | undefined): { running: string; completed: string } {
|
|
const suffix = object ? ` ${object}` : "";
|
|
switch (action) {
|
|
case "read": return { running: `Reading${suffix || " data"}`, completed: `Read${suffix || " data"}` };
|
|
case "list": return { running: `Listing${suffix || " items"}`, completed: `Listed${suffix || " items"}` };
|
|
case "search": return { running: `Searching${suffix || ""}`, completed: `Searched${suffix || ""}` };
|
|
case "fetch": return { running: `Fetching${suffix || " data"}`, completed: `Fetched${suffix || " data"}` };
|
|
case "open": return { running: `Opening${suffix || " an item"}`, completed: `Opened${suffix || " an item"}` };
|
|
case "update": return { running: `Updating${suffix || " data"}`, completed: `Updated${suffix || " data"}` };
|
|
case "create": return { running: `Creating${suffix || " an item"}`, completed: `Created${suffix || " an item"}` };
|
|
case "delete": return { running: `Deleting${suffix || " an item"}`, completed: `Deleted${suffix || " an item"}` };
|
|
case "move": return { running: `Moving${suffix || " an item"}`, completed: `Moved${suffix || " an item"}` };
|
|
case "run": return { running: "Running a command", completed: "Ran a command" };
|
|
case "request": return { running: `Requesting${suffix || " input"}`, completed: `Requested${suffix || " input"}` };
|
|
case "post": return { running: `Posting${suffix || " an update"}`, completed: `Posted${suffix || " an update"}` };
|
|
case "start": return { running: `Starting${suffix || " an operation"}`, completed: `Started${suffix || " an operation"}` };
|
|
case "stop": return { running: `Stopping${suffix || " an operation"}`, completed: `Stopped${suffix || " an operation"}` };
|
|
case "wait": return { running: "Waiting", completed: "Finished waiting" };
|
|
case "finish": return { running: "Reporting completion", completed: "Reported completion" };
|
|
case "block": return { running: "Reporting a blocker", completed: "Reported a blocker" };
|
|
case "think": return { running: "Thinking", completed: "Finished thinking" };
|
|
case "switch": return { running: `Switching${suffix || " mode"}`, completed: `Switched${suffix || " mode"}` };
|
|
case "other": return { running: "Running", completed: "Ran" };
|
|
}
|
|
}
|
|
|
|
function defaultSummaryGroup(action: Action): ToolSummaryGroup {
|
|
switch (action) {
|
|
case "run": return group("command", "command", "commands");
|
|
case "read":
|
|
case "list": return group("read", "read", "reads");
|
|
case "search": return group("search", "search", "searches");
|
|
case "update":
|
|
case "create":
|
|
case "delete":
|
|
case "move": return group("file_change", "file change", "file changes");
|
|
case "start":
|
|
case "stop": return group("delegation", "delegation", "delegations");
|
|
case "wait": return group("wait", "wait", "waits");
|
|
default: return group("tool_action", "tool action", "tool actions");
|
|
}
|
|
}
|
|
|
|
function paperclipSummaryGroup(action: Action): ToolSummaryGroup {
|
|
if (action === "read" || action === "list") return group("paperclip_read", "Paperclip read", "Paperclip reads");
|
|
return group("task_operation", "task operation", "task operations");
|
|
}
|
|
|
|
/**
|
|
* Resolve one tool into status-specific copy and iconography. Precedence is:
|
|
* exact aliases, canonical ACP operation/kind, normalized verb, then a named
|
|
* fallback. MCP remains visible as the source icon without losing semantics.
|
|
*/
|
|
export function toolActivityPresentation(input: ToolActivityPresentationInput): ToolActivityPresentation {
|
|
const rawName = (input.name ?? "").trim();
|
|
const parsedMcp = mcpToolIdentity(rawName);
|
|
const namespace = (input.namespace ?? parsedMcp?.namespace ?? "").trim();
|
|
// The name itself is authoritative for historical ACPX records that were
|
|
// persisted as builtin before MCP transport normalization existed.
|
|
const transport = (parsedMcp ? "mcp" : input.transport ?? "builtin").toLowerCase();
|
|
const semanticName = (parsedMcp?.name ?? rawName).trim();
|
|
const words = identifierWords(semanticName);
|
|
const key = normalizedKey(semanticName);
|
|
const exact = EXACT_ACTIONS[key];
|
|
const operationAction = OPERATION_ACTIONS[(input.operation ?? "").trim().toLowerCase()];
|
|
const inferred = inferredAction(words);
|
|
const action = exact?.action ?? operationAction ?? inferred ?? "other";
|
|
const confidence: ToolClassificationConfidence = exact
|
|
? "exact"
|
|
: operationAction
|
|
? "kind"
|
|
: inferred
|
|
? "inferred"
|
|
: isGenericToolName(semanticName)
|
|
? "unnamed"
|
|
: "fallback";
|
|
const displayName = isGenericToolName(semanticName) ? "Unnamed tool" : humanizeToolName(semanticName);
|
|
const identifierLikeName = /^[A-Za-z][A-Za-z0-9_.:-]*$/.test(semanticName);
|
|
const objectWords = inferred && identifierLikeName && words.length > 1 ? words.slice(1) : [];
|
|
const object = objectWords.length ? sentenceCase(objectWords).replace(/^./, (letter) => letter.toLowerCase()) : undefined;
|
|
const copy = exact?.running && exact.completed
|
|
? { running: exact.running, completed: exact.completed }
|
|
: action === "other"
|
|
? isGenericToolName(semanticName)
|
|
? { running: "Running an unnamed tool", completed: "Ran an unnamed tool" }
|
|
: { running: `Running ${displayName}`, completed: `Ran ${displayName}` }
|
|
: actionCopy(action, exact ? undefined : object);
|
|
const semanticFamily = exact?.family ?? actionFamily(action);
|
|
const family = transport === "mcp" ? "mcp" : semanticFamily;
|
|
const sourceLabel = namespace
|
|
? humanizeToolName(namespace)
|
|
: transport === "mcp"
|
|
? "MCP"
|
|
: undefined;
|
|
const summaryGroup = namespace.toLowerCase() === "paperclip"
|
|
? paperclipSummaryGroup(action)
|
|
: exact?.group ?? defaultSummaryGroup(action);
|
|
|
|
return {
|
|
icon: FAMILY_ICONS[family],
|
|
family,
|
|
runningLabel: copy.running,
|
|
completedLabel: copy.completed,
|
|
failedLabel: `${copy.completed} · failed`,
|
|
interruptedLabel: `${copy.running} · stopped`,
|
|
displayName,
|
|
sourceLabel,
|
|
technicalName: rawName || undefined,
|
|
confidence,
|
|
summaryGroup,
|
|
...(exact?.sentence ? { sentenceSubject: true } : {}),
|
|
};
|
|
}
|
|
|
|
/** Compact compatibility mapping used by legacy tool rows and live pills. */
|
|
export function toolTaxonomy(name: string | undefined | null): ToolTaxonomyEntry {
|
|
const presentation = toolActivityPresentation({ name });
|
|
return {
|
|
family: presentation.family,
|
|
icon: presentation.icon,
|
|
verbLabel: presentation.runningLabel,
|
|
};
|
|
}
|
|
|
|
/** Icons for tool-free informative statuses. */
|
|
export function statusLabelIcon(label: string | undefined | null): ToolIcon | null {
|
|
const raw = (label ?? "").trim().toLowerCase();
|
|
if (raw === "thinking") return Brain;
|
|
if (raw === "responding" || raw.startsWith("responding (")) return MessageSquareReply;
|
|
return null;
|
|
}
|