feat(core): Artifact Metadata Binding (${env|arg|sys|secret})
Load-time resolve of frontmatter bindings into Module.metadata; Secret masking; sys.meta / --bind; llm ctor prefers meta over env_get. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
4a2d89406b
commit
88dc6d5a54
31 files changed
+2466
-49
No files matched your search
+12
-1
@@ -198,6 +198,8 @@ pub enum HostFn {
|
||||
StatsMean = 189,
|
||||
StatsMedian = 190,
|
||||
StatsStdev = 191,
|
||||
Meta = 192,
|
||||
MetaGet = 193,
|
||||
}
|
||||
|
||||
|
||||
@@ -386,6 +388,8 @@ impl HostFn {
|
||||
189 => Self::StatsMean,
|
||||
190 => Self::StatsMedian,
|
||||
191 => Self::StatsStdev,
|
||||
192 => Self::Meta,
|
||||
193 => Self::MetaGet,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
@@ -577,6 +581,8 @@ impl HostFn {
|
||||
"host_stats_mean" | "stats_mean" => Self::StatsMean,
|
||||
"host_stats_median" | "stats_median" => Self::StatsMedian,
|
||||
"host_stats_stdev" | "stats_stdev" => Self::StatsStdev,
|
||||
"host_meta" | "meta" => Self::Meta,
|
||||
"host_meta_get" | "meta_get" => Self::MetaGet,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
@@ -755,6 +761,8 @@ impl HostFn {
|
||||
Self::StatsMean => "host_stats_mean",
|
||||
Self::StatsMedian => "host_stats_median",
|
||||
Self::StatsStdev => "host_stats_stdev",
|
||||
Self::Meta => "host_meta",
|
||||
Self::MetaGet => "host_meta_get",
|
||||
Self::WritebackRecord => "host_writeback_record",
|
||||
Self::WritebackGet => "host_writeback_get",
|
||||
Self::WritebackClear => "host_writeback_clear",
|
||||
@@ -778,11 +786,12 @@ impl HostFn {
|
||||
&["path"]
|
||||
}
|
||||
Self::WriteText | Self::AppendText => &["path", "text"],
|
||||
Self::NowUnix | Self::NowMs | Self::Args | Self::Cwd => &[],
|
||||
Self::NowUnix | Self::NowMs | Self::Args | Self::Cwd | Self::Meta => &[],
|
||||
Self::FormatTime => &["unix", "pattern"],
|
||||
Self::ParseTime => &["text", "pattern"],
|
||||
Self::SleepMs => &["ms"],
|
||||
Self::EnvGet => &["name"],
|
||||
Self::MetaGet => &["key"],
|
||||
Self::EnvSet => &["name", "value"],
|
||||
Self::Exit => &["code"],
|
||||
Self::Exec => &["cmd"],
|
||||
@@ -980,6 +989,8 @@ pub fn call_host(
|
||||
HostFn::DotenvLoad => sys::dotenv_load(ctx, bound.get("path")),
|
||||
HostFn::Args => sys::args(ctx),
|
||||
HostFn::Cwd => sys::cwd(ctx),
|
||||
HostFn::Meta => sys::meta(ctx),
|
||||
HostFn::MetaGet => sys::meta_get(ctx, require(bound, "key")?),
|
||||
HostFn::Exit => sys::exit(ctx, require(bound, "code")?),
|
||||
HostFn::Exec => sys::exec(
|
||||
ctx,
|
||||
|
||||
@@ -146,6 +146,7 @@ pub(crate) fn value_to_json(v: &Value) -> Result<serde_json::Value, String> {
|
||||
}
|
||||
},
|
||||
Value::Code(c) => serde_json::Value::String(c.source.clone()),
|
||||
Value::Secret(_) => serde_json::Value::String("<secret>".into()),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -103,6 +103,8 @@ pub struct HostContext {
|
||||
pub current_line: u32,
|
||||
/// Entry-file line of each active user call (for writeback anchoring).
|
||||
pub call_site_lines: Vec<u32>,
|
||||
/// Bound Artifact Metadata from the entry `.mq.md` (Phase 1 Binding).
|
||||
pub entry_metadata: Vec<(String, crate::value::Value)>,
|
||||
/// Concurrent subtasks (`lib/subtask`): file / function / foreign.
|
||||
#[cfg_attr(not(feature = "exec-host"), allow(dead_code))]
|
||||
pub(crate) subtasks: HashMap<u64, subtask::Handle>,
|
||||
@@ -129,6 +131,7 @@ impl Default for HostContext {
|
||||
call_stack: Vec::new(),
|
||||
current_line: 1,
|
||||
call_site_lines: Vec::new(),
|
||||
entry_metadata: Vec::new(),
|
||||
subtasks: HashMap::new(),
|
||||
subtask_seq: 0,
|
||||
log_min_level: 20, // Info
|
||||
|
||||
@@ -408,6 +408,7 @@ fn spawn_fn(
|
||||
host.argv = argv;
|
||||
host.foreign_cmds = foreign_cmds;
|
||||
host.set_entry_source(Some(&module_path), &source);
|
||||
host.entry_metadata = module.metadata.clone();
|
||||
let mut interp = Interpreter::with_capture(Some(&module_path), false).with_host(host);
|
||||
interp
|
||||
.invoke_function(&module, &name, &call_args)
|
||||
|
||||
@@ -93,6 +93,22 @@ pub fn cwd(ctx: &HostContext) -> Result<Value, String> {
|
||||
Ok(Value::Text(ctx.cwd.display().to_string()))
|
||||
}
|
||||
|
||||
/// Bound entry Artifact Metadata (map).
|
||||
pub fn meta(ctx: &HostContext) -> Result<Value, String> {
|
||||
Ok(Value::Map(ctx.entry_metadata.clone()))
|
||||
}
|
||||
|
||||
/// Lookup one metadata key; missing → None.
|
||||
pub fn meta_get(ctx: &HostContext, key: &Value) -> Result<Value, String> {
|
||||
let k = as_text(key, "key")?;
|
||||
Ok(ctx
|
||||
.entry_metadata
|
||||
.iter()
|
||||
.find(|(name, _)| name == k)
|
||||
.map(|(_, v)| v.clone())
|
||||
.unwrap_or(Value::None))
|
||||
}
|
||||
|
||||
pub fn exit(ctx: &HostContext, code: &Value) -> Result<Value, String> {
|
||||
let c = as_i64(code, "code")?;
|
||||
if ctx.soft_side_effects {
|
||||
|
||||
Reference in new issue
Block a user