pi-daddy 0.50.0 → 0.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +13 -20
  3. package/dist/governance/approval-prompt.d.ts +4 -0
  4. package/dist/governance/approval-prompt.d.ts.map +1 -1
  5. package/dist/governance/approval-prompt.js +4 -5
  6. package/dist/governance/approval-prompt.js.map +1 -1
  7. package/dist/governance/initiative-coordinator.d.ts +5 -0
  8. package/dist/governance/initiative-coordinator.d.ts.map +1 -1
  9. package/dist/governance/initiative-coordinator.js +16 -0
  10. package/dist/governance/initiative-coordinator.js.map +1 -1
  11. package/dist/governance/permission-question.d.ts +4 -0
  12. package/dist/governance/permission-question.d.ts.map +1 -0
  13. package/dist/governance/permission-question.js +102 -0
  14. package/dist/governance/permission-question.js.map +1 -0
  15. package/dist/kernel/chain.d.ts +1 -0
  16. package/dist/kernel/chain.d.ts.map +1 -1
  17. package/dist/kernel/chain.js.map +1 -1
  18. package/dist/kernel/dashboard-observation.d.ts +15 -5
  19. package/dist/kernel/dashboard-observation.d.ts.map +1 -1
  20. package/dist/kernel/dashboard-observation.js.map +1 -1
  21. package/dist/products/activity-summary.d.ts +8 -0
  22. package/dist/products/activity-summary.d.ts.map +1 -0
  23. package/dist/products/activity-summary.js +101 -0
  24. package/dist/products/activity-summary.js.map +1 -0
  25. package/dist/products/activity-timeline.d.ts +4 -1
  26. package/dist/products/activity-timeline.d.ts.map +1 -1
  27. package/dist/products/activity-timeline.js +9 -1
  28. package/dist/products/activity-timeline.js.map +1 -1
  29. package/dist/products/dashboard-activity.d.ts +9 -0
  30. package/dist/products/dashboard-activity.d.ts.map +1 -0
  31. package/dist/products/dashboard-activity.js +119 -0
  32. package/dist/products/dashboard-activity.js.map +1 -0
  33. package/dist/products/dashboard-cli.d.ts +2 -1
  34. package/dist/products/dashboard-cli.d.ts.map +1 -1
  35. package/dist/products/dashboard-cli.js +17 -6
  36. package/dist/products/dashboard-cli.js.map +1 -1
  37. package/dist/products/dashboard-components.d.ts +10 -0
  38. package/dist/products/dashboard-components.d.ts.map +1 -0
  39. package/dist/products/dashboard-components.js +196 -0
  40. package/dist/products/dashboard-components.js.map +1 -0
  41. package/dist/products/dashboard-display-controls.d.ts.map +1 -1
  42. package/dist/products/dashboard-display-controls.js +43 -3
  43. package/dist/products/dashboard-display-controls.js.map +1 -1
  44. package/dist/products/dashboard-layout.d.ts +6 -0
  45. package/dist/products/dashboard-layout.d.ts.map +1 -0
  46. package/dist/products/dashboard-layout.js +61 -0
  47. package/dist/products/dashboard-layout.js.map +1 -0
  48. package/dist/products/dashboard-panels.d.ts +4 -0
  49. package/dist/products/dashboard-panels.d.ts.map +1 -1
  50. package/dist/products/dashboard-panels.js +321 -120
  51. package/dist/products/dashboard-panels.js.map +1 -1
  52. package/dist/products/dashboard-recap.d.ts +4 -0
  53. package/dist/products/dashboard-recap.d.ts.map +1 -0
  54. package/dist/products/dashboard-recap.js +43 -0
  55. package/dist/products/dashboard-recap.js.map +1 -0
  56. package/dist/products/dashboard-screen.d.ts +11 -3
  57. package/dist/products/dashboard-screen.d.ts.map +1 -1
  58. package/dist/products/dashboard-screen.js +224 -62
  59. package/dist/products/dashboard-screen.js.map +1 -1
  60. package/dist/products/dashboard-session-client.d.ts +6 -5
  61. package/dist/products/dashboard-session-client.d.ts.map +1 -1
  62. package/dist/products/dashboard-session-client.js.map +1 -1
  63. package/dist/products/ecosystem-versions.d.ts +2 -0
  64. package/dist/products/ecosystem-versions.d.ts.map +1 -1
  65. package/extensions/activity-timeline.ts +7 -1
  66. package/extensions/approvals.ts +7 -0
  67. package/extensions/dashboard-live.ts +45 -5
  68. package/extensions/dashboard-observation.ts +1 -3
  69. package/extensions/delegate-chain.ts +2 -0
  70. package/extensions/delegation-artifacts.ts +34 -4
  71. package/extensions/delegation-operations.ts +12 -4
  72. package/extensions/delegation.ts +4 -0
  73. package/extensions/ecosystem-versions.ts +25 -3
  74. package/extensions/execute-child.ts +4 -0
  75. package/extensions/initiative-handoff.ts +59 -0
  76. package/extensions/initiative-runtime.ts +39 -1
  77. package/extensions/run-delegation.ts +2 -0
  78. package/extensions/runtime-snapshot.ts +8 -4
  79. package/extensions/session.ts +2 -2
  80. package/package.json +1 -1
  81. package/src/governance/approval-prompt.ts +7 -6
  82. package/src/governance/initiative-coordinator.ts +16 -0
  83. package/src/governance/permission-question.ts +108 -0
  84. package/src/kernel/chain.ts +1 -0
  85. package/src/kernel/dashboard-observation.ts +15 -1
  86. package/src/products/activity-summary.ts +101 -0
  87. package/src/products/activity-timeline.ts +11 -0
  88. package/src/products/dashboard-activity.ts +136 -0
  89. package/src/products/dashboard-cli.ts +29 -7
  90. package/src/products/dashboard-components.ts +219 -0
  91. package/src/products/dashboard-display-controls.ts +37 -3
  92. package/src/products/dashboard-layout.ts +71 -0
  93. package/src/products/dashboard-panels.ts +359 -145
  94. package/src/products/dashboard-recap.ts +48 -0
  95. package/src/products/dashboard-screen.ts +264 -68
  96. package/src/products/dashboard-session-client.ts +7 -1
  97. package/src/products/ecosystem-versions.ts +2 -0
