pi-daddy 0.26.1 → 0.27.1

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 (131) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/PRODUCT-GUIDE.md +127 -0
  3. package/README.md +23 -2
  4. package/REQUIREMENTS.md +41 -0
  5. package/dist/catalog.d.ts +1 -7
  6. package/dist/catalog.d.ts.map +1 -1
  7. package/dist/catalog.js +8 -40
  8. package/dist/catalog.js.map +1 -1
  9. package/dist/cli.d.ts +2 -2
  10. package/dist/cli.d.ts.map +1 -1
  11. package/dist/cli.js +44 -14
  12. package/dist/cli.js.map +1 -1
  13. package/dist/daily-dashboard-host.d.ts +14 -1
  14. package/dist/daily-dashboard-host.d.ts.map +1 -1
  15. package/dist/daily-dashboard-host.js +40 -17
  16. package/dist/daily-dashboard-host.js.map +1 -1
  17. package/dist/daily-panel.d.ts +36 -0
  18. package/dist/daily-panel.d.ts.map +1 -0
  19. package/dist/daily-panel.js +84 -0
  20. package/dist/daily-panel.js.map +1 -0
  21. package/dist/daily-view-render.d.ts +2 -1
  22. package/dist/daily-view-render.d.ts.map +1 -1
  23. package/dist/daily-view-render.js +2 -1
  24. package/dist/daily-view-render.js.map +1 -1
  25. package/dist/daily-view.d.ts +3 -0
  26. package/dist/daily-view.d.ts.map +1 -1
  27. package/dist/daily-view.js +6 -0
  28. package/dist/daily-view.js.map +1 -1
  29. package/dist/dashboard-cli.d.ts +2 -0
  30. package/dist/dashboard-cli.d.ts.map +1 -1
  31. package/dist/dashboard-cli.js +37 -15
  32. package/dist/dashboard-cli.js.map +1 -1
  33. package/dist/dashboard-host-contract.d.ts +2 -0
  34. package/dist/dashboard-host-contract.d.ts.map +1 -1
  35. package/dist/dashboard-host-contract.js.map +1 -1
  36. package/dist/dashboard-host-transport.d.ts.map +1 -1
  37. package/dist/dashboard-host-transport.js +6 -3
  38. package/dist/dashboard-host-transport.js.map +1 -1
  39. package/dist/dashboard-host.d.ts +30 -2
  40. package/dist/dashboard-host.d.ts.map +1 -1
  41. package/dist/dashboard-host.js +73 -11
  42. package/dist/dashboard-host.js.map +1 -1
  43. package/dist/dashboard-menu.d.ts +16 -0
  44. package/dist/dashboard-menu.d.ts.map +1 -0
  45. package/dist/dashboard-menu.js +33 -0
  46. package/dist/dashboard-menu.js.map +1 -0
  47. package/dist/definitions.d.ts +3 -8
  48. package/dist/definitions.d.ts.map +1 -1
  49. package/dist/definitions.js +19 -43
  50. package/dist/definitions.js.map +1 -1
  51. package/dist/factory-order.d.ts +10 -10
  52. package/dist/index.d.ts +7 -1
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +7 -1
  55. package/dist/index.js.map +1 -1
  56. package/dist/init.d.ts +7 -19
  57. package/dist/init.d.ts.map +1 -1
  58. package/dist/init.js +9 -20
  59. package/dist/init.js.map +1 -1
  60. package/dist/learning-connection.d.ts +127 -0
  61. package/dist/learning-connection.d.ts.map +1 -0
  62. package/dist/learning-connection.js +54 -0
  63. package/dist/learning-connection.js.map +1 -0
  64. package/dist/model-preflight.d.ts +5 -0
  65. package/dist/model-preflight.d.ts.map +1 -1
  66. package/dist/model-preflight.js +9 -0
  67. package/dist/model-preflight.js.map +1 -1
  68. package/dist/product-files.d.ts +6 -0
  69. package/dist/product-files.d.ts.map +1 -0
  70. package/dist/product-files.js +55 -0
  71. package/dist/product-files.js.map +1 -0
  72. package/dist/skill-packages.d.ts +6 -24
  73. package/dist/skill-packages.d.ts.map +1 -1
  74. package/dist/skill-packages.js +74 -33
  75. package/dist/skill-packages.js.map +1 -1
  76. package/dist/skill-resources.d.ts +21 -0
  77. package/dist/skill-resources.d.ts.map +1 -0
  78. package/dist/skill-resources.js +52 -0
  79. package/dist/skill-resources.js.map +1 -0
  80. package/dist/work-command.d.ts.map +1 -1
  81. package/dist/work-command.js +14 -6
  82. package/dist/work-command.js.map +1 -1
  83. package/dist/work-policy-registry.d.ts +133 -0
  84. package/dist/work-policy-registry.d.ts.map +1 -0
  85. package/dist/work-policy-registry.js +128 -0
  86. package/dist/work-policy-registry.js.map +1 -0
  87. package/dist/work-run.d.ts +56 -0
  88. package/dist/work-run.d.ts.map +1 -0
  89. package/dist/work-run.js +102 -0
  90. package/dist/work-run.js.map +1 -0
  91. package/dist/work-setup.d.ts +40 -0
  92. package/dist/work-setup.d.ts.map +1 -0
  93. package/dist/work-setup.js +174 -0
  94. package/dist/work-setup.js.map +1 -0
  95. package/extensions/daily-dashboard-session.ts +16 -7
  96. package/extensions/execute-child.ts +2 -2
  97. package/extensions/grants-command.ts +2 -2
  98. package/extensions/grants.ts +6 -2
  99. package/extensions/init-command.ts +3 -2
  100. package/extensions/learning-outcome-session.ts +38 -0
  101. package/extensions/learning-session.ts +59 -0
  102. package/extensions/ordinary-runtime.ts +2 -2
  103. package/extensions/run-delegation.ts +2 -2
  104. package/extensions/work-policy-session.ts +139 -0
  105. package/extensions/work-run-session.ts +75 -0
  106. package/extensions/work-runtime.ts +2 -2
  107. package/extensions/work-session.ts +132 -0
  108. package/package.json +9 -1
  109. package/src/catalog.ts +7 -37
  110. package/src/cli.ts +34 -14
  111. package/src/daily-dashboard-host.ts +32 -15
  112. package/src/daily-panel.ts +80 -0
  113. package/src/daily-view-render.ts +2 -1
  114. package/src/daily-view.ts +8 -0
  115. package/src/dashboard-cli.ts +29 -17
  116. package/src/dashboard-host-contract.ts +2 -0
  117. package/src/dashboard-host-transport.ts +7 -4
  118. package/src/dashboard-host.ts +48 -13
  119. package/src/dashboard-menu.ts +28 -0
  120. package/src/definitions.ts +16 -44
  121. package/src/index.ts +7 -1
  122. package/src/init.ts +10 -20
  123. package/src/learning-connection.ts +70 -0
  124. package/src/model-preflight.ts +9 -0
  125. package/src/product-files.ts +34 -0
  126. package/src/skill-packages.ts +59 -34
  127. package/src/skill-resources.ts +48 -0
  128. package/src/work-command.ts +11 -6
  129. package/src/work-policy-registry.ts +81 -0
  130. package/src/work-run.ts +79 -0
  131. package/src/work-setup.ts +141 -0
