@botlearn-course/daemon 0.0.29 → 0.0.30-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.
@@ -440,8 +440,11 @@ export class DeepseekTuiAdapter {
440
440
  // Newer runtimes must advertise native external tools; never silently fall
441
441
  // back to asynchronous MCP discovery after a capability/protocol failure.
442
442
  const legacySkillsMcp = runtimeVersion === "0.8.39";
443
- const needsCourseSkills = Boolean(opts.skillProvider || managedActivationId);
444
- const courseSkills = needsCourseSkills && !legacySkillsMcp
443
+ // Managed turns always run in an isolated runtime profile; the Skill tools themselves
444
+ // are exposed only when this activation authorizes at least one course Skill.
445
+ const isolatesSkillProfile = Boolean(opts.skillProvider || managedActivationId);
446
+ const exposesCourseSkills = (opts.skillProvider?.catalog.length ?? 0) > 0;
447
+ const courseSkills = exposesCourseSkills && !legacySkillsMcp
445
448
  ? new DeepseekCourseSkills({
446
449
  prepared: opts.skillProvider,
447
450
  onEvent: opts.onSkillEvent ?? (async () => { }),
@@ -451,14 +454,14 @@ export class DeepseekTuiAdapter {
451
454
  let progressMcpConfig;
452
455
  let runtimeConfigPath;
453
456
  try {
454
- courseSkillsMcpServer = needsCourseSkills && legacySkillsMcp
457
+ courseSkillsMcpServer = exposesCourseSkills && legacySkillsMcp
455
458
  ? await startCourseSkillsMcpServer({
456
459
  prepared: opts.skillProvider,
457
460
  onEvent: opts.onSkillEvent ?? (async () => { }),
458
461
  })
459
462
  : undefined;
460
463
  progressMcpConfig =
461
- this.progressPromptInjectionEnabled || needsCourseSkills
464
+ this.progressPromptInjectionEnabled || isolatesSkillProfile
462
465
  || (managedActivationId && opts.env?.DEEPSEEK_BASE_URL?.trim())
463
466
  ? createProgressMcpConfig({
464
467
  ...(courseSkillsMcpServer
@@ -466,7 +469,7 @@ export class DeepseekTuiAdapter {
466
469
  : {}),
467
470
  })
468
471
  : undefined;
469
- if (needsCourseSkills && progressMcpConfig) {
472
+ if (isolatesSkillProfile && progressMcpConfig) {
470
473
  prepareRuntimeSkillsHome(progressMcpConfig.dir, Boolean(this.managedActivationId(opts)));
471
474
  }
472
475
  runtimeConfigPath = createManagedRuntimeConfig(opts, progressMcpConfig);
@@ -490,7 +493,7 @@ export class DeepseekTuiAdapter {
490
493
  try {
491
494
  child = this.spawnFn(launch.binary, launch.args, {
492
495
  cwd: opts.cwd,
493
- env: this.spawnEnv(opts, progressMcpConfig?.path, runtimeConfigPath, progressMcpConfig && needsCourseSkills
496
+ env: this.spawnEnv(opts, progressMcpConfig?.path, runtimeConfigPath, progressMcpConfig && isolatesSkillProfile
494
497
  ? path.join(progressMcpConfig.dir, RUNTIME_SKILLS_RELATIVE_PATH)
495
498
  : undefined),
496
499
  ...launch.identity,
@@ -1494,7 +1497,11 @@ function extractDeepseekError(eventName, payload) {
1494
1497
  return undefined;
1495
1498
  }
1496
1499
  function classifyDeepseekProviderError(error) {
1497
- return /"code"\s*:\s*"insufficient_user_quota"/.test(error)
1500
+ // DeepSeek can flatten a provider 403 into this authorization-prefixed message,
1501
+ // dropping the structured code. Match the specific precharge signature only.
1502
+ const quotaCode = /"code"\s*:\s*"(?:insufficient_user_quota|insufficient_token_quota|insufficient_quota|trial_credit_insufficient|credit_insufficient)"/.test(error);
1503
+ const prechargeFailure = /^Authorization failed:\s*预扣费额度失败,\s*用户剩余额度:\s*[$$][0-9]+(?:\.[0-9]+)?,\s*需要预扣费额度:\s*[$$][0-9]+(?:\.[0-9]+)?(?:\s|$)/.test(error);
1504
+ return quotaCode || prechargeFailure
1498
1505
  ? "model_token_quota_exhausted"
1499
1506
  : undefined;
1500
1507
  }
@@ -77,11 +77,15 @@ export class PiAgentAdapter {
77
77
  const prepared = await prepareManagedPi(opts);
78
78
  let skills;
79
79
  try {
80
- skills = await startCourseSkillsMcpServer({ prepared: opts.skillProvider,
81
- onEvent: opts.onSkillEvent ?? (async () => { }) });
82
- await skills.markApplied();
83
- const delegation = writeManagedPiDelegation(prepared.delegationDir, opts, skills.socketPath);
84
- return await this.execute({ ...opts, env: prepared.env }, skills.socketPath, true, delegation);
80
+ // Without an authorized Skill the turn gets no Skill tools: an empty catalog only
81
+ // invites the model to look it up and narrate the result to the learner.
82
+ if ((opts.skillProvider?.catalog.length ?? 0) > 0) {
83
+ skills = await startCourseSkillsMcpServer({ prepared: opts.skillProvider,
84
+ onEvent: opts.onSkillEvent ?? (async () => { }) });
85
+ await skills.markApplied();
86
+ }
87
+ const delegation = writeManagedPiDelegation(prepared.delegationDir, opts, skills?.socketPath);
88
+ return await this.execute({ ...opts, env: prepared.env }, skills?.socketPath, true, delegation);
85
89
  }
86
90
  finally {
87
91
  try {
@@ -56,11 +56,17 @@ export function readDelegation(file) {
56
56
  throw new Error("Invalid managed delegation path");
57
57
  const config = object(JSON.parse(readFileSync(file, "utf8")));
58
58
  const keys = ["binary", "model", "workspaceDir", "systemPrompt", "workerPromptPath", "webExtension",
59
- "skillsExtension", "skillsSocket", "subagentExtension"];
59
+ "subagentExtension"];
60
60
  for (const key of keys) {
61
61
  if (typeof config[key] !== "string" || !config[key])
62
62
  throw new Error("Invalid managed delegation configuration");
63
63
  }
64
+ // Skill delegation is all-or-nothing: an activation without Skills omits both fields.
65
+ const skillKeys = ["skillsExtension", "skillsSocket"];
66
+ const presentSkillKeys = skillKeys.filter((key) => config[key] !== undefined);
67
+ if (presentSkillKeys.length === 1 || presentSkillKeys.some((key) => typeof config[key] !== "string" || !config[key])) {
68
+ throw new Error("Invalid managed delegation configuration");
69
+ }
64
70
  if (config.thinking !== undefined && typeof config.thinking !== "string") {
65
71
  throw new Error("Invalid managed delegation thinking level");
66
72
  }
@@ -73,7 +79,9 @@ export function childArgs(config, manifestPath, task) {
73
79
  "--model", config.model];
74
80
  if (config.thinking)
75
81
  args.push("--thinking", config.thinking);
76
- args.push("--system-prompt", config.systemPrompt, "--append-system-prompt", config.workerPromptPath, "--extension", config.skillsExtension, "--botlearn-course-skills-socket", config.skillsSocket, "--extension", config.webExtension, "--extension", config.subagentExtension, "--botlearn-delegation-manifest", manifestPath, `Task: ${task}`);
82
+ args.push("--system-prompt", config.systemPrompt, "--append-system-prompt", config.workerPromptPath, ...(config.skillsExtension && config.skillsSocket ? [
83
+ "--extension", config.skillsExtension, "--botlearn-course-skills-socket", config.skillsSocket,
84
+ ] : []), "--extension", config.webExtension, "--extension", config.subagentExtension, "--botlearn-delegation-manifest", manifestPath, `Task: ${task}`);
77
85
  return args;
78
86
  }
79
87
  const active = new Set();
@@ -10,8 +10,9 @@ export interface ManagedPiDelegation {
10
10
  systemPrompt: string;
11
11
  workerPromptPath: string;
12
12
  webExtension: string;
13
- skillsExtension: string;
14
- skillsSocket: string;
13
+ /** Present only when the activation authorizes at least one course Skill. */
14
+ skillsExtension?: string;
15
+ skillsSocket?: string;
15
16
  subagentExtension: string;
16
17
  }
17
18
  /** The image verifies the CLI once; per-turn probes read immutable installed metadata. */
@@ -22,4 +23,4 @@ export declare function prepareManagedPi(opts: EngineRunOptions): Promise<{
22
23
  cleanup(): void;
23
24
  }>;
24
25
  /** Called after the course Skills socket exists, before the first Pi process starts. */
25
- export declare function writeManagedPiDelegation(dir: string, opts: EngineRunOptions, skillsSocket: string): string;
26
+ export declare function writeManagedPiDelegation(dir: string, opts: EngineRunOptions, skillsSocket?: string): string;
@@ -102,7 +102,8 @@ export function writeManagedPiDelegation(dir, opts, skillsSocket) {
102
102
  const thinkingIndex = opts.extraArgs?.indexOf("--thinking") ?? -1;
103
103
  const model = modelIndex >= 0 ? opts.extraArgs?.[modelIndex + 1] : undefined;
104
104
  const thinking = thinkingIndex >= 0 ? opts.extraArgs?.[thinkingIndex + 1] : undefined;
105
- if (!model || opts.systemPrompt === undefined || !skillsSocket.startsWith("/")) {
105
+ if (!model || opts.systemPrompt === undefined
106
+ || (skillsSocket !== undefined && !skillsSocket.startsWith("/"))) {
106
107
  throw new Error("pi-agent managed delegation configuration is incomplete");
107
108
  }
108
109
  const workerPromptPath = path.join(dir, "worker.md");
@@ -116,8 +117,10 @@ export function writeManagedPiDelegation(dir, opts, skillsSocket) {
116
117
  systemPrompt: opts.systemPrompt,
117
118
  workerPromptPath,
118
119
  webExtension: MANAGED_PI_WEB_ACCESS_EXTENSION,
119
- skillsExtension: path.resolve(fileURLToPath(new URL("./pi-course-skills-extension.js", import.meta.url))),
120
- skillsSocket,
120
+ ...(skillsSocket ? {
121
+ skillsExtension: path.resolve(fileURLToPath(new URL("./pi-course-skills-extension.js", import.meta.url))),
122
+ skillsSocket,
123
+ } : {}),
121
124
  subagentExtension: MANAGED_PI_SUBAGENT_EXTENSION,
122
125
  };
123
126
  const file = path.join(dir, "launch.json");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botlearn-course/daemon",
3
- "version": "0.0.29",
3
+ "version": "0.0.30-beta.1",
4
4
  "description": "BotLearn Course daemon for Agent Service managed sandboxes (internal).",
5
5
  "type": "module",
6
6
  "bin": {