pi-better-server 0.7.2 → 0.7.3
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/package.json +1 -1
- package/src/runtime/domain/subagents/index.domain.mjs +6 -2
- package/src/runtime/domain/subagents/index.ts +7 -2
- package/src/runtime/domain/subagents/output-payload.domain.mjs +3 -1
- package/src/runtime/domain/subagents/output-payload.ts +2 -0
- package/src/runtime/domain/subagents/package.json +1 -1
- package/src/runtime/domain/subagents/tools.domain.mjs +3 -2
- package/src/runtime/domain/subagents/tools.ts +3 -2
- package/src/runtime/domain/subagents/workflow-assignment.domain.mjs +25 -0
- package/src/runtime/domain/subagents/workflow-assignment.ts +35 -0
- package/src/runtime/query-executor.ts +11 -2
- package/src/version.ts +1 -1
package/package.json
CHANGED
|
@@ -47,6 +47,7 @@ import { deliverSubagentPrompt, effectiveSubagentSettings, subagentSettingsTool
|
|
|
47
47
|
import { STEER_FILE_ENV, readSteerReceipt } from "./child-steer.domain.mjs";
|
|
48
48
|
import { continuationTimingParams, configuredMaxMinutes, decideTiming, describeTiming, DEFAULT_TIMING_MINUTES, emptyProgress, foldProgress, formatTimingLimits, isTimingMinutes, isProgressRelevantLine, resolveRunTiming, steerText, stuckAlertText, TIMING_ENV, timingParameterSchemas, toolWaitAlertText, validatedTimingMinutes, } from "./timing.domain.mjs";
|
|
49
49
|
import { readAppendedLines } from "./log-cursor.domain.mjs";
|
|
50
|
+
import { launchWorkflowAssignment } from "./workflow-assignment.domain.mjs";
|
|
50
51
|
import { DELEGATION_MODES, DELEGATION_MODE_REQUEST, isDelegationMode, normalizeDelegationMode } from "./delegation.domain.mjs";
|
|
51
52
|
import { resolveExtensions, extensionArgs } from "./extensions.domain.mjs";
|
|
52
53
|
import { prepareTaskRuntime, applyDirectApplicationLoadout, DEFAULT_TASK_PERMISSIONS, RUN_APPLICATION, SDK_BUILTIN_TOOLS } from "./task-policy.domain.mjs";
|
|
@@ -2786,13 +2787,13 @@ export default function (pi, managed) {
|
|
|
2786
2787
|
ctx = captureLaunchContext(ctx);
|
|
2787
2788
|
restoreDelegationMode(ctx);
|
|
2788
2789
|
await workerOperations.start();
|
|
2789
|
-
return definition.execute(key,
|
|
2790
|
+
return launchWorkflowAssignment(pi, ctx, key, params, args => definition.execute(key, args, signal, onUpdate, ctx));
|
|
2790
2791
|
} } : { ...definition, async execute(key, params, signal, _onUpdate, ctx) {
|
|
2791
2792
|
ctx = captureLaunchContext(ctx);
|
|
2792
2793
|
catalogHostFrom(ctx);
|
|
2793
2794
|
const { submitManagedLaunch } = await import("./managed-launch-client.domain.mjs");
|
|
2794
2795
|
void activateWorkObservation();
|
|
2795
|
-
return await observeNavigatorLaunch(ctx, "subagents", key, "Subagent launch", () => submitManagedLaunch(pi, ctx, key, definition.name,
|
|
2796
|
+
return launchWorkflowAssignment(pi, ctx, key, params, async (args) => await observeNavigatorLaunch(ctx, "subagents", key, "Subagent launch", () => submitManagedLaunch(pi, ctx, key, definition.name, args, signal)));
|
|
2796
2797
|
} });
|
|
2797
2798
|
};
|
|
2798
2799
|
announceExecutionAdapter(pi, {
|
|
@@ -3947,6 +3948,9 @@ export default function (pi, managed) {
|
|
|
3947
3948
|
],
|
|
3948
3949
|
parameters: Type.Object({
|
|
3949
3950
|
prompt: Type.String({ description: "The task for the subagent. This is the only context it gets — be self-contained. On a continuation this is the next user turn; the original task and role stay in saved history." }),
|
|
3951
|
+
workflow: Type.Optional(Type.Object({
|
|
3952
|
+
runId: Type.String(), step: Type.String(),
|
|
3953
|
+
}, { description: "Bind this launch to a ready dynamic workflow item. Supply its selected role or agent and inherit catalog skills." })),
|
|
3950
3954
|
session_name: Type.Optional(Type.String({ description: "Exact name of one saved conversation in the current folder and descendants. Alternative to session_id. Duplicate names report matching session ids instead of choosing a conversation." })),
|
|
3951
3955
|
session_id: Type.Optional(Type.String({ description: "Native session id of a saved conversation to continue (reported for every launch and attempt). Omit to start a new conversation. A continuation gets a new run id but keeps this session id, history, workspace, and frozen launch recipe." })),
|
|
3952
3956
|
name: Type.Optional(Type.String({ description: "Short label for the run (e.g. 'reviewer'). Ignored when agent or role is set, except as the direct-role alias when alias is omitted." })),
|
|
@@ -82,6 +82,7 @@ import {
|
|
|
82
82
|
type TimingStopReason,
|
|
83
83
|
} from "./timing.ts";
|
|
84
84
|
import { readAppendedLines, type LogCursor } from "./log-cursor.ts";
|
|
85
|
+
import { launchWorkflowAssignment } from "./workflow-assignment.ts";
|
|
85
86
|
import { DELEGATION_MODES, DELEGATION_MODE_REQUEST, isDelegationMode, normalizeDelegationMode, type DelegationMode } from "./delegation.ts";
|
|
86
87
|
import { resolveExtensions, extensionArgs } from "./extensions.ts";
|
|
87
88
|
import { prepareTaskRuntime, applyDirectApplicationLoadout, DEFAULT_TASK_PERMISSIONS, RUN_APPLICATION, SDK_BUILTIN_TOOLS } from "./task-policy.ts";
|
|
@@ -2804,13 +2805,14 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
2804
2805
|
ctx = captureLaunchContext(ctx);
|
|
2805
2806
|
restoreDelegationMode(ctx);
|
|
2806
2807
|
await workerOperations.start();
|
|
2807
|
-
return definition.execute(key,
|
|
2808
|
+
return launchWorkflowAssignment(pi, ctx, key, params, args => definition.execute(key, args, signal, onUpdate, ctx));
|
|
2808
2809
|
} } : { ...definition, async execute(key, params, signal, _onUpdate, ctx) {
|
|
2809
2810
|
ctx = captureLaunchContext(ctx);
|
|
2810
2811
|
catalogHostFrom(ctx);
|
|
2811
2812
|
const { submitManagedLaunch } = await import("./managed-launch-client.ts");
|
|
2812
2813
|
void activateWorkObservation();
|
|
2813
|
-
return
|
|
2814
|
+
return launchWorkflowAssignment(pi, ctx, key, params, async args =>
|
|
2815
|
+
await observeNavigatorLaunch(ctx, "subagents", key, "Subagent launch", () => submitManagedLaunch(pi, ctx, key, definition.name, args, signal)) as never);
|
|
2814
2816
|
} });
|
|
2815
2817
|
};
|
|
2816
2818
|
announceExecutionAdapter(pi, {
|
|
@@ -4020,6 +4022,9 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
4020
4022
|
],
|
|
4021
4023
|
parameters: Type.Object({
|
|
4022
4024
|
prompt: Type.String({ description: "The task for the subagent. This is the only context it gets — be self-contained. On a continuation this is the next user turn; the original task and role stay in saved history." }),
|
|
4025
|
+
workflow: Type.Optional(Type.Object({
|
|
4026
|
+
runId: Type.String(), step: Type.String(),
|
|
4027
|
+
}, { description: "Bind this launch to a ready dynamic workflow item. Supply its selected role or agent and inherit catalog skills." })),
|
|
4023
4028
|
session_name: Type.Optional(Type.String({ description: "Exact name of one saved conversation in the current folder and descendants. Alternative to session_id. Duplicate names report matching session ids instead of choosing a conversation." })),
|
|
4024
4029
|
session_id: Type.Optional(Type.String({ description: "Native session id of a saved conversation to continue (reported for every launch and attempt). Omit to start a new conversation. A continuation gets a new run id but keeps this session id, history, workspace, and frozen launch recipe." })),
|
|
4025
4030
|
name: Type.Optional(Type.String({ description: "Short label for the run (e.g. 'reviewer'). Ignored when agent or role is set, except as the direct-role alias when alias is omitted." })),
|
|
@@ -521,7 +521,7 @@ export function assembleOrphanedResult(id, meta, healthLine, request = {}, scope
|
|
|
521
521
|
statusCursor: ctx.statusCursor,
|
|
522
522
|
});
|
|
523
523
|
}
|
|
524
|
-
export function assembleSubagentResult(id, meta, request = {}, healthLine = "", scopeKey = defaultScope()) {
|
|
524
|
+
export function assembleSubagentResult(id, meta, request = {}, healthLine = "", scopeKey = defaultScope(), observed) {
|
|
525
525
|
healthLine = [healthLine, projectionDiagnostic(meta)].filter(Boolean).join("\n");
|
|
526
526
|
const st = effectiveStatus(meta);
|
|
527
527
|
if (isRawMode(request.mode) || cursorKind(request.cursor) === "f")
|
|
@@ -601,6 +601,8 @@ export function assembleSubagentResult(id, meta, request = {}, healthLine = "",
|
|
|
601
601
|
}
|
|
602
602
|
const exceptional = isRoutineComplete(lifecycle) ? undefined : formatLifecycleDiagnostics(lifecycle);
|
|
603
603
|
const answer = run.finalText || "";
|
|
604
|
+
if (observed)
|
|
605
|
+
observed.hasFinalAnswer = Boolean(answer.trim());
|
|
604
606
|
const fallback = !answer
|
|
605
607
|
? (run.lastActivity
|
|
606
608
|
? `(no final answer parsed; latest activity)\n${run.lastActivity}`
|
|
@@ -702,6 +702,7 @@ export function assembleSubagentResult(
|
|
|
702
702
|
request: PayloadRequest = {},
|
|
703
703
|
healthLine = "",
|
|
704
704
|
scopeKey = defaultScope(),
|
|
705
|
+
observed?: { hasFinalAnswer?: boolean },
|
|
705
706
|
): string {
|
|
706
707
|
healthLine = [healthLine, projectionDiagnostic(meta)].filter(Boolean).join("\n");
|
|
707
708
|
const st = effectiveStatus(meta);
|
|
@@ -782,6 +783,7 @@ export function assembleSubagentResult(
|
|
|
782
783
|
|
|
783
784
|
const exceptional = isRoutineComplete(lifecycle) ? undefined : formatLifecycleDiagnostics(lifecycle);
|
|
784
785
|
const answer = run.finalText || "";
|
|
786
|
+
if (observed) observed.hasFinalAnswer = Boolean(answer.trim());
|
|
785
787
|
const fallback = !answer
|
|
786
788
|
? (run.lastActivity
|
|
787
789
|
? `(no final answer parsed; latest activity)\n${run.lastActivity}`
|
|
@@ -475,12 +475,13 @@ export function subagentResultTool(Type, baseSession = {}) {
|
|
|
475
475
|
verified: true, waits: inspected.dependencies ?? [], ...{ outcome: inspected.outcome },
|
|
476
476
|
}) : observed?.assignment;
|
|
477
477
|
return withAssignmentObservations(assignment ? [{ meta, assignment }] : [], () => {
|
|
478
|
+
const observedAnswer = {};
|
|
478
479
|
const resultText = (body) => {
|
|
479
480
|
const evidence = outcome;
|
|
480
481
|
const operations = evidence?.dependencies?.flatMap((wait) => wait.dependencies.map((dependency) => dependency.operationId)).slice(0, 5) ?? [];
|
|
481
482
|
const header = evidence?.outcome ? `Outcome r${evidence.outcome.revision}: ${evidence.outcome.outcome}. ${evidence.outcome.reason.slice(0, 256)}${operations.length ? `\nEvidence operations: ${operations.join(", ")}` : ""}\n` : "";
|
|
482
483
|
const result = subagentResultText(header + body);
|
|
483
|
-
return { ...result, details: { ...result.details, outcome, outcomeSupport: meta.outcomeSupport, assignment: assignment ?? assignmentFor(meta, effectiveStatus(meta)), snapshot: observed?.snapshot, ...permissionDetails(p.id, budgetFor("answer", p.maxBytes)) } };
|
|
484
|
+
return { ...result, details: { ...result.details, ...observedAnswer, outcome, outcomeSupport: meta.outcomeSupport, assignment: assignment ?? assignmentFor(meta, effectiveStatus(meta)), snapshot: observed?.snapshot, ...permissionDetails(p.id, budgetFor("answer", p.maxBytes)) } };
|
|
484
485
|
};
|
|
485
486
|
if (params.operation_id && outcome) {
|
|
486
487
|
const evidence = outcome;
|
|
@@ -497,7 +498,7 @@ export function subagentResultTool(Type, baseSession = {}) {
|
|
|
497
498
|
}
|
|
498
499
|
return resultText(assembleRunningResult(p.id, meta, p, scopeKey, healthLine));
|
|
499
500
|
}
|
|
500
|
-
return resultText(assembleSubagentResult(p.id, meta, p, healthLine, scopeKey));
|
|
501
|
+
return resultText(assembleSubagentResult(p.id, meta, p, healthLine, scopeKey, observedAnswer));
|
|
501
502
|
});
|
|
502
503
|
},
|
|
503
504
|
};
|
|
@@ -542,12 +542,13 @@ export function subagentResultTool(Type: TypeModule, baseSession: SubagentToolSe
|
|
|
542
542
|
verified: true, waits: inspected.dependencies ?? [], ...{ outcome: inspected.outcome },
|
|
543
543
|
}) : observed?.assignment;
|
|
544
544
|
return withAssignmentObservations(assignment ? [{ meta, assignment }] : [], () => {
|
|
545
|
+
const observedAnswer: { hasFinalAnswer?: boolean } = {};
|
|
545
546
|
const resultText = (body: string) => {
|
|
546
547
|
const evidence = outcome as { outcome?: { revision: number; outcome: string; reason: string }; dependencies?: Array<{ dependencies: Array<{ operationId: string }> }> } | null;
|
|
547
548
|
const operations = evidence?.dependencies?.flatMap((wait) => wait.dependencies.map((dependency) => dependency.operationId)).slice(0, 5) ?? [];
|
|
548
549
|
const header = evidence?.outcome ? `Outcome r${evidence.outcome.revision}: ${evidence.outcome.outcome}. ${evidence.outcome.reason.slice(0, 256)}${operations.length ? `\nEvidence operations: ${operations.join(", ")}` : ""}\n` : "";
|
|
549
550
|
const result = subagentResultText(header + body);
|
|
550
|
-
return { ...result, details: { ...result.details, outcome, outcomeSupport: meta.outcomeSupport, assignment: assignment ?? assignmentFor(meta, effectiveStatus(meta)), snapshot: observed?.snapshot, ...permissionDetails(p.id, budgetFor("answer", p.maxBytes)) } };
|
|
551
|
+
return { ...result, details: { ...result.details, ...observedAnswer, outcome, outcomeSupport: meta.outcomeSupport, assignment: assignment ?? assignmentFor(meta, effectiveStatus(meta)), snapshot: observed?.snapshot, ...permissionDetails(p.id, budgetFor("answer", p.maxBytes)) } };
|
|
551
552
|
};
|
|
552
553
|
if ((params as Record<string, unknown>).operation_id && outcome) {
|
|
553
554
|
const evidence = outcome as { outcome: { revision: number; outcome: string; reason: string }; logs: Array<{ text: string }> };
|
|
@@ -564,7 +565,7 @@ export function subagentResultTool(Type: TypeModule, baseSession: SubagentToolSe
|
|
|
564
565
|
}
|
|
565
566
|
return resultText(assembleRunningResult(p.id, meta, p, scopeKey, healthLine));
|
|
566
567
|
}
|
|
567
|
-
return resultText(assembleSubagentResult(p.id, meta, p, healthLine, scopeKey));
|
|
568
|
+
return resultText(assembleSubagentResult(p.id, meta, p, healthLine, scopeKey, observedAnswer));
|
|
568
569
|
});
|
|
569
570
|
},
|
|
570
571
|
} as ToolDefinition;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-subagents/workflow-assignment.ts. Do not edit directly.
|
|
2
|
+
export const WORKFLOW_ASSIGNMENT = "pi-better-subagents:workflow-assignment";
|
|
3
|
+
/** Wrap only explicitly workflow-bound launches. The normal spawn path owns all execution permissions. */
|
|
4
|
+
export async function launchWorkflowAssignment(pi, ctx, callId, params, launch) {
|
|
5
|
+
const input = params;
|
|
6
|
+
if (!input.workflow)
|
|
7
|
+
return launch(params);
|
|
8
|
+
const request = { ref: input.workflow, callId, ctx, input };
|
|
9
|
+
pi.events.emit(WORKFLOW_ASSIGNMENT, request);
|
|
10
|
+
if (!request.admission)
|
|
11
|
+
throw new Error(request.error ?? "No active workflow authorized this assignment.");
|
|
12
|
+
const { workflow: _workflow, ...args } = input;
|
|
13
|
+
let result;
|
|
14
|
+
try {
|
|
15
|
+
result = await launch({ ...args, prompt: request.admission.prompt });
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
request.admission.settled({ error: error instanceof Error ? error.message : String(error) });
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
const receipt = result.details;
|
|
22
|
+
request.admission.settled(receipt?.launched && receipt.runId ? { runId: receipt.runId }
|
|
23
|
+
: { error: result.content.find(part => part.type === "text")?.text || "Assignment did not launch." });
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
export const WORKFLOW_ASSIGNMENT = "pi-better-subagents:workflow-assignment";
|
|
4
|
+
export interface WorkflowAssignmentRequest {
|
|
5
|
+
ref: { runId: string; step: string };
|
|
6
|
+
callId: string;
|
|
7
|
+
ctx: ExtensionContext;
|
|
8
|
+
input: Record<string, unknown>;
|
|
9
|
+
/** The workflow owner claims the ready item synchronously before launch. */
|
|
10
|
+
admission?: { prompt: string; settled(outcome: { runId?: string; error?: string }): void };
|
|
11
|
+
error?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Wrap only explicitly workflow-bound launches. The normal spawn path owns all execution permissions. */
|
|
15
|
+
export async function launchWorkflowAssignment<P, R extends { details?: unknown; content: readonly { type: string; text?: string }[] }>(
|
|
16
|
+
pi: ExtensionAPI, ctx: ExtensionContext, callId: string, params: P, launch: (params: P) => Promise<R>,
|
|
17
|
+
): Promise<R> {
|
|
18
|
+
const input = params as Record<string, unknown>;
|
|
19
|
+
if (!input.workflow) return launch(params);
|
|
20
|
+
const request: WorkflowAssignmentRequest = { ref: input.workflow as WorkflowAssignmentRequest["ref"], callId, ctx, input };
|
|
21
|
+
pi.events.emit(WORKFLOW_ASSIGNMENT, request);
|
|
22
|
+
if (!request.admission) throw new Error(request.error ?? "No active workflow authorized this assignment.");
|
|
23
|
+
const { workflow: _workflow, ...args } = input;
|
|
24
|
+
let result: R;
|
|
25
|
+
try {
|
|
26
|
+
result = await launch({ ...args, prompt: request.admission.prompt } as P);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
request.admission.settled({ error: error instanceof Error ? error.message : String(error) });
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
const receipt = result.details as { launched?: boolean; runId?: string } | undefined;
|
|
32
|
+
request.admission.settled(receipt?.launched && receipt.runId ? { runId: receipt.runId }
|
|
33
|
+
: { error: result.content.find(part => part.type === "text")?.text || "Assignment did not launch." });
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
@@ -50,6 +50,7 @@ export class WorkQueryExecutor {
|
|
|
50
50
|
private watchdog?: ReturnType<typeof setInterval>;
|
|
51
51
|
private watchdogCheck?: ReturnType<typeof setImmediate>;
|
|
52
52
|
private lastResponse = performance.now();
|
|
53
|
+
private gracedHeartbeat?: bigint;
|
|
53
54
|
private heartbeat!: BigInt64Array;
|
|
54
55
|
private probe?: Int32Array;
|
|
55
56
|
private workerMetrics: WorkerMetrics = {};
|
|
@@ -88,13 +89,20 @@ export class WorkQueryExecutor {
|
|
|
88
89
|
let resumedAt = previousCheck;
|
|
89
90
|
this.watchdog = setInterval(() => {
|
|
90
91
|
const now = performance.now();
|
|
91
|
-
|
|
92
|
-
if (now - previousCheck > watchdogMs) resumedAt = now;
|
|
92
|
+
const delayed = now - previousCheck > watchdogMs;
|
|
93
93
|
previousCheck = now;
|
|
94
94
|
if (this.closed || this.failure || now - Math.max(this.lastResponse, resumedAt) <= watchdogMs) return;
|
|
95
95
|
// Drain queued worker responses before treating a delayed timer as worker silence.
|
|
96
96
|
this.watchdogCheck ??= setImmediate(() => {
|
|
97
97
|
this.watchdogCheck = undefined;
|
|
98
|
+
// After system sleep, allow a stale heartbeat one interval to advance.
|
|
99
|
+
const tick = Atomics.load(this.heartbeat, 0);
|
|
100
|
+
if (delayed && this.gracedHeartbeat !== tick &&
|
|
101
|
+
(tick === 0n || Number(process.hrtime.bigint() - tick) / 1e6 > watchdogMs)) {
|
|
102
|
+
this.gracedHeartbeat = tick;
|
|
103
|
+
resumedAt = performance.now();
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
98
106
|
this.checkWatchdog();
|
|
99
107
|
});
|
|
100
108
|
this.watchdogCheck.unref();
|
|
@@ -121,6 +129,7 @@ export class WorkQueryExecutor {
|
|
|
121
129
|
}
|
|
122
130
|
|
|
123
131
|
private startWorker() {
|
|
132
|
+
this.gracedHeartbeat = undefined;
|
|
124
133
|
if (this.options.budgetBuffer) {
|
|
125
134
|
// startWorker runs only initially or after the preceding thread exited.
|
|
126
135
|
// A dead generation cannot retain source credits in the shared budget.
|
package/src/version.ts
CHANGED