wordpress-agent-kit 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/.github/agents/wp-architect.agent.md +1 -0
  2. package/.github/skills/wordpress-router/SKILL.md +1 -0
  3. package/.github/skills/wp-abilities-api/SKILL.md +1 -0
  4. package/.github/skills/wp-block-development/SKILL.md +1 -0
  5. package/.github/skills/wp-block-themes/SKILL.md +1 -0
  6. package/.github/skills/wp-interactivity-api/SKILL.md +1 -0
  7. package/.github/skills/wp-performance/SKILL.md +1 -0
  8. package/.github/skills/wp-phpstan/SKILL.md +1 -0
  9. package/.github/skills/wp-playground/SKILL.md +1 -0
  10. package/.github/skills/wp-plugin-development/SKILL.md +1 -0
  11. package/.github/skills/wp-project-triage/SKILL.md +1 -0
  12. package/.github/skills/wp-rest-api/SKILL.md +1 -0
  13. package/.github/skills/wp-wpcli-and-ops/SKILL.md +1 -0
  14. package/.github/skills/wpds/SKILL.md +1 -0
  15. package/.github/workflows/ci.yml +44 -0
  16. package/.husky/pre-commit +7 -0
  17. package/AGENTS.md +33 -10
  18. package/AGENTS.template.md +63 -18
  19. package/CLI_REVIEW.md +250 -0
  20. package/README.md +240 -68
  21. package/biome.json +39 -0
  22. package/dist/cli.js +75 -4
  23. package/dist/commands/install.js +84 -10
  24. package/dist/commands/run-playground.js +59 -14
  25. package/dist/commands/setup.js +222 -163
  26. package/dist/commands/sync-skills.js +33 -60
  27. package/dist/commands/upgrade.js +211 -0
  28. package/dist/lib/api.js +511 -0
  29. package/dist/lib/installer.js +114 -6
  30. package/dist/lib/triage-mapper.js +18 -20
  31. package/dist/lib/updater.js +260 -0
  32. package/dist/utils/exit-codes.js +60 -0
  33. package/dist/utils/output.js +96 -0
  34. package/dist/utils/paths.js +1 -1
  35. package/dist/utils/run.js +1 -1
  36. package/extensions/wp-agent-kit/index.ts +630 -0
  37. package/package.json +27 -4
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  name: WordPress Architect
3
3
  description: Expert developer that orchestrates Agent Skills, official Handbooks, and project-specific instructions.
4
+ license: GPL-2.0-or-later
4
5
  ---
5
6
 
6
7
  # Role
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  name: wordpress-router
3
3
  description: "Use when the user asks about WordPress codebases (plugins, themes, block themes, Gutenberg blocks, WP core checkouts) and you need to quickly classify the repo and route to the correct workflow/skill (blocks, theme.json, REST API, WP-CLI, performance, security, testing, release packaging)."
4
+ license: GPL-2.0-or-later
4
5
  compatibility: "Targets WordPress 6.9+ (PHP 7.2.24+). Filesystem-based agent with bash + node. Some workflows require WP-CLI."
5
6
  ---
6
7
 
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  name: wp-abilities-api
3
3
  description: "Use when working with the WordPress Abilities API (wp_register_ability, wp_register_ability_category, /wp-json/wp-abilities/v1/*, @wordpress/abilities) including defining abilities, categories, meta, REST exposure, and permissions checks for clients."
4
+ license: GPL-2.0-or-later
4
5
  compatibility: "Targets WordPress 6.9+ (PHP 7.2.24+). Filesystem-based agent with bash + node. Some workflows require WP-CLI."
5
6
  ---
6
7
 
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  name: wp-block-development
3
3
  description: "Use when developing WordPress (Gutenberg) blocks: block.json metadata, register_block_type(_from_metadata), attributes/serialization, supports, dynamic rendering (render.php/render_callback), deprecations/migrations, viewScript vs viewScriptModule, and @wordpress/scripts/@wordpress/create-block build and test workflows."
