@botlearn-course/daemon 0.0.29-beta.3 → 0.0.29-beta.4

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 (54) hide show
  1. package/README.md +29 -89
  2. package/dist/auth-store.d.ts +1 -11
  3. package/dist/auth-store.js +2 -83
  4. package/dist/cli.d.ts +0 -15
  5. package/dist/cli.js +12 -204
  6. package/dist/index.d.ts +0 -3
  7. package/dist/index.js +0 -3
  8. package/dist/run-dispatcher.d.ts +1 -5
  9. package/dist/run-dispatcher.js +41 -116
  10. package/dist/runtime-capabilities.js +3 -11
  11. package/dist/runtimes/engine.js +15 -52
  12. package/dist/runtimes/index.d.ts +1 -7
  13. package/dist/runtimes/index.js +1 -45
  14. package/dist/runtimes/pi-agent.js +38 -7
  15. package/dist/runtimes/pi-managed-launch.d.ts +5 -0
  16. package/dist/runtimes/pi-managed-launch.js +41 -0
  17. package/dist/runtimes/pi-managed-subagent-extension.d.ts +127 -0
  18. package/dist/runtimes/pi-managed-subagent-extension.js +303 -0
  19. package/dist/runtimes/pi-managed.d.ts +16 -2
  20. package/dist/runtimes/pi-managed.js +38 -16
  21. package/dist/runtimes/probe.d.ts +0 -5
  22. package/dist/runtimes/probe.js +0 -16
  23. package/dist/types.d.ts +10 -73
  24. package/dist/workspace.d.ts +0 -2
  25. package/dist/workspace.js +0 -10
  26. package/package.json +2 -2
  27. package/dist/course-client.d.ts +0 -46
  28. package/dist/course-client.js +0 -158
  29. package/dist/doctor.d.ts +0 -15
  30. package/dist/doctor.js +0 -85
  31. package/dist/runtime-profile.d.ts +0 -8
  32. package/dist/runtime-profile.js +0 -236
  33. package/dist/runtimes/acp-stream.d.ts +0 -96
  34. package/dist/runtimes/acp-stream.js +0 -490
  35. package/dist/runtimes/claude-code.d.ts +0 -41
  36. package/dist/runtimes/claude-code.js +0 -364
  37. package/dist/runtimes/codex.d.ts +0 -44
  38. package/dist/runtimes/codex.js +0 -348
  39. package/dist/runtimes/gemini.d.ts +0 -39
  40. package/dist/runtimes/gemini.js +0 -264
  41. package/dist/runtimes/hermes-agent.d.ts +0 -61
  42. package/dist/runtimes/hermes-agent.js +0 -191
  43. package/dist/runtimes/kimi.d.ts +0 -35
  44. package/dist/runtimes/kimi.js +0 -343
  45. package/dist/runtimes/native-tool-blocks.d.ts +0 -3
  46. package/dist/runtimes/native-tool-blocks.js +0 -98
  47. package/dist/runtimes/ndjson-stream.d.ts +0 -48
  48. package/dist/runtimes/ndjson-stream.js +0 -210
  49. package/dist/runtimes/openclaw-acp.d.ts +0 -52
  50. package/dist/runtimes/openclaw-acp.js +0 -893
  51. package/dist/runtimes/runtime-errors.d.ts +0 -20
  52. package/dist/runtimes/runtime-errors.js +0 -95
  53. package/dist/runtimes/text-cap.d.ts +0 -7
  54. package/dist/runtimes/text-cap.js +0 -25
