agent-knowledge-cli 0.1.2__py3-none-any.whl

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 (88) hide show
  1. agent_knowledge/__init__.py +3 -0
  2. agent_knowledge/__main__.py +3 -0
  3. agent_knowledge/assets/__init__.py +0 -0
  4. agent_knowledge/assets/claude/global.md +44 -0
  5. agent_knowledge/assets/claude/project-template.md +46 -0
  6. agent_knowledge/assets/claude/scripts/install.sh +85 -0
  7. agent_knowledge/assets/commands/doctor.md +21 -0
  8. agent_knowledge/assets/commands/global-knowledge-sync.md +27 -0
  9. agent_knowledge/assets/commands/graphify-sync.md +26 -0
  10. agent_knowledge/assets/commands/knowledge-sync.md +26 -0
  11. agent_knowledge/assets/commands/ship.md +29 -0
  12. agent_knowledge/assets/rules/generate-architecture-doc.mdc +87 -0
  13. agent_knowledge/assets/rules/history-backfill.mdc +67 -0
  14. agent_knowledge/assets/rules/memory-bootstrap.mdc +53 -0
  15. agent_knowledge/assets/rules/memory-writeback.mdc +90 -0
  16. agent_knowledge/assets/rules/shared-memory.mdc +102 -0
  17. agent_knowledge/assets/rules/workflow-orchestration.mdc +93 -0
  18. agent_knowledge/assets/rules-global/action-first.mdc +26 -0
  19. agent_knowledge/assets/rules-global/no-icons-emojis.mdc +16 -0
  20. agent_knowledge/assets/rules-global/no-unsolicited-docs.mdc +20 -0
  21. agent_knowledge/assets/scripts/bootstrap-memory-tree.sh +389 -0
  22. agent_knowledge/assets/scripts/compact-memory.sh +191 -0
  23. agent_knowledge/assets/scripts/doctor.sh +137 -0
  24. agent_knowledge/assets/scripts/global-knowledge-sync.sh +372 -0
  25. agent_knowledge/assets/scripts/graphify-sync.sh +397 -0
  26. agent_knowledge/assets/scripts/import-agent-history.sh +706 -0
  27. agent_knowledge/assets/scripts/install-project-links.sh +258 -0
  28. agent_knowledge/assets/scripts/lib/knowledge-common.sh +875 -0
  29. agent_knowledge/assets/scripts/measure-token-savings.py +540 -0
  30. agent_knowledge/assets/scripts/ship.sh +256 -0
  31. agent_knowledge/assets/scripts/update-knowledge.sh +341 -0
  32. agent_knowledge/assets/scripts/validate-knowledge.sh +265 -0
  33. agent_knowledge/assets/skills/decision-recording/SKILL.md +124 -0
  34. agent_knowledge/assets/skills/history-backfill/SKILL.md +115 -0
  35. agent_knowledge/assets/skills/memory-compaction/SKILL.md +115 -0
  36. agent_knowledge/assets/skills/memory-management/SKILL.md +134 -0
  37. agent_knowledge/assets/skills/project-ontology-bootstrap/SKILL.md +173 -0
  38. agent_knowledge/assets/skills/session-management/SKILL.md +116 -0
  39. agent_knowledge/assets/skills-cursor/create-rule/SKILL.md +164 -0
  40. agent_knowledge/assets/skills-cursor/create-skill/SKILL.md +498 -0
  41. agent_knowledge/assets/skills-cursor/create-subagent/SKILL.md +225 -0
  42. agent_knowledge/assets/skills-cursor/migrate-to-skills/SKILL.md +134 -0
  43. agent_knowledge/assets/skills-cursor/shell/SKILL.md +24 -0
  44. agent_knowledge/assets/skills-cursor/update-cursor-settings/SKILL.md +122 -0
  45. agent_knowledge/assets/templates/dashboards/project-overview.template.md +24 -0
  46. agent_knowledge/assets/templates/dashboards/session-rollup.template.md +23 -0
  47. agent_knowledge/assets/templates/hooks/hooks.json.template +11 -0
  48. agent_knowledge/assets/templates/integrations/claude/CLAUDE.md +7 -0
  49. agent_knowledge/assets/templates/integrations/codex/AGENTS.md +7 -0
  50. agent_knowledge/assets/templates/integrations/cursor/agent-knowledge.mdc +11 -0
  51. agent_knowledge/assets/templates/integrations/cursor/hooks.json +11 -0
  52. agent_knowledge/assets/templates/memory/MEMORY.root.template.md +36 -0
  53. agent_knowledge/assets/templates/memory/branch.template.md +33 -0
  54. agent_knowledge/assets/templates/memory/decision.template.md +33 -0
  55. agent_knowledge/assets/templates/memory/profile.hybrid.yaml +16 -0
  56. agent_knowledge/assets/templates/memory/profile.ml-platform.yaml +18 -0
  57. agent_knowledge/assets/templates/memory/profile.robotics.yaml +19 -0
  58. agent_knowledge/assets/templates/memory/profile.web-app.yaml +16 -0
  59. agent_knowledge/assets/templates/portfolio/.obsidian/README.md +21 -0
  60. agent_knowledge/assets/templates/portfolio/.obsidian/app.json +5 -0
  61. agent_knowledge/assets/templates/portfolio/.obsidian/core-plugins.json +7 -0
  62. agent_knowledge/assets/templates/project/.agent-project.yaml +36 -0
  63. agent_knowledge/assets/templates/project/.agentknowledgeignore +10 -0
  64. agent_knowledge/assets/templates/project/AGENTS.md +87 -0
  65. agent_knowledge/assets/templates/project/agent-knowledge/.obsidian/README.md +23 -0
  66. agent_knowledge/assets/templates/project/agent-knowledge/.obsidian/app.json +5 -0
  67. agent_knowledge/assets/templates/project/agent-knowledge/.obsidian/core-plugins.json +7 -0
  68. agent_knowledge/assets/templates/project/agent-knowledge/Evidence/README.md +34 -0
  69. agent_knowledge/assets/templates/project/agent-knowledge/Evidence/imports/README.md +29 -0
  70. agent_knowledge/assets/templates/project/agent-knowledge/Evidence/raw/README.md +25 -0
  71. agent_knowledge/assets/templates/project/agent-knowledge/Memory/MEMORY.md +37 -0
  72. agent_knowledge/assets/templates/project/agent-knowledge/Memory/decisions/decisions.md +31 -0
  73. agent_knowledge/assets/templates/project/agent-knowledge/Outputs/README.md +24 -0
  74. agent_knowledge/assets/templates/project/agent-knowledge/STATUS.md +43 -0
  75. agent_knowledge/assets/templates/project/agent-knowledge/Sessions/README.md +21 -0
  76. agent_knowledge/assets/templates/project/agent-knowledge/Templates/README.md +19 -0
  77. agent_knowledge/assets/templates/project/gitignore.agent-knowledge +13 -0
  78. agent_knowledge/cli.py +457 -0
  79. agent_knowledge/runtime/__init__.py +0 -0
  80. agent_knowledge/runtime/integrations.py +154 -0
  81. agent_knowledge/runtime/paths.py +46 -0
  82. agent_knowledge/runtime/shell.py +22 -0
  83. agent_knowledge/runtime/sync.py +255 -0
  84. agent_knowledge_cli-0.1.2.dist-info/METADATA +155 -0
  85. agent_knowledge_cli-0.1.2.dist-info/RECORD +88 -0
  86. agent_knowledge_cli-0.1.2.dist-info/WHEEL +4 -0
  87. agent_knowledge_cli-0.1.2.dist-info/entry_points.txt +2 -0
  88. agent_knowledge_cli-0.1.2.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,134 @@
