@oh-my-pi/pi-coding-agent 16.1.13 → 16.1.15

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 (153) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/dist/cli.js +5615 -2833
  3. package/dist/types/advisor/runtime.d.ts +3 -0
  4. package/dist/types/config/settings-schema.d.ts +64 -14
  5. package/dist/types/eval/__tests__/julia-prelude.test.d.ts +1 -0
  6. package/dist/types/eval/backend-helpers.d.ts +23 -0
  7. package/dist/types/eval/executor-base.d.ts +118 -0
  8. package/dist/types/eval/index.d.ts +2 -0
  9. package/dist/types/eval/jl/executor.d.ts +44 -0
  10. package/dist/types/eval/jl/index.d.ts +11 -0
  11. package/dist/types/eval/jl/kernel.d.ts +28 -0
  12. package/dist/types/eval/jl/prelude.d.ts +1 -0
  13. package/dist/types/eval/jl/runtime.d.ts +22 -0
  14. package/dist/types/eval/kernel-base.d.ts +105 -0
  15. package/dist/types/eval/py/kernel.d.ts +3 -61
  16. package/dist/types/eval/rb/executor.d.ts +77 -0
  17. package/dist/types/eval/rb/index.d.ts +11 -0
  18. package/dist/types/eval/rb/kernel.d.ts +31 -0
  19. package/dist/types/eval/rb/prelude.d.ts +1 -0
  20. package/dist/types/eval/rb/runtime.d.ts +23 -0
  21. package/dist/types/eval/runtime-env.d.ts +24 -0
  22. package/dist/types/eval/types.d.ts +3 -3
  23. package/dist/types/export/share.d.ts +8 -1
  24. package/dist/types/extensibility/extensions/runner.d.ts +2 -15
  25. package/dist/types/extensibility/hooks/loader.d.ts +1 -25
  26. package/dist/types/extensibility/session-handler-types.d.ts +23 -0
  27. package/dist/types/jsonrpc/message-framing.d.ts +35 -0
  28. package/dist/types/mcp/transports/stdio.d.ts +12 -1
  29. package/dist/types/mnemopi/embed-client.d.ts +7 -24
  30. package/dist/types/modes/components/chat-transcript-builder.d.ts +1 -1
  31. package/dist/types/modes/components/custom-editor.d.ts +11 -0
  32. package/dist/types/modes/components/selector-helpers.d.ts +53 -0
  33. package/dist/types/modes/components/status-line/context-thresholds.d.ts +4 -3
  34. package/dist/types/modes/components/status-line/types.d.ts +1 -0
  35. package/dist/types/modes/interactive-mode.d.ts +0 -2
  36. package/dist/types/modes/theme/theme.d.ts +8 -1
  37. package/dist/types/modes/types.d.ts +0 -2
  38. package/dist/types/modes/utils/copy-targets.d.ts +1 -1
  39. package/dist/types/modes/utils/interactive-context-helpers.d.ts +14 -0
  40. package/dist/types/modes/utils/transcript-render-helpers.d.ts +54 -0
  41. package/dist/types/sdk.d.ts +1 -1
  42. package/dist/types/secrets/obfuscator.d.ts +3 -3
  43. package/dist/types/session/agent-session.d.ts +2 -2
  44. package/dist/types/stt/asr-client.d.ts +3 -29
  45. package/dist/types/subprocess/worker-client.d.ts +149 -0
  46. package/dist/types/subprocess/worker-runtime.d.ts +107 -0
  47. package/dist/types/tiny/title-client.d.ts +14 -34
  48. package/dist/types/tools/eval-backends.d.ts +6 -3
  49. package/dist/types/tools/eval-render.d.ts +6 -5
  50. package/dist/types/tools/eval.d.ts +13 -15
  51. package/dist/types/tools/index.d.ts +3 -3
  52. package/dist/types/tts/tts-client.d.ts +3 -28
  53. package/dist/types/tui/code-cell.d.ts +7 -0
  54. package/dist/types/utils/file-display-mode.d.ts +1 -1
  55. package/dist/types/utils/shell-snapshot.d.ts +10 -0
  56. package/dist/types/web/parallel.d.ts +6 -0
  57. package/dist/types/web/search/providers/perplexity.d.ts +17 -3
  58. package/package.json +12 -12
  59. package/src/advisor/__tests__/advisor.test.ts +114 -0
  60. package/src/advisor/runtime.ts +129 -1
  61. package/src/config/model-registry.ts +12 -4
  62. package/src/config/settings-schema.ts +74 -18
  63. package/src/config/settings.ts +5 -0
  64. package/src/dap/client.ts +13 -107
  65. package/src/eval/__tests__/julia-prelude.test.ts +77 -0
  66. package/src/eval/backend-helpers.ts +48 -0
  67. package/src/eval/executor-base.ts +425 -0
  68. package/src/eval/index.ts +2 -0
  69. package/src/eval/jl/executor.ts +540 -0
  70. package/src/eval/jl/index.ts +54 -0
  71. package/src/eval/jl/kernel.ts +235 -0
  72. package/src/eval/jl/prelude.jl +930 -0
  73. package/src/eval/jl/prelude.ts +3 -0
  74. package/src/eval/jl/runner.jl +634 -0
  75. package/src/eval/jl/runtime.ts +118 -0
  76. package/src/eval/js/index.ts +3 -14
  77. package/src/eval/kernel-base.ts +569 -0
  78. package/src/eval/py/executor.ts +43 -252
  79. package/src/eval/py/index.ts +9 -20
  80. package/src/eval/py/kernel.ts +29 -544
  81. package/src/eval/rb/executor.ts +504 -0
  82. package/src/eval/rb/index.ts +54 -0
  83. package/src/eval/rb/kernel.ts +230 -0
  84. package/src/eval/rb/prelude.rb +721 -0
  85. package/src/eval/rb/prelude.ts +3 -0
  86. package/src/eval/rb/runner.rb +474 -0
  87. package/src/eval/rb/runtime.ts +132 -0
  88. package/src/eval/runtime-env.ts +104 -0
  89. package/src/eval/types.ts +3 -3
  90. package/src/exec/bash-executor.ts +44 -0
  91. package/src/export/share.ts +51 -28
  92. package/src/extensibility/extensions/runner.ts +4 -11
  93. package/src/extensibility/hooks/loader.ts +3 -21
  94. package/src/extensibility/session-handler-types.ts +21 -0
  95. package/src/internal-urls/docs-index.generated.txt +1 -1
  96. package/src/jsonrpc/message-framing.ts +142 -0
  97. package/src/lsp/client.ts +13 -109
  98. package/src/mcp/transports/stdio.ts +20 -4
  99. package/src/mnemopi/embed-client.ts +43 -198
  100. package/src/modes/components/agent-dashboard.ts +17 -40
  101. package/src/modes/components/chat-transcript-builder.ts +18 -102
  102. package/src/modes/components/custom-editor.test.ts +22 -0
  103. package/src/modes/components/custom-editor.ts +29 -1
  104. package/src/modes/components/extensions/extension-dashboard.ts +4 -13
  105. package/src/modes/components/extensions/extension-list.ts +16 -44
  106. package/src/modes/components/footer.ts +4 -3
  107. package/src/modes/components/history-search.ts +4 -16
  108. package/src/modes/components/selector-helpers.ts +129 -0
  109. package/src/modes/components/settings-selector.ts +7 -5
  110. package/src/modes/components/status-line/component.ts +5 -1
  111. package/src/modes/components/status-line/context-thresholds.ts +11 -3
  112. package/src/modes/components/status-line/segments.ts +1 -1
  113. package/src/modes/components/status-line/types.ts +1 -0
  114. package/src/modes/components/tree-selector.ts +13 -18
  115. package/src/modes/controllers/command-controller.ts +1 -0
  116. package/src/modes/controllers/event-controller.ts +3 -9
  117. package/src/modes/controllers/input-controller.ts +32 -54
  118. package/src/modes/interactive-mode.ts +5 -7
  119. package/src/modes/theme/theme.ts +35 -0
  120. package/src/modes/types.ts +0 -2
  121. package/src/modes/utils/copy-targets.ts +3 -2
  122. package/src/modes/utils/interactive-context-helpers.ts +27 -0
  123. package/src/modes/utils/transcript-render-helpers.ts +157 -0
  124. package/src/modes/utils/ui-helpers.ts +21 -126
  125. package/src/prompts/system/system-prompt.md +5 -5
  126. package/src/prompts/tools/bash.md +2 -3
  127. package/src/prompts/tools/eval.md +6 -4
  128. package/src/prompts/tools/find.md +0 -4
  129. package/src/prompts/tools/read.md +1 -2
  130. package/src/prompts/tools/replace.md +1 -1
  131. package/src/sdk.ts +13 -7
  132. package/src/secrets/obfuscator.ts +3 -9
  133. package/src/session/agent-session.ts +42 -9
  134. package/src/slash-commands/builtin-registry.ts +2 -1
  135. package/src/stt/asr-client.ts +35 -215
  136. package/src/stt/asr-worker.ts +29 -181
  137. package/src/subprocess/worker-client.ts +297 -0
  138. package/src/subprocess/worker-runtime.ts +277 -0
  139. package/src/task/executor.ts +4 -4
  140. package/src/tiny/title-client.ts +53 -219
  141. package/src/tiny/worker.ts +29 -180
  142. package/src/tools/eval-backends.ts +10 -3
  143. package/src/tools/eval-render.ts +17 -8
  144. package/src/tools/eval.ts +187 -22
  145. package/src/tools/index.ts +51 -28
  146. package/src/tts/tts-client.ts +38 -206
  147. package/src/tts/tts-worker.ts +23 -97
  148. package/src/tui/code-cell.ts +12 -1
  149. package/src/utils/file-display-mode.ts +2 -3
  150. package/src/utils/shell-snapshot.ts +63 -1
  151. package/src/web/parallel.ts +43 -42
  152. package/src/web/search/providers/parallel.ts +10 -99
  153. package/src/web/search/providers/perplexity.ts +18 -6
