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.
import { ChevronRight, Sparkles } from "lucide-react";
import { useMemo } from "react";
import {
toolGroupPresentation,
toolNameLabel,
toolPresentation,
} from "@/features/rooms/runtime-status/runtime-tool-presentation";
import { MessageMarkdown } from "@/features/rooms/chat/message-markdown";
import { TaskActivityBlock } from "@/features/rooms/runtime-status/task-activity-block";
import {
parseTaskCommand,
createdTaskId,
type TaskCommand,
} from "@/features/rooms/runtime-status/task-command";
import type { TeamHubMessageActivityRecord } from "@/features/teamhub/teamhub-types";
import type { Translate } from "@/i18n/language";
import { useT } from "@/i18n/use-translation";
import { runtimeStatusMessages } from "@/features/rooms/runtime-status/runtime-status.messages";
import {
activityMessageText,
asObject,
contentBlockRecords,
indexToolCalls,
isAssistantMessage,
isEventRecord,
isUserMessage,
nativeCommand,
nativeOutput,
nativePayload,
reasoningText,
stringValue,
type ToolCallPair,
} from "./native-activity-records";
import { runPanelMessages as m } from "./run-panel.messages";
export function RuntimeHistoryView({
records,
}: {
records: TeamHubMessageActivityRecord[];
}) {
const t = useT();
const orderedRecords = useMemo(
() => [...records].sort((left, right) => left.ordinal - right.ordinal),
[records],
);
const callPairs = useMemo(
() => indexToolCalls(orderedRecords),
[orderedRecords],
);
const items = useMemo(
() => activityTimelineItems(t, orderedRecords, callPairs),
[t, callPairs, orderedRecords],
);
return (
<ol
aria-label={t(runtimeStatusMessages.activityLog)}
className="space-y-1 bg-white px-4 py-3 text-xs font-normal leading-5 text-app-body"
>
{items.map((item) =>
item.kind === "tool_calls" ? (
<RuntimeToolCallsActivity calls={item.calls} key={item.key} />
) : item.kind === "task" ? (
<TaskActivityBlock
command={item.command}
key={item.key}
taskId={item.taskId}
/>
) : (
<RuntimeActivityRecord key={item.key} record={item.record} />
),
)}
</ol>
);
}
interface ActivityToolCall {
pair?: ToolCallPair;
record: TeamHubMessageActivityRecord;
}
type ActivityTimelineItem =
| { calls: ActivityToolCall[]; key: string; kind: "tool_calls" }
| { command: TaskCommand; key: string; kind: "task"; taskId?: string }
| {
kind: "record";
key: string;
record: TeamHubMessageActivityRecord;
};
function activityTimelineItems(
t: Translate,
records: TeamHubMessageActivityRecord[],
callPairs: ReadonlyMap<string, ToolCallPair>,
): ActivityTimelineItem[] {
const items: ActivityTimelineItem[] = [];
const thinkingTitles = new Set<string>();
// Later steps name a Task only by id; reuse the name it was created with.
const taskNames = new Map<string, string>();
for (const source of records.flatMap(contentBlockRecords)) {
let record = source;
if (record.native_type === "event_msg.mcp_tool_call_end") {
const invocation = asObject(nativePayload(record)?.invocation);
record = {
...record,
category: "tool_call",
tool_name: toolNameLabel(
stringValue(invocation?.tool) ?? t(m.toolCall),
),
};
} else if (record.category === "tool_call") {
if (
record.tool_name === "exec" &&
!parseTaskCommand(nativeCommand(record) ?? "")
)
continue;
} else if (record.category === "reasoning") {
const summary = reasoningText(t, record);
if (!summary?.trim()) continue;
if (thinkingTitles.has(summary)) continue;
thinkingTitles.add(summary);
} else if (record.category === "message") {
if (
isEventRecord(record) ||
(!isAssistantMessage(record) && !isUserMessage(record)) ||
(isUserMessage(record) && activityMessageText(t, record).length > 240)
)
continue;
} else {
continue;
}
const pair = record.tool_call_id
? callPairs.get(record.tool_call_id)
: undefined;
const taskCommand =
record.category === "tool_call"
? parseTaskCommand(nativeCommand(record) ?? "")
: undefined;
if (taskCommand) {
const taskId =
taskCommand.taskId ??
(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({
command: name ? { ...taskCommand, name } : taskCommand,
key: `task-${record.ordinal}-${items.length}`,
kind: "task",
taskId,
});
continue;
}
if (record.category !== "tool_call") {
items.push({
kind: "record",
key: `record-${record.ordinal}-${items.length}`,
record,
});
continue;
}
const previous = items.at(-1);
if (previous?.kind === "tool_calls") {
previous.calls.push({ pair, record });
continue;
}
items.push({
calls: [{ pair, record }],
key: `tool-calls-${record.ordinal}`,
kind: "tool_calls",
});
}
return items;
}
function RuntimeToolCallsActivity({ calls }: { calls: ActivityToolCall[] }) {
const t = useT();
const presentedCalls = calls.map(({ pair, record }) => {
const name = record.tool_name ?? pair?.call?.tool_name ?? t(m.toolCall);
const invocation = asObject(nativePayload(record)?.invocation);
// Native history carries tool names, not activity kinds: show the name.
const shownName = stringValue(invocation?.tool) ?? name;
return {
record,
name: shownName,
...toolPresentation(t, "tool", shownName),
};
});
const { icon: GroupIcon, label: groupLabel } = toolGroupPresentation(
t,
presentedCalls,
);
return (
<li>
<details className="group">
<summary className="flex min-h-8 cursor-pointer list-none items-center gap-2 py-1.5 text-app-muted hover:text-app-body focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-app-focus [&::-webkit-details-marker]:hidden">
<span className="relative inline-flex size-[15px] shrink-0 items-center justify-center">
<GroupIcon
aria-hidden="true"
className="absolute inset-0 m-auto group-hover:hidden group-focus-within:hidden group-open:hidden"
size={15}
/>
<ChevronRight
aria-hidden="true"
className="absolute inset-0 m-auto hidden group-hover:block group-focus-within:block group-open:block group-open:rotate-90 motion-reduce:transition-none"
size={15}
/>
</span>
<span className="min-w-0 flex-1 truncate" title={groupLabel}>
{groupLabel}
</span>
</summary>
<ul className="space-y-1 pb-3 pl-[1.45rem]">
{presentedCalls.map(({ record, name, icon: Icon, label }) => {
return (
<li
className="flex min-h-7 items-center gap-2"
key={`${record.ordinal}:${record.tool_call_id}`}
>
<Icon aria-label={label} className="shrink-0" size={13} />
<span className="truncate" title={name}>
{name}
</span>
</li>
);
})}
</ul>
</details>
</li>
);
}
function RuntimeActivityRecord({
record,
}: {
record: TeamHubMessageActivityRecord;
}) {
const t = useT();
if (record.category === "reasoning") {
const title = reasoningText(t, record)?.replace(
/^\*\*([\s\S]+)\*\*$/,
"$1",
);
return (
<li className="flex min-h-8 items-start gap-2 py-1.5 text-app-muted">
<Sparkles aria-hidden="true" className="mt-0.5 shrink-0" size={15} />
<p className="min-w-0 flex-1 line-clamp-2" title={title}>
{title}
</p>
</li>
);
}
return (
<li className="py-2">
<MessageMarkdown
authorKind={isAssistantMessage(record) ? "agent" : "human"}
body={activityMessageText(t, record)}
/>
</li>
);
}