truth-mirror 0.7.1

Truthfulness gate and adversarial reviewer harness for AI coding agents.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
use std::path::PathBuf;

use clap::{ArgGroup, Args, Parser, Subcommand, ValueEnum};
use serde::{Deserialize, Serialize};

#[derive(Debug, Parser)]
#[command(
    name = "truth-mirror",
    version,
    about = "Truthfulness gate and reviewer harness for coding agents.",
    propagate_version = true
)]
pub struct Cli {
    #[arg(
        long,
        global = true,
        env = "TRUTH_MIRROR_STATE_DIR",
        default_value = ".truth",
        value_name = "DIR"
    )]
    pub state_dir: PathBuf,

    #[arg(long, global = true, env = "TRUTH_MIRROR_CONFIG", value_name = "FILE")]
    pub config: Option<PathBuf>,

    #[command(subcommand)]
    pub command: Commands,
}

#[derive(Debug, Subcommand)]
pub enum Commands {
    /// Install, uninstall, or preview agent hook shims.
    InstallHooks(InstallHooksArgs),
    /// Review a commit or the staged diff with a separate reviewer model.
    Review(ReviewArgs),
    /// Run deterministic repository gates.
    Gate(GateArgs),
    /// Reinject unresolved findings into an agent prompt surface.
    Reinject(ReinjectArgs),
    /// Inspect or update the dual ledger.
    Ledger(LedgerArgs),
    /// Inspect, render, approve, apply, or reject memory-skill candidates.
    MemorySkill(MemorySkillArgs),
    /// Run the post-commit reviewer loop.
    Watch(WatchArgs),
    /// Show hook wiring, review queue, run, ledger, and checkpoint status.
    Status(StatusArgs),
    /// Print or install the embedded truth-mirror skill document.
    Skills(SkillsArgs),
    /// Full teardown: remove all hooks, surfaces, and optional state dirs.
    Uninstall(UninstallArgs),
    /// Internal git hook dispatcher.
    #[command(hide = true)]
    HookDispatch(HookDispatchArgs),
}

#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, ValueEnum)]
#[serde(rename_all = "kebab-case")]
pub enum Agent {
    Claude,
    Codex,
    Pi,
}

#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, ValueEnum)]
#[serde(rename_all = "kebab-case")]
pub enum ReviewerHarness {
    Claude,
    Codex,
    Pi,
    Gemini,
    Opencode,
    Custom,
}

#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, ValueEnum)]
#[serde(rename_all = "kebab-case")]
pub enum ReviewScope {
    Commit,
    Staged,
    Auto,
    WorkingTree,
    Branch,
}

#[derive(Debug, Args)]
pub struct InstallHooksArgs {
    #[arg(long)]
    pub claude: bool,

    #[arg(long)]
    pub codex: bool,

    #[arg(long)]
    pub pi: bool,

    #[arg(long)]
    pub uninstall: bool,

    #[arg(long)]
    pub dry_run: bool,

    /// Write a local-hook forwarder into a non-Husky core.hooksPath directory.
    #[arg(long)]
    pub inject_forwarder: bool,
}

/// Arguments for the standalone `uninstall` subcommand (full teardown).
#[derive(Debug, Args)]
pub struct UninstallArgs {
    /// Print what would be done without making any changes.
    #[arg(long)]
    pub dry_run: bool,

    /// Also delete the entire state dirs (`.truth/` and `.truth-mirror/`),
    /// including the ledger and review queue. Without `--purge`, ledger data
    /// is preserved.
    #[arg(long)]
    pub purge: bool,
}

#[derive(Debug, Args)]
pub struct ReviewArgs {
    #[command(subcommand)]
    pub command: Option<ReviewCommand>,

    #[arg(value_name = "SHA", conflicts_with = "staged")]
    pub target: Option<String>,

    #[arg(long)]
    pub staged: bool,

    #[arg(long, value_enum, value_name = "SCOPE", default_value_t = ReviewScope::Commit)]
    pub scope: ReviewScope,

    #[arg(long, value_name = "REF")]
    pub base: Option<String>,

    #[arg(long, value_enum, value_name = "AGENT")]
    pub watched_agent: Option<Agent>,

