1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//! Eighth agentic recipe — driving Formal AI to *explain how it itself works*,
//! grounded in its own source, data, and tests, reachable through the agentic
//! interface (issue #558).
//!
//! Issue #558 ("Auto learning") asks that a user be able to *"ask how Formal AI
//! itself works"* and receive an answer *"grounded in its source and data"* rather
//! than prose docs alone (`R558-08`). [`crate::self_explanation`] composes that
//! grounded answer: an ordered set of topics, each citing the *real* artifacts it
//! rests on (source files resolved through the owned manifest, generated data
//! artifacts, and the tests that lock the behaviour). This module makes it reachable
//! *through the agentic interface*: an external agent CLI (`Codex`, `OpenCode`,
//! `Gemini`, `Agent CLI`) — or the in-repo driver — asks Formal AI how it works, and
//! the deterministic planner walks a write → verify → final recipe that emits the
//! grounded explanation as Links Notation, exactly like the self-healing, ledger,
//! source-graph, self-AST, and diagram recipes emit their self-inspection documents.
//!
//! Like [`super::source_graph`], the emitted document depends on the whole source
//! tree (each source citation's `content_id` and the manifest id change with every
//! edit), so it is asserted *live* in the issue-#558 tests and never pinned
//! byte-for-byte in a committed `data/meta/*.lino`. Every source citation is verified
//! against the owned manifest at construction ([`crate::self_explanation::Citation::source`]
//! panics on an unknown path), so the recipe cannot answer with a fabricated source
//! reference. Neural inference stays a NON-GOAL — the explanation is a deterministic
//! function of the embedded source and a fixed set of cited paths.
use OnceLock;
use crate;
/// The workspace path the planner writes the generated explanation document to.
pub const EXPLAIN_PATH: &str = "how-formal-ai-works.lino";
/// The canonical grounded explanation, computed once per process.
///
/// Building it resolves every source citation against the owned manifest; the recipe
/// touches it several times per run (planner write step, verify step, final answer)
/// and a server may serve it repeatedly, so memoising keeps the loop responsive
/// without changing its deterministic result.
/// A *differently worded* request for the self-explanation recipe.
///
/// The router recognises the intent from the words, not a hardcoded string.
/// Deliberately avoids the source-graph keywords ("recompile", whole-source-to-links
/// "and back") and the ledger keywords so the self-inspection recipes never collide.
pub const EXPLAIN_TASK: &str =
"Explain how Formal AI itself works, and ground the answer in its own source \
files, data artifacts, and tests rather than prose documentation.";
/// Keywords that mark a user turn as the self-explanation recipe.
///
/// Deliberately narrow: every keyword pins the "how <the system> works" intent so an
/// ordinary "explain this text" or "how do I …" request does not match, and none
/// overlaps the other self-inspection recipes' keywords.
const EXPLAIN_KEYWORDS: = ;
/// Whether `prompt` asks how Formal AI itself works with a grounded answer (issue
/// #558's `R558-08`).
/// Render the grounded self-explanation document (Links Notation). Deterministic and
/// ends with exactly one trailing newline.
///
/// The output is what the Agent CLI writes to [`EXPLAIN_PATH`]. It is asserted *live*
/// (never committed byte-for-byte) in the issue-#558 tests, because the source
/// citations' content ids and the manifest id change with every source edit —
/// committing it would force a regenerate on every unrelated PR.
/// The grounded explanation backing the recipe. Exposed so tests can assert the
/// citations resolve without rebuilding it.
/// The self-contained final answer: a natural-language summary plus the generated
/// grounded explanation document inline.