# Nop.Plugin.Misc.AIPlugin — AI Agent Protocol

This plugin follows the AI Agent Core Protocol defined in AyCode.Core. Same rules apply: `[LOADED_DOCS]` prefix (count+delta format), docs-before-code, no-re-read policy, context recovery on compaction, explicit consent for modifications.

**Full protocol:** `../../../../../../Aycode/Source/AyCode.Core/.github/copilot-instructions.md`
**Protocol history:** `../../../../../../Aycode/Source/AyCode.Core/.github/LLM_PROTOCOL_DECISIONS.md`

## Session Setup

**Mandatory reads at session start** — in addition to this `copilot-instructions.md`, the agent MUST also load:

1. **Canonical AI Agent Core Protocol** — AyCode.Core's `copilot-instructions.md` (for the full numbered Rules #1-6 that this inherit file references but does NOT duplicate). Path: `../../../../../../Aycode/Source/AyCode.Core/.github/copilot-instructions.md`.
2. **The two reactive workspace skills** (see `## Shared Agent Skills` section below for paths; the three user-gated skills are lazy-loaded on demand):
   - `docs-discovery/SKILL.md` — **reactive** (triggers on domain questions)
   - `docs-check/SKILL.md` — **reactive** (triggers at end of code-modifying responses)

Lazy-loaded (read on invocation, not at session start; the `## Shared Agent Skills` bullets below describe their triggers):
   - `protocol-audit/SKILL.md` — user-invoked / LLM-suggest-back on meta-protocol file modifications
   - `adr-author/SKILL.md` — user-invoked / LLM-suggest-back on ADR-worthy conversation
   - `docs-archive/SKILL.md` — user-invoked / LLM-suggest-back on bloated active artifact files

The first response's `[LOADED_DOCS: ...]` prefix must reflect **4 files** (this file + AyCode.Core's `copilot-instructions.md` + 2 reactive SKILL.md files). Lazy-loaded skills add to the count when invoked.

**Why mandatory**: workspace skills live as plain `SKILL.md` files in `.github/skills/` — LLMs do NOT auto-discover them via any built-in skill-registry. Without pre-loading, implicit triggers (e.g., "domain question → invoke docs-discovery" at the moment of the question) may be missed. This file inherits rules from AyCode.Core, so the canonical protocol file must be loaded alongside. One-time cost per session; Rule #3 (no-re-read) prevents repeated reads; re-read only if Rule #4 (Context Recovery) fires.

**Amortization — critical, do NOT re-evaluate per-turn**: the Session Setup cost is measured over the ENTIRE session, not per single turn. A typical session has many turns; the first domain question alone already recoups the investment (alternative — repeated source-code `Grep`/`Read` per turn — costs 10-20K tokens *per turn* with lower output quality). Do NOT flag pre-loaded content as "wasteful" for turns that don't invoke it — the design depends on cross-turn amortization + Rule #3 (no-re-read) + on-demand specificity of Rule #4 (Context Recovery). This amortization is the **central token-economics principle** of the entire protocol stack.

## Workspace Dependencies

@repo {
  name = "Nop.Plugin.Misc.AIPlugin"
  prefix = "MGFBANKPLUG"
  type = "consumer"
  layer = 3
  own-dep-repos = [
    "Mango.Nop.Core: ../../Libraries/Mango.Nop.Core",
    "AyCode.Core: ../../../../../../Aycode/Source/AyCode.Core"
  ]
}

> nopCommerce plugin (Layer 3 consumer) built on Mango.Nop.Core (Layer 2 framework) and AyCode.Core (Layer 0). Contains FruitBank-specific AI/server-side logic for the nopCommerce plugin surface.
> External repos in `own-dep-repos` are fully accessible — read their source code, docs, and `.github/copilot-instructions.md` freely when you need type definitions, base classes, or context.

## Shared Agent Skills

