continuous-improvement 3.1.0 → 3.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/.claude-plugin/marketplace.json +78 -0
- package/CHANGELOG.md +191 -0
- package/LICENSE +21 -21
- package/QUICKSTART.md +101 -81
- package/README.md +207 -359
- package/SKILL.md +87 -9
- package/action.yml +33 -33
- package/bin/analyze.sh +161 -153
- package/bin/backfill.mjs +172 -0
- package/bin/check-docs-substrings.mjs +333 -0
- package/bin/check-everything-mirror.mjs +145 -0
- package/bin/check-routing-targets.mjs +151 -0
- package/bin/check-skill-law-tag.mjs +128 -0
- package/bin/check-skill-mirror.mjs +119 -0
- package/bin/check-skill-tiers.mjs +116 -0
- package/bin/check-third-party-shape.mjs +202 -0
- package/bin/generate-plugin-manifests.mjs +169 -0
- package/bin/harvest-friction.mjs +279 -0
- package/bin/hook-stats.mjs +258 -0
- package/bin/install.mjs +417 -516
- package/bin/lint-transcript.mjs +182 -210
- package/bin/mcp-server.mjs +840 -617
- package/bin/observe.mjs +148 -0
- package/bin/pre-commit-block-strays.sh +49 -0
- package/bin/refresh-third-party.mjs +416 -0
- package/bin/unified-cli.mjs +533 -0
- package/commands/continuous-improvement.md +115 -74
- package/commands/dashboard.md +56 -56
- package/commands/discipline.md +51 -37
- package/commands/harvest.md +76 -0
- package/commands/learn-eval.md +117 -0
- package/commands/planning-with-files.md +66 -0
- package/commands/proceed-with-the-recommendation.md +62 -0
- package/commands/ralph.md +103 -0
- package/commands/release-train.md +81 -0
- package/commands/seven-laws.md +16 -0
- package/commands/superpowers.md +153 -0
- package/commands/swarm.md +101 -0
- package/commands/workspace-surface-audit.md +77 -0
- package/hooks/observe.sh +172 -134
- package/hooks/session.sh +106 -106
- package/hooks/three-section-close.mjs +181 -0
- package/instinct-packs/go.json +58 -58
- package/instinct-packs/meta.json +16 -0
- package/instinct-packs/python.json +58 -58
- package/instinct-packs/react.json +58 -58
- package/lib/cli-anything.mjs +401 -0
- package/lib/compound-engineering.mjs +831 -0
- package/lib/observe-event.mjs +128 -0
- package/lib/plugin-metadata.mjs +432 -0
- package/lib/pm-marketplace.mjs +61 -0
- package/lib/pm-skills.mjs +1274 -0
- package/lib/resolve-home-dir.mjs +43 -0
- package/lib/skill-tiers.mjs +137 -0
- package/lib/unified-plugin.mjs +924 -0
- package/llms.txt +68 -43
- package/package.json +28 -19
- package/plugins/beginner.json +17 -6
- package/plugins/continuous-improvement/.claude-plugin/marketplace.json +20 -0
- package/plugins/continuous-improvement/.claude-plugin/plugin.json +26 -0
- package/plugins/continuous-improvement/LICENSE +21 -0
- package/plugins/continuous-improvement/README.md +56 -0
- package/plugins/continuous-improvement/bin/backfill.mjs +172 -0
- package/plugins/continuous-improvement/bin/mcp-server.mjs +886 -0
- package/plugins/continuous-improvement/bin/observe.mjs +148 -0
- package/plugins/continuous-improvement/commands/continuous-improvement.md +115 -0
- package/plugins/continuous-improvement/commands/dashboard.md +56 -0
- package/plugins/continuous-improvement/commands/discipline.md +51 -0
- package/plugins/continuous-improvement/commands/harvest.md +76 -0
- package/plugins/continuous-improvement/commands/learn-eval.md +117 -0
- package/plugins/continuous-improvement/commands/planning-with-files.md +66 -0
- package/plugins/continuous-improvement/commands/proceed-with-the-recommendation.md +62 -0
- package/plugins/continuous-improvement/commands/ralph.md +103 -0
- package/plugins/continuous-improvement/commands/release-train.md +81 -0
- package/plugins/continuous-improvement/commands/seven-laws.md +16 -0
- package/plugins/continuous-improvement/commands/superpowers.md +153 -0
- package/plugins/continuous-improvement/commands/swarm.md +101 -0
- package/plugins/continuous-improvement/commands/workspace-surface-audit.md +77 -0
- package/plugins/continuous-improvement/hooks/hooks.json +60 -0
- package/plugins/continuous-improvement/hooks/observe.sh +172 -0
- package/plugins/continuous-improvement/hooks/session.sh +106 -0
- package/plugins/continuous-improvement/hooks/three-section-close.mjs +181 -0
- package/plugins/continuous-improvement/instinct-packs/go.json +58 -0
- package/plugins/continuous-improvement/instinct-packs/meta.json +16 -0
- package/plugins/continuous-improvement/instinct-packs/python.json +58 -0
- package/plugins/continuous-improvement/instinct-packs/react.json +58 -0
- package/plugins/continuous-improvement/lib/observe-event.mjs +128 -0
- package/plugins/continuous-improvement/lib/plugin-metadata.mjs +432 -0
- package/plugins/continuous-improvement/lib/resolve-home-dir.mjs +43 -0
- package/plugins/continuous-improvement/skills/README.md +34 -0
- package/plugins/continuous-improvement/skills/continuous-improvement/SKILL.md +249 -0
- package/plugins/continuous-improvement/skills/deploy-receipt/SKILL.md +131 -0
- package/plugins/continuous-improvement/skills/gateguard/SKILL.md +155 -0
- package/plugins/continuous-improvement/skills/para-memory-files/SKILL.md +108 -0
- package/plugins/continuous-improvement/skills/proceed-with-the-recommendation/SKILL.md +454 -0
- package/plugins/continuous-improvement/skills/ralph/SKILL.md +221 -0
- package/plugins/continuous-improvement/skills/safety-guard/SKILL.md +76 -0
- package/plugins/continuous-improvement/skills/strategic-compact/SKILL.md +104 -0
- package/plugins/continuous-improvement/skills/superpowers/SKILL.md +212 -0
- package/plugins/continuous-improvement/skills/tdd-workflow/SKILL.md +411 -0
- package/plugins/continuous-improvement/skills/token-budget-advisor/SKILL.md +136 -0
- package/plugins/continuous-improvement/skills/verification-loop/SKILL.md +192 -0
- package/plugins/continuous-improvement/skills/wild-risa-balance/SKILL.md +191 -0
- package/plugins/continuous-improvement/skills/workspace-surface-audit/SKILL.md +147 -0
- package/plugins/continuous-improvement/templates/planning-with-files/findings.md +8 -0
- package/plugins/continuous-improvement/templates/planning-with-files/progress.md +7 -0
- package/plugins/continuous-improvement/templates/planning-with-files/task_plan.md +23 -0
- package/plugins/expert.json +26 -5
- package/skills/README.md +79 -0
- package/skills/deploy-receipt.md +131 -0
- package/skills/gateguard.md +155 -0
- package/skills/para-memory-files.md +108 -0
- package/skills/proceed-with-the-recommendation.md +454 -0
- package/skills/ralph.md +221 -0
- package/skills/safety-guard.md +76 -0
- package/skills/strategic-compact.md +104 -0
- package/skills/superpowers.md +212 -0
- package/skills/tdd-workflow.md +411 -0
- package/skills/token-budget-advisor.md +136 -0
- package/skills/verification-loop.md +192 -0
- package/skills/wild-risa-balance.md +191 -0
- package/skills/workspace-surface-audit.md +147 -0
- package/templates/planning-with-files/findings.md +8 -0
- package/templates/planning-with-files/progress.md +7 -0
- package/templates/planning-with-files/task_plan.md +23 -0
- package/templates/verify-ladder.example.json +47 -0
package/SKILL.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: continuous-improvement
|
|
3
|
-
|
|
3
|
+
tier: core
|
|
4
|
+
description: "Install structured self-improvement loops with instinct-based learning into Claude Code — research, plan, execute, verify, reflect, learn, iterate. On-demand or weekly analysis to save tokens. Supports multi-agent parallel analysis."
|
|
4
5
|
---
|
|
5
6
|
|
|
6
7
|
# continuous-improvement
|
|
@@ -28,9 +29,9 @@ Before executing, state:
|
|
|
28
29
|
## Law 3: One Thing at a Time
|
|
29
30
|
|
|
30
31
|
- Complete and verify one task before starting the next
|
|
31
|
-
- Never spawn parallel work for tasks you can do directly
|
|
32
32
|
- Never report completion until you've checked actual output
|
|
33
33
|
- If you want to "also quickly add" something — stop. Finish first.
|
|
34
|
+
- **Multi-agent OK:** Delegate independent, parallelizable work to sub-agents (e.g., security review + code review + tests in parallel). Each agent follows the 7 Laws independently. Only parallelize when tasks have no shared state.
|
|
34
35
|
|
|
35
36
|
## Law 4: Verify Before Reporting
|
|
36
37
|
|
|
@@ -50,10 +51,35 @@ After non-trivial tasks:
|
|
|
50
51
|
- What failed:
|
|
51
52
|
- What I'd do differently:
|
|
52
53
|
- Rule to add:
|
|
54
|
+
- Iteration — Next best recommendations (ranked, top 3):
|
|
55
|
+
1. <primary — strongest next move>
|
|
56
|
+
2. <alternative — different angle, if user wants to pivot>
|
|
57
|
+
3. <alternative — smaller/larger scope, if user wants to adjust>
|
|
53
58
|
```
|
|
54
59
|
|
|
55
60
|
The "Rule to add" field feeds Law 7 — it becomes an instinct with 0.6 starting confidence.
|
|
56
61
|
|
|
62
|
+
The "Iteration — Next best recommendations" field feeds Law 6. List the **top 3 ranked** core-development moves based on the current code state — what to build, fix, refactor, or investigate next so the feature/system advances. Item #1 is the strongest recommendation; #2 and #3 are alternative directions the user can pick from. NOT git plumbing (commit, push, PR), NOT pure CI ceremony (run tests, type-check), NOT deploy steps. Those belong in the end-of-run summary, not here.
|
|
63
|
+
|
|
64
|
+
Format per item: `<verb> <object at path:line> (<why, one clause grounded in current context>)`.
|
|
65
|
+
|
|
66
|
+
Good examples (development progression):
|
|
67
|
+
- `Implement settleWeekAndPostPrizes writer for quiz source in src/scheduled.ts (real_contest writer exists; quiz path is recognized but inert)`
|
|
68
|
+
- `Refactor contestModeGuard at src/routes/trading-contest.ts to share the 4-mode switch with /admin/mode (logic duplicated, drift risk)`
|
|
69
|
+
- `Investigate why Saturday cron occasionally skips Week activation in src/scheduled.ts:625 (one missed run on 2026-04-19; root cause unknown)`
|
|
70
|
+
- `Add server-side enforcement for the $100 new-deposit rule in real-contest entry handler (currently advisory; admin reviews post-contest)`
|
|
71
|
+
|
|
72
|
+
Anti-examples (rejected — these are workflow, not development):
|
|
73
|
+
- `Commit changes` / `Open PR` / `Push to origin` → belongs in summary, not here
|
|
74
|
+
- `Run vitest` / `Run tsc` → that is verification (Law 4), already done before reporting
|
|
75
|
+
- `Deploy to prod` → operational, needs-approval, never an autonomous next step
|
|
76
|
+
|
|
77
|
+
Rules:
|
|
78
|
+
- Always exactly 3 items, ranked. Not 2, not 5.
|
|
79
|
+
- All 3 must be distinct directions — do not pad with rephrases of #1.
|
|
80
|
+
- If fewer than 3 real moves exist, fill remaining slots with `None — goal met from this angle.` rather than inventing busywork.
|
|
81
|
+
- If the goal is fully met across all angles, write `1. None — goal met, stop.` and omit #2 and #3.
|
|
82
|
+
|
|
57
83
|
## Law 6: Iterate Means One Thing
|
|
58
84
|
|
|
59
85
|
One change → verify → next change.
|
|
@@ -74,6 +100,19 @@ If the user corrects you, the instinct weakens. If they don't, it strengthens.
|
|
|
74
100
|
|
|
75
101
|
Nothing learned is permanent. Everything decays without reinforcement.
|
|
76
102
|
|
|
103
|
+
### Friction Harvest Pipeline (`/harvest`)
|
|
104
|
+
|
|
105
|
+
Beyond the reflection-driven path above, the **friction harvest classifier** turns observation logs (`~/.claude/instincts/<project-hash>/observations.jsonl`) into typed instincts automatically. Run via `/harvest` or `node bin/harvest-friction.mjs`. Four typed friction patterns with confidence scoring:
|
|
106
|
+
|
|
107
|
+
- **`env_issue`** — jq missing, command not found, not recognized as cmdlet
|
|
108
|
+
- **`permission_block`** — sandbox / harness blocked, Permission denied
|
|
109
|
+
- **`wrong_approach`** — file changed since last read (parallel-actor stale)
|
|
110
|
+
- **`buggy_code`** — file not read first, old_string ambiguous, file too large
|
|
111
|
+
|
|
112
|
+
Idempotent: each instinct's `dedup_key = sha1(type + tool + summary[:120])`; re-running on the same observations does not duplicate previously-written instincts. Confidence weights frequency × recency-decay so old failures fade and recurring ones strengthen, in line with the Law 7 contract above.
|
|
113
|
+
|
|
114
|
+
The harvest is opt-in: it runs only when explicitly invoked. Cron / hook triggers are deliberately not wired so the operator stays in control of when the classifier reads observation history.
|
|
115
|
+
|
|
77
116
|
## The Loop
|
|
78
117
|
|
|
79
118
|
```
|
|
@@ -86,11 +125,23 @@ If you're skipping a step, that's the step you need most.
|
|
|
86
125
|
|
|
87
126
|
## Instinct System (Mulahazah)
|
|
88
127
|
|
|
89
|
-
|
|
128
|
+
### Execution Mode: On-Demand (Default)
|
|
129
|
+
|
|
130
|
+
The instinct system does **NOT** run automatically at session start. This saves tokens.
|
|
131
|
+
|
|
132
|
+
| Mode | When it runs | Token cost |
|
|
133
|
+
|------|-------------|------------|
|
|
134
|
+
| **On-demand** (default) | Only when user runs `/continuous-improvement` or `/dashboard` | Zero overhead per session |
|
|
135
|
+
| **Weekly** | User schedules via `/loop 7d /continuous-improvement analyze` or cron | One analysis per week |
|
|
136
|
+
| **Always-on** (opt-in) | Set `always_on: true` in project instinct config | Runs at every session start |
|
|
137
|
+
|
|
138
|
+
**To enable always-on:** Create `~/.claude/instincts/<hash>/config.yaml` with `always_on: true`. Otherwise, instincts are only loaded when explicitly requested.
|
|
139
|
+
|
|
140
|
+
**Hooks still capture silently** — observations accumulate in `observations.jsonl` with near-zero cost. The expensive part (reading, analyzing, creating instincts) only happens when you ask for it.
|
|
90
141
|
|
|
91
142
|
### Auto-Level Detection
|
|
92
143
|
|
|
93
|
-
|
|
144
|
+
When analysis is triggered (on-demand, weekly, or always-on), determine level:
|
|
94
145
|
|
|
95
146
|
1. **Find project hash:** Run `git rev-parse --show-toplevel 2>/dev/null`, then SHA-256 first 12 chars of the path
|
|
96
147
|
2. **Check observations:** Count lines in `~/.claude/instincts/<hash>/observations.jsonl`
|
|
@@ -105,9 +156,9 @@ Determine current level automatically:
|
|
|
105
156
|
|
|
106
157
|
Multiple levels can be active simultaneously — you might auto-apply some instincts while suggesting others.
|
|
107
158
|
|
|
108
|
-
###
|
|
159
|
+
### Analysis (On-Demand)
|
|
109
160
|
|
|
110
|
-
When
|
|
161
|
+
When triggered by `/continuous-improvement analyze`, weekly schedule, or always-on mode:
|
|
111
162
|
|
|
112
163
|
1. Read `observations.jsonl` (last 500 lines)
|
|
113
164
|
2. Read existing instincts (project + global `*.yaml` files)
|
|
@@ -119,6 +170,16 @@ When 20+ unprocessed observations exist, analyze them as part of session startup
|
|
|
119
170
|
4. Create/update instinct YAML files in the project directory
|
|
120
171
|
5. Be conservative: only create instincts for 3+ observations of the same pattern
|
|
121
172
|
|
|
173
|
+
### Multi-Agent Analysis
|
|
174
|
+
|
|
175
|
+
For large observation backlogs (500+ lines), parallelize analysis across agents:
|
|
176
|
+
|
|
177
|
+
- **Agent 1:** Analyze user corrections and error→fix sequences
|
|
178
|
+
- **Agent 2:** Analyze repeated workflows and tool preferences
|
|
179
|
+
- **Agent 3:** Cross-reference with existing instincts for updates/promotions
|
|
180
|
+
|
|
181
|
+
Each agent writes to separate temp files; the orchestrator merges results and deduplicates.
|
|
182
|
+
|
|
122
183
|
### Instinct Format
|
|
123
184
|
|
|
124
185
|
Each instinct is a YAML file in `~/.claude/instincts/<hash>/` or `~/.claude/instincts/global/`:
|
|
@@ -160,12 +221,29 @@ Cap: 0.9 max. Scope: default to project; promote to global when seen in 2+ proje
|
|
|
160
221
|
|
|
161
222
|
## /continuous-improvement Command
|
|
162
223
|
|
|
163
|
-
Run `/continuous-improvement`
|
|
224
|
+
Run `/continuous-improvement` when you want to reflect and learn — not every session.
|
|
164
225
|
|
|
165
226
|
1. **Reflect** — Generate Law 5 reflection
|
|
166
227
|
2. **Analyze** — Process pending observations into instincts
|
|
167
228
|
3. **Status** — Show all instincts with confidence and current level
|
|
168
229
|
|
|
169
230
|
Subcommands:
|
|
170
|
-
- `/continuous-improvement status` — Instinct overview only
|
|
171
|
-
- `/continuous-improvement analyze` —
|
|
231
|
+
- `/continuous-improvement status` — Instinct overview only (lightweight, reads YAML only)
|
|
232
|
+
- `/continuous-improvement analyze` — Process pending observations into instincts
|
|
233
|
+
- `/continuous-improvement weekly` — Set up weekly analysis schedule
|
|
234
|
+
- `/continuous-improvement always-on` — Enable/disable always-on mode for this project
|
|
235
|
+
|
|
236
|
+
## Planning-With-Files (Opt-In)
|
|
237
|
+
|
|
238
|
+
Use this workflow only when the user explicitly asks for persistent, file-based planning or asks to use Planning-With-Files.
|
|
239
|
+
|
|
240
|
+
- Detect the project root with `git rev-parse --show-toplevel`; if that fails, use the current working directory.
|
|
241
|
+
- Create and maintain three project-root files:
|
|
242
|
+
- `task_plan.md` — phases, status, questions, decisions, errors
|
|
243
|
+
- `findings.md` — research notes, sources, synthesized discoveries
|
|
244
|
+
- `progress.md` — session log, verification notes, checkpoints
|
|
245
|
+
- Default phases in `task_plan.md`: `Research`, `Plan`, `Execute`, `Verify`, `Reflect`
|
|
246
|
+
- Never create these files automatically for normal work. This workflow is opt-in.
|
|
247
|
+
- Never overwrite existing planning files unless the user explicitly asks to reset or replace them.
|
|
248
|
+
|
|
249
|
+
When resuming work, read the three files before making major decisions so context survives long tasks and new sessions.
|
package/action.yml
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
name: 'AI Agent Discipline Linter'
|
|
2
|
-
description: '
|
|
3
|
-
author: 'naimkatiman'
|
|
4
|
-
|
|
5
|
-
branding:
|
|
6
|
-
icon: 'check-circle'
|
|
7
|
-
color: 'green'
|
|
8
|
-
|
|
9
|
-
inputs:
|
|
10
|
-
transcript-path:
|
|
11
|
-
description: 'Path to the agent transcript file (JSONL format)'
|
|
12
|
-
required: false
|
|
13
|
-
default: ''
|
|
14
|
-
observations-path:
|
|
15
|
-
description: 'Path to observations.jsonl from a CI session'
|
|
16
|
-
required: false
|
|
17
|
-
default: ''
|
|
18
|
-
strict:
|
|
19
|
-
description: 'Fail the check if any law violations are detected'
|
|
20
|
-
required: false
|
|
21
|
-
default: 'false'
|
|
22
|
-
|
|
23
|
-
outputs:
|
|
24
|
-
violations:
|
|
25
|
-
description: 'Number of law violations found'
|
|
26
|
-
score:
|
|
27
|
-
description: 'Discipline score (0-100)'
|
|
28
|
-
report:
|
|
29
|
-
description: 'Markdown-formatted report'
|
|
30
|
-
|
|
31
|
-
runs:
|
|
32
|
-
using: 'node20'
|
|
33
|
-
main: 'bin/lint-transcript.mjs'
|
|
1
|
+
name: 'AI Agent Discipline Linter'
|
|
2
|
+
description: 'Catch agents that skipped research, planning, or verification — by linting their transcript in CI against the 7 Laws of AI Agent Discipline.'
|
|
3
|
+
author: 'naimkatiman'
|
|
4
|
+
|
|
5
|
+
branding:
|
|
6
|
+
icon: 'check-circle'
|
|
7
|
+
color: 'green'
|
|
8
|
+
|
|
9
|
+
inputs:
|
|
10
|
+
transcript-path:
|
|
11
|
+
description: 'Path to the agent transcript file (JSONL format)'
|
|
12
|
+
required: false
|
|
13
|
+
default: ''
|
|
14
|
+
observations-path:
|
|
15
|
+
description: 'Path to observations.jsonl from a CI session'
|
|
16
|
+
required: false
|
|
17
|
+
default: ''
|
|
18
|
+
strict:
|
|
19
|
+
description: 'Fail the check if any law violations are detected'
|
|
20
|
+
required: false
|
|
21
|
+
default: 'false'
|
|
22
|
+
|
|
23
|
+
outputs:
|
|
24
|
+
violations:
|
|
25
|
+
description: 'Number of law violations found'
|
|
26
|
+
score:
|
|
27
|
+
description: 'Discipline score (0-100)'
|
|
28
|
+
report:
|
|
29
|
+
description: 'Markdown-formatted report'
|
|
30
|
+
|
|
31
|
+
runs:
|
|
32
|
+
using: 'node20'
|
|
33
|
+
main: 'bin/lint-transcript.mjs'
|
package/bin/analyze.sh
CHANGED
|
@@ -1,153 +1,161 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# analyze.sh — Read observations.jsonl, detect patterns, create instinct YAML files
|
|
3
|
-
# Runs via /continuous-improvement command. Uses claude CLI with Haiku for cost-efficient analysis.
|
|
4
|
-
|
|
5
|
-
set -euo pipefail
|
|
6
|
-
|
|
7
|
-
INSTINCTS_DIR="${HOME}/.claude/instincts"
|
|
8
|
-
|
|
9
|
-
# ---------------------------------------------------------------------------
|
|
10
|
-
# Detect project
|
|
11
|
-
# ---------------------------------------------------------------------------
|
|
12
|
-
PROJECT_ROOT=""
|
|
13
|
-
if [[ -n "${CLAUDE_PROJECT_DIR:-}" && -d "${CLAUDE_PROJECT_DIR}" ]]; then
|
|
14
|
-
PROJECT_ROOT="${CLAUDE_PROJECT_DIR}"
|
|
15
|
-
fi
|
|
16
|
-
if [[ -z "$PROJECT_ROOT" ]]; then
|
|
17
|
-
PROJECT_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || true)"
|
|
18
|
-
fi
|
|
19
|
-
if [[ -z "$PROJECT_ROOT" ]]; then
|
|
20
|
-
PROJECT_ROOT="global"
|
|
21
|
-
fi
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
#
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
echo "
|
|
42
|
-
exit 0
|
|
43
|
-
fi
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
for
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
# ---------------------------------------------------------------------------
|
|
54
|
-
#
|
|
55
|
-
# ---------------------------------------------------------------------------
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
$
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# analyze.sh — Read observations.jsonl, detect patterns, create instinct YAML files
|
|
3
|
+
# Runs via /continuous-improvement command. Uses claude CLI with Haiku for cost-efficient analysis.
|
|
4
|
+
|
|
5
|
+
set -euo pipefail
|
|
6
|
+
|
|
7
|
+
INSTINCTS_DIR="${HOME}/.claude/instincts"
|
|
8
|
+
|
|
9
|
+
# ---------------------------------------------------------------------------
|
|
10
|
+
# Detect project
|
|
11
|
+
# ---------------------------------------------------------------------------
|
|
12
|
+
PROJECT_ROOT=""
|
|
13
|
+
if [[ -n "${CLAUDE_PROJECT_DIR:-}" && -d "${CLAUDE_PROJECT_DIR}" ]]; then
|
|
14
|
+
PROJECT_ROOT="${CLAUDE_PROJECT_DIR}"
|
|
15
|
+
fi
|
|
16
|
+
if [[ -z "$PROJECT_ROOT" ]]; then
|
|
17
|
+
PROJECT_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || true)"
|
|
18
|
+
fi
|
|
19
|
+
if [[ -z "$PROJECT_ROOT" ]]; then
|
|
20
|
+
PROJECT_ROOT="global"
|
|
21
|
+
fi
|
|
22
|
+
|
|
23
|
+
# Use shasum on macOS, sha256sum on Linux
|
|
24
|
+
if command -v sha256sum &>/dev/null; then
|
|
25
|
+
PROJECT_HASH="$(printf '%s' "$PROJECT_ROOT" | sha256sum | cut -c1-12)"
|
|
26
|
+
elif command -v shasum &>/dev/null; then
|
|
27
|
+
PROJECT_HASH="$(printf '%s' "$PROJECT_ROOT" | shasum -a 256 | cut -c1-12)"
|
|
28
|
+
else
|
|
29
|
+
# Fallback: use project root basename if no hashing available
|
|
30
|
+
PROJECT_HASH="$(basename "$PROJECT_ROOT" | tr -cd 'a-zA-Z0-9' | cut -c1-12)"
|
|
31
|
+
fi
|
|
32
|
+
PROJECT_NAME="$(basename "${PROJECT_ROOT%.git}")"
|
|
33
|
+
PROJECT_DIR="${INSTINCTS_DIR}/${PROJECT_HASH}"
|
|
34
|
+
OBS_FILE="${PROJECT_DIR}/observations.jsonl"
|
|
35
|
+
|
|
36
|
+
# ---------------------------------------------------------------------------
|
|
37
|
+
# Check observations exist
|
|
38
|
+
# ---------------------------------------------------------------------------
|
|
39
|
+
if [[ ! -f "$OBS_FILE" ]] || [[ ! -s "$OBS_FILE" ]]; then
|
|
40
|
+
echo "No observations found at ${OBS_FILE}"
|
|
41
|
+
echo "Use Claude Code with hooks installed to generate observations."
|
|
42
|
+
exit 0
|
|
43
|
+
fi
|
|
44
|
+
|
|
45
|
+
OBS_COUNT=$(wc -l < "$OBS_FILE")
|
|
46
|
+
echo "Found ${OBS_COUNT} observations in ${OBS_FILE}"
|
|
47
|
+
|
|
48
|
+
if (( OBS_COUNT < 20 )); then
|
|
49
|
+
echo "Need at least 20 observations for meaningful analysis. Keep using Claude Code (${OBS_COUNT}/20)."
|
|
50
|
+
exit 0
|
|
51
|
+
fi
|
|
52
|
+
|
|
53
|
+
# ---------------------------------------------------------------------------
|
|
54
|
+
# Read existing instincts to avoid duplicates
|
|
55
|
+
# ---------------------------------------------------------------------------
|
|
56
|
+
EXISTING_INSTINCTS=""
|
|
57
|
+
for f in "${PROJECT_DIR}"/*.yaml "${INSTINCTS_DIR}/global"/*.yaml; do
|
|
58
|
+
[[ -f "$f" ]] && EXISTING_INSTINCTS="${EXISTING_INSTINCTS}$(cat "$f")"$'\n'
|
|
59
|
+
done
|
|
60
|
+
|
|
61
|
+
# ---------------------------------------------------------------------------
|
|
62
|
+
# Take last 500 observations
|
|
63
|
+
# ---------------------------------------------------------------------------
|
|
64
|
+
RECENT_OBS=$(tail -500 "$OBS_FILE")
|
|
65
|
+
|
|
66
|
+
# ---------------------------------------------------------------------------
|
|
67
|
+
# Build analysis prompt
|
|
68
|
+
# ---------------------------------------------------------------------------
|
|
69
|
+
ANALYSIS_PROMPT="Analyze these Claude Code session observations and extract behavioral patterns as instinct YAML files.
|
|
70
|
+
|
|
71
|
+
OBSERVATIONS (JSONL — each line is a tool call):
|
|
72
|
+
${RECENT_OBS}
|
|
73
|
+
|
|
74
|
+
EXISTING INSTINCTS (already learned — do NOT duplicate these):
|
|
75
|
+
${EXISTING_INSTINCTS}
|
|
76
|
+
|
|
77
|
+
YOUR TASK:
|
|
78
|
+
1. Look for REPEATED PATTERNS — same tool sequence used 3+ times
|
|
79
|
+
2. Look for ERROR-THEN-FIX sequences — tool fails, next tools fix it
|
|
80
|
+
3. Look for TOOL PREFERENCES — one tool consistently chosen over alternatives
|
|
81
|
+
4. Look for WORKFLOW PATTERNS — consistent ordering of operations
|
|
82
|
+
5. Look for USER CORRECTIONS — user says no/stop/don't after an action
|
|
83
|
+
|
|
84
|
+
OUTPUT FORMAT — output ONLY new instincts as YAML blocks, separated by ---:
|
|
85
|
+
|
|
86
|
+
id: descriptive-kebab-case-id
|
|
87
|
+
trigger: \"when [specific situation]\"
|
|
88
|
+
confidence: 0.5
|
|
89
|
+
domain: workflow|tooling|testing|patterns
|
|
90
|
+
source: observation
|
|
91
|
+
scope: project
|
|
92
|
+
project_id: ${PROJECT_HASH}
|
|
93
|
+
created: \"$(date -u +%Y-%m-%d)\"
|
|
94
|
+
last_seen: \"$(date -u +%Y-%m-%d)\"
|
|
95
|
+
observation_count: [number of times pattern was seen]
|
|
96
|
+
---
|
|
97
|
+
[One sentence describing the specific actionable behavior]
|
|
98
|
+
|
|
99
|
+
Rules:
|
|
100
|
+
- Only create instincts for patterns seen 3+ times
|
|
101
|
+
- Start confidence at 0.5 (suggest level)
|
|
102
|
+
- Be specific and actionable (not vague advice)
|
|
103
|
+
- Different from existing instincts listed above
|
|
104
|
+
|
|
105
|
+
If no new patterns are found, output exactly: NO_NEW_PATTERNS
|
|
106
|
+
|
|
107
|
+
Output ONLY the YAML blocks or NO_NEW_PATTERNS. No explanation, no preamble."
|
|
108
|
+
|
|
109
|
+
# ---------------------------------------------------------------------------
|
|
110
|
+
# Run analysis with Haiku
|
|
111
|
+
# ---------------------------------------------------------------------------
|
|
112
|
+
echo "Analyzing patterns with Haiku..."
|
|
113
|
+
RESULT=$(echo "$ANALYSIS_PROMPT" | claude --model haiku --print -p - 2>/dev/null) || {
|
|
114
|
+
echo "Analysis failed — claude CLI error. Try running manually."
|
|
115
|
+
exit 1
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if [[ "$RESULT" == "NO_NEW_PATTERNS" ]] || [[ -z "$RESULT" ]]; then
|
|
119
|
+
echo "No new patterns detected yet. Keep using Claude Code — patterns emerge over time."
|
|
120
|
+
exit 0
|
|
121
|
+
fi
|
|
122
|
+
|
|
123
|
+
# ---------------------------------------------------------------------------
|
|
124
|
+
# Write instinct YAML files
|
|
125
|
+
# ---------------------------------------------------------------------------
|
|
126
|
+
mkdir -p "$PROJECT_DIR"
|
|
127
|
+
|
|
128
|
+
NEW_COUNT=0
|
|
129
|
+
INSTINCT_ID=""
|
|
130
|
+
BLOCK=""
|
|
131
|
+
|
|
132
|
+
while IFS= read -r line; do
|
|
133
|
+
if [[ "$line" == "---" ]] && [[ -n "$BLOCK" ]]; then
|
|
134
|
+
if [[ -n "$INSTINCT_ID" ]]; then
|
|
135
|
+
DEST="${PROJECT_DIR}/${INSTINCT_ID}.yaml"
|
|
136
|
+
printf '%s\n' "$BLOCK" > "$DEST"
|
|
137
|
+
echo " + ${INSTINCT_ID} -> ${DEST}"
|
|
138
|
+
NEW_COUNT=$((NEW_COUNT + 1))
|
|
139
|
+
fi
|
|
140
|
+
INSTINCT_ID=""
|
|
141
|
+
BLOCK=""
|
|
142
|
+
else
|
|
143
|
+
BLOCK="${BLOCK}${line}"$'\n'
|
|
144
|
+
if [[ "$line" =~ ^id:\ (.+) ]]; then
|
|
145
|
+
INSTINCT_ID="${BASH_REMATCH[1]}"
|
|
146
|
+
INSTINCT_ID="${INSTINCT_ID//\"/}"
|
|
147
|
+
INSTINCT_ID="${INSTINCT_ID//\'/}"
|
|
148
|
+
fi
|
|
149
|
+
fi
|
|
150
|
+
done <<< "$RESULT"
|
|
151
|
+
|
|
152
|
+
# Handle last block
|
|
153
|
+
if [[ -n "$INSTINCT_ID" ]] && [[ -n "$BLOCK" ]]; then
|
|
154
|
+
DEST="${PROJECT_DIR}/${INSTINCT_ID}.yaml"
|
|
155
|
+
printf '%s\n' "$BLOCK" > "$DEST"
|
|
156
|
+
echo " + ${INSTINCT_ID} -> ${DEST}"
|
|
157
|
+
NEW_COUNT=$((NEW_COUNT + 1))
|
|
158
|
+
fi
|
|
159
|
+
|
|
160
|
+
echo ""
|
|
161
|
+
echo "Created ${NEW_COUNT} new instinct(s) in ${PROJECT_DIR}/"
|