@davidorex/pi-behavior-monitors 0.1.4 → 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/CHANGELOG.md +30 -66
- package/README.md +9 -1
- package/dist/index.d.ts +149 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1456 -0
- package/dist/index.js.map +1 -0
- package/examples/commit-hygiene/classify.md +29 -0
- package/examples/commit-hygiene.instructions.json +1 -0
- package/examples/commit-hygiene.monitor.json +33 -0
- package/examples/commit-hygiene.patterns.json +44 -0
- package/examples/fragility/classify.md +33 -0
- package/examples/fragility.monitor.json +61 -60
- package/examples/fragility.patterns.json +84 -84
- package/examples/hedge/classify.md +38 -0
- package/examples/hedge.monitor.json +33 -32
- package/examples/hedge.patterns.json +56 -8
- package/examples/work-quality/classify.md +30 -0
- package/examples/work-quality.monitor.json +61 -60
- package/examples/work-quality.patterns.json +77 -11
- package/package.json +53 -48
- package/schemas/monitor-pattern.schema.json +36 -36
- package/schemas/monitor.schema.json +158 -154
- package/skills/pi-behavior-monitors/SKILL.md +359 -47
- package/index.ts +0 -1284
|
@@ -1,3 +1,146 @@
|
|
|
1
|
+
# @davidorex/pi-behavior-monitors
|
|
2
|
+
|
|
3
|
+
> Behavior monitors for pi that watch agent activity and steer corrections
|
|
4
|
+
|
|
5
|
+
## Tools
|
|
6
|
+
|
|
7
|
+
### monitors-status
|
|
8
|
+
|
|
9
|
+
List all behavior monitors with their current state.
|
|
10
|
+
|
|
11
|
+
*List all behavior monitors with their current state*
|
|
12
|
+
|
|
13
|
+
### monitors-inspect
|
|
14
|
+
|
|
15
|
+
Inspect a monitor — config, state, pattern count, rule count.
|
|
16
|
+
|
|
17
|
+
*Inspect a monitor — config, state, pattern count, rule count*
|
|
18
|
+
|
|
19
|
+
| Parameter | Type | Required | Description |
|
|
20
|
+
|-----------|------|----------|-------------|
|
|
21
|
+
| `monitor` | string | yes | Monitor name |
|
|
22
|
+
|
|
23
|
+
### monitors-control
|
|
24
|
+
|
|
25
|
+
Control monitors — enable, disable, dismiss, or reset.
|
|
26
|
+
|
|
27
|
+
*Control monitors — enable, disable, dismiss, or reset*
|
|
28
|
+
|
|
29
|
+
| Parameter | Type | Required | Description |
|
|
30
|
+
|-----------|------|----------|-------------|
|
|
31
|
+
| `action` | unknown | yes | |
|
|
32
|
+
| `monitor` | string | no | Monitor name (required for dismiss/reset) |
|
|
33
|
+
|
|
34
|
+
### monitors-rules
|
|
35
|
+
|
|
36
|
+
Manage monitor rules — list, add, remove, or replace calibration rules.
|
|
37
|
+
|
|
38
|
+
*Manage monitor rules — list, add, remove, or replace calibration rules*
|
|
39
|
+
|
|
40
|
+
| Parameter | Type | Required | Description |
|
|
41
|
+
|-----------|------|----------|-------------|
|
|
42
|
+
| `monitor` | string | yes | Monitor name |
|
|
43
|
+
| `action` | unknown | yes | |
|
|
44
|
+
| `text` | string | no | Rule text (for add/replace) |
|
|
45
|
+
| `index` | number | no | Rule index, 1-based (for remove/replace) |
|
|
46
|
+
|
|
47
|
+
### monitors-patterns
|
|
48
|
+
|
|
49
|
+
List patterns for a behavior monitor.
|
|
50
|
+
|
|
51
|
+
*List patterns for a behavior monitor*
|
|
52
|
+
|
|
53
|
+
| Parameter | Type | Required | Description |
|
|
54
|
+
|-----------|------|----------|-------------|
|
|
55
|
+
| `monitor` | string | yes | Monitor name |
|
|
56
|
+
|
|
57
|
+
## Commands
|
|
58
|
+
|
|
59
|
+
### /monitors
|
|
60
|
+
|
|
61
|
+
Manage behavior monitors
|
|
62
|
+
|
|
63
|
+
Subcommands: `on`, `off`, `fragility`, `response-style`
|
|
64
|
+
|
|
65
|
+
## Events
|
|
66
|
+
|
|
67
|
+
- `session_start`
|
|
68
|
+
- `session_switch`
|
|
69
|
+
- `agent_end`
|
|
70
|
+
- `turn_start`
|
|
71
|
+
- `message_end`
|
|
72
|
+
|
|
73
|
+
## Bundled Resources
|
|
74
|
+
|
|
75
|
+
### schemas/ (2 files)
|
|
76
|
+
|
|
77
|
+
- `schemas/monitor-pattern.schema.json`
|
|
78
|
+
- `schemas/monitor.schema.json`
|
|
79
|
+
|
|
80
|
+
### examples/ (16 files)
|
|
81
|
+
|
|
82
|
+
- `examples/commit-hygiene/classify.md`
|
|
83
|
+
- `examples/commit-hygiene.instructions.json`
|
|
84
|
+
- `examples/commit-hygiene.monitor.json`
|
|
85
|
+
- `examples/commit-hygiene.patterns.json`
|
|
86
|
+
- `examples/fragility/classify.md`
|
|
87
|
+
- `examples/fragility.instructions.json`
|
|
88
|
+
- `examples/fragility.monitor.json`
|
|
89
|
+
- `examples/fragility.patterns.json`
|
|
90
|
+
- `examples/hedge/classify.md`
|
|
91
|
+
- `examples/hedge.instructions.json`
|
|
92
|
+
- `examples/hedge.monitor.json`
|
|
93
|
+
- `examples/hedge.patterns.json`
|
|
94
|
+
- `examples/work-quality/classify.md`
|
|
95
|
+
- `examples/work-quality.instructions.json`
|
|
96
|
+
- `examples/work-quality.monitor.json`
|
|
97
|
+
- `examples/work-quality.patterns.json`
|
|
98
|
+
|
|
99
|
+
## Monitor Vocabulary
|
|
100
|
+
|
|
101
|
+
### Context Collectors
|
|
102
|
+
|
|
103
|
+
| Collector | Placeholder | Description | Limits |
|
|
104
|
+
|-----------|-------------|-------------|--------|
|
|
105
|
+
| `user_text` | `{user_text}` / `{{ user_text }}` | Most recent user message text | — |
|
|
106
|
+
| `assistant_text` | `{assistant_text}` / `{{ assistant_text }}` | Most recent assistant message text | — |
|
|
107
|
+
| `tool_results` | `{tool_results}` / `{{ tool_results }}` | Tool results with tool name and error status | Last 5, truncated 2000 chars |
|
|
108
|
+
| `tool_calls` | `{tool_calls}` / `{{ tool_calls }}` | Tool calls and results interleaved | Last 20, truncated 2000 chars |
|
|
109
|
+
| `custom_messages` | `{custom_messages}` / `{{ custom_messages }}` | Custom extension messages since last user message | — |
|
|
110
|
+
| `project_vision` | `{project_vision}` / `{{ project_vision }}` | .project/project.json vision, core_value, name | — |
|
|
111
|
+
| `project_conventions` | `{project_conventions}` / `{{ project_conventions }}` | .project/conformance-reference.json principle names | — |
|
|
112
|
+
| `git_status` | `{git_status}` / `{{ git_status }}` | Output of git status --porcelain | 5s timeout |
|
|
113
|
+
|
|
114
|
+
Any string is accepted in `classify.context`. Unknown collector names produce empty string (graceful degradation).
|
|
115
|
+
|
|
116
|
+
Built-in placeholders (always available, not listed in `classify.context`):
|
|
117
|
+
- `{patterns}` / `{{ patterns }}` — formatted from patterns JSON as numbered list: `1. [severity] description`
|
|
118
|
+
- `{instructions}` / `{{ instructions }}` — formatted from instructions JSON as bulleted list with "Operating instructions from the user (follow these strictly):" preamble — empty string if no instructions
|
|
119
|
+
- `{iteration}` / `{{ iteration }}` — current consecutive steer count (0-indexed)
|
|
120
|
+
|
|
121
|
+
### When Conditions
|
|
122
|
+
|
|
123
|
+
- `always` — Fire every time the event occurs
|
|
124
|
+
- `has_tool_results` — Fire only if tool results present since last user message
|
|
125
|
+
- `has_file_writes` — Fire only if write or edit tool called since last user message
|
|
126
|
+
- `has_bash` — Fire only if bash tool called since last user message
|
|
127
|
+
- `every(N)` — Fire every Nth activation (counter resets when user text changes)
|
|
128
|
+
- `tool(name)` — Fire only if specific named tool called since last user message
|
|
129
|
+
|
|
130
|
+
### Events
|
|
131
|
+
|
|
132
|
+
`message_end`, `turn_end`, `agent_end`, `command`
|
|
133
|
+
|
|
134
|
+
### Verdict Types
|
|
135
|
+
|
|
136
|
+
`clean`, `flag`, `new`
|
|
137
|
+
|
|
138
|
+
### Scope Targets
|
|
139
|
+
|
|
140
|
+
`main`, `subagent`, `all`, `workflow`
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
1
144
|
---
|
|
2
145
|
name: pi-behavior-monitors
|
|
3
146
|
description: >
|
|
@@ -42,17 +185,24 @@ bundled monitor, delete its three files (`.monitor.json`, `.patterns.json`,
|
|
|
42
185
|
</seeding>
|
|
43
186
|
|
|
44
187
|
<file_structure>
|
|
45
|
-
Each monitor is a
|
|
188
|
+
Each monitor is a set of files sharing a name prefix:
|
|
46
189
|
|
|
47
190
|
```
|
|
48
191
|
.pi/monitors/
|
|
49
192
|
├── fragility.monitor.json # Monitor definition (classify + patterns + actions + scope)
|
|
50
193
|
├── fragility.patterns.json # Known patterns (JSON array, grows automatically)
|
|
51
194
|
├── fragility.instructions.json # User corrections (JSON array, optional)
|
|
195
|
+
├── fragility/
|
|
196
|
+
│ └── classify.md # Nunjucks template for classification prompt (optional)
|
|
52
197
|
```
|
|
53
198
|
|
|
54
199
|
The instructions file is optional. If omitted, the extension defaults the path to
|
|
55
200
|
`${name}.instructions.json` and treats a missing file as an empty array.
|
|
201
|
+
|
|
202
|
+
The classify template is optional. When `classify.promptTemplate` is set in the monitor
|
|
203
|
+
definition, the template is resolved through a three-tier search: `.pi/monitors/` (project),
|
|
204
|
+
`~/.pi/agent/monitors/` (user), then the package `examples/` directory. A user overrides a
|
|
205
|
+
bundled template by placing a file at the same relative path in `.pi/monitors/`.
|
|
56
206
|
</file_structure>
|
|
57
207
|
|
|
58
208
|
<monitor_definition>
|
|
@@ -72,7 +222,8 @@ A `.monitor.json` file conforms to `schemas/monitor.schema.json`:
|
|
|
72
222
|
"model": "claude-sonnet-4-20250514",
|
|
73
223
|
"context": ["tool_results", "assistant_text"],
|
|
74
224
|
"excludes": ["other-monitor"],
|
|
75
|
-
"
|
|
225
|
+
"promptTemplate": "my-monitor/classify.md",
|
|
226
|
+
"prompt": "Inline fallback if template not found. {tool_results} {assistant_text} {patterns} {instructions}\n\nReply CLEAN, FLAG:<desc>, or NEW:<pattern>|<desc>."
|
|
76
227
|
},
|
|
77
228
|
"patterns": {
|
|
78
229
|
"path": "my-monitor.patterns.json",
|
|
@@ -140,9 +291,10 @@ Non-main scopes can still write findings to JSON files.
|
|
|
140
291
|
| Field | Default | Description |
|
|
141
292
|
|-------|---------|-------------|
|
|
142
293
|
| `classify.model` | `claude-sonnet-4-20250514` | Model for classification. Plain model ID uses `anthropic` provider. Use `provider/model` for other providers. |
|
|
143
|
-
| `classify.context` | `["tool_results", "assistant_text"]` |
|
|
294
|
+
| `classify.context` | `["tool_results", "assistant_text"]` | Context collector names. Any string accepted — unknown collectors produce empty string. |
|
|
144
295
|
| `classify.excludes` | `[]` | Monitor names — skip activation if any of these already steered this turn. |
|
|
145
|
-
| `classify.
|
|
296
|
+
| `classify.promptTemplate` | — | Path to `.md` Nunjucks template file. Searched in `.pi/monitors/`, `~/.pi/agent/monitors/`, then package `examples/`. Takes precedence over `prompt`. |
|
|
297
|
+
| `classify.prompt` | — | Inline classification prompt with `{placeholder}` substitution. Used when `promptTemplate` is absent. One of `promptTemplate` or `prompt` is required. |
|
|
146
298
|
|
|
147
299
|
**Actions block** — per verdict (`on_flag`, `on_new`, `on_clean`):
|
|
148
300
|
|
|
@@ -160,29 +312,7 @@ Non-main scopes can still write findings to JSON files.
|
|
|
160
312
|
`null` means no action on clean (the default behavior).
|
|
161
313
|
</fields>
|
|
162
314
|
|
|
163
|
-
|
|
164
|
-
- `always` — fire every time the event occurs
|
|
165
|
-
- `has_tool_results` — fire only if tool results are present since last user message
|
|
166
|
-
- `has_file_writes` — fire only if `write` or `edit` tool was called since last user message
|
|
167
|
-
- `has_bash` — fire only if `bash` tool was called since last user message
|
|
168
|
-
- `tool(name)` — fire only if a specific named tool was called since last user message
|
|
169
|
-
- `every(N)` — fire every Nth activation within the same user prompt (counter resets when user text changes)
|
|
170
|
-
</when_conditions>
|
|
171
|
-
|
|
172
|
-
<context_collectors>
|
|
173
|
-
| Collector | Placeholder | What it collects | Limits |
|
|
174
|
-
|-----------|-------------|------------------|--------|
|
|
175
|
-
| `user_text` | `{user_text}` | Most recent user message text (walks back past assistant to find preceding user message) | — |
|
|
176
|
-
| `assistant_text` | `{assistant_text}` | Most recent assistant message text | — |
|
|
177
|
-
| `tool_results` | `{tool_results}` | Tool results with tool name and error status | Last 5, each truncated to 2000 chars |
|
|
178
|
-
| `tool_calls` | `{tool_calls}` | Tool calls and their results interleaved | Last 20, each truncated to 2000 chars |
|
|
179
|
-
| `custom_messages` | `{custom_messages}` | Custom extension messages since last user message | — |
|
|
180
|
-
|
|
181
|
-
Built-in placeholders (always available, not listed in `classify.context`):
|
|
182
|
-
- `{patterns}` — formatted from patterns JSON as numbered list: `1. [severity] description`
|
|
183
|
-
- `{instructions}` — formatted from instructions JSON as bulleted list with preamble "Operating instructions from the user (follow these strictly):" — empty string if no instructions
|
|
184
|
-
- `{iteration}` — current consecutive steer count (0-indexed)
|
|
185
|
-
</context_collectors>
|
|
315
|
+
<!-- when_conditions and context_collectors tables are generated from code registries — see Monitor Vocabulary section in SKILL.md -->
|
|
186
316
|
|
|
187
317
|
<patterns_file>
|
|
188
318
|
JSON array conforming to `schemas/monitor-pattern.schema.json`:
|
|
@@ -243,6 +373,52 @@ Rules are injected into the classification prompt under a preamble
|
|
|
243
373
|
non-empty. An empty array or missing file produces no rules block in the prompt.
|
|
244
374
|
</instructions_file>
|
|
245
375
|
|
|
376
|
+
<prompt_templates>
|
|
377
|
+
Monitors support two prompt rendering modes:
|
|
378
|
+
|
|
379
|
+
**Inline prompts** (`classify.prompt`) — simple `{placeholder}` string replacement. Good for
|
|
380
|
+
single-paragraph classifiers. All context collectors and built-in placeholders are available
|
|
381
|
+
as `{name}`.
|
|
382
|
+
|
|
383
|
+
**Nunjucks templates** (`classify.promptTemplate`) — `.md` files with full Nunjucks syntax:
|
|
384
|
+
conditionals (`{% if %}`), loops (`{% for %}`), template inheritance, filters. Used when
|
|
385
|
+
the classify prompt needs conditional sections (e.g., iteration-aware acknowledgment).
|
|
386
|
+
|
|
387
|
+
Template variables use `{{ name }}` syntax. All context collectors and built-in placeholders
|
|
388
|
+
are available: `{{ patterns }}`, `{{ instructions }}`, `{{ iteration }}`, plus any collectors
|
|
389
|
+
listed in `classify.context`.
|
|
390
|
+
|
|
391
|
+
When both `promptTemplate` and `prompt` are set, the template is tried first. If the template
|
|
392
|
+
file is not found or fails to render, the inline prompt is used as fallback.
|
|
393
|
+
|
|
394
|
+
**Iteration-aware acknowledgment pattern** — templates should include this block to support
|
|
395
|
+
monitor-agent dialogue (the agent acknowledging a steer and stating a plan):
|
|
396
|
+
|
|
397
|
+
```markdown
|
|
398
|
+
{% if iteration > 0 %}
|
|
399
|
+
NOTE: You have steered {{ iteration }} time(s) already this session.
|
|
400
|
+
The agent's latest response is below. If the agent explicitly acknowledged
|
|
401
|
+
the issue and stated a concrete plan to address it (not just "noted" but
|
|
402
|
+
a specific action), reply CLEAN to allow the agent to follow through.
|
|
403
|
+
Re-flag only if the agent ignored or deflected the steer.
|
|
404
|
+
|
|
405
|
+
Agent response:
|
|
406
|
+
{{ assistant_text }}
|
|
407
|
+
{% endif %}
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
This requires `assistant_text` in the `classify.context` array. When the classifier sees
|
|
411
|
+
genuine acknowledgment, it replies CLEAN, which resets `whileCount` to 0 and gives the agent
|
|
412
|
+
a fresh turn without re-flagging.
|
|
413
|
+
|
|
414
|
+
**Template search order** (first match wins):
|
|
415
|
+
1. `.pi/monitors/<template-path>` — project-level override
|
|
416
|
+
2. `~/.pi/agent/monitors/<template-path>` — user-level
|
|
417
|
+
3. Package `examples/<template-path>` — builtin
|
|
418
|
+
|
|
419
|
+
All four bundled monitors ship with Nunjucks templates in `examples/<name>/classify.md`.
|
|
420
|
+
</prompt_templates>
|
|
421
|
+
|
|
246
422
|
<verdict_format>
|
|
247
423
|
The classification LLM must respond with one of:
|
|
248
424
|
|
|
@@ -310,7 +486,9 @@ for other extensions or workflows to invoke classification directly.
|
|
|
310
486
|
</commands>
|
|
311
487
|
|
|
312
488
|
<bundled_monitors>
|
|
313
|
-
|
|
489
|
+
Four example monitors ship in `examples/` and are seeded on first run. Each has a
|
|
490
|
+
Nunjucks classify template in `examples/<name>/classify.md` with iteration-aware
|
|
491
|
+
acknowledgment support:
|
|
314
492
|
|
|
315
493
|
**fragility** (`message_end`, `when: has_tool_results`)
|
|
316
494
|
Watches for unaddressed fragilities after tool use — errors, warnings, or broken state the
|
|
@@ -338,6 +516,14 @@ under `category: "work-quality"`. Ceiling: 3.
|
|
|
338
516
|
11 bundled patterns across categories: methodology (trial-and-error, symptom-fix,
|
|
339
517
|
double-edit, edit-without-read, insanity-retry, no-plan), verification (no-verify),
|
|
340
518
|
scope (excessive-changes, wrong-problem), quality (copy-paste), cleanup (debug-artifacts).
|
|
519
|
+
|
|
520
|
+
**commit-hygiene** (`agent_end`, `when: has_file_writes`)
|
|
521
|
+
Fires when the agent finishes a turn that included file writes. Checks tool call history
|
|
522
|
+
for git commit commands. If no commit occurred, steers to commit. If committed with a
|
|
523
|
+
generic or certainty-language message, steers to improve. Does not write findings — commits
|
|
524
|
+
are their own artifact. Ceiling: 3.
|
|
525
|
+
6 bundled patterns across categories: missing-commit (no-commit), message-quality
|
|
526
|
+
(generic-message, certainty-language, no-context), commit-safety (amend-not-new, force-push).
|
|
341
527
|
</bundled_monitors>
|
|
342
528
|
|
|
343
529
|
<disabling_monitors>
|
|
@@ -356,27 +542,75 @@ Monitors also auto-silence at their ceiling. With `escalate: "ask"`, the user is
|
|
|
356
542
|
to continue or dismiss. With `escalate: "dismiss"`, the monitor silences automatically.
|
|
357
543
|
</disabling_monitors>
|
|
358
544
|
|
|
359
|
-
<
|
|
360
|
-
|
|
545
|
+
<creating_monitors>
|
|
546
|
+
When the user asks to create a monitor — either from a described behavior ("flag responses
|
|
547
|
+
that end with questions") or from a discovered need during conversation ("that response
|
|
548
|
+
did X wrong, make a monitor for it") — follow this workflow:
|
|
549
|
+
|
|
550
|
+
**Step 1: Determine the detection target.** What specific behavior in the assistant's output
|
|
551
|
+
should trigger a flag? Translate the user's description into concrete, observable patterns.
|
|
552
|
+
|
|
553
|
+
**Step 2: Choose event and when.** Match the detection target to the right trigger:
|
|
554
|
+
- Response content issues (trailing questions, lazy options, tone) → `turn_end`, `when: always`
|
|
555
|
+
- Tool use issues (no commit, no test, bad edits) → `agent_end`, `when: has_file_writes` or `has_tool_results`
|
|
556
|
+
- Post-action fragility (ignoring errors) → `message_end`, `when: has_tool_results`
|
|
557
|
+
- On-demand analysis → `command`, `when: always`
|
|
558
|
+
|
|
559
|
+
**Step 3: Choose context collectors.** What data does the classifier need to see?
|
|
560
|
+
- Checking the assistant's final response text → `assistant_text`
|
|
561
|
+
- Checking what the user asked (to compare against response) → `user_text`
|
|
562
|
+
- Checking what tools were called → `tool_calls`
|
|
563
|
+
- Checking tool outputs for errors/warnings → `tool_results`
|
|
564
|
+
- Checking git state → `git_status`
|
|
565
|
+
- Include `assistant_text` if you want iteration-aware acknowledgment (recommended).
|
|
566
|
+
|
|
567
|
+
**Step 4: Write the patterns file.** Each pattern is a specific, observable anti-pattern.
|
|
568
|
+
Write descriptions that a classifier LLM can match against the collected context. Start with
|
|
569
|
+
3-8 seed patterns. Set `learn: true` so the monitor grows its pattern library from `NEW:`
|
|
570
|
+
verdicts at runtime.
|
|
571
|
+
|
|
572
|
+
**Step 5: Write the classify template.** Use a Nunjucks `.md` file for anything beyond
|
|
573
|
+
trivial classification. The template must:
|
|
574
|
+
- Present the collected context to the classifier
|
|
575
|
+
- List the patterns to check against
|
|
576
|
+
- Include the verdict format instructions (CLEAN/FLAG/NEW)
|
|
577
|
+
- Include the iteration-aware acknowledgment block if `assistant_text` is collected
|
|
578
|
+
|
|
579
|
+
**Step 6: Write the monitor definition.** Wire everything together in the `.monitor.json`.
|
|
580
|
+
|
|
581
|
+
**Step 7: Create empty instructions file.** Write `[]` so the user can add calibration
|
|
582
|
+
rules via `/monitors <name> rules add <text>`.
|
|
583
|
+
|
|
584
|
+
**Step 8: Activate.** After creating the files, tell the user to run `/reload 3` to
|
|
585
|
+
reload extensions and activate the new monitor without restarting the session.
|
|
586
|
+
|
|
587
|
+
### Example: response-mandates monitor
|
|
588
|
+
|
|
589
|
+
User says: "create a monitor that flags responses ending with questions and responses
|
|
590
|
+
that present lazy deferral options."
|
|
591
|
+
|
|
592
|
+
**Files to create:**
|
|
593
|
+
|
|
594
|
+
1. `.pi/monitors/response-mandates.monitor.json`:
|
|
361
595
|
|
|
362
596
|
```json
|
|
363
597
|
{
|
|
364
|
-
"name": "
|
|
365
|
-
"description": "
|
|
598
|
+
"name": "response-mandates",
|
|
599
|
+
"description": "Flags responses that violate communication mandates: trailing questions, lazy deferral options, non-optimal solutions",
|
|
366
600
|
"event": "turn_end",
|
|
367
|
-
"when": "
|
|
601
|
+
"when": "always",
|
|
368
602
|
"scope": { "target": "main" },
|
|
369
603
|
"classify": {
|
|
370
604
|
"model": "claude-sonnet-4-20250514",
|
|
371
|
-
"context": ["
|
|
372
|
-
"excludes": [],
|
|
373
|
-
"
|
|
605
|
+
"context": ["assistant_text", "user_text"],
|
|
606
|
+
"excludes": ["fragility"],
|
|
607
|
+
"promptTemplate": "response-mandates/classify.md"
|
|
374
608
|
},
|
|
375
|
-
"patterns": { "path": "
|
|
376
|
-
"instructions": { "path": "
|
|
609
|
+
"patterns": { "path": "response-mandates.patterns.json", "learn": true },
|
|
610
|
+
"instructions": { "path": "response-mandates.instructions.json" },
|
|
377
611
|
"actions": {
|
|
378
|
-
"on_flag": { "steer": "
|
|
379
|
-
"on_new": { "steer": "
|
|
612
|
+
"on_flag": { "steer": "Rewrite your response: report findings and state actions — do not end with a question or present options that defer proper work." },
|
|
613
|
+
"on_new": { "steer": "Rewrite your response: report findings and state actions — do not end with a question or present options that defer proper work.", "learn_pattern": true },
|
|
380
614
|
"on_clean": null
|
|
381
615
|
},
|
|
382
616
|
"ceiling": 3,
|
|
@@ -384,30 +618,108 @@ to continue or dismiss. With `escalate: "dismiss"`, the monitor silences automat
|
|
|
384
618
|
}
|
|
385
619
|
```
|
|
386
620
|
|
|
387
|
-
2.
|
|
621
|
+
2. `.pi/monitors/response-mandates/classify.md`:
|
|
622
|
+
|
|
623
|
+
```markdown
|
|
624
|
+
The user said:
|
|
625
|
+
"{{ user_text }}"
|
|
626
|
+
|
|
627
|
+
The assistant's response:
|
|
628
|
+
"{{ assistant_text }}"
|
|
629
|
+
|
|
630
|
+
{{ instructions }}
|
|
631
|
+
|
|
632
|
+
Check the assistant's response against these anti-patterns:
|
|
633
|
+
{{ patterns }}
|
|
634
|
+
|
|
635
|
+
Specifically check:
|
|
636
|
+
1. Does the response end with a question to the user? The final sentence or paragraph
|
|
637
|
+
should not be a question unless the user explicitly asked to be consulted. Rhetorical
|
|
638
|
+
questions, permission-seeking ("shall I...?", "would you like...?"), and steering
|
|
639
|
+
questions ("what do you think?") are all violations.
|
|
640
|
+
2. Does the response present options where one or more options leave known issues
|
|
641
|
+
unaddressed? If a problem has been identified, every option presented must address it.
|
|
642
|
+
Options that defer proper work to a vague future ("we could address this later",
|
|
643
|
+
"for now we can...") are violations.
|
|
644
|
+
3. Does the response propose a non-durable solution when a durable one is known? Workarounds,
|
|
645
|
+
temporary fixes, and partial solutions when the root cause is understood are violations.
|
|
646
|
+
|
|
647
|
+
{% if iteration > 0 %}
|
|
648
|
+
NOTE: You have steered {{ iteration }} time(s) already this session.
|
|
649
|
+
If the agent explicitly acknowledged the mandate violation and rewrote its response
|
|
650
|
+
without the violation, reply CLEAN. Re-flag only if the violation persists.
|
|
651
|
+
|
|
652
|
+
Agent response:
|
|
653
|
+
{{ assistant_text }}
|
|
654
|
+
{% endif %}
|
|
655
|
+
|
|
656
|
+
Reply CLEAN if the response follows all mandates.
|
|
657
|
+
Reply FLAG:<description> if a known pattern was matched.
|
|
658
|
+
Reply NEW:<pattern>|<description> if a violation not covered by existing patterns was detected.
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
3. `.pi/monitors/response-mandates.patterns.json`:
|
|
388
662
|
|
|
389
663
|
```json
|
|
390
664
|
[
|
|
391
|
-
{ "id": "
|
|
392
|
-
{ "id": "
|
|
393
|
-
{ "id": "
|
|
665
|
+
{ "id": "trailing-question", "description": "Response ends with a question to the user instead of reporting and acting", "severity": "error", "category": "communication", "source": "bundled" },
|
|
666
|
+
{ "id": "permission-seeking", "description": "Asks permission before acting when the user has already given direction", "severity": "warning", "category": "communication", "source": "bundled" },
|
|
667
|
+
{ "id": "steering-question", "description": "Ends with 'what do you think?', 'does that sound right?', or similar steering questions", "severity": "error", "category": "communication", "source": "bundled" },
|
|
668
|
+
{ "id": "lazy-deferral", "description": "Presents options that defer known issues to a vague future ('we can address later', 'for now')", "severity": "error", "category": "anti-laziness", "source": "bundled" },
|
|
669
|
+
{ "id": "fragility-tolerant-option", "description": "Offers an option that leaves identified fragility unaddressed", "severity": "error", "category": "anti-laziness", "source": "bundled" },
|
|
670
|
+
{ "id": "workaround-over-fix", "description": "Proposes workaround when root cause is understood and fixable", "severity": "warning", "category": "anti-laziness", "source": "bundled" }
|
|
394
671
|
]
|
|
395
672
|
```
|
|
396
673
|
|
|
397
|
-
|
|
674
|
+
4. `.pi/monitors/response-mandates.instructions.json`:
|
|
398
675
|
|
|
399
676
|
```json
|
|
400
677
|
[]
|
|
401
678
|
```
|
|
402
|
-
|
|
679
|
+
|
|
680
|
+
After creating all files, tell the user: "Monitor created. Run `/reload 3` to activate
|
|
681
|
+
it in this session."
|
|
682
|
+
</creating_monitors>
|
|
683
|
+
|
|
684
|
+
<modifying_monitors>
|
|
685
|
+
**Adding patterns** — When the user identifies a new anti-pattern during conversation
|
|
686
|
+
("that kind of response should also be flagged"), add it to the patterns JSON file.
|
|
687
|
+
Each pattern needs `id`, `description`, `severity`, and `source: "user"`.
|
|
688
|
+
|
|
689
|
+
**Adding rules** — Use the `monitors-rules` tool or `/monitors <name> rules add <text>`
|
|
690
|
+
to add calibration rules. Rules fine-tune the classifier without changing patterns.
|
|
691
|
+
Example: "responses that end with 'let me know' are not questions."
|
|
692
|
+
|
|
693
|
+
**Changing the classify prompt** — Edit the Nunjucks template file or the inline prompt.
|
|
694
|
+
For template-based monitors, edit the `.md` file. For inline monitors, edit the `prompt`
|
|
695
|
+
field in the `.monitor.json`.
|
|
696
|
+
|
|
697
|
+
**Upgrading inline to template** — When a monitor needs conditionals (iteration-aware
|
|
698
|
+
acknowledgment, optional context sections), create a `<name>/classify.md` template file
|
|
699
|
+
in `.pi/monitors/` and add `"promptTemplate": "<name>/classify.md"` to the classify block.
|
|
700
|
+
The inline `prompt` remains as fallback.
|
|
701
|
+
|
|
702
|
+
**Adjusting sensitivity** — Lower the `ceiling` to escalate sooner if the monitor is
|
|
703
|
+
over-firing. Raise it to give the agent more chances. Set `escalate: "dismiss"` to
|
|
704
|
+
auto-silence without prompting.
|
|
705
|
+
|
|
706
|
+
After any file changes, tell the user to run `/reload 3` to pick up the changes.
|
|
707
|
+
</modifying_monitors>
|
|
403
708
|
|
|
404
709
|
<success_criteria>
|
|
405
710
|
- Monitor `.monitor.json` validates against `schemas/monitor.schema.json`
|
|
406
711
|
- Patterns `.patterns.json` validates against `schemas/monitor-pattern.schema.json`
|
|
407
712
|
- Patterns array is non-empty (empty patterns = monitor does nothing)
|
|
408
|
-
- Classification prompt includes `{patterns}`
|
|
713
|
+
- Classification prompt (template or inline) includes `{{ patterns }}` / `{patterns}` and verdict format instructions (CLEAN/FLAG/NEW)
|
|
714
|
+
- If using `promptTemplate`, the `.md` file exists at the declared path relative to one of the template search directories
|
|
715
|
+
- If using templates, `assistant_text` is in `classify.context` for iteration-aware acknowledgment
|
|
409
716
|
- Actions specify `steer` for `scope.target: "main"` monitors, `write` for findings output
|
|
410
717
|
- `write.path` is set relative to project cwd, not monitor directory
|
|
411
718
|
- `excludes` lists monitors that should not double-steer in the same turn
|
|
412
719
|
- Instructions file exists (even if empty `[]`) to enable `/monitors <name> rules add <text>` calibration
|
|
720
|
+
- After creating or modifying monitor files, remind user to run `/reload 3`
|
|
413
721
|
</success_criteria>
|
|
722
|
+
|
|
723
|
+
---
|
|
724
|
+
|
|
725
|
+
*Generated from source by `scripts/generate-skills.js` — do not edit by hand.*
|