contract-cli 0.2.1

Beautiful contracts from the CLI — NDA, NCNDA, consulting, MSA, SOW, service, loan. Plain English, 1-3 pages, agent-friendly.
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
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
use clap::{Parser, Subcommand};

const HELP_FOOTER: &str = "\
Tips:
  • Run `contract agent-info | jq` for the full capability manifest (commands, flags, exit codes)
  • The DB is SHARED with invoice-cli — always `contract issuer list` / `contract clients list` before creating entities
  • Pipe any command to jq for structured data: `contract list | jq '.data'`
  • Template chain at render: --template > contract.default_template > \"helvetica-nera\"
  • Drafts render with a DRAFT watermark; use --final for a clean signing copy
  • `contract doctor` verifies typst, the DB, packs, and templates before you start

Examples:
  contract new --kind nda --as acme --client meridian --purpose 'evaluating a joint venture' --term-years 3
    Quick mutual NDA with a 3-year confidentiality term

  contract new --kind consulting --as acme --client meridian --fee fixed:8400:SGD --term-months 3 \\
      --purpose 'design a dashboard' --deliverable 'Designs' --deliverable 'Build' --ip-assignment client
    Consulting agreement with a fixed fee and deliverables

  contract render NDA-acme-2026-0001 --final --open
    Render a clean, watermark-free PDF and open it

  contract sign NDA-acme-2026-0001 --side us --name 'B. Djordjevic' --title Director
    Record one side's signature (status auto-bumps to 'signed' when both sides sign)

  contract template list | jq '.data'
    Inspect available PDF templates as structured JSON";

#[derive(Parser, Debug)]
#[command(
    name = "contract",
    version,
    about = "Beautiful contracts from the CLI — NDA, consulting, MSA, SOW, service",
    after_long_help = HELP_FOOTER,
    after_help = HELP_FOOTER
)]
pub struct Cli {
    /// Emit JSON envelope on stdout (auto-detected when piped)
    #[arg(long, global = true)]
    pub json: bool,
    /// Suppress human output
    #[arg(long, global = true)]
    pub quiet: bool,
    #[command(subcommand)]
    pub command: Commands,
}

#[derive(Subcommand, Debug)]
pub enum Commands {
    /// Manage issuers (companies you contract AS)
    #[command(visible_alias = "issuers", subcommand)]
    Issuer(IssuerCmd),

    /// Manage clients (counterparties)
    #[command(visible_alias = "client", subcommand)]
    Clients(ClientCmd),

    /// Manage contracts (new/list/show/render/mark/sign/edit/duplicate/delete)
    #[command(subcommand)]
    Contracts(ContractCmd),

    /// Shorthand: `contract new …` (= `contract contracts new …`)
    #[command(name = "new")]
    New(ContractNewArgs),

    /// Shorthand: `contract list` (= `contract contracts list`)
    #[command(name = "list", alias = "ls")]
    List(ContractListArgs),

    /// Shorthand: `contract show <number>`
    #[command(name = "show", alias = "get")]
    Show { number: String },

    /// Shorthand: `contract render <number>`
    #[command(name = "render")]
    Render(ContractRenderArgs),

    /// Shorthand: `contract mark <number> <status>`
    #[command(name = "mark")]
    Mark { number: String, status: String },

    /// Shorthand: `contract sign <number> --side us|them --name "..."`
    #[command(name = "sign")]
    Sign(SignArgs),

    /// Shorthand: `contract edit <number> …` (= `contract contracts edit …`)
    #[command(name = "edit")]
    Edit(ContractEditArgs),

    /// Shorthand: `contract duplicate <number>` (= `contract contracts duplicate …`)
    #[command(name = "duplicate", visible_alias = "clone")]
    Duplicate(DuplicateArgs),

    /// Shorthand: `contract delete <number>` (= `contract contracts delete …`)
    #[command(name = "delete", visible_alias = "rm")]
    Delete(DeleteArgs),

    /// Browse clause packs (the building blocks per contract kind)
    #[command(visible_alias = "packs", subcommand)]
    Pack(PackCmd),

    /// Inspect / find / preview PDF templates
    #[command(visible_alias = "templates", subcommand)]
    Template(TemplateCmd),

    /// Browse contract kinds (nda, ncnda, consulting, loan, …)
    #[command(visible_alias = "kind", subcommand)]
    Kinds(KindsCmd),

    /// Show / edit config
    #[command(subcommand)]
    Config(ConfigCmd),

    /// Self-describing JSON manifest for agents
    #[command(visible_alias = "info")]
    AgentInfo,

    /// Install the embedded skill into ~/.claude, ~/.codex, ~/.gemini
    #[command(subcommand)]
    Skill(SkillCmd),

    /// Run dependency & config diagnostics
    Doctor,