@@ -10,6 +10,8 @@ import { parseDashboardLedger } from "./dashboard-projection.ts";
10
10
  import { renderDashboard } from "./dashboard-render.ts";
11
11
  import { createDailyViewReader, isDailyViewReader, readDailyView, type DailyViewOptions } from "./daily-view.ts";
12
12
  import { renderDailyView } from "./daily-view-render.ts";
13
+ import { renderDailyPanel, panelLines, learningSummary, type PanelAction, type WorkPresentation } from "./daily-panel.ts";
14
+ import { createDashboardMenu } from "./dashboard-menu.ts";
13
15
  import { projectWorkLedger, type WorkProjectionContext } from "./work-ledger.ts";
14
16
  import { parseRetentionJson } from "./retention-json.ts";
15
17
  import { createInterface } from "node:readline";
@@ -49,6 +51,7 @@ export interface DashboardFrameOptions {
49
51
  debrief?: DebriefPresenter;
50
52
  debriefJson?: boolean;
51
53
  connected?: DashboardConnection;
54
+ actionMenu?: ReturnType<typeof createDashboardMenu>;
52
55
  }
53
56
  export async function dashboardHostAction(host:DashboardConnection,line:string){
54
57
  if(!isDashboardConnection(host)||Buffer.byteLength(line)>60000)throw Error("genuine bounded dashboard connection required");
@@ -60,10 +63,10 @@ export async function dashboardHostAction(host:DashboardConnection,line:string){
60
63
 
61
64
  /** A fulfilled host call is not necessarily an applied native effect; keep those facts distinct in the UI. */
62
65
  export function dashboardActionFeedback(command:string,outcome:unknown):string{
63
- const value=outcome&&typeof outcome==="object"?outcome as {state?:unknown;result?:unknown}:{};
66
+ const value=outcome&&typeof outcome==="object"?outcome as {state?:unknown;result?:unknown;error?:unknown;reason?:unknown}:{};
64
67
  const state=typeof value.state==="string"?value.state:"unrecognised host response";
65
68
  if(state==="failed-or-unknown"||state==="readback-only")return `NO ACTION CLAIM: ${command} returned ${state}; inspect/reconcile explicitly.`;
66
- if(state!=="acknowledged")return `NOT APPLIED: ${command} returned ${state}.`;
69
+ if(state!=="acknowledged")return `NOT APPLIED: ${command} returned ${state}.${typeof (value.error??value.reason)==="string"?` ${String(value.error??value.reason).slice(0,1024)}`:""}`;
67
70
  const result=value.result&&typeof value.result==="object"?value.result as {application?:unknown}:null;
68
71
  // A retained records[] snapshot has no outer dashboard request correlation. Never select an old receipt.
69
72
  const nativeApplication=typeof result?.application==="string"?result.application:undefined;
@@ -110,15 +113,14 @@ export async function dashboardFrame(options: DashboardFrameOptions): Promise<st
110
113
  if(options.connected){
111
114
  if(!isDashboardConnection(options.connected))throw Error("original dashboard connection required");
112
115
  let view:Awaited<ReturnType<DashboardConnection["frame"]>>;
113
- try{view=await options.connected.frame();}catch(error){return `PI-DADDY — CONNECTED HOST ERROR\n${error instanceof Error ? error.message : String(error)}\nNo prior acceptance, presentation or continuity substituted. No action retried.`;}
116
+ try{view=await options.connected.frame();}catch(error){options.actionMenu?.clear();return panelLines(["PI-DADDY — Disconnected", "The original host is unavailable. No action was retried.", "Return to Pi: /grants host, then /grants dashboard.", ...(options.details?[String(error)]:[])],options.width);}
114
117
  if(options.dailyJson||options.debriefJson)return JSON.stringify(view);
115
118
  const source=view.source as {daily?:Parameters<typeof renderDailyView>[0]}|null;
116
- const actions=(view.actions as {key:string;label:string}[]|undefined)??[];
117
- const hostError=typeof view.error==="string"&&view.error?`HOST ERROR — ${view.error}`:null;
118
- return ["PI-DADDY — CONNECTED HOST (snapshot; identity/acceptance not authenticated)",hostError,source?.daily?renderDailyView(source.daily,options.width):"Source unavailable; no previous acceptance substituted.",
119
- view.debrief?renderDebrief(view.debrief as Parameters<typeof renderDebrief>[0],options.width):"Debrief deferred/closed. No implicit presentation or steering.",
120
- `Host control ${view.control}; acknowledgement ${view.acknowledgement}. Attention reserved ${view.attention.attentionUsed}/5 (not proof of delivery). Tip ${view.tip}.`,
121
- actions.length?`ACTIONS — type one command and Enter\n${actions.map(action=>` ${action.key} — ${action.label}`).join("\n")}`:"ACTIONS — none currently authorized; refresh never acts."].filter((line):line is string=>Boolean(line)).join("\n\n");
119
+ const actions=(view.actions as PanelAction[]|undefined)??[];
120
+ const menu=(options.actionMenu??createDashboardMenu()).show(view.tip,actions);
121
+ const learning=view.debrief?["Retained review open below"]:learningSummary(view.learning);
122
+ const summary=source?.daily?renderDailyPanel(source.daily,options.width,{details:options.details,connected:true,presentation:view.presentation as WorkPresentation|null,error:view.error,controls:view.controls,control:view.control,actions:menu,learning}):panelLines(["PI-DADDY — Needs you","Work observation unavailable. Capture current work or open Details.",...menu.map(a=>`${a.choice} ${a.label}`)],options.width);
123
+ return [summary,view.debrief?renderDebrief(view.debrief as Parameters<typeof renderDebrief>[0],options.width):"",options.details?panelLines([`Host control ${view.control}; acknowledgement ${view.acknowledgement}. Attention reserved ${view.attention.attentionUsed}/5. Tip ${view.tip}.`,JSON.stringify(view.controls),JSON.stringify(view.learning),...actions.map(a=>`${a.key} — ${a.label}`)],options.width):""].filter(Boolean).join("\n\n");
122
124
  }
123
125
  if (options.debrief || options.debriefJson) {
124
126
  if (!isDebriefPresenter(options.debrief)) return "PI-DADDY — DEBRIEF UNAVAILABLE: genuine presenter/host missing";
@@ -128,7 +130,7 @@ export async function dashboardFrame(options: DashboardFrameOptions): Promise<st
128
130
  try {
129
131
  if (options.dailyReader !== undefined && !isDailyViewReader(options.dailyReader)) throw new TypeError("untrusted daily reader callback");
130
132
  const view = await (options.dailyReader ?? readDailyView)(options.dailyView);
131
- return options.dailyJson ? JSON.stringify(view) : renderDailyView(view, options.width);
133
+ return options.dailyJson ? JSON.stringify(view) : renderDailyPanel(view, options.width, { details: options.details });
132
134
  } catch {
133
135
  return "PI-DADDY — DAILY VIEW UNAVAILABLE\nInvalid or unavailable read-only input. No previous acceptance or continuity was substituted.";
134
136
  }
@@ -227,6 +229,8 @@ export async function runDashboard(argv = process.argv.slice(2), env: NodeJS.Pro
227
229
  if (!host.debrief) await debrief.open({ mode: "manual", userPresent: true }); // Explicit CLI fixture only; never override a host deferral.
228
230
  }
229
231
  const dailyReader = createDailyViewReader();
232
+ const actionMenu=createDashboardMenu();
233
+ let details=cli.details;
230
234
  let previous = "";
231
235
  let feedback = "";
232
236
  let input: ReturnType<typeof createInterface> | null = null;
@@ -237,13 +241,13 @@ export async function runDashboard(argv = process.argv.slice(2), env: NodeJS.Pro
237
241
  protocol,
238
242
  color: cli.color,
239
243
  width: process.stdout.columns || 80,
240
- details: cli.details,
244
+ details, actionMenu,
241
245
  dailyView, dailyReader, dailyJson: cli.dailyJson, debrief, debriefJson: cli.debriefJson, connected,
242
246
  });
243
- const rendered = feedback ? `${frame}\n\n${feedback}` : frame;
247
+ const rendered = feedback ? `${panelLines([feedback], process.stdout.columns || 80)}\n\n${frame}` : frame;
244
248
  if (rendered === previous && !clear) return;
245
249
  previous = rendered;
246
- const prompt = "COMMAND — type an exact listed key, then Enter (refresh never acts): ";
250
+ const prompt = "Action number / d Details, then Enter: ";
247
251
  const draft = input?.line ?? "";
248
252
  process.stdout.write(clear ? `\u001b]0;PI-DADDY\u0007\u001b[2J\u001b[H${rendered}\n\n${input ? prompt + draft : ""}` : `${rendered}\n`);
249
253
  if (input) input.setPrompt(prompt);
@@ -253,7 +257,7 @@ export async function runDashboard(argv = process.argv.slice(2), env: NodeJS.Pro
253
257
  await draw(false);
254
258
  return;
255
259
  }
256
- input = debrief || connected ? createInterface({ input: process.stdin, output: process.stdout, terminal: true }) : null;
260
+ input = createInterface({ input: process.stdin, output: process.stdout, terminal: Boolean(process.stdin.isTTY) });
257
261
  await draw(true);
258
262
  let drawing = false;
259
263
  const redraw = (): void => {
@@ -264,10 +268,18 @@ export async function runDashboard(argv = process.argv.slice(2), env: NodeJS.Pro
264
268
  let acting = false;
265
269
  input?.on("line", line => {
266
270
  if (acting) return; // never replay a line typed while the prior exact command is still settling.
271
+ if(line.trim().toLowerCase()==="d"){details=!details;redraw();return;}
267
272
  acting = true;
268
- feedback = `COMMAND ${line.trim() || "(empty)"} — applying the displayed exact request…`;
269
- void (connected?dashboardHostAction(connected,line):debriefAction(debrief!, line)).then(outcome => {
270
- feedback = connected ? dashboardActionFeedback(line.trim() || "command", outcome) : `ACKNOWLEDGED: ${line.trim() || "command"}. Refreshed state is shown below.`;
273
+ let label=line.trim()||"(empty)";
274
+ const act=async()=>{
275
+ if(connected&&/^\d+$/.test(line.trim())){const selected=actionMenu.select(line.trim());label=selected.label;return connected.humanAction(selected.key,{tip:selected.tip,requestDigest:selected.requestDigest});}
276
+ if(connected)return dashboardHostAction(connected,line);
277
+ if(debrief)return debriefAction(debrief,line);
278
+ throw Error("Read-only snapshot; no controls connected");
279
+ };
280
+ feedback = `Action ${label} — awaiting acknowledgement…`;
281
+ void act().then(outcome => {
282
+ feedback = connected ? dashboardActionFeedback(label, outcome) : `ACKNOWLEDGED: ${label}. Refreshed state is shown below.`;
271
283
  }).catch(error => {
272
284
  feedback = `REJECTED: ${error instanceof Error ? error.message : String(error)}. No command was retried; inspect the refreshed offered keys.`;
273
285
  }).finally(() => { acting = false; redraw(); });
@@ -32,6 +32,8 @@ export interface DashboardHostConfig {
32
32
  budgetDigest: string; experimentDigest: string | null; harnessArtifactDigest: string;
33
33
  ordinaryDigest?: string;
34
34
  learningLifecycleId?: string;
35
+ /** Explicit host journal, while reusing the original trust store/attention across host lifetimes. */
36
+ journalDirectory?: string;
35
37
  }
36
38
  export interface DashboardHostRequest { version: "1.0"; requestId: string; hostDigest: string; expectedTip: string; selectionDigest: string; operation: "observe" | "present" | "presented" | "defer" | "debrief" | "dispatch" | "intent" | "cancel" | "dispatch-reconcile" | "intent-reconcile" | "ordinary-cancel"; payload: unknown }
37
39
  export interface DashboardHostAuthority {
@@ -13,10 +13,13 @@ export async function serveDashboardHost(path:string,host:DashboardHost){
13
13
  if(!isDashboardHost(host))throw Error("original dashboard host required");await parent(path);const clients=new Set<Socket>(),tasks=new Set<Promise<void>>();
14
14
  const server=createServer(socket=>{if(clients.size>=4){socket.destroy();return;}clients.add(socket);socket.on("close",()=>clients.delete(socket));socket.on("error",()=>{});socket.setTimeout(5000,()=>socket.destroy());let size=0,used=false;const chunks:Buffer[]=[];
15
15
  socket.on("data",bytes=>{if(used)return;size+=bytes.length;if(size>65536){socket.destroy();return;}chunks.push(bytes);if(bytes.at(-1)!==10)return;used=true;
16
- const task=(async()=>{try{const text=new TextDecoder("utf-8",{fatal:true}).decode(Buffer.concat(chunks));const r=parseRetentionJson(text,65536) as {operation:string;request?:DashboardHostRequest;key?:string};let result:unknown;
16
+ const task=(async()=>{try{const text=new TextDecoder("utf-8",{fatal:true}).decode(Buffer.concat(chunks));const r=parseRetentionJson(text,65536) as {operation:string;request?:DashboardHostRequest;key?:string;expected?:{tip:string;requestDigest:string}};let result:unknown;
17
17
  if(Object.keys(r).join()==="operation"&&r.operation==="frame")result=await host.frame();
18
18
  else if(Object.keys(r).sort().join()==="operation,request"&&r.operation==="action")result=await host.action(dashboardHostRequest(r.request!));
19
- else if(Object.keys(r).sort().join()==="key,operation"&&r.operation==="human-action"&&typeof r.key==="string")result=await host.humanAction(r.key);
19
+ else if(["key,operation","expected,key,operation"].includes(Object.keys(r).sort().join())&&r.operation==="human-action"&&typeof r.key==="string"){
20
+ if(r.expected&&(!/^[a-f0-9]{64}$/.test(r.expected.tip)||!/^[a-f0-9]{64}$/.test(r.expected.requestDigest)||Object.keys(r.expected).sort().join()!=="requestDigest,tip"))throw Error("exact displayed action required");
21
+ result=await host.humanAction(r.key,r.expected);
22
+ }
20
23
  else throw Error("closed dashboard protocol required");
21
24
  const output=JSON.stringify({ok:true,result})+"\n";if(Buffer.byteLength(output)>512*1024)throw Error("dashboard frame bound exceeded");socket.end(output);
22
25
  }catch{socket.end(JSON.stringify({ok:false,error:"refused or acknowledgement unknown; explicit readback only"})+"\n");}})();tasks.add(task);void task.finally(()=>tasks.delete(task));
@@ -28,7 +31,7 @@ export async function serveDashboardHost(path:string,host:DashboardHost){
28
31
  }
29
32
  /** Explicit operator-selected endpoint. Socket ownership is access policy, not module/human authentication. */
30
33
  export function connectDashboardHost(path:string):DashboardConnection{
31
- const call=async(operation:string,payload:{request?:DashboardHostRequest;key?:string}={})=>{await parent(path);const s=await lstat(path);if(!s.isSocket()||s.mode&0o077||s.uid!==process.getuid?.())throw Error("private original dashboard endpoint unavailable");
34
+ const call=async(operation:string,payload:{request?:DashboardHostRequest;key?:string;expected?:{tip:string;requestDigest:string}}={})=>{await parent(path);const s=await lstat(path);if(!s.isSocket()||s.mode&0o077||s.uid!==process.getuid?.())throw Error("private original dashboard endpoint unavailable");
32
35
  return new Promise<any>((resolve,reject)=>{const socket=createConnection(path);let size=0,done=false;const chunks:Buffer[]=[];const fail=(e:unknown)=>{if(!done){done=true;socket.destroy();reject(e);}};
33
36
  socket.setTimeout(5000,()=>fail(Error("dashboard acknowledgement timeout; do not repeat action")));socket.on("error",fail);socket.on("connect",()=>socket.write(JSON.stringify({operation,...payload})+"\n"));
34
37
  socket.on("data",b=>{size+=b.length;if(size>512*1024){fail(Error("dashboard frame limit"));return;}chunks.push(b);});
@@ -36,5 +39,5 @@ export function connectDashboardHost(path:string):DashboardConnection{
36
39
  socket.on("close",()=>{if(!done)fail(Error("dashboard disconnected; acknowledgement unknown"));});
37
40
  });
38
41
  };
39
- const api={frame:()=>call("frame"),action:(r:DashboardHostRequest)=>call("action",{request:dashboardHostRequest(r)}),humanAction:(key:string)=>call("human-action",{key})};connections.add(api);return Object.freeze(api);
42
+ const api={frame:()=>call("frame"),action:(r:DashboardHostRequest)=>call("action",{request:dashboardHostRequest(r)}),humanAction:(key:string,expected?:{tip:string;requestDigest:string})=>call("human-action",{key,...(expected?{expected}:{})})};connections.add(api);return Object.freeze(api);
40
43
  }
@@ -1,3 +1,4 @@
1
+ import type { WorkPresentation } from "./daily-panel.ts";
1
2
  import { isOrdinaryChildren, holdOrdinaryDispatch, type OrdinaryChildren, type OrdinaryCancellation } from "./ordinary-children.ts";
2
3
  import { loadedDashboardHarnessDigest } from "./dashboard-harness.ts";
3
4
  import { join, isAbsolute } from "node:path";
@@ -22,6 +23,11 @@ export type DashboardHost=ReturnType<typeof openDashboardHost>;
22
23
  export interface DashboardHostOptions { ordinary?:OrdinaryChildren; harness:DashboardHarness; config:DashboardHostConfig; budget:GovernedBudgetBinding; experiment?:ReturnType<typeof openExperiment>; authority:()=>DashboardHostAuthority|null;
23
24
  /** Exact actions constructed and authorized by the owner; the dashboard exposes only human labels/keys. */
24
25
  humanActions?:(context:{hostDigest:string;selectionDigest:string;tip:string;observations:readonly {sourceId:string;checkpointId:string}[];preparedPresentationDigest:string|null})=>readonly {key:string;label:string;request:DashboardHostRequest}[]|Promise<readonly {key:string;label:string;request:DashboardHostRequest}[]>;
26
+ /** Read-only, digest-bound local outcome labels. Never grants acceptance or control. */
27
+ presentation?: () => WorkPresentation | null | Promise<WorkPresentation | null>;
28
+ currentWork?: () => Promise<import("./daily-view.ts").DailyView>;
29
+ learningView?: () => unknown;
30
+ afterObservation?: (observation: import("./dashboard-observation.ts").DashboardObservation) => void;
25
31
  /** Explicit approved observation effect only; refresh/frame never invokes it. */
26
32
  beforeObservation?:(sourceId:string)=>Promise<void>;
27
33
  /** Owner callback after the exact intent journal reports applied; failure keeps host acknowledgement unknown. */
@@ -30,7 +36,8 @@ export interface DashboardHostOptions { ordinary?:OrdinaryChildren; harness:Dash
30
36
  presence?:()=>{present:boolean;closing:boolean;evidenceDigest:string;expiresAt:number}|null;
31
37
  }
32
38
  function configuration(input:DashboardHostConfig){
33
- const c=detached(input);controlShape(c,["version","trustDirectory","trustPolicyId","archiveRoot","scope","author","policyPath","policySha256","sources","selection","cases","blind","budgetDigest","experimentDigest","harnessArtifactDigest",...(Object.hasOwn(c,"ordinaryDigest")?["ordinaryDigest"]:[]),...(Object.hasOwn(c,"learningLifecycleId")?["learningLifecycleId"]:[])]);
39
+ const c=detached(input);controlShape(c,["version","trustDirectory","trustPolicyId","archiveRoot","scope","author","policyPath","policySha256","sources","selection","cases","blind","budgetDigest","experimentDigest","harnessArtifactDigest",...(Object.hasOwn(c,"ordinaryDigest")?["ordinaryDigest"]:[]),...(Object.hasOwn(c,"learningLifecycleId")?["learningLifecycleId"]:[]),...(Object.hasOwn(c,"journalDirectory")?["journalDirectory"]:[])]);
40
+ if(c.journalDirectory!==undefined&&(typeof c.journalDirectory!=="string"||!isAbsolute(c.journalDirectory)))throw Error("explicit host journal directory required");
34
41
  if(Object.hasOwn(c,"ordinaryDigest")&&!sha(c.ordinaryDigest))throw Error("invalid ordinary binding digest");
35
42
  if(Object.hasOwn(c,"learningLifecycleId")&&!sha(c.learningLifecycleId))throw Error("invalid learning lifecycle manifest");
36
43
  if(c.version!=="producer-dashboard-host-v1"||![c.trustDirectory,c.archiveRoot,c.policyPath].every(p=>typeof p==="string"&&isAbsolute(p))||![c.trustPolicyId,c.policySha256,c.budgetDigest,c.harnessArtifactDigest].every(sha)||!(c.experimentDigest===null||sha(c.experimentDigest))||typeof c.scope!=="string"||!c.scope||c.scope.length>128||typeof c.author!=="string"||!c.author||c.author.length>256||!Array.isArray(c.sources)||c.sources.length<1||c.sources.length>32||new Set(c.sources.map(s=>s.id)).size!==c.sources.length||c.sources.filter(s=>s.kind==="work").length>1||c.sources.some(s=>!/^[a-zA-Z0-9:_-]{1,128}$/.test(s.id)||!["work","retention","facts"].includes(s.kind)))throw Error("invalid explicit dashboard host binding");
@@ -43,7 +50,7 @@ export function createDashboardHost(options:DashboardHostOptions){
43
50
  if(!a?.hostDigests.includes(dashboardHostDigest(c)))throw Error("independent exact host authority required");
44
51
  const trust=h.openTrustLifecycle(c.trustDirectory),view=trust.inspect(Date.now());
45
52
  if(view.policyId!==c.trustPolicyId)throw Error("trust policy changed");
46
- h.learningJournal(join(c.trustDirectory,"producer-host"),{type:"producer-host-initial",config:c});
53
+ h.learningJournal(c.journalDirectory??join(c.trustDirectory,"producer-host"),{type:"producer-host-initial",config:c});
47
54
  return openDashboardHost(options);
48
55
  }
49
56
  /** Existing native writers + original controllers; no model, launch, authority-file loader or PID recovery. */
@@ -53,7 +60,7 @@ export function openDashboardHost(options:DashboardHostOptions){
53
60
  const budget=openResourceBudget(options.budget),experiment=options.experiment,ordinary=options.ordinary;
54
61
  if(ordinary&&(!isOrdinaryChildren(ordinary)||ordinary.bindingDigest!==c.ordinaryDigest))throw Error("original ordinary controller binding required");
55
62
  if(resourceBindingDigest(budget.binding)!==c.budgetDigest||experiment&&(!isExperimentController(experiment)||experimentBindingDigest(experiment.binding)!==c.experimentDigest))throw Error("original controller binding required");
56
- const trust=h.openTrustLifecycle(c.trustDirectory),journal=h.learningJournal(join(c.trustDirectory,"producer-host"));
63
+ const trust=h.openTrustLifecycle(c.trustDirectory),journal=h.learningJournal(c.journalDirectory??join(c.trustDirectory,"producer-host"));
57
64
  const initial=journal.read()[0].value;
58
65
  if(initial.type!=="producer-host-initial"||dataDigest(initial.config)!==hostDigest)throw Error("host store binding changed; no new budget");
59
66
  const trustInput=trust.history()[0].value.input as {archiveRoot:string;component:unknown;exposure:{attentionRemaining:number}|null};
@@ -62,7 +69,7 @@ export function openDashboardHost(options:DashboardHostOptions){
62
69
  const observation=dashboardObservations(h,c,journal.read),history=()=>journal.read();
63
70
  const append=(value:Record<string,unknown>)=>journal.append(history().at(-1)!.id,value);
64
71
  const saved=():DebriefCheckpoint|null=>{const rows=history().filter(e=>e.value.type==="checkpoint");return rows.length?detached(rows.at(-1)!.value.checkpoint) as DebriefCheckpoint:null;};
65
- let presenter:DebriefPresenter|undefined,busy=false,poisoned=false,presentationRevision:number|null=null,presenceDigest:string|null=null,attentionDeferred:string|null=null,presentationAcknowledged=false;
72
+ let presenter:DebriefPresenter|undefined,busy=false,poisoned=false,stopped=false,presentationRevision:number|null=null,presenceDigest:string|null=null,attentionDeferred:string|null=null,presentationAcknowledged=false;
66
73
  const ordinaryDispatchHoldKey=dataDigest({hostDigest,control:"pause-new-ordinary-dispatch"});
67
74
  // A host frame is a read-only snapshot: ordinary children may attach or settle without advancing this journal.
68
75
  // Within one tip, a key keeps its first exact request; humanAction revalidates it against current native authority.
@@ -88,39 +95,60 @@ export function openDashboardHost(options:DashboardHostOptions){
88
95
  return {key:x.key,label:x.label,operation:request.operation,request};});
89
96
  };
90
97
  const api={hostDigest,selectionDigest,
98
+ /** Same owner gate as action: checking stop cannot race a newly admitted effect. Never releases a hold. */
99
+ async stop(){
100
+ if(stopped)return;if(busy)throw Error("Cannot stop: dashboard operation busy; wait for its acknowledgement first");busy=true;
101
+ try{
102
+ const rows=history();
103
+ if(poisoned||rows.some(e=>e.value.type==="host-failure")||rows.some(e=>e.value.type==="claim"&&!rows.some(r=>r.value.type==="result"&&r.value.requestId===e.value.requestId)))throw Error("Cannot stop: acknowledgement unknown; retain this original host for readback. Do not repeat effects. Ending the whole Pi session does not reconcile or release this hold.");
104
+ if(c.ordinaryDigest&&!ordinary)throw Error("Cannot stop: original ordinary boundary unavailable; no recovery");
105
+ const dispatch=await budget.controls(null).inspect();
106
+ if(dispatch.admission==="blocked-pending")throw Error("Cannot stop: pending original control requires explicit reconciliation, then resume before stopping");
107
+ if(dispatch.paused||ordinary&&(ordinary.inspect() as {admission:string}).admission!=="open")throw Error("Cannot stop: resume new work in the original dashboard first. Any pending intent also needs its original reconciliation; no hold was released.");
108
+ stopped=true;presenter?.close();presentationRevision=null;
109
+ }finally{busy=false;}
110
+ },
111
+ /** Final owner-session disposal only, not /grants host stop. Disconnects without resolving/releasing any control. */
112
+ endSession(){stopped=true;presenter?.close();presentationRevision=null;},
91
113
  async frame(){
92
114
  const rows=history(),tip=rows.at(-1)!.id,a=authority();let source:unknown=null,error:string|null=null;
93
115
  let selection=c.selection,selectionState="current-control-snapshot";
94
116
  try{selection=await currentSelection();}catch(e){error=String(e);selectionState="unavailable-host-declaration-only";}
95
- try{source=await observation.view(selectionState==="current-control-snapshot"?a:null,selection);}catch(e){error=String(e);}
117
+ try{source=await observation.view(selectionState==="current-control-snapshot"?a:null,selection);
118
+ if(options.currentWork)source={...(source as object),daily:await options.currentWork()};
119
+ }catch(e){error=String(e);}
96
120
  let debrief:unknown=null;
97
121
  if(a&&presenter&&presentationRevision!==null&&presence()?.evidenceDigest===presenceDigest){try{await paused(presentationRevision);debrief=presenter.view();}catch{debrief=null;}}
98
122
  let controls:unknown=null;try{controls=await nativeRead();}catch(e){error=String(e);}
99
123
  let learning:unknown=null;if(c.learningLifecycleId)try{learning=h.readLearningLifecycle(c.archiveRoot,c.learningLifecycleId);}catch(e){error=String(e);}
100
- const attention=trust.inspect(Date.now());let actions:{key:string;label:string;operation:string}[]=[];
124
+ let presentation:WorkPresentation|null=null;try{presentation=await options.presentation?.()??null;}catch(e){error=String(e);}
125
+ if(options.learningView)try{learning=options.learningView();}catch(e){learning={state:"deferred",reason:String(e)};}
126
+ const attention=trust.inspect(Date.now());let actions:{key:string;label:string;operation:string;requestDigest:string}[]=[];
101
127
  try{const available=await availableHumanActions();
102
128
  // A frame that completed after its captured tip is stale and cannot replace a newer display generation.
103
- if(history().at(-1)!.id===tip){
129
+ if(!stopped&&history().at(-1)!.id===tip){
104
130
  if(!displayedActions||displayedActions.tip!==tip)displayedActions={tip,actions:new Map()};
105
131
  const additions=available.filter(action=>!displayedActions!.actions.has(action.key));
106
132
  if(displayedActions.actions.size+additions.length>MAX_DISPLAYED_ACTIONS_PER_TIP)throw Error("displayed dashboard action capacity exhausted");
107
133
  const shown=available.filter(action=>{const prior=displayedActions!.actions.get(action.key);
108
134
  if(prior&&dashboardHostRequestDigest(prior.request)!==dashboardHostRequestDigest(action.request))return false;
109
135
  if(!prior)displayedActions!.actions.set(action.key,action);return true;});
110
- actions=shown.map(({key,label,operation})=>({key,label,operation}));
136
+ actions=shown.map(({key,label,operation,request})=>({key,label,operation,requestDigest:dashboardHostRequestDigest(request)}));
111
137
  }}catch(e){error=String(e);}
112
- return freeze(detached({version:"producer-dashboard-frame-v1",hostDigest,selectionDigest:dashboardSelectionDigest(selection),selectionState,tip,source,controls,learning,debrief,attention,error,actions,
138
+ return freeze(detached({version:"producer-dashboard-frame-v1",hostDigest,selectionDigest:dashboardSelectionDigest(selection),selectionState,tip,source,controls,learning,debrief,attention,error,actions,presentation,
113
139
  requests:rows.filter(e=>["claim","result","presentation","defer","ordinary-intent-pending"].includes(String(e.value.type))).map(e=>e.value),
114
140
  control:rows.some(e=>e.value.type==="host-failure")?"failed":rows.some(e=>e.value.type==="claim"&&!rows.some(r=>r.value.type==="result"&&r.value.requestId===e.value.requestId))?"unknown":"not-assessed",
115
141
  acknowledgement:poisoned?"unknown":"readback-only",identity:"independently-declared-host; not human/module authentication",activeBranch:null,acceptance:"not-assessed",freshness:"snapshot-unknown",workerInteractions:0}));
116
142
  },
117
143
  /** Explicit reconciliation is read-only. A retained claim is never replayed as an effect. */
118
144
  reconcile:()=>api.frame(),
119
- async humanAction(key:string){const tip=history().at(-1)!.id;if(!displayedActions||displayedActions.tip!==tip)throw Error("dashboard actions must be displayed at the current tip");
145
+ async humanAction(key:string,expected?:{tip:string;requestDigest:string}){const tip=history().at(-1)!.id;if(expected&&expected.tip!==tip)throw Error("displayed action is stale; select again");if(!displayedActions||displayedActions.tip!==tip)throw Error("dashboard actions must be displayed at the current tip");
120
146
  const found=displayedActions.actions.get(key);if(!found)throw Error(`unknown dashboard action ${JSON.stringify(key)}`);
147
+ if(expected&&dashboardHostRequestDigest(found.request)!==expected.requestDigest)throw Error("displayed action identity changed; no effect attempted");
121
148
  const current=(await availableHumanActions()).find(action=>action.key===key);if(!current||current.label!==found.label||dashboardHostRequestDigest(current.request)!==dashboardHostRequestDigest(found.request))throw Error("displayed dashboard action changed; no effect attempted");return api.action(found.request);},
122
149
  async action(input:DashboardHostRequest){
123
150
  const request=dashboardHostRequest(input),digest=dashboardHostRequestDigest(request);
151
+ if(stopped)throw Error("dashboard host stopped; no effect attempted");
124
152
  if(busy||poisoned)throw Error("dashboard operation busy or acknowledgement unknown");busy=true;let attempted=false;
125
153
  try{
126
154
  const rows=history(),old=rows.find(e=>e.value.type==="claim"&&e.value.requestId===request.requestId);
@@ -135,7 +163,7 @@ export function openDashboardHost(options:DashboardHostOptions){
135
163
  try{
136
164
  if(request.operation==="observe"){
137
165
  const sourceId=(request.payload as {sourceId?:unknown})?.sourceId;if(typeof sourceId!=="string")throw Error("exact observation source required");await options.beforeObservation?.(sourceId);
138
- const captured=observation.observe(request.payload,a!,selection);append({type:"observation",observation:captured});result=captured;
166
+ const captured=observation.observe(request.payload,a!,selection);append({type:"observation",observation:captured});options.afterObservation?.(captured);result=captured;
139
167
  }else if(request.operation==="present"){
140
168
  const p=detached(request.payload) as {userPresent:boolean;closing:boolean;evidenceDigest:string;dispatchRevision:number};
141
169
  if(Object.keys(p).sort().join()!=="closing,dispatchRevision,evidenceDigest,userPresent"||!sha(p.evidenceDigest)||typeof p.userPresent!=="boolean"||typeof p.closing!=="boolean"||!Number.isSafeInteger(p.dispatchRevision))throw Error("explicit presence/boundary evidence required");
@@ -165,8 +193,10 @@ export function openDashboardHost(options:DashboardHostOptions){
165
193
  const port=budget.controls(a!.dispatch),ordinaryHold=ordinary&&["pause-dispatch","resume-dispatch"].includes(native.action)?holdOrdinaryDispatch(ordinary,ordinaryDispatchHoldKey):undefined;
166
194
  if(request.operation==="dispatch-reconcile"&&(await port.inspect()).records.find(r=>r.request.requestId===native.requestId)?.digest!==dispatchRequestDigest(native))throw Error("exact original dispatch reconciliation required");
167
195
  result=request.operation==="dispatch"?await port.request(native):await port.reconcile(native.requestId);
168
- const record=(result as {records:{request:{requestId:string};decision:string;application:string}[]}).records.find(r=>r.request.requestId===native.requestId);
169
- if(ordinaryHold&&(record?.decision!=="approved"||native.action==="resume-dispatch"&&record.application==="applied"))ordinaryHold.release();
196
+ const snapshot=result as import("./dispatch-control.ts").DispatchSnapshot,record=snapshot.records.find(r=>r.request.requestId===native.requestId);
197
+ if(!record)throw Error("native dispatch application acknowledgement unavailable");
198
+ // A denied resume must not undo an earlier pause/pending control. Release only after final host sync.
199
+ if(ordinaryHold&&(native.action==="resume-dispatch"&&record.decision==="approved"&&record.application==="applied"||record.application==="not-applied"&&snapshot.admission==="enabled"))releaseOrdinary=ordinaryHold.release;
170
200
  }else if(request.operation==="intent"||request.operation==="intent-reconcile"){
171
201
  const native=detached(intentRequest(request.payload as IntentRequest)) as IntentRequest,port=budget.intentControls(a!.dispatch),digest=intentRequestDigest(native);
172
202
  if(c.ordinaryDigest&&!ordinary)throw Error("original ordinary boundary unavailable; no recovery");
@@ -202,6 +232,11 @@ export function openDashboardHost(options:DashboardHostOptions){
202
232
  }else throw Error("unsupported dashboard operation");
203
233
  }
204
234
  }catch(error){presenter?.close();presentationRevision=null;append({type:"result",requestId:request.requestId,state:"failed-or-unknown",reason:String(error)});throw error;}
235
+ if(["dispatch","dispatch-reconcile","intent","intent-reconcile"].includes(request.operation)&&result&&typeof result==="object"){
236
+ const snapshot=result as {records?:{requestId?:string;request?:{requestId:string};application?:string}[]},nativeId=(request.payload as {requestId:string}).requestId;
237
+ const applied=snapshot.records?.find(r=>(r.requestId??r.request?.requestId)===nativeId);
238
+ if(applied?.application)result={...result,application:applied.application,nativeRequestId:nativeId};
239
+ }
205
240
  append({type:"result",requestId:request.requestId,state:"acknowledged",resultDigest:dataDigest(result??null)});releaseOrdinary?.();return {state:"acknowledged",result};
206
241
  }catch(error){if(attempted){poisoned=true;try{if(history().some(e=>e.value.type==="claim"&&e.value.requestId===request.requestId))append({type:"host-failure",requestId:request.requestId,reason:String(error)});}catch{/* Failure recording also unacknowledged; no claim of no effects. */}}throw error;}finally{busy=false;}
207
242
  }
@@ -0,0 +1,28 @@
1
+ import type { PanelAction } from "./daily-panel.ts";
2
+ /** Numbers never acquire another meaning during repaint, including after a new journal tip. */
3
+ export function createDashboardMenu() {
4
+ const ids = new Map<string, string>();
5
+ const choices = new Map<string, { key: string; tip: string; requestDigest: string; label: string }>();
6
+ let current = new Set<string>();
7
+ return {
8
+ show(tip: string, actions: readonly PanelAction[]) {
9
+ current = new Set();
10
+ return actions.map(action => {
11
+ if (!action.requestDigest) return { choice: action.key, label: action.label };
12
+ const identity = JSON.stringify([tip, action.key, action.requestDigest, action.label]);
13
+ let choice = ids.get(identity);
14
+ if (!choice) {
15
+ if (ids.size >= 32768) throw Error("Action menu capacity reached; reopen the panel. No choice was remapped.");
16
+ choice = String(ids.size + 1); ids.set(identity, choice);
17
+ choices.set(choice, { key: action.key, tip, requestDigest: action.requestDigest, label: action.label });
18
+ }
19
+ current.add(choice); return { choice, label: action.label };
20
+ });
21
+ },
22
+ select(choice: string) {
23
+ if (!current.has(choice)) throw Error("That action is no longer displayed; select a current number.");
24
+ return choices.get(choice)!;
25
+ },
26
+ clear() { current.clear(); },
27
+ };
28
+ }
@@ -20,9 +20,8 @@
20
20
  */
21
21
 
22
22
  import { createHash } from "node:crypto";
23
- import { readFile, readdir } from "node:fs/promises";
24
- import { join } from "node:path";
25
- import { skillDirs } from "./catalog.ts";
23
+ import { readFile } from "node:fs/promises";
24
+ import { resolveSkillResources, skillResourceName } from "./skill-resources.ts";
26
25
  import { CAPABILITY_NAMESPACE_PREFIXES } from "./capabilities.ts";
27
26
  import type { Capability } from "./resolve.ts";
28
27
 
@@ -133,6 +132,11 @@ export function parseSkillDefinition(source: string, text: string): SkillDefinit
133
132
  continue;
134
133
  }
135
134
 
135
+ // A YAML collection/block we cannot parse is not an explicit empty ceiling.
136
+ if (key === "allowed-tools" && value === "") {
137
+ const nextValue = lines.slice(i + 1).find(line => line.trim() !== "" && !/^\s*#/.test(line));
138
+ if (/^\s+\S/.test(nextValue ?? "")) continue;
139
+ }
136
140
  fields.set(key, value);
137
141
  }
138
142
 
@@ -144,7 +148,7 @@ export function parseSkillDefinition(source: string, text: string): SkillDefinit
144
148
  // skills by their directory, so trusting a frontmatter `name` lets our view and the loader's
145
149
  // disagree about which file a name refers to. The spec requires `name` to match the parent
146
150
  // directory anyway, so a mismatch is the file's defect and not something to honour.
147
- name: nameFromPath(source),
151
+ name: skillResourceName(source),
148
152
  description,
149
153
  allowedTools: fields.get("allowed-tools"),
150
154
  metadata: Object.keys(metadata).length > 0 ? metadata : undefined,
@@ -153,14 +157,6 @@ export function parseSkillDefinition(source: string, text: string): SkillDefinit
153
157
  };
154
158
  }
155
159
 
156
- /** `/skills/review/SKILL.md` -> `review`; `/skills/triage.md` -> `triage`. */
157
- function nameFromPath(source: string): string {
158
- const parts = source.split("/").filter((p) => p.length > 0);
159
- const last = parts.at(-1) ?? "";
160
- if (last.toLowerCase() === "skill.md") return parts.at(-2) ?? "";
161
- return last.replace(/\.md$/i, "");
162
- }
163
-
164
160
  /**
165
161
  * Turn a definition's `allowed-tools` into a capability ceiling.
166
162
  *
@@ -199,41 +195,17 @@ export function ceilingForDefinition(definition: SkillDefinition): DefinitionCei
199
195
  }
200
196
 
201
197
  /**
202
- * Discover `SKILL.md` definitions under pi's skill roots.
203
- *
204
- * Deliberately the SAME roots and the same convention the catalog uses (`skillDirs`): a directory
205
- * containing `SKILL.md` is one definition named after the directory, and a top-level `.md` is one named
206
- * after the file. If discovery and the catalog disagreed, a definition could be spawnable but not
207
- * grantable, or listed but unspawnable.
208
- *
209
- * Earlier directories win on a name collision, matching pi's own precedence — project before global.
198
+ * Read definitions from Pi's enabled resources, including installed packages and local overrides.
199
+ * Resolver precedence and filters are shared with the capability catalog; unregistered npm packages
200
+ * are not runtime resources until legacy init explicitly scaffolds them.
210
201
  */
211
202
  export async function loadDefinitions(cwd: string): Promise<Map<string, SkillDefinition>> {
212
203
  const definitions = new Map<string, SkillDefinition>();
213
- for (const dir of skillDirs(cwd)) {
214
- let names: string[];
215
- try {
216
- names = await readdir(dir);
217
- } catch {
218
- continue; // an absent skill root is normal
219
- }
220
- for (const name of [...names].sort()) {
221
- // A directory holding SKILL.md, or a top-level .md — try the former first, exactly as the
222
- // catalog does, so the two cannot disagree about what exists.
223
- const candidates = [join(dir, name, "SKILL.md"), ...(name.endsWith(".md") ? [join(dir, name)] : [])];
224
- for (const path of candidates) {
225
- let text: string;
226
- try {
227
- text = await readFile(path, "utf8");
228
- } catch {
229
- continue; // not this shape; try the next candidate
230
- }
231
- const parsed = parseSkillDefinition(path, text);
232
- // First writer wins, so project definitions shadow global ones rather than the reverse.
233
- if (parsed && !definitions.has(parsed.name)) definitions.set(parsed.name, parsed);
234
- break;
235
- }
236
- }
204
+ for (const { path } of (await resolveSkillResources(cwd)).skills) {
205
+ let text: string;
206
+ try { text = await readFile(path, "utf8"); } catch { continue; }
207
+ const parsed = parseSkillDefinition(path, text);
208
+ if (parsed && !definitions.has(parsed.name)) definitions.set(parsed.name, parsed);
237
209
  }
238
210
  return definitions;
239
211
  }
package/src/index.ts CHANGED
@@ -45,7 +45,8 @@ export { renderDebrief, debriefAction as dashboardDebriefAction } from "./debrie
45
45
  export { type ReviewPort, type ReviewRequest, type BlindPort, type BlindChoice } from "./debrief-contract.ts";
46
46
  export { readDailyView, createDailyViewReader, DAILY_VIEW_VERSION, type DailyView, type DailyViewOptions,
47
47
  type DailyAttempt, type DailyObligation } from "./daily-view.ts";
48
- export { renderDailyView } from "./daily-view-render.ts";
48
+ export { renderDailyView, renderDailyDetails } from "./daily-view-render.ts";
49
+ export { renderDailyPanel, type PanelOptions, type WorkPresentation } from "./daily-panel.ts";
49
50
  export { parseArchiveProjection, ARCHIVE_PROJECTION_VERSION } from "./daily-view-input.ts";
50
51
  export { bindWorkIntent } from "./intent-application.ts";
51
52
  export { intentRequestDigest, parseIntentRequest, type IntentRequest, type IntentSelection, type IntentPriority,
@@ -154,6 +155,11 @@ export {
154
155
  } from "./dashboard-projection.ts";
155
156
 
156
157
  export { renderDashboard, type DashboardRenderOptions } from "./dashboard-render.ts";
158
+ export { declareWork, loadDeclaredWork, type DeclaredWorkState } from "./work-command.ts";
159
+ export { workSetup, recordWorkSetup, selectRecordedWork, loadWorkSetup, listWorkSetups, workPresentation, type WorkSetup, type WorkTaskSetup, type RecordedWorkSetup } from "./work-setup.ts";
160
+ export { runWorkSetup, inspectWorkRun, type WorkRunResult, type WorkRunInitial, type WorkPolicyPin } from "./work-run.ts";
161
+ export { workPolicy, workPolicyDigest, policyForSetup, createWorkPolicyRegistry, openWorkPolicyRegistry, workPolicyActivationDigest, type WorkPolicy, type WorkPolicyRegistry, type WorkPolicyActivation } from "./work-policy-registry.ts";
162
+ export { learningHarness, bindLearningConnection, loadLearningConnection, bindLearningAdoption, learningScopeDigest, type LearningConnection, type LearningWorkspace } from "./learning-connection.ts";
157
163
 
158
164
  export {
159
165
  runMeasuredAgentSession,
package/src/init.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * `pi-daddy init` — scaffold a governed project from the skill packages already installed (B2, P3).
3
3
  *
4
- * Today an operator wanting to govern a package of skills must, per skill: create a directory, copy the
5
- * body, hand-write frontmatter, choose a capability set with no guidance, and assemble a `PI_GRANTS_GRANT`
6
- * string by hand. Seven times, for `principal-pi-skills`. This does the mechanical parts.
4
+ * Legacy unregistered npm packages can be scaffolded per skill: create a directory, copy the
5
+ * body and declaration copies plus a starting `PI_GRANTS_GRANT`. Configured enabled Pi resources
6
+ * are referenced where installed instead (ADR-0074); no competing .pi/skills copy is created.
7
7
  *
8
8
  * **The line it does not cross, and the reason this module exists at all:** `init` writes files an operator
9
9
  * then **reviews, edits and commits**. It never chooses a ceiling. A skill that declares `allowed-tools` is
@@ -32,23 +32,9 @@ import { PI_BUILTIN_TOOLS } from "./pi-tools.ts";
32
32
  import type { Capability } from "./resolve.ts";
33
33
  import type { SkillPackage } from "./skill-packages.ts";
34
34
 
35
- /** Why a discovered skill is not authorised in the generated grant. `null` means it is. */
36
35
  /**
37
- * How many of `from`'s skills actually **declare** a ceiling.
38
- *
39
- * Exported because the number is printed to an operator and was wrong: `cli.ts` filtered on
40
- * `withheld === null`, which is false for all three `WithholdReason`s — so a skill that declares
41
- * `allowed-tools` perfectly well and merely needs a withheld capability counted as not declaring one.
42
- * Against `principal-pi-skills` that printed *"7 skill(s), 3 declaring allowed-tools"* while all seven
43
- * declared. R-28's shape: a diagnostic disagreeing with the thing it describes.
44
- *
45
- * **It was invisible until the integration worked.** Before ceilings shipped, none of the seven declared
46
- * and the line read *"0 declaring"* — correct by coincidence, for the wrong reason. A count that is right
47
- * only while the interesting case is absent is the kind this project keeps finding.
48
- *
49
- * `undeclared` is the only reason that means "did not declare". `pattern` declared something this package
50
- * refuses to reinterpret, and `needs-withheld` declared something fine that the operator must opt into —
51
- * both are declarations.
36
+ * Count declarations, not authorizations (R-73). Both pattern and needs-withheld mean the skill
37
+ * declared a ceiling; only undeclared means it did not. The CLI must report the same distinction.
52
38
  */
53
39
  export function countDeclaring(skills: PlannedSkill[], from: string): number {
54
40
  return skills.filter((s) => s.from === from && s.withheld !== "undeclared").length;
@@ -62,6 +48,8 @@ export interface PlannedSkill {
62
48
  from: string;
63
49
  sourcePath: string;
64
50
  targetPath: string;
51
+ /** Configured skills stay at their installed/local source, including when --force is used. */
52
+ referenced?: boolean;
65
53
  /** Exactly what would be written — the file verbatim, or the file plus a commented note. */
66
54
  content: string;
67
55
  /** The declared ceiling, empty when the declaration is absent or unusable. */
@@ -191,7 +179,8 @@ export function planInit(
191
179
  name,
192
180
  from: `${pkg.name}@${pkg.version}`,
193
181
  sourcePath: skill.path,
194
- targetPath: join(cwd, ".pi", "skills", name, "SKILL.md"),
182
+ targetPath: skill.referenced ? skill.path : join(cwd, ".pi", "skills", name, "SKILL.md"),
183
+ referenced: skill.referenced,
195
184
  content: withPlaceholder(skill.text, withheld === null, note),
196
185
  ceiling: ceiling.capabilities,
197
186
  withheld,
@@ -391,6 +380,7 @@ export async function applyInit(plan: InitPlan, options: { force?: boolean } = {
391
380
  }
392
381
  const force = options.force === true;
393
382
  for (const skill of plan.skills) {
383
+ if (skill.referenced) continue;
394
384
  if (force) await replace(skill.targetPath, skill.content, outcome);
395
385
  else await createUnlessPresent(skill.targetPath, skill.content, outcome);
396
386
  }