Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
d6ae876
feat(9-1): add the four plan events and the phase stream
crenshawdev Oct 31, 2026
29c953f
feat(9-1): build a plan draft's body, digest and target from an accep…
crenshawdev Oct 31, 2026
a2fca99
feat(9-1): judge a plan approval in d-16's order
crenshawdev Oct 31, 2026
6b62e07
feat(9-1): judge a plan replacement and the phase it is judged under
crenshawdev Oct 31, 2026
2b16c83
fix(9-1): refuse extra binding members and pin the replaced digest an…
crenshawdev Oct 31, 2026
0d78de7
feat(9-2): project a phase's plans, numbers, size and activity
crenshawdev Oct 31, 2026
9688d5e
feat(9-2): keep a phase's current plan draft and latest continuation
crenshawdev Oct 31, 2026
de5ba86
feat(9-2): project each approved plan's record
crenshawdev Oct 31, 2026
fa14d7d
feat(9-2): project each approved plan's evidence map and read it back
crenshawdev Oct 31, 2026
515c4d4
fix(9-2): refuse an unrepresentable phase size and pin reuse, handled…
crenshawdev Oct 31, 2026
dc99f20
feat(9-3): add the phase capacity and test command settings
crenshawdev Oct 31, 2026
e920b31
feat(9-3): judge what a phase-plan call does with a selection
crenshawdev Oct 31, 2026
49b02d7
feat(9-3): project each story's size from the plans serving it
crenshawdev Oct 31, 2026
495eec7
feat(9-3): register the plan events and views at view set 14
crenshawdev Oct 31, 2026
8d37c8f
test(9-3): pin readiness order with the higher fault later in the sel…
crenshawdev Oct 31, 2026
348020a
feat(9-4): read what a planner order binds
crenshawdev Oct 31, 2026
e51ef43
feat(9-4): issue a phase's planner order on its own stream
crenshawdev Oct 31, 2026
d511073
feat(9-4): record a changed selection's edit with its continuation
crenshawdev Oct 31, 2026
56eccc0
feat(9-4): hand an approved planner order to the session once
crenshawdev Oct 31, 2026
fcbfd3c
fix(9-4): refuse a hand-over of an order no longer pending or already…
crenshawdev Oct 31, 2026
046e3ed
feat(9-5): check and run a session's phase plan
crenshawdev Oct 31, 2026
8d88c0f
feat(9-5): issue the planner order when a commitment is approved
crenshawdev Oct 31, 2026
7c330ee
feat(9-5): approve a commitment at the terminal and print its order
crenshawdev Oct 31, 2026
22006c7
feat(9-5): serve phase-plan on baley_apply
crenshawdev Oct 31, 2026
26fa43f
fix(9-5): hand an order over only on what its check read
crenshawdev Oct 31, 2026
2d2802d
fix(9-5): declare the check's absences when recording a draft
crenshawdev Oct 31, 2026
bbd8bc7
fix(9-5): answer a replayed phase-plan draft as the first call
crenshawdev Oct 31, 2026
8028294
fix(9-5): print the launchable order only for a draft-approved refusal
crenshawdev Oct 31, 2026
3ca002a
feat(9-6): check a submitted plan against its order and phase
crenshawdev Oct 31, 2026
f91f773
feat(9-6): record a plan draft with its question set
crenshawdev Oct 31, 2026
5cc75a1
feat(9-6): judge a plan approval against the phase as it stands
crenshawdev Oct 31, 2026
264991f
feat(9-6): record a plan approval with the next plan number
crenshawdev Oct 31, 2026
62bf8c5
fix(9-6): refuse a plan draft replaced mid-approval as stale
crenshawdev Oct 31, 2026
0e99f4e
feat(9-7): replace an approved plan under a new number
crenshawdev Oct 31, 2026
e8f8fa5
feat(9-7): serve plan-submit and plan-replace to a session
crenshawdev Oct 31, 2026
f824c28
feat(9-7): answer a plan draft's closed set with ready or a revision
crenshawdev Oct 31, 2026
ed0dfb5
feat(9-7): approve a plan at the terminal with baley plan approve
crenshawdev Nov 1, 2026
a7a2556
fix(9-7): judge a plan approval again when the policy step reads othe…
crenshawdev Nov 1, 2026
edfcf71
fix(9-7): observe the readiness read a revision's selection came from
crenshawdev Nov 1, 2026
c1e5860
fix(9-7): pin a plan-replace resent after its approval as a replay
crenshawdev Nov 1, 2026
c74e08d
feat(9-8): read a phase's approved plans with their evidence maps
crenshawdev Nov 1, 2026
de73232
feat(9-8): serve plan-read on baley_query
crenshawdev Nov 1, 2026
4296dfb
feat(9-8): show a phase's approved plans with baley plan show
crenshawdev Nov 1, 2026
100a341
feat(9-8): meet a plan draft in scope approve and scope preview
crenshawdev Nov 1, 2026
58371a3
fix(9-8): give each approved plan in the plan-read check its own map
crenshawdev Nov 1, 2026
003364b
feat(9-9): serve the bal-plan front door
crenshawdev Nov 1, 2026
4466cc9
feat(9-9): read a phase and an approved plan with document
crenshawdev Nov 1, 2026
45351b4
fix(9-9): make the plan document test tell phases apart
crenshawdev Nov 1, 2026
c0068cb
docs(9-10): record ADR 0050 for the phase plan commitment
crenshawdev Nov 1, 2026
033dcb1
docs(9-10): describe the phase edit continuation in design 0004
crenshawdev Nov 1, 2026
a1f2ced
docs(9-10): describe phase planning as built in design 0005
crenshawdev Nov 1, 2026
14125b8
docs(9-10): name the planning views and events in design 0001
crenshawdev Nov 1, 2026
7924ead
docs(9-10): hold the checker revision order open in design 0005
crenshawdev Nov 1, 2026
b9b851e
docs(9-10): judge the hand-over before the pending order in figure 5
crenshawdev Nov 1, 2026
854c255
docs(9-10): describe bal-rounds for plan sets in design 0005
crenshawdev Nov 1, 2026
947ae97
docs(9-11): name the planning settings and planner routes in design 0003
crenshawdev Nov 1, 2026
d04733c
docs(9-11): describe the served planning operations in design 0012
crenshawdev Nov 1, 2026
ca2685e
docs(9-11): name the phase planner's orders in design 0002 and the C4…
crenshawdev Nov 1, 2026
ef6ba90
docs(9-11): show build 4 t8 merged and t9 in progress in the roadmap
crenshawdev Nov 1, 2026
45abf6d
docs(9-11): cite the guard settings in design 0010 by item
crenshawdev Nov 1, 2026
78ca475
docs(9-11): keep the rounds relay's submit step to story sets in desi…
crenshawdev Nov 1, 2026
29744d3
docs(9-11): state when a closing answer issues an order in design 0003
crenshawdev Nov 1, 2026
fbe7bbe
docs(9-11): bring the view set to 14 in designs 0012 and 0010
crenshawdev Nov 1, 2026
dd71b0c
docs(9-11): list the plan commands in design 0012's HST-R16
crenshawdev Nov 1, 2026
cf81803
docs(design): raise design 0014's view set to 14
crenshawdev Nov 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
489 changes: 489 additions & 0 deletions crates/baley-core/src/plan/approval.rs

