kiromi-ai-cli 0.2.2

Operator and developer CLI for the kiromi-ai-memory store: append, search, snapshot, regenerate, migrate-scheme, gc, audit-tail.
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
// SPDX-License-Identifier: Apache-2.0 OR MIT
//! Top-level clap derive surface.

use std::path::PathBuf;

use clap::{Args, Parser, Subcommand};

/// `kiromi-ai` — operator/dev CLI for the kiromi-ai-memory memory store.
#[derive(Debug, Parser)]
#[command(name = "kiromi-ai", version, about, long_about = None)]
pub(crate) struct Cli {
    /// Globals shared by every subcommand.
    #[command(flatten)]
    pub(crate) globals: GlobalArgs,

    /// Subcommand to run.
    #[command(subcommand)]
    pub(crate) command: Command,
}

/// Globals shared by every subcommand.
#[derive(Debug, Args, Clone)]
pub(crate) struct GlobalArgs {
    /// Path to the config file. Defaults to the per-OS user config dir.
    #[arg(long, env = "KIROMI_AI_CONFIG", global = true)]
    pub(crate) config: Option<PathBuf>,

    /// Storage URI (e.g. `local:./store`, `memory:`).
    #[arg(long, env = "KIROMI_AI_STORAGE", global = true)]
    pub(crate) storage: Option<String>,

    /// Metadata URI (e.g. `sqlite:./store/metadata.db`, `sqlite::memory:`).
    #[arg(long, env = "KIROMI_AI_METADATA", global = true)]
    pub(crate) metadata: Option<String>,

    /// Tenant id.
    #[arg(long, env = "KIROMI_AI_TENANT", global = true)]
    pub(crate) tenant: Option<String>,

    /// Partition scheme template.
    #[arg(long, env = "KIROMI_AI_SCHEME", global = true)]
    pub(crate) scheme: Option<String>,

    /// Embedder family (e.g. `onnx`, `mock`).
    #[arg(
        long = "embedder-family",
        env = "KIROMI_AI_EMBEDDER_FAMILY",
        global = true
    )]
    pub(crate) embedder_family: Option<String>,

    /// Embedder config as raw JSON (`'{"model":"..."}'`) or `@path/to/cfg.json`.
    #[arg(
        long = "embedder-config",
        env = "KIROMI_AI_EMBEDDER_CONFIG",
        global = true
    )]
    pub(crate) embedder_config: Option<String>,

    /// Disable engine-side embedding. Append must then carry `--embedding`.
    #[arg(long = "no-embedder", env = "KIROMI_AI_NO_EMBEDDER", global = true)]
    pub(crate) no_embedder: bool,

    /// Audit-log actor field.
    #[arg(long, env = "KIROMI_AI_ACTOR", global = true)]
    pub(crate) actor: Option<String>,

    /// Emit machine-readable JSON instead of human-readable tables.
    #[arg(long, env = "KIROMI_AI_JSON", global = true)]
    pub(crate) json: bool,

    /// Increase log verbosity. `-v` = debug, `-vv` = trace.
    #[arg(short, long, action = clap::ArgAction::Count, global = true)]
    pub(crate) verbose: u8,
}

/// Top-level subcommand.
#[derive(Debug, Subcommand)]
pub(crate) enum Command {
    /// Initialise a fresh store: write `schema_meta`, validate connectivity.
    Init(InitArgs),
    /// Append a memory to a partition.
    Append(AppendArgs),
    /// Fetch a single memory.
    Get(GetArgs),
    /// List memories under a partition.
    List(ListArgs),
    /// Search across memories.
    Search(SearchArgs),
    /// Same-leaf related lookup.
    Related(RelatedArgs),
    /// Manage explicit links.
    #[command(subcommand)]
    Link(LinkCmd),
    /// Soft-delete a single memory.
    Delete(DeleteArgs),
    /// Soft-delete every memory under a partition.
    #[command(name = "delete-partition")]
    DeletePartition(DeletePartitionArgs),
    /// Dump SQL + audit-log rows for a memory or partition.
    Inspect(InspectArgs),
    /// Copy every live memory under a partition to a directory.
    Export(ExportArgs),
    /// Manage typed memory metadata attributes (Plan 11).
    #[command(subcommand)]
    Attribute(AttributeCmd),
    /// Manage point-in-time snapshots (Plan 12).
    #[command(subcommand)]
    Snapshot(SnapshotCmd),
    /// Reindex / regenerate-embeddings / list-stale subjects (Plan 12).
    #[command(subcommand)]
    Regenerate(RegenerateCmd),
    /// Repartition the store under a new partition scheme (Plan 12).
    #[command(name = "migrate-scheme")]
    MigrateScheme(MigrateSchemeArgs),
    /// Reap orphan blobs after a retention window (Plan 12).
    Gc(GcArgs),
    /// Assemble a token-budget-bounded context block list (Plan 12).
    Context(ContextArgs),
}

