@tangle-network/agent-interface 5.10.31 → 5.10.32

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/README.md CHANGED
@@ -58,6 +58,24 @@ materialization receipts. The function does not load resources or estimate token
58
58
  Its coverage explicitly leaves tokenization, materialization, and observed use unassessed.
59
59
  A capability declaration is not evidence that it was delivered, opened, or applied.
60
60
 
61
+ ## Skill provenance
62
+
63
+ `mountSkill(source, content)` mounts one `SKILL.md` as an inline skill and returns the
64
+ provenance record to keep at `extensions[<profile name>].resourceProvenance`.
65
+ `mountSkillDirectory(source, files, { skillsDirectory })` mounts a whole skill directory
66
+ read at one commit: `SKILL.md` as the same inline skill, and every other file as an inline
67
+ `resources.files` mount at `<skillsDirectory>/<name>/<relative path>`, so the relative links
68
+ in `SKILL.md` resolve once the materializer writes the skill to
69
+ `<skillsDirectory>/<name>/SKILL.md`. Pass the skills directory of the harness the profile
70
+ targets; the materializer's `skillDirForHarness(harness)` owns that table. It refuses a
71
+ path that leaves the skill directory, a duplicate path and a directory without `SKILL.md`.
72
+
73
+ `verifyResourceProvenance(profile, { read })` checks every record. A skill mounted with
74
+ its directory claims the whole directory: each listed file needs a record at the skill's
75
+ commit and beside its `SKILL.md`, its exact bytes mounted at the same relative path, and
76
+ no unlisted file may be mounted in the skill's directory. Inline content is text; mount a
77
+ binary file by GitHub ref.
78
+
61
79
  ## Workspace paths
62
80
 
63
81
  `WorkspaceRequest.snapshot` restores a portable workspace through closed content-addressed manifest and archive references. It includes the source lease and policy identities, and carries no inline file bytes. The accepted request binds both artifact hashes, because the archive also identifies Git HEAD and staged state. A snapshot cannot be combined with `repoUrl`, `gitRef` or a provider-native `checkpoint`; its `cwd` uses the repository base.
@@ -325,19 +343,21 @@ The three code states are intentionally distinct:
325
343
 
326
344
  ## Versioning
327
345
 
328
- This package follows semantic versioning from 1.0.0.
346
+ This package follows semantic versioning from 1.0.0. Release admission decides the
347
+ bump: `pnpm check:package-artifacts` runs agent-runtime's `scripts/check-version-bump.mjs --archive`
348
+ on every packed archive before the release workflow publishes it, and refuses what these rules exclude.
329
349
 
330
- - A minor release is additive. A new export, a new optional field, and a new member on an exported union are minor.
331
- - A patch release is a fix. A behaviour correction that keeps every declared type is patch.
332
- - A major release removes or narrows. A deleted export, a removed member, a narrowed type, and a new required field are major.
350
+ - An additive change is a patch. A new export, a new optional field, and a new member on an exported union are patch, so write a `patch` changeset for them; admission refuses a minor over a published 1.x+ release.
351
+ - A behaviour correction that keeps every declared type is also a patch.
352
+ - A major release removes or narrows. A deleted export, a removed member, a narrowed type, and a new required field are major; admission refuses a major that names no incompatibility.
333
353
 
334
- Declare this package with a caret range, and set the floor to the lowest minor you actually use.
335
- A package that reads an export added in 1.4.0 declares `^1.4.0`, because `^1.0.0` lets a resolver keep 1.0.0.
336
- A caret range admits every later additive minor without a consumer release.
337
- Do not declare a single-generation window such as `>=1.4.0 <1.5.0`; that shape forces a coordinated release across every repository on each minor.
354
+ Declare this package with a caret range, and set the floor to the lowest release you actually use.
355
+ A package that reads an export added in 5.10.32 declares `^5.10.32`, because `^5.10.0` lets a resolver keep 5.10.0.
356
+ A caret range admits every later additive release without a consumer release.
357
+ Do not declare a single-generation window such as `>=5.10.32 <5.11.0`; that shape forces a coordinated release across every repository.
338
358
 
339
359
  Write a `default` branch in every `switch` over an exported union.