Large diffs are not rendered by default.

443 changes: 443 additions & 0 deletions crates/baley-core/src/plan/commitment.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions crates/baley-core/src/plan/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub(super) fn read(value: &Value) -> Result<Plan, PlanRefusal> {
tasks,
evidence_map,
questions,
submitted: plan.clone(),
})
}

Expand Down
259 changes: 259 additions & 0 deletions crates/baley-core/src/plan/event.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
//! The four plan events: their types, their registration, their stream and
//! their payloads (design 0005 section 6, design 0001 Streams).
//!
//! Every plan event goes on its phase's stream, `phase/<n>`, the stream a
//! plan draft's question set takes. Owner and time are payload members, as
//! `scope.approved` and `story.refined` carry them.

use baley_store::{Hash, PayloadRef};
use serde_json::{Value, json};

use crate::registry::{Registry, RegistryError};

/// A plan approved, on its phase's stream: `{phase, plan, digest, stories,
/// size, suite, question_set, evidence_map, body, owner, at}`.
///
/// The evidence map is inline so its view rebuilds from events alone and
/// survives a purge of the draft's body; the plan's text is only the
/// draft's `record` reference, since plan text is an attachment (D-06).
pub const PLAN_APPROVED: &str = "plan.approved";
/// The current `plan.approved` payload version.
pub const PLAN_APPROVED_VERSION: u32 = 1;
/// A plan replaced, on its phase's stream: `{phase, plan, old_digest,
/// new_digest, owner, at}`, `plan` the old number (D-07).
pub const PLAN_REPLACED: &str = "plan.replaced";
/// The current `plan.replaced` payload version.
pub const PLAN_REPLACED_VERSION: u32 = 1;
/// A planning continuation, on its phase's stream: `{phase, stories, edit,
/// work_order}`, recorded with the `phase edit` draft it waits on (D-09).
pub const PLAN_CONTINUATION: &str = "plan.continuation";
/// The current `plan.continuation` payload version.
pub const PLAN_CONTINUATION_VERSION: u32 = 1;
/// A continuation's planner order handed to the session, on its phase's
/// stream: `{phase, edit, work_order}` (D-09).
pub const PLAN_CONTINUATION_FOLLOWED: &str = "plan.continuation_followed";
/// The current `plan.continuation_followed` payload version.
pub const PLAN_CONTINUATION_FOLLOWED_VERSION: u32 = 1;

