work-kit-cli 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +147 -0
  2. package/cli/bin/work-kit.mjs +21 -0
  3. package/cli/src/commands/complete.ts +163 -0
  4. package/cli/src/commands/completions.ts +137 -0
  5. package/cli/src/commands/context.ts +41 -0
  6. package/cli/src/commands/doctor.ts +79 -0
  7. package/cli/src/commands/init.test.ts +116 -0
  8. package/cli/src/commands/init.ts +184 -0
  9. package/cli/src/commands/loopback.ts +64 -0
  10. package/cli/src/commands/next.ts +172 -0
  11. package/cli/src/commands/observe.ts +144 -0
  12. package/cli/src/commands/setup.ts +159 -0
  13. package/cli/src/commands/status.ts +50 -0
  14. package/cli/src/commands/uninstall.ts +89 -0
  15. package/cli/src/commands/upgrade.ts +12 -0
  16. package/cli/src/commands/validate.ts +34 -0
  17. package/cli/src/commands/workflow.ts +125 -0
  18. package/cli/src/config/agent-map.ts +62 -0
  19. package/cli/src/config/loopback-routes.ts +45 -0
  20. package/cli/src/config/phases.ts +119 -0
  21. package/cli/src/context/extractor.test.ts +77 -0
  22. package/cli/src/context/extractor.ts +73 -0
  23. package/cli/src/context/prompt-builder.ts +70 -0
  24. package/cli/src/engine/loopbacks.test.ts +33 -0
  25. package/cli/src/engine/loopbacks.ts +32 -0
  26. package/cli/src/engine/parallel.ts +60 -0
  27. package/cli/src/engine/phases.ts +23 -0
  28. package/cli/src/engine/transitions.test.ts +117 -0
  29. package/cli/src/engine/transitions.ts +97 -0
  30. package/cli/src/index.ts +253 -0
  31. package/cli/src/observer/data.ts +267 -0
  32. package/cli/src/observer/renderer.ts +364 -0
  33. package/cli/src/observer/watcher.ts +104 -0
  34. package/cli/src/state/helpers.test.ts +91 -0
  35. package/cli/src/state/helpers.ts +65 -0
  36. package/cli/src/state/schema.ts +113 -0
  37. package/cli/src/state/store.ts +82 -0
  38. package/cli/src/state/validators.test.ts +105 -0
  39. package/cli/src/state/validators.ts +81 -0
  40. package/cli/src/utils/colors.ts +12 -0
  41. package/package.json +50 -0
  42. package/skills/auto-kit/SKILL.md +216 -0
  43. package/skills/build/SKILL.md +88 -0
  44. package/skills/build/stages/commit.md +43 -0
  45. package/skills/build/stages/core.md +48 -0
  46. package/skills/build/stages/integration.md +44 -0
  47. package/skills/build/stages/migration.md +41 -0
  48. package/skills/build/stages/red.md +44 -0
  49. package/skills/build/stages/refactor.md +48 -0
  50. package/skills/build/stages/setup.md +42 -0
  51. package/skills/build/stages/ui.md +51 -0
  52. package/skills/deploy/SKILL.md +62 -0
  53. package/skills/deploy/stages/merge.md +59 -0
  54. package/skills/deploy/stages/monitor.md +39 -0
  55. package/skills/deploy/stages/remediate.md +54 -0
  56. package/skills/full-kit/SKILL.md +197 -0
  57. package/skills/plan/SKILL.md +77 -0
  58. package/skills/plan/stages/architecture.md +53 -0
  59. package/skills/plan/stages/audit.md +58 -0
  60. package/skills/plan/stages/blueprint.md +60 -0
  61. package/skills/plan/stages/clarify.md +61 -0
  62. package/skills/plan/stages/investigate.md +47 -0
  63. package/skills/plan/stages/scope.md +46 -0
  64. package/skills/plan/stages/sketch.md +44 -0
  65. package/skills/plan/stages/ux-flow.md +49 -0
  66. package/skills/review/SKILL.md +104 -0
  67. package/skills/review/stages/compliance.md +48 -0
  68. package/skills/review/stages/handoff.md +59 -0
  69. package/skills/review/stages/performance.md +45 -0
  70. package/skills/review/stages/security.md +49 -0
  71. package/skills/review/stages/self-review.md +41 -0
  72. package/skills/test/SKILL.md +83 -0
  73. package/skills/test/stages/e2e.md +44 -0
  74. package/skills/test/stages/validate.md +51 -0
  75. package/skills/test/stages/verify.md +41 -0
  76. package/skills/wrap-up/SKILL.md +81 -0
