spool-memory 0.2.3

Local-first developer memory system — persistent, structured knowledge for AI coding tools
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
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
use crate::domain::{MemoryScope, OutputFormat, TargetTool, WakeupProfile};
use clap::{Args, Parser, Subcommand, ValueEnum};
use std::path::PathBuf;

#[derive(Debug, Parser)]
#[command(
    name = "spool",
    version,
    about = "Obsidian knowledge-based context extractor"
)]
pub struct Cli {
    #[command(subcommand)]
    pub command: Command,
}

#[derive(Debug, Subcommand)]
pub enum Command {
    Get(GetArgs),
    Explain(ExplainArgs),
    Wakeup(WakeupArgs),
    Memory(MemoryArgs),
    Mcp(McpArgs),
    Hook(HookArgs),
    Init(InitArgs),
    Status(StatusArgs),
    #[cfg(feature = "embedding")]
    Embedding(EmbeddingArgs),
    Knowledge(KnowledgeArgs),
}

#[derive(Debug, Clone, Args)]
pub struct InitArgs {
    /// Vault 根目录路径
    #[arg(long)]
    pub vault: Option<PathBuf>,
    /// 项目 ID
    #[arg(long)]
    pub project_id: Option<String>,
    /// 项目仓库路径(默认当前目录)
    #[arg(long)]
    pub repo: Option<PathBuf>,
}

#[derive(Debug, Clone, Args)]
pub struct StatusArgs {
    /// 配置文件路径(默认 ~/.spool/config.toml)
    #[arg(long)]
    pub config: Option<PathBuf>,
}

#[derive(Debug, Clone, Args)]
pub struct CommonRouteArgs {
    #[arg(long)]
    pub config: PathBuf,
    #[arg(long)]
    pub task: String,
    #[arg(long)]
    pub cwd: PathBuf,
    #[arg(long, value_delimiter = ',')]
    pub files: Vec<String>,
    #[arg(long, value_enum, default_value_t = TargetValue::Claude)]
    pub target: TargetValue,
}

#[derive(Debug, Clone, Args)]
pub struct GetArgs {
    #[command(flatten)]
    pub common: CommonRouteArgs,
    #[arg(long, value_enum)]
    pub format: Option<FormatValue>,
}

#[derive(Debug, Clone, Args)]
pub struct ExplainArgs {
    #[command(flatten)]
    pub common: CommonRouteArgs,
}

#[derive(Debug, Clone, Args)]
pub struct WakeupArgs {
    #[command(flatten)]
    pub common: CommonRouteArgs,
    #[arg(long, value_enum)]
    pub profile: WakeupProfileValue,
    #[arg(long, value_enum)]
    pub format: Option<FormatValue>,
}

#[derive(Debug, Clone, Args)]
pub struct MemoryArgs {
    #[command(subcommand)]
    pub command: MemoryCommand,
}

#[derive(Debug, Clone, Subcommand)]
pub enum MemoryCommand {
    List(MemoryListArgs),
    Show(MemoryShowArgs),
    History(MemoryShowArgs),
    RecordManual(MemoryRecordArgs),
    Propose(MemoryRecordArgs),
    Accept(MemoryActionArgs),
    Promote(MemoryActionArgs),
    Archive(MemoryActionArgs),
    Import(MemoryImportArgs),
    ImportGit(MemoryImportGitArgs),
    SyncVault(MemorySyncVaultArgs),
    Dedup(MemoryDedupArgs),
    Consolidate(MemoryConsolidateArgs),
    Prune(MemoryPruneArgs),
    Lint(MemoryLintArgs),
    SyncIndex(MemorySyncIndexArgs),
    Stats(MemoryStatsArgs),
}

#[derive(Debug, Clone, Args)]
pub struct MemoryListArgs {
    #[arg(long)]
    pub config: PathBuf,
    #[arg(long, value_enum)]
    pub view: MemoryListViewValue,
    #[arg(long, value_enum)]
    pub format: Option<MemoryFormatValue>,
    #[arg(long)]
    pub daemon_bin: Option<PathBuf>,
}

