@codeharbor/agent-playbook 0.2.2 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeharbor/agent-playbook",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Local skill manager and installer for agent-playbook across Claude Code, Codex, and Gemini.",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
@@ -2,6 +2,15 @@
2
2
  name: api-designer
3
3
  description: REST and GraphQL API architect for designing robust, scalable APIs. Use when designing new APIs or improving existing ones.
4
4
  allowed-tools: Read, Write, Edit, Bash, Grep, Glob, WebFetch, WebSearch
5
+ metadata:
6
+ hooks:
7
+ after_complete:
8
+ - trigger: self-improving-agent
9
+ mode: background
10
+ reason: "Learn from API design patterns"
11
+ - trigger: session-logger
12
+ mode: auto
13
+ reason: "Log API design activity"
5
14
  ---
6
15
 
7
16
  # API Designer
@@ -2,6 +2,12 @@
2
2
  name: api-documenter
3
3
  description: API documentation specialist for OpenAPI/Swagger specifications. Use when documenting REST or GraphQL APIs.
4
4
  allowed-tools: Read, Write, Edit, Bash, Grep, Glob
5
+ metadata:
6
+ hooks:
7
+ after_complete:
8
+ - trigger: session-logger
9
+ mode: auto
10
+ reason: "Log documentation activity"
5
11
  ---
6
12
 
7
13
  # API Documenter
@@ -2,6 +2,15 @@
2
2
  name: architecting-solutions
3
3
  description: Designs technical solutions and architecture. Use when user says "design solution", "architecture design", "technical design", or "方案设计" WITHOUT mentioning PRD. For PRD-specific work, use prd-planner skill instead.
4
4
  allowed-tools: Read, Write, Edit, Bash, AskUserQuestion, WebSearch, Grep, Glob
5
+ metadata:
6
+ hooks:
7
+ after_complete:
8
+ - trigger: self-improving-agent
9
+ mode: background
10
+ reason: "Learn from architecture patterns"
11
+ - trigger: session-logger
12
+ mode: auto
13
+ reason: "Log architecture design"
5
14
  ---
6
15
 
7
16
  # Architecting Solutions
@@ -2,6 +2,15 @@
2
2
  name: code-reviewer
3
3
  description: Reviews pull requests and code changes for quality, security, and best practices. Use when user asks for code review, PR review, or mentions reviewing changes.
4
4
  allowed-tools: Read, Grep, Glob, Bash, WebFetch, WebSearch
5
+ metadata:
6
+ hooks:
7
+ after_complete:
8
+ - trigger: self-improving-agent
9
+ mode: background
10
+ reason: "Learn from review patterns"
11
+ - trigger: session-logger
12
+ mode: auto
13
+ reason: "Log review activity"
5
14
  ---
6
15
 
7
16
  # Code Reviewer
@@ -2,6 +2,12 @@
2
2
  name: commit-helper
3
3
  description: Helps write Git commit messages following the Conventional Commits specification. Use this skill when the user asks to commit changes, write commit messages, format commits, or mentions git commits.
4
4
  allowed-tools: Read, Write, Edit, Bash, Grep
5
+ metadata:
6
+ hooks:
7
+ after_complete:
8
+ - trigger: session-logger
9
+ mode: auto
10
+ reason: "Log commit activity"
5
11
  ---
6
12
 
7
13
  # Commit Message Helper
@@ -2,6 +2,12 @@
2
2
  name: create-pr
3
3
  description: Creates pull requests with bilingual documentation updates. Use when user asks to create PR, make a pull request, or submit changes for review. Automatically updates both English and Chinese README files.
4
4
  allowed-tools: Read, Write, Edit, Bash, Grep, AskUserQuestion
5
+ metadata:
6
+ hooks:
7
+ after_complete:
8
+ - trigger: session-logger
9
+ mode: auto
10
+ reason: "Log PR creation"
5
11
  ---
6
12
 
7
13
  # Create PR
@@ -2,6 +2,15 @@
2
2
  name: debugger
3
3
  description: Advanced debugging specialist for diagnosing and resolving code issues. Use when user encounters bugs, errors, unexpected behavior, or mentions debugging.
