claude-everything-workflow 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +50 -19
  2. package/hooks/check-code-size.js +111 -0
  3. package/package.json +1 -1
  4. package/rules/02-code-size.md +11 -2
  5. package/rules/common/hooks.md +2 -1
  6. package/rules/common/skills-learning.md +7 -0
  7. package/scripts/install.ps1 +80 -43
  8. package/scripts/install.sh +56 -3
  9. package/scripts/verify-harness.js +156 -26
  10. package/settings.json +8 -40
  11. package/skills/brainstorming/scripts/frame-template.html +25 -26
  12. package/skills/brainstorming/scripts/helper.js +101 -22
  13. package/skills/brainstorming/scripts/server.cjs +399 -30
  14. package/skills/brainstorming/scripts/start-server.sh +70 -9
  15. package/skills/brainstorming/scripts/stop-server.sh +66 -2
  16. package/skills/brainstorming/visual-companion.md +33 -22
  17. package/skills/learn/.gitkeep +0 -0
  18. package/skills/learn/README.md +15 -0
  19. package/skills/learn/debugging/.gitkeep +0 -0
  20. package/skills/learn/pr/.gitkeep +0 -0
  21. package/skills/learn/testing/.gitkeep +0 -0
  22. package/skills/subagent-driven-development/SKILL.md +425 -0
  23. package/skills/subagent-driven-development/implementer-prompt.md +139 -0
  24. package/skills/subagent-driven-development/scripts/review-package +44 -0
  25. package/skills/subagent-driven-development/scripts/sdd-workspace +22 -0
  26. package/skills/subagent-driven-development/scripts/task-brief +40 -0
  27. package/skills/subagent-driven-development/task-reviewer-prompt.md +188 -0
  28. package/skills/using-superpowers/SKILL.md +75 -0
  29. package/skills/writing-plans/SKILL.md +25 -2
  30. package/commands/acceptance.md +0 -73
  31. package/hooks/evaluate-session.js +0 -59
  32. package/hooks/pre-compact.js +0 -92
  33. package/hooks/runtime/session-utils.js +0 -45
  34. package/hooks/session-end.js +0 -62
  35. package/hooks/session-start.js +0 -60
