* feat(dates): add due date schema and --due flag - Add due_at and defer_until columns to issues table via migration 035 - Implement --due flag on create command with ISO date parsing - Extend RPC protocol and daemon to pass DueAt from CLI to storage - Display DueAt and DeferUntil in show command output - Update Issue type with new date fields Users can now set due dates when creating issues, enabling deadline-based task management. * feat(dates): add compact duration parser (+6h, +1d, +2w) - Create internal/timeparsing package with layered parser architecture - Implement parseCompactDuration with regex pattern [+-]?\d+[hdwmy] - Add comprehensive test suite (22 cases) for duration parsing - Integrate into create.go with fallback to ISO format Supports hours (h), days (d), weeks (w), months (m), and years (y). Negative values allowed for past dates. * feat(dates): add NLP parsing for natural language dates Integrate olebedev/when library for natural language time expressions. The layered parser now handles: compact duration → absolute formats → NLP. Changes: - Add olebedev/when dependency for NLP parsing - Implement ParseNaturalLanguage and ParseRelativeTime functions - Reorder layers: absolute formats before NLP to avoid misinterpretation - Simplify create.go to use unified ParseRelativeTime - Add comprehensive NLP test coverage (22 test cases) Supports: tomorrow, next monday, in 3 days, 3 days ago * feat(dates): add --defer flag to create/update/defer commands Add time-based deferral support alongside existing status-based defer. Issues can now be hidden from bd ready until a specific time. Changes: - Add --defer flag to bd create (sets defer_until on creation) - Add --due and --defer flags to bd update (modify existing issues) - Add --until flag to bd defer (combines status=deferred with defer_until) - Add DueAt/DeferUntil fields to UpdateArgs in protocol.go Supports: +1h, tomorrow, next monday, 2025-01-15 * feat(dates): add defer_until filtering to ready command Add time-based deferral support to bd ready: - Add --include-deferred flag to show issues with future defer_until - Filter out issues where defer_until > now by default - Update undefer to clear defer_until alongside status change - Add IncludeDeferred to WorkFilter and RPC ReadyArgs Part of GH#820: Relative Date Parsing (Phase 5) * feat(dates): add polish and tests for relative date parsing Add user-facing warnings when defer date is in the past to help catch common mistakes. Expand help text with format examples and document the olebedev/when September parsing quirk. Tests: - TestCreateSuite/WithDueAt, WithDeferUntil, WithBothDueAndDefer - TestReadyWorkDeferUntil (ExcludesFutureDeferredByDefault, IncludeDeferredShowsAll) Docs: - CLAUDE.md quick reference updated with new flags - Help text examples for --due, --defer on create/update Closes: Phase 6 of beads-820-relative-dates spec * feat(list): add time-based query filters for defer/due dates Add --deferred, --defer-before, --defer-after, --due-before, --due-after, and --overdue flags to bd list command. All date filters now support relative time expressions (+6h, tomorrow, next monday) via the timeparsing package. Filters: - --deferred: issues with defer_until set - --defer-before/after: filter by defer_until date range - --due-before/after: filter by due_at date range - --overdue: due_at in past AND status != closed Existing date filters (--created-after, etc.) now also support relative time expressions through updated parseTimeFlag(). * build(nix): update vendorHash for olebedev/when dependency The olebedev/when library was added for natural language date parsing (GH#820). This changes go.sum, requiring an updated vendorHash in the Nix flake configuration.
140 lines
4.8 KiB
Go
140 lines
4.8 KiB
Go
package sqlite
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/steveyegge/beads/internal/types"
|
|
)
|
|
|
|
// isUniqueConstraintError checks if error is a UNIQUE constraint violation
|
|
// Used to detect and handle duplicate IDs in JSONL imports gracefully
|
|
func isUniqueConstraintError(err error) bool {
|
|
if err == nil {
|
|
return false
|
|
}
|
|
errMsg := err.Error()
|
|
return strings.Contains(errMsg, "UNIQUE constraint failed") ||
|
|
strings.Contains(errMsg, "constraint failed: UNIQUE")
|
|
}
|
|
|
|
// insertIssue inserts a single issue into the database
|
|
func insertIssue(ctx context.Context, conn *sql.Conn, issue *types.Issue) error {
|
|
sourceRepo := issue.SourceRepo
|
|
if sourceRepo == "" {
|
|
sourceRepo = "." // Default to primary repo
|
|
}
|
|
|
|
wisp := 0
|
|
if issue.Ephemeral {
|
|
wisp = 1
|
|
}
|
|
pinned := 0
|
|
if issue.Pinned {
|
|
pinned = 1
|
|
}
|
|
isTemplate := 0
|
|
if issue.IsTemplate {
|
|
isTemplate = 1
|
|
}
|
|
|
|
_, err := conn.ExecContext(ctx, `
|
|
INSERT OR IGNORE INTO issues (
|
|
id, content_hash, title, description, design, acceptance_criteria, notes,
|
|
status, priority, issue_type, assignee, estimated_minutes,
|
|
created_at, created_by, updated_at, closed_at, external_ref, source_repo, close_reason,
|
|
deleted_at, deleted_by, delete_reason, original_type,
|
|
sender, ephemeral, pinned, is_template,
|
|
await_type, await_id, timeout_ns, waiters, mol_type,
|
|
event_kind, actor, target, payload,
|
|
due_at, defer_until
|
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
`,
|
|
issue.ID, issue.ContentHash, issue.Title, issue.Description, issue.Design,
|
|
issue.AcceptanceCriteria, issue.Notes, issue.Status,
|
|
issue.Priority, issue.IssueType, issue.Assignee,
|
|
issue.EstimatedMinutes, issue.CreatedAt, issue.CreatedBy, issue.UpdatedAt,
|
|
issue.ClosedAt, issue.ExternalRef, sourceRepo, issue.CloseReason,
|
|
issue.DeletedAt, issue.DeletedBy, issue.DeleteReason, issue.OriginalType,
|
|
issue.Sender, wisp, pinned, isTemplate,
|
|
issue.AwaitType, issue.AwaitID, int64(issue.Timeout), formatJSONStringArray(issue.Waiters),
|
|
string(issue.MolType),
|
|
issue.EventKind, issue.Actor, issue.Target, issue.Payload,
|
|
issue.DueAt, issue.DeferUntil,
|
|
)
|
|
if err != nil {
|
|
// INSERT OR IGNORE should handle duplicates, but driver may still return error
|
|
// Explicitly ignore UNIQUE constraint errors (expected for duplicate IDs in JSONL)
|
|
if !isUniqueConstraintError(err) {
|
|
return fmt.Errorf("failed to insert issue: %w", err)
|
|
}
|
|
// Duplicate ID detected and ignored (INSERT OR IGNORE succeeded)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// insertIssues bulk inserts multiple issues using a prepared statement
|
|
func insertIssues(ctx context.Context, conn *sql.Conn, issues []*types.Issue) error {
|
|
stmt, err := conn.PrepareContext(ctx, `
|
|
INSERT OR IGNORE INTO issues (
|
|
id, content_hash, title, description, design, acceptance_criteria, notes,
|
|
status, priority, issue_type, assignee, estimated_minutes,
|
|
created_at, created_by, updated_at, closed_at, external_ref, source_repo, close_reason,
|
|
deleted_at, deleted_by, delete_reason, original_type,
|
|
sender, ephemeral, pinned, is_template,
|
|
await_type, await_id, timeout_ns, waiters, mol_type,
|
|
event_kind, actor, target, payload,
|
|
due_at, defer_until
|
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
`)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to prepare statement: %w", err)
|
|
}
|
|
defer func() { _ = stmt.Close() }()
|
|
|
|
for _, issue := range issues {
|
|
sourceRepo := issue.SourceRepo
|
|
if sourceRepo == "" {
|
|
sourceRepo = "." // Default to primary repo
|
|
}
|
|
|
|
wisp := 0
|
|
if issue.Ephemeral {
|
|
wisp = 1
|
|
}
|
|
pinned := 0
|
|
if issue.Pinned {
|
|
pinned = 1
|
|
}
|
|
isTemplate := 0
|
|
if issue.IsTemplate {
|
|
isTemplate = 1
|
|
}
|
|
|
|
_, err = stmt.ExecContext(ctx,
|
|
issue.ID, issue.ContentHash, issue.Title, issue.Description, issue.Design,
|
|
issue.AcceptanceCriteria, issue.Notes, issue.Status,
|
|
issue.Priority, issue.IssueType, issue.Assignee,
|
|
issue.EstimatedMinutes, issue.CreatedAt, issue.CreatedBy, issue.UpdatedAt,
|
|
issue.ClosedAt, issue.ExternalRef, sourceRepo, issue.CloseReason,
|
|
issue.DeletedAt, issue.DeletedBy, issue.DeleteReason, issue.OriginalType,
|
|
issue.Sender, wisp, pinned, isTemplate,
|
|
issue.AwaitType, issue.AwaitID, int64(issue.Timeout), formatJSONStringArray(issue.Waiters),
|
|
string(issue.MolType),
|
|
issue.EventKind, issue.Actor, issue.Target, issue.Payload,
|
|
issue.DueAt, issue.DeferUntil,
|
|
)
|
|
if err != nil {
|
|
// INSERT OR IGNORE should handle duplicates, but driver may still return error
|
|
// Explicitly ignore UNIQUE constraint errors (expected for duplicate IDs in JSONL)
|
|
if !isUniqueConstraintError(err) {
|
|
return fmt.Errorf("failed to insert issue %s: %w", issue.ID, err)
|
|
}
|
|
// Duplicate ID detected and ignored (INSERT OR IGNORE succeeded)
|
|
}
|
|
}
|
|
return nil
|
|
}
|