pi-daddy 0.57.0 → 0.58.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 (42) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/kernel/dashboard-observation.d.ts +40 -0
  3. package/dist/kernel/dashboard-observation.d.ts.map +1 -1
  4. package/dist/kernel/dashboard-observation.js +42 -3
  5. package/dist/kernel/dashboard-observation.js.map +1 -1
  6. package/dist/products/dashboard-cli.d.ts.map +1 -1
  7. package/dist/products/dashboard-cli.js +1 -1
  8. package/dist/products/dashboard-cli.js.map +1 -1
  9. package/dist/products/dashboard-components.d.ts.map +1 -1
  10. package/dist/products/dashboard-components.js +57 -8
  11. package/dist/products/dashboard-components.js.map +1 -1
  12. package/dist/products/dashboard-inventory-view.d.ts +9 -0
  13. package/dist/products/dashboard-inventory-view.d.ts.map +1 -0
  14. package/dist/products/dashboard-inventory-view.js +44 -0
  15. package/dist/products/dashboard-inventory-view.js.map +1 -0
  16. package/dist/products/dashboard-layout.js +4 -3
  17. package/dist/products/dashboard-layout.js.map +1 -1
  18. package/dist/products/dashboard-panels.d.ts.map +1 -1
  19. package/dist/products/dashboard-panels.js +7 -3
  20. package/dist/products/dashboard-panels.js.map +1 -1
  21. package/dist/products/dashboard-screen.d.ts +2 -0
  22. package/dist/products/dashboard-screen.d.ts.map +1 -1
  23. package/dist/products/dashboard-screen.js +9 -4
  24. package/dist/products/dashboard-screen.js.map +1 -1
  25. package/dist/products/dashboard-session-client.d.ts +4 -2
  26. package/dist/products/dashboard-session-client.d.ts.map +1 -1
  27. package/dist/products/dashboard-session-client.js +24 -7
  28. package/dist/products/dashboard-session-client.js.map +1 -1
  29. package/extensions/dashboard-session-server.ts +4 -0
  30. package/extensions/dashboard-source-refresh.ts +95 -0
  31. package/extensions/dashboard-sources.ts +42 -4
  32. package/extensions/runtime-snapshot.ts +1 -0
  33. package/extensions/session.ts +1 -0
  34. package/package.json +1 -1
  35. package/src/kernel/dashboard-observation.ts +86 -4
  36. package/src/products/dashboard-cli.ts +1 -0
  37. package/src/products/dashboard-components.ts +57 -9
  38. package/src/products/dashboard-inventory-view.ts +44 -0
  39. package/src/products/dashboard-layout.ts +6 -4
  40. package/src/products/dashboard-panels.ts +9 -3
  41. package/src/products/dashboard-screen.ts +11 -4
  42. package/src/products/dashboard-session-client.ts +31 -11