4
+ license: GPL-2.0-or-later
4
5
  compatibility: "Targets WordPress 6.9+ (PHP 7.2.24+). Filesystem-based agent with bash + node. Some workflows require WP-CLI."
5
6
  ---
6
7
 
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  name: wp-block-themes
3
3
  description: "Use when developing WordPress block themes: theme.json (global settings/styles), templates and template parts, patterns, style variations, and Site Editor troubleshooting (style hierarchy, overrides, caching)."
4
+ license: GPL-2.0-or-later
4
5
  compatibility: "Targets WordPress 6.9+ (PHP 7.2.24+). Filesystem-based agent with bash + node. Some workflows require WP-CLI."
5
6
  ---
6
7
 
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  name: wp-interactivity-api
3
3
  description: "Use when building or debugging WordPress Interactivity API features (data-wp-* directives, @wordpress/interactivity store/state/actions, block viewScriptModule integration, wp_interactivity_*()) including performance, hydration, and directive behavior."
4
+ license: GPL-2.0-or-later
4
5
  compatibility: "Targets WordPress 6.9+ (PHP 7.2.24+). Filesystem-based agent with bash + node. Some workflows require WP-CLI."
5
6
  ---
6
7
 
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  name: wp-performance
3
3
  description: "Use when investigating or improving WordPress performance (backend-only agent): profiling and measurement (WP-CLI profile/doctor, Server-Timing, Query Monitor via REST headers), database/query optimization, autoloaded options, object caching, cron, HTTP API calls, and safe verification."
4
+ license: GPL-2.0-or-later
4
5
  compatibility: "Targets WordPress 6.9+ (PHP 7.2.24+). Backend-only agent; prefers WP-CLI (doctor/profile) when available."
5
6
  ---
6
7
 
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  name: wp-phpstan
3
3
  description: "Use when configuring, running, or fixing PHPStan static analysis in WordPress projects (plugins/themes/sites): phpstan.neon setup, baselines, WordPress-specific typing, and handling third-party plugin classes."
4
+ license: GPL-2.0-or-later
4
5
  compatibility: "Targets WordPress 6.9+ (PHP 7.2.24+). Requires Composer-based PHPStan."
5
6
  ---
6
7
 
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  name: wp-playground
3
3
  description: "Use for WordPress Playground workflows: fast disposable WP instances in the browser or locally via @wp-playground/cli (server, run-blueprint, build-snapshot), auto-mounting plugins/themes, switching WP/PHP versions, blueprints, and debugging (Xdebug)."
4
+ license: GPL-2.0-or-later
4
5
  compatibility: "Targets WordPress 6.9+ (PHP 7.2.24+). Playground CLI requires Node.js 20.18+; runs WP in WebAssembly with SQLite."
5
6
  ---
6
7
 
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  name: wp-plugin-development
3
3
  description: "Use when developing WordPress plugins: architecture and hooks, activation/deactivation/uninstall, admin UI and Settings API, data storage, cron/tasks, security (nonces/capabilities/sanitization/escaping), and release packaging."
4
+ license: GPL-2.0-or-later
4
5
  compatibility: "Targets WordPress 6.9+ (PHP 7.2.24+). Filesystem-based agent with bash + node. Some workflows require WP-CLI."
5
6
  ---
6
7
 
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  name: wp-project-triage
3
3
  description: "Use when you need a deterministic inspection of a WordPress repository (plugin/theme/block theme/WP core/Gutenberg/full site) including tooling/tests/version hints, and a structured JSON report to guide workflows and guardrails."
4
+ license: GPL-2.0-or-later
4
5
  compatibility: "Targets WordPress 6.9+ (PHP 7.2.24+). Filesystem-based agent with bash + node. Some workflows require WP-CLI."
5
6
  ---
6
7
 
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  name: wp-rest-api
3
3
  description: "Use when building, extending, or debugging WordPress REST API endpoints/routes: register_rest_route, WP_REST_Controller/controller classes, schema/argument validation, permission_callback/authentication, response shaping, register_rest_field/register_meta, or exposing CPTs/taxonomies via show_in_rest."
