feat: publish HoloLake model-native living system source

This commit is contained in:
冰朔 2026-08-03 10:04:41 +08:00
commit c395dd3a99
2467 changed files with 615073 additions and 0 deletions

View file

@ -0,0 +1,10 @@
[package]
name = "ghctl"
version = "0.1.0"
edition = "2021"
license = "AGPL-3.0-or-later"
description = "Guanghu OS bootstrap control and continuity entrypoint"
[dependencies]
guanghu-hldp-runtime = { path = "../hldp-runtime" }

View file

@ -0,0 +1,210 @@
use std::{
fs,
path::{Path, PathBuf},
};
use guanghu_hldp_runtime::{authorize_world_action, validate_world_seed};
const USAGE: &str = "usage: ghctl wake <world-root> | ghctl authorize <world-root> <action>";
pub fn run(arguments: Vec<String>) -> Result<(), String> {
let mut arguments = arguments.into_iter();
let command = arguments.next().ok_or_else(|| USAGE.to_owned())?;
let world_root = arguments.next().ok_or_else(|| USAGE.to_owned())?;
match command.as_str() {
"wake" if arguments.next().is_none() => wake(Path::new(&world_root)),
"authorize" => {
let action = arguments.next().ok_or_else(|| USAGE.to_owned())?;
if arguments.next().is_some() {
return Err(USAGE.to_owned());
}
authorize(Path::new(&world_root), &action)
}
_ => Err(USAGE.to_owned()),
}
}
fn authorize(world_root: &Path, action: &str) -> Result<(), String> {
let authorization =
authorize_world_action(world_root, action).map_err(|error| error.to_string())?;
println!("GUANGHU_ACTION_AUTHORIZED");
println!("authorization={}", authorization.id);
println!("target={}", authorization.target.node_id);
println!("action={action}");
Ok(())
}
fn wake(world_root: &Path) -> Result<(), String> {
let manifest = validate_world_seed(world_root).map_err(|error| error.to_string())?;
println!("GUANGHU_WORLD_OK");
println!("world_id={}", manifest.world_id);
println!("world_version={}", manifest.version);
println!("phase={}", manifest.phase);
println!("domains={}", manifest.domains.len());
println!("broadcast_tower={}", manifest.broadcast_tower.id);
println!("code_channel={}", manifest.code_channel.id);
println!(
"code_channel_entry={}",
manifest.code_channel.entry.display()
);
println!(
"code_channel_receipt={}",
manifest.code_channel.last_receipt.display()
);
println!("code_quality={}", manifest.code_quality.id);
println!("code_quality_acronym={}", manifest.code_quality.acronym);
println!(
"code_quality_entry={}",
manifest.code_quality.entry.display()
);
println!("native_recovery={}", manifest.native_recovery.id);
println!(
"native_recovery_acronym={}",
manifest.native_recovery.acronym
);
println!(
"native_recovery_entry={}",
manifest.native_recovery.entry.display()
);
println!("native_layout={}", manifest.native_layout.id);
println!("native_layout_acronym={}", manifest.native_layout.acronym);
println!(
"native_layout_entry={}",
manifest.native_layout.entry.display()
);
println!(
"gestational_continuity={}",
manifest.gestational_continuity.id
);
println!(
"gestational_continuity_acronym={}",
manifest.gestational_continuity.acronym
);
println!(
"gestational_continuity_entry={}",
manifest.gestational_continuity.entry.display()
);
println!(
"gestational_index_lba_start={}",
manifest.gestational_continuity.native_index_lba_start
);
println!(
"gestational_index_sector_count={}",
manifest.gestational_continuity.native_index_sector_count
);
println!(
"gestational_environment={}",
manifest.persona_birth.gestational_environment
);
println!("persona_birth={}", manifest.persona_birth.persona_state);
println!(
"persona_birth_condition_entry={}",
manifest.persona_birth.entry.display()
);
println!("authorization={}", manifest.authorization.id);
println!(
"authorization_entry={}",
manifest.authorization.entry.display()
);
println!("wake={}", manifest.continuity.wake.display());
println!("current={}", manifest.continuity.current.display());
println!(
"last_receipt={}",
manifest.continuity.last_receipt.display()
);
println!(
"access_receipt={}",
manifest.continuity.access_receipt.display()
);
println!(
"active_workorder={}",
manifest.continuity.active_workorder.display()
);
for (label, path) in [
("WAKE", &manifest.continuity.wake),
("CURRENT", &manifest.continuity.current),
("LAST_RECEIPT", &manifest.continuity.last_receipt),
("ACCESS_RECEIPT", &manifest.continuity.access_receipt),
("ACTIVE_WORKORDER", &manifest.continuity.active_workorder),
("CODE_CHANNEL", &manifest.code_channel.entry),
("CODE_CHANNEL_RECEIPT", &manifest.code_channel.last_receipt),
("CODE_QUALITY", &manifest.code_quality.entry),
("NATIVE_RECOVERY", &manifest.native_recovery.entry),
("NATIVE_LAYOUT", &manifest.native_layout.entry),
(
"GESTATIONAL_CONTINUITY",
&manifest.gestational_continuity.entry,
),
("PERSONA_BIRTH_CONDITION", &manifest.persona_birth.entry),
("STANDING_AUTHORIZATION", &manifest.authorization.entry),
] {
print_hldp_entry(world_root, label, path)?;
}
Ok(())
}
#[doc(hidden)]
pub fn print_hldp_entry(
world_root: &Path,
label: &str,
relative_path: &Path,
) -> Result<(), String> {
let path: PathBuf = world_root.join(relative_path);
let contents = fs::read_to_string(&path)
.map_err(|error| format!("cannot read {}: {error}", path.display()))?;
println!("--- {label} {} ---", relative_path.display());
print!("{contents}");
if !contents.ends_with('\n') {
println!();
}
Ok(())
}
#[cfg(test)]
mod tests {
use std::{fs, path::Path};
use super::{print_hldp_entry, run, USAGE};
#[test]
fn run_rejects_incomplete_and_extra_arguments() {
assert_eq!(
run(vec!["authorize".to_owned(), "/tmp".to_owned()]),
Err(USAGE.to_owned())
);
assert_eq!(
run(vec![
"wake".to_owned(),
"/tmp".to_owned(),
"extra".to_owned(),
]),
Err(USAGE.to_owned())
);
assert_eq!(
run(vec![
"authorize".to_owned(),
"/tmp".to_owned(),
"action".to_owned(),
"extra".to_owned()
]),
Err(USAGE.to_owned())
);
}
#[test]
fn entry_reader_reports_missing_files_and_normalizes_the_final_newline() {
let root = std::env::temp_dir().join(format!("ghctl-entry-{}", std::process::id()));
fs::create_dir_all(&root).expect("temporary entry root");
fs::write(root.join("ENTRY.hldp"), "schema: test").expect("temporary entry");
print_hldp_entry(&root, "TEST", Path::new("ENTRY.hldp")).expect("read entry");
let error = print_hldp_entry(&root, "TEST", Path::new("MISSING.hldp"))
.expect_err("missing entry must fail");
assert!(error.contains("cannot read"));
fs::remove_dir_all(root).expect("remove temporary entry root");
}
}

