goosedump 0.12.35

Browse, search, compact, and learn from coding-agent sessions
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
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (C) Jarkko Sakkinen 2026

use std::path::PathBuf;
use std::str::FromStr;

use argh::FromArgs;

use crate::engine::{Client, memory};

mod run;

pub(crate) use run::run;
/// A provider-qualified session target (`provider:id`).
#[derive(Debug, Clone)]
struct Target {
    provider: Client,
    id: String,
}

impl Target {
    fn qualified(&self) -> String {
        format!("{}:{}", self.provider.as_str(), self.id)
    }
}

impl FromStr for Target {
    type Err = String;

    fn from_str(value: &str) -> Result<Self, Self::Err> {
        let (provider, id) = value
            .split_once(':')
            .ok_or_else(|| "session must be qualified as provider:id".to_string())?;
        if id.is_empty() {
            return Err("session id must not be empty".to_string());
        }
        Ok(Self {
            provider: provider.parse()?,
            id: id.to_string(),
        })
    }
}

/// A durable-memory ID or a provider-qualified session target.
#[derive(Debug, Clone)]
enum MemoryTarget {
    Id(String),
    Session(Target),
}

impl FromStr for MemoryTarget {
    type Err = String;

    fn from_str(value: &str) -> Result<Self, Self::Err> {
        if value.starts_with("mem_") {
            return Ok(Self::Id(value.to_string()));
        }
        Target::from_str(value)
            .map(Self::Session)
            .map_err(|_| "memory target must be mem_<id> or provider:id".to_string())
    }
}

#[derive(FromArgs)]
#[argh(description = "browse, search, compact, and learn from coding-agent sessions")]
struct GoosedumpArgs {
    #[argh(subcommand)]
    command: GoosedumpCommand,
}

#[derive(FromArgs)]
#[argh(subcommand)]
enum GoosedumpCommand {
    Session(SessionArgs),
    Memory(MemoryArgs),
    #[cfg(feature = "bench")]
    BenchExpertCache(BenchExpertCacheArgs),
    #[cfg(feature = "bench")]
    BenchInference(BenchInferenceArgs),
    #[cfg(feature = "bench")]
    BenchMemory(BenchMemoryArgs),
}

#[cfg(feature = "bench")]
#[derive(FromArgs)]
#[argh(
    subcommand,
    name = "bench-expert-cache",
    description = "run synthetic routed-expert cache checks"
)]
struct BenchExpertCacheArgs {}

#[cfg(feature = "bench")]
#[derive(FromArgs)]
#[argh(
    subcommand,
    name = "bench-inference",
    description = "run the fixed local-inference benchmark"
)]
struct BenchInferenceArgs {
    #[argh(switch, description = "evict the text model from the Linux page cache")]
    cold: bool,

    #[argh(option, default = "8", description = "benchmark prompt repetitions")]
    prompt_repetitions: usize,

    #[argh(option, default = "4", description = "maximum generated tokens")]
    max_tokens: usize,
}

#[cfg(feature = "bench")]
#[derive(FromArgs)]
#[argh(
    subcommand,
    name = "bench-memory",
    description = "run the fixed sequential-memory benchmark"
)]
struct BenchMemoryArgs {}

#[derive(FromArgs)]
#[argh(
    subcommand,
    name = "session",
    description = "list, show, search, compact, copy, or remove sessions"
)]
struct SessionArgs {
    #[argh(subcommand)]
    command: SessionCommand,
}

#[derive(FromArgs)]
#[argh(subcommand)]
enum SessionCommand {
    List(ListSessionsArgs),
    Show(ShowSessionArgs),
    Find(FindSessionArgs),
    Search(SearchSessionArgs),
    Compact(CompactSessionArgs),
    Copy(CopySessionArgs),
    Remove(RemoveSessionArgs),
}

#[derive(FromArgs)]
#[argh(
    subcommand,
    name = "list",
    description = "list discovered sessions as provider:id targets"
)]
struct ListSessionsArgs {
    #[argh(option, short = 'q', description = "JSON query filter")]
    query: Option<String>,

    #[argh(switch, description = "output in JSON format")]
    json: bool,
}

#[derive(FromArgs)]
#[argh(subcommand, name = "show", description = "print a session transcript")]
struct ShowSessionArgs {
    #[argh(positional)]
    target: Target,

    #[argh(option, short = 'e', long = "entry", description = "entry ID")]
    entries: Vec<String>,

    #[argh(switch, description = "all branches")]
    all: bool,

    #[argh(option, description = "first entry ID")]
    from: Option<String>,

    #[argh(option, description = "exclusive final entry ID")]
    before: Option<String>,

    #[argh(option, long = "as", description = "render provider")]
    render_as: Option<Client>,
}

#[derive(FromArgs)]
#[argh(
    subcommand,
    name = "find",
    description = "find session messages by shell-style glob"
)]
struct FindSessionArgs {
    #[argh(positional)]
    target: Target,

    #[argh(positional)]
    pattern: String,

    #[argh(option, short = 'e', long = "entry", description = "entry ID")]
    entries: Vec<String>,

    #[argh(switch, description = "all branches")]
    all: bool,

    #[argh(option, description = "first entry ID")]
    from: Option<String>,

    #[argh(option, description = "exclusive final entry ID")]
    before: Option<String>,

    #[argh(option, long = "as", description = "render provider")]
    render_as: Option<Client>,
}

#[derive(FromArgs)]
#[argh(
    subcommand,
    name = "search",
    description = "rank session messages by relevance"
)]
struct SearchSessionArgs {
    #[argh(positional)]
    target: Target,

