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.
- package/.github/agents/wp-architect.agent.md +1 -0
- package/.github/skills/wordpress-router/SKILL.md +1 -0
- package/.github/skills/wp-abilities-api/SKILL.md +1 -0
- package/.github/skills/wp-block-development/SKILL.md +1 -0
- package/.github/skills/wp-block-themes/SKILL.md +1 -0
- package/.github/skills/wp-interactivity-api/SKILL.md +1 -0
- package/.github/skills/wp-performance/SKILL.md +1 -0
- package/.github/skills/wp-phpstan/SKILL.md +1 -0
- package/.github/skills/wp-playground/SKILL.md +1 -0
- package/.github/skills/wp-plugin-development/SKILL.md +1 -0
- package/.github/skills/wp-project-triage/SKILL.md +1 -0
- package/.github/skills/wp-rest-api/SKILL.md +1 -0
- package/.github/skills/wp-wpcli-and-ops/SKILL.md +1 -0
- package/.github/skills/wpds/SKILL.md +1 -0
- package/.github/workflows/ci.yml +44 -0
- package/.husky/pre-commit +7 -0
- package/AGENTS.md +33 -10
- package/AGENTS.template.md +63 -18
- package/CLI_REVIEW.md +250 -0
- package/README.md +240 -68
- package/biome.json +39 -0
- package/dist/cli.js +75 -4
- package/dist/commands/install.js +84 -10
- package/dist/commands/run-playground.js +59 -14
- package/dist/commands/setup.js +222 -163
- package/dist/commands/sync-skills.js +33 -60
- package/dist/commands/upgrade.js +211 -0
- package/dist/lib/api.js +511 -0
- package/dist/lib/installer.js +114 -6
- package/dist/lib/triage-mapper.js +18 -20
- package/dist/lib/updater.js +260 -0
- package/dist/utils/exit-codes.js +60 -0
- package/dist/utils/output.js +96 -0
- package/dist/utils/paths.js +1 -1
- package/dist/utils/run.js +1 -1
- package/extensions/wp-agent-kit/index.ts +630 -0
- package/package.json +27 -4
package/README.md
CHANGED
|
@@ -2,117 +2,289 @@
|
|
|
2
2
|
|
|
3
3
|
[](LICENSE)
|
|
4
4
|
[](https://www.typescriptlang.org/)
|
|
5
|
-
[](package.json)
|
|
6
|
+
[](package.json)
|
|
7
|
+
[](.github/workflows/ci.yml)
|
|
7
8
|
|
|
8
|
-
**WordPress-focused AI agent starter kit** for GitHub Copilot, Claude, and
|
|
9
|
+
**WordPress-focused AI agent starter kit** for GitHub Copilot, Cursor, Claude, and Pi Coding Agent. Installs 13 specialized WordPress agent skills, an agent persona, workflow instructions, and AGENTS.md configuration — everything an AI coding agent needs to build WordPress plugins, themes, and blocks correctly.
|
|
9
10
|
|
|
10
11
|
Maintained by [Kyle Brodeur](https://brodeur.me).
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
---
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
## Getting Started
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
Choose your scenario:
|
|
18
|
+
|
|
19
|
+
### Scenario 1: Brand New WordPress Project
|
|
17
20
|
|
|
18
21
|
```bash
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
# 1. Install the kit (copies skills, agents, instructions, AGENTS.md template)
|
|
23
|
+
npx wp-agent-kit install /path/to/my-plugin --platform github
|
|
24
|
+
|
|
25
|
+
# 2. Run auto-setup (detects project type and configures AGENTS.md)
|
|
26
|
+
npx wp-agent-kit setup /path/to/my-plugin --auto
|
|
27
|
+
|
|
28
|
+
# 3. (Optional) Verify the triage report
|
|
29
|
+
node .github/skills/wp-project-triage/scripts/detect_wp_project.mjs
|
|
22
30
|
```
|
|
23
31
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
-
|
|
27
|
-
|
|
32
|
+
**What gets installed:**
|
|
33
|
+
```
|
|
34
|
+
my-plugin/
|
|
35
|
+
├── AGENTS.md # Project-specific agent instructions
|
|
36
|
+
├── AGENTS.template.md # Template reference for future updates
|
|
37
|
+
├── .github/
|
|
38
|
+
│ ├── agents/
|
|
39
|
+
│ │ └── wp-architect.agent.md # WordPress Architect agent persona
|
|
40
|
+
│ ├── instructions/
|
|
41
|
+
│ │ └── wordpress-workflow.instructions.md
|
|
42
|
+
│ ├── prompts/
|
|
43
|
+
│ └── skills/ # 13 WordPress skills
|
|
44
|
+
│ ├── wp-project-triage/ # Project detection
|
|
45
|
+
│ ├── wp-plugin-development/ # Plugin architecture
|
|
46
|
+
│ ├── wp-block-development/ # Gutenberg blocks
|
|
47
|
+
│ ├── wp-block-themes/ # Block themes
|
|
48
|
+
│ ├── wp-rest-api/ # REST API
|
|
49
|
+
│ ├── wp-interactivity-api/ # Interactivity API
|
|
50
|
+
│ ├── wp-abilities-api/ # Abilities API
|
|
51
|
+
│ ├── wp-performance/ # Performance profiling
|
|
52
|
+
│ ├── wp-phpstan/ # Static analysis
|
|
53
|
+
│ ├── wp-wpcli-and-ops/ # WP-CLI operations
|
|
54
|
+
│ ├── wp-playground/ # Testing environments
|
|
55
|
+
│ ├── wpds/ # Design system
|
|
56
|
+
│ └── wordpress-router/ # Repo classification
|
|
57
|
+
└── .wp-agent-kit-manifest.github.json # Safe-update tracking
|
|
58
|
+
```
|
|
28
59
|
|
|
29
|
-
###
|
|
60
|
+
### Scenario 2: Existing WordPress Project
|
|
30
61
|
|
|
31
|
-
|
|
62
|
+
```bash
|
|
63
|
+
# 1. Install kit (preserves your existing AGENTS.md)
|
|
64
|
+
npx wp-agent-kit install /path/to/existing-plugin --platform github
|
|
32
65
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
- **`wordpress-agent-kit-agent.tar.gz`** - For generic `.agent` workflows
|
|
36
|
-
- **`wordpress-agent-kit-cursor.tar.gz`** - For Cursor IDE
|
|
66
|
+
# 2. Run triage to detect your project's type, tech stack, and tooling
|
|
67
|
+
node .github/skills/wp-project-triage/scripts/detect_wp_project.mjs
|
|
37
68
|
|
|
38
|
-
|
|
69
|
+
# 3. Configure based on detection (headless)
|
|
70
|
+
npx wp-agent-kit setup /path/to/existing-plugin --auto
|
|
39
71
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
72
|
+
# Or specify explicitly
|
|
73
|
+
npx wp-agent-kit setup /path/to/existing-plugin \
|
|
74
|
+
--project-type plugin \
|
|
75
|
+
--tech-stack gutenberg,rest-api,wpcli,composer,npm \
|
|
76
|
+
--package-manager pnpm \
|
|
77
|
+
--yes
|
|
43
78
|
```
|
|
44
79
|
|
|
45
|
-
|
|
46
|
-
- **
|
|
47
|
-
-
|
|
48
|
-
-
|
|
49
|
-
- Set up prompt templates.
|
|
80
|
+
**Key behavior:**
|
|
81
|
+
- Your existing `AGENTS.md` is **never overwritten** — only new sections are added
|
|
82
|
+
- Triage inspects your codebase and returns structured JSON with project kind, signals, and tooling
|
|
83
|
+
- Setup updates only the tooling/configuration sections of AGENTS.md
|
|
50
84
|
|
|
51
|
-
|
|
85
|
+
### Scenario 3: Upgrading an Existing Kit Installation
|
|
52
86
|
|
|
53
87
|
```bash
|
|
54
|
-
|
|
88
|
+
# Check if an update is available
|
|
89
|
+
npx wp-agent-kit upgrade --check-only
|
|
90
|
+
|
|
91
|
+
# Preview what would change (dry-run)
|
|
92
|
+
npx wp-agent-kit install --dry-run
|
|
93
|
+
|
|
94
|
+
# Apply safe update (preserves your modifications)
|
|
95
|
+
npx wp-agent-kit upgrade --force
|
|
55
96
|
```
|
|
56
97
|
|
|
57
|
-
|
|
58
|
-
-
|
|
59
|
-
-
|
|
60
|
-
-
|
|
98
|
+
**Safe update behavior:**
|
|
99
|
+
- Compares installed files against a manifest of original hashes
|
|
100
|
+
- Files you haven't modified → automatically updated
|
|
101
|
+
- Files you modified → **skipped** (preserved)
|
|
102
|
+
- Use `--force` to overwrite your modifications with upstream changes
|
|
103
|
+
- A backup is created at `.wp-agent-kit-backup-{timestamp}/` before making changes
|
|
61
104
|
|
|
62
|
-
|
|
105
|
+
```bash
|
|
106
|
+
# Emergency: override all safety and replace everything
|
|
107
|
+
npx wp-agent-kit install --no-safe --force
|
|
108
|
+
```
|
|
63
109
|
|
|
64
|
-
|
|
65
|
-
- **Teams adopting GitHub Copilot or Claude** for WordPress codebases.
|
|
66
|
-
- **Anyone building custom WordPress workflows** who needs agents to follow WordPress Coding Standards, security best practices, and core APIs.
|
|
110
|
+
---
|
|
67
111
|
|
|
68
|
-
##
|
|
112
|
+
## Quick Reference
|
|
69
113
|
|
|
70
|
-
|
|
71
|
-
- **Instructions & Workflows**: Pre-built guidance for common WordPress dev cycles.
|
|
72
|
-
- **AGENTS.md**: Single-file agent onboarding that loads skills on demand.
|
|
73
|
-
- **Sync Scripts**: Pull latest skills from official [WordPress/agent-skills](https://github.com/WordPress/agent-skills) repository.
|
|
114
|
+
### CLI Commands
|
|
74
115
|
|
|
75
|
-
|
|
116
|
+
| Command | Purpose |
|
|
117
|
+
|---------|---------|
|
|
118
|
+
| `install [dir]` | Install kit into a project |
|
|
119
|
+
| `setup [dir]` | Interactive or headless configuration |
|
|
120
|
+
| `sync-skills [ref]` | Pull latest skills from WordPress/agent-skills |
|
|
121
|
+
| `upgrade [dir]` | Check or apply version upgrades |
|
|
122
|
+
| `playground` | Launch local WordPress Playground |
|
|
76
123
|
|
|
77
|
-
|
|
124
|
+
### Platform Flags
|
|
78
125
|
|
|
79
|
-
|
|
126
|
+
| Platform | Flag | Target Directory |
|
|
127
|
+
|----------|------|-----------------|
|
|
128
|
+
| GitHub Copilot / VS Code | `--platform github` | `.github/` |
|
|
129
|
+
| Cursor IDE | `--platform cursor` | `.cursor/` |
|
|
130
|
+
| Claude Code | `--platform claude` | `.claude/` |
|
|
131
|
+
| Pi Coding Agent | `--platform pi` | `.pi/agent/` |
|
|
132
|
+
| Generic .agent | `--platform agent` | `.agent/` |
|
|
80
133
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
134
|
+
### Agent-Friendly Flags (All Commands)
|
|
135
|
+
|
|
136
|
+
| Flag | Description |
|
|
137
|
+
|------|-------------|
|
|
138
|
+
| `--json` | Machine-readable JSON output |
|
|
139
|
+
| `--dry-run` | Preview changes without applying |
|
|
140
|
+
| `--ndjson` | Newline-delimited JSON for streaming |
|
|
141
|
+
| `--quiet` | Suppress non-error output |
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## Pi Coding Agent Integration
|
|
84
146
|
|
|
85
|
-
|
|
147
|
+
This package is also a Pi extension — install it once and all WordPress skills and tools are available to Pi:
|
|
86
148
|
|
|
87
149
|
```bash
|
|
88
|
-
|
|
89
|
-
pnpm build:bundles
|
|
150
|
+
pi install npm:wordpress-agent-kit
|
|
90
151
|
```
|
|
91
152
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
153
|
+
### Pi Tools (Callable by the Agent)
|
|
154
|
+
|
|
155
|
+
| Tool | What it does |
|
|
156
|
+
|------|-------------|
|
|
157
|
+
| `wp_triage` | Detect WordPress project type, signals, and tooling |
|
|
158
|
+
| `wp_install_kit` | Install/update kit into a project (safe by default) |
|
|
159
|
+
| `wp_sync_skills` | Sync skills from WordPress/agent-skills upstream |
|
|
160
|
+
| `wp_upgrade` | Check and apply version upgrades |
|
|
161
|
+
|
|
162
|
+
### Pi Commands (Type `/` in Pi TUI)
|
|
163
|
+
|
|
164
|
+
| Command | What it does |
|
|
165
|
+
|---------|-------------|
|
|
166
|
+
| `/wp-triage [dir]` | Run project detection, show in status bar |
|
|
167
|
+
| `/wp-install [dir]` | Install kit into current project |
|
|
168
|
+
| `/wp-sync-skills [ref]` | Sync skills from upstream |
|
|
169
|
+
| `/wp-upgrade` | Show installed vs latest version |
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## Programmatic API
|
|
174
|
+
|
|
175
|
+
Import directly into scripts, tests, or other tools:
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
import {
|
|
179
|
+
installKitApi, // Install/update kit
|
|
180
|
+
syncSkillsApi, // Sync skills from upstream
|
|
181
|
+
runTriageApi, // Run project detection
|
|
182
|
+
configureAgentsMdApi, // Configure AGENTS.md
|
|
183
|
+
computeChanges, // Preview file changes (dry-run)
|
|
184
|
+
isKitInstalled, // Check if kit is installed
|
|
185
|
+
loadManifest, // Read install manifest
|
|
186
|
+
updateKit, // Raw safe update
|
|
187
|
+
ExitCode, // Semantic exit codes
|
|
188
|
+
} from 'wordpress-agent-kit/api';
|
|
189
|
+
|
|
190
|
+
// Install with safe update
|
|
191
|
+
const result = await installKitApi({
|
|
192
|
+
targetDir: '/path/to/my-plugin',
|
|
193
|
+
platform: 'github',
|
|
194
|
+
safe: true, // Use manifest-based diff
|
|
195
|
+
backup: true, // Create backup before changes
|
|
196
|
+
force: false, // Don't overwrite user mods
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// Dry-run preview
|
|
200
|
+
const preview = await installKitApi({
|
|
201
|
+
targetDir: '/path/to/my-plugin',
|
|
202
|
+
platform: 'github',
|
|
203
|
+
dryRun: true,
|
|
204
|
+
});
|
|
205
|
+
// preview.data.actions → [{ type: 'create', target: '...', description: '...' }]
|
|
206
|
+
|
|
207
|
+
// Detect project type
|
|
208
|
+
const triage = await runTriageApi({ targetDir: '/path/to/project' });
|
|
209
|
+
console.log(triage.data.project.primary); // "plugin"
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Semantic Exit Codes
|
|
213
|
+
|
|
214
|
+
| Code | Meaning |
|
|
215
|
+
|------|---------|
|
|
216
|
+
| 0 | Success |
|
|
217
|
+
| 2 | Invalid arguments |
|
|
218
|
+
| 3 | Not found |
|
|
219
|
+
| 4 | Permission denied |
|
|
220
|
+
| 5 | Already exists |
|
|
221
|
+
| 6 | Git error |
|
|
222
|
+
| 7 | Network error |
|
|
223
|
+
| 8 | Validation failed |
|
|
224
|
+
| 130 | Cancelled |
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Skills Reference
|
|
229
|
+
|
|
230
|
+
All 13 skills follow the [AgentSkills.io](https://agentskills.io) specification:
|
|
231
|
+
|
|
232
|
+
| Skill | When to Use |
|
|
233
|
+
|-------|------------|
|
|
234
|
+
| `wordpress-router` | Classify a WordPress repo and route to the right workflow |
|
|
235
|
+
| `wp-project-triage` | Run deterministic project detection (type, tooling, versions) |
|
|
236
|
+
| `wp-plugin-development` | Develop WordPress plugins (hooks, settings, security, release) |
|
|
237
|
+
| `wp-block-development` | Develop Gutenberg blocks (block.json, attributes, rendering) |
|
|
238
|
+
| `wp-block-themes` | Develop block themes (theme.json, templates, patterns, variations) |
|
|
239
|
+
| `wp-rest-api` | Build, extend, or debug REST API endpoints/routes |
|
|
240
|
+
| `wp-interactivity-api` | Build Interactive blocks with data-wp-* directives |
|
|
241
|
+
| `wp-abilities-api` | Register and consume WordPress Abilities API |
|
|
242
|
+
| `wp-performance` | Profile and optimize WordPress performance |
|
|
243
|
+
| `wp-phpstan` | Configure and run PHPStan static analysis |
|
|
244
|
+
| `wp-wpcli-and-ops` | WP-CLI commands, automation, multisite operations |
|
|
245
|
+
| `wp-playground` | Test in disposable WordPress Playground instances |
|
|
246
|
+
| `wpds` | Build UIs with the WordPress Design System |
|
|
247
|
+
|
|
248
|
+
---
|
|
97
249
|
|
|
98
|
-
|
|
250
|
+
## Development
|
|
99
251
|
|
|
100
252
|
```bash
|
|
101
|
-
|
|
253
|
+
# Install dependencies
|
|
254
|
+
pnpm install
|
|
255
|
+
|
|
256
|
+
# Run in dev mode
|
|
257
|
+
pnpm dev
|
|
258
|
+
|
|
259
|
+
# Type-check
|
|
260
|
+
pnpm check
|
|
261
|
+
|
|
262
|
+
# Lint & format
|
|
263
|
+
pnpm lint:check
|
|
264
|
+
pnpm format
|
|
265
|
+
|
|
266
|
+
# Run tests
|
|
267
|
+
pnpm test:run
|
|
268
|
+
|
|
269
|
+
# Build for distribution
|
|
270
|
+
pnpm build
|
|
271
|
+
|
|
272
|
+
# Full pre-publish check (build + lint + test)
|
|
273
|
+
pnpm prepublishOnly
|
|
102
274
|
```
|
|
103
275
|
|
|
104
|
-
|
|
276
|
+
---
|
|
105
277
|
|
|
106
|
-
|
|
278
|
+
## Documentation
|
|
107
279
|
|
|
108
|
-
**
|
|
280
|
+
- **[CLI_REVIEW.md](CLI_REVIEW.md)** — Initial architecture review and design decisions
|
|
281
|
+
- **[CHANGELOG.md](CHANGELOG.md)** — Version history and release notes
|
|
282
|
+
- **[AGENTS.md](AGENTS.md)** — Agent instructions for this repository
|
|
109
283
|
|
|
110
|
-
|
|
111
|
-
2. Run WordPress project triage (via `wp-project-triage` skill) to generate tailored instructions.
|
|
112
|
-
3. Update `.github/instructions/wordpress-workflow.instructions.md` with your workflow.
|
|
113
|
-
4. Keep prompts in `.github/prompts/` accurate for your plugin/theme.
|
|
284
|
+
---
|
|
114
285
|
|
|
115
286
|
## Credits
|
|
116
287
|
|
|
117
|
-
- **[
|
|
118
|
-
- **[
|
|
288
|
+
- **[AgentSkills.io](https://agentskills.io)** — The agent skills specification
|
|
289
|
+
- **[AGENTS.md](https://agentskills.io)** — The agent configuration standard
|
|
290
|
+
- **[WordPress/agent-skills](https://github.com/WordPress/agent-skills)** — Upstream skills repository
|
package/biome.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
|
|
3
|
+
"vcs": {
|
|
4
|
+
"enabled": true,
|
|
5
|
+
"clientKind": "git",
|
|
6
|
+
"useIgnoreFile": true
|
|
7
|
+
},
|
|
8
|
+
"files": {
|
|
9
|
+
"include": ["src/**/*.ts", "tests/**/*.ts", "scripts/**/*.ts", "extensions/**/*.ts"],
|
|
10
|
+
"ignoreUnknown": true
|
|
11
|
+
},
|
|
12
|
+
"organizeImports": {
|
|
13
|
+
"enabled": true
|
|
14
|
+
},
|
|
15
|
+
"linter": {
|
|
16
|
+
"enabled": true,
|
|
17
|
+
"rules": {
|
|
18
|
+
"recommended": true,
|
|
19
|
+
"suspicious": {
|
|
20
|
+
"noExplicitAny": "warn"
|
|
21
|
+
},
|
|
22
|
+
"correctness": {
|
|
23
|
+
"noUnusedVariables": "error"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"formatter": {
|
|
28
|
+
"enabled": true,
|
|
29
|
+
"indentStyle": "tab",
|
|
30
|
+
"lineWidth": 100
|
|
31
|
+
},
|
|
32
|
+
"javascript": {
|
|
33
|
+
"formatter": {
|
|
34
|
+
"quoteStyle": "single",
|
|
35
|
+
"trailingCommas": "es5",
|
|
36
|
+
"semicolons": "always"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -1,19 +1,90 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
2
3
|
import { Command } from 'commander';
|
|
3
|
-
import { createRequire } from 'module';
|
|
4
4
|
import { installCommand } from './commands/install.js';
|
|
5
|
+
import { runPlaygroundCommand } from './commands/run-playground.js';
|
|
5
6
|
import { setupCommand } from './commands/setup.js';
|
|
6
7
|
import { syncSkillsCommand } from './commands/sync-skills.js';
|
|
7
|
-
import {
|
|
8
|
+
import { upgradeCommand } from './commands/upgrade.js';
|
|
9
|
+
import { ExitCode } from './utils/exit-codes.js';
|
|
10
|
+
import { createFormatter } from './utils/output.js';
|
|
11
|
+
import { OutputFormatter } from './utils/output.js';
|
|
8
12
|
const require = createRequire(import.meta.url);
|
|
9
13
|
const { version } = require('../package.json');
|
|
10
14
|
const program = new Command();
|
|
15
|
+
// Global options for all commands
|
|
11
16
|
program
|
|
12
17
|
.name('wp-agent-kit')
|
|
13
18
|
.description('Utilities for WordPress Agent Kit')
|
|
14
|
-
.version(version)
|
|
19
|
+
.version(version)
|
|
20
|
+
.option('--json', 'Output JSON result to stdout', false)
|
|
21
|
+
.option('--quiet', 'Suppress all output except errors', false)
|
|
22
|
+
.option('--ndjson', 'Output NDJSON progress events (for long operations)', false)
|
|
23
|
+
.option('--dry-run', 'Preview actions without executing', false)
|
|
24
|
+
.configureHelp({
|
|
25
|
+
sortSubcommands: true,
|
|
26
|
+
});
|
|
27
|
+
// Add commands
|
|
15
28
|
program.addCommand(installCommand);
|
|
16
29
|
program.addCommand(setupCommand);
|
|
17
30
|
program.addCommand(syncSkillsCommand);
|
|
18
31
|
program.addCommand(runPlaygroundCommand);
|
|
19
|
-
program.
|
|
32
|
+
program.addCommand(upgradeCommand);
|
|
33
|
+
// Global error handler
|
|
34
|
+
program.exitOverride((err) => {
|
|
35
|
+
if (err.code === 'commander.helpDisplayed' || err.code === 'commander.versionDisplayed') {
|
|
36
|
+
process.exit(ExitCode.OK);
|
|
37
|
+
}
|
|
38
|
+
if (err.code === 'commander.unknownOption' || err.code === 'commander.invalidArgument') {
|
|
39
|
+
const formatter = createFormatter({ json: true }, 'wp-agent-kit', version);
|
|
40
|
+
const result = formatter.fail({
|
|
41
|
+
code: 'INVALID_ARGS',
|
|
42
|
+
message: err.message,
|
|
43
|
+
exitCode: ExitCode.INVALID_ARGS,
|
|
44
|
+
});
|
|
45
|
+
process.exit(OutputFormatter.getExitCode(result));
|
|
46
|
+
}
|
|
47
|
+
throw err;
|
|
48
|
+
});
|
|
49
|
+
// Custom help with examples
|
|
50
|
+
program.addHelpText('after', `
|
|
51
|
+
Examples:
|
|
52
|
+
$ wp-agent-kit install --platform github
|
|
53
|
+
$ wp-agent-kit setup --auto --json
|
|
54
|
+
$ wp-agent-kit sync-skills --ref trunk --ndjson
|
|
55
|
+
$ wp-agent-kit install --platform pi --dry-run --json
|
|
56
|
+
$ wp-agent-kit upgrade --check-only --json
|
|
57
|
+
|
|
58
|
+
Programmatic API:
|
|
59
|
+
import { installKit, syncSkills, runTriage } from 'wordpress-agent-kit/api';
|
|
60
|
+
|
|
61
|
+
For more info: https://github.com/kylebrodeur/wordpress-agent-kit
|
|
62
|
+
`);
|
|
63
|
+
try {
|
|
64
|
+
program.parse(process.argv);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
// Handle errors from commands that use process.exit
|
|
68
|
+
const err = error;
|
|
69
|
+
if (err.exitCode !== undefined) {
|
|
70
|
+
process.exit(err.exitCode);
|
|
71
|
+
}
|
|
72
|
+
// Fallback for unexpected errors
|
|
73
|
+
const formatter = createFormatter({ json: true }, 'wp-agent-kit', version);
|
|
74
|
+
const result = formatter.fail({
|
|
75
|
+
code: 'UNEXPECTED_ERROR',
|
|
76
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
77
|
+
exitCode: ExitCode.ERROR,
|
|
78
|
+
});
|
|
79
|
+
process.exit(OutputFormatter.getExitCode(result));
|
|
80
|
+
}
|
|
81
|
+
// Handle unhandled rejections
|
|
82
|
+
process.on('unhandledRejection', (reason) => {
|
|
83
|
+
const formatter = createFormatter({ json: true }, 'wp-agent-kit', version);
|
|
84
|
+
const result = formatter.fail({
|
|
85
|
+
code: 'UNHANDLED_REJECTION',
|
|
86
|
+
message: reason instanceof Error ? reason.message : String(reason),
|
|
87
|
+
exitCode: ExitCode.ERROR,
|
|
88
|
+
});
|
|
89
|
+
process.exit(OutputFormatter.getExitCode(result));
|
|
90
|
+
});
|
package/dist/commands/install.js
CHANGED
|
@@ -1,27 +1,101 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
1
|
import path from 'node:path';
|
|
3
|
-
import {
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { installKitApi, isKitInstalled, loadManifest, } from '../lib/api.js';
|
|
4
|
+
import { OutputFormatter, createFormatter } from '../utils/output.js';
|
|
5
|
+
function isDryRunResult(result) {
|
|
6
|
+
return result.success && 'wouldExecute' in (result.data || {});
|
|
7
|
+
}
|
|
8
|
+
function isRegularResult(result) {
|
|
9
|
+
return result.success && !('wouldExecute' in (result.data || {}));
|
|
10
|
+
}
|
|
4
11
|
/**
|
|
5
12
|
* Command to install the WordPress Agent Kit into a target directory.
|
|
6
13
|
* Takes an optional directory argument, defaulting to the current working directory.
|
|
14
|
+
* Supports --json, --quiet, --ndjson, --dry-run global flags.
|
|
15
|
+
* Safe update mode preserves user modifications on re-install.
|
|
7
16
|
*/
|
|
8
17
|
export const installCommand = new Command('install')
|
|
9
18
|
.description('Install the WordPress Agent Kit into a target directory')
|
|
10
19
|
.argument('[dir]', 'Target directory to install into', process.cwd())
|
|
11
20
|
.option('--platform <platform>', 'Target platform (github, cursor, claude, agent, pi)', 'github')
|
|
12
|
-
.
|
|
21
|
+
.option('--force', 'Overwrite user modifications on update', false)
|
|
22
|
+
.option('--no-safe', 'Disable safe update (use full nuke-and-replace)')
|
|
23
|
+
.option('--no-backup', 'Skip creating a backup before overwriting files')
|
|
24
|
+
.action(async (dir, options, command) => {
|
|
25
|
+
const globalOpts = command.parent?.opts() || {};
|
|
13
26
|
const platform = options.platform;
|
|
14
27
|
const validPlatforms = ['github', 'cursor', 'claude', 'agent', 'pi'];
|
|
15
28
|
if (!validPlatforms.includes(platform)) {
|
|
16
|
-
|
|
17
|
-
|
|
29
|
+
const formatter = createFormatter(globalOpts, 'install', '0.0.0');
|
|
30
|
+
const result = formatter.fail({
|
|
31
|
+
code: 'INVALID_PLATFORM',
|
|
32
|
+
message: `Invalid platform: ${platform}. Valid options: ${validPlatforms.join(', ')}`,
|
|
33
|
+
exitCode: 2,
|
|
34
|
+
});
|
|
35
|
+
process.exit(OutputFormatter.getExitCode(result));
|
|
18
36
|
}
|
|
19
37
|
const targetDir = path.resolve(dir);
|
|
20
|
-
|
|
21
|
-
|
|
38
|
+
const isUpdate = isKitInstalled(targetDir, platform);
|
|
39
|
+
const existingManifest = loadManifest(targetDir, platform);
|
|
40
|
+
const installOptions = {
|
|
41
|
+
targetDir,
|
|
42
|
+
platform: platform,
|
|
43
|
+
force: options.force,
|
|
44
|
+
dryRun: globalOpts.dryRun,
|
|
45
|
+
safe: options.safe !== false, // Default: true (safe)
|
|
46
|
+
backup: options.backup !== false, // Default: true
|
|
47
|
+
};
|
|
48
|
+
const result = await installKitApi(installOptions);
|
|
49
|
+
if (globalOpts.json || globalOpts.ndjson || globalOpts.quiet) {
|
|
50
|
+
process.exit(OutputFormatter.getExitCode(result));
|
|
51
|
+
}
|
|
52
|
+
// Human-readable output
|
|
53
|
+
if (isRegularResult(result)) {
|
|
54
|
+
const data = result.data;
|
|
55
|
+
if (isUpdate) {
|
|
56
|
+
console.log(`✓ Updated WordPress Agent Kit (${platform}) in ${targetDir}`);
|
|
57
|
+
if (existingManifest) {
|
|
58
|
+
console.log(` Previous version: ${existingManifest.version}`);
|
|
59
|
+
}
|
|
60
|
+
console.log(` Files: ${data.filesCreated.length} created/updated`);
|
|
61
|
+
if (data.filesSkipped.length > 0) {
|
|
62
|
+
console.log(` Skipped: ${data.filesSkipped.length} files (user-modified, preserved)`);
|
|
63
|
+
}
|
|
64
|
+
if (data.conflicts && data.conflicts.length > 0) {
|
|
65
|
+
console.log(`\n⚠ ${data.conflicts.length} conflict(s) detected:`);
|
|
66
|
+
for (const conflict of data.conflicts) {
|
|
67
|
+
console.log(` - ${conflict}`);
|
|
68
|
+
}
|
|
69
|
+
console.log(' Re-run with --force to overwrite.');
|
|
70
|
+
}
|
|
71
|
+
if (data.backupDir) {
|
|
72
|
+
console.log(` Backup: ${data.backupDir}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
console.log(`✓ Installed WordPress Agent Kit (${platform}) to ${targetDir}`);
|
|
77
|
+
console.log(` Files: ${data.filesCreated.length} created, ${data.filesSkipped.length} skipped`);
|
|
78
|
+
}
|
|
79
|
+
console.log(` Duration: ${data.durationMs}ms`);
|
|
80
|
+
}
|
|
81
|
+
else if (isDryRunResult(result)) {
|
|
82
|
+
const summary = result.data.summary;
|
|
83
|
+
if (isUpdate) {
|
|
84
|
+
console.log(`✓ Dry-run update (${platform}) for ${targetDir}:`);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
console.log(`✓ Dry-run install (${platform}) to ${targetDir}:`);
|
|
88
|
+
}
|
|
89
|
+
console.log(` Would create: ${summary.filesCreated.length} files`);
|
|
90
|
+
if (summary.filesSkipped && summary.filesSkipped.length > 0) {
|
|
91
|
+
console.log(` Would skip: ${summary.filesSkipped.length} files (user-modified)`);
|
|
92
|
+
}
|
|
93
|
+
if (summary.conflicts && summary.conflicts.length > 0) {
|
|
94
|
+
console.log(` Conflicts: ${summary.conflicts.length} files (use --force to overwrite)`);
|
|
95
|
+
}
|
|
22
96
|
}
|
|
23
|
-
|
|
24
|
-
console.error(error
|
|
25
|
-
process.exit(1);
|
|
97
|
+
else {
|
|
98
|
+
console.error(`✗ Installation failed: ${result.error?.message}`);
|
|
26
99
|
}
|
|
100
|
+
process.exit(result.success ? 0 : 1);
|
|
27
101
|
});
|