pi-ui-extend 0.1.59 → 0.1.62

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.
@@ -2,6 +2,7 @@ import { createHash } from "node:crypto";
2
2
  import { readFile } from "node:fs/promises";
3
3
  import { homedir } from "node:os";
4
4
  import { join } from "node:path";
5
+ import { AuthStorage } from "@earendil-works/pi-coding-agent";
5
6
  import { formatCompactProgressBar } from "../../context-progress-bar.js";
6
7
  import { APP_ICONS } from "../icons.js";
7
8
  const OPENAI_USAGE_URL = "https://chatgpt.com/backend-api/wham/usage";
@@ -168,26 +169,25 @@ export function openAIUsageStatusFromResponse(data, modelKey, now = Date.now())
168
169
  };
169
170
  }
170
171
  async function queryOpenAIModelUsage(modelKey) {
171
- const authData = await readOpenAIAuth();
172
+ let authData = await readOpenAIAuth();
172
173
  if (!authData || authData.type !== "oauth" || !authData.access)
173
174
  return undefined;
174
175
  if (isExpired(authData))
175
- return undefined;
176
+ authData = await refreshOpenAICodexAuth();
177
+ if (!authData.access)
178
+ throw new Error("OpenAI Codex OAuth refresh returned no access token");
176
179
  const usage = await fetchOpenAIUsage(authData.access);
177
180
  return openAIUsageStatusFromResponse(usage, modelKey);
178
181
  }
179
182
  async function queryOpenAIAccountUsage(now) {
180
- const authData = await readOpenAIAuth();
183
+ let authData = await readOpenAIAuth();
181
184
  if (!authData || authData.type !== "oauth" || !authData.access)
182
185
  return undefined;
183
- if (isExpired(authData))
184
- return {
185
- account: accountLabelFromOpenAIAuth(authData),
186
- windows: [],
187
- limitReached: false,
188
- error: "OAuth token is expired",
189
- };
190
186
  try {
187
+ if (isExpired(authData))
188
+ authData = await refreshOpenAICodexAuth();
189
+ if (!authData.access)
190
+ throw new Error("OpenAI Codex OAuth refresh returned no access token");
191
191
  const usage = await fetchOpenAIUsage(authData.access);
192
192
  const windows = [usage.rate_limit?.primary_window, usage.rate_limit?.secondary_window]
193
193
  .filter(isRateLimitWindow)
@@ -219,6 +219,22 @@ async function queryOpenAIAccountUsage(now) {
219
219
  };
220
220
  }
221
221
  }
