Skip to content

feat: add 'prime' subcommand for LLM agent orientation#6

Merged
DTTerastar merged 1 commit into
mainfrom
feat/prime-command
Apr 25, 2026
Merged

feat: add 'prime' subcommand for LLM agent orientation#6
DTTerastar merged 1 commit into
mainfrom
feat/prime-command

Conversation

@DTTerastar
Copy link
Copy Markdown
Collaborator

Summary

Agents calling this CLI as a tool tend to flail without a written contract — piping JSON to python, hunting for a non-existent --json flag, redirecting stderr with 2>&1. prime is the emerging convention (à la liftoff-cli, disler/pi-vs-claude-code) for "load context for the agent" subcommands.

crono-export prime prints a one-screen primer covering:

  • I/O contract — JSON array on stdout (the only mode), errors on stderr, [] is success-with-zero-rows.
  • Auth — env vars, no token cache.
  • Date flags--today / --days N / --start..--end; "today" is local.
  • Each subcommand's row shape, calling out the typed-vs-string distinction (servings/biometrics/exercises are typed; nutrition/notes return raw CSV strings — cast with jq tonumber).
  • jq recipes for the questions an agent is most likely to ask (today's macros, 7-day protein total, latest weight reading, breakfast foods).

Also added a pointer in root --help and the README feature bullet so an agent finds it without being told.

Test plan

  • go build ./... clean
  • go vet ./... clean
  • crono-export prime produces 77 lines of orientation, exit 0
  • crono-export --help lists prime and the LLM pointer
  • Eyeball: have an agent call prime first and see if the flailing pattern stops

🤖 Generated with Claude Code

Agents calling this CLI as a tool tend to flail without a written contract:
piping JSON to python, looking for a --json flag (there is none — JSON is
the only output mode), redirecting stderr with 2>&1.  'prime' is the
emerging convention for "load context for the agent" subcommands.

'crono-export prime' prints a one-screen primer covering:
  - I/O contract: JSON array on stdout, errors on stderr, '[]' is success
  - Auth: env vars, no token cache
  - Date flags: --today/--days/--start..--end, "today" is local
  - Each subcommand's row shape, with the typed-vs-string distinction
    called out (servings/biometrics/exercises are typed; nutrition/notes
    return raw CSV strings — cast with jq tonumber)
  - jq recipes for the questions an agent is most likely to ask

Also pointer in root --help and README so an agent finds it without
having to be told.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@DTTerastar DTTerastar merged commit 0503108 into main Apr 25, 2026
1 check passed
DTTerastar added a commit that referenced this pull request May 19, 2026
Review feedback on #44:

- **Must fix #1: README.md stale.** Replaced the "no token cache"
  paragraph with the cache location ($XDG_CACHE_HOME), the
  CRONOMETER_NO_CACHE opt-out, the `auth logout` subcommand, and a
  security note ("treat session.json like a password").  Folds in the
  reviewer's nice-to-have #5 (security guidance) at the same time.

- **Must fix #2: gofmt.**  Ran `gofmt -w` on `cmd/format.go` and
  `internal/cronoclient/daterange_test.go` (trailing blank line + struct
  field alignment).  `internal/cronoapi/gwt.go` is also flagged but is
  pre-existing from #37 — landed as a separate chore commit so this
  PR's diff stays scoped to release-blocker work.

- **Nice-to-have #4: cache schema version.**  Added
  `cacheSchemaVersion = 1` and a `Version int` field on cachedSession.
  Old/mismatched versions are silently treated as a miss so a future
  incompatible bump triggers a transparent re-login instead of a
  JSON-shape error.  New test: TestSessionCacheVersionMismatch.

Skipped: race on concurrent fresh logins (#6) — reviewer agreed this is
fine for a single-user CLI.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
DTTerastar added a commit that referenced this pull request May 19, 2026
* feat: release-blocker bundle for v0.2.0 (#17 #18 #21 #16 #15 #23 #39 #40)

Bundles eight ship-blocker fixes called out in the QA triage on main:

- **#39 session cache (major):** persist auth/cookies to
  $XDG_CACHE_HOME/crono-export/session.json (mode 0600), retry-on-stale,
  CRONOMETER_NO_CACHE escape hatch, new `auth logout` subcommand. Fixes
  the rate-limit foot-gun where 5–6 back-to-back calls trip Cronometer's
  throttle. Also de-duplicates the "login failed: login failed:" wrap.
- **#17 typed nutrition/notes JSON (breaking):** csvToJSON now returns
  []map[string]any with best-effort coercion (numeric → float64,
  true/false → bool, empty → null). Drops the contract drift where two
  of five subcommands forced jq `tonumber` on every column.
- **#15 + #23 validation before login:** Args=cobra.NoArgs + a PreRunE
  that calls chosenFormat — bad --format / positional args now exit
  fast without burning a Cronometer login attempt.
- **#16 + #18 + #21 contract-violation trio:** empty markdown is silent
  on stdout (friendly note → stderr); --until alone uses 7d window
  ending at --until (was 1-day); inverted --since/--until warns to
  stderr and returns empty + exit 0 (was non-zero error).
- **#40 VitaminDIU cosmetic:** strippedSuffix table had "UI" instead of
  the standard "IU" abbreviation; vitamin D markdown was rendering
  without splitting the unit. Added TestStrippedSuffix to cover.
- **#19 closed as part-fixed/part-wontfix:** zone-as-UTC was already
  fixed by the clean-room rewrite (#37); the wire CSV carries no
  time-of-day to surface. Documented in prime GOTCHAS.

New tests cover: strippedSuffix (cmd), resolveDateRange (cronoclient),
coerceCSVValue + csvToJSON (cronoclient), session cache round-trip
(cronoclient).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fixup: address PR review — README, gofmt, cache schema version

Review feedback on #44:

- **Must fix #1: README.md stale.** Replaced the "no token cache"
  paragraph with the cache location ($XDG_CACHE_HOME), the
  CRONOMETER_NO_CACHE opt-out, the `auth logout` subcommand, and a
  security note ("treat session.json like a password").  Folds in the
  reviewer's nice-to-have #5 (security guidance) at the same time.

- **Must fix #2: gofmt.**  Ran `gofmt -w` on `cmd/format.go` and
  `internal/cronoclient/daterange_test.go` (trailing blank line + struct
  field alignment).  `internal/cronoapi/gwt.go` is also flagged but is
  pre-existing from #37 — landed as a separate chore commit so this
  PR's diff stays scoped to release-blocker work.

- **Nice-to-have #4: cache schema version.**  Added
  `cacheSchemaVersion = 1` and a `Version int` field on cachedSession.
  Old/mismatched versions are silently treated as a miss so a future
  incompatible bump triggers a transparent re-login instead of a
  JSON-shape error.  New test: TestSessionCacheVersionMismatch.

Skipped: race on concurrent fresh logins (#6) — reviewer agreed this is
fine for a single-user CLI.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore: gofmt internal/cronoapi/gwt.go (preexisting drift from #37)

Pure formatting: column-aligned const block and var block. No logic change.
Flagged by `gofmt -l .` during review of #44.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@DTTerastar DTTerastar deleted the feat/prime-command branch May 19, 2026 04:03
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