@query-ai/digital-workers 1.0.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.
@@ -0,0 +1,628 @@
1
+ ---
2
+ name: threat-hunt
3
+ description: Use when hunting for threats, testing a hypothesis, proactively searching for TTPs, or when the analyst asks "what should I hunt?"
4
+ ---
5
+
6
+ # Threat Hunt
7
+
8
+ ## ABSOLUTE RULES — Read These First
9
+
10
+ **1. NEVER use Bash, cat, python, jq, or any shell command to process data.** Not for MCP results. Not for saved files. Not for "just extracting a summary." NEVER. If results overflow to a file, your query was too broad — re-query with specific field selectors or tighter filters.
11
+
12
+ **2. NEVER use `**` on broad queries.** The `**` wildcard returns entire OCSF events (millions of characters). Use specific field selectors. Use `**` only when scoped to a single host or single event type with a narrow filter.
13
+
14
+ **3. ALWAYS validate before execute.** Every FSQL query goes through `Validate_FSQL_Query` before `Execute_FSQL_Query`. No exceptions.
15
+
16
+ **4. ALWAYS save artifacts.** Write evidence files at every phase exit using the Write tool.
17
+
18
+ **5. LOG EVERY QUERY.** Every `Execute_FSQL_Query` call — whether it succeeds, fails, or returns empty — MUST be appended to `queries.md` with the query text, result count, and a 1-line summary. No undocumented queries. The audit trail is incomplete if even one query is missing.
19
+
20
+ **6. TREAT MCP TOOLS AS COLLABORATORS.** Do not fire-and-forget. `FSQL_Query_Generation` may need 2-3 rounds of iteration. `Search_FSQL_SCHEMA` may need different search terms. Validate before execute. Always.
21
+
22
+ These rules are non-negotiable. If you find yourself reaching for cat, python, or `**` on a broad query, STOP and re-read this section.
23
+
24
+ ## Iron Law
25
+
26
+ **EVERY HUNT STARTS WITH A HYPOTHESIS AND ENDS WITH A VERDICT. NO FISHING EXPEDITIONS.**
27
+
28
+ The hypothesis is the anchor. Without it, you are querying blindly. With it, every query has purpose, every result has context, and every gap is measurable.
29
+
30
+ ## Overview
31
+
32
+ You are the master orchestrator for the Digital Workers proactive threat hunting workflow. This implements the Sqrrl hunting loop: Hypothesis > Investigate > Discover Patterns > Automate Detections. You invoke specialist skills at each phase.
33
+
34
+ Hunts are NOT investigations. Investigations respond to alerts. Hunts proactively seek threats that evaded detection. The workflow, artifact structure, and completion model are different.
35
+
36
+ ## Step 0: Detect Hunt Trigger Mode
37
+
38
+ **Read the analyst's prompt and detect the mode. Announce it and start immediately — do not wait for confirmation.**
39
+
40
+ **DEFAULT BEHAVIOR: If the analyst invokes a hunt without a specific hypothesis, technique, intel, or anomaly — default to Suggest Mode.** Do NOT run the qualification gate for vague prompts. Suggest mode IS the answer to vague prompts.
41
+
42
+ ### Mode Detection Rules
43
+
44
+ **Parse the prompt for these signals:**
45
+
46
+ | Mode | Signal | Phase 0 Behavior |
47
+ |------|--------|-------------------|
48
+ | **Direct Hypothesis** | Analyst states a hypothesis ("I think attackers are using RDP..." / "Hunt for credential dumping on domain controllers") | Validate testable, extract scope, proceed |
49
+ | **Intel-Driven** | Analyst provides article/advisory/IOC list ("Hunt based on this advisory..." / "Here are IOCs from the latest campaign") | Invoke `digital-workers:hypothesis-builder` to extract TTPs |
50
+ | **TTP-Driven** | Analyst names a MITRE technique ("Hunt for T1021.001" / "Look for lateral movement via remote services") | Invoke `digital-workers:hypothesis-builder` for data-source-aware hypothesis |
51
+ | **Data-Driven** | Analyst references anomaly/pattern ("I noticed unusual DNS traffic..." / "There's a spike in auth failures") | Invoke `digital-workers:hypothesis-builder` to frame as testable hypothesis |
52
+ | **Suggest Mode (DEFAULT)** | Analyst asks "what should I hunt?" / "suggest hunts" / "let's go hunting" / ANY prompt without qualifying input | Invoke `digital-workers:hypothesis-builder` in suggest mode — presents Top 10 ranked recommendations |
53
+
54
+ **Suggest mode triggers include:**
55
+ - "What should I hunt?"
56
+ - "Suggest hunts" / "What's worth looking at?"
57
+ - "Let's go hunting" (no specific target)
58
+ - "Start a hunt" (no hypothesis attached)
59
+ - "Hunt for threats" (too vague for direct hypothesis)
60
+ - Any invocation of `threat-hunt` that doesn't contain a specific TTP, technique ID, IOC, threat actor, or described anomaly
61
+
62
+ **Announce format — one line, then start immediately:**
63
+ > "**Direct Hypothesis** — hunting for RDP-based lateral movement across domain controllers, 7d lookback."
64
+
65
+ > "**Intel-Driven** — extracting TTPs from advisory, building data-source-aware hypothesis."
66
+
67
+ > "**Suggest Mode** — analyzing environment data sources, hunt history, and threat landscape to recommend Top 10 hunts."
68
+
69
+ ---
70
+
71
+ ## The 4-Phase Sqrrl Hunting Loop
72
+
73
+ ```
74
+ PHASE 0: HYPOTHESIS INTAKE
75
+ | Two modes: analyst provides hypothesis directly, OR provides raw intel
76
+ | Invoke: digital-workers:hypothesis-builder (always — even for direct hypotheses,
77
+ | to map TTPs to data sources, determine tier, and define confidence targets)
78
+ | Output: Testable hypothesis with scope, TTPs, data sources, AND hunt tier
79
+ | Announce tier: "Broad hunt — 4 TTPs across 5 connectors, environment-wide scope"
80
+ v
81
+ PHASE 1: HUNT PLANNING & DATA AVAILABILITY MAPPING
82
+ | Call FSQL_Connectors -> list active connectors
83
+ | For each relevant connector, fetch docs (static) or Search_FSQL_SCHEMA (dynamic)
84
+ | Read environment profile for known gaps
85
+ | Build DATA AVAILABILITY MAP
86
+ | Catalog available threat intel connectors for IOC enrichment
87
+ | Define query strategy via fsql-expert
88
+ | Pre-validate planned queries via Validate_FSQL_Query
89
+ | Set scope (time range, hosts/users/segments)
90
+ | Apply circuit breaker from tier (Focused: 25 min, Broad: 45 min)
91
+ | Document COVERAGE GAPS -> feeds Phase 3
92
+ v
93
+ PHASE 2: INVESTIGATION (The Hunt)
94
+ | Execute queries via digital-workers:fsql-expert
95
+ | Layer 1a/1b discovery -> targeted telemetry pivots
96
+ | Invoke specialists when triggered (identity-investigator, network-investigator) — MANDATORY
97
+ | Invoke threat-intel-enricher if IOCs surface
98
+ | Evidence quality check at phase exit
99
+ | Log every query to queries.md
100
+ | LIVE PROGRESS REPORTING after every query
101
+ v
102
+ PHASE 3: PATTERN & ATTACK DISCOVERY
103
+ | Invoke: digital-workers:hunt-pattern-analyzer
104
+ | Classify findings
105
+ | IF ACTIVE THREAT -> hand off to alert-investigation
106
+ v
107
+ PHASE 4: DETECTION AUTOMATION
108
+ | Invoke: digital-workers:detection-engineer
109
+ | Generate FSQL detections, Sigma rules, Query recipes
110
+ | Test detections against historical data
111
+ | Generate gap remediation plan
112
+ v
113
+ COMPLETE — Present hunt report + detection package
114
+ ```
115
+
116
+ ---
117
+
118
+ ## Hunt Tiers
119
+
120
+ | Tier | Scope | Circuit Breaker |
121
+ |------|-------|-----------------|
122
+ | **Focused** | Single TTP, narrow scope (specific hosts, users, or segments) | Pause at 25 min |
123
+ | **Broad** | Multiple TTPs, org-wide sweep, environment-wide scope | Pause at 45 min |
124
+
125
+ Tier is determined by `digital-workers:hypothesis-builder` during Phase 0 based on the number of TTPs, data sources, and scope breadth. The analyst can override: "keep it focused" caps at Focused, "go broad" forces Broad.
126
+
127
+ ---
128
+
129
+ ## Completion Model — Confidence-Based
130
+
131
+ Hunts do NOT have a hard query budget. Unlike investigations (which cap at 5/15/25 queries), hunts are driven by confidence. The goal is to reach 90% confidence that the hypothesis has been adequately tested.
132
+
133
+ Track confidence across three dimensions:
134
+
135
+ | Dimension | Weight | What It Measures |
136
+ |-----------|--------|------------------|
137
+ | **Data Coverage** | 40% | Have we queried all data sources in the availability map? |
138
+ | **TTP Coverage** | 40% | Have we tested all behaviors from the hypothesis? |
139
+ | **Enrichment Depth** | 20% | For findings, have we pivoted, enriched IOCs, checked TI? |
140
+
141
+ Overall confidence = weighted average. Hunt concludes at **90%+**.
142
+
143
+ **Circuit breaker output when time limit hit:**
144
+
145
+ ```
146
+ HUNT PAUSED — Circuit breaker at 25 min (Focused tier)
147
+ Queries executed: 22
148
+ Confidence: 78% — below 90% threshold
149
+ Untested: T1021.001 via [connector] (email-based lateral indicators)
150
+
151
+ Options:
152
+ "continue" — extend the hunt to reach 90% confidence
153
+ "wrap up" — conclude with current findings (78% confidence noted in report)
154
+ ```
155
+
156
+ ---
157
+
158
+ ## Phase 0: Hypothesis Intake
159
+
160
+ ### Entry: Analyst provides hunt request
161
+
162
+ **Step 1: Detect trigger mode** (see Step 0 table above).
163
+
164
+ **Step 2: Invoke `digital-workers:hypothesis-builder`**
165
+
166
+ Always invoke the hypothesis-builder — even for direct hypotheses. It performs critical functions:
167
+ - **Detects hunt history tier** (Tier 1: zero history, Tier 2: local `docs/hunts/`, Tier 3: integrated via Linear/Notion/JIRA MCP)
168
+ - Maps the hypothesis to specific MITRE ATT&CK techniques
169
+ - Identifies required data sources per TTP
170
+ - Determines hunt tier (Focused vs. Broad)
171
+ - Defines confidence targets per dimension
172
+ - Validates that the hypothesis is testable (falsifiable, scoped, time-bounded)
173
+
174
+ **For Suggest Mode (default when no hypothesis provided):**
175
+ The hypothesis-builder detects the hunt history tier, discovers available connectors, maps coverage to MITRE ATT&CK, and presents **Top 10 ranked recommendations** scored across 5 dimensions (data availability, TTP risk impact, never tested, TI relevance, environment change). The analyst selects a recommendation, and the hunt proceeds from that selection.
176
+
177
+ **Step 3: Announce and proceed**
178
+
179
+ Announce the tier and hypothesis, then continue immediately to Phase 1:
180
+ > "**Focused hunt** — T1059.001 PowerShell execution on domain controllers, 7d lookback. 1 TTP, 2 connectors."
181
+
182
+ > "**Broad hunt** — 4 TTPs across 5 connectors, environment-wide scope. Lateral movement campaign indicators."
183
+
184
+ **Phase 0 Exit — Save artifacts:**
185
+ 1. Create the hunt directory: `docs/hunts/YYYY-MM-DD-<hypothesis-slug>/`
186
+ 2. Write `hypothesis.md` — testable hypothesis, TTPs, scope, tier, confidence targets
187
+
188
+ **Phase 0 Exit Criteria:** Testable hypothesis defined, TTPs mapped, tier assigned. **Continue immediately to Phase 1.**
189
+
190
+ **HARD GATE — Phase 0 Exit:**
191
+ Before proceeding to Phase 1, verify:
192
+ - [ ] `digital-workers:hypothesis-builder` was invoked (not just hypothesis.md written — the skill performs TTP mapping, data source identification, and tier determination that the orchestrator must not replicate)
193
+ - [ ] `hypothesis.md` has been written to the hunt directory
194
+ - [ ] Hypothesis is testable (falsifiable, scoped, time-bounded)
195
+ - [ ] TTPs are mapped to MITRE ATT&CK technique IDs
196
+ - [ ] Hunt tier is assigned (Focused or Broad)
197
+ - [ ] Circuit breaker time is set
198
+
199
+ If `hypothesis-builder` was not invoked, STOP. Invoke it now.
200
+ If `hypothesis.md` does not exist, STOP. Write it now. Do NOT proceed to Phase 1 without both.
201
+
202
+ Write the artifact NOW, before the next phase begins. The artifact is the gate — if it doesn't exist, the phase isn't complete.
203
+
204
+ Continue immediately to Phase 1 — do not stop or wait for user input.
205
+
206
+ ---
207
+
208
+ ## Phase 1: Hunt Planning & Data Availability Mapping
209
+
210
+ ### Entry: Hypothesis defined with TTPs and scope
211
+
212
+ **Step 1: Discover connectors**
213
+
214
+ Call `FSQL_Connectors` to get the current connector landscape. Classify each connector as relevant or irrelevant to this hunt.
215
+
216
+ **Step 2: Build the Data Availability Map**
217
+
218
+ For each relevant connector:
219
+ - **Static Schema connectors:** Fixed API contracts, documented at `https://docs.query.ai/docs/<connector-slug>`. Fetch docs to confirm supported event types.
220
+ - **Dynamic Schema connectors:** Customer-defined OCSF mappings. Use `Search_FSQL_SCHEMA` to discover actual coverage. These require verification — field paths may differ from standard OCSF.
221
+
222
+ **Step 3: Read environment profile**
223
+
224
+ Read `digital-workers/learned/environment-profile.json` if it exists. Cross-reference known gaps, known false positives, and query performance hints.
225
+
226
+ **Step 4: Catalog threat intel connectors**
227
+
228
+ 1. From the `FSQL_Connectors` output, identify TI connectors
229
+ 2. Classify: Reputation, OSINT/Threat Feed, Vulnerability Intel, Infrastructure Recon, Geolocation
230
+ 3. For each TI connector, use `Search_FSQL_SCHEMA` to find queryable fields
231
+ 4. Build TI section of the data availability map
232
+
233
+ **Step 5: Define query strategy**
234
+
235
+ Invoke `digital-workers:fsql-expert` to plan the query sequence. Pre-validate planned queries via `Validate_FSQL_Query`.
236
+
237
+ **Step 6: Set scope and circuit breaker**
238
+
239
+ Define time range, target hosts/users/segments. Apply the circuit breaker from the tier:
240
+ - Focused: 25 min
241
+ - Broad: 45 min
242
+
243
+ **Data Availability Map format:**
244
+
245
+ ```
246
+ DATA AVAILABILITY MAP
247
+ ━━━━━━━━━━━━━━━━━━━━
248
+ Hypothesis: [statement]
249
+
250
+ STATIC SCHEMA CONNECTORS:
251
+ [Connector Name] (static)
252
+ Supports: [event types from docs]
253
+ Source: Query docs
254
+
255
+ DYNAMIC SCHEMA CONNECTORS:
256
+ [Connector Name] (dynamic)
257
+ Mapped event classes: [confirmed via schema search]
258
+ NOTE: Customer-defined mappings — verify paths
259
+
260
+ TTP COVERAGE:
261
+ [Technique ID] ([Name])
262
+ Need: [event type] with [fields]
263
+ Available: [YES/NO/PARTIAL]
264
+ Status: [AVAILABLE / PARTIAL / COVERAGE GAP]
265
+
266
+ THREAT INTEL CONNECTORS:
267
+ [Discovered at runtime]
268
+
269
+ GAPS IDENTIFIED:
270
+ 1. [description] -> Impact: [which TTPs blocked]
271
+ ```
272
+
273
+ **Phase 1 Exit — Save artifacts:**
274
+ 1. Write `data-map.md` — full data availability map
275
+ 2. Append to `queries.md` — any schema discovery queries run
276
+
277
+ **Phase 1 Exit Criteria:** Data availability map complete, query strategy defined, scope set, circuit breaker configured. **Continue immediately to Phase 2.**
278
+
279
+ **HARD GATE — Phase 1 Exit:**
280
+ Before proceeding to Phase 2, verify:
281
+ - [ ] `data-map.md` has been written to the hunt directory
282
+ - [ ] At least one connector identified per TTP in the hypothesis
283
+ - [ ] Coverage gaps documented for any TTP without a data source
284
+ - [ ] Query strategy defined (which event types, which connectors, what order)
285
+
286
+ If `data-map.md` does not exist, STOP. Write it now. Do NOT proceed to Phase 2 without it.
287
+
288
+ Write the artifact NOW, before the next phase begins. The artifact is the gate — if it doesn't exist, the phase isn't complete.
289
+
290
+ Continue immediately to Phase 2 — do not stop or wait for user input.
291
+
292
+ ---
293
+
294
+ ## Phase 2: Investigation (The Hunt)
295
+
296
+ ### Entry: Data availability map complete, query strategy defined
297
+
298
+ **Step 1: Execute queries**
299
+
300
+ Invoke `digital-workers:fsql-expert` to execute the planned query sequence. Follow the layered approach:
301
+
302
+ - **Layer 1a: Discovery scans** — broad-but-lightweight `*.message, *.time` queries to find where IOCs/patterns appear
303
+ - **Layer 1b: Targeted detail** — specific field selectors on event types identified in Layer 1a
304
+ - **Layer 1c: SUMMARIZE for hypothesis quantification** — when your hypothesis is about prevalence or scope ("is this TTP widespread?", "how many hosts show this behavior?"), use SUMMARIZE after Layer 1a confirms the TTP exists:
305
+ ```
306
+ -- How many hosts show this behavior?
307
+ SUMMARIZE COUNT DISTINCT process_activity.device.hostname
308
+ WITH process_activity.process.cmd_line ICONTAINS '-encodedcommand' AFTER 7d
309
+
310
+ -- How many events per host? (concentrated vs distributed)
311
+ SUMMARIZE COUNT process_activity.message GROUP BY process_activity.device.hostname
312
+ WITH process_activity.process.cmd_line ICONTAINS '-encodedcommand' AFTER 7d
313
+
314
+ -- Detection coverage: are these being caught?
315
+ SUMMARIZE COUNT detection_finding.message GROUP BY detection_finding.message, detection_finding.status_id
316
+ WITH detection_finding.attacks.technique.uid = 'T1059.001' AFTER 7d
317
+ ```
318
+ SUMMARIZE answers "how much?" and "how widespread?". QUERY answers "what exactly happened?". Use both — SUMMARIZE for scope, QUERY for detail on the most interesting hits.
319
+
320
+ > **Constraints:** SUMMARIZE has known execution limits — `status_id` filtering fails on detection_finding (use GROUP BY instead), `FROM` not supported, high-cardinality GROUP BY can overflow. If SUMMARIZE returns empty, fall back to QUERY. See fsql-expert Layer 1c for workarounds and check `summarize_support` in the environment profile.
321
+
322
+ - **Telemetry pivots** — for any findings, pivot from detection data to raw telemetry (process_activity, file_activity, authentication, network_activity)
323
+
324
+ **Artifact timing — write as you go, not at the end:**
325
+ - `queries.md`: Append after EVERY query execution. Do not batch-write at phase exit.
326
+ The audit trail must be current at all times — if the hunt is interrupted, the
327
+ log must reflect all work completed to that point.
328
+
329
+ **Step 2: Invoke specialists (MANDATORY when trigger conditions are met)**
330
+
331
+ Based on what the hunt uncovers:
332
+
333
+ | Finding Type | Specialist |
334
+ |-------------|------------|
335
+ | Identity/auth anomalies | `digital-workers:identity-investigator` |
336
+ | Network/lateral indicators | `digital-workers:network-investigator` |
337
+ | IOCs surfaced | `digital-workers:threat-intel-enricher` |
338
+
339
+ **MANDATORY: You MUST invoke specialist skills when their trigger conditions are met.**
340
+ Do NOT perform specialist work yourself. The specialist skills exist because they apply domain-specific logic, query patterns, and quality checks that the orchestrator does not replicate.
341
+
342
+ - If authentication/identity findings surface → invoke `digital-workers:identity-investigator`
343
+ - If network/lateral indicators surface → invoke `digital-workers:network-investigator`
344
+ - If IOCs surface → invoke `digital-workers:threat-intel-enricher`
345
+
346
+ Similarly:
347
+ - Phase 0: You MUST invoke `digital-workers:hypothesis-builder` (already stated, reinforced here)
348
+ - Phase 3: You MUST invoke `digital-workers:hunt-pattern-analyzer`
349
+ - Phase 4: You MUST invoke `digital-workers:detection-engineer`
350
+
351
+ **Step 3: Track confidence**
352
+
353
+ After every query, update the confidence dimensions:
354
+ - Data Coverage: [queried sources] / [total sources in map]
355
+ - TTP Coverage: [tested techniques] / [total techniques in hypothesis]
356
+ - Enrichment Depth: [enriched findings] / [total findings]
357
+
358
+ **Step 4: Live progress reporting (MANDATORY)**
359
+
360
+ After EVERY query, report status to the analyst:
361
+
362
+ ```
363
+ ━━━ HUNT STATUS ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
364
+ Phase 2: Investigation | Query 17 | 18 min elapsed
365
+ Hypothesis: [hypothesis statement]
366
+ Currently testing: T1021.001 — authentication patterns across [connector]
367
+ Coverage: Data 3/4 (75%) | TTPs 2/3 (67%) | Confidence: ~80%
368
+ Findings so far: 1 suspicious pattern, 0 active threats
369
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
370
+ ```
371
+
372
+ **Finding alerts — announce immediately when discovered:**
373
+
374
+ ```
375
+ FINDING: Suspicious authentication pattern detected
376
+ 3 service accounts with RDP logins from 5+ unique source IPs in 24h
377
+ Querying lateral movement indicators next...
378
+ ```
379
+
380
+ **Active threat escalation — stop the hunt immediately:**
381
+
382
+ ```
383
+ ACTIVE THREAT DETECTED — Pausing hunt
384
+ Evidence of ongoing credential stuffing against service accounts
385
+ Handing off to alert-investigation for formal triage...
386
+ ```
387
+
388
+ **Step 5: Evidence quality check at phase exit**
389
+
390
+ Before transitioning to Phase 3, verify:
391
+ - All planned data sources were queried (or gaps documented)
392
+ - All TTPs from the hypothesis were tested
393
+ - Findings have been enriched (pivots, TI, specialist analysis)
394
+ - Every query is logged in `queries.md`
395
+
396
+ **Assumptions & Caveats — MANDATORY for dynamic connectors:**
397
+
398
+ Every empty result against a dynamic connector must document:
399
+
400
+ ```
401
+ QUERY: [the FSQL query]
402
+ CONNECTOR: [name] (dynamic schema)
403
+ RESULT: Empty — 0 records
404
+ POSSIBLE EXPLANATIONS:
405
+ (a) Data genuinely does not exist
406
+ (b) Data exists but mapped to different OCSF path
407
+ (c) Time range or filter excluded records
408
+ RECOMMENDATION: Verify field mapping in Query UI
409
+ ```
410
+
411
+ **Phase 2 Exit — Save artifacts:**
412
+ 1. Append to `queries.md` — all hunt queries with result counts and findings
413
+ 2. Write initial `findings.md` if findings exist
414
+ 3. Write `iocs.md` if IOCs were discovered
415
+
416
+ **Phase transition announcement:**
417
+
418
+ ```
419
+ ━━━ PHASE TRANSITION ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
420
+ Moving to Phase 3: Pattern & Attack Discovery
421
+ Phase 2 complete: 22 queries | 3 findings | 1 coverage gap | 24 min
422
+ Confidence at Phase 2 exit: 92%
423
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
424
+ ```
425
+
426
+ **MANDATORY: Before transitioning to Phase 3, invoke `digital-workers:hunt-quality-checker`.**
427
+ This is the hunt equivalent of `evidence-quality-checker` at Gate 2/3. Do NOT skip it.
428
+ If any check FAILs, fix the issue before proceeding.
429
+
430
+ **Phase 2 Exit Criteria:** Confidence at 90%+ (or circuit breaker hit with analyst decision), all queries logged, findings documented. **Continue immediately to Phase 3.**
431
+
432
+ ---
433
+
434
+ ## Phase 3: Pattern & Attack Discovery
435
+
436
+ ### Entry: Investigation phase complete with findings
437
+
438
+ **Step 1: Invoke `digital-workers:hunt-pattern-analyzer`**
439
+
440
+ Pass all findings, queries, and the hypothesis for pattern analysis.
441
+
442
+ **Step 2: Classify findings**
443
+
444
+ Each finding gets classified:
445
+
446
+ | Classification | Description | Next Action |
447
+ |---------------|-------------|-------------|
448
+ | **Active Threat** | Confirmed malicious activity in progress | STOP hunt. Hand off to `alert-investigation` with evidence package. |
449
+ | **Suspicious Pattern** | Anomalous behavior that warrants monitoring but is not confirmed malicious | Document. Feed to Phase 4 for detection creation. |
450
+ | **Policy Gap** | Behavior that should be prevented by policy but isn't | Document. Recommend policy update. |
451
+ | **Coverage Gap** | Data source or detection missing for a TTP | Document. Feed to Phase 4 for gap remediation. |
452
+ | **Clean** | Hypothesis tested, no evidence found | Document with confidence level and caveats. |
453
+
454
+ **HARD GATE — Active Threat Detection:**
455
+ If ANY finding is classified as Active Threat at ANY point during the hunt:
456
+ 1. STOP the hunt immediately. Do NOT execute any more hunt queries.
457
+ 2. Write all accumulated artifacts (hypothesis.md, data-map.md, queries.md, findings.md).
458
+ 3. Hand off to `alert-investigation` with the evidence package.
459
+ 4. The hunt is PAUSED. It may resume only after the active threat investigation completes.
460
+
461
+ This is non-negotiable. An active threat takes priority over hunt completion.
462
+
463
+ **Phase 3 Exit — Save artifacts:**
464
+ 1. Write `findings.md` — all classified findings with evidence
465
+ 2. Update `queries.md` if additional pattern analysis queries were run
466
+
467
+ **Phase 3 Exit Criteria:** All findings classified, active threats escalated, patterns identified. **Continue immediately to Phase 4.**
468
+
469
+ ---
470
+
471
+ ## Phase 4: Detection Automation
472
+
473
+ ### Entry: Findings classified, patterns identified
474
+
475
+ **You MUST complete Phase 4 before writing report.md.** Phase 4 is not optional.
476
+ Every hunt produces detections — even clean hunts produce zero-baseline detections
477
+ and gap remediation plans. If findings are clean, generate detections that would
478
+ catch the hypothesized behavior if it occurs in the future.
479
+
480
+ You MUST invoke `digital-workers:detection-engineer` to generate detections.
481
+ Do NOT write detections inline — the specialist skill ensures consistent format,
482
+ Sigma rule quality, and recipe generation.
483
+
484
+ **Step 1: Invoke `digital-workers:detection-engineer`**
485
+
486
+ For each finding classified as Suspicious Pattern, Policy Gap, or Coverage Gap:
487
+ - Generate FSQL detection queries
488
+ - Generate Sigma rules
489
+ - Generate Query recipes where applicable
490
+
491
+ **Step 2: Test detections**
492
+
493
+ Test generated detections against historical data to validate they would have caught the pattern. Document true positive rate, false positive rate, and any tuning needed.
494
+
495
+ **Step 3: Generate gap remediation plan**
496
+
497
+ For every coverage gap identified in Phases 1-3:
498
+ - What data source is missing or incomplete
499
+ - What the gap means for detection capability
500
+ - Recommended remediation (enable logging, add connector, adjust mapping)
501
+ - Priority (critical gap vs. nice-to-have)
502
+
503
+ **Phase 4 Exit — Save artifacts:**
504
+ 1. Write `detections.md` — all generated detections with test results
505
+ 2. Write `gaps.md` — gap remediation plan
506
+ 3. Write `report.md` — full hunt report
507
+
508
+ **Phase 4 Exit Criteria:** Detections generated and tested, gap remediation plan complete, hunt report written.
509
+
510
+ ---
511
+
512
+ ## Hunt Artifact Structure
513
+
514
+ ```
515
+ docs/hunts/YYYY-MM-DD-<hypothesis-slug>/
516
+ hypothesis.md <- Phase 0 output
517
+ data-map.md <- Phase 1 output
518
+ queries.md <- Every FSQL query + results (ALL phases)
519
+ findings.md <- Phase 3 output
520
+ detections.md <- Phase 4 output
521
+ gaps.md <- Gap remediation plan
522
+ report.md <- Full hunt report
523
+ iocs.md <- IOCs discovered (if any)
524
+ ```
525
+
526
+ Create the hunt directory at Phase 0 exit. **Use the Write tool** (never Bash/echo) to save artifacts. Write markdown, not JSON.
527
+
528
+ **The `queries.md` log is mandatory.** After every FSQL query execution, append the query text, result count, and a 1-2 line summary. This is the audit trail.
529
+
530
+ ---
531
+
532
+ ## Live Progress Reporting — MANDATORY
533
+
534
+ The analyst must never stare at a blank screen during a hunt. Report status after every query.
535
+
536
+ ### After Every Query
537
+
538
+ ```
539
+ ━━━ HUNT STATUS ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
540
+ Phase 2: Investigation | Query 17 | 18 min elapsed
541
+ Hypothesis: [hypothesis statement]
542
+ Currently testing: T1021.001 — authentication patterns across [connector]
543
+ Coverage: Data 3/4 (75%) | TTPs 2/3 (67%) | Confidence: ~80%
544
+ Findings so far: 1 suspicious pattern, 0 active threats
545
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
546
+ ```
547
+
548
+ ### Phase Transitions
549
+
550
+ ```
551
+ ━━━ PHASE TRANSITION ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
552
+ Moving to Phase 3: Pattern & Attack Discovery
553
+ Phase 2 complete: 22 queries | 3 findings | 1 coverage gap | 24 min
554
+ Confidence at Phase 2 exit: 92%
555
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
556
+ ```
557
+
558
+ ### Finding Alerts
559
+
560
+ ```
561
+ FINDING: Suspicious authentication pattern detected
562
+ 3 service accounts with RDP logins from 5+ unique source IPs in 24h
563
+ Querying lateral movement indicators next...
564
+ ```
565
+
566
+ ### Active Threat Escalation
567
+
568
+ ```
569
+ ACTIVE THREAT DETECTED — Pausing hunt
570
+ Evidence of ongoing credential stuffing against service accounts
571
+ Handing off to alert-investigation for formal triage...
572
+ ```
573
+
574
+ ### Circuit Breaker
575
+
576
+ ```
577
+ HUNT PAUSED — Circuit breaker at 25 min (Focused tier)
578
+ Queries executed: 22
579
+ Confidence: 78% — below 90% threshold
580
+ Untested: T1021.001 via [connector] (email-based lateral indicators)
581
+
582
+ Options:
583
+ "continue" — extend the hunt to reach 90% confidence
584
+ "wrap up" — conclude with current findings (78% confidence noted in report)
585
+ ```
586
+
587
+ ---
588
+
589
+ ## Connector Documentation Awareness
590
+
591
+ Two types of connectors exist in the Query mesh:
592
+
593
+ - **Static Schema:** Fixed API contracts, documented at `https://docs.query.ai/docs/<connector-slug>`. Schema is predictable.
594
+ - **Dynamic Schema:** Customer-defined OCSF mappings. Use `Search_FSQL_SCHEMA` to discover actual coverage. Field paths may differ from standard OCSF.
595
+
596
+ Always verify dynamic schema connectors before writing queries. Do not assume field paths exist — confirm via `Search_FSQL_SCHEMA`.
597
+
598
+ ---
599
+
600
+ ## Integration with alert-investigation
601
+
602
+ If Phase 3 discovers an active threat:
603
+ 1. STOP the hunt immediately
604
+ 2. Package the evidence: hypothesis, queries, findings, IOCs
605
+ 3. Hand off to `alert-investigation` — the hunt evidence becomes the intake
606
+ 4. The hunt pauses until the active threat is resolved
607
+ 5. After resolution, the hunt may resume to complete remaining TTPs
608
+
609
+ ---
610
+
611
+ ## Red Flags
612
+
613
+ | Red Flag | Correct Action |
614
+ |----------|---------------|
615
+ | "Let's just query everything and see what we find" | STOP. That's a fishing expedition, not a hunt. Start with a hypothesis. |
616
+ | Analyst says "let's hunt" with no hypothesis and you run the qualification gate | STOP. Default to suggest mode. Present data-driven Top 10 recommendations. The qualification gate is for when suggest mode output needs narrowing, not for vague prompts. |
617
+ | Starting Phase 2 without a data availability map | STOP. Go back to Phase 1. Blind queries waste time and produce false confidence. |
618
+ | Skipping `Validate_FSQL_Query` before `Execute_FSQL_Query` | STOP. Validate every query. No exceptions. |
619
+ | Running 45 minutes on a Focused hunt without pausing | STOP. Circuit breaker exists for a reason. Pause, report confidence, let the analyst decide. |
620
+ | Not reporting progress after queries | STOP. The analyst must never stare at a blank screen. Report status after every query. |
621
+ | Classifying "no data" as "clean" | STOP. No data may mean a coverage gap, not a clean environment. Check the data availability map. |
622
+ | Active threat found, continuing the hunt | STOP. Active threats get immediate escalation. The hunt pauses. |
623
+ | Fire-and-forget on MCP tools | STOP. `FSQL_Query_Generation` output needs review. Iterate. Validate. Cross-reference with schema. |
624
+ | Not saving artifacts at phase exits | STOP. Write `hypothesis.md`, `data-map.md`, `queries.md`, `findings.md`, `detections.md`, `gaps.md`. The audit trail is the value. |
625
+ | Hardcoding connector names | STOP. All connectors discovered at runtime via `FSQL_Connectors`. |
626
+ | Empty results on dynamic connector without assumptions caveat | STOP. Document possible explanations. Empty does not equal confirmed absent for dynamic schema. |
627
+ | Presenting hunt report without gap remediation plan | STOP. Gaps are a first-class deliverable. Every hunt produces detections AND gap remediation. |
628
+ | Using Bash, cat, python, or jq to process data | STOP. **Never use shell commands to process hunt data.** Analyze MCP results directly as an LLM. |