capdag 0.92.23685 → 0.93.23689

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.
package/capdag.js CHANGED
@@ -4257,7 +4257,7 @@ class PluginRepoServer {
4257
4257
  }
4258
4258
 
4259
4259
  // ============================================================================
4260
- // Route Notation — compact, round-trippable DAG path identifiers
4260
+ // Machine Notation — compact, round-trippable DAG path identifiers
4261
4261
  //
4262
4262
  // Route notation describes capability transformation paths using bracket-
4263
4263
  // delimited statements:
@@ -4268,18 +4268,18 @@ class PluginRepoServer {
4268
4268
  // ============================================================================
4269
4269
 
4270
4270
  /**
4271
- * Error types for route notation parsing.
4272
- * Mirrors Rust RouteNotationError exactly.
4271
+ * Error types for machine notation parsing.
4272
+ * Mirrors Rust MachineSyntaxError exactly.
4273
4273
  */
4274
- class RouteNotationError extends Error {
4274
+ class MachineSyntaxError extends Error {
4275
4275
  constructor(code, message) {
4276
4276
  super(message);
4277
- this.name = 'RouteNotationError';
4277
+ this.name = 'MachineSyntaxError';
4278
4278
  this.code = code;
4279
4279
  }
4280
4280
  }
4281
4281
 
4282
- const RouteNotationErrorCodes = {
4282
+ const MachineSyntaxErrorCodes = {
4283
4283
  EMPTY: 'Empty',
4284
4284
  UNTERMINATED_STATEMENT: 'UnterminatedStatement',
4285
4285
  INVALID_CAP_URN: 'InvalidCapUrn',
@@ -4300,9 +4300,9 @@ const RouteNotationErrorCodes = {
4300
4300
  * media types into a target media type. The isLoop flag indicates
4301
4301
  * ForEach semantics (the capability is applied to each item in a list).
4302
4302
  *
4303
- * Mirrors Rust RouteEdge.
4303
+ * Mirrors Rust MachineEdge.
4304
4304
  */
4305
- class RouteEdge {
4305
+ class MachineEdge {
4306
4306
  /**
4307
4307
  * @param {MediaUrn[]} sources - Input media URN(s)
4308
4308
  * @param {CapUrn} capUrn - The capability URN (edge label)
@@ -4326,7 +4326,7 @@ class RouteEdge {
4326
4326
  * - Same isLoop flag
4327
4327
  *
4328
4328
  * Source order does not matter — fan-in sources are compared as sets.
4329
- * Mirrors Rust RouteEdge::is_equivalent.
4329
+ * Mirrors Rust MachineEdge::is_equivalent.
4330
4330
  */
4331
4331
  isEquivalent(other) {
4332
4332
  if (this.isLoop !== other.isLoop) {
@@ -4370,7 +4370,7 @@ class RouteEdge {
4370
4370
 
4371
4371
  /**
4372
4372
  * Display string for this edge.
4373
- * Mirrors Rust Display for RouteEdge.
4373
+ * Mirrors Rust Display for MachineEdge.
4374
4374
  */
4375
4375
  toString() {
4376
4376
  const sources = this.sources.map(s => s.toString()).join(', ');
@@ -4380,7 +4380,7 @@ class RouteEdge {
4380
4380
  }
4381
4381
 
4382
4382
  /**
4383
- * A route graph — the semantic model behind route notation.
4383
+ * A route graph — the semantic model behind machine notation.
4384
4384
  *
4385
4385
  * The graph is a collection of directed edges where each edge is a capability
4386
4386
  * that transforms source media types into a target media type.
@@ -4389,11 +4389,11 @@ class RouteEdge {
4389
4389
  * of ordering. Alias names used in the textual notation are not part of
4390
4390
  * the graph model.
4391
4391
  *
4392
- * Mirrors Rust RouteGraph.
4392
+ * Mirrors Rust Machine.
4393
4393
  */
4394
- class RouteGraph {
4394
+ class Machine {
4395
4395
  /**
4396
- * @param {RouteEdge[]} edges
4396
+ * @param {MachineEdge[]} edges
4397
4397
  */
4398
4398
  constructor(edges) {
4399
4399
  this._edges = edges;
@@ -4401,25 +4401,25 @@ class RouteGraph {
4401
4401
 
4402
4402
  /**
4403
4403
  * Create an empty route graph.
4404
- * @returns {RouteGraph}
4404
+ * @returns {Machine}
4405
4405
  */
4406
4406
  static empty() {
4407
- return new RouteGraph([]);
4407
+ return new Machine([]);
4408
4408
  }
4409
4409
 
4410
4410
  /**
4411
- * Parse route notation into a RouteGraph.
4411
+ * Parse machine notation into a Machine.
4412
4412
  * @param {string} input
4413
- * @returns {RouteGraph}
4414
- * @throws {RouteNotationError}
4413
+ * @returns {Machine}
4414
+ * @throws {MachineSyntaxError}
4415
4415
  */
4416
4416
  static fromString(input) {
4417
- return parseRouteNotation(input);
4417
+ return parseMachine(input);
4418
4418
  }
4419
4419
 
4420
4420
  /**
4421
4421
  * Get the edges of this graph.
4422
- * @returns {RouteEdge[]}
4422
+ * @returns {MachineEdge[]}
4423
4423
  */
4424
4424
  edges() {
4425
4425
  return this._edges;
@@ -4445,10 +4445,10 @@ class RouteGraph {
4445
4445
  * Check if two route graphs are semantically equivalent.
4446
4446
  *
4447
4447
  * Two graphs are equivalent if they have the same set of edges
4448
- * (compared using RouteEdge.isEquivalent). Edge ordering
4448
+ * (compared using MachineEdge.isEquivalent). Edge ordering
4449
4449
  * does not matter.
4450
4450
  *
4451
- * Mirrors Rust RouteGraph::is_equivalent.
4451
+ * Mirrors Rust Machine::is_equivalent.
4452
4452
  */
4453
4453
  isEquivalent(other) {
4454
4454
  if (this._edges.length !== other._edges.length) {
@@ -4480,7 +4480,7 @@ class RouteGraph {
4480
4480
  * also produced as targets by any other edge. These are the "root"
4481
4481
  * inputs to the graph.
4482
4482
  *
4483
- * Mirrors Rust RouteGraph::root_sources.
4483
+ * Mirrors Rust Machine::root_sources.
4484
4484
  * @returns {MediaUrn[]}
4485
4485
  */
4486
4486
  rootSources() {
@@ -4505,7 +4505,7 @@ class RouteGraph {
4505
4505
  * Collect all unique target media URNs that are not consumed as sources
4506
4506
  * by any other edge. These are the "leaf" outputs of the graph.
4507
4507
  *
4508
- * Mirrors Rust RouteGraph::leaf_targets.
4508
+ * Mirrors Rust Machine::leaf_targets.
4509
4509
  * @returns {MediaUrn[]}
4510
4510
  */
4511
4511
  leafTargets() {
@@ -4530,13 +4530,13 @@ class RouteGraph {
4530
4530
  // =========================================================================
4531
4531
 
4532
4532
  /**
4533
- * Serialize this route graph to canonical one-line route notation.
4533
+ * Serialize this route graph to canonical one-line machine notation.
4534
4534
  *
4535
4535
  * The output is deterministic: same graph → same string.
4536
- * Mirrors Rust RouteGraph::to_route_notation.
4536
+ * Mirrors Rust Machine::to_machine_notation.
4537
4537
  * @returns {string}
4538
4538
  */
4539
- toRouteNotation() {
4539
+ toMachineNotation() {
4540
4540
  if (this._edges.length === 0) {
4541
4541
  return '';
4542
4542
  }
@@ -4587,11 +4587,11 @@ class RouteGraph {
4587
4587
  }
4588
4588
 
4589
4589
  /**
4590
- * Serialize to multi-line route notation (one statement per line).
4591
- * Mirrors Rust RouteGraph::to_route_notation_multiline.
4590
+ * Serialize to multi-line machine notation (one statement per line).
4591
+ * Mirrors Rust Machine::to_machine_notation_multiline.
4592
4592
  * @returns {string}
4593
4593
  */
4594
- toRouteNotationMultiline() {
4594
+ toMachineNotationMultiline() {
4595
4595
  if (this._edges.length === 0) {
4596
4596
  return '';
4597
4597
  }
@@ -4647,7 +4647,7 @@ class RouteGraph {
4647
4647
  * - nodeNames: Map<string, string> (media_urn_canonical → node_name)
4648
4648
  * - edgeOrder: number[] (edge indices in canonical order)
4649
4649
  *
4650
- * Mirrors Rust RouteGraph::build_serialization_maps.
4650
+ * Mirrors Rust Machine::build_serialization_maps.
4651
4651
  * @private
4652
4652
  */
4653
4653
  _buildSerializationMaps() {
@@ -4716,13 +4716,13 @@ class RouteGraph {
4716
4716
 
4717
4717
  /**
4718
4718
  * Display string for this graph.
4719
- * Mirrors Rust Display for RouteGraph.
4719
+ * Mirrors Rust Display for Machine.
4720
4720
  */
4721
4721
  toString() {
4722
4722
  if (this._edges.length === 0) {
4723
- return 'RouteGraph(empty)';
4723
+ return 'Machine(empty)';
4724
4724
  }
4725
- return `RouteGraph(${this._edges.length} edges)`;
4725
+ return `Machine(${this._edges.length} edges)`;
4726
4726
  }
4727
4727
  }
4728
4728
 
@@ -4732,7 +4732,7 @@ class RouteGraph {
4732
4732
  // ============================================================================
4733
4733
 
4734
4734
  // Load the Peggy-generated parser
4735
- const routeParser = require('./route-parser.js');
4735
+ const routeParser = require('./machine-parser.js');
4736
4736
 
4737
4737
  /**
4738
4738
  * Assign a media URN to a node, or check consistency if already assigned.
@@ -4748,8 +4748,8 @@ function assignOrCheckNode(node, mediaUrn, nodeMedia, position) {
4748
4748
  if (existing !== undefined) {
4749
4749
  const compatible = existing.isComparable(mediaUrn);
4750
4750
  if (!compatible) {
4751
- throw new RouteNotationError(
4752
- RouteNotationErrorCodes.INVALID_WIRING,
4751
+ throw new MachineSyntaxError(
4752
+ MachineSyntaxErrorCodes.INVALID_WIRING,
4753
4753
  `invalid wiring at statement ${position}: node '${node}' has conflicting media types: existing '${existing}', new '${mediaUrn}'`
4754
4754
  );
4755
4755
  }
@@ -4759,25 +4759,25 @@ function assignOrCheckNode(node, mediaUrn, nodeMedia, position) {
4759
4759
  }
4760
4760
 
4761
4761
  /**
4762
- * Parse route notation into a RouteGraph.
4762
+ * Parse machine notation into a Machine.
4763
4763
  *
4764
4764
  * Uses the Peggy-generated PEG parser to parse the input, then resolves
4765
4765
  * cap URNs and derives media URNs from cap in/out specs.
4766
4766
  *
4767
4767
  * Fails hard — no fallbacks, no guessing, no recovery.
4768
4768
  *
4769
- * Mirrors Rust parse_route_notation exactly.
4769
+ * Mirrors Rust parse_machine exactly.
4770
4770
  *
4771
4771
  * @param {string} input - Route notation string
4772
- * @returns {RouteGraph}
4773
- * @throws {RouteNotationError}
4772
+ * @returns {Machine}
4773
+ * @throws {MachineSyntaxError}
4774
4774
  */
4775
- function parseRouteNotation(input) {
4775
+ function parseMachine(input) {
4776
4776
  const trimmed = input.trim();
4777
4777
  if (trimmed.length === 0) {
4778
- throw new RouteNotationError(
4779
- RouteNotationErrorCodes.EMPTY,
4780
- 'route notation is empty'
4778
+ throw new MachineSyntaxError(
4779
+ MachineSyntaxErrorCodes.EMPTY,
4780
+ 'machine notation is empty'
4781
4781
  );
4782
4782
  }
4783
4783
 
@@ -4786,8 +4786,8 @@ function parseRouteNotation(input) {
4786
4786
  try {
4787
4787
  stmts = routeParser.parse(trimmed);
4788
4788
  } catch (e) {
4789
- throw new RouteNotationError(
4790
- RouteNotationErrorCodes.PARSE_ERROR,
4789
+ throw new MachineSyntaxError(
4790
+ MachineSyntaxErrorCodes.PARSE_ERROR,
4791
4791
  `parse error: ${e.message}`
4792
4792
  );
4793
4793
  }
@@ -4804,8 +4804,8 @@ function parseRouteNotation(input) {
4804
4804
  try {
4805
4805
  capUrn = CapUrn.fromString(stmt.capUrn);
4806
4806
  } catch (e) {
4807
- throw new RouteNotationError(
4808
- RouteNotationErrorCodes.INVALID_CAP_URN,
4807
+ throw new MachineSyntaxError(
4808
+ MachineSyntaxErrorCodes.INVALID_CAP_URN,
4809
4809
  `invalid cap URN in header '${stmt.alias}': ${e.message}`
4810
4810
  );
4811
4811
  }
@@ -4826,18 +4826,18 @@ function parseRouteNotation(input) {
4826
4826
  for (const header of headers) {
4827
4827
  if (aliasMap.has(header.alias)) {
4828
4828
  const firstPos = aliasMap.get(header.alias).position;
4829
- throw new RouteNotationError(
4830
- RouteNotationErrorCodes.DUPLICATE_ALIAS,
4829
+ throw new MachineSyntaxError(
4830
+ MachineSyntaxErrorCodes.DUPLICATE_ALIAS,
4831
4831
  `duplicate alias '${header.alias}' (first defined at statement ${firstPos})`
4832
4832
  );
4833
4833
  }
4834
4834
  aliasMap.set(header.alias, { capUrn: header.capUrn, position: header.position });
4835
4835
  }
4836
4836
 
4837
- // Phase 4: Resolve wirings into RouteEdges
4837
+ // Phase 4: Resolve wirings into MachineEdges
4838
4838
  if (wirings.length === 0 && headers.length > 0) {
4839
- throw new RouteNotationError(
4840
- RouteNotationErrorCodes.NO_EDGES,
4839
+ throw new MachineSyntaxError(
4840
+ MachineSyntaxErrorCodes.NO_EDGES,
4841
4841
  'route has headers but no wirings — define at least one edge'
4842
4842
  );
4843
4843
  }
@@ -4849,8 +4849,8 @@ function parseRouteNotation(input) {
4849
4849
  // Look up the cap alias
4850
4850
  const aliasEntry = aliasMap.get(wiring.capAlias);
4851
4851
  if (!aliasEntry) {
4852
- throw new RouteNotationError(
4853
- RouteNotationErrorCodes.UNDEFINED_ALIAS,
4852
+ throw new MachineSyntaxError(
4853
+ MachineSyntaxErrorCodes.UNDEFINED_ALIAS,
4854
4854
  `wiring references undefined alias '${wiring.capAlias}'`
4855
4855
  );
4856
4856
  }
@@ -4859,15 +4859,15 @@ function parseRouteNotation(input) {
4859
4859
  // Check node-alias collisions
4860
4860
  for (const src of wiring.sources) {
4861
4861
  if (aliasMap.has(src)) {
4862
- throw new RouteNotationError(
4863
- RouteNotationErrorCodes.NODE_ALIAS_COLLISION,
4862
+ throw new MachineSyntaxError(
4863
+ MachineSyntaxErrorCodes.NODE_ALIAS_COLLISION,
4864
4864
  `node name '${src}' collides with cap alias '${src}'`
4865
4865
  );
4866
4866
  }
4867
4867
  }
4868
4868
  if (aliasMap.has(wiring.target)) {
4869
- throw new RouteNotationError(
4870
- RouteNotationErrorCodes.NODE_ALIAS_COLLISION,
4869
+ throw new MachineSyntaxError(
4870
+ MachineSyntaxErrorCodes.NODE_ALIAS_COLLISION,
4871
4871
  `node name '${wiring.target}' collides with cap alias '${wiring.target}'`
4872
4872
  );
4873
4873
  }
@@ -4877,8 +4877,8 @@ function parseRouteNotation(input) {
4877
4877
  try {
4878
4878
  capInMedia = capUrn.inMediaUrn();
4879
4879
  } catch (e) {
4880
- throw new RouteNotationError(
4881
- RouteNotationErrorCodes.INVALID_MEDIA_URN,
4880
+ throw new MachineSyntaxError(
4881
+ MachineSyntaxErrorCodes.INVALID_MEDIA_URN,
4882
4882
  `invalid media URN in cap '${wiring.capAlias}': in= spec: ${e.message}`
4883
4883
  );
4884
4884
  }
@@ -4887,8 +4887,8 @@ function parseRouteNotation(input) {
4887
4887
  try {
4888
4888
  capOutMedia = capUrn.outMediaUrn();
4889
4889
  } catch (e) {
4890
- throw new RouteNotationError(
4891
- RouteNotationErrorCodes.INVALID_MEDIA_URN,
4890
+ throw new MachineSyntaxError(
4891
+ MachineSyntaxErrorCodes.INVALID_MEDIA_URN,
4892
4892
  `invalid media URN in cap '${wiring.capAlias}': out= spec: ${e.message}`
4893
4893
  );
4894
4894
  }
@@ -4917,24 +4917,24 @@ function parseRouteNotation(input) {
4917
4917
  // Assign target media URN
4918
4918
  assignOrCheckNode(wiring.target, capOutMedia, nodeMedia, wiring.position);
4919
4919
 
4920
- edges.push(new RouteEdge(sourceUrns, capUrn, capOutMedia, wiring.isLoop));
4920
+ edges.push(new MachineEdge(sourceUrns, capUrn, capOutMedia, wiring.isLoop));
4921
4921
  }
4922
4922
 
4923
- return new RouteGraph(edges);
4923
+ return new Machine(edges);
4924
4924
  }
4925
4925
 
4926
4926
  // ============================================================================
4927
- // RouteGraphBuilder — programmatic path construction
4927
+ // MachineBuilder — programmatic path construction
4928
4928
  // ============================================================================
4929
4929
 
4930
4930
  /**
4931
- * Builder for constructing RouteGraphs programmatically.
4931
+ * Builder for constructing Machines programmatically.
4932
4932
  *
4933
4933
  * Provides a fluent API for building route graphs without writing
4934
- * route notation strings. Useful for constructing paths from graph
4934
+ * machine notation strings. Useful for constructing paths from graph
4935
4935
  * exploration (e.g., selecting paths in the UI).
4936
4936
  */
4937
- class RouteGraphBuilder {
4937
+ class MachineBuilder {
4938
4938
  constructor() {
4939
4939
  this._edges = [];
4940
4940
  }
@@ -4945,13 +4945,13 @@ class RouteGraphBuilder {
4945
4945
  * @param {string} capUrnStr - Cap URN string
4946
4946
  * @param {string} targetUrn - Target media URN string
4947
4947
  * @param {boolean} [isLoop=false] - Whether this edge has ForEach semantics
4948
- * @returns {RouteGraphBuilder} this (for chaining)
4948
+ * @returns {MachineBuilder} this (for chaining)
4949
4949
  */
4950
4950
  addEdge(sourceUrns, capUrnStr, targetUrn, isLoop = false) {
4951
4951
  const sources = sourceUrns.map(s => MediaUrn.fromString(s));
4952
4952
  const capUrn = CapUrn.fromString(capUrnStr);
4953
4953
  const target = MediaUrn.fromString(targetUrn);
4954
- this._edges.push(new RouteEdge(sources, capUrn, target, isLoop));
4954
+ this._edges.push(new MachineEdge(sources, capUrn, target, isLoop));
4955
4955
  return this;
4956
4956
  }
4957
4957
 
@@ -4959,26 +4959,26 @@ class RouteGraphBuilder {
4959
4959
  * Add a linear chain of edges from CapGraphEdge[] (from CapGraph.findAllPaths).
4960
4960
  *
4961
4961
  * Each CapGraphEdge has fromUrn, toUrn, and cap (with cap.urn).
4962
- * This converts the path into a series of RouteEdges.
4962
+ * This converts the path into a series of MachineEdges.
4963
4963
  *
4964
4964
  * @param {CapGraphEdge[]} capGraphEdges - Array of CapGraphEdge from pathfinding
4965
- * @returns {RouteGraphBuilder} this (for chaining)
4965
+ * @returns {MachineBuilder} this (for chaining)
4966
4966
  */
4967
4967
  addCapGraphPath(capGraphEdges) {
4968
4968
  for (const edge of capGraphEdges) {
4969
4969
  const source = MediaUrn.fromString(edge.fromUrn);
4970
4970
  const target = MediaUrn.fromString(edge.toUrn);
4971
- this._edges.push(new RouteEdge([source], edge.cap.urn, target, false));
4971
+ this._edges.push(new MachineEdge([source], edge.cap.urn, target, false));
4972
4972
  }
4973
4973
  return this;
4974
4974
  }
4975
4975
 
4976
4976
  /**
4977
- * Build the RouteGraph from the accumulated edges.
4978
- * @returns {RouteGraph}
4977
+ * Build the Machine from the accumulated edges.
4978
+ * @returns {Machine}
4979
4979
  */
4980
4980
  build() {
4981
- return new RouteGraph([...this._edges]);
4981
+ return new Machine([...this._edges]);
4982
4982
  }
4983
4983
  }
4984
4984
 
@@ -5101,10 +5101,10 @@ module.exports = {
5101
5101
  PluginRepoClient,
5102
5102
  PluginRepoServer,
5103
5103
  // Route notation
5104
- RouteNotationError,
5105
- RouteNotationErrorCodes,
5106
- RouteEdge,
5107
- RouteGraph,
5108
- RouteGraphBuilder,
5109
- parseRouteNotation,
5104
+ MachineSyntaxError,
5105
+ MachineSyntaxErrorCodes,
5106
+ MachineEdge,
5107
+ Machine,
5108
+ MachineBuilder,
5109
+ parseMachine,
5110
5110
  };