@altopelago/sansa 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,26 +1,197 @@
1
1
  {
2
2
  "implementation": "@altopelago/sansa",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "profiles": [
5
5
  "value-semantics-minimum-consumer",
6
+ "aeon.value.default.v1",
7
+ "aeon.value.string.codepoint.v1",
8
+ "aeon.value.string.natural.ascii.v1",
9
+ "aeon.value.string.locale.fr.v1",
6
10
  "addressing",
7
11
  "resolve",
8
- "query"
12
+ "query",
13
+ "instruction"
9
14
  ],
10
15
  "capabilities": [
11
16
  "AEON.ValueSemantics",
12
17
  "SANSA.Addressing",
13
18
  "SANSA.Resolve",
14
19
  "SANSA.Query",
15
- "SANSA.Transform"
20
+ "SANSA.Instruction",
21
+ "SANSA.Mutate",
22
+ "SANSA.Transform",
23
+ "SANSA.Graph"
16
24
  ],
17
25
  "core": {
18
26
  "valueSemanticsMinimumConsumer": true,
19
27
  "addressing": true,
20
28
  "resolve": true,
21
- "query": true
29
+ "query": true,
30
+ "instruction": false,
31
+ "mutate": false
22
32
  },
33
+ "experimentalCapabilities": [
34
+ {
35
+ "id": "sansa.graph.structured.one-hop.v1",
36
+ "capability": "SANSA.Graph",
37
+ "category": "declared-relationship-traversal",
38
+ "maturity": "experimental",
39
+ "entryPoints": ["traverseGraph", "traverseGraphSequence"],
40
+ "semantics": [
41
+ "structured declarations only",
42
+ "one-hop directed traversal",
43
+ "explicit bounded multi-hop declaration sequences",
44
+ "complete ordered multi-hop path provenance",
45
+ "index-neutral traversal through optional namespace lookup acceleration",
46
+ "explicit omit-or-error cycle policy",
47
+ "explicit schema-version applicability",
48
+ "source and target semantic-type constraints",
49
+ "per-source edge cardinality constraints",
50
+ "same-namespace traversal only",
51
+ "absolute address reference targets",
52
+ "address-valued relationship edges",
53
+ "deterministic Binding Set and Path Set",
54
+ "explicit Query-before and contextual Query/Transform-after composition",
55
+ "mandatory explicit budgets",
56
+ "aggregate depth, node, edge, and result budgets across hops",
57
+ "independent authorization callback per traversal step",
58
+ "read-only"
59
+ ],
60
+ "boundaries": [
61
+ "relationship declaration authority remains external to SANSA",
62
+ "AEOS or an AEOS-adjacent profile owns relationship meaning",
63
+ "target adapters own index health, rebuild, and scan fallback",
64
+ "traversal conveys location, never authorization",
65
+ "Graph authorization does not authorize composed Query reads",
66
+ "relationship mutation remains SANSA.Mutate responsibility",
67
+ "no graph storage, indexing, query language, or implicit recursive traversal claim"
68
+ ]
69
+ },
70
+ {
71
+ "id": "sansa.instruction.prototype.v1",
72
+ "capability": "SANSA.Instruction",
73
+ "category": "instruction-parse-lower-plan",
74
+ "maturity": "experimental",
75
+ "verbs": [
76
+ "create",
77
+ "replace",
78
+ "remove",
79
+ "insert",
80
+ "append",
81
+ "move"
82
+ ],
83
+ "aliases": [
84
+ {
85
+ "sourceVerb": "append",
86
+ "canonicalVerb": "insert",
87
+ "placement": "last"
88
+ }
89
+ ],
90
+ "entryPoints": [
91
+ "parseInstruction",
92
+ "lowerInstruction",
93
+ "planInstruction"
94
+ ],
95
+ "boundaries": [
96
+ "lowering emits SANSA.Mutate request operations",
97
+ "append is source-level Instruction sugar and lowers to insert-last mutation intent",
98
+ "require clauses lower into SANSA.Mutate preconditions",
99
+ "because and by clauses are inert claimed provenance, not authorization or authentication",
100
+ "planning delegates to SANSA.Mutate plan API",
101
+ "target-surface validation remains a downstream Mutate/adapter boundary",
102
+ "apply remains SANSA.Mutate adapter responsibility"
103
+ ]
104
+ },
105
+ {
106
+ "id": "sansa.mutate.plan.v1",
107
+ "capability": "SANSA.Mutate",
108
+ "category": "mutation-plan",
109
+ "maturity": "experimental",
110
+ "operations": [
111
+ "create",
112
+ "replace",
113
+ "remove",
114
+ "insert",
115
+ "move"
116
+ ],
117
+ "valueIntentHints": [
118
+ "datatype",
119
+ "kind"
120
+ ],
121
+ "targetSurfaceValidation": [
122
+ "aeon",
123
+ "json",
124
+ "custom"
125
+ ],
126
+ "entryPoints": [
127
+ "planMutation",
128
+ "validateMutationPlanTarget",
129
+ "applyMutationPlan"
130
+ ],
131
+ "adapterCapabilityFlags": [
132
+ "supportsCreate",
133
+ "supportsReplace",
134
+ "supportsRemove",
135
+ "supportsOrderedInsert",
136
+ "supportsMove",
137
+ "supportsStableBindingIdentity",
138
+ "supportsAtomicApply"
139
+ ]
140
+ },
141
+ {
142
+ "id": "sansa.mutate.policy.planFilter",
143
+ "capability": "SANSA.Mutate",
144
+ "category": "policy",
145
+ "maturity": "experimental",
146
+ "surface": "workbench",
147
+ "entryPoints": [
148
+ "tools/mutate-web",
149
+ "/api/mutate options.policySource"
150
+ ],
151
+ "policyRuleFields": [
152
+ "operation",
153
+ "operations",
154
+ "target",
155
+ "parent",
156
+ "container",
157
+ "source",
158
+ "anchor",
159
+ "name",
160
+ "names",
161
+ "datatype",
162
+ "datatypes",
163
+ "kind",
164
+ "kinds",
165
+ "value",
166
+ "values"
167
+ ],
168
+ "diagnostics": [
169
+ "SANSA_MUTATE_POLICY_INVALID_JSON",
170
+ "SANSA_MUTATE_POLICY_INVALID",
171
+ "SANSA_MUTATE_POLICY_INVALID_ADDRESS",
172
+ "SANSA_MUTATE_POLICY_DENIED"
173
+ ],
174
+ "boundaries": [
175
+ "policy is trusted consumer input, not document input",
176
+ "policy authorizes or denies already planned mutation intent",
177
+ "policy must not rewrite mutation plans or make schema-invalid values valid",
178
+ "unsupported policy fields fail closed instead of being ignored",
179
+ "policy remains outside SANSA.Mutate core conformance"
180
+ ]
181
+ }
182
+ ],
23
183
  "policies": [
184
+ {
185
+ "id": "dynamic-address-activation",
186
+ "capability": "SANSA.Query",
187
+ "category": "authority",
188
+ "maturity": "proposal",
189
+ "requiredFor": "path",
190
+ "modes": [
191
+ "trusted",
192
+ "constrained"
193
+ ]
194
+ },
24
195
  {
25
196
  "id": "validation",
26
197
  "capability": "SANSA.Query",
@@ -52,6 +223,41 @@
52
223
  "capability": "SANSA.Query",
53
224
  "category": "evaluation-budget",
54
225
  "phase": "select"
226
+ },
227
+ {
228
+ "id": "maxOperations",
229
+ "capability": "SANSA.Mutate",
230
+ "category": "mutation-budget",
231
+ "phase": "plan-apply",
232
+ "maturity": "experimental"
233
+ },
234
+ {
235
+ "id": "maxPreconditions",
236
+ "capability": "SANSA.Mutate",
237
+ "category": "mutation-budget",
238
+ "phase": "plan-apply",
239
+ "maturity": "experimental"
240
+ },
241
+ {
242
+ "id": "maxValueNodes",
243
+ "capability": "SANSA.Mutate",
244
+ "category": "mutation-budget",
245
+ "phase": "plan-apply",
246
+ "maturity": "experimental"
247
+ },
248
+ {
249
+ "id": "maxValueDepth",
250
+ "capability": "SANSA.Mutate",
251
+ "category": "mutation-budget",
252
+ "phase": "plan-apply",
253
+ "maturity": "experimental"
254
+ },
255
+ {
256
+ "id": "maxStringLength",
257
+ "capability": "SANSA.Mutate",
258
+ "category": "mutation-budget",
259
+ "phase": "plan-apply",
260
+ "maturity": "experimental"
55
261
  }
56
262
  ],
57
263
  "extensions": [
@@ -0,0 +1,345 @@
1
+ # SANSA Instruction Tool
2
+
3
+ The package includes an experimental instruction tool for exercising
4
+ SANSA.Instruction parse, lower, and plan behavior from the command line.
5
+ The browser Mutate Workbench also accepts Instruction source through its input
6
+ mode toggle.
7
+
8
+ ```bash
9
+ npm run instruction -- --mode parse --instruction 'replace $.inventory.items[1].qty with :int32 10'
10
+ npm run instruction -- --mode lower --instruction $'from $.inventory.items.*\nwhere .sku == "B-200"\nreplace .qty with :int32, 10'
11
+ npm run instruction -- --mode plan --instruction $'from $.inventory.items.*\nwhere .sku == "B-200"\nreplace .qty with :int32, 10'
12
+ npm run instruction -- --mode plan --target json --instruction 'create $.types.selectorCliProbe with :sansa, $.inventory.items.*'
13
+ npm run instruction -- --format json --mode plan --instruction-file instruction.sansai
14
+ ```
15
+
16
+ The default fixture is [../fixtures/query-inventory.json](../fixtures/query-inventory.json),
17
+ the same host-neutral namespace fixture used by the Query CLI. Use
18
+ `--fixture <path>` to test against another JSON or AEON fixture, and
19
+ `--fixture-kind json|aeon` when the extension is ambiguous.
20
+
21
+ `.aeon` fixture support is optional and uses the same AEON TypeScript Core
22
+ runtime discovery path as the Query tool. JSON fixtures expose bindings with
23
+ `address`, `children`, optional `attributeSpace` or `attributes`, optional
24
+ `localSpaces`, and scalar values through `value` or `scalar`.
25
+
26
+ ## Modes
27
+
28
+ `parse` validates instruction source and prints its canonical form.
29
+
30
+ ```bash
31
+ npm run instruction -- --mode parse --instruction 'replace $.inventory.items[1].qty with :int32 10'
32
+ ```
33
+
34
+ Text output:
35
+
36
+ ```text
37
+ replace $.inventory.items[1].qty with :int32, 10
38
+ ```
39
+
40
+ `lower` resolves query-shaped candidate clauses and emits structured
41
+ SANSA.Mutate request operations. It does not call the mutate planner.
42
+
43
+ ```bash
44
+ npm run instruction -- --mode lower --instruction $'from $.inventory.items.*\nwhere .sku == "B-200"\nreplace .qty with :int32, 10'
45
+ ```
46
+
47
+ Text output:
48
+
49
+ ```text
50
+ replace $.inventory.items[1].qty = 10 (datatype:int32, kind:number)
51
+ ```
52
+
53
+ `plan` lowers the instruction and then calls `planMutation(...)`. This is the
54
+ best CLI mode for checking whether an instruction can become a conservative
55
+ mutation plan.
56
+
57
+ ```bash
58
+ npm run instruction -- --mode plan --instruction $'from $.inventory.items.*\nwhere .sku == "B-200"\nreplace .qty with :int32, 10'
59
+ ```
60
+
61
+ Text output includes the lowered operation and the planned operation summary.
62
+ JSON output includes a sanitized plan summary instead of live binding objects.
63
+
64
+ `plan` mode may also validate the resulting plan against a target surface:
65
+
66
+ ```bash
67
+ npm run instruction -- --mode plan --target aeon --instruction $'from $.inventory.items.*\nwhere .sku == "B-200"\nreplace .qty with :int32, 10'
68
+ npm run instruction -- --mode plan --target json --instruction 'create $.types.selectorCliProbe with :sansa, $.inventory.items.*'
69
+ npm run instruction -- --mode plan --target json-compatible --instruction 'create $.types.label with "ok"'
70
+ ```
71
+
72
+ The target check runs after planning by calling
73
+ `validateMutationPlanTarget(plan, target)`. It does not change instruction
74
+ parsing, lowering, or mutation planning.
75
+ `json-compatible` is accepted as an alias for the JSON target surface; target
76
+ diagnostics still report normalized `targetFormat: "json"`.
77
+
78
+ ## Phase Model
79
+
80
+ Instruction tooling keeps the conservative mutation phases visible:
81
+
82
+ ```text
83
+ Instruction Source
84
+ -> Parsed Instruction
85
+ -> Lowered Structured Operations
86
+ -> Mutation Plan
87
+ -> Consumer Policy / Authorization
88
+ -> Target Surface Check
89
+ -> Preview / Apply
90
+ ```
91
+
92
+ The command-line tool stops at parse, lower, or plan unless `--target` is
93
+ provided. The browser Mutate Workbench can additionally run its experimental
94
+ policy plan filter after planning and before target-surface validation. Policy
95
+ and target-surface checks are post-plan consumer checks; neither one is encoded
96
+ by the Instruction source.
97
+
98
+ Each phase has a different authority boundary:
99
+
100
+ | Phase | Question Answered | Example Failure |
101
+ | --- | --- | --- |
102
+ | `parse` | Is this valid Instruction syntax and literal payload syntax? | `replace $.x with lower("A")` is rejected because values must be literals. |
103
+ | `lower` | Can candidate-relative Instruction intent become exact structured mutation requests? | `from $.items.* replace .missing with "x"` fails when `.missing` resolves nowhere. |
104
+ | `plan` | Are the exact mutation requests structurally legal against this namespace? | `append .sku with "x"` can lower, then fail because `.sku` is not an ordered container. |
105
+ | `policy` | Does a trusted consumer authorize the already-planned operations? | A default-deny workbench policy rejects a create operation with no matching allow rule. |
106
+ | `target` | Can the selected target format represent the planned value and datatype/kind intent? | JSON target mode rejects `:sansa, $.inventory.items.*`. |
107
+ | `apply` | Can the host mutation adapter apply the already-planned operation now? | Apply fails if a target or ordered anchor has drifted since planning. |
108
+
109
+ Target and policy phases are deliberately outside Instruction. An Instruction
110
+ can be syntactically valid, lower successfully, and produce a valid mutation
111
+ plan while still being denied by a consumer policy or rejected by a selected
112
+ target renderer.
113
+
114
+ ## Instruction Surface
115
+
116
+ This prototype accepts the conservative mutation verbs currently supported by
117
+ the SANSA.Mutate planner, plus source-level aliases that lower to those verbs:
118
+
119
+ ```text
120
+ create $.inventory.status with "active"
121
+ create "display name" with "Adapter"
122
+ replace $.inventory.qty with :int32, 10
123
+ remove $.inventory.oldStatus
124
+ insert first in $.inventory.tags with "new"
125
+ insert last in $.inventory.tags with "sale"
126
+ append $.inventory.tags with "sale"
127
+ insert before $.inventory.tags[1] in $.inventory.tags with :string, "featured"
128
+ insert after $.inventory.tags[1] in $.inventory.tags with :string, "clearance"
129
+ move $.inventory.tags[0] first in $.inventory.tags
130
+ move $.inventory.tags[0] last in $.inventory.tags
131
+ move $.inventory.tags[0] before $.inventory.tags[2] in $.inventory.tags
132
+ move $.inventory.tags[0] after $.inventory.tags[2] in $.inventory.tags
133
+ ```
134
+
135
+ `append <container> with <value>` and `append in <container> with <value>` are
136
+ source-level aliases for `insert last in <container> with <value>`. They lower
137
+ to an ordinary SANSA.Mutate `insert` operation with `placement: "last"` and
138
+ canonicalize as `insert last ...`.
139
+
140
+ For `insert` and `move`, `first` and `last` describe a destination within the
141
+ named container. `before <anchor>` and `after <anchor>` additionally name an
142
+ anchor that must resolve to a child of that same container during planning.
143
+
144
+ Instructions may also use `from` and `where` clauses to lower
145
+ candidate-relative targets into exact mutation requests:
146
+
147
+ ```text
148
+ because "manual correction"
149
+ by "Bob"
150
+ from $.inventory.items.*
151
+ where .sku == "C-300"
152
+ create status with "pending"
153
+ ```
154
+
155
+ `where` selects candidate bindings. `require` preserves a Mutate precondition
156
+ that must hold during planning and, by default, again before apply:
157
+
158
+ ```text
159
+ from $.inventory.items.*
160
+ where .sku == "A-100"
161
+ require .qty == 1
162
+ require .status == "open"
163
+ replace .qty with :int32, 10
164
+ ```
165
+
166
+ For candidate-relative instructions, each surviving candidate receives a
167
+ candidate-scoped precondition target. This keeps filtering and fail-closed
168
+ mutation guards separate.
169
+
170
+ One Instruction contains one declared mutation intent. That intent may lower to
171
+ multiple exact operations when a candidate selector matches multiple bindings,
172
+ but repeated source-level mutation clauses are rejected rather than treated as a
173
+ batch syntax. Use structured mutation-request JSON for heterogeneous or
174
+ unrelated multi-operation batches.
175
+
176
+ `because` and `by` are optional source-provenance clauses. They are preserved as
177
+ inert metadata on the lowered instruction and plan source:
178
+
179
+ ```text
180
+ because "manual correction"
181
+ by "Bob"
182
+ from $.inventory.items.*
183
+ where .sku == "A-100"
184
+ replace .qty with :int32, 10
185
+ ```
186
+
187
+ `because` is a human-readable reason. `by` is claimed attribution. Neither
188
+ clause provides authorization, authentication, approval, signature material, or
189
+ audit proof. Real actor identity, delegation, policy checks, and audit evidence
190
+ belong to the host envelope or mutation adapter.
191
+
192
+ Values use type-first intent in the same broad style as AEON-facing examples:
193
+
194
+ ```text
195
+ create $.types.brand with :brandColor, #ff00aa
196
+ create $.types.format with :csv[","], "sku,name"
197
+ create $.types.color.@.selector with :sansa, $.inventory.items.*
198
+ create $.types.@.selector with :sansa, $.inventory.items.*
199
+ create $.types.absentCopy with :null<string>, !notApplicable
200
+ create $.cloneCopy with :number, ~target
201
+ ```
202
+
203
+ The optional comma after a datatype annotation is accepted for readability:
204
+ `:int32 10` and `:int32, 10` are equivalent.
205
+
206
+ The datatype annotation is operation intent. The literal still supplies the
207
+ representation family: `:csv[","], "sku,name"` is string-shaped payload with
208
+ `csv[","]` datatype intent, while `:tuple, ("sku", 7)` is tuple-shaped payload
209
+ with `tuple` datatype intent. Top-level datatype and representation kind are
210
+ preserved on the structured mutation operation.
211
+
212
+ Instruction values also include a conservative container-literal slice for
213
+ testing structured mutation payloads:
214
+
215
+ ```text
216
+ create $.types.settings with :object, { enabled = true }
217
+ create $.types.settingsGeneric with :object<node>, { enabled = true }
218
+ create $.types.aliases with :list<string>, ["adapter", "driver"]
219
+ create $.types.pairing with :tuple<string>, ("sku", "A-100")
220
+ create $.types.badge with :node<node>, <badge(<label("new")>)>
221
+ insert before $.inventory.items[1] in $.inventory.items with :object, { sku = "B-150" name = "Brace" qty = 4 category = "hardware" }
222
+ append in $.inventory.items[1].roles with :string, "admin,editor"
223
+ ```
224
+
225
+ Some datatype annotations are valid Instruction intent but may still be
226
+ rejected by a selected target surface. For example, `csv[","]` can be planned as
227
+ SANSA.Mutate intent, while the current AEON target surface rejects square
228
+ bracket arguments on `csv`.
229
+
230
+ List, tuple, and node-child values use commas between items in this prototype.
231
+ Object fields use AEON-like `name = value` fields and may be separated by
232
+ layout or commas. Duplicate object field names are rejected so instruction
233
+ authoring never silently applies last-value-wins behavior:
234
+
235
+ ```text
236
+ create $.types.settings with :object, { enabled = true, status = false }
237
+ create $.types.labels with :object, { "display name" = "Adapter", "quote\"key" = "ok" }
238
+ ```
239
+
240
+ Quoted object field names use AEON-style quoted keys, not address-style member
241
+ selectors. For example, `"display name" = "Adapter"` is valid inside an
242
+ Instruction object value, while `["display name"] = "Adapter"` is reserved for
243
+ SANSA address/member selector syntax and is rejected in object values.
244
+
245
+ Nested value annotations inside container literals are retained in the parsed
246
+ Instruction AST and canonical source, but the conservative structured Mutate
247
+ operation currently carries the plain container payload plus top-level value
248
+ intent. Child-specific datatype intent needs separate exact operations or a
249
+ future structured value-intent model.
250
+
251
+ Instruction values are literal payloads. Query expressions such as
252
+ `lower("A")`, membership expressions, and candidate-relative value expressions
253
+ are not accepted as replacement or create payloads in this conservative slice.
254
+
255
+ Instruction parsing and lowering are target-neutral. A target format can reject
256
+ value intent that SANSA can express. For example, `:string<null>` is valid
257
+ Instruction datatype intent, but the current AEON workbench target rejects it
258
+ because AEON only allows generic parameters on specific datatype families:
259
+
260
+ ```text
261
+ create $.types.textProbe with :string<null>, ""
262
+ ```
263
+
264
+ The browser Mutate Workbench exposes this as a separate target-surface phase.
265
+ The default target is AEON. JSON target mode is stricter and accepts only
266
+ JSON-compatible object/list/string/number/boolean/null values while rejecting
267
+ AEON-only features such as attributes, typed SANSA values, parameterized
268
+ datatypes, tuples, nodes, references, NaN, and Infinity.
269
+
270
+ | Instruction intent | AEON target | JSON target |
271
+ | --- | --- | --- |
272
+ | `:object, { enabled = true }` | accepted | accepted |
273
+ | `:list, ["adapter"]` | accepted | accepted |
274
+ | `:list<string>, ["adapter"]` | accepted | rejected: parameterized datatype |
275
+ | `:object<node>, { enabled = true }` | accepted | rejected: parameterized datatype |
276
+ | `:tuple<string>, ("sku", "A-100")` | accepted | rejected: parameterized datatype |
277
+ | `:node<node>, <badge(<label("new")>)>` | accepted | rejected: parameterized datatype |
278
+ | `:sansa, $.inventory.items.*` | accepted | rejected: SANSA datatype |
279
+ | `:tuple, ("sku", 7)` | accepted | rejected: tuple datatype |
280
+ | `:node, <badge("new")>` | accepted | rejected: node datatype |
281
+ | `:number, ~target` | accepted | rejected: reference-family payload |
282
+ | `$.item.@.selector with :sansa, $.path` | accepted when AEON attribute-space exists | rejected: attribute-space mutation |
283
+
284
+ Examples that lower successfully but fail JSON target-surface validation:
285
+
286
+ ```text
287
+ create $.inventory.aliases with :list<string>, ["adapter"]
288
+ create $.inventory.pair with :tuple, ("sku", 7)
289
+ create $.inventory.badge with :node, <badge("new", 3)>
290
+ create $.inventory.copy with :number, ~target
291
+ ```
292
+
293
+ Quoted create member names are accepted for member names that cannot be written
294
+ as bare identifiers. Attribute creation uses ordinary SANSA attribute-space
295
+ addressing (`.@.`) and lowers to a create operation whose parent is the
296
+ attribute space.
297
+
298
+ This is not yet a full replacement for structured mutation-request JSON.
299
+ Instruction preserves source-level claimed provenance, but it does not express
300
+ heterogeneous multi-operation requests as a single instruction. Use structured
301
+ JSON for those cases until a later instruction/vocabulary slice defines them.
302
+
303
+ The Mutate Workbench labels examples that only exist on one input surface as
304
+ `structured-only` or `instruction-only` so this boundary is visible while
305
+ testing. The workbench also includes instruction-only diagnostic examples for
306
+ duplicate object fields, literal-only value failures, invalid create member
307
+ names, target-surface rejection, and policy-boundary behavior. Policy examples
308
+ load their policy JSON into the Policy tab when selected, so the planned or
309
+ applied operation and the trusted authorization surface can be inspected
310
+ together. Workbench examples are defined in
311
+ [tools/mutate-web/examples.mjs](../tools/mutate-web/examples.mjs) so the UI and
312
+ runtime tests consume the same catalog. Catalog variants also declare expected
313
+ plan behavior, operation counts, selected text snippets, and focused apply
314
+ checks so example drift is caught by the package test suite.
315
+
316
+ ## Diagnostics
317
+
318
+ Failures preserve the phase boundary:
319
+
320
+ - parse failures come from `parseInstruction(...)`;
321
+ - lower failures come from instruction lowering, candidate resolution, or
322
+ candidate-relative target resolution;
323
+ - plan failures come from `planMutation(...)`;
324
+ - policy failures come from a trusted consumer or workbench policy layer;
325
+ - target-surface failures come from a target renderer/adapter deciding that the
326
+ planned value cannot be represented by that target.
327
+
328
+ Candidate-relative misses are lowering failures. Structural mutation legality,
329
+ such as inserting into a non-ordered container or moving across containers,
330
+ remains a Mutate planning failure after lowering has produced exact addresses.
331
+
332
+ For example, a missing candidate-relative target fails during lowering:
333
+
334
+ ```bash
335
+ npm run instruction -- --mode lower --instruction $'from $.inventory.items.*\nreplace .missing with "x"'
336
+ ```
337
+
338
+ Workbench text diagnostics include nested parse causes when available, so an
339
+ instruction parse wrapper can still expose the concrete source error such as
340
+ `SANSA_INSTRUCTION_DUPLICATE_OBJECT_FIELD`.
341
+ Target-surface text diagnostics include available context such as target format,
342
+ datatype, and value path, while JSON diagnostics expose those fields
343
+ structurally as `targetFormat`, `datatype`, and `valuePath`.
344
+
345
+ JSON diagnostics are available with `--format json`.