pi-crew 0.5.2 → 0.5.6

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 (137) hide show
  1. package/CHANGELOG.md +183 -0
  2. package/README.md +17 -1
  3. package/docs/architecture.md +2 -0
  4. package/docs/bugs/cross-session-notification-leakage.md +82 -0
  5. package/docs/coding-agent-optimization.md +268 -0
  6. package/docs/deep-review-report.md +384 -0
  7. package/docs/distillation/cybersecurity-patterns.md +294 -0
  8. package/docs/migration-v0.4-v0.5.md +208 -0
  9. package/docs/optimization-plan.md +642 -0
  10. package/docs/pi-crew-v0.5.5-audit-fix-plan.md +133 -0
  11. package/docs/pi-mono-opportunities.md +969 -0
  12. package/docs/pi-mono-review.md +291 -0
  13. package/docs/skills/REFERENCE.md +144 -0
  14. package/package.json +12 -9
  15. package/skills/artifact-analysis-loop/SKILL.md +302 -0
  16. package/skills/async-worker-recovery/SKILL.md +19 -1
  17. package/skills/child-pi-spawning/SKILL.md +19 -6
  18. package/skills/context-artifact-hygiene/SKILL.md +19 -2
  19. package/skills/delegation-patterns/SKILL.md +68 -3
  20. package/skills/detection-pipeline-design/SKILL.md +285 -0
  21. package/skills/event-log-tracing/SKILL.md +20 -6
  22. package/skills/git-master/SKILL.md +20 -6
  23. package/skills/hunting-investigation-loop/SKILL.md +401 -0
  24. package/skills/incident-playbook-construction/SKILL.md +383 -0
  25. package/skills/live-agent-lifecycle/SKILL.md +20 -6
  26. package/skills/mailbox-interactive/SKILL.md +19 -6
  27. package/skills/model-routing-context/SKILL.md +19 -1
  28. package/skills/multi-perspective-review/SKILL.md +19 -4
  29. package/skills/observability-reliability/SKILL.md +19 -2
  30. package/skills/orchestration/SKILL.md +20 -2
  31. package/skills/ownership-session-security/SKILL.md +20 -2
  32. package/skills/pi-extension-lifecycle/SKILL.md +20 -2
  33. package/skills/post-mortem/SKILL.md +7 -2
  34. package/skills/read-only-explorer/SKILL.md +20 -6
  35. package/skills/requirements-to-task-packet/SKILL.md +23 -3
  36. package/skills/resource-discovery-config/SKILL.md +20 -2
  37. package/skills/runtime-state-reader/SKILL.md +20 -2
  38. package/skills/safe-bash/SKILL.md +21 -6
  39. package/skills/scrutinize/SKILL.md +20 -2
  40. package/skills/secure-agent-orchestration-review/SKILL.md +29 -2
  41. package/skills/security-review/SKILL.md +560 -0
  42. package/skills/state-mutation-locking/SKILL.md +22 -2
  43. package/skills/systematic-debugging/SKILL.md +8 -6
  44. package/skills/threat-hypothesis-framework/SKILL.md +175 -0
  45. package/skills/ui-render-performance/SKILL.md +20 -2
  46. package/skills/verification-before-done/SKILL.md +17 -2
  47. package/skills/widget-rendering/SKILL.md +21 -6
  48. package/skills/workspace-isolation/SKILL.md +20 -6
  49. package/skills/worktree-isolation/SKILL.md +20 -6
  50. package/src/agents/agent-config.ts +40 -1
  51. package/src/benchmark/benchmark-runner.ts +45 -0
  52. package/src/benchmark/feedback-loop.ts +5 -0
  53. package/src/config/config.ts +32 -5
  54. package/src/config/role-tools.ts +82 -0
  55. package/src/config/suggestions.ts +8 -0
  56. package/src/config/types.ts +4 -0
  57. package/src/extension/async-notifier.ts +10 -1
  58. package/src/extension/crew-cleanup.ts +114 -0
  59. package/src/extension/cross-extension-rpc.ts +1 -1
  60. package/src/extension/notification-router.ts +18 -0
  61. package/src/extension/register.ts +27 -19
  62. package/src/extension/registration/subagent-tools.ts +1 -1
  63. package/src/extension/team-tool/anchor.ts +201 -0
  64. package/src/extension/team-tool/api.ts +2 -1
  65. package/src/extension/team-tool/auto-summarize.ts +154 -0
  66. package/src/extension/team-tool/run.ts +42 -7
  67. package/src/extension/team-tool.ts +44 -2
  68. package/src/hooks/registry.ts +1 -3
  69. package/src/observability/event-bus.ts +69 -0
  70. package/src/observability/event-to-metric.ts +0 -2
  71. package/src/runtime/anchor-manager.ts +473 -0
  72. package/src/runtime/async-runner.ts +8 -4
  73. package/src/runtime/auto-summarize.ts +350 -0
  74. package/src/runtime/background-runner.ts +10 -3
  75. package/src/runtime/budget-tracker.ts +354 -0
  76. package/src/runtime/chain-runner.ts +507 -0
  77. package/src/runtime/child-pi.ts +123 -35
  78. package/src/runtime/crash-recovery.ts +5 -4
  79. package/src/runtime/crew-agent-runtime.ts +1 -0
  80. package/src/runtime/custom-tools/irc-tool.ts +13 -0
  81. package/src/runtime/custom-tools/submit-result-tool.ts +3 -2
  82. package/src/runtime/delivery-coordinator.ts +10 -3
  83. package/src/runtime/dynamic-script-runner.ts +482 -0
  84. package/src/runtime/foreground-control.ts +87 -17
  85. package/src/runtime/handoff-manager.ts +589 -0
  86. package/src/runtime/hidden-handoff.ts +424 -0
  87. package/src/runtime/live-agent-manager.ts +20 -4
  88. package/src/runtime/live-session-runtime.ts +39 -4
  89. package/src/runtime/manifest-cache.ts +2 -1
  90. package/src/runtime/model-resolver.ts +16 -4
  91. package/src/runtime/phase-tracker.ts +373 -0
  92. package/src/runtime/pi-args.ts +11 -1
  93. package/src/runtime/pi-json-output.ts +31 -0
  94. package/src/runtime/pipeline-runner.ts +514 -0
  95. package/src/runtime/progress-tracker.ts +124 -0
  96. package/src/runtime/retry-runner.ts +354 -0
  97. package/src/runtime/sandbox.ts +252 -0
  98. package/src/runtime/scheduler.ts +7 -2
  99. package/src/runtime/skill-effectiveness.ts +473 -0
  100. package/src/runtime/skill-instructions.ts +37 -3
  101. package/src/runtime/subagent-manager.ts +1 -1
  102. package/src/runtime/task-graph.ts +11 -1
  103. package/src/runtime/task-runner.ts +92 -18
  104. package/src/runtime/team-runner.ts +13 -12
  105. package/src/runtime/tool-progress.ts +10 -3
  106. package/src/runtime/verification-gates.ts +367 -0
  107. package/src/schema/team-tool-schema.ts +37 -0
  108. package/src/skills/discover-skills.ts +5 -0
  109. package/src/state/active-run-registry.ts +9 -2
  110. package/src/state/contracts.ts +9 -0
  111. package/src/state/crew-init.ts +3 -3
  112. package/src/state/decision-ledger.ts +98 -55
  113. package/src/state/event-log-rotation.ts +2 -2
  114. package/src/state/event-log.ts +144 -10
  115. package/src/state/hook-instinct-bridge.ts +5 -5
  116. package/src/state/mailbox.ts +10 -0
  117. package/src/state/run-cache.ts +18 -8
  118. package/src/state/state-store.ts +3 -1
  119. package/src/state/types.ts +4 -0
  120. package/src/tools/safe-bash-extension.ts +1 -0
  121. package/src/tools/safe-bash.ts +152 -20
  122. package/src/types/new-api-types.ts +34 -0
  123. package/src/ui/agent-management-overlay.ts +5 -1
  124. package/src/ui/crew-widget.ts +29 -15
  125. package/src/ui/overlays/mailbox-detail-overlay.ts +13 -2
  126. package/src/ui/powerbar-publisher.ts +101 -7
  127. package/src/ui/tool-render.ts +15 -15
  128. package/src/ui/transcript-cache.ts +13 -0
  129. package/src/utils/bm25-search.ts +16 -8
  130. package/src/utils/env-filter.ts +8 -5
  131. package/src/utils/redaction.ts +169 -15
  132. package/src/utils/session-utils.ts +52 -0
  133. package/src/utils/sse-parser.ts +10 -1
  134. package/src/worktree/cleanup.ts +6 -1
  135. package/src/worktree/worktree-manager.ts +32 -13
  136. package/workflows/chain.workflow.md +252 -0
  137. package/workflows/pipeline.workflow.md +27 -0