4
4
  allowed-tools: Read, Write, Edit, Bash, Grep, Glob
5
+ metadata:
6
+ hooks:
7
+ after_complete:
8
+ - trigger: self-improving-agent
9
+ mode: background
10
+ reason: "Learn from debugging patterns"
11
+ - trigger: session-logger
12
+ mode: auto
13
+ reason: "Log debugging session"
5
14
  ---
6
15
 
7
16
  # Debugger
@@ -2,6 +2,12 @@
2
2
  name: deployment-engineer
3
3
  description: Deployment automation specialist for CI/CD pipelines and infrastructure. Use when setting up deployment, configuring CI/CD, or managing releases.
4
4
  allowed-tools: Read, Write, Edit, Bash, Grep, Glob
5
+ metadata:
6
+ hooks:
7
+ after_complete:
8
+ - trigger: session-logger
9
+ mode: auto
10
+ reason: "Log deployment activity"
5
11
  ---
6
12
 
7
13
  # Deployment Engineer
@@ -2,6 +2,12 @@
2
2
  name: documentation-engineer
3
3
  description: Technical documentation expert for creating clear, comprehensive documentation. Use when user asks to write docs, create README, or document code.
4
4
  allowed-tools: Read, Write, Edit, Grep, Glob, WebFetch, WebSearch
5
+ metadata:
6
+ hooks:
7
+ after_complete:
8
+ - trigger: session-logger
9
+ mode: auto
10
+ reason: "Log documentation activity"
5
11
  ---
6
12
 
7
13
  # Documentation Engineer
@@ -2,6 +2,15 @@
2
2
  name: performance-engineer
3
3
  description: Performance optimization specialist for improving application speed and efficiency. Use when investigating performance issues or optimizing code.
4
4
  allowed-tools: Read, Write, Edit, Bash, Grep, Glob
5
+ metadata:
6
+ hooks:
7
+ after_complete:
8
+ - trigger: self-improving-agent
9
+ mode: background
10
+ reason: "Learn from performance patterns"
11
+ - trigger: session-logger
12
+ mode: auto
13
+ reason: "Log performance optimization"
5
14
  ---
6
15
 
7
16
  # Performance Engineer
@@ -2,6 +2,12 @@
2
2
  name: planning-with-files
3
3
  description: Uses persistent markdown files for general planning, progress tracking, and knowledge storage (Manus-style workflow). Use for multi-step tasks, research projects, or general organization WITHOUT mentioning PRD. For PRD-specific work, use prd-planner skill instead.
4
4
  allowed-tools: Read, Write, Edit, Bash, Grep, Glob
5
+ metadata:
6
+ hooks:
7
+ after_complete:
8
+ - trigger: session-logger
9
+ mode: auto
10
+ reason: "Log planning activity"
5
11
  ---
6
12
 
7
13
  # Planning with Files
@@ -1,6 +1,16 @@
1
1
  ---
2
2
  name: prd-implementation-precheck
3
3
  description: Implement PRDs/specs with a mandatory precheck review before coding. Use when a user asks to implement a PRD/feature spec/requirements doc or says "implement PRD/spec". Perform a preflight review, raise questions on scope/consistency/risks, then implement after confirmation.
4
+ allowed-tools: Read, Write, Edit, Bash, Grep, Glob, AskUserQuestion
5
+ metadata:
6
+ hooks:
7
+ after_complete:
8
+ - trigger: self-improving-agent
9
+ mode: background
10
+ reason: "Learn from implementation patterns"
11
+ - trigger: session-logger
12
+ mode: auto
13
+ reason: "Log PRD implementation activity"
4
14
  ---
5
15
 
6
16
  # PRD Implementation Precheck
@@ -2,6 +2,12 @@
2
2
  name: qa-expert
3
3
  description: Quality assurance expert for testing strategies and quality gates. Use when planning test coverage, setting up QA processes, or improving quality standards.
4
4
  allowed-tools: Read, Write, Edit, Bash, Grep, Glob, WebFetch, WebSearch
5
+ metadata:
6
+ hooks:
7
+ after_complete:
8
+ - trigger: session-logger
9
+ mode: auto
10
+ reason: "Log QA activity"
5
11
  ---
