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

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.
@@ -134,7 +134,7 @@ const TOOLS = [
134
134
  },
135
135
  {
136
136
  name: 'getIntentElementContext',
137
- description: 'read-only query that returns an intent subgraph context for one element. Uses ArchiMate semantic dependency traversal with dependencyDepth and dependentDepth, preserving native subgraph elements, relationships, and views.',
137
+ description: 'read-only query that returns an intent subgraph context for one element. Uses ArchiMate semantic dependency traversal with dependencyDepth and dependentDepth, preserving native subgraph elements, relationships, and views. Output is bounded by maxBytes (default ARGO_CONTEXT_MAX_BYTES or 32000): beyond it non-focus members degrade to identity (id/type/name) with a complete id manifest under truncation, so the host never silently cuts the payload. On a large/hub element leave includeAttributes/includeTestcases off and prefer queryNeo4jGraph to locate ids, then read them narrowly.',
138
138
  inputSchema: intentElementContextInputSchema(),
139
139
  },
140
140
  {
@@ -343,8 +343,9 @@ function intentElementContextInputSchema() {
343
343
  dependentDepth: { type: 'number', description: 'Default: 1. Semantic dependents that rely on the focus element.' },
344
344
  associationDepth: { type: 'number', description: 'Default: 1. Association neighbors are expanded at least one layer.' },
345
345
  associationNeighborDependencyDepth: { type: 'number', description: 'Default: 0. Optional dependency expansion from association neighbors.' },
346
- includeAttributes: { type: 'boolean', description: 'Default: false. Include `attributes` (commit/session/release ledgers) verbatim; omitted by default from this structural read (the focus element always keeps its own).' },
347
- includeTestcases: { type: 'boolean', description: 'Default: false. Include member `testcases` verbatim; omitted by default from this structural read.' },
346
+ includeAttributes: { type: 'boolean', description: 'Default: false. Include `attributes` (commit/session/release ledgers) verbatim; omitted by default from this structural read (the focus element always keeps its own). On a hub element this ledger can dominate the payload.' },
347
+ includeTestcases: { type: 'boolean', description: 'Default: false. Include member `testcases` verbatim; omitted by default from this structural read. On a hub element this can be large.' },
348
+ maxBytes: { type: 'number', description: 'Optional output budget in UTF-8 bytes. Default: ARGO_CONTEXT_MAX_BYTES env or 32000. 0 = unlimited. Above the budget, non-focus members degrade to identity (id/type/name) with a complete id manifest under `truncation`; the payload is never silently truncated by the host.' },
348
349
  },
349
350
  additionalProperties: false,
350
351
  };
@@ -101,6 +101,7 @@ const HOST_ONLY_ENV_KEYS = Object.freeze([
101
101
  'ARGO_SEMANTIC_DEDUP_THRESHOLD',
102
102
  'ARGO_COST_PROFILER',
103
103
  'ARGO_COST_TRACE_MAX_BYTES',
104
+ 'ARGO_CONTEXT_MAX_BYTES',
104
105
  ]);
105
106
  const PROHIBITED_RUNTIME_FIELD_KEYS = Object.freeze(['neo4jUri', 'embeddingCredential']);
106
107
  const SECRET_KEYS = new Set(['ARGO_NEO4J_DATABASE_PASSWORD', 'QWEN_KEY', 'ARGO_RERANK_API_KEY', EMBEDDING_API_KEY_KEY]);
@@ -227,12 +227,12 @@ const TOOLS = [
227
227
  },
228
228
  {
229
229
  name: 'getIntentElementContext',
230
- description: 'read-only query that returns an intent subgraph context for one element. Uses ArchiMate semantic dependency traversal with dependencyDepth and dependentDepth, preserving native subgraph elements, relationships, and views.',
230
+ description: 'read-only query that returns an intent subgraph context for one element. Uses ArchiMate semantic dependency traversal with dependencyDepth and dependentDepth, preserving native subgraph elements, relationships, and views. Output is bounded by maxBytes (default ARGO_CONTEXT_MAX_BYTES or 32000): beyond it non-focus members degrade to identity (id/type/name) and a complete id manifest is returned under truncation, so the host never silently cuts the payload. On a large/hub element leave includeAttributes/includeTestcases off (they are the ledger and can dominate the size) and prefer queryNeo4jGraph to locate ids, then read them narrowly.',
231
231
  inputSchema: intentElementContextInputSchema(),
232
232
  },
