@oh-my-pi/pi-coding-agent 15.13.3 → 16.0.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/dist/cli.js +506 -443
  3. package/dist/types/advisor/__tests__/advisor.test.d.ts +1 -0
  4. package/dist/types/advisor/advise-tool.d.ts +58 -0
  5. package/dist/types/advisor/index.d.ts +3 -0
  6. package/dist/types/advisor/runtime.d.ts +52 -0
  7. package/dist/types/advisor/watchdog.d.ts +5 -0
  8. package/dist/types/config/model-roles.d.ts +1 -1
  9. package/dist/types/config/settings-schema.d.ts +44 -5
  10. package/dist/types/modes/components/advisor-message.d.ts +9 -0
  11. package/dist/types/modes/components/assistant-message.d.ts +1 -0
  12. package/dist/types/modes/controllers/command-controller.d.ts +3 -1
  13. package/dist/types/modes/interactive-mode.d.ts +3 -1
  14. package/dist/types/modes/types.d.ts +3 -1
  15. package/dist/types/sdk.d.ts +3 -3
  16. package/dist/types/session/agent-session.d.ts +71 -2
  17. package/dist/types/session/session-history-format.d.ts +4 -0
  18. package/dist/types/session/yield-queue.d.ts +2 -0
  19. package/dist/types/tools/path-utils.d.ts +1 -0
  20. package/dist/types/tools/report-tool-issue.d.ts +0 -1
  21. package/package.json +13 -13
  22. package/src/advisor/__tests__/advisor.test.ts +586 -0
  23. package/src/advisor/advise-tool.ts +87 -0
  24. package/src/advisor/index.ts +3 -0
  25. package/src/advisor/runtime.ts +248 -0
  26. package/src/advisor/watchdog.ts +83 -0
  27. package/src/config/model-roles.ts +13 -1
  28. package/src/config/settings-schema.ts +42 -5
  29. package/src/internal-urls/docs-index.generated.ts +6 -5
  30. package/src/main.ts +4 -0
  31. package/src/modes/components/advisor-message.ts +99 -0
  32. package/src/modes/components/agent-hub.ts +7 -0
  33. package/src/modes/components/assistant-message.ts +86 -0
  34. package/src/modes/components/status-line/segments.ts +20 -7
  35. package/src/modes/controllers/command-controller.ts +69 -2
  36. package/src/modes/interactive-mode.ts +12 -2
  37. package/src/modes/types.ts +3 -1
  38. package/src/modes/utils/ui-helpers.ts +9 -0
  39. package/src/prompts/advisor/advise-tool.md +1 -0
  40. package/src/prompts/advisor/system.md +31 -0
  41. package/src/sdk.ts +52 -13
  42. package/src/session/agent-session.ts +560 -13
  43. package/src/session/session-dump-format.ts +15 -131
  44. package/src/session/session-history-format.ts +30 -11
  45. package/src/session/yield-queue.ts +5 -1
  46. package/src/slash-commands/builtin-registry.ts +102 -4
  47. package/src/system-prompt.ts +1 -1
  48. package/src/tools/path-utils.ts +33 -2
  49. package/src/tools/report-tool-issue.ts +2 -7
  50. package/src/web/scrapers/docs-rs.ts +2 -3
package/src/sdk.ts CHANGED
@@ -16,7 +16,7 @@ import {
16
16
  type SimpleStreamOptions,
17
17
  streamSimple,
18
18
  } from "@oh-my-pi/pi-ai";
