Generate stories

From Fr-e-d/GAAI-framework · View interactive version

Generate stories is an AI agent skill from the GitHub repository Fr-e-d/GAAI-framework. Translate a single Epic into clear, actionable User Stories with explicit acceptance criteria. Activate when an Epic is defined and work needs to be prepared for Delivery execution.

How to use this skill

Skill file

Generate Stories

Purpose / When to Activate

Activate when:

Stories are the contract between Discovery and Delivery. They must be the main execution unit in GAAI.


Process

  1. Read the Story template at contexts/artefacts/stories/_template.story.md. Read the parent Epic file. Derive story IDs using the parent Epic ID prefix (e.g., Epic E01 produces stories E01S01, E01S02, etc.).

CRITICAL — Decision Cross-Reference (MUST execute before writing any story):

CRITICAL — Collision Guard (MUST execute before writing any file):

.gaai/core/scripts/lib/allocate-id.sh story <epic_prefix> (where <epic_prefix> is

the parent Epic's ID, e.g. E220). This script serialises allocation under an exclusive

flock, accounts for IDs in every backlog file (active.backlog.yaml,

blocked.backlog.yaml, archived done/*.yaml), existing story artefact files and the

host-stable reservation ledger, and writes a reservation before returning. **Never compute the next story number

by scanning the backlog manually** — the allocator is the single authority. If the

allocator script is absent (fresh install), fall back to the scan-and-verify pattern as a

degraded mode with a stderr warning.

Check the exit status and keep stderr visible (never 2>/dev/null): exit 3 means the

id could not be recorded on the shared reservation record and nothing was allocated. That

is not the "script absent" case, so do not fall back to scan-max. Follow

base.rules.md § Forbidden Patterns (allocator) instead.

contexts/artefacts/stories/{id}.story.md. If the file exists and its id frontmatter

matches a different epic or title, STOP immediately — this means an ID collision

between two epics. Surface the conflict to the human and do not proceed.

intent), treat it as an update — read the existing content first and preserve any human

edits.

different epics because each did an independent scan-max on its own branch-isolated

backlog. The allocator fixes this by serialising under flock and recording reservations

in a host-stable ledger visible to all local sessions before any branch merges.

CRITICAL — Definition of Ready (DoR) Enforcement (MUST execute after writing each story):

CRITICAL — Custom Skill Contract (MUST execute for any story involving a custom skill):

available custom skills. If that file is absent, scan .gaai/project/skills/ directly

for files matching */SKILL.md and extract the name frontmatter field from each.

Build a set of valid custom skill names.

skill name(s) in the story's required_skills frontmatter field (YAML list, e.g.

required_skills: [my-skill]). Only reference skill names that exist in the set from

step (a). Do NOT declare a skill that is not found there — the daemon has no fallback

resolution for a missing custom skill.

that explicitly names that skill's expected output — the observable artifact or

state change the skill produces (not merely "the skill was invoked"). The AC is the

surface qa-review uses to verify the skill's contract was honored.

required_skills: []. The absence of the field does not trigger validation.

autonomous Delivery via an explicit story required_skills contract — autonomy never

selects a custom skill on its own. The bound output AC is the only QA-verifiable surface;

without it, validate-artefacts returns BLOCKED. Both this framework and the cloud

product enforce identical semantics independently.

  1. Read parent Epic domain. If Epic has a domain, set it as the story's default. Allow explicit override per story.
  2. Write from the user's perspective
  3. Focus on behavior, not UI or technology
  4. Keep stories small and independent
  5. Ensure every story is testable
  6. Avoid technical solutions in story body
  7. For each story, answer: "What should the user be able to do or experience?"
  8. Output using canonical Story template
  9. MANDATORY — Validation gates via isolated sub-agents (MUST pass before backlog registration).

Before registering ANY story in the backlog, the Discovery Agent MUST execute both gates in sequence. Both gates MUST be invoked as isolated sub-agents (via the Agent tool) — never executed inline by the main Discovery agent, even if the main agent is the one that created the story. The author of a story cannot objectively validate its own work (Core Principle #5 — Independent Evaluation).

a) Format gate — invoke validate-artefacts (SKILL-VALIDATE-ARTEFACTS-001) as an isolated sub-agent. Provide the generated stories and their parent Epic. If verdict is BLOCKED, fix the flagged issues in the main agent and re-invoke the sub-agent until PASS.

b) Independent Review gate — invoke the Review Sub-Agent (SUB-AGENT-REVIEW-001) at the applicable tier. The Review Sub-Agent executes the review-story-alignment (SKILL-RSA-001) 3-pass process during Tier 2 review. Provide the stories + Epic + referenced DECs + Discovery Session Brief (if one was compiled). If no Session Brief exists, the reviewer runs in Tier 1 (DEC constraints + DoR + attestation + scope creep). If any story FAILs, the Discovery Agent resolves findings (from Brief + DECs) or escalates to the human, then re-invokes the reviewer. Maximum 2 review cycles — after that, all remaining findings escalate to the human.

