"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.CURSORRULES_TEMPLATE = exports.AGENTS_MD_TEMPLATE = exports.CELL_RULES_MARKER = exports.CURSORRULES_FILENAME = exports.AGENTS_MD_FILENAME = void 0;
exports.isCellRulesFile = isCellRulesFile;
exports.writeAgentsMd = writeAgentsMd;
exports.writeCursorRules = writeCursorRules;
exports.writeCellRules = writeCellRules;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
exports.AGENTS_MD_FILENAME = 'AGENTS.md';
exports.CURSORRULES_FILENAME = '.cursorrules';
exports.CELL_RULES_MARKER = '# fivo-cell:rules:v1';
exports.AGENTS_MD_TEMPLATE = `${exports.CELL_RULES_MARKER}
# FIVO Cell — AI Memory Rules

FIVO Cell is installed and configured for this project. Use its MCP tools
(named \`cell_*\`) to maintain permanent memory across sessions.

## The @cell Convention

Whenever the user types \`@cell\` in their message (e.g. "@cell what did I
just edit?" or "@cell fix this bug"), you MUST do the following BEFORE
responding:

1. **Call \`cell_get_context\` FIRST** to load this project's full context.
2. **Pass \`project\` as the current folder name** — derive it from
   \`path.basename(process.cwd())\` or the absolute path the IDE is open
   in. If unsure, call \`cell_list_projects\` and pick the matching one.
3. **Also pass \`tool\`** set to YOUR ACTUAL IDE/TOOL NAME (the one you
   are running in right now). Cell formats the block differently for
   each tool. The valid values are:
   - If you are in **Antigravity** / **Gemini** IDE → pass \`"tool": "antigravity"\`
   - If you are in **Cursor** → pass \`"tool": "cursor"\`
   - If you are in **OpenCode** CLI → pass \`"tool": "opencode"\`
   - If you are in **Claude Code** CLI → pass \`"tool": "claude-code"\`
   - If you are in **Codex** CLI → pass \`"tool": "codex"\`
   - If you are in **Windsurf** / **Codeium** → pass \`"tool": "windsurf"\`
   - If you are in **GitHub Copilot** → pass \`"tool": "copilot"\`
   - If you are in **Aider** → pass \`"tool": "aider"\`
   - If you are in **Continue.dev** → pass \`"tool": "continue-dev"\`
   - If you are unsure / none of the above → omit \`tool\` and Cell
     returns the rich text block (works for every IDE).
   DO NOT pass \`"opencode"\` unless you are actually OpenCode. If you
   are Antigravity, the correct value is \`"antigravity"\` (not
   \`"opencode"\`, not \`"cursor"\`, not \`"antigravity-ide"\`).
4. **Use the returned context** to inform your answer — it contains the
   last session, recent file edits (live events), blind spots, style
   hints, predictions, tried approaches, **session bridge (what just happened)**,
   and **continuity thread (what's been happening across sessions)**.

## Supreme Context: Bridge + Continuity

Fivo Cell v7+ maintains **Supreme Context** — AI never starts a session blind:

- **🌉 Session Bridge**: Automatically captured at session end. Auto-injected
   at session start. Contains: summary, open questions, failed approaches,
   working approaches, last thought, file focus, vibe snapshot.
- **🧵 Continuity Thread**: Tracks work across multiple sessions. Knows
   what you're building, open questions, pending actions, key learnings.
- **🔮 Context Predictions**: Predicts what you'll need — which files,
   which errors may recur, which decisions need revisiting.

**The bridge is auto-loaded in every \`@cell\` block.** You don't need to
ask for it — just read the \`🌉 LAST SESSION BRIDGE\` and \`🧵 CONTINUITY
THREAD\` sections at the top of the context block and use them.

## Common Cell Tools

| Task | Tool |
|------|------|
| Load project context (\`@cell\`) | \`cell_get_context\` |
| Open a work session | \`cell_session_start\` |
| Close a session with key decisions | \`cell_session_end\` |
| See recent sessions | \`cell_session_recent\` |
| See recent file saves | \`cell_watch_events\` |
| Start the file watcher | \`cell_watch_start\` |
| Stop the file watcher | \`cell_watch_stop\` |
| Detect code risks (try/catch, null checks, validation) | \`cell_blindspots\` |
| Scan the project | \`cell_scan\` |
| Log an error you hit | \`cell_log_error\` |
| Log how you fixed it | \`cell_log_fix\` |
| Log a key decision | \`cell_log_decision\` |
| List all registered projects | \`cell_list_projects\` |

There are 67 cell tools in total. Run \`cell --help\` to see all of them.

## Session Discipline

- **At the start of a non-trivial task** (multi-file work, refactor,
  feature, debugging session): call \`cell_session_start\` to open a
  session.
- **At the end** (or before a long break): call \`cell_session_end\` with
  \`keyDecisions\` summarising what you decided and \`filesTouched\`
  listing the files you changed.
- If the user switches tools (e.g. Cursor → Antigravity) within a
  project, the bridge context is auto-loaded — read it from the @cell
  block to understand what was just done.

## Supreme Context: Never Start Blind

Fivo v7 includes **Supreme Context** that auto-injects into every
\`@cell\` block:

- **🌉 Bridge**: Last session's summary, decisions, open questions,
  file focus, failed approaches (don't retry), working approaches
- **🧵 Continuity Thread**: Cross-session work tracking — what's being
  built, pending actions, key learnings across sessions
- **🔮 Predictions**: What files you'll need, which errors may recur,
  which decisions need revisiting

Read these sections at the top of the context block and you'll
immediately know what was happening and what to do next.

## Watcher Awareness

- If the watcher is active, the @cell block includes the most recent
  file edits. Trust those for "what did I just edit" questions.
- If the user reports a file change you don't know about, call
  \`cell_watch_events\` directly.

## Anti-Patterns to Avoid

- Do NOT guess a project name. If unsure, call \`cell_list_projects\`.
- Do NOT skip \`cell_get_context\` when @cell is in the prompt — the
  whole point of the convention is automatic context.
- Do NOT call \`cell_get_context\` for every message. Only when @cell
  appears, or when context is genuinely needed.
- Do NOT modify or remove this file. To regenerate it, run
  \`cell scan\` again (it is idempotent — existing files are kept).

## Regeneration

This file is auto-generated by \`cell scan\`. To remove it: \`cell scan --no-rules\`.
`;
exports.CURSORRULES_TEMPLATE = `${exports.CELL_RULES_MARKER}
# FIVO Cell — Cursor Rules

When the user types \`@cell\` in chat or Composer, you MUST call the
\`cell_get_context\` MCP tool FIRST, with \`project\` set to the current
folder name and \`tool\` set to \`cursor\`. Then use the returned block
to inform your response. See AGENTS.md for the full convention.
`;
function isCellRulesFile(content) {
    return content.includes(exports.CELL_RULES_MARKER);
}
function writeAgentsMd(projectPath, opts = {}) {
    const filePath = path.join(projectPath, exports.AGENTS_MD_FILENAME);
    if (fs.existsSync(filePath) && !opts.overwrite) {
        return 'exists';
    }
    try {
        fs.writeFileSync(filePath, exports.AGENTS_MD_TEMPLATE, 'utf8');
        return 'written';
    }
    catch {
        return 'skipped';
    }
}
function writeCursorRules(projectPath, opts = {}) {
    const filePath = path.join(projectPath, exports.CURSORRULES_FILENAME);
    if (fs.existsSync(filePath) && !opts.overwrite) {
        return 'exists';
    }
    try {
        fs.writeFileSync(filePath, exports.CURSORRULES_TEMPLATE, 'utf8');
        return 'written';
    }
    catch {
        return 'skipped';
    }
}
function writeCellRules(projectPath, opts = {}) {
    const agentsMd = writeAgentsMd(projectPath, opts);
    const cursorRules = opts.cursor === false ? 'skipped' : writeCursorRules(projectPath, opts);
    return { agentsMd, cursorRules };
}
//# sourceMappingURL=agents-md.js.map