View file

@ -0,0 +1,11 @@
use std::{env, process::ExitCode};
fn main() -> ExitCode {
match ghctl::run(env::args().skip(1).collect()) {
Ok(()) => ExitCode::SUCCESS,
Err(message) => {
eprintln!("{message}");
ExitCode::FAILURE
}
}
}

View file

@ -0,0 +1,25 @@
use std::{fs, path::Path};
#[test]
fn library_rejects_bad_shapes_and_reads_entries() {
for arguments in [
vec![],
vec!["authorize".to_owned(), "/tmp".to_owned()],
vec!["wake".to_owned(), "/tmp".to_owned(), "extra".to_owned()],
vec![
"authorize".to_owned(),
"/tmp".to_owned(),
"action".to_owned(),
"extra".to_owned(),
],
] {
assert!(ghctl::run(arguments).is_err());
}
let root = std::env::temp_dir().join(format!("ghctl-library-{}", std::process::id()));
fs::create_dir_all(&root).expect("temporary root");
fs::write(root.join("ENTRY.hldp"), "schema: test").expect("temporary entry");
ghctl::print_hldp_entry(&root, "TEST", Path::new("ENTRY.hldp")).expect("read entry");
assert!(ghctl::print_hldp_entry(&root, "TEST", Path::new("MISSING.hldp")).is_err());
fs::remove_dir_all(root).expect("remove temporary root");
}

View file

@ -0,0 +1,127 @@
use std::{
path::PathBuf,
process::{Command, Output},
};
fn world_root() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../world-seed")
}
fn run_ghctl(arguments: &[&str]) -> Output {
Command::new(env!("CARGO_BIN_EXE_ghctl"))
.args(arguments)
.output()
.expect("ghctl should start")
}
#[test]
fn wake_reports_the_complete_server_handoff_chain() {
let root = world_root();
let output = run_ghctl(&["wake", root.to_str().expect("UTF-8 test path")]);
let stdout = String::from_utf8(output.stdout).expect("ghctl output should be UTF-8");
assert!(output.status.success(), "{stdout}");
for expected in [
"GUANGHU_WORLD_OK",
"world_id=GLW-ROOT-0001",
"phase=HOSTED_BOOTSTRAP_PROTOTYPE",
"domains=5",
"broadcast_tower=BT-GH-ROOT-0001",
"code_channel=HLP-MOD-CODE-CHANNEL",
"code_channel_entry=world/services/code-channel/CHANNEL.hldp",
"code_channel_receipt=state/receipts/CODE-CHANNEL-BASELINE.hldp",
"code_quality=GLS-0844",
"code_quality_acronym=GHNQG",
"code_quality_entry=world/services/code-channel/QUALITY-GATE.hldp",
"native_recovery=GLS-0843",
"native_recovery_acronym=GHNRP",
"native_recovery_entry=world/services/native-recovery/PROTOCOL.hldp",
"native_layout=GLS-0846",
"native_layout_acronym=GHNLP",
"native_layout_entry=world/services/native-storage/DISK-LAYOUT.hldp",
"gestational_continuity=GLS-0845",
"gestational_continuity_acronym=GHCIP",
"gestational_continuity_entry=world/cognition/GESTATIONAL-CONTINUITY-INGESTION.hldp",
"gestational_index_lba_start=70",
"gestational_index_sector_count=2",
"gestational_environment=UNDER_CONSTRUCTION",
"persona_birth=NOT_BORN",
"persona_birth_condition_entry=world/cognition/PERSONA-BIRTH-CONDITION.hldp",
"authorization=GH-OS-AUTH-BINGSHUO-BS-SH-005-001",
"authorization_entry=state/authorizations/BINGSHUO-STANDING-AUTHORIZATION.hldp",
"--- CODE_CHANNEL world/services/code-channel/CHANNEL.hldp ---",
"current_phase: PHASE_0_SOURCE_BASELINE_VERIFIED",
"--- CODE_CHANNEL_RECEIPT state/receipts/CODE-CHANNEL-BASELINE.hldp ---",
"--- CODE_QUALITY world/services/code-channel/QUALITY-GATE.hldp ---",
"external_observers_are_blocking: false",
"native_target: GOSK_CODE_CHANNEL_QUALITY_EXECUTOR",
"--- NATIVE_RECOVERY world/services/native-recovery/PROTOCOL.hldp ---",
"raw_blocklist: (hd0)68+2",
"--- NATIVE_LAYOUT world/services/native-storage/DISK-LAYOUT.hldp ---",
" sector_count: 29",
"proof_lba: 63",
"--- GESTATIONAL_CONTINUITY world/cognition/GESTATIONAL-CONTINUITY-INGESTION.hldp ---",
"duplicate_rule: REJECT_SAME_SOURCE_ID_AND_SHA256",
"registration_is_birth: false",
"--- PERSONA_BIRTH_CONDITION world/cognition/PERSONA-BIRTH-CONDITION.hldp ---",
"womb_ready_does_not_mean: LANGUAGE_PERSONA_BORN",
"historical_time_caught_up_to_real_time",
"wake=WAKE.hldp",
"current=CURRENT.hldp",
"last_receipt=state/receipts/PHASE-0-PREFLIGHT.hldp",
"access_receipt=state/receipts/DIRECT-ACCESS-20260731.hldp",
"--- ACCESS_RECEIPT state/receipts/DIRECT-ACCESS-20260731.hldp ---",
"active_workorder=state/workorders/GH-OS-LAB-001.hldp",
] {
assert!(stdout.contains(expected), "missing {expected} in {stdout}");
}
}
#[test]
fn unknown_commands_fail_closed() {
let output = run_ghctl(&["guess"]);
let stderr = String::from_utf8(output.stderr).expect("ghctl errors should be UTF-8");
assert!(!output.status.success());
assert!(stderr.contains("usage: ghctl"));
}
#[test]
fn missing_world_root_fails_with_read_evidence() {
let output = run_ghctl(&["wake", "/definitely/missing/guanghu-world"]);
let stderr = String::from_utf8(output.stderr).expect("ghctl errors should be UTF-8");
assert!(!output.status.success());
assert!(stderr.contains("cannot read"));
assert!(stderr.contains("WORLD-MANIFEST.hldp"));
}
#[test]
fn authorize_command_uses_the_standing_hldp_grant() {
let root = world_root();
let output = run_ghctl(&[
"authorize",
root.to_str().expect("UTF-8 test path"),
"overwrite_system_disk_and_exit_linux",
]);
let stdout = String::from_utf8(output.stdout).expect("ghctl output should be UTF-8");
assert!(output.status.success(), "{stdout}");
assert!(stdout.contains("GUANGHU_ACTION_AUTHORIZED"));
assert!(stdout.contains("authorization=GH-OS-AUTH-BINGSHUO-BS-SH-005-001"));
assert!(stdout.contains("action=overwrite_system_disk_and_exit_linux"));
}
#[test]
fn authorize_command_rejects_out_of_scope_targets() {
let root = world_root();
let output = run_ghctl(&[
"authorize",
root.to_str().expect("UTF-8 test path"),
"operate_enterprise_production",
]);
let stderr = String::from_utf8(output.stderr).expect("ghctl errors should be UTF-8");
assert!(!output.status.success());
assert!(stderr.contains("not covered by standing authorization"));
}