Add --all flag for context and decisions commands#121
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
--allskips glob matching entirely and returns every entry from every discovered AGENTS.yaml file. It still respects--onand--whenfilters 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) andMatch(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
ResolveAllfunction vs reusingResolve: I considered makingResolvehandle the--allcase by accepting an empty path, but that would have muddied a function that currently has a clean contract (FilePath xor DirPath required). A separateResolveAllwith its own request/result types keeps both paths simple and independently testable.Duplicated fields on
AllDecisionEntryinstead of embeddingDecisionEntry: The existingDecisionEntryhasyamlstruct tags with snake_case keys. The--alloutput 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 rightjsontags. A little repetitive but avoids a custom marshaler.--alland<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:
Add ResolveAll to core engine with result types — New types in
schema.go, newResolveAllfunction inengine.gothat walks the tree withfilepath.WalkDir, parses each AGENTS.yaml, applies action/timing filters but skips glob matching, and populates source metadata. Core engine tests included.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.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
Resolves #120