package/src/eval/types.ts CHANGED
@@ -1,16 +1,16 @@
1
1
  /** Runtime backend that an eval cell dispatches to. */
2
- export type EvalLanguage = "python" | "js";
2
+ export type EvalLanguage = "python" | "js" | "ruby" | "julia";
3
3
 
4
4
  import type { ImageContent } from "@oh-my-pi/pi-ai";
5
5
  import type { OutputMeta } from "../tools/output-meta";
6
6
 
7
- /** Status event emitted by prelude helpers (python or js) for TUI rendering. */
7
+ /** Status event emitted by eval prelude helpers for TUI rendering. */
8
8
  export interface EvalStatusEvent {
9
9
  op: string;
10
10
  [key: string]: unknown;
11
11
  }
12
12
 
13
- /** Display output captured during eval execution. Union of python and js shapes. */
13
+ /** Display output captured during eval execution across supported backends. */
14
14
  export type EvalDisplayOutput =
15
15
  | { type: "json"; data: unknown }
16
16
  | { type: "image"; data: string; mimeType: string }
@@ -59,6 +59,42 @@ const shellSessionQuarantines = new Map<string, Promise<unknown>>();
59
59
  /** Session keys with a command currently in flight on the persistent Shell. */
60
60
  const shellSessionsInUse = new Set<string>();