    #[argh(positional)]
    query: String,

    #[argh(option, short = 'e', long = "entry", description = "entry ID")]
    entries: Vec<String>,

    #[argh(switch, description = "all branches")]
    all: bool,

    #[argh(option, description = "first entry ID")]
    from: Option<String>,

    #[argh(option, description = "exclusive final entry ID")]
    before: Option<String>,

    #[argh(option, description = "result page")]
    page: Option<usize>,

    #[argh(option, long = "as", description = "render provider")]
    render_as: Option<Client>,
}

#[derive(FromArgs)]
#[argh(
    subcommand,
    name = "compact",
    description = "create a compaction summary for a session"
)]
struct CompactSessionArgs {
    #[argh(positional)]
    target: Target,

    #[argh(option, short = 'e', long = "entry", description = "entry ID")]
    entries: Vec<String>,

    #[argh(switch, description = "all branches")]
    all: bool,

    #[argh(option, description = "first entry ID")]
    from: Option<String>,

    #[argh(option, description = "exclusive final entry ID")]
    before: Option<String>,

    #[argh(option, description = "prior summary")]
    previous_summary: Option<String>,

    #[argh(
        option,
        default = "4096",
        description = "maximum estimated summary tokens; 0 disables the limit"
    )]
    summary_max_tokens: usize,

    #[argh(option, long = "as", description = "render provider")]
    render_as: Option<Client>,

    #[argh(switch, description = "screen-readable output")]
    plain: bool,
}

#[derive(FromArgs)]
#[argh(
    subcommand,
    name = "copy",
    description = "preview or write a cross-provider session copy"
)]
struct CopySessionArgs {
    #[argh(positional)]
    target: Target,

    #[argh(option, description = "destination provider")]
    to: Client,

    #[argh(switch, description = "perform the copy")]
    yes: bool,
}

#[derive(FromArgs)]
#[argh(
    subcommand,
    name = "remove",
    description = "preview or remove a session and its descendants"
)]
struct RemoveSessionArgs {
    #[argh(positional)]
    target: Target,

    #[argh(switch, description = "remove the session")]
    yes: bool,
}

#[derive(FromArgs)]
#[argh(
    subcommand,
    name = "memory",
    description = "learn, recall, list, show, forget, or status durable memory"
)]
struct MemoryArgs {
    #[argh(subcommand)]
    command: MemoryCommand,
}

#[derive(FromArgs)]
#[argh(subcommand)]
enum MemoryCommand {
    Learn(MemoryLearnArgs),
    Recall(MemoryRecallArgs),
    List(MemoryListArgs),
    Show(MemoryShowArgs),
    Forget(MemoryForgetArgs),
    Status(MemoryStatusArgs),
}

#[derive(FromArgs)]
#[argh(
    subcommand,
    name = "learn",
    description = "learn durable claims from new session evidence"
)]
struct MemoryLearnArgs {
    #[argh(positional)]
    target: Target,

    #[argh(switch, description = "all branches")]
    all: bool,

    #[argh(switch, description = "output in JSON format")]
    json: bool,
}

#[derive(FromArgs)]
#[argh(
    subcommand,
    name = "recall",
    description = "search durable claims by lexical, entity, and semantic match"
)]
struct MemoryRecallArgs {
    #[argh(positional)]
    query: String,

    #[argh(option, description = "project working directory")]
    project: Option<PathBuf>,

    #[argh(switch, description = "search every project")]
    all_projects: bool,

    #[argh(option, long = "type", description = "memory type")]
    memory_type: Option<memory::MemoryType>,

    #[argh(option, default = "10", description = "result limit")]
    limit: usize,

    #[argh(
        option,
        default = "2048",
        description = "maximum estimated result tokens"
    )]
    max_tokens: usize,

    #[argh(switch, description = "include superseded historical memories")]
    history: bool,

    #[argh(switch, description = "output in JSON format")]
    json: bool,
}

#[derive(FromArgs)]
#[argh(subcommand, name = "list", description = "list recent durable claims")]
struct MemoryListArgs {
    #[argh(option, description = "project working directory")]
    project: Option<PathBuf>,

    #[argh(switch, description = "list every project")]
    all_projects: bool,

    #[argh(option, long = "type", description = "memory type")]
    memory_type: Option<memory::MemoryType>,

    #[argh(option, default = "20", description = "result limit")]
    limit: usize,

    #[argh(switch, description = "include superseded historical memories")]
    history: bool,

    #[argh(switch, description = "output in JSON format")]
    json: bool,
}

#[derive(FromArgs)]
#[argh(
    subcommand,
    name = "show",
    description = "show one claim with cited evidence"
)]
struct MemoryShowArgs {
    #[argh(positional)]
    id: String,

    #[argh(switch, description = "output in JSON format")]
    json: bool,
}

#[derive(FromArgs)]
#[argh(
    subcommand,
    name = "forget",
    description = "tombstone a claim or a session's retained evidence"
)]
struct MemoryForgetArgs {
    #[argh(positional)]
    target: MemoryTarget,

    #[argh(switch, description = "perform the forget operation")]
    yes: bool,

    #[argh(switch, description = "output in JSON format")]
    json: bool,
}

#[derive(FromArgs)]
#[argh(
    subcommand,
    name = "status",
    description = "show memory storage and indexing status"
)]
struct MemoryStatusArgs {
    #[argh(switch, description = "output in JSON format")]
    json: bool,
}