Files

88 lines
3.5 KiB
Markdown
Raw Permalink Normal View History

# Master Regex Patterns & Passing Reference
> **Box is the main surface.** All operator work goes through Box (`box.muse-dev.online`). The web UI, `box` CLI, and agents share the same API endpoints and parsing patterns.
This document serves as the canonical reference for regular expressions used across NetVM's orchestrators, harvesters, loop state managers, and agent message parsers.
---
## 1. Quick Pattern Directory
| Pattern Key | Purpose | Match Example |
|---|---|---|
| `work_order` | Parses `[WO:<id>] [from <sender>] ...` | `[WO:7fce46e0] [from super] Audit — Check stats` |
| `ack` | Parses `[ACK:<id>] [from <sender>]` | `[ACK:7fce46e0] [from 646]` |
| `verb` | Matches `[ACK\|CLAIM\|RESULT\|DECLINE\|NO-ACTION <id>]` | `[CLAIM 7fce46e0]` |
| `result` | Parses `[RESULT <id>] <status> <summary>` | `[RESULT 7fce46e0] OK 14 endpoints healthy` |
| `tool_call` | Parses inline `[TOOL <op> <args>]` | `[TOOL followup.create {"in_m": 5}]` |
| `job_tag` | Matches `[JOB <id>]` | `[JOB ml-646-20261005]` |
| `nudge` | Parses followup SLA nudges | `[NUDGE 7fce46e0] [nudge 1/3] Deadline 19:45: ...` |
| `fleet_alert` | Parses alert broadcasts | `[fleet-alert] CRITICAL: VM unreachable x2` |
| `uuid` | RFC 4122 UUID v4 detector | `dc6d72ca-4b02-4217-bf41-7dbca19c5c24` |
| `short_hex` | 6-12 character hex IDs | `7fce46e0` |
| `subagent_update`| Subagent status notices | `[SUBAGENT-UPDATE] Subagent 'audit' (4a2b8e) ...` |
| `swarm_slot` | Swarm worker slot targets | `[JOB swarm-99a/1]` |
---
## 2. Core Patterns & Named Capture Groups
### 2.1 Work Order Pattern (`work_order`)
```python
r"^\[WO:(?P<wo_id>[a-f0-9-]+)\]\s+\[from\s+(?P<sender>[a-zA-Z0-9_-]+)\]\s+(?P<title>[^—\n]+?)\s*—\s*(?P<body>.+)$"
```
* **Flags**: `re.MULTILINE`, `re.DOTALL`
* **Groups**:
- `wo_id`: The unique tracking ID.
- `sender`: Originating identity (`super`, `646`, `pip`, etc.).
- `title`: Short task name preceding the em-dash (`—`).
- `body`: Instruction payload following the em-dash.
### 2.2 Standard Verbs (`verb`)
```python
r"\[(?P<verb>ACK|CLAIM|RESULT|DECLINE|NO-ACTION)\s+(?P<job_id>[A-Za-z0-9_/-]+)\]"
```
* **Groups**:
- `verb`: One of the 5 canonical lifecycle verbs.
- `job_id`: Target job, work order, or swarm slot.
### 2.3 Task Result (`result`)
```python
r"\[RESULT\s+(?P<job_id>[A-Za-z0-9_/-]+)\]\s*(?P<status>OK|FAIL|DECLINE|SUCCESS|ERROR)?\s*(?P<summary>.*?)(?=\[RESULT\s|\Z)"
```
* **Flags**: `re.DOTALL`
* **Groups**:
- `job_id`: Target task ID.
- `status`: Optional explicit status keyword.
- `summary`: Detailed response text.
### 2.4 In-Band Tool Directives (`tool_call`)
```python
r"\[(?P<engine>TOOL|EXEC)\s+(?P<op>[a-zA-Z0-9_.-]+)\s+(?P<args>\{.*?\})\]"
```
* **Groups**:
- `engine`: `TOOL` or `EXEC`.
- `op`: Method name (e.g. `followup.create`, `health.check`).
- `args`: Embedded JSON argument payload.
---
## 3. CLI Pattern Passing & Validation
The unified CLI allows testing strings directly against these patterns:
```bash
# Test a string against a specific pattern
super docs regex result --test "[RESULT 7fce46e0] OK Task complete"
box docs regex work_order --test "[WO:8a12bc44] [from super] Audit — verify 200"
# Parse an agent utterance through ALL registered patterns
super docs parse "[RESULT 7fce46e0] OK Verified 14 endpoints"
box docs parse "[TOOL followup.create {\"in_m\": 5, \"prompt\": \"check\"}]"
# View raw JSON pattern definition
super docs get regex_patterns work_order --json
```
When run with `--json`, the parser outputs structured dictionary mappings suitable for programmatic ingestion by subagents.