61
61
 
62
+ /**
63
+ * Shells retained past their turn because a background (`nohup`/`&`) job is
64
+ * still running. A per-call `:async:` Shell is normally dropped at teardown,
65
+ * which SIGKILLs its children via kill-on-drop. Keeping the reference alive lets
66
+ * the process survive across turns; the Shell is dropped once its last
67
+ * background job exits (reaped by the poll loop below). Children stay
68
+ * kill-on-drop, so they still die when the harness tears the Shell down on exit.
69
+ */
70
+ const retainedShells = new Set<Shell>();
71
+ const RETAIN_REAP_INTERVAL_MS = 5_000;
72
+
73
+ async function retainShellWithLiveBackgroundJobs(shell: Shell): Promise<void> {
74
+ let live: number;
75
+ try {
76
+ live = await shell.liveBackgroundJobCount();
77
+ } catch {
78
+ return;
79
+ }
80
+ if (live <= 0) return;
81
+ retainedShells.add(shell);
82
+ const interval = setInterval(() => {
83
+ void shell
84
+ .liveBackgroundJobCount()
85
+ .then(remaining => {
86
+ if (remaining > 0) return;
87
+ clearInterval(interval);
88
+ retainedShells.delete(shell);
89
+ })
90
+ .catch(() => {
91
+ clearInterval(interval);
92
+ retainedShells.delete(shell);
93
+ });
94
+ }, RETAIN_REAP_INTERVAL_MS);
95
+ interval.unref?.();
96
+ }
97
+
62
98
  function quarantineShellSession(
63
99
  sessionKey: string,
64
100
  runPromise: Promise<ShellRunResult>,
@@ -411,6 +447,14 @@ export async function executeBash(command: string, options?: BashExecutorOptions
411
447
  // `:async:` keys are per-job (jobId is unique), so the Shell would
412
448
  // otherwise stay in the process-global map forever after completion.
413
449
  shellSessions.delete(sessionKey);
450
+ // Dropping the only reference to a per-call `:async:` Shell SIGKILLs
451
+ // any `nohup`/`&` children (kill-on-drop). If the command left a live
452
+ // background job, retain the Shell so the process survives across
453
+ // turns; it is reaped once its last job exits and still dies with the
454
+ // harness. Skip on resetSession (cancel/error) — those tear down.
455
+ if (!resetSession && shellSession) {
456
+ await retainShellWithLiveBackgroundJobs(shellSession);
457
+ }
414
458
  }
415
459
  }
