pi-crew 0.5.1 → 0.5.5

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 (132) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/README.md +1 -1
  3. package/docs/actions-reference.md +87 -0
  4. package/docs/bugs/cross-session-notification-leakage.md +82 -0
  5. package/docs/coding-agent-optimization.md +268 -0
  6. package/docs/commands-reference.md +5 -0
  7. package/docs/deep-review-report.md +384 -0
  8. package/docs/distillation/cybersecurity-patterns.md +294 -0
  9. package/docs/migration-v0.4-v0.5.md +191 -0
  10. package/docs/optimization-plan.md +642 -0
  11. package/docs/pi-crew-bugs.md +6 -0
  12. package/docs/pi-mono-opportunities.md +969 -0
  13. package/docs/pi-mono-review.md +291 -0
  14. package/{skills → docs/skills}/REFERENCE.md +13 -5
  15. package/index.ts +1 -1
  16. package/package.json +19 -16
  17. package/skills/artifact-analysis-loop/SKILL.md +302 -0
  18. package/skills/async-worker-recovery/SKILL.md +19 -1
  19. package/skills/child-pi-spawning/SKILL.md +19 -6
  20. package/skills/context-artifact-hygiene/SKILL.md +19 -2
  21. package/skills/delegation-patterns/SKILL.md +68 -3
  22. package/skills/detection-pipeline-design/SKILL.md +285 -0
  23. package/skills/event-log-tracing/SKILL.md +20 -6
  24. package/skills/git-master/SKILL.md +20 -6
  25. package/skills/hunting-investigation-loop/SKILL.md +401 -0
  26. package/skills/incident-playbook-construction/SKILL.md +383 -0
  27. package/skills/live-agent-lifecycle/SKILL.md +20 -6
  28. package/skills/mailbox-interactive/SKILL.md +19 -6
  29. package/skills/model-routing-context/SKILL.md +19 -1
  30. package/skills/multi-perspective-review/SKILL.md +19 -4
  31. package/skills/observability-reliability/SKILL.md +19 -2
  32. package/skills/orchestration/SKILL.md +20 -2
  33. package/skills/ownership-session-security/SKILL.md +20 -2
  34. package/skills/pi-extension-lifecycle/SKILL.md +20 -2
  35. package/skills/post-mortem/SKILL.md +7 -2
  36. package/skills/read-only-explorer/SKILL.md +20 -6
  37. package/skills/requirements-to-task-packet/SKILL.md +23 -3
  38. package/skills/resource-discovery-config/SKILL.md +20 -2
  39. package/skills/runtime-state-reader/SKILL.md +20 -2
  40. package/skills/safe-bash/SKILL.md +21 -6
  41. package/skills/scrutinize/SKILL.md +20 -2
  42. package/skills/secure-agent-orchestration-review/SKILL.md +29 -2
  43. package/skills/security-review/SKILL.md +560 -0
  44. package/skills/state-mutation-locking/SKILL.md +22 -2
  45. package/skills/systematic-debugging/SKILL.md +8 -6
  46. package/skills/threat-hypothesis-framework/SKILL.md +175 -0
  47. package/skills/ui-render-performance/SKILL.md +20 -2
  48. package/skills/verification-before-done/SKILL.md +17 -2
  49. package/skills/widget-rendering/SKILL.md +21 -6
  50. package/skills/workspace-isolation/SKILL.md +20 -6
  51. package/skills/worktree-isolation/SKILL.md +20 -6
  52. package/src/agents/agent-config.ts +40 -1
  53. package/src/benchmark/benchmark-runner.ts +245 -0
  54. package/src/benchmark/feedback-loop.ts +66 -0
  55. package/src/config/config.ts +22 -5
  56. package/src/config/role-tools.ts +82 -0
  57. package/src/config/types.ts +4 -0
  58. package/src/extension/async-notifier.ts +1 -1
  59. package/src/extension/autonomous-policy.ts +1 -1
  60. package/src/extension/crew-cleanup.ts +114 -0
  61. package/src/extension/cross-extension-rpc.ts +1 -1
  62. package/src/extension/plan-orchestrate.ts +322 -0
  63. package/src/extension/register.ts +46 -44
  64. package/src/extension/registration/command-utils.ts +1 -1
  65. package/src/extension/registration/commands.ts +1 -1
  66. package/src/extension/registration/compaction-guard.ts +1 -1
  67. package/src/extension/registration/subagent-helpers.ts +1 -1
  68. package/src/extension/registration/subagent-tools.ts +1 -1
  69. package/src/extension/registration/team-tool.ts +1 -1
  70. package/src/extension/registration/viewers.ts +1 -1
  71. package/src/extension/session-summary.ts +1 -1
  72. package/src/extension/team-manager-command.ts +1 -1
  73. package/src/extension/team-tool/context.ts +1 -1
  74. package/src/extension/team-tool/handle-schedule.ts +183 -0
  75. package/src/extension/team-tool/orchestrate.ts +102 -0
  76. package/src/extension/team-tool/run.ts +222 -35
  77. package/src/extension/team-tool.ts +10 -0
  78. package/src/extension/tool-result.ts +1 -1
  79. package/src/i18n.ts +1 -1
  80. package/src/observability/event-bus.ts +60 -0
  81. package/src/observability/event-to-metric.ts +1 -1
  82. package/src/prompt/prompt-runtime.ts +1 -1
  83. package/src/runtime/background-runner.ts +35 -7
  84. package/src/runtime/child-pi.ts +122 -34
  85. package/src/runtime/crash-recovery.ts +1 -1
  86. package/src/runtime/crew-agent-runtime.ts +1 -0
  87. package/src/runtime/crew-hooks.ts +240 -0
  88. package/src/runtime/custom-tools/irc-tool.ts +1 -1
  89. package/src/runtime/custom-tools/submit-result-tool.ts +1 -1
  90. package/src/runtime/diagnostic-export.ts +38 -2
  91. package/src/runtime/foreground-control.ts +87 -17
  92. package/src/runtime/foreground-watchdog.ts +1 -1
  93. package/src/runtime/live-session-runtime.ts +1 -1
  94. package/src/runtime/mcp-proxy.ts +1 -1
  95. package/src/runtime/pi-args.ts +11 -1
  96. package/src/runtime/pi-json-output.ts +31 -0
  97. package/src/runtime/pi-spawn.ts +20 -4
  98. package/src/runtime/process-status.ts +15 -2
  99. package/src/runtime/progress-tracker.ts +124 -0
  100. package/src/runtime/runtime-resolver.ts +1 -1
  101. package/src/runtime/session-resources.ts +1 -1
  102. package/src/runtime/skill-effectiveness.ts +473 -0
  103. package/src/runtime/skill-instructions.ts +37 -3
  104. package/src/runtime/task-runner.ts +122 -18
  105. package/src/runtime/team-runner.ts +17 -11
  106. package/src/runtime/tool-progress.ts +10 -3
  107. package/src/runtime/verification-gates.ts +367 -0
  108. package/src/schema/team-tool-schema.ts +31 -1
  109. package/src/state/crew-init.ts +56 -38
  110. package/src/state/decision-ledger.ts +344 -0
  111. package/src/state/event-log.ts +136 -10
  112. package/src/state/hook-instinct-bridge.ts +90 -0
  113. package/src/state/hook-integrations.ts +51 -0
  114. package/src/state/instinct-store.ts +249 -0
  115. package/src/state/run-metrics.ts +135 -0
  116. package/src/state/state-store.ts +3 -1
  117. package/src/state/tiered-eval.ts +471 -0
  118. package/src/state/types-eval.ts +58 -0
  119. package/src/state/types.ts +7 -0
  120. package/src/tools/safe-bash-extension.ts +5 -5
  121. package/src/types/new-api-types.ts +34 -0
  122. package/src/ui/agent-management-overlay.ts +5 -1
  123. package/src/ui/crew-widget.ts +30 -16
  124. package/src/ui/pi-ui-compat.ts +1 -1
  125. package/src/ui/powerbar-publisher.ts +100 -7
  126. package/src/ui/run-action-dispatcher.ts +1 -1
  127. package/src/ui/tool-render.ts +17 -17
  128. package/src/utils/project-detector.ts +160 -0
  129. package/src/utils/session-utils.ts +52 -0
  130. package/src/worktree/worktree-manager.ts +32 -13
  131. package/test-bugs-all.mjs +1 -1
  132. package/skills/.gitkeep +0 -0
