Skip to content

feat(log): list and search default to the current repo's sessions (--all-repos to widen) - #329

Merged
ZacxDev merged 5 commits into
mainfrom
feat/log-repo-scope
Dec 4, 2026
Merged

ZacxDev merged 5 commits into
mainfrom
feat/log-repo-scope

Conversation

@ZacxDev

@ZacxDev ZacxDev commented Dec 4, 2026 •

Copy link
Copy Markdown
Owner

What

cairn log list and cairn log search now default to the current repository's records, across every git worktree of it, and widen only with the new --all-repos. The scope is per RECORD (operator decision on round-0 Q1): a search keeps only the hits whose own record ran in the repo. A list names the sessions with any record there.

Why: --repo picked the instance and filtered nothing, and the index kept ONE cwd per session (its first). A search from one repo therefore returned other repos' records, client content included, and printed them into the calling session's own captured transcript. Per-session scoping alone would still have answered repo B's records to repo A whenever a session launched in A and then worked in B.

Rebased onto main after #328 (log query). ⚠ log query is unscoped: its SQL reads every session of the caller. Scoping it is a separate decision and is deliberately not in this PR.

Final CLI contract

invocation (list / search) records kept stderr line (after cairn: instance=… when printed)
no scope flag, inside a git repo (or --repo P) those whose own cwd is, or lies below, any worktree git worktree list names for that repo cairn: sessions=repo:<main worktree path> worktrees=<N>
--cwd PREFIX those whose own cwd starts with PREFIX. ⚠ Behaviour change: this is per record now (it was the session's first cwd) cairn: sessions=cwd:<PREFIX>
--all-repos every record (the old behaviour) cairn: sessions=all-repos
--all-repos with --cwd none exit 2
no scope flag outside any git repo, or --repo naming a non-repo none exit 2; the message names --cwd PREFIX and --all-repos
  • A search hit line's cwd= is now the hit record's own directory.
  • A filtered list row names the session once. It shows an in-scope directory (the passing one with the earliest record; ties go to the smaller path), that directory's first human prompt, and the time span over every passing directory. It never shows the session's first cwd or prompt, which may belong to another repo. An unfiltered (--all-repos) list is unchanged.
  • Records with no cwd: a Claude Code record that names no cwd takes the last one its stream named. An opencode unit takes its session's directory. A unit with no directory at all is kept only by --all-repos.
  • --repo P sets the repo and still routes the instance. log read SESSION is unchanged. log query is unscoped.
  • Exit codes (unchanged set):
code meaning
0 served (no matches included)
2 usage: the two refusals above, and the listener's 400
3 nothing was read: unreachable, unconfigured, credential refused, the one not-found, an instance that does not serve search, or a listener too old for the repo filter (405 on the scoped POST)
5 any other answer, including a hit record or list row outside the filter
11 unrouted

Nothing is printed on stdout in the 3 and 5 cases this PR adds.

  • Unconfigured listener, measured with cmd >out 2>err; echo $?: exit 3, 0 bytes of stdout, on both the installed client and this branch. It was already the documented 3, so nothing changed there.

Mechanism

  1. Per-record cwd in the index (internal/transcript/index.go). IndexUnit.Cwd is the record's own cwd. The Claude indexer tracks the cwd in force over every record of the stream, including records at or before the cursor, so a batch that starts mid-stream still carries the directory an earlier batch saw. transcript_units.cwd stores it. Search filters u.cwd, both cwd_under (transcriptwire.CwdUnderAny / cwdUnderSQL, a path-component boundary) and cwd (a prefix), and a hit's cwd is its unit's.
  2. List without scanning units. The new transcript_session_cwds table has one row per (session, directory): the first human prompt of the main stream recorded there, plus the first and last record times there. It is a handful of rows per session. Each batch's rows are merged into it: the first prompt is kept once set, and the span only widens. A filtered list uses DISTINCT ON (root) over the passing rows with min/max window functions, and never touches transcript_units.
  3. Worktree-aware default and POST transport, unchanged. The client sends one cwd_under per outermost worktree from git worktree list --porcelain. With per-record cwd, records written inside sibling worktrees now actually show those paths. The request is POST /client/v1/log/{list,search} with a form body, because hundreds of worktrees would overflow a proxied GET request line.
  4. Round-0 D1 taken. The cwd_under echo and its missing-echo exit-3 branch are deleted. A listener older than this PR has no POST route, so it answers 405 and the client exits 3. The client still re-checks every hit and list row against the scope (exit 5), and that check is exact now that the listener filters per record.

Deploy order and the backfill (operator steps)

  1. Deploy the cairn-ui image first. On start it applies migration 5:
    • ALTER TABLE transcript_units ADD COLUMN cwd … DEFAULT '', a catalogue-only change with no table rewrite;
    • CREATE TABLE transcript_session_cwds;
    • UPDATE transcript_index_cursors SET through = 0.
  2. The reindex runs by itself, with no downtime. The indexer's startup backfill sees every cursor at 0, re-reads every stored stream, and replaces each unit's rows by key. This is the same idempotent path a crash takes, so no duplicates are written. It is rate-limited (DefaultUnitsPerSecond), like the original backfill. While a root waits, its units carry cwd = '', which no directory filter keeps. So the scoped search fails closed and answers less, never more, and --all-repos answers everything throughout. Track progress on the primary:
    SELECT count(*) FILTER (WHERE cwd = '') AS pending, count(*) AS units FROM transcript_units;
    pending should fall to the units whose records name no directory at all.
  3. Then pin the client. Before step 1, a default log list|search from the new client exits 3 (405) with nothing printed. --cwd and --all-repos are GET and keep working, but against an old listener --cwd is still session-level.

Rollback: DELETE FROM schema_migrations WHERE version = 5; lets an older build start. The column and table stay and are ignored. Re-upgrading zeroes the cursors again and re-reads everything (refuseFromTheFuture in migrate.go).

Tests: red at 5f9e69c (the previous head), green at this head

I ran the new tests against 5f9e69c's production code and its own (session-level) index test double.

test 5f9e69c head
transcript TestTheRepoScopeIsPerRecord. The session launched in /w/a and worked in /w/b-client: A's search returns only A-cwd records, B's returns only B-cwd records (including one that inherits its cwd), and a name-prefix sibling is excluded. List semantics (in-scope dir, its prompt, span) and --cwd per record are covered too. RED: A's search answered all 5 of the session's records as cwd=/w/a, and B's search missed the session entirely green
cairn-ui binary, Postgres tier: one session's two records (/work/alpha, then /work/bravo-client) POSTed through the real listener and real SQL; each directory returns only its own record; list under B shows B's prompt RED: the /work/alpha search answered the client-tree record, labelled cwd=/work/alpha green
pgstore TestTheRepoScopeIsPerRecordInSQL (search and list per record, and the merge of per-directory rows across batches) n/a (needs the new column; does not compile) green
pgstore TestMigrationFiveReindexesAVersionFourDatabaseInPlace (a v4 row gets cwd '' and cursor 0; the scoped search returns nothing while the unscoped one still answers; the re-read by key leaves one row, now in scope) n/a (no migration 5) green
transcript TestMigrationFiveReindexesInPlace (the same backfill on the indexer: no duplicates, and fail-closed beforehand) n/a green
transcript TestTheRecordCwdCarriesAcrossPassesAndTheFirstPromptStays green at 5f9e69c: an invariant guard there, since its session lives in one directory. It is the regression guard for the carry and first-prompt logic. green
client tests (worktree default, flags, refusals, 405 → 3, outside hit or row → 5) as reported before green

go test passes for ./internal/client/ ./internal/clientapi/ ./internal/transcript/... ./internal/transcriptwire/, both in a checkout and in a copy with no .git. The full Postgres tier for ./internal/pgstore/ ./cmd/cairn-ui/ passes on a throwaway unix-socket Postgres 18 (its own PID recorded and stopped). Other changes: the pgtest declaration ledger, the Guard C surface ledger (new unexported row fields, no memo text), and the route counts after #328 (11 without the query role, 12 with it).

Mutation results (Go and SQL; each restored; positive control included)

mutant killed by
unit cwd = the session's first cwd (Go indexer) TestTheRepoScopeIsPerRecord, TestMigrationFiveReindexesInPlace
no cwd carry for a record without one TestTheRepoScopeIsPerRecord (s-idx-ab#4@ with an empty cwd)
carry tracked only after the cursor TestTheRecordCwdCarriesAcrossPasses… (survived the first battery, so I added this test)
per-directory first prompt overwritten by a later one TestTheRecordCwdCarriesAcrossPasses… (survived the first battery, so I added this test)
test double filters by session cwd TestTheRepoScopeIsPerRecord, TestMigrationFive…
SQL search cwd_under on s.cwd TestTheRepoScopeIsPerRecordInSQL, TestMigrationFive…InPlace (pg), binary e2e
SQL --cwd prefix on s.cwd TestTheRepoScopeIsPerRecordInSQL
SQL list filters s.cwd, not the per-directory rows TestTheRepoScopeIsPerRecordInSQL, binary e2e
SQL list picks the latest directory TestTheRepoScopeIsPerRecordInSQL
SQL insert drops the unit cwd TestSearchAndListFilterAndPage, TestTheRepoScopeIsPerRecordInSQL, TestMigrationFive…, binary e2e
migration 5 keeps the cursors TestMigrationFive…InPlace (cursor is 7, want 0)
SQL boundary → plain string prefix TestSearchAndListFilterAndPage, TestTheRepoScopeIsPerRecordInSQL, binary e2e
client skips the outside-hit check TestALogAnswerOutsideTheRepoScopeIsNeverPrinted
RepoWorktrees keeps only the first worktree TestLogDefaultsToTheCurrentReposWorktrees
(control) scope-line text contract-format test + TestLogScopeFlags

Round 1 fixes (audit 7414863049; no 🔴 — not re-audited, each tested and mutation-checked)

Rebased onto main after #330 (5f362a4); the only conflict was CHANGELOG.md (both rows kept, this one on top).

finding fix guard (watched fail under the named mutant)
🟡1 every pass map-decoded every pre-cursor record to relearn the carried cwd the carried cwd is stored with the cursor (transcript.Cursor{Through, Cwd}, transcript_index_cursors.cwd, added to migration 5, which has not been applied outside tests), so a pass decodes only the records after its cursor: O(new records) TestAPassResumesTheCarriedCwdFromItsCursor: a pass decodes only record 2 and takes its directory from the stored cursor. Mutants: decode before the cursor skip → decoded [1 2]; ignore the cursor cwd → killed (with the carry test). pg tier: the cursor stores /work/alpha past a cwd-less record (mutant "cursor cwd not stored" killed)
🟡2 opencode per-record cwd untested TestAnOpencodeUnitIsScopedByItsSessionsDirectory (transcript), and scoped searches over the opencode and Claude sessions in the pg-tier real-index test mutant "opencode unit cwd = """ killed in both packages
🟡3 scoped search fell to the all-time step and read every match (per-unit cwd, unindexed) scopeRoots reads the scope's sessions from transcript_session_cwds, and both steps add u.root = ANY($11), so they read only those units through the (root, at) index. A scope whose passing directories all start inside the window, and which holds no untimed unit, is answered by the window step alone. A scope naming no session answers nothing without running the text search TestASmallRepoScopedSearchIsAnsweredByTheWindowStep, with the all-time step stalled: the scoped search returns its hit, not Partial, from the window step alone narrowed to its session (control: unscoped → Partial). TestAScopedAllTimeStepReadsOnlyTheScopesSessions: an inconsistent "liar" session is kept out only by the narrowing; an untimed unit forces the all-time step. Mutants killed: no root narrowing, never window-only, ignore untimed, roots not passed
🟢4 v4 DROP recipe failed on the new FK recipe now drops transcript_session_cwds first TestTheDocumentedIndexDropSucceedsAndReUpgrades runs the recipe as written, then re-upgrades

EXPLAIN ANALYZE (PG 18; 300k units in 3,000 sessions; 10 sessions in the scoped repo; a word in 60% of units), scoped all-time step:

plan time
without the session narrowing 19.7 ms (parallel seq scan, ~299k rows removed by filter)
with it 1.25 ms (bitmap index scan on (root, at), 1,000 rows, 400 removed by the cwd filter)

The per-unit cwd column needs no index. The narrowing inside the window step's session sub-select is performance only, because the outer clause already enforces it, so no test pins it.

Operator note, migration 5 (deploy step 1): it also adds transcript_index_cursors.cwd. The progress query and the rollback are unchanged. The DROP recipe now includes transcript_session_cwds.

Remaining limits

  • A removed worktree is no longer listed.
  • A unit with no cwd at all is only reachable with --all-repos.
  • The client does not re-check --cwd answers against the prefix, so --cwd against an old listener stays session-level until step 1 above.

🤖 Generated with Claude Code

ZacxDev added a commit that referenced this pull request Dec 4, 2026
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ZacxDev

ZacxDev commented Dec 4, 2026

Copy link
Copy Markdown
Owner Author

Audit round 0: requirements and deletion, PR #329 @ 5f9e69c

Verdict: requirement questioned (Q1), plus deletion candidates D1 and D2. The correctness checklist was not run, because that is round 1's job.

Ledger: round 0 · requirements: 13 (unattributed: 11, agent design choices) · deletion candidates: 2 · open premises: 1 (forcing: user)

Requirements and their authors

The brief's operator-ask block could not be read: none of the 3 commits carries a session trailer. The requirement below was relayed by the dispatching session as an operator decision, and it is paraphrased here rather than quoted.

# requirement author of record
R1 log list and log search cover the current repo's sessions by default Zach. When asked how a session-log search in one repo should be kept from pulling in other repos' (including client) content, he chose the option that puts the default in the cairn client, so every caller gets the guard
R2 --all-repos is required to widen Zach (the same choice)
R3 refuse with exit 2 outside a git repo, or when --repo is not a repo agent (fail-closed, which follows from R1)
R4 the scope is every worktree from git worktree list, not a path prefix agent ("the repos use sibling-dir worktrees")
R5 the match is at a path-component boundary, written once in Go and once in SQL agent (needed for R1 to be correct)
R6 the scoped request is a POST with a form body, served by two new routes with a body bound agent (needed for R4's size, about 31 KB against nginx's 8 KB request line)
R7 the listener echoes cwd_under, and an answer without the echo exits 3 agent
R8 the client rechecks every hit or row against the scope, and an outside one exits 5 unprinted agent
R9 a 405 on the POST exits 3 and names the flags that work around it agent
R10 a cairn: sessions=… line on stderr agent
R11 --cwd with --all-repos is a usage error agent
R12 nested worktrees are deduplicated, with a cap of 1024 per request agent
R13 log read SESSION stays unscoped agent (unchanged behaviour)

I raise no deletion candidate on the grounds that nobody asked for something. R3–R13 are design choices made in service of R1 and R2.

Q1: the scope is per SESSION, keyed on its first cwd. It is not per record.

transcript_sessions.cwd is the first cwd seen (internal/pgstore/transcriptindex.go:117-123), and both SQL filters test that column (:293-294, :454-455). So all the content from a session that was launched in repo A and then worked in repo B, including a client repo, sits inside A's default scope.

Measured on the live listener with the installed client, using --cwd for one repo's base clone and --since 2026-11-01 --limit 50. I counted lines only, so no snippet was read:

  • Positive control (the repo's own name): 50 hits in 4 sessions.
  • A term specific to one client repo: 50 hits (the cap) in 6 sessions.
  • The client org's name: 50 hits in 8 sessions.

That shows the term is present. It does not show the hits are client content, which I deliberately did not read. The structural point stands either way. The ask was about content from other repos, and the PR delivers a guard at session level. Closing the gap would mean indexing a cwd per record, which is a capture/index change that this PR's shape does not extend to.

D1: delete the cwd_under echo and its exit-3 branch

The two CwdUnder echo fields are at transcriptwire.go:151 and :197, the echo comparison is at log.go:312 in breach, and the echo tests go with them.

The case the echo guards (an older listener that ignores the filter) can no longer happen. The scoped request is POST-only, and a listener from before this PR has no POST route, so it answers 405 and R9 already exits 3. The leak half is covered without it, too: R8's per-hit check refuses any outside session that any listener prints. The only thing the echo adds is choosing between exit 3 and exit 5 for a future listener that serves the POST and drops the filter. Keep R8 and R9.

D2: simplify R4 and R6 by sending the main worktree and the current toplevel, as a GET

The premise behind R4 is that sessions live in sibling worktrees. Measured on the live index:

  • For this repo, all 38 sessions whose cwd starts with the base-clone path have the base clone itself as their cwd. None starts in a sibling worktree.
  • Across every session under /home/zach/ from 2026-11-01 to 2026-12-04 (219 sessions, with no week reaching the 200 cap), no first cwd is a sibling worktree directory. They are base clones, scratch directories or non-git agent directories.

Sessions start in the base clone and move into worktrees. Nested worktrees and subagent streams belong to the root session's cwd. With one or two paths, the request fits a GET, so the two POST routes, the body bound, the POST-with-query 400 and the deploy-order hazard can all go. If D1 is not taken, the echo would then become load-bearing.

What this costs: a session launched directly inside a sibling worktree would be missed. None appears in the sample, and the scope above is the only scope I measured.

Alternatives I considered and did not recommend:

  • A server-side git-common-dir identity, or sending one common-dir path. The server cannot map a cwd to a repo (the index stores a cwd only), so this needs new capture-time data. It is larger, not simpler. It would also fix the removed-worktree limit, but per the measurement above that limit is immaterial.
  • Filtering only on the client. This needs no server change, but --limit and top-N would be taken from every repo's hits before filtering.
  • Raising nginx's buffer instead of using POST. Every worktree path would then sit in access logs.

Not raised here

D1 — delete the cwd_under echo (transcriptwire echo fields, the breach() echo compare, the missing-echo exit-3 branch, its tests): POST-only + pre-PR listener ⇒ 405 already exits 3, and the per-hit outside-scope check already blocks any leak
D2 — replace git-worktree-list enumeration + the two POST routes/body bound with main-worktree (+ current toplevel) cwd_under over GET: measured 0 sessions whose first cwd is a sibling worktree (cairn 38/38 = base clone; 219 sessions Nov-01..Dec-04 under /home/zach)
Q1 — the default scope is per SESSION keyed on its FIRST cwd, so a session launched in repo A that then works in repo B (incl. a client repo) is fully inside A's default; is session-granular scope acceptable for the operator's ask, or must the guard be per-record (per-unit cwd in the index, a capture/index change)? · forcing: user

@ZacxDev

ZacxDev commented Dec 4, 2026

Copy link
Copy Markdown
Owner Author

Operator answer to the round-0 premise (relayed from the session where the operator was asked):

Q1=answered: scope per RECORD, not per session — index each record's own cwd and filter search/list on it (worktree-aware matching stays, since agents work inside sibling worktrees); accept that cwd is still a heuristic for content.

ZacxDev added a commit that referenced this pull request Dec 4, 2026
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ZacxDev
ZacxDev force-pushed the feat/log-repo-scope branch from 5f9e69c to 0985d29 Compare December 4, 2026 13:57
ZacxDev added a commit that referenced this pull request Dec 4, 2026
…n place

Operator decision on #329's round-0 Q1: `cwd_under` and `cwd` keep RECORDS, not
sessions. The index kept one cwd per session (its first), so a session launched
in repo A that then worked in client repo B answered B's records to A's search.

- Each indexed unit now carries its own record's cwd (`IndexUnit.Cwd`): a Claude
  Code record naming none takes the last one its stream named (tracked over the
  whole stream, so a batch starting mid-stream carries it); an opencode unit
  takes its session's directory; a unit with none matches no directory filter.
- Search filters `transcript_units.cwd`, and a hit's cwd is its unit's.
- List reads a new `transcript_session_cwds` table, one row per (session,
  directory), merged across batches: a session is listed when ANY directory
  passes, answering the earliest-first passing directory, ITS first prompt and
  the span over every passing one. No unit is scanned.
- `--cwd` is per record the same way (a prefix): a behaviour change, documented.
- Migration 5 adds the column (no rewrite) and the table and zeroes every index
  cursor, so the indexer's startup backfill re-reads every stream and replaces
  rows by key. Until a root is re-read its units carry cwd '' and the scoped
  search answers less, never more; `--all-repos` is unaffected.
- Round-0 D1: the `cwd_under` echo and its exit-3 branch are deleted. A 405 on
  the scoped POST stays exit 3, and the client's per-hit/per-row check stays
  exit 5 (exact now that the listener filters per record).
- `log query` (#328) is left unscoped (a separate decision).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ZacxDev

ZacxDev commented Dec 4, 2026

Copy link
Copy Markdown
Owner Author

Audit round 1 (read-only, head 0985d29), 0 🔴, so the ladder ends. Findings were handed to the operator. Summary: 🟡 the indexer now map-decodes every record before the cursor on every pass (index.go:727). 🟡 opencode per-unit cwd is untested: the mutant that sets it to "" survives. 🟡 the default scoped search falls to the all-time step and Partial much more often for small repos. 🟢 the v4 rollback DROP TABLE recipe (migrate.go:435) now fails on the new FK. The PR also conflicts with main in CHANGELOG.md after #330.

1. The search and list scope is per record: a hit's cwd is its own unit's, and a list row shows an in-scope directory (SQL and Go). I verified this with mutants B, B2, E, H and I, all killed.
2. A Claude record with no cwd carries the stream's last cwd, across passes (mutant A killed).
3. Migration 5 adds the column without a rewrite, adds transcript_session_cwds and zeroes the cursors, and the re-read is by key with no duplicates (mutant C killed; the pgtest tier passed on PG 18.6).
4. The client refuses to print an out-of-scope hit or row (exit 5), and a 405 on the scoped POST exits 3 (mutant D killed; I checked the 405 path in the old dispatcher).
5. Rollback is `DELETE FROM schema_migrations WHERE version=5`, and the old build tolerates the column and the table. I reasoned this from the column-naming INSERTs and the FK cascade; I did not run it.
6. An opencode unit takes its session's directory. NOT GUARDED: mutant F survives.

ZacxDev and others added 5 commits December 4, 2026 08:48
`cairn log list|search` now print only sessions whose cwd is, or lies below,
a worktree of the git repository --repo names (default: the working
directory). `--cwd PREFIX` replaces that default, `--all-repos` removes it,
the two together are exit 2, and outside a git repo with neither the verb
refuses (exit 2) instead of searching everything. stderr names what was
covered: `cairn: sessions=repo:<main worktree> worktrees=<N>`,
`sessions=cwd:<PREFIX>` or `sessions=all-repos`. `log read` is unchanged.

Why: `--repo` picked the instance and filtered nothing, so a search from one
repo printed other repos' transcript content into the calling session's own
(captured) transcript.

Mechanism: the stored records carry `cwd` and `gitBranch` and nothing that
identifies a repository, so the client resolves the set itself with
`git worktree list --porcelain` and sends one `cwd_under` per outermost
worktree. The listener keeps a session whose cwd IS one of them or lies
below one (transcriptwire.CwdUnderAny, at a path-component boundary; the
same rule in pgstore SQL, pinned by the Postgres tier) and echoes the set.
A plain prefix cannot work: worktrees are sibling directories, and the
prefix that names them also names unrelated `<repo>-*` repos.

The scoped request is a POST with a form body (new rows in the client
listener's route ledger): one path per worktree is tens of KiB on a repo
with hundreds of worktrees, past a proxied GET request line. Fail closed
against an older listener: a 405 on the POST, or an answer without the
`cwd_under` echo, is exit 3 with nothing printed; an echoed answer naming a
session outside the set is exit 5, nothing printed.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The ledger-class probe ran `log search` with no scope flag, which outside a
git checkout (the nix sandbox, the mutant copies) is now the exit-2 refusal;
it passes --all-repos, since it measures the ledger class, not the scope.
The binary's Postgres-tier test counts the listener's 11 routes and drives
a POSTed cwd_under search through the real listener and SQL.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…n place

Operator decision on #329's round-0 Q1: `cwd_under` and `cwd` keep RECORDS, not
sessions. The index kept one cwd per session (its first), so a session launched
in repo A that then worked in client repo B answered B's records to A's search.

- Each indexed unit now carries its own record's cwd (`IndexUnit.Cwd`): a Claude
  Code record naming none takes the last one its stream named (tracked over the
  whole stream, so a batch starting mid-stream carries it); an opencode unit
  takes its session's directory; a unit with none matches no directory filter.
- Search filters `transcript_units.cwd`, and a hit's cwd is its unit's.
- List reads a new `transcript_session_cwds` table, one row per (session,
  directory), merged across batches: a session is listed when ANY directory
  passes, answering the earliest-first passing directory, ITS first prompt and
  the span over every passing one. No unit is scanned.
- `--cwd` is per record the same way (a prefix): a behaviour change, documented.
- Migration 5 adds the column (no rewrite) and the table and zeroes every index
  cursor, so the indexer's startup backfill re-reads every stream and replaces
  rows by key. Until a root is re-read its units carry cwd '' and the scoped
  search answers less, never more; `--all-repos` is unaffected.
- Round-0 D1: the `cwd_under` echo and its exit-3 branch are deleted. A 405 on
  the scoped POST stays exit 3, and the client's per-hit/per-row check stays
  exit 5 (exact now that the listener filters per record).
- `log query` (#328) is left unscoped (a separate decision).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…d search to its sessions

- 🟡1 The carried cwd is stored WITH each stream's cursor (`Cursor.Cwd`,
  `transcript_index_cursors.cwd`, added to the still-unreleased migration 5),
  so a pass decodes only the records after its cursor instead of map-decoding
  every earlier record to relearn the directory.
- 🟡2 Opencode per-record cwd is tested (transcript + Postgres tier): the
  mutant that blanks it now dies.
- 🟡3 A scoped search first names its sessions from transcript_session_cwds
  (`scopeRoots`) and both steps read only their units through the (root, at)
  index; a scope whose records all lie in the window (no untimed unit) is
  answered by the window step alone, never Partial. EXPLAIN ANALYZE on a
  300k-unit fixture: the scoped all-time step went 19.7 ms (parallel seq scan,
  ~300k rows removed by filter) -> 1.25 ms (bitmap on (root, at)); no index on
  the per-unit cwd is needed.
- 🟢4 The documented index DROP recipe includes transcript_session_cwds, and a
  Postgres-tier test runs it as written.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ZacxDev
ZacxDev force-pushed the feat/log-repo-scope branch from 0985d29 to f9fc141 Compare December 4, 2026 15:04
@ZacxDev
ZacxDev marked this pull request as ready for review December 4, 2026 15:18
@ZacxDev
ZacxDev merged commit e72afdf into main Dec 4, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant