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
//! Eleventh agentic recipe — recompile Formal AI and reattach the improved worker to
//! the UI, reachable via the agentic interface (issue #558, `R558-06`).
//!
//! Issue #558 ("Auto learning") asks that Formal AI be able to *"recompile and reattach
//! the improved code to the UI"* — the final step of the self-change loop, once a change
//! is accepted. [`crate::rebuild_plan`] composes that as a deterministic, human-gated
//! plan derived from an already-accepted change ([`crate::change_request::AcceptedChange`],
//! which only exists after a green benchmark gate *and* a human approval). 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 to
//! rebuild and reattach the improved worker to the UI, and the deterministic planner
//! walks a write → verify → final recipe that emits the ordered, reversible
//! rebuild-and-reattach pipeline as Links Notation, exactly like the change-request,
//! source-graph, explain, and repair-strategy recipes emit their documents.
//!
//! Like [`super::source_graph`], [`super::explain`], and [`super::change_request`], the
//! emitted document depends on the whole source tree (the reattached artifacts'
//! content ids 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`. The reattached
//! artifacts are grounded against the real repository bytes and the owned manifest, so
//! the recipe cannot answer with a fabricated artifact. Nothing here rebuilds or
//! restarts anything: the plan is the reviewable *product*, so the "recompile and
//! reattach" guardrail (observable, testable, reversible, human-approved) is preserved.
//! Neural inference stays a NON-GOAL — the plan is a deterministic function of the
//! accepted change and the embedded artifacts.
use OnceLock;
use crate;
/// The workspace path the planner writes the generated rebuild-and-reattach plan to.
pub const REBUILD_PATH: &str = "rebuild-and-reattach.lino";
/// The canonical rebuild-and-reattach plan, computed once per process.
///
/// Building it accepts the canonical change through the same green-gate-plus-approval
/// the ledger and change request enforce, then grounds every reattached artifact; 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 rebuild-and-reattach recipe.
///
/// The router recognises the intent from the words, not a hardcoded string.
/// Deliberately avoids the source-graph keyword "recompile" (and its "entire"/"whole"/
/// "all" fallback), the change-request "capability"/"feature"/"support" fallback, the
/// self-healing "heal"/"learn a" fallback, and the ledger/explain/repair-strategy
/// keywords, so the recipes never collide: this recipe keys on *reattaching* the rebuilt
/// worker to the UI.
pub const REBUILD_TASK: &str =
"An improvement to Formal AI was accepted — now rebuild it and reattach the improved \
WebAssembly worker to the UI: give me the ordered, reversible steps to regenerate \
the worker, reattach it to the browser UI, hot-swap the local server, and verify \
the UI uses the accepted version.";
/// Keywords that mark a user turn as the rebuild-and-reattach recipe.
///
/// Deliberately narrow: every keyword pins the "reattach the rebuilt worker to the UI"
/// intent, and none overlaps the other recipes' keywords (in particular the source-graph
/// recipe owns "recompile", which is absent here — this recipe keys on "reattach").
const REBUILD_KEYWORDS: = ;
/// Whether `prompt` asks the rebuild-and-reattach recipe (issue #558's `R558-06`).
/// Render the rebuild-and-reattach plan (Links Notation) for the canonical accepted
/// change. Deterministic and ends with exactly one trailing newline.
///
/// The output is what the Agent CLI writes to [`REBUILD_PATH`]. It is asserted *live*
/// (never committed byte-for-byte) in the issue-#558 tests, because the reattached
/// artifacts' content ids change with every source edit — committing it would force a
/// regenerate on every unrelated PR.
/// The canonical rebuild-and-reattach plan backing the recipe. Exposed so tests can
/// assert the plan grounds its artifacts without rebuilding it.
/// The self-contained final answer: a natural-language summary plus the generated
/// rebuild-and-reattach plan inline.