refactor(construction_depth): Phase B language-advantage pass — dichotomy wave

This commit is contained in:
Nick committed 2026-10-12 18:13:11 +01:00
1 parent 265bb509a7
commit b8b14d5be6
1 file changed
+178 -128
+178 -128
View File
@@ -58,6 +58,90 @@ impl Depth {
}
}
/// The five depth levels (oracle LEVELS).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Level {
None,
Unresolved,
Light,
Standard,
Full,
}
impl Level {
pub fn as_str(self) -> &'static str {
match self {
Level::None => "NONE",
Level::Unresolved => "UNRESOLVED",
Level::Light => "LIGHT",
Level::Standard => "STANDARD",
Level::Full => "FULL",
}
}
}
/// The construction modes the kernel discriminates. Any non-canonical mode
/// string falls through to the EXISTING_PROJECT_CHANGE path (oracle
/// behavior: the default branch is the escalation path).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum Mode {
NotConstruction,
Unknown,
LocalChange,
ProjectBuild,
ExistingProjectChange,
}
impl Mode {
fn parse(s: &str) -> Self {
match s {
"NOT_CONSTRUCTION" => Self::NotConstruction,
"UNKNOWN" => Self::Unknown,
"LOCAL_CHANGE" => Self::LocalChange,
"PROJECT_BUILD" => Self::ProjectBuild,
_ => Self::ExistingProjectChange,
}
}
}
const LOCAL_CEREMONY: [&str; 4] = [
"classification",
"authority/scope",
"focused verification",
"durable result",
];
const LOCAL_BYPASSED: [&str; 5] = [
"requirements/completeness",
"patterns",
"capability/toolchain check",
"project bootstrap",
"deployment/rollback",
];
const BUILD_CEREMONY: [&str; 9] = [
"project bootstrap",
"requirements/completeness",
"capability/toolchain decisions",
"patterns/obligations",
"Construction Contract",
"implementation",
"verification",
"deployment/rollback strategy",
"maintenance lifecycle",
];
const EPC_CEREMONY: [&str; 7] = [
"classification",
"requirements/completeness",
"capability fit",
"Construction Contract",
"scope",
"obligations",
"verification",
];
fn owned(v: &[&str]) -> Vec<String> {
v.iter().map(|s| (*s).to_string()).collect()
}
/// Oracle-exact depth selection: mode gates the lifecycle shape, evidence
/// modifiers escalate within EXISTING_PROJECT_CHANGE. Mirrors the Python
/// oracle branch-for-branch (batch 125 + facade-burn divergence fixes).
@@ -72,137 +156,103 @@ pub fn select_depth(
external_service: bool,
uncertainty: &str,
) -> Depth {
if mode == "NOT_CONSTRUCTION" {
// §13C: NOT_CONSTRUCTION has NO construction depth — not even LIGHT
return Depth {
level: "NONE".into(),
reason: "not construction — no construction depth applies".into(),
evidence: vec![format!("mode: {mode}")],
ceremony: vec![],
bypassed: vec!["all".into()],
};
}
if mode == "UNKNOWN" {
// §13C: UNKNOWN means construction hasn't started — no lifecycle yet
return Depth {
level: "UNRESOLVED".into(),
reason: "UNKNOWN — probe/clarify before any construction lifecycle begins".into(),
evidence: vec![format!("mode: {mode}")],
ceremony: vec!["probe/clarify".into()],
bypassed: vec![
"contract".into(),
"patterns".into(),
"bootstrap".into(),
"depth selection".into(),
],
};
}
if mode == "LOCAL_CHANGE" {
let mut ev = vec![format!("mode: {mode}")];
ev.push("LOCAL_CHANGE: bounded scope, minimal ceremony".into());
let mut ceremony = vec![
"classification".to_string(),
"authority/scope".to_string(),
"focused verification".to_string(),
"durable result".to_string(),
];
let bypassed = vec![
"requirements/completeness".to_string(),
"patterns".to_string(),
"capability/toolchain check".to_string(),
"project bootstrap".to_string(),
"deployment/rollback".to_string(),
];
if user_locked_layout {
ev.push(
"USER-LOCKED layout surface — preservation obligation retained even at LIGHT depth"
.into(),
);
ceremony.push("layout obligation check".into());
match Mode::parse(mode) {
Mode::NotConstruction => {
// §13C: NOT_CONSTRUCTION has NO construction depth — not even LIGHT
Depth {
level: Level::None.as_str().into(),
reason: "not construction — no construction depth applies".into(),
evidence: vec![format!("mode: {mode}")],
ceremony: vec![],
bypassed: vec!["all".into()],
}
}
return Depth {
level: "LIGHT".into(),
reason: "bounded local fix — governance without ceremony".into(),
evidence: ev,
ceremony,
bypassed,
};
}
if mode == "PROJECT_BUILD" {
let mut ev = vec![format!("mode: {mode}")];
ev.push("PROJECT_BUILD: full lifecycle required".into());
return Depth {
level: "FULL".into(),
reason: "genuinely new project — full Scaffolding lifecycle".into(),
evidence: ev,
ceremony: vec![
"project bootstrap".to_string(),
"requirements/completeness".to_string(),
"capability/toolchain decisions".to_string(),
"patterns/obligations".to_string(),
"Construction Contract".to_string(),
"implementation".to_string(),
"verification".to_string(),
"deployment/rollback strategy".to_string(),
"maintenance lifecycle".to_string(),
],
bypassed: vec![],
};
}
Mode::Unknown => {
// §13C: UNKNOWN means construction hasn't started — no lifecycle yet
Depth {
level: Level::Unresolved.as_str().into(),
reason: "UNKNOWN — probe/clarify before any construction lifecycle begins".into(),
evidence: vec![format!("mode: {mode}")],
ceremony: vec!["probe/clarify".into()],
bypassed: owned(&["contract", "patterns", "bootstrap", "depth selection"]),
}
}
Mode::LocalChange => {
let mut ev = vec![format!("mode: {mode}")];
ev.push("LOCAL_CHANGE: bounded scope, minimal ceremony".into());
let mut ceremony = owned(&LOCAL_CEREMONY);
if user_locked_layout {
ev.push(
"USER-LOCKED layout surface — preservation obligation retained even at LIGHT depth"
.into(),
);
ceremony.push("layout obligation check".into());
}
Depth {
level: Level::Light.as_str().into(),
reason: "bounded local fix — governance without ceremony".into(),
evidence: ev,
ceremony,
bypassed: owned(&LOCAL_BYPASSED),
}
}
Mode::ProjectBuild => {
let mut ev = vec![format!("mode: {mode}")];
ev.push("PROJECT_BUILD: full lifecycle required".into());
Depth {
level: Level::Full.as_str().into(),
reason: "genuinely new project — full Scaffolding lifecycle".into(),
evidence: ev,
ceremony: owned(&BUILD_CEREMONY),
bypassed: vec![],
}
}
Mode::ExistingProjectChange => {
// base STANDARD, escalate on modifiers
let mut ev = vec![format!("mode: {mode}")];
let mut ceremony = owned(&EPC_CEREMONY);
let mut level = Level::Standard;
let mut reason = "existing-project change — proportional governance".to_string();
// EXISTING_PROJECT_CHANGE (and any non-canonical mode): base STANDARD,
// escalate on modifiers.
let mut ev = vec![format!("mode: {mode}")];
let mut ceremony = vec![
"classification".to_string(),
"requirements/completeness".to_string(),
"capability fit".to_string(),
"Construction Contract".to_string(),
"scope".to_string(),
"obligations".to_string(),
"verification".to_string(),
];
let bypassed: Vec<String> = vec![];
let mut level = "STANDARD";
let mut reason = "existing-project change — proportional governance".to_string();
if has_migration {
ev.push("migration: old/new compatibility + rollback obligations".into());
ceremony.push("migration proof".into());
ceremony.push("rollback preparation".into());
}
if breaking {
ev.push("breaking change: stronger approval + regression obligations".into());
ceremony.push("consumer migration completeness".into());
}
if user_locked_layout {
ev.push("USER-LOCKED layout surface affected".into());
ceremony.push("layout obligation check".into());
}
if external_service {
ev.push("external service consequence".into());
ceremony.push("deployment verification".into());
}
if uncertainty == "high" {
ev.push("high uncertainty: probe before deeper ceremony".into());
ceremony.insert(0, "evidence probe".into());
}
if affected_surface_len > 5 {
ev.push(format!("wide affected surface: {affected_surface_len} entries"));
level = Level::Full;
reason = "wide surface — full depth warranted".into();
}
if breaking && has_migration {
level = Level::Full;
reason = "breaking + migration — full depth".into();
}
if has_migration {
ev.push("migration: old/new compatibility + rollback obligations".into());
ceremony.push("migration proof".into());
ceremony.push("rollback preparation".into());
}
if breaking {
ev.push("breaking change: stronger approval + regression obligations".into());
ceremony.push("consumer migration completeness".into());
}
if user_locked_layout {
ev.push("USER-LOCKED layout surface affected".into());
ceremony.push("layout obligation check".into());
}
if external_service {
ev.push("external service consequence".into());
ceremony.push("deployment verification".into());
}
if uncertainty == "high" {
ev.push("high uncertainty: probe before deeper ceremony".into());
ceremony.insert(0, "evidence probe".into());
}
if affected_surface_len > 5 {
ev.push(format!("wide affected surface: {affected_surface_len} entries"));
level = "FULL";
reason = "wide surface — full depth warranted".into();
}
if breaking && has_migration {
level = "FULL";
reason = "breaking + migration — full depth".into();
}
Depth {
level: level.into(),
reason,
evidence: ev,
ceremony,
bypassed,
Depth {
level: level.as_str().into(),
reason,
evidence: ev,
ceremony,
bypassed: vec![],
}
}
}
}