6
12
 
7
13
  # QA Expert
@@ -2,6 +2,15 @@
2
2
  name: refactoring-specialist
3
3
  description: Code refactoring expert for improving code structure, readability, and maintainability. Use when user asks to refactor, clean up, or improve code quality.
4
4
  allowed-tools: Read, Write, Edit, Bash, Grep, Glob
5
+ metadata:
6
+ hooks:
7
+ after_complete:
8
+ - trigger: self-improving-agent
9
+ mode: background
10
+ reason: "Learn from refactoring patterns"
11
+ - trigger: session-logger
12
+ mode: auto
13
+ reason: "Log refactoring activity"
5
14
  ---
6
15
 
7
16
  # Refactoring Specialist
@@ -2,6 +2,15 @@
2
2
  name: security-auditor
3
3
  description: Security vulnerability expert covering OWASP Top 10 and common security issues. Use when conducting security audits or reviewing code for vulnerabilities.
4
4
  allowed-tools: Read, Grep, Glob, Bash, WebSearch
5
+ metadata:
6
+ hooks:
7
+ after_complete:
8
+ - trigger: self-improving-agent
9
+ mode: background
10
+ reason: "Learn from security patterns"
11
+ - trigger: session-logger
12
+ mode: auto
13
+ reason: "Log security audit"
5
14
  ---
6
15
 
7
16
  # Security Auditor
@@ -154,3 +154,123 @@ Session logs are stored in `sessions/` which is in `.gitignore`.
154
154
  3. **Include code snippets**: Save important solutions
155
155
  4. **Track decisions**: Why did you choose X over Y?
156
156
  5. **List pending items**: What to do next time
157
+
158
+ ## Rich Content Extraction (for Self-Improving Agent)
159
+
160
+ When triggered by other skills via hooks, session-logger extracts structured data for learning:
161
+
162
+ ### Skill Context Capture
163
+
164
+ When a skill completes, capture:
165
+
166
+ ```markdown
167
+ ## Skill Execution Context
168
+
169
+ **Skill**: {skill-name}
170
+ **Trigger**: {user-invoked | hook-triggered | auto-triggered}
171
+ **Status**: {completed | error | partial}
172
+ **Duration**: {approximate time}
173
+
174
+ ### Input Context
175
+ - User request: {original request}
176
+ - Files involved: {list of files}
177
+ - Codebase patterns detected: {patterns}
178
+
179
+ ### Output Summary
180
+ - Actions taken: {list}
181
+ - Files modified: {list with changes}
182
+ - Decisions made: {key decisions}
183
+
184
+ ### Learning Signals
185
+ - What worked well: {successes}
186
+ - What could improve: {areas for improvement}
187
+ - Patterns discovered: {new patterns}
188
+ - Errors encountered: {errors and resolutions}
189
+ ```
190
+
191
+ ### Error Context Capture
192
+
193
+ When a skill encounters errors:
194
+
195
+ ```markdown
196
+ ## Error Context
197
+
198
+ **Error Type**: {type}
199
+ **Error Message**: {message}
200
+ **Stack Trace**: {if available}
201
+
202
+ ### Resolution Attempted
203
+ - Approach: {what was tried}
204
+ - Result: {success/failure}
205
+ - Root cause: {if identified}
206
+
207
+ ### Prevention Notes
208
+ - How to avoid: {prevention strategy}
209
+ - Related patterns: {similar issues}
210
+ ```
211
+
212
+ ### Pattern Extraction
213
+
214
+ Extract reusable patterns for the self-improving-agent:
215
+
216
+ ```markdown
217
+ ## Extracted Patterns
218
+
219
+ ### Code Patterns
220
+ - Pattern name: {name}
221
+ - Context: {when to use}
222
+ - Example: {code snippet}
223
+
224
+ ### Workflow Patterns
225
+ - Trigger: {what initiates}
226
+ - Steps: {sequence}
227
+ - Outcome: {expected result}
228
+
229
+ ### Anti-Patterns
230
+ - Pattern: {what to avoid}
231
+ - Why: {reason}
232
+ - Alternative: {better approach}
233
+ ```
234
+
235
+ ### Structured Data Format
236
+
237
+ For machine-readable extraction, use YAML front matter in session logs:
238
+
239
+ ```yaml
240
+ ---
241
+ session_type: skill_execution
242
+ skill_name: code-reviewer
243
+ trigger_source: hook
244
+ status: completed
245
+ files_modified:
246
+ - path: src/utils.ts
247
+ changes: refactored error handling
248
+ patterns_learned:
249
+ - name: error-boundary-pattern
250
+ category: error-handling
251
+ confidence: high
252
+ errors_encountered: []
253
+ learning_signals:
254
+ successes:
255
+ - "Identified code smell in utils.ts"
256
+ improvements:
257
+ - "Could have suggested more specific refactoring"
258
+ ---
259
+ ```
260
+
261
+ ### Integration with Self-Improving Agent
262
+
263
+ When triggered by `self-improving-agent`:
264
+
265
+ 1. **Extract episodic memory**: Capture the full context of what happened
266
+ 2. **Identify semantic patterns**: Tag reusable knowledge
267
+ 3. **Update working memory**: Note immediate follow-ups needed
268
+ 4. **Signal completion**: Write trigger file if skill chaining is needed
269
+
270
+ ### Auto-Trigger Behavior
271
+
272
+ When invoked via hooks with `mode: auto`:
273
+ - Silently create/update session log
274
+ - Extract structured data without user interaction
275
+ - Append to existing session if same day/topic
276
+ - Create new session if context differs significantly
@@ -2,6 +2,12 @@
2
2
  name: skill-router
