Skip to main content

kintsugi_intercept/
hook.rs

1//! Agent-CLI hook adapter.
2//!
3//! Many AI coding CLIs can run a command before they execute a tool, hand it a
4//! JSON description of the call, and read a decision back. This adapter bridges
5//! that payload to a [`ProposedCommand`], asks the daemon, and maps the
6//! [`Verdict`] to the CLI's decision protocol.
7//!
8//! The per-CLI wire formats live in [`crate::dialect`]; this module owns the
9//! shared *policy*: the daemon round-trip, the fail-closed-catastrophic
10//! backstop, and the Allow/Deny/Hold → decision mapping. Selecting a dialect is
11//! one `--agent <id>` flag, so a single `kintsugi-hook` binary serves every CLI.
12//!
13//! Fail-open: a malformed payload, a non-shell tool, or an unreachable daemon
14//! never blocks the agent — *except* a catastrophic command with the daemon
15//! down (denied fail-closed), or when `KINTSUGI_FAIL_CLOSED=1`.
16
17use std::path::Path;
18
19use kintsugi_core::{shell, Class, Decision, ObservedIngest, ProposedCommand};
20use kintsugi_daemon::Client;
21use serde::Deserialize;
22
23pub use crate::dialect::HookOutcome;
24
25use crate::dialect::{self, Dialect, Parsed, Resolved};
26use crate::observe;
27
28/// Which hook event the caller asked us to handle (`--event`). The default is the
29/// pre-tool decision path, so an invocation without the flag is byte-identical to
30/// the pre-V1.1 behaviour — a typo or a missing flag can never disarm the shell
31/// gate.
32#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
33pub enum HookEvent {
34    /// Pre-tool: judge a shell command (the original contract).
35    #[default]
36    PreToolUse,
37    /// File-write observation: label the written path for provenance so a tainted
38    /// session's output carries the taint into a later reader. Observation only —
39    /// it never blocks, and it never touches a command verdict.
40    Write,
41}
42
43/// Handle one hook payload for a given dialect, performing the daemon round-trip.
44pub fn handle_with(dialect: Dialect, input: &str) -> HookOutcome {
45    handle_with_event(dialect, input, HookEvent::PreToolUse)
46}
47
48/// Handle one hook payload for an explicit event kind (the `--event` flag).
49///
50/// [`HookEvent::Write`] is routed to write observation *before* any shell
51/// parsing and returns silent/0 unconditionally: a write label can never gate the
52/// agent. Every other event takes the exact pre-tool path below.
53pub fn handle_with_event(dialect: Dialect, input: &str, event: HookEvent) -> HookOutcome {
54    if event == HookEvent::Write {
55        observe_write_call(dialect, input);
56        // A mis-registration — `beforeShellExecution` pointed at `--event write` —
57        // must not remove the gate. If the payload is a shell call, fall through to
58        // the decision path instead of returning silence; the observation above
59        // already happened, so nothing is lost either way.
60        if !matches!(dialect.parse(input), Parsed::Shell(_)) {
61            return HookOutcome::silent();
62        }
63        eprintln!(
64            "kintsugi-hook: --event write received a shell payload — honouring the gate instead of \
65             only observing; check the {} hook registration",
66            dialect.agent_id()
67        );
68    }
69    // Route on the explicit event marker BEFORE any shell parsing: a
70    // PostToolUse payload reports a call that ALREADY ran. Re-judging it as a
71    // proposal would double-log a command nobody proposed and "deny" an
72    // action that cannot be undone by a deny. The observation below only
73    // labels the session for future commands — it never blocks and never
74    // touches the verdict path a PreToolUse payload takes.
75    if is_post_tool_use(input) {
76        observe_post_call(dialect, input);
77        return HookOutcome::silent();
78    }
79    let parsed = match dialect.parse(input) {
80        Parsed::Shell(s) => s,
81        Parsed::NotShell => {
82            // Not a shell tool — but it may be a content-ingesting one (a web
83            // fetch, search, MCP call, out-of-workspace read). Observe it for
84            // provenance taint, then pass: observation only labels, never blocks.
85            observe_content_call(dialect, input);
86            return HookOutcome::silent();
87        }
88        Parsed::Bad(e) => {
89            // Never block the agent on a payload we couldn't parse.
90            eprintln!(
91                "kintsugi-hook: could not parse {} payload: {e}",
92                dialect.agent_id()
93            );
94            return HookOutcome::silent();
95        }
96    };
97
98    let argv = shell::split(&parsed.command);
99    let session = parsed.session_id.clone();
100    let cwd = parsed.cwd.clone();
101    let proposed =
102        ProposedCommand::new(dialect.agent_id(), parsed.cwd, argv.clone(), parsed.command)
103            .with_session(parsed.session_id);
104
105    match Client::send(&proposed) {
106        Ok(verdict) => {
107            let resolved = match dialect::resolve(&verdict) {
108                // A catastrophic command is held in Kintsugi's queue but denied to
109                // the agent: an in-agent "allow" would run it with no snapshot,
110                // voiding reversibility. The agent can't offer that approval, so
111                // tell the human where it lives — otherwise the agent just sees a
112                // bare deny and silently works around it.
113                Resolved::Deny(reason)
114                    if verdict.decision == Decision::Hold
115                        && verdict.class == Class::Catastrophic =>
116                {
117                    Resolved::Deny(held_for_approval(&reason, &proposed.id.to_string()))
118                }
119                other => other,
120            };
121            let outcome = dialect.format(&resolved);
122            // A shell command that fetches remote content (`curl`/`wget`/`git
123            // clone`) taints the session for FUTURE commands. Observe it only when
124            // it will actually run (Allow) and AFTER the verdict — so the fetch is
125            // judged against prior state and isn't tripped by its own taint.
126            if matches!(resolved, Resolved::Allow) {
127                observe_shell_ingest(dialect, &argv, session.as_deref(), &cwd);
128            }
129            outcome
130        }
131        Err(e) => {
132            // Daemon down: locally classify so a catastrophic command is still
133            // denied (fail-closed for the hard floor); non-catastrophic honors
134            // the fail-open default.
135            if kintsugi_core::classify(&proposed).class == Class::Catastrophic {
136                eprintln!(
137                    "kintsugi-hook: daemon unreachable; denying catastrophic (fail-closed): {e}"
138                );
139                dialect.format(&dialect::Resolved::Deny(
140                    "Kintsugi daemon unreachable; catastrophic command blocked (fail-closed)"
141                        .into(),
142                ))
143            } else if fail_closed() {
144                eprintln!("kintsugi-hook: daemon unreachable; denying (fail-closed): {e}");
145                dialect.format(&dialect::Resolved::Deny(
146                    "Kintsugi daemon unreachable (fail-closed)".into(),
147                ))
148            } else {
149                eprintln!("kintsugi-hook: warning: daemon unreachable; allowing unguarded: {e}");
150                dialect.pass()
151            }
152        }
153    }
154}
155
156/// Backwards-compatible Claude Code entry point.
157pub fn handle(input: &str) -> HookOutcome {
158    handle_with(Dialect::Claude, input)
159}
160
161/// Observe a non-shell content-tool call (web fetch / search / MCP / read) as a
162/// provenance taint source. Best-effort and silent: a parse miss, an untracked
163/// session, or an unreachable daemon must never affect the agent — observation
164/// only labels, it is not a gate.
165fn observe_content_call(dialect: Dialect, input: &str) {
166    let Some(call) = dialect.parse_content(input) else {
167        return;
168    };
169    if let Some(src) = observe::classify_tool_ingest(&call.tool, &call.input, &call.cwd) {
170        send_ingest(dialect, src, call.session_id.as_deref(), &call.cwd);
171    }
172}
173
174/// Observe a *completed* tool call's result as a provenance taint source (V1.1
175/// result-content, fed by a PostToolUse event). Same contract as
176/// [`observe_content_call`]: best-effort and silent — a parse miss, an untracked
177/// session, or an unreachable daemon never affects the agent. The tool already
178/// ran, so there is nothing to gate; this only labels the session for FUTURE
179/// commands, purely additively on top of the pre-tool act taint.
180fn observe_post_call(dialect: Dialect, input: &str) {
181    let Some(call) = dialect.parse_post(input) else {
182        return;
183    };
184    // An untrusted ingest (web fetch, search, out-of-workspace read) taints the
185    // session…
186    if let Some(src) =
187        observe::classify_result_ingest(&call.tool, &call.input, &call.response, &call.cwd)
188    {
189        send_ingest(dialect, src, call.session_id.as_deref(), &call.cwd);
190    }
191    // …and a read of a path an earlier tainted session wrote propagates that
192    // taint to this reader. Both are observation-only, escalation-only.
193    if let Some(path) = observe::classify_tool_read(&call.tool, &call.input, &call.cwd) {
194        send_read(call.session_id.as_deref(), &path, &call.cwd);
195    }
196}
197
198/// Observe a file write by the agent's session as a provenance propagation step
199/// (V1.1): a session that has ingested untrusted content taints the paths it
200/// writes, so a later reader of that file inherits the taint. Same contract as
201/// the ingest observers: best-effort and silent — a parse miss, an untracked
202/// session, or an unreachable daemon never affects the agent.
203fn observe_write_call(dialect: Dialect, input: &str) {
204    let Some(call) = dialect.parse_write(input) else {
205        return;
206    };
207    if let Some(path) = observe::classify_tool_write(&call.tool, &call.input, &call.cwd) {
208        send_write(call.session_id.as_deref(), &path, &call.cwd);
209    }
210}
211
212/// Report a write observation to the daemon. Skips untracked sessions (a
213/// `None`/empty session can never be taint-tracked, so there is nothing to
214/// propagate — the same convention as [`send_ingest`]) and swallows any IPC error
215/// (observation never blocks the agent).
216fn send_write(session: Option<&str>, path: &str, cwd: &Path) {
217    let Some(session) = session.filter(|s| !s.is_empty()) else {
218        return;
219    };
220    let _ = Client::write_observed(session, path, cwd);
221}
222
223/// Report a read of a (possibly labelled) path. Best-effort and silent, exactly
224/// like [`send_write`]: an unreachable daemon or an untracked session never
225/// affects the agent.
226fn send_read(session: Option<&str>, path: &str, cwd: &Path) {
227    let Some(session) = session.filter(|s| !s.is_empty()) else {
228        return;
229    };
230    let _ = Client::read_observed(session, path, cwd);
231}
232
233/// The narrow event-marker probe used to route PostToolUse payloads. Only the
234/// explicit `hook_event_name` the agent itself stamps decides — never payload
235/// shape (a PreToolUse shell payload misrouted onto the post path would
236/// bypass the decision gate, so a guess is never acceptable).
237#[derive(Debug, Deserialize)]
238struct EventMarker {
239    #[serde(default)]
240    hook_event_name: Option<String>,
241}
242
243/// Is this payload a `PostToolUse` event? Malformed input, other events, and
244/// missing markers all answer no — the decision path is the default.
245fn is_post_tool_use(input: &str) -> bool {
246    serde_json::from_str::<EventMarker>(input)
247        .ok()
248        .and_then(|e| e.hook_event_name)
249        .is_some_and(|name| name == "PostToolUse")
250}
251
252/// Observe a shell command that ingests remote content (`curl`/`wget`/`git
253/// clone`). Best-effort and silent, same as [`observe_content_call`].
254fn observe_shell_ingest(dialect: Dialect, argv: &[String], session: Option<&str>, cwd: &Path) {
255    if let Some(src) = observe::classify_shell_ingest(argv) {
256        send_ingest(dialect, src, session, cwd);
257    }
258}
259
260/// Build and send an [`ObservedIngest`] to the daemon. Skips untracked sessions
261/// (a `None`/empty session can never be taint-tracked, so there is nothing to
262/// label) and swallows any IPC error (observation never blocks the agent).
263fn send_ingest(dialect: Dialect, src: observe::IngestSource, session: Option<&str>, cwd: &Path) {
264    let Some(session) = session.filter(|s| !s.is_empty()) else {
265        return;
266    };
267    let observed = ObservedIngest::now(src.kind, src.id, dialect.agent_id(), session, cwd);
268    let _ = Client::ingest(&observed);
269}
270
271/// Augment a catastrophic deny with the stop → approve → continue flow.
272///
273/// A hook is one-shot: by the time you see this, the agent already got the deny
274/// and there is no parked tool call to resume. The agent must never run a
275/// catastrophic itself, and approving it elsewhere does NOT auto-resume the agent.
276/// So this message tells the agent to *stop and hand off to the human*, who can
277/// run it from the trusted UI (Held → Approve & run) or via `kintsugi run <id>` —
278/// both snapshot first (so `kintsugi undo` works) and are gated on a deliberate
279/// human action (a real-terminal keypress on the CLI; a click in the unlocked app)
280/// so an agent shelling out still can't self-approve. After the human handles it,
281/// they tell the agent to continue. The short id prefix is surfaced for the CLI.
282fn held_for_approval(reason: &str, id: &str) -> String {
283    let short = id.get(..8).unwrap_or(id);
284    format!(
285        "{reason} Kintsugi blocked this catastrophic command — do NOT run it or try to work \
286         around it. Stop and tell the user: if they want it, they can approve it in the Kintsugi \
287         app (Held → Approve & run) or run `kintsugi run {short}` in their terminal — either way \
288         it is snapshotted first, so `kintsugi undo` can roll it back. You will not resume \
289         automatically; once they've handled it, they can tell you to continue."
290    )
291}
292
293/// True if the admin-set fail-closed marker is present (an agent can't unset a
294/// root-owned marker) OR the `KINTSUGI_FAIL_CLOSED` env var opts in. The marker
295/// wins, so `KINTSUGI_FAIL_CLOSED=0` can't re-open the gate.
296fn fail_closed() -> bool {
297    kintsugi_daemon::is_fail_closed_marked()
298        || matches!(
299            std::env::var("KINTSUGI_FAIL_CLOSED").ok().as_deref(),
300            Some("1") | Some("true") | Some("yes")
301        )
302}
303
304/// Parse the `--agent <id>` flag from argv, defaulting to Claude Code.
305///
306/// Unknown ids fall back to Claude with a warning rather than failing — a
307/// misconfigured hook should still guard, not crash the agent.
308pub fn dialect_from_args<I: IntoIterator<Item = String>>(args: I) -> Dialect {
309    let mut it = args.into_iter();
310    while let Some(a) = it.next() {
311        let value = if let Some(v) = a.strip_prefix("--agent=") {
312            Some(v.to_string())
313        } else if a == "--agent" {
314            it.next()
315        } else {
316            None
317        };
318        if let Some(v) = value {
319            match Dialect::from_agent(&v) {
320                Some(d) => return d,
321                None => {
322                    eprintln!("kintsugi-hook: unknown --agent '{v}', defaulting to claude-code");
323                    return Dialect::Claude;
324                }
325            }
326        }
327    }
328    Dialect::Claude
329}
330
331/// Read the `--event <kind>` flag from argv, defaulting to the pre-tool path.
332///
333/// Unknown values fall back to the pre-tool path with a warning rather than
334/// failing or silently doing nothing: the shell gate is the default, so an
335/// unrecognized flag cannot weaken it.
336pub fn event_from_args<I: IntoIterator<Item = String>>(args: I) -> HookEvent {
337    let mut it = args.into_iter();
338    while let Some(a) = it.next() {
339        let value = if let Some(v) = a.strip_prefix("--event=") {
340            Some(v.to_string())
341        } else if a == "--event" {
342            it.next()
343        } else {
344            None
345        };
346        if let Some(v) = value {
347            return match v.as_str() {
348                "write" => HookEvent::Write,
349                other => {
350                    eprintln!("kintsugi-hook: unknown --event '{other}', using the pre-tool path");
351                    HookEvent::PreToolUse
352                }
353            };
354        }
355    }
356    HookEvent::PreToolUse
357}
358
359/// Read the hook payload from stdin and emit the outcome, picking the dialect and
360/// event kind from the process arguments.
361pub fn run() -> i32 {
362    let args: Vec<String> = std::env::args().skip(1).collect();
363    let dialect = dialect_from_args(args.iter().cloned());
364    let event = event_from_args(args);
365    let stdin = std::io::stdin();
366    let stdout = std::io::stdout();
367    run_io_event(dialect, event, stdin.lock(), stdout.lock())
368}
369
370/// The hook over arbitrary reader/writer for a given dialect (testable). Takes
371/// the original pre-tool path.
372pub fn run_io<R: std::io::Read, W: std::io::Write>(dialect: Dialect, reader: R, writer: W) -> i32 {
373    run_io_event(dialect, HookEvent::PreToolUse, reader, writer)
374}
375
376/// The hook over arbitrary reader/writer for a dialect and event kind (testable).
377pub fn run_io_event<R: std::io::Read, W: std::io::Write>(
378    dialect: Dialect,
379    event: HookEvent,
380    mut reader: R,
381    mut writer: W,
382) -> i32 {
383    let mut input = String::new();
384    if let Err(e) = reader.read_to_string(&mut input) {
385        eprintln!("kintsugi-hook: failed to read stdin: {e}");
386        return 0; // fail-open
387    }
388    let outcome = handle_with_event(dialect, &input, event);
389    if let Some(out) = outcome.stdout {
390        let _ = writeln!(writer, "{out}");
391    }
392    outcome.exit_code
393}
394
395#[cfg(test)]
396mod tests {
397    use super::*;
398
399    #[test]
400    fn non_shell_tool_is_allowed_silently() {
401        let payload = r#"{"tool_name":"Edit","tool_input":{"file_path":"x"}}"#;
402        assert_eq!(handle(payload), HookOutcome::silent());
403    }
404
405    #[test]
406    fn held_for_approval_guides_stop_approve_continue() {
407        let msg = held_for_approval("recursively deletes files.", "abcd1234-5678-90ab-cdef");
408        assert!(msg.contains("recursively deletes files."));
409        assert!(
410            msg.contains("do NOT run it") && msg.contains("work around"),
411            "must tell the agent to stop, not run or work around it"
412        );
413        assert!(
414            msg.contains("Kintsugi app") || msg.contains("Approve & run"),
415            "should point at approving in the app"
416        );
417        assert!(
418            msg.contains("kintsugi run abcd1234"),
419            "should give the guarded CLI run command with the short id"
420        );
421        assert!(msg.contains("undo"), "should mention reversibility");
422        assert!(
423            msg.contains("continue"),
424            "should set up the human-driven resume (tell the agent to continue)"
425        );
426    }
427
428    #[test]
429    fn malformed_payload_is_allowed_silently() {
430        assert_eq!(handle("not json"), HookOutcome::silent());
431    }
432
433    #[test]
434    fn empty_command_is_allowed_silently() {
435        let payload = r#"{"tool_name":"Bash","tool_input":{"command":"   "}}"#;
436        assert_eq!(handle(payload), HookOutcome::silent());
437    }
438
439    #[test]
440    fn run_io_allows_non_shell_tool_silently() {
441        let input = br#"{"tool_name":"Edit","tool_input":{"file_path":"x"}}"#;
442        let mut out = Vec::new();
443        let code = run_io(Dialect::Claude, &input[..], &mut out);
444        assert_eq!(code, 0);
445        assert!(out.is_empty(), "allow-silent writes nothing");
446    }
447
448    #[test]
449    fn dialect_from_args_reads_flag_forms() {
450        assert_eq!(
451            dialect_from_args(["--agent".to_string(), "cursor".to_string()]),
452            Dialect::Cursor
453        );
454        assert_eq!(
455            dialect_from_args(["--agent=qwen".to_string()]),
456            Dialect::Qwen
457        );
458        // No flag → Claude (backwards compatible).
459        assert_eq!(dialect_from_args(Vec::<String>::new()), Dialect::Claude);
460        // Unknown → Claude fallback.
461        assert_eq!(
462            dialect_from_args(["--agent=banana".to_string()]),
463            Dialect::Claude
464        );
465    }
466
467    // ----- PostToolUse routing (V1.1) -----------------------------------------
468
469    #[test]
470    fn post_tool_use_event_is_observed_never_gated() {
471        // Sessionless so the ingest send is skipped (no daemon in unit
472        // tests): a post event is pure observation — silent, no verdict.
473        let payload = r#"{
474            "hook_event_name": "PostToolUse",
475            "tool_name": "WebFetch",
476            "tool_input": { "url": "https://example.com/p" },
477            "tool_response": "page body",
478            "cwd": "/work"
479        }"#;
480        assert_eq!(handle(payload), HookOutcome::silent());
481    }
482
483    #[test]
484    fn post_tool_use_shell_result_is_never_rejudged_as_a_proposal() {
485        // The same catastrophic Bash call, but as a PostToolUse event: it
486        // already ran. Re-judging a completed call would double-log it and
487        // "deny" an action that cannot be undone by a deny — and the pre-tool
488        // path WOULD deny this fail-closed, so silence here proves the post
489        // routing held and never touched the decision path.
490        let payload = r#"{
491            "hook_event_name": "PostToolUse",
492            "tool_name": "Bash",
493            "tool_input": { "command": "rm -rf /" },
494            "tool_response": "done"
495        }"#;
496        assert_eq!(handle(payload), HookOutcome::silent());
497    }
498
499    #[test]
500    fn is_post_tool_use_matches_only_the_explicit_event_marker() {
501        assert!(is_post_tool_use(
502            r#"{"hook_event_name":"PostToolUse","tool_name":"Read"}"#
503        ));
504        // Pre-tool events, other events, a missing marker, and garbage all
505        // take the decision path — the post route is never entered on a guess
506        // (misrouting a PreToolUse payload here would bypass the shell gate).
507        assert!(!is_post_tool_use(
508            r#"{"hook_event_name":"PreToolUse","tool_name":"Bash"}"#
509        ));
510        assert!(!is_post_tool_use(
511            r#"{"hook_event_name":"postToolUse","tool_name":"Bash"}"#
512        ));
513        assert!(!is_post_tool_use(r#"{"tool_name":"Bash"}"#));
514        assert!(!is_post_tool_use("not json"));
515        assert!(!is_post_tool_use(r#"["an array"]"#));
516        assert!(!is_post_tool_use("42"));
517    }
518
519    // ----- --event (V1.1 file-write observation) ------------------------------
520
521    #[test]
522    fn event_from_args_defaults_to_the_pre_tool_path() {
523        // No flag (every pre-V1.1 invocation) and an unknown value both take the
524        // exact original path — a typo can never silently disable the shell gate.
525        assert_eq!(event_from_args(Vec::<String>::new()), HookEvent::PreToolUse);
526        assert_eq!(
527            event_from_args(["--agent".to_string(), "opencode".to_string()]),
528            HookEvent::PreToolUse
529        );
530        assert_eq!(
531            event_from_args(["--event".to_string(), "writes".to_string()]),
532            HookEvent::PreToolUse
533        );
534        // Both flag forms.
535        assert_eq!(
536            event_from_args(["--event".to_string(), "write".to_string()]),
537            HookEvent::Write
538        );
539        assert_eq!(
540            event_from_args(["--agent=opencode".to_string(), "--event=write".to_string()]),
541            HookEvent::Write
542        );
543    }
544
545    #[test]
546    fn a_write_event_is_observation_only_and_never_gates() {
547        // No session → send_write skips before any IPC, so this is a pure unit
548        // test. The contract: silent, exit 0, whatever the payload.
549        let payload = r#"{
550            "tool": "write",
551            "args": { "filePath": "/work/repo/src/notes.rs" },
552            "cwd": "/work/repo"
553        }"#;
554        assert_eq!(
555            handle_with_event(Dialect::OpenCode, payload, HookEvent::Write),
556            HookOutcome::silent()
557        );
558    }
559
560    #[test]
561    fn a_write_event_falls_through_to_the_gate_for_shell_payloads() {
562        // A FILE-write payload is inert on this route: a write observation never
563        // denies. But a shell payload arriving here means the registration is wrong
564        // (`beforeShellExecution` pointed at `--event write`), and silently passing
565        // it would remove the gate — so it is decided instead.
566        let file_write =
567            r#"{"tool":"write","args":{"filePath":"/work/repo/x.rs"},"cwd":"/work/repo"}"#;
568        assert_eq!(
569            handle_with_event(Dialect::OpenCode, file_write, HookEvent::Write),
570            HookOutcome::silent()
571        );
572        // Garbage is harmless.
573        assert_eq!(
574            handle_with_event(Dialect::OpenCode, "not json", HookEvent::Write),
575            HookOutcome::silent()
576        );
577        // A catastrophic shell command on this route still gets a verdict.
578        let shell = r#"{"command":"rm -rf /","cwd":"/work"}"#;
579        assert_ne!(
580            handle_with_event(Dialect::Cursor, shell, HookEvent::Write),
581            HookOutcome::silent(),
582            "a shell payload on the write route must not be waved through"
583        );
584    }
585
586    #[test]
587    fn run_io_event_handles_the_write_route() {
588        let input = br#"{"tool":"write","args":{"filePath":"/work/repo/x"},"cwd":"/work/repo"}"#;
589        let mut out = Vec::new();
590        let code = run_io_event(Dialect::OpenCode, HookEvent::Write, &input[..], &mut out);
591        assert_eq!(code, 0);
592        assert!(out.is_empty(), "a write observation writes nothing");
593    }
594}