diff options
| author | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-11-13 13:23:54 +0000 |
|---|---|---|
| committer | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-11-13 13:23:54 +0000 |
| commit | 36000f876225aabd5740cbb0c7045ad0e89de3a2 (patch) | |
| tree | 164daedcdf2e6e880df5182fd7e01d7da07ebe3e | |
| parent | 285e0fd4a43a10f87e2689dbb76be9e102fb2fa1 (diff) | |
| download | ai-memory-36000f876225aabd5740cbb0c7045ad0e89de3a2.tar.gz | |
list: one line per reasoning entry, short hash first
why SYMBOL and search both need a starting point -- a symbol name or a word you already know. `list` is the inventory: short hash, entry id, kind, and the body flattened to a line. Unattached entries sort first and read "uncommitted"; a superseded entry reads "kind->#N". --session, --kind and --commit narrow it.
| -rw-r--r-- | doc/SKILL.md | 4 | ||||
| -rw-r--r-- | main.odin | 118 |
2 files changed, 122 insertions, 0 deletions
diff --git a/doc/SKILL.md b/doc/SKILL.md index 67b4529..99076e8 100644 --- a/doc/SKILL.md +++ b/doc/SKILL.md @@ -233,6 +233,10 @@ nothing. Amending *before* recording is cheaper than repairing afterwards. `symbols.basename` (`compute_gemma`), then a `LIKE '%…%'` scan for partial names. - `log` prints how many reasoning entries each commit carries — commits with `(0)` are the ones worth annotating later. +- `list` is the inventory view: one line per entry, `short-hash #id kind body` + truncated to a line. Unattached entries come first (labelled `uncommitted`), + then the newest commit's, and a superseded entry reads `kind->#N`. `--session`, + `--kind` and `--commit` narrow it; skim `list` before opening entries with `why`. ## Troubleshooting diff --git a/main.odin b/main.odin index 6079bd5..a81800c 100644 --- a/main.odin +++ b/main.odin @@ -18,6 +18,8 @@ usage: ai-memory <command> [options] [--basis HOW] [--supersedes ID] attach <HASH|HEAD> [--session S] link unattached reasoning to a commit why <symbol> [--all] commits and reasoning that touched a symbol + list [--limit N] one line per reasoning entry, newest commit first + [--session S] [--kind K] [--commit HASH] search <text> [--all] full-text search over reasoning (--all also shows superseded entries) log [--limit N] recent commits and how much reasoning they carry @@ -157,6 +159,8 @@ main :: proc() { } case "log": ok = cmd_log(args[1:]) + case "list": + ok = cmd_list(args[1:]) case "status": ok = cmd_status() case "help", "--help", "-h": @@ -835,6 +839,28 @@ fmt_ts :: proc(ts: i64) -> string { } // indent_rest keeps multi-line reasoning readable under its commit line. +// one_line flattens a body onto one line and truncates it, for listings. +one_line :: proc(s: string, max: int) -> string { + out := make([dynamic]u8, 0, len(s), context.temp_allocator) + space := false + for i in 0 ..< len(s) { + c := s[i] + if c == '\n' || c == '\r' || c == '\t' || c == ' ' { + space = len(out) > 0 + continue + } + if space { + append(&out, ' ') + space = false + } + append(&out, c) + } + if len(out) <= max { + return string(out[:]) + } + return fmt.tprintf("%s...", string(out[:max - 3])) +} + indent_rest :: proc(s: string) -> string { out, _ := strings.replace_all(s, "\n", "\n ", context.temp_allocator) return out @@ -885,3 +911,95 @@ flag_bool :: proc(args: []string, name: string) -> bool { return false } + +// ---- list ----------------------------------------------------------------- + +// cmd_list prints one line per reasoning entry, newest commit first, so the +// record can be skimmed without following symbol to commit to entry. +cmd_list :: proc(args: []string) -> bool { + limit := parse_int(flag_or(args, "--limit", "40"), 40) + session := flag_or(args, "--session", "") + kind := flag_or(args, "--kind", "") + commit := flag_or(args, "--commit", "") + + db, ok := open_db() + if !ok { + return false + } + defer db_close(&db) + + // Anonymous placeholders, bound in the order they appear. + query := `select r.id, r.kind, r.body, r.commit_hash, coalesce(c.author_ts, 0), + (select min(s.id) from reasoning s where s.supersedes = r.id) + from reasoning r + left join commits c on c.hash = r.commit_hash` + + conds := make([dynamic]string, 0, 3, context.temp_allocator) + if len(session) > 0 { + append(&conds, "r.session_id = ?") + } + if len(kind) > 0 { + append(&conds, "r.kind = ?") + } + if len(commit) > 0 { + append(&conds, "r.commit_hash like ?") + } + if len(conds) > 0 { + filter := "" + for c, i in conds { + if i > 0 { + filter = fmt.tprintf("%s and", filter) + } + filter = fmt.tprintf("%s %s", filter, c) + } + query = fmt.tprintf("%s where%s", query, filter) + } + // Unattached entries first: they are the work that has no commit yet. + query = fmt.tprintf("%s order by (r.commit_hash is null) desc, c.author_ts desc, r.id limit ?", + query) + + s, sok := stmt(&db, query) + if !sok { + return false + } + defer stmt_close(&s) + + idx := 1 + if len(session) > 0 { + stmt_bind_text(&s, idx, session) + idx += 1 + } + if len(kind) > 0 { + stmt_bind_text(&s, idx, kind) + idx += 1 + } + if len(commit) > 0 { + stmt_bind_text(&s, idx, fmt.tprintf("%s%%", commit)) + idx += 1 + } + stmt_bind_i64(&s, idx, i64(limit)) + + for { + rc := stmt_step(&s) + if rc == .Done { + break + } + if rc != .Row { + return false + } + hash := stmt_col_text(&s, 3) + label := "uncommitted" + if len(hash) > 0 { + label = short_hash(hash) + } + kind_text := stmt_col_text(&s, 1) + superseded := stmt_col_i64(&s, 5) + if superseded != 0 { + kind_text = fmt.tprintf("%s->#%d", kind_text, superseded) + } + fmt.printfln("%s #%d %s %s", + label, stmt_col_i64(&s, 0), kind_text, + one_line(stmt_col_text(&s, 2), 96)) + } + return true +} |
