feat(m0.6-r4): public Analysis v1 and Trace v1
- add check --emit with a deterministic, read-only semantic projection: package-aware modules, signatures, normalized bodies, refs, calls, diagnostics and source digests - remove stale analysis artifacts on compile errors; atomic writes - add run/call --trace-file with interpreter call/branch/loop/return events and host effect events under one sequence; redact values and record error status - add Analysis/Trace v1 specs, ADR-0015 and an independent Python consumer - add contract tests for determinism, stale artifacts, trace ordering/status and secret redaction
This commit is contained in:
1 parent
25a1faa6ef
commit
b5a28a9825
16 files changed
+1365
-13
No files matched your search
@@ -17,7 +17,7 @@ use crate::capability::{Capabilities, CapabilityAudit, CapabilityBroker};
|
||||
use crate::context::ExecutionContext;
|
||||
use crate::fs::ProjectFs;
|
||||
use crate::handles::{contains_plugin_handle, PluginHandleTable};
|
||||
use crate::trace::{EffectTrace, TraceEntry};
|
||||
use crate::trace::{EffectTrace, SemanticEvent, TraceEntry};
|
||||
use marqdo_sandbox::{PlatformCapabilities, SandboxMode};
|
||||
|
||||
/// Host operations reachable from the language surface.
|
||||
@@ -90,6 +90,21 @@ pub trait Host {
|
||||
|
||||
/// Recorded effects.
|
||||
fn trace(&self) -> &[TraceEntry];
|
||||
|
||||
/// Record one semantic event (Trace v1). Default: ignored.
|
||||
fn record_semantic(
|
||||
&mut self,
|
||||
_kind: &str,
|
||||
_function_id: Option<&str>,
|
||||
_span: Option<Span>,
|
||||
_detail: Option<&str>,
|
||||
) {
|
||||
}
|
||||
|
||||
/// Recorded semantic events. Default: empty.
|
||||
fn semantic_events(&self) -> &[SemanticEvent] {
|
||||
&[]
|
||||
}
|
||||
}
|
||||
|
||||
/// Default capability host implementation.
|
||||
@@ -124,6 +139,8 @@ pub struct StdHost {
|
||||
broker_audit: Arc<Mutex<Vec<CapabilityAudit>>>,
|
||||
/// Host-issued opaque plugin handles.
|
||||
pub handles: PluginHandleTable,
|
||||
semantic_events: Vec<SemanticEvent>,
|
||||
next_event_seq: u64,
|
||||
}
|
||||
|
||||
struct PluginSlot {
|
||||
@@ -164,6 +181,8 @@ impl StdHost {
|
||||
vendor_capabilities: BTreeSet::new(),
|
||||
broker_audit: Arc::new(Mutex::new(Vec::new())),
|
||||
handles: PluginHandleTable::default(),
|
||||
semantic_events: Vec::new(),
|
||||
next_event_seq: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,6 +289,17 @@ impl StdHost {
|
||||
exports
|
||||
}
|
||||
|
||||
/// Recorded semantic events (Trace v1).
|
||||
pub fn semantic_events(&self) -> &[SemanticEvent] {
|
||||
&self.semantic_events
|
||||
}
|
||||
|
||||
fn next_seq(&mut self) -> u64 {
|
||||
let seq = self.next_event_seq;
|
||||
self.next_event_seq += 1;
|
||||
seq
|
||||
}
|
||||
|
||||
/// Audited plugin capability decisions.
|
||||
pub fn capability_audit(&self) -> Vec<CapabilityAudit> {
|
||||
self.broker_audit
|
||||
@@ -436,12 +466,14 @@ impl Host for StdHost {
|
||||
ctx: &ExecutionContext,
|
||||
) -> Result<Value, RuntimeError> {
|
||||
let started = Instant::now();
|
||||
let seq = self.next_seq();
|
||||
let result = self.dispatch(op, args, ctx);
|
||||
let summary = match &result {
|
||||
Ok(_) => "ok".to_string(),
|
||||
Err(error) => error.code().to_string(),
|
||||
};
|
||||
self.trace.record(
|
||||
seq,
|
||||
op.name(),
|
||||
ctx.module_id.clone(),
|
||||
ctx.span,
|
||||
@@ -470,6 +502,27 @@ impl Host for StdHost {
|
||||
fn trace(&self) -> &[TraceEntry] {
|
||||
self.trace.entries()
|
||||
}
|
||||
|
||||
fn record_semantic(
|
||||
&mut self,
|
||||
kind: &str,
|
||||
function_id: Option<&str>,
|
||||
span: Option<Span>,
|
||||
detail: Option<&str>,
|
||||
) {
|
||||
let seq = self.next_seq();
|
||||
self.semantic_events.push(SemanticEvent {
|
||||
seq,
|
||||
kind: kind.to_string(),
|
||||
function_id: function_id.map(str::to_string),
|
||||
span,
|
||||
detail: detail.map(str::to_string),
|
||||
});
|
||||
}
|
||||
|
||||
fn semantic_events(&self) -> &[SemanticEvent] {
|
||||
&self.semantic_events
|
||||
}
|
||||
}
|
||||
|
||||
fn map_plugin_error(error: PluginError) -> RuntimeError {
|
||||
|
||||
@@ -20,4 +20,4 @@ pub use fs::ProjectFs;
|
||||
pub use handles::{contains_plugin_handle, PluginHandleTable};
|
||||
pub use host::{arity, expect_text, Host, HostOp, StdHost};
|
||||
pub use marqdo_sandbox::{PlatformCapabilities, SandboxMode, StrictIsolation};
|
||||
pub use trace::{EffectTrace, TraceEntry};
|
||||
pub use trace::{EffectTrace, SemanticEvent, TraceEntry};
|
||||
@@ -8,6 +8,9 @@ use serde::{Deserialize, Serialize};
|
||||
/// One recorded host effect.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct TraceEntry {
|
||||
/// Global event sequence within the run.
|
||||
#[serde(default)]
|
||||
pub seq: u64,
|
||||
/// Operation name (`print`, `fs.read`, `foreign.call`, ...).
|
||||
pub op: String,
|
||||
/// Module that initiated it.
|
||||
@@ -41,6 +44,7 @@ impl EffectTrace {
|
||||
/// Record an effect.
|
||||
pub fn record(
|
||||
&mut self,
|
||||
seq: u64,
|
||||
op: impl Into<String>,
|
||||
module: impl Into<String>,
|
||||
span: Option<Span>,
|
||||
@@ -51,6 +55,7 @@ impl EffectTrace {
|
||||
return;
|
||||
}
|
||||
self.entries.push(TraceEntry {
|
||||
seq,
|
||||
op: op.into(),
|
||||
module: module.into(),
|
||||
span,
|
||||
@@ -64,3 +69,18 @@ impl EffectTrace {
|
||||
&self.entries
|
||||
}
|
||||
}
|
||||
|
||||
/// One semantic event emitted by the interpreter (Trace v1).
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct SemanticEvent {
|
||||
/// Global event sequence within the run.
|
||||
pub seq: u64,
|
||||
/// Stable event kind (`call.enter`, `call.exit`, `branch.eval`, ...).
|
||||
pub kind: String,
|
||||
/// Canonical function id, when inside a call.
|
||||
pub function_id: Option<String>,
|
||||
/// Source span, when known.
|
||||
pub span: Option<Span>,
|
||||
/// Non-sensitive detail (`ok`, `true`, `int`, an error code).
|
||||
pub detail: Option<String>,
|
||||
}
|
||||
Reference in new issue
Block a user