Skip to content

Commit 5c5cbf3

Browse files
authored
Merge pull request #120 from cyberfabric/bugfix/load-system-prompts-wrong-rules
refactor(init): unify root AGENTS.md and CLAUDE.md managed blocks
2 parents 57cd1eb + 164c01b commit 5c5cbf3

File tree

16 files changed

+92
-183
lines changed

16 files changed

+92
-183
lines changed

.bootstrap/.core/skills/cypilot/SKILL.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,23 @@ description: "Invoke when user asks to do something with Cypilot, or wants to an
88

99
<!-- toc -->
1010

11-
- [Goal](#goal)
12-
- [Preconditions](#preconditions)
13-
- [⚠️ MUST Instruction Semantics ⚠️](#must-instruction-semantics)
14-
- [Agent Acknowledgment](#agent-acknowledgment)
15-
- [Execution Logging](#execution-logging)
16-
- [Variables](#variables)
17-
- [Template Variable Resolution](#template-variable-resolution)
18-
- [CLI Resolution](#cli-resolution)
19-
- [Protocol Guard](#protocol-guard)
20-
- [Cypilot Mode](#cypilot-mode)
21-
- [Agent-Safe Invocation](#agent-safe-invocation)
22-
- [Quick Commands (No Protocol)](#quick-commands-no-protocol)
23-
- [Workflow Routing](#workflow-routing)
24-
- [Command Reference](#command-reference)
25-
- [Auto-Configuration](#auto-configuration)
26-
- [Project Configuration](#project-configuration)
11+
- [Cypilot Unified Tool](#cypilot-unified-tool)
12+
- [Goal](#goal)
13+
- [Preconditions](#preconditions)
14+
- [⚠️ MUST Instruction Semantics ⚠️](#️-must-instruction-semantics-️)
15+
- [Agent Acknowledgment](#agent-acknowledgment)
16+
- [Execution Logging](#execution-logging)
17+
- [Variables](#variables)
18+
- [Template Variable Resolution](#template-variable-resolution)
19+
- [CLI Resolution](#cli-resolution)
20+
- [Protocol Guard](#protocol-guard)
21+
- [Cypilot Mode](#cypilot-mode)
22+
- [Agent-Safe Invocation](#agent-safe-invocation)
23+
- [Quick Commands (No Protocol)](#quick-commands-no-protocol)
24+
- [Workflow Routing](#workflow-routing)
25+
- [Command Reference](#command-reference)
26+
- [Auto-Configuration](#auto-configuration)
27+
- [Project Configuration](#project-configuration)
2728

2829
<!-- /toc -->
2930

@@ -73,7 +74,7 @@ Example:
7374

7475
| Variable | Value | Use |
7576
|---|---|---|
76-
| `{cypilot_path}` | Directory containing this `../../SKILL.md` | Base path for all Cypilot-relative references |
77+
| `{cypilot_path}` | Directory path resolved from root `AGENTS.md` | Base path for all Cypilot-relative references |
7778
| `{cypilot_mode}` | `on` or `off` | Current Cypilot mode state |
7879
| `{cpt_cmd}` | `cpt` or `python3 {cypilot_path}/.core/skills/cypilot/scripts/cypilot.py` | Resolved CLI entrypoint |
7980
| `{cpt_installed}` | `true` or `false` | Whether the `cpt` CLI is available |

.bootstrap/.core/skills/cypilot/scripts/cypilot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def main(argv: Optional[List[str]] = None) -> int:
1717
from .cli import main as _main
1818
return _main(argv)
1919

20-
__version__ = "v3.2.0-beta"
20+
__version__ = "v3.2.1-beta"
2121

2222
__all__ = [
2323
# Main entry point

.bootstrap/.core/skills/cypilot/scripts/cypilot/commands/init.py

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -273,22 +273,9 @@ def _compute_managed_block(install_dir: str) -> str:
273273
# @cpt-begin:cpt-cypilot-algo-core-infra-inject-root-agents:p1:inst-compute-block
274274
return (
275275
f"{MARKER_START}\n"
276-
f"## Cypilot AI Agent Navigation\n"
277-
f"\n"
278-
f"**Remember these variables while working in this project:**\n"
279-
f"\n"
280276
f"```toml\n"
281277
f'cypilot_path = "{install_dir}"\n'
282278
f"```\n"
283-
f"\n"
284-
f"## Navigation Rules\n"
285-
f"\n"
286-
f"ALWAYS open and follow `{{cypilot_path}}/.gen/AGENTS.md` FIRST\n"
287-
f"\n"
288-
f"ALWAYS open and follow `{{cypilot_path}}/config/AGENTS.md` FIRST\n"
289-
f"\n"
290-
f"ALWAYS invoke `{{cypilot_path}}/.core/skills/cypilot/SKILL.md` WHEN user asks to do something with Cypilot\n"
291-
f"\n"
292279
f"{MARKER_END}"
293280
)
294281
# @cpt-end:cpt-cypilot-algo-core-infra-inject-root-agents:p1:inst-compute-block
@@ -340,38 +327,9 @@ def _inject_root_agents(project_root: Path, install_dir: str, dry_run: bool = Fa
340327
return _inject_managed_block(project_root / "AGENTS.md", install_dir, dry_run)
341328

342329
# @cpt-begin:cpt-cypilot-flow-core-infra-project-init:p1:inst-init-inject-claude
343-
def _compute_claude_block() -> str:
344-
return (
345-
f"{MARKER_START}\n"
346-
f"STOP and READ `AGENTS.md` in project root before ANY tool calls or skill invocation\n"
347-
f"{MARKER_END}"
348-
)
349-
350330
def _inject_root_claude(project_root: Path, install_dir: str, dry_run: bool = False) -> str:
351331
"""Inject or update root CLAUDE.md managed block. Returns action taken."""
352-
claude_file = project_root / "CLAUDE.md"
353-
expected_block = _compute_claude_block()
354-
355-
if not claude_file.is_file():
356-
if not dry_run:
357-
claude_file.write_text(expected_block + "\n", encoding="utf-8")
358-
return "created"
359-
360-
content = claude_file.read_text(encoding="utf-8")
361-
362-
if MARKER_START in content and MARKER_END in content:
363-
start_idx = content.index(MARKER_START)
364-
end_idx = content.index(MARKER_END) + len(MARKER_END)
365-
current_block = content[start_idx:end_idx]
366-
if current_block == expected_block.strip():
367-
return "unchanged"
368-
new_content = content[:start_idx] + expected_block + content[end_idx:]
369-
else:
370-
new_content = expected_block + "\n\n" + content
371-
372-
if not dry_run:
373-
claude_file.write_text(new_content, encoding="utf-8")
374-
return "updated"
332+
return _inject_managed_block(project_root / "CLAUDE.md", install_dir, dry_run)
375333
# @cpt-end:cpt-cypilot-flow-core-infra-project-init:p1:inst-init-inject-claude
376334

377335
def cmd_init(argv: List[str]) -> int:

.bootstrap/.core/whatsnew.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,12 @@ details = """\
181181
- **Checklist and methodology normalization** — streamlined `code-checklist.md`, `consistency-checklist.md`, `plan-checklist.md`, `prompt-engineering.md`, `reverse-engineering.md`, and `auto-config.md` into denser formats optimized for agent consumption
182182
- **Post-compaction TOC fix** — marker-based `validate-toc` now expects the same heading set that `toc` generates, so documents with secondary `H1` sections such as `# MUST HAVE` / `# MUST NOT HAVE` validate correctly with `--max-level 2`
183183
- **Regression coverage added** — test coverage now includes the marker-based TOC validation case with secondary `H1` sections in a single document\
184+
"""
185+
186+
["v3.2.1-beta"]
187+
summary = "Compact root markers, unified CLAUDE.md injection"
188+
details = """\
189+
- **Compact root marker blocks** — removed verbose navigation rules from `AGENTS.md` and `CLAUDE.md` managed blocks; now contains only the `cypilot_path` TOML definition
190+
- **Unified CLAUDE.md injection** — `_inject_root_claude()` now reuses `_inject_managed_block()` for consistent block generation
191+
- **Variable description fix** — `{cypilot_path}` documentation updated to clarify it's resolved from root `AGENTS.md`\
184192
"""

AGENTS.md

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,5 @@
11
<!-- @cpt:root-agents -->
2-
## Cypilot AI Agent Navigation
3-
4-
**Remember these variables while working in this project:**
5-
62
```toml
73
cypilot_path = ".bootstrap"
84
```
9-
10-
## Navigation Rules
11-
12-
ALWAYS open and follow `{cypilot_path}/.gen/AGENTS.md` FIRST
13-
14-
ALWAYS open and follow `{cypilot_path}/config/AGENTS.md` FIRST
15-
16-
ALWAYS invoke `{cypilot_path}/.core/skills/cypilot/SKILL.md` WHEN user asks to do something with Cypilot
17-
185
<!-- /@cpt:root-agents -->
19-
20-
## Cypilot AI Agent Navigation
21-
22-
**Version**: 1.1
23-
24-
---
25-
26-
## Navigation Rules
27-
28-
ALWAYS open and follow `{cypilot_path}/config/AGENTS.md` WHEN starting any Cypilot work
29-
30-
### Dependency Error Handling
31-
32-
**If referenced file not found**:
33-
- Log warning to user: "Cypilot dependency not found: {path}"
34-
- Continue with available files — do NOT fail silently
35-
- If critical dependency missing (SKILL.md, workflow), inform user and suggest `/cypilot` to reinitialize

CLAUDE.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
<!-- @cpt:root-agents -->
2-
STOP and READ `AGENTS.md` in project root before ANY tool calls or skill invocation
2+
```toml
3+
cypilot_path = ".bootstrap"
4+
```
35
<!-- /@cpt:root-agents -->

architecture/DESIGN.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -890,18 +890,19 @@ sequenceDiagram
890890

891891
**Description**: User initializes Cypilot in a project. The skill engine asks for install directory and agent selection. It defines a **root system** (name and slug derived from the project directory name), creates core configs (`core.toml` with root system, `artifacts.toml` with default autodetect rules), generates agent entry points, and sets up `{cypilot_path}/config/AGENTS.md` with default WHEN rules. After core setup, the tool prompts `Install SDLC kit? [a]ccept [d]ecline`. If accepted, the kit is downloaded from GitHub. If the kit source contains `manifest.toml`, the Kit Manager validates the manifest, reads declared resources, prompts the user for destination paths on `user_modifiable` resources, copies each resource to its resolved path, resolves template variables in kit files, and registers all resource bindings in `core.toml`. If no `manifest.toml` is present, files are copied to the default kit config directory. If declined, the user can install kits later via `cpt kit install`.
892892

893-
**Root AGENTS.md injection**: During initialization (and verified on every CLI invocation), the engine ensures the project root `AGENTS.md` file contains a managed block that points agents to the Cypilot navigation entry:
893+
**Root AGENTS.md / CLAUDE.md injection**: During initialization (and verified on every CLI invocation), the engine ensures the project root `AGENTS.md` and `CLAUDE.md` files contain the same managed block with only the configured adapter path:
894894

895-
```markdown
895+
````markdown
896896
<!-- @cpt:root-agents -->
897-
ALWAYS open and follow `{cypilot_path}/.gen/AGENTS.md` FIRST
898-
ALWAYS open and follow `{cypilot_path}/config/AGENTS.md` WHEN it exists
899-
<!-- @/cpt:root-agents -->
897+
```toml
898+
cypilot_path = ".bootstrap"
900899
```
900+
<!-- @/cpt:root-agents -->
901+
````
901902

902-
The block is inserted at the **beginning** of the file. If the file does not exist, it is created. The path inside the block reflects the actual install directory (e.g., `@/{cypilot_path}/config/AGENTS.md`). Content between the `<!-- @cpt:root-agents -->` and `<!-- @/cpt:root-agents -->` comment markers is fully managed by Cypilot — it is overwritten on every check, so manual edits inside the block are discarded.
903+
The block is inserted at the **beginning** of each file. If a file does not exist, it is created. The managed content is a TOML fence that declares only `cypilot_path`, and the path reflects the actual install directory. Content between the `<!-- @cpt:root-agents -->` and `<!-- @/cpt:root-agents -->` comment markers is fully managed by Cypilot — it is overwritten on every check, so manual edits inside the block are discarded.
903904

904-
**Integrity invariant**: every Cypilot CLI command (not just `init`) verifies the root `AGENTS.md` block exists and is correct before proceeding. If the block is missing or the path is stale (e.g., install directory changed), the engine silently re-injects it. This guarantees that any agent opening the project will be routed to Cypilot regardless of how the IDE session started.
905+
**Integrity invariant**: every Cypilot CLI command (not just `init`) verifies the root `AGENTS.md` and `CLAUDE.md` blocks exist and are correct before proceeding. If a block is missing or the path is stale (e.g., install directory changed), the engine silently re-injects it. This guarantees that root agent files always expose the current `cypilot_path` without duplicating navigation rules.
905906

906907
#### Artifact Validation
907908

architecture/features/agent-integration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Without this feature, users would need to manually create and maintain agent-spe
8383
1. - `p1` - Generate agent-native entry points (skill shims, workflow proxies, rules) - `inst-generate-entry-points`
8484
2. - `p1` - Write files to agent directory (e.g., `.windsurf/workflows/`, `.cursor/rules/`) - `inst-write-files`
8585
8. - `p1` - Compose and write main SKILL.md from collected skill sections - `inst-compose-skill`
86-
9. - `p1` - Inject managed block into root AGENTS.md - `inst-inject-agents`
86+
9. - `p1` - Inject the same managed `cypilot_path` block into root AGENTS.md and CLAUDE.md - `inst-inject-agents`
8787
10. [x] - `p1` - **RETURN** generation report (agents, files written, workflows discovered) - `inst-return-report`
8888

8989
### Execute Generic Workflow

architecture/specs/sysprompts.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,25 +89,24 @@ All sysprompt files are optional. Only files referenced in `AGENTS.md` are loade
8989

9090
## Root AGENTS.md Entry
9191

92-
Cypilot injects a managed block into the **project root** `AGENTS.md` that routes agents to `{cypilot_path}/config/AGENTS.md`:
92+
Cypilot injects the same managed block into the **project root** `AGENTS.md` and `CLAUDE.md`, exposing only the configured adapter path:
9393

94-
```markdown
94+
````markdown
9595
<!-- @cpt:root-agents -->
96-
ALWAYS open and follow `{cypilot_path}/.gen/AGENTS.md` FIRST
97-
ALWAYS open and follow `{cypilot_path}/config/AGENTS.md` WHEN it exists
98-
<!-- @/cpt:root-agents -->
96+
```toml
97+
cypilot_path = ".bootstrap"
9998
```
99+
<!-- @/cpt:root-agents -->
100+
````
100101

101102
**Behavior**:
102-
- Inserted at the **beginning** of the root `AGENTS.md` file
103-
- If the file does not exist, it is created
104-
- The path reflects the actual install directory (e.g., `@/{cypilot_path}/config/AGENTS.md`)
103+
- Inserted at the **beginning** of the root `AGENTS.md` and `CLAUDE.md` files
104+
- If a file does not exist, it is created
105+
- The path reflects the actual install directory via `cypilot_path`
105106
- Content between the `<!-- @cpt:root-agents -->` and `<!-- @/cpt:root-agents -->` markers is **fully managed** by Cypilot — overwritten on every check
106107
- Manual edits inside the block are discarded
107108

108-
**Integrity check**: every Cypilot CLI invocation (not just `init`) verifies the block exists and the path is correct. If the block is missing or stale, it is silently re-injected.
109-
110-
This ensures any agent that opens the project is immediately routed to Cypilot's navigation entry point.
109+
**Integrity check**: every Cypilot CLI invocation (not just `init`) verifies both blocks exist and the path is correct. If a block is missing or stale, it is silently re-injected. This ensures any agent that opens the project is immediately routed to Cypilot's navigation entry point.
111110

112111
---
113112

skills/cypilot/SKILL.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,23 @@ description: "Invoke when user asks to do something with Cypilot, or wants to an
88

99
<!-- toc -->
1010

11-
- [Goal](#goal)
12-
- [Preconditions](#preconditions)
13-
- [⚠️ MUST Instruction Semantics ⚠️](#must-instruction-semantics)
14-
- [Agent Acknowledgment](#agent-acknowledgment)
15-
- [Execution Logging](#execution-logging)
16-
- [Variables](#variables)
17-
- [Template Variable Resolution](#template-variable-resolution)
18-
- [CLI Resolution](#cli-resolution)
19-
- [Protocol Guard](#protocol-guard)
20-
- [Cypilot Mode](#cypilot-mode)
21-
- [Agent-Safe Invocation](#agent-safe-invocation)
22-
- [Quick Commands (No Protocol)](#quick-commands-no-protocol)
23-
- [Workflow Routing](#workflow-routing)
24-
- [Command Reference](#command-reference)
25-
- [Auto-Configuration](#auto-configuration)
26-
- [Project Configuration](#project-configuration)
11+
- [Cypilot Unified Tool](#cypilot-unified-tool)
12+
- [Goal](#goal)
13+
- [Preconditions](#preconditions)
14+
- [⚠️ MUST Instruction Semantics ⚠️](#️-must-instruction-semantics-️)
15+
- [Agent Acknowledgment](#agent-acknowledgment)
16+
- [Execution Logging](#execution-logging)
17+
- [Variables](#variables)
18+
- [Template Variable Resolution](#template-variable-resolution)
19+
- [CLI Resolution](#cli-resolution)
20+
- [Protocol Guard](#protocol-guard)
21+
- [Cypilot Mode](#cypilot-mode)
22+
- [Agent-Safe Invocation](#agent-safe-invocation)
23+
- [Quick Commands (No Protocol)](#quick-commands-no-protocol)
24+
- [Workflow Routing](#workflow-routing)
25+
- [Command Reference](#command-reference)
26+
- [Auto-Configuration](#auto-configuration)
27+
- [Project Configuration](#project-configuration)
2728

2829
<!-- /toc -->
2930

@@ -73,7 +74,7 @@ Example:
7374

7475
| Variable | Value | Use |
7576
|---|---|---|
76-
| `{cypilot_path}` | Directory containing this `../../SKILL.md` | Base path for all Cypilot-relative references |
77+
| `{cypilot_path}` | Directory path resolved from root `AGENTS.md` | Base path for all Cypilot-relative references |
7778
| `{cypilot_mode}` | `on` or `off` | Current Cypilot mode state |
7879
| `{cpt_cmd}` | `cpt` or `python3 {cypilot_path}/.core/skills/cypilot/scripts/cypilot.py` | Resolved CLI entrypoint |
7980
| `{cpt_installed}` | `true` or `false` | Whether the `cpt` CLI is available |

0 commit comments

Comments
 (0)