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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
//! `bl-chore` — the guarded close-gate mint at claim (design bl-3df3).
//!
//! An opt-in, first-party plugin: at `claim.pre`, for the task being claimed, it
//! mints one close-gate child per configured chore ("Run the test suite", ...) so
//! the claiming agent must discharge them before `bl close` succeeds. It is the
//! CREATE side only — a human (or a resolver plugin) closes the gate; bl-chore
//! never resolves it (§10). Two guards keep it sound:
//!
//! - **tag-skip** (always-on, structural): if the claimed task carries bl-chore's
//! own tag, bail — claiming a chore must not mint a chore-of-a-chore. A chore is
//! a LEAF, so the epic-skip has-children check would not catch it. Read off the
//! §7 wire (`current_state.tags`), no store query.
//! - **epic-skip** (a knob, default-on, in the plugin's own config): if the
//! claimed task already has any live child, bail — keeps epics clutter-free AND
//! gives idempotency for free (a reclaim finds the chores it minted before).
//!
//! **THE MINT IS A FILE WRITE, NOT AN OP (bl-1da3).** It used to shell `bl
//! create` once per chore. §14's appendix — rollback for effects whose binding
//! artifact lives in an EXTERNAL system — was stretched to cover that, calling
//! balls "the external tracker that assigns its own id". Balls is not external to
//! itself. Core CAN reach the store: it is the change worktree this plugin is
//! invoked in, and `pre` is the sanctioned door (§8 step 2, "pre modifiers …
//! edit the shared worktree"; §8.3, "a `pre` plugin edits the SHARED change
//! worktree, so it can also touch a SIBLING `tasks/*.md`"). So the mint is two
//! ordinary writes into that worktree — `tasks/<child>.md`, and the `{id, on:
//! close}` blocker onto the parent's file, which is already there because
//! `base.stage` ran before this phase.
//!
//! What that DELETES is the point: the nested op and its own commit point, the
//! `Bl` shell seam, the scratch record that carried ids across a process
//! boundary, the rollback that took them back down, the mid-list inline unwind,
//! and the `close.post` sweep of the record. **There is no rollback because
//! there is no separate effect to undo** — the children live in the claim's own
//! change worktree, so an aborted claim discards them with it, and the §14
//! appendix stops applying rather than being satisfied.
//!
//! Nothing derives a clock or an identity twice: the op instant is read off the
//! parent's freshly-staged `updated`, and the child inherits the parent's
//! `root_commit` (bl-1ce7) rather than re-asking git.
use fs;
use io;
use ;
use Deserialize;
use crateIdScheme;
use crate;
use crate;
/// The §6 self-description, emitted on `bl-chore protocol`. ONE op now: the mint
/// is part of the claim's own atom, so there is no `close` record to retire and
/// no rollback to declare. The WIRING (`bl conf prepend claim.pre bl-chore`) is
/// config, never the binary (§6) — balls reads this only to validate a bind.
pub const PROTOCOL_JSON: &str = r#"{"protocol":[1],"ops":["claim"]}"#;
/// The slice of the §7 wire bl-chore reads. Output-only [`crate::wire`] is the
/// core's side; this is the receiving end, so it owns its own input type and
/// serde drops every field it does not name — keeping it stable as the wire grows.
/// `landing` — where this plugin's committed config lives. The project repo root
/// is no longer needed: nothing is shelled, and the worktree the mint writes is
/// this process's cwd. Defaults empty so a partial/stealth wire still
/// deserializes (the guards short-circuit first).
/// Just the ball the op is about.
/// Just the claimed task's tags — the only field tag-skip needs.
/// bl-chore's own config (`<landing>/config/plugins/<name>/chores.toml`) — a list
/// of declarative chore specs plus the epic-skip knob. Lives in the plugin's own
/// territory (balls never reads it, §4 severability).
/// One chore: a title (required) plus optional declared body/priority — never
/// flags or shell. The gate edge and the recursion-break tag are this module's,
/// so a caller can never forget them.
/// The epic-skip default — a missing `epic_skip` key is ON (the conservative call:
/// a leaf you gave one real subtask gets no chores; override per-repo in config).
/// Dispatch one bl-chore invocation. `op`/`phase` are argv; `plugin` is the
/// schedule name (`BALLS_PLUGIN_NAME` — the recursion-break tag AND the config
/// territory both derive from it); `dir` is the CHANGE WORKTREE (the process cwd
/// core invokes a hook in), which is both what the mint writes and what
/// epic-skip reads; `stdin` is the §7 wire.
///
/// Only the `claim.pre` forward pass does anything. A ROLLBACK is a no-op by
/// construction, not by care: whatever this wrote is in the worktree core
/// discards. A malformed payload or a failed write is an error (aborts the
/// claim); a guard firing, or nothing to do, is a clean `Ok(())`.
/// Write one `tasks/<child>.md` per chore and hang each on the parent as a
/// close-gate blocker. Every id is re-rolled off the ids ALREADY in the worktree,
/// so the children of one claim cannot collide with each other or with a sibling
/// `pre` plugin's fresh write (§ id generation — the scheme is public and the
/// live set is right here).
///
/// The parent is read once, for the two facts a child inherits rather than
/// re-derives: the op instant (`updated`, stamped by `base.stage` moments ago —
/// a second clock would be a second answer) and `root_commit`, so a chore is
/// bound to the same repo as the ball it gates (bl-1ce7) without asking git.
/// `<landing>/config/plugins/<plugin>/chores.toml` — the plugin's own committed
/// config territory on the landing (§2/§4).
/// Read + parse the chore config; an ABSENT file is the present-but-empty config
/// (mint nothing — opting the plugin in without writing chores is a valid no-op),
/// routed through the SAME serde defaults so `epic_skip`-on lives in one place.
/// Whether any ball in the worktree names `parent` as its parent — the epic-skip
/// predicate. This was the plugin's one store query (`bl list --json`, a second
/// nested op); the change worktree is the same live set, one directory read away,
/// so the query had no reason to leave the process.