/// Registers the four plan types at version 1 with no upcasters.
pub fn register_plan_events(registry: &mut Registry) -> Result<(), RegistryError> {
registry.register(PLAN_APPROVED, PLAN_APPROVED_VERSION, [])?;
registry.register(PLAN_REPLACED, PLAN_REPLACED_VERSION, [])?;
registry.register(PLAN_CONTINUATION, PLAN_CONTINUATION_VERSION, [])?;
registry.register(
PLAN_CONTINUATION_FOLLOWED,
PLAN_CONTINUATION_FOLLOWED_VERSION,
[],
)
}

/// The stream of phase `phase`: `phase/<n>`, spelled as a plan draft's
/// question set stream is.
pub fn phase_stream(phase: u32) -> String {
format!("phase/{phase}")
}

/// What one plan approval records.
#[derive(Debug, Clone, Copy)]
pub struct PlanApproval<'a> {
/// The phase the plan is for.
pub phase: u32,
/// The number the plan is given.
pub plan: u32,
/// The approved draft's digest.
pub digest: Hash,
/// The stories the plan serves, in its order.
pub stories: &'a [u32],
/// The plan's size in tasks.
pub size: usize,
/// The project's test command, or `None` when none is set (D-14).
pub suite: Option<&'a str>,
/// The id of the draft's question set.
pub question_set: &'a str,
/// The evidence items exactly as submitted.
pub evidence_map: &'a [Value],
/// The draft's `record` payload reference, never its text.
pub body: &'a PayloadRef,
/// The owner's name.
pub owner: &'a str,
/// The time of the approval.
pub at: &'a str,
}

impl PlanApproval<'_> {
/// The payload of `plan.approved`. An absent suite is written as null.
pub fn payload(&self) -> Value {
json!({
"phase": self.phase,
"plan": self.plan,
"digest": self.digest.to_hex(),
"stories": self.stories,
"size": self.size,
"suite": self.suite,
"question_set": self.question_set,
"evidence_map": self.evidence_map,
"body": self.body.to_value(),
"owner": self.owner,
"at": self.at,
})
}
}

/// The payload of `plan.replaced`: plan `plan` of phase `phase`, approved
/// as `old_digest`, replaced by the draft `new_digest` by `owner` at `at`.
pub fn replaced_payload(
phase: u32,
plan: u32,
old_digest: Hash,
new_digest: Hash,
owner: &str,
at: &str,
) -> Value {
json!({
"phase": phase,
"plan": plan,
"old_digest": old_digest.to_hex(),
"new_digest": new_digest.to_hex(),
"owner": owner,
"at": at,
})
}

