@agentic-kit/harness 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 (87) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +176 -0
  3. package/blueprint/blueprint-defaults.d.ts +2 -0
  4. package/blueprint/blueprint-defaults.js +123 -0
  5. package/blueprint/blueprint-schema.d.ts +138 -0
  6. package/blueprint/blueprint-schema.js +86 -0
  7. package/blueprint/field-type.d.ts +25 -0
  8. package/blueprint/field-type.js +99 -0
  9. package/blueprint/internal-policies.d.ts +2 -0
  10. package/blueprint/internal-policies.js +14 -0
  11. package/blueprint/policy-provisioning.d.ts +79 -0
  12. package/blueprint/policy-provisioning.js +570 -0
  13. package/esm/blueprint/blueprint-defaults.d.ts +2 -0
  14. package/esm/blueprint/blueprint-defaults.js +120 -0
  15. package/esm/blueprint/blueprint-schema.d.ts +138 -0
  16. package/esm/blueprint/blueprint-schema.js +83 -0
  17. package/esm/blueprint/field-type.d.ts +25 -0
  18. package/esm/blueprint/field-type.js +94 -0
  19. package/esm/blueprint/internal-policies.d.ts +2 -0
  20. package/esm/blueprint/internal-policies.js +10 -0
  21. package/esm/blueprint/policy-provisioning.d.ts +79 -0
  22. package/esm/blueprint/policy-provisioning.js +553 -0
  23. package/esm/gating/confirm-gate.d.ts +46 -0
  24. package/esm/gating/confirm-gate.js +55 -0
  25. package/esm/gating/decline-guard.d.ts +7 -0
  26. package/esm/gating/decline-guard.js +48 -0
  27. package/esm/gating/preview.d.ts +37 -0
  28. package/esm/gating/preview.js +5 -0
  29. package/esm/gating/prompts.d.ts +8 -0
  30. package/esm/gating/prompts.js +175 -0
  31. package/esm/index.d.ts +20 -0
  32. package/esm/index.js +20 -0
  33. package/esm/skills/fetch.d.ts +31 -0
  34. package/esm/skills/fetch.js +84 -0
  35. package/esm/skills/frontmatter.d.ts +7 -0
  36. package/esm/skills/frontmatter.js +28 -0
  37. package/esm/skills/integrity.d.ts +8 -0
  38. package/esm/skills/integrity.js +28 -0
  39. package/esm/skills/manifest.d.ts +39 -0
  40. package/esm/skills/manifest.js +36 -0
  41. package/esm/skills/materialize.d.ts +13 -0
  42. package/esm/skills/materialize.js +26 -0
  43. package/esm/skills/overlay.d.ts +11 -0
  44. package/esm/skills/overlay.js +25 -0
  45. package/esm/skills/registry.d.ts +36 -0
  46. package/esm/skills/registry.js +30 -0
  47. package/esm/skills/source.d.ts +21 -0
  48. package/esm/skills/source.js +51 -0
  49. package/esm/skills/update-check.d.ts +36 -0
  50. package/esm/skills/update-check.js +74 -0
  51. package/esm/stash.d.ts +20 -0
  52. package/esm/stash.js +19 -0
  53. package/esm/types.d.ts +60 -0
  54. package/esm/types.js +8 -0
  55. package/gating/confirm-gate.d.ts +46 -0
  56. package/gating/confirm-gate.js +58 -0
  57. package/gating/decline-guard.d.ts +7 -0
  58. package/gating/decline-guard.js +52 -0
  59. package/gating/preview.d.ts +37 -0
  60. package/gating/preview.js +6 -0
  61. package/gating/prompts.d.ts +8 -0
  62. package/gating/prompts.js +179 -0
  63. package/index.d.ts +20 -0
  64. package/index.js +36 -0
  65. package/package.json +42 -0
  66. package/skills/fetch.d.ts +31 -0
  67. package/skills/fetch.js +122 -0
  68. package/skills/frontmatter.d.ts +7 -0
  69. package/skills/frontmatter.js +31 -0
  70. package/skills/integrity.d.ts +8 -0
  71. package/skills/integrity.js +64 -0
  72. package/skills/manifest.d.ts +39 -0
  73. package/skills/manifest.js +40 -0
  74. package/skills/materialize.d.ts +13 -0
  75. package/skills/materialize.js +62 -0
  76. package/skills/overlay.d.ts +11 -0
  77. package/skills/overlay.js +28 -0
  78. package/skills/registry.d.ts +36 -0
  79. package/skills/registry.js +34 -0
  80. package/skills/source.d.ts +21 -0
  81. package/skills/source.js +88 -0
  82. package/skills/update-check.d.ts +36 -0
  83. package/skills/update-check.js +110 -0
  84. package/stash.d.ts +20 -0
  85. package/stash.js +55 -0
  86. package/types.d.ts +60 -0
  87. package/types.js +9 -0
