Skip to content

Commit 8b19c54

Browse files
committed
feat: nudges for agents configs
1 parent 844768b commit 8b19c54

25 files changed

Lines changed: 1526 additions & 24 deletions

.archcore/.sync-state.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,26 @@
702702
"source": "mcp/adding-mcp-track-prompts.guide.md",
703703
"target": "code-quality/in-process-mcp-integration-tests.adr.md",
704704
"type": "depends_on"
705+
},
706+
{
707+
"source": "integrations/instruction-nudge-on-init.adr.md",
708+
"target": "integrations/supported-ai-agents.doc.md",
709+
"type": "related"
710+
},
711+
{
712+
"source": "integrations/instruction-nudge-on-init.adr.md",
713+
"target": "integrations/agent-hooks-integration.guide.md",
714+
"type": "related"
715+
},
716+
{
717+
"source": "integrations/instruction-nudge-on-init.adr.md",
718+
"target": "marketing/product-positioning.rule.md",
719+
"type": "related"
720+
},
721+
{
722+
"source": "integrations/instruction-nudge-on-init.adr.md",
723+
"target": "cli-ui/building-the-cli.guide.md",
724+
"type": "related"
705725
}
706726
]
707727
}

.archcore/cli-ui/building-the-cli.guide.md

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ go test ./cmd/ -run TestX # Run a specific test
3131
./archcore update # Self-update to the latest release
3232
```
3333

34-
`init` creates `.archcore/` with a free-form directory structure — documents are organized by domain/feature/team, and category is derived from the filename suffix (`slug.type.md`). Settings go in `.archcore/settings.json`. It also auto-detects AI agents and installs hooks + MCP config for all found agents.
34+
`init` creates `.archcore/` with a free-form directory structure — documents are organized by domain/feature/team, and category is derived from the filename suffix (`slug.type.md`). Settings go in `.archcore/settings.json`. It also auto-detects AI agents and installs hooks + MCP config for all found agents, then offers (opt-in) to write a usage-nudge instruction file per agent.
3535

3636
## Settings and Configuration
3737

@@ -151,10 +151,11 @@ To add support for a new AI coding agent:
151151
- `WriteMCPConfig` — write the archcore MCP entry (use `WriteStandardMCPJSON` if the agent uses standard `mcpServers` format)
152152
- `WriteHooksConfig` — set to `nil` if hooks not supported
153153
- `ManualMCPInstallHint` — set if MCP must be installed manually (e.g., Cline)
154+
- `InstructionsPath`, `WriteInstructions`, `RemoveInstructions` — the usage-nudge target. Point them at a shared helper in `internal/agents/instructions.go` (`agentsMDInstructions*` for `AGENTS.md`, `geminiInstructions*` for `GEMINI.md`, or an owned target like Claude's). `TestAllAgents_RequiredFields` fails if any are nil.
154155

155156
3. **Register the agent** — Add the constructor call to the `all` slice in `internal/agents/agents.go`
156157

157-
4. **Add tests** — Create `internal/agents/<name>_test.go` covering detection, MCP config writing, and idempotency
158+
4. **Add tests** — Create `internal/agents/<name>_test.go` covering detection, MCP config writing, idempotency, and the instruction target
158159

159160
5. **If hooks are supported:**
160161
- Create `cmd/hooks_<name>.go` with a `newHooksXxxCmd()` subcommand using `newSessionStartHookCmd`
@@ -164,7 +165,7 @@ To add support for a new AI coding agent:
164165
- Add the agent case to `installHooksForAgent()` in `cmd/hooks.go`
165166

166167
6. **Update documentation:**
167-
- Add the agent to [Supported AI Agents Registry](../integrations/supported-ai-agents.doc.md)
168+
- Add the agent to [Supported AI Agents Registry](../integrations/supported-ai-agents.doc.md) (registry table + Instruction Nudge Files table)
168169
- Add config examples to [Agent Integration Guide](../integrations/agent-hooks-integration.guide.md)
169170

170171
## Key Design Patterns
@@ -175,15 +176,5 @@ To add support for a new AI coding agent:
175176
- **Interactive forms**`charmbracelet/huh` for interactive input, with flag-based fallbacks.
176177
- **Co-located tests** — every command and package has adjacent `_test.go` files using `t.TempDir()` and table-driven subtests.
177178
- **Shared session-start handler** — all hook-supporting agents use the same `handleSessionStart` and `buildSessionContext` via the `newSessionStartHookCmd` factory, differing only in event name and config format.
179+
- **Usage-nudge instruction files**`archcore init` (opt-in) and `archcore instructions install`/`remove` write a discovery hint per agent into `AGENTS.md` / `GEMINI.md` / `.claude/rules/archcore.md`. Shared files use an idempotent fenced upsert that preserves user content; helpers live in `internal/agents/instructions.go`, the command in `cmd/instructions.go`. See [Usage-Nudge Instruction File per Agent](../integrations/instruction-nudge-on-init.adr.md).
178180
- **Invalid config backup** — corrupted config files are backed up as `.bak` before being overwritten. See [Backup Invalid Configs](../integrations/backup-invalid-configs.adr.md).
179-
180-
## Key Dependencies
181-
182-
| Package | Purpose |
183-
|---------|---------|
184-
| `github.com/spf13/cobra` | CLI framework |
185-
| `github.com/charmbracelet/huh` | Interactive terminal forms |
186-
| `github.com/charmbracelet/lipgloss` | Terminal styling |
187-
| `github.com/mark3labs/mcp-go` | MCP stdio server |
188-
| `gopkg.in/yaml.v3` | YAML frontmatter parsing |
189-
| `github.com/wk8/go-ordered-map/v2` | Deterministic JSON key ordering (hooks config) |

.archcore/integrations/agent-hooks-integration.guide.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ status: accepted
55

66
## Overview
77

8-
Archcore integrates with AI coding agents via two mechanisms:
8+
Archcore integrates with AI coding agents via three mechanisms:
99

1010
- **Hooks** — Lifecycle event interception (session start) to inject context. Supported by Claude Code, Cursor, Gemini CLI, and GitHub Copilot. Only the `SessionStart` event is active — see [Disable Stop and Prompt Hooks ADR](disable-stop-and-prompt-hooks.adr.md).
1111
- **MCP** — Model Context Protocol server providing document management tools (`init_project`, `list_documents`, `get_document`, `create_document`, `update_document`, `remove_document`, `add_relation`, `remove_relation`, `list_relations`). Supported by all agents except Cline (manual setup).
12+
- **Instruction nudge** — A short, always-on "use Archcore" hint written into each agent's instruction file (`AGENTS.md`, `GEMINI.md`, or `.claude/rules/archcore.md`) so agents discover the MCP tools without the Archcore plugin. See [Usage Nudge](#usage-nudge-instruction-files) below.
1213

1314
See [Supported AI Agents Registry](supported-ai-agents.doc.md) for the full agent list and capabilities.
1415

@@ -29,8 +30,9 @@ archcore init
2930
3. If no agents are detected, prompts the user to pick one (or skips in non-interactive mode)
3031
4. Installs hooks for agents that support them (Claude Code, Cursor, Gemini CLI, GitHub Copilot)
3132
5. Installs MCP config for all detected agents
33+
6. Offers (opt-in) to write a usage-nudge instruction file per agent — see [Usage Nudge](#usage-nudge-instruction-files)
3234

33-
Source: `cmd/init.go` (`installHooksForAgent` + `installMCPForAgent` loop).
35+
Source: `cmd/init.go` (`installHooksForAgent` + `installMCPForAgent` loop, then `maybeInstallInstructions`).
3436

3537
### Path B — Agent-first (MCP `init_project`)
3638

@@ -60,6 +62,16 @@ archcore mcp install # auto-detect and install for all found agen
6062
archcore mcp install --agent codex-cli # install for a specific agent
6163
```
6264