3
3
  description: Intelligently routes user requests to the most appropriate Claude Code skill. ALWAYS use this skill FIRST when user asks for help, mentions "skill", "which", "how to", or seems unsure about which approach to take. This is the default entry point for all skill-related requests.
4
4
  allowed-tools: Read, AskUserQuestion, WebSearch, Grep
5
+ metadata:
6
+ hooks:
7
+ after_complete:
8
+ - trigger: session-logger
9
+ mode: auto
10
+ reason: "Log skill routing decisions"
5
11
  ---
6
12
 
7
13
  # Skill Router
@@ -2,6 +2,12 @@
2
2
  name: test-automator
3
3
  description: Test automation framework expert for creating and maintaining automated tests. Use when user asks to write tests, automate testing, or improve test coverage.
4
4
  allowed-tools: Read, Write, Edit, Bash, Grep, Glob
5
+ metadata:
6
+ hooks:
7
+ after_complete:
8
+ - trigger: session-logger
9
+ mode: auto
10
+ reason: "Log test creation"
5
11
  ---
6
12
 
7
13
  # Test Automator
package/src/cli.js CHANGED
@@ -264,9 +264,16 @@ async function handleSelfImprove(options) {
264
264
  const memoryRoot = path.join(os.homedir(), ".claude", "memory");
265
265
  const episodicDir = path.join(memoryRoot, "episodic", String(now.getFullYear()));
266
266
  const workingDir = path.join(memoryRoot, "working");
267
+ const triggersDir = path.join(memoryRoot, "triggers");
267
268
 
268
269
  ensureDir(episodicDir, false);
269
270
  ensureDir(workingDir, false);
271
+ ensureDir(triggersDir, false);
272
+
273
+ const toolName = input.tool_name || "";
274
+ const toolInput = input.tool_input || {};
275
+ const toolOutput = input.tool_output || {};
276
+ const hookEvent = input.hook_event_name || "PostToolUse";
270
277
 
271
278
  const entry = {
272
279
  id: `ep-${now.toISOString()}`.replace(/[:.]/g, "-"),
@@ -275,11 +282,57 @@ async function handleSelfImprove(options) {
275
282
  cwd,
276
283
  transcript_path: transcriptPath,
277
284
  agent_playbook_version: VERSION,
278
- hook_event: input.hook_event_name || "PostToolUse",
279
- tool_name: input.tool_name || "",
280
- tool_input: input.tool_input || "",
285
+ hook_event: hookEvent,
286
+ tool_name: toolName,
287
+ tool_input: toolInput,
288
+ tool_output: typeof toolOutput === "string" ? toolOutput.slice(0, 2000) : toolOutput,
281
289
  };
282
290
 
291
+ // Detect skill invocations and completions
292
+ if (toolName === "Skill") {
293
+ const skillName = toolInput.skill || "";
294
+ entry.skill_invoked = skillName;
295
+ entry.skill_args = toolInput.args || "";
296
+
297
+ // Track skill start in working memory
298
+ const skillStatePath = path.join(workingDir, "active_skills.json");
299
+ const skillState = readJsonSafe(skillStatePath) || { active: [], history: [] };
300
+
301
+ if (!skillState.active.includes(skillName)) {
302
+ skillState.active.push(skillName);
303
+ skillState.history.push({
304
+ skill: skillName,
305
+ started_at: now.toISOString(),
306
+ session_id: sessionId,
307
+ });
308
+ writeJson(skillStatePath, skillState);
309
+ }
310
+ }
311
+
312
+ // Detect skill completion patterns in tool output
313
+ const skillCompletion = detectSkillCompletion(toolName, toolInput, toolOutput, cwd);
314
+ if (skillCompletion) {
315
+ entry.skill_completed = skillCompletion.skill;
316
+ entry.completion_type = skillCompletion.type;
317
+
318
+ // Update active skills state
319
+ const skillStatePath = path.join(workingDir, "active_skills.json");
320
+ const skillState = readJsonSafe(skillStatePath) || { active: [], history: [] };
321
+ skillState.active = skillState.active.filter((s) => s !== skillCompletion.skill);
322
+
323
+ const historyEntry = skillState.history.find(
324
+ (h) => h.skill === skillCompletion.skill && !h.completed_at
325
+ );
326
+ if (historyEntry) {
327
+ historyEntry.completed_at = now.toISOString();
328
+ historyEntry.completion_type = skillCompletion.type;
329
+ }
330
+ writeJson(skillStatePath, skillState);
331
+
332
+ // Create trigger file for skill chaining
333
+ createSkillTrigger(triggersDir, skillCompletion, sessionId, cwd, now);
334
+ }
335
+
283
336
  const entryPath = path.join(episodicDir, `${entry.id}.json`);
284
337
  fs.writeFileSync(entryPath, JSON.stringify(entry, null, 2));
285
338
 
@@ -288,6 +341,145 @@ async function handleSelfImprove(options) {
288
341
  console.error(`Self-improvement entry saved to ${entryPath}`);
289
342
  }
290
343
 
344
+ function detectSkillCompletion(toolName, toolInput, toolOutput, cwd) {
345
+ const outputStr = typeof toolOutput === "string" ? toolOutput : JSON.stringify(toolOutput);
346
+
347
+ // Detect PRD completion
348
+ if (toolName === "Write" || toolName === "Edit") {
349
+ const filePath = toolInput.file_path || "";
350
+ if (filePath.includes("-prd.md") || filePath.includes("prd-task-plan.md")) {
351
+ if (outputStr.includes("COMPLETE") || outputStr.includes("Phase 6")) {
352
+ return { skill: "prd-planner", type: "prd_complete", file: filePath };
353
+ }
354
+ }
355
+ }
356
+
357
+ // Detect commit completion (commit-helper)
358
+ if (toolName === "Bash") {
359
+ const command = toolInput.command || "";
360
+ if (command.includes("git commit") && !outputStr.includes("error") && !outputStr.includes("fatal")) {
361
+ return { skill: "commit-helper", type: "commit_complete", command };
362
+ }
363
+ }
364
+
365
+ // Detect PR creation (create-pr)
366
+ if (toolName === "Bash") {
367
+ const command = toolInput.command || "";
368
+ if (command.includes("gh pr create") && outputStr.includes("github.com")) {
369
+ const prUrlMatch = outputStr.match(/https:\/\/github\.com\/[^\s]+\/pull\/\d+/);
370
+ return {
371
+ skill: "create-pr",
372
+ type: "pr_created",
373
+ pr_url: prUrlMatch ? prUrlMatch[0] : null,
374
+ };
375
+ }
376
+ }
377
+
378
+ // Detect test completion
379
+ if (toolName === "Bash") {
380
+ const command = toolInput.command || "";
381
+ if (
382
+ (command.includes("npm test") ||
383
+ command.includes("bun test") ||
384
+ command.includes("pytest") ||
385
+ command.includes("go test")) &&
386
+ (outputStr.includes("passed") || outputStr.includes("PASS"))
387
+ ) {
388
+ return { skill: "test-automator", type: "tests_passed", command };
389
+ }
390
+ }
391
+
392
+ // Detect session log creation
393
+ if (toolName === "Write") {
394
+ const filePath = toolInput.file_path || "";
395
+ if (filePath.includes("sessions/") && filePath.endsWith(".md")) {
396
+ return { skill: "session-logger", type: "session_saved", file: filePath };
397
+ }
398
+ }
399
+
400
+ return null;
401
+ }
402
+
403
+ function createSkillTrigger(triggersDir, completion, sessionId, cwd, now) {
404
+ const triggerFile = path.join(
405
+ triggersDir,
406
+ `${completion.skill}-${now.toISOString().replace(/[:.]/g, "-")}.json`
407
+ );
408
+
409
+ const trigger = {
410
+ source_skill: completion.skill,
411
+ completion_type: completion.type,
412
+ timestamp: now.toISOString(),
413
+ session_id: sessionId,
414
+ cwd,
415
+ details: completion,
416
+ pending_triggers: getHooksForSkill(completion.skill, completion.type),
417
+ };
418
+
419
+ writeJson(triggerFile, trigger);
420
+ console.error(`Skill trigger created: ${completion.skill} -> ${trigger.pending_triggers.map((t) => t.trigger).join(", ") || "none"}`);
421
+ }
422
+
423
+ function getHooksForSkill(skillName, completionType) {
424
+ // Define hooks based on skill completion
425
+ const hookDefinitions = {
426
+ "prd-planner": {
427
+ after_complete: [
428
+ { trigger: "self-improving-agent", mode: "background" },
429
+ { trigger: "session-logger", mode: "auto" },
430
+ ],
431
+ },
432
+ "prd-implementation-precheck": {
433
+ after_complete: [
434
+ { trigger: "code-reviewer", mode: "ask_first" },
435
+ { trigger: "self-improving-agent", mode: "background" },
436
+ { trigger: "session-logger", mode: "auto" },
437
+ ],
438
+ },
439
+ "commit-helper": {
440
+ after_complete: [{ trigger: "session-logger", mode: "auto" }],
441
+ },
442
+ "create-pr": {
443
+ after_complete: [{ trigger: "session-logger", mode: "auto" }],
444
+ },
445
+ "code-reviewer": {
446
+ after_complete: [
447
+ { trigger: "self-improving-agent", mode: "background" },
448
+ { trigger: "session-logger", mode: "auto" },
449
+ ],
450
+ },
451
+ "debugger": {
452
+ after_complete: [
453
+ { trigger: "self-improving-agent", mode: "background" },
454
+ { trigger: "session-logger", mode: "auto" },
455
+ ],
456
+ },
457
+ "refactoring-specialist": {
458
+ after_complete: [
459
+ { trigger: "self-improving-agent", mode: "background" },
460
+ { trigger: "session-logger", mode: "auto" },
461
+ ],
462
+ },
463
+ "test-automator": {
464
+ after_complete: [{ trigger: "session-logger", mode: "auto" }],
465
+ },
466
+ "self-improving-agent": {
467
+ after_complete: [
468
+ { trigger: "create-pr", mode: "ask_first", condition: "skills_modified" },
469
+ { trigger: "session-logger", mode: "auto" },
470
+ ],
471
+ },
472
+ };
473
+
474
+ const hooks = hookDefinitions[skillName];
475
+ if (!hooks) {
476
+ return [];
477
+ }
478
+
479
+ // Return after_complete hooks by default
480
+ return hooks.after_complete || [];
481
+ }
482
+
291
483
  function handleSkills(options, positionals, context) {
292
484
  const settings = resolveSettings(options, context || {});
293
485
  const subcommand = positionals[0] || "list";