continuous-improvement 3.15.0 → 3.17.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.
Files changed (32) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/CHANGELOG.md +20 -0
  3. package/README.md +5 -4
  4. package/bin/check-skill-count-prose.mjs +168 -0
  5. package/bin/install.mjs +46 -1
  6. package/bin/lint-transcript.mjs +15 -3
  7. package/bin/mcp-server.mjs +1 -0
  8. package/commands/intent-driven-development.md +36 -0
  9. package/commands/roast.md +34 -0
  10. package/hooks/workflow-distill.mjs +145 -0
  11. package/lib/plugin-metadata.mjs +8 -3
  12. package/lib/version-check.mjs +115 -0
  13. package/llms.txt +1 -1
  14. package/package.json +4 -3
  15. package/plugins/beginner.json +1 -1
  16. package/plugins/continuous-improvement/.claude-plugin/marketplace.json +2 -2
  17. package/plugins/continuous-improvement/.claude-plugin/plugin.json +2 -2
  18. package/plugins/continuous-improvement/bin/mcp-server.mjs +1 -0
  19. package/plugins/continuous-improvement/commands/intent-driven-development.md +36 -0
  20. package/plugins/continuous-improvement/commands/roast.md +34 -0
  21. package/plugins/continuous-improvement/hooks/hooks.json +6 -1
  22. package/plugins/continuous-improvement/hooks/workflow-distill.mjs +145 -0
  23. package/plugins/continuous-improvement/lib/plugin-metadata.mjs +8 -3
  24. package/plugins/continuous-improvement/skills/README.md +2 -0
  25. package/plugins/continuous-improvement/skills/intent-driven-development/SKILL.md +161 -0
  26. package/plugins/continuous-improvement/skills/roast/SKILL.md +108 -0
  27. package/plugins/continuous-improvement/skills/strategic-compact/SKILL.md +12 -32
  28. package/plugins/expert.json +1 -1
  29. package/skills/README.md +1 -1
  30. package/skills/intent-driven-development.md +161 -0
  31. package/skills/roast.md +108 -0
  32. package/skills/strategic-compact.md +12 -32