#[derive(Debug, Clone, Args)]
pub struct MemoryShowArgs {
    #[arg(long)]
    pub config: PathBuf,
    #[arg(long)]
    pub record_id: String,
    #[arg(long, value_enum)]
    pub format: Option<MemoryFormatValue>,
    #[arg(long)]
    pub daemon_bin: Option<PathBuf>,
}

#[derive(Debug, Clone, Args)]
pub struct MemoryActionArgs {
    #[arg(long)]
    pub config: PathBuf,
    #[arg(long)]
    pub record_id: String,
    #[arg(long)]
    pub actor: Option<String>,
    #[arg(long)]
    pub reason: Option<String>,
    #[arg(long, value_delimiter = ',')]
    pub evidence_refs: Vec<String>,
}

#[derive(Debug, Clone, Args)]
pub struct MemoryRecordArgs {
    #[arg(long)]
    pub config: PathBuf,
    #[arg(long)]
    pub title: String,
    #[arg(long)]
    pub summary: String,
    #[arg(long)]
    pub memory_type: String,
    #[arg(long, value_enum)]
    pub scope: MemoryScopeValue,
    #[arg(long)]
    pub source_ref: String,
    #[arg(long)]
    pub project_id: Option<String>,
    #[arg(long)]
    pub user_id: Option<String>,
    #[arg(long)]
    pub sensitivity: Option<String>,
    #[arg(long)]
    pub actor: Option<String>,
    #[arg(long)]
    pub reason: Option<String>,
    #[arg(long, value_delimiter = ',')]
    pub evidence_refs: Vec<String>,
}

#[derive(Debug, Clone, Args)]
pub struct MemoryImportArgs {
    #[arg(long)]
    pub config: PathBuf,
    /// 来源 provider(claude / codex),对应 session_sources 读取目录
    #[arg(long, value_enum)]
    pub provider: SessionProviderValue,
    /// provider-local session id(raw,不带 "claude:" / "codex:" 前缀)
    #[arg(long)]
    pub session_id: String,
    /// 默认只打印候选;加 --apply 才真正写入 ledger
    #[arg(long, default_value_t = false)]
    pub apply: bool,
    #[arg(long, default_value = "spool-importer")]
    pub actor: String,
    #[arg(long, value_enum, default_value_t = MemoryFormatValue::Markdown)]
    pub format: MemoryFormatValue,
}

#[derive(Debug, Clone, Args)]
pub struct MemoryImportGitArgs {
    #[arg(long)]
    pub config: PathBuf,
    /// Git 仓库路径(默认当前目录)
    #[arg(long)]
    pub repo: Option<PathBuf>,
    /// 扫描最近 N 条 commit(默认 30)
    #[arg(long, default_value_t = 30)]
    pub limit: usize,
    /// 只预览不写入
    #[arg(long, default_value_t = false)]
    pub dry_run: bool,
}

#[derive(Debug, Clone, Args)]
pub struct MemorySyncVaultArgs {
    #[arg(long)]
    pub config: PathBuf,
    /// 不写入文件,仅打印将会发生的动作
    #[arg(long, default_value_t = false)]
    pub dry_run: bool,
    /// 对缺少 entities/tags/triggers 的记录进行启发式补充
    #[arg(long, default_value_t = false)]
    pub enrich: bool,
}

#[derive(Debug, Clone, Args)]
pub struct MemoryDedupArgs {
    #[arg(long)]
    pub config: PathBuf,
}

#[derive(Debug, Clone, Args)]
pub struct MemoryConsolidateArgs {
    #[arg(long)]
    pub config: PathBuf,
    /// 只预览不执行(默认行为)
    #[arg(long, default_value_t = false)]
    pub dry_run: bool,
    /// 执行合并
    #[arg(long, default_value_t = false)]
    pub apply: bool,
}