/// `snapshot` subcommand variants (Plan 12).
#[derive(Debug, Subcommand)]
pub(crate) enum SnapshotCmd {
    /// Take a fresh snapshot.
    Create(SnapshotCreateArgs),
    /// List every known snapshot.
    List,
    /// Delete a snapshot row (manifest blob is reaped by `gc`).
    Delete(SnapshotDeleteArgs),
    /// Restore the live set to a snapshot.
    Restore(SnapshotRestoreArgs),
}

/// `snapshot create` args.
#[derive(Debug, Args)]
pub(crate) struct SnapshotCreateArgs {
    /// Optional human tag.
    #[arg(long)]
    pub(crate) tag: Option<String>,
    /// Optional human reason.
    #[arg(long)]
    pub(crate) reason: Option<String>,
}

/// `snapshot delete` args.
#[derive(Debug, Args)]
pub(crate) struct SnapshotDeleteArgs {
    /// Snapshot id (ULID).
    pub(crate) id: String,
}

/// `snapshot restore` args.
#[derive(Debug, Args)]
pub(crate) struct SnapshotRestoreArgs {
    /// Snapshot id (ULID).
    pub(crate) id: String,
    /// Skip the typed-attribute round-trip.
    #[arg(long = "no-attributes")]
    pub(crate) no_attributes: bool,
}

/// `regenerate` subcommand variants (Plan 12).
#[derive(Debug, Subcommand)]
pub(crate) enum RegenerateCmd {
    /// Re-embed every live memory under the supplied scope.
    Embeddings(RegenerateEmbeddingsArgs),
    /// List subjects whose summary is stale (or every subject under
    /// `--scope` when `--force` is set).
    #[command(name = "summaries-list")]
    SummariesList(RegenerateSummariesListArgs),
    /// Cheap rebuild of vector + lexical indices.
    Reindex(ReindexArgs),
}

/// Common scope flag.
#[derive(Debug, Args)]
pub(crate) struct ScopeArg {
    /// Scope: `all`, `tenant`, or `partition=<path>`.
    #[arg(long, default_value = "all")]
    pub(crate) scope: String,
}

/// `regenerate embeddings` args.
#[derive(Debug, Args)]
pub(crate) struct RegenerateEmbeddingsArgs {
    #[command(flatten)]
    pub(crate) scope: ScopeArg,
}

/// `regenerate summaries-list` args.
#[derive(Debug, Args)]
pub(crate) struct RegenerateSummariesListArgs {
    #[command(flatten)]
    pub(crate) scope: ScopeArg,
    /// Yield every subject under scope regardless of stale flag.
    #[arg(long)]
    pub(crate) force: bool,
    /// Style filter — `compact` or `detailed`.
    #[arg(long, default_value = "compact")]
    pub(crate) style: String,
}

/// `regenerate reindex` args.
#[derive(Debug, Args)]
pub(crate) struct ReindexArgs {
    #[command(flatten)]
    pub(crate) scope: ScopeArg,
}

/// `migrate-scheme` args.
#[derive(Debug, Args)]
pub(crate) struct MigrateSchemeArgs {
    /// New partition scheme template.
    #[arg(long = "new-scheme")]
    pub(crate) new_scheme: String,
    /// Mapper binary — receives JSON memory records on stdin (one per
    /// line) and emits JSON `{"partitions": {"k": "v", ...}}` lines.
    #[arg(long = "mapper-binary")]
    pub(crate) mapper_binary: std::path::PathBuf,
    /// Dry run.
    #[arg(long)]
    pub(crate) dry_run: bool,
    /// Skip the pre-migration snapshot.
    #[arg(long = "no-snapshot")]
    pub(crate) no_snapshot: bool,
    /// Memories per checkpoint batch.
    #[arg(long = "batch-size", default_value_t = 64)]
    pub(crate) batch_size: u32,
}

/// `gc` args.
#[derive(Debug, Args)]
pub(crate) struct GcArgs {
    /// Retention window (e.g. `24h`, `0`).
    #[arg(long = "retain-for", default_value = "24h")]
    pub(crate) retain_for: String,
    /// Dry run.
    #[arg(long)]
    pub(crate) dry_run: bool,
}

