@oh-my-pi/pi-coding-agent 17.0.0 → 17.0.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.
Files changed (101) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/dist/cli.js +3305 -3302
  3. package/dist/types/advisor/advise-tool.d.ts +5 -2
  4. package/dist/types/cli-commands.d.ts +14 -1
  5. package/dist/types/config/model-registry.d.ts +4 -0
  6. package/dist/types/config/models-config-schema.d.ts +10 -0
  7. package/dist/types/config/models-config.d.ts +6 -0
  8. package/dist/types/config/settings-schema.d.ts +1 -1
  9. package/dist/types/discovery/substitute-plugin-root.d.ts +20 -7
  10. package/dist/types/internal-urls/agent-protocol.d.ts +1 -0
  11. package/dist/types/lib/xai-http.d.ts +11 -0
  12. package/dist/types/modes/acp/acp-agent.d.ts +3 -0
  13. package/dist/types/modes/acp/acp-mode.d.ts +6 -2
  14. package/dist/types/modes/components/assistant-message.d.ts +2 -0
  15. package/dist/types/modes/components/custom-editor-plugin-ctor.test.d.ts +1 -0
  16. package/dist/types/modes/components/custom-editor.d.ts +23 -1
  17. package/dist/types/modes/components/hook-editor.d.ts +9 -2
  18. package/dist/types/modes/components/login-dialog.test.d.ts +1 -0
  19. package/dist/types/modes/components/session-selector.d.ts +2 -0
  20. package/dist/types/modes/components/tool-execution.d.ts +8 -1
  21. package/dist/types/modes/components/tool-execution.test.d.ts +1 -0
  22. package/dist/types/modes/interactive-mode.d.ts +6 -0
  23. package/dist/types/modes/noninteractive-dispose.test.d.ts +1 -0
  24. package/dist/types/modes/types.d.ts +10 -0
  25. package/dist/types/modes/utils/transcript-render-helpers.d.ts +2 -2
  26. package/dist/types/session/agent-session.d.ts +9 -1
  27. package/dist/types/session/streaming-output.d.ts +2 -0
  28. package/dist/types/slash-commands/types.d.ts +4 -4
  29. package/dist/types/system-prompt.d.ts +1 -1
  30. package/dist/types/tools/browser/registry.d.ts +7 -3
  31. package/dist/types/tools/browser/tab-supervisor.d.ts +2 -0
  32. package/dist/types/tools/index.d.ts +3 -1
  33. package/dist/types/tools/manage-skill.d.ts +2 -0
  34. package/dist/types/web/search/index.d.ts +2 -0
  35. package/dist/types/web/search/providers/base.d.ts +3 -0
  36. package/package.json +12 -12
  37. package/src/advisor/__tests__/advisor.test.ts +22 -12
  38. package/src/advisor/advise-tool.ts +7 -3
  39. package/src/cli/bench-cli.ts +4 -1
  40. package/src/cli/grep-cli.ts +2 -1
  41. package/src/cli-commands.ts +57 -23
  42. package/src/config/model-registry.ts +9 -0
  43. package/src/config/model-resolver.ts +43 -5
  44. package/src/config/models-config-schema.ts +1 -0
  45. package/src/config/settings-schema.ts +2 -1
  46. package/src/discovery/codex.ts +14 -4
  47. package/src/discovery/substitute-plugin-root.ts +23 -7
  48. package/src/export/html/template.js +2 -0
  49. package/src/internal-urls/__tests__/agent-protocol-nested.test.ts +73 -0
  50. package/src/internal-urls/agent-protocol.ts +73 -39
  51. package/src/lib/xai-http.ts +28 -2
  52. package/src/modes/acp/acp-agent.ts +28 -9
  53. package/src/modes/acp/acp-event-mapper.ts +8 -0
  54. package/src/modes/acp/acp-mode.ts +18 -4
  55. package/src/modes/components/assistant-message.ts +35 -14
  56. package/src/modes/components/chat-transcript-builder.ts +2 -0
  57. package/src/modes/components/custom-editor-plugin-ctor.test.ts +36 -0
  58. package/src/modes/components/custom-editor.ts +62 -1
  59. package/src/modes/components/hook-editor.ts +17 -2
  60. package/src/modes/components/login-dialog.test.ts +56 -0
  61. package/src/modes/components/login-dialog.ts +7 -3
  62. package/src/modes/components/plan-review-overlay.ts +51 -10
  63. package/src/modes/components/session-selector.ts +6 -0
  64. package/src/modes/components/status-line/component.ts +2 -4
  65. package/src/modes/components/tool-execution.test.ts +101 -0
  66. package/src/modes/components/tool-execution.ts +117 -9
  67. package/src/modes/components/transcript-container.ts +30 -2
  68. package/src/modes/controllers/command-controller-shared.ts +1 -1
  69. package/src/modes/controllers/command-controller.ts +1 -1
  70. package/src/modes/controllers/event-controller.ts +1 -0
  71. package/src/modes/controllers/selector-controller.ts +19 -17
  72. package/src/modes/interactive-mode.ts +66 -11
  73. package/src/modes/noninteractive-dispose.test.ts +60 -0
  74. package/src/modes/print-mode.ts +8 -3
  75. package/src/modes/rpc/rpc-mode.ts +12 -3
  76. package/src/modes/theme/theme.ts +2 -2
  77. package/src/modes/types.ts +10 -0
  78. package/src/modes/utils/interactive-context-helpers.ts +3 -1
  79. package/src/modes/utils/transcript-render-helpers.ts +3 -2
  80. package/src/prompts/system/system-prompt.md +1 -1
  81. package/src/sdk.ts +6 -2
  82. package/src/session/agent-session.ts +79 -34
  83. package/src/session/session-listing.ts +6 -5
  84. package/src/session/session-loader.ts +9 -0
  85. package/src/session/session-persistence.ts +11 -0
  86. package/src/session/streaming-output.ts +3 -1
  87. package/src/slash-commands/builtin-registry.ts +2 -0
  88. package/src/slash-commands/types.ts +4 -4
  89. package/src/system-prompt.ts +2 -2
  90. package/src/tools/browser/registry.ts +9 -2
  91. package/src/tools/browser/tab-supervisor.ts +65 -10
  92. package/src/tools/browser.ts +4 -3
  93. package/src/tools/eval.ts +3 -0
  94. package/src/tools/image-gen.ts +561 -512
  95. package/src/tools/index.ts +3 -1
  96. package/src/tools/manage-skill.ts +5 -3
  97. package/src/tools/output-meta.ts +7 -0
  98. package/src/tools/path-utils.ts +8 -5
  99. package/src/web/search/index.ts +21 -6
  100. package/src/web/search/providers/base.ts +3 -0
  101. package/src/web/search/providers/xai.ts +40 -9
