gentle-pi 4.6.0 → 4.7.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/README.md +10 -11
- package/assets/agents/gentle-ai-explore.md +1 -0
- package/assets/agents/gentle-ai-verify.md +5 -2
- package/assets/agents/gentle-ai-worker.md +3 -0
- package/assets/agents/jd-fix-agent.md +1 -0
- package/assets/agents/jd-judge-a.md +1 -0
- package/assets/agents/jd-judge-b.md +1 -0
- package/assets/design-canvas/canvas.css +13 -1
- package/assets/design-canvas/canvas.js +11 -2
- package/assets/install-wizard/wizard.js +1 -0
- package/assets/migrations/agent-body-history.json +16 -1
- package/assets/orchestrator-delegation-reference.md +4 -4
- package/assets/orchestrator-delegation.md +1 -1
- package/assets/orchestrator-full-delegation-card.md +65 -0
- package/assets/orchestrator-full-delegation.md +34 -0
- package/assets/orchestrator-memory.md +3 -3
- package/assets/orchestrator-prompts.md +1 -1
- package/assets/orchestrator-skills.md +1 -1
- package/assets/orchestrator-verification.md +7 -5
- package/assets/orchestrator.md +3 -3
- package/bin/gentle-shell.mjs +164 -56
- package/docs/agent-status.md +61 -0
- package/docs/bundled-install.md +7 -5
- package/docs/delegated-verification.md +29 -7
- package/docs/gentle-agents-activity.md +14 -0
- package/docs/gentle-shell.md +54 -16
- package/docs/install-wizard.md +1 -1
- package/docs/permission-modes.md +9 -4
- package/docs/readme-reference.md +75 -30
- package/docs/render-cache-performance.md +11 -1
- package/docs/review-coordinator.md +33 -0
- package/docs/review-request-context.md +19 -0
- package/docs/review-windows-acl.md +18 -0
- package/docs/voice.md +6 -3
- package/docs/yolo-mode.md +5 -5
- package/extensions/ask-user-choice.ts +1 -0
- package/extensions/ask-user-question.ts +1 -0
- package/extensions/child-safety.ts +3 -0
- package/extensions/gentle-agent-status.ts +99 -0
- package/extensions/gentle-agents.ts +326 -34
- package/extensions/gentle-ai.ts +1496 -454
- package/extensions/gentle-shell.ts +293 -63
- package/extensions/gentle-todo.ts +18 -2
- package/extensions/gentle-tps.ts +48 -0
- package/extensions/quiet-tools.ts +38 -8
- package/extensions/skill-registry.ts +175 -18
- package/extensions/startup-banner.ts +30 -3
- package/lib/agent-profile-pin.ts +3 -3
- package/lib/agent-profiles.ts +160 -2
- package/lib/agent-status.ts +105 -0
- package/lib/agents-config.ts +46 -0
- package/lib/agents-history.ts +24 -5
- package/lib/agents-messaging.ts +47 -5
- package/lib/agents-runner.ts +183 -12
- package/lib/auto-permission-runtime.ts +1 -1
- package/lib/bounded-writer-admission.ts +13 -1
- package/lib/card-content-policy.ts +8 -6
- package/lib/command-palette.ts +133 -17
- package/lib/context-backstop.ts +14 -5
- package/lib/destructive-command-guard.ts +48 -4
- package/lib/execution-surface-guard.ts +20 -0
- package/lib/exploration-budget.ts +4 -2
- package/lib/gentle-ai-binary.ts +1 -1
- package/lib/gentle-design.ts +3 -0
- package/lib/gentle-shell-bundled.ts +6 -19
- package/lib/gentle-shell-launcher.ts +43 -8
- package/lib/herdr-activity.ts +14 -2
- package/lib/herdr-busy.ts +45 -0
- package/lib/image-attachments.ts +33 -0
- package/lib/image-disk-cache.ts +137 -0
- package/lib/inprocess-reviewer.ts +270 -140
- package/lib/jobs-view.ts +198 -11
- package/lib/model-routing-authority.ts +22 -4
- package/lib/native-choice-list.ts +20 -2
- package/lib/native-review-cli.ts +96 -19
- package/lib/orchestrator-mode-policy.ts +105 -0
- package/lib/questionnaire/questionnaire-view.ts +105 -12
- package/lib/rdd-mode-control.ts +32 -0
- package/lib/reply-language-anchor.ts +104 -0
- package/lib/review-blocker.ts +92 -0
- package/lib/review-candidate-symlink-scan.ts +136 -0
- package/lib/review-candidate-view-owner.ts +81 -44
- package/lib/review-continuation-registry.ts +99 -0
- package/lib/review-coordinator.ts +163 -0
- package/lib/review-failure-facts.ts +49 -0
- package/lib/review-host-relay.ts +46 -10
- package/lib/review-integration-v2.ts +7 -1
- package/lib/review-relay-phase-timing.ts +45 -0
- package/lib/review-start-context.ts +17 -0
- package/lib/session-profile-freeze.ts +4 -2
- package/lib/shell-bar.ts +140 -58
- package/lib/shell-changes.ts +2 -0
- package/lib/shell-panel.ts +17 -3
- package/lib/shell-sidebar-layout.ts +112 -40
- package/lib/shell-sidebar.ts +7 -0
- package/lib/shell-todo.ts +10 -3
- package/lib/verifier-admission.ts +1 -1
- package/lib/visual-customization-policy.ts +36 -16
- package/lib/visual-customize-view.ts +216 -21
- package/lib/visual-layout-preview.ts +9 -5
- package/lib/visual-profiles.ts +2 -2
- package/lib/windows-session-transport.ts +53 -2
- package/lib/yolo-session-policy.ts +40 -15
- package/package.json +2 -1
- package/runtime/gentle-ai-binary.mjs +1 -1
- package/runtime/gentle-shell-bundled.mjs +6 -19
- package/runtime/gentle-shell-launcher.mjs +42 -7
- package/runtime/native-review-cli.mjs +93 -16
- package/runtime/review-integration-v2.mjs +7 -1
- package/scripts/build-full-delegation-card.mjs +175 -0
- package/scripts/bundled-install.mjs +38 -8
- package/scripts/download-progress.mjs +68 -0
- package/scripts/gentle-ai-installer.mjs +41 -18
- package/scripts/gentle-ai-proxy.mjs +294 -0
- package/scripts/install-gentle-ai.mjs +14 -1
- package/scripts/installer-preflight.mjs +5 -5
- package/scripts/installer-runner.mjs +27 -12
- package/scripts/installer-server.mjs +8 -7
- package/scripts/render-cache-host.mjs +72 -0
- package/scripts/render-cache-performance-worker.mjs +5 -4
- package/scripts/render-cache-performance.mjs +6 -1
- package/scripts/run-test-suite.mjs +40 -28
- package/scripts/verify-package-files.mjs +12 -2
- package/scripts/voice-worker.cjs +32 -6
- package/skills/design/SKILL.md +11 -8
- package/skills/gentle-ai/SKILL.md +2 -2
- package/skills/gentle-ui-design/SKILL.md +46 -0
- package/skills/gentle-ui-design/references/adaptive-interfaces.md +46 -0
- package/skills/gentle-ui-design/references/browse-and-compare.md +62 -0
- package/skills/gentle-ui-design/references/composition-and-feedback.md +56 -0
- package/skills/gentle-ui-design/references/task-and-content.md +60 -0
- package/skills/skill-registry/SKILL.md +4 -2
- package/skills/work-unit-commits/SKILL.md +6 -7
- package/tests/agent-home.test.ts +28 -9
- package/tests/agent-profiles-workflow.test.ts +163 -0
- package/tests/agent-risk-escalation.test.ts +1 -1
- package/tests/agent-status.test.ts +143 -0
- package/tests/agents-config.test.ts +96 -0
- package/tests/agents-history.test.ts +31 -0
- package/tests/agents-jobs-frames.test.ts +93 -0
- package/tests/agents-prompt-lifecycle-runtime.test.ts +376 -0
- package/tests/agents-runner-drain.test.ts +193 -0
- package/tests/agents-runner.test.ts +178 -2
- package/tests/append-system-prompt-route.test.ts +4 -1
- package/tests/ask-user-choice.test.ts +4 -3
- package/tests/ask-user-question.test.ts +97 -0
- package/tests/auto-permission-runtime.test.ts +1 -1
- package/tests/autonomous-guard.test.ts +346 -10
- package/tests/bounded-stop-contract.test.ts +43 -3
- package/tests/bridge-cost.test.ts +19 -4
- package/tests/bundled-install.test.ts +30 -5
- package/tests/card-content-policy.test.ts +3 -3
- package/tests/chained-pr-skill.test.ts +8 -6
- package/tests/child-safety.test.ts +11 -0
- package/tests/codegraph-tools.test.ts +11 -5
- package/tests/command-palette.test.ts +284 -1
- package/tests/delegate-for-reason-contract.test.ts +3 -3
- package/tests/design-canvas-assets.test.ts +185 -2
- package/tests/destructive-command-guard.test.ts +52 -0
- package/tests/download-progress.test.ts +71 -0
- package/tests/execution-surface-guard.test.ts +55 -0
- package/tests/fixtures/primary-session-prompt/gentleman.golden.md +9 -5
- package/tests/fixtures/proxy-tls/proxy.crt +19 -0
- package/tests/fixtures/proxy-tls/proxy.key +28 -0
- package/tests/fixtures/session-profile-v1/gentle-ai-reviewer.ts +89 -0
- package/tests/fixtures/session-profile-v1/replay.ts +53 -6
- package/tests/full-delegation-closure.test.ts +131 -0
- package/tests/full-delegation-notices.test.ts +76 -0
- package/tests/generic-agent-tools.test.ts +3 -3
- package/tests/gentle-agent-status.test.ts +74 -0
- package/tests/gentle-agents-child-jobs.test.ts +237 -0
- package/tests/gentle-agents.test.ts +1070 -12
- package/tests/gentle-ai-binary.test.ts +3 -1
- package/tests/gentle-ai-elapsed-store.test.ts +19 -0
- package/tests/gentle-ai-exploration-budget.test.ts +18 -2
- package/tests/gentle-ai-installer.test.ts +134 -51
- package/tests/gentle-ai-proxy.test.ts +434 -0
- package/tests/gentle-ai.test.ts +113 -38
- package/tests/gentle-design.test.ts +21 -0
- package/tests/gentle-herdr-activity.test.ts +9 -6
- package/tests/gentle-shell-bin.test.ts +123 -0
- package/tests/gentle-shell-bundled.test.ts +207 -31
- package/tests/gentle-shell-launcher.test.ts +77 -10
- package/tests/gentle-shell.test.ts +899 -59
- package/tests/gentle-todo.test.ts +19 -2
- package/tests/gentle-tps.test.ts +123 -0
- package/tests/gentle-ui-design-skill.test.ts +59 -0
- package/tests/herdr-busy.test.ts +59 -0
- package/tests/herdr-task-summary-policy.test.ts +8 -4
- package/tests/image-disk-cache.test.ts +163 -0
- package/tests/independent-recovery-delivery.test.ts +83 -0
- package/tests/inprocess-reviewer.test.ts +176 -4
- package/tests/installer-posix-bootstrap.test.ts +1 -1
- package/tests/installer-preflight.test.ts +5 -4
- package/tests/installer-runner.test.ts +79 -44
- package/tests/installer-server.test.ts +14 -11
- package/tests/jobs-view.test.ts +260 -6
- package/tests/modal-mouse-boundaries.test.ts +136 -0
- package/tests/model-routing-authority.test.ts +178 -2
- package/tests/native-choice-list.test.ts +77 -2
- package/tests/native-review-capability-contract.test.ts +7 -1
- package/tests/native-review-cli.test.ts +269 -1
- package/tests/no-self-pause-contract.test.ts +4 -1
- package/tests/odd-routing-canonical-ratchet.test.ts +3 -3
- package/tests/orchestrator-budget.test.ts +7 -2
- package/tests/orchestrator-delegation-mode.test.ts +153 -0
- package/tests/orchestrator-mode-policy.test.ts +175 -0
- package/tests/orchestrator-prompt-budget.test.ts +3 -1
- package/tests/orchestrator-rdd-ownership.test.ts +2 -2
- package/tests/package-manifest.test.ts +11 -9
- package/tests/permission-allowlist.test.ts +202 -0
- package/tests/pi-update-launcher.test.ts +8 -0
- package/tests/pnpm-workspace-config.test.ts +58 -0
- package/tests/primary-session-prompt.test.ts +13 -0
- package/tests/profile-pin.test.ts +29 -2
- package/tests/profile-tier-footer.test.ts +5 -0
- package/tests/profiles-panel-delegation-mode.test.ts +422 -0
- package/tests/questionnaire-view.test.ts +115 -0
- package/tests/quiet-bash-runtime.test.ts +1 -1
- package/tests/quiet-tool-rendering.test.ts +48 -0
- package/tests/rdd-aware-verification-contract.test.ts +16 -11
- package/tests/rdd-customize.test.ts +287 -0
- package/tests/rdd-mode-cache.test.ts +450 -0
- package/tests/rdd-mode-control.test.ts +407 -0
- package/tests/rdd-mode-scope-regression.test.ts +137 -0
- package/tests/rdd-off-independent-regression.test.ts +69 -0
- package/tests/rdd-status-line.test.ts +18 -0
- package/tests/render-cache-performance.test.ts +171 -2
- package/tests/reply-language-anchor.test.ts +173 -0
- package/tests/review-agent-end-preflight.test.ts +1 -1
- package/tests/review-blocker.test.ts +193 -0
- package/tests/review-candidate-owner-retry.test.ts +1 -1
- package/tests/review-candidate-symlink-scan.test.ts +157 -0
- package/tests/review-candidate-view.test.ts +1 -1
- package/tests/review-candidate-windows-boundary.test.ts +131 -0
- package/tests/review-candidate-windows-probe.test.ts +63 -0
- package/tests/review-committed-restart-ack.test.ts +129 -0
- package/tests/review-continuation-registry.test.ts +76 -0
- package/tests/review-controller-native-routing.test.ts +261 -5
- package/tests/review-controller-workspace-root.test.ts +230 -3
- package/tests/review-controller.test.ts +96 -11
- package/tests/review-coordinator-runtime.test.ts +117 -0
- package/tests/review-coordinator.test.ts +195 -0
- package/tests/review-failure-facts.test.ts +87 -0
- package/tests/review-host-relay-routing.test.ts +258 -4
- package/tests/review-host-relay.test.ts +39 -0
- package/tests/review-integration-v2.test.ts +46 -3
- package/tests/review-json-arguments.test.ts +65 -10
- package/tests/review-last-event-closure.test.ts +68 -0
- package/tests/review-loadout-rdd-off-sdk.test.ts +65 -31
- package/tests/review-owner-identity.test.ts +60 -24
- package/tests/review-relay-phase-timing.test.ts +128 -0
- package/tests/review-relay-transport-agent.test.ts +12 -2
- package/tests/review-reviewer-evidence.test.ts +183 -0
- package/tests/review-risk-assessment.test.ts +74 -3
- package/tests/review-session-standing-permission-controller.test.ts +21 -1
- package/tests/review-start-context.test.ts +19 -0
- package/tests/review-tool-prose-budget.test.ts +121 -0
- package/tests/run-test-suite.test.ts +122 -1
- package/tests/runtime-harness.mjs +4 -1
- package/tests/sensitive-path-tools.test.ts +181 -5
- package/tests/session-profile-append-controller-pi.test.ts +60 -31
- package/tests/session-profile-binding.test.ts +19 -1
- package/tests/session-profile-disk-reader-pi.test.ts +58 -16
- package/tests/session-profile-v1-compat.test.ts +35 -1
- package/tests/shell-bar.test.ts +186 -42
- package/tests/shell-panel.test.ts +50 -22
- package/tests/shell-sidebar-fullscreen.test.ts +5 -5
- package/tests/shell-sidebar-layout.test.ts +294 -23
- package/tests/shell-sidebar-scroll-benchmark.test.ts +1 -1
- package/tests/shell-surface-transparent.test.ts +89 -0
- package/tests/shell-todo.test.ts +12 -0
- package/tests/skill-registry.test.ts +838 -5
- package/tests/startup-banner.test.ts +152 -1
- package/tests/startup-home-repo.test.ts +2 -0
- package/tests/support/review-coordinator-runtime.ts +69 -0
- package/tests/task-size-routing-contract.test.ts +5 -3
- package/tests/verifier-admission.test.ts +49 -0
- package/tests/verify-first-launch-contract.test.ts +78 -3
- package/tests/visual-customization-policy.test.ts +39 -6
- package/tests/visual-customize-view.test.ts +573 -9
- package/tests/visual-layout-preview.test.ts +15 -1
- package/tests/visual-profiles.test.ts +11 -0
- package/tests/voice-worker.test.ts +73 -2
- package/tests/windows-session-transport.test.ts +126 -0
- package/tests/work-continuity-contract.test.ts +28 -0
- package/tests/writer-feature-document-admission.test.ts +92 -0
- package/tests/yolo-customize.test.ts +27 -4
- package/tests/yolo-mode.test.ts +23 -18
- package/tests/yolo-session-policy.test.ts +270 -1
|
@@ -95,7 +95,7 @@ export interface InProcessReviewerRequest {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
export type InProcessReviewerOutcome =
|
|
98
|
-
| { readonly kind: "text"; readonly text: string; readonly reviewerModel: string }
|
|
98
|
+
| { readonly kind: "text"; readonly text: string; readonly reviewerModel: string; readonly evidence?: Record<string, unknown> }
|
|
99
99
|
| { readonly kind: "refused"; readonly code: InProcessReviewerFailureCode; readonly message: string; readonly evidence?: Record<string, unknown> };
|
|
100
100
|
|
|
101
101
|
export interface InProcessReviewerDeps {
|
|
@@ -103,6 +103,8 @@ export interface InProcessReviewerDeps {
|
|
|
103
103
|
readonly complete: typeof completeSimple;
|
|
104
104
|
/** Test seam for the single user message's timestamp; defaults to Date.now. */
|
|
105
105
|
readonly now?: () => number;
|
|
106
|
+
/** Host-only facts, including on thrown auth errors. Never awaited; observer failure is non-authoritative. */
|
|
107
|
+
readonly onEvidence?: (evidence: Record<string, unknown>) => void | Promise<void>;
|
|
106
108
|
}
|
|
107
109
|
|
|
108
110
|
// No existing bound covers the reviewer's completion text: the child this
|
|
@@ -149,7 +151,7 @@ function sanitizeErrorExcerpt(error: unknown): string {
|
|
|
149
151
|
return collapsed.length <= ERROR_EXCERPT_MAX_CHARS ? collapsed : `${collapsed.slice(0, ERROR_EXCERPT_MAX_CHARS - 1)}…`;
|
|
150
152
|
}
|
|
151
153
|
|
|
152
|
-
function refuse(code: InProcessReviewerFailureCode, message: string, evidence?: Record<string, unknown>): InProcessReviewerOutcome {
|
|
154
|
+
function refuse(code: InProcessReviewerFailureCode, message: string, evidence?: Record<string, unknown>): Extract<InProcessReviewerOutcome, { kind: "refused" }> {
|
|
153
155
|
return { kind: "refused", code, message, ...(evidence === undefined ? {} : { evidence }) };
|
|
154
156
|
}
|
|
155
157
|
|
|
@@ -158,7 +160,7 @@ function isTextContent(part: { type?: unknown }): part is TextContent {
|
|
|
158
160
|
}
|
|
159
161
|
|
|
160
162
|
/** Completion diagnostics are facts only; never copy provider text, errors, or payloads. */
|
|
161
|
-
function
|
|
163
|
+
function completionEvidence(model: Model<Api>, assistant: AssistantMessage): Record<string, unknown> {
|
|
162
164
|
const evidence: Record<string, unknown> = { reviewerModel: `${model.provider}/${model.id}`.slice(0, 512) };
|
|
163
165
|
if (["pending", "stop", "length", "toolUse", "error", "aborted", "deferred"].includes(assistant.stopReason)) {
|
|
164
166
|
evidence.stopReason = assistant.stopReason;
|
|
@@ -171,6 +173,17 @@ function emptyOutputEvidence(model: Model<Api>, assistant: AssistantMessage): Re
|
|
|
171
173
|
addCounter(usage, key, assistant.usage?.[key]);
|
|
172
174
|
}
|
|
173
175
|
if (Object.keys(usage).length > 0) evidence.usage = usage;
|
|
176
|
+
// Copy only numbers the completion actually reported. Do not calculate
|
|
177
|
+
// missing totals or confuse SDK-reported cost with verified billing.
|
|
178
|
+
const reportedCost = assistant.usage?.cost;
|
|
179
|
+
const cost: Record<string, number | boolean> = {};
|
|
180
|
+
for (const key of ["input", "output", "cacheRead", "cacheWrite", "total"] as const) {
|
|
181
|
+
const value = reportedCost?.[key];
|
|
182
|
+
if (typeof value === "number" && Number.isFinite(value) && value >= 0) cost[key] = value;
|
|
183
|
+
}
|
|
184
|
+
const totalFromProvider = (reportedCost as unknown as Record<string, unknown> | undefined)?.totalFromProvider;
|
|
185
|
+
if (typeof totalFromProvider === "boolean") cost.totalFromProvider = totalFromProvider;
|
|
186
|
+
if (Object.keys(cost).length > 0) evidence.cost = cost;
|
|
174
187
|
const text = assistant.content.filter(isTextContent);
|
|
175
188
|
const thinking = assistant.content.filter((part) => part.type === "thinking");
|
|
176
189
|
const content: Record<string, number> = {};
|
|
@@ -211,13 +224,70 @@ export function openCodeSessionAttributionHeaders(model: Model<Api>, sessionId:
|
|
|
211
224
|
return { "x-opencode-session": sessionId, "x-opencode-client": "pi" };
|
|
212
225
|
}
|
|
213
226
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
227
|
+
// Own settlement independently of the provider's AbortSignal handling. A timed
|
|
228
|
+
// out provider may continue running; its late fulfillment/rejection is consumed
|
|
229
|
+
// without resuming the reviewer pipeline or authorizing a submission.
|
|
230
|
+
function reviewerDeadline(request: InProcessReviewerRequest) {
|
|
231
|
+
const controller = new AbortController();
|
|
232
|
+
const endsAt = performance.now() + request.timeoutMs;
|
|
233
|
+
const interrupted = Symbol("reviewer interrupted");
|
|
234
|
+
let timedOut = false;
|
|
235
|
+
let refusal: InProcessReviewerOutcome | undefined;
|
|
236
|
+
const failure = (): InProcessReviewerOutcome | undefined => {
|
|
237
|
+
if (refusal !== undefined) return refusal;
|
|
238
|
+
// The deadline wins if already elapsed when cancellation is observed.
|
|
239
|
+
// Otherwise caller cancellation settles immediately and retains ABORTED.
|
|
240
|
+
if (timedOut || performance.now() >= endsAt) {
|
|
241
|
+
refusal = refuse(INPROCESS_REVIEWER_FAILURE.TIMED_OUT, `Reviewer completion for ${request.routingKey} exceeded its ${request.timeoutMs}ms bound.`);
|
|
242
|
+
controller.abort(new DOMException("Reviewer deadline exceeded", "TimeoutError"));
|
|
243
|
+
} else if (request.signal?.aborted) {
|
|
244
|
+
refusal = refuse(INPROCESS_REVIEWER_FAILURE.ABORTED, `Reviewer completion for ${request.routingKey} was aborted by the caller.`);
|
|
245
|
+
controller.abort(request.signal.reason);
|
|
246
|
+
}
|
|
247
|
+
return refusal;
|
|
248
|
+
};
|
|
249
|
+
const onCallerAbort = () => { failure(); };
|
|
250
|
+
request.signal?.addEventListener("abort", onCallerAbort, { once: true });
|
|
251
|
+
const timer = setTimeout(() => { timedOut = true; failure(); }, request.timeoutMs);
|
|
252
|
+
return {
|
|
253
|
+
signal: controller.signal,
|
|
254
|
+
failure,
|
|
255
|
+
wait<T>(start: () => Promise<T>): Promise<T> {
|
|
256
|
+
return new Promise<T>((resolve, reject) => {
|
|
257
|
+
if (failure() !== undefined) { reject(interrupted); return; }
|
|
258
|
+
let settled = false;
|
|
259
|
+
const finish = (action: () => void) => {
|
|
260
|
+
if (settled) return;
|
|
261
|
+
settled = true;
|
|
262
|
+
controller.signal.removeEventListener("abort", onAbort);
|
|
263
|
+
action();
|
|
264
|
+
};
|
|
265
|
+
const onAbort = () => finish(() => reject(interrupted));
|
|
266
|
+
controller.signal.addEventListener("abort", onAbort, { once: true });
|
|
267
|
+
let pending: Promise<T>;
|
|
268
|
+
try { pending = start(); }
|
|
269
|
+
catch (error) { finish(() => reject(error)); return; }
|
|
270
|
+
// Both handlers stay attached after interruption to consume a late
|
|
271
|
+
// provider rejection, but finish can never resume this call twice.
|
|
272
|
+
Promise.resolve(pending).then(
|
|
273
|
+
value => finish(() => failure() === undefined ? resolve(value) : reject(interrupted)),
|
|
274
|
+
error => finish(() => reject(error)),
|
|
275
|
+
);
|
|
276
|
+
});
|
|
277
|
+
},
|
|
278
|
+
dispose() {
|
|
279
|
+
clearTimeout(timer);
|
|
280
|
+
request.signal?.removeEventListener("abort", onCallerAbort);
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
type InProcessReviewerModelResolution =
|
|
286
|
+
| { readonly kind: "resolved"; readonly model: Model<Api>; readonly provider?: InProcessReviewerProvider; readonly providerId: string }
|
|
287
|
+
| Extract<InProcessReviewerOutcome, { kind: "refused" }>;
|
|
288
|
+
|
|
289
|
+
/** Resolve only caller-owned model routing; no authentication or completion. */
|
|
290
|
+
export function resolveInProcessReviewerModel(request: Pick<InProcessReviewerRequest, "selection" | "routingKey">, registry: InProcessReviewerRegistry): InProcessReviewerModelResolution {
|
|
221
291
|
const parsed = parseSelection(request.selection);
|
|
222
292
|
if (parsed === undefined) {
|
|
223
293
|
return refuse(
|
|
@@ -226,7 +296,7 @@ export async function runInProcessReviewer(request: InProcessReviewerRequest, de
|
|
|
226
296
|
);
|
|
227
297
|
}
|
|
228
298
|
|
|
229
|
-
const model =
|
|
299
|
+
const model = registry.find(parsed.provider, parsed.modelId);
|
|
230
300
|
if (model === undefined) {
|
|
231
301
|
return refuse(
|
|
232
302
|
INPROCESS_REVIEWER_FAILURE.MODEL_NOT_FOUND,
|
|
@@ -252,148 +322,208 @@ export async function runInProcessReviewer(request: InProcessReviewerRequest, de
|
|
|
252
322
|
// construction. Keying on the returned field instead would make that
|
|
253
323
|
// guarantee depend on every provider's `getModels()` echoing its own id,
|
|
254
324
|
// which a native or OAuth-modified extension provider is free not to do.
|
|
255
|
-
const provider =
|
|
256
|
-
if (
|
|
325
|
+
const provider = registry.getProvider?.(parsed.provider);
|
|
326
|
+
if (registry.getProvider !== undefined && provider === undefined) {
|
|
327
|
+
const evidence: Record<string, unknown> = { provider: parsed.provider, api: model.api };
|
|
328
|
+
// Preserve already resolved identity when configuration refuses before auth.
|
|
329
|
+
if (typeof model.provider === "string" && typeof model.id === "string") {
|
|
330
|
+
evidence.reviewerModel = `${model.provider}/${model.id}`.slice(0, 512);
|
|
331
|
+
evidence.provider = model.provider.slice(0, 256);
|
|
332
|
+
}
|
|
257
333
|
return refuse(
|
|
258
334
|
INPROCESS_REVIEWER_FAILURE.MODEL_NOT_FOUND,
|
|
259
335
|
`The model registry resolved ${JSON.stringify(request.selection)} for ${request.routingKey} but owns no provider for ${JSON.stringify(parsed.provider)}; reassign ${request.routingKey} to a model whose provider the interactive pi can actually dispatch.`,
|
|
260
|
-
|
|
261
|
-
);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
const auth = await deps.registry.getApiKeyAndHeaders(model);
|
|
265
|
-
// Negation narrowing (`!auth.ok`) does not eliminate the `ok: true` arm of
|
|
266
|
-
// this discriminated union under this project's `strict: false` tsconfig;
|
|
267
|
-
// an explicit `=== false` comparison narrows correctly in both directions.
|
|
268
|
-
if (auth.ok === false) {
|
|
269
|
-
return refuse(
|
|
270
|
-
INPROCESS_REVIEWER_FAILURE.AUTH_UNAVAILABLE,
|
|
271
|
-
`No credentials available for provider ${JSON.stringify(parsed.provider)} (used by ${request.routingKey}): ${auth.error}`,
|
|
272
|
-
);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
const reasoning = resolveReasoning(request.thinking, model);
|
|
276
|
-
if (reasoning.ok === false) {
|
|
277
|
-
return refuse(
|
|
278
|
-
INPROCESS_REVIEWER_FAILURE.THINKING_INVALID,
|
|
279
|
-
`Unknown thinking level ${JSON.stringify(request.thinking)} for ${request.routingKey}; use one of off, minimal, low, medium, high, xhigh, max.`,
|
|
336
|
+
evidence,
|
|
280
337
|
);
|
|
281
338
|
}
|
|
339
|
+
return { kind: "resolved", model, ...(provider === undefined ? {} : { provider }), providerId: parsed.provider };
|
|
340
|
+
}
|
|
282
341
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
342
|
+
/**
|
|
343
|
+
* Runs one reviewer completion in-process: resolve the model, authenticate,
|
|
344
|
+
* map the routing thinking label, and complete exactly one frozen prompt as
|
|
345
|
+
* a single user message. Never retries, never falls back to another model,
|
|
346
|
+
* never reads process.env — every seam is injected through `deps`.
|
|
347
|
+
*/
|
|
348
|
+
export async function runInProcessReviewer(request: InProcessReviewerRequest, deps: InProcessReviewerDeps): Promise<InProcessReviewerOutcome> {
|
|
349
|
+
const began = performance.now();
|
|
350
|
+
let phase: "configuration" | "auth" | "completion" = "configuration";
|
|
351
|
+
let resolvedModel: Model<Api> | undefined, resolvedAssistant: AssistantMessage | undefined;
|
|
352
|
+
let authStarted: number | undefined, completionStarted: number | undefined;
|
|
353
|
+
let authDurationMs: number | undefined, completionDurationMs: number | undefined;
|
|
354
|
+
let finalEvidence: Record<string, unknown> | undefined;
|
|
355
|
+
/** Capture allowlisted facts at one instant, including unfinished phase durations. */
|
|
356
|
+
const snapshot = (): Record<string, unknown> => {
|
|
357
|
+
const evidence: Record<string, unknown> = { phase };
|
|
358
|
+
/** Omit unavailable or invalid measurements rather than inventing a duration. */
|
|
359
|
+
const duration = (key: string, value: number | undefined) => {
|
|
360
|
+
if (typeof value === "number" && Number.isFinite(value) && value >= 0) evidence[key] = value;
|
|
361
|
+
};
|
|
362
|
+
const now = performance.now();
|
|
363
|
+
duration("durationMs", now - began);
|
|
364
|
+
duration("authDurationMs", authDurationMs ?? (authStarted === undefined ? undefined : now - authStarted));
|
|
365
|
+
duration("completionDurationMs", completionDurationMs ?? (completionStarted === undefined ? undefined : now - completionStarted));
|
|
366
|
+
if (resolvedModel !== undefined) {
|
|
367
|
+
if (typeof resolvedModel.provider === "string" && typeof resolvedModel.id === "string") {
|
|
368
|
+
evidence.reviewerModel = `${resolvedModel.provider}/${resolvedModel.id}`.slice(0, 512);
|
|
369
|
+
evidence.provider = resolvedModel.provider.slice(0, 256);
|
|
370
|
+
}
|
|
371
|
+
// Diagnostics never change an otherwise valid completion or refusal.
|
|
372
|
+
try { if (resolvedAssistant !== undefined) Object.assign(evidence, completionEvidence(resolvedModel, resolvedAssistant)); } catch { /* malformed diagnostic metadata is unavailable */ }
|
|
373
|
+
}
|
|
374
|
+
return evidence;
|
|
309
375
|
};
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
// `options.sessionId` and otherwise fall back to something coarser (for
|
|
315
|
-
// example the worktree), which would merge every reviewer completion into
|
|
316
|
-
// one growing conversation. A fresh id per completion keeps each review
|
|
317
|
-
// isolated. It is deliberately not `request.sessionId`: that is the parent
|
|
318
|
-
// session's id and would merge reviewer calls into the parent's conversation.
|
|
319
|
-
sessionId: `review-${request.routingKey}-${randomUUID()}`,
|
|
320
|
-
...(auth.apiKey === undefined ? {} : { apiKey: auth.apiKey }),
|
|
321
|
-
...(auth.env === undefined ? {} : { env: auth.env }),
|
|
322
|
-
...(auth.headers === undefined && attributionHeaders === undefined ? {} : { headers: attributionHeaders === undefined ? auth.headers : { ...attributionHeaders, ...auth.headers } }),
|
|
323
|
-
...(reasoning.reasoning === undefined ? {} : { reasoning: reasoning.reasoning }),
|
|
324
|
-
...(request.transport === undefined ? {} : { transport: request.transport }),
|
|
325
|
-
...(request.tier !== undefined && supportsOpenAIFast(requestModel)
|
|
326
|
-
? { onPayload: (payload: unknown) => applyOpenAITier(payload, request.tier, requestModel) }
|
|
327
|
-
: {}),
|
|
376
|
+
/** Freeze the final evidence before phase cleanup or late provider settlement. */
|
|
377
|
+
const finish = (outcome: InProcessReviewerOutcome): InProcessReviewerOutcome => {
|
|
378
|
+
finalEvidence = { ...outcome.evidence, ...snapshot() };
|
|
379
|
+
return { ...outcome, evidence: finalEvidence };
|
|
328
380
|
};
|
|
381
|
+
try {
|
|
382
|
+
const resolved = resolveInProcessReviewerModel(request, deps.registry);
|
|
383
|
+
if (resolved.kind === "refused") return finish(resolved);
|
|
384
|
+
const { model, provider, providerId } = resolved;
|
|
385
|
+
resolvedModel = model;
|
|
386
|
+
|
|
387
|
+
// Authentication and completion share one monotonic host deadline. Do not
|
|
388
|
+
// restart its budget after auth or rely on a provider to settle on abort.
|
|
389
|
+
const deadline = reviewerDeadline(request);
|
|
390
|
+
try {
|
|
391
|
+
let auth: Awaited<ReturnType<InProcessReviewerRegistry["getApiKeyAndHeaders"]>>;
|
|
392
|
+
try { auth = await deadline.wait(() => {
|
|
393
|
+
phase = "auth"; authStarted = performance.now();
|
|
394
|
+
return deps.registry.getApiKeyAndHeaders(model);
|
|
395
|
+
}); }
|
|
396
|
+
catch (error) {
|
|
397
|
+
const stopped = deadline.failure();
|
|
398
|
+
if (stopped !== undefined) return finish(stopped);
|
|
399
|
+
throw error;
|
|
400
|
+
}
|
|
401
|
+
finally { if (authStarted !== undefined) authDurationMs = performance.now() - authStarted; }
|
|
402
|
+
// Negation narrowing (`!auth.ok`) does not eliminate the `ok: true` arm of
|
|
403
|
+
// this discriminated union under this project's `strict: false` tsconfig;
|
|
404
|
+
// an explicit `=== false` comparison narrows correctly in both directions.
|
|
405
|
+
if (auth.ok === false) {
|
|
406
|
+
return finish(refuse(
|
|
407
|
+
INPROCESS_REVIEWER_FAILURE.AUTH_UNAVAILABLE,
|
|
408
|
+
`No credentials available for provider ${JSON.stringify(providerId)} (used by ${request.routingKey}): ${auth.error}`,
|
|
409
|
+
));
|
|
410
|
+
}
|
|
329
411
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
return refuse(INPROCESS_REVIEWER_FAILURE.TIMED_OUT, `Reviewer completion for ${request.routingKey} exceeded its ${request.timeoutMs}ms bound.`);
|
|
339
|
-
}
|
|
340
|
-
if (request.signal?.aborted === true) {
|
|
341
|
-
return refuse(INPROCESS_REVIEWER_FAILURE.ABORTED, `Reviewer completion for ${request.routingKey} was aborted by the caller.`);
|
|
342
|
-
}
|
|
343
|
-
return undefined;
|
|
344
|
-
};
|
|
412
|
+
phase = "configuration";
|
|
413
|
+
const reasoning = resolveReasoning(request.thinking, model);
|
|
414
|
+
if (reasoning.ok === false) {
|
|
415
|
+
return finish(refuse(
|
|
416
|
+
INPROCESS_REVIEWER_FAILURE.THINKING_INVALID,
|
|
417
|
+
`Unknown thinking level ${JSON.stringify(request.thinking)} for ${request.routingKey}; use one of off, minimal, low, medium, high, xhigh, max.`,
|
|
418
|
+
));
|
|
419
|
+
}
|
|
345
420
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
421
|
+
// OAuth resolution may supply an account-specific endpoint alongside the
|
|
422
|
+
// exchanged API key. Match ModelRuntime.prepareRequest: apply that endpoint
|
|
423
|
+
// to a request-local copy, never mutate the shared registry model.
|
|
424
|
+
const requestModel = auth.baseUrl ? { ...model, baseUrl: auth.baseUrl } : model;
|
|
425
|
+
|
|
426
|
+
// Extension side-calls bypass pi's main agent loop, which is where OpenCode
|
|
427
|
+
// attribution headers are otherwise added. Use the effective request model
|
|
428
|
+
// and place attribution defaults beneath the registry's own auth headers,
|
|
429
|
+
// matching pi's core merge order for explicit header sources.
|
|
430
|
+
const attributionHeaders = openCodeSessionAttributionHeaders(requestModel, request.sessionId);
|
|
431
|
+
|
|
432
|
+
const context: Context = {
|
|
433
|
+
messages: [
|
|
434
|
+
{
|
|
435
|
+
role: "user",
|
|
436
|
+
content: [{ type: "text", text: request.prompt.toString("utf8") }],
|
|
437
|
+
timestamp: (deps.now ?? Date.now)(),
|
|
438
|
+
},
|
|
439
|
+
],
|
|
440
|
+
};
|
|
441
|
+
const options: SimpleStreamOptions = {
|
|
442
|
+
signal: deadline.signal,
|
|
443
|
+
// Preserve the provider's configured transport budget. The host's
|
|
444
|
+
// earlier deadline still includes auth and cannot be extended by it.
|
|
445
|
+
timeoutMs: request.timeoutMs,
|
|
446
|
+
// Providers that keep server-side conversation state key it on
|
|
447
|
+
// `options.sessionId` and otherwise fall back to something coarser (for
|
|
448
|
+
// example the worktree), which would merge every reviewer completion into
|
|
449
|
+
// one growing conversation. A fresh id per completion keeps each review
|
|
450
|
+
// isolated. It is deliberately not `request.sessionId`: that is the parent
|
|
451
|
+
// session's id and would merge reviewer calls into the parent's conversation.
|
|
452
|
+
sessionId: `review-${request.routingKey}-${randomUUID()}`,
|
|
453
|
+
...(auth.apiKey === undefined ? {} : { apiKey: auth.apiKey }),
|
|
454
|
+
...(auth.env === undefined ? {} : { env: auth.env }),
|
|
455
|
+
...(auth.headers === undefined && attributionHeaders === undefined ? {} : { headers: attributionHeaders === undefined ? auth.headers : { ...attributionHeaders, ...auth.headers } }),
|
|
456
|
+
...(reasoning.reasoning === undefined ? {} : { reasoning: reasoning.reasoning }),
|
|
457
|
+
...(request.transport === undefined ? {} : { transport: request.transport }),
|
|
458
|
+
...(request.tier !== undefined && supportsOpenAIFast(requestModel)
|
|
459
|
+
? { onPayload: (payload: unknown) => applyOpenAITier(payload, request.tier, requestModel) }
|
|
460
|
+
: {}),
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
// `SimpleStreamOptions` is identical on both paths; only the return shape
|
|
464
|
+
// differs (an event stream versus a promise), hence `.result()` — which is
|
|
465
|
+
// exactly what pi-ai's own compat layer does with the same stream.
|
|
466
|
+
let assistant: AssistantMessage;
|
|
467
|
+
try {
|
|
468
|
+
assistant = await deadline.wait(() => {
|
|
469
|
+
phase = "completion"; completionStarted = performance.now();
|
|
470
|
+
return provider === undefined ? deps.complete(requestModel, context, options) : provider.streamSimple(requestModel, context, options).result();
|
|
471
|
+
});
|
|
472
|
+
resolvedAssistant = assistant;
|
|
473
|
+
} catch (error) {
|
|
474
|
+
return finish(deadline.failure() ?? refuse(INPROCESS_REVIEWER_FAILURE.PROVIDER_FAILED, `Reviewer completion failed for ${request.routingKey}: ${sanitizeErrorExcerpt(error)}`));
|
|
475
|
+
}
|
|
355
476
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
477
|
+
finally { if (completionStarted !== undefined) completionDurationMs = performance.now() - completionStarted; }
|
|
478
|
+
|
|
479
|
+
const resolvedAbort = deadline.failure();
|
|
480
|
+
if (resolvedAbort !== undefined) return finish(resolvedAbort);
|
|
481
|
+
if (assistant.stopReason === "aborted") {
|
|
482
|
+
// No signal of ours fired, so the provider cut the completion on its
|
|
483
|
+
// own: that is a provider failure, and its partial text is not a review.
|
|
484
|
+
return finish(refuse(
|
|
485
|
+
INPROCESS_REVIEWER_FAILURE.PROVIDER_FAILED,
|
|
486
|
+
`Reviewer completion failed for ${request.routingKey}: the provider reported an aborted completion (${assistant.errorMessage ?? "no provider message"}).`,
|
|
487
|
+
));
|
|
488
|
+
}
|
|
366
489
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
490
|
+
if (assistant.stopReason === "error") {
|
|
491
|
+
return finish(refuse(
|
|
492
|
+
INPROCESS_REVIEWER_FAILURE.PROVIDER_FAILED,
|
|
493
|
+
`Reviewer completion failed for ${request.routingKey}: ${assistant.errorMessage ?? "unknown provider error"}`,
|
|
494
|
+
));
|
|
495
|
+
}
|
|
496
|
+
if (assistant.content.some((part) => part.type === "toolCall")) {
|
|
497
|
+
return finish(refuse(
|
|
498
|
+
INPROCESS_REVIEWER_FAILURE.TOOL_CALL_ATTEMPTED,
|
|
499
|
+
`Reviewer attempted a tool call for ${request.routingKey}; the in-process reviewer completion must answer in text only.`,
|
|
500
|
+
));
|
|
501
|
+
}
|
|
379
502
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
503
|
+
const text = assistant.content.filter(isTextContent).map((part) => part.text).join("");
|
|
504
|
+
if (text.length === 0) {
|
|
505
|
+
const stopReason = ["pending", "stop", "length", "toolUse", "error", "aborted", "deferred"].includes(assistant.stopReason) ? assistant.stopReason : undefined;
|
|
506
|
+
return finish(refuse(
|
|
507
|
+
INPROCESS_REVIEWER_FAILURE.EMPTY_OUTPUT,
|
|
508
|
+
`Reviewer produced no text for ${request.routingKey} (stopReason: ${stopReason ?? "unknown"}).`,
|
|
509
|
+
));
|
|
510
|
+
}
|
|
389
511
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
512
|
+
const textBytes = Buffer.byteLength(text, "utf8");
|
|
513
|
+
if (textBytes > INPROCESS_REVIEWER_OUTPUT_MAX_BYTES) {
|
|
514
|
+
return finish(refuse(
|
|
515
|
+
INPROCESS_REVIEWER_FAILURE.OUTPUT_TOO_LARGE,
|
|
516
|
+
`Reviewer output for ${request.routingKey} exceeds the ${INPROCESS_REVIEWER_OUTPUT_MAX_BYTES}-byte bound (received ${textBytes} bytes).`,
|
|
517
|
+
));
|
|
518
|
+
}
|
|
397
519
|
|
|
398
|
-
|
|
520
|
+
return finish({ kind: "text", text, reviewerModel: `${model.provider}/${model.id}` });
|
|
521
|
+
} finally { deadline.dispose(); }
|
|
522
|
+
|
|
523
|
+
} finally {
|
|
524
|
+
try {
|
|
525
|
+
const observer = deps.onEvidence?.(structuredClone(finalEvidence ?? snapshot()));
|
|
526
|
+
if (observer !== undefined) void Promise.resolve(observer).catch(() => {});
|
|
527
|
+
} catch { /* Host diagnostics never affect classification or settlement. */ }
|
|
528
|
+
}
|
|
399
529
|
}
|