You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 1058aa5
Browse filesBrowse the repository at this point in the historyBrowse files
feat(check): add --base flag for cross-file rule parity between local and CI (#339)
* feat(check): add --base flag for cross-file rule parity between local and CI
`ctx.changedFiles` was empty by default, making cross-file dependency
rules (e.g., "if config.yml changed, manifest.yml must also change")
silently pass locally. These rules only worked in CI via a non-obvious
`git reset --soft` workaround.
Now `archgate check` auto-detects the base branch and populates
`changedFiles` with the branch diff (`git diff <base>...HEAD`). The
resolution priority is: `--staged` flag (skips base) → `--base <ref>`
flag → `.archgate/config.json` `baseBranch` → git auto-detect → empty.
Changes:
- Add `detectBaseRef()` and `getFilesChangedSinceRef()` to git-files.ts
- Add `--base [ref]` flag to `check` and `review-context` commands
- Extend `ProjectConfigSchema` with optional `baseBranch` field
- Extend `runChecks` and `buildReviewContext` options with `base`
- Add `used_base` to check telemetry event
- Add unit tests for new git helpers and integration tests for --base
- Document Bun.env parallel test leakage pattern in agent memory
Closes#338
Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
* refactor: extract resolveBaseRef helper and add review-context --base tests
Extract duplicated base resolution logic from check.ts and
review-context.ts into a shared resolveBaseRef() function in
git-files.ts. Add integration tests for review-context --base
to close the coverage gap.
Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
* docs: document --base flag and changedFiles auto-detection
Update CLI reference, rule API, concepts, writing-rules guide, and
CI integration guide to document the new --base flag and automatic
base branch detection for changedFiles. Includes both English and
Portuguese (pt-br) translations.
Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
* docs: regenerate llms-full.txt
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
---------
Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy file name to clipboardExpand all lines: .claude/agent-memory/archgate-developer/MEMORY.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -56,6 +56,7 @@ Skipping steps 2 or 3 is a workflow violation. The user should NEVER have to inv
56
56
-**GitHub CodeQL "default setup" can silently skip PRs — use an explicit workflow** — The repository-level "default setup" for CodeQL does not guarantee analysis on every PR. PR #279 (Renovate deps update) had zero CodeQL analyses, dropping the Scorecard SAST score from 10 to 9. Fix: add an explicit `.github/workflows/codeql.yml` that runs on `push: [main]`, `pull_request: [main]`, and a weekly schedule. After merging, disable the "default setup" in repository Settings > Code security > Code scanning to avoid duplicate analyses. The explicit workflow gives Scorecard a detectable `github/codeql-action` reference and guarantees coverage.
57
57
- **`GITHUB_TOKEN`-authored pushes do NOT trigger downstream workflows — release.yml MUST use the GH App token** — When an Actions workflow pushes commits or opens PRs using `${{ github.token }}` / `secrets.GITHUB_TOKEN`, GitHub intentionally suppresses the resulting `push` / `pull_request` events to prevent recursion. Symptom on release PRs: the head SHA has no `pull_request`-event check runs, so `Validate Code` / `Lint, Test & Check` / `DCO Sign-off Check` are missing from the PR rollup and branch protection treats the PR as missing required checks. PR [#131](https://github.com/archgate/cli/pull/131) papered over this by manually `gh workflow run` + posting commit statuses, but `workflow_dispatch` runs land on `head_branch: release` with `pull_requests: []` — they are not associated with the PR ref, so `Lint, Test & Check` stayed orphaned and the bug recurred on PR [#251](https://github.com/archgate/cli/pull/251). Root-cause fix: in `release.yml` the `pull-request` job MUST generate a GitHub App installation token via `actions/create-github-app-token` (using `secrets.GH_APP_APP_ID` / `secrets.GH_APP_PRIVATE_KEY`) and pass it to BOTH `actions/checkout` and `simple-release-action`. App-token-authored pushes DO trigger `pull_request` events naturally. Apply the same pattern to any future workflow that pushes to a branch whose downstream CI must run.
58
58
59
+
-**`Bun.env` modifications in parallel test files leak into integration test subprocesses** — Bun test runner runs all test files in a single process sharing `Bun.env`. Tests that set `Bun.env.HOME`, `Bun.env.GIT_CONFIG_NOSYSTEM`, or `Bun.env.GIT_CONFIG_GLOBAL` (e.g., `auth.test.ts`, `credential-store.test.ts`) modify the shared environment. Integration tests that spawn CLI subprocesses via `runCli()` spread `process.env` (which IS `Bun.env`) into the child, inheriting the leaked values. Symptom: git operations in the subprocess fail with "not a git repo" or similar, but the test passes in isolation. Fix: integration tests that rely on git must explicitly reset git-related env vars in the `runCli` call: `runCli(args, dir, { GIT_CONFIG_NOSYSTEM: "", GIT_CONFIG_GLOBAL: "" })`. Applied in `tests/integration/check.test.ts` for the `--base` tests.
59
60
-**Cross-command I/O sharing: export from the existing command file, don't create shared files** — When two commands need to share I/O functions (console.log with styleText), you CANNOT put them in `src/helpers/` (ARCH-002 forbids console.log in helpers) or create a new file under `src/commands/<parent>/` without a register function (ARCH-001 requires register\*Command export, ARCH-016 requires docs heading). The correct pattern: export the shared functions from the command file that already defines them (e.g., `plugin/install.ts` exports `installForEditor()` and `printManualInstructions()`) and import them in the other command. Applied in `upgrade.ts` importing from `./plugin/install`.
| `ctx.projectRoot` | `string` | Absolute path to the project root directory |
795
+
| `ctx.scopedFiles` | `string[]` | Files matching the ADR's `files` globs, or all project files if no globs are set |
796
+
| `ctx.changedFiles` | `string[]` | Files changed in git (auto-detected from branch diff, or from `--staged`/`--base`) |
797
797
798
798
### File Operations
799
799
@@ -897,7 +897,7 @@ Rules execute with the following guarantees:
897
897
- **Parallel across ADRs** -- Rules from different ADRs run concurrently for faster execution.
898
898
- **Sequential within an ADR** -- Rules belonging to the same ADR run one after another, so earlier rules can establish context for later ones.
899
899
- **Scoped files are pre-resolved** -- The `ctx.scopedFiles` array is populated before your `check` function is called, based on the ADR's `files` globs.
900
-
- **Changed files for staged mode** -- When running `archgate check --staged`, `ctx.changedFiles` contains only the files staged in git, letting rules skip unchanged files for faster feedback.
900
+
- **Changed files auto-detected** -- `ctx.changedFiles` is automatically populated with the branch diff against the base branch (e.g., `main`). Use `--staged` for pre-commit hooks (staged files only) or `--base <ref>` for an explicit base. This enables cross-file dependency rules to work locally, not just in CI.
901
901
902
902
The editor plugins for [Claude Code](/guides/claude-code-plugin/) and [Cursor](/guides/cursor-integration/) run `archgate check` automatically after every code change. The agent reads the applicable ADRs, writes compliant code, and validates -- no manual check commands needed. [Sign up for beta access](https://plugins.archgate.dev).
903
903
@@ -1045,6 +1045,16 @@ Warnings (severity `warning`) are logged but do not affect the exit code. Only `
1045
1045
1046
1046
## Narrowing scope
1047
1047
1048
+
### Check files changed in the PR
1049
+
1050
+
Use `--base` to compare against the PR's base branch. This gives cross-file dependency rules the full picture of what changed:
Without `--base`, the base branch is auto-detected from `origin/HEAD`. The explicit form is recommended in CI for deterministic behavior.
1057
+
1048
1058
### Check only staged files
1049
1059
1050
1060
Use `--staged` to limit checking to git-staged files. This is useful in pre-commit hooks or when you only want to validate what is about to be committed:
@@ -2721,14 +2731,22 @@ Use `ctx.scopedFiles` when your rule should only apply to files the ADR governs.
2721
2731
2722
2732
### ctx.changedFiles
2723
2733
2724
-
An array of file paths that have been modified (git staged or changed). Useful for incremental checking -- only validate files that were actually touched.
2734
+
An array of file paths that differ from the base branch. Auto-detected by default, or populated from `--staged` / `--base <ref>`. Useful for incremental checking and cross-file dependency rules.
2725
2735
2726
2736
```typescript
2737
+
// Incremental checking -- only validate changed files
// Cross-file dependency -- if file A changed, file B must also change
2743
+
if (ctx.changedFiles.includes("config/database.yml")) {
2744
+
if (!ctx.changedFiles.includes("deploy/manifest.yml")) {
2745
+
ctx.report.violation({
2746
+
message: "config changed but manifest was not bumped",
2747
+
file: "config/database.yml",
2748
+
});
2749
+
}
2732
2750
}
2733
2751
```
2734
2752
@@ -2899,7 +2917,7 @@ ARCH-006/no-unapproved-deps
2899
2917
}
2900
2918
```
2901
2919
2902
-
2. **Use `ctx.changedFiles` for incremental checking.** When running `archgate check --staged`, `ctx.changedFiles` contains only the git-staged files. Filter `ctx.scopedFiles` against it to check only what changed.
2920
+
2. **Use `ctx.changedFiles` for incremental checking.** `ctx.changedFiles` is auto-populated with the branch diff (or staged files with `--staged`). Filter `ctx.scopedFiles` against it to check only what changed, or use it directly for cross-file dependency rules.
2903
2921
2904
2922
3. **Keep rules focused on one concern.** A rule that checks both naming conventions and import patterns should be split into two rules with separate IDs.
2905
2923
@@ -3571,13 +3589,14 @@ Loads every ADR with `rules: true` in its frontmatter, executes the companion `.
| `--staged` | Only check git-staged files (useful for pre-commit hooks) |
3595
+
| `--base [ref]` | Compare changed files against a base ref (auto-detects when omitted) |
3596
+
| `--json` | Machine-readable JSON output |
3597
+
| `--ci` | GitHub Actions annotation format |
3598
+
| `--adr <id>` | Only check rules from a specific ADR |
3599
+
| `--verbose` | Show passing rules and timing info |
3581
3600
3582
3601
## Arguments
3583
3602
@@ -3607,6 +3626,12 @@ Check only staged files before committing:
3607
3626
archgate check --staged
3608
3627
```
3609
3628
3629
+
Check all files changed on the current branch vs `main`:
3630
+
3631
+
```bash
3632
+
archgate check --base main
3633
+
```
3634
+
3610
3635
Check a single ADR:
3611
3636
3612
3637
```bash
@@ -3637,6 +3662,26 @@ Get GitHub Actions annotations:
3637
3662
archgate check --ci
3638
3663
```
3639
3664
3665
+
## Changed files detection
3666
+
3667
+
By default, `archgate check` auto-detects the base branch and populates `ctx.changedFiles` with the branch diff (`git diff <base>...HEAD`). This enables cross-file dependency rules to work locally -- not just in CI.
3668
+
3669
+
The base ref is resolved in priority order:
3670
+
3671
+
| Priority | Source | `changedFiles` populated with |
Auto-detection tries `origin/HEAD`, then `origin/main`, `origin/master`, local `main`, and local `master`. To set a project default, add `baseBranch` to `.archgate/config.json`:
3680
+
3681
+
```json
3682
+
{ "baseBranch": "main" }
3683
+
```
3684
+
3640
3685
## Diagnostics
3641
3686
3642
3687
During execution, `archgate check` emits warnings for common misconfigurations that may cause slow or unexpected results:
| `--base [ref]` | Compare changed files against a base ref (auto-detects when omitted) |
4160
+
| `--run-checks` | Include ADR compliance check results |
4161
+
| `--domain <domain>` | Filter to a single domain |
4116
4162
4117
4163
## Example
4118
4164
@@ -4624,7 +4670,7 @@ Files matching the ADR's `files` glob patterns from its frontmatter. If the ADR
4624
4670
changedFiles: string[];
4625
4671
```
4626
4672
4627
-
Files that have been modified according to git. When `--staged` is used, this contains only staged files. When running without `--staged`, this contains all changed files (staged and unstaged). Empty when no git changes are detected.
4673
+
Files that have been modified according to git. By default, this is auto-populated with the branch diff against the detected base branch (e.g., `origin/main`). When `--staged` is used, this contains only staged files. When `--base <ref>` is used, this contains all files changed since that ref. Empty when base detection fails or no changes are found. Use this to build cross-file dependency rules (e.g., "if file A changed, file B must also change").
|`ctx.projectRoot`|`string`| Absolute path to the project root directory |
61
+
|`ctx.scopedFiles`|`string[]`| Files matching the ADR's `files` globs, or all project files if no globs are set |
62
+
|`ctx.changedFiles`|`string[]`| Files changed in git (auto-detected from branch diff, or from `--staged`/`--base`)|
63
63
64
64
### File Operations
65
65
@@ -163,7 +163,7 @@ Rules execute with the following guarantees:
163
163
-**Parallel across ADRs** -- Rules from different ADRs run concurrently for faster execution.
164
164
-**Sequential within an ADR** -- Rules belonging to the same ADR run one after another, so earlier rules can establish context for later ones.
165
165
-**Scoped files are pre-resolved** -- The `ctx.scopedFiles` array is populated before your `check` function is called, based on the ADR's `files` globs.
166
-
-**Changed files for staged mode** -- When running `archgate check --staged`, `ctx.changedFiles` contains only the files staged in git, letting rules skip unchanged files for faster feedback.
166
+
-**Changed files auto-detected** -- `ctx.changedFiles` is automatically populated with the branch diff against the base branch (e.g., `main`). Use `--staged` for pre-commit hooks (staged files only) or `--base <ref>` for an explicit base. This enables cross-file dependency rules to work locally, not just in CI.
167
167
168
168
:::tip[Run checks automatically with editor plugins]
169
169
The editor plugins for [Claude Code](/guides/claude-code-plugin/) and [Cursor](/guides/cursor-integration/) run `archgate check` automatically after every code change. The agent reads the applicable ADRs, writes compliant code, and validates -- no manual check commands needed. [Sign up for beta access](https://plugins.archgate.dev).
Without `--base`, the base branch is auto-detected from `origin/HEAD`. The explicit form is recommended in CI for deterministic behavior.
154
+
145
155
### Check only staged files
146
156
147
157
Use `--staged` to limit checking to git-staged files. This is useful in pre-commit hooks or when you only want to validate what is about to be committed:
Copy file name to clipboardExpand all lines: docs/src/content/docs/guides/writing-rules.mdx
+12-4Lines changed: 12 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -99,14 +99,22 @@ Use `ctx.scopedFiles` when your rule should only apply to files the ADR governs.
99
99
100
100
### ctx.changedFiles
101
101
102
-
An array of file paths that have been modified (git staged or changed). Useful for incremental checking -- only validate files that were actually touched.
102
+
An array of file paths that differ from the base branch. Auto-detected by default, or populated from `--staged` / `--base <ref>`. Useful for incremental checking and cross-file dependency rules.
103
103
104
104
```typescript
105
+
// Incremental checking -- only validate changed files
105
106
const filesToCheck =ctx.scopedFiles.filter((f) =>
106
107
ctx.changedFiles.includes(f)
107
108
);
108
-
for (const file offilesToCheck) {
109
-
// Only check changed files
109
+
110
+
// Cross-file dependency -- if file A changed, file B must also change
111
+
if (ctx.changedFiles.includes("config/database.yml")) {
112
+
if (!ctx.changedFiles.includes("deploy/manifest.yml")) {
113
+
ctx.report.violation({
114
+
message: "config changed but manifest was not bumped",
115
+
file: "config/database.yml",
116
+
});
117
+
}
110
118
}
111
119
```
112
120
@@ -277,7 +285,7 @@ ARCH-006/no-unapproved-deps
277
285
}
278
286
```
279
287
280
-
2.**Use `ctx.changedFiles` for incremental checking.**When running `archgate check --staged`, `ctx.changedFiles`contains only the git-staged files. Filter `ctx.scopedFiles` against it to check only what changed.
288
+
2.**Use `ctx.changedFiles` for incremental checking.**`ctx.changedFiles`is auto-populated with the branch diff (or staged files with `--staged`). Filter `ctx.scopedFiles` against it to check only what changed, or use it directly for cross-file dependency rules.
281
289
282
290
3.**Keep rules focused on one concern.** A rule that checks both naming conventions and import patterns should be split into two rules with separate IDs.
0 commit comments