paseo-follow-up 2.7.0-beta.2 → 2.7.0-beta.4
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/engine.ts +14 -6
- package/server/feeds.ts +12 -10
- package/server/list-cache.ts +39 -7
- package/server/mcp-source.ts +1 -1
- package/server/mcp.mjs +1 -1
- package/server/tasks.ts +8 -7
- package/shared/contracts.ts +14 -4
- package/shared/list.ts +79 -0
- package/shared/model.ts +6 -0
- package/shared/send-decision.ts +54 -5
- package/shared/status-invariants.ts +36 -2
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.4",
|
|
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/engine.ts
CHANGED
|
@@ -23,7 +23,7 @@ import { recordSnapshot } from "./deployment-anchor";
|
|
|
23
23
|
import { askRefusal } from "../shared/reopen";
|
|
24
24
|
import { pruneUnsent } from "./batch-archive";
|
|
25
25
|
import { holdSuperseded, liftHold } from "../shared/status";
|
|
26
|
-
import { agentAnswered, autoSentLastHour, autoTurnsPerHour, DEFAULT_MAX_AUTO_SENDS, runningAutoTurns, changedNotGone, conditionId, holdsQueue, inProgressHolds, IN_PROGRESS_MAX_MS, isCapped, MAIN_WAIT, movedOnReason, personHeld, personPart, QUIET_WAIT, readSince, repairWait, sendDecision, settleUnacknowledged, stillApplies, stuckRepair, UNACKNOWLEDGED_MS, type MainWait } from "../shared/send-decision";
|
|
26
|
+
import { agentAnswered, autoSentLastHour, autoTurnsPerHour, DEFAULT_MAX_AUTO_SENDS, runningAutoTurns, changedNotGone, conditionId, holdsQueue, inProgressHolds, IN_PROGRESS_MAX_MS, isCapped, MAIN_WAIT, movedOnReason, personHeld, personPart, QUIET_WAIT, readSince, repairWait, sendDecision, settleGoneParts, settleUnacknowledged, stillApplies, stuckRepair, UNACKNOWLEDGED_MS, type MainWait } from "../shared/send-decision";
|
|
27
27
|
import { isRepair } from "../shared/task-rows";
|
|
28
28
|
import { outsideQuestions, parseOutsideId, type OutsideRun } from "../shared/outside-run";
|
|
29
29
|
import { dismissItem, undoDismissItem } from "./dismiss";
|
|
@@ -163,7 +163,7 @@ export class Engine {
|
|
|
163
163
|
}
|
|
164
164
|
// A batch left blocked or unconfirmed by a release before a-batch-item-leaves-once-nothing-applies, whose PRs
|
|
165
165
|
// have since merged or changed, settles at start-up, dormant workspaces included (no tick observes those).
|
|
166
|
-
if (w.enable_tracking && !w.archived) settleMoot(w, eligible, this.now());
|
|
166
|
+
if (w.enable_tracking && !w.archived) { settleMoot(w, eligible, this.now()); settleGoneParts(w); }
|
|
167
167
|
const healed = healBatches(w);
|
|
168
168
|
if (healed.restored || healed.relabelled || healed.duplicates) console.warn(`[follow-up] healed batches in ${w.id}: ${healed.restored} answered restored, ${healed.relabelled} relabelled as updated, ${healed.duplicates} duplicates set aside`);
|
|
169
169
|
for (const b of w.batches) if (isRecovery(b) && b.state === "pending" && !b.enable_manual_recovery) { b.state = "cancelled"; b.result = "Recovery is now optional. Run recovery when needed; registered work continues independently."; }
|
|
@@ -898,6 +898,9 @@ export class Engine {
|
|
|
898
898
|
// A stuck batch re-checks what it asked for like a queued one: once nothing still applies, it settles and leaves
|
|
899
899
|
// Needs you (a-batch-item-leaves-once-nothing-applies).
|
|
900
900
|
settleMoot(w, tasks, this.now());
|
|
901
|
+
// A person part leaves with its task: once GitHub no longer shows the condition, nothing of it waits on a person
|
|
902
|
+
// (a-person-part-leaves-with-its-task), and it stays gone if the condition comes back as new work.
|
|
903
|
+
settleGoneParts(w);
|
|
901
904
|
// A human-only outcome isn't a delivery that awaits GitHub: its still-open conditions are held as "person" at once.
|
|
902
905
|
// An in-progress answer holds its unchanged conditions while the agent's work runs (inProgressHolds), then they go
|
|
903
906
|
// out again like any unacknowledged condition, toward the same cap.
|
|
@@ -1002,20 +1005,25 @@ export class Engine {
|
|
|
1002
1005
|
agentWorkspace({ version: 1, workspaces: [w] }, agentId, "read", w.id);
|
|
1003
1006
|
requireTracking(w, agentId);
|
|
1004
1007
|
const b = w.batches.find(b => b.id === batchId);
|
|
1005
|
-
|
|
1008
|
+
// Still in progress, the agent may name its person part again or take back one set by mistake (waitingOn ""):
|
|
1009
|
+
// only the part and the words change, never when it settled (a-person-part-leaves-with-its-task).
|
|
1010
|
+
const restated = !!b?.inProgress && b.state === "completed" && outcome === "in_progress" && waitingOn !== undefined && !humanOnly;
|
|
1011
|
+
if (!b || !restated && !["sending", "sent", "blocked", "uncertain"].includes(b.state)) throw new Error("Batch is not awaiting acknowledgment.");
|
|
1006
1012
|
if ((b.recipientAgentId ?? w.mainAgentId) !== agentId) throw new Error(`Only the assigned agent can acknowledge this batch: expected agent ${b.recipientAgentId ?? w.mainAgentId}, received agent ${agentId}.`);
|
|
1007
1013
|
if (outcome === "completed" && b.tasks.some(t => t.kind === "obligation" && w.obligations.some(o => o.id === t.target && o.communication && o.status !== "waived" && (o.status !== "done" || !replyRecorded(o.communication))))) throw new Error("Record the sent reply on each communication task before completing this batch, or acknowledge blocked with the posting/access reason.");
|
|
1008
1014
|
if (humanOnly && (isRecovery(b) || completionCheck(b))) throw new Error("humanOnly is for repair batches. Acknowledge this one blocked with the reason.");
|
|
1009
1015
|
if (outcome === "in_progress" && (isRecovery(b) || completionCheck(b))) throw new Error("in_progress is for repair batches. Acknowledge this one completed or blocked.");
|
|
1016
|
+
if (restated) { b.result = result; if (waitingOn!.trim()) b.waitingOn = waitingOn!.trim(); else delete b.waitingOn; return w; }
|
|
1010
1017
|
// in_progress: the agent (or its own subagent) is already on it. Not a failure and not finished: the batch settles
|
|
1011
1018
|
// completed and its unchanged conditions wait for that work (inProgressHolds), never sent again meanwhile.
|
|
1012
1019
|
b.state = humanOnly || outcome === "in_progress" ? "completed" : outcome; b.result = result; b.acknowledgmentError = null; b.settledAt = new Date(this.now()).toISOString();
|
|
1013
1020
|
if (completionCheck(b) && outcome === "completed") b.doneCheckOutcome = "acknowledged";
|
|
1014
1021
|
if (humanOnly) b.humanOnly = true; else delete b.humanOnly;
|
|
1015
1022
|
// The person part is this answer's: a later answer without one says nothing waits on a person any more.
|
|
1016
|
-
// An in_progress answer that
|
|
1017
|
-
//
|
|
1018
|
-
|
|
1023
|
+
// An in_progress answer that leaves waitingOn out carries the last one over: "already on it" isn't "nothing waits on
|
|
1024
|
+
// a person". An explicit empty waitingOn takes a part set by mistake back while staying in progress; a completed or
|
|
1025
|
+
// blocked answer without one, or Hand back to agent, clears it too.
|
|
1026
|
+
const carried = outcome === "in_progress" && waitingOn === undefined ? b.tasks.map(t => personPart({ ...w, batches: w.batches.filter(x => x !== b) }, t.key)?.text).find(Boolean) : undefined;
|
|
1019
1027
|
const part = waitingOn?.trim() || carried;
|
|
1020
1028
|
if (part && !isRecovery(b) && !completionCheck(b)) b.waitingOn = part; else delete b.waitingOn;
|
|
1021
1029
|
if (outcome === "in_progress") b.inProgress = true; else delete b.inProgress;
|
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
|
}
|
package/server/mcp-source.ts
CHANGED
|
@@ -417,7 +417,7 @@ export const mcpSource: string = [
|
|
|
417
417
|
" [\"register_pr\", \"Register a PR this workspace produced, after submitting it, parents before children; again after restacking to update stack or parent. Mentions and external dependencies aren't yours. A closed PR is settled; disposition says why. agentMerges=true when you merge it yourself with no human review; false hands it back.\", \"follow.register-pr\", { repo: string, number: integer, stack: string, parentNumber: { type: [\"integer\", \"null\"], minimum: 1 }, disposition: string, agentMerges: boolean }, [\"repo\", \"number\", \"stack\"]],",
|
|
418
418
|
" [\"exclude_stack\", \"Move a stack registered by mistake out of this workspace: its PRs and the tasks in obligationIds go to an audit and can't be registered again. reason: the scope or ownership evidence.\", \"follow.exclude-stack\", { stack: string, reason: string, obligationIds: array }, [\"stack\", \"reason\"]],",
|
|
419
419
|
" [\"update_obligation\", \"Record a concrete follow-up task: a production check, migration, decision or stakeholder reply. Not approve/merge/deploy checklists. afterPrs: owner/repo#number. A task comes due by itself when its afterPrs reach dependencyStage, or on recheck (no PRs: 3 days after your last update); Follow-up names due tasks at your turn's end. status: waiting on a PR or another agent; blocked only on the developer; working records you (workingAgentId: your subagent). trigger sends the task to you as a message: now, merge or deploy (with delayDays) only for timing the developer asked for; at (at or inMinutes) for a time they named, or to check back on something Follow-up can't see. Never a sleep loop or your own timer (CI: wait_for_checks). communication: a Slack reply the developer authorized.\", \"follow.obligation\", { id: string, workingAgentId: string, title: string, status: { type: \"string\", enum: [\"pending\", \"waiting\", \"working\", \"blocked\", \"done\", \"waived\"] }, afterPrs: array, dependencyStage: { type: \"string\", enum: [\"merged\", \"deployed\"] }, evidence: string, ask: { ...string, description: \"With blocked: a decision you haven't asked yet (asked with ask_question: pass question).\" }, question: { type: \"string\", pattern: \"^Q\\\\d+$\", description: \"With blocked: the Q<n> you asked with ask_question (task set to this task).\" }, need: { type: \"string\", enum: [\"decision\", \"action\"], description: \"With ask: decision (they choose) or action (they do something and report back; the card has Done). Left out: read from the ask.\" }, enable_follow_up: boolean, communication, trigger, recheck: { type: \"string\", description: \"\\\"YYYY-MM-DD\\\": when to look again. Set it when you keep a due task open, with why in evidence.\" }, new: { type: \"boolean\", description: \"Add it even though a similar open task exists.\" } }, [\"title\", \"status\"]],",
|
|
420
|
-
" [\"acknowledge_batch\", \"Report a Follow-up batch's result by its batch ID before ending the turn. completed: every task verified. in_progress: you or your subagent are already on it; it isn't resent until that ends or GitHub changes. blocked: the reason; humanOnly=true when only a person can move it (a reviewer must re-review). waitingOn: the part
|
|
420
|
+
" [\"acknowledge_batch\", \"Report a Follow-up batch's result by its batch ID before ending the turn. completed: every task verified. in_progress: you or your subagent are already on it; it isn't resent until that ends or GitHub changes. blocked: the reason; humanOnly=true when only a person can move it (a reviewer must re-review). waitingOn: the part only a person (never an agent or a report) can move, while you do the rest; \\\"\\\" clears it.\", \"follow.acknowledge\", { batchId: string, outcome: { type: \"string\", enum: [\"completed\", \"blocked\", \"in_progress\"] }, result: { ...string, maxLength: 2000 }, humanOnly: { type: \"boolean\" }, waitingOn: { ...string, maxLength: 500 } }, [\"batchId\", \"outcome\", \"result\"]],",
|
|
421
421
|
" [\"ask_question\", \"Ask the developer a decision you can't make yourself: a short title, the question, lettered options with what each means for them, and the one you recommend. big: only when building ahead would send something off this machine, change something others rely on, or most remaining work builds on it. Link a PR (owner/repo#number) or task; a task waiting on it then goes blocked with update_obligation question=\\\"Q<n>\\\". Asking again returns the open one; supersedes=\\\"Q<n>\\\" replaces it. Every card ends with Something else; don't add an \\\"Other\\\" option. URLs and owner/repo#123 are clickable. The reply says what to do until the answer arrives.\", \"follow.ask-question\", { title: { ...string, maxLength: 120 }, question: { ...string, maxLength: 2000 }, options: { type: \"array\", maxItems: 26, items: { type: \"object\", properties: { letter: { type: \"string\", pattern: \"^[A-Z]$\" }, label: { ...string, maxLength: 200 }, consequence: { ...string, maxLength: 600 } }, required: [\"letter\", \"label\"], additionalProperties: false } }, recommend: string, big: string, background: string, links: { type: \"array\", maxItems: 10, items: { type: \"object\", properties: { url: string, path: string, card: string, label: string }, additionalProperties: false } }, pr: string, task: string, supersedes: { type: \"string\", pattern: \"^Q\\\\d+$\" } }, [\"title\", \"question\"]],",
|
|
422
422
|
" [\"record_answer\", \"Record the developer's answer to an open question when they answered in chat. choice: the option letter, their short answer when there were no options, or \\\"other\\\" with their words in words.\", \"follow.record-answer\", { id: string, choice: string, words: string }, [\"id\", \"choice\"]],",
|
|
423
423
|
" [\"note_question\", \"When the developer asks something to answer rather than do (an opinion, a how or why), call this first with their words: it goes on their Your questions. Once per message. Not for commands, status pings or a message with a ctx- id. The reply says how to hand in the answer.\", \"follow.note-question\", { question: { ...string, minLength: 1, maxLength: 2000 } }, [\"question\"]],",
|
package/server/mcp.mjs
CHANGED
|
@@ -33,7 +33,7 @@ const tools = [
|
|
|
33
33
|
["register_pr", "Register a PR this workspace produced, after submitting it, parents before children; again after restacking to update stack or parent. Mentions and external dependencies aren't yours. A closed PR is settled; disposition says why. agentMerges=true when you merge it yourself with no human review; false hands it back.", "follow.register-pr", { repo: string, number: integer, stack: string, parentNumber: { type: ["integer", "null"], minimum: 1 }, disposition: string, agentMerges: boolean }, ["repo", "number", "stack"]],
|
|
34
34
|
["exclude_stack", "Move a stack registered by mistake out of this workspace: its PRs and the tasks in obligationIds go to an audit and can't be registered again. reason: the scope or ownership evidence.", "follow.exclude-stack", { stack: string, reason: string, obligationIds: array }, ["stack", "reason"]],
|
|
35
35
|
["update_obligation", "Record a concrete follow-up task: a production check, migration, decision or stakeholder reply. Not approve/merge/deploy checklists. afterPrs: owner/repo#number. A task comes due by itself when its afterPrs reach dependencyStage, or on recheck (no PRs: 3 days after your last update); Follow-up names due tasks at your turn's end. status: waiting on a PR or another agent; blocked only on the developer; working records you (workingAgentId: your subagent). trigger sends the task to you as a message: now, merge or deploy (with delayDays) only for timing the developer asked for; at (at or inMinutes) for a time they named, or to check back on something Follow-up can't see. Never a sleep loop or your own timer (CI: wait_for_checks). communication: a Slack reply the developer authorized.", "follow.obligation", { id: string, workingAgentId: string, title: string, status: { type: "string", enum: ["pending", "waiting", "working", "blocked", "done", "waived"] }, afterPrs: array, dependencyStage: { type: "string", enum: ["merged", "deployed"] }, evidence: string, ask: { ...string, description: "With blocked: a decision you haven't asked yet (asked with ask_question: pass question)." }, question: { type: "string", pattern: "^Q\\d+$", description: "With blocked: the Q<n> you asked with ask_question (task set to this task)." }, need: { type: "string", enum: ["decision", "action"], description: "With ask: decision (they choose) or action (they do something and report back; the card has Done). Left out: read from the ask." }, enable_follow_up: boolean, communication, trigger, recheck: { type: "string", description: "\"YYYY-MM-DD\": when to look again. Set it when you keep a due task open, with why in evidence." }, new: { type: "boolean", description: "Add it even though a similar open task exists." } }, ["title", "status"]],
|
|
36
|
-
["acknowledge_batch", "Report a Follow-up batch's result by its batch ID before ending the turn. completed: every task verified. in_progress: you or your subagent are already on it; it isn't resent until that ends or GitHub changes. blocked: the reason; humanOnly=true when only a person can move it (a reviewer must re-review). waitingOn: the part
|
|
36
|
+
["acknowledge_batch", "Report a Follow-up batch's result by its batch ID before ending the turn. completed: every task verified. in_progress: you or your subagent are already on it; it isn't resent until that ends or GitHub changes. blocked: the reason; humanOnly=true when only a person can move it (a reviewer must re-review). waitingOn: the part only a person (never an agent or a report) can move, while you do the rest; \"\" clears it.", "follow.acknowledge", { batchId: string, outcome: { type: "string", enum: ["completed", "blocked", "in_progress"] }, result: { ...string, maxLength: 2000 }, humanOnly: { type: "boolean" }, waitingOn: { ...string, maxLength: 500 } }, ["batchId", "outcome", "result"]],
|
|
37
37
|
["ask_question", "Ask the developer a decision you can't make yourself: a short title, the question, lettered options with what each means for them, and the one you recommend. big: only when building ahead would send something off this machine, change something others rely on, or most remaining work builds on it. Link a PR (owner/repo#number) or task; a task waiting on it then goes blocked with update_obligation question=\"Q<n>\". Asking again returns the open one; supersedes=\"Q<n>\" replaces it. Every card ends with Something else; don't add an \"Other\" option. URLs and owner/repo#123 are clickable. The reply says what to do until the answer arrives.", "follow.ask-question", { title: { ...string, maxLength: 120 }, question: { ...string, maxLength: 2000 }, options: { type: "array", maxItems: 26, items: { type: "object", properties: { letter: { type: "string", pattern: "^[A-Z]$" }, label: { ...string, maxLength: 200 }, consequence: { ...string, maxLength: 600 } }, required: ["letter", "label"], additionalProperties: false } }, recommend: string, big: string, background: string, links: { type: "array", maxItems: 10, items: { type: "object", properties: { url: string, path: string, card: string, label: string }, additionalProperties: false } }, pr: string, task: string, supersedes: { type: "string", pattern: "^Q\\d+$" } }, ["title", "question"]],
|
|
38
38
|
["record_answer", "Record the developer's answer to an open question when they answered in chat. choice: the option letter, their short answer when there were no options, or \"other\" with their words in words.", "follow.record-answer", { id: string, choice: string, words: string }, ["id", "choice"]],
|
|
39
39
|
["note_question", "When the developer asks something to answer rather than do (an opinion, a how or why), call this first with their words: it goes on their Your questions. Once per message. Not for commands, status pings or a message with a ctx- id. The reply says how to hand in the answer.", "follow.note-question", { question: { ...string, minLength: 1, maxLength: 2000 } }, ["question"]],
|
package/server/tasks.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { join } from "node:path";
|
|
|
9
9
|
import { communicationReady } from "../shared/communication";
|
|
10
10
|
import { taskSchedule } from "../shared/task-trigger";
|
|
11
11
|
import { isWorkspaceRoot, type WorkspaceAgent } from "./workspace-agent";
|
|
12
|
-
import { personPart, taskUpdate } from "../shared/send-decision";
|
|
12
|
+
import { addedChecks, mergedParent, personPart, repairable, reviewAsks, taskUpdate } from "../shared/send-decision";
|
|
13
13
|
import { FIX_ONLY_LINE, type ReviewComments } from "../shared/pr-workflow";
|
|
14
14
|
|
|
15
15
|
function fingerprint(value: unknown): string { return createHash("sha256").update(JSON.stringify(value)).digest("hex"); }
|
|
@@ -24,12 +24,13 @@ export function tasksFor(w: Workspace, now = Date.now(), wording: TaskWording =
|
|
|
24
24
|
const tasks: Task[] = [];
|
|
25
25
|
const add = (kind: Task["kind"], target: string, title: string, value: unknown, parts?: string[]) => tasks.push({ key: `${kind}:${target}`, kind, target, title, fingerprint: fingerprint(value), ...(parts ? { parts } : {}) });
|
|
26
26
|
for (const pr of w.prs) {
|
|
27
|
-
|
|
28
|
-
if (!
|
|
27
|
+
// The same conditions taskGone (shared/send-decision.ts) reads: a task is yielded exactly while it isn't gone.
|
|
28
|
+
if (!repairable(pr)) continue;
|
|
29
|
+
const s = pr.snapshot!;
|
|
29
30
|
if (s.conflict) add("conflict", pr.key, `Resolve merge conflicts on ${pr.repo}#${pr.number}`, [s.head, s.base, "conflict"]);
|
|
30
31
|
// Review comments Off: no review-comment repair at all; the threads stay on the PR row for people.
|
|
31
32
|
const comments = wording.reviewComments?.(pr.repo) ?? "reply";
|
|
32
|
-
if (comments !== "off" && (s
|
|
33
|
+
if (comments !== "off" && reviewAsks(s)) {
|
|
33
34
|
// a-person-part-is-a-person-item: the agent's count leaves out the part it said waits on a person (the PR row keeps all).
|
|
34
35
|
const n = s.threads.length - (s.threads.length > 1 && personPart(w, `review:${pr.key}`) ? 1 : 0);
|
|
35
36
|
const reason = s.threads.length ? `${n} open thread${n === 1 ? "" : "s"}` : "changes requested";
|
|
@@ -42,11 +43,11 @@ export function tasksFor(w: Workspace, now = Date.now(), wording: TaskWording =
|
|
|
42
43
|
}
|
|
43
44
|
// Add to repairs (invariant 222, an-added-check-is-repaired): an optional check the developer added joins the PR's
|
|
44
45
|
// checks repair while it fails. Without one the repair's title and fingerprint are what they always were.
|
|
45
|
-
const added = (
|
|
46
|
+
const added = addedChecks(pr);
|
|
46
47
|
if (s.failedChecks.length && !added.length) add("checks", pr.key, `Fix required checks on ${pr.repo}#${pr.number}: ${s.failedChecks.join(", ")}`, [s.head, s.failedChecks.slice().sort()]);
|
|
47
48
|
else if (added.length) add("checks", pr.key, `Fix ${s.failedChecks.length ? "checks" : "optional checks"} on ${pr.repo}#${pr.number}: ${[...s.failedChecks, ...added].join(", ")}${s.failedChecks.length ? ` (${added.join(", ")} optional, added by the developer)` : " (added by the developer)"}`, [s.head, s.failedChecks.slice().sort(), added.slice().sort()]);
|
|
48
|
-
const parent = w
|
|
49
|
-
if (parent?.snapshot
|
|
49
|
+
const parent = mergedParent(w, pr);
|
|
50
|
+
if (parent?.snapshot) add("restack", pr.key, wording.github?.(pr.repo) || s.prWorkflow === "github" ? `Restack ${pr.repo}#${pr.number} onto ${s.trunk} after ${parent.repo}#${parent.number} merged: rebase, push with --force-with-lease, and retarget with gh pr edit --base ${s.trunk} if GitHub didn't` : `Reconcile stack parent after ${parent.repo}#${parent.number} merged`, [parent.key, parent.snapshot.head]);
|
|
50
51
|
}
|
|
51
52
|
for (const o of followUpObligations(w)) {
|
|
52
53
|
if (!o.enable_follow_up || !["pending", "waiting"].includes(o.status) || !communicationReady(o.communication)) continue;
|
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
|
+
}
|
package/shared/model.ts
CHANGED
|
@@ -184,6 +184,12 @@ export const batchSchema = z.object({
|
|
|
184
184
|
* tells the agent to leave that part (a-person-part-is-a-person-item).
|
|
185
185
|
*/
|
|
186
186
|
waitingOn: z.string().max(500).optional(),
|
|
187
|
+
/**
|
|
188
|
+
* Keys of this batch's tasks whose condition went away after the answer named `waitingOn` (the conflict resolved, the
|
|
189
|
+
* PR merged): the part no longer waits on a person for them, even if the condition comes back as new work
|
|
190
|
+
* (a-person-part-leaves-with-its-task, settleGoneParts in shared/send-decision.ts).
|
|
191
|
+
*/
|
|
192
|
+
partGone: z.array(z.string().max(500)).optional(),
|
|
187
193
|
/**
|
|
188
194
|
* The agent acknowledged it in_progress: it (or its own subagent) is already working on it. Settled completed, not a
|
|
189
195
|
* failure; its unchanged conditions are not sent again while that work runs (inProgressHolds, shared/send-decision.ts),
|
package/shared/send-decision.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { completionCheck, type Task, type Batch as StoredBatch } from "./model";
|
|
2
|
-
import type { ListBatch as Batch, ListWorkspace as Workspace } from "./list";
|
|
2
|
+
import type { ListBatch as Batch, ListPr, ListWorkspace as Workspace } from "./list";
|
|
3
|
+
import { finishedTask } from "./finished";
|
|
3
4
|
import { recoveryBatch } from "./follow-up";
|
|
4
5
|
|
|
5
6
|
/** How long a new batch waits before it goes out on its own, so tasks that land together go in one message. */
|
|
@@ -233,17 +234,35 @@ export const personHeld = (w: Pick<Workspace, "batches">, t: Pick<Task, "key" |
|
|
|
233
234
|
/**
|
|
234
235
|
* a-person-part-is-a-person-item: what the agent's latest answer for this task said only a person can move
|
|
235
236
|
* (Batch.waitingOn), else null. Keyed by the task, not its fingerprint, so a review that keeps changing keeps it; a
|
|
236
|
-
* later answer without one drops it.
|
|
237
|
+
* later answer without one drops it. a-person-part-leaves-with-its-task: once the task itself is gone (taskGone, or
|
|
238
|
+
* seen gone since the answer: Batch.partGone) nothing of it waits on a person, so a returning condition never brings
|
|
239
|
+
* the old part back. Without `prs` (a batch list alone) only the record decides.
|
|
237
240
|
*/
|
|
238
|
-
export function personPart(w: Pick<Workspace, "batches"
|
|
241
|
+
export function personPart(w: Pick<Workspace, "batches"> & Partial<Pick<Workspace, "prs" | "obligations">>, taskKey: string): { batchId: string; text: string } | null {
|
|
239
242
|
for (let i = w.batches.length - 1; i >= 0; i--) {
|
|
240
243
|
const b = w.batches[i]!;
|
|
241
|
-
|
|
242
|
-
|
|
244
|
+
const t = b.tasks.find(t => t.key === taskKey);
|
|
245
|
+
if (!b.sentAt || !b.settledAt || !["completed", "blocked"].includes(b.state) || b.unacknowledged || !t) continue;
|
|
246
|
+
if (!b.waitingOn || b.partGone?.includes(taskKey) || w.prs && taskGone({ prs: w.prs, obligations: w.obligations ?? [] }, t)) return null;
|
|
247
|
+
return { batchId: b.id, text: b.waitingOn };
|
|
243
248
|
}
|
|
244
249
|
return null;
|
|
245
250
|
}
|
|
246
251
|
|
|
252
|
+
/**
|
|
253
|
+
* Records, on each answer whose person part still stands, the tasks whose condition is gone now (taskGone), so the part
|
|
254
|
+
* stays gone if the condition comes back later as new work (a-person-part-leaves-with-its-task). Run with settleMoot.
|
|
255
|
+
*/
|
|
256
|
+
export function settleGoneParts(w: Pick<Workspace, "batches" | "prs" | "obligations">): void {
|
|
257
|
+
const keys = new Set(w.batches.flatMap(b => b.waitingOn ? b.tasks.map(t => t.key) : []));
|
|
258
|
+
for (const key of keys) {
|
|
259
|
+
const before = personPart({ batches: w.batches }, key);
|
|
260
|
+
if (!before || personPart(w, key)) continue;
|
|
261
|
+
const b = w.batches.find(b => b.id === before.batchId)!;
|
|
262
|
+
b.partGone = [...(b.partGone ?? []), key];
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
247
266
|
/** Blocked or unconfirmed: a repair batch whose outcome the developer is shown (Needs you's "The repairs didn't finish"). */
|
|
248
267
|
export const stuckRepair = (b: Pick<Batch, "state" | "tasks" | "movedOn">) =>
|
|
249
268
|
["blocked", "uncertain"].includes(b.state) && !b.movedOn && !recoveryBatch(b) && !(b.tasks.length > 0 && b.tasks.every(t => t.kind === "completion"));
|
|
@@ -260,6 +279,36 @@ function conditionKnown(w: Pick<Workspace, "prs">, t: Pick<Task, "kind" | "targe
|
|
|
260
279
|
return !pr || !!pr.snapshot?.complete && !pr.error;
|
|
261
280
|
}
|
|
262
281
|
|
|
282
|
+
/** A PR Follow-up repairs: GitHub answered in full and it is open and not a draft (server/tasks.ts tasksFor). */
|
|
283
|
+
export const repairable = (pr: Pick<ListPr, "snapshot" | "error">) => !!pr.snapshot?.complete && !pr.error && pr.snapshot.state === "OPEN" && !pr.snapshot.draft;
|
|
284
|
+
/** The review asks for something: open threads, or changes requested. */
|
|
285
|
+
export const reviewAsks = (s: Pick<NonNullable<ListPr["snapshot"]>, "threads" | "reviewDecision">) => !!s.threads?.length || s.reviewDecision === "CHANGES_REQUESTED";
|
|
286
|
+
/** Failing optional checks the developer added to repairs (Add to repairs, invariant 222). */
|
|
287
|
+
export const addedChecks = (pr: Pick<ListPr, "snapshot" | "repairChecks">) => (pr.snapshot?.otherFailedChecks ?? []).filter(c => pr.repairChecks?.includes(c));
|
|
288
|
+
/** The PR's stack parent once it merged (the restack task), else undefined. */
|
|
289
|
+
export const mergedParent = <P extends Pick<ListPr, "key" | "snapshot">>(w: { prs: readonly P[] }, pr: Pick<ListPr, "parent">): P | undefined => { const p = w.prs.find(p => p.key === pr.parent); return p?.snapshot?.state === "MERGED" ? p : undefined; };
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* a-person-part-leaves-with-its-task: the task's condition is known to be gone, by the same conditions tasksFor
|
|
293
|
+
* (server/tasks.ts) yields a task of that key with: the PR merged, closed, a draft or untracked, the conflict resolved,
|
|
294
|
+
* no open thread or requested change, the checks passing, the parent not merged, the task done, waived or removed.
|
|
295
|
+
* While GitHub's answer for its PR is unknown it isn't gone. A setting (Review comments Off) never makes it gone.
|
|
296
|
+
*/
|
|
297
|
+
export function taskGone(w: Pick<Workspace, "prs" | "obligations">, t: Pick<Task, "kind" | "target">): boolean {
|
|
298
|
+
if (t.kind === "inventory" || t.kind === "completion" || !conditionKnown(w, t)) return false;
|
|
299
|
+
if (t.kind === "obligation") { const o = w.obligations.find(o => o.id === t.target); return !o || finishedTask(o); }
|
|
300
|
+
const pr = w.prs.find(p => p.key === t.target);
|
|
301
|
+
if (!pr || !repairable(pr)) return true;
|
|
302
|
+
const s = pr.snapshot!;
|
|
303
|
+
switch (t.kind) {
|
|
304
|
+
case "conflict": return !s.conflict;
|
|
305
|
+
case "review": return !reviewAsks(s);
|
|
306
|
+
case "checks": return !s.failedChecks?.length && !addedChecks(pr).length;
|
|
307
|
+
case "restack": return !mergedParent(w, pr);
|
|
308
|
+
default: return false;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
263
312
|
/**
|
|
264
313
|
* Whether a stuck repair batch still asks for anything: some task's condition (key and fingerprint) is still open in
|
|
265
314
|
* `open` (server/tasks.ts tasksFor, the PRs as they are now), or its PR's state is unknown. Once nothing applies (every
|
|
@@ -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";
|
|
@@ -18,7 +18,7 @@ import { HOME_GROUPS, homeCounts, prChip, trackedGroup, type HomeModel } from ".
|
|
|
18
18
|
import { needsEntries } from "./view-r";
|
|
19
19
|
import { freshPriorities, type Priority } from "./priorities";
|
|
20
20
|
import { agentCard, automaticHold, batchView, finishLine, holdSuperseded } from "./status";
|
|
21
|
-
import { conditionId, isCapped, mainWait, NO_PROGRESS_CAP, personHeld, personPart, sendDecision, stuckRepair } from "./send-decision";
|
|
21
|
+
import { conditionId, isCapped, mainWait, NO_PROGRESS_CAP, personHeld, personPart, sendDecision, stuckRepair, taskGone } from "./send-decision";
|
|
22
22
|
import { messageStrip, obligationDelivery, repairRows } from "./task-rows";
|
|
23
23
|
import { followUpObligations } from "./follow-up";
|
|
24
24
|
import { PRESENCE, claimsWorking, taskStatus, waitedAgent } from "./task-status";
|
|
@@ -195,6 +195,18 @@ export const INVARIANTS: Invariant[] = [
|
|
|
195
195
|
return null;
|
|
196
196
|
},
|
|
197
197
|
},
|
|
198
|
+
{
|
|
199
|
+
id: "a-person-part-leaves-with-its-task",
|
|
200
|
+
why: "2026-12-04 (2.7.0-beta.2): a main agent acknowledged two conflict repairs with waitingOn set. Hours after the conflicts were fixed and both PRs were mergeable, Needs you still showed \"Part of #N waits on a person\" for each: the part only checked that the PR was open. Once its task's condition is gone (whatever tasksFor no longer yields) the part leaves; while GitHub's answer is unknown it stays.",
|
|
201
|
+
check(w, now) {
|
|
202
|
+
for (const i of needsYou(w, now)) {
|
|
203
|
+
if (i.kind !== "person" || !i.part) continue;
|
|
204
|
+
const t = w.batches.flatMap(b => b.tasks).find(t => t.key === i.taskKey);
|
|
205
|
+
if (t && taskGone(w, t)) return `${i.taskKey}: GitHub no longer shows the task, but Needs you still says part of it waits on a person`;
|
|
206
|
+
}
|
|
207
|
+
return null;
|
|
208
|
+
},
|
|
209
|
+
},
|
|
198
210
|
{
|
|
199
211
|
id: "a-pr-summary-says-the-worst",
|
|
200
212
|
why: "2026-11-22: a 126-PR workspace with four PRs failing checks read \"#1001+125 ✓\" on Home (the chip took the first open PR's state) and \"Checks are running\" in the panel header (running outranked failing). A line or chip that sums up a workspace's PRs says the worst of its open PRs, and the chip counts failing PRs as the live line does.",
|
|
@@ -864,6 +876,28 @@ export const INVARIANTS: Invariant[] = [
|
|
|
864
876
|
return null;
|
|
865
877
|
},
|
|
866
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
|
+
},
|
|
867
901
|
];
|
|
868
902
|
|
|
869
903
|
export function violations(w: Workspace, now: number): { id: string; detail: string }[] {
|