From kmgraph
Resolves a requested model tier or legacy model name to a concrete model for the active platform, using tier mappings from me.md. Supports alias-based backwards compatibility.
How this command is triggered — by the user, by Claude, or both
Slash command
/kmgraph:kmg-ai-model-tier-resolverkmg-init-shared/The summary Claude sees in its command listing — used to decide when to auto-load this command
## Module: ai-model-tier-resolver
### Input Contract
Caller sets these variables before invoking this module:
| Variable | Description |
|---|---|
| `$requested_tier` | A tier label (`fast-tier`, `standard-tier`, `powerful-tier`) or a legacy model name (e.g., `Haiku`, `claude-sonnet-4-6`) |
| `{KG_PATH}` | Active KG path (for me.md lookup) |
---
### Step R-1: Alias Map (Backwards Compatibility — ADR-041)
Check if `$requested_tier` is a legacy model name rather than a tier label.
**Valid tier labels** (pass through to R-2 unchanged):
- `fast-tier`
- `standard-tier`
- `powerful-tier`
...Caller sets these variables before invoking this module:
| Variable | Description |
|---|---|
$requested_tier | A tier label (fast-tier, standard-tier, powerful-tier) or a legacy model name (e.g., Haiku, claude-sonnet-4-6) |
{KG_PATH} | Active KG path (for me.md lookup) |
Check if $requested_tier is a legacy model name rather than a tier label.
Valid tier labels (pass through to R-2 unchanged):
fast-tierstandard-tierpowerful-tierAlias map (match case-insensitively):
| Legacy name pattern | Resolves to |
|---|---|
Haiku, haiku, claude-haiku-* | fast-tier |
Sonnet, sonnet, claude-sonnet-* | standard-tier |
Opus, opus, claude-opus-* | powerful-tier |
Gemini Flash, flash-*, gemini-flash-* | fast-tier |
Gemini Pro, pro-*, gemini-pro-* | standard-tier |
Gemini Ultra, Ultra, ultra-*, gemini-ultra-* | powerful-tier |
If alias matched:
Resolve $requested_tier → tier label (e.g., Haiku → fast-tier)
Emit this message once per day (tracked via /tmp/.kg-tier-alias-warned-$(date +%Y-%m-%d) — one flag file per calendar day; multiple sessions on the same day suppress after the first):
⚠️ Model name
[legacy_name]is deprecated — use tier label[resolved_tier]instead. Update yourme.mdtier_map or dispatcher invocation. Aliases will be removed in v0.6.0.
Continue to R-2 with the resolved tier label.
If no alias matched and $requested_tier is not a valid tier label:
Halt with:
"Unknown tier or model name:
[$requested_tier]. Usefast-tier,standard-tier, orpowerful-tier. Run/kmgraph:kmg-initto configure tier mappings."
Read me.md YAML frontmatter in this order (project overrides user on conflict):
~/.kmgraph/me.md{KG_PATH}/me.md (override layer)Identify the active platform:
claudegeminiollamalm-studio$CLAUDE_CODE_VERSION, $GEMINI_VERSION, etc. (same as init walkthrough)Find the platform entry in platforms[] matching the active platform name.
If no platforms[] block found in either me.md:
Halt with:
"No tier mappings configured. Run
/kmgraph:kmg-init(or/kmgraph:upgrade) to set up tier mappings for your platform."
If active platform not found in platforms[]:
Halt with:
"No tier mapping for platform
[platform_name]. Run/kmgraph:kmg-initto add it."
Look up tier_map[$requested_tier] in the platform entry.
Store result as $mapped_value.
If $mapped_value is non-empty: Continue to R-4 (validation).
If $mapped_value is empty or absent: Apply collapse chain (R-3C).
Direction: downward only. Starting from $requested_tier, try progressively cheaper tiers. Never upgrade (never try a higher tier than what was requested).
If $requested_tier is | Try fallbacks in order |
|---|---|
powerful-tier | standard-tier → fast-tier |
standard-tier | fast-tier only |
fast-tier | (none — halt immediately if empty) |
For each fallback tier:
tier_map[$fallback_tier][$requested_tier] not configured — falling back to [$fallback_tier]." Then set $mapped_value and continue to R-4.If all three tiers are empty:
Halt with:
"No model available. Run
/kmgraph:kmg-initto configure tier mappings."
This gate fires only here — never from file scanning, frontmatter inspection, or grep over arbitrary files.
Validate $mapped_value by applying these checks in order. Fail on the first match:
$mapped_value is fast-tier, standard-tier, or powerful-tier → suspicious (tier label used as model value).$mapped_value case-insensitively matches any key in the R-1 alias map (e.g., Haiku, Sonnet, Opus, Flash, Ultra) → suspicious (alias used as model value).$mapped_value contains no hyphen (-), colon (:), or numeric suffix → suspicious (bare word with no version or type separator).A value that passes all three checks is treated as a valid model ID (e.g., claude-sonnet-4-6, llama3.1:8b, gemini-pro-1.5).
If any check triggers (value is suspicious):
Emit once per day (tracked via /tmp/.kg-model-suspicious-$(date +%Y-%m-%d)):
⚠️ Tier
[$requested_tier]maps to[$mapped_value]which may not be a valid model ID. Check yourme.mdtier_map. Continuing anyway — invocation may fail.
Do NOT halt. Continue with $mapped_value as-is so the user sees the downstream error rather than a silent block.
On success: $resolved_model = $mapped_value
Caller passes this to the subagent:
--model [$resolved_model]
| Condition | Action |
|---|---|
| Unknown tier label, no alias match | Halt with actionable message |
| No platforms[] in me.md | Halt with actionable message |
| Active platform missing from platforms[] | Halt with actionable message |
| All tiers empty (collapse exhausted) | Halt with actionable message |
| Suspicious model ID (validation gate) | Warn once, continue |
| Legacy alias used | Warn once (deprecation), continue |
npx claudepluginhub technomensch/knowledge-graph --plugin kmgraph