@oh-my-pi/pi-coding-agent 17.0.1 → 17.0.2

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 (126) hide show
  1. package/CHANGELOG.md +92 -20
  2. package/dist/cli.js +3485 -3448
  3. package/dist/types/advisor/config.d.ts +14 -6
  4. package/dist/types/advisor/runtime.d.ts +20 -11
  5. package/dist/types/autolearn/controller.d.ts +1 -0
  6. package/dist/types/config/model-discovery.d.ts +17 -0
  7. package/dist/types/config/model-resolver.d.ts +6 -2
  8. package/dist/types/config/settings-schema.d.ts +32 -7
  9. package/dist/types/config/settings.d.ts +50 -0
  10. package/dist/types/cursor.d.ts +11 -0
  11. package/dist/types/discovery/helpers.d.ts +5 -2
  12. package/dist/types/exec/bash-executor.d.ts +2 -0
  13. package/dist/types/extensibility/extensions/managed-timers.d.ts +15 -0
  14. package/dist/types/extensibility/extensions/runner.d.ts +7 -0
  15. package/dist/types/extensibility/extensions/types.d.ts +18 -0
  16. package/dist/types/extensibility/legacy-pi-coding-agent-shim.d.ts +40 -0
  17. package/dist/types/extensibility/shared-events.d.ts +6 -0
  18. package/dist/types/extensibility/utils.d.ts +2 -2
  19. package/dist/types/mcp/transports/stdio.d.ts +13 -1
  20. package/dist/types/modes/components/advisor-config.d.ts +8 -1
  21. package/dist/types/modes/components/hook-editor.d.ts +7 -0
  22. package/dist/types/modes/components/model-hub.d.ts +5 -2
  23. package/dist/types/modes/components/session-selector.d.ts +2 -0
  24. package/dist/types/modes/controllers/command-controller.d.ts +8 -0
  25. package/dist/types/modes/controllers/selector-controller.d.ts +3 -1
  26. package/dist/types/modes/print-mode.d.ts +1 -1
  27. package/dist/types/modes/warp-events.d.ts +24 -0
  28. package/dist/types/modes/warp-events.test.d.ts +1 -0
  29. package/dist/types/plan-mode/model-transition.d.ts +47 -0
  30. package/dist/types/plan-mode/model-transition.test.d.ts +1 -0
  31. package/dist/types/registry/agent-lifecycle.d.ts +26 -1
  32. package/dist/types/sdk.d.ts +13 -2
  33. package/dist/types/session/agent-session.d.ts +34 -10
  34. package/dist/types/session/session-history-format.d.ts +10 -0
  35. package/dist/types/session/session-manager.d.ts +14 -0
  36. package/dist/types/slash-commands/helpers/active-oauth-account.d.ts +9 -0
  37. package/dist/types/task/label.d.ts +1 -1
  38. package/dist/types/telemetry-export.d.ts +34 -9
  39. package/dist/types/tools/approval.d.ts +8 -0
  40. package/dist/types/tools/bash.d.ts +2 -0
  41. package/dist/types/tools/essential-tools.d.ts +29 -0
  42. package/dist/types/tools/image-gen.d.ts +2 -1
  43. package/dist/types/tools/index.d.ts +1 -0
  44. package/dist/types/tools/xdev.d.ts +11 -2
  45. package/dist/types/utils/title-generator.d.ts +2 -1
  46. package/dist/types/web/search/providers/kimi.d.ts +4 -1
  47. package/dist/types/web/search/types.d.ts +1 -1
  48. package/package.json +21 -16
  49. package/src/advisor/__tests__/advisor.test.ts +1304 -42
  50. package/src/advisor/__tests__/config.test.ts +58 -2
  51. package/src/advisor/config.ts +76 -24
  52. package/src/advisor/runtime.ts +445 -92
  53. package/src/autolearn/controller.ts +23 -28
  54. package/src/cli.ts +5 -1
  55. package/src/config/model-discovery.ts +81 -21
  56. package/src/config/model-registry.ts +25 -6
  57. package/src/config/model-resolver.ts +14 -7
  58. package/src/config/settings-schema.ts +42 -6
  59. package/src/config/settings.ts +405 -25
  60. package/src/cursor.ts +20 -3
  61. package/src/debug/report-bundle.ts +40 -4
  62. package/src/discovery/helpers.ts +28 -5
  63. package/src/exec/bash-executor.ts +14 -5
  64. package/src/extensibility/custom-tools/loader.ts +3 -3
  65. package/src/extensibility/custom-tools/wrapper.ts +2 -1
  66. package/src/extensibility/extensions/loader.ts +3 -3
  67. package/src/extensibility/extensions/managed-timers.ts +83 -0
  68. package/src/extensibility/extensions/runner.ts +26 -0
  69. package/src/extensibility/extensions/types.ts +18 -0
  70. package/src/extensibility/extensions/wrapper.ts +2 -1
  71. package/src/extensibility/hooks/loader.ts +3 -3
  72. package/src/extensibility/legacy-pi-coding-agent-shim.ts +96 -1
  73. package/src/extensibility/plugins/legacy-pi-compat.ts +225 -22
  74. package/src/extensibility/plugins/manager.ts +2 -2
  75. package/src/extensibility/shared-events.ts +6 -0
  76. package/src/extensibility/utils.ts +91 -25
  77. package/src/irc/bus.ts +22 -3
  78. package/src/launch/broker.ts +3 -2
  79. package/src/launch/client.ts +2 -2
  80. package/src/launch/presence.ts +2 -2
  81. package/src/lsp/client.ts +1 -1
  82. package/src/main.ts +11 -8
  83. package/src/mcp/manager.ts +9 -3
  84. package/src/mcp/transports/stdio.ts +103 -23
  85. package/src/modes/components/advisor-config.ts +65 -3
  86. package/src/modes/components/ask-dialog.ts +1 -1
  87. package/src/modes/components/hook-editor.ts +18 -3
  88. package/src/modes/components/model-hub.ts +138 -42
  89. package/src/modes/components/session-selector.ts +4 -0
  90. package/src/modes/components/status-line/component.test.ts +1 -0
  91. package/src/modes/components/status-line/segments.ts +21 -6
  92. package/src/modes/controllers/command-controller.ts +167 -47
  93. package/src/modes/controllers/event-controller.ts +5 -0
  94. package/src/modes/controllers/extension-ui-controller.ts +4 -22
  95. package/src/modes/controllers/input-controller.ts +12 -12
  96. package/src/modes/controllers/selector-controller.ts +191 -31
  97. package/src/modes/interactive-mode.ts +139 -54
  98. package/src/modes/print-mode.ts +3 -3
  99. package/src/modes/rpc/host-tools.ts +2 -1
  100. package/src/modes/rpc/rpc-mode.ts +19 -4
  101. package/src/modes/warp-events.test.ts +794 -0
  102. package/src/modes/warp-events.ts +232 -0
  103. package/src/plan-mode/model-transition.test.ts +60 -0
  104. package/src/plan-mode/model-transition.ts +51 -0
  105. package/src/registry/agent-lifecycle.ts +133 -18
  106. package/src/sdk.ts +221 -42
  107. package/src/session/agent-session.ts +1285 -348
  108. package/src/session/session-history-format.ts +20 -5
  109. package/src/session/session-manager.ts +48 -0
  110. package/src/slash-commands/builtin-registry.ts +7 -0
  111. package/src/slash-commands/helpers/active-oauth-account.ts +16 -0
  112. package/src/task/executor.ts +1 -1
  113. package/src/task/label.ts +2 -0
  114. package/src/telemetry-export.ts +453 -97
  115. package/src/tools/approval.ts +11 -0
  116. package/src/tools/bash.ts +71 -38
  117. package/src/tools/essential-tools.ts +45 -0
  118. package/src/tools/gh.ts +169 -2
  119. package/src/tools/image-gen.ts +69 -7
  120. package/src/tools/index.ts +7 -5
  121. package/src/tools/read.ts +48 -3
  122. package/src/tools/write.ts +22 -4
  123. package/src/tools/xdev.ts +14 -3
  124. package/src/utils/title-generator.ts +15 -4
  125. package/src/web/search/providers/kimi.ts +18 -12
  126. package/src/web/search/types.ts +6 -1