@@ -0,0 +1,188 @@
1
+ # Task Reviewer Prompt Template
2
+
3
+ Use this template when dispatching a task reviewer subagent. The reviewer
4
+ reads the task's diff once and returns two verdicts: spec compliance and
5
+ code quality.
6
+
7
+ **Purpose:** Verify one task's implementation matches its requirements (nothing
8
+ more, nothing less) and is well-built (clean, tested, maintainable)
9
+
10
+ ```
11
+ Subagent (general-purpose):
12
+ description: "Review Task N (spec + quality)"
13
+ model: [MODEL — REQUIRED: choose per SKILL.md Model Selection; an omitted
14
+ model silently inherits the session's most expensive one]
15
+ prompt: |
16
+ You are reviewing one task's implementation: first whether it matches its
17
+ requirements, then whether it is well-built. This is a task-scoped gate,
18
+ not a merge review — a broad whole-branch review happens separately after
19
+ all tasks are complete.
20
+
21
+ ## What Was Requested
22
+
23
+ Read the task brief: [BRIEF_FILE]
24
+
25
+ Global constraints from the spec/design that bind this task:
26
+ [GLOBAL_CONSTRAINTS]
27
+
28
+ ## What the Implementer Claims They Built
29
+
30
+ Read the implementer's report: [REPORT_FILE]
31
+
32
+ ## Diff Under Review
33
+
34
+ **Base:** [BASE_SHA]
35
+ **Head:** [HEAD_SHA]
36
+ **Diff file:** [DIFF_FILE]
37
+
38
+ Read the diff file once — it contains the commit list, a stat summary,
39
+ and the full diff with surrounding context, and it is your view of the
40
+ change. The diff's context lines ARE the changed files: do not Read a
41
+ changed file separately unless a hunk you must judge is cut off
42
+ mid-function — and say so in your report. Do not re-run git commands.
43
+ If the diff file is missing, fetch the diff yourself:
44
+ `git diff --stat [BASE_SHA]..[HEAD_SHA]` and `git diff [BASE_SHA]..[HEAD_SHA]`.
45
+ Do not crawl the broader codebase. Inspect code outside the diff only
46
+ to evaluate a concrete risk you can name — one focused check per named
47
+ risk, and name both the risk and what you checked in your report.
48
+ Cross-cutting changes are legitimate named risks: if the diff changes
49
+ lock ordering, a function or API contract, or shared mutable state,
50
+ checking the call sites is the right method.
51
+
52
+ Your review is read-only on this checkout. Do not mutate the working
53
+ tree, the index, HEAD, or branch state in any way.
54
+
55
+ ## Do Not Trust the Report
56
+
57
+ Treat the implementer's report as unverified claims about the code. It
58
+ may be incomplete, inaccurate, or optimistic. Verify the claims against
59
+ the diff. Design rationales in the report are claims too: "left it per
60
+ YAGNI," "kept it simple deliberately," or any other justification is the
61
+ implementer grading their own work. Judge the code on its merits — a
62
+ stated rationale never downgrades a finding's severity.
63
+
64
+ ## Tests
65
+
66
+ The implementer already ran the tests and reported results with TDD
67
+ evidence for exactly this code. Do not re-run the suite to confirm their
68
+ report. Run a test only when reading the code raises a specific doubt
69
+ that no existing run answers — and then a focused test, never a
70
+ package-wide suite, race detector run, or repeated/high-count loop. If
71
+ heavy validation seems warranted, recommend it in your report instead of
72
+ running it. If you cannot run commands in this environment, name the
73
+ test you would run.
74
+
75
+ Warnings or other noise in the implementer's reported test output are
76
+ findings — test output should be pristine.
77
+
78
+ ## Part 1: Spec Compliance
79
+
80
+ Compare the diff against What Was Requested:
81
+
82
+ - **Missing:** requirements they skipped, missed, or claimed without
83
+ implementing
84
+ - **Extra:** features that weren't requested, over-engineering, unneeded
85
+ "nice to haves"
86
+ - **Misunderstood:** right feature built the wrong way, wrong problem
87
+ solved
88
+
89
+ If a requirement cannot be verified from this diff alone (it lives in
90
+ unchanged code or spans tasks), report it as a ⚠️ item instead of
91
+ broadening your search.
92
+
93
+ ## Part 2: Code Quality
94
+
95
+ **Code quality:**
96
+ - Clean separation of concerns?
97
+ - Proper error handling?
98
+ - DRY without premature abstraction?
99
+ - Edge cases handled?
100
+
101
+ **Tests:**
102
+ - Do the new and changed tests verify real behavior, not mocks?
103
+ - Are the task's edge cases covered?
104
+
105
+ **Structure:**
106
+ - Does each file have one clear responsibility with a well-defined interface?
107
+ - Are units decomposed so they can be understood and tested independently?
108
+ - Is the implementation following the file structure from the plan?
109
+ - Did this change create new files that are already large, or
110
+ significantly grow existing files? (Don't flag pre-existing file
111
+ sizes — focus on what this change contributed.)
112
+
113
+ Your report should point at evidence: file:line references for every
114
+ finding and for any check you would otherwise answer with a bare
115
+ "yes." A tight report that cites lines gives the controller everything
116
+ it needs.
117
+
118
+ Your final message is the report itself: begin directly with the
119
+ spec-compliance verdict. Every line is a verdict, a finding with
120
+ file:line, or a check you ran — no preamble, no process narration,
121
+ no closing summary.
122
+
123
+ ## Calibration
124
+
125
+ Categorize issues by actual severity. Not everything is Critical.
126
+ Important means this task cannot be trusted until it is fixed: incorrect
127
+ or fragile behavior, a missed requirement, or maintainability damage you
128
+ would block a merge over — verbatim duplication of a logic block,
129
+ swallowed errors, tests that assert nothing. "Coverage could be broader"
130
+ and polish suggestions are Minor.
131
+ If the plan or brief explicitly mandates something this rubric calls a
132
+ defect (a test that asserts nothing, verbatim duplication of a logic
133
+ block), that IS a finding — report it as Important, labeled
134
+ plan-mandated. The plan's authorship does not grade its own work; the
135
+ human decides.
136
+ Acknowledge what was done well before listing issues — accurate praise
137
+ helps the implementer trust the rest of the feedback.
138
+
139
+ ## Output Format
140
+
141
+ ### Spec Compliance
142
+
143
+ - ✅ Spec compliant | ❌ Issues found: [what's missing/extra/misunderstood,
144
+ with file:line references]
145
+ - ⚠️ Cannot verify from diff: [requirements you could not verify from the
146
+ diff alone, and what the controller should check — report alongside the
147
+ ✅/❌ verdict for everything you could verify]
148
+
149
+ ### Strengths
150
+ [What's well done? Be specific.]
151
+
152
+ ### Issues
153
+
154
+ #### Critical (Must Fix)
155
+ #### Important (Should Fix)
156
+ #### Minor (Nice to Have)
157
+
158
+ For each issue: file:line, what's wrong, why it matters, how to fix
159
+ (if not obvious).
160
+
161
+ ### Assessment
162
+
163
+ **Task quality:** [Approved | Needs fixes]
164
+
165
+ **Reasoning:** [1-2 sentence technical assessment]
166
+ ```
167
+
168
+ **Placeholders:**
169
+ - `[MODEL]` — REQUIRED: reviewer model per SKILL.md Model Selection
170
+ - `[BRIEF_FILE]` — REQUIRED: the task brief file (`scripts/task-brief PLAN N`
171
+ prints the path; same file the implementer worked from)
172
+ - `[GLOBAL_CONSTRAINTS]` — the binding requirements copied verbatim from
173
+ the plan's Global Constraints section or the spec: exact values, formats,
174
+ and stated relationships between components (not process rules — those
175
+ are already in this template)
176
+ - `[REPORT_FILE]` — REQUIRED: the file the implementer wrote its detailed
177
+ report to
178
+ - `[BASE_SHA]` — commit before this task
179
+ - `[HEAD_SHA]` — current commit
180
+ - `[DIFF_FILE]` — REQUIRED: the path the controller wrote the review
181
+ package to (`scripts/review-package BASE HEAD` prints the unique path it
182
+ wrote; the package never enters the controller's context)
183
+
184
+ **Reviewer returns:** Spec Compliance verdict (✅/❌/⚠️), Strengths, Issues
185
+ (Critical/Important/Minor), Task quality verdict
186
+
187
+ A fix dispatch can address spec gaps and quality findings together;
188
+ re-review after fixes covers both verdicts.
@@ -0,0 +1,75 @@
1
+ ---
2
+ name: using-superpowers
3
+ description: "Use when starting or routing a non-trivial task in this workflow harness, when the user references Superpowers, or when deciding which skill, command, rule, or agent should govern the work. Establishes skill invocation discipline: check relevant process skills before acting, follow user/project instructions first, and verify before completion."
4
+ ---
5
+
6
+ # Using Superpowers
7
+
8
+ This is the workflow router for the local Superpowers-inspired harness. It keeps action disciplined while respecting this repository's Chinese communication rules and Git boundaries.
9
+
10
+ ## Priority
11
+
12
+ Follow instructions in this order:
13
+
14
+ 1. User instructions, including direct requests, `AGENTS.md`, `CLAUDE.md`, and repo-local rules.
15
+ 2. Applicable skills, commands, agents, and hooks from this repository.
16
+ 3. Default agent behavior.
17
+
18
+ If a skill conflicts with explicit User instructions or project instructions, follow the user/project instruction and state the conflict if it affects the outcome.
19
+
20
+ ## Skill Invocation Rule
21
+
22
+ Before taking action on a non-trivial task:
23
+
24
+ 1. Decide whether a process skill applies.
25
+ 2. Load the applicable skill before exploration, implementation, clarification, or final claims.
26
+ 3. Announce briefly which skill is being used and why.
27
+ 4. Follow the skill's gate, checklist, and verification requirements.
28
+ 5. If the skill is not a fit after reading it, say so briefly and continue with the smallest suitable workflow.
29
+
30
+ Do not rely on memory of a skill. Skills evolve; use the current `SKILL.md` content.
31
+
32
+ ## Routing
33
+
34
+ Use process skills before implementation skills:
35
+
36
+ ```text
37
+ Task arrives
38
+ -> unclear / high-risk / multi-file? -> brainstorming
39
+ -> approved spec, no plan? -> writing-plans
40
+ -> approved plan + SDD/commit approved? -> subagent-driven-development
41
+ -> approved plan, no commit approval? -> executing-plans
42
+ -> bug / failing test / unexpected result -> systematic-debugging
43
+ -> behavior change with test path? -> test-driven-development
44
+ -> dirty worktree / risky branch work? -> using-git-worktrees
45
+ -> completion / fixed / ready claim? -> verification-before-completion
46
+ -> external skill learning or edit? -> skill-creator + skills-learning
47
+ ```
48
+
49
+ - Complex, ambiguous, architectural, integration, high-risk, cross-file, or behavior-changing work: use `skills/brainstorming/SKILL.md` first.
50
+ - Approved spec that needs an implementation plan: use `skills/writing-plans/SKILL.md`.
51
+ - Approved plan with independent tasks and approved commit/PR/SDD handling: use `skills/subagent-driven-development/SKILL.md`.
52
+ - Approved plan without commit handling or with tightly coupled tasks: use `skills/executing-plans/SKILL.md`.
53
+ - Bug, failing test, flaky behavior, or unexpected result: use `skills/systematic-debugging/SKILL.md` before proposing a fix.
54
+ - Behavior-changing implementation with a viable test path: use `skills/test-driven-development/SKILL.md`.
55
+ - Risky branch work, dirty worktree, parallel effort, or PR cleanup: consider `skills/using-git-worktrees/SKILL.md`.
56
+ - Completion, fixed, passing, ready, or PR-readiness claims: use `skills/verification-before-completion/SKILL.md`.
57
+ - External skill learning or skill edits: use `skills/skill-creator/SKILL.md` and `rules/common/skills-learning.md`.
58
+
59
+ Then apply domain skills such as documentation lookup, E2E testing, or workflow engineering as needed.
60
+
61
+ ## Red Flags
62
+
63
+ Stop and check skills before continuing if you think:
64
+
65
+ - "This is just a quick code change."
66
+ - "I need to inspect files before deciding."
67
+ - "I remember what this skill says."
68
+ - "The user asked for the outcome, so the workflow gate can be skipped."
69
+ - "The verification should pass."
70
+
71
+ These are usually signs that a process skill should shape the next step.
72
+
73
+ ## Completion
74
+
75
+ Before saying work is complete, fixed, passing, or ready, apply `skills/verification-before-completion/SKILL.md` and report fresh evidence, skipped checks, and remaining risk.
@@ -63,6 +63,13 @@ Do not include commit steps by default. Add `git add` or `git commit` steps only
63
63
 
64
64
  **Tech Stack:** [Key technologies/libraries]
65
65
 
66
+ ## Global Constraints
67
+
68
+ [The spec's project-wide requirements — version floors, dependency limits,
69
+ naming and copy rules, platform requirements, commit/PR boundaries, exact
70
+ values — one line each, copied verbatim from the spec or user instruction.
71
+ Every task's requirements implicitly include this section.]
72
+
66
73
  ---
67
74
  ```
68
75
 
@@ -76,6 +83,10 @@ Do not include commit steps by default. Add `git add` or `git commit` steps only
76
83
  - Modify: `exact/path/to/existing.py:123-145`
77
84
  - Test: `tests/exact/path/to/test.py`
78
85
 
86
+ **Interfaces:**
87
+ - Consumes: [what this task uses from earlier tasks — exact signatures, file paths, commands, or data contracts]
88
+ - Produces: [what later tasks rely on — exact function names, parameter and return types, CLI flags, file formats, or documented behavior. A task implementer may see only this task, so neighboring contracts must be explicit.]
89
+
79
90
  - [ ] **Step 1: Write the failing test**
80
91
 
81
92
  ```python
@@ -118,12 +129,15 @@ Every step must contain the actual content an engineer needs. These are **plan f
118
129
  - "Similar to Task N" (repeat the code — the engineer may be reading tasks out of order)
119
130
  - Steps that describe what to do without showing how (code blocks required for code steps)
120
131
  - References to types, functions, or methods not defined in any task
132
+ - Missing `Global Constraints` or per-task `Interfaces` blocks
121
133
 
122
134
  ## Remember
123
135
  - Exact file paths always
124
136
  - Complete code in every step — if a step changes code, show the code
125
137
  - Exact commands with expected output
126
138
  - DRY, YAGNI, TDD, verification checkpoints
139
+ - Copy binding cross-task constraints into `Global Constraints`; do not assume implementers or reviewers will remember the spec.
140
+ - Every task needs an `Interfaces` block, even if it says `Consumes: none` or `Produces: none`.
127
141
  - Do not default to commits; leave changes uncommitted unless the user explicitly asks for commit, push, PR, or an approved workflow includes commit handling.
128
142
 
129
143
  ## Self-Review
@@ -136,6 +150,8 @@ After writing the complete plan, look at the spec with fresh eyes and check the
136
150
 
137
151
  **3. Type consistency:** Do the types, method signatures, and property names you used in later tasks match what you defined in earlier tasks? A function called `clearLayers()` in Task 3 but `clearFullLayers()` in Task 7 is a bug.
138
152
 
153
+ **4. Contract propagation:** Did every task get the relevant `Global Constraints` and the exact `Interfaces` it consumes and produces? If a later task depends on a name, format, flag, or file from an earlier task, both tasks must say so consistently.
154
+
139
155
  If you find issues, fix them inline. No need to re-review — just fix and move on. If you find a spec requirement with no task, add the task.
140
156
 
141
157
  ## Execution Handoff
@@ -144,12 +160,19 @@ After saving the plan, offer execution choice:
144
160
 
145
161
  **"Plan complete and saved to `docs/superpowers/plans/<filename>.md`. If you want me to execute it, I will use `skills/executing-plans/SKILL.md`. Two execution options:**
146
162
 
147
- **1. Project-Agent Loop (recommended for substantial plans)** - Use this project's existing agents. Dispatch one fresh implementation subagent per task, then run two reviews before marking the task complete.
163
+ **1. Subagent-Driven Development (when commit handling is approved)** - Use `skills/subagent-driven-development/SKILL.md` for independent tasks, task briefs, implementer report files, review packages, and the `.superpowers/sdd` progress ledger.
164
+
165
+ **2. Project-Agent Loop (no commits by default)** - Use this project's existing agents. Dispatch one fresh implementation subagent per task, then run two reviews before marking the task complete.
148
166
 
149
- **2. Inline Execution (lightweight)** - Execute tasks in this session, task-by-task, with checkpoints. Use this for small, clear, tightly coupled work.
167
+ **3. Inline Execution (lightweight)** - Execute tasks in this session, task-by-task, with checkpoints. Use this for small, clear, tightly coupled work.
150
168
 
151
169
  **Which approach?"**
152
170
 
171
+ **If Subagent-Driven Development chosen:**
172
+ - Confirm the user has approved commit handling, PR handling, or SDD-style execution. If not, use Project-Agent Loop or Inline Execution instead.
173
+ - Use `skills/subagent-driven-development/SKILL.md`.
174
+ - The SDD progress ledger and scratch artifacts live under `.superpowers/sdd/` and must stay out of commits.
175
+
153
176
  **If Project-Agent Loop chosen:**
154
177
  - Read the full plan once and extract each task with its files, tests, commands, and acceptance criteria.
155
178
  - For each task, dispatch a fresh implementation subagent with only that task plus the necessary project context. Before dispatching, read the matching `agents/*.md` file and use its role, process, and constraints as the subagent prompt. In runtimes that do not expose custom agent names directly, dispatch a generic worker and seed it with the selected project-agent prompt.
@@ -1,73 +0,0 @@
1
- ---
2
- description: 验收实现是否满足需求、spec、plan 和验证证据
3
- ---
4
-
5
- # /acceptance - 需求验收
6
-
7
- `/acceptance` 是 Verify Gate 之后、`/pr` 之前的验收入口,依赖 `commands/verify.md` 定义的验证证据。它不替代测试,也不发明新的执行器;它把现有 spec、plan、diff、测试结果和 `/verify` 输出整理成可审查的验收结论。
8
-
9
- ## 使用方式
10
-
11
- ```text
12
- /acceptance
13
- /acceptance docs/superpowers/specs/2026-06-16-feature-design.md
14
- /acceptance --staged
15
- ```
16
-
17
- ## 输入来源
18
-
19
- 按可用性读取:
20
-
21
- 1. 用户指定的 spec、plan 或需求说明。
22
- 2. `docs/superpowers/specs/` 中与当前任务相关的 design spec。
23
- 3. `docs/superpowers/plans/` 中与当前任务相关的 implementation plan。
24
- 4. 当前 `git diff` 或 `--staged` diff。
25
- 5. 本轮已运行的测试、构建、lint、E2E、`/verify` 结果。
26
-
27
- 如果缺少 spec 或 plan,仍可基于用户原始需求和 diff 做轻量验收,但必须标记“验收依据不足”。
28
-
29
- ## 验收流程
30
-
31
- 1. 提取需求点、验收标准和非目标。
32
- 2. 对照 diff,判断每个需求是否有实现证据。
33
- 3. 对照测试和 `/verify`,判断每个验收标准是否有验证证据。
34
- 4. 检查是否有未运行项、失败项、范围外改动和剩余风险。
35
- 5. 输出明确结论:通过、部分通过、失败或依据不足。
36
-
37
- ## 输出格式
38
-
39
- ```text
40
- 验收结果: [通过/部分通过/失败/依据不足]
41
-
42
- 需求覆盖:
43
- - REQ-1: [通过/失败/未验证] — [实现证据路径或原因]
44
-
45
- 验收标准:
46
- - AC-1: [通过/失败/未验证] — [测试命令、人工检查或证据路径]
47
-
48
- 测试证据:
49
- - <command>: <passed/failed/not run> — <evidence>
50
-
51
- 未验收项:
52
- - [项目] — [原因]
53
-
54
- 范围外改动:
55
- - [文件/行为] — [是否需要回滚或说明]
56
-
57
- 剩余风险:
58
- - [风险 or 无已知剩余风险]
59
- ```
60
-
61
- ## 判定标准
62
-
63
- - **通过**:需求覆盖完整,验收标准均有证据,关键验证通过,无阻塞风险。
64
- - **部分通过**:核心路径通过,但存在非阻塞缺口、未运行检查或低风险未验收项。
65
- - **失败**:需求缺失、关键验收标准失败、关键验证失败或存在阻塞风险。
66
- - **依据不足**:没有足够的需求、spec、plan 或验证证据支撑验收结论。
67
-
68
- ## 约束
69
-
70
- - 不要把“测试通过”等同于“验收通过”;必须对照需求和验收标准。
71
- - 不要声称验收通过,除非有实现证据和验证证据。
72
- - 未运行检查必须写明原因。
73
- - 发现缺口时,回到实现、测试或 `/verify` 阶段,不直接进入 `/pr`。
@@ -1,59 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Evaluate Session Hook
4
- *
5
- * 会话结束时评估是否有可提取的模式
6
- * 用于 Stop hook
7
- */
8
-
9
- const path = require('path')
10
- const fs = require('fs')
11
- const os = require('os')
12
-
13
- function getLearnedSkillsDir() {
14
- return path.join(os.homedir(), '.claude', 'skills', 'learn')
15
- }
16
-
17
- function ensureDir(dir) {
18
- if (!fs.existsSync(dir)) {
19
- fs.mkdirSync(dir, { recursive: true })
20
- }
21
- }
22
-
23
- async function main() {
24
- // 默认配置
25
- const minSessionLength = 10
26
- const learnedSkillsPath = getLearnedSkillsDir()
27
-
28
- // 确保学习技能根目录存在;具体技能保存到分类子目录
29
- ensureDir(learnedSkillsPath)
30
-
31
- // 获取会话记录路径
32
- const transcriptPath = process.env.CLAUDE_TRANSCRIPT_PATH
33
-
34
- if (!transcriptPath || !fs.existsSync(transcriptPath)) {
35
- process.exit(0)
36
- }
37
-
38
- // 计算用户消息数量
39
- const content = fs.readFileSync(transcriptPath, 'utf8')
40
- const messageCount = (content.match(/"type":"user"/g) || []).length
41
-
42
- // 跳过短会话
43
- if (messageCount < minSessionLength) {
44
- console.error(`[ContinuousLearning] 会话过短 (${messageCount} 消息),跳过`)
45
- process.exit(0)
46
- }
47
-
48
- // 提示开始评估
49
- console.error(`[ContinuousLearning] 会话有 ${messageCount} 消息 - 评估可提取模式`)
50
- console.error(`[ContinuousLearning] 保存技能到分类目录: ${path.join(learnedSkillsPath, '<category>')}`)
51
- console.error('[ContinuousLearning] 提示: 使用 /learn 手动提取有价值的模式')
52
-
53
- process.exit(0)
54
- }
55
-
56
- main().catch(err => {
57
- console.error('[ContinuousLearning] 错误:', err.message)
58
- process.exit(0)
59
- })
@@ -1,92 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * PreCompact Hook
4
- *
5
- * 在上下文压缩前保存关键信息
6
- * 用于 PreCompact hook
7
- */
8
-
9
- const fs = require('fs')
10
- const path = require('path')
11
- const os = require('os')
12
- const crypto = require('crypto')
13
- const { execFileSync } = require('child_process')
14
-
15
- function getCompactLogPath() {
16
- const claudeDir = path.join(os.homedir(), '.claude')
17
- return path.join(claudeDir, 'compact-history.jsonl')
18
- }
19
-
20
- function ensureDir(filePath) {
21
- const dir = path.dirname(filePath)
22
- if (!fs.existsSync(dir)) {
23
- fs.mkdirSync(dir, { recursive: true })
24
- }
25
- }
26
-
27
- function getProjectContext(input) {
28
- const cwd = input.cwd || process.cwd()
29
- let projectRoot = cwd
30
-
31
- try {
32
- projectRoot = execFileSync('git', ['rev-parse', '--show-toplevel'], {
33
- cwd,
34
- encoding: 'utf8',
35
- timeout: 1000,
36
- windowsHide: true,
37
- stdio: ['ignore', 'pipe', 'ignore']
38
- }).trim()
39
- } catch {
40
- projectRoot = path.resolve(cwd)
41
- }
42
-
43
- const projectId = crypto
44
- .createHash('sha1')
45
- .update(projectRoot.toLowerCase())
46
- .digest('hex')
47
- .slice(0, 12)
48
-
49
- return {
50
- cwd,
51
- project_root: projectRoot,
52
- project_name: path.basename(projectRoot),
53
- project_id: projectId
54
- }
55
- }
56
-
57
- async function main() {
58
- let data = ''
59
-
60
- process.stdin.on('data', chunk => {
61
- data += chunk
62
- })
63
-
64
- process.stdin.on('end', () => {
65
- try {
66
- const input = JSON.parse(data)
67
-
68
- // 记录压缩事件
69
- const compactLog = {
70
- timestamp: new Date().toISOString(),
71
- session_id: input.session_id,
72
- ...getProjectContext(input),
73
- context_size: input.context_size || 'unknown',
74
- message_count: input.message_count || 'unknown'
75
- }
76
-
77
- const logPath = getCompactLogPath()
78
- ensureDir(logPath)
79
-
80
- fs.appendFileSync(logPath, JSON.stringify(compactLog) + '\n')
81
-
82
- // 提示用户
83
- console.error('[PreCompact] 上下文即将压缩,关键信息已保存')
84
- console.error(`[PreCompact] 当前消息数: ${compactLog.message_count}`)
85
-
86
- } catch (error) {
87
- console.error(`[PreCompact] 保存失败: ${error.message}`)
88
- }
89
- })
90
- }
91
-
92
- main()
@@ -1,45 +0,0 @@
1
- /**
2
- * Session Hook 共享工具
3
- */
4
-
5
- 'use strict'
6
-
7
- const fs = require('fs')
8
- const os = require('os')
9
- const path = require('path')
10
-
11
- function getHomeDir() {
12
- const explicit = process.env.HOME || process.env.USERPROFILE
13
- if (explicit && explicit.trim().length > 0) {
14
- return path.resolve(explicit)
15
- }
16
- return os.homedir()
17
- }
18
-
19
- function getClaudeDir() {
20
- return path.join(getHomeDir(), '.claude')
21
- }
22
-
23
- function ensureDir(dirPath) {
24
- if (!fs.existsSync(dirPath)) {
25
- fs.mkdirSync(dirPath, { recursive: true })
26
- }
27
- return dirPath
28
- }
29
-
30
- function getDateTimeString() {
31
- const now = new Date()
32
- const y = now.getFullYear()
33
- const m = String(now.getMonth() + 1).padStart(2, '0')
34
- const d = String(now.getDate()).padStart(2, '0')
35
- const h = String(now.getHours()).padStart(2, '0')
36
- const min = String(now.getMinutes()).padStart(2, '0')
37
- const s = String(now.getSeconds()).padStart(2, '0')
38
- return `${y}-${m}-${d} ${h}:${min}:${s}`
39
- }
40
-
41
- module.exports = {
42
- ensureDir,
43
- getClaudeDir,
44
- getDateTimeString
45
- }
@@ -1,62 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Session End Hook
4
- *
5
- * 会话结束时持久化状态
6
- * 用于 SessionEnd hook 或手动调用
7
- */
8
-
9
- 'use strict'
10
-
11
- const fs = require('fs')
12
- const path = require('path')
13
-
14
- function getSessionDir() {
15
- const utils = require('./runtime/session-utils')
16
- return utils.ensureDir(
17
- path.join(utils.getClaudeDir(), 'session-data')
18
- )
19
- }
20
-
21
- function getProjectName() {
22
- try {
23
- const { execSync } = require('child_process')
24
- const toplevel = execSync('git rev-parse --show-toplevel', {
25
- encoding: 'utf8',
26
- timeout: 5000
27
- }).trim()
28
- return path.basename(toplevel)
29
- } catch {
30
- return path.basename(process.cwd()) || 'unknown'
31
- }
32
- }
33
-
34
- function run() {
35
- const sessionDir = getSessionDir()
36
- const stateFile = path.join(sessionDir, 'last-state.json')
37
-
38
- const utils = require('./runtime/session-utils')
39
- const state = {
40
- project: getProjectName(),
41
- lastActive: utils.getDateTimeString(),
42
- cwd: process.cwd(),
43
- sessionId: process.env.CLAUDE_SESSION_ID || null
44
- }
45
-
46
- try {
47
- fs.writeFileSync(stateFile, JSON.stringify(state, null, 2), 'utf8')
48
- process.stderr.write(
49
- `[Session] 状态已保存: ${stateFile}\n`
50
- )
51
- } catch (err) {
52
- process.stderr.write(
53
- `[Session] 保存状态失败: ${err.message}\n`
54
- )
55
- }
56
- }
57
-
58
- module.exports = { run }
59
-
60
- if (require.main === module) {
61
- run()
62
- }