    /// Distribution-aware update (brew / cargo)
    Update {
        /// Check only — no mutation
        #[arg(long)]
        check: bool,
    },

    /// Hidden: deterministically trigger each exit code (conformance testing)
    #[command(name = "contract", hide = true)]
    ExitHook { code: i32 },
}

// ─── Issuers ─────────────────────────────────────────────────────────────

#[derive(Subcommand, Debug)]
pub enum IssuerCmd {
    /// Add a new issuer
    #[command(visible_alias = "new")]
    Add {
        slug: String,
        #[arg(long)]
        name: String,
        #[arg(long)]
        legal_name: Option<String>,
        #[arg(long, default_value = "sg")]
        jurisdiction: String,
        #[arg(long)]
        tax_id: Option<String>,
        #[arg(long)]
        company_no: Option<String>,
        #[arg(long)]
        address: String,
        #[arg(long)]
        email: Option<String>,
        #[arg(long)]
        phone: Option<String>,
        /// Path to logo image (PNG/SVG/JPG) — used in contract header
        #[arg(long)]
        logo: Option<String>,
        /// Default output dir for `contract render`
        #[arg(long)]
        output_dir: Option<String>,
    },
    Edit {
        slug: String,
        #[arg(long)]
        name: Option<String>,
        #[arg(long)]
        legal_name: Option<String>,
        #[arg(long)]
        jurisdiction: Option<String>,
        #[arg(long)]
        tax_id: Option<String>,
        #[arg(long)]
        company_no: Option<String>,
        #[arg(long)]
        address: Option<String>,
        #[arg(long)]
        email: Option<String>,
        #[arg(long)]
        phone: Option<String>,
        #[arg(long)]
        logo: Option<String>,
        #[arg(long)]
        logo_clear: bool,
        #[arg(long)]
        output_dir: Option<String>,
    },
    #[command(visible_alias = "ls")]
    List,
    #[command(visible_alias = "get")]
    Show { slug: String },
    #[command(visible_alias = "rm")]
    Delete { slug: String },
}

// ─── Clients ─────────────────────────────────────────────────────────────

#[derive(Subcommand, Debug)]
pub enum ClientCmd {
    #[command(visible_alias = "new")]
    Add {
        slug: String,
        #[arg(long)]
        name: String,
        /// Legal entity name on the contract (e.g. "Meridian & Co. Pty Ltd")
        #[arg(long)]
        legal_name: Option<String>,
        /// Registration / company number
        #[arg(long)]
        company_no: Option<String>,
        /// Legal jurisdiction of incorporation (e.g. "Singapore", "Delaware")
        #[arg(long)]
        jurisdiction: Option<String>,
        #[arg(long)]
        attn: Option<String>,
        #[arg(long)]
        country: Option<String>,
        #[arg(long)]
        address: String,
        #[arg(long)]
        email: Option<String>,
        #[arg(long)]
        notes: Option<String>,
    },
    Edit {
        slug: String,
        #[arg(long)]
        name: Option<String>,
        #[arg(long)]
        legal_name: Option<String>,
        #[arg(long)]
        company_no: Option<String>,
        #[arg(long)]
        jurisdiction: Option<String>,
        #[arg(long)]
        attn: Option<String>,
        #[arg(long)]
        country: Option<String>,
        #[arg(long)]
        address: Option<String>,
        #[arg(long)]
        email: Option<String>,
        #[arg(long)]
        notes: Option<String>,
    },
    #[command(visible_alias = "ls")]
    List,
    #[command(visible_alias = "get")]
    Show { slug: String },
    #[command(visible_alias = "rm")]
    Delete { slug: String },
}

// ─── Contracts ───────────────────────────────────────────────────────────

