continuous-improvement 3.1.0 → 3.9.1
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 +66 -0
- package/CHANGELOG.md +216 -0
- package/QUICKSTART.md +79 -12
- package/README.md +229 -349
- package/SKILL.md +87 -9
- package/action.yml +1 -1
- package/bin/analyze.sh +9 -1
- package/bin/backfill.mjs +172 -0
- package/bin/check-doc-runtime-claims.mjs +120 -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 +171 -0
- package/bin/harvest-friction.mjs +279 -0
- package/bin/hook-stats.mjs +258 -0
- package/bin/install.mjs +407 -499
- package/bin/lint-transcript.mjs +182 -210
- package/bin/mcp-server.mjs +834 -608
- 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 +43 -2
- package/commands/discipline.md +14 -0
- 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 +180 -0
- package/commands/swarm.md +101 -0
- package/commands/workspace-surface-audit.md +77 -0
- package/hooks/gateguard.mjs +172 -0
- package/hooks/observe.sh +42 -4
- package/hooks/session.sh +3 -3
- package/hooks/three-section-close.mjs +181 -0
- package/instinct-packs/meta.json +16 -0
- package/lib/cli-anything.mjs +401 -0
- package/lib/compound-engineering.mjs +831 -0
- package/lib/gateguard-state.mjs +85 -0
- package/lib/observe-event.mjs +128 -0
- package/lib/plugin-metadata.mjs +435 -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 +32 -7
- package/package.json +29 -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 +57 -0
- package/plugins/continuous-improvement/agents/README.md +120 -0
- package/plugins/continuous-improvement/agents/code-reviewer.md +97 -0
- package/plugins/continuous-improvement/agents/security-auditor.md +101 -0
- package/plugins/continuous-improvement/agents/test-engineer.md +95 -0
- package/plugins/continuous-improvement/bin/backfill.mjs +172 -0
- package/plugins/continuous-improvement/bin/mcp-server.mjs +889 -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 +180 -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/gateguard.mjs +172 -0
- package/plugins/continuous-improvement/hooks/hooks.json +65 -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 +435 -0
- package/plugins/continuous-improvement/lib/resolve-home-dir.mjs +43 -0
- package/plugins/continuous-improvement/skills/README.md +37 -0
- package/plugins/continuous-improvement/skills/continuous-improvement/SKILL.md +249 -0
- package/plugins/continuous-improvement/skills/deploy-receipt/SKILL.md +178 -0
- package/plugins/continuous-improvement/skills/gateguard/SKILL.md +163 -0
- package/plugins/continuous-improvement/skills/para-memory-files/SKILL.md +108 -0
- package/plugins/continuous-improvement/skills/proceed-with-the-recommendation/SKILL.md +447 -0
- package/plugins/continuous-improvement/skills/ralph/SKILL.md +221 -0
- package/plugins/continuous-improvement/skills/recovery-classification/SKILL.md +73 -0
- package/plugins/continuous-improvement/skills/safety-guard/SKILL.md +76 -0
- package/plugins/continuous-improvement/skills/state-reconciliation/SKILL.md +63 -0
- package/plugins/continuous-improvement/skills/strategic-compact/SKILL.md +104 -0
- package/plugins/continuous-improvement/skills/superpowers/SKILL.md +219 -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 +224 -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/skills/worktree-safety/SKILL.md +66 -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 +178 -0
- package/skills/gateguard.md +163 -0
- package/skills/para-memory-files.md +108 -0
- package/skills/proceed-with-the-recommendation.md +447 -0
- package/skills/ralph.md +221 -0
- package/skills/recovery-classification.md +73 -0
- package/skills/safety-guard.md +76 -0
- package/skills/state-reconciliation.md +63 -0
- package/skills/strategic-compact.md +104 -0
- package/skills/superpowers.md +219 -0
- package/skills/tdd-workflow.md +411 -0
- package/skills/token-budget-advisor.md +136 -0
- package/skills/verification-loop.md +224 -0
- package/skills/wild-risa-balance.md +191 -0
- package/skills/workspace-surface-audit.md +147 -0
- package/skills/worktree-safety.md +66 -0
- package/templates/insights-claude-md.md +91 -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 +60 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Runtime PreToolUse gateguard hook.
|
|
4
|
+
*
|
|
5
|
+
* Stdin : JSON { tool_name, tool_input }
|
|
6
|
+
* Stdout : JSON { decision: "allow" | "block", reason?: string }
|
|
7
|
+
* Exit : 0 always (decision is in stdout, fail-open on parse error).
|
|
8
|
+
*
|
|
9
|
+
* Three-stage gate per skills/gateguard.md:
|
|
10
|
+
* - DENY : first mutating tool call per file, with fact-list reason
|
|
11
|
+
* - FORCE : agent presents facts (model-side; out of band)
|
|
12
|
+
* - ALLOW : retry once `_gateguard_facts_presented: true` is set or the
|
|
13
|
+
* per-file marker is recorded in session state
|
|
14
|
+
*
|
|
15
|
+
* Read-only and exploratory tools (Read, Grep, Glob, routine Bash) bypass
|
|
16
|
+
* unconditionally. Destructive Bash gates EVERY call, not just first.
|
|
17
|
+
*
|
|
18
|
+
* V1 honest limitations (see src/lib/gateguard-state.mts header):
|
|
19
|
+
* honor-system flag, state-file deletion, parallel-hook race.
|
|
20
|
+
*
|
|
21
|
+
* MultiEdit handling (V1): gates on edits[0].file_path only. Per-file
|
|
22
|
+
* batching is not implemented — TODO: extend to gate every entry in
|
|
23
|
+
* edits[]. Tracked in issue #106 acceptance criteria item 5.
|
|
24
|
+
*/
|
|
25
|
+
import { readFileSync } from "node:fs";
|
|
26
|
+
import { isCapReached, loadState, markFileCleared, resolveSessionDir, saveState, } from "../lib/gateguard-state.mjs";
|
|
27
|
+
const TOOL_ROUTE = {
|
|
28
|
+
Read: "allow",
|
|
29
|
+
Grep: "allow",
|
|
30
|
+
Glob: "allow",
|
|
31
|
+
LS: "allow",
|
|
32
|
+
NotebookRead: "allow",
|
|
33
|
+
Write: "mutating-file",
|
|
34
|
+
Edit: "mutating-file",
|
|
35
|
+
MultiEdit: "mutating-file",
|
|
36
|
+
NotebookEdit: "mutating-file",
|
|
37
|
+
Bash: "allow",
|
|
38
|
+
};
|
|
39
|
+
const DESTRUCTIVE_PATTERNS = [
|
|
40
|
+
"rm -rf",
|
|
41
|
+
"rm -fr",
|
|
42
|
+
"git reset --hard",
|
|
43
|
+
"git push --force",
|
|
44
|
+
"git push -f",
|
|
45
|
+
"--force-with-lease",
|
|
46
|
+
"git branch -D",
|
|
47
|
+
"drop table",
|
|
48
|
+
"drop database",
|
|
49
|
+
"drop schema",
|
|
50
|
+
"truncate ",
|
|
51
|
+
"mkfs",
|
|
52
|
+
"dd if=",
|
|
53
|
+
"format ",
|
|
54
|
+
"rmdir /s",
|
|
55
|
+
"del /f /q",
|
|
56
|
+
"del /q /f",
|
|
57
|
+
"Remove-Item -Recurse",
|
|
58
|
+
"Remove-Item -Force",
|
|
59
|
+
];
|
|
60
|
+
function isDestructiveBash(command) {
|
|
61
|
+
const lower = command.toLowerCase();
|
|
62
|
+
return DESTRUCTIVE_PATTERNS.some((p) => lower.includes(p.toLowerCase()));
|
|
63
|
+
}
|
|
64
|
+
function classifyTool(toolName, toolInput) {
|
|
65
|
+
const route = TOOL_ROUTE[toolName] ?? "allow";
|
|
66
|
+
if (route !== "allow")
|
|
67
|
+
return route;
|
|
68
|
+
if (toolName === "Bash" && typeof toolInput.command === "string") {
|
|
69
|
+
if (isDestructiveBash(toolInput.command))
|
|
70
|
+
return "destructive-bash";
|
|
71
|
+
}
|
|
72
|
+
return "allow";
|
|
73
|
+
}
|
|
74
|
+
function extractFilePath(toolInput) {
|
|
75
|
+
if (typeof toolInput.file_path === "string")
|
|
76
|
+
return toolInput.file_path;
|
|
77
|
+
// MultiEdit V1: first edit's file_path is the canonical key.
|
|
78
|
+
if (Array.isArray(toolInput.edits) && toolInput.edits.length > 0) {
|
|
79
|
+
const first = toolInput.edits[0];
|
|
80
|
+
if (first && typeof first.file_path === "string")
|
|
81
|
+
return first.file_path;
|
|
82
|
+
}
|
|
83
|
+
if (typeof toolInput.command === "string")
|
|
84
|
+
return toolInput.command;
|
|
85
|
+
return "";
|
|
86
|
+
}
|
|
87
|
+
function buildMutatingFileReason(toolName, filePath) {
|
|
88
|
+
return [
|
|
89
|
+
`Before ${toolName === "Write" ? "creating" : "editing"} ${filePath || "<unknown>"}, present these facts:`,
|
|
90
|
+
"",
|
|
91
|
+
" 1. List ALL files that import/require this file (use Grep)",
|
|
92
|
+
" 2. List the public functions/classes affected by this change",
|
|
93
|
+
" 3. If this file reads/writes data files, show field names, structure, and date format",
|
|
94
|
+
" 4. Quote the user's current instruction verbatim",
|
|
95
|
+
"",
|
|
96
|
+
"After presenting the facts, retry with `_gateguard_facts_presented: true` in tool_input,",
|
|
97
|
+
"or with the same file_path after a previous clearance has been recorded for this session.",
|
|
98
|
+
].join("\n");
|
|
99
|
+
}
|
|
100
|
+
function buildDestructiveBashReason(command) {
|
|
101
|
+
return [
|
|
102
|
+
`Destructive command requested: ${command}`,
|
|
103
|
+
"",
|
|
104
|
+
" 1. List ALL files/data this command will modify or delete",
|
|
105
|
+
" 2. Write a one-line rollback procedure",
|
|
106
|
+
" 3. Quote the user's current instruction verbatim",
|
|
107
|
+
"",
|
|
108
|
+
"Destructive Bash gates EVERY call — clearance is not cached.",
|
|
109
|
+
].join("\n");
|
|
110
|
+
}
|
|
111
|
+
function buildCapReachedReason() {
|
|
112
|
+
return [
|
|
113
|
+
"Gateguard session clearance cap reached (50 distinct files).",
|
|
114
|
+
"Start a new Claude Code session to reset the gate. The cap exists to bound",
|
|
115
|
+
"stuck-loop or rogue-agent clearance from compounding within a single session.",
|
|
116
|
+
].join("\n");
|
|
117
|
+
}
|
|
118
|
+
function emit(decision) {
|
|
119
|
+
process.stdout.write(`${JSON.stringify(decision)}\n`);
|
|
120
|
+
process.exit(0);
|
|
121
|
+
}
|
|
122
|
+
function main() {
|
|
123
|
+
let raw = "";
|
|
124
|
+
try {
|
|
125
|
+
raw = readFileSync(0, "utf8");
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
emit({ decision: "allow" });
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
let payload;
|
|
132
|
+
try {
|
|
133
|
+
payload = JSON.parse(raw);
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
emit({ decision: "allow" }); // fail-open
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const toolName = typeof payload.tool_name === "string" ? payload.tool_name : "";
|
|
140
|
+
const toolInput = payload.tool_input ?? {};
|
|
141
|
+
const gate = classifyTool(toolName, toolInput);
|
|
142
|
+
if (gate === "allow") {
|
|
143
|
+
emit({ decision: "allow" });
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (gate === "destructive-bash") {
|
|
147
|
+
const cmd = typeof toolInput.command === "string" ? toolInput.command : "";
|
|
148
|
+
emit({ decision: "block", reason: buildDestructiveBashReason(cmd) });
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
// mutating-file
|
|
152
|
+
const sessionDir = resolveSessionDir();
|
|
153
|
+
const state = loadState(sessionDir);
|
|
154
|
+
const filePath = extractFilePath(toolInput);
|
|
155
|
+
const factsFlagged = toolInput._gateguard_facts_presented === true;
|
|
156
|
+
const alreadyCleared = filePath !== "" && filePath in state.cleared_files;
|
|
157
|
+
if (!factsFlagged && !alreadyCleared) {
|
|
158
|
+
emit({ decision: "block", reason: buildMutatingFileReason(toolName, filePath) });
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (factsFlagged && !alreadyCleared) {
|
|
162
|
+
if (isCapReached(state)) {
|
|
163
|
+
emit({ decision: "block", reason: buildCapReachedReason() });
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (filePath !== "") {
|
|
167
|
+
saveState(sessionDir, markFileCleared(state, filePath));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
emit({ decision: "allow" });
|
|
171
|
+
}
|
|
172
|
+
main();
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "Gateguard fact-forcing PreToolUse, observation, session lifecycle, and 3-section-close discipline hooks for continuous-improvement.",
|
|
3
|
+
"hooks": {
|
|
4
|
+
"PreToolUse": [
|
|
5
|
+
{
|
|
6
|
+
"hooks": [
|
|
7
|
+
{
|
|
8
|
+
"type": "command",
|
|
9
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/gateguard.mjs\"",
|
|
10
|
+
"timeout": 5
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"type": "command",
|
|
14
|
+
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/hooks/observe.sh\"",
|
|
15
|
+
"timeout": 5
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"PostToolUse": [
|
|
21
|
+
{
|
|
22
|
+
"hooks": [
|
|
23
|
+
{
|
|
24
|
+
"type": "command",
|
|
25
|
+
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/hooks/observe.sh\"",
|
|
26
|
+
"timeout": 5
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
"SessionStart": [
|
|
32
|
+
{
|
|
33
|
+
"hooks": [
|
|
34
|
+
{
|
|
35
|
+
"type": "command",
|
|
36
|
+
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/hooks/session.sh\"",
|
|
37
|
+
"timeout": 5
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
"SessionEnd": [
|
|
43
|
+
{
|
|
44
|
+
"hooks": [
|
|
45
|
+
{
|
|
46
|
+
"type": "command",
|
|
47
|
+
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/hooks/session.sh\"",
|
|
48
|
+
"timeout": 5
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
],
|
|
53
|
+
"Stop": [
|
|
54
|
+
{
|
|
55
|
+
"hooks": [
|
|
56
|
+
{
|
|
57
|
+
"type": "command",
|
|
58
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/three-section-close.mjs\"",
|
|
59
|
+
"timeout": 5
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# observe.sh — Mulahazah PreToolUse/PostToolUse observation hook.
|
|
3
|
+
#
|
|
4
|
+
# Two-phase design:
|
|
5
|
+
# 1. PREFERRED: exec the Node observer (bin/observe.mjs) which captures the
|
|
6
|
+
# rich event schema (tool_input.command for Bash, file_path for Edit/
|
|
7
|
+
# Write/Read, tool_output) without depending on jq.
|
|
8
|
+
# 2. FALLBACK: if either node is missing OR the Node observer file is not
|
|
9
|
+
# installed alongside this script, fall through to the in-bash thin-
|
|
10
|
+
# schema path below. The fallback preserves prior behavior so an
|
|
11
|
+
# operator who never re-runs `npx continuous-improvement install` is
|
|
12
|
+
# no worse off than today.
|
|
13
|
+
#
|
|
14
|
+
# Always exits 0 — never blocks the Claude session.
|
|
15
|
+
# Usage: echo '<hook_json>' | observe.sh
|
|
16
|
+
|
|
17
|
+
trap 'exit 0' EXIT ERR INT TERM
|
|
18
|
+
|
|
19
|
+
# Phase 1 — try the Node observer. The shim copies bin/observe.mjs and
|
|
20
|
+
# lib/observe-event.mjs alongside this script under ${HOME}/.claude/instincts/
|
|
21
|
+
# preserving the bin/ + lib/ subdirectory layout so the relative import
|
|
22
|
+
# resolves: observe.mjs lives at .../instincts/bin/observe.mjs, the imported
|
|
23
|
+
# observe-event.mjs at .../instincts/lib/observe-event.mjs.
|
|
24
|
+
NODE_OBSERVER="$(dirname "${BASH_SOURCE[0]}")/bin/observe.mjs"
|
|
25
|
+
if [[ -f "$NODE_OBSERVER" ]] && command -v node &>/dev/null; then
|
|
26
|
+
exec node "$NODE_OBSERVER"
|
|
27
|
+
fi
|
|
28
|
+
|
|
29
|
+
# Phase 2 — bash fallback (thin schema; preserved for back-compat).
|
|
30
|
+
INSTINCTS_DIR="${HOME}/.claude/instincts"
|
|
31
|
+
|
|
32
|
+
# ---------------------------------------------------------------------------
|
|
33
|
+
# Read stdin (hook payload) — single read for performance
|
|
34
|
+
# ---------------------------------------------------------------------------
|
|
35
|
+
INPUT="$(cat)"
|
|
36
|
+
[[ -z "$INPUT" ]] && exit 0
|
|
37
|
+
|
|
38
|
+
# ---------------------------------------------------------------------------
|
|
39
|
+
# Parse hook payload — use jq if available, otherwise basic extraction
|
|
40
|
+
#
|
|
41
|
+
# When jq is missing, observation rows lack tool_input/tool_output, which
|
|
42
|
+
# defeats the auto-instinct pipeline. Emit a one-shot stderr warning per
|
|
43
|
+
# project so the operator notices at the next session start instead of
|
|
44
|
+
# discovering the gap weeks later. The marker file makes it idempotent.
|
|
45
|
+
# ---------------------------------------------------------------------------
|
|
46
|
+
if command -v jq &>/dev/null; then
|
|
47
|
+
read -r TOOL_NAME SESSION_ID HAS_OUTPUT INPUT_JSON OUTPUT_JSON <<< "$(
|
|
48
|
+
printf '%s' "$INPUT" | jq -r '
|
|
49
|
+
(.tool_name // ""),
|
|
50
|
+
(.session_id // ""),
|
|
51
|
+
(if has("tool_output") then "yes" else "no" end),
|
|
52
|
+
((.tool_input // {} | tostring) | .[0:500]),
|
|
53
|
+
((.tool_output // {} | tostring) | .[0:200])
|
|
54
|
+
' | paste - - - - -
|
|
55
|
+
)"
|
|
56
|
+
else
|
|
57
|
+
# One-shot stderr warning per HOME so the operator learns the constraint.
|
|
58
|
+
# Marker lives next to instincts/ (not inside it) so it never collides with
|
|
59
|
+
# tests or analysis loops that iterate INSTINCTS_DIR for project-hash dirs.
|
|
60
|
+
JQ_WARN_MARKER="${HOME}/.claude/.continuous-improvement-jq-warned"
|
|
61
|
+
if [[ ! -f "$JQ_WARN_MARKER" ]]; then
|
|
62
|
+
mkdir -p "${HOME}/.claude" 2>/dev/null
|
|
63
|
+
printf '[continuous-improvement] jq not found on PATH — observe.sh is using thin-schema fallback. Install jq to enable auto-instinct detection (winget install jqlang.jq | brew install jq | apt install jq). This warning is one-shot per host.\n' >&2
|
|
64
|
+
: > "$JQ_WARN_MARKER"
|
|
65
|
+
fi
|
|
66
|
+
# Fallback: extract tool_name with basic pattern matching
|
|
67
|
+
TOOL_NAME="$(printf '%s' "$INPUT" | sed -n 's/.*"tool_name" *: *"\([^"]*\)".*/\1/p' | head -1)"
|
|
68
|
+
SESSION_ID="$(printf '%s' "$INPUT" | sed -n 's/.*"session_id" *: *"\([^"]*\)".*/\1/p' | head -1)"
|
|
69
|
+
HAS_OUTPUT="no"
|
|
70
|
+
printf '%s' "$INPUT" | grep -q '"tool_output"' && HAS_OUTPUT="yes"
|
|
71
|
+
INPUT_JSON="$(printf '%s' "$INPUT" | head -c 500)"
|
|
72
|
+
OUTPUT_JSON=""
|
|
73
|
+
fi
|
|
74
|
+
|
|
75
|
+
[[ -z "$TOOL_NAME" ]] && exit 0
|
|
76
|
+
|
|
77
|
+
# Determine event type
|
|
78
|
+
if [[ "$HAS_OUTPUT" == "yes" ]]; then
|
|
79
|
+
EVENT="tool_complete"
|
|
80
|
+
else
|
|
81
|
+
EVENT="tool_start"
|
|
82
|
+
fi
|
|
83
|
+
|
|
84
|
+
# ---------------------------------------------------------------------------
|
|
85
|
+
# Project detection
|
|
86
|
+
# ---------------------------------------------------------------------------
|
|
87
|
+
PROJECT_ROOT=""
|
|
88
|
+
|
|
89
|
+
if [[ -n "${CLAUDE_PROJECT_DIR:-}" && -d "${CLAUDE_PROJECT_DIR}" ]]; then
|
|
90
|
+
PROJECT_ROOT="${CLAUDE_PROJECT_DIR}"
|
|
91
|
+
fi
|
|
92
|
+
|
|
93
|
+
if [[ -z "$PROJECT_ROOT" ]]; then
|
|
94
|
+
PROJECT_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || true)"
|
|
95
|
+
fi
|
|
96
|
+
|
|
97
|
+
if [[ -z "$PROJECT_ROOT" ]]; then
|
|
98
|
+
PROJECT_ROOT="global"
|
|
99
|
+
fi
|
|
100
|
+
|
|
101
|
+
# ---------------------------------------------------------------------------
|
|
102
|
+
# Compute project hash and name
|
|
103
|
+
# ---------------------------------------------------------------------------
|
|
104
|
+
PROJECT_HASH="$(printf '%s' "$PROJECT_ROOT" | sha256sum | cut -c1-12)"
|
|
105
|
+
PROJECT_NAME="$(basename "${PROJECT_ROOT%.git}")"
|
|
106
|
+
|
|
107
|
+
# ---------------------------------------------------------------------------
|
|
108
|
+
# Directory setup
|
|
109
|
+
# ---------------------------------------------------------------------------
|
|
110
|
+
PROJECT_DIR="${INSTINCTS_DIR}/${PROJECT_HASH}"
|
|
111
|
+
OBS_FILE="${PROJECT_DIR}/observations.jsonl"
|
|
112
|
+
|
|
113
|
+
[[ -d "$PROJECT_DIR" ]] || mkdir -p "$PROJECT_DIR"
|
|
114
|
+
|
|
115
|
+
# ---------------------------------------------------------------------------
|
|
116
|
+
# Rotate observations.jsonl at 10,000 lines
|
|
117
|
+
# ---------------------------------------------------------------------------
|
|
118
|
+
if [[ -f "$OBS_FILE" ]]; then
|
|
119
|
+
LINE_COUNT="$(wc -l < "$OBS_FILE")"
|
|
120
|
+
if (( LINE_COUNT >= 10000 )); then
|
|
121
|
+
mv "$OBS_FILE" "${PROJECT_DIR}/observations.$(date -u +"%Y-%m-%d-%H%M%S").jsonl"
|
|
122
|
+
|
|
123
|
+
# Clean up old archives - keep only 10 most recent
|
|
124
|
+
ls -t "${PROJECT_DIR}"/observations.*.jsonl 2>/dev/null | tail -n +11 | xargs -r rm -f
|
|
125
|
+
fi
|
|
126
|
+
fi
|
|
127
|
+
|
|
128
|
+
# ---------------------------------------------------------------------------
|
|
129
|
+
# Append JSONL observation line
|
|
130
|
+
# ---------------------------------------------------------------------------
|
|
131
|
+
TS="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
|
|
132
|
+
|
|
133
|
+
if command -v jq &>/dev/null; then
|
|
134
|
+
printf '%s\n' "$(jq -cn \
|
|
135
|
+
--arg ts "$TS" \
|
|
136
|
+
--arg event "$EVENT" \
|
|
137
|
+
--arg session "$SESSION_ID" \
|
|
138
|
+
--arg tool "$TOOL_NAME" \
|
|
139
|
+
--arg input_summary "$INPUT_JSON" \
|
|
140
|
+
--arg output_summary "$OUTPUT_JSON" \
|
|
141
|
+
--arg project_id "$PROJECT_HASH" \
|
|
142
|
+
--arg project_name "$PROJECT_NAME" \
|
|
143
|
+
'{ts:$ts,event:$event,session:$session,tool:$tool,input_summary:$input_summary,output_summary:$output_summary,project_id:$project_id,project_name:$project_name}')" \
|
|
144
|
+
>> "$OBS_FILE"
|
|
145
|
+
else
|
|
146
|
+
# Fallback: manual JSON construction
|
|
147
|
+
printf '{"ts":"%s","event":"%s","session":"%s","tool":"%s","project_id":"%s","project_name":"%s"}\n' \
|
|
148
|
+
"$TS" "$EVENT" "$SESSION_ID" "$TOOL_NAME" "$PROJECT_HASH" "$PROJECT_NAME" \
|
|
149
|
+
>> "$OBS_FILE"
|
|
150
|
+
fi
|
|
151
|
+
|
|
152
|
+
# ---------------------------------------------------------------------------
|
|
153
|
+
# Write project.json if new project
|
|
154
|
+
# ---------------------------------------------------------------------------
|
|
155
|
+
PROJECT_JSON="${PROJECT_DIR}/project.json"
|
|
156
|
+
if [[ ! -f "$PROJECT_JSON" ]]; then
|
|
157
|
+
if command -v jq &>/dev/null; then
|
|
158
|
+
jq -n \
|
|
159
|
+
--arg id "$PROJECT_HASH" \
|
|
160
|
+
--arg name "$PROJECT_NAME" \
|
|
161
|
+
--arg root "$PROJECT_ROOT" \
|
|
162
|
+
--arg created_at "$TS" \
|
|
163
|
+
'{id:$id,name:$name,root:$root,created_at:$created_at}' \
|
|
164
|
+
> "$PROJECT_JSON"
|
|
165
|
+
else
|
|
166
|
+
printf '{"id":"%s","name":"%s","root":"%s","created_at":"%s"}\n' \
|
|
167
|
+
"$PROJECT_HASH" "$PROJECT_NAME" "$PROJECT_ROOT" "$TS" \
|
|
168
|
+
> "$PROJECT_JSON"
|
|
169
|
+
fi
|
|
170
|
+
fi
|
|
171
|
+
|
|
172
|
+
exit 0
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# session.sh — SessionStart/SessionEnd hook for continuous-improvement
|
|
3
|
+
# SessionStart: loads instincts and prints status
|
|
4
|
+
# SessionEnd: prompts reflection
|
|
5
|
+
# Always exits 0 — never blocks the session
|
|
6
|
+
trap 'exit 0' EXIT ERR INT TERM
|
|
7
|
+
|
|
8
|
+
INSTINCTS_DIR="${HOME}/.claude/instincts"
|
|
9
|
+
|
|
10
|
+
# Read stdin
|
|
11
|
+
INPUT="$(cat)"
|
|
12
|
+
[[ -z "$INPUT" ]] && exit 0
|
|
13
|
+
|
|
14
|
+
# ---------------------------------------------------------------------------
|
|
15
|
+
# Detect event type from hook context
|
|
16
|
+
# ---------------------------------------------------------------------------
|
|
17
|
+
# SessionStart hooks receive no tool_name, SessionEnd hooks may vary.
|
|
18
|
+
# We detect based on the hook_type field or the calling context.
|
|
19
|
+
EVENT_TYPE=""
|
|
20
|
+
if command -v jq &>/dev/null; then
|
|
21
|
+
EVENT_TYPE="$(printf '%s' "$INPUT" | jq -r '.hook_type // .event_type // "unknown"' 2>/dev/null)"
|
|
22
|
+
else
|
|
23
|
+
if printf '%s' "$INPUT" | grep -q '"SessionStart"'; then
|
|
24
|
+
EVENT_TYPE="SessionStart"
|
|
25
|
+
elif printf '%s' "$INPUT" | grep -q '"SessionEnd"'; then
|
|
26
|
+
EVENT_TYPE="SessionEnd"
|
|
27
|
+
fi
|
|
28
|
+
fi
|
|
29
|
+
|
|
30
|
+
# ---------------------------------------------------------------------------
|
|
31
|
+
# Project detection (same as observe.sh)
|
|
32
|
+
# ---------------------------------------------------------------------------
|
|
33
|
+
PROJECT_ROOT=""
|
|
34
|
+
if [[ -n "${CLAUDE_PROJECT_DIR:-}" && -d "${CLAUDE_PROJECT_DIR}" ]]; then
|
|
35
|
+
PROJECT_ROOT="${CLAUDE_PROJECT_DIR}"
|
|
36
|
+
fi
|
|
37
|
+
if [[ -z "$PROJECT_ROOT" ]]; then
|
|
38
|
+
PROJECT_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || true)"
|
|
39
|
+
fi
|
|
40
|
+
if [[ -z "$PROJECT_ROOT" ]]; then
|
|
41
|
+
PROJECT_ROOT="global"
|
|
42
|
+
fi
|
|
43
|
+
|
|
44
|
+
PROJECT_HASH="$(printf '%s' "$PROJECT_ROOT" | sha256sum | cut -c1-12)"
|
|
45
|
+
PROJECT_DIR="${INSTINCTS_DIR}/${PROJECT_HASH}"
|
|
46
|
+
|
|
47
|
+
# ---------------------------------------------------------------------------
|
|
48
|
+
# SessionStart: count observations and instincts, print brief status
|
|
49
|
+
# ---------------------------------------------------------------------------
|
|
50
|
+
if [[ "$EVENT_TYPE" == "SessionStart" || "$EVENT_TYPE" == "unknown" ]]; then
|
|
51
|
+
OBS_COUNT=0
|
|
52
|
+
INSTINCT_COUNT=0
|
|
53
|
+
|
|
54
|
+
OBS_FILE="${PROJECT_DIR}/observations.jsonl"
|
|
55
|
+
if [[ -f "$OBS_FILE" ]]; then
|
|
56
|
+
OBS_COUNT="$(wc -l < "$OBS_FILE" 2>/dev/null || echo 0)"
|
|
57
|
+
fi
|
|
58
|
+
|
|
59
|
+
# Count yaml files in project + global
|
|
60
|
+
for dir in "$PROJECT_DIR" "${INSTINCTS_DIR}/global"; do
|
|
61
|
+
if [[ -d "$dir" ]]; then
|
|
62
|
+
count="$(find "$dir" -maxdepth 1 -name '*.yaml' 2>/dev/null | wc -l)"
|
|
63
|
+
INSTINCT_COUNT=$((INSTINCT_COUNT + count))
|
|
64
|
+
fi
|
|
65
|
+
done
|
|
66
|
+
|
|
67
|
+
# Determine level
|
|
68
|
+
LEVEL="CAPTURE"
|
|
69
|
+
if (( OBS_COUNT >= 20 )) || (( INSTINCT_COUNT > 0 )); then
|
|
70
|
+
LEVEL="ANALYZE"
|
|
71
|
+
fi
|
|
72
|
+
|
|
73
|
+
# Check for high-confidence instincts
|
|
74
|
+
if (( INSTINCT_COUNT > 0 )); then
|
|
75
|
+
for dir in "$PROJECT_DIR" "${INSTINCTS_DIR}/global"; do
|
|
76
|
+
if [[ -d "$dir" ]]; then
|
|
77
|
+
for f in "$dir"/*.yaml; do
|
|
78
|
+
[[ -f "$f" ]] || continue
|
|
79
|
+
conf="$(grep '^confidence:' "$f" 2>/dev/null | head -1 | sed 's/confidence: *//')"
|
|
80
|
+
if [[ -n "$conf" ]]; then
|
|
81
|
+
# Compare as integer (multiply by 100) using awk for portability
|
|
82
|
+
int_conf="$(printf '%s' "$conf" | awk '{printf "%.0f", $1 * 100}')"
|
|
83
|
+
if [[ -n "$int_conf" ]] && (( int_conf >= 70 )); then
|
|
84
|
+
LEVEL="AUTO-APPLY"
|
|
85
|
+
break 2
|
|
86
|
+
elif (( int_conf >= 50 )); then
|
|
87
|
+
LEVEL="SUGGEST"
|
|
88
|
+
fi
|
|
89
|
+
fi
|
|
90
|
+
done
|
|
91
|
+
fi
|
|
92
|
+
done
|
|
93
|
+
fi
|
|
94
|
+
|
|
95
|
+
# Write status to stderr (visible in hook output, not blocking)
|
|
96
|
+
echo "[continuous-improvement] Level: ${LEVEL} | Observations: ${OBS_COUNT} | Instincts: ${INSTINCT_COUNT}" >&2
|
|
97
|
+
fi
|
|
98
|
+
|
|
99
|
+
# ---------------------------------------------------------------------------
|
|
100
|
+
# SessionEnd: remind to reflect
|
|
101
|
+
# ---------------------------------------------------------------------------
|
|
102
|
+
if [[ "$EVENT_TYPE" == "SessionEnd" ]]; then
|
|
103
|
+
echo "[continuous-improvement] Session ending. Run /continuous-improvement to reflect and capture learnings." >&2
|
|
104
|
+
fi
|
|
105
|
+
|
|
106
|
+
exit 0
|