4
+ license: GPL-2.0-or-later
4
5
  compatibility: "Targets WordPress 6.9+ (PHP 7.2.24+). Filesystem-based agent with bash + node. Some workflows require WP-CLI."
5
6
  ---
6
7
 
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  name: wp-wpcli-and-ops
3
3
  description: "Use when working with WP-CLI (wp) for WordPress operations: safe search-replace, db export/import, plugin/theme/user/content management, cron, cache flushing, multisite, and scripting/automation with wp-cli.yml."
4
+ license: GPL-2.0-or-later
4
5
  compatibility: "Targets WordPress 6.9+ (PHP 7.2.24+). Requires WP-CLI in the execution environment."
5
6
  ---
6
7
 
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  name: wpds
3
3
  description: "Use when building UIs leveraging the WordPress Design System (WPDS) and its components, tokens, patterns, etc."
4
+ license: GPL-2.0-or-later
4
5
  compatibility: "Requires WPDS MCP server configured and running. Targets WordPress 6.9+ (PHP 7.2.24+)."
5
6
  ---
6
7
 
@@ -0,0 +1,44 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main, master]
6
+ pull_request:
7
+ branches: [main, master]
8
+
9
+ jobs:
10
+ lint-and-test:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - name: Checkout repository
14
+ uses: actions/checkout@v4
15
+
16
+ - name: Setup pnpm
17
+ uses: pnpm/action-setup@v4
18
+ with:
19
+ version: 9
20
+ run_install: false
21
+
22
+ - name: Setup Node.js
23
+ uses: actions/setup-node@v4
24
+ with:
25
+ node-version: '22'
26
+ cache: 'pnpm'
27
+
28
+ - name: Install dependencies
29
+ run: pnpm install --frozen-lockfile
30
+
31
+ - name: Check formatting
32
+ run: pnpm run format:check
33
+
34
+ - name: Run lint
35
+ run: pnpm run lint:check
36
+
37
+ - name: Type check
38
+ run: pnpm run check
39
+
40
+ - name: Run tests
41
+ run: pnpm run test:run
42
+
43
+ - name: Build
44
+ run: pnpm run build
@@ -0,0 +1,7 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ pnpm exec biome check --write .
5
+ git add -A
6
+ pnpm run lint:check
7
+ pnpm run test:run
package/AGENTS.md CHANGED
@@ -8,32 +8,55 @@ This is a Node.js CLI tool (`wp-agent-kit`) designed to scaffold AI agent config
8
8
  - **Prompting**: `@clack/prompts`
9
9
  - **Build**: `tsc` (TypeScript Compiler)
10
10
  - **Test**: `vitest`
11
+ - **Lint/Format**: Biome + ESLint
11
12
 
12
13
  ## Architecture
13
14
  - **Entry Point**: `src/cli.ts`
14
- - **Commands**: `src/commands/*.ts` (e.g., `install`, `setup`, `sync-skills`, `playground`)
15
- - **Core Logic**: `src/lib/*.ts` (e.g., `installer.ts` for file copying, `triage-mapper.ts` for project detection)
16
- - **Utilities**: `src/utils/*.ts` (e.g., `paths.ts`, `run.ts`)
15
+ - **Commands**: `src/commands/*.ts` (e.g., `install`, `setup`, `sync-skills`, `playground`, `upgrade`)
16
+ - **Core Logic**: `src/lib/*.ts` (e.g., `installer.ts` for file copying, `triage-mapper.ts` for project detection, `api.ts` for programmatic API)
17
+ - **Utilities**: `src/utils/*.ts` (e.g., `paths.ts`, `run.ts`, `output.ts`, `exit-codes.ts`)
17
18
  - **Assets**:
18
19
  - `AGENTS.template.md`: The template file copied to user projects.
19
- - `.github/`: The source of skills and instructions copied to user projects.
20
+ - `.github/`: The source of skills (14 WordPress skills), instructions, agents, and prompts copied to user projects.
20
21
  - `vendor/wp-agent-skills/`: Submodule containing upstream skills.
21
22
 
