@llm-dev-ops/agentics-cli 1.4.4 → 1.4.7

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.
Files changed (167) hide show
  1. package/dist/adapters/base-adapter.d.ts +117 -0
  2. package/dist/adapters/base-adapter.d.ts.map +1 -1
  3. package/dist/adapters/base-adapter.js +143 -0
  4. package/dist/adapters/base-adapter.js.map +1 -1
  5. package/dist/agents/cli-ux-agent.d.ts.map +1 -1
  6. package/dist/agents/cli-ux-agent.js +2 -1
  7. package/dist/agents/cli-ux-agent.js.map +1 -1
  8. package/dist/auth/identity-resolver.d.ts +21 -0
  9. package/dist/auth/identity-resolver.d.ts.map +1 -0
  10. package/dist/auth/identity-resolver.js +68 -0
  11. package/dist/auth/identity-resolver.js.map +1 -0
  12. package/dist/auth/index.d.ts +2 -0
  13. package/dist/auth/index.d.ts.map +1 -1
  14. package/dist/auth/index.js +2 -0
  15. package/dist/auth/index.js.map +1 -1
  16. package/dist/auth/role-permissions.d.ts +12 -0
  17. package/dist/auth/role-permissions.d.ts.map +1 -0
  18. package/dist/auth/role-permissions.js +43 -0
  19. package/dist/auth/role-permissions.js.map +1 -0
  20. package/dist/cli/index.js +162 -157
  21. package/dist/cli/index.js.map +1 -1
  22. package/dist/commands/deploy.d.ts +4 -4
  23. package/dist/commands/deploy.d.ts.map +1 -1
  24. package/dist/commands/deploy.js +83 -21
  25. package/dist/commands/deploy.js.map +1 -1
  26. package/dist/commands/erp.d.ts +1 -1
  27. package/dist/commands/erp.d.ts.map +1 -1
  28. package/dist/commands/erp.js +65 -5
  29. package/dist/commands/erp.js.map +1 -1
  30. package/dist/commands/export.d.ts +5 -5
  31. package/dist/commands/export.js +5 -5
  32. package/dist/commands/inspect.d.ts +28 -0
  33. package/dist/commands/inspect.d.ts.map +1 -1
  34. package/dist/commands/inspect.js +113 -0
  35. package/dist/commands/inspect.js.map +1 -1
  36. package/dist/commands/login.d.ts +8 -6
  37. package/dist/commands/login.d.ts.map +1 -1
  38. package/dist/commands/login.js +171 -89
  39. package/dist/commands/login.js.map +1 -1
  40. package/dist/commands/logout.d.ts.map +1 -1
  41. package/dist/commands/logout.js +4 -1
  42. package/dist/commands/logout.js.map +1 -1
  43. package/dist/commands/plan.d.ts +8 -5
  44. package/dist/commands/plan.d.ts.map +1 -1
  45. package/dist/commands/plan.js +88 -63
  46. package/dist/commands/plan.js.map +1 -1
  47. package/dist/commands/policy.d.ts +53 -0
  48. package/dist/commands/policy.d.ts.map +1 -1
  49. package/dist/commands/policy.js +201 -5
  50. package/dist/commands/policy.js.map +1 -1
  51. package/dist/commands/quantify.d.ts +1 -1
  52. package/dist/commands/quantify.d.ts.map +1 -1
  53. package/dist/commands/quantify.js +2 -4
  54. package/dist/commands/quantify.js.map +1 -1
  55. package/dist/commands/simulate.d.ts +3 -2
  56. package/dist/commands/simulate.d.ts.map +1 -1
  57. package/dist/commands/simulate.js +154 -37
  58. package/dist/commands/simulate.js.map +1 -1
  59. package/dist/commands/usage.d.ts +3 -3
  60. package/dist/commands/usage.js +7 -7
  61. package/dist/commands/usage.js.map +1 -1
  62. package/dist/commands/whoami.d.ts +6 -0
  63. package/dist/commands/whoami.d.ts.map +1 -1
  64. package/dist/commands/whoami.js +44 -7
  65. package/dist/commands/whoami.js.map +1 -1
  66. package/dist/contracts/adr-002-operational-enforcement.d.ts +684 -0
  67. package/dist/contracts/adr-002-operational-enforcement.d.ts.map +1 -0
  68. package/dist/contracts/adr-002-operational-enforcement.js +671 -0
  69. package/dist/contracts/adr-002-operational-enforcement.js.map +1 -0
  70. package/dist/contracts/adr-003-governance-architecture.d.ts +766 -0
  71. package/dist/contracts/adr-003-governance-architecture.d.ts.map +1 -0
  72. package/dist/contracts/adr-003-governance-architecture.js +773 -0
  73. package/dist/contracts/adr-003-governance-architecture.js.map +1 -0
  74. package/dist/contracts/adr-004-enterprise-integration-memory.d.ts +1150 -0
  75. package/dist/contracts/adr-004-enterprise-integration-memory.d.ts.map +1 -0
  76. package/dist/contracts/adr-004-enterprise-integration-memory.js +1158 -0
  77. package/dist/contracts/adr-004-enterprise-integration-memory.js.map +1 -0
  78. package/dist/contracts/adr-005-system-coherence-drift-self-governance.d.ts +1393 -0
  79. package/dist/contracts/adr-005-system-coherence-drift-self-governance.d.ts.map +1 -0
  80. package/dist/contracts/adr-005-system-coherence-drift-self-governance.js +1371 -0
  81. package/dist/contracts/adr-005-system-coherence-drift-self-governance.js.map +1 -0
  82. package/dist/contracts/adr-command-semantics.d.ts +150 -0
  83. package/dist/contracts/adr-command-semantics.d.ts.map +1 -0
  84. package/dist/contracts/adr-command-semantics.js +984 -0
  85. package/dist/contracts/adr-command-semantics.js.map +1 -0
  86. package/dist/contracts/index.d.ts +5 -0
  87. package/dist/contracts/index.d.ts.map +1 -1
  88. package/dist/contracts/index.js +16 -0
  89. package/dist/contracts/index.js.map +1 -1
  90. package/dist/enterprise/index.d.ts +16 -0
  91. package/dist/enterprise/index.d.ts.map +1 -0
  92. package/dist/enterprise/index.js +17 -0
  93. package/dist/enterprise/index.js.map +1 -0
  94. package/dist/enterprise/integration-registry.d.ts +73 -0
  95. package/dist/enterprise/integration-registry.d.ts.map +1 -0
  96. package/dist/enterprise/integration-registry.js +252 -0
  97. package/dist/enterprise/integration-registry.js.map +1 -0
  98. package/dist/enterprise/lineage.d.ts +73 -0
  99. package/dist/enterprise/lineage.d.ts.map +1 -0
  100. package/dist/enterprise/lineage.js +218 -0
  101. package/dist/enterprise/lineage.js.map +1 -0
  102. package/dist/gates/argument-guard.d.ts +39 -0
  103. package/dist/gates/argument-guard.d.ts.map +1 -0
  104. package/dist/gates/argument-guard.js +180 -0
  105. package/dist/gates/argument-guard.js.map +1 -0
  106. package/dist/gates/auth-session-gate.d.ts +47 -0
  107. package/dist/gates/auth-session-gate.d.ts.map +1 -0
  108. package/dist/gates/auth-session-gate.js +151 -0
  109. package/dist/gates/auth-session-gate.js.map +1 -0
  110. package/dist/gates/execution-gate.d.ts +12 -17
  111. package/dist/gates/execution-gate.d.ts.map +1 -1
  112. package/dist/gates/execution-gate.js +74 -46
  113. package/dist/gates/execution-gate.js.map +1 -1
  114. package/dist/gates/index.d.ts +25 -2
  115. package/dist/gates/index.d.ts.map +1 -1
  116. package/dist/gates/index.js +31 -2
  117. package/dist/gates/index.js.map +1 -1
  118. package/dist/gates/lineage-gate.d.ts +55 -0
  119. package/dist/gates/lineage-gate.d.ts.map +1 -0
  120. package/dist/gates/lineage-gate.js +127 -0
  121. package/dist/gates/lineage-gate.js.map +1 -0
  122. package/dist/gates/output-format-gate.d.ts +54 -0
  123. package/dist/gates/output-format-gate.d.ts.map +1 -0
  124. package/dist/gates/output-format-gate.js +136 -0
  125. package/dist/gates/output-format-gate.js.map +1 -0
  126. package/dist/gates/service-health-gate.d.ts +56 -0
  127. package/dist/gates/service-health-gate.d.ts.map +1 -0
  128. package/dist/gates/service-health-gate.js +179 -0
  129. package/dist/gates/service-health-gate.js.map +1 -0
  130. package/dist/modules/help-renderer.d.ts +25 -0
  131. package/dist/modules/help-renderer.d.ts.map +1 -0
  132. package/dist/modules/help-renderer.js +163 -0
  133. package/dist/modules/help-renderer.js.map +1 -0
  134. package/dist/modules/index.d.ts +1 -0
  135. package/dist/modules/index.d.ts.map +1 -1
  136. package/dist/modules/index.js +1 -0
  137. package/dist/modules/index.js.map +1 -1
  138. package/dist/server/index.d.ts +2 -0
  139. package/dist/server/index.d.ts.map +1 -1
  140. package/dist/server/index.js +16 -1
  141. package/dist/server/index.js.map +1 -1
  142. package/dist/server/routes/auth.d.ts.map +1 -1
  143. package/dist/server/routes/auth.js +45 -8
  144. package/dist/server/routes/auth.js.map +1 -1
  145. package/dist/server/routes/identity.d.ts +9 -0
  146. package/dist/server/routes/identity.d.ts.map +1 -0
  147. package/dist/server/routes/identity.js +100 -0
  148. package/dist/server/routes/identity.js.map +1 -0
  149. package/dist/server/routes/index.d.ts +2 -0
  150. package/dist/server/routes/index.d.ts.map +1 -1
  151. package/dist/server/routes/index.js +2 -0
  152. package/dist/server/routes/index.js.map +1 -1
  153. package/dist/server/routes/lineage.d.ts +15 -0
  154. package/dist/server/routes/lineage.d.ts.map +1 -0
  155. package/dist/server/routes/lineage.js +128 -0
  156. package/dist/server/routes/lineage.js.map +1 -0
  157. package/dist/types/index.d.ts +134 -0
  158. package/dist/types/index.d.ts.map +1 -1
  159. package/dist/utils/identity-store.d.ts +31 -0
  160. package/dist/utils/identity-store.d.ts.map +1 -0
  161. package/dist/utils/identity-store.js +97 -0
  162. package/dist/utils/identity-store.js.map +1 -0
  163. package/dist/utils/index.d.ts +2 -0
  164. package/dist/utils/index.d.ts.map +1 -1
  165. package/dist/utils/index.js +1 -0
  166. package/dist/utils/index.js.map +1 -1
  167. package/package.json +4 -4
