@botlearn-course/daemon 0.0.26-v2 → 0.0.27-beta.1

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.
@@ -124,6 +124,7 @@ export declare class AgentServiceSandboxClient implements RunReportingClient, Pe
124
124
  private replaySpool;
125
125
  private sendHeartbeat;
126
126
  private sendCommandAck;
127
+ private handleWorkspaceFilesList;
127
128
  private handleWorkspaceFileRead;
128
129
  private sendWorkspaceFileResult;
129
130
  private sendControlFrame;
@@ -1,9 +1,10 @@
1
+ import { scanWorkspaceFiles } from "./file-candidates.js";
1
2
  import { RUNTIME_PROMPT_CAPABILITY, validateRuntimePrompt } from "./runtime-prompt.js";
2
3
  import { randomUUID } from "node:crypto";
3
4
  import { chmodSync, closeSync, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, writeFileSync, } from "node:fs";
4
5
  import path from "node:path";
5
6
  import { ensureDaemonHome } from "./auth-store.js";
6
- import { AGENT_SERVICE_WS_SCHEMA, AGENT_SERVICE_WS_SUBPROTOCOL, createSandboxFrame, createWorkspaceFileChunk, parseSandboxFrame, UnsupportedSandboxProtocolError, WORKSPACE_FILE_READ_BINARY_CAPABILITY, } from "./agent-service-ws-protocol.js";
7
+ import { AGENT_SERVICE_WS_SCHEMA, AGENT_SERVICE_WS_SUBPROTOCOL, createSandboxFrame, createWorkspaceFileChunk, parseSandboxFrame, UnsupportedSandboxProtocolError, WORKSPACE_FILE_READ_BINARY_CAPABILITY, WORKSPACE_FILES_LIST_CAPABILITY, } from "./agent-service-ws-protocol.js";
7
8
  import { log as defaultLog, setOperationalLogSink, } from "./log.js";
8
9
  import { availableRunCapabilities, runtimeSupportsCourseSkills, } from "./runtime-capabilities.js";
9
10
  import { activationRuntimeEnv, runtimeChildEnv } from "./runtime-env.js";