340
- An exhaustiveness check that assigns the remaining case to `never` fails when a minor adds a member, and this promise does not cover it.
360
+ An exhaustiveness check that assigns the remaining case to `never` fails when a release adds a member, and this promise does not cover it.
341
361
 
342
362
  ## License
343
363
 
@@ -6,8 +6,14 @@
6
6
  * came from and their SHA-256, so an edit to either the inline copy or the
7
7
  * source shows up as a mismatch instead of a silent change of behavior.
8
8
  * Records live at `extensions[<profile name>].resourceProvenance`.
9
+ *
10
+ * A skill is usually a directory: `SKILL.md` links sibling files such as
11
+ * `references/format.md` by relative path. `mountSkillDirectory` mounts the
12
+ * whole directory: `SKILL.md` as the skill, and every other file as a
13
+ * `resources.files` entry at the same relative path under the directory the
14
+ * harness discovers the skill in, so the links resolve after materialization.
9
15
  */
10
- import type { AgentProfile, AgentProfileResourceRef } from "./agent-profile.js";
16
+ import type { AgentProfile, AgentProfileFileMount, AgentProfileResourceRef } from "./agent-profile.js";
11
17
  /** One file at one commit. */
12
18
  export interface AgentProfileResourceSource {
13
19
  /** `owner/repo`. */
@@ -18,10 +24,25 @@ export interface AgentProfileResourceSource {
18
24
  }
19
25
  /** The record a profile keeps for one inline resource. */
20
26
  export interface AgentProfileResourceProvenance extends AgentProfileResourceSource {
21
- /** Name of the inline resource the bytes were mounted as. */
27
+ /**
28
+ * Name of the inline resource the bytes were mounted as. For a file of a
29
+ * skill directory it is `<skill>/<path relative to the skill directory>`.
30
+ */
22
31
  name: string;
23
32
  /** Lowercase hex SHA-256 of the content's UTF-8 bytes. */
24
33
  sha256: string;
34
+ /**
35
+ * Set on a skill mounted with its directory: the workspace directory its
36
+ * other files are mounted in, `<skillsDirectory>/<skill name>`.
37
+ */
38
+ mountedAt?: string;
39
+ /**
40
+ * Set with `mountedAt`: every other file of the skill directory, relative to
41
+ * it and sorted. `[]` claims `SKILL.md` is the whole directory.
42
+ */
43
+ siblings?: string[];
44
+ /** Set on a file of a skill directory: the name of the skill it belongs to. */
45
+ skill?: string;
25
46
  }
26
47
  export type AgentProfileInlineResource = Extract<AgentProfileResourceRef, {
27
48
  kind: "inline";
@@ -35,6 +56,51 @@ export declare function mountSkill(source: AgentProfileResourceSource & {
35
56
  skill: AgentProfileInlineResource;
36
57
  provenance: AgentProfileResourceProvenance;
37
58
  };
59
+ /** A skill directory at one commit. */
60
+ export interface AgentProfileSkillDirectorySource {
61
+ /** `owner/repo`. */
62
+ repository: string;
63
+ /** Full commit SHA every file was read at. */
64
+ ref: string;
65
+ /** The skill directory in the repository, such as `skills/release-notes`; `""` is the repository root. */
66
+ directory: string;
67
+ /** The skill's name. It is one path segment: the materializer mounts `SKILL.md` at `<skills directory>/<name>/SKILL.md`. */
68
+ name: string;
69
+ }
70
+ /** One file of a skill directory, with its path relative to that directory. */
71
+ export interface AgentProfileSkillFile {
72
+ /** `SKILL.md`, or a sibling such as `references/format.md`. */
73
+ path: string;
74
+ /** The file's exact text at the commit. Binary files have no lossless inline form; mount them by GitHub ref. */
75
+ content: string;
76
+ /** Mount the file executable, as Git mode 100755 records it. A skill's `SKILL.md` has no mode. */
77
+ executable?: boolean;
78
+ }
79
+ export interface MountSkillDirectoryOptions {
80
+ /**
81
+ * The workspace directory the profile's harness discovers skills in, such as
82
+ * `.claude/skills`. The materializer mounts an inline skill at
83
+ * `<this>/<name>/SKILL.md` for the harness it targets, so siblings must be
84
+ * mounted under the same directory for relative links to resolve.
85
+ */
86
+ skillsDirectory: string;
87
+ }
88
+ export interface MountedSkillDirectory {
89
+ /** `SKILL.md` as an inline skill, exactly as `mountSkill` returns it. */
90
+ skill: AgentProfileInlineResource;
91
+ /** Every other file, sorted by path, mounted at `<skillsDirectory>/<name>/<path>` as an inline resource named `<name>/<path>`. */
92
+ files: AgentProfileFileMount[];
93
+ /** The skill's record, carrying `mountedAt` and `siblings`, then one record per file in `files` order. */
94
+ provenance: AgentProfileResourceProvenance[];
95
+ }
96
+ /**
97
+ * Mount a skill directory read at one commit: `SKILL.md` as an inline skill
98
+ * and every other file as an inline `resources.files` mount beside it, with a
99
+ * provenance record for each file. Throws on a ref that is not a full commit
100
+ * SHA, a path that leaves the skill directory, a duplicate path, or a
101
+ * directory without `SKILL.md`.
102
+ */
103
+ export declare function mountSkillDirectory(source: AgentProfileSkillDirectorySource, files: readonly AgentProfileSkillFile[], options: MountSkillDirectoryOptions): MountedSkillDirectory;
38
104
  /**
39
105
  * Every reason a profile's provenance records do not hold; empty when they do.
40
106
  *
@@ -42,6 +108,11 @@ export declare function mountSkill(source: AgentProfileResourceSource & {
42
108
  * hash to it. Inline resources without a record are not checked: a record is
43
109
  * the producer's claim, and only claims are verified. With `read`, the source file at that commit must hash to it too,
44
110
  * which catches a record that was rewritten together with the inline copy.
111
+ *
112
+ * A skill mounted with its directory claims the whole directory: each file it
113
+ * lists must have a record at the skill's commit and source directory, the
114
+ * same relative path inside the skill, and exact inline bytes mounted at
115
+ * `<mountedAt>/<path>`; no other file may be mounted inside `mountedAt`.
45
116
  */
46
117
  export declare function verifyResourceProvenance(profile: AgentProfile, options?: {
47
118
  namespace?: string;
@@ -6,8 +6,14 @@
6
6
  * came from and their SHA-256, so an edit to either the inline copy or the
7
7
  * source shows up as a mismatch instead of a silent change of behavior.
8
8
  * Records live at `extensions[<profile name>].resourceProvenance`.
9
+ *
10
+ * A skill is usually a directory: `SKILL.md` links sibling files such as
11
+ * `references/format.md` by relative path. `mountSkillDirectory` mounts the
12
+ * whole directory: `SKILL.md` as the skill, and every other file as a
13
+ * `resources.files` entry at the same relative path under the directory the
14
+ * harness discovers the skill in, so the links resolve after materialization.
9
15
  */
10
- import { gitObjectSchema, sha256Utf8 } from "./agent-candidate-schema-common.js";
16
+ import { gitObjectSchema, isSafeRelativePath, sha256Utf8, } from "./agent-candidate-schema-common.js";
11
17
  /** Mount `content` as an inline skill and return the provenance record to keep beside it. */
12
18
  export function mountSkill(source, content) {
13
19
  if (!gitObjectSchema.safeParse(source.ref).success) {
@@ -24,6 +30,70 @@ export function mountSkill(source, content) {
24
30
  },
25
31
  };
26
32
  }
33
+ /**
34
+ * Mount a skill directory read at one commit: `SKILL.md` as an inline skill
35
+ * and every other file as an inline `resources.files` mount beside it, with a
36
+ * provenance record for each file. Throws on a ref that is not a full commit
37
+ * SHA, a path that leaves the skill directory, a duplicate path, or a
38
+ * directory without `SKILL.md`.
39
+ */
40
+ export function mountSkillDirectory(source, files, options) {
41
+ const at = `mountSkillDirectory ${JSON.stringify(source.name)}`;
42
+ if (!isSafeRelativePath(source.name, false) || source.name.includes("/")) {
43
+ throw new Error(`${at}: the skill name must be one path segment`);
44
+ }
45
+ if (source.directory !== "" && !isSafeRelativePath(source.directory, false)) {
46
+ throw new Error(`${at}: directory ${JSON.stringify(source.directory)} is not a repository path`);
47
+ }
48
+ if (!isSafeRelativePath(options.skillsDirectory, false)) {
49
+ throw new Error(`${at}: skillsDirectory ${JSON.stringify(options.skillsDirectory)} is not a workspace path`);
50
+ }
51
+ let skillFile;
52
+ const siblings = [];
53
+ const seen = new Set();
54
+ for (const file of files) {
55
+ if (!isSafeRelativePath(file.path, false)) {
56
+ throw new Error(`${at}: ${JSON.stringify(file.path)} is not a path inside the skill directory`);
57
+ }
58
+ if (seen.has(file.path))
59
+ throw new Error(`${at}: ${file.path} is listed twice`);
60
+ seen.add(file.path);
61
+ if (file.path !== SKILL_FILE) {
62
+ siblings.push(file);
63
+ }
64
+ else if (file.executable === true) {
65
+ throw new Error(`${at}: ${SKILL_FILE} mounts as a skill, which cannot be executable`);
66
+ }
67
+ else {
68
+ skillFile = file;
69
+ }
70
+ }
71
+ if (skillFile === undefined)
72
+ throw new Error(`${at}: the skill directory has no ${SKILL_FILE}`);
73
+ siblings.sort((left, right) => compare(left.path, right.path));
74
+ const sourcePath = (relative) => source.directory === "" ? relative : `${source.directory}/${relative}`;
75
+ const mountedAt = `${options.skillsDirectory}/${source.name}`;
76
+ const { skill, provenance } = mountSkill({ repository: source.repository, ref: source.ref, path: sourcePath(SKILL_FILE), name: source.name }, skillFile.content);
77
+ return {
78
+ skill,
79
+ files: siblings.map((file) => ({
80
+ path: `${mountedAt}/${file.path}`,
81
+ resource: { kind: "inline", name: `${source.name}/${file.path}`, content: file.content },
82
+ ...(file.executable === true ? { executable: true } : {}),
83
+ })),
84
+ provenance: [
85
+ { ...provenance, mountedAt, siblings: siblings.map((file) => file.path) },
86
+ ...siblings.map((file) => ({
87
+ name: `${source.name}/${file.path}`,
88
+ repository: source.repository,
89
+ ref: source.ref,
90
+ path: sourcePath(file.path),
91
+ sha256: contentSha256(file.content),
92
+ skill: source.name,
93
+ })),
94
+ ],
95
+ };
96
+ }
27
97
  /**
28
98
  * Every reason a profile's provenance records do not hold; empty when they do.
29
99
  *
@@ -31,6 +101,11 @@ export function mountSkill(source, content) {
31
101
  * hash to it. Inline resources without a record are not checked: a record is
32
102
  * the producer's claim, and only claims are verified. With `read`, the source file at that commit must hash to it too,
33
103
  * which catches a record that was rewritten together with the inline copy.
104
+ *
105
+ * A skill mounted with its directory claims the whole directory: each file it
106
+ * lists must have a record at the skill's commit and source directory, the
107
+ * same relative path inside the skill, and exact inline bytes mounted at
108
+ * `<mountedAt>/<path>`; no other file may be mounted inside `mountedAt`.
34
109
  */
35
110
  export async function verifyResourceProvenance(profile, options = {}) {
36
111
  const namespace = options.namespace ?? profile.name;
@@ -43,23 +118,28 @@ export async function verifyResourceProvenance(profile, options = {}) {
43
118
  return [`extensions.${namespace}.resourceProvenance must be an array`];
44
119
  const inline = inlineResourcesByName(profile);
45
120
  const problems = [];
121
+ const checked = [];
46
122
  for (const [index, record] of records.entries()) {
47
123
  const at = `extensions.${namespace}.resourceProvenance[${index}]`;
48
124
  if (!isProvenanceRecord(record)) {
49
- problems.push(`${at}: needs string name, repository, ref, path and a 64-hex sha256`);
125
+ problems.push(`${at}: needs string name, repository, ref, path and a 64-hex sha256; mountedAt with a siblings string array, or skill, when present`);
50
126
  continue;
51
127
  }
128
+ checked.push({ at, record });
52
129
  if (!gitObjectSchema.safeParse(record.ref).success) {
53
130
  problems.push(`${at} (${record.name}): ref "${record.ref}" is not a full commit SHA`);
54
131
  }
55
- const mounted = inline.get(record.name) ?? [];
56
- if (mounted.length === 0) {
57
- problems.push(`${at} (${record.name}): no inline resource has this name`);
58
- }
59
- for (const content of mounted) {
60
- const actual = contentSha256(content);
61
- if (actual !== record.sha256) {
62
- problems.push(`${at} (${record.name}): inline bytes hash to ${actual}, record says ${record.sha256}`);
132
+ // A skill directory's file is checked where it is mounted, below.
133
+ if (record.skill === undefined) {
134
+ const mounted = inline.get(record.name) ?? [];
135
+ if (mounted.length === 0) {
136
+ problems.push(`${at} (${record.name}): no inline resource has this name`);
137
+ }
138
+ for (const content of mounted) {
139
+ const actual = contentSha256(content);
140
+ if (actual !== record.sha256) {
141
+ problems.push(`${at} (${record.name}): inline bytes hash to ${actual}, record says ${record.sha256}`);
142
+ }
63
143
  }
64
144
  }
65
145
  if (options.read !== undefined) {
@@ -77,8 +157,103 @@ export async function verifyResourceProvenance(profile, options = {}) {
77
157
  }
78
158
  }
79
159
  }
160
+ problems.push(...skillDirectoryProblems(checked, profile.resources?.files ?? []));
80
161
  return problems;
81
162
  }
163
+ const SKILL_FILE = "SKILL.md";
164
+ /** The checks a skill mounted with its directory adds: every listed file, and only those, mounted beside it. */
165
+ function skillDirectoryProblems(checked, files) {
166
+ const problems = [];
167
+ const skills = new Map();
168
+ for (const { at, record } of checked) {
169
+ if (record.mountedAt === undefined || record.siblings === undefined)
170
+ continue;
171
+ const directoryRecord = record;
172
+ if (skills.has(record.name)) {
173
+ problems.push(`${at} (${record.name}): another record already mounts this skill's directory`);
174
+ continue;
175
+ }
176
+ skills.set(record.name, { at, record: directoryRecord });
177
+ }
178
+ const recorded = new Set();
179
+ for (const { at, record } of checked) {
180
+ if (record.skill === undefined)
181
+ continue;
182
+ const owner = skills.get(record.skill);
183
+ if (owner === undefined) {
184
+ problems.push(`${at} (${record.name}): skill "${record.skill}" has no record that mounts its directory`);
185
+ continue;
186
+ }
187
+ const skill = owner.record;
188
+ const prefix = `${record.skill}/`;
189
+ const relative = record.name.startsWith(prefix) ? record.name.slice(prefix.length) : undefined;
190
+ if (relative === undefined || !isSafeRelativePath(relative, false) || relative === SKILL_FILE) {
191
+ problems.push(`${at} (${record.name}): the name is not a file inside the directory of skill "${record.skill}"`);
192
+ continue;
193
+ }
194
+ recorded.add(record.name);
195
+ if (!skill.siblings.includes(relative)) {
196
+ problems.push(`${at} (${record.name}): skill "${record.skill}" does not list ${relative} among its files`);
197
+ }
198
+ if (record.repository !== skill.repository || record.ref !== skill.ref) {
199
+ problems.push(`${at} (${record.name}): read from ${record.repository}@${record.ref}, but the skill is at ${skill.repository}@${skill.ref}`);
200
+ }
201
+ const directory = sourceDirectory(skill.path);
202
+ const expected = directory === "" ? relative : `${directory}/${relative}`;
203
+ if (record.path !== expected) {
204
+ problems.push(`${at} (${record.name}): source ${record.path} is not ${expected}, beside the skill's ${SKILL_FILE}`);
205
+ }
206
+ const mountPath = `${skill.mountedAt}/${relative}`;
207
+ const mounted = files.filter((file) => file.path === mountPath);
208
+ if (mounted.length === 0)
209
+ problems.push(`${at} (${record.name}): nothing is mounted at ${mountPath}`);
210
+ for (const file of mounted) {
211
+ if (file.resource.kind !== "inline") {
212
+ problems.push(`${at} (${record.name}): ${mountPath} is not an inline resource`);
213
+ continue;
214
+ }
215
+ const actual = contentSha256(file.resource.content);
216
+ if (actual !== record.sha256) {
217
+ problems.push(`${at} (${record.name}): bytes mounted at ${mountPath} hash to ${actual}, record says ${record.sha256}`);
218
+ }
219
+ }
220
+ }
221
+ for (const { at, record } of skills.values()) {
222
+ const name = record.name;
223
+ if (record.path !== SKILL_FILE && !record.path.endsWith(`/${SKILL_FILE}`)) {
224
+ problems.push(`${at} (${name}): a skill mounted with its directory is read from a ${SKILL_FILE}, not ${record.path}`);
225
+ }
226
+ if (!isSafeRelativePath(record.mountedAt, false) || !record.mountedAt.endsWith(`/${name}`)) {
227
+ problems.push(`${at} (${name}): mountedAt "${record.mountedAt}" is not a workspace directory named for the skill`);
228
+ continue;
229
+ }
230
+ const listed = new Set();
231
+ for (const relative of record.siblings) {
232
+ if (!isSafeRelativePath(relative, false) || relative === SKILL_FILE || listed.has(relative)) {
233
+ problems.push(`${at} (${name}): lists ${JSON.stringify(relative)}, which is not a distinct file inside its directory`);
234
+ continue;
235
+ }
236
+ listed.add(relative);
237
+ if (!recorded.has(`${name}/${relative}`)) {
238
+ problems.push(`${at} (${name}): lists ${relative}, but no record covers ${name}/${relative}`);
239
+ }
240
+ }
241
+ const inside = `${record.mountedAt}/`;
242
+ for (const file of files) {
243
+ if (file.path.startsWith(inside) && !listed.has(file.path.slice(inside.length))) {
244
+ problems.push(`${at} (${name}): ${file.path} is mounted in the skill's directory, but the skill does not list it`);
245
+ }
246
+ }
247
+ }
248
+ return problems;
249
+ }
250
+ function sourceDirectory(path) {
251
+ const slash = path.lastIndexOf("/");
252
+ return slash < 0 ? "" : path.slice(0, slash);
253
+ }
254
+ function compare(left, right) {
255
+ return left < right ? -1 : left > right ? 1 : 0;
256
+ }
82
257
  function contentSha256(content) {
83
258
  return sha256Utf8(content).slice("sha256:".length);
84
259
  }
@@ -86,9 +261,20 @@ function isProvenanceRecord(value) {
86
261
  if (value === null || typeof value !== "object")
87
262
  return false;
88
263
  const record = value;
264
+ const { mountedAt, siblings, skill } = record;
265
+ const directory = mountedAt === undefined && siblings === undefined
266
+ ? true
267
+ : typeof mountedAt === "string" &&
268
+ Array.isArray(siblings) &&
269
+ siblings.every((sibling) => typeof sibling === "string");
270
+ const member = skill === undefined || (typeof skill === "string" && skill !== "");
89
271
  return (["name", "repository", "ref", "path"].every((key) => typeof record[key] === "string" && record[key] !== "") &&
90
272
  typeof record.sha256 === "string" &&
91
- /^[a-f0-9]{64}$/.test(record.sha256));
273
+ /^[a-f0-9]{64}$/.test(record.sha256) &&
274
+ directory &&
275
+ member &&
276
+ // A file of a skill directory is not itself a skill directory.
277
+ !(skill !== undefined && mountedAt !== undefined));
92
278
  }
93
279
  /**
94
280
  * Inline contents by name. A record names a resource but not its kind, and
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-interface",
3
- "version": "5.10.31",
3
+ "version": "5.10.32",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "license": "MIT",