package/src/tools/read.ts CHANGED
@@ -36,7 +36,7 @@ import {
36
36
  import { normalizeToLF } from "../edit/normalize";
37
37
  import { isNotebookPath, readEditableNotebookText } from "../edit/notebook";
38
38
  import type { RenderResultOptions } from "../extensibility/custom-tools/types";
39
- import { InternalUrlRouter, resolveLocalUrlToFile } from "../internal-urls";
39
+ import { InternalUrlRouter, resolveLocalUrlToFile, resolveLocalUrlToPath } from "../internal-urls";
40
40
  import { type ResolvedArtifactFile, resolveArtifactFile } from "../internal-urls/artifact-protocol";
41
41
  import { parseInternalUrl } from "../internal-urls/parse";
42
42
  import type { InternalUrl } from "../internal-urls/types";
@@ -920,6 +920,32 @@ export class ReadTool implements AgentTool<typeof readSchema, ReadToolDetails> {
920
920
  });
921
921
  }
922
922
 
923
+ /**
924
+ * Recover the active approved plan when a model rewrites its `local://` URL
925
+ * as a same-basename path in the working-directory root.
926
+ *
927
+ * Only missing cwd-root paths qualify, so a real working-tree file always
928
+ * wins and unrelated paths cannot escape into the session artifact sandbox.
929
+ */
930
+ #approvedPlanAlias(missingAbsolutePath: string): string | undefined {
931
+ const planReferencePath = this.session.getPlanReferencePath?.();
932
+ if (!planReferencePath?.startsWith("local:")) return undefined;
933
+
934
+ const requestedPath = path.resolve(missingAbsolutePath);
935
+ if (path.dirname(requestedPath) !== path.resolve(this.session.cwd)) return undefined;
936
+
937
+ const localProtocolOptions = this.session.localProtocolOptions ?? {
938
+ getArtifactsDir: () => this.session.getArtifactsDir?.() ?? null,
939
+ getSessionId: () => this.session.getSessionId?.() ?? null,
940
+ };
941
+ try {
942
+ const approvedPlanPath = resolveLocalUrlToPath(planReferencePath, localProtocolOptions);
943
+ return path.basename(requestedPath) === path.basename(approvedPlanPath) ? approvedPlanPath : undefined;
944
+ } catch {
945
+ return undefined;
946
+ }
947
+ }
948
+
923
949
  async #tryReadDelimitedPaths(