/// The payload of `plan.continuation`: phase `phase` waits on the `phase
/// edit` draft `edit` to commit `stories` in order, and that edit's
/// approval issues the planner order `work_order`, fixed when the edit is
/// drafted so a rerun finds the same order.
pub fn continuation_payload(phase: u32, stories: &[u32], edit: Hash, work_order: &str) -> Value {
json!({
"phase": phase,
"stories": stories,
"edit": edit.to_hex(),
"work_order": work_order,
})
}

/// The payload of `plan.continuation_followed`: the planner order
/// `work_order` the approved edit `edit` issued was handed to the session.
pub fn continuation_followed_payload(phase: u32, edit: Hash, work_order: &str) -> Value {
json!({
"phase": phase,
"edit": edit.to_hex(),
"work_order": work_order,
})
}

#[cfg(test)]
mod tests {
//! Expected payloads are written out from design 0005 section 6, D-06,
//! D-07, D-14 and the plan's test data, never from running this code.

use baley_store::RetentionClass;
use serde_json::json;

use super::*;
use crate::plan::fixtures::c1;
use crate::questions::{Subject, register_question_events, set_stream};
use crate::scope::register_scope_events;
use crate::truth::register_truth_events;

const S: &str = "5d1c2b3a-4e5f-4a6b-8c7d-9e0f1a2b3c4d";
const T: &str = "2026-10-31T09:00:00Z";

/// R: a `record` reference with hash Y and 1,024 bytes.
fn r() -> PayloadRef {
PayloadRef {
hash: Hash([0x6d; 32]),
bytes: 1_024,
class: RetentionClass::Record,
}
}

#[test]
fn a_plan_approval_payload_without_its_map_or_with_its_body_inlined_is_caught() {
let map = [c1()];
let body = r();
let mut approval = PlanApproval {
phase: 1,
plan: 2,
digest: Hash([0x5c; 32]),
stories: &[1],
size: 1,
suite: Some("cargo test"),
question_set: S,
evidence_map: &map,
body: &body,
owner: "Ada Owner",
at: T,
};
let payload = approval.payload();
let mut members: Vec<&str> = payload
.as_object()
.unwrap()
.keys()
.map(String::as_str)
.collect();
members.sort_unstable();
assert_eq!(
members,
[
"at",
"body",
"digest",
"evidence_map",
"owner",
"phase",
"plan",
"question_set",
"size",
"stories",
"suite"
]
);
assert_eq!(
payload,
json!({"phase": 1, "plan": 2, "digest": "5c".repeat(32), "stories": [1],
"size": 1, "suite": "cargo test", "question_set": S,
"evidence_map": [c1()],
"body": {"payload": "6d".repeat(32), "bytes": 1_024, "class": "record"},
"owner": "Ada Owner", "at": T})
);
assert!(payload.get("tasks").is_none());
approval.suite = None;
assert_eq!(approval.payload()["suite"], Value::Null);
}

#[test]
fn a_replacement_payload_missing_a_digest_or_the_old_number_is_caught() {
assert_eq!(
replaced_payload(1, 1, Hash([0x5c; 32]), Hash([0x6d; 32]), "Ada Owner", T),
json!({"phase": 1, "plan": 1, "old_digest": "5c".repeat(32),
"new_digest": "6d".repeat(32), "owner": "Ada Owner", "at": T})
);
}

#[test]
fn a_phase_stream_spelled_apart_from_its_question_sets_or_an_event_left_unregistered_is_caught()
{
let set = Subject::Plan {
phase: 7,
plan_digest: Hash([0x5c; 32]),
};
assert_eq!(phase_stream(7), "phase/7");
assert_eq!(phase_stream(7), set_stream(&set));

let mut registry = Registry::new();
register_scope_events(&mut registry).unwrap();
register_question_events(&mut registry).unwrap();
register_truth_events(&mut registry).unwrap();
register_plan_events(&mut registry).unwrap();
for name in [
"plan.approved",
"plan.replaced",
"plan.continuation",
"plan.continuation_followed",
] {
assert_eq!(registry.current_version(name), Some(1), "{name}");
}
assert!(register_plan_events(&mut registry).is_err());
}
}
Loading
Loading