#[derive(clap::Args, Debug, Clone)]
pub struct ContractNewArgs {
    /// Contract kind: nda | consulting | msa | sow | service
    #[arg(long)]
    pub kind: String,
    /// Issuer slug (your side)
    #[arg(long = "as")]
    pub r#as: Option<String>,
    /// Client slug (counterparty)
    #[arg(long)]
    pub client: String,
    /// Title — defaults to a sensible per-kind label
    #[arg(long)]
    pub title: Option<String>,
    /// Effective date (YYYY-MM-DD; defaults to today)
    #[arg(long)]
    pub effective: Option<String>,
    /// Explicit end date (YYYY-MM-DD). Mutually exclusive with --term-months.
    #[arg(long, conflicts_with = "term_months")]
    pub end: Option<String>,
    /// Term length in months. Mutually exclusive with --end.
    #[arg(long)]
    pub term_months: Option<i64>,
    /// Term length in years (sugar for --term-months N*12)
    #[arg(long, conflicts_with_all = ["end", "term_months"])]
    pub term_years: Option<i64>,
    /// Governing law (e.g. "Singapore", "England and Wales", "Delaware")
    #[arg(long)]
    pub governing_law: Option<String>,
    /// Court venue (e.g. "Courts of Singapore")
    #[arg(long)]
    pub venue: Option<String>,
    /// Fee spec for consulting / msa / sow / service.
    /// Formats: "fixed:8400:SGD" | "hourly:200:SGD" | "daily:1500:SGD"
    ///        | "retainer:5000:SGD/month".
    #[arg(long)]
    pub fee: Option<String>,
    /// Payment schedule: on-completion | monthly | on-milestone | upon-invoice
    #[arg(long)]
    pub fee_schedule: Option<String>,
    /// NDA: unilateral | mutual (default mutual)
    #[arg(long)]
    pub mutuality: Option<String>,
    /// NDA: disclosing side — us | them | both (default both for mutual)
    #[arg(long)]
    pub disclosing_side: Option<String>,
    /// NDA / consulting: purpose / scope summary
    #[arg(long)]
    pub purpose: Option<String>,
    /// Consulting: deliverable lines (repeat). e.g. --deliverable "Discovery"
    #[arg(long = "deliverable")]
    pub deliverables: Vec<String>,
    /// Consulting: who owns work-product IP (client | consultant | shared)
    #[arg(long)]
    pub ip_assignment: Option<String>,
    /// Days of notice required for termination for convenience
    #[arg(long)]
    pub termination_notice_days: Option<i64>,
    /// Set an arbitrary term key used by the clause pack's {{vars}},
    /// e.g. --term principal_text='£10,000 (ten thousand pounds)' (repeat)
    #[arg(long = "term")]
    pub terms: Vec<String>,
    /// Pack slug (default = "standard"). Picks a different clause library.
    #[arg(long)]
    pub pack: Option<String>,
    /// Append a clause slug from the pack that isn't included by default
    #[arg(long = "include")]
    pub include: Vec<String>,
    /// Remove a clause slug that the pack would include by default
    #[arg(long = "exclude")]
    pub exclude: Vec<String>,
    /// Free-form notes (not rendered on the contract body, kept for reference)
    #[arg(long)]
    pub notes: Option<String>,
    /// Override the rendered template (else config default)
    #[arg(long)]
    pub template: Option<String>,
}

#[derive(clap::Args, Debug, Clone)]
pub struct ContractListArgs {
    #[arg(long)]
    pub kind: Option<String>,
    #[arg(long)]
    pub status: Option<String>,
    #[arg(long = "as")]
    pub issuer: Option<String>,
}

#[derive(clap::Args, Debug, Clone)]
pub struct ContractRenderArgs {
    pub number: String,
    /// Template override
    #[arg(long)]
    pub template: Option<String>,
    /// Output path (defaults to issuer default_output_dir / ./contract-<number>.pdf)
    #[arg(long, short)]
    pub out: Option<String>,
    /// Open the PDF after rendering
    #[arg(long)]
    pub open: bool,
    /// Render with DRAFT watermark — implicit when status != signed/active
    #[arg(long)]
    pub draft: bool,
    /// Force render without DRAFT watermark even if status != signed/active.
    /// Use when you genuinely want a clean copy for review before signing.
    #[arg(long = "final", conflicts_with = "draft")]
    pub final_render: bool,
}

#[derive(clap::Args, Debug, Clone)]
pub struct SignArgs {
    pub number: String,
    /// us | them
    #[arg(long)]
    pub side: String,
    #[arg(long)]
    pub name: String,
    #[arg(long)]
    pub title: Option<String>,
    /// Signature date (YYYY-MM-DD; defaults to today)
    #[arg(long)]
    pub date: Option<String>,
    /// Re-sign an already-executed contract (overwrites the recorded signature)
    #[arg(long)]
    pub force: bool,
}

#[derive(clap::Args, Debug, Clone)]
pub struct ContractEditArgs {
    pub number: String,
    #[arg(long)]
    pub client: Option<String>,
    #[arg(long)]
    pub title: Option<String>,
    #[arg(long)]
    pub effective: Option<String>,
    /// Explicit end date (YYYY-MM-DD). Mutually exclusive with --term-months.
    #[arg(long, conflicts_with = "term_months")]
    pub end: Option<String>,
    #[arg(long)]
    pub term_months: Option<i64>,
    #[arg(long)]
    pub governing_law: Option<String>,
    #[arg(long)]
    pub venue: Option<String>,
    #[arg(long)]
    pub fee: Option<String>,
    #[arg(long)]
    pub fee_schedule: Option<String>,
    /// Set a term key directly, e.g. --term repayment_date=2026-12-01 (repeat)
    #[arg(long = "term")]
    pub terms: Vec<String>,
    #[arg(long)]
    pub notes: Option<String>,
    #[arg(long)]
    pub template: Option<String>,
}