package/dist/types.d.ts CHANGED
@@ -18,7 +18,7 @@ export interface RunInputAttachment {
18
18
  export interface MaterializedInputAttachment extends RunInputAttachment {
19
19
  workspace_path: string;
20
20
  }
21
- /** `GET /daemon/runs/next` 下发的 run.start 载荷(snake_case,与后端 RunStartPayloadOut 一致)。 */
21
+ /** Agent Service `turn.start` 下发的 run.start 载荷(snake_case,与后端 RunStartPayloadOut 一致)。 */
22
22
  export interface RunStartPayload {
23
23
  runtime_prompt?: RuntimePrompt;
24
24
  agent_run_id: string;
@@ -28,7 +28,7 @@ export interface RunStartPayload {
28
28
  task_id: string | null;
29
29
  agent_instance_id: string | null;
30
30
  runtime: {
31
- id?: string;
31
+ id: string;
32
32
  model?: string;
33
33
  reasoning_effort?: string;
34
34
  model_contract?: {
@@ -39,8 +39,6 @@ export interface RunStartPayload {
39
39
  max_output_tokens_limit: number;
40
40
  reasoning_efforts: string[];
41
41
  };
42
- thinking?: boolean;
43
- web_search?: boolean;
44
42
  [key: string]: unknown;
45
43
  };
46
44
  input: {
@@ -50,7 +48,6 @@ export interface RunStartPayload {
50
48
  attachments?: RunInputAttachment[];
51
49
  };
52
50
  context: {
53
- instructions?: string[];
54
51
  metadata?: Record<string, unknown>;
55
52
  [key: string]: unknown;
56
53
  };
@@ -62,8 +59,8 @@ export interface RunStartPayload {
62
59
  };
63
60
  }
64
61
  /**
65
- * `POST /daemon/runs/{id}/events` 接受的事件类型。
66
- * 与后端 DaemonRunEventIn.type 的 Literal 严格一致 —— 发送其他类型会得到 422。
62
+ * 经 Agent Service `turn.event` 上报的 run 事件类型。
63
+ * 必须与 Course Service 接受的事件类型一致,发送其他类型会被拒绝。
67
64
  */
68
65
  export type RunEventType = "run.accepted" | "run.started" | "run.block" | "run.observation" | "run.trace" | "run.message" | "run.completed" | "run.failed" | "run.cancelled";
69
66
  export interface RunEvent {
@@ -84,7 +81,7 @@ export interface RunEventReceipt {
84
81
  candidate_attempt?: number;
85
82
  retry_feedback?: string;
86
83
  }
87
- /** `POST /daemon/runs/{id}/files` 的文件候选(与后端 DaemonRunFileIn 一致)。 */
84
+ /** 经 Agent Service 上报的文件候选。 */
88
85
  export interface RunFileCandidate {
89
86
  event?: "created" | "modified" | "deleted";
90
87
  /** workspace 相对路径,正斜杠;不得包含 `..`、绝对路径或反斜杠(后端 400)。 */
@@ -101,43 +98,6 @@ export interface RunFileRecord extends RunFileCandidate {
101
98
  storage_url?: string | null;
102
99
  status: "candidate" | "saved" | "ignored" | "failed";
103
100
  }
104
- export interface RuntimeProfileArchiveFile {
105
- path: string;
106
- content: string;
107
- sha256?: string;
108
- size?: number;
109
- }
110
- export interface RuntimeProfileSkillPackage {
111
- id: string;
112
- version: string;
113
- digest: string;
114
- archiveManifest: {
115
- name?: string;
116
- skillMd: string;
117
- files?: RuntimeProfileArchiveFile[];
118
- };
119
- }
120
- export interface CourseRuntimeProfile {
121
- schemaVersion: "botlearn-course-runtime-profile/0.1";
122
- profileId: string;
123
- profileHash: string;
124
- courseVersionId: string;
125
- promptPack: {
126
- id: string;
127
- version: string;
128
- digest: string;
129
- systemInstructions: string;
130
- };
131
- skillPackages: RuntimeProfileSkillPackage[];
132
- requiredCapabilities: string[];
133
- }
134
- export interface AppliedRunRuntimeProfile {
135
- profileId: string;
136
- profileHash: string;
137
- promptPackPath: string;
138
- skillsRoot: string;
139
- skillRefs: string[];
140
- }
141
101
  /** runtime adapter 产出的普通归一化块;raw 仅进本地 transcript。 */
142
102
  export interface RuntimeContentBlock {
143
103
  activity?: RuntimeActivity;
@@ -192,17 +152,11 @@ export interface RuntimeCompletionSummary {
192
152
  turn_status?: string;
193
153
  finish_reason?: string;
194
154
  }
195
- export interface RuntimeAuthProbe {
196
- checked: boolean;
197
- ok: boolean;
198
- message?: string;
199
- }
200
- /** doctor / capabilities 使用的探测结果。 */
155
+ /** runtime 安装/版本探测结果。 */
201
156
  export interface RuntimeProbe {
202
157
  available: boolean;
203
158
  path?: string;
204
159
  version?: string;
205
- auth?: RuntimeAuthProbe;
206
160
  }
207
161
  /** runtime 执行期间向 dispatcher 汇报的通道。adapter 不直接触碰 Course API。 */
208
162
  export interface CourseRuntimeSink {
@@ -277,32 +231,15 @@ export interface RuntimeFailureSummary {
277
231
  export interface RuntimeModule {
278
232
  id: string;
279
233
  displayName: string;
280
- /** PATH 上的规范二进制名,doctor 展示用。 */
234
+ /** PATH 上的规范二进制名。 */
281
235
  binary: string;
282
236
  /** 覆盖二进制路径的环境变量;缺省为 `BOTLEARN_<ID>_BIN`(id 大写、`-`→`_`)。 */
283
237
  envVar?: string;
284
- /** 快速探测(安装/版本)。必须廉价:login/capabilities 上报会频繁调用,不得触发真实模型调用。 */
238
+ /** 快速探测(安装/版本)。必须廉价,不得触发真实模型调用。 */
285
239
  probe(): Promise<RuntimeProbe>;
286
- /** 登录态探测,可能昂贵(如真实调用一次 CLI)。仅 doctor 按需调用。 */
287
- probeAuth?(): Promise<RuntimeAuthProbe>;
288
240
  create(): CourseRuntime;
289
- /** probe 不可用时 doctor 显示的安装提示。 */
241
+ /** probe 不可用时的安装提示。 */
290
242
  installHint?: string;
291
- /** 仅测试/demo 用(如 fake),不进入 capabilities 上报,除非显式启用。 */
243
+ /** 仅测试/demo 用(如 fake),除非显式启用否则不注册。 */
292
244
  hidden?: boolean;
293
245
  }
294
- export interface RuntimeProbeEntry {
295
- id: string;
296
- displayName: string;
297
- binary: string;
298
- result: RuntimeProbe;
299
- installHint?: string;
300
- }
301
- export interface DaemonAuth {
302
- daemonId: string;
303
- userId: string;
304
- label: string;
305
- accessToken: string;
306
- refreshToken: string;
307
- courseApiUrl: string;
308
- }
@@ -16,8 +16,6 @@ export declare function runRootDir(agentRunId: string): string;
16
16
  /** runtime 的 cwd。 */
17
17
  export declare function runWorkspaceDir(agentRunId: string): string;
18
18
  export declare function transcriptPath(agentRunId: string): string;
19
- export declare function runtimeProfileDir(agentRunId: string): string;
20
- export declare function runtimeProfileRunRootDir(agentRunId: string): string;
21
19
  export declare function runtimeSessionRootDir(runtimeSessionId: string, sandboxGeneration: number): string;
22
20
  /**
23
21
  * durable workspace:managed sandbox 使用稳定路径
package/dist/workspace.js CHANGED
@@ -32,16 +32,6 @@ export function runWorkspaceDir(agentRunId) {
32
32
  export function transcriptPath(agentRunId) {
33
33
  return path.join(runRootDir(agentRunId), "transcript.jsonl");
34
34
  }
35
- export function runtimeProfileDir(agentRunId) {
36
- assertSafeId(agentRunId, "agent_run_id");
37
- const managedRoot = process.env.BOTLEARN_AGENT_SERVICE_PROFILE_ROOT?.trim();
38
- return managedRoot
39
- ? path.join(managedRoot, agentRunId, "runtime-profile")
40
- : path.join(runRootDir(agentRunId), "runtime-profile");
41
- }
42
- export function runtimeProfileRunRootDir(agentRunId) {
43
- return path.dirname(runtimeProfileDir(agentRunId));
44
- }
45
35
  export function runtimeSessionRootDir(runtimeSessionId, sandboxGeneration) {
46
36
  assertSafeId(runtimeSessionId, "runtime_session_id");
47
37
  if (!Number.isInteger(sandboxGeneration) || sandboxGeneration < 1) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@botlearn-course/daemon",
3
- "version": "0.0.29-beta.3",
4
- "description": "Lightweight BotLearn Course daemon: run course tasks on your own machine with your own agent runtime (BYOA).",
3
+ "version": "0.0.29-beta.4",
4
+ "description": "BotLearn Course daemon for Agent Service managed sandboxes (internal).",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "botlearn-course-daemon": "dist/cli.js",
@@ -1,46 +0,0 @@
1
- import type { CourseRuntimeProfile, DaemonAuth, RunEvent, RunEventReceipt, RunFileCandidate, RunFileRecord, RunStartPayload } from "./types.js";
2
- export declare class CourseClientError extends Error {
3
- readonly status: number;
4
- constructor(status: number, message: string);
5
- }
6
- /** 401:daemon 凭据失效(refresh 也救不回来),调用方应引导重新 login。 */
7
- export declare function isAuthFailure(err: unknown): boolean;
8
- /** 409:run 在服务端已进入终态(如用户取消),后续上报应静默停止。 */
9
- export declare function isRunTerminal(err: unknown): boolean;
10
- export interface CourseClientOptions {
11
- refreshToken?: string;
12
- onAuthRefreshed?: (auth: DaemonAuth) => void;
13
- }
14
- /**
15
- * Course Service HTTP 客户端。
16
- *
17
- * Course Service 是真相源;client 只用短期 access token 回报已分配给本 daemon 的 run。
18
- * 第一版用 POST poll/events,不做 WS。401 时自动用 refresh token 换新并单次重试。
19
- */
20
- export declare class CourseClient {
21
- private readonly baseUrl;
22
- private accessToken;
23
- private refreshToken?;
24
- private readonly onAuthRefreshed?;
25
- constructor(baseUrl: string, accessToken: string, opts?: CourseClientOptions);
26
- static fromAuth(auth: DaemonAuth, opts?: Omit<CourseClientOptions, "refreshToken">): CourseClient;
27
- setAccessToken(token: string): void;
28
- private url;
29
- fetchJson<T>(method: string, p: string, body: unknown, accessToken: string | null, traceId?: string, signal?: AbortSignal): Promise<T>;
30
- private refreshAuth;
31
- private request;
32
- /** 领取下一个分配给本 daemon 的 queued run(无则返回 null)。 */
33
- claimNextRun(): Promise<RunStartPayload | null>;
34
- postEvent(agentRunId: string, event: RunEvent): Promise<RunEventReceipt>;
35
- postFiles(agentRunId: string, files: RunFileCandidate[], truncated?: boolean, signal?: AbortSignal): Promise<RunFileRecord[]>;
36
- getRunRuntimeProfile(agentRunId: string): Promise<CourseRuntimeProfile>;
37
- }
38
- export interface LoginOptions {
39
- courseApiUrl: string;
40
- code: string;
41
- label?: string;
42
- machineFingerprint?: string;
43
- capabilities?: Record<string, unknown>;
44
- }
45
- export declare function loginCourseDaemon(opts: LoginOptions): Promise<DaemonAuth>;
46
- export declare function refreshCourseDaemonSession(courseApiUrl: string, refreshToken: string): Promise<DaemonAuth>;
@@ -1,158 +0,0 @@
1
- import { redactSecretString, redactSecretsDeep } from "./redaction.js";
2
- export class CourseClientError extends Error {
3
- status;
4
- constructor(status, message) {
5
- super(message);
6
- this.status = status;
7
- this.name = "CourseClientError";
8
- }
9
- }
10
- /** 401:daemon 凭据失效(refresh 也救不回来),调用方应引导重新 login。 */
11
- export function isAuthFailure(err) {
12
- return err instanceof CourseClientError && err.status === 401;
13
- }
14
- /** 409:run 在服务端已进入终态(如用户取消),后续上报应静默停止。 */
15
- export function isRunTerminal(err) {
16
- return err instanceof CourseClientError && err.status === 409;
17
- }
18
- // 错误信息里只保留响应文本前 500 字符,且先脱敏——绝不回显请求体(可能含 code/token)。
19
- const ERROR_BODY_MAX_CHARS = 500;
20
- /**
21
- * Course Service HTTP 客户端。
22
- *
23
- * Course Service 是真相源;client 只用短期 access token 回报已分配给本 daemon 的 run。
24
- * 第一版用 POST poll/events,不做 WS。401 时自动用 refresh token 换新并单次重试。
25
- */
26
- export class CourseClient {
27
- baseUrl;
28
- accessToken;
29
- refreshToken;
30
- onAuthRefreshed;
31
- constructor(baseUrl, accessToken, opts = {}) {
32
- this.baseUrl = baseUrl;
33
- this.accessToken = accessToken;
34
- this.refreshToken = opts.refreshToken;
35
- this.onAuthRefreshed = opts.onAuthRefreshed;
36
- }
37
- static fromAuth(auth, opts = {}) {
38
- return new CourseClient(auth.courseApiUrl, auth.accessToken, {
39
- ...opts,
40
- refreshToken: auth.refreshToken,
41
- });
42
- }
43
- setAccessToken(token) {
44
- this.accessToken = token;
45
- }
46
- // courseApiUrl 可能是 host 根,也可能已带 /course/v1 —— 去重避免拼出 /course/v1/course/v1。
47
- url(p) {
48
- const base = this.baseUrl.replace(/\/+$/, "");
49
- if (base.endsWith("/course/v1") && p.startsWith("/course/v1/")) {
50
- return `${base}${p.slice("/course/v1".length)}`;
51
- }
52
- return `${base}${p}`;
53
- }
54
- async fetchJson(method, p, body, accessToken, traceId, signal) {
55
- const res = await fetch(this.url(p), {
56
- method,
57
- signal,
58
- headers: {
59
- ...(accessToken ? { authorization: `Bearer ${accessToken}` } : {}),
60
- ...(traceId ? { "x-trace-id": traceId } : {}),
61
- ...(body !== undefined ? { "content-type": "application/json" } : {}),
62
- },
63
- body: body !== undefined ? JSON.stringify(body) : undefined,
64
- });
65
- if (!res.ok) {
66
- const text = await res.text().catch(() => "");
67
- const detail = redactSecretString(text.slice(0, ERROR_BODY_MAX_CHARS));
68
- throw new CourseClientError(res.status, `${method} ${p} -> ${res.status} ${detail}`);
69
- }
70
- const raw = await res.text();
71
- return (raw ? JSON.parse(raw) : null);
72
- }
73
- async refreshAuth() {
74
- if (!this.refreshToken)
75
- return false;
76
- try {
77
- const auth = await refreshCourseDaemonSession(this.baseUrl, this.refreshToken);
78
- this.accessToken = auth.accessToken;
79
- this.refreshToken = auth.refreshToken;
80
- this.onAuthRefreshed?.(auth);
81
- return true;
82
- }
83
- catch {
84
- return false;
85
- }
86
- }
87
- async request(method, p, body, traceId, signal) {
88
- try {
89
- return await this.fetchJson(method, p, body, this.accessToken, traceId, signal);
90
- }
91
- catch (err) {
92
- if (!(err instanceof CourseClientError) || err.status !== 401)
93
- throw err;
94
- const refreshed = await this.refreshAuth();
95
- if (!refreshed)
96
- throw err;
97
- return await this.fetchJson(method, p, body, this.accessToken, traceId, signal);
98
- }
99
- }
100
- /** 领取下一个分配给本 daemon 的 queued run(无则返回 null)。 */
101
- async claimNextRun() {
102
- return this.request("GET", "/course/v1/daemon/runs/next");
103
- }
104
- async postEvent(agentRunId, event) {
105
- const credentials = [this.accessToken, this.refreshToken].filter((value) => typeof value === "string");
106
- const sanitized = redactSecretsDeep(event, 8, credentials);
107
- const response = await this.request("POST", `/course/v1/daemon/runs/${agentRunId}/events`, sanitized, event.trace_id);
108
- return response?.disposition === "retry"
109
- ? {
110
- disposition: "retry",
111
- ...(typeof response.candidate_attempt === "number"
112
- ? { candidate_attempt: response.candidate_attempt }
113
- : {}),
114
- ...(typeof response.retry_feedback === "string"
115
- ? { retry_feedback: response.retry_feedback }
116
- : {}),
117
- }
118
- : { disposition: "accepted" };
119
- }
120
- async postFiles(agentRunId, files, truncated = false, signal) {
121
- return this.request("POST", `/course/v1/daemon/runs/${agentRunId}/files`, { files, truncated }, undefined, signal);
122
- }
123
- async getRunRuntimeProfile(agentRunId) {
124
- return this.request("GET", `/course/v1/daemon/runs/${agentRunId}/runtime-profile`);
125
- }
126
- }
127
- function authFromResponse(baseUrl, raw) {
128
- const daemonId = raw.daemonId ?? raw.daemon_id;
129
- const userId = raw.userId ?? raw.user_id;
130
- const accessToken = raw.accessToken ?? raw.access_token;
131
- const refreshToken = raw.refreshToken ?? raw.refresh_token;
132
- if (!daemonId || !userId || !accessToken || !refreshToken) {
133
- throw new Error("daemon auth response is missing required fields");
134
- }
135
- return {
136
- daemonId,
137
- userId,
138
- label: raw.label ?? "",
139
- accessToken,
140
- refreshToken,
141
- courseApiUrl: raw.courseApiUrl ?? raw.course_api_url ?? baseUrl,
142
- };
143
- }
144
- export async function loginCourseDaemon(opts) {
145
- const client = new CourseClient(opts.courseApiUrl, "");
146
- const raw = await client.fetchJson("POST", "/course/v1/daemon/login", {
147
- code: opts.code,
148
- label: opts.label ?? "",
149
- machine_fingerprint: opts.machineFingerprint,
150
- capabilities: opts.capabilities ?? {},
151
- }, null);
152
- return authFromResponse(opts.courseApiUrl, raw);
153
- }
154
- export async function refreshCourseDaemonSession(courseApiUrl, refreshToken) {
155
- const client = new CourseClient(courseApiUrl, "");
156
- const raw = await client.fetchJson("POST", "/course/v1/daemon/session", { refresh_token: refreshToken }, null);
157
- return authFromResponse(courseApiUrl, raw);
158
- }
package/dist/doctor.d.ts DELETED
@@ -1,15 +0,0 @@
1
- import type { RuntimeProbeEntry } from "./types.js";
2
- export interface DoctorResult {
3
- text: string;
4
- availableCount: number;
5
- totalCount: number;
6
- }
7
- export declare function renderRuntimeTable(entries: RuntimeProbeEntry[]): string[];
8
- export interface CourseDoctorOptions {
9
- includeHidden?: boolean;
10
- /** 探测函数注入点(测试用);缺省走真实 registry probe。 */
11
- detect?: (opts: {
12
- includeHidden?: boolean;
13
- }) => Promise<RuntimeProbeEntry[]>;
14
- }
15
- export declare function runCourseDoctor(opts?: CourseDoctorOptions): Promise<DoctorResult>;
package/dist/doctor.js DELETED
@@ -1,85 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import { authFilePath, readAuth } from "./auth-store.js";
3
- import { detectRuntimes, getRuntimeModule } from "./runtimes/index.js";
4
- function pad(s, n) {
5
- return s + " ".repeat(Math.max(0, n - s.length));
6
- }
7
- // token 绝不出现在 doctor 输出:Auth 区只显示非敏感身份字段。
8
- function renderAuthSection() {
9
- const lines = ["Auth"];
10
- const file = authFilePath();
11
- const auth = readAuth();
12
- if (!auth) {
13
- const state = existsSync(file) ? "unreadable" : "missing";
14
- lines.push(` auth.json: ${state} (${file})`);
15
- lines.push(" run: botlearn-course-daemon course login --api-url <url> --code <blic_xxx>");
16
- return lines;
17
- }
18
- lines.push(` auth.json: present (${file})`);
19
- lines.push(` courseApiUrl: ${auth.courseApiUrl}`);
20
- lines.push(` daemonId: ${auth.daemonId}`);
21
- lines.push(` label: ${auth.label || "—"}`);
22
- return lines;
23
- }
24
- export function renderRuntimeTable(entries) {
25
- const lines = [];
26
- const rows = entries.map((e) => ({
27
- runtime: e.id,
28
- name: e.displayName,
29
- status: e.result.available ? "ok" : "missing",
30
- version: e.result.version ?? "—",
31
- path: e.result.path ?? "—",
32
- }));
33
- const widths = {
34
- runtime: Math.max(7, ...rows.map((r) => r.runtime.length)),
35
- name: Math.max(4, ...rows.map((r) => r.name.length)),
36
- status: Math.max(6, ...rows.map((r) => r.status.length)),
37
- version: Math.max(7, ...rows.map((r) => r.version.length)),
38
- };
39
- lines.push(`${pad("RUNTIME", widths.runtime)} ${pad("NAME", widths.name)} ${pad("STATUS", widths.status)} ${pad("VERSION", widths.version)} PATH`);
40
- for (let i = 0; i < rows.length; i += 1) {
41
- const r = rows[i];
42
- const e = entries[i];
43
- lines.push(`${pad(r.runtime, widths.runtime)} ${pad(r.name, widths.name)} ${pad(r.status, widths.status)} ${pad(r.version, widths.version)} ${r.path}`);
44
- if (!e.result.available && e.installHint) {
45
- lines.push(` → ${e.installHint}`);
46
- }
47
- if (e.result.auth) {
48
- const auth = e.result.auth;
49
- const authStatus = auth.checked ? (auth.ok ? "ok" : "failed") : "skipped";
50
- lines.push(` auth ${authStatus}: ${auth.message ?? ""}`.trimEnd());
51
- }
52
- }
53
- return lines;
54
- }
55
- export async function runCourseDoctor(opts = {}) {
56
- const detect = opts.detect ?? detectRuntimes;
57
- const entries = await detect({ includeHidden: opts.includeHidden });
58
- // 登录态探测可能昂贵(真实调用一次 CLI),只在 doctor 里对可用 runtime 补跑;
59
- // 注入的 entry 已带 auth 时保留,避免测试注入被覆盖。
60
- for (const e of entries) {
61
- if (!e.result.available || e.result.auth)
62
- continue;
63
- const probeAuth = getRuntimeModule(e.id)?.probeAuth;
64
- if (!probeAuth)
65
- continue;
66
- try {
67
- e.result.auth = await probeAuth();
68
- }
69
- catch (err) {
70
- e.result.auth = {
71
- checked: true,
72
- ok: false,
73
- message: err instanceof Error ? err.message : String(err),
74
- };
75
- }
76
- }
77
- const availableCount = entries.filter((e) => e.result.available).length;
78
- const lines = [];
79
- lines.push(...renderAuthSection());
80
- lines.push("");
81
- lines.push("Runtimes");
82
- lines.push(...renderRuntimeTable(entries));
83
- lines.push(`\n${availableCount}/${entries.length} runtimes available`);
84
- return { text: lines.join("\n"), availableCount, totalCount: entries.length };
85
- }
@@ -1,8 +0,0 @@
1
- import type { AppliedRunRuntimeProfile, RunStartPayload } from "./types.js";
2
- export declare class RuntimeProfileApplyError extends Error {
3
- readonly code = "profile_apply_failed";
4
- constructor(message: string);
5
- }
6
- export declare function applyRunRuntimeProfile(payload: RunStartPayload, raw: unknown): AppliedRunRuntimeProfile;
7
- export declare function cleanupRunRuntimeProfile(agentRunId: string): void;
8
- export declare function runtimeProfileInstructions(payload: RunStartPayload, applied: AppliedRunRuntimeProfile): string[];