@@ -0,0 +1,285 @@
1
+ ---
2
+ name: detection-pipeline-design
3
+ description: "Design data pipelines for security monitoring and threat intelligence."
4
+ triggers:
5
+ - "build pipeline"
6
+ - "design detection"
7
+ - "setup monitoring"
8
+ - "enrich data"
9
+ - "threat intelligence"
10
+ ---
11
+ # detection-pipeline-design
12
+
13
+ Use this skill when designing data pipelines for security detection and enrichment.
14
+
15
+ ## Source
16
+
17
+ Distilled from `building-ioc-enrichment-pipeline-with-opencti` (Anthropic Cybersecurity Skills) and generalized for software/build context.
18
+
19
+ ## When to Use
20
+
21
+ - Building detection and monitoring systems
22
+ - Designing security data pipelines
23
+ - Setting up automated threat intelligence
24
+ - Creating alert enrichment workflows
25
+ - Integrating security scanning into CI/CD
26
+
27
+ ## Pipeline Architecture
28
+
29
+ ```
30
+ ┌─────────┐ ┌──────────┐ ┌──────────┐ ┌─────────┐ ┌─────────┐
31
+ │ Input │ → │ Transform│ → │ Enrich │ → │ Score │ → │ Route │
32
+ │ Data │ │ (Norm) │ │ (Context)│ │ (Conf) │ │(Action) │
33
+ └─────────┘ └──────────┘ └──────────┘ └─────────┘ └─────────┘
34
+
35
+ ┌──────────┐
36
+ │ Output │
37
+ │ Findings │
38
+ └──────────┘
39
+ ```
40
+
41
+ ## Pipeline Components
42
+
43
+ ### 1. Input Stage
44
+
45
+ ```yaml
46
+ input:
47
+ types:
48
+ - name: file_change
49
+ sources: [git, filesystem]
50
+ - name: log_event
51
+ sources: [application, system]
52
+ - name: alert
53
+ sources: [scanner, monitor]
54
+ - name: dependency
55
+ sources: [npm, pip, cargo]
56
+ format: [json, plain_text, structured]
57
+ polling: [real_time, batch, scheduled]
58
+ ```
59
+
60
+ ### 2. Transform Stage
61
+
62
+ ```yaml
63
+ transform:
64
+ operations:
65
+ - name: normalize
66
+ description: Convert to standard format
67
+ output: stix_like_object
68
+ - name: extract_indicators
69
+ description: Pull out IOCs
70
+ extract: [ips, domains, hashes, credentials, tokens]
71
+ - name: enrich_metadata
72
+ description: Add context
73
+ add: [file_type, language, framework, timestamp]
74
+ output_format: json
75
+ ```
76
+
77
+ ### 3. Enrich Stage
78
+
79
+ ```yaml
80
+ enrich:
81
+ internal_sources:
82
+ - name: vulnerability_db
83
+ query: [cve_id, cwe]
84
+ - name: code_analysis
85
+ query: [pattern, structure]
86
+ - name: git_history
87
+ query: [author, commit, diff]
88
+ external_sources:
89
+ - name: npm_audit
90
+ api: npmjs.org
91
+ - name: osv
92
+ api: osv.dev
93
+ - name: gh_advisory
94
+ api: github.com/advisories
95
+ async: true
96
+ timeout_ms: 5000
97
+ ```
98
+
99
+ ### 4. Score Stage
100
+
101
+ ```yaml
102
+ score:
103
+ confidence_calculation:
104
+ factors:
105
+ - name: source_reliability
106
+ weight: 0.3
107
+ scale: [0-10]
108
+ - name: contextual_evidence
109
+ weight: 0.4
110
+ scale: [0-10]
111
+ - name: historical_matches
112
+ weight: 0.3
113
+ scale: [0-10]
114
+ formula: >
115
+ (reliability * 0.3) +
116
+ (evidence * 0.4) +
117
+ (historical * 0.3)
118
+ thresholds:
119
+ critical: [90-100]
120
+ high: [70-89]
121
+ medium: [40-69]
122
+ low: [0-39]
123
+ ```
124
+
125
+ ### 5. Route Stage
126
+
127
+ ```yaml
128
+ route:
129
+ paths:
130
+ - condition: "score >= 90"
131
+ action: [alert, block, notify]
132
+ destination: [security_team, incident_response]
133
+ - condition: "score >= 70"
134
+ action: [alert, review]
135
+ destination: [security_queue]
136
+ - condition: "score >= 40"
137
+ action: [log, monitor]
138
+ destination: [security_logs]
139
+ - condition: "score < 40"
140
+ action: [ignore]
141
+ destination: []
142
+ ```
143
+
144
+ ## Pipeline Design Patterns
145
+
146
+ ### Pattern 1: Real-time File Monitoring
147
+
148
+ ```yaml
149
+ pipeline:
150
+ name: file-change-detection
151
+ trigger:
152
+ type: filesystem_watch
153
+ paths: ["src/**/*.ts", "src/**/*.js"]
154
+ transform:
155
+ - extract: [imports, function_calls, secrets]
156
+ enrich:
157
+ - check: npm_audit
158
+ - check: known_vulnerable_patterns
159
+ score:
160
+ - base: vulnerability_severity
161
+ - modifier: exploitability
162
+ route:
163
+ critical: slack_alert + block_merge
164
+ high: github_issue + notify
165
+ medium: log + track
166
+ ```
167
+
168
+ ### Pattern 2: Dependency Vulnerability Pipeline
169
+
170
+ ```yaml
171
+ pipeline:
172
+ name: dependency-vuln-scan
173
+ trigger:
174
+ type: package_lock_change
175
+ transform:
176
+ - extract: [package_names, versions, sources]
177
+ enrich:
178
+ - query: osv_database
179
+ - query: npm_advisories
180
+ - query: github_advisories
181
+ score:
182
+ - base: cvss_score
183
+ - modifier: [has_exploit, is_dependencies]
184
+ route:
185
+ critical: [create_security_issue, alert_team]
186
+ high: [create_issue, schedule_fix]
187
+ medium: [add_to_backlog]
188
+ low: [note_in_changelog]
189
+ ```
190
+
191
+ ### Pattern 3: Secret Detection Pipeline
192
+
193
+ ```yaml
194
+ pipeline:
195
+ name: secret-detection
196
+ trigger:
197
+ type: git_push
198
+ transform:
199
+ - extract: [api_keys, tokens, passwords, credentials]
200
+ enrich:
201
+ - validate: key_format
202
+ - check: blacklists
203
+ score:
204
+ - base: key_validity
205
+ - modifier: [key_age, exposure_scope]
206
+ route:
207
+ critical: [revoke_key, alert_security, block_push]
208
+ high: [notify_owner, rotate_key]
209
+ medium: [flag_for_review]
210
+ low: [log]
211
+ ```
212
+
213
+ ## Implementation Example
214
+
215
+ ```typescript
216
+ interface DetectionPipeline {
217
+ name: string;
218
+ input: InputConfig;
219
+ transform: TransformConfig;
220
+ enrich: EnrichConfig;
221
+ score: ScoreConfig;
222
+ route: RouteConfig;
223
+ }
224
+
225
+ async function runPipeline(pipeline: DetectionPipeline, data: unknown): Promise<PipelineResult> {
226
+ // 1. Input validation
227
+ const normalized = normalizeInput(data, pipeline.input);
228
+
229
+ // 2. Transform - extract indicators
230
+ const indicators = extractIndicators(normalized, pipeline.transform);
231
+
232
+ // 3. Enrich - query external/internal sources
233
+ const enriched = await enrichIndicators(indicators, pipeline.enrich);
234
+
235
+ // 4. Score - calculate confidence
236
+ const scored = calculateScore(enriched, pipeline.score);
237
+
238
+ // 5. Route - determine action
239
+ const action = determineAction(scored, pipeline.route);
240
+
241
+ return { indicators, enriched, scored, action };
242
+ }
243
+ ```
244
+
245
+ ## Enforcement — Detection Pipeline Design Gate
246
+
247
+ **Before deploying detection pipelines, verify:**
248
+
249
+ - [ ] Input format validated before transform stage
250
+ - [ ] Scoring thresholds tuned to environment (not hardcoded defaults)
251
+ - [ ] Confidence calculation includes multiple factors (reliability, evidence, history)
252
+ - [ ] Route actions match score thresholds (critical → block, low → ignore)
253
+ - [ ] False positive rate measured and acceptable
254
+ - [ ] External API calls are async (non-blocking)
255
+
256
+ If ANY answer is NO → Stop. Tune the pipeline before deploying.
257
+
258
+ ## Anti-Patterns
259
+
260
+ - **Don't** skip input validation (garbage in, garbage out)
261
+ - **Don't** skip enrichment (missing context leads to false positives)
262
+ - **Don't** use fixed thresholds (tune based on environment)
263
+ - **Don't** ignore false positive rates (kills analyst productivity)
264
+ - **Don't** block on external APIs in synchronous path (use async)
265
+
266
+ ## Tools & Integrations
267
+
268
+ | Tool | Pipeline Role |
269
+ |------|---------------|
270
+ | `semgrep` | Static analysis, pattern matching |
271
+ | `npm audit` | Dependency vulnerability |
272
+ | `trufflehog` | Secret scanning |
273
+ | `grype` | Container vulnerability |
274
+ | `syft` | SBOM generation |
275
+
276
+ ## Verification
277
+
278
+ For pipeline design changes:
279
+ ```bash
280
+ cd pi-crew
281
+ npx tsc --noEmit
282
+ node --experimental-strip-types --test test/unit/detection-pipeline.test.ts
283
+ ```
284
+
285
+ *See also: `detection-signature-authoring` (in security-review) for detection rule patterns.*
@@ -1,8 +1,13 @@
1
1
  ---
