workflow-agent-cli 2.4.0 → 2.4.1

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/README.md CHANGED
@@ -188,6 +188,12 @@ workflow-agent scope:migrate
188
188
  | `workflow-agent doctor` | Run health checks and get optimization tips |
189
189
  | `workflow-agent scope:create` | Create a custom scope package |
190
190
  | `workflow-agent scope:migrate` | Migrate inline scopes to package |
191
+ | `workflow-agent learn:record` | Record a new fix pattern or blueprint |
192
+ | `workflow-agent learn:list` | List recorded patterns |
193
+ | `workflow-agent learn:apply <id>` | Apply a pattern to current project |
194
+ | `workflow-agent learn:sync` | Sync patterns with community registry |
195
+ | `workflow-agent learn:config` | Configure learning settings |
196
+ | `workflow-agent learn:stats` | View learning statistics |
191
197
 
192
198
  ### Command Options
193
199
 
@@ -207,6 +213,28 @@ workflow-agent scope:migrate
207
213
  - `--category <type>` - Suggestion category (feature, bug, improvement, documentation)
208
214
  - `--author <name>` - Your name or username
209
215
 
216
+ #### `learn:record`
217
+
218
+ - `--type <type>` - Pattern type: `fix` or `blueprint`
219
+ - `--name <name>` - Human-readable pattern name
220
+ - `--description <desc>` - What the pattern does
221
+ - `--category <cat>` - Fix category: `lint`, `type-error`, `dependency`, `config`, etc.
222
+ - `--framework <fw>` - Target framework: `next`, `react`, `vue`, etc.
223
+ - `--version <ver>` - Semver version range
224
+
225
+ #### `learn:list`
226
+
227
+ - `--type <type>` - Filter by pattern type
228
+ - `--framework <fw>` - Filter by framework
229
+ - `--deprecated` - Include deprecated patterns
230
+
231
+ #### `learn:config`
232
+
233
+ - `--enable-telemetry` - Enable anonymous usage telemetry
234
+ - `--disable-telemetry` - Disable telemetry
235
+ - `--enable-sync` - Enable community pattern sync
236
+ - `--disable-sync` - Disable sync
237
+
210
238
  ---
211
239
 
