@koinzhang/paseo-plugin-activity 0.7.0 → 0.8.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.
@@ -1,9 +1,8 @@
1
- import { Icon, TextInput } from "@getpaseo/plugin/client/react-native";
1
+ import { Icon, TextInput } from "@getpaseo/plugin/client/ui";
2
2
  import { useEffect, useMemo, useRef, useState, type ReactNode, type RefObject } from "react";
3
3
  import {
4
4
  Animated,
5
5
  Easing,
6
- Pressable,
7
6
  Text,
8
7
  View,
9
8
  type TextStyle,
@@ -18,6 +17,7 @@ import {
18
17
  countSubAgentsByParent,
19
18
  isAgentRunning,
20
19
  SEARCH_ANIM_MS,
20
+ SEARCH_CLOSE_ANIM_MS,
21
21
  SEARCH_TITLE_GAP,
22
22
  type AgentGroup,
23
23
  type AgentShowField,
@@ -26,7 +26,8 @@ import {
26
26
  } from "./constants.ts";
27
27
  import { formatAgentMeta } from "./filters.ts";
28
28
  import type { WorkspaceTheme } from "./constants.ts";
29
- import { CONTROL, ICON_SIZE } from "../design-tokens.ts";
29
+ import { ICON_SIZE } from "../design-tokens.ts";
30
+ import { IconButton } from "../ui.tsx";
30
31
  import { useMessages } from "../use-app-language.ts";
31
32
 
32
33
  export type AgentsSectionStyles = AgentRowStyles & {
@@ -201,8 +202,8 @@ export function AgentsSection({
201
202
  if (!agentSearchOpen) return;
202
203
  Animated.timing(searchProgress, {
203
204
  toValue: 0,
204
- duration: SEARCH_ANIM_MS,
205
- easing: Easing.in(Easing.cubic),
205
+ duration: SEARCH_CLOSE_ANIM_MS,
206
+ easing: Easing.out(Easing.cubic),
206
207
  useNativeDriver: false,
207
208
  }).start(({ finished }) => {
208
209
  if (!finished) return;
@@ -315,34 +316,24 @@ export function AgentsSection({
315
316
  </Animated.View>
316
317
  </View>
317
318
  <View style={styles.headerActions}>
318
- <Pressable
319
- accessibilityRole="button"
320
- accessibilityLabel={agentSearchOpen ? m.workspace.closeSearch : m.workspace.openSearch}
321
- accessibilityState={{ expanded: agentSearchOpen }}
322
- hitSlop={CONTROL.hitSlop}
319
+ <IconButton
320
+ icon={agentSearchOpen ? "X" : "Search"}
321
+ label={agentSearchOpen ? m.workspace.closeSearch : m.workspace.openSearch}
322
+ expanded={agentSearchOpen}
323
323
  onPress={() => {
324
324
  if (agentSearchOpen) closeAgentSearch();
325
325
  else openAgentSearch();
326
326
  }}
327
- style={styles.titleAction}
328
- >
329
- <Icon
330
- name={agentSearchOpen ? "X" : "Search"}
331
- size={ICON_SIZE.action}
332
- color={theme.colors.foregroundMuted}
333
- />
334
- </Pressable>
327
+ color={theme.colors.foregroundMuted}
328
+ />
335
329
  <View ref={triggerRef} collapsable={false}>
336
- <Pressable
337
- accessibilityRole="button"
338
- accessibilityLabel={m.workspace.displayOptions}
339
- accessibilityState={{ expanded: menuOpen }}
340
- hitSlop={CONTROL.hitSlop}
330
+ <IconButton
331
+ icon="Settings2"
332
+ label={m.workspace.displayOptions}
333
+ expanded={menuOpen}
341
334
  onPress={onToggleMenu}
342
- style={styles.titleAction}
343
- >
344
- <Icon name="Settings2" size={ICON_SIZE.action} color={theme.colors.foregroundMuted} />
345
- </Pressable>
335
+ color={theme.colors.foregroundMuted}
336
+ />
346
337
  </View>
347
338
  </View>
348
339
  </View>
@@ -365,34 +356,25 @@ export function AgentsSection({
365
356
  ) : null}
366
357
  {showPager ? (
367
358
  <View style={styles.pagerRow}>
368
- <Pressable
369
- accessibilityRole="button"
370
- accessibilityLabel={m.workspace.previousPage}
371
- accessibilityState={{ disabled: safePage === 0 }}
372
- disabled={safePage === 0}
373
- hitSlop={CONTROL.hitSlop}
359
+ <IconButton
360
+ icon="ChevronLeft"
361
+ label={m.workspace.previousPage}
374
362
  onPress={() => setPageIndex((p) => Math.max(0, p - 1))}
375
- style={[styles.pagerButton, safePage === 0 ? styles.pagerButtonDisabled : null]}
376
- >
377
- <Icon name="ChevronLeft" size={ICON_SIZE.action} color={theme.colors.foregroundMuted} />
378
- </Pressable>
363
+ color={theme.colors.foregroundMuted}
364
+ disabled={safePage === 0}
365
+ style={safePage === 0 ? styles.pagerButtonDisabled : undefined}
366
+ />
379
367
  <Text style={styles.pagerLabel}>
380
368
  {safePage + 1} / {pageCount}
381
369
  </Text>
382
- <Pressable
383
- accessibilityRole="button"
384
- accessibilityLabel={m.workspace.nextPage}
385
- accessibilityState={{ disabled: safePage >= pageCount - 1 }}
386
- disabled={safePage >= pageCount - 1}
387
- hitSlop={CONTROL.hitSlop}
370
+ <IconButton
371
+ icon="ChevronRight"
372
+ label={m.workspace.nextPage}
388
373
  onPress={() => setPageIndex((p) => Math.min(pageCount - 1, p + 1))}
389
- style={[
390
- styles.pagerButton,
391
- safePage >= pageCount - 1 ? styles.pagerButtonDisabled : null,
392
- ]}
393
- >
394
- <Icon name="ChevronRight" size={ICON_SIZE.action} color={theme.colors.foregroundMuted} />
395
- </Pressable>
374
+ color={theme.colors.foregroundMuted}
375
+ disabled={safePage >= pageCount - 1}
376
+ style={safePage >= pageCount - 1 ? styles.pagerButtonDisabled : undefined}
377
+ />
396
378
  </View>
397
379
  ) : null}
398
380
  </View>
@@ -81,6 +81,8 @@ export type MenuOption = { id: string; label: string; icon: string };
81
81
  /** Agents header row / search pill height — keep fixed to avoid layout jump. */
82
82
  export const AGENT_HEADER_HEIGHT = 28;
83
83
  export const SEARCH_ANIM_MS = 220;
84
+ /** Closing stays faster than opening (084). */
85
+ export const SEARCH_CLOSE_ANIM_MS = 160;
84
86
  export const SEARCH_TITLE_GAP = 8;
85
87
  /** Host MenuFlyout overlap between root surface and submenu (`SUBMENU_OVERLAP`). */
86
88
  export const MENU_SUBMENU_OVERLAP = 5;
@@ -1,4 +1,4 @@
1
- import { Icon } from "@getpaseo/plugin/client/react-native";
1
+ import { Icon } from "@getpaseo/plugin/client/ui";
2
2
  import type { ReactNode } from "react";
3
3
  import { Pressable, Text, View, type TextStyle, type ViewStyle } from "react-native";
4
4
  import { type MenuOption } from "./constants.ts";
@@ -4,7 +4,7 @@ import {
4
4
  useRpc,
5
5
  useSettings,
6
6
  } from "@getpaseo/plugin/client";
7
- import { useToast } from "@getpaseo/plugin/client/react-native";
7
+ import { useToast } from "@getpaseo/plugin/client/ui";
8
8
  import { useQuery, useQueryClient } from "@tanstack/react-query";
9
9
  import { useEffect, useMemo, useRef, useState } from "react";
10
10
  import { useRegisterOpenAgent } from "../open-agent.ts";
@@ -429,6 +429,9 @@ export function WorkspaceActivityPanel({
429
429
  gap: 12,
430
430
  paddingVertical: ROW_PADDING.dense,
431
431
  },
432
+ listRowPressed: {
433
+ backgroundColor: theme.colors.surface2,
434
+ },
432
435
  timelineMarker: {
433
436
  width: 18,
434
437
  alignSelf: "stretch" as const,
@@ -535,6 +538,9 @@ export function WorkspaceActivityPanel({
535
538
  gap: 10,
536
539
  paddingVertical: ROW_PADDING.dense,
537
540
  },
541
+ terminalRowPressed: {
542
+ backgroundColor: theme.colors.surface2,
543
+ },
538
544
  terminalPreview: {
539
545
  marginLeft: 28,
540
546
  marginBottom: 4,
@@ -1,4 +1,4 @@
1
- import { Icon } from "@getpaseo/plugin/client/react-native";
1
+ import { Icon } from "@getpaseo/plugin/client/ui";
2
2
  import type { ReactNode } from "react";
3
3
  import { Pressable, Text, View, type TextStyle, type ViewStyle } from "react-native";
4
4
  import { formatDisplayName } from "../../shared/format.ts";
@@ -26,6 +26,7 @@ export type RankSectionStyles = {
26
26
  headerActions: ViewStyle;
27
27
  panel: ViewStyle;
28
28
  listRow: ViewStyle;
29
+ listRowPressed: ViewStyle;
29
30
  timelineMarker: ViewStyle;
30
31
  timelineLineTop: ViewStyle;
31
32
  timelineLineBottom: ViewStyle;
@@ -126,7 +127,7 @@ export function RankSection({
126
127
  accessibilityState={{ disabled: !canOpen }}
127
128
  disabled={!canOpen}
128
129
  onPress={canOpen ? () => openAgent({ agentId: item.agentId }) : undefined}
129
- style={styles.listRow}
130
+ style={({ pressed }) => [styles.listRow, pressed ? styles.listRowPressed : null]}
130
131
  >
131
132
  <View style={styles.timelineMarker}>
132
133
  {index > 0 ? <View style={styles.timelineLineTop} /> : null}
@@ -169,7 +170,7 @@ export function RankSection({
169
170
  accessibilityState={{ disabled: !canOpen }}
170
171
  disabled={!canOpen}
171
172
  onPress={canOpen ? () => openAgent({ agentId: item.agentId }) : undefined}
172
- style={styles.listRow}
173
+ style={({ pressed }) => [styles.listRow, pressed ? styles.listRowPressed : null]}
173
174
  >
174
175
  <View style={styles.timelineMarker}>
175
176
  {index > 0 ? <View style={styles.timelineLineTop} /> : null}
@@ -21,7 +21,7 @@ export function RunningIndicator({
21
21
  toValue: 1,
22
22
  duration: SPIN_DURATION_MS,
23
23
  easing: Easing.linear,
24
- useNativeDriver: false,
24
+ useNativeDriver: true,
25
25
  }),
26
26
  );
27
27
  animation.start();
@@ -1,5 +1,5 @@
1
1
  import { usePaseo } from "@getpaseo/plugin/client";
2
- import { Icon } from "@getpaseo/plugin/client/react-native";
2
+ import { Icon } from "@getpaseo/plugin/client/ui";
3
3
  import { useQuery } from "@tanstack/react-query";
4
4
  import { useEffect, useState, type ReactNode } from "react";
5
5
  import {
@@ -14,7 +14,7 @@ import {
14
14
  import { collapseHomePath } from "../../shared/home-path.ts";
15
15
  import { TERMINAL_PREVIEW_LINES, TERMINAL_REFETCH_MS } from "./constants.ts";
16
16
  import { terminalPreviewLines } from "./terminal-preview.ts";
17
- import { CONTROL, ICON_SIZE } from "../design-tokens.ts";
17
+ import { CONTROL, ICON_SIZE, PRESS } from "../design-tokens.ts";
18
18
  import { useMessages } from "../use-app-language.ts";
19
19
 
20
20
  export type TerminalListItem = {
@@ -30,6 +30,7 @@ export type TerminalsSectionStyles = {
30
30
  sectionTitle: TextStyle;
31
31
  panel: ViewStyle;
32
32
  terminalRow: ViewStyle;
33
+ terminalRowPressed: ViewStyle;
33
34
  listMain: ViewStyle;
34
35
  listTitle: TextStyle;
35
36
  listMeta: TextStyle;
@@ -100,7 +101,10 @@ export function TerminalsSection({
100
101
  }
101
102
  accessibilityState={{ expanded }}
102
103
  onPress={() => setExpandedId(expanded ? null : item.id)}
103
- style={styles.terminalRow}
104
+ style={({ pressed }) => [
105
+ styles.terminalRow,
106
+ pressed ? styles.terminalRowPressed : null,
107
+ ]}
104
108
  {...(Platform.OS === "web"
105
109
  ? ({
106
110
  onMouseEnter: () => setHoveredId(item.id),
@@ -126,7 +130,11 @@ export function TerminalsSection({
126
130
  hitSlop={CONTROL.hitSlop}
127
131
  onPress={() => onClose(item)}
128
132
  pointerEvents={showClose ? "auto" : "none"}
129
- style={[styles.titleAction, { opacity: showClose ? 1 : 0 }]}
133
+ style={({ pressed }) => [
134
+ styles.titleAction,
135
+ { opacity: showClose ? 1 : 0 },
136
+ pressed ? { opacity: PRESS.opacity, transform: [{ scale: PRESS.scale }] } : null,
137
+ ]}
130
138
  >
131
139
  {busy ? (
132
140
  <ActivityIndicator size="small" color={mutedColor} />
package/index.client.tsx CHANGED
@@ -4,11 +4,12 @@ import { UsagePanel } from "./client/panel.tsx";
4
4
  import { contributeAttentionPills } from "./client/attention-pill.tsx";
5
5
  import { contributeHeaderButtons } from "./client/header-button.ts";
6
6
  import { contributePills } from "./client/pill.tsx";
7
+ import { ACTIVITY_SCREEN_ID, ActivitySidebarItem } from "./client/sidebar-item.tsx";
7
8
  import { WorkspaceActivityPanel } from "./client/workspace-panel.tsx";
8
9
  import { currentAppLanguage, watchAppLanguage } from "./client/use-app-language.ts";
9
10
  import { messagesFor } from "./shared/i18n.ts";
10
11
 
11
- const GLOBAL_SURFACE_ID = "activity";
12
+ const GLOBAL_SCREEN_ID = ACTIVITY_SCREEN_ID;
12
13
 
13
14
  /** Command titles follow the app language; the host has no update(), so re-register on change. */
14
15
  function addScopedCommands(client: PluginClientContext): () => void {
@@ -40,19 +41,21 @@ function addScopedCommands(client: PluginClientContext): () => void {
40
41
  }
41
42
 
42
43
  export default function contribute(client: PluginClientContext) {
43
- client.addSurface(GLOBAL_SURFACE_ID, GlobalUsageSurface);
44
- client.addSidebarItem({
45
- id: "activity",
44
+ client.addScreen({
45
+ id: GLOBAL_SCREEN_ID,
46
46
  title: "Activity",
47
- icon: "Activity",
48
- surface: GLOBAL_SURFACE_ID,
47
+ Component: GlobalUsageSurface,
48
+ });
49
+ client.addSidebarHeaderItem({
50
+ id: GLOBAL_SCREEN_ID,
51
+ title: "Activity",
52
+ Component: ActivitySidebarItem,
49
53
  });
50
54
 
51
- client.addWorkspacePanel({
55
+ client.addAgentPanel({
52
56
  id: "usage",
53
57
  title: "Activity",
54
58
  icon: "Activity",
55
- context: "agent",
56
59
  Component: UsagePanel,
57
60
  });
58
61
 
@@ -60,7 +63,6 @@ export default function contribute(client: PluginClientContext) {
60
63
  id: "workspace-activity",
61
64
  title: "Activity",
62
65
  icon: "Activity",
63
- context: "workspace",
64
66
  locations: ["explorer"],
65
67
  Component: WorkspaceActivityPanel,
66
68
  });
@@ -71,8 +73,8 @@ export default function contribute(client: PluginClientContext) {
71
73
  icon: "Activity",
72
74
  keywords: ["activity", "tool", "usage", "provider", "all", "global", "sidebar"],
73
75
  context: "global",
74
- onSelect({ openSurface }) {
75
- openSurface(GLOBAL_SURFACE_ID);
76
+ onSelect({ openScreen }) {
77
+ openScreen({ screenId: GLOBAL_SCREEN_ID });
76
78
  },
77
79
  });
78
80
 
package/index.server.ts CHANGED
@@ -20,10 +20,9 @@ import {
20
20
  createUnarchiveAgentHandler,
21
21
  } from "./server/handlers.ts";
22
22
  import { agentRowFromHook } from "./server/agents.ts";
23
- import { ingestTimeline, ingestUserMessages } from "./server/ingest.ts";
24
- import { resolveAgentModel } from "./server/resolve-model.ts";
25
23
  import { createRpcCache } from "./server/rpc-cache.ts";
26
24
  import { createUsageStore } from "./server/store.ts";
25
+ import { ingestTurnAfter } from "./server/turn-ingest.ts";
27
26
  import {
28
27
  usageActivityByHourRpc,
29
28
  usageActivityByDayRpc,
@@ -97,17 +96,17 @@ export default function contribute(server: PluginServerContext) {
97
96
  server.handle(usageHostInfoRpc, () => ({ homeDir: homedir() }));
98
97
  server.handle(usageReadSkillRpc, createReadSkillHandler());
99
98
 
100
- const removeCreated = server.on("agent.created", (event, context) => {
99
+ const removeCreated = server.addHook("agent.create.after", async (event, context) => {
101
100
  void background.request(context.paseo);
102
101
  try {
103
102
  store.upsertAgents([agentRowFromHook(event.agent)]);
104
103
  console.log(`[activity] agent.created id=${event.agent.id}`);
105
104
  } catch (error) {
106
- console.error("[activity] failed to ingest agent.created", error);
105
+ console.error("[activity] failed to ingest agent.create.after", error);
107
106
  }
108
107
  });
109
108
 
110
- const removeArchived = server.on("agent.archived", (event, context) => {
109
+ const removeArchived = server.addHook("agent.archive.after", async (event, context) => {
111
110
  void background.request(context.paseo);
112
111
  try {
113
112
  store.upsertAgents([
@@ -118,43 +117,24 @@ export default function contribute(server: PluginServerContext) {
118
117
  ]);
119
118
  console.log(`[activity] agent.archived id=${event.agent.id}`);
120
119
  } catch (error) {
121
- console.error("[activity] failed to ingest agent.archived", error);
120
+ console.error("[activity] failed to ingest agent.archive.after", error);
122
121
  }
123
122
  });
124
123
 
125
- const removeTurnEnded = server.on("agent.turn_ended", (event, context) => {
124
+ const removeTurnEnded = server.addHook("agent.turn.after", async (event, context) => {
126
125
  void background.request(context.paseo);
127
126
  void (async () => {
128
127
  try {
129
- const existing = store.getAgent(event.agent.id);
130
- store.upsertAgents([
131
- agentRowFromHook(event.agent, {
132
- createdAt: existing?.createdAt,
133
- archivedAt: existing?.archivedAt,
134
- }),
135
- ]);
136
- const model = await resolveAgentModel(context.paseo, event.agent.id);
137
- store.upsertUserMessages(
138
- ingestUserMessages(event.timeline, event.agent, { model }),
139
- );
140
- store.pruneReplayDuplicateMessages(event.agent.id);
141
- // event.timeline is the whole history; calls already stored in a terminal
142
- // status cannot change from a live snapshot, so only the rest are upserted.
143
- const settled = store.terminalCallIds(event.agent.id);
144
- const pending = event.timeline.filter(
145
- (item) => item.type !== "tool_call" || !settled.has(item.callId),
146
- );
147
- const rows = ingestTimeline(pending, event.agent, null, {
128
+ const rows = await ingestTurnAfter(store, context.paseo, event.agent, {
148
129
  homeDir: homedir(),
149
130
  });
150
- if (rows.length > 0) {
151
- store.upsertMany(rows);
131
+ if (rows > 0) {
152
132
  console.log(
153
- `[activity] turn_ended agent=${event.agent.id} rows=${rows.length} total=${store.count()}`,
133
+ `[activity] turn.after agent=${event.agent.id} rows=${rows} total=${store.count()}`,
154
134
  );
155
135
  }
156
136
  } catch (error) {
157
- console.error("[activity] failed to ingest agent.turn_ended", error);
137
+ console.error("[activity] failed to ingest agent.turn.after", error);
158
138
  }
159
139
  })();
160
140
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koinzhang/paseo-plugin-activity",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Local usage analytics and workspace agent ops for Paseo: tools, agents, messages, models, Explorer fleet list, and terminals.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -22,10 +22,10 @@
22
22
  ],
23
23
  "scripts": {
24
24
  "typecheck": "tsc --noEmit",
25
- "test": "node --experimental-strip-types --test server/background-sync.test.ts server/handlers-query.test.ts client/attention-agents.test.ts client/latest-user-message.test.ts client/pill-data-cache.test.ts client/hidden-pill-recheck.test.ts client/agent-directory.test.ts client/workspace/list-host-agents.test.ts client/workspace/constants.test.ts client/workspace/filters.test.ts client/workspace/host-archive-sync.test.ts client/rank-color.test.ts client/color-mix.test.ts client/design-tokens.test.ts client/fit-text.test.ts client/provider-filter.test.ts client/range.test.ts client/panel-visibility.test.ts client/workspace/terminal-preview.test.ts shared/activity.test.ts shared/insights.test.ts shared/i18n.test.ts shared/classify.test.ts shared/usage.test.ts shared/format.test.ts shared/explorer-agent-display.test.ts shared/agent-title-search.test.ts shared/list-agent-pages.test.ts shared/agent-page-size.test.ts server/store.test.ts server/ingest.test.ts server/skill-path.test.ts server/mcp-servers.test.ts server/agents.test.ts server/migrate-data.test.ts server/messages.test.ts server/resolve-model.test.ts server/rpc-cache.test.ts"
25
+ "test": "node --experimental-strip-types --test server/background-sync.test.ts server/handlers-query.test.ts client/attention-agents.test.ts client/latest-user-message.test.ts client/pill-data-cache.test.ts client/hidden-pill-recheck.test.ts client/agent-directory.test.ts client/workspace/list-host-agents.test.ts client/workspace/constants.test.ts client/workspace/filters.test.ts client/workspace/host-archive-sync.test.ts client/rank-color.test.ts client/color-mix.test.ts client/design-tokens.test.ts client/fit-text.test.ts client/provider-filter.test.ts client/range.test.ts client/panel-visibility.test.ts client/workspace/terminal-preview.test.ts shared/activity.test.ts shared/insights.test.ts shared/i18n.test.ts shared/classify.test.ts shared/usage.test.ts shared/format.test.ts shared/explorer-agent-display.test.ts shared/agent-title-search.test.ts shared/list-agent-pages.test.ts shared/agent-page-size.test.ts server/store.test.ts server/ingest.test.ts server/skill-path.test.ts server/mcp-servers.test.ts server/agents.test.ts server/migrate-data.test.ts server/messages.test.ts server/resolve-model.test.ts server/turn-ingest.test.ts server/rpc-cache.test.ts"
26
26
  },
27
27
  "devDependencies": {
28
- "@getpaseo/plugin": "0.9.0-beta.2",
28
+ "@getpaseo/plugin": "0.15.1",
29
29
  "@tanstack/react-query": "^5.90.11",
30
30
  "@types/node": "^24.13.5",
31
31
  "@types/react": "~19.2.0",
package/paseo-plugin.json CHANGED
@@ -2,6 +2,6 @@
2
2
  "id": "activity",
3
3
  "description": "Local usage analytics and workspace agent ops: Explorer fleet list, live attention, and terminals",
4
4
  "requirements": {
5
- "paseo": ">=0.9.0"
5
+ "paseo": ">=0.15.0"
6
6
  }
7
7
  }
@@ -1,14 +1,14 @@
1
- import type { PluginHookContext, PluginLifecycleEvents } from "@getpaseo/plugin/server";
1
+ import type { PluginHookContext, PluginHookEvents } from "@getpaseo/plugin/server";
2
2
 
3
3
  /**
4
4
  * Host types re-derived from the plugin SDK.
5
5
  *
6
6
  * Plugins must only import host-provided specifiers (`@getpaseo/plugin*`, zod,
7
- * react, react-native, @tanstack/react-query, node builtins): Paseo compiles
8
- * plugin sources without installing dependencies, so direct `@getpaseo/protocol`
9
- * or `@getpaseo/client` imports fail the runtime-boundary build.
7
+ * react, react-native, @tanstack/react-query, node builtins) or dependencies the
8
+ * plugin installs itself: Paseo compiles plugin sources without installing
9
+ * dependencies, so `@getpaseo/protocol` and `@getpaseo/client` imports fail the
10
+ * runtime-boundary build unless they resolve from the plugin's node_modules.
10
11
  */
11
- export type AgentTimelineItem =
12
- PluginLifecycleEvents["agent.turn_ended"]["timeline"][number];
12
+ export type AgentTimelineItem = PluginHookEvents["agent.turn.after"]["timeline"][number];
13
13
 
14
14
  export type PaseoApi = PluginHookContext["paseo"];
@@ -0,0 +1,180 @@
1
+ import assert from "node:assert/strict";
2
+ import { mkdtempSync, rmSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { test } from "node:test";
6
+ import type { PluginHookAgent, PluginHookContext } from "@getpaseo/plugin/server";
7
+ import type { AgentTimelineItem } from "./host-types.ts";
8
+ import { createUsageStore } from "./store.ts";
9
+ import { TURN_TAIL_LIMIT, ingestTurnAfter, refetchTimelineTail } from "./turn-ingest.ts";
10
+
11
+ const agent: PluginHookAgent = {
12
+ id: "agent-1",
13
+ workspaceId: "ws-1",
14
+ parentAgentId: null,
15
+ provider: "claude",
16
+ cwd: "/repo",
17
+ title: "turn ingest agent",
18
+ };
19
+
20
+ type RefetchOptions = {
21
+ projection?: string;
22
+ direction?: string;
23
+ limit?: number;
24
+ };
25
+
26
+ function fakePaseo(
27
+ entries: Array<{ item: AgentTimelineItem }>,
28
+ options: { error?: string; model?: string | null } = {},
29
+ ) {
30
+ const requests: RefetchOptions[] = [];
31
+ const refetch = async (input: RefetchOptions) => {
32
+ requests.push(input);
33
+ return { entries, error: options.error ?? null };
34
+ };
35
+ const snapshot = options.model ? { model: options.model } : null;
36
+ const paseo = {
37
+ agents: {
38
+ ref: () => ({
39
+ current: () => snapshot,
40
+ refresh: async () => snapshot,
41
+ timeline: { refetch },
42
+ }),
43
+ },
44
+ } as unknown as PluginHookContext["paseo"];
45
+ return { paseo, requests };
46
+ }
47
+
48
+ function withStore(run: (store: ReturnType<typeof createUsageStore>) => Promise<void>) {
49
+ return async () => {
50
+ const dir = mkdtempSync(join(tmpdir(), "activity-turn-ingest-"));
51
+ const store = createUsageStore({ dir, driver: "jsonl" });
52
+ try {
53
+ await run(store);
54
+ } finally {
55
+ store.close();
56
+ rmSync(dir, { recursive: true, force: true });
57
+ }
58
+ };
59
+ }
60
+
61
+ const toolCall = (callId: string, name: string, detail: AgentTimelineItem | undefined): AgentTimelineItem => ({
62
+ type: "tool_call",
63
+ callId,
64
+ name,
65
+ detail: detail as never,
66
+ status: "completed",
67
+ error: null,
68
+ });
69
+
70
+ test("refetchTimelineTail reads canonical recent history", async () => {
71
+ const items: AgentTimelineItem[] = [{ type: "user_message", text: "hi" }];
72
+ const { paseo, requests } = fakePaseo(items.map((item) => ({ item })));
73
+
74
+ const timeline = await refetchTimelineTail(paseo, agent.id);
75
+
76
+ assert.deepEqual(requests, [
77
+ { projection: "canonical", direction: "tail", limit: TURN_TAIL_LIMIT },
78
+ ]);
79
+ assert.deepEqual(timeline, items);
80
+ });
81
+
82
+ test("refetchTimelineTail surfaces daemon errors", async () => {
83
+ const { paseo } = fakePaseo([], { error: "timeline unavailable" });
84
+
85
+ await assert.rejects(() => refetchTimelineTail(paseo, agent.id), /timeline unavailable/);
86
+ });
87
+
88
+ test(
89
+ "ingestTurnAfter records tool calls from the refetched tail",
90
+ withStore(async (store) => {
91
+ const { paseo } = fakePaseo(
92
+ [
93
+ { item: { type: "user_message", messageId: "m-1", text: "hi" } },
94
+ {
95
+ item: {
96
+ type: "tool_call",
97
+ callId: "call-1",
98
+ name: "Skill",
99
+ detail: { type: "plain_text", label: "paseo-plugin" },
100
+ status: "completed",
101
+ error: null,
102
+ },
103
+ },
104
+ {
105
+ item: {
106
+ type: "tool_call",
107
+ callId: "call-2",
108
+ name: "Bash",
109
+ detail: { type: "shell", command: "git status", exitCode: 0 },
110
+ status: "completed",
111
+ error: null,
112
+ },
113
+ },
114
+ ],
115
+ { model: "claude-sonnet-4" },
116
+ );
117
+
118
+ const rows = await ingestTurnAfter(store, paseo, agent, { homeDir: "/home/tester" });
119
+
120
+ assert.equal(rows, 2);
121
+ const stored = store.select({ agentId: agent.id });
122
+ assert.deepEqual(stored.map((row) => row.callId).sort(), ["call-1", "call-2"]);
123
+ assert.equal(store.getAgent(agent.id)?.title, "turn ingest agent");
124
+ assert.equal(store.selectUserMessages({ agentId: agent.id })[0]?.model, "claude-sonnet-4");
125
+ }),
126
+ );
127
+
128
+ test(
129
+ "ingestTurnAfter keeps terminal calls and their stored classification",
130
+ withStore(async (store) => {
131
+ const first = fakePaseo([
132
+ {
133
+ item: {
134
+ type: "tool_call",
135
+ callId: "call-1",
136
+ name: "Skill",
137
+ detail: { type: "plain_text", label: "paseo-plugin" },
138
+ status: "completed",
139
+ error: null,
140
+ },
141
+ },
142
+ ]);
143
+ await ingestTurnAfter(store, first.paseo, agent, { homeDir: "/home/tester" });
144
+ const before = store.getRow(agent.id, "call-1");
145
+ assert.equal(before?.category, "skill");
146
+
147
+ // A later snapshot carries the same terminal call with a different detail.
148
+ const second = fakePaseo([
149
+ {
150
+ item: {
151
+ type: "tool_call",
152
+ callId: "call-1",
153
+ name: "Bash",
154
+ detail: { type: "shell", command: "git status", exitCode: 0 },
155
+ status: "completed",
156
+ error: null,
157
+ },
158
+ },
159
+ ]);
160
+ const rows = await ingestTurnAfter(store, second.paseo, agent, { homeDir: "/home/tester" });
161
+
162
+ assert.equal(rows, 0);
163
+ assert.deepEqual(store.getRow(agent.id, "call-1"), before);
164
+ }),
165
+ );
166
+
167
+ test(
168
+ "ingestTurnAfter preserves the registry creation time across turns",
169
+ withStore(async (store) => {
170
+ const { paseo } = fakePaseo([], {});
171
+ await ingestTurnAfter(store, paseo, agent);
172
+ const createdAt = store.getAgent(agent.id)?.createdAt;
173
+ assert.ok(createdAt);
174
+
175
+ await ingestTurnAfter(store, paseo, { ...agent, title: "renamed" });
176
+
177
+ assert.equal(store.getAgent(agent.id)?.createdAt, createdAt);
178
+ assert.equal(store.getAgent(agent.id)?.title, "renamed");
179
+ }),
180
+ );