@hmharness/kernel 0.23.34 → 0.23.35
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/dist/loop.d.ts +22 -0
- package/dist/loop.js +26 -6
- package/dist/types.d.ts +10 -0
- package/package.json +1 -1
package/dist/loop.d.ts
CHANGED
|
@@ -8,6 +8,9 @@ export interface LoopEvents {
|
|
|
8
8
|
onToolResult?(name: string, output: string, isError: boolean): void;
|
|
9
9
|
/** Called when a tool requested approval. granted=false means denied. */
|
|
10
10
|
onApproval?(name: string, args: Record<string, unknown>, granted: boolean): void;
|
|
11
|
+
/** Called when the pre-execution action gate was consulted (v0.24 P2A):
|
|
12
|
+
* allowed=false means the call was refused before execution. */
|
|
13
|
+
onGate?(name: string, args: Record<string, unknown>, allowed: boolean, reason?: string): void;
|
|
11
14
|
/** Fired when an injected user message entered the working transcript
|
|
12
15
|
* (web Ctrl+Enter / TUI Enter-while-running). The message is appended
|
|
13
16
|
* after the previous tool batch, before the next model call. */
|
|
@@ -17,6 +20,20 @@ export interface LoopEvents {
|
|
|
17
20
|
export interface LoopApproval {
|
|
18
21
|
ask(toolName: string, args: Record<string, unknown>): Promise<boolean>;
|
|
19
22
|
}
|
|
23
|
+
/** Pre-execution action gate (v0.24 P2A live intervention point). The loop
|
|
24
|
+
* consults the gate BEFORE a tool call executes; a refusal becomes the tool
|
|
25
|
+
* result (the model sees the reason and can re-plan) and the tool never
|
|
26
|
+
* runs. This is the hook a learned world model uses to act on its
|
|
27
|
+
* predictions — calibration only becomes task value if it can change
|
|
28
|
+
* behavior at execution time. */
|
|
29
|
+
export interface LoopToolGate {
|
|
30
|
+
check(name: string, args: Record<string, unknown>): Promise<{
|
|
31
|
+
allowed: true;
|
|
32
|
+
} | {
|
|
33
|
+
allowed: false;
|
|
34
|
+
reason: string;
|
|
35
|
+
}>;
|
|
36
|
+
}
|
|
20
37
|
export interface LoopResult {
|
|
21
38
|
text: string;
|
|
22
39
|
turns: number;
|
|
@@ -62,6 +79,11 @@ export declare function runLoop(opts: {
|
|
|
62
79
|
* model's context window (window.ts registry / provider.contextWindow). */
|
|
63
80
|
maxContextChars?: number;
|
|
64
81
|
approval?: LoopApproval;
|
|
82
|
+
/** Pre-execution action gate (v0.24 P2A): consulted BEFORE approval — an
|
|
83
|
+
* automated gate should not wake the human dialog for a call it already
|
|
84
|
+
* blocks. A refusal never executes the tool; the reason becomes its tool
|
|
85
|
+
* result so the model can choose another path. */
|
|
86
|
+
toolGate?: LoopToolGate;
|
|
65
87
|
events?: LoopEvents;
|
|
66
88
|
/** Injectable model call (tests pass a fake; production uses provider.chat). */
|
|
67
89
|
chatImpl?: typeof chat;
|
package/dist/loop.js
CHANGED
|
@@ -203,15 +203,35 @@ export async function runLoop(opts) {
|
|
|
203
203
|
p.isError = true;
|
|
204
204
|
p.skip = true;
|
|
205
205
|
}
|
|
206
|
-
else
|
|
207
|
-
//
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
206
|
+
else {
|
|
207
|
+
// v0.24 P2A intervention point: the gate runs BEFORE approval (an
|
|
208
|
+
// automated refusal should not queue a human dialog) and BEFORE
|
|
209
|
+
// execution. A refusal never executes the tool; the reason becomes
|
|
210
|
+
// its tool result so the model sees WHY and can re-plan. An ALLOW
|
|
211
|
+
// falls through to the normal approval path — the gate never
|
|
212
|
+
// substitutes for the human dialog on risky tools.
|
|
213
|
+
let refused = null;
|
|
214
|
+
if (opts.toolGate) {
|
|
215
|
+
const verdict = await opts.toolGate.check(name, args);
|
|
216
|
+
events?.onGate?.(name, args, verdict.allowed, verdict.allowed ? undefined : verdict.reason);
|
|
217
|
+
if (!verdict.allowed)
|
|
218
|
+
refused = verdict.reason;
|
|
219
|
+
}
|
|
220
|
+
if (refused !== null) {
|
|
221
|
+
p.output = `[action gate] ${refused}`;
|
|
212
222
|
p.isError = true;
|
|
213
223
|
p.skip = true;
|
|
214
224
|
}
|
|
225
|
+
else if (tool.needsApproval?.(args, ctx)) {
|
|
226
|
+
// Safe default: with no gate wired in, risky tools are denied.
|
|
227
|
+
const granted = opts.approval ? await opts.approval.ask(name, args) : false;
|
|
228
|
+
events?.onApproval?.(name, args, granted);
|
|
229
|
+
if (!granted) {
|
|
230
|
+
p.output = 'User declined this action. Ask how to proceed or find a non-destructive alternative.';
|
|
231
|
+
p.isError = true;
|
|
232
|
+
p.skip = true;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
215
235
|
}
|
|
216
236
|
planned.push(p);
|
|
217
237
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -103,6 +103,16 @@ export interface HmhConfig {
|
|
|
103
103
|
locale?: 'zh' | 'en';
|
|
104
104
|
/** UI theme preference: 'dark' (default) | 'light' | 'system'. */
|
|
105
105
|
theme?: 'dark' | 'light' | 'system';
|
|
106
|
+
/** Action gate (v0.24 P2A research, 2026-10-15): when enabled, a
|
|
107
|
+
* sequence-conditioned world-model gate consults before every tool call
|
|
108
|
+
* and refuses historically-risky patterns (read_file->edit_file style).
|
|
109
|
+
* DEFAULT OFF: live experiments (66 runs) showed zero task gain on
|
|
110
|
+
* non-failing populations at ~2x token cost — opt-in for production A/B
|
|
111
|
+
* telemetry only. tau = minimum acceptable success rate (default 0.7). */
|
|
112
|
+
gate?: {
|
|
113
|
+
enabled?: boolean;
|
|
114
|
+
tau?: number;
|
|
115
|
+
};
|
|
106
116
|
/** Run a background evolution cycle after every N recorded insights
|
|
107
117
|
* (default 3; 0 disables). Tier 3 of the feedback ladder: Tier 1 = raw
|
|
108
118
|
* error self-notes (every task, zero cost), Tier 2 = one model-call
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hmharness/kernel",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.35",
|
|
4
4
|
"description": "hmharness kernel: tool registry, provider adapters, the agent loop, session log, config. Zero runtime dependencies (Node >=22 native fetch).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|