Termination rule (founder-confirmed): After review cycle 2, if the only remaining findings are MEDIUM (or lower) and each names a specific deterministic fix the reviewer already prescribed, Discovery applies those fixes, re-verifies once (re-run the reviewer or a targeted self-check on the changed lines), and attests on a clean PASS. Only unresolved CRITICAL or HIGH findings — or any finding requiring a non-obvious judgment call — escalate to the human. The 2-cycle ceiling still caps full re-review rounds; the single post-cycle-2 surgical re-verify is not a third adversarial cycle.

These gates are sequential: format must PASS before the independent review runs.

No exceptions. Both gates run for every story creation or modification — regardless of batch size (1 story or 20), origin (full Epic session, bug triage, single amendment), or whether a Session Brief was compiled. For batch reviews (2+ stories), invoke a separate Review Sub-Agent per story to eliminate positional bias (see review.sub-agent.md § Positional bias mitigation).

A story registered in the backlog as refined without both gates passing via sub-agents is a governance violation. If this step is skipped, the commit message will lack gate evidence (e.g., "validate-artefacts: PASS, review[tier-2]: PASS"), which is detectable in review.

Rationale: (1) In a past incident, Discovery produced 14 stories and registered them as refined without running either gate — the gates were not in the skill's step list. (2) Later, Discovery self-validated both gates inline, using the "no Session Brief" skip condition to bypass the alignment gate entirely. In both cases, the main agent marked its own homework — no independent review occurred. This step closes both gaps by mandating sub-agent execution with no skip conditions. (3) Updated 2026-03-30: the alignment gate is now executed by the Review Sub-Agent (SUB-AGENT-REVIEW-001), enforcing Core Principle #5 (Independent Evaluation).

  1. MANDATORY — Epic dependency propagation (MUST execute before backlog registration).
  1. MANDATORY — Register in backlog. After writing all story files, add each story to contexts/backlog/active.backlog.yaml with:

A story that exists only as an artefact file but is not in the backlog is invisible to Delivery and will never be executed. This step is non-negotiable.

Rationale (status lifecycle): A prior Discovery batch had stories rolled back from in_progress because they were registered as refined while Discovery was still iterating Reviewer cycle-1 corrections. The daemon picked up the un-reviewed drafts and began implementing architecturally wrong code based on factual errors that the Reviewer would have caught. The fix is strict adherence to the draft → refined lifecycle defined in base.rules.md § Backlog State Lifecycle — this clause makes the timing explicit at skill level.

Rationale (pipeline-schema fields): A Discovery batch registered new stories without phase_status + delivery_pipeline fields. The daemon picked up the first story at the next poll, marked its top-level status to in_progress, then errored out at the 3-phase dispatch step (phase_status=''), leaving the entry in a stuck state. Root cause : this skill predated the 3-phase pipeline schema (introduced via a foundational backlog migration story when projects flip cutover_state.default_pipeline to 3phase) and never enumerated the new mandatory fields in step 12. Mitigation : the bullet above now mandates both fields whenever cutover_state.default_pipeline = 3phase, with an explicit pointer to the failure mode so the skill author understands why the field is non-optional rather than nice-to-have.

CRITICAL — Backlog YAML write safety (MUST follow):

  1. MANDATORY — Commit & push to staging (ATOMIC). After all story files are written and registered in the backlog, commit all generated/modified files and push to staging in the same step. Commit without push is a violation — Delivery cannot pick up stories that exist only locally.

Outputs

Template: contexts/artefacts/stories/_template.story.md

Produces files at contexts/artefacts/stories/{id}.story.md:

As a {user role},
I want {goal},
so that {benefit/value}.

Acceptance Criteria:
- [ ] Given {context}, when {action}, then {expected result}

Quality Checks


Non-Goals

This skill must NOT:

Stories are the contract. Ambiguous stories produce ambiguous software.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.