* fix(update): fence unforced --notes overwrites behind --force across all surfaces bd update --notes silently replaced existing notes, destroying handoff history. The contract now refuses an unforced overwrite of non-empty notes with ErrNotesOverwrite (409 notes_overwrite_refused over HTTP, force_notes_overwrite to override), enforced inside the mutation transaction on both the dolt and uow backends, for single updates and batch apply alike. CAS guards keep precedence: a stale --if-assignee/--if-status still surfaces as the exit-13 mismatch, on both backends, before the fence speaks. CLI: --force and --if-assignee are no longer mutually exclusive (that exclusion made overwriting under a guard impossible); both update routes translate the fence's sentinel into the same actionable advice (--force to overwrite, --append-notes to preserve history), and the post---force warning is worded as an audit statement. The shipped plugin skill docs and bd note help now prescribe --append-notes for handoffs instead of the newly fenced bare --notes. The fence is the single enforcement point: no client-side pre-read copies of the rule. Conformance contracts, unit tests for AuthorizeNotesOverwrite, and embedded/proxied/httpapi regression coverage included. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MAFpn9pUw8WKMfymteZHbh * fix(update): exempt explicit clears from the notes fence; share its predicate CI surfaced three gaps in the fence's reach: - Clearing notes (--notes "" / patch.notes: "") was refused, diverging from every sibling text field's clear and from the backend behavior contracts. The fence now targets only its actual footgun — replacing non-empty notes with different non-empty content — via a single shared predicate, issueops.NotesReplacement, used by both the contract's AuthorizeNotesOverwrite and the CLI's warning path, so the two can no longer drift. Prose updated to match everywhere the rule is stated (ErrNotesOverwrite, ForceNotesOverwrite, OpenAPI spec + regenerated types). - The revision-CAS integration tests' incidental concurrent writes now patch design instead of notes, so they no longer depend on notes-fence semantics at all. - The historical-upgrade harness deliberately replaces fixture notes and asserts the new value; its two bd update --notes calls now pass --force. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MAFpn9pUw8WKMfymteZHbh * fix(update): address review — changelog BREAKING entry, problem.go doc block, close-policy-under-guard test Review follow-ups on #5946 (bee-ghosttrack, MERGE-AFTER-FIXES): - CHANGELOG: BREAKING entry under [Unreleased] ### Changed for the notes fence on both wires (CLI exit 1, HTTP 409 notes_overwrite_refused), with the --force / --append-notes migration line. It also names the two deliberate edges: the explicit-clear exemption, and --force widening to the close-policy half under --if-assignee now that the flag pair is legal. - problem.go: CodeNotesOverwrite's comment had landed inside CodeDependencyCycle's doc block; each const now sits under its own docs. - assign_fence_embedded_test.go: pin the previously untested close-policy half of --force under --if-assignee (refused unforced, authorized forced). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JyuQ6Tjv3D7tpNqeb2WDED * test(update): align TestWarnNotesReplacement with the post-fence warning copy The test landed on main after this branch was cut and pins the pre-fence wording, where the warning fired on any unforced overwrite. Since the fence, an unforced overwrite is refused outright and warnNotesReplacement fires only after a forced one — the audit trail for a habitual --force — so the copy it pins is now '--force replaced existing notes'. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JyuQ6Tjv3D7tpNqeb2WDED * docs(import): record bd import's notes-fence exemption as by-design (GH#6190) Import consults none of the per-field live-state fences — notes overwrite, live-claim reassign, close policy — and that is the intended shape, not an omission: its contract is wholesale row replacement, guarded by its own staleness check (only strictly-newer rows rewrite local state, --allow-stale is the single deliberate-overwrite opt-in) and reported field-by-field in updated_issues. Named in AuthorizeNotesOverwrite's enforcement-boundary comment and in bd import's help; the published CLI docs pick the help text up at the next release pin bump. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JyuQ6Tjv3D7tpNqeb2WDED * fix(update): refuse --notes "" and add --clear-notes; stop --notes help reading as additive GH#6021: an empty --notes wiped the whole notes field at exit 0 behind the same ✓ Updated receipt as a successful write — and the empty string is exactly what a dead command substitution collapses to. The empty value is now refused on both CLI routes (the accident and the deliberate clear are the same bytes at the flag layer), and the deliberate clear gets its own verb, --clear-notes, mutually exclusive with --notes/--append-notes. A verb rather than the proposed --allow-empty-notes opt-in: what needs authorizing is an intent, not an input path — --allow-empty-description unblocks stdin/file plumbing, which notes does not have — and an opt-in passed habitually would silently disarm the guard while a habitual --clear-notes fails loudly. --force does not bypass the refusal; the fence's clear exemption stands, so the verb alone authorizes the erase. The HTTP API is unchanged: patch.notes "" still clears. GH#6272: bd update --help called --notes "Additional notes" and the prime text said "Add supplementary notes" — both read as appending, so agents following the injected guidance faithfully clobbered prior context. The update help now names the operation with the --append-notes contrast at the point of use, the shared/create help is field-named like --description and --design, and the prime line points at bd update --append-notes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JyuQ6Tjv3D7tpNqeb2WDED * fix(bazel): enumerate the PR-new files in cmd/bd and issueops srcs The base added cmd/bd/BUILD.bazel and internal/storage/issueops/BUILD.bazel with EXPLICIT srcs lists after this branch was cut, so the three files this PR adds were never enumerated: cmd/bd/update_notes_guard.go (go_library bd_lib) cmd/bd/update_notes_guard_test.go (go_test bd_test) internal/storage/issueops/aggregate_authorize_notes_test.go (go_test) The go_library omission is a hard build break, not a silent skip: update.go:215,220 and update_input.go:106,111 are enumerated and call validateNotesUpdate / clearNotesRequested, so //cmd/bd:bd_lib compiles the callers without the callee. bazel.yml arms unconditionally for fork PRs (head.repo.fork == true) and builds //cmd/bd:bd + //cmd/bd:bd_test, so this reds the lane. make bazel-sync-check cannot see it -- go_srcs.py only validates the glob-based go_srcs filegroup, never the rule srcs lists. Generated by make bazel-sync (gazelle), not hand-edited, so the workflow's own BUILD-files-in-sync drift step agrees byte-for-byte. * fix(notes): name --clear-notes in bd note's rm guidance, correct the fence boundary comment, pin both request-shape rules Takes all three non-gating minors from the review. No behavior change: two prose fixes and two test cases. 1. cmd/bd/note.go's rm|remove|delete branch advised `bd update <id> --notes "text" --force` under "To change or clear notes", but clearing through --notes is exactly what this PR made impossible -- validateNotesUpdate refuses an empty value unconditionally and --force does not reach it. The branch now names both verbs separately: --notes --force to replace, --clear-notes to clear. The edit and update branches speak only of replacing and were already correct, so they are untouched. 2. aggregate.go's enforcement-boundary comment claimed the UpdateIssueInTx funnel's "one notes-replacing caller is bd edit". Under this PR's own NotesReplacement predicate there are at least four more (bd note's read-combine-write, bd defer --reason, bd rename and delete-tombstoning's mechanical ID rewrites, bd compact's clears). The exemption is still sound -- every funnel writer derives its new value from the current notes -- so the comment now names those CLASSES instead of a single caller, which is the claim that is actually true and that a future fence auditor can check. 3. Both branches this PR adds to ValidateUpdateRequest were uncovered: the batch apply leg reaches them here and nowhere else, while the single-issue HTTP handler's own pre-check returns before storage. Added a sibling table (the existing one varies only the patch; these two rules are properties of the REQUEST) with a case each. Mutation-checked, disjoint: neutralizing the force-without-notes branch reds only the first case, neutralizing the notes+append branch reds only the second, and the pre-existing canonical-fields table stays green under both. Not an amend of 5ffcc9c16c: that commit's message states it was generated by make bazel-sync and not hand-edited, so folding hand-written Go into it would falsify the claim its own BUILD-files-in-sync argument rests on. No new files, so the srcs lists it repaired stay correct. --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
208 lines
6.4 KiB
Go
208 lines
6.4 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/steveyegge/beads/internal/metrics"
|
|
"github.com/steveyegge/beads/internal/storage/issueops"
|
|
"github.com/steveyegge/beads/internal/ui"
|
|
)
|
|
|
|
// validateNoteArgs runs as cobra's Args validation for "note", before RunE
|
|
// and (on the local/embedded path) before the id ever reaches
|
|
// ResolvePartialID's fuzzy/substring matching. Mirror of validateCommentArgs
|
|
// (#5369): "note" has no subcommands of its own — its only job is "append a
|
|
// note to <id>" — so when the id positional argument is exactly a reserved
|
|
// word that is a common subcommand-shaped typo, the near-certain explanation
|
|
// is not that a bead is genuinely named that word (real ids always carry a
|
|
// prefix+hyphen — see looksLikePrefixedID). Left unguarded, that word
|
|
// silently resolves via ResolvePartialID's substring/prefix fallback to
|
|
// whatever existing bead or wisp id happens to contain it, and the note
|
|
// lands on the WRONG issue with no error. (GH#5370)
|
|
//
|
|
// Denylist is broader than #5369's {list, add}: "show" is invited by this
|
|
// guard's own error text ("bd show <issue-id>"); "update" is invited by the
|
|
// guard's own hints referencing "bd update <issue-id>" four times; and
|
|
// edit/rm/remove/delete are common subcommand-shaped typos for mutating
|
|
// commands. Broader-than-#5369 matches the in-repo direction of PR #5393
|
|
// for the comment sibling.
|
|
func validateNoteArgs(cmd *cobra.Command, args []string) error {
|
|
if err := cobra.MinimumNArgs(1)(cmd, args); err != nil {
|
|
return err
|
|
}
|
|
switch args[0] {
|
|
case "list":
|
|
return HandleErrorRespectJSON(`"bd note list ..." is not valid — "note" takes an issue id first and has no "list" subcommand.
|
|
|
|
To append a note:
|
|
bd note <issue-id> "text"
|
|
|
|
To read notes on an issue:
|
|
bd show <issue-id>
|
|
|
|
See: bd note --help`)
|
|
case "add":
|
|
return HandleErrorRespectJSON(`"bd note add ..." is not valid — "note" already means "append a note" and takes an issue id first, not the word "add".
|
|
|
|
To append a note:
|
|
bd note <issue-id> "text"
|
|
|
|
(Equivalent long form: bd update <issue-id> --append-notes "text".)
|
|
|
|
See: bd note --help`)
|
|
case "show":
|
|
return HandleErrorRespectJSON(`"bd note show ..." is not valid — "note" takes an issue id first and has no "show" subcommand.
|
|
|
|
To read notes on an issue:
|
|
bd show <issue-id>
|
|
|
|
To append a note:
|
|
bd note <issue-id> "text"
|
|
|
|
See: bd note --help`)
|
|
case "edit":
|
|
return HandleErrorRespectJSON(`"bd note edit ..." is not valid — "note" only appends and has no "edit" subcommand.
|
|
|
|
To append a note:
|
|
bd note <issue-id> "text"
|
|
|
|
To replace existing notes (requires --force once notes are set):
|
|
bd update <issue-id> --notes "text" --force
|
|
|
|
See: bd note --help`)
|
|
case "rm", "remove", "delete":
|
|
return HandleErrorRespectJSON(`"bd note %s ..." is not valid — "note" only appends and has no "%s" subcommand.
|
|
|
|
To append a note:
|
|
bd note <issue-id> "text"
|
|
|
|
To replace notes (requires --force once notes are set):
|
|
bd update <issue-id> --notes "text" --force
|
|
|
|
To clear notes:
|
|
bd update <issue-id> --clear-notes
|
|
|
|
See: bd note --help`, args[0], args[0])
|
|
case "update":
|
|
return HandleErrorRespectJSON(`"bd note update ..." is not valid — "note" takes an issue id first and has no "update" subcommand.
|
|
|
|
To append a note:
|
|
bd note <issue-id> "text"
|
|
|
|
To append or replace notes via the long form:
|
|
bd update <issue-id> --append-notes "text"
|
|
bd update <issue-id> --notes "text" --force (replaces; --force needed once notes are set)
|
|
|
|
See: bd note --help`)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
var noteCmd = &cobra.Command{
|
|
Use: "note <id> [text...]",
|
|
GroupID: "issues",
|
|
Short: "Append a note to an issue",
|
|
Long: `Append a note to an issue's notes field.
|
|
|
|
Shorthand for 'bd update <id> --append-notes "text"'.
|
|
|
|
Examples:
|
|
bd note gt-abc "Fixed the flaky test"
|
|
bd note gt-abc Fixed the flaky test
|
|
echo "note from pipe" | bd note gt-abc --stdin
|
|
bd note gt-abc --file notes.txt
|
|
|
|
Note: "note" has NO subcommands — it only appends.
|
|
To read notes on an issue, use: bd show <id>`,
|
|
Args: validateNoteArgs,
|
|
SilenceUsage: true,
|
|
SilenceErrors: true,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
CheckReadonly("note")
|
|
|
|
evt := metrics.NewCommandEvent("note")
|
|
defer func() {
|
|
if c := metrics.Global(); c != nil {
|
|
c.CloseEventAndAdd(evt)
|
|
}
|
|
}()
|
|
|
|
id := args[0]
|
|
textArgs := args[1:]
|
|
|
|
noteText, err := requireTextFromSources("note text", "use positional args, --stdin, or --file",
|
|
cmdTextSources(cmd, textArgs))
|
|
if err != nil {
|
|
return HandleErrorRespectJSON("%v", err)
|
|
}
|
|
|
|
if usesProxiedServer() {
|
|
return runNoteProxiedServer(rootCtx, id, noteText)
|
|
}
|
|
|
|
ctx := rootCtx
|
|
|
|
result, err := resolveAndGetIssueForMutation(ctx, store, id)
|
|
if err != nil {
|
|
if result != nil {
|
|
result.Close()
|
|
}
|
|
return HandleErrorRespectJSON("resolving %s: %v", id, err)
|
|
}
|
|
if result == nil || result.Issue == nil {
|
|
if result != nil {
|
|
result.Close()
|
|
}
|
|
return HandleErrorRespectJSON("issue %s not found", id)
|
|
}
|
|
defer result.Close()
|
|
|
|
issue := result.Issue
|
|
issueStore := result.Store
|
|
|
|
if err := validateIssueUpdatable(id, issue); err != nil {
|
|
return HandleErrorRespectJSON("%s", err)
|
|
}
|
|
|
|
// Passed as an append OPERATION, not a pre-merged value: the storage
|
|
// layer re-reads the row inside the mutation transaction and appends
|
|
// there. Concatenating onto the `issue` snapshot here (read in an
|
|
// earlier transaction) silently erased notes committed by a concurrent
|
|
// `bd note` / `bd update --append-notes` — both processes exited 0.
|
|
updates := map[string]interface{}{
|
|
issueops.OpAppendNotes: noteText,
|
|
}
|
|
if err := issueStore.UpdateIssue(ctx, result.ResolvedID, updates, actor); err != nil {
|
|
return HandleErrorRespectJSON("updating %s: %v", id, err)
|
|
}
|
|
if err := commitPendingIfEmbedded(ctx, issueStore, actor, doltAutoCommitParams{
|
|
Command: "note",
|
|
IssueIDs: []string{result.ResolvedID},
|
|
}); err != nil {
|
|
return HandleErrorRespectJSON("failed to commit: %v", err)
|
|
}
|
|
|
|
SetLastTouchedID(result.ResolvedID)
|
|
|
|
updatedIssue, _ := issueStore.GetIssue(ctx, result.ResolvedID)
|
|
title := ""
|
|
if updatedIssue != nil {
|
|
title = updatedIssue.Title
|
|
}
|
|
if jsonOutput {
|
|
if updatedIssue != nil {
|
|
return outputJSON(updatedIssue)
|
|
}
|
|
return nil
|
|
}
|
|
fmt.Printf("%s Note added to %s\n", ui.RenderPass("✓"), formatFeedbackID(result.ResolvedID, title))
|
|
return nil
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
registerTextSourceFlags(noteCmd, "note text")
|
|
noteCmd.ValidArgsFunction = issueIDCompletion
|
|
rootCmd.AddCommand(noteCmd)
|
|
}
|