@@ -0,0 +1,95 @@
1
+ /** Visible-client demand may recheck bounded metadata; no timer starts work on its own. */
2
+ import type {
3
+ DashboardSourceRefreshCallback,
4
+ DashboardSourceSnapshot,
5
+ DashboardSourceUpdate,
6
+ } from "../src/kernel/dashboard-observation.ts";
7
+
8
+ export const DASHBOARD_REFRESH_INTERVAL_MS = 30_000;
9
+ export const DASHBOARD_REFRESH_TIMEOUT_MS = 5_000;
10
+ const MAX_BACKOFF_MS = 300_000;
11
+
12
+ export function dashboardSourceRefresh(
13
+ snapshot: DashboardSourceSnapshot,
14
+ refresh: DashboardSourceRefreshCallback,
15
+ active: () => boolean,
16
+ publish: (value: DashboardSourceUpdate) => boolean,
17
+ now: () => number,
18
+ ) {
19
+ let closed = false,
20
+ failures = 0,
21
+ nextAttempt = 0;
22
+ let lastAttempt: number | undefined;
23
+ let pending:
24
+ | { controller: AbortController; timer: ReturnType<typeof setTimeout>; failed: boolean; attemptedAt: string }
25
+ | undefined;
26
+ snapshot.refresh = { state: "idle" };
27
+ const current = () => !closed && active();
28
+ return {
29
+ observed(replacedInventory: boolean) {
30
+ if (!current()) return;
31
+ if (snapshot.refresh?.state === "failed" && !replacedInventory) return;
32
+ if (pending && !pending.controller.signal.aborted && !replacedInventory) return;
33
+ pending?.controller.abort();
34
+ if (pending) clearTimeout(pending.timer);
35
+ failures = 0;
36
+ nextAttempt = lastAttempt === undefined ? 0 : lastAttempt + DASHBOARD_REFRESH_INTERVAL_MS;
37
+ snapshot.refresh = {
38
+ state: "idle",
39
+ ...(nextAttempt ? { nextAttemptAt: new Date(nextAttempt).toISOString() } : {}),
40
+ };
41
+ },
42
+ request() {
43
+ if (!current()) return false;
44
+ if (pending) return !pending.controller.signal.aborted;
45
+ const time = now();
46
+ if (time < nextAttempt) return false;
47
+ lastAttempt = time;
48
+ const controller = new AbortController(),
49
+ attemptedAt = new Date(time).toISOString();
50
+ const fail = () => {
51
+ if (!current() || pending !== attempt || attempt.failed) return;
52
+ attempt.failed = true;
53
+ failures++;
54
+ nextAttempt = now() + Math.min(DASHBOARD_REFRESH_INTERVAL_MS * 2 ** (failures - 1), MAX_BACKOFF_MS);
55
+ snapshot.refresh = { state: "failed", attemptedAt, nextAttemptAt: new Date(nextAttempt).toISOString() };
56
+ };
57
+ const timer = setTimeout(() => {
58
+ controller.abort();
59
+ fail();
60
+ }, DASHBOARD_REFRESH_TIMEOUT_MS);
61
+ timer.unref?.();
62
+ const attempt = { controller, timer, failed: false, attemptedAt };
63
+ pending = attempt;
64
+ snapshot.refresh = { state: "checking", attemptedAt };
65
+ void Promise.resolve()
66
+ .then(() => {
67
+ if (current() && !controller.signal.aborted) return refresh({ signal: controller.signal });
68
+ })
69
+ .then((value) => {
70
+ if (!current() || controller.signal.aborted || pending !== attempt) return;
71
+ if (!value || !publish(value)) {
72
+ fail();
73
+ return;
74
+ }
75
+ failures = 0;
76
+ nextAttempt = now() + DASHBOARD_REFRESH_INTERVAL_MS;
77
+ snapshot.refresh = { state: "idle", attemptedAt, nextAttemptAt: new Date(nextAttempt).toISOString() };
78
+ })
79
+ .catch(() => {
80
+ if (!controller.signal.aborted) fail();
81
+ })
82
+ .finally(() => {
83
+ clearTimeout(timer);
84
+ if (pending === attempt) pending = undefined;
85
+ });
86
+ return true;
87
+ },
88
+ close() {
89
+ closed = true;
90
+ pending?.controller.abort();
91
+ if (pending) clearTimeout(pending.timer);
92
+ snapshot.refresh = { ...snapshot.refresh, state: "idle" };
93
+ },
94
+ };
95
+ }
@@ -1,5 +1,6 @@
1
1
  /** Optional trusted producers publish display observations; no automatic work, tools, or persistent store. */
2
2
  import { registerDashboardChoiceOwner } from "./dashboard-choice-controls.ts";
3
+ import { dashboardSourceRefresh } from "./dashboard-source-refresh.ts";
3
4
  import { randomUUID } from "node:crypto";