@@ -1,9 +1,16 @@
1
1
  /** Six current-session destinations share stable row identities; contributions are labels, never authority. */
2
- import type { DashboardContribution } from "../kernel/dashboard-observation.ts";
2
+ import type { DashboardContribution, DashboardSourceSnapshot } from "../kernel/dashboard-observation.ts";
3
3
  import type { DashboardItem, DashboardScreenOptions } from "./dashboard-screen.ts";
4
- import { dashboardText } from "./dashboard-screen.ts";
4
+ import { dashboardText, friendlyStatus } from "./dashboard-screen.ts";
5
+ import { activityStoryItems } from "./dashboard-activity.ts";
6
+ import {
7
+ componentItems,
8
+ isComponentObservation,
9
+ publishedEvidenceItem,
10
+ savedEvidenceItem,
11
+ } from "./dashboard-components.ts";
12
+ import { previewWidth, sectionHeading } from "./dashboard-layout.ts";
5
13
  import { activityTaskKey } from "./activity-timeline.ts";
6
- import { truncate, cellWidth } from "./dashboard-render.ts";
7
14
  export type DashboardDestination = "now" | "work" | "reviews" | "activity" | "evidence" | "settings";
8
15
  export const DASHBOARD_DESTINATIONS: DashboardDestination[] = [
9
16
  "now",
@@ -14,27 +21,196 @@ export const DASHBOARD_DESTINATIONS: DashboardDestination[] = [
14
21
  "settings",
15
22
  ];
16
23
  const clean = (s: string) => dashboardText(s).replace(/\s+/g, " ").trim();
17
- const row = (item: DashboardContribution, key: string, source: string, stale = false): DashboardItem => ({
18
- key,
19
- label: item.label,
20
- status: stale ? "last-observed" : item.state,
21
- elapsed: "",
22
- agent: item.kind === "work",
23
- details: [
24
- `Source: ${source}`,
25
- `Observed state: ${item.state}${stale ? " (stale/disconnected)" : ""}`,
26
- ...(item.details ?? []),
27
- ...(item.reference ? [`Reference: ${item.reference}`] : []),
28
- ...(item.kind === "review" ? ["A reported judgment is not execution authority or overall task acceptance."] : []),
29
- "Reported observations do not grant execution authority or task approval.",
30
- ...(stale ? ["Current liveness/applicability unknown; no automatic retry."] : []),
31
- ],
32
- });
24
+ export function staleSource(source: DashboardSourceSnapshot, options: DashboardScreenOptions): boolean {
25
+ return (
26
+ options.connected === false ||
27
+ source.availability === "closed" ||
28
+ (options.now?.getTime() ?? Date.now()) - Date.parse(source.observedAt) > source.staleAfterMs
29
+ );
30
+ }
31
+
32
+ const sourceKey = (source: DashboardSourceSnapshot, item: DashboardContribution) =>
33
+ `source:${source.producer}:${source.generation}:${item.id}`;
34
+
35
+ /** A current request for review takes precedence over general workflow suggestions. */
36
+ function sessionNext(options: DashboardScreenOptions) {
37
+ const current = options.session!.observation!.sources.filter((source) => !staleSource(source, options));
38
+ const recommendations = current.flatMap((source) =>
39
+ source.items.filter((item) => item.kind === "next").map((item) => ({ item, source })),
40
+ );
41
+ for (const next of recommendations) {
42
+ if (next.item.state !== "approval-wait") continue;
43
+ const reviews = next.source.items.filter(
44
+ (item) =>
45
+ item.kind === "review" &&
46
+ item.state === "approval-wait" &&
47
+ !(next.source.producer === "bookie" && reviewTotals(item)) &&
48
+ (!next.item.reference || item.reference === next.item.reference),
49
+ );
50
+ if (reviews.length === 1) return { ...next, reviewKey: sourceKey(next.source, reviews[0]!) };
51
+ }
52
+ const general = recommendations.filter(({ item }) => item.state !== "approval-wait" || !item.reference);
53
+ const next =
54
+ general.find(({ item }) => ["dependency-wait", "failed", "unknown", "unavailable"].includes(item.state)) ??
55
+ general[0];
56
+ return next && { ...next, reviewKey: undefined };
57
+ }
58
+
59
+ export function sessionNextLines(options: DashboardScreenOptions): [string, string] {
60
+ if (options.connected === false) return ["NEXT", "Reconnect to the parent Pi session for current work."];
61
+ if (options.session?.pendingApprovals.length)
62
+ return ["NEXT · Permission", "Respond to the permission request in the parent Pi session."];
63
+ const next = sessionNext(options);
64
+ if (!next) {
65
+ const sources = options.session!.observation!.sources;
66
+ if (sources.length && sources.every((source) => staleSource(source, options)))
67
+ return ["NEXT", "Waiting for a current status from Pi."];
68
+ }
69
+ return [
70
+ next?.reviewKey ? "NEXT · [3] Reviews" : "NEXT",
71
+ next ? clean(next.item.label) : "No current next step reported.",
72
+ ];
73
+ }
74
+ function contributionDetails(item: DashboardContribution, source: string, stale: boolean): string[] {
75
+ const details = item.details ?? [];
76
+ if (!source.startsWith("bookie@") || item.kind !== "review" || item.state !== "approval-wait") return details;
77
+ const open = details.find((line) => line.startsWith("Open /bookie-work review"));
78
+ if (stale)
79
+ return details.filter(
80
+ (line) => !line.startsWith("Open /bookie-work review") && !line.startsWith("Record your review decision"),
81
+ );
82
+ return open ? [open, ...details.filter((line) => line !== open)] : details;
83
+ }
84
+ const row = (
85
+ item: DashboardContribution,
86
+ key: string,
87
+ source: string,
88
+ stale = false,
89
+ label = item.label,
90
+ taskReview?: DashboardContribution,
91
+ ): DashboardItem => {
92
+ const details = contributionDetails(item, source, stale);
93
+ const handoff = taskReview ?? item;
94
+ const pendingTask = source.startsWith("bookie@") && item.kind === "work" && item.state === "approval-wait";
95
+ const currentHandoff =
96
+ !stale &&
97
+ source.startsWith("bookie@") &&
98
+ handoff.kind === "review" &&
99
+ handoff.state === "approval-wait" &&
100
+ !reviewTotals(handoff);
101
+ const brief = currentHandoff
102
+ ? contributionDetails(handoff, source, stale).filter(
103
+ (line) =>
104
+ !/^(?:\/|[A-Za-z]:[\\/]|(?:Reference|Source|Observed at):)/i.test(line) &&
105
+ !/\b[a-f0-9]{64}\b/i.test(line) &&
106
+ line !== "Output: handoff",
107
+ )
108
+ : [];
109
+ const openInstruction = brief.indexOf("Open /bookie-work review to read the saved handoff.");
110
+ if (openInstruction >= 0) {
111
+ const choice = taskReview && (label === item.label ? label : item.label.split("/").at(-1));
112
+ brief.splice(
113
+ openInstruction,
114
+ 1,
115
+ "In your main Pi chat, run",
116
+ "/bookie-work review",
117
+ ...(choice ? [`If asked, select ${choice}.`] : []),
118
+ );
119
+ const decision = brief.indexOf("Record your review decision for this output in the selected project.");
120
+ if (decision >= 0) brief[decision] = "Read the output and record your decision.";
121
+ }
122
+ if (currentHandoff && !brief.length) brief.push("Awaiting a review decision for this output.");
123
+ if (!currentHandoff && pendingTask)
124
+ brief.push(
125
+ stale
126
+ ? "Last seen awaiting a decision. Check the parent Pi session for current status."
127
+ : "A decision is pending. Check the selected task in the parent Pi session for its review evidence.",
128
+ );
129
+ return {
130
+ key,
131
+ label,
132
+ status: stale ? "last-observed" : item.state,
133
+ elapsed: "",
134
+ agent: item.kind === "work",
135
+ ...(source.startsWith("bookie@") && reviewTotals(item) ? { reviewSummary: true } : {}),
136
+ ...(brief.length ? { briefDetails: brief } : {}),
137
+ details: [
138
+ ...(stale ? ["Last recorded details. Current state is unknown."] : []),
139
+ ...details,
140
+ ...(label !== item.label ? [item.label] : []),
141
+ `Observed state: ${item.state}${stale ? " (stale/disconnected)" : ""}`,
142
+ `Source: ${source}`,
143
+ ...(item.reference ? [`Reference: ${item.reference}`] : []),
144
+ ...(taskReview?.reference ? [`Saved handoff reference: ${taskReview.reference}`] : []),
145
+ ...(item.kind === "review"
146
+ ? [
147
+ item.state === "approval-wait"
148
+ ? "The reviewer decides on this output."
149
+ : "A reported judgment is not execution authority or overall task acceptance.",
150
+ ]
151
+ : []),
152
+ "Reported observations do not grant execution authority or task approval.",
153
+ ...(stale ? ["Current liveness/applicability unknown; no automatic retry."] : []),
154
+ ],
155
+ };
156
+ };
157
+
158
+ const reviewTotals = (item: DashboardContribution) =>
159
+ item.kind === "review" && item.id === "reviews" && item.label === "Selected output judgment observations";
160
+
161
+ // Bookie publishes work with its task revision and the corresponding review with its output digest.
162
+ // Only the task ID within this one observation links the two records.
163
+ function reviewForTask(item: DashboardContribution, source: DashboardSourceSnapshot, stale: boolean) {
164
+ if (
165
+ stale ||
166
+ source.producer !== "bookie" ||
167
+ item.kind !== "work" ||
168
+ item.state !== "approval-wait" ||
169
+ !item.reference
170
+ )
171
+ return;
172
+ const matches = source.items.filter(
173
+ (candidate) =>
174
+ candidate.id === `review-${item.id}` &&
175
+ candidate.kind === "review" &&
176
+ candidate.state === "approval-wait" &&
177
+ candidate.reference,
178
+ );
179
+ return matches.length === 1 ? matches[0] : undefined;
180
+ }
181
+
182
+ // A Bookie task can publish its canonical document path as its only label.
183
+ // Abbreviate unambiguous sibling names while keeping the full path in Details.
184
+ function bookieLabel(item: DashboardContribution, source: DashboardSourceSnapshot): string {
185
+ if (reviewTotals(item)) return "Review totals";
186
+ if (item.kind !== "work" || !item.label.startsWith("/")) return item.label;
187
+ const name = (label: string) => label.split("/").at(-1)?.replace(/\.md$/i, "").replace(/[-_]+/g, " ");
188
+ const title = name(item.label);
189
+ if (
190
+ !title ||
191
+ !item.label.endsWith(".md") ||
192
+ source.items.some((other) => other.kind === "work" && other.id !== item.id && name(other.label) === title)
193
+ )
194
+ return item.label;
195
+ return title;
196
+ }
197
+
198
+ function rowText(item: DashboardItem, destination: DashboardDestination, selected: boolean): string {
199
+ const label = clean(item.label);
200
+ const marker = selected ? "> " : " ";
201
+ if (item.key.startsWith("component:")) return marker + label;
202
+ if (item.status === "last-observed") return `${marker}Last seen · ${label}`;
203
+ if (item.reviewSummary) return marker + label;
204
+ if (item.key.startsWith("activity:") && item.status === "observed") return marker + label;
205
+ const waitingForReview = destination === "reviews" && item.status === "approval-wait";
206
+ const described = waitingForReview && /^ready for review[:\s]/i.test(label);
207
+ const status = described ? "" : ` · ${waitingForReview ? "Awaiting review" : friendlyStatus(clean(item.status))}`;
208
+ return `${marker}${label}${status}${item.elapsed ? " " + item.elapsed : ""}`;
209
+ }
33
210
  export function sessionDashboardItems(options: DashboardScreenOptions): DashboardItem[] {
34
211
  const observed = options.session!.observation!;
35
212
  const destination = options.screen.destination ?? "now";
36
213
  const staleOwner = options.connected === false;
37
- const now = options.now?.getTime() ?? Date.now();
38
214
  const wanted =
39
215
  destination === "work"
40
216
  ? ["work"]
@@ -44,51 +220,46 @@ export function sessionDashboardItems(options: DashboardScreenOptions): Dashboar
44
220
  ? ["evidence"]
45
221
  : destination === "activity"
46
222
  ? ["status"]
47
- : ["work", "status"];
223
+ : ["work"];
48
224
  const published = observed.sources.flatMap((source) =>
49
225
  source.items
50
226
  .filter(
51
227
  (item) =>
52
228
  wanted.includes(item.kind) &&
229
+ !isComponentObservation(source, item) &&
230
+ !(
231
+ destination === "reviews" &&
232
+ !options.screen.expanded &&
233
+ source.producer === "bookie" &&
234
+ reviewTotals(item) &&
235
+ source.items.some((other) => other.kind === "review" && other.id !== item.id)
236
+ ) &&
53
237
  !(source.producer === "daddy-initiative" && item.id === "scope" && ["now", "work"].includes(destination)),
54
238
  )
55
- .map((item) =>
56
- row(
239
+ .map((item) => {
240
+ const stale = staleSource(source, options);
241
+ const linked = reviewForTask(item, source, stale);
242
+ const display = row(
57
243
  item,
58
- `source:${source.producer}:${source.generation}:${item.id}`,
244
+ sourceKey(source, item),
59
245
  `${source.producer}@${source.producerVersion} · seq ${source.sequence} · ${source.observedAt}`,
60
- staleOwner || source.availability === "closed" || now - Date.parse(source.observedAt) > source.staleAfterMs,
61
- ),
62
- ),
246
+ stale,
247
+ source.producer === "bookie" ? bookieLabel(item, source) : item.label,
248
+ linked,
249
+ );
250
+ if (linked) display.relatedReviewKey = sourceKey(source, linked);
251
+ return item.kind === "evidence" ? publishedEvidenceItem(source, item, display) : display;
252
+ }),
63
253
  );
64
- if (destination === "reviews") return published;
65
- if (destination === "evidence")
66
- return [
67
- ...(observed.artifacts ?? []).map((a) => ({
68
- key: `artifact:${a.executionId}`,
69
- label: a.operationId,
70
- status: "retained",
71
- elapsed: "",
72
- details: [
73
- `Producer: pi-daddy`,
74
- `Execution: ${a.executionId}`,
75
- `Manifest SHA-256: ${a.sha256}`,
76
- "Producer reference observed in this session; payload not loaded by the dashboard.",
77
- "Retained is not reviewed, applicable or approved. Use the authorized artifact resolver for content.",
78
- ],
79
- })),
80
- ...published,
81
- ];
254
+ if (destination === "reviews") {
255
+ const first = sessionNext(options)?.reviewKey;
256
+ const priority = (item: DashboardItem) =>
257
+ item.key === first ? 2 : Number(item.status === "approval-wait" && !item.reviewSummary);
258
+ return published.sort((a, b) => priority(b) - priority(a));
259
+ }
260
+ if (destination === "evidence") return [...(observed.artifacts ?? []).map(savedEvidenceItem), ...published];
82
261
  if (destination === "activity")
83
- return [
84
- ...(observed.activity ?? [])
85
- .slice()
86
- .reverse()
87
- .map((item) =>
88
- row(item, `activity:${observed.generation}:${item.id}`, `Pi owner · ${observed.sessionId}`, staleOwner),
89
- ),
90
- ...published,
91
- ];
262
+ return [...activityStoryItems(observed.activity ?? [], observed.generation, staleOwner), ...published];
92
263
  const native = options.items.map((item) =>
93
264
  staleOwner
94
265
  ? {
@@ -101,115 +272,158 @@ export function sessionDashboardItems(options: DashboardScreenOptions): Dashboar
101
272
  const activity = options.session?.activity;
102
273
  const parentShown =
103
274
  activity && native.some((item) => item.taskKey === activityTaskKey(activity.rootId, activity.taskId));
104
- return [
105
- ...(observed.turn && !parentShown
106
- ? [row(observed.turn, `owner:${observed.generation}:${observed.turn.id}`, "Pi owner", staleOwner)]
275
+ const ownerTurn = observed.turn;
276
+ const tasks = native.map((item) => {
277
+ // A running parent can supply a more recent public tool purpose than its persisted start record.
278
+ if (
279
+ activity &&
280
+ item.taskKey === activityTaskKey(activity.rootId, activity.taskId) &&
281
+ ownerTurn?.state === "running" &&
282
+ !staleOwner &&
283
+ ["running", "active"].includes(item.status)
284
+ )
285
+ return { ...item, label: ownerTurn.label };
286
+ return item;
287
+ });
288
+ const items = [
289
+ ...(ownerTurn && !parentShown
290
+ ? [row(ownerTurn, `owner:${observed.generation}:${ownerTurn.id}`, "Pi owner", staleOwner)]
107
291
  : []),
108
- ...native,
292
+ ...tasks,
109
293
  ...published,
110
294
  ];
295
+ items.sort((a, b) => {
296
+ const rank = workGroups.indexOf(workGroup(a)) - workGroups.indexOf(workGroup(b));
297
+ return rank || (workGroup(a) === "Recently finished" ? (b.updatedAt ?? "").localeCompare(a.updatedAt ?? "") : 0);
298
+ });
299
+ if (destination !== "now") return items;
300
+ // Tasks has the complete queue. Keep the overview navigable even after a long session.
301
+ // A producer may publish a review without a matching task or a recommended next action.
302
+ const represented = new Set(items.map((i) => i.relatedReviewKey).filter(Boolean));
303
+ for (const source of observed.sources) {
304
+ if (staleSource(source, options)) continue;
305
+ for (const review of source.items) {
306
+ const key = sourceKey(source, review);
307
+ if (
308
+ review.kind === "review" &&
309
+ review.state === "approval-wait" &&
310
+ review.reference &&
311
+ !reviewTotals(review) &&
312
+ !represented.has(key)
313
+ )
314
+ items.push(row(review, key, `${source.producer}@${source.producerVersion}`));
315
+ }
316
+ }
317
+ const nextReview = sessionNext(options)?.reviewKey;
318
+ if (nextReview) {
319
+ const index = items.findIndex((i) => i.relatedReviewKey === nextReview || i.key === nextReview);
320
+ // Keep task rows ahead of independent review rows; Reviews opens the exact recommended output.
321
+ if (index > 0 && items[index]?.relatedReviewKey === nextReview) items.unshift(items.splice(index, 1)[0]!);
322
+ }
323
+ const shown = workGroups.flatMap((group) => {
324
+ const matches = items.filter((item) => workGroup(item) === group);
325
+ return matches.slice(0, group === "Recently finished" ? 2 : 3);
326
+ });
327
+ const recent = shown.some((i) => workGroup(i) === "Recently finished")
328
+ ? []
329
+ : activityStoryItems(observed.activity ?? [], observed.generation, staleOwner).slice(0, 2);
330
+ return [...shown, ...recent, ...componentItems(options)];
331
+ }
332
+
333
+ const workGroups = [
334
+ "Needs your permission",
335
+ "Needs your decision",
336
+ "Needs attention",
337
+ "In progress",
338
+ "Other tasks",
339
+ "Recently finished",
340
+ "Last known",
341
+ "Tools",
342
+ ];
343
+ function workGroup(item: DashboardItem): string {
344
+ if (item.key.startsWith("component:")) return "Tools";
345
+ if (item.key.startsWith("activity:")) return "Latest activity";
346
+ if (["last-observed", "historical"].includes(item.status)) return "Last known";
347
+ if (item.approval) return "Needs your permission";
348
+ if (item.status === "approval-wait") return "Needs your decision";
349
+ if (["needs-you", "failed", "refused", "incomplete", "dependency-wait"].includes(item.status))
350
+ return "Needs attention";
351
+ if (["running", "active", "starting", "authorised", "cancel-requested"].includes(item.status)) return "In progress";
352
+ if (["settled", "completed", "finished", "cancelled", "historical", "last-observed"].includes(item.status))
353
+ return "Recently finished";
354
+ return "Other tasks";
355
+ }
356
+
357
+ function listHeading(item: DashboardItem, destination: DashboardDestination) {
358
+ if (destination === "now" || destination === "work")
359
+ return destination === "work" && workGroup(item) === "Recently finished" ? "Finished" : workGroup(item);
360
+ if (destination === "reviews")
361
+ return item.status === "approval-wait" && !item.reviewSummary ? "Waiting for your review" : "Review records";
362
+ return destination === "evidence"
363
+ ? "Saved results"
364
+ : item.key.startsWith("source:")
365
+ ? "Current reports"
366
+ : "What happened";
111
367
  }
112
368
  export function sessionPanelLines(options: DashboardScreenOptions, items: DashboardItem[], width: number): string[] {
113
369
  const observation = options.session!.observation!,
114
370
  screen = options.screen;
115
371
  const destination = screen.destination ?? "now";
116
372
  const sourceRows = observation.sources.flatMap((s) => s.items.map((item) => ({ source: s, item })));
117
- const lines: string[] = [`${destination.toUpperCase()} · CURRENT SESSION`];
118
- const staleSource = (source: (typeof observation.sources)[number]) =>
119
- options.connected === false ||
120
- source.availability === "closed" ||
121
- (options.now?.getTime() ?? Date.now()) - Date.parse(source.observedAt) > source.staleAfterMs;
373
+ const lines: string[] = [];
122
374
  const initiative = observation.sources.find((source) => source.producer === "daddy-initiative");
123
375
  const scope = initiative?.items.find((item) => item.id === "scope");
124
- if (scope && (destination === "now" || destination === "work")) {
125
- lines.push(`SELECTED ${scope.label}${staleSource(initiative!) ? " (last observed)" : ""}`);
126
- if (destination === "work" && scope.details?.[1]) lines.push(scope.details[1]);
376
+ const roomy = options.height >= 22;
377
+ if (destination === "work") {
378
+ lines.push("All session tasks, grouped by status.");
379
+ if (scope) {
380
+ lines.push(`Selected ${clean(scope.label)}${staleSource(initiative!, options) ? " (last known)" : ""}`);
381
+ if (scope.details?.[1]) lines.push(scope.details[1]);
382
+ }
127
383
  }
128
384
  if (destination === "now") {
129
- const goal = sourceRows.find((x) => x.item.kind === "goal");
130
- lines.push(
131
- "GOAL",
132
- goal
133
- ? `${goal.item.label} (${goal.source.producer}${staleSource(goal.source) ? "; stale" : ""})`
134
- : (options.current ?? "Goal not reported; no inference from a finished step."),
135
- );
136
- const next = sourceRows.find((x) => x.item.kind === "next");
137
- const nextStale =
138
- next &&
139
- (options.connected === false ||
140
- next.source.availability === "closed" ||
141
- (options.now?.getTime() ?? Date.now()) - Date.parse(next.source.observedAt) > next.source.staleAfterMs);
142
- lines.push(
143
- "NEXT",
144
- next
145
- ? `${next.item.label} (${next.source.producer}${nextStale ? "; stale" : ""})`
146
- : "No coordinator recommendation reported.",
147
- );
148
- const attention = items.filter((x) =>
149
- [
150
- "failed",
151
- "refused",
152
- "incomplete",
153
- "unknown",
154
- "unavailable",
155
- "needs-you",
156
- "approval-wait",
157
- "dependency-wait",
158
- "cancel-requested",
159
- ].includes(x.status),
160
- );
161
- if (attention.length) {
162
- lines.push(`ATTENTION · ${attention.length}`);
163
- for (const item of attention.slice(0, 3)) lines.push(`${item.label} · ${item.status}`);
385
+ const goals = sourceRows.filter((x) => x.item.kind === "goal");
386
+ const goal = goals.find((x) => !staleSource(x.source, options)) ?? goals[0];
387
+ if (goal) {
388
+ const project = goal.source.producer === "bookie" && /^\/projects\/([^/]+)\/project\.md$/.exec(goal.item.label);
389
+ lines.push(project ? `Project · ${clean(project[1]!)}` : `Goal · ${clean(goal.item.label)}`);
390
+ if (staleSource(goal.source, options)) lines[lines.length - 1] += " (last known)";
164
391
  }
165
- const result = [...items].reverse().find((x) => ["settled", "finished", "completed"].includes(x.status));
166
- if (result) lines.push(`LATEST UPDATE · ${result.label} (${result.status})`);
167
392
  }
168
-
169
- if (!items.length)
170
- lines.push(
393
+ if (!items.length) {
394
+ const fallback =
171
395
  destination === "reviews"
172
- ? "No review producer observations available."
396
+ ? options.connected === false || observation.sources.some((s) => staleSource(s, options))
397
+ ? "Current reviews unknown. Check the main Pi chat."
398
+ : "No reviews waiting. Open [2] Tasks to see progress."
173
399
  : destination === "evidence"
174
- ? "No current-session result references observed."
175
- : "No observations for this view.",
176
- );
177
- const selected = items.find((x) => x.key === screen.selectedKey);
178
- const rows = items.map(
179
- (x) =>
180
- `${x.key === screen.selectedKey ? ">" : " "} ${clean(x.label)} · ${clean(x.status)}${x.elapsed ? " " + x.elapsed : ""}`,
181
- );
182
- const expanded = screen.expanded && width >= 96;
183
- if (expanded && rows.length) {
184
- const left = Math.floor(width * 0.45),
185
- right = width - left - 3;
186
- const details = [selected ? `DETAIL · ${clean(selected.label)}` : "DETAIL", ...(selected?.details ?? [])];
187
- const length = Math.max(rows.length, details.length);
188
- for (let i = 0; i < length; i++) {
189
- const a = truncate(clean(rows[i] ?? ""), left);
190
- lines.push(a + " ".repeat(Math.max(0, left - cellWidth(a))) + " | " + truncate(clean(details[i] ?? ""), right));
191
- }
192
- } else {
193
- lines.push(...rows);
194
- if (screen.expanded) lines.push("Expanded layout needs 96 columns; same selection retained.");
400
+ ? "No saved results reported to this dashboard."
401
+ : destination === "activity"
402
+ ? "No activity has been recorded in this session yet."
403
+ : "No tasks reported for this session yet.";
404
+ lines.push(fallback);
195
405
  }
196
- if (destination === "now") {
197
- lines.push("COMPONENTS");
198
- for (const producer of ["principal", "bookie", "scout", "skill-harness"]) {
199
- const streams = observation.sources.filter(
200
- (x) => x.producer === producer || (producer === "scout" && x.producer.startsWith("scout-")),
201
- );
202
- const stale = streams.filter(
203
- (s) =>
204
- options.connected === false ||
205
- s.availability === "closed" ||
206
- (options.now?.getTime() ?? Date.now()) - Date.parse(s.observedAt) > s.staleAfterMs,
207
- ).length;
208
- const status = !streams.length
209
- ? "status adapter unavailable"
210
- : `${streams.length - stale} observed${stale ? `; ${stale} last observed / stale` : ""}`;
211
- lines.push(`${producer}: ${status}`);
212
- }
406
+ const left = previewWidth(destination, Boolean(screen.expanded), width);
407
+ const rows: string[] = [];
408
+ for (let start = 0; start < items.length;) {
409
+ const group = listHeading(items[start]!, destination);
410
+ let end = start + 1;
411
+ while (end < items.length && listHeading(items[end]!, destination) === group) end++;
412
+ if (roomy && (rows.length || lines.length)) rows.push("");
413
+ const count = destination === "now" ? "" : ` · ${end - start}`;
414
+ rows.push(sectionHeading(group + count, left ?? width));
415
+ for (const item of items.slice(start, end)) rows.push(rowText(item, destination, item.key === screen.selectedKey));
416
+ start = end;
417
+ }
418
+ lines.push(...rows);
419
+ if (destination === "now" && options.height >= 18 && items.some((i) => !i.key.startsWith("component:"))) {
420
+ if (roomy) lines.push("");
421
+ lines.push("[2] Tasks · See the full task list");
422
+ }
423
+ if (screen.expanded && left === undefined)
424
+ lines.push("Side-by-side layout needs 82 columns; same selection retained.");
425
+ if (destination === "now" && screen.expanded) {
426
+ lines.push(sectionHeading("Resource details", width));
213
427
  const resource = observation.resources;
214
428
  lines.push(`Parent RSS: ${(resource.rssBytes / 1024 / 1024).toFixed(1)} MiB`, "Host and child memory: unknown");
215
429
  }
@@ -0,0 +1,48 @@
1
+ import { activityStoryItems } from "./dashboard-activity.ts";
2
+ import { staleSource } from "./dashboard-panels.ts";
3
+ import type { DashboardScreenOptions } from "./dashboard-screen.ts";
4
+
5
+ /** Current owner hook events, newest first. Producer snapshots can describe current state only. */
6
+ export function sessionRecapLines(options: DashboardScreenOptions): string[] {
7
+ const session = options.session;
8
+ const observed = session?.observation;
9
+ if (!session || !observed)
10
+ return [
11
+ options.connected === false
12
+ ? "Disconnected · no observed session activity."
13
+ : "No session activity has been observed.",
14
+ ];
15
+
16
+ const lines: string[] = [];
17
+ if (options.connected === false) {
18
+ lines.push("Disconnected · last observed activity");
19
+ } else {
20
+ const work = observed.sources.find((source) => source.producer === "bookie" && !staleSource(source, options));
21
+ const ready = work?.items.filter(
22
+ (item) => item.kind === "review" && item.id !== "reviews" && item.state === "approval-wait" && item.reference,
23
+ ).length;
24
+ const waiting = work?.items.filter((item) => item.kind === "work" && item.state === "dependency-wait").length;
25
+ if (session.pendingApprovals.length) lines.push(`Pending permissions: ${session.pendingApprovals.length}`);
26
+ if (ready) lines.push(`Ready for review · ${ready} shown by Bookie`);
27
+ if (waiting) lines.push(`Waiting on a dependency · ${waiting} shown by Bookie`);
28
+ }
29
+
30
+ const recent = activityStoryItems(observed.activity ?? [], observed.generation, false).slice(0, 5);
31
+ lines.push(
32
+ ...(recent.length
33
+ ? [
34
+ "Recent activity · newest first",
35
+ ...recent.map((item) =>
36
+ item.status === "failed"
37
+ ? `Failed · ${item.label}`
38
+ : item.status === "finished"
39
+ ? `Finished · ${item.label}`
40
+ : item.status === "Started"
41
+ ? `Started · ${item.label}`
42
+ : item.label,
43
+ ),
44
+ ]
45
+ : ["No recent session events recorded."]),
46
+ );
47
+ return lines;
48
+ }