Skip to content

refactor: align project with Go API CLI Playbook SOP#12

Merged
Leechael merged 8 commits into
mainfrom
refactor/sop-compliance
Mar 29, 2026
Merged

refactor: align project with Go API CLI Playbook SOP#12
Leechael merged 8 commits into
mainfrom
refactor/sop-compliance

Conversation

@Leechael
Copy link
Copy Markdown
Owner

@Leechael Leechael commented Mar 29, 2026

Summary

  • Rename packages to match SOP layout: internal/cli -> internal/cmd, internal/roam -> internal/client
  • Extract internal/model for shared types (APIError, SearchResult, PageSearchResult, EstimateResult)
  • Add internal/output with Formatter struct (JSON/plain/jq modes, Hint to stderr)
  • Add ExitCode(err) int with stable exit codes: 0 (OK), 1 (error), 2 (auth 401/403), 3 (not found 404)
  • Add embedded help system: docs/help/topics/ with HELP TOPICS block in root --help, file-based topic routing
  • Add help topics: exit-codes and datalog (Clojure dialect reference with regex, string ops, schema attributes)
  • Update go.mod module path to github.com/Leechael/roam-cli
  • Fix Makefile ci target to output binary to bin/ instead of repo root
  • Add golden snapshot tests for root help and help topic routing
  • Add httptest-based unit tests for client package (Q, Write, BatchActions, error mapping)
  • Add output Formatter unit tests (JSON, plain, jq validation)

Test plan

  • make ci passes (fmt, vet, unit tests, BDD tests, build)
  • roam-cli --help shows HELP TOPICS block with datalog and exit-codes
  • roam-cli help exit-codes prints topic content
  • roam-cli help datalog prints Datalog query reference
  • roam-cli help unknown-xyz exits non-zero and lists available topics
  • Golden snapshot tests pass without -update flag
  • Client httptest tests cover success, 401, 404, empty body

Summary by cubic

Aligned the CLI with the SOP layout, added stable exit codes, and introduced an embedded help system with topic files. Also fixed output formatting so plain/default modes no longer print unexpected JSON.

  • Refactors

    • Renamed packages: internal/cli -> internal/cmd, internal/roam -> internal/client; extracted shared types into internal/model.
    • Added internal/output for consistent JSON/plain/jq formatting.
    • Switched entrypoint to cmd.NewRootCmd() and cmd.ExitCode(); silenced Cobra usage/errors for cleaner stderr.
    • Updated module path to github.com/Leechael/roam-cli; fixed imports; make ci now builds to bin/.
  • New Features

    • Stable exit codes: 0 OK, 1 error, 2 auth (401/403), 3 not found (404).
    • Embedded help topics with a HELP TOPICS block; help <topic> reads from docs/help/topics/ (added datalog and exit-codes).
    • Relative dates across flags (today/yesterday/tomorrow); added block find --today.
    • Tests: httptest client coverage, output formatter tests, and golden snapshots for root/help topics.
    • Fixed: internal/output Print is a no-op in plain/default modes to avoid unexpected JSON output.

Written for commit efdf628. Summary will update on new commits.

…ind --today

- Set SilenceUsage and SilenceErrors on root command so errors no longer
  print the full --help output
- Add "Error: " prefix in main.go to preserve standard error formatting
- Support today/yesterday/tomorrow in parseDateFlexible, benefiting
  --daily, --date, and --to-daily-page flags across all commands
- Add --today flag to block find as shorthand for --daily today
- Unify date flag help text format across journal, save, and block find
- Rename module path from roam-cli to github.com/Leechael/roamresearch-skills
- Rename internal/cli -> internal/cmd, internal/roam -> internal/client
- Add ExitCode(err) int with 0/1/2/3 mapping (auth, not-found)
- Update main.go to use NewRootCmd + ExitCode pattern
- Add embedded help system: docs/help/topics/ with HELP TOPICS block
- Add help topic routing (file-based topics + example categories)
- Update all import paths and package declarations
Move APIError, SearchResult, PageSearchResult, EstimateResult from
internal/client into a dedicated model package to match SOP layout.
Implements Formatter struct with Print, PrintJSON, Hint (stderr), and
PrintMessage methods. Includes validation and unit tests for all modes.
- Golden snapshot tests for root --help and help exit-codes output
- Client unit tests with httptest for Q, Write, BatchActions, error codes
- Add exit-codes.md and datalog.md embedded help topics
The remote repository was renamed from roamresearch-skills to roam-cli.
Update go.mod module path and all import paths to match.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 37 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="internal/output/output.go">

<violation number="1" location="internal/output/output.go:55">
P2: Print always falls back to JSON even in plain/default modes. This contradicts the documented behavior and will emit JSON when callers expect to write their own human-readable/plain output.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread internal/output/output.go
Print was falling through to printJSON even when neither --json nor --jq
was set, producing unexpected JSON output in plain/human-readable modes.
Return nil instead so callers handle their own output.
@Leechael Leechael merged commit 185d2c7 into main Mar 29, 2026
3 checks passed
@Leechael Leechael deleted the refactor/sop-compliance branch March 29, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant