pi-daddy 0.52.0 → 0.53.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 (39) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +22 -10
  3. package/dist/products/dashboard-cli.d.ts.map +1 -1
  4. package/dist/products/dashboard-cli.js +20 -1
  5. package/dist/products/dashboard-cli.js.map +1 -1
  6. package/dist/products/dashboard-display-controls.js +3 -3
  7. package/dist/products/dashboard-display-controls.js.map +1 -1
  8. package/dist/products/dashboard-handshake.d.ts +2 -0
  9. package/dist/products/dashboard-handshake.d.ts.map +1 -1
  10. package/dist/products/dashboard-handshake.js +39 -43
  11. package/dist/products/dashboard-handshake.js.map +1 -1
  12. package/dist/products/dashboard-herdr.d.ts.map +1 -1
  13. package/dist/products/dashboard-herdr.js +7 -1
  14. package/dist/products/dashboard-herdr.js.map +1 -1
  15. package/dist/products/dashboard-screen.d.ts +1 -0
  16. package/dist/products/dashboard-screen.d.ts.map +1 -1
  17. package/dist/products/dashboard-screen.js +14 -3
  18. package/dist/products/dashboard-screen.js.map +1 -1
  19. package/dist/products/dashboard-session-client.d.ts +5 -2
  20. package/dist/products/dashboard-session-client.d.ts.map +1 -1
  21. package/dist/products/dashboard-session-client.js +14 -10
  22. package/dist/products/dashboard-session-client.js.map +1 -1
  23. package/dist/products/dashboard-settings.d.ts +10 -1
  24. package/dist/products/dashboard-settings.d.ts.map +1 -1
  25. package/dist/products/dashboard-settings.js +26 -1
  26. package/dist/products/dashboard-settings.js.map +1 -1
  27. package/extensions/dashboard-session-server.ts +6 -1
  28. package/extensions/dashboard-settings.ts +15 -1
  29. package/extensions/grants.ts +10 -4
  30. package/extensions/session-report.ts +4 -0
  31. package/extensions/session.ts +2 -1
  32. package/package.json +2 -2
  33. package/src/products/dashboard-cli.ts +17 -2
  34. package/src/products/dashboard-display-controls.ts +3 -3
  35. package/src/products/dashboard-handshake.ts +45 -49
  36. package/src/products/dashboard-herdr.ts +9 -1
  37. package/src/products/dashboard-screen.ts +18 -5
  38. package/src/products/dashboard-session-client.ts +17 -12
  39. package/src/products/dashboard-settings.ts +36 -2
@@ -1,6 +1,7 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
3
3
  import { dirname, resolve } from "node:path";