2
2
  name: event-log-tracing
3
- description: "Structured event logging for worker lifecycle, live agents, crash recovery. Use when debugging crashes, tracing agent lifecycle, investigating stale runs. Triggers: event log, trace events, worker crashed, agent died, stale run, events.jsonl."
3
+ description: "Structured event logging for worker lifecycle, live agents, crash recovery."
4
+ triggers:
5
+ - "event log"
6
+ - "trace events"
7
+ - "worker crashed"
8
+ - "agent died"
9
+ - "stale run"
4
10
  ---
5
-
6
11
  # event-log-tracing
7
12
 
8
13
  Every pi-crew run writes a persistent event log at `.crew/state/runs/<runId>/events.jsonl`. Events are the primary evidence for understanding what happened — especially when workers crash, agents get stuck, or runs become orphaned.
@@ -31,8 +36,6 @@ Every event is a JSON object on one line:
31
36
  **Optional fields:** `taskId`, `message`, `data`, `metadata`
32
37
  **Metadata auto-populated:** `seq` (line number), `provenance` (who wrote it), `fingerprint` (for terminal events)
33
38
 
34
- ---
35
-
36
39
  ## Event Taxonomy
37
40
 
38
41
  ### Worker Lifecycle Events (from child-pi.ts via onLifecycleEvent callback)
