@koinzhang/paseo-plugin-activity 0.3.0 → 0.5.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/CHANGELOG.md +42 -2
- package/README.md +7 -6
- package/client/agent-directory.test.ts +191 -0
- package/client/agent-directory.ts +150 -0
- package/client/attention-agents.test.ts +94 -0
- package/client/attention-agents.ts +67 -0
- package/client/attention-pill.tsx +166 -0
- package/client/attention-popover.tsx +161 -0
- package/client/attention-status-store.ts +47 -0
- package/client/global-surface.tsx +3 -1
- package/client/latest-user-message.test.ts +34 -0
- package/client/latest-user-message.ts +96 -0
- package/client/open-agent.ts +32 -0
- package/client/panel.tsx +2 -0
- package/client/pill-directory.ts +20 -68
- package/client/use-agent-turn-end.ts +23 -3
- package/client/use-latest-user-message.ts +15 -0
- package/client/use-workspace-agent-statuses.ts +23 -0
- package/client/workspace/agent-row.tsx +49 -22
- package/client/workspace/agents-section.tsx +90 -22
- package/client/workspace/constants.test.ts +66 -0
- package/client/workspace/constants.ts +39 -1
- package/client/workspace/filters.test.ts +59 -0
- package/client/workspace/filters.ts +9 -0
- package/client/workspace/host-archive-sync.test.ts +46 -0
- package/client/workspace/host-archive-sync.ts +15 -0
- package/client/workspace/list-host-agents.test.ts +44 -38
- package/client/workspace/list-host-agents.ts +60 -57
- package/client/workspace/panel.tsx +43 -26
- package/index.client.tsx +7 -1
- package/package.json +3 -3
- package/paseo-plugin.json +1 -1
- package/shared/explorer-agent-display.ts +1 -1
- package/shared/usage.test.ts +8 -2
- package/shared/usage.ts +7 -0
- package/client/pill-directory.test.ts +0 -92
- package/client/workspace/status-cache.test.ts +0 -62
- package/client/workspace/status-cache.ts +0 -19
package/CHANGELOG.md
CHANGED
|
@@ -5,7 +5,45 @@ All notable changes to `@koinzhang/paseo-plugin-activity` are documented in this
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
-
## [
|
|
8
|
+
## [0.5.0] - 2026-09-20
|
|
9
|
+
|
|
10
|
+
Requires Paseo **>= 0.9.0-beta.2**.
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Pin the plugin SDK to `0.9.0-beta.2` and use independent, API-owned directory observations, shared within each entry/surface API.
|
|
15
|
+
- Reconcile all pages on bootstrap/reconnect, replay concurrent updates, retain 15s polling, and release observations after the last consumer unmounts.
|
|
16
|
+
- Handle timeline subscription restoration/errors and use SDK cleanup with release error handling.
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- Restore real-time workspace and attention updates: beta.2 API listeners do not receive the app's directory observation.
|
|
21
|
+
- Read lifecycle and archive state from explicit directory fields. Missing host UI snapshots, directory removals, and Closed no longer synthesize an archive or permanently lock lifecycle state.
|
|
22
|
+
- Reflect host archive/unarchive immediately in workspace rows, preserving usage metrics even if an older RPC finishes later.
|
|
23
|
+
- Remove the host-cache-to-query effect loop that caused React maximum update depth errors; retain stable workspace query keys.
|
|
24
|
+
|
|
25
|
+
## [0.4.0] - 2026-09-20
|
|
26
|
+
|
|
27
|
+
Last release that supports Paseo **0.8.0**. Later versions require Paseo **>= 0.9.0**.
|
|
28
|
+
|
|
29
|
+
### Added
|
|
30
|
+
|
|
31
|
+
- Composer **Needs attention** pill (same workspace): one shared entry for other agents with finished / permission / error attention; click always opens the same popover list (Explorer-style rows); icon tint follows aggregate priority.
|
|
32
|
+
- Explorer Agents rows show the direct subagent count at the bottom-right of the bot icon when the local registry has children (`parentAgentId`); the count follows the Agents Status filter (Active / Archived / both). Host list also resolves the legacy `paseo.parent-agent-id` label. The running spinner keeps priority on that corner.
|
|
33
|
+
- Explorer Agents **Show → Prompt**: optional row meta for the latest user message preview (host timeline; same path as the attention pill).
|
|
34
|
+
|
|
35
|
+
### Changed
|
|
36
|
+
|
|
37
|
+
- Attention pill no longer direct-jumps when only one peer needs attention — always popover for finished / permission / error.
|
|
38
|
+
- Attention popover row meta shows the latest user message preview (host timeline tail; not stored in usage.db) instead of finished / needs-attention labels.
|
|
39
|
+
- Attention pill icon switches with attention kind: `Bell` for permission, `CircleAlert` for error, `CircleCheck` for finished (priority permission > error > finished when mixed).
|
|
40
|
+
|
|
41
|
+
### Fixed
|
|
42
|
+
|
|
43
|
+
- Explorer Agents lifecycle **Closed** updates near-real-time via host `useAgent` snapshots (no `list({ subscribe })`); directory `remove` keeps the row as Closed instead of dropping status; missing `workspaceId` on pushes still merges when the agent is already tracked.
|
|
44
|
+
- Attention pill icon/list now follow the same `agents.subscribe` in-memory store as visibility (no separate 15s react-query path), so tint updates with pushes; partial directory pushes keep prior permission/attention fields; background polls no longer disable the pill.
|
|
45
|
+
- Attention pill row open uses the existing `navigation.openAgent` bridge (registered by Agent / Workspace / Global panels); no `openPanel("usage")` fallback. Preview fetch tries projected then canonical timeline tail.
|
|
46
|
+
- Attention pill visibility is synced from the contribute layer (directory + subscribe + 15s poll). Starting at `visible: false` previously unmounted the icon, so the show effect never ran and the pill stayed hidden even when peers needed attention.
|
|
9
47
|
|
|
10
48
|
## [0.3.0] - 2026-09-19
|
|
11
49
|
|
|
@@ -75,7 +113,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
75
113
|
- Command Center entries: open panels and export a markdown usage report.
|
|
76
114
|
- Plugin renamed from `tool-usage` to `activity`, migrating the old data directory automatically.
|
|
77
115
|
|
|
78
|
-
[Unreleased]: https://github.com/koinzhang/paseo-plugins/compare/activity-v0.
|
|
116
|
+
[Unreleased]: https://github.com/koinzhang/paseo-plugins/compare/activity-v0.5.0...HEAD
|
|
117
|
+
[0.5.0]: https://github.com/koinzhang/paseo-plugins/releases/tag/activity-v0.5.0
|
|
118
|
+
[0.4.0]: https://github.com/koinzhang/paseo-plugins/releases/tag/activity-v0.4.0
|
|
79
119
|
[0.3.0]: https://github.com/koinzhang/paseo-plugins/releases/tag/activity-v0.3.0
|
|
80
120
|
[0.2.0]: https://github.com/koinzhang/paseo-plugins/releases/tag/activity-v0.2.0
|
|
81
121
|
[0.1.0]: https://github.com/koinzhang/paseo-plugins/releases/tag/activity-v0.1.0
|
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ It still answers “how am I using Paseo” (tools, messages, models, habits). W
|
|
|
8
8
|
|---|---|
|
|
9
9
|
| **Global** | Cross-workspace habits: heatmap, provider filter, insights, most-used skills / MCP / models |
|
|
10
10
|
| **Workspace** | Per-workspace agent fleet: ranked list + display prefs + archive; live status (permission / finished / error / running); open Terminals; shell / file / messages KPIs; times via shared `FormattedTime` |
|
|
11
|
-
| **Agent** | Current session: dense tool KPIs, Skills / MCP header toggle, SKILL.md reader, composer pill;
|
|
11
|
+
| **Agent** | Current session: dense tool KPIs, Skills / MCP header toggle, SKILL.md reader, composer Activity pill; **Needs attention** pill jumps to other same-workspace finished/permission/error sessions |
|
|
12
12
|
|
|
13
13
|
Architecture notes: [docs/architecture.md](./docs/architecture.md).
|
|
14
14
|
|
|
@@ -26,9 +26,9 @@ Ingests every agent's Paseo timeline into a local SQLite database. Queries read
|
|
|
26
26
|
## Where it shows up
|
|
27
27
|
|
|
28
28
|
- **Sidebar Activity** — global view by provider (heatmap, KPIs, insights, most used)
|
|
29
|
-
- **Explorer → Activity** — workspace agents as a management list (search / sort / group / status / lifecycle / archive), live attention (permission badge, status colors, running spinner; directory
|
|
29
|
+
- **Explorer → Activity** — workspace agents as a management list (search / sort / group / status / lifecycle / archive), live attention (permission badge, status colors, running spinner; API-owned directory observation + explicit lifecycle/archive fields + 15s reconciliation), open Terminals (list / preview / close), plus workspace KPIs and top skills / MCP (toggle hidden when only one kind has data); usage queries get a best-effort refresh hint when agents leave running
|
|
30
30
|
- **Agent workspace panel** — per-agent tool detail (dense KPI including messages / Skills / MCP toggle / SKILL.md); refreshes on timeline turn terminal events
|
|
31
|
-
- **Composer
|
|
31
|
+
- **Composer pills** — Activity: current agent's skill / MCP summary (hidden when empty); **Needs attention**: other same-workspace agents with finished / permission / error (hidden when none; click opens shared list)
|
|
32
32
|
- **Command Center** — Activity · Workspace Activity · Agent Activity
|
|
33
33
|
|
|
34
34
|
## Data
|
|
@@ -37,7 +37,7 @@ Everything lives on the daemon machine in `~/.paseo/plugin-data/activity/` (SQLi
|
|
|
37
37
|
|
|
38
38
|
## Install
|
|
39
39
|
|
|
40
|
-
Requires Paseo
|
|
40
|
+
Requires Paseo **>= 0.9.0-beta.2** (current package targets **0.9.0-beta.2**). **0.4.0** is the last release that supports Paseo 0.8.0.
|
|
41
41
|
|
|
42
42
|
From Git (Paseo 0.8 and later):
|
|
43
43
|
|
|
@@ -45,10 +45,11 @@ From Git (Paseo 0.8 and later):
|
|
|
45
45
|
paseo plugin add koinzhang/paseo-plugins --path activity
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
From npm (Paseo 0.9 and later; this is the source paseo.cafe hands to Paseo 0.9+):
|
|
48
|
+
From npm (Paseo 0.9 and later; this is the source paseo.cafe hands to Paseo 0.9+). Pin `0.4.0` on Paseo 0.8:
|
|
49
49
|
|
|
50
50
|
```bash
|
|
51
51
|
paseo plugin install npm:@koinzhang/paseo-plugin-activity
|
|
52
|
+
# Paseo 0.8: npm:@koinzhang/paseo-plugin-activity@0.4.0
|
|
52
53
|
```
|
|
53
54
|
|
|
54
55
|
After source changes, reload and check status:
|
|
@@ -78,7 +79,7 @@ This plugin is spec-driven: read [specs/README.md](./specs/README.md) before cod
|
|
|
78
79
|
|
|
79
80
|
## Publish
|
|
80
81
|
|
|
81
|
-
Release history: [CHANGELOG.md](./CHANGELOG.md) (current **0.
|
|
82
|
+
Release history: [CHANGELOG.md](./CHANGELOG.md) (current **0.4.0**). npm releases go through a GitHub Release tag `activity-vX.Y.Z` (not push-to-`main` alone). Steps: [CONTRIBUTING.md § Publishing to npm](../CONTRIBUTING.md#publishing-to-npm).
|
|
82
83
|
|
|
83
84
|
## License
|
|
84
85
|
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import { setImmediate } from "node:timers/promises";
|
|
4
|
+
import { createPaseoApi } from "@getpaseo/client";
|
|
5
|
+
import { watchAgentDirectory, type DirectoryAgent } from "./agent-directory.ts";
|
|
6
|
+
import { watchPillDirectory } from "./pill-directory.ts";
|
|
7
|
+
|
|
8
|
+
type Page = { entries: Array<{ agent: DirectoryAgent }>; pageInfo: { hasMore: boolean; nextCursor: string | null }; subscriptionId?: string };
|
|
9
|
+
const agent = (id: string, extra: object = {}) => ({ id, workspaceId: "w", status: "idle", archivedAt: null, ...extra }) as DirectoryAgent;
|
|
10
|
+
const page = (agents: DirectoryAgent[], nextCursor: string | null = null): Page => ({ entries: agents.map(agent => ({ agent })), pageInfo: { hasMore: nextCursor !== null, nextCursor } });
|
|
11
|
+
function deferred<T>() {
|
|
12
|
+
let resolve!: (value: T) => void;
|
|
13
|
+
let reject!: (error: Error) => void;
|
|
14
|
+
const promise = new Promise<T>((yes, no) => { resolve = yes; reject = no; });
|
|
15
|
+
return { promise, resolve, reject };
|
|
16
|
+
}
|
|
17
|
+
function harness(initial = page([agent("a")])) {
|
|
18
|
+
type Observer = { snapshot(page: Page): void; update(message: unknown): void; error?(error: Error): void };
|
|
19
|
+
const owned: Array<{ emit(update: object): void; reconnect(value: Page): void; fail(): void; released: boolean; signal?: AbortSignal }> = [];
|
|
20
|
+
let reads = 0;
|
|
21
|
+
let read: (options: any) => Promise<Page> = async () => initial;
|
|
22
|
+
let bootstrap: Promise<Page> | undefined;
|
|
23
|
+
let rejectRelease = false;
|
|
24
|
+
const daemon = {
|
|
25
|
+
fetchAgents: (options: unknown) => { reads++; return read(options); },
|
|
26
|
+
observeAgents(options: { signal?: AbortSignal }) {
|
|
27
|
+
let observer: Observer | undefined;
|
|
28
|
+
const entry = {
|
|
29
|
+
signal: options.signal,
|
|
30
|
+
released: false,
|
|
31
|
+
emit(payload: object) { observer?.update({ type: "agent_update", payload }); },
|
|
32
|
+
reconnect(value: Page) { observer?.snapshot({ ...value, subscriptionId: "restored" }); },
|
|
33
|
+
fail() { observer?.error?.(new Error("subscription lost")); },
|
|
34
|
+
};
|
|
35
|
+
owned.push(entry);
|
|
36
|
+
return {
|
|
37
|
+
ready: bootstrap ?? Promise.resolve({ ...initial, subscriptionId: String(owned.length) }),
|
|
38
|
+
subscribe(next: Observer) { observer = next; next.snapshot(initial); return () => { observer = undefined; }; },
|
|
39
|
+
async release() { entry.released = true; if (rejectRelease) throw new Error("release failed"); },
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
api: () => createPaseoApi(daemon as unknown as Parameters<typeof createPaseoApi>[0]),
|
|
45
|
+
owned,
|
|
46
|
+
setRead(fn: typeof read) { read = fn; },
|
|
47
|
+
setBootstrap(value: Promise<Page>) { bootstrap = value; },
|
|
48
|
+
setReleaseFailure() { rejectRelease = true; },
|
|
49
|
+
get reads() { return reads; },
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
test("real beta.2 API isolates owners; watchers share only their own API and release last", async () => {
|
|
54
|
+
const h = harness();
|
|
55
|
+
const host = h.api(), plugin = h.api(), surface = h.api();
|
|
56
|
+
await host.agents.list({ subscribe: {} });
|
|
57
|
+
let seen: ReadonlyMap<string, DirectoryAgent> | undefined;
|
|
58
|
+
const stop = watchAgentDirectory(plugin.agents, (value) => { seen = value; });
|
|
59
|
+
const stop2 = watchAgentDirectory(plugin.agents, () => {});
|
|
60
|
+
const stopSurface = watchAgentDirectory(surface.agents, () => {});
|
|
61
|
+
await setImmediate();
|
|
62
|
+
assert.equal(h.owned.length, 3);
|
|
63
|
+
h.owned[0]!.emit({ kind: "remove", agentId: "a" });
|
|
64
|
+
assert.equal(seen?.has("a"), true);
|
|
65
|
+
h.owned[1]!.emit({ kind: "upsert", agent: agent("a", { status: "running" }) });
|
|
66
|
+
assert.equal(seen?.get("a")?.status, "running");
|
|
67
|
+
stop();
|
|
68
|
+
assert.equal(h.owned[1]!.released, false);
|
|
69
|
+
stop2(); stopSurface();
|
|
70
|
+
await setImmediate();
|
|
71
|
+
assert.equal(h.owned[1]!.released, true);
|
|
72
|
+
assert.equal(h.owned[2]!.released, true);
|
|
73
|
+
assert.equal(h.owned[0]!.released, false);
|
|
74
|
+
await host.dispose();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("bootstrap pagination replays concurrent updates and reconnect rebuilds all pages", async () => {
|
|
78
|
+
const h = harness(page([agent("a")], "next"));
|
|
79
|
+
const tail = deferred<Page>();
|
|
80
|
+
h.setRead(async (options) => { assert.equal(options.page.cursor, "next"); return tail.promise; });
|
|
81
|
+
const api = h.api();
|
|
82
|
+
let seen: ReadonlyMap<string, DirectoryAgent> | undefined;
|
|
83
|
+
const stop = watchAgentDirectory(api.agents, value => { seen = value; });
|
|
84
|
+
try {
|
|
85
|
+
await setImmediate();
|
|
86
|
+
assert.equal(Boolean(seen), false);
|
|
87
|
+
h.owned[0]!.emit({ kind: "remove", agentId: "a" });
|
|
88
|
+
h.owned[0]!.emit({ kind: "upsert", agent: agent("b", { status: "running" }) });
|
|
89
|
+
tail.resolve(page([agent("b")]));
|
|
90
|
+
await setImmediate();
|
|
91
|
+
assert.equal(seen?.has("a"), false);
|
|
92
|
+
assert.equal(seen?.get("b")?.status, "running");
|
|
93
|
+
h.setRead(async () => page([agent("d")]));
|
|
94
|
+
h.owned[0]!.reconnect(page([agent("c")], "restored-next"));
|
|
95
|
+
await setImmediate();
|
|
96
|
+
assert.deepEqual([...seen!.keys()], ["c", "d"]);
|
|
97
|
+
} finally { stop(); }
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("a stale poll cannot overwrite a newer live update", async () => {
|
|
101
|
+
const h = harness();
|
|
102
|
+
const pending = deferred<Page>();
|
|
103
|
+
h.setRead(() => pending.promise);
|
|
104
|
+
let seen: ReadonlyMap<string, DirectoryAgent> | undefined;
|
|
105
|
+
const stop = watchAgentDirectory(h.api().agents, value => { seen = value; }, 1);
|
|
106
|
+
try {
|
|
107
|
+
while (!h.reads) await setImmediate();
|
|
108
|
+
h.owned[0]!.emit({ kind: "upsert", agent: agent("a", { status: "closed", archivedAt: null }) });
|
|
109
|
+
pending.resolve(page([agent("a")]));
|
|
110
|
+
h.setRead(async () => page([agent("a", { status: "closed", archivedAt: null })]));
|
|
111
|
+
await setImmediate();
|
|
112
|
+
assert.equal(seen?.get("a")?.status, "closed");
|
|
113
|
+
} finally { stop(); }
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("unmount during bootstrap aborts demand and releases a late handle without publishing", async () => {
|
|
117
|
+
const h = harness();
|
|
118
|
+
const pending = deferred<Page>();
|
|
119
|
+
h.setBootstrap(pending.promise);
|
|
120
|
+
let calls = 0;
|
|
121
|
+
const stop = watchAgentDirectory(h.api().agents, () => { calls++; });
|
|
122
|
+
stop();
|
|
123
|
+
assert.equal(h.owned[0]?.signal?.aborted, true);
|
|
124
|
+
pending.resolve(page([agent("late")]));
|
|
125
|
+
await setImmediate();
|
|
126
|
+
assert.equal(h.owned[0]?.released, true);
|
|
127
|
+
assert.equal(calls, 0);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test("subscription failure retries, and release failure is handled", async (t) => {
|
|
131
|
+
const errors: unknown[] = [];
|
|
132
|
+
t.mock.method(console, "error", (...args: unknown[]) => { errors.push(args); });
|
|
133
|
+
const h = harness();
|
|
134
|
+
const stop = watchAgentDirectory(h.api().agents, () => {}, 1);
|
|
135
|
+
await setImmediate();
|
|
136
|
+
h.owned[0]!.fail();
|
|
137
|
+
while (h.owned.length < 2) await setImmediate();
|
|
138
|
+
await setImmediate();
|
|
139
|
+
assert.equal(h.owned[0]?.released, true);
|
|
140
|
+
h.setReleaseFailure();
|
|
141
|
+
stop();
|
|
142
|
+
await setImmediate();
|
|
143
|
+
assert.ok(errors.some(args => String(args).includes("release failed")));
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("pill directory observes archive/unarchive and does not revive unchanged idle pills", async () => {
|
|
147
|
+
const h = harness();
|
|
148
|
+
const seen = new Set<string>();
|
|
149
|
+
let published = 0;
|
|
150
|
+
const stop = watchPillDirectory(h.api().agents, value => { published++; seen.add(value.id); }, id => seen.delete(id));
|
|
151
|
+
try {
|
|
152
|
+
await setImmediate();
|
|
153
|
+
assert.deepEqual([...seen], ["a"]);
|
|
154
|
+
h.owned[0]!.emit({ kind: "upsert", agent: agent("a") });
|
|
155
|
+
assert.equal(published, 1);
|
|
156
|
+
h.owned[0]!.emit({ kind: "upsert", agent: agent("a", { status: "closed", archivedAt: "2026-09-20" }) });
|
|
157
|
+
assert.equal(seen.size, 0);
|
|
158
|
+
h.owned[0]!.emit({ kind: "upsert", agent: agent("a") });
|
|
159
|
+
assert.deepEqual([...seen], ["a"]);
|
|
160
|
+
assert.equal(published, 2);
|
|
161
|
+
} finally { stop(); }
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test("bootstrap subscription rejection still falls back to plain reads", async (t) => {
|
|
165
|
+
t.mock.method(console, "error", () => {});
|
|
166
|
+
const h = harness();
|
|
167
|
+
h.setBootstrap(Promise.reject(new Error("observation unavailable")));
|
|
168
|
+
let seen: ReadonlyMap<string, DirectoryAgent> | undefined;
|
|
169
|
+
const stop = watchAgentDirectory(h.api().agents, value => { seen = value; });
|
|
170
|
+
try {
|
|
171
|
+
await setImmediate();
|
|
172
|
+
assert.equal(h.reads, 1);
|
|
173
|
+
assert.equal(seen?.has("a"), true);
|
|
174
|
+
} finally { stop(); }
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test("a restored snapshot supersedes an outstanding pre-reconnect poll", async () => {
|
|
178
|
+
const h = harness();
|
|
179
|
+
const oldRead = deferred<Page>();
|
|
180
|
+
h.setRead(() => oldRead.promise);
|
|
181
|
+
let seen: ReadonlyMap<string, DirectoryAgent> | undefined;
|
|
182
|
+
const stop = watchAgentDirectory(h.api().agents, value => { seen = value; }, 1);
|
|
183
|
+
try {
|
|
184
|
+
while (!h.reads) await setImmediate();
|
|
185
|
+
h.owned[0]!.reconnect(page([agent("restored")]));
|
|
186
|
+
oldRead.resolve(page([agent("stale")]));
|
|
187
|
+
h.setRead(async () => page([agent("restored")]));
|
|
188
|
+
await setImmediate();
|
|
189
|
+
assert.deepEqual([...seen!.keys()], ["restored"]);
|
|
190
|
+
} finally { stop(); }
|
|
191
|
+
});
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type { PluginClientContext } from "@getpaseo/plugin/client";
|
|
2
|
+
|
|
3
|
+
export type AgentsApi = PluginClientContext["paseo"]["agents"];
|
|
4
|
+
export type DirectoryAgent = Awaited<ReturnType<AgentsApi["list"]>>["entries"][number]["agent"];
|
|
5
|
+
type ListResult = Awaited<ReturnType<AgentsApi["list"]>>;
|
|
6
|
+
export type DirectoryUpdate = Parameters<Parameters<AgentsApi["subscribe"]>[0]>[0];
|
|
7
|
+
export type DirectoryListener = (
|
|
8
|
+
agents: ReadonlyMap<string, DirectoryAgent>,
|
|
9
|
+
update?: DirectoryUpdate,
|
|
10
|
+
) => void;
|
|
11
|
+
|
|
12
|
+
const directories = new WeakMap<AgentsApi, {
|
|
13
|
+
listen(listener: DirectoryListener): () => void;
|
|
14
|
+
}>();
|
|
15
|
+
|
|
16
|
+
/** One owned beta.2 observation per API, shared only by that API's consumers. */
|
|
17
|
+
export function watchAgentDirectory(
|
|
18
|
+
agents: AgentsApi,
|
|
19
|
+
listener: DirectoryListener,
|
|
20
|
+
intervalMs = 15_000,
|
|
21
|
+
): () => void {
|
|
22
|
+
let directory = directories.get(agents);
|
|
23
|
+
if (!directory) {
|
|
24
|
+
const listeners = new Set<DirectoryListener>();
|
|
25
|
+
let snapshot: Map<string, DirectoryAgent> | undefined;
|
|
26
|
+
let disposed = false;
|
|
27
|
+
let connecting = false;
|
|
28
|
+
let reading = false;
|
|
29
|
+
let generation = 0;
|
|
30
|
+
let pending: DirectoryUpdate[] = [];
|
|
31
|
+
const lifetime = new AbortController();
|
|
32
|
+
let controller: AbortController | undefined;
|
|
33
|
+
let release: (() => Promise<void>) | undefined;
|
|
34
|
+
const report = (error: unknown) => console.error("[activity] agent directory failed", error);
|
|
35
|
+
const safeRelease = () => {
|
|
36
|
+
const stop = release;
|
|
37
|
+
release = undefined;
|
|
38
|
+
if (stop) void stop().catch(report);
|
|
39
|
+
};
|
|
40
|
+
const publish = (update?: DirectoryUpdate) => {
|
|
41
|
+
if (disposed || !snapshot) return;
|
|
42
|
+
for (const callback of listeners) {
|
|
43
|
+
try { callback(snapshot, update); } catch (error) { report(error); }
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const apply = (map: Map<string, DirectoryAgent>, update: DirectoryUpdate) => {
|
|
47
|
+
if (update.kind === "remove") map.delete(update.agentId);
|
|
48
|
+
else map.set(update.agent.id, update.agent);
|
|
49
|
+
};
|
|
50
|
+
async function read(first?: ListResult) {
|
|
51
|
+
const run = ++generation;
|
|
52
|
+
const signal = lifetime.signal;
|
|
53
|
+
reading = true;
|
|
54
|
+
pending = [];
|
|
55
|
+
try {
|
|
56
|
+
let page = first ?? await agents.list({
|
|
57
|
+
filter: { includeArchived: true }, page: { limit: 200 }, signal,
|
|
58
|
+
});
|
|
59
|
+
const next = new Map<string, DirectoryAgent>();
|
|
60
|
+
for (let pages = 0; ; pages++) {
|
|
61
|
+
if (disposed || run !== generation) return;
|
|
62
|
+
for (const { agent } of page.entries) next.set(agent.id, agent);
|
|
63
|
+
if (!page.pageInfo.hasMore) break;
|
|
64
|
+
if (!page.pageInfo.nextCursor || pages >= 99) throw new Error("Incomplete agent directory pagination");
|
|
65
|
+
page = await agents.list({
|
|
66
|
+
filter: { includeArchived: true },
|
|
67
|
+
page: { limit: 200, cursor: page.pageInfo.nextCursor }, signal,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
for (const update of pending) apply(next, update);
|
|
71
|
+
snapshot = next;
|
|
72
|
+
publish();
|
|
73
|
+
} catch (error) {
|
|
74
|
+
if (!disposed && run === generation) report(error);
|
|
75
|
+
} finally {
|
|
76
|
+
if (run === generation) { reading = false; pending = []; }
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async function connect() {
|
|
80
|
+
if (disposed || connecting || release) return;
|
|
81
|
+
connecting = true;
|
|
82
|
+
controller = new AbortController();
|
|
83
|
+
try {
|
|
84
|
+
const result = await agents.list({
|
|
85
|
+
filter: { includeArchived: true }, page: { limit: 200 },
|
|
86
|
+
subscribe: {}, signal: controller.signal,
|
|
87
|
+
});
|
|
88
|
+
if (disposed) {
|
|
89
|
+
await result.subscription.release();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
release = () => result.subscription.release();
|
|
93
|
+
result.subscription.subscribe({
|
|
94
|
+
// Called immediately and again after reconnect. Rebuild all pages each time.
|
|
95
|
+
snapshot: (page) => { void read(page); },
|
|
96
|
+
update: (message) => {
|
|
97
|
+
if (disposed || message.type !== "agent_update") return;
|
|
98
|
+
const update = message.payload;
|
|
99
|
+
if (reading) pending.push(update);
|
|
100
|
+
if (snapshot) {
|
|
101
|
+
snapshot = new Map(snapshot);
|
|
102
|
+
apply(snapshot, update);
|
|
103
|
+
publish(update);
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
error: (error) => {
|
|
107
|
+
if (disposed) return;
|
|
108
|
+
report(error);
|
|
109
|
+
++generation;
|
|
110
|
+
reading = false;
|
|
111
|
+
controller?.abort();
|
|
112
|
+
safeRelease();
|
|
113
|
+
void read();
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
} catch (error) {
|
|
117
|
+
if (!disposed) {
|
|
118
|
+
report(error);
|
|
119
|
+
await read();
|
|
120
|
+
}
|
|
121
|
+
} finally {
|
|
122
|
+
connecting = false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const timer = setInterval(() => {
|
|
126
|
+
if (!release) void connect();
|
|
127
|
+
else if (!reading) void read();
|
|
128
|
+
}, intervalMs);
|
|
129
|
+
directory = {
|
|
130
|
+
listen(callback) {
|
|
131
|
+
listeners.add(callback);
|
|
132
|
+
if (snapshot) callback(snapshot);
|
|
133
|
+
return () => {
|
|
134
|
+
listeners.delete(callback);
|
|
135
|
+
if (listeners.size !== 0 || disposed) return;
|
|
136
|
+
disposed = true;
|
|
137
|
+
++generation;
|
|
138
|
+
clearInterval(timer);
|
|
139
|
+
lifetime.abort();
|
|
140
|
+
controller?.abort();
|
|
141
|
+
safeRelease();
|
|
142
|
+
directories.delete(agents);
|
|
143
|
+
};
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
directories.set(agents, directory);
|
|
147
|
+
void connect();
|
|
148
|
+
}
|
|
149
|
+
return directory.listen(listener);
|
|
150
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import {
|
|
4
|
+
attentionPillIconName,
|
|
5
|
+
attentionPillTint,
|
|
6
|
+
filterAttentionAgents,
|
|
7
|
+
} from "./attention-agents.ts";
|
|
8
|
+
import type { AgentStatusInfo } from "./workspace/constants.ts";
|
|
9
|
+
|
|
10
|
+
function status(partial: Partial<AgentStatusInfo>): AgentStatusInfo {
|
|
11
|
+
return {
|
|
12
|
+
rank: 0,
|
|
13
|
+
updatedAt: null,
|
|
14
|
+
status: null,
|
|
15
|
+
permissionCount: 0,
|
|
16
|
+
requiresAttention: false,
|
|
17
|
+
attentionReason: null,
|
|
18
|
+
parentAgentId: null,
|
|
19
|
+
...partial,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe("filterAttentionAgents", () => {
|
|
24
|
+
it("keeps finished, permission, and error; drops current and idle", () => {
|
|
25
|
+
const statuses = {
|
|
26
|
+
self: status({ requiresAttention: true, attentionReason: "finished" }),
|
|
27
|
+
done: status({
|
|
28
|
+
requiresAttention: true,
|
|
29
|
+
attentionReason: "finished",
|
|
30
|
+
updatedAt: "2026-09-20T10:00:00Z",
|
|
31
|
+
}),
|
|
32
|
+
wait: status({
|
|
33
|
+
permissionCount: 1,
|
|
34
|
+
updatedAt: "2026-09-20T09:00:00Z",
|
|
35
|
+
}),
|
|
36
|
+
fail: status({
|
|
37
|
+
status: "error",
|
|
38
|
+
requiresAttention: true,
|
|
39
|
+
attentionReason: "error",
|
|
40
|
+
updatedAt: "2026-09-20T08:00:00Z",
|
|
41
|
+
}),
|
|
42
|
+
idle: status({ status: "idle" }),
|
|
43
|
+
};
|
|
44
|
+
const items = filterAttentionAgents(statuses, "self");
|
|
45
|
+
assert.deepEqual(
|
|
46
|
+
items.map((item) => item.agentId),
|
|
47
|
+
["wait", "fail", "done"],
|
|
48
|
+
);
|
|
49
|
+
assert.deepEqual(
|
|
50
|
+
items.map((item) => item.kind),
|
|
51
|
+
["permission", "error", "finished"],
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("returns empty when statuses missing", () => {
|
|
56
|
+
assert.deepEqual(filterAttentionAgents(undefined, "a"), []);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe("attentionPillTint", () => {
|
|
61
|
+
it("prefers permission, then error, then finished", () => {
|
|
62
|
+
assert.equal(attentionPillTint([]), null);
|
|
63
|
+
assert.equal(
|
|
64
|
+
attentionPillTint([
|
|
65
|
+
{ agentId: "a", kind: "finished", permissionCount: 0, updatedAt: null },
|
|
66
|
+
]),
|
|
67
|
+
"finished",
|
|
68
|
+
);
|
|
69
|
+
assert.equal(
|
|
70
|
+
attentionPillTint([
|
|
71
|
+
{ agentId: "a", kind: "finished", permissionCount: 0, updatedAt: null },
|
|
72
|
+
{ agentId: "b", kind: "error", permissionCount: 0, updatedAt: null },
|
|
73
|
+
]),
|
|
74
|
+
"error",
|
|
75
|
+
);
|
|
76
|
+
assert.equal(
|
|
77
|
+
attentionPillTint([
|
|
78
|
+
{ agentId: "a", kind: "finished", permissionCount: 0, updatedAt: null },
|
|
79
|
+
{ agentId: "b", kind: "error", permissionCount: 0, updatedAt: null },
|
|
80
|
+
{ agentId: "c", kind: "permission", permissionCount: 1, updatedAt: null },
|
|
81
|
+
]),
|
|
82
|
+
"permission",
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe("attentionPillIconName", () => {
|
|
88
|
+
it("maps tint to lucide names", () => {
|
|
89
|
+
assert.equal(attentionPillIconName(null), "Bell");
|
|
90
|
+
assert.equal(attentionPillIconName("permission"), "Bell");
|
|
91
|
+
assert.equal(attentionPillIconName("error"), "CircleAlert");
|
|
92
|
+
assert.equal(attentionPillIconName("finished"), "CircleCheck");
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
attentionKind,
|
|
3
|
+
type AgentAttentionKind,
|
|
4
|
+
type AgentStatusInfo,
|
|
5
|
+
} from "./workspace/constants.ts";
|
|
6
|
+
|
|
7
|
+
export type AttentionAgentItem = {
|
|
8
|
+
agentId: string;
|
|
9
|
+
kind: NonNullable<AgentAttentionKind>;
|
|
10
|
+
permissionCount: number;
|
|
11
|
+
updatedAt: string | null;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const KIND_ORDER: Record<NonNullable<AgentAttentionKind>, number> = {
|
|
15
|
+
permission: 0,
|
|
16
|
+
error: 1,
|
|
17
|
+
finished: 2,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** Same-workspace interrupt targets: finished / permission / error; never current. */
|
|
21
|
+
export function filterAttentionAgents(
|
|
22
|
+
statuses: Record<string, AgentStatusInfo> | undefined,
|
|
23
|
+
currentAgentId: string,
|
|
24
|
+
): AttentionAgentItem[] {
|
|
25
|
+
if (!statuses) return [];
|
|
26
|
+
const items: AttentionAgentItem[] = [];
|
|
27
|
+
for (const [agentId, info] of Object.entries(statuses)) {
|
|
28
|
+
if (agentId === currentAgentId) continue;
|
|
29
|
+
const kind = attentionKind(info);
|
|
30
|
+
if (kind == null) continue;
|
|
31
|
+
items.push({
|
|
32
|
+
agentId,
|
|
33
|
+
kind,
|
|
34
|
+
permissionCount: info.permissionCount,
|
|
35
|
+
updatedAt: info.updatedAt,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return items.sort(compareAttentionAgents);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function compareAttentionAgents(a: AttentionAgentItem, b: AttentionAgentItem): number {
|
|
42
|
+
const byKind = KIND_ORDER[a.kind] - KIND_ORDER[b.kind];
|
|
43
|
+
if (byKind !== 0) return byKind;
|
|
44
|
+
const aAt = a.updatedAt ?? "";
|
|
45
|
+
const bAt = b.updatedAt ?? "";
|
|
46
|
+
if (aAt !== bAt) return aAt < bAt ? 1 : -1;
|
|
47
|
+
return a.agentId.localeCompare(b.agentId);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Pill icon tint: permission > error > finished. */
|
|
51
|
+
export function attentionPillTint(
|
|
52
|
+
items: ReadonlyArray<AttentionAgentItem>,
|
|
53
|
+
): NonNullable<AgentAttentionKind> | null {
|
|
54
|
+
if (items.length === 0) return null;
|
|
55
|
+
if (items.some((item) => item.kind === "permission")) return "permission";
|
|
56
|
+
if (items.some((item) => item.kind === "error")) return "error";
|
|
57
|
+
return "finished";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Lucide name: Bell = permission, CircleAlert = error, CircleCheck = finished. */
|
|
61
|
+
export function attentionPillIconName(
|
|
62
|
+
tint: NonNullable<AgentAttentionKind> | null,
|
|
63
|
+
): "Bell" | "CircleAlert" | "CircleCheck" {
|
|
64
|
+
if (tint === "finished") return "CircleCheck";
|
|
65
|
+
if (tint === "error") return "CircleAlert";
|
|
66
|
+
return "Bell";
|
|
67
|
+
}
|