@@ -0,0 +1,218 @@
1
+ /**
2
+ * Lineage Tracking Module (ADR-004, Domain 2)
3
+ *
4
+ * PURPOSE: Track parent-child relationships between simulation artifacts.
5
+ * Ruvector stores lineage as first-class data, not inferred from timestamps.
6
+ *
7
+ * INVARIANTS ENFORCED:
8
+ * - Invariant 1: Every simulation has a memory footprint
9
+ * - Invariant 2: Every integration/ERP mapping derives from a simulation
10
+ * - Invariant 3: No integration proposal without traceability
11
+ * - Invariant 7: CLI is only path for artifact creation
12
+ *
13
+ * FORBIDDEN:
14
+ * - Creating lineage without a simulation parent
15
+ * - Querying live enterprise systems
16
+ * - Storing credentials or tokens
17
+ * - Business logic (lineage is structural, not behavioral)
18
+ */
19
+ import * as crypto from 'node:crypto';
20
+ // ============================================================================
21
+ // Lineage Record Construction
22
+ // ============================================================================
23
+ /**
24
+ * Create a lineage record for an artifact.
25
+ * Every artifact persisted in Ruvector must have a corresponding lineage record.
26
+ *
27
+ * @param artifactId - The artifact this lineage entry describes
28
+ * @param category - The type of artifact
29
+ * @param simulationId - The parent simulation (Invariant 2)
30
+ * @param decisionContext - The natural language input that seeded synthesis
31
+ * @param attribution - Identity attribution (user_id, org_id)
32
+ * @param planId - The plan this artifact belongs to (optional)
33
+ */
34
+ export function createLineageRecord(artifactId, category, simulationId, decisionContext, attribution, planId) {
35
+ return {
36
+ id: `lin-${crypto.randomUUID()}`,
37
+ artifact_id: artifactId,
38
+ artifact_category: category,
39
+ simulation_id: simulationId,
40
+ plan_id: planId,
41
+ decision_context: decisionContext,
42
+ attribution,
43
+ governance: {
44
+ gate_pipeline_version: '1.0.0',
45
+ synthesis_classification: classifySynthesis(category),
46
+ },
47
+ created_at: new Date().toISOString(),
48
+ };
49
+ }
50
+ /**
51
+ * Determine the synthesis classification for an artifact category.
52
+ * Mirrors ADR-001 classifications.
53
+ */
54
+ function classifySynthesis(category) {
55
+ switch (category) {
56
+ case 'simulation':
57
+ case 'plan':
58
+ case 'integration_mapping':
59
+ case 'erp_proposal':
60
+ case 'cost_projection':
61
+ case 'risk_assessment':
62
+ return 'SYNTHESIS_REQUIRED';
63
+ case 'deployment':
64
+ case 'decision':
65
+ return 'COMMITMENT_GRADE';
66
+ default:
67
+ return 'SYNTHESIS_REQUIRED';
68
+ }
69
+ }
70
+ // ============================================================================
71
+ // Simulation Memory Record Construction
72
+ // ============================================================================
73
+ /**
74
+ * Create a simulation memory record for Ruvector persistence (Invariant 1).
75
+ * Called when a simulation is initiated through the CLI.
76
+ */
77
+ export function createSimulationMemoryRecord(id, intent, attribution) {
78
+ const now = new Date().toISOString();
79
+ return {
80
+ id,
81
+ type: 'simulation',
82
+ intent,
83
+ status: 'created',
84
+ attribution,
85
+ artifact_ids: [],
86
+ created_at: now,
87
+ updated_at: now,
88
+ checksum: computeChecksum({ id, intent, created_at: now }),
89
+ };
90
+ }
91
+ /**
92
+ * Update a simulation memory record with completion data.
93
+ */
94
+ export function completeSimulationMemoryRecord(record, result, artifactIds) {
95
+ const now = new Date().toISOString();
96
+ return {
97
+ ...record,
98
+ status: 'completed',
99
+ result,
100
+ artifact_ids: [...record.artifact_ids, ...artifactIds],
101
+ updated_at: now,
102
+ checksum: computeChecksum({ ...record, result, updated_at: now }),
103
+ };
104
+ }
105
+ /**
106
+ * Mark a simulation memory record as failed.
107
+ */
108
+ export function failSimulationMemoryRecord(record, error) {
109
+ const now = new Date().toISOString();
110
+ return {
111
+ ...record,
112
+ status: 'failed',
113
+ result: { error },
114
+ updated_at: now,
115
+ checksum: computeChecksum({ ...record, error, updated_at: now }),
116
+ };
117
+ }
118
+ // ============================================================================
119
+ // Integration Proposal Construction
120
+ // ============================================================================
121
+ /**
122
+ * Create an integration proposal derived from a simulation (Invariant 2).
123
+ * Proposals describe what would change, not what has changed.
124
+ */
125
+ export function createIntegrationProposal(integrationName, proposedChanges, risks, dependencies, simulationId, attribution, planId) {
126
+ return {
127
+ id: `intprop-${crypto.randomUUID()}`,
128
+ type: 'integration_proposal',
129
+ integration_name: integrationName,
130
+ proposed_changes: proposedChanges,
131
+ risks,
132
+ dependencies,
133
+ simulation_id: simulationId,
134
+ plan_id: planId,
135
+ attribution,
136
+ created_at: new Date().toISOString(),
137
+ };
138
+ }
139
+ // ============================================================================
140
+ // ERP Surface Mapping Construction
141
+ // ============================================================================
142
+ /**
143
+ * Create an ERP Surface mapping derived from a simulation (Invariant 6).
144
+ * ERP Surface never initiates — it receives proposed implementations.
145
+ */
146
+ export function createErpSurfaceMapping(erpType, entityType, proposedImplementation, simulationId, integrationProposalIds, attribution) {
147
+ return {
148
+ id: `erpmap-${crypto.randomUUID()}`,
149
+ type: 'erp_mapping',
150
+ erp_type: erpType,
151
+ entity_type: entityType,
152
+ proposed_implementation: proposedImplementation,
153
+ simulation_id: simulationId,
154
+ integration_proposal_ids: integrationProposalIds,
155
+ attribution,
156
+ created_at: new Date().toISOString(),
157
+ };
158
+ }
159
+ // ============================================================================
160
+ // Traceability Validation
161
+ // ============================================================================
162
+ /**
163
+ * Validate that an artifact has a valid simulation parent.
164
+ * Returns a validation result with specific error messaging.
165
+ *
166
+ * ADR-004, Invariant 3: No integration proposal exists without traceability.
167
+ */
168
+ export function validateTraceability(simulationId, artifactType) {
169
+ if (!simulationId) {
170
+ return {
171
+ valid: false,
172
+ message: `${artifactType} requires a simulation_id. ` +
173
+ `All enterprise artifacts must trace to a governed simulation ` +
174
+ `(ADR-004, Invariant 2).`,
175
+ };
176
+ }
177
+ if (typeof simulationId !== 'string' || simulationId.trim() === '') {
178
+ return {
179
+ valid: false,
180
+ message: `${artifactType} simulation_id must be a non-empty string. ` +
181
+ `Received: ${String(simulationId)}`,
182
+ };
183
+ }
184
+ return { valid: true, message: '' };
185
+ }
186
+ /**
187
+ * Validate that a lineage chain is complete.
188
+ * Checks that simulation → plan → artifact chain is traceable.
189
+ */
190
+ export function validateLineageChain(records) {
191
+ const missing = [];
192
+ for (const record of records) {
193
+ if (!record.simulation_id) {
194
+ missing.push(`Lineage ${record.id}: missing simulation_id`);
195
+ }
196
+ if (!record.attribution.created_by) {
197
+ missing.push(`Lineage ${record.id}: missing attribution.created_by`);
198
+ }
199
+ if (!record.attribution.org_id) {
200
+ missing.push(`Lineage ${record.id}: missing attribution.org_id`);
201
+ }
202
+ if (!record.decision_context) {
203
+ missing.push(`Lineage ${record.id}: missing decision_context`);
204
+ }
205
+ }
206
+ return {
207
+ complete: missing.length === 0,
208
+ missing,
209
+ };
210
+ }
211
+ // ============================================================================
212
+ // Internal Helpers
213
+ // ============================================================================
214
+ function computeChecksum(data) {
215
+ const canonical = JSON.stringify(data);
216
+ return crypto.createHash('sha256').update(canonical).digest('hex');
217
+ }
218
+ //# sourceMappingURL=lineage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lineage.js","sourceRoot":"","sources":["../../src/enterprise/lineage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAUtC,+EAA+E;AAC/E,8BAA8B;AAC9B,+EAA+E;AAE/E;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB,CACjC,UAAkB,EAClB,QAA0B,EAC1B,YAAoB,EACpB,eAAuB,EACvB,WAAwB,EACxB,MAAe;IAEf,OAAO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,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;YAC1B,OAAO,CAAC,IAAI,CAAC,WAAW,MAAM,CAAC,EAAE,yBAAyB,CAAC,CAAC;QAC9D,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,UAAU,EAAE,CAAC;YACnC,OAAO,CAAC,IAAI,CAAC,WAAW,MAAM,CAAC,EAAE,kCAAkC,CAAC,CAAC;QACvE,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;YAC/B,OAAO,CAAC,IAAI,CAAC,WAAW,MAAM,CAAC,EAAE,8BAA8B,CAAC,CAAC;QACnE,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC;YAC7B,OAAO,CAAC,IAAI,CAAC,WAAW,MAAM,CAAC,EAAE,4BAA4B,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,OAAO,CAAC,MAAM,KAAK,CAAC;QAC9B,OAAO;KACR,CAAC;AACJ,CAAC;AAED,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E,SAAS,eAAe,CAAC,IAAa;IACpC,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACvC,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACrE,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Argument Guard Gate (Gate 5)
3
+ *
4
+ * Runtime validation middleware derived from ADR-001 (Command Argument Semantics).
5
+ * This gate enforces:
6
+ *
7
+ * 1. ID vs Natural Language argument rules
8
+ * 2. Required argument presence
9
+ * 3. Synthesis allow/deny per command
10
+ * 4. Confirmation enforcement for irreversible commands
11
+ * 5. Deterministic, instructional error messages
12
+ *
13
+ * The ADR (adr-command-semantics.ts) is the authoritative policy.
14
+ * This gate is mechanically derived from it.
15
+ */
16
+ import type { CommandObject } from '../types/index.js';
17
+ import { type CommandSpec } from '../contracts/adr-command-semantics.js';
18
+ export interface ArgumentGuardResult {
19
+ allowed: boolean;
20
+ exitCode?: number;
21
+ message?: string;
22
+ spec?: CommandSpec;
23
+ }
24
+ /**
25
+ * Check if the given command object passes argument validation.
26
+ * Returns a result indicating whether the command may proceed.
27
+ */
28
+ export declare function checkArgumentGuard(cmd: CommandObject): ArgumentGuardResult;
29
+ /**
30
+ * Enforce the argument guard. Exits the process on failure.
31
+ * Follows the same pattern as other gates (execution-gate, auth-session-gate).
32
+ */
33
+ export declare function enforceArgumentGuard(cmd: CommandObject): void;
34
+ /**
35
+ * Check if a command requires argument validation.
36
+ * Built-in commands (help, version) are exempt.
37
+ */
38
+ export declare function requiresArgumentValidation(command: string): boolean;
39
+ //# sourceMappingURL=argument-guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"argument-guard.d.ts","sourceRoot":"","sources":["../../src/gates/argument-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAIL,KAAK,WAAW,EAEjB,MAAM,uCAAuC,CAAC;AAO/C,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAMD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,aAAa,GAAG,mBAAmB,CA6B1E;AA6HD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,aAAa,GAAG,IAAI,CAO7D;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAGnE"}
@@ -0,0 +1,180 @@
1
+ /**
2
+ * Argument Guard Gate (Gate 5)
3
+ *
4
+ * Runtime validation middleware derived from ADR-001 (Command Argument Semantics).
5
+ * This gate enforces:
6
+ *
7
+ * 1. ID vs Natural Language argument rules
8
+ * 2. Required argument presence
9
+ * 3. Synthesis allow/deny per command
10
+ * 4. Confirmation enforcement for irreversible commands
11
+ * 5. Deterministic, instructional error messages
12
+ *
13
+ * The ADR (adr-command-semantics.ts) is the authoritative policy.
14
+ * This gate is mechanically derived from it.
15
+ */
16
+ import { lookupCommand, classifyArgument, validateArgument, } from '../contracts/adr-command-semantics.js';
17
+ import { EXIT_CODES } from '../types/index.js';
18
+ // ============================================================================
19
+ // Guard Implementation
20
+ // ============================================================================
21
+ /**
22
+ * Check if the given command object passes argument validation.
23
+ * Returns a result indicating whether the command may proceed.
24
+ */
25
+ export function checkArgumentGuard(cmd) {
26
+ const { command, subcommand, positionalArgs } = cmd;
27
+ // Step 1: Look up command spec in ADR registry
28
+ const spec = lookupCommand(command, subcommand);
29
+ if (!spec) {
30
+ // Command not in registry. Commands like 'help', 'version' may have
31
+ // no subcommand spec. Allow unregistered commands to pass through
32
+ // (other gates handle unknown commands).
33
+ const primarySpec = lookupCommand(command);
34
+ if (!primarySpec && subcommand) {
35
+ // Try: maybe the subcommand is actually a positional arg
36
+ // for the primary command (e.g., "plan <manifestQuery>")
37
+ const parentSpec = lookupCommand(command);
38
+ if (parentSpec) {
39
+ const modifiedCmd = {
40
+ ...cmd,
41
+ positionalArgs: [subcommand, ...positionalArgs],
42
+ };
43
+ return validateArgs(parentSpec, modifiedCmd);
44
+ }
45
+ }
46
+ // No spec found — allow through (other gates will catch truly invalid commands)
47
+ return { allowed: true };
48
+ }
49
+ // Step 2: Validate argument count, types, and confirmation requirements
50
+ return validateArgs(spec, cmd);
51
+ }
52
+ /**
53
+ * Validate positional arguments against the command spec.
54
+ * Accepts the full CommandObject to access flags for confirmation checks.
55
+ */
56
+ function validateArgs(spec, cmd) {
57
+ const positionalArgs = cmd.positionalArgs;
58
+ const requiredArgs = spec.args.filter(a => a.required);
59
+ // Case A: Missing required arguments
60
+ if (requiredArgs.length > 0 && positionalArgs.length < requiredArgs.length) {
61
+ const missing = requiredArgs.slice(positionalArgs.length);
62
+ const missingNames = missing.map(a => `<${a.name}>`).join(' ');
63
+ const examples = missing.map(a => ` ${a.example} — ${a.description}`).join('\n');
64
+ return {
65
+ allowed: false,
66
+ exitCode: EXIT_CODES.ARG_VALIDATION_ERROR,
67
+ message: `Error: Missing required argument${missing.length > 1 ? 's' : ''}: ${missingNames}\n` +
68
+ `\n` +
69
+ `Usage: agentics ${spec.command} ${spec.args.map(a => a.required ? `<${a.name}>` : `[${a.name}]`).join(' ')}\n` +
70
+ `\n` +
71
+ `Expected:\n` +
72
+ `${examples}\n` +
73
+ `\n` +
74
+ formatArgumentTypeHint(missing[0].type),
75
+ spec,
76
+ };
77
+ }
78
+ // Case B/C: Wrong argument type
79
+ for (let i = 0; i < spec.args.length && i < positionalArgs.length; i++) {
80
+ const argSpec = spec.args[i];
81
+ const argValue = positionalArgs[i];
82
+ const error = validateArgument(argValue, argSpec);
83
+ if (error) {
84
+ return {
85
+ allowed: false,
86
+ exitCode: EXIT_CODES.ARG_VALIDATION_ERROR,
87
+ message: `Error: Invalid argument for '${spec.command}'\n` +
88
+ `\n` +
89
+ `${error}\n` +
90
+ `\n` +
91
+ `Usage: agentics ${spec.command} ${spec.args.map(a => a.required ? `<${a.name}>` : `[${a.name}]`).join(' ')}`,
92
+ spec,
93
+ };
94
+ }
95
+ }
96
+ // Case D: Synthesis attempted on forbidden command
97
+ // (Checked at the command level — if NL detected on SYNTHESIS_FORBIDDEN)
98
+ if (spec.synthesis === 'SYNTHESIS_FORBIDDEN') {
99
+ for (let i = 0; i < spec.args.length && i < positionalArgs.length; i++) {
100
+ const argSpec = spec.args[i];
101
+ if (argSpec.type === 'ID') {
102
+ const detected = classifyArgument(positionalArgs[i]);
103
+ if (detected === 'NATURAL_LANGUAGE') {
104
+ return {
105
+ allowed: false,
106
+ exitCode: EXIT_CODES.ARG_VALIDATION_ERROR,
107
+ message: `Error: Synthesis is not allowed on '${spec.command}'.\n` +
108
+ `\n` +
109
+ `This command requires an ID, not a description.\n` +
110
+ `Natural language input triggers synthesis, which is forbidden for this command.\n` +
111
+ `\n` +
112
+ `Usage: agentics ${spec.command} <${argSpec.name}>\n` +
113
+ `Example: agentics ${spec.command} ${argSpec.example}`,
114
+ spec,
115
+ };
116
+ }
117
+ }
118
+ }
119
+ }
120
+ // Case E: Irreversible command without explicit confirmation (ADR-002 Decision 2, Rule 4)
121
+ if (spec.requiresConfirmation) {
122
+ const hasForceFlag = cmd.flags['force'] === true;
123
+ if (!hasForceFlag) {
124
+ const argsUsage = spec.args.map(a => a.required ? `<${a.name}>` : `[${a.name}]`).join(' ');
125
+ return {
126
+ allowed: false,
127
+ exitCode: EXIT_CODES.ARG_VALIDATION_ERROR,
128
+ message: `Error: Command '${spec.command}' requires explicit confirmation.\n` +
129
+ `\n` +
130
+ (spec.irreversible
131
+ ? `This command performs an irreversible operation and cannot be undone.\n`
132
+ : `This command requires confirmation before proceeding.\n`) +
133
+ `You must provide the --force flag to confirm.\n` +
134
+ `\n` +
135
+ `Usage: agentics ${spec.command} ${argsUsage} --force`,
136
+ spec,
137
+ };
138
+ }
139
+ }
140
+ return { allowed: true, spec };
141
+ }
142
+ /**
143
+ * Generate a hint string for the expected argument type.
144
+ */
145
+ function formatArgumentTypeHint(type) {
146
+ switch (type) {
147
+ case 'ID':
148
+ return 'Hint: IDs are lowercase, hyphenated identifiers or UUIDs.\n' +
149
+ ' They resolve to persisted objects. Never use quoted text here.';
150
+ case 'NATURAL_LANGUAGE':
151
+ return 'Hint: Descriptions must be quoted natural language strings.\n' +
152
+ ' They seed synthesis to create new resources.';
153
+ case 'SELECTOR':
154
+ return 'Hint: Selectors are keywords like "latest" or UUIDs.\n' +
155
+ ' They select existing resources without triggering synthesis.';
156
+ }
157
+ }
158
+ // ============================================================================
159
+ // Gate Enforcement
160
+ // ============================================================================
161
+ /**
162
+ * Enforce the argument guard. Exits the process on failure.
163
+ * Follows the same pattern as other gates (execution-gate, auth-session-gate).
164
+ */
165
+ export function enforceArgumentGuard(cmd) {
166
+ const result = checkArgumentGuard(cmd);
167
+ if (!result.allowed) {
168
+ console.error(result.message);
169
+ process.exit(result.exitCode ?? EXIT_CODES.ARG_VALIDATION_ERROR);
170
+ }
171
+ }
172
+ /**
173
+ * Check if a command requires argument validation.
174
+ * Built-in commands (help, version) are exempt.
175
+ */
176
+ export function requiresArgumentValidation(command) {
177
+ const exempt = ['help', 'version'];
178
+ return !exempt.includes(command);
179
+ }
180
+ //# sourceMappingURL=argument-guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"argument-guard.js","sourceRoot":"","sources":["../../src/gates/argument-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,gBAAgB,GAGjB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAa/C,+EAA+E;AAC/E,uBAAuB;AACvB,+EAA+E;AAE/E;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAkB;IACnD,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,GAAG,GAAG,CAAC;IAEpD,+CAA+C;IAC/C,MAAM,IAAI,GAAG,aAAa,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IAEhD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,oEAAoE;QACpE,kEAAkE;QAClE,yCAAyC;QACzC,MAAM,WAAW,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;QAC3C,IAAI,CAAC,WAAW,IAAI,UAAU,EAAE,CAAC;YAC/B,yDAAyD;YACzD,yDAAyD;YACzD,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;YAC1C,IAAI,UAAU,EAAE,CAA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,CAAC;IACnE,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,0BAA0B,CAAC,OAAe;IACxD,MAAM,MAAM,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACnC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACnC,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Authentication Session Gate Module
3
+ *
4
+ * CONTROL PLANE HARDENING
5
+ *
6
+ * PURPOSE: Enforce authenticated session requirement for ALL operational commands.
7
+ * CLI MUST require valid authentication before invoking remote services.
8
+ *
9
+ * CRITICAL REQUIREMENTS:
10
+ * - CLI requires authenticated session
11
+ * - No anonymous operations allowed
12
+ * - Clear error messaging for auth failures
13
+ *
14
+ * FORBIDDEN:
15
+ * - Fallback to anonymous access
16
+ * - Silent auth bypass
17
+ * - Local execution fallback
18
+ */
19
+ /**
20
+ * Exit code for authentication required.
21
+ */
22
+ export declare const AUTH_REQUIRED_EXIT_CODE: 130;
23
+ export declare class AuthSessionRequiredError extends Error {
24
+ constructor();
25
+ }
26
+ export interface AuthSessionGateResult {
27
+ authenticated: boolean;
28
+ method?: 'platform' | 'gcp';
29
+ account?: string;
30
+ exitCode?: number;
31
+ message?: string;
32
+ }
33
+ /**
34
+ * Check if user has valid authentication.
35
+ * Checks both platform credentials and GCP credentials.
36
+ */
37
+ export declare function checkAuthSessionGate(): Promise<AuthSessionGateResult>;
38
+ /**
39
+ * Enforce the authentication session gate.
40
+ * Exits the process if no valid authentication is found.
41
+ */
42
+ export declare function enforceAuthSessionGate(): Promise<void>;
43
+ /**
44
+ * Check if a command requires authentication.
45
+ */
46
+ export declare function requiresAuthentication(command: string): boolean;
47
+ //# sourceMappingURL=auth-session-gate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-session-gate.d.ts","sourceRoot":"","sources":["../../src/gates/auth-session-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAUH;;GAEG;AACH,eAAO,MAAM,uBAAuB,KAAwB,CAAC;AAM7D,qBAAa,wBAAyB,SAAQ,KAAK;;CAyBlD;AAMD,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,OAAO,CAAC;IACvB,MAAM,CAAC,EAAE,UAAU,GAAG,KAAK,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAoCD;;;GAGG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,qBAAqB,CAAC,CA2B3E;AAED;;;GAGG;AACH,wBAAsB,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC,CAO5D;AAqBD;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAE/D"}
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Authentication Session Gate Module
3
+ *
4
+ * CONTROL PLANE HARDENING
5
+ *
6
+ * PURPOSE: Enforce authenticated session requirement for ALL operational commands.
7
+ * CLI MUST require valid authentication before invoking remote services.
8
+ *
9
+ * CRITICAL REQUIREMENTS:
10
+ * - CLI requires authenticated session
11
+ * - No anonymous operations allowed
12
+ * - Clear error messaging for auth failures
13
+ *
14
+ * FORBIDDEN:
15
+ * - Fallback to anonymous access
16
+ * - Silent auth bypass
17
+ * - Local execution fallback
18
+ */
19
+ import { hasValidCredentials, getActiveAccount } from '../auth/gcp-identity.js';
20
+ import { createCredentialStore } from '../utils/credentials.js';
21
+ import { EXIT_CODES } from '../types/index.js';
22
+ // ============================================================================
23
+ // Authentication Gate Configuration
24
+ // ============================================================================
25
+ /**
26
+ * Exit code for authentication required.
27
+ */
28
+ export const AUTH_REQUIRED_EXIT_CODE = EXIT_CODES.AUTH_ERROR;
29
+ // ============================================================================
30
+ // Authentication Gate Error
31
+ // ============================================================================
32
+ export class AuthSessionRequiredError extends Error {
33
+ constructor() {
34
+ super(`\n` +
35
+ `━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n` +
36
+ ` AUTHENTICATION REQUIRED\n` +
37
+ `━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n` +
38
+ `\n` +
39
+ ` The CLI requires an authenticated session to execute this command.\n` +
40
+ ` No valid credentials were found.\n` +
41
+ `\n` +
42
+ ` TO AUTHENTICATE:\n` +
43
+ `\n` +
44
+ ` Option 1: Platform login (recommended)\n` +
45
+ ` agentics login\n` +
46
+ `\n` +
47
+ ` Option 2: GCP authentication\n` +
48
+ ` gcloud auth login\n` +
49
+ `\n` +
50
+ ` After authenticating, re-run your command.\n` +
51
+ `\n` +
52
+ `━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n`);
53
+ this.name = 'AuthSessionRequiredError';
54
+ }
55
+ }
56
+ // ============================================================================
57
+ // Authentication Gate Implementation
58
+ // ============================================================================
59
+ /**
60
+ * Check if user has valid platform credentials.
61
+ */
62
+ async function hasPlatformCredentials() {
63
+ try {
64
+ const store = createCredentialStore();
65
+ const credentials = await store.load();
66
+ if (credentials && credentials.api_key) {
67
+ return { valid: true, email: credentials.email };
68
+ }
69
+ return { valid: false };
70
+ }
71
+ catch {
72
+ return { valid: false };
73
+ }
74
+ }
75
+ /**
76
+ * Check if user has valid GCP credentials.
77
+ */
78
+ function hasGcpCredentials() {
79
+ const hasCredentials = hasValidCredentials();
80
+ if (hasCredentials) {
81
+ const account = getActiveAccount();
82
+ return { valid: true, account: account ?? undefined };
83
+ }
84
+ return { valid: false };
85
+ }
86
+ /**
87
+ * Check if user has valid authentication.
88
+ * Checks both platform credentials and GCP credentials.
89
+ */
90
+ export async function checkAuthSessionGate() {
91
+ // Check platform credentials first
92
+ const platformAuth = await hasPlatformCredentials();
93
+ if (platformAuth.valid) {
94
+ return {
95
+ authenticated: true,
96
+ method: 'platform',
97
+ account: platformAuth.email,
98
+ };
99
+ }
100
+ // Fall back to GCP credentials
101
+ const gcpAuth = hasGcpCredentials();
102
+ if (gcpAuth.valid) {
103
+ return {
104
+ authenticated: true,
105
+ method: 'gcp',
106
+ account: gcpAuth.account,
107
+ };
108
+ }
109
+ // No valid credentials found
110
+ return {
111
+ authenticated: false,
112
+ exitCode: AUTH_REQUIRED_EXIT_CODE,
113
+ message: new AuthSessionRequiredError().message,
114
+ };
115
+ }
116
+ /**
117
+ * Enforce the authentication session gate.
118
+ * Exits the process if no valid authentication is found.
119
+ */
120
+ export async function enforceAuthSessionGate() {
121
+ const result = await checkAuthSessionGate();
122
+ if (!result.authenticated) {
123
+ console.error(result.message);
124
+ process.exit(result.exitCode);
125
+ }
126
+ }
127
+ /**
128
+ * Commands that require authentication.
129
+ * All operational commands require authentication.
130
+ * Only login, whoami, help, and version are allowed without authentication.
131
+ */
132
+ const AUTH_REQUIRED_COMMANDS = new Set([
133
+ 'plan',
134
+ 'simulate',
135
+ 'inspect',
136
+ 'quantify',
137
+ 'deploy',
138
+ 'export',
139
+ 'diligence',
140
+ 'usage',
141
+ 'policy',
142
+ 'erp',
143
+ 'logout',
144
+ ]);
145
+ /**
146
+ * Check if a command requires authentication.
147
+ */
148
+ export function requiresAuthentication(command) {
149
+ return AUTH_REQUIRED_COMMANDS.has(command);
150
+ }
151
+ //# sourceMappingURL=auth-session-gate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-session-gate.js","sourceRoot":"","sources":["../../src/gates/auth-session-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAA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