cursor-kg

cursor-kg is a cursor rule for Cursor from kipill/KPKnowledgeGraph. It costs 759 tokens per session, scanned A, original, Apache-2.0.

Rules for using a project's knowledge graph before making larger code changes. A knowledge graph is an index of connected notes about code, systems, and known problems.

In plain words
What is it for?
They define when to query, inspect, update, or verify graph entries, and when to send feedback about entries that were actually used.
Why use it?
They help locate existing code knowledge, reuse possibilities, and known pitfalls before editing unfamiliar or cross-module systems.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc).

Good fit They define when to query, inspect, update, or verify graph entries, and when to send feedback about entries that were actually used.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/kipill/kpknowledgegraph/cursor-kg
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/kipill/KPKnowledgeGraph

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for cursor-kg

README.md
[![agentmods](https://agentmods.dev/badge/rules/kipill/kpknowledgegraph/cursor-kg/github.svg)](https://agentmods.dev/rules/kipill/kpknowledgegraph/cursor-kg)
Your own site
<a href="https://agentmods.dev/rules/kipill/kpknowledgegraph/cursor-kg"><img src="https://agentmods.dev/badge/rules/kipill/kpknowledgegraph/cursor-kg/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for cursor-kg

Your own site · 80×15
<a href="https://agentmods.dev/rules/kipill/kpknowledgegraph/cursor-kg"><img src="https://agentmods.dev/badge/rules/kipill/kpknowledgegraph/cursor-kg.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 759 This file is loaded in full into every session.
When invoked 759 The same file — it is already loaded in full.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00759 $0.00759
Opus 5.5 $0.00304 $0.00304
Sonnet 5.5 $0.00152 $0.00152
Haiku 4.5 $0.00076 $0.00076

Measured 2mo ago against content hash 4cc5e976f5c7, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

cursor-kg scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

templates/cursor-kg.mdc · 46 lines

What it actually says

知识图谱(kg)使用约定

本项目装有 KPKnowledgeGraph——一个「先查图谱再读代码」的成长型知识索引。 图谱数据在 .claude/kg/,唯一出入口是 kg MCP 工具(server 名 kg)。

何时先查图谱(满足任一,动代码前)

  • 新功能开发:「加一个 X」「实现 Y」
  • 跨模块改动:涉及联动 / 同步 / 触发 / 跨服 / 通知
  • 不熟悉的系统名,或重构 / 迁移某系统

小改动(改单个方法 / 调数值 / 加 log)、bug 排查、性能调优、纯问答 → 跳过。

怎么查

  1. kg_query(query="关键词") 直接搜——一次返回代码路径 / 踩坑 / 出边入边。
  2. 无命中或可疑时 kg_catalog() 拿全量轻量目录,用语义判断哪些 entry 相关, 再 kg_get_entry(entry_id=...) 取详情。字面无命中 ≠ 图谱没有。
  3. 造新行为的需求(「加个能做 Y 的功能」),先 kg_scout_reuse(requirement=...) 做复用分诊:是配现成能力还是真要开发——转述给用户 + 给选项,等人拍板, 绝不自行采纳推荐就写代码。

写图谱(⚠ Cursor 无 hook 拦截,靠本约定自律)

  • 禁止直接 Edit / Write graph*.json / reverse_index.json / *.jsonl—— 它们只能经 kg MCP 写工具(自带 schema 校验 + changelog + 反向索引重建)。 绕过会破坏图谱一致性,且丢失 changelog。
  • entries/*.md 深度文档可直接编辑,不受限。
  • 写工具:kg_add_entry / kg_update_entry / kg_add_relation / kg_add_pitfall / kg_verify_edge / kg_add_capability_catalog / kg_add_capability_members。 每个写操作的 reason 参数要写清「哪个任务 / 发现了什么」。

任务完成后

  • 对实际用过的每个 entry 调 kg_feedback(entry_id, accurate, note)(遥测,不改图谱, 无需问用户):路径直达 / 联动正确 → accurate=true;漂移 / 误导 → false 并写明。
  • 发现新踩坑 / 验证了 draft 边 / 新增了系统 → 建议用户更新图谱(不自动改), 同意后走对应 MCP 写工具。
  • 图谱路径和实际代码对不上时:代码是 source of truth,顺手 kg_update_entry 修正 (会强校验新路径真实存在)。

MCP 不可用时

查询可退化为直接 Read .claude/kg/graph*.json;写操作不许退化为直接编辑文件, 报告用户 MCP 异常。

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2mo ago First seen · 46 lines · 759 tokens per session scan A 4cc5e976f5c7

Subscribe to this mod's changes

cursor-kg is a cursor rule published in the GitHub repository kipill/KPKnowledgeGraph (9 stars, last pushed 3mo ago), licensed Apache-2.0. It adds 759 tokens to every session, about $0.0030 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.