archgraph-argo-beta 0.27.0-beta.11 → 0.27.0-beta.12

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.
@@ -149,18 +149,17 @@ const TOOLS = [
149
149
  },
150
150
  {
151
151
  name: 'addArchitectureElement',
152
- description: 'Use for one element. Creates a new element or adds an existing element to view_ids. view_ids is required so elements never exist outside views. element.id is REQUIRED: a non-empty, caller-assigned, stable string — there is no auto-id (reuse an existing id, or allocate the next one from the graph).',
152
+ description: 'Use for one element. Creates a new element or adds an existing element to view_ids. view_ids is required so elements never exist outside views. element.id is OPTIONAL: omit it and the server auto-allocates a unique id (returned in the result); provide it to pin a specific id (must not collide with a different element).',
153
153
  inputSchema: {
154
154
  type: 'object',
155
155
  required: ['element', 'view_ids'],
156
156
  properties: {
157
157
  element: {
158
158
  type: 'object',
159
- required: ['id'],
160
159
  properties: {
161
- id: { type: 'string', minLength: 1, description: 'Element id (non-empty, caller-assigned, stable). REQUIRED — the graph is written by id and there is NO auto-id: reuse an existing id (onConflict:"reuse" with the same (type,name)) or allocate the next one (e.g. MATCH (e:Element {graphKey:$graphKey}) RETURN max(toInteger(e.id))).' },
160
+ id: { type: 'string', description: 'Element id (OPTIONAL). Omit to let the server auto-allocate a unique id (a semantic slug from the name, e.g. "graph-wiki-federation-center", suffixed -002.. if taken). If provided it must not collide with a DIFFERENT element (a same (type,name) match is idempotent reuse).' },
162
161
  },
163
- description: 'The element to create/attach. MUST include a non-empty `id`.',
162
+ description: 'The element to create/attach. `id` is optional — omit it and the server allocates one (returned in the result).',
164
163
  },
165
164
  view_ids: { type: 'array', minItems: 1, items: { type: 'string' } },
166
165
  onConflict: { type: 'string', enum: ['reuse', 'allowDuplicate'], description: 'Dedup policy (default reuse). reuse: find-or-create — attach an existing exact (type, name) match; a same-type semantic near-duplicate also blocks creation. allowDuplicate: create anyway (even if a duplicate exists), requires a justification.' },
@@ -200,7 +199,7 @@ const TOOLS = [
200
199
  },
201
200
  {
202
201
  name: 'addArchitectureRelationship',
203
- description: 'Use for one relationship. Creates a new relationship or adds an existing relationship to view_ids. relationship.type is the ArchiMate 3.2 relationship type and is validated against endpoint element types.',
202
+ description: 'Use for one relationship. Creates a new relationship or adds an existing relationship to view_ids. relationship.type is the ArchiMate 3.2 relationship type and is validated against endpoint element types. relationship.id is OPTIONAL: omit it and the server auto-allocates a unique id (returned in the result).',
204
203
  inputSchema: {
205
204
  type: 'object',
206
205
  required: ['relationship', 'view_ids'],
@@ -244,7 +243,7 @@ const TOOLS = [
244
243
  },
245
244
  {
246
245
  name: 'addArchitectureView',
247
- description: 'Use for one view. The graph must have exactly one top-level view named SystemArchitecture; all sub-views must attach to an element with parent_element_id.',
246
+ description: 'Use for one view. The graph must have exactly one top-level view named SystemArchitecture; all sub-views must attach to an element with parent_element_id. view.view_id is OPTIONAL: omit it and the server auto-allocates a unique view_id (returned in the result).',
248
247
  inputSchema: {
249
248
  type: 'object',
250
249
  required: ['view'],
@@ -247,18 +247,17 @@ const TOOLS = [
247
247
  },
248
248
  {
249
249
  name: 'addArchitectureElement',
250
- description: 'Use for one element. Creates a new element or adds an existing element to view_ids. view_ids is required so elements never exist outside views. element.id is REQUIRED: a non-empty, caller-assigned, stable string — there is no auto-id (reuse an existing id, or allocate the next one from the graph). Set dryRun to preview without writing.',
250
+ description: 'Use for one element. Creates a new element or adds an existing element to view_ids. view_ids is required so elements never exist outside views. element.id is OPTIONAL: omit it and the server auto-allocates a unique id (returned in the result); provide it to pin a specific id (must not collide with a different element). Set dryRun to preview without writing.',
251
251
  inputSchema: {
252
252
  type: 'object',
253
253
  required: ['element', 'view_ids'],
254
254
  properties: {
255
255
  element: {
256
256
  type: 'object',
257
- required: ['id'],
258
257
  properties: {
259
- id: { type: 'string', minLength: 1, description: 'Element id (non-empty, caller-assigned, stable). REQUIRED — the graph is written by id and there is NO auto-id: reuse an existing id (onConflict:"reuse" with the same (type,name)) or allocate the next one (e.g. MATCH (e:Element {graphKey:$graphKey}) RETURN max(toInteger(e.id))).' },
258
+ id: { type: 'string', description: 'Element id (OPTIONAL). Omit to let the server auto-allocate a unique id (a semantic slug from the name, e.g. "graph-wiki-federation-center", suffixed -002.. if taken). If provided it must not collide with a DIFFERENT element (a same (type,name) match is idempotent reuse).' },
260
259
  },
261
- description: 'The element to create/attach. MUST include a non-empty `id`.',
260
+ description: 'The element to create/attach. `id` is optional — omit it and the server allocates one (returned in the result).',
262
261
  },
263
262
  view_ids: { type: 'array', minItems: 1, items: { type: 'string' } },
264
263
  onConflict: { type: 'string', enum: ['reuse', 'allowDuplicate'], description: 'Dedup policy (default reuse). reuse: find-or-create — attach an existing exact (type, name) match; a same-type semantic near-duplicate also blocks creation. allowDuplicate: create anyway (even if a duplicate exists), requires a justification.' },
@@ -301,7 +300,7 @@ const TOOLS = [
301
300
  },
302
301
  {
303
302
  name: 'addArchitectureRelationship',
304
- description: 'Use for one relationship. Creates a new relationship or adds an existing relationship to view_ids. relationship.type is the ArchiMate 3.2 relationship type and is validated against endpoint element types. Set dryRun to preview without writing.',
303
+ description: 'Use for one relationship. Creates a new relationship or adds an existing relationship to view_ids. relationship.type is the ArchiMate 3.2 relationship type and is validated against endpoint element types. relationship.id is OPTIONAL: omit it and the server auto-allocates a unique id (returned in the result). Set dryRun to preview without writing.',
305
304
  inputSchema: {
306
305
  type: 'object',
307
306
  required: ['relationship', 'view_ids'],
@@ -348,7 +347,7 @@ const TOOLS = [
348
347
  },
349
348
  {
350
349
  name: 'addArchitectureView',
351
- description: 'Use for one view. The graph must have exactly one top-level view named SystemArchitecture; all sub-views must attach to an element with parent_element_id. Set dryRun to preview without writing.',
350
+ description: 'Use for one view. The graph must have exactly one top-level view named SystemArchitecture; all sub-views must attach to an element with parent_element_id. view.view_id is OPTIONAL: omit it and the server auto-allocates a unique view_id (returned in the result). Set dryRun to preview without writing.',
352
351
  inputSchema: {
353
352
  type: 'object',
354
353
  required: ['view'],
@@ -1623,19 +1622,30 @@ function applyMutations(document, mutations, options = {}) {
1623
1622
  if (mutation.type === 'addElement') {
1624
1623
  requireObject(mutation.element, 'mutation.element');
1625
1624
  const scopedViews = requireViewScope(nextDocument.views, mutation.view_ids, 'mutation.view_ids');
1626
- if (typeof mutation.element.id !== 'string' || mutation.element.id === '') {
1627
- // Actionable: the caller must supply a stable id (issue #8). Not a generic
1628
- // requireId message — say what is missing and how to get one.
1629
- throw new Error(
1630
- "addElement requires element.id: a non-empty, caller-assigned, stable string. There is no auto-id — set `id` explicitly: " +
1631
- "reuse an existing element's id with onConflict:'reuse' (matched by the same (type,name)), or allocate the next id " +
1632
- '(e.g. MATCH (e:Element {graphKey:$graphKey}) RETURN max(toInteger(e.id))).',
1633
- );
1634
- }
1635
- const existingElement = findById(nextDocument.elements, mutation.element.id);
1636
- let targetElementId = mutation.element.id;
1637
- let reusedElement = false;
1638
- if (!existingElement) {
1625
+ const requestedElementId = typeof mutation.element.id === 'string' && mutation.element.id !== ''
1626
+ ? mutation.element.id
1627
+ : null;
1628
+ let targetElementId;
1629
+ let elementCreated = false;
1630
+ let elementReused = false;
1631
+
1632
+ const existingById = requestedElementId ? findById(nextDocument.elements, requestedElementId) : undefined;
1633
+ if (existingById) {
1634
+ // An explicit id that already exists: idempotent ONLY if it is the same
1635
+ // (type,name). Otherwise the caller picked a taken id — fail loudly instead
1636
+ // of silently attaching an unrelated element (issue #8 collision safety).
1637
+ const sameIdentity = existingById.type === mutation.element.type
1638
+ && normalizeDedupName(existingById.name) === normalizeDedupName(mutation.element.name);
1639
+ if (!sameIdentity) {
1640
+ throw new Error(
1641
+ `addElement id '${requestedElementId}' is already used by a different element `
1642
+ + `(type '${existingById.type}', name '${existingById.name}'). Choose another id (or omit id to auto-allocate one), `
1643
+ + `attach the existing element by using its id, or update it with updateArchitectureElement.`,
1644
+ );
1645
+ }
1646
+ targetElementId = requestedElementId;
1647
+ elementReused = true;
1648
+ } else {
1639
1649
  const candidates = findDuplicateElements(nextDocument.elements, mutation.element);
1640
1650
  const resolution = resolveDuplicateConflict({
1641
1651
  onConflict: mutation.onConflict,
@@ -1644,12 +1654,19 @@ function applyMutations(document, mutations, options = {}) {
1644
1654
  }, candidates);
1645
1655
  if (resolution.action === 'reuse') {
1646
1656
  targetElementId = resolution.existing.id;
1647
- reusedElement = true;
1657
+ elementReused = true;
1648
1658
  } else {
1649
- nextDocument.elements.push(clone(mutation.element));
1650
- syncViewsToElementSubdiagramViews(nextDocument, findById(nextDocument.elements, mutation.element.id));
1659
+ targetElementId = requestedElementId || allocateUniqueId(
1660
+ nextDocument.elements.map(entry => entry.id),
1661
+ mutation.element.name,
1662
+ slugifyId(mutation.element.type) || 'element',
1663
+ );
1664
+ nextDocument.elements.push({ ...clone(mutation.element), id: targetElementId });
1665
+ syncViewsToElementSubdiagramViews(nextDocument, findById(nextDocument.elements, targetElementId));
1666
+ elementCreated = true;
1651
1667
  }
1652
1668
  }
1669
+
1653
1670
  for (const view of scopedViews) {
1654
1671
  view.included_elements = addUnique(view.included_elements || [], [targetElementId]);
1655
1672
  touchedViewIds.add(view.view_id);
@@ -1660,8 +1677,10 @@ function applyMutations(document, mutations, options = {}) {
1660
1677
  type: mutation.type,
1661
1678
  id: targetElementId,
1662
1679
  view_ids: mutation.view_ids,
1663
- created: !existingElement && !reusedElement,
1664
- ...(reusedElement ? { reused: true, reusedId: targetElementId, requestedId: mutation.element.id } : {}),
1680
+ created: elementCreated,
1681
+ ...(elementReused ? { reused: true, reusedId: targetElementId } : {}),
1682
+ ...(requestedElementId === null && elementCreated ? { allocatedId: targetElementId } : {}),
1683
+ ...(elementReused && requestedElementId && requestedElementId !== targetElementId ? { requestedId: requestedElementId } : {}),
1665
1684
  });
1666
1685
  continue;
1667
1686
  }
@@ -1760,13 +1779,35 @@ function applyMutations(document, mutations, options = {}) {
1760
1779
  if (mutation.type === 'addRelationship') {
1761
1780
  requireObject(mutation.relationship, 'mutation.relationship');
1762
1781
  const scopedViews = requireViewScope(nextDocument.views, mutation.view_ids, 'mutation.view_ids');
1763
- requireId(mutation.relationship.id, 'mutation.relationship.id');
1764
- const existingRelationship = findById(nextDocument.relationships, mutation.relationship.id);
1765
- let targetRelationshipId = mutation.relationship.id;
1782
+ const requestedRelationshipId = typeof mutation.relationship.id === 'string' && mutation.relationship.id !== ''
1783
+ ? mutation.relationship.id
1784
+ : null;
1785
+ let targetRelationshipId;
1766
1786
  let sourceElementId = mutation.relationship.source_id;
1767
1787
  let targetEndpointId = mutation.relationship.target_id;
1768
- let reusedRelationship = false;
1769
- if (!existingRelationship) {
1788
+ let relationshipCreated = false;
1789
+ let relationshipReused = false;
1790
+
1791
+ const existingById = requestedRelationshipId ? findById(nextDocument.relationships, requestedRelationshipId) : undefined;
1792
+ if (existingById) {
1793
+ // Explicit id that already exists: idempotent only for the same natural key;
1794
+ // otherwise fail loudly instead of silently attaching an unrelated edge.
1795
+ const sameIdentity = existingById.source_id === mutation.relationship.source_id
1796
+ && existingById.type === mutation.relationship.type
1797
+ && existingById.target_id === mutation.relationship.target_id
1798
+ && normalizeDedupName(existingById.name) === normalizeDedupName(mutation.relationship.name);
1799
+ if (!sameIdentity) {
1800
+ throw new Error(
1801
+ `addRelationship id '${requestedRelationshipId}' is already used by a different relationship `
1802
+ + `(source '${existingById.source_id}', type '${existingById.type}', target '${existingById.target_id}'). `
1803
+ + 'Choose another id (or omit id to auto-allocate one), or update it with updateArchitectureRelationship.',
1804
+ );
1805
+ }
1806
+ targetRelationshipId = requestedRelationshipId;
1807
+ sourceElementId = existingById.source_id;
1808
+ targetEndpointId = existingById.target_id;
1809
+ relationshipReused = true;
1810
+ } else {
1770
1811
  const candidates = findDuplicateRelationships(nextDocument.relationships, mutation.relationship);
1771
1812
  const resolution = resolveDuplicateConflict({
1772
1813
  onConflict: mutation.onConflict,
@@ -1777,9 +1818,15 @@ function applyMutations(document, mutations, options = {}) {
1777
1818
  targetRelationshipId = resolution.existing.id;
1778
1819
  sourceElementId = resolution.existing.source_id;
1779
1820
  targetEndpointId = resolution.existing.target_id;
1780
- reusedRelationship = true;
1821
+ relationshipReused = true;
1781
1822
  } else {
1782
- nextDocument.relationships.push(clone(mutation.relationship));
1823
+ targetRelationshipId = requestedRelationshipId || allocateUniqueId(
1824
+ nextDocument.relationships.map(entry => entry.id),
1825
+ mutation.relationship.name || `${mutation.relationship.source_id}-${mutation.relationship.type}-${mutation.relationship.target_id}`,
1826
+ 'relationship',
1827
+ );
1828
+ nextDocument.relationships.push({ ...clone(mutation.relationship), id: targetRelationshipId });
1829
+ relationshipCreated = true;
1783
1830
  }
1784
1831
  }
1785
1832
  for (const view of scopedViews) {
@@ -1795,8 +1842,9 @@ function applyMutations(document, mutations, options = {}) {
1795
1842
  type: mutation.type,
1796
1843
  id: targetRelationshipId,
1797
1844
  view_ids: mutation.view_ids,
1798
- created: !existingRelationship && !reusedRelationship,
1799
- ...(reusedRelationship ? { reused: true, reusedId: targetRelationshipId, requestedId: mutation.relationship.id } : {}),
1845
+ created: relationshipCreated,
1846
+ ...(relationshipReused ? { reused: true, reusedId: targetRelationshipId } : {}),
1847
+ ...(requestedRelationshipId === null && relationshipCreated ? { allocatedId: targetRelationshipId } : {}),
1800
1848
  });
1801
1849
  continue;
1802
1850
  }
@@ -1880,38 +1928,65 @@ function applyMutations(document, mutations, options = {}) {
1880
1928
 
1881
1929
  if (mutation.type === 'addView') {
1882
1930
  requireObject(mutation.view, 'mutation.view');
1883
- if (findView(nextDocument.views, mutation.view.view_id)) {
1884
- throw new Error(`View '${mutation.view.view_id}' already exists`);
1885
- }
1886
- const candidates = findDuplicateViews(nextDocument.views, mutation.view);
1887
- const resolution = resolveDuplicateConflict({
1888
- onConflict: mutation.onConflict,
1889
- justification: mutation.justification,
1890
- label: `view (name '${mutation.view.view_name}')`,
1891
- }, candidates);
1892
- if (resolution.action === 'reuse') {
1893
- mutationSummaries.push({
1894
- type: mutation.type,
1895
- id: resolution.existing.view_id,
1896
- created: false,
1897
- reused: true,
1898
- reusedId: resolution.existing.view_id,
1899
- requestedId: mutation.view.view_id,
1900
- });
1901
- } else {
1902
- const newView = clone(mutation.view);
1903
- if (Array.isArray(newView.included_elements)) {
1904
- newView.included_elements = addUnique([], newView.included_elements);
1931
+ const requestedViewId = typeof mutation.view.view_id === 'string' && mutation.view.view_id !== ''
1932
+ ? mutation.view.view_id
1933
+ : null;
1934
+ let targetViewId;
1935
+ let viewCreated = false;
1936
+ let viewReused = false;
1937
+
1938
+ const existingById = requestedViewId ? findView(nextDocument.views, requestedViewId) : undefined;
1939
+ if (existingById) {
1940
+ // Explicit view_id that already exists: idempotent only for the same
1941
+ // (parent,name); otherwise fail loudly.
1942
+ const sameIdentity = (existingById.parent_element_id || '') === (mutation.view.parent_element_id || '')
1943
+ && normalizeDedupName(existingById.view_name) === normalizeDedupName(mutation.view.view_name);
1944
+ if (!sameIdentity) {
1945
+ throw new Error(
1946
+ `addView view_id '${requestedViewId}' is already used by a different view `
1947
+ + `(name '${existingById.view_name}', parent '${existingById.parent_element_id || ''}'). `
1948
+ + 'Choose another view_id (or omit it to auto-allocate one), or update it with updateArchitectureView.',
1949
+ );
1905
1950
  }
1906
- if (Array.isArray(newView.included_relationships)) {
1907
- newView.included_relationships = addUnique([], newView.included_relationships);
1951
+ targetViewId = requestedViewId;
1952
+ viewReused = true;
1953
+ } else {
1954
+ const candidates = findDuplicateViews(nextDocument.views, mutation.view);
1955
+ const resolution = resolveDuplicateConflict({
1956
+ onConflict: mutation.onConflict,
1957
+ justification: mutation.justification,
1958
+ label: `view (name '${mutation.view.view_name}')`,
1959
+ }, candidates);
1960
+ if (resolution.action === 'reuse') {
1961
+ targetViewId = resolution.existing.view_id;
1962
+ viewReused = true;
1963
+ } else {
1964
+ targetViewId = requestedViewId || allocateUniqueId(
1965
+ nextDocument.views.map(entry => entry.view_id),
1966
+ mutation.view.view_name,
1967
+ 'view',
1968
+ );
1969
+ const newView = { ...clone(mutation.view), view_id: targetViewId };
1970
+ if (Array.isArray(newView.included_elements)) {
1971
+ newView.included_elements = addUnique([], newView.included_elements);
1972
+ }
1973
+ if (Array.isArray(newView.included_relationships)) {
1974
+ newView.included_relationships = addUnique([], newView.included_relationships);
1975
+ }
1976
+ nextDocument.views.push(newView);
1977
+ upsertSubdiagramViewIntoElement(nextDocument, newView.parent_element_id, newView);
1978
+ touchedViewIds.add(newView.view_id);
1979
+ viewLimitCheckIds.add(newView.view_id);
1980
+ viewCreated = true;
1908
1981
  }
1909
- nextDocument.views.push(newView);
1910
- upsertSubdiagramViewIntoElement(nextDocument, newView.parent_element_id, newView);
1911
- touchedViewIds.add(newView.view_id);
1912
- viewLimitCheckIds.add(newView.view_id);
1913
- mutationSummaries.push({ type: mutation.type, id: newView.view_id });
1914
1982
  }
1983
+ mutationSummaries.push({
1984
+ type: mutation.type,
1985
+ id: targetViewId,
1986
+ created: viewCreated,
1987
+ ...(viewReused ? { reused: true, reusedId: targetViewId } : {}),
1988
+ ...(requestedViewId === null && viewCreated ? { allocatedId: targetViewId } : {}),
1989
+ });
1915
1990
  continue;
1916
1991
  }
1917
1992
 
@@ -1983,6 +2058,33 @@ function requireObject(value, label) {
1983
2058
  }
1984
2059
  }
1985
2060
 
2061
+ function slugifyId(seed) {
2062
+ return String(seed == null ? '' : seed)
2063
+ .toLowerCase()
2064
+ .replace(/[^a-z0-9]+/g, '-')
2065
+ .replace(/-{2,}/g, '-')
2066
+ .replace(/^-+|-+$/g, '');
2067
+ }
2068
+
2069
+ // One unified id strategy for the whole framework (issue #8): a semantic slug
2070
+ // derived from the entity's human name, made unique within its collection by a
2071
+ // numeric suffix. Callers MAY omit an id; the server allocates one. There is no
2072
+ // per-repository id strategy — ArchGraph has a single one.
2073
+ function allocateUniqueId(existingIds, seed, fallbackBase) {
2074
+ const taken = new Set((Array.isArray(existingIds) ? existingIds : []).map(String));
2075
+ const base = slugifyId(seed) || fallbackBase || 'item';
2076
+ if (!taken.has(base)) {
2077
+ return base;
2078
+ }
2079
+ for (let n = 2; n < 100000; n += 1) {
2080
+ const candidate = `${base}-${String(n).padStart(3, '0')}`;
2081
+ if (!taken.has(candidate)) {
2082
+ return candidate;
2083
+ }
2084
+ }
2085
+ return `${base}-${Date.now()}`;
2086
+ }
2087
+
1986
2088
  function requireId(value, label) {
1987
2089
  if (typeof value !== 'string' || value.length === 0) {
1988
2090
  throw new Error(`${label} must be a non-empty string`);
@@ -2877,6 +2979,18 @@ function compactMutationResponse(payload) {
2877
2979
  status: payload && payload.status,
2878
2980
  written: Boolean(payload && payload.written),
2879
2981
  };
2982
+ // A successful write must tell the caller which id was used/allocated and whether
2983
+ // it created or reused — otherwise an omitted (auto-allocated) id is invisible
2984
+ // and an id collision would look like a create. Kept to a few fields (issue #8).
2985
+ if (Array.isArray(payload && payload.mutations) && payload.mutations.length > 0) {
2986
+ compact.mutations = payload.mutations.map((entry) => ({
2987
+ type: entry.type,
2988
+ id: entry.id,
2989
+ created: entry.created,
2990
+ ...(entry.reused ? { reused: true, reusedId: entry.reusedId } : {}),
2991
+ ...(entry.allocatedId ? { allocatedId: entry.allocatedId } : {}),
2992
+ }));
2993
+ }
2880
2994
  if (payload && payload.embeddingLifecycle && payload.embeddingLifecycle.state) {
2881
2995
  compact.embeddingLifecycle = { state: payload.embeddingLifecycle.state };
2882
2996
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "archgraph-argo-beta",
3
- "version": "0.27.0-beta.11",
3
+ "version": "0.27.0-beta.12",
4
4
  "description": "Deploy the ArchGraph ARGO toolchain, skills, and rules (schema, scripts, argo-init skill, global rule) with one command.",
5
5
  "license": "MIT",
6
6
  "bin": {