Commit graph

23 commits

Author SHA1 Message Date
Julian Knutsen
b2b153b7b8
fix(update): exit nonzero when a multi-ID update partially fails (#4726)
* fix(update): exit nonzero when a multi-ID update partially fails

bd update applies updates per issue ID, but the exit code only went
nonzero when every ID failed (len(args) > 0 && firstUpdatedID == "").
A single successful ID reset the whole batch to exit 0, so a bogus or
unresolvable ID mid-batch was silently swallowed and callers (scripts,
orchestrators) could not detect a partial batch. The GH audit flagged
this: per-ID errors were printed inline on stderr, but the process
reported success.

Empirical baseline-vs-patched evidence (red-team scenarios S1-S7):
baseline `bd update good1 bogus good2 --priority 1` exits rc=0 with one
inline stderr line; patched exits rc=1 with "1 of 3 issues failed to
update" plus a per-ID report. In --json mode the last stderr line is
now a machine-parseable failure report ({error, failed[], schema_version},
envelope-aware) while stdout keeps the array-of-updated-issues success
shape (parsed_list_len=2, both good IDs applied - the command stays
per-ID, not atomic). All-good paths are unchanged: rc=0 and stderr
byte-identical to baseline in both text and JSON modes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* docs: auto-regenerate CLI reference

Applied from the cli-docs-freshness-patch artifact of https://github.com/gastownhall/beads/actions/runs/29144979580
(generated with CI's canonical pinned build). See
scripts/check-cli-docs-drift.sh for how drift is attributed.

* docs: auto-regenerate CLI reference

Applied from the cli-docs-freshness-patch artifact of https://github.com/gastownhall/beads/actions/runs/29521598853
(generated with CI's canonical pinned build). See
scripts/check-cli-docs-drift.sh for how drift is attributed.

* fix(update): per-ID failure handling + output parity for multi-ID batches

Maintainer review fixup for PR #4726.

`bd update` over multiple IDs is per-ID, not atomic: every failed ID must
be reported and the command must exit nonzero while the other IDs still
update. Several paths still short-circuited that contract; this fixup
brings them all in line with the documented behavior.

Direct-mode metadata failures are now per-ID (review finding: major /
correctness). A `--metadata` merge or `--set-metadata`/`--unset-metadata`
edit that failed for one ID (e.g. that issue's stored metadata is not a
JSON object) used to return immediately -- aborting the batch, skipping
later IDs, and in --json mode writing the error to stdout instead of the
stderr failure report. It now prints the per-ID error, records the failed
ID, closes the unmutated result, and continues, exactly like the
resolve/update/label/parent paths. Added text and --json coverage with a
middle ID whose existing metadata is non-object for both the merge and the
edit paths.

Proxied-server exit-code parity (review finding: major / correctness). The
proxied path used to exit 0 whenever another ID in the batch succeeded,
hiding generic per-ID failures from exit-code automation.
runUpdateProxiedServer now accumulates every failed ID -- generic per-ID
errors and lost --claim races alike -- and returns the shared
reportUpdateFailures() after emitting successful output, so the batch
exits nonzero with the same stderr failure report (text and --json) as the
non-proxied path.

Proxied output-mode consistency (review finding: minor / maintainability).
Proxied success output now keys off the same global JSON decision (--json
OR --format json OR config) that reportUpdateFailures uses, so success
output and the failure report can no longer disagree on format within one
invocation.

Also fold the non-proxied reparent old-parent RemoveDependency failure
into the failed-ID ledger (review finding: minor / correctness): a failed
removal no longer proceeds to add the new parent edge on top of a stale
one, and no longer counts the ID as a silent success.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Test User <test@test.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Eddie the Engineer <adopt-pr@gascity.com>
2026-07-18 19:34:20 -07:00
Chris Sells
39d07f8442 fix(docs-tooling): harden the CLI-docs pipeline per PR #4722 review
- docsmint: all page rewrites (HTML-comment, relative-link, ESM) now skip
  fenced code blocks; fence contents render verbatim
- docsmint: spliceCLINav fails closed when the "pages" key found after
  "group": "CLI Reference" is not a sibling key of the same object, and
  validates the spliced docs.json parses before writing
- docsmint: neutralize MDX ESM hazards in docs/CLI_REFERENCE.md too (bd
  emits it without the per-page transforms, but Mintlify serves it as a
  hidden page); regenerated docs/CLI_REFERENCE.md accordingly
- help_all: fail loudly when two commands collide on the same doc page ID
  instead of letting the later write win; repair a garbled comment
- generate-cli-docs.sh: --check no longer trusts a repo-root ./bd it was
  not explicitly given (the CGO guard detects CGO-ness, not staleness)
- docsync: validate the docs.json redirects array (well-formed, no dup
  sources, destinations resolve)
- pour: runtime strings match the corrected Long text (Dolt sync, issue
  database — not "sync to git" / "persistent in .beads/")
- testdata: formula_help.txt asserts the new docs/workflows/formulas.md path
2026-07-12 11:07:12 -07:00
Jack J Garzella
7be354810f
feat(formula): make primitives discoverable to coding agents (GH#3621) (#3781)
* feat(formula): add bd formula schema reflection-driven primitive index (beads-9ib)

Generates internal/formula/schema_gen.go from types.go via go:generate,
exposing all 18 exported structs (Formula, Step, LoopSpec, OnCompleteSpec,
etc.) with field types, json/toml tags, required-flag, and doc comments.

Surfaced via:
  bd formula schema                 # list every primitive
  bd formula schema loop            # show LoopSpec fields
  bd formula primitives on_complete # alias + snake_case match
  bd formula schema --json          # machine-readable

Lookup prefers exact match over Spec/Rule(s) suffix-strip, so "gate"
resolves to Gate (not GateRule). Fields tagged json:"-" (Step.SourceFormula,
Step.SourceLocation) are excluded.

TestSchemaGenIsCurrent re-runs the AST walker in-memory and byte-diffs
against the committed schema_gen.go, so a new struct in types.go without
a regen will fail CI.

Item 2 of GH#3621.

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

* feat(formula): point bd formula --help at the primitive index (beads-lnf)

Extends the cobra Long descriptions on `formula`, `formula list`, and
`formula show` so an agent reading any of them is told that
`bd formula schema` (alias `primitives`), the curated
`examples/formulas/primitives/` directory, and the website primitives
reference exist. Without these pointers, agents land on the formula
surface and conclude there is no primitive index — which is the exact
failure mode GH#3621 is closing.

Adds cmd/bd/testdata/formula_help.txt as the regression gate: a
scripttest that runs `bd formula --help` (plus `--help` on the list
and show subcommands) and asserts the four pointers are present. If
someone deletes a pointer, the snapshot fails.

website/docs/cli-reference/formula.md is auto-generated from the Long
descriptions via `bd help --doc formula`, so the website doc inherits
the pointers on its next regeneration with no manual edit.

Item 1 of GH#3621.

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

* feat(formula): curated primitive examples + smoke harness (beads-0sp)

Adds examples/formulas/primitives/ with one minimal `.formula.toml` per
empirically wired primitive in internal/formula/types.go:

  loop-count    LoopSpec.count       expand body 3x → .iter1.work…
  loop-range    LoopSpec.range/var   {n} substitutes into title
  children-epic Step.Children        epic + children w/ sibling needs
  branch-fanin  ComposeRules.Branch  fork-join, deploy depends on 3 sibs
  condition     Step.Condition       var-driven step inclusion
  gate-timer    Step.Gate            sibling gate-typed issue blocks step

Each fixture has a header doc-comment explaining the primitive in
plain language; README.md indexes them with a one-line description
each and points back at `bd formula schema`.

cmd/bd/formula_primitives_test.go is the smoke harness: for each
fixture it parses, cooks through the full transformation pipeline
(loops → branches → gates → advice → expansions → conditions), and
asserts the primitive's observable effect on the cooked subgraph
(issue IDs, blocking deps, substituted titles, gate await_type).
Cooks against an in-memory subgraph rather than a Dolt-backed temp
DB so the harness exercises the primitive transformation, not the
persistence/auto-export infrastructure.

A subtest fails if a fixture is added to the directory without a
registered assertion in cases[] — the harness exists to prove
primitives are wired, not just that fixtures parse.

Explicitly omits an `on_complete` fixture; that primitive is a
runtime no-op as of v1.0.3 and ships with beads-i02's resolution,
not this epic.

Item 3 of GH#3621.

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

* fix(formula): satisfy CI gosec G306 + regen CLI doc for new help text

Two CI fixes for the formula primitives PR:

  - internal/formula/cmd/schemagen/main.go:26 — drop WriteFile perms
    from 0644 to 0600 (gosec G306).
  - website/docs/cli-reference/formula.md and the v1.0.0 mirror —
    regenerated from the updated `bd formula --help` Long text via
    scripts/generate-cli-docs.sh, using a CGO_ENABLED=0 bd build to
    match CI.

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

* fix(formula): distinguish schema from wired primitives

* fix(formula): regen schema_gen.go for rebase onto current main

Upstream main's Formula struct gained an Intent field after PR #3781 was
opened; regenerate schema_gen.go via go generate so
TestSchemaGenIsCurrent passes after rebasing the PR's commits onto
current main.

Maintainer fix-merge for gastownhall/beads#3781.

Agent-Signature: claude-fable-5-medium on behalf of matt wilkie

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: matt wilkie <maphew@gmail.com>
2026-07-06 22:26:41 -07:00
matt wilkie
3988db7e0d
fix(init): make JSONL auto-export opt-in (#4063)
* fix(init): make JSONL auto-export opt-in

Default export.auto and export.git-add to false for new repos, make the init prompt opt-in, and update docs/tests to describe JSONL as an optional viewer/interchange/backup export rather than core sync behavior.

Fixes GH#4062

* refactor(auto-export): check commit before throttle

Move cheap Dolt commit change detection ahead of the auto-export throttle and extract the throttle decision into a tested helper. This keeps the default-off design while carrying the compatible part of Jeremy Longshore's GH#4061 refactor.

Based-on: 313e1f8258

Co-authored-by: jeremylongshore <jeremylongshore@users.noreply.github.com>

* docs: regenerate versioned CLI references
* docs: call out JSONL export opt-in change

---------

_codex-gpt-5.5-medium on behalf of CI Bot_
_codex-gpt-5.5-high on behalf of matt wilkie_
Co-authored-by: CI Bot <ci@beads.test>
2026-05-21 16:21:00 -07:00
matt wilkie
64e504d541
fix: enable auto-export by default and add init prompt (GH#2973) (#3204)
* fix: enable auto-export by default with canonical issues.jsonl name (GH#2973)

Users expected JSONL export to refresh automatically but export.auto
defaulted to false, requiring explicit opt-in. Also the default filename
(export.jsonl) didn't match the canonical issues.jsonl used in docs and
git hooks. Change defaults: export.auto=true, export.path=issues.jsonl,
export.git-add=true so viewers (bv) and git workflows see fresh data
without extra configuration.

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

* feat(init): add auto-export prompt and document export.* config (GH#2973)

Interactive bd init now asks whether to enable auto-export (default: yes).
Users can opt out during setup instead of discovering the setting later.

Also documents the export.* config namespace in bd config --help with
all four keys (export.auto, export.path, export.interval, export.git-add)
and adds export examples.

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

* docs: document export.* auto-export config keys (GH#2973)

Document the export.auto/path/interval/git-add keys in docs/CONFIG.md
and note the default-on switch in CHANGELOG.md [Unreleased].

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

* fix(export): don't prime throttle on empty init and skip git-add without git (GH#2973)

Review feedback on #3204 surfaced two regressions in the default-on
auto-export path:

1. bd init's PersistentPostRun fired maybeAutoExport with zero issues,
   writing an empty .beads/issues.jsonl and saving export-state.json with
   the current dolt commit + timestamp. The next `bd create` was then
   throttled for up to export.interval (default 60s) because the
   timestamp check in maybeAutoExport returned before considering the new
   commit, leaving issues.jsonl stale on fresh repos.

   Skip saving state and remove the empty file when the export produced
   no issues and no memories. The next write runs a real export
   immediately.

2. export.git-add defaulting to true emitted
   `Warning: auto-export: git add failed: exit status 128` on every
   write in the supported standalone BEADS_DIR flow where init
   intentionally skips `git init`. Gate the git add call on isGitRepo()
   so standalone users get silent, working auto-export.

Adds a scripttest regression guard for the init -> immediate create
path.

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

* test(memory): disable auto-export in concurrent test (GH#2973)

TestEmbeddedMemoryConcurrent started failing on this branch after
auto-export became the default: every concurrent 'bd remember'/'bd
forget' call now fires maybeAutoExport, which reads store state after
the write. Under 8-worker contention this intermittently leaves a
forgotten key visible to 'bd memories'.

The test exercises memory concurrency, not export behavior; opt it
out of auto-export so the signal stays focused. Followup: investigate
the race between write commit and post-write auto-export read in
embedded Dolt concurrent paths.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 16:02:58 -07:00
matt wilkie
9d0b7ad5f1
fix: remove nonexistent -i flag from bd import references (#3200)
The bd import command takes a positional file argument, not a -i flag.
Three files referenced the nonexistent flag:
- cmd/bd/testdata/import.txt (testscript fixture)
- cmd/bd/testdata/export.txt (testscript fixture)
- CLAUDE.md (documentation)

Also updated CLAUDE.md comment from 'SQLite cache' to 'Dolt database'
to reflect the current storage backend.

Fixes bd-6nr, related to bd-7ds.

Amp-Thread-ID: https://ampcode.com/threads/T-019d7da6-5933-71c3-87bf-45fb4594ef25

Co-authored-by: Amp <amp@ampcode.com>
2026-04-11 12:31:38 -07:00
lizzy
0fe9c03233 feat: surface quality/lifecycle commands in prime, template, and doctor (fix-merge PR #2664)
Surfaces existing but undiscoverable commands in bd prime output (CLI mode)
and beads-section.md template. Adds doctor --check=conventions as a composite
of lint, stale, and orphan checks (advisory only).

Fix-merge changes:
- Remove Close Reason Format section (not an established convention yet)
- Fix --by to --with for bd supersede (matches actual flag name)

Co-Authored-By: seanmartinsmith <114885497+seanmartinsmith@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-20 17:50:24 -07:00
darcy
f9b306f152 docs(claim): standardize start-work semantics to --claim (#2070)
Standardize start-work semantics to `bd update <id> --claim` across docs,
examples, templates, and website static LLM artifacts. Replaces
`--status in_progress` with `--claim` where the meaning is start-work.

Also fixes stale comment in llms.txt ("Update status" → "Start work").

Co-Authored-By: Valeriy Pavlovich <iqdoctor@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 22:11:39 -08:00
beads/crew/lizzy
10b1af3f9b test: add error case and missing command script tests (dolt-test-evu)
Add 12 new script tests covering error cases for existing commands
(create, update, show, close, dep, delete) and missing command
coverage (comments, label, search, config, lint, delete). All new
tests pass; 6 pre-existing script test failures remain unchanged.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 18:47:41 -08:00
Steve Yegge
e67f27c092 bd sync: 2025-12-23 23:38:57 2025-12-24 00:06:41 -08:00
Steve Yegge
2de1695615 bd sync: 2025-12-23 22:33:32 2025-12-23 22:33:33 -08:00
Steve Yegge
cf9e5a597b bd sync: 2025-12-23 20:50:50 2025-12-23 20:50:50 -08:00
Steve Yegge
9c8761abc9 bd sync: 2025-12-23 20:45:19 2025-12-23 20:45:19 -08:00
Steve Yegge
7b671662aa bd sync: 2025-12-23 13:49:07 2025-12-23 14:39:07 -08:00
Steve Yegge
c4ce191bb2 feat: add --resolution as alias for --reason on bd close (GH#721)
Jira CLIs use --resolution flag (go-jira, jira-cli). Adding this as a
hidden alias improves agent ergonomics - LLMs have a prior for this flag.

Follows same pattern as --body alias for --description (GitHub CLI).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-23 13:16:18 -08:00
Steve Yegge
abbdbf487a fix: Update dep_add test to match current show output format 2025-11-04 00:23:25 -08:00
Steve Yegge
b4cb636d92 Switch from hex to Base36 encoding for issue IDs (GH #213)
This change improves information density by using Base36 (0-9, a-z) instead
of hex (0-9, a-f) for hash-based issue IDs. Key benefits:

- Shorter IDs: Can now use 3-char IDs (was 4-char minimum)
- Better scaling: 3 chars good for ~160 issues, 4 chars for ~980 issues
- Case-insensitive: Maintains excellent CLI usability
- Backward compatible: Old hex IDs continue to work

Changes:
- Implemented Base36 encoding with proper truncation (keep LSB)
- Updated adaptive length thresholds (3-8 chars instead of 4-8)
- Fixed collision probability math to match encoding (was calculating
  for base36 but encoding in hex - now both use base36)
- Fixed ID parser bug (use prefixWithHyphen for substring matching)
- Updated all tests and test data patterns

Fixes #213

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-03 12:02:15 -08:00
Steve Yegge
0215e73780 Fix config system: rename config.json → metadata.json, fix config.yaml loading
- Renamed config.json to metadata.json to clarify purpose (database metadata)
- Fixed config.yaml/config.json conflict by making Viper explicitly load only config.yaml
- Added automatic migration from config.json to metadata.json on first read
- Fixed jsonOutput variable shadowing across 22 command files
- Updated bd init to create both metadata.json and config.yaml template
- Fixed 5 failing JSON output tests
- All tests passing

Resolves config file confusion and makes config.yaml work correctly.
Closes #178 (global flags), addresses config issues from #193

Amp-Thread-ID: https://ampcode.com/threads/T-e6ac8192-e18f-4ed7-83bc-4a5986718bb7
Co-authored-by: Amp <amp@ampcode.com>
2025-11-02 14:31:22 -08:00
Steve Yegge
64fe51d6bb Remove obsolete collision remapping code and tests
- Deleted collision remapping tests (obsolete with hash IDs bd-8e05)
- Simplified collision.go from 704 to 138 lines
- Removed RemapCollisions, ScoreCollisions, and reference update code
- Removed issue_counters table dependencies (bd-807b)
- Added COLLISION_MATH.md documentation
- Fixed RenameCounterPrefix and ResetCounter to be no-ops
- Closed bd-a58f, bd-3d65, bd-807b

Hash-based IDs make collision remapping unnecessary since collisions
are extremely rare (same ID = same content).

Amp-Thread-ID: https://ampcode.com/threads/T-cbb0f111-6a95-4598-b03e-c137112f9875
Co-authored-by: Amp <amp@ampcode.com>
2025-10-31 00:19:42 -07:00
Steve Yegge
881e0940a7 Add config.json support for database path configuration (bd-163)
- Create internal/configfile package for config.json handling
- bd init now creates .beads/config.json with database, version, and jsonl_export fields
- Database discovery checks config.json first, falls back to beads.db
- Update .gitignore to not ignore config.json (part of repo state)
- Update test to expect beads.db and config.json
- Backward compatible with existing beads.db-only setups
2025-10-26 18:44:27 -07:00
Ben Madore
cfe15a9d34
Enhance .gitignore created during bd init (#98)
- Expand .gitignore to include all SQLite-related files (journal, WAL, SHM)
- Add daemon runtime files (logs, PID, socket)
- Include legacy database filenames
- Explicitly allow JSONL files with !*.jsonl pattern
- Add test coverage to verify .gitignore content
2025-10-21 13:59:19 -07:00
Ben Madore
789145f842
Add .gitignore to .beads directory during init (#64)
- Create .gitignore file in .beads/ when running bd init
    - Ignores *.db and *.db-* patterns to prevent database commits
    - Add test coverage to verify .gitignore creation
    - Add .claude/settings.local.json to project .gitignore

    🤖 Generated with [Claude Code](https://claude.com/claude-code)

    Co-Authored-By: Claude <noreply@anthropic.com>

Co-authored-by: Ben Madore <madorb@users.noreply.github.com>
2025-10-17 11:24:39 -07:00
Travis Cline
b17fcdbb2a
Add scripttest-based integration tests (#59)
- Complete test coverage for all major bd commands:
  blocked, close, create, dep (add/remove/tree), export, help,
  import, init, list, quickstart, ready, show, stats, update, version
- Test data files validate command behavior and output
- Enables automated testing of full CLI workflows
2025-10-16 17:11:54 -07:00