continuous-improvement 1.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.
@@ -0,0 +1,115 @@
1
+ #!/usr/bin/env bash
2
+ # start-observer.sh — Start the Mulahazah background observer
3
+ # Checks for an existing instance, cleans up stale PIDs, and launches observer-loop.sh.
4
+
5
+ set -euo pipefail
6
+
7
+ MULAHAZAH_DIR="${HOME}/.claude/mulahazah"
8
+ PID_FILE="${MULAHAZAH_DIR}/observer.pid"
9
+ LOG_FILE="${MULAHAZAH_DIR}/observer.log"
10
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
11
+ LOOP_SCRIPT="${SCRIPT_DIR}/observer-loop.sh"
12
+
13
+ # ---------------------------------------------------------------------------
14
+ # Helpers
15
+ # ---------------------------------------------------------------------------
16
+ print_status() {
17
+ local pid="$1"
18
+ echo "Mulahazah observer is running (PID ${pid})"
19
+ echo ""
20
+ echo " Force immediate analysis: kill -USR1 ${pid}"
21
+ echo " Stop observer: kill ${pid}"
22
+ echo " View logs: tail -f ${LOG_FILE}"
23
+ echo " PID file: ${PID_FILE}"
24
+ }
25
+
26
+ # ---------------------------------------------------------------------------
27
+ # Validate dependencies
28
+ # ---------------------------------------------------------------------------
29
+ if ! command -v jq &>/dev/null; then
30
+ echo "Error: jq is required but not installed." >&2
31
+ exit 1
32
+ fi
33
+
34
+ if ! command -v claude &>/dev/null; then
35
+ echo "Error: claude CLI is required but not installed." >&2
36
+ exit 1
37
+ fi
38
+
39
+ if [[ ! -f "$LOOP_SCRIPT" ]]; then
40
+ echo "Error: observer-loop.sh not found at ${LOOP_SCRIPT}" >&2
41
+ exit 1
42
+ fi
43
+
44
+ # ---------------------------------------------------------------------------
45
+ # Check for existing running instance
46
+ # ---------------------------------------------------------------------------
47
+ if [[ -f "$PID_FILE" ]]; then
48
+ EXISTING_PID="$(cat "$PID_FILE" 2>/dev/null || true)"
49
+
50
+ if [[ -n "$EXISTING_PID" ]] && kill -0 "$EXISTING_PID" 2>/dev/null; then
51
+ # Process is alive
52
+ echo "Mulahazah observer is already running."
53
+ echo ""
54
+ print_status "$EXISTING_PID"
55
+ exit 0
56
+ else
57
+ # Stale PID file — process is gone
58
+ echo "Cleaning up stale PID file (PID ${EXISTING_PID:-unknown} is no longer running)"
59
+ rm -f "$PID_FILE"
60
+ fi
61
+ fi
62
+
63
+ # ---------------------------------------------------------------------------
64
+ # Ensure Mulahazah directory structure exists
65
+ # ---------------------------------------------------------------------------
66
+ mkdir -p "${MULAHAZAH_DIR}/projects"
67
+ mkdir -p "${MULAHAZAH_DIR}/instincts/global"
68
+
69
+ # ---------------------------------------------------------------------------
70
+ # Initialize config.json if it doesn't exist
71
+ # ---------------------------------------------------------------------------
72
+ CONFIG_FILE="${MULAHAZAH_DIR}/config.json"
73
+ if [[ ! -f "$CONFIG_FILE" ]]; then
74
+ # Check if a repo-level config exists next to this script's parent
75
+ REPO_CONFIG="$(dirname "$SCRIPT_DIR")/config.json"
76
+ if [[ -f "$REPO_CONFIG" ]]; then
77
+ cp "$REPO_CONFIG" "$CONFIG_FILE"
78
+ echo "Initialized config from ${REPO_CONFIG}"
79
+ else
80
+ cat > "$CONFIG_FILE" <<'EOF'
81
+ {
82
+ "version": "2.0",
83
+ "observer": {
84
+ "enabled": true,
85
+ "run_interval_minutes": 5,
86
+ "min_observations_to_analyze": 20,
87
+ "model": "haiku"
88
+ }
89
+ }
90
+ EOF
91
+ echo "Created default config at ${CONFIG_FILE}"
92
+ fi
93
+ fi
94
+
95
+ # ---------------------------------------------------------------------------
96
+ # Launch observer-loop.sh in background with nohup
97
+ # ---------------------------------------------------------------------------
98
+ nohup bash "$LOOP_SCRIPT" >> "$LOG_FILE" 2>&1 &
99
+ OBSERVER_PID=$!
100
+
101
+ # Write PID file
102
+ printf '%d\n' "$OBSERVER_PID" > "$PID_FILE"
103
+
104
+ # Brief pause to confirm the process started
105
+ sleep 1
106
+ if ! kill -0 "$OBSERVER_PID" 2>/dev/null; then
107
+ echo "Error: observer-loop.sh failed to start. Check logs:" >&2
108
+ echo " ${LOG_FILE}" >&2
109
+ rm -f "$PID_FILE"
110
+ exit 1
111
+ fi
112
+
113
+ echo "Mulahazah observer started."
114
+ echo ""
115
+ print_status "$OBSERVER_PID"
package/config.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "version": "2.0",
3
+ "observer": {
4
+ "enabled": true,
5
+ "run_interval_minutes": 5,
6
+ "min_observations_to_analyze": 20,
7
+ "model": "haiku"
8
+ }
9
+ }
@@ -0,0 +1,153 @@
1
+ # Failure Taxonomy: How AI Agents Break
2
+
3
+ A structured classification of AI agent failure modes, organized by root cause.
4
+
5
+ ---
6
+
7
+ ## Category 1: Scope Failures
8
+
9
+ Failures where the agent does the wrong amount of work.
10
+
11
+ ### 1.1 Feature Sprawl
12
+ - **Description:** Agent expands scope far beyond the request
13
+ - **Trigger:** Open-ended tasks like "add X" or "improve Y"
14
+ - **Example:** Asked to add dark mode, builds a full theme engine
15
+ - **Prevention:** Law 2 — Plan with explicit anti-scope
16
+ - **Severity:** High — creates technical debt and introduces bugs in unrelated code
17
+
18
+ ### 1.2 Gold Plating
19
+ - **Description:** Agent adds unnecessary polish, optimization, or features
20
+ - **Trigger:** Agent completes the task and keeps going
21
+ - **Example:** Adding error handling to functions that can't fail, optimizing code that runs once
22
+ - **Prevention:** Law 3 — One thing at a time; Law 6 — Iterate means one change
23
+ - **Severity:** Medium — wastes time, may introduce bugs
24
+
25
+ ### 1.3 Under-Delivery
26
+ - **Description:** Agent delivers less than requested but reports completion
27
+ - **Trigger:** Complex tasks where the agent loses track of requirements
28
+ - **Example:** Implementing 3 of 5 requested endpoints and saying "done"
29
+ - **Prevention:** Law 4 — Verify against the original request before reporting
30
+ - **Severity:** High — user trusts the completion report
31
+
32
+ ---
33
+
34
+ ## Category 2: Execution Failures
35
+
36
+ Failures in how the agent carries out the work.
37
+
38
+ ### 2.1 Blind Execution
39
+ - **Description:** Agent writes code without researching constraints
40
+ - **Trigger:** Any task involving external APIs, libraries, or services
41
+ - **Example:** Setting polling interval to 10s on an API with 100 req/hour limit
42
+ - **Prevention:** Law 1 — Research rate limits, constraints, and existing implementations
43
+ - **Severity:** Critical — can cause production incidents
44
+
45
+ ### 2.2 Compounding Changes
46
+ - **Description:** Agent makes multiple changes before testing any of them
47
+ - **Trigger:** Refactoring, bug fixes, feature additions
48
+ - **Example:** Changing the ORM, query logic, and pagination in one commit
49
+ - **Prevention:** Law 6 — One change, verify, next change
50
+ - **Severity:** High — makes debugging extremely difficult
51
+
52
+ ### 2.3 Session Explosion
53
+ - **Description:** Agent spawns parallel tasks that conflict or duplicate work
54
+ - **Trigger:** Tasks that seem decomposable
55
+ - **Example:** Launching 3 different caching approaches simultaneously
56
+ - **Prevention:** Law 3 — One thing at a time; pick the simplest approach
57
+ - **Severity:** High — multiplies complexity and failure points
58
+
59
+ ### 2.4 Workaround Cascades
60
+ - **Description:** Agent encounters an error and builds around it instead of fixing it
61
+ - **Trigger:** Errors that seem hard to fix directly
62
+ - **Example:** Adding a proxy to avoid CORS instead of adding the header server-side
63
+ - **Prevention:** Law 4 — Report errors honestly; Law 1 — Research the actual fix
64
+ - **Severity:** High — creates architectural debt
65
+
66
+ ---
67
+
68
+ ## Category 3: Verification Failures
69
+
70
+ Failures in confirming the work is correct.
71
+
72
+ ### 3.1 Premature Completion
73
+ - **Description:** Agent reports "done" without running the code
74
+ - **Trigger:** Any task completion
75
+ - **Example:** "The function is implemented!" — but it has a syntax error
76
+ - **Prevention:** Law 4 — Run it, check output, confirm build passes
77
+ - **Severity:** Critical — user trusts the agent's report
78
+
79
+ ### 3.2 Assumed Success
80
+ - **Description:** Agent checks partial output and assumes the rest is correct
81
+ - **Trigger:** Long-running tasks, tasks with multiple outputs
82
+ - **Example:** Checking that the API returns 200 but not checking the response body
83
+ - **Prevention:** Law 4 — Check the actual result, not a proxy for the result
84
+ - **Severity:** High — bugs hide in unchecked outputs
85
+
86
+ ### 3.3 Confirmation Bias
87
+ - **Description:** Agent interprets ambiguous output as success
88
+ - **Trigger:** Tasks where "correct" is subjective or loosely defined
89
+ - **Example:** "The output looks right" when it's missing a field
90
+ - **Prevention:** Law 2 — Define verification criteria in the plan
91
+ - **Severity:** Medium — subtle bugs that emerge later
92
+
93
+ ---
94
+
95
+ ## Category 4: Communication Failures
96
+
97
+ Failures in how the agent reports its work.
98
+
99
+ ### 4.1 Silent Error Masking
100
+ - **Description:** Agent encounters errors and doesn't mention them
101
+ - **Trigger:** Errors during execution that the agent works around
102
+ - **Example:** Import fails, agent rewrites the import path without mentioning it
103
+ - **Prevention:** Law 4 — Report all errors, even ones you fix
104
+ - **Severity:** High — user doesn't know about fragile workarounds
105
+
106
+ ### 4.2 Overconfident Reporting
107
+ - **Description:** Agent presents uncertain results as definitive
108
+ - **Trigger:** Complex tasks with partial success
109
+ - **Example:** "Everything works!" when 2 of 5 tests are skipped
110
+ - **Prevention:** Law 4 — Specific verification, not general claims
111
+ - **Severity:** High — erodes trust when issues surface later
112
+
113
+ ### 4.3 Missing Context
114
+ - **Description:** Agent completes work but doesn't explain trade-offs or limitations
115
+ - **Trigger:** Tasks with multiple valid approaches
116
+ - **Example:** Choosing in-memory cache without mentioning it won't survive restarts
117
+ - **Prevention:** Law 5 — Reflect on decisions and trade-offs
118
+ - **Severity:** Medium — user makes uninformed decisions
119
+
120
+ ---
121
+
122
+ ## Category 5: Learning Failures
123
+
124
+ Failures in adapting from experience.
125
+
126
+ ### 5.1 Repeated Mistakes
127
+ - **Description:** Agent makes the same error across sessions
128
+ - **Trigger:** Any error that isn't captured in system instructions
129
+ - **Example:** Hitting the same rate limit three sessions in a row
130
+ - **Prevention:** Law 5 — Reflect and generate rules for the system prompt
131
+ - **Severity:** High — wastes time and erodes trust
132
+
133
+ ### 5.2 Pattern Blindness
134
+ - **Description:** Agent doesn't recognize that a current situation matches a past one
135
+ - **Trigger:** Similar tasks in different contexts
136
+ - **Example:** Over-engineering a feature after learning not to in a different project
137
+ - **Prevention:** Law 5 — Generate transferable rules, not situation-specific notes
138
+ - **Severity:** Medium — slower convergence on good behavior
139
+
140
+ ---
141
+
142
+ ## Cross-Reference: Laws to Failures
143
+
144
+ | Law | Prevents |
145
+ |-----|----------|
146
+ | Law 1: Research | 2.1, 2.4, 3.3 |
147
+ | Law 2: Plan | 1.1, 1.3, 3.3 |
148
+ | Law 3: One Thing | 1.1, 1.2, 2.3 |
149
+ | Law 4: Verify | 1.3, 3.1, 3.2, 4.1, 4.2 |
150
+ | Law 5: Reflect | 4.3, 5.1, 5.2 |
151
+ | Law 6: Iterate | 1.2, 2.2 |
152
+
153
+ Every failure mode maps to at least one law. Every law prevents at least two failure modes.
@@ -0,0 +1,105 @@
1
+ # Integration Guide
2
+
3
+ ## Fast path
4
+
5
+ ```bash
6
+ npx continuous-improvement install
7
+ ```
8
+
9
+ If auto-detect does not hit the right target:
10
+
11
+ ```bash
12
+ npx continuous-improvement install --claude
13
+ npx continuous-improvement install --codex
14
+ npx continuous-improvement install --cursor
15
+ npx continuous-improvement install --openclaw
16
+ npx continuous-improvement install --chatgpt
17
+ ```
18
+
19
+ ## Targets
20
+
21
+ ### Claude Code
22
+
23
+ Project-level:
24
+
25
+ ```bash
26
+ npx continuous-improvement install --claude
27
+ ```
28
+
29
+ Global:
30
+
31
+ ```bash
32
+ npx continuous-improvement install --claude --global
33
+ ```
34
+
35
+ This appends the continuous-improvement rules to `CLAUDE.md`.
36
+
37
+ ### Codex / AGENTS.md flows
38
+
39
+ ```bash
40
+ npx continuous-improvement install --codex
41
+ ```
42
+
43
+ This appends the rules to `AGENTS.md` in the current project.
44
+
45
+ ### Cursor
46
+
47
+ ```bash
48
+ npx continuous-improvement install --cursor
49
+ ```
50
+
51
+ This appends the rules to `.cursorrules`.
52
+
53
+ ### OpenClaw skill
54
+
55
+ ```bash
56
+ npx continuous-improvement install --openclaw
57
+ ```
58
+
59
+ This installs:
60
+
61
+ ```text
62
+ ~/.openclaw/skills/continuous-improvement/SKILL.md
63
+ ```
64
+
65
+ ### ChatGPT
66
+
67
+ ```bash
68
+ npx continuous-improvement install --chatgpt
69
+ ```
70
+
71
+ This prints the exact text to paste into ChatGPT Custom Instructions.
72
+
73
+ ## Uninstall
74
+
75
+ ```bash
76
+ npx continuous-improvement uninstall --claude
77
+ npx continuous-improvement uninstall --codex
78
+ npx continuous-improvement uninstall --cursor
79
+ npx continuous-improvement uninstall --openclaw
80
+ ```
81
+
82
+ ## Manual fallback
83
+
84
+ Use these files directly if you do not want the installer:
85
+
86
+ - `prompts/coding-agent.md`
87
+ - `prompts/core.md`
88
+ - `prompts/minimal.md`
89
+ - `skills/continuous-improvement/SKILL.md`
90
+
91
+ ## How to verify it worked
92
+
93
+ Give the agent a task like:
94
+
95
+ > Add a caching layer to the API.
96
+
97
+ If continuous-improvement is working, the agent should:
98
+
99
+ 1. research first
100
+ 2. define scope and anti-scope
101
+ 3. state verification steps
102
+ 4. execute one thing at a time
103
+ 5. reflect after the task
104
+
105
+ If it skips straight to coding and declares victory without checks, it is not installed correctly.
@@ -0,0 +1,127 @@
1
+ # Philosophy: Why continuous-improvement Works
2
+
3
+ ---
4
+
5
+ ## The Core Insight
6
+
7
+ AI agents fail not because they lack capability, but because they lack discipline.
8
+
9
+ A language model trained on code completions will complete things. That's what it's optimized for. Whether the completion is correct, scoped, or verified is orthogonal to the training signal.
10
+
11
+ continuous-improvement doesn't add capability. It adds structure. And structure, it turns out, is the bottleneck.
12
+
13
+ ---
14
+
15
+ ## Structure Beats Intelligence
16
+
17
+ Consider two agents:
18
+
19
+ **Agent A:** State-of-the-art model, unlimited context, no framework.
20
+ **Agent B:** Previous-gen model, standard context, continuous-improvement installed.
21
+
22
+ Give both the task: "Fix the login bug."
23
+
24
+ Agent A will investigate, find the bug, fix it, refactor the surrounding code, add error handling, update the tests, add a new feature it noticed was missing, and report "done" — having introduced two new bugs in the code it didn't need to touch.
25
+
26
+ Agent B will investigate, find the bug, fix it, verify the fix, and stop. It will report what it found, what it changed, and what it didn't change.
27
+
28
+ Agent B ships. Agent A creates a follow-up ticket.
29
+
30
+ This is not hypothetical. This happens every day in codebases using AI agents.
31
+
32
+ ---
33
+
34
+ ## Why Agents Over-Execute
35
+
36
+ Three forces drive agents to do too much:
37
+
38
+ ### 1. Completion Bias
39
+
40
+ Language models are trained to complete. An open-ended task is an invitation to keep going. "Add caching" becomes "add caching, monitoring, warming, invalidation, distributed sync, and a management CLI" because each addition is a natural completion of the previous one.
41
+
42
+ The cure: anti-scope. Explicitly stating what you will NOT build creates a boundary that completion bias can't cross.
43
+
44
+ ### 2. Helpfulness Gradient
45
+
46
+ Agents are trained to be helpful. More features feels more helpful. "While I'm here, I'll also..." is the agent equivalent of a developer gold-plating a feature.
47
+
48
+ The cure: one thing at a time. When the task is singular, the helpfulness gradient points at completing that task, not expanding it.
49
+
50
+ ### 3. Verification Avoidance
51
+
52
+ Verification is boring. The agent has already "solved" the problem in its internal representation. Running the build, checking the output, and confirming the results is mechanical work that doesn't exercise the model's strengths.
53
+
54
+ The cure: making verification a non-negotiable step. "Done" has a checklist, and the checklist includes actual verification — not assumed verification.
55
+
56
+ ---
57
+
58
+ ## Why Reflection Matters
59
+
60
+ Agents don't learn between sessions. Your context window is their entire universe. When the session ends, the lessons vanish.
61
+
62
+ This is a fundamental limitation that no amount of model improvement will fix. Even with perfect memory, an agent that doesn't explicitly reflect won't extract transferable lessons.
63
+
64
+ Structured reflection solves this by creating artifacts:
65
+
66
+ ```
67
+ ## Reflection
68
+ - What worked: In-memory cache was simpler than Redis for single-server
69
+ - What failed: nothing
70
+ - What I'd do differently: nothing
71
+ - Rule to add: For single-server deployments, start with in-memory. Upgrade to Redis only when you add a second server.
72
+ ```
73
+
74
+ That "rule to add" becomes a system prompt addition, a CLAUDE.md entry, or a team convention. The agent that reflects today fails differently tomorrow. The agent that doesn't reflects makes the same mistake forever.
75
+
76
+ ---
77
+
78
+ ## The Loop Is the Product
79
+
80
+ ```
81
+ Research → Plan → Execute (one thing) → Verify → Reflect → Iterate
82
+ ```
83
+
84
+ This loop is not novel. It's a formalization of what good engineers do naturally:
85
+ - Understand the problem before solving it
86
+ - Define what you're building and what you're not
87
+ - Do one thing, check it works, do the next thing
88
+ - Confirm the result before claiming victory
89
+ - Learn from the experience
90
+
91
+ The novelty is applying it to AI agents — entities that are powerful enough to skip every step and confident enough to never notice.
92
+
93
+ ---
94
+
95
+ ## Why "One Thing at a Time" Is the Most Important Law
96
+
97
+ If you could only install one law, install Law 3.
98
+
99
+ Every other failure mode is amplified by doing multiple things at once:
100
+ - Feature sprawl is multiple features without verification
101
+ - Compounding iteration is multiple changes without testing
102
+ - Session explosion is multiple approaches without completion
103
+ - Silent failure is multiple workarounds without reporting
104
+
105
+ "One thing at a time" is the circuit breaker. It limits the blast radius of every mistake to exactly one change. When something breaks, you know what caused it. When something works, you know what to keep.
106
+
107
+ It's slower per-step. It's faster to correct completion. Always.
108
+
109
+ ---
110
+
111
+ ## Design Principles
112
+
113
+ ### Opinionated Over Flexible
114
+
115
+ "It depends" doesn't belong in a system prompt. Agents need clear rules, not frameworks for making decisions. The 6 laws are deliberately prescriptive.
116
+
117
+ ### Practical Over Theoretical
118
+
119
+ Every law exists because its absence caused a real failure. No law was added for theoretical completeness or because it "seemed right."
120
+
121
+ ### Minimal Over Comprehensive
122
+
123
+ The prompt must fit in a context window alongside actual work. Every word competes with code, docs, and conversation for attention. The laws are as short as they can be while remaining unambiguous.
124
+
125
+ ### Universal Over Tool-Specific
126
+
127
+ The core prompt works in any agent. The variants optimize for specific tools but the principles are the same. Research, plan, execute, verify, reflect, iterate. The loop doesn't care about your IDE.