@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.
- package/LICENSE +23 -0
- package/README.md +176 -0
- package/blueprint/blueprint-defaults.d.ts +2 -0
- package/blueprint/blueprint-defaults.js +123 -0
- package/blueprint/blueprint-schema.d.ts +138 -0
- package/blueprint/blueprint-schema.js +86 -0
- package/blueprint/field-type.d.ts +25 -0
- package/blueprint/field-type.js +99 -0
- package/blueprint/internal-policies.d.ts +2 -0
- package/blueprint/internal-policies.js +14 -0
- package/blueprint/policy-provisioning.d.ts +79 -0
- package/blueprint/policy-provisioning.js +570 -0
- package/esm/blueprint/blueprint-defaults.d.ts +2 -0
- package/esm/blueprint/blueprint-defaults.js +120 -0
- package/esm/blueprint/blueprint-schema.d.ts +138 -0
- package/esm/blueprint/blueprint-schema.js +83 -0
- package/esm/blueprint/field-type.d.ts +25 -0
- package/esm/blueprint/field-type.js +94 -0
- package/esm/blueprint/internal-policies.d.ts +2 -0
- package/esm/blueprint/internal-policies.js +10 -0
- package/esm/blueprint/policy-provisioning.d.ts +79 -0
- package/esm/blueprint/policy-provisioning.js +553 -0
- package/esm/gating/confirm-gate.d.ts +46 -0
- package/esm/gating/confirm-gate.js +55 -0
- package/esm/gating/decline-guard.d.ts +7 -0
- package/esm/gating/decline-guard.js +48 -0
- package/esm/gating/preview.d.ts +37 -0
- package/esm/gating/preview.js +5 -0
- package/esm/gating/prompts.d.ts +8 -0
- package/esm/gating/prompts.js +175 -0
- package/esm/index.d.ts +20 -0
- package/esm/index.js +20 -0
- package/esm/skills/fetch.d.ts +31 -0
- package/esm/skills/fetch.js +84 -0
- package/esm/skills/frontmatter.d.ts +7 -0
- package/esm/skills/frontmatter.js +28 -0
- package/esm/skills/integrity.d.ts +8 -0
- package/esm/skills/integrity.js +28 -0
- package/esm/skills/manifest.d.ts +39 -0
- package/esm/skills/manifest.js +36 -0
- package/esm/skills/materialize.d.ts +13 -0
- package/esm/skills/materialize.js +26 -0
- package/esm/skills/overlay.d.ts +11 -0
- package/esm/skills/overlay.js +25 -0
- package/esm/skills/registry.d.ts +36 -0
- package/esm/skills/registry.js +30 -0
- package/esm/skills/source.d.ts +21 -0
- package/esm/skills/source.js +51 -0
- package/esm/skills/update-check.d.ts +36 -0
- package/esm/skills/update-check.js +74 -0
- package/esm/stash.d.ts +20 -0
- package/esm/stash.js +19 -0
- package/esm/types.d.ts +60 -0
- package/esm/types.js +8 -0
- package/gating/confirm-gate.d.ts +46 -0
- package/gating/confirm-gate.js +58 -0
- package/gating/decline-guard.d.ts +7 -0
- package/gating/decline-guard.js +52 -0
- package/gating/preview.d.ts +37 -0
- package/gating/preview.js +6 -0
- package/gating/prompts.d.ts +8 -0
- package/gating/prompts.js +179 -0
- package/index.d.ts +20 -0
- package/index.js +36 -0
- package/package.json +42 -0
- package/skills/fetch.d.ts +31 -0
- package/skills/fetch.js +122 -0
- package/skills/frontmatter.d.ts +7 -0
- package/skills/frontmatter.js +31 -0
- package/skills/integrity.d.ts +8 -0
- package/skills/integrity.js +64 -0
- package/skills/manifest.d.ts +39 -0
- package/skills/manifest.js +40 -0
- package/skills/materialize.d.ts +13 -0
- package/skills/materialize.js +62 -0
- package/skills/overlay.d.ts +11 -0
- package/skills/overlay.js +28 -0
- package/skills/registry.d.ts +36 -0
- package/skills/registry.js +34 -0
- package/skills/source.d.ts +21 -0
- package/skills/source.js +88 -0
- package/skills/update-check.d.ts +36 -0
- package/skills/update-check.js +110 -0
- package/stash.d.ts +20 -0
- package/stash.js +55 -0
- package/types.d.ts +60 -0
- package/types.js +9 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { layerAllowsSkill, validateManifest } from './manifest';
|
|
2
|
+
/**
|
|
3
|
+
* Resolve the effective skill set from ordered source layers.
|
|
4
|
+
*
|
|
5
|
+
* Sources are applied in manifest order; a later layer replaces an
|
|
6
|
+
* earlier layer's skill of the same name wholesale (all files), and may add
|
|
7
|
+
* new skills. Include/exclude filters apply per layer.
|
|
8
|
+
*/
|
|
9
|
+
export async function resolveSkills(manifest, sources) {
|
|
10
|
+
validateManifest(manifest);
|
|
11
|
+
const byName = new Map(sources.map((s) => [s.name, s]));
|
|
12
|
+
const resolved = new Map();
|
|
13
|
+
for (const ref of manifest.sources) {
|
|
14
|
+
const source = byName.get(ref.name);
|
|
15
|
+
if (!source) {
|
|
16
|
+
throw new Error(`Manifest source ${ref.name} has no registered SkillSource`);
|
|
17
|
+
}
|
|
18
|
+
for (const skill of await source.load()) {
|
|
19
|
+
if (!layerAllowsSkill(ref, skill.name))
|
|
20
|
+
continue;
|
|
21
|
+
resolved.set(skill.name, skill);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return [...resolved.values()];
|
|
25
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal npm registry client for skill releases. HTTP is injectable so
|
|
3
|
+
* hosts can add proxies/auth and tests can run offline.
|
|
4
|
+
*/
|
|
5
|
+
export type FetchLike = (url: string, init?: {
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
}) => Promise<{
|
|
8
|
+
ok: boolean;
|
|
9
|
+
status: number;
|
|
10
|
+
json(): Promise<unknown>;
|
|
11
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
12
|
+
}>;
|
|
13
|
+
export interface RegistryOptions {
|
|
14
|
+
registryUrl?: string;
|
|
15
|
+
fetchImpl?: FetchLike;
|
|
16
|
+
}
|
|
17
|
+
export interface PackumentVersion {
|
|
18
|
+
version: string;
|
|
19
|
+
dist: {
|
|
20
|
+
tarball: string;
|
|
21
|
+
integrity?: string;
|
|
22
|
+
shasum?: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export interface Packument {
|
|
26
|
+
name: string;
|
|
27
|
+
'dist-tags': Record<string, string>;
|
|
28
|
+
versions: Record<string, PackumentVersion>;
|
|
29
|
+
}
|
|
30
|
+
export declare class RegistryClient {
|
|
31
|
+
private readonly registryUrl;
|
|
32
|
+
private readonly fetchImpl;
|
|
33
|
+
constructor(options?: RegistryOptions);
|
|
34
|
+
packument(pkg: string): Promise<Packument>;
|
|
35
|
+
tarball(url: string): Promise<Buffer>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal npm registry client for skill releases. HTTP is injectable so
|
|
3
|
+
* hosts can add proxies/auth and tests can run offline.
|
|
4
|
+
*/
|
|
5
|
+
const DEFAULT_REGISTRY = 'https://registry.npmjs.org';
|
|
6
|
+
export class RegistryClient {
|
|
7
|
+
registryUrl;
|
|
8
|
+
fetchImpl;
|
|
9
|
+
constructor(options = {}) {
|
|
10
|
+
this.registryUrl = (options.registryUrl ?? DEFAULT_REGISTRY).replace(/\/$/, '');
|
|
11
|
+
this.fetchImpl = options.fetchImpl ?? fetch;
|
|
12
|
+
}
|
|
13
|
+
async packument(pkg) {
|
|
14
|
+
const url = `${this.registryUrl}/${pkg.replace('/', '%2f')}`;
|
|
15
|
+
const res = await this.fetchImpl(url, {
|
|
16
|
+
headers: { accept: 'application/vnd.npm.install-v1+json' },
|
|
17
|
+
});
|
|
18
|
+
if (!res.ok) {
|
|
19
|
+
throw new Error(`Registry request failed for ${pkg}: HTTP ${res.status}`);
|
|
20
|
+
}
|
|
21
|
+
return (await res.json());
|
|
22
|
+
}
|
|
23
|
+
async tarball(url) {
|
|
24
|
+
const res = await this.fetchImpl(url);
|
|
25
|
+
if (!res.ok) {
|
|
26
|
+
throw new Error(`Tarball download failed: HTTP ${res.status} (${url})`);
|
|
27
|
+
}
|
|
28
|
+
return Buffer.from(await res.arrayBuffer());
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { HarnessSkill } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* A resolvable layer of skills. Implementations: local directory (vendored
|
|
4
|
+
* snapshot, git checkout, unpacked npm release). Network fetchers resolve a
|
|
5
|
+
* release into a local directory and hand it to `DirectorySkillSource`.
|
|
6
|
+
*/
|
|
7
|
+
export interface SkillSource {
|
|
8
|
+
name: string;
|
|
9
|
+
load(): Promise<HarnessSkill[]>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Loads skills from a directory of `<skill-name>/SKILL.md` folders — the
|
|
13
|
+
* agentskills.io layout used by `constructive-skills` (`.agents/skills/`) and
|
|
14
|
+
* by unpacked release tarballs.
|
|
15
|
+
*/
|
|
16
|
+
export declare class DirectorySkillSource implements SkillSource {
|
|
17
|
+
readonly name: string;
|
|
18
|
+
private readonly dir;
|
|
19
|
+
constructor(name: string, dir: string);
|
|
20
|
+
load(): Promise<HarnessSkill[]>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { parseFrontmatter } from './frontmatter';
|
|
4
|
+
/**
|
|
5
|
+
* Loads skills from a directory of `<skill-name>/SKILL.md` folders — the
|
|
6
|
+
* agentskills.io layout used by `constructive-skills` (`.agents/skills/`) and
|
|
7
|
+
* by unpacked release tarballs.
|
|
8
|
+
*/
|
|
9
|
+
export class DirectorySkillSource {
|
|
10
|
+
name;
|
|
11
|
+
dir;
|
|
12
|
+
constructor(name, dir) {
|
|
13
|
+
this.name = name;
|
|
14
|
+
this.dir = dir;
|
|
15
|
+
}
|
|
16
|
+
async load() {
|
|
17
|
+
if (!fs.existsSync(this.dir)) {
|
|
18
|
+
throw new Error(`Skill source directory not found: ${this.dir}`);
|
|
19
|
+
}
|
|
20
|
+
const skills = [];
|
|
21
|
+
for (const entry of fs.readdirSync(this.dir, { withFileTypes: true })) {
|
|
22
|
+
if (!entry.isDirectory())
|
|
23
|
+
continue;
|
|
24
|
+
const skillDir = path.join(this.dir, entry.name);
|
|
25
|
+
const skillMd = path.join(skillDir, 'SKILL.md');
|
|
26
|
+
if (!fs.existsSync(skillMd))
|
|
27
|
+
continue;
|
|
28
|
+
const raw = fs.readFileSync(skillMd, 'utf8');
|
|
29
|
+
const { name, description } = parseFrontmatter(raw);
|
|
30
|
+
const files = [{ relPath: 'SKILL.md', contents: raw }];
|
|
31
|
+
collectExtraFiles(skillDir, '', files);
|
|
32
|
+
skills.push({ name, description, files, sourceName: this.name });
|
|
33
|
+
}
|
|
34
|
+
return skills;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function collectExtraFiles(root, rel, out) {
|
|
38
|
+
const dir = path.join(root, rel);
|
|
39
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
40
|
+
const entryRel = rel ? path.join(rel, entry.name) : entry.name;
|
|
41
|
+
if (entry.isDirectory()) {
|
|
42
|
+
collectExtraFiles(root, entryRel, out);
|
|
43
|
+
}
|
|
44
|
+
else if (entry.isFile() && entryRel !== 'SKILL.md') {
|
|
45
|
+
out.push({
|
|
46
|
+
relPath: entryRel,
|
|
47
|
+
contents: fs.readFileSync(path.join(root, entryRel), 'utf8'),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { RegistryOptions } from './registry';
|
|
2
|
+
export interface UpdateCheckOptions extends RegistryOptions {
|
|
3
|
+
pkg: string;
|
|
4
|
+
/** Version currently in use. */
|
|
5
|
+
currentVersion: string;
|
|
6
|
+
/**
|
|
7
|
+
* Semver range the installed harness supports (`compatibleSkillsRange`).
|
|
8
|
+
* Newer releases outside this range are reported but never recommended.
|
|
9
|
+
*/
|
|
10
|
+
compatibleRange?: string;
|
|
11
|
+
/** Cache file (e.g. `harnessDirs().updateCheckFile`). */
|
|
12
|
+
cacheFile: string;
|
|
13
|
+
/** Re-query the registry only after this long (default 24h). */
|
|
14
|
+
ttlMs?: number;
|
|
15
|
+
now?: () => number;
|
|
16
|
+
}
|
|
17
|
+
export interface UpdateCheckResult {
|
|
18
|
+
checkedAt: number;
|
|
19
|
+
/** True when this result came from the cache file, not the registry. */
|
|
20
|
+
fromCache: boolean;
|
|
21
|
+
currentVersion: string;
|
|
22
|
+
/** Newest published version overall. */
|
|
23
|
+
latestVersion: string;
|
|
24
|
+
/** Newest version inside compatibleRange — the one an updater may adopt. */
|
|
25
|
+
latestCompatible: string | null;
|
|
26
|
+
/** True when latestCompatible is newer than currentVersion. */
|
|
27
|
+
updateAvailable: boolean;
|
|
28
|
+
/** True when a newer release exists but only outside compatibleRange. */
|
|
29
|
+
harnessUpgradeRequired: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Check the registry for newer skill releases, caching results on disk so
|
|
33
|
+
* repeated sessions don't hit the network. Registry failures fall back to the
|
|
34
|
+
* cached result (stale ok) or report "no update" — never throw.
|
|
35
|
+
*/
|
|
36
|
+
export declare function checkForSkillsUpdate(options: UpdateCheckOptions): Promise<UpdateCheckResult>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as semver from 'semver';
|
|
4
|
+
import { RegistryClient } from './registry';
|
|
5
|
+
const DEFAULT_TTL_MS = 24 * 60 * 60 * 1000;
|
|
6
|
+
/**
|
|
7
|
+
* Check the registry for newer skill releases, caching results on disk so
|
|
8
|
+
* repeated sessions don't hit the network. Registry failures fall back to the
|
|
9
|
+
* cached result (stale ok) or report "no update" — never throw.
|
|
10
|
+
*/
|
|
11
|
+
export async function checkForSkillsUpdate(options) {
|
|
12
|
+
const now = options.now ?? Date.now;
|
|
13
|
+
const ttl = options.ttlMs ?? DEFAULT_TTL_MS;
|
|
14
|
+
const cached = readCache(options.cacheFile);
|
|
15
|
+
if (cached && cached.currentVersion === options.currentVersion && now() - cached.checkedAt < ttl) {
|
|
16
|
+
return { ...cached, fromCache: true };
|
|
17
|
+
}
|
|
18
|
+
let versions;
|
|
19
|
+
try {
|
|
20
|
+
const packument = await new RegistryClient(options).packument(options.pkg);
|
|
21
|
+
versions = Object.keys(packument.versions).filter((v) => semver.valid(v));
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
if (cached)
|
|
25
|
+
return { ...cached, fromCache: true };
|
|
26
|
+
return noUpdate(options.currentVersion, now());
|
|
27
|
+
}
|
|
28
|
+
if (versions.length === 0)
|
|
29
|
+
return noUpdate(options.currentVersion, now());
|
|
30
|
+
const latestVersion = versions.sort(semver.rcompare)[0];
|
|
31
|
+
const latestCompatible = options.compatibleRange
|
|
32
|
+
? semver.maxSatisfying(versions, options.compatibleRange)
|
|
33
|
+
: latestVersion;
|
|
34
|
+
const result = {
|
|
35
|
+
checkedAt: now(),
|
|
36
|
+
fromCache: false,
|
|
37
|
+
currentVersion: options.currentVersion,
|
|
38
|
+
latestVersion,
|
|
39
|
+
latestCompatible,
|
|
40
|
+
updateAvailable: latestCompatible !== null && semver.gt(latestCompatible, options.currentVersion),
|
|
41
|
+
harnessUpgradeRequired: semver.gt(latestVersion, options.currentVersion) &&
|
|
42
|
+
(latestCompatible === null || semver.gt(latestVersion, latestCompatible)),
|
|
43
|
+
};
|
|
44
|
+
writeCache(options.cacheFile, result);
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
function noUpdate(currentVersion, checkedAt) {
|
|
48
|
+
return {
|
|
49
|
+
checkedAt,
|
|
50
|
+
fromCache: false,
|
|
51
|
+
currentVersion,
|
|
52
|
+
latestVersion: currentVersion,
|
|
53
|
+
latestCompatible: currentVersion,
|
|
54
|
+
updateAvailable: false,
|
|
55
|
+
harnessUpgradeRequired: false,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function readCache(cacheFile) {
|
|
59
|
+
try {
|
|
60
|
+
return JSON.parse(fs.readFileSync(cacheFile, 'utf8'));
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function writeCache(cacheFile, result) {
|
|
67
|
+
try {
|
|
68
|
+
fs.mkdirSync(path.dirname(cacheFile), { recursive: true });
|
|
69
|
+
fs.writeFileSync(cacheFile, JSON.stringify(result, null, 2));
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// Cache write failures are non-fatal.
|
|
73
|
+
}
|
|
74
|
+
}
|
package/esm/stash.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AppStashResult } from 'appstash';
|
|
2
|
+
export interface HarnessDirs {
|
|
3
|
+
/** appstash root layout for the tool (config/cache/data/logs/tmp). */
|
|
4
|
+
stash: AppStashResult;
|
|
5
|
+
/** Root for downloaded skill releases: `<data>/skills`. */
|
|
6
|
+
skillsRoot: string;
|
|
7
|
+
/** Directory for one resolved skills release: `<data>/skills/<version>`. */
|
|
8
|
+
skillsVersionDir(version: string): string;
|
|
9
|
+
/** Materialized (merged) skill tree consumed by the agent session. */
|
|
10
|
+
materializedDir: string;
|
|
11
|
+
/** Cached update-check metadata: `<cache>/skills-update-check.json`. */
|
|
12
|
+
updateCheckFile: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Resolve the harness's on-disk layout via appstash.
|
|
16
|
+
*
|
|
17
|
+
* Defaults to `~/.constructive/…` with XDG/tmp fallbacks; hosts that need an
|
|
18
|
+
* app-specific root (e.g. Electron userData) can pass `baseDir`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function harnessDirs(tool?: string, baseDir?: string): HarnessDirs;
|
package/esm/stash.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import { appstash } from 'appstash';
|
|
3
|
+
/**
|
|
4
|
+
* Resolve the harness's on-disk layout via appstash.
|
|
5
|
+
*
|
|
6
|
+
* Defaults to `~/.constructive/…` with XDG/tmp fallbacks; hosts that need an
|
|
7
|
+
* app-specific root (e.g. Electron userData) can pass `baseDir`.
|
|
8
|
+
*/
|
|
9
|
+
export function harnessDirs(tool = 'constructive', baseDir) {
|
|
10
|
+
const stash = appstash(tool, { ensure: true, baseDir });
|
|
11
|
+
const skillsRoot = path.join(stash.data, 'skills');
|
|
12
|
+
return {
|
|
13
|
+
stash,
|
|
14
|
+
skillsRoot,
|
|
15
|
+
skillsVersionDir: (version) => path.join(skillsRoot, version),
|
|
16
|
+
materializedDir: path.join(stash.cache, 'skills-materialized'),
|
|
17
|
+
updateCheckFile: path.join(stash.cache, 'skills-update-check.json'),
|
|
18
|
+
};
|
|
19
|
+
}
|
package/esm/types.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-neutral contracts for the Constructive harness.
|
|
3
|
+
*
|
|
4
|
+
* A harness host (Electron desktop, terminal CLI, MCP server) supplies a
|
|
5
|
+
* `HarnessContext`; the harness core supplies skills, tools, and policies
|
|
6
|
+
* built against these interfaces without knowing anything about the host.
|
|
7
|
+
*/
|
|
8
|
+
/** A single file belonging to a skill (SKILL.md plus optional references/scripts). */
|
|
9
|
+
export interface SkillFile {
|
|
10
|
+
/** Path relative to the skill directory, e.g. `SKILL.md` or `references/topic.md`. */
|
|
11
|
+
relPath: string;
|
|
12
|
+
contents: string;
|
|
13
|
+
}
|
|
14
|
+
/** A resolved skill: parsed identity plus every file it ships. */
|
|
15
|
+
export interface HarnessSkill {
|
|
16
|
+
name: string;
|
|
17
|
+
description: string;
|
|
18
|
+
files: SkillFile[];
|
|
19
|
+
/** Name of the manifest source layer this skill was resolved from. */
|
|
20
|
+
sourceName: string;
|
|
21
|
+
}
|
|
22
|
+
/** Result of a data-plane token request for a provisioned database. */
|
|
23
|
+
export interface DataTokenResult {
|
|
24
|
+
token: string | null;
|
|
25
|
+
/** Where the token came from (host-specific, e.g. `env`, `broker`, `preview`). */
|
|
26
|
+
origin?: string;
|
|
27
|
+
}
|
|
28
|
+
/** Credential access the host must provide; the core never reads secrets itself. */
|
|
29
|
+
export interface HarnessCredentials {
|
|
30
|
+
/** Control-plane (account) bearer token, or null when signed out. */
|
|
31
|
+
accountBearer(): Promise<string | null>;
|
|
32
|
+
/** Data-plane token for a specific provisioned database. */
|
|
33
|
+
dataToken(databaseId: string): Promise<DataTokenResult>;
|
|
34
|
+
}
|
|
35
|
+
/** Backend endpoint configuration pinned by the host / project binding. */
|
|
36
|
+
export interface HarnessEndpoints {
|
|
37
|
+
/** Platform GraphQL endpoint, e.g. `http://api.localhost:3000/graphql`. */
|
|
38
|
+
apiEndpoint: string;
|
|
39
|
+
/** Modules control-plane endpoint used by provisioning. */
|
|
40
|
+
modulesEndpoint: string;
|
|
41
|
+
}
|
|
42
|
+
/** A confirmation request for a mutating/gated tool call. */
|
|
43
|
+
export interface GateRequest {
|
|
44
|
+
toolName: string;
|
|
45
|
+
title: string;
|
|
46
|
+
detail?: string;
|
|
47
|
+
args?: Record<string, unknown>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Everything a harness host injects. Mirrors the injection points identified
|
|
51
|
+
* in the desktop extraction (credentials, endpoints, confirm gate, project cwd).
|
|
52
|
+
*/
|
|
53
|
+
export interface HarnessContext {
|
|
54
|
+
/** Project working directory (where `.constructive/` and `.env` live). */
|
|
55
|
+
cwd: string;
|
|
56
|
+
endpoints: HarnessEndpoints;
|
|
57
|
+
credentials: HarnessCredentials;
|
|
58
|
+
/** Ask the user to confirm a gated tool call. Resolve false to decline. */
|
|
59
|
+
confirm(request: GateRequest): Promise<boolean>;
|
|
60
|
+
}
|
package/esm/types.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-neutral contracts for the Constructive harness.
|
|
3
|
+
*
|
|
4
|
+
* A harness host (Electron desktop, terminal CLI, MCP server) supplies a
|
|
5
|
+
* `HarnessContext`; the harness core supplies skills, tools, and policies
|
|
6
|
+
* built against these interfaces without knowing anything about the host.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ConfirmPreview } from './preview';
|
|
2
|
+
/**
|
|
3
|
+
* Host-neutral confirm gate for mutating db tools. Structurally mirrors the
|
|
4
|
+
* pi extension `tool_call` hook so a pi adapter is a thin mapping, but takes
|
|
5
|
+
* every host capability (confirm UI, skip notification, context/token/preview
|
|
6
|
+
* resolvers) as injected deps — no Electron, no pi imports.
|
|
7
|
+
*/
|
|
8
|
+
export type GateToolCallEvent = {
|
|
9
|
+
toolName: string;
|
|
10
|
+
toolCallId: string;
|
|
11
|
+
input?: Record<string, unknown>;
|
|
12
|
+
};
|
|
13
|
+
/** `block: true` stops the tool call; `reason` is surfaced to the agent. */
|
|
14
|
+
export type GateResult = {
|
|
15
|
+
block: true;
|
|
16
|
+
reason: string;
|
|
17
|
+
} | undefined;
|
|
18
|
+
export type GateHost = {
|
|
19
|
+
/** Whether a confirmation UI is available (headless hosts return false). */
|
|
20
|
+
hasUI: boolean;
|
|
21
|
+
/** Ask the user to approve the call. Resolve false to decline. */
|
|
22
|
+
confirmTool(toolCallId: string, title: string, message: string, preview?: ConfirmPreview): Promise<boolean>;
|
|
23
|
+
/** A retry of an already-declined call was auto-skipped without prompting. */
|
|
24
|
+
notifyToolSkipped(toolCallId: string): void;
|
|
25
|
+
};
|
|
26
|
+
export type ConfirmGateDeps = {
|
|
27
|
+
/**
|
|
28
|
+
* Whether the project is provisioned/runnable at `cwd`. Unrunnable calls
|
|
29
|
+
* skip the confirm so the tool can return its clean "provision first"
|
|
30
|
+
* message instead of making the user approve something that fails.
|
|
31
|
+
*/
|
|
32
|
+
isProjectRunnable(cwd: string): Promise<boolean>;
|
|
33
|
+
/** Whether a data-plane token is available (gates `add_records`). */
|
|
34
|
+
hasDataToken(cwd: string): Promise<boolean>;
|
|
35
|
+
/**
|
|
36
|
+
* Resolve the preview for `create_template` (its tables live in the
|
|
37
|
+
* blueprint it copies, not in the tool input). Return undefined when a
|
|
38
|
+
* preview can't be built.
|
|
39
|
+
*/
|
|
40
|
+
resolveTemplatePreview(cwd: string, blueprintName: string | undefined, displayName: string): Promise<ConfirmPreview | undefined>;
|
|
41
|
+
};
|
|
42
|
+
export type ConfirmGate = {
|
|
43
|
+
onAgentStart: () => void;
|
|
44
|
+
onToolCall: (event: GateToolCallEvent, host: GateHost, cwd: string) => Promise<GateResult>;
|
|
45
|
+
};
|
|
46
|
+
export declare function createConfirmGate(deps: ConfirmGateDeps): ConfirmGate;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createConfirmGate = createConfirmGate;
|
|
4
|
+
const decline_guard_1 = require("./decline-guard");
|
|
5
|
+
const prompts_1 = require("./prompts");
|
|
6
|
+
function createConfirmGate(deps) {
|
|
7
|
+
const declineGuard = (0, decline_guard_1.createDeclineGuard)();
|
|
8
|
+
async function confirmOrDecline(event, host, input, preview) {
|
|
9
|
+
const { title, message, preview: basePreview } = (0, prompts_1.buildConfirmPrompt)(event.toolName, input);
|
|
10
|
+
const approved = await host.confirmTool(event.toolCallId, title, message, preview ?? basePreview);
|
|
11
|
+
if (!approved) {
|
|
12
|
+
declineGuard.recordDecline(event.toolName, input);
|
|
13
|
+
return { block: true, reason: (0, decline_guard_1.buildDeclineReason)(event.toolName) };
|
|
14
|
+
}
|
|
15
|
+
// An approved mutation changes database state, so earlier declines may no
|
|
16
|
+
// longer describe the same effect (e.g. a create_template preview derives
|
|
17
|
+
// from the blueprint, not the input) — let them re-prompt with fresh eyes.
|
|
18
|
+
declineGuard.clear();
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
onAgentStart: () => declineGuard.clear(),
|
|
23
|
+
onToolCall: async (event, host, cwd) => {
|
|
24
|
+
if (!prompts_1.MUTATING_DB_TOOLS.has(event.toolName))
|
|
25
|
+
return;
|
|
26
|
+
const input = event.input;
|
|
27
|
+
const retryBlock = declineGuard.checkRetry(event.toolName, input);
|
|
28
|
+
if (retryBlock) {
|
|
29
|
+
if (host.hasUI) {
|
|
30
|
+
host.notifyToolSkipped(event.toolCallId);
|
|
31
|
+
}
|
|
32
|
+
return { block: true, reason: retryBlock };
|
|
33
|
+
}
|
|
34
|
+
if (!host.hasUI) {
|
|
35
|
+
return {
|
|
36
|
+
block: true,
|
|
37
|
+
reason: `Cannot confirm "${event.toolName}" — no confirmation UI is available.`,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// provision_database is the tool that CREATES the project context, so it
|
|
41
|
+
// can't gate on an existing one — confirm it directly.
|
|
42
|
+
if (event.toolName === 'provision_database') {
|
|
43
|
+
return confirmOrDecline(event, host, input);
|
|
44
|
+
}
|
|
45
|
+
if (!(await deps.isProjectRunnable(cwd)))
|
|
46
|
+
return;
|
|
47
|
+
if (event.toolName === 'add_records' && !(await deps.hasDataToken(cwd)))
|
|
48
|
+
return;
|
|
49
|
+
let resolvedPreview;
|
|
50
|
+
if (event.toolName === 'create_template') {
|
|
51
|
+
const blueprintName = typeof input?.blueprintName === 'string' ? input.blueprintName : undefined;
|
|
52
|
+
const displayName = typeof input?.displayName === 'string' ? input.displayName : '';
|
|
53
|
+
resolvedPreview = await deps.resolveTemplatePreview(cwd, blueprintName, displayName);
|
|
54
|
+
}
|
|
55
|
+
return confirmOrDecline(event, host, input, resolvedPreview);
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type DeclineGuard = {
|
|
2
|
+
recordDecline: (toolName: string, input: Record<string, unknown> | undefined) => void;
|
|
3
|
+
checkRetry: (toolName: string, input: Record<string, unknown> | undefined) => string | null;
|
|
4
|
+
clear: () => void;
|
|
5
|
+
};
|
|
6
|
+
export declare function buildDeclineReason(toolName: string): string;
|
|
7
|
+
export declare function createDeclineGuard(): DeclineGuard;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Per-session memory of tool calls the user declined in the current agent run.
|
|
3
|
+
// A declined call re-issued with equivalent arguments is blocked without
|
|
4
|
+
// re-prompting the user; the memory clears when a new run starts (agent_start),
|
|
5
|
+
// so a later "go ahead" from the user re-prompts normally. That reset assumes
|
|
6
|
+
// user messages only arrive between runs — if mid-run steering ever lands, a
|
|
7
|
+
// steered approval won't clear this memory and needs its own reset hook.
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.buildDeclineReason = buildDeclineReason;
|
|
10
|
+
exports.createDeclineGuard = createDeclineGuard;
|
|
11
|
+
function canonicalize(value) {
|
|
12
|
+
if (Array.isArray(value))
|
|
13
|
+
return value.map(canonicalize);
|
|
14
|
+
if (typeof value === 'object' && value !== null) {
|
|
15
|
+
const record = value;
|
|
16
|
+
const sorted = {};
|
|
17
|
+
for (const key of Object.keys(record).sort()) {
|
|
18
|
+
sorted[key] = canonicalize(record[key]);
|
|
19
|
+
}
|
|
20
|
+
return sorted;
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
function callKey(toolName, input) {
|
|
25
|
+
return `${toolName}::${JSON.stringify(canonicalize(input ?? {}))}`;
|
|
26
|
+
}
|
|
27
|
+
function buildDeclineReason(toolName) {
|
|
28
|
+
return (`The user reviewed this ${toolName} call and declined it. ` +
|
|
29
|
+
`This is a deliberate decision, not an error — do not call ${toolName} again with the same arguments. ` +
|
|
30
|
+
`Continue the task without it, or tell the user in one sentence what you can't do without it.`);
|
|
31
|
+
}
|
|
32
|
+
function buildRetryBlockReason(toolName) {
|
|
33
|
+
return (`Blocked: the user already declined this exact ${toolName} call in this run, ` +
|
|
34
|
+
`so it was not shown to the user again. Do not issue it again — ` +
|
|
35
|
+
`proceed without it or ask the user how they'd like to continue.`);
|
|
36
|
+
}
|
|
37
|
+
function createDeclineGuard() {
|
|
38
|
+
const declined = new Set();
|
|
39
|
+
return {
|
|
40
|
+
recordDecline(toolName, input) {
|
|
41
|
+
declined.add(callKey(toolName, input));
|
|
42
|
+
},
|
|
43
|
+
checkRetry(toolName, input) {
|
|
44
|
+
if (!declined.has(callKey(toolName, input)))
|
|
45
|
+
return null;
|
|
46
|
+
return buildRetryBlockReason(toolName);
|
|
47
|
+
},
|
|
48
|
+
clear() {
|
|
49
|
+
declined.clear();
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -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,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;
|