AppState (app/state.rs) is now lifecycle + EngineLink (client port, control channel, worker status, pool, queue timeout) + HttpPolicy (api key, CORS, trusted origins) + ModelView (name, aliases, tokenizer, template, vision port, prefix-cache and memory views) + Services (response store, monitor, MCP port, settings, clock, started_at). Field uses were rewritten mechanically (state.worker -> state.engine.worker, ...); no handler logic changed. The old impl_default_for_appstate.rs, which held the route table and the admin handlers, is app/routes.rs, app/admin_routes.rs and app/readiness.rs. main.rs (1156 lines: an 840-line argument match, the serve function, two helpers) is now 8 lines. The argument match is split into command groups under src/cli/ (operations, model_fetch, model_inspect, model_ensure, model_prepare, kar_inspect, kar_verify, kar_overlay, model_text; each owns its arms in their old order and answers Ok(false) for a line it does not own), serve() and shutdown_signal() are src/serve.rs (the composition root), the usage text is cli/usage.rs. The binary name and every command line are unchanged. Architecture gate: control-plane/src/main.rs leaves the oversize list (1156 -> 8). --allow-increase was used because the type change forces the AppState struct literals in seven already-oversize test/example files to nest by group: cp_replay.rs +7, responses/tests.rs +11, backend_worker_http.rs +14, mcp_hub.rs +3, memory_gate_http.rs +7, vision_http.rs +6, desktop-core api_over_runtime.rs +6 (55 lines in all, against 1148 lines removed from main.rs). Test outcomes are unchanged (597 ok / 2 ignored before and after, 14 new tests from S16).
136 lines
6.3 KiB
Rust
136 lines
6.3 KiB
Rust
//! `model` commands that read a GGUF file: metadata, tensor index and the derived identities.
|
|
|
|
use std::path::Path;
|
|
|
|
use strata_control::{BoxError, derived_iq3, derived_mixed, gguf, model};
|
|
|
|
/// Run the command in `args` if this group owns it; `Ok(false)` when it does not.
|
|
pub async fn run(args: &[String]) -> Result<bool, BoxError> {
|
|
let handled: Result<(), BoxError> = match args {
|
|
[model, action, path] if model == "model" && action == "inspect-metadata" => {
|
|
// Every key/value as one JSON object; non-finite floats are the strings "nan", "inf", "-inf".
|
|
let entries = gguf::metadata_entries(Path::new(path))?;
|
|
println!("{}", strata_control::gguf_json::metadata_json(entries));
|
|
Ok(())
|
|
}
|
|
[model, action, path] if model == "model" && action == "inspect" => {
|
|
let summary = gguf::inspect(Path::new(path))?;
|
|
println!("GGUF v3: {path}");
|
|
println!("size: {} bytes", summary.file_size);
|
|
println!(
|
|
"tensors: {}; metadata: {}",
|
|
summary.tensors, summary.metadata
|
|
);
|
|
println!("data starts at byte {}", summary.data_start);
|
|
if let Some(architecture) = summary.architecture {
|
|
println!("architecture: {architecture}");
|
|
}
|
|
if let (Some(no), Some(count)) = (summary.split_no, summary.split_count) {
|
|
println!("split: {}/{}", no + 1, count);
|
|
}
|
|
println!("tensor types: {:?}", summary.types);
|
|
Ok(())
|
|
}
|
|
[model, action, path] if model == "model" && action == "index" => {
|
|
print_tensor_index(Path::new(path), false)
|
|
}
|
|
[model, action, path, hash_flag]
|
|
if model == "model" && action == "index" && hash_flag == "--hash" =>
|
|
{
|
|
print_tensor_index(Path::new(path), true)
|
|
}
|
|
[model, action, path] if model == "model" && action == "derive-iq3-identity" => {
|
|
let identity = derived_iq3::fingerprint(Path::new(path))?;
|
|
println!(
|
|
"{}",
|
|
serde_json::to_string_pretty(&serde_json::json!({
|
|
"derivation": "strata-next/iq3_s-to-f32-le-v1",
|
|
"gguf_sha256": hex::encode(identity.gguf_sha256),
|
|
"derived_f32_sha256": hex::encode(identity.derived_sha256),
|
|
"derived_f32_bytes": identity.derived_bytes,
|
|
"tensors": identity.tensors.iter().map(|tensor| serde_json::json!({
|
|
"name": tensor.name,
|
|
"derived_offset": tensor.derived_offset,
|
|
"derived_bytes": tensor.derived_bytes,
|
|
"iq3_sha256": hex::encode(tensor.iq3_sha256),
|
|
"f32_sha256": hex::encode(tensor.f32_sha256),
|
|
})).collect::<Vec<_>>(),
|
|
}))?
|
|
);
|
|
Ok(())
|
|
}
|
|
[model, action, path] if model == "model" && action == "derive-mixed-identity" => {
|
|
let identity = derived_mixed::fingerprint(Path::new(path))?;
|
|
println!(
|
|
"{}",
|
|
serde_json::to_string_pretty(&serde_json::json!({
|
|
"derivation": "strata-next/gguf-mixed-to-f32-le-v1",
|
|
"gguf_sha256": hex::encode(identity.gguf_sha256),
|
|
"derived_f32_sha256": hex::encode(identity.derived_sha256),
|
|
"derived_f32_bytes": identity.derived_bytes,
|
|
"tensors": identity.tensors.iter().map(|tensor| serde_json::json!({
|
|
"name": tensor.name,
|
|
"source_kind": tensor.source_kind,
|
|
"source_sha256": hex::encode(tensor.source_sha256),
|
|
"derived_offset": tensor.derived_offset,
|
|
"derived_bytes": tensor.derived_bytes,
|
|
"f32_sha256": hex::encode(tensor.f32_sha256),
|
|
})).collect::<Vec<_>>(),
|
|
}))?
|
|
);
|
|
Ok(())
|
|
}
|
|
[model, action, manifest_spec, source_flag, source_dir]
|
|
if model == "model"
|
|
&& action == "derive-sharded-identity"
|
|
&& source_flag == "--source-dir" =>
|
|
{
|
|
let manifest = model::Manifest::from_spec(manifest_spec).await?;
|
|
let identity = derived_mixed::fingerprint_shards(&manifest, Path::new(source_dir))?;
|
|
println!(
|
|
"{}",
|
|
serde_json::to_string_pretty(&serde_json::json!({
|
|
"derivation": "strata-next/gguf-shards-to-f32-le-v1",
|
|
"derived_f32_sha256": hex::encode(identity.derived_sha256),
|
|
"derived_f32_bytes": identity.derived_bytes,
|
|
"shards": identity.shards.iter().map(|shard| serde_json::json!({
|
|
"name": shard.name,
|
|
"gguf_sha256": hex::encode(shard.gguf_sha256),
|
|
"gguf_bytes": shard.gguf_bytes,
|
|
"tensor_count": shard.tensor_count,
|
|
})).collect::<Vec<_>>(),
|
|
"tensors": identity.tensors.iter().map(|tensor| serde_json::json!({
|
|
"name": tensor.name,
|
|
"source_kind": tensor.source_kind,
|
|
"source_sha256": hex::encode(tensor.source_sha256),
|
|
"derived_offset": tensor.derived_offset,
|
|
"derived_bytes": tensor.derived_bytes,
|
|
"f32_sha256": hex::encode(tensor.f32_sha256),
|
|
})).collect::<Vec<_>>(),
|
|
}))?
|
|
);
|
|
Ok(())
|
|
}
|
|
_ => return Ok(false),
|
|
};
|
|
handled.map(|()| true)
|
|
}
|
|
|
|
fn print_tensor_index(path: &Path, hash: bool) -> Result<(), BoxError> {
|
|
let index = gguf::tensor_index(path)?;
|
|
for (number, tensor) in index.tensors.iter().enumerate() {
|
|
let mut row = serde_json::json!({
|
|
"name": tensor.name,
|
|
"dimensions": tensor.dimensions,
|
|
"type": tensor.kind,
|
|
"offset": index.summary.data_start + tensor.offset,
|
|
"bytes": tensor.bytes,
|
|
});
|
|
if hash {
|
|
row["sha256"] = hex::encode(gguf::tensor_sha256(path, &index, number)?).into();
|
|
}
|
|
println!("{row}");
|
|
}
|
|
Ok(())
|
|
}
|