Skip to main content

Coder

Struct Coder 

Source
pub struct Coder { /* private fields */ }
Expand description

The coder. Holds the inference backend the orchestrator uses for each run call; the backend is Arc<dyn …> so callers can share one backend across coder + non-coder paths.

§Issue #93 — operator-rooted parent key

Coder optionally holds the worker’s operator-rooted parent AgentKey (from WorkerIdentity::Operator { root }). When a dispatch needs to spawn a subprocess plugin (today: future ProviderPluginBackend::complete), it derives a delegated child via AgentKey::delegate so the child’s cert chain roots back to the operator’s UserKey from ~/.newt/identity.pem — never a synthetic key.

Implementations§

Source§

impl Coder

Source

pub fn new(backend: Arc<dyn InferenceBackend>) -> Self

Build a coder bound to backend.

Source

pub fn with_parent_key(self, parent: Arc<AgentKey>) -> Self

Builder: attach the operator-rooted parent AgentKey the coder will use to delegate per-spawn children for subprocess plugins (issue #93).

The acp-worker plumbs this in from WorkerIdentity::Operator { root } via [WorkerIdentity::parent_key]; the AllowNoKey debug fallback leaves it None. When present, Self::plugin_envelope_for can be called by future dispatch paths that need to spawn a provider plugin without first synthesizing a key.

Source

pub fn parent_key(&self) -> Option<&Arc<AgentKey>>

Borrow the parent AgentKey, if one is configured. Tests use this to assert the operator-rooted threading; future dispatch paths that spawn provider plugins use it to delegate per-spawn children.

Source

pub fn plugin_envelope_for( &self, role: &str, child_caveats: Caveats, ) -> Option<Result<String, EnvelopeError>>

Mint a plugin-side envelope for a subprocess running under role with child_caveats, by delegating from the coder’s operator-rooted parent key.

Returns:

  • Some(Ok(envelope)) on the happy path — the envelope’s cert chain roots back to the operator’s UserKey (issue #93).
  • Some(Err(_)) if delegation refused (child_caveats would amplify the parent’s authority, etc.).
  • None when no parent key is configured (the WorkerIdentity::AllowNoKey debug path or a legacy test that didn’t thread identity).

The returned envelope is the same shape newt-mesh’s plugin_envelope::serialize_for_plugin produces — base64’d JSON of an agent_mesh_protocol::CertChain — so plugins decode it identically.

Source

pub async fn run( &self, workspace: &Path, task: &str, caveats: &Caveats, ) -> Result<CoderRun>

Run one turn against workspace under the authority carried by caveats.

caveats is the peer’s signed, verified attenuated authority — see docs/decisions/agentic_object_capability_security.md and the 35a caveats_for_peer extractor in newt-mesh. Every tool dispatch this method makes (fs_read for the prompt scan, net for the inference call, fs_write for the apply, plus the max_calls budget for inference turns) goes through the enforcement helpers below — no path bypasses the check, even when caveats == Caveats::top(). That symmetry is load-bearing: 35c will tighten authority per peer, and a “skip checks if top” shortcut would silently break that tightening.

On any caveat refusal we return CoderError::CapabilityDenied carrying the axis name and the concrete target the dispatch tried to touch — enough context for the arbiter scorecard to count this as a scrubbed sortie rather than a model failure.

Happy path: build prompt -> infer -> normalize -> apply.

Weak-model fallback: when the model emits a Emission::UnifiedDiff (even under the whole-file directive) and that diff fails to apply — its line numbers / context are too far off even for the fuzzy matcher in newt-tools::apply_patch — we issue exactly ONE re-prompt asking for the COMPLETE file(s) in FILE:/END-FILE form, then apply via the hardened apply_whole_files path. The retry counts as a second inference call against the max_calls budget; if that budget would be exhausted we return the original apply error rather than escalating to a denial.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Coder

§

impl !UnwindSafe for Coder

§

impl Freeze for Coder

§

impl Send for Coder

§

impl Sync for Coder

§

impl Unpin for Coder

§

impl UnsafeUnpin for Coder

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more