Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

fix(web): link a Task step by the ID its receipt names

LeoXing1f9c1bc4131e
diff --git a/apps/web/src/features/rooms/runtime-status/runtime-activity-path.test.tsx b/apps/web/src/features/rooms/runtime-status/runtime-activity-path.test.tsx
index e89a968e..5a2344bc 100644
--- a/apps/web/src/features/rooms/runtime-status/runtime-activity-path.test.tsx
+++ b/apps/web/src/features/rooms/runtime-status/runtime-activity-path.test.tsx
@@ -53,6 +53,10 @@ describe("Runtime activity path", () => {
label: "Input",
},
];
+ const created = "workitem_0123456789abcdef0123456789abcdef";
+ const receipt = (text: string) => [
+ { content: text, format: "text" as const, label: "Output" },
+ ];
const items = projectRuntimeActivityPath([
record("1", {
activity_id: "create",
@@ -65,6 +69,7 @@ describe("Runtime activity path", () => {
}),
record("2", {
activity_id: "create",
+ content: receipt(`Task created and running\nTask ID: ${created}`),
outcome: "succeeded",
type: "activity.finished",
}),
@@ -77,12 +82,27 @@ describe("Runtime activity path", () => {
title: "Bash",
type: "activity.started",
}),
+ record("4", {
+ activity_id: "check",
+ content: input("teamhub task check"),
+ kind: "tool",
+ title: "Bash",
+ type: "activity.started",
+ }),
+ record("5", {
+ activity_id: "check",
+ // A check lists many Tasks; none of them is the step's own.
+ content: receipt(`Rivals ${created} running`),
+ outcome: "succeeded",
+ type: "activity.finished",
+ }),
]);
expect(items).toMatchObject([
{
active: false,
command: { name: "Rivals", operation: "create" },
kind: "task",
+ taskId: created,
},
{
active: true,
@@ -90,7 +110,9 @@ describe("Runtime activity path", () => {
kind: "task",
taskId: "workitem_1",
},
+ { command: { operation: "check" }, kind: "task" },
]);
+ expect(items[2]).not.toHaveProperty("taskId");
});
it("positions the viewport at the bottom of the latest activity, including a tall last entry", async () => {
diff --git a/apps/web/src/features/rooms/runtime-status/runtime-activity-path.ts b/apps/web/src/features/rooms/runtime-status/runtime-activity-path.ts
index 4b922dc3..6b02ec49 100644
--- a/apps/web/src/features/rooms/runtime-status/runtime-activity-path.ts
+++ b/apps/web/src/features/rooms/runtime-status/runtime-activity-path.ts
@@ -9,7 +9,7 @@ import {
} from "./runtime-presentation-events";
import {
parseTaskCommand,
- taskIdFromOutput,
+ createdTaskId,
type TaskCommand,
} from "./task-command";
@@ -272,9 +272,14 @@ function pushActivity(
if (activity.kind === "response") return;
// The Computer names a TeamHub command by what it does, so a Task step can
// arrive as any kind; its `teamhub task` command line is what marks it.
- const task = parseTaskCommand(commandText(entries));
+ const input = inputBlock(entries);
+ const task = parseTaskCommand(commandText(input));
if (task) {
- const taskId = task.taskId ?? taskIdFromOutput(outputText(entries));
+ const taskId =
+ task.taskId ??
+ (task.operation === "create"
+ ? createdTaskId(outputText(entries, input))
+ : undefined);
items.push({
active,
command: task,
@@ -333,13 +338,17 @@ function pushActivity(
});
}
-/** The command line an Activity ran, from its first code or JSON block. */
-function commandText(entries: readonly RuntimeActivityEntry[]) {
- const block = entries.find(
+/** An Activity's input: its first code or JSON block. */
+function inputBlock(entries: readonly RuntimeActivityEntry[]) {
+ return entries.find(
(entry) =>
entry.type === "content" &&
(entry.block.format === "code" || entry.block.format === "json"),
);
+}
+
+/** The command line an Activity ran, from its input block. */
+function commandText(block: RuntimeActivityEntry | undefined) {
if (block?.type !== "content") return "";
if (block.block.format === "code") return block.block.content;
try {
@@ -356,10 +365,15 @@ function commandText(entries: readonly RuntimeActivityEntry[]) {
return "";
}
-/** Every block the Activity carried; a CLI receipt would be among them. */
-function outputText(entries: readonly RuntimeActivityEntry[]) {
+/** What the Activity published besides its input, such as a CLI receipt. */
+function outputText(
+ entries: readonly RuntimeActivityEntry[],
+ input: RuntimeActivityEntry | undefined,
+) {
return entries
- .map((entry) => (entry.type === "content" ? entry.block.content : ""))
+ .map((entry) =>
+ entry !== input && entry.type === "content" ? entry.block.content : "",
+ )
.join("\n");
}
diff --git a/apps/web/src/features/rooms/runtime-status/task-activity-block.tsx b/apps/web/src/features/rooms/runtime-status/task-activity-block.tsx
index 63cfe8f5..7625d4fa 100644
--- a/apps/web/src/features/rooms/runtime-status/task-activity-block.tsx
+++ b/apps/web/src/features/rooms/runtime-status/task-activity-block.tsx
@@ -12,17 +12,12 @@ import { StatusPill } from "@/components/ui/status-pill";
import { teamHubData } from "@/features/teamhub/teamhub-api";
import { useTeamHubRuntime } from "@/features/teamhub/teamhub-runtime";
import type { TeamHubTaskExecution } from "@/features/teamhub/teamhub-types";
-import {
- roomTasksQueryOptions,
- tenantWorkItemTargetQueryOptions,
-} from "@/features/work-items/work-item-queries";
+import { tenantWorkItemTargetQueryOptions } from "@/features/work-items/work-item-queries";
import { RunningDots } from "../task-sidebar/running-dots";
import type { TaskCommand } from "./task-command";
interface TaskActivityLinks {
- /** The Room whose Meta ran these steps. */
- roomId: string;
tenantId: string;
openTask?: (taskId: string, title: string) => void;
}
@@ -33,13 +28,9 @@ const TaskActivityLinksContext = createContext<TaskActivityLinks | null>(null);
export function TaskActivityLinksProvider({
children,
openTask,
- roomId,
tenantId,
}: TaskActivityLinks & { children: ReactNode }) {
- const links = useMemo(
- () => ({ openTask, roomId, tenantId }),
- [openTask, roomId, tenantId],
- );
+ const links = useMemo(() => ({ openTask, tenantId }), [openTask, tenantId]);
return (
<TaskActivityLinksContext.Provider value={links}>
{children}
@@ -78,32 +69,18 @@ export function TaskActivityBlock({
const links = useContext(TaskActivityLinksContext);
const { client } = useTeamHubRuntime();
const tenantId = links?.tenantId ?? "";
- // A create step's receipt stays on the Computer, so it names no Task; the
- // Room's Tasks hold it under the same name once the step has finished.
- const named = useQuery({
- ...roomTasksQueryOptions(client, tenantId, links?.roomId ?? ""),
- enabled:
- !taskId &&
- !active &&
- command.operation === "create" &&
- Boolean(command.name && links?.roomId),
- retry: false,
- select: (page) => page.items.filter((task) => task.title === command.name),
- });
- const id =
- taskId ?? (named.data?.length === 1 ? named.data[0]!.id : undefined);
- const readable = Boolean(id && tenantId) && command.operation !== "check";
+ const readable = Boolean(taskId && tenantId) && command.operation !== "check";
const item = useQuery({
- ...tenantWorkItemTargetQueryOptions(client, tenantId, id ?? ""),
+ ...tenantWorkItemTargetQueryOptions(client, tenantId, taskId ?? ""),
enabled: readable && !command.name,
retry: false,
});
const execution = useQuery({
- queryKey: ["teamhub", tenantId, "task-execution", id],
+ queryKey: ["teamhub", tenantId, "task-execution", taskId],
queryFn: () =>
teamHubData(
client.api.GET("/v0/tasks/{taskId}/execution", {
- params: { path: { taskId: id ?? "" } },
+ params: { path: { taskId: taskId ?? "" } },
}),
),
enabled: readable,
@@ -119,8 +96,8 @@ export function TaskActivityBlock({
? undefined
: (command.name ?? item.data?.title);
const open =
- id && title !== undefined && links?.openTask
- ? () => links.openTask?.(id, title)
+ taskId && title !== undefined && links?.openTask
+ ? () => links.openTask?.(taskId, title)
: undefined;
const row = (
<>
diff --git a/apps/web/src/features/rooms/runtime-status/task-command.ts b/apps/web/src/features/rooms/runtime-status/task-command.ts
index d5b9803d..2bc0d50d 100644
--- a/apps/web/src/features/rooms/runtime-status/task-command.ts
+++ b/apps/web/src/features/rooms/runtime-status/task-command.ts
@@ -54,10 +54,12 @@ export function parseTaskCommand(command: string): TaskCommand | undefined {
};
}
-/** The `task_id` in the CLI's JSON receipt, when the output carries one. */
-export function taskIdFromOutput(output: string | undefined) {
- const match = output?.match(/"task_id"\s*:\s*"([A-Za-z0-9][A-Za-z0-9_-]*)"/);
- return match?.[1];
+/**
+ * The Task a `task create` receipt names. The receipt is display text, so the
+ * Task is found by TeamHub's ID format, never by the receipt's wording.
+ */
+export function createdTaskId(output: string | undefined) {
+ return output?.match(/\bworkitem_[0-9a-f]{32}\b/)?.[0];
}
/** Splits a command line into words, honoring single and double quotes. */
diff --git a/apps/web/src/features/rooms/task-sidebar/adapters/runtime-history-view.test.tsx b/apps/web/src/features/rooms/task-sidebar/adapters/runtime-history-view.test.tsx
index a3f81fb1..b03c0ccf 100644
--- a/apps/web/src/features/rooms/task-sidebar/adapters/runtime-history-view.test.tsx
+++ b/apps/web/src/features/rooms/task-sidebar/adapters/runtime-history-view.test.tsx
@@ -1,8 +1,12 @@
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { fireEvent, render, screen, within } from "@testing-library/react";
-import { describe, expect, it } from "vitest";
+import { describe, expect, it, vi } from "vitest";
+import { TeamHubRuntimeProvider } from "@/features/teamhub/teamhub-runtime";
import type { TeamHubMessageActivityRecord } from "@/features/teamhub/teamhub-types";
+import { createTestTeamHubRuntime } from "@/test/teamhub-test-runtime";
+import { TaskActivityLinksProvider } from "../../runtime-status/task-activity-block";
import { RuntimeHistoryView } from "./runtime-history-view";
describe("RuntimeHistoryView", () => {
@@ -163,6 +167,76 @@ describe("RuntimeHistoryView", () => {
expect(screen.getByText("fixed").tagName).toBe("STRONG");
});
+ it("opens the Task a create step's receipt names", async () => {
+ const created = "workitem_0123456789abcdef0123456789abcdef";
+ const runtime = createTestTeamHubRuntime();
+ runtime.server.on("GET", "/v0/tasks/{taskId}/execution", () => ({
+ status: "idle",
+ task_id: created,
+ }));
+ const openTask = vi.fn();
+ const command =
+ 'teamhub task create --name "Rivals" --requirement "Compare"';
+ render(
+ <QueryClientProvider
+ client={
+ new QueryClient({ defaultOptions: { queries: { retry: false } } })
+ }
+ >
+ <TeamHubRuntimeProvider runtime={runtime}>
+ <TaskActivityLinksProvider openTask={openTask} tenantId="tenant-1">
+ <RuntimeHistoryView
+ records={[
+ claudeRecord(0, "tool_call", {
+ native_type: "assistant.tool_use",
+ role: "assistant",
+ tool_call_id: "create",
+ tool_name: "Bash",
+ native_record: {
+ type: "assistant",
+ message: {
+ role: "assistant",
+ content: [
+ {
+ type: "tool_use",
+ id: "create",
+ name: "Bash",
+ input: { command },
+ },
+ ],
+ },
+ },
+ }),
+ claudeRecord(1, "tool_result", {
+ native_type: "user.tool_result",
+ role: "user",
+ tool_call_id: "create",
+ tool_name: "Bash",
+ native_record: {
+ type: "user",
+ message: {
+ role: "user",
+ content: [
+ {
+ type: "tool_result",
+ tool_use_id: "create",
+ content: `Task created and running\nTask ID: ${created}`,
+ },
+ ],
+ },
+ },
+ }),
+ ]}
+ />
+ </TaskActivityLinksProvider>
+ </TeamHubRuntimeProvider>
+ </QueryClientProvider>,
+ );
+ expect(await screen.findByText("Finished")).toBeVisible();
+ fireEvent.click(screen.getByRole("button", { name: "Open task Rivals" }));
+ expect(openTask).toHaveBeenCalledWith(created, "Rivals");
+ });
+
it("includes thinking, reply and every tool from mixed Claude messages", () => {
render(
<RuntimeHistoryView
diff --git a/apps/web/src/features/rooms/task-sidebar/adapters/runtime-history-view.tsx b/apps/web/src/features/rooms/task-sidebar/adapters/runtime-history-view.tsx
index fbdea093..c43a8b87 100644
--- a/apps/web/src/features/rooms/task-sidebar/adapters/runtime-history-view.tsx
+++ b/apps/web/src/features/rooms/task-sidebar/adapters/runtime-history-view.tsx
@@ -11,7 +11,7 @@ import { MessageMarkdown } from "@/features/rooms/chat/message-markdown";
import { TaskActivityBlock } from "@/features/rooms/runtime-status/task-activity-block";
import {
parseTaskCommand,
- taskIdFromOutput,
+ createdTaskId,
type TaskCommand,
} from "@/features/rooms/runtime-status/task-command";
import type { TeamHubMessageActivityRecord } from "@/features/teamhub/teamhub-types";
@@ -133,7 +133,9 @@ function activityTimelineItems(
if (taskCommand) {
const taskId =
taskCommand.taskId ??
- taskIdFromOutput(pair?.result && nativeOutput(pair.result));
+ (taskCommand.operation === "create" && pair?.result
+ ? createdTaskId(nativeOutput(pair.result))
+ : undefined);
if (taskId && taskCommand.name) taskNames.set(taskId, taskCommand.name);
const name = taskCommand.name ?? (taskId && taskNames.get(taskId));
items.push({
diff --git a/apps/web/src/features/rooms/task-sidebar/adapters/task-conversation-dialog.tsx b/apps/web/src/features/rooms/task-sidebar/adapters/task-conversation-dialog.tsx
index 2a899876..ee8f2e66 100644
--- a/apps/web/src/features/rooms/task-sidebar/adapters/task-conversation-dialog.tsx
+++ b/apps/web/src/features/rooms/task-sidebar/adapters/task-conversation-dialog.tsx
@@ -48,11 +48,7 @@ export function TaskConversationProvider({
[],
);
return (
- <TaskActivityLinksProvider
- openTask={openTask}
- roomId={roomId}
- tenantId={tenantId}
- >
+ <TaskActivityLinksProvider openTask={openTask} tenantId={tenantId}>
{children}
{task ? (
<TaskConversationDialog
diff --git a/apps/web/src/features/work-items/work-item-queries.ts b/apps/web/src/features/work-items/work-item-queries.ts
index 1a7a6371..fb10e458 100644
--- a/apps/web/src/features/work-items/work-item-queries.ts
+++ b/apps/web/src/features/work-items/work-item-queries.ts
@@ -91,34 +91,6 @@ export function tenantAgentWorkItemsQueryOptions(
});
}
-/** Every Task the Room's Meta delegated, finished ones included. */
-export function roomTasksQueryOptions(
- client: Pick<TeamHubClient, "api">,
- tenantId: string,
- roomId: string,
-) {
- return queryOptions({
- queryFn: () =>
- collectTeamHubCursorPages((pagination) =>
- teamHubData(
- client.api.GET("/v0/tenants/{tenantId}/work-items", {
- params: {
- path: { tenantId },
- query: {
- ...pagination,
- kind: "task",
- origin_room_id: roomId,
- scope: "tenant",
- },
- },
- }),
- ),
- ),
- queryKey: ["teamhub", tenantId, "work-items", "room-tasks", roomId],
- staleTime: 0,
- });
-}
-
export function tenantWorkItemsDashboardQueryOptions(
client: Pick<TeamHubClient, "api">,
tenantId: string,