@code-yeongyu/senpi-codemode 2026.7.25-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.
- package/CHANGELOG.md +250 -0
- package/LICENSE +22 -0
- package/README.md +161 -0
- package/package.json +58 -0
- package/src/bridge/http-server.ts +236 -0
- package/src/bridge/protocol.ts +198 -0
- package/src/bridge/reserved.ts +9 -0
- package/src/bridges/agent-bridge.ts +197 -0
- package/src/bridges/output-bridge.ts +96 -0
- package/src/bridges/schema-injection.ts +3 -0
- package/src/codemode/runtime.ts +258 -0
- package/src/codemode/tools.ts +106 -0
- package/src/completion/handler.ts +192 -0
- package/src/completion/tool-bridge.ts +55 -0
- package/src/config/settings.ts +215 -0
- package/src/extension/runtime-factory.ts +114 -0
- package/src/extension/session-manager-proxy.ts +116 -0
- package/src/extension/session-manager.ts +215 -0
- package/src/host-sdk.ts +1 -0
- package/src/index.ts +181 -0
- package/src/interpreters/detect.ts +161 -0
- package/src/kernels/jl/kernel.ts +37 -0
- package/src/kernels/jl/prelude.jl +283 -0
- package/src/kernels/jl/runner.jl +327 -0
- package/src/kernels/js/context-manager.ts +296 -0
- package/src/kernels/js/inline-worker-entry.js +23 -0
- package/src/kernels/js/inline-worker.ts +15 -0
- package/src/kernels/js/kernel-contract.ts +38 -0
- package/src/kernels/js/local-module-loader.ts +108 -0
- package/src/kernels/js/prelude.ts +15 -0
- package/src/kernels/js/rewrite-imports.ts +164 -0
- package/src/kernels/js/run-queue.ts +82 -0
- package/src/kernels/js/worker-core.d.ts +18 -0
- package/src/kernels/js/worker-core.js +94 -0
- package/src/kernels/js/worker-entry.js +23 -0
- package/src/kernels/js/worker-host.ts +117 -0
- package/src/kernels/js/worker-indirect-eval.js +88 -0
- package/src/kernels/js/worker-runtime.js +401 -0
- package/src/kernels/py/kernel-contract.ts +32 -0
- package/src/kernels/py/kernel.ts +290 -0
- package/src/kernels/py/prelude.py +954 -0
- package/src/kernels/py/process.ts +119 -0
- package/src/kernels/py/transport.ts +237 -0
- package/src/kernels/rb/kernel.ts +26 -0
- package/src/kernels/rb/prelude.rb +270 -0
- package/src/kernels/rb/runner.rb +204 -0
- package/src/kernels/shared/subprocess-contract.ts +22 -0
- package/src/kernels/shared/subprocess-kernel.ts +266 -0
- package/src/kernels/shared/subprocess-process.ts +174 -0
- package/src/kernels/shared/subprocess-queue.ts +101 -0
- package/src/kernels/shared/subprocess-run.ts +98 -0
- package/src/output/output-meta.ts +89 -0
- package/src/output/streaming-output.ts +296 -0
- package/src/prompt/eval-prompt.ts +319 -0
- package/src/timeouts/bridge-timeout.ts +16 -0
- package/src/timeouts/idle-timeout.ts +84 -0
- package/src/tool/cell-handler.ts +279 -0
- package/src/tool/eval-tool.ts +285 -0
- package/src/tool/image.ts +274 -0
- package/src/tool/json-tree.ts +247 -0
- package/src/tool/render.ts +876 -0
- package/src/tool/status-events.ts +12 -0
- package/src/tool/types.ts +114 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EvalStatusEvent } from "./types.ts";
|
|
2
|
+
|
|
3
|
+
export function upsertStatusEvent(events: EvalStatusEvent[], event: EvalStatusEvent): void {
|
|
4
|
+
if (event.op === "agent" && typeof event.id === "string") {
|
|
5
|
+
const index = events.findIndex((candidate) => candidate.op === "agent" && candidate.id === event.id);
|
|
6
|
+
if (index >= 0) {
|
|
7
|
+
events[index] = event;
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
events.push(event);
|
|
12
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { AgentToolResult, AgentToolUpdateCallback } from "@code-yeongyu/senpi";
|
|
2
|
+
import { Type } from "typebox";
|
|
3
|
+
import type { HostToKernelMessage, KernelToHostMessage } from "../bridge/protocol.ts";
|
|
4
|
+
import type { TruncationMeta } from "../output/output-meta.ts";
|
|
5
|
+
|
|
6
|
+
export const evalLanguageOrder = ["py", "js", "rb", "jl"] as const;
|
|
7
|
+
export type EvalLanguage = (typeof evalLanguageOrder)[number];
|
|
8
|
+
export type EnabledEvalLanguages = Readonly<Record<EvalLanguage, boolean>>;
|
|
9
|
+
|
|
10
|
+
export function enabledLanguageList(enabled: EnabledEvalLanguages): EvalLanguage[] {
|
|
11
|
+
return evalLanguageOrder.filter((language) => enabled[language]);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const fullEvalInputSchema = Type.Object({
|
|
15
|
+
language: Type.Union([Type.Literal("py"), Type.Literal("js"), Type.Literal("rb"), Type.Literal("jl")]),
|
|
16
|
+
code: Type.String({ description: "Cell body, verbatim." }),
|
|
17
|
+
title: Type.Optional(Type.String({ description: "Short transcript label." })),
|
|
18
|
+
timeout: Type.Optional(Type.Number({ minimum: 1, description: "Timeout in seconds." })),
|
|
19
|
+
reset: Type.Optional(Type.Boolean({ description: "Reset this language kernel before running." })),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export function createEvalInputSchema(enabled: EnabledEvalLanguages): typeof fullEvalInputSchema {
|
|
23
|
+
const languages = enabledLanguageList(enabled);
|
|
24
|
+
if (languages.length === 0) throw new Error("eval requires at least one enabled language");
|
|
25
|
+
const languageSchema =
|
|
26
|
+
languages.length === 1
|
|
27
|
+
? Type.Union([Type.Literal(languages[0])])
|
|
28
|
+
: Type.Union(languages.map((item) => Type.Literal(item)));
|
|
29
|
+
return Type.Object({
|
|
30
|
+
language: languageSchema,
|
|
31
|
+
code: Type.String({ description: "Cell body, verbatim." }),
|
|
32
|
+
title: Type.Optional(Type.String({ description: "Short transcript label." })),
|
|
33
|
+
timeout: Type.Optional(Type.Number({ minimum: 1, description: "Timeout in seconds." })),
|
|
34
|
+
reset: Type.Optional(Type.Boolean({ description: "Reset this language kernel before running." })),
|
|
35
|
+
}) as typeof fullEvalInputSchema;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type EvalInputSchema = typeof fullEvalInputSchema;
|
|
39
|
+
export interface EvalToolInput {
|
|
40
|
+
readonly language: EvalLanguage;
|
|
41
|
+
readonly code: string;
|
|
42
|
+
readonly title?: string;
|
|
43
|
+
readonly timeout?: number;
|
|
44
|
+
readonly reset?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export type EvalKernelResult = Extract<KernelToHostMessage, { type: "result" }>;
|
|
47
|
+
export type EvalToolCallMessage = Extract<KernelToHostMessage, { type: "tool-call" }>;
|
|
48
|
+
|
|
49
|
+
export interface EvalKernelRunInput {
|
|
50
|
+
readonly cellId: string;
|
|
51
|
+
readonly code: string;
|
|
52
|
+
readonly timeoutMs?: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface EvalKernel {
|
|
56
|
+
run(input: EvalKernelRunInput): Promise<EvalKernelResult>;
|
|
57
|
+
interrupt(reason?: string): Promise<void>;
|
|
58
|
+
deliverToolReply(message: Extract<HostToKernelMessage, { type: "tool-reply" }>): void;
|
|
59
|
+
reset(): Promise<void>;
|
|
60
|
+
close(): Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface EvalKernelManager {
|
|
64
|
+
getKernel(language: EvalLanguage, onMessage: (message: KernelToHostMessage) => void): Promise<EvalKernel>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export type ExecuteTool = (
|
|
68
|
+
toolName: string,
|
|
69
|
+
params: unknown,
|
|
70
|
+
options?: { signal?: AbortSignal; onUpdate?: AgentToolUpdateCallback<unknown> },
|
|
71
|
+
) => Promise<AgentToolResult<unknown>>;
|
|
72
|
+
|
|
73
|
+
export interface EvalToolCallSummary {
|
|
74
|
+
readonly name: string;
|
|
75
|
+
readonly ok: boolean;
|
|
76
|
+
readonly error?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export type EvalStatusEvent = { readonly op: string } & Readonly<Record<string, unknown>>;
|
|
80
|
+
|
|
81
|
+
export type EvalDisplayOutput =
|
|
82
|
+
| { readonly type: "json"; readonly data: unknown }
|
|
83
|
+
| { readonly type: "image"; readonly data: string; readonly mimeType: string }
|
|
84
|
+
| { readonly type: "markdown"; readonly text: string }
|
|
85
|
+
| { readonly type: "status"; readonly event: EvalStatusEvent };
|
|
86
|
+
|
|
87
|
+
export type EvalCellResult = {
|
|
88
|
+
readonly index: number;
|
|
89
|
+
readonly title?: string;
|
|
90
|
+
readonly code: string;
|
|
91
|
+
readonly language: EvalLanguage;
|
|
92
|
+
readonly output: string;
|
|
93
|
+
readonly status: "pending" | "running" | "complete" | "error";
|
|
94
|
+
readonly exitCode?: number;
|
|
95
|
+
readonly durationMs?: number;
|
|
96
|
+
readonly statusEvents?: readonly EvalStatusEvent[];
|
|
97
|
+
readonly hasMarkdown?: boolean;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export interface EvalToolDetails {
|
|
101
|
+
readonly language: EvalLanguage;
|
|
102
|
+
readonly languages?: readonly EvalLanguage[];
|
|
103
|
+
readonly title?: string;
|
|
104
|
+
readonly durationMs: number;
|
|
105
|
+
readonly toolCalls: readonly EvalToolCallSummary[];
|
|
106
|
+
readonly truncated: boolean;
|
|
107
|
+
readonly isError?: boolean;
|
|
108
|
+
readonly phase?: string;
|
|
109
|
+
readonly cells?: readonly EvalCellResult[];
|
|
110
|
+
readonly statusEvents?: readonly EvalStatusEvent[];
|
|
111
|
+
readonly jsonOutputs?: readonly unknown[];
|
|
112
|
+
readonly notice?: string;
|
|
113
|
+
readonly meta?: TruncationMeta;
|
|
114
|
+
}
|