pi-daddy 0.61.0 → 0.62.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.
- package/CHANGELOG.md +9 -0
- package/README.md +62 -3
- package/dist/kernel/context-handoff.d.ts +14 -0
- package/dist/kernel/context-handoff.d.ts.map +1 -1
- package/dist/kernel/context-handoff.js +17 -0
- package/dist/kernel/context-handoff.js.map +1 -1
- package/dist/kernel/delegate-types.d.ts +3 -0
- package/dist/kernel/delegate-types.d.ts.map +1 -1
- package/dist/kernel/delegate-types.js.map +1 -1
- package/dist/kernel/delegate.d.ts.map +1 -1
- package/dist/kernel/delegate.js +30 -8
- package/dist/kernel/delegate.js.map +1 -1
- package/dist/kernel/env-names.d.ts +2 -0
- package/dist/kernel/env-names.d.ts.map +1 -1
- package/dist/kernel/env-names.js +3 -0
- package/dist/kernel/env-names.js.map +1 -1
- package/dist/kernel/propagation.d.ts +1 -1
- package/dist/kernel/propagation.d.ts.map +1 -1
- package/dist/kernel/propagation.js +2 -0
- package/dist/kernel/propagation.js.map +1 -1
- package/dist/kernel/spawn.d.ts +3 -0
- package/dist/kernel/spawn.d.ts.map +1 -1
- package/dist/kernel/spawn.js +4 -0
- package/dist/kernel/spawn.js.map +1 -1
- package/dist/kernel/work-mode.d.ts +24 -0
- package/dist/kernel/work-mode.d.ts.map +1 -0
- package/dist/kernel/work-mode.js +73 -0
- package/dist/kernel/work-mode.js.map +1 -0
- package/dist/products/dashboard-cli.d.ts.map +1 -1
- package/dist/products/dashboard-cli.js +36 -0
- package/dist/products/dashboard-cli.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 +25 -0
- package/dist/products/dashboard-display-controls.js.map +1 -1
- package/dist/products/dashboard-screen.d.ts +3 -1
- package/dist/products/dashboard-screen.d.ts.map +1 -1
- package/dist/products/dashboard-screen.js +23 -13
- package/dist/products/dashboard-screen.js.map +1 -1
- package/dist/products/dashboard-session-client.d.ts +6 -0
- package/dist/products/dashboard-session-client.d.ts.map +1 -1
- package/dist/products/dashboard-session-client.js +21 -4
- package/dist/products/dashboard-session-client.js.map +1 -1
- package/dist/products/dashboard-settings.d.ts +4 -2
- package/dist/products/dashboard-settings.d.ts.map +1 -1
- package/dist/products/dashboard-settings.js +27 -2
- package/dist/products/dashboard-settings.js.map +1 -1
- package/dist/products/dashboard-work-mode.d.ts +27 -0
- package/dist/products/dashboard-work-mode.d.ts.map +1 -0
- package/dist/products/dashboard-work-mode.js +117 -0
- package/dist/products/dashboard-work-mode.js.map +1 -0
- package/extensions/dashboard-session-server.ts +13 -0
- package/extensions/dashboard-settings.ts +2 -0
- package/extensions/definition-describe.ts +3 -1
- package/extensions/delegation-operations.ts +25 -1
- package/extensions/grants.ts +3 -0
- package/extensions/reload-environment.ts +2 -0
- package/extensions/run-delegation.ts +11 -2
- package/extensions/work-mode-command.ts +82 -0
- package/extensions/work-mode.ts +226 -0
- package/package.json +2 -2
- package/src/kernel/context-handoff.ts +19 -0
- package/src/kernel/delegate-types.ts +3 -0
- package/src/kernel/delegate.ts +38 -14
- package/src/kernel/env-names.ts +3 -0
- package/src/kernel/propagation.ts +2 -0
- package/src/kernel/spawn.ts +5 -0
- package/src/kernel/work-mode.ts +85 -0
- package/src/products/dashboard-cli.ts +33 -1
- package/src/products/dashboard-display-controls.ts +22 -1
- package/src/products/dashboard-screen.ts +45 -14
- package/src/products/dashboard-session-client.ts +26 -4
- package/src/products/dashboard-settings.ts +33 -3
- package/src/products/dashboard-work-mode.ts +151 -0
|
@@ -16,6 +16,7 @@ import type { GrantsSession } from "./session.ts";
|
|
|
16
16
|
import { getDashboardControlState, setAutoApproval } from "./session-auto-mode.ts";
|
|
17
17
|
import { saveSessionModelEdits, sessionModelRows } from "./session-model-prompt.ts";
|
|
18
18
|
import { childUsageInSession } from "../src/executors/child-usage.ts";
|
|
19
|
+
import { setWorkMode } from "./work-mode.ts";
|
|
19
20
|
|
|
20
21
|
export interface DashboardSessionEndpoint {
|
|
21
22
|
socketPath: string;
|
|
@@ -117,6 +118,8 @@ interface DashboardWireRequest {
|
|
|
117
118
|
choiceId?: unknown;
|
|
118
119
|
revision?: unknown;
|
|
119
120
|
answer?: unknown;
|
|
121
|
+
selection?: unknown;
|
|
122
|
+
scope?: unknown;
|
|
120
123
|
expectedOwner?: { sessionId?: unknown; cwd?: unknown; generation?: unknown };
|
|
121
124
|
}
|
|
122
125
|
async function respond(
|
|
@@ -127,6 +130,11 @@ async function respond(
|
|
|
127
130
|
): Promise<Record<string, unknown>> {
|
|
128
131
|
if (request.token !== token) return { ok: false, error: "unauthorised dashboard request" };
|
|
129
132
|
const choiceAction = request.action === "inspect-choice" || request.action === "answer-choice";
|
|
133
|
+
if (request.action === "set-work-mode") {
|
|
134
|
+
const allowed = ["token", "action", "expectedOwner", "selection", "scope"];
|
|
135
|
+
if (Object.keys(request).some((key) => !allowed.includes(key)))
|
|
136
|
+
return { ok: false, error: "Invalid work mode request" };
|
|
137
|
+
}
|
|
130
138
|
if (choiceAction) {
|
|
131
139
|
const allowed = ["token", "action", "expectedOwner", "sourceGeneration", "choiceId"];
|
|
132
140
|
if (request.action === "answer-choice") allowed.push("revision", "answer");
|
|
@@ -137,6 +145,7 @@ async function respond(
|
|
|
137
145
|
choiceAction ||
|
|
138
146
|
request.action === "edit-jev" ||
|
|
139
147
|
request.action === "set-telemetry" ||
|
|
148
|
+
request.action === "set-work-mode" ||
|
|
140
149
|
(request.action !== "get" && request.expectedOwner !== undefined)
|
|
141
150
|
) {
|
|
142
151
|
const observed = session.dashboardObservations?.(),
|
|
@@ -182,6 +191,9 @@ async function respond(
|
|
|
182
191
|
choiceOutcome: "refused",
|
|
183
192
|
error: "Bookie declined the answer. Refresh and check the choice and answer.",
|
|
184
193
|
};
|
|
194
|
+
} else if (request.action === "set-work-mode") {
|
|
195
|
+
checkClient();
|
|
196
|
+
setWorkMode(session, request.selection, request.scope);
|
|
185
197
|
} else if (request.action === "set-limit") {
|
|
186
198
|
setDashboardLimit(session, request.key, request.seconds);
|
|
187
199
|
} else if (request.action === "edit-jev") {
|
|
@@ -229,6 +241,7 @@ async function respond(
|
|
|
229
241
|
...(sourceRefreshRequested ? { sourceRefreshRequested: true } : {}),
|
|
230
242
|
...(choiceDetail ? { choiceDetail } : {}),
|
|
231
243
|
...(request.action === "answer-choice" ? { choiceSaved: true } : {}),
|
|
244
|
+
...(request.action === "set-work-mode" ? { workModeApplied: true } : {}),
|
|
232
245
|
...controls,
|
|
233
246
|
...dashboardObservation(session),
|
|
234
247
|
...(session.activity ? { activity: { ...session.activity } } : {}),
|
|
@@ -6,6 +6,7 @@ import type { DashboardJevState, DashboardSettingsSnapshot } from "../src/produc
|
|
|
6
6
|
import { telemetrySnapshot, setTelemetryEnabled, closeTelemetry } from "./dashboard-telemetry.ts";
|
|
7
7
|
import { isJevEditAction, type JevEditAction } from "../src/products/dashboard-settings.ts";
|
|
8
8
|
import { MAX_CHILDREN_PER_CALL } from "../src/kernel/fanout.ts";
|
|
9
|
+
import { workModeSnapshot } from "./work-mode.ts";
|
|
9
10
|
import {
|
|
10
11
|
ENV_CHILD_TIMEOUT,
|
|
11
12
|
ENV_CHILD_IDLE_TIMEOUT,
|
|
@@ -178,6 +179,7 @@ export async function dashboardSettingsSnapshot(
|
|
|
178
179
|
perCall: MAX_CHILDREN_PER_CALL,
|
|
179
180
|
jev: jev ?? (await dashboardJev(session, "status")),
|
|
180
181
|
telemetry: telemetrySnapshot(session),
|
|
182
|
+
workMode: workModeSnapshot(session),
|
|
181
183
|
};
|
|
182
184
|
}
|
|
183
185
|
export async function setDashboardTelemetry(session: GrantsSession, enabled: boolean): Promise<void> {
|
|
@@ -3,6 +3,7 @@ import { publicEvidenceCall } from "./public-evidence.ts";
|
|
|
3
3
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
4
4
|
import { Type } from "typebox";
|
|
5
5
|
import { ceilingForDefinition, digestDefinition } from "../src/kernel/definitions.ts";
|
|
6
|
+
import { definitionContextContract } from "../src/kernel/context-handoff.ts";
|
|
6
7
|
import { maySpawnDefinition } from "../src/kernel/delegate.ts";
|
|
7
8
|
import { replaySafeCeiling } from "../src/kernel/replay-safe.ts";
|
|
8
9
|
import { hostModel, liveParentTools } from "./parent-tool-host.ts";
|
|
@@ -111,7 +112,7 @@ export function registerDefinitionDescribe(pi: ExtensionAPI, session: GrantsSess
|
|
|
111
112
|
name: "delegate_describe",
|
|
112
113
|
label: "Describe a governed definition",
|
|
113
114
|
description:
|
|
114
|
-
"Read the exact selected definition identity and Principal binding before delegation. " +
|
|
115
|
+
"Read the exact selected definition identity, context ceiling/default and Principal binding before delegation. " +
|
|
115
116
|
"Binds its definitionId to this agent's later delegations in this session. Starts no child and grants nothing.",
|
|
116
117
|
parameters: Type.Object({ agent: Type.String() }),
|
|
117
118
|
async execute(_id, params, _signal, _onUpdate, ctx) {
|
|
@@ -131,6 +132,7 @@ export function registerDefinitionDescribe(pi: ExtensionAPI, session: GrantsSess
|
|
|
131
132
|
binding: definition.binding ?? null,
|
|
132
133
|
definitionId: definition.definitionId,
|
|
133
134
|
delegationArguments: { agent: params.agent, definitionId: definition.definitionId },
|
|
135
|
+
contextContract: definitionContextContract(ceilingForDefinition(definition).capabilities),
|
|
134
136
|
selectedResources: definition.selectedResources ?? null,
|
|
135
137
|
// Declared tools this session would run for the child itself, through its own tool pipeline (2026-11-17),
|
|
136
138
|
// for a child on this session's own provider and model, which is the only kind it runs them for. Like the
|
|
@@ -221,6 +221,8 @@ export async function claimDelegationOperation(
|
|
|
221
221
|
? new GovernanceRefusal(preview.refusal)
|
|
222
222
|
: Error(preview.reason ?? "Operation request is not authorized");
|
|
223
223
|
const evidenceErrors: unknown[] = [];
|
|
224
|
+
let recordedNotStarted = false;
|
|
225
|
+
let existingState: string | undefined;
|
|
224
226
|
try {
|
|
225
227
|
await recordDelegationDecision({ session, plan: preview, ids, agent: spec.agent });
|
|
226
228
|
} catch (error) {
|
|
@@ -233,12 +235,34 @@ export async function claimDelegationOperation(
|
|
|
233
235
|
// Election records identity, not permission. Only this newly elected, unlaunched
|
|
234
236
|
// occurrence may supply no-start proof; a duplicate must never rewrite its owner.
|
|
235
237
|
const claim = await elect();
|
|
236
|
-
if (!claim.reused)
|
|
238
|
+
if (!claim.reused) {
|
|
239
|
+
await claim.finish!("not-started", { cleanup: { state: "not-started" } });
|
|
240
|
+
recordedNotStarted = true;
|
|
241
|
+
} else existingState = claim.operation.state;
|
|
237
242
|
} catch (error) {
|
|
238
243
|
// Keep the typed governance refusal and make missing/conflicting evidence explicit.
|
|
239
244
|
evidenceErrors.push(error);
|
|
240
245
|
failure.message += `; operation evidence unavailable: ${String(error)}`;
|
|
241
246
|
}
|
|
247
|
+
if (preview.refusal?.code === "CONTEXT_REQUEST_INVALID") {
|
|
248
|
+
if (recordedNotStarted) {
|
|
249
|
+
failure.message +=
|
|
250
|
+
` Operation ${JSON.stringify(operationId)} is recorded not-started; its ID remains terminal. ` +
|
|
251
|
+
(spec.agent && session.definitions.get(spec.agent)?.binding
|
|
252
|
+
? "Recover the original operation through its workflow owner, then use the corrected delegation arguments it provides. " +
|
|
253
|
+
"Do not invent a replacement operation ID or repeat completed work."
|
|
254
|
+
: "Correct the context arguments and make one new attempt with a new operation_id, keeping this refused record. " +
|
|
255
|
+
"This is an argument correction, not a retry of executed work; all current permission checks still apply.");
|
|
256
|
+
} else if (existingState !== undefined) {
|
|
257
|
+
failure.message +=
|
|
258
|
+
` Operation ${JSON.stringify(operationId)} already exists (${existingState}). ` +
|
|
259
|
+
"Inspect or recover that original operation before any new attempt; this refusal did not replace its record.";
|
|
260
|
+
} else {
|
|
261
|
+
failure.message +=
|
|
262
|
+
"No reliable operation no-start record was returned. Inspect or recover the original operation before any new attempt; " +
|
|
263
|
+
"this refusal alone does not prove earlier work never started.";
|
|
264
|
+
}
|
|
265
|
+
}
|
|
242
266
|
if (evidenceErrors.length)
|
|
243
267
|
failure.cause =
|
|
244
268
|
evidenceErrors.length === 1
|
package/extensions/grants.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { registerProjectMemoryOwner } from "./project-memory-owner.ts";
|
|
2
|
+
import { registerWorkMode } from "./work-mode.ts";
|
|
2
3
|
import { registerDashboardSettings, childExecutionLimits, closeDashboardTelemetry } from "./dashboard-settings.ts";
|
|
3
4
|
import { bindEcosystemVersions } from "./ecosystem-versions.ts";
|
|
4
5
|
import {
|
|
@@ -102,6 +103,7 @@ export default function (pi: ExtensionAPI, trustedSession?: GrantsSession) {
|
|
|
102
103
|
registerChildUsageReport(pi, session);
|
|
103
104
|
const runtimeSnapshot = registerRuntimeSnapshot(pi, session);
|
|
104
105
|
registerDashboardSettings(pi, session);
|
|
106
|
+
const beginWorkMode = registerWorkMode(pi, session);
|
|
105
107
|
const projectMemory = registerProjectMemoryOwner(pi, session);
|
|
106
108
|
const dashboardPluginRoot = fileURLToPath(new URL("../herdr-plugin/", import.meta.url));
|
|
107
109
|
const dashboardPaths = defaultDashboardPaths(agentDir());
|
|
@@ -164,6 +166,7 @@ export default function (pi: ExtensionAPI, trustedSession?: GrantsSession) {
|
|
|
164
166
|
try {
|
|
165
167
|
const nativeId = (owner as { getSessionId?: () => string }).getSessionId?.() ?? session.episodeId;
|
|
166
168
|
await initializeSessionAutoMode(session, reload.environment, nativeId);
|
|
169
|
+
beginWorkMode(ctx, event?.reason ?? "startup", reload.environment);
|
|
167
170
|
} catch (error) {
|
|
168
171
|
session.autoModeFailure = `Daddy Auto mode unavailable: ${String(error)}`;
|
|
169
172
|
throw error;
|
|
@@ -6,6 +6,7 @@ import type { BoundedReadCleanupError } from "../src/kernel/bounded-read.ts";
|
|
|
6
6
|
|
|
7
7
|
/** The root baseline and latest child publication for one real Pi session owner. */
|
|
8
8
|
export interface ReloadLifecycle {
|
|
9
|
+
workMode?: import("./work-mode.ts").WorkModeLifecycle;
|
|
9
10
|
operationFinals?: import("./delegation-operations.ts").OperationFinalStore;
|
|
10
11
|
executionSettings?: { nativeSessionId: string; wallMs?: number; idleMs?: number };
|
|
11
12
|
autoMode?: import("./session-auto-mode.ts").SessionAutoLifecycle;
|
|
@@ -167,6 +168,7 @@ export function bindReloadLifecycle(
|
|
|
167
168
|
root: current,
|
|
168
169
|
autoMode: existing.autoMode,
|
|
169
170
|
executionSettings: existing.executionSettings,
|
|
171
|
+
workMode: existing.workMode,
|
|
170
172
|
activityRootId: existing.activityRootId,
|
|
171
173
|
episodeId: existing.episodeId,
|
|
172
174
|
capacity: existing.capacity,
|
|
@@ -9,6 +9,8 @@ import { reconcileDelegationCapacity, reserveDelegationCapacity } from "./sessio
|
|
|
9
9
|
import type { CapacityReservation } from "../src/kernel/capacity.ts";
|
|
10
10
|
import { assertDefinitionIdentity } from "./definition-describe.ts";
|
|
11
11
|
import { replayIfSafe, type AttemptObservation } from "./replay-retry.ts";
|
|
12
|
+
import { capturedWorkMode } from "./work-mode.ts";
|
|
13
|
+
import type { WorkModeSelection } from "../src/kernel/work-mode.ts";
|
|
12
14
|
/**
|
|
13
15
|
* Plan, gate, audit and run ONE governed child — the whole of a delegation except its tool surface.
|
|
14
16
|
*
|
|
@@ -276,6 +278,8 @@ async function runOneDelegationImplementation(
|
|
|
276
278
|
* mistake unspellable.
|
|
277
279
|
*/
|
|
278
280
|
options: {
|
|
281
|
+
/** Captured before the first await and reused unchanged by an automatic retry. */
|
|
282
|
+
workMode?: WorkModeSelection;
|
|
279
283
|
operationClaim?: OperationClaim;
|
|
280
284
|
/** Trusted observation at the actual executor boundary, not a caller/tool parameter. */
|
|
281
285
|
onExecutorEntry?: () => void;
|
|
@@ -423,7 +427,11 @@ async function runOneDelegationImplementation(
|
|
|
423
427
|
executorRefusal ||= nativeRefusal;
|
|
424
428
|
|
|
425
429
|
// Parent-run tools are decided by THIS delegation's live tool context: it is what will run them.
|
|
426
|
-
const planContext = {
|
|
430
|
+
const planContext = {
|
|
431
|
+
...extra,
|
|
432
|
+
...session.parentToolContext?.(ctx),
|
|
433
|
+
...(options.workMode ? { workMode: options.workMode } : {}),
|
|
434
|
+
};
|
|
427
435
|
let preparedWorkspace: PreparedWorkspace | undefined;
|
|
428
436
|
let approvalOutcome: ApprovalOutcome | undefined;
|
|
429
437
|
let plan: ReturnType<typeof planDelegation>;
|
|
@@ -587,8 +595,9 @@ export async function runOneDelegation(
|
|
|
587
595
|
...args: Parameters<typeof runOneDelegationImplementation>
|
|
588
596
|
): Promise<DelegationOutcome> {
|
|
589
597
|
const [session, spec, ids, budget, ctx, signal] = args;
|
|
598
|
+
const workMode = capturedWorkMode(session);
|
|
590
599
|
const finalScope = operationFinalScope(session);
|
|
591
|
-
const options = args[6]
|
|
600
|
+
const options = { ...args[6], ...(workMode ? { workMode } : {}) };
|
|
592
601
|
const binding = options.definitionBinding;
|
|
593
602
|
const bindOutcome = (outcome: DelegationOutcome) =>
|
|
594
603
|
binding ? Object.assign(outcome, { definitionBinding: { ...binding } }) : outcome;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/** Human command access without a dashboard. This command is not exposed as a model tool. */
|
|
2
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import type { GrantsSession } from "./session.ts";
|
|
4
|
+
import { setWorkMode, workModeSnapshot } from "./work-mode.ts";
|
|
5
|
+
import {
|
|
6
|
+
WORK_MODE_EMPHASES,
|
|
7
|
+
WORK_MODE_LABELS,
|
|
8
|
+
workModeLabel,
|
|
9
|
+
type WorkModeSelection,
|
|
10
|
+
} from "../src/kernel/work-mode.ts";
|
|
11
|
+
|
|
12
|
+
export function registerWorkModeCommand(pi: ExtensionAPI, session: GrantsSession): void {
|
|
13
|
+
pi.registerCommand("work-mode", {
|
|
14
|
+
description: "Choose Standard (current behavior) or optional Ambitious guidance for this session or next request",
|
|
15
|
+
handler: async (args, ctx) => {
|
|
16
|
+
try {
|
|
17
|
+
const initial = workModeSnapshot(session);
|
|
18
|
+
if (args.trim() === "status") {
|
|
19
|
+
ctx.ui.notify(
|
|
20
|
+
[
|
|
21
|
+
`Session: ${workModeLabel(initial.selection)}`,
|
|
22
|
+
`Active: ${initial.active ? workModeLabel(initial.active) : "idle"}`,
|
|
23
|
+
`Next: ${workModeLabel(initial.nextRequest ?? initial.selection)}`,
|
|
24
|
+
].join("\n"),
|
|
25
|
+
"info",
|
|
26
|
+
);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const owner = session.reloadLifecycle.workMode;
|
|
30
|
+
let selection: WorkModeSelection;
|
|
31
|
+
let scope: "session" | "next-request";
|
|
32
|
+
if (args.trim()) {
|
|
33
|
+
const [mode, target = "session", ...emphases] = args.trim().split(/\s+/);
|
|
34
|
+
if ((mode !== "standard" && mode !== "ambitious") || !["session", "next"].includes(target))
|
|
35
|
+
throw new Error(
|
|
36
|
+
"Use /work-mode, or /work-mode standard|ambitious session|next [speed altitude depth range]",
|
|
37
|
+
);
|
|
38
|
+
selection = { mode, emphases: emphases as WorkModeSelection["emphases"] };
|
|
39
|
+
scope = target === "next" ? "next-request" : "session";
|
|
40
|
+
} else {
|
|
41
|
+
if (!ctx.hasUI)
|
|
42
|
+
throw new Error("Use /work-mode standard|ambitious session|next [speed altitude depth range]");
|
|
43
|
+
const mode = await ctx.ui.select("Work mode · approach only", ["Standard · current behavior", "Ambitious"]);
|
|
44
|
+
if (!mode) return;
|
|
45
|
+
const target = await ctx.ui.select("Apply to", [
|
|
46
|
+
"This session · /new resets to Standard",
|
|
47
|
+
"Next request only · includes its children",
|
|
48
|
+
]);
|
|
49
|
+
if (!target) return;
|
|
50
|
+
scope = target.startsWith("This session") ? "session" : "next-request";
|
|
51
|
+
selection = { mode: mode.startsWith("Standard") ? "standard" : "ambitious", emphases: [] };
|
|
52
|
+
if (selection.mode === "ambitious") {
|
|
53
|
+
while (true) {
|
|
54
|
+
const options = WORK_MODE_EMPHASES.map(
|
|
55
|
+
(key) => `${selection.emphases.includes(key) ? "[x]" : "[ ]"} ${WORK_MODE_LABELS[key]}`,
|
|
56
|
+
);
|
|
57
|
+
const chosen = await ctx.ui.select("Optional emphases · none selected means balanced", [
|
|
58
|
+
...options,
|
|
59
|
+
"Apply selection",
|
|
60
|
+
]);
|
|
61
|
+
if (!chosen) return;
|
|
62
|
+
if (chosen === "Apply selection") break;
|
|
63
|
+
const key = WORK_MODE_EMPHASES[options.indexOf(chosen)];
|
|
64
|
+
if (key)
|
|
65
|
+
selection.emphases = selection.emphases.includes(key)
|
|
66
|
+
? selection.emphases.filter((item) => item !== key)
|
|
67
|
+
: [...selection.emphases, key];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (session.reloadLifecycle.workMode !== owner) throw new Error("Session changed; choose the mode again");
|
|
72
|
+
setWorkMode(session, selection, scope);
|
|
73
|
+
ctx.ui.notify(
|
|
74
|
+
`${workModeLabel(selection)} · ${scope === "session" ? "this session; /new resets to Standard" : "next request only"}. Running work keeps its captured mode.`,
|
|
75
|
+
"info",
|
|
76
|
+
);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
ctx.ui.notify(error instanceof Error ? error.message : "Work-mode selection was not applied", "error");
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/** Session-owned optional guidance. Selection is operator input, never a model tool or memory inference. */
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import type { GrantsSession } from "./session.ts";
|
|
5
|
+
import {
|
|
6
|
+
ENV_WORK_MODE,
|
|
7
|
+
parseWorkMode,
|
|
8
|
+
standardWorkMode,
|
|
9
|
+
workModeGuidance,
|
|
10
|
+
type WorkModeSelection,
|
|
11
|
+
type WorkModeSnapshot,
|
|
12
|
+
} from "../src/kernel/work-mode.ts";
|
|
13
|
+
import { registerWorkModeCommand } from "./work-mode-command.ts";
|
|
14
|
+
|
|
15
|
+
export const WORK_MODE_ENTRY = "pi-daddy:work-mode:v1";
|
|
16
|
+
interface PendingMode {
|
|
17
|
+
id: string;
|
|
18
|
+
selection: WorkModeSelection;
|
|
19
|
+
}
|
|
20
|
+
interface StoredMode {
|
|
21
|
+
version: 1;
|
|
22
|
+
selection: WorkModeSelection;
|
|
23
|
+
pending?: PendingMode;
|
|
24
|
+
consumed?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface WorkModeLifecycle {
|
|
27
|
+
nativeSessionId: string;
|
|
28
|
+
selection: WorkModeSelection;
|
|
29
|
+
pending?: PendingMode;
|
|
30
|
+
active?: WorkModeSelection;
|
|
31
|
+
inherited: boolean;
|
|
32
|
+
note?: string;
|
|
33
|
+
isIdle?: () => boolean;
|
|
34
|
+
write: (value: StoredMode) => void;
|
|
35
|
+
}
|
|
36
|
+
type ModeContext = Pick<ExtensionContext, "sessionManager" | "ui"> & Partial<Pick<ExtensionContext, "isIdle">>;
|
|
37
|
+
const clone = (value: WorkModeSelection) => parseWorkMode(value)!;
|
|
38
|
+
const validId = (value: unknown): value is string => typeof value === "string" && /^[a-f0-9-]{36}$/.test(value);
|
|
39
|
+
|
|
40
|
+
function storedMode(value: unknown): StoredMode | undefined {
|
|
41
|
+
if (!value || typeof value !== "object") return;
|
|
42
|
+
const input = value as Record<string, unknown>;
|
|
43
|
+
if (input.version !== 1) return;
|
|
44
|
+
const selection = parseWorkMode(input.selection);
|
|
45
|
+
if (!selection) return;
|
|
46
|
+
const pending = input.pending as Partial<PendingMode> | undefined;
|
|
47
|
+
if (pending && (!validId(pending.id) || !parseWorkMode(pending.selection))) return;
|
|
48
|
+
if (input.consumed !== undefined && !validId(input.consumed)) return;
|
|
49
|
+
return {
|
|
50
|
+
version: 1,
|
|
51
|
+
selection,
|
|
52
|
+
...(pending ? { pending: { id: pending.id!, selection: clone(pending.selection!) } } : {}),
|
|
53
|
+
...(typeof input.consumed === "string" ? { consumed: input.consumed } : {}),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function modeEntry(entry: unknown): StoredMode | undefined {
|
|
57
|
+
if (!entry || typeof entry !== "object") return;
|
|
58
|
+
const item = entry as { type?: string; customType?: string; data?: unknown };
|
|
59
|
+
return item.type === "custom" && item.customType === WORK_MODE_ENTRY ? storedMode(item.data) : undefined;
|
|
60
|
+
}
|
|
61
|
+
function current(session: GrantsSession): WorkModeLifecycle | undefined {
|
|
62
|
+
const state = session.reloadLifecycle?.workMode;
|
|
63
|
+
const owner = session.reloadLifecycle?.autoMode;
|
|
64
|
+
return session.ownerBound &&
|
|
65
|
+
state &&
|
|
66
|
+
owner?.nativeSessionId === state.nativeSessionId &&
|
|
67
|
+
session.autoMode === owner.reader
|
|
68
|
+
? state
|
|
69
|
+
: undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Called after the normal owner binding, before startup publishes child environment. */
|
|
73
|
+
export function initializeWorkMode(
|
|
74
|
+
pi: Pick<ExtensionAPI, "appendEntry">,
|
|
75
|
+
session: GrantsSession,
|
|
76
|
+
ctx: ModeContext,
|
|
77
|
+
reason: string,
|
|
78
|
+
environment: NodeJS.ProcessEnv = process.env,
|
|
79
|
+
): void {
|
|
80
|
+
const id = ctx.sessionManager?.getSessionId?.() ?? session.episodeId;
|
|
81
|
+
const existing = session.reloadLifecycle.workMode;
|
|
82
|
+
const write = (value: StoredMode) => {
|
|
83
|
+
if (typeof pi.appendEntry !== "function") throw new Error("Work-mode session recording is unavailable");
|
|
84
|
+
pi.appendEntry(WORK_MODE_ENTRY, value);
|
|
85
|
+
};
|
|
86
|
+
if (reason === "reload" && existing?.nativeSessionId === id) {
|
|
87
|
+
existing.write = write;
|
|
88
|
+
existing.isIdle = ctx.isIdle ? () => ctx.isIdle!() : undefined;
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const state: WorkModeLifecycle = {
|
|
92
|
+
nativeSessionId: id,
|
|
93
|
+
selection: standardWorkMode(),
|
|
94
|
+
inherited: false,
|
|
95
|
+
write,
|
|
96
|
+
...(ctx.isIdle ? { isIdle: () => ctx.isIdle!() } : {}),
|
|
97
|
+
};
|
|
98
|
+
session.reloadLifecycle.workMode = state;
|
|
99
|
+
if (session.depth > 0 || session.ownExecutionId) {
|
|
100
|
+
state.inherited = true;
|
|
101
|
+
const raw = environment[ENV_WORK_MODE];
|
|
102
|
+
if (raw !== undefined) {
|
|
103
|
+
try {
|
|
104
|
+
const parsed = raw.length <= 512 ? parseWorkMode(JSON.parse(raw)) : undefined;
|
|
105
|
+
if (!parsed) throw Error();
|
|
106
|
+
state.selection = parsed;
|
|
107
|
+
} catch {
|
|
108
|
+
state.note =
|
|
109
|
+
"Inherited work-mode guidance is unavailable; Standard applies. Execution permissions are unchanged.";
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (reason === "new") return;
|
|
115
|
+
try {
|
|
116
|
+
const entries = ctx.sessionManager?.getEntries?.() ?? [];
|
|
117
|
+
const consumed = new Set(entries.map(modeEntry).flatMap((item) => (item?.consumed ? [item.consumed] : [])));
|
|
118
|
+
const branch = ctx.sessionManager?.getBranch?.() ?? [];
|
|
119
|
+
for (let index = branch.length - 1; index >= 0; index--) {
|
|
120
|
+
const entry = branch[index];
|
|
121
|
+
if (entry.type !== "custom" || entry.customType !== WORK_MODE_ENTRY) continue;
|
|
122
|
+
const record = modeEntry(entry);
|
|
123
|
+
if (!record) {
|
|
124
|
+
state.note = "Saved work-mode settings could not be read; Standard applies. Select a mode again if wanted.";
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
state.selection = record.selection;
|
|
128
|
+
// A fork is a new conversation; a historical one-shot request must never become its next request.
|
|
129
|
+
if (reason !== "fork" && record.pending && !consumed.has(record.pending.id)) state.pending = record.pending;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
} catch {
|
|
133
|
+
state.note = "Saved work-mode settings are unavailable; Standard applies.";
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function workModeSnapshot(session: GrantsSession): WorkModeSnapshot {
|
|
138
|
+
const state = current(session);
|
|
139
|
+
return state
|
|
140
|
+
? {
|
|
141
|
+
available: true,
|
|
142
|
+
selection: clone(state.selection),
|
|
143
|
+
inherited: state.inherited,
|
|
144
|
+
...(state.pending ? { nextRequest: clone(state.pending.selection) } : {}),
|
|
145
|
+
// Preparation can fail without agent_settled. Display the owner's live idle state rather
|
|
146
|
+
// than treating a captured prompt as proof that a run is still active.
|
|
147
|
+
...(state.active && !state.isIdle?.() ? { active: clone(state.active) } : {}),
|
|
148
|
+
...(state.note ? { note: state.note } : {}),
|
|
149
|
+
}
|
|
150
|
+
: { available: false, selection: standardWorkMode(), inherited: false };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Explicit operator edit. A session edit clears a queued one-shot override but keeps active work frozen. */
|
|
154
|
+
export function setWorkMode(session: GrantsSession, value: unknown, scope: unknown): void {
|
|
155
|
+
const state = current(session);
|
|
156
|
+
if (!state || state.inherited || !session.reloadLifecycle.autoMode?.authority)
|
|
157
|
+
throw new Error("Work mode can only be changed in the connected owning parent");
|
|
158
|
+
const selection = parseWorkMode(value);
|
|
159
|
+
if (!selection || (scope !== "session" && scope !== "next-request"))
|
|
160
|
+
throw new Error("Choose Standard or Ambitious, valid emphases, and a session or next-request scope");
|
|
161
|
+
const next: StoredMode =
|
|
162
|
+
scope === "session"
|
|
163
|
+
? { version: 1, selection }
|
|
164
|
+
: { version: 1, selection: state.selection, pending: { id: randomUUID(), selection } };
|
|
165
|
+
try {
|
|
166
|
+
state.write(next);
|
|
167
|
+
} catch {
|
|
168
|
+
throw new Error("Work-mode selection was not saved; the previous setting still applies");
|
|
169
|
+
}
|
|
170
|
+
state.selection = clone(next.selection);
|
|
171
|
+
state.pending = next.pending;
|
|
172
|
+
delete state.note;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Capture before any asynchronous discovery/gating; one override belongs to one complete Pi run. */
|
|
176
|
+
export function beginWorkModeRequest(session: GrantsSession, freshRequest = false): WorkModeSelection | undefined {
|
|
177
|
+
const state = current(session);
|
|
178
|
+
if (!state) return;
|
|
179
|
+
if (state.active && !freshRequest) return clone(state.active);
|
|
180
|
+
let selection = state.pending?.selection ?? state.selection;
|
|
181
|
+
if (state.pending) {
|
|
182
|
+
try {
|
|
183
|
+
state.write({ version: 1, selection: state.selection, consumed: state.pending.id });
|
|
184
|
+
delete state.pending;
|
|
185
|
+
} catch {
|
|
186
|
+
// Do not run an override whose consumption cannot be recorded; ordinary delivery remains available.
|
|
187
|
+
state.note = "Next-request mode could not be recorded and was not used; the session mode applies.";
|
|
188
|
+
selection = state.selection;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
state.active = clone(selection);
|
|
192
|
+
return clone(selection);
|
|
193
|
+
}
|
|
194
|
+
export function finishWorkModeRequest(session: GrantsSession): void {
|
|
195
|
+
const state = current(session);
|
|
196
|
+
if (state) delete state.active;
|
|
197
|
+
}
|
|
198
|
+
/** Child dispatch uses only the active capture, never a later UI selection. */
|
|
199
|
+
export function capturedWorkMode(session: GrantsSession): WorkModeSelection | undefined {
|
|
200
|
+
const state = current(session);
|
|
201
|
+
const selected = state?.active ?? (state?.inherited ? state.selection : undefined);
|
|
202
|
+
return selected?.mode === "ambitious" ? clone(selected) : undefined;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function registerWorkMode(pi: ExtensionAPI, session: GrantsSession) {
|
|
206
|
+
pi.on("before_agent_start", (event) => {
|
|
207
|
+
// Native retry/compaction continues the same agent run without this hook. A new hook is a new request,
|
|
208
|
+
// including after preparation failed before agent_settled could be emitted.
|
|
209
|
+
const selected = beginWorkModeRequest(session, true);
|
|
210
|
+
// Child launch already appended the role-preserving guidance; only maintain its descendant snapshot here.
|
|
211
|
+
if (current(session)?.inherited) return;
|
|
212
|
+
const guidance = workModeGuidance(selected, "parent");
|
|
213
|
+
if (!guidance) return;
|
|
214
|
+
// Keep Pi's structured prompt live: a full-prompt return would freeze out later extensions'
|
|
215
|
+
// guidelines and native tool-loadout updates. Respect an explicit earlier override if present.
|
|
216
|
+
if (event.systemPromptOptions.forceSystemPrompt !== undefined)
|
|
217
|
+
event.systemPromptOptions.forceSystemPrompt += `\n\n${guidance}`;
|
|
218
|
+
else event.systemPromptOptions.promptGuidelines.push(guidance);
|
|
219
|
+
});
|
|
220
|
+
// agent_end may precede a retry/compaction. Only a settled run consumes the active capture.
|
|
221
|
+
pi.on("agent_settled", () => finishWorkModeRequest(session));
|
|
222
|
+
pi.on("session_tree", (_event, ctx) => initializeWorkMode(pi, session, ctx, "tree"));
|
|
223
|
+
registerWorkModeCommand(pi, session);
|
|
224
|
+
return (ctx: ModeContext, reason: string, environment: NodeJS.ProcessEnv) =>
|
|
225
|
+
initializeWorkMode(pi, session, ctx, reason, environment);
|
|
226
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-daddy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.62.1",
|
|
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",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"typecheck": "tsc -p tsconfig.check.json",
|
|
54
54
|
"test": "node scripts/unit-tests.ts",
|
|
55
55
|
"test:integration": "node --test test-integration/*.it.ts",
|
|
56
|
-
"test:integration:ci": "node --test test-integration/approval.it.ts test-integration/governance.it.ts test-integration/activity.it.ts test-integration/auto-chain.it.ts test-integration/pi-sdk/automatic-start.it.ts test-integration/pi-sdk/dashboard-prompts.it.ts test-integration/pi-sdk/owned-pattern-cleanup.it.ts test-integration/pi-sdk/child-tool-delivery.it.ts test-integration/pi-sdk/parent-run-tools.it.ts test-integration/pi-sdk/described-binding.it.ts test-integration/pi-sdk/child-usage-total.it.ts",
|
|
56
|
+
"test:integration:ci": "node --test test-integration/approval.it.ts test-integration/governance.it.ts test-integration/activity.it.ts test-integration/auto-chain.it.ts test-integration/pi-sdk/automatic-start.it.ts test-integration/pi-sdk/dashboard-prompts.it.ts test-integration/pi-sdk/owned-pattern-cleanup.it.ts test-integration/pi-sdk/child-tool-delivery.it.ts test-integration/pi-sdk/parent-run-tools.it.ts test-integration/pi-sdk/described-binding.it.ts test-integration/pi-sdk/child-usage-total.it.ts test-integration/pi-sdk/work-mode.it.ts test-integration/pi-sdk/work-mode-request-boundary.it.ts",
|
|
57
57
|
"contracts:generate": "node scripts/generate-ledger-record-contract.ts",
|
|
58
58
|
"prepack": "npm run build",
|
|
59
59
|
"test:smoke": "node scripts/smoke-installed.mjs",
|
|
@@ -95,6 +95,25 @@ export const DEFAULT_CONTEXT_TURNS = 20;
|
|
|
95
95
|
/** Total budget for everything that crosses, matching the chain handoff so one cap governs both channels. */
|
|
96
96
|
export const CONTEXT_MAX_BYTES = 32 * 1024;
|
|
97
97
|
|
|
98
|
+
/** Definition ceiling only: describing an available handoff never grants it or bypasses its approval. */
|
|
99
|
+
export function definitionContextContract(capabilities: readonly Capability[]) {
|
|
100
|
+
const permitted = new Set(capabilities.flatMap((id) => [id, ...(CONTEXT_SUBSUMPTION[id] ?? [])]));
|
|
101
|
+
const modes = CONTEXT_MODES.filter((mode) => mode === "none" || permitted.has(contextCapability(mode)));
|
|
102
|
+
return {
|
|
103
|
+
version: 1 as const,
|
|
104
|
+
definitionModes: modes,
|
|
105
|
+
defaultRequest: { mode: "none" as const },
|
|
106
|
+
guidance:
|
|
107
|
+
"Context is optional extra parent-session material. For independent review in the same workspace, " +
|
|
108
|
+
"omit context and let the child inspect the checkout with its own read tools. " +
|
|
109
|
+
"Keep the task scope, acceptance criteria and exact evidence references; do not omit required evidence. " +
|
|
110
|
+
"The definition ceiling is not permission: the current parent grant and approval checks still apply.",
|
|
111
|
+
...(modes.includes("files")
|
|
112
|
+
? { files: { minItems: 1, maxItems: MAX_CONTEXT_FILES, paths: "repository-relative" as const } }
|
|
113
|
+
: {}),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
98
117
|
/**
|
|
99
118
|
* Validate a model-supplied request, or refuse it.
|
|
100
119
|
*
|
|
@@ -12,6 +12,7 @@ import type { Catalog } from "./catalog.ts";
|
|
|
12
12
|
import type { ApprovalBinding, CorrelationMetadata } from "./correlation.ts";
|
|
13
13
|
import type { StructuredRefusal } from "./refusals.ts";
|
|
14
14
|
import type { WorkspacePins } from "./workspace-pin.ts";
|
|
15
|
+
import type { WorkModeSelection } from "./work-mode.ts";
|
|
15
16
|
|
|
16
17
|
/** The two ways a child can be started. Defined here, below the executors, so the ledger and the planner can name it without importing an executor (ADR-0076 layering). */
|
|
17
18
|
export const EXECUTOR_KINDS = ["process", "herdr"] as const;
|
|
@@ -59,6 +60,8 @@ export interface DelegationRequest {
|
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
export interface DelegationContext {
|
|
63
|
+
/** Optional working-style snapshot; no capability, approval or task-identity authority. */
|
|
64
|
+
workMode?: WorkModeSelection;
|
|
62
65
|
autoModeRef?: AutoModeRef;
|
|
63
66
|
ownGrant: Capability[];
|
|
64
67
|
/** Stable identity shared by the root session and every descendant. */
|