Skip to content

Add --all flag for context and decisions commands#121

Merged
gregology merged 3 commits intomainfrom
all-flag-context-decisions
Apr 8, 2026
Merged

Add --all flag for context and decisions commands#121
gregology merged 3 commits intomainfrom
all-flag-context-decisions

Conversation

@gregology
Copy link
Copy Markdown
Contributor

@gregology gregology bot commented Apr 8, 2026

Closes #120

Why

If you want to see every decision in a project right now, you have to pass a path and hope the globs line up. There's no way to just dump everything. This is a problem for agents doing planning — they need to see all architectural decisions so they don't propose something that was already evaluated and rejected.

--all skips glob matching entirely and returns every entry from every discovered AGENTS.yaml file. It still respects --on and --when filters for context.

Output includes source metadata

When you query a specific file, you already know where the entry applies. But when dumping everything, you need to know which AGENTS.yaml file each entry came from and what globs it targets. Both text and JSON output include SourceFile (relative path to the AGENTS.yaml) and Match (the entry's glob patterns) when using --all. This metadata is intentionally omitted from normal path-based queries where it would just be noise.

Design choices

Separate ResolveAll function vs reusing Resolve: I considered making Resolve handle the --all case by accepting an empty path, but that would have muddied a function that currently has a clean contract (FilePath xor DirPath required). A separate ResolveAll with its own request/result types keeps both paths simple and independently testable.

Duplicated fields on AllDecisionEntry instead of embedding DecisionEntry: The existing DecisionEntry has yaml struct tags with snake_case keys. The --all output needs capitalized JSON keys (Decision, Match, SourceFile) to match the issue's spec. Embedding would inherit the wrong tags, so the fields are duplicated with the right json tags. A little repetitive but avoids a custom marshaler.

--all and <path> are mutually exclusive: The issue suggested this and it makes sense — combining them would be confusing. You either want everything or you want what matches a specific path.

Review walkthrough

Each commit maps to one step of the decomposed implementation:

  1. Add ResolveAll to core engine with result types — New types in schema.go, new ResolveAll function in engine.go that walks the tree with filepath.WalkDir, parses each AGENTS.yaml, applies action/timing filters but skips glob matching, and populates source metadata. Core engine tests included.

  2. Wire --all flag into CLI commands with output formatting and tests — Flag parsing in cmdContext/cmdDecisions, mutual exclusivity validation, text and JSON formatting for the new output types. CLI integration tests cover both commands in both output modes, filter interaction, and the mutual exclusivity error.

  3. Update documentation — CLI reference and README updated to document --all.

Developer metrics

Total duration: 15m 44s
Turns: 206
Tool calls: 141
Tokens: 4,176,352 input / 38,263 output

Stage Model Duration Turns Tool calls Tokens (in/out) Cache read Cache creation
triage claude-opus-4-6 2m 33s 35 30 141,174 / 2,859 103,042 38,122
decompose claude-opus-4-6 1m 31s 12 12 124,150 / 2,396 80,482 43,664
implement_step_1 claude-opus-4-6 4m 36s 72 40 1,554,732 / 14,753 1,498,409 56,239
implement_step_2 claude-opus-4-6 4m 21s 51 28 1,378,519 / 14,300 1,323,539 54,913
docs_review claude-opus-4-6 1m 1s 14 11 354,880 / 2,428 287,296 67,572
craft_pr claude-opus-4-6 1m 39s 22 20 622,897 / 1,527 541,114 81,770

Resolves #120

gregology bot added 3 commits April 8, 2026 12:11
Add new types and a `ResolveAll` function to the core package that walks the directory tree, discovers all AGENTS.yaml files, and returns every context/decision entry without glob filtering.

**`internal/core/schema.go`:**
- Add `ResolveAllRequest` struct: `Root string`, `Action Action`, `Timing Timing`
- Add `ResolveAllResult` struct: `ContextEntries []AllContextEntry`, `DecisionEntries []AllDecisionEntry`
- Add `AllContextEntry` struct: `Content string` (json:"Content"), `Match []string` (json:"Match"), `SourceFile string` (json:"SourceFile")
- Add `AllDecisionEntry` struct: all fields from `DecisionEntry` (Decision, Rationale, Alternatives, RevisitWhen, Date) plus `Match []string` (json:"Match"), `SourceFile string` (json:"SourceFile"). Do NOT embed DecisionEntry — duplicate the fields so JSON tags can be customized (capitalized keys to match the issue's example output).

**`internal/core/engine.go`:**
- Add `ResolveAll(req ResolveAllRequest) (*ResolveAllResult, []string, error)` that:
  1. Defaults `Root` to `os.Getwd()` if empty
  2. Walks the tree from Root using `filepath.WalkDir`, collecting directories that contain AGENTS.yaml or AGENTS.yml
  3. For each found file: reads, parses YAML into `ContextFile`, calls `applyDefaults`
  4. For context entries: filters by `Action` and `Timing` (reuse `matchesAction` and timing logic from `filterContext`), but skips glob matching. Builds `AllContextEntry` with `SourceFile` set to the AGENTS.yaml path relative to Root, and `Match` from the entry.
  5. For decision entries: no filtering, just collects all. Builds `AllDecisionEntry` with same `SourceFile` and `Match` population.
  6. Returns warnings for parse failures (same pattern as `discoverAndParse`)

**`internal/core/engine_test.go`:**
- Add `TestResolveAll_CollectsAllEntries`: create a temp dir with AGENTS.yaml files at root and a subdirectory, each with context and decision entries scoped to specific globs. Call `ResolveAll` and verify ALL entries are returned regardless of glob patterns.
- Add `TestResolveAll_FiltersActionAndTiming`: verify that Action/Timing filtering still works (e.g., requesting ActionEdit filters out read-only entries).
- Add `TestResolveAll_PopulatesSourceFileAndMatch`: verify SourceFile is the relative path to the AGENTS.yaml file and Match contains the entry's glob patterns.
- Add `TestResolveAll_WarnsOnParseFailure`: verify malformed YAML produces a warning but doesn't stop processing.
…d tests

Add `--all` flag support to `cmdContext` and `cmdDecisions` in `cmd/sctx/main.go`, with appropriate output formatting and integration tests.

**`cmd/sctx/main.go`:**
- Add `errAllAndPath` sentinel: `errors.New("--all and <path> are mutually exclusive")`
- Update `usage` string to show `--all` option for both commands:
  - `sctx context [<path>] [--all] [--on <action>] [--when <timing>] [--json]`
  - `sctx decisions [<path>] [--all] [--json]`
- Update `cmdContext`:
  - Scan args for `--all` flag before extracting positional path
  - If `--all` and a positional path are both present, return `errAllAndPath`
  - If `--all`: call `core.ResolveAll()` with action/timing, format output
  - Text format: `"  - <Content>\n    Match: <Match patterns>\n    (from <SourceFile>)\n"`
  - JSON format: encode `[]AllContextEntry` directly
  - If no `--all` and no path: return `errMissingPath` (existing behavior preserved)
- Update `cmdDecisions` similarly:
  - Text format: existing decision format plus `"    Match: <patterns>\n    (from <SourceFile>)\n"`
  - JSON format: encode `[]AllDecisionEntry` directly

**`cmd/sctx/main_test.go`:**
- Add `TestCmdContext_All`: create temp dir with multiple AGENTS.yaml files, run cmdContext with `--all`, verify all entries returned with SourceFile and Match in output
- Add `TestCmdContext_AllJson`: same but with `--json`, verify JSON contains SourceFile and Match fields
- Add `TestCmdContext_AllWithPath`: verify `--all` and a path returns `errAllAndPath`
- Add `TestCmdContext_AllWithFilters`: verify `--on` and `--when` work with `--all`
- Add `TestCmdDecisions_All`: same pattern for decisions
- Add `TestCmdDecisions_AllJson`: JSON output test
- Add `TestCmdDecisions_AllWithPath`: mutual exclusivity test
@gregology gregology merged commit 15d12de into main Apr 8, 2026
2 checks passed
@gregology gregology deleted the all-flag-context-decisions branch April 8, 2026 16:36
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.

Feature request: --all flag for decisions and context commands

1 participant