/// `context` args.
#[derive(Debug, Args)]
pub(crate) struct ContextArgs {
    /// Focus node — `memory:<id>:<partition>` or `partition:<path>`.
    #[arg(long)]
    pub(crate) focus: String,
    /// Token budget.
    #[arg(long, default_value_t = 4_000)]
    pub(crate) budget: u32,
    /// Top-K memories to include for partition focus.
    #[arg(long = "top-k", default_value_t = 5)]
    pub(crate) top_k: u32,
    /// Include the tenant memo block.
    #[arg(long, default_value_t = true)]
    pub(crate) memo: bool,
}

/// `attribute` subcommand variants (Plan 11).
#[derive(Debug, Subcommand)]
pub(crate) enum AttributeCmd {
    /// Set one attribute on a memory.
    Set(AttrSetArgs),
    /// Read one attribute.
    Get(AttrGetArgs),
    /// Clear one attribute.
    Clear(AttrClearArgs),
    /// List every attribute on a memory.
    List(AttrListArgs),
    /// Find memory ids by exact (key, value) match.
    Find(AttrFindArgs),
    /// Find memory ids by inclusive `[min, max]` range on `(key, value)`.
    FindRange(AttrFindRangeArgs),
}

/// Shared kind tag for attribute CLI args.
#[derive(Debug, Args, Clone)]
pub(crate) struct AttrKindArg {
    /// Value kind: `string`, `int`, `decimal`, `bool`, `timestamp`, or `array`.
    /// `array` parses `--value` as a JSON array of typed values.
    #[arg(long, default_value = "string")]
    pub(crate) kind: String,
}

/// `attribute set` args.
#[derive(Debug, Args)]
pub(crate) struct AttrSetArgs {
    /// Memory id.
    #[arg(long)]
    pub(crate) memory: String,
    /// Attribute key.
    #[arg(long)]
    pub(crate) key: String,
    /// Attribute value (parsed against `--kind`).
    #[arg(long)]
    pub(crate) value: String,
    #[command(flatten)]
    pub(crate) kind: AttrKindArg,
}

/// `attribute get` args.
#[derive(Debug, Args)]
pub(crate) struct AttrGetArgs {
    /// Memory id.
    #[arg(long)]
    pub(crate) memory: String,
    /// Attribute key.
    #[arg(long)]
    pub(crate) key: String,
}

/// `attribute clear` args.
#[derive(Debug, Args)]
pub(crate) struct AttrClearArgs {
    /// Memory id.
    #[arg(long)]
    pub(crate) memory: String,
    /// Attribute key.
    #[arg(long)]
    pub(crate) key: String,
}

/// `attribute list` args.
#[derive(Debug, Args)]
pub(crate) struct AttrListArgs {
    /// Memory id.
    #[arg(long)]
    pub(crate) memory: String,
}

/// `attribute find` args.
#[derive(Debug, Args)]
pub(crate) struct AttrFindArgs {
    /// Attribute key.
    #[arg(long)]
    pub(crate) key: String,
    /// Attribute value (parsed against `--kind`).
    #[arg(long)]
    pub(crate) value: String,
    #[command(flatten)]
    pub(crate) kind: AttrKindArg,
}

/// `attribute find-range` args.
#[derive(Debug, Args)]
pub(crate) struct AttrFindRangeArgs {
    /// Attribute key.
    #[arg(long)]
    pub(crate) key: String,
    /// Inclusive minimum.
    #[arg(long)]
    pub(crate) min: String,
    /// Inclusive maximum.
    #[arg(long)]
    pub(crate) max: String,
    /// Kind: `int`, `decimal`, or `timestamp`.
    #[arg(long, default_value = "int")]
    pub(crate) kind: String,
}

/// `init` subcommand args.
#[derive(Debug, Args)]
pub(crate) struct InitArgs {
    /// Force re-initialise. Slice 1: errors on existing store.
    #[arg(long)]
    pub(crate) force: bool,
}

/// `append` subcommand args.
#[derive(Debug, Args)]
pub(crate) struct AppendArgs {
    /// `key=value,key=value` partition selector.
    #[arg(long)]
    pub(crate) partition: String,

    /// Read content from this file. Conflicts with `--stdin` and `--message`.
    #[arg(long, conflicts_with_all = ["stdin", "message"])]
    pub(crate) file: Option<PathBuf>,

