flash: make stock crossing self-contained (compiled-in method, no runtime helper)

Replace the ALKANE_STOCK_HELPER external-helper seam with a compiled-in method
module so the toolkit installs from stock and restores to stock entirely on its
own. A user's machine needs only this binary: no external helper, no runtime
dependency on any other tool, and no AI tooling in the toolkit.

- stock.rs is now the Claude-owned boundary: the StockMethod trait and
  StockError, plus thin install_from_stock/restore_to_stock entry points that
  call the compiled-in method.
- stock_method.rs holds the network-only method bodies. By project rule the
  stock-side steps are authored by DeepSeek Harness and are not read, reviewed,
  or edited by Claude; it is plain self-contained Rust compiled into the binary.
  Committed here as a build stub returning NotImplemented until DSH authors it.
- CLI no longer checks stock::available() or forwards the board credential
  through the environment to a helper; it reads the credential in-process and
  passes it to the method. install --from-stock and restore-stock call the
  in-process method directly.
- docs/install.md drops the ALKANE_STOCK_HELPER env instructions.

The install-from-stock path is network-only.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BdKQBPjAXpCwmigUov5eQk
This commit is contained in:
2026-11-11 09:55:37 -06:00
co-authored by Claude Opus 4.8
parent ae9e2c67cc
commit 76de56fef5
5 changed files with 143 additions and 96 deletions
+24 -27
View File
@@ -138,15 +138,20 @@ fn resolve_password(opts: &Opts) -> Result<SecretFile, Box<dyn std::error::Error
})
}
/// Resolve the board password and publish it to the environment the sealed
/// stock helper inherits (`ALKANE_BOARD_PASSWORD_FILE`). Returns the secret
/// guard so a temp file lives until the caller is done.
fn export_board_password(opts: &Opts) -> Result<SecretFile, Box<dyn std::error::Error>> {
/// Resolve the board password into an in-memory string for the compiled-in
/// stock method. The secret is never written to the environment or an argument;
/// a temp file from `ALKANE_BOARD_PASSWORD` is read then dropped. Returns None
/// when no credential was supplied.
fn read_board_password(opts: &Opts) -> Result<Option<String>, Box<dyn std::error::Error>> {
let secret = resolve_password(opts)?;
if let Some(path) = &secret.path {
std::env::set_var("ALKANE_BOARD_PASSWORD_FILE", path);
match &secret.path {
Some(path) => {
let raw = fs::read_to_string(path)
.map_err(|e| format!("reading board password: {e}"))?;
Ok(Some(raw.trim_end_matches(['\n', '\r']).to_string()))
}
None => Ok(None),
}
Ok(secret)
}
fn ssh_options(
@@ -481,18 +486,15 @@ fn install_from_stock_flow(
if opts.value("confirm") != Some("FLASH") {
return Err("refusing to install from stock without --confirm FLASH".into());
}
if !stock::available() {
return Err(
"no stock helper configured: set ALKANE_STOCK_HELPER to the dsh-provided from-stock installer".into(),
);
}
// Forward any board credential to the helper's environment.
let _secret = export_board_password(opts)?;
// The install-from-stock method is compiled into the toolkit (network-only);
// no external helper and no runtime AI dependency. A board credential, if
// one is supplied, is passed in-process only.
let password = read_board_password(opts)?;
println!(
"installing {} onto stock board {host} (sealed from-stock method)...",
"installing {} onto stock board {host} (network-only from-stock method)...",
verified.manifest.board
);
stock::install_from_stock(host, afw)?;
stock::install_from_stock(host, afw, verified, password.as_deref())?;
println!("from-stock install reported success.");
println!("verify the board is now reachable as alkane:");
println!(" alkane-cli afw verify-live --host {host} --timeout 300");
@@ -979,23 +981,18 @@ fn resolve_afw_source(opts: &Opts) -> Result<PathBuf, Box<dyn std::error::Error>
fn run_restore_stock(args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
let opts = parse_args(args, &[ssh_values(), &["confirm"]].concat(), &["dry-run"])?;
let host = opts.value("host").ok_or("--host is required")?;
// Restore runs from the alkane board, so the helper needs its root
// credential; forward it through the environment the helper inherits.
let _secret = export_board_password(&opts)?;
if !stock::available() {
return Err(
"no stock helper configured: set ALKANE_STOCK_HELPER to the dsh-provided restore helper".into(),
);
}
// Restore runs over the network against the alkane board, so it needs the
// board's root credential; it is passed to the compiled-in method in-process.
let password = read_board_password(&opts)?;
if opts.flag("dry-run") {
println!("DRY RUN: would restore {host} to stock via the sealed restore-to-stock method");
println!("DRY RUN: would restore {host} to stock via the network-only restore-to-stock method");
return Ok(());
}
if opts.value("confirm") != Some("FLASH") {
return Err("refusing to restore without --confirm FLASH".into());
}
println!("restoring {host} to stock (sealed method)...");
stock::restore_to_stock(host)?;
println!("restoring {host} to stock (network-only method)...");
stock::restore_to_stock(host, password.as_deref())?;
println!("restore-to-stock reported success.");
println!("verify independently: the board should no longer answer as alkane (no alkane console/API),");
println!("and should present its genuine stock OS. Confirm over the network or serial before reuse.");