@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
@@ -1,4 +1,5 @@
1
1
  import type { AgentMessage } from "@oh-my-pi/pi-agent-core";
2
+ import { type SecretObfuscator } from "../secrets/obfuscator";
2
3
  /** Minimal slice of `Agent` the runtime drives — satisfied by pi-agent-core `Agent`. */
3
4
  export interface AdvisorAgent {
4
5
  prompt(input: string): Promise<void>;
@@ -13,6 +14,8 @@ export interface AdvisorRuntimeHost {
13
14
  snapshotMessages(): AgentMessage[];
14
15
  /** Surface one advice note to the primary (enqueues into the session YieldQueue). */
15
16
  enqueueAdvice(note: string, severity?: "nit" | "concern" | "blocker"): void;
17
+ /** Redact primary transcript bytes before they reach the advisor model. */
18
+ obfuscator?: SecretObfuscator;
16
19
  /**
17
20
  * Pre-prompt context maintenance for the advisor's own append-only context.
18
21
  * Promotes the advisor model to a larger sibling when its context nears the
@@ -1636,6 +1636,26 @@ export declare const SETTINGS_SCHEMA: {
1636
1636
  readonly description: "Share viewer/upload base used by /share (encrypted blob upload + viewer; links are <base>/<id>#<key>)";
1637
1637
  };
1638
1638
  };
1639
+ readonly "share.store": {
1640
+ readonly type: "enum";
1641
+ readonly values: readonly ["blob", "gist"];
1642
+ readonly default: "blob";
1643
+ readonly ui: {
1644
+ readonly tab: "interaction";
1645
+ readonly group: "Collab";
1646
+ readonly label: "Share Store";
1647
+ readonly description: "Where /share uploads the encrypted session blob";
1648
+ readonly options: readonly [{
1649
+ readonly value: "blob";
1650
+ readonly label: "Encrypted Blob";
1651
+ readonly description: "Upload to the share server (no GitHub account needed; avoids gist API rate limits)";
1652
+ }, {
1653
+ readonly value: "gist";
1654
+ readonly label: "GitHub Gist";
1655
+ readonly description: "Push to a secret gist (needs authenticated gh), falling back to the share server";
1656
+ }];
1657
+ };
1658
+ };
1639
1659
  readonly "share.redactSecrets": {
1640
1660
  readonly type: "boolean";
1641
1661
  readonly default: true;
@@ -2886,16 +2906,6 @@ export declare const SETTINGS_SCHEMA: {
2886
2906
  readonly description: "Prepend line numbers to read tool output by default";
2887
2907
  };
2888
2908
  };
2889
- readonly readHashLines: {
2890
- readonly type: "boolean";
2891
- readonly default: true;
2892
- readonly ui: {
2893
- readonly tab: "files";
2894
- readonly group: "Reading";
2895
- readonly label: "Hash Lines";
2896
- readonly description: "Include snapshot-tag headers and line numbers in read output for hashline edit mode ([PATH#TAG] plus LINE:content)";
2897
- };
2898
- };
2899
2909
  readonly "read.defaultLimit": {
2900
2910
  readonly type: "number";
2901
2911
  readonly default: 300;
@@ -3152,7 +3162,7 @@ export declare const SETTINGS_SCHEMA: {
3152
3162
  readonly default: true;
3153
3163
  readonly ui: {
3154
3164
  readonly tab: "shell";
3155
- readonly group: "Eval & Python";
3165
+ readonly group: "Eval & Runtimes";
3156
3166
  readonly label: "Python Eval Backend";
3157
3167
  readonly description: "Allow the eval tool to dispatch Python cells to the IPython kernel";
3158
3168
  };
@@ -3162,18 +3172,38 @@ export declare const SETTINGS_SCHEMA: {
3162
3172
  readonly default: true;
3163
3173
  readonly ui: {
3164
3174
  readonly tab: "shell";
3165
- readonly group: "Eval & Python";
3175
+ readonly group: "Eval & Runtimes";
3166
3176
  readonly label: "JavaScript Eval Backend";
3167
3177
  readonly description: "Allow the eval tool to dispatch JavaScript cells to the in-process runtime";
3168
3178
  };
3169
3179
  };
3180
+ readonly "eval.rb": {
3181
+ readonly type: "boolean";
3182
+ readonly default: false;
3183
+ readonly ui: {
3184
+ readonly tab: "shell";
3185
+ readonly group: "Eval & Runtimes";
3186
+ readonly label: "Ruby Eval Backend";
3187
+ readonly description: "Allow the eval tool to dispatch Ruby cells to the persistent Ruby kernel";
3188
+ };
3189
+ };
3190
+ readonly "eval.jl": {
3191
+ readonly type: "boolean";
3192
+ readonly default: false;
3193
+ readonly ui: {
3194
+ readonly tab: "shell";
3195
+ readonly group: "Eval & Runtimes";
3196
+ readonly label: "Julia Eval Backend";
3197
+ readonly description: "Allow the eval tool to dispatch Julia cells to the persistent Julia kernel";
3198
+ };
3199
+ };
3170
3200
  readonly "python.kernelMode": {
3171
3201
  readonly type: "enum";
3172
3202
  readonly values: readonly ["session", "per-call"];
3173
3203
  readonly default: "session";
3174
3204
  readonly ui: {
3175
3205
  readonly tab: "shell";
3176
- readonly group: "Eval & Python";
3206
+ readonly group: "Eval & Runtimes";
3177
3207
  readonly label: "Python Kernel Mode";
3178
3208
  readonly description: "Keep the IPython kernel alive across eval calls or start fresh each time";
3179
3209
  };
@@ -3183,11 +3213,31 @@ export declare const SETTINGS_SCHEMA: {
3183
3213
  readonly default: "";
3184
3214
  readonly ui: {
3185
3215
  readonly tab: "shell";
3186
- readonly group: "Eval & Python";
3216
+ readonly group: "Eval & Runtimes";
3187
3217
  readonly label: "Python Interpreter";
3188
3218
  readonly description: "Optional path to an exact Python executable. When set, automatic Python runtime discovery is skipped.";
3189
3219
  };
3190
3220
  };
3221
+ readonly "ruby.interpreter": {
3222
+ readonly type: "string";
3223
+ readonly default: "";
3224
+ readonly ui: {
3225
+ readonly tab: "shell";
3226
+ readonly group: "Eval & Runtimes";
3227
+ readonly label: "Ruby Interpreter";
3228
+ readonly description: "Optional path to an exact Ruby executable. When set, automatic Ruby runtime discovery is skipped.";
3229
+ };
3230
+ };
3231
+ readonly "julia.interpreter": {
3232
+ readonly type: "string";
3233
+ readonly default: "";
3234
+ readonly ui: {
3235
+ readonly tab: "shell";
3236
+ readonly group: "Eval & Runtimes";
3237
+ readonly label: "Julia Interpreter";
3238
+ readonly description: "Optional path to an exact Julia executable. When set, automatic Julia runtime discovery is skipped.";
3239
+ };
3240
+ };
3191
3241
  readonly "tools.approval": {
3192
3242
  readonly type: "record";
3193
3243
  readonly default: {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Helpers shared by the per-language eval backend definitions (jl/js/py/rb
3
+ * index modules): session-id namespacing, settings access, and projection of
4
+ * executor results into the ExecutorBackend result shape.
5
+ */
6
+ import type { ToolSession } from "../tools";
7
+ import type { ExecutorBackendResult } from "./backend";
8
+ import type { EvalDisplayOutput } from "./types";
9
+ export declare function namespaceSessionId(sessionId: string, prefix: string): string;
10
+ export declare function readSetting<T>(session: ToolSession, key: string): T | undefined;
11
+ export declare function readInterpreterSetting(session: ToolSession, key: string): string | undefined;
12
+ export declare function toExecutorBackendResult(result: {
13
+ output: string;
14
+ exitCode: number | undefined;
15
+ cancelled: boolean;
16
+ truncated: boolean;
17
+ artifactId?: string | undefined;
18
+ totalLines: number;
19
+ totalBytes: number;
20
+ outputLines: number;
21
+ outputBytes: number;
22
+ displayOutputs: EvalDisplayOutput[];
23
+ }): ExecutorBackendResult;
@@ -0,0 +1,118 @@
1
+ import type { ToolSession } from "../tools";
2
+ import type { JsStatusEvent } from "./js/shared/types";
3
+ import type { KernelDisplayOutput } from "./py/display";
4
+ /**
5
+ * Constructor for a language executor's cancellation error. Each backend
6
+ * subclasses {@link Error} and carries a `timedOut` flag distinguishing a
7
+ * deadline expiry from a plain abort.
8
+ */
9
+ export type CancelledErrorClass = new (timedOut: boolean) => Error & {
10
+ timedOut: boolean;
11
+ };
12
+ /** Managed-env values a kernel patch may carry (`null` clears, `undefined` skips). */
13
+ export type KernelEnvPatch = Record<string, string | null | undefined>;
14
+ /**
15
+ * Options every kernel-backed language executor shares. Per-language option
16
+ * interfaces structurally extend this; the base executor only reads these.
17
+ */
18
+ export interface KernelExecutorBaseOptions {
19
+ cwd?: string;
20
+ timeoutMs?: number;
21
+ deadlineMs?: number;
22
+ idleTimeoutMs?: number;
23
+ onChunk?: (chunk: string) => Promise<void> | void;
24
+ signal?: AbortSignal;
25
+ onStatus?: (event: JsStatusEvent) => void;
26
+ emitStatus?: (event: JsStatusEvent) => void;
27
+ toolSession?: ToolSession;
28
+ bridgeSessionId?: string;
29
+ artifactId?: string;
30
+ artifactPath?: string;
31
+ }
32
+ /** Normalised execution result produced by {@link executeWithKernelBase}. */
33
+ export interface KernelExecutionResult {
34
+ output: string;
35
+ exitCode: number | undefined;
36
+ cancelled: boolean;
37
+ truncated: boolean;
38
+ artifactId: string | undefined;
39
+ totalLines: number;
40
+ totalBytes: number;
41
+ outputLines: number;
42
+ outputBytes: number;
43
+ displayOutputs: KernelDisplayOutput[];
44
+ stdinRequested: boolean;
45
+ }
46
+ /** Minimal kernel surface the base executor drives, satisfied by every backend kernel. */
47
+ export interface GenericKernel<TEnv> {
48
+ execute(code: string, options: {
49
+ cwd?: string;
50
+ env?: TEnv;
51
+ id: string;
52
+ signal?: AbortSignal;
53
+ timeoutMs?: number;
54
+ onChunk: (text: string) => Promise<void> | void;
55
+ onDisplay: (output: KernelDisplayOutput) => Promise<void> | void;
56
+ }): Promise<{
57
+ status: "ok" | "error";
58
+ cancelled: boolean;
59
+ timedOut: boolean;
60
+ kernelKilled?: boolean;
61
+ stdinRequested?: boolean;
62
+ }>;
63
+ }
64
+ export declare function getExecutionDeadlineMs(options?: {
65
+ deadlineMs?: number;
66
+ timeoutMs?: number;
67
+ }): number | undefined;
68
+ export declare function getRemainingTimeoutMs(deadlineMs?: number): number | undefined;
69
+ export declare function isCancellationError(error: unknown, cancelledErrorClass: CancelledErrorClass): boolean;
70
+ export declare function isTimedOutCancellation(error: unknown, cancelledErrorClass: CancelledErrorClass, signal?: AbortSignal): boolean;
71
+ export declare function waitForPromiseWithCancellation<T>(promise: Promise<T>, options: {
72
+ signal?: AbortSignal;
73
+ deadlineMs?: number;
74
+ }, cancelledErrorClass: CancelledErrorClass): Promise<T>;
75
+ export declare function createCancelledKernelResult(output: string): KernelExecutionResult;
76
+ export declare const MANAGED_KERNEL_ENV_KEYS: readonly ["PI_SESSION_FILE", "PI_ARTIFACTS_DIR", "PI_TOOL_BRIDGE_URL", "PI_TOOL_BRIDGE_TOKEN", "PI_TOOL_BRIDGE_SESSION", "PI_EVAL_LOCAL_ROOTS"];
77
+ interface ManagedKernelEnvOptions {
78
+ sessionFile?: string;
79
+ artifactsDir?: string;
80
+ bridgeSessionId?: string;
81
+ bridge?: {
82
+ url: string;
83
+ token: string;
84
+ };
85
+ localRoots?: Record<string, string>;
86
+ }
87
+ export declare function buildManagedKernelEnvPatch(options: ManagedKernelEnvOptions): Record<string, string | null>;
88
+ export declare function buildManagedKernelEnv(options: ManagedKernelEnvOptions): Record<string, string> | undefined;
89
+ export declare function attachSessionOwner(session: {
90
+ ownerIds: Set<string>;
91
+ hasFallbackOwner: boolean;
92
+ }, sessionId: string, ownerId: string | undefined): void;
93
+ export interface ExecuteWithKernelBaseParams<TOptions extends KernelExecutorBaseOptions, TEnv extends KernelEnvPatch = Record<string, string | null>> {
94
+ kernel: GenericKernel<TEnv>;
95
+ code: string;
96
+ options: TOptions | undefined;
97
+ /** Prefix for the per-execution run id (e.g. `"py"`, `"rb"`, `"jl"`). */
98
+ runIdPrefix: string;
99
+ /** Human-readable language label used in the failure log line. */
100
+ errorLogLabel: string;
101
+ /**
102
+ * Julia surfaces eval-timeout control events through its normal status path,
103
+ * so they must NOT be filtered out the way the JS-status backends do.
104
+ */
105
+ isJulia?: boolean;
106
+ cancelledErrorClass: CancelledErrorClass;
107
+ buildKernelEnvPatch: (options: TOptions) => TEnv;
108
+ formatKernelTimeoutAnnotation: (executionTimeoutMs: number | undefined, kernelKilled: boolean) => string;
109
+ formatTimeoutAnnotation: (executionTimeoutMs: number | undefined) => string | undefined;
110
+ /**
111
+ * Override how the wall-clock deadline is derived from options. Defaults to
112
+ * {@link getExecutionDeadlineMs}; Julia passes the pre-computed `deadlineMs`
113
+ * straight through instead of re-deriving from `timeoutMs`.
114
+ */
115
+ resolveDeadlineMs?: (options: TOptions | undefined) => number | undefined;
116
+ }
117
+ export declare function executeWithKernelBase<TOptions extends KernelExecutorBaseOptions, TEnv extends KernelEnvPatch = Record<string, string | null>>(params: ExecuteWithKernelBaseParams<TOptions, TEnv>): Promise<KernelExecutionResult>;
118
+ export {};
@@ -1,4 +1,6 @@
1
1
  export * from "./backend";
2
+ export { default as juliaBackend } from "./jl";
2
3
  export { default as jsBackend } from "./js";
3
4
  export { default as pythonBackend } from "./py";
5
+ export { default as rubyBackend } from "./rb";
4
6
  export * from "./types";
@@ -0,0 +1,44 @@
1
+ import type { ToolSession } from "../../tools";
2
+ import { type PyToolBridgeInfo } from "../py/tool-bridge";
3
+ import type { EvalDisplayOutput, EvalStatusEvent } from "../types";
4
+ import { JuliaKernel, type KernelExecuteOptions, type KernelExecuteResult } from "./kernel";
5
+ export interface JuliaExecutorOptions {
6
+ cwd?: string;
7
+ sessionId?: string;
8
+ sessionFile?: string;
9
+ artifactsDir?: string;
10
+ localRoots?: Record<string, string>;
11
+ interpreter?: string;
12
+ onChunk?: (text: string) => void | Promise<void>;
13
+ onStatus?: (event: EvalStatusEvent) => void;
14
+ signal?: AbortSignal;
15
+ timeoutMs?: number;
16
+ deadlineMs?: number;
17
+ idleTimeoutMs?: number;
18
+ kernelOwnerId?: string;
19
+ reset?: boolean;
20
+ toolSession?: ToolSession;
21
+ bridge?: PyToolBridgeInfo;
22
+ bridgeSessionId?: string;
23
+ artifactId?: string;
24
+ }
25
+ export interface JuliaKernelExecutor {
26
+ execute: (code: string, options?: KernelExecuteOptions) => Promise<KernelExecuteResult>;
27
+ }
28
+ export interface JuliaResult {
29
+ output: string;
30
+ exitCode: number | undefined;
31
+ cancelled: boolean;
32
+ truncated: boolean;
33
+ artifactId: string | undefined;
34
+ totalLines: number;
35
+ totalBytes: number;
36
+ outputLines: number;
37
+ outputBytes: number;
38
+ displayOutputs: EvalDisplayOutput[];
39
+ stdinRequested: boolean;
40
+ }
41
+ export declare function disposeAllJuliaKernelSessions(): Promise<void>;
42
+ export declare function disposeJuliaKernelSessionsByOwner(ownerId: string): Promise<void>;
43
+ export declare function executeJuliaWithKernel(kernel: JuliaKernel, code: string, options?: JuliaExecutorOptions): Promise<JuliaResult>;
44
+ export declare function executeJulia(code: string, options?: JuliaExecutorOptions): Promise<JuliaResult>;
@@ -0,0 +1,11 @@
1
+ import type { ToolSession } from "../../tools";
2
+ import { type ExecutorBackendExecOptions, type ExecutorBackendResult } from "../backend";
3
+ export declare function namespaceSessionId(sessionId: string): string;
4
+ declare const _default: {
5
+ id: "julia";
6
+ label: string;
7
+ highlightLang: string;
8
+ isAvailable(session: ToolSession): Promise<boolean>;
9
+ execute(code: string, opts: ExecutorBackendExecOptions): Promise<ExecutorBackendResult>;
10
+ };
11
+ export default _default;
@@ -0,0 +1,28 @@
1
+ import { BaseKernel, type KernelStartOptions } from "../kernel-base";
2
+ import type { KernelDisplayOutput } from "../py/display";
3
+ import { type JuliaRuntime } from "./runtime";
4
+ export type { KernelExecuteResult, KernelRuntimeEnv } from "../kernel-base";
5
+ export { renderKernelDisplay } from "../py/display";
6
+ export type { KernelDisplayOutput };
7
+ export interface KernelExecuteOptions {
8
+ id?: string;
9
+ cwd?: string;
10
+ env?: Record<string, string | undefined>;
11
+ silent?: boolean;
12
+ storeHistory?: boolean;
13
+ timeoutMs?: number;
14
+ signal?: AbortSignal;
15
+ onChunk?: (text: string) => void | Promise<void>;
16
+ onDisplay?: (output: KernelDisplayOutput) => void | Promise<void>;
17
+ }
18
+ export interface JuliaKernelAvailability {
19
+ ok: boolean;
20
+ juliaPath?: string;
21
+ runtime?: JuliaRuntime;
22
+ reason?: string;
23
+ }
24
+ export declare function checkJuliaKernelAvailability(cwd: string, interpreter?: string): Promise<JuliaKernelAvailability>;
25
+ export declare class JuliaKernel extends BaseKernel<KernelExecuteOptions> {
26
+ private constructor();
27
+ static start(options: KernelStartOptions): Promise<JuliaKernel>;
28
+ }
@@ -0,0 +1 @@
1
+ export declare const JULIA_PRELUDE: string;
@@ -0,0 +1,22 @@
1
+ export interface JuliaRuntime {
2
+ /** Path to the julia executable. */
3
+ juliaPath: string;
4
+ /** Filtered environment variables. */
5
+ env: Record<string, string | undefined>;
6
+ }
7
+ export declare const filterEnv: (env: Record<string, string | undefined>) => Record<string, string | undefined>;
8
+ /**
9
+ * Resolve an explicitly configured interpreter (`julia.interpreter`) into a
10
+ * runtime, bypassing discovery. Does not probe the executable.
11
+ * `~` expands to the home directory and relative paths resolve against `cwd`.
12
+ */
13
+ export declare function resolveExplicitJuliaRuntime(interpreter: string, cwd: string, baseEnv: Record<string, string | undefined>): JuliaRuntime;
14
+ /**
15
+ * Enumerate candidate Julia runtimes in priority order. With an explicit
16
+ * interpreter that is the only candidate; otherwise the first `julia` on PATH.
17
+ */
18
+ export declare function enumerateJuliaRuntimes(cwd: string, baseEnv: Record<string, string | undefined>, interpreter?: string): JuliaRuntime[];
19
+ /**
20
+ * Resolve the highest-priority Julia runtime. Throws when none exists.
21
+ */
22
+ export declare function resolveJuliaRuntime(cwd: string, baseEnv: Record<string, string | undefined>, interpreter?: string): JuliaRuntime;
@@ -0,0 +1,105 @@
1
+ import type { Subprocess } from "bun";
2
+ import { type KernelDisplayOutput } from "./py/display";
3
+ export type KernelRuntimeEnv = Record<string, string | null>;
4
+ export interface KernelExecuteOptions {
5
+ id?: string;
6
+ /** Runtime working directory applied immediately before this request executes. */
7
+ cwd?: string;
8
+ /** Managed runtime environment variables applied immediately before this request executes. */
9
+ env?: Record<string, string | undefined> | Record<string, string | null>;
10
+ signal?: AbortSignal;
11
+ onChunk?: (text: string) => Promise<void> | void;
12
+ onDisplay?: (output: KernelDisplayOutput) => Promise<void> | void;
13
+ timeoutMs?: number;
14
+ silent?: boolean;
15
+ storeHistory?: boolean;
16
+ allowStdin?: boolean;
17
+ }
18
+ export interface KernelExecuteResult {
19
+ status: "ok" | "error";
20
+ executionCount?: number;
21
+ error?: {
22
+ name: string;
23
+ value: string;
24
+ traceback: string[];
25
+ };
26
+ cancelled: boolean;
27
+ timedOut: boolean;
28
+ stdinRequested: boolean;
29
+ /**
30
+ * True when the kernel subprocess was killed as part of settling this
31
+ * execution (e.g. SIGINT was ignored and we escalated to shutdown, or the
32
+ * kernel died unexpectedly). When false, the kernel remains reusable.
33
+ */
34
+ kernelKilled?: boolean;
35
+ }
36
+ export interface KernelShutdownResult {
37
+ confirmed: boolean;
38
+ }
39
+ export interface KernelShutdownOptions {
40
+ signal?: AbortSignal;
41
+ timeoutMs?: number;
42
+ }
43
+ /** Per-language lifecycle configuration consumed by each kernel's `start()`. */
44
+ export interface KernelStartOptions {
45
+ cwd: string;
46
+ env?: Record<string, string | undefined>;
47
+ /** Explicit interpreter path; skips discovery when set. */
48
+ interpreter?: string;
49
+ signal?: AbortSignal;
50
+ deadlineMs?: number;
51
+ }
52
+ /** Per-language configuration handed to {@link BaseKernel} by each subclass. */
53
+ export interface BaseKernelOptions<TExecuteOptions extends KernelExecuteOptions = KernelExecuteOptions> {
54
+ /** Human-readable language label used in log messages and errors. */
55
+ languageName: string;
56
+ /** When true, every IPC frame is logged at debug level. */
57
+ traceIpc: boolean;
58
+ /** Wire payload asking the runner to exit cleanly. */
59
+ exitPayload: string;
60
+ /** How long to wait after SIGINT before escalating to subprocess termination. */
61
+ interruptEscalationMs: number;
62
+ /** Default grace period applied by {@link BaseKernel.shutdown}. */
63
+ shutdownGraceMs: number;
64
+ /** Serializes an execution request into the runner's wire protocol. */
65
+ buildPayload: (code: string, msgId: string, options?: TExecuteOptions) => string;
66
+ }
67
+ export type FrameType = "started" | "stdout" | "stderr" | "display" | "result" | "error" | "done";
68
+ export interface Frame {
69
+ type: FrameType;
70
+ id?: string;
71
+ data?: string;
72
+ bundle?: Record<string, unknown>;
73
+ ename?: string;
74
+ evalue?: string;
75
+ traceback?: string[];
76
+ status?: "ok" | "error";
77
+ executionCount?: number;
78
+ cancelled?: boolean;
79
+ }
80
+ export declare function getRemainingTimeMs(deadlineMs?: number): number | undefined;
81
+ export declare function createAbortError(name: "AbortError" | "TimeoutError", message: string): Error;
82
+ export declare function throwIfAborted(signal: AbortSignal | undefined, fallbackReason: string): void;
83
+ export declare function isTimeoutReason(reason: unknown): boolean;
84
+ /**
85
+ * Shared subprocess-backed kernel machinery for the language runners. Each
86
+ * language subclasses this, supplying its binary/runner via a static `start()`
87
+ * and its wire protocol via {@link BaseKernelOptions.buildPayload}. The IPC loop
88
+ * speaks NDJSON: the runner emits one JSON {@link Frame} per line; outbound
89
+ * requests are serialized by `buildPayload` (which may itself be NDJSON or any
90
+ * other line-delimited encoding).
91
+ *
92
+ * `TExecuteOptions` is the language's own execute-options type so each runner's
93
+ * `buildPayload` sees its precise option shape (e.g. environment-map variants).
94
+ */
95
+ export declare abstract class BaseKernel<TExecuteOptions extends KernelExecuteOptions = KernelExecuteOptions> {
96
+ #private;
97
+ readonly id: string;
98
+ constructor(id: string, options: BaseKernelOptions<TExecuteOptions>);
99
+ setProcess(proc: Subprocess<"pipe", "pipe", "pipe">): void;
100
+ isAlive(): boolean;
101
+ execute(code: string, options?: TExecuteOptions): Promise<KernelExecuteResult>;
102
+ interrupt(): Promise<void>;
103
+ shutdown(options?: KernelShutdownOptions): Promise<KernelShutdownResult>;
104
+ executeWithBudget(code: string, signal: AbortSignal | undefined, timeoutMs: number, label: string): Promise<void>;
105
+ }
@@ -1,60 +1,8 @@
1
- import { type KernelDisplayOutput } from "./display";
1
+ import { BaseKernel, type KernelStartOptions } from "../kernel-base";
2
2
  import { type PythonRuntime } from "./runtime";
3
+ export type { KernelExecuteOptions, KernelExecuteResult, KernelRuntimeEnv, KernelShutdownOptions, KernelShutdownResult, } from "../kernel-base";
3
4
  export type { KernelDisplayOutput, PythonStatusEvent } from "./display";
4
5
  export { renderKernelDisplay } from "./display";
5
- export type KernelRuntimeEnv = Record<string, string | null>;
6
- export interface KernelExecuteOptions {
7
- id?: string;
8
- /** Runtime working directory applied immediately before this request executes. */
9
- cwd?: string;
10
- /** Managed runtime environment variables applied immediately before this request executes. */
11
- env?: KernelRuntimeEnv;
12
- signal?: AbortSignal;
13
- onChunk?: (text: string) => Promise<void> | void;
14
- onDisplay?: (output: KernelDisplayOutput) => Promise<void> | void;
15
- timeoutMs?: number;
16
- silent?: boolean;
17
- storeHistory?: boolean;
18
- allowStdin?: boolean;
19
- }
20
- export interface KernelExecuteResult {
21
- status: "ok" | "error";
22
- executionCount?: number;
23
- error?: {
24
- name: string;
25
- value: string;
26
- traceback: string[];
27
- };
28
- cancelled: boolean;
29
- timedOut: boolean;
30
- stdinRequested: boolean;
31
- /**
32
- * True when the kernel subprocess was killed as part of settling this
33
- * execution (e.g. SIGINT was ignored and we escalated to shutdown, or the
34
- * kernel died unexpectedly). When false, the kernel remains reusable.
35
- */
36
- kernelKilled?: boolean;
37
- }
38
- export interface KernelShutdownResult {
39
- confirmed: boolean;
40
- }
41
- interface KernelLifecycleOptions {
42
- signal?: AbortSignal;
43
- deadlineMs?: number;
44
- }
45
- interface KernelStartOptions extends KernelLifecycleOptions {
46
- cwd: string;
47
- env?: Record<string, string | undefined>;
48
- /**
49
- * Explicit interpreter path (`python.interpreter` from the session's
50
- * settings). When set, runtime discovery is skipped entirely.
51
- */
52
- interpreter?: string;
53
- }
54
- interface KernelShutdownOptions {
55
- signal?: AbortSignal;
56
- timeoutMs?: number;
57
- }
58
6
  export interface PythonKernelAvailability {
59
7
  ok: boolean;
60
8
  pythonPath?: string;
@@ -63,13 +11,7 @@ export interface PythonKernelAvailability {
63
11
  runtime?: PythonRuntime;
64
12
  }
65
13
  export declare function checkPythonKernelAvailability(cwd: string, interpreter?: string): Promise<PythonKernelAvailability>;
66
- export declare class PythonKernel {
67
- #private;
68
- readonly id: string;
14
+ export declare class PythonKernel extends BaseKernel {
69
15
  private constructor();
70
16
  static start(options: KernelStartOptions): Promise<PythonKernel>;
71
- isAlive(): boolean;
72
- execute(code: string, options?: KernelExecuteOptions): Promise<KernelExecuteResult>;
73
- interrupt(): Promise<void>;
74
- shutdown(options?: KernelShutdownOptions): Promise<KernelShutdownResult>;
75
17
  }
@@ -0,0 +1,77 @@
1
+ import type { ToolSession } from "../../tools";
2
+ import type { JsStatusEvent } from "../js/shared/types";
3
+ import { type KernelDisplayOutput, type KernelExecuteOptions, type KernelExecuteResult } from "./kernel";
4
+ export interface RubyExecutorOptions {
5
+ /** Working directory for command execution */
6
+ cwd?: string;
7
+ /** Timeout in milliseconds */
8
+ timeoutMs?: number;
9
+ /** Absolute wall-clock deadline in milliseconds since epoch */
10
+ deadlineMs?: number;
11
+ /**
12
+ * Runtime-work budget (ms). Used only for timeout-annotation text when the
13
+ * caller drives cancellation via the eval watchdog `signal`. Does not arm a timer.
14
+ */
15
+ idleTimeoutMs?: number;
16
+ /** Callback for streaming output chunks (already sanitized) */
17
+ onChunk?: (chunk: string) => Promise<void> | void;
18
+ /** AbortSignal for cancellation */
19
+ signal?: AbortSignal;
20
+ /** Session identifier for kernel reuse */
21
+ sessionId?: string;
22
+ /** Logical owner identifier for retained kernel cleanup */
23
+ kernelOwnerId?: string;
24
+ /** Explicit interpreter path (`ruby.interpreter`). Skips discovery when set. */
25
+ interpreter?: string;
26
+ /** Restart the kernel before executing */
27
+ reset?: boolean;
28
+ /** Session file path for accessing task outputs */
29
+ sessionFile?: string;
30
+ /** Effective artifacts directory for the current session. */
31
+ artifactsDir?: string;
32
+ /** Artifact path/id for full output storage */
33
+ artifactPath?: string;
34
+ artifactId?: string;
35
+ /**
36
+ * On-disk roots the prelude helpers substitute for internal-URL schemes
37
+ * (e.g. `{ local: "/…/artifacts/local" }`). Exported to the kernel as
38
+ * `PI_EVAL_LOCAL_ROOTS` (JSON).
39
+ */
40
+ localRoots?: Record<string, string>;
41
+ /**
42
+ * ToolSession used to resolve host-side `tool.<name>(args)` calls. When
43
+ * omitted, the bridge env vars are not injected and `tool.foo(...)` raises.
44
+ */
45
+ toolSession?: ToolSession;
46
+ /** Callback for status events emitted by tool bridge invocations. */
47
+ emitStatus?: (event: JsStatusEvent) => void;
48
+ /** Live status events streamed as they are emitted. */
49
+ onStatus?: (event: JsStatusEvent) => void;
50
+ /** @internal Bridge session id, set by `executeRuby` before delegating. */
51
+ bridgeSessionId?: string;
52
+ /** @internal Bridge endpoint info, set by `executeRuby` before delegating. */
53
+ bridge?: {
54
+ url: string;
55
+ token: string;
56
+ };
57
+ }
58
+ export interface RubyKernelExecutor {
59
+ execute: (code: string, options?: KernelExecuteOptions) => Promise<KernelExecuteResult>;
60
+ }
61
+ export interface RubyResult {
62
+ output: string;
63
+ exitCode: number | undefined;
64
+ cancelled: boolean;
65
+ truncated: boolean;
66
+ artifactId?: string;
67
+ totalLines: number;
68
+ totalBytes: number;
69
+ outputLines: number;
70
+ outputBytes: number;
71
+ displayOutputs: KernelDisplayOutput[];
72
+ stdinRequested: boolean;
73
+ }
74
+ export declare function disposeAllRubyKernelSessions(): Promise<void>;
75
+ export declare function disposeRubyKernelSessionsByOwner(ownerId: string): Promise<void>;
76
+ export declare function executeRubyWithKernel(kernel: RubyKernelExecutor, code: string, options?: RubyExecutorOptions): Promise<RubyResult>;
77
+ export declare function executeRuby(code: string, options?: RubyExecutorOptions): Promise<RubyResult>;