@agentic-kit/harness 0.12.0 → 0.14.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 +4 -0
- package/adapter.d.ts +33 -0
- package/adapter.js +17 -0
- package/esm/adapter.d.ts +33 -0
- package/esm/adapter.js +16 -0
- package/esm/gating/approvals.d.ts +47 -0
- package/esm/gating/approvals.js +38 -0
- package/esm/gating/run-gate.d.ts +57 -0
- package/esm/gating/run-gate.js +72 -0
- package/esm/gating/run-policy.d.ts +47 -0
- package/esm/gating/run-policy.js +43 -0
- package/esm/index.d.ts +4 -0
- package/esm/index.js +4 -0
- package/gating/approvals.d.ts +47 -0
- package/gating/approvals.js +42 -0
- package/gating/run-gate.d.ts +57 -0
- package/gating/run-gate.js +77 -0
- package/gating/run-policy.d.ts +47 -0
- package/gating/run-policy.js +48 -0
- package/index.d.ts +4 -0
- package/index.js +4 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -25,6 +25,8 @@ Code only: **no skills are bundled**. Skills are pulled at runtime from [`constr
|
|
|
25
25
|
- **Skill releases** — fetch a pinned release (npm version/range/dist-tag, or a git tag/semver/SHA/branch straight from GitHub), verified and cached under `~/.constructive/data/skills/<version>/`; offline falls back to the newest local release.
|
|
26
26
|
- **Ordered overlays** — layer skill sources (hardened base → team overlays → private known-gaps), last write wins by skill name, with include/exclude filters and transitive `requires:` expansion.
|
|
27
27
|
- **Confirm gating** — a host-neutral gate for mutating db tools: per-run decline memory (equivalent-args retries are auto-blocked), short-circuits for runnable projects, and structured previews your UI renders.
|
|
28
|
+
- **Run gate** — a policy (`allow` / `deny` / `ask`) plus an approval rendezvous, so a cloud run's `rm -rf` can be answered from a browser tab. The gate settles the decision and records it; an adapter only maps its harness's tool-call event onto it.
|
|
29
|
+
- **Harness adapter contract** — `HarnessAdapter` / `HarnessRun`: a harness is identified by an `id`, the `transcriptFormat` its entries are recorded under, and `startRun`. Nothing in the platform names a vendor.
|
|
28
30
|
- **Blueprint logic** — `expandBlueprintDefaults()`, the zod `BlueprintZod`/JSON-Schema `BlueprintSchema`, field type/default parsing, and policy-provisioning tables.
|
|
29
31
|
- **Appstash state** — everything lives in the [`appstash`](https://www.npmjs.com/package/appstash) `~/.constructive/{config,cache,data,logs}` layout; project directories are untouched.
|
|
30
32
|
|
|
@@ -71,6 +73,8 @@ materializeSkills(dirs.materializedDir, skills, {
|
|
|
71
73
|
- **Freshness** — `checkForSkillsUpdate()` / `checkForSkillsUpdateFromGit()`: TTL-cached update checks that never throw, respect `compatibleSkillsRange`, and flag `harnessUpgradeRequired` when newer skills need newer tool code.
|
|
72
74
|
- **Resolution** — `SkillsManifest`, `DirectorySkillSource` (agentskills.io layout: `<skill>/SKILL.md` + references/scripts), `resolveSkills()`, `materializeSkills()` with `{{VAR}}` substitution.
|
|
73
75
|
- **Gating** — `createConfirmGate()`, `buildConfirmPrompt()`, `MUTATING_DB_TOOLS`, `ConfirmPreview`; adapters map host events onto `GateToolCallEvent`/`GateResult` 1:1.
|
|
76
|
+
- **Run gate** — `createRunGate()`, `RunGatePolicy` / `RunGateRule` / `RunGateVerdict`, `ApprovalChannel` with `pollingApprovalChannel()` / `staticApprovalChannel()`, and `RunGateDecisionRecord` for the audit trail.
|
|
77
|
+
- **Adapters** — `HarnessAdapter`, `HarnessRun`; [`@agentic-kit/pi`](https://www.npmjs.com/package/@agentic-kit/pi) is the first implementation.
|
|
74
78
|
- **Blueprints** — `expandBlueprintDefaults()`, `BlueprintZod`/`BlueprintSchema`, field types/defaults, policy provisioning.
|
|
75
79
|
|
|
76
80
|
## Hosts
|
package/adapter.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What Constructive needs from a coding-agent harness.
|
|
3
|
+
*
|
|
4
|
+
* The lanes a run is wrapped in — the run log, the metering gateway, the run
|
|
5
|
+
* gate — are harness-neutral; only their *attachment* is vendor-specific (pi
|
|
6
|
+
* takes extension factories through a resource loader, another harness will take
|
|
7
|
+
* plugins, or a subprocess). An adapter is exactly that attachment plus the
|
|
8
|
+
* identity of the transcript it produces, so a host can start a run without
|
|
9
|
+
* naming a vendor.
|
|
10
|
+
*
|
|
11
|
+
* Deliberately thin: it declares only what a host actually calls on a started
|
|
12
|
+
* run. Prompting, tool registration and event subscription stay on the
|
|
13
|
+
* adapter's own run handle, because those surfaces differ enough between
|
|
14
|
+
* harnesses that a lowest common denominator would be a lie.
|
|
15
|
+
*/
|
|
16
|
+
export interface HarnessRun {
|
|
17
|
+
/** The run these lanes belong to; the run log's partition key. */
|
|
18
|
+
readonly runId: string;
|
|
19
|
+
/** Drain every lane that buffers (log entries, usage reports). */
|
|
20
|
+
flush(): Promise<void>;
|
|
21
|
+
/** Flush, then release the harness's resources. */
|
|
22
|
+
close(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export interface HarnessAdapter<TStartOptions, TRun extends HarnessRun = HarnessRun> {
|
|
25
|
+
/** Stable adapter id, e.g. `pi`. */
|
|
26
|
+
readonly id: string;
|
|
27
|
+
/**
|
|
28
|
+
* The `transcriptFormat` the run's entries are recorded under, so a reader can
|
|
29
|
+
* pick the projector that understands them.
|
|
30
|
+
*/
|
|
31
|
+
readonly transcriptFormat: string;
|
|
32
|
+
startRun(options: TStartOptions): Promise<TRun>;
|
|
33
|
+
}
|
package/adapter.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* What Constructive needs from a coding-agent harness.
|
|
4
|
+
*
|
|
5
|
+
* The lanes a run is wrapped in — the run log, the metering gateway, the run
|
|
6
|
+
* gate — are harness-neutral; only their *attachment* is vendor-specific (pi
|
|
7
|
+
* takes extension factories through a resource loader, another harness will take
|
|
8
|
+
* plugins, or a subprocess). An adapter is exactly that attachment plus the
|
|
9
|
+
* identity of the transcript it produces, so a host can start a run without
|
|
10
|
+
* naming a vendor.
|
|
11
|
+
*
|
|
12
|
+
* Deliberately thin: it declares only what a host actually calls on a started
|
|
13
|
+
* run. Prompting, tool registration and event subscription stay on the
|
|
14
|
+
* adapter's own run handle, because those surfaces differ enough between
|
|
15
|
+
* harnesses that a lowest common denominator would be a lie.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/esm/adapter.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What Constructive needs from a coding-agent harness.
|
|
3
|
+
*
|
|
4
|
+
* The lanes a run is wrapped in — the run log, the metering gateway, the run
|
|
5
|
+
* gate — are harness-neutral; only their *attachment* is vendor-specific (pi
|
|
6
|
+
* takes extension factories through a resource loader, another harness will take
|
|
7
|
+
* plugins, or a subprocess). An adapter is exactly that attachment plus the
|
|
8
|
+
* identity of the transcript it produces, so a host can start a run without
|
|
9
|
+
* naming a vendor.
|
|
10
|
+
*
|
|
11
|
+
* Deliberately thin: it declares only what a host actually calls on a started
|
|
12
|
+
* run. Prompting, tool registration and event subscription stay on the
|
|
13
|
+
* adapter's own run handle, because those surfaces differ enough between
|
|
14
|
+
* harnesses that a lowest common denominator would be a lie.
|
|
15
|
+
*/
|
|
16
|
+
export interface HarnessRun {
|
|
17
|
+
/** The run these lanes belong to; the run log's partition key. */
|
|
18
|
+
readonly runId: string;
|
|
19
|
+
/** Drain every lane that buffers (log entries, usage reports). */
|
|
20
|
+
flush(): Promise<void>;
|
|
21
|
+
/** Flush, then release the harness's resources. */
|
|
22
|
+
close(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export interface HarnessAdapter<TStartOptions, TRun extends HarnessRun = HarnessRun> {
|
|
25
|
+
/** Stable adapter id, e.g. `pi`. */
|
|
26
|
+
readonly id: string;
|
|
27
|
+
/**
|
|
28
|
+
* The `transcriptFormat` the run's entries are recorded under, so a reader can
|
|
29
|
+
* pick the projector that understands them.
|
|
30
|
+
*/
|
|
31
|
+
readonly transcriptFormat: string;
|
|
32
|
+
startRun(options: TStartOptions): Promise<TRun>;
|
|
33
|
+
}
|
package/esm/adapter.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What Constructive needs from a coding-agent harness.
|
|
3
|
+
*
|
|
4
|
+
* The lanes a run is wrapped in — the run log, the metering gateway, the run
|
|
5
|
+
* gate — are harness-neutral; only their *attachment* is vendor-specific (pi
|
|
6
|
+
* takes extension factories through a resource loader, another harness will take
|
|
7
|
+
* plugins, or a subprocess). An adapter is exactly that attachment plus the
|
|
8
|
+
* identity of the transcript it produces, so a host can start a run without
|
|
9
|
+
* naming a vendor.
|
|
10
|
+
*
|
|
11
|
+
* Deliberately thin: it declares only what a host actually calls on a started
|
|
12
|
+
* run. Prompting, tool registration and event subscription stay on the
|
|
13
|
+
* adapter's own run handle, because those surfaces differ enough between
|
|
14
|
+
* harnesses that a lowest common denominator would be a lie.
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The asynchronous half of the gate: an `ask` verdict has to reach a human who
|
|
3
|
+
* may be on another machine, so approval is an interface rather than a prompt.
|
|
4
|
+
*
|
|
5
|
+
* `pollingApprovalChannel` is the baseline implementation of the platform's
|
|
6
|
+
* rendezvous model — the request is submitted (a row), and the decision is
|
|
7
|
+
* polled for (another row). No socket back into the agent's process, which is
|
|
8
|
+
* what lets a cloud run be approved from a browser.
|
|
9
|
+
*/
|
|
10
|
+
export interface ApprovalRequest {
|
|
11
|
+
runId: string;
|
|
12
|
+
toolCallId: string;
|
|
13
|
+
toolName: string;
|
|
14
|
+
input: Record<string, unknown>;
|
|
15
|
+
/** The policy's reason for asking. */
|
|
16
|
+
reason?: string;
|
|
17
|
+
requestedAt: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ApprovalOutcome {
|
|
20
|
+
decision: 'allow' | 'deny';
|
|
21
|
+
reason?: string;
|
|
22
|
+
/** Who decided, when the channel knows. */
|
|
23
|
+
actorId?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface ApprovalChannel {
|
|
26
|
+
/** Resolves once a decision exists; may take as long as a human takes. */
|
|
27
|
+
request(request: ApprovalRequest): Promise<ApprovalOutcome>;
|
|
28
|
+
}
|
|
29
|
+
export interface PollingApprovalChannelOptions {
|
|
30
|
+
/** Publish the request (insert the row, post to the API). */
|
|
31
|
+
submit: (request: ApprovalRequest) => Promise<void>;
|
|
32
|
+
/** Read the decision, or `undefined` while it is still outstanding. */
|
|
33
|
+
poll: (request: ApprovalRequest) => Promise<ApprovalOutcome | undefined>;
|
|
34
|
+
intervalMs?: number;
|
|
35
|
+
/** Give up after this long. Omit to wait indefinitely. */
|
|
36
|
+
timeoutMs?: number;
|
|
37
|
+
/** Verdict on timeout. Defaults to `deny`: an unattended run must not take an
|
|
38
|
+
* action nobody approved just because nobody was watching. */
|
|
39
|
+
onTimeout?: 'deny' | 'allow';
|
|
40
|
+
/** Injectable clock/sleep for tests. */
|
|
41
|
+
sleep?: (ms: number) => Promise<void>;
|
|
42
|
+
now?: () => number;
|
|
43
|
+
}
|
|
44
|
+
export declare function pollingApprovalChannel(options: PollingApprovalChannelOptions): ApprovalChannel;
|
|
45
|
+
/** Decide every request the same way — for tests, and for a headless run that is
|
|
46
|
+
* explicitly configured to auto-approve. */
|
|
47
|
+
export declare function staticApprovalChannel(outcome: ApprovalOutcome): ApprovalChannel;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The asynchronous half of the gate: an `ask` verdict has to reach a human who
|
|
3
|
+
* may be on another machine, so approval is an interface rather than a prompt.
|
|
4
|
+
*
|
|
5
|
+
* `pollingApprovalChannel` is the baseline implementation of the platform's
|
|
6
|
+
* rendezvous model — the request is submitted (a row), and the decision is
|
|
7
|
+
* polled for (another row). No socket back into the agent's process, which is
|
|
8
|
+
* what lets a cloud run be approved from a browser.
|
|
9
|
+
*/
|
|
10
|
+
export function pollingApprovalChannel(options) {
|
|
11
|
+
const intervalMs = options.intervalMs ?? 1000;
|
|
12
|
+
const onTimeout = options.onTimeout ?? 'deny';
|
|
13
|
+
const sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
14
|
+
const now = options.now ?? (() => Date.now());
|
|
15
|
+
return {
|
|
16
|
+
async request(request) {
|
|
17
|
+
await options.submit(request);
|
|
18
|
+
const startedAt = now();
|
|
19
|
+
for (;;) {
|
|
20
|
+
const outcome = await options.poll(request);
|
|
21
|
+
if (outcome)
|
|
22
|
+
return outcome;
|
|
23
|
+
if (options.timeoutMs !== undefined && now() - startedAt >= options.timeoutMs) {
|
|
24
|
+
return {
|
|
25
|
+
decision: onTimeout,
|
|
26
|
+
reason: `gate: no decision within ${options.timeoutMs}ms`
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
await sleep(intervalMs);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** Decide every request the same way — for tests, and for a headless run that is
|
|
35
|
+
* explicitly configured to auto-approve. */
|
|
36
|
+
export function staticApprovalChannel(outcome) {
|
|
37
|
+
return { request: () => Promise.resolve(outcome) };
|
|
38
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The run gate: evaluate the run's policy for one tool call and, when the policy
|
|
3
|
+
* will not decide alone, wait for a human through the approval channel.
|
|
4
|
+
*
|
|
5
|
+
* Harness-neutral on purpose. An adapter owns one line of glue — map its
|
|
6
|
+
* harness's tool-call event onto `decide()` and turn the outcome into whatever
|
|
7
|
+
* that harness expects from a blocked call — so the policy, the approval
|
|
8
|
+
* rendezvous and the audit record are the same for every harness.
|
|
9
|
+
*/
|
|
10
|
+
import { type ApprovalChannel, type ApprovalRequest } from './approvals';
|
|
11
|
+
import { RunGatePolicy, type RunGatePolicyOptions, type RunGateVerdict } from './run-policy';
|
|
12
|
+
export interface RunGateDecisionRecord {
|
|
13
|
+
runId: string;
|
|
14
|
+
toolCallId: string;
|
|
15
|
+
toolName: string;
|
|
16
|
+
input: Record<string, unknown>;
|
|
17
|
+
/** What the policy said. */
|
|
18
|
+
verdict: RunGateVerdict;
|
|
19
|
+
/** How the request was finally settled. */
|
|
20
|
+
decision: 'allow' | 'deny';
|
|
21
|
+
reason?: string;
|
|
22
|
+
actorId?: string;
|
|
23
|
+
decidedAt: string;
|
|
24
|
+
}
|
|
25
|
+
export interface RunGateOptions {
|
|
26
|
+
runId: string;
|
|
27
|
+
/** A policy, or the options to build one. */
|
|
28
|
+
policy: RunGatePolicy | RunGatePolicyOptions;
|
|
29
|
+
/** Required only if the policy can produce `ask`. */
|
|
30
|
+
approvals?: ApprovalChannel;
|
|
31
|
+
/** Every settled decision, for the run log / audit trail. */
|
|
32
|
+
onDecision?: (record: RunGateDecisionRecord) => void;
|
|
33
|
+
now?: () => Date;
|
|
34
|
+
}
|
|
35
|
+
export interface RunGateToolCall {
|
|
36
|
+
toolCallId: string;
|
|
37
|
+
toolName: string;
|
|
38
|
+
input?: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
export interface RunGateOutcome {
|
|
41
|
+
/** `false` means the harness must not run the call. */
|
|
42
|
+
allowed: boolean;
|
|
43
|
+
/** The model's only explanation for a refusal, so policies should be specific. */
|
|
44
|
+
reason?: string;
|
|
45
|
+
}
|
|
46
|
+
export declare class RunGate {
|
|
47
|
+
readonly policy: RunGatePolicy;
|
|
48
|
+
/** Requests currently waiting on a human. */
|
|
49
|
+
readonly pending: ReadonlyMap<string, ApprovalRequest>;
|
|
50
|
+
private readonly options;
|
|
51
|
+
private readonly now;
|
|
52
|
+
private readonly waiting;
|
|
53
|
+
constructor(options: RunGateOptions);
|
|
54
|
+
decide(call: RunGateToolCall): Promise<RunGateOutcome>;
|
|
55
|
+
private ask;
|
|
56
|
+
}
|
|
57
|
+
export declare function createRunGate(options: RunGateOptions): RunGate;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The run gate: evaluate the run's policy for one tool call and, when the policy
|
|
3
|
+
* will not decide alone, wait for a human through the approval channel.
|
|
4
|
+
*
|
|
5
|
+
* Harness-neutral on purpose. An adapter owns one line of glue — map its
|
|
6
|
+
* harness's tool-call event onto `decide()` and turn the outcome into whatever
|
|
7
|
+
* that harness expects from a blocked call — so the policy, the approval
|
|
8
|
+
* rendezvous and the audit record are the same for every harness.
|
|
9
|
+
*/
|
|
10
|
+
import { RunGatePolicy } from './run-policy';
|
|
11
|
+
export class RunGate {
|
|
12
|
+
policy;
|
|
13
|
+
/** Requests currently waiting on a human. */
|
|
14
|
+
pending;
|
|
15
|
+
options;
|
|
16
|
+
now;
|
|
17
|
+
waiting = new Map();
|
|
18
|
+
constructor(options) {
|
|
19
|
+
this.options = options;
|
|
20
|
+
this.now = options.now ?? (() => new Date());
|
|
21
|
+
this.policy = options.policy instanceof RunGatePolicy ? options.policy : new RunGatePolicy(options.policy);
|
|
22
|
+
this.pending = this.waiting;
|
|
23
|
+
if (canAsk(this.policy) && !options.approvals) {
|
|
24
|
+
throw new Error('gate: the policy can produce "ask", so an approvals channel is required');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async decide(call) {
|
|
28
|
+
const input = call.input ?? {};
|
|
29
|
+
const verdict = this.policy.evaluate({ toolName: call.toolName, input });
|
|
30
|
+
const settled = verdict.decision === 'ask'
|
|
31
|
+
? await this.ask(call.toolCallId, call.toolName, input, verdict)
|
|
32
|
+
: { decision: verdict.decision, ...(verdict.reason === undefined ? {} : { reason: verdict.reason }) };
|
|
33
|
+
this.options.onDecision?.({
|
|
34
|
+
runId: this.options.runId,
|
|
35
|
+
toolCallId: call.toolCallId,
|
|
36
|
+
toolName: call.toolName,
|
|
37
|
+
input,
|
|
38
|
+
verdict,
|
|
39
|
+
decision: settled.decision,
|
|
40
|
+
...(settled.reason === undefined ? {} : { reason: settled.reason }),
|
|
41
|
+
...(settled.actorId === undefined ? {} : { actorId: settled.actorId }),
|
|
42
|
+
decidedAt: this.now().toISOString()
|
|
43
|
+
});
|
|
44
|
+
if (settled.decision === 'allow')
|
|
45
|
+
return { allowed: true };
|
|
46
|
+
return { allowed: false, reason: settled.reason ?? `gate: ${call.toolName} is not permitted in this run` };
|
|
47
|
+
}
|
|
48
|
+
async ask(toolCallId, toolName, input, verdict) {
|
|
49
|
+
const request = {
|
|
50
|
+
runId: this.options.runId,
|
|
51
|
+
toolCallId,
|
|
52
|
+
toolName,
|
|
53
|
+
input,
|
|
54
|
+
...(verdict.reason === undefined ? {} : { reason: verdict.reason }),
|
|
55
|
+
requestedAt: this.now().toISOString()
|
|
56
|
+
};
|
|
57
|
+
this.waiting.set(toolCallId, request);
|
|
58
|
+
try {
|
|
59
|
+
return await this.options.approvals.request(request);
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
this.waiting.delete(toolCallId);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export function createRunGate(options) {
|
|
67
|
+
return new RunGate(options);
|
|
68
|
+
}
|
|
69
|
+
function canAsk(policy) {
|
|
70
|
+
const decisions = [policy.defaultDecision, ...policy.rules.map((rule) => rule.decision)];
|
|
71
|
+
return decisions.includes('ask');
|
|
72
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The declared half of the run gate: which tool calls run, which are refused,
|
|
3
|
+
* and which need a human. A policy is data — an ordered rule list evaluated with
|
|
4
|
+
* no I/O — so the same policy can be asserted in a test, stored on a run row,
|
|
5
|
+
* and shown in a UI.
|
|
6
|
+
*
|
|
7
|
+
* This is the *run's* policy, decided wherever the run is configured and
|
|
8
|
+
* enforceable without a UI, as opposed to `ConfirmGatePolicy` in
|
|
9
|
+
* `./policy`, which is a host's interactive confirm surface. Harness-neutral:
|
|
10
|
+
* an adapter maps its own tool-call event onto `RunGateRequest`.
|
|
11
|
+
*/
|
|
12
|
+
export type RunGateDecision = 'allow' | 'deny' | 'ask';
|
|
13
|
+
export interface RunGateRequest {
|
|
14
|
+
toolName: string;
|
|
15
|
+
input: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
export interface RunGateRule {
|
|
18
|
+
/** Tool name, or `*` for every tool. */
|
|
19
|
+
tool: string;
|
|
20
|
+
decision: RunGateDecision;
|
|
21
|
+
/** Narrow the rule to particular arguments (e.g. a bash command pattern). */
|
|
22
|
+
match?: (request: RunGateRequest) => boolean;
|
|
23
|
+
/** Shown to the model when denied, and to the human when asked. */
|
|
24
|
+
reason?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface RunGateVerdict {
|
|
27
|
+
decision: RunGateDecision;
|
|
28
|
+
reason?: string;
|
|
29
|
+
/** The rule that decided, or `undefined` when the default applied. */
|
|
30
|
+
rule?: RunGateRule;
|
|
31
|
+
}
|
|
32
|
+
export interface RunGatePolicyOptions {
|
|
33
|
+
rules?: readonly RunGateRule[];
|
|
34
|
+
/** Verdict when no rule matches. Defaults to `ask` — an undeclared tool is
|
|
35
|
+
* not implicitly trusted, and denying outright would strand the run. */
|
|
36
|
+
defaultDecision?: RunGateDecision;
|
|
37
|
+
defaultReason?: string;
|
|
38
|
+
}
|
|
39
|
+
export declare class RunGatePolicy {
|
|
40
|
+
readonly rules: readonly RunGateRule[];
|
|
41
|
+
readonly defaultDecision: RunGateDecision;
|
|
42
|
+
private readonly defaultReason;
|
|
43
|
+
constructor(options?: RunGatePolicyOptions);
|
|
44
|
+
/** First matching rule wins, so order the list most specific first. */
|
|
45
|
+
evaluate(request: RunGateRequest): RunGateVerdict;
|
|
46
|
+
}
|
|
47
|
+
export declare function runGatePolicy(options?: RunGatePolicyOptions): RunGatePolicy;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The declared half of the run gate: which tool calls run, which are refused,
|
|
3
|
+
* and which need a human. A policy is data — an ordered rule list evaluated with
|
|
4
|
+
* no I/O — so the same policy can be asserted in a test, stored on a run row,
|
|
5
|
+
* and shown in a UI.
|
|
6
|
+
*
|
|
7
|
+
* This is the *run's* policy, decided wherever the run is configured and
|
|
8
|
+
* enforceable without a UI, as opposed to `ConfirmGatePolicy` in
|
|
9
|
+
* `./policy`, which is a host's interactive confirm surface. Harness-neutral:
|
|
10
|
+
* an adapter maps its own tool-call event onto `RunGateRequest`.
|
|
11
|
+
*/
|
|
12
|
+
export class RunGatePolicy {
|
|
13
|
+
rules;
|
|
14
|
+
defaultDecision;
|
|
15
|
+
defaultReason;
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
this.rules = options.rules ?? [];
|
|
18
|
+
this.defaultDecision = options.defaultDecision ?? 'ask';
|
|
19
|
+
this.defaultReason = options.defaultReason;
|
|
20
|
+
for (const rule of this.rules) {
|
|
21
|
+
if (!rule.tool)
|
|
22
|
+
throw new Error('gate: every rule needs a tool name (or "*")');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** First matching rule wins, so order the list most specific first. */
|
|
26
|
+
evaluate(request) {
|
|
27
|
+
for (const rule of this.rules) {
|
|
28
|
+
if (rule.tool !== '*' && rule.tool !== request.toolName)
|
|
29
|
+
continue;
|
|
30
|
+
if (rule.match && !rule.match(request))
|
|
31
|
+
continue;
|
|
32
|
+
return rule.reason === undefined
|
|
33
|
+
? { decision: rule.decision, rule }
|
|
34
|
+
: { decision: rule.decision, reason: rule.reason, rule };
|
|
35
|
+
}
|
|
36
|
+
return this.defaultReason === undefined
|
|
37
|
+
? { decision: this.defaultDecision }
|
|
38
|
+
: { decision: this.defaultDecision, reason: this.defaultReason };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export function runGatePolicy(options = {}) {
|
|
42
|
+
return new RunGatePolicy(options);
|
|
43
|
+
}
|
package/esm/index.d.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
export * from './adapter';
|
|
1
2
|
export * from './blueprint/blueprint-defaults';
|
|
2
3
|
export * from './blueprint/blueprint-schema';
|
|
3
4
|
export * from './blueprint/field-type';
|
|
4
5
|
export * from './blueprint/internal-policies';
|
|
5
6
|
export * from './blueprint/policy-provisioning';
|
|
7
|
+
export * from './gating/approvals';
|
|
6
8
|
export * from './gating/confirm-gate';
|
|
7
9
|
export * from './gating/constructive-policy';
|
|
8
10
|
export * from './gating/decline-guard';
|
|
9
11
|
export * from './gating/policy';
|
|
10
12
|
export * from './gating/preview';
|
|
11
13
|
export * from './gating/prompts';
|
|
14
|
+
export * from './gating/run-gate';
|
|
15
|
+
export * from './gating/run-policy';
|
|
12
16
|
export * from './skills/default-source';
|
|
13
17
|
export * from './skills/fetch';
|
|
14
18
|
export * from './skills/frontmatter';
|
package/esm/index.js
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
export * from './adapter';
|
|
1
2
|
export * from './blueprint/blueprint-defaults';
|
|
2
3
|
export * from './blueprint/blueprint-schema';
|
|
3
4
|
export * from './blueprint/field-type';
|
|
4
5
|
export * from './blueprint/internal-policies';
|
|
5
6
|
export * from './blueprint/policy-provisioning';
|
|
7
|
+
export * from './gating/approvals';
|
|
6
8
|
export * from './gating/confirm-gate';
|
|
7
9
|
export * from './gating/constructive-policy';
|
|
8
10
|
export * from './gating/decline-guard';
|
|
9
11
|
export * from './gating/policy';
|
|
10
12
|
export * from './gating/preview';
|
|
11
13
|
export * from './gating/prompts';
|
|
14
|
+
export * from './gating/run-gate';
|
|
15
|
+
export * from './gating/run-policy';
|
|
12
16
|
export * from './skills/default-source';
|
|
13
17
|
export * from './skills/fetch';
|
|
14
18
|
export * from './skills/frontmatter';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The asynchronous half of the gate: an `ask` verdict has to reach a human who
|
|
3
|
+
* may be on another machine, so approval is an interface rather than a prompt.
|
|
4
|
+
*
|
|
5
|
+
* `pollingApprovalChannel` is the baseline implementation of the platform's
|
|
6
|
+
* rendezvous model — the request is submitted (a row), and the decision is
|
|
7
|
+
* polled for (another row). No socket back into the agent's process, which is
|
|
8
|
+
* what lets a cloud run be approved from a browser.
|
|
9
|
+
*/
|
|
10
|
+
export interface ApprovalRequest {
|
|
11
|
+
runId: string;
|
|
12
|
+
toolCallId: string;
|
|
13
|
+
toolName: string;
|
|
14
|
+
input: Record<string, unknown>;
|
|
15
|
+
/** The policy's reason for asking. */
|
|
16
|
+
reason?: string;
|
|
17
|
+
requestedAt: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ApprovalOutcome {
|
|
20
|
+
decision: 'allow' | 'deny';
|
|
21
|
+
reason?: string;
|
|
22
|
+
/** Who decided, when the channel knows. */
|
|
23
|
+
actorId?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface ApprovalChannel {
|
|
26
|
+
/** Resolves once a decision exists; may take as long as a human takes. */
|
|
27
|
+
request(request: ApprovalRequest): Promise<ApprovalOutcome>;
|
|
28
|
+
}
|
|
29
|
+
export interface PollingApprovalChannelOptions {
|
|
30
|
+
/** Publish the request (insert the row, post to the API). */
|
|
31
|
+
submit: (request: ApprovalRequest) => Promise<void>;
|
|
32
|
+
/** Read the decision, or `undefined` while it is still outstanding. */
|
|
33
|
+
poll: (request: ApprovalRequest) => Promise<ApprovalOutcome | undefined>;
|
|
34
|
+
intervalMs?: number;
|
|
35
|
+
/** Give up after this long. Omit to wait indefinitely. */
|
|
36
|
+
timeoutMs?: number;
|
|
37
|
+
/** Verdict on timeout. Defaults to `deny`: an unattended run must not take an
|
|
38
|
+
* action nobody approved just because nobody was watching. */
|
|
39
|
+
onTimeout?: 'deny' | 'allow';
|
|
40
|
+
/** Injectable clock/sleep for tests. */
|
|
41
|
+
sleep?: (ms: number) => Promise<void>;
|
|
42
|
+
now?: () => number;
|
|
43
|
+
}
|
|
44
|
+
export declare function pollingApprovalChannel(options: PollingApprovalChannelOptions): ApprovalChannel;
|
|
45
|
+
/** Decide every request the same way — for tests, and for a headless run that is
|
|
46
|
+
* explicitly configured to auto-approve. */
|
|
47
|
+
export declare function staticApprovalChannel(outcome: ApprovalOutcome): ApprovalChannel;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The asynchronous half of the gate: an `ask` verdict has to reach a human who
|
|
4
|
+
* may be on another machine, so approval is an interface rather than a prompt.
|
|
5
|
+
*
|
|
6
|
+
* `pollingApprovalChannel` is the baseline implementation of the platform's
|
|
7
|
+
* rendezvous model — the request is submitted (a row), and the decision is
|
|
8
|
+
* polled for (another row). No socket back into the agent's process, which is
|
|
9
|
+
* what lets a cloud run be approved from a browser.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.pollingApprovalChannel = pollingApprovalChannel;
|
|
13
|
+
exports.staticApprovalChannel = staticApprovalChannel;
|
|
14
|
+
function pollingApprovalChannel(options) {
|
|
15
|
+
const intervalMs = options.intervalMs ?? 1000;
|
|
16
|
+
const onTimeout = options.onTimeout ?? 'deny';
|
|
17
|
+
const sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
18
|
+
const now = options.now ?? (() => Date.now());
|
|
19
|
+
return {
|
|
20
|
+
async request(request) {
|
|
21
|
+
await options.submit(request);
|
|
22
|
+
const startedAt = now();
|
|
23
|
+
for (;;) {
|
|
24
|
+
const outcome = await options.poll(request);
|
|
25
|
+
if (outcome)
|
|
26
|
+
return outcome;
|
|
27
|
+
if (options.timeoutMs !== undefined && now() - startedAt >= options.timeoutMs) {
|
|
28
|
+
return {
|
|
29
|
+
decision: onTimeout,
|
|
30
|
+
reason: `gate: no decision within ${options.timeoutMs}ms`
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
await sleep(intervalMs);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** Decide every request the same way — for tests, and for a headless run that is
|
|
39
|
+
* explicitly configured to auto-approve. */
|
|
40
|
+
function staticApprovalChannel(outcome) {
|
|
41
|
+
return { request: () => Promise.resolve(outcome) };
|
|
42
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The run gate: evaluate the run's policy for one tool call and, when the policy
|
|
3
|
+
* will not decide alone, wait for a human through the approval channel.
|
|
4
|
+
*
|
|
5
|
+
* Harness-neutral on purpose. An adapter owns one line of glue — map its
|
|
6
|
+
* harness's tool-call event onto `decide()` and turn the outcome into whatever
|
|
7
|
+
* that harness expects from a blocked call — so the policy, the approval
|
|
8
|
+
* rendezvous and the audit record are the same for every harness.
|
|
9
|
+
*/
|
|
10
|
+
import { type ApprovalChannel, type ApprovalRequest } from './approvals';
|
|
11
|
+
import { RunGatePolicy, type RunGatePolicyOptions, type RunGateVerdict } from './run-policy';
|
|
12
|
+
export interface RunGateDecisionRecord {
|
|
13
|
+
runId: string;
|
|
14
|
+
toolCallId: string;
|
|
15
|
+
toolName: string;
|
|
16
|
+
input: Record<string, unknown>;
|
|
17
|
+
/** What the policy said. */
|
|
18
|
+
verdict: RunGateVerdict;
|
|
19
|
+
/** How the request was finally settled. */
|
|
20
|
+
decision: 'allow' | 'deny';
|
|
21
|
+
reason?: string;
|
|
22
|
+
actorId?: string;
|
|
23
|
+
decidedAt: string;
|
|
24
|
+
}
|
|
25
|
+
export interface RunGateOptions {
|
|
26
|
+
runId: string;
|
|
27
|
+
/** A policy, or the options to build one. */
|
|
28
|
+
policy: RunGatePolicy | RunGatePolicyOptions;
|
|
29
|
+
/** Required only if the policy can produce `ask`. */
|
|
30
|
+
approvals?: ApprovalChannel;
|
|
31
|
+
/** Every settled decision, for the run log / audit trail. */
|
|
32
|
+
onDecision?: (record: RunGateDecisionRecord) => void;
|
|
33
|
+
now?: () => Date;
|
|
34
|
+
}
|
|
35
|
+
export interface RunGateToolCall {
|
|
36
|
+
toolCallId: string;
|
|
37
|
+
toolName: string;
|
|
38
|
+
input?: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
export interface RunGateOutcome {
|
|
41
|
+
/** `false` means the harness must not run the call. */
|
|
42
|
+
allowed: boolean;
|
|
43
|
+
/** The model's only explanation for a refusal, so policies should be specific. */
|
|
44
|
+
reason?: string;
|
|
45
|
+
}
|
|
46
|
+
export declare class RunGate {
|
|
47
|
+
readonly policy: RunGatePolicy;
|
|
48
|
+
/** Requests currently waiting on a human. */
|
|
49
|
+
readonly pending: ReadonlyMap<string, ApprovalRequest>;
|
|
50
|
+
private readonly options;
|
|
51
|
+
private readonly now;
|
|
52
|
+
private readonly waiting;
|
|
53
|
+
constructor(options: RunGateOptions);
|
|
54
|
+
decide(call: RunGateToolCall): Promise<RunGateOutcome>;
|
|
55
|
+
private ask;
|
|
56
|
+
}
|
|
57
|
+
export declare function createRunGate(options: RunGateOptions): RunGate;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The run gate: evaluate the run's policy for one tool call and, when the policy
|
|
4
|
+
* will not decide alone, wait for a human through the approval channel.
|
|
5
|
+
*
|
|
6
|
+
* Harness-neutral on purpose. An adapter owns one line of glue — map its
|
|
7
|
+
* harness's tool-call event onto `decide()` and turn the outcome into whatever
|
|
8
|
+
* that harness expects from a blocked call — so the policy, the approval
|
|
9
|
+
* rendezvous and the audit record are the same for every harness.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.RunGate = void 0;
|
|
13
|
+
exports.createRunGate = createRunGate;
|
|
14
|
+
const run_policy_1 = require("./run-policy");
|
|
15
|
+
class RunGate {
|
|
16
|
+
policy;
|
|
17
|
+
/** Requests currently waiting on a human. */
|
|
18
|
+
pending;
|
|
19
|
+
options;
|
|
20
|
+
now;
|
|
21
|
+
waiting = new Map();
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this.options = options;
|
|
24
|
+
this.now = options.now ?? (() => new Date());
|
|
25
|
+
this.policy = options.policy instanceof run_policy_1.RunGatePolicy ? options.policy : new run_policy_1.RunGatePolicy(options.policy);
|
|
26
|
+
this.pending = this.waiting;
|
|
27
|
+
if (canAsk(this.policy) && !options.approvals) {
|
|
28
|
+
throw new Error('gate: the policy can produce "ask", so an approvals channel is required');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async decide(call) {
|
|
32
|
+
const input = call.input ?? {};
|
|
33
|
+
const verdict = this.policy.evaluate({ toolName: call.toolName, input });
|
|
34
|
+
const settled = verdict.decision === 'ask'
|
|
35
|
+
? await this.ask(call.toolCallId, call.toolName, input, verdict)
|
|
36
|
+
: { decision: verdict.decision, ...(verdict.reason === undefined ? {} : { reason: verdict.reason }) };
|
|
37
|
+
this.options.onDecision?.({
|
|
38
|
+
runId: this.options.runId,
|
|
39
|
+
toolCallId: call.toolCallId,
|
|
40
|
+
toolName: call.toolName,
|
|
41
|
+
input,
|
|
42
|
+
verdict,
|
|
43
|
+
decision: settled.decision,
|
|
44
|
+
...(settled.reason === undefined ? {} : { reason: settled.reason }),
|
|
45
|
+
...(settled.actorId === undefined ? {} : { actorId: settled.actorId }),
|
|
46
|
+
decidedAt: this.now().toISOString()
|
|
47
|
+
});
|
|
48
|
+
if (settled.decision === 'allow')
|
|
49
|
+
return { allowed: true };
|
|
50
|
+
return { allowed: false, reason: settled.reason ?? `gate: ${call.toolName} is not permitted in this run` };
|
|
51
|
+
}
|
|
52
|
+
async ask(toolCallId, toolName, input, verdict) {
|
|
53
|
+
const request = {
|
|
54
|
+
runId: this.options.runId,
|
|
55
|
+
toolCallId,
|
|
56
|
+
toolName,
|
|
57
|
+
input,
|
|
58
|
+
...(verdict.reason === undefined ? {} : { reason: verdict.reason }),
|
|
59
|
+
requestedAt: this.now().toISOString()
|
|
60
|
+
};
|
|
61
|
+
this.waiting.set(toolCallId, request);
|
|
62
|
+
try {
|
|
63
|
+
return await this.options.approvals.request(request);
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
this.waiting.delete(toolCallId);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.RunGate = RunGate;
|
|
71
|
+
function createRunGate(options) {
|
|
72
|
+
return new RunGate(options);
|
|
73
|
+
}
|
|
74
|
+
function canAsk(policy) {
|
|
75
|
+
const decisions = [policy.defaultDecision, ...policy.rules.map((rule) => rule.decision)];
|
|
76
|
+
return decisions.includes('ask');
|
|
77
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The declared half of the run gate: which tool calls run, which are refused,
|
|
3
|
+
* and which need a human. A policy is data — an ordered rule list evaluated with
|
|
4
|
+
* no I/O — so the same policy can be asserted in a test, stored on a run row,
|
|
5
|
+
* and shown in a UI.
|
|
6
|
+
*
|
|
7
|
+
* This is the *run's* policy, decided wherever the run is configured and
|
|
8
|
+
* enforceable without a UI, as opposed to `ConfirmGatePolicy` in
|
|
9
|
+
* `./policy`, which is a host's interactive confirm surface. Harness-neutral:
|
|
10
|
+
* an adapter maps its own tool-call event onto `RunGateRequest`.
|
|
11
|
+
*/
|
|
12
|
+
export type RunGateDecision = 'allow' | 'deny' | 'ask';
|
|
13
|
+
export interface RunGateRequest {
|
|
14
|
+
toolName: string;
|
|
15
|
+
input: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
export interface RunGateRule {
|
|
18
|
+
/** Tool name, or `*` for every tool. */
|
|
19
|
+
tool: string;
|
|
20
|
+
decision: RunGateDecision;
|
|
21
|
+
/** Narrow the rule to particular arguments (e.g. a bash command pattern). */
|
|
22
|
+
match?: (request: RunGateRequest) => boolean;
|
|
23
|
+
/** Shown to the model when denied, and to the human when asked. */
|
|
24
|
+
reason?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface RunGateVerdict {
|
|
27
|
+
decision: RunGateDecision;
|
|
28
|
+
reason?: string;
|
|
29
|
+
/** The rule that decided, or `undefined` when the default applied. */
|
|
30
|
+
rule?: RunGateRule;
|
|
31
|
+
}
|
|
32
|
+
export interface RunGatePolicyOptions {
|
|
33
|
+
rules?: readonly RunGateRule[];
|
|
34
|
+
/** Verdict when no rule matches. Defaults to `ask` — an undeclared tool is
|
|
35
|
+
* not implicitly trusted, and denying outright would strand the run. */
|
|
36
|
+
defaultDecision?: RunGateDecision;
|
|
37
|
+
defaultReason?: string;
|
|
38
|
+
}
|
|
39
|
+
export declare class RunGatePolicy {
|
|
40
|
+
readonly rules: readonly RunGateRule[];
|
|
41
|
+
readonly defaultDecision: RunGateDecision;
|
|
42
|
+
private readonly defaultReason;
|
|
43
|
+
constructor(options?: RunGatePolicyOptions);
|
|
44
|
+
/** First matching rule wins, so order the list most specific first. */
|
|
45
|
+
evaluate(request: RunGateRequest): RunGateVerdict;
|
|
46
|
+
}
|
|
47
|
+
export declare function runGatePolicy(options?: RunGatePolicyOptions): RunGatePolicy;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The declared half of the run gate: which tool calls run, which are refused,
|
|
4
|
+
* and which need a human. A policy is data — an ordered rule list evaluated with
|
|
5
|
+
* no I/O — so the same policy can be asserted in a test, stored on a run row,
|
|
6
|
+
* and shown in a UI.
|
|
7
|
+
*
|
|
8
|
+
* This is the *run's* policy, decided wherever the run is configured and
|
|
9
|
+
* enforceable without a UI, as opposed to `ConfirmGatePolicy` in
|
|
10
|
+
* `./policy`, which is a host's interactive confirm surface. Harness-neutral:
|
|
11
|
+
* an adapter maps its own tool-call event onto `RunGateRequest`.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.RunGatePolicy = void 0;
|
|
15
|
+
exports.runGatePolicy = runGatePolicy;
|
|
16
|
+
class RunGatePolicy {
|
|
17
|
+
rules;
|
|
18
|
+
defaultDecision;
|
|
19
|
+
defaultReason;
|
|
20
|
+
constructor(options = {}) {
|
|
21
|
+
this.rules = options.rules ?? [];
|
|
22
|
+
this.defaultDecision = options.defaultDecision ?? 'ask';
|
|
23
|
+
this.defaultReason = options.defaultReason;
|
|
24
|
+
for (const rule of this.rules) {
|
|
25
|
+
if (!rule.tool)
|
|
26
|
+
throw new Error('gate: every rule needs a tool name (or "*")');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** First matching rule wins, so order the list most specific first. */
|
|
30
|
+
evaluate(request) {
|
|
31
|
+
for (const rule of this.rules) {
|
|
32
|
+
if (rule.tool !== '*' && rule.tool !== request.toolName)
|
|
33
|
+
continue;
|
|
34
|
+
if (rule.match && !rule.match(request))
|
|
35
|
+
continue;
|
|
36
|
+
return rule.reason === undefined
|
|
37
|
+
? { decision: rule.decision, rule }
|
|
38
|
+
: { decision: rule.decision, reason: rule.reason, rule };
|
|
39
|
+
}
|
|
40
|
+
return this.defaultReason === undefined
|
|
41
|
+
? { decision: this.defaultDecision }
|
|
42
|
+
: { decision: this.defaultDecision, reason: this.defaultReason };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.RunGatePolicy = RunGatePolicy;
|
|
46
|
+
function runGatePolicy(options = {}) {
|
|
47
|
+
return new RunGatePolicy(options);
|
|
48
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
export * from './adapter';
|
|
1
2
|
export * from './blueprint/blueprint-defaults';
|
|
2
3
|
export * from './blueprint/blueprint-schema';
|
|
3
4
|
export * from './blueprint/field-type';
|
|
4
5
|
export * from './blueprint/internal-policies';
|
|
5
6
|
export * from './blueprint/policy-provisioning';
|
|
7
|
+
export * from './gating/approvals';
|
|
6
8
|
export * from './gating/confirm-gate';
|
|
7
9
|
export * from './gating/constructive-policy';
|
|
8
10
|
export * from './gating/decline-guard';
|
|
9
11
|
export * from './gating/policy';
|
|
10
12
|
export * from './gating/preview';
|
|
11
13
|
export * from './gating/prompts';
|
|
14
|
+
export * from './gating/run-gate';
|
|
15
|
+
export * from './gating/run-policy';
|
|
12
16
|
export * from './skills/default-source';
|
|
13
17
|
export * from './skills/fetch';
|
|
14
18
|
export * from './skills/frontmatter';
|
package/index.js
CHANGED
|
@@ -14,17 +14,21 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./adapter"), exports);
|
|
17
18
|
__exportStar(require("./blueprint/blueprint-defaults"), exports);
|
|
18
19
|
__exportStar(require("./blueprint/blueprint-schema"), exports);
|
|
19
20
|
__exportStar(require("./blueprint/field-type"), exports);
|
|
20
21
|
__exportStar(require("./blueprint/internal-policies"), exports);
|
|
21
22
|
__exportStar(require("./blueprint/policy-provisioning"), exports);
|
|
23
|
+
__exportStar(require("./gating/approvals"), exports);
|
|
22
24
|
__exportStar(require("./gating/confirm-gate"), exports);
|
|
23
25
|
__exportStar(require("./gating/constructive-policy"), exports);
|
|
24
26
|
__exportStar(require("./gating/decline-guard"), exports);
|
|
25
27
|
__exportStar(require("./gating/policy"), exports);
|
|
26
28
|
__exportStar(require("./gating/preview"), exports);
|
|
27
29
|
__exportStar(require("./gating/prompts"), exports);
|
|
30
|
+
__exportStar(require("./gating/run-gate"), exports);
|
|
31
|
+
__exportStar(require("./gating/run-policy"), exports);
|
|
28
32
|
__exportStar(require("./skills/default-source"), exports);
|
|
29
33
|
__exportStar(require("./skills/fetch"), exports);
|
|
30
34
|
__exportStar(require("./skills/frontmatter"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentic-kit/harness",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.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.8.0"
|
|
39
39
|
},
|
|
40
40
|
"keywords": [],
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "b5b6b9f05276b7e9cbd3d1f4acd31dd315c353ea"
|
|
42
42
|
}
|