areev_loop/llm.rs
1//! Optional LLM enrichment (proposal §9).
2//!
3//! The engine's deterministic output stays a pure function of `(store, params,
4//! now)`. This layer is strictly **additive**: with a backend attached the
5//! pipeline gains two optional stages —
6//!
7//! ```text
8//! ANALYZE (deterministic) → DISCOVER (LLM) → ENRICH (LLM) → VALIDATE+DEDUP → STORE
9//! ```
10//!
11//! and with no backend those stages are the identity function, so the no-LLM
12//! path is byte-for-byte the deterministic path. The LLM can only:
13//! - **DISCOVER**: propose *new* draft recommendations, which enter through
14//! the ordinary candidate/dedup/store path stamped `origin = llm` — so they
15//! can **never auto-apply** and never target prompt/host surfaces. A draft
16//! MAY author a `lesson` (one capped imperative line); a lesson-bearing
17//! draft that survives GROUND + VERIFY stamps as an *applicable*,
18//! rollbackable `ADD fact` proposal instead of an advisory flag — still
19//! `origin = llm`, so applying it always takes a human review with a
20//! BECAUSE plus an explicit apply; and
21//! - **ENRICH**: add a whitelisted `guidance` note to a deterministic
22//! recommendation. The engine-templated summary is always kept; the model
23//! never rewrites it.
24//!
25//! Trust floor (enforced by the engine, not the backend): responses are parsed
26//! to a fixed schema (unknown fields dropped, strings capped), DISCOVER drafts
27//! must cite evidence present in the bundle (by bundle id, full hash, or an
28//! unambiguous hash prefix), instructions never interleave with evidence, and
29//! a failed/timed-out/garbled call drops the LLM contribution for the run
30//! rather than failing it.
31//!
32//! `CommandLlm` mirrors the shipped `CommandEmbed`: whitespace-split argv (no
33//! shell), one process per call, a JSON request on stdin and a JSON response on
34//! stdout, and a construction-time probe that fails loud.
35
36use crate::error::{Error, Result};
37use serde::{Deserialize, Serialize};
38use serde_json::Value;
39
40/// Caps that bound what a single LLM contribution can inject (defense in depth;
41/// the engine enforces them after parsing).
42pub const MAX_LLM_DRAFTS: usize = 8;
43pub const MAX_GUIDANCE_LEN: usize = 600;
44pub const MAX_SUMMARY_LEN: usize = 200;
45/// An authored lesson is one imperative line — anything longer is a document,
46/// not a lesson, and a bound on what a single approved apply can put into
47/// every future prompt.
48pub const MAX_LESSON_LEN: usize = 240;
49/// Caps on the rest of the proposal vocabulary. Each one bounds what a single
50/// approved apply can put into every future run of the agent, so they are part
51/// of the trust floor rather than tuning knobs.
52pub const MAX_RELATION_LEN: usize = 64;
53pub const MAX_OBJECT_LEN: usize = 480;
54/// A skill step is one instruction line; a skill has at most this many.
55pub const MAX_SKILL_STEP_LEN: usize = 240;
56pub const MAX_SKILL_STEPS: usize = 20;
57/// A skill name is an identifier a person types at `skill_view`, not a title.
58pub const MAX_SKILL_NAME_LEN: usize = 64;
59/// A plan has at most this many steps; a condition is one short line.
60pub const MAX_PLAN_NODES: usize = 20;
61pub const MAX_COND_LEN: usize = 200;
62pub const MAX_QUERY_BODY_LEN: usize = 2_000;
63pub const MAX_PLAN_EDITS: usize = 8;
64pub const MAX_CODE_LEN: usize = 20_000;
65
66/// A backend that answers one JSON request with one JSON response. Object-safe
67/// so the engine can hold a `Box<dyn LlmBackend>`.
68pub trait LlmBackend: Send + Sync {
69 /// Model identifier, stamped as provenance on `origin = llm` grains.
70 fn model(&self) -> &str;
71 /// Run one request. `request` is a JSON string; the returned text is
72 /// expected to be JSON and is validated by the caller.
73 fn complete(&self, request: &str) -> Result<String>;
74}
75
76/// Boxed backends forward — lets decorators wrap `Box<dyn LlmBackend>`
77/// without knowing the concrete type.
78impl<T: LlmBackend + ?Sized> LlmBackend for Box<T> {
79 fn model(&self) -> &str {
80 (**self).model()
81 }
82 fn complete(&self, request: &str) -> Result<String> {
83 (**self).complete(request)
84 }
85}
86
87// ---- wire schema (request) -------------------------------------------------
88
89/// One deterministic finding, handed to DISCOVER as context (never as an
90/// instruction — see `LlmRequest`).
91#[derive(Debug, Clone, Serialize)]
92pub struct FindingBrief {
93 pub analyzer: String,
94 pub summary: String,
95 pub target: String,
96 pub severity: String,
97}
98
99/// One evidence grain, provenance-tagged. `id` is the bundle-local label
100/// (`e1`, `e2`, …) a draft may cite instead of the 64-hex `hash`: the engine
101/// resolves either back to the grain, so a citation is still checked against
102/// the bundle — it is just no longer a transcription test for the model.
103#[derive(Debug, Clone, Serialize)]
104pub struct EvidenceItem {
105 pub id: String,
106 pub hash: String,
107 pub grain_type: String,
108 pub text: String,
109}
110
111/// The request envelope. `op` selects the stage; `instructions` is a fixed
112/// engine string kept in its own field so it never interleaves with evidence.
113#[derive(Debug, Clone, Serialize)]
114pub struct LlmRequest<'a> {
115 #[serde(rename = "loop")]
116 pub loop_proto: u8,
117 pub op: &'a str,
118 pub instructions: &'a str,
119 #[serde(skip_serializing_if = "Vec::is_empty")]
120 pub findings: Vec<FindingBrief>,
121 #[serde(skip_serializing_if = "Vec::is_empty")]
122 pub evidence: Vec<EvidenceItem>,
123 /// The operator's recent decisions — what they reject/approve — so the
124 /// model learns this reviewer's taste. (Bounded by the engine.)
125 #[serde(skip_serializing_if = "Vec::is_empty")]
126 pub rejected: Vec<String>,
127 #[serde(skip_serializing_if = "Vec::is_empty")]
128 pub approved: Vec<String>,
129}
130
131// ---- wire schema (response) ------------------------------------------------
132
133/// One DISCOVER draft as returned by the model. Unknown fields are dropped by
134/// serde; the engine further validates (cite-check, caps, target class,
135/// grounding, and independent verification before it is ever stored).
136#[derive(Debug, Clone, Deserialize, Default)]
137#[serde(default)]
138pub struct LlmDraft {
139 pub summary: String,
140 pub target: String,
141 pub guidance: String,
142 pub evidence: Vec<String>,
143 /// The model's self-reported confidence 0.0–1.0 that this finding is both
144 /// correct and materially useful (§5.1). Missing/garbled → 0.0 (rejected by
145 /// the confidence floor), a safe default.
146 pub confidence: f64,
147 /// Optional authored lesson: one imperative rule the model proposes to
148 /// record as a Fact grain. Empty (the default) keeps the draft advisory.
149 /// A non-empty lesson makes the surviving recommendation *applicable* —
150 /// through human review + apply only, never auto-apply — and the lesson
151 /// text is folded into the GROUND claim and VERIFY summary so both gates
152 /// judge exactly what an apply would write.
153 pub lesson: String,
154 /// The generalized proposal vocabulary (§9.1): what change this draft asks
155 /// a reviewer to make. Held as raw JSON so one draft naming an unknown or
156 /// malformed `kind` degrades to advisory instead of dropping the whole
157 /// response — read it through [`LlmDraft::parsed_proposal`].
158 pub proposal: Option<Value>,
159}
160
161/// One field-level edit to a Workflow plan grain. `from` is a staleness check
162/// (it must equal what the live plan holds at `path`), which is what stops a
163/// proposal authored against a superseded plan from applying to a newer one —
164/// the role `base_digest` plays on [`super::recommendation::Proposal::Edit`].
165#[derive(Debug, Clone, Deserialize, Default, PartialEq)]
166#[serde(default)]
167pub struct PlanEdit {
168 /// A dotted path into the plan body, e.g. `edges.2.max_cycles`. The
169 /// engine's allowlist decides which paths are editable at all.
170 pub path: String,
171 pub from: Value,
172 pub to: Value,
173}
174
175/// What a DISCOVER draft proposes to change. Closed vocabulary: every variant
176/// maps onto an apply path that already records an inverse, and anything the
177/// model returns outside it leaves the draft advisory.
178///
179/// Note what each variant does NOT carry. The subject of a `Fact`, the name of
180/// a `QueryRevision`, the hash of a `PlanRevision` and the tool of a
181/// `CodeRevision` all come from the draft's `target`, and the evalset a
182/// `CodeRevision` is gated against comes from the substrate — so the model
183/// names the change but never names its own scope or its own grader.
184#[derive(Debug, Clone, Deserialize, PartialEq)]
185#[serde(tag = "kind", rename_all = "snake_case")]
186pub enum DraftProposal {
187 /// One imperative line recorded as a Fact with `relation = "lesson"`.
188 /// The pre-vocabulary shape, and still the default one.
189 Lesson {
190 #[serde(default)]
191 lesson: String,
192 },
193 /// A durable fact under a model-chosen relation — the "stop making a
194 /// person re-supply this every time" proposal.
195 Fact {
196 #[serde(default)]
197 relation: String,
198 #[serde(default)]
199 object: String,
200 },
201 /// A rewrite of the saved CAL query or template named by the target: the
202 /// agent changing how it assembles its own context.
203 QueryRevision {
204 #[serde(default)]
205 body: String,
206 },
207 /// Field-level edits to the Workflow plan named by the target. Node
208 /// topology is not expressible here by construction — only the paths the
209 /// engine's allowlist admits.
210 PlanRevision {
211 #[serde(default)]
212 edits: Vec<PlanEdit>,
213 },
214 /// New source for the executable tool named by the target. Applies only
215 /// through §7.4's recorded evalset-run edge (Rule E1).
216 CodeRevision {
217 #[serde(default)]
218 source: String,
219 },
220 /// A reusable procedure — a Skill grain — derived from a trajectory that
221 /// succeeded: what it does, when to reach for it, and the ordered steps.
222 /// The skill's NAME comes from the target (`entity:<ns>/<name>`), like a
223 /// fact's subject; when a live skill of that name exists the proposal
224 /// supersedes it rather than adding a near-duplicate (PAST-Bench's own
225 /// analysis names "splits into near-duplicate notes" as the procedural
226 /// failure mode). Offered only when `Policy::skills.enabled`.
227 Skill {
228 #[serde(default)]
229 description: String,
230 #[serde(default)]
231 when_to_use: String,
232 #[serde(default)]
233 steps: Vec<String>,
234 },
235 /// A reusable procedure as a PLAN: named steps, each bound to a tool the
236 /// evidence shows was called, and edges with conditions in the runtime's
237 /// frozen grammar. Applies as a Workflow grain (the structure the runtime
238 /// validates and can execute) plus a Skill grain of the same name (the
239 /// prose a model reads), in one batch; a live pair of that name is
240 /// superseded. Offered only when `Policy::plans.enabled`.
241 Plan {
242 #[serde(default)]
243 description: String,
244 #[serde(default)]
245 when_to_use: String,
246 #[serde(default)]
247 nodes: Vec<PlanNodeDraft>,
248 #[serde(default)]
249 edges: Vec<PlanEdgeDraft>,
250 },
251}
252
253/// One step of a `plan` draft: an identifier, the tool it calls, and what it
254/// does with it.
255#[derive(Debug, Clone, Deserialize, Default, PartialEq)]
256#[serde(default)]
257pub struct PlanNodeDraft {
258 pub id: String,
259 pub tool: String,
260 pub step: String,
261}
262
263/// One edge of a `plan` draft. `cond` is in the runtime's frozen grammar
264/// (`path == literal`, `path != literal`, `path exists`, `!path`).
265#[derive(Debug, Clone, Deserialize, Default, PartialEq)]
266#[serde(default)]
267pub struct PlanEdgeDraft {
268 pub src: String,
269 pub dst: String,
270 pub cond: Option<String>,
271 pub max_cycles: Option<u32>,
272}
273
274impl LlmDraft {
275 /// The proposal this draft makes, or `None` when it is advisory.
276 ///
277 /// An explicit `proposal` decides on its own: if it names an unknown kind
278 /// or fails to parse, the draft is advisory rather than being quietly
279 /// re-read as something the model did not ask for. `lesson` is the
280 /// fallback only when no `proposal` was sent at all, which is what keeps
281 /// every transcript recorded before the vocabulary existed parsing — and
282 /// therefore keeps the published runs comparable.
283 pub fn parsed_proposal(&self) -> Option<DraftProposal> {
284 if let Some(v) = &self.proposal {
285 return serde_json::from_value::<DraftProposal>(v.clone()).ok();
286 }
287 if self.lesson.trim().is_empty() {
288 None
289 } else {
290 Some(DraftProposal::Lesson {
291 lesson: self.lesson.clone(),
292 })
293 }
294 }
295}
296
297/// The DISCOVER response.
298#[derive(Debug, Clone, Deserialize, Default)]
299#[serde(default)]
300pub struct DiscoverResponse {
301 pub recommendations: Vec<LlmDraft>,
302}
303
304/// The ENRICH response: guidance keyed by target_ref of a deterministic rec.
305#[derive(Debug, Clone, Deserialize, Default)]
306#[serde(default)]
307pub struct EnrichResponse {
308 /// `[{ "target": "...", "guidance": "..." }]`
309 pub notes: Vec<EnrichNote>,
310}
311
312#[derive(Debug, Clone, Deserialize, Default)]
313#[serde(default)]
314pub struct EnrichNote {
315 pub target: String,
316 pub guidance: String,
317}
318
319// ---- verifier stages (§5.2 GROUND, §5.3 VERIFY) ----------------------------
320
321/// GROUND request: for each candidate draft, does its cited evidence actually
322/// *entail* the claim? Decompose-then-entail is asked of the model here; a
323/// stronger deployment can swap a dedicated entailment checker behind the same
324/// shape. Kept a separate op/call from DISCOVER (proposer ≠ grounder).
325#[derive(Debug, Clone, Serialize)]
326pub struct GroundRequest<'a> {
327 #[serde(rename = "loop")]
328 pub loop_proto: u8,
329 pub op: &'a str, // "ground"
330 pub instructions: &'a str,
331 pub claims: Vec<GroundItem>,
332}
333
334#[derive(Debug, Clone, Serialize)]
335pub struct GroundItem {
336 pub id: usize,
337 pub claim: String,
338 pub evidence: Vec<EvidenceItem>,
339}
340
341#[derive(Debug, Clone, Deserialize, Default)]
342#[serde(default)]
343pub struct GroundResponse {
344 pub results: Vec<GroundResult>,
345}
346
347#[derive(Debug, Clone, Deserialize, Default)]
348#[serde(default)]
349pub struct GroundResult {
350 pub id: usize,
351 pub supported: bool,
352 pub reason: String,
353}
354
355/// VERIFY request: an **independent** adversarial pass (a separate call from the
356/// proposer — the anti-Goodhart rule) that tries to refute each grounded draft
357/// on novelty / reality / out-of-context grounds and returns keep/kill + a
358/// calibrated confidence. Deterministic findings are passed as context so the
359/// verifier can reject drafts that merely restate them.
360#[derive(Debug, Clone, Serialize)]
361pub struct VerifyRequest<'a> {
362 #[serde(rename = "loop")]
363 pub loop_proto: u8,
364 pub op: &'a str, // "verify"
365 pub instructions: &'a str,
366 pub findings: Vec<VerifyItem>,
367}
368
369#[derive(Debug, Clone, Serialize)]
370pub struct VerifyItem {
371 pub id: usize,
372 pub summary: String,
373 pub target: String,
374 pub evidence: Vec<EvidenceItem>,
375}
376
377#[derive(Debug, Clone, Deserialize, Default)]
378#[serde(default)]
379pub struct VerifyResponse {
380 pub results: Vec<VerifyResult>,
381}
382
383#[derive(Debug, Clone, Deserialize, Default)]
384#[serde(default)]
385pub struct VerifyResult {
386 pub id: usize,
387 pub keep: bool,
388 pub confidence: f64,
389 pub reason: String,
390}
391
392/// The probe response.
393#[derive(Debug, Clone, Deserialize, Default)]
394#[serde(default)]
395struct ProbeResponse {
396 model: String,
397}
398
399/// A subprocess LLM backend. One process per call; argv is whitespace-split
400/// with no shell (identical rules to `CommandEmbed`).
401pub struct CommandLlm {
402 argv: Vec<String>,
403 model: String,
404}
405
406impl CommandLlm {
407 /// Construct and probe. The probe (`{"loop":1,"op":"probe"}`) must return
408 /// JSON with a `model` (or one is supplied), so a misconfigured command
409 /// fails at construction, not mid-run.
410 pub fn new(cmd: &str, model: Option<&str>) -> Result<Self> {
411 let argv: Vec<String> = cmd.split_whitespace().map(str::to_string).collect();
412 if argv.is_empty() {
413 return Err(Error::LlmBackend("--llm-cmd is empty".into()));
414 }
415 let mut me = CommandLlm {
416 argv,
417 model: model.unwrap_or("").to_string(),
418 };
419 let probe = me.run(r#"{"loop":1,"op":"probe"}"#)?;
420 let parsed: ProbeResponse = serde_json::from_str(probe.trim()).map_err(|e| {
421 Error::LlmBackend(format!("--llm-cmd probe did not return JSON with a model: {e}"))
422 })?;
423 if me.model.is_empty() {
424 me.model = if parsed.model.is_empty() {
425 "unspecified".to_string()
426 } else {
427 parsed.model
428 };
429 }
430 Ok(me)
431 }
432
433 fn run(&self, request: &str) -> Result<String> {
434 let out = crate::proc::run_argv(&self.argv, request, Some(crate::proc::DEFAULT_TIMEOUT))
435 .map_err(|e| Error::LlmBackend(format!("spawn --llm-cmd {:?}: {e}", self.argv[0])))?;
436 if let Some(why) = out.failure("--llm-cmd") {
437 return Err(Error::LlmBackend(why));
438 }
439 String::from_utf8(out.stdout)
440 .map_err(|e| Error::LlmBackend(format!("--llm-cmd stdout not UTF-8: {e}")))
441 }
442}
443
444impl LlmBackend for CommandLlm {
445 fn model(&self) -> &str {
446 &self.model
447 }
448 fn complete(&self, request: &str) -> Result<String> {
449 self.run(request)
450 }
451}
452
453/// Parse a DISCOVER response, dropping anything malformed. Never errors on
454/// model garbage — a bad response yields no drafts.
455pub fn parse_discover(raw: &str) -> DiscoverResponse {
456 serde_json::from_str(raw.trim()).unwrap_or_default()
457}
458
459/// Parse an ENRICH response, dropping anything malformed.
460pub fn parse_enrich(raw: &str) -> EnrichResponse {
461 serde_json::from_str(raw.trim()).unwrap_or_default()
462}
463
464/// Parse a GROUND response; garbage → no results (⇒ every draft is treated as
465/// ungrounded and dropped, the safe default).
466pub fn parse_ground(raw: &str) -> GroundResponse {
467 serde_json::from_str(raw.trim()).unwrap_or_default()
468}
469
470/// Parse a VERIFY response; garbage → no results (⇒ every draft is dropped).
471pub fn parse_verify(raw: &str) -> VerifyResponse {
472 serde_json::from_str(raw.trim()).unwrap_or_default()
473}
474
475/// Truncate to a char cap without splitting a UTF-8 boundary.
476pub fn cap(s: &str, max: usize) -> String {
477 if s.chars().count() <= max {
478 s.to_string()
479 } else {
480 s.chars().take(max).collect()
481 }
482}
483
484#[cfg(test)]
485mod tests {
486 use super::*;
487
488 #[test]
489 fn parse_discover_drops_garbage() {
490 assert!(parse_discover("not json").recommendations.is_empty());
491 let r = parse_discover(r#"{"recommendations":[{"summary":"s","target":"entity:x/y","evidence":["h1"],"junk":1}]}"#);
492 assert_eq!(r.recommendations.len(), 1);
493 assert_eq!(r.recommendations[0].summary, "s");
494 assert_eq!(r.recommendations[0].evidence, vec!["h1"]);
495 }
496
497 #[test]
498 fn parse_enrich_reads_notes() {
499 let r = parse_enrich(r#"{"notes":[{"target":"entity:a/b","guidance":"g"}]}"#);
500 assert_eq!(r.notes.len(), 1);
501 assert_eq!(r.notes[0].guidance, "g");
502 }
503
504 #[test]
505 fn lesson_desugars_when_no_proposal_is_sent() {
506 // Every transcript recorded before the vocabulary existed must still
507 // resolve to the same change, or the published runs stop being
508 // comparable with anything measured after it.
509 let r = parse_discover(
510 r#"{"recommendations":[{"summary":"s","target":"entity:a/b","evidence":["h"],"lesson":"Do the thing"}]}"#,
511 );
512 assert_eq!(
513 r.recommendations[0].parsed_proposal(),
514 Some(DraftProposal::Lesson { lesson: "Do the thing".into() })
515 );
516 }
517
518 #[test]
519 fn an_explicit_proposal_wins_over_lesson() {
520 let r = parse_discover(
521 r#"{"recommendations":[{"summary":"s","target":"entity:a/b","evidence":["h"],
522 "lesson":"ignored","proposal":{"kind":"fact","relation":"alias_of","object":"Cobalt Cloud"}}]}"#,
523 );
524 assert_eq!(
525 r.recommendations[0].parsed_proposal(),
526 Some(DraftProposal::Fact {
527 relation: "alias_of".into(),
528 object: "Cobalt Cloud".into()
529 })
530 );
531 }
532
533 #[test]
534 fn an_unparseable_proposal_is_advisory_not_reinterpreted() {
535 // A garbled proposal must NOT fall back to the lesson: applying an
536 // `ADD fact` when the model asked for something we could not read is
537 // doing something it never proposed.
538 for body in [
539 r#""proposal":{"kind":"teleport","x":1}"#,
540 r#""proposal":{"kind":"plan_revision","edits":"not-a-list"}"#,
541 r#""proposal":42"#,
542 ] {
543 let raw = format!(
544 r#"{{"recommendations":[{{"summary":"s","target":"entity:a/b","evidence":["h"],"lesson":"L",{body}}}]}}"#
545 );
546 let r = parse_discover(&raw);
547 assert_eq!(r.recommendations.len(), 1, "{body}");
548 assert_eq!(r.recommendations[0].parsed_proposal(), None, "{body}");
549 }
550 }
551
552 #[test]
553 fn one_bad_proposal_does_not_drop_its_siblings() {
554 // Per-draft tolerance: the whole response surviving is what keeps a
555 // single malformed kind from silently costing a run its findings.
556 let r = parse_discover(
557 r#"{"recommendations":[
558 {"summary":"a","target":"entity:a/b","evidence":["h"],"proposal":{"kind":"nope"}},
559 {"summary":"b","target":"entity:a/c","evidence":["h"],"proposal":{"kind":"lesson","lesson":"Keep me"}}
560 ]}"#,
561 );
562 assert_eq!(r.recommendations.len(), 2);
563 assert_eq!(r.recommendations[0].parsed_proposal(), None);
564 assert_eq!(
565 r.recommendations[1].parsed_proposal(),
566 Some(DraftProposal::Lesson { lesson: "Keep me".into() })
567 );
568 }
569
570 #[test]
571 fn plan_edits_carry_their_staleness_check() {
572 let r = parse_discover(
573 r#"{"recommendations":[{"summary":"s","target":"grain:abc","evidence":["h"],
574 "proposal":{"kind":"plan_revision","edits":[{"path":"retries.fetch","from":null,"to":3}]}}]}"#,
575 );
576 let Some(DraftProposal::PlanRevision { edits }) =
577 r.recommendations[0].parsed_proposal()
578 else {
579 panic!("expected a plan revision");
580 };
581 assert_eq!(edits.len(), 1);
582 assert_eq!(edits[0].path, "retries.fetch");
583 assert_eq!(edits[0].from, Value::Null);
584 assert_eq!(edits[0].to, Value::from(3));
585 }
586
587 #[test]
588 fn cap_respects_char_boundaries() {
589 assert_eq!(cap("hello", 3), "hel");
590 assert_eq!(cap("héllo", 2), "hé");
591 assert_eq!(cap("hi", 5), "hi");
592 }
593 #[test]
594 fn skill_proposal_parses_and_missing_fields_default_empty() {
595 let raw = r#"{"recommendations":[{"summary":"s","target":"entity:ops/triage-batch","evidence":["e1"],
596 "proposal":{"kind":"skill","description":"Triage an open ticket batch","when_to_use":"a batch of open helpdesk tickets arrives",
597 "steps":["List open tickets with helpdesk_list_tickets","Fetch each with helpdesk_get_ticket","Update priority and tags"]}}]}"#;
598 let d = &parse_discover(raw).recommendations[0];
599 match d.parsed_proposal() {
600 Some(DraftProposal::Skill { description, when_to_use, steps }) => {
601 assert_eq!(description, "Triage an open ticket batch");
602 assert!(when_to_use.starts_with("a batch"));
603 assert_eq!(steps.len(), 3);
604 }
605 other => panic!("expected a skill, got {other:?}"),
606 }
607 let d = &parse_discover(r#"{"recommendations":[{"summary":"s","target":"entity:a/b","evidence":["e1"],"proposal":{"kind":"skill"}}]}"#)
608 .recommendations[0];
609 assert!(
610 matches!(d.parsed_proposal(), Some(DraftProposal::Skill { steps, .. }) if steps.is_empty()),
611 "a bare skill parses to empties; the engine, not the parser, decides it is too thin"
612 );
613 }
614
615}