@@ -112,8 +115,6 @@ These track the full lifecycle from spawn to cleanup.
112
115
  | `crew.run.reconciled_stale` | `reconcileStaleRun` repaired a stale run | `{verdict}` |
113
116
  | `crew.run.orphan_cancelled` | `cancelOrphanedRuns` cancelled a run | `{ownerSessionId, cancelledTasks}` |
114
117
 
115
- ---
116
-
117
118
  ## appendEvent Pipeline
118
119
 
119
120
  ```
@@ -257,6 +258,19 @@ crew.run.reconciled_stale verdict=pid_dead
257
258
 
258
259
  ---
259
260
 
261
+ ## Enforcement — Event Log Tracing Gate
262
+
263
+ **Before interpreting events or debugging crashes, verify:**
264
+
265
+ - [ ] Event format validated (required fields: time, type, runId present)
266
+ - [ ] runId correlation confirmed (all events have same runId for the trace)
267
+ - [ ] Terminal events have fingerprints (completed/failed/cancelled)
268
+ - [ ] Event sequence matches expected lifecycle pattern
269
+ - [ ] Corrupt JSONL handled (skip malformed lines, don't fail entire read)
270
+ - [ ] Secrets redacted in data fields before logging
271
+
272
+ If ANY answer is NO → Stop. Re-examine event source and format.
273
+
260
274
  ## Anti-patterns
261
275
 
262
276
  - **`logInternalError` only logs in debug mode**: Production errors are silent — `events.jsonl` is the only durable evidence. Always emit events, never rely on `console.error`.
@@ -1,8 +1,13 @@
1
1
  ---
2
2
  name: git-master
3
- description: Commit and release hygiene for safe version-control work. Use when preparing commits, releases, version bumps, publishing, or validating package installation.
3
+ description: "Commit and release hygiene for safe version-control work."
4
+ triggers:
5
+ - "commit this"
6
+ - "tag release"
7
+ - "bump version"
8
+ - "publish package"
9
+ - "prepare release"
4
10
  ---
5
-
6
11
  # git-master
7
12
 
8
13
  Use this skill for commit/release hygiene. This skill covers git workflow from local changes to published releases.
@@ -186,6 +191,19 @@ git stash drop # remove latest stash
186
191
  git stash clear # remove all stashes
187
192
  ```