212
240
  ## 📦 Preset Scope Libraries
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "workflow-agent-cli",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "A self-evolving workflow management system for AI agent development",
5
5
  "keywords": [
6
6
  "workflow",
@@ -0,0 +1,536 @@
1
+ # Pattern Analysis Workflow
2
+
3
+ > **Purpose**: This document defines the step-by-step workflow that AI agents must follow when analyzing a codebase for patterns and updating the central pattern store. Following this workflow ensures consistent pattern capture, proper anonymization, and meaningful contribution to the ecosystem's shared knowledge.
4
+
5
+ ---
6
+
7
+ ## Table of Contents
8
+
9
+ 1. [When to Perform Pattern Analysis](#when-to-perform-pattern-analysis)
10
+ 2. [Phase 1: Discovery](#phase-1-discovery)
11
+ 3. [Phase 2: Categorization](#phase-2-categorization)
12
+ 4. [Phase 3: Pattern Extraction](#phase-3-pattern-extraction)
13
+ 5. [Phase 4: Validation](#phase-4-validation)
14
+ 6. [Phase 5: Store Update](#phase-5-store-update)
15
+ 7. [Phase 6: Reporting](#phase-6-reporting)
16
+ 8. [Pattern Quality Criteria](#pattern-quality-criteria)
17
+ 9. [CLI Commands Reference](#cli-commands-reference)
18
+
19
+ ---
20
+
21
+ ## When to Perform Pattern Analysis
22
+
23
+ Initiate pattern analysis when:
24
+
25
+ | Trigger | Description |
26
+ |---------|-------------|
27
+ | **Post-fix success** | A quality issue was detected and auto-fixed successfully |
28
+ | **User request** | User explicitly asks to "analyze patterns" or "record what we learned" |
29
+ | **Project setup complete** | A new project was scaffolded and configured successfully |
30
+ | **Migration complete** | A framework upgrade or refactor was completed without issues |
31
+ | **CI/CD passing** | All quality checks pass after non-trivial changes |
32
+
33
+ ---
34
+
35
+ ## Phase 1: Discovery
36
+
37
+ ### Objective
38
+ Identify candidate patterns worth capturing from the current work session.
39
+
40
+ ### Steps
41
+
42
+ 1. **Review Recent Changes**
43
+ ```bash
44
+ # Check what was modified
45
+ git diff HEAD~5 --name-only
46
+
47
+ # Review specific fix patterns
48
+ git log --oneline -10 --grep="fix"
49
+ ```
50
+
51
+ 2. **Identify Pattern Candidates**
52
+ Look for:
53
+ - ✅ Fixes that resolved linting errors
54
+ - ✅ Configuration changes that fixed build issues
55
+ - ✅ Dependency resolutions
56
+ - ✅ Type error fixes
57
+ - ✅ Repeatable project setup steps
58
+ - ✅ Framework-specific workarounds
59
+
60
+ 3. **Check Existing Patterns**
61
+ ```bash
62
+ # List current patterns to avoid duplicates
63
+ workflow learn:list --framework <current-framework>
64
+ ```
65
+
66
+ 4. **Document Candidates**
67
+ Create a mental or written list of patterns worth capturing:
68
+ ```
69
+ Pattern Candidates:
70
+ 1. [lint] ESLint prefer-const auto-fix
71
+ 2. [type-error] Null assertion for optional chaining
72
+ 3. [config] Next.js 14 App Router image config
73
+ ```
74
+
75
+ ---
76
+
77
+ ## Phase 2: Categorization
78
+
79
+ ### Objective
80
+ Classify each pattern candidate into the appropriate type and category.
81
+
82
+ ### Pattern Types
83
+
84
+ | Type | Use When | Example |
85
+ |------|----------|---------|
86
+ | **Fix Pattern** | Solves a specific, repeatable error | ESLint rule violation fix |
87
+ | **Blueprint** | Represents complete project/feature setup | Next.js 14 TypeScript starter |
88
+
89
+ ### Fix Pattern Categories
90
+
91
+ Choose the most specific category:
92
+
93
+ | Category | Description | Examples |
94
+ |----------|-------------|----------|
95
+ | `lint` | Linting rule violations | ESLint, Prettier, Stylelint |
96
+ | `type-error` | TypeScript/type system errors | Missing types, inference issues |
97
+ | `dependency` | Package/module resolution | Missing deps, version conflicts |
98
+ | `config` | Configuration file issues | tsconfig, next.config, vite.config |
99
+ | `runtime` | Runtime errors | Null refs, async issues |
100
+ | `build` | Build/compilation failures | Bundler errors, missing exports |
101
+ | `test` | Test failures | Jest, Vitest, Playwright |
102
+ | `security` | Security vulnerabilities | Dependency audits, secrets |
103
+
104
+ ### Tag Schema
105
+
106
+ Apply tags for discoverability:
107
+
108
+ ```
109
+ framework:<name> → framework:next, framework:react
110
+ tool:<name> → tool:eslint, tool:prettier
111
+ error-type:<type> → error-type:unused-import, error-type:missing-type
112
+ file-type:<ext> → file-type:tsx, file-type:json
113
+ custom:<value> → custom:app-router, custom:server-component
114
+ ```
115
+
116
+ ---
117
+
118
+ ## Phase 3: Pattern Extraction
119
+
120
+ ### Objective
121
+ Convert the identified fixes into structured pattern definitions.
122
+
123
+ ### For Fix Patterns
124
+
125
+ Extract these components:
126
+
127
+ ```typescript
128
+ {
129
+ // IDENTIFICATION
130
+ name: string, // "ESLint prefer-const fix"
131
+ description: string, // "Replace let with const for variables that are never reassigned"
132
+ category: string, // "lint"
133
+
134
+ // TRIGGER (when does this apply?)
135
+ trigger: {
136
+ errorPattern: string, // Regex: "Prefer const over let"
137
+ errorMessage: string, // Example: "'x' is never reassigned"
138
+ filePattern: string, // Glob: "*.ts,*.tsx"
139
+ },
140
+
141
+ // SOLUTION (how to fix it)
142
+ solution: {
143
+ type: string, // "file-change" | "command" | "config-update"
144
+ steps: [{
145
+ order: 1,
146
+ action: string, // "modify" | "run" | "install" | "create"
147
+ target: string, // File path or command
148
+ description: string, // Human-readable step
149
+ }]
150
+ },
151
+
152
+ // COMPATIBILITY (where does this work?)
153
+ compatibility: {
154
+ framework: string, // "next" | "react" | "vue" | ...
155
+ frameworkVersion: string, // "^14.0.0"
156
+ runtime: string, // "node"
157
+ runtimeVersion: string, // ">=18.0.0"
158
+ },
159
+
160
+ // METADATA
161
+ tags: [{ name: string, category: string }],
162
+ source: "manual" | "auto-heal" | "verify-fix" | "imported",
163
+ isPrivate: true,
164
+ }
165
+ ```
166
+
167
+ ### For Blueprints
168
+
169
+ Extract these components:
170
+
171
+ ```typescript
172
+ {
173
+ // IDENTIFICATION
174
+ name: string, // "Next.js 14 TypeScript Starter"
175
+ description: string, // "Complete setup with App Router, Tailwind, and testing"
176
+
177
+ // STACK DEFINITION
178
+ stack: {
179
+ framework: string, // "next"
180
+ language: string, // "typescript"
181
+ runtime: string, // "node"
182
+ packageManager: string, // "pnpm"
183
+ dependencies: [{ name: string, version: string }],
184
+ devDependencies: [{ name: string, version: string }],
185
+ },
186
+
187
+ // PROJECT STRUCTURE
188
+ structure: {
189
+ directories: [{ path: string, purpose: string }],
190
+ keyFiles: [{ path: string, purpose: string, template?: string }],
191
+ },
192
+
193
+ // SETUP STEPS
194
+ setup: {
195
+ prerequisites: string[],
196
+ steps: [{ order: number, command: string, description: string }],
197
+ configs: [{ file: string, content: string, description: string }],
198
+ },
199
+
200
+ // METADATA
201
+ tags: [{ name: string, category: string }],
202
+ relatedPatterns: string[], // UUIDs of related fix patterns
203
+ isPrivate: true,
204
+ }
205
+ ```
206
+
207
+ ---
208
+
209
+ ## Phase 4: Validation
210
+
211
+ ### Objective
212
+ Ensure patterns are high-quality before storing.
213
+
214
+ ### Quality Checklist
215
+
216
+ Before recording any pattern, verify:
217
+
218
+ - [ ] **Reproducible**: Can this fix be applied to similar situations?
219
+ - [ ] **Specific**: Is the trigger pattern precise enough to avoid false matches?
220
+ - [ ] **Complete**: Are all solution steps documented?
221
+ - [ ] **Tested**: Did the fix actually work when applied?
222
+ - [ ] **Unique**: Does this not duplicate an existing pattern?
223
+ - [ ] **Anonymized**: No PII, absolute paths, or secrets in the pattern?
224
+
225
+ ### Validation Commands
226
+
227
+ ```bash
228
+ # Check for similar existing patterns
229
+ workflow learn:list --search "<error-message-fragment>"
230
+
231
+ # Preview what would be recorded
232
+ workflow learn:record --type fix --name "..." --dry-run
233
+ ```
234
+
235
+ ### Anonymization Rules
236
+
237
+ Ensure these are NOT in the pattern:
238
+
239
+ | Data Type | Example | Action |
240
+ |-----------|---------|--------|
241
+ | Absolute paths | `/home/user/project` | Remove or use `<PATH>` |
242
+ | Email addresses | `dev@company.com` | Remove entirely |
243
+ | API keys | `sk_live_...` | Never include |
244
+ | IP addresses | `192.168.1.100` | Remove or use `<IP>` |
245
+ | Repo-specific names | `my-company-app` | Generalize |
246
+
247
+ ---
248
+
249
+ ## Phase 5: Store Update
250
+
251
+ ### Objective
252
+ Persist validated patterns to the central store.
253
+
254
+ ### Recording Fix Patterns
255
+
256
+ ```bash
257
+ workflow learn:record \
258
+ --type fix \
259
+ --name "ESLint prefer-const fix" \
260
+ --description "Replace let with const for never-reassigned variables" \
261
+ --category lint \
262
+ --framework node \
263
+ --tags "tool:eslint,error-type:prefer-const"
264
+ ```
265
+
266
+ ### Recording Blueprints
267
+
268
+ ```bash
269
+ workflow learn:record \
270
+ --type blueprint \
271
+ --name "Next.js 14 App Router Starter" \
272
+ --description "TypeScript project with Tailwind, ESLint, and Vitest" \
273
+ --framework next \
274
+ --version "^14.0.0" \
275
+ --tags "framework:next,tool:tailwind,tool:vitest"
276
+ ```
277
+
278
+ ### Programmatic Recording
279
+
280
+ When automating pattern capture:
281
+
282
+ ```typescript
283
+ import { PatternStore, type FixPattern } from "@hawkinside_out/workflow-improvement-tracker";
284
+
285
+ const store = new PatternStore(process.cwd());
286
+ await store.initialize();
287
+
288
+ const pattern: FixPattern = {
289
+ id: crypto.randomUUID(),
290
+ name: "ESLint prefer-const fix",
291
+ description: "Replace let with const for never-reassigned variables",
292
+ category: "lint",
293
+ tags: [
294
+ { name: "eslint", category: "tool" },
295
+ { name: "prefer-const", category: "error-type" },
296
+ ],
297
+ trigger: {
298
+ errorPattern: "Prefer const over let",
299
+ filePattern: "*.ts,*.tsx",
300
+ },
301
+ solution: {
302
+ type: "file-change",
303
+ steps: [{
304
+ order: 1,
305
+ action: "modify",
306
+ target: "<file>",
307
+ description: "Change 'let' to 'const' for the flagged variable",
308
+ }],
309
+ },
310
+ compatibility: {
311
+ framework: "node",
312
+ frameworkVersion: "*",
313
+ },
314
+ metrics: {
315
+ successRate: 100,
316
+ applications: 0,
317
+ successes: 0,
318
+ failures: 0,
319
+ },
320
+ source: "manual",
321
+ isPrivate: true,
322
+ createdAt: new Date().toISOString(),
323
+ updatedAt: new Date().toISOString(),
324
+ };
325
+
326
+ const result = await store.saveFixPattern(pattern);
327
+ if (result.success) {
328
+ console.log(`✓ Pattern saved: ${result.data?.id}`);
329
+ }
330
+ ```
331
+
332
+ ### Updating Existing Patterns
333
+
334
+ When a pattern needs improvement:
335
+
336
+ ```typescript
337
+ // Get existing pattern
338
+ const existing = await store.getFixPattern(patternId);
339
+
340
+ // Update with better trigger
341
+ existing.trigger.errorPattern = "more specific regex";
342
+ existing.updatedAt = new Date().toISOString();
343
+
344
+ // Save (handles version conflict automatically)
345
+ await store.saveFixPattern(existing);
346
+ ```
347
+
348
+ ---
349
+
350
+ ## Phase 6: Reporting
351
+
352
+ ### Objective
353
+ Communicate what patterns were captured and their status.
354
+
355
+ ### Post-Analysis Report Template
356
+
357
+ After completing pattern analysis, report:
358
+
359
+ ```markdown
360
+ ## 📚 Pattern Analysis Complete
361
+
362
+ ### Patterns Recorded
363
+ | Type | Name | Category | Status |
364
+ |------|------|----------|--------|
365
+ | Fix | ESLint prefer-const | lint | ✅ Saved |
366
+ | Fix | TS null assertion | type-error | ✅ Saved |
367
+ | Blueprint | Next.js 14 Starter | - | ⏭ Skipped (duplicate) |
368
+
369
+ ### Store Statistics
370
+ - Total Fix Patterns: 45
371
+ - Total Blueprints: 7
372
+ - This Session: +2 fixes
373
+
374
+ ### Next Steps
375
+ - Run `workflow learn:list` to view all patterns
376
+ - Run `workflow learn:sync --push` to share with community
377
+ ```
378
+
379
+ ### View Statistics
380
+
381
+ ```bash
382
+ workflow learn:stats
383
+ ```
384
+
385
+ ---
386
+
387
+ ## Pattern Quality Criteria
388
+
389
+ ### Good Pattern Characteristics
390
+
391
+ | Criteria | Good Example | Bad Example |
392
+ |----------|--------------|-------------|
393
+ | **Specificity** | `errorPattern: "Cannot find module '@/.*'"` | `errorPattern: "error"` |
394
+ | **Reusability** | Works across similar projects | Only works in one specific repo |
395
+ | **Documentation** | Clear description with context | "Fixes the thing" |
396
+ | **Versioning** | `frameworkVersion: "^14.0.0"` | No version specified |
397
+
398
+ ### Pattern Red Flags
399
+
400
+ Do NOT record patterns that:
401
+
402
+ - 🚫 Contain hardcoded project-specific paths
403
+ - 🚫 Reference internal/proprietary APIs
404
+ - 🚫 Include commented-out code
405
+ - 🚫 Have success rate below 50% (after 5+ uses)
406
+ - 🚫 Duplicate existing patterns with minor variations
407
+
408
+ ---
409
+
410
+ ## CLI Commands Reference
411
+
412
+ ### Recording
413
+
414
+ ```bash
415
+ # Record a fix pattern
416
+ workflow learn:record --type fix --name "..." --description "..." --category lint
417
+
418
+ # Record a blueprint
419
+ workflow learn:record --type blueprint --name "..." --description "..."
420
+
421
+ # Dry run (preview only)
422
+ workflow learn:record --type fix --name "..." --dry-run
423
+ ```
424
+
425
+ ### Viewing
426
+
427
+ ```bash
428
+ # List all patterns
429
+ workflow learn:list
430
+
431
+ # Filter by type
432
+ workflow learn:list --type fix
433
+
434
+ # Filter by framework
435
+ workflow learn:list --framework next
436
+
437
+ # Include deprecated
438
+ workflow learn:list --deprecated
439
+
440
+ # Search patterns
441
+ workflow learn:list --search "eslint"
442
+ ```
443
+
444
+ ### Applying
445
+
446
+ ```bash
447
+ # Apply a pattern
448
+ workflow learn:apply <pattern-id>
449
+
450
+ # Dry run
451
+ workflow learn:apply <pattern-id> --dry-run
452
+ ```
453
+
454
+ ### Managing
455
+
456
+ ```bash
457
+ # View statistics
458
+ workflow learn:stats
459
+
460
+ # Deprecate a pattern
461
+ workflow learn:deprecate <pattern-id> --reason "Superseded by better solution"
462
+
463
+ # Configure sync settings
464
+ workflow learn:config --enable-sync
465
+ workflow learn:config --disable-telemetry
466
+ ```
467
+
468
+ ### Syncing
469
+
470
+ ```bash
471
+ # Preview sync
472
+ workflow learn:sync --dry-run
473
+
474
+ # Push to community
475
+ workflow learn:sync --push
476
+
477
+ # Pull from community
478
+ workflow learn:sync --pull
479
+ ```
480
+
481
+ ---
482
+
483
+ ## Quick Reference: Agent Workflow
484
+
485
+ When asked to analyze patterns:
486
+
487
+ ```
488
+ 1. DISCOVER → Review recent changes, identify fixes worth capturing
489
+ 2. CATEGORIZE → Classify as fix/blueprint, assign category and tags
490
+ 3. EXTRACT → Build structured pattern with trigger + solution
491
+ 4. VALIDATE → Check quality, uniqueness, anonymization
492
+ 5. STORE → Use CLI or API to persist pattern
493
+ 6. REPORT → Summarize what was captured
494
+ ```
495
+
496
+ ### One-Liner for Auto-Recording
497
+
498
+ After successful verification with fixes:
499
+
500
+ ```bash
501
+ workflow verify --fix --learn
502
+ ```
503
+
504
+ This automatically:
505
+ 1. Runs all quality checks
506
+ 2. Applies auto-fixes
507
+ 3. Re-validates
508
+ 4. Records successful fixes as patterns
509
+
510
+ ---
511
+
512
+ ## Storage Locations
513
+
514
+ Patterns are stored in:
515
+
516
+ ```
517
+ .workflow/
518
+ ├── patterns/
519
+ │ ├── fixes/
520
+ │ │ ├── <uuid>.json ← Fix patterns
521
+ │ │ └── ...
522
+ │ └── blueprints/
523
+ │ ├── <uuid>.json ← Blueprints
524
+ │ └── ...
525
+ └── .contributor-id ← Anonymous contributor ID
526
+ ```
527
+
528
+ Each pattern file contains the full schema plus metadata for versioning and conflict resolution.
529
+
530
+ ---
531
+
532
+ ## Related Documents
533
+
534
+ - [Agent Editing Instructions](./AGENT_EDITING_INSTRUCTIONS.md) - General editing rules
535
+ - [Self-Improvement Mandate](./SELF_IMPROVEMENT_MANDATE.md) - Improvement tracking
536
+ - [Agent Learning System](/docs/content/agent-learning.mdx) - Full API documentation