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
@@ -0,0 +1,211 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { Command } from 'commander';
5
+ import { installKitApi } from '../lib/api.js';
6
+ import { PLATFORM_FOLDERS } from '../lib/installer.js';
7
+ import { ExitCode } from '../utils/exit-codes.js';
8
+ import { OutputFormatter, createFormatter } from '../utils/output.js';
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = path.dirname(__filename);
11
+ const PACKAGE_ROOT = path.resolve(__dirname, '..', '..');
12
+ function isDryRunResult(result) {
13
+ return result.success && 'wouldExecute' in (result.data || {});
14
+ }
15
+ function isRegularResult(result) {
16
+ return result.success && !('wouldExecute' in (result.data || {}));
17
+ }
18
+ /** Current package version */
19
+ const CURRENT_VERSION = (() => {
20
+ try {
21
+ const pkg = JSON.parse(fs.readFileSync(path.join(PACKAGE_ROOT, 'package.json'), 'utf-8'));
22
+ return pkg.version;
23
+ }
24
+ catch {
25
+ return '0.0.0';
26
+ }
27
+ })();
28
+ /** Version detection from installed kit */
29
+ function detectInstalledVersion(targetDir) {
30
+ // Check AGENTS.md for version marker
31
+ const agentsPath = path.join(targetDir, 'AGENTS.md');
32
+ if (fs.existsSync(agentsPath)) {
33
+ const content = fs.readFileSync(agentsPath, 'utf-8');
34
+ const match = content.match(/wp-agent-kit[:\s]+v?(\d+\.\d+\.\d+)/i);
35
+ if (match)
36
+ return match[1];
37
+ }
38
+ // Check package.json if exists in target
39
+ const pkgPath = path.join(targetDir, 'package.json');
40
+ if (fs.existsSync(pkgPath)) {
41
+ try {
42
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
43
+ if (pkg.devDependencies?.['wordpress-agent-kit']) {
44
+ return pkg.devDependencies['wordpress-agent-kit'].replace(/^[\^~]/, '');
45
+ }
46
+ }
47
+ catch {
48
+ // ignore
49
+ }
50
+ }
51
+ return null;
52
+ }
53
+ /** Detect which platforms are installed */
54
+ function detectInstalledPlatforms(targetDir) {
55
+ const platforms = ['github', 'cursor', 'claude', 'agent', 'pi'];
56
+ return platforms.filter((p) => fs.existsSync(path.join(targetDir, PLATFORM_FOLDERS[p])));
57
+ }
58
+ /** Compare semantic versions */
59
+ function compareVersions(a, b) {
60
+ const pa = a.split('.').map(Number);
61
+ const pb = b.split('.').map(Number);
62
+ for (let i = 0; i < 3; i++) {
63
+ if (pa[i] !== pb[i])
64
+ return pa[i] - pb[i];
65
+ }
66
+ return 0;
67
+ }
68
+ /** Upgrade command */
69
+ export const upgradeCommand = new Command('upgrade')
70
+ .description('Upgrade existing WordPress Agent Kit installation to latest version')
71
+ .argument('[dir]', 'Target directory', process.cwd())
72
+ .option('--platform <platform>', 'Specific platform to upgrade (github, cursor, claude, agent, pi, all)', 'all')
73
+ .option('--force', 'Overwrite local modifications', false)
74
+ .option('--check-only', 'Only check for updates, do not apply', false)
75
+ .option('--from-version <version>', 'Override detected current version')
76
+ .action(async (dir, options, command) => {
77
+ const globalOpts = command.parent?.opts() || {};
78
+ const targetDir = path.resolve(dir);
79
+ const formatter = createFormatter(globalOpts, 'upgrade', CURRENT_VERSION);
80
+ if (!fs.existsSync(targetDir)) {
81
+ const result = formatter.fail({
82
+ code: 'NOT_FOUND',
83
+ message: `Target directory does not exist: ${targetDir}`,
84
+ exitCode: ExitCode.NOT_FOUND,
85
+ });
86
+ process.exit(OutputFormatter.getExitCode(result));
87
+ }
88
+ // Detect installed platforms
89
+ const platformsToCheck = options.platform === 'all'
90
+ ? detectInstalledPlatforms(targetDir)
91
+ : [options.platform];
92
+ if (platformsToCheck.length === 0) {
93
+ const result = formatter.fail({
94
+ code: 'NOT_INSTALLED',
95
+ message: `No WordPress Agent Kit installation found in ${targetDir}`,
96
+ exitCode: ExitCode.NOT_FOUND,
97
+ });
98
+ process.exit(OutputFormatter.getExitCode(result));
99
+ }
100
+ // Detect or override version
101
+ let currentVersion = options.fromVersion;
102
+ if (!currentVersion) {
103
+ currentVersion = detectInstalledVersion(targetDir);
104
+ }
105
+ currentVersion = currentVersion || 'unknown';
106
+ const hasUpdate = currentVersion !== 'unknown' && compareVersions(CURRENT_VERSION, currentVersion) > 0;
107
+ const upgradeInfo = {
108
+ targetDir,
109
+ currentVersion,
110
+ latestVersion: CURRENT_VERSION,
111
+ hasUpdate,
112
+ platforms: platformsToCheck,
113
+ checkOnly: options.checkOnly,
114
+ };
115
+ if (globalOpts.json || globalOpts.quiet) {
116
+ const result = formatter.success(upgradeInfo);
117
+ process.exit(OutputFormatter.getExitCode(result));
118
+ }
119
+ // Human output
120
+ console.log('WordPress Agent Kit Upgrade Check');
121
+ console.log(` Target: ${targetDir}`);
122
+ console.log(` Current: ${currentVersion}`);
123
+ console.log(` Latest: ${CURRENT_VERSION}`);
124
+ console.log(` Platforms: ${platformsToCheck.join(', ')}`);
125
+ if (!hasUpdate && currentVersion !== 'unknown') {
126
+ console.log('\n✓ Already up to date');
127
+ process.exit(0);
128
+ }
129
+ if (currentVersion === 'unknown') {
130
+ console.log('\n⚠ Could not detect current version');
131
+ }
132
+ else {
133
+ console.log('\n✓ Update available');
134
+ }
135
+ if (options.checkOnly) {
136
+ console.log('\nDry run (--check-only): no changes made');
137
+ process.exit(0);
138
+ }
139
+ // Confirm upgrade in interactive mode
140
+ if (!globalOpts.json && !globalOpts.quiet) {
141
+ if (!options.force) {
142
+ console.log('\nUse --force to apply upgrade, or --check-only to preview');
143
+ process.exit(0);
144
+ }
145
+ }
146
+ // Perform upgrade for each platform
147
+ const results = [];
148
+ for (const platform of platformsToCheck) {
149
+ const installResult = await installKitApi({
150
+ targetDir,
151
+ platform,
152
+ force: options.force,
153
+ dryRun: globalOpts.dryRun,
154
+ safe: true,
155
+ backup: !options.force, // Skip backup if forcing
156
+ });
157
+ results.push({ platform, ...installResult });
158
+ }
159
+ const successCount = results.filter((r) => r.success).length;
160
+ const totalCreated = results.reduce((sum, r) => {
161
+ if (!r.success)
162
+ return sum;
163
+ if (isRegularResult(r)) {
164
+ return sum + (r.data.filesCreated?.length || 0);
165
+ }
166
+ if (isDryRunResult(r)) {
167
+ return sum + (r.data.summary.filesCreated?.length || 0);
168
+ }
169
+ return sum;
170
+ }, 0);
171
+ const totalSkipped = results.reduce((sum, r) => {
172
+ if (!r.success)
173
+ return sum;
174
+ if (isRegularResult(r)) {
175
+ return sum + (r.data.filesSkipped?.length || 0);
176
+ }
177
+ if (isDryRunResult(r)) {
178
+ return sum + (r.data.summary.filesSkipped?.length || 0);
179
+ }
180
+ return sum;
181
+ }, 0);
182
+ const allConflicts = results.reduce((acc, r) => {
183
+ if (!r.success)
184
+ return acc;
185
+ if (isRegularResult(r) && r.data.conflicts) {
186
+ acc.push(...r.data.conflicts);
187
+ }
188
+ if (isDryRunResult(r) && r.data.summary.conflicts) {
189
+ acc.push(...r.data.summary.conflicts);
190
+ }
191
+ return acc;
192
+ }, []);
193
+ console.log(`\n✓ Upgraded ${successCount}/${results.length} platform(s)`);
194
+ console.log(` Files updated: ${totalCreated}`);
195
+ if (totalSkipped > 0) {
196
+ console.log(` Files preserved: ${totalSkipped} (user-modified)`);
197
+ }
198
+ if (allConflicts.length > 0) {
199
+ console.log(` ⚠ Conflicts: ${allConflicts.length} files (re-run with --force to overwrite)`);
200
+ }
201
+ console.log(` Version: ${currentVersion} → ${CURRENT_VERSION}`);
202
+ const failed = results.filter((r) => !r.success);
203
+ if (failed.length > 0) {
204
+ console.error('\nFailures:');
205
+ for (const f of failed) {
206
+ console.error(` ${f.platform}: ${f.error?.message}`);
207
+ }
208
+ process.exit(1);
209
+ }
210
+ process.exit(0);
211
+ });