@agentropy/runtime 0.0.0-stage → 0.1.0

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.
Files changed (85) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +39 -2
  3. package/dist/a2a-client.d.ts +111 -0
  4. package/dist/a2a-client.js +386 -0
  5. package/dist/a2a-history.d.ts +27 -0
  6. package/dist/a2a-history.js +67 -0
  7. package/dist/a2a-http.d.ts +46 -0
  8. package/dist/a2a-http.js +183 -0
  9. package/dist/a2a-protocol.d.ts +77 -0
  10. package/dist/a2a-protocol.js +148 -0
  11. package/dist/a2a-push-receiver.d.ts +24 -0
  12. package/dist/a2a-push-receiver.js +161 -0
  13. package/dist/a2a-push.d.ts +85 -0
  14. package/dist/a2a-push.js +385 -0
  15. package/dist/a2a-server.d.ts +82 -0
  16. package/dist/a2a-server.js +523 -0
  17. package/dist/a2a-sse.d.ts +5 -0
  18. package/dist/a2a-sse.js +36 -0
  19. package/dist/a2a.d.ts +41 -0
  20. package/dist/a2a.js +40 -0
  21. package/dist/app.d.ts +256 -0
  22. package/dist/app.js +541 -0
  23. package/dist/audit.d.ts +229 -0
  24. package/dist/audit.js +718 -0
  25. package/dist/bounded-body.d.ts +32 -0
  26. package/dist/bounded-body.js +124 -0
  27. package/dist/communication.d.ts +62 -0
  28. package/dist/communication.js +142 -0
  29. package/dist/compaction.d.ts +24 -0
  30. package/dist/compaction.js +202 -0
  31. package/dist/federation.d.ts +108 -0
  32. package/dist/federation.js +241 -0
  33. package/dist/http-path.d.ts +7 -0
  34. package/dist/http-path.js +14 -0
  35. package/dist/human-actions.d.ts +62 -0
  36. package/dist/human-actions.js +359 -0
  37. package/dist/implementation.d.ts +47 -0
  38. package/dist/implementation.js +138 -0
  39. package/dist/inbox.d.ts +101 -0
  40. package/dist/inbox.js +389 -0
  41. package/dist/index.d.ts +32 -0
  42. package/dist/index.js +32 -0
  43. package/dist/ingress.d.ts +35 -0
  44. package/dist/ingress.js +86 -0
  45. package/dist/lifecycle.d.ts +45 -0
  46. package/dist/lifecycle.js +57 -0
  47. package/dist/limits.d.ts +43 -0
  48. package/dist/limits.js +71 -0
  49. package/dist/mcp.d.ts +111 -0
  50. package/dist/mcp.js +308 -0
  51. package/dist/memory.d.ts +25 -0
  52. package/dist/memory.js +134 -0
  53. package/dist/model-routing.d.ts +66 -0
  54. package/dist/model-routing.js +80 -0
  55. package/dist/otel.d.ts +60 -0
  56. package/dist/otel.js +72 -0
  57. package/dist/outbox.d.ts +116 -0
  58. package/dist/outbox.js +327 -0
  59. package/dist/policy-cache.d.ts +69 -0
  60. package/dist/policy-cache.js +178 -0
  61. package/dist/priority.d.ts +27 -0
  62. package/dist/priority.js +28 -0
  63. package/dist/quotas.d.ts +19 -0
  64. package/dist/quotas.js +47 -0
  65. package/dist/reasoning.d.ts +54 -0
  66. package/dist/reasoning.js +307 -0
  67. package/dist/registry.d.ts +101 -0
  68. package/dist/registry.js +369 -0
  69. package/dist/remote.d.ts +130 -0
  70. package/dist/remote.js +473 -0
  71. package/dist/runtime.d.ts +167 -0
  72. package/dist/runtime.js +1035 -0
  73. package/dist/skills.d.ts +86 -0
  74. package/dist/skills.js +376 -0
  75. package/dist/task-service.d.ts +239 -0
  76. package/dist/task-service.js +790 -0
  77. package/dist/tools.d.ts +140 -0
  78. package/dist/tools.js +476 -0
  79. package/dist/wake-index.d.ts +9 -0
  80. package/dist/wake-index.js +11 -0
  81. package/dist/wakeups.d.ts +142 -0
  82. package/dist/wakeups.js +501 -0
  83. package/dist/workflow.d.ts +36 -0
  84. package/dist/workflow.js +101 -0
  85. package/package.json +48 -3