#[derive(Debug, Clone, Args)]
pub struct MemoryPruneArgs {
    #[arg(long)]
    pub config: PathBuf,
    /// 只预览不执行(默认行为)
    #[arg(long, default_value_t = false)]
    pub dry_run: bool,
    /// 执行归档
    #[arg(long, default_value_t = false)]
    pub apply: bool,
}

#[derive(Debug, Clone, Args)]
pub struct MemoryLintArgs {
    #[arg(long)]
    pub config: PathBuf,
    /// 以 JSON 输出 (默认 markdown)
    #[arg(long, default_value_t = false)]
    pub json: bool,
}

#[derive(Debug, Clone, Args)]
pub struct MemorySyncIndexArgs {
    #[arg(long)]
    pub config: PathBuf,
    /// Write the regenerated INDEX.md (default is dry-run preview).
    #[arg(long, default_value_t = false)]
    pub apply: bool,
}

#[derive(Debug, Clone, Args)]
pub struct MemoryStatsArgs {
    #[arg(long)]
    pub config: PathBuf,
}

// ─────────────────────────────────────────────────────────────────────
// spool mcp <subcommand> — installer surface for AI client integration.
// R1 wires Claude Code only; the trait infrastructure (see
// `src/installers/`) reserves room for Codex/Cursor in P1.
// ─────────────────────────────────────────────────────────────────────

#[derive(Debug, Clone, Args)]
pub struct McpArgs {
    #[command(subcommand)]
    pub command: McpCommand,
}

#[derive(Debug, Clone, Subcommand)]
pub enum McpCommand {
    Install(McpInstallArgs),
    Update(McpUpdateArgs),
    Uninstall(McpUninstallArgs),
    Doctor(McpDoctorArgs),
}

#[derive(Debug, Clone, Args)]
pub struct McpInstallArgs {
    #[arg(long, value_enum, default_value_t = ClientValue::Claude)]
    pub client: ClientValue,
    /// 指向 spool.toml 配置文件 (mcpServers 条目里写绝对路径)
    #[arg(long)]
    pub config: PathBuf,
    /// 自定义 spool-mcp 二进制路径 (默认走 ~/.cargo/bin/spool-mcp)
    #[arg(long)]
    pub binary_path: Option<PathBuf>,
    /// 仅打印将要发生的写入,不修改任何文件
    #[arg(long, default_value_t = false)]
    pub dry_run: bool,
    /// 已存在 spool 条目时强制覆盖 (默认拒绝并要求 uninstall 后重装)
    #[arg(long, default_value_t = false)]
    pub force: bool,
    /// 输出格式
    #[arg(long, value_enum, default_value_t = McpReportFormat::Text)]
    pub format: McpReportFormat,
}

#[derive(Debug, Clone, Args)]
pub struct McpUpdateArgs {
    #[arg(long, value_enum, default_value_t = ClientValue::Claude)]
    pub client: ClientValue,
    /// 指向 spool.toml 配置文件 (mcpServers 条目里写绝对路径)
    #[arg(long)]
    pub config: PathBuf,
    /// 自定义 spool-mcp 二进制路径 (默认走 ~/.cargo/bin/spool-mcp)
    #[arg(long)]
    pub binary_path: Option<PathBuf>,
    /// 仅打印将要发生的写入,不修改任何文件
    #[arg(long, default_value_t = false)]
    pub dry_run: bool,
    /// 输出格式
    #[arg(long, value_enum, default_value_t = McpReportFormat::Text)]
    pub format: McpReportFormat,
}

#[derive(Debug, Clone, Args)]
pub struct McpUninstallArgs {
    #[arg(long, value_enum, default_value_t = ClientValue::Claude)]
    pub client: ClientValue,
    #[arg(long, default_value_t = false)]
    pub dry_run: bool,
    #[arg(long, value_enum, default_value_t = McpReportFormat::Text)]
    pub format: McpReportFormat,
}

