@sigloch/graph-api-core 5.6.0 → 5.8.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.
@@ -0,0 +1,37 @@
1
+ /**
2
+ * format-e-door.ts — die Tuer des Format-E-Vertrags (CR-SM-359).
3
+ *
4
+ * Format-E ist ein Familienvertrag: Codec und Deskriptor liegen in diesem Paket, jeder Konsument
5
+ * (graphcode, graph-view-edit, …) liest und schreibt denselben Dialekt. Die Tuer gehoert deshalb
6
+ * hierher und nicht in eine Anwendung — CR-GC-641 hatte sie in graphcode gebaut, und damit hatte
7
+ * ein Konsument den Vertrag eines anderen definiert.
8
+ *
9
+ * Die Tuer ist ein Zod-Schema, kein Typ: zur Laufzeit pruefbar, und als Konstante zaehlt die Regel
10
+ * RC-09 (contracts) jeden, der sie parst, gegen das Modell des Konsumenten. Ein zweiter Leser
11
+ * desselben Textes ist damit ein Befund, keine Stilfrage (Spike CR-GC-637).
12
+ *
13
+ * @author andreas@siglochconsulting
14
+ */
15
+ import { z } from 'zod/v4';
16
+ import { FormatECodec } from './format-e-codec.js';
17
+ import type { Graph } from './types.js';
18
+ /**
19
+ * Die EINE SE-Instanz des Codecs. `FormatECodec` traegt keinen Zustand ueber den Aufruf hinaus —
20
+ * eine zweite Instanz waere kein Fehler, aber eine zweite Stelle, an der jemand einen anderen
21
+ * Deskriptor unterschieben koennte. Konsumenten importieren diese, statt eine eigene zu bauen.
22
+ */
23
+ export declare const SE_FORMAT_E_CODEC: FormatECodec;
24
+ /**
25
+ * Format-E-Text → Operations-Diff, ueber den SE-Codec.
26
+ *
27
+ * Eingabe ist `{ text, bestand }`: der Parser typisiert uids, die der Text nicht deklariert, aus
28
+ * dem Bestand — ein reiner Kanten-Batch zwischen bestehenden Knoten braucht keine
29
+ * `### <TYPE>`-Sektion. Jeder Codec-Fehler wird ein Zod-Issue, wortgleich.
30
+ */
31
+ export declare const FormatEInputSchema: z.ZodPipe<z.ZodObject<{
32
+ text: z.ZodString;
33
+ bestand: z.ZodCustom<Graph, Graph>;
34
+ }, z.core.$strip>, z.ZodTransform<import("./types.js").FormatEDiff, {
35
+ text: string;
36
+ bestand: Graph;
37
+ }>>;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * format-e-door.ts — die Tuer des Format-E-Vertrags (CR-SM-359).
3
+ *
4
+ * Format-E ist ein Familienvertrag: Codec und Deskriptor liegen in diesem Paket, jeder Konsument
5
+ * (graphcode, graph-view-edit, …) liest und schreibt denselben Dialekt. Die Tuer gehoert deshalb
6
+ * hierher und nicht in eine Anwendung — CR-GC-641 hatte sie in graphcode gebaut, und damit hatte
7
+ * ein Konsument den Vertrag eines anderen definiert.
8
+ *
9
+ * Die Tuer ist ein Zod-Schema, kein Typ: zur Laufzeit pruefbar, und als Konstante zaehlt die Regel
10
+ * RC-09 (contracts) jeden, der sie parst, gegen das Modell des Konsumenten. Ein zweiter Leser
11
+ * desselben Textes ist damit ein Befund, keine Stilfrage (Spike CR-GC-637).
12
+ *
13
+ * @author andreas@siglochconsulting
14
+ */
15
+ import { z } from 'zod/v4';
16
+ import { FormatECodec } from './format-e-codec.js';
17
+ import { SE_DESCRIPTOR } from './se-descriptor.js';
18
+ /**
19
+ * Die EINE SE-Instanz des Codecs. `FormatECodec` traegt keinen Zustand ueber den Aufruf hinaus —
20
+ * eine zweite Instanz waere kein Fehler, aber eine zweite Stelle, an der jemand einen anderen
21
+ * Deskriptor unterschieben koennte. Konsumenten importieren diese, statt eine eigene zu bauen.
22
+ */
23
+ export const SE_FORMAT_E_CODEC = new FormatECodec(SE_DESCRIPTOR);
24
+ /**
25
+ * Format-E-Text → Operations-Diff, ueber den SE-Codec.
26
+ *
27
+ * Eingabe ist `{ text, bestand }`: der Parser typisiert uids, die der Text nicht deklariert, aus
28
+ * dem Bestand — ein reiner Kanten-Batch zwischen bestehenden Knoten braucht keine
29
+ * `### <TYPE>`-Sektion. Jeder Codec-Fehler wird ein Zod-Issue, wortgleich.
30
+ */
31
+ export const FormatEInputSchema = z
32
+ .object({
33
+ text: z.string(),
34
+ bestand: z.custom((g) => typeof g === 'object' && g !== null && Array.isArray(g.nodes)),
35
+ })
36
+ .transform(({ text, bestand }, ctx) => {
37
+ const typeIndex = new Map(bestand.nodes.map((n) => [n.uid, n.type]));
38
+ const diff = SE_FORMAT_E_CODEC.parse(text, { resolveType: (uid) => typeIndex.get(uid) });
39
+ for (const message of diff.errors)
40
+ ctx.addIssue({ code: 'custom', message });
41
+ return diff;
42
+ });
@@ -33,23 +33,40 @@
33
33
  *