188
193
 
194
+ ## Enforcement — Git Master Gate
195
+
196
+ **Before committing or publishing, verify:**
197
+
198
+ - [ ] `git status` reviewed — only related files staged
199
+ - [ ] `git diff --staged` reviewed — no unintended changes
200
+ - [ ] Tests pass locally (`npm test` or appropriate test command)
201
+ - [ ] No secrets in staged changes (API keys, tokens, passwords)
202
+ - [ ] Commit message follows format: `type(scope): subject` (50 chars or less)
203
+ - [ ] No generated files staged unless intentional
204
+
205
+ If ANY answer is NO → Stop. Fix issues before committing.
206
+
189
207
  ## Anti-patterns
190
208
 
191
209
  - **Committing generated files**: Don't commit `dist/`, `build/`, `*.min.js` unless intentional
@@ -195,8 +213,6 @@ git stash clear # remove all stashes
195
213
  - **Committing secrets**: Check for `API_KEY`, `TOKEN`, `PASSWORD`, `SECRET` before staging
196
214
  - **Unclear messages**: "fix stuff" is not a valid commit message
197
215
 
198
- ---
199
-
200
216
  ## Source patterns
201
217
 
202
218
  - `src/state/atomic-write.ts` — atomic git-safe file writes
@@ -204,8 +220,6 @@ git stash clear # remove all stashes
204
220
  - `src/utils/conflict-detect.ts` — git conflict detection
205
221
  - `package.json` — version field, publish scripts
206
222
 
207
- ---
208
-
209
223
  ## Verification
210
224
 
211
225
  ```bash