* fix(cli): one text-source layer for comment, note, and human respond
`bd comment`, `bd note` and `bd comments add` each read their body text a
little differently, and all three applied a SILENT precedence when a caller
gave two sources: positional text plus --stdin or --file resolved to the flag
and dropped the positional half with no message. In every case we could find,
the dropped half was the text the caller meant.
One textSources layer now owns the reading for all of them. Naming two sources
is an ERROR ("cannot combine positional text ... with --stdin") rather than a
precedence question; --file content is passed through verbatim, matching every
other file-input flag (--body-file, --design-file, --reason-file), while stdin
keeps trimming the trailing newline a shell appends; and an explicitly-set-but-
empty text flag counts as a source via cobra's Changed, so `--response ""` gets
"cannot be empty" rather than "no text provided".
`bd human respond` joins them: its response can come from positional args,
--response, --file or --stdin, so --response is no longer a required flag.
`bd human dismiss` takes its reason positionally as well as via --reason, and
both accept trailing free text (`<id> [text...]`) the way `bd comment` does —
a second argument is text, never a second id. The "Response: " prefix and the
shared Dismissed close reason are now formatted ONCE, before the proxied
dispatch, so the two backends cannot shape them differently; the same move
lets the proxied comment entry points take resolved text instead of re-reading
the flags themselves.
`human stats` classifies dismissals by that shared Dismissed prefix instead of
a case-insensitive substring search for "dismiss", so the writer and the
classifier cannot drift. Beads closed earlier with a lowercase or mid-string
"dismiss" move from the Dismissed count to Responded; CHANGELOG carries the
note.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UzyFzAJkmN3MGhXSo9AMwQ
* fix(human): bring `human list`/`stats` to bd list parity via IncludeAllTypes
`bd human list` built its own two-field filter: a label match plus whatever
--status the caller typed, unvalidated. So it showed closed beads by default
where `bd list` hides them, answered a typo'd status with a silent empty list
instead of an error, and — because it never went through the shared builder —
could not be told what a default listing is SUPPOSED to hide.
It goes through workapi.BuildListFilter now, which gets it the done/frozen
status exclusions, the pinned default, status validation against built-in and
custom names, comma-separated sets, and "all". `human stats` counts the same
universe (--status=all) through the same path, and the proxied side calls
openAndPrepare rather than hand-building a second filter, so the command
cannot mean one thing in direct mode and another behind the proxy.
What it must NOT inherit is the type suppression: a `human` label is an
explicit request for a person's attention, and this command is the only place
a person sees it, so gates, wisps, infra beads and templates all show. That is
the new issueops.ListRequest.IncludeAllTypes — the union of IncludeTemplates,
IncludeGates, IncludeInfra AND IncludeEphemeral. Both the type exclusions and
the PLANE decision now live in one applyTypeSuppressions that the flag skips
whole, so it decides the ephemeral plane too rather than lifting three type
knobs and leaving `bd human list` blind to human-labeled wisps. A suppression
added there in future is lifted here without touching this command.
Two pinned fixes fall out of parsing the status selector ONCE instead of
comparing the raw string in three places:
* --status=all no longer forces Pinned=false. "all" promises every status;
the string comparison never matched it, so the one selector that hides
nothing kept hiding pinned beads. The golden case status_all_keyword is
re-recorded (Pinned false -> null) and TestPinnedDefaultBySelector owns
the rule now.
* --status=pinned,closed no longer excludes the pinned beads it asks for —
the same comparison missed every multi-status set.
--ready is deliberately unaffected: it forces status open and otherwise
ignores the selector, so an "all" the query never applies must not have a
pinned side effect either.
BEHAVIOR CHANGE, called out in CHANGELOG: scripts using --status=all as a way
to list everything EXCEPT pinned beads will see pinned beads appear. Add
--no-pinned to keep the old result.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UzyFzAJkmN3MGhXSo9AMwQ
* fix(human): let proxied respond/dismiss answer wisps, and stop the phantom label warning
Two gaps in the proxied twins of `bd human respond`/`dismiss`, both of which
`bd human list` showing every bead type now makes reachable:
WISPS. The pair resolved through proxiedRequireIssue and then wrote the
comment and the close against the DURABLE tables. A human-labeled wisp is a
bead a person can see in `bd human list` — so it has to be one they can also
answer. Resolution goes through workapi.GetIssueOrWisp and the write side
branches: AddCommentToWisp/CloseWisp for the ephemeral plane, unchanged calls
for the durable one, still inside the single RunTx the proxied write
convention asks for.
THE ADVISORY WARNING FIRED ON A FAILED LOAD. The missing-'human'-label warning
read labels with the error discarded, so a label load that FAILED was
indistinguishable from a bead with no human label, and the user was told the
label was missing when nothing had been checked. The result now carries
labelsKnown, and a failed load simply warns nothing.
NOT salvaged: the post-commit close-hook firing this branch originally carried.
It was written when each proxied call site hand-wired its own hooks; main has
since moved firing onto the unit-of-work plumbing (uow.NewNotifyingProvider,
bd-opisf), which buffers during the transaction and drains after Commit. The
proxied human close already fires its hooks — a hand-wired call here would
fire each one twice. The reason is recorded on closeHumanProxied so the next
reader does not re-add it.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UzyFzAJkmN3MGhXSo9AMwQ
---------
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
315 lines
9.1 KiB
Go
315 lines
9.1 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/steveyegge/beads/internal/metrics"
|
|
"github.com/steveyegge/beads/internal/storage"
|
|
"github.com/steveyegge/beads/internal/types"
|
|
"github.com/steveyegge/beads/internal/uimd"
|
|
"github.com/steveyegge/beads/issueops"
|
|
)
|
|
|
|
// validateCommentsArgs runs as cobra's Args validation for the parent
|
|
// "comments" command, which executes before PersistentPreRunE opens the
|
|
// store (or runs migrations) and before RunE's usesProxiedServer() dispatch.
|
|
// The parent command only lists comments for a single issue, so any trailing
|
|
// positional arg is a mistake — most commonly the swapped-order add,
|
|
// `bd comments <id> add <text>`, which otherwise falls through, reads only
|
|
// args[0], and silently drops the rest with exit 0 (GH#4642). Validating
|
|
// here (rather than inside RunE, local-store-only) rejects the malformed
|
|
// invocation identically for the direct and proxied-server paths, before
|
|
// either one can open a store, run a migration, or hit the remote-migrate
|
|
// gate for an invocation that is guaranteed to fail.
|
|
func validateCommentsArgs(cmd *cobra.Command, args []string) error {
|
|
if err := cobra.MinimumNArgs(1)(cmd, args); err != nil {
|
|
return err
|
|
}
|
|
if len(args) <= 1 {
|
|
return nil
|
|
}
|
|
|
|
issueID := args[0]
|
|
if args[1] == "add" {
|
|
return HandleErrorRespectJSON(`"bd comments <issue-id> add ..." is not valid — the subcommand must come first.
|
|
|
|
To add a comment, run:
|
|
bd comments add <issue-id> <text>
|
|
|
|
Example:
|
|
bd comments add %s "your comment"
|
|
|
|
See: bd comments --help`, issueID)
|
|
}
|
|
return HandleErrorRespectJSON(`"bd comments" takes a single issue id and lists its comments.
|
|
|
|
To list comments:
|
|
bd comments <issue-id>
|
|
|
|
To add a comment:
|
|
bd comments add <issue-id> <text>
|
|
|
|
See: bd comments --help`)
|
|
}
|
|
|
|
var commentsCmd = &cobra.Command{
|
|
Use: "comments [issue-id]",
|
|
GroupID: "issues",
|
|
Short: "View or manage comments on an issue",
|
|
Long: `View or manage comments on an issue.
|
|
|
|
Examples:
|
|
# List all comments on an issue (issue id is required — there is no "comments list")
|
|
bd comments bd-123
|
|
|
|
# List comments in JSON format
|
|
bd comments bd-123 --json
|
|
|
|
# Add a comment
|
|
bd comments add bd-123 "This is a comment"
|
|
|
|
# Add a comment from a file
|
|
bd comments add bd-123 -f notes.txt`,
|
|
Args: validateCommentsArgs,
|
|
SilenceUsage: true,
|
|
SilenceErrors: true,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
evt := metrics.NewCommandEvent("comments")
|
|
defer func() {
|
|
if c := metrics.Global(); c != nil {
|
|
c.CloseEventAndAdd(evt)
|
|
}
|
|
}()
|
|
|
|
if usesProxiedServer() {
|
|
return runCommentsProxiedServer(cmd, rootCtx, args)
|
|
}
|
|
|
|
localTime, _ := cmd.Flags().GetBool("local-time")
|
|
issueID := args[0]
|
|
|
|
if err := ensureStoreActive(); err != nil {
|
|
return HandleErrorRespectJSON("getting comments: %v", err)
|
|
}
|
|
ctx := rootCtx
|
|
|
|
result, err := resolveAndGetIssueWithRouting(ctx, store, issueID)
|
|
if err != nil {
|
|
if result != nil {
|
|
result.Close()
|
|
}
|
|
return HandleErrorRespectJSON("resolving %s: %v", issueID, err)
|
|
}
|
|
if result == nil || result.Issue == nil {
|
|
if result != nil {
|
|
result.Close()
|
|
}
|
|
return HandleErrorRespectJSON("issue %s not found", issueID)
|
|
}
|
|
defer result.Close()
|
|
issueID = result.ResolvedID
|
|
|
|
comments, err := result.Store.GetIssueComments(ctx, issueID)
|
|
if err != nil {
|
|
return HandleErrorRespectJSON("getting comments: %v", err)
|
|
}
|
|
|
|
if comments == nil {
|
|
comments = make([]*types.Comment, 0)
|
|
}
|
|
|
|
if jsonOutput {
|
|
return outputJSON(comments)
|
|
}
|
|
|
|
if len(comments) == 0 {
|
|
fmt.Printf("No comments on %s\n", issueID)
|
|
return nil
|
|
}
|
|
|
|
fmt.Printf("\nComments on %s:\n\n", issueID)
|
|
for _, comment := range comments {
|
|
ts := comment.CreatedAt
|
|
if localTime {
|
|
ts = ts.Local()
|
|
}
|
|
fmt.Printf("[%s] at %s\n", comment.Author, ts.Format("2006-01-02 15:04"))
|
|
rendered := uimd.RenderMarkdown(comment.Text)
|
|
for _, line := range strings.Split(strings.TrimRight(rendered, "\n"), "\n") {
|
|
fmt.Printf(" %s\n", line)
|
|
}
|
|
fmt.Println()
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
|
|
var commentsMisplacedListCmd = &cobra.Command{
|
|
Use: "list",
|
|
Short: "Invalid — use bd comments <issue-id> to list comments",
|
|
SilenceUsage: true,
|
|
SilenceErrors: true,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
return HandleErrorRespectJSON(`"bd comments list" is not valid.
|
|
|
|
To list comments on an issue, run:
|
|
bd comments <issue-id>
|
|
|
|
Example:
|
|
bd comments bd-123
|
|
|
|
See: bd comments --help`)
|
|
},
|
|
}
|
|
|
|
var commentsAddCmd = &cobra.Command{
|
|
Use: "add [issue-id] [text...]",
|
|
Short: "Add a comment to an issue",
|
|
Long: `Add a comment to an issue.
|
|
|
|
Examples:
|
|
# Add a comment
|
|
bd comments add bd-123 "Working on this now"
|
|
|
|
# Add a comment from a file
|
|
bd comments add bd-123 -f notes.txt`,
|
|
Args: cobra.MinimumNArgs(1),
|
|
SilenceUsage: true,
|
|
SilenceErrors: true,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
CheckReadonly("comment add")
|
|
|
|
evt := metrics.NewCommandEvent("comments-add")
|
|
defer func() {
|
|
if c := metrics.Global(); c != nil {
|
|
c.CloseEventAndAdd(evt)
|
|
}
|
|
}()
|
|
|
|
issueID := args[0]
|
|
|
|
commentText, err := requireTextFromSources("comment text", "use positional args or -f to read from file",
|
|
cmdTextSources(cmd, args[1:]))
|
|
if err != nil {
|
|
return HandleErrorRespectJSON("%v", err)
|
|
}
|
|
|
|
author, _ := cmd.Flags().GetString("author")
|
|
if author == "" {
|
|
author = getActorWithGit()
|
|
}
|
|
|
|
// Dispatched after the text is resolved so both backends read the
|
|
// same sources and report the same conflicts.
|
|
if usesProxiedServer() {
|
|
return runCommentsAddProxiedServer(rootCtx, issueID, author, commentText)
|
|
}
|
|
|
|
if err := ensureStoreActive(); err != nil {
|
|
return HandleErrorRespectJSON("adding comment: %v", err)
|
|
}
|
|
ctx := rootCtx
|
|
|
|
result, err := resolveAndGetIssueForMutation(ctx, store, issueID)
|
|
if err != nil {
|
|
if result != nil {
|
|
result.Close()
|
|
}
|
|
return HandleErrorRespectJSON("resolving %s: %v", issueID, err)
|
|
}
|
|
if result == nil || result.Issue == nil {
|
|
if result != nil {
|
|
result.Close()
|
|
}
|
|
return HandleErrorRespectJSON("issue %s not found", issueID)
|
|
}
|
|
defer result.Close()
|
|
issueID = result.ResolvedID
|
|
|
|
comment, err := addCommentDirect(ctx, result.Store, issueID, author, commentText)
|
|
if err != nil {
|
|
return HandleErrorRespectJSON("adding comment: %v", err)
|
|
}
|
|
if err := commitPendingIfEmbedded(ctx, result.Store, actor, doltAutoCommitParams{
|
|
Command: "comments add",
|
|
IssueIDs: []string{issueID},
|
|
}); err != nil {
|
|
return HandleErrorRespectJSON("failed to commit: %v", err)
|
|
}
|
|
|
|
if jsonOutput {
|
|
return outputJSON(comment)
|
|
}
|
|
|
|
fmt.Printf("Comment added to %s\n", issueID)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
// addCommentDirect appends one comment through the Commenter role and returns
|
|
// the stored comment. It is the direct-route sibling of addCommentProxied and
|
|
// builds the SAME request, so the two front doors ask the storage layer one
|
|
// question.
|
|
//
|
|
// The role is reached through the STORE's own accessor, never a constructor:
|
|
// that accessor is where the store's decorator stack — hooks, telemetry — adds
|
|
// its layer, so a comment written here fires the same hook a comment written
|
|
// through the provider does. The store is the caller's rather than the global
|
|
// one, because a prefix-routed write has to reach the role through the store
|
|
// that actually holds the issue.
|
|
//
|
|
// The RESOLVE stays with the caller. On this route it is fuzzy, prefix-routed
|
|
// and cross-repo, none of which belongs on a contract an unattended client also
|
|
// calls, and the caller has already produced the canonical id. The role runs
|
|
// the issue-then-wisp fallback itself, so the comment lands on the plane the id
|
|
// actually names.
|
|
//
|
|
// The auto-commit policy is applied HERE rather than by each caller. The role
|
|
// creates its Dolt version commit inside the storage layer, so
|
|
// `--dolt-auto-commit batch` can only defer it by saying so on the context —
|
|
// the reason issueOpsContext exists — and a caller that forgets writes exactly
|
|
// the per-write commit batch mode is there to avoid. Both comment commands come
|
|
// through this function, so the policy is stated once.
|
|
func addCommentDirect(ctx context.Context, st storage.DoltStorage, issueID, author, text string) (*types.Comment, error) {
|
|
opsCtx, err := issueOpsContext(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
commenter, err := st.Commenter()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
result, err := commenter.AddComment(opsCtx, issueops.AddCommentRequest{
|
|
Author: author,
|
|
IssueID: issueID,
|
|
Text: text,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return result.Comment, nil
|
|
}
|
|
|
|
func init() {
|
|
commentsCmd.AddCommand(commentsMisplacedListCmd)
|
|
commentsCmd.AddCommand(commentsAddCmd)
|
|
commentsCmd.Flags().Bool("local-time", false, "Show timestamps in local time instead of UTC")
|
|
commentsAddCmd.Flags().StringP("file", "f", "", "Read comment text from file")
|
|
commentsAddCmd.Flags().StringP("author", "a", "", "Add author to comment")
|
|
|
|
// Issue ID completions
|
|
commentsCmd.ValidArgsFunction = issueIDCompletion
|
|
commentsAddCmd.ValidArgsFunction = issueIDCompletion
|
|
|
|
rootCmd.AddCommand(commentsCmd)
|
|
}
|
|
|
|
func isUnknownOperationError(err error) bool {
|
|
if err == nil {
|
|
return false
|
|
}
|
|
return strings.Contains(err.Error(), "unknown operation")
|
|
}
|