@botlearn-course/daemon 0.0.28-beta.3 → 0.0.28-beta.5
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/README.md +50 -0
- package/dist/agent-service-sandbox.d.ts +1 -1
- package/dist/agent-service-sandbox.js +27 -13
- package/dist/agent-service-ws-protocol.d.ts +1 -1
- package/dist/agent-service-ws-protocol.js +12 -2
- package/dist/course-client.d.ts +2 -2
- package/dist/course-client.js +7 -6
- package/dist/file-candidates.d.ts +5 -2
- package/dist/file-candidates.js +61 -34
- package/dist/mcp/course-skills-server.d.ts +45 -1
- package/dist/mcp/course-skills-server.js +10 -10
- package/dist/run-dispatcher.d.ts +1 -1
- package/dist/run-dispatcher.js +1 -1
- package/dist/runtime-prompt.d.ts +2 -2
- package/dist/runtime-prompt.js +2 -2
- package/dist/runtimes/deepseek-tui.js +67 -107
- package/dist/runtimes/engine.js +4 -4
- package/dist/runtimes/pi-agent.d.ts +2 -2
- package/dist/runtimes/pi-agent.js +45 -10
- package/dist/runtimes/pi-course-skills-extension.d.ts +29 -0
- package/dist/runtimes/pi-course-skills-extension.js +60 -0
- package/dist/runtimes/pi-managed.d.ts +0 -1
- package/dist/runtimes/pi-managed.js +1 -14
- package/dist/runtimes/pi-session.d.ts +9 -0
- package/dist/runtimes/pi-session.js +74 -0
- package/dist/runtimes/progress.d.ts +1 -1
- package/dist/runtimes/progress.js +6 -4
- package/dist/tool-observation.d.ts +2 -1
- package/dist/tool-observation.js +20 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -74,6 +74,34 @@ run 的 `runtime.id` 决定用哪个 adapter 执行;未指定时默认 `codex`
|
|
|
74
74
|
各 runtime 的登录(API key / OAuth)沿用你本机已有的配置 —— daemon 不保存、不代管任何
|
|
75
75
|
runtime 凭据。
|
|
76
76
|
|
|
77
|
+
### Pi Agent 接入与协议验证
|
|
78
|
+
|
|
79
|
+
本机安装 `npm install -g @earendil-works/pi-coding-agent@0.85.1`,使用 Pi 自身的配置管理模型
|
|
80
|
+
和凭据。模型参数可使用 `provider/model`。`BOTLEARN_PI_AGENT_BIN` 可覆盖本机执行路径,
|
|
81
|
+
未设置时查找 PATH 上的 `pi`;启动前检查精确版本,版本不匹配显式失败。
|
|
82
|
+
配置在下一轮启动时生效,删除覆盖即恢复 PATH 查找。
|
|
83
|
+
|
|
84
|
+
每轮使用独立 RPC 进程,原生会话保存在当前工作区的 `.botlearn-pi-runtime` 隐藏目录。
|
|
85
|
+
daemon 持久化原生会话文件名,用显式 `--session` 续接;启动后先用 `get_state` 校验,再发送
|
|
86
|
+
本轮输入。正常续聊保留原生工具调用与结果,仅新建、文件明确缺失或重新生成时注入 Course
|
|
87
|
+
持久对话。空文件、损坏记录、权限错误和协议失败明确报错,不自动重跑任务。
|
|
88
|
+
系统提示、模型选择和授权技能随每轮进程刷新,继续禁用隐式发现;托管临时 HOME 清理不影响会话文件。
|
|
89
|
+
托管执行沿用固定启动器、短期模型代理授权及显式课程技能目录;需部署匹配的镜像和 Daemon,
|
|
90
|
+
并通过 `AGENT_SERVICE_RUNTIMES` 开放。本机路径覆盖不会启用托管能力。
|
|
91
|
+
|
|
92
|
+
真实程序协议测试使用本地模型替身,不读取 `.env` 或调用付费模型:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
BOTLEARN_TEST_PI_BIN=/absolute/path/to/pi \
|
|
96
|
+
BOTLEARN_TEST_DEEPSEEK_BIN=/absolute/path/to/codewhale \
|
|
97
|
+
BOTLEARN_TEST_DEEPSEEK_OLD_BIN=/absolute/path/to/deepseek-0.8.39 \
|
|
98
|
+
pnpm exec vitest run src/runtimes/__tests__/runtime-binaries.test.ts
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
未提供对应二进制路径时跳过该项。2026-09-08 的进程内系统指令刷新门禁在 `0.8.39`
|
|
102
|
+
和 `0.9.12` 均失败,详见[历史实测报告](../../docs/qa/2026-09-08-pi-runtime-and-deepseek-upgrade.md)。
|
|
103
|
+
该结果不能作为新版升级验收通过的证据。
|
|
104
|
+
|
|
77
105
|
## 环境变量
|
|
78
106
|
|
|
79
107
|
| 变量 | 说明 |
|
|
@@ -155,3 +183,25 @@ major、minor 或 prerelease 时才填写精确 SemVer(例如 `1.0.0` 或 `1.1
|
|
|
155
183
|
|
|
156
184
|
所有正式版发布到 npm dist-tag `latest`,prerelease 发布到 `next`。CI 会串行化发布并在
|
|
157
185
|
上传前确认目标版本尚不存在,避免并发任务重复发布同一个版本。
|
|
186
|
+
|
|
187
|
+
## 托管 Codewhale 代理凭据
|
|
188
|
+
|
|
189
|
+
托管 `deepseek-tui` 每轮从 activation 的 `DEEPSEEK_BASE_URL` 生成临时
|
|
190
|
+
`[providers.deepseek]` 路由,并用 `api_key_env = "DEEPSEEK_API_KEY"` 显式绑定当轮凭据。
|
|
191
|
+
子进程不再接收 URL 环境覆盖,避免 Codewhale 0.9.12 将其判定为未绑定的新路由。
|
|
192
|
+
未启用视觉模型时同样生成该配置;配置随本轮进程清理,凭据不会写入供应商路由或命令行。
|
|
193
|
+
托管进程固定关闭 Codewhale 自带遥测,BotLearn 原有执行事实记录继续使用既有通道。
|
|
194
|
+
这些规则由适配器代码拥有,更新 daemon 后生效,无需新增部署配置或数据库迁移。
|
|
195
|
+
|
|
196
|
+
镜像内的真实二进制回归入口是 `scripts/smoke-codewhale-managed.mjs`:构建 daemon 后,
|
|
197
|
+
以 `0:2000` 运行并挂载整个包目录,添加 `--network none` 和
|
|
198
|
+
`--add-host model-proxy.test:127.0.0.1`。验证非 localhost 代理、凭据轮换、UID 1001
|
|
199
|
+
文件写入、会话恢复和第二轮系统提示词更新;模型使用本地确定性替身。
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
### 文件元数据批量登记
|
|
203
|
+
|
|
204
|
+
运行收尾以 `files` 数组批量登记本轮新增、修改的文件;手动资源刷新使用同一接口全量扫描。
|
|
205
|
+
每批最多 50 项、元数据数组最多 192 KiB,长文本预览按字节大小分批而不裁短;预览仍最多 4000 字符。
|
|
206
|
+
整个扫描后上报阶段默认最多等待 10 秒。每批服务端事务提交后确认,普通运行保留上报失败日志并完成。
|
|
207
|
+
详情与三组件配套发布要求见 `docs/specs/agent-service-sandbox-daemon-websocket.md` 第 12.3 节。
|
|
@@ -78,7 +78,7 @@ export declare class AgentServiceSandboxClient implements RunReportingClient, Pe
|
|
|
78
78
|
stopGracefully(): Promise<void>;
|
|
79
79
|
private drainWorkspace;
|
|
80
80
|
postEvent(agentRunId: string, event: RunEvent): Promise<RunEventReceipt>;
|
|
81
|
-
|
|
81
|
+
postFiles(agentRunId: string, files: RunFileCandidate[], truncated?: boolean, signal?: AbortSignal): Promise<RunFileRecord[]>;
|
|
82
82
|
recordWorkspaceScanMeasurement(agentRunId: string, measurement: WorkspaceScanMeasurement): Promise<void>;
|
|
83
83
|
private connectOnce;
|
|
84
84
|
private handleHello;
|
|
@@ -685,15 +685,18 @@ export class AgentServiceSandboxClient {
|
|
|
685
685
|
await this.sendFrame(frame);
|
|
686
686
|
return event.type !== "run.block" ? await ack : { disposition: "accepted" };
|
|
687
687
|
}
|
|
688
|
-
async
|
|
688
|
+
async postFiles(agentRunId, files, truncated = false, signal) {
|
|
689
|
+
signal?.throwIfAborted();
|
|
689
690
|
const scope = this.turnScopes.get(agentRunId);
|
|
690
691
|
if (!scope)
|
|
691
692
|
throw new Error("Agent Service sandbox file has no active turn scope");
|
|
692
|
-
if (
|
|
693
|
+
if (files.length < 1 || files.length > 50)
|
|
694
|
+
throw new Error("File batch requires 1–50 files");
|
|
695
|
+
if (files.some(file => !file.sha256 || !Number.isInteger(file.size_bytes) || (file.size_bytes ?? -1) < 0)) {
|
|
693
696
|
throw new Error("Agent Service sandbox file requires size_bytes and sha256");
|
|
694
697
|
}
|
|
695
698
|
const frame = createSandboxFrame({
|
|
696
|
-
type: "turn.
|
|
699
|
+
type: "turn.files.report",
|
|
697
700
|
sandboxId: this.options.sandboxId,
|
|
698
701
|
sandboxGeneration: this.sandboxGeneration,
|
|
699
702
|
connectionEpoch: this.connectionEpoch,
|
|
@@ -702,17 +705,25 @@ export class AgentServiceSandboxClient {
|
|
|
702
705
|
agentRunId,
|
|
703
706
|
workerAttempt: scope.workerAttempt,
|
|
704
707
|
activationId: scope.activationId,
|
|
705
|
-
payload:
|
|
708
|
+
payload: { files, truncated },
|
|
706
709
|
});
|
|
710
|
+
let rejectReport;
|
|
707
711
|
const reported = new Promise((resolve, reject) => {
|
|
712
|
+
rejectReport = reject;
|
|
708
713
|
this.pendingFileReports.set(frame.frame_id, {
|
|
709
|
-
scope: { ...scope },
|
|
710
|
-
resolve,
|
|
711
|
-
reject,
|
|
714
|
+
scope: { ...scope }, files, agentRunId, resolve, reject,
|
|
712
715
|
});
|
|
713
716
|
});
|
|
714
|
-
|
|
715
|
-
|
|
717
|
+
const abort = () => rejectReport(new Error("file batch reporting aborted"));
|
|
718
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
719
|
+
try {
|
|
720
|
+
const [, records] = await Promise.all([this.sendFrame(frame), reported]);
|
|
721
|
+
return records;
|
|
722
|
+
}
|
|
723
|
+
finally {
|
|
724
|
+
signal?.removeEventListener("abort", abort);
|
|
725
|
+
this.pendingFileReports.delete(frame.frame_id);
|
|
726
|
+
}
|
|
716
727
|
}
|
|
717
728
|
async recordWorkspaceScanMeasurement(agentRunId, measurement) {
|
|
718
729
|
if (!this.turnScopes.has(agentRunId)) {
|
|
@@ -1685,12 +1696,15 @@ export class AgentServiceSandboxClient {
|
|
|
1685
1696
|
if (pendingFile) {
|
|
1686
1697
|
this.assertTurnScope(frame, pendingFile.scope, "file report ACK");
|
|
1687
1698
|
this.pendingFileReports.delete(frameId);
|
|
1688
|
-
const
|
|
1689
|
-
if (!file || typeof file !== "object" ||
|
|
1690
|
-
|
|
1699
|
+
const files = frame.payload.files;
|
|
1700
|
+
if (!Array.isArray(files) || files.length !== pendingFile.files.length || files.some((file, i) => (!file || typeof file !== "object" || typeof file.id !== "string"
|
|
1701
|
+
|| file.agent_run_id !== pendingFile.agentRunId
|
|
1702
|
+
|| file.path !== pendingFile.files[i]?.path
|
|
1703
|
+
|| file.sha256 !== pendingFile.files[i]?.sha256))) {
|
|
1704
|
+
pendingFile.reject(new Error("file report ACK does not match the batch"));
|
|
1691
1705
|
}
|
|
1692
1706
|
else {
|
|
1693
|
-
pendingFile.resolve(
|
|
1707
|
+
pendingFile.resolve(files);
|
|
1694
1708
|
}
|
|
1695
1709
|
return;
|
|
1696
1710
|
}
|
|
@@ -4,7 +4,7 @@ export declare const WORKSPACE_FILE_READ_BINARY_CAPABILITY: "workspace_file_read
|
|
|
4
4
|
export declare const WORKSPACE_FILES_LIST_CAPABILITY: "workspace_files_list_v1";
|
|
5
5
|
export declare const WORKSPACE_FILE_CHUNK_BYTES: number;
|
|
6
6
|
export declare const WORKSPACE_FILE_CHUNK_HEADER_BYTES = 29;
|
|
7
|
-
export type SandboxFrameType = "sandbox.hello" | "sandbox.sync" | "session.open" | "session.activate" | "turn.start" | "turn.cancel" | "session.close" | "sandbox.drain" | "sandbox.shutdown" | "event.ack" | "auth.rotate" | "workspace.file.read" | "workspace.files.list" | "ping" | "sandbox.ready" | "sandbox.heartbeat" | "command.ack" | "session.opened" | "session.open_failed" | "session.closed" | "activation.cleaned" | "turn.event" | "turn.
|
|
7
|
+
export type SandboxFrameType = "sandbox.hello" | "sandbox.sync" | "session.open" | "session.activate" | "turn.start" | "turn.cancel" | "session.close" | "sandbox.drain" | "sandbox.shutdown" | "event.ack" | "auth.rotate" | "workspace.file.read" | "workspace.files.list" | "ping" | "sandbox.ready" | "sandbox.heartbeat" | "command.ack" | "session.opened" | "session.open_failed" | "session.closed" | "activation.cleaned" | "turn.event" | "turn.files.report" | "workspace.file.result" | "workspace.files.result" | "sandbox.drained" | "sandbox.log" | "pong" | "protocol.error";
|
|
8
8
|
export declare class UnsupportedSandboxProtocolError extends Error {
|
|
9
9
|
readonly schemaVersion: unknown;
|
|
10
10
|
constructor(schemaVersion: unknown);
|
|
@@ -29,7 +29,7 @@ const FRAME_TYPES = new Set([
|
|
|
29
29
|
"session.closed",
|
|
30
30
|
"activation.cleaned",
|
|
31
31
|
"turn.event",
|
|
32
|
-
"turn.
|
|
32
|
+
"turn.files.report",
|
|
33
33
|
"workspace.file.result",
|
|
34
34
|
"workspace.files.result",
|
|
35
35
|
"sandbox.drained",
|
|
@@ -57,7 +57,7 @@ const TURN_TYPES = new Set([
|
|
|
57
57
|
"event.ack",
|
|
58
58
|
"activation.cleaned",
|
|
59
59
|
"turn.event",
|
|
60
|
-
"turn.
|
|
60
|
+
"turn.files.report",
|
|
61
61
|
]);
|
|
62
62
|
const FRAME_KEYS = new Set([
|
|
63
63
|
"schema_version",
|
|
@@ -194,6 +194,16 @@ export function parseSandboxFrame(raw, maxBytes = 262_144) {
|
|
|
194
194
|
if (!value.payload || typeof value.payload !== "object" || Array.isArray(value.payload)) {
|
|
195
195
|
throw new Error("frame payload must be an object");
|
|
196
196
|
}
|
|
197
|
+
if (type === "turn.files.report") {
|
|
198
|
+
const payload = value.payload;
|
|
199
|
+
if (!Array.isArray(payload.files) || payload.files.length < 1 || payload.files.length > 50
|
|
200
|
+
|| payload.files.some(file => !file || typeof file !== "object" || Array.isArray(file))) {
|
|
201
|
+
throw new Error("turn.files.report requires 1–50 file objects");
|
|
202
|
+
}
|
|
203
|
+
if (payload.truncated !== undefined && typeof payload.truncated !== "boolean") {
|
|
204
|
+
throw new Error("turn.files.report truncated must be a boolean");
|
|
205
|
+
}
|
|
206
|
+
}
|
|
197
207
|
for (const key of ["frame_id", "sandbox_id", "sent_at"]) {
|
|
198
208
|
if (typeof value[key] !== "string" || !value[key])
|
|
199
209
|
throw new Error(`${key} is required`);
|
package/dist/course-client.d.ts
CHANGED
|
@@ -26,13 +26,13 @@ export declare class CourseClient {
|
|
|
26
26
|
static fromAuth(auth: DaemonAuth, opts?: Omit<CourseClientOptions, "refreshToken">): CourseClient;
|
|
27
27
|
setAccessToken(token: string): void;
|
|
28
28
|
private url;
|
|
29
|
-
fetchJson<T>(method: string, p: string, body: unknown, accessToken: string | null, traceId?: string): Promise<T>;
|
|
29
|
+
fetchJson<T>(method: string, p: string, body: unknown, accessToken: string | null, traceId?: string, signal?: AbortSignal): Promise<T>;
|
|
30
30
|
private refreshAuth;
|
|
31
31
|
private request;
|
|
32
32
|
/** 领取下一个分配给本 daemon 的 queued run(无则返回 null)。 */
|
|
33
33
|
claimNextRun(): Promise<RunStartPayload | null>;
|
|
34
34
|
postEvent(agentRunId: string, event: RunEvent): Promise<RunEventReceipt>;
|
|
35
|
-
|
|
35
|
+
postFiles(agentRunId: string, files: RunFileCandidate[], truncated?: boolean, signal?: AbortSignal): Promise<RunFileRecord[]>;
|
|
36
36
|
getRunRuntimeProfile(agentRunId: string): Promise<CourseRuntimeProfile>;
|
|
37
37
|
}
|
|
38
38
|
export interface LoginOptions {
|
package/dist/course-client.js
CHANGED
|
@@ -51,9 +51,10 @@ export class CourseClient {
|
|
|
51
51
|
}
|
|
52
52
|
return `${base}${p}`;
|
|
53
53
|
}
|
|
54
|
-
async fetchJson(method, p, body, accessToken, traceId) {
|
|
54
|
+
async fetchJson(method, p, body, accessToken, traceId, signal) {
|
|
55
55
|
const res = await fetch(this.url(p), {
|
|
56
56
|
method,
|
|
57
|
+
signal,
|
|
57
58
|
headers: {
|
|
58
59
|
...(accessToken ? { authorization: `Bearer ${accessToken}` } : {}),
|
|
59
60
|
...(traceId ? { "x-trace-id": traceId } : {}),
|
|
@@ -83,9 +84,9 @@ export class CourseClient {
|
|
|
83
84
|
return false;
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
|
-
async request(method, p, body, traceId) {
|
|
87
|
+
async request(method, p, body, traceId, signal) {
|
|
87
88
|
try {
|
|
88
|
-
return await this.fetchJson(method, p, body, this.accessToken, traceId);
|
|
89
|
+
return await this.fetchJson(method, p, body, this.accessToken, traceId, signal);
|
|
89
90
|
}
|
|
90
91
|
catch (err) {
|
|
91
92
|
if (!(err instanceof CourseClientError) || err.status !== 401)
|
|
@@ -93,7 +94,7 @@ export class CourseClient {
|
|
|
93
94
|
const refreshed = await this.refreshAuth();
|
|
94
95
|
if (!refreshed)
|
|
95
96
|
throw err;
|
|
96
|
-
return await this.fetchJson(method, p, body, this.accessToken, traceId);
|
|
97
|
+
return await this.fetchJson(method, p, body, this.accessToken, traceId, signal);
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
100
|
/** 领取下一个分配给本 daemon 的 queued run(无则返回 null)。 */
|
|
@@ -116,8 +117,8 @@ export class CourseClient {
|
|
|
116
117
|
}
|
|
117
118
|
: { disposition: "accepted" };
|
|
118
119
|
}
|
|
119
|
-
async
|
|
120
|
-
return this.request("POST", `/course/v1/daemon/runs/${agentRunId}/files`,
|
|
120
|
+
async postFiles(agentRunId, files, truncated = false, signal) {
|
|
121
|
+
return this.request("POST", `/course/v1/daemon/runs/${agentRunId}/files`, { files, truncated }, undefined, signal);
|
|
121
122
|
}
|
|
122
123
|
async getRunRuntimeProfile(agentRunId) {
|
|
123
124
|
return this.request("GET", `/course/v1/daemon/runs/${agentRunId}/runtime-profile`);
|
|
@@ -7,11 +7,13 @@ export interface ScanLimits {
|
|
|
7
7
|
maxDepth?: number;
|
|
8
8
|
maxReportMs?: number;
|
|
9
9
|
}
|
|
10
|
+
export declare const FILE_REPORT_BATCH_MAX_FILES = 50;
|
|
11
|
+
export declare const FILE_REPORT_BATCH_MAX_BYTES: number;
|
|
10
12
|
export interface ScannedFile extends RunFileCandidate {
|
|
11
13
|
absPath: string;
|
|
12
14
|
}
|
|
13
15
|
export interface FileReportingClient {
|
|
14
|
-
|
|
16
|
+
postFiles(agentRunId: string, files: RunFileCandidate[], truncated?: boolean, signal?: AbortSignal): Promise<unknown>;
|
|
15
17
|
recordWorkspaceScanMeasurement?(agentRunId: string, measurement: WorkspaceScanMeasurement): Promise<void> | void;
|
|
16
18
|
}
|
|
17
19
|
export interface WorkspaceScanMeasurement {
|
|
@@ -53,8 +55,9 @@ export declare function scanWorkspaceFiles(workspaceDir: string, limits?: ScanLi
|
|
|
53
55
|
}>;
|
|
54
56
|
/** 捕获普通 Agent turn 开始前的 workspace 基线。 */
|
|
55
57
|
export declare function captureWorkspaceFileBaseline(workspaceDir: string, limits?: ScanLimits): Promise<WorkspaceFileBaseline>;
|
|
58
|
+
export declare function fileReportBatches(files: RunFileCandidate[]): RunFileCandidate[][];
|
|
56
59
|
/**
|
|
57
|
-
*
|
|
60
|
+
* 扫描并一次性上报文件候选。整批失败只 warn 不中断;返回上报结果。
|
|
58
61
|
*/
|
|
59
62
|
export declare function reportFileCandidates(client: FileReportingClient, agentRunId: string, workspaceDir: string, log: Logger, limits?: ScanLimits, baseline?: WorkspaceFileBaseline): Promise<FileReportResult>;
|
|
60
63
|
export {};
|
package/dist/file-candidates.js
CHANGED
|
@@ -4,13 +4,17 @@ import { open, readdir } from "node:fs/promises";
|
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { performance } from "node:perf_hooks";
|
|
6
6
|
import { redactSecretString } from "./redaction.js";
|
|
7
|
-
const
|
|
7
|
+
export const FILE_REPORT_BATCH_MAX_FILES = 50;
|
|
8
|
+
// Reserve 64 KiB of the 256 KiB WS frame for envelopes and server record fields.
|
|
9
|
+
export const FILE_REPORT_BATCH_MAX_BYTES = 192 * 1024;
|
|
10
|
+
const DEFAULT_MAX_FILES = FILE_REPORT_BATCH_MAX_FILES;
|
|
8
11
|
// 与后端 settings.daemon_max_file_bytes 默认一致。
|
|
9
12
|
const DEFAULT_MAX_FILE_BYTES = 50 * 1024 * 1024;
|
|
10
13
|
// 与后端 MAX_PREVIEW_CHARS 一致。
|
|
11
14
|
const DEFAULT_MAX_PREVIEW_CHARS = 4000;
|
|
12
15
|
const DEFAULT_MAX_DEPTH = 8;
|
|
13
|
-
|
|
16
|
+
// One bounded metadata request, including Course Service commit and acknowledgement.
|
|
17
|
+
const DEFAULT_MAX_REPORT_MS = 10_000;
|
|
14
18
|
// 文本启发式:前 4KiB 不含 NUL 字节即视为文本,可取 preview。
|
|
15
19
|
const TEXT_SNIFF_BYTES = 4096;
|
|
16
20
|
// 与后端 _is_safe_relative_path 同规:非空、非绝对、无反斜杠、无 .. 段、无空段。
|
|
@@ -168,8 +172,28 @@ export async function captureWorkspaceFileBaseline(workspaceDir, limits = {}) {
|
|
|
168
172
|
truncated,
|
|
169
173
|
};
|
|
170
174
|
}
|
|
175
|
+
export function fileReportBatches(files) {
|
|
176
|
+
const batches = [];
|
|
177
|
+
let batch = [];
|
|
178
|
+
let bytes = 2;
|
|
179
|
+
for (const file of files) {
|
|
180
|
+
const size = Buffer.byteLength(JSON.stringify(file), "utf8") + 1;
|
|
181
|
+
if (size + 2 > FILE_REPORT_BATCH_MAX_BYTES)
|
|
182
|
+
throw new Error("file metadata exceeds batch limit");
|
|
183
|
+
if (batch.length === FILE_REPORT_BATCH_MAX_FILES || bytes + size > FILE_REPORT_BATCH_MAX_BYTES) {
|
|
184
|
+
batches.push(batch);
|
|
185
|
+
batch = [];
|
|
186
|
+
bytes = 2;
|
|
187
|
+
}
|
|
188
|
+
batch.push(file);
|
|
189
|
+
bytes += size;
|
|
190
|
+
}
|
|
191
|
+
if (batch.length)
|
|
192
|
+
batches.push(batch);
|
|
193
|
+
return batches;
|
|
194
|
+
}
|
|
171
195
|
/**
|
|
172
|
-
*
|
|
196
|
+
* 扫描并一次性上报文件候选。整批失败只 warn 不中断;返回上报结果。
|
|
173
197
|
*/
|
|
174
198
|
export async function reportFileCandidates(client, agentRunId, workspaceDir, log, limits, baseline) {
|
|
175
199
|
const scan = await scanWorkspaceFiles(workspaceDir, limits);
|
|
@@ -201,38 +225,41 @@ export async function reportFileCandidates(client, agentRunId, workspaceDir, log
|
|
|
201
225
|
if (truncated) {
|
|
202
226
|
log.warn("workspace file scan truncated", { agentRunId, reported: files.length });
|
|
203
227
|
}
|
|
228
|
+
if (files.length === 0)
|
|
229
|
+
return { reported: 0, failed: 0, truncated, scan: measurement };
|
|
204
230
|
let reported = 0;
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
path: candidate.path,
|
|
229
|
-
error: err instanceof Error ? err.message : String(err),
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
finally {
|
|
233
|
-
if (timeout !== undefined)
|
|
234
|
-
clearTimeout(timeout);
|
|
231
|
+
const deadline = Date.now() + (limits?.maxReportMs ?? DEFAULT_MAX_REPORT_MS);
|
|
232
|
+
try {
|
|
233
|
+
const batches = fileReportBatches(files.map(({ absPath: _absPath, ...file }) => file));
|
|
234
|
+
for (const batch of batches) {
|
|
235
|
+
const remainingMs = deadline - Date.now();
|
|
236
|
+
if (remainingMs <= 0)
|
|
237
|
+
throw new Error("workspace file metadata report timed out");
|
|
238
|
+
const controller = new AbortController();
|
|
239
|
+
let timeout;
|
|
240
|
+
try {
|
|
241
|
+
await Promise.race([
|
|
242
|
+
client.postFiles(agentRunId, batch, truncated, controller.signal),
|
|
243
|
+
new Promise((_resolve, reject) => {
|
|
244
|
+
timeout = setTimeout(() => reject(new Error("workspace file metadata report timed out")), remainingMs);
|
|
245
|
+
}),
|
|
246
|
+
]);
|
|
247
|
+
reported += batch.length;
|
|
248
|
+
}
|
|
249
|
+
finally {
|
|
250
|
+
if (timeout !== undefined)
|
|
251
|
+
clearTimeout(timeout);
|
|
252
|
+
controller.abort();
|
|
253
|
+
}
|
|
235
254
|
}
|
|
236
255
|
}
|
|
237
|
-
|
|
256
|
+
catch (err) {
|
|
257
|
+
log.warn("file batch report failed", {
|
|
258
|
+
agentRunId,
|
|
259
|
+
reported,
|
|
260
|
+
failed: files.length - reported,
|
|
261
|
+
error: err instanceof Error ? err.message : String(err),
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
return { reported, failed: files.length - reported, truncated, scan: measurement };
|
|
238
265
|
}
|
|
@@ -15,6 +15,50 @@ interface JsonRpcResponse {
|
|
|
15
15
|
message: string;
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
+
export declare const COURSE_SKILL_TOOLS: readonly [{
|
|
19
|
+
readonly name: "list_skills";
|
|
20
|
+
readonly description: "List the immutable BotLearn Course Skills authorized for this activation.";
|
|
21
|
+
readonly inputSchema: {
|
|
22
|
+
readonly type: "object";
|
|
23
|
+
readonly properties: {};
|
|
24
|
+
readonly additionalProperties: false;
|
|
25
|
+
};
|
|
26
|
+
}, {
|
|
27
|
+
readonly name: "load_skill";
|
|
28
|
+
readonly description: "Load the locked SKILL.md for one authorized Course Skill before following it.";
|
|
29
|
+
readonly inputSchema: {
|
|
30
|
+
readonly type: "object";
|
|
31
|
+
readonly properties: {
|
|
32
|
+
readonly ref: {
|
|
33
|
+
readonly type: "string";
|
|
34
|
+
readonly minLength: 5;
|
|
35
|
+
readonly maxLength: 240;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
readonly required: readonly ["ref"];
|
|
39
|
+
readonly additionalProperties: false;
|
|
40
|
+
};
|
|
41
|
+
}, {
|
|
42
|
+
readonly name: "load_reference";
|
|
43
|
+
readonly description: "Load one relative reference path from a Course Skill already loaded in this activation.";
|
|
44
|
+
readonly inputSchema: {
|
|
45
|
+
readonly type: "object";
|
|
46
|
+
readonly properties: {
|
|
47
|
+
readonly ref: {
|
|
48
|
+
readonly type: "string";
|
|
49
|
+
readonly minLength: 5;
|
|
50
|
+
readonly maxLength: 240;
|
|
51
|
+
};
|
|
52
|
+
readonly path: {
|
|
53
|
+
readonly type: "string";
|
|
54
|
+
readonly minLength: 1;
|
|
55
|
+
readonly maxLength: 240;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
readonly required: readonly ["ref", "path"];
|
|
59
|
+
readonly additionalProperties: false;
|
|
60
|
+
};
|
|
61
|
+
}];
|
|
18
62
|
export interface CourseSkillsMcpServer {
|
|
19
63
|
socketPath: string;
|
|
20
64
|
catalog: RuntimeSkillCatalogEntry[];
|
|
@@ -22,7 +66,7 @@ export interface CourseSkillsMcpServer {
|
|
|
22
66
|
close(): Promise<void>;
|
|
23
67
|
}
|
|
24
68
|
export interface CourseSkillsMcpServerOptions {
|
|
25
|
-
prepared
|
|
69
|
+
prepared?: PreparedRuntimeSkillProvider;
|
|
26
70
|
onEvent(event: RuntimeSkillEvent): Promise<void>;
|
|
27
71
|
/**
|
|
28
72
|
* Managed Agent Service root. `undefined` auto-detects it; `null` is only for
|
|
@@ -6,9 +6,9 @@ import { RuntimeSkillProviderError, safeReferencePath, } from "../runtime-skills
|
|
|
6
6
|
const DEFAULT_PROTOCOL_VERSION = "2024-11-05";
|
|
7
7
|
const MAX_REQUEST_LINE_BYTES = 32 * 1024;
|
|
8
8
|
const MAX_REFERENCE_BYTES_PER_ACTIVATION = 1024 * 1024;
|
|
9
|
-
const
|
|
9
|
+
export const COURSE_SKILL_TOOLS = [
|
|
10
10
|
{
|
|
11
|
-
name: "
|
|
11
|
+
name: "list_skills",
|
|
12
12
|
description: "List the immutable BotLearn Course Skills authorized for this activation.",
|
|
13
13
|
inputSchema: {
|
|
14
14
|
type: "object",
|
|
@@ -17,7 +17,7 @@ const TOOLS = [
|
|
|
17
17
|
},
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
|
-
name: "
|
|
20
|
+
name: "load_skill",
|
|
21
21
|
description: "Load the locked SKILL.md for one authorized Course Skill before following it.",
|
|
22
22
|
inputSchema: {
|
|
23
23
|
type: "object",
|
|
@@ -50,10 +50,10 @@ export class CourseSkillsMcpRuntime {
|
|
|
50
50
|
referenceBytes = 0;
|
|
51
51
|
constructor(options) {
|
|
52
52
|
this.options = options;
|
|
53
|
-
this.grantsByRef = new Map(options.prepared
|
|
53
|
+
this.grantsByRef = new Map((options.prepared?.catalog ?? []).map((entry) => [entry.ref, entry]));
|
|
54
54
|
}
|
|
55
55
|
async emitAppliedEvents() {
|
|
56
|
-
for (const entry of this.options.prepared
|
|
56
|
+
for (const entry of (this.options.prepared?.catalog ?? [])) {
|
|
57
57
|
await this.emit(entry, "applied");
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -81,7 +81,7 @@ export class CourseSkillsMcpRuntime {
|
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
83
|
if (request.method === "tools/list") {
|
|
84
|
-
return { jsonrpc: "2.0", id, result: { tools:
|
|
84
|
+
return { jsonrpc: "2.0", id, result: { tools: COURSE_SKILL_TOOLS } };
|
|
85
85
|
}
|
|
86
86
|
if (request.method !== "tools/call") {
|
|
87
87
|
return { jsonrpc: "2.0", id, error: { code: -32601, message: "Method not found" } };
|
|
@@ -90,10 +90,10 @@ export class CourseSkillsMcpRuntime {
|
|
|
90
90
|
const name = params && typeof params.name === "string" ? params.name : "";
|
|
91
91
|
const args = params ? objectValue(params.arguments) : null;
|
|
92
92
|
try {
|
|
93
|
-
if (name === "
|
|
93
|
+
if (name === "list_skills") {
|
|
94
94
|
requireExactArguments(args, []);
|
|
95
95
|
return toolSuccess(id, "skill_catalog_listed", {
|
|
96
|
-
skills: this.options.prepared
|
|
96
|
+
skills: (this.options.prepared?.catalog ?? []).map((entry) => ({
|
|
97
97
|
ref: entry.ref,
|
|
98
98
|
digest: entry.digest,
|
|
99
99
|
name: entry.name,
|
|
@@ -103,7 +103,7 @@ export class CourseSkillsMcpRuntime {
|
|
|
103
103
|
})),
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
|
-
if (name === "
|
|
106
|
+
if (name === "load_skill") {
|
|
107
107
|
requireExactArguments(args, ["ref"]);
|
|
108
108
|
const ref = requiredArgument(args, "ref");
|
|
109
109
|
return toolSuccess(id, "skill_loaded", await this.loadSkill(ref));
|
|
@@ -257,7 +257,7 @@ export async function startCourseSkillsMcpServer(options) {
|
|
|
257
257
|
let applied;
|
|
258
258
|
return {
|
|
259
259
|
socketPath,
|
|
260
|
-
catalog: options.prepared
|
|
260
|
+
catalog: (options.prepared?.catalog ?? []),
|
|
261
261
|
markApplied() {
|
|
262
262
|
applied ??= runtime.emitAppliedEvents();
|
|
263
263
|
return applied;
|
package/dist/run-dispatcher.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export interface PersistentSessionExecution {
|
|
|
27
27
|
}
|
|
28
28
|
export interface RunReportingClient {
|
|
29
29
|
postEvent(agentRunId: string, event: RunEvent): Promise<void | RunEventReceipt>;
|
|
30
|
-
|
|
30
|
+
postFiles(agentRunId: string, files: import("./types.js").RunFileCandidate[], truncated?: boolean, signal?: AbortSignal): Promise<unknown>;
|
|
31
31
|
recordWorkspaceScanMeasurement?(agentRunId: string, measurement: WorkspaceScanMeasurement): Promise<void> | void;
|
|
32
32
|
getRunRuntimeProfile?(agentRunId: string): Promise<CourseRuntimeProfile>;
|
|
33
33
|
}
|
package/dist/run-dispatcher.js
CHANGED
|
@@ -826,7 +826,7 @@ export class RunDispatcher {
|
|
|
826
826
|
finalText = text;
|
|
827
827
|
},
|
|
828
828
|
file: async (file) => {
|
|
829
|
-
await this.client.
|
|
829
|
+
await this.client.postFiles(runId, [file]);
|
|
830
830
|
},
|
|
831
831
|
runtimeSession: async (sessionId) => {
|
|
832
832
|
activeNativeSessionId = sessionId;
|
package/dist/runtime-prompt.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export declare const RUNTIME_PROMPT_CAPABILITY = "
|
|
1
|
+
export declare const RUNTIME_PROMPT_CAPABILITY = "runtime_prompt_v2";
|
|
2
2
|
/** Server-owned model instructions. Audit metadata never becomes model text. */
|
|
3
3
|
export interface RuntimePrompt {
|
|
4
|
-
schemaVersion: "botlearn-runtime-prompt/0.
|
|
4
|
+
schemaVersion: "botlearn-runtime-prompt/0.2";
|
|
5
5
|
systemPrompt: string;
|
|
6
6
|
digest: string;
|
|
7
7
|
skillRefs: string[];
|
package/dist/runtime-prompt.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
export const RUNTIME_PROMPT_CAPABILITY = "
|
|
2
|
+
export const RUNTIME_PROMPT_CAPABILITY = "runtime_prompt_v2";
|
|
3
3
|
export function validateRuntimePrompt(value, expectedSkillRefs) {
|
|
4
4
|
if (!value || typeof value !== "object")
|
|
5
5
|
throw new Error("runtime_prompt_missing");
|
|
6
6
|
const item = value;
|
|
7
7
|
if (Object.keys(item).sort().join(",") !== "digest,schemaVersion,skillRefs,systemPrompt"
|
|
8
|
-
|| item.schemaVersion !== "botlearn-runtime-prompt/0.
|
|
8
|
+
|| item.schemaVersion !== "botlearn-runtime-prompt/0.2"
|
|
9
9
|
|| typeof item.systemPrompt !== "string"
|
|
10
10
|
|| !item.systemPrompt.trim()
|
|
11
11
|
|| Buffer.byteLength(item.systemPrompt) > 100_000
|