233
233
  {
234
234
  name: 'getArchitectureViewContext',
235
- description: 'read-only query that resolves one view by view_id into its complete membership: the view object, every member element (from included_elements), every member relationship (from included_relationships), the parent element, and optionally child sub-views declared by member elements. Resolves ids into full canonical objects instead of returning raw id lists. Optional includeEaGeometry (default false) additionally returns the EA diagram geometry of the resolved view: element boxes plus each connector ROUTE (t_diagramlinks.Path as `path` + parsed `points`, with the non-route Geometry override kept separately under `geometry`).',
235
+ description: 'read-only query that resolves one view by view_id into its complete membership: the view object, every member element (from included_elements), every member relationship (from included_relationships), the parent element, and optionally child sub-views declared by member elements. Resolves ids into full canonical objects instead of returning raw id lists. Output is bounded by maxBytes (default ARGO_CONTEXT_MAX_BYTES or 32000): beyond it members degrade to identity (id/type/name) with a complete id manifest under truncation. Optional includeEaGeometry (default false) additionally returns the EA diagram geometry of the resolved view: element boxes plus each connector ROUTE (t_diagramlinks.Path as `path` + parsed `points`, with the non-route Geometry override kept separately under `geometry`).',
236
236
  inputSchema: viewContextInputSchema(),
237
237
  },
238
238
  {
@@ -483,8 +483,9 @@ function intentElementContextInputSchema() {
483
483
  dependentDepth: { type: 'number', description: 'Default: 1. Semantic dependents that rely on the focus element.' },
484
484
  associationDepth: { type: 'number', description: 'Default: 1. Association neighbors are expanded at least one layer.' },
485
485
  associationNeighborDependencyDepth: { type: 'number', description: 'Default: 0. Optional dependency expansion from association neighbors.' },
486
- includeAttributes: { type: 'boolean', description: 'Default: false. Include `attributes` (commit/session/release ledgers) verbatim. Omitted by default from this structural read; the focus element always keeps its own. Semantic retrieval embeds attributes, so semantic hits keep them.' },
487
- includeTestcases: { type: 'boolean', description: 'Default: false. Include member `testcases` verbatim. Omitted by default from this structural read (bookkeeping); pass true when you need acceptance cases. Semantic retrieval embeds testcase descriptions, so semantic hits keep them.' },
486
+ includeAttributes: { type: 'boolean', description: 'Default: false. Include `attributes` (commit/session/release ledgers) verbatim. Omitted by default from this structural read; the focus element always keeps its own. Semantic retrieval embeds attributes, so semantic hits keep them. On a hub element this ledger can dominate the payload — prefer leaving it off and reading bookkeeping narrowly.' },
487
+ includeTestcases: { type: 'boolean', description: 'Default: false. Include member `testcases` verbatim. Omitted by default from this structural read (bookkeeping); pass true when you need acceptance cases. Semantic retrieval embeds testcase descriptions, so semantic hits keep them. On a hub element this can be large — prefer leaving it off.' },
488
+ maxBytes: { type: 'number', description: 'Optional output budget in UTF-8 bytes (the exact serialized response). Default: ARGO_CONTEXT_MAX_BYTES env or 32000. 0 = unlimited. When the payload exceeds the budget, non-focus members degrade to identity (id/type/name) and a complete id manifest is returned under `truncation` — the payload is never silently truncated by the host.' },
488
489
  },
489
490
  additionalProperties: false,
490
491
  };