@@ -0,0 +1,115 @@
1
+ // version-check.mts — Pure update-check decision core + a thin npm-registry fetch
2
+ // helper. The decision functions take no ambient I/O: the caller injects the local
3
+ // version, the fetched remote version, the cached state, and the clock, so the whole
4
+ // thing is unit-testable offline (mirrors how the goal-state / recall scorers are
5
+ // structured). The ONLY network is fetchLatestNpmVersion, which fails closed
6
+ // (returns null) on any error. No telemetry: a one-way read of the public registry.
7
+ //
8
+ // Wired into bin/install.mts at install end so the nudge only appears when the user
9
+ // explicitly invokes the CLI. See docs/plans/2026-06-25-version-check-nudge.md.
10
+ // Two-tier TTL, copied from gstack: poll often while up-to-date so a release is
11
+ // caught quickly, then back off once an upgrade is known so the nudge is not
12
+ // re-fetched on every invocation.
13
+ export const TTL_UP_TO_DATE_MS = 60 * 60 * 1000; // 60 min
14
+ export const TTL_UPGRADE_MS = 12 * 60 * 60 * 1000; // 720 min
15
+ const NPM_REGISTRY = "https://registry.npmjs.org";
16
+ /** Parse "a.b.c" (ignoring a leading v and any -prerelease/+build suffix) into a
17
+ * numeric triple. Fail closed: any non-numeric core component returns null. */
18
+ export function parseSemver(version) {
19
+ if (typeof version !== "string")
20
+ return null;
21
+ const core = version.trim().replace(/^v/, "").split(/[-+]/)[0] ?? "";
22
+ const parts = core.split(".");
23
+ if (parts.length !== 3)
24
+ return null;
25
+ const nums = parts.map((p) => (/^\d+$/.test(p) ? Number(p) : NaN));
26
+ if (nums.some((n) => !Number.isFinite(n)))
27
+ return null;
28
+ return [nums[0], nums[1], nums[2]];
29
+ }
30
+ /** Is `remote` a strictly higher release than `local`? Non-semver on either side
31
+ * fails closed to false (never nudge on garbage; never nudge a dev build that is
32
+ * ahead of or equal to the registry). */
33
+ export function isNewer(remote, local) {
34
+ const r = parseSemver(remote);
35
+ const l = parseSemver(local);
36
+ if (!r || !l)
37
+ return false;
38
+ for (let i = 0; i < 3; i += 1) {
39
+ if (r[i] > l[i])
40
+ return true;
41
+ if (r[i] < l[i])
42
+ return false;
43
+ }
44
+ return false;
45
+ }
46
+ /** Should the network fetch be skipped because the cached result is still fresh?
47
+ * Absent/NaN checkedAt fails OPEN (fetch) — a corrupt cache must not wedge the
48
+ * check off permanently. */
49
+ export function isThrottled(cache, now) {
50
+ if (!cache || typeof cache.checkedAt !== "number" || !Number.isFinite(cache.checkedAt))
51
+ return false;
52
+ const ttl = cache.status === "upgrade-available" ? TTL_UPGRADE_MS : TTL_UP_TO_DATE_MS;
53
+ return now - cache.checkedAt < ttl;
54
+ }
55
+ function buildNotice(local, remote) {
56
+ return (`continuous-improvement ${remote} is available (you have ${local}). ` +
57
+ "Update: marketplace → /plugin marketplace update continuous-improvement, " +
58
+ "or npm → npx continuous-improvement install. Silence: CLAUDE_CI_UPDATE_CHECK=off");
59
+ }
60
+ /** Re-surface a still-valid pending upgrade straight from the cache, so a throttled
61
+ * invocation does not lose the nudge. Returns null unless the cache says an upgrade
62
+ * is pending AND that cached remote is still newer than the current local. */
63
+ export function pendingNotice(cache, local) {
64
+ if (!cache || cache.status !== "upgrade-available")
65
+ return null;
66
+ if (typeof cache.remote !== "string" || !isNewer(cache.remote, local))
67
+ return null;
68
+ return buildNotice(local, cache.remote);
69
+ }
70
+ /** The pure decision from a fresh fetch. `remote === null` (fetch failed) yields
71
+ * `unknown` with no notice and no cache write, so the next invocation retries
72
+ * rather than caching a false "up-to-date". */
73
+ export function evaluateUpdateCheck(args) {
74
+ const { local, remote, now } = args;
75
+ if (remote === null || parseSemver(remote) === null) {
76
+ return { status: "unknown", notice: null, nextCache: null };
77
+ }
78
+ if (isNewer(remote, local)) {
79
+ return {
80
+ status: "upgrade-available",
81
+ notice: buildNotice(local, remote),
82
+ nextCache: { status: "upgrade-available", local, remote, checkedAt: now },
83
+ };
84
+ }
85
+ return {
86
+ status: "up-to-date",
87
+ notice: null,
88
+ nextCache: { status: "up-to-date", local, remote, checkedAt: now },
89
+ };
90
+ }
91
+ /** Fetch the `latest` dist-tag version for a package from the public npm registry.
92
+ * The only network in this module. Fails closed (returns null) on any error:
93
+ * timeout, non-2xx, malformed JSON, or a non-semver version string. fetchImpl and
94
+ * timeoutMs are injectable so callers and tests stay offline-deterministic. */
95
+ export async function fetchLatestNpmVersion(pkg, opts = {}) {
96
+ const fetchImpl = opts.fetchImpl ?? globalThis.fetch;
97
+ if (typeof fetchImpl !== "function")
98
+ return null;
99
+ try {
100
+ const res = await fetchImpl(`${NPM_REGISTRY}/${pkg}/latest`, {
101
+ headers: { Accept: "application/vnd.npm.install-v1+json" },
102
+ signal: AbortSignal.timeout(opts.timeoutMs ?? 5000),
103
+ });
104
+ if (!res.ok)
105
+ return null;
106
+ const body = (await res.json());
107
+ const version = typeof body.version === "string" ? body.version : null;
108
+ if (!version || parseSemver(version) === null)
109
+ return null;
110
+ return version;
111
+ }
112
+ catch {
113
+ return null;
114
+ }
115
+ }
package/llms.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  # continuous-improvement
2
2
 
3
- > The persistent-memory and runtime-discipline layer for Claude Code. It remembers the corrections you already gave, grounds every edit in real facts before it lands, and — through the Mulahazah engine — turns each fix into a reusable instinct, so a lesson learned once is applied automatically next time with no re-teaching. Built on the 7 Laws of AI Agent Discipline (research, plan, verify, reflect, learn) and shipped as 25 bundled skills, instinct-aware hooks, an MCP toolset for recall and reflection, and a GitHub Action transcript linter that feeds real work history back into sharper instincts.
3
+ > The persistent-memory and runtime-discipline layer for Claude Code. It remembers the corrections you already gave, grounds every edit in real facts before it lands, and — through the Mulahazah engine — turns each fix into a reusable instinct, so a lesson learned once is applied automatically next time with no re-teaching. Built on the 7 Laws of AI Agent Discipline (research, plan, verify, reflect, learn) and shipped as 27 bundled skills, instinct-aware hooks, an MCP toolset for recall and reflection, and a GitHub Action transcript linter that feeds real work history back into sharper instincts.
4
4
 