65+
### Usage Nudge (instruction files)
66+
67+
```bash
68+
archcore instructions install # auto-detect; write the hint for all found agents
69+
archcore instructions install --agent cursor # write for a specific agent
70+
archcore instructions remove # strip the hint from every known target
71+
```
72+
73+
The hint points agents at `.archcore/` through the MCP tools so they discover and use it even without the Archcore plugin. `archcore init` offers this as an opt-in step (interactive only; non-interactive runs skip it). Targets: `.claude/rules/archcore.md` (Claude Code, owned file), `GEMINI.md` (Gemini CLI), `AGENTS.md` (all others). Shared files use a `<!-- archcore:start -->` / `<!-- archcore:end -->` fenced block — only that span is touched, so user content is preserved and re-running is idempotent. See [Supported AI Agents Registry](supported-ai-agents.doc.md) and the [instruction-nudge ADR](instruction-nudge-on-init.adr.md).
74+
6375
## Auto-Detection
6476

6577
Archcore detects agents by checking for marker directories or files in the project root:
@@ -102,6 +114,16 @@ Source: `internal/agents/agents.go` (`Detect` function), individual agent `Detec
102114
| Codex CLI | `.codex/config.toml` | TOML `[mcp_servers.archcore]` block |
103115
| Roo Code | `.roo/mcp.json` | Standard `mcpServers` JSON |
104116

117+
### Instruction Nudge (8 agents → 3 files, opt-in)
118+
119+
| Agent | Instruction File | Write Mode |
120+
| ------------------------------------------------------------ | --------------------------- | ------------------ |
121+
| Claude Code | `.claude/rules/archcore.md` | owned (whole file) |
122+
| Gemini CLI | `GEMINI.md` | fenced upsert |
123+
| Cursor, OpenCode, Codex CLI, Roo Code, Cline, GitHub Copilot | `AGENTS.md` | fenced upsert |
124+
125+
Written by the opt-in step in `archcore init` or by `archcore instructions install`. The six `AGENTS.md` agents share one file (written once).
126+
105127
## Per-Agent Config Examples
106128

107129
### Claude Code — `.claude/settings.json`
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
title: "Write a Usage-Nudge Instruction File per Agent on init"
3+
status: accepted
4+
---
5+
6+
## Context
7+
8+
Hooks and MCP config give agents the *tools*, but not a reason to reach for them. The Archcore plugin (Claude Code / Cursor / Codex) supplies discoverability through skills, a default prompt, and hooks — but **CLI-only users get none of that**, and several supported hosts (Copilot, Gemini CLI, OpenCode, Cline, Roo) have no Archcore plugin at all, so the CLI is their only integration path.
9+
10+
This matters more under **Tool Search**: Claude Code (and others) now defer MCP tools — only tool *names* load at startup, schemas load on demand. So an always-on instruction nudge is the **discovery trigger**: without it, a CLI-only agent may never search for Archcore's tools on a relevant turn.
11+
12+
The `AGENTS.md` standard is read natively by most supported hosts, and prior art (Context7 ships a `.claude/rules/` file plus an `AGENTS.md` block) shows the pattern converts "type it every time" into "it just happens".
13+
14+
## Decision
15+
16+
`archcore` writes a short, always-on "use Archcore" hint into each detected host's instruction file, as **install-time host-awareness** owned by the **CLI** (the same category as the MCP-config writing it already does in `internal/agents`). This does not violate the "CLI stays host-agnostic at runtime" rule — there is no runtime host detection.
17+
18+
**Triggers:**
19+
- `archcore init` offers it as an **opt-in** step (interactive confirm, default yes) after hooks + MCP install. Non-interactive `init` skips it with a hint, because the nudge lands in user-curated files.
20+
- `archcore instructions install [--agent <id>]` and `archcore instructions remove [--agent <id>]` cover manual and automated runs.
21+
22+
**Per-host targets (AGENTS.md-first):**
23+
24+
| Agent | Instruction file | Write mode |
25+
|-------|------------------|------------|
26+
| Claude Code | `.claude/rules/archcore.md` | owned (whole file) |
27+
| Gemini CLI | `GEMINI.md` | fenced upsert |
28+
| Cursor, OpenCode, Codex CLI, Roo Code, Cline, GitHub Copilot | `AGENTS.md` | fenced upsert |
29+
30+
**Ownership and idempotency:**
31+
- **Owned files** — archcore owns the whole file and overwrites freely. Claude Code does not read `AGENTS.md` (it reads `.claude/rules/*.md`, which auto-load at CLAUDE.md priority), so it gets a dedicated file.
32+
- **Fenced upsert** — for shared user files, archcore only ever replaces the span between `<!-- archcore:start -->` and `<!-- archcore:end -->`; content outside the markers is never touched. A single shared marker pair (not per-host markers) lets the Archcore plugin target the same block later. Writing twice yields byte-identical output.
33+
- **Dedup** — callers collapse the selected agents to unique instruction-file paths, so the six `AGENTS.md` agents trigger a single write.
34+
35+
**Content** is host-neutral, outcome-first, and references Archcore through its **MCP tools** (not plugin slash commands — CLI-only users have no plugin). It splits the cheap discovery search from the selective deep read, so invocation tracks *relevance* rather than volume: lean on the search, and skip only turns the repo would have no opinion on (syntax trivia, throwaway snippets, pure mechanics). The skip is keyed on the nature of the turn — a prior the agent can form up front — not on whether a rule exists, which the agent cannot know without the very lookup it is being told to skip. Wording uses "project context" rather than "memory" to stay aligned with [Archcore Product Positioning](../marketing/product-positioning.rule.md).
36+
37+
## Alternatives
38+
39+
- **Plugin owns the nudge.** Rejected: CLI-only and plugin-less hosts would get nothing — exactly the users this targets. The CLI owns the baseline block for all hosts; the plugin can later enrich or defer to the same marker.
40+
- **Always write without a confirm** (as hooks/MCP do). Rejected for `init`: `AGENTS.md` / `GEMINI.md` are user-curated content files, not machine config, so prose is appended only with consent. The fenced upsert keeps it non-destructive and `instructions remove` makes it reversible.
41+
- **Per-host native files everywhere** (`.cursor/rules/archcore.mdc` with `alwaysApply`, `.roo/rules/`, `.clinerules/`). Deferred to a later iteration: v1 relies on each host's native `AGENTS.md` support for single-exposure simplicity. `alwaysApply` is an opt-in upgrade for a hard always-on guarantee.
42+
- **Unify Gemini onto `AGENTS.md`** by editing `contextFileName` in `.gemini/settings.json`. Rejected for v1: invasive settings edit; a plain `GEMINI.md` write is simpler.
43+
- **Blunt "Do NOT use Archcore for…" prohibition keyed on rule-presence.** Rejected: gating on "general programming help with no project-specific rule attached" asks the agent to predict a fact about the doc store it cannot know without the very lookup it is told to skip. It silently suppressed invocation exactly when a doc *did* apply — which reads to users as a dead, useless integration — and the failure worsens as the store grows and more areas get covered. The relevance-and-cost framing in **Content** keeps a brake (skip trivial turns) without the unknowable precondition.
44+
45+
## Consequences
46+
47+
- CLI-only users (and plugin-less hosts) now discover and invoke Archcore without manual prompting — the gap this closes.
48+
- Non-destructive (fenced upsert) and reversible (`instructions remove`).
49+
- Cost: one extra opt-in prompt during interactive `init`; non-interactive `init` skips the nudge, so automation must call `archcore instructions install` explicitly.
50+
- Maintenance: every agent must wire `InstructionsPath`, `WriteInstructions`, and `RemoveInstructions`. This is enforced by `TestAllAgents_RequiredFields`, so a new agent cannot silently omit a target.
51+
- Helpers live in `internal/agents/instructions.go`; the command layer (`cmd/instructions.go`) handles dedup, display, and the `install`/`remove` subcommands; the `init` opt-in lives behind the `confirmInstructions` seam in `cmd/init.go`.

0 commit comments

Comments
 (0)