@agentic-kit/harness 0.1.0 → 0.2.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.
- package/README.md +13 -1
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -0
- package/esm/skills/frontmatter.d.ts +3 -1
- package/esm/skills/frontmatter.js +20 -2
- package/esm/skills/git-fetch.d.ts +32 -0
- package/esm/skills/git-fetch.js +120 -0
- package/esm/skills/overlay.d.ts +14 -1
- package/esm/skills/overlay.js +27 -1
- package/esm/skills/source.js +2 -2
- package/esm/skills/update-check.d.ts +13 -2
- package/esm/skills/update-check.js +15 -2
- package/esm/types.d.ts +2 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +2 -2
- package/skills/frontmatter.d.ts +3 -1
- package/skills/frontmatter.js +20 -2
- package/skills/git-fetch.d.ts +32 -0
- package/skills/git-fetch.js +157 -0
- package/skills/overlay.d.ts +14 -1
- package/skills/overlay.js +27 -1
- package/skills/source.js +2 -2
- package/skills/update-check.d.ts +13 -2
- package/skills/update-check.js +16 -2
- package/types.d.ts +2 -0
package/README.md
CHANGED
|
@@ -43,6 +43,13 @@ the core owns everything host-neutral.
|
|
|
43
43
|
releases inside `compatibleSkillsRange`, and flags
|
|
44
44
|
`harnessUpgradeRequired` when newer skills need newer tool code. Never
|
|
45
45
|
throws — falls back to cache or "no update" offline.
|
|
46
|
+
- `fetchSkillsFromGit()` / `checkForSkillsUpdateFromGit()` — the same fetch
|
|
47
|
+
and update check straight from the GitHub repo (the skills repo is just a
|
|
48
|
+
git repository, released by tagging): a pin (tag, semver range against
|
|
49
|
+
tags, full commit SHA, or branch) resolves via the GitHub API, the
|
|
50
|
+
codeload tarball unpacks into the same `<skillsRoot>/<version>/` layout,
|
|
51
|
+
so caching, offline fallback (`latestLocalRelease()`), and
|
|
52
|
+
`DirectorySkillSource` work identically.
|
|
46
53
|
- Ordered-overlay skill resolution:
|
|
47
54
|
- `SkillsManifest` — ordered source layers, each with its own version pin
|
|
48
55
|
and include/exclude filters, plus `compatibleSkillsRange` so updaters
|
|
@@ -50,7 +57,12 @@ the core owns everything host-neutral.
|
|
|
50
57
|
- `DirectorySkillSource` — loads the agentskills.io layout
|
|
51
58
|
(`<skill>/SKILL.md` + references/scripts).
|
|
52
59
|
- `resolveSkills()` — last-write-wins merge across layers (hardened base →
|
|
53
|
-
team overlays → private known-gaps overlay)
|
|
60
|
+
team overlays → private known-gaps overlay), then transitive frontmatter
|
|
61
|
+
`requires:` expansion: a skill can declare skills it depends on
|
|
62
|
+
(`requires: [constructive-security]` or a YAML list) and they are pulled
|
|
63
|
+
in even when a layer's `include` filter omits them; explicit `exclude`
|
|
64
|
+
entries still win, and unresolvable requirements surface through
|
|
65
|
+
`onMissingRequire` instead of throwing.
|
|
54
66
|
- `materializeSkills()` — writes the merged tree with `{{VAR}}`
|
|
55
67
|
substitution (e.g. `HARNESS_TEMPLATES_DIR`).
|
|
56
68
|
|
package/esm/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './skills/materialize';
|
|
|
8
8
|
export * from './skills/registry';
|
|
9
9
|
export * from './skills/integrity';
|
|
10
10
|
export * from './skills/fetch';
|
|
11
|
+
export * from './skills/git-fetch';
|
|
11
12
|
export * from './skills/update-check';
|
|
12
13
|
export * from './gating/preview';
|
|
13
14
|
export * from './gating/decline-guard';
|
package/esm/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export * from './skills/materialize';
|
|
|
8
8
|
export * from './skills/registry';
|
|
9
9
|
export * from './skills/integrity';
|
|
10
10
|
export * from './skills/fetch';
|
|
11
|
+
export * from './skills/git-fetch';
|
|
11
12
|
export * from './skills/update-check';
|
|
12
13
|
export * from './gating/preview';
|
|
13
14
|
export * from './gating/decline-guard';
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export interface ParsedSkillFrontmatter {
|
|
2
2
|
name: string;
|
|
3
3
|
description: string;
|
|
4
|
+
/** Skill names this skill depends on (frontmatter `requires:`). */
|
|
5
|
+
requires: string[];
|
|
4
6
|
body: string;
|
|
5
7
|
}
|
|
6
|
-
/** Parse the minimal YAML frontmatter (`name`, `description`) of a SKILL.md. */
|
|
8
|
+
/** Parse the minimal YAML frontmatter (`name`, `description`, optional `requires`) of a SKILL.md. */
|
|
7
9
|
export declare function parseFrontmatter(raw: string): ParsedSkillFrontmatter;
|
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
function parseRequires(fm) {
|
|
2
|
+
const inline = fm.match(/(?:^|\n)requires:\s*\[([^\]]*)\]/);
|
|
3
|
+
if (inline) {
|
|
4
|
+
return inline[1]
|
|
5
|
+
.split(',')
|
|
6
|
+
.map((s) => unquoteScalar(s.trim()) ?? '')
|
|
7
|
+
.filter(Boolean);
|
|
8
|
+
}
|
|
9
|
+
const block = fm.match(/(?:^|\n)requires:\s*\n((?:[ \t]+-[^\n]*\n?)+)/);
|
|
10
|
+
if (block) {
|
|
11
|
+
return block[1]
|
|
12
|
+
.split('\n')
|
|
13
|
+
.map((line) => line.replace(/^[ \t]+-\s*/, '').trim())
|
|
14
|
+
.map((s) => unquoteScalar(s) ?? '')
|
|
15
|
+
.filter(Boolean);
|
|
16
|
+
}
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
1
19
|
function unquoteScalar(value) {
|
|
2
20
|
if (value && value.length >= 2 && value.startsWith('"') && value.endsWith('"')) {
|
|
3
21
|
try {
|
|
@@ -9,7 +27,7 @@ function unquoteScalar(value) {
|
|
|
9
27
|
}
|
|
10
28
|
return value;
|
|
11
29
|
}
|
|
12
|
-
/** Parse the minimal YAML frontmatter (`name`, `description`) of a SKILL.md. */
|
|
30
|
+
/** Parse the minimal YAML frontmatter (`name`, `description`, optional `requires`) of a SKILL.md. */
|
|
13
31
|
export function parseFrontmatter(raw) {
|
|
14
32
|
const match = raw.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/);
|
|
15
33
|
if (!match) {
|
|
@@ -24,5 +42,5 @@ export function parseFrontmatter(raw) {
|
|
|
24
42
|
throw new Error('Skill frontmatter missing `name`');
|
|
25
43
|
if (!description)
|
|
26
44
|
throw new Error('Skill frontmatter missing `description`');
|
|
27
|
-
return { name, description, body };
|
|
45
|
+
return { name, description, requires: parseRequires(fm), body };
|
|
28
46
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { FetchedRelease } from './fetch';
|
|
2
|
+
import { FetchLike } from './registry';
|
|
3
|
+
/**
|
|
4
|
+
* GitHub-repo skill source: the skills repo is just a git repository
|
|
5
|
+
* (e.g. `constructive-io/constructive-skills`), released by tagging. Releases
|
|
6
|
+
* are downloaded as codeload tarballs and unpacked into the same
|
|
7
|
+
* `<skillsRoot>/<version>/` layout the npm fetcher uses, so
|
|
8
|
+
* `latestLocalRelease()` and `DirectorySkillSource` work identically for both.
|
|
9
|
+
*/
|
|
10
|
+
export interface GitFetchOptions {
|
|
11
|
+
/** `owner/repo`, e.g. `constructive-io/constructive-skills`. */
|
|
12
|
+
repo: string;
|
|
13
|
+
/**
|
|
14
|
+
* Ref pin: a tag (`v1.2.0`), a semver range resolved against tags
|
|
15
|
+
* (`^1.2.0`), a full commit SHA, or a branch name. Tags and SHAs are
|
|
16
|
+
* reproducible pins; a branch is a moving pointer resolved at fetch time.
|
|
17
|
+
*/
|
|
18
|
+
pin: string;
|
|
19
|
+
/** Root directory releases unpack into: `<skillsRoot>/<version>/`. */
|
|
20
|
+
skillsRoot: string;
|
|
21
|
+
/** Path of the skills tree inside the repo (default `.agents/skills`). */
|
|
22
|
+
repoSubdir?: string;
|
|
23
|
+
/** GitHub API/codeload base overrides (GHES) and injectable HTTP. */
|
|
24
|
+
apiUrl?: string;
|
|
25
|
+
codeloadUrl?: string;
|
|
26
|
+
fetchImpl?: FetchLike;
|
|
27
|
+
/** Token for private repos; sent as `authorization: Bearer <token>`. */
|
|
28
|
+
token?: string;
|
|
29
|
+
}
|
|
30
|
+
export declare function fetchSkillsFromGit(options: GitFetchOptions): Promise<FetchedRelease>;
|
|
31
|
+
/** Semver versions published as tags on the repo (e.g. `v1.2.0` → `1.2.0`). */
|
|
32
|
+
export declare function listGitTagVersions(options: Pick<GitFetchOptions, 'repo' | 'apiUrl' | 'fetchImpl' | 'token'>): Promise<string[]>;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as os from 'os';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import * as semver from 'semver';
|
|
5
|
+
import * as tar from 'tar';
|
|
6
|
+
const DEFAULT_API = 'https://api.github.com';
|
|
7
|
+
const DEFAULT_CODELOAD = 'https://codeload.github.com';
|
|
8
|
+
const FULL_SHA = /^[0-9a-f]{40}$/;
|
|
9
|
+
export async function fetchSkillsFromGit(options) {
|
|
10
|
+
const subdir = options.repoSubdir ?? '.agents/skills';
|
|
11
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
12
|
+
// Reproducible pins already on disk never touch the network.
|
|
13
|
+
const exact = semver.valid(cleanTag(options.pin)) ?? (FULL_SHA.test(options.pin) ? options.pin : null);
|
|
14
|
+
if (exact) {
|
|
15
|
+
const cached = cachedGitRelease(options.skillsRoot, exact, subdir);
|
|
16
|
+
if (cached)
|
|
17
|
+
return cached;
|
|
18
|
+
}
|
|
19
|
+
const resolved = await resolveGitPin(options, fetchImpl);
|
|
20
|
+
const cached = cachedGitRelease(options.skillsRoot, resolved.version, subdir);
|
|
21
|
+
if (cached)
|
|
22
|
+
return cached;
|
|
23
|
+
const codeload = (options.codeloadUrl ?? DEFAULT_CODELOAD).replace(/\/$/, '');
|
|
24
|
+
const url = `${codeload}/${options.repo}/tar.gz/${resolved.ref}`;
|
|
25
|
+
const res = await fetchImpl(url, { headers: authHeaders(options.token) });
|
|
26
|
+
if (!res.ok) {
|
|
27
|
+
throw new Error(`Git tarball download failed: HTTP ${res.status} (${url})`);
|
|
28
|
+
}
|
|
29
|
+
const data = Buffer.from(await res.arrayBuffer());
|
|
30
|
+
const versionDir = path.join(options.skillsRoot, resolved.version);
|
|
31
|
+
const staging = fs.mkdtempSync(path.join(os.tmpdir(), 'harness-skills-git-'));
|
|
32
|
+
try {
|
|
33
|
+
const tarballPath = path.join(staging, 'release.tgz');
|
|
34
|
+
fs.writeFileSync(tarballPath, data);
|
|
35
|
+
const unpackDir = path.join(staging, 'repo');
|
|
36
|
+
fs.mkdirSync(unpackDir);
|
|
37
|
+
await tar.extract({ file: tarballPath, cwd: unpackDir, strip: 1 });
|
|
38
|
+
if (!fs.existsSync(path.join(unpackDir, subdir))) {
|
|
39
|
+
throw new Error(`${options.repo}@${resolved.ref} has no ${subdir} directory`);
|
|
40
|
+
}
|
|
41
|
+
fs.mkdirSync(path.dirname(versionDir), { recursive: true });
|
|
42
|
+
fs.rmSync(versionDir, { recursive: true, force: true });
|
|
43
|
+
fs.renameSync(unpackDir, versionDir);
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
fs.rmSync(staging, { recursive: true, force: true });
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
version: resolved.version,
|
|
50
|
+
skillsDir: path.join(versionDir, subdir),
|
|
51
|
+
fromCache: false,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Resolve a pin to a downloadable ref:
|
|
56
|
+
* 1. full commit SHA → itself;
|
|
57
|
+
* 2. exact tag (with or without `v`) → that tag;
|
|
58
|
+
* 3. semver range → highest satisfying tag;
|
|
59
|
+
* 4. anything else → treated as a branch, resolved to its head SHA.
|
|
60
|
+
*/
|
|
61
|
+
async function resolveGitPin(options, fetchImpl) {
|
|
62
|
+
const { pin } = options;
|
|
63
|
+
if (FULL_SHA.test(pin)) {
|
|
64
|
+
return { version: pin, ref: pin, sha: pin };
|
|
65
|
+
}
|
|
66
|
+
const tags = await listTags(options, fetchImpl);
|
|
67
|
+
const byVersion = new Map();
|
|
68
|
+
for (const tag of tags) {
|
|
69
|
+
const version = semver.valid(cleanTag(tag.name));
|
|
70
|
+
if (version)
|
|
71
|
+
byVersion.set(version, tag);
|
|
72
|
+
}
|
|
73
|
+
const exact = semver.valid(cleanTag(pin));
|
|
74
|
+
if (exact && byVersion.has(exact)) {
|
|
75
|
+
const tag = byVersion.get(exact);
|
|
76
|
+
return { version: exact, ref: tag.name, sha: tag.sha };
|
|
77
|
+
}
|
|
78
|
+
const resolved = semver.maxSatisfying([...byVersion.keys()], pin);
|
|
79
|
+
if (resolved) {
|
|
80
|
+
const tag = byVersion.get(resolved);
|
|
81
|
+
return { version: resolved, ref: tag.name, sha: tag.sha };
|
|
82
|
+
}
|
|
83
|
+
// Branch pin: resolve the head SHA so the unpacked dir is content-addressed.
|
|
84
|
+
const api = (options.apiUrl ?? DEFAULT_API).replace(/\/$/, '');
|
|
85
|
+
const res = await fetchImpl(`${api}/repos/${options.repo}/commits/${encodeURIComponent(pin)}`, {
|
|
86
|
+
headers: { accept: 'application/vnd.github+json', ...authHeaders(options.token) },
|
|
87
|
+
});
|
|
88
|
+
if (!res.ok) {
|
|
89
|
+
throw new Error(`No tag satisfies "${pin}" and ref lookup failed: HTTP ${res.status}`);
|
|
90
|
+
}
|
|
91
|
+
const commit = (await res.json());
|
|
92
|
+
return { version: commit.sha, ref: commit.sha, sha: commit.sha };
|
|
93
|
+
}
|
|
94
|
+
/** Semver versions published as tags on the repo (e.g. `v1.2.0` → `1.2.0`). */
|
|
95
|
+
export async function listGitTagVersions(options) {
|
|
96
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
97
|
+
const tags = await listTags(options, fetchImpl);
|
|
98
|
+
return tags.map((t) => semver.valid(cleanTag(t.name))).filter((v) => v !== null);
|
|
99
|
+
}
|
|
100
|
+
async function listTags(options, fetchImpl) {
|
|
101
|
+
const api = (options.apiUrl ?? DEFAULT_API).replace(/\/$/, '');
|
|
102
|
+
const res = await fetchImpl(`${api}/repos/${options.repo}/tags?per_page=100`, {
|
|
103
|
+
headers: { accept: 'application/vnd.github+json', ...authHeaders(options.token) },
|
|
104
|
+
});
|
|
105
|
+
if (!res.ok) {
|
|
106
|
+
throw new Error(`Tag listing failed for ${options.repo}: HTTP ${res.status}`);
|
|
107
|
+
}
|
|
108
|
+
const tags = (await res.json());
|
|
109
|
+
return tags.map((t) => ({ name: t.name, sha: t.commit.sha }));
|
|
110
|
+
}
|
|
111
|
+
function cachedGitRelease(skillsRoot, version, subdir) {
|
|
112
|
+
const skillsDir = path.join(skillsRoot, version, subdir);
|
|
113
|
+
return fs.existsSync(skillsDir) ? { version, skillsDir, fromCache: true } : null;
|
|
114
|
+
}
|
|
115
|
+
function cleanTag(tag) {
|
|
116
|
+
return tag.replace(/^v/, '');
|
|
117
|
+
}
|
|
118
|
+
function authHeaders(token) {
|
|
119
|
+
return token ? { authorization: `Bearer ${token}` } : {};
|
|
120
|
+
}
|
package/esm/skills/overlay.d.ts
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
import { HarnessSkill } from '../types';
|
|
2
2
|
import { SkillsManifest } from './manifest';
|
|
3
3
|
import { SkillSource } from './source';
|
|
4
|
+
export interface ResolveSkillsOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Called for every `requires:` entry that names a skill not present in any
|
|
7
|
+
* layer (or explicitly excluded everywhere). Missing requirements never
|
|
8
|
+
* throw — a skill may legitimately depend on one the host bundles itself.
|
|
9
|
+
*/
|
|
10
|
+
onMissingRequire?: (skillName: string, requiredName: string) => void;
|
|
11
|
+
}
|
|
4
12
|
/**
|
|
5
13
|
* Resolve the effective skill set from ordered source layers.
|
|
6
14
|
*
|
|
7
15
|
* Sources are applied in manifest order; a later layer replaces an
|
|
8
16
|
* earlier layer's skill of the same name wholesale (all files), and may add
|
|
9
17
|
* new skills. Include/exclude filters apply per layer.
|
|
18
|
+
*
|
|
19
|
+
* After merging, frontmatter `requires:` dependencies are followed
|
|
20
|
+
* transitively: a required skill is pulled in even when a layer's `include`
|
|
21
|
+
* list omits it. Explicit `exclude` entries still win — an excluded skill is
|
|
22
|
+
* never pulled back in by a dependency.
|
|
10
23
|
*/
|
|
11
|
-
export declare function resolveSkills(manifest: SkillsManifest, sources: SkillSource[]): Promise<HarnessSkill[]>;
|
|
24
|
+
export declare function resolveSkills(manifest: SkillsManifest, sources: SkillSource[], options?: ResolveSkillsOptions): Promise<HarnessSkill[]>;
|
package/esm/skills/overlay.js
CHANGED
|
@@ -5,21 +5,47 @@ import { layerAllowsSkill, validateManifest } from './manifest';
|
|
|
5
5
|
* Sources are applied in manifest order; a later layer replaces an
|
|
6
6
|
* earlier layer's skill of the same name wholesale (all files), and may add
|
|
7
7
|
* new skills. Include/exclude filters apply per layer.
|
|
8
|
+
*
|
|
9
|
+
* After merging, frontmatter `requires:` dependencies are followed
|
|
10
|
+
* transitively: a required skill is pulled in even when a layer's `include`
|
|
11
|
+
* list omits it. Explicit `exclude` entries still win — an excluded skill is
|
|
12
|
+
* never pulled back in by a dependency.
|
|
8
13
|
*/
|
|
9
|
-
export async function resolveSkills(manifest, sources) {
|
|
14
|
+
export async function resolveSkills(manifest, sources, options = {}) {
|
|
10
15
|
validateManifest(manifest);
|
|
11
16
|
const byName = new Map(sources.map((s) => [s.name, s]));
|
|
12
17
|
const resolved = new Map();
|
|
18
|
+
/** Merged pool ignoring `include` filters (but honoring `exclude`) — the
|
|
19
|
+
* candidates a `requires:` may pull in. */
|
|
20
|
+
const requirePool = new Map();
|
|
13
21
|
for (const ref of manifest.sources) {
|
|
14
22
|
const source = byName.get(ref.name);
|
|
15
23
|
if (!source) {
|
|
16
24
|
throw new Error(`Manifest source ${ref.name} has no registered SkillSource`);
|
|
17
25
|
}
|
|
18
26
|
for (const skill of await source.load()) {
|
|
27
|
+
if (ref.exclude?.includes(skill.name))
|
|
28
|
+
continue;
|
|
29
|
+
requirePool.set(skill.name, skill);
|
|
19
30
|
if (!layerAllowsSkill(ref, skill.name))
|
|
20
31
|
continue;
|
|
21
32
|
resolved.set(skill.name, skill);
|
|
22
33
|
}
|
|
23
34
|
}
|
|
35
|
+
const queue = [...resolved.values()];
|
|
36
|
+
while (queue.length > 0) {
|
|
37
|
+
const skill = queue.pop();
|
|
38
|
+
for (const requiredName of skill.requires) {
|
|
39
|
+
if (resolved.has(requiredName))
|
|
40
|
+
continue;
|
|
41
|
+
const required = requirePool.get(requiredName);
|
|
42
|
+
if (!required) {
|
|
43
|
+
options.onMissingRequire?.(skill.name, requiredName);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
resolved.set(requiredName, required);
|
|
47
|
+
queue.push(required);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
24
50
|
return [...resolved.values()];
|
|
25
51
|
}
|
package/esm/skills/source.js
CHANGED
|
@@ -26,10 +26,10 @@ export class DirectorySkillSource {
|
|
|
26
26
|
if (!fs.existsSync(skillMd))
|
|
27
27
|
continue;
|
|
28
28
|
const raw = fs.readFileSync(skillMd, 'utf8');
|
|
29
|
-
const { name, description } = parseFrontmatter(raw);
|
|
29
|
+
const { name, description, requires } = parseFrontmatter(raw);
|
|
30
30
|
const files = [{ relPath: 'SKILL.md', contents: raw }];
|
|
31
31
|
collectExtraFiles(skillDir, '', files);
|
|
32
|
-
skills.push({ name, description, files, sourceName: this.name });
|
|
32
|
+
skills.push({ name, description, requires, files, sourceName: this.name });
|
|
33
33
|
}
|
|
34
34
|
return skills;
|
|
35
35
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { GitFetchOptions } from './git-fetch';
|
|
1
2
|
import { RegistryOptions } from './registry';
|
|
2
|
-
|
|
3
|
-
pkg: string;
|
|
3
|
+
interface UpdateCheckCommonOptions {
|
|
4
4
|
/** Version currently in use. */
|
|
5
5
|
currentVersion: string;
|
|
6
6
|
/**
|
|
@@ -14,6 +14,11 @@ export interface UpdateCheckOptions extends RegistryOptions {
|
|
|
14
14
|
ttlMs?: number;
|
|
15
15
|
now?: () => number;
|
|
16
16
|
}
|
|
17
|
+
export interface UpdateCheckOptions extends RegistryOptions, UpdateCheckCommonOptions {
|
|
18
|
+
pkg: string;
|
|
19
|
+
}
|
|
20
|
+
export interface GitUpdateCheckOptions extends Pick<GitFetchOptions, 'repo' | 'apiUrl' | 'fetchImpl' | 'token'>, UpdateCheckCommonOptions {
|
|
21
|
+
}
|
|
17
22
|
export interface UpdateCheckResult {
|
|
18
23
|
checkedAt: number;
|
|
19
24
|
/** True when this result came from the cache file, not the registry. */
|
|
@@ -34,3 +39,9 @@ export interface UpdateCheckResult {
|
|
|
34
39
|
* cached result (stale ok) or report "no update" — never throw.
|
|
35
40
|
*/
|
|
36
41
|
export declare function checkForSkillsUpdate(options: UpdateCheckOptions): Promise<UpdateCheckResult>;
|
|
42
|
+
/**
|
|
43
|
+
* Same update check against a GitHub repo's semver tags instead of an npm
|
|
44
|
+
* registry (the skills repo is just a git repository, released by tagging).
|
|
45
|
+
*/
|
|
46
|
+
export declare function checkForSkillsUpdateFromGit(options: GitUpdateCheckOptions): Promise<UpdateCheckResult>;
|
|
47
|
+
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
import * as semver from 'semver';
|
|
4
|
+
import { listGitTagVersions } from './git-fetch';
|
|
4
5
|
import { RegistryClient } from './registry';
|
|
5
6
|
const DEFAULT_TTL_MS = 24 * 60 * 60 * 1000;
|
|
6
7
|
/**
|
|
@@ -9,6 +10,19 @@ const DEFAULT_TTL_MS = 24 * 60 * 60 * 1000;
|
|
|
9
10
|
* cached result (stale ok) or report "no update" — never throw.
|
|
10
11
|
*/
|
|
11
12
|
export async function checkForSkillsUpdate(options) {
|
|
13
|
+
return checkWithLister(options, async () => {
|
|
14
|
+
const packument = await new RegistryClient(options).packument(options.pkg);
|
|
15
|
+
return Object.keys(packument.versions);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Same update check against a GitHub repo's semver tags instead of an npm
|
|
20
|
+
* registry (the skills repo is just a git repository, released by tagging).
|
|
21
|
+
*/
|
|
22
|
+
export async function checkForSkillsUpdateFromGit(options) {
|
|
23
|
+
return checkWithLister(options, () => listGitTagVersions(options));
|
|
24
|
+
}
|
|
25
|
+
async function checkWithLister(options, listVersions) {
|
|
12
26
|
const now = options.now ?? Date.now;
|
|
13
27
|
const ttl = options.ttlMs ?? DEFAULT_TTL_MS;
|
|
14
28
|
const cached = readCache(options.cacheFile);
|
|
@@ -17,8 +31,7 @@ export async function checkForSkillsUpdate(options) {
|
|
|
17
31
|
}
|
|
18
32
|
let versions;
|
|
19
33
|
try {
|
|
20
|
-
|
|
21
|
-
versions = Object.keys(packument.versions).filter((v) => semver.valid(v));
|
|
34
|
+
versions = (await listVersions()).filter((v) => semver.valid(v));
|
|
22
35
|
}
|
|
23
36
|
catch {
|
|
24
37
|
if (cached)
|
package/esm/types.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export interface SkillFile {
|
|
|
15
15
|
export interface HarnessSkill {
|
|
16
16
|
name: string;
|
|
17
17
|
description: string;
|
|
18
|
+
/** Skill names this skill depends on (frontmatter `requires:`). */
|
|
19
|
+
requires: string[];
|
|
18
20
|
files: SkillFile[];
|
|
19
21
|
/** Name of the manifest source layer this skill was resolved from. */
|
|
20
22
|
sourceName: string;
|
package/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './skills/materialize';
|
|
|
8
8
|
export * from './skills/registry';
|
|
9
9
|
export * from './skills/integrity';
|
|
10
10
|
export * from './skills/fetch';
|
|
11
|
+
export * from './skills/git-fetch';
|
|
11
12
|
export * from './skills/update-check';
|
|
12
13
|
export * from './gating/preview';
|
|
13
14
|
export * from './gating/decline-guard';
|
package/index.js
CHANGED
|
@@ -24,6 +24,7 @@ __exportStar(require("./skills/materialize"), exports);
|
|
|
24
24
|
__exportStar(require("./skills/registry"), exports);
|
|
25
25
|
__exportStar(require("./skills/integrity"), exports);
|
|
26
26
|
__exportStar(require("./skills/fetch"), exports);
|
|
27
|
+
__exportStar(require("./skills/git-fetch"), exports);
|
|
27
28
|
__exportStar(require("./skills/update-check"), exports);
|
|
28
29
|
__exportStar(require("./gating/preview"), exports);
|
|
29
30
|
__exportStar(require("./gating/decline-guard"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentic-kit/harness",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
5
5
|
"description": "Host-agnostic Constructive harness core — skill overlay resolution, materialization, and on-disk layout for harness hosts (desktop, CLI, MCP)",
|
|
6
6
|
"main": "index.js",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"@types/semver": "^7.7.0"
|
|
39
39
|
},
|
|
40
40
|
"keywords": [],
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "af2e71e8ea8705344beb98152b4f15b88dc1b122"
|
|
42
42
|
}
|
package/skills/frontmatter.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export interface ParsedSkillFrontmatter {
|
|
2
2
|
name: string;
|
|
3
3
|
description: string;
|
|
4
|
+
/** Skill names this skill depends on (frontmatter `requires:`). */
|
|
5
|
+
requires: string[];
|
|
4
6
|
body: string;
|
|
5
7
|
}
|
|
6
|
-
/** Parse the minimal YAML frontmatter (`name`, `description`) of a SKILL.md. */
|
|
8
|
+
/** Parse the minimal YAML frontmatter (`name`, `description`, optional `requires`) of a SKILL.md. */
|
|
7
9
|
export declare function parseFrontmatter(raw: string): ParsedSkillFrontmatter;
|
package/skills/frontmatter.js
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseFrontmatter = parseFrontmatter;
|
|
4
|
+
function parseRequires(fm) {
|
|
5
|
+
const inline = fm.match(/(?:^|\n)requires:\s*\[([^\]]*)\]/);
|
|
6
|
+
if (inline) {
|
|
7
|
+
return inline[1]
|
|
8
|
+
.split(',')
|
|
9
|
+
.map((s) => unquoteScalar(s.trim()) ?? '')
|
|
10
|
+
.filter(Boolean);
|
|
11
|
+
}
|
|
12
|
+
const block = fm.match(/(?:^|\n)requires:\s*\n((?:[ \t]+-[^\n]*\n?)+)/);
|
|
13
|
+
if (block) {
|
|
14
|
+
return block[1]
|
|
15
|
+
.split('\n')
|
|
16
|
+
.map((line) => line.replace(/^[ \t]+-\s*/, '').trim())
|
|
17
|
+
.map((s) => unquoteScalar(s) ?? '')
|
|
18
|
+
.filter(Boolean);
|
|
19
|
+
}
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
4
22
|
function unquoteScalar(value) {
|
|
5
23
|
if (value && value.length >= 2 && value.startsWith('"') && value.endsWith('"')) {
|
|
6
24
|
try {
|
|
@@ -12,7 +30,7 @@ function unquoteScalar(value) {
|
|
|
12
30
|
}
|
|
13
31
|
return value;
|
|
14
32
|
}
|
|
15
|
-
/** Parse the minimal YAML frontmatter (`name`, `description`) of a SKILL.md. */
|
|
33
|
+
/** Parse the minimal YAML frontmatter (`name`, `description`, optional `requires`) of a SKILL.md. */
|
|
16
34
|
function parseFrontmatter(raw) {
|
|
17
35
|
const match = raw.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/);
|
|
18
36
|
if (!match) {
|
|
@@ -27,5 +45,5 @@ function parseFrontmatter(raw) {
|
|
|
27
45
|
throw new Error('Skill frontmatter missing `name`');
|
|
28
46
|
if (!description)
|
|
29
47
|
throw new Error('Skill frontmatter missing `description`');
|
|
30
|
-
return { name, description, body };
|
|
48
|
+
return { name, description, requires: parseRequires(fm), body };
|
|
31
49
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { FetchedRelease } from './fetch';
|
|
2
|
+
import { FetchLike } from './registry';
|
|
3
|
+
/**
|
|
4
|
+
* GitHub-repo skill source: the skills repo is just a git repository
|
|
5
|
+
* (e.g. `constructive-io/constructive-skills`), released by tagging. Releases
|
|
6
|
+
* are downloaded as codeload tarballs and unpacked into the same
|
|
7
|
+
* `<skillsRoot>/<version>/` layout the npm fetcher uses, so
|
|
8
|
+
* `latestLocalRelease()` and `DirectorySkillSource` work identically for both.
|
|
9
|
+
*/
|
|
10
|
+
export interface GitFetchOptions {
|
|
11
|
+
/** `owner/repo`, e.g. `constructive-io/constructive-skills`. */
|
|
12
|
+
repo: string;
|
|
13
|
+
/**
|
|
14
|
+
* Ref pin: a tag (`v1.2.0`), a semver range resolved against tags
|
|
15
|
+
* (`^1.2.0`), a full commit SHA, or a branch name. Tags and SHAs are
|
|
16
|
+
* reproducible pins; a branch is a moving pointer resolved at fetch time.
|
|
17
|
+
*/
|
|
18
|
+
pin: string;
|
|
19
|
+
/** Root directory releases unpack into: `<skillsRoot>/<version>/`. */
|
|
20
|
+
skillsRoot: string;
|
|
21
|
+
/** Path of the skills tree inside the repo (default `.agents/skills`). */
|
|
22
|
+
repoSubdir?: string;
|
|
23
|
+
/** GitHub API/codeload base overrides (GHES) and injectable HTTP. */
|
|
24
|
+
apiUrl?: string;
|
|
25
|
+
codeloadUrl?: string;
|
|
26
|
+
fetchImpl?: FetchLike;
|
|
27
|
+
/** Token for private repos; sent as `authorization: Bearer <token>`. */
|
|
28
|
+
token?: string;
|
|
29
|
+
}
|
|
30
|
+
export declare function fetchSkillsFromGit(options: GitFetchOptions): Promise<FetchedRelease>;
|
|
31
|
+
/** Semver versions published as tags on the repo (e.g. `v1.2.0` → `1.2.0`). */
|
|
32
|
+
export declare function listGitTagVersions(options: Pick<GitFetchOptions, 'repo' | 'apiUrl' | 'fetchImpl' | 'token'>): Promise<string[]>;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.fetchSkillsFromGit = fetchSkillsFromGit;
|
|
37
|
+
exports.listGitTagVersions = listGitTagVersions;
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
39
|
+
const os = __importStar(require("os"));
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const semver = __importStar(require("semver"));
|
|
42
|
+
const tar = __importStar(require("tar"));
|
|
43
|
+
const DEFAULT_API = 'https://api.github.com';
|
|
44
|
+
const DEFAULT_CODELOAD = 'https://codeload.github.com';
|
|
45
|
+
const FULL_SHA = /^[0-9a-f]{40}$/;
|
|
46
|
+
async function fetchSkillsFromGit(options) {
|
|
47
|
+
const subdir = options.repoSubdir ?? '.agents/skills';
|
|
48
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
49
|
+
// Reproducible pins already on disk never touch the network.
|
|
50
|
+
const exact = semver.valid(cleanTag(options.pin)) ?? (FULL_SHA.test(options.pin) ? options.pin : null);
|
|
51
|
+
if (exact) {
|
|
52
|
+
const cached = cachedGitRelease(options.skillsRoot, exact, subdir);
|
|
53
|
+
if (cached)
|
|
54
|
+
return cached;
|
|
55
|
+
}
|
|
56
|
+
const resolved = await resolveGitPin(options, fetchImpl);
|
|
57
|
+
const cached = cachedGitRelease(options.skillsRoot, resolved.version, subdir);
|
|
58
|
+
if (cached)
|
|
59
|
+
return cached;
|
|
60
|
+
const codeload = (options.codeloadUrl ?? DEFAULT_CODELOAD).replace(/\/$/, '');
|
|
61
|
+
const url = `${codeload}/${options.repo}/tar.gz/${resolved.ref}`;
|
|
62
|
+
const res = await fetchImpl(url, { headers: authHeaders(options.token) });
|
|
63
|
+
if (!res.ok) {
|
|
64
|
+
throw new Error(`Git tarball download failed: HTTP ${res.status} (${url})`);
|
|
65
|
+
}
|
|
66
|
+
const data = Buffer.from(await res.arrayBuffer());
|
|
67
|
+
const versionDir = path.join(options.skillsRoot, resolved.version);
|
|
68
|
+
const staging = fs.mkdtempSync(path.join(os.tmpdir(), 'harness-skills-git-'));
|
|
69
|
+
try {
|
|
70
|
+
const tarballPath = path.join(staging, 'release.tgz');
|
|
71
|
+
fs.writeFileSync(tarballPath, data);
|
|
72
|
+
const unpackDir = path.join(staging, 'repo');
|
|
73
|
+
fs.mkdirSync(unpackDir);
|
|
74
|
+
await tar.extract({ file: tarballPath, cwd: unpackDir, strip: 1 });
|
|
75
|
+
if (!fs.existsSync(path.join(unpackDir, subdir))) {
|
|
76
|
+
throw new Error(`${options.repo}@${resolved.ref} has no ${subdir} directory`);
|
|
77
|
+
}
|
|
78
|
+
fs.mkdirSync(path.dirname(versionDir), { recursive: true });
|
|
79
|
+
fs.rmSync(versionDir, { recursive: true, force: true });
|
|
80
|
+
fs.renameSync(unpackDir, versionDir);
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
fs.rmSync(staging, { recursive: true, force: true });
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
version: resolved.version,
|
|
87
|
+
skillsDir: path.join(versionDir, subdir),
|
|
88
|
+
fromCache: false,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Resolve a pin to a downloadable ref:
|
|
93
|
+
* 1. full commit SHA → itself;
|
|
94
|
+
* 2. exact tag (with or without `v`) → that tag;
|
|
95
|
+
* 3. semver range → highest satisfying tag;
|
|
96
|
+
* 4. anything else → treated as a branch, resolved to its head SHA.
|
|
97
|
+
*/
|
|
98
|
+
async function resolveGitPin(options, fetchImpl) {
|
|
99
|
+
const { pin } = options;
|
|
100
|
+
if (FULL_SHA.test(pin)) {
|
|
101
|
+
return { version: pin, ref: pin, sha: pin };
|
|
102
|
+
}
|
|
103
|
+
const tags = await listTags(options, fetchImpl);
|
|
104
|
+
const byVersion = new Map();
|
|
105
|
+
for (const tag of tags) {
|
|
106
|
+
const version = semver.valid(cleanTag(tag.name));
|
|
107
|
+
if (version)
|
|
108
|
+
byVersion.set(version, tag);
|
|
109
|
+
}
|
|
110
|
+
const exact = semver.valid(cleanTag(pin));
|
|
111
|
+
if (exact && byVersion.has(exact)) {
|
|
112
|
+
const tag = byVersion.get(exact);
|
|
113
|
+
return { version: exact, ref: tag.name, sha: tag.sha };
|
|
114
|
+
}
|
|
115
|
+
const resolved = semver.maxSatisfying([...byVersion.keys()], pin);
|
|
116
|
+
if (resolved) {
|
|
117
|
+
const tag = byVersion.get(resolved);
|
|
118
|
+
return { version: resolved, ref: tag.name, sha: tag.sha };
|
|
119
|
+
}
|
|
120
|
+
// Branch pin: resolve the head SHA so the unpacked dir is content-addressed.
|
|
121
|
+
const api = (options.apiUrl ?? DEFAULT_API).replace(/\/$/, '');
|
|
122
|
+
const res = await fetchImpl(`${api}/repos/${options.repo}/commits/${encodeURIComponent(pin)}`, {
|
|
123
|
+
headers: { accept: 'application/vnd.github+json', ...authHeaders(options.token) },
|
|
124
|
+
});
|
|
125
|
+
if (!res.ok) {
|
|
126
|
+
throw new Error(`No tag satisfies "${pin}" and ref lookup failed: HTTP ${res.status}`);
|
|
127
|
+
}
|
|
128
|
+
const commit = (await res.json());
|
|
129
|
+
return { version: commit.sha, ref: commit.sha, sha: commit.sha };
|
|
130
|
+
}
|
|
131
|
+
/** Semver versions published as tags on the repo (e.g. `v1.2.0` → `1.2.0`). */
|
|
132
|
+
async function listGitTagVersions(options) {
|
|
133
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
134
|
+
const tags = await listTags(options, fetchImpl);
|
|
135
|
+
return tags.map((t) => semver.valid(cleanTag(t.name))).filter((v) => v !== null);
|
|
136
|
+
}
|
|
137
|
+
async function listTags(options, fetchImpl) {
|
|
138
|
+
const api = (options.apiUrl ?? DEFAULT_API).replace(/\/$/, '');
|
|
139
|
+
const res = await fetchImpl(`${api}/repos/${options.repo}/tags?per_page=100`, {
|
|
140
|
+
headers: { accept: 'application/vnd.github+json', ...authHeaders(options.token) },
|
|
141
|
+
});
|
|
142
|
+
if (!res.ok) {
|
|
143
|
+
throw new Error(`Tag listing failed for ${options.repo}: HTTP ${res.status}`);
|
|
144
|
+
}
|
|
145
|
+
const tags = (await res.json());
|
|
146
|
+
return tags.map((t) => ({ name: t.name, sha: t.commit.sha }));
|
|
147
|
+
}
|
|
148
|
+
function cachedGitRelease(skillsRoot, version, subdir) {
|
|
149
|
+
const skillsDir = path.join(skillsRoot, version, subdir);
|
|
150
|
+
return fs.existsSync(skillsDir) ? { version, skillsDir, fromCache: true } : null;
|
|
151
|
+
}
|
|
152
|
+
function cleanTag(tag) {
|
|
153
|
+
return tag.replace(/^v/, '');
|
|
154
|
+
}
|
|
155
|
+
function authHeaders(token) {
|
|
156
|
+
return token ? { authorization: `Bearer ${token}` } : {};
|
|
157
|
+
}
|
package/skills/overlay.d.ts
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
import { HarnessSkill } from '../types';
|
|
2
2
|
import { SkillsManifest } from './manifest';
|
|
3
3
|
import { SkillSource } from './source';
|
|
4
|
+
export interface ResolveSkillsOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Called for every `requires:` entry that names a skill not present in any
|
|
7
|
+
* layer (or explicitly excluded everywhere). Missing requirements never
|
|
8
|
+
* throw — a skill may legitimately depend on one the host bundles itself.
|
|
9
|
+
*/
|
|
10
|
+
onMissingRequire?: (skillName: string, requiredName: string) => void;
|
|
11
|
+
}
|
|
4
12
|
/**
|
|
5
13
|
* Resolve the effective skill set from ordered source layers.
|
|
6
14
|
*
|
|
7
15
|
* Sources are applied in manifest order; a later layer replaces an
|
|
8
16
|
* earlier layer's skill of the same name wholesale (all files), and may add
|
|
9
17
|
* new skills. Include/exclude filters apply per layer.
|
|
18
|
+
*
|
|
19
|
+
* After merging, frontmatter `requires:` dependencies are followed
|
|
20
|
+
* transitively: a required skill is pulled in even when a layer's `include`
|
|
21
|
+
* list omits it. Explicit `exclude` entries still win — an excluded skill is
|
|
22
|
+
* never pulled back in by a dependency.
|
|
10
23
|
*/
|
|
11
|
-
export declare function resolveSkills(manifest: SkillsManifest, sources: SkillSource[]): Promise<HarnessSkill[]>;
|
|
24
|
+
export declare function resolveSkills(manifest: SkillsManifest, sources: SkillSource[], options?: ResolveSkillsOptions): Promise<HarnessSkill[]>;
|
package/skills/overlay.js
CHANGED
|
@@ -8,21 +8,47 @@ const manifest_1 = require("./manifest");
|
|
|
8
8
|
* Sources are applied in manifest order; a later layer replaces an
|
|
9
9
|
* earlier layer's skill of the same name wholesale (all files), and may add
|
|
10
10
|
* new skills. Include/exclude filters apply per layer.
|
|
11
|
+
*
|
|
12
|
+
* After merging, frontmatter `requires:` dependencies are followed
|
|
13
|
+
* transitively: a required skill is pulled in even when a layer's `include`
|
|
14
|
+
* list omits it. Explicit `exclude` entries still win — an excluded skill is
|
|
15
|
+
* never pulled back in by a dependency.
|
|
11
16
|
*/
|
|
12
|
-
async function resolveSkills(manifest, sources) {
|
|
17
|
+
async function resolveSkills(manifest, sources, options = {}) {
|
|
13
18
|
(0, manifest_1.validateManifest)(manifest);
|
|
14
19
|
const byName = new Map(sources.map((s) => [s.name, s]));
|
|
15
20
|
const resolved = new Map();
|
|
21
|
+
/** Merged pool ignoring `include` filters (but honoring `exclude`) — the
|
|
22
|
+
* candidates a `requires:` may pull in. */
|
|
23
|
+
const requirePool = new Map();
|
|
16
24
|
for (const ref of manifest.sources) {
|
|
17
25
|
const source = byName.get(ref.name);
|
|
18
26
|
if (!source) {
|
|
19
27
|
throw new Error(`Manifest source ${ref.name} has no registered SkillSource`);
|
|
20
28
|
}
|
|
21
29
|
for (const skill of await source.load()) {
|
|
30
|
+
if (ref.exclude?.includes(skill.name))
|
|
31
|
+
continue;
|
|
32
|
+
requirePool.set(skill.name, skill);
|
|
22
33
|
if (!(0, manifest_1.layerAllowsSkill)(ref, skill.name))
|
|
23
34
|
continue;
|
|
24
35
|
resolved.set(skill.name, skill);
|
|
25
36
|
}
|
|
26
37
|
}
|
|
38
|
+
const queue = [...resolved.values()];
|
|
39
|
+
while (queue.length > 0) {
|
|
40
|
+
const skill = queue.pop();
|
|
41
|
+
for (const requiredName of skill.requires) {
|
|
42
|
+
if (resolved.has(requiredName))
|
|
43
|
+
continue;
|
|
44
|
+
const required = requirePool.get(requiredName);
|
|
45
|
+
if (!required) {
|
|
46
|
+
options.onMissingRequire?.(skill.name, requiredName);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
resolved.set(requiredName, required);
|
|
50
|
+
queue.push(required);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
27
53
|
return [...resolved.values()];
|
|
28
54
|
}
|
package/skills/source.js
CHANGED
|
@@ -62,10 +62,10 @@ class DirectorySkillSource {
|
|
|
62
62
|
if (!fs.existsSync(skillMd))
|
|
63
63
|
continue;
|
|
64
64
|
const raw = fs.readFileSync(skillMd, 'utf8');
|
|
65
|
-
const { name, description } = (0, frontmatter_1.parseFrontmatter)(raw);
|
|
65
|
+
const { name, description, requires } = (0, frontmatter_1.parseFrontmatter)(raw);
|
|
66
66
|
const files = [{ relPath: 'SKILL.md', contents: raw }];
|
|
67
67
|
collectExtraFiles(skillDir, '', files);
|
|
68
|
-
skills.push({ name, description, files, sourceName: this.name });
|
|
68
|
+
skills.push({ name, description, requires, files, sourceName: this.name });
|
|
69
69
|
}
|
|
70
70
|
return skills;
|
|
71
71
|
}
|
package/skills/update-check.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { GitFetchOptions } from './git-fetch';
|
|
1
2
|
import { RegistryOptions } from './registry';
|
|
2
|
-
|
|
3
|
-
pkg: string;
|
|
3
|
+
interface UpdateCheckCommonOptions {
|
|
4
4
|
/** Version currently in use. */
|
|
5
5
|
currentVersion: string;
|
|
6
6
|
/**
|
|
@@ -14,6 +14,11 @@ export interface UpdateCheckOptions extends RegistryOptions {
|
|
|
14
14
|
ttlMs?: number;
|
|
15
15
|
now?: () => number;
|
|
16
16
|
}
|
|
17
|
+
export interface UpdateCheckOptions extends RegistryOptions, UpdateCheckCommonOptions {
|
|
18
|
+
pkg: string;
|
|
19
|
+
}
|
|
20
|
+
export interface GitUpdateCheckOptions extends Pick<GitFetchOptions, 'repo' | 'apiUrl' | 'fetchImpl' | 'token'>, UpdateCheckCommonOptions {
|
|
21
|
+
}
|
|
17
22
|
export interface UpdateCheckResult {
|
|
18
23
|
checkedAt: number;
|
|
19
24
|
/** True when this result came from the cache file, not the registry. */
|
|
@@ -34,3 +39,9 @@ export interface UpdateCheckResult {
|
|
|
34
39
|
* cached result (stale ok) or report "no update" — never throw.
|
|
35
40
|
*/
|
|
36
41
|
export declare function checkForSkillsUpdate(options: UpdateCheckOptions): Promise<UpdateCheckResult>;
|
|
42
|
+
/**
|
|
43
|
+
* Same update check against a GitHub repo's semver tags instead of an npm
|
|
44
|
+
* registry (the skills repo is just a git repository, released by tagging).
|
|
45
|
+
*/
|
|
46
|
+
export declare function checkForSkillsUpdateFromGit(options: GitUpdateCheckOptions): Promise<UpdateCheckResult>;
|
|
47
|
+
export {};
|
package/skills/update-check.js
CHANGED
|
@@ -34,9 +34,11 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.checkForSkillsUpdate = checkForSkillsUpdate;
|
|
37
|
+
exports.checkForSkillsUpdateFromGit = checkForSkillsUpdateFromGit;
|
|
37
38
|
const fs = __importStar(require("fs"));
|
|
38
39
|
const path = __importStar(require("path"));
|
|
39
40
|
const semver = __importStar(require("semver"));
|
|
41
|
+
const git_fetch_1 = require("./git-fetch");
|
|
40
42
|
const registry_1 = require("./registry");
|
|
41
43
|
const DEFAULT_TTL_MS = 24 * 60 * 60 * 1000;
|
|
42
44
|
/**
|
|
@@ -45,6 +47,19 @@ const DEFAULT_TTL_MS = 24 * 60 * 60 * 1000;
|
|
|
45
47
|
* cached result (stale ok) or report "no update" — never throw.
|
|
46
48
|
*/
|
|
47
49
|
async function checkForSkillsUpdate(options) {
|
|
50
|
+
return checkWithLister(options, async () => {
|
|
51
|
+
const packument = await new registry_1.RegistryClient(options).packument(options.pkg);
|
|
52
|
+
return Object.keys(packument.versions);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Same update check against a GitHub repo's semver tags instead of an npm
|
|
57
|
+
* registry (the skills repo is just a git repository, released by tagging).
|
|
58
|
+
*/
|
|
59
|
+
async function checkForSkillsUpdateFromGit(options) {
|
|
60
|
+
return checkWithLister(options, () => (0, git_fetch_1.listGitTagVersions)(options));
|
|
61
|
+
}
|
|
62
|
+
async function checkWithLister(options, listVersions) {
|
|
48
63
|
const now = options.now ?? Date.now;
|
|
49
64
|
const ttl = options.ttlMs ?? DEFAULT_TTL_MS;
|
|
50
65
|
const cached = readCache(options.cacheFile);
|
|
@@ -53,8 +68,7 @@ async function checkForSkillsUpdate(options) {
|
|
|
53
68
|
}
|
|
54
69
|
let versions;
|
|
55
70
|
try {
|
|
56
|
-
|
|
57
|
-
versions = Object.keys(packument.versions).filter((v) => semver.valid(v));
|
|
71
|
+
versions = (await listVersions()).filter((v) => semver.valid(v));
|
|
58
72
|
}
|
|
59
73
|
catch {
|
|
60
74
|
if (cached)
|
package/types.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export interface SkillFile {
|
|
|
15
15
|
export interface HarnessSkill {
|
|
16
16
|
name: string;
|
|
17
17
|
description: string;
|
|
18
|
+
/** Skill names this skill depends on (frontmatter `requires:`). */
|
|
19
|
+
requires: string[];
|
|
18
20
|
files: SkillFile[];
|
|
19
21
|
/** Name of the manifest source layer this skill was resolved from. */
|
|
20
22
|
sourceName: string;
|