paseo-recap 0.2.2 → 0.2.3

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/client/pills.tsx CHANGED
@@ -29,133 +29,136 @@ function pillButton({
29
29
  return { visible, label, icon: busy ? SpinnerIcon : icon };
30
30
  }
31
31
 
32
+ export interface RecapPills {
33
+ start(): void;
34
+ stop(): void;
35
+ refresh(): Promise<void>;
36
+ /** Shows progress on an agent's pill while a manual recap request runs, then its result. */
37
+ track<T>(agentId: string, request: Promise<T>): Promise<T>;
38
+ }
39
+
32
40
  /**
33
41
  * Keeps one composer pill per agent in sync with daemon recaps. Recaps finish after an idle delay
34
42
  * without any agent update, so the list is also polled, faster right after agent activity.
43
+ *
44
+ * A factory rather than a class: plugin client bundles reach Hermes (iOS, Android) without Metro's
45
+ * transforms, and Hermes rejects class syntax (getpaseo/paseo#5783).
35
46
  */
36
- export class RecapPills {
37
- readonly #client: PluginClientContext;
38
- readonly #pills = new Map<string, PluginButtonRegistration>();
39
- readonly #lifetime = new AbortController();
40
- #views = new Map<string, RecapView>();
41
- #debounce: ReturnType<typeof setTimeout> | null = null;
42
- #poll: ReturnType<typeof setInterval> | null = null;
43
- #refreshing = false;
44
- #lastRefreshAt = 0;
45
- #activeUntil = 0;
46
- readonly #popover = makeRecapPopover({
47
- cachedView: (agentId) => this.#views.get(agentId),
48
- track: (agentId, request) => this.track(agentId, request),
49
- });
50
-
51
- constructor(client: PluginClientContext) {
52
- this.#client = client;
53
- }
54
-
55
- start(): void {
56
- this.#client.paseo.agents
57
- .list({ subscribe: {}, signal: this.#lifetime.signal })
58
- .then(({ subscription }) => {
59
- subscription.subscribe({
60
- snapshot: ({ entries }) => {
61
- this.#removeAll();
62
- for (const { agent } of entries) this.#register(agent);
63
- this.#scheduleRefresh();
64
- },
65
- update: (message) => {
66
- if (message.type !== "agent_update") return;
67
- const update = message.payload;
68
- if (update.kind === "remove") this.#remove(update.agentId);
69
- else if (!this.#pills.has(update.agent.id)) this.#register(update.agent);
70
- this.#activeUntil = Date.now() + ACTIVE_WINDOW_MS;
71
- this.#scheduleRefresh();
72
- },
73
- });
74
- })
75
- .catch((error: unknown) => {
76
- if (!this.#lifetime.signal.aborted) console.error("[paseo-recap] agent observation failed", error);
77
- });
78
- this.#poll = setInterval(() => {
79
- const now = Date.now();
80
- const pending = [...this.#views.values()].some(isPending);
81
- if (pending || now < this.#activeUntil || now - this.#lastRefreshAt >= IDLE_POLL_MS) {
82
- void this.refresh();
83
- }
84
- }, TICK_MS);
85
- }
47
+ export function createRecapPills(client: PluginClientContext): RecapPills {
48
+ const pills = new Map<string, PluginButtonRegistration>();
49
+ const lifetime = new AbortController();
50
+ let views = new Map<string, RecapView>();
51
+ let debounce: ReturnType<typeof setTimeout> | null = null;
52
+ let poll: ReturnType<typeof setInterval> | null = null;
53
+ let refreshing = false;
54
+ let lastRefreshAt = 0;
55
+ let activeUntil = 0;
86
56
 
87
- async refresh(): Promise<void> {
88
- if (this.#refreshing || this.#lifetime.signal.aborted) return;
89
- this.#refreshing = true;
90
- this.#lastRefreshAt = Date.now();
57
+ const render = (): void => {
58
+ const now = Date.now();
59
+ for (const [agentId, pill] of pills) {
60
+ pill.update(pillButton(pillPresentation(views.get(agentId), now)));
61
+ }
62
+ };
63
+
64
+ const refresh = async (): Promise<void> => {
65
+ if (refreshing || lifetime.signal.aborted) return;
66
+ refreshing = true;
67
+ lastRefreshAt = Date.now();
91
68
  try {
92
- const { recaps } = await this.#client.rpc(recapListRpc, {});
93
- this.#views = new Map(recaps.map((view) => [view.agentId, view]));
94
- this.#render();
69
+ const { recaps } = await client.rpc(recapListRpc, {});
70
+ views = new Map(recaps.map((view) => [view.agentId, view]));
71
+ render();
95
72
  } catch (error) {
96
73
  console.error("[paseo-recap] failed to load recaps", error);
97
74
  } finally {
98
- this.#refreshing = false;
75
+ refreshing = false;
99
76
  }
100
- }
77
+ };
101
78
 
102
- /** Shows progress on an agent's pill while a manual recap request runs, then its result. */
103
- async track<T>(agentId: string, request: Promise<T>): Promise<T> {
104
- const view = this.#views.get(agentId) ?? { agentId, recap: null, previous: [], error: null, state: "idle" };
105
- this.#views.set(agentId, { ...view, state: "generating", error: null });
106
- this.#render();
79
+ const track = async <T,>(agentId: string, request: Promise<T>): Promise<T> => {
80
+ const view = views.get(agentId) ?? { agentId, recap: null, previous: [], error: null, state: "idle" };
81
+ views.set(agentId, { ...view, state: "generating", error: null });
82
+ render();
107
83
  try {
108
84
  return await request;
109
85
  } finally {
110
- void this.refresh();
86
+ void refresh();
111
87
  }
112
- }
113
-
114
- stop(): void {
115
- this.#lifetime.abort();
116
- if (this.#debounce) clearTimeout(this.#debounce);
117
- if (this.#poll) clearInterval(this.#poll);
118
- this.#removeAll();
119
- }
120
-
121
- #register(agent: { id: string; workspaceId?: string | null }): void {
122
- if (this.#lifetime.signal.aborted || !agent.workspaceId) return;
123
- this.#pills.get(agent.id)?.remove();
124
- const registration = this.#client.addComposerPill({
88
+ };
89
+
90
+ const popover = makeRecapPopover({ cachedView: (agentId) => views.get(agentId), track });
91
+
92
+ const register = (agent: { id: string; workspaceId?: string | null }): void => {
93
+ if (lifetime.signal.aborted || !agent.workspaceId) return;
94
+ pills.get(agent.id)?.remove();
95
+ const registration = client.addComposerPill({
125
96
  id: "recap",
126
97
  workspaceId: agent.workspaceId,
127
98
  agentId: agent.id,
128
99
  button: {
129
100
  title: "Session recap",
130
- ...pillButton(pillPresentation(this.#views.get(agent.id), Date.now())),
131
- behavior: { kind: "popover", Content: this.#popover },
101
+ ...pillButton(pillPresentation(views.get(agent.id), Date.now())),
102
+ behavior: { kind: "popover", Content: popover },
132
103
  },
133
104
  });
134
- this.#pills.set(agent.id, registration);
135
- }
105
+ pills.set(agent.id, registration);
106
+ };
136
107
 
137
- #render(): void {
138
- const now = Date.now();
139
- for (const [agentId, pill] of this.#pills) {
140
- pill.update(pillButton(pillPresentation(this.#views.get(agentId), now)));
141
- }
142
- }
108
+ const remove = (agentId: string): void => {
109
+ pills.get(agentId)?.remove();
110
+ pills.delete(agentId);
111
+ };
112
+
113
+ const removeAll = (): void => {
114
+ for (const pill of pills.values()) pill.remove();
115
+ pills.clear();
116
+ };
143
117
 
144
- #scheduleRefresh(): void {
145
- if (this.#debounce) clearTimeout(this.#debounce);
146
- this.#debounce = setTimeout(() => {
147
- this.#debounce = null;
148
- void this.refresh();
118
+ const scheduleRefresh = (): void => {
119
+ if (debounce) clearTimeout(debounce);
120
+ debounce = setTimeout(() => {
121
+ debounce = null;
122
+ void refresh();
149
123
  }, UPDATE_DEBOUNCE_MS);
150
- }
124
+ };
125
+
126
+ const start = (): void => {
127
+ client.paseo.agents
128
+ .list({ subscribe: {}, signal: lifetime.signal })
129
+ .then(({ subscription }) => {
130
+ subscription.subscribe({
131
+ snapshot: ({ entries }) => {
132
+ removeAll();
133
+ for (const { agent } of entries) register(agent);
134
+ scheduleRefresh();
135
+ },
136
+ update: (message) => {
137
+ if (message.type !== "agent_update") return;
138
+ const update = message.payload;
139
+ if (update.kind === "remove") remove(update.agentId);
140
+ else if (!pills.has(update.agent.id)) register(update.agent);
141
+ activeUntil = Date.now() + ACTIVE_WINDOW_MS;
142
+ scheduleRefresh();
143
+ },
144
+ });
145
+ })
146
+ .catch((error: unknown) => {
147
+ if (!lifetime.signal.aborted) console.error("[paseo-recap] agent observation failed", error);
148
+ });
149
+ poll = setInterval(() => {
150
+ const now = Date.now();
151
+ const pending = [...views.values()].some(isPending);
152
+ if (pending || now < activeUntil || now - lastRefreshAt >= IDLE_POLL_MS) void refresh();
153
+ }, TICK_MS);
154
+ };
151
155
 
152
- #remove(agentId: string): void {
153
- this.#pills.get(agentId)?.remove();
154
- this.#pills.delete(agentId);
155
- }
156
+ const stop = (): void => {
157
+ lifetime.abort();
158
+ if (debounce) clearTimeout(debounce);
159
+ if (poll) clearInterval(poll);
160
+ removeAll();
161
+ };
156
162
 
157
- #removeAll(): void {
158
- for (const pill of this.#pills.values()) pill.remove();
159
- this.#pills.clear();
160
- }
163
+ return { start, stop, refresh, track };
161
164
  }
package/index.client.tsx CHANGED
@@ -1,11 +1,11 @@
1
1
  import type { PluginClientContext } from "@getpaseo/plugin/client";
2
2
  import { RecapLine } from "./client/recap-line";
3
- import { RecapPills } from "./client/pills";
3
+ import { createRecapPills } from "./client/pills";
4
4
  import { RecapSettingsScreen } from "./client/settings-screen";
5
5
  import { RECAP_TIMELINE_KIND, RecapTimelineDataSchema, recapRegenerateRpc } from "./shared/recap";
6
6
 
7
7
  export default function contribute(client: PluginClientContext) {
8
- const pills = new RecapPills(client);
8
+ const pills = createRecapPills(client);
9
9
  pills.start();
10
10
 
11
11
  const removeTimelineRenderer = client.addTimelineRenderer({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paseo-recap",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Writes a short recap of each agent's goal, progress, and next step after every turn, like Claude Code's session recap.",
5
5
  "license": "MIT",
6
6
  "files": [