/aimi-engineering:references:plan:phase-4-metadata-identityfrom aimi-engineering
Patches metadata fields on tasks.json after story-merge, handling pre-filled vs. hand-patched paths. Writes a metadata-patch.json and invokes the CLI to apply it.
Claude never picks this command on its own
Its frontmatter has no description. Without a description, Claude Code leaves it out of the list Claude chooses from. Typing /aimi-engineering:references:plan:phase-4-metadata-identity still runs it.
Loaded by
commands/plan.mdwhen itsApplies when:condition holds.
After story-merge writes the tasks.json, patch the metadata object — and read which of the two paths this run took before writing anything, because they leave different work to do.
When story-merge was invoked with --feature and --phase (the ROADMAP_MODE=true, non-split path — the CLI refuses that pair together with --split full-stack, so it never coexists with either split axis), four fields are already in the document story-merge wrote: roadmapPath, phase, baseRef and pluginVersion. Each one arrives pre-filled and is checked here rather than composed here — confirm the value against its own bullet below, report a mismatch and STOP, and never recompute one over a value the merge already validated. An absent baseRef or pluginVersion on this path is the correct pre-filled state (its source did not answer), not a gap to fill.
On every other invocation — a legacy merge, and both split axes — nothing is pre-filled and Phase 4 hand-patches those same four fields exactly as it always has. The bullets below carry both paths; nothing in the legacy one changed.
Either way the skeleton story-merge emits is minimal (title: "feat: merged tasks", branchName: "feat/merged") and everything under Authored here, never derived below is this phase's to write, on both paths.
Never rewrite a tasks file to change its metadata. For each file, use the Write tool to put only the keys this phase sets, as one JSON object, in .aimi/.tasks-staging/metadata-patch.json, then run:
AIMI_CLI=$(cat "${AIMI_CONFIG_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/aimi}/cli-path" 2>/dev/null || cat "${CLAUDE_CONFIG_DIR:-$HOME/.claude}/aimi-engineering-cli-path" 2>/dev/null)
: "${AIMI_CLI:?AIMI_CLI is empty — re-resolve via cat ~/.config/aimi/cli-path in this Bash call}"
$AIMI_CLI patch-metadata --tasks-file "[tasks file path]" --from .aimi/.tasks-staging/metadata-patch.json
Each key replaces the value it names, whole; --remove <key> deletes one. It prints {patched, unchanged, removed}. A non-zero exit wrote nothing: it refuses a branchName outside the pattern below and a changed baseRef, pluginVersion, roadmapPath or phase the merge pre-filled. Report the line verbatim and STOP. One call per tasks file; rm -f the patch file after the last. When story-merge failed, RUN_DIR is preserved and nothing is patched: write the object to <RUN_DIR>/metadata.json for diagnostic reference instead.
Patch the metadata object of the tasks.json story-merge wrote with the fields below. Four of them — baseRef, pluginVersion, roadmapPath and phase — are verified rather than authored on a run where story-merge was invoked with --feature and --phase; each of those four bullets says what verification means for its own field, and what to do on the legacy path where it is still hand-patched.
Authored here, never derived: title, branchName, issues, finalize, decisions and researchPaths — story-merge composes none of these on any path. branchName's prefix is metadata.type, decided at the - **type** bullet below and therefore not knowable at merge time; the other five are accumulated by this command's own earlier phases and never travel to the merge at all. Reading the split the wrong way costs something in both directions: hand-patching one of the four verified fields overwrites a value the merge already validated, and waiting for one of these six to be pre-filled loses it.
title: <type>: <Descriptive Name>. <Descriptive Name> is written in English, even when FEATURE_DESCRIPTION was typed in another language — the title is authored here rather than copied verbatim from the typed text. See the Artifact Language Rule (${CLAUDE_PLUGIN_ROOT}/commands/references/user-communication.md § Artifact Language Rule), which governs every plugin-owned prose field this command writes, metadata.title among them.
type: feat, ref, bug, or chore
branchName: Kebab-case, prefixed with type. For SIDE-axis split files: type/[feature]-frontend and type/[feature]-backend. For PROJECT-axis split files (MERGE_RETURN is an array): type/[feature]-<project-slug>, one per returned entry, where <project-slug> is the slugified project story-merge already used for that entry's basename — read it from the entry rather than re-slugifying (printf '%s' "$MERGE_RETURN" | jq -r '.[].branchName' | sed 's|^feat/merged-||' yields one slug per entry, in returned order — equivalently, the segment each entry's path basename carries before -tasks.json). Its ROADMAP_MODE=true equivalent is the phase-branch value suffixed the same way: type/${featureSlug}-phase-${SELECTED_PHASE_ID_SLUG}-${PHASE_SLUG}-<project-slug>.
SELECTED_PHASE_ID_SLUG is SELECTED_PHASE_ID with every . replaced by -, and every branchName below is built from it — never from the raw id. Phase ids are legitimately decimal (roadmap-init accepts 5.5 and composes .dir from the raw value), but every computed branchName here is validated against ^[a-zA-Z0-9][a-zA-Z0-9/_-]*$, a regex with no dot — so interpolating the raw id yields ...-phase-5.5-..., which this command's own Phase 4 rule then rejects with "report the invalid branch name and STOP", making a decimal phase impossible to plan. The same rule, the same regex and the same slugified symbol live in the phase-branch derivation (PHASE_ID_SLUG) of references/execute/step-1-7-claim-the-phase.md and in aimi-cli.sh's _ROADMAP_BRANCH_REGEX, which enforces the shape on a roadmap's .branch at write time; conforming the value is the fix, never widening the regex. The raw SELECTED_PHASE_ID is still what every filesystem path (${featureSlug}-phase-${SELECTED_PHASE_ID}-tasks.json and both split basenames) and every --phase argument uses — those name real on-disk files that carry the dot and match roadmap.json's own numeric id. An id with no dot slugifies to itself, so every integer-id phase keeps byte-for-byte the branchName it has today.
Per-project base branch: the branch each PROJECT-axis branch is cut from is resolved per repo, not globally — this is the detection Phase 0 defers when AIMI_ROOT_IS_GIT_REPO is false:
AIMI_CLI=$(cat "${AIMI_CONFIG_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/aimi}/cli-path" 2>/dev/null || cat "${CLAUDE_CONFIG_DIR:-$HOME/.claude}/aimi-engineering-cli-path" 2>/dev/null)
: "${AIMI_CLI:?AIMI_CLI is empty — re-resolve via cat ~/.config/aimi/cli-path in this Bash call}"
# PROJECT_PATH is the entry's own .project ("." for the root group)
if [ "$PROJECT_PATH" = "." ] || [ -z "$PROJECT_PATH" ] || [ "$PROJECT_PATH" = "null" ]; then
PROJECT_ROOT="$AIMI_ROOT"
else
case "$PROJECT_PATH" in
/*|..|../*|*/..|*/../*)
echo "Invalid project in MERGE_RETURN entry: $PROJECT_PATH" >&2
exit 1
;;
esac
if ! [[ "$PROJECT_PATH" =~ ^[a-zA-Z0-9][a-zA-Z0-9/_.-]*$ ]]; then
echo "Invalid project in MERGE_RETURN entry: $PROJECT_PATH" >&2
exit 1
fi
PROJECT_ROOT="$AIMI_ROOT/$PROJECT_PATH"
fi
PROJECT_DEFAULT=$($AIMI_CLI detect-default-branch --project "$PROJECT_ROOT")
The two guards above are defense in depth, not the primary check — detect-default-branch --project does a bare cd into whatever it is handed, so no unvalidated value may reach it. The primary refusal is the Project Path Gate at the top of Phase 3e, which runs while RUN_DIR still exists; by the time this block executes, story-merge has already deleted the staging dir and a STOP here loses the run's expansion work. Keep both — this one is byte-identical to the Step 0.9 check in references/execute/step-0-9-split-flow.md so the two stay diffable.
This is the same CLI verb references/execute/step-2-per-project-branch-setup.md uses for its own per-project branch setup (detect-default-branch --project [resolved_project_path], Step 0.9 and Per-Project Branch Setup) and commands/next.md uses for a container root — reuse it; never add a second per-repo detection mechanism here. A project whose detect-default-branch fails is not a usable repo: report it and STOP rather than falling back to $AIMI_ROOT's branch. When ROADMAP_MODE=true and not split: type/${featureSlug}-phase-${SELECTED_PHASE_ID_SLUG}-${PHASE_SLUG} instead (matches the container branch /aimi:execute creates for this phase — execute.md slugifies the id the same way, so the two agree on a decimal phase as well as an integer one). When ROADMAP_MODE=true and split (implementationScope == "full-stack", composed phase+split case — outline 13): the phase-branch value from the rule above, suffixed the same way the flat split case suffixes its own branchName — type/${featureSlug}-phase-${SELECTED_PHASE_ID_SLUG}-${PHASE_SLUG}-frontend / -backend on the SIDE axis, type/${featureSlug}-phase-${SELECTED_PHASE_ID_SLUG}-${PHASE_SLUG}-<project-slug> per returned entry on the PROJECT axis — so each split worktree/branch /aimi:execute creates matches that file's own metadata.branchName exactly; this exact-match is what lets the worktree-budget hook's governing-file resolution (_select_governing_tasks_file) pick the right split file for each sub-orchestrator's own concurrency limit. Validate every computed branchName — one per file in SPLIT_FILES, not just the first — against ^[a-zA-Z0-9][a-zA-Z0-9/_-]*$ before writing; refuse the write (report the invalid computed branch name and STOP; do not fall back to a mangled variant) if any fails, exactly as the flat-mode branchName derivation already requires.
createdAt: Today's date (YYYY-MM-DD)
baseRef: The commit the plan was written against — the full 40-character SHA printed by git rev-parse HEAD, read at Phase 4 time in the repository this file's stories target. Single-repo/monorepo (AIMI_ROOT_IS_GIT_REPO=true): run it in $AIMI_ROOT. Multi-repo (AIMI_ROOT_IS_GIT_REPO=false): $AIMI_ROOT is not a repository at all, so the value comes from the file's own project root — the same PROJECT_ROOT the per-project base-branch block above already resolves. Omit the key entirely when no single repository root resolves for the file, or when git rev-parse HEAD exits non-zero (an unborn branch has no commit to name): an absent key reads as "this plan predates the field", which a later reader can recover from, where "" or a placeholder reads as a SHA and cannot. Writing the field is the whole obligation here — comparing it against the branch an executor actually starts from belongs to whoever consumes it, and nothing in this command reads it back. When story-merge was invoked with --feature and --phase, this field arrives pre-filled and is verified rather than authored: confirm it is a full 40-character SHA naming the repository this file's stories target — that path is single-repo by construction, since the CLI refuses the pair with --split full-stack — and leave the value byte-for-byte alone. On that path an absent key means the merge's own git rev-parse HEAD did not answer; that is the omit rule above already applied, not a gap for Phase 4 to fill in.
pluginVersion: The version of the plugin install that wrote this file — the bare string printed by $AIMI_CLI version, using the $AIMI_CLI the per-project base-branch block above already resolves (no new resolution idiom belongs here). Ask the CLI that is actually running; never read a version out of .claude-plugin/plugin.json at a guessed path. The stamp exists to record which install produced the artifact, and a development checkout routinely sits at a different version from the installed cache executing this command — Layer 0-dev exists precisely because those two diverge — so a file read names the wrong writer exactly when the answer matters. This is a shared value, patched byte-identically into every file in SPLIT_FILES: a version names the writer, and one /aimi:plan invocation has exactly one writer no matter how many repositories it splits across, unlike branchName and baseRef, which name a repository and so resolve per file. Omit the key entirely when $AIMI_CLI version exits non-zero or prints an empty string — never null, never "", never a placeholder such as unknown: an absent key reads as "this plan predates the field", which a later reader can recover from, where a placeholder reads as a real version and silently poisons every per-release slice built on it. When story-merge was invoked with --feature and --phase, this field arrives pre-filled and is verified rather than authored: the merge stamped it from the CLI that actually ran, which is the same install this command is running under, so confirm it names that install and leave the value alone. On that path an absent key means that CLI's own version did not answer, and the field stays ABSENT rather than becoming a placeholder — the same non-placeholder rule as above, enforced one step earlier.
issues: The forge-confirmed issue numbers this plan closes — the confirmedIssues[] working memory the Issue Reference Confirmation Gate accumulated back in Phase 0, as an array of positive integers in ascending order. Omit the key entirely when that list is empty: when the description named no numbers, when every candidate was dropped by the gate's found/open filter, when the user confirmed none, and on every INTERACTIVE_MODE=agent run, which never confirms any. Never [], never null, never a guessed number — the same non-placeholder rule baseRef and pluginVersion above already follow, and for the sharper reason: this key's consumer is /aimi:open-pr, which turns each entry into a Closes line that shuts a real issue when the PR merges, so an invented entry does not merely read wrong, it closes someone else's work. This is a shared value, patched byte-identically into every file in SPLIT_FILES — the issues a plan closes belong to the plan, not to one of the repositories it happens to span.
finalize: The round's single end-of-round step — the one commit no story can structurally make, because it must land after every story has. An object carrying exactly three keys: intent (a string saying what the step is for), files (a non-empty array of the paths the step writes) and commitSubject (the subject line the step will commit under). Emit it at most once per round, and name in files the paths no story may declare in its own implementation.files — a chore(release) bump touching plugin.json, marketplace.json and CHANGELOG.md is the case it exists for, and a story that also declares one of them is racing the final step for the same write. validate-tasks warns (never errors) when a story claims a declared path, because a file can legitimately belong to both and the choice is the reader's; a finalize that is present but missing any of the three keys, or whose files is not a non-empty array of strings, is an error and refuses the file. Omit the key entirely when the round declares no final step — never null, never {}, the same non-placeholder rule baseRef, pluginVersion and issues above already follow, and for the same reason: an absent key reads as "this plan predates the field" or "this round ends with its last story", both of which a later reader can act on, where an empty object reads as a step that was declared and then forgotten. This value resolves per file on a split rather than being shared — see the patch rule below for which file carries it on each axis.
What the command file sets; muted values are Claude Code's defaults
7-day visitors to each command page
npx claudepluginhub aimi-so/aimi-engineering-plugin --plugin aimi-engineering156 commands in this plugin
/aimi:brainstormExplore ideas through guided brainstorming with batched questions and codebase research/aimi:deepenEnrich tasks.json stories with research insights/design:aimi:design:auditaimi:design:auditTechnical quality audit for frontend interfaces — accessibility (a11y), performance, theming, responsive design, and anti-pattern detection. Dedicated home for WCAG/a11y checks. Use when you need a systematic, code-level quality report before release.Other plugins' commands for the same job