416
460
  }
@@ -3,13 +3,13 @@
3
3
  *
4
4
  * The session JSON is gzipped and sealed with a fresh AES-256-GCM key
5
5
  * (`[12B IV][ciphertext+tag]`, same layout as collab frames), then pushed to
6
- * one of two stores:
6
+ * one of two stores, chosen by `share.store`:
7
7
  *
8
- * 1. A secret GitHub gist (preferredfree, durable, no relay storage)
9
- * holding base64 of the sealed blob, when an authenticated `gh` exists.
10
- * 2. The share server (`POST <serverUrl>` `{"id":"…"}`), capped at 1 MB;
11
- * oversized sessions are truncated (images first, then long strings,
12
- * then oldest entries) until the sealed blob fits.
8
+ * 1. The share server (default`POST <serverUrl>` `{"id":"…"}`), capped
9
+ * at 1 MB; oversized sessions are truncated (images first, then long
10
+ * strings, then oldest entries) until the sealed blob fits.
11
+ * 2. A secret GitHub gist (`store: "gist"`, when an authenticated `gh`
12
+ * exists; falls back to the share server) holding base64 of the blob.
13
13
  *
14
14
  * Either way the link is `<serverUrl>/<id>#<base64url key>`. The viewer page
15
15
  * served there fetches the blob (gist ids are hex; server ids never are),
@@ -50,9 +50,17 @@ const TEXT_CAPS = [32_768, 8_192, 2_048, 512];
50
50
  const BLANK_IMAGE_DATA_URL = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
51
51
  const IMAGE_OMITTED_TEXT = "[image omitted from share]";
52
52
 