#[derive(Debug, Clone, Args)]
pub struct McpDoctorArgs {
    #[arg(long, value_enum, default_value_t = ClientValue::Claude)]
    pub client: ClientValue,
    /// 指向 spool.toml 配置文件 (诊断会校验该路径存在)
    #[arg(long)]
    pub config: PathBuf,
    /// 自定义 spool-mcp 二进制路径
    #[arg(long)]
    pub binary_path: Option<PathBuf>,
    #[arg(long, value_enum, default_value_t = McpReportFormat::Text)]
    pub format: McpReportFormat,
}

#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum ClientValue {
    Claude,
    Codex,
    Cursor,
    Opencode,
}

#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum McpReportFormat {
    Text,
    Json,
}

// ─────────────────────────────────────────────────────────────────────
// spool hook <subcommand> — invoked by AI client hook scripts.
// All hooks MUST exit 0 even on internal failure (D7 in PRD); the
// `run_silent` wrapper in `src/hook_runtime/mod.rs` enforces this.
// ─────────────────────────────────────────────────────────────────────

#[derive(Debug, Clone, Args)]
pub struct HookArgs {
    #[command(subcommand)]
    pub command: HookCommand,
}

#[derive(Debug, Clone, Subcommand)]
pub enum HookCommand {
    SessionStart(HookSessionStartArgs),
    UserPrompt(HookSimpleArgs),
    PostToolUse(HookPostToolUseArgs),
    Stop(HookStopArgs),
    PreCompact(HookSimpleArgs),
}

#[derive(Debug, Clone, Args)]
pub struct HookSessionStartArgs {
    #[arg(long)]
    pub config: PathBuf,
    /// 用户当前工作目录 (默认 current_dir)
    #[arg(long)]
    pub cwd: Option<PathBuf>,
    /// 可选 task hint (默认 "session start")
    #[arg(long)]
    pub task: Option<String>,
    /// wakeup profile (默认 project)
    #[arg(long, value_enum, default_value_t = WakeupProfileValue::Project)]
    pub profile: WakeupProfileValue,
}

#[derive(Debug, Clone, Args)]
pub struct HookSimpleArgs {
    #[arg(long)]
    pub config: PathBuf,
    #[arg(long)]
    pub cwd: Option<PathBuf>,
}

#[derive(Debug, Clone, Args)]
pub struct HookPostToolUseArgs {
    #[arg(long)]
    pub config: PathBuf,
    #[arg(long)]
    pub cwd: Option<PathBuf>,
    /// 触发的工具名 (Bash / Edit / ...)
    #[arg(long)]
    pub tool_name: Option<String>,
    /// 工具调用 payload (会被截断到 4 KiB)
    #[arg(long)]
    pub payload: Option<String>,
}

/// Stop hook input. Supports three ways to locate the session
/// transcript (in priority order):
///   1. `--transcript-path` — explicit absolute path
///   2. `--hook-input` — raw JSON from Claude Code's stdin payload
///      containing `{"transcript_path": "..."}`
///   3. fallback: scan `~/.claude/projects/<sanitized-cwd>/` and
///      pick the most recently modified `.jsonl`
#[derive(Debug, Clone, Args)]
pub struct HookStopArgs {
    #[arg(long)]
    pub config: PathBuf,
    #[arg(long)]
    pub cwd: Option<PathBuf>,
    #[arg(long)]
    pub transcript_path: Option<PathBuf>,
    /// Raw stdin payload Claude Code sends to Stop hook. Hook script
    /// passes this in via `--hook-input "$(cat)"`.
    #[arg(long)]
    pub hook_input: Option<String>,
    /// Test/admin override for `$HOME` (used by smoke tests + dry
    /// runs). Production callers leave this empty and we read the
    /// real `$HOME`.
    #[arg(long, hide = true)]
    pub home: Option<PathBuf>,
}

#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum SessionProviderValue {
    Claude,
    Codex,
}

impl SessionProviderValue {
    pub fn as_str(self) -> &'static str {
        match self {
            Self::Claude => "claude",
            Self::Codex => "codex",
        }
    }
}