4
5
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
5
6
  import {
@@ -8,6 +9,7 @@ import {
8
9
  isBookieChoice,
9
10
  validDashboardSourceUpdate,
10
11
  type DashboardSourceSnapshot,
12
+ type DashboardSourceRefreshCallback,
11
13
  type DashboardSourceUpdate,
12
14
  } from "../src/kernel/dashboard-observation.ts";
13
15
  export interface DashboardSourceOwner {
@@ -20,6 +22,7 @@ export function registerDashboardSources(
20
22
  now: () => number = Date.now,
21
23
  ) {
22
24
  const sources = new Map<string, DashboardSourceSnapshot>();
25
+ const refreshers = new Map<string, ReturnType<typeof dashboardSourceRefresh>>();
23
26
  let closed = false;
24
27
  let owner = current(),
25
28
  generation = randomUUID(),
@@ -29,6 +32,8 @@ export function registerDashboardSources(
29
32
  const selected = current();
30
33
  if (selected !== owner) {
31
34
  owner = selected;
35
+ for (const refresh of refreshers.values()) refresh.close();
36
+ refreshers.clear();
32
37
  sources.clear();
33
38
  generation = randomUUID();
34
39
  sequence = 0;
@@ -51,6 +56,7 @@ export function registerDashboardSources(
51
56
  cwd?: unknown;
52
57
  producer?: unknown;
53
58
  producerVersion?: unknown;
59
+ refresh?: unknown;
54
60
  reply?: (value: unknown) => void;
55
61
  };
56
62
  if (r?.version !== 1 || typeof r.reply !== "function") return;
@@ -71,6 +77,7 @@ export function registerDashboardSources(
71
77
  typeof r.producerVersion !== "string" ||
72
78
  !r.producerVersion ||
73
79
  r.producerVersion.length > 80 ||
80
+ (r.refresh !== undefined && typeof r.refresh !== "function") ||
74
81
  (!sources.has(r.producer) && sources.size >= DASHBOARD_SOURCE_LIMIT)
75
82
  ) {
76
83
  reply({ version: 1, ok: false, reason: "dashboard source registration unavailable" });
@@ -89,21 +96,44 @@ export function registerDashboardSources(
89
96
  items: [],
90
97
  };
91
98
  sources.set(producer, snapshot);
99
+ refreshers.get(producer)?.close();
100
+ refreshers.delete(producer);
92
101
  const active = () =>
93
102
  reconcile() === selected && sources.get(producer) === snapshot && snapshot.availability !== "closed";
103
+ const publish = (value: DashboardSourceUpdate) => {
104
+ if (!active() || !validDashboardSourceUpdate(value) || value.sequence <= snapshot.sequence) return false;
105
+ snapshot.sequence = value.sequence;
106
+ snapshot.items = structuredClone(value.items);
107
+ if (value.inventory) snapshot.inventory = structuredClone(value.inventory);
108
+ else delete snapshot.inventory;
109
+ snapshot.observedAt = new Date(now()).toISOString();
110
+ return true;
111
+ };
112
+ if (r.refresh)
113
+ refreshers.set(
114
+ producer,
115
+ dashboardSourceRefresh(snapshot, r.refresh as DashboardSourceRefreshCallback, active, publish, now),
116
+ );
94
117
  reply({
95
118
  version: 1,
96
119
  ok: true,
97
120
  generation: token,
121
+ capabilities: { inventory: 1, refresh: 1 },
98
122
  publish(value: DashboardSourceUpdate) {
99
- if (!active() || !validDashboardSourceUpdate(value) || value.sequence <= snapshot.sequence) return false;
100
- snapshot.sequence = value.sequence;
101
- snapshot.items = structuredClone(value.items);
102
- snapshot.observedAt = new Date(now()).toISOString();
123
+ const previousInventory = snapshot.inventory;
124
+ if (!publish(value)) return false;
125
+ refreshers
126
+ .get(producer)
127
+ ?.observed(
128
+ value.inventory !== undefined && JSON.stringify(previousInventory) !== JSON.stringify(value.inventory),
129
+ );
103
130
  return true;
104
131
  },
105
132
  close() {
106
133
  if (active()) {
134
+ refreshers.get(producer)?.close();
135
+ refreshers.delete(producer);
136
+ delete snapshot.inventory;
107
137
  snapshot.items = snapshot.items.filter((item) => !isBookieChoice(producer, item));
108
138
  snapshot.availability = "closed";
109
139
  snapshot.observedAt = new Date(now()).toISOString();
@@ -113,6 +143,12 @@ export function registerDashboardSources(
113
143
  });
114
144
  return {
115
145
  choices,
146
+ requestRefresh() {
147
+ if (!reconcile()) return false;
148
+ let requested = false;
149
+ for (const refresh of refreshers.values()) requested = refresh.request() || requested;
150
+ return requested;
151
+ },
116
152
  snapshot() {
117
153
  const selected = reconcile();
118
154
  return selected
@@ -128,6 +164,8 @@ export function registerDashboardSources(
128
164
  },
129
165
  close() {
130
166
  closed = true;
167
+ for (const refresh of refreshers.values()) refresh.close();
168
+ refreshers.clear();
131
169
  choices.close();
132
170
  off?.();
133
171
  sources.clear();
@@ -36,6 +36,7 @@ export function registerRuntimeSnapshot(
36
36
  : undefined,
37
37
  );
38
38
  session.dashboardObservations = () => dashboardSources.snapshot();
39
+ session.dashboardRefreshSources = () => dashboardSources.requestRefresh();
39
40
  session.dashboardChoices = dashboardSources.choices;
40
41
  session.dashboardLive = registerDashboardLive(pi, () =>
41
42
  bound?.lifecycle === session.reloadLifecycle && session.reloadLifecycle.runtimeSnapshotGeneration === generation
@@ -156,6 +156,7 @@ export interface GrantsSession extends NativeSessionHost {
156
156
  dashboardArtifacts?: DashboardSavedEvidence[];
157
157
  dashboardChoices?: ReturnType<typeof import("./dashboard-choice-controls.ts").registerDashboardChoiceOwner>;
158
158
  dashboardObservations?: () => Omit<DashboardOwnerObservation, "version" | "resources" | "capture"> | undefined;
159
+ dashboardRefreshSources?: () => boolean;
159
160
  autoMode?: AutoModeReader;
160
161
  autoModeFailure?: string;
161
162
  /** Reconciled from the actual owner root on reload; captured call owners stay immutable. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-daddy",
3
- "version": "0.57.0",
3
+ "version": "0.58.0",
4
4
  "description": "Capability governance for pi sub-agents: spawn Agent Skills (SKILL.md) definitions whose allowed-tools becomes a grant that can only narrow going down a delegation tree, enforced by pi's own --tools allowlist, with an append-only ledger.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -2,6 +2,9 @@
2
2
  export const DASHBOARD_SOURCE_EVENT = "pi-daddy:dashboard-source:v1";
3
3
  export const DASHBOARD_SOURCE_LIMIT = 8;
4
4
  export const DASHBOARD_SOURCE_BYTES = 4096;
5
+ export const DASHBOARD_INVENTORY_BYTES = 8192;
6
+ export const DASHBOARD_INVENTORY_ENTRIES = 12;
7
+ export const DASHBOARD_RESPONSE_BYTES = 64 * 1024 + DASHBOARD_SOURCE_LIMIT * DASHBOARD_INVENTORY_BYTES;
5
8
  export type DashboardContributionKind = "goal" | "next" | "work" | "review" | "evidence" | "status";
6
9
  export type DashboardObservedState =
7
10
  | "observed"
@@ -26,20 +29,58 @@ export interface DashboardContribution {
26
29
  export const isBookieChoice = (producer: string, item: DashboardContribution) =>
27
30
  producer === "bookie-memory" && item.id.startsWith("open-choice-");
28
31
 
32
+ export interface DashboardInventoryEntry {
33
+ id: string;
34
+ title: string;
35
+ summary: string;
36
+ details?: string[];
37
+ /** Exact display reference only; opening inventory never dereferences it or grants access. */
38
+ reference?: string;
39
+ }
40
+ export interface DashboardInventory {
41
+ scope: string;
42
+ state: "available" | "empty" | "unavailable" | "unknown";
43
+ summary: string;
44
+ /** Exact visible total only when known. Omit it for an incomplete or unauthorized scan. */
45
+ count?: number;
46
+ /** The displayed/enumerated entries are a bounded selection; count may still be exact. */
47
+ limited: boolean;
48
+ entries: DashboardInventoryEntry[];
49
+ }
29
50
  export interface DashboardSourceUpdate {
30
51
  sequence: number;
31
52
  items: DashboardContribution[];
53
+ /** Send only after the registration reply advertises capabilities.inventory === 1. */
54
+ inventory?: DashboardInventory;
55
+ }
56
+ export interface DashboardSourceRefresh {
57
+ state: "idle" | "checking" | "failed";
58
+ attemptedAt?: string;
59
+ nextAttemptAt?: string;
32
60
  }
61
+ /** Return a fresh bounded observation; never publish from inside the refresh callback. */
62
+ export type DashboardSourceRefreshCallback = (request: {
63
+ signal: AbortSignal;
64
+ }) => DashboardSourceUpdate | undefined | Promise<DashboardSourceUpdate | undefined>;
33
65
  /** Trusted in-process registration. Callbacks are never serialized to a model or terminal client. */
34
66
  export type DashboardSourceRegistrationReply =
35
67
  | { version: 1; ok: false; reason: string }
36
- | { version: 1; ok: true; generation: string; publish(update: DashboardSourceUpdate): boolean; close(): void };
68
+ | {
69
+ version: 1;
70
+ ok: true;
71
+ generation: string;
72
+ capabilities?: { inventory: 1; refresh: 1 };
73
+ publish(update: DashboardSourceUpdate): boolean;
74
+ close(): void;
75
+ };
37
76
  export interface DashboardSourceRegistration {
38
77
  version: 1;
39
78
  sessionId: string;
40
79
  cwd: string;
41
80
  producer: string;
42
81
  producerVersion: string;
82
+ /** Authorized metadata reads only, with cancellation; no automatic work or model calls. */
83
+ refresh?: DashboardSourceRefreshCallback;
43
84
  reply(value: DashboardSourceRegistrationReply): void;
44
85
  }
45
86
  export interface DashboardSourceSnapshot extends DashboardSourceUpdate {
@@ -49,6 +90,7 @@ export interface DashboardSourceSnapshot extends DashboardSourceUpdate {
49
90
  observedAt: string;
50
91
  staleAfterMs: number;
51
92
  availability: "observed" | "closed";
93
+ refresh?: DashboardSourceRefresh;
52
94
  }
53
95
  /** Session-local display metadata from the same elected child that published the reference. */
54
96
  export interface DashboardResultDescription {
@@ -87,14 +129,53 @@ export interface DashboardOwnerObservation {
87
129
  }
88
130
  const object = (x: unknown): x is Record<string, unknown> => !!x && typeof x === "object" && !Array.isArray(x);
89
131
  const bounded = (x: unknown, max: number): x is string => typeof x === "string" && x.length > 0 && x.length <= max;
132
+ export function validDashboardInventory(value: unknown): value is DashboardInventory {
133
+ if (
134
+ !object(value) ||
135
+ Object.keys(value).some((k) => !["scope", "state", "summary", "count", "limited", "entries"].includes(k)) ||
136
+ !bounded(value.scope, 160) ||
137
+ !bounded(value.summary, 480) ||
138
+ !["available", "empty", "unavailable", "unknown"].includes(String(value.state)) ||
139
+ typeof value.limited !== "boolean" ||
140
+ !Array.isArray(value.entries) ||
141
+ value.entries.length > DASHBOARD_INVENTORY_ENTRIES ||
142
+ (value.count !== undefined && (!Number.isSafeInteger(value.count) || Number(value.count) < value.entries.length)) ||
143
+ (value.state === "empty" && (value.entries.length > 0 || value.limited || value.count !== 0)) ||
144
+ (["unavailable", "unknown"].includes(String(value.state)) &&
145
+ (value.entries.length > 0 || value.count !== undefined))
146
+ )
147
+ return false;
148
+ const ids = new Set<string>();
149
+ for (const entry of value.entries) {
150
+ if (
151
+ !object(entry) ||
152
+ Object.keys(entry).some((k) => !["id", "title", "summary", "details", "reference"].includes(k)) ||
153
+ !bounded(entry.id, 160) ||
154
+ ids.has(entry.id) ||
155
+ !bounded(entry.title, 160) ||
156
+ !bounded(entry.summary, 480) ||
157
+ (entry.reference !== undefined && !bounded(entry.reference, 512)) ||
158
+ (entry.details !== undefined &&
159
+ (!Array.isArray(entry.details) || entry.details.length > 6 || !entry.details.every((x) => bounded(x, 480))))
160
+ )
161
+ return false;
162
+ ids.add(entry.id);
163
+ }
164
+ try {
165
+ return Buffer.byteLength(JSON.stringify(value)) <= DASHBOARD_INVENTORY_BYTES;
166
+ } catch {
167
+ return false;
168
+ }
169
+ }
90
170
  export function validDashboardSourceUpdate(value: unknown): value is DashboardSourceUpdate {
91
171
  if (
92
172
  !object(value) ||
93
- Object.keys(value).some((k) => !["sequence", "items"].includes(k)) ||
173
+ Object.keys(value).some((k) => !["sequence", "items", "inventory"].includes(k)) ||
94
174
  !Number.isSafeInteger(value.sequence) ||
95
175
  Number(value.sequence) < 0 ||
96
176
  !Array.isArray(value.items) ||
97
- value.items.length > 8
177
+ value.items.length > 8 ||
178
+ (value.inventory !== undefined && !validDashboardInventory(value.inventory))
98
179
  )
99
180
  return false;
100
181
  const ids = new Set<string>();
@@ -125,7 +206,8 @@ export function validDashboardSourceUpdate(value: unknown): value is DashboardSo
125
206
  ids.add(row.id);
126
207
  }
127
208
  try {
128
- if (Buffer.byteLength(JSON.stringify(value)) > DASHBOARD_SOURCE_BYTES) return false;
209
+ if (Buffer.byteLength(JSON.stringify({ sequence: value.sequence, items: value.items })) > DASHBOARD_SOURCE_BYTES)
210
+ return false;
129
211
  } catch {
130
212
  return false;
131
213
  }
@@ -382,6 +382,7 @@ export async function runDashboard(argv = process.argv.slice(2), env: NodeJS.Pro
382
382
  ["now", "work"].includes(display.screen.destination ?? "now");
383
383
  await connection.refresh(
384
384
  interactive && editingChoice ? "picker" : interactive && showsChoices ? "list" : undefined,
385
+ interactive,
385
386
  );
386
387
  const jev = connection.state.snapshot?.settings?.jev;
387
388
  if (notice === JEV_CONSENT_NOTICE && jev && !jev.pending) notice = dashboardJevNotice(jev);
@@ -9,12 +9,15 @@ import { validChoiceId } from "../kernel/dashboard-choice.ts";
9
9
  import { isBookieChoice } from "../kernel/dashboard-observation.ts";
10
10
  import type { EcosystemVersionRow } from "./ecosystem-versions.ts";
11
11
  import { safeDashboardSummary } from "./activity-summary.ts";
12
+ import { inventoryPresentation, observationAge } from "./dashboard-inventory-view.ts";
12
13
 
13
14
  const BOOKIE_LIMIT_MESSAGE = "Only a bounded selection of saved open choices could be displayed.";
14
15
 
15
16
  type KnownSource = "bookie" | "scout-local" | "scout-worker";
16
17
 
17
18
  export function isComponentObservation(source: DashboardSourceSnapshot, item: DashboardContribution): boolean {
19
+ if (["bookie-memory", "scout-local", "scout-worker"].includes(source.producer) && item.id === "availability")
20
+ return item.kind === "status";
18
21
  if (source.producer === "bookie-memory") return item.id === "project-memory" && item.kind === "work";
19
22
  return (
20
23
  (source.producer === "scout-local" || source.producer === "scout-worker") &&
@@ -71,6 +74,15 @@ function scoutDescription(worker: boolean, item: DashboardContribution): [string
71
74
  }
72
75
  }
73
76
 
77
+ function memoryDescription(item: DashboardContribution | undefined, partial: boolean): [string, string] {
78
+ if (item?.state === "observed")
79
+ return ["Ready in this folder", "Bookie can save and recall routine notes for this workspace."];
80
+ return [
81
+ item?.state === "unavailable" ? "Memory unavailable" : partial ? "Notes partially checked" : "Cannot check notes",
82
+ item?.details?.[0] ?? "The current project notes could not be checked. Previous history is not confirmed empty.",
83
+ ];
84
+ }
85
+
74
86
  /** Choices are current project observations; a saved question never creates a live input request. */
75
87
  export function bookieOpenChoices(options: DashboardScreenOptions): DashboardItem[] {
76
88
  const source = options.session?.observation?.sources.find((s) => s.producer === "bookie-memory");
@@ -125,8 +137,7 @@ function componentItem(producer: KnownSource, options: DashboardScreenOptions):
125
137
  const workSource = sources?.find((s) => s.producer === producer);
126
138
  const memory = bookie
127
139
  ? sources?.find(
128
- (s) =>
129
- s.producer === "bookie-memory" && s.items.some((i) => isComponentObservation(s, i) && i.state === "observed"),
140
+ (s) => s.producer === "bookie-memory" && s.items.some((i) => isComponentObservation(s, i) && i.kind === "work"),
130
141
  )
131
142
  : undefined;
132
143
  const source =
@@ -134,27 +145,48 @@ function componentItem(producer: KnownSource, options: DashboardScreenOptions):
134
145
 
135
146
  const pkg = options.session?.versions?.rows.find((r) => r.id === (bookie ? "bookie-pi-skills" : "pi-scout-research"));
136
147
  if (!source && !(pkg?.source || pkg?.loadedVersion || pkg?.installedVersion || pkg?.state === "multiple")) return;
137
- const item = source?.items.find((i) => isComponentObservation(source, i));
148
+ const item = source?.items.find((i) => isComponentObservation(source, i) && i.kind === "work");
149
+ const availability = source?.items.find((i) => i.id === "availability" && i.kind === "status");
138
150
  let state = "observed",
139
151
  status: string,
140
152
  explanation: string;
141
153
  if (
142
154
  options.connected === false ||
155
+ source?.refresh?.state === "failed" ||
143
156
  (source &&
144
157
  !current(source, options) &&
145
158
  !(source.producer === "bookie-memory" && options.session?.auto.enabled === false))
146
159
  ) {
147
160
  state = "last-observed";
148
- status = "Live status unknown";
161
+ status =
162
+ options.connected === false
163
+ ? "Disconnected"
164
+ : source?.availability === "closed"
165
+ ? "Status connection ended"
166
+ : source?.refresh?.state === "checking"
167
+ ? "Checking status"
168
+ : source?.refresh?.state === "failed"
169
+ ? "Status check unavailable"
170
+ : "Status update overdue";
149
171
  const lastReport =
150
172
  source?.producer === "bookie-memory"
151
- ? "Ready in this folder"
173
+ ? memoryDescription(item, source.inventory?.state === "available")[0]
152
174
  : item
153
175
  ? scoutDescription(worker, item)[0]
154
176
  : bookie && source?.items.some((i) => i.kind === "goal" && i.id === "scope")
155
177
  ? "Project connected"
156
178
  : undefined;
157
- explanation = (lastReport ? `Last report: ${lastReport}. ` : "") + "Check the main Pi chat for current status.";
179
+ explanation =
180
+ (lastReport ? `Last report: ${lastReport}. ` : "") +
181
+ (options.connected === false
182
+ ? "Reconnect to Pi to check current availability."
183
+ : source?.availability === "closed"
184
+ ? "The producer's status connection is no longer active."
185
+ : source?.refresh?.state === "checking"
186
+ ? "A fresh status check is in progress."
187
+ : source?.refresh?.state === "failed"
188
+ ? "The producer could not return a current report; a later refresh can try again."
189
+ : "The previous report expired. Current availability has not yet been rechecked.");
158
190
  } else if (
159
191
  bookie &&
160
192
  options.session &&
@@ -171,11 +203,15 @@ function componentItem(producer: KnownSource, options: DashboardScreenOptions):
171
203
  : "Auto starts off by default.";
172
204
  explanation = `${origin} Turn Auto on in Settings for automatic notes in this folder, or use /bookie-context to select memory manually. A session toggle does not change the startup setting.`;
173
205
  } else if (source?.producer === "bookie-memory") {
174
- status = "Ready in this folder";
175
- explanation = "Bookie can save and recall routine notes for this workspace.";
206
+ state = item?.state ?? "unknown";
207
+ [status, explanation] = memoryDescription(item, source.inventory?.state === "available");
176
208
  } else if (bookie && source?.items.length) {
177
209
  status = "Project connected";
178
210
  explanation = "Bookie is sharing the selected project’s work with Pi.";
211
+ } else if (availability) {
212
+ state = availability.state;
213
+ status = availability.label;
214
+ explanation = availability.details?.[0] ?? "Current availability reported by Scout.";
179
215
  } else if (item) {
180
216
  state = item.state;
181
217
  [status, explanation] = scoutDescription(worker, item);
@@ -197,17 +233,29 @@ function componentItem(producer: KnownSource, options: DashboardScreenOptions):
197
233
  const isMemory = source?.producer === "bookie-memory";
198
234
  const limited =
199
235
  isMemory && state === "observed" && options.session?.auto.enabled && sourceDetails.includes(BOOKIE_LIMIT_MESSAGE);
200
- const briefDetails = limited
236
+ const explanationLines = limited
201
237
  ? [explanation, "Bookie could only show part of this project’s open choices."]
202
238
  : [explanation];
239
+ const canShowInventory = source && current(source, options) && (!bookie || options.session?.auto.enabled);
240
+ const showInventory = canShowInventory && source.refresh?.state !== "failed";
241
+ const inventory = inventoryPresentation(showInventory ? source.inventory : undefined);
242
+ const age = observationAge(source, options.now?.getTime() ?? Date.now());
243
+ const briefDetails = [
244
+ ...explanationLines,
245
+ ...(source?.inventory || state === "last-observed" ? [age] : []),
246
+ ...inventory.content,
247
+ ];
203
248
  return {
204
249
  key: `component:${producer}`,
205
250
  label: `${title} · ${status}`,
206
251
  status: state,
207
252
  elapsed: "",
208
253
  briefDetails,
254
+ ...(source?.inventory && showInventory ? { browse: true, previewLines: inventory.preview } : {}),
209
255
  details: [
210
256
  ...briefDetails,
257
+ age,
258
+ ...inventory.references,
211
259
  ...(source
212
260
  ? [`Source: ${source.producer} · ${source.producerVersion}`, `Last update: ${source.observedAt}`]
213
261
  : []),
@@ -0,0 +1,44 @@
1
+ /** Human content previews from an authorized, current producer snapshot; rendering performs no reads. */
2
+ import type { DashboardInventory, DashboardSourceSnapshot } from "../kernel/dashboard-observation.ts";
3
+ import { dashboardText } from "./dashboard-screen.ts";
4
+ import { truncate } from "./dashboard-render.ts";
5
+
6
+ const clean = (text: string) => dashboardText(text).replace(/\s+/g, " ").trim();
7
+
8
+ export function inventoryPresentation(inventory: DashboardInventory | undefined) {
9
+ if (!inventory) return { preview: [] as string[], content: [] as string[], references: [] as string[] };
10
+ const entries = inventory.state === "available" ? inventory.entries : [];
11
+ const summary = clean(inventory.summary);
12
+ const coverage = inventory.limited
13
+ ? inventory.count === undefined
14
+ ? "Showing a bounded selection; this is not the full inventory."
15
+ : `Showing ${entries.length} of ${inventory.count} saved items.`
16
+ : undefined;
17
+ return {
18
+ preview: [truncate(summary, 110), ...entries.slice(0, 2).map((entry) => `• ${truncate(clean(entry.title), 90)}`)],
19
+ content: [
20
+ `Scope: ${clean(inventory.scope)}`,
21
+ summary,
22
+ ...(coverage ? [coverage] : []),
23
+ ...entries.flatMap((entry, index) => [
24
+ "",
25
+ `${index + 1}. ${clean(entry.title)}`,
26
+ ` ${clean(entry.summary)}`,
27
+ ...(entry.details ?? []).map((line) => ` ${clean(line)}`),
28
+ ]),
29
+ ],
30
+ references: entries.flatMap((entry) =>
31
+ entry.reference ? [`${clean(entry.title)}: ${clean(entry.reference)}`] : [],
32
+ ),
33
+ };
34
+ }
35
+
36
+ export function observationAge(source: DashboardSourceSnapshot | undefined, now: number): string {
37
+ if (!source) return "No status report received yet.";
38
+ const age = now - Date.parse(source.observedAt);
39
+ if (!Number.isFinite(age) || age < 0) return "The last update time could not be verified.";
40
+ if (age < 10_000) return "Updated just now.";
41
+ if (age < 60_000) return `Updated ${Math.floor(age / 1000)}s ago.`;
42
+ if (age < 3_600_000) return `Updated ${Math.floor(age / 60_000)}m ago.`;
43
+ return `Updated ${Math.floor(age / 3_600_000)}h ago.`;
44
+ }
@@ -50,17 +50,19 @@ function paintCell(cell: string): string {
50
50
  );
51
51
  }
52
52
  if (/^ /.test(text)) {
53
- const status =
54
- /( · )(Failed|Blocked|Run failed|Last attempt failed|Unavailable|Awaiting decision|Needs you|Live status unknown|Running|Finished|Saved|Available)(?= |$| ·)/;
53
+ const status = new RegExp(
54
+ "( · )(Failed|Blocked|Run failed|Last attempt failed|Unavailable|Awaiting decision|Needs you|" +
55
+ "Disconnected|Checking status|Status update overdue|Status check unavailable|Running|Finished|Saved|Available|Ready[^·]*)(?= |$| ·)",
56
+ );
55
57
  return (
56
58
  text.replace(status, (_, separator, state) => {
57
59
  const color = /^(Failed|Blocked|Last attempt failed|Run failed)$/.test(state)
58
60
  ? "90"
59
61
  : state === "Unavailable"
60
62
  ? "1;31"
61
- : /Awaiting|Needs you|unknown/.test(state)
63
+ : /Awaiting|Needs you|Disconnected|overdue|unavailable/.test(state)
62
64
  ? "33"
63
- : state === "Running"
65
+ : /Running|Checking/.test(state)
64
66
  ? "36"
65
67
  : "32";
66
68
  return separator + sgr(state, color);
@@ -367,13 +367,15 @@ const workGroups = [
367
367
  "Other tasks",
368
368
  "Recently finished",
369
369
  "Last known",
370
- "Tools",
370
+ "Memory",
371
+ "Research",
371
372
  ];
372
373
  export function needsUserInput(item: DashboardItem): boolean {
373
374
  return !item.reviewSummary && ["needs-you", "approval-wait"].includes(item.status);
374
375
  }
375
376
  function workGroup(item: DashboardItem): string {
376
- if (item.key.startsWith("component:")) return needsUserInput(item) ? "Needs your decision" : "Tools";
377
+ if (item.key.startsWith("component:"))
378
+ return needsUserInput(item) ? "Needs your decision" : item.key === "component:bookie" ? "Memory" : "Research";
377
379
  if (item.key.startsWith("activity:")) return "Latest activity";
378
380
  if (["last-observed", "historical"].includes(item.status)) return "Last known";
379
381
  if (needsUserInput(item)) {
@@ -449,7 +451,11 @@ export function sessionPanelLines(options: DashboardScreenOptions, items: Dashbo
449
451
  if (roomy && (rows.length || lines.length)) rows.push("");
450
452
  const count = destination === "now" ? "" : ` · ${end - start}`;
451
453
  rows.push(sectionHeading(group + count, left ?? width));
452
- for (const item of items.slice(start, end)) rows.push(rowText(item, destination, item.key === screen.selectedKey));
454
+ for (const item of items.slice(start, end)) {
455
+ rows.push(rowText(item, destination, item.key === screen.selectedKey));
456
+ for (const line of (item.previewLines ?? []).slice(0, options.height >= 28 ? 3 : 2))
457
+ rows.push(` ${clean(line)}`);
458
+ }
453
459
  start = end;
454
460
  }
455
461
  lines.push(...rows);