feat(host): capability host, budgets, effect tracing and kernel adapters
Implements the single side-effect boundary from blueprint sections 7.3 and 9: - Capabilities: console/math, project-relative fs globs, net hosts, process, foreign, plugins; pure/project defaults deny external I/O and grants are explicit, checked at execution time (never at parse time). - Budget: evaluation fuel, call-stack depth, program output bytes and a wall-clock deadline, all reported as resource.exhausted. - EffectTrace: op/module/span/duration/result entries with no secret data. - StdHost: canonical Host implementation dispatching print, fs read/write and the math/foreign kernels; all errors are structured RuntimeErrors, including a permission.denied path with a grant hint. - ProjectFs: project-rooted, rejects absolute paths, `..` traversal and symlink escapes outside the root; bounded UTF-8 reads and safe writes. - Math adapter: parse/eval/substitute through marqdo-math with exact rational binding conversion and explicit unsupported-operation errors. - Foreign adapter: capability-gated one-shot run/call through marqdo-foreign, typed wire input, structured result map, timeout/output limits mapped to budget errors.
This commit is contained in:
1 parent
d799617076
commit
17b68da7f9
9 files changed
+1237
-1
No files matched your search
@@ -0,0 +1,66 @@
|
||||
//! Effect tracing.
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use marqdo_span::Span;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// One recorded host effect.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct TraceEntry {
|
||||
/// Operation name (`print`, `fs.read`, `foreign.call`, ...).
|
||||
pub op: String,
|
||||
/// Module that initiated it.
|
||||
pub module: String,
|
||||
/// Source span of the call site.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub span: Option<Span>,
|
||||
/// Wall-clock duration.
|
||||
pub duration_micros: u64,
|
||||
/// Result summary (`ok`, or a diagnostic code). Never contains secrets.
|
||||
pub result: String,
|
||||
}
|
||||
|
||||
/// Collected effects for one run.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct EffectTrace {
|
||||
entries: Vec<TraceEntry>,
|
||||
/// Whether tracing is enabled.
|
||||
pub enabled: bool,
|
||||
}
|
||||
|
||||
impl EffectTrace {
|
||||
/// Enable tracing.
|
||||
pub fn enabled() -> Self {
|
||||
Self {
|
||||
entries: Vec::new(),
|
||||
enabled: true,
|
||||
}
|
||||
}
|
||||
|
||||
/// Record an effect.
|
||||
pub fn record(
|
||||
&mut self,
|
||||
op: impl Into<String>,
|
||||
module: impl Into<String>,
|
||||
span: Option<Span>,
|
||||
duration: Duration,
|
||||
result: impl Into<String>,
|
||||
) {
|
||||
if !self.enabled {
|
||||
return;
|
||||
}
|
||||
self.entries.push(TraceEntry {
|
||||
op: op.into(),
|
||||
module: module.into(),
|
||||
span,
|
||||
duration_micros: duration.as_micros() as u64,
|
||||
result: result.into(),
|
||||
});
|
||||
}
|
||||
|
||||
/// Recorded entries.
|
||||
pub fn entries(&self) -> &[TraceEntry] {
|
||||
&self.entries
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user