Skip to content

Implementing Apply

llms.txt lists every page for an agent

An applier writes declared source to a provider. This page is the write-side peer of Implementing Observation, and it exists for the same reason: a caller can trust a result only when it says what it did not do.

Per resource in the plan, an applier returns exactly one verdict:

verdictmeans
APPLIEDthe provider was called and the resource converged — created, updated or unchanged
PRUNEDowned, no longer declared, deleted
NOT-ATTEMPTEDno provider call was made, carrying a total reason

The three are disjoint and total. Every resource handed to the applier appears in exactly one of them. A resource in none of them was silently dropped, and this contract prevents that.

Each bucket is an array of one shape, all three extending ApplyRef so a resource is named the same way everywhere. packages/core/src/apply.ts is the contract.

interface ApplyRef { kind: string; name: string; } // the provider's own type name, verbatim
interface AppliedResource extends ApplyRef {
action: "created" | "updated" | "unchanged";
physicalId?: string;
}
interface PrunedResource extends ApplyRef {
deleted: boolean; // false when the delete was a no-op; still PRUNED
}
interface NotAttemptedResource extends ApplyRef {
reason: NotAttemptedReason;
detail?: string; // the status and body, the missing binding, the unsupported kind
}

applyRefKey(ref) produces the kind/name string the conformance suite and the diagnostics use.

The read path had two ways to return nothing for a declared entity and no way to tell them apart (the provider said it is absent, or the lexicon never looked), and the second was classifying as create. That is what observation.ts fixed.

The write path had the identical hole:

const mapper = MAPPERS[r.kind];
if (!mapper) {
console.log(`skip: no mapper for kind ${r.kind}`);
continue; // never appears in `applied`, or anywhere
}

A caller receiving { applied: [...] } could not distinguish a complete apply from one that dropped half the manifest, and ApplyOp had nothing to gate on. A console.log on stdout is not a signal in a result, the same way a warn on stderr was not a signal in a change set.

type NotAttemptedReason =
| "unsupported-kind" // no mapper/writer for this type
| "no-credentials" // no usable authorization for the target
| "no-binding" // no concrete target resolved
| "dependency-failed" // an upstream in the same run failed
| "filtered" // withheld by a caller-requested scope
| "not-prunable"; // an owned orphan of a kind that cannot be enumerated

Pick one. Consumers switch exhaustively over these values, so a reason is never a free-form string. A free-form string is what a console.log already was.

not-prunable is the prune-side reason. It separates “there was nothing to prune” from “I could not look for anything to prune here.” An applier that cannot enumerate a kind cannot know whether an owned orphan of it exists.

import { applyResult } from "@intentius/chant";
return applyResult(applied, pruned, notAttempted);

Versioned and self-discriminating (apply: "v1"), so an un-migrated applier may keep returning its own shape. That shape normalizes to “everything I was handed, I attempted”, which is the claim it already makes implicitly.

Reporting NOT-ATTEMPTED requires the envelope, since only the envelope can express it.

Two helpers come with it, both from @intentius/chant:

HelperUse
notAttemptedAll(refs, reason, detail?)The whole-apply refusal. Turns every resource in the plan into a NOT-ATTEMPTED entry with one reason, for a bind that failed outright. The write-side peer of unobservedAll.
normalizeApply(value)Turns either accepted shape (or undefined) into three always-present arrays. What every consumer, and every conformance assertion, works with.

To say “I applied nothing because I could not”, return notAttemptedAll. Returning nothing normalizes to three empty arrays, which reads as an empty plan.

Prune deletes only what chant owns. The marker channel differs per provider (tags on Azure, machine metadata on Fly), and the rule does not. Read the marker before issuing a delete, and never delete a resource that does not carry it. Which channel your lexicon reads on which path is declared as ownershipChannel on the plugin.

Assertion 4 is what holds you to it. A comment saying prune is owned-only is not enforcement, and every applier that got this wrong had the comment.

chant