@botlearn-course/daemon 0.0.29-beta.7 → 0.0.29-beta.8

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.
@@ -3,6 +3,7 @@ import type { WorkspaceScanMeasurement } from "./file-candidates.js";
3
3
  import { type RuntimeSkillProviderFactory } from "./runtime-skills.js";
4
4
  import { type PersistentSessionExecution, type PreparedPersistentTurn, type RunReportingClient } from "./run-dispatcher.js";
5
5
  import type { CourseRuntime, RunEvent, RunEventReceipt, RunFileCandidate, RunFileRecord, RunStartPayload } from "./types.js";
6
+ import type { StartupTimer } from "./startup-timings.js";
6
7
  /** Task-scoped CourseRuns route each run to its own native thread (course-agent-session-scope.md). */
7
8
  export declare const NATIVE_SESSION_KEY_CAPABILITY = "native_session_key_v1";
8
9
  export declare function workspaceDurabilityCapabilities(): string[];
@@ -18,6 +19,8 @@ export interface AgentServiceSandboxOptions {
18
19
  sleep?: (ms: number) => Promise<void>;
19
20
  /** Test/provider injection; production uses the bounded HTTP Runtime Skill Provider. */
20
21
  prepareSkillProvider?: RuntimeSkillProviderFactory;
22
+ /** Cold-start stage timer; its payload is sent once with the first `sandbox.ready`. */
23
+ startupTimer?: StartupTimer;
21
24
  }