#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum TargetValue {
    Claude,
    Codex,
    Opencode,
}

impl From<TargetValue> for TargetTool {
    fn from(value: TargetValue) -> Self {
        match value {
            TargetValue::Claude => TargetTool::Claude,
            TargetValue::Codex => TargetTool::Codex,
            TargetValue::Opencode => TargetTool::Opencode,
        }
    }
}

#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum FormatValue {
    Prompt,
    Markdown,
    Json,
}

#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum WakeupProfileValue {
    Developer,
    Project,
}

#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum MemoryListViewValue {
    PendingReview,
    WakeupReady,
}

#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum MemoryFormatValue {
    Markdown,
    Json,
}

#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum MemoryScopeValue {
    User,
    Project,
    Workspace,
    Team,
    Agent,
}

impl From<FormatValue> for OutputFormat {
    fn from(value: FormatValue) -> Self {
        match value {
            FormatValue::Prompt => OutputFormat::Prompt,
            FormatValue::Markdown => OutputFormat::Markdown,
            FormatValue::Json => OutputFormat::Json,
        }
    }
}

impl From<WakeupProfileValue> for WakeupProfile {
    fn from(value: WakeupProfileValue) -> Self {
        match value {
            WakeupProfileValue::Developer => WakeupProfile::Developer,
            WakeupProfileValue::Project => WakeupProfile::Project,
        }
    }
}

impl From<MemoryScopeValue> for MemoryScope {
    fn from(value: MemoryScopeValue) -> Self {
        match value {
            MemoryScopeValue::User => MemoryScope::User,
            MemoryScopeValue::Project => MemoryScope::Project,
            MemoryScopeValue::Workspace => MemoryScope::Workspace,
            MemoryScopeValue::Team => MemoryScope::Team,
            MemoryScopeValue::Agent => MemoryScope::Agent,
        }
    }
}

// ─────────────────────────────────────────────────────────────────────
// spool embedding <subcommand> — local embedding model management.
// Feature-gated behind `embedding`.
// ─────────────────────────────────────────────────────────────────────

#[cfg(feature = "embedding")]
#[derive(Debug, Clone, Args)]
pub struct EmbeddingArgs {
    #[command(subcommand)]
    pub command: EmbeddingCommand,
}

#[cfg(feature = "embedding")]
#[derive(Debug, Clone, Subcommand)]
pub enum EmbeddingCommand {
    /// 构建/重建嵌入索引
    Build(EmbeddingBuildArgs),
    /// 显示索引状态(记录数、模型、大小)
    Status(EmbeddingStatusArgs),
}

#[cfg(feature = "embedding")]
#[derive(Debug, Clone, Args)]
pub struct EmbeddingBuildArgs {
    #[arg(long)]
    pub config: PathBuf,
}

#[cfg(feature = "embedding")]
#[derive(Debug, Clone, Args)]
pub struct EmbeddingStatusArgs {
    #[arg(long)]
    pub config: PathBuf,
}

// ─────────────────────────────────────────────────────────────────────
// spool knowledge <subcommand> — knowledge distillation pipeline.
// ─────────────────────────────────────────────────────────────────────

#[derive(Debug, Clone, Args)]
pub struct KnowledgeArgs {
    #[command(subcommand)]
    pub command: KnowledgeCommand,
}

#[derive(Debug, Clone, Subcommand)]
pub enum KnowledgeCommand {
    /// 检测可聚合的碎片集群并生成知识页草稿
    Distill(KnowledgeDistillArgs),
}

#[derive(Debug, Clone, Args)]
pub struct KnowledgeDistillArgs {
    #[arg(long)]
    pub config: PathBuf,
    /// 只预览不写入
    #[arg(long, default_value_t = false)]
    pub dry_run: bool,
    /// 执行写入(生成 candidate 知识页)
    #[arg(long, default_value_t = false)]
    pub apply: bool,
    /// 操作者
    #[arg(long, default_value = "spool-knowledge")]
    pub actor: String,
}