@capybara-hq/kernel 0.1.0-rc.83 → 0.1.0-rc.84

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.
@@ -119,6 +119,14 @@ export type ReadGitTreeOptions = GitOptions & {
119
119
  */
120
120
  include?: (path: string, type: "tree" | "blob") => boolean;
121
121
  };
122
+ /**
123
+ * The git tree oid of a directory holding exactly `files` (paths relative to it, `/`-separated) as
124
+ * regular files of mode 100644: git's own blob and tree hashing, so it is the oid
125
+ * {@link readGitTreeAndOids} gives that directory when none of its files is executable (symlinks and
126
+ * submodules are refused there). For files known without reading git, e.g. the verified offline
127
+ * pack of a bootstrap git entry; an executable file in the repository only makes the oids differ.
128
+ */
129
+ export declare function gitTreeOidOf(files: ReadonlyMap<string, Uint8Array>): string;
122
130
  /**
123
131
  * {@link readGitTree}, plus the git tree oids of directories at the same commit: `trees` gets the
124
132
  * files read and returns directory paths relative to the repository root (`.` is the root); each
@@ -1,3 +1,4 @@
1
+ import { createHash } from "node:crypto";
1
2
  import * as fsp from "node:fs/promises";
2
3
  import { tmpdir } from "node:os";
3
4
  import { join } from "node:path";
@@ -377,6 +378,39 @@ function pathSegments(path) {
377
378
  export async function readGitTree(loc, o) {
378
379
  return (await readGitTreeAndOids(loc, o)).files;
379
380
  }
381
+ /**
382
+ * The git tree oid of a directory holding exactly `files` (paths relative to it, `/`-separated) as
383
+ * regular files of mode 100644: git's own blob and tree hashing, so it is the oid
384
+ * {@link readGitTreeAndOids} gives that directory when none of its files is executable (symlinks and
385
+ * submodules are refused there). For files known without reading git, e.g. the verified offline
386
+ * pack of a bootstrap git entry; an executable file in the repository only makes the oids differ.
387
+ */
388
+ export function gitTreeOidOf(files) {
389
+ const root = new Map();
390
+ for (const [path, data] of files) {
391
+ const segs = path.split("/");
392
+ let dir = root;
393
+ for (const seg of segs.slice(0, -1)) {
394
+ let sub = dir.get(seg);
395
+ if (!(sub instanceof Map)) {
396
+ sub = new Map();
397
+ dir.set(seg, sub);
398
+ }
399
+ dir = sub;
400
+ }
401
+ dir.set(segs[segs.length - 1], data);
402
+ }
403
+ const hash = (type, body) => createHash("sha1").update(`${type} ${body.byteLength}\0`).update(body).digest();
404
+ const tree = (dir) => {
405
+ // git orders entries by their bytes, a directory as if its name ended in "/"
406
+ const entries = [...dir].map(([name, v]) => v instanceof Map
407
+ ? { key: Buffer.from(`${name}/`), head: `40000 ${name}\0`, oid: tree(v) }
408
+ : { key: Buffer.from(name), head: `100644 ${name}\0`, oid: hash("blob", v) });
409
+ entries.sort((a, b) => Buffer.compare(a.key, b.key));
410
+ return hash("tree", Buffer.concat(entries.flatMap((e) => [Buffer.from(e.head), e.oid])));
411
+ };
412
+ return tree(root).toString("hex");
413
+ }
380
414
  /**
381
415
  * {@link readGitTree}, plus the git tree oids of directories at the same commit: `trees` gets the
382
416
  * files read and returns directory paths relative to the repository root (`.` is the root); each
@@ -208,7 +208,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
208
208
  /** The host versions (an entry's `minKernel` is judged against them). */
209
209
  export declare const HOST_VERSIONS: {
210
210
  readonly kernel: string;
211
- readonly sdk: "0.1.0-rc.68";
211
+ readonly sdk: "0.1.0-rc.69";
212
212
  };
213
213
  /** Whether this deployment satisfies the entry's `minKernel`. */
214
214
  export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
@@ -13,6 +13,7 @@ import { Inject, Injectable, Optional } from "@nestjs/common";
13
13
  import { sql } from "kysely";
14
14
  import semver from "semver";
15
15
  import { marketplaceGitSource, repoOwner } from "../catalog/catalog.service.js";
16
+ import { gitTreeOidOf } from "../catalog/git-source.js";
16
17
  import { CONFIG_MARKETPLACE_PREFIX } from "../catalog/marketplaces.service.js";
17
18
  import { otherNameOwner } from "../catalog/ownership.js";
18
19
  import { catalogPackageError, } from "../catalog/plugin-import.js";
@@ -391,7 +392,10 @@ let BootstrapService = class BootstrapService {
391
392
  commit: e.commit,
392
393
  path: e.path,
393
394
  ...(m.ref !== undefined && { ref: m.ref }),
394
- }, { commit: e.commit, tree: at.tree }, false);
395
+ },
396
+ // From the offline directory git was not read: the verified pack holds exactly the tree's
397
+ // files, so their oid is the tree's (a later commit elsewhere is then no content change)
398
+ { commit: e.commit, tree: at.tree ?? gitTreeOidOf(git.files) }, false);
395
399
  const marketplaceId = managedMarketplaceId(m.name);
396
400
  // The managed row is created by the kernel start before its bootstrap step; `capybara
397
401
  // bootstrap` may run before any start, when the item cannot name it yet (a foreign key).
@@ -23,24 +23,9 @@ const canonical = (v) => {
23
23
  }
24
24
  return JSON.stringify(v) ?? "null";
25
25
  };
26
- /**
27
- * A reviewed static manifest without the `config.org` list that packages packed before core#720
28
- * carry (stored install records and catalog sections keep it as reviewed). The list is dropped, not
29
- * compared: the SDK no longer has org-only config, and `defineExtension` drops the module's own
30
- * `config.org` the same way. Removed with the other pre-core#720 readers once the official plugins are
31
- * republished and re-pinned (core#720 plan Task 17).
32
- */
33
- function withoutLegacyOrgConfig(section) {
34
- const config = section.config;
35
- if (config === undefined || !("org" in config))
36
- return section;
37
- const { org: _legacyOrg, ...rest } = config;
38
- return { ...section, config: rest };
39
- }
40
26
  /** Whether a module's manifest matches the reviewed static manifest (same name and {@link staticManifestOf}). */
41
27
  export function matchesSection(manifest, name, section) {
42
- return (manifest.name === name &&
43
- canonical(staticManifestOf(manifest)) === canonical(withoutLegacyOrgConfig(section)));
28
+ return manifest.name === name && canonical(staticManifestOf(manifest)) === canonical(section);
44
29
  }
45
30
  /** 导入一个插件模块(default 导出)并按 defineExtension 校验清单。 */
46
31
  export async function importExtensionModule(url, label, resolveFrom) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/kernel",
3
- "version": "0.1.0-rc.83",
3
+ "version": "0.1.0-rc.84",
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.68"
69
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.69"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@langchain/langgraph-checkpoint-validation": "^1.2.0",