5
5
  ## What This Is
6
6
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "continuous-improvement",
3
- "version": "3.15.0",
4
- "description": "The persistent-memory and runtime-discipline layer for Claude Code. It remembers the corrections you already gave, grounds every edit in real facts before it lands, and — through the Mulahazah engine — turns each fix into a reusable instinct, so a lesson learned once is applied automatically next time with no re-teaching. Built on the 7 Laws of AI Agent Discipline (research, plan, verify, reflect, learn) and shipped as 25 bundled skills, instinct-aware hooks, an MCP toolset for recall and reflection, and a GitHub Action transcript linter that feeds real work history back into sharper instincts. Beginner: one /plugin install command. Expert: adds MCP tools and session hooks.",
3
+ "version": "3.17.0",
4
+ "description": "The persistent-memory and runtime-discipline layer for Claude Code. It remembers the corrections you already gave, grounds every edit in real facts before it lands, and — through the Mulahazah engine — turns each fix into a reusable instinct, so a lesson learned once is applied automatically next time with no re-teaching. Built on the 7 Laws of AI Agent Discipline (research, plan, verify, reflect, learn) and shipped as 27 bundled skills, instinct-aware hooks, an MCP toolset for recall and reflection, and a GitHub Action transcript linter that feeds real work history back into sharper instincts. Beginner: one /plugin install command. Expert: adds MCP tools and session hooks.",
5
5
  "keywords": [
6
6
  "claude-code",
7
7
  "claude-code-skill",
@@ -44,6 +44,7 @@
44
44
  "verify:skill-tiers": "node bin/check-skill-tiers.mjs",
45
45
  "verify:skill-law-tag": "node bin/check-skill-law-tag.mjs",
46
46
  "verify:skill-count": "node bin/check-skill-count.mjs",
47
+ "verify:skill-count-prose": "node bin/check-skill-count-prose.mjs",
47
48
  "verify:docs-substrings": "node bin/check-docs-substrings.mjs",
48
49
  "verify:everything-mirror": "node bin/check-everything-mirror.mjs",
49
50
  "verify:routing-targets": "node bin/check-routing-targets.mjs",
@@ -52,7 +53,7 @@
52
53
  "verify:scripts-citation-drift": "node bin/check-scripts-citation-drift.mjs",
53
54
  "verify:third-party-shape": "node bin/check-third-party-shape.mjs",
54
55
  "verify:tool-count": "node bin/check-tool-count.mjs",
55
- "verify:all": "npm run verify:skill-mirror && npm run verify:skill-tiers && npm run verify:skill-law-tag && npm run verify:skill-count && npm run verify:docs-substrings && npm run verify:everything-mirror && npm run verify:routing-targets && npm run verify:doc-runtime-claims && npm run verify:test-imports-only && npm run verify:scripts-citation-drift && npm run verify:third-party-shape && npm run verify:tool-count && npm run typecheck"
56
+ "verify:all": "npm run verify:skill-mirror && npm run verify:skill-tiers && npm run verify:skill-law-tag && npm run verify:skill-count && npm run verify:skill-count-prose && npm run verify:docs-substrings && npm run verify:everything-mirror && npm run verify:routing-targets && npm run verify:doc-runtime-claims && npm run verify:test-imports-only && npm run verify:scripts-citation-drift && npm run verify:third-party-shape && npm run verify:tool-count && npm run typecheck"
56
57
  },
