ai-runtime-kit 0.5.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 (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +307 -0
  3. package/bin/cli.js +52 -0
  4. package/package.json +40 -0
  5. package/runtime/BOOTSTRAP.md +230 -0
  6. package/runtime/CAPABILITIES.md +166 -0
  7. package/runtime/INDEX.md +397 -0
  8. package/runtime/PRIORITIES.md +84 -0
  9. package/runtime/RUNTIME_HEALTH.md +87 -0
  10. package/runtime/RUNTIME_MODE.md +109 -0
  11. package/runtime/RUNTIME_TRANSITIONS.md +141 -0
  12. package/runtime/RUNTIME_VERSION.md +17 -0
  13. package/runtime/SAFETY.md +156 -0
  14. package/runtime/adr/0000-template.md +55 -0
  15. package/runtime/agents/executor.md +19 -0
  16. package/runtime/agents/verifier.md +83 -0
  17. package/runtime/hooks/README.md +163 -0
  18. package/runtime/hooks/_template/HOOK.md +87 -0
  19. package/runtime/hooks/pre-executor/runtime-scoped-preflight/HOOK.md +189 -0
  20. package/runtime/memory/architecture/principles.md +107 -0
  21. package/runtime/memory/engineering/principles.md +102 -0
  22. package/runtime/memory/runtime/context-loading.md +107 -0
  23. package/runtime/plans/_template.md +81 -0
  24. package/runtime/prds/_template.md +73 -0
  25. package/runtime/reviews/_template.md +37 -0
  26. package/runtime/rules/README.md +101 -0
  27. package/runtime/rules/_template/RULE.md +75 -0
  28. package/runtime/skills/README.md +96 -0
  29. package/runtime/skills/_template/SKILL.md +61 -0
  30. package/runtime/specs/_template/spec.md +50 -0
  31. package/runtime/specs/_template-bug-fix/spec.md +120 -0
  32. package/runtime/tasks/TASK_STATUS.md +58 -0
  33. package/runtime/tasks/_template.md +73 -0
  34. package/runtime/workflows/branching.md +128 -0
  35. package/runtime/workflows/bug-fix.md +169 -0
  36. package/runtime/workflows/feature-development.md +238 -0
  37. package/src/diff.js +81 -0
  38. package/src/git.js +38 -0
  39. package/src/init.js +166 -0
  40. package/src/prompt.js +17 -0
  41. package/src/snapshot.js +84 -0
  42. package/src/templates.js +96 -0
  43. package/src/upgrade.js +179 -0
  44. package/src/version.js +42 -0
@@ -0,0 +1,120 @@
1
+ # Bug Fix Spec: <Short Name>
2
+
3
+ ## Status
4
+
5
+ DRAFT
6
+ <!-- Allowed: DRAFT | APPROVED | REJECTED | SUPERSEDED.
7
+ See .ai/runtime/workflows/bug-fix.md for lifecycle rules. -->
8
+
9
+ ## 1. Goal
10
+
11
+ Describe the corrective outcome in one paragraph. Focus on what
12
+ behavior changes, not how. Reference the affected user or system
13
+ behavior, not the implementation.
14
+
15
+ ## 2. Scope
16
+
17
+ <!-- If any in-scope path is under .ai/runtime/**, this is a
18
+ runtime-scoped governance change. Flag it explicitly and
19
+ follow .ai/runtime/SAFETY.md § Runtime Tree Protection. -->
20
+
21
+ ### In scope
22
+
23
+ -
24
+
25
+ ### Out of scope
26
+
27
+ -
28
+
29
+ ## 3. Root Cause
30
+
31
+ Name the underlying defect, not the symptom.
32
+
33
+ - **Cause:** <smallest accurate description of why the bug occurred>
34
+ - **Origin:** <commit hash, spec path, or design decision that
35
+ introduced the cause; "unknown" if not traceable>
36
+ - **Locality:** local | systemic
37
+ <!-- Systemic causes require a follow-up spec; link in §10. -->
38
+
39
+ If the root cause is genuinely unknown after investigation, write
40
+ "Unknown — best hypothesis: <X>" and state what evidence would
41
+ confirm or refute it.
42
+
43
+ ## 4. Reproduction
44
+
45
+ Minimum steps a reviewer can run to observe the bug BEFORE the fix.
46
+
47
+ ### Preconditions
48
+
49
+ -
50
+
51
+ ### Steps
52
+
53
+ ```bash
54
+ # exact commands or HTTP calls
55
+ ```
56
+
57
+ ### Observed (wrong) output
58
+
59
+ ```
60
+ ```
61
+
62
+ ### Expected (correct) output
63
+
64
+ ```
65
+ ```
66
+
67
+ If the bug only reproduces in production, document the
68
+ trace/log/event ID and the time window here, and state explicitly
69
+ that local reproduction is not available.
70
+
71
+ ## 5. Regression Test
72
+
73
+ The test that fails before the fix and passes after.
74
+
75
+ - **File:** `<path>` (new | modified)
76
+ - **Test name(s):** `<test name>`
77
+ - **Catching assertion:** <one line: which assertion fails before
78
+ the fix>
79
+ - **Red proof:** <paste failing output OR link the commit that
80
+ demonstrates red state>
81
+
82
+ Exception: pure documentation fixes (no behavior change) may write
83
+ "No regression test — documentation fix; §Acceptance Criteria greps
84
+ serve as the regression check".
85
+
86
+ ## 6. Fix Strategy
87
+
88
+ One paragraph. The minimal change that addresses §3 Root Cause,
89
+ not the symptom.
90
+
91
+ ## 7. Risks
92
+
93
+ -
94
+
95
+ ## 8. Acceptance Criteria
96
+
97
+ - Regression test from §5 is present in the diff and passes.
98
+ - §4 Reproduction steps no longer reproduce the bug after the fix
99
+ is applied.
100
+ - `npm run verify` passes.
101
+
102
+ ## 9. Verification Commands
103
+
104
+ ```bash
105
+ npm run verify
106
+ # plus any spec-specific assertions
107
+ ```
108
+
109
+ ## 10. Related Specs
110
+
111
+ -
112
+
113
+ ## 11. Related ADRs
114
+
115
+ -
116
+
117
+ ## 12. Rollback Plan
118
+
119
+ 1.
120
+ 2.
@@ -0,0 +1,58 @@
1
+ # Task Status System
2
+
3
+ ## Purpose
4
+
5
+ Define task lifecycle states for local AI engineering workflow.
6
+
7
+ ## Status Values
8
+
9
+ ### TODO
10
+
11
+ Task is defined but not started.
12
+
13
+ ### IN_PROGRESS
14
+
15
+ Task is currently being implemented.
16
+
17
+ ### BLOCKED
18
+
19
+ Task cannot proceed because it needs clarification, dependency completion, or external input.
20
+
21
+ ### IN_REVIEW
22
+
23
+ Implementation is complete and waiting for review.
24
+
25
+ ### DONE
26
+
27
+ Task is implemented, verified, reviewed if needed, and committed.
28
+
29
+ ## Status Rules
30
+
31
+ - New tasks start as TODO.
32
+ - Executor changes TODO to IN_PROGRESS before implementation.
33
+ - Executor changes IN_PROGRESS to IN_REVIEW after implementation and verification.
34
+ - Reviewer changes IN_REVIEW to DONE after approval.
35
+ - If verification fails, task remains IN_PROGRESS.
36
+ - If scope is unclear, task becomes BLOCKED.
37
+
38
+ ## Required Task Fields
39
+
40
+ Each task should include:
41
+
42
+ - Goal
43
+ - Related Spec
44
+ - Related Plan
45
+ - Dependencies
46
+ - Files Likely Affected
47
+ - Constraints
48
+ - Acceptance Criteria
49
+ - Verification
50
+ - Status
51
+
52
+ ## Dependency Rules
53
+
54
+ - A task cannot start until all dependencies are DONE.
55
+ - BLOCKED tasks must explain the blocking dependency.
56
+ - Parallelizable tasks may run independently if they do not modify overlapping files.
57
+
58
+ <!-- Active task-set tables live in .ai/project/tasks/TASK_STATUS.md. -->
@@ -0,0 +1,73 @@
1
+ # Task: <TASK_NAME>
2
+
3
+ ## Goal
4
+
5
+ Describe the specific engineering goal.
6
+
7
+ ---
8
+
9
+ ## Related Spec
10
+
11
+ -
12
+
13
+ ---
14
+
15
+ ## Dependencies
16
+
17
+ -
18
+
19
+ ---
20
+
21
+ ## Blocks
22
+
23
+ -
24
+
25
+ ---
26
+
27
+ ## Parallelizable With
28
+
29
+ -
30
+
31
+ ---
32
+
33
+ ## Files Likely Affected
34
+
35
+ -
36
+
37
+ ---
38
+
39
+ ## Constraints
40
+
41
+ -
42
+
43
+ ---
44
+
45
+ ## Acceptance Criteria
46
+
47
+ -
48
+
49
+ ---
50
+
51
+ ## Verification
52
+
53
+ ```bash
54
+ npm run verify
55
+ ```
56
+
57
+ ---
58
+
59
+ ## Status
60
+
61
+ TODO
62
+
63
+ ## Owner
64
+
65
+ executor
66
+
67
+ ## Blocked By
68
+
69
+ None.
70
+
71
+ ## Review Required
72
+
73
+ Yes
@@ -0,0 +1,128 @@
1
+ # Branching Workflow
2
+
3
+ ## Purpose
4
+
5
+ Define when feature work must be done on a branch and how branches map onto the spec / plan / task / ADR lifecycle.
6
+
7
+ This workflow exists because `feature-development.md` previously specified commit conventions but said nothing about branching. The `user-system` feature exposed the gap: roadmap-scale features need long-lived branches and per-spec sub-branches to keep `main` deployable and reviewable.
8
+
9
+ ---
10
+
11
+ ## Branching Rules
12
+
13
+ Pick the smallest tier that fits the work.
14
+
15
+ ### Tier 1 — Commit directly on `main`
16
+
17
+ Allowed for:
18
+
19
+ - ~20 lines of additive code or fewer
20
+ - no new dependencies
21
+ - no public API surface change beyond a single new additive route or field
22
+ - no ADR required
23
+ - no contract change beyond an additive endpoint section
24
+ - runtime mode does not change
25
+
26
+ Examples: `feat(readyz)`, `docs: ...`, `chore: ...` that touches only runtime metadata.
27
+
28
+ ### Tier 2 — Single feature branch
29
+
30
+ Required for:
31
+
32
+ - any spec whose plan has more than one task
33
+ - any spec that introduces a new dependency
34
+ - any spec that changes existing response shapes
35
+ - any spec that requires an ADR (see Tier 3 if the ADR itself introduces architecture)
36
+ - any refactor that touches more than one module
37
+
38
+ Branch naming:
39
+
40
+ ```
41
+ feat/<spec-id>
42
+ fix/<spec-id>
43
+ refactor/<spec-id>
44
+ chore/runtime-<topic>
45
+ ```
46
+
47
+ `<spec-id>` is the spec directory name without the date prefix when unambiguous, or the full spec directory name when ambiguous.
48
+
49
+ Workflow:
50
+
51
+ 1. Open the branch from latest `main`.
52
+ 2. Commit per task or per coherent unit (executor + verifier + reviewer chain stays intact).
53
+ 3. Merge to `main` only when all of the following are DONE: tasks, plan, review file, contract updates, `npm run verify`.
54
+ 4. Use `--no-ff` merges so the feature boundary is preserved.
55
+
56
+ ### Tier 3 — Roadmap feature with sub-spec branches
57
+
58
+ Required for any **roadmap spec** (a spec that decomposes into multiple child specs).
59
+
60
+ Structure:
61
+
62
+ ```
63
+ main
64
+ └── feat/<roadmap-id> ← long-lived branch
65
+ ├── feat/<roadmap-id>--<sub-spec-1> ← sub-branch, merges into long-lived
66
+ ├── feat/<roadmap-id>--<sub-spec-2>
67
+ └── feat/<roadmap-id>--<sub-spec-N>
68
+ ```
69
+
70
+ **Sub-branch naming uses `--` (double dash) as the separator between the roadmap id and the sub-spec id**, not `/`. Git stores refs hierarchically: once `feat/<roadmap-id>` exists as a branch (a file under `.git/refs/heads/`), creating `feat/<roadmap-id>/<sub>` would require the same name to also be a directory, which git rejects with `cannot lock ref … exists`. The `--` separator keeps the visual hierarchy without colliding with the ref store.
71
+
72
+ Workflow:
73
+
74
+ 1. Open `feat/<roadmap-id>` from latest `main`. The roadmap spec, the ADRs that justify the roadmap, and the roadmap plan land here as the first commit.
75
+ 2. For each child spec, open `feat/<roadmap-id>--<sub-spec>` from the long-lived branch.
76
+ 3. Each child sub-branch follows the full Spec → Plan → Tasks → Execute → Verify → Review → Commit lifecycle from `feature-development.md`.
77
+ 4. Merge child branches into the long-lived branch with `--no-ff`. The long-lived branch must always pass `npm run verify`.
78
+ 5. Merge the long-lived branch into `main` only when every child spec is DONE and the roadmap spec itself is marked DONE (or SUPERSEDED if scope evolved).
79
+ 6. Rebase the long-lived branch on `main` if `main` advances during the roadmap, to keep history linear.
80
+
81
+ ---
82
+
83
+ ## Governance Rule Branches
84
+
85
+ Changes to `.ai/runtime/**` files (mode, health, workflows, capabilities, safety, priorities, lifecycle, agents, commands, templates, generic memory) are governance changes per `SAFETY.md` § Runtime Tree Protection. These must:
86
+
87
+ - live on a branch named `chore/runtime-<topic>`
88
+ - include a review file under `.ai/project/reviews/`
89
+ - be authorized by a spec under `.ai/project/specs/YYYY-MM-DD-<name>/` whose §2 Scope explicitly lists the touched `.ai/runtime/**` paths
90
+ - if introducing a new constraint, land on `main` BEFORE any feature work that relies on the new constraint
91
+ - never be combined with feature code in the same commit
92
+
93
+ Exception: trivial typo or wording fixes inside a single doc file may be Tier 1.
94
+
95
+ ---
96
+
97
+ ## Branch Hygiene
98
+
99
+ - Never force-push `main`.
100
+ - Never force-push a long-lived roadmap branch shared with other contributors.
101
+ - Force-push within an unmerged single-author feature branch is allowed if it improves review.
102
+ - Do not skip pre-commit or pre-push hooks unless explicitly authorized.
103
+ - Delete sub-spec branches after merge into the long-lived branch.
104
+ - Delete feature branches after merge into `main`.
105
+
106
+ ---
107
+
108
+ ## Mapping to runtime artifacts
109
+
110
+ | Branch tier | Required artifacts before merge |
111
+ |---|---|
112
+ | Tier 1 | conventional commit; updated task/plan/spec statuses if applicable |
113
+ | Tier 2 | spec APPROVED · plan DONE · all tasks DONE · review file · contracts updated · `npm run verify` passes |
114
+ | Tier 3 — sub-branch | same as Tier 2 |
115
+ | Tier 3 — long-lived | every child spec DONE; roadmap spec DONE or SUPERSEDED; aggregated review file optional |
116
+ | Governance branch | review file |
117
+
118
+ ---
119
+
120
+ ## Verification
121
+
122
+ `npm run verify` must pass:
123
+
124
+ - before merging any branch into `main`
125
+ - before merging any sub-spec branch into the long-lived roadmap branch
126
+ - on the long-lived branch after every sub-spec merge
127
+
128
+ If verification fails on the long-lived branch after a sub-spec merge, runtime health transitions to YELLOW or RED per `RUNTIME_TRANSITIONS.md`, and no further sub-spec merges are allowed until recovery.
@@ -0,0 +1,169 @@
1
+ # Bug Fix Workflow
2
+
3
+ ## Purpose
4
+
5
+ Use this workflow to ship one corrective change safely with AI
6
+ assistance. A "bug fix" here means a change whose primary intent is
7
+ to bring observed behavior in line with documented or expected
8
+ behavior, not to extend functionality.
9
+
10
+ ## When this workflow applies
11
+
12
+ This workflow applies when ANY of the following is true:
13
+
14
+ - the spec directory is named `YYYY-MM-DD-fix-<name>/`,
15
+ - the spec includes a `## Root Cause` section,
16
+ - the change is committed with a `fix:` prefix per
17
+ `feature-development.md` § Commit conventions.
18
+
19
+ When in doubt, prefer this workflow over `feature-development.md`.
20
+ Production incidents (`INCIDENT` runtime mode) are out of scope;
21
+ follow `SAFETY.md` for those.
22
+
23
+ ## Roles
24
+
25
+ Same as `feature-development.md`:
26
+
27
+ - ChatGPT: define, design, review, summarize
28
+ - Claude Code: implement, refactor, verify
29
+
30
+ ## Spec lifecycle
31
+
32
+ Same lifecycle as feature specs (`DRAFT → APPROVED → REJECTED →
33
+ SUPERSEDED`). Use the bug-fix-specific template at
34
+ `.ai/runtime/specs/_template-bug-fix/spec.md`, which augments the
35
+ feature spec shape with three required sections (see §Required spec
36
+ sections below).
37
+
38
+ ## Required spec sections
39
+
40
+ A bug-fix spec MUST include all sections of the feature spec
41
+ template, PLUS the following three sections:
42
+
43
+ ### `## Root Cause`
44
+
45
+ Name the underlying defect, not the symptom. Required content:
46
+
47
+ - the smallest accurate description of why the bug occurred (e.g.
48
+ "validator middleware ran after the route handler that threw"),
49
+ - the commit, spec, or design decision that introduced the cause
50
+ if knowable (link the commit hash or spec path),
51
+ - whether the cause is local (one module) or systemic (pattern
52
+ repeated across modules) — systemic causes require a follow-up
53
+ spec and must be linked in `## 10. Related Specs`.
54
+
55
+ If the root cause is genuinely unknown after investigation, write
56
+ "Unknown — best hypothesis: <X>" and explain what evidence would
57
+ confirm or refute it. Do not skip the section.
58
+
59
+ ### `## Reproduction`
60
+
61
+ The minimal steps a reviewer can run to observe the bug BEFORE the
62
+ fix is applied. Required content:
63
+
64
+ - preconditions (env vars, fixtures, branch),
65
+ - exact commands or HTTP calls,
66
+ - the observed (wrong) output,
67
+ - the expected (correct) output.
68
+
69
+ If the bug only reproduces in production, document the
70
+ trace/log/event ID and the time window instead of commands, and
71
+ state explicitly that local reproduction is not available.
72
+
73
+ ### `## Regression Test`
74
+
75
+ The test that fails before the fix and passes after. Required
76
+ content:
77
+
78
+ - the test file path (new or modified),
79
+ - the test name(s) added,
80
+ - a one-line statement of which assertion catches the bug,
81
+ - proof that the test was red before the fix (paste the failing
82
+ output, or note the commit that demonstrates the red state).
83
+
84
+ Exception: pure documentation fixes (no behavior change) may state
85
+ "No regression test — documentation fix; spec §Acceptance Criteria
86
+ greps serve as the regression check" and rely on the spec's grep
87
+ assertions instead.
88
+
89
+ ## Workflow
90
+
91
+ ### 1. Define spec
92
+
93
+ Copy `.ai/runtime/specs/_template-bug-fix/spec.md` into
94
+ `.ai/project/specs/YYYY-MM-DD-fix-<name>/spec.md`. Fill in every
95
+ required section, including the three above.
96
+
97
+ Pick the spec name to describe the cause when possible, not the
98
+ symptom (`fix-validator-after-handler`, not `fix-500-on-login`).
99
+
100
+ ### 2. Plan
101
+
102
+ Same as `feature-development.md` § Workflow. Bug-fix plans are
103
+ typically smaller (1–2 tasks) but the structure is identical.
104
+
105
+ ### 3. Execute with Claude Code
106
+
107
+ Claude Code must read the same context as feature work
108
+ (`feature-development.md` § Execute), plus:
109
+
110
+ - the spec's `## Root Cause` section (drives the fix shape),
111
+ - the spec's `## Reproduction` (drives the regression test shape),
112
+ - the spec's `## Regression Test` (drives the test file edit).
113
+
114
+ Executor order:
115
+
116
+ 1. Write the regression test first; confirm it fails.
117
+ 2. Apply the minimal fix that addresses the named root cause.
118
+ 3. Re-run the test; confirm it passes.
119
+ 4. Run `npm run verify`.
120
+
121
+ This order is mandatory unless the spec's `## Regression Test`
122
+ invokes the documentation exception above.
123
+
124
+ ### 4. Verify
125
+
126
+ Same as `feature-development.md` § Verify, plus:
127
+
128
+ - the new regression test must be present in the diff and passing,
129
+ - the spec's `## Reproduction` steps must no longer reproduce the
130
+ bug (reviewer confirms by re-running them post-fix).
131
+
132
+ ### 5. Review
133
+
134
+ Same as `feature-development.md` § Review. The review file MUST
135
+ explicitly state whether the three required sections (Root Cause,
136
+ Reproduction, Regression Test) are present and adequate.
137
+
138
+ ### 6. Commit
139
+
140
+ Use `fix:` as the conventional commit prefix.
141
+
142
+ ## Definition of done
143
+
144
+ A bug fix is done only when:
145
+
146
+ - spec exists with all three required sections filled,
147
+ - regression test exists and passes,
148
+ - fix is implemented,
149
+ - `npm run verify` passes,
150
+ - review exists and confirms the three required sections,
151
+ - changes are committed with `fix:` prefix.
152
+
153
+ ## Branching
154
+
155
+ Same as `branching.md`. No bug-fix-specific tier; the existing Tier
156
+ 1 / Tier 2 / Tier 3 / Governance rules apply unchanged.
157
+
158
+ ## Relationship to feature-development.md
159
+
160
+ This workflow is a strict superset of `feature-development.md` for
161
+ the spec/plan/task/review pipeline. Differences are limited to:
162
+
163
+ - spec template (bug-fix template adds three required sections),
164
+ - executor order (regression test first),
165
+ - review file must explicitly check the three required sections,
166
+ - commit prefix (`fix:` instead of `feat:`).
167
+
168
+ For any topic not covered here, defer to
169
+ `feature-development.md`.