From kmgraph
**Purpose:** Detect implicit mid-session behavioral corrections and preferences — phrases the user issues without asking to "capture" anything — and offer to write them to the authoritative rule files (`knowledge/rules.md` or `~/.kmgraph/me.md`), rather than only the MEMORY.md feedback system.
npx claudepluginhub technomensch/knowledge-graph --plugin kmgraphThis skill uses the workspace's default tool permissions.
**Purpose:** Detect implicit mid-session behavioral corrections and preferences — phrases the user issues without asking to "capture" anything — and offer to write them to the authoritative rule files (`knowledge/rules.md` or `~/.kmgraph/me.md`), rather than only the MEMORY.md feedback system.
Fetches up-to-date documentation from Context7 for libraries and frameworks like React, Next.js, Prisma. Use for setup questions, API references, and code examples.
Retrieves current documentation, API references, and code examples for libraries, frameworks, SDKs, CLIs, and services via Context7 CLI. Ideal for API syntax, configs, migrations, and setup queries.
Uses ctx7 CLI to fetch current library docs, manage AI coding skills (install/search/generate), and configure Context7 MCP for AI editors.
Purpose: Detect implicit mid-session behavioral corrections and preferences — phrases the user issues without asking to "capture" anything — and offer to write them to the authoritative rule files (knowledge/rules.md or ~/.kmgraph/me.md), rather than only the MEMORY.md feedback system.
High-confidence — fire immediately:
Medium-confidence — fire only if Claude just performed the action being corrected in the previous turn:
Ephemeral guards — phrases with these scope-limiting words indicate session-only instructions, NOT rules:
Observation/complaint guards — past-tense descriptions of what happened are NOT directives:
Clarification guards — corrections to a misunderstanding in this turn are NOT rules:
Code-correction guards — corrections about code in a diff are NOT behavioral rules:
any in TypeScript" (about code content, not Claude's process)const not var" (linting preference, not behavioral)In-context choice guards — selecting between options presented by Claude is NOT a rule:
Other skill triggers — yield to these:
capture-router skill handleslesson-capture skill handlesadr-guide skill handlesRun this detection block once per rules-capture invocation, just before Scope Classification. Detection result is a conceptual struct: {platform: string, agents_present: bool}.
platform is one of: claude-code, gemini, cursor, windsurf, copilot, zed, claude-code-web, unknown.
agents_present is true when AGENTS.md (or a recognized case variant) is found at project root, regardless of which platform is detected.
Walk up from cwd until a .git/ directory is found. If none found, use cwd as root. All paths below are relative to this root.
Use Glob to look for AGENTS.md, agents.md, Agents.md at project root.
AGENTS.md is found: set agents_present = true.agents.md or Agents.md) is found: set agents_present = true AND record a warning: "Found agents.md — the AGENTS.md spec requires uppercase AGENTS.md. Rename to activate for all tool adopters."agents_present = false.Priority 1 — Claude Code: Check whether a .claude/ directory exists at project root (Glob: .claude/).
platform = "claude-code". Config target: CLAUDE.md.Priority 2 — Gemini: Check whether GEMINI.md or AGENT.md exists at project root. Also check wrong-case variants gemini.md, Gemini.md, agent.md, Agent.md.
platform = "gemini". Config target: GEMINI.md.platform = "gemini" AND record warning: "Found gemini.md (or agent.md) — Gemini CLI requires uppercase GEMINI.md. Rename to activate."Priority 3 — Cursor: Check whether a .cursor/ directory exists at project root (Glob: .cursor/).
platform = "cursor". Config target: .cursor/rules/ (fallback: .cursorrules).Priority 4 — Windsurf: Check whether .windsurfrules file exists at project root. Use [ -f "$root/.windsurfrules" ] (not -e) — if .windsurfrules is a directory, Windsurf is NOT detected.
platform = "windsurf". Config target: .windsurfrules.Priority 5 — GitHub Copilot: Check whether .github/copilot-instructions.md exists at project root (Glob: .github/copilot-instructions.md).
platform = "copilot". Config target: .github/copilot-instructions.md.Priority 6 — Zed: Check whether a .zed/ directory OR a .rules file exists at project root. For .rules, use [ -f "$root/.rules" ] — if .rules is a directory, Zed is NOT detected via that indicator.
platform = "zed". Config target: .rules.Priority 7 — AGENTS.md only (no other native indicator matched): agents_present was set in Step 2. Platform is not set by this priority level — it contributes only to the agents_present flag. platform is not assigned at this step — leave it at its current unset value and continue to Priority 8.
Priority 8 — Claude Code (web / IDE without CLI): Check whether CLAUDE.md exists at project root with no .claude/ directory (already confirmed absent from priority 1). Also check wrong-case variants claude.md, Claude.md.
CLAUDE.md found: platform = "claude-code-web". Config target: CLAUDE.md.platform = "claude-code-web" AND record warning: "Found claude.md — Claude Code requires uppercase CLAUDE.md. Rename to activate."Priority 9 — Unknown: No indicator matched in priorities 1–8.
platform = "unknown". Route to knowledge/rules.md with a note (see Scope Classification)..claude/ + AGENTS.md): This is expected layering. Keep the native platform result; set agents_present = true. Do NOT ask the user.GEMINI.md + .windsurfrules both present): Genuine ambiguity — ask the user: "I found both GEMINI.md and .windsurfrules. Which platform should I write this rule to?" Then use the user's answer as the detected platform.Before presenting routing targets to the user, check whether the top two candidate target files resolve to the same inode using realpath -e:
realpath -e "$root/CLAUDE.md"
realpath -e "$root/AGENTS.md"
realpath -e returns an error for either path (dangling symlink, circular chain, permission denied): treat that file as absent for dedup purposes only, and log: "Found broken symlink at <path> — treating as absent."If any wrong-case warning was recorded in Steps 2–3, append it to the routing suggestion shown in the Execution Flow section. Example:
Want me to make this a rule? → CLAUDE.md § Platform Preferences (Claude Code)
⚠️ Found "claude.md" — Claude Code requires the filename to be "CLAUDE.md" (uppercase).
The file is not loaded by Claude Code. Rename it to activate.
Still route the rule to the correct target (the user's intent is clear; the rename is their fix).
After completing Steps 1–6, the detection result {platform, agents_present} is available for use in Scope Classification and Execution Flow below. Detection is not cached across invocations — LLM context has no persistent state between calls.
After trigger fires, classify using two axes:
Axis 1 — Scope: project vs personal
Axis 2 — Type: rule vs me
Combined into four targets:
| Scope | Type | → Target | Committed? |
|---|---|---|---|
| Project | Rule | knowledge/rules.md | Yes (team-wide) |
| Project | Me | knowledge/me.md | No (gitignored, user-specific) |
| Personal | Rule | ~/.kmgraph/rules.md | Personal KG |
| Personal | Me | ~/.kmgraph/me.md | Personal KG (gitignored) |
Signal examples per target:
knowledge/rules.md: "always run npm run build before PR", "never force-push", "from now on identify model per phase" — team processknowledge/me.md: "in this project, I prefer to see diffs before you push", "remind me to check the hook after ECC installs" — personal workflow for this project~/.kmgraph/rules.md: "don't use the term 'update' for files that need to be created" — cross-project process rule~/.kmgraph/me.md: "no em dashes in any written content", "less technical jargon in confirmations" — identity/style across all projectsIf both axes are ambiguous: ask one question — "Is this a rule for the whole team on this project, just for you on this project, or for all your projects?"
Axis 3 — Platform-specificity: platform-specific vs universal
A rule is platform-specific if it references a named tool, API, or command unavailable on at least one other platform.
Pass 1 — Hard signals (auto-classify as platform-specific):
Glob, Grep, Read, Edit, Write, Bash, Agent, WebFetch, ctx_batch_execute, ctx_search, MCP, slash command, hook, CLAUDE.mdGemini, gemini, GEMINI.md, AGENT.md, activate_skillCursor, .cursorrules, .cursor/rulesWindsurf, Cascade, .windsurfrulesCopilot, copilot-instructions, @workspaceZed, .zed/, .rulesPass 2 — Soft signals (ask one clarifying question before routing):
Universal (no platform signal — route to knowledge/rules.md as before):
If lesson-capture and rules-capture would both fire on the same turn (e.g., "figured it out — and from now on always invalidate on write"):
lesson-capture handles the bug-solved portionrules-capture handles the behavioral directive portionWithout asking the user anything, classify scope and draft a one-line preview of the rule:
CLAUDE.md)platform = unknown: suggest knowledge/rules.md with a platform-rule shortcutAppend a single suggestion line to the end of your normal reply (do NOT replace the reply).
Format (shown conditionally based on detection results):
Want me to make this a rule? → {suggested_target} ({scope label})
"{preview of rule as Always/Never/preference statement}"
(platform / agents / yes / project-me / personal-rule / personal-me / no)
When platform = unknown and rule is platform-specific, replace platform with platform-rule in the shortcut list.
Shortcut visibility rules:
platform shortcut: shown ONLY when platform ≠ unknown AND rule is platform-specificplatform-rule shortcut: shown ONLY when platform = unknown AND rule is platform-specific (in place of platform)agents shortcut: shown ONLY when agents_present = trueFull shortcut reference:
platform — write to the detected platform's native config file (e.g., CLAUDE.md, GEMINI.md, .windsurfrules)agents — write to AGENTS.mdplatform-rule — shown instead of platform when platform = unknown and rule is platform-specific; prompts user: "Which platform file should I write to?" then routes accordinglyyes — accept suggested target as-isproject-me → knowledge/me.mdpersonal-rule → ~/.kmgraph/rules.mdpersonal-me → ~/.kmgraph/me.mdno — drop, do not re-prompt this sessionExample — platform-specific rule detected in Claude Code with AGENTS.md present:
Want me to make this a rule? → CLAUDE.md § Platform Preferences (platform, Claude Code)
"Always use Glob for file search, not find."
(platform / agents / yes / project-me / personal-rule / personal-me / no)
Example — universal rule (no platform signal, no AGENTS.md):
Want me to make this a rule? → knowledge/rules.md (project, team)
"Always run tests before committing."
(yes / project-me / personal-rule / personal-me / no)
(platform and agents shortcuts omitted — not applicable.)
Example — platform-specific rule with platform=unknown fallback:
Want me to make this a rule? → knowledge/rules.md (universal — platform unknown)
"Always use Glob for file search, not find."
(platform-rule / yes / project-me / personal-rule / personal-me / no)
(platform-rule shortcut asks "Which platform file should I write to?" then routes accordingly.)
Example — personal style rule:
Want me to make this a rule? → ~/.kmgraph/me.md (personal style)
"Avoid technical jargon in user-facing confirmation messages."
(yes / project-me / personal-rule / personal-me / no)
rules-capture-agent with structured payload (see below)CLAUDE.md), dispatch to agentAGENTS.md, dispatch to agentknowledge/me.md, dispatch to agent~/.kmgraph/rules.md, dispatch to agent~/.kmgraph/me.md, dispatch to agentWhen dispatching to rules-capture-agent, pass:
context:
rule_preview: "Always open the plan file in the editor immediately after writing it."
target_file: "knowledge/rules.md" # exact path — one of:
# knowledge/rules.md
# knowledge/me.md
# ~/.kmgraph/rules.md
# ~/.kmgraph/me.md
# CLAUDE.md, GEMINI.md, .windsurfrules, etc. (platform-specific)
# AGENTS.md
scope: "project-rule" # one of: project-rule | project-me | personal-rule | personal-me
# | platform-specific | agents
source_quote: "[exact phrase user said that triggered this]"
session_context: "[1-2 sentence summary of what was happening when this correction arose]"
platform: "claude-code" # from detection result; omit field entirely if platform = unknown
agents_present: true # from detection result; always include
This skill does NOT conflict with:
capture-router — fires on explicit "capture/save/remember that"; rules-capture fires on implicit behavioral directives without capture vocabularylesson-capture — fires on bugs solved/patterns learned; rules-capture fires on process/behavioral directives; both may fire on the same turn (see Conflict Priority Rule above)adr-guide — fires on architecture decisions with trade-off rationaledoc-update-router — fires on "update docs" requests