@hivehub/rulebook 5.2.1 → 5.3.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 (157) hide show
  1. package/.claude/commands/analysis.md +35 -0
  2. package/.claude/commands/rulebook-task-apply.md +7 -25
  3. package/.claude/commands/rulebook-task-archive.md +10 -19
  4. package/.claude/commands/rulebook-task-create.md +1 -1
  5. package/README.md +354 -965
  6. package/dist/cli/commands/analysis.d.ts +8 -0
  7. package/dist/cli/commands/analysis.d.ts.map +1 -0
  8. package/dist/cli/commands/analysis.js +78 -0
  9. package/dist/cli/commands/analysis.js.map +1 -0
  10. package/dist/cli/commands/context-intelligence.d.ts +33 -0
  11. package/dist/cli/commands/context-intelligence.d.ts.map +1 -0
  12. package/dist/cli/commands/context-intelligence.js +181 -0
  13. package/dist/cli/commands/context-intelligence.js.map +1 -0
  14. package/dist/cli/commands/index.d.ts +19 -0
  15. package/dist/cli/commands/index.d.ts.map +1 -0
  16. package/dist/cli/commands/index.js +19 -0
  17. package/dist/cli/commands/index.js.map +1 -0
  18. package/dist/cli/commands/init.d.ts +15 -0
  19. package/dist/cli/commands/init.d.ts.map +1 -0
  20. package/dist/cli/commands/init.js +608 -0
  21. package/dist/cli/commands/init.js.map +1 -0
  22. package/dist/cli/commands/mcp.d.ts +10 -0
  23. package/dist/cli/commands/mcp.d.ts.map +1 -0
  24. package/dist/cli/commands/mcp.js +128 -0
  25. package/dist/cli/commands/mcp.js.map +1 -0
  26. package/dist/cli/commands/memory.d.ts +24 -0
  27. package/dist/cli/commands/memory.d.ts.map +1 -0
  28. package/dist/cli/commands/memory.js +265 -0
  29. package/dist/cli/commands/memory.js.map +1 -0
  30. package/dist/cli/commands/misc.d.ts +33 -0
  31. package/dist/cli/commands/misc.d.ts.map +1 -0
  32. package/dist/cli/commands/misc.js +576 -0
  33. package/dist/cli/commands/misc.js.map +1 -0
  34. package/dist/cli/commands/plans.d.ts +15 -0
  35. package/dist/cli/commands/plans.d.ts.map +1 -0
  36. package/dist/cli/commands/plans.js +266 -0
  37. package/dist/cli/commands/plans.js.map +1 -0
  38. package/dist/cli/commands/ralph.d.ts +45 -0
  39. package/dist/cli/commands/ralph.d.ts.map +1 -0
  40. package/dist/cli/commands/ralph.js +694 -0
  41. package/dist/cli/commands/ralph.js.map +1 -0
  42. package/dist/cli/commands/skills.d.ts +9 -0
  43. package/dist/cli/commands/skills.d.ts.map +1 -0
  44. package/dist/cli/commands/skills.js +249 -0
  45. package/dist/cli/commands/skills.js.map +1 -0
  46. package/dist/cli/commands/task.d.ts +16 -0
  47. package/dist/cli/commands/task.d.ts.map +1 -0
  48. package/dist/cli/commands/task.js +256 -0
  49. package/dist/cli/commands/task.js.map +1 -0
  50. package/dist/cli/commands/update.d.ts +14 -0
  51. package/dist/cli/commands/update.d.ts.map +1 -0
  52. package/dist/cli/commands/update.js +636 -0
  53. package/dist/cli/commands/update.js.map +1 -0
  54. package/dist/cli/commands/workspace.d.ts +6 -0
  55. package/dist/cli/commands/workspace.d.ts.map +1 -0
  56. package/dist/cli/commands/workspace.js +141 -0
  57. package/dist/cli/commands/workspace.js.map +1 -0
  58. package/dist/core/agent-template-engine.js +28 -28
  59. package/dist/core/analysis-manager.d.ts +56 -0
  60. package/dist/core/analysis-manager.d.ts.map +1 -0
  61. package/dist/core/analysis-manager.js +218 -0
  62. package/dist/core/analysis-manager.js.map +1 -0
  63. package/dist/core/claude-md-generator.d.ts +52 -0
  64. package/dist/core/claude-md-generator.d.ts.map +1 -0
  65. package/dist/core/claude-md-generator.js +104 -0
  66. package/dist/core/claude-md-generator.js.map +1 -0
  67. package/dist/core/claude-settings-manager.d.ts +37 -0
  68. package/dist/core/claude-settings-manager.d.ts.map +1 -0
  69. package/dist/core/claude-settings-manager.js +168 -0
  70. package/dist/core/claude-settings-manager.js.map +1 -0
  71. package/dist/core/compact-context-manager.d.ts +34 -0
  72. package/dist/core/compact-context-manager.d.ts.map +1 -0
  73. package/dist/core/compact-context-manager.js +60 -0
  74. package/dist/core/compact-context-manager.js.map +1 -0
  75. package/dist/core/doctor.d.ts +19 -0
  76. package/dist/core/doctor.d.ts.map +1 -0
  77. package/dist/core/doctor.js +163 -0
  78. package/dist/core/doctor.js.map +1 -0
  79. package/dist/core/generator.js +28 -28
  80. package/dist/core/mcp-reference-generator.d.ts +13 -0
  81. package/dist/core/mcp-reference-generator.d.ts.map +1 -0
  82. package/dist/core/mcp-reference-generator.js +66 -0
  83. package/dist/core/mcp-reference-generator.js.map +1 -0
  84. package/dist/core/merger.d.ts +35 -0
  85. package/dist/core/merger.d.ts.map +1 -1
  86. package/dist/core/merger.js +120 -0
  87. package/dist/core/merger.js.map +1 -1
  88. package/dist/core/prd-generator.d.ts.map +1 -1
  89. package/dist/core/prd-generator.js +7 -1
  90. package/dist/core/prd-generator.js.map +1 -1
  91. package/dist/core/ralph-manager.d.ts.map +1 -1
  92. package/dist/core/ralph-manager.js +17 -0
  93. package/dist/core/ralph-manager.js.map +1 -1
  94. package/dist/core/rules-generator.d.ts +73 -0
  95. package/dist/core/rules-generator.d.ts.map +1 -0
  96. package/dist/core/rules-generator.js +201 -0
  97. package/dist/core/rules-generator.js.map +1 -0
  98. package/dist/core/state-writer.d.ts +35 -0
  99. package/dist/core/state-writer.d.ts.map +1 -0
  100. package/dist/core/state-writer.js +81 -0
  101. package/dist/core/state-writer.js.map +1 -0
  102. package/dist/core/task-manager.d.ts +35 -0
  103. package/dist/core/task-manager.d.ts.map +1 -1
  104. package/dist/core/task-manager.js +135 -38
  105. package/dist/core/task-manager.js.map +1 -1
  106. package/dist/core/telemetry.d.ts +29 -0
  107. package/dist/core/telemetry.d.ts.map +1 -0
  108. package/dist/core/telemetry.js +57 -0
  109. package/dist/core/telemetry.js.map +1 -0
  110. package/dist/core/workflow-generator.d.ts.map +1 -1
  111. package/dist/core/workflow-generator.js +2 -177
  112. package/dist/core/workflow-generator.js.map +1 -1
  113. package/dist/index.js +28 -1
  114. package/dist/index.js.map +1 -1
  115. package/dist/mcp/rulebook-server.d.ts.map +1 -1
  116. package/dist/mcp/rulebook-server.js +190 -7
  117. package/dist/mcp/rulebook-server.js.map +1 -1
  118. package/dist/memory/memory-store.js +91 -91
  119. package/dist/types.d.ts +11 -0
  120. package/dist/types.d.ts.map +1 -1
  121. package/dist/utils/gitignore.d.ts +10 -0
  122. package/dist/utils/gitignore.d.ts.map +1 -0
  123. package/dist/utils/gitignore.js +38 -0
  124. package/dist/utils/gitignore.js.map +1 -0
  125. package/package.json +1 -1
  126. package/templates/compact-context/_default.md +23 -0
  127. package/templates/compact-context/cpp.md +26 -0
  128. package/templates/compact-context/go.md +26 -0
  129. package/templates/compact-context/python.md +26 -0
  130. package/templates/compact-context/rust.md +28 -0
  131. package/templates/compact-context/typescript.md +29 -0
  132. package/templates/core/CLAUDE_MD_v2.md +71 -0
  133. package/templates/hooks/check-context-and-handoff.ps1 +50 -0
  134. package/templates/hooks/check-context-and-handoff.sh +69 -0
  135. package/templates/hooks/enforce-mcp-for-tasks.sh +31 -0
  136. package/templates/hooks/enforce-no-deferred.sh +21 -0
  137. package/templates/hooks/enforce-no-shortcuts.sh +31 -0
  138. package/templates/hooks/enforce-team-for-background-agents.ps1 +63 -0
  139. package/templates/hooks/enforce-team-for-background-agents.sh +55 -0
  140. package/templates/hooks/on-compact-reinject.sh +34 -0
  141. package/templates/hooks/resume-from-handoff.ps1 +33 -0
  142. package/templates/hooks/resume-from-handoff.sh +55 -0
  143. package/templates/rules/consult-analysis-before-implementing.md +23 -0
  144. package/templates/rules/cpp.md +46 -0
  145. package/templates/rules/csharp.md +44 -0
  146. package/templates/rules/diagnostic-first.md +39 -0
  147. package/templates/rules/fail-twice-escalate.md +46 -0
  148. package/templates/rules/go.md +40 -0
  149. package/templates/rules/java.md +43 -0
  150. package/templates/rules/javascript.md +39 -0
  151. package/templates/rules/multi-agent-teams.md +75 -0
  152. package/templates/rules/python.md +43 -0
  153. package/templates/rules/respect-handoff-trigger.md +41 -0
  154. package/templates/rules/rust.md +40 -0
  155. package/templates/rules/typescript.md +40 -0
  156. package/templates/skills/dev/analysis/SKILL.md +19 -0
  157. package/templates/skills/dev/handoff/SKILL.md +27 -0
@@ -0,0 +1,40 @@
1
+ ---
2
+ paths:
3
+ - "**/*.go"
4
+ - "go.mod"
5
+ - "go.sum"
6
+ ---
7
+ <!-- Generated by @hivehub/rulebook v5.3.0 — delete this comment to prevent regeneration on `rulebook update` -->
8
+
9
+ # Go rules
10
+
11
+ Loaded by Claude Code when touching Go sources.
12
+
13
+ ## Non-negotiables
14
+
15
+ 1. **`go vet ./...` before `go test ./...`.** Vet is near-instant and catches common issues before the slower test runner.
16
+ 2. **`gofmt -s -w .` and `goimports -w .`** on every file you touch. There is no formatting debate in Go.
17
+ 3. **Error handling is explicit.** Every `err` is either handled, wrapped with `fmt.Errorf("context: %w", err)`, or propagated up. Never `_ = err`.
18
+ 4. **No naked returns in functions longer than 5 lines.** They obscure control flow.
19
+ 5. **`context.Context` is the first parameter** for any function that does I/O or may block. Never store contexts in structs.
20
+
21
+ ## Conventions
22
+
23
+ - Package names are short, lowercase, and singular (`user`, not `users` or `userManager`).
24
+ - Interfaces defined by the consumer, not the producer. Keep them small (1–3 methods).
25
+ - Struct fields ordered: exported before unexported, grouped by logical purpose.
26
+ - Use `any` instead of `interface{}` (Go 1.18+).
27
+ - Prefer table-driven tests with `t.Run` subtests.
28
+
29
+ ## Testing
30
+
31
+ - Test files live in the same package, suffix `_test.go`.
32
+ - `testify/require` or stdlib `testing` — pick one and stick with it.
33
+ - Race detector on CI: `go test -race ./...`.
34
+ - No test skipping without `t.Skip("reason: ...")`.
35
+
36
+ ## Build & tooling
37
+
38
+ - `go mod tidy` after adding imports; commit both `go.mod` and `go.sum`.
39
+ - Never commit `vendor/` unless the project explicitly vendors.
40
+ - Use `go build ./...` to catch packages you forgot to test.
@@ -0,0 +1,43 @@
1
+ ---
2
+ paths:
3
+ - "**/*.java"
4
+ - "pom.xml"
5
+ - "**/build.gradle"
6
+ - "**/build.gradle.kts"
7
+ - "**/settings.gradle"
8
+ - "**/settings.gradle.kts"
9
+ ---
10
+ <!-- Generated by @hivehub/rulebook v5.3.0 — delete this comment to prevent regeneration on `rulebook update` -->
11
+
12
+ # Java rules
13
+
14
+ Loaded by Claude Code when touching Java sources or build files.
15
+
16
+ ## Non-negotiables
17
+
18
+ 1. **Compile before test.** `mvn compile` / `gradle classes` before running the test suite. Compilation errors are cheaper to fix than a broken test run.
19
+ 2. **Static analysis enabled.** SpotBugs, ErrorProne, or Checkstyle per project config. Warnings count as failures.
20
+ 3. **Null safety.** Use `Optional<T>` for values that may be absent at API boundaries. Annotate fields with `@Nullable` / `@NonNull` where the project uses JSR-305 / JSpecify.
21
+ 4. **Immutability first.** `final` by default on fields, parameters, and local variables. Prefer records (Java 16+) for data carriers.
22
+ 5. **Never swallow exceptions.** Every `catch` either handles, wraps (`throw new X("context", e)`), or logs with context.
23
+
24
+ ## Conventions
25
+
26
+ - Follow the project's Google Java Style or similar — formatter handles it.
27
+ - Package names all lowercase, reverse-DNS (`com.hivehub.rulebook.foo`).
28
+ - One public class per file; file name matches the class.
29
+ - Prefer composition over inheritance; avoid deep hierarchies.
30
+ - Use `java.time` (not `java.util.Date`) for dates and times.
31
+
32
+ ## Testing
33
+
34
+ - JUnit 5 is default; use the project's configured framework.
35
+ - AssertJ or Hamcrest for readable assertions.
36
+ - Mockito for mocks; avoid PowerMock unless strictly necessary.
37
+ - One logical assertion per test; multiple mechanical ones allowed.
38
+
39
+ ## Build & tooling
40
+
41
+ - Commit `pom.xml` / `build.gradle`, never `target/` / `build/`.
42
+ - Pin plugin versions; do not use ranges.
43
+ - Java version declared in the build file, not assumed from the environment.
@@ -0,0 +1,39 @@
1
+ ---
2
+ paths:
3
+ - "**/*.js"
4
+ - "**/*.jsx"
5
+ - "**/*.mjs"
6
+ - "**/*.cjs"
7
+ - "package.json"
8
+ ---
9
+ <!-- Generated by @hivehub/rulebook v5.3.0 — delete this comment to prevent regeneration on `rulebook update` -->
10
+
11
+ # JavaScript rules
12
+
13
+ Loaded by Claude Code when touching JavaScript files.
14
+
15
+ ## Non-negotiables
16
+
17
+ 1. **Lint before test.** Run the project's linter (ESLint / Biome) before the test suite. Lint errors are cheaper to surface than test failures.
18
+ 2. **No `var`.** Use `const` by default, `let` only when reassignment is necessary.
19
+ 3. **Strict equality.** Always `===` and `!==`, never `==` / `!=`.
20
+ 4. **No implicit globals.** Every file that modifies state at the top level should explicitly export it.
21
+ 5. **Module type matches the project.** If the project is ESM (`"type": "module"` in package.json), use `import`/`export`; if CommonJS, use `require`/`module.exports`. Do not mix without a clear boundary.
22
+
23
+ ## Conventions
24
+
25
+ - Prefer arrow functions for callbacks; named `function` declarations for top-level or hoisted functions.
26
+ - `async`/`await` over raw Promise chains.
27
+ - Destructure function arguments when there are 3+ parameters.
28
+ - Never rely on falsy checks for "value exists" — use explicit `=== undefined` / `!= null` where the distinction matters.
29
+
30
+ ## Testing
31
+
32
+ - Use the project's configured test runner. Do not add a new one.
33
+ - Mock external boundaries (network, filesystem, time).
34
+ - No `describe.skip` / `it.skip` left behind in committed code.
35
+
36
+ ## Dependencies
37
+
38
+ - Check `package.json` before adding imports. Do not install new dependencies without explicit authorization.
39
+ - Pin `peerDependencies` carefully; they affect consumers of the package.
@@ -0,0 +1,75 @@
1
+ <!-- Generated by @hivehub/rulebook v5.3.0 — delete this comment to prevent regeneration on `rulebook update` -->
2
+
3
+ # Multi-agent work MUST use Teams
4
+
5
+ This project has **more than one specialized agent** and relies on Claude Code's
6
+ experimental Teams feature (`CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1`). When
7
+ you need parallel execution across agents, use **Teams** — not standalone
8
+ background `Agent` calls.
9
+
10
+ ## Why
11
+
12
+ Standalone background agents **cannot communicate with each other**. Only
13
+ agents inside a Team have access to the `SendMessage` tool. When two or
14
+ more independent background agents run without a Team:
15
+
16
+ - They cannot coordinate, share intermediate results, or reach consensus.
17
+ - They silently produce conflicting edits or duplicate work.
18
+ - You lose the ability to orchestrate hand-offs between specialists.
19
+
20
+ Rulebook enforces this with a `PreToolUse` hook that **denies** any
21
+ `Agent` invocation with `run_in_background: true` unless it is either:
22
+
23
+ 1. `subagent_type: team-lead` (the coordinator that will create the Team), or
24
+ 2. Passes `team_name` (already joined to an existing Team).
25
+
26
+ Foreground single-agent calls are unaffected.
27
+
28
+ ## How to do parallel multi-agent work correctly
29
+
30
+ **Option A — Spawn a team-lead that creates the Team:**
31
+
32
+ ```
33
+ Agent(
34
+ subagent_type: "team-lead",
35
+ run_in_background: true,
36
+ description: "Coordinate the refactor",
37
+ prompt: "Create a team with roles [...]"
38
+ )
39
+ ```
40
+
41
+ The team-lead then uses `TeamCreate` and dispatches members with `team_name`.
42
+
43
+ **Option B — Create the Team first, then spawn members:**
44
+
45
+ ```
46
+ TeamCreate(name: "refactor-team", members: [...])
47
+ Agent(
48
+ subagent_type: "rust-expert",
49
+ team_name: "refactor-team",
50
+ run_in_background: true,
51
+ description: "Port the auth module",
52
+ prompt: "..."
53
+ )
54
+ Agent(
55
+ subagent_type: "test-writer",
56
+ team_name: "refactor-team",
57
+ run_in_background: true,
58
+ description: "Write tests",
59
+ prompt: "..."
60
+ )
61
+ ```
62
+
63
+ Both members can now exchange messages via `SendMessage`.
64
+
65
+ ## What is NOT blocked
66
+
67
+ - **Foreground `Agent`** (any `subagent_type`, no `run_in_background`): always allowed. Use this for simple delegation where you just need the result.
68
+ - **Background `Agent` with `team_name` set**: allowed because the agent has a coordination channel.
69
+ - **Background `Agent` with `subagent_type: "team-lead"`**: allowed because a team-lead is expected to bootstrap its Team before dispatching members.
70
+
71
+ ## Environment requirement
72
+
73
+ This feature requires `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1` in your
74
+ `.claude/settings.json`. Rulebook sets this automatically when
75
+ `multi_agent: true` is enabled in `.rulebook/rulebook.json`.
@@ -0,0 +1,43 @@
1
+ ---
2
+ paths:
3
+ - "**/*.py"
4
+ - "**/*.pyi"
5
+ - "pyproject.toml"
6
+ - "setup.py"
7
+ - "setup.cfg"
8
+ - "requirements*.txt"
9
+ ---
10
+ <!-- Generated by @hivehub/rulebook v5.3.0 — delete this comment to prevent regeneration on `rulebook update` -->
11
+
12
+ # Python rules
13
+
14
+ Loaded by Claude Code when touching Python files.
15
+
16
+ ## Non-negotiables
17
+
18
+ 1. **Type-check before test.** Run `mypy` / `pyright` / `pyre` (whichever the project configures) before `pytest`. Type errors are 10x cheaper to discover than test failures.
19
+ 2. **Lint with `ruff` or the project's linter** before committing. `ruff check` is fast enough to run on every save.
20
+ 3. **Format with `black` / `ruff format`** — never hand-format.
21
+ 4. **Type hints on all public functions.** `def foo(x: int) -> str` minimum. Use `from __future__ import annotations` for forward refs.
22
+ 5. **No bare `except:`** — catch specific exceptions or `except Exception as e:` at the very least.
23
+
24
+ ## Conventions
25
+
26
+ - Follow PEP 8 (handled by the formatter).
27
+ - `pathlib.Path` over `os.path` for filesystem operations.
28
+ - f-strings over `.format()` and `%` formatting.
29
+ - Dataclasses or `pydantic` for data containers, not raw dicts at API boundaries.
30
+ - `logging` module, never `print()`, for anything that ships.
31
+
32
+ ## Testing
33
+
34
+ - `pytest` is the default; use the project's configured runner.
35
+ - Fixtures in `conftest.py`, one per module where relevant.
36
+ - `pytest-cov` for coverage; meet the project's threshold.
37
+ - No skipped tests without an explicit comment linking to an issue.
38
+
39
+ ## Dependencies & environments
40
+
41
+ - Respect the project's virtualenv / pyenv / poetry / uv setup. Do not install globally.
42
+ - `pyproject.toml` over `setup.py` for new projects.
43
+ - Pin versions in production; unpin only in libraries.
@@ -0,0 +1,41 @@
1
+ <!-- Generated by @hivehub/rulebook v5.3.0 — delete this comment to prevent regeneration on `rulebook update` -->
2
+
3
+ # Respect handoff triggers
4
+
5
+ When you receive `additionalContext` mentioning a **handoff trigger**
6
+ (containing phrases like "CONTEXT AT", "invoke /handoff", or
7
+ "session state"), you MUST:
8
+
9
+ 1. **Stop** your current task immediately — do not finish the current
10
+ step, do not start a new one.
11
+ 2. **Invoke the `/handoff` skill** to write `.rulebook/handoff/_pending.md`
12
+ with: active task, decisions made this session, files touched, next
13
+ steps, and the exact resume command.
14
+ 3. **Display the message** `>>> TYPE /clear NOW — your context will be auto-restored <<<`
15
+ prominently so the user sees it.
16
+ 4. **Do not continue working** past the handoff message. The user must
17
+ type `/clear` before any further implementation.
18
+
19
+ ## Why
20
+
21
+ Sessions degrade as context fills. Research shows that model quality
22
+ at 80%+ context is measurably lower than at 0–50%. The handoff
23
+ mechanism ensures work is preserved and the next session starts fresh
24
+ with full context loaded via the `SessionStart` resume hook.
25
+
26
+ This rule has the **highest precedence** after `git-safety.md`. If a
27
+ handoff trigger fires while you are mid-edit, finish the current
28
+ atomic write (do not leave a file in a broken state), then stop.
29
+
30
+ ## What triggers a handoff
31
+
32
+ The `Stop` hook (`check-context-and-handoff.sh`) estimates context
33
+ usage from the JSONL transcript. Two thresholds:
34
+
35
+ - **warn (default 75%)**: advisory — the model should invoke `/handoff`
36
+ and suggest `/clear`.
37
+ - **force (default 90%)**: mandatory — the model MUST invoke `/handoff`
38
+ and MUST NOT continue working.
39
+
40
+ Both thresholds are configurable in `.rulebook/rulebook.json` under
41
+ `handoff.warnThresholdPct` and `handoff.forceThresholdPct`.
@@ -0,0 +1,40 @@
1
+ ---
2
+ paths:
3
+ - "**/*.rs"
4
+ - "Cargo.toml"
5
+ - "Cargo.lock"
6
+ - "rust-toolchain.toml"
7
+ ---
8
+ <!-- Generated by @hivehub/rulebook v5.3.0 — delete this comment to prevent regeneration on `rulebook update` -->
9
+
10
+ # Rust rules
11
+
12
+ Loaded by Claude Code when touching Rust sources or Cargo manifests.
13
+
14
+ ## Non-negotiables
15
+
16
+ 1. **`cargo check` before `cargo test`.** Check is 5–10x faster and surfaces type/borrow errors immediately. `cargo test` runs the checker anyway, but you lose the fast feedback loop.
17
+ 2. **`cargo clippy -- -D warnings`** must pass before committing. Warnings are errors in this project.
18
+ 3. **`cargo fmt`** before committing. Formatting is not a stylistic choice — `rustfmt` is the only authority.
19
+ 4. **No `unwrap()` / `expect()` in non-test code** unless the invariant is obvious from the surrounding 5 lines. Prefer `?` and proper error types.
20
+ 5. **No `unsafe` without a `// SAFETY:` comment** explaining why the invariants hold.
21
+
22
+ ## Conventions
23
+
24
+ - Error types: use `thiserror` for libraries, `anyhow` for applications. Do not mix.
25
+ - `Result<T, E>` returns on public APIs; never panic for recoverable errors.
26
+ - `#[must_use]` on functions returning a value the caller must handle.
27
+ - Lifetimes explicit only when the compiler asks for them. Do not add elided lifetimes "for clarity".
28
+ - Trait bounds on the impl block, not on every method, unless they genuinely differ.
29
+
30
+ ## Testing
31
+
32
+ - Unit tests in `#[cfg(test)] mod tests { ... }` at the bottom of the same file.
33
+ - Integration tests in `tests/`, one file per public behavior.
34
+ - `cargo test --all-features` is the baseline; default features may hide bugs.
35
+
36
+ ## Build & tooling
37
+
38
+ - Never commit `target/` or `Cargo.lock` for libraries (commit for binaries).
39
+ - Prefer `cargo add <crate>` over editing `Cargo.toml` by hand.
40
+ - Use `cargo-watch` locally; never add watchers to CI.
@@ -0,0 +1,40 @@
1
+ ---
2
+ paths:
3
+ - "**/*.ts"
4
+ - "**/*.tsx"
5
+ - "tsconfig.json"
6
+ - "tsconfig.*.json"
7
+ ---
8
+ <!-- Generated by @hivehub/rulebook v5.3.0 — delete this comment to prevent regeneration on `rulebook update` -->
9
+
10
+ # TypeScript rules
11
+
12
+ Loaded by Claude Code when touching TypeScript files. Keeps guidance focused so the main `CLAUDE.md` stays small.
13
+
14
+ ## Non-negotiables
15
+
16
+ 1. **Type-check before test.** Run the project's `type-check` (usually `tsc --noEmit` or `npm run type-check`) before running the test suite. A type error is a faster, cheaper signal than a test failure.
17
+ 2. **No `any`** unless the value is genuinely untyped (e.g. `JSON.parse` output before validation). Prefer `unknown` with a narrowing step.
18
+ 3. **No `// @ts-ignore` / `// @ts-expect-error`** without a one-line comment explaining why. If you can fix the type, fix it.
19
+ 4. **Strict null checks.** Treat `undefined` and `null` as distinct. Use optional chaining (`?.`) and nullish coalescing (`??`), not `||`, for "value might be absent" logic.
20
+ 5. **ESM everywhere.** Use `import`/`export`, not `require`. Relative imports include the `.js` extension (Node ESM rule) even when the source file is `.ts`.
21
+
22
+ ## Conventions
23
+
24
+ - Public API types live next to their implementation. Large shared types go in `src/types.ts` or `src/types/`.
25
+ - Interfaces for object shapes, `type` aliases for unions and mapped types.
26
+ - `readonly` wherever mutation is not required.
27
+ - Exhaustive `switch` on union types uses a `const _exhaustive: never = x;` tail.
28
+ - Async functions return `Promise<T>` explicitly on public APIs.
29
+
30
+ ## Testing
31
+
32
+ - Use the project's configured test runner (Vitest, Jest, Node test) — do not add a new one.
33
+ - Mock at the module boundary, not inside the unit under test.
34
+ - Every `describe` has at least one `it`; no empty test blocks.
35
+
36
+ ## Build & tooling
37
+
38
+ - Never commit `dist/`, `build/`, `.tsbuildinfo`, or `node_modules/`.
39
+ - `tsconfig.json` is the source of truth for compiler options. Do not override via inline comments unless explicitly required.
40
+ - Prefer `tsx` / `ts-node` for scripts; never shell-execute a raw `.ts` file in production.
@@ -0,0 +1,19 @@
1
+ ---
2
+ name: analysis
3
+ description: Create structured analyses with numbered findings, execution plans, and task materialization
4
+ model: opus
5
+ context: fork
6
+ agent: researcher
7
+ ---
8
+ Create a structured analysis for: $ARGUMENTS
9
+
10
+ Steps:
11
+ 1. Call `rulebook_analysis_create` with the topic to scaffold `docs/analysis/<slug>/`
12
+ 2. Check existing knowledge: `rulebook_knowledge_list` and `rulebook_memory_search` for prior context
13
+ 3. Investigate the topic — read relevant files, search codebase, fetch docs as needed
14
+ 4. Fill `findings.md` with numbered findings (F-001..F-NNN), each with: title, evidence (file:line), impact, confidence
15
+ 5. Design phased execution plan in `execution-plan.md`
16
+ 6. Consolidate the executive summary in `README.md`
17
+ 7. Capture each key finding to the knowledge base: `rulebook_knowledge_add` for patterns/anti-patterns
18
+ 8. Save analysis summary to memory: `rulebook_memory_save` with type `observation` and tags `["analysis", "<slug>"]`
19
+ 9. Offer to materialize implementation tasks from the execution plan via `rulebook_task_create`
@@ -0,0 +1,27 @@
1
+ ---
2
+ name: handoff
3
+ description: Save session state to .rulebook/handoff/_pending.md for cross-session continuity
4
+ model: sonnet
5
+ context: fork
6
+ agent: researcher
7
+ ---
8
+ Save a session handoff to `.rulebook/handoff/_pending.md`.
9
+
10
+ The handoff file MUST contain:
11
+
12
+ 1. **Active task**: current task ID + phase + which checklist items are done
13
+ 2. **Decisions made this session**: architectural choices, trade-offs, rejected alternatives
14
+ 3. **Files touched**: list of files modified with one-line reason each
15
+ 4. **Next steps**: concrete, actionable items (not vague "continue working")
16
+ 5. **Exact resume command**: what to tell the next session to do first
17
+ 6. **Open questions / blockers**: anything unresolved that needs the user's input
18
+
19
+ Write the file to `.rulebook/handoff/_pending.md` using the Write tool.
20
+
21
+ After writing successfully, display this message prominently:
22
+
23
+ >>> TYPE /clear NOW — your context will be auto-restored in the next session <<<
24
+
25
+ If the file `.rulebook/handoff/.urgent` exists, skip any confirmations and write immediately.
26
+
27
+ The SessionStart hook (`resume-from-handoff.sh`) will automatically inject the handoff content into the next session and archive the file.