@gpambrozio/paseo-herald 0.5.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 +40 -0
- package/README.md +8 -5
- package/client/agents.ts +85 -0
- package/client/announcer.ts +3 -2
- package/client/herald.tsx +69 -236
- package/client/rows.ts +165 -0
- package/client/screen.ts +32 -0
- package/client/sidebar.tsx +146 -0
- package/client/waiting.ts +109 -0
- package/index.client.tsx +11 -11
- package/index.server.ts +4 -3
- package/package.json +5 -4
- package/paseo-plugin.json +1 -1
- package/server/cleanup.ts +15 -5
- package/server/config.ts +4 -12
- package/server/data-dir.ts +153 -0
package/client/rows.ts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who is waiting, as rows: Paseo's attention list joined with Herald's
|
|
3
|
+
* entries, and how a row is named and drawn. Pure — the screen, the sidebar
|
|
4
|
+
* row's badge and its popover all read the same join, so they cannot disagree
|
|
5
|
+
* about the count.
|
|
6
|
+
*/
|
|
7
|
+
import type { PluginTheme } from "@getpaseo/plugin";
|
|
8
|
+
|
|
9
|
+
import type { AttentionEntry, AttentionReason } from "../shared/herald";
|
|
10
|
+
|
|
11
|
+
/** A row's reason: one of Herald's, or "attention" when only Paseo's flag is known. */
|
|
12
|
+
export type RowReason = AttentionReason | "attention";
|
|
13
|
+
|
|
14
|
+
export interface Row {
|
|
15
|
+
agentId: string;
|
|
16
|
+
title: string | null;
|
|
17
|
+
workspaceId: string | null;
|
|
18
|
+
cwd: string;
|
|
19
|
+
reason: RowReason;
|
|
20
|
+
/** ISO time the row sorts by: the event, or when Paseo flagged the agent. */
|
|
21
|
+
at: string;
|
|
22
|
+
entry: AttentionEntry | null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The fields the join reads off a Paseo agent snapshot. */
|
|
26
|
+
export interface FlaggedAgent {
|
|
27
|
+
id: string;
|
|
28
|
+
title: string | null;
|
|
29
|
+
workspaceId: string | null;
|
|
30
|
+
cwd: string;
|
|
31
|
+
status: string;
|
|
32
|
+
attentionReason: "finished" | "error" | "permission" | null;
|
|
33
|
+
at: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A Paseo-flagged agent worth a row: one whose session is still open. Paseo
|
|
38
|
+
* keeps an agent flagged until the user's next message, however long ago the
|
|
39
|
+
* turn ended, and that is right — a question asked a week ago is still
|
|
40
|
+
* unanswered. A *closed* session is not waiting on anyone until it is opened
|
|
41
|
+
* again, and a turn reported as finished on an agent that is *running* was
|
|
42
|
+
* not the end of anything — some providers say a turn is done and carry on.
|
|
43
|
+
* Those two are the cases dropped here.
|
|
44
|
+
*/
|
|
45
|
+
function isCurrent(agent: FlaggedAgent): boolean {
|
|
46
|
+
if (agent.status === "closed") return false;
|
|
47
|
+
if (agent.attentionReason === "finished" && agent.status === "running") return false;
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Herald's entries win over Paseo's flags for the same agent, since they carry
|
|
53
|
+
* the reason and the sentence. A *finished* entry on an agent that is working
|
|
54
|
+
* again is already withheld by the daemon, which knows each entry's agent
|
|
55
|
+
* without having to enumerate every running one — see `Liveness`.
|
|
56
|
+
*/
|
|
57
|
+
export function joinRows(entries: AttentionEntry[], flagged: FlaggedAgent[]): Row[] {
|
|
58
|
+
const byAgent = new Map<string, Row>();
|
|
59
|
+
entries.forEach((entry) => {
|
|
60
|
+
byAgent.set(entry.agentId, {
|
|
61
|
+
agentId: entry.agentId,
|
|
62
|
+
title: entry.agentTitle,
|
|
63
|
+
workspaceId: entry.workspaceId,
|
|
64
|
+
cwd: entry.cwd,
|
|
65
|
+
reason: entry.reason,
|
|
66
|
+
at: entry.createdAt,
|
|
67
|
+
entry,
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
flagged.forEach((agent) => {
|
|
71
|
+
if (byAgent.has(agent.id) || !isCurrent(agent)) return;
|
|
72
|
+
byAgent.set(agent.id, {
|
|
73
|
+
agentId: agent.id,
|
|
74
|
+
title: agent.title,
|
|
75
|
+
workspaceId: agent.workspaceId,
|
|
76
|
+
cwd: agent.cwd,
|
|
77
|
+
reason: agent.attentionReason ?? "attention",
|
|
78
|
+
at: agent.at,
|
|
79
|
+
entry: null,
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
return [...byAgent.values()].sort((a, b) => b.at.localeCompare(a.at));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function basename(path: string): string {
|
|
86
|
+
const parts = path.split("/").filter((part) => part !== "");
|
|
87
|
+
return parts[parts.length - 1] ?? path;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Agents are usually untitled; the workspace names the work. Paseo's current
|
|
92
|
+
* workspace title first, then the one Herald stored with the entry, then the
|
|
93
|
+
* folder.
|
|
94
|
+
*/
|
|
95
|
+
export function rowTitle(row: Row, workspaceNames: Record<string, string>): string {
|
|
96
|
+
const live = row.workspaceId === null ? undefined : workspaceNames[row.workspaceId];
|
|
97
|
+
return live ?? row.entry?.workspaceTitle ?? basename(row.cwd);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The line under the title: the agent's own title or, failing that, what it
|
|
102
|
+
* was last asked — which is what tells two untitled agents in one workspace
|
|
103
|
+
* apart.
|
|
104
|
+
*/
|
|
105
|
+
export function rowSubtitle(row: Row): string | null {
|
|
106
|
+
return row.title?.trim() || row.entry?.lastRequest || null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface ReasonLook {
|
|
110
|
+
icon: string;
|
|
111
|
+
label: string;
|
|
112
|
+
tone: "accent" | "success" | "warning" | "danger" | "muted";
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function lookOf(reason: RowReason): ReasonLook {
|
|
116
|
+
switch (reason) {
|
|
117
|
+
case "question":
|
|
118
|
+
return { icon: "MessageCircle", label: "Question", tone: "accent" };
|
|
119
|
+
case "plan":
|
|
120
|
+
return { icon: "ClipboardList", label: "Plan to approve", tone: "accent" };
|
|
121
|
+
case "permission":
|
|
122
|
+
return { icon: "Shield", label: "Permission", tone: "warning" };
|
|
123
|
+
case "finished":
|
|
124
|
+
return { icon: "Check", label: "Finished", tone: "success" };
|
|
125
|
+
case "error":
|
|
126
|
+
return { icon: "X", label: "Error", tone: "danger" };
|
|
127
|
+
case "canceled":
|
|
128
|
+
return { icon: "Ban", label: "Interrupted", tone: "muted" };
|
|
129
|
+
case "attention":
|
|
130
|
+
return { icon: "Megaphone", label: "Needs you", tone: "accent" };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function toneColor(theme: PluginTheme, tone: ReasonLook["tone"]): string {
|
|
135
|
+
const { colors } = theme;
|
|
136
|
+
switch (tone) {
|
|
137
|
+
case "accent":
|
|
138
|
+
return colors.accent;
|
|
139
|
+
case "success":
|
|
140
|
+
return colors.statusSuccess;
|
|
141
|
+
case "warning":
|
|
142
|
+
return colors.statusWarning;
|
|
143
|
+
case "danger":
|
|
144
|
+
return colors.statusDanger;
|
|
145
|
+
case "muted":
|
|
146
|
+
return colors.foregroundMuted;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** `color` at `alpha` (two hex digits), or `fallback` when `color` is not `#rrggbb`. */
|
|
151
|
+
export function withAlpha(color: string, alpha: string, fallback = color): string {
|
|
152
|
+
return /^#[0-9a-fA-F]{6}$/.test(color) ? `${color}${alpha}` : fallback;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function relativeTime(iso: string, now = Date.now()): string {
|
|
156
|
+
const seconds = Math.round((now - new Date(iso).getTime()) / 1000);
|
|
157
|
+
if (!Number.isFinite(seconds)) return "";
|
|
158
|
+
if (seconds < 45) return "just now";
|
|
159
|
+
const minutes = Math.round(seconds / 60);
|
|
160
|
+
if (minutes < 60) return `${minutes} min ago`;
|
|
161
|
+
const hours = Math.round(minutes / 60);
|
|
162
|
+
if (hours < 24) return `${hours} h ago`;
|
|
163
|
+
const days = Math.round(hours / 24);
|
|
164
|
+
return days === 1 ? "yesterday" : `${days} days ago`;
|
|
165
|
+
}
|
package/client/screen.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Herald screen's id and its one param. Pure.
|
|
3
|
+
*
|
|
4
|
+
* The id is the sidebar item's too, and is not a free choice: Settings ›
|
|
5
|
+
* Sidebar keys its ordering and hidden state on the item id, and a saved
|
|
6
|
+
* `/plugin/herald/sidebar/herald` link resolves to the screen of the same id,
|
|
7
|
+
* so renaming either loses both.
|
|
8
|
+
*/
|
|
9
|
+
import type { PluginOpenScreenInput, PluginScreenParams } from "@getpaseo/plugin/client";
|
|
10
|
+
|
|
11
|
+
export const HERALD_SCREEN_ID = "herald";
|
|
12
|
+
export const HERALD_TITLE = "Herald";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The screen param naming the agent to bring into view, set by the sidebar
|
|
16
|
+
* popover. A param rather than component state so it lives in the screen's URL.
|
|
17
|
+
*/
|
|
18
|
+
export const AGENT_PARAM = "agent";
|
|
19
|
+
|
|
20
|
+
/** The agent the screen's params ask it to focus, or null. */
|
|
21
|
+
export function focusedAgentId(params: PluginScreenParams): string | null {
|
|
22
|
+
const value = params[AGENT_PARAM];
|
|
23
|
+
return value === undefined || value === "" ? null : value;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Opens the Herald screen, focused on `agentId` when one is given. */
|
|
27
|
+
export function heraldScreenInput(agentId: string | null = null): PluginOpenScreenInput {
|
|
28
|
+
return {
|
|
29
|
+
screenId: HERALD_SCREEN_ID,
|
|
30
|
+
params: agentId === null ? {} : { [AGENT_PARAM]: agentId },
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Herald's row in the sidebar header, and the popover behind its badge.
|
|
3
|
+
*
|
|
4
|
+
* The row opens the Herald screen, as it always has. While anyone is waiting
|
|
5
|
+
* it carries a count, and the count is a button of its own — `SidebarRow`
|
|
6
|
+
* draws `trailing` beside the row's pressable — that opens a list of who is
|
|
7
|
+
* waiting; picking one opens the screen focused on that agent. The popover is
|
|
8
|
+
* given no `navigation`, so it cannot open the agent itself.
|
|
9
|
+
*
|
|
10
|
+
* The count is the screen's own join (`client/waiting.ts`), so the two never
|
|
11
|
+
* disagree, and with both on show they poll once between them.
|
|
12
|
+
*/
|
|
13
|
+
import type { PluginPopoverProps, PluginSidebarItemProps } from "@getpaseo/plugin/client";
|
|
14
|
+
import { Icon } from "@getpaseo/plugin/client/react-native";
|
|
15
|
+
import { SidebarRow } from "@getpaseo/plugin/client/ui";
|
|
16
|
+
import { useMemo } from "react";
|
|
17
|
+
import { Pressable, Text, View } from "react-native";
|
|
18
|
+
|
|
19
|
+
import { lookOf, relativeTime, rowSubtitle, rowTitle, toneColor, withAlpha } from "./rows";
|
|
20
|
+
import { HERALD_SCREEN_ID, heraldScreenInput } from "./screen";
|
|
21
|
+
import { useWaiting, useWaitingNudges } from "./waiting";
|
|
22
|
+
|
|
23
|
+
function waitingLabel(count: number): string {
|
|
24
|
+
return `${count} ${count === 1 ? "agent" : "agents"} waiting for you`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function HeraldSidebarItem({ theme, currentScreen, openScreen, openPopover }: PluginSidebarItemProps) {
|
|
28
|
+
const waiting = useWaiting();
|
|
29
|
+
useWaitingNudges();
|
|
30
|
+
const count = waiting.data?.rows.length ?? 0;
|
|
31
|
+
|
|
32
|
+
const styles = useMemo(() => {
|
|
33
|
+
const warning = theme.colors.statusWarning;
|
|
34
|
+
return {
|
|
35
|
+
badge: {
|
|
36
|
+
minWidth: 18,
|
|
37
|
+
paddingHorizontal: 5,
|
|
38
|
+
paddingVertical: 1,
|
|
39
|
+
borderRadius: 9,
|
|
40
|
+
alignItems: "center" as const,
|
|
41
|
+
backgroundColor: withAlpha(warning, "26", theme.colors.surface2),
|
|
42
|
+
},
|
|
43
|
+
badgeText: { color: warning, fontSize: 11, fontWeight: "600" as const },
|
|
44
|
+
};
|
|
45
|
+
}, [theme]);
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<SidebarRow
|
|
49
|
+
icon="Megaphone"
|
|
50
|
+
active={currentScreen?.screenId === HERALD_SCREEN_ID}
|
|
51
|
+
trailing={
|
|
52
|
+
count === 0 ? undefined : (
|
|
53
|
+
<Pressable
|
|
54
|
+
accessibilityRole="button"
|
|
55
|
+
accessibilityLabel={`${waitingLabel(count)}. Show them`}
|
|
56
|
+
hitSlop={6}
|
|
57
|
+
onPress={() => openPopover(WaitingPopover)}
|
|
58
|
+
style={styles.badge}
|
|
59
|
+
>
|
|
60
|
+
<Text style={styles.badgeText}>{count}</Text>
|
|
61
|
+
</Pressable>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
onPress={() => openScreen(heraldScreenInput())}
|
|
65
|
+
/>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Who is waiting, newest first; a press opens the Herald screen on that agent. */
|
|
70
|
+
function WaitingPopover({ theme, openScreen }: PluginPopoverProps) {
|
|
71
|
+
const waiting = useWaiting();
|
|
72
|
+
const rows = waiting.data?.rows ?? [];
|
|
73
|
+
const workspaceNames = waiting.data?.workspaceNames ?? {};
|
|
74
|
+
|
|
75
|
+
const styles = useMemo(() => {
|
|
76
|
+
const { colors } = theme;
|
|
77
|
+
return {
|
|
78
|
+
heading: { color: colors.foregroundMuted, fontSize: 12, fontWeight: "600" as const },
|
|
79
|
+
row: {
|
|
80
|
+
flexDirection: "row" as const,
|
|
81
|
+
alignItems: "center" as const,
|
|
82
|
+
gap: 10,
|
|
83
|
+
paddingHorizontal: 8,
|
|
84
|
+
paddingVertical: 6,
|
|
85
|
+
borderRadius: 6,
|
|
86
|
+
},
|
|
87
|
+
rowPressed: { backgroundColor: colors.surface2 },
|
|
88
|
+
rowText: { flex: 1, gap: 1 },
|
|
89
|
+
title: { color: colors.foreground, fontSize: 13, fontWeight: "600" as const },
|
|
90
|
+
meta: { color: colors.foregroundMuted, fontSize: 12 },
|
|
91
|
+
empty: { color: colors.foregroundMuted, fontSize: 13, paddingHorizontal: 8, paddingVertical: 6 },
|
|
92
|
+
footer: {
|
|
93
|
+
flexDirection: "row" as const,
|
|
94
|
+
alignItems: "center" as const,
|
|
95
|
+
gap: 8,
|
|
96
|
+
paddingHorizontal: 8,
|
|
97
|
+
paddingVertical: 6,
|
|
98
|
+
marginTop: 4,
|
|
99
|
+
borderTopWidth: 1,
|
|
100
|
+
borderTopColor: colors.border,
|
|
101
|
+
},
|
|
102
|
+
footerText: { color: colors.accent, fontSize: 13 },
|
|
103
|
+
};
|
|
104
|
+
}, [theme]);
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<View style={{ gap: 2 }}>
|
|
108
|
+
<Text style={styles.heading}>{rows.length === 0 ? "Herald" : waitingLabel(rows.length)}</Text>
|
|
109
|
+
{rows.length === 0 ? <Text style={styles.empty}>Nothing needs you right now.</Text> : null}
|
|
110
|
+
{rows.map((row) => {
|
|
111
|
+
const look = lookOf(row.reason);
|
|
112
|
+
const color = toneColor(theme, look.tone);
|
|
113
|
+
const title = rowTitle(row, workspaceNames);
|
|
114
|
+
const subtitle = rowSubtitle(row);
|
|
115
|
+
return (
|
|
116
|
+
<Pressable
|
|
117
|
+
key={row.agentId}
|
|
118
|
+
accessibilityRole="button"
|
|
119
|
+
accessibilityLabel={`${look.label}: ${title}`}
|
|
120
|
+
onPress={() => openScreen(heraldScreenInput(row.agentId))}
|
|
121
|
+
style={({ pressed }) => [styles.row, pressed ? styles.rowPressed : null]}
|
|
122
|
+
>
|
|
123
|
+
<Icon name={look.icon} size={14} color={color} />
|
|
124
|
+
<View style={styles.rowText}>
|
|
125
|
+
<Text style={styles.title} numberOfLines={1}>
|
|
126
|
+
{title}
|
|
127
|
+
</Text>
|
|
128
|
+
<Text style={styles.meta} numberOfLines={1}>
|
|
129
|
+
{subtitle === null ? look.label : `${look.label} · ${subtitle}`}
|
|
130
|
+
</Text>
|
|
131
|
+
</View>
|
|
132
|
+
<Text style={styles.meta}>{relativeTime(row.at)}</Text>
|
|
133
|
+
</Pressable>
|
|
134
|
+
);
|
|
135
|
+
})}
|
|
136
|
+
<Pressable
|
|
137
|
+
accessibilityRole="button"
|
|
138
|
+
onPress={() => openScreen(heraldScreenInput())}
|
|
139
|
+
style={({ pressed }) => [styles.footer, pressed ? styles.rowPressed : null]}
|
|
140
|
+
>
|
|
141
|
+
<Icon name="Megaphone" size={14} color={theme.colors.accent} />
|
|
142
|
+
<Text style={styles.footerText}>Open Herald</Text>
|
|
143
|
+
</Pressable>
|
|
144
|
+
</View>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The waiting list, loaded once for everything that draws it: the screen, the
|
|
3
|
+
* sidebar row's badge and the row's popover. One query key, so with the
|
|
4
|
+
* screen open beside the sidebar they poll once between them.
|
|
5
|
+
*
|
|
6
|
+
* Async **function expressions**, never async arrows, and no closure in a
|
|
7
|
+
* `for…of` body: the app `eval`s the client bundle, and Hermes's eval compiler
|
|
8
|
+
* on iOS and Android gets both wrong.
|
|
9
|
+
*/
|
|
10
|
+
import { usePaseo, useRpc } from "@getpaseo/plugin/client";
|
|
11
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
12
|
+
import { useEffect } from "react";
|
|
13
|
+
|
|
14
|
+
import { listAttention } from "../shared/herald";
|
|
15
|
+
import { watchAgents } from "./agents";
|
|
16
|
+
import { joinRows, type FlaggedAgent, type Row } from "./rows";
|
|
17
|
+
|
|
18
|
+
export interface Waiting {
|
|
19
|
+
rows: Row[];
|
|
20
|
+
/** Workspace id to its current title, for naming rows. */
|
|
21
|
+
workspaceNames: Record<string, string>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const WAITING_QUERY_KEY = ["herald", "waiting"] as const;
|
|
25
|
+
|
|
26
|
+
const IDLE_REFRESH_MS = 10_000;
|
|
27
|
+
const BUSY_REFRESH_MS = 2_500;
|
|
28
|
+
const NUDGE_DEBOUNCE_MS = 400;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The last list loaded, so a remount — the screen is unmounted whenever the
|
|
32
|
+
* user opens an agent from it — repaints before the first load answers.
|
|
33
|
+
*
|
|
34
|
+
* Workspace names come from the host API, not `useWorkspace`: the SDK's state
|
|
35
|
+
* hooks are for workspace and agent panels and throw in a screen or a sidebar
|
|
36
|
+
* item ("Plugin state hooks must run inside a workspace panel").
|
|
37
|
+
*/
|
|
38
|
+
let cachedWaiting: Waiting | null = null;
|
|
39
|
+
|
|
40
|
+
function hasPending(waiting: Waiting | undefined): boolean {
|
|
41
|
+
return waiting?.rows.some((row) => row.entry?.summary.status === "pending") ?? false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Paseo's attention flag decides who is listed — it is what the sidebar
|
|
46
|
+
* badges already follow — and Herald's entries explain why, in a sentence.
|
|
47
|
+
* Polled, and quickened while a summary is being written.
|
|
48
|
+
*/
|
|
49
|
+
export function useWaiting() {
|
|
50
|
+
const paseo = usePaseo();
|
|
51
|
+
const list = useRpc(listAttention);
|
|
52
|
+
return useQuery({
|
|
53
|
+
queryKey: WAITING_QUERY_KEY,
|
|
54
|
+
queryFn: async function loadWaiting(): Promise<Waiting> {
|
|
55
|
+
const [attention, flagged, workspaces] = await Promise.all([
|
|
56
|
+
list({}),
|
|
57
|
+
paseo.agents.list({ filter: { requiresAttention: true }, page: { limit: 100 } }),
|
|
58
|
+
paseo.workspaces.list({ page: { limit: 200 } }),
|
|
59
|
+
]);
|
|
60
|
+
const workspaceNames: Record<string, string> = {};
|
|
61
|
+
workspaces.entries.forEach((workspace) => {
|
|
62
|
+
workspaceNames[workspace.id] = workspace.title ?? workspace.name;
|
|
63
|
+
});
|
|
64
|
+
const agents: FlaggedAgent[] = flagged.entries.map((item) => ({
|
|
65
|
+
id: item.agent.id,
|
|
66
|
+
title: item.agent.title ?? null,
|
|
67
|
+
workspaceId: item.agent.workspaceId ?? null,
|
|
68
|
+
cwd: item.agent.cwd,
|
|
69
|
+
status: item.agent.status,
|
|
70
|
+
attentionReason: item.agent.attentionReason ?? null,
|
|
71
|
+
at: item.agent.attentionTimestamp ?? item.agent.updatedAt,
|
|
72
|
+
}));
|
|
73
|
+
const waiting = { rows: joinRows(attention.entries, agents), workspaceNames };
|
|
74
|
+
cachedWaiting = waiting;
|
|
75
|
+
return waiting;
|
|
76
|
+
},
|
|
77
|
+
refetchInterval: (query) => (hasPending(query.state.data) ? BUSY_REFRESH_MS : IDLE_REFRESH_MS),
|
|
78
|
+
...(cachedWaiting === null ? {} : { placeholderData: cachedWaiting }),
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Loads the list again within a moment of Paseo reporting any agent change,
|
|
84
|
+
* so a new arrival does not wait for the poll. Opens an agents observation —
|
|
85
|
+
* see `client/agents.ts` — and releases it on unmount.
|
|
86
|
+
*
|
|
87
|
+
* Kept apart from `useWaiting` so the popover, which lives only while it is
|
|
88
|
+
* open under a row that already listens, does not open a second one.
|
|
89
|
+
*/
|
|
90
|
+
export function useWaitingNudges(): void {
|
|
91
|
+
const paseo = usePaseo();
|
|
92
|
+
const queryClient = useQueryClient();
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
let debounce: ReturnType<typeof setTimeout> | null = null;
|
|
95
|
+
const unwatch = watchAgents(paseo, () => {
|
|
96
|
+
if (debounce !== null) clearTimeout(debounce);
|
|
97
|
+
debounce = setTimeout(() => {
|
|
98
|
+
debounce = null;
|
|
99
|
+
// `cancelRefetch: false` joins a load already in flight — the screen
|
|
100
|
+
// and the sidebar row both listen — rather than restarting it.
|
|
101
|
+
void queryClient.invalidateQueries({ queryKey: WAITING_QUERY_KEY }, { cancelRefetch: false });
|
|
102
|
+
}, NUDGE_DEBOUNCE_MS);
|
|
103
|
+
});
|
|
104
|
+
return () => {
|
|
105
|
+
if (debounce !== null) clearTimeout(debounce);
|
|
106
|
+
unwatch();
|
|
107
|
+
};
|
|
108
|
+
}, [paseo, queryClient]);
|
|
109
|
+
}
|
package/index.client.tsx
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { PluginClientContext } from "@getpaseo/plugin/client";
|
|
2
2
|
|
|
3
3
|
import { startAnnouncer } from "./client/announcer";
|
|
4
|
-
import {
|
|
4
|
+
import { HeraldScreen, bindSettingsOpener } from "./client/herald";
|
|
5
|
+
import { HERALD_SCREEN_ID, HERALD_TITLE, heraldScreenInput } from "./client/screen";
|
|
5
6
|
import { HeraldSettingsScreen } from "./client/settings-screen";
|
|
7
|
+
import { HeraldSidebarItem } from "./client/sidebar";
|
|
6
8
|
import { HeraldTimelineCard } from "./client/timeline-card";
|
|
7
9
|
import { HERALD_CARD_KIND, HERALD_CARD_VERSION, HeraldCardSchema } from "./shared/timeline";
|
|
8
10
|
|
|
@@ -11,8 +13,12 @@ export default function contribute(client: PluginClientContext) {
|
|
|
11
13
|
// what speaks. Everything below is how the user sees and tunes it.
|
|
12
14
|
const announcer = startAnnouncer(client);
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
//
|
|
16
|
+
// The screen and the sidebar row share the id the 0.10 sidebar item had, so
|
|
17
|
+
// Settings › Sidebar keeps the row's place and a saved
|
|
18
|
+
// `/plugin/herald/sidebar/herald` link still opens the screen.
|
|
19
|
+
client.addScreen({ id: HERALD_SCREEN_ID, title: HERALD_TITLE, Component: HeraldScreen });
|
|
20
|
+
client.addSidebarHeaderItem({ id: HERALD_SCREEN_ID, title: HERALD_TITLE, Component: HeraldSidebarItem });
|
|
21
|
+
// The screen's own settings button. A screen is given no way to open a
|
|
16
22
|
// settings screen, so the capability is lent to it from here.
|
|
17
23
|
bindSettingsOpener((id) => {
|
|
18
24
|
client.openSettings(id);
|
|
@@ -25,12 +31,6 @@ export default function contribute(client: PluginClientContext) {
|
|
|
25
31
|
schema: HeraldCardSchema,
|
|
26
32
|
Component: HeraldTimelineCard,
|
|
27
33
|
});
|
|
28
|
-
client.addSidebarItem({
|
|
29
|
-
id: "herald",
|
|
30
|
-
title: "Herald",
|
|
31
|
-
icon: "Megaphone",
|
|
32
|
-
surface: "herald",
|
|
33
|
-
});
|
|
34
34
|
client.addSettingsScreen({
|
|
35
35
|
id: "herald",
|
|
36
36
|
title: "Herald",
|
|
@@ -43,8 +43,8 @@ export default function contribute(client: PluginClientContext) {
|
|
|
43
43
|
icon: "Megaphone",
|
|
44
44
|
keywords: ["herald", "attention", "waiting", "needs you", "speak", "voice"],
|
|
45
45
|
context: "global",
|
|
46
|
-
onSelect({
|
|
47
|
-
|
|
46
|
+
onSelect({ openScreen }) {
|
|
47
|
+
openScreen(heraldScreenInput());
|
|
48
48
|
},
|
|
49
49
|
});
|
|
50
50
|
client.addCommandCenterItem({
|
package/index.server.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
1
|
|
|
3
2
|
import type { PluginServerContext } from "@getpaseo/plugin/server";
|
|
4
3
|
|
|
5
4
|
import { sweepHelpers } from "./server/cleanup";
|
|
6
|
-
import {
|
|
5
|
+
import { readHeraldConfig, writeHeraldConfig } from "./server/config";
|
|
6
|
+
import { dataPath, migrateLegacyData } from "./server/data-dir";
|
|
7
7
|
import { registerHooks } from "./server/hooks";
|
|
8
8
|
import { Liveness } from "./server/liveness";
|
|
9
9
|
import { listSayVoices, renderWithSay, sayAvailable } from "./server/say";
|
|
@@ -23,7 +23,8 @@ import { speechSettings } from "./shared/settings";
|
|
|
23
23
|
const SWEEP_DELAY_MS = 30_000;
|
|
24
24
|
|
|
25
25
|
export default function contribute(server: PluginServerContext) {
|
|
26
|
-
|
|
26
|
+
migrateLegacyData(["config.json", "attention.json"]);
|
|
27
|
+
const store = new AttentionStore(dataPath("attention.json"));
|
|
27
28
|
// Not awaited, because a contribution registers its handlers synchronously —
|
|
28
29
|
// it returns a cleanup, not a promise. Events therefore arrive *during* this
|
|
29
30
|
// read, so the store merges rather than overwrites: see `touched` there.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gpambrozio/paseo-herald",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Paseo plugin: speaks one sentence when an agent needs you, and lists everything waiting in a sidebar panel",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/gpambrozio/paseo-plugins/tree/main/herald",
|
|
@@ -29,9 +29,10 @@
|
|
|
29
29
|
"test": "vitest run --passWithNoTests"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@getpaseo/client": "0.
|
|
33
|
-
"@getpaseo/plugin": "0.
|
|
34
|
-
"@getpaseo/protocol": "0.
|
|
32
|
+
"@getpaseo/client": "0.11.0",
|
|
33
|
+
"@getpaseo/plugin": "0.11.0",
|
|
34
|
+
"@getpaseo/protocol": "0.11.0",
|
|
35
|
+
"@tanstack/react-query": "^5.104.1",
|
|
35
36
|
"@types/node": "^26.5.0",
|
|
36
37
|
"@types/react": "~19.2.0",
|
|
37
38
|
"react": "19.1.0",
|
package/paseo-plugin.json
CHANGED
package/server/cleanup.ts
CHANGED
|
@@ -20,7 +20,7 @@ import { access, constants } from "node:fs/promises";
|
|
|
20
20
|
import { homedir } from "node:os";
|
|
21
21
|
import { delimiter, join } from "node:path";
|
|
22
22
|
|
|
23
|
-
import { paseoHome } from "./
|
|
23
|
+
import { paseoHome } from "./data-dir";
|
|
24
24
|
|
|
25
25
|
/** Stamped on every helper at creation, and the only thing a sweep goes by. */
|
|
26
26
|
export const HELPER_LABEL_KEY = "herald.role";
|
|
@@ -49,10 +49,20 @@ export interface CliResult {
|
|
|
49
49
|
|
|
50
50
|
let cliLookup: Promise<string | null> | null = null;
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
/**
|
|
53
|
+
* The daemon hands its plugins `PASEO_CLI`, the CLI it shipped with, which is
|
|
54
|
+
* the one that surely speaks its protocol — an older standalone `paseo` first
|
|
55
|
+
* on `PATH` may not reach a password-protected daemon at all. `PATH` and the
|
|
56
|
+
* usual install directories are the fallback for a daemon that does not.
|
|
57
|
+
*/
|
|
58
|
+
export async function findCli(env: NodeJS.ProcessEnv = process.env): Promise<string | null> {
|
|
59
|
+
const onPath = (env.PATH ?? "").split(delimiter).filter((dir) => dir !== "");
|
|
60
|
+
const shipped = env.PASEO_CLI?.trim();
|
|
61
|
+
const candidates = [
|
|
62
|
+
...(shipped === undefined || shipped === "" ? [] : [shipped]),
|
|
63
|
+
...[...onPath, join(homedir(), ".local", "bin"), ...EXTRA_CLI_DIRS].map((dir) => join(dir, "paseo")),
|
|
64
|
+
];
|
|
65
|
+
for (const candidate of candidates) {
|
|
56
66
|
try {
|
|
57
67
|
await access(candidate, constants.X_OK);
|
|
58
68
|
return candidate;
|
package/server/config.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The daemon's own file: `$PASEO_HOME/
|
|
2
|
+
* The daemon's own file: `$PASEO_HOME/plugin-data/herald/config.json`. It holds
|
|
3
3
|
* what the hooks act on — which events get a summary and which model writes
|
|
4
4
|
* it — and nothing the app only draws.
|
|
5
5
|
*
|
|
@@ -7,21 +7,13 @@
|
|
|
7
7
|
* to take effect on the next event, and the file is a few hundred bytes.
|
|
8
8
|
*/
|
|
9
9
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
10
|
-
import {
|
|
11
|
-
import { dirname, join } from "node:path";
|
|
10
|
+
import { dirname } from "node:path";
|
|
12
11
|
|
|
13
12
|
import { DEFAULT_CONFIG, HeraldConfigSchema, type HeraldConfig } from "../shared/herald";
|
|
14
|
-
|
|
15
|
-
export function paseoHome(): string {
|
|
16
|
-
return process.env.PASEO_HOME ?? join(homedir(), ".paseo");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function pluginDir(): string {
|
|
20
|
-
return join(paseoHome(), "plugins", "herald");
|
|
21
|
-
}
|
|
13
|
+
import { dataPath } from "./data-dir";
|
|
22
14
|
|
|
23
15
|
function configPath(): string {
|
|
24
|
-
return
|
|
16
|
+
return dataPath("config.json");
|
|
25
17
|
}
|
|
26
18
|
|
|
27
19
|
/**
|