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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
//! Shared subagent-dispatch primitive (ARCH §2.3 step 2, §2.5).
//!
//! Every dispatched subagent — compactor (§2.7), worker (§2.5) — starts
//! with the same on-disk shape: a branch off the parent's tip, a sibling
//! worktree at `<conv-repo>/<full-descent>/` (§2.2), `goal.md` (and, for
//! roles with a per-dispatch soul, `soul.md`) at the worktree root, the
//! agent's `name` settled by the trim (§2.3), all
//! committed as the dispatch commit. ARCH §2.5 calls dispatch "the
//! primitive"; this module is its in-process realization, shared between
//! the role-specific entry points.
//!
//! The function is `pub(crate)` because the only legitimate callers are
//! sibling modules within `prompt::` — the CLI surface for
//! procedure-to-procedure invocation is `lernie dispatch <role>` per
//! §3.4, never a direct library call.
use Error;
use crateGitRunner;
use Path;
/// Worktree-relative goal artifact (ARCH §2.8). At the worktree root
/// so manifest pinning (§5.2) sees it.
pub const GOAL_FILE: &str = "goal.md";
/// Worktree-relative soul artifact (ARCH §2.3 step 2 / §4.3). At the
/// worktree root for the same reason `goal.md` is.
pub const SOUL_FILE: &str = "soul.md";
/// Inputs to a subagent dispatch's spawn step. Held as a struct so the
/// compactor and worker call sites pass identically-shaped requests.
pub
/// Spawn the subagent branch and write the dispatch commit. Steps,
/// in order:
///
/// 1. `git worktree add -b agents/<sub-id> <sub_worktree>
/// agents/<parent-id>` in the parent worktree (any access point onto
/// the one workspace repository, §2.2). Ids are bare hyphenated
/// descents; the `agents/` ref prefix is applied here, at the git
/// boundary (§2.3).
/// 2. Trim the forked tree to the child's context (§2.2, §2.3 step 2,
/// §5.1): the config commit's control files leave, and the
/// `descriptions/**` descriptors are derived from the governing
/// config commit to the child's own grant — checked out from it, not
/// inherited from the fork point (`--ignore-unmatch` keeps the
/// removal half total whatever that point carried). Then the fork
/// point's **inherited dialog** leaves (`messages/**`, `summary/**`,
/// `skills/**` — branch-scoped, §2.2): a child's opening context is
/// its goal, soul and pins plus what is deposited to it, never its
/// dispatcher's conversation — except the compactor, whose subject
/// that conversation is
/// ([`crate::prompt::dispatch::prune_inherited_dialog`]). This part
/// is the child spawn's own, not [`trim_to_context`]'s: a
/// fork-back-in *root* resumes the conversation it forks (§7.2) and
/// must keep it.
/// 3. Write `goal.md` (and `soul.md` when supplied) to the new worktree,
/// plus any caller-supplied pinned documents at their validated
/// destinations (§2.5, [`crate::prompt::pinned_doc`]).
/// 4. `git add` the artifacts.
/// 5. `git commit -m <commit_subject>` — the dispatch commit (§2.3
/// step 2 / §2.10). Step 1 of the subagent's own step loop, when
/// one runs, takes no further pre-call commit; the dispatch commit
/// *is* its read state.
pub