23
+ ## Package Exports
24
+ - `wordpress-agent-kit` → CLI entry (`dist/cli.js`)
25
+ - `wordpress-agent-kit/api` → Programmatic API (`dist/lib/api.js`)
26
+
22
27
  ## Development Workflow
23
28
  - **Run locally**: `npm run dev` (uses `tsx src/cli.ts`)
24
29
  - **Build**: `npm run build` (outputs to `dist/`)
30
+ - **TypeCheck**: `npm run check` (no-emit type checking)
25
31
  - **Test**: `npm test` (runs Vitest)
26
- - **Lint**: `npm run lint`
32
+ - **Lint**: `npm run lint:check` (ESLint + Biome)
33
+ - **Format**: `npm run format` (Prettier + Biome)
34
+ - **Pre-commit**: Husky runs lint:check + test:run
27
35
 
28
36
  ## Key Commands
29
- - `install`: Copies `.github` and `AGENTS.md` template to a target directory.
30
- - `setup`: Interactive wizard that detects project type and configures the kit.
31
- - `sync-skills`: Pulls skills from `WordPress/agent-skills` into `.github/skills`.
37
+ - `install`: Copies `.github` and `AGENTS.md` template to a target directory. Supports `--json`, `--dry-run`, `--ndjson`.
38
+ - `setup`: Interactive wizard that detects project type and configures the kit. Supports `--auto`, `--project-type`, `--tech-stack`, `--yes`.
39
+ - `sync-skills`: Pulls skills from `WordPress/agent-skills` into `.github/skills`. Supports `--json`, `--dry-run`.
32
40
  - `playground`: Launches a local WordPress Playground instance using a blueprint.
33
- - `build-release`: Packages the CLI for release.
41
+ - `upgrade`: Checks for and applies newer versions. Supports `--check-only`, `--force`, `--json`.
42
+
43
+ ## Agent-Friendly Features (v0.3.0+)
44
+ - `--json`: Structured JSON output with success/data/error/time fields
45
+ - `--dry-run`: Preview mode showing what would happen without making changes
46
+ - `--ndjson`: Newline-delimited JSON for streaming long operations
47
+ - `--quiet`: Suppress non-essential output
48
+ - **Semantic exit codes**: 0=OK, 2=Invalid Args, 3=Not Found, 4=Permission Denied, 5=Already Exists, 6=Git Error, 7=Network Error, 8=Validation Error, 130=Cancelled
49
+ - **Programmatic API**: `import { installKitApi, syncSkillsApi, runTriageApi, configureAgentsMdApi } from 'wordpress-agent-kit/api'`
34
50
 
35
51
  ## Notes for Agents
36
52
  - When modifying commands, ensure you update the corresponding JSDoc comments.
37
53
  - The `src/lib/installer.ts` file is critical as it handles the file copying logic.
38
54
  - The `src/lib/triage-mapper.ts` file contains logic for mapping project detection results to configuration options.
39
- - The `vendor` directory is gitignored and populated via submodule or script.
55
+ - The `src/lib/api.ts` file exposes the programmatic API all changes to command logic should flow through to the API.
56
+ - The `vendor` directory is gitignored and populated via submodule or script.
57
+ - The `.github/skills/` directory contains 14 WordPress skills following the AgentSkills.io spec.
58
+ - CI runs on every push: lint, typecheck, test, build. No publish workflow (manual npm publish only).
59
+
60
+ ## Pi Extension (Package)
61
+ - `pi.extensions`: `./extensions/wp-agent-kit` — registers WordPress agent tools
62
+ - `pi.skills`: `./.github/skills` — 14 WordPress skills discoverable by Pi
@@ -1,31 +1,76 @@
1
1
  # Project: WordPress Codebase
2
2
 
3
- This repository is WordPress-centric (plugin, theme, or site). Agents should prioritize local skills and official WordPress standards.
3
+ This repository is WordPress-centric (plugin, theme, block theme, or site). Agents should prioritize local skills and official WordPress standards.
4
4
 
5
5
  ## Onboarding
6
6
 
