cc-discipline 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +153 -0
- package/README.zh-CN.md +207 -0
- package/bin/cli.sh +96 -0
- package/global/CLAUDE.md +43 -0
- package/init.sh +486 -0
- package/lib/doctor.sh +145 -0
- package/lib/stack-remove.sh +68 -0
- package/lib/status.sh +95 -0
- package/package.json +34 -0
- package/templates/.claude/agents/investigator.md +44 -0
- package/templates/.claude/agents/reviewer.md +46 -0
- package/templates/.claude/hooks/action-counter.sh +28 -0
- package/templates/.claude/hooks/phase-gate.sh +10 -0
- package/templates/.claude/hooks/post-error-remind.sh +109 -0
- package/templates/.claude/hooks/pre-edit-guard.sh +79 -0
- package/templates/.claude/hooks/session-start.sh +43 -0
- package/templates/.claude/hooks/streak-breaker.sh +111 -0
- package/templates/.claude/rules/00-core-principles.md +12 -0
- package/templates/.claude/rules/01-debugging.md +22 -0
- package/templates/.claude/rules/02-before-edit.md +11 -0
- package/templates/.claude/rules/03-context-mgmt.md +19 -0
- package/templates/.claude/rules/04-no-mole-whacking.md +26 -0
- package/templates/.claude/rules/05-phase-discipline.md +13 -0
- package/templates/.claude/rules/06-multi-task.md +11 -0
- package/templates/.claude/rules/07-integrity.md +81 -0
- package/templates/.claude/rules/stacks/embedded.md +24 -0
- package/templates/.claude/rules/stacks/js-ts.md +21 -0
- package/templates/.claude/rules/stacks/mobile.md +16 -0
- package/templates/.claude/rules/stacks/python.md +20 -0
- package/templates/.claude/rules/stacks/rtl.md +24 -0
- package/templates/.claude/settings.json +75 -0
- package/templates/.claude/skills/commit/SKILL.md +40 -0
- package/templates/.claude/skills/evaluate/SKILL.md +57 -0
- package/templates/.claude/skills/self-check/SKILL.md +62 -0
- package/templates/CLAUDE.md +80 -0
- package/templates/docs/debug-log.md +48 -0
- package/templates/docs/progress.md +29 -0
- package/templates/memory/MEMORY.md +23 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TechHU
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# cc-discipline
|
|
2
|
+
|
|
3
|
+
Guardrails for Claude Code. Shell hooks that **actually block** bad behavior, not just markdown that asks nicely.
|
|
4
|
+
|
|
5
|
+
[中文文档](README.zh-CN.md)
|
|
6
|
+
|
|
7
|
+
## The Problem
|
|
8
|
+
|
|
9
|
+
Claude Code in long sessions tends to:
|
|
10
|
+
- Edit the same file 5+ times chasing symptoms instead of finding root cause
|
|
11
|
+
- See an error and immediately change code without understanding it
|
|
12
|
+
- Lose track of what it was doing after context compaction
|
|
13
|
+
|
|
14
|
+
Markdown rules help, but Claude can ignore them. **Hooks can't be ignored** — they run as shell scripts and `exit 2` physically blocks the operation.
|
|
15
|
+
|
|
16
|
+
## What This Does
|
|
17
|
+
|
|
18
|
+
### Hooks (the enforcer)
|
|
19
|
+
|
|
20
|
+
Three shell scripts that run automatically before/after Claude's actions:
|
|
21
|
+
|
|
22
|
+
**`streak-breaker.sh`** — Tracks per-file edit counts. Warns at 3, **hard-blocks at 5**. Forces Claude to stop and find the root cause instead of endlessly patching.
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
MOLE-WHACKING ALERT (hard stop)
|
|
26
|
+
File src/auth.py has been edited 5 times.
|
|
27
|
+
You are repeatedly patching symptoms instead of solving the root cause.
|
|
28
|
+
Required actions:
|
|
29
|
+
1. Stop editing this file immediately
|
|
30
|
+
2. Review the purpose of all 5 edits
|
|
31
|
+
3. Look for the common root cause
|
|
32
|
+
4. Report findings to the user and wait for guidance
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**`pre-edit-guard.sh`** — Checks `docs/debug-log.md` for unverified hypotheses. If you're debugging and haven't finished the process, it blocks source code edits until you do.
|
|
36
|
+
|
|
37
|
+
**`post-error-remind.sh`** — Detects error patterns (test failures, crashes, build errors) in command output and injects a debugging discipline reminder before Claude can react impulsively.
|
|
38
|
+
|
|
39
|
+
### Rules (the reminders)
|
|
40
|
+
|
|
41
|
+
Auto-injected markdown in `.claude/rules/` — Claude sees them when operating on matching files. Not as strong as hooks, but provides structure:
|
|
42
|
+
|
|
43
|
+
- Debugging process: gather → hypothesize → verify → fix (no skipping)
|
|
44
|
+
- Pre-edit checklist: understand the file, know the impact, fix root cause
|
|
45
|
+
- Mole-whacking detection: recognize the pattern, stop, report
|
|
46
|
+
- Phase discipline: stay in research/plan/implement, don't jump ahead
|
|
47
|
+
- Multi-task gates: complete tasks in order, confirm each before moving on
|
|
48
|
+
- Tech stack rules for Python, JS/TS, embedded, RTL, mobile
|
|
49
|
+
|
|
50
|
+
### Subagents (the auditors)
|
|
51
|
+
|
|
52
|
+
- **reviewer** — Reviews your modification plan in a separate context. Challenges assumptions, suggests alternatives, checks for missing edge cases.
|
|
53
|
+
- **investigator** — Researches the codebase in isolation. Returns structured findings without polluting your main conversation.
|
|
54
|
+
|
|
55
|
+
## Install
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
git clone https://github.com/TechHU-GS/cc-discipline.git ~/.cc-discipline
|
|
59
|
+
cd your-project
|
|
60
|
+
bash ~/.cc-discipline/init.sh
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The installer is interactive — pick your tech stack, name your project, done.
|
|
64
|
+
|
|
65
|
+
**Already have a `.claude/` setup?** The installer detects this and runs in append mode:
|
|
66
|
+
- Your `CLAUDE.md` is **never overwritten**
|
|
67
|
+
- Your `settings.json` hooks are **preserved** (cc-discipline hooks are merged in via `jq`)
|
|
68
|
+
- Your custom rules, agents, and docs are **untouched**
|
|
69
|
+
- A timestamped backup is created before any changes
|
|
70
|
+
|
|
71
|
+
**Upgrading?** Just run `init.sh` again. It detects the existing installation and updates framework files while preserving your configuration.
|
|
72
|
+
|
|
73
|
+
## What Gets Installed
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
.claude/
|
|
77
|
+
├── rules/ # Auto-injected when Claude operates on matching files
|
|
78
|
+
│ ├── 00-core-principles.md
|
|
79
|
+
│ ├── 01-debugging.md
|
|
80
|
+
│ ├── 02-before-edit.md
|
|
81
|
+
│ ├── 03-context-mgmt.md
|
|
82
|
+
│ ├── 04-no-mole-whacking.md
|
|
83
|
+
│ ├── 05-phase-discipline.md
|
|
84
|
+
│ ├── 06-multi-task.md
|
|
85
|
+
│ └── stacks/ # Picked during install
|
|
86
|
+
├── hooks/ # Shell scripts, exit 2 = block operation
|
|
87
|
+
│ ├── streak-breaker.sh
|
|
88
|
+
│ ├── pre-edit-guard.sh
|
|
89
|
+
│ └── post-error-remind.sh
|
|
90
|
+
├── agents/
|
|
91
|
+
│ ├── reviewer.md
|
|
92
|
+
│ └── investigator.md
|
|
93
|
+
├── skills/
|
|
94
|
+
│ └── commit/SKILL.md # /commit: test → update docs → commit
|
|
95
|
+
└── settings.json # Hook registration
|
|
96
|
+
docs/
|
|
97
|
+
├── progress.md # Claude maintains this, read after compact
|
|
98
|
+
└── debug-log.md # Debug session tracking
|
|
99
|
+
CLAUDE.md # Your project info (you fill this in)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Customization
|
|
103
|
+
|
|
104
|
+
**Adjust hook strictness:**
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# In .claude/hooks/streak-breaker.sh
|
|
108
|
+
WARN_THRESHOLD=3 # Warn after N edits to same file
|
|
109
|
+
STOP_THRESHOLD=5 # Hard block after N edits
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**Add your own rules:**
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
cat > .claude/rules/my-rule.md << 'EOF'
|
|
116
|
+
---
|
|
117
|
+
globs: "src/api/**/*"
|
|
118
|
+
description: "API layer rules"
|
|
119
|
+
---
|
|
120
|
+
- All API changes must be backwards-compatible
|
|
121
|
+
- New endpoints need OpenAPI spec updates
|
|
122
|
+
EOF
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**Write your own hooks:**
|
|
126
|
+
|
|
127
|
+
Any script in `.claude/hooks/` can be registered in `settings.json`. The key behaviors:
|
|
128
|
+
- `exit 0` = allow (stdout can inject context via JSON for PreToolUse hooks)
|
|
129
|
+
- `exit 2` + stderr = block operation, stderr message shown to Claude
|
|
130
|
+
|
|
131
|
+
See [Claude Code hooks docs](https://docs.anthropic.com/en/docs/claude-code/hooks) for the full spec.
|
|
132
|
+
|
|
133
|
+
## FAQ
|
|
134
|
+
|
|
135
|
+
**Is this just markdown rules?**
|
|
136
|
+
No. The hooks are the real enforcement — they're shell scripts that physically block operations. The rules are supplementary structure.
|
|
137
|
+
|
|
138
|
+
**Does it slow things down?**
|
|
139
|
+
No. Hooks are lightweight shell scripts, typically <100ms. Rules add ~8KB to context (~2%).
|
|
140
|
+
|
|
141
|
+
**Should I commit `.claude/` to git?**
|
|
142
|
+
Yes. Team members get the same guardrails. Hook paths use `$CLAUDE_PROJECT_DIR`, so they work across machines.
|
|
143
|
+
|
|
144
|
+
**Does it work with existing projects?**
|
|
145
|
+
Yes. The installer has an append mode that merges with your existing `.claude/` configuration without overwriting anything. Run `init.sh` and it auto-detects.
|
|
146
|
+
|
|
147
|
+
## Contributing
|
|
148
|
+
|
|
149
|
+
PRs welcome — especially new hooks. The hooks are where the real value is.
|
|
150
|
+
|
|
151
|
+
## License
|
|
152
|
+
|
|
153
|
+
[MIT](LICENSE)
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# cc-discipline
|
|
2
|
+
|
|
3
|
+
**Claude Code 项目纪律框架** — 让 AI 编码助手在复杂任务中保持专注和纪律。
|
|
4
|
+
|
|
5
|
+
解决 Claude Code 在长对话、复杂任务中常见的问题:
|
|
6
|
+
- 🎯 思路跑偏、丢失主线目标
|
|
7
|
+
- 🔨 打地鼠式修补症状
|
|
8
|
+
- ⚡ 急于锁定第一个解释
|
|
9
|
+
- 🧠 compact 后丢失关键上下文和原则
|
|
10
|
+
- 🔄 反复犯同样的错误
|
|
11
|
+
|
|
12
|
+
## 架构:三层防线
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
┌─────────────────────────────────────────┐
|
|
16
|
+
│ Layer 3: Subagents(独立判断) │
|
|
17
|
+
│ reviewer — 独立 context 审查方案 │
|
|
18
|
+
│ investigator — 隔离调研不污染主对话 │
|
|
19
|
+
├─────────────────────────────────────────┤
|
|
20
|
+
│ Layer 2: Hooks(代码强制) │
|
|
21
|
+
│ pre-edit-guard — 编辑前检查纪律 │
|
|
22
|
+
│ streak-breaker — 检测打地鼠模式 │
|
|
23
|
+
│ post-error-remind — 错误后提醒流程 │
|
|
24
|
+
├─────────────────────────────────────────┤
|
|
25
|
+
│ Layer 1: Rules(自动注入) │
|
|
26
|
+
│ core-principles — 核心原则 │
|
|
27
|
+
│ debugging — 调试纪律 │
|
|
28
|
+
│ before-edit — 修改前检查 │
|
|
29
|
+
│ context-mgmt — 上下文管理 │
|
|
30
|
+
│ no-mole-whacking — 反打地鼠 │
|
|
31
|
+
│ stacks/* — 技术栈特有规则 │
|
|
32
|
+
├─────────────────────────────────────────┤
|
|
33
|
+
│ Foundation: CLAUDE.md + docs/ │
|
|
34
|
+
│ 项目信息 + 进度记录 + 调试日志 │
|
|
35
|
+
└─────────────────────────────────────────┘
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**Rules** = 贴在它眼前(自动注入,按路径触发)
|
|
39
|
+
**Hooks** = 锁住它的手(代码级强制,可阻止操作)
|
|
40
|
+
**Subagents** = 派人盯着它(独立 context 审查,不被主对话惯性影响)
|
|
41
|
+
|
|
42
|
+
## 快速开始
|
|
43
|
+
|
|
44
|
+
### 方法 1: 克隆 + 初始化脚本
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
git clone https://github.com/TechHU-GS/cc-discipline.git ~/.cc-discipline
|
|
48
|
+
|
|
49
|
+
# In your project directory:
|
|
50
|
+
cd your-project
|
|
51
|
+
bash ~/.cc-discipline/init.sh
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 方法 2: GitHub Template
|
|
55
|
+
|
|
56
|
+
1. 点击本仓库的 **Use this template** 按钮
|
|
57
|
+
2. 创建新项目后,编辑 `CLAUDE.md` 填写项目信息
|
|
58
|
+
|
|
59
|
+
### 方法 3: 只安装全局规则
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
git clone https://github.com/TechHU-GS/cc-discipline.git /tmp/cc-discipline
|
|
63
|
+
cp /tmp/cc-discipline/global/CLAUDE.md ~/.claude/CLAUDE.md
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## 文件结构
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
your-project/
|
|
70
|
+
├── CLAUDE.md # 项目特有信息(你维护)
|
|
71
|
+
├── .claude/
|
|
72
|
+
│ ├── settings.json # Hooks 配置
|
|
73
|
+
│ ├── rules/
|
|
74
|
+
│ │ ├── 00-core-principles.md # 核心工作原则
|
|
75
|
+
│ │ ├── 01-debugging.md # 调试纪律
|
|
76
|
+
│ │ ├── 02-before-edit.md # 修改前检查
|
|
77
|
+
│ │ ├── 03-context-mgmt.md # 上下文管理
|
|
78
|
+
│ │ ├── 04-no-mole-whacking.md # 反打地鼠
|
|
79
|
+
│ │ └── stacks/ # 技术栈特有规则
|
|
80
|
+
│ │ ├── rtl.md # RTL / IC 设计
|
|
81
|
+
│ │ ├── embedded.md # 嵌入式 C/C++
|
|
82
|
+
│ │ ├── python.md # Python
|
|
83
|
+
│ │ ├── js-ts.md # JavaScript/TypeScript
|
|
84
|
+
│ │ └── mobile.md # 移动端
|
|
85
|
+
│ ├── hooks/
|
|
86
|
+
│ │ ├── pre-edit-guard.sh # 编辑前纪律检查
|
|
87
|
+
│ │ ├── streak-breaker.sh # 打地鼠检测(同文件编辑≥5次硬停止)
|
|
88
|
+
│ │ └── post-error-remind.sh # 错误后调试流程提醒
|
|
89
|
+
│ ├── agents/
|
|
90
|
+
│ │ ├── reviewer.md # 代码审查员(独立 context)
|
|
91
|
+
│ │ └── investigator.md # 代码调查员(隔离调研)
|
|
92
|
+
│ └── skills/
|
|
93
|
+
│ └── commit/SKILL.md # /commit 智能提交
|
|
94
|
+
├── docs/
|
|
95
|
+
│ ├── progress.md # 进度记录(Claude 维护)
|
|
96
|
+
│ └── debug-log.md # 调试日志(Claude 维护)
|
|
97
|
+
└── ~/.claude/
|
|
98
|
+
└── CLAUDE.md # 全局通用纪律(可选)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## 各层详解
|
|
102
|
+
|
|
103
|
+
### Rules(自动注入)
|
|
104
|
+
|
|
105
|
+
放在 `.claude/rules/` 下的 Markdown 文件会根据 `globs` 匹配自动注入到 Claude 的上下文中。
|
|
106
|
+
Claude 无法选择性忽略这些规则——它们在操作匹配文件时会自动出现。
|
|
107
|
+
|
|
108
|
+
**核心规则**(对所有文件生效):
|
|
109
|
+
- `00-core-principles.md` — 先理解再动手、不锁定第一解释、连续3次失败必须停下
|
|
110
|
+
- `01-debugging.md` — 四阶段调试流程(收集→假设→验证→修复)
|
|
111
|
+
- `03-context-mgmt.md` — 主动检查点、调研隔离、compact 策略
|
|
112
|
+
- `04-no-mole-whacking.md` — 打地鼠检测和汇报模板
|
|
113
|
+
|
|
114
|
+
**源码规则**(编辑 src/ 等目录时生效):
|
|
115
|
+
- `02-before-edit.md` — 修改前的 5 项强制检查
|
|
116
|
+
|
|
117
|
+
**技术栈规则**(按文件类型触发):
|
|
118
|
+
- `.v/.sv/.vhd` → RTL 规则(时序意识、CDC 检查、综合/仿真区分)
|
|
119
|
+
- `.c/.h` → 嵌入式规则(资源意识、中断安全、volatile)
|
|
120
|
+
- `.py` → Python 规则(类型标注、依赖管理、测试)
|
|
121
|
+
- `.js/.ts/.tsx` → JS/TS 规则(类型安全、异步处理)
|
|
122
|
+
- `.swift/.kt/.dart` → 移动端规则(主线程、生命周期、权限)
|
|
123
|
+
|
|
124
|
+
### Hooks(代码强制)
|
|
125
|
+
|
|
126
|
+
Hooks 是在 Claude 执行操作前/后自动运行的 shell 脚本。**exit 2 可以直接阻止操作**。
|
|
127
|
+
|
|
128
|
+
| Hook | 触发时机 | 作用 |
|
|
129
|
+
|------|---------|------|
|
|
130
|
+
| `pre-edit-guard.sh` | 编辑文件前 | 检查是否有未完成的调试流程 |
|
|
131
|
+
| `streak-breaker.sh` | 编辑文件前 | 同文件编辑 ≥3 次警告,≥5 次硬停止 |
|
|
132
|
+
| `post-error-remind.sh` | 执行命令后 | 检测到错误输出时提醒遵守调试纪律 |
|
|
133
|
+
|
|
134
|
+
**调整硬度**:编辑 hook 脚本中的 `exit` 返回值:
|
|
135
|
+
- `exit 0` = 允许操作(可附带提醒信息)
|
|
136
|
+
- `exit 1` = 报错但不阻止操作(hook 执行失败)
|
|
137
|
+
- `exit 2` = 阻止操作,Claude 看到消息后会调整行为(硬停止)
|
|
138
|
+
|
|
139
|
+
### Subagents(独立判断)
|
|
140
|
+
|
|
141
|
+
| Agent | 用途 | 权限 |
|
|
142
|
+
|-------|------|------|
|
|
143
|
+
| `reviewer` | 审查修改方案是否合理 | 只读(Read, Grep, Glob) |
|
|
144
|
+
| `investigator` | 深入调研代码库 | 只读 + Bash(仅限查询命令) |
|
|
145
|
+
|
|
146
|
+
使用方式:
|
|
147
|
+
```
|
|
148
|
+
让 reviewer 审查我的修改方案
|
|
149
|
+
让 investigator 调查 src/auth/ 模块的实现
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## 自定义
|
|
153
|
+
|
|
154
|
+
### 添加项目特有规则
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
# Create a new rule
|
|
158
|
+
cat > .claude/rules/my-rule.md << 'EOF'
|
|
159
|
+
---
|
|
160
|
+
globs: "src/api/**/*"
|
|
161
|
+
description: "API 层特有规则"
|
|
162
|
+
---
|
|
163
|
+
## API 修改规则
|
|
164
|
+
- 所有 API 变更必须向后兼容
|
|
165
|
+
- 新增 endpoint 必须有对应的 OpenAPI spec 更新
|
|
166
|
+
EOF
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### 调整 Hook 灵敏度
|
|
170
|
+
|
|
171
|
+
编辑 `.claude/hooks/streak-breaker.sh`:
|
|
172
|
+
```bash
|
|
173
|
+
WARN_THRESHOLD=3 # Warning after N edits to same file
|
|
174
|
+
STOP_THRESHOLD=5 # Hard block after N edits to same file
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### 添加新的子代理
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
cat > .claude/agents/my-agent.md << 'EOF'
|
|
181
|
+
---
|
|
182
|
+
name: my-agent
|
|
183
|
+
description: "描述这个子代理做什么"
|
|
184
|
+
model: sonnet
|
|
185
|
+
tools: Read, Grep, Glob
|
|
186
|
+
---
|
|
187
|
+
你是 [角色描述]。你的职责是...
|
|
188
|
+
EOF
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## FAQ
|
|
192
|
+
|
|
193
|
+
**Q: Rules 和 CLAUDE.md 有什么区别?**
|
|
194
|
+
A: CLAUDE.md 在对话开始时读取一次。Rules 是按文件路径匹配自动注入的——当 Claude 操作匹配 glob 的文件时,对应规则会自动出现在它的上下文中。Rules 更可靠,因为它们不依赖 Claude "记得去看"。
|
|
195
|
+
|
|
196
|
+
**Q: Hooks 会影响性能吗?**
|
|
197
|
+
A: 几乎不会。它们是轻量的 shell 脚本,执行时间通常 <100ms。
|
|
198
|
+
|
|
199
|
+
**Q: 可以把 .claude/ 提交到 git 吗?**
|
|
200
|
+
A: 强烈建议提交。这样团队成员都能共享同一套纪律。注意 `.claude/settings.json` 中的 hooks 路径是相对路径,团队成员不需要额外配置。
|
|
201
|
+
|
|
202
|
+
**Q: 和 devpace 等第三方工具冲突吗?**
|
|
203
|
+
A: 不冲突。本框架是纯文件级别的,不依赖任何第三方工具。可以和 devpace、Claude MPM 等工具并行使用。
|
|
204
|
+
|
|
205
|
+
## License
|
|
206
|
+
|
|
207
|
+
MIT — 自由使用、修改、分发。
|
package/bin/cli.sh
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# cc-discipline CLI entry point
|
|
3
|
+
# Resolves symlinks (npm bin creates symlinks) to find the real package directory
|
|
4
|
+
|
|
5
|
+
set -e
|
|
6
|
+
|
|
7
|
+
# Resolve the real path of this script (works through npm symlinks)
|
|
8
|
+
SOURCE="${BASH_SOURCE[0]}"
|
|
9
|
+
while [ -L "$SOURCE" ]; do
|
|
10
|
+
DIR="$(cd "$(dirname "$SOURCE")" && pwd)"
|
|
11
|
+
SOURCE="$(readlink "$SOURCE")"
|
|
12
|
+
# If SOURCE is relative, resolve it relative to DIR
|
|
13
|
+
[[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE"
|
|
14
|
+
done
|
|
15
|
+
BIN_DIR="$(cd "$(dirname "$SOURCE")" && pwd)"
|
|
16
|
+
PKG_DIR="$(cd "$BIN_DIR/.." && pwd)"
|
|
17
|
+
|
|
18
|
+
export CC_DISCIPLINE_PKG_DIR="$PKG_DIR"
|
|
19
|
+
|
|
20
|
+
# ─── Version ───
|
|
21
|
+
VERSION=$(node -p "require('$PKG_DIR/package.json').version" 2>/dev/null || echo "unknown")
|
|
22
|
+
|
|
23
|
+
# ─── Route subcommands ───
|
|
24
|
+
COMMAND="${1:-init}"
|
|
25
|
+
|
|
26
|
+
case "$COMMAND" in
|
|
27
|
+
init)
|
|
28
|
+
shift 2>/dev/null || true
|
|
29
|
+
bash "$PKG_DIR/init.sh" "$@"
|
|
30
|
+
;;
|
|
31
|
+
upgrade)
|
|
32
|
+
shift
|
|
33
|
+
bash "$PKG_DIR/init.sh" --auto "$@"
|
|
34
|
+
;;
|
|
35
|
+
status)
|
|
36
|
+
bash "$PKG_DIR/lib/status.sh"
|
|
37
|
+
;;
|
|
38
|
+
doctor)
|
|
39
|
+
bash "$PKG_DIR/lib/doctor.sh"
|
|
40
|
+
;;
|
|
41
|
+
add-stack)
|
|
42
|
+
shift
|
|
43
|
+
if [ -z "$1" ]; then
|
|
44
|
+
echo "Usage: cc-discipline add-stack <numbers>"
|
|
45
|
+
echo " e.g.: cc-discipline add-stack 3 4"
|
|
46
|
+
exit 1
|
|
47
|
+
fi
|
|
48
|
+
bash "$PKG_DIR/init.sh" --stack "$*" --no-global
|
|
49
|
+
;;
|
|
50
|
+
remove-stack)
|
|
51
|
+
shift
|
|
52
|
+
bash "$PKG_DIR/lib/stack-remove.sh" "$@"
|
|
53
|
+
;;
|
|
54
|
+
-v|--version|version)
|
|
55
|
+
echo "cc-discipline v${VERSION}"
|
|
56
|
+
;;
|
|
57
|
+
-h|--help|help)
|
|
58
|
+
cat <<EOF
|
|
59
|
+
cc-discipline v${VERSION} — Discipline framework for Claude Code
|
|
60
|
+
|
|
61
|
+
Usage: cc-discipline <command> [options]
|
|
62
|
+
|
|
63
|
+
Commands:
|
|
64
|
+
init [options] Install discipline into current project (default)
|
|
65
|
+
upgrade Upgrade rules/hooks (shortcut for init --auto)
|
|
66
|
+
add-stack <numbers> Add stack rules (e.g., add-stack 3 4)
|
|
67
|
+
remove-stack <numbers> Remove stack rules
|
|
68
|
+
status Show installed version, stacks, and hooks
|
|
69
|
+
doctor Check installation integrity
|
|
70
|
+
version Show version
|
|
71
|
+
|
|
72
|
+
Init options:
|
|
73
|
+
--auto Non-interactive with defaults
|
|
74
|
+
--stack <choices> Stack selection: 1-7, space-separated
|
|
75
|
+
--name <name> Project name (default: directory name)
|
|
76
|
+
--global Install global rules to ~/.claude/CLAUDE.md
|
|
77
|
+
--no-global Skip global rules install
|
|
78
|
+
|
|
79
|
+
Stacks:
|
|
80
|
+
1=RTL 2=Embedded 3=Python 4=JS/TS 5=Mobile 6=Fullstack 7=General
|
|
81
|
+
|
|
82
|
+
Examples:
|
|
83
|
+
npx cc-discipline # Interactive setup
|
|
84
|
+
npx cc-discipline init --auto # Non-interactive defaults
|
|
85
|
+
npx cc-discipline init --auto --stack "3 4" # Python + JS/TS
|
|
86
|
+
npx cc-discipline upgrade # Upgrade to latest
|
|
87
|
+
npx cc-discipline status # Check what's installed
|
|
88
|
+
npx cc-discipline doctor # Diagnose issues
|
|
89
|
+
EOF
|
|
90
|
+
;;
|
|
91
|
+
*)
|
|
92
|
+
echo "Unknown command: $COMMAND"
|
|
93
|
+
echo "Run 'cc-discipline --help' for usage"
|
|
94
|
+
exit 1
|
|
95
|
+
;;
|
|
96
|
+
esac
|
package/global/CLAUDE.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Global Discipline — applies to all projects
|
|
2
|
+
|
|
3
|
+
> This file is placed at ~/.claude/CLAUDE.md and applies to all projects.
|
|
4
|
+
> Project-specific rules go in each project's CLAUDE.md and .claude/rules/.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Mindset
|
|
9
|
+
|
|
10
|
+
You are an **engineer**, not a **code generator**.
|
|
11
|
+
An engineer's core competency is: understand the problem → analyze approaches → weigh trade-offs → execute precisely.
|
|
12
|
+
Don't skip the first three steps and jump straight to the fourth.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Universal Principles
|
|
17
|
+
|
|
18
|
+
1. **Understand before acting** — If unsure, ask. Don't guess.
|
|
19
|
+
2. **Minimal changes** — Do what is asked. Don't do what isn't asked.
|
|
20
|
+
3. **One thing at a time** — Don't mix unrelated changes in a single modification.
|
|
21
|
+
4. **Explain your reasoning** — Especially when making trade-off judgments.
|
|
22
|
+
5. **Admit uncertainty** — "I'm not sure because..." is 100x better than a confident wrong answer.
|
|
23
|
+
|
|
24
|
+
<!-- Anti-pattern checks moved to .claude/rules/00-core-principles.md and 04-no-mole-whacking.md,
|
|
25
|
+
project-level rules are auto-injected, no need to repeat here. -->
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Collaboration with Humans
|
|
30
|
+
|
|
31
|
+
- When human says "stop", stop immediately. Don't say "let me try one more thing".
|
|
32
|
+
- When human corrects you, first understand why you were wrong. Don't just change to what human said and move on.
|
|
33
|
+
- When unsure of human's intent, confirm before acting.
|
|
34
|
+
- Provide options for human to decide, rather than making decisions for them.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Context Hygiene
|
|
39
|
+
|
|
40
|
+
- Use subagents for research. Don't read large volumes of files in the main conversation.
|
|
41
|
+
- Update docs/progress.md after completing each milestone.
|
|
42
|
+
- Proactively warn when context is nearly full. Don't wait for auto-compact.
|
|
43
|
+
- First thing after compact: read `docs/progress.md` and `docs/debug-log.md`.
|