paseo-follow-up 2.7.0-beta.3 → 2.7.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/home-view.ts +30 -14
- package/client/live.tsx +35 -11
- package/index.server.ts +9 -2
- package/package.json +1 -1
- package/server/agent-parity.ts +1 -0
- package/server/feeds.ts +12 -10
- package/server/list-cache.ts +39 -7
- package/server/overseer-prompt-source.ts +1 -0
- package/server/overseer-prompt.md +1 -0
- package/shared/contracts.ts +14 -4
- package/shared/list.ts +79 -0
- package/shared/status-invariants.ts +23 -1
package/client/home-view.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { DispatchRecord } from "../shared/dispatch";
|
|
|
2
2
|
import { reportInstalledVersion } from "./install-scope";
|
|
3
3
|
import type { PluginClientContext } from "@getpaseo/plugin/client";
|
|
4
4
|
import type { ImageUpload } from "../shared/images";
|
|
5
|
-
import { contextAskRpc, contextListRpc, questionActionRpc, dispatchRecordsRpc, homeFeed, queueNeedsSchema, overseerAskRpc, overseerRestartRpc, overseerStartRpc, overseerStatusRpc, prioritiesRpc, prStatsSettingsRpc, rankNowRpc, rankStatusRpc, usageRpc } from "../shared/contracts";
|
|
5
|
+
import { agentTitlesRpc, contextAskRpc, contextListRpc, questionActionRpc, dispatchRecordsRpc, homeFeed, queueNeedsSchema, overseerAskRpc, overseerRestartRpc, overseerStartRpc, overseerStatusRpc, prioritiesRpc, prStatsSettingsRpc, rankNowRpc, rankStatusRpc, usageRpc } from "../shared/contracts";
|
|
6
6
|
import { openFeed } from "./feeds";
|
|
7
7
|
import { followDisplayDoc } from "./display";
|
|
8
8
|
import { sharedRead, USAGE_SHARED_MS } from "./shared-read";
|
|
@@ -41,6 +41,10 @@ const SIDEBAR_SORT_KEY = "follow-up.sidebar.sort";
|
|
|
41
41
|
/** This device's copy of the Display setting `home_view`, so the list opens arranged before the setting arrives. */
|
|
42
42
|
const VIEW_KEY = "follow-up.home.view";
|
|
43
43
|
const PRIORITY_POLL_MS = 60_000;
|
|
44
|
+
/** Home opens Paseo's agent subscription with this one-agent page (invariant 253); updates arrive for every agent. */
|
|
45
|
+
export const AGENT_FIRST_PAGE = 1;
|
|
46
|
+
/** follow.agent-titles before the worker's first directory read: asked again this often, at most this many times. */
|
|
47
|
+
const TITLES_RETRY_MS = 3_000, TITLES_RETRIES = 10;
|
|
44
48
|
|
|
45
49
|
/** Per-device storage where the host has it (web, desktop). Native or blocked storage: memory only. */
|
|
46
50
|
const storage = {
|
|
@@ -222,9 +226,12 @@ export function createHomeExtras(client: PluginClientContext) {
|
|
|
222
226
|
}).catch(() => undefined);
|
|
223
227
|
if (!home) void readDispatches();
|
|
224
228
|
|
|
229
|
+
/** Agents Paseo said are archived or removed: a titles read that answers after it doesn't bring them back. */
|
|
230
|
+
const gone = new Set<string>();
|
|
225
231
|
const putAgent = (a: AgentEntry["agent"]) => {
|
|
226
232
|
if (!a?.id) return;
|
|
227
|
-
if (a.archivedAt) { if (agents.delete(a.id)) emitSoon(); return; }
|
|
233
|
+
if (a.archivedAt) { gone.add(a.id); if (agents.delete(a.id)) emitSoon(); return; }
|
|
234
|
+
gone.delete(a.id);
|
|
228
235
|
const prior = agents.get(a.id);
|
|
229
236
|
const next = { id: a.id, title: a.title ?? null, workspaceId: a.workspaceId ?? null };
|
|
230
237
|
if (prior && prior.title === next.title && prior.workspaceId === next.workspaceId) return;
|
|
@@ -232,14 +239,17 @@ export function createHomeExtras(client: PluginClientContext) {
|
|
|
232
239
|
};
|
|
233
240
|
// Push for the inbox and live stores (1.4.0): an agent's status, attention or permissions changing is when Needs you
|
|
234
241
|
// and the pills can change, so those stores re-read then instead of polling every few seconds.
|
|
242
|
+
// a-change-sends-only-what-changed (invariant 253): this client no longer lists every agent at connect, so the first
|
|
243
|
+
// update it sees for an agent (one outside the first page, or new) counts as activity too: a permission request on
|
|
244
|
+
// an agent it never listed must reach Needs you. Only the first page's own entries are taken as the starting state.
|
|
235
245
|
const activity = new Set<() => void>();
|
|
236
246
|
const signatures = new Map<string, string>();
|
|
237
|
-
const noteActivity = (a: unknown) => {
|
|
247
|
+
const noteActivity = (a: unknown, listed = false) => {
|
|
238
248
|
const x = a as { id?: string; status?: string; requiresAttention?: boolean; attentionReason?: string | null; pendingPermissions?: unknown[]; archivedAt?: string | null } | undefined;
|
|
239
249
|
if (!x?.id) return;
|
|
240
250
|
const signature = [x.status, x.requiresAttention, x.attentionReason, x.pendingPermissions?.length ?? 0, x.archivedAt].join("|");
|
|
241
251
|
const prior = signatures.get(x.id); signatures.set(x.id, signature);
|
|
242
|
-
if (prior
|
|
252
|
+
if (prior === undefined ? !listed : prior !== signature) for (const l of activity) l();
|
|
243
253
|
};
|
|
244
254
|
// Per-agent listeners (the chat's created-agent cards): Paseo's own agent stream, so a card's state costs no RPC.
|
|
245
255
|
const agentWatchers = new Map<string, Set<(agent: unknown) => void>>();
|
|
@@ -247,23 +257,29 @@ export function createHomeExtras(client: PluginClientContext) {
|
|
|
247
257
|
const u = update as { kind: string; agent?: AgentEntry["agent"]; agentId?: string };
|
|
248
258
|
const watchers = agentWatchers.get(u.agent?.id ?? u.agentId ?? "");
|
|
249
259
|
if (watchers) for (const w of watchers) w(u.kind === "remove" ? null : u.agent);
|
|
250
|
-
if (u.kind === "remove") { if (u.agentId
|
|
260
|
+
if (u.kind === "remove") { if (u.agentId) { gone.add(u.agentId); if (agents.delete(u.agentId)) emitSoon(); signatures.delete(u.agentId); } for (const l of activity) l(); }
|
|
251
261
|
else { putAgent(u.agent); noteActivity(u.agent); }
|
|
252
262
|
});
|
|
253
263
|
let release: (() => Promise<void>) | null = null;
|
|
264
|
+
// The subscription only needs a page to open it: Paseo sends updates for every agent its filter matches, on that
|
|
265
|
+
// page or not. Every page of full agent snapshots at connect was megabytes on a big install, for titles only.
|
|
254
266
|
void (async () => {
|
|
255
|
-
const page = await client.paseo.agents.list({ subscribe: {}, page: { limit:
|
|
267
|
+
const page = await client.paseo.agents.list({ subscribe: {}, page: { limit: AGENT_FIRST_PAGE } });
|
|
256
268
|
if (stopped) { await page.subscription.release(); return; }
|
|
257
269
|
release = () => page.subscription.release();
|
|
258
|
-
(page.entries as AgentEntry[]).forEach(e => { putAgent(e.agent); noteActivity(e.agent); });
|
|
259
|
-
let cursor = page.pageInfo.nextCursor;
|
|
260
|
-
for (let i = 0; cursor && !stopped && i < 20; i++) {
|
|
261
|
-
const next = await client.paseo.agents.list({ page: { limit: 200, cursor } });
|
|
262
|
-
(next.entries as AgentEntry[]).forEach(e => { putAgent(e.agent); noteActivity(e.agent); });
|
|
263
|
-
if (next.pageInfo.nextCursor === cursor) break;
|
|
264
|
-
cursor = next.pageInfo.nextCursor;
|
|
265
|
-
}
|
|
270
|
+
(page.entries as AgentEntry[]).forEach(e => { putAgent(e.agent); noteActivity(e.agent, true); });
|
|
266
271
|
})().catch(() => undefined);
|
|
272
|
+
// Search's agent titles: one compact read from the worker. What Paseo's stream sent first wins.
|
|
273
|
+
// A worker that hasn't read its directory yet (just started) says so: ask again a few times, then Paseo's updates
|
|
274
|
+
// alone fill titles in.
|
|
275
|
+
const readTitles = (attempt: number): void => void client.rpc(agentTitlesRpc, {}).then(r => {
|
|
276
|
+
if (stopped) return;
|
|
277
|
+
let added = false;
|
|
278
|
+
for (const [id, title, workspaceId] of r.agents) if (!agents.has(id) && !gone.has(id)) { agents.set(id, { id, title, workspaceId }); added = true; }
|
|
279
|
+
if (added) emitSoon();
|
|
280
|
+
if (!r.ready && attempt < TITLES_RETRIES) { const t = setTimeout(() => { timers.delete(t); readTitles(attempt + 1); }, TITLES_RETRY_MS); timers.add(t); }
|
|
281
|
+
}).catch(() => undefined);
|
|
282
|
+
readTitles(0);
|
|
267
283
|
|
|
268
284
|
return {
|
|
269
285
|
subscribe(listener: () => void) { listeners.add(listener); return () => { listeners.delete(listener); }; },
|
package/client/live.tsx
CHANGED
|
@@ -6,7 +6,7 @@ import type { PluginButtonIconProps, PluginClientContext, PluginSidebarItemProps
|
|
|
6
6
|
import { Icon, SidebarRow } from "@getpaseo/plugin/client/ui";
|
|
7
7
|
import { listRpc, workspacesFeed } from "../shared/contracts";
|
|
8
8
|
import { openFeed, type Feed } from "./feeds";
|
|
9
|
-
import { isArchivedEntry, listEntry, listEntrySchema, splitReadStamps, withReadStamps, type ArchivedListWorkspace, type ListEntry, type ListWorkspace, type ReadStamps } from "../shared/list";
|
|
9
|
+
import { applyEntryPatch, isArchivedEntry, listEntry, listEntrySchema, splitReadStamps, withReadStamps, type ArchivedListWorkspace, type EntryPatch, type ListEntry, type ListWorkspace, type ReadStamps } from "../shared/list";
|
|
10
10
|
import type { Workspace } from "../shared/model";
|
|
11
11
|
import { activeNeeds, needsYou } from "../shared/attention";
|
|
12
12
|
import { useSidebarViewActive } from "./inbox";
|
|
@@ -82,33 +82,57 @@ export function createLiveStore(client: PluginClientContext) {
|
|
|
82
82
|
const kept = recallLastKnown("workspaces", z.array(listEntrySchema));
|
|
83
83
|
if (kept) hold(new Map(kept.map(w => [w.id, w])));
|
|
84
84
|
const offKeep = registerLastKnown("workspaces", () => all.size ? [...all.values()] : null);
|
|
85
|
-
|
|
85
|
+
/**
|
|
86
|
+
* a-change-sends-only-what-changed (invariant 253): each entry as the worker last sent it (bare, before stamps and
|
|
87
|
+
* before a newer whole read replaced it on screen) and the revision it arrived at. A patch applies to that copy only
|
|
88
|
+
* when its `from`..`to` range includes that revision; otherwise the store reads the list whole once.
|
|
89
|
+
*/
|
|
90
|
+
let bases = new Map<string, { entry: ListEntry; at: number }>();
|
|
91
|
+
let resyncing = false;
|
|
92
|
+
const resync = () => {
|
|
93
|
+
if (resyncing || stopped) return;
|
|
94
|
+
resyncing = true;
|
|
95
|
+
void client.rpc(listRpc, { patch: true }).then(r => { if (!stopped) apply(r); }).catch(() => undefined).finally(() => { resyncing = false; });
|
|
96
|
+
};
|
|
97
|
+
const apply = (result: { full?: boolean; workspaces: ListEntry[]; patches?: EntryPatch[]; removed?: string[]; revision?: number; reads?: Record<string, ReadStamps> }) => {
|
|
86
98
|
const diff = result.full === false;
|
|
87
99
|
const reads = result.reads ?? {};
|
|
88
|
-
|
|
100
|
+
const at = result.revision ?? 0;
|
|
101
|
+
if (diff && !result.workspaces.length && !result.patches?.length && !result.removed?.length && !Object.keys(reads).length) return;
|
|
89
102
|
const next = diff ? new Map(all) : new Map<string, ListEntry>();
|
|
90
|
-
if (!diff) stamps = new Map();
|
|
103
|
+
if (!diff) { stamps = new Map(); bases = new Map(); }
|
|
91
104
|
for (const [id, s] of Object.entries(reads)) stamps.set(id, s);
|
|
92
|
-
for (const id of result.removed ?? []) { next.delete(id); stamps.delete(id); }
|
|
93
|
-
|
|
105
|
+
for (const id of result.removed ?? []) { next.delete(id); stamps.delete(id); bases.delete(id); }
|
|
106
|
+
const sent: ListEntry[] = [];
|
|
107
|
+
for (const w of result.workspaces) { bases.set(w.id, { entry: w, at }); sent.push(w); }
|
|
108
|
+
let stale = false;
|
|
109
|
+
for (const p of result.patches ?? []) {
|
|
110
|
+
const base = bases.get(p.id);
|
|
111
|
+
if (!base || base.at < p.from || base.at >= p.to) { stale = true; continue; }
|
|
112
|
+
const parsed = listEntrySchema.safeParse(applyEntryPatch(base.entry, p));
|
|
113
|
+
if (!parsed.success) { stale = true; continue; }
|
|
114
|
+
bases.set(p.id, { entry: parsed.data, at }); sent.push(parsed.data);
|
|
115
|
+
}
|
|
116
|
+
for (const w of sent) { const filled = withReadStamps(w, stamps.get(w.id)); next.set(w.id, diff ? newer(all.get(w.id), filled) : filled); }
|
|
94
117
|
// Stamps alone: the held entry with its new stamps (a new object only for those workspaces).
|
|
95
|
-
const
|
|
96
|
-
for (const id of Object.keys(reads)) { const held = next.get(id); if (held && !
|
|
118
|
+
const ids = new Set(sent.map(w => w.id));
|
|
119
|
+
for (const id of Object.keys(reads)) { const held = next.get(id); if (held && !ids.has(id)) next.set(id, withReadStamps(held, stamps.get(id))); }
|
|
97
120
|
hold(next); revision = result.revision;
|
|
98
|
-
settle(
|
|
121
|
+
settle(sent);
|
|
99
122
|
emit();
|
|
123
|
+
if (stale) resync();
|
|
100
124
|
};
|
|
101
125
|
// Paseo 0.15: poll the revision diff. 0.16: the worker pushes the same diff (follow.workspaces-feed), and nothing polls.
|
|
102
126
|
const poll = async () => {
|
|
103
127
|
try {
|
|
104
|
-
const result = await client.rpc(listRpc, revision === undefined ? {} : { since: revision });
|
|
128
|
+
const result = await client.rpc(listRpc, revision === undefined ? { patch: true } : { since: revision, patch: true });
|
|
105
129
|
if (stopped || pushed()) return;
|
|
106
130
|
apply(result);
|
|
107
131
|
} catch { /* Keep the last answer through restarts and disconnects. */ }
|
|
108
132
|
finally { if (!stopped && !pushed()) { if (timer) clearTimeout(timer); timer = whileVisible(POLL_MS, () => void poll()); } }
|
|
109
133
|
};
|
|
110
134
|
// The feed went down (the worker restarted): read now and poll until it is back.
|
|
111
|
-
feed = openFeed(client, workspacesFeed, {}, { event: event => { if (!stopped) apply(event); }, down: () => { if (timer) clearTimeout(timer); void poll(); }, up: () => { if (timer) clearTimeout(timer); timer = null; } });
|
|
135
|
+
feed = openFeed(client, workspacesFeed, { patch: true }, { event: event => { if (!stopped) apply(event); }, down: () => { if (timer) clearTimeout(timer); void poll(); }, up: () => { if (timer) clearTimeout(timer); timer = null; } });
|
|
112
136
|
// The store keeps list forms only: a read's full workspace is projected (shared/list.ts listEntry) before it's held.
|
|
113
137
|
const accept = (w: Workspace) => {
|
|
114
138
|
const held = all.get(w.id);
|
package/index.server.ts
CHANGED
|
@@ -910,7 +910,7 @@ export default function contribute(server: PluginServerContext) {
|
|
|
910
910
|
const view = browserWorkspaces(entries.filter(e => e !== null));
|
|
911
911
|
return { tracked: true, ...view, workspaces: view.workspaces.map(w => ({ ...w, title: w.title.slice(0, 200), agentStatus: w.agentStatus.slice(0, 40), state: w.state.slice(0, 200) })) };
|
|
912
912
|
});
|
|
913
|
-
handle(rpc.listRpc, async ({ since }) => { if (waiting) return { workspaces: [], full: false, removed: [], error: waiting }; await ready; const { stampsOnly: _s, ...answer } = listCache.answer(await store.snapshot(), since); return { ...answer, error: loadError ?? hookError ?? writeHealth.message() ?? engine.error }; });
|
|
913
|
+
handle(rpc.listRpc, async ({ since, patch }) => { if (waiting) return { workspaces: [], full: false, removed: [], error: waiting }; await ready; const { stampsOnly: _s, ...answer } = listCache.answer(await store.snapshot(), since, { patch }); return { ...answer, error: loadError ?? hookError ?? writeHealth.message() ?? engine.error }; });
|
|
914
914
|
// Settled history is bounded (shared/history.ts boundHistory); the Activity card pages the rest with follow.activity.
|
|
915
915
|
handle(rpc.getRpc, async ({ workspaceId }) => { if (waiting) return { workspace: null, error: waiting }; await ready; const w = (await store.snapshot()).workspaces.find(w => w.id === workspaceId && w.enable_tracking); return { workspace: w ? boundHistory(w) : null, error: loadError ?? hookError ?? writeHealth.message() ?? engine.error }; });
|
|
916
916
|
handle(rpc.activityRpc, async ({ workspaceId, tab, query, offset, limit }) => {
|
|
@@ -2179,6 +2179,13 @@ export default function contribute(server: PluginServerContext) {
|
|
|
2179
2179
|
// The chat's created cards: the engine's directory snapshot as it stands (never waits on or asks the daemon, wakes
|
|
2180
2180
|
// nothing) and the store. Before the engine's first read the cards just show no state yet.
|
|
2181
2181
|
// The engine's snapshot as it stands, plus remembered archived agents; ids it lacks are looked up once, not awaited.
|
|
2182
|
+
// From the directory's rows as they stand (an-ack-never-waits: never a daemon read in the reply); before the first
|
|
2183
|
+
// read it starts one and says so, and the client asks again.
|
|
2184
|
+
handle(rpc.agentTitlesRpc, async () => {
|
|
2185
|
+
const rows = gateway.directory.snapshot();
|
|
2186
|
+
if (!rows) { void gateway.directory.read().catch(() => undefined); return { agents: [], ready: false }; }
|
|
2187
|
+
return { agents: rows.agents.filter(({ agent }) => !agent.archivedAt).map(({ agent }) => [agent.id, agent.title ?? null, agent.workspaceId ?? null] as [string, string | null, string | null]), ready: true };
|
|
2188
|
+
});
|
|
2182
2189
|
handle(rpc.createdItemsRpc, async input => { gateway.directory.lookup(input.agentIds); return createdItems(input, gateway.directory.snapshotFor(input.agentIds), (await store.snapshot()).workspaces); });
|
|
2183
2190
|
// The Report sheet: who it can send to (directory metadata only; nothing is loaded), Send to agent, Open on GitHub.
|
|
2184
2191
|
handle(rpc.reportTargetsRpc, async ({ workspaceId, agentId }, { paseo }) => {
|
|
@@ -2305,7 +2312,7 @@ export default function contribute(server: PluginServerContext) {
|
|
|
2305
2312
|
const serve = <I extends ZodType, E extends ZodType>(contract: PluginSubscriptionContract<I, E>, run: (input: zOutput<I>, push: (event: unknown) => Promise<void>, signal: AbortSignal) => void) => {
|
|
2306
2313
|
try { server.handle(contract, (input, context) => { run(input, context.push as (event: unknown) => Promise<void>, context.signal); }); } catch { /* A 0.15 host: no subscriptions. */ }
|
|
2307
2314
|
};
|
|
2308
|
-
serve(rpc.workspacesFeed, (input, push, signal) => workspacesFeed.serve(input.since, push, signal));
|
|
2315
|
+
serve(rpc.workspacesFeed, (input, push, signal) => workspacesFeed.serve(input.since, push, signal, { patch: input.patch }));
|
|
2309
2316
|
serve(rpc.inboxFeed, (_input, push, signal) => inboxFeed.serve(push, signal));
|
|
2310
2317
|
serve(rpc.homeFeed, (_input, push, signal) => homeFeed.serve(push, signal));
|
|
2311
2318
|
serve(rpc.displayFeed, (_input, push, signal) => displayFeed.serve(push, signal));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "paseo-follow-up",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "2.7.0-beta.
|
|
4
|
+
"version": "2.7.0-beta.5",
|
|
5
5
|
"description": "Every agent, one inbox. Follow-up brings what all your coding agents need from you into one ranked list, and follows their work through merge, deploy and after.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
package/server/agent-parity.ts
CHANGED
|
@@ -314,6 +314,7 @@ export const PARITY: Record<string, { tools: readonly string[]; note?: string }
|
|
|
314
314
|
"follow.dismiss-update-notice": { exempt: "Hides Home's update line for the person looking at it; updates_status already tells an agent what that line said." },
|
|
315
315
|
"follow.report-issue-targets": { tools: ["report_issue"], note: "The Report sheet's agent picker. An agent asked to report files it itself with report_issue; it has no one to hand the prompt to." },
|
|
316
316
|
"follow.report-issue-send": { tools: ["report_send", "report_issue"], note: "report_send hands a report to an agent, a new agent or a new workspace, as the sheet's Send does; an agent reporting for itself calls report_issue directly." },
|
|
317
|
+
"follow.agent-titles": { exempt: "Agent titles for Home's search, read-only; an agent lists agents with Paseo's own list_agents." },
|
|
317
318
|
"follow.created-items": { tools: ["workspace_status"], note: "Read-only live facts for the chat's created-agent / created-workspace cards; an agent reads them through workspace_status and Paseo's own list_agents." },
|
|
318
319
|
"follow.report-issue-link": { tools: ["report_issue"], note: "Open on GitHub with no agent to send to; report_issue's confirm returns the same prefilled link without GitHub auth." },
|
|
319
320
|
"follow.whats-new-seen": { exempt: "Records that a person closed What's new on a device; an agent reading the notes isn't someone seeing the sheet." },
|
package/server/feeds.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ListCache } from "./list-cache";
|
|
2
2
|
import type { State } from "../shared/model";
|
|
3
|
-
import { READS_PUSH_MS, type ListEntry, type ReadStamps } from "../shared/list";
|
|
3
|
+
import { READS_PUSH_MS, type EntryPatch, type ListEntry, type ReadStamps } from "../shared/list";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Pushes instead of client polling (Paseo 0.16 subscriptions, plan item 6). A feed is one shared serve per topic: a
|
|
@@ -54,7 +54,7 @@ export class ValueFeed<E> {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
export type WorkspacesEvent = { revision: number; full: boolean; workspaces: ListEntry[]; removed: string[]; reads: Record<string, ReadStamps>; error: string | null };
|
|
57
|
+
export type WorkspacesEvent = { revision: number; full: boolean; workspaces: ListEntry[]; patches?: EntryPatch[]; removed: string[]; reads: Record<string, ReadStamps>; error: string | null };
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* follow.list as a feed: each subscriber holds a revision, and a change sends it only the workspaces changed since,
|
|
@@ -69,7 +69,7 @@ export type WorkspacesEvent = { revision: number; full: boolean; workspaces: Lis
|
|
|
69
69
|
* of the workspace (invariant 150).
|
|
70
70
|
*/
|
|
71
71
|
export class WorkspacesFeed {
|
|
72
|
-
private subs = new Set<{ push: Push<WorkspacesEvent>; revision: number | undefined; error: string | null; readsAt: number }>();
|
|
72
|
+
private subs = new Set<{ push: Push<WorkspacesEvent>; revision: number | undefined; error: string | null; readsAt: number; patch: boolean }>();
|
|
73
73
|
private reading: Promise<void> | null = null;
|
|
74
74
|
private again = false;
|
|
75
75
|
/** The next pass sends held read stamps at once: a read the developer asked for (follow.refresh) shows when it lands. */
|
|
@@ -77,14 +77,15 @@ export class WorkspacesFeed {
|
|
|
77
77
|
constructor(private cache: ListCache, private state: () => Promise<State>, private error: () => string | null, private now: () => number = Date.now) {}
|
|
78
78
|
get size() { return this.subs.size; }
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
/** `patch`: the client applies changes inside an entry (invariant 253); an older client gets whole entries. */
|
|
81
|
+
serve(since: number | undefined, push: Push<WorkspacesEvent>, signal: AbortSignal, opts: { patch?: boolean } = {}): void {
|
|
81
82
|
if (signal.aborted) return;
|
|
82
|
-
const sub = { push, revision: since, error: null as string | null, readsAt: this.now() };
|
|
83
|
+
const sub = { push, revision: since, error: null as string | null, readsAt: this.now(), patch: !!opts.patch };
|
|
83
84
|
this.subs.add(sub);
|
|
84
85
|
signal.addEventListener("abort", () => { this.subs.delete(sub); }, { once: true });
|
|
85
86
|
void this.state().then(state => {
|
|
86
87
|
if (!this.subs.has(sub)) return;
|
|
87
|
-
const { stampsOnly: _s, ...answer } = this.cache.answer(state, sub.revision);
|
|
88
|
+
const { stampsOnly: _s, ...answer } = this.cache.answer(state, sub.revision, { patch: sub.patch });
|
|
88
89
|
sub.revision = answer.revision; sub.error = this.error();
|
|
89
90
|
return push({ ...answer, error: sub.error });
|
|
90
91
|
}).catch(() => undefined);
|
|
@@ -100,11 +101,12 @@ export class WorkspacesFeed {
|
|
|
100
101
|
const readsNow = this.readsNow; this.readsNow = false;
|
|
101
102
|
const state = await this.state();
|
|
102
103
|
const error = this.error();
|
|
103
|
-
const answers = new Map<
|
|
104
|
+
const answers = new Map<string, ReturnType<ListCache["answer"]>>();
|
|
104
105
|
await Promise.all([...this.subs].map(sub => {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
const key = `${sub.revision}:${sub.patch}`;
|
|
107
|
+
let answer = answers.get(key);
|
|
108
|
+
if (!answer) { answer = this.cache.answer(state, sub.revision, { patch: sub.patch }); answers.set(key, answer); }
|
|
109
|
+
const empty = !answer.full && !answer.workspaces.length && !answer.patches?.length && !answer.removed.length && !Object.keys(answer.reads).length;
|
|
108
110
|
if (empty && sub.error === error) { sub.revision = answer.revision; return undefined; }
|
|
109
111
|
// Only read stamps moved: hold them (keeping the revision) until the window is up.
|
|
110
112
|
if (answer.stampsOnly && !readsNow && sub.error === error && this.now() - sub.readsAt < READS_PUSH_MS) return undefined;
|
package/server/list-cache.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { State, Workspace } from "../shared/model";
|
|
2
|
-
import { listEntry, splitReadStamps, type ListEntry, type ReadStamps } from "../shared/list";
|
|
2
|
+
import { diffEntry, listEntry, splitReadStamps, type EntryPatch, type ListEntry, type ReadStamps } from "../shared/list";
|
|
3
|
+
|
|
4
|
+
/** A patch is sent instead of the whole entry only when it is at most this share of the entry's bytes. */
|
|
5
|
+
export const PATCH_MAX_SHARE = 0.5;
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
8
|
* Diffed answers for follow.list (1.3.0-beta.4). Clients send the revision they hold and get back only the
|
|
@@ -31,6 +34,13 @@ export class ListCache {
|
|
|
31
34
|
private current: ListEntry[] = [];
|
|
32
35
|
/** Each listed workspace's list form, as last projected from `objects`. */
|
|
33
36
|
private entries = new Map<string, ListEntry>();
|
|
37
|
+
/**
|
|
38
|
+
* a-change-sends-only-what-changed (invariant 253): each changed workspace's previous entry and the revision it
|
|
39
|
+
* became current at, so a client holding that version gets a patch (shared/list.ts diffEntry) instead of the whole
|
|
40
|
+
* entry. The patch is made once per change and shared by every client (`patchFor`).
|
|
41
|
+
*/
|
|
42
|
+
private prev = new Map<string, { entry: ListEntry; at: number }>();
|
|
43
|
+
private patches = new Map<string, EntryPatch | null>();
|
|
34
44
|
/** The oldest revision a diff can be computed from; older clients get the full list. */
|
|
35
45
|
private floor = this.revision;
|
|
36
46
|
constructor(private select: (state: State) => Workspace[] = state => state.workspaces.filter(w => w.enable_tracking)) {}
|
|
@@ -52,16 +62,22 @@ export class ListCache {
|
|
|
52
62
|
this.objects.set(w.id, w);
|
|
53
63
|
const { bare: entry, stamps } = splitReadStamps(listEntry(w));
|
|
54
64
|
const text = JSON.stringify(entry);
|
|
65
|
+
const before = this.entries.get(w.id);
|
|
55
66
|
this.entries.set(w.id, entry);
|
|
56
67
|
next.push(entry);
|
|
57
|
-
if (this.json.get(w.id) !== text) {
|
|
68
|
+
if (this.json.get(w.id) !== text) {
|
|
69
|
+
const at = this.changedAt.get(w.id);
|
|
70
|
+
if (before && at !== undefined && this.json.has(w.id)) this.prev.set(w.id, { entry: before, at }); else this.prev.delete(w.id);
|
|
71
|
+
this.patches.delete(w.id);
|
|
72
|
+
this.json.set(w.id, text); this.changedAt.set(w.id, revision); this.removedAt.delete(w.id); changed = true;
|
|
73
|
+
}
|
|
58
74
|
const stampText = stamps ? JSON.stringify(stamps) : "";
|
|
59
75
|
if ((this.stampJson.get(w.id) ?? "") !== stampText) {
|
|
60
76
|
this.stampJson.set(w.id, stampText); this.stampsAt.set(w.id, revision); changed = true;
|
|
61
77
|
if (stamps) this.stamps.set(w.id, stamps); else this.stamps.delete(w.id);
|
|
62
78
|
}
|
|
63
79
|
}
|
|
64
|
-
for (const id of [...this.json.keys()]) if (!seen.has(id)) { this.json.delete(id); this.objects.delete(id); this.entries.delete(id); this.changedAt.delete(id); this.stampJson.delete(id); this.stamps.delete(id); this.stampsAt.delete(id); this.removedAt.set(id, revision); changed = true; }
|
|
80
|
+
for (const id of [...this.json.keys()]) if (!seen.has(id)) { this.json.delete(id); this.objects.delete(id); this.entries.delete(id); this.changedAt.delete(id); this.stampJson.delete(id); this.stamps.delete(id); this.stampsAt.delete(id); this.prev.delete(id); this.patches.delete(id); this.removedAt.set(id, revision); changed = true; }
|
|
65
81
|
// Removal records are kept for a while so slow clients still learn about them; past that they resync fully.
|
|
66
82
|
if (this.removedAt.size > 500) { const cut = [...this.removedAt.values()].sort((a, b) => a - b)[this.removedAt.size - 500]; for (const [id, at] of this.removedAt) if (at < cut) this.removedAt.delete(id); this.floor = cut; }
|
|
67
83
|
this.current = next;
|
|
@@ -72,14 +88,30 @@ export class ListCache {
|
|
|
72
88
|
* stamps of every listed workspace (full) or of those whose stamps moved since (diff), whose entries the client
|
|
73
89
|
* fills them into. `stampsOnly`: a diff that carries nothing but stamps.
|
|
74
90
|
*/
|
|
75
|
-
answer(state: State, since?: number): { revision: number; full: boolean; workspaces: ListEntry[]; removed: string[]; reads: Record<string, ReadStamps>; stampsOnly: boolean } {
|
|
91
|
+
answer(state: State, since?: number, opts: { patch?: boolean } = {}): { revision: number; full: boolean; workspaces: ListEntry[]; patches?: EntryPatch[]; removed: string[]; reads: Record<string, ReadStamps>; stampsOnly: boolean } {
|
|
76
92
|
this.update(state);
|
|
77
93
|
if (since === undefined || since > this.revision || since < this.floor) return { revision: this.revision, full: true, workspaces: this.current, removed: [], reads: Object.fromEntries(this.stamps), stampsOnly: false };
|
|
78
|
-
const
|
|
94
|
+
const changed = this.current.filter(w => (this.changedAt.get(w.id) ?? 0) > since);
|
|
95
|
+
// A client that asks for patches and holds the previous version gets what moved inside it, not the whole entry.
|
|
96
|
+
const patches = opts.patch ? changed.flatMap(w => { const p = this.patchFor(w.id, since); return p ? [p] : []; }) : [];
|
|
97
|
+
const patched = new Set(patches.map(p => p.id));
|
|
98
|
+
const workspaces = patched.size ? changed.filter(w => !patched.has(w.id)) : changed;
|
|
79
99
|
const removed = [...this.removedAt].filter(([, at]) => at > since).map(([id]) => id);
|
|
80
|
-
// A
|
|
100
|
+
// A workspace sent whole carries its stamps too, so the client never holds a bare entry. A patched one keeps the
|
|
101
|
+
// stamps the client holds; they go only if they moved.
|
|
81
102
|
const ids = new Set(workspaces.map(w => w.id));
|
|
82
103
|
const reads = Object.fromEntries([...this.stamps].filter(([id]) => ids.has(id) || (this.stampsAt.get(id) ?? 0) > since));
|
|
83
|
-
return { revision: this.revision, full: false, workspaces, removed, reads, stampsOnly: !
|
|
104
|
+
return { revision: this.revision, full: false, workspaces, ...(opts.patch ? { patches } : {}), removed, reads, stampsOnly: !changed.length && !removed.length && Object.keys(reads).length > 0 };
|
|
105
|
+
}
|
|
106
|
+
/** The patch from the version a client held at `since` to the current one, or null (no such version kept, or the patch isn't smaller). */
|
|
107
|
+
private patchFor(id: string, since: number): EntryPatch | null {
|
|
108
|
+
const prev = this.prev.get(id); const to = this.changedAt.get(id);
|
|
109
|
+
if (!prev || to === undefined || since < prev.at || since >= to) return null;
|
|
110
|
+
if (!this.patches.has(id)) {
|
|
111
|
+
const body = diffEntry(prev.entry, this.entries.get(id)!);
|
|
112
|
+
const patch = body && { id, from: prev.at, to, ...body };
|
|
113
|
+
this.patches.set(id, patch && JSON.stringify(patch).length <= PATCH_MAX_SHARE * (this.json.get(id)?.length ?? 0) ? patch : null);
|
|
114
|
+
}
|
|
115
|
+
return this.patches.get(id) ?? null;
|
|
84
116
|
}
|
|
85
117
|
}
|
|
@@ -14,6 +14,7 @@ export const overseerPrompt: string = [
|
|
|
14
14
|
"5. Never merge, approve, close or archive anything, and never post to people (Slack, email, Linear, GitHub comments). Those stay the developer's. If they ask, tell them the agent that should do it or that it's their click.",
|
|
15
15
|
"6. Status questions (\"what's going on with SCIM?\", \"what needs me?\"): answer from the digest and the tools. Be specific: workspace, state, what it waits for.",
|
|
16
16
|
" - \"What should I work on first?\" or \"re-rank\": call `rerank`. It refreshes Home's Priority sort from Linear, Slack, review requests and the weekly plan, and returns the top 10 with reasons. Answer with the first two or three.",
|
|
17
|
+
" - \"When did we decide X?\" or \"where did we say Y?\": search past conversations with `transcript_search_conversations` (scope `host`, since your own workspace holds only your chats) and read around a hit with `transcript_read_conversation`; answer with the workspace and date. If those tools are missing, say Transcript Search isn't on.",
|
|
17
18
|
"7. Keep replies to the developer brief: one to three lines, no headers, no recap of the digest, and don't repeat their answer back to them. Name workspaces as Home shows them. Talk to the developer as \"you\".",
|
|
18
19
|
"8. Subagents: if you ever start one, start it in bypass permission mode (Claude `--mode bypassPermissions`, Codex `--mode full-access`) and tell it to do the same.",
|
|
19
20
|
"",
|
|
@@ -12,5 +12,6 @@ Rules:
|
|
|
12
12
|
5. Never merge, approve, close or archive anything, and never post to people (Slack, email, Linear, GitHub comments). Those stay the developer's. If they ask, tell them the agent that should do it or that it's their click.
|
|
13
13
|
6. Status questions ("what's going on with SCIM?", "what needs me?"): answer from the digest and the tools. Be specific: workspace, state, what it waits for.
|
|
14
14
|
- "What should I work on first?" or "re-rank": call `rerank`. It refreshes Home's Priority sort from Linear, Slack, review requests and the weekly plan, and returns the top 10 with reasons. Answer with the first two or three.
|
|
15
|
+
- "When did we decide X?" or "where did we say Y?": search past conversations with `transcript_search_conversations` (scope `host`, since your own workspace holds only your chats) and read around a hit with `transcript_read_conversation`; answer with the workspace and date. If those tools are missing, say Transcript Search isn't on.
|
|
15
16
|
7. Keep replies to the developer brief: one to three lines, no headers, no recap of the digest, and don't repeat their answer back to them. Name workspaces as Home shows them. Talk to the developer as "you".
|
|
16
17
|
8. Subagents: if you ever start one, start it in bypass permission mode (Claude `--mode bypassPermissions`, Codex `--mode full-access`) and tell it to do the same.
|
package/shared/contracts.ts
CHANGED
|
@@ -25,7 +25,7 @@ import { actionChangeSchema, dispatchActionSchema, dispatchInputSchema, dispatch
|
|
|
25
25
|
import { agentTreeNodeSchema, inboxRowSchema } from "./inbox";
|
|
26
26
|
import { briefSchema } from "./brief";
|
|
27
27
|
import { batchSchema, idSchema, prSchema, textSchema, workspaceSchema } from "./model";
|
|
28
|
-
import { listEntrySchema, readStampsSchema } from "./list";
|
|
28
|
+
import { entryPatchSchema, listEntrySchema, readStampsSchema } from "./list";
|
|
29
29
|
import { communicationSchema } from "./communication";
|
|
30
30
|
import { taskTriggerInputSchema } from "./task-trigger";
|
|
31
31
|
import { QUESTION_MODES, questionSchema } from "./questions";
|
|
@@ -51,7 +51,7 @@ const agentCommunicationSchema = z.strictObject({
|
|
|
51
51
|
* Tracked workspaces. 1.3.0-beta.4: pass the `revision` you hold as `since` to get only what changed (`full` false,
|
|
52
52
|
* plus `removed` ids). Without it, or when it's too old, the answer is the full list.
|
|
53
53
|
*/
|
|
54
|
-
export const listRpc = defineRpc({ name: "follow.list", input: z.object({ since: z.number().optional() }), output: z.object({ workspaces: z.array(listEntrySchema), error: z.string().nullable(), revision: z.number().optional(), full: z.boolean().optional(), removed: z.array(z.string()).optional(), reads: readStampsSchema.optional() }) });
|
|
54
|
+
export const listRpc = defineRpc({ name: "follow.list", input: z.object({ since: z.number().optional(), patch: z.boolean().optional() }), output: z.object({ workspaces: z.array(listEntrySchema), patches: z.array(entryPatchSchema).optional(), error: z.string().nullable(), revision: z.number().optional(), full: z.boolean().optional(), removed: z.array(z.string()).optional(), reads: readStampsSchema.optional() }) });
|
|
55
55
|
export const getRpc = defineRpc({ name: "follow.get", input: z.object({ workspaceId: idSchema }), output: z.object({ workspace: workspaceSchema.nullable(), error: z.string().nullable() }) });
|
|
56
56
|
const hitSchema = z.object({ ranges: z.array(z.array(z.tuple([z.number(), z.number()]))), via: z.object({ label: z.string(), text: z.string(), ranges: z.array(z.tuple([z.number(), z.number()])) }).nullable() }).nullable();
|
|
57
57
|
const activityRowSchema = z.object({ key: z.string(), at: z.string(), icon: z.string(), tone: z.enum(["merged", "success", "warning", "danger", "muted"]), text: z.string(), detail: z.string().nullable(), took: z.string().nullable() });
|
|
@@ -499,14 +499,24 @@ export const createdItemsRpc = defineRpc({ name: "follow.created-items",
|
|
|
499
499
|
workspaces: z.record(z.string(), z.object({ name: z.string().nullable(), follow: followLineSchema.nullable() })),
|
|
500
500
|
}) });
|
|
501
501
|
|
|
502
|
+
/**
|
|
503
|
+
* Every agent's title and workspace, for Home's search (a-change-sends-only-what-changed, invariant 253): one
|
|
504
|
+
* `[id, title, workspaceId]` row per agent from the worker's directory, instead of the client listing every page of
|
|
505
|
+
* Paseo's agent snapshots at connect. Paseo's agent subscription keeps the titles current after it.
|
|
506
|
+
*/
|
|
507
|
+
export const agentTitlesRpc = defineRpc({ name: "follow.agent-titles", input: z.object({}),
|
|
508
|
+
output: z.object({ agents: z.array(z.tuple([z.string(), z.string().nullable(), z.string().nullable()])),
|
|
509
|
+
/** False before the worker's first directory read (it answers from that cache, never waiting on Paseo): ask again soon. */
|
|
510
|
+
ready: z.boolean() }) });
|
|
511
|
+
|
|
502
512
|
/**
|
|
503
513
|
* Subscriptions (Paseo 0.16, `client.subscribe`): the polled reads above as pushes from the worker's own state
|
|
504
514
|
* (server/feeds.ts). Plain objects rather than `defineSubscription`, which a 0.15 host's SDK doesn't have; on 0.15 the
|
|
505
515
|
* client keeps polling the RPCs (`client/feeds.ts`). Each pushes its current value first, then only real changes.
|
|
506
516
|
*/
|
|
507
517
|
const subscription = <I extends z.ZodType, E extends z.ZodType>(name: string, input: I, event: E): PluginSubscriptionContract<I, E> => ({ name, input, event });
|
|
508
|
-
export const workspacesFeed = subscription("follow.workspaces-feed", z.object({ since: z.number().optional() }),
|
|
509
|
-
z.object({ revision: z.number(), full: z.boolean(), workspaces: z.array(listEntrySchema), removed: z.array(z.string()), reads: readStampsSchema.optional(), error: z.string().nullable() }));
|
|
518
|
+
export const workspacesFeed = subscription("follow.workspaces-feed", z.object({ since: z.number().optional(), patch: z.boolean().optional() }),
|
|
519
|
+
z.object({ revision: z.number(), full: z.boolean(), workspaces: z.array(listEntrySchema), patches: z.array(entryPatchSchema).optional(), removed: z.array(z.string()), reads: readStampsSchema.optional(), error: z.string().nullable() }));
|
|
510
520
|
export const inboxFeed = subscription("follow.inbox-feed", z.object({}), inboxListRpc.output);
|
|
511
521
|
/** Home's extras: priorities, the ranker, the Overseer and the usage meters (without the worker's live resources). */
|
|
512
522
|
export const homeFeed = subscription("follow.home-feed", z.object({}), z.object({
|
package/shared/list.ts
CHANGED
|
@@ -175,3 +175,82 @@ export function provisionalWorkspace(entry: ListWorkspace): Workspace {
|
|
|
175
175
|
questions: entry.questions.map(q => ({ ...q, background: q.background ?? null, links: q.links ?? [] })),
|
|
176
176
|
} satisfies Workspace;
|
|
177
177
|
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* A change inside one workspace, by item id (a-change-sends-only-what-changed, invariant 253). A busy workspace's list
|
|
181
|
+
* entry is large (its settled history, every merged PR's title), and before this a change to one of its tasks sent
|
|
182
|
+
* the whole entry again to every client: on a slow phone link the feed's pushes of one busy workspace were megabytes
|
|
183
|
+
* every few minutes. ListCache sends a client that asks for patches (`patch: true`) only what moved in an entry it
|
|
184
|
+
* already holds: changed top-level fields (`set`, `unset`) and, for each list of items with an id (`key` for PRs, `id`
|
|
185
|
+
* for tasks, batches, questions, PR actions), the items that changed or arrived (`items[field].set`), the ids that
|
|
186
|
+
* left (`drop`) and the order when it isn't the old order with new items appended (`order`).
|
|
187
|
+
*
|
|
188
|
+
* `from`..`to` is the revision range in which the client's copy is the base the patch was made from: the client
|
|
189
|
+
* applies it only when the revision it holds that entry at is in the range, and otherwise reads the list whole once
|
|
190
|
+
* (client/live.tsx). The result is exactly the entry a whole push would carry (tests/feed-patches.test.ts).
|
|
191
|
+
*/
|
|
192
|
+
const itemsPatchSchema = z.object({ set: z.array(z.record(z.string(), z.unknown())).optional(), drop: z.array(z.string()).optional(), order: z.array(z.string()).optional() });
|
|
193
|
+
export const entryPatchSchema = z.object({
|
|
194
|
+
id: z.string(), from: z.number(), to: z.number(),
|
|
195
|
+
set: z.record(z.string(), z.unknown()).optional(), unset: z.array(z.string()).optional(),
|
|
196
|
+
items: z.record(z.string(), itemsPatchSchema).optional(),
|
|
197
|
+
});
|
|
198
|
+
export type EntryPatch = z.infer<typeof entryPatchSchema>;
|
|
199
|
+
type Body = Omit<EntryPatch, "id" | "from" | "to">;
|
|
200
|
+
|
|
201
|
+
/** An item's id in a list the patch can address by id: a PR's `key`, everything else's `id`. */
|
|
202
|
+
const itemId = (x: unknown): string | null => {
|
|
203
|
+
if (!x || typeof x !== "object" || Array.isArray(x)) return null;
|
|
204
|
+
const o = x as { key?: unknown; id?: unknown };
|
|
205
|
+
return typeof o.key === "string" ? o.key : typeof o.id === "string" ? o.id : null;
|
|
206
|
+
};
|
|
207
|
+
/** The ids of a list whose every item has a distinct one, else null (such a list goes whole). */
|
|
208
|
+
const keyedIds = (value: unknown): string[] | null => {
|
|
209
|
+
if (!Array.isArray(value)) return null;
|
|
210
|
+
const ids = value.map(itemId);
|
|
211
|
+
if (ids.some(id => id === null) || new Set(ids).size !== ids.length) return null;
|
|
212
|
+
return ids as string[];
|
|
213
|
+
};
|
|
214
|
+
const same = (a: readonly string[], b: readonly string[]) => a.length === b.length && a.every((x, i) => x === b[i]);
|
|
215
|
+
|
|
216
|
+
/** What changed from `prev` to `next` (both list entries of one workspace); null when nothing did. Pure. */
|
|
217
|
+
export function diffEntry(prev: ListEntry, next: ListEntry): Body | null {
|
|
218
|
+
const a = prev as Record<string, unknown>, b = next as Record<string, unknown>;
|
|
219
|
+
const set: Record<string, unknown> = {}; const unset: string[] = []; const items: NonNullable<Body["items"]> = {};
|
|
220
|
+
for (const k of Object.keys(a)) if (b[k] === undefined && a[k] !== undefined) unset.push(k);
|
|
221
|
+
for (const [k, value] of Object.entries(b)) {
|
|
222
|
+
if (value === undefined) continue;
|
|
223
|
+
const was = a[k];
|
|
224
|
+
const before = keyedIds(was), after = keyedIds(value);
|
|
225
|
+
if (before && after) {
|
|
226
|
+
const old = new Map((was as unknown[]).map((x, i) => [before[i]!, JSON.stringify(x)]));
|
|
227
|
+
const changed = (value as unknown[]).filter((x, i) => old.get(after[i]!) !== JSON.stringify(x)) as Record<string, unknown>[];
|
|
228
|
+
const kept = new Set(after); const drop = before.filter(id => !kept.has(id));
|
|
229
|
+
const expected = [...before.filter(id => kept.has(id)), ...after.filter(id => !old.has(id))];
|
|
230
|
+
const order = same(expected, after) ? null : after;
|
|
231
|
+
if (changed.length || drop.length || order) items[k] = { ...(changed.length ? { set: changed } : {}), ...(drop.length ? { drop } : {}), ...(order ? { order } : {}) };
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
if (was === undefined || JSON.stringify(was) !== JSON.stringify(value)) set[k] = value;
|
|
235
|
+
}
|
|
236
|
+
if (!Object.keys(set).length && !unset.length && !Object.keys(items).length) return null;
|
|
237
|
+
return { ...(Object.keys(set).length ? { set } : {}), ...(unset.length ? { unset } : {}), ...(Object.keys(items).length ? { items } : {}) };
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** `base` with `patch` applied: the entry the patch was made toward, before parsing (client/live.tsx parses it). Pure. */
|
|
241
|
+
export function applyEntryPatch(base: ListEntry, patch: Body): ListEntry {
|
|
242
|
+
const out = { ...base } as Record<string, unknown>;
|
|
243
|
+
for (const k of patch.unset ?? []) delete out[k];
|
|
244
|
+
for (const [k, v] of Object.entries(patch.set ?? {})) out[k] = v;
|
|
245
|
+
for (const [k, p] of Object.entries(patch.items ?? {})) {
|
|
246
|
+
const held = Array.isArray(out[k]) ? out[k] as unknown[] : [];
|
|
247
|
+
const byId = new Map(held.map(x => [itemId(x) ?? "", x]));
|
|
248
|
+
const dropped = new Set(p.drop ?? []);
|
|
249
|
+
for (const id of dropped) byId.delete(id);
|
|
250
|
+
const fresh: string[] = [];
|
|
251
|
+
for (const x of p.set ?? []) { const id = itemId(x) ?? ""; if (!byId.has(id)) fresh.push(id); byId.set(id, x); }
|
|
252
|
+
const order = p.order ?? [...held.map(x => itemId(x) ?? "").filter(id => !dropped.has(id)), ...fresh];
|
|
253
|
+
out[k] = order.filter(id => byId.has(id)).map(id => byId.get(id));
|
|
254
|
+
}
|
|
255
|
+
return out as ListEntry;
|
|
256
|
+
}
|
|
@@ -5,7 +5,7 @@ import { oneReading } from "./status";
|
|
|
5
5
|
import type { Actor } from "./actor";
|
|
6
6
|
import { ANY_HOOK_TEXT_PREFIXES } from "./message-sender";
|
|
7
7
|
import { BATCH_PREFIXES, RECOVERY_TITLES } from "./legacy";
|
|
8
|
-
import { listEntrySchema, type ListWorkspace as Workspace } from "./list";
|
|
8
|
+
import { applyEntryPatch, diffEntry, listEntrySchema, type ListWorkspace as Workspace } from "./list";
|
|
9
9
|
import { z } from "zod";
|
|
10
10
|
import { decodeLastKnown, encodeLastKnown } from "./last-known";
|
|
11
11
|
import { answerMessage, awaitingSend, duplicateOpenQuestions, findTaskCover, isOpen, isOther, TASK_DONE, taskCardsFor, taskNeed, parseAnswerMessage, parseAnswersMessage } from "./questions";
|
|
@@ -876,6 +876,28 @@ export const INVARIANTS: Invariant[] = [
|
|
|
876
876
|
return null;
|
|
877
877
|
},
|
|
878
878
|
},
|
|
879
|
+
{
|
|
880
|
+
id: "a-change-sends-only-what-changed",
|
|
881
|
+
why: "2026-12-05 (AGENTS.md invariant 253, issue #503): one task changed in a busy workspace resent its whole list entry (its settled history, every merged PR's title) to every client on every change, megabytes on a slow phone link. A client that asks for patches gets the items that moved; applying the patch to the entry it holds must give exactly the new entry, or a feed would draw something other than what the worker holds.",
|
|
882
|
+
check(whole) {
|
|
883
|
+
// A bounded sample of the entry (a few items of each list), so the check costs the same for any workspace
|
|
884
|
+
// (a-check-costs-linear-in-its-workspace); the diff works item by item, so a sample exercises the same paths.
|
|
885
|
+
const w: Workspace = { ...whole, prs: whole.prs.slice(0, 3), obligations: whole.obligations.slice(0, 3), questions: whole.questions.slice(0, 3), batches: whole.batches.slice(0, 3) };
|
|
886
|
+
const canon = (v: unknown): string => JSON.stringify(v, (_k, x) => x && typeof x === "object" && !Array.isArray(x) ? Object.fromEntries(Object.keys(x).sort().map(k => [k, (x as Record<string, unknown>)[k]])) : x);
|
|
887
|
+
const changes: Workspace[] = [
|
|
888
|
+
{ ...w, title: `${w.title} (renamed)` },
|
|
889
|
+
w.obligations.length ? { ...w, obligations: [{ ...w.obligations[0]!, title: `${w.obligations[0]!.title} again` }, ...w.obligations.slice(1)] } : w,
|
|
890
|
+
w.prs.length > 1 ? { ...w, prs: [...w.prs.slice(1), w.prs[0]!] } : w,
|
|
891
|
+
w.questions.length ? { ...w, questions: w.questions.slice(1) } : w,
|
|
892
|
+
];
|
|
893
|
+
for (const next of changes) {
|
|
894
|
+
const body = diffEntry(w, next);
|
|
895
|
+
if (!body) { if (canon(next) !== canon(w)) return "a changed entry made no patch"; continue; }
|
|
896
|
+
if (canon(applyEntryPatch(w, body)) !== canon(next)) return "a patch applied to the entry it was made from isn't the new entry";
|
|
897
|
+
}
|
|
898
|
+
return diffEntry(w, JSON.parse(JSON.stringify(w)) as Workspace) ? "an unchanged entry made a patch" : null;
|
|
899
|
+
},
|
|
900
|
+
},
|
|
879
901
|
];
|
|
880
902
|
|
|
881
903
|
export function violations(w: Workspace, now: number): { id: string; detail: string }[] {
|