@@ -0,0 +1,48 @@
1
+ // Per-session memory of tool calls the user declined in the current agent run.
2
+ // A declined call re-issued with equivalent arguments is blocked without
3
+ // re-prompting the user; the memory clears when a new run starts (agent_start),
4
+ // so a later "go ahead" from the user re-prompts normally. That reset assumes
5
+ // user messages only arrive between runs — if mid-run steering ever lands, a
6
+ // steered approval won't clear this memory and needs its own reset hook.
7
+ function canonicalize(value) {
8
+ if (Array.isArray(value))
9
+ return value.map(canonicalize);
10
+ if (typeof value === 'object' && value !== null) {
11
+ const record = value;
12
+ const sorted = {};
13
+ for (const key of Object.keys(record).sort()) {
14
+ sorted[key] = canonicalize(record[key]);
15
+ }
16
+ return sorted;
17
+ }
18
+ return value;
19
+ }
20
+ function callKey(toolName, input) {
21
+ return `${toolName}::${JSON.stringify(canonicalize(input ?? {}))}`;
22
+ }
23
+ export function buildDeclineReason(toolName) {
24
+ return (`The user reviewed this ${toolName} call and declined it. ` +
25
+ `This is a deliberate decision, not an error — do not call ${toolName} again with the same arguments. ` +
26
+ `Continue the task without it, or tell the user in one sentence what you can't do without it.`);
27
+ }
28
+ function buildRetryBlockReason(toolName) {
29
+ return (`Blocked: the user already declined this exact ${toolName} call in this run, ` +
30
+ `so it was not shown to the user again. Do not issue it again — ` +
31
+ `proceed without it or ask the user how they'd like to continue.`);
32
+ }
33
+ export function createDeclineGuard() {
34
+ const declined = new Set();
35
+ return {
36
+ recordDecline(toolName, input) {
37
+ declined.add(callKey(toolName, input));
38
+ },
39
+ checkRetry(toolName, input) {
40
+ if (!declined.has(callKey(toolName, input)))
41
+ return null;
42
+ return buildRetryBlockReason(toolName);
43
+ },
44
+ clear() {
45
+ declined.clear();
46
+ },
47
+ };
48
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * What a gated action will concretely do (e.g. the rows about to be inserted),
3
+ * so hosts can render it for review before the user approves.
4
+ */
5
+ export type ConfirmPreviewField = {
6
+ name: string;
7
+ type: string;
8
+ isRequired: boolean;
9
+ defaultValue: string | null;
10
+ };
11
+ export type ConfirmPreviewTable = {
12
+ name: string;
13
+ fields: ConfirmPreviewField[];
14
+ policies: string[];
15
+ relationCount: number;
16
+ };
17
+ export type ConfirmPreview = {
18
+ kind: 'records';
19
+ tableName: string;
20
+ rows: Record<string, unknown>[];
21
+ } | {
22
+ kind: 'blueprint';
23
+ tables: ConfirmPreviewTable[];
24
+ } | {
25
+ kind: 'template';
26
+ displayName: string;
27
+ blueprintName?: string;
28
+ tables: ConfirmPreviewTable[];
29
+ } | {
30
+ kind: 'policies';
31
+ tableName: string;
32
+ policies: string[];
33
+ } | {
34
+ kind: 'field';
35
+ tableName: string;
36
+ field: ConfirmPreviewField;
37
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * What a gated action will concretely do (e.g. the rows about to be inserted),
3
+ * so hosts can render it for review before the user approves.
4
+ */
5
+ export {};
@@ -0,0 +1,8 @@
1
+ export declare const MUTATING_DB_TOOLS: Set<string>;
2
+ import type { ConfirmPreview } from './preview';
3
+ export type ConfirmPrompt = {
4
+ title: string;
5
+ message: string;
6
+ preview?: ConfirmPreview;
7
+ };
8
+ export declare function buildConfirmPrompt(toolName: string, input: Record<string, unknown> | undefined): ConfirmPrompt;
@@ -0,0 +1,175 @@
1
+ export const MUTATING_DB_TOOLS = new Set([
2
+ 'provision_database',
3
+ 'provision_blueprint',
4
+ 'add_relation',
5
+ 'delete_table',
6
+ 'create_field',
7
+ 'update_field',
8
+ 'delete_field',
9
+ 'add_policies',
10
+ 'apply_template',
11
+ 'create_template',
12
+ 'update_template',
13
+ 'delete_template',
14
+ 'add_records',
15
+ 'run_codegen',
16
+ ]);
17
+ import { filterInternalPolicies } from '../blueprint/internal-policies';
18
+ function str(input, key) {
19
+ const value = input?.[key];
20
+ return typeof value === 'string' ? value : undefined;
21
+ }
22
+ function recordRows(input) {
23
+ const records = input?.records;
24
+ if (!Array.isArray(records))
25
+ return [];
26
+ return records.filter((r) => typeof r === 'object' && r !== null);
27
+ }
28
+ function obj(value) {
29
+ return typeof value === 'object' && value !== null ? value : undefined;
30
+ }
31
+ function arr(value) {
32
+ return Array.isArray(value) ? value.map(obj).filter((v) => !!v) : [];
33
+ }
34
+ function previewField(raw) {
35
+ return {
36
+ name: typeof raw.name === 'string' ? raw.name : '?',
37
+ type: typeof raw.type === 'string' ? raw.type : '?',
38
+ isRequired: raw.is_required === true,
39
+ defaultValue: typeof raw.default === 'string' ? raw.default : null,
40
+ };
41
+ }
42
+ function blueprintTables(input) {
43
+ const definition = obj(input?.definition);
44
+ if (!definition)
45
+ return [];
46
+ const relations = arr(definition.relations);
47
+ return arr(definition.tables).map((table) => {
48
+ const tableName = typeof table.table_name === 'string' ? table.table_name : '?';
49
+ return {
50
+ name: tableName,
51
+ fields: arr(table.fields).map(previewField),
52
+ policies: filterInternalPolicies(arr(table.policies)
53
+ .map((policy) => (typeof policy.$type === 'string' ? policy.$type : null))
54
+ .filter((p) => !!p)),
55
+ relationCount: relations.filter((r) => r.source_table === tableName).length,
56
+ };
57
+ });
58
+ }
59
+ function policyTypes(input) {
60
+ return filterInternalPolicies(arr(input?.policies)
61
+ .map((policy) => (typeof policy.policy_type === 'string' ? policy.policy_type : null))
62
+ .filter((p) => !!p));
63
+ }
64
+ export function buildConfirmPrompt(toolName, input) {
65
+ switch (toolName) {
66
+ case 'provision_database': {
67
+ const name = str(input, 'database_name') ?? 'new database';
68
+ return {
69
+ title: 'Provision database?',
70
+ message: `Sign up an owner and provision a new Constructive database "${name}" (standard module set), then write credentials to the project .env.`,
71
+ };
72
+ }
73
+ case 'provision_blueprint': {
74
+ const name = str(input, 'name') ?? 'new schema';
75
+ const tables = blueprintTables(input);
76
+ const count = tables.length;
77
+ return {
78
+ title: 'Create tables?',
79
+ message: `Provision blueprint "${name}"${count ? ` (${count} table${count === 1 ? '' : 's'})` : ''} in the project database.`,
80
+ preview: count > 0 ? { kind: 'blueprint', tables } : undefined,
81
+ };
82
+ }
83
+ case 'add_relation': {
84
+ const source = str(input, 'source_table') ?? '?';
85
+ const target = str(input, 'target_table') ?? '?';
86
+ const isManyToMany = str(input, 'relation_type') === 'many_to_many';
87
+ const message = isManyToMany
88
+ ? `Create a junction table "${str(input, 'junction_table_name') ?? '?'}" linking existing tables "${source}" ↔ "${target}".`
89
+ : `Add a foreign-key column "${str(input, 'field_name') ?? '?'}" on existing table "${source}" referencing "${target}".`;
90
+ return { title: 'Add relation?', message };
91
+ }
92
+ case 'delete_table':
93
+ return {
94
+ title: 'Delete table?',
95
+ message: `Permanently delete the table "${str(input, 'table_name') ?? '?'}" and its data.`,
96
+ };
97
+ case 'create_field': {
98
+ const tableName = str(input, 'table_name') ?? '?';
99
+ const fieldName = str(input, 'field_name') ?? '?';
100
+ return {
101
+ title: 'Add field?',
102
+ message: `Add field "${fieldName}" to table "${tableName}".`,
103
+ preview: {
104
+ kind: 'field',
105
+ tableName,
106
+ field: {
107
+ name: fieldName,
108
+ type: str(input, 'type') ?? '?',
109
+ isRequired: input?.is_required === true,
110
+ defaultValue: str(input, 'default_value') ?? null,
111
+ },
112
+ },
113
+ };
114
+ }
115
+ case 'update_field':
116
+ return {
117
+ title: 'Update field?',
118
+ message: `Modify field "${str(input, 'field_name') ?? '?'}" on table "${str(input, 'table_name') ?? '?'}".`,
119
+ };
120
+ case 'delete_field':
121
+ return {
122
+ title: 'Delete field?',
123
+ message: `Permanently delete field "${str(input, 'field_name') ?? '?'}" from table "${str(input, 'table_name') ?? '?'}".`,
124
+ };
125
+ case 'add_policies': {
126
+ const tableName = str(input, 'table_name') ?? '?';
127
+ const policies = policyTypes(input);
128
+ const count = policies.length;
129
+ return {
130
+ title: 'Add policies?',
131
+ message: `Add ${count || ''} RLS ${count === 1 ? 'policy' : 'policies'} to table "${tableName}".`,
132
+ preview: count > 0 ? { kind: 'policies', tableName, policies } : undefined,
133
+ };
134
+ }
135
+ case 'apply_template':
136
+ return {
137
+ title: 'Apply template?',
138
+ message: `Apply blueprint template "${str(input, 'templateName') ?? '?'}" to the project database.`,
139
+ };
140
+ case 'create_template': {
141
+ const source = str(input, 'blueprintName');
142
+ return {
143
+ title: 'Create template?',
144
+ message: `Create reusable template "${str(input, 'displayName') ?? '?'}" in the catalog from ${source ? `blueprint "${source}"` : 'the latest blueprint'}.`,
145
+ };
146
+ }
147
+ case 'update_template':
148
+ return {
149
+ title: 'Update template?',
150
+ message: `Update blueprint template "${str(input, 'templateName') ?? '?'}".`,
151
+ };
152
+ case 'delete_template':
153
+ return {
154
+ title: 'Delete template?',
155
+ message: `Permanently delete blueprint template "${str(input, 'templateName') ?? '?'}".`,
156
+ };
157
+ case 'add_records': {
158
+ const rows = recordRows(input);
159
+ const count = rows.length;
160
+ const tableName = str(input, 'table_name') ?? '?';
161
+ return {
162
+ title: 'Add records?',
163
+ message: `Insert ${count || ''} row${count === 1 ? '' : 's'} into table "${tableName}".`,
164
+ preview: count > 0 ? { kind: 'records', tableName, rows } : undefined,
165
+ };
166
+ }
167
+ case 'run_codegen':
168
+ return {
169
+ title: 'Run codegen?',
170
+ message: 'Generate the typed GraphQL SDK in packages/app (upgrade codegen, run it, normalize barrels).',
171
+ };
172
+ default:
173
+ return { title: 'Run tool?', message: `Allow "${toolName}" to run?` };
174
+ }
175
+ }
package/esm/index.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ export * from './types';
2
+ export * from './stash';
3
+ export * from './skills/frontmatter';
4
+ export * from './skills/manifest';
5
+ export * from './skills/source';
6
+ export * from './skills/overlay';
7
+ export * from './skills/materialize';
8
+ export * from './skills/registry';
9
+ export * from './skills/integrity';
10
+ export * from './skills/fetch';
11
+ export * from './skills/update-check';
12
+ export * from './gating/preview';
13
+ export * from './gating/decline-guard';
14
+ export * from './gating/prompts';
15
+ export * from './gating/confirm-gate';
16
+ export * from './blueprint/field-type';
17
+ export * from './blueprint/internal-policies';
18
+ export * from './blueprint/policy-provisioning';
19
+ export * from './blueprint/blueprint-schema';
20
+ export * from './blueprint/blueprint-defaults';
package/esm/index.js ADDED
@@ -0,0 +1,20 @@
1
+ export * from './types';
2
+ export * from './stash';
3
+ export * from './skills/frontmatter';
4
+ export * from './skills/manifest';
5
+ export * from './skills/source';
6
+ export * from './skills/overlay';
7
+ export * from './skills/materialize';
8
+ export * from './skills/registry';
9
+ export * from './skills/integrity';
10
+ export * from './skills/fetch';
11
+ export * from './skills/update-check';
12
+ export * from './gating/preview';
13
+ export * from './gating/decline-guard';
14
+ export * from './gating/prompts';
15
+ export * from './gating/confirm-gate';
16
+ export * from './blueprint/field-type';
17
+ export * from './blueprint/internal-policies';
18
+ export * from './blueprint/policy-provisioning';
19
+ export * from './blueprint/blueprint-schema';
20
+ export * from './blueprint/blueprint-defaults';
@@ -0,0 +1,31 @@
1
+ import { Packument, RegistryOptions } from './registry';
2
+ export interface FetchReleaseOptions extends RegistryOptions {
3
+ /** npm package that ships the skills, e.g. `@constructive-io/skills`. */
4
+ pkg: string;
5
+ /**
6
+ * Version pin: exact version, semver range, or dist-tag. Ranges resolve to
7
+ * the highest satisfying published version.
8
+ */
9
+ pin: string;
10
+ /** Root directory releases unpack into: `<skillsRoot>/<version>/`. */
11
+ skillsRoot: string;
12
+ /** Path of the skills tree inside the package (default `.agents/skills`). */
13
+ packageSubdir?: string;
14
+ }
15
+ export interface FetchedRelease {
16
+ version: string;
17
+ /** Directory containing `<skill>/SKILL.md` folders, ready for DirectorySkillSource. */
18
+ skillsDir: string;
19
+ /** True when the release was already on disk and no download happened. */
20
+ fromCache: boolean;
21
+ }
22
+ export declare function resolvePin(packument: Packument, pin: string): string;
23
+ /**
24
+ * Ensure a skills release is unpacked under `<skillsRoot>/<version>/` and
25
+ * return its skills directory. Downloads at most once per version: an already
26
+ * unpacked release is reused without touching the network, so a previously
27
+ * fetched version keeps working offline.
28
+ */
29
+ export declare function fetchSkillsRelease(options: FetchReleaseOptions): Promise<FetchedRelease>;
30
+ /** Newest already-downloaded version under `skillsRoot`, or null. */
31
+ export declare function latestLocalRelease(skillsRoot: string, subdir?: string): FetchedRelease | null;
@@ -0,0 +1,84 @@
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
+ import { verifyIntegrity } from './integrity';
7
+ import { RegistryClient } from './registry';
8
+ export function resolvePin(packument, pin) {
9
+ const distTag = packument['dist-tags'][pin];
10
+ if (distTag)
11
+ return distTag;
12
+ if (packument.versions[pin])
13
+ return pin;
14
+ const versions = Object.keys(packument.versions);
15
+ const resolved = semver.maxSatisfying(versions, pin);
16
+ if (!resolved) {
17
+ throw new Error(`No published version of ${packument.name} satisfies pin "${pin}"`);
18
+ }
19
+ return resolved;
20
+ }
21
+ /**
22
+ * Ensure a skills release is unpacked under `<skillsRoot>/<version>/` and
23
+ * return its skills directory. Downloads at most once per version: an already
24
+ * unpacked release is reused without touching the network, so a previously
25
+ * fetched version keeps working offline.
26
+ */
27
+ export async function fetchSkillsRelease(options) {
28
+ const subdir = options.packageSubdir ?? '.agents/skills';
29
+ const client = new RegistryClient(options);
30
+ const exactPin = semver.valid(options.pin);
31
+ if (exactPin) {
32
+ const cached = cachedRelease(options.skillsRoot, exactPin, subdir);
33
+ if (cached)
34
+ return cached;
35
+ }
36
+ const packument = await client.packument(options.pkg);
37
+ const version = resolvePin(packument, options.pin);
38
+ const cached = cachedRelease(options.skillsRoot, version, subdir);
39
+ if (cached)
40
+ return cached;
41
+ const release = packument.versions[version];
42
+ const data = await client.tarball(release.dist.tarball);
43
+ verifyIntegrity(data, release.dist);
44
+ const versionDir = path.join(options.skillsRoot, version);
45
+ const staging = fs.mkdtempSync(path.join(os.tmpdir(), 'harness-skills-'));
46
+ try {
47
+ const tarballPath = path.join(staging, 'release.tgz');
48
+ fs.writeFileSync(tarballPath, data);
49
+ const unpackDir = path.join(staging, 'package');
50
+ fs.mkdirSync(unpackDir);
51
+ await tar.extract({ file: tarballPath, cwd: unpackDir, strip: 1 });
52
+ fs.mkdirSync(path.dirname(versionDir), { recursive: true });
53
+ fs.rmSync(versionDir, { recursive: true, force: true });
54
+ fs.renameSync(unpackDir, versionDir);
55
+ }
56
+ finally {
57
+ fs.rmSync(staging, { recursive: true, force: true });
58
+ }
59
+ const skillsDir = path.join(versionDir, subdir);
60
+ if (!fs.existsSync(skillsDir)) {
61
+ throw new Error(`Release ${options.pkg}@${version} has no ${subdir} directory`);
62
+ }
63
+ return { version, skillsDir, fromCache: false };
64
+ }
65
+ /** Newest already-downloaded version under `skillsRoot`, or null. */
66
+ export function latestLocalRelease(skillsRoot, subdir = '.agents/skills') {
67
+ if (!fs.existsSync(skillsRoot))
68
+ return null;
69
+ const versions = fs
70
+ .readdirSync(skillsRoot)
71
+ .filter((name) => semver.valid(name) && fs.existsSync(path.join(skillsRoot, name, subdir)))
72
+ .sort(semver.rcompare);
73
+ if (versions.length === 0)
74
+ return null;
75
+ return {
76
+ version: versions[0],
77
+ skillsDir: path.join(skillsRoot, versions[0], subdir),
78
+ fromCache: true,
79
+ };
80
+ }
81
+ function cachedRelease(skillsRoot, version, subdir) {
82
+ const skillsDir = path.join(skillsRoot, version, subdir);
83
+ return fs.existsSync(skillsDir) ? { version, skillsDir, fromCache: true } : null;
84
+ }
@@ -0,0 +1,7 @@
1
+ export interface ParsedSkillFrontmatter {
2
+ name: string;
3
+ description: string;
4
+ body: string;
5
+ }
6
+ /** Parse the minimal YAML frontmatter (`name`, `description`) of a SKILL.md. */
7
+ export declare function parseFrontmatter(raw: string): ParsedSkillFrontmatter;
@@ -0,0 +1,28 @@
1
+ function unquoteScalar(value) {
2
+ if (value && value.length >= 2 && value.startsWith('"') && value.endsWith('"')) {
3
+ try {
4
+ return JSON.parse(value);
5
+ }
6
+ catch {
7
+ return value;
8
+ }
9
+ }
10
+ return value;
11
+ }
12
+ /** Parse the minimal YAML frontmatter (`name`, `description`) of a SKILL.md. */
13
+ export function parseFrontmatter(raw) {
14
+ const match = raw.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/);
15
+ if (!match) {
16
+ throw new Error('Skill is missing YAML frontmatter (expected leading `---` block)');
17
+ }
18
+ const [, fm, body] = match;
19
+ const nameMatch = fm.match(/(?:^|\n)name:\s*(.+?)\s*(?:\n|$)/);
20
+ const descMatch = fm.match(/(?:^|\n)description:\s*(.+?)\s*(?:\n|$)/);
21
+ const name = unquoteScalar(nameMatch?.[1]?.trim());
22
+ const description = unquoteScalar(descMatch?.[1]?.trim());
23
+ if (!name)
24
+ throw new Error('Skill frontmatter missing `name`');
25
+ if (!description)
26
+ throw new Error('Skill frontmatter missing `description`');
27
+ return { name, description, body };
28
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Verify an npm SRI `integrity` string (`sha512-<base64>`, `sha256-…`) or a
3
+ * legacy hex `shasum` (sha1) against tarball bytes. Throws on mismatch.
4
+ */
5
+ export declare function verifyIntegrity(data: Buffer, { integrity, shasum }: {
6
+ integrity?: string;
7
+ shasum?: string;
8
+ }): void;
@@ -0,0 +1,28 @@
1
+ import * as crypto from 'crypto';
2
+ /**
3
+ * Verify an npm SRI `integrity` string (`sha512-<base64>`, `sha256-…`) or a
4
+ * legacy hex `shasum` (sha1) against tarball bytes. Throws on mismatch.
5
+ */
6
+ export function verifyIntegrity(data, { integrity, shasum }) {
7
+ if (integrity) {
8
+ const dash = integrity.indexOf('-');
9
+ if (dash === -1) {
10
+ throw new Error(`Malformed integrity string: ${integrity}`);
11
+ }
12
+ const algorithm = integrity.slice(0, dash);
13
+ const expected = integrity.slice(dash + 1);
14
+ const actual = crypto.createHash(algorithm).update(data).digest('base64');
15
+ if (actual !== expected) {
16
+ throw new Error(`Integrity check failed (${algorithm}): expected ${expected}, got ${actual}`);
17
+ }
18
+ return;
19
+ }
20
+ if (shasum) {
21
+ const actual = crypto.createHash('sha1').update(data).digest('hex');
22
+ if (actual !== shasum) {
23
+ throw new Error(`Integrity check failed (sha1): expected ${shasum}, got ${actual}`);
24
+ }
25
+ return;
26
+ }
27
+ throw new Error('Release has no integrity metadata to verify');
28
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Ordered-overlay skill source manifest.
3
+ *
4
+ * Skills are resolved from an ordered list of sources; later sources override
5
+ * or add skills by name (last-write-wins). Typical order:
6
+ *
7
+ * 1. `constructive-skills` at a pinned release (hardened public base)
8
+ * 2. team overlay repo(s) (skills being iterated on)
9
+ * 3. private known-gaps overlay (internal deployments only)
10
+ *
11
+ * Each layer keeps its own pin so the base can harden slowly while overlays
12
+ * stay fresh; promoting an overlay skill upstream = moving the file down a
13
+ * layer.
14
+ */
15
+ export interface SkillSourceRef {
16
+ /** Unique layer name, e.g. `constructive-skills`, `team-overlay`. */
17
+ name: string;
18
+ /**
19
+ * Version/SHA pin for the layer. For npm sources a semver or dist-tag; for
20
+ * git sources a commit SHA; for local directories informational only.
21
+ */
22
+ pin?: string;
23
+ /** Restrict this layer to an explicit set of skill names (default: all). */
24
+ include?: string[];
25
+ /** Skill names to skip from this layer. */
26
+ exclude?: string[];
27
+ }
28
+ export interface SkillsManifest {
29
+ /** Ordered layers, lowest precedence first. */
30
+ sources: SkillSourceRef[];
31
+ /**
32
+ * Semver range of the skills release the installed harness tool code
33
+ * supports. Updaters must not adopt releases outside this range, so skill
34
+ * docs can never drift ahead of installed tool signatures.
35
+ */
36
+ compatibleSkillsRange?: string;
37
+ }
38
+ export declare function validateManifest(manifest: SkillsManifest): void;
39
+ export declare function layerAllowsSkill(source: SkillSourceRef, skillName: string): boolean;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Ordered-overlay skill source manifest.
3
+ *
4
+ * Skills are resolved from an ordered list of sources; later sources override
5
+ * or add skills by name (last-write-wins). Typical order:
6
+ *
7
+ * 1. `constructive-skills` at a pinned release (hardened public base)
8
+ * 2. team overlay repo(s) (skills being iterated on)
9
+ * 3. private known-gaps overlay (internal deployments only)
10
+ *
11
+ * Each layer keeps its own pin so the base can harden slowly while overlays
12
+ * stay fresh; promoting an overlay skill upstream = moving the file down a
13
+ * layer.
14
+ */
15
+ export function validateManifest(manifest) {
16
+ if (!Array.isArray(manifest.sources) || manifest.sources.length === 0) {
17
+ throw new Error('Skills manifest must declare at least one source layer');
18
+ }
19
+ const seen = new Set();
20
+ for (const source of manifest.sources) {
21
+ if (!source.name) {
22
+ throw new Error('Every manifest source needs a unique `name`');
23
+ }
24
+ if (seen.has(source.name)) {
25
+ throw new Error(`Duplicate manifest source name: ${source.name}`);
26
+ }
27
+ seen.add(source.name);
28
+ }
29
+ }
30
+ export function layerAllowsSkill(source, skillName) {
31
+ if (source.exclude?.includes(skillName))
32
+ return false;
33
+ if (source.include && !source.include.includes(skillName))
34
+ return false;
35
+ return true;
36
+ }
@@ -0,0 +1,13 @@
1
+ import { HarnessSkill } from '../types';
2
+ export interface MaterializeOptions {
3
+ /**
4
+ * `{{VAR}}` substitutions applied to every skill file, e.g.
5
+ * `{ HARNESS_TEMPLATES_DIR: '/abs/path' }`. Host adapters supply real paths.
6
+ */
7
+ templateVars?: Record<string, string>;
8
+ }
9
+ /**
10
+ * Write a resolved skill set to `<targetDir>/<skill-name>/…`, replacing any
11
+ * previous contents so removed skills do not linger.
12
+ */
13
+ export declare function materializeSkills(targetDir: string, skills: HarnessSkill[], options?: MaterializeOptions): string[];
@@ -0,0 +1,26 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ /**
4
+ * Write a resolved skill set to `<targetDir>/<skill-name>/…`, replacing any
5
+ * previous contents so removed skills do not linger.
6
+ */
7
+ export function materializeSkills(targetDir, skills, options = {}) {
8
+ fs.rmSync(targetDir, { recursive: true, force: true });
9
+ fs.mkdirSync(targetDir, { recursive: true });
10
+ const written = [];
11
+ for (const skill of skills) {
12
+ const skillDir = path.join(targetDir, skill.name);
13
+ for (const file of skill.files) {
14
+ const dest = path.join(skillDir, file.relPath);
15
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
16
+ fs.writeFileSync(dest, substitute(file.contents, options.templateVars));
17
+ }
18
+ written.push(skillDir);
19
+ }
20
+ return written;
21
+ }
22
+ function substitute(contents, vars) {
23
+ if (!vars)
24
+ return contents;
25
+ return contents.replace(/\{\{([A-Z0-9_]+)\}\}/g, (whole, key) => key in vars ? vars[key] : whole);
26
+ }
@@ -0,0 +1,11 @@
1
+ import { HarnessSkill } from '../types';
2
+ import { SkillsManifest } from './manifest';
3
+ import { SkillSource } from './source';
4
+ /**
5
+ * Resolve the effective skill set from ordered source layers.
6
+ *
7
+ * Sources are applied in manifest order; a later layer replaces an
8
+ * earlier layer's skill of the same name wholesale (all files), and may add
9
+ * new skills. Include/exclude filters apply per layer.
10
+ */
11
+ export declare function resolveSkills(manifest: SkillsManifest, sources: SkillSource[]): Promise<HarnessSkill[]>;