codebyplan 1.5.1 → 1.8.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/dist/cli.js +4462 -748
- package/package.json +5 -1
- package/templates/.gitkeep +0 -0
- package/templates/README.md +20 -0
- package/templates/agents/cbp-cc-executor.md +213 -0
- package/templates/agents/cbp-database-agent.md +229 -0
- package/templates/agents/cbp-improve-claude.md +245 -0
- package/templates/agents/cbp-improve-round.md +284 -0
- package/templates/agents/cbp-mechanical-edits.md +111 -0
- package/templates/agents/cbp-research.md +282 -0
- package/templates/agents/cbp-round-executor.md +604 -0
- package/templates/agents/cbp-security-agent.md +134 -0
- package/templates/agents/cbp-task-check.md +213 -0
- package/templates/agents/cbp-task-planner.md +582 -0
- package/templates/agents/cbp-test-e2e-agent.md +363 -0
- package/templates/agents/cbp-testing-qa-agent.md +400 -0
- package/templates/context/mcp-docs.md +139 -0
- package/templates/hooks/README.md +236 -0
- package/templates/hooks/cbp-auto-test-hooks.sh +44 -0
- package/templates/hooks/cbp-lint-format-on-edit.sh +159 -0
- package/templates/hooks/cbp-maestro-yaml-validate.sh +100 -0
- package/templates/hooks/cbp-mcp-migration-guard.sh +32 -0
- package/templates/hooks/cbp-mcp-round-sync.sh +79 -0
- package/templates/hooks/cbp-mcp-worktree-inject.sh +76 -0
- package/templates/hooks/cbp-notify.sh +68 -0
- package/templates/hooks/cbp-plugin-dispatch.sh +29 -0
- package/templates/hooks/cbp-pre-commit-quality-gate.sh +204 -0
- package/templates/hooks/cbp-statusline.sh +347 -0
- package/templates/hooks/cbp-subagent-statusline.sh +182 -0
- package/templates/hooks/cbp-test-coverage-gate.sh +144 -0
- package/templates/hooks/cbp-test-hooks.sh +320 -0
- package/templates/hooks/hooks.json +85 -0
- package/templates/hooks/validate-context-usage.sh +59 -0
- package/templates/hooks/validate-git-commit.sh +78 -0
- package/templates/hooks/validate-git-stash-deny.sh +32 -0
- package/templates/hooks/validate-structure-lengths.sh +57 -0
- package/templates/hooks/validate-structure-lib.sh +104 -0
- package/templates/hooks/validate-structure-patterns.sh +54 -0
- package/templates/hooks/validate-structure-scope.sh +33 -0
- package/templates/hooks/validate-structure-smoke.sh +95 -0
- package/templates/hooks/validate-structure-templates.sh +34 -0
- package/templates/hooks/validate-structure.sh +69 -0
- package/templates/rules/.gitkeep +0 -0
- package/templates/rules/README.md +47 -0
- package/templates/rules/context-file-loading.md +52 -0
- package/templates/rules/scope-vocabulary.md +64 -0
- package/templates/rules/todo-backend.md +109 -0
- package/templates/settings.project.base.json +55 -0
- package/templates/settings.user.base.json +25 -0
- package/templates/skills/cbp-build-cc-agent/SKILL.md +139 -0
- package/templates/skills/cbp-build-cc-agent/examples/read-only-reviewer.md +32 -0
- package/templates/skills/cbp-build-cc-agent/examples/with-hooks.md +41 -0
- package/templates/skills/cbp-build-cc-agent/examples/with-skills-preload.md +25 -0
- package/templates/skills/cbp-build-cc-agent/reference/cbp-quality.md +153 -0
- package/templates/skills/cbp-build-cc-agent/reference/frontmatter-fields.md +37 -0
- package/templates/skills/cbp-build-cc-agent/reference/permission-modes.md +18 -0
- package/templates/skills/cbp-build-cc-agent/scripts/validate-agent.sh +67 -0
- package/templates/skills/cbp-build-cc-agent/templates/agent.md +66 -0
- package/templates/skills/cbp-build-cc-claude-file/SKILL.md +178 -0
- package/templates/skills/cbp-build-cc-claude-file/examples/minimal-project.md +33 -0
- package/templates/skills/cbp-build-cc-claude-file/examples/monorepo-with-imports.md +39 -0
- package/templates/skills/cbp-build-cc-claude-file/reference/imports.md +72 -0
- package/templates/skills/cbp-build-cc-claude-file/reference/what-belongs.md +39 -0
- package/templates/skills/cbp-build-cc-claude-file/templates/project-claude-md.md +48 -0
- package/templates/skills/cbp-build-cc-claude-file/templates/user-claude-md.md +22 -0
- package/templates/skills/cbp-build-cc-memory/SKILL.md +201 -0
- package/templates/skills/cbp-build-cc-memory/examples/feedback-memory.md +11 -0
- package/templates/skills/cbp-build-cc-memory/examples/project-memory.md +11 -0
- package/templates/skills/cbp-build-cc-memory/examples/reference-memory.md +13 -0
- package/templates/skills/cbp-build-cc-memory/examples/user-memory.md +14 -0
- package/templates/skills/cbp-build-cc-memory/reference/memory-types.md +59 -0
- package/templates/skills/cbp-build-cc-memory/reference/when-to-save.md +62 -0
- package/templates/skills/cbp-build-cc-memory/templates/MEMORY-index.md +4 -0
- package/templates/skills/cbp-build-cc-memory/templates/memory-entry.md +15 -0
- package/templates/skills/cbp-build-cc-mode/SKILL.md +99 -0
- package/templates/skills/cbp-build-cc-rule/SKILL.md +176 -0
- package/templates/skills/cbp-build-cc-rule/examples/global-rule.md +19 -0
- package/templates/skills/cbp-build-cc-rule/examples/scoped-rule.md +41 -0
- package/templates/skills/cbp-build-cc-rule/reference/paths-patterns.md +48 -0
- package/templates/skills/cbp-build-cc-rule/templates/rule.md +32 -0
- package/templates/skills/cbp-build-cc-settings/SKILL.md +220 -0
- package/templates/skills/cbp-build-cc-settings/examples/hooks-config.json +64 -0
- package/templates/skills/cbp-build-cc-settings/examples/permissions-config.json +34 -0
- package/templates/skills/cbp-build-cc-settings/examples/sandbox-config.json +42 -0
- package/templates/skills/cbp-build-cc-settings/reference/cbp-conventions.md +104 -0
- package/templates/skills/cbp-build-cc-settings/reference/permission-rules.md +61 -0
- package/templates/skills/cbp-build-cc-settings/reference/scope-precedence.md +73 -0
- package/templates/skills/cbp-build-cc-settings/reference/settings-fields.md +166 -0
- package/templates/skills/cbp-build-cc-settings/templates/settings.json +23 -0
- package/templates/skills/cbp-build-cc-settings/templates/settings.local.json +10 -0
- package/templates/skills/cbp-build-cc-skill/SKILL.md +154 -0
- package/templates/skills/cbp-build-cc-skill/examples/dynamic-context.md +31 -0
- package/templates/skills/cbp-build-cc-skill/examples/fork-skill.md +22 -0
- package/templates/skills/cbp-build-cc-skill/examples/knowledge-skill.md +25 -0
- package/templates/skills/cbp-build-cc-skill/examples/task-skill.md +29 -0
- package/templates/skills/cbp-build-cc-skill/reference/cbp-quality.md +157 -0
- package/templates/skills/cbp-build-cc-skill/reference/frontmatter-fields.md +35 -0
- package/templates/skills/cbp-build-cc-skill/reference/string-substitutions.md +60 -0
- package/templates/skills/cbp-build-cc-skill/scripts/validate-skill.sh +90 -0
- package/templates/skills/cbp-build-cc-skill/templates/skill.md +51 -0
- package/templates/skills/cbp-checkpoint-check/SKILL.md +156 -0
- package/templates/skills/cbp-checkpoint-complete/SKILL.md +109 -0
- package/templates/skills/cbp-checkpoint-create/SKILL.md +287 -0
- package/templates/skills/cbp-checkpoint-end/SKILL.md +241 -0
- package/templates/skills/cbp-checkpoint-update/SKILL.md +115 -0
- package/templates/skills/cbp-frontend-a11y/SKILL.md +109 -0
- package/templates/skills/cbp-frontend-a11y/reference/aria-roles-states.md +130 -0
- package/templates/skills/cbp-frontend-a11y/reference/contrast-visual.md +122 -0
- package/templates/skills/cbp-frontend-a11y/reference/keyboard-patterns.md +154 -0
- package/templates/skills/cbp-frontend-a11y/reference/semantic-html.md +111 -0
- package/templates/skills/cbp-frontend-design/SKILL.md +145 -0
- package/templates/skills/cbp-frontend-design/reference/nextjs-scss.md +118 -0
- package/templates/skills/cbp-frontend-design/reference/rn-expo.md +101 -0
- package/templates/skills/cbp-frontend-design/reference/tauri-react.md +82 -0
- package/templates/skills/cbp-frontend-ui/SKILL.md +262 -0
- package/templates/skills/cbp-frontend-ui/reference/ui-label-maps.md +42 -0
- package/templates/skills/cbp-frontend-ui/reference/ui-layout-patterns.md +105 -0
- package/templates/skills/cbp-frontend-ui/reference/variant-defaults.md +149 -0
- package/templates/skills/cbp-frontend-ux/SKILL.md +181 -0
- package/templates/skills/cbp-git-branch-feat-create/SKILL.md +115 -0
- package/templates/skills/cbp-git-commit/SKILL.md +278 -0
- package/templates/skills/cbp-git-worktree-create/SKILL.md +226 -0
- package/templates/skills/cbp-git-worktree-remove/SKILL.md +145 -0
- package/templates/skills/cbp-merge-main/SKILL.md +228 -0
- package/templates/skills/cbp-round-check/SKILL.md +104 -0
- package/templates/skills/cbp-round-end/SKILL.md +183 -0
- package/templates/skills/cbp-round-end/reference/findings-presentation.md +44 -0
- package/templates/skills/cbp-round-end/reference/inline-fallback.md +35 -0
- package/templates/skills/cbp-round-execute/SKILL.md +211 -0
- package/templates/skills/cbp-round-execute/reference/inline-fallback.md +59 -0
- package/templates/skills/cbp-round-input/SKILL.md +165 -0
- package/templates/skills/cbp-round-start/SKILL.md +222 -0
- package/templates/skills/cbp-round-update/SKILL.md +163 -0
- package/templates/skills/cbp-session-end/SKILL.md +187 -0
- package/templates/skills/cbp-session-start/SKILL.md +155 -0
- package/templates/skills/cbp-ship/SKILL.md +332 -0
- package/templates/skills/cbp-ship/reference/changesets-overview.md +120 -0
- package/templates/skills/cbp-ship/reference/eas-cli-overview.md +60 -0
- package/templates/skills/cbp-ship/reference/gh-cli-overview.md +135 -0
- package/templates/skills/cbp-ship/reference/gh-cli-shipment-commands.md +283 -0
- package/templates/skills/cbp-ship/reference/npm-publish-monorepo.md +252 -0
- package/templates/skills/cbp-ship/reference/npm-publish-oidc-trusted.md +157 -0
- package/templates/skills/cbp-ship/reference/npm-publish-overview.md +171 -0
- package/templates/skills/cbp-ship/reference/preflight-checklist.md +88 -0
- package/templates/skills/cbp-ship/reference/railway-nestjs-deployment.md +169 -0
- package/templates/skills/cbp-ship/reference/railway-overview.md +120 -0
- package/templates/skills/cbp-ship/reference/railway-troubleshooting.md +168 -0
- package/templates/skills/cbp-ship/reference/release-please-overview.md +99 -0
- package/templates/skills/cbp-ship/reference/surface-expo-eas.md +155 -0
- package/templates/skills/cbp-ship/reference/surface-npm.md +180 -0
- package/templates/skills/cbp-ship/reference/surface-railway.md +152 -0
- package/templates/skills/cbp-ship/reference/surface-supabase.md +178 -0
- package/templates/skills/cbp-ship/reference/surface-tauri.md +138 -0
- package/templates/skills/cbp-ship/reference/surface-vercel.md +124 -0
- package/templates/skills/cbp-ship/reference/surface-vscode-ext.md +144 -0
- package/templates/skills/cbp-ship/reference/surfaces.md +60 -0
- package/templates/skills/cbp-ship/reference/testflight-automation.md +215 -0
- package/templates/skills/cbp-ship/reference/testflight-internal-vs-external.md +69 -0
- package/templates/skills/cbp-ship/reference/testflight-overview.md +98 -0
- package/templates/skills/cbp-ship/reference/versioning.md +116 -0
- package/templates/skills/cbp-ship/scripts/detect-surfaces.sh +217 -0
- package/templates/skills/cbp-ship/scripts/verify-expo-eas.sh +35 -0
- package/templates/skills/cbp-ship/scripts/verify-npm.sh +21 -0
- package/templates/skills/cbp-ship/scripts/verify-railway.sh +41 -0
- package/templates/skills/cbp-ship/scripts/verify-supabase.sh +19 -0
- package/templates/skills/cbp-ship/scripts/verify-tauri.sh +24 -0
- package/templates/skills/cbp-ship/scripts/verify-vercel.sh +32 -0
- package/templates/skills/cbp-ship/scripts/verify-vscode-ext.sh +25 -0
- package/templates/skills/cbp-ship/templates/eas.json +66 -0
- package/templates/skills/cbp-ship/templates/railway.toml +15 -0
- package/templates/skills/cbp-ship/templates/release-please-config.json +17 -0
- package/templates/skills/cbp-ship/templates/vercel.json +19 -0
- package/templates/skills/cbp-ship/templates/vscodeignore +21 -0
- package/templates/skills/cbp-ship/templates/workflow-changesets.yml +41 -0
- package/templates/skills/cbp-ship/templates/workflow-eas-submit.yml +53 -0
- package/templates/skills/cbp-ship/templates/workflow-npm-publish.yml +36 -0
- package/templates/skills/cbp-ship/templates/workflow-release-please.yml +21 -0
- package/templates/skills/cbp-ship/templates/workflow-tauri-release.yml +69 -0
- package/templates/skills/cbp-ship/templates/workflow-vsce-publish.yml +31 -0
- package/templates/skills/cbp-ship-configure/SKILL.md +296 -0
- package/templates/skills/cbp-ship-configure/reference/expo-mobile.md +204 -0
- package/templates/skills/cbp-ship-configure/reference/npm-package.md +165 -0
- package/templates/skills/cbp-ship-configure/reference/railway-backend.md +199 -0
- package/templates/skills/cbp-ship-configure/reference/supabase.md +200 -0
- package/templates/skills/cbp-ship-configure/reference/tauri-desktop.md +181 -0
- package/templates/skills/cbp-ship-configure/reference/vercel.md +117 -0
- package/templates/skills/cbp-ship-configure/reference/vscode-ext.md +155 -0
- package/templates/skills/cbp-ship-main/SKILL.md +65 -0
- package/templates/skills/cbp-supabase-branch-check/SKILL.md +337 -0
- package/templates/skills/cbp-supabase-branch-check/reference/dag-steps.md +29 -0
- package/templates/skills/cbp-supabase-migrate/SKILL.md +314 -0
- package/templates/skills/cbp-supabase-migrate/reference/advisor-triage.md +70 -0
- package/templates/skills/cbp-supabase-migrate/reference/cli-fallback.md +87 -0
- package/templates/skills/cbp-supabase-migrate/reference/preflight-dry-run.md +58 -0
- package/templates/skills/cbp-supabase-setup/SKILL.md +239 -0
- package/templates/skills/cbp-supabase-setup/reference/branching-setup.md +121 -0
- package/templates/skills/cbp-supabase-setup/reference/cli-fallback.md +109 -0
- package/templates/skills/cbp-task-check/SKILL.md +166 -0
- package/templates/skills/cbp-task-complete/SKILL.md +206 -0
- package/templates/skills/cbp-task-complete/reference/checkpoint-done-branching.md +48 -0
- package/templates/skills/cbp-task-complete/reference/next-step-heuristic.md +56 -0
- package/templates/skills/cbp-task-create/SKILL.md +167 -0
- package/templates/skills/cbp-task-start/SKILL.md +239 -0
- package/templates/skills/cbp-task-testing/SKILL.md +277 -0
- package/templates/skills/cbp-todo/SKILL.md +97 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# @scope: org-shared
|
|
3
|
+
# Hook Helper Library: Shared primitives for validate-structure-*.sh
|
|
4
|
+
# Purpose: Block/warn formatters, path-matching, content extraction,
|
|
5
|
+
# frontmatter / scope-marker detection, line counting.
|
|
6
|
+
# Sourced by validate-structure.sh and its 4 sub-helpers — never run directly.
|
|
7
|
+
#
|
|
8
|
+
# Conventions:
|
|
9
|
+
# - All functions are stateless; callers pass state explicitly OR rely
|
|
10
|
+
# on the dispatcher's already-set environment ($REL_PATH, $FILE_PATH,
|
|
11
|
+
# $INPUT, $REPO_ROOT, $EXT) when documented per-function.
|
|
12
|
+
# - Functions emit to stderr only via block()/warn() — never echo to stdout.
|
|
13
|
+
# - The dispatcher (validate-structure.sh) sources this lib once before
|
|
14
|
+
# the 4 sub-helpers; sub-helpers rely on the lib being pre-loaded.
|
|
15
|
+
# Idempotent: re-sourcing is a no-op via _validate_structure_lib_loaded.
|
|
16
|
+
|
|
17
|
+
[ -n "${_validate_structure_lib_loaded:-}" ] && return 0
|
|
18
|
+
_validate_structure_lib_loaded=1
|
|
19
|
+
|
|
20
|
+
# ===== block / warn =====
|
|
21
|
+
|
|
22
|
+
# block <message> [expected_hint]
|
|
23
|
+
# Emit a structure violation to stderr and exit 2.
|
|
24
|
+
block() {
|
|
25
|
+
echo "[HOOK END] validate-structure (BLOCKED)"
|
|
26
|
+
echo "STRUCTURE VIOLATION: $1" >&2
|
|
27
|
+
echo "" >&2
|
|
28
|
+
if [ -n "${2:-}" ]; then
|
|
29
|
+
echo "Expected: $2" >&2
|
|
30
|
+
fi
|
|
31
|
+
echo "" >&2
|
|
32
|
+
echo "Structure is enforced from: /.claude/rules/structure-*.md" >&2
|
|
33
|
+
exit 2
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
# warn <message>
|
|
37
|
+
# Emit a non-blocking structure warning to stderr.
|
|
38
|
+
warn() {
|
|
39
|
+
echo "STRUCTURE WARNING: $1" >&2
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
# ===== path matching =====
|
|
43
|
+
|
|
44
|
+
# match_path <pattern>
|
|
45
|
+
# Returns 0 if $REL_PATH matches the extended-regex pattern.
|
|
46
|
+
match_path() {
|
|
47
|
+
echo "$REL_PATH" | grep -qE "$1"
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
# enforce_path_pattern <scope_prefix> <full_pattern> <block_message> <expected_hint>
|
|
51
|
+
# If $REL_PATH is in <scope_prefix>, it MUST also match <full_pattern>; else block.
|
|
52
|
+
# Use to collapse the recurring "if-in-prefix-and-not-matching-full" idiom.
|
|
53
|
+
enforce_path_pattern() {
|
|
54
|
+
local scope_prefix="$1" full_pattern="$2" block_msg="$3" expected="$4"
|
|
55
|
+
if match_path "$scope_prefix"; then
|
|
56
|
+
if ! match_path "$full_pattern"; then
|
|
57
|
+
block "$block_msg" "$expected"
|
|
58
|
+
fi
|
|
59
|
+
fi
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
# ===== input / content extraction =====
|
|
63
|
+
|
|
64
|
+
# read_input_content
|
|
65
|
+
# Echo the tool's pending content (Write content or Edit new_string),
|
|
66
|
+
# pulling from $INPUT (the dispatcher's stdin JSON). Empty if neither present.
|
|
67
|
+
read_input_content() {
|
|
68
|
+
echo "$INPUT" | jq -r '.tool_input.content // .tool_input.new_string // empty' 2>/dev/null
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
# count_lines <content_string> [fallback_filepath]
|
|
72
|
+
# Count lines in <content_string>; if empty, fall back to wc -l on <fallback_filepath>.
|
|
73
|
+
# Echo the count (0 if neither yields anything).
|
|
74
|
+
count_lines() {
|
|
75
|
+
local content="$1" fallback="${2:-}"
|
|
76
|
+
if [ -n "$content" ]; then
|
|
77
|
+
printf '%s' "$content" | awk 'END { print NR }'
|
|
78
|
+
elif [ -n "$fallback" ] && [ -f "$fallback" ]; then
|
|
79
|
+
wc -l < "$fallback" | tr -d ' '
|
|
80
|
+
else
|
|
81
|
+
echo 0
|
|
82
|
+
fi
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
# ===== frontmatter / scope detection =====
|
|
86
|
+
|
|
87
|
+
# has_yaml_frontmatter <file_path>
|
|
88
|
+
# Returns 0 if the first line is `---` (YAML frontmatter opener). Missing file → 1.
|
|
89
|
+
has_yaml_frontmatter() {
|
|
90
|
+
[ -f "$1" ] && head -1 "$1" 2>/dev/null | grep -q "^---$"
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
# has_yaml_field <file_path> <field_name> [head_lines=10]
|
|
94
|
+
# Returns 0 if `<field>:` appears in the first <head_lines> of the file.
|
|
95
|
+
has_yaml_field() {
|
|
96
|
+
local fp="$1" field="$2" n="${3:-10}"
|
|
97
|
+
[ -f "$fp" ] && head -"$n" "$fp" 2>/dev/null | grep -q "^${field}:"
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
# has_scope_comment <file_path>
|
|
101
|
+
# Returns 0 if a `# @scope:` comment appears in the first 5 lines (sh hook convention).
|
|
102
|
+
has_scope_comment() {
|
|
103
|
+
[ -f "$1" ] && head -5 "$1" 2>/dev/null | grep -q "^# @scope:"
|
|
104
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# @scope: org-shared
|
|
3
|
+
# Hook Helper: Pattern validation for validate-structure.sh
|
|
4
|
+
# Purpose: Validate file paths against structure patterns
|
|
5
|
+
# Sourced by validate-structure.sh - not run directly
|
|
6
|
+
#
|
|
7
|
+
# Expects: $REL_PATH, $FILE_PATH, $INPUT, block(), warn(), match_path(),
|
|
8
|
+
# enforce_path_pattern(), read_input_content() (from validate-structure-lib.sh)
|
|
9
|
+
|
|
10
|
+
# ===== Path-pattern enforcement =====
|
|
11
|
+
# Each row: enforce_path_pattern <prefix> <full_pattern> <block_msg> <expected_hint>
|
|
12
|
+
_SUB='(templates|examples|reference|scripts)/[a-z0-9.-]+\.(md|sh|json|ya?ml)'
|
|
13
|
+
enforce_path_pattern '^/\.claude/skills/' "^/\.claude/skills/[a-z0-9-]+/(SKILL\.md|[a-z0-9-]+\.md|${_SUB})$" 'Invalid skill path' "Pattern: /.claude/skills/{name}/SKILL.md | /.claude/skills/{name}/{file}.md | /.claude/skills/{name}/(templates|examples|reference|scripts)/{file}.{md,sh,json,yaml}"
|
|
14
|
+
enforce_path_pattern '^/\.claude/agents/' "^/\.claude/agents/([a-z0-9-]+\.md|[a-z0-9-]+/(AGENT\.md|[a-z0-9-]+\.md|${_SUB}))$" 'Invalid agent path' "Pattern: /.claude/agents/{name}.md | /.claude/agents/{name}/AGENT.md | /.claude/agents/{name}/{file}.md | /.claude/agents/{name}/(templates|examples|reference|scripts)/{file}.{md,sh,json,yaml}"
|
|
15
|
+
enforce_path_pattern '^/\.claude/rules/' '^/\.claude/rules/[a-z-]+\.md$' 'Invalid native rule path' 'Pattern: /.claude/rules/{name}.md'
|
|
16
|
+
if match_path '^/\.claude/hooks/' && ! match_path '^/\.claude/hooks/__test-fixtures__/'; then
|
|
17
|
+
if ! match_path '^/\.claude/hooks/[a-z-]+\.sh$'; then
|
|
18
|
+
block 'Invalid hook path' 'Pattern: /.claude/hooks/{name}.sh'
|
|
19
|
+
fi
|
|
20
|
+
fi
|
|
21
|
+
enforce_path_pattern '^/\.claude/context/' '^/\.claude/context/([a-z0-9-]+/)*[a-z0-9-]+\.(md|json)$' 'Invalid context path' 'Pattern: /.claude/context/{name}.(md|json) or /.claude/context/{subdir}/{name}.(md|json)'
|
|
22
|
+
enforce_path_pattern '^/\.claude/docs/architecture/' '^/\.claude/docs/architecture/[a-z-]+\.md$' 'Invalid architecture path' 'Pattern: /.claude/docs/architecture/{name}.md'
|
|
23
|
+
enforce_path_pattern '^/docs/structure/' '^/docs/structure/[a-z-]+\.(md|json)$' 'Invalid structure path' 'Pattern: /docs/structure/{name}.md or .json'
|
|
24
|
+
|
|
25
|
+
# Research files: only enforce {1-8}-{name}.md if filename starts with a digit
|
|
26
|
+
if match_path '^/\.claude/docs/research/[a-z-]+/'; then
|
|
27
|
+
RESEARCH_FILE=$(basename "$REL_PATH")
|
|
28
|
+
if echo "$RESEARCH_FILE" | grep -qE '^[0-9]' && ! echo "$RESEARCH_FILE" | grep -qE '^[1-8]-[a-z-]+\.md$'; then
|
|
29
|
+
block "Invalid research file" "Pattern: {1-8}-{name}.md (phases 1-8 only)"
|
|
30
|
+
fi
|
|
31
|
+
fi
|
|
32
|
+
|
|
33
|
+
# Stack: index/usage/guide/updates files OR the top-level update-checks.md
|
|
34
|
+
if match_path '^/\.claude/docs/stack/' \
|
|
35
|
+
&& ! match_path '^/\.claude/docs/stack/update-checks\.md$' \
|
|
36
|
+
&& ! match_path '^/\.claude/docs/stack/[a-z-]+/(index|usage|guide|updates)\.md$'; then
|
|
37
|
+
block "Invalid stack path" "Pattern: /.claude/docs/stack/{name}/(index|usage|guide|updates).md or /.claude/docs/stack/update-checks.md"
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
# Notation consistency (warn-only): flag bare-colon command notation in .claude/ markdown
|
|
41
|
+
# See: /.claude/rules/notation-consistency.md — all command refs must use /cbp-* form
|
|
42
|
+
if match_path '^/\.claude/(rules|skills|agents)/' && match_path '\.md$'; then
|
|
43
|
+
CONTENT=$(read_input_content)
|
|
44
|
+
[ -z "$CONTENT" ] && [ -f "$FILE_PATH" ] && CONTENT=$(cat "$FILE_PATH" 2>/dev/null || true)
|
|
45
|
+
if [ -n "$CONTENT" ]; then
|
|
46
|
+
COLON_HITS=$(echo "$CONTENT" | grep -nE '`(round|task|checkpoint|git|session|fix|ship|worktree|build-cc):[a-z-]+`' 2>/dev/null || true)
|
|
47
|
+
if [ -n "$COLON_HITS" ]; then
|
|
48
|
+
warn "Notation consistency: bare-colon command reference detected — use /cbp-* form instead"
|
|
49
|
+
warn " File: ${REL_PATH}"
|
|
50
|
+
warn " Matches:"
|
|
51
|
+
echo "$COLON_HITS" | sed 's/^/ /' >&2
|
|
52
|
+
fi
|
|
53
|
+
fi
|
|
54
|
+
fi
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# @scope: org-shared
|
|
3
|
+
# Hook Helper: Scope marker validation for validate-structure.sh
|
|
4
|
+
# Purpose: Ensure all .claude/ files have a scope marker for structural classification
|
|
5
|
+
# Sourced by validate-structure.sh - not run directly
|
|
6
|
+
#
|
|
7
|
+
# Expects: $REL_PATH, $FILE_PATH, $EXT, warn(), match_path(),
|
|
8
|
+
# has_yaml_frontmatter(), has_yaml_field(), has_scope_comment() (from validate-structure-lib.sh)
|
|
9
|
+
|
|
10
|
+
# Only check .claude/ files
|
|
11
|
+
if ! match_path '^/\.claude/'; then
|
|
12
|
+
return 0 2>/dev/null || true
|
|
13
|
+
fi
|
|
14
|
+
|
|
15
|
+
case "$EXT" in
|
|
16
|
+
md)
|
|
17
|
+
if has_yaml_frontmatter "$FILE_PATH"; then
|
|
18
|
+
if ! has_yaml_field "$FILE_PATH" scope; then
|
|
19
|
+
warn "Missing scope: in frontmatter. Add 'scope: org-shared' / 'scope: project-shared' / 'scope: repo-only:<name>' for structural classification. See rules/scope-vocabulary.md."
|
|
20
|
+
fi
|
|
21
|
+
else
|
|
22
|
+
warn "Missing frontmatter with scope:. Add YAML frontmatter with 'scope: org-shared' / 'scope: project-shared' / 'scope: repo-only:<name>'. See rules/scope-vocabulary.md."
|
|
23
|
+
fi
|
|
24
|
+
;;
|
|
25
|
+
sh)
|
|
26
|
+
if ! has_scope_comment "$FILE_PATH"; then
|
|
27
|
+
warn "Missing # @scope: comment. Add '# @scope: org-shared' / '# @scope: project-shared' / '# @scope: repo-only:<name>' after shebang. See rules/scope-vocabulary.md."
|
|
28
|
+
fi
|
|
29
|
+
;;
|
|
30
|
+
json)
|
|
31
|
+
# JSON can't have frontmatter — skip
|
|
32
|
+
;;
|
|
33
|
+
esac
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# @scope: org-shared
|
|
3
|
+
# Smoke runner for validate-structure-*.sh + validate-structure-lib.sh
|
|
4
|
+
# Iterates fixtures under __test-fixtures__/validate-structure/{good,bad}/
|
|
5
|
+
# Each test case maps a fixture file → simulated rel path inside .claude/
|
|
6
|
+
# → expected exit code → optional expected stderr pattern.
|
|
7
|
+
#
|
|
8
|
+
# Run on demand: bash .claude/hooks/validate-structure-smoke.sh
|
|
9
|
+
# Exit 0 = all pass, Exit 1 = at least one fail.
|
|
10
|
+
|
|
11
|
+
set +e # tests intentionally produce non-zero exits — handle per-case
|
|
12
|
+
|
|
13
|
+
REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
|
|
14
|
+
HOOK_DIR="$REPO_ROOT/.claude/hooks"
|
|
15
|
+
FIX_DIR="$HOOK_DIR/__test-fixtures__/validate-structure"
|
|
16
|
+
DISPATCHER="$HOOK_DIR/validate-structure.sh"
|
|
17
|
+
|
|
18
|
+
PASS=0
|
|
19
|
+
FAIL=0
|
|
20
|
+
FAIL_LIST=""
|
|
21
|
+
|
|
22
|
+
# Stage a scratch repo mirror so the dispatcher's REPO_ROOT computation
|
|
23
|
+
# (relative to its own location) remains stable while we feed simulated paths.
|
|
24
|
+
SCRATCH=$(mktemp -d)
|
|
25
|
+
trap 'rm -rf "$SCRATCH"' EXIT
|
|
26
|
+
mkdir -p "$SCRATCH/.claude/hooks"
|
|
27
|
+
cp "$HOOK_DIR"/validate-structure*.sh "$SCRATCH/.claude/hooks/"
|
|
28
|
+
# Sourced sibling — required by dispatcher even though it's outside this task's scope
|
|
29
|
+
[ -f "$HOOK_DIR/validate-context-usage.sh" ] && cp "$HOOK_DIR/validate-context-usage.sh" "$SCRATCH/.claude/hooks/"
|
|
30
|
+
SCRATCH_DISPATCHER="$SCRATCH/.claude/hooks/validate-structure.sh"
|
|
31
|
+
|
|
32
|
+
run_case() {
|
|
33
|
+
local label="$1" fixture="$2" rel_path="$3" want_exit="$4" want_stderr="${5:-}"
|
|
34
|
+
local sim_abs="$SCRATCH$rel_path"
|
|
35
|
+
mkdir -p "$(dirname "$sim_abs")"
|
|
36
|
+
if [ -f "$FIX_DIR/$fixture" ]; then
|
|
37
|
+
cp "$FIX_DIR/$fixture" "$sim_abs"
|
|
38
|
+
fi
|
|
39
|
+
local json="{\"tool_input\":{\"file_path\":\"$sim_abs\"}}"
|
|
40
|
+
local stderr_file
|
|
41
|
+
stderr_file=$(mktemp)
|
|
42
|
+
echo "$json" | bash "$SCRATCH_DISPATCHER" >/dev/null 2>"$stderr_file"
|
|
43
|
+
local got_exit=$?
|
|
44
|
+
local ok=1
|
|
45
|
+
if [ "$got_exit" -ne "$want_exit" ]; then
|
|
46
|
+
ok=0
|
|
47
|
+
fi
|
|
48
|
+
if [ -n "$want_stderr" ] && ! grep -q -- "$want_stderr" "$stderr_file"; then
|
|
49
|
+
ok=0
|
|
50
|
+
fi
|
|
51
|
+
if [ "$ok" -eq 1 ]; then
|
|
52
|
+
echo "PASS $label"
|
|
53
|
+
PASS=$((PASS+1))
|
|
54
|
+
else
|
|
55
|
+
echo "FAIL $label (got exit=$got_exit, want=$want_exit)"
|
|
56
|
+
head -5 "$stderr_file" | sed 's/^/ /'
|
|
57
|
+
FAIL=$((FAIL+1))
|
|
58
|
+
FAIL_LIST="$FAIL_LIST $label"
|
|
59
|
+
fi
|
|
60
|
+
rm -f "$stderr_file"
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
# ===== Good fixtures (must exit 0) =====
|
|
64
|
+
run_case "good-skill" good/skill.md /.claude/skills/cbp-fixture/SKILL.md 0
|
|
65
|
+
run_case "good-agent" good/agent.md /.claude/agents/cbp-fixture/AGENT.md 0
|
|
66
|
+
run_case "good-rule" good/rule.md /.claude/rules/cbp-fixture.md 0
|
|
67
|
+
run_case "good-hook" good/hook.sh /.claude/hooks/cbp-fixture.sh 0
|
|
68
|
+
|
|
69
|
+
# ===== Bad fixtures: structural blocks (exit 2) =====
|
|
70
|
+
run_case "bad-uppercase-skill-dir" "" /.claude/skills/Bad_Name/SKILL.md 2 "Invalid skill path"
|
|
71
|
+
run_case "bad-uppercase-hook" "" /.claude/hooks/UPPER.sh 2 "Filename must be kebab-case"
|
|
72
|
+
run_case "bad-uppercase-context" "" /.claude/context/UPPER.md 2 "Filename must be kebab-case"
|
|
73
|
+
run_case "bad-research-bad-phase" "" /.claude/docs/research/foo/9-bad.md 2 "Invalid research file"
|
|
74
|
+
run_case "bad-over-length-rule" bad/over-length-rule.md /.claude/rules/cbp-fixture-overlength.md 2 "exceeds hard limit"
|
|
75
|
+
|
|
76
|
+
# ===== Warn-only fixtures (exit 0 but stderr has WARNING) =====
|
|
77
|
+
run_case "warn-missing-frontmatter" bad/missing-frontmatter.md /.claude/rules/cbp-fixture-no-frontmatter.md 0 "Missing frontmatter"
|
|
78
|
+
run_case "warn-missing-scope-field" bad/missing-scope-field.md /.claude/rules/cbp-fixture-no-scope-field.md 0 "Missing scope:"
|
|
79
|
+
run_case "warn-missing-scope-comment" bad/missing-scope-comment.sh /.claude/hooks/cbp-fixture-no-scope-comment.sh 0 "Missing # @scope:"
|
|
80
|
+
|
|
81
|
+
# ===== Fixture-path exemption (R2 fix for self-blocking bug) =====
|
|
82
|
+
# A Write to a path under .claude/hooks/__test-fixtures__/ must NOT be blocked
|
|
83
|
+
# by the hooks-pattern enforcement, even though the prefix matches /.claude/hooks/.
|
|
84
|
+
run_case "fixture-path-exempted" "" /.claude/hooks/__test-fixtures__/validate-structure/good/new-fixture.md 0
|
|
85
|
+
# Regression: the exemption must NOT inadvertently allow uppercase hook names
|
|
86
|
+
# OUTSIDE the __test-fixtures__/ subtree.
|
|
87
|
+
run_case "non-fixture-bad-hook-still-blocks" "" /.claude/hooks/Some_Bad.sh 2 "Filename must be kebab-case"
|
|
88
|
+
|
|
89
|
+
echo
|
|
90
|
+
echo "Total: $PASS passed, $FAIL failed"
|
|
91
|
+
if [ "$FAIL" -gt 0 ]; then
|
|
92
|
+
echo "Failed:$FAIL_LIST"
|
|
93
|
+
exit 1
|
|
94
|
+
fi
|
|
95
|
+
exit 0
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# @scope: org-shared
|
|
3
|
+
# Hook Helper: Template/context suggestion for validate-structure.sh
|
|
4
|
+
# Purpose: Map file locations to applicable templates or context files
|
|
5
|
+
# Sourced by validate-structure.sh - not run directly
|
|
6
|
+
#
|
|
7
|
+
# Expects: $REL_PATH, $REPO_ROOT (no shared lib helpers needed — pure mapping table)
|
|
8
|
+
|
|
9
|
+
TEMPLATE=""
|
|
10
|
+
|
|
11
|
+
# Map file location to template or context file
|
|
12
|
+
case "$REL_PATH" in
|
|
13
|
+
/.claude/skills/*) TEMPLATE="/packages/codebyplan-package/templates/skills/build-cc-skill/reference/cbp-quality.md" ;;
|
|
14
|
+
/.claude/agents/*/AGENT.md) TEMPLATE="/packages/codebyplan-package/templates/skills/build-cc-agent/reference/cbp-quality.md" ;;
|
|
15
|
+
/.claude/docs/research/*/1-*) TEMPLATE="/docs/templates/.claude/docs/research/1-problem.md" ;;
|
|
16
|
+
/.claude/docs/research/*/2-*) TEMPLATE="/docs/templates/.claude/docs/research/2-claude-default.md" ;;
|
|
17
|
+
/.claude/docs/research/*/3-*) TEMPLATE="/docs/templates/.claude/docs/research/3-official-docs.md" ;;
|
|
18
|
+
/.claude/docs/research/*/4-*) TEMPLATE="/docs/templates/.claude/docs/research/4-solutions.md" ;;
|
|
19
|
+
/.claude/docs/research/*/5-*) TEMPLATE="/docs/templates/.claude/docs/research/5-codebase-analysis.md" ;;
|
|
20
|
+
/.claude/docs/research/*/6-*) TEMPLATE="/docs/templates/.claude/docs/research/6-web-research.md" ;;
|
|
21
|
+
/.claude/docs/research/*/7-*) TEMPLATE="/docs/templates/.claude/docs/research/7-implementation.md" ;;
|
|
22
|
+
/.claude/docs/research/*/8-*) TEMPLATE="/docs/templates/.claude/docs/research/8-chosen.md" ;;
|
|
23
|
+
/.claude/docs/stack/*/index.md) TEMPLATE="/docs/templates/.claude/docs/stack/index.md" ;;
|
|
24
|
+
/.claude/docs/stack/*/usage.md) TEMPLATE="/docs/templates/.claude/docs/stack/usage.md" ;;
|
|
25
|
+
/.claude/docs/stack/*/guide.md) TEMPLATE="/docs/templates/.claude/docs/stack/guide.md" ;;
|
|
26
|
+
/.claude/docs/stack/*/updates.md) TEMPLATE="/docs/templates/.claude/docs/stack/updates.md" ;;
|
|
27
|
+
esac
|
|
28
|
+
|
|
29
|
+
# Output template suggestion if applicable
|
|
30
|
+
if [ -n "$TEMPLATE" ] && [ -f "$REPO_ROOT$TEMPLATE" ]; then
|
|
31
|
+
echo ""
|
|
32
|
+
echo "REFERENCE: $TEMPLATE"
|
|
33
|
+
echo "Read this file for quality expectations and required sections."
|
|
34
|
+
fi
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# @scope: org-shared
|
|
3
|
+
# @hook: PreToolUse Edit|Write
|
|
4
|
+
# Hook: PreToolUse for Edit|Write
|
|
5
|
+
# Purpose: Validate file paths against structure patterns
|
|
6
|
+
# Structure rules: /.claude/rules/structure-*.md (auto-loaded by Claude)
|
|
7
|
+
# This hook mirrors those rules for automated enforcement
|
|
8
|
+
#
|
|
9
|
+
# Exit 0 = allow, Exit 2 = block (stderr sent to Claude)
|
|
10
|
+
|
|
11
|
+
set -e
|
|
12
|
+
|
|
13
|
+
echo "[HOOK START] validate-structure"
|
|
14
|
+
|
|
15
|
+
REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
|
|
16
|
+
HOOK_DIR="$(dirname "$0")"
|
|
17
|
+
|
|
18
|
+
# Read JSON input from stdin
|
|
19
|
+
INPUT=$(cat)
|
|
20
|
+
|
|
21
|
+
# Source shared helpers (defines block, warn, match_path, read_input_content, etc.)
|
|
22
|
+
source "$HOOK_DIR/validate-structure-lib.sh"
|
|
23
|
+
|
|
24
|
+
# Extract file path
|
|
25
|
+
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // .tool_input.filePath // empty')
|
|
26
|
+
|
|
27
|
+
if [ -z "$FILE_PATH" ]; then
|
|
28
|
+
echo "[HOOK END] validate-structure (no file path)"
|
|
29
|
+
exit 0
|
|
30
|
+
fi
|
|
31
|
+
|
|
32
|
+
# Get relative path from repo root
|
|
33
|
+
REL_PATH="${FILE_PATH#$REPO_ROOT}"
|
|
34
|
+
|
|
35
|
+
# Get file extension
|
|
36
|
+
EXT="${FILE_PATH##*.}"
|
|
37
|
+
|
|
38
|
+
# Skip non-markdown/non-script files (source code, etc.)
|
|
39
|
+
case "$EXT" in
|
|
40
|
+
md|sh|json) ;;
|
|
41
|
+
*)
|
|
42
|
+
echo "[HOOK END] validate-structure (allowed: source code)"
|
|
43
|
+
exit 0
|
|
44
|
+
;;
|
|
45
|
+
esac
|
|
46
|
+
|
|
47
|
+
# ===== VALIDATE NAMING CONVENTION =====
|
|
48
|
+
FILENAME=$(basename "$FILE_PATH" ".$EXT")
|
|
49
|
+
|
|
50
|
+
if match_path '^/(\.claude|docs)/'; then
|
|
51
|
+
# Skip special naming patterns (SKILL/AGENT/CLAUDE/MEMORY/TASK-N/CHK-NNN/date/week-N/research phase/README)
|
|
52
|
+
# CHK formats: CHK-001 (generic) or CHK-H001/CHK-A001/CHK-B001 (launch: Homepage/Application/Backdoor)
|
|
53
|
+
if ! echo "$FILENAME" | grep -qE '^(SKILL|AGENT|CLAUDE|MEMORY|TASK-[1-9]|[0-9]{2}-[0-9]{2}-[0-9]{2}-CHK-([0-9]{3}|[HAB][0-9]{3})|CHK-([0-9]{3}|[HAB][0-9]{3})|[0-9]{2}-[0-9]{2}-[0-9]{2}|week-[0-9]+|[1-8]-|README)'; then
|
|
54
|
+
if echo "$FILENAME" | grep -qE '[A-Z]|_'; then
|
|
55
|
+
block "Filename must be kebab-case (lowercase with hyphens)" "Got: $FILENAME, Expected: $(echo "$FILENAME" | tr '[:upper:]' '[:lower:]' | tr '_' '-')"
|
|
56
|
+
fi
|
|
57
|
+
fi
|
|
58
|
+
fi
|
|
59
|
+
|
|
60
|
+
# ===== VALIDATE PATTERNS AND TEMPLATES =====
|
|
61
|
+
source "$HOOK_DIR/validate-structure-patterns.sh"
|
|
62
|
+
source "$HOOK_DIR/validate-structure-templates.sh"
|
|
63
|
+
source "$HOOK_DIR/validate-structure-scope.sh"
|
|
64
|
+
source "$HOOK_DIR/validate-structure-lengths.sh"
|
|
65
|
+
source "$HOOK_DIR/validate-context-usage.sh"
|
|
66
|
+
|
|
67
|
+
# ===== ALL VALIDATIONS PASSED =====
|
|
68
|
+
echo "[HOOK END] validate-structure (passed)"
|
|
69
|
+
exit 0
|
|
File without changes
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Rules
|
|
2
|
+
|
|
3
|
+
The `rules/` directory is a first-class shippable template category — parallel to `skills/`, `agents/`, and `hooks/` — for load-bearing behavioral constraints that the `@codebyplan/claude` CLI installs into a consuming project's `./.claude/rules/` directory.
|
|
4
|
+
|
|
5
|
+
## Bar for shipping a rule
|
|
6
|
+
|
|
7
|
+
A rule earns a place here only when it meets all three criteria:
|
|
8
|
+
|
|
9
|
+
1. **Load-bearing**: removing it would degrade Claude's behavior in a demonstrable way.
|
|
10
|
+
2. **High-signal**: the constraint fires on real patterns, not edge cases. Evidence of repeated application is required.
|
|
11
|
+
3. **Narrow scope**: the rule says one thing clearly. Omnibus or catch-all rules are rejected.
|
|
12
|
+
|
|
13
|
+
This is a curated set, not a dumping ground.
|
|
14
|
+
|
|
15
|
+
## File format
|
|
16
|
+
|
|
17
|
+
Flat `<name>.md` files at the top level of `templates/rules/`. Each file uses standard Claude rule frontmatter (YAML block at the top) followed by a markdown body:
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
---
|
|
21
|
+
scope: org-shared # CBP sync: org-shared | project-shared | repo-only:<repo-name>
|
|
22
|
+
paths:
|
|
23
|
+
# Narrow to the smallest directory that covers the rule's intent.
|
|
24
|
+
# Avoid "**/*.ts" — loads on every TS edit across the repo.
|
|
25
|
+
- "apps/*/src/app/api/**/*.ts"
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
Rule body here.
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
See `.claude/skills/build-cc-rule/templates/rule.md` for the authoritative template.
|
|
32
|
+
|
|
33
|
+
The `install`/`update`/`uninstall` flow handles these files identically to how it handles other template categories. No additional wiring is needed.
|
|
34
|
+
|
|
35
|
+
## Current status
|
|
36
|
+
|
|
37
|
+
Zero rules are shipped today. The wiring is in place so future PRs can land curated rules through the same install/update/uninstall flow as other templates.
|
|
38
|
+
|
|
39
|
+
## Contributing a rule
|
|
40
|
+
|
|
41
|
+
Each new rule needs its own justification in the PR description:
|
|
42
|
+
|
|
43
|
+
- Why it is load-bearing (what breaks without it)
|
|
44
|
+
- Evidence of high-signal application (where it has prevented problems)
|
|
45
|
+
- Scope statement (what the rule enforces and what it deliberately does not)
|
|
46
|
+
|
|
47
|
+
Rules that cannot answer all three are deferred until the evidence is there.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
---
|
|
2
|
+
scope: org-shared
|
|
3
|
+
paths:
|
|
4
|
+
- ".claude/context/**/*"
|
|
5
|
+
- ".claude/agents/**/*"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Context File Loading
|
|
9
|
+
|
|
10
|
+
`.claude/context/**` holds on-demand agent/skill input data — checklists, playbooks, framework recipes. This rule defines who loads what, when, and how missing files are handled.
|
|
11
|
+
|
|
12
|
+
## Canonical Mapping
|
|
13
|
+
|
|
14
|
+
| Context File | Loaded By | Phase | Purpose |
|
|
15
|
+
|--------------|-----------|-------|---------|
|
|
16
|
+
| `context/testing/unit.md` | `cbp-round-executor` | Step 3.6 | Unit test patterns per framework |
|
|
17
|
+
| `context/testing/e2e.md` | `cbp-test-e2e-agent` | Entry | E2E framework setup + spec patterns |
|
|
18
|
+
| `context/testing/e2e.md` | `cbp-testing-qa-agent` | Preflight | Env var list per framework |
|
|
19
|
+
| `context/testing/eslint.md` | `cbp-task-planner` | Phase 1.5 | ESLint Compliance Checklist |
|
|
20
|
+
| `context/testing/eslint.md` | `cbp-improve-round` | Phase 1.5 | Config-file compliance audit |
|
|
21
|
+
| `context/mcp-docs.md` | `cbp-task-planner` | Phase 2.6 | MCP library doc lookup contract — per-dependency consultation via DocsByPlan MCP tools (resolve_library_id → search_chunks/lookup_symbol → get_chunk) |
|
|
22
|
+
| `context/mcp-docs.md` | `cbp-round-executor` | Step 3.4 | Library-specific reference — pre-write API verification via DocsByPlan MCP tools |
|
|
23
|
+
|
|
24
|
+
New context files MUST be added here in the same change that introduces the consumer — or the file is orphan infrastructure.
|
|
25
|
+
|
|
26
|
+
## Load Contract
|
|
27
|
+
|
|
28
|
+
- **Read with the Read tool** — never paraphrase from memory
|
|
29
|
+
- **Fail loudly on missing file** — return `status: failed`, `reason: "required context file {path} not found"`; no fallback heuristic
|
|
30
|
+
- **Log the load** — agent output includes `context_loaded: [{path, sha_first_line}]` for auditability
|
|
31
|
+
|
|
32
|
+
## Why Fail Loudly
|
|
33
|
+
|
|
34
|
+
Silent fallback hides drift. A rename or deletion of `context/testing/unit.md` would let `cbp-round-executor` keep writing tests from memory, drifting from the canonical recipe. A failed agent surfaces the drift on the first invocation; silent fallback lets it compound.
|
|
35
|
+
|
|
36
|
+
## Path Convention
|
|
37
|
+
|
|
38
|
+
- `context/{topic}/` subdirectories (kebab-case)
|
|
39
|
+
- `context/{topic}/{name}.{md,json}` (kebab-case)
|
|
40
|
+
- No frontmatter required — these are inputs, not managed files
|
|
41
|
+
- Path layout enforced by `validate-structure-patterns.sh`
|
|
42
|
+
|
|
43
|
+
## Update Discipline
|
|
44
|
+
|
|
45
|
+
When editing a context file, check every consumer in the Canonical Mapping:
|
|
46
|
+
|
|
47
|
+
- Edit changes a section name or checklist item the consumer cites → update the consumer's phase description
|
|
48
|
+
- Edit is additive (new section) → no consumer update needed; agent re-reads on each invocation
|
|
49
|
+
|
|
50
|
+
## Orphans
|
|
51
|
+
|
|
52
|
+
A file under `context/**` with no consumer in the Canonical Mapping is infrastructure debt. `cbp-improve-claude` MUST flag orphans as high-priority cleanup proposals.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
---
|
|
2
|
+
scope: org-shared
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Scope Vocabulary
|
|
6
|
+
|
|
7
|
+
Canonical scope-marker enum for `.claude/` files. Every CBP-managed agent, skill, rule, and hook script must declare exactly one `scope:` value from the enum below. The marker is enforced by three validators (cross-linked at the bottom of this file).
|
|
8
|
+
|
|
9
|
+
## Enum values
|
|
10
|
+
|
|
11
|
+
- **`org-shared`** — Shared across organisations. CBP-framework infrastructure that lands identically in every consuming repo (e.g. the `cbp-build-cc-*` authoring skills, the validate-\* hooks, this rule). Updates propagate via the `codebyplan` package's `claude` subcommand group (`npx codebyplan claude install|update|uninstall`).
|
|
12
|
+
- **`project-shared`** — Shared within a single project family — multiple repos that live under one project umbrella. Use for skills/agents/rules that are reused across the project's apps + packages but not appropriate for cross-org distribution.
|
|
13
|
+
- **`repo-only:<repo-name>`** — Bound to a single repo. The `<repo-name>` suffix is the repo's slug (lowercase, dash-separated). Use for repo-specific automations that have no meaning outside that codebase.
|
|
14
|
+
|
|
15
|
+
## Examples
|
|
16
|
+
|
|
17
|
+
### YAML frontmatter form
|
|
18
|
+
|
|
19
|
+
Used by `.md` files (rules, skills, agents, CLAUDE.md). Place the marker in the top-of-file YAML block:
|
|
20
|
+
|
|
21
|
+
```yaml
|
|
22
|
+
---
|
|
23
|
+
scope: org-shared
|
|
24
|
+
---
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```yaml
|
|
28
|
+
---
|
|
29
|
+
scope: project-shared
|
|
30
|
+
---
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```yaml
|
|
34
|
+
---
|
|
35
|
+
scope: repo-only:codebyplan-mcp
|
|
36
|
+
---
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Shebang-comment form
|
|
40
|
+
|
|
41
|
+
Used by `.sh` hook scripts and `.sh` tooling under `.claude/`. Place the marker on a comment line near the top of the file (after the shebang):
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
#!/usr/bin/env bash
|
|
45
|
+
# @scope: org-shared
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
#!/usr/bin/env bash
|
|
50
|
+
# @scope: project-shared
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
#!/usr/bin/env bash
|
|
55
|
+
# @scope: repo-only:codebyplan-mcp
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Enforcement
|
|
59
|
+
|
|
60
|
+
Three validators enforce this enum. A file missing the marker (or carrying a non-enum value) fails validation:
|
|
61
|
+
|
|
62
|
+
- `.claude/hooks/validate-structure-scope.sh` — warns on missing markers across all `.claude/` files at session start.
|
|
63
|
+
- `.claude/skills/cbp-build-cc-agent/scripts/validate-agent.sh` — blocks agent authoring when `scope:` is absent.
|
|
64
|
+
- `.claude/skills/cbp-build-cc-skill/scripts/validate-skill.sh` — blocks skill authoring when `scope:` is absent.
|