pi-daddy 0.55.0 → 0.56.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.
- package/CHANGELOG.md +4 -0
- package/README.md +1 -1
- package/dist/kernel/dashboard-choice.d.ts +58 -0
- package/dist/kernel/dashboard-choice.d.ts.map +1 -0
- package/dist/kernel/dashboard-choice.js +34 -0
- package/dist/kernel/dashboard-choice.js.map +1 -0
- package/dist/products/dashboard-choice-picker.d.ts +22 -0
- package/dist/products/dashboard-choice-picker.d.ts.map +1 -0
- package/dist/products/dashboard-choice-picker.js +219 -0
- package/dist/products/dashboard-choice-picker.js.map +1 -0
- package/dist/products/dashboard-cli.d.ts.map +1 -1
- package/dist/products/dashboard-cli.js +16 -4
- package/dist/products/dashboard-cli.js.map +1 -1
- package/dist/products/dashboard-components.d.ts.map +1 -1
- package/dist/products/dashboard-components.js +21 -1
- package/dist/products/dashboard-components.js.map +1 -1
- package/dist/products/dashboard-display-controls.d.ts +1 -1
- package/dist/products/dashboard-display-controls.d.ts.map +1 -1
- package/dist/products/dashboard-display-controls.js +6 -1
- package/dist/products/dashboard-display-controls.js.map +1 -1
- package/dist/products/dashboard-screen.d.ts +5 -1
- package/dist/products/dashboard-screen.d.ts.map +1 -1
- package/dist/products/dashboard-screen.js +17 -6
- package/dist/products/dashboard-screen.js.map +1 -1
- package/dist/products/dashboard-session-client.d.ts +18 -5
- package/dist/products/dashboard-session-client.d.ts.map +1 -1
- package/dist/products/dashboard-session-client.js +92 -14
- package/dist/products/dashboard-session-client.js.map +1 -1
- package/extensions/dashboard-choice-controls.ts +152 -0
- package/extensions/dashboard-session-server.ts +92 -17
- package/extensions/dashboard-sources.ts +12 -0
- package/extensions/runtime-snapshot.ts +1 -0
- package/extensions/session.ts +1 -0
- package/package.json +1 -1
- package/src/kernel/dashboard-choice.ts +73 -0
- package/src/products/dashboard-choice-picker.ts +228 -0
- package/src/products/dashboard-cli.ts +18 -3
- package/src/products/dashboard-components.ts +21 -1
- package/src/products/dashboard-display-controls.ts +7 -1
- package/src/products/dashboard-screen.ts +19 -6
- package/src/products/dashboard-session-client.ts +129 -19
|
@@ -1,10 +1,21 @@
|
|
|
1
|
+
import { validChoiceDetail, } from "../kernel/dashboard-choice.js";
|
|
1
2
|
import { createConnection } from "node:net";
|
|
3
|
+
class ChoiceDeclined extends Error {
|
|
4
|
+
stale;
|
|
5
|
+
constructor(stale) {
|
|
6
|
+
super(stale
|
|
7
|
+
? "Choice is no longer available. Refresh and reopen it."
|
|
8
|
+
: "Bookie declined the answer. Refresh and check the choice and answer.");
|
|
9
|
+
this.stale = stale;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
2
12
|
export async function dashboardSessionRequest(socketPath, token, request) {
|
|
3
13
|
return new Promise((resolve, reject) => {
|
|
4
14
|
const socket = createConnection(socketPath);
|
|
5
15
|
let output = "";
|
|
6
16
|
socket.setEncoding("utf8");
|
|
7
|
-
|
|
17
|
+
const choiceAction = request.action === "inspect-choice" || request.action === "answer-choice";
|
|
18
|
+
socket.setTimeout(choiceAction ? 30_000 : 2_000, () => socket.destroy(new Error("dashboard session request timed out")));
|
|
8
19
|
socket.once("error", reject);
|
|
9
20
|
socket.on("data", (chunk) => {
|
|
10
21
|
output += chunk;
|
|
@@ -14,8 +25,19 @@ export async function dashboardSessionRequest(socketPath, token, request) {
|
|
|
14
25
|
socket.once("end", () => {
|
|
15
26
|
try {
|
|
16
27
|
const parsed = JSON.parse(output);
|
|
17
|
-
if (!parsed.ok)
|
|
28
|
+
if (!parsed.ok) {
|
|
29
|
+
if (choiceAction) {
|
|
30
|
+
if (parsed.choiceOutcome === "stale" || parsed.choiceOutcome === "refused")
|
|
31
|
+
throw new ChoiceDeclined(parsed.choiceOutcome === "stale");
|
|
32
|
+
throw Error("The owner could not confirm the choice request.");
|
|
33
|
+
}
|
|
18
34
|
throw new Error(parsed.error ?? "dashboard session request failed");
|
|
35
|
+
}
|
|
36
|
+
if (request.action === "inspect-choice" &&
|
|
37
|
+
(!validChoiceDetail(parsed.choiceDetail) || parsed.choiceDetail.id !== request.choiceId))
|
|
38
|
+
throw Error("The owner returned an unavailable choice.");
|
|
39
|
+
if (request.action === "answer-choice" && parsed.choiceSaved !== true)
|
|
40
|
+
throw Error("Bookie did not confirm the answer.");
|
|
19
41
|
if (!parsed.auto ||
|
|
20
42
|
typeof parsed.auto.enabled !== "boolean" ||
|
|
21
43
|
!["default", "environment", "session"].includes(parsed.auto.source) ||
|
|
@@ -35,6 +57,7 @@ export async function dashboardSessionRequest(socketPath, token, request) {
|
|
|
35
57
|
export function createDashboardConnection(request) {
|
|
36
58
|
const state = { pending: false };
|
|
37
59
|
let generation = 0, poll = 0, requestedJev;
|
|
60
|
+
let choiceInterest = 0, consumedInterest = 0;
|
|
38
61
|
const retired = new Set();
|
|
39
62
|
const accept = (snapshot) => {
|
|
40
63
|
const previous = state.lastObserved?.observation, next = snapshot.observation;
|
|
@@ -59,14 +82,46 @@ export function createDashboardConnection(request) {
|
|
|
59
82
|
state.acknowledgment.state = snapshot.settings.jev.enabled === requestedJev ? "applied" : "refused";
|
|
60
83
|
return true;
|
|
61
84
|
};
|
|
85
|
+
const matchesOwner = (snapshot, target) => {
|
|
86
|
+
const owner = snapshot?.observation, expected = target.expectedOwner;
|
|
87
|
+
return (!!owner &&
|
|
88
|
+
owner.sessionId === expected.sessionId &&
|
|
89
|
+
owner.cwd === expected.cwd &&
|
|
90
|
+
owner.generation === expected.generation);
|
|
91
|
+
};
|
|
92
|
+
const matches = (snapshot, target) => {
|
|
93
|
+
const source = snapshot?.observation?.sources.find((s) => s.producer === "bookie-memory" && s.generation === target.sourceGeneration);
|
|
94
|
+
return (matchesOwner(snapshot, target) &&
|
|
95
|
+
snapshot?.choiceControls?.sourceGeneration === target.sourceGeneration &&
|
|
96
|
+
source?.availability === "observed" &&
|
|
97
|
+
source.items.some((i) => i.id === target.choiceId && i.kind === "work" && i.state === "observed"));
|
|
98
|
+
};
|
|
62
99
|
return {
|
|
63
100
|
state,
|
|
64
|
-
async
|
|
101
|
+
async inspectChoice(target) {
|
|
102
|
+
if (!request || state.pending || !matches(state.snapshot, target))
|
|
103
|
+
throw new ChoiceDeclined(true);
|
|
104
|
+
const result = await request({ ...target, action: "inspect-choice" });
|
|
105
|
+
if (!matches(state.snapshot, target) ||
|
|
106
|
+
!matches(result, target) ||
|
|
107
|
+
!validChoiceDetail(result.choiceDetail) ||
|
|
108
|
+
result.choiceDetail.id !== target.choiceId)
|
|
109
|
+
throw new ChoiceDeclined(true);
|
|
110
|
+
return result.choiceDetail;
|
|
111
|
+
},
|
|
112
|
+
requestChoiceRefresh() {
|
|
113
|
+
choiceInterest++;
|
|
114
|
+
},
|
|
115
|
+
async refresh(visibleChoices) {
|
|
65
116
|
if (!request || state.pending)
|
|
66
117
|
return;
|
|
67
118
|
const observed = generation, order = ++poll;
|
|
68
119
|
try {
|
|
69
|
-
const
|
|
120
|
+
const interest = choiceInterest;
|
|
121
|
+
const wanted = visibleChoices === "picker" || (visibleChoices === "list" && interest !== consumedInterest);
|
|
122
|
+
const { choiceRefreshRequested, ...snapshot } = await request(wanted ? { action: "get", refreshChoices: true } : { action: "get" });
|
|
123
|
+
if (choiceRefreshRequested)
|
|
124
|
+
consumedInterest = Math.max(consumedInterest, interest);
|
|
70
125
|
if (generation === observed && order === poll && !accept(snapshot)) {
|
|
71
126
|
state.snapshot = undefined;
|
|
72
127
|
state.error = "Owner observation is stale or unavailable; controls disabled until a fresh reply.";
|
|
@@ -82,22 +137,32 @@ export function createDashboardConnection(request) {
|
|
|
82
137
|
async change(action) {
|
|
83
138
|
if (!request || !state.snapshot || state.pending)
|
|
84
139
|
return false;
|
|
140
|
+
if (action.action === "answer-choice" && !matches(state.snapshot, action)) {
|
|
141
|
+
state.acknowledgment = {
|
|
142
|
+
action: action.action,
|
|
143
|
+
state: "refused",
|
|
144
|
+
effect: "Choice changed. Refresh and reopen it.",
|
|
145
|
+
};
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
85
148
|
const observedOwner = state.snapshot.observation;
|
|
86
149
|
generation++;
|
|
87
150
|
state.pending = true;
|
|
88
151
|
requestedJev = action.action === "set-jev" ? action.enabled : undefined;
|
|
89
|
-
const effect = action.action === "
|
|
90
|
-
? "
|
|
91
|
-
: action.action === "
|
|
92
|
-
? "
|
|
93
|
-
: action.action === "
|
|
94
|
-
? "
|
|
95
|
-
:
|
|
152
|
+
const effect = action.action === "answer-choice"
|
|
153
|
+
? "Save this answer in project memory"
|
|
154
|
+
: action.action === "set-auto"
|
|
155
|
+
? "current permission handling; admitted work unchanged"
|
|
156
|
+
: action.action === "edit-jev"
|
|
157
|
+
? "use the main Pi session; current values shown below"
|
|
158
|
+
: action.action === "set-jev"
|
|
159
|
+
? "current JEV session; separate paid-call and storage choices"
|
|
160
|
+
: "future children; running children unchanged";
|
|
96
161
|
state.acknowledgment = { action: action.action, state: "pending", effect };
|
|
97
162
|
try {
|
|
98
163
|
const snapshot = await request({
|
|
99
164
|
...action,
|
|
100
|
-
...(observedOwner
|
|
165
|
+
...(observedOwner && !action.expectedOwner
|
|
101
166
|
? {
|
|
102
167
|
expectedOwner: {
|
|
103
168
|
sessionId: observedOwner.sessionId,
|
|
@@ -107,7 +172,10 @@ export function createDashboardConnection(request) {
|
|
|
107
172
|
}
|
|
108
173
|
: {}),
|
|
109
174
|
});
|
|
110
|
-
if (!
|
|
175
|
+
if (action.action === "answer-choice" && (snapshot.choiceSaved !== true || !matchesOwner(snapshot, action)))
|
|
176
|
+
throw Error("Bookie did not confirm the answer.");
|
|
177
|
+
const { choiceDetail: _detail, choiceSaved: _saved, ...observed } = snapshot;
|
|
178
|
+
if (!accept(observed))
|
|
111
179
|
throw Error("owner acknowledgment is stale; reconcile before another action");
|
|
112
180
|
state.acknowledgment.state =
|
|
113
181
|
action.action === "edit-jev"
|
|
@@ -122,9 +190,19 @@ export function createDashboardConnection(request) {
|
|
|
122
190
|
return true;
|
|
123
191
|
}
|
|
124
192
|
catch (error) {
|
|
193
|
+
if (action.action === "answer-choice" && error instanceof ChoiceDeclined) {
|
|
194
|
+
if (error.stale)
|
|
195
|
+
state.snapshot = undefined;
|
|
196
|
+
state.acknowledgment.state = "refused";
|
|
197
|
+
state.error = error.message;
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
125
200
|
state.snapshot = undefined;
|
|
126
201
|
state.acknowledgment.state = "unconfirmed";
|
|
127
|
-
state.error =
|
|
202
|
+
state.error =
|
|
203
|
+
action.action === "answer-choice"
|
|
204
|
+
? "Save unconfirmed. Check project memory before retrying."
|
|
205
|
+
: `Control change not confirmed; inspect owner before retrying: ${error instanceof Error ? error.message : String(error)}`;
|
|
128
206
|
return false;
|
|
129
207
|
}
|
|
130
208
|
finally {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dashboard-session-client.js","sourceRoot":"","sources":["../../src/products/dashboard-session-client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dashboard-session-client.js","sourceRoot":"","sources":["../../src/products/dashboard-session-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,GAIlB,MAAM,+BAA+B,CAAC;AAIvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAmB5C,MAAM,cAAe,SAAQ,KAAK;IACvB,KAAK,CAAU;IACxB,YAAY,KAAc;QACxB,KAAK,CACH,KAAK;YACH,CAAC,CAAC,uDAAuD;YACzD,CAAC,CAAC,sEAAsE,CAC3E,CAAC;QACF,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAWD,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,UAAkB,EAClB,KAAa,EACb,OAA+B;IAE/B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,MAAM,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;QAC5C,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,MAAM,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type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import type { DashboardSourceSnapshot } from "../src/kernel/dashboard-observation.ts";
|
|
4
|
+
import {
|
|
5
|
+
DASHBOARD_CHOICE_EVENT,
|
|
6
|
+
validChoiceAnswer,
|
|
7
|
+
validChoiceDetail,
|
|
8
|
+
validChoiceId,
|
|
9
|
+
validChoiceRevision,
|
|
10
|
+
type DashboardChoiceRegistration,
|
|
11
|
+
type DashboardChoiceDetail,
|
|
12
|
+
type DashboardChoiceOutcome,
|
|
13
|
+
} from "../src/kernel/dashboard-choice.ts";
|
|
14
|
+
|
|
15
|
+
type Source = { sessionId: string; cwd: string; source: DashboardSourceSnapshot };
|
|
16
|
+
type Binding = {
|
|
17
|
+
source: DashboardSourceSnapshot;
|
|
18
|
+
provider: DashboardChoiceRegistration;
|
|
19
|
+
lastRenewal: number;
|
|
20
|
+
renewing: boolean;
|
|
21
|
+
};
|
|
22
|
+
export function registerDashboardChoiceOwner(pi: ExtensionAPI, lookup: () => Source | undefined, now: () => number) {
|
|
23
|
+
let binding: Binding | undefined;
|
|
24
|
+
const installed = new WeakSet<DashboardSourceSnapshot>();
|
|
25
|
+
const off = pi.events?.on?.(DASHBOARD_CHOICE_EVENT, (input: unknown) => {
|
|
26
|
+
const r = input as DashboardChoiceRegistration | undefined;
|
|
27
|
+
if (r?.version !== 1 || typeof r.reply !== "function") return;
|
|
28
|
+
const current = lookup();
|
|
29
|
+
if (
|
|
30
|
+
!current ||
|
|
31
|
+
current.source.availability !== "observed" ||
|
|
32
|
+
r.sessionId !== current.sessionId ||
|
|
33
|
+
r.cwd !== current.cwd ||
|
|
34
|
+
r.sourceGeneration !== current.source.generation ||
|
|
35
|
+
installed.has(current.source) ||
|
|
36
|
+
typeof r.inspect !== "function" ||
|
|
37
|
+
typeof r.answer !== "function"
|
|
38
|
+
) {
|
|
39
|
+
r.reply({ version: 1, ok: false });
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
installed.add(current.source);
|
|
43
|
+
const entry: Binding = { source: current.source, provider: r, lastRenewal: -Infinity, renewing: false };
|
|
44
|
+
binding = entry;
|
|
45
|
+
r.reply({
|
|
46
|
+
version: 1,
|
|
47
|
+
ok: true,
|
|
48
|
+
close() {
|
|
49
|
+
if (binding === entry) binding = undefined;
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
const current = () => {
|
|
54
|
+
const source = lookup()?.source;
|
|
55
|
+
return source && source === binding?.source && source.availability === "observed" ? binding : undefined;
|
|
56
|
+
};
|
|
57
|
+
const active = () => {
|
|
58
|
+
const entry = current();
|
|
59
|
+
if (!entry) return;
|
|
60
|
+
const age = now() - Date.parse(entry.source.observedAt);
|
|
61
|
+
return Number.isFinite(age) && age >= 0 && age <= entry.source.staleAfterMs ? entry : undefined;
|
|
62
|
+
};
|
|
63
|
+
const row = (entry: Binding, id: unknown) =>
|
|
64
|
+
entry.source.items.find((item) => item.id === id && item.kind === "work" && item.state === "observed");
|
|
65
|
+
const ready = (sourceGeneration: unknown, choiceId: unknown) => {
|
|
66
|
+
const entry = active();
|
|
67
|
+
if (entry && entry.source.generation === sourceGeneration && validChoiceId(choiceId) && row(entry, choiceId))
|
|
68
|
+
return entry;
|
|
69
|
+
return undefined;
|
|
70
|
+
};
|
|
71
|
+
const fence = (entry: Binding, id: string, label: string, checkClient: () => void) => () => {
|
|
72
|
+
checkClient();
|
|
73
|
+
if (active() !== entry || row(entry, id)?.label !== label) throw Error("Choice is no longer current");
|
|
74
|
+
};
|
|
75
|
+
let saving: Binding | undefined;
|
|
76
|
+
return {
|
|
77
|
+
requestRenewal() {
|
|
78
|
+
const entry = current();
|
|
79
|
+
if (!entry?.provider.renew || !entry.source.items.some((item) => validChoiceId(item.id) && row(entry, item.id)))
|
|
80
|
+
return false;
|
|
81
|
+
const time = now(),
|
|
82
|
+
age = time - Date.parse(entry.source.observedAt);
|
|
83
|
+
if (!Number.isFinite(age) || age < entry.source.staleAfterMs - 15_000) return false;
|
|
84
|
+
if (entry.renewing || time - entry.lastRenewal < 30_000) return true;
|
|
85
|
+
// Demand is explicit. The old publication keeps its original age until Bookie actually republishes.
|
|
86
|
+
entry.lastRenewal = time;
|
|
87
|
+
entry.renewing = true;
|
|
88
|
+
void Promise.resolve()
|
|
89
|
+
.then(() => {
|
|
90
|
+
if (current() === entry) return entry.provider.renew?.();
|
|
91
|
+
})
|
|
92
|
+
.catch(() => undefined)
|
|
93
|
+
.finally(() => {
|
|
94
|
+
entry.renewing = false;
|
|
95
|
+
});
|
|
96
|
+
return true;
|
|
97
|
+
},
|
|
98
|
+
controls() {
|
|
99
|
+
const entry = active();
|
|
100
|
+
return entry ? { sourceGeneration: entry.source.generation } : undefined;
|
|
101
|
+
},
|
|
102
|
+
currentDetail(sourceGeneration: unknown, detail: DashboardChoiceDetail) {
|
|
103
|
+
const entry = ready(sourceGeneration, detail.id);
|
|
104
|
+
return !!entry && row(entry, detail.id)?.label === detail.label;
|
|
105
|
+
},
|
|
106
|
+
async inspect(
|
|
107
|
+
sourceGeneration: unknown,
|
|
108
|
+
id: unknown,
|
|
109
|
+
checkClient: () => void,
|
|
110
|
+
): Promise<DashboardChoiceDetail | undefined> {
|
|
111
|
+
const entry = ready(sourceGeneration, id);
|
|
112
|
+
if (!entry || typeof id !== "string") return;
|
|
113
|
+
const label = row(entry, id)!.label;
|
|
114
|
+
const assertCurrent = fence(entry, id, label, checkClient);
|
|
115
|
+
try {
|
|
116
|
+
assertCurrent();
|
|
117
|
+
const detail = await entry.provider.inspect(id, assertCurrent);
|
|
118
|
+
assertCurrent();
|
|
119
|
+
if (validChoiceDetail(detail) && detail.id === id && detail.label === label) return structuredClone(detail);
|
|
120
|
+
} catch {
|
|
121
|
+
// Provider errors can carry private project text or paths.
|
|
122
|
+
}
|
|
123
|
+
return undefined;
|
|
124
|
+
},
|
|
125
|
+
async answer(
|
|
126
|
+
sourceGeneration: unknown,
|
|
127
|
+
id: unknown,
|
|
128
|
+
revision: unknown,
|
|
129
|
+
answer: unknown,
|
|
130
|
+
checkClient: () => void,
|
|
131
|
+
): Promise<DashboardChoiceOutcome> {
|
|
132
|
+
const entry = ready(sourceGeneration, id);
|
|
133
|
+
if (!entry || typeof id !== "string" || !validChoiceRevision(revision) || !validChoiceAnswer(answer) || saving)
|
|
134
|
+
return "refused";
|
|
135
|
+
const assertCurrent = fence(entry, id, row(entry, id)!.label, checkClient);
|
|
136
|
+
saving = entry;
|
|
137
|
+
try {
|
|
138
|
+
assertCurrent();
|
|
139
|
+
const result = await entry.provider.answer(id, revision, answer, assertCurrent);
|
|
140
|
+
return result === "saved" || result === "refused" ? result : "unconfirmed";
|
|
141
|
+
} catch {
|
|
142
|
+
return "unconfirmed";
|
|
143
|
+
} finally {
|
|
144
|
+
saving = undefined;
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
close() {
|
|
148
|
+
binding = undefined;
|
|
149
|
+
off?.();
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DashboardChoiceDetail } from "../src/kernel/dashboard-choice.ts";
|
|
1
2
|
import { isJevEditAction } from "../src/products/dashboard-settings.ts";
|
|
2
3
|
import { dashboardObservation } from "./dashboard-observation.ts";
|
|
3
4
|
import { dashboardSettingsSnapshot, dashboardJev, setDashboardLimit } from "./dashboard-settings.ts";
|
|
@@ -54,9 +55,25 @@ async function start(session: GrantsSession): Promise<DashboardSessionEndpoint>
|
|
|
54
55
|
if (!input.includes("\n")) return;
|
|
55
56
|
handled = true;
|
|
56
57
|
const line = input.slice(0, input.indexOf("\n"));
|
|
57
|
-
|
|
58
|
+
let request: DashboardWireRequest;
|
|
59
|
+
try {
|
|
60
|
+
request = JSON.parse(line);
|
|
61
|
+
if (!request || typeof request !== "object" || Array.isArray(request)) throw Error();
|
|
62
|
+
} catch {
|
|
63
|
+
socket.end(JSON.stringify({ ok: false, error: "Invalid dashboard request" }) + "\n");
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const choiceAction = request.action === "inspect-choice" || request.action === "answer-choice";
|
|
67
|
+
if (choiceAction && request.token === token) socket.setTimeout(30_000);
|
|
68
|
+
void respond(session, token, request, () => {
|
|
69
|
+
if (socket.destroyed) throw Error("Dashboard disconnected");
|
|
70
|
+
})
|
|
58
71
|
.then((value) => socket.end(`${JSON.stringify(value)}\n`))
|
|
59
|
-
.catch((error) =>
|
|
72
|
+
.catch((error) =>
|
|
73
|
+
socket.end(
|
|
74
|
+
`${JSON.stringify({ ok: false, error: choiceAction ? "Bookie could not confirm the choice request." : String(error) })}\n`,
|
|
75
|
+
),
|
|
76
|
+
);
|
|
60
77
|
});
|
|
61
78
|
});
|
|
62
79
|
await new Promise<void>((resolve, reject) => {
|
|
@@ -80,19 +97,40 @@ async function start(session: GrantsSession): Promise<DashboardSessionEndpoint>
|
|
|
80
97
|
};
|
|
81
98
|
}
|
|
82
99
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
100
|
+
interface DashboardWireRequest {
|
|
101
|
+
token?: unknown;
|
|
102
|
+
action?: unknown;
|
|
103
|
+
edits?: unknown;
|
|
104
|
+
enabled?: unknown;
|
|
105
|
+
key?: unknown;
|
|
106
|
+
refreshChoices?: unknown;
|
|
107
|
+
seconds?: unknown;
|
|
108
|
+
option?: unknown;
|
|
109
|
+
sourceGeneration?: unknown;
|
|
110
|
+
choiceId?: unknown;
|
|
111
|
+
revision?: unknown;
|
|
112
|
+
answer?: unknown;
|
|
113
|
+
expectedOwner?: { sessionId?: unknown; cwd?: unknown; generation?: unknown };
|
|
114
|
+
}
|
|
115
|
+
async function respond(
|
|
116
|
+
session: GrantsSession,
|
|
117
|
+
token: string,
|
|
118
|
+
request: DashboardWireRequest,
|
|
119
|
+
checkClient: () => void,
|
|
120
|
+
): Promise<Record<string, unknown>> {
|
|
94
121
|
if (request.token !== token) return { ok: false, error: "unauthorised dashboard request" };
|
|
95
|
-
|
|
122
|
+
const choiceAction = request.action === "inspect-choice" || request.action === "answer-choice";
|
|
123
|
+
if (choiceAction) {
|
|
124
|
+
const allowed = ["token", "action", "expectedOwner", "sourceGeneration", "choiceId"];
|
|
125
|
+
if (request.action === "answer-choice") allowed.push("revision", "answer");
|
|
126
|
+
if (Object.keys(request).some((key) => !allowed.includes(key)))
|
|
127
|
+
return { ok: false, choiceOutcome: "refused", error: "Invalid choice request" };
|
|
128
|
+
}
|
|
129
|
+
if (
|
|
130
|
+
choiceAction ||
|
|
131
|
+
request.action === "edit-jev" ||
|
|
132
|
+
(request.action !== "get" && request.expectedOwner !== undefined)
|
|
133
|
+
) {
|
|
96
134
|
const observed = session.dashboardObservations?.(),
|
|
97
135
|
expected = request.expectedOwner;
|
|
98
136
|
if (
|
|
@@ -102,13 +140,41 @@ async function respond(session: GrantsSession, token: string, line: string): Pro
|
|
|
102
140
|
expected.cwd !== observed.cwd ||
|
|
103
141
|
expected.generation !== observed.generation
|
|
104
142
|
)
|
|
105
|
-
return {
|
|
143
|
+
return {
|
|
144
|
+
ok: false,
|
|
145
|
+
...(choiceAction ? { choiceOutcome: "stale" } : {}),
|
|
146
|
+
error: "Dashboard owner changed before action; refresh and inspect the new session",
|
|
147
|
+
};
|
|
106
148
|
}
|
|
107
149
|
const lifecycle = session.reloadLifecycle,
|
|
108
150
|
owner = lifecycle.autoMode;
|
|
109
151
|
const displayOwner = session.dashboardObservations?.()?.generation;
|
|
110
|
-
let jev;
|
|
111
|
-
if (request.action === "
|
|
152
|
+
let jev, choiceDetail: DashboardChoiceDetail | undefined;
|
|
153
|
+
if (request.action === "inspect-choice") {
|
|
154
|
+
choiceDetail = await session.dashboardChoices?.inspect(request.sourceGeneration, request.choiceId, checkClient);
|
|
155
|
+
if (!choiceDetail)
|
|
156
|
+
return { ok: false, choiceOutcome: "stale", error: "Choice is no longer available. Refresh and reopen it." };
|
|
157
|
+
} else if (request.action === "answer-choice") {
|
|
158
|
+
const outcome = await session.dashboardChoices?.answer(
|
|
159
|
+
request.sourceGeneration,
|
|
160
|
+
request.choiceId,
|
|
161
|
+
request.revision,
|
|
162
|
+
request.answer,
|
|
163
|
+
checkClient,
|
|
164
|
+
);
|
|
165
|
+
if (outcome !== "saved")
|
|
166
|
+
return outcome === "unconfirmed"
|
|
167
|
+
? {
|
|
168
|
+
ok: false,
|
|
169
|
+
choiceOutcome: "unconfirmed",
|
|
170
|
+
error: "Bookie could not confirm the save. Check project memory before retrying.",
|
|
171
|
+
}
|
|
172
|
+
: {
|
|
173
|
+
ok: false,
|
|
174
|
+
choiceOutcome: "refused",
|
|
175
|
+
error: "Bookie declined the answer. Refresh and check the choice and answer.",
|
|
176
|
+
};
|
|
177
|
+
} else if (request.action === "set-limit") {
|
|
112
178
|
setDashboardLimit(session, request.key, request.seconds);
|
|
113
179
|
} else if (request.action === "edit-jev") {
|
|
114
180
|
if (!isJevEditAction(request.option)) return { ok: false, error: "Unknown JEV setting" };
|
|
@@ -138,8 +204,17 @@ async function respond(session: GrantsSession, token: string, line: string): Pro
|
|
|
138
204
|
session.dashboardObservations?.()?.generation !== displayOwner
|
|
139
205
|
)
|
|
140
206
|
throw Error("Dashboard owner changed; action outcome requires reconciliation");
|
|
207
|
+
if (choiceDetail && !session.dashboardChoices?.currentDetail(request.sourceGeneration, choiceDetail))
|
|
208
|
+
return { ok: false, choiceOutcome: "stale", error: "Choice is no longer available. Refresh and reopen it." };
|
|
209
|
+
const choiceRefreshRequested =
|
|
210
|
+
request.action === "get" && request.refreshChoices === true && session.dashboardChoices?.requestRenewal();
|
|
211
|
+
const choiceControls = session.dashboardChoices?.controls();
|
|
141
212
|
return {
|
|
142
213
|
ok: true,
|
|
214
|
+
...(choiceControls ? { choiceControls } : {}),
|
|
215
|
+
...(choiceRefreshRequested ? { choiceRefreshRequested: true } : {}),
|
|
216
|
+
...(choiceDetail ? { choiceDetail } : {}),
|
|
217
|
+
...(request.action === "answer-choice" ? { choiceSaved: true } : {}),
|
|
143
218
|
...controls,
|
|
144
219
|
...dashboardObservation(session),
|
|
145
220
|
...(session.activity ? { activity: { ...session.activity } } : {}),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** Optional trusted producers publish display observations; no automatic work, tools, or persistent store. */
|
|
2
|
+
import { registerDashboardChoiceOwner } from "./dashboard-choice-controls.ts";
|
|
2
3
|
import { randomUUID } from "node:crypto";
|
|
3
4
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
4
5
|
import {
|
|
@@ -34,6 +35,15 @@ export function registerDashboardSources(
|
|
|
34
35
|
}
|
|
35
36
|
return selected;
|
|
36
37
|
};
|
|
38
|
+
const choices = registerDashboardChoiceOwner(
|
|
39
|
+
pi,
|
|
40
|
+
() => {
|
|
41
|
+
const selected = reconcile();
|
|
42
|
+
const source = sources.get("bookie-memory");
|
|
43
|
+
return selected && source ? { sessionId: selected.sessionId, cwd: selected.cwd, source } : undefined;
|
|
44
|
+
},
|
|
45
|
+
now,
|
|
46
|
+
);
|
|
37
47
|
const off = pi.events?.on?.(DASHBOARD_SOURCE_EVENT, (input: unknown) => {
|
|
38
48
|
const r = input as {
|
|
39
49
|
version?: unknown;
|
|
@@ -102,6 +112,7 @@ export function registerDashboardSources(
|
|
|
102
112
|
});
|
|
103
113
|
});
|
|
104
114
|
return {
|
|
115
|
+
choices,
|
|
105
116
|
snapshot() {
|
|
106
117
|
const selected = reconcile();
|
|
107
118
|
return selected
|
|
@@ -117,6 +128,7 @@ export function registerDashboardSources(
|
|
|
117
128
|
},
|
|
118
129
|
close() {
|
|
119
130
|
closed = true;
|
|
131
|
+
choices.close();
|
|
120
132
|
off?.();
|
|
121
133
|
sources.clear();
|
|
122
134
|
owner = undefined;
|
|
@@ -35,6 +35,7 @@ export function registerRuntimeSnapshot(
|
|
|
35
35
|
: undefined,
|
|
36
36
|
);
|
|
37
37
|
session.dashboardObservations = () => dashboardSources.snapshot();
|
|
38
|
+
session.dashboardChoices = dashboardSources.choices;
|
|
38
39
|
session.dashboardLive = registerDashboardLive(pi, () =>
|
|
39
40
|
bound?.lifecycle === session.reloadLifecycle && session.reloadLifecycle.runtimeSnapshotGeneration === generation
|
|
40
41
|
? bound
|
package/extensions/session.ts
CHANGED
|
@@ -153,6 +153,7 @@ export interface GrantsSession extends NativeSessionHost {
|
|
|
153
153
|
ecosystemVersions?: () => EcosystemVersions;
|
|
154
154
|
dashboardLive?: () => { turn?: DashboardContribution; activity: DashboardContribution[] };
|
|
155
155
|
dashboardArtifacts?: DashboardSavedEvidence[];
|
|
156
|
+
dashboardChoices?: ReturnType<typeof import("./dashboard-choice-controls.ts").registerDashboardChoiceOwner>;
|
|
156
157
|
dashboardObservations?: () => Omit<DashboardOwnerObservation, "version" | "resources" | "capture"> | undefined;
|
|
157
158
|
autoMode?: AutoModeReader;
|
|
158
159
|
autoModeFailure?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-daddy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.56.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",
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/** Private owner controls, available only on the authenticated dashboard connection. */
|
|
2
|
+
export const DASHBOARD_CHOICE_EVENT = "pi-daddy:bookie-choice-controls:v1";
|
|
3
|
+
export interface DashboardChoiceDetail {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
title: string;
|
|
7
|
+
revision: string;
|
|
8
|
+
options: string[];
|
|
9
|
+
recommendation?: { option: string; reason: string; evidence: string };
|
|
10
|
+
}
|
|
11
|
+
export type DashboardChoiceAnswer = { option: string } | { custom: string };
|
|
12
|
+
export interface DashboardChoiceTarget {
|
|
13
|
+
choiceId: string;
|
|
14
|
+
sourceGeneration: string;
|
|
15
|
+
expectedOwner: { sessionId: string; cwd: string; generation: string };
|
|
16
|
+
}
|
|
17
|
+
export type DashboardChoiceAction = DashboardChoiceTarget &
|
|
18
|
+
({ action: "inspect-choice" } | { action: "answer-choice"; revision: string; answer: DashboardChoiceAnswer });
|
|
19
|
+
export type DashboardChoiceOutcome = "saved" | "refused" | "unconfirmed";
|
|
20
|
+
export interface DashboardChoiceRegistration {
|
|
21
|
+
version: 1;
|
|
22
|
+
sessionId: string;
|
|
23
|
+
cwd: string;
|
|
24
|
+
sourceGeneration: string;
|
|
25
|
+
renew?(): Promise<void>;
|
|
26
|
+
inspect(id: string, assertCurrent: () => void): Promise<DashboardChoiceDetail | undefined>;
|
|
27
|
+
answer(
|
|
28
|
+
id: string,
|
|
29
|
+
revision: string,
|
|
30
|
+
answer: DashboardChoiceAnswer,
|
|
31
|
+
assertCurrent: () => void,
|
|
32
|
+
): Promise<DashboardChoiceOutcome>;
|
|
33
|
+
reply(value: { version: 1; ok: false } | { version: 1; ok: true; close(): void }): void;
|
|
34
|
+
}
|
|
35
|
+
const record = (x: unknown): x is Record<string, unknown> => typeof x === "object" && x !== null && !Array.isArray(x);
|
|
36
|
+
const text = (v: unknown, length: number): v is string =>
|
|
37
|
+
typeof v === "string" &&
|
|
38
|
+
v.trim() === v &&
|
|
39
|
+
v.length > 0 &&
|
|
40
|
+
v.length <= length &&
|
|
41
|
+
!/[\p{Cc}\p{Cf}\p{Cs}\p{Zl}\p{Zp}]/u.test(v);
|
|
42
|
+
const keys = (v: object, allowed: string[]) => Object.keys(v).every((k) => allowed.includes(k));
|
|
43
|
+
export const validChoiceId = (v: unknown): v is string =>
|
|
44
|
+
typeof v === "string" && /^open-choice-[a-zA-Z0-9_-]{1,128}$/.test(v);
|
|
45
|
+
export const validChoiceRevision = (v: unknown): v is string =>
|
|
46
|
+
typeof v === "string" && /^sha256:[a-f0-9]{64}$/.test(v);
|
|
47
|
+
export const validChoiceAnswer = (v: unknown): v is DashboardChoiceAnswer =>
|
|
48
|
+
record(v) && ((keys(v, ["option"]) && text(v.option, 120)) || (keys(v, ["custom"]) && text(v.custom, 240)));
|
|
49
|
+
export function validChoiceDetail(v: unknown): v is DashboardChoiceDetail {
|
|
50
|
+
if (
|
|
51
|
+
!record(v) ||
|
|
52
|
+
!keys(v, ["id", "label", "title", "revision", "options", "recommendation"]) ||
|
|
53
|
+
!validChoiceId(v.id) ||
|
|
54
|
+
!text(v.label, 240) ||
|
|
55
|
+
!text(v.title, 120) ||
|
|
56
|
+
!validChoiceRevision(v.revision) ||
|
|
57
|
+
!Array.isArray(v.options) ||
|
|
58
|
+
v.options.length > 8 ||
|
|
59
|
+
!v.options.every((option) => text(option, 120)) ||
|
|
60
|
+
new Set(v.options).size !== v.options.length
|
|
61
|
+
)
|
|
62
|
+
return false;
|
|
63
|
+
const rec = v.recommendation;
|
|
64
|
+
return (
|
|
65
|
+
rec === undefined ||
|
|
66
|
+
(record(rec) &&
|
|
67
|
+
keys(rec, ["option", "reason", "evidence"]) &&
|
|
68
|
+
text(rec.option, 120) &&
|
|
69
|
+
v.options.includes(rec.option) &&
|
|
70
|
+
text(rec.reason, 240) &&
|
|
71
|
+
text(rec.evidence, 240))
|
|
72
|
+
);
|
|
73
|
+
}
|