@@ -0,0 +1,88 @@
1
+ ---
2
+ name: build
3
+ description: "Run the Build phase — 8 sub-stages from Setup to Commit. Follows the Blueprint from Plan."
4
+ user-invocable: false
5
+ allowed-tools: Bash, Read, Write, Edit, Glob, Grep
6
+ ---
7
+
8
+ You are the **Lead Developer**. Execute the implementation plan from the Blueprint precisely.
9
+
10
+ ## Sub-stages (in order)
11
+
12
+ 1. **Setup** — Create branch, install deps, scaffold
13
+ 2. **Migration** — Database schema changes
14
+ 3. **Red** — Write failing tests first (TDD red phase)
15
+ 4. **Core** — Make tests pass — service layer, API, business logic (TDD green phase)
16
+ 5. **UI** — Components, pages, interactions
17
+ 6. **Refactor** — Improve code quality, keep tests green (TDD refactor phase)
18
+ 7. **Integration** — Wire everything together, verify full data flow
19
+ 8. **Commit** — Clean commits, push branch, create PR
20
+
21
+ ## Execution
22
+
23
+ For each sub-stage:
24
+ 1. Read the sub-stage file (e.g., `.claude/skills/build/stages/setup.md`)
25
+ 2. Reference the Blueprint in `.work-kit/state.md` — follow its steps for this layer
26
+ 3. Write actual code, run actual commands
27
+ 4. Update `.work-kit/state.md` with outputs
28
+ 5. Proceed to the next sub-stage
29
+
30
+ ## Key Principle
31
+
32
+ **Follow the Blueprint.** The Plan phase already decided what to build and how. Your job is execution, not redesign. If you discover the Blueprint is wrong, note it and adapt minimally — don't redesign mid-build.
33
+
34
+ ## Recording
35
+
36
+ Throughout every sub-stage, capture three things in the shared state.md sections:
37
+
38
+ - **`## Decisions`** — Whenever you choose between real alternatives, append: `**<context>**: chose <X> over <Y> — <why>`. Skip obvious choices.
39
+ - **`## Deviations`** — Whenever you diverge from the Blueprint, append: `**<Blueprint step>**: <what changed> — <why>`. Every deviation needs a reason.
40
+
41
+ These feed into the final work-kit log summary. If you don't record them here, they're lost.
42
+
43
+ ## Loop-back
44
+
45
+ If **Refactor** returns "broken" (tests failing after refactor):
46
+ - Revert the refactoring that broke tests
47
+ - Go back to **Core** to fix
48
+ - Re-run **Refactor**
49
+ - Max 2 loops, then proceed with tests passing (skip further refactoring)
50
+
51
+ ## Context Input
52
+
53
+ This phase runs as a **fresh agent**. Read only these sections from `.work-kit/state.md`:
54
+ - `### Plan: Final` — the Blueprint, Architecture, Scope, and Constraints
55
+ - `## Criteria` — what "done" looks like
56
+ - `## Description` — original request for context
57
+
58
+ Do NOT read the Plan sub-stage working notes (Clarify, Investigate, Sketch, etc.) — they're consumed by Plan: Final.
59
+
60
+ ## Final Output
61
+
62
+ After all sub-stages are done, append a `### Build: Final` section to state.md. This is the **only section the Test agent reads**.
63
+
64
+ ```markdown
65
+ ### Build: Final
66
+
67
+ **PR:** #<number> — <title>
68
+ **PR URL:** <url>
69
+ **Branch:** feature/<slug>
70
+
71
+ **What was built:**
72
+ - <file>: <what was implemented>
73
+ - ...
74
+
75
+ **Test status:**
76
+ - New tests: <count> (all passing)
77
+ - Existing tests: all passing | <failures>
78
+
79
+ **Deviations from Blueprint:**
80
+ - <deviation and why — or "None">
81
+
82
+ **Known issues:**
83
+ - <anything the Test/Review agents should watch for — or "None">
84
+ ```
85
+
86
+ Then:
87
+ - Update state: `**Phase:** build (complete)`
88
+ - Commit state: `git add .work-kit/ && git commit -m "work-kit: complete build"`
@@ -0,0 +1,43 @@
1
+ ---
2
+ description: "Build sub-stage: Create clean commits, push branch, create PR."
3
+ ---
4
+
5
+ # Commit
6
+
7
+ **Role:** Release Preparer
8
+ **Goal:** Clean git history, push, and open a PR.
9
+
10
+ ## Instructions
11
+
12
+ 1. Review all changes with `git diff` and `git status`
13
+ 2. Stage changes in logical groups — don't dump everything in one commit
14
+ 3. Write clear commit messages:
15
+ - First line: imperative, under 72 chars (e.g., "Add avatar upload service and API endpoint")
16
+ - Body: explain what and why, not how
17
+ 4. Push the feature branch
18
+ 5. Create a pull request:
19
+ - Title: concise summary of the feature
20
+ - Body: description, what changed, how to test
21
+ 6. Record the PR URL
22
+
23
+ ## Output (append to state.md)
24
+
25
+ ```markdown
26
+ ### Build: Commit
27
+
28
+ **Commits:**
29
+ - `<hash>` — <message summary>
30
+ - ...
31
+
32
+ **Branch Pushed:** feature/<slug>
33
+ **PR:** #<number> — <title>
34
+ **PR URL:** <url>
35
+ ```
36
+
37
+ ## Rules
38
+
39
+ - Don't include `.work-kit/` state files in the PR commits — commit those separately
40
+ - Don't include unrelated changes
41
+ - If there are secrets or env files staged, remove them
42
+ - Prefer multiple focused commits over one giant commit
43
+ - PR description should be useful to a reviewer — not a wall of text
@@ -0,0 +1,48 @@
1
+ ---
2
+ description: "Build sub-stage: Make failing tests pass — service layer, API, business logic (TDD green phase)."
3
+ ---
4
+
5
+ # Core — Make Tests Pass
6
+
7
+ **Role:** Core Developer
8
+ **Goal:** Implement the minimum code to make all failing tests pass.
9
+
10
+ ## Instructions
11
+
12
+ 1. Read the failing tests from the Red phase
13
+ 2. Implement the code needed to make them pass:
14
+ - Service layer functions
15
+ - API route handlers
16
+ - Validation schemas
17
+ - Business logic
18
+ 3. Follow the Blueprint's Architecture section for structure
19
+ 4. Match existing codebase patterns found during Investigate
20
+ 5. Run tests after each major piece — watch them go green one by one
21
+
22
+ ## Output (append to state.md)
23
+
24
+ ```markdown
25
+ ### Build: Core
26
+
27
+ **Files Changed:**
28
+ - `<path>` — <what was implemented>
29
+
30
+ **Functions Implemented:**
31
+ - `<name>` in `<file>` — <purpose>
32
+
33
+ **Test Status:**
34
+ - Previously failing: <N>
35
+ - Now passing: <M>
36
+ - Still failing: <K> (explain why if > 0)
37
+
38
+ **Notes:**
39
+ - <any deviations from Blueprint — also record in the `## Deviations` section of state.md>
40
+ ```
41
+
42
+ ## Rules
43
+
44
+ - Write the **minimum** code to pass tests — no gold-plating
45
+ - Don't refactor yet — that's the Refactor sub-stage
46
+ - Don't build UI yet — that's the UI sub-stage
47
+ - If a test expectation seems wrong, fix the test only if the Blueprint supports it
48
+ - Match existing code patterns exactly — naming, file structure, error handling
@@ -0,0 +1,44 @@
1
+ ---
2
+ description: "Build sub-stage: Wire everything together, verify full data flow end-to-end."
3
+ ---
4
+
5
+ # Integration
6
+
7
+ **Role:** Integration Engineer
8
+ **Goal:** Verify the full data flow works end-to-end: UI → API → Service → DB → Response → UI.
9
+
10
+ ## Instructions
11
+
12
+ 1. Trace every code path from user action to database and back
13
+ 2. Verify data flows correctly at each boundary:
14
+ - UI sends correct request to API
15
+ - API validates and calls correct service function
16
+ - Service performs correct DB operations
17
+ - Response flows back through each layer correctly
18
+ 3. Fix any wiring issues (wrong imports, missing props, incorrect types)
19
+ 4. Run the full test suite to confirm nothing broke
20
+ 5. Manually test key flows if possible (dev server)
21
+
22
+ ## Output (append to state.md)
23
+
24
+ ```markdown
25
+ ### Build: Integration
26
+
27
+ **Integration Points Verified:**
28
+ - <flow description>: working | fixed (<what was wrong>)
29
+
30
+ **Issues Fixed:**
31
+ - <issue and fix — or "None">
32
+
33
+ **Full Test Suite:** passing | failing (<details>)
34
+
35
+ **Notes:**
36
+ - <anything discovered during integration>
37
+ ```
38
+
39
+ ## Rules
40
+
41
+ - This is verification, not new development — if you're writing significant new code, something was missed earlier
42
+ - Check TypeScript types across boundaries — mismatches here cause runtime bugs
43
+ - If the dev server is available, actually navigate the flow
44
+ - Document any issues found — they indicate gaps in the Blueprint for future reference
@@ -0,0 +1,41 @@
1
+ ---
2
+ description: "Build sub-stage: Generate and verify database schema changes."
3
+ ---
4
+
5
+ # Migration
6
+
7
+ **Role:** Database Engineer
8
+ **Goal:** Apply schema changes from the Architecture plan.
9
+
10
+ ## Instructions
11
+
12
+ 1. Check the Blueprint/Architecture for data model changes
13
+ 2. If no DB changes needed, output `has_migration: false` and move on
14
+ 3. Otherwise:
15
+ - Update the schema definition files per your project's ORM
16
+ - Generate the migration
17
+ - Run the migration
18
+ - **Verify** the migration actually applied by checking the database directly
19
+ 4. Verify the application still connects to the DB and existing features work
20
+
21
+ ## Output (append to state.md)
22
+
23
+ ```markdown
24
+ ### Build: Migration
25
+
26
+ **Has Migration:** true/false
27
+ **Migration File:** <path>
28
+ **Changes:**
29
+ - <table.column: type — added/modified/removed>
30
+
31
+ **Verification:**
32
+ - Schema check: <pass/fail>
33
+ - App connection: <pass/fail>
34
+ ```
35
+
36
+ ## Rules
37
+
38
+ - Always verify migrations applied — don't trust "success" output alone
39
+ - Use `IF NOT EXISTS` / `IF EXISTS` guards where appropriate
40
+ - If the project uses Drizzle: run `pnpm db:generate` then `pnpm db:migrate`, then verify with psql
41
+ - If migration fails, diagnose and fix before proceeding — don't skip
@@ -0,0 +1,44 @@
1
+ ---
2
+ description: "Build sub-stage: Write failing tests BEFORE implementation (TDD red phase)."
3
+ ---
4
+
5
+ # Red — Write Failing Tests
6
+
7
+ **Role:** Test Author
8
+ **Goal:** Define expected behavior through tests that don't pass yet.
9
+
10
+ ## Instructions
11
+
12
+ 1. Read the Blueprint's test expectations for each layer
13
+ 2. Write tests that describe the expected behavior:
14
+ - Service/business logic tests
15
+ - API endpoint tests (request → expected response)
16
+ - Component tests (render → expected output/behavior)
17
+ 3. Run the tests — **all new tests must fail** (that's the point)
18
+ 4. If any test accidentally passes, you're testing something that already exists — remove or adjust it
19
+
20
+ ## Output (append to state.md)
21
+
22
+ ```markdown
23
+ ### Build: Red (Failing Tests)
24
+
25
+ **Tests Written:**
26
+ - `<test file>`: <what it tests>
27
+ - <test case 1> — FAIL (expected)
28
+ - <test case 2> — FAIL (expected)
29
+
30
+ **Test Output:**
31
+ <summary of test run — X tests, Y failing, Z passing (pre-existing)>
32
+
33
+ **Criteria Coverage:**
34
+ - "<criterion>" → tested by <test name>
35
+ ```
36
+
37
+ ## Rules
38
+
39
+ - Write tests FIRST — this is the "Red" in Red-Green-Refactor
40
+ - Tests should be specific to acceptance criteria
41
+ - Don't test implementation details — test behavior
42
+ - Existing tests must still pass — only NEW tests should fail
43
+ - Match the project's existing test patterns and frameworks
44
+ - If the project has no test framework set up, set one up as part of this step
@@ -0,0 +1,48 @@
1
+ ---
2
+ description: "Build sub-stage: Improve code quality while keeping all tests green (TDD refactor phase)."
3
+ ---
4
+
5
+ # Refactor
6
+
7
+ **Role:** Code Quality Engineer
8
+ **Goal:** Clean up implementation code while maintaining all passing tests.
9
+
10
+ ## Instructions
11
+
12
+ 1. Run full test suite — confirm everything passes before starting
13
+ 2. Review code for:
14
+ - Duplication that should be extracted
15
+ - Unclear naming
16
+ - Functions that are too long
17
+ - Missing error handling at system boundaries
18
+ - Dead code or unused imports
19
+ 3. Refactor incrementally — run tests after each change
20
+ 4. If tests break: **stop immediately**, revert the breaking change
21
+
22
+ ## Output (append to state.md)
23
+
24
+ ```markdown
25
+ ### Build: Refactor
26
+
27
+ **Refactoring Summary:**
28
+ - <what was improved and why>
29
+
30
+ **Test Status:** passing | broken
31
+
32
+ **If broken:**
33
+ - What broke: <description>
34
+ - Reverted: yes/no
35
+ ```
36
+
37
+ ## Outcome Routing
38
+
39
+ - **passing** → All tests green, proceed to Integration
40
+ - **broken** → Tests broke and couldn't recover. Loop back to Core to fix.
41
+
42
+ ## Rules
43
+
44
+ - Tests MUST be green before AND after refactoring
45
+ - Don't add new features during refactor — only improve existing code
46
+ - Don't refactor code you didn't write/modify in this feature
47
+ - If code is already clean, say so and move on — don't refactor for its own sake
48
+ - Small, incremental changes — not a big-bang rewrite
@@ -0,0 +1,42 @@
1
+ ---
2
+ description: "Build sub-stage: Branch creation, dependency installation, scaffolding."
3
+ ---
4
+
5
+ # Setup
6
+
7
+ **Role:** Project Scaffolder
8
+ **Goal:** Prepare the workspace for implementation. No feature code yet.
9
+
10
+ ## Instructions
11
+
12
+ 1. Verify you're in the correct worktree on the feature branch
13
+ 2. Install any new dependencies specified in the Blueprint
14
+ 3. Create new files/directories that the Blueprint calls for (empty scaffolds)
15
+ 4. Update config files if the Blueprint requires it
16
+ 5. Verify the project still builds/compiles cleanly after setup
17
+
18
+ ## Output (append to state.md)
19
+
20
+ ```markdown
21
+ ### Build: Setup
22
+
23
+ **Branch:** feature/<slug> (confirmed)
24
+ **Dependencies Added:**
25
+ - <package> — <why>
26
+
27
+ **Files Created:**
28
+ - `<path>` — <scaffold for what>
29
+
30
+ **Config Changes:**
31
+ - `<file>` — <what changed>
32
+
33
+ **Build Status:** clean | issues (detail)
34
+ ```
35
+
36
+ ## Rules
37
+
38
+ - Do NOT write implementation code — just scaffolding (empty files, directory structure)
39
+ - Do NOT write tests yet — that's Red
40
+ - If the worktree already has setup from a previous loop-back, verify state and skip what's done
41
+ - If dependency installation fails, diagnose the issue — don't proceed with broken dependencies
42
+ - Run the build/compile check to ensure nothing is broken before proceeding
@@ -0,0 +1,51 @@
1
+ ---
2
+ description: "Build sub-stage: Implement UI components, pages, and interactions."
3
+ ---
4
+
5
+ # UI
6
+
7
+ **Role:** Frontend Developer
8
+ **Goal:** Build the user-facing interface per the UX Flow and Blueprint.
9
+
10
+ ## Instructions
11
+
12
+ 1. If no UI changes are needed (from UX Flow: `has_ui_changes: false`), skip this step
13
+ 2. Otherwise, implement:
14
+ - New components per Blueprint/Architecture
15
+ - Page modifications
16
+ - Forms, interactions, navigation
17
+ - Loading, error, and empty states (from UX Flow)
18
+ 3. Follow existing UI patterns from Investigate findings
19
+ 4. Wire components to the API/service layer built in Core
20
+ 5. Run any UI/component tests
21
+
22
+ ## Output (append to state.md)
23
+
24
+ ```markdown
25
+ ### Build: UI
26
+
27
+ **Components Created:**
28
+ - `<ComponentName>` in `<path>` — <purpose>
29
+
30
+ **Components Modified:**
31
+ - `<ComponentName>` in `<path>` — <what changed>
32
+
33
+ **Pages Affected:**
34
+ - `<route/path>` — <what changed>
35
+
36
+ **States Handled:**
37
+ - Loading: yes/no
38
+ - Error: yes/no
39
+ - Empty: yes/no
40
+
41
+ **Notes:**
42
+ - <deviations from UX Flow and why>
43
+ ```
44
+
45
+ ## Rules
46
+
47
+ - Match the project's existing design system / component patterns
48
+ - Every interactive element must have `cursor: pointer`
49
+ - Handle all states from UX Flow — don't skip empty/error states
50
+ - Don't introduce new UI libraries unless the Blueprint calls for it
51
+ - Accessibility basics: labels, keyboard nav, ARIA where needed
@@ -0,0 +1,62 @@
1
+ ---
2
+ name: deploy
3
+ description: "Run the Deploy phase (optional) — 3 sub-stages: Merge, Monitor, Remediate."
4
+ user-invocable: false
5
+ allowed-tools: Bash, Read, Write, Edit, Glob, Grep
6
+ ---
7
+
8
+ You are the **Release Engineer**. Get this PR merged and deployed safely.
9
+
10
+ ## Sub-stages (in order)
11
+
12
+ 1. **Merge** — Get the PR merged safely
13
+ 2. **Monitor** — Watch for deployment issues
14
+ 3. **Remediate** — Handle deployment outcome
15
+
16
+ ## Execution
17
+
18
+ For each sub-stage:
19
+ 1. Read the sub-stage file (e.g., `.claude/skills/deploy/stages/merge.md`)
20
+ 2. Follow its instructions
21
+ 3. Update `.work-kit/state.md` with outputs
22
+ 4. Proceed to next sub-stage
23
+
24
+ ## Key Principle
25
+
26
+ **Verify before acting, monitor after acting.** Never merge with failing CI. Merge is automatic after review approval — no user confirmation needed. Never walk away after merge without checking deployment.
27
+
28
+ ## Recording
29
+
30
+ Update the shared state.md sections:
31
+
32
+ - **`## Decisions`** — Record merge method choice, any rollback decisions.
33
+
34
+ ## This phase is optional
35
+
36
+ If the user says "skip deploy" or the project doesn't have CI/CD, skip this phase entirely. The feature is considered complete after Review/Handoff approval.
37
+
38
+ ## Context Input
39
+
40
+ This phase runs as a **fresh agent**. Read only these sections from `.work-kit/state.md`:
41
+ - `### Review: Final` — ship decision, concerns
42
+ - `### Build: Final` — PR URL, branch
43
+ - `## Criteria` — for final confirmation
44
+
45
+ ## Final Output
46
+
47
+ After all sub-stages are done, append a `### Deploy: Final` section to state.md. This is what **Wrap-up reads**.
48
+
49
+ ```markdown
50
+ ### Deploy: Final
51
+
52
+ **PR:** #<number>
53
+ **Merge status:** merged | fix_needed | abort
54
+ **Deploy status:** deployed | failed | not_applicable
55
+ **Final status:** success | fix_and_redeploy | rolled_back
56
+
57
+ **Summary:** <what happened>
58
+ ```
59
+
60
+ Then:
61
+ - Update state: `**Phase:** deploy (complete)`
62
+ - Commit state: `git add .work-kit/ && git commit -m "work-kit: complete deploy"`
@@ -0,0 +1,59 @@
1
+ ---
2
+ description: "Deploy sub-stage: Get the PR merged safely."
3
+ ---
4
+
5
+ # Merge
6
+
7
+ **Role:** Merge Manager
8
+ **Goal:** Get the PR merged with confidence.
9
+
10
+ ## Instructions
11
+
12
+ 1. Determine the default branch (`main` or `master`):
13
+ ```bash
14
+ git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@' || echo "main"
15
+ ```
16
+ 2. Sync the feature branch with the default branch:
17
+ ```bash
18
+ git fetch origin
19
+ git rebase origin/<default-branch>
20
+ ```
21
+ If rebase conflicts occur, resolve them. If they're non-trivial, report to the user and abort.
22
+ 3. If a PR exists, check CI status — all checks must pass. If CI fails, diagnose and fix (loop back to Build if needed).
23
+ 4. Merge automatically using the project's preferred method (check CONTRIBUTING.md or README; default to squash):
24
+ - If a PR exists: merge via `gh pr merge --squash --delete-branch`
25
+ - If no PR: merge locally:
26
+ ```bash
27
+ git checkout <default-branch>
28
+ git merge --squash feature/<slug>
29
+ git commit -m "feat: <slug>"
30
+ git branch -d feature/<slug>
31
+ ```
32
+
33
+ ## Output (append to state.md)
34
+
35
+ ```markdown
36
+ ### Deploy: Merge
37
+
38
+ **PR:** #<number>
39
+ **CI Status:** passing | failing
40
+ **Conflicts:** none | resolved
41
+ **Merge Method:** squash | merge | rebase
42
+ **Result:** merged | fix_needed | abort
43
+ ```
44
+
45
+ ## Outcome Routing
46
+
47
+ - **merged** → Proceed to Monitor
48
+ - **fix_needed** → Loop back to Build/Core with the specific issue
49
+ - **abort** → Stop work. Report to user.
50
+
51
+ ## Rules
52
+
53
+ - NEVER force push to main/master
54
+ - NEVER merge with failing CI
55
+ - If CI fails, diagnose the issue — don't just retry
56
+ - If rebase conflicts are non-trivial, explain them to the user before resolving
57
+ - Merge is fully autonomous — do NOT ask the user for permission at any step (review phase already approved it)
58
+ - Push, create PR, and merge without stopping for confirmation
59
+ - The entire sync → push → PR → merge flow should complete in one agent pass
@@ -0,0 +1,39 @@
1
+ ---
2
+ description: "Deploy sub-stage: Monitor deployment after merge."
3
+ ---
4
+
5
+ # Monitor
6
+
7
+ **Role:** Deployment Monitor
8
+ **Goal:** Verify the deployment succeeds and the feature works in production.
9
+
10
+ ## Instructions
11
+
12
+ 1. Check CI/CD pipeline status after merge
13
+ 2. Wait for deployment to complete (if applicable)
14
+ 3. Verify health checks pass
15
+ 4. Check for errors in logs (if accessible)
16
+ 5. Verify the feature works as expected in the deployed environment
17
+
18
+ ## Output (append to state.md)
19
+
20
+ ```markdown
21
+ ### Deploy: Monitor
22
+
23
+ **Deploy Status:** deployed | pending | failed | not_applicable
24
+ **Pipeline:** <url or "no CI/CD">
25
+ **Health Checks:** passing | failing | not_applicable
26
+ **Notes:**
27
+ - <observations>
28
+ ```
29
+
30
+ ## Outcome Routing
31
+
32
+ - **deployed** → Proceed to Remediate (success path)
33
+ - **failed** → Proceed to Remediate (failure path)
34
+
35
+ ## Rules
36
+
37
+ - If the project has no CI/CD, mark as `not_applicable` and move on
38
+ - Don't wait indefinitely — if deployment takes more than a few minutes, note it and move on
39
+ - If you can't access production logs/monitoring, say so
@@ -0,0 +1,54 @@
1
+ ---
2
+ description: "Deploy sub-stage: Handle deployment outcome — confirm success or manage failure."
3
+ ---
4
+
5
+ # Remediate
6
+
7
+ **Role:** Incident Responder
8
+ **Goal:** Confirm successful deployment or manage failure.
9
+
10
+ ## Instructions
11
+
12
+ ### If deployment succeeded:
13
+ 1. Confirm the feature is healthy
14
+ 2. Output `final_status: success`
15
+ 3. Done — the feature is shipped
16
+
17
+ ### If deployment failed:
18
+ 1. Analyze the failure:
19
+ - Build failure? Test failure? Runtime error? Config issue?
20
+ 2. Recommend action:
21
+ - **fix_and_redeploy**: Issue is small and fixable → loop back to Build/Core
22
+ - **rolled_back**: Issue is serious → revert the merge, explain to user
23
+
24
+ ## Output (append to state.md)
25
+
26
+ ```markdown
27
+ ### Deploy: Remediate
28
+
29
+ **Final Status:** success | fix_and_redeploy | rolled_back
30
+ **Failure Category:** build | test | deploy | runtime | config | none
31
+ **Summary:**
32
+ - <what happened>
33
+
34
+ **If fix_and_redeploy:**
35
+ - Issue: <what needs to be fixed>
36
+ - Plan: <how to fix>
37
+
38
+ **If rolled_back:**
39
+ - Reason: <why rollback was necessary>
40
+ - Revert: <commit hash or PR>
41
+ ```
42
+
43
+ ## Outcome Routing
44
+
45
+ - **success** → Work is complete. Orchestrator writes work-kit log.
46
+ - **fix_and_redeploy** → Loop back to Build/Core with the fix context
47
+ - **rolled_back** → Work is stopped. Report to user.
48
+
49
+ ## Rules
50
+
51
+ - Don't panic on failure — diagnose first
52
+ - Prefer fix-forward over rollback for small issues
53
+ - Rollback is the right call for data corruption, security issues, or widespread breakage
54
+ - Always explain to the user what happened and why