7
- - Core agent: `.github/agents/wp-architect.agent.md`
8
- - Workflow: `.github/instructions/wordpress-workflow.instructions.md`
9
- - Skills live in: `.github/skills/`
7
+ - **Core Agent**: `.github/agents/wp-architect.agent.md` — the primary agent persona
8
+ - **Workflow Instructions**: `.github/instructions/wordpress-workflow.instructions.md` — project-specific conventions
9
+ - **Skills**: `.github/skills/` — specialized agent skills for WordPress development
10
10
 
11
- ## Project Discovery (required before changes)
11
+ ## Project Discovery (Required Before Changes)
12
12
 
13
- 1. Run project triage:
14
- - `node .github/skills/wp-project-triage/scripts/detect_wp_project.mjs`
15
- 2. If routing is unclear, use the router decision tree:
16
- - `.github/skills/wordpress-router/references/decision-tree.md`
17
- 3. Update repo-specific guidance:
18
- - Choose the project prefix based on existing code (functions/classes/constants).
19
- - Confirm folder structure (single-file plugin vs `includes/`, blocks, theme, full site).
20
- - Confirm target WordPress/PHP versions if relevant.
13
+ 1. **Run project triage** to classify the codebase:
14
+ ```bash
15
+ node .github/skills/wp-project-triage/scripts/detect_wp_project.mjs
16
+ ```
17
+ This outputs a JSON report with project kind, signals, and tooling.
18
+
19
+ 2. **Route to the right skill**:
20
+ - If routing is unclear, consult `.github/skills/wordpress-router/references/decision-tree.md`
21
+ - For plugins: `wp-plugin-development`
22
+ - For block themes: `wp-block-themes`
23
+ - For Gutenberg blocks: `wp-block-development`
24
+ - For REST API work: `wp-rest-api`
25
+ - For WP-CLI operations: `wp-wpcli-and-ops`
26
+
27
+ 3. **Update repo-specific guidance** based on triage results:
28
+ - Confirm the project prefix (functions, classes, constants)
29
+ - Confirm the folder structure (single-file plugin, `includes/`, blocks, theme, full site)
30
+ - Confirm target WordPress and PHP versions
31
+
32
+ ## Architecture
33
+
34
+ <!-- Populated by project triage — do not remove -->
35
+
36
+ - **Project Type**: <!-- plugin | theme | block-theme | site | gutenberg -->
37
+ - **PHP Version**: <!-- minimum PHP version -->
38
+ - **WP Version**: <!-- minimum WordPress version -->
39
+ - **Build Tool**: <!-- webpack | @wordpress/scripts | vite | none -->
40
+ - **Test Framework**: <!-- PHPUnit | Jest | Cypress | none -->
41
+
42
+ ## Commands
43
+
44
+ <!-- Populated by project triage — do not remove -->
45
+
46
+ | Purpose | Command |
47
+ |---------|---------|
48
+ | Build | <!-- e.g., npm run build --> |
49
+ | Lint (PHP) | <!-- e.g., composer lint --> |
50
+ | Lint (JS/CSS) | <!-- e.g., npm run lint --> |
51
+ | Test | <!-- e.g., npm test, composer test --> |
52
+ | Dev server | <!-- e.g., npm start --> |
53
+
54
+ ## Code Conventions
55
+
56
+ <!-- Populated by project triage — do not remove -->
57
+
58
+ - **Prefix**: <!-- e.g., myplugin_ for functions, MyPlugin\ for namespaces -->
59
+ - **Indentation**: Tabs for PHP, <!-- 2 spaces for JS -->
60
+ - **PHP Standards**: [WordPress PHP Coding Standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/)
61
+ - **JS Standards**: <!-- WordPress JS standards -->
21
62
 
22
63
  ## Security Baseline
23
64
 
24
- - Sanitize input early, escape output late.
25
- - Use nonces for state-changing requests.
26
- - Enforce capabilities for privileged actions.
65
+ - **Sanitize Early**: Validate and sanitize all user input (`sanitize_text_field`, `sanitize_email`, etc.)
66
+ - **Escape Late**: Escape all output (`esc_html`, `esc_attr`, `esc_url`, `wp_kses`)
67
+ - **Use Nonces**: All state-changing requests must include nonce verification (`wp_nonce_field`, `check_admin_referer`)
68
+ - **Check Capabilities**: Privileged actions require capability checks (`current_user_can`)
69
+ - **Validate AJAX/REST**: Use `permission_callback` for REST endpoints and capability checks for AJAX handlers
27
70
 
