paseo-follow-up 1.4.0-beta.30 → 1.4.0-beta.31

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/README.md CHANGED
@@ -221,7 +221,7 @@ This replaces the separate **Wait** plugin (`paseo-wait`). While that plugin is
221
221
  Install the beta:
222
222
 
223
223
  ```sh
224
- paseo plugin update follow-through --version 1.4.0-beta.30
224
+ paseo plugin update follow-through --version 1.4.0-beta.31
225
225
  # or, for a fresh install:
226
226
  paseo plugin install npm:paseo-follow-up@beta
227
227
  ```
package/index.server.ts CHANGED
@@ -264,6 +264,7 @@ export default function contribute(server: PluginServerContext) {
264
264
  * 1.4.0-beta.25: once, collapse open questions that were asked twice or more (see collapseDuplicateQuestions). The
265
265
  * oldest stays open; answered ones are never touched. Backed up first, like the other migrations.
266
266
  */
267
+ const BRIEF_REOPEN_MIGRATION = "reopen-collapsed-briefs-1";
267
268
  const dedupeQuestions = async () => {
268
269
  if ((await store.snapshot()).migrations?.includes(QUESTION_DEDUPE_MIGRATION)) return;
269
270
  await copyFile(join(directory, "state.json"), join(directory, "state.before-question-dedupe.json.bak"), 1).catch(error => { if (!["ENOENT", "EEXIST"].includes((error as NodeJS.ErrnoException).code ?? "")) throw error; });
@@ -274,6 +275,19 @@ export default function contribute(server: PluginServerContext) {
274
275
  state.migrations = [...state.migrations ?? [], QUESTION_DEDUPE_MIGRATION];
275
276
  });
276
277
  };
278
+ /**
279
+ * 1.4.0-beta.25: once, reopen Needs-you cards that another agent's message (or Follow-up, a continuation, a schedule)
280
+ * collapsed while their questions are still open (Inbox.reopenCollapsed). Questions are the source of truth.
281
+ */
282
+ const reopenBriefs = async () => {
283
+ if ((await store.snapshot()).migrations?.includes(BRIEF_REOPEN_MIGRATION)) return;
284
+ const snapshot = await store.snapshot();
285
+ await inbox.reopenCollapsed(async (agentId, ids) => {
286
+ const w = snapshot.workspaces.find(w => w.mainAgentId === agentId);
287
+ return new Set((w?.questions ?? []).filter(q => ids.includes(q.id) && !q.answer && !q.closed).map(q => q.id));
288
+ }).catch(error => console.warn("[follow-up] reopening collapsed cards failed:", error));
289
+ await store.mutate(state => { state.migrations = [...state.migrations ?? [], BRIEF_REOPEN_MIGRATION]; });
290
+ };
277
291
  /** 1.3.0-beta.3: back up once before the active-scope migration (applied by the engine after its first discovery). */