@@ -0,0 +1,401 @@
1
+ ---
2
+ name: hunting-investigation-loop
3
+ description: "Active hypothesis-driven investigation and threat hunting."
4
+ triggers:
5
+ - "hunt for"
6
+ - "find evidence of"
7
+ - "investigate"
8
+ - "active search"
9
+ - "forensic hunt"
10
+ ---
11
+ # hunting-investigation-loop
12
+
13
+ Use this skill when conducting active, hypothesis-driven threat hunting and investigation.
14
+
15
+ ## Source
16
+
17
+ Distilled from 28 `hunting-for-*` skills (Anthropic Cybersecurity Skills) and generalized for software/codebase context.
18
+
19
+ ## When to Use
20
+
21
+ - Proactively hunting for indicators of compromise
22
+ - Investigating suspicious patterns without clear incident
23
+ - Periodic security assessments
24
+ - After threat intelligence suggests specific patterns
25
+ - Purple team exercises
26
+
27
+ ## Core Loop
28
+
29
+ ```
30
+ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
31
+ │ Form │ → │ Locate │ → │ Query │ → │ Analyze │
32
+ │ Hypothesis │ │ Data Sources│ │ Search │ │ Results │
33
+ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘
34
+
35
+ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
36
+ │ Report │ ← │ Document │ ← │ Scope │ ← │ Validate │
37
+ │ Findings │ │ Evidence │ │ Extent │ │ Findings │
38
+ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘
39
+ ```
40
+
41
+ ## Investigation Loop
42
+
43
+ ```markdown
44
+ ## Hunting Investigation Loop
45
+
46
+ 1. **Form Hypothesis** → "There might be [vulnerability/pattern] in [location]"
47
+ 2. **Identify Hunt** → Search location: [files, commits, logs, configs]
48
+ 3. **Execute Search** → Query: [grep, regex, pattern match]
49
+ 4. **Analyze Results** → Filter: [true_positive, false_positive, noise]
50
+ 5. **Validate** → Confirm: [secondary source, cross-reference]
51
+ 6. **Scope** → Extent: [how many files, lines, occurrences]
52
+ 7. **Document** → Findings: [file, line, pattern, severity]
53
+ ```
54
+
55
+ ## Hunt Structure
56
+
57
+ ```yaml
58
+ hunt:
59
+ id: string # e.g., "HUNT-2026-001"
60
+ hypothesis: string # What we're testing
61
+ technique: string # e.g., "credential_theft", "injection"
62
+ status: [planned|running|completed|cancelled]
63
+
64
+ data_sources:
65
+ - name: string
66
+ type: [file|commit|log|config|database]
67
+ locations: [paths, globs, queries]
68
+ priority: [high|medium|low]
69
+
70
+ search_patterns:
71
+ - pattern: string
72
+ type: [regex|AST|signature|heuristic]
73
+ context_needed: int # Lines before/after
74
+ expected_findings: int # Estimated findings
75
+
76
+ validation:
77
+ methods:
78
+ - name: string
79
+ description: string
80
+ expected: string # What validation should confirm
81
+ cross_references:
82
+ - source: string
83
+ query: string
84
+
85
+ findings:
86
+ - file: string
87
+ line: number
88
+ evidence: string
89
+ confidence: [high|medium|low]
90
+ validated: boolean
91
+
92
+ scope:
93
+ total_findings: int
94
+ files_affected: int
95
+ severity: [critical|high|medium|low]
96
+
97
+ next_actions:
98
+ - investigate: [further analysis needed]
99
+ - contain: [immediate action required]
100
+ - remediate: [fix required]
101
+ - close: [false positive, no action]
102
+ ```
103
+
104
+ ## Hypothesis Templates
105
+
106
+ ### Template 1: Credential Pattern Hunt
107
+
108
+ ```yaml
109
+ hypothesis:
110
+ id: HUNT-2026-CRED-001
111
+ title: Hardcoded credentials in codebase
112
+ technique: credential_exposure
113
+ data_sources:
114
+ - name: source_code
115
+ type: file
116
+ locations: ["**/*.ts", "**/*.js", "**/*.py"]
117
+ - name: config_files
118
+ type: file
119
+ locations: ["**/*.json", "**/*.yaml", "**/*.env"]
120
+ search_patterns:
121
+ - pattern: '(password|secret|token|key)\s*[=:]\s*["\'][^"\']{10,}'
122
+ type: regex
123
+ - pattern: 'process\.env\.[A-Z_]{5,}'
124
+ type: regex
125
+ validation:
126
+ - method: git_history_check
127
+ description: Check if credentials were ever committed
128
+ - method: secret_scanner
129
+ description: Run trufflehog to confirm
130
+ ```
131
+
132
+ ### Template 2: Injection Pattern Hunt
133
+
134
+ ```yaml
135
+ hypothesis:
136
+ id: HUNT-2026-INJ-001
137
+ title: Code injection vulnerabilities
138
+ technique: command_injection
139
+ data_sources:
140
+ - name: source_code
141
+ type: file
142
+ locations: ["**/*.ts", "**/*.js", "**/*.py", "**/*.go"]
143
+ search_patterns:
144
+ - pattern: '(eval|exec|Function|spawn)\s*\('
145
+ type: regex
146
+ - pattern: 'child_process.*exec.*template'
147
+ type: AST
148
+ validation:
149
+ - method: confirm_user_input_taint
150
+ description: Check if eval input includes user data
151
+ - method: test_in_sandbox
152
+ description: Execute with controlled input
153
+ ```
154
+
155
+ ### Template 3: Supply Chain Hunt
156
+
157
+ ```yaml
158
+ hypothesis:
159
+ id: HUNT-2026-SUPPLY-001
160
+ title: Dependency confusion or typosquatting
161
+ technique: supply_chain_attack
162
+ data_sources:
163
+ - name: package_manifest
164
+ type: file
165
+ locations: ["package.json", "requirements.txt", "Cargo.toml"]
166
+ search_patterns:
167
+ - pattern: '"@private/.*"'
168
+ type: regex
169
+ - pattern: 'version.*>.*9999999'
170
+ type: regex
171
+ validation:
172
+ - method: npm_audit
173
+ description: Check for malicious packages
174
+ - method: typosquat_check
175
+ description: Check for similar package names
176
+ ```
177
+
178
+ ### Template 4: Persistence Mechanism Hunt
179
+
180
+ ```yaml
181
+ hypothesis:
182
+ id: HUNT-2026-PERS-001
183
+ title: Malicious persistence mechanisms
184
+ technique: persistence
185
+ data_sources:
186
+ - name: startup_files
187
+ type: file
188
+ locations: ["**/startup/**", "**/init/**", "**/.profile"]
189
+ - name: cron_configs
190
+ type: file
191
+ locations: ["**/cron/**", "**/.crontab"]
192
+ - name: systemd
193
+ type: file
194
+ locations: ["**/*.service", "**/systemd/**"]
195
+ search_patterns:
196
+ - pattern: '(wget|curl).*\|.*(bash|sh)'
197
+ type: regex
198
+ - pattern: 'nohup.*background'
199
+ type: regex
200
+ validation:
201
+ - method: confirm_evil_binary
202
+ description: Check downloaded binary hash
203
+ - method: network_check
204
+ description: Check for suspicious network activity
205
+ ```
206
+
207
+ ## Hunt Execution
208
+
209
+ ### Phase 1: Form Hypothesis
210
+
211
+ Before starting a hunt, clearly define:
212
+ - What you're looking for
213
+ - Why you think it might exist
214
+ - Where to look
215
+ - How to confirm
216
+
217
+ ```markdown
218
+ ## Hypothesis Formulation Checklist
219
+
220
+ - [ ] Clear technique/pattern being hunted
221
+ - [ ] Known attack chain context
222
+ - [ ] Data sources identified
223
+ - [ ] Search patterns defined
224
+ - [ ] Validation method specified
225
+ - [ ] False positive patterns identified
226
+ ```
227
+
228
+ ### Phase 2: Execute Search
229
+
230
+ Run searches in priority order:
231
+
232
+ ```bash
233
+ # High priority - common locations
234
+ rg -n "pattern" --type ts src/ | head -50
235
+
236
+ # Config files
237
+ rg -n "pattern" --type json --type yaml config/ | head -20
238
+
239
+ # Check for encoded/obfuscated
240
+ rg -n "atob|b64decode|base64" --type js | head -20
241
+ ```
242
+
243
+ ### Phase 3: Analyze Results
244
+
245
+ Filter findings by:
246
+ 1. **True Positive** - Actual vulnerability/indicator
247
+ 2. **False Positive** - Known benign pattern
248
+ 3. **Noise** - Irrelevant matches
249
+
250
+ ```yaml
251
+ analysis:
252
+ true_positives:
253
+ count: int
254
+ examples:
255
+ - file: path
256
+ line: number
257
+ reason: why this is a finding
258
+ false_positives:
259
+ count: int
260
+ reasons:
261
+ - known_benign_pattern
262
+ - test_code
263
+ - excluded_by_validation
264
+ noise:
265
+ count: int
266
+ reasons:
267
+ - not_in_scope
268
+ - duplicate_findings
269
+ ```
270
+
271
+ ### Phase 4: Validate
272
+
273
+ For each potential finding:
274
+ 1. Cross-reference with other data sources
275
+ 2. Check git history for context
276
+ 3. Verify with secondary method
277
+ 4. Assess exploitability
278
+
279
+ ```yaml
280
+ validation:
281
+ method_1:
282
+ name: secondary_source_check
283
+ result: [confirmed|suspected|false_positive]
284
+ evidence: string
285
+ method_2:
286
+ name: git_history_check
287
+ result: [confirmed|suspected|false_positive]
288
+ evidence: string
289
+ method_3:
290
+ name: exploitability_assessment
291
+ result: [confirmed|suspected|false_positive]
292
+ evidence: string
293
+ ```
294
+
295
+ ### Phase 5: Scope and Document
296
+
297
+ Document findings with:
298
+ - Exact location (file:line)
299
+ - Evidence (code snippet, pattern match)
300
+ - Confidence level
301
+ - Validation results
302
+ - Recommended action
303
+
304
+ ## Hunt Report Format
305
+
306
+ ```
307
+ Hunt Report: [HUNT-ID]
308
+ ==============
309
+
310
+ Hypothesis: [what we tested]
311
+ Hunt Date: [timestamp]
312
+ Hypothesis: [technique/pattern]
313
+
314
+ ## Executive Summary
315
+
316
+ - Total Findings: [N]
317
+ - Critical: [N] | High: [N] | Medium: [N] | Low: [N]
318
+ - Files Affected: [N]
319
+ - Confidence: [Overall assessment]
320
+
321
+ ## Data Sources Searched
322
+
323
+ - [source 1]: [findings count]
324
+ - [source 2]: [findings count]
325
+
326
+ ## Findings
327
+
328
+ ### [Finding 1] - [Severity]
329
+ Location: [file:line]
330
+ Evidence:
331
+ ```
332
+ [code snippet]
333
+ ```
334
+ Validated: [YES/NO - how]
335
+ Recommendation: [action]
336
+
337
+ ### [Finding 2]...
338
+
339
+ ## False Positives
340
+
341
+ - [why certain matches were dismissed]
342
+
343
+ ## Next Actions
344
+
345
+ - [ ] Investigate further: [specific items]
346
+ - [ ] Remediate: [specific items]
347
+ - [ ] Monitor: [specific items]
348
+
349
+ ## Conclusion
350
+
351
+ [Overall assessment of hunt results]
352
+ ```
353
+
354
+ ## Hunt Status Tracking
355
+
356
+ ```yaml
357
+ hunt_status:
358
+ planned:
359
+ - id: string
360
+ hypothesis: string
361
+ planned_date: date
362
+ running:
363
+ - id: string
364
+ start_time: timestamp
365
+ current_phase: [form|locate|query|analyze|validate|report]
366
+ findings_count: int
367
+ completed:
368
+ - id: string
369
+ end_time: timestamp
370
+ outcome: [findings_confirmed|no_findings|false_positive]
371
+ report_path: string
372
+ ```
373
+
374
+ ## Anti-Patterns
375
+
376
+ - **Don't** hunt without clear hypothesis (scattershot searching)
377
+ - **Don't** skip data source identification (missing coverage)
378
+ - **Don't** skip validation (false positive flood)
379
+ - **Don't** skip false positive documentation (repeating mistakes)
380
+ - **Don't** report without confidence level (misleads stakeholders)
381
+
382
+ ## Tools
383
+
384
+ | Tool | Purpose |
385
+ |------|---------|
386
+ | `rg` (ripgrep) | Pattern search in files |
387
+ | `git log` | History investigation |
388
+ | `semgrep` | AST-based pattern matching |
389
+ | `grep` | Binary/encoded string search |
390
+ | `jq` | JSON log analysis |
391
+
392
+ ## Verification
393
+
394
+ For hunting framework changes:
395
+ ```bash
396
+ cd pi-crew
397
+ npx tsc --noEmit
398
+ node --experimental-strip-types --test test/unit/hunting-patterns.test.ts
399
+ ```
400
+
401
+ *See also: `threat-hypothesis-framework` for structured hypothesis creation, `read-only-explorer` for exploration fundamentals.*