From cf8514da6df2d6e4805f0d20ecd65d6c525450a4 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Mar 2026 01:27:29 +0000 Subject: [PATCH 1/2] TL-14, TL-15: Multi-target transport config emit + substrate cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TL-14: Multi-target emit — emit transport middleware configuration per target language. Adds emit functions for Rust (Target SDK constructors), Go (struct literals), C (static const structs), and MIPS (data section). Each bundle emitter now produces inline middleware config and a JSON manifest file alongside generated code. The Protobuf/gRPC pattern: .dag declares domain policy, compiler emits config, runtime consumes it. TL-15: Substrate cleanup — lib/transport/ becomes pure Target SDK. Removes all hardcoded provider-specific error parsing (parse_github_error, parse_gcp_error, parse_anthropic_error, parse_openai_error) and the ProviderDiagnostics struct from classify.rs. Error extraction now uses only the error_shape JSON-path rules from TL-16. The parse_provider_error_shapes fallback is eliminated; the field is retained in the IR struct for serialization backward compat but is always false. Lane 2 is now fully complete (all 25 tasks done). https://claude.ai/code/session_01ChHSbjrUYfHYWXrRgxLQwF --- core/daglang/daglang-emit/src/lib.rs | 111 +++- core/daglang/daglang-emit/src/service_emit.rs | 594 ++++++++++++++++++ core/daglang/daglang-lower/src/lib.rs | 5 +- core/ir/src/transport/middleware.rs | 35 +- lib/transport/src/classify.rs | 244 +++---- tasks.md | 11 +- 6 files changed, 839 insertions(+), 161 deletions(-) diff --git a/core/daglang/daglang-emit/src/lib.rs b/core/daglang/daglang-emit/src/lib.rs index 594878fcd74..264a56b4540 100644 --- a/core/daglang/daglang-emit/src/lib.rs +++ b/core/daglang/daglang-emit/src/lib.rs @@ -321,6 +321,16 @@ pub fn emit_rust_bundle( } } + // TL-14: Also collect symbols for middleware config emission. + let (rust_symbols, _, _) = collect_symbols_with_metadata(dag)?; + let rust_middleware_funcs = + emit_middleware_inline_funcs(&rust_symbols, service_emit::emit_rust_middleware_config); + if !rust_middleware_funcs.is_empty() { + emitted_functions.push(format!( + "// Transport middleware configuration (TL-14).\n{rust_middleware_funcs}" + )); + } + let module_count = artifacts.tool_metadata.modules.len(); let manifest_rendered = render_manifest(&artifacts.manifest); @@ -345,6 +355,10 @@ pub fn emit_rust_bundle( content: backend.emit_progress_manifest(&manifest_rendered), }, ]; + // TL-14: Emit middleware config JSON manifest. + if let Some(manifest) = emit_middleware_manifest("rust", &rust_symbols) { + files.push(manifest); + } if let Some(test_file) = test_gen::emit_dry_run_completion_test("rust", &artifacts.obligations) { files.push(test_file); @@ -383,7 +397,7 @@ pub fn emit_go_bundle( let has_service_transport = symbols.iter().any(|s| s.spec.is_some()); - let symbol_funcs = symbols + let mut symbol_funcs = symbols .iter() .map(|sym| { if let Some(ref spec) = sym.spec { @@ -401,6 +415,14 @@ pub fn emit_go_bundle( .collect::>() .join("\n"); + // TL-14: Append inline Go middleware config functions. + let go_middleware_funcs = + emit_middleware_inline_funcs(&symbols, service_emit::emit_go_middleware_config); + if !go_middleware_funcs.is_empty() { + symbol_funcs.push_str("\n// Transport middleware configuration (TL-14).\n"); + symbol_funcs.push_str(&go_middleware_funcs); + } + let entrypoint_lits = entrypoints .iter() .map(|entry| format!("\"{entry}\"")) @@ -450,6 +472,10 @@ pub fn emit_go_bundle( content: manifest_rendered, }, ]; + // TL-14: Emit middleware config JSON manifest. + if let Some(manifest) = emit_middleware_manifest("go", &symbols) { + files.push(manifest); + } if let Some(test_file) = test_gen::emit_dry_run_completion_test("go", &artifacts.obligations) { files.push(test_file); } @@ -501,6 +527,15 @@ pub fn emit_c_bundle( .collect::>() .join("\n"); + // TL-14: Emit inline C middleware config structs. + let c_middleware_funcs = + emit_middleware_inline_funcs(&symbols, service_emit::emit_c_middleware_config); + let symbol_funcs = if c_middleware_funcs.is_empty() { + symbol_funcs + } else { + format!("{symbol_funcs}\n/* Transport middleware configuration (TL-14). */\n{c_middleware_funcs}\n") + }; + let entrypoint_defs = entrypoints .iter() .map(|entry| format!("\"{entry}\"")) @@ -541,6 +576,10 @@ pub fn emit_c_bundle( content: manifest_rendered, }, ]; + // TL-14: Emit middleware config JSON manifest. + if let Some(manifest) = emit_middleware_manifest("c", &symbols) { + files.push(manifest); + } if let Some(test_file) = test_gen::emit_dry_run_completion_test("c", &artifacts.obligations) { files.push(test_file); } @@ -585,6 +624,10 @@ pub fn emit_mips_bundle( .collect::>() .join("\n"); + // TL-14: Emit inline MIPS middleware config data. + let mips_middleware_data = + emit_middleware_inline_funcs(&symbols, service_emit::emit_mips_middleware_config); + let main_s = if has_makegen_asset { let content = require_embedded_asset(embedded_data, "mips", MAKEGEN_ASSET_KEY)? .content @@ -596,9 +639,11 @@ pub fn emit_mips_bundle( .collect::>() .join(", "); format!( - ".text\n.globl main\n\n{label_defs}\nmain:\n li $a0, 1\n la $a1, makegen_content\n li $a2, {}\n li $v0, 4004\n syscall\n li $a0, 0\n li $v0, 4001\n syscall\n\n.data\nmakegen_content:\n .byte {makefile_bytes}\n", + ".text\n.globl main\n\n{label_defs}\nmain:\n li $a0, 1\n la $a1, makegen_content\n li $a2, {}\n li $v0, 4004\n syscall\n li $a0, 0\n li $v0, 4001\n syscall\n\n.data\nmakegen_content:\n .byte {makefile_bytes}\n{mips_middleware_data}", content.len() ) + } else if !mips_middleware_data.is_empty() { + format!(".text\n.globl main\n\n{label_defs}\nmain:\n li $v0, 10\n syscall\n\n.data\n{mips_middleware_data}") } else { format!(".text\n.globl main\n\n{label_defs}\nmain:\n li $v0, 10\n syscall\n") }; @@ -613,6 +658,10 @@ pub fn emit_mips_bundle( content: manifest_rendered, }, ]; + // TL-14: Emit middleware config JSON manifest. + if let Some(manifest) = emit_middleware_manifest("mips", &symbols) { + files.push(manifest); + } if let Some(test_file) = test_gen::emit_dry_run_completion_test("mips", &artifacts.obligations) { files.push(test_file); @@ -639,6 +688,64 @@ struct CollectedSymbol { service_phase: Option, } +/// Collect middleware configs from symbols for JSON manifest emission (TL-14). +/// +/// Returns a list of (operation_name, config) pairs, deduplicated to one entry +/// per operation (prepare/execute/parse share the same spec). +fn collect_middleware_configs( + symbols: &[CollectedSymbol], +) -> Vec<(String, &gunbc_ir::transport::TransportMiddlewareConfig)> { + let mut seen = HashSet::new(); + let mut configs = Vec::new(); + for sym in symbols { + if sym.service_phase != Some(service_emit::ServiceTransportPhase::Prepare) { + continue; + } + let middleware = sym + .spec + .as_ref() + .and_then(service_emit::extract_middleware); + if let Some(mw) = middleware { + if seen.insert(&sym.name) { + configs.push((sym.name.clone(), mw)); + } + } + } + configs +} + +/// Emit middleware config as an additional JSON manifest file (TL-14). +fn emit_middleware_manifest( + backend: &str, + symbols: &[CollectedSymbol], +) -> Option { + let configs = collect_middleware_configs(symbols); + if configs.is_empty() { + return None; + } + let json = service_emit::serialize_middleware_config_json(&configs); + Some(EmittedFile { + path: format!("target/generated/{backend}/transport_middleware.json"), + content: json, + }) +} + +/// Emit inline middleware config functions for a specific backend (TL-14). +fn emit_middleware_inline_funcs( + symbols: &[CollectedSymbol], + emit_fn: fn(&str, &gunbc_ir::transport::TransportMiddlewareConfig) -> String, +) -> String { + let configs = collect_middleware_configs(symbols); + if configs.is_empty() { + return String::new(); + } + configs + .iter() + .map(|(name, config)| emit_fn(name, config)) + .collect::>() + .join("\n") +} + fn collect_symbols_with_metadata( dag: &ReachableDag, ) -> Result<(Vec, usize, usize), EmitError> { diff --git a/core/daglang/daglang-emit/src/service_emit.rs b/core/daglang/daglang-emit/src/service_emit.rs index 064810521c7..0e71e529391 100644 --- a/core/daglang/daglang-emit/src/service_emit.rs +++ b/core/daglang/daglang-emit/src/service_emit.rs @@ -17,6 +17,9 @@ use daglang_lower::{ ArgvSegment, FieldSpec, RestOperationSpec, ServiceOperationSpec, ShellOperationSpec, ShellOutputParsing, }; +use gunbc_ir::transport::middleware::{ + RateLimitAlgorithm, RetryBackoff, TransportMiddlewareConfig, +}; /// Explicit service transport phase for generated operation nodes. /// @@ -698,6 +701,411 @@ fn c_path_args(template: &str, _fields: &[FieldSpec]) -> String { args.join(", ") } +// =========================================================================== +// Multi-target transport middleware config emission (TL-14) +// =========================================================================== + +/// Extract `TransportMiddlewareConfig` from a `ServiceOperationSpec`, if present. +pub fn extract_middleware(spec: &ServiceOperationSpec) -> Option<&TransportMiddlewareConfig> { + match spec { + ServiceOperationSpec::Rest(rest) => rest.middleware.as_ref(), + _ => None, + } +} + +/// Emit a Rust function that constructs `TransportMiddlewareConfig` for an operation. +/// +/// The generated code links to the Target SDK types from `gunbc_ir::transport::middleware`. +pub fn emit_rust_middleware_config( + op_name: &str, + config: &TransportMiddlewareConfig, +) -> String { + let mut out = String::new(); + out.push_str(&format!( + "/// Transport middleware configuration for `{op_name}`.\n\ + pub fn {op_name}_middleware_config() -> gunbc_ir::transport::middleware::TransportMiddlewareConfig {{\n\ + " + )); + out.push_str(" gunbc_ir::transport::middleware::TransportMiddlewareConfig {\n"); + + // Rate limit. + if let Some(ref rl) = config.rate_limit { + let algo = match rl.algorithm { + RateLimitAlgorithm::TokenBucket => "TokenBucket", + RateLimitAlgorithm::SlidingWindow => "SlidingWindow", + }; + out.push_str(&format!( + " rate_limit: Some(gunbc_ir::transport::middleware::RateLimitConfig {{\n\ + \x20 scope_key: \"{scope_key}\".to_string(),\n\ + \x20 algorithm: gunbc_ir::transport::middleware::RateLimitAlgorithm::{algo},\n\ + \x20 max_burst: {max_burst},\n\ + \x20 requests: {requests},\n\ + \x20 window_seconds: {window_seconds},\n\ + \x20 honor_retry_after: {honor_retry_after},\n\ + \x20 }}),\n", + scope_key = rl.scope_key, + max_burst = rl.max_burst, + requests = rl.requests, + window_seconds = rl.window_seconds, + honor_retry_after = rl.honor_retry_after, + )); + } else { + out.push_str(" rate_limit: None,\n"); + } + + // Retry. + if let Some(ref retry) = config.retry { + let backoff = match retry.backoff { + RetryBackoff::Fixed => "Fixed", + RetryBackoff::Exponential => "Exponential", + RetryBackoff::ExponentialJitter => "ExponentialJitter", + }; + let statuses = retry + .retry_statuses + .iter() + .map(std::string::ToString::to_string) + .collect::>() + .join(", "); + out.push_str(&format!( + " retry: Some(gunbc_ir::transport::middleware::RetryConfig {{\n\ + \x20 max_attempts: {max_attempts},\n\ + \x20 base_delay_ms: {base_delay_ms},\n\ + \x20 max_delay_ms: {max_delay_ms},\n\ + \x20 backoff: gunbc_ir::transport::middleware::RetryBackoff::{backoff},\n\ + \x20 retry_statuses: vec![{statuses}],\n\ + \x20 retry_network_errors: {retry_network_errors},\n\ + \x20 require_idempotent_or_readonly: {require_idempotent},\n\ + \x20 circuit_breaker: None,\n\ + \x20 }}),\n", + max_attempts = retry.max_attempts, + base_delay_ms = retry.base_delay_ms, + max_delay_ms = retry.max_delay_ms, + retry_network_errors = retry.retry_network_errors, + require_idempotent = retry.require_idempotent_or_readonly, + )); + } else { + out.push_str(" retry: None,\n"); + } + + // Credential. + out.push_str(" credential: None,\n"); + + // Response classification with error shape. + if let Some(ref rc) = config.response_classification { + out.push_str( + " response_classification: Some(gunbc_ir::transport::middleware::ResponseClassification {\n", + ); + out.push_str(&format!( + " provider: gunbc_ir::transport::middleware::ResponseProvider::{provider},\n", + provider = rust_response_provider_variant(rc.provider), + )); + out.push_str(&format!( + " prioritize_auth_errors: {pae},\n", + pae = rc.prioritize_auth_errors, + )); + out.push_str(&format!( + " parse_provider_error_shapes: {ppes},\n", + ppes = rc.parse_provider_error_shapes, + )); + if let Some(ref shape) = rc.error_shape { + out.push_str( + " error_shape: Some(gunbc_ir::transport::middleware::ErrorShapeExtraction {\n", + ); + out.push_str(&format!( + " message_path: \"{}\".to_string(),\n", + shape.message_path, + )); + if let Some(ref cp) = shape.code_path { + out.push_str(&format!( + " code_path: Some(\"{}\".to_string()),\n", + cp, + )); + } else { + out.push_str(" code_path: None,\n"); + } + if let Some(ref dp) = shape.details_path { + out.push_str(&format!( + " details_path: Some(\"{}\".to_string()),\n", + dp, + )); + } else { + out.push_str(" details_path: None,\n"); + } + out.push_str(" }),\n"); + } else { + out.push_str(" error_shape: None,\n"); + } + out.push_str(" }),\n"); + } else { + out.push_str(" response_classification: None,\n"); + } + + out.push_str(" }\n"); + out.push_str("}\n"); + out +} + +/// Emit a Go struct literal returning `TransportMiddlewareConfig` for an operation. +pub fn emit_go_middleware_config( + op_name: &str, + config: &TransportMiddlewareConfig, +) -> String { + let mut out = String::new(); + out.push_str(&format!( + "// {op_name}MiddlewareConfig returns the transport middleware configuration.\n\ + func {op_name}MiddlewareConfig() TransportMiddlewareConfig {{\n\ + \treturn TransportMiddlewareConfig{{\n" + )); + + // Rate limit. + if let Some(ref rl) = config.rate_limit { + let algo = match rl.algorithm { + RateLimitAlgorithm::TokenBucket => "TokenBucket", + RateLimitAlgorithm::SlidingWindow => "SlidingWindow", + }; + out.push_str(&format!( + "\t\tRateLimit: &RateLimitConfig{{\n\ + \t\t\tScopeKey: \"{scope_key}\",\n\ + \t\t\tAlgorithm: \"{algo}\",\n\ + \t\t\tMaxBurst: {max_burst},\n\ + \t\t\tRequests: {requests},\n\ + \t\t\tWindowSeconds: {window_seconds},\n\ + \t\t\tHonorRetryAfter: {honor_retry_after},\n\ + \t\t}},\n", + scope_key = rl.scope_key, + max_burst = rl.max_burst, + requests = rl.requests, + window_seconds = rl.window_seconds, + honor_retry_after = rl.honor_retry_after, + )); + } + + // Retry. + if let Some(ref retry) = config.retry { + let backoff = match retry.backoff { + RetryBackoff::Fixed => "fixed", + RetryBackoff::Exponential => "exponential", + RetryBackoff::ExponentialJitter => "exponential_jitter", + }; + let statuses = retry + .retry_statuses + .iter() + .map(std::string::ToString::to_string) + .collect::>() + .join(", "); + out.push_str(&format!( + "\t\tRetry: &RetryConfig{{\n\ + \t\t\tMaxAttempts: {max_attempts},\n\ + \t\t\tBaseDelayMs: {base_delay_ms},\n\ + \t\t\tMaxDelayMs: {max_delay_ms},\n\ + \t\t\tBackoff: \"{backoff}\",\n\ + \t\t\tRetryStatuses: []int{{{statuses}}},\n\ + \t\t\tRetryNetworkErrors: {retry_network_errors},\n\ + \t\t\tRequireIdempotentOrReadonly: {require_idempotent},\n\ + \t\t}},\n", + max_attempts = retry.max_attempts, + base_delay_ms = retry.base_delay_ms, + max_delay_ms = retry.max_delay_ms, + retry_network_errors = retry.retry_network_errors, + require_idempotent = retry.require_idempotent_or_readonly, + )); + } + + // Error shape. + if let Some(ref rc) = config.response_classification { + if let Some(ref shape) = rc.error_shape { + out.push_str(&format!( + "\t\tErrorShape: &ErrorShapeExtraction{{\n\ + \t\t\tMessagePath: \"{message_path}\",\n", + message_path = shape.message_path, + )); + if let Some(ref cp) = shape.code_path { + out.push_str(&format!("\t\t\tCodePath: \"{}\",\n", cp)); + } + out.push_str("\t\t},\n"); + } + } + + out.push_str("\t}\n}\n"); + out +} + +/// Emit C middleware config constants for an operation. +pub fn emit_c_middleware_config( + op_name: &str, + config: &TransportMiddlewareConfig, +) -> String { + let mut out = String::new(); + out.push_str(&format!( + "/* {op_name}: transport middleware configuration */\n" + )); + + if let Some(ref rl) = config.rate_limit { + let algo = match rl.algorithm { + RateLimitAlgorithm::TokenBucket => "TOKEN_BUCKET", + RateLimitAlgorithm::SlidingWindow => "SLIDING_WINDOW", + }; + out.push_str(&format!( + "static const struct {{\n\ + \x20 const char* scope_key;\n\ + \x20 const char* algorithm;\n\ + \x20 unsigned int max_burst;\n\ + \x20 unsigned int requests;\n\ + \x20 unsigned int window_seconds;\n\ + \x20 int honor_retry_after;\n\ + }} {op_name}_rate_limit = {{\n\ + \x20 .scope_key = \"{scope_key}\",\n\ + \x20 .algorithm = \"{algo}\",\n\ + \x20 .max_burst = {max_burst},\n\ + \x20 .requests = {requests},\n\ + \x20 .window_seconds = {window_seconds},\n\ + \x20 .honor_retry_after = {honor_retry_after},\n\ + }};\n\n", + scope_key = rl.scope_key, + max_burst = rl.max_burst, + requests = rl.requests, + window_seconds = rl.window_seconds, + honor_retry_after = if rl.honor_retry_after { 1 } else { 0 }, + )); + } + + if let Some(ref retry) = config.retry { + let backoff = match retry.backoff { + RetryBackoff::Fixed => "FIXED", + RetryBackoff::Exponential => "EXPONENTIAL", + RetryBackoff::ExponentialJitter => "EXPONENTIAL_JITTER", + }; + let statuses = retry + .retry_statuses + .iter() + .map(std::string::ToString::to_string) + .collect::>() + .join(", "); + out.push_str(&format!( + "static const struct {{\n\ + \x20 unsigned int max_attempts;\n\ + \x20 unsigned long base_delay_ms;\n\ + \x20 unsigned long max_delay_ms;\n\ + \x20 const char* backoff;\n\ + \x20 int retry_network_errors;\n\ + \x20 int require_idempotent_or_readonly;\n\ + }} {op_name}_retry = {{\n\ + \x20 .max_attempts = {max_attempts},\n\ + \x20 .base_delay_ms = {base_delay_ms},\n\ + \x20 .max_delay_ms = {max_delay_ms},\n\ + \x20 .backoff = \"{backoff}\",\n\ + \x20 .retry_network_errors = {retry_network_errors},\n\ + \x20 .require_idempotent_or_readonly = {require_idempotent},\n\ + }};\nstatic const int {op_name}_retry_statuses[] = {{{statuses}}};\n\n", + max_attempts = retry.max_attempts, + base_delay_ms = retry.base_delay_ms, + max_delay_ms = retry.max_delay_ms, + retry_network_errors = if retry.retry_network_errors { 1 } else { 0 }, + require_idempotent = if retry.require_idempotent_or_readonly { + 1 + } else { + 0 + }, + )); + } + + if let Some(ref rc) = config.response_classification { + if let Some(ref shape) = rc.error_shape { + out.push_str(&format!( + "static const struct {{\n\ + \x20 const char* message_path;\n\ + \x20 const char* code_path;\n\ + }} {op_name}_error_shape = {{\n\ + \x20 .message_path = \"{message_path}\",\n\ + \x20 .code_path = {code_path},\n\ + }};\n\n", + message_path = shape.message_path, + code_path = shape + .code_path + .as_deref() + .map(|p| format!("\"{}\"", p)) + .unwrap_or_else(|| "NULL".to_string()), + )); + } + } + + out +} + +/// Emit MIPS data section with middleware config for an operation. +pub fn emit_mips_middleware_config( + op_name: &str, + config: &TransportMiddlewareConfig, +) -> String { + let mut out = String::new(); + out.push_str(&format!(" # {op_name}: transport middleware config\n")); + + if let Some(ref rl) = config.rate_limit { + out.push_str(&format!( + "{op_name}_rate_limit_scope:\n .asciiz \"{scope_key}\"\n\ + {op_name}_rate_limit_requests:\n .word {requests}\n\ + {op_name}_rate_limit_window:\n .word {window_seconds}\n\ + {op_name}_rate_limit_burst:\n .word {max_burst}\n", + scope_key = rl.scope_key, + requests = rl.requests, + window_seconds = rl.window_seconds, + max_burst = rl.max_burst, + )); + } + + if let Some(ref retry) = config.retry { + out.push_str(&format!( + "{op_name}_retry_max_attempts:\n .word {max_attempts}\n\ + {op_name}_retry_base_delay:\n .word {base_delay_ms}\n\ + {op_name}_retry_max_delay:\n .word {max_delay_ms}\n", + max_attempts = retry.max_attempts, + base_delay_ms = retry.base_delay_ms, + max_delay_ms = retry.max_delay_ms, + )); + } + + if let Some(ref rc) = config.response_classification { + if let Some(ref shape) = rc.error_shape { + out.push_str(&format!( + "{op_name}_error_message_path:\n .asciiz \"{}\"\n", + shape.message_path, + )); + } + } + + out +} + +/// Serialize a `TransportMiddlewareConfig` to a JSON string. +/// +/// Used to emit a language-agnostic middleware config manifest file alongside +/// the generated code. Any runtime can deserialize this to configure middleware. +pub fn serialize_middleware_config_json( + configs: &[(String, &TransportMiddlewareConfig)], +) -> String { + let mut map = serde_json::Map::new(); + for (name, config) in configs { + if let Ok(val) = serde_json::to_value(config) { + map.insert(name.clone(), val); + } + } + serde_json::to_string_pretty(&serde_json::Value::Object(map)) + .unwrap_or_else(|_| "{}".to_string()) +} + +fn rust_response_provider_variant( + provider: gunbc_ir::transport::middleware::ResponseProvider, +) -> &'static str { + use gunbc_ir::transport::middleware::ResponseProvider; + match provider { + ResponseProvider::Generic => "Generic", + ResponseProvider::GitHub => "GitHub", + ResponseProvider::Gcp => "Gcp", + ResponseProvider::Anthropic => "Anthropic", + ResponseProvider::OpenAi => "OpenAi", + } +} + // =========================================================================== // Tests // =========================================================================== @@ -1046,4 +1454,190 @@ mod tests { "has description: {code}" ); } + + // -- TL-14: Multi-target middleware config emission tests -- + + fn sample_middleware_config() -> TransportMiddlewareConfig { + use gunbc_ir::transport::middleware::*; + TransportMiddlewareConfig { + rate_limit: Some(RateLimitConfig { + scope_key: "github:core".to_string(), + algorithm: RateLimitAlgorithm::TokenBucket, + max_burst: 20, + requests: 5000, + window_seconds: 3600, + honor_retry_after: true, + }), + retry: Some(RetryConfig { + max_attempts: 3, + base_delay_ms: 100, + max_delay_ms: 2000, + backoff: RetryBackoff::ExponentialJitter, + retry_statuses: vec![429, 500, 502, 503, 504], + retry_network_errors: true, + require_idempotent_or_readonly: false, + circuit_breaker: None, + }), + credential: None, + response_classification: Some(ResponseClassification { + provider: gunbc_ir::transport::middleware::ResponseProvider::GitHub, + prioritize_auth_errors: true, + parse_provider_error_shapes: false, + error_shape: Some(ErrorShapeExtraction { + message_path: ".message".to_string(), + code_path: Some(".status".to_string()), + details_path: Some(".documentation_url".to_string()), + }), + }), + } + } + + #[test] + fn rust_middleware_config_emits_constructor() { + let config = sample_middleware_config(); + let code = emit_rust_middleware_config("github_gist_create", &config); + assert!( + code.contains("fn github_gist_create_middleware_config()"), + "has function: {code}" + ); + assert!( + code.contains("scope_key: \"github:core\""), + "has rate limit scope: {code}" + ); + assert!( + code.contains("TokenBucket"), + "has rate limit algorithm: {code}" + ); + assert!( + code.contains("max_attempts: 3"), + "has retry max_attempts: {code}" + ); + assert!( + code.contains("ExponentialJitter"), + "has retry backoff: {code}" + ); + assert!( + code.contains("message_path: \".message\""), + "has error shape message path: {code}" + ); + assert!( + code.contains("code_path: Some(\".status\""), + "has error shape code path: {code}" + ); + } + + #[test] + fn go_middleware_config_emits_struct() { + let config = sample_middleware_config(); + let code = emit_go_middleware_config("github_gist_create", &config); + assert!( + code.contains("func github_gist_createMiddlewareConfig()"), + "has function: {code}" + ); + assert!( + code.contains("ScopeKey: \"github:core\""), + "has rate limit scope: {code}" + ); + assert!( + code.contains("MaxAttempts: 3"), + "has retry max_attempts: {code}" + ); + assert!( + code.contains("MessagePath: \".message\""), + "has error shape: {code}" + ); + } + + #[test] + fn c_middleware_config_emits_structs() { + let config = sample_middleware_config(); + let code = emit_c_middleware_config("github_gist_create", &config); + assert!( + code.contains("github_gist_create_rate_limit"), + "has rate limit struct: {code}" + ); + assert!( + code.contains("scope_key = \"github:core\""), + "has scope key: {code}" + ); + assert!( + code.contains("github_gist_create_retry"), + "has retry struct: {code}" + ); + assert!( + code.contains("github_gist_create_error_shape"), + "has error shape struct: {code}" + ); + assert!( + code.contains("message_path = \".message\""), + "has message path: {code}" + ); + } + + #[test] + fn mips_middleware_config_emits_data_section() { + let config = sample_middleware_config(); + let code = emit_mips_middleware_config("github_gist_create", &config); + assert!( + code.contains("github_gist_create_rate_limit_scope"), + "has rate limit label: {code}" + ); + assert!( + code.contains("\"github:core\""), + "has scope key: {code}" + ); + assert!( + code.contains("github_gist_create_retry_max_attempts"), + "has retry label: {code}" + ); + assert!( + code.contains(".word 3"), + "has retry max_attempts value: {code}" + ); + assert!( + code.contains("github_gist_create_error_message_path"), + "has error shape label: {code}" + ); + } + + #[test] + fn extract_middleware_from_rest_spec() { + let mut spec = sample_rest_spec(); + spec.middleware = Some(sample_middleware_config()); + let op_spec = ServiceOperationSpec::Rest(Box::new(spec)); + let mw = extract_middleware(&op_spec); + assert!(mw.is_some(), "should extract middleware from REST spec"); + assert!(mw.unwrap().rate_limit.is_some(), "should have rate limit"); + } + + #[test] + fn extract_middleware_from_shell_spec_returns_none() { + let op_spec = ServiceOperationSpec::Shell(sample_shell_spec()); + assert!(extract_middleware(&op_spec).is_none()); + } + + #[test] + fn middleware_config_empty_emits_nones() { + let config = TransportMiddlewareConfig::default(); + let code = emit_rust_middleware_config("empty_op", &config); + assert!(code.contains("rate_limit: None"), "has None rate limit: {code}"); + assert!(code.contains("retry: None"), "has None retry: {code}"); + assert!( + code.contains("response_classification: None"), + "has None classification: {code}" + ); + } + + #[test] + fn serialize_middleware_config_json_produces_valid_json() { + let config = sample_middleware_config(); + let json = serialize_middleware_config_json(&[ + ("github_gist_create".to_string(), &config), + ]); + let parsed: serde_json::Value = serde_json::from_str(&json).expect("valid JSON"); + assert!(parsed.get("github_gist_create").is_some()); + assert!( + parsed["github_gist_create"]["rate_limit"]["scope_key"] == "github:core" + ); + } } diff --git a/core/daglang/daglang-lower/src/lib.rs b/core/daglang/daglang-lower/src/lib.rs index c43570ca41c..d6a586349e1 100644 --- a/core/daglang/daglang-lower/src/lib.rs +++ b/core/daglang/daglang-lower/src/lib.rs @@ -5245,12 +5245,13 @@ fn derive_middleware_config( } }); - // Infer response provider from service name (fallback when no error_shape). + // TL-15: parse_provider_error_shapes is always false — the transport layer + // uses only error_shape JSON-path extraction. let response_classification = infer_response_provider(&service.name).map(|provider| { ResponseClassification { provider, prioritize_auth_errors: true, - parse_provider_error_shapes: error_shape.is_none(), + parse_provider_error_shapes: false, error_shape: error_shape.clone(), } }); diff --git a/core/ir/src/transport/middleware.rs b/core/ir/src/transport/middleware.rs index 5a1ec61a3b8..1d5801b68bd 100644 --- a/core/ir/src/transport/middleware.rs +++ b/core/ir/src/transport/middleware.rs @@ -126,24 +126,33 @@ pub enum CredentialInjection { } /// Response classification policy and provider hint. +/// +/// # TL-15: Provider-agnostic classification +/// +/// Error extraction uses only the `error_shape` JSON-path rules. The +/// `parse_provider_error_shapes` field is retained for serialization backward +/// compatibility but is not used by the transport layer. New code should +/// always populate `error_shape`. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct ResponseClassification { pub provider: ResponseProvider, /// Prefer auth-classification over generic 4xx when both signals exist. #[serde(default)] pub prioritize_auth_errors: bool, - /// Attempt provider-specific body parsing for richer diagnostics. - #[serde(default = "default_parse_provider_error_shapes")] + /// Legacy field retained for serialization backward compatibility. + /// The transport layer ignores this field — all error extraction uses + /// `error_shape` JSON-path rules (TL-15). + #[serde(default, skip_serializing_if = "is_false")] pub parse_provider_error_shapes: bool, /// JSON-path based error shape extraction rules (TL-16). - /// When present, the transport layer uses these paths to extract error - /// details from the response body instead of hardcoded provider parsing. + /// The transport layer uses these paths to extract error details from the + /// response body. This is the sole error extraction mechanism (TL-15). #[serde(default, skip_serializing_if = "Option::is_none")] pub error_shape: Option, } -fn default_parse_provider_error_shapes() -> bool { - true +fn is_false(v: &bool) -> bool { + !v } /// JSON-path based error shape extraction (TL-16). @@ -215,8 +224,12 @@ mod tests { response_classification: Some(ResponseClassification { provider: ResponseProvider::GitHub, prioritize_auth_errors: true, - parse_provider_error_shapes: true, - error_shape: None, + parse_provider_error_shapes: false, + error_shape: Some(ErrorShapeExtraction { + message_path: ".message".to_string(), + code_path: None, + details_path: Some(".documentation_url".to_string()), + }), }), }; @@ -237,13 +250,15 @@ mod tests { } #[test] - fn response_classification_defaults_parse_provider_shapes() { + fn response_classification_defaults_parse_provider_shapes_to_false() { let json = r#"{ "provider":"gcp", "prioritize_auth_errors":true }"#; let cfg: ResponseClassification = serde_json::from_str(json).expect("classification"); - assert!(cfg.parse_provider_error_shapes); + // TL-15: parse_provider_error_shapes defaults to false; the transport + // layer uses only error_shape JSON-path extraction. + assert!(!cfg.parse_provider_error_shapes); assert!(cfg.error_shape.is_none()); } diff --git a/lib/transport/src/classify.rs b/lib/transport/src/classify.rs index 40e2f192f62..cdaa583fcbb 100644 --- a/lib/transport/src/classify.rs +++ b/lib/transport/src/classify.rs @@ -2,6 +2,13 @@ //! //! Classification is used by middleware (retry, metrics, diagnostics) to make //! transport decisions before provider-specific parse stages run. +//! +//! # TL-15: Provider-agnostic classification +//! +//! Error message extraction uses only the `error_shape` JSON-path rules +//! declared in `.dag` service definitions. No provider-specific parsing +//! functions exist in this module — the compiler emits all provider knowledge +//! as `ErrorShapeExtraction` config (TL-14 / TL-16). use gunbc_ir::transport::{ ErrorShapeExtraction, HttpResponse, ResponseClassification, ResponseProvider, RestResponse, @@ -51,14 +58,11 @@ pub fn classify_rest_response( return None; } - // TL-16: Prefer error_shape JSON-path extraction over hardcoded provider parsing. - let message = if let Some(ref shape) = policy.error_shape { - extract_error_message_by_path(shape, &response.body) - } else if policy.parse_provider_error_shapes { - provider_error_message(policy.provider, &response.body) - } else { - None - }; + // TL-15: Only use error_shape JSON-path extraction. No hardcoded provider parsing. + let message = policy + .error_shape + .as_ref() + .and_then(|shape| extract_error_message_by_path(shape, &response.body)); Some(ClassifiedResponse { kind: classify_status( @@ -83,18 +87,12 @@ pub fn classify_http_response( } let parsed = serde_json::from_str::(&response.body).ok(); - // TL-16: Prefer error_shape JSON-path extraction over hardcoded provider parsing. - let message = if let Some(ref shape) = policy.error_shape { + // TL-15: Only use error_shape JSON-path extraction. No hardcoded provider parsing. + let message = policy.error_shape.as_ref().and_then(|shape| { parsed .as_ref() .and_then(|body| extract_error_message_by_path(shape, body)) - } else if policy.parse_provider_error_shapes { - parsed - .as_ref() - .and_then(|body| provider_error_message(policy.provider, body)) - } else { - None - }; + }); Some(ClassifiedResponse { kind: classify_status( @@ -144,102 +142,11 @@ fn classify_status( ClassifiedErrorKind::Unknown } -/// Provider-specific error details parsed from response body. -#[derive(Debug, Clone, Default)] -pub struct ProviderDiagnostics { - /// Primary error message. - pub message: Option, - /// Error type/code (provider-specific). - pub error_type: Option, - /// HTTP status string (GCP). - pub status: Option, - /// Documentation URL (GitHub). - pub documentation_url: Option, - /// Numeric error code (GCP, OpenAI). - pub code: Option, -} - -impl ProviderDiagnostics { - /// Combine fields into a human-readable message. - pub fn to_message(&self) -> Option { - if let Some(msg) = &self.message { - let mut result = msg.clone(); - if let Some(doc) = &self.documentation_url { - result.push_str(" (see: "); - result.push_str(doc); - result.push(')'); - } - Some(result) - } else { - self.error_type.clone() - } - } -} - -/// Parse provider-specific error shape from response body. -pub fn parse_provider_error(provider: ResponseProvider, body: &JsonValue) -> ProviderDiagnostics { - match provider { - ResponseProvider::GitHub => parse_github_error(body), - ResponseProvider::Gcp => parse_gcp_error(body), - ResponseProvider::Anthropic => parse_anthropic_error(body), - ResponseProvider::OpenAi => parse_openai_error(body), - ResponseProvider::Generic => ProviderDiagnostics::default(), - } -} - -/// GitHub error shape: `{ message, documentation_url }` -fn parse_github_error(body: &JsonValue) -> ProviderDiagnostics { - ProviderDiagnostics { - message: body.get("message").and_then(JsonValue::as_str).map(String::from), - documentation_url: body.get("documentation_url").and_then(JsonValue::as_str).map(String::from), - ..Default::default() - } -} - -/// GCP error shape: `{ error: { code, message, status } }` -fn parse_gcp_error(body: &JsonValue) -> ProviderDiagnostics { - let error = body.get("error"); - ProviderDiagnostics { - message: error.and_then(|e| e.get("message")).and_then(JsonValue::as_str).map(String::from), - status: error.and_then(|e| e.get("status")).and_then(JsonValue::as_str).map(String::from), - code: error.and_then(|e| e.get("code")).and_then(JsonValue::as_i64), - ..Default::default() - } -} - -/// Anthropic error shape: `{ type, error: { type, message } }` -fn parse_anthropic_error(body: &JsonValue) -> ProviderDiagnostics { - let error = body.get("error"); - ProviderDiagnostics { - message: error.and_then(|e| e.get("message")).and_then(JsonValue::as_str).map(String::from), - error_type: error - .and_then(|e| e.get("type")) - .and_then(JsonValue::as_str) - .map(String::from) - .or_else(|| body.get("type").and_then(JsonValue::as_str).map(String::from)), - ..Default::default() - } -} - -/// OpenAI error shape: `{ error: { message, type, code } }` -fn parse_openai_error(body: &JsonValue) -> ProviderDiagnostics { - let error = body.get("error"); - ProviderDiagnostics { - message: error.and_then(|e| e.get("message")).and_then(JsonValue::as_str).map(String::from), - error_type: error.and_then(|e| e.get("type")).and_then(JsonValue::as_str).map(String::from), - code: error.and_then(|e| e.get("code")).and_then(JsonValue::as_i64), - ..Default::default() - } -} - -fn provider_error_message(provider: ResponseProvider, body: &JsonValue) -> Option { - parse_provider_error(provider, body).to_message() -} - /// Extract error message from response body using JSON-path rules (TL-16). /// -/// Replaces hardcoded provider parsing with declarative JSON-path extraction -/// from `error_shape {}` blocks in `.dag` files. +/// Uses declarative JSON-path extraction from `error_shape {}` blocks in `.dag` +/// files. This is the sole error extraction mechanism — no provider-specific +/// parsing functions exist (TL-15 cleanup). fn extract_error_message_by_path(shape: &ErrorShapeExtraction, body: &JsonValue) -> Option { let message = resolve_json_path(&shape.message_path, body) .and_then(JsonValue::as_str) @@ -267,7 +174,11 @@ fn json_value_to_string(v: &JsonValue) -> String { /// Resolve a dotted JSON path (e.g., ".error.message") against a JSON value. fn resolve_json_path<'a>(path: &str, body: &'a JsonValue) -> Option<&'a JsonValue> { - let path = path.strip_prefix("$.").unwrap_or(path).strip_prefix('.').unwrap_or(path); + let path = path + .strip_prefix("$.") + .unwrap_or(path) + .strip_prefix('.') + .unwrap_or(path); let mut current = body; for segment in path.split('.') { if segment.is_empty() { @@ -323,7 +234,7 @@ fn default_policy() -> ResponseClassification { ResponseClassification { provider: ResponseProvider::Generic, prioritize_auth_errors: true, - parse_provider_error_shapes: true, + parse_provider_error_shapes: false, error_shape: None, } } @@ -398,6 +309,62 @@ mod tests { use super::*; use gunbc_ir::transport::{HttpResponse, RestResponse}; + /// Helper: Build a policy with error_shape for GitHub-style errors. + fn github_error_shape_policy() -> ResponseClassification { + ResponseClassification { + provider: ResponseProvider::GitHub, + prioritize_auth_errors: true, + parse_provider_error_shapes: false, + error_shape: Some(ErrorShapeExtraction { + message_path: ".message".to_string(), + code_path: None, + details_path: Some(".documentation_url".to_string()), + }), + } + } + + /// Helper: Build a policy with error_shape for GCP-style errors. + fn gcp_error_shape_policy() -> ResponseClassification { + ResponseClassification { + provider: ResponseProvider::Gcp, + prioritize_auth_errors: true, + parse_provider_error_shapes: false, + error_shape: Some(ErrorShapeExtraction { + message_path: ".error.message".to_string(), + code_path: Some(".error.status".to_string()), + details_path: None, + }), + } + } + + /// Helper: Build a policy with error_shape for Anthropic-style errors. + fn anthropic_error_shape_policy() -> ResponseClassification { + ResponseClassification { + provider: ResponseProvider::Anthropic, + prioritize_auth_errors: true, + parse_provider_error_shapes: false, + error_shape: Some(ErrorShapeExtraction { + message_path: ".error.message".to_string(), + code_path: Some(".error.type".to_string()), + details_path: None, + }), + } + } + + /// Helper: Build a policy with error_shape for OpenAI-style errors. + fn openai_error_shape_policy() -> ResponseClassification { + ResponseClassification { + provider: ResponseProvider::OpenAi, + prioritize_auth_errors: true, + parse_provider_error_shapes: false, + error_shape: Some(ErrorShapeExtraction { + message_path: ".error.message".to_string(), + code_path: Some(".error.type".to_string()), + details_path: None, + }), + } + } + #[test] fn github_rate_limit_uses_retry_after_header() { let mut response = RestResponse::new( @@ -410,13 +377,8 @@ mod tests { response .headers .insert("Retry-After".to_string(), "42".to_string()); - let policy = ResponseClassification { - provider: ResponseProvider::GitHub, - prioritize_auth_errors: true, - parse_provider_error_shapes: true, - error_shape: None, - }; + let policy = github_error_shape_policy(); let classified = classify_rest_response(&response, &policy).expect("non-2xx should classify"); assert_eq!(classified.kind, ClassifiedErrorKind::RateLimit); @@ -439,12 +401,7 @@ mod tests { } }), ); - let policy = ResponseClassification { - provider: ResponseProvider::Gcp, - prioritize_auth_errors: true, - parse_provider_error_shapes: true, - error_shape: None, - }; + let policy = gcp_error_shape_policy(); let classified = classify_rest_response(&response, &policy).expect("classification"); assert_eq!(classified.kind, ClassifiedErrorKind::Client); assert_eq!(classified.message, Some("Invalid project id".to_string())); @@ -462,27 +419,37 @@ mod tests { } }), ); - let policy = ResponseClassification { - provider: ResponseProvider::Anthropic, - prioritize_auth_errors: true, - parse_provider_error_shapes: true, - error_shape: None, - }; + let policy = anthropic_error_shape_policy(); let classified = classify_rest_response(&response, &policy).expect("classification"); assert_eq!(classified.kind, ClassifiedErrorKind::Auth); } #[test] - fn malformed_provider_shape_falls_back_to_status_classification() { + fn malformed_body_falls_back_to_status_classification() { let response = RestResponse::new(500, serde_json::json!({"unexpected": true})); + let policy = gcp_error_shape_policy(); + let classified = classify_rest_response(&response, &policy).expect("classification"); + assert_eq!(classified.kind, ClassifiedErrorKind::Server); + assert_eq!(classified.message, None); + } + + #[test] + fn no_error_shape_falls_back_to_status_only() { + let response = RestResponse::new( + 403, + serde_json::json!({ + "message": "Forbidden" + }), + ); let policy = ResponseClassification { - provider: ResponseProvider::Gcp, + provider: ResponseProvider::Generic, prioritize_auth_errors: true, - parse_provider_error_shapes: true, + parse_provider_error_shapes: false, error_shape: None, }; let classified = classify_rest_response(&response, &policy).expect("classification"); - assert_eq!(classified.kind, ClassifiedErrorKind::Server); + assert_eq!(classified.kind, ClassifiedErrorKind::Auth); + // No error_shape means no message extraction. assert_eq!(classified.message, None); } @@ -493,12 +460,7 @@ mod tests { headers: HashMap::new(), body: r#"{"error":{"message":"invalid api key"}}"#.to_string(), }; - let policy = ResponseClassification { - provider: ResponseProvider::OpenAi, - prioritize_auth_errors: true, - parse_provider_error_shapes: true, - error_shape: None, - }; + let policy = openai_error_shape_policy(); let classified = classify_http_response(&response, &policy).expect("classification"); assert_eq!(classified.kind, ClassifiedErrorKind::Auth); assert_eq!(classified.message, Some("invalid api key".to_string())); diff --git a/tasks.md b/tasks.md index 1e2a6f68c05..1a2ea4349c8 100644 --- a/tasks.md +++ b/tasks.md @@ -16,9 +16,8 @@ Lane 1: Compiler Critical Path Unblock SDLC execution — C10, C10a, then C24/C25/C26 (C10:C26, A1:A4) -Lane 2: Service Contracts & Transport - Transport domain modeling + multi-target emit - (TL-14:15) +Lane 2: Service Contracts & Transport ✓ + All complete (TL-14, TL-15 done) Lane 3: SDLC Ship Part B: Wire real transports → cloud profile works (SC-1:8) @@ -175,11 +174,11 @@ configuration (rate limits, error shapes) from Rust into `.dag` files. | 2 | TL-11 | **DSL syntax for transport blocks.** Add `rate_limit {}`, `retry {}`, `error_shape {}`, `credential {}` blocks to grammar. | L | **Done** | | 3 | TL-12 | **Lower transport blocks to IR.** Rate limit budgets → `RateLimitConfig`. Retry policies → `RetryConfig`. | M | **Done** | | 4 | TL-13 | **Domain data migration.** Move hardcoded rate limits from Rust to `dsl/services/*.dag`. Delete provider-specific branches from `classify.rs`. | M | **Done** | -| 5 | TL-14 | **Multi-target emit.** Emit transport configuration per target language. Rust links to Target SDK. Go/Python stubs for future. | XL | Open | -| 6 | TL-15 | **Substrate cleanup.** `lib/transport/` becomes pure Target SDK. Delete `GITHUB_CORE_LIMIT` constants, `host.contains("github.com")` branches. | L | Open (needs TL-14) | +| 5 | TL-14 | **Multi-target emit.** Emit transport configuration per target language. Rust links to Target SDK. Go/Python stubs for future. | XL | **Done** | +| 6 | TL-15 | **Substrate cleanup.** `lib/transport/` becomes pure Target SDK. Delete `GITHUB_CORE_LIMIT` constants, `host.contains("github.com")` branches. | L | **Done** | | 7 | TL-16 | **Dynamic JSON-path error shapes.** Lower `error_shape {}` blocks into JSON-path extraction rules in IR. Delete `ResponseProvider` enum, `infer_response_provider()`, hardcoded `parse_*_error` functions. Transport layer blindly executes JSON-path extractions. | L | **Done** | -**Remaining open**: TL-14 (XL — multi-target emit), TL-15 (L — depends on TL-14) +**All TL tasks complete.** --- From 908d4c8490a8f5047d4776583f0361d2d8efd674 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Mar 2026 03:06:22 +0000 Subject: [PATCH 2/2] Fix deps subcommand invocation + add Phase 3 aspirational tasks Fix 1: workflow_commands.dag deps entries referenced `-p gunbc-deps` (library crate) instead of `-p gunbc-dag` (where the binary lives). Also added distinguishing subcommand args ("deps" vs "deps-generate") so execute_installs and write_deps_toml invoke different operations. Fixes 2 and 3 from the review were already applied in prior commits: - Value::Json field access flattening (resolve.rs:398-401) - A1-A5 binary purge (src/bin/ only has ci.rs + codegen_cli.rs) Phase 3 "Purist Engine" section adds 5 aspirational tasks (C27-C30, CT-8) for the final compiler refactor: Daggen AOT compilation, dynamic JSON-path output mappings, type-aware JSON bridging, typed config blocks, and contract test generation wiring. https://claude.ai/code/session_01ChHSbjrUYfHYWXrRgxLQwF --- dsl/config/workflow_commands.dag | 4 ++-- tasks.md | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/dsl/config/workflow_commands.dag b/dsl/config/workflow_commands.dag index dff32a6ae29..43f08f1cfb0 100644 --- a/dsl/config/workflow_commands.dag +++ b/dsl/config/workflow_commands.dag @@ -100,8 +100,8 @@ data workflow_commands: List = [ commands: [ { node_id: "deps.compilation_ensure", label: "compilation ensure", program: "cargo", args: ["build", "--workspace", "--bins"] }, { node_id: "deps.codegen_ensure", label: "codegen ensure", program: "cargo", args: ["run", "-p", "gunbc-dag", "--bin", "gunbc-codegen-dag"] }, - { node_id: "deps.execute_installs", label: "deps", program: "cargo", args: ["run", "-p", "gunbc-deps", "--bin", "gunbc-deps", "--"] }, - { node_id: "deps.write_deps_toml", label: "deps", program: "cargo", args: ["run", "-p", "gunbc-deps", "--bin", "gunbc-deps", "--"] } + { node_id: "deps.execute_installs", label: "deps", program: "cargo", args: ["run", "-p", "gunbc-dag", "--bin", "gunbc-deps", "--", "deps"] }, + { node_id: "deps.write_deps_toml", label: "deps", program: "cargo", args: ["run", "-p", "gunbc-dag", "--bin", "gunbc-deps", "--", "deps-generate"] } ] }, { diff --git a/tasks.md b/tasks.md index 1a2ea4349c8..0a9ed91044f 100644 --- a/tasks.md +++ b/tasks.md @@ -292,6 +292,24 @@ observability, retry resilience, and zero-downtime deploys. --- +# Phase 3: The Purist Engine (Aspirational) + +Final stages of the compiler refactor. Eliminate all runtime interpretation, +achieve fully hermetic AOT compilation, and strong-type every boundary. + +C24 (Pure Dataflow Lowering) is the keystone dependency — tracked in Lane 1 Part A above. +C27 and SR-8 cover related ground (typed config blocks). + +| # | ID | Task | Size | Status | Deps | +|---|-----|------|------|--------|------| +| 1 | C28 | **Daggen (AOT DAG Compilation).** Currently, generated CLI tools (`gunbc-sdlc`, etc.) parse and resolve `.dag` files dynamically at runtime via `build_dsl_graph_with_profile`. Implement "Daggen" to compile lowered DAGs directly into static `Dag` Rust structs during `make codegen`. The final binaries should contain zero DSL parsing/resolution logic, becoming fully hermetic AOT executables. | XL | Pending | C24 | +| 2 | C29 | **Dynamic JSON-Path Output Mappings.** Just like `error_shape` (TL-16), extend JSONPath extraction to successful responses. Lower output mappings into extraction rules (e.g., `issue_id: "$.id"`) so the Rust runtime doesn't need hardcoded struct extraction logic. | M | Pending | TL-16 | +| 3 | C30 | **Strict Type-Aware JSON Bridging.** `value_bridge.rs` currently hijacks the JSON keys `__enum` and `__bytes` to reconstruct complex `Value` types. This is "in-band signaling" and could collide with actual API payloads. Make `from_bridge_json` type-aware by passing the expected `TypeId` (which is known statically from the port). Delete the `__enum` JSON dictionary hacks. | M | Pending | — | +| 4 | C27 | **Typed Config Blocks.** The parser currently skips unknown tokens in `config {}` blocks and stores them as stringified `extra: Vec<(String, String)>`. Replace this pragmatic fallback with strongly typed AST parsing for provider-specific config fields (e.g. `bucket: String`, `model: String`). | S | Pending | — | +| 5 | CT-8 | **Wire Contract Test Generation.** Connect the new `StructuredContract` and `ProviderResponseContract` infrastructure in `core/ir/src/contract.rs` to `gunbc-testgen`. Emit S-Tier hermetic tests that mathematically prove every provider binding obeys the `.dag` behavioral contracts. | M | Pending | CT-1 | + +--- + # Backlog Triaged items not yet assigned to a lane. Promote when lane queues thin.