924
950
  readPath: string,
925
951
  signal?: AbortSignal,
@@ -2292,7 +2318,8 @@ export class ReadTool implements AgentTool<typeof readSchema, ReadToolDetails> {
2292
2318
  isDirectory = stat.isDirectory();
2293
2319
  } catch (error) {
2294
2320
  if (isNotFoundError(error)) {
2295
- // Attempt unique suffix resolution before falling back to fuzzy suggestions
2321
+ // Attempt unique suffix resolution before falling back to the approved-plan
2322
+ // alias or fuzzy suggestions. Existing workspace files retain precedence.
2296
2323
  if (!isRemoteMountPath(absolutePath)) {
2297
2324
  const suffixMatch = await this.#findSuffixMatchCached(suffixCache, localReadPath, signal);
2298
2325
  if (suffixMatch) {
@@ -2303,12 +2330,30 @@ export class ReadTool implements AgentTool<typeof readSchema, ReadToolDetails> {
2303
2330
  isDirectory = retryStat.isDirectory();
2304
2331
  suffixResolution = { from: localReadPath, to: suffixMatch.displayPath };
2305
2332
  } catch {
2306
- // Suffix match candidate no longer stats — fall through to error path
2333
+ // Suffix match candidate no longer stats — continue through
2334
+ // approved-plan recovery and the original not-found error.
2307
2335
  }
2308
2336
  }
2309
2337
  }
2310
2338
 
2339
+ let recoveredApprovedPlan = false;
2311
2340
  if (!suffixResolution) {
2341
+ const approvedPlanPath = this.#approvedPlanAlias(absolutePath);
2342
+ if (approvedPlanPath) {
2343
+ try {
2344
+ const approvedPlanStat = await Bun.file(approvedPlanPath).stat();
2345
+ absolutePath = approvedPlanPath;
2346
+ fileSize = approvedPlanStat.size;
2347
+ isDirectory = approvedPlanStat.isDirectory();
2348
+ recoveredApprovedPlan = true;
2349
+ } catch {
2350
+ // The referenced plan disappeared after resolution; continue through
2351
+ // the ordinary delimited-path fallback and not-found error.
2352
+ }
2353
+ }
2354
+ }
2355
+
2356
+ if (!recoveredApprovedPlan && !suffixResolution) {
2312
2357
  const delimitedResult = await this.#tryReadDelimitedPaths(readPath, signal);
2313
2358
  if (delimitedResult) return delimitedResult;
2314
2359
  throw new ToolError(`Path '${localReadPath}' not found`);
@@ -36,7 +36,7 @@ import {
36
36
  writeArchive,
37
37
  } from "../utils/zip";
38
38
  import { routeWriteThroughBridge } from "./acp-bridge";
39
- import { truncateForPrompt } from "./approval";
39
+ import { resolveToolTier, truncateForPrompt } from "./approval";
40
40
  import { assertEditableFile } from "./auto-generated-guard";
41
41
  import {
42
42
  type ConflictEntry,
@@ -398,9 +398,27 @@ export class WriteTool implements AgentTool<typeof writeSchema, WriteToolDetails
398
398
  if (xdevTarget.name === REPORT_ISSUE_DEVICE_NAME) return "write";
399
399
  if (xdevTarget.name && isResolutionDeviceName(xdevTarget.name)) return "read";
400
400
  const inst = xdevTarget.name ? this.session.xdevRegistry?.get(xdevTarget.name) : undefined;
401
- const decision = typeof inst?.approval === "function" ? undefined : inst?.approval;
402
- const tier = typeof decision === "object" ? decision?.tier : decision;
403
- return tier ?? "exec";
401
+ if (!inst) return "exec";
402
+ // Decode the device JSON payload and evaluate the mounted tool's own
403
+ // approval (which may be argument-dependent, e.g. ast_edit is read-tier
404
+ // for internal-URL paths, debug is read-tier for inspection actions).
405
+ // Malformed JSON, non-object payloads, missing content, and approval
406
+ // functions that reject schema-invalid objects stay exec so the gate
407
+ // fails closed — the dispatch itself rejects invalid arguments too.
408
+ const rawContent = (args as Partial<WriteParams>).content;
409
+ if (typeof rawContent !== "string") return "exec";
410
+ let parsed: unknown;
411
+ try {
412
+ parsed = JSON.parse(rawContent);
413
+ } catch {
414
+ return "exec";
415
+ }
416
+ if (!isRecord(parsed)) return "exec";
417
+ try {
418
+ return resolveToolTier(inst, parsed);
419
+ } catch {
420
+ return "exec";
421
+ }
404
422
  }
405
423
  // Remote SSH writes open an outbound connection and run a remote shell —
406
424
  // gate them like the exec-tier `ssh` tool, ahead of the handler-write
package/src/tools/xdev.ts CHANGED
@@ -44,15 +44,26 @@ import { ToolError } from "./tool-errors";
44
44
  */
45
45
  export const XDEV_KEEP_TOP_LEVEL: Record<string, true> = { todo: true, ask: true, grep: true };
46
46
 
47
+ /**
48
+ * Tools that carry the `xd://` transport itself and therefore can never be
49
+ * mounted as devices: `read xd://` lists/documents devices and
50
+ * `write xd://<tool>` executes them. Demoting either leaves every mounted
51
+ * device unreachable (issue #5764), so they stay top-level regardless of a
52
+ * declared `loadMode`.
53
+ */
54
+ export const XDEV_TRANSPORT_TOOLS: Record<string, true> = { read: true, write: true };
55
+
47
56
  /**
48
57
  * Whether an enabled tool is presented under `xd://` (rather than top-level)
49
58
  * while the `xd://` transport is active. Discoverable tools mount unless they
50
- * are pinned top-level by {@link XDEV_KEEP_TOP_LEVEL}; essential tools never do.
51
- * The caller gates this on the transport being active (a session-owned
59
+ * are pinned top-level by {@link XDEV_KEEP_TOP_LEVEL} or carry the transport
60
+ * itself ({@link XDEV_TRANSPORT_TOOLS}); essential tools never do. The caller
61
+ * gates this on the transport being active (a session-owned
52
62
  * {@link XdevRegistry} existing).
53
63
  */
54
64
  export function isMountableUnderXdev(tool: { name: string; loadMode?: ToolLoadMode }): boolean {
55
- return tool.loadMode === "discoverable" && !(tool.name in XDEV_KEEP_TOP_LEVEL);
65
+ if (tool.name in XDEV_TRANSPORT_TOOLS || tool.name in XDEV_KEEP_TOP_LEVEL) return false;
66
+ return tool.loadMode === "discoverable";
56
67
  }
57
68
 
58
69
  /** Dispatch metadata carried on write-tool details for renderer delegation. */
@@ -68,6 +68,7 @@ function getTitleModel(registry: ModelRegistry, settings: Settings, currentModel
68
68
  * resolver instead of a pre-evaluated value ensures the metadata's account_uuid
69
69
  * reflects the credential actually selected for this request.
70
70
  * @param customSystemPrompt Optional title-specific system prompt override
71
+ * @param signal Session-lifecycle cancellation for background title requests
71
72
  */
72
73
  export async function generateSessionTitle(
73
74
  firstMessage: string,
@@ -77,6 +78,7 @@ export async function generateSessionTitle(
77
78
  currentModel?: Model<Api>,
78
79
  metadataResolver?: (provider: string) => Record<string, unknown> | undefined,
79
80
  customSystemPrompt?: string,
81
+ signal?: AbortSignal,
80
82
  ): Promise<string | null> {
81
83
  // Defer titling for greetings / acknowledgements / empty input. The default
82
84
  // tiny title model can't reliably decline trivial input, so this happens
@@ -97,7 +99,7 @@ export async function generateSessionTitle(
97
99
  sessionId,
98
100
  currentModel,
99
101
  metadataResolver,
100
- undefined,
102
+ signal,
101
103
  titleSystemPrompt,
102
104
  );
103
105
  }
@@ -117,9 +119,18 @@ export async function generateSessionTitle(
117
119
  return null;
118
120
  }
119
121
  try {
120
- const localTitle = titleSystemPrompt
121
- ? await tinyTitleClient.generate(tinyModel, firstMessage, { systemPrompt: titleSystemPrompt })
122
- : await tinyTitleClient.generate(tinyModel, firstMessage);
122
+ let localTitle: string | null;
123
+ if (signal) {
124
+ localTitle = await tinyTitleClient.generate(
125
+ tinyModel,
126
+ firstMessage,
127
+ titleSystemPrompt ? { signal, systemPrompt: titleSystemPrompt } : { signal },
128
+ );
129
+ } else if (titleSystemPrompt) {
130
+ localTitle = await tinyTitleClient.generate(tinyModel, firstMessage, { systemPrompt: titleSystemPrompt });
131
+ } else {
132
+ localTitle = await tinyTitleClient.generate(tinyModel, firstMessage);
133
+ }
123
134
  if (!localTitle) {
124
135
  logger.warn("title-generator: local tiny model produced no title; skipping (no online fallback)", {
125
136
  sessionId,
@@ -1,7 +1,10 @@
1
1
  /**
2
2
  * Kimi Web Search Provider
3
3
  *
4
- * Uses Moonshot Kimi Code search API to retrieve web results.
4
+ * Uses the Kimi Code search API to retrieve web results. This is the Kimi Code
5
+ * membership service, distinct from the Moonshot Open Platform — it requires a
6
+ * Kimi Code Console credential (`omp /login kimi-code` or an explicit
7
+ * `MOONSHOT_SEARCH_API_KEY` / `KIMI_SEARCH_API_KEY`), not `MOONSHOT_API_KEY`.
5
8
  * Endpoint: POST https://api.kimi.com/coding/v1/search
6
9
  */
7
10
  import { type ApiKey, type AuthStorage, type FetchImpl, withAuth } from "@oh-my-pi/pi-ai";
@@ -58,11 +61,17 @@ function resolveBaseUrl(): string {
58
61
  }
59
62
 
60
63
  /**
61
- * Resolve the Kimi search credential. Highest precedence is the static env key;
62
- * otherwise an AuthStorage-backed resolver for whichever stored provider id
63
- * holds a key (`moonshot` first, then `kimi-code`), so a stale token triggers
64
- * the central force-refresh / sibling-rotate retry. Returns `undefined` when
65
- * neither is configured.
64
+ * Resolve the Kimi Code search credential. Highest precedence is the explicit
65
+ * search-key env override; otherwise an AuthStorage-backed resolver for a
66
+ * stored `kimi-code` credential (from `omp /login kimi-code`), so a stale token
67
+ * triggers the central force-refresh / sibling-rotate retry. Returns
68
+ * `undefined` when neither is configured.
69
+ *
70
+ * The endpoint (`https://api.kimi.com/coding/v1/search`) is the Kimi Code
71
+ * membership service, which has a different credential system from the Moonshot
72
+ * Open Platform (`https://api.moonshot.ai`). A stored `moonshot` credential
73
+ * (or `MOONSHOT_API_KEY`) is NOT accepted here — it 401s against Kimi Code
74
+ * (issue #5762).
66
75
  */
67
76
  async function resolveKey(
68
77
  authStorage: AuthStorage,
@@ -72,10 +81,8 @@ async function resolveKey(
72
81
  const envKey = asTrimmed($env.MOONSHOT_SEARCH_API_KEY) ?? asTrimmed($env.KIMI_SEARCH_API_KEY);
73
82
  if (envKey) return envKey;
74
83
 
75
- for (const provider of ["moonshot", "kimi-code"] as const) {
76
- const stored = await authStorage.getApiKey(provider, sessionId, { signal });
77
- if (stored) return authStorage.resolver(provider, { sessionId });
78
- }
84
+ const stored = await authStorage.getApiKey("kimi-code", sessionId, { signal });
85
+ if (stored) return authStorage.resolver("kimi-code", { sessionId });
79
86
  return undefined;
80
87
  }
81
88
 
@@ -127,7 +134,7 @@ export async function searchKimi(params: KimiSearchParams): Promise<SearchRespon
127
134
  const keyOrResolver = await resolveKey(params.authStorage, params.sessionId, params.signal);
128
135
  if (!keyOrResolver) {
129
136
  throw new Error(
130
- "Kimi search credentials not found. Set MOONSHOT_SEARCH_API_KEY, KIMI_SEARCH_API_KEY, MOONSHOT_API_KEY, or login with 'omp /login moonshot'.",
137
+ "Kimi search credentials not found. Kimi web search uses the Kimi Code service (api.kimi.com); set MOONSHOT_SEARCH_API_KEY / KIMI_SEARCH_API_KEY to a Kimi Code Console key, or login with 'omp /login kimi-code'. A Moonshot Open Platform key (MOONSHOT_API_KEY) is not accepted here.",
131
138
  );
132
139
  }
133
140
 
@@ -176,7 +183,6 @@ export class KimiProvider extends SearchProvider {
176
183
  return (
177
184
  !!asTrimmed($env.MOONSHOT_SEARCH_API_KEY) ||
178
185
  !!asTrimmed($env.KIMI_SEARCH_API_KEY) ||
179
- authStorage.hasAuth("moonshot") ||
180
186
  authStorage.hasAuth("kimi-code")
181
187
  );
182
188
  }
@@ -39,7 +39,12 @@ export const SEARCH_PROVIDER_OPTIONS = [
39
39
  { value: "tavily", label: "Tavily", description: "Requires TAVILY_API_KEY" },
40
40
  { value: "firecrawl", label: "Firecrawl", description: "Requires FIRECRAWL_API_KEY" },
41
41
  { value: "brave", label: "Brave", description: "Requires BRAVE_API_KEY" },
42
- { value: "kimi", label: "Kimi", description: "Requires MOONSHOT_SEARCH_API_KEY or MOONSHOT_API_KEY" },
42
+ {
43
+ value: "kimi",
44
+ label: "Kimi",
45
+ description:
46
+ "Kimi Code search (requires a Kimi Code Console key via KIMI_SEARCH_API_KEY/MOONSHOT_SEARCH_API_KEY or /login kimi-code; not MOONSHOT_API_KEY)",
47
+ },
43
48
  { value: "parallel", label: "Parallel", description: "Requires PARALLEL_API_KEY" },
44
49
  { value: "synthetic", label: "Synthetic", description: "Requires SYNTHETIC_API_KEY" },
45
50
  { value: "searxng", label: "SearXNG", description: "Requires SEARXNG_ENDPOINT or searxng.endpoint" },