34
34
  * @author andreas@siglochconsulting
35
35
  */
36
- import type { Graph, GraphEdge, GraphNode } from './types.js';
36
+ import { z } from 'zod/v4';
37
+ import type { Graph, GraphNode } from './types.js';
37
38
  export type ImpactRole = 'seed' | 'whitebox' | 'blackbox';
38
39
  /** A slice node: the graph node plus its role and BFS distance from the changeset. */
39
40
  export type ImpactSliceNode = GraphNode & {
40
41
  role: ImpactRole;
41
42
  distance: number;
42
43
  };
43
- export interface ImpactSlice {
44
- /** The seeds actually present in the graph (order of first mention, deduped). */
45
- seeds: string[];
46
- /** The requested traversal depth (whitebox horizon; blackbox ring sits at depth+1). */
47
- depth: number;
48
- /** Slice nodes in the graph's node order — blackbox nodes carry identity only. */
49
- nodes: ImpactSliceNode[];
50
- /** Induced edges: kept iff both endpoints are in the slice. */
51
- edges: GraphEdge[];
52
- }
44
+ export declare const ImpactSliceSchema: z.ZodObject<{
45
+ seeds: z.ZodArray<z.ZodString>;
46
+ depth: z.ZodNumber;
47
+ nodes: z.ZodArray<z.ZodObject<{
48
+ uid: z.ZodString;
49
+ type: z.ZodString;
50
+ name: z.ZodString;
51
+ description: z.ZodOptional<z.ZodString>;
52
+ attributes: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
53
+ createdAt: z.ZodOptional<z.ZodString>;
54
+ updatedAt: z.ZodOptional<z.ZodString>;
55
+ role: z.ZodEnum<{
56
+ seed: "seed";
57
+ whitebox: "whitebox";
58
+ blackbox: "blackbox";
59
+ }>;
60
+ distance: z.ZodNumber;
61
+ }, z.core.$strip>>;
62
+ edges: z.ZodArray<z.ZodObject<{
63
+ sourceId: z.ZodString;
64
+ targetId: z.ZodString;
65
+ edgeType: z.ZodString;
66
+ attributes: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
67
+ }, z.core.$strip>>;
68
+ }, z.core.$strip>;
69
+ export type ImpactSlice = z.infer<typeof ImpactSliceSchema>;
53
70
  /**
54
71
  * Compute the impact slice of `seedIds` over a loaded graph: directed incoming
55
72
  * BFS to `depth` (whitebox) plus the materialized blackbox ring at depth+1.
@@ -1,3 +1,51 @@
1
+ /**
2
+ * impactSlice — THE directed impact traversal (CR-GC-365, Weg b).
3
+ *
4
+ * One definition of "blast radius", two readers: graphcode's `graph_impact`
5
+ * (MCP surface, agent) and graph-view-edit's ImpactMap (viewer). Before this,
6
+ * the MCP side ran a directed incoming Kuzu query while the viewer ran its own
7
+ * undirected frontier-BFS in the browser — what the human saw was a superset
8
+ * in direction and a subset in depth of what the agent got, computed from a
9
+ * different source.
10
+ *
11
+ * Semantics (node-equal to the former Kuzu query `(m)-[*1..depth]->(root)`,
12
+ * direction 'in' — conformance-tested against KuzuAdapter.getSubgraph):
13
+ *
14
+ * - Traversal is DIRECTED INCOMING: dependents, i.e. nodes with a directed
15
+ * path INTO a seed of length <= depth (who breaks if the seed changes).
16
+ * `distance` is the shortest such path length (0 = seed).
17
+ *
18
+ * - Roles per SPIKE-GC-minimal-whitebox §8 (`seed | whitebox | blackbox`):
19
+ * seed distance 0 — the changeset,
20
+ * whitebox distance 1..depth — full node (description, attributes),
21
+ * blackbox distance depth+1 — the frontier ONE step beyond the request:
22
+ * identity only (uid/type/name), description and attributes
23
+ * stripped. The cut is materialized in the artifact, not merely
24
+ * meant in a renderer; the ring is also the honest
25
+ * "+"-affordance: a bigger slice (same function, depth+1) opens
26
+ * exactly these nodes.
27
+ *
28
+ * - Edges only when BOTH ends lie in the slice (§8 — no edges into nothing).
29
+ *
30
+ * Pure function over a loaded Graph — no store handle, browser-safe (exported
31
+ * from `./browser.js` too). Seeds not present in the graph are dropped; no
32
+ * present seed yields an empty slice, never a full dump.
33
+ *
34
+ * @author andreas@siglochconsulting
35
+ */
36
+ import { z } from 'zod/v4';
37
+ import { GraphNodeSchema, GraphEdgeSchema } from './schemas.js';
38
+ // CR-SM-361: der Slice ist ein Zod-Vertrag, kein Typ — `impactSlice` prueft seine Ausgabe.
39
+ export const ImpactSliceSchema = z.object({
40
+ /** The seeds actually present in the graph (order of first mention, deduped). */
41
+ seeds: z.array(z.string()),
42
+ /** The requested traversal depth (whitebox horizon; blackbox ring sits at depth+1). */
43
+ depth: z.number(),
44
+ /** Slice nodes in the graph's node order — blackbox nodes carry identity only. */
45
+ nodes: z.array(GraphNodeSchema.extend({ role: z.enum(['seed', 'whitebox', 'blackbox']), distance: z.number() })),
46
+ /** Induced edges: kept iff both endpoints are in the slice. */
47
+ edges: z.array(GraphEdgeSchema),
48
+ });
1
49
  /**
2
50
  * Compute the impact slice of `seedIds` over a loaded graph: directed incoming
3
51
  * BFS to `depth` (whitebox) plus the materialized blackbox ring at depth+1.
@@ -45,5 +93,7 @@ export function impactSlice(graph, seedIds, depth) {
45
93
  }
46
94
  const inSlice = new Set(nodes.map((n) => n.uid));
47
95
  const edges = graph.edges.filter((e) => inSlice.has(e.sourceId) && inSlice.has(e.targetId));
48
- return { seeds, depth, nodes, edges };
96
+ const slice = { seeds, depth, nodes, edges };
97
+ ImpactSliceSchema.parse(slice); // CR-SM-361: der Erzeuger prueft seinen Vertrag
98
+ return slice;
49
99
  }
package/dist/index.d.ts CHANGED
@@ -13,6 +13,7 @@ export type { FormatEOperation, FormatEDiff } from './types.js';
13
13
  export { GraphNodeSchema, GraphEdgeSchema, GraphSchema, GraphScopeSchema, GraphQuerySchema, MutationResultSchema, HealthStatusSchema, } from './schemas.js';
14
14
  export { GraphService } from './graph-service.js';
15
15
  export { FormatECodec } from './format-e-codec.js';
16
+ export { SE_FORMAT_E_CODEC, FormatEInputSchema } from './format-e-door.js';
16
17
  export type { Rule, RuleViolation, RuleEngine } from './rule-engine.js';
17
18
  export { DefaultRuleEngine } from './rule-engine.js';
18
19
  export type { AuditEntry, AuditLog, OperationsLog } from './audit.js';
@@ -25,7 +26,7 @@ export type { GraphApiConfig } from './factory.js';
25
26
  export { SE_DESCRIPTOR, createSeDescriptor, projectToOntologyGraph, fromOntologyGraph } from './se-descriptor.js';
26
27
  export { findRoot } from './find-root.js';
27
28
  export type { RootQueryGraph } from './find-root.js';
28
- export { impactSlice } from './impact-slice.js';
29
+ export { impactSlice, ImpactSliceSchema } from './impact-slice.js';
29
30
  export type { ImpactSlice, ImpactSliceNode, ImpactRole } from './impact-slice.js';
30
31
  export { applyEdgeOps, updateEdge, mergeNodes } from './edge-ops.js';
31
32
  export type { EdgeIdentity, UpdateEdgeSet, UpdateEdgeResult, MergeNodesResult, EdgeOp, } from './edge-ops.js';
package/dist/index.js CHANGED
@@ -13,6 +13,8 @@ export { GraphNodeSchema, GraphEdgeSchema, GraphSchema, GraphScopeSchema, GraphQ
13
13
  export { GraphService } from './graph-service.js';
14
14
  // Format E Codec
15
15
  export { FormatECodec } from './format-e-codec.js';
16
+ // CR-SM-359: die Tuer des Format-E-Vertrags und die eine SE-Codec-Instanz — Konsumenten bauen keine eigene.
17
+ export { SE_FORMAT_E_CODEC, FormatEInputSchema } from './format-e-door.js';
16
18
  export { DefaultRuleEngine } from './rule-engine.js';
17
19
  export { InMemoryAuditLog, FileOperationsLog, AUDIT_FILE, AUDIT_BASENAME, DEFAULT_COMPACT_BYTES } from './audit.js';
18
20
  export { MemoryAdapter } from './memory-adapter.js';
@@ -24,7 +26,7 @@ export { SE_DESCRIPTOR, createSeDescriptor, projectToOntologyGraph, fromOntology
24
26
  export { findRoot } from './find-root.js';
25
27
  // The shared directed impact traversal (CR-GC-365 b) — one definition for
26
28
  // graphcode's graph_impact and graph-view-edit's ImpactMap.
27
- export { impactSlice } from './impact-slice.js';
29
+ export { impactSlice, ImpactSliceSchema } from './impact-slice.js';
28
30
  // Edge ops — update-edge (flip/retype) + merge-nodes, shared by GraphService.mutate()
29
31
  // and the graphcode Apply-Gate (CR-198)
30
32
  export { applyEdgeOps, updateEdge, mergeNodes } from './edge-ops.js';
@@ -13,30 +13,11 @@ export interface RuleViolation {
13
13
  fixHint?: string;
14
14
  /** Carried from the contracts rule: candidate_targets / existing_traces context for fix automation. */