19
- import type { ToolCallSyntax } from "@oh-my-pi/pi-ai/grammar";
19
+ import type { Dialect } from "@oh-my-pi/pi-ai/dialect";
20
20
  import {
21
21
  getOpenAICodexTransportDetails,
22
22
  prewarmOpenAICodexResponses,
@@ -35,6 +35,7 @@ import {
35
35
  prompt,
36
36
  Snowflake,
37
37
  } from "@oh-my-pi/pi-utils";
38
+ import { ADVISOR_READONLY_TOOL_NAMES, discoverWatchdogFiles } from "./advisor";
38
39
  import { type AsyncJob, AsyncJobManager } from "./async";
39
40
  import { AutoLearnController, buildAutoLearnInstructions } from "./autolearn/controller";
40
41
  import { loadCapability } from "./capability";
@@ -551,12 +552,12 @@ export interface CreateAgentSessionResult {
551
552
  eventBus: EventBus;
552
553
  }
553
554
 
554
- export type ToolCallFormat = "auto" | "native" | ToolCallSyntax;
555
+ export type DialectFormat = "auto" | "native" | Dialect;
555
556
 
556
- export function resolveToolCallSyntax(
557
- format: ToolCallFormat,
557
+ export function resolveDialect(
558
+ format: DialectFormat,
558
559
  model: Pick<Model, "supportsTools"> | undefined,
559
- ): ToolCallSyntax | undefined {
560
+ ): Dialect | undefined {
560
561
  if (format === "native") return undefined;
561
562
  if (format === "auto") return model?.supportsTools === false ? "glm" : undefined;
562
563
  return format;
@@ -1141,6 +1142,8 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
1141
1142
  ? Promise.resolve(options.contextFiles)
1142
1143
  : logger.time("discoverContextFiles", discoverContextFiles, cwd, agentDir);
1143
1144
  contextFilesPromise.catch(() => {});
1145
+ const watchdogFilesPromise = logger.time("discoverWatchdogFiles", () => discoverWatchdogFiles(cwd, agentDir));
1146
+ watchdogFilesPromise.catch(() => {});
1144
1147
  const promptTemplatesPromise = options.promptTemplates
1145
1148
  ? Promise.resolve(options.promptTemplates)
1146
1149
  : logger.time("discoverPromptTemplates", discoverPromptTemplates, cwd, agentDir);
@@ -1370,9 +1373,10 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
1370
1373
  }
1371
1374
  return result;
1372
1375
  };
1373
- const [contextFiles, resolvedWorkspaceTree] = await Promise.all([
1376
+ const [contextFiles, resolvedWorkspaceTree, watchdogFiles] = await Promise.all([
1374
1377
  contextFilesPromise,
1375
1378
  raceWithDeadline("buildWorkspaceTree", workspaceTreePromise),
1379
+ watchdogFilesPromise,
1376
1380
  ]);
1377
1381
 
1378
1382
  let agent: Agent;
@@ -1608,8 +1612,9 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
1608
1612
  let startDeferredMCPDiscovery:
1609
1613
  | ((liveSession: AgentSession, activation: DeferredMCPActivation) => void)
1610
1614
  | undefined;
1615
+ const startupQuiet = settings.get("startup.quiet");
1611
1616
  const onMCPConnecting = (serverNames: string[]) => {
1612
- if (!options.hasUI || serverNames.length === 0) return;
1617
+ if (!options.hasUI || startupQuiet || serverNames.length === 0) return;
1613
1618
  eventBus.emit(MCP_CONNECTING_EVENT_CHANNEL, { serverNames } satisfies McpConnectingEvent);
1614
1619
  };
1615
1620
  const mcpDiscoverOptions = {
@@ -2161,10 +2166,9 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
2161
2166
  }
2162
2167
  appendPrompt = parts.join("\n\n");
2163
2168
  }
2164
- // Owned/in-band tool syntax (non-native) repeats the catalog as `# Tool:`
2169
+ // Owned/in-band tool dialect (non-native) repeats the catalog as `# Tool:`
2165
2170
  // sections; native tool calling lets the compact name list suffice.
2166
- const nativeTools =
2167
- resolveToolCallSyntax(settings.get("tools.format"), agent?.state.model ?? model) === undefined;
2171
+ const nativeTools = resolveDialect(settings.get("tools.format"), agent?.state.model ?? model) === undefined;
2168
2172
  const defaultPrompt = await buildSystemPromptInternal({
2169
2173
  cwd,
2170
2174
  skills,
@@ -2506,7 +2510,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
2506
2510
  return result;
2507
2511
  },
2508
2512
  intentTracing: !!intentField,
2509
- toolCallSyntax: resolveToolCallSyntax(settings.get("tools.format"), model),
2513
+ dialect: resolveDialect(settings.get("tools.format"), model),
2510
2514
  abortOnFabricatedToolResult: settings.get("tools.abortOnFabricatedResult"),
2511
2515
  getToolChoice: () => session?.nextToolChoice(),
2512
2516
  telemetry: options.telemetry,
@@ -2537,7 +2541,41 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
2537
2541
  }
2538
2542
  }
2539
2543
 
2544
+ // Hard-isolated read-only toolset for the advisor (built unconditionally so
2545
+ // it can be toggled at runtime). Fresh ReadTool/SearchTool/FindTool bound to a
2546
+ // DISTINCT ToolSession so the advisor's investigative reads never touch the
2547
+ // primary's snapshot, seen-lines, conflict, or summary caches (all keyed on
2548
+ // session identity). `cwd` stays dynamic; edit/yield capabilities are off.
2549
+ const advisorToolSession: ToolSession = {
2550
+ ...toolSession,
2551
+ get cwd() {
2552
+ return sessionManager.getCwd();
2553
+ },
2554
+ hasEditTool: false,
2555
+ requireYieldTool: false,
2556
+ conflictHistory: undefined,
2557
+ fileSnapshotStore: undefined,
2558
+ getSessionId: () => {
2559
+ const id = sessionManager.getSessionId?.();
2560
+ return id ? `${id}-advisor` : null;
2561
+ },
2562
+ getAgentId: () => "advisor",
2563
+ };
2564
+ const built = await Promise.all(
2565
+ [...ADVISOR_READONLY_TOOL_NAMES].map(name =>
2566
+ BUILTIN_TOOLS[name as keyof typeof BUILTIN_TOOLS](advisorToolSession),
2567
+ ),
2568
+ );
2569
+ const advisorReadOnlyTools: Tool[] = built
2570
+ .filter((tool): tool is Tool => tool != null)
2571
+ .map(wrapToolWithMetaNotice);
2572
+
2573
+ let advisorWatchdogPrompt: string | undefined;
2574
+ if (watchdogFiles && watchdogFiles.length > 0) {
2575
+ advisorWatchdogPrompt = watchdogFiles.join("\n\n");
2576
+ }
2540
2577
  session = new AgentSession({
2578
+ advisorWatchdogPrompt,
2541
2579
  agent,
2542
2580
  thinkingLevel: autoThinking ? AUTO_THINKING : effectiveThinkingLevel,
2543
2581
  sessionManager,
@@ -2592,6 +2630,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
2592
2630
  agentKind,
2593
2631
  providerSessionId: options.providerSessionId,
2594
2632
  parentEvalSessionId: options.parentEvalSessionId,
2633
+ advisorReadOnlyTools,
2595
2634
  });
2596
2635
  hasSession = true;
2597
2636
  if (asyncJobManager) {
@@ -2696,7 +2735,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
2696
2735
  type: "completed",
2697
2736
  servers: result.servers,
2698
2737
  };
2699
- eventBus.emit(LSP_STARTUP_EVENT_CHANNEL, event);
2738
+ if (!startupQuiet) eventBus.emit(LSP_STARTUP_EVENT_CHANNEL, event);
2700
2739
  } catch (error) {
2701
2740
  const errorMessage = error instanceof Error ? error.message : String(error);
2702
2741
  logger.warn("LSP server warmup failed", { cwd, error: errorMessage });
@@ -2708,7 +2747,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
2708
2747
  type: "failed",
2709
2748
  error: errorMessage,
2710
2749
  };
2711
- eventBus.emit(LSP_STARTUP_EVENT_CHANNEL, event);
2750
+ if (!startupQuiet) eventBus.emit(LSP_STARTUP_EVENT_CHANNEL, event);
2712
2751
  }
2713
2752
  })();
2714
2753
  }