278
292
  const backupActiveScope = async () => {
279
293
  if ((await store.snapshot()).migrations?.includes(ACTIVE_SCOPE_MIGRATION)) return;
@@ -291,6 +305,7 @@ export default function contribute(server: PluginServerContext) {
291
305
  await engine.recover();
292
306
  await migrateTracking();
293
307
  await dedupeQuestions();
308
+ await reopenBriefs();
294
309
  await backupActiveScope();
295
310
  // Reviewers: the one-time seed from earlier requests, before history is pruned. An unreadable reviewers.json only affects Add reviewers.
296
311
  await reviewerStore.migrate(await store.snapshot()).catch(() => undefined);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "paseo-follow-up",
3
3
  "private": false,
4
- "version": "1.4.0-beta.30",
4
+ "version": "1.4.0-beta.31",
5
5
  "description": "Follow every workspace PR stack in Paseo, answer agent questions, batch repairs for the main agent, and see what needs you.",
6
6
  "type": "module",
7
7
  "files": [
@@ -7,7 +7,7 @@ import { join } from "node:path";
7
7
  * fails open: an unknown or unreadable format means "the developer wrote it", which clears a flag
8
8
  * rather than leaving noise.
9
9
  */
10
- export type Sender = "agent" | "follow-up" | "defer" | "session" | "schedule" | "tom";
10
+ export type Sender = "agent" | "follow-up" | "defer" | "session" | "schedule" | "tom" | "unknown";
11
11
  export type Message = { text: string; messageId?: string | null; clientMessageId?: string | null };
12
12
  export type Ledger = { agentId: string; messageId: string | null; at: string; by?: string; action?: string }[];
13
13
  export type Sources = {
@@ -21,6 +21,11 @@ export const WINDOW_MS = 10_000;
21
21
 
22
22
  const ENVELOPE = /^\s*<paseo-system\b[^>]*\bkind="(agent-message|agent-notification)"/;
23
23
 
24
+ /**
25
+ * Only "tom" may answer a brief. A turn whose prompt wasn't seen is "unknown", never the developer: before 1.4.0-beta.25
26
+ * an unseen prompt fell back to the developer, so another agent's message (which Paseo 0.15 stores as an agent_message
27
+ * tool call, not a user message) answered the open brief with the developer's previous message.
28
+ */
24
29
  export async function classify(message: Message | null, agentId: string, at: number, sources: Sources): Promise<Sender> {
25
30
  if (message && ENVELOPE.test(message.text)) return "agent";
26
31
  const safe = async (check: () => Promise<boolean>) => { try { return await check(); } catch { return false; } };
@@ -40,7 +45,7 @@ export async function classify(message: Message | null, agentId: string, at: num
40
45
  if (await safe(() => sources.defer(agentId, at))) return "defer";
41
46
  if (await safe(() => sources.session(agentId, at))) return "session";
42
47
  if (await safe(() => sources.schedule(agentId, at))) return "schedule";
43
- return "tom";
48
+ return message ? "tom" : "unknown";
44
49
  }
45
50
 
46
51
  const near = (iso: unknown, at: number) => typeof iso === "string" && Number.isFinite(Date.parse(iso)) && Math.abs(Date.parse(iso) - at) <= WINDOW_MS;
@@ -87,3 +92,21 @@ export function newestUserMessage(items: unknown[]): Message | null {
87
92
  }
88
93
  return null;
89
94
  }
95
+
96
+ /**
97
+ * What started the current turn, from the timeline tail (newest last). Paseo 0.15 projects an agent's message into a
98
+ * completed `agent_message` tool call carrying its sender, and a schedule or heartbeat prompt into a `heartbeat` tool
99
+ * call; only a developer's own words stay a user message. If the previous turn's output comes before any prompt, the
100
+ * new prompt isn't in the tail yet: unknown, so nothing is answered on a guess.
101
+ */
102
+ export function turnPrompt(items: unknown[]): { message: Message | null; from: "agent" | "schedule" | null } {
103
+ for (let i = items.length - 1; i >= 0; i--) {
104
+ const item = items[i] as { type?: string; name?: string; callId?: string; text?: unknown; agentMessage?: { text?: unknown }; messageId?: string; clientMessageId?: string } | null;
105
+ if (!item || typeof item !== "object") continue;
106
+ if (item.type === "user_message" && typeof item.text === "string") return { message: { text: item.text, messageId: item.messageId ?? null, clientMessageId: item.clientMessageId ?? null }, from: null };
107
+ if (item.type === "tool_call" && (item.name === "agent_message" || item.agentMessage || item.callId?.startsWith("paseo-agent-message:"))) return { message: null, from: "agent" };
108
+ if (item.type === "tool_call" && item.name === "heartbeat" && item.callId?.startsWith("paseo-system:")) return { message: null, from: "schedule" };
109
+ if (item.type === "assistant_message" || item.type === "tool_call") return { message: null, from: null };
110
+ }
111
+ return { message: null, from: null };
112
+ }
package/server/inbox.ts CHANGED
@@ -5,8 +5,8 @@ import { emptyInbox, expired, inboxStateSchema, newEntry, reduce, StaleSignOff,
5
5
  import type { State as FollowState, Workspace as FollowWorkspace } from "../shared/model";
6
6
  import { prActionBlocks } from "../shared/pr-actions";
7
7
  import { configuredReviewers, noReviewers, reviewerLabel, withoutAuthor } from "../shared/reviewers";
8
- import { classify, newestUserMessage, type Sources } from "./inbox-classifier";
9
- import { briefOrigin, briefStep, pickBrief, type Brief, type BriefEvent, type BriefSources, type NeedsYouRecord, type PrState } from "../shared/brief";
8
+ import { classify, turnPrompt, type Sources } from "./inbox-classifier";
9
+ import { briefOrigin, briefStep, pickBrief, shouldReopen, type Brief, type BriefEvent, type BriefSources, type NeedsYouRecord, type PrState } from "../shared/brief";
10
10
 
11
11
  /** The flag store: plugin-data/follow-through/inbox.json. A new file, so existing state never changes shape. */
12
12
  export class InboxStore {
@@ -264,10 +264,11 @@ export class Inbox {
264
264
  const at = this.now();
265
265
  this.turns.set(agent.id, { turnId: turnId ?? null, at });
266
266
  const items = await this.o.directory.tail(agent.id, 20).catch(() => []);
267
- const message = newestUserMessage(items);
268
- const sender = await classify(message, agent.id, at, this.o.sources);
269
- // The developer's message answers the open brief; anything else means the agent kept going.
270
- const brief: BriefEvent = sender === "tom" ? { type: "message", text: message?.text ?? null } : { type: "turn_start" };
267
+ const prompt = turnPrompt(items);
268
+ const sender = prompt.from ?? await classify(prompt.message, agent.id, at, this.o.sources);
269
+ // Only the developer's own message answers the open brief. Another agent's message, Follow-up's prompts, a
270
+ // continuation after compaction or a schedule start a turn but leave the card open: its questions still are.
271
+ const brief: BriefEvent = sender === "tom" ? { type: "message", text: prompt.message?.text ?? null } : { type: "turn_start" };
271
272
  await this.apply([{ agentId: root.rootId, event: { type: "message", from: sender === "tom" ? "tom" : "automation" }, brief: () => brief }]);
272
273
  }
273
274
 
@@ -633,6 +634,32 @@ export class Inbox {
633
634
  return { results };
634
635
  }
635
636
 
637
+ /**
638
+ * One-time repair (1.4.0-beta.25): an agent's current card that a non-developer turn collapsed while its questions are
639
+ * still open comes back open, in the inbox and in the chat (the timeline item is re-appended with the same id).
640
+ * Only cards collapsed in the last week; `openQuestions` says which of an agent's linked questions are open.
641
+ */
642
+ async reopenCollapsed(openQuestions: (agentId: string, ids: string[]) => Promise<ReadonlySet<string>>): Promise<string[]> {
643
+ const state = await this.store.snapshot();
644
+ const due: string[] = [];
645
+ for (const [agentId, e] of Object.entries(state.entries)) {
646
+ const b = e?.brief;
647
+ if (!b || b.state === "open" || !b.questionIds.length || !b.outcomeAt || this.now() - Date.parse(b.outcomeAt) > 7 * 86_400_000) continue;
648
+ if (shouldReopen(b, await openQuestions(agentId, b.questionIds).catch(() => new Set<string>()), false)) due.push(agentId);
649
+ }
650
+ const appends: { agentId: string; brief: Brief }[] = [];
651
+ if (due.length) await this.store.mutate(s => {
652
+ for (const agentId of due) {
653
+ const b = s.entries[agentId]?.brief;
654
+ if (!b || b.state === "open") continue;
655
+ const reopened: Brief = { ...b, state: "open", outcome: null, outcomeAt: null };
656
+ s.entries[agentId]!.brief = reopened; appends.push({ agentId, brief: reopened });
657
+ }
658
+ });
659
+ await this.flush(appends);
660
+ return appends.map(a => a.agentId);
661
+ }
662
+
636
663
  /** The stored brief for one agent, for Home's detail pane. */
637
664
  async brief(agentId: string): Promise<Brief | null> {
638
665
  if (!await this.on()) return null;
package/shared/brief.ts CHANGED
@@ -328,9 +328,10 @@ export function briefStep(prev: Brief | null, event: BriefEvent, now: string): {
328
328
  appends.push(brief);
329
329
  return { brief, appends };
330
330
  }
331
+ // A turn the developer didn't start (another agent, Follow-up, a continuation, a schedule) leaves the card open:
332
+ // only the developer answers it, and only a newer brief from the same agent supersedes it.
331
333
  case "turn_start":
332
- if (prev?.state !== "open") return keep;
333
- { const b = collapse(prev, "superseded", "The agent kept going"); return { brief: b, appends: [b] }; }
334
+ return keep;
334
335
  case "message": {
335
336
  if (prev?.state !== "open") return keep;
336
337
  const picked = matchOption(prev, event.text);
@@ -409,3 +410,19 @@ export function nothingNeededLine(ask: string): string {
409
410
  const rest = ask.replace(/^\s*nothing(?: is)? needed(?: from you)?\s*[.:·—–-]?\s*/i, "").trim();
410
411
  return rest ? `Nothing needed · ${rest}` : "Nothing needed";
411
412
  }
413
+
414
+ // ---------- one source of truth: the card follows its questions (1.4.0-beta.25) ----------
415
+
416
+ /** Outcomes only the developer produces: a reply, an option pick, sign-off. Anything else never closes a card. */
417
+ export const developerClosed = (b: Pick<Brief, "state" | "outcome">) => b.state === "signed" || b.state === "answered" && /^You (replied|picked)\b/.test(b.outcome ?? "");
418
+ /**
419
+ * Whether an agent's current brief (the newest) must be shown open: it links questions that are still open on the
420
+ * server, and nothing the developer did closed it. Before 1.4.0-beta.25 a turn started by another agent (or Follow-up,
421
+ * a continuation, a schedule) superseded it, or answered it with the developer's previous message.
422
+ * `trustReplies: false` (the one-time repair) also reopens "You replied" cards, since those can't be told apart.
423
+ */
424
+ export function shouldReopen(b: Pick<Brief, "state" | "outcome" | "questionIds">, openQuestionIds: ReadonlySet<string>, trustReplies = true): boolean {
425
+ if (b.state === "open" || !b.questionIds.some(id => openQuestionIds.has(id))) return false;
426
+ if (b.state === "superseded") return true;
427
+ return !trustReplies && b.state === "answered" && b.outcome === "You replied";
428
+ }
@@ -1,5 +1,6 @@
1
1
  import type { Workspace } from "./model";
2
2
  import { duplicateOpenQuestions } from "./questions";
3
+ import { shouldReopen, type Brief } from "./brief";
3
4
 
4
5
  /**
5
6
  * Status invariants: what must hold for any workspace, whatever path changed it. Pure, no IO, and never throwing:
@@ -28,3 +29,11 @@ export function violations(w: Workspace, now: number): { id: string; detail: str
28
29
  }
29
30
  return out;
30
31
  }
32
+
33
+ /**
34
+ * Needs-you cards (briefs live in the inbox store, not the workspace). An agent's current card follows its linked
35
+ * questions: while one is open on the server, only the developer closes the card. `brief-follows-questions`.
36
+ */
37
+ export function briefViolations(current: Pick<Brief, "id" | "state" | "outcome" | "questionIds">, openQuestionIds: ReadonlySet<string>): { id: string; detail: string }[] {
38
+ return shouldReopen(current, openQuestionIds) ? [{ id: "brief-follows-questions", detail: `${current.id} is ${current.state} while ${current.questionIds.filter(id => openQuestionIds.has(id)).join(", ")} ${current.questionIds.filter(id => openQuestionIds.has(id)).length === 1 ? "is" : "are"} open` }] : [];
39
+ }