GitNexus/gitnexus/src/cli
Gergő Magyar fdea46729e feat(cli): add .gitnexusrc config and --default-branch for analyze (#243) (#1996)
* feat(cli): add .gitnexusrc config and --default-branch for analyze (#243)

Let a repo preconfigure recurring `gitnexus analyze` options via a
project-local `.gitnexusrc` (JSON) plus a new `--default-branch` flag, so
projects on `develop`/`master` no longer get the generated regression
example rewritten to `base_ref: "main"` on every analyze run.

- New `cli/analyze-config.ts`: locate/parse/validate `.gitnexusrc` (flat +
  nested `analyze` form, alias mapping, fail-closed on unknown keys / bad
  types / hidden chars), merge with CLI (CLI overrides config), and resolve
  the default branch (CLI > config defaultBranch/branch > auto-detected
  origin/HEAD > "main").
- `getDefaultBranch()` in storage/git.ts (best-effort, local-only, no network).
- Thread `defaultBranch` through analyze -> run-analyze -> ai-context so the
  generated regression-compare example uses the configured branch,
  JSON-escaped; the --skills re-generation path uses the same branch.
- `skipContextFiles`/`skipAiContext` alias `skipAgentsMd` (block only, does
  not imply skipSkills); `indexOnly` stays the stronger "skip all injection".
- README + CLI help; unit tests for the config module and end-to-end wiring
  tests that fail if config is parsed but not threaded into analyze/context.

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

* fix(cli): harden .gitnexusrc against Markdown injection and stale base_ref (#243)

Addresses the tri-review findings on PR #1996.

- P1 (Markdown injection into generated AGENTS.md/CLAUDE.md): reject the
  backtick in validateBranchName (covers --default-branch, .gitnexusrc, and the
  origin/HEAD auto-detect via sanitizeDetectedBranch) and strip it at the
  ai-context sink (markdownSafeBranch); reject Markdown-significant chars
  (` * [ ] < >) in the config `name` (it lands in generated bold/code-spans),
  while still allowing `_ . - /`. Corrected the false "can't break the code
  span" comment.
- P2 (configured defaultBranch silently no-ops on an up-to-date repo): on the
  alreadyUpToDate fast path, surgically refresh only the `base_ref:` line in
  AGENTS.md/CLAUDE.md (refreshBaseRefLine), preserving the rest of the block
  incl. --skills community rows; no-op when unchanged.
- P3: gate the .gitnexusrc key lookup with Object.hasOwn so inherited keys
  (__proto__, constructor, …) hit the actionable "Unknown key" error.
- Cleanups: strip a leading UTF-8 BOM before JSON.parse; give --default-branch
  CLI validation its own `default-branch-invalid` recovery hint; drop the dead
  `options.defaultBranch` write and the now-redundant `options?.` chaining.
- Tests: backtick rejection + even-backtick generated output, 255-char branch
  bound, config `name` Markdown rejection, __proto__ → Unknown key, BOM,
  mergeAnalyzeOptions omits defaultBranch, willGenerateContext suppression, and
  the fast-path base_ref refresh.

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

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 06:48:55 +01:00
..
i18n feat(cli): add --uid/--file/--kind disambiguation flags to impact (#1907) (#1914) 2026-05-30 11:03:13 +01:00
ai-context.ts feat(cli): add .gitnexusrc config and --default-branch for analyze (#243) (#1996) 2026-06-04 06:48:55 +01:00
analyze-config.ts feat(cli): add .gitnexusrc config and --default-branch for analyze (#243) (#1996) 2026-06-04 06:48:55 +01:00
analyze.ts feat(cli): add .gitnexusrc config and --default-branch for analyze (#243) (#1996) 2026-06-04 06:48:55 +01:00
augment.ts feat(cursor): upgrade hooks to Cursor 2.4 postToolUse for Read/Grep/Shell coverage (#1467) 2026-05-10 13:29:06 +01:00
clean.ts feat(i18n): make web and CLI language-aware (#1748) 2026-05-23 06:14:24 +01:00
cli-message.ts feat(cli): add .gitnexusrc config and --default-branch for analyze (#243) (#1996) 2026-06-04 06:48:55 +01:00
detect-changes-format.ts feat(i18n): make web and CLI language-aware (#1748) 2026-05-23 06:14:24 +01:00
doctor.ts fix(embeddings): guard local ONNX runtime on macOS Intel before transformers.js import (#1987) 2026-06-03 09:46:16 +01:00
eval-server.ts feat(mcp): add limit/offset/summaryOnly pagination to impact tool (#1818) 2026-05-26 08:48:24 +01:00
format-elapsed.ts feat(progress): add per-language progress reporting to scope-resolution phase (#1813) 2026-05-25 11:53:54 +01:00
group.ts feat(core): adopt pino structured logger (#1336) 2026-05-07 20:56:25 +01:00
help-i18n.ts feat(cli): add --uid/--file/--kind disambiguation flags to impact (#1907) (#1914) 2026-05-30 11:03:13 +01:00
index-repo.ts fix(cli): keep GitNexus ignores inside .gitnexus (#1248) 2026-05-01 16:46:05 +01:00
index.ts feat(cli): add .gitnexusrc config and --default-branch for analyze (#243) (#1996) 2026-06-04 06:48:55 +01:00
lazy-action.ts fix(cli): detect missing LadybugDB native binary at startup with actionable guidance (#835) (#1837) 2026-05-26 17:10:08 +01:00
list.ts feat(i18n): make web and CLI language-aware (#1748) 2026-05-23 06:14:24 +01:00
mcp.ts feat(core): adopt pino structured logger (#1336) 2026-05-07 20:56:25 +01:00
optional-grammars.ts fix(install): materialize vendored grammars to fix Windows EPERM (#1728) (#1729) 2026-05-21 16:47:22 +01:00
publish.ts feat(cli): add gitnexus publish for opt-in understand-quickly registry (#1425) 2026-05-09 09:52:26 +01:00
remove.ts feat(i18n): make web and CLI language-aware (#1748) 2026-05-23 06:14:24 +01:00
resolve-invocation.ts fix(cli): steer docs, skills, and hooks through a CLI-neutral project-local runner (#1939) (#1945) 2026-06-02 09:00:34 +01:00
serve.ts feat(i18n): make web and CLI language-aware (#1748) 2026-05-23 06:14:24 +01:00
setup.ts fix(cli): steer docs, skills, and hooks through a CLI-neutral project-local runner (#1939) (#1945) 2026-06-02 09:00:34 +01:00
skill-gen.ts feat: configure eslint with unused import removal (#564) 2026-03-28 15:28:09 +00:00
status.ts feat(i18n): make web and CLI language-aware (#1748) 2026-05-23 06:14:24 +01:00
tool.ts feat(cli): add --uid/--file/--kind disambiguation flags to impact (#1907) (#1914) 2026-05-30 11:03:13 +01:00
wiki.ts feat(wiki): support local Claude and Codex providers (#1769) 2026-05-25 12:59:48 +01:00