4
+ import { userInfo } from "node:os";
4
5
  import {
5
6
  DASHBOARD_PLUGIN_ID,
6
7
  dashboardHerdrExec,
@@ -13,6 +14,7 @@ import {
13
14
  } from "./dashboard-herdr.ts";
14
15
  import { DASHBOARD_PROTOCOL_VERSION } from "./dashboard-cli.ts";
15
16
  import type { HerdrExec } from "../executors/herdr-cli.ts";
17
+ import { withFileLock } from "../governance/file-lock.ts";
16
18
  import { defaultActivityTimelinePath, parseActivityTimeline, renderActivityTimeline } from "./activity-timeline.ts";
17
19
 
18
20
  export type DashboardPromptChoice = "not-now" | "never";
@@ -73,6 +75,8 @@ export interface DashboardHandshakeInput {
73
75
  ledgerPath?: string;
74
76
  pluginRoot: string;
75
77
  preferencePath: string;
78
+ /** Supply an isolated OS account home when testing a shared Herdr registry. */
79
+ registryOwnerHome?: string;
76
80
  paneStatePath: string;
77
81
  sessionEndpoint?: { socketPath: string; token: string };
78
82
  ui: DashboardHandshakeUI;
@@ -91,61 +95,53 @@ export async function offerDashboardHandshake(input: DashboardHandshakeInput): P
91
95
  const preference = await loadPreference(input.preferencePath);
92
96
  if (preference) return "suppressed";
93
97
  const plugin = await inspectDashboardPlugin(exec, input.pluginRoot);
94
- // A compatible bundled panel is local software already chosen by the operator. Present it by default;
95
- // pane identity makes this one panel per caller tab/session and --no-focus avoids focus theft.
96
- if (plugin.state === "compatible") {
97
- const opened = await openOrReuseDashboard({
98
- exec,
99
- host: host.host,
100
- ledgerPath: input.ledgerPath ?? "",
101
- cwd: input.cwd,
102
- statePath: input.paneStatePath,
103
- pluginRoot: input.pluginRoot,
104
- allowInactive: true,
105
- sessionEndpoint: input.sessionEndpoint,
106
- });
107
- input.ui.notify(`pi-daddy dashboard ${opened.kind} in pane ${opened.paneId} without changing focus.`, "info");
108
- return "already-installed";
109
- }
110
- const replacingDifferentPackage = plugin.state === "incompatible" && plugin.incompatibility === "package-root";
111
- if (plugin.state !== "absent" && !replacingDifferentPackage) {
98
+ if (plugin.plugin?.enabled === false) return "suppressed";
99
+ const replacing =
100
+ plugin.state === "incompatible" && plugin.incompatibility === "package-root" && plugin.plugin?.enabled === true;
101
+ if (plugin.state !== "compatible" && plugin.state !== "absent" && !replacing) {
112
102
  input.ui.notify(`pi-daddy dashboard: ${plugin.diagnostic}`, "error");
113
103
  return "failed";
114
104
  }
115
-
116
- const affirmative = replacingDifferentPackage ? "Relink and open" : "Install and open";
117
- const choices = replacingDifferentPackage ? [affirmative, "Not now"] : [affirmative, "Not now", "Never ask"];
118
- const choice = await input.ui.select(
119
- replacingDifferentPackage
120
- ? "The pi-daddy dashboard is linked from a different package. Relink this bundled copy and open it?"
121
- : "Herdr detected. Install and open the pi-daddy dashboard?",
122
- choices,
123
- );
124
- if (!choices.includes(choice ?? "")) {
125
- // Escape, timeout and UI teardown return undefined. None is an operator choice, so none may become a
126
- // durable preference merely because the dialog disappeared.
127
- input.ui.notify("pi-daddy dashboard: installation prompt dismissed; no preference was stored.", "info");
128
- return "deferred";
129
- }
130
- if (choice !== affirmative) {
131
- if (replacingDifferentPackage) {
132
- input.ui.notify("pi-daddy dashboard: existing link unchanged; no preference was stored.", "info");
105
+ if (replacing) {
106
+ const choice = await input.ui.select(
107
+ "The dashboard is linked to another Pi Daddy installation. Use this installation's dashboard instead?",
108
+ ["Relink and open", "Not now", "Keep existing link"],
109
+ );
110
+ if (choice !== "Relink and open") {
111
+ if (choice === "Keep existing link") await savePreference(input.preferencePath, "never");
112
+ input.ui.notify("pi-daddy dashboard: kept the existing dashboard link.", "info");
133
113
  return "deferred";
134
114
  }
135
- const recorded = choice === "Never ask" ? "never" : "not-now";
136
- await savePreference(input.preferencePath, recorded);
137
- input.ui.notify(
138
- recorded === "never"
139
- ? "pi-daddy dashboard: startup installation prompt disabled. /grants dashboard remains available."
140
- : "pi-daddy dashboard: not installed. /grants dashboard will report the manual setup when requested.",
141
- "info",
115
+ }
116
+ let outcome: DashboardHandshakeOutcome = "already-installed";
117
+ if (plugin.state !== "compatible") {
118
+ // Herdr plugin links are shared across Pi profiles. Lock once per OS account,
119
+ // independently of Pi settings, environment HOME, and the bundled plugin path.
120
+ const registryLock = resolve(
121
+ input.registryOwnerHome ?? userInfo().homedir,
122
+ ".cache",
123
+ "pi-daddy",
124
+ "herdr-plugin-registry",
142
125
  );
143
- return "deferred";
126
+ await mkdir(dirname(registryLock), { recursive: true, mode: 0o700 });
127
+ outcome = await withFileLock(registryLock, "dashboard setup", async () => {
128
+ if (await loadPreference(input.preferencePath)) return "suppressed" as const;
129
+ const current = await inspectDashboardPlugin(exec, input.pluginRoot);
130
+ if (current.state === "compatible") return "already-installed" as const;
131
+ if (
132
+ current.state !== plugin.state ||
133
+ current.incompatibility !== plugin.incompatibility ||
134
+ current.plugin?.plugin_root !== plugin.plugin?.plugin_root ||
135
+ current.plugin?.enabled !== plugin.plugin?.enabled
136
+ )
137
+ throw Error("The dashboard installation changed during startup. Reopen the dashboard to inspect it.");
138
+ await linkDashboardPlugin(input.pluginRoot, exec);
139
+ const linked = await inspectDashboardPlugin(exec, input.pluginRoot);
140
+ if (linked.state !== "compatible") throw new Error(linked.diagnostic);
141
+ return "installed" as const;
142
+ });
143
+ if (outcome === "suppressed") return outcome;
144
144
  }
145
-
146
- await linkDashboardPlugin(input.pluginRoot, exec);
147
- const linked = await inspectDashboardPlugin(exec, input.pluginRoot);
148
- if (linked.state !== "compatible") throw new Error(linked.diagnostic);
149
145
  const opened = await openOrReuseDashboard({
150
146
  exec,
151
147
  host: host.host,
@@ -157,7 +153,7 @@ export async function offerDashboardHandshake(input: DashboardHandshakeInput): P
157
153
  sessionEndpoint: input.sessionEndpoint,
158
154
  });
159
155
  input.ui.notify(`pi-daddy dashboard ${opened.kind} in pane ${opened.paneId} without changing focus.`, "info");
160
- return "installed";
156
+ return outcome;
161
157
  } catch (error) {
162
158
  input.ui.notify(
163
159
  `pi-daddy dashboard setup failed: ${error instanceof Error ? error.message : String(error)}`,
@@ -127,7 +127,15 @@ export async function inspectDashboardPlugin(
127
127
  try {
128
128
  const parsed = parseReply(await exec(["plugin", "list", "--json"]));
129
129
  if (parsed.error) return { state: "unavailable", diagnostic: `Herdr plugin registry unavailable: ${parsed.error}` };
130
- const plugins = Array.isArray(parsed.result?.plugins) ? (parsed.result.plugins as Record<string, unknown>[]) : [];
130
+ if (
131
+ !Array.isArray(parsed.result?.plugins) ||
132
+ !parsed.result.plugins.every((row) => typeof row?.plugin_id === "string")
133
+ )
134
+ return {
135
+ state: "unavailable",
136
+ diagnostic: "Herdr returned an unreadable plugin list. Check the Herdr connection.",
137
+ };
138
+ const plugins = parsed.result.plugins as Record<string, unknown>[];
131
139
  const plugin = plugins.find((candidate) => candidate.plugin_id === DASHBOARD_PLUGIN_ID);
132
140
  if (!plugin) return { state: "absent", diagnostic: `Herdr plugin ${DASHBOARD_PLUGIN_ID} is not installed.` };
133
141
  // Protocol and provenance both precede enabled state. A root-only repair is offered only when the
@@ -10,7 +10,7 @@ import { activityTaskTitle } from "./dashboard-activity.ts";
10
10
  import { versionLines } from "./dashboard-components.ts";
11
11
  import { sessionRecapLines } from "./dashboard-recap.ts";
12
12
  import { colorSessionLine, previewWidth, sectionHeading } from "./dashboard-layout.ts";
13
- import { dashboardSettingsLines, type DashboardSettingKey } from "./dashboard-settings.ts";
13
+ import { visibleSettingKeys, dashboardSettingsLines, type DashboardSettingKey } from "./dashboard-settings.ts";
14
14
  /** Height-bounded, task-first view. Permission state is always supplied by the owner. */
15
15
  import type { EcosystemVersionRow } from "./ecosystem-versions.ts";
16
16
  import type { DashboardProjection } from "./dashboard-projection.ts";
@@ -43,6 +43,7 @@ export interface DashboardScreenState {
43
43
  manualScroll?: boolean;
44
44
  selections?: Record<string, string>;
45
45
  settingKey?: DashboardSettingKey;
46
+ settingKeys?: DashboardSettingKey[];
46
47
  versionId?: EcosystemVersionRow["id"];
47
48
  versionRows?: EcosystemVersionRow[];
48
49
  selectedKey?: string;
@@ -351,14 +352,24 @@ export function renderDashboardScreen(options: DashboardScreenOptions): string {
351
352
  const ack = options.acknowledgment;
352
353
  if (ack?.state === "unconfirmed") {
353
354
  const setting =
354
- ({ "set-auto": "Auto", "set-jev": "JEV", set: "model", "set-limit": "limit" } as Record<string, string>)[
355
- ack.action
356
- ] ?? "setting";
355
+ (
356
+ {
357
+ "set-auto": "Auto",
358
+ "set-jev": "JEV",
359
+ "edit-jev": "JEV settings",
360
+ set: "model",
361
+ "set-limit": "limit",
362
+ } as Record<string, string>
363
+ )[ack.action] ?? "setting";
357
364
  fixed.push(
358
365
  ...wrapDashboardLines([`Unconfirmed ${setting} change. Check the main Pi chat before trying again.`], width),
359
366
  );
360
367
  } else if (ack && (!disconnected || !modern) && (!modern || screen.view === "settings" || ack.state === "refused")) {
361
- fixed.push(clean(`${ack.action}: ${ack.state} · ${ack.effect}`));
368
+ fixed.push(
369
+ ack.action === "edit-jev" && ack.state === "opened"
370
+ ? "JEV settings · current values below"
371
+ : clean(`${ack.action}: ${ack.state} · ${ack.effect}`),
372
+ );
362
373
  }
363
374
  if (modern && options.filter && options.filter !== "everything" && screen.view === "main")
364
375
  fixed.push(`Filter: ${options.filter} · Tab to change`);
@@ -415,6 +426,8 @@ export function renderDashboardScreen(options: DashboardScreenOptions): string {
415
426
  "Finished means observed completion, not acceptance.",
416
427
  );
417
428
  else if (screen.view === "settings") {
429
+ screen.settingKeys = visibleSettingKeys(session?.settings?.jev);
430
+ if (screen.settingKey && !screen.settingKeys.includes(screen.settingKey)) screen.settingKey = "jev";
418
431
  body.push(
419
432
  ...(disconnected
420
433
  ? [
@@ -1,5 +1,5 @@
1
1
  import type { DashboardOwnerObservation } from "../kernel/dashboard-observation.ts";
2
- import type { DashboardSettingsSnapshot } from "./dashboard-settings.ts";
2
+ import type { DashboardSettingsSnapshot, JevEditAction } from "./dashboard-settings.ts";
3
3
  import type { EcosystemVersions } from "./ecosystem-versions.ts";
4
4
  import { createConnection } from "node:net";
5
5
 
@@ -19,6 +19,7 @@ export type DashboardSessionAction = (
19
19
  | { action: "set"; edits: string }
20
20
  | { action: "set-auto"; enabled: boolean }
21
21
  | { action: "set-jev"; enabled: boolean }
22
+ | { action: "edit-jev"; option: JevEditAction }
22
23
  | { action: "set-limit"; key: "wall" | "idle"; seconds: number }
23
24
  ) & { expectedOwner?: { sessionId: string; cwd: string; generation: string } };
24
25
 
@@ -60,7 +61,7 @@ export async function dashboardSessionRequest(
60
61
 
61
62
  export type DashboardAcknowledgment = {
62
63
  action: string;
63
- state: "pending" | "applied" | "refused" | "unconfirmed";
64
+ state: "opened" | "pending" | "applied" | "refused" | "unconfirmed";
64
65
  effect: string;
65
66
  };
66
67
 
@@ -129,9 +130,11 @@ export function createDashboardConnection(
129
130
  const effect =
130
131
  action.action === "set-auto"
131
132
  ? "current permission handling; admitted work unchanged"
132
- : action.action === "set-jev"
133
- ? "current JEV session; separate paid-call and storage choices"
134
- : "future children; running children unchanged";
133
+ : action.action === "edit-jev"
134
+ ? "use the main Pi session; current values shown below"
135
+ : action.action === "set-jev"
136
+ ? "current JEV session; separate paid-call and storage choices"
137
+ : "future children; running children unchanged";
135
138
  state.acknowledgment = { action: action.action, state: "pending", effect };
136
139
  try {
137
140
  const snapshot = await request({
@@ -148,13 +151,15 @@ export function createDashboardConnection(
148
151
  });
149
152
  if (!accept(snapshot)) throw Error("owner acknowledgment is stale; reconcile before another action");
150
153
  state.acknowledgment.state =
151
- action.action === "set-jev"
152
- ? snapshot.settings?.jev.pending
153
- ? "pending"
154
- : snapshot.settings?.jev.enabled === action.enabled
155
- ? "applied"
156
- : "refused"
157
- : "applied";
154
+ action.action === "edit-jev"
155
+ ? "opened"
156
+ : action.action === "set-jev"
157
+ ? snapshot.settings?.jev.pending
158
+ ? "pending"
159
+ : snapshot.settings?.jev.enabled === action.enabled
160
+ ? "applied"
161
+ : "refused"
162
+ : "applied";
158
163
  return true;
159
164
  } catch (error) {
160
165
  state.snapshot = undefined;
@@ -1,5 +1,10 @@
1
1
  /** Settings are owner observations; rendering never grants consent or changes execution. */
2
- export type DashboardSettingKey = "auto" | "jev" | "wall" | "idle" | "descendants" | "depth" | "perCall";
2
+ export const JEV_EDIT_ACTIONS = ["limit", "configure", "hints"] as const;
3
+ export type JevEditAction = (typeof JEV_EDIT_ACTIONS)[number];
4
+ export const isJevEditAction = (value: unknown): value is JevEditAction =>
5
+ JEV_EDIT_ACTIONS.some((key) => value === key);
6
+ export type DashboardSettingKey =
7
+ JevEditAction | "auto" | "jev" | "wall" | "idle" | "descendants" | "depth" | "perCall";
3
8
  export const DASHBOARD_SETTING_KEYS: DashboardSettingKey[] = [
4
9
  "auto",
5
10
  "jev",
@@ -16,6 +21,10 @@ export interface DashboardJevState {
16
21
  mode?: string;
17
22
  storage?: string | null;
18
23
  remaining?: number;
24
+ limit?: number;
25
+ used?: number;
26
+ hintsEnabled?: boolean;
27
+ controls?: JevEditAction[];
19
28
  availability?: string;
20
29
  providerReadiness?: string;
21
30
  selectedProvider?: string;
@@ -24,6 +33,10 @@ export interface DashboardJevState {
24
33
  storageRoot?: string;
25
34
  error?: string;
26
35
  }
36
+ export function visibleSettingKeys(jev?: DashboardJevState): DashboardSettingKey[] {
37
+ const extra = JEV_EDIT_ACTIONS.filter((key) => jev?.available && jev.controls?.includes(key));
38
+ return ["auto", "jev", ...extra, ...DASHBOARD_SETTING_KEYS.slice(2)];
39
+ }
27
40
  export interface DashboardSettingsSnapshot {
28
41
  editable: boolean;
29
42
  wallSeconds: number;
@@ -36,6 +49,7 @@ export interface DashboardSettingsSnapshot {
36
49
  perCall: number;
37
50
  jev: DashboardJevState;
38
51
  }
52
+ export const JEV_EDITOR_NOTICE = "Finish editing in the main Pi session.";
39
53
  export const JEV_CONSENT_NOTICE = "Complete JEV paid-call and LoRA-storage choices in the parent Pi session";
40
54
  export function dashboardJevNotice(jev: DashboardJevState): string {
41
55
  if (jev.pending) return JEV_CONSENT_NOTICE;
@@ -57,9 +71,29 @@ export function dashboardSettingsLines(
57
71
  "jev",
58
72
  `JEV: ${jev.pending ? "waiting for consent" : !jev.available ? "unavailable" : jev.enabled ? "ON" : "OFF"}`,
59
73
  ),
74
+ ...(jev.available && jev.controls?.includes("limit")
75
+ ? [
76
+ row("limit", `Call limit: ${jev.limit ?? "unknown"} per session`),
77
+ ` ${jev.used ?? "?"} used · ${jev.remaining ?? "?"} available now`,
78
+ ]
79
+ : []),
80
+ ...(jev.available && jev.controls?.includes("configure")
81
+ ? [row("configure", "Choose JEV model and storage…")]
82
+ : []),
83
+ ...(jev.available && jev.controls?.includes("hints")
84
+ ? [
85
+ row(
86
+ "hints",
87
+ `Tool hints: ${jev.hintsEnabled === true ? "ON" : jev.hintsEnabled === false ? "OFF" : "unknown"}`,
88
+ ),
89
+ " Suggestions only · above 90% confidence",
90
+ ]
91
+ : []),
60
92
  ...(jev.available
61
93
  ? [
62
- ` ${jev.availability ?? "unknown"} · ${jev.remaining ?? 0} paid calls left`,
94
+ ...(jev.controls?.includes("limit")
95
+ ? [` Provider status: ${jev.availability ?? "unknown"}`]
96
+ : [` ${jev.availability ?? "unknown"} · ${jev.remaining ?? 0} paid calls left`]),
63
97
  ` Key: ${jev.providerReadiness ?? "unknown"}; storage: ${jev.storage ?? "not granted"}`,
64
98
  ...(jev.selectedProvider || jev.selectedModel
65
99
  ? [` Model: ${jev.selectedProvider ?? "unknown"}/${jev.selectedModel ?? "not reported"}`]