1
+ ---
2
+ name: memory-management
3
+ description: Read on session start. Manages adaptive durable memory across conversations. Use when reading or writing curated memory under agent-knowledge/Memory/.
4
+ ---
5
+
6
+ # Memory Management
7
+
8
+ Manages the adaptive project memory tree. Read this skill at session start.
9
+
10
+ The memory directory path is provided by the session-start hook
11
+ (e.g., `~/.cursor/projects/<project-id>/memory/MEMORY.md`).
12
+ For project-shared memory, the canonical repo entrypoint is `./agent-knowledge`.
13
+ Durable curated memory lives at `agent-knowledge/Memory/MEMORY.md`.
14
+
15
+ ---
16
+
17
+ ## Tree structure
18
+
19
+ ```text
20
+ agent-knowledge/
21
+ Memory/
22
+ MEMORY.md <- root memory note -- always loaded, keep it short
23
+ <topic>.md <- flat branch note (no subtopics needed)
24
+ <topic>/
25
+ <topic>.md <- branch entry note (same name as folder)
26
+ <subtopic>.md <- leaf notes beside the entry
27
+ decisions/
28
+ decisions.md <- decision log, newest first
29
+ YYYY-MM-DD-slug.md
30
+ Evidence/
31
+ raw/
32
+ imports/
33
+ Sessions/ <- milestone-oriented temporary state
34
+ Outputs/
35
+ Dashboards/
36
+ STATUS.md
37
+ ```
38
+
39
+ ### Branch convention
40
+
41
+ - **One branch = one functional domain**. Do not lump unrelated subsystems together.
42
+ - **Folder name = ontology node**. The folder is the topic.
43
+ - **Same-name entry note** (`<topic>/<topic>.md`) = summary and routing for the branch.
44
+ - **Flat note** (`<topic>.md`) when there are no subtopics yet.
45
+ - **Promote to folder** only when the topic grows subtopics.
46
+ - **Keep each note under ~150 lines**. Split if bigger.
47
+ - **Link related notes** to each other with relative markdown links.
48
+ - **Use the project's own terminology** for branch names, not generic templates.
49
+ - **Do not use generic names** like "architecture" or "conventions" to group unrelated content.
50
+ Instead, use the project's own domain names (e.g., perception, navigation, localization).
51
+
52
+ Evidence (`agent-knowledge/Evidence/raw/` and `agent-knowledge/Evidence/imports/`) is separate from curated memory (`agent-knowledge/Memory/`).
53
+ Never copy raw evidence into memory. Distill only stable, verified facts.
54
+ Generated structural outputs belong in `Evidence/` or `Outputs/` first.
55
+ Only curated notes under `Memory/` are durable project knowledge.
56
+
57
+ ---
58
+
59
+ ## Durable note requirements
60
+
61
+ Every durable memory note must have YAML frontmatter.
62
+
63
+ Branch notes use these sections:
64
+
65
+ | Section | Content | Updated when |
66
+ |---------|---------|--------------|
67
+ | **Purpose** | One sentence: what this area covers | At creation; rarely changes |
68
+ | **Current State** | Verified facts about what is true now | Every writeback |
69
+ | **Recent Changes** | Rolling log, YYYY-MM-DD format, pruned after ~4 weeks | After meaningful changes |
70
+ | **Decisions** | Links to `decisions/YYYY-MM-DD-slug.md` | When a decision is recorded |
71
+ | **Open Questions** | Unresolved items for future sessions | When identified; removed when resolved |
72
+
73
+ Use markdown links for portability. Avoid wiki-links and tool-specific metadata.
74
+
75
+ ---
76
+
77
+ ## Reading the tree
78
+
79
+ 1. `Memory/MEMORY.md` loads automatically first.
80
+ 2. Identify which branch notes the task touches from the Branches section.
81
+ 3. Read only the relevant branch entry notes -- keep context lean.
82
+ 4. For branches with folders, read subtopic notes only if the specific detail is needed.
83
+ 5. Do not read branches unrelated to your task.
84
+
85
+ ---
86
+
87
+ ## Writing to the tree
88
+
89
+ - **Memory/MEMORY.md**: short branch summaries + links. No dense detail.
90
+ - **Branch entry note**: all durable facts for that area, organized by section.
91
+ - **Subtopic note**: created only when an entry note grows beyond ~150 lines.
92
+ - **Decision file**: one file per architectural decision, linked from the branch.
93
+
94
+ Format for facts: lead with the fact. For lessons: add **Why:** and **How to apply:**.
95
+
96
+ ---
97
+
98
+ ## Bootstrap
99
+
100
+ If `agent-knowledge/Memory/MEMORY.md` is missing or empty:
101
+ -> Read and follow the `project-ontology-bootstrap` skill before any other work.
102
+
103
+ ---
104
+
105
+ ## When to write back
106
+
107
+ Write to memory when any of these happen:
108
+ - A new architectural decision is made
109
+ - A pattern or convention is confirmed
110
+ - A gotcha is discovered
111
+ - A feature area is substantially completed or changed
112
+ - A recurring mistake is corrected
113
+
114
+ Do NOT write:
115
+ - In-progress task state -> session file only
116
+ - Speculative plans -> wait until confirmed
117
+ - Facts already in git history that are easily re-discoverable
118
+ - Raw evidence -> keep it in `Evidence/`
119
+ - Machine-generated summaries -> keep in `Evidence/` or `Outputs/` until curated
120
+
121
+ ---
122
+
123
+ ## Compaction
124
+
125
+ When `Memory/MEMORY.md` grows noisy or a branch note exceeds ~150 lines:
126
+ -> Read and follow the `memory-compaction` skill.
127
+
128
+ ---
129
+
130
+ ## Explicit user requests
131
+
132
+ - "Remember X" -> save it immediately to the relevant branch note
133
+ - "Forget X" -> remove or mark stale in the relevant branch note
134
+ - "Why did we choose X" -> read `decisions/decisions.md` and the linked decision file
@@ -0,0 +1,173 @@
1
+ ---
2
+ name: project-ontology-bootstrap
3
+ description: Bootstrap an adaptive project knowledge tree. Use when agent-knowledge/Memory/MEMORY.md is missing, broken, or too generic.
4
+ ---
5
+
6
+ # Project Ontology Bootstrap
7
+
8
+ Creates a minimal knowledge scaffold, then the agent infers the ontology from the
9
+ real project. Run this once -- then maintain with the writeback rule.
10
+
11
+ ## When to use
12
+
13
+ - `agent-knowledge/Memory/MEMORY.md` does not exist or is empty
14
+ - `Memory/MEMORY.md` exists but is still generic bootstrap content
15
+ - User says "initialize memory", "bootstrap memory", or "set up project memory"
16
+ - Starting work on an inherited repo with no prior agent memory
17
+
18
+ ---
19
+
20
+ ## Step 0 -- Verify the local pointer
21
+
22
+ The project entrypoint is `./agent-knowledge`.
23
+
24
+ - `./agent-knowledge` must be a symlink or junction to the real dedicated knowledge folder
25
+ - The external folder is the source of truth
26
+ - Manual and scripted bootstrap still write through `./agent-knowledge` as the local handle
27
+
28
+ If the pointer does not exist yet, create it first with:
29
+
30
+ ```bash
31
+ scripts/install-project-links.sh --slug <project-slug> --repo /path/to/project
32
+ ```
33
+
34
+ ---
35
+
36
+ ## Step 1 -- Run the bootstrap script
37
+
38
+ ```bash
39
+ scripts/bootstrap-memory-tree.sh /path/to/project
40
+ ```
41
+
42
+ This creates a minimal scaffold:
43
+ ```text
44
+ agent-knowledge/
45
+ Memory/
46
+ MEMORY.md <- root durable memory note
47
+ decisions/
48
+ decisions.md <- decision log (same-name convention)
49
+ Evidence/
50
+ raw/
51
+ imports/
52
+ Sessions/
53
+ Outputs/
54
+ Dashboards/
55
+ Templates/
56
+ .obsidian/
57
+ STATUS.md
58
+ ```
59
+
60
+ The script detects a profile hint (web-app, robotics, ml-platform, or hybrid) and
61
+ stores it in STATUS.md. The hint does NOT create branch notes -- that is the agent's job.
62
+
63
+ ---
64
+
65
+ ## Step 2 -- Inspect the repo and infer the ontology
66
+
67
+ After the scaffold exists, inspect:
68
+ - Manifests and lockfiles
69
+ - Directory structure
70
+ - Docs (README.md, AGENTS.md, CLAUDE.md, docs/)
71
+ - Config files
72
+ - Test directories
73
+ - Workflow files
74
+ - Any evidence already present under Evidence/
75
+
76
+ From these signals, determine the project's natural decomposition. Use the project's
77
+ own terminology, not generic template names.
78
+
79
+ ---
80
+
81
+ ## Step 3 -- Create initial branch notes
82
+
83
+ Create one branch per functional domain in the project. Use the same-name convention:
84
+
85
+ - Small topic with no subtopics: `Memory/<topic>.md`
86
+ - Bigger topic with subtopics: `Memory/<topic>/<topic>.md`
87
+
88
+ Each branch note must stay under ~150 lines. If a topic is too big for one note,
89
+ split it into a folder with subtopic notes.
90
+
91
+ Do NOT put the whole system description in a single file. Split by functional domain.
92
+
93
+ Example for a robotics project:
94
+ ```text
95
+ Memory/
96
+ MEMORY.md
97
+ stack.md # build system, deps, hardware platform
98
+ perception/
99
+ perception.md # vision pipeline overview
100
+ object-detection.md # YOLO, TensorRT, tracking
101
+ lane-detection.md # lane following
102
+ navigation/
103
+ navigation.md # path planning, row driving
104
+ path-following.md # pure pursuit, drive controller
105
+ localization/
106
+ localization.md # EKF, IMU, GNSS, LiDAR odometry
107
+ cloud-interface.md # STOMP, fleet management
108
+ vehicle-interface.md # CAN, LLC, hardware abstraction
109
+ safety.md # obstacle detection, fault monitoring
110
+ decisions/
111
+ decisions.md
112
+ ```
113
+
114
+ Rules:
115
+ - Use the project's own decomposition and terminology, not generic templates
116
+ - Each branch = one focused functional domain. Do NOT use generic names like
117
+ "architecture" or "conventions" to lump unrelated subsystems together.
118
+ - Keep each note under ~150 lines. Split if bigger.
119
+ - Link related notes to each other with relative markdown links
120
+ (e.g., `See [localization](localization/localization.md) for sensor fusion`)
121
+ - Do not create empty placeholder branches
122
+ - Each branch entry note should have frontmatter, Purpose, Current State, Recent Changes,
123
+ Decisions, and Open Questions sections
124
+
125
+ ---
126
+
127
+ ## Step 4 -- Seed from immediately available facts
128
+
129
+ For each branch you create, seed it with verified facts:
130
+
131
+ - Read manifests, configs, docs, and directory structure
132
+ - Write only confirmed facts to Current State
133
+ - Do not invent facts or speculate
134
+ - If a source is machine-generated, verify against the repo before writing to Memory/
135
+
136
+ ---
137
+
138
+ ## Step 5 -- Update Memory/MEMORY.md
139
+
140
+ Add links to each branch note in the Branches section:
141
+
142
+ ```markdown
143
+ ## Branches
144
+
145
+ - [Stack](stack.md) -- Python 3.10, ROS2 Humble, colcon build system
146
+ - [Perception](perception/perception.md) -- Camera pipeline, YOLO detection, depth fusion
147
+ - [Navigation](navigation/navigation.md) -- Nav2 stack, custom costmap layers
148
+ ```
149
+
150
+ ---
151
+
152
+ ## Step 6 -- Trigger history backfill
153
+
154
+ Bootstrap creates structure only. To fill it with real project history:
155
+
156
+ ```bash
157
+ scripts/import-agent-history.sh /path/to/project
158
+ ```
159
+
160
+ Then follow the `history-backfill` skill to distill evidence into memory.
161
+
162
+ ---
163
+
164
+ ## Output checklist
165
+
166
+ After bootstrap, verify:
167
+ - [ ] `agent-knowledge/Memory/MEMORY.md` exists and uses YAML frontmatter
168
+ - [ ] `agent-knowledge/Memory/decisions/decisions.md` exists
169
+ - [ ] Each branch note has a Purpose and at least one entry in Current State
170
+ - [ ] `agent-knowledge/Evidence/raw/` and `agent-knowledge/Evidence/imports/` exist
171
+ - [ ] `agent-knowledge/Sessions/` exists
172
+ - [ ] `Memory/MEMORY.md` is still short enough to scan quickly
173
+ - [ ] No INDEX.md files were created
@@ -0,0 +1,116 @@
1
+ ---
2
+ name: session-management
3
+ description: Read on session start. Tracks work progress in session files during conversations. Use when recording milestones, decisions, blockers, or when the session-start hook creates a session file.
4
+ ---
5
+
6
+ # Session Management
7
+
8
+ Session files preserve in-progress context through long sessions and help new sessions
9
+ resume quickly from prior work.
10
+
11
+ The session file path is provided by the session-start hook
12
+ (e.g., `~/.cursor/projects/<project-id>/sessions/`).
13
+ For project-shared session notes, use `agent-knowledge/Sessions/`.
14
+
15
+ ---
16
+
17
+ ## Session vs memory — the key distinction
18
+
19
+ | Session file | Memory tree |
20
+ |-------------|------------|
21
+ | Ephemeral — deleted or archived when no longer active | Durable — persists across all sessions |
22
+ | Tracks current task progress | Tracks stable project understanding |
23
+ | Milestone-oriented log entries | Fact-oriented structured files |
24
+ | Private to one conversation thread | Shared across all agents and conversations |
25
+ | Write freely, prune aggressively | Write carefully, never speculate |
26
+
27
+ **Rule**: if a fact belongs to future sessions, it goes in memory. If it only matters for this session, it stays in the session file.
28
+
29
+ ---
30
+
31
+ ## Session file format
32
+
33
+ Filename: `YYYY-MM-DD-<title-slug>-<UUID>.tmp`
34
+ (slug defaults to `session` until the task is clear, then updated)
35
+
36
+ ```markdown
37
+ ## Current State
38
+ [One-line description of current focus]
39
+
40
+ ### Completed
41
+ - [Milestone outcomes, not step-by-step details]
42
+
43
+ ### In Progress
44
+ - [What is actively being worked on]
45
+
46
+ ### Blockers
47
+ - [What is preventing progress]
48
+
49
+ ### Notes for Next Session
50
+ - [What to load immediately when resuming]
51
+
52
+ ### Context to Load
53
+ - [Which memory areas and files to read on resume]
54
+
55
+ ## Session Log
56
+ **HH:MM** - [Milestone outcome in one line]
57
+ ```
58
+
59
+ ---
60
+
61
+ ## How to update
62
+
63
+ 1. Read the current session file first.
64
+ 2. If nothing meaningful happened since the last log entry, do not write.
65
+ 3. If a meaningful milestone occurred, write one checkpoint:
66
+ - Refresh **Current State**
67
+ - Update Completed / In Progress / Blockers
68
+ - Add one timestamped Session Log line
69
+ 4. Set the session title once the task is clear.
70
+ 5. Keep entries milestone-oriented — not every tool call.
71
+
72
+ ---
73
+
74
+ ## When NOT to write
75
+
76
+ - Between sequential tool calls in the same task
77
+ - For trivial progress (e.g., reading a file, minor edits)
78
+ - When the hook fires but no real milestone occurred
79
+
80
+ ---
81
+
82
+ ## Writeback gate — before closing a session
83
+
84
+ Before ending a session with meaningful output, check:
85
+
86
+ **Did this session change durable project understanding?**
87
+
88
+ If yes — follow the `memory-writeback` rule:
89
+ 1. Identify the durable fact (decision, pattern, gotcha, lesson)
90
+ 2. Write it to the relevant `agent-knowledge/Memory/<area>.md`
91
+ 3. For architectural decisions: use the `decision-recording` skill
92
+ 4. Once written to memory, remove or summarize it in the session file (avoid duplication)
93
+
94
+ If no meaningful new project understanding was produced — no writeback needed. State this explicitly:
95
+ > Memory writeback: none needed (no new durable facts this session).
96
+
97
+ Examples that should NOT trigger writeback:
98
+ - Progress within one task but no stable new conclusion
99
+ - Temporary debugging state
100
+ - Notes that only matter to the current conversation
101
+ - Evidence review that did not change curated understanding
102
+
103
+ ---
104
+
105
+ ## Session log entry format
106
+
107
+ ```markdown
108
+ **HH:MM** - [Milestone outcome in one line]
109
+ ```
110
+
111
+ Example:
112
+ ```markdown
113
+ **14:32** - bootstrapped memory tree (hybrid profile, 5 area files created)
114
+ **15:10** - backfill complete: stack, architecture, gotchas populated from git history
115
+ **15:45** - decision recorded: use-raw-sql (decisions/2025-01-15-use-raw-sql.md)
116
+ ```
@@ -0,0 +1,164 @@
1
+ ---
2
+ name: create-rule
3
+ description: >-
4
+ Create Cursor rules for persistent AI guidance. Use when you want to create a
5
+ rule, add coding standards, set up project conventions, configure
6
+ file-specific patterns, create RULE.md files, or asks about .cursor/rules/ or
7
+ AGENTS.md.
8
+ ---
9
+ # Creating Cursor Rules
10
+
11
+ Create project rules in `.cursor/rules/` to provide persistent context for the AI agent.
12
+
13
+ ## Gather Requirements
14
+
15
+ Before creating a rule, determine:
16
+
17
+ 1. **Purpose**: What should this rule enforce or teach?
18
+ 2. **Scope**: Should it always apply, or only for specific files?
19
+ 3. **File patterns**: If file-specific, which glob patterns?
20
+
21
+ ### Inferring from Context
22
+
23
+ If you have previous conversation context, infer rules from what was discussed. You can create multiple rules if the conversation covers distinct topics or patterns. Don't ask redundant questions if the context already provides the answers.
24
+
25
+ ### Required Questions
26
+
27
+ If the user hasn't specified scope, ask:
28
+ - "Should this rule always apply, or only when working with specific files?"
29
+
30
+ If they mentioned specific files and haven't provided concrete patterns, ask:
31
+ - "Which file patterns should this rule apply to?" (e.g., `**/*.ts`, `backend/**/*.py`)
32
+
33
+ It's very important that we get clarity on the file patterns.
34
+
35
+ Use the AskQuestion tool when available to gather this efficiently.
36
+
37
+ ---
38
+
39
+ ## Rule File Format
40
+
41
+ Rules are `.mdc` files in `.cursor/rules/` with YAML frontmatter:
42
+
43
+ ```
44
+ .cursor/rules/
45
+ typescript-standards.mdc
46
+ react-patterns.mdc
47
+ api-conventions.mdc
48
+ ```
49
+
50
+ ### File Structure
51
+
52
+ ```markdown
53
+ ---
54
+ description: Brief description of what this rule does
55
+ globs: **/*.ts # File pattern for file-specific rules
56
+ alwaysApply: false # Set to true if rule should always apply
57
+ ---
58
+
59
+ # Rule Title
60
+
61
+ Your rule content here...
62
+ ```
63
+
64
+ ### Frontmatter Fields
65
+
66
+ | Field | Type | Description |
67
+ |-------|------|-------------|
68
+ | `description` | string | What the rule does (shown in rule picker) |
69
+ | `globs` | string | File pattern - rule applies when matching files are open |
70
+ | `alwaysApply` | boolean | If true, applies to every session |
71
+
72
+ ---
73
+
74
+ ## Rule Configurations
75
+
76
+ ### Always Apply
77
+
78
+ For universal standards that should apply to every conversation:
79
+
80
+ ```yaml
81
+ ---
82
+ description: Core coding standards for the project
83
+ alwaysApply: true
84
+ ---
85
+ ```
86
+
87
+ ### Apply to Specific Files
88
+
89
+ For rules that apply when working with certain file types:
90
+
91
+ ```yaml
92
+ ---
93
+ description: TypeScript conventions for this project
94
+ globs: **/*.ts
95
+ alwaysApply: false
96
+ ---
97
+ ```
98
+
99
+ ---
100
+
101
+ ## Best Practices
102
+
103
+ ### Keep Rules Concise
104
+
105
+ - **Under 50 lines**: Rules should be concise and to the point
106
+ - **One concern per rule**: Split large rules into focused pieces
107
+ - **Actionable**: Write like clear internal docs
108
+ - **Concrete examples**: Ideally provide concrete examples of how to fix issues
109
+
110
+ ---
111
+
112
+ ## Example Rules
113
+
114
+ ### TypeScript Standards
115
+
116
+ ```markdown
117
+ ---
118
+ description: TypeScript coding standards
119
+ globs: **/*.ts
120
+ alwaysApply: false
121
+ ---
122
+
123
+ # Error Handling
124
+
125
+ \`\`\`typescript
126
+ // ❌ BAD
127
+ try {
128
+ await fetchData();
129
+ } catch (e) {}
130
+
131
+ // ✅ GOOD
132
+ try {
133
+ await fetchData();
134
+ } catch (e) {
135
+ logger.error('Failed to fetch', { error: e });
136
+ throw new DataFetchError('Unable to retrieve data', { cause: e });
137
+ }
138
+ \`\`\`
139
+ ```
140
+
141
+ ### React Patterns
142
+
143
+ ```markdown
144
+ ---
145
+ description: React component patterns
146
+ globs: **/*.tsx
147
+ alwaysApply: false
148
+ ---
149
+
150
+ # React Patterns
151
+
152
+ - Use functional components
153
+ - Extract custom hooks for reusable logic
154
+ - Colocate styles with components
155
+ ```
156
+
157
+ ---
158
+
159
+ ## Checklist
160
+
161
+ - [ ] File is `.mdc` format in `.cursor/rules/`
162
+ - [ ] Frontmatter configured correctly
163
+ - [ ] Content under 500 lines
164
+ - [ ] Includes concrete examples