diff --git a/.codex-plugin/plugin.json b/.codex-plugin/plugin.json new file mode 100644 index 0000000..0197ddb --- /dev/null +++ b/.codex-plugin/plugin.json @@ -0,0 +1,55 @@ +{ + "name": "archipy", + "version": "0.24.0", + "description": "Codex plugin: skills and hooks for building apps with ArchiPy", + "author": { + "name": "SyntaxArc" + }, + "repository": "https://github.com/SyntaxArc/archipy-plugin", + "license": "MIT", + "keywords": [ + "archipy", + "python", + "clean-architecture", + "codex" + ], + "skills": "./skills", + "hooks": { + "SessionStart": [ + { + "matcher": "startup|resume|clear|compact|fork", + "hooks": [ + { + "type": "command", + "command": "python3 \"${PLUGIN_ROOT}/scripts/scaffold_hygiene.py\" SessionStart", + "statusMessage": "Loading ArchiPy guidance" + } + ] + } + ], + "PreToolUse": [ + { + "matcher": "apply_patch|Write|Edit", + "hooks": [ + { + "type": "command", + "command": "python3 \"${PLUGIN_ROOT}/scripts/scaffold_hygiene.py\" PreToolUse", + "statusMessage": "Checking ArchiPy adapter paths" + } + ] + } + ], + "PostToolUse": [ + { + "matcher": "apply_patch|Write|Edit", + "hooks": [ + { + "type": "command", + "command": "python3 \"${PLUGIN_ROOT}/scripts/scaffold_hygiene.py\" PostToolUse", + "statusMessage": "Loading ArchiPy file guidance" + } + ] + } + ] + } +} diff --git a/AGENTS.md b/AGENTS.md index 60604b8..80fd53d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,6 +1,6 @@ # ArchiPy Plugin — Agent Instructions -Works in **Cursor** and **Claude Code**. +Works in **Codex**, **Cursor**, and **Claude Code**. Consumer plugin for **apps that depend on** PyPI [`archipy`](https://pypi.org/project/archipy/). @@ -14,7 +14,7 @@ Consumer plugin for **apps that depend on** PyPI [`archipy`](https://pypi.org/pr ## Prefer plugin entry points -| Need | Skill (slash command) | +| Need | Skill (Codex `$name`; Cursor / Claude slash command) | |---------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------| | New app tree | `/scaffold-app` | | Full domain slice | `/scaffold-domain` | @@ -29,11 +29,13 @@ Consumer plugin for **apps that depend on** PyPI [`archipy`](https://pypi.org/pr Issues, branches, PRs, checklists and merges: use the `pr-steward` plugin skills (`new-issue`, `split-issue`, `open-pr`, `tick-checklist`, `merge-pr`; https://github.com/SyntaxArc/pr-steward). This plugin no longer ships a contributing rule. +In Codex, invoke a skill as `$skill-name` (for example, `$scaffold-app`). Cursor and Claude Code use slash commands. + Bundled cheat sheet: `skills/archipy-docs/reference.md`. When a skill runs, read its `SKILL.md` in full before generating files. Resolve `skills/*/reference/` templates from the plugin installation (Cursor: `$CURSOR_PLUGIN_ROOT`; Claude Code substitutes -`${CLAUDE_SKILL_DIR}` in skills, alongside `${CLAUDE_PLUGIN_ROOT}`), copy +`${CLAUDE_SKILL_DIR}` in skills, alongside `${CLAUDE_PLUGIN_ROOT}`; Codex provides `${PLUGIN_ROOT}`), copy them into the app, and never edit plugin templates in place. Live docs: https://syntaxarc.github.io/ArchiPy/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 78f5a72..e05efff 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,6 +16,10 @@ ln -sfn "$(pwd)" ~/.cursor/plugins/local/archipy # Claude Code mkdir -p ~/.claude/plugins/local ln -sfn "$(pwd)" ~/.claude/plugins/local/archipy + +# Codex +codex plugin marketplace add SyntaxArc/archipy-plugin +codex plugin add archipy@archipy ``` Reload the editor after edits. @@ -38,25 +42,27 @@ python3 scripts/check_catalog.py python3 -m unittest discover -s tests -v ``` -## Dual IDE parity +## Client manifest parity -Keep Cursor and Claude manifests in sync: +Keep all client manifests in sync: | File | Field | |-----------------------------------|----------------------| | `.cursor-plugin/plugin.json` | `version` | | `.claude-plugin/plugin.json` | `version` | +| `.codex-plugin/plugin.json` | `version` | | `.cursor-plugin/marketplace.json` | `plugins[0].version` | | `.claude-plugin/marketplace.json` | `plugins[0].version` | -All four must share the same SemVer string. +All five must share the same SemVer string. -`hooks` paths **must differ**: Cursor `./hooks/hooks.json`, Claude Code `./hooks/claude-hooks.json`. +Hook formats are client-specific: Cursor uses `./hooks/hooks.json`, Claude Code uses `./hooks/claude-hooks.json`, and +Codex declares its hooks in `.codex-plugin/plugin.json`. ## Release checklist 1. Update `CHANGELOG.md` (Keep a Changelog). -2. Bump all four JSON versions together. +2. Bump all five JSON versions together. 3. Run `python3 scripts/check_catalog.py` and `python3 -m unittest discover -s tests -v`. 4. Open a focused PR; conventional commits (`feat`, `fix`, `docs`, `chore`, …). Merge after CI is green. 5. Tag the merge commit `vX.Y.Z` and push the tag. `.github/workflows/release.yml` re-runs the checks, verifies the @@ -65,22 +71,22 @@ All four must share the same SemVer string. ## Hooks -Plugin hooks (both run `scripts/scaffold_hygiene.py`; keep Cursor and Claude Code behavior in parity): +Plugin hooks run `scripts/scaffold_hygiene.py` for all three clients: -| Event | Cursor (`hooks/hooks.json`) | Claude Code (`hooks/claude-hooks.json`) | -|---|---|---| -| Session start | `sessionStart` → `additional_context`: reminder + ArchiPy version | `SessionStart` → `hookSpecificOutput.additionalContext`: reminder + version + always-on rule bodies | -| Before Write | `preToolUse` → `permission: "deny"` for a **new** file under a top-level `adapters/` | `PreToolUse` → `permissionDecision: "deny"`, same condition | -| After edits | `postToolUse` → adapter-path warning | `PostToolUse` → warning + glob-matched rule bodies | +| Event | Cursor (`hooks/hooks.json`) | Claude Code (`hooks/claude-hooks.json`) | Codex (`.codex-plugin/plugin.json`) | +|---|---|---|---| +| Session start | `sessionStart` → `additional_context`: reminder + ArchiPy version | `SessionStart` → `hookSpecificOutput.additionalContext`: reminder + version + always-on rule bodies | `SessionStart` → same context and always-on rules | +| Before file edits | `preToolUse` → deny a **new** file under top-level `adapters/` | `PreToolUse` → deny, same condition | `PreToolUse` on `apply_patch` → deny the same misplaced new file | +| After edits | `postToolUse` → adapter-path warning | `PostToolUse` → warning + glob-matched rule bodies | `PostToolUse` on `apply_patch` → warning + glob-matched rule bodies | - All hooks run only when the project's `pyproject.toml`, `uv.lock`, or `requirements.txt` depends on `archipy` (Claude sends `cwd`; Cursor sends `cwd` on tool events and `workspace_roots` everywhere). -- Cursor loads `.mdc` rules natively, so only Claude gets rule bodies. Claude ignores Cursor's top-level - `additional_context`, and Cursor ignores `hookSpecificOutput`. +- Cursor loads `.mdc` rules natively. Claude Code and Codex receive rule bodies through hooks; Cursor ignores + `hookSpecificOutput`. - Claude path-scoped rules inject once per session (and subagent), reset on each `SessionStart` (startup/resume/clear/compact). - The adapter guard only blocks creating new files; existing top-level `adapters/` files in legacy apps stay editable. -- Do not point both manifests at the same hooks file — schemas differ. +- Keep hook configurations client-specific — their schemas and edit tool events differ. ## Evals diff --git a/README.md b/README.md index a24c645..20253ce 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ [![ArchiPy Docs](https://img.shields.io/badge/docs-ArchiPy-blue.svg)](https://syntaxarc.github.io/ArchiPy/) [![ArchiPy](https://img.shields.io/badge/library-SyntaxArc%2FArchiPy-0F172A.svg)](https://github.com/SyntaxArc/ArchiPy) -Rules, skills, and slash commands for **application teams that build -with [ArchiPy](https://github.com/SyntaxArc/ArchiPy)**. Works with both **Cursor** and **Claude Code**. +Rules and skills for **application teams that build +with [ArchiPy](https://github.com/SyntaxArc/ArchiPy)**. Works with **Codex**, **Cursor**, and **Claude Code**. ## What this is @@ -16,13 +16,13 @@ It ships: - **Rules** — persistent guidance while editing matching files - **Agents** — `archipy-reviewer` for architecture reviews of app diffs -- **Skills** — scaffolding and docs workflows, also invocable as slash commands (`/scaffold-app`, `/docs-helpers`, …) +- **Skills** — scaffolding and docs workflows, invocable as Codex `$skill-name` or Cursor / Claude slash commands It is **not** for maintaining the ArchiPy library itself (no library changelog or core BDD internals). ## Requirements -- [Cursor](https://cursor.com/) with plugin support, **or** [Claude Code](https://code.claude.com/) with plugin support +- [Codex](https://developers.openai.com/plugins/build/plugins), [Cursor](https://cursor.com/) with plugin support, or [Claude Code](https://code.claude.com/) with plugin support - Apps targeting **Python 3.14+** - [`uv`](https://docs.astral.sh/uv/) package manager - PyPI package [`archipy`](https://pypi.org/project/archipy/) (install the extras your service needs) @@ -70,6 +70,17 @@ Then restart Claude Code or run `/reload-plugins`. /plugin install archipy@archipy ``` +### Codex — GitHub marketplace + +```bash +codex plugin marketplace add SyntaxArc/archipy-plugin +codex plugin add archipy@archipy +``` + +Restart Codex or start a new session after installation. Invoke skills as `$skill-name` (for example, `$scaffold-app`). +Codex asks you to review and trust the bundled hooks before running them. Codex loads skills and hooks; the +`archipy-reviewer` subagent remains available only in Cursor and Claude Code. + ### Companion plugin: pr-steward The issue, branch, PR, checklist and merge workflow is not part of this plugin. Install @@ -106,11 +117,12 @@ The issue, branch, PR, checklist and merge workflow is not part of this plugin. ### Skills (22) -Every skill is a slash command in both Cursor and Claude Code (Claude Code namespaces them as `/archipy:`). +Cursor and Claude Code expose skills as slash commands (Claude Code namespaces them as `/archipy:`); Codex +invokes them as `$skill-name`. `docs-*` skills set `disable-model-invocation: true`: they are user shortcuts into `archipy-docs`, so the model sees each workflow once. -| Skill | Slash | Invoked by | When to use | +| Skill | Cursor / Claude command | Invoked by | When to use | |--------------------------|---------------------------|-------------|-------------------------------------------------------------------------| | `scaffold-app` | `/scaffold-app` | Model + you | Bootstrap a new ArchiPy-based service layout | | `scaffold-domain` | `/scaffold-domain` | Model + you | Full domain slice (models, repo, logic, service) | @@ -150,10 +162,10 @@ the layer-producing scaffold skills run it in their `## Verify` step. Claude Cod ## Quick start -1. Install the plugin locally (symlink above) and reload Cursor. +1. Install the plugin above. For Codex, restart Codex or start a new session after installation. 2. Open an application workspace (empty or existing Python service). -3. In Agent chat, run `/scaffold-app` — answer package name and extras (e.g. `redis`). -4. Run `/docs-quickstart` to confirm config + first adapter steps. +3. In Agent chat, invoke `$scaffold-app` in Codex or `/scaffold-app` in Cursor / Claude Code — answer package name and extras (e.g. `redis`). +4. Invoke `$docs-quickstart` in Codex or `/docs-quickstart` elsewhere to confirm config + first adapter steps. 5. Expect: `AppConfig`, models stub, `repositories//`, optional `manage.py` (if `fastapi`), helpers tree, `.env.example`. @@ -350,6 +362,7 @@ archipy-plugin/ │ ├── plugin.json # Cursor plugin manifest │ └── marketplace.json # Cursor marketplace catalog ├── hooks/ # Cursor hooks.json + Claude claude-hooks.json +├── .codex-plugin/ # Codex manifest and hooks ├── scripts/ # Catalog checks + hook scripts ├── rules/ # .mdc rules ├── skills/ # SKILL.md directories (+ docs reference) @@ -364,11 +377,11 @@ archipy-plugin/ ``` Cursor loads `rules/` (`.mdc`), `skills/`, and `hooks/hooks.json`. Claude Code loads `skills/` and -`hooks/claude-hooks.json`. Claude Code does **not** load Cursor `.mdc` rules. In projects that depend on `archipy`, hooks in both tools add a -reminder and the app's ArchiPy version at session start and block creating new domain adapters outside -`repositories/{domain}/adapters/`; in Claude Code they also inject always-on and glob-matched rule text (once per -session). See `CONTRIBUTING.md` § Hooks. -Skills double as slash commands; only the `docs-*` shortcuts set `disable-model-invocation: true`. +`hooks/claude-hooks.json`. Codex loads `skills/` and the hooks declared in `.codex-plugin/plugin.json`; it does not +load Cursor `.mdc` rules natively. In projects that depend on `archipy`, all three clients add a reminder and the +app's ArchiPy version at session start. Claude Code and Codex also inject always-on and path-matched rule text. The +adapter guard handles Claude `Write` and Codex `apply_patch` operations. See `CONTRIBUTING.md` § Hooks. +Only the `docs-*` shortcuts set `disable-model-invocation: true`. ## ArchiPy docs map @@ -388,10 +401,9 @@ Skills double as slash commands; only the `docs-*` shortcuts set `disable-model- ## Developing / contributing -See [CONTRIBUTING.md](CONTRIBUTING.md) for the full checklist (version bump across four JSON files, catalog sync, CI). +See [CONTRIBUTING.md](CONTRIBUTING.md) for the full checklist (version bump across five JSON files, catalog sync, CI). -1. Clone this repo and symlink it to `~/.cursor/plugins/local/archipy` (Cursor) or `~/.claude/plugins/local/archipy` - (Claude Code). +1. Clone this repo and install it in your client using the steps above (Codex, Cursor, or Claude Code). 2. Edit rules (`.mdc` frontmatter: `description`, `alwaysApply` / `globs`), skills (`name` + `description` matching folder name), `docs-*` skills also set `disable-model-invocation: true`. diff --git a/scripts/check_catalog.py b/scripts/check_catalog.py index 3899cce..6bed055 100755 --- a/scripts/check_catalog.py +++ b/scripts/check_catalog.py @@ -13,6 +13,7 @@ MANIFESTS = ( ROOT / ".cursor-plugin" / "plugin.json", ROOT / ".claude-plugin" / "plugin.json", + ROOT / ".codex-plugin" / "plugin.json", ROOT / ".cursor-plugin" / "marketplace.json", ROOT / ".claude-plugin" / "marketplace.json", ) diff --git a/scripts/scaffold_hygiene.py b/scripts/scaffold_hygiene.py index c380cc3..69c70d2 100755 --- a/scripts/scaffold_hygiene.py +++ b/scripts/scaffold_hygiene.py @@ -21,10 +21,10 @@ "Domain adapters under repositories/{domain}/adapters/ only. " "Prefer archipy.helpers.utils (DatetimeUtils, PasswordUtils, JWTUtils, TOTPUtils, StringUtils, FileUtils, AppUtils) " "over hand-rolled datetime/password/JWT/string code. " - "Prefer the plugin skills (/scaffold-*, /redis-search, archipy-docs)." + "Prefer the plugin skills (scaffold-*, redis-search, archipy-docs)." ) -# Cursor event names (camelCase). Claude Code uses PascalCase and a different hooks.json schema. +# Cursor event names (camelCase). Claude Code and Codex use PascalCase with hookSpecificOutput. CURSOR_SESSION = "sessionStart" CURSOR_POST = "postToolUse" CLAUDE_SESSION = "SessionStart" @@ -37,10 +37,14 @@ UV_LOCK_ARCHIPY_RE = re.compile(r'^\[\[package\]\]\nname = "archipy"\nversion = "([^"]+)"', re.MULTILINE) PYPROJECT_ARCHIPY_RE = re.compile(r"""["']archipy(?:\[([^\]]*)\])?\s*([<>=~!][^"']*)?["']""") ARCHIPY_DEP_RE = re.compile(r"""(^|[\s"'\[,])archipy([\s"'\[\]=<>~!,]|$)""", re.MULTILINE) +APPLY_PATCH_PATH_RE = re.compile( + r"^\*\*\* (?:Add|Update|Delete) File: (.+)$|^\*\*\* Move to: (.+)$", + re.MULTILINE, +) def _plugin_root() -> Path: - for key in ("CLAUDE_PLUGIN_ROOT", "CURSOR_PLUGIN_ROOT"): + for key in ("PLUGIN_ROOT", "CLAUDE_PLUGIN_ROOT", "CURSOR_PLUGIN_ROOT"): raw = os.environ.get(key) if raw: return Path(raw) @@ -62,12 +66,12 @@ def _emit(payload: dict[str, Any]) -> None: def _emit_claude(event: str, context: str) -> dict[str, Any]: - """Build Claude Code hook output; Claude ignores Cursor's top-level `additional_context`.""" + """Build Claude Code / Codex hook output; Cursor ignores `hookSpecificOutput`.""" return {"hookSpecificOutput": {"hookEventName": event, "additionalContext": context}} def _project_dir(payload: dict[str, Any]) -> Path: - """Claude sends `cwd`; Cursor sends `cwd` on tool events and `workspace_roots` on every event.""" + """Claude Code and Codex send `cwd`; Cursor also sends `workspace_roots` on every event.""" roots = payload.get("workspace_roots") root = roots[0] if isinstance(roots, list) and roots else None return Path(str(payload.get("cwd") or root or os.environ.get("CLAUDE_PROJECT_DIR") or Path.cwd())) @@ -165,6 +169,9 @@ def _paths_from_payload(payload: dict[str, Any]) -> list[str]: value = tool_input.get(key) if value: paths.append(str(value)) + if payload.get("tool_name") == "apply_patch" and isinstance(tool_input.get("command"), str): + for match in APPLY_PATCH_PATH_RE.finditer(tool_input["command"]): + paths.append(match.group(1) or match.group(2)) elif isinstance(tool_input, str): try: parsed = json.loads(tool_input) @@ -292,11 +299,11 @@ def _relative_to_cwd(file_path: str, cwd: str) -> str | None: def _new_adapter_violation(payload: dict[str, Any]) -> str | None: - """Reason to block a Write that creates a domain adapter outside repositories/{domain}/adapters/. + """Reason to block a Write/apply_patch that creates an adapter outside repositories/{domain}/adapters/. Only new files are blocked: legacy apps must still be able to edit an existing top-level adapters/ package. """ - if payload.get("tool_name") != "Write" or not _is_archipy_app(payload): + if payload.get("tool_name") not in {"Write", "apply_patch"} or not _is_archipy_app(payload): return None cwd = str(_project_dir(payload)) for file_path in _paths_from_payload(payload): diff --git a/skills/redis-search/SKILL.md b/skills/redis-search/SKILL.md index 11ea9f7..1052b09 100644 --- a/skills/redis-search/SKILL.md +++ b/skills/redis-search/SKILL.md @@ -21,7 +21,7 @@ to this `SKILL.md`'s directory in the plugin installation — not the app worksp `reference/fulltext_adapter.py`, `reference/vector_adapter.py`, `reference/search_cache_adapter.py`. Resolve files under `reference/` relative to this `SKILL.md` in the plugin installation -(`$CURSOR_PLUGIN_ROOT/skills/redis-search/` or `${CLAUDE_SKILL_DIR}/`). These are plugin templates, +(`$PLUGIN_ROOT/skills/redis-search/`, `$CURSOR_PLUGIN_ROOT/skills/redis-search/`, or `${CLAUDE_SKILL_DIR}/`). These are plugin templates, not app-relative paths. Copy and adapt them into the app; never edit the plugin copies. ## Read first diff --git a/skills/scaffold-bdd/SKILL.md b/skills/scaffold-bdd/SKILL.md index 1cf90b4..9a04f19 100644 --- a/skills/scaffold-bdd/SKILL.md +++ b/skills/scaffold-bdd/SKILL.md @@ -39,7 +39,7 @@ FastAPI's `TestClient` needs nothing extra with `archipy[fastapi]`. gRPC tests n ## Generate Resolve files under `reference/` relative to this `SKILL.md` in the plugin installation -(`$CURSOR_PLUGIN_ROOT/skills/scaffold-bdd/` or `${CLAUDE_SKILL_DIR}/`). These are +(`$PLUGIN_ROOT/skills/scaffold-bdd/`, `$CURSOR_PLUGIN_ROOT/skills/scaffold-bdd/`, or `${CLAUDE_SKILL_DIR}/`). These are plugin templates, not app-relative paths. Copy and adapt them into the app; never edit the plugin copies. **Copy templates from `reference/`, adapt package imports, create only if missing:** diff --git a/skills/scaffold-domain/SKILL.md b/skills/scaffold-domain/SKILL.md index 1c8edfa..ab2efb2 100644 --- a/skills/scaffold-domain/SKILL.md +++ b/skills/scaffold-domain/SKILL.md @@ -32,8 +32,8 @@ Read these plugin rules in full before generating files (paths relative to this ## Compose — do not fork templates Before generating files, read these plugin skills in full. Resolve `../...` paths relative to this `SKILL.md` file's -directory in the plugin installation (`$CURSOR_PLUGIN_ROOT/skills/scaffold-domain/` or -`${CLAUDE_SKILL_DIR}/`) — not relative to the app workspace: +directory in the plugin installation (`$PLUGIN_ROOT/skills/scaffold-domain/`, +`$CURSOR_PLUGIN_ROOT/skills/scaffold-domain/`, or `${CLAUDE_SKILL_DIR}/`) — not relative to the app workspace: - `../scaffold-models/SKILL.md` - `../scaffold-adapter/SKILL.md` diff --git a/skills/scaffold-health-checks/SKILL.md b/skills/scaffold-health-checks/SKILL.md index 9e3fef2..eccac3e 100644 --- a/skills/scaffold-health-checks/SKILL.md +++ b/skills/scaffold-health-checks/SKILL.md @@ -61,7 +61,7 @@ styles on one server. ## Generate Resolve files under `reference/` relative to this `SKILL.md` in the plugin installation -(`$CURSOR_PLUGIN_ROOT/skills/scaffold-health-checks/` or +(`$PLUGIN_ROOT/skills/scaffold-health-checks/`, `$CURSOR_PLUGIN_ROOT/skills/scaffold-health-checks/`, or `${CLAUDE_SKILL_DIR}/`). These are plugin templates, not app-relative paths. Copy and adapt them into the app; never edit the plugin copies.