Skip to content

feat(cli): add infer reset and infer insights commands - #1241

Merged
edenreich merged 4 commits into
mainfrom
feat/reset-insights-commands
Sep 18, 2026
Merged

edenreich merged 4 commits into
mainfrom
feat/reset-insights-commands

Conversation

@edenreich

Copy link
Copy Markdown
Contributor

Summary

Promotes the /reset and /insights chat shortcuts to top-level commands, so local runtime state can be wiped and sessions analyzed without a TUI.

The only non-TUI route today is infer headless "/reset", which is the wrong entry point: headless boots the gateway container and lists models before it ever dispatches the shortcut, so wiping local state needed a working gateway. And infer headless "/reset confirm" silently did nothing, because the confirm gate is process-scoped.

infer reset                       # preview every path that would be deleted; deletes nothing
infer reset confirm               # perform the wipe
infer reset insights [--model]    # analyze past sessions first, then preview
infer insights [since] [--model]  # write a report to ~/.infer/insights/

Both commands are thin wrappers dispatched through shortcuts.Run — the same non-TUI path headless uses — so neither reimplements any reset or insights logic.

Changes

  • cmd/reset — parent + confirm + insights subcommands. Preview and confirm need no gateway and no model; only insights does.
  • cmd/insights — infer insights [since] with --model/-m, and the shared EnsureModel helper that infer reset insights reuses (same shape as cmd/init → cmd/migrate).
  • ResetShortcut.UseCLISurface — adapts the shortcut to the command line. The preview gate starts satisfied (two shell invocations are two processes, so the 5-minute window could never be satisfied the way it is in the TUI), and the preview points at infer reset confirm instead of the slash command. TUI output is unchanged.
  • EnsureModel — resolves --model then agent.model and validates against ListModels before starting a generation. A one-shot command inherits no model selection from a chat session, so without this the generator asked the gateway to analyze with an empty model. Fails fast with no model specified; use --model or set agent.model in config.
  • Registered in cmd/root, with cmd/root/root_test.go topology updated.
  • Docs: command reference entries in README.md, cross-references from the /reset and /insights shortcut entries in README.md and docs/shortcuts-guide.md.

Testing

task precommit:run and task test pass.

  • cmd/reset/reset_test.go — preview lists the seeded dirs and leaves them on disk; confirm empties them and leaves config.yaml alone.
  • cmd/insights/insights_test.go — pins the no-model failure and the shared flag spelling.
  • Wipe semantics themselves stay covered by the existing internal/presentation/shortcuts/reset_test.go.

Verified against a throwaway $HOME: preview leaves everything in place, confirm empties the runtime dirs while config.yaml and skills/ survive, infer reset bogus exits 1 with an unknown-command error, and both insights paths exit 1 on an unset model without touching the gateway.

Notes

infer headless "/reset confirm" still only previews — same process-scoped gate. Left as is, since infer reset confirm is now the supported entry point and teaching the generic headless dispatcher to special-case one shortcut's gate would be worse than the gap.

Promote the /reset and /insights chat shortcuts to top-level commands so
local runtime state can be wiped and sessions analyzed without a TUI.

Both commands are thin wrappers over the existing shortcuts, dispatched
through shortcuts.Run - the same non-TUI path headless uses - so neither
reimplements any reset or insights logic.

- infer reset previews, infer reset confirm wipes, infer reset insights
  analyzes first. The preview and confirm paths need no gateway or model.
- infer insights [since] writes the report, with --model to pick the model.
- ResetShortcut.UseCLISurface adapts the shortcut to the command line: the
  process-scoped confirm gate starts satisfied (two shell invocations are
  two processes and could never satisfy it) and the preview points at
  `infer reset confirm` instead of the slash command.
- EnsureModel resolves --model then agent.model and validates it against
  the gateway before generating. A one-shot command inherits no model
  selection from a chat session, so without it the generator asked the
  gateway to analyze with an empty model.
@edenreich
edenreich requested a review from a team as a code owner September 18, 2026 15:56
Comment thread cmd/reset/reset.go Resolved
Neither shortcut needs bespoke Go code now that `infer reset` and `infer
insights` exist. Both become YAML files written to ~/.infer/shortcuts/ by
`infer init`, wrapping the commands the way /export and /env already wrap
`infer export` and `infer env` - so users can edit, re-point or delete them
like any other shortcut.

- Delete ResetShortcut and InsightsShortcut, their metadata registrations
  and their container registrations. The wipe moves into cmd/reset as plain
  functions; the InsightsGenerator stays and is reached through the new
  container accessor.
- The preview/confirm arm gate goes with it: it guarded against a
  tab-completed /reset confirm in the TUI, and the TUI no longer executes Go
  code for /reset. `infer reset confirm` is deliberate on its own.
- Vendored reset.yaml and insights.yaml declare subcommands by name only, so
  resolveCommandConfig appends the name to the parent's args. Spelling the
  full command out again would have run `infer reset reset confirm`; a test
  in cmd/init now pins that shape for both files.
- A chat session running during a wipe keeps its in-memory conversation, so
  the command and the YAML comments both say to run /new or restart.
Running `infer reset confirm` on a real machine left state behind and a
skeleton of empty directories.

- The persistent memory directory is now a wipe target, resolved through
  cfg.ResolveMemoryDir() so a memory.dir override is honored. A git-backed
  memory dir gets the same treatment remote stores already get: the local
  clone is cleared and the output says the remote syncs back on next run.
- Per-project runtime dirs are deleted outright instead of being recreated
  empty. The project dir itself stays, since projects.yaml references it, so
  targets now splits into prune (deleted) and empty (deleted and recreated
  because they are fixed userspace locations).
- A project whose working directory no longer exists is removed whole. The
  slug is the cwd with separators replaced by "-", which is ambiguous -
  /a/my-project and /a/my/project collide - and a wrong guess would delete a
  live project's state, so a slug counts as stale only when no reading of it
  resolves on disk. The search is pruned by the filesystem rather than
  enumerating 2^n splits.
- Insights reads the MEMORY.md index as a third source, capped at
  memory.max_chars on a line boundary. The index is read rather than the fact
  files because it is already one line per fact, which keeps ingestion cheap;
  `/reset insights` runs before the wipe so the facts survive in the report.
  The report frontmatter gains memory_facts.

projects.yaml is left alone: it belongs to the desktop app, stores project
names rather than paths, and those names collide across repos, so no entry can
be matched to a stale runtime dir safely.
@edenreich
edenreich merged commit 46bb2fe into main Sep 18, 2026
1 check passed
@edenreich
edenreich deleted the feat/reset-insights-commands branch September 18, 2026 16:51
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.204.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant