@hivehub/rulebook 5.5.1 → 5.7.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/.claude/commands/rulebook-learn-capture.md +41 -48
- package/.claude/commands/rulebook-learn-list.md +13 -13
- package/README.md +332 -394
- package/dist/cli/commands/context-intelligence.d.ts +0 -1
- package/dist/cli/commands/context-intelligence.d.ts.map +1 -1
- package/dist/cli/commands/context-intelligence.js +12 -33
- package/dist/cli/commands/context-intelligence.js.map +1 -1
- package/dist/cli/commands/index.d.ts +4 -7
- package/dist/cli/commands/index.d.ts.map +1 -1
- package/dist/cli/commands/index.js +4 -7
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +40 -81
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/mcp.d.ts +0 -1
- package/dist/cli/commands/mcp.d.ts.map +1 -1
- package/dist/cli/commands/mcp.js +1 -7
- package/dist/cli/commands/mcp.js.map +1 -1
- package/dist/cli/commands/memory.d.ts +7 -1
- package/dist/cli/commands/memory.d.ts.map +1 -1
- package/dist/cli/commands/memory.js +51 -57
- package/dist/cli/commands/memory.js.map +1 -1
- package/dist/cli/commands/misc.d.ts +1 -15
- package/dist/cli/commands/misc.d.ts.map +1 -1
- package/dist/cli/commands/misc.js +36 -215
- package/dist/cli/commands/misc.js.map +1 -1
- package/dist/cli/commands/plans.d.ts +0 -6
- package/dist/cli/commands/plans.d.ts.map +1 -1
- package/dist/cli/commands/plans.js +9 -77
- package/dist/cli/commands/plans.js.map +1 -1
- package/dist/cli/commands/skills.js +6 -6
- package/dist/cli/commands/skills.js.map +1 -1
- package/dist/cli/commands/task.js +4 -4
- package/dist/cli/commands/task.js.map +1 -1
- package/dist/cli/commands/update.d.ts.map +1 -1
- package/dist/cli/commands/update.js +122 -52
- package/dist/cli/commands/update.js.map +1 -1
- package/dist/cli/prompts.d.ts.map +1 -1
- package/dist/cli/prompts.js +1 -78
- package/dist/cli/prompts.js.map +1 -1
- package/dist/core/claude/claude-mcp.d.ts +59 -0
- package/dist/core/claude/claude-mcp.d.ts.map +1 -0
- package/dist/core/claude/claude-mcp.js +220 -0
- package/dist/core/claude/claude-mcp.js.map +1 -0
- package/dist/core/claude/claude-md-generator.d.ts +52 -0
- package/dist/core/claude/claude-md-generator.d.ts.map +1 -0
- package/dist/core/claude/claude-md-generator.js +104 -0
- package/dist/core/claude/claude-md-generator.js.map +1 -0
- package/dist/core/claude/claude-settings-manager.d.ts +44 -0
- package/dist/core/claude/claude-settings-manager.d.ts.map +1 -0
- package/dist/core/claude/claude-settings-manager.js +194 -0
- package/dist/core/claude/claude-settings-manager.js.map +1 -0
- package/dist/core/claude-settings-manager.d.ts.map +1 -1
- package/dist/core/claude-settings-manager.js +9 -3
- package/dist/core/claude-settings-manager.js.map +1 -1
- package/dist/core/console/cli-bridge.d.ts +113 -0
- package/dist/core/console/cli-bridge.d.ts.map +1 -0
- package/dist/core/console/cli-bridge.js +1094 -0
- package/dist/core/console/cli-bridge.js.map +1 -0
- package/dist/core/detect/detector.d.ts +35 -0
- package/dist/core/detect/detector.d.ts.map +1 -0
- package/dist/core/detect/detector.js +541 -0
- package/dist/core/detect/detector.js.map +1 -0
- package/dist/core/docs/docs-generator.d.ts +9 -0
- package/dist/core/docs/docs-generator.d.ts.map +1 -0
- package/dist/core/docs/docs-generator.js +531 -0
- package/dist/core/docs/docs-generator.js.map +1 -0
- package/dist/core/docs/mcp-reference-generator.d.ts +13 -0
- package/dist/core/docs/mcp-reference-generator.d.ts.map +1 -0
- package/dist/core/docs/mcp-reference-generator.js +66 -0
- package/dist/core/docs/mcp-reference-generator.js.map +1 -0
- package/dist/core/generators/generator.d.ts +54 -0
- package/dist/core/generators/generator.d.ts.map +1 -0
- package/dist/core/generators/generator.js +1041 -0
- package/dist/core/generators/generator.js.map +1 -0
- package/dist/core/generators/gitignore-generator.d.ts +13 -0
- package/dist/core/generators/gitignore-generator.d.ts.map +1 -0
- package/dist/core/generators/gitignore-generator.js +307 -0
- package/dist/core/generators/gitignore-generator.js.map +1 -0
- package/dist/core/generators/minimal-scaffolder.d.ts +8 -0
- package/dist/core/generators/minimal-scaffolder.d.ts.map +1 -0
- package/dist/core/generators/minimal-scaffolder.js +51 -0
- package/dist/core/generators/minimal-scaffolder.js.map +1 -0
- package/dist/core/generators/rules-generator.d.ts +73 -0
- package/dist/core/generators/rules-generator.d.ts.map +1 -0
- package/dist/core/generators/rules-generator.js +202 -0
- package/dist/core/generators/rules-generator.js.map +1 -0
- package/dist/core/generators/workflow-generator.d.ts +15 -0
- package/dist/core/generators/workflow-generator.d.ts.map +1 -0
- package/dist/core/generators/workflow-generator.js +390 -0
- package/dist/core/generators/workflow-generator.js.map +1 -0
- package/dist/core/ide/multi-tool-generator.d.ts +59 -0
- package/dist/core/ide/multi-tool-generator.d.ts.map +1 -0
- package/dist/core/ide/multi-tool-generator.js +157 -0
- package/dist/core/ide/multi-tool-generator.js.map +1 -0
- package/dist/core/ide/opencode-generator.d.ts +72 -0
- package/dist/core/ide/opencode-generator.d.ts.map +1 -0
- package/dist/core/ide/opencode-generator.js +450 -0
- package/dist/core/ide/opencode-generator.js.map +1 -0
- package/dist/core/merger.d.ts +1 -1
- package/dist/core/merger.d.ts.map +1 -1
- package/dist/core/merger.js +5 -5
- package/dist/core/merger.js.map +1 -1
- package/dist/core/migrator.d.ts +0 -1
- package/dist/core/migrator.d.ts.map +1 -1
- package/dist/core/migrator.js +4 -29
- package/dist/core/migrator.js.map +1 -1
- package/dist/core/quality/coverage-checker.d.ts +14 -0
- package/dist/core/quality/coverage-checker.d.ts.map +1 -0
- package/dist/core/quality/coverage-checker.js +176 -0
- package/dist/core/quality/coverage-checker.js.map +1 -0
- package/dist/core/quality/dependency-checker.d.ts +21 -0
- package/dist/core/quality/dependency-checker.d.ts.map +1 -0
- package/dist/core/quality/dependency-checker.js +247 -0
- package/dist/core/quality/dependency-checker.js.map +1 -0
- package/dist/core/quality/doctor.d.ts +19 -0
- package/dist/core/quality/doctor.d.ts.map +1 -0
- package/dist/core/quality/doctor.js +163 -0
- package/dist/core/quality/doctor.js.map +1 -0
- package/dist/core/quality/validator.d.ts +21 -0
- package/dist/core/quality/validator.d.ts.map +1 -0
- package/dist/core/quality/validator.js +177 -0
- package/dist/core/quality/validator.js.map +1 -0
- package/dist/core/ralph-scripts.d.ts.map +1 -1
- package/dist/core/ralph-scripts.js +7 -6
- package/dist/core/ralph-scripts.js.map +1 -1
- package/dist/core/skills/skills-manager.d.ts +126 -0
- package/dist/core/skills/skills-manager.d.ts.map +1 -0
- package/dist/core/skills/skills-manager.js +630 -0
- package/dist/core/skills/skills-manager.js.map +1 -0
- package/dist/core/state/config-manager.d.ts +86 -0
- package/dist/core/state/config-manager.d.ts.map +1 -0
- package/dist/core/state/config-manager.js +562 -0
- package/dist/core/state/config-manager.js.map +1 -0
- package/dist/core/state/override-manager.d.ts +23 -0
- package/dist/core/state/override-manager.d.ts.map +1 -0
- package/dist/core/state/override-manager.js +82 -0
- package/dist/core/state/override-manager.js.map +1 -0
- package/dist/core/state/state-writer.d.ts +34 -0
- package/dist/core/state/state-writer.d.ts.map +1 -0
- package/dist/core/state/state-writer.js +78 -0
- package/dist/core/state/state-writer.js.map +1 -0
- package/dist/core/state/version-bumper.d.ts +19 -0
- package/dist/core/state/version-bumper.d.ts.map +1 -0
- package/dist/core/state/version-bumper.js +180 -0
- package/dist/core/state/version-bumper.js.map +1 -0
- package/dist/core/tasks/decision-manager.d.ts +25 -0
- package/dist/core/tasks/decision-manager.d.ts.map +1 -0
- package/dist/core/tasks/decision-manager.js +183 -0
- package/dist/core/tasks/decision-manager.js.map +1 -0
- package/dist/core/tasks/knowledge-manager.d.ts +24 -0
- package/dist/core/tasks/knowledge-manager.d.ts.map +1 -0
- package/dist/core/tasks/knowledge-manager.js +173 -0
- package/dist/core/tasks/knowledge-manager.js.map +1 -0
- package/dist/core/tasks/learn-manager.d.ts +27 -0
- package/dist/core/tasks/learn-manager.d.ts.map +1 -0
- package/dist/core/tasks/learn-manager.js +121 -0
- package/dist/core/tasks/learn-manager.js.map +1 -0
- package/dist/core/tasks/plans-manager.d.ts +46 -0
- package/dist/core/tasks/plans-manager.d.ts.map +1 -0
- package/dist/core/tasks/plans-manager.js +158 -0
- package/dist/core/tasks/plans-manager.js.map +1 -0
- package/dist/core/tasks/task-manager.d.ts +127 -0
- package/dist/core/tasks/task-manager.d.ts.map +1 -0
- package/dist/core/tasks/task-manager.js +607 -0
- package/dist/core/tasks/task-manager.js.map +1 -0
- package/dist/core/workspace/project-worker.d.ts +6 -6
- package/dist/core/workspace/project-worker.d.ts.map +1 -1
- package/dist/core/workspace/project-worker.js +6 -6
- package/dist/core/workspace/project-worker.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -176
- package/dist/index.js.map +1 -1
- package/dist/mcp/rulebook-server.d.ts.map +1 -1
- package/dist/mcp/rulebook-server.js +16 -960
- package/dist/mcp/rulebook-server.js.map +1 -1
- package/dist/memory/file-search.d.ts +43 -0
- package/dist/memory/file-search.d.ts.map +1 -0
- package/dist/memory/file-search.js +228 -0
- package/dist/memory/file-search.js.map +1 -0
- package/dist/memory/file-store.d.ts +99 -0
- package/dist/memory/file-store.d.ts.map +1 -0
- package/dist/memory/file-store.js +615 -0
- package/dist/memory/file-store.js.map +1 -0
- package/dist/memory/legacy-migrator.d.ts +27 -0
- package/dist/memory/legacy-migrator.d.ts.map +1 -0
- package/dist/memory/legacy-migrator.js +185 -0
- package/dist/memory/legacy-migrator.js.map +1 -0
- package/dist/memory/memory-manager.d.ts +25 -24
- package/dist/memory/memory-manager.d.ts.map +1 -1
- package/dist/memory/memory-manager.js +97 -140
- package/dist/memory/memory-manager.js.map +1 -1
- package/dist/memory/memory-types.d.ts +1 -1
- package/dist/memory/memory-types.d.ts.map +1 -1
- package/dist/types.d.ts +8 -119
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/file-system.d.ts +22 -0
- package/dist/utils/file-system.d.ts.map +1 -1
- package/dist/utils/file-system.js +31 -0
- package/dist/utils/file-system.js.map +1 -1
- package/dist/utils/git-hooks.d.ts.map +1 -1
- package/dist/utils/git-hooks.js +3 -2
- package/dist/utils/git-hooks.js.map +1 -1
- package/package.json +2 -6
- package/templates/agents/context-intelligence.md +50 -52
- package/templates/cli/OPENCODE.md +85 -18
- package/templates/commands/rulebook-learn-capture.md +41 -48
- package/templates/commands/rulebook-learn-list.md +13 -13
- package/templates/core/AGENTS_LEAN.md +0 -14
- package/templates/hooks/check-context-and-handoff.sh +74 -76
- package/templates/hooks/enforce-pre-tool.sh +70 -0
- package/templates/hooks/enforce-team-for-background-agents.sh +55 -55
- package/templates/hooks/on-compact-reinject.sh +34 -34
- package/templates/hooks/resume-from-handoff.sh +61 -61
- package/templates/hooks/terse-activate.sh +197 -197
- package/templates/hooks/terse-mode-tracker.sh +190 -187
- package/templates/ides/OPENCODE.md +63 -0
- package/templates/skills/cli/opencode/SKILL.md +82 -28
- package/.claude/commands/ralph-config.md +0 -112
- package/.claude/commands/ralph-history.md +0 -110
- package/.claude/commands/ralph-init.md +0 -72
- package/.claude/commands/ralph-pause-resume.md +0 -105
- package/.claude/commands/ralph-run.md +0 -101
- package/.claude/commands/ralph-status.md +0 -76
- package/templates/core/RALPH.md +0 -471
- package/templates/frameworks/ANGULAR.md +0 -36
- package/templates/frameworks/DJANGO.md +0 -83
- package/templates/frameworks/ELECTRON.md +0 -147
- package/templates/frameworks/FLASK.md +0 -38
- package/templates/frameworks/FLUTTER.md +0 -55
- package/templates/frameworks/JQUERY.md +0 -32
- package/templates/frameworks/LARAVEL.md +0 -38
- package/templates/frameworks/NESTJS.md +0 -43
- package/templates/frameworks/NEXTJS.md +0 -127
- package/templates/frameworks/NUXT.md +0 -40
- package/templates/frameworks/RAILS.md +0 -66
- package/templates/frameworks/REACT.md +0 -38
- package/templates/frameworks/REACT_NATIVE.md +0 -47
- package/templates/frameworks/SPRING.md +0 -39
- package/templates/frameworks/SYMFONY.md +0 -36
- package/templates/frameworks/VUE.md +0 -36
- package/templates/frameworks/ZEND.md +0 -35
- package/templates/hooks/enforce-mcp-for-tasks.sh +0 -31
- package/templates/hooks/enforce-no-deferred.sh +0 -21
- package/templates/hooks/enforce-no-shortcuts.sh +0 -31
- package/templates/ides/COPILOT.md +0 -37
- package/templates/ides/CURSOR.md +0 -43
- package/templates/ides/JETBRAINS_AI.md +0 -35
- package/templates/ides/REPLIT.md +0 -36
- package/templates/ides/TABNINE.md +0 -29
- package/templates/ides/VSCODE.md +0 -40
- package/templates/ides/WINDSURF.md +0 -36
- package/templates/ides/ZED.md +0 -32
- package/templates/ides/cursor-mdc/go.mdc +0 -24
- package/templates/ides/cursor-mdc/python.mdc +0 -24
- package/templates/ides/cursor-mdc/quality.mdc +0 -25
- package/templates/ides/cursor-mdc/ralph.mdc +0 -39
- package/templates/ides/cursor-mdc/rulebook.mdc +0 -38
- package/templates/ides/cursor-mdc/rust.mdc +0 -24
- package/templates/ides/cursor-mdc/typescript.mdc +0 -25
- package/templates/ralph/ralph-history.bat +0 -4
- package/templates/ralph/ralph-history.sh +0 -5
- package/templates/ralph/ralph-init.bat +0 -5
- package/templates/ralph/ralph-init.sh +0 -5
- package/templates/ralph/ralph-pause.bat +0 -5
- package/templates/ralph/ralph-pause.sh +0 -5
- package/templates/ralph/ralph-run.bat +0 -5
- package/templates/ralph/ralph-run.sh +0 -5
- package/templates/ralph/ralph-status.bat +0 -4
- package/templates/ralph/ralph-status.sh +0 -5
- package/templates/services/AZURE_BLOB.md +0 -184
- package/templates/services/CASSANDRA.md +0 -239
- package/templates/services/DATADOG.md +0 -26
- package/templates/services/DOCKER.md +0 -124
- package/templates/services/DOCKER_COMPOSE.md +0 -168
- package/templates/services/DYNAMODB.md +0 -308
- package/templates/services/ELASTICSEARCH.md +0 -347
- package/templates/services/GCS.md +0 -178
- package/templates/services/HELM.md +0 -194
- package/templates/services/INFLUXDB.md +0 -265
- package/templates/services/KAFKA.md +0 -341
- package/templates/services/KUBERNETES.md +0 -208
- package/templates/services/MARIADB.md +0 -183
- package/templates/services/MEMCACHED.md +0 -242
- package/templates/services/MINIO.md +0 -201
- package/templates/services/MONGODB.md +0 -268
- package/templates/services/MYSQL.md +0 -358
- package/templates/services/NEO4J.md +0 -247
- package/templates/services/OPENTELEMETRY.md +0 -25
- package/templates/services/ORACLE.md +0 -290
- package/templates/services/PINO.md +0 -24
- package/templates/services/POSTGRESQL.md +0 -326
- package/templates/services/PROMETHEUS.md +0 -33
- package/templates/services/RABBITMQ.md +0 -286
- package/templates/services/REDIS.md +0 -292
- package/templates/services/S3.md +0 -298
- package/templates/services/SENTRY.md +0 -23
- package/templates/services/SQLITE.md +0 -294
- package/templates/services/SQLSERVER.md +0 -294
- package/templates/services/WINSTON.md +0 -30
- package/templates/skills/frameworks/angular/SKILL.md +0 -46
- package/templates/skills/frameworks/django/SKILL.md +0 -93
- package/templates/skills/frameworks/electron/SKILL.md +0 -157
- package/templates/skills/frameworks/flask/SKILL.md +0 -48
- package/templates/skills/frameworks/flutter/SKILL.md +0 -65
- package/templates/skills/frameworks/jquery/SKILL.md +0 -42
- package/templates/skills/frameworks/laravel/SKILL.md +0 -48
- package/templates/skills/frameworks/nestjs/SKILL.md +0 -53
- package/templates/skills/frameworks/nextjs/SKILL.md +0 -137
- package/templates/skills/frameworks/nuxt/SKILL.md +0 -50
- package/templates/skills/frameworks/rails/SKILL.md +0 -76
- package/templates/skills/frameworks/react/SKILL.md +0 -48
- package/templates/skills/frameworks/react-native/SKILL.md +0 -57
- package/templates/skills/frameworks/spring/SKILL.md +0 -49
- package/templates/skills/frameworks/symfony/SKILL.md +0 -46
- package/templates/skills/frameworks/vue/SKILL.md +0 -46
- package/templates/skills/frameworks/zend/SKILL.md +0 -45
- package/templates/skills/services/azure-blob/SKILL.md +0 -194
- package/templates/skills/services/cassandra/SKILL.md +0 -249
- package/templates/skills/services/dynamodb/SKILL.md +0 -318
- package/templates/skills/services/elasticsearch/SKILL.md +0 -357
- package/templates/skills/services/gcs/SKILL.md +0 -188
- package/templates/skills/services/influxdb/SKILL.md +0 -275
- package/templates/skills/services/kafka/SKILL.md +0 -351
- package/templates/skills/services/mariadb/SKILL.md +0 -193
- package/templates/skills/services/memcached/SKILL.md +0 -252
- package/templates/skills/services/minio/SKILL.md +0 -211
- package/templates/skills/services/mongodb/SKILL.md +0 -278
- package/templates/skills/services/mysql/SKILL.md +0 -368
- package/templates/skills/services/neo4j/SKILL.md +0 -257
- package/templates/skills/services/oracle/SKILL.md +0 -300
- package/templates/skills/services/postgresql/SKILL.md +0 -336
- package/templates/skills/services/rabbitmq/SKILL.md +0 -296
- package/templates/skills/services/redis/SKILL.md +0 -302
- package/templates/skills/services/s3/SKILL.md +0 -308
- package/templates/skills/services/sqlite/SKILL.md +0 -304
- package/templates/skills/services/sqlserver/SKILL.md +0 -304
- package/templates/skills/workflows/ralph/SETUP.md +0 -228
- package/templates/skills/workflows/ralph/SKILL.md +0 -309
- package/templates/skills/workflows/ralph/install.sh +0 -87
- package/templates/skills/workflows/ralph/manifest.json +0 -158
|
@@ -1,52 +1,50 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: context-intelligence
|
|
3
|
-
model: haiku
|
|
4
|
-
description: Manages project decisions, knowledge base, and learnings. Use for capturing ADRs, patterns/anti-patterns, and post-implementation learnings.
|
|
5
|
-
tools: Read, Glob, Grep, Bash, Write, Edit
|
|
6
|
-
maxTurns: 15
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
You are a context-intelligence agent. Your primary responsibility is managing the project's institutional knowledge: decisions, patterns, and learnings.
|
|
10
|
-
|
|
11
|
-
## Responsibilities
|
|
12
|
-
|
|
13
|
-
- Create and manage Architecture Decision Records (ADRs) via `rulebook decision`
|
|
14
|
-
- Add patterns and anti-patterns to the knowledge base via `rulebook knowledge`
|
|
15
|
-
- Capture and promote learnings via `rulebook learn`
|
|
16
|
-
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
-
|
|
49
|
-
-
|
|
50
|
-
-
|
|
51
|
-
- Tag all entries for searchability
|
|
52
|
-
- When promoting a learning, verify the promoted entry is complete
|
|
1
|
+
---
|
|
2
|
+
name: context-intelligence
|
|
3
|
+
model: haiku
|
|
4
|
+
description: Manages project decisions, knowledge base, and learnings. Use for capturing ADRs, patterns/anti-patterns, and post-implementation learnings.
|
|
5
|
+
tools: Read, Glob, Grep, Bash, Write, Edit
|
|
6
|
+
maxTurns: 15
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
You are a context-intelligence agent. Your primary responsibility is managing the project's institutional knowledge: decisions, patterns, and learnings.
|
|
10
|
+
|
|
11
|
+
## Responsibilities
|
|
12
|
+
|
|
13
|
+
- Create and manage Architecture Decision Records (ADRs) via `rulebook decision`
|
|
14
|
+
- Add patterns and anti-patterns to the knowledge base via `rulebook knowledge`
|
|
15
|
+
- Capture and promote learnings via `rulebook learn`
|
|
16
|
+
- Ensure decisions have proper context, alternatives, and consequences
|
|
17
|
+
|
|
18
|
+
## Workflow
|
|
19
|
+
|
|
20
|
+
### When creating a decision:
|
|
21
|
+
1. Check existing decisions: `rulebook decision list`
|
|
22
|
+
2. Create: `rulebook decision create "<title>" --context "<context>"`
|
|
23
|
+
3. Enrich the `.rulebook/decisions/NNN-<slug>.md` file with full details
|
|
24
|
+
4. Verify: `rulebook decision show <id>`
|
|
25
|
+
|
|
26
|
+
### When adding knowledge:
|
|
27
|
+
1. Check existing entries: `rulebook knowledge list`
|
|
28
|
+
2. Create: `rulebook knowledge add <pattern|anti-pattern> "<title>" --category <cat>`
|
|
29
|
+
3. Enrich `.rulebook/knowledge/<type>s/<slug>.md` with examples and guidelines
|
|
30
|
+
4. Verify: `rulebook knowledge show <slug>`
|
|
31
|
+
|
|
32
|
+
### When capturing learnings:
|
|
33
|
+
1. Capture: `rulebook learn capture --title "<title>" --content "<content>" --tags "tag1,tag2"`
|
|
34
|
+
2. Promote significant learnings: `rulebook learn promote <id> knowledge|decision`
|
|
35
|
+
|
|
36
|
+
## Standards
|
|
37
|
+
|
|
38
|
+
1. Every decision MUST include context, the decision, alternatives, and consequences
|
|
39
|
+
2. Patterns MUST include concrete code examples (not abstract descriptions)
|
|
40
|
+
3. Anti-patterns MUST explain what to do instead
|
|
41
|
+
4. Learnings should be captured immediately after discovery, not batched
|
|
42
|
+
5. Use descriptive titles — they appear in AGENTS.md for AI context
|
|
43
|
+
|
|
44
|
+
## Rules
|
|
45
|
+
|
|
46
|
+
- Do NOT modify production source code — only `.rulebook/` files
|
|
47
|
+
- Do NOT delete decisions — supersede or deprecate them
|
|
48
|
+
- Knowledge entries auto-appear in AGENTS.md after `rulebook update`
|
|
49
|
+
- Tag all entries for searchability
|
|
50
|
+
- When promoting a learning, verify the promoted entry is complete
|
|
@@ -1,18 +1,85 @@
|
|
|
1
|
-
<!-- OPENCODE:START -->
|
|
2
|
-
# OpenCode Rules
|
|
3
|
-
|
|
4
|
-
**Tool**:
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
<!-- OPENCODE:START -->
|
|
2
|
+
# OpenCode Rules
|
|
3
|
+
|
|
4
|
+
**Tool**: [OpenCode](https://opencode.ai) — open-source terminal coding agent (SST).
|
|
5
|
+
|
|
6
|
+
OpenCode reads `AGENTS.md` natively (with `CLAUDE.md` as fallback). When
|
|
7
|
+
Rulebook is initialized in this project, OpenCode also gets:
|
|
8
|
+
|
|
9
|
+
- `opencode.json` — declares the rulebook MCP server and lazy-loads the
|
|
10
|
+
project rule files via the `instructions` array.
|
|
11
|
+
- `.opencode/commands/` — mirrors Rulebook's user-invocable slash commands
|
|
12
|
+
(`/handoff`, `/rulebook-task-*`, `/rulebook-decision-*`,
|
|
13
|
+
`/rulebook-knowledge-*`, `/rulebook-memory-*`, `/rulebook-learn-*`).
|
|
14
|
+
- `.opencode/agents/` — mirrors role agents (`researcher`, `implementer`,
|
|
15
|
+
`tester`, `code-reviewer`, `architect`, etc.) translated to OpenCode's
|
|
16
|
+
frontmatter schema (`mode`, `model`, `permission`).
|
|
17
|
+
- `.opencode/skills/` — mirrors the dev skill library normalized to
|
|
18
|
+
OpenCode's strict skill-name regex.
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
# Install OpenCode
|
|
24
|
+
curl -fsSL https://opencode.ai/install | bash
|
|
25
|
+
|
|
26
|
+
# In a Rulebook-managed project, OpenCode picks up everything automatically:
|
|
27
|
+
opencode
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Workflow
|
|
31
|
+
|
|
32
|
+
1. **Reference rules** — `AGENTS.md`, `AGENTS.override.md`, and
|
|
33
|
+
`.rulebook/specs/*.md` are wired into `instructions` so the model
|
|
34
|
+
has them on demand without burning context.
|
|
35
|
+
2. **Use slash commands** — type `/rulebook-task-create`,
|
|
36
|
+
`/rulebook-task-list`, `/handoff`, etc. They're real OpenCode
|
|
37
|
+
commands, not just prompt text.
|
|
38
|
+
3. **Delegate to role agents** — `@researcher analyze X`,
|
|
39
|
+
`@implementer add Y`, `@tester cover Z`. Each role has its own
|
|
40
|
+
`model`, `permission`, and `description` matching the Rulebook
|
|
41
|
+
delegation table.
|
|
42
|
+
4. **Quality checks** — type-check / lint / test before committing,
|
|
43
|
+
per `AGENTS.md` quality-gate rules.
|
|
44
|
+
5. **Save learnings** — `rulebook memory save`, `rulebook knowledge add`,
|
|
45
|
+
`rulebook learn capture`, or invoke the corresponding slash commands.
|
|
46
|
+
|
|
47
|
+
## Sequential editing
|
|
48
|
+
|
|
49
|
+
OpenCode is held to the same Rulebook discipline as Claude Code:
|
|
50
|
+
|
|
51
|
+
- Edit files **one at a time** (Read → Edit → Read → Edit), not in batch.
|
|
52
|
+
- For 3+ files across subsystems, decompose into 1–2 file sub-tasks.
|
|
53
|
+
- Run diagnostics (type-check / lint) **before** the test suite.
|
|
54
|
+
|
|
55
|
+
## MCP & token usage
|
|
56
|
+
|
|
57
|
+
The `mcp.rulebook` entry in `opencode.json` exposes the full Rulebook
|
|
58
|
+
MCP toolset (`rulebook_task_*`, `rulebook_memory_*`, `rulebook_decision_*`,
|
|
59
|
+
`rulebook_knowledge_*`, etc.). Prefer MCP tools over shell commands when
|
|
60
|
+
both exist — they're faster, structured, and don't pollute context.
|
|
61
|
+
|
|
62
|
+
Output discipline: prefer concise output. Don't generate "Quality Checks"
|
|
63
|
+
status tables, "Next Steps" sections, or restate the question. Put
|
|
64
|
+
implementation details in code comments, not markdown.
|
|
65
|
+
|
|
66
|
+
## Isolation from Claude Code
|
|
67
|
+
|
|
68
|
+
OpenCode falls back to `CLAUDE.md` if `AGENTS.md` is absent. To force
|
|
69
|
+
OpenCode to ignore a `CLAUDE.md` shared with Claude Code, set:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
export OPENCODE_DISABLE_CLAUDE_CODE=*
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Documentation
|
|
76
|
+
|
|
77
|
+
- [opencode.ai/docs/rules](https://opencode.ai/docs/rules/)
|
|
78
|
+
- [opencode.ai/docs/config](https://opencode.ai/docs/config/)
|
|
79
|
+
- [opencode.ai/docs/mcp-servers](https://opencode.ai/docs/mcp-servers/)
|
|
80
|
+
- [opencode.ai/docs/commands](https://opencode.ai/docs/commands/)
|
|
81
|
+
- [opencode.ai/docs/agents](https://opencode.ai/docs/agents/)
|
|
82
|
+
- [opencode.ai/docs/skills](https://opencode.ai/docs/skills/)
|
|
83
|
+
- [opencode.ai/docs/permissions](https://opencode.ai/docs/permissions/)
|
|
84
|
+
|
|
85
|
+
<!-- OPENCODE:END -->
|
|
@@ -1,48 +1,41 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: /rulebook-learn-capture
|
|
3
|
-
id: rulebook-learn-capture
|
|
4
|
-
category: Rulebook
|
|
5
|
-
description: Capture a learning from implementation work for future reference.
|
|
6
|
-
---
|
|
7
|
-
<!-- RULEBOOK:START -->
|
|
8
|
-
**Guardrails**
|
|
9
|
-
- Learnings are saved to both the memory system and `.rulebook/learnings/` for offline backup.
|
|
10
|
-
- Learnings can be promoted to patterns/decisions later via `rulebook learn promote`.
|
|
11
|
-
|
|
12
|
-
**Steps**
|
|
13
|
-
1. **Gather the Learning**:
|
|
14
|
-
- **Title**: Short description of what was learned
|
|
15
|
-
- **Content**: Full explanation — what happened, what was discovered, why it matters
|
|
16
|
-
- **Tags**: Keywords for searchability
|
|
17
|
-
- **Related Task**: Task ID if this learning came from a specific task
|
|
18
|
-
- **Source**: `manual` (default)
|
|
19
|
-
|
|
20
|
-
2. **Capture**:
|
|
21
|
-
```bash
|
|
22
|
-
rulebook learn capture --title "<title>" --content "<content>" --tags "tag1,tag2" --related-task <task-id>
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
3. **Verify**:
|
|
26
|
-
```bash
|
|
27
|
-
rulebook learn list --limit 5
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
**Promotion Flow**
|
|
31
|
-
If a learning is significant enough to become a team pattern or decision:
|
|
32
|
-
```bash
|
|
33
|
-
rulebook learn promote <id> knowledge # → creates a pattern
|
|
34
|
-
rulebook learn promote <id> decision # → creates an ADR
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
rulebook
|
|
41
|
-
|
|
42
|
-
This reads `.rulebook/ralph/history/iteration-*.json` and captures entries with non-empty learnings.
|
|
43
|
-
|
|
44
|
-
**Reference**
|
|
45
|
-
- Learnings are searchable via `rulebook memory search`
|
|
46
|
-
- Use `rulebook learn list` to see all learnings
|
|
47
|
-
- Learnings captured during `rulebook task archive` have source `task-archive`
|
|
48
|
-
<!-- RULEBOOK:END -->
|
|
1
|
+
---
|
|
2
|
+
name: /rulebook-learn-capture
|
|
3
|
+
id: rulebook-learn-capture
|
|
4
|
+
category: Rulebook
|
|
5
|
+
description: Capture a learning from implementation work for future reference.
|
|
6
|
+
---
|
|
7
|
+
<!-- RULEBOOK:START -->
|
|
8
|
+
**Guardrails**
|
|
9
|
+
- Learnings are saved to both the memory system and `.rulebook/learnings/` for offline backup.
|
|
10
|
+
- Learnings can be promoted to patterns/decisions later via `rulebook learn promote`.
|
|
11
|
+
|
|
12
|
+
**Steps**
|
|
13
|
+
1. **Gather the Learning**:
|
|
14
|
+
- **Title**: Short description of what was learned
|
|
15
|
+
- **Content**: Full explanation — what happened, what was discovered, why it matters
|
|
16
|
+
- **Tags**: Keywords for searchability
|
|
17
|
+
- **Related Task**: Task ID if this learning came from a specific task
|
|
18
|
+
- **Source**: `manual` (default) or `task-archive`
|
|
19
|
+
|
|
20
|
+
2. **Capture**:
|
|
21
|
+
```bash
|
|
22
|
+
rulebook learn capture --title "<title>" --content "<content>" --tags "tag1,tag2" --related-task <task-id>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
3. **Verify**:
|
|
26
|
+
```bash
|
|
27
|
+
rulebook learn list --limit 5
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**Promotion Flow**
|
|
31
|
+
If a learning is significant enough to become a team pattern or decision:
|
|
32
|
+
```bash
|
|
33
|
+
rulebook learn promote <id> knowledge # → creates a pattern
|
|
34
|
+
rulebook learn promote <id> decision # → creates an ADR
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Reference**
|
|
38
|
+
- Learnings are searchable via `rulebook memory search`
|
|
39
|
+
- Use `rulebook learn list` to see all learnings
|
|
40
|
+
- Learnings captured during `rulebook task archive` have source `task-archive`
|
|
41
|
+
<!-- RULEBOOK:END -->
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: /rulebook-learn-list
|
|
3
|
-
id: rulebook-learn-list
|
|
4
|
-
category: Rulebook
|
|
5
|
-
description: List captured learnings with source and promotion status.
|
|
6
|
-
---
|
|
7
|
-
<!-- RULEBOOK:START -->
|
|
8
|
-
**Steps**
|
|
9
|
-
1. Run `rulebook learn list` to see all learnings (newest first).
|
|
10
|
-
2. Optionally limit: `rulebook learn list --limit 10`
|
|
11
|
-
3. Present results with source badge (manual/
|
|
12
|
-
4. Suggest promotion for significant learnings: `rulebook learn promote <id> knowledge|decision`
|
|
13
|
-
<!-- RULEBOOK:END -->
|
|
1
|
+
---
|
|
2
|
+
name: /rulebook-learn-list
|
|
3
|
+
id: rulebook-learn-list
|
|
4
|
+
category: Rulebook
|
|
5
|
+
description: List captured learnings with source and promotion status.
|
|
6
|
+
---
|
|
7
|
+
<!-- RULEBOOK:START -->
|
|
8
|
+
**Steps**
|
|
9
|
+
1. Run `rulebook learn list` to see all learnings (newest first).
|
|
10
|
+
2. Optionally limit: `rulebook learn list --limit 10`
|
|
11
|
+
3. Present results with source badge (manual/archive) and promotion status.
|
|
12
|
+
4. Suggest promotion for significant learnings: `rulebook learn promote <id> knowledge|decision`
|
|
13
|
+
<!-- RULEBOOK:END -->
|
|
@@ -157,20 +157,6 @@ LANGUAGE_REFS
|
|
|
157
157
|
|
|
158
158
|
MODULE_REFS
|
|
159
159
|
|
|
160
|
-
## Ralph Autonomous Loop
|
|
161
|
-
|
|
162
|
-
5-gate quality enforcement (type-check, lint, tests, coverage, security) per iteration, fresh context per iteration, parallel story execution, plan checkpoints, learning extraction.
|
|
163
|
-
|
|
164
|
-
```bash
|
|
165
|
-
rulebook ralph init # Generate PRD from tasks
|
|
166
|
-
rulebook ralph run --max-iterations 10
|
|
167
|
-
rulebook ralph status / history / pause / resume
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
PRD format: `userStories` array with `id`, `title`, `description`, `acceptanceCriteria`, `priority`, `passes: boolean`, `notes`. Status tracked via `passes`, NOT enum.
|
|
171
|
-
|
|
172
|
-
Iteration records in `.rulebook/ralph/history/iteration-N.json`. Status: `success` (5/5 gates), `partial` (2-4), `failed` (0-1).
|
|
173
|
-
|
|
174
160
|
## Multi-Agent Teams
|
|
175
161
|
|
|
176
162
|
Requires `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1`. Background `Agent` calls **must** use a Team (`team_name` parameter) — standalone background agents can't communicate via `SendMessage`. Foreground calls and `team-lead` agents are exempt.
|
|
@@ -1,76 +1,74 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Claude Code Stop hook — context freshness monitor.
|
|
3
|
-
#
|
|
4
|
-
# Runs after every model turn. Estimates the current context usage
|
|
5
|
-
# from the JSONL transcript and, when it exceeds the configured
|
|
6
|
-
# threshold, emits additionalContext instructing the model to invoke
|
|
7
|
-
# the /handoff skill and tell the user to type /clear.
|
|
8
|
-
#
|
|
9
|
-
# Thresholds are read from .rulebook/rulebook.json `handoff` section.
|
|
10
|
-
# Defaults: warn=75, force=90 (percentage of estimated max context).
|
|
11
|
-
|
|
12
|
-
set -euo pipefail
|
|
13
|
-
|
|
14
|
-
# Read the hook input from stdin (Claude Code passes it as JSON)
|
|
15
|
-
input="$(cat)"
|
|
16
|
-
|
|
17
|
-
# Resolve project root from hook input cwd, NOT $(pwd) — the hook may be
|
|
18
|
-
# invoked from a sub-directory the user is currently editing.
|
|
19
|
-
PROJECT_ROOT=""
|
|
20
|
-
if [[ -n "$input" ]] && command -v jq &>/dev/null; then
|
|
21
|
-
PROJECT_ROOT="$(printf '%s' "$input" | jq -r '.cwd // empty' 2>/dev/null || true)"
|
|
22
|
-
fi
|
|
23
|
-
[[ -z "$PROJECT_ROOT" ]] && PROJECT_ROOT="${CLAUDE_PROJECT_DIR:-$(pwd)}"
|
|
24
|
-
|
|
25
|
-
CONFIG_FILE="${PROJECT_ROOT}/.rulebook/rulebook.json"
|
|
26
|
-
HANDOFF_DIR="${PROJECT_ROOT}/.rulebook/handoff"
|
|
27
|
-
|
|
28
|
-
# Defaults
|
|
29
|
-
WARN_PCT=75
|
|
30
|
-
FORCE_PCT=90
|
|
31
|
-
MAX_CONTEXT_CHARS=1600000 # ~400k tokens ≈ 1.6M chars (rough 1:4 ratio)
|
|
32
|
-
|
|
33
|
-
# Override from config if available
|
|
34
|
-
if [[ -f "$CONFIG_FILE" ]] && command -v jq &>/dev/null; then
|
|
35
|
-
WARN_PCT=$(jq -r '.handoff.warnThresholdPct // 75' "$CONFIG_FILE" 2>/dev/null || echo 75)
|
|
36
|
-
FORCE_PCT=$(jq -r '.handoff.forceThresholdPct // 90' "$CONFIG_FILE" 2>/dev/null || echo 90)
|
|
37
|
-
fi
|
|
38
|
-
|
|
39
|
-
#
|
|
40
|
-
#
|
|
41
|
-
#
|
|
42
|
-
#
|
|
43
|
-
transcript_size=0
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if [[ -
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
fi
|
|
76
|
-
exit 0
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Claude Code Stop hook — context freshness monitor.
|
|
3
|
+
#
|
|
4
|
+
# Runs after every model turn. Estimates the current context usage
|
|
5
|
+
# from the JSONL transcript and, when it exceeds the configured
|
|
6
|
+
# threshold, emits additionalContext instructing the model to invoke
|
|
7
|
+
# the /handoff skill and tell the user to type /clear.
|
|
8
|
+
#
|
|
9
|
+
# Thresholds are read from .rulebook/rulebook.json `handoff` section.
|
|
10
|
+
# Defaults: warn=75, force=90 (percentage of estimated max context).
|
|
11
|
+
|
|
12
|
+
set -euo pipefail
|
|
13
|
+
|
|
14
|
+
# Read the hook input from stdin (Claude Code passes it as JSON)
|
|
15
|
+
input="$(cat)"
|
|
16
|
+
|
|
17
|
+
# Resolve project root from hook input cwd, NOT $(pwd) — the hook may be
|
|
18
|
+
# invoked from a sub-directory the user is currently editing.
|
|
19
|
+
PROJECT_ROOT=""
|
|
20
|
+
if [[ -n "$input" ]] && command -v jq &>/dev/null; then
|
|
21
|
+
PROJECT_ROOT="$(printf '%s' "$input" | jq -r '.cwd // empty' 2>/dev/null || true)"
|
|
22
|
+
fi
|
|
23
|
+
[[ -z "$PROJECT_ROOT" ]] && PROJECT_ROOT="${CLAUDE_PROJECT_DIR:-$(pwd)}"
|
|
24
|
+
|
|
25
|
+
CONFIG_FILE="${PROJECT_ROOT}/.rulebook/rulebook.json"
|
|
26
|
+
HANDOFF_DIR="${PROJECT_ROOT}/.rulebook/handoff"
|
|
27
|
+
|
|
28
|
+
# Defaults
|
|
29
|
+
WARN_PCT=75
|
|
30
|
+
FORCE_PCT=90
|
|
31
|
+
MAX_CONTEXT_CHARS=1600000 # ~400k tokens ≈ 1.6M chars (rough 1:4 ratio)
|
|
32
|
+
|
|
33
|
+
# Override from config if available
|
|
34
|
+
if [[ -f "$CONFIG_FILE" ]] && command -v jq &>/dev/null; then
|
|
35
|
+
WARN_PCT=$(jq -r '.handoff.warnThresholdPct // 75' "$CONFIG_FILE" 2>/dev/null || echo 75)
|
|
36
|
+
FORCE_PCT=$(jq -r '.handoff.forceThresholdPct // 90' "$CONFIG_FILE" 2>/dev/null || echo 90)
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
# Resolve transcript size from the payload's transcript_path. Claude Code
|
|
40
|
+
# always passes this in Stop hook stdin (Anthropic hook spec), so we avoid
|
|
41
|
+
# scanning $HOME/.claude/projects — which grows linearly with session count
|
|
42
|
+
# and also returns the wrong file in concurrent sessions.
|
|
43
|
+
transcript_size=0
|
|
44
|
+
|
|
45
|
+
if [[ -n "$input" ]] && command -v jq &>/dev/null; then
|
|
46
|
+
transcript_path="$(printf '%s' "$input" | jq -r '.transcript_path // empty' 2>/dev/null || true)"
|
|
47
|
+
if [[ -n "$transcript_path" && -f "$transcript_path" ]]; then
|
|
48
|
+
transcript_size=$(stat -c%s "$transcript_path" 2>/dev/null || stat -f%z "$transcript_path" 2>/dev/null || echo 0)
|
|
49
|
+
fi
|
|
50
|
+
fi
|
|
51
|
+
|
|
52
|
+
# If we couldn't get transcript size, emit nothing (no-op)
|
|
53
|
+
if [[ "$transcript_size" -eq 0 ]]; then
|
|
54
|
+
printf '%s' '{}'
|
|
55
|
+
exit 0
|
|
56
|
+
fi
|
|
57
|
+
|
|
58
|
+
# Estimate context percentage
|
|
59
|
+
pct=$(( transcript_size * 100 / MAX_CONTEXT_CHARS ))
|
|
60
|
+
|
|
61
|
+
if [[ "$pct" -ge "$FORCE_PCT" ]]; then
|
|
62
|
+
# Force mode: write urgent sentinel + emit strong instruction
|
|
63
|
+
mkdir -p "$HANDOFF_DIR"
|
|
64
|
+
touch "${HANDOFF_DIR}/.urgent"
|
|
65
|
+
msg="⚠️ CONTEXT AT ${pct}% (FORCE THRESHOLD). You MUST invoke /handoff NOW to save session state to .rulebook/handoff/_pending.md. After it succeeds, tell the user: '>>> TYPE /clear NOW — your context will be auto-restored in the next session <<<'. Do NOT continue working until the user has typed /clear."
|
|
66
|
+
jq -nc --arg msg "$msg" '{ hookSpecificOutput: { hookEventName: "Stop", additionalContext: $msg } }'
|
|
67
|
+
elif [[ "$pct" -ge "$WARN_PCT" ]]; then
|
|
68
|
+
msg="⚠️ Context at ${pct}%. Recommended: invoke /handoff to save session state. After it succeeds, tell the user to type /clear for a fresh session."
|
|
69
|
+
jq -nc --arg msg "$msg" '{ hookSpecificOutput: { hookEventName: "Stop", additionalContext: $msg } }'
|
|
70
|
+
else
|
|
71
|
+
# Below threshold — no-op
|
|
72
|
+
printf '%s' '{}'
|
|
73
|
+
fi
|
|
74
|
+
exit 0
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# PreToolUse hook (v5.6.0): consolidated deny rules.
|
|
3
|
+
#
|
|
4
|
+
# Replaces three legacy hooks (enforce-no-deferred / enforce-no-shortcuts /
|
|
5
|
+
# enforce-mcp-for-tasks) with a single bash + node invocation. Each rule's
|
|
6
|
+
# permissionDecisionReason is preserved verbatim so existing user guidance
|
|
7
|
+
# is unchanged.
|
|
8
|
+
set -euo pipefail
|
|
9
|
+
input="$(cat)"
|
|
10
|
+
|
|
11
|
+
result="$(node -e "
|
|
12
|
+
const input = JSON.parse(process.argv[1]);
|
|
13
|
+
const tool = input.tool_name || '';
|
|
14
|
+
const ti = input.tool_input || {};
|
|
15
|
+
const file = (ti.file_path || ti.filePath || '').replace(/\\\\/g, '/');
|
|
16
|
+
const content = ti.new_string || ti.content || '';
|
|
17
|
+
const cmd = ti.command || '';
|
|
18
|
+
|
|
19
|
+
// Rule: mcp-for-tasks — manual creation of task scaffolding is forbidden.
|
|
20
|
+
if (tool === 'Write' || tool === 'Edit') {
|
|
21
|
+
const m = file.match(/\.rulebook\/tasks\/[^/]+\/(proposal\.md|\.metadata\.json)\$/);
|
|
22
|
+
if (m) {
|
|
23
|
+
try { require('fs').accessSync(file); /* existing file: allow edit */ }
|
|
24
|
+
catch { console.log('DENY_MCP'); process.exit(0); }
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (tool === 'Bash' && /mkdir.*\\.rulebook\\/tasks\\//.test(cmd)) {
|
|
28
|
+
console.log('DENY_MCP'); process.exit(0);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Rule: no-deferred — tasks.md must not contain deferred / skip / later / TODO.
|
|
32
|
+
if ((tool === 'Edit' || tool === 'Write') && file.endsWith('tasks.md')) {
|
|
33
|
+
if (/\\b(deferred|skip(ped)?|later|todo)\\b/i.test(content)) {
|
|
34
|
+
console.log('DENY_DEFERRED'); process.exit(0);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Rule: no-shortcuts — source files must not contain TODO/FIXME/HACK or stub/placeholder.
|
|
39
|
+
if (tool === 'Edit' || tool === 'Write') {
|
|
40
|
+
if (/\\.(ts|tsx|js|jsx|py|rs|go|java|cs|cpp|c|hpp|h)\$/.test(file)
|
|
41
|
+
&& !/\\.test\\.|\\.spec\\.|__tests__|\\/tests\\//.test(file)) {
|
|
42
|
+
if (/\\/\\/\\s*(TODO|FIXME|HACK)\\b|\\/\\*\\s*(TODO|FIXME|HACK)\\b|#\\s*(TODO|FIXME|HACK)\\b/.test(content)) {
|
|
43
|
+
console.log('DENY_TODO'); process.exit(0);
|
|
44
|
+
}
|
|
45
|
+
if (/\\bplaceholder\\b|\\bstub\\b/i.test(content)) {
|
|
46
|
+
console.log('DENY_STUB'); process.exit(0);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
console.log('ALLOW');
|
|
52
|
+
" "$input" 2>/dev/null || echo "ALLOW")"
|
|
53
|
+
|
|
54
|
+
case "$result" in
|
|
55
|
+
DENY_MCP)
|
|
56
|
+
echo '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"DENIED: task files must be created via rulebook_task_create MCP tool, not manually. Use: rulebook_task_create({ taskId: phase1_your-task-name })"}}'
|
|
57
|
+
;;
|
|
58
|
+
DENY_DEFERRED)
|
|
59
|
+
echo '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"DENIED: tasks.md cannot contain deferred, skip, later, or TODO. Implement the item now or explain why impossible. See .claude/rules/no-deferred.md"}}'
|
|
60
|
+
;;
|
|
61
|
+
DENY_TODO)
|
|
62
|
+
echo '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"DENIED: source code cannot contain // TODO, // FIXME, or // HACK. Implement the logic now. See .claude/rules/no-shortcuts.md"}}'
|
|
63
|
+
;;
|
|
64
|
+
DENY_STUB)
|
|
65
|
+
echo '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"DENIED: source code cannot contain placeholders or stubs. Implement real logic. See .claude/rules/no-shortcuts.md"}}'
|
|
66
|
+
;;
|
|
67
|
+
*)
|
|
68
|
+
echo '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"allow"}}'
|
|
69
|
+
;;
|
|
70
|
+
esac
|