22
25
  /**
23
26
  * Long-running daemon client for one user-scoped managed sandbox (ADR-015).
@@ -784,7 +784,9 @@ export class AgentServiceSandboxClient {
784
784
  // Attach message/close listeners before awaiting open; the server may send
785
785
  // sandbox.hello immediately after the upgrade completes.
786
786
  const inbox = new SocketInbox(socket);
787
+ this.options.startupTimer?.mark("state_loaded");
787
788
  await waitForOpen(socket);
789
+ this.options.startupTimer?.mark("websocket_open");
788
790
  if (socket.protocol !== AGENT_SERVICE_WS_SUBPROTOCOL) {
789
791
  socket.close(4410, "protocol_incompatible");
790
792
  throw new SandboxClosedError(4410, "protocol_incompatible");
@@ -855,6 +857,7 @@ export class AgentServiceSandboxClient {
855
857
  }
856
858
  }
857
859
  async handleHello(frame) {
860
+ this.options.startupTimer?.mark("hello_received");
858
861
  await this.lifecycleChain;
859
862
  if (frame.sandbox_id !== this.options.sandboxId) {
860
863
  throw new SandboxClosedError(4403, "sandbox_mismatch");
@@ -899,6 +902,8 @@ export class AgentServiceSandboxClient {
899
902
  this.runtimeLogPolicy = runtimeLogPolicy(frame.payload.runtime_log_policy);
900
903
  this.persist();
901
904
  assertWorkspaceFilesystem(process.env.BOTLEARN_AGENT_SERVICE_WORKSPACE_ROOT ?? "");
905
+ this.options.startupTimer?.mark("hello_processed");
906
+ const startupTimings = this.options.startupTimer?.takeReadyPayload();
902
907
  await this.sendControlFrame("sandbox.ready", {
903
908
  protocol_versions: [AGENT_SERVICE_WS_SCHEMA],
904
909
  capabilities: [
@@ -917,6 +922,7 @@ export class AgentServiceSandboxClient {
917
922
  },
918
923
  resumed_sessions: Object.keys(this.state.sessions),
919
924
  spool_frames: this.spoolFrameCount(),
925
+ ...(startupTimings ? { startup_timings: startupTimings } : {}),
920
926
  });
921
927
  this.runtimeLogHandshakeReady = true;
922
928
  }
package/dist/cli.js CHANGED
@@ -6,6 +6,7 @@ import { AgentServiceSandboxClient } from "./agent-service-sandbox.js";
6
6
  import { augmentProcessPath } from "./path-env.js";
7
7
  import { redactSecretString } from "./redaction.js";
8
8
  import { clearAgentServiceControlEnv } from "./runtime-env.js";
9
+ import { StartupTimer, parseBootstrapStartupTimings } from "./startup-timings.js";
9
10
  import { RUNTIME_MODULES, fakeRuntimeEnabled } from "./runtimes/index.js";
10
11
  const pkg = createRequire(import.meta.url)("../package.json");
11
12
  const SESSION_BOOTSTRAP_MAX_BYTES = 64 * 1024;
@@ -119,6 +120,8 @@ export function assertManagedCourseDaemonVersion(actualVersion, selectedVersion)
119
120
  }
120
121
  }
121
122
  async function cmdAgentServiceSession(args) {
123
+ const startupTimer = new StartupTimer(parseBootstrapStartupTimings(process.env.BOTLEARN_BOOTSTRAP_STARTUP_TIMINGS));
124
+ startupTimer.mark("process_start");
122
125
  const bootstrap = args.flags["bootstrap-stdin"] === true
123
126
  ? await readSandboxBootstrapFromStdin()
124
127
  : {
@@ -132,6 +135,7 @@ async function cmdAgentServiceSession(args) {
132
135
  return 1;
133
136
  }
134
137
  assertManagedCourseDaemonVersion(pkg.version, process.env.BOTLEARN_MANAGED_COURSE_DAEMON_VERSION?.trim() || undefined);
138
+ startupTimer.mark("read_bootstrap");
135
139
  augmentProcessPath();
136
140
  const runtimes = new Map();
137
141
  for (const mod of RUNTIME_MODULES) {
@@ -139,11 +143,13 @@ async function cmdAgentServiceSession(args) {
139
143
  continue;
140
144
  runtimes.set(mod.id, mod.create());
141
145
  }
146
+ startupTimer.mark("create_runtimes");
142
147
  const client = new AgentServiceSandboxClient({
143
148
  wsUrl,
144
149
  sandboxId,
145
150
  sandboxToken,
146
151
  runtimes,
152
+ startupTimer,
147
153
  daemonVersion: pkg.version,
148
154
  deepseekTuiVersion: process.env.BOTLEARN_MANAGED_DEEPSEEK_TUI_VERSION?.trim() || undefined,
149
155
  });
@@ -92,8 +92,9 @@ export class CourseSkillsMcpRuntime {
92
92
  try {
93
93
  if (name === "list_skills") {
94
94
  requireExactArguments(args, []);
95
+ const catalog = this.options.prepared?.catalog ?? [];
95
96
  return toolSuccess(id, "skill_catalog_listed", {
96
- skills: (this.options.prepared?.catalog ?? []).map((entry) => ({
97
+ skills: catalog.map((entry) => ({
97
98
  ref: entry.ref,
98
99
  digest: entry.digest,
99
100
  name: entry.name,
@@ -101,6 +102,9 @@ export class CourseSkillsMcpRuntime {
101
102
  version: entry.version,
102
103
  requiredCapabilities: entry.requiredCapabilities,
103
104
  })),
105
+ ...(catalog.length === 0 ? {
106
+ message: "当前课程未为本次任务配备 Skill(技能),无需重复获取技能目录。请依据当前任务说明继续。",
107
+ } : {}),
104
108
  });
105
109
  }
106
110
  if (name === "load_skill") {
@@ -21,6 +21,7 @@ const AGENT_SERVICE_SUPERVISOR_ENV_KEYS = [
21
21
  "BOTLEARN_MANAGED_DEEPSEEK_TUI_VERSION",
22
22
  "BOTLEARN_AGENT_SERVICE_WORKSPACE_ROOT",
23
23
  "BOTLEARN_AGENT_SERVICE_PROFILE_ROOT",
24
+ "BOTLEARN_BOOTSTRAP_STARTUP_TIMINGS",
24
25
  ];
25
26
  const ACTIVATION_RUNTIME_ENV_KEYS = new Set([
26
27
  "DEEPSEEK_API_KEY",
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Cold-start timing for one daemon process, reported once in `sandbox.ready`.
3
+ *
4
+ * The runtime bootstrap hands its own stage timings over in
5
+ * `BOTLEARN_BOOTSTRAP_STARTUP_TIMINGS`; the daemon appends its stages so Agent
6
+ * Service can log one launcher-to-ready timeline. Values are durations and epoch
7
+ * milliseconds only — never paths, tokens or other payload content.
8
+ */
9
+ export interface BootstrapStartupTimings {
10
+ process_started_at_ms?: number;
11
+ bootstrap_started_at_ms?: number;
12
+ stages_ms: Record<string, number>;
13
+ total_ms?: number;
14
+ }
15
+ export interface StartupTimingsPayload {
16
+ bootstrap?: BootstrapStartupTimings;
17
+ daemon_process_started_at_ms: number;
18
+ daemon_stages_ms: Record<string, number>;
19
+ }
20
+ /** Parse the bootstrap hand-off; anything malformed is dropped, never thrown. */
21
+ export declare function parseBootstrapStartupTimings(raw: string | undefined): BootstrapStartupTimings | undefined;
22
+ /** Sequential stage timer: each mark records milliseconds since the previous mark. */
23
+ export declare class StartupTimer {
24
+ private readonly bootstrap;
25
+ private readonly now;
26
+ private readonly processStartedAt;
27
+ private last;
28
+ private readonly stages;
29
+ private reported;
30
+ constructor(bootstrap: BootstrapStartupTimings | undefined, now?: () => number, processStartedAt?: number);
31
+ mark(stage: string): void;
32
+ /** Return the payload once; later reconnects of the same process report nothing. */
33
+ takeReadyPayload(): StartupTimingsPayload | undefined;
34
+ }
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Cold-start timing for one daemon process, reported once in `sandbox.ready`.
3
+ *
4
+ * The runtime bootstrap hands its own stage timings over in
5
+ * `BOTLEARN_BOOTSTRAP_STARTUP_TIMINGS`; the daemon appends its stages so Agent
6
+ * Service can log one launcher-to-ready timeline. Values are durations and epoch
7
+ * milliseconds only — never paths, tokens or other payload content.
8
+ */
9
+ const MAX_STAGES = 32;
10
+ const STAGE_NAME = /^[a-z][a-z0-9_]{0,47}$/u;
11
+ const MAX_MS = 24 * 60 * 60 * 1000;
12
+ function boundedMs(value, max = MAX_MS) {
13
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= max
14
+ ? Math.round(value)
15
+ : undefined;
16
+ }
17
+ function boundedEpochMs(value) {
18
+ return boundedMs(value, Number.MAX_SAFE_INTEGER);
19
+ }
20
+ /** Parse the bootstrap hand-off; anything malformed is dropped, never thrown. */
21
+ export function parseBootstrapStartupTimings(raw) {
22
+ if (!raw || raw.length > 4096)
23
+ return undefined;
24
+ let parsed;
25
+ try {
26
+ parsed = JSON.parse(raw);
27
+ }
28
+ catch {
29
+ return undefined;
30
+ }
31
+ if (!parsed || typeof parsed !== "object")
32
+ return undefined;
33
+ const source = parsed;
34
+ const stages = {};
35
+ const rawStages = source.stagesMs;
36
+ if (rawStages && typeof rawStages === "object") {
37
+ for (const [name, value] of Object.entries(rawStages).slice(0, MAX_STAGES)) {
38
+ const ms = boundedMs(value);
39
+ if (STAGE_NAME.test(name) && ms !== undefined)
40
+ stages[name] = ms;
41
+ }
42
+ }
43
+ const result = { stages_ms: stages };
44
+ const processStartedAt = boundedEpochMs(source.processStartedAtMs);
45
+ const bootstrapStartedAt = boundedEpochMs(source.bootstrapStartedAtMs);
46
+ const total = boundedMs(source.totalMs);
47
+ if (processStartedAt !== undefined)
48
+ result.process_started_at_ms = processStartedAt;
49
+ if (bootstrapStartedAt !== undefined)
50
+ result.bootstrap_started_at_ms = bootstrapStartedAt;
51
+ if (total !== undefined)
52
+ result.total_ms = total;
53
+ return result;
54
+ }
55
+ /** Sequential stage timer: each mark records milliseconds since the previous mark. */
56
+ export class StartupTimer {
57
+ bootstrap;
58
+ now;
59
+ processStartedAt;
60
+ last;
61
+ stages = {};
62
+ reported = false;
63
+ constructor(bootstrap, now = Date.now, processStartedAt = performance.timeOrigin) {
64
+ this.bootstrap = bootstrap;
65
+ this.now = now;
66
+ this.processStartedAt = processStartedAt;
67
+ this.last = Math.round(processStartedAt);
68
+ }
69
+ mark(stage) {
70
+ if (this.reported || !STAGE_NAME.test(stage) || stage in this.stages)
71
+ return;
72
+ if (Object.keys(this.stages).length >= MAX_STAGES)
73
+ return;
74
+ const current = this.now();
75
+ this.stages[stage] = Math.max(0, Math.round(current - this.last));
76
+ this.last = current;
77
+ }
78
+ /** Return the payload once; later reconnects of the same process report nothing. */
79
+ takeReadyPayload() {
80
+ if (this.reported)
81
+ return undefined;
82
+ this.reported = true;
83
+ return {
84
+ ...(this.bootstrap ? { bootstrap: this.bootstrap } : {}),
85
+ daemon_process_started_at_ms: Math.round(this.processStartedAt),
86
+ daemon_stages_ms: { ...this.stages },
87
+ };
88
+ }
89
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botlearn-course/daemon",
3
- "version": "0.0.29-beta.7",
3
+ "version": "0.0.29-beta.8",
4
4
  "description": "BotLearn Course daemon for Agent Service managed sandboxes (internal).",
5
5
  "type": "module",
6
6
  "bin": {