222
+ async function refreshOpenAICodexAuth() {
223
+ // Delegate to pi core so refresh-token rotation is persisted under the same
224
+ // cross-process auth.json lock used by model requests.
225
+ const authStorage = AuthStorage.create(getPiAuthPath());
226
+ const access = await authStorage.getApiKey("openai-codex", { includeFallback: false });
227
+ const credential = authStorage.get("openai-codex");
228
+ if (!access || credential?.type !== "oauth" || !credential.access || isExpired(credential)) {
229
+ throw new Error("OpenAI Codex OAuth token refresh failed");
230
+ }
231
+ return {
232
+ type: "oauth",
233
+ access: credential.access,
234
+ refresh: credential.refresh,
235
+ expires: credential.expires,
236
+ };
237
+ }
222
238
  async function readOpenAIAuth() {
223
239
  const authData = await readOpenCodeAuth();
224
240
  const piAuth = await readPiAuth();
@@ -362,6 +362,22 @@ npm run test:async-subagents-selection-e2e
362
362
  npm run test:e2e
363
363
  ```
364
364
 
365
+ ### Prompt evaluations
366
+
367
+ Prompt evaluations are opt-in because they call a real model. They cover model-facing behavior that deterministic tests cannot prove: tool selection for `todo` and `compress`, async-subagent delegation/lifecycle boundaries, default internal role routing, ultrawork classification, and DCP summary retention. They are intentionally excluded from `npm test`.
368
+
369
+ ```bash
370
+ # Full prompt-eval suite
371
+ npm run test:prompt-evals
372
+
373
+ # Focused suites
374
+ npm run test:prompt-evals:tool-selection
375
+ npm run test:prompt-evals:async
376
+ npm run test:prompt-evals:dcp
377
+ ```
378
+
379
+ The default live model is `zai/glm-5-turbo`. Override it for the whole suite with `PI_TOOLS_SUITE_E2E_MODEL=provider/model`, or use the existing component variables such as `TOOL_SELECTION_E2E_MODEL`, `ASYNC_SUBAGENTS_MODEL`, `ASYNC_SUBAGENTS_ROUTING_E2E_MODEL`, and `DCP_SUMMARY_E2E_MODEL`. The normal deterministic coverage remains `npm test`; run prompt evals after changing tool descriptions, routing/classifier prompts, DCP summary prompts, or the default evaluation model.
380
+
365
381
  Supporting docs and historical standalone README content are kept in `docs/`; third-party license texts are kept in `licenses/`.
366
382
 
367
383
  ## SDK pin
@@ -24,6 +24,10 @@
24
24
  "test": "bun test test",
25
25
  "test:async-subagents-e2e": "ASYNC_SUBAGENTS_E2E=1 ASYNC_SUBAGENTS_DEBUG_LOGS=1 ASYNC_SUBAGENTS_MODEL=zai/glm-5-turbo bun test --concurrent --max-concurrency=30 test/async-subagents",
26
26
  "test:async-subagents-selection-e2e": "ASYNC_SUBAGENTS_SELECTION_E2E=1 ASYNC_SUBAGENTS_MODEL=zai/glm-5-turbo bun test --concurrent --max-concurrency=30 test/async-subagents/selection-e2e.test.ts",
27
+ "test:prompt-evals:tool-selection": "PROMPT_EVAL_E2E=1 bun test --concurrent --max-concurrency=10 test/tool-selection-e2e.test.ts",
28
+ "test:prompt-evals:async": "PROMPT_EVAL_E2E=1 bun test --concurrent --max-concurrency=5 test/async-subagents/selection-e2e.test.ts test/prompt-evals/async-routing-e2e.test.ts",
29
+ "test:prompt-evals:dcp": "PROMPT_EVAL_E2E=1 bun test --concurrent --max-concurrency=5 test/prompt-evals/dcp-summary-e2e.test.ts",
30
+ "test:prompt-evals": "PROMPT_EVAL_E2E=1 bun test --concurrent --max-concurrency=5 test/tool-selection-e2e.test.ts test/async-subagents/selection-e2e.test.ts test/prompt-evals",
27
31
  "bench:locate": "PI_LOCATE_BENCH_ITERATIONS=5 PI_LOCATE_BENCH_FAKE_IDX=0 PI_LOCATE_BENCH_MODEL=zai/glm-5-turbo PI_LOCATE_BENCH_MODES=direct-read-grep,ast-structural,repo-search-hybrid,repo-discovery,subagent-search,unrestricted-suite node test/fixtures/hard-to-find-project/benchmark/run-locate-benchmark.mjs",
28
32
  "bench:locate:analyze": "node test/fixtures/hard-to-find-project/benchmark/analyze-locate-benchmark.mjs",
29
33
  "test:locate-benchmark-e2e": "PI_LOCATE_BENCH_E2E=1 PI_LOCATE_BENCH_MODEL=zai/glm-5-turbo bun test test/locate-benchmark-e2e.test.ts",
@@ -38,9 +42,9 @@
38
42
  "vscode-languageserver-protocol": "^3.17.5"
39
43
  },
40
44
  "peerDependencies": {
41
- "@earendil-works/pi-ai": "0.80.6",
42
- "@earendil-works/pi-coding-agent": "0.80.6",
43
- "@earendil-works/pi-tui": "0.80.6",
45
+ "@earendil-works/pi-ai": "0.80.7",
46
+ "@earendil-works/pi-coding-agent": "0.80.7",
47
+ "@earendil-works/pi-tui": "0.80.7",
44
48
  "typebox": "*"
45
49
  },
46
50
  "devDependencies": {
@@ -124,14 +124,14 @@
124
124
  },
125
125
 
126
126
  "gpt": {
127
- "description": "Prefer enabled GPT-family models: spark/mini for cheap roles, gpt-5.6-sol for heavy roles; fallback cross-provider on quota.",
127
+ "description": "Use the GPT-5.6 family by role: luna for fast tasks, terra for balanced work, and sol for heavy reasoning; fallback cross-provider on quota.",
128
128
  "types": {
129
- "quick": { "model": "openai-codex/gpt-5.3-codex-spark", "fallbackModels": ["zai/glm-4.5-air"], "thinking": "off" },
130
- "scan": { "model": "openai-codex/gpt-5.3-codex-spark", "fallbackModels": ["zai/glm-4.5-air"], "thinking": "off" },
131
- "research": { "model": "openai-codex/gpt-5.4-mini", "fallbackModels": ["zai/glm-5-turbo"], "thinking": "low" },
132
- "docs": { "model": "openai-codex/gpt-5.3-codex-spark", "fallbackModels": ["zai/glm-4.5-air"], "thinking": "low" },
133
- "frontend": { "model": "openai-codex/gpt-5.4-mini", "fallbackModels": ["antigravity/gemini-3-flash-preview", "zai/glm-5.2"], "thinking": "medium" },
134
- "tests": { "model": "openai-codex/gpt-5.4-mini", "fallbackModels": ["zai/glm-5-turbo"], "thinking": "medium" },
129
+ "quick": { "model": "openai-codex/gpt-5.6-luna", "fallbackModels": ["zai/glm-4.5-air"], "thinking": "off" },
130
+ "scan": { "model": "openai-codex/gpt-5.6-luna", "fallbackModels": ["zai/glm-4.5-air"], "thinking": "off" },
131
+ "research": { "model": "openai-codex/gpt-5.6-terra", "fallbackModels": ["zai/glm-5-turbo"], "thinking": "low" },
132
+ "docs": { "model": "openai-codex/gpt-5.6-luna", "fallbackModels": ["zai/glm-4.5-air"], "thinking": "low" },
133
+ "frontend": { "model": "openai-codex/gpt-5.6-terra", "fallbackModels": ["antigravity/gemini-3-flash-preview", "zai/glm-5.2"], "thinking": "medium" },
134
+ "tests": { "model": "openai-codex/gpt-5.6-terra", "fallbackModels": ["zai/glm-5-turbo"], "thinking": "medium" },
135
135
  "review": { "model": "openai-codex/gpt-5.6-sol", "fallbackModels": ["zai/glm-5.2"], "thinking": "high" },
136
136
  "implement": { "model": "openai-codex/gpt-5.6-sol", "fallbackModels": ["zai/glm-5.2"], "thinking": "high" },
137
137
  "deep": { "model": "openai-codex/gpt-5.6-sol", "fallbackModels": ["zai/glm-5.2"], "thinking": "high" }
@@ -116,7 +116,7 @@ export function buildProgrammaticSummary(
116
116
  return lines.join("\n")
117
117
  }
118
118
 
119
- const SUMMARIZER_SYSTEM_PROMPT = `You summarize a slice of a coding agent's conversation so it can replace the raw messages in context. Produce a dense, continuation-focused summary: preserve user intent, decisions made, files/symbols changed or inspected, exact errors still actionable, verification status, and next steps. Drop full logs, repeated output, and incidental detail. Be concise (roughly 4-10 bullets). Output ONLY the summary text, no preamble.`
119
+ const SUMMARIZER_SYSTEM_PROMPT = `You summarize a slice of a coding agent's conversation so it can replace the raw messages in context. Produce a dense, continuation-focused summary: preserve user intent, decisions made, files/symbols changed or inspected, exact errors still actionable, verification status, and next steps. Do not infer, invent, or add facts absent from the source; preserve uncertainty instead of filling gaps. Drop full logs, repeated output, and incidental detail. Be concise (roughly 4-10 bullets). Output ONLY the summary text, no preamble.`
120
120
 
121
121
  /** Outcome of one summarizer-model attempt, surfaced in DCP debug logs. */
122
122
  export interface ModelSummaryAttempt {
@@ -25,7 +25,7 @@ Do not compress active work, still-needed raw context, or material whose exact c
25
25
 
26
26
  DCP reminders: handle critical/high-context reminders promptly and compress any safe high-yield closed slice before more exploration; routine reminders mean compress only if a safe, closed, useful slice exists, otherwise continue the next atomic step and re-check later.
27
27
 
28
- Summaries must preserve only what is needed to continue: user intent and constraints, accepted decisions, files/symbols changed or inspected, actionable errors, verification status, and next steps. Drop incidental transcript detail, duplicate outputs, full logs, long code/JSON/diffs, and prose not needed later; include short literals only when required.
28
+ Summaries must preserve only what is needed to continue: user intent and constraints, accepted decisions, files/symbols changed or inspected, actionable errors, verification status, and next steps. Do not infer, invent, or add facts that are not present in the selected messages. Drop incidental transcript detail, duplicate outputs, full logs, long code/JSON/diffs, and prose not needed later; include short literals only when required.
29
29
  `.trim()
30
30
 
31
31
  /**
@@ -55,6 +55,8 @@ If a \`<dcp-system-reminder>\` is present in context, treat it as a signal to ev
55
55
  THE SUMMARY
56
56
  Your summary must be COMPLETE FOR CONTINUATION, not a transcript rewrite. Preserve only information that will plausibly matter later: user intent, accepted constraints, decisions, files/symbols changed or inspected, exact errors that are still actionable, verification status, and next steps.
57
57
 
58
+ Do not infer, invent, or add facts that are not present in the selected range. If the source is uncertain or incomplete, preserve that uncertainty instead of filling gaps.
59
+
58
60
  If active unfinished work exists, start with \`Active objective\` and \`Next step\`.
59
61
 
60
62
  Default to a compact structured summary (roughly 4-10 bullets for a normal completed work slice). Grow beyond that only when the compressed range contains multiple independent decisions, unresolved blockers, or precise state that is genuinely required to continue.
@@ -155,35 +155,35 @@ export const DEFAULT_PI_TOOLS_SUITE_CONFIG_JSONC = String.raw`{
155
155
  }
156
156
  },
157
157
  "gpt": {
158
- "description": "Prefer enabled GPT-family models: spark/mini for cheap roles, gpt-5.6-sol for heavy roles; fallback cross-provider on quota.",
158
+ "description": "Use the GPT-5.6 family by role: luna for fast tasks, terra for balanced work, and sol for heavy reasoning; fallback cross-provider on quota.",
159
159
  "types": {
160
160
  "quick": {
161
- "model": "openai-codex/gpt-5.3-codex-spark",
161
+ "model": "openai-codex/gpt-5.6-luna",
162
162
  "fallbackModels": ["zai/glm-4.5-air"],
163
163
  "thinking": "off"
164
164
  },
165
165
  "scan": {
166
- "model": "openai-codex/gpt-5.3-codex-spark",
166
+ "model": "openai-codex/gpt-5.6-luna",
167
167
  "fallbackModels": ["zai/glm-4.5-air"],
168
168
  "thinking": "off"
169
169
  },
170
170
  "research": {
171
- "model": "openai-codex/gpt-5.4-mini",
171
+ "model": "openai-codex/gpt-5.6-terra",
172
172
  "fallbackModels": ["zai/glm-5-turbo"],
173
173
  "thinking": "low"
174
174
  },
175
175
  "docs": {
176
- "model": "openai-codex/gpt-5.3-codex-spark",
176
+ "model": "openai-codex/gpt-5.6-luna",
177
177
  "fallbackModels": ["zai/glm-4.5-air"],
178
178
  "thinking": "low"
179
179
  },
180
180
  "frontend": {
181
- "model": "antigravity/gemini-3-flash-preview",
182
- "fallbackModels": ["zai/glm-5.2"],
181
+ "model": "openai-codex/gpt-5.6-terra",
182
+ "fallbackModels": ["antigravity/gemini-3-flash-preview", "zai/glm-5.2"],
183
183
  "thinking": "medium"
184
184
  },
185
185
  "tests": {
186
- "model": "openai-codex/gpt-5.4-mini",
186
+ "model": "openai-codex/gpt-5.6-terra",
187
187
  "fallbackModels": ["zai/glm-5-turbo"],
188
188
  "thinking": "medium"
189
189
  },
@@ -220,6 +220,7 @@ export const TODO_TOOL_DESCRIPTION: ToolDescription = {
220
220
  promptGuidelines: [
221
221
  "Use `todo` for complex work with 3+ steps, explicit user task lists, or new non-trivial requirements. Skip single trivial tasks and purely conversational requests.",
222
222
  "For multi-step implementation/debugging plans, include a final user-facing report todo in the initial plan with acceptance criteria for changed files/behavior, verification results, and remaining manual actions; close it immediately before the final response, never via compression.",
223
+ "When create or batch_create already sets the intended status, do not issue a redundant update with the same status; continue the work instead.",
223
224
  "Resync before continuing when user/new findings change scope, requirements, safety, feasibility, approach, dependencies, or order; update tasks/blockers and defer obsolete work.",
224
225
  "Update todos when starting, finishing, blocking, splitting, abandoning, or materially changing a step; before planned work mark exactly one in_progress with activeForm and complete it only after verification.",
225
226
  "If partial, tests fail, or blocked, keep the task in_progress and add/update a blocker. Never use `clear`, `delete`, or batch deletion to hide unfinished/stale/forgotten todos; delete only on explicit request or creation mistake.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-ui-extend",
3
- "version": "0.1.59",
3
+ "version": "0.1.62",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "bin": {
@@ -65,9 +65,9 @@
65
65
  "prepublishOnly": "npm run check && npm run build:pix && npm run generate-schemas"
66
66
  },
67
67
  "dependencies": {
68
- "@earendil-works/pi-ai": "0.80.6",
69
- "@earendil-works/pi-coding-agent": "0.80.6",
70
- "@earendil-works/pi-tui": "0.80.6",
68
+ "@earendil-works/pi-ai": "0.80.7",
69
+ "@earendil-works/pi-coding-agent": "0.80.7",
70
+ "@earendil-works/pi-tui": "0.80.7",
71
71
  "@mariozechner/clipboard": "^0.3.9",
72
72
  "jsonc-parser": "3.3.1",
73
73
  "typebox": "1.1.38",