@koinzhang/paseo-plugin-activity 0.4.0 → 0.6.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 +61 -2
- package/README.md +3 -3
- package/client/activity-heatmap.tsx +17 -25
- package/client/agent-creations.tsx +207 -0
- package/client/agent-directory.test.ts +191 -0
- package/client/agent-directory.ts +150 -0
- package/client/attention-pill.tsx +17 -105
- package/client/color-mix.test.ts +27 -0
- package/client/color-mix.ts +38 -0
- package/client/fit-text.test.ts +41 -0
- package/client/fit-text.ts +33 -0
- package/client/global-surface.tsx +104 -31
- package/client/hourly-activity-timeline.tsx +392 -0
- package/client/measured-width.ts +72 -0
- package/client/pill-directory.ts +20 -68
- package/client/range.test.ts +44 -0
- package/client/range.ts +14 -0
- package/client/rank-color.test.ts +108 -14
- package/client/rank-color.ts +261 -48
- package/client/usage-stats.tsx +116 -5
- package/client/use-agent-turn-end.ts +19 -2
- package/client/use-workspace-agent-statuses.ts +18 -42
- package/client/workspace/constants.ts +2 -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 +11 -63
- package/client/workspace/list-host-agents.ts +4 -58
- package/client/workspace/panel.tsx +99 -12
- package/client/workspace/rank-section.tsx +150 -11
- package/index.server.ts +30 -0
- package/package.json +3 -3
- package/paseo-plugin.json +1 -1
- package/server/background-sync.test.ts +43 -0
- package/server/background-sync.ts +9 -0
- package/server/handlers-query.test.ts +225 -0
- package/server/handlers.ts +117 -0
- package/shared/activity.test.ts +123 -6
- package/shared/activity.ts +103 -5
- package/shared/classify.test.ts +10 -0
- package/shared/classify.ts +10 -0
- package/shared/explorer-agent-display.test.ts +61 -0
- package/shared/explorer-agent-display.ts +21 -2
- package/shared/format.test.ts +28 -3
- package/shared/format.ts +22 -2
- package/shared/insights.test.ts +113 -70
- package/shared/insights.ts +53 -39
- package/shared/usage.test.ts +209 -0
- package/shared/usage.ts +283 -1
- package/client/pill-directory.test.ts +0 -92
- package/client/workspace/agent-live-status-sync.tsx +0 -103
- package/client/workspace/status-cache.test.ts +0 -62
- package/client/workspace/status-cache.ts +0 -23
package/client/usage-stats.tsx
CHANGED
|
@@ -1,4 +1,111 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { Text, View, type TextStyle } from "react-native";
|
|
3
|
+
import { fitFontSize } from "./fit-text.ts";
|
|
4
|
+
|
|
5
|
+
/** Hidden measuring box wide enough to never clamp the text (051). */
|
|
6
|
+
const MEASURE_WIDTH = 1000;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Single-line text that shrinks instead of wrapping (051). KPI tiles are
|
|
10
|
+
* ~130px wide, so 18px values like "Cursor · 61%" used to wrap onto two lines
|
|
11
|
+
* and push the labels out of line. The hidden copy measures the intrinsic width
|
|
12
|
+
* at `base` (an unconstrained box, since a constrained one reports the clamped
|
|
13
|
+
* width), then the visible text is scaled to fit. `numberOfLines={1}` stays as
|
|
14
|
+
* the hard guard: a bad measurement can only ellipsize, never wrap.
|
|
15
|
+
*/
|
|
16
|
+
function FitText({ text, available, base, min, lineHeight, color, weight, tabular }: {
|
|
17
|
+
text: string;
|
|
18
|
+
available: number;
|
|
19
|
+
base: number;
|
|
20
|
+
min?: number;
|
|
21
|
+
lineHeight: number;
|
|
22
|
+
color: string;
|
|
23
|
+
weight?: "500";
|
|
24
|
+
tabular?: boolean;
|
|
25
|
+
}) {
|
|
26
|
+
// The hidden copy renders at `fontSize` and reports its width; the fit is
|
|
27
|
+
// derived from that single measurement, so a tile resize re-fits without
|
|
28
|
+
// needing a new measurement.
|
|
29
|
+
const [measured, setMeasured] = useState({ size: base, width: 0 });
|
|
30
|
+
const fontSize = fitFontSize(measured, available, { base, min });
|
|
31
|
+
const style: TextStyle = {
|
|
32
|
+
color,
|
|
33
|
+
fontSize,
|
|
34
|
+
lineHeight,
|
|
35
|
+
fontWeight: weight,
|
|
36
|
+
fontVariant: tabular ? ["tabular-nums"] : undefined,
|
|
37
|
+
};
|
|
38
|
+
return (
|
|
39
|
+
<>
|
|
40
|
+
<View
|
|
41
|
+
pointerEvents="none"
|
|
42
|
+
style={{ position: "absolute", left: 0, top: 0, width: 0, height: 0, overflow: "hidden" }}
|
|
43
|
+
>
|
|
44
|
+
<View style={{ position: "absolute", left: 0, top: 0, width: MEASURE_WIDTH, flexDirection: "row", opacity: 0 }}>
|
|
45
|
+
<Text
|
|
46
|
+
numberOfLines={1}
|
|
47
|
+
onLayout={(event) =>
|
|
48
|
+
setMeasured({ size: fontSize, width: event.nativeEvent.layout.width })
|
|
49
|
+
}
|
|
50
|
+
style={{ ...style, flexShrink: 0 }}
|
|
51
|
+
>
|
|
52
|
+
{text}
|
|
53
|
+
</Text>
|
|
54
|
+
</View>
|
|
55
|
+
</View>
|
|
56
|
+
<Text numberOfLines={1} style={style}>
|
|
57
|
+
{text}
|
|
58
|
+
</Text>
|
|
59
|
+
</>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function StatTile({ item, colors, dense, compact, bordered }: {
|
|
64
|
+
item: { label: string; value: string };
|
|
65
|
+
colors: { border: string; foreground: string; foregroundMuted: string };
|
|
66
|
+
dense: boolean;
|
|
67
|
+
compact: boolean;
|
|
68
|
+
bordered: boolean;
|
|
69
|
+
}) {
|
|
70
|
+
const [width, setWidth] = useState(0);
|
|
71
|
+
const padding = dense ? 8 : 12;
|
|
72
|
+
const available = Math.max(0, width - padding * 2);
|
|
73
|
+
return (
|
|
74
|
+
<View
|
|
75
|
+
onLayout={(event) => setWidth(event.nativeEvent.layout.width)}
|
|
76
|
+
style={{
|
|
77
|
+
position: "relative",
|
|
78
|
+
flexGrow: 1,
|
|
79
|
+
flexBasis: dense ? 84 : compact ? 100 : 120,
|
|
80
|
+
minWidth: 0,
|
|
81
|
+
alignItems: "center",
|
|
82
|
+
paddingHorizontal: padding,
|
|
83
|
+
paddingVertical: dense ? 2 : 4,
|
|
84
|
+
gap: dense ? 4 : 6,
|
|
85
|
+
borderLeftWidth: bordered ? 1 : 0,
|
|
86
|
+
borderLeftColor: colors.border,
|
|
87
|
+
}}
|
|
88
|
+
>
|
|
89
|
+
<FitText
|
|
90
|
+
text={item.value}
|
|
91
|
+
available={available}
|
|
92
|
+
base={18}
|
|
93
|
+
lineHeight={22}
|
|
94
|
+
color={colors.foreground}
|
|
95
|
+
weight="500"
|
|
96
|
+
tabular
|
|
97
|
+
/>
|
|
98
|
+
<FitText
|
|
99
|
+
text={item.label}
|
|
100
|
+
available={available}
|
|
101
|
+
base={12}
|
|
102
|
+
min={10}
|
|
103
|
+
lineHeight={16}
|
|
104
|
+
color={colors.foregroundMuted}
|
|
105
|
+
/>
|
|
106
|
+
</View>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
2
109
|
|
|
3
110
|
export function UsageStats({ items, colors, compact, dense }: {
|
|
4
111
|
items: ReadonlyArray<{ label: string; value: string }>;
|
|
@@ -10,10 +117,14 @@ export function UsageStats({ items, colors, compact, dense }: {
|
|
|
10
117
|
return (
|
|
11
118
|
<View style={{ flexDirection: "row", flexWrap: "wrap", borderWidth: 1, borderColor: colors.border, borderRadius: 20, paddingVertical: dense ? 6 : compact ? 8 : 18, rowGap: dense ? 10 : 16 }}>
|
|
12
119
|
{items.map((item, index) => (
|
|
13
|
-
<
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
120
|
+
<StatTile
|
|
121
|
+
key={item.label}
|
|
122
|
+
item={item}
|
|
123
|
+
colors={colors}
|
|
124
|
+
dense={dense === true}
|
|
125
|
+
compact={compact}
|
|
126
|
+
bordered={index > 0 && !compact}
|
|
127
|
+
/>
|
|
17
128
|
))}
|
|
18
129
|
</View>
|
|
19
130
|
);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { usePaseo } from "@getpaseo/plugin/client";
|
|
2
2
|
import { useEffect, useRef } from "react";
|
|
3
|
+
import { watchAgentDirectory } from "./agent-directory.ts";
|
|
3
4
|
|
|
4
5
|
const TURN_END_DEBOUNCE_MS = 300;
|
|
5
6
|
const INGEST_SETTLE_MS = 2_000;
|
|
@@ -36,10 +37,26 @@ function useActivityRefresh(scope: AgentTurnEndScope, onTurnEnd: () => void): vo
|
|
|
36
37
|
};
|
|
37
38
|
const unsubscribe = agentId != null
|
|
38
39
|
? paseo.agents.ref(agentId).timeline.subscribe(({ event }) => {
|
|
39
|
-
if (
|
|
40
|
+
if (event.type === "subscription_restored") {
|
|
41
|
+
// Live-only after reconnect; refresh in case a turn ended while offline.
|
|
42
|
+
schedule();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (event.type === "error") {
|
|
46
|
+
console.error(
|
|
47
|
+
"[activity] timeline observation stopped; polling remains active",
|
|
48
|
+
"error" in event ? event.error : event,
|
|
49
|
+
);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (["turn_completed", "turn_failed", "turn_canceled", "replacement"].includes(event.type)) {
|
|
53
|
+
schedule();
|
|
54
|
+
}
|
|
40
55
|
})
|
|
41
|
-
: paseo.agents
|
|
56
|
+
: watchAgentDirectory(paseo.agents, (_snapshot, update) => {
|
|
42
57
|
// Workspace-wide hint only. The 15s query poll owns completeness.
|
|
58
|
+
// The surface owns its API observation, independently of the entry.
|
|
59
|
+
if (!update) { schedule(); return; }
|
|
43
60
|
if (update.kind === "remove") {
|
|
44
61
|
schedule();
|
|
45
62
|
return;
|
|
@@ -1,47 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "
|
|
5
|
-
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
6
|
-
import { useEffect, useMemo } from "react";
|
|
1
|
+
import { usePaseo } from "@getpaseo/plugin/client";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { watchAgentDirectory } from "./agent-directory.ts";
|
|
4
|
+
import { agentStatusInfo } from "./workspace/list-host-agents.ts";
|
|
7
5
|
import type { AgentStatusInfo } from "./workspace/constants.ts";
|
|
8
|
-
import { loadWorkspaceAgentStatuses } from "./workspace/list-host-agents.ts";
|
|
9
|
-
import { updateWorkspaceStatusCache } from "./workspace/status-cache.ts";
|
|
10
6
|
|
|
11
|
-
|
|
12
|
-
workspaceId: string,
|
|
13
|
-
projectId: string | null | undefined,
|
|
14
|
-
) {
|
|
15
|
-
return ["activity", "workspace-agent-status", workspaceId, projectId ?? null] as const;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Shared host agent status map for a workspace (Explorer + attention pill).
|
|
20
|
-
* 15s poll owns completeness; subscribe accelerates without list({ subscribe }).
|
|
21
|
-
*/
|
|
7
|
+
/** Directory snapshots are authoritative; host UI cache absence is not a lifecycle event. */
|
|
22
8
|
export function useWorkspaceAgentStatuses(workspaceId: string) {
|
|
23
9
|
const paseo = usePaseo();
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
useEffect(
|
|
39
|
-
() =>
|
|
40
|
-
paseo.agents.subscribe((update) => {
|
|
41
|
-
updateWorkspaceStatusCache(queryClient, queryKey, workspaceId, update);
|
|
42
|
-
}),
|
|
43
|
-
[paseo, queryClient, workspaceId, queryKey],
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
return query as typeof query & { data: Record<string, AgentStatusInfo> | undefined };
|
|
10
|
+
const [state, setState] = useState<{
|
|
11
|
+
paseo: typeof paseo;
|
|
12
|
+
workspaceId: string;
|
|
13
|
+
data: Record<string, AgentStatusInfo>;
|
|
14
|
+
}>();
|
|
15
|
+
useEffect(() => watchAgentDirectory(paseo.agents, (snapshot) => {
|
|
16
|
+
const data: Record<string, AgentStatusInfo> = {};
|
|
17
|
+
for (const agent of snapshot.values()) {
|
|
18
|
+
if (agent.workspaceId === workspaceId) data[agent.id] = agentStatusInfo(agent);
|
|
19
|
+
}
|
|
20
|
+
setState({ paseo, workspaceId, data });
|
|
21
|
+
}), [paseo, workspaceId]);
|
|
22
|
+
return { data: state?.paseo === paseo && state.workspaceId === workspaceId ? state.data : undefined };
|
|
47
23
|
}
|
|
@@ -13,6 +13,8 @@ export type AgentLifecycleFilter = "idle" | "running" | "error" | "closed";
|
|
|
13
13
|
export type MenuFlyout = "sort" | "group" | "show" | "status" | "lifecycle";
|
|
14
14
|
|
|
15
15
|
export type AgentStatusInfo = {
|
|
16
|
+
/** Explicit host archive state; absent means unknown. */
|
|
17
|
+
archivedAt?: string | null;
|
|
16
18
|
rank: number;
|
|
17
19
|
updatedAt: string | null;
|
|
18
20
|
status: string | null;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import type { AgentUsageItem } from "../../shared/usage.ts";
|
|
4
|
+
import { reconcileHostArchive } from "./host-archive-sync.ts";
|
|
5
|
+
import { agentStatusInfo } from "./list-host-agents.ts";
|
|
6
|
+
|
|
7
|
+
function item(agentId: string, archivedAt: string | null = null): AgentUsageItem {
|
|
8
|
+
return {
|
|
9
|
+
agentId,
|
|
10
|
+
provider: "cursor",
|
|
11
|
+
title: agentId,
|
|
12
|
+
callCount: 0,
|
|
13
|
+
skillCalls: 0,
|
|
14
|
+
mcpCalls: 0,
|
|
15
|
+
shellCalls: 0,
|
|
16
|
+
fileReads: 0,
|
|
17
|
+
fileWrites: 0,
|
|
18
|
+
messageCount: 0,
|
|
19
|
+
coding: false,
|
|
20
|
+
createdAt: "2026-09-20T00:00:00.000Z",
|
|
21
|
+
updatedAt: "2026-09-20T00:00:00.000Z",
|
|
22
|
+
archivedAt,
|
|
23
|
+
parentAgentId: null,
|
|
24
|
+
lastActivityAt: null,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
test("missing host cache and closed status do not synthesize archive", () => {
|
|
29
|
+
const rows = [item("a")];
|
|
30
|
+
assert.equal(reconcileHostArchive(rows, undefined)[0], rows[0]);
|
|
31
|
+
assert.equal(reconcileHostArchive(rows, {})[0], rows[0]);
|
|
32
|
+
const statuses = { a: agentStatusInfo({ id: "a", status: "closed", archivedAt: null }) };
|
|
33
|
+
assert.equal(reconcileHostArchive(rows, statuses)[0]?.archivedAt, null);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("explicit host archive and unarchive override delayed DB results without changing metrics", () => {
|
|
37
|
+
const row = { ...item("a"), callCount: 42 };
|
|
38
|
+
const archived = { a: agentStatusInfo({ id: "a", archivedAt: "2026-09-20T08:30:43.446Z" }) };
|
|
39
|
+
const first = reconcileHostArchive([row], archived)[0]!;
|
|
40
|
+
assert.equal(first.archivedAt, archived.a.archivedAt);
|
|
41
|
+
assert.equal(first.callCount, 42);
|
|
42
|
+
assert.equal(row.archivedAt, null);
|
|
43
|
+
assert.equal(reconcileHostArchive([row], archived)[0]?.archivedAt, first.archivedAt);
|
|
44
|
+
const active = { a: agentStatusInfo({ id: "a", archivedAt: null }) };
|
|
45
|
+
assert.equal(reconcileHostArchive([first], active)[0]?.archivedAt, null);
|
|
46
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AgentUsageItem } from "../../shared/usage.ts";
|
|
2
|
+
import type { AgentStatusInfo } from "./constants.ts";
|
|
3
|
+
|
|
4
|
+
/** Preserve DB metrics while explicit host archive state wins over delayed RPC results. */
|
|
5
|
+
export function reconcileHostArchive(
|
|
6
|
+
items: ReadonlyArray<AgentUsageItem>,
|
|
7
|
+
statuses: Record<string, AgentStatusInfo> | undefined,
|
|
8
|
+
): AgentUsageItem[] {
|
|
9
|
+
return items.map((item) => {
|
|
10
|
+
const archivedAt = statuses?.[item.agentId]?.archivedAt;
|
|
11
|
+
return archivedAt === undefined || archivedAt === item.archivedAt
|
|
12
|
+
? item
|
|
13
|
+
: { ...item, archivedAt };
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -1,48 +1,6 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { test } from "node:test";
|
|
3
|
-
import {
|
|
4
|
-
import { agentStatusInfo, applyAgentStatusUpdate, loadWorkspaceAgentStatuses } from "./list-host-agents.ts";
|
|
5
|
-
|
|
6
|
-
test("workspace status uses daemon placement project ID on every page and rejects other workspaces", async () => {
|
|
7
|
-
let pages = 0;
|
|
8
|
-
const map = await loadWorkspaceAgentStatuses({ agents: { list: async (options) => {
|
|
9
|
-
assert.deepEqual(options.filter, { includeArchived: true, projectKeys: ["prj_c187d0857b6da810"] });
|
|
10
|
-
pages++;
|
|
11
|
-
return {
|
|
12
|
-
entries: [{ agent: { id: `a${pages}`, workspaceId: pages === 1 ? "other" : "w", pendingPermissions: [{}] } },
|
|
13
|
-
{ agent: { id: "unknown" } }],
|
|
14
|
-
pageInfo: { hasMore: pages === 1, nextCursor: pages === 1 ? "next" : null },
|
|
15
|
-
};
|
|
16
|
-
} } }, "w", "prj_c187d0857b6da810");
|
|
17
|
-
assert.equal(pages, 2);
|
|
18
|
-
assert.deepEqual(Object.keys(map), ["a2"]);
|
|
19
|
-
assert.equal(map.a2?.permissionCount, 1);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
// Reproduce daemon 0.8's structural filter, including the two different keys.
|
|
23
|
-
test("pending questions survive a poll when catalog key differs from placement key", async () => {
|
|
24
|
-
const workspace = { id: "w", projectId: "prj_project" };
|
|
25
|
-
const project = { projectId: workspace.projectId, projectKey: "remote:github.com/org/repo" };
|
|
26
|
-
const entry = {
|
|
27
|
-
agent: { id: "waiting", workspaceId: workspace.id, status: "running",
|
|
28
|
-
requiresAttention: false, attentionReason: null, pendingPermissions: [{ tool: "question" }] },
|
|
29
|
-
project: { projectKey: project.projectId },
|
|
30
|
-
};
|
|
31
|
-
const paseo = { agents: { list: async (options: { filter?: { projectKeys?: string[] } }) => ({
|
|
32
|
-
entries: !options.filter?.projectKeys || options.filter.projectKeys.includes(entry.project.projectKey) ? [entry] : [],
|
|
33
|
-
pageInfo: { hasMore: false, nextCursor: null },
|
|
34
|
-
}) } };
|
|
35
|
-
const incorrect = await loadWorkspaceAgentStatuses(paseo, workspace.id, project.projectKey);
|
|
36
|
-
assert.deepEqual(incorrect, {});
|
|
37
|
-
for (let poll = 0; poll < 2; poll++) {
|
|
38
|
-
const statuses = await loadWorkspaceAgentStatuses(paseo, workspace.id, workspace.projectId);
|
|
39
|
-
assert.equal(statuses.waiting?.permissionCount, 1);
|
|
40
|
-
assert.equal(statuses.waiting?.rank, 0);
|
|
41
|
-
assert.equal(attentionKind(statuses.waiting), "permission");
|
|
42
|
-
}
|
|
43
|
-
const fallback = await loadWorkspaceAgentStatuses(paseo, workspace.id);
|
|
44
|
-
assert.equal(fallback.waiting?.permissionCount, 1);
|
|
45
|
-
});
|
|
3
|
+
import { agentStatusInfo, applyAgentStatusUpdate } from "./list-host-agents.ts";
|
|
46
4
|
|
|
47
5
|
test("agentStatusInfo maps parentAgentId and preserves it on partial pushes", () => {
|
|
48
6
|
const first = agentStatusInfo({ id: "child", workspaceId: "w", parentAgentId: "parent" });
|
|
@@ -78,26 +36,16 @@ test("agentStatusInfo falls back to paseo.parent-agent-id label when field is nu
|
|
|
78
36
|
assert.equal(prefersField.parentAgentId, "root");
|
|
79
37
|
});
|
|
80
38
|
|
|
81
|
-
test("
|
|
82
|
-
const map = {
|
|
83
|
-
a: agentStatusInfo({ id: "a", workspaceId: "w", status: "
|
|
84
|
-
b: agentStatusInfo({ id: "b", workspaceId: "w", status: "running", pendingPermissions: [{}] }),
|
|
39
|
+
test("remove only removes membership; closed is accepted only from explicit status", () => {
|
|
40
|
+
const map: Record<string, ReturnType<typeof agentStatusInfo>> = {
|
|
41
|
+
a: agentStatusInfo({ id: "a", workspaceId: "w", status: "running" }),
|
|
85
42
|
};
|
|
86
43
|
applyAgentStatusUpdate(map, "w", { kind: "remove", agentId: "a" });
|
|
87
|
-
assert.equal(map.a
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
});
|
|
93
|
-
assert.equal(map.
|
|
94
|
-
assert.equal(map.b.permissionCount, 1);
|
|
95
|
-
applyAgentStatusUpdate(map, "w", {
|
|
96
|
-
kind: "upsert",
|
|
97
|
-
agent: { id: "c", status: "idle" },
|
|
98
|
-
});
|
|
99
|
-
assert.equal(
|
|
100
|
-
(map as Record<string, ReturnType<typeof agentStatusInfo>>).c,
|
|
101
|
-
undefined,
|
|
102
|
-
);
|
|
44
|
+
assert.equal(Boolean(map.a), false);
|
|
45
|
+
applyAgentStatusUpdate(map, "w", { kind: "upsert", agent: { id: "a", workspaceId: "w", status: "closed", archivedAt: null } });
|
|
46
|
+
assert.equal(map.a?.status, "closed");
|
|
47
|
+
assert.equal(map.a?.archivedAt, null);
|
|
48
|
+
// A new authoritative snapshot can reopen without a timestamp heuristic.
|
|
49
|
+
applyAgentStatusUpdate(map, "w", { kind: "upsert", agent: { id: "a", workspaceId: "w", status: "idle", archivedAt: null } });
|
|
50
|
+
assert.equal(map.a?.status, "idle");
|
|
103
51
|
});
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { listAllAgentPages } from "../../shared/list-agent-pages.ts";
|
|
2
1
|
import {
|
|
3
2
|
attentionRank,
|
|
4
|
-
HOST_AGENT_PAGE_LIMIT,
|
|
5
3
|
type AgentStatusInfo,
|
|
6
4
|
} from "./constants.ts";
|
|
7
5
|
|
|
@@ -10,6 +8,7 @@ export type HostAgentEntry = {
|
|
|
10
8
|
id: string;
|
|
11
9
|
workspaceId?: string;
|
|
12
10
|
status?: string;
|
|
11
|
+
archivedAt?: string | null;
|
|
13
12
|
updatedAt?: string;
|
|
14
13
|
requiresAttention?: boolean;
|
|
15
14
|
attentionReason?: string | null;
|
|
@@ -33,67 +32,13 @@ export function resolveParentAgentId(agent: HostAgentEntry["agent"]): string | n
|
|
|
33
32
|
return typeof legacy === "string" && legacy.trim() ? legacy.trim() : null;
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
type HostAgentsApi = {
|
|
37
|
-
agents: {
|
|
38
|
-
subscribe?: (handler: (update: HostAgentUpdate) => void) => () => void;
|
|
39
|
-
list: (options: {
|
|
40
|
-
filter?: { includeArchived?: boolean; projectKeys?: string[] };
|
|
41
|
-
page?: { limit: number; cursor?: string };
|
|
42
|
-
}) => Promise<{
|
|
43
|
-
entries: ReadonlyArray<HostAgentEntry>;
|
|
44
|
-
pageInfo: { hasMore: boolean; nextCursor: string | null };
|
|
45
|
-
}>;
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Fetch project agents then enforce workspace scope. In daemon 0.8,
|
|
51
|
-
* ProjectPlacement.projectKey is projectId; the project catalog's repository
|
|
52
|
-
* key is a different identifier and produces an empty agent directory.
|
|
53
|
-
*/
|
|
54
|
-
export async function loadWorkspaceAgentStatuses(
|
|
55
|
-
paseo: HostAgentsApi,
|
|
56
|
-
workspaceId: string,
|
|
57
|
-
projectId?: string | null,
|
|
58
|
-
): Promise<Record<string, AgentStatusInfo>> {
|
|
59
|
-
const pending: HostAgentUpdate[] = [];
|
|
60
|
-
const unsubscribe = paseo.agents.subscribe?.((update) => pending.push(update));
|
|
61
|
-
try {
|
|
62
|
-
const entries = await listAllAgentPages(
|
|
63
|
-
async (cursor) => {
|
|
64
|
-
const result = await paseo.agents.list({
|
|
65
|
-
filter: { includeArchived: true, ...(projectId ? { projectKeys: [projectId] } : {}) },
|
|
66
|
-
page: { limit: HOST_AGENT_PAGE_LIMIT, ...(cursor ? { cursor } : {}) },
|
|
67
|
-
});
|
|
68
|
-
return { entries: result.entries, pageInfo: result.pageInfo };
|
|
69
|
-
},
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
const map: Record<string, AgentStatusInfo> = {};
|
|
73
|
-
for (const entry of entries) {
|
|
74
|
-
const agent = entry.agent;
|
|
75
|
-
if (agent.workspaceId !== workspaceId) continue;
|
|
76
|
-
map[agent.id] = agentStatusInfo(agent);
|
|
77
|
-
}
|
|
78
|
-
for (const update of pending) applyAgentStatusUpdate(map, workspaceId, update);
|
|
79
|
-
return map;
|
|
80
|
-
} finally {
|
|
81
|
-
unsubscribe?.();
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
35
|
export function applyAgentStatusUpdate(
|
|
86
36
|
map: Record<string, AgentStatusInfo>, workspaceId: string, update: HostAgentUpdate,
|
|
87
37
|
): void {
|
|
88
38
|
const id = update.kind === "remove" ? update.agentId : update.agent.id;
|
|
89
39
|
if (update.kind === "remove") {
|
|
90
|
-
//
|
|
91
|
-
|
|
92
|
-
if (!previous) return;
|
|
93
|
-
map[id] = agentStatusInfo(
|
|
94
|
-
{ id, workspaceId, status: "closed", updatedAt: previous.updatedAt ?? undefined },
|
|
95
|
-
previous,
|
|
96
|
-
);
|
|
40
|
+
// Removal is directory membership, not Closed or Archived.
|
|
41
|
+
delete map[id];
|
|
97
42
|
return;
|
|
98
43
|
}
|
|
99
44
|
const agentWorkspaceId = update.agent.workspaceId;
|
|
@@ -130,6 +75,7 @@ export function agentStatusInfo(
|
|
|
130
75
|
? resolveParentAgentId(agent)
|
|
131
76
|
: (previous?.parentAgentId ?? null);
|
|
132
77
|
return {
|
|
78
|
+
archivedAt: agent.archivedAt !== undefined ? agent.archivedAt : previous?.archivedAt,
|
|
133
79
|
rank: attentionRank({
|
|
134
80
|
status: agent.status,
|
|
135
81
|
requiresAttention,
|