@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
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { createReadStream, chmodSync, lstatSync, mkdirSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createInterface } from "node:readline";
|
|
4
|
+
// Like DeepSeek's native store, this survives per-turn HOME cleanup and NAS remounts.
|
|
5
|
+
// The daemon owns the opaque filename handle; never ask Pi to search global sessions.
|
|
6
|
+
const SESSION_DIR = ".botlearn-pi-runtime";
|
|
7
|
+
const SESSION_FILE = /^[A-Za-z0-9][A-Za-z0-9._-]*\.jsonl$/;
|
|
8
|
+
export async function preparePiSession(opts) {
|
|
9
|
+
const dir = path.resolve(opts.cwd, SESSION_DIR);
|
|
10
|
+
mkdirSync(dir, { recursive: true, mode: 0o770 });
|
|
11
|
+
if (!lstatSync(dir).isDirectory())
|
|
12
|
+
throw new Error("pi-agent session directory is not a real directory");
|
|
13
|
+
chmodSync(dir, 0o770);
|
|
14
|
+
const handle = opts.sessionId?.trim();
|
|
15
|
+
if (!handle)
|
|
16
|
+
return { dir, text: opts.text };
|
|
17
|
+
if (!SESSION_FILE.test(handle))
|
|
18
|
+
throw new Error("pi-agent invalid native session handle");
|
|
19
|
+
const file = path.join(dir, handle);
|
|
20
|
+
let stat;
|
|
21
|
+
try {
|
|
22
|
+
stat = lstatSync(file);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
// Only a confirmed missing local file permits bootstrap, before any model/tool work.
|
|
26
|
+
if (error.code === "ENOENT") {
|
|
27
|
+
return { dir, text: opts.recoveryText ?? opts.text };
|
|
28
|
+
}
|
|
29
|
+
throw new Error("pi-agent native session could not be read");
|
|
30
|
+
}
|
|
31
|
+
if (!stat.isFile() || stat.size === 0)
|
|
32
|
+
throw new Error("pi-agent invalid native session file");
|
|
33
|
+
// Pi skips malformed JSONL records. Reject corruption rather than silently losing history.
|
|
34
|
+
const input = createReadStream(file, { encoding: "utf8", signal: opts.signal });
|
|
35
|
+
const lines = createInterface({ input, crlfDelay: Infinity });
|
|
36
|
+
let id;
|
|
37
|
+
try {
|
|
38
|
+
for await (const line of lines) {
|
|
39
|
+
if (!line.trim())
|
|
40
|
+
continue;
|
|
41
|
+
const entry = JSON.parse(line);
|
|
42
|
+
if (!entry || typeof entry !== "object" || typeof entry.type !== "string")
|
|
43
|
+
throw new Error();
|
|
44
|
+
if (!id) {
|
|
45
|
+
if (entry.type !== "session" || entry.version !== 3 || typeof entry.id !== "string" || !entry.id) {
|
|
46
|
+
throw new Error();
|
|
47
|
+
}
|
|
48
|
+
id = entry.id;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (!id)
|
|
52
|
+
throw new Error();
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
opts.signal.throwIfAborted();
|
|
56
|
+
throw new Error("pi-agent invalid or unreadable native session records");
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
lines.close();
|
|
60
|
+
input.destroy();
|
|
61
|
+
}
|
|
62
|
+
return { dir, file, id, text: opts.text };
|
|
63
|
+
}
|
|
64
|
+
export function piSessionHandle(session, state) {
|
|
65
|
+
const file = typeof state.sessionFile === "string" ? state.sessionFile : "";
|
|
66
|
+
if (!path.isAbsolute(file) || path.dirname(file) !== session.dir
|
|
67
|
+
|| !SESSION_FILE.test(path.basename(file)) || typeof state.sessionId !== "string" || !state.sessionId
|
|
68
|
+
|| !Number.isSafeInteger(state.messageCount) || Number(state.messageCount) < 0
|
|
69
|
+
|| (!session.file && state.messageCount !== 0)
|
|
70
|
+
|| (session.file && (file !== session.file || state.sessionId !== session.id || Number(state.messageCount) === 0))) {
|
|
71
|
+
throw new Error("pi-agent native session state did not match the requested session");
|
|
72
|
+
}
|
|
73
|
+
return path.basename(file);
|
|
74
|
+
}
|
|
@@ -28,7 +28,7 @@ export interface ProgressMcpConfigOptions {
|
|
|
28
28
|
* config, and a path writes a sanitized runtime-readable config below that root.
|
|
29
29
|
*/
|
|
30
30
|
managedRoot?: string | null;
|
|
31
|
-
/** Activation-scoped daemon socket exposed through the clean-env
|
|
31
|
+
/** Activation-scoped daemon socket exposed through the clean-env courseskills relay. */
|
|
32
32
|
courseSkillsSocketPath?: string;
|
|
33
33
|
platform?: NodeJS.Platform;
|
|
34
34
|
}
|
|
@@ -155,8 +155,8 @@ export function createProgressMcpConfig(options = {}) {
|
|
|
155
155
|
const courseSkillsSocketPath = options.courseSkillsSocketPath
|
|
156
156
|
? validCourseSkillsSocketPath(options.courseSkillsSocketPath)
|
|
157
157
|
: undefined;
|
|
158
|
-
if (courseSkillsSocketPath && Object.hasOwn(baseServers, "
|
|
159
|
-
throw new ProgressMcpConfigError("DeepSeek MCP server key '
|
|
158
|
+
if (courseSkillsSocketPath && Object.hasOwn(baseServers, "courseskills")) {
|
|
159
|
+
throw new ProgressMcpConfigError("DeepSeek MCP server key 'courseskills' is reserved for BotLearn Course Skills");
|
|
160
160
|
}
|
|
161
161
|
const dir = mkdtempSync(path.join(managedRoot ?? tmpdir(), "botlearn-progress-mcp-"));
|
|
162
162
|
const configPath = path.join(dir, "mcp.json");
|
|
@@ -179,7 +179,9 @@ export function createProgressMcpConfig(options = {}) {
|
|
|
179
179
|
},
|
|
180
180
|
...(courseSkillsSocketPath
|
|
181
181
|
? {
|
|
182
|
-
|
|
182
|
+
// DeepSeek 0.8.39 splits mcp_<server>_<tool> at the first underscore.
|
|
183
|
+
// A server key containing underscores can be listed but cannot execute.
|
|
184
|
+
courseskills: {
|
|
183
185
|
command: "/usr/bin/env",
|
|
184
186
|
args: [
|
|
185
187
|
"-i",
|
|
@@ -216,7 +218,7 @@ function validCourseSkillsSocketPath(value) {
|
|
|
216
218
|
if (!path.isAbsolute(value)
|
|
217
219
|
|| value.includes("\0")
|
|
218
220
|
|| Buffer.byteLength(value, "utf8") > 240) {
|
|
219
|
-
throw new ProgressMcpConfigError("
|
|
221
|
+
throw new ProgressMcpConfigError("courseskills MCP socket path must be a bounded absolute path");
|
|
220
222
|
}
|
|
221
223
|
return value;
|
|
222
224
|
}
|
|
@@ -6,6 +6,7 @@ export interface ToolObservationPayload extends Record<string, unknown> {
|
|
|
6
6
|
runtime: string;
|
|
7
7
|
status: "started" | "completed" | "error";
|
|
8
8
|
name?: string;
|
|
9
|
+
tool_call_id?: string;
|
|
9
10
|
detail_preview?: string;
|
|
10
11
|
detail_truncated: boolean;
|
|
11
12
|
detail_full?: string;
|
|
@@ -19,7 +20,7 @@ export interface ToolObservationPayload extends Record<string, unknown> {
|
|
|
19
20
|
* and paths inside the current workspace become workspace-relative. Other semantic content,
|
|
20
21
|
* including execution-host paths outside that workspace, stays intact. `detail_preview` is
|
|
21
22
|
* a bounded feed-sized excerpt; `detail_full` carries the same allowlisted projection at
|
|
22
|
-
* audit fidelity (deeper walk, larger arrays, 64k chars). Message text, request IDs, and
|
|
23
|
+
* audit fidelity (deeper walk, larger arrays, 64k chars). Message text, model request IDs, and
|
|
23
24
|
* arbitrary envelope metadata never cross this boundary.
|
|
24
25
|
*/
|
|
25
26
|
export declare function buildToolObservation(block: RuntimeBlock, runtime: string, workspaceDir: string): ToolObservationPayload | null;
|
package/dist/tool-observation.js
CHANGED
|
@@ -47,7 +47,7 @@ const RESULT_FIELDS = new Set([
|
|
|
47
47
|
* and paths inside the current workspace become workspace-relative. Other semantic content,
|
|
48
48
|
* including execution-host paths outside that workspace, stays intact. `detail_preview` is
|
|
49
49
|
* a bounded feed-sized excerpt; `detail_full` carries the same allowlisted projection at
|
|
50
|
-
* audit fidelity (deeper walk, larger arrays, 64k chars). Message text, request IDs, and
|
|
50
|
+
* audit fidelity (deeper walk, larger arrays, 64k chars). Message text, model request IDs, and
|
|
51
51
|
* arbitrary envelope metadata never cross this boundary.
|
|
52
52
|
*/
|
|
53
53
|
export function buildToolObservation(block, runtime, workspaceDir) {
|
|
@@ -77,7 +77,9 @@ export function buildToolObservation(block, runtime, workspaceDir) {
|
|
|
77
77
|
const detailFull = detailFullTruncated
|
|
78
78
|
? `${serializedFull.slice(0, DETAIL_FULL_MAX_CHARS - 1)}…`
|
|
79
79
|
: serializedFull;
|
|
80
|
+
const callId = toolCallId(block.raw);
|
|
80
81
|
return {
|
|
82
|
+
...(callId ? { tool_call_id: callId } : {}),
|
|
81
83
|
schema_version: AGENT_TOOL_OBSERVATION_SCHEMA_VERSION,
|
|
82
84
|
kind: block.kind,
|
|
83
85
|
runtime,
|
|
@@ -143,3 +145,20 @@ function normalizeWorkspacePaths(value, workspaceDir) {
|
|
|
143
145
|
normalizeWorkspacePaths(item, workspaceDir),
|
|
144
146
|
]));
|
|
145
147
|
}
|
|
148
|
+
function toolCallId(raw, depth = 0) {
|
|
149
|
+
if (!raw || typeof raw !== "object" || depth > 4)
|
|
150
|
+
return undefined;
|
|
151
|
+
const value = raw;
|
|
152
|
+
for (const key of ["tool_call_id", "toolCallId", "call_id", "id"]) {
|
|
153
|
+
const candidate = value[key];
|
|
154
|
+
if (typeof candidate === "string" && /^[A-Za-z0-9_.:-]{1,120}$/.test(candidate)
|
|
155
|
+
&& redactSecretsDeep(candidate) === candidate)
|
|
156
|
+
return candidate;
|
|
157
|
+
}
|
|
158
|
+
for (const key of ["payload", "raw", "data", "tool_call", "item"]) {
|
|
159
|
+
const found = toolCallId(value[key], depth + 1);
|
|
160
|
+
if (found)
|
|
161
|
+
return found;
|
|
162
|
+
}
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
package/package.json
CHANGED