@@ -502,6 +503,7 @@ function viewContextInputSchema() {
502
503
  includeAttributes: { type: 'boolean', description: 'Default: false. Include member/relationship `attributes` (commit/session/release ledgers) verbatim. Omitted by default from this structural read (bookkeeping); pass true when you need provenance.' },
503
504
  includeTestcases: { type: 'boolean', description: 'Default: false. Include member `testcases` verbatim. Omitted by default from this structural read; pass true for acceptance-case lookups.' },
504
505
  includeEaGeometry: { type: 'boolean', description: 'Default: false (opt-in). When true, additionally resolve the diagram GEOMETRY (element boxes + connector line routes) for this view from the workspace EA model (.qea) and return it under a `geometry` field aligned by schema id with the resolved members. Each geometry relationship carries: `path` (the EA route from t_diagramlinks.Path, "" when EA auto-routes), `points` (the parsed [{x,y}] waypoints), `edge` (the EDGE route-style token or null) and `geometry` (the raw SX/SY/EX/EY override string, which contains NO waypoints). By default the EA model is never touched and no `geometry` field is returned; a missing EA model/diagram yields geometry.present=false, never an error.' },
506
+ maxBytes: { type: 'number', description: 'Optional output budget in UTF-8 bytes (the exact serialized response). Default: ARGO_CONTEXT_MAX_BYTES env or 32000. 0 = unlimited. When the payload exceeds the budget, members degrade to identity (id/type/name) and a complete id manifest is returned under `truncation` — the payload is never silently truncated by the host.' },
505
507
  },
506
508
  additionalProperties: false,
507
509
  };
@@ -686,6 +688,217 @@ function buildAgentProjection(omitted) {
686
688
  };
687
689
  }
688
690
 
