@capybara-hq/kernel 0.1.0-rc.76 → 0.1.0-rc.77

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/bootstrap.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "schemaVersion": 1,
4
4
  "marketplace": {
5
5
  "url": "https://github.com/capybara-hq/plugins.git",
6
- "commit": "1c9b0dd4ae64d1f199afa3a17d35de4810ab08e5"
6
+ "commit": "a9c5d9c9328a855162c2bbaf758f261add863fa2"
7
7
  },
8
8
  "plugins": [
9
9
  {
@@ -90,16 +90,16 @@
90
90
  "name": "device-docker",
91
91
  "source": "npm",
92
92
  "npm": "@capybara-hq/plugin-device-docker",
93
- "version": "0.1.0-rc.23",
94
- "integrity": "sha512-xR28dC3NPIsRaG4jprsvWa7nFZkc7aURbl7o16TTP7j0oNBEhkkZcj2EQRRfz3/XpRMKSxqVT2tdK3KMK3y0AQ==",
93
+ "version": "0.1.0-rc.24",
94
+ "integrity": "sha512-M+XP8iLgbQe8K27u29Ta2O5Pg+1pCHT4lFZPN9VxyP9+FrtqBcYG0Uf0tC9/f1MUWBdN4fesyeqHXUpoObUg+w==",
95
95
  "required": false
96
96
  },
97
97
  {
98
98
  "name": "device-local",
99
99
  "source": "npm",
100
100
  "npm": "@capybara-hq/plugin-device-local",
101
- "version": "0.1.0-rc.5",
102
- "integrity": "sha512-HaR5VFeK2AqMy4EM6glwGd0cZtgjMMS8AsOqimUCYPMT/eubrP/VuxB3eAFpR007xvommVIv5jd5XnXLbiYanw==",
101
+ "version": "0.1.0-rc.6",
102
+ "integrity": "sha512-wB9147kTphsBKwtvcgd6fylqECDqtqeZfkqiDY2jBAcErjrOL19alogWYIstof9les4CSi6tO8VgBgdfSYN97A==",
103
103
  "required": false,
104
104
  "scope": "all"
105
105
  },
@@ -203,7 +203,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
203
203
  /** The host versions (an entry's `minKernel` is judged against them). */
204
204
  export declare const HOST_VERSIONS: {
205
205
  readonly kernel: string;
206
- readonly sdk: "0.1.0-rc.61";
206
+ readonly sdk: "0.1.0-rc.62";
207
207
  };
208
208
  /** Whether this deployment satisfies the entry's `minKernel`. */
209
209
  export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
@@ -150,7 +150,7 @@ export declare const BOOTSTRAP_LOCK_TTL: unique symbol;
150
150
  /** What a run imports a declarative entry or an entry's catalog version with. */
151
151
  export type BootstrapImports = Pick<PluginImport, "prepare" | "prepareGit" | "confirm">;
152
152
  /**
153
- * What a run moves the platform to a raised pin of a plugin without an extension with (the
153
+ * What a run moves the platform to a raised pin with, with or without an extension (the
154
154
  * platform plugin update, acting as the kernel).
155
155
  */
156
156
  export type BootstrapUpdater = Pick<PlatformPluginUpdater, "preview" | "update">;
@@ -227,7 +227,7 @@ export declare class BootstrapService {
227
227
  packages?: ReadonlyMap<string, Uint8Array>;
228
228
  /** The plugin import a declarative entry (or an entry's catalog version) goes through. */
229
229
  imports: BootstrapImports;
230
- /** The platform update a raised pin of a declarative entry goes through. */
230
+ /** The platform update a raised pin goes through (after the extension step, if any). */
231
231
  updater: BootstrapUpdater;
232
232
  }): Promise<BootstrapResult>;
233
233
  /**
@@ -255,6 +255,23 @@ export declare class BootstrapService {
255
255
  /** The entry names the last completed run handled (undefined before any run completed). */
256
256
  private lastRunNames;
257
257
  private entry;