    #[arg(long, value_enum, value_name = "HARNESS")]
    pub reviewer_harness: Option<ReviewerHarness>,

    #[arg(long, value_name = "MODEL")]
    pub watched_model: Option<String>,

    #[arg(long, value_name = "MODEL")]
    pub reviewer_model: Option<String>,

    #[arg(long, value_enum, value_name = "EFFORT")]
    pub reviewer_effort: Option<crate::config::Effort>,

    #[arg(long)]
    pub allow_same_model: bool,

    #[arg(long)]
    pub strict_two_pass: bool,

    #[arg(long, value_enum, value_name = "HARNESS")]
    pub arbiter_harness: Option<ReviewerHarness>,

    #[arg(long, value_name = "MODEL")]
    pub arbiter_model: Option<String>,

    #[arg(long, value_enum, value_name = "EFFORT")]
    pub arbiter_effort: Option<crate::config::Effort>,

    /// Sic the adversarial reviewer in a loop until N lies or N fuckups.
    #[arg(long)]
    pub strict_goal: bool,

    #[arg(long, value_name = "N")]
    pub stop_after_lies: Option<u32>,

    #[arg(long, value_name = "N")]
    pub stop_after_fuckups: Option<u32>,

    #[arg(long, value_name = "N")]
    pub max_passes: Option<u32>,
}

#[derive(Debug, Subcommand)]
pub enum ReviewCommand {
    /// Show tracked review run status, or all known runs when no id is provided.
    Status {
        #[arg(value_name = "RUN_ID")]
        run_id: Option<String>,
    },
    /// Show the latest completed/failed review run, or a specific run.
    Result {
        #[arg(value_name = "RUN_ID")]
        run_id: Option<String>,
    },
    /// Cancel a review run and remove it from the review queue.
    ///
    /// Queued runs and running runs whose worker has died are cancelled directly.
    /// Pass `--force` to kill a running run whose worker is still alive.
    Cancel {
        #[arg(value_name = "RUN_ID")]
        run_id: String,

        /// Kill the worker process of a still-running run before cancelling it.
        #[arg(long)]
        force: bool,
    },
}

#[derive(Debug, Args)]
#[command(group(
    ArgGroup::new("gate_mode")
        .required(true)
        .args(["pre_push", "commit_msg", "pre_tool_use"])
))]
pub struct GateArgs {
    #[arg(long, value_name = "RANGE", conflicts_with = "commit_msg")]
    pub pre_push: Option<String>,

    #[arg(long, value_name = "FILE", conflicts_with = "pre_push")]
    pub commit_msg: Option<PathBuf>,

    #[arg(long, value_name = "FILE", requires = "commit_msg")]
    pub claim_file: Option<PathBuf>,

    #[arg(long, value_name = "FILE", requires = "commit_msg")]
    pub diff_file: Option<PathBuf>,

    #[arg(long = "fake-marker", value_name = "TOKEN", requires = "commit_msg")]
    pub fake_markers: Vec<String>,

    /// Enforcement gate: block a mutating tool call when the ledger has unresolved
    /// rejections beyond the configured threshold.
    #[arg(long, conflicts_with_all = ["pre_push", "commit_msg"])]
    pub pre_tool_use: bool,

    /// The tool name being gated (for `--pre-tool-use`).
    #[arg(long, value_name = "NAME", requires = "pre_tool_use")]
    pub tool: Option<String>,
}

#[derive(Debug, Args)]
pub struct ReinjectArgs {
    #[arg(long, value_enum)]
    pub agent: Agent,
}

#[derive(Debug, Args)]
pub struct LedgerArgs {
    #[command(subcommand)]
    pub command: LedgerCommand,
}

#[derive(Debug, Subcommand)]
pub enum LedgerCommand {
    List,
    Show {
        #[arg(value_name = "SHA")]
        sha: String,
    },
    Resolve {
        #[arg(value_name = "SHA")]
        sha: String,
    },
    Waive {
        #[arg(value_name = "SHA")]
        sha: String,

        #[arg(long, value_name = "REASON")]
        reason: String,
    },
    Stats,
}