28
71
  ## Output Requirements
29
72
 
30
- - Prefer minimal, standards-compliant changes.
31
- - Follow existing conventions in the codebase.
73
+ - Prefer minimal, standards-compliant changes over large rewrites
74
+ - Follow existing conventions in the codebase (naming, patterns, architecture)
75
+ - Cite which skill or handbook informed the solution
76
+ - Cross-check against this file (`AGENTS.md`) before finalizing output
package/CLI_REVIEW.md ADDED
@@ -0,0 +1,250 @@
1
+ # WordPress Agent Kit CLI - Accessibility & Agent-Friendly Review
2
+
3
+ **Date**: 2026-06-08
4
+ **Version**: 0.2.1
5
+
6
+ ---
7
+
8
+ ## Executive Summary
9
+
10
+ The current CLI is functional for **human developers** using interactive prompts (`@clack/prompts`), but lacks features for **programmatic/agent usage**:
11
+
12
+ - ❌ No JSON output mode
13
+ - ❌ No machine-readable result objects
14
+ - ❌ No programmatic API (only CLI entrypoint)
15
+ - ❌ No non-interactive "headless" mode for all commands
16
+ - ❌ No structured logging/event streaming
17
+ - ❌ Exit codes not consistently semantic
18
+
19
+ ---
20
+
21
+ ## Current Architecture
22
+
23
+ ```
24
+ src/
25
+ ├── cli.ts # Entry point, Commander setup
26
+ ├── commands/
27
+ │ ├── install.ts # Non-interactive (args + flags only) ✓
28
+ │ ├── setup.ts # Interactive (prompts only) ✗
29
+ │ ├── sync-skills.ts # Non-interactive (args + flags only) ✓
30
+ │ └── run-playground.ts # Non-interactive ✓
31
+ ├── lib/
32
+ │ ├── installer.ts # Core logic (pure functions) ✓
33
+ │ └── triage-mapper.ts # Pure mappers ✓
34
+ └── utils/
35
+ ├── paths.ts # Path resolution
36
+ └── run.ts # Command runner
37
+ ```
38
+
39
+ **Good**: Core logic (`installKit`, mappers) is pure and testable.
40
+ **Gap**: `setup.ts` couples interactive prompts with business logic.
41
+
42
+ ---
43
+
44
+ ## Recommendations
45
+
46
+ ### 1. Add JSON Output Mode (--json)
47
+
48
+ **Goal**: Every command outputs structured JSON to stdout when requested.
49
+
50
+ ```bash
51
+ # Success
52
+ wp-agent-kit install /path/to/project --platform github --json
53
+ # {"success":true,"targetDir":"/path/to/project","platform":"github","filesCopied":["AGENTS.md",".github/..."],"durationMs":142}
54
+
55
+ # Failure
56
+ wp-agent-kit install /nonexistent --json
57
+ # {"success":false,"error":"E_NOT_FOUND","message":"Target directory does not exist","code":"ENOENT"}
58
+ ```
59
+
60
+ **Implementation**:
61
+ - Add `--json` / `--output json` global flag in `cli.ts`
62
+ - Create `OutputFormatter` utility: `json`, `human`, `quiet`
63
+ - Return structured result objects from all command actions
64
+ - Separate stdout (JSON) from stderr (human diagnostics)
65
+
66
+ ### 2. Add Machine-Readable Exit Codes
67
+
68
+ | Code | Meaning |
69
+ |------|---------|
70
+ | 0 | Success |
71
+ | 1 | General error |
72
+ | 2 | Invalid arguments / usage |
73
+ | 3 | Target not found / ENOENT |
74
+ | 4 | Permission denied / EACCES |
75
+ | 5 | Already exists (without --force) |
76
+ | 6 | Git/submodule error |
77
+ | 7 | Network/fetch error |
78
+ | 8 | Validation failed |
79
+ | 130 | Cancelled (SIGINT) |
80
+
81
+ ### 3. Extract Programmatic API
82
+
83
+ Expose core functions for direct import by agents/scripts:
84
+
85
+ ```typescript
86
+ // src/api.ts (new)
87
+ export interface InstallOptions {
88
+ targetDir: string;
89
+ platform: Platform;
90
+ force?: boolean;
91
+ dryRun?: boolean;
92
+ }
93
+
94
+ export interface InstallResult {
95
+ success: boolean;
96
+ targetDir: string;
97
+ platform: Platform;
98
+ filesCreated: string[];
99
+ filesSkipped: string[];
100
+ errors: string[];
101
+ durationMs: number;
102
+ }
103
+
104
+ export async function installKit(options: InstallOptions): Promise<InstallResult>;
105
+ export async function syncSkills(options: SyncOptions): Promise<SyncResult>;
106
+ export async function runTriage(targetDir: string): Promise<TriageResult>;
107
+ export async function configureAgentsMd(options: ConfigureOptions): Promise<ConfigureResult>;
108
+ ```
109
+
110
+ **Benefits**:
111
+ - Agents can import and call directly: `import { installKit } from 'wordpress-agent-kit'`
112
+ - No subprocess overhead
113
+ - Full TypeScript types
114
+ - Testable in isolation
115
+
116
+ ### 4. Make `setup` Command Headless-Capable
117
+
118
+ Current `setup.ts` is prompt-driven. Add non-interactive mode:
119
+
120
+ ```bash
121
+ # Full non-interactive (requires all flags)
122
+ wp-agent-kit setup /path/to/project \
123
+ --project-type plugin \
124
+ --tech-stack gutenberg,rest-api,composer \
125
+ --platform github \
126
+ --yes \
127
+ --json
128
+
129
+ # Hybrid: run triage, apply detected values, no prompts
130
+ wp-agent-kit setup /path/to/project --auto --json
131
+ ```
132
+
133
+ **Flag Matrix for `setup`**:
134
+ | Flag | Description |
135
+ |------|-------------|
136
+ | `--project-type <type>` | plugin \| theme \| block-theme \| site \| blocks \| other |
137
+ | `--tech-stack <list>` | Comma-separated: gutenberg,interactivity,rest-api,wpcli,composer,phpstan,npm,playground |
138
+ | `--platform <platform>` | github \| cursor \| claude \| agent \| pi |
139
+ | `--package-manager <pm>` | npm \| pnpm \| yarn |
140
+ | `--auto` | Run triage, apply detected values, skip prompts |
141
+ | `--yes` / `-y` | Accept all confirmations (requires other flags) |
142
+ | `--reset` | Overwrite existing |
143
+ | `--dry-run` | Show what would be done |
144
+
145
+ ### 5. Add Structured Logging / Event Stream
146
+
147
+ For long-running operations (sync-skills, playground), emit NDJSON events:
148
+
149
+ ```bash
150
+ wp-agent-kit sync-skills --json-stream
151
+ # {"event":"start","phase":"clone","timestamp":"..."}
152
+ # {"event":"progress","phase":"fetch","message":"Fetching tags...","timestamp":"..."}
153
+ # {"event":"complete","phase":"install","result":{"skillsSynced":42,"timestamp":"..."}}
154
+ ```
155
+
156
+ **Events**: `start`, `progress`, `phase-change`, `warning`, `complete`, `error`
157
+
158
+ ### 6. Add Dry-Run / Preview Mode
159
+
160
+ ```bash
161
+ wp-agent-kit install /path --dry-run --json
162
+ # {"wouldCopy":[{"src":"AGENTS.template.md","dest":"/path/AGENTS.md"},{"src":".github/...","dest":"/path/.github/..."}],"wouldCreateDirs":[]}
163
+
164
+ wp-agent-kit setup /path --dry-run --auto --json
165
+ # {"wouldInstall":true,"detectedType":"plugin","detectedTech":["gutenberg","npm"],"wouldModify":["AGENTS.md"]}
166
+ ```
167
+
168
+ ### 7. Add Shell Completion (Modern CLI Standard)
169
+
170
+ ```bash
171
+ # Generate completion scripts
172
+ wp-agent-kit completion bash > /etc/bash_completion.d/wp-agent-kit
173
+ wp-agent-kit completion zsh > ~/.zsh/completions/_wp-agent-kit
174
+ wp-agent-kit completion fish > ~/.config/fish/completions/wp-agent-kit.fish
175
+ ```
176
+
177
+ Commander.js supports this natively: `program.enablePositionalOptions().addHelpCommand().configureOutput({ writeOut: ... })`
178
+
179
+ ### 8. Add `--version` JSON Output
180
+
181
+ ```bash
182
+ wp-agent-kit --version --json
183
+ # {"name":"wp-agent-kit","version":"0.2.1","node":"20.18.0","platform":"linux"}
184
+ ```
185
+
186
+ ---
187
+
188
+ ## Priority Matrix
189
+
190
+ | Priority | Feature | Effort | Impact |
191
+ |----------|---------|--------|--------|
192
+ | **P0** | JSON output (`--json`) | Low | High |
193
+ | **P0** | Semantic exit codes | Low | High |
194
+ | **P0** | Programmatic API export | Medium | High |
195
+ | **P1** | Headless `setup` mode | Medium | High |
196
+ | **P1** | Dry-run/preview | Low | Medium |
197
+ | **P2** | NDJSON event streaming | Medium | Medium |
198
+ | **P2** | Shell completions | Low | Medium |
199
+ | **P3** | Man page generation | Low | Low |
200
+
201
+ ---
202
+
203
+ ## Example: Agent-Friendly Workflow
204
+
205
+ ```bash
206
+ # 1. Agent detects WordPress project
207
+ wp-agent-kit setup /workspace/my-plugin --auto --json
208
+ # {"success":true,"applied":{"projectType":"plugin","techStack":["gutenberg","npm"]},"filesModified":["AGENTS.md"]}
209
+
210
+ # 2. Agent syncs latest skills
211
+ wp-agent-kit sync-skills --json
212
+ # {"success":true,"skillsSynced":47,"source":"WordPress/agent-skills@trunk"}
213
+
214
+ # 3. Agent installs for specific platform (e.g., Cursor)
215
+ wp-agent-kit install /workspace/my-plugin --platform cursor --json
216
+ # {"success":true,"platform":"cursor","targetDir":"/workspace/my-plugin","filesCreated":[".cursor/...","AGENTS.md"]}
217
+ ```
218
+
219
+ ---
220
+
221
+ ## Implementation Notes
222
+
223
+ ### Minimal Changes for P0
224
+
225
+ 1. **cli.ts**: Add global `--json` flag, result formatter
226
+ 2. **commands/*.ts**: Return structured results instead of `process.exit()`
227
+ 3. **lib/installer.ts**: Return `InstallResult` object (already close)
228
+ 4. **package.json**: Add `"exports": { ".": "./dist/cli.js", "./api": "./dist/api.js" }`
229
+
230
+ ### Testing Strategy
231
+
232
+ ```typescript
233
+ // tests/api/install.api.test.ts
234
+ import { installKit } from '../../src/api.js';
235
+
236
+ it('returns structured result on success', async () => {
237
+ const result = await installKit({ targetDir: '/tmp/test', platform: 'github' });
238
+ expect(result.success).toBe(true);
239
+ expect(result.filesCreated).toContain('AGENTS.md');
240
+ });
241
+ ```
242
+
243
+ ---
244
+
245
+ ## References
246
+
247
+ - [Commander.js JSON output patterns](https://github.com/tj/commander.js/blob/master/Examples/options-json.ts)
248
+ - [CLI Guidelines - Output](https://clig.dev/#output)
249
+ - [12-factor CLI apps](https://medium.com/@jdxcode/12-factor-cli-apps-dd3c227a0e46)
250
+ - [GitHub CLI `gh` JSON patterns](https://cli.github.com/manual/gh_help_formatting)