paseo-recap 0.0.0-stage → 0.2.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kingsley
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/OVERVIEW.md ADDED
@@ -0,0 +1,41 @@
1
+ Recap writes a short note on where each agent stands, like the session recap in Claude Code. After an agent finishes a turn, a muted line appears in the conversation with the goal, what is done, and the next step. You can glance at any agent and pick up where it left off without scrolling back.
2
+
3
+ Recaps work with every provider Paseo runs, including Claude, Codex, OpenCode, OMP, Pi, and custom agents. The recap line is display only and never becomes part of the agent's context.
4
+
5
+ ## Setup
6
+
7
+ Recaps are written by a command line tool on the host running the Paseo daemon. At least one of `claude`, `codex`, or `opencode` must be on the daemon's `PATH` and logged in. Recaps use that existing login, so they count toward the same plan or API usage.
8
+
9
+ ## What you get
10
+
11
+ - **Recap line.** About 40 words after a completed turn, with a **Next** step when one was agreed or asked.
12
+ - **Recap pill.** A pill above the composer on every agent shows how old the latest recap is. Tap it to read the recap, generate one now, regenerate it, or see the previous four. The `/paseo-recap` command does the same. Claude agents keep their own `/recap` from Claude Code.
13
+ - **Automatic timing.** The first recap comes after your third message, then one after each completed turn once the agent has been quiet for 10 seconds. Replying sooner skips that turn.
14
+
15
+ Recaps are skipped for canceled or failed turns, while a permission request is pending, during context compaction, and for providers at 90% or more of their usage limit. Agents started by other agents are not recapped automatically, but you can generate one from their pill.
16
+
17
+ ## Settings
18
+
19
+ Open **Settings → Plugins → paseo-recap → Recap**.
20
+
21
+ - **Generate recaps automatically.** Turns automatic recaps on or off. The pill and `/paseo-recap` always work.
22
+ - **Every N turns**, **Wait after a turn**, and **Start after** control when automatic recaps run.
23
+ - **Recent exchanges to read.** How many of your messages and the replies a recap reads, from 1 to 100. The default is 8.
24
+ - **Recap subagents** and **Wait for subagents.** Recap agents started by other agents, and hold a parent's recap while its subagents run, for up to 10 minutes.
25
+ - **Recap model.** Recaps pick a model the way Paseo's metadata generation does: the models set in Paseo's metadata generation settings, then Paseo's small models that are installed, such as Claude Haiku. By default an agent whose own provider has one of those small models is recapped by it first. You can also choose any Claude, Codex, or OpenCode model by name. The settings page lists the exact models that will run.
26
+
27
+ ## Data and permissions
28
+
29
+ A recap reads only the text of recent user and assistant messages, plus the agent's title and its current to-do item. It never reads tool output, file contents, or reasoning. That text goes to one model at a time, through its command line tool.
30
+
31
+ With **Same as agent** or **Metadata model**, a model that is unavailable or fails is followed by the next one: the agent's own provider first (for Same as agent, when it has a small model), then the models in Paseo's metadata generation settings, then Paseo's small models that are installed (Claude Haiku, GPT-5.4 mini, MiniMax M3, Nemotron 3 Super). Any of those providers can therefore receive the conversation text. Unlike Paseo's own metadata generation, a recap never falls back to the agent's large model. Choosing Claude, Codex, or OpenCode sends recaps only to that provider, with no fallback.
32
+
33
+ Claude runs with no tools, MCP servers, or user settings. Codex runs in a read-only sandbox with your own Codex configuration, which includes any MCP servers you have set up there. OpenCode runs its read-only plan agent. Each run uses a temporary folder. Claude and Codex runs are not saved as sessions. OpenCode always saves one, and the plugin deletes it right after the run; if that deletion fails, the session stays in OpenCode.
34
+
35
+ Recaps are saved with owner-only permissions in the Paseo data folder, kept for 30 days, and deleted when the agent is archived.
36
+
37
+ ## Limits
38
+
39
+ - Recap lines in the conversation live in the daemon's memory and disappear after a daemon restart. The saved recap and the pill remain.
40
+ - A recap reads recent messages, not the whole session. Decisions made long ago appear only if they come up again or are part of the agent's title.
41
+ - Models sometimes go slightly over the 40 word target.
package/README.md CHANGED
@@ -1,3 +1,141 @@
1
- # Temporary Holding Version
1
+ # paseo-recap
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **Claude Code-style session recaps for every agent in [Paseo](https://github.com/getpaseo/paseo).**
4
+
5
+ When an agent finishes a turn, paseo-recap writes a short "where things stand" note — the goal,
6
+ what is done, and the next step — and shows it right in the conversation. Glance at any agent and
7
+ know where it is, without scrolling back. Works with every provider Paseo runs: Claude, Codex,
8
+ OpenCode, OMP, Pi, and custom agents.
9
+
10
+ ![After an agent fixes a login bug, a muted recap line sums up the work and the next step, with the Recap pill above the composer](docs/images/recap.png)
11
+
12
+ ## Features
13
+
14
+ - **Recap in the conversation.** A muted line after the turn it summarizes, with a **Next:** step,
15
+ like Claude Code's session recap. Display-only: it never enters the agent's context.
16
+ - **Recap pill on every agent.** Shows the latest recap's age; tap it to read, regenerate, or see
17
+ earlier recaps, or to generate one for an agent that has none yet. `/paseo-recap` does the same
18
+ (Claude agents keep Claude Code's own `/recap`).
19
+ - **Picks a model like Paseo does.** Recaps use the same order as Paseo's metadata generation: your
20
+ metadata generation models, then Paseo's small models that are installed, such as Claude Haiku.
21
+ Never the agent's large model. Or choose any Claude, Codex, or OpenCode model; the settings screen
22
+ shows exactly which models will run.
23
+ - **Quiet and cheap.** About 40 words, from recent text only. Skips canceled turns, pending
24
+ permissions, context compaction, and providers near their usage limit. ~3 s and ~$0.002 per recap
25
+ with Claude Haiku.
26
+
27
+ <p align="center"><img src="docs/images/recap-card.png" width="420" alt="The Recap card, opened from the pill, with the summary, the next step, and Regenerate"></p>
28
+
29
+ ## Requirements
30
+
31
+ - Paseo **0.10.3** or later, with plugins enabled (**Settings → Plugins → Enable plugins**, or
32
+ `"pluginsEnabled": true` in `~/.paseo/config.json`)
33
+ - At least one of the `claude`, `codex`, or `opencode` CLIs on the daemon's `PATH`, logged in
34
+
35
+ ## Install
36
+
37
+ Install **Recap** from [paseo.sh/plugins](https://paseo.sh/plugins), or from npm:
38
+
39
+ ```bash
40
+ paseo plugin install npm:paseo-recap
41
+ ```
42
+
43
+ You can also paste `npm:paseo-recap` into **Settings → Plugins → Plugin source**, or install the
44
+ latest source with `paseo plugin install github:kingsleydon/paseo-recap`.
45
+
46
+ Recaps start with the next completed turn of each agent. For an agent that is already idle, tap its
47
+ **Recap** pill and choose **Generate**.
48
+
49
+ ## Settings
50
+
51
+ **Settings → Plugins → paseo-recap → Recap.** Numbers and model names are typed in and validated as
52
+ you type.
53
+
54
+ | Setting | Default | Description |
55
+ |---|---|---|
56
+ | Generate recaps automatically | On | `/paseo-recap` and the pill always work, even when off |
57
+ | Every N turns | 1 | Completed turns between recaps (1–50) |
58
+ | Wait after a turn (seconds) | 10 | Quiet time before a recap; replying sooner skips that turn (0–3600) |
59
+ | Start after (messages) | 3 | Your messages before an agent's first recap, as in Claude Code (1–50) |
60
+ | Recent exchanges to read | 8 | Your messages and the replies a recap reads, within ~8,000 tokens (1–100) |
61
+ | Recap subagents | Off | Also recap agents started by other agents |
62
+ | Wait for subagents | Off | Hold an agent's recap while its subagents run, up to 10 minutes |
63
+ | Recap model | Same as agent | Same as agent, Metadata model, or Claude / Codex / OpenCode with any model id |
64
+
65
+ ## How it works
66
+
67
+ 1. When a turn completes and the agent stays quiet for the wait time, the daemon-side plugin takes
68
+ the recent user and assistant text — never tool output, file contents, or reasoning — and asks a
69
+ local CLI for a structured `{ summary, next_action }` recap.
70
+ 2. The recap is stored under `$PASEO_HOME/plugin-data/paseo-recap/` and appended to the
71
+ conversation as a plugin row. A new turn cancels a pending recap and marks the last one out of
72
+ date.
73
+ 3. CLIs run one-shot in a temporary directory with your existing login. Claude and Codex save no
74
+ session; OpenCode's session is deleted right after the run (logged if that fails).
75
+ At most two run at once; a CLI that is missing, logged out, or rate limited is skipped for ten
76
+ minutes and the next model is tried.
77
+
78
+ | CLI | Invocation |
79
+ |---|---|
80
+ | `claude` | `claude -p --json-schema … --tools "" --strict-mcp-config --setting-sources "" --no-session-persistence`, thinking off |
81
+ | `codex` | `codex exec --ephemeral --sandbox read-only --output-schema … --disable hooks`, low reasoning effort, with your Codex configuration |
82
+ | `opencode` | `opencode run --pure --agent plan --format json`; the session is deleted afterwards |
83
+
84
+ See [docs/design.md](docs/design.md) for the full design, edge cases, and a comparison with Claude
85
+ Code, Codex, and OMP.
86
+
87
+ ## Privacy and security
88
+
89
+ - Recaps send recent conversation text to one model at a time, using that CLI's login. With
90
+ **Same as agent** or **Metadata model**, a model that is unavailable or fails is followed by the
91
+ next: the agent's own provider (when it has a small model), Paseo's metadata generation models,
92
+ then Paseo's installed small models, so any of them can receive that text. A specific provider
93
+ gets recaps only for itself.
94
+ - Claude runs with no tools, MCP servers, or settings. Codex runs in a read-only sandbox with your
95
+ own Codex configuration, including any MCP servers you set up there. OpenCode uses its read-only
96
+ `plan` agent, which rejects permission requests.
97
+ - Recaps are stored with owner-only permissions, kept for 30 days, and deleted when the agent is
98
+ archived. Recap rows in the conversation live in daemon memory and are gone after a restart.
99
+ - Like every Paseo plugin, this is trusted code that runs unsandboxed on the daemon host.
100
+
101
+ ## Development
102
+
103
+ ```bash
104
+ npm install
105
+ npm run typecheck
106
+ npm test
107
+ RECAP_E2E=1 npx vitest run test/generators.real.e2e.test.ts # real CLIs, costs a few cents
108
+ paseo plugin install "$PWD"
109
+ paseo plugin reload paseo-recap # after changes
110
+ paseo plugin logs paseo-recap
111
+ ```
112
+
113
+ | Path | Contents |
114
+ |---|---|
115
+ | `index.server.ts` | Daemon entry: lifecycle hooks, RPCs, timeline rows |
116
+ | `index.client.tsx` | App entry: recap line, pill, settings screen, `/paseo-recap` |
117
+ | `server/scheduler.ts` | Per-agent state machine: when to recap |
118
+ | `server/history.ts`, `server/prompt.ts` | What a recap reads and the prompt |
119
+ | `server/models.ts`, `server/generators.ts`, `server/cli.ts`, `server/process.ts` | Which model runs, queue and fallback, per-CLI arguments, process runner |
120
+ | `server/store.ts`, `server/usage.ts` | Recap storage, usage-limit guard |
121
+ | `client/` | Recap line, pill and card, settings screen |
122
+ | `shared/recap.ts` | Providers, settings schema, recap types, RPC contracts |
123
+
124
+ ## Releasing
125
+
126
+ Releases publish to npm from GitHub Actions with [trusted publishing](https://docs.npmjs.com/trusted-publishers)
127
+ (OIDC), so no npm token is stored anywhere. The publish job runs in the `npm` GitHub environment,
128
+ which only `v*` tags can deploy to, and npm trusts only that environment. Bump `version` in `package.json` in a PR, merge it,
129
+ then tag the merged commit:
130
+
131
+ ```bash
132
+ git tag v0.2.0 && git push origin v0.2.0
133
+ ```
134
+
135
+ [`.github/workflows/publish.yml`](.github/workflows/publish.yml) checks that the tag matches the
136
+ version, runs the type check and tests, and publishes with provenance. Once the paseo.sh listing
137
+ uses the npm package as its source, the registry proposes each new version automatically.
138
+
139
+ ## License
140
+
141
+ [MIT](LICENSE)
@@ -0,0 +1,56 @@
1
+ import { isRecapProvider, RECAP_PROVIDERS, type ModelPlan, type ModelRef, type RecapView } from "../shared/recap";
2
+
3
+ export function relativeTime(iso: string, now: number): string {
4
+ const seconds = Math.max(0, Math.round((now - Date.parse(iso)) / 1000));
5
+ if (!Number.isFinite(seconds) || seconds < 60) return "now";
6
+ const minutes = Math.round(seconds / 60);
7
+ if (minutes < 60) return `${minutes}m`;
8
+ const hours = Math.round(minutes / 60);
9
+ if (hours < 48) return `${hours}h`;
10
+ return `${Math.round(hours / 24)}d`;
11
+ }
12
+
13
+ export interface PillPresentation {
14
+ visible: boolean;
15
+ label: string;
16
+ /** Lucide icon name; ignored while `busy`, when the pill shows a spinner instead. */
17
+ icon: string;
18
+ busy: boolean;
19
+ }
20
+
21
+ export function pillPresentation(view: RecapView | undefined, now: number): PillPresentation {
22
+ if (view?.state === "generating") return { visible: true, label: "Recap…", icon: "ScrollText", busy: true };
23
+ // Shown even before the first recap, so agents that predate the plugin can get one in a tap.
24
+ if (!view?.recap) return { visible: true, label: "Recap", icon: "ScrollText", busy: false };
25
+ return {
26
+ visible: true,
27
+ label: `Recap · ${relativeTime(view.recap.generatedAt, now)}`,
28
+ icon: view.recap.stale ? "History" : "ScrollText",
29
+ busy: false,
30
+ };
31
+ }
32
+
33
+ /** A recap is on its way: worth polling closely so the pill never lingers on stale progress. */
34
+ export function isPending(view: RecapView): boolean {
35
+ return view.state === "waiting" || view.state === "generating";
36
+ }
37
+
38
+ function providerLabel(provider: string): string {
39
+ return isRecapProvider(provider) ? RECAP_PROVIDERS[provider].label : provider;
40
+ }
41
+
42
+ function modelName({ provider, model }: ModelRef): string {
43
+ return `${providerLabel(provider)} ${model ?? "default model"}`;
44
+ }
45
+
46
+ /** Plain-language list of the models a setting resolves to, e.g. "Claude haiku, then Codex gpt-6-luna." */
47
+ export function describePlan(plan: ModelPlan): string {
48
+ const order = plan.fallback.map(modelName).join(", then ");
49
+ if (plan.perProvider.length === 0) {
50
+ return order === "" ? "No supported model. Install and log in to claude, codex, or opencode." : `${order}.`;
51
+ }
52
+ const own = plan.perProvider
53
+ .map((ref) => `${providerLabel(ref.provider)} agents: ${modelName(ref)}.`)
54
+ .join(" ");
55
+ return order === "" ? own : `${own} Other agents, or if that fails: ${order}.`;
56
+ }
@@ -0,0 +1,161 @@
1
+ import type {
2
+ PluginButton,
3
+ PluginButtonIconProps,
4
+ PluginButtonRegistration,
5
+ PluginClientContext,
6
+ } from "@getpaseo/plugin/client";
7
+ import { ActivityIndicator } from "react-native";
8
+ import { recapListRpc, type RecapView } from "../shared/recap";
9
+ import { isPending, pillPresentation, type PillPresentation } from "./format";
10
+ import { makeRecapPopover } from "./recap-card";
11
+
12
+ const TICK_MS = 2_000;
13
+ const IDLE_POLL_MS = 30_000;
14
+ /** After agent activity, poll every tick: a recap lands a few seconds after the idle delay. */
15
+ const ACTIVE_WINDOW_MS = 30_000;
16
+ const UPDATE_DEBOUNCE_MS = 1_000;
17
+
18
+ /** Sized to the icon slot, as Paseo's own pills draw their loading spinner. */
19
+ function SpinnerIcon({ size, color }: PluginButtonIconProps) {
20
+ return <ActivityIndicator size={size} color={color} />;
21
+ }
22
+
23
+ function pillButton({
24
+ visible,
25
+ label,
26
+ icon,
27
+ busy,
28
+ }: PillPresentation): Pick<PluginButton, "visible" | "label" | "icon"> {
29
+ return { visible, label, icon: busy ? SpinnerIcon : icon };
30
+ }
31
+
32
+ /**
33
+ * Keeps one composer pill per agent in sync with daemon recaps. Recaps finish after an idle delay
34
+ * without any agent update, so the list is also polled, faster right after agent activity.
35
+ */
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
+ }
86
+
87
+ async refresh(): Promise<void> {
88
+ if (this.#refreshing || this.#lifetime.signal.aborted) return;
89
+ this.#refreshing = true;
90
+ this.#lastRefreshAt = Date.now();
91
+ try {
92
+ const { recaps } = await this.#client.rpc(recapListRpc, {});
93
+ this.#views = new Map(recaps.map((view) => [view.agentId, view]));
94
+ this.#render();
95
+ } catch (error) {
96
+ console.error("[paseo-recap] failed to load recaps", error);
97
+ } finally {
98
+ this.#refreshing = false;
99
+ }
100
+ }
101
+
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();
107
+ try {
108
+ return await request;
109
+ } finally {
110
+ void this.refresh();
111
+ }
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({
125
+ id: "recap",
126
+ workspaceId: agent.workspaceId,
127
+ agentId: agent.id,
128
+ button: {
129
+ title: "Session recap",
130
+ ...pillButton(pillPresentation(this.#views.get(agent.id), Date.now())),
131
+ behavior: { kind: "popover", Content: this.#popover },
132
+ },
133
+ });
134
+ this.#pills.set(agent.id, registration);
135
+ }
136
+
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
+ }
143
+
144
+ #scheduleRefresh(): void {
145
+ if (this.#debounce) clearTimeout(this.#debounce);
146
+ this.#debounce = setTimeout(() => {
147
+ this.#debounce = null;
148
+ void this.refresh();
149
+ }, UPDATE_DEBOUNCE_MS);
150
+ }
151
+
152
+ #remove(agentId: string): void {
153
+ this.#pills.get(agentId)?.remove();
154
+ this.#pills.delete(agentId);
155
+ }
156
+
157
+ #removeAll(): void {
158
+ for (const pill of this.#pills.values()) pill.remove();
159
+ this.#pills.clear();
160
+ }
161
+ }
@@ -0,0 +1,218 @@
1
+ import type { PluginButtonContentProps, PluginHostProps } from "@getpaseo/plugin/client";
2
+ import { useRpc } from "@getpaseo/plugin/client";
3
+ import { Icon } from "@getpaseo/plugin/client/react-native";
4
+ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
5
+ import { useMemo, useState, type ReactNode } from "react";
6
+ import { ActivityIndicator, Pressable, Text, View } from "react-native";
7
+ import { recapGetRpc, recapRegenerateRpc, type RecapView, type StoredRecap } from "../shared/recap";
8
+ import { relativeTime } from "./format";
9
+
10
+ const GENERATING_POLL_MS = 2_000;
11
+
12
+ export function recapQueryKey(agentId: string) {
13
+ return ["paseo-recap", "recap", agentId] as const;
14
+ }
15
+
16
+ type Theme = PluginHostProps["theme"];
17
+
18
+ // Sizes follow Paseo's own controls: 15 px content text, 14 px secondary text, 32 px small and
19
+ // 28 px extra-small buttons.
20
+ function useRecapStyles(theme: Theme) {
21
+ return useMemo(() => {
22
+ const button = {
23
+ minHeight: 32,
24
+ paddingHorizontal: 12,
25
+ borderRadius: 12,
26
+ flexDirection: "row" as const,
27
+ alignItems: "center" as const,
28
+ justifyContent: "center" as const,
29
+ gap: 8,
30
+ };
31
+ return {
32
+ summary: { color: theme.colors.foreground, fontSize: 15, lineHeight: 21 },
33
+ summaryMuted: { color: theme.colors.foregroundMuted, fontSize: 14, lineHeight: 20 },
34
+ next: { color: theme.colors.foreground, fontSize: 14, lineHeight: 20 },
35
+ nextLabel: { color: theme.colors.foregroundMuted },
36
+ meta: { color: theme.colors.foregroundMuted, fontSize: 12 },
37
+ error: { color: theme.colors.statusDanger, fontSize: 14, lineHeight: 20 },
38
+ row: { flexDirection: "row" as const, alignItems: "center" as const, gap: 8 },
39
+ button: { ...button, backgroundColor: theme.colors.surface2 },
40
+ ghostButton: { ...button, minHeight: 28, gap: 6, backgroundColor: "transparent" },
41
+ metaRow: { flexDirection: "row" as const, alignItems: "center" as const, gap: 8 },
42
+ metaText: { flex: 1, color: theme.colors.foregroundMuted, fontSize: 12 },
43
+ // Ghost buttons have no background; outdent them so their labels line up with the card edge.
44
+ actions: { flexDirection: "row" as const, alignItems: "center" as const, marginRight: -button.paddingHorizontal },
45
+ buttonText: { color: theme.colors.foreground, fontSize: 14 },
46
+ ghostButtonText: { color: theme.colors.foregroundMuted, fontSize: 12 },
47
+ pressed: { opacity: 0.85 },
48
+ disabled: { opacity: 0.5 },
49
+ earlier: { gap: 12, paddingTop: 12, borderTopWidth: 1, borderTopColor: theme.colors.border },
50
+ };
51
+ }, [theme]);
52
+ }
53
+
54
+ export function recapAge(recap: StoredRecap, now: number): string {
55
+ const age = relativeTime(recap.generatedAt, now);
56
+ return age === "now" ? "Just now" : `${age} ago`;
57
+ }
58
+
59
+ /** Summary, next action, and metadata of one recap. Plain text only: model output is untrusted. */
60
+ export function RecapBody({
61
+ theme,
62
+ recap,
63
+ muted = false,
64
+ actions = null,
65
+ }: {
66
+ theme: Theme;
67
+ recap: StoredRecap;
68
+ muted?: boolean;
69
+ /** Quiet buttons shown at the end of the metadata line. */
70
+ actions?: ReactNode;
71
+ }) {
72
+ const styles = useRecapStyles(theme);
73
+ return (
74
+ <>
75
+ <Text style={muted ? styles.summaryMuted : styles.summary} selectable>
76
+ {recap.summary}
77
+ </Text>
78
+ {recap.nextAction && !muted ? (
79
+ <Text style={styles.next} selectable>
80
+ <Text style={styles.nextLabel}>Next: </Text>
81
+ {recap.nextAction}
82
+ </Text>
83
+ ) : null}
84
+ <View style={styles.metaRow}>
85
+ <Text style={styles.metaText}>
86
+ {recap.stale && !muted ? "Out of date · " : ""}
87
+ {recapAge(recap, Date.now())}
88
+ {` · ${recap.generator.model ?? recap.generator.provider}`}
89
+ {recap.trigger === "manual" ? " · manual" : ""}
90
+ </Text>
91
+ {actions}
92
+ </View>
93
+ </>
94
+ );
95
+ }
96
+
97
+ /** What the card needs from the pills that open it. */
98
+ export interface RecapPopoverSource {
99
+ /** The pill's latest view of an agent's recap, so the card opens at its full size. */
100
+ cachedView(agentId: string): RecapView | undefined;
101
+ /** Reports a manual recap request, so the pill can show its progress. */
102
+ track<T>(agentId: string, request: Promise<T>): Promise<T>;
103
+ }
104
+
105
+ export function makeRecapPopover(source: RecapPopoverSource) {
106
+ return function RecapPopover(props: PluginButtonContentProps) {
107
+ if (props.context !== "agent") return null;
108
+ return <RecapCard {...props} agentId={props.agentId} source={source} />;
109
+ };
110
+ }
111
+
112
+ function RecapCard({
113
+ theme,
114
+ layout,
115
+ agentId,
116
+ source,
117
+ }: PluginButtonContentProps & { agentId: string; source: RecapPopoverSource }) {
118
+ const getRecap = useRpc(recapGetRpc);
119
+ const regenerateRecap = useRpc(recapRegenerateRpc);
120
+ const queryClient = useQueryClient();
121
+ const [showEarlier, setShowEarlier] = useState(false);
122
+ const styles = useRecapStyles(theme);
123
+ const query = useQuery({
124
+ queryKey: recapQueryKey(agentId),
125
+ queryFn: () => getRecap({ agentId }),
126
+ // Paseo sizes a popover to its first render; starting from the pill's data avoids opening at
127
+ // the size of a loading spinner and clipping the recap that arrives a moment later.
128
+ initialData: () => source.cachedView(agentId),
129
+ refetchInterval: (current) =>
130
+ current.state.data?.state === "generating" ? GENERATING_POLL_MS : false,
131
+ });
132
+ const regenerate = useMutation({
133
+ // The RPC resolves only after generation finishes; `regenerate.isPending` shows progress here.
134
+ mutationFn: () => source.track(agentId, regenerateRecap({ agentId })),
135
+ onSettled: (view) => {
136
+ if (view) queryClient.setQueryData(recapQueryKey(agentId), view);
137
+ else void query.refetch();
138
+ },
139
+ });
140
+
141
+ const view = query.data;
142
+ const recap = view?.recap ?? null;
143
+ const previous = view?.previous ?? [];
144
+ const generating = view?.state === "generating" || regenerate.isPending;
145
+ const error = query.error || regenerate.error ? "Could not load the recap." : (view?.error ?? null);
146
+
147
+ const generateButton = (
148
+ <Pressable
149
+ accessibilityRole="button"
150
+ accessibilityLabel={recap ? "Regenerate recap" : "Generate recap"}
151
+ accessibilityState={{ disabled: generating, busy: generating }}
152
+ disabled={generating}
153
+ onPress={() => regenerate.mutate()}
154
+ style={({ pressed }) => [
155
+ recap ? styles.ghostButton : styles.button,
156
+ pressed && styles.pressed,
157
+ generating && styles.disabled,
158
+ ]}
159
+ >
160
+ {generating ? (
161
+ <ActivityIndicator size={recap ? 12 : "small"} color={theme.colors.foregroundMuted} />
162
+ ) : recap ? (
163
+ <Icon name="RefreshCw" size={12} color={theme.colors.foregroundMuted} />
164
+ ) : null}
165
+ <Text style={recap ? styles.ghostButtonText : styles.buttonText}>
166
+ {generating ? "Generating…" : recap ? "Regenerate" : "Generate"}
167
+ </Text>
168
+ </Pressable>
169
+ );
170
+ const earlierButton =
171
+ previous.length > 0 ? (
172
+ <Pressable
173
+ accessibilityRole="button"
174
+ accessibilityState={{ expanded: showEarlier }}
175
+ onPress={() => setShowEarlier((value) => !value)}
176
+ style={({ pressed }) => [styles.ghostButton, pressed && styles.pressed]}
177
+ >
178
+ <Text style={styles.ghostButtonText}>{showEarlier ? "Hide earlier" : `Earlier (${previous.length})`}</Text>
179
+ </Pressable>
180
+ ) : null;
181
+
182
+ return (
183
+ <View style={{ gap: 12, maxWidth: layout.compact ? undefined : 400 }}>
184
+ {query.isPending ? <ActivityIndicator color={theme.colors.foregroundMuted} /> : null}
185
+ {recap ? (
186
+ // With a recap shown, regenerating is secondary: quiet buttons on the metadata line.
187
+ <RecapBody
188
+ theme={theme}
189
+ recap={recap}
190
+ actions={
191
+ <View style={styles.actions}>
192
+ {generateButton}
193
+ {earlierButton}
194
+ </View>
195
+ }
196
+ />
197
+ ) : (
198
+ // Without one, Generate is the card's main action.
199
+ <>
200
+ {!query.isPending && !generating ? (
201
+ <Text style={styles.meta}>No recap yet. One appears after this agent's next turn, or generate it now.</Text>
202
+ ) : null}
203
+ <View style={styles.row}>{generateButton}</View>
204
+ </>
205
+ )}
206
+ {error ? <Text style={styles.error}>{error}</Text> : null}
207
+ {showEarlier ? (
208
+ <View style={styles.earlier}>
209
+ {previous.map((item) => (
210
+ <View key={item.generatedAt} style={{ gap: 4 }}>
211
+ <RecapBody theme={theme} recap={item} muted />
212
+ </View>
213
+ ))}
214
+ </View>
215
+ ) : null}
216
+ </View>
217
+ );
218
+ }