#[derive(Debug, Args)]
pub struct MemorySkillArgs {
    #[command(subcommand)]
    pub command: MemorySkillCommand,
}

#[derive(Debug, Subcommand)]
pub enum MemorySkillCommand {
    /// List all memory-skill candidates.
    List,
    /// Show details for one memory-skill candidate.
    Show {
        #[arg(value_name = "CANDIDATE_ID")]
        candidate_id: String,
    },
    /// Render one memory-skill candidate as a skill document.
    Render {
        #[arg(value_name = "CANDIDATE_ID")]
        candidate_id: String,
    },
    /// Approve a candidate, optionally applying it immediately.
    Approve {
        #[arg(value_name = "CANDIDATE_ID")]
        candidate_id: String,

        #[arg(long)]
        apply: bool,
    },
    /// Apply a previously approved candidate.
    Apply {
        #[arg(value_name = "CANDIDATE_ID")]
        candidate_id: String,
    },
    /// Reject a candidate with a human-readable reason.
    Reject {
        #[arg(value_name = "CANDIDATE_ID")]
        candidate_id: String,

        #[arg(long, value_name = "REASON")]
        reason: String,
    },
    /// Supersede a candidate with a better replacement candidate.
    Supersede {
        #[arg(value_name = "CANDIDATE_ID")]
        candidate_id: String,

        #[arg(long, value_name = "REPLACEMENT_ID")]
        replacement: String,

        #[arg(long, value_name = "REASON")]
        reason: String,
    },
    /// Dismiss a suggested advisory so it stops being reinjected.
    DismissAdvisory {
        #[arg(value_name = "ADVISORY_ID")]
        advisory_id: String,
    },
}

#[derive(Debug, Args)]
pub struct WatchArgs {
    #[arg(long, value_enum, value_name = "AGENT")]
    pub watched_agent: Option<Agent>,

    #[arg(long, value_enum, value_name = "HARNESS")]
    pub reviewer_harness: Option<ReviewerHarness>,

    #[arg(long, value_name = "MODEL")]
    pub watched_model: Option<String>,

    #[arg(long, value_name = "MODEL")]
    pub reviewer_model: Option<String>,

    #[arg(long, value_enum, value_name = "EFFORT")]
    pub reviewer_effort: Option<crate::config::Effort>,

    #[arg(long)]
    pub allow_same_model: bool,

    /// Drain the review queue exactly once and exit (deterministic; used in CI).
    #[arg(long)]
    pub once: bool,

    /// Poll interval in seconds when running as a daemon (ignored with --once).
    #[arg(long, value_name = "SECONDS", default_value_t = 5)]
    pub poll_secs: u64,
}

#[derive(Debug, Args)]
pub struct StatusArgs {}

#[derive(Debug, Args)]
pub struct SkillsArgs {
    #[command(subcommand)]
    pub command: SkillsCommand,
}

#[derive(Debug, Subcommand)]
pub enum SkillsCommand {
    /// Print the embedded skill document to stdout.
    Echo,
    /// Write the skill document to <dir>/truth-mirror/SKILL.md.
    Install {
        /// Target skills directory (defaults to `.agents/skills`).
        #[arg(long, value_name = "PATH")]
        dir: Option<PathBuf>,

        /// Overwrite an existing skill file.
        #[arg(long)]
        force: bool,
    },
}

#[derive(Debug, Args)]
pub struct HookDispatchArgs {
    #[arg(value_enum)]
    pub hook: HookName,

    #[arg(value_name = "ARGS")]
    pub args: Vec<String>,
}

#[derive(Clone, Copy, Debug, Eq, PartialEq, ValueEnum)]
#[value(rename_all = "kebab-case")]
pub enum HookName {
    CommitMsg,
    PostCommit,
    PrePush,
}

impl HookName {
    pub fn as_str(self) -> &'static str {
        match self {
            Self::CommitMsg => "commit-msg",
            Self::PostCommit => "post-commit",
            Self::PrePush => "pre-push",
        }
    }
}

#[cfg(test)]
mod tests {
    use clap::CommandFactory;

    use super::Cli;

    #[test]
    fn clap_contract_is_valid() {
        Cli::command().debug_assert();
    }
}