#[derive(clap::Args, Debug, Clone)]
pub struct DuplicateArgs {
    pub number: String,
    #[arg(long)]
    pub client: Option<String>,
    #[arg(long = "as")]
    pub r#as: Option<String>,
}

#[derive(clap::Args, Debug, Clone)]
pub struct DeleteArgs {
    pub number: String,
    /// Allow deleting a non-draft contract
    #[arg(long)]
    pub force: bool,
}

#[derive(Subcommand, Debug)]
pub enum ContractCmd {
    /// Create a new contract
    #[command(visible_alias = "create")]
    New(ContractNewArgs),
    /// List contracts
    #[command(visible_alias = "ls")]
    List(ContractListArgs),
    /// Show one contract's metadata + clause list
    #[command(visible_alias = "get")]
    Show { number: String },
    /// Edit DRAFT contract metadata (status != draft is immutable)
    Edit(ContractEditArgs),
    /// Render contract to PDF
    Render(ContractRenderArgs),
    /// Update status: draft | sent | signed | active | expired | terminated
    Mark { number: String, status: String },
    /// Record a signature (auto-bumps status to "signed" when both sides done)
    Sign(SignArgs),
    /// Manage the clause set for a contract
    #[command(subcommand)]
    Clauses(ClauseCmd),
    /// Clone an existing contract as a new draft
    #[command(visible_alias = "clone")]
    Duplicate(DuplicateArgs),
    /// Delete a contract (draft only unless --force)
    #[command(visible_alias = "rm")]
    Delete(DeleteArgs),
}

#[derive(Subcommand, Debug)]
pub enum ClauseCmd {
    /// List clauses currently attached to a contract
    #[command(visible_alias = "ls")]
    List { number: String },
    /// Add a clause to a contract (pack default or custom from --from-file)
    Add {
        number: String,
        slug: String,
        /// Override heading
        #[arg(long)]
        heading: Option<String>,
        /// Custom body markdown — direct string
        #[arg(long)]
        body: Option<String>,
        /// Custom body markdown — read from file
        #[arg(long = "from-file")]
        from_file: Option<String>,
        /// Insert at zero-indexed position (default: end)
        #[arg(long)]
        position: Option<i64>,
    },
    /// Edit a clause that is currently attached
    Edit {
        number: String,
        slug: String,
        #[arg(long)]
        heading: Option<String>,
        #[arg(long)]
        body: Option<String>,
        #[arg(long = "from-file")]
        from_file: Option<String>,
    },
    /// Remove a clause
    #[command(visible_alias = "rm")]
    Remove { number: String, slug: String },
    /// Move a clause to a new position
    Move {
        number: String,
        slug: String,
        position: i64,
    },
    /// Reset the contract's clause set to the pack default
    Reset { number: String },
}

// ─── Packs / Templates / Config / Skill ───────────────────────────────────

#[derive(Subcommand, Debug)]
pub enum PackCmd {
    /// List available kind/pack combinations
    #[command(visible_alias = "ls")]
    List,
    /// Show available clauses (slug + heading) for a kind + pack
    #[command(visible_alias = "get")]
    Show {
        kind: String,
        #[arg(long, default_value = "standard")]
        pack: String,
    },
}

#[derive(Subcommand, Debug)]
pub enum TemplateCmd {
    /// List templates with descriptions, moods, tags, and fonts
    #[command(visible_alias = "ls")]
    List,
    /// Find a template from a free-text description of the look you want
    #[command(visible_alias = "suggest")]
    Find {
        /// e.g. "magazine masthead", "swiss minimal", "warm cream data-room"
        #[arg(required = true, num_args = 1..)]
        query: Vec<String>,
    },
    /// Render a preview contract with synthetic data
    Preview {
        name: String,
        /// Which contract kind to preview (default consulting)
        #[arg(long, default_value = "consulting")]
        kind: String,
        #[arg(long, short)]
        out: Option<String>,
    },
}

#[derive(Subcommand, Debug)]
pub enum KindsCmd {
    /// List contract kinds with descriptions and trigger tags
    #[command(visible_alias = "ls")]
    List,
    /// Find a contract kind from a free-text description of what you need
    #[command(visible_alias = "suggest")]
    Find {
        /// e.g. "stop them going around me to my contact", "lend money"
        #[arg(required = true, num_args = 1..)]
        query: Vec<String>,
    },
}

#[derive(Subcommand, Debug)]
pub enum ConfigCmd {
    /// Display current configuration
    Show,
    /// Print the config file path
    Path,
    /// Set a config key (default_issuer, default_template, open_pdf, self_update)
    Set { key: String, value: String },
}

#[derive(Subcommand, Debug)]
pub enum SkillCmd {
    /// Install the embedded skill into ~/.claude, ~/.codex, ~/.gemini
    Install,
    /// Report where the skill is installed and whether it is current
    Status,
}