Skills defined in other repos. **Two reactive skills are pre-loaded at session start; three user-gated skills are lazy-loaded on demand** — see `## Session Setup` above for the load matrix:

- **docs-discovery** — Load relevant `.md` documentation (main + `_ISSUES` + `_TODO` paired sets) BEFORE source-code search or modifications. Saves tokens vs. grep-based rediscovery.
  Location: `AyCode.Core/.github/skills/docs-discovery/SKILL.md` (see `own-dep-repos` above for the relative path to AyCode.Core)
  **Invoke proactively** before any domain-related coding task (see "Documentation-first coding" below). Honours the active repo's **no-re-read** rule.

- **protocol-audit** — Cross-repo consistency audit for `.github/copilot-instructions.md` across all repos.
  Location: `AyCode.Core/.github/skills/protocol-audit/SKILL.md`
  Activate from an AyCode.Core session, or read the SKILL.md directly and follow its steps.

- **docs-check** — Evaluate loaded `.md` files at the end of every code-modifying response: drift vs code, missing topic coverage, csproj-glob registration gaps for new `.md` files, and new issue/TODO candidates. Emits the `[DOCUMENTATION CHECK]` section.
  Location: `AyCode.Core/.github/skills/docs-check/SKILL.md`
  **Invoke at the end of every code-modifying response.** Read-only on loaded docs; all patches surface as proposals (Rule #5 approval required).

- **adr-author** — Create Architecture Decision Records (ADRs) for architecturally significant design decisions. Structured interview (context → alternatives → trade-offs → decision → consequences) producing a durable `docs/adr/NNNN-<slug>.md` file (product decisions) or a new `LLMP-DEC-N` row in the protocol decision log (meta-protocol decisions).
  Location: `AyCode.Core/.github/skills/adr-author/SKILL.md`
  **Invoke on explicit user request** ("let's plan X", "decide Y vs Z", "design the W module") **or proactively flag** when the conversation looks ADR-worthy (user must confirm — never auto-invoke).

- **docs-archive** — Rotate entries from active `_ISSUES.md`, `_TODO.md`, and `LLM_PROTOCOL_DECISIONS.md` into **year-month bucket** archive companions (`*_<YYYY>_<MM>.md`). Two rules: **(A)** `_ISSUES.md` / `_TODO.md` — only `Status: Closed` entries are archive-eligible (per `TOPIC_CODES.md` 3-value vocabulary: `Open` / `InProgress` / `Closed`); **(B)** `LLM_PROTOCOL_DECISIONS.md` — last-15-active rolling window (LLMP-DEC-67), older entries rotate by entry date. Bucket derived from a date in the entry body. Active files retain `Open` / `InProgress` entries plus a pointer to the archives. Archive files are NOT auto-loaded — agents read them on-demand when historical context becomes relevant.
  Location: `AyCode.Core/.github/skills/docs-archive/SKILL.md`
  **Invoke on explicit user request** ("archive ISSUES", "rotate logs") **or proactively flag** when an active artifact file has many closed prior entries (user must confirm — never auto-invoke).

## Protocol History

Cumulative log of LLM-protocol decisions (rule changes, new skills, structural shifts):

- `AyCode.Core/.github/LLM_PROTOCOL_DECISIONS.md`

Read this file when you need to understand **why** a rule is the way it is, or before proposing a protocol change — it may save a debate about something already resolved.

## Documentation-first coding

Before running any source-code `Grep` / `get_file` / `code_search` in response to a domain-related request, invoke the **`docs-discovery`** skill (path above). Scans `docs/` folders in THIS repo AND in referenced repos (via `own-dep-repos`) via Glob, loads paired .md sets as a unit. Rule-number-agnostic — refers to rule NAMES (no-re-read, folder-navigation, explicit-consent) which are stable across repos.

## Related Documentation

| Document | Topic |
|---|---|
| `docs/` | Plugin-specific documentation (if present) |
| `README.md` | Plugin overview |
| `plugin.json` | nopCommerce plugin manifest |