258
+ /**
259
+ * After the extension step: when the install record runs the pin from `bootstrap` and the
260
+ * plugin's platform version came from `bootstrap` at a lower version (raised just now, or by a
261
+ * run before core#727 that moved only the extension), the platform update moves the platform to
262
+ * the pin, acting as the kernel. A version the super admin moved to stays; a disabled item gets
263
+ * none (the update refuses it; the super admin applies the version once they enable it).
264
+ * Returns whether the platform moved.
265
+ */
266
+ private raisePlatform;
267
+ /**
268
+ * The platform update to the pin, acting as the kernel (actor `null`). The update recomputes its
269
+ * preview under the item's lock; a scope sync the extension step owed may run between the two
270
+ * and change the orgs the preview covers (409 `plugin.upgrade_stale`): previewed again, a few
271
+ * times.
272
+ */
273
+ private applyPlatform;
274
+ private logDisabled;
258
275
  /**
259
276
  * The live (not deleted) platform catalog item of this name: its platform version (the one orgs
260
277
  * install, else its latest) and where that version came from. undefined: no such item.
@@ -436,22 +436,18 @@ let BootstrapService = class BootstrapService {
436
436
  if (live !== undefined) {
437
437
  // As the extension path does: a version the bootstrap put there is raised to the pin; one
438
438
  // the super admin moved to (another source, or a higher version) stays
439
- if (live.source !== "bootstrap" || !isLower(live.version, e.version)) {
439
+ if (!raisable(live, e.version)) {
440
440
  return { name: e.name, action: "kept", version: live.version };
441
441
  }
442
442
  if (live.disabled) {
443
443
  // The update refuses a disabled item: the version waits in the catalog, and the super
444
444
  // admin applies it once they enable the plugin
445
445
  await this.importOnly(e, bytes, source, imports, git);
446
- this.log.info("bootstrap: the plugin is disabled on the deployment; the pinned version is imported, not applied", { plugin: e.name, version: e.version, current: live.version });
446
+ this.logDisabled(e, live.version);
447
447
  return { name: e.name, action: "kept", version: live.version };
448
448
  }
449
449
  await this.importOnly(e, bytes, source, imports, git, true);
450
- const preview = await updater.preview(live.itemId, e.version);
451
- await updater.update(null, live.itemId, {
452
- version: e.version,
453
- diffHash: preview.diffHash,
454
- });
450
+ await this.applyPlatform(updater, live.itemId, e.version);
455
451
  return { name: e.name, action: "upgraded", version: e.version };
456
452
  }
457
453
  // A builtin entry a super admin removed is put back; an optional one stays out (Ruling 5)
@@ -509,8 +505,62 @@ let BootstrapService = class BootstrapService {
509
505
  leftDisabled = await this.enableOrWarn(e);
510
506
  }
511
507
  await this.markBuiltin(e.name, builtin);
508
+ // The catalog version of the pin is imported now; the platform (its skills, templates, themes
509
+ // and org installs) follows the extension the same way a declarative entry does (core#727)
510
+ if (await this.raisePlatform(e, updater)) {
511
+ result = { name: e.name, action: "upgraded", version: e.version };
512
+ }
512
513
  return leftDisabled === undefined ? result : { ...result, leftDisabled };
513
514
  }
515
+ /**
516
+ * After the extension step: when the install record runs the pin from `bootstrap` and the
517
+ * plugin's platform version came from `bootstrap` at a lower version (raised just now, or by a
518
+ * run before core#727 that moved only the extension), the platform update moves the platform to
519
+ * the pin, acting as the kernel. A version the super admin moved to stays; a disabled item gets
520
+ * none (the update refuses it; the super admin applies the version once they enable it).
521
+ * Returns whether the platform moved.
522
+ */
523
+ async raisePlatform(e, updater) {
524
+ const row = await this.db
525
+ .selectFrom("extension_installs")
526
+ .select(["version", "source"])
527
+ .where("name", "=", e.name)
528
+ .executeTakeFirst();
529
+ if (row?.source !== "bootstrap" || row.version !== e.version)
530
+ return false;
531
+ const live = await this.platformVersion(e.name);
532
+ if (live === undefined || !raisable(live, e.version))
533
+ return false;
534
+ if (live.disabled) {
535
+ this.logDisabled(e, live.version);
536
+ return false;
537
+ }
538
+ await this.applyPlatform(updater, live.itemId, e.version);
539
+ return true;
540
+ }
541
+ /**
542
+ * The platform update to the pin, acting as the kernel (actor `null`). The update recomputes its
543
+ * preview under the item's lock; a scope sync the extension step owed may run between the two
544
+ * and change the orgs the preview covers (409 `plugin.upgrade_stale`): previewed again, a few
545
+ * times.
546
+ */
547
+ async applyPlatform(updater, itemId, version) {
548
+ for (let attempt = 1;; attempt++) {
549
+ const preview = await updater.preview(itemId, version);
550
+ try {
551
+ await updater.update(null, itemId, { version, diffHash: preview.diffHash });
552
+ return;
553
+ }
554
+ catch (err) {
555
+ if (attempt >= 3 || !(err instanceof ApiError) || err.code !== "plugin.upgrade_stale") {
556
+ throw err;
557
+ }
558
+ }
559
+ }
560
+ }
561
+ logDisabled(e, current) {
562
+ this.log.info("bootstrap: the plugin is disabled on the deployment; the pinned version is imported, not applied", { plugin: e.name, version: e.version, current });
563
+ }
514
564
  /**
515
565
  * The live (not deleted) platform catalog item of this name: its platform version (the one orgs
516
566
  * install, else its latest) and where that version came from. undefined: no such item.
@@ -812,3 +862,8 @@ function carried(r, carry) {
812
862
  }
813
863
  /** `installed` is below `pinned` (a version that is not semver is never upgraded). */