@@ -0,0 +1,86 @@
1
+ import { type SkillAccess, type SkillLoader, type SkillMetadata, type SkillPin, type SkillRecord, type SkillRequirements, type Store, type TrustedPrincipal, type VersionedRef } from '@agentropy/core';
2
+ import { type SecurityServices } from './tools.js';
3
+ /** Parse SKILL.md into standard metadata and the Markdown body. Unknown frontmatter keys are ignored. */
4
+ export declare function parseSkillMd(text: string): {
5
+ metadata: SkillMetadata;
6
+ body: string;
7
+ };
8
+ /** sha256 over every relative path and file content, in sorted order. */
9
+ export declare function digestSkillDirectory(root: string): Promise<{
10
+ digest: string;
11
+ files: string[];
12
+ }>;
13
+ export interface SkillRegistration {
14
+ id?: string;
15
+ version: string;
16
+ requires?: SkillRequirements;
17
+ publisher: string;
18
+ }
19
+ export declare class InMemorySkillRegistry {
20
+ private readonly security;
21
+ private readonly verify;
22
+ /**
23
+ * With a `store`, activation and revocation are kept there (FEAT-074): another worker refuses a revoked skill at
24
+ * once, and `register` after a restart adopts the stored status; `revoked` is final.
25
+ */
26
+ private readonly options;
27
+ private readonly entries;
28
+ constructor(security: SecurityServices, verify: (metadata: SkillMetadata, publisher: string) => boolean,
29
+ /**
30
+ * With a `store`, activation and revocation are kept there (FEAT-074): another worker refuses a revoked skill at
31
+ * once, and `register` after a restart adopts the stored status; `revoked` is final.
32
+ */
33
+ options?: {
34
+ store?: Store;
35
+ });
36
+ private guard;
37
+ /** Register a skill directory in the standard format, without converting or rewriting it. */
38
+ register(directory: string, opts: SkillRegistration, admin: TrustedPrincipal): Promise<SkillRecord>;
39
+ /** The record with the status the store has (this process's own when it has no store). */
40
+ refreshed(ref: VersionedRef): Promise<SkillRecord | undefined>;
41
+ activate(ref: VersionedRef, admin: TrustedPrincipal): Promise<SkillRecord>;
42
+ revoke(ref: VersionedRef, admin: TrustedPrincipal): Promise<SkillRecord>;
43
+ get(ref: VersionedRef): SkillRecord | undefined;
44
+ /**
45
+ * Every version of a skill with this process's own status, which only moves when this process acts on it or calls
46
+ * `refreshed`. What must agree with other workers on the store (task acceptance) uses `refreshedVersions`.
47
+ */
48
+ versions(id: string): SkillRecord[];
49
+ /**
50
+ * Every version of a skill with the status the store has (FIX-084): an activation or revoke on another worker
51
+ * counts. Task acceptance resolves against this. Without a store it answers as `versions` does.
52
+ */
53
+ refreshedVersions(id: string): Promise<SkillRecord[]>;
54
+ /** Metadata-first discovery: never reads instructions or resources. */
55
+ discover(query: {
56
+ text?: string;
57
+ }, caller: TrustedPrincipal): Promise<Pick<SkillRecord, 'id' | 'version' | 'metadata'>[]>;
58
+ /** Internal: root directory of a pinned, non-revoked skill. */
59
+ rootFor(pin: SkillPin): Promise<{
60
+ record: SkillRecord;
61
+ root: string;
62
+ }>;
63
+ private require;
64
+ }
65
+ /** Filesystem loader with content verification on every load (progressive disclosure: metadata → body → resources). */
66
+ export declare class FileSystemSkillLoader implements SkillLoader {
67
+ private readonly registry;
68
+ constructor(registry: InMemorySkillRegistry);
69
+ metadata(pin: SkillPin): Promise<SkillMetadata>;
70
+ instructions(pin: SkillPin): Promise<string>;
71
+ resource(pin: SkillPin, relativePath: string): Promise<Uint8Array>;
72
+ private verified;
73
+ }
74
+ /** AgentContext.skills: read-only access to a task's pinned skills; grants nothing and executes nothing. */
75
+ export declare class PinnedSkillAccess implements SkillAccess {
76
+ private readonly loader;
77
+ private readonly registry;
78
+ private readonly pins;
79
+ constructor(loader: FileSystemSkillLoader, registry: InMemorySkillRegistry, pins: readonly SkillPin[]);
80
+ list(): SkillMetadata[];
81
+ instructions(skillId: string): Promise<string>;
82
+ resource(skillId: string, relativePath: string): Promise<Uint8Array>;
83
+ /** Script execution is outside Skill v1. */
84
+ executeScript(skillId: string, relativePath: string): Promise<never>;
85
+ private pin;
86
+ }
package/dist/skills.js ADDED
@@ -0,0 +1,376 @@
1
+ /** Skill v1: registry, filesystem source, progressive-disclosure loader and handler access. Never executes scripts. */
2
+ import { createHash } from 'node:crypto';
3
+ import { lstat, readFile, readdir, realpath, stat } from 'node:fs/promises';
4
+ import { basename, isAbsolute, join, normalize, relative, sep, } from 'node:path';
5
+ import { AGENT_SKILLS_SPEC_VERSION, AgentropyError, enforcePolicy, validateSkillMetadata, } from '@agentropy/core';
6
+ import { conflicts, effectiveStatus, lifecycleKey, moveLifecycle, readLifecycle, readLifecycles, } from './lifecycle.js';
7
+ import semver from 'semver';
8
+ import { parse as parseYaml } from 'yaml';
9
+ import { recordAudit } from './tools.js';
10
+ /** Bounds of a registered skill folder (it is hashed and read whole on every load). */
11
+ const MAX_SKILL_FILES = 500;
12
+ const MAX_SKILL_BYTES = 16 * 1024 * 1024;
13
+ const FRONTMATTER = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/;
14
+ const SPEC_KEYS = [
15
+ 'name',
16
+ 'description',
17
+ 'license',
18
+ 'compatibility',
19
+ 'metadata',
20
+ ];
21
+ /** Parse SKILL.md into standard metadata and the Markdown body. Unknown frontmatter keys are ignored. */
22
+ export function parseSkillMd(text) {
23
+ const m = FRONTMATTER.exec(text);
24
+ if (!m)
25
+ throw new AgentropyError('SchemaViolation', 'SKILL.md must start with YAML frontmatter', { details: { what: 'SKILL.md', reason: 'frontmatter' } });
26
+ let raw;
27
+ try {
28
+ raw = parseYaml(m[1]);
29
+ }
30
+ catch {
31
+ throw new AgentropyError('SchemaViolation', 'SKILL.md frontmatter is not valid YAML', { details: { what: 'SKILL.md', reason: 'yaml' } });
32
+ }
33
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw))
34
+ throw new AgentropyError('SchemaViolation', 'SKILL.md frontmatter must be a mapping', { details: { what: 'SKILL.md' } });
35
+ const fm = raw;
36
+ const candidate = {};
37
+ for (const k of SPEC_KEYS)
38
+ if (fm[k] !== undefined)
39
+ candidate[k] = fm[k];
40
+ const allowed = fm['allowed-tools'];
41
+ if (allowed !== undefined)
42
+ candidate.allowedTools =
43
+ typeof allowed === 'string'
44
+ ? allowed.split(/\s+/).filter(Boolean)
45
+ : allowed;
46
+ return {
47
+ metadata: validateSkillMetadata(candidate),
48
+ body: text.slice(m[0].length),
49
+ };
50
+ }
51
+ /** Lists files (sorted, POSIX-style relative paths). Symlinks are refused: they can escape the skill root. */
52
+ async function listFiles(root, dir = root) {
53
+ const out = [];
54
+ for (const entry of await readdir(dir, { withFileTypes: true })) {
55
+ const full = join(dir, entry.name);
56
+ if (entry.isSymbolicLink())
57
+ throw new AgentropyError('PermissionDenied', 'Skills may not contain symbolic links', { details: { reason: 'path' } });
58
+ if (entry.isDirectory())
59
+ out.push(...(await listFiles(root, full)));
60
+ else if (entry.isFile())
61
+ out.push(relative(root, full).split(sep).join('/'));
62
+ }
63
+ return out.sort((a, b) => a === 'SKILL.md' ? -1 : b === 'SKILL.md' ? 1 : a.localeCompare(b));
64
+ }
65
+ /** sha256 over every relative path and file content, in sorted order. */
66
+ export async function digestSkillDirectory(root) {
67
+ const files = await listFiles(root);
68
+ const hash = createHash('sha256');
69
+ for (const f of files) {
70
+ hash
71
+ .update(f)
72
+ .update('\0')
73
+ .update(await readFile(join(root, f)))
74
+ .update('\0');
75
+ }
76
+ return { digest: `sha256:${hash.digest('hex')}`, files };
77
+ }
78
+ export class InMemorySkillRegistry {
79
+ security;
80
+ verify;
81
+ options;
82
+ entries = new Map();
83
+ constructor(security, verify,
84
+ /**
85
+ * With a `store`, activation and revocation are kept there (FEAT-074): another worker refuses a revoked skill at
86
+ * once, and `register` after a restart adopts the stored status; `revoked` is final.
87
+ */
88
+ options = {}) {
89
+ this.security = security;
90
+ this.verify = verify;
91
+ this.options = options;
92
+ }
93
+ async guard(admin, operation, id) {
94
+ await enforcePolicy(this.security.pdp, {
95
+ principal: admin,
96
+ action: `skill-admin:${operation}`,
97
+ resource: { type: 'skill', id, tenantId: admin.tenantId },
98
+ });
99
+ await recordAudit(this.security.audit, {
100
+ type: `skill.${operation}`,
101
+ tenantId: admin.tenantId,
102
+ principalId: admin.id,
103
+ action: `skill-admin:${operation}`,
104
+ resource: { type: 'skill', id },
105
+ decision: 'allow',
106
+ at: this.security.now(),
107
+ });
108
+ }
109
+ /** Register a skill directory in the standard format, without converting or rewriting it. */
110
+ async register(directory, opts, admin) {
111
+ if (!semver.valid(opts.version))
112
+ throw new AgentropyError('SchemaViolation', 'Skill version must be SemVer', { details: { what: 'SkillRegistration' } });
113
+ const root = await realpath(directory);
114
+ let text;
115
+ try {
116
+ text = await readFile(join(root, 'SKILL.md'), 'utf8');
117
+ }
118
+ catch {
119
+ throw new AgentropyError('SchemaViolation', 'Skill directory has no SKILL.md', { details: { what: 'SKILL.md', reason: 'missing' } });
120
+ }
121
+ const { metadata } = parseSkillMd(text);
122
+ if (metadata.name !== basename(root)) {
123
+ throw new AgentropyError('SchemaViolation', 'Skill name must match its directory name', { details: { what: 'SKILL.md', reason: 'name-directory' } });
124
+ }
125
+ const id = opts.id ?? metadata.name;
126
+ const { digest, files } = await digestSkillDirectory(root);
127
+ // A skill folder is read whole on every load: bound what a registration may bring.
128
+ if (files.length > MAX_SKILL_FILES)
129
+ throw new AgentropyError('SchemaViolation', `A skill has at most ${MAX_SKILL_FILES} files`, { details: { what: 'skill', reason: 'tooManyFiles' } });
130
+ let bytes = 0;
131
+ for (const f of files)
132
+ bytes += (await stat(join(root, f))).size;
133
+ if (bytes > MAX_SKILL_BYTES)
134
+ throw new AgentropyError('SchemaViolation', `A skill is at most ${MAX_SKILL_BYTES} bytes`, { details: { what: 'skill', reason: 'tooLarge', size: bytes } });
135
+ const key = `${id}@${opts.version}`;
136
+ const existing = this.entries.get(key);
137
+ if (existing) {
138
+ if (existing.record.digest === digest)
139
+ return ((await this.refreshed({ id, version: opts.version })) ??
140
+ structuredClone(existing.record));
141
+ throw new AgentropyError('InvalidConfiguration', `${key} is already registered with different content`, { details: { reason: 'immutable', id } });
142
+ }
143
+ const row = this.options.store
144
+ ? (await readLifecycle(this.options.store, 'skill', {
145
+ id,
146
+ version: opts.version,
147
+ }))?.value
148
+ : undefined;
149
+ if (conflicts(row, digest))
150
+ throw new AgentropyError('InvalidConfiguration', `${key} is already registered with different content`, { details: { reason: 'immutable', id } });
151
+ await this.guard(admin, 'register', id);
152
+ const record = {
153
+ id,
154
+ version: opts.version,
155
+ specVersion: AGENT_SKILLS_SPEC_VERSION,
156
+ metadata,
157
+ digest,
158
+ provenance: {
159
+ publisher: opts.publisher,
160
+ source: root,
161
+ verified: this.verify(metadata, opts.publisher),
162
+ },
163
+ requires: structuredClone(opts.requires ?? {}),
164
+ files,
165
+ status: 'registered',
166
+ revision: 1,
167
+ };
168
+ record.status = effectiveStatus('registered', row, digest, record.provenance.verified);
169
+ this.entries.set(key, { record, root });
170
+ return structuredClone(record);
171
+ }
172
+ /** The record with the status the store has (this process's own when it has no store). */
173
+ async refreshed(ref) {
174
+ const e = this.entries.get(`${ref.id}@${ref.version}`);
175
+ if (!e)
176
+ return undefined;
177
+ if (this.options.store) {
178
+ const row = (await readLifecycle(this.options.store, 'skill', ref))
179
+ ?.value;
180
+ const status = effectiveStatus(e.record.status, row, e.record.digest, e.record.provenance.verified);
181
+ if (status !== e.record.status) {
182
+ e.record.status = status;
183
+ e.record.revision += 1;
184
+ }
185
+ }
186
+ return structuredClone(e.record);
187
+ }
188
+ async activate(ref, admin) {
189
+ const e = this.require(ref);
190
+ if (!e.record.provenance.verified)
191
+ throw new AgentropyError('PermissionDenied', 'Unverified skills cannot be activated', { details: { reason: 'unverified' } });
192
+ const known = (await this.refreshed(ref)).status;
193
+ if (known !== 'registered')
194
+ throw new AgentropyError('InvalidState', `Cannot activate a ${known} skill`, { details: { status: known } });
195
+ await this.guard(admin, 'activate', ref.id);
196
+ if (this.options.store)
197
+ await moveLifecycle(this.options.store, 'skill', ref, {
198
+ from: ['registered'],
199
+ to: 'active',
200
+ local: e.record.status,
201
+ digest: e.record.digest,
202
+ by: admin.id,
203
+ at: this.security.now(),
204
+ });
205
+ e.record.status = 'active';
206
+ e.record.revision += 1;
207
+ return structuredClone(e.record);
208
+ }
209
+ async revoke(ref, admin) {
210
+ const e = this.require(ref);
211
+ if ((await this.refreshed(ref)).status === 'revoked')
212
+ throw new AgentropyError('InvalidState', 'Skill already revoked', {
213
+ details: { status: 'revoked' },
214
+ });
215
+ await this.guard(admin, 'revoke', ref.id);
216
+ if (this.options.store)
217
+ await moveLifecycle(this.options.store, 'skill', ref, {
218
+ from: ['registered', 'active'],
219
+ to: 'revoked',
220
+ local: e.record.status,
221
+ digest: e.record.digest,
222
+ by: admin.id,
223
+ at: this.security.now(),
224
+ });
225
+ e.record.status = 'revoked';
226
+ e.record.revision += 1;
227
+ return structuredClone(e.record);
228
+ }
229
+ get(ref) {
230
+ const e = this.entries.get(`${ref.id}@${ref.version}`);
231
+ return e ? structuredClone(e.record) : undefined;
232
+ }
233
+ /**
234
+ * Every version of a skill with this process's own status, which only moves when this process acts on it or calls
235
+ * `refreshed`. What must agree with other workers on the store (task acceptance) uses `refreshedVersions`.
236
+ */
237
+ versions(id) {
238
+ return [...this.entries.values()]
239
+ .filter((e) => e.record.id === id)
240
+ .map((e) => structuredClone(e.record));
241
+ }
242
+ /**
243
+ * Every version of a skill with the status the store has (FIX-084): an activation or revoke on another worker
244
+ * counts. Task acceptance resolves against this. Without a store it answers as `versions` does.
245
+ */
246
+ async refreshedVersions(id) {
247
+ const mine = [...this.entries.values()]
248
+ .map((e) => e.record)
249
+ .filter((r) => r.id === id);
250
+ if (this.options.store && mine.length > 0) {
251
+ const rows = await readLifecycles(this.options.store, 'skill');
252
+ for (const r of mine) {
253
+ const status = effectiveStatus(r.status, rows.get(lifecycleKey('skill', r)), r.digest, r.provenance.verified);
254
+ if (status !== r.status) {
255
+ r.status = status;
256
+ r.revision += 1;
257
+ }
258
+ }
259
+ }
260
+ return mine.map((r) => structuredClone(r));
261
+ }
262
+ /** Metadata-first discovery: never reads instructions or resources. */
263
+ async discover(query, caller) {
264
+ void caller;
265
+ const text = query.text?.toLowerCase();
266
+ const rows = this.options.store
267
+ ? await readLifecycles(this.options.store, 'skill')
268
+ : new Map();
269
+ return [...this.entries.values()]
270
+ .map((e) => e.record)
271
+ .filter((r) => effectiveStatus(r.status, rows.get(lifecycleKey('skill', r)), r.digest, r.provenance.verified) !== 'revoked')
272
+ .filter((r) => text
273
+ ? `${r.metadata.name} ${r.metadata.description}`
274
+ .toLowerCase()
275
+ .includes(text)
276
+ : true)
277
+ .sort((a, b) => a.id.localeCompare(b.id) || semver.compare(a.version, b.version))
278
+ .map((r) => ({
279
+ id: r.id,
280
+ version: r.version,
281
+ metadata: structuredClone(r.metadata),
282
+ }));
283
+ }
284
+ /** Internal: root directory of a pinned, non-revoked skill. */
285
+ async rootFor(pin) {
286
+ const e = this.require(pin);
287
+ await this.refreshed(pin); // revoked on another worker counts
288
+ if (e.record.status === 'revoked')
289
+ throw new AgentropyError('PermissionDenied', `Skill ${pin.id} is revoked`, { details: { status: 'revoked' } });
290
+ if (e.record.digest !== pin.digest)
291
+ throw new AgentropyError('IncompatibleVersion', `Skill ${pin.id}@${pin.version} pin does not match the registry`, { details: { kind: 'skill' } });
292
+ return { record: e.record, root: e.root };
293
+ }
294
+ require(ref) {
295
+ const e = this.entries.get(`${ref.id}@${ref.version}`);
296
+ if (!e)
297
+ throw new AgentropyError('NotFound', `Skill ${ref.id}@${ref.version} not found`, { details: { kind: 'skill' } });
298
+ return e;
299
+ }
300
+ }
301
+ /** Filesystem loader with content verification on every load (progressive disclosure: metadata → body → resources). */
302
+ export class FileSystemSkillLoader {
303
+ registry;
304
+ constructor(registry) {
305
+ this.registry = registry;
306
+ }
307
+ async metadata(pin) {
308
+ return structuredClone((await this.registry.rootFor(pin)).record.metadata);
309
+ }
310
+ async instructions(pin) {
311
+ const { root } = await this.verified(pin);
312
+ return parseSkillMd(await readFile(join(root, 'SKILL.md'), 'utf8')).body;
313
+ }
314
+ async resource(pin, relativePath) {
315
+ const safe = normalize(relativePath);
316
+ if (!relativePath ||
317
+ isAbsolute(relativePath) ||
318
+ safe.split(/[\\/]/).includes('..') ||
319
+ safe.startsWith(sep)) {
320
+ throw new AgentropyError('PermissionDenied', 'Skill resource path must stay inside the skill', { details: { reason: 'path' } });
321
+ }
322
+ const { root, record } = await this.verified(pin);
323
+ const rel = safe.split(sep).join('/');
324
+ if (!record.files.includes(rel))
325
+ throw new AgentropyError('NotFound', 'Skill resource not found', {
326
+ details: { kind: 'skill-resource' },
327
+ });
328
+ const full = join(root, rel);
329
+ if ((await lstat(full)).isSymbolicLink() ||
330
+ !(await realpath(full)).startsWith(root + sep)) {
331
+ throw new AgentropyError('PermissionDenied', 'Skill resource path must stay inside the skill', { details: { reason: 'path' } });
332
+ }
333
+ return new Uint8Array(await readFile(full));
334
+ }
335
+ async verified(pin) {
336
+ const resolved = await this.registry.rootFor(pin);
337
+ const { digest } = await digestSkillDirectory(resolved.root);
338
+ if (digest !== pin.digest)
339
+ throw new AgentropyError('IncompatibleVersion', `Skill ${pin.id} content changed after pinning`, { details: { kind: 'skill' } });
340
+ return resolved;
341
+ }
342
+ }
343
+ /** AgentContext.skills: read-only access to a task's pinned skills; grants nothing and executes nothing. */
344
+ export class PinnedSkillAccess {
345
+ loader;
346
+ registry;
347
+ pins;
348
+ constructor(loader, registry, pins) {
349
+ this.loader = loader;
350
+ this.registry = registry;
351
+ this.pins = pins;
352
+ }
353
+ list() {
354
+ return this.pins
355
+ .map((p) => this.registry.get(p)?.metadata)
356
+ .filter((m) => m !== undefined);
357
+ }
358
+ async instructions(skillId) {
359
+ return this.loader.instructions(this.pin(skillId));
360
+ }
361
+ async resource(skillId, relativePath) {
362
+ return this.loader.resource(this.pin(skillId), relativePath);
363
+ }
364
+ /** Script execution is outside Skill v1. */
365
+ async executeScript(skillId, relativePath) {
366
+ this.pin(skillId);
367
+ void relativePath;
368
+ throw new AgentropyError('UnsupportedOperation', 'Skill script execution is not supported in v1', { details: { feature: 'skill-scripts' } });
369
+ }
370
+ pin(skillId) {
371
+ const p = this.pins.find((x) => x.id === skillId);
372
+ if (!p)
373
+ throw new AgentropyError('CapabilityNotDeclared', `Skill ${skillId} is not pinned for this task`, { details: { kind: 'skill' } });
374
+ return p;
375
+ }
376
+ }