beads/cmd/bd/mol_last_activity.go
Harry 8cd24769fc fix: use proper RFC3339 timezone in WIQL date formatting (bd-wz8)
The WIQL date format string used a literal 'Z' character instead of Go's
proper Z07:00 timezone placeholder. While .UTC() masked the issue for UTC
inputs, the format was fragile — if a non-UTC time were passed without
.UTC(), the output would claim UTC (literal Z) while containing local time.

Changes:
- Extract formatWIQLDate() helper that encapsulates UTC conversion + RFC3339
  formatting, making it impossible to forget either step
- Replace inline format string in buildPullWIQLMulti() with the new helper
- Fix same pattern in mol_last_activity.go (display output)
- Add TestFormatWIQLDate with 7 cases: UTC, non-UTC offsets, nanosecond
  truncation, day boundary rollovers, and Z-suffix invariant assertion
- Add non-UTC test case to TestBuildPullWIQL for end-to-end coverage

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-30 12:31:26 -07:00

56 lines
1.3 KiB
Go

package main
import (
"fmt"
"time"
"github.com/spf13/cobra"
"github.com/steveyegge/beads/internal/utils"
)
var molLastActivityCmd = &cobra.Command{
Use: "last-activity <molecule-id>",
Short: "Show last activity timestamp for a molecule",
Long: `Show the most recent activity timestamp for a molecule.
Returns the timestamp of the most recent change to any step in the molecule,
making it easy to detect stale or stuck molecules.
Activity sources:
step_closed - A step was closed
step_updated - A step was updated (claimed, edited, etc.)
molecule_updated - The molecule root itself was updated
Examples:
bd mol last-activity hq-wisp-0laki
bd mol last-activity hq-wisp-0laki --json`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
ctx := rootCtx
if store == nil {
FatalError("no database connection")
}
moleculeID, err := utils.ResolvePartialID(ctx, store, args[0])
if err != nil {
FatalError("molecule '%s' not found", args[0])
}
activity, err := store.GetMoleculeLastActivity(ctx, moleculeID)
if err != nil {
FatalError("%v", err)
}
if jsonOutput {
outputJSON(activity)
return
}
fmt.Println(activity.LastActivity.UTC().Format(time.RFC3339))
},
}
func init() {
molCmd.AddCommand(molLastActivityCmd)
}