15
15
  context?: unknown;
16
- /**
17
- * Stamped by the engine from the rule that produced this violation (CR-GC-312).
18
- * `false` = visible but not gate-relevant. Absent means gating, so every existing
19
- * consumer keeps its behaviour without reading the field.
20
- */
21
- gating?: boolean;
22
16
  }
23
17
  export interface Rule {
24
18
  id: string;
25
19
  name: string;
26
20
  severity: 'error' | 'warning' | 'info';
27
- /**
28
- * May an `error` from this rule BLOCK a write? (CR-GC-312) Default `true`.
29
- *
30
- * Severity says how bad a finding is; this says whether the gate acts on it. The
31
- * two are separate because a rule family can be correct and worth surfacing long
32
- * before a repo has paid off its backlog — switching one on would otherwise freeze
33
- * every write on debt the writer did not create. Set `false` to surface a rule in
34
- * `evaluate`/readiness while it is still being worked down, then promote it.
35
- *
36
- * NOT a severity downgrade: the violation keeps `severity: 'error'` and reads as one
37
- * everywhere it is displayed.
38
- */
39
- gating?: boolean;
40
21
  /**
41
22
  * `policy` (CR-GC-402) overrides the threshold set this rule was BOUND with at
42
23
  * descriptor construction, for this call only. Omitted = judge with the bound one,
@@ -19,12 +19,9 @@ export class DefaultRuleEngine {
19
19
  evaluate(graph, policy) {
20
20
  const violations = [];
21
21
  for (const rule of this.rules) {
22
- // CR-GC-312: stamp `gating` from the rule so a consumer's gate can filter
23
- // without a second lookup into the catalog. Only stamped when the rule opts
24
- // OUT — an absent field means gating, the pre-existing behaviour.
25
- const stamp = rule.gating === false ? { gating: false } : undefined;
22
+ // CR-SM-353: kein `gating`-Stempel mehr — die Schwere IST die Gate-Wirkung (`error` blockt).
26
23
  for (const v of rule.evaluate(graph, policy))
27
- violations.push(stamp ? { ...v, ...stamp } : v);
24
+ violations.push(v);
28
25
  }
29
26
  return violations;
30
27
  }
@@ -9,7 +9,7 @@
9
9
  * - Graph (nodes/edges) ⟷ OntologyGraph (elements/traces)
10
10
  * - RuleViolation (ruleId/…) ⟷ contracts RuleViolation (rule_id/…)
11
11
  */
12
- import { ElementType, TraceType, TRACE_PATTERNS, V3_RULES, MT_RULES, UC_RULES, FC_RULES, SC_RULES, CR_RULES, AO_RULES, FM_RULES, VIEW_RULES, AF_RULES, ONTOLOGY_VERSION, DEFAULT_METRIC_POLICY, normalizeReqKinds, } from '@sigloch/contracts/se';
12
+ import { ElementType, TraceType, TRACE_PATTERNS, V3_RULES, MT_RULES, UC_RULES, FC_RULES, SC_RULES, CR_RULES, AO_RULES, FM_RULES, VIEW_RULES, AF_RULES, TASK_OUTCOME_RULES, ONTOLOGY_VERSION, DEFAULT_METRIC_POLICY, normalizeReqKinds, } from '@sigloch/contracts/se';
13
13
  /**
14
14
  * Project an ontology-agnostic Graph (nodes/edges) onto the SE OntologyGraph
15
15
  * (elements/traces) that contracts/se rules evaluate against. Type-specific
@@ -136,19 +136,14 @@ function liftAttributes(rest) {
136
136
  * - RC (conformance) needs `CodeFacts` from a repo checkout, which this package has
137
137
  * no access to; graphcode evaluates those itself in `src/conformance.ts`.
138
138
  *
139
- * `gating` (see `Rule`) is what makes the switch-on safe. V3/MT keep their gate power;
140
- * the newly wired families are advisory until a repo has worked its backlog down —
141
- * otherwise the 114 pre-existing errors in graphcode's own graph would block every
142
- * write on debt the writer did not create. Promotion is a per-family decision, not a
143
- * side effect of being registered.
144
- *
145
- * CR-SM-309: IO is promoted (decision 2026-09-11). IO-02 ("a FLOW has exactly ONE
146
- * producer", error) guards the one-FLOW-per-connection cut; without gate power a
147
- * suggested merge put two producers back into one FLOW and passed the gate. The delta
148
- * baseline keeps the switch-on safe: only NEW findings block, graphcode's own graph is
149
- * at IO-02 = 0, and IO-01 shares the prefix but is a warning, which never blocks.
139
+ * CR-SM-353: `gating` entfaellt — die Schwere IST die Gate-Wirkung. Der Einschalt-Schutz, den das
140
+ * Flag einmal bot (114 Altfunde in graphcodes eigenem Graphen haetten jeden Write blockiert), ist
141
+ * seit der Delta-Semantik des Gates doppelt: nur NEU eingefuehrte error-Funde blocken, Altlast nie.
142
+ * Was blieb, war eine zweite Bedeutung von `error`, die jeder Konsument einzeln auseinanderhalten
143
+ * musste (Rewind opus5-12: `blockingErrors 0 → 8` fuer FM-03-Funde, die nie geblockt haetten).
144
+ * Jetzt: jede Regel mit `severity: 'error'` in `ALL_RULE_DEFS` steht im Gate-Katalog und blockt
145
+ * (IO-02, R-01, R-08, R-18, R-29); alles andere ist `warning` oder `info`.
150
146
  */
151
- const GATING_PREFIXES = ['R-', 'RD-', 'MT-', 'IO-'];
152
147
  const SE_RULE_DEFS = [
153
148
  ...V3_RULES,
154
149
  ...UC_RULES,
@@ -159,13 +154,13 @@ const SE_RULE_DEFS = [
159
154
  ...FM_RULES,
160
155
  ...VIEW_RULES,
161
156
  ...AF_RULES,
157
+ ...TASK_OUTCOME_RULES, // CR-SM-355: Task-Ausgaenge trade / irr
162
158
  ];
163
159
  function adapt(def, evaluate, boundPolicy) {
164
160
  return {
165
161
  id: def.id,
166
162
  name: def.name,
167
163
  severity: def.severity,
168
- gating: GATING_PREFIXES.some((p) => def.id.startsWith(p)),
169
164
  // CR-GC-402: the CALLER's policy wins for this evaluation, the descriptor's bound
170
165
  // one is the fallback. Without this the threshold was frozen at construction, so a
171
166
  // consumer of the published `SE_DESCRIPTOR` judged with `DEFAULT_METRIC_POLICY` no
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sigloch/graph-api-core",
3
- "version": "5.6.0",
3
+ "version": "5.8.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -43,7 +43,7 @@
43
43
  "access": "public"
44
44
  },
45
45
  "peerDependencies": {
46
- "@sigloch/contracts": ">=10 <11",
46
+ "@sigloch/contracts": ">=10.11 <11",
47
47
  "kuzu-wasm": "^0.11.3"
48
48
  },
49
49
  "peerDependenciesMeta": {
@@ -52,7 +52,7 @@
52
52
  }
53
53
  },
54
54
  "devDependencies": {
55
- "@sigloch/contracts": ">=10 <11",
55
+ "@sigloch/contracts": ">=10.11 <11",
56
56
  "kuzu-wasm": "^0.11.3"
57
57
  }
58
58
  }