$npx -y skills add AgamiAI/agami-core --skill agami-save-correctionSaves a user correction so future queries learn from it. Always appends a (question, corrected_sql) pair to the subject area's example library under <artifacts_dir>/<profile>/prompt_examples/<area>/. Additionally, classifies the correction and — when applicable — applies a surgic
| 1 | # agami save-correction |
| 2 | |
| 3 | **Before suggesting any slash command in chat, read [`shared/invocation-conventions.md`](../../shared/invocation-conventions.md).** Agami slash commands: `/agami-connect`, `/agami-query`, `/agami-model`, `/agami-save-correction`, `/agami-reconcile`. (`/agami-model`'s Review tab absorbed the former `/agami-review`.) Never write the un-prefixed forms (`/save-correction`, `/init`, etc.) or colon forms (`/agami:save-correction`) — those don't exist. **`/agami-init` was folded into `/agami-connect` Phase 0a.** For chat replies, prefer natural language ("say 'save this as a correction'", "say 'remember this'") — the agami-save-correction skill's `when_to_use` matcher routes correctly. |
| 4 | |
| 5 | You are recording a user correction. Goal: persist the fix so similar questions get better answers next time. |
| 6 | |
| 7 | This skill does two things, in this order: |
| 8 | |
| 9 | 1. **Always**: append the `(question, corrected_sql)` pair to the subject area's example library at `<artifacts_dir>/<profile>/prompt_examples/<area>/examples.yaml`. |
| 10 | 2. **When applicable**: surgically update the semantic model at `<artifacts_dir>/<profile>/` (a relationship/column/table edit, or a new metric) with the knowledge implied by the correction, **via the curation engine** (`semantic_model.cli curate`), which **validates** before write and reverts on failure. If the user's correction would break the model, refuse the model update (the example still gets saved). |
| 11 | |
| 12 | For the model format: [`semantic_model/__init__.py`](../../../../packages/agami-core/src/semantic_model/__init__.py) (layout) + `packages/agami-core/src/semantic_model/models.py`. The curation engine is `packages/agami-core/src/semantic_model/curate.py`. |
| 13 | For SQL safety: [`shared/sql-generation-rules.md`](../../shared/sql-generation-rules.md). |
| 14 | For dialect rules: [`shared/dialect-rules.md`](../../shared/dialect-rules.md). |
| 15 | For DB error classification: [`shared/db_error_classifier.md`](../../shared/db_error_classifier.md). |
| 16 | |
| 17 | --- |
| 18 | |
| 19 | ## Phase −1: Plan-mode check |
| 20 | |
| 21 | Run the detection + ask logic from [`shared/plan-mode-check.md`](../../shared/plan-mode-check.md). agami-save-correction needs Write (examples + model edits) and Bash (EXPLAIN-validation) — both are blocked in plan mode. |
| 22 | |
| 23 | **If plan mode is active and the user picks `Stay in plan mode` (or this skill is invoked under an active plan-mode context):** refuse and end the turn. **DO NOT write a plan file. DO NOT call `ExitPlanMode`.** Refusal text (verbatim): |
| 24 | |
| 25 | > I can't save corrections in plan mode — switch to **Auto** or **Edit Automatically** mode (Shift+Tab to cycle) and re-invoke. The correction won't persist otherwise. |
| 26 | |
| 27 | If plan mode is not active, skip this phase silently and go to Phase 1. |
| 28 | |
| 29 | --- |
| 30 | |
| 31 | ## Phase 1: Identify the correction |
| 32 | |
| 33 | ### 1a — resolve the active profile and artifacts_dir |
| 34 | |
| 35 | Resolve `<profile>` in this order: `AGAMI_PROFILE` env var → `active_profile` field in `<artifacts_dir>/local/.config` → literal string `"default"` (legacy fallback). |
| 36 | |
| 37 | Resolve `<artifacts_dir>` per [`shared/file-layout.md → Configuring artifacts_dir`](../../shared/file-layout.md#configuring-artifacts_dir): `AGAMI_ARTIFACTS_DIR` env var → `<artifacts_dir>/local/.config.artifacts_dir` → default `$HOME/agami-artifacts`. All examples / model / ORGANIZATION.md paths in this skill resolve under `<artifacts_dir>/<profile>/`. USER_MEMORY.md is at `<artifacts_dir>/USER_MEMORY.md` (top-level, cross-database). |
| 38 | |
| 39 | For v1.0 / v1.1 fallback paths (`<artifacts_dir>/local/<profile>.yaml`, `<artifacts_dir>/local/<profile>-examples.yaml`, `<artifacts_dir>/<profile>/`), only read; never write. Migration is agami-connect's job — this skill assumes the user has already migrated by the time they're saving corrections. |
| 40 | |
| 41 | ### 1b — find the most recent query |
| 42 | |
| 43 | Read the last entry in `<artifacts_dir>/local/query_log.jsonl`. Need `question` and `sql`. |
| 44 | |
| 45 | If the log is empty: "I don't have a recent query to attach this correction to. Ask the question first, then save the correction." Stop. |
| 46 | |
| 47 | # |