    /// Read content from stdin.
    #[arg(long, conflicts_with_all = ["file", "message"])]
    pub(crate) stdin: bool,

    /// Inline message text. Conflicts with `--file` / `--stdin`.
    #[arg(long, conflicts_with_all = ["file", "stdin"])]
    pub(crate) message: Option<String>,

    /// Content kind. `md` (default) or `txt`.
    #[arg(long, default_value = "md")]
    pub(crate) kind: String,

    /// Path to a JSON file containing a `Vec<f32>`. Required when
    /// `--no-embedder` is set.
    #[arg(long)]
    pub(crate) embedding: Option<PathBuf>,

    /// Explicit links — repeatable. Each value is a memory id (ULID).
    #[arg(long = "link", value_name = "MEMORY_ID")]
    pub(crate) links: Vec<String>,
}

/// `get` subcommand args.
#[derive(Debug, Args)]
pub(crate) struct GetArgs {
    /// Memory id (ULID).
    pub(crate) id: String,
}

/// `list` subcommand args.
#[derive(Debug, Args)]
pub(crate) struct ListArgs {
    /// `key=value,...` partition selector.
    #[arg(long)]
    pub(crate) partition: String,

    /// Page size.
    #[arg(long, default_value_t = 50)]
    pub(crate) limit: u32,

    /// Continuation cursor returned by a prior page.
    #[arg(long)]
    pub(crate) cursor: Option<String>,

    /// Include soft-tombstoned memories.
    #[arg(long = "include-tombstoned")]
    pub(crate) include_tombstoned: bool,
}

/// `search` subcommand args.
#[derive(Debug, Args)]
pub(crate) struct SearchArgs {
    /// Query text.
    pub(crate) query: String,

    /// Pure semantic search.
    #[arg(long, conflicts_with_all = ["text", "hybrid"])]
    pub(crate) semantic: bool,
    /// Pure lexical search.
    #[arg(long, conflicts_with_all = ["semantic", "hybrid"])]
    pub(crate) text: bool,
    /// Hybrid (default).
    #[arg(long, conflicts_with_all = ["semantic", "text"])]
    pub(crate) hybrid: bool,

    /// Hybrid alpha (0.0–1.0). Ignored unless `--hybrid`.
    #[arg(long)]
    pub(crate) alpha: Option<f32>,

    /// Top-K hits to return.
    #[arg(long, default_value_t = 10)]
    pub(crate) top: usize,

    /// Restrict the search to one partition (full path).
    #[arg(long)]
    pub(crate) within: Option<String>,
}

/// `related` subcommand args.
#[derive(Debug, Args)]
pub(crate) struct RelatedArgs {
    /// Memory id (ULID).
    pub(crate) id: String,
    /// Top-K neighbours.
    #[arg(long, default_value_t = 5)]
    pub(crate) top: usize,
}

/// `link` subcommand variants.
#[derive(Debug, Subcommand)]
pub(crate) enum LinkCmd {
    /// Add a `src → dst` link (and the implicit reverse).
    Add {
        /// Source memory id.
        src: String,
        /// Destination memory id.
        dst: String,
    },
    /// Remove a link.
    Remove {
        /// Source memory id.
        src: String,
        /// Destination memory id.
        dst: String,
    },
    /// List all links sourced at a memory.
    List {
        /// Memory id (ULID).
        id: String,
    },
}

/// `delete` subcommand args.
#[derive(Debug, Args)]
pub(crate) struct DeleteArgs {
    /// Memory id (ULID).
    pub(crate) id: String,
}

/// `delete-partition` subcommand args.
#[derive(Debug, Args)]
pub(crate) struct DeletePartitionArgs {
    /// Full partition path, e.g. `user=alex/year=2026/month=05/topic=meetings`.
    pub(crate) path: String,
}

/// `inspect` subcommand args.
#[derive(Debug, Args)]
pub(crate) struct InspectArgs {
    /// Inspect a single memory.
    #[arg(long, conflicts_with = "partition")]
    pub(crate) memory: Option<String>,
    /// Inspect a partition.
    #[arg(long, conflicts_with = "memory")]
    pub(crate) partition: Option<String>,
}

/// `export` subcommand args.
#[derive(Debug, Args)]
pub(crate) struct ExportArgs {
    /// Partition selector.
    #[arg(long)]
    pub(crate) partition: String,
    /// Destination directory (created if absent).
    #[arg(long)]
    pub(crate) to: PathBuf,
}