814
864
  const isLower = (installed, pinned) => semver.valid(installed) !== null && semver.valid(pinned) !== null && semver.lt(installed, pinned);
865
+ /**
866
+ * A platform version the bootstrap raises to the pin: one the bootstrap put there, below the pin
867
+ * (one the super admin moved to, from another source or at a higher version, stays).
868
+ */
869
+ const raisable = (live, pinned) => live.source === "bootstrap" && isLower(live.version, pinned);
@@ -63,10 +63,12 @@ export declare function findSkillVersion(db: KernelSchemaDb, ctx: Pick<BuiltinCa
63
63
  /** A digest of the right shape for the renderer; only inside the sentinel directory. */
64
64
  export declare const PROJECT_DIR_DIGEST = "000000000000";
65
65
  /** Why a project skill's SKILL.md could not be used (each caller phrases it for its reader). */
66
- export type ProjectSkillProblem = {
67
- kind: "outside_mode";
66
+ export type ProjectSkillProblem =
67
+ /** The path built from the recorded root fails the shape checks (`why`: which). */
68
+ {
69
+ kind: "bad_path";
68
70
  path: string;
69
- mode: string;
71
+ why: string;
70
72
  } | {
71
73
  kind: "gone";
72
74
  path: string;
@@ -97,12 +99,11 @@ export interface ProjectSkillFile {
97
99
  truncated: boolean;
98
100
  }
99
101
  /**
100
- * Reads `<root>/.agents/skills/<name>/SKILL.md` in `s` (its path checked as `Read` checks one,
101
- * {@link checkToolPath}) and parses it; its name must be its
102
- * directory's. Shared by `Skill` and a person's invocation (`SkillInvoker`), so both read a
103
- * project skill the same way. A problem with the file or its path throws
104
- * {@link ProjectSkillReadError}; the sandbox's own failures (offline, lost files, ...) and an abort
105
- * are rethrown as they are.
102
+ * Reads `<root>/.agents/skills/<name>/SKILL.md` in `s` (its path shape checked as `Read` checks
103
+ * one, `validateSandboxPathShape`) and parses it; its name must be its directory's. A problem with
104
+ * the file or its path throws {@link ProjectSkillReadError}; the sandbox's own failures (offline,
105
+ * lost files, a read outside the scope the device admits, ...) and an abort are rethrown as they
106
+ * are.
106
107
  */
107
108
  export declare function readProjectSkill(s: SandboxSession, root: string, bare: string, signal?: AbortSignal): Promise<ProjectSkillFile>;
108
109
  /** 内置工具 `Skill`(见文件头)。 */
@@ -1,5 +1,5 @@
1
1
  import { createHash } from "node:crypto";
2
- import { parseSkillMd, renderSkillBody, SKILL_ENTRY_FILE, SKILL_INVOCATION_LIMITS, SKILLS_SANDBOX_ROOT, skillDigest, skillInvocation, skillSandboxDir, skillSandboxPath, ToolError, } from "@capybara-hq/plugin-sdk";
2
+ import { parseSkillMd, renderSkillBody, SKILL_ENTRY_FILE, SKILL_INVOCATION_LIMITS, SKILLS_SANDBOX_ROOT, skillDigest, skillInvocation, skillSandboxDir, skillSandboxPath, ToolError, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
3
3
  import { sql } from "kysely";
4
4
  import { normalizeStoredDefinition } from "../../agents/definition.js";
5
5
  import { ApiError } from "../../errors.js";
@@ -11,7 +11,7 @@ import { resolveSkillForkType } from "../../runtime/subagents/roster.js";
11
11
  import { invocationOf, resolveSkills } from "../../skills/catalog.js";
12
12
  import { PLATFORM_SOURCE, skillFileStore } from "../../skills/usable.js";
13
13
  import { AGENT_TOOL, SANDBOX_TOOL_NAMES } from "../builtin-names.js";
14
- import { checkToolPath, clip, display, inSandboxPreparation, inToolSandbox, mapSandboxError, sandboxBaseTimeoutMs, sandboxConversationOf, sandboxUnusableReason, withNotices, withPathLease, } from "./sandbox/common.js";
14
+ import { clip, display, inSandboxPreparation, inToolSandbox, mapSandboxError, sandboxBaseTimeoutMs, sandboxConversationOf, sandboxUnusableReason, withNotices, withPathLease, } from "./sandbox/common.js";
15
15
  /**
16
16
  * Builtin tool `Skill` (M5 T14, ruling M17): resolves the name against the latest skills catalog
17
17
  * snapshot in the log to an id and version, and returns that version's SKILL.md body and file list
@@ -392,7 +392,7 @@ const notInProject = (asked, project, names) => {
392
392
  const more = names.length > shown.length ? ", …" : "";
393
393
  return `Skill "${clip(asked, 80)}" is not one of the skills of the project "${project}"; call Skill with one of the project's skills (${shown.length === 0 ? "it lists none" : `${shown.join(", ")}${more}`}).`;
394
394
  };
395
- const projectOutsideModeText = (asked, path, mode) => `Skill "${asked}" cannot be loaded: ${path} is outside what the device can read in ${mode} mode now. Ask the user to switch the device to auto mode, or do the task without the skill.`;
395
+ const projectBadPathText = (asked, path, why) => `Skill "${asked}" cannot be loaded: the project's recorded root makes its SKILL.md path ${clip(path, 300)}, which is not a clean absolute path (${why}), so nothing was read. Ask the user to check the project's location on the device, or do the task without the skill.`;
396
396
  const projectFileGoneText = (asked, path) => `Skill "${asked}" cannot be loaded: ${path} is no longer on the device. Check the project's .agents/skills directory with Glob or Read, or do the task without the skill.`;
397
397
  const projectReadFailedText = (asked, path, why) => `Skill "${asked}" cannot be loaded: reading ${path} on the device failed (${clip(why, 300)}). Retry once; if it fails again, do the task without the skill.`;
398
398
  const projectParseText = (asked, path, why) => `Skill "${asked}" cannot be loaded: ${path} is not a valid SKILL.md (${clip(why, 300)}). Ask the user to fix it, or do the task without the skill.`;
@@ -405,24 +405,20 @@ export class ProjectSkillReadError extends Error {
405
405
  }
406
406
  }
407
407
  /**
408
- * Reads `<root>/.agents/skills/<name>/SKILL.md` in `s` (its path checked as `Read` checks one,
409
- * {@link checkToolPath}) and parses it; its name must be its
410
- * directory's. Shared by `Skill` and a person's invocation (`SkillInvoker`), so both read a
411
- * project skill the same way. A problem with the file or its path throws
412
- * {@link ProjectSkillReadError}; the sandbox's own failures (offline, lost files, ...) and an abort
413
- * are rethrown as they are.
408
+ * Reads `<root>/.agents/skills/<name>/SKILL.md` in `s` (its path shape checked as `Read` checks
409
+ * one, `validateSandboxPathShape`) and parses it; its name must be its directory's. A problem with
410
+ * the file or its path throws {@link ProjectSkillReadError}; the sandbox's own failures (offline,
411
+ * lost files, a read outside the scope the device admits, ...) and an abort are rethrown as they
412
+ * are.
414
413
  */
415
414
  export async function readProjectSkill(s, root, bare, signal = s.signal) {
416
415
  const dir = `${root}/${PROJECT_SKILLS_DIR}/${bare}`;
417
416
  const path = `${dir}/${SKILL_ENTRY_FILE}`;
418
- try {
419
- checkToolPath(path);
420
- }
421
- catch (e) {
422
- if (!(e instanceof ToolError))
423
- throw e;
424
- // only a path whose shape fails (from the recorded root) is refused here
425
- throw new ProjectSkillReadError({ kind: "outside_mode", path, mode: "sandbox" });
417
+ // only a path whose shape fails (from the recorded root) is refused here; what the device may
418
+ // read is the provider's rule, refused by the read itself
419
+ const shape = validateSandboxPathShape(path);
420
+ if (shape.length > 0) {
421
+ throw new ProjectSkillReadError({ kind: "bad_path", path, why: shape.join("; ") });
426
422
  }
427
423
  let read;
428
424
  try {
@@ -469,8 +465,8 @@ export async function readProjectSkill(s, root, bare, signal = s.signal) {
469
465
  /** The model's text for a {@link ProjectSkillProblem} of `Skill`. */
470
466
  function projectProblemText(asked, p) {
471
467
  switch (p.kind) {
472
- case "outside_mode":
473
- return projectOutsideModeText(asked, p.path, p.mode);
468
+ case "bad_path":
469
+ return projectBadPathText(asked, p.path, p.why);
474
470
  case "gone":
475
471
  return projectFileGoneText(asked, p.path);
476
472
  case "read_failed":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/kernel",
3
- "version": "0.1.0-rc.76",
3
+ "version": "0.1.0-rc.77",
4
4
  "description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -66,7 +66,7 @@
66
66
  "yaml": "^2.9.1",
67
67
  "yauzl": "3.4.0",
68
68
  "zod": "^4.6.7",
69
- "@capybara-hq/plugin-sdk": "^0.1.0-rc.61"
69
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.62"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@langchain/langgraph-checkpoint-validation": "^1.2.0",