@@ -160,7 +160,9 @@ export interface ToolSession {
160
160
  /** Pre-loaded workspace tree (forwarded to subagents to skip re-scanning) */
161
161
  workspaceTree?: WorkspaceTree;
162
162
  /** Pre-loaded skills */
163
- skills?: Skill[];
163
+ skills?: readonly Skill[];
164
+ /** Rediscover live session skills after a tool mutates their backing files. */
165
+ refreshSkills?: () => Promise<void>;
164
166
  /** Pre-loaded prompt templates */
165
167
  promptTemplates?: PromptTemplate[];
166
168
  /** Pre-loaded rules (forwarded to subagents to skip re-discovery). */
@@ -45,16 +45,17 @@ export class ManageSkillTool implements AgentTool<typeof manageSkillSchema> {
45
45
  readonly loadMode = "essential" as const;
46
46
  readonly summary = "Create, update, or delete an isolated managed skill";
47
47
 
48
- // No session state needed: createIf reads settings; writes target the
49
- // home-based managed-skills dir directly.
48
+ constructor(private readonly refreshSkills?: () => Promise<void>) {}
49
+
50
50
  static createIf(session: ToolSession): ManageSkillTool | null {
51
51
  if (!session.settings.get("autolearn.enabled")) return null;
52
- return new ManageSkillTool();
52
+ return new ManageSkillTool(session.refreshSkills);
53
53
  }
54
54
 
55
55
  async execute(_id: string, params: ManageSkillParams): Promise<AgentToolResult> {
56
56
  if (params.action === "delete") {
57
57
  await deleteManagedSkill(params.name);
58
+ await this.refreshSkills?.();
58
59
  return {
59
60
  content: [{ type: "text", text: `Deleted managed skill "${params.name}".` }],
60
61
  details: { action: "delete", name: params.name },
@@ -90,6 +91,7 @@ export class ManageSkillTool implements AgentTool<typeof manageSkillSchema> {
90
91
  description: params.description,
91
92
  body: params.body,
92
93
  });
94
+ await this.refreshSkills?.();
93
95
  const relativePath = path.relative(getManagedSkillsDir(), skillPath);
94
96
  const verb = params.action === "create" ? "Created" : "Updated";
95
97
  return {
@@ -191,6 +191,13 @@ export class OutputMetaBuilder {
191
191
 
192
192
  /** Add truncation info from OutputSummary. No-op if not truncated. */
193
193
  truncationFromSummary(summary: OutputSummary, options: TruncationSummaryOptions): this {
194
+ // A per-line column cap only trims individual lines (with a `…` marker);
195
+ // it is not a window/byte truncation, so surface it as its own limit
196
+ // notice rather than a "Showing lines X-Y … limit" range. This runs even
197
+ // when the output is otherwise complete (`truncated === false`).
198
+ if (summary.columnMax != null && summary.columnMax > 0 && (summary.columnTruncatedLines ?? 0) > 0) {
199
+ this.columnTruncated(summary.columnMax);
200
+ }
194
201
  if (!summary.truncated) return this;
195
202
 
196
203
  const { direction, startLine = 1, totalFileLines } = options;
@@ -148,11 +148,14 @@ export function expandTilde(filePath: string, home?: string): string {
148
148
 
149
149
  export function expandPath(filePath: string): string {
150
150
  // Some models intermittently prefix an otherwise-valid path with a stray
151
- // `:` (e.g. `:/abs/path`, `:../rel`). No real path starts with `:` and it
152
- // never begins a selector against an absolute/relative path, so strip it
153
- // before resolution mirroring the `@`-prefix normalization above and the
154
- // implicit stripping `write` already tolerates (issue #5508).
155
- const deColoned = /^:(?=[/~]|\.\.?\/)/.test(filePath) ? filePath.slice(1) : filePath;
151
+ // `:` (e.g. `:/abs/path`, `:../rel`, or the Windows forms `:C:\repo\file`
152
+ // and `:.\src`). No real path starts with `:` and it never begins a
153
+ // selector against an absolute/relative path, so strip it before
154
+ // resolution mirroring the `@`-prefix normalization above and the
155
+ // implicit stripping `write` already tolerates (issues #5508, #5624). The
156
+ // lookahead admits POSIX (`/`, `~`, `./`, `../`) and Windows (`\`, `.\`,
157
+ // `..\`, drive-letter `C:`) path shapes.
158
+ const deColoned = /^:(?=[/\\~]|\.\.?[/\\]|[A-Za-z]:)/.test(filePath) ? filePath.slice(1) : filePath;
156
159
  const normalized = stripWindowsExtendedLengthPathPrefix(
157
160
  stripFileUrl(normalizeUnicodeSpaces(normalizeAtPrefix(deColoned))),
158
161
  );
@@ -8,6 +8,7 @@ import type { AgentTool, AgentToolContext, AgentToolResult, AgentToolUpdateCallb
8
8
  import type { AuthStorage } from "@oh-my-pi/pi-ai";
9
9
  import { prompt } from "@oh-my-pi/pi-utils";
10
10
  import { type } from "arktype";
11
+ import { ModelRegistry } from "../../config/model-registry";
11
12
  import { settings } from "../../config/settings";
12
13
  import type { CustomTool, CustomToolContext, RenderResultOptions } from "../../extensibility/custom-tools/types";
13
14
  import type { Theme } from "../../modes/theme/theme";
@@ -118,6 +119,7 @@ function hasRenderableSearchContent(response: SearchResponse): boolean {
118
119
 
119
120
  interface ExecuteSearchOptions {
120
121
  authStorage: AuthStorage;
122
+ modelRegistry?: ModelRegistry;
121
123
  sessionId?: string;
122
124
  signal?: AbortSignal;
123
125
  }
@@ -128,7 +130,7 @@ async function executeSearch(
128
130
  params: SearchQueryParams,
129
131
  options: ExecuteSearchOptions,
130
132
  ): Promise<{ content: Array<{ type: "text"; text: string }>; details: SearchRenderDetails }> {
131
- const { authStorage, sessionId, signal } = options;
133
+ const { authStorage, modelRegistry, sessionId, signal } = options;
132
134
  const explicitProvider = params.provider;
133
135
  let candidates: SearchProviderCandidate[];
134
136
  if (explicitProvider && explicitProvider !== "auto") {
@@ -187,6 +189,7 @@ async function executeSearch(
187
189
  temperature: params.temperature,
188
190
  signal,
189
191
  authStorage,
192
+ modelRegistry,
190
193
  sessionId,
191
194
  antigravityEndpointMode,
192
195
  geminiModel,
@@ -246,16 +249,18 @@ async function executeSearch(
246
249
  */
247
250
  export async function runSearchQuery(
248
251
  params: SearchQueryParams,
249
- options: { authStorage?: AuthStorage; sessionId?: string; signal?: AbortSignal } = {},
252
+ options: { authStorage?: AuthStorage; modelRegistry?: ModelRegistry; sessionId?: string; signal?: AbortSignal } = {},
250
253
  ): Promise<{ content: Array<{ type: "text"; text: string }>; details: SearchRenderDetails }> {
251
- const createdAuthStorage = options.authStorage ? undefined : await discoverAuthStorage();
252
- const authStorage = options.authStorage ?? createdAuthStorage;
254
+ const createdAuthStorage = options.authStorage || options.modelRegistry ? undefined : await discoverAuthStorage();
255
+ const authStorage = options.authStorage ?? options.modelRegistry?.authStorage ?? createdAuthStorage;
253
256
  if (!authStorage) {
254
257
  throw new Error("Failed to initialize authentication storage");
255
258
  }
259
+ const modelRegistry = options.modelRegistry ?? (createdAuthStorage ? new ModelRegistry(authStorage) : undefined);
256
260
  try {
257
261
  return await executeSearch("cli-web-search", params, {
258
262
  authStorage,
263
+ modelRegistry,
259
264
  sessionId: options.sessionId,
260
265
  signal: options.signal,
261
266
  });
@@ -295,7 +300,12 @@ export class WebSearchTool implements AgentTool<typeof webSearchSchema, SearchRe
295
300
  ): Promise<AgentToolResult<SearchRenderDetails>> {
296
301
  const authStorage = this.#session.authStorage ?? (await discoverAuthStorage());
297
302
  const sessionId = this.#session.getSessionId?.() ?? undefined;
298
- return executeSearch(_toolCallId, params, { authStorage, sessionId, signal });
303
+ return executeSearch(_toolCallId, params, {
304
+ authStorage,
305
+ modelRegistry: this.#session.modelRegistry,
306
+ sessionId,
307
+ signal,
308
+ });
299
309
  }
300
310
  }
301
311
 
@@ -316,7 +326,12 @@ export const webSearchCustomTool: CustomTool<typeof webSearchSchema, SearchRende
316
326
  ) {
317
327
  const authStorage = ctx.modelRegistry?.authStorage ?? (await discoverAuthStorage());
318
328
  const sessionId = ctx.sessionManager.getSessionId();
319
- return executeSearch(toolCallId, params, { authStorage, sessionId, signal });
329
+ return executeSearch(toolCallId, params, {
330
+ authStorage,
331
+ modelRegistry: ctx.modelRegistry,
332
+ sessionId,
333
+ signal,
334
+ });
320
335
  },
321
336
 
322
337
  renderCall(args: SearchToolParams, options: RenderResultOptions, theme: Theme) {
@@ -1,4 +1,5 @@
1
1
  import type { AuthStorage, FetchImpl } from "@oh-my-pi/pi-ai";
2
+ import type { ModelRegistry } from "../../../config/model-registry";
2
3
  import type { SearchProviderId, SearchResponse } from "../types";
3
4
 
4
5
  /**
@@ -45,6 +46,8 @@ export interface SearchParams {
45
46
  * the per-credential single-flight refresh.
46
47
  */
47
48
  authStorage: AuthStorage;
49
+ /** Provider/model transport settings used by native search endpoints. */
50
+ modelRegistry?: ModelRegistry;
48
51
  /**
49
52
  * Optional session id used as the round-robin / sticky key when selecting
50
53
  * among multiple credentials for the same provider. Pass through from the
@@ -1,5 +1,6 @@
1
1
  import { type ApiKey, type ApiKeyResolver, type AuthStorage, withAuth } from "@oh-my-pi/pi-ai";
2
2
  import { $env } from "@oh-my-pi/pi-utils";
3
+ import { resolveXAIHttpTransport, type XAIHttpProvider, type XAIHttpTransport } from "../../../lib/xai-http";
3
4
  import type { SearchCitation, SearchResponse, SearchSource, SearchUsage } from "../../../web/search/types";
4
5
  import { SearchProviderError } from "../../../web/search/types";
5
6
  import { clampNumResults } from "../utils";
@@ -7,7 +8,7 @@ import type { SearchParams } from "./base";
7
8
  import { SearchProvider } from "./base";
8
9
  import { classifyProviderHttpError, withHardTimeout } from "./utils";
9
10
 
10
- const XAI_RESPONSES_URL = "https://api.x.ai/v1/responses";
11
+ const XAI_DEFAULT_BASE_URL = "https://api.x.ai/v1";
11
12
  const XAI_WEB_SEARCH_MODEL = "grok-4.3";
12
13
  const DEFAULT_NUM_RESULTS = 10;
13
14
  const MAX_NUM_RESULTS = 30;
@@ -75,10 +76,12 @@ async function postXAIResponses(
75
76
  apiKey: string,
76
77
  params: SearchParams,
77
78
  body: Record<string, unknown>,
79
+ transport: XAIHttpTransport,
78
80
  ): Promise<Response> {
79
- return (params.fetch ?? fetch)(XAI_RESPONSES_URL, {
81
+ return (params.fetch ?? fetch)(`${transport.baseURL.replace(/\/+$/, "")}/responses`, {
80
82
  method: "POST",
81
83
  headers: {
84
+ ...transport.headers,
82
85
  "Content-Type": "application/json",
83
86
  Authorization: `Bearer ${apiKey}`,
84
87
  },
@@ -93,9 +96,13 @@ function throwXAIResponsesError(status: number, errorText: string): never {
93
96
  throw new SearchProviderError("xai", `xAI Responses API error (${status}): ${errorText}`, status);
94
97
  }
95
98
 
96
- async function callXAIResponses(apiKey: string, params: SearchParams): Promise<XAIResponsesResponse> {
99
+ async function callXAIResponses(
100
+ apiKey: string,
101
+ params: SearchParams,
102
+ transport: XAIHttpTransport,
103
+ ): Promise<XAIResponsesResponse> {
97
104
  const requestBody = buildRequestBody(params);
98
- const response = await postXAIResponses(apiKey, params, requestBody);
105
+ const response = await postXAIResponses(apiKey, params, requestBody, transport);
99
106
 
100
107
  if (!response.ok) {
101
108
  throwXAIResponsesError(response.status, await response.text());
@@ -235,19 +242,24 @@ function shouldPreferXAIOAuth(authStorage: AuthStorage): boolean {
235
242
  return true;
236
243
  }
237
244
 
238
- function resolveXAIWebSearchApiKey(params: SearchParams): ApiKeyResolver {
245
+ interface XAIWebSearchAuth {
246
+ provider: XAIHttpProvider;
247
+ keyOrResolver: ApiKey;
248
+ }
249
+
250
+ function resolveXAIWebSearchAuth(params: SearchParams): XAIWebSearchAuth {
239
251
  const xaiResolver = params.authStorage.resolver("xai", {
240
252
  sessionId: params.sessionId,
241
253
  });
242
254
  const xaiOAuthOrigin = params.authStorage.getCredentialOrigin("xai-oauth");
243
255
  if (!shouldPreferXAIOAuth(params.authStorage)) {
244
- return xaiResolver;
256
+ return { provider: "xai", keyOrResolver: xaiResolver };
245
257
  }
246
258
 
247
259
  const xaiOAuthResolver = params.authStorage.resolver("xai-oauth", {
248
260
  sessionId: params.sessionId,
249
261
  });
250
- return async ctx => {
262
+ const keyOrResolver: ApiKeyResolver = async ctx => {
251
263
  const xaiOAuthKey = await xaiOAuthResolver(ctx);
252
264
  if (xaiOAuthKey) {
253
265
  const borrowedSharedEnvKey =
@@ -259,14 +271,33 @@ function resolveXAIWebSearchApiKey(params: SearchParams): ApiKeyResolver {
259
271
  }
260
272
  return xaiResolver(ctx);
261
273
  };
274
+ return { provider: "xai-oauth", keyOrResolver };
262
275
  }
263
276
 
264
277
  /** Execute xAI Responses API web search. */
265
278
  export async function searchXAI(params: SearchParams): Promise<SearchResponse> {
266
- const keyOrResolver: ApiKey = resolveXAIWebSearchApiKey(params);
279
+ const auth = resolveXAIWebSearchAuth(params);
280
+ const transport = params.modelRegistry
281
+ ? resolveXAIHttpTransport(params.modelRegistry, auth.provider, XAI_WEB_SEARCH_MODEL)
282
+ : { baseURL: XAI_DEFAULT_BASE_URL };
283
+ const customEndpoint = transport.baseURL.replace(/\/+$/, "") !== XAI_DEFAULT_BASE_URL;
284
+ const credentialOrigin = params.authStorage.getCredentialOrigin(auth.provider);
285
+ if (
286
+ customEndpoint &&
287
+ auth.provider === "xai-oauth" &&
288
+ (credentialOrigin?.kind === "oauth" || credentialOrigin?.kind === "env")
289
+ ) {
290
+ throw new SearchProviderError(
291
+ "xai",
292
+ `Refusing to send official xAI OAuth credentials to custom endpoint ${transport.baseURL}. Configure an API key for provider "xai-oauth".`,
293
+ );
294
+ }
295
+ const keyOrResolver: ApiKey = customEndpoint
296
+ ? params.authStorage.resolver(auth.provider, { sessionId: params.sessionId })
297
+ : auth.keyOrResolver;
267
298
 
268
299
  const resultCap = clampNumResults(params.numSearchResults ?? params.limit, DEFAULT_NUM_RESULTS, MAX_NUM_RESULTS);
269
- const response = await withAuth(keyOrResolver, (key: string) => callXAIResponses(key, params), {
300
+ const response = await withAuth(keyOrResolver, (key: string) => callXAIResponses(key, params, transport), {
270
301
  signal: params.signal,
271
302
  missingKeyMessage: 'xAI credentials not found. Set XAI_API_KEY or configure an API key for provider "xai".',
272
303
  });