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.
- package/LICENSE +21 -0
- package/README.md +307 -0
- package/bin/cli.js +52 -0
- package/package.json +40 -0
- package/runtime/BOOTSTRAP.md +230 -0
- package/runtime/CAPABILITIES.md +166 -0
- package/runtime/INDEX.md +397 -0
- package/runtime/PRIORITIES.md +84 -0
- package/runtime/RUNTIME_HEALTH.md +87 -0
- package/runtime/RUNTIME_MODE.md +109 -0
- package/runtime/RUNTIME_TRANSITIONS.md +141 -0
- package/runtime/RUNTIME_VERSION.md +17 -0
- package/runtime/SAFETY.md +156 -0
- package/runtime/adr/0000-template.md +55 -0
- package/runtime/agents/executor.md +19 -0
- package/runtime/agents/verifier.md +83 -0
- package/runtime/hooks/README.md +163 -0
- package/runtime/hooks/_template/HOOK.md +87 -0
- package/runtime/hooks/pre-executor/runtime-scoped-preflight/HOOK.md +189 -0
- package/runtime/memory/architecture/principles.md +107 -0
- package/runtime/memory/engineering/principles.md +102 -0
- package/runtime/memory/runtime/context-loading.md +107 -0
- package/runtime/plans/_template.md +81 -0
- package/runtime/prds/_template.md +73 -0
- package/runtime/reviews/_template.md +37 -0
- package/runtime/rules/README.md +101 -0
- package/runtime/rules/_template/RULE.md +75 -0
- package/runtime/skills/README.md +96 -0
- package/runtime/skills/_template/SKILL.md +61 -0
- package/runtime/specs/_template/spec.md +50 -0
- package/runtime/specs/_template-bug-fix/spec.md +120 -0
- package/runtime/tasks/TASK_STATUS.md +58 -0
- package/runtime/tasks/_template.md +73 -0
- package/runtime/workflows/branching.md +128 -0
- package/runtime/workflows/bug-fix.md +169 -0
- package/runtime/workflows/feature-development.md +238 -0
- package/src/diff.js +81 -0
- package/src/git.js +38 -0
- package/src/init.js +166 -0
- package/src/prompt.js +17 -0
- package/src/snapshot.js +84 -0
- package/src/templates.js +96 -0
- package/src/upgrade.js +179 -0
- package/src/version.js +42 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# Runtime Hooks
|
|
2
|
+
|
|
3
|
+
This directory hosts **agent-pipeline transition hooks**. Each hook
|
|
4
|
+
is a single `HOOK.md` describing one boundary contract between two
|
|
5
|
+
agents in the recommended agent flow
|
|
6
|
+
(`INDEX.md` § "Recommended Agent Flow").
|
|
7
|
+
|
|
8
|
+
## Hooks vs Skills vs Rules vs Events
|
|
9
|
+
|
|
10
|
+
| | Skill | Rule | Event | Hook |
|
|
11
|
+
| --- | --- | --- | --- | --- |
|
|
12
|
+
| Trigger | Task type | File scope | Runtime state change | Agent transition |
|
|
13
|
+
| Loaded when | Task matches the skill's purpose | Task touches files in scope | Something happened | Pipeline reaches a transition matching `appliesWhen` |
|
|
14
|
+
| Tense | "How to do X" | "Always do X in scope Y" | "X just happened" | "Before/after agent N runs, do X if condition" |
|
|
15
|
+
| Example | "How to add an Express endpoint" | "Never use `any` in `.ts` files" | `VERIFICATION_FAILED` | "Before Executor starts on a runtime-scoped spec, snapshot baseline tests" |
|
|
16
|
+
|
|
17
|
+
If a guideline is task-conditional, it's a `skill`.
|
|
18
|
+
If it applies whenever code in a language is touched, it's a `rule`.
|
|
19
|
+
If it's a post-fact narration of state change, it's an `event`.
|
|
20
|
+
If it gates the handoff between two agents, it's a `hook`.
|
|
21
|
+
|
|
22
|
+
## Hooks vs Git hooks
|
|
23
|
+
|
|
24
|
+
This directory is **unrelated** to the Husky pre-commit / pre-push /
|
|
25
|
+
commit-msg hooks documented in `ADR-0006` and
|
|
26
|
+
`.ai/project/memory/core/tech-stack.md`. Those are git-level
|
|
27
|
+
toolchain hooks; these are agent-pipeline orchestration hooks. The
|
|
28
|
+
two systems do not interact.
|
|
29
|
+
|
|
30
|
+
## Directory layout
|
|
31
|
+
|
|
32
|
+
```txt
|
|
33
|
+
.ai/runtime/hooks/
|
|
34
|
+
├── _template/
|
|
35
|
+
│ └── HOOK.md # template — copy from here
|
|
36
|
+
├── pre-architect/ <hook-name>/HOOK.md
|
|
37
|
+
├── post-architect/ <hook-name>/HOOK.md
|
|
38
|
+
├── pre-planner/ <hook-name>/HOOK.md
|
|
39
|
+
├── post-planner/ <hook-name>/HOOK.md
|
|
40
|
+
├── pre-executor/ <hook-name>/HOOK.md
|
|
41
|
+
├── post-executor/ <hook-name>/HOOK.md
|
|
42
|
+
├── pre-verifier/ <hook-name>/HOOK.md
|
|
43
|
+
├── post-verifier/ <hook-name>/HOOK.md
|
|
44
|
+
├── pre-reviewer/ <hook-name>/HOOK.md
|
|
45
|
+
└── post-reviewer/ <hook-name>/HOOK.md
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Naming:
|
|
49
|
+
|
|
50
|
+
- `<hook-name>` is a short noun phrase in lowercase kebab-case
|
|
51
|
+
(`baseline-snapshot`, `contract-change-followup`,
|
|
52
|
+
`runtime-edit-followup`).
|
|
53
|
+
- One hook per directory; one `HOOK.md` per hook. If a transition
|
|
54
|
+
has multiple distinct concerns, split into multiple hook
|
|
55
|
+
directories under the same `<phase>-<agent>/` parent.
|
|
56
|
+
- Phase-agent directories are created lazily — do not pre-seed empty
|
|
57
|
+
directories.
|
|
58
|
+
|
|
59
|
+
## Trigger taxonomy
|
|
60
|
+
|
|
61
|
+
A hook attaches to exactly one transition. Transitions are:
|
|
62
|
+
|
|
63
|
+
| Phase | Agent | Meaning |
|
|
64
|
+
| --- | --- | --- |
|
|
65
|
+
| `pre` | architect | Before spec drafting begins |
|
|
66
|
+
| `post` | architect | After spec is drafted but before plan |
|
|
67
|
+
| `pre` | planner | Before task graph is produced |
|
|
68
|
+
| `post` | planner | After plan exists but before execution |
|
|
69
|
+
| `pre` | executor | Before code edits begin |
|
|
70
|
+
| `post` | executor | After edits but before verification |
|
|
71
|
+
| `pre` | verifier | Before verification commands run |
|
|
72
|
+
| `post` | verifier | After verification result is known |
|
|
73
|
+
| `pre` | reviewer | Before review file is written |
|
|
74
|
+
| `post` | reviewer | After review file is written |
|
|
75
|
+
|
|
76
|
+
There are no hooks for `INCIDENT` or `GOVERNANCE_RECOVERY` agents
|
|
77
|
+
because those modes follow `SAFETY.md` directly and bypass the
|
|
78
|
+
recommended flow; introducing hooks for them is out of scope here.
|
|
79
|
+
|
|
80
|
+
## Gate behavior
|
|
81
|
+
|
|
82
|
+
Three levels, in increasing strictness:
|
|
83
|
+
|
|
84
|
+
- **ADVISORY** — the hook's action runs; its outcome is logged in
|
|
85
|
+
the review file. The transition proceeds regardless.
|
|
86
|
+
- **GATE** — if the action fails or is skipped, the downstream
|
|
87
|
+
agent MUST NOT start. The blocking condition must be recorded in
|
|
88
|
+
the review file (or, if review is downstream of this hook, in the
|
|
89
|
+
task/spec file).
|
|
90
|
+
- **MUTATION** — the action produces a required artifact (file,
|
|
91
|
+
status update, log). The transition is blocked until the artifact
|
|
92
|
+
exists. The artifact path is named in the hook's `## Outputs`
|
|
93
|
+
section.
|
|
94
|
+
|
|
95
|
+
Pick the weakest level that captures the contract. Inflation to GATE
|
|
96
|
+
or MUTATION requires a documented incident or contract risk.
|
|
97
|
+
|
|
98
|
+
## When to create a hook
|
|
99
|
+
|
|
100
|
+
A new hook is worth authoring when ANY of:
|
|
101
|
+
|
|
102
|
+
- a review has caught the same boundary-handoff mistake across 2+
|
|
103
|
+
specs (e.g. "Executor began before Verifier captured a baseline"),
|
|
104
|
+
- a runtime-protection rule (`SAFETY.md`) needs a checkable handoff
|
|
105
|
+
contract to actually be observable in practice,
|
|
106
|
+
- a recurring agent-orchestration pattern emerges that is too
|
|
107
|
+
structural to live in a workflow file's prose.
|
|
108
|
+
|
|
109
|
+
Do NOT create a hook for:
|
|
110
|
+
|
|
111
|
+
- a one-off boundary concern (note it in the spec's §11 Resolved
|
|
112
|
+
Decisions instead),
|
|
113
|
+
- something a workflow file's prose already enforces clearly
|
|
114
|
+
(`feature-development.md` § "Verify"),
|
|
115
|
+
- a project-specific convention (those belong in
|
|
116
|
+
`.ai/project/memory/`),
|
|
117
|
+
- a code-pattern concern (that's a skill or rule).
|
|
118
|
+
|
|
119
|
+
## How hooks get loaded
|
|
120
|
+
|
|
121
|
+
Three loading paths, mirroring the skills system:
|
|
122
|
+
|
|
123
|
+
1. **Workflow file** — `.ai/runtime/workflows/feature-development.md`
|
|
124
|
+
tells each agent step to load relevant hooks for its phase.
|
|
125
|
+
Strongest current path.
|
|
126
|
+
2. **Context-loading rule** —
|
|
127
|
+
`.ai/runtime/memory/runtime/context-loading.md` lists hooks under
|
|
128
|
+
Feature Implementation and Review.
|
|
129
|
+
3. **Frontmatter signals (declarative)** — the hook's
|
|
130
|
+
`appliesWhen.pathPatterns` / `specSignals` / `runtimeModes` are
|
|
131
|
+
read by the agent during context-loading to judge applicability.
|
|
132
|
+
No runtime tooling reads or enforces these; they exist to help
|
|
133
|
+
agents filter. Weakest path.
|
|
134
|
+
|
|
135
|
+
A spec whose work falls into a hook's `appliesWhen` does NOT need to
|
|
136
|
+
reference the hook in §2 Scope explicitly — context-loading paths 1
|
|
137
|
+
and 2 handle discovery. A spec that AUTHORS or MODIFIES a hook MUST
|
|
138
|
+
list the hook's path in §2 Scope (runtime-scoped governance per
|
|
139
|
+
`SAFETY.md` § Runtime Tree Protection).
|
|
140
|
+
|
|
141
|
+
## Authoring a new hook — the workflow
|
|
142
|
+
|
|
143
|
+
1. **Open a spec** under `.ai/project/specs/YYYY-MM-DD-<name>/` whose
|
|
144
|
+
§2 Scope lists the new hook's path. Runtime-scoped governance
|
|
145
|
+
per `SAFETY.md` § Runtime Tree Protection.
|
|
146
|
+
2. **Copy the template**: `cp .ai/runtime/hooks/_template/HOOK.md
|
|
147
|
+
.ai/runtime/hooks/<phase>-<agent>/<hook-name>/HOOK.md`. Create
|
|
148
|
+
parent dirs.
|
|
149
|
+
3. **Fill in frontmatter and body sections.** Pick the weakest gate
|
|
150
|
+
level that captures the contract. Cite a concrete "why" with at
|
|
151
|
+
least one incident or anti-pattern.
|
|
152
|
+
4. **Register the hook** by adding a bullet to `INDEX.md`'s
|
|
153
|
+
`## Hooks` section.
|
|
154
|
+
5. **Verify**: `npm run verify`.
|
|
155
|
+
6. **Review**: standard review file under
|
|
156
|
+
`.ai/project/reviews/`.
|
|
157
|
+
|
|
158
|
+
## Modifying an existing hook
|
|
159
|
+
|
|
160
|
+
Same as authoring: a runtime-scoped spec, with §2 Scope listing the
|
|
161
|
+
modified `HOOK.md` path. If the modification changes gate behavior
|
|
162
|
+
(e.g. ADVISORY → GATE), the spec must list which in-flight specs
|
|
163
|
+
would have been blocked by the new gate and budget for that impact.
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Hook template. Copy this file to
|
|
3
|
+
`.ai/runtime/hooks/<phase>-<agent>/<hook-name>/HOOK.md` and fill it
|
|
4
|
+
in. <phase> is `pre` or `post`; <agent> is one of architect /
|
|
5
|
+
planner / executor / verifier / reviewer.
|
|
6
|
+
|
|
7
|
+
The YAML frontmatter below is DECLARATIVE: no runtime tool reads or
|
|
8
|
+
enforces it. Agents read it during context-loading to judge whether
|
|
9
|
+
this hook applies. See `.ai/runtime/hooks/README.md` § "How hooks
|
|
10
|
+
get loaded" for the loading paths.
|
|
11
|
+
-->
|
|
12
|
+
---
|
|
13
|
+
name: <hook-name-kebab-case>
|
|
14
|
+
description: <one sentence: which transition this attaches to and what it enforces>
|
|
15
|
+
metadata:
|
|
16
|
+
phase: pre | post
|
|
17
|
+
agent: architect | planner | executor | verifier | reviewer
|
|
18
|
+
gate: ADVISORY | GATE | MUTATION
|
|
19
|
+
appliesWhen:
|
|
20
|
+
pathPatterns:
|
|
21
|
+
- "<glob: e.g. .ai/runtime/**>"
|
|
22
|
+
specSignals:
|
|
23
|
+
- "<phrase that appears in spec §2 Scope, e.g. 'contract change'>"
|
|
24
|
+
runtimeModes:
|
|
25
|
+
- "<FEATURE_DEVELOPMENT | REFACTOR | INCIDENT | GOVERNANCE_RECOVERY>"
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
# <Hook Name>
|
|
29
|
+
|
|
30
|
+
<One paragraph stating the transition contract: at this transition,
|
|
31
|
+
under these conditions, this action must happen.>
|
|
32
|
+
|
|
33
|
+
## Trigger
|
|
34
|
+
|
|
35
|
+
- **Phase**: pre | post
|
|
36
|
+
- **Agent transition**: e.g. `Planner → Executor` (for `pre-executor`)
|
|
37
|
+
- **Applies when**: <condition that activates the hook — e.g. spec
|
|
38
|
+
§2 Scope lists `.ai/runtime/**`, or the diff touches a contract>
|
|
39
|
+
|
|
40
|
+
## Action
|
|
41
|
+
|
|
42
|
+
What the activating agent (or operator) must do when the hook fires.
|
|
43
|
+
Imperative form. Concrete enough to be checkable.
|
|
44
|
+
|
|
45
|
+
## Gate behavior
|
|
46
|
+
|
|
47
|
+
One of:
|
|
48
|
+
|
|
49
|
+
- **ADVISORY** — log the action's outcome; do not block the transition.
|
|
50
|
+
- **GATE** — if the action fails or is skipped, the transition is
|
|
51
|
+
blocked. The downstream agent MUST NOT start.
|
|
52
|
+
- **MUTATION** — the action produces a required artifact (file, log,
|
|
53
|
+
status update). The transition is blocked until the artifact exists.
|
|
54
|
+
|
|
55
|
+
State which one and why.
|
|
56
|
+
|
|
57
|
+
## Inputs
|
|
58
|
+
|
|
59
|
+
What the hook reads: spec sections, prior agent outputs, git diff,
|
|
60
|
+
contracts, etc.
|
|
61
|
+
|
|
62
|
+
## Outputs
|
|
63
|
+
|
|
64
|
+
What the hook produces: artifact path, status field update, log line,
|
|
65
|
+
or "advisory note only".
|
|
66
|
+
|
|
67
|
+
## Failure mode
|
|
68
|
+
|
|
69
|
+
What happens if the action cannot be completed. For ADVISORY: how the
|
|
70
|
+
failure is recorded. For GATE / MUTATION: who is notified and what
|
|
71
|
+
manual override looks like (e.g. spec §11 Resolved Decisions note).
|
|
72
|
+
|
|
73
|
+
## Why
|
|
74
|
+
|
|
75
|
+
Cite a concrete failure mode or prior incident the hook prevents.
|
|
76
|
+
Without a documented "why", the hook has no defense when a future
|
|
77
|
+
contributor challenges it.
|
|
78
|
+
|
|
79
|
+
## Examples
|
|
80
|
+
|
|
81
|
+
### When this hook fires
|
|
82
|
+
|
|
83
|
+
<a short scenario where the hook's `appliesWhen` matches>
|
|
84
|
+
|
|
85
|
+
### When this hook does not fire
|
|
86
|
+
|
|
87
|
+
<a near-miss scenario showing the boundary>
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: runtime-scoped-preflight
|
|
3
|
+
description: Pre-Executor GATE — when a spec touches .ai/runtime/**, verify branch, scope, and spec path preconditions before code edits begin.
|
|
4
|
+
metadata:
|
|
5
|
+
phase: pre
|
|
6
|
+
agent: executor
|
|
7
|
+
gate: GATE
|
|
8
|
+
appliesWhen:
|
|
9
|
+
pathPatterns:
|
|
10
|
+
- ".ai/runtime/**"
|
|
11
|
+
specSignals:
|
|
12
|
+
- "runtime-scoped"
|
|
13
|
+
- "Runtime Tree Protection"
|
|
14
|
+
runtimeModes:
|
|
15
|
+
- FEATURE_DEVELOPMENT
|
|
16
|
+
- BUG_FIX
|
|
17
|
+
- REFACTOR
|
|
18
|
+
- GOVERNANCE_RECOVERY
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
# Runtime-Scoped Preflight
|
|
22
|
+
|
|
23
|
+
At the `Planner → Executor` transition, if the spec's §2 Scope
|
|
24
|
+
lists any path under `.ai/runtime/**`, the Executor MUST verify
|
|
25
|
+
three preconditions before applying any file edit. Failing the
|
|
26
|
+
check blocks the transition; the Executor stops and surfaces the
|
|
27
|
+
failure to the operator.
|
|
28
|
+
|
|
29
|
+
This hook is the agent-pipeline complement to `SAFETY.md` §
|
|
30
|
+
Runtime Tree Protection. Where SAFETY.md states the rule,
|
|
31
|
+
this hook makes the rule observable at the moment of
|
|
32
|
+
violation — i.e. before any change is written.
|
|
33
|
+
|
|
34
|
+
## Trigger
|
|
35
|
+
|
|
36
|
+
- **Phase**: pre
|
|
37
|
+
- **Agent transition**: `Planner → Executor`
|
|
38
|
+
- **Applies when**: the spec's §2 Scope lists at least one path
|
|
39
|
+
matching `.ai/runtime/**`. Examples of qualifying scope
|
|
40
|
+
entries:
|
|
41
|
+
- `.ai/runtime/SAFETY.md`
|
|
42
|
+
- `.ai/runtime/workflows/feature-development.md`
|
|
43
|
+
- any new file under `.ai/runtime/hooks/`, `rules/`,
|
|
44
|
+
`skills/`, or `specs/_template/`.
|
|
45
|
+
|
|
46
|
+
## Action
|
|
47
|
+
|
|
48
|
+
Before the Executor opens an edit tool, confirm ALL three:
|
|
49
|
+
|
|
50
|
+
1. **Scope contract.** Every runtime path the task will touch
|
|
51
|
+
appears verbatim in §2 Scope's `Includes` list (not just in
|
|
52
|
+
`§3 Requirements`). Implicit touches via subdirectory
|
|
53
|
+
wildcards (`.ai/runtime/**`) are not sufficient; each file
|
|
54
|
+
must be named.
|
|
55
|
+
2. **Branch name.** The current branch name starts with
|
|
56
|
+
`chore/runtime-` per
|
|
57
|
+
`.ai/runtime/workflows/branching.md` § Governance Rule
|
|
58
|
+
Branches. Bare descriptive names (`fix/x`,
|
|
59
|
+
`feat/x`) do not satisfy this.
|
|
60
|
+
3. **Spec home.** A spec file exists at
|
|
61
|
+
`.ai/project/specs/YYYY-MM-DD-<name>/spec.md` whose §2 Scope
|
|
62
|
+
was the source of (1). Out-of-band edits to runtime/ (no
|
|
63
|
+
spec, no review) are not permitted.
|
|
64
|
+
|
|
65
|
+
If ANY check fails, STOP. Do not write files. Report the failed
|
|
66
|
+
precondition to the operator and request remediation.
|
|
67
|
+
|
|
68
|
+
## Gate behavior
|
|
69
|
+
|
|
70
|
+
**GATE**. A failed precondition blocks the transition. The
|
|
71
|
+
Executor MUST NOT start. The operator must either:
|
|
72
|
+
|
|
73
|
+
- correct the precondition (rename branch, expand §2 Scope, or
|
|
74
|
+
add the missing spec), or
|
|
75
|
+
- record in the spec's §11 Resolved Decisions why the
|
|
76
|
+
precondition does not apply (rare — almost always indicates
|
|
77
|
+
the change should not be made here).
|
|
78
|
+
|
|
79
|
+
Manual override requires the spec's §11 to explicitly cite this
|
|
80
|
+
hook by path (`.ai/runtime/hooks/pre-executor/runtime-scoped-preflight/HOOK.md`).
|
|
81
|
+
Silent override is forbidden and constitutes a Forbidden
|
|
82
|
+
Operation under `SAFETY.md`.
|
|
83
|
+
|
|
84
|
+
## Inputs
|
|
85
|
+
|
|
86
|
+
- The spec file's §2 Scope content (§ Includes specifically).
|
|
87
|
+
- Current `git rev-parse --abbrev-ref HEAD` value.
|
|
88
|
+
- Existence of the spec file on disk at the named path.
|
|
89
|
+
|
|
90
|
+
## Outputs
|
|
91
|
+
|
|
92
|
+
Advisory note recorded in the review file under
|
|
93
|
+
`.ai/project/reviews/<spec-name>-review.md`'s § Verification
|
|
94
|
+
subsection, even on success, of the form:
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
Runtime-scoped preflight (HOOK pre-executor/runtime-scoped-preflight):
|
|
98
|
+
- Scope contract: PASS — listed paths: <paths>
|
|
99
|
+
- Branch name: PASS — `<branch-name>`
|
|
100
|
+
- Spec home: PASS — `<spec-path>`
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
On failure: no review file is written (the Executor blocked
|
|
104
|
+
before reaching the Review phase). The operator's response
|
|
105
|
+
appears in the spec body itself.
|
|
106
|
+
|
|
107
|
+
## Failure mode
|
|
108
|
+
|
|
109
|
+
GATE failure halts the pipeline. The Executor must:
|
|
110
|
+
|
|
111
|
+
1. State which of the three preconditions failed and why.
|
|
112
|
+
2. Surface the relevant rule citation (SAFETY.md § Runtime
|
|
113
|
+
Tree Protection, branching.md § Governance Rule Branches).
|
|
114
|
+
3. Wait for operator remediation. No silent retry.
|
|
115
|
+
|
|
116
|
+
If the operator chooses to override via §11 Resolved Decisions,
|
|
117
|
+
the override block must:
|
|
118
|
+
|
|
119
|
+
- name this hook by path,
|
|
120
|
+
- name the specific precondition being bypassed,
|
|
121
|
+
- justify why the bypass is safer than the bypassed
|
|
122
|
+
precondition.
|
|
123
|
+
|
|
124
|
+
## Why
|
|
125
|
+
|
|
126
|
+
`SAFETY.md` § Runtime Tree Protection is one of the most-cited
|
|
127
|
+
governance rules in this repo. Multiple specs land per day that
|
|
128
|
+
touch runtime/. Without an observable handoff contract, the
|
|
129
|
+
rule depends entirely on each Executor invocation remembering
|
|
130
|
+
to check.
|
|
131
|
+
|
|
132
|
+
Specific anti-patterns this hook prevents:
|
|
133
|
+
|
|
134
|
+
- **Runtime edits in project-scoped branches.** A feature-spec
|
|
135
|
+
branch like `feat/notes-module` quietly edits `RUNTIME_MODE.md`
|
|
136
|
+
because the executor noticed a tangentially related drift.
|
|
137
|
+
No spec authorisation, no review, no governance trail.
|
|
138
|
+
`2026-05-12-workflow-maintenance` (the retrospective)
|
|
139
|
+
documents the kind of out-of-band edit this pattern produces.
|
|
140
|
+
- **Wildcard scope.** A spec lists `.ai/runtime/**` in §2 Scope
|
|
141
|
+
to mean "I might touch a few files here" — and then the
|
|
142
|
+
executor touches a dozen. The hook forces enumeration.
|
|
143
|
+
- **Missing spec.** A direct edit to `.ai/runtime/BOOTSTRAP.md`
|
|
144
|
+
with no spec at all. The hook fails check (3).
|
|
145
|
+
|
|
146
|
+
`feedback_governance_bootstrap_order` (this repo's lived
|
|
147
|
+
memory note: "write the rule on trunk before applying it") is
|
|
148
|
+
strengthened by check (1) and (3) acting before any code is
|
|
149
|
+
written.
|
|
150
|
+
|
|
151
|
+
## Examples
|
|
152
|
+
|
|
153
|
+
### When this hook fires
|
|
154
|
+
|
|
155
|
+
Spec `2026-05-13-add-bug-fix-mode` lists in §2 Scope:
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
- `.ai/runtime/RUNTIME_MODE.md` — modify ...
|
|
159
|
+
- `.ai/runtime/BOOTSTRAP.md` — modify ...
|
|
160
|
+
- `.ai/runtime/RUNTIME_TRANSITIONS.md` — modify ...
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Three runtime paths. The hook fires at `pre-executor`. The
|
|
164
|
+
Executor verifies:
|
|
165
|
+
|
|
166
|
+
1. ✅ Scope contract — all three paths listed by name.
|
|
167
|
+
2. ✅ Branch — `chore/runtime-bug-fix-mode`.
|
|
168
|
+
3. ✅ Spec home — exists.
|
|
169
|
+
|
|
170
|
+
Pass. Executor proceeds.
|
|
171
|
+
|
|
172
|
+
### When this hook does not fire
|
|
173
|
+
|
|
174
|
+
Spec `2026-05-13-claudemd-runtime-paths` lists in §2 Scope only
|
|
175
|
+
`CLAUDE.md` and `.ai/project/...` files. No `.ai/runtime/**`
|
|
176
|
+
path appears. The hook's `appliesWhen.pathPatterns` does not
|
|
177
|
+
match. The hook does not fire; the Executor proceeds without
|
|
178
|
+
preflight.
|
|
179
|
+
|
|
180
|
+
### Near-miss: the bypass case
|
|
181
|
+
|
|
182
|
+
Spec body says "as a one-time exception, also patch
|
|
183
|
+
`.ai/runtime/CAPABILITIES.md` to align labels." But §2 Scope
|
|
184
|
+
only lists project files. The hook fires anyway because
|
|
185
|
+
the **intent** (visible in §3 Requirements or §11 narrative)
|
|
186
|
+
touches runtime/. Check (1) fails on "not in Includes list".
|
|
187
|
+
The Executor must either move the runtime touch into §2 Scope
|
|
188
|
+
formally (running the proper spec workflow) or split it into a
|
|
189
|
+
follow-up spec.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# Architecture Principles
|
|
2
|
+
|
|
3
|
+
Generic architectural guidance for projects using this runtime.
|
|
4
|
+
Project-specific conventions (concrete `src/` tree, ADR references,
|
|
5
|
+
persistence stack) live in
|
|
6
|
+
`.ai/project/memory/architecture/conventions.md`.
|
|
7
|
+
|
|
8
|
+
## Goals
|
|
9
|
+
|
|
10
|
+
- maintainability
|
|
11
|
+
- modularity
|
|
12
|
+
- testability
|
|
13
|
+
- backward compatibility
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Preferred Structure (general shape)
|
|
18
|
+
|
|
19
|
+
Recommended top-level layering:
|
|
20
|
+
|
|
21
|
+
- composition root (app construction)
|
|
22
|
+
- entry point (process startup only)
|
|
23
|
+
- feature modules (vertical, owning a domain end-to-end)
|
|
24
|
+
- cross-module middleware
|
|
25
|
+
- shared infrastructure
|
|
26
|
+
- framework-agnostic shared helpers
|
|
27
|
+
|
|
28
|
+
Concrete directory layout for this project lives in
|
|
29
|
+
`.ai/project/memory/architecture/conventions.md`.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## App Structure
|
|
34
|
+
|
|
35
|
+
- composition root file:
|
|
36
|
+
- middleware registration
|
|
37
|
+
- route registration
|
|
38
|
+
|
|
39
|
+
- entry file:
|
|
40
|
+
- process startup only
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Module Rules
|
|
45
|
+
|
|
46
|
+
A feature module owns a feature end-to-end. Conventional files inside
|
|
47
|
+
a module:
|
|
48
|
+
|
|
49
|
+
- routes file — HTTP boundary
|
|
50
|
+
- service file — orchestration / use cases (optional)
|
|
51
|
+
- repository file — persistence access (optional)
|
|
52
|
+
- module-private domain helpers
|
|
53
|
+
- co-located tests
|
|
54
|
+
|
|
55
|
+
Module internals are private. A module's public surface is what the
|
|
56
|
+
composition root (and any other consuming module) imports — prefer a
|
|
57
|
+
small set of exports.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Layer Rules
|
|
62
|
+
|
|
63
|
+
- **shared layer** — pure helpers, framework-agnostic. Depends on
|
|
64
|
+
nothing else inside the source tree.
|
|
65
|
+
- **infrastructure layer** — shared runtime infrastructure (DB pool,
|
|
66
|
+
schema, migrations). Depends only on shared.
|
|
67
|
+
- **middleware layer** — cross-module HTTP middleware. Depends on
|
|
68
|
+
infrastructure and shared.
|
|
69
|
+
- **module layer** — feature modules. May depend on middleware,
|
|
70
|
+
infrastructure, shared, and the *public surface* of another module.
|
|
71
|
+
Must not reach into another module's internal files.
|
|
72
|
+
- **composition root** — wires everything; the only place that imports
|
|
73
|
+
every module.
|
|
74
|
+
|
|
75
|
+
Forbidden:
|
|
76
|
+
|
|
77
|
+
- infrastructure importing from modules.
|
|
78
|
+
- shared importing from anywhere inside source.
|
|
79
|
+
- A module reaching into another module's internal files.
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Refactor Principles
|
|
84
|
+
|
|
85
|
+
- prefer behavior-preserving refactors
|
|
86
|
+
- prefer small migrations
|
|
87
|
+
- avoid large rewrites
|
|
88
|
+
- preserve contracts
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## Service Design
|
|
93
|
+
|
|
94
|
+
- services should avoid HTTP concerns
|
|
95
|
+
- routes should remain thin
|
|
96
|
+
- utilities should remain pure
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## Middleware Design
|
|
101
|
+
|
|
102
|
+
- middleware should be composable
|
|
103
|
+
- avoid hidden side effects
|
|
104
|
+
- prefer explicit registration
|
|
105
|
+
- middleware that only serves one module belongs inside that module;
|
|
106
|
+
only middleware shared across modules lives in the cross-module
|
|
107
|
+
middleware layer
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# Engineering Principles
|
|
2
|
+
|
|
3
|
+
Generic engineering principles for projects using this runtime.
|
|
4
|
+
Project-specific conventions (Biome configuration, commit-message
|
|
5
|
+
contract, persistence patterns) live in
|
|
6
|
+
`.ai/project/memory/engineering/conventions.md`.
|
|
7
|
+
|
|
8
|
+
## General Principles
|
|
9
|
+
|
|
10
|
+
- Keep implementations simple.
|
|
11
|
+
- Prefer readability over cleverness.
|
|
12
|
+
- Preserve backward compatibility for public APIs.
|
|
13
|
+
- Avoid unnecessary dependencies.
|
|
14
|
+
- Prefer small focused changes.
|
|
15
|
+
- Tests are required for public API changes.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Project Structure
|
|
20
|
+
|
|
21
|
+
The project structure pattern in this runtime follows a composition
|
|
22
|
+
root + entry separation:
|
|
23
|
+
|
|
24
|
+
- One file owns app construction and route registration.
|
|
25
|
+
- One file owns process startup only.
|
|
26
|
+
|
|
27
|
+
Do not place route logic inside the startup file.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## API Design
|
|
32
|
+
|
|
33
|
+
- Responses must be JSON.
|
|
34
|
+
- Public API changes require contract updates.
|
|
35
|
+
- Breaking API changes require ADR approval.
|
|
36
|
+
- Additive changes are preferred over destructive changes.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Testing
|
|
41
|
+
|
|
42
|
+
Requirements:
|
|
43
|
+
|
|
44
|
+
- Tests must not bind real network ports.
|
|
45
|
+
- Tests should validate response structure.
|
|
46
|
+
- Existing tests must continue passing.
|
|
47
|
+
|
|
48
|
+
(Specific test framework choices belong in project conventions.)
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Verification
|
|
53
|
+
|
|
54
|
+
Minimum required checks:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npm test
|
|
58
|
+
npm run build
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Contracts
|
|
64
|
+
|
|
65
|
+
Before modifying public APIs:
|
|
66
|
+
|
|
67
|
+
- read `.ai/project/contracts/**`
|
|
68
|
+
- preserve required fields
|
|
69
|
+
- preserve field types
|
|
70
|
+
- preserve backward compatibility
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## ADR Rules
|
|
75
|
+
|
|
76
|
+
Create ADRs for:
|
|
77
|
+
|
|
78
|
+
- architecture changes
|
|
79
|
+
- breaking API changes
|
|
80
|
+
- major dependency decisions
|
|
81
|
+
- structural refactors
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Review Expectations
|
|
86
|
+
|
|
87
|
+
Reviews should check:
|
|
88
|
+
|
|
89
|
+
- correctness
|
|
90
|
+
- maintainability
|
|
91
|
+
- compatibility
|
|
92
|
+
- testing coverage
|
|
93
|
+
- architecture consistency
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## Preferred Engineering Style
|
|
98
|
+
|
|
99
|
+
- explicit over implicit
|
|
100
|
+
- modular over monolithic
|
|
101
|
+
- stable over clever
|
|
102
|
+
- testable over tightly coupled
|