@@ -861,6 +862,7 @@ export class AgentServiceSandboxClient {
861
862
  protocol_versions: [AGENT_SERVICE_WS_SCHEMA],
862
863
  capabilities: [
863
864
  WORKSPACE_FILE_READ_BINARY_CAPABILITY,
865
+ WORKSPACE_FILES_LIST_CAPABILITY,
864
866
  RUNTIME_PROMPT_CAPABILITY,
865
867
  ...workspaceDurabilityCapabilities(),
866
868
  ],
@@ -1036,6 +1038,11 @@ export class AgentServiceSandboxClient {
1036
1038
  await this.sendCommandAck(frame, "ok");
1037
1039
  return;
1038
1040
  }
1041
+ case "workspace.files.list":
1042
+ void this.handleWorkspaceFilesList(frame).catch(() => {
1043
+ this.log.warn("Workspace file list response failed");
1044
+ });
1045
+ return;
1039
1046
  case "workspace.file.read":
1040
1047
  void this.handleWorkspaceFileRead(frame).catch((error) => {
1041
1048
  this.log.warn("Agent Service workspace file read response failed", {
@@ -1790,6 +1797,41 @@ export class AgentServiceSandboxClient {
1790
1797
  ...(retryable !== undefined ? { retryable } : {}),
1791
1798
  });
1792
1799
  }
1800
+ async handleWorkspaceFilesList(frame) {
1801
+ const session = this.state.sessions[frame.runtime_session_id];
1802
+ const requestId = frame.payload.request_id;
1803
+ let payload = {
1804
+ request_id: requestId, status: "rejected", error_code: "workspace_file_unavailable",
1805
+ };
1806
+ if (typeof requestId !== "string" || !WORKSPACE_FILE_TRANSFER_ID.test(requestId))
1807
+ return;
1808
+ if (session?.workspaceId && !this.workspaceFileReadInFlight) {
1809
+ this.workspaceFileReadInFlight = true;
1810
+ try {
1811
+ const scan = await scanWorkspaceFiles(runtimeSessionWorkspaceDir(session.workspaceId, this.sandboxGeneration), { maxPreviewChars: 0 });
1812
+ payload = {
1813
+ request_id: requestId, status: "ok", truncated: scan.truncated,
1814
+ files: scan.files.map(({ path, name, size_bytes, sha256 }) => ({
1815
+ path, name, size_bytes, sha256,
1816
+ })),
1817
+ };
1818
+ }
1819
+ catch {
1820
+ // A scan failure is never an empty successful directory.
1821
+ }
1822
+ finally {
1823
+ this.workspaceFileReadInFlight = false;
1824
+ }
1825
+ }
1826
+ if (frame.sandbox_generation !== this.sandboxGeneration ||
1827
+ frame.connection_epoch !== this.connectionEpoch)
1828
+ return;
1829
+ await this.sendFrame(createSandboxFrame({
1830
+ type: "workspace.files.result", sandboxId: this.options.sandboxId,
1831
+ sandboxGeneration: this.sandboxGeneration, connectionEpoch: this.connectionEpoch,
1832
+ seq: this.nextOutboundSeq(), runtimeSessionId: frame.runtime_session_id, payload,
1833
+ }));
1834
+ }
1793
1835
  async handleWorkspaceFileRead(frame) {
1794
1836
  const transferId = frame.payload.transfer_id;
1795
1837
  const relativePath = frame.payload.path;
@@ -1,9 +1,10 @@
1
1
  export declare const AGENT_SERVICE_WS_SCHEMA: "botlearn-agent-sandbox-ws/0.4";
2
2
  export declare const AGENT_SERVICE_WS_SUBPROTOCOL: "botlearn-agent-sandbox.v4";
3
3
  export declare const WORKSPACE_FILE_READ_BINARY_CAPABILITY: "workspace_file_read_binary_v1";
4
+ export declare const WORKSPACE_FILES_LIST_CAPABILITY: "workspace_files_list_v1";
4
5
  export declare const WORKSPACE_FILE_CHUNK_BYTES: number;
5
6
  export declare const WORKSPACE_FILE_CHUNK_HEADER_BYTES = 29;
6
- 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" | "ping" | "sandbox.ready" | "sandbox.heartbeat" | "command.ack" | "session.opened" | "session.open_failed" | "session.closed" | "activation.cleaned" | "turn.event" | "turn.file.report" | "workspace.file.result" | "sandbox.drained" | "sandbox.log" | "pong" | "protocol.error";
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.file.report" | "workspace.file.result" | "workspace.files.result" | "sandbox.drained" | "sandbox.log" | "pong" | "protocol.error";
7
8
  export declare class UnsupportedSandboxProtocolError extends Error {
8
9
  readonly schemaVersion: unknown;
9
10
  constructor(schemaVersion: unknown);
@@ -2,6 +2,7 @@ import { randomUUID } from "node:crypto";
2
2
  export const AGENT_SERVICE_WS_SCHEMA = "botlearn-agent-sandbox-ws/0.4";
3
3
  export const AGENT_SERVICE_WS_SUBPROTOCOL = "botlearn-agent-sandbox.v4";
4
4
  export const WORKSPACE_FILE_READ_BINARY_CAPABILITY = "workspace_file_read_binary_v1";
5
+ export const WORKSPACE_FILES_LIST_CAPABILITY = "workspace_files_list_v1";
5
6
  export const WORKSPACE_FILE_CHUNK_BYTES = 64 * 1024;
6
7
  export const WORKSPACE_FILE_CHUNK_HEADER_BYTES = 29;
7
8
  const WORKSPACE_FILE_CHUNK_MAGIC = Buffer.from("BLWF", "ascii");
@@ -18,6 +19,7 @@ const FRAME_TYPES = new Set([
18
19
  "event.ack",
19
20
  "auth.rotate",
20
21
  "workspace.file.read",
22
+ "workspace.files.list",
21
23
  "ping",
22
24
  "sandbox.ready",
23
25
  "sandbox.heartbeat",
@@ -29,6 +31,7 @@ const FRAME_TYPES = new Set([
29
31
  "turn.event",
30
32
  "turn.file.report",
31
33
  "workspace.file.result",
34
+ "workspace.files.result",
32
35
  "sandbox.drained",
33
36
  "sandbox.log",
34
37
  "pong",
@@ -43,7 +46,9 @@ const SESSION_TYPES = new Set([
43
46
  "session.open_failed",
44
47
  "session.closed",
45
48
  "workspace.file.read",
49
+ "workspace.files.list",
46
50
  "workspace.file.result",
51
+ "workspace.files.result",
47
52
  ]);
48
53
  /** TURN 帧:必须带 runtime_session_id + agent_run_id + worker_attempt + activation_id 四元组。 */
49
54
  const TURN_TYPES = new Set([
@@ -94,6 +94,7 @@ export async function scanWorkspaceFiles(workspaceDir, limits = {}) {
94
94
  entries = await readdir(dir, { withFileTypes: true });
95
95
  }
96
96
  catch {
97
+ truncated = true;
97
98
  return;
98
99
  }
99
100
  entries.sort((a, b) => a.name.localeCompare(b.name));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botlearn-course/daemon",
3
- "version": "0.0.26-v2",
3
+ "version": "0.0.27-beta.1",
4
4
  "description": "Lightweight BotLearn Course daemon: run course tasks on your own machine with your own agent runtime (BYOA).",
5
5
  "type": "module",
6
6
  "bin": {