53
+ export type ShareStore = "blob" | "gist";
54
+
53
55
  export interface ShareSessionOptions {
54
56
  /** Share server/viewer base URL; defaults to {@link DEFAULT_SHARE_URL}. */
55
57
  serverUrl?: string;
58
+ /**
59
+ * Where to upload the sealed blob. `"blob"` (default) posts to the share
60
+ * server; `"gist"` pushes to a secret GitHub gist first (needs an
61
+ * authenticated `gh`) and falls back to the server.
62
+ */
63
+ store?: ShareStore;
56
64
  /** Agent state for system prompt + tool descriptions in the snapshot. */
57
65
  state?: AgentState;
58
66
  /**
@@ -268,7 +276,7 @@ function redactShareMessage(o: SecretObfuscator, message: AgentMessage): AgentMe
268
276
  }
269
277
  }
270
278
 
271
- /** Share the session; tries a secret gist first, then the share server. */
279
+ /** Share the session; uploads to the share server unless `options.store` is `"gist"`. */
272
280
  export async function shareSession(sm: SessionManager, options?: ShareSessionOptions): Promise<ShareSessionResult> {
273
281
  const data = buildShareSnapshot(sm, options);
274
282
  const keyBytes = new Uint8Array(SHARE_KEY_BYTES);
@@ -277,29 +285,23 @@ export async function shareSession(sm: SessionManager, options?: ShareSessionOpt
277
285
  const keyText = Buffer.from(keyBytes).toString("base64url");
278
286
  const base = normalizeShareServerUrl(options?.serverUrl);
279
287
 
280
- const forGist = await sealToFit(key, data, GIST_MAX_SEALED_BYTES);
281
- const gist = await tryCreateGist(forGist.sealed);
282
- if (gist) {
283
- return {
284
- url: `${base}/${gist.id}#${keyText}`,
285
- method: "gist",
286
- gistUrl: gist.url,
287
- truncated: forGist.truncated,
288
- sealedBytes: forGist.sealed.byteLength,
289
- };
288
+ if (options?.store === "gist") {
289
+ const forGist = await sealToFit(key, data, GIST_MAX_SEALED_BYTES);
290
+ const gist = await tryCreateGist(forGist.sealed);
291
+ if (gist) {
292
+ return {
293
+ url: `${base}/${gist.id}#${keyText}`,
294
+ method: "gist",
295
+ gistUrl: gist.url,
296
+ truncated: forGist.truncated,
297
+ sealedBytes: forGist.sealed.byteLength,
298
+ };
299
+ }
300
+ // gh unusable or gist creation failed — fall back to the share server.
301
+ return shareViaServer(key, data, base, keyText, forGist);
290
302
  }
291
303
 
292
- const forServer =
293
- forGist.sealed.byteLength <= SERVER_MAX_SEALED_BYTES
294
- ? forGist
295
- : await sealToFit(key, data, SERVER_MAX_SEALED_BYTES);
296
- const id = await uploadToServer(forServer.sealed, base);
297
- return {
298
- url: `${base}/${id}#${keyText}`,
299
- method: "server",
300
- truncated: forServer.truncated,
301
- sealedBytes: forServer.sealed.byteLength,
302
- };
304
+ return shareViaServer(key, data, base, keyText);
303
305
  }
304
306
 
305
307
  /** Strip trailing slashes so `<base>/<id>` composes cleanly. */
@@ -433,6 +435,27 @@ async function tryCreateGist(sealed: Uint8Array): Promise<{ id: string; url: str
433
435
  }
434
436
  }
435
437
 
438
+ /** Seal to the server cap (reusing `preFit` when it already fits) and upload. */
439
+ async function shareViaServer(
440
+ key: CryptoKey,
441
+ data: SessionData,
442
+ base: string,
443
+ keyText: string,
444
+ preFit?: SealedSession,
445
+ ): Promise<ShareSessionResult> {
446
+ const forServer =
447
+ preFit && preFit.sealed.byteLength <= SERVER_MAX_SEALED_BYTES
448
+ ? preFit
449
+ : await sealToFit(key, data, SERVER_MAX_SEALED_BYTES);
450
+ const id = await uploadToServer(forServer.sealed, base);
451
+ return {
452
+ url: `${base}/${id}#${keyText}`,
453
+ method: "server",
454
+ truncated: forServer.truncated,
455
+ sealedBytes: forServer.sealed.byteLength,
456
+ };
457
+ }
458
+
436
459
  /** POST the sealed blob to the share server; returns the assigned id. */
437
460
  async function uploadToServer(sealed: Uint8Array, base: string): Promise<string> {
438
461
  let res: Response;
@@ -10,6 +10,7 @@ import type { Settings } from "../../config/settings";
10
10
  import type { MemoryRuntimeContext } from "../../memory-backend";
11
11
  import { type Theme, theme } from "../../modes/theme/theme";
12
12
  import type { SessionManager } from "../../session/session-manager";
13
+ import type { BranchHandler, NavigateTreeHandler, NewSessionHandler } from "../session-handler-types";
13
14
  import { createExtensionModelQuery } from "./model-api";
14
15
  import type {
15
16
  AfterProviderResponseEvent,
@@ -141,17 +142,9 @@ type RunnerEmitResult<TEvent extends RunnerEmitEvent> = TEvent extends { type: "
141
142
  ? SessionStopEventResult | undefined
142
143
  : undefined;
143
144
 
144
- export type NewSessionHandler = (options?: {
145
- parentSession?: string;
146
- setup?: (sessionManager: SessionManager) => Promise<void>;
147
- }) => Promise<{ cancelled: boolean }>;
148
-
149
- export type BranchHandler = (entryId: string) => Promise<{ cancelled: boolean }>;
150
-
151
- export type NavigateTreeHandler = (
152
- targetId: string,
153
- options?: { summarize?: boolean },
154
- ) => Promise<{ cancelled: boolean }>;
145
+ // Session-lifecycle handler types live once in session-handler-types (imported
146
+ // above for local use); re-exported here to keep this module's public API stable.
147
+ export type { BranchHandler, NavigateTreeHandler, NewSessionHandler };
155
148
 
156
149
  export type SwitchSessionHandler = (sessionPath: string) => Promise<{ cancelled: boolean }>;
157
150
 
@@ -11,7 +11,6 @@ import { loadCapability } from "../../discovery";
11
11
  // Runtime self-reference: dereference this namespace only inside loader functions to keep the index.ts cycle safe.
12
12
  import * as PiCodingAgent from "../../index";
13
13
  import type { HookMessage } from "../../session/messages";
14
- import type { SessionManager } from "../../session/session-manager";
15
14
  import * as typebox from "../typebox";
16
15
  import { resolvePath } from "../utils";
17
16
  import { execCommand } from "./runner";
@@ -35,26 +34,9 @@ export type SendMessageHandler = <T = unknown>(
35
34
  */
36
35
  export type AppendEntryHandler = <T = unknown>(customType: string, data?: T) => void;
37
36
 
38
- /**
39
- * New session handler type for ctx.newSession() in HookCommandContext.
40
- */
41
- export type NewSessionHandler = (options?: {
42
- parentSession?: string;
43
- setup?: (sessionManager: SessionManager) => Promise<void>;
44
- }) => Promise<{ cancelled: boolean }>;
45
-
46
- /**
47
- * Branch handler type for ctx.branch() in HookCommandContext.
48
- */
49
- export type BranchHandler = (entryId: string) => Promise<{ cancelled: boolean }>;
50
-
51
- /**
52
- * Navigate tree handler type for ctx.navigateTree() in HookCommandContext.
53
- */
54
- export type NavigateTreeHandler = (
55
- targetId: string,
56
- options?: { summarize?: boolean },
57
- ) => Promise<{ cancelled: boolean }>;
37
+ // Session-lifecycle handler types live once in session-handler-types; re-exported
38
+ // here because hooks/runner.ts imports them from this module.
39
+ export type { BranchHandler, NavigateTreeHandler, NewSessionHandler } from "../session-handler-types";
58
40
 
59
41
  /**
60
42
  * Registered handlers for a loaded hook.
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Session-lifecycle handler types shared by the extension runner and the hook
3
+ * loader/runner. Both surfaces wire the same new-session / branch / navigate
4
+ * handlers into their command contexts; this is the single source of truth.
5
+ */
6
+ import type { SessionManager } from "../session/session-manager";
7
+
8
+ /** Handler for `ctx.newSession()` — creates (and optionally seeds) a session. */
9
+ export type NewSessionHandler = (options?: {
10
+ parentSession?: string;
11
+ setup?: (sessionManager: SessionManager) => Promise<void>;
12
+ }) => Promise<{ cancelled: boolean }>;
13
+
14
+ /** Handler for `ctx.branch()` — branches from a transcript entry. */
15
+ export type BranchHandler = (entryId: string) => Promise<{ cancelled: boolean }>;
16
+
17
+ /** Handler for `ctx.navigateTree()` — navigates the session tree. */
18
+ export type NavigateTreeHandler = (
19
+ targetId: string,
20
+ options?: { summarize?: boolean },
21
+ ) => Promise<{ cancelled: boolean }>;