691
+ // ---------------------------------------------------------------------------
692
+ // Context output budget (bounded, well-formed structural reads)
693
+ // ---------------------------------------------------------------------------
694
+ // A hub element/view can expand a semantic subgraph to tens of KB, which the
695
+ // HOST then cuts mid-JSON — the agent receives a malformed partial observation.
696
+ // This budget makes the ceiling the framework's, not the host's: above maxBytes
697
+ // the non-focus members degrade to identity (id/type/name), the focus element +
698
+ // boundary/explorationHints are kept, and EVERY included id is listed under
699
+ // `truncation` — so the payload is always valid JSON and always navigable.
700
+ // Default (or ARGO_CONTEXT_MAX_BYTES); 0 = unlimited. Semantic retrieval is NOT
701
+ // affected (only these two structural builders).
702
+ const DEFAULT_CONTEXT_MAX_BYTES = 32000;
703
+ const CONTEXT_BUDGET_NOTE =
704
+ 'The full payload exceeded maxBytes, so non-focus members are reduced to identity '
705
+ + '(id/type/name). The focus element and boundary/explorationHints are kept and every '
706
+ + 'included id is listed here. Raise maxBytes (0 = unlimited) or narrow the traversal '
707
+ + '(dependencyDepth/dependentDepth) to read details.';
708
+
709
+ function resolveContextMaxBytes(args = {}) {
710
+ const raw = args && args.maxBytes !== undefined ? args.maxBytes : process.env.ARGO_CONTEXT_MAX_BYTES;
711
+ if (raw === undefined || raw === null || raw === '') {
712
+ return DEFAULT_CONTEXT_MAX_BYTES;
713
+ }
714
+ const numeric = Number(raw);
715
+ if (!Number.isFinite(numeric) || numeric < 0) {
716
+ return DEFAULT_CONTEXT_MAX_BYTES;
717
+ }
718
+ return Math.floor(numeric);
719
+ }
720
+
721
+ // Budget is measured on the EXACT serialization the caller receives
722
+ // (`toolResult` pretty-prints with 2 spaces), in UTF-8 bytes.
723
+ function payloadByteLength(value) {
724
+ try { return Buffer.byteLength(JSON.stringify(value, null, 2)); } catch (_) { return 0; }
725
+ }
726
+
727
+ function identityElementRecord(element) {
728
+ return { id: element.id, name: element.name, type: element.type };
729
+ }
730
+
731
+ function identityRelationshipRecord(relationship) {
732
+ return {
733
+ id: relationship.id,
734
+ name: relationship.name,
735
+ type: relationship.type,
736
+ source_id: relationship.source_id,
737
+ target_id: relationship.target_id,
738
+ };
739
+ }
740
+
741
+ function identityViewRecord(view) {
742
+ return { view_id: view.view_id, view_name: view.view_name };
743
+ }
744
+
745
+ function budgetTruncationBase(result, maxBytes, fullBytes, ids) {
746
+ return {
747
+ truncated: true,
748
+ reason: 'context_budget_exceeded',
749
+ maxBytes,
750
+ fullBytes,
751
+ includedElementIds: ids.elements,
752
+ includedRelationshipIds: ids.relationships,
753
+ includedViewIds: ids.views,
754
+ note: CONTEXT_BUDGET_NOTE,
755
+ };
756
+ }
757
+
758
+ // Shrink the manifest id lists (last resort) so even a pathological hub stays
759
+ // within budget. The focus id is never dropped; `manifestTruncated` records any
760
+ // real loss of a listed id.
761
+ function trimManifestToBudget(result, maxBytes) {
762
+ const truncation = result.truncation;
763
+ const arrays = ['includedElementIds', 'includedRelationshipIds', 'includedViewIds'];
764
+ const focusId = result.focusElementId;
765
+ for (let ratio = 0.9; ratio >= 0; ratio -= 0.1) {
766
+ for (const key of arrays) {
767
+ const full = truncation[key] || [];
768
+ const kept = full.slice(0, Math.ceil(full.length * ratio));
769
+ if (key === 'includedElementIds' && focusId && !kept.includes(focusId)) {
770
+ kept.unshift(focusId);
771
+ }
772
+ truncation[key] = kept;
773
+ }
774
+ truncation.manifestTruncated = true;
775
+ if (payloadByteLength(result) <= maxBytes) return;
776
+ }
777
+ truncation.manifestTruncated = true;
778
+ }
779
+
780
+ function applyContextBudget(result, maxBytes) {
781
+ if (!result || result.status !== 'passed' || !maxBytes || maxBytes <= 0) {
782
+ return result;
783
+ }
784
+ const fullBytes = payloadByteLength(result);
785
+ if (fullBytes <= maxBytes) {
786
+ return result;
787
+ }
788
+
789
+ const subgraph = result.subgraph || {};
790
+ const elements = Array.isArray(subgraph.elements) ? subgraph.elements : [];
791
+ const relationships = Array.isArray(subgraph.relationships) ? subgraph.relationships : [];
792
+ const views = Array.isArray(subgraph.views) ? subgraph.views : [];
793
+ const focusId = result.focusElementId;
794
+ const ids = {
795
+ elements: elements.map((entry) => entry.id),
796
+ relationships: relationships.map((entry) => entry.id),
797
+ views: views.map((entry) => entry.view_id),
798
+ };
799
+ const truncated = (tier) => budgetTruncationBase(result, maxBytes, fullBytes, ids);
800
+ const nonFocusCount = elements.filter((entry) => entry.id !== focusId).length;
801
+
802
+ const compact = {
803
+ ...result,
804
+ subgraph: {
805
+ ...subgraph,
806
+ elements: elements.map((entry) => (entry.id === focusId ? entry : identityElementRecord(entry))),
807
+ relationships: relationships.map(identityRelationshipRecord),
808
+ views: views.map(identityViewRecord),
809
+ },
810
+ truncation: { ...truncated('identity'), omittedElementDetails: nonFocusCount },
811
+ };
812
+ if (payloadByteLength(compact) <= maxBytes) {
813
+ return compact;
814
+ }
815
+
816
+ const idsOnly = {
817
+ ...result,
818
+ subgraph: {
819
+ ...subgraph,
820
+ elements: elements.map((entry) => (entry.id === focusId ? entry : { id: entry.id })),
821
+ relationships: relationships.map((entry) => ({ id: entry.id })),
822
+ views: views.map((entry) => ({ view_id: entry.view_id })),
823
+ },
824
+ truncation: truncated('ids-only'),
825
+ };
826
+ if (payloadByteLength(idsOnly) <= maxBytes) {
827
+ return idsOnly;
828
+ }
829
+
830
+ const manifestOnly = {
831
+ ...result,
832
+ subgraph: {
833
+ elements: elements.filter((entry) => entry.id === focusId),
834
+ relationships: [],
835
+ views: [],
836
+ },
837
+ truncation: truncated('manifest-only'),
838
+ };
839
+ trimManifestToBudget(manifestOnly, maxBytes);
840
+ return manifestOnly;
841
+ }
842
+
843
+ function applyViewContextBudget(result, maxBytes) {
844
+ if (!result || result.status !== 'passed' || !maxBytes || maxBytes <= 0) {
845
+ return result;
846
+ }
847
+ const fullBytes = payloadByteLength(result);
848
+ if (fullBytes <= maxBytes) {
849
+ return result;
850
+ }
851
+
852
+ const elements = Array.isArray(result.elements) ? result.elements : [];
853
+ const relationships = Array.isArray(result.relationships) ? result.relationships : [];
854
+ const childViews = Array.isArray(result.childViews) ? result.childViews : [];
855
+ const ids = {
856
+ elements: elements.map((entry) => entry.id),
857
+ relationships: relationships.map((entry) => entry.id),
858
+ views: childViews.map((entry) => entry.view_id),
859
+ };
860
+ const strippedView = result.view
861
+ ? { ...result.view, included_elements: [], included_relationships: [] }
862
+ : result.view;
863
+ const truncated = (tier) => ({ ...budgetTruncationBase(result, maxBytes, fullBytes, ids), tier });
864
+
865
+ const compact = {
866
+ ...result,
867
+ elements: elements.map(identityElementRecord),
868
+ relationships: relationships.map(identityRelationshipRecord),
869
+ parentElement: result.parentElement ? identityElementRecord(result.parentElement) : result.parentElement,
870
+ childViews: childViews.map(identityViewRecord),
871
+ truncation: { ...truncated('identity'), omittedElementDetails: elements.length },
872
+ };
873
+ if (payloadByteLength(compact) <= maxBytes) {
874
+ return compact;
875
+ }
876
+
877
+ const idsOnly = {
878
+ ...result,
879
+ elements: elements.map((entry) => ({ id: entry.id })),
880
+ relationships: relationships.map((entry) => ({ id: entry.id })),
881
+ parentElement: result.parentElement ? { id: result.parentElement.id } : result.parentElement,
882
+ childViews: childViews.map((entry) => ({ view_id: entry.view_id })),
883
+ truncation: truncated('ids-only'),
884
+ };
885
+ if (payloadByteLength(idsOnly) <= maxBytes) {
886
+ return idsOnly;
887
+ }
888
+
889
+ const manifestOnly = {
890
+ ...result,
891
+ view: strippedView,
892
+ elements: [],
893
+ relationships: [],
894
+ parentElement: null,
895
+ childViews: [],
896
+ truncation: truncated('manifest-only'),
897
+ };
898
+ trimManifestToBudget(manifestOnly, maxBytes);
899
+ return manifestOnly;
900
+ }
901
+
689
902
  function buildIntentElementContext(context, args = {}) {
690
903
  const profile = args.profile || 'generic-agent';
691
904
  const focusResult = resolveFocusElement(context.document, args);
@@ -812,7 +1025,7 @@ function buildIntentElementContext(context, args = {}) {
812
1025
  };
813
1026
  const projection = buildAgentProjection(omitted);
814
1027
  if (projection) result.projection = projection;
815
- return result;
1028
+ return applyContextBudget(result, resolveContextMaxBytes(args));
816
1029
  }
817
1030
 
818
1031
  // ---------------------------------------------------------------------------
@@ -956,7 +1169,7 @@ function buildViewContext(context, args = {}) {
956
1169
  }
957
1170
  const projection = buildAgentProjection(omitted);
958
1171
  if (projection) result.projection = projection;
959
- return result;
1172
+ return applyViewContextBudget(result, resolveContextMaxBytes(args));
960
1173
  }
961
1174
 
962
1175
  function resolveFocusElement(document, args) {
@@ -4863,6 +5076,9 @@ module.exports = {
4863
5076
  buildGetSystemArchitectureStructuredContent,
4864
5077
  TOOLS,
4865
5078
  applyMutations,
5079
+ applyContextBudget,
5080
+ applyViewContextBudget,
5081
+ resolveContextMaxBytes,
4866
5082
  buildBusinessSemanticSummary,
4867
5083
  buildSemanticDedupAdvisory,
4868
5084
  selectCreatedElementAdds,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "archgraph-argo-beta",
3
- "version": "0.27.0-beta.12",
3
+ "version": "0.27.0-beta.13",
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": {