@agentic-kit/harness 0.11.0 → 0.12.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/esm/gating/confirm-gate.d.ts +21 -32
- package/esm/gating/confirm-gate.js +15 -40
- package/esm/gating/constructive-policy.d.ts +35 -0
- package/esm/gating/constructive-policy.js +45 -0
- package/esm/gating/policy.d.ts +36 -0
- package/esm/gating/policy.js +1 -0
- package/esm/gating/preview.d.ts +6 -0
- package/esm/gating/prompts.d.ts +1 -6
- package/esm/index.d.ts +2 -0
- package/esm/index.js +2 -0
- package/gating/confirm-gate.d.ts +21 -32
- package/gating/confirm-gate.js +15 -40
- package/gating/constructive-policy.d.ts +35 -0
- package/gating/constructive-policy.js +48 -0
- package/gating/policy.d.ts +36 -0
- package/gating/policy.js +2 -0
- package/gating/preview.d.ts +6 -0
- package/gating/prompts.d.ts +1 -6
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +2 -2
|
@@ -1,15 +1,14 @@
|
|
|
1
|
+
import type { ConstructiveGateDeps } from './constructive-policy';
|
|
2
|
+
import type { GatePolicy, GateToolCallEvent } from './policy';
|
|
1
3
|
import type { ConfirmPreview } from './preview';
|
|
2
4
|
/**
|
|
3
|
-
* Host-neutral confirm gate
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Host-neutral confirm gate. It owns the mechanics of asking a human —
|
|
6
|
+
* decline memory, auto-skipping a declined retry, refusing gated calls on a
|
|
7
|
+
* headless host — and takes both the host's capabilities (confirm UI, skip
|
|
8
|
+
* notification) and its policy (which calls are gated, what the prompt says)
|
|
9
|
+
* as injected dependencies. Structurally mirrors the pi extension `tool_call`
|
|
10
|
+
* hook so a pi adapter is a thin mapping: no Electron, no pi imports.
|
|
7
11
|
*/
|
|
8
|
-
export type GateToolCallEvent = {
|
|
9
|
-
toolName: string;
|
|
10
|
-
toolCallId: string;
|
|
11
|
-
input?: Record<string, unknown>;
|
|
12
|
-
};
|
|
13
12
|
/** `block: true` stops the tool call; `reason` is surfaced to the agent. */
|
|
14
13
|
export type GateResult = {
|
|
15
14
|
block: true;
|
|
@@ -23,31 +22,21 @@ export type GateHost = {
|
|
|
23
22
|
/** A retry of an already-declined call was auto-skipped without prompting. */
|
|
24
23
|
notifyToolSkipped(toolCallId: string): void;
|
|
25
24
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
* preview can't be built.
|
|
39
|
-
*/
|
|
40
|
-
resolveTemplatePreview(cwd: string, blueprintName: string | undefined, displayName: string): Promise<ConfirmPreview | undefined>;
|
|
41
|
-
/**
|
|
42
|
-
* Tool names that require a human decision. The policy belongs to the host,
|
|
43
|
-
* not the harness: Desktop/CLI gate Constructive's mutating db tools, a
|
|
44
|
-
* remote coding host gates a different set. Defaults to
|
|
45
|
-
* `MUTATING_DB_TOOLS`.
|
|
46
|
-
*/
|
|
47
|
-
gatedTools?: ReadonlySet<string>;
|
|
25
|
+
/**
|
|
26
|
+
* The Constructive database deps, from which the gate derives the default
|
|
27
|
+
* `GatePolicy`. Kept as the name every existing host passes.
|
|
28
|
+
*/
|
|
29
|
+
export type ConfirmGateDeps = ConstructiveGateDeps;
|
|
30
|
+
/**
|
|
31
|
+
* Either hand the gate the Constructive deps and get its database policy, or
|
|
32
|
+
* hand it a policy of your own — a remote coding host gating `bash` has no
|
|
33
|
+
* project context or data token to speak of.
|
|
34
|
+
*/
|
|
35
|
+
export type ConfirmGateOptions = ConfirmGateDeps | {
|
|
36
|
+
policy: GatePolicy;
|
|
48
37
|
};
|
|
49
38
|
export type ConfirmGate = {
|
|
50
39
|
onAgentStart: () => void;
|
|
51
40
|
onToolCall: (event: GateToolCallEvent, host: GateHost, cwd: string) => Promise<GateResult>;
|
|
52
41
|
};
|
|
53
|
-
export declare function createConfirmGate(
|
|
42
|
+
export declare function createConfirmGate(options: ConfirmGateOptions): ConfirmGate;
|
|
@@ -1,31 +1,14 @@
|
|
|
1
|
+
import { createConstructiveGatePolicy } from './constructive-policy';
|
|
1
2
|
import { buildDeclineReason, createDeclineGuard } from './decline-guard';
|
|
2
|
-
|
|
3
|
-
export function createConfirmGate(deps) {
|
|
3
|
+
export function createConfirmGate(options) {
|
|
4
4
|
const declineGuard = createDeclineGuard();
|
|
5
|
-
const
|
|
6
|
-
async function confirmOrDecline(event, host, input, preview) {
|
|
7
|
-
const { title, message, preview: basePreview } = buildConfirmPrompt(event.toolName, input);
|
|
8
|
-
const approved = await host.confirmTool(event.toolCallId, title, message, preview ?? basePreview);
|
|
9
|
-
if (!approved) {
|
|
10
|
-
declineGuard.recordDecline(event.toolName, input);
|
|
11
|
-
return { block: true, reason: buildDeclineReason(event.toolName) };
|
|
12
|
-
}
|
|
13
|
-
// An approved mutation changes database state, so earlier declines may no
|
|
14
|
-
// longer describe the same effect (e.g. a create_template preview derives
|
|
15
|
-
// from the blueprint, not the input) — let them re-prompt with fresh eyes.
|
|
16
|
-
declineGuard.clear();
|
|
17
|
-
return undefined;
|
|
18
|
-
}
|
|
5
|
+
const policy = 'policy' in options ? options.policy : createConstructiveGatePolicy(options);
|
|
19
6
|
return {
|
|
20
7
|
onAgentStart: () => declineGuard.clear(),
|
|
21
8
|
onToolCall: async (event, host, cwd) => {
|
|
22
|
-
if (!
|
|
9
|
+
if (!policy.isGated(event))
|
|
23
10
|
return;
|
|
24
11
|
const input = event.input;
|
|
25
|
-
// manage_entity_types multiplexes read + write actions behind one tool
|
|
26
|
-
// name; its read action is not a mutation, so it skips the gate.
|
|
27
|
-
if (event.toolName === 'manage_entity_types' && input?.action === 'list')
|
|
28
|
-
return;
|
|
29
12
|
const retryBlock = declineGuard.checkRetry(event.toolName, input);
|
|
30
13
|
if (retryBlock) {
|
|
31
14
|
if (host.hasUI) {
|
|
@@ -39,27 +22,19 @@ export function createConfirmGate(deps) {
|
|
|
39
22
|
reason: `Cannot confirm "${event.toolName}" — no confirmation UI is available.`,
|
|
40
23
|
};
|
|
41
24
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (event.toolName === 'provision_database') {
|
|
45
|
-
return confirmOrDecline(event, host, input);
|
|
46
|
-
}
|
|
47
|
-
if (!(await deps.isProjectRunnable(cwd)))
|
|
25
|
+
const prompt = await policy.resolvePrompt(event, cwd);
|
|
26
|
+
if (!prompt)
|
|
48
27
|
return;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
!(await deps.hasDataToken(cwd))) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
let resolvedPreview;
|
|
57
|
-
if (event.toolName === 'create_template') {
|
|
58
|
-
const blueprintName = typeof input?.blueprintName === 'string' ? input.blueprintName : undefined;
|
|
59
|
-
const displayName = typeof input?.displayName === 'string' ? input.displayName : '';
|
|
60
|
-
resolvedPreview = await deps.resolveTemplatePreview(cwd, blueprintName, displayName);
|
|
28
|
+
const approved = await host.confirmTool(event.toolCallId, prompt.title, prompt.message, prompt.preview);
|
|
29
|
+
if (!approved) {
|
|
30
|
+
declineGuard.recordDecline(event.toolName, input);
|
|
31
|
+
return { block: true, reason: buildDeclineReason(event.toolName) };
|
|
61
32
|
}
|
|
62
|
-
|
|
33
|
+
// An approved mutation changes state, so earlier declines may no longer
|
|
34
|
+
// describe the same effect (e.g. a create_template preview derives from
|
|
35
|
+
// the blueprint, not the input) — let them re-prompt with fresh eyes.
|
|
36
|
+
declineGuard.clear();
|
|
37
|
+
return undefined;
|
|
63
38
|
},
|
|
64
39
|
};
|
|
65
40
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { GatePolicy } from './policy';
|
|
2
|
+
import type { ConfirmPreview } from './preview';
|
|
3
|
+
/**
|
|
4
|
+
* Host capabilities the Constructive database policy needs. These are
|
|
5
|
+
* Constructive-specific — a policy for another host asks for whatever *its*
|
|
6
|
+
* rules depend on instead.
|
|
7
|
+
*/
|
|
8
|
+
export type ConstructiveGateDeps = {
|
|
9
|
+
/**
|
|
10
|
+
* Whether the project is provisioned/runnable at `cwd`. Unrunnable calls
|
|
11
|
+
* skip the confirm so the tool can return its clean "provision first"
|
|
12
|
+
* message instead of making the user approve something that fails.
|
|
13
|
+
*/
|
|
14
|
+
isProjectRunnable(cwd: string): Promise<boolean>;
|
|
15
|
+
/** Whether a data-plane token is available (gates `add_records`). */
|
|
16
|
+
hasDataToken(cwd: string): Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* Resolve the preview for `create_template` (its tables live in the
|
|
19
|
+
* blueprint it copies, not in the tool input). Return undefined when a
|
|
20
|
+
* preview can't be built.
|
|
21
|
+
*/
|
|
22
|
+
resolveTemplatePreview(cwd: string, blueprintName: string | undefined, displayName: string): Promise<ConfirmPreview | undefined>;
|
|
23
|
+
/**
|
|
24
|
+
* Tool names that require a human decision. Defaults to
|
|
25
|
+
* `MUTATING_DB_TOOLS`; a host that wants a different set entirely is better
|
|
26
|
+
* served by its own `GatePolicy`.
|
|
27
|
+
*/
|
|
28
|
+
gatedTools?: ReadonlySet<string>;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* The gate policy for Constructive's database tools, as the Desktop and CLI
|
|
32
|
+
* hosts want it: gate every mutating db tool, and skip the confirm when the
|
|
33
|
+
* call is going to bounce off a missing project or a missing sign-in anyway.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createConstructiveGatePolicy(deps: ConstructiveGateDeps): GatePolicy;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { buildConfirmPrompt, MUTATING_DB_TOOLS } from './prompts';
|
|
2
|
+
/**
|
|
3
|
+
* The gate policy for Constructive's database tools, as the Desktop and CLI
|
|
4
|
+
* hosts want it: gate every mutating db tool, and skip the confirm when the
|
|
5
|
+
* call is going to bounce off a missing project or a missing sign-in anyway.
|
|
6
|
+
*/
|
|
7
|
+
export function createConstructiveGatePolicy(deps) {
|
|
8
|
+
const gatedTools = deps.gatedTools ?? MUTATING_DB_TOOLS;
|
|
9
|
+
return {
|
|
10
|
+
isGated: (event) => {
|
|
11
|
+
if (!gatedTools.has(event.toolName))
|
|
12
|
+
return false;
|
|
13
|
+
// manage_entity_types multiplexes read + write actions behind one tool
|
|
14
|
+
// name; its read action is not a mutation, so it skips the gate.
|
|
15
|
+
if (event.toolName === 'manage_entity_types' && event.input?.action === 'list')
|
|
16
|
+
return false;
|
|
17
|
+
return true;
|
|
18
|
+
},
|
|
19
|
+
resolvePrompt: async (event, cwd) => {
|
|
20
|
+
const input = event.input;
|
|
21
|
+
const prompt = buildConfirmPrompt(event.toolName, input);
|
|
22
|
+
// provision_database is the tool that CREATES the project context, so it
|
|
23
|
+
// can't gate on an existing one — confirm it directly.
|
|
24
|
+
if (event.toolName === 'provision_database')
|
|
25
|
+
return prompt;
|
|
26
|
+
if (!(await deps.isProjectRunnable(cwd)))
|
|
27
|
+
return null;
|
|
28
|
+
// Tools that need an app sign-in skip the confirm when no data token
|
|
29
|
+
// exists — the tool returns its sign-in prompt instead of making the
|
|
30
|
+
// user approve something that fails.
|
|
31
|
+
if ((event.toolName === 'add_records' || event.toolName === 'create_api_key') &&
|
|
32
|
+
!(await deps.hasDataToken(cwd))) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
if (event.toolName === 'create_template') {
|
|
36
|
+
const blueprintName = typeof input?.blueprintName === 'string' ? input.blueprintName : undefined;
|
|
37
|
+
const displayName = typeof input?.displayName === 'string' ? input.displayName : '';
|
|
38
|
+
const preview = await deps.resolveTemplatePreview(cwd, blueprintName, displayName);
|
|
39
|
+
if (preview)
|
|
40
|
+
return { ...prompt, preview };
|
|
41
|
+
}
|
|
42
|
+
return prompt;
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ConfirmPrompt } from './preview';
|
|
2
|
+
/**
|
|
3
|
+
* What the gate knows about a tool call. Hosts map their agent's event shape
|
|
4
|
+
* onto this (pi's `ToolCallEvent`, an MCP request, …).
|
|
5
|
+
*/
|
|
6
|
+
export type GateToolCallEvent = {
|
|
7
|
+
toolName: string;
|
|
8
|
+
toolCallId: string;
|
|
9
|
+
input?: Record<string, unknown>;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* The host's answer to "which calls need a human decision, and what do we show
|
|
13
|
+
* the human?". Everything tool-specific lives here — which tool names are
|
|
14
|
+
* gated, which arguments turn a gated name into a harmless read, and the
|
|
15
|
+
* wording of the confirmation — so the gate itself stays host-neutral and only
|
|
16
|
+
* owns the mechanics (decline memory, headless blocking, prompting).
|
|
17
|
+
*
|
|
18
|
+
* `createConstructiveGatePolicy` is the Constructive database policy the
|
|
19
|
+
* Desktop/CLI hosts use; a remote coding host supplies its own.
|
|
20
|
+
*/
|
|
21
|
+
export type GatePolicy = {
|
|
22
|
+
/**
|
|
23
|
+
* Whether this call needs a human decision at all. Cheap and synchronous:
|
|
24
|
+
* it runs before the decline memory and the headless block, so it must
|
|
25
|
+
* decide from the tool name and arguments alone — no I/O.
|
|
26
|
+
*/
|
|
27
|
+
isGated(event: GateToolCallEvent): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* The prompt to put in front of the user, or `null` to let an already-gated
|
|
30
|
+
* call through without one. Runs only for gated calls on a host with a
|
|
31
|
+
* confirm surface, so it may do I/O to build a richer preview or to check a
|
|
32
|
+
* precondition that makes the confirm pointless (e.g. the call is going to
|
|
33
|
+
* fail with "sign in first" anyway).
|
|
34
|
+
*/
|
|
35
|
+
resolvePrompt(event: GateToolCallEvent, cwd: string): Promise<ConfirmPrompt | null>;
|
|
36
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/gating/preview.d.ts
CHANGED
|
@@ -35,3 +35,9 @@ export type ConfirmPreview = {
|
|
|
35
35
|
tableName: string;
|
|
36
36
|
field: ConfirmPreviewField;
|
|
37
37
|
};
|
|
38
|
+
/** What a host puts in front of the user for one gated call. */
|
|
39
|
+
export type ConfirmPrompt = {
|
|
40
|
+
title: string;
|
|
41
|
+
message: string;
|
|
42
|
+
preview?: ConfirmPreview;
|
|
43
|
+
};
|
package/esm/gating/prompts.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
export declare const MUTATING_DB_TOOLS: Set<string>;
|
|
2
|
-
import type {
|
|
3
|
-
export type ConfirmPrompt = {
|
|
4
|
-
title: string;
|
|
5
|
-
message: string;
|
|
6
|
-
preview?: ConfirmPreview;
|
|
7
|
-
};
|
|
2
|
+
import type { ConfirmPrompt } from './preview';
|
|
8
3
|
export declare function buildConfirmPrompt(toolName: string, input: Record<string, unknown> | undefined): ConfirmPrompt;
|
package/esm/index.d.ts
CHANGED
|
@@ -4,7 +4,9 @@ export * from './blueprint/field-type';
|
|
|
4
4
|
export * from './blueprint/internal-policies';
|
|
5
5
|
export * from './blueprint/policy-provisioning';
|
|
6
6
|
export * from './gating/confirm-gate';
|
|
7
|
+
export * from './gating/constructive-policy';
|
|
7
8
|
export * from './gating/decline-guard';
|
|
9
|
+
export * from './gating/policy';
|
|
8
10
|
export * from './gating/preview';
|
|
9
11
|
export * from './gating/prompts';
|
|
10
12
|
export * from './skills/default-source';
|
package/esm/index.js
CHANGED
|
@@ -4,7 +4,9 @@ export * from './blueprint/field-type';
|
|
|
4
4
|
export * from './blueprint/internal-policies';
|
|
5
5
|
export * from './blueprint/policy-provisioning';
|
|
6
6
|
export * from './gating/confirm-gate';
|
|
7
|
+
export * from './gating/constructive-policy';
|
|
7
8
|
export * from './gating/decline-guard';
|
|
9
|
+
export * from './gating/policy';
|
|
8
10
|
export * from './gating/preview';
|
|
9
11
|
export * from './gating/prompts';
|
|
10
12
|
export * from './skills/default-source';
|
package/gating/confirm-gate.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
+
import type { ConstructiveGateDeps } from './constructive-policy';
|
|
2
|
+
import type { GatePolicy, GateToolCallEvent } from './policy';
|
|
1
3
|
import type { ConfirmPreview } from './preview';
|
|
2
4
|
/**
|
|
3
|
-
* Host-neutral confirm gate
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Host-neutral confirm gate. It owns the mechanics of asking a human —
|
|
6
|
+
* decline memory, auto-skipping a declined retry, refusing gated calls on a
|
|
7
|
+
* headless host — and takes both the host's capabilities (confirm UI, skip
|
|
8
|
+
* notification) and its policy (which calls are gated, what the prompt says)
|
|
9
|
+
* as injected dependencies. Structurally mirrors the pi extension `tool_call`
|
|
10
|
+
* hook so a pi adapter is a thin mapping: no Electron, no pi imports.
|
|
7
11
|
*/
|
|
8
|
-
export type GateToolCallEvent = {
|
|
9
|
-
toolName: string;
|
|
10
|
-
toolCallId: string;
|
|
11
|
-
input?: Record<string, unknown>;
|
|
12
|
-
};
|
|
13
12
|
/** `block: true` stops the tool call; `reason` is surfaced to the agent. */
|
|
14
13
|
export type GateResult = {
|
|
15
14
|
block: true;
|
|
@@ -23,31 +22,21 @@ export type GateHost = {
|
|
|
23
22
|
/** A retry of an already-declined call was auto-skipped without prompting. */
|
|
24
23
|
notifyToolSkipped(toolCallId: string): void;
|
|
25
24
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
* preview can't be built.
|
|
39
|
-
*/
|
|
40
|
-
resolveTemplatePreview(cwd: string, blueprintName: string | undefined, displayName: string): Promise<ConfirmPreview | undefined>;
|
|
41
|
-
/**
|
|
42
|
-
* Tool names that require a human decision. The policy belongs to the host,
|
|
43
|
-
* not the harness: Desktop/CLI gate Constructive's mutating db tools, a
|
|
44
|
-
* remote coding host gates a different set. Defaults to
|
|
45
|
-
* `MUTATING_DB_TOOLS`.
|
|
46
|
-
*/
|
|
47
|
-
gatedTools?: ReadonlySet<string>;
|
|
25
|
+
/**
|
|
26
|
+
* The Constructive database deps, from which the gate derives the default
|
|
27
|
+
* `GatePolicy`. Kept as the name every existing host passes.
|
|
28
|
+
*/
|
|
29
|
+
export type ConfirmGateDeps = ConstructiveGateDeps;
|
|
30
|
+
/**
|
|
31
|
+
* Either hand the gate the Constructive deps and get its database policy, or
|
|
32
|
+
* hand it a policy of your own — a remote coding host gating `bash` has no
|
|
33
|
+
* project context or data token to speak of.
|
|
34
|
+
*/
|
|
35
|
+
export type ConfirmGateOptions = ConfirmGateDeps | {
|
|
36
|
+
policy: GatePolicy;
|
|
48
37
|
};
|
|
49
38
|
export type ConfirmGate = {
|
|
50
39
|
onAgentStart: () => void;
|
|
51
40
|
onToolCall: (event: GateToolCallEvent, host: GateHost, cwd: string) => Promise<GateResult>;
|
|
52
41
|
};
|
|
53
|
-
export declare function createConfirmGate(
|
|
42
|
+
export declare function createConfirmGate(options: ConfirmGateOptions): ConfirmGate;
|
package/gating/confirm-gate.js
CHANGED
|
@@ -1,34 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createConfirmGate = createConfirmGate;
|
|
4
|
+
const constructive_policy_1 = require("./constructive-policy");
|
|
4
5
|
const decline_guard_1 = require("./decline-guard");
|
|
5
|
-
|
|
6
|
-
function createConfirmGate(deps) {
|
|
6
|
+
function createConfirmGate(options) {
|
|
7
7
|
const declineGuard = (0, decline_guard_1.createDeclineGuard)();
|
|
8
|
-
const
|
|
9
|
-
async function confirmOrDecline(event, host, input, preview) {
|
|
10
|
-
const { title, message, preview: basePreview } = (0, prompts_1.buildConfirmPrompt)(event.toolName, input);
|
|
11
|
-
const approved = await host.confirmTool(event.toolCallId, title, message, preview ?? basePreview);
|
|
12
|
-
if (!approved) {
|
|
13
|
-
declineGuard.recordDecline(event.toolName, input);
|
|
14
|
-
return { block: true, reason: (0, decline_guard_1.buildDeclineReason)(event.toolName) };
|
|
15
|
-
}
|
|
16
|
-
// An approved mutation changes database state, so earlier declines may no
|
|
17
|
-
// longer describe the same effect (e.g. a create_template preview derives
|
|
18
|
-
// from the blueprint, not the input) — let them re-prompt with fresh eyes.
|
|
19
|
-
declineGuard.clear();
|
|
20
|
-
return undefined;
|
|
21
|
-
}
|
|
8
|
+
const policy = 'policy' in options ? options.policy : (0, constructive_policy_1.createConstructiveGatePolicy)(options);
|
|
22
9
|
return {
|
|
23
10
|
onAgentStart: () => declineGuard.clear(),
|
|
24
11
|
onToolCall: async (event, host, cwd) => {
|
|
25
|
-
if (!
|
|
12
|
+
if (!policy.isGated(event))
|
|
26
13
|
return;
|
|
27
14
|
const input = event.input;
|
|
28
|
-
// manage_entity_types multiplexes read + write actions behind one tool
|
|
29
|
-
// name; its read action is not a mutation, so it skips the gate.
|
|
30
|
-
if (event.toolName === 'manage_entity_types' && input?.action === 'list')
|
|
31
|
-
return;
|
|
32
15
|
const retryBlock = declineGuard.checkRetry(event.toolName, input);
|
|
33
16
|
if (retryBlock) {
|
|
34
17
|
if (host.hasUI) {
|
|
@@ -42,27 +25,19 @@ function createConfirmGate(deps) {
|
|
|
42
25
|
reason: `Cannot confirm "${event.toolName}" — no confirmation UI is available.`,
|
|
43
26
|
};
|
|
44
27
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (event.toolName === 'provision_database') {
|
|
48
|
-
return confirmOrDecline(event, host, input);
|
|
49
|
-
}
|
|
50
|
-
if (!(await deps.isProjectRunnable(cwd)))
|
|
28
|
+
const prompt = await policy.resolvePrompt(event, cwd);
|
|
29
|
+
if (!prompt)
|
|
51
30
|
return;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
!(await deps.hasDataToken(cwd))) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
let resolvedPreview;
|
|
60
|
-
if (event.toolName === 'create_template') {
|
|
61
|
-
const blueprintName = typeof input?.blueprintName === 'string' ? input.blueprintName : undefined;
|
|
62
|
-
const displayName = typeof input?.displayName === 'string' ? input.displayName : '';
|
|
63
|
-
resolvedPreview = await deps.resolveTemplatePreview(cwd, blueprintName, displayName);
|
|
31
|
+
const approved = await host.confirmTool(event.toolCallId, prompt.title, prompt.message, prompt.preview);
|
|
32
|
+
if (!approved) {
|
|
33
|
+
declineGuard.recordDecline(event.toolName, input);
|
|
34
|
+
return { block: true, reason: (0, decline_guard_1.buildDeclineReason)(event.toolName) };
|
|
64
35
|
}
|
|
65
|
-
|
|
36
|
+
// An approved mutation changes state, so earlier declines may no longer
|
|
37
|
+
// describe the same effect (e.g. a create_template preview derives from
|
|
38
|
+
// the blueprint, not the input) — let them re-prompt with fresh eyes.
|
|
39
|
+
declineGuard.clear();
|
|
40
|
+
return undefined;
|
|
66
41
|
},
|
|
67
42
|
};
|
|
68
43
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { GatePolicy } from './policy';
|
|
2
|
+
import type { ConfirmPreview } from './preview';
|
|
3
|
+
/**
|
|
4
|
+
* Host capabilities the Constructive database policy needs. These are
|
|
5
|
+
* Constructive-specific — a policy for another host asks for whatever *its*
|
|
6
|
+
* rules depend on instead.
|
|
7
|
+
*/
|
|
8
|
+
export type ConstructiveGateDeps = {
|
|
9
|
+
/**
|
|
10
|
+
* Whether the project is provisioned/runnable at `cwd`. Unrunnable calls
|
|
11
|
+
* skip the confirm so the tool can return its clean "provision first"
|
|
12
|
+
* message instead of making the user approve something that fails.
|
|
13
|
+
*/
|
|
14
|
+
isProjectRunnable(cwd: string): Promise<boolean>;
|
|
15
|
+
/** Whether a data-plane token is available (gates `add_records`). */
|
|
16
|
+
hasDataToken(cwd: string): Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* Resolve the preview for `create_template` (its tables live in the
|
|
19
|
+
* blueprint it copies, not in the tool input). Return undefined when a
|
|
20
|
+
* preview can't be built.
|
|
21
|
+
*/
|
|
22
|
+
resolveTemplatePreview(cwd: string, blueprintName: string | undefined, displayName: string): Promise<ConfirmPreview | undefined>;
|
|
23
|
+
/**
|
|
24
|
+
* Tool names that require a human decision. Defaults to
|
|
25
|
+
* `MUTATING_DB_TOOLS`; a host that wants a different set entirely is better
|
|
26
|
+
* served by its own `GatePolicy`.
|
|
27
|
+
*/
|
|
28
|
+
gatedTools?: ReadonlySet<string>;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* The gate policy for Constructive's database tools, as the Desktop and CLI
|
|
32
|
+
* hosts want it: gate every mutating db tool, and skip the confirm when the
|
|
33
|
+
* call is going to bounce off a missing project or a missing sign-in anyway.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createConstructiveGatePolicy(deps: ConstructiveGateDeps): GatePolicy;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createConstructiveGatePolicy = createConstructiveGatePolicy;
|
|
4
|
+
const prompts_1 = require("./prompts");
|
|
5
|
+
/**
|
|
6
|
+
* The gate policy for Constructive's database tools, as the Desktop and CLI
|
|
7
|
+
* hosts want it: gate every mutating db tool, and skip the confirm when the
|
|
8
|
+
* call is going to bounce off a missing project or a missing sign-in anyway.
|
|
9
|
+
*/
|
|
10
|
+
function createConstructiveGatePolicy(deps) {
|
|
11
|
+
const gatedTools = deps.gatedTools ?? prompts_1.MUTATING_DB_TOOLS;
|
|
12
|
+
return {
|
|
13
|
+
isGated: (event) => {
|
|
14
|
+
if (!gatedTools.has(event.toolName))
|
|
15
|
+
return false;
|
|
16
|
+
// manage_entity_types multiplexes read + write actions behind one tool
|
|
17
|
+
// name; its read action is not a mutation, so it skips the gate.
|
|
18
|
+
if (event.toolName === 'manage_entity_types' && event.input?.action === 'list')
|
|
19
|
+
return false;
|
|
20
|
+
return true;
|
|
21
|
+
},
|
|
22
|
+
resolvePrompt: async (event, cwd) => {
|
|
23
|
+
const input = event.input;
|
|
24
|
+
const prompt = (0, prompts_1.buildConfirmPrompt)(event.toolName, input);
|
|
25
|
+
// provision_database is the tool that CREATES the project context, so it
|
|
26
|
+
// can't gate on an existing one — confirm it directly.
|
|
27
|
+
if (event.toolName === 'provision_database')
|
|
28
|
+
return prompt;
|
|
29
|
+
if (!(await deps.isProjectRunnable(cwd)))
|
|
30
|
+
return null;
|
|
31
|
+
// Tools that need an app sign-in skip the confirm when no data token
|
|
32
|
+
// exists — the tool returns its sign-in prompt instead of making the
|
|
33
|
+
// user approve something that fails.
|
|
34
|
+
if ((event.toolName === 'add_records' || event.toolName === 'create_api_key') &&
|
|
35
|
+
!(await deps.hasDataToken(cwd))) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
if (event.toolName === 'create_template') {
|
|
39
|
+
const blueprintName = typeof input?.blueprintName === 'string' ? input.blueprintName : undefined;
|
|
40
|
+
const displayName = typeof input?.displayName === 'string' ? input.displayName : '';
|
|
41
|
+
const preview = await deps.resolveTemplatePreview(cwd, blueprintName, displayName);
|
|
42
|
+
if (preview)
|
|
43
|
+
return { ...prompt, preview };
|
|
44
|
+
}
|
|
45
|
+
return prompt;
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ConfirmPrompt } from './preview';
|
|
2
|
+
/**
|
|
3
|
+
* What the gate knows about a tool call. Hosts map their agent's event shape
|
|
4
|
+
* onto this (pi's `ToolCallEvent`, an MCP request, …).
|
|
5
|
+
*/
|
|
6
|
+
export type GateToolCallEvent = {
|
|
7
|
+
toolName: string;
|
|
8
|
+
toolCallId: string;
|
|
9
|
+
input?: Record<string, unknown>;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* The host's answer to "which calls need a human decision, and what do we show
|
|
13
|
+
* the human?". Everything tool-specific lives here — which tool names are
|
|
14
|
+
* gated, which arguments turn a gated name into a harmless read, and the
|
|
15
|
+
* wording of the confirmation — so the gate itself stays host-neutral and only
|
|
16
|
+
* owns the mechanics (decline memory, headless blocking, prompting).
|
|
17
|
+
*
|
|
18
|
+
* `createConstructiveGatePolicy` is the Constructive database policy the
|
|
19
|
+
* Desktop/CLI hosts use; a remote coding host supplies its own.
|
|
20
|
+
*/
|
|
21
|
+
export type GatePolicy = {
|
|
22
|
+
/**
|
|
23
|
+
* Whether this call needs a human decision at all. Cheap and synchronous:
|
|
24
|
+
* it runs before the decline memory and the headless block, so it must
|
|
25
|
+
* decide from the tool name and arguments alone — no I/O.
|
|
26
|
+
*/
|
|
27
|
+
isGated(event: GateToolCallEvent): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* The prompt to put in front of the user, or `null` to let an already-gated
|
|
30
|
+
* call through without one. Runs only for gated calls on a host with a
|
|
31
|
+
* confirm surface, so it may do I/O to build a richer preview or to check a
|
|
32
|
+
* precondition that makes the confirm pointless (e.g. the call is going to
|
|
33
|
+
* fail with "sign in first" anyway).
|
|
34
|
+
*/
|
|
35
|
+
resolvePrompt(event: GateToolCallEvent, cwd: string): Promise<ConfirmPrompt | null>;
|
|
36
|
+
};
|
package/gating/policy.js
ADDED
package/gating/preview.d.ts
CHANGED
|
@@ -35,3 +35,9 @@ export type ConfirmPreview = {
|
|
|
35
35
|
tableName: string;
|
|
36
36
|
field: ConfirmPreviewField;
|
|
37
37
|
};
|
|
38
|
+
/** What a host puts in front of the user for one gated call. */
|
|
39
|
+
export type ConfirmPrompt = {
|
|
40
|
+
title: string;
|
|
41
|
+
message: string;
|
|
42
|
+
preview?: ConfirmPreview;
|
|
43
|
+
};
|
package/gating/prompts.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
export declare const MUTATING_DB_TOOLS: Set<string>;
|
|
2
|
-
import type {
|
|
3
|
-
export type ConfirmPrompt = {
|
|
4
|
-
title: string;
|
|
5
|
-
message: string;
|
|
6
|
-
preview?: ConfirmPreview;
|
|
7
|
-
};
|
|
2
|
+
import type { ConfirmPrompt } from './preview';
|
|
8
3
|
export declare function buildConfirmPrompt(toolName: string, input: Record<string, unknown> | undefined): ConfirmPrompt;
|
package/index.d.ts
CHANGED
|
@@ -4,7 +4,9 @@ export * from './blueprint/field-type';
|
|
|
4
4
|
export * from './blueprint/internal-policies';
|
|
5
5
|
export * from './blueprint/policy-provisioning';
|
|
6
6
|
export * from './gating/confirm-gate';
|
|
7
|
+
export * from './gating/constructive-policy';
|
|
7
8
|
export * from './gating/decline-guard';
|
|
9
|
+
export * from './gating/policy';
|
|
8
10
|
export * from './gating/preview';
|
|
9
11
|
export * from './gating/prompts';
|
|
10
12
|
export * from './skills/default-source';
|
package/index.js
CHANGED
|
@@ -20,7 +20,9 @@ __exportStar(require("./blueprint/field-type"), exports);
|
|
|
20
20
|
__exportStar(require("./blueprint/internal-policies"), exports);
|
|
21
21
|
__exportStar(require("./blueprint/policy-provisioning"), exports);
|
|
22
22
|
__exportStar(require("./gating/confirm-gate"), exports);
|
|
23
|
+
__exportStar(require("./gating/constructive-policy"), exports);
|
|
23
24
|
__exportStar(require("./gating/decline-guard"), exports);
|
|
25
|
+
__exportStar(require("./gating/policy"), exports);
|
|
24
26
|
__exportStar(require("./gating/preview"), exports);
|
|
25
27
|
__exportStar(require("./gating/prompts"), exports);
|
|
26
28
|
__exportStar(require("./skills/default-source"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentic-kit/harness",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.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": "6d4354f47b8bd4d3d1c2bd918a12dcb0315e1931"
|
|
42
42
|
}
|