57
58
  "files": [
58
59
  ".claude-plugin/",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "continuous-improvement",
3
- "version": "3.15.0",
3
+ "version": "3.17.0",
4
4
  "mode": "beginner",
5
5
  "description": "Beginner mode: see what your agent learned, list its instincts, and request a session reflection. Bundles three grounding skills (gateguard, tdd-workflow, verification-loop) so research, memory, tests, and verification happen by default — every edit starts from facts, not guesses.",
6
6
  "tools": [
@@ -7,8 +7,8 @@
7
7
  "plugins": [
8
8
  {
9
9
  "name": "continuous-improvement",
10
- "description": "The persistent-memory and runtime-discipline layer for Claude Code. It remembers the corrections you already gave, grounds every edit in real facts before it lands, and — through the Mulahazah engine — turns each fix into a reusable instinct, so a lesson learned once is applied automatically next time with no re-teaching. Built on the 7 Laws of AI Agent Discipline (research, plan, verify, reflect, learn) and shipped as 25 bundled skills, instinct-aware hooks, an MCP toolset for recall and reflection, and a GitHub Action transcript linter that feeds real work history back into sharper instincts.",
11
- "version": "3.15.0",
10
+ "description": "The persistent-memory and runtime-discipline layer for Claude Code. It remembers the corrections you already gave, grounds every edit in real facts before it lands, and — through the Mulahazah engine — turns each fix into a reusable instinct, so a lesson learned once is applied automatically next time with no re-teaching. Built on the 7 Laws of AI Agent Discipline (research, plan, verify, reflect, learn) and shipped as 27 bundled skills, instinct-aware hooks, an MCP toolset for recall and reflection, and a GitHub Action transcript linter that feeds real work history back into sharper instincts.",
11
+ "version": "3.17.0",
12
12
  "source": "./",
13
13
  "author": {
14
14
  "name": "naimkatiman"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "continuous-improvement",
3
- "version": "3.15.0",
4
- "description": "The persistent-memory and runtime-discipline layer for Claude Code. It remembers the corrections you already gave, grounds every edit in real facts before it lands, and — through the Mulahazah engine — turns each fix into a reusable instinct, so a lesson learned once is applied automatically next time with no re-teaching. Built on the 7 Laws of AI Agent Discipline (research, plan, verify, reflect, learn) and shipped as 25 bundled skills, instinct-aware hooks, an MCP toolset for recall and reflection, and a GitHub Action transcript linter that feeds real work history back into sharper instincts.",
3
+ "version": "3.17.0",
4
+ "description": "The persistent-memory and runtime-discipline layer for Claude Code. It remembers the corrections you already gave, grounds every edit in real facts before it lands, and — through the Mulahazah engine — turns each fix into a reusable instinct, so a lesson learned once is applied automatically next time with no re-teaching. Built on the 7 Laws of AI Agent Discipline (research, plan, verify, reflect, learn) and shipped as 27 bundled skills, instinct-aware hooks, an MCP toolset for recall and reflection, and a GitHub Action transcript linter that feeds real work history back into sharper instincts.",
5
5
  "author": {
6
6
  "name": "naimkatiman",
7
7
  "url": "https://github.com/naimkatiman"
@@ -219,6 +219,7 @@ function readDistillObservations(projectHash) {
219
219
  tool: getString(observation.tool),
220
220
  input_summary: getString(observation.input_summary),
221
221
  output_summary: getString(observation.output_summary),
222
+ event: getString(observation.event),
222
223
  }));
223
224
  }
224
225
  function detectLevel(projectHash) {
@@ -0,0 +1,36 @@
1
+ ---
2
+ name: intent-driven-development
3
+ description: "Turn an ambiguous or high-impact change into scoped, verifiable acceptance criteria (observable AC-NNN, explicit scope, named verification methods, and a [revised] protocol that forbids silently dropping a criterion) before or alongside implementation. Enforces Law 2 (Plan Is Sacred)."
4
+ argument-hint: "[the change to scope into acceptance criteria]"
5
+ ---
6
+
7
+ # /intent-driven-development
8
+
9
+ Convert an ambiguous or high-impact request into observable acceptance criteria before you build, so "done" is a fact two people would agree on and the agreed plan is held sacred (Law 2). Produce useful criteria without ceremony: inspect context first, expose only genuine ambiguity, choose verification that fits the risk.
10
+
11
+ ## Trigger phrases
12
+
13
+ - `/intent-driven-development`
14
+ - `/intent-driven-development <the change>`
15
+ - "define acceptance criteria"
16
+ - "scope this change" / "make this testable"
17
+ - "de-risk this before we build it"
18
+ - "prepare implementation requirements for another agent"
19
+
20
+ Do not trigger for trivial edits, one-line fixes, active debugging, code review, or requests whose acceptance conditions are already clear.
21
+
22
+ ## What happens
23
+
24
+ 1. **Inspect and scope.** Read the repo, docs, schemas, and tests for technical facts before asking. Capture product or business constraints only from the user or a product artifact, never inferred from code.
25
+ 2. **Choose depth.** Quick Capture (3-7 criteria, low or moderate risk) or Full Acceptance Brief (security, data, migration, cross-system, or handoff).
26
+ 3. **Write criteria.** Each `AC-NNN` names a scenario, a trigger, an expected observable result, a prohibited side effect when meaningful, a verification method, and a priority. No vague words without defined evidence.
27
+ 4. **Proceed or hand off.** Record the criteria and continue for a clear request; present blockers and wait when a change is risky. If a criterion cannot be met mid-build, mark it `[revised]`, increment the revision, and re-present only the changed criteria.
28
+
29
+ ## Skill file
30
+
31
+ Full behavior is defined in [`skills/intent-driven-development.md`](../skills/intent-driven-development.md).
32
+
33
+ ## Pairs with
34
+
35
+ - `/grill-me`: grill-me clarifies a fuzzy input; this skill turns the agreed intent into verifiable criteria.
36
+ - `/roast`: roast validates the idea, then scope the survivor into acceptance criteria.
@@ -0,0 +1,34 @@
1
+ ---
2
+ name: roast
3
+ description: "Convene a 5-persona adversarial council (Contrarian, Expansionist, Logician, Researcher, Buyer) to pressure-test an idea, then deliver one GO / RESHAPE / KILL verdict plus the cheapest 48-hour test to de-risk it. Enforces Law 1 (Research Before Executing)."
4
+ argument-hint: "[the idea to roast]"
5
+ ---
6
+
7
+ # /roast
8
+
9
+ Pressure-test an idea before you build it. Convene a council of five independent persona agents who attack the idea from every angle, then act as the Judge and return one decisive verdict — so Law 1 (Research Before Executing) is satisfied on the *idea* itself, not just the plan.
10
+
11
+ ## Trigger phrases
12
+
13
+ - `/roast`
14
+ - `/roast <the idea>`
15
+ - "roast this idea"
16
+ - "convene the council"
17
+ - "pressure-test this" / "stress-test this idea"
18
+ - "validate this business idea"
19
+ - "give me a brutal second opinion before I build this"
20
+
21
+ ## What happens
22
+
23
+ 1. **Brief.** Read the idea from the argument (if given) and ask up to 3-4 clarifying questions in one batch — the idea, the buyer + money model, your edge, your constraints. Skip the questions if the user says "just run it."
24
+ 2. **Council (parallel).** Spin up all five personas in parallel, each pasted the same brief: Contrarian (assume it fails), Expansionist (the 10x case), Logician (first-principles, no web), Researcher (web evidence + competitors), Buyer (role-play the target customer). Each returns a stance, 3-5 sharp points, the one thing you must hear, and a 1-10 score.
25
+ 3. **Verdict.** Act as the Judge: resolve the council's tension, fold in the economics lens, and return one `GO / RESHAPE / KILL` call with the biggest risk, biggest upside, money read, and — most importantly — the cheapest 48-hour test to validate the riskiest assumption before building anything.
26
+
27
+ ## Skill file
28
+
29
+ Full behavior is defined in [`skills/roast.md`](../skills/roast.md).
30
+
31
+ ## Pairs with
32
+
33
+ - `/grill-me` — roast validates the idea; grill-me then hardens the plan.
34
+ - `/proceed-with-the-recommendation` — walk the verdict's next steps under the 7 Laws.
@@ -1,5 +1,5 @@
1
1
  {
2
- "description": "Gateguard fact-forcing PreToolUse, companion-preference enforcement, observation, session lifecycle, 3-section-close discipline, goal-drift Stop gate, and UserPromptSubmit lazy-routing plus opt-in proactive recall-briefing hooks for continuous-improvement.",
2
+ "description": "Gateguard fact-forcing PreToolUse, companion-preference enforcement, observation, session lifecycle, 3-section-close discipline, goal-drift Stop gate, opt-in workflow-distill Stop nudge, and UserPromptSubmit lazy-routing plus opt-in proactive recall-briefing hooks for continuous-improvement.",
3
3
  "hooks": {
4
4
  "PreToolUse": [
5
5
  {
@@ -88,6 +88,11 @@
88
88
  "type": "command",
89
89
  "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/goal-drift-stop.mjs\"",
90
90
  "timeout": 5
91
+ },
92
+ {
93
+ "type": "command",
94
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/workflow-distill.mjs\"",
95
+ "timeout": 5
91
96
  }
92
97
  ]
93
98
  }
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env node
2
+ // workflow-distill.mts — Stop hook (opt-in, default off) that nudges the operator
3
+ // to persist a verified native Workflow run as a Mulahazah draft instinct via the
4
+ // ci_distill_from_workflow MCP tool. This is the one integration a per-turn
5
+ // orchestration primitive cannot do for itself: make the lesson of an expensive
6
+ // multi-agent run survive the run instead of evaporating when the turn ends — the
7
+ // fast-follow deferred in docs/plans/2026-06-08-workflow-instinct-bridge.md.
8
+ //
9
+ // Mode via CLAUDE_WORKFLOW_DISTILL_NUDGE: "on" | "off" (default).
10
+ // - off (default): no-op. Operators who do not use native Workflows are never
11
+ // nagged.
12
+ // - on: if the session's observation feed shows a verified Workflow run that
13
+ // has not already been nudged, print ONE stderr line suggesting
14
+ // ci_distill_from_workflow. It is an amplifier, never a gate — it cannot
15
+ // block the Stop and writes nothing to stdout.
16
+ //
17
+ // Project-hash resolution is byte-identical to bin/observe.mts and
18
+ // hooks/goal-drift-stop.mts so this hook reads the SAME observations.jsonl the
19
+ // observer writes. The "is this run verified" decision is the pure, already-tested
20
+ // workflowRunFromObservations (src/lib/skill-distill.mts), which fails closed:
21
+ // no Workflow row, unparseable meta, or no following verify-exit-0 => null => no
22
+ // nudge. Per-run dedup state lives in
23
+ // ~/.claude/instincts/<project-hash>/workflow-distill-state.json keyed by run
24
+ // name + verify command, so a run is nudged at most once. Fail-open by
25
+ // construction: any error exits 0 and never blocks. No network. 5s hook budget.
26
+ import { execFileSync } from "node:child_process";
27
+ import { createHash } from "node:crypto";
28
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
29
+ import { join } from "node:path";
30
+ import { resolveHomeDir } from "../lib/resolve-home-dir.mjs";
31
+ import { workflowRunFromObservations } from "../lib/skill-distill.mjs";
32
+ function safeJsonParse(text) {
33
+ try {
34
+ return JSON.parse(text);
35
+ }
36
+ catch {
37
+ return null;
38
+ }
39
+ }
40
+ function resolveMode() {
41
+ return (process.env.CLAUDE_WORKFLOW_DISTILL_NUDGE ?? "off").trim().toLowerCase() === "on" ? "on" : "off";
42
+ }
43
+ // Mirrors bin/observe.mts:resolveProjectRoot — the same basis the observer uses
44
+ // to bucket observations.jsonl, so the hash here resolves to the same file.
45
+ function resolveProjectRoot() {
46
+ const fromEnv = process.env.CLAUDE_PROJECT_DIR;
47
+ if (fromEnv)
48
+ return fromEnv;
49
+ try {
50
+ const root = execFileSync("git", ["rev-parse", "--show-toplevel"], {
51
+ encoding: "utf8",
52
+ stdio: ["ignore", "pipe", "ignore"],
53
+ }).trim();
54
+ if (root)
55
+ return root;
56
+ }
57
+ catch {
58
+ // not a git repo
59
+ }
60
+ return "global";
61
+ }
62
+ function projectHash(root) {
63
+ return createHash("sha256").update(root).digest("hex").slice(0, 12);
64
+ }
65
+ function readObservations(instinctsProjectDir) {
66
+ const file = join(instinctsProjectDir, "observations.jsonl");
67
+ try {
68
+ if (!existsSync(file))
69
+ return [];
70
+ const lines = readFileSync(file, "utf8")
71
+ .split("\n")
72
+ .filter((line) => line.trim().length > 0);
73
+ const out = [];
74
+ // A workflow row plus its following verify both sit near the tail; a bounded
75
+ // window keeps the 5s budget safe on a long-lived feed.
76
+ for (const line of lines.slice(-5000)) {
77
+ const row = safeJsonParse(line);
78
+ if (!row)
79
+ continue;
80
+ out.push({
81
+ ts: typeof row.ts === "string" ? row.ts : "",
82
+ session: typeof row.session === "string" ? row.session : "",
83
+ session_id: typeof row.session_id === "string" ? row.session_id : "",
84
+ tool: typeof row.tool === "string" ? row.tool : "",
85
+ input_summary: typeof row.input_summary === "string" ? row.input_summary : "",
86
+ output_summary: typeof row.output_summary === "string" ? row.output_summary : "",
87
+ });
88
+ }
89
+ return out;
90
+ }
91
+ catch {
92
+ return [];
93
+ }
94
+ }
95
+ function readNudgedKeys(instinctsProjectDir) {
96
+ const file = join(instinctsProjectDir, "workflow-distill-state.json");
97
+ try {
98
+ if (!existsSync(file))
99
+ return new Set();
100
+ const parsed = safeJsonParse(readFileSync(file, "utf8"));
101
+ const arr = parsed && Array.isArray(parsed.nudged) ? parsed.nudged : [];
102
+ return new Set(arr.filter((x) => typeof x === "string"));
103
+ }
104
+ catch {
105
+ return new Set();
106
+ }
107
+ }
108
+ function persistNudged(instinctsProjectDir, keys) {
109
+ try {
110
+ mkdirSync(instinctsProjectDir, { recursive: true });
111
+ writeFileSync(join(instinctsProjectDir, "workflow-distill-state.json"), JSON.stringify({ ts: new Date().toISOString(), nudged: [...keys] }) + "\n", "utf8");
112
+ }
113
+ catch {
114
+ // dedup persistence is best-effort; never throw
115
+ }
116
+ }
117
+ function main() {
118
+ if (resolveMode() === "off")
119
+ return;
120
+ const home = resolveHomeDir();
121
+ if (!home)
122
+ return;
123
+ const projectRoot = resolveProjectRoot();
124
+ const instinctsProjectDir = join(home, ".claude", "instincts", projectHash(projectRoot));
125
+ const observations = readObservations(instinctsProjectDir);
126
+ if (observations.length === 0)
127
+ return;
128
+ const run = workflowRunFromObservations(observations);
129
+ if (!run)
130
+ return; // fail closed: no verified run, nothing to nudge
131
+ const runKey = `${run.name}::${run.verifyCommand}`;
132
+ const nudged = readNudgedKeys(instinctsProjectDir);
133
+ if (nudged.has(runKey))
134
+ return; // already nudged this run — stay quiet
135
+ process.stderr.write(`[continuous-improvement] workflow-distill: verified workflow run "${run.name}" detected — ` +
136
+ "run the ci_distill_from_workflow MCP tool to persist it as a Mulahazah draft instinct.\n");
137
+ nudged.add(runKey);
138
+ persistNudged(instinctsProjectDir, nudged);
139
+ }
140
+ try {
141
+ main();
142
+ }
143
+ catch {
144
+ // fail open — never block the session due to a hook bug
145
+ }
@@ -26,7 +26,7 @@ const KEYWORDS = [
26
26
  "transcript-linter",
27
27
  ];
28
28
  const CLAUDE_PLUGIN_CATEGORY = "productivity";
29
- const SHARED_PLUGIN_DESCRIPTION = "The persistent-memory and runtime-discipline layer for Claude Code. It remembers the corrections you already gave, grounds every edit in real facts before it lands, and — through the Mulahazah engine — turns each fix into a reusable instinct, so a lesson learned once is applied automatically next time with no re-teaching. Built on the 7 Laws of AI Agent Discipline (research, plan, verify, reflect, learn) and shipped as 25 bundled skills, instinct-aware hooks, an MCP toolset for recall and reflection, and a GitHub Action transcript linter that feeds real work history back into sharper instincts.";
29
+ const SHARED_PLUGIN_DESCRIPTION = "The persistent-memory and runtime-discipline layer for Claude Code. It remembers the corrections you already gave, grounds every edit in real facts before it lands, and — through the Mulahazah engine — turns each fix into a reusable instinct, so a lesson learned once is applied automatically next time with no re-teaching. Built on the 7 Laws of AI Agent Discipline (research, plan, verify, reflect, learn) and shipped as 27 bundled skills, instinct-aware hooks, an MCP toolset for recall and reflection, and a GitHub Action transcript linter that feeds real work history back into sharper instincts.";
30
30
  // Four vendored upstream companions registered alongside the CI plugin.
31
31
  // Each entry points at a pinned-SHA snapshot under third-party/<name>/.
32
32
  // See third-party/MANIFEST.md for refresh recipes and per-snapshot
@@ -492,6 +492,11 @@ export function getPluginHooksConfig() {
492
492
  command: "node \"${CLAUDE_PLUGIN_ROOT}/hooks/goal-drift-stop.mjs\"",
493
493
  timeout: 5,
494
494
  };
495
+ const workflowDistillCommand = {
496
+ type: "command",
497
+ command: "node \"${CLAUDE_PLUGIN_ROOT}/hooks/workflow-distill.mjs\"",
498
+ timeout: 5,
499
+ };
495
500
  const routePromptCommand = {
496
501
  type: "command",
497
502
  command: "node \"${CLAUDE_PLUGIN_ROOT}/hooks/route-prompt.mjs\"",
@@ -503,7 +508,7 @@ export function getPluginHooksConfig() {
503
508
  timeout: 5,
504
509
  };
505
510
  return {
506
- description: "Gateguard fact-forcing PreToolUse, companion-preference enforcement, observation, session lifecycle, 3-section-close discipline, goal-drift Stop gate, and UserPromptSubmit lazy-routing plus opt-in proactive recall-briefing hooks for continuous-improvement.",
511
+ description: "Gateguard fact-forcing PreToolUse, companion-preference enforcement, observation, session lifecycle, 3-section-close discipline, goal-drift Stop gate, opt-in workflow-distill Stop nudge, and UserPromptSubmit lazy-routing plus opt-in proactive recall-briefing hooks for continuous-improvement.",
507
512
  hooks: {
508
513
  // gateguard runs FIRST on PreToolUse so its block decision short-circuits
509
514
  // before companion-preference sees the call. companion-preference runs
@@ -527,7 +532,7 @@ export function getPluginHooksConfig() {
527
532
  UserPromptSubmit: [{ hooks: [routePromptCommand, recallBriefingCommand] }],
528
533
  SessionStart: [{ hooks: [sessionCommand] }],
529
534
  SessionEnd: [{ hooks: [sessionCommand] }],
530
- Stop: [{ hooks: [threeSectionCloseCommand, goalDriftStopCommand] }],
535
+ Stop: [{ hooks: [threeSectionCloseCommand, goalDriftStopCommand, workflowDistillCommand] }],
531
536
  },
532
537
  };
533
538
  }
@@ -29,8 +29,10 @@ skill set on disk.
29
29
  - `grill-me` — Enforces Law 1 (Research Before Executing) of the 7 Laws of AI Agent Discipline. Interview the user relentlessly about a plan or design until shared understanding is reached, resolving every branch of the decision tree before any code is written. Ported from mattpocock/skills under MIT.
30
30
  - `grill-with-docs` — Enforces Law 1 (Research Before Executing) and Law 7 (Learn From Every Session) of the 7 Laws of AI Agent Discipline. Grilling session that challenges your plan against the existing domain model, sharpens terminology, and updates CONTEXT.md + ADRs inline as decisions crystallise. Ported from mattpocock/skills under MIT.
31
31
  - `handoff` — Enforces Law 5 (Reflect After Every Session) of the 7 Laws of AI Agent Discipline. Compact the current conversation into a handoff document for another agent to pick up. Ported from mattpocock/skills under MIT.
32
+ - `intent-driven-development` — Enforces Law 2 (Plan Is Sacred) of the 7 Laws of AI Agent Discipline. Turn an ambiguous or high-impact change into scoped, verifiable acceptance criteria (observable AC-NNN, explicit in/out scope, named verification methods, and a [revised] protocol that forbids silently dropping a criterion) before or alongside implementation, so the plan that gets built is the plan that was agreed, not an invented default. Use when clarifying a feature, defining acceptance criteria, de-risking a security/data/migration/integration change, or preparing implementation requirements for another agent. Do not trigger for trivial edits, straightforward fixes, active debugging, or code review.
32
33
  - `reconcile` — Enforces Law 1 (Research Before Executing) of the 7 Laws of AI Agent Discipline. Establishes git ground truth — branch, status, stashes, worktrees, ahead/behind — before any mutation, halts on protected or destructive operations, and verifies a push actually landed instead of assuming it did.
33
34
  - `recovery-classification` — Enforces Law 4 (Verify Before Reporting) of the 7 Laws of AI Agent Discipline. After any failure in the verification ladder or auto-loop, classify the failure class before retrying — provider, tool-schema, deterministic-policy, git, worktree, runtime — so retry-vs-pause-vs-self-heal-vs-stop is an intentional decision, not a generic 'try again'.
35
+ - `roast` — Enforces Law 1 (Research Before Executing) of the 7 Laws of AI Agent Discipline. Convene a 5-persona adversarial council (Contrarian, Expansionist, Logician, Researcher, Buyer) that attacks an idea from every angle, then a Judge returns one GO / RESHAPE / KILL verdict plus the cheapest 48-hour test to de-risk it — so you pressure-test an idea before sinking time into building the wrong thing.
34
36
  - `safety-guard` — Enforces Law 3 (One Thing at a Time) of the 7 Laws of AI Agent Discipline by scoping edits to a directory and blocking destructive shell commands. Use this skill to prevent destructive operations when working on production systems or running agents autonomously.
35
37
  - `skill-distillation` — Enforces Law 7 (Learn From Every Session) of the 7 Laws of AI Agent Discipline. Distills repeated successful tool sequences into reusable draft instincts, so a pattern that worked three times becomes a captured recipe instead of being re-derived from scratch every session.
36
38
  - `state-reconciliation` — Enforces Law 4 (Verify Before Reporting) of the 7 Laws of AI Agent Discipline. Pre-dispatch invariant: reconcile DB-vs-disk-vs-memory state before any unit runs, so a stale flag, missing artifact, or out-of-sync row never re-dispatches a unit that already completed or never started.