Skip to content

read: implement context model, resolver, and per-source readers - #168

Open
anish749 wants to merge 7 commits into
mainfrom
read-protocol-context-and-readers
Open

read: implement context model, resolver, and per-source readers#168
anish749 wants to merge 7 commits into
mainfrom
read-protocol-context-and-readers

Conversation

@anish749

Copy link
Copy Markdown
Owner

Problem

The read protocol defines a unified selection model for reading data across all sources, but pigeon's read command currently requires explicit platform/account/contact flags with no workspace-scoping concept.

Solution

Implements the context and reader layers from the read protocol:

  • Context model (config/context.go): Contexts in config.yaml map platform keys to account identifiers, with string-or-array YAML support
  • Context resolver (pctx/): Resolution chain (flag → env → default → infer), source-to-platform mapping, account matching per platform
  • Per-source readers (reader/): Gmail, Calendar, Drive, Slack, WhatsApp, Linear — each with dedup, filtering, and sorting per protocol spec
  • Unified CLI (cli/read.go): pigeon read <source> [selector] [flags] replaces the old --platform --account --contact surface
  • Context-aware pigeon list --context= support

@anish749
anish749 force-pushed the read-protocol-context-and-readers branch 2 times, most recently from 007b07e to b31bcaf Compare April 11, 2026 21:53
Adds the read protocol foundation: context-based account resolution,
per-source read algorithms, and a unified CLI surface.
- Propagate errors from store.ReadMeta instead of _ assignment
- Propagate errors from readDriveComments instead of silent fallback
- Collect parse errors in loops (gmail, calendar, drive, linear) using
  errors.Join pattern instead of log-then-swallow
- Propagate loadPendingDeletes and scanner errors
- Propagate cobra flag parse errors in CLI layer
- Revert unintended reordering of LinearConfig in config.go — only
  change is the two new fields (Contexts, DefaultContext)
Delete internal/reader/ entirely — it duplicated types, parsing, dedup,
and formatting that already exist in modelv1, compact, and store.

The read command is now thin dispatch:
- Context resolution picks accounts (pctx.ResolveContextName + Resolve)
- Source dispatch picks directories (paths type chain)
- store.ReadLines + compact.DedupGWS handle JSONL reading and dedup
- GWS sources output raw JSON lines (no custom formatters)
- Messaging sources use existing store.ReadConversation + modelv1.FormatDateFile
- Drive sources cat markdown/CSV content + raw comment JSONL

Also:
- ContextName is now a typed string, resolved once at CLI boundary
- pctx.Resolve no longer reads env vars — receives ContextName from caller
- Revert daemon.go identity context to original "default"
@anish749
anish749 force-pushed the read-protocol-context-and-readers branch from d18d073 to e4edb6b Compare April 12, 2026 19:28
Use read.Glob (rg-backed) for --since and all-files cases instead of
hand-rolled listDateFilesInDir + selectDateFiles. For --date, construct
the path directly — no listing needed.

Removes listDateFilesInDir, selectDateFiles, and filterLinesByTime
(which also had a double-append bug).
Move ReadGWSLines, ReadDriveContent, ReadMessaging, ReadLinearIssue,
and fuzzy matchers from cli/read.go to commands/read.go — following
the existing pattern where cli/ is thin flag parsing and commands/
has testable business logic.

Add 17 tests covering:
- Gmail dedup, sort, last-N, default-last, empty dir
- Calendar via the same GWS path
- Messaging fuzzy match (exact, single, ambiguous, none)
- Drive content + comments, no match
- Linear issue dedup, fuzzy match, not found
- filterCancelled no-op for non-events

cli/read.go is now pure dispatch: parse flags → resolve context →
call commands → print output.
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