@llm-dev-ops/agentics-cli 1.4.6 → 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 (120) 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/auth/identity-resolver.d.ts +21 -0
  6. package/dist/auth/identity-resolver.d.ts.map +1 -0
  7. package/dist/auth/identity-resolver.js +68 -0
  8. package/dist/auth/identity-resolver.js.map +1 -0
  9. package/dist/auth/index.d.ts +2 -0
  10. package/dist/auth/index.d.ts.map +1 -1
  11. package/dist/auth/index.js +2 -0
  12. package/dist/auth/index.js.map +1 -1
  13. package/dist/auth/role-permissions.d.ts +12 -0
  14. package/dist/auth/role-permissions.d.ts.map +1 -0
  15. package/dist/auth/role-permissions.js +43 -0
  16. package/dist/auth/role-permissions.js.map +1 -0
  17. package/dist/cli/index.js +30 -134
  18. package/dist/cli/index.js.map +1 -1
  19. package/dist/commands/erp.d.ts.map +1 -1
  20. package/dist/commands/erp.js +62 -0
  21. package/dist/commands/erp.js.map +1 -1
  22. package/dist/commands/login.d.ts.map +1 -1
  23. package/dist/commands/login.js +25 -0
  24. package/dist/commands/login.js.map +1 -1
  25. package/dist/commands/logout.d.ts.map +1 -1
  26. package/dist/commands/logout.js +4 -1
  27. package/dist/commands/logout.js.map +1 -1
  28. package/dist/commands/plan.d.ts.map +1 -1
  29. package/dist/commands/plan.js +6 -5
  30. package/dist/commands/plan.js.map +1 -1
  31. package/dist/commands/simulate.d.ts.map +1 -1
  32. package/dist/commands/simulate.js +57 -1
  33. package/dist/commands/simulate.js.map +1 -1
  34. package/dist/commands/whoami.d.ts +4 -0
  35. package/dist/commands/whoami.d.ts.map +1 -1
  36. package/dist/commands/whoami.js +22 -5
  37. package/dist/commands/whoami.js.map +1 -1
  38. package/dist/contracts/adr-002-operational-enforcement.d.ts +684 -0
  39. package/dist/contracts/adr-002-operational-enforcement.d.ts.map +1 -0
  40. package/dist/contracts/adr-002-operational-enforcement.js +671 -0
  41. package/dist/contracts/adr-002-operational-enforcement.js.map +1 -0
  42. package/dist/contracts/adr-003-governance-architecture.d.ts +766 -0
  43. package/dist/contracts/adr-003-governance-architecture.d.ts.map +1 -0
  44. package/dist/contracts/adr-003-governance-architecture.js +773 -0
  45. package/dist/contracts/adr-003-governance-architecture.js.map +1 -0
  46. package/dist/contracts/adr-004-enterprise-integration-memory.d.ts +1150 -0
  47. package/dist/contracts/adr-004-enterprise-integration-memory.d.ts.map +1 -0
  48. package/dist/contracts/adr-004-enterprise-integration-memory.js +1158 -0
  49. package/dist/contracts/adr-004-enterprise-integration-memory.js.map +1 -0
  50. package/dist/contracts/adr-005-system-coherence-drift-self-governance.d.ts +1393 -0
  51. package/dist/contracts/adr-005-system-coherence-drift-self-governance.d.ts.map +1 -0
  52. package/dist/contracts/adr-005-system-coherence-drift-self-governance.js +1371 -0
  53. package/dist/contracts/adr-005-system-coherence-drift-self-governance.js.map +1 -0
  54. package/dist/contracts/adr-command-semantics.d.ts +150 -0
  55. package/dist/contracts/adr-command-semantics.d.ts.map +1 -0
  56. package/dist/contracts/adr-command-semantics.js +984 -0
  57. package/dist/contracts/adr-command-semantics.js.map +1 -0
  58. package/dist/contracts/index.d.ts +5 -0
  59. package/dist/contracts/index.d.ts.map +1 -1
  60. package/dist/contracts/index.js +16 -0
  61. package/dist/contracts/index.js.map +1 -1
  62. package/dist/enterprise/index.d.ts +16 -0
  63. package/dist/enterprise/index.d.ts.map +1 -0
  64. package/dist/enterprise/index.js +17 -0
  65. package/dist/enterprise/index.js.map +1 -0
  66. package/dist/enterprise/integration-registry.d.ts +73 -0
  67. package/dist/enterprise/integration-registry.d.ts.map +1 -0
  68. package/dist/enterprise/integration-registry.js +252 -0
  69. package/dist/enterprise/integration-registry.js.map +1 -0
  70. package/dist/enterprise/lineage.d.ts +73 -0
  71. package/dist/enterprise/lineage.d.ts.map +1 -0
  72. package/dist/enterprise/lineage.js +218 -0
  73. package/dist/enterprise/lineage.js.map +1 -0
  74. package/dist/gates/argument-guard.d.ts +39 -0
  75. package/dist/gates/argument-guard.d.ts.map +1 -0
  76. package/dist/gates/argument-guard.js +180 -0
  77. package/dist/gates/argument-guard.js.map +1 -0
  78. package/dist/gates/index.d.ts +5 -0
  79. package/dist/gates/index.d.ts.map +1 -1
  80. package/dist/gates/index.js +7 -0
  81. package/dist/gates/index.js.map +1 -1
  82. package/dist/gates/lineage-gate.d.ts +55 -0
  83. package/dist/gates/lineage-gate.d.ts.map +1 -0
  84. package/dist/gates/lineage-gate.js +127 -0
  85. package/dist/gates/lineage-gate.js.map +1 -0
  86. package/dist/modules/help-renderer.d.ts +25 -0
  87. package/dist/modules/help-renderer.d.ts.map +1 -0
  88. package/dist/modules/help-renderer.js +163 -0
  89. package/dist/modules/help-renderer.js.map +1 -0
  90. package/dist/modules/index.d.ts +1 -0
  91. package/dist/modules/index.d.ts.map +1 -1
  92. package/dist/modules/index.js +1 -0
  93. package/dist/modules/index.js.map +1 -1
  94. package/dist/server/index.d.ts +2 -0
  95. package/dist/server/index.d.ts.map +1 -1
  96. package/dist/server/index.js +16 -1
  97. package/dist/server/index.js.map +1 -1
  98. package/dist/server/routes/identity.d.ts +9 -0
  99. package/dist/server/routes/identity.d.ts.map +1 -0
  100. package/dist/server/routes/identity.js +100 -0
  101. package/dist/server/routes/identity.js.map +1 -0
  102. package/dist/server/routes/index.d.ts +2 -0
  103. package/dist/server/routes/index.d.ts.map +1 -1
  104. package/dist/server/routes/index.js +2 -0
  105. package/dist/server/routes/index.js.map +1 -1
  106. package/dist/server/routes/lineage.d.ts +15 -0
  107. package/dist/server/routes/lineage.d.ts.map +1 -0
  108. package/dist/server/routes/lineage.js +128 -0
  109. package/dist/server/routes/lineage.js.map +1 -0
  110. package/dist/types/index.d.ts +132 -0
  111. package/dist/types/index.d.ts.map +1 -1
  112. package/dist/utils/identity-store.d.ts +31 -0
  113. package/dist/utils/identity-store.d.ts.map +1 -0
  114. package/dist/utils/identity-store.js +97 -0
  115. package/dist/utils/identity-store.js.map +1 -0
  116. package/dist/utils/index.d.ts +2 -0
  117. package/dist/utils/index.d.ts.map +1 -1
  118. package/dist/utils/index.js +1 -0
  119. package/dist/utils/index.js.map +1 -1
  120. package/package.json +1 -1
@@ -0,0 +1,684 @@
1
+ /**
2
+ * ADR-002: Operational Enforcement of CLI Governance
3
+ *
4
+ * STATUS: Accepted
5
+ * DATE: 2026-01-28
6
+ * AUTHORS: Platform Engineering
7
+ * SUPERSEDES: None
8
+ * DEPENDS ON: ADR-001 (Command Argument Semantics & Synthesis Governance)
9
+ *
10
+ * ============================================================================
11
+ * CONTEXT
12
+ * ============================================================================
13
+ *
14
+ * ADR-001 defines the semantic rules for the Agentics CLI:
15
+ * - Argument type classification (ID, NATURAL_LANGUAGE, SELECTOR)
16
+ * - Synthesis governance (REQUIRED, FORBIDDEN, COMMITMENT_GRADE)
17
+ * - Command contracts (argument specs, irreversibility, confirmation)
18
+ *
19
+ * However, ADRs without mechanical enforcement drift. Without a runtime
20
+ * enforcement layer, schema-driven CI, and regression controls:
21
+ *
22
+ * - Developers add commands without registering them in the ADR
23
+ * - Validation logic diverges from the declared contract
24
+ * - Help text lies about argument types
25
+ * - Tests don't cover argument contract violations
26
+ * - New gate bypass paths appear without review
27
+ *
28
+ * This ADR defines how ADR-001 governance becomes executable and
29
+ * continuously enforced. It does NOT redefine command semantics.
30
+ *
31
+ * ============================================================================
32
+ * DECISION 1: MACHINE-READABLE ADR SCHEMA
33
+ * ============================================================================
34
+ *
35
+ * The COMMAND_REGISTRY in adr-command-semantics.ts IS the machine-readable
36
+ * schema. This decision formalizes it as the single source of truth and
37
+ * defines the contract it must satisfy.
38
+ *
39
+ * The schema (COMMAND_REGISTRY) MUST:
40
+ *
41
+ * 1. BE VERSIONED
42
+ * - The registry exports an ADR_SCHEMA_VERSION constant
43
+ * - Version follows semver: MAJOR.MINOR.PATCH
44
+ * - MAJOR: breaking argument contract changes
45
+ * - MINOR: new commands or optional fields
46
+ * - PATCH: help text or example corrections
47
+ *
48
+ * 2. BE HUMAN-AUDITABLE
49
+ * - TypeScript source with JSDoc comments on every command group
50
+ * - Grouped by domain (identity, simulation, planning, etc.)
51
+ * - No generated code — hand-authored and reviewed
52
+ *
53
+ * 3. BE DIFF-FRIENDLY
54
+ * - One command per object literal
55
+ * - Consistent field ordering: command, primary, subcommand,
56
+ * description, synthesis, args, irreversible, requiresConfirmation
57
+ * - Readonly arrays and properties prevent accidental mutation
58
+ *
59
+ * 4. BE LOADABLE AT RUNTIME
60
+ * - Imported by the argument-guard gate at CLI startup
61
+ * - Imported by the help renderer for usage generation
62
+ * - No file I/O or dynamic loading — compile-time resolution
63
+ *
64
+ * 5. BE CONSUMABLE BY:
65
+ * - CLI validation middleware (argument-guard.ts)
66
+ * - Unit test generation (schema-derived test cases)
67
+ * - Help / usage rendering (help-renderer.ts)
68
+ * - CI checks (schema completeness assertions)
69
+ *
70
+ * EXPLICITLY PROHIBITED:
71
+ *
72
+ * - Hard-coding validation rules outside the registry
73
+ * (all rules flow from COMMAND_REGISTRY → argument-guard.ts)
74
+ *
75
+ * - Divergent definitions across layers
76
+ * (help text, error messages, tests all read from COMMAND_REGISTRY)
77
+ *
78
+ * - Inline command specs in switch/case dispatch
79
+ * (cli/index.ts dispatches, contracts/adr-command-semantics.ts defines)
80
+ *
81
+ * ============================================================================
82
+ * DECISION 2: CLI ENTRYPOINT VALIDATION MIDDLEWARE
83
+ * ============================================================================
84
+ *
85
+ * A single validation middleware layer (the Argument Guard Gate) exists at
86
+ * the CLI entrypoint. This decision formalizes its position, behavior, and
87
+ * invariants.
88
+ *
89
+ * LOCATION:
90
+ * src/gates/argument-guard.ts
91
+ *
92
+ * LOADING:
93
+ * The guard imports COMMAND_REGISTRY from adr-command-semantics.ts
94
+ * at module initialization. No lazy loading. No fallback registry.
95
+ *
96
+ * EXECUTION ORDER (within the 5-gate pipeline):
97
+ * Gate 1: Execution Gate — kill-switch / entitlement check
98
+ * Gate 2: Auth Session Gate — requires authenticated session
99
+ * Gate 3: Service Health Gate — validates backend availability
100
+ * Gate 4: Output Format Gate — enforces structured output
101
+ * Gate 5: Argument Guard Gate — ADR-001 contract enforcement ← THIS
102
+ *
103
+ * The Argument Guard Gate MUST:
104
+ *
105
+ * 1. Load the ADR schema (COMMAND_REGISTRY) at import time
106
+ *
107
+ * 2. Validate arguments BEFORE command execution:
108
+ * a. Look up the command+subcommand in the registry
109
+ * b. Verify required arguments are present
110
+ * c. Classify each argument (ID / NATURAL_LANGUAGE / SELECTOR)
111
+ * d. Reject type mismatches (e.g., NL where ID expected)
112
+ *
113
+ * 3. Enforce synthesis governance:
114
+ * a. SYNTHESIS_FORBIDDEN commands MUST reject NL arguments
115
+ * b. SYNTHESIS_REQUIRED commands MUST accept NL arguments
116
+ * c. COMMITMENT_GRADE commands MUST require ID + confirmation
117
+ *
118
+ * 4. Enforce irreversible action constraints:
119
+ * a. Commands marked irreversible: true MUST require --force
120
+ * or interactive confirmation before execution
121
+ * b. Commands marked requiresConfirmation: true MUST NOT proceed
122
+ * without explicit user consent
123
+ *
124
+ * 5. Block execution on violation:
125
+ * a. Exit with EXIT_CODES.ARG_VALIDATION_ERROR (100)
126
+ * b. Print deterministic, instructional error to stderr
127
+ * c. Include: expected type, received value, usage example
128
+ *
129
+ * 6. Produce deterministic, instructional errors:
130
+ * a. Error message format is fixed, not generated by LLM
131
+ * b. Includes: command name, expected argument spec, example
132
+ * c. No suggestions, no "did you mean", no inference
133
+ *
134
+ * BEHAVIORAL RULES:
135
+ *
136
+ * - Validation happens BEFORE any LLM call
137
+ * - Validation happens BEFORE any state mutation
138
+ * - Validation happens BEFORE any network request
139
+ * - No inference or correction of user input
140
+ * - No interactive fallback ("did you mean X?")
141
+ * - No partial execution on validation failure
142
+ * - Middleware is mandatory for all non-exempt commands
143
+ * (exempt: help, version)
144
+ *
145
+ * ARCHITECTURAL CONSTRAINT:
146
+ *
147
+ * All CLI commands MUST pass through the 5-gate pipeline.
148
+ * No bypass paths are allowed. The gate enforcement order in
149
+ * src/cli/index.ts is the ONLY execution path.
150
+ *
151
+ * Any code path that dispatches a command without passing through
152
+ * all 5 gates is a bug.
153
+ *
154
+ * ============================================================================
155
+ * DECISION 3: CI / REGRESSION ENFORCEMENT
156
+ * ============================================================================
157
+ *
158
+ * CI enforcement guarantees the CLI cannot drift from the ADR schema.
159
+ *
160
+ * CI RESPONSIBILITIES:
161
+ *
162
+ * 1. VALIDATE THE ADR SCHEMA ITSELF
163
+ * - Every CommandSpec has all required fields
164
+ * - Every command string matches the format "primary subcommand"
165
+ * - No duplicate command entries
166
+ * - All ArgumentSpec entries have valid type, name, example
167
+ * - Schema version constant is present and valid semver
168
+ *
169
+ * 2. ENSURE EVERY CLI COMMAND IS DECLARED IN THE SCHEMA
170
+ * - Parse the switch/case dispatch in src/cli/index.ts
171
+ * - For each case label, assert a matching COMMAND_REGISTRY entry exists
172
+ * - For each subcommand branch, assert the primary+subcommand pair exists
173
+ * - FAIL if a dispatch path exists without a schema entry
174
+ *
175
+ * 3. ENSURE EVERY SCHEMA ENTRY HAS AN IMPLEMENTATION
176
+ * - For each COMMAND_REGISTRY entry, assert a matching dispatch path
177
+ * - FAIL if a schema entry exists without implementation
178
+ * - This prevents "dead" registry entries that mislead auditors
179
+ *
180
+ * 4. ENSURE HELP OUTPUT IS GENERATED FROM THE SCHEMA
181
+ * - The help renderer MUST consume COMMAND_REGISTRY
182
+ * - Help text for argument types, descriptions, and examples
183
+ * MUST match the registry verbatim
184
+ * - Snapshot tests capture help output and detect drift
185
+ *
186
+ * 5. RUN COMMAND-LEVEL TESTS DERIVED FROM THE SCHEMA
187
+ * - For each command with args[].type === 'ID':
188
+ * Assert NL input is rejected with ARG_VALIDATION_ERROR
189
+ * - For each command with synthesis === 'SYNTHESIS_FORBIDDEN':
190
+ * Assert NL arguments are rejected
191
+ * - For each command with irreversible === true:
192
+ * Assert --force is required
193
+ * - For each command with required args:
194
+ * Assert missing args produce instructional errors
195
+ *
196
+ * 6. FAIL BUILDS IF:
197
+ * - A command exists in dispatch without a schema entry
198
+ * - A schema entry exists without a dispatch implementation
199
+ * - Argument contracts change without ADR schema version bump
200
+ * - Help output snapshot changes without schema change
201
+ * - Argument Guard gate is bypassed in any code path
202
+ *
203
+ * REQUIRED CI ARTIFACTS:
204
+ *
205
+ * a. Schema validation tests
206
+ * Location: tests/unit/contracts/adr-schema-validation.test.ts
207
+ * Validates COMMAND_REGISTRY structural integrity
208
+ *
209
+ * b. Generated command behavior tests
210
+ * Location: tests/unit/contracts/adr-command-behavior.test.ts
211
+ * Auto-generates test cases from COMMAND_REGISTRY entries
212
+ *
213
+ * c. Snapshot tests for help output
214
+ * Location: tests/unit/contracts/adr-help-snapshot.test.ts
215
+ * Captures and compares help text against schema
216
+ *
217
+ * d. ADR version compatibility checks
218
+ * Location: tests/unit/contracts/adr-version-compat.test.ts
219
+ * Validates schema version constant and changelog
220
+ *
221
+ * e. Gate bypass detection
222
+ * Location: tests/unit/contracts/adr-gate-bypass.test.ts
223
+ * Static analysis to ensure no command dispatch without gate pipeline
224
+ *
225
+ * CI EXECUTION TIMING:
226
+ *
227
+ * - ON PULL REQUEST: all schema validation + behavior tests
228
+ * - ON MERGE TO MAIN: full suite + snapshot comparison + bypass detection
229
+ * - ON RELEASE: version compatibility check + schema export artifact
230
+ *
231
+ * DEVELOPER FEEDBACK LOOP:
232
+ *
233
+ * When CI fails due to an ADR violation:
234
+ * 1. Error message identifies the specific violation type
235
+ * 2. Error message references the ADR decision number
236
+ * 3. Error message provides the exact fix required
237
+ * 4. No ambiguity — the fix is mechanical, not judgmental
238
+ *
239
+ * Example CI failure message:
240
+ *
241
+ * ADR-002 VIOLATION: Command 'notify send' exists in CLI dispatch
242
+ * (src/cli/index.ts:847) but has no COMMAND_REGISTRY entry.
243
+ *
244
+ * Fix: Add a CommandSpec to COMMAND_REGISTRY in
245
+ * src/contracts/adr-command-semantics.ts for 'notify send'.
246
+ *
247
+ * See: ADR-002, Decision 3, Rule 2
248
+ *
249
+ * ============================================================================
250
+ * CONSEQUENCES
251
+ * ============================================================================
252
+ *
253
+ * POSITIVE:
254
+ *
255
+ * - Changing CLI behavior REQUIRES changing the schema first
256
+ * - Breaking the schema breaks CI — no silent drift
257
+ * - Help text cannot lie — it's derived from the same registry
258
+ * - Validation cannot be bypassed — gate pipeline is enforced
259
+ * - The CLI behaves deterministically, like claude-flow / claude-code
260
+ * - New commands cannot ship without full ADR registration
261
+ * - Argument type mismatches are caught before any side effects
262
+ * - Test coverage for argument contracts is mechanically complete
263
+ *
264
+ * NEGATIVE:
265
+ *
266
+ * - Adding a new command requires touching 3 files minimum:
267
+ * 1. adr-command-semantics.ts (schema registration)
268
+ * 2. cli/index.ts (dispatch implementation)
269
+ * 3. commands/<name>.ts (command handler)
270
+ * This is intentional friction that prevents undocumented commands.
271
+ *
272
+ * - Schema version bumps are required for any argument contract change.
273
+ * This is intentional — argument contracts are API surfaces.
274
+ *
275
+ * - CI will reject PRs that add commands without schema entries.
276
+ * This is the desired behavior, not a limitation.
277
+ *
278
+ * ============================================================================
279
+ * EXPLICIT CONSTRAINTS
280
+ * ============================================================================
281
+ *
282
+ * 1. The Argument Guard gate MUST NOT perform inference.
283
+ * It validates. It does not guess, suggest, or correct.
284
+ *
285
+ * 2. The COMMAND_REGISTRY MUST be the sole source of truth for:
286
+ * - Which commands exist
287
+ * - What arguments each command accepts
288
+ * - What argument types are expected
289
+ * - Whether synthesis is allowed
290
+ * - Whether the command is irreversible
291
+ * - Whether confirmation is required
292
+ *
293
+ * 3. No validation logic may exist outside the gate pipeline.
294
+ * Individual command handlers MUST NOT re-validate arguments.
295
+ * They receive pre-validated input from the gate.
296
+ *
297
+ * 4. The gate pipeline order (1-5) MUST NOT be reordered.
298
+ * Gates are ordered by severity: execution → auth → health →
299
+ * format → arguments. This ensures the cheapest checks run first.
300
+ *
301
+ * 5. CI enforcement MUST NOT be optional.
302
+ * There is no --skip-adr-checks flag. There is no
303
+ * DISABLE_SCHEMA_VALIDATION environment variable.
304
+ *
305
+ * ============================================================================
306
+ * ANTI-PATTERNS (WHAT IS FORBIDDEN)
307
+ * ============================================================================
308
+ *
309
+ * 1. INLINE VALIDATION
310
+ * Forbidden: Checking argument types inside command handlers.
311
+ * Required: All validation flows through argument-guard.ts.
312
+ *
313
+ * 2. DUPLICATE REGISTRIES
314
+ * Forbidden: Maintaining a separate list of commands in help text,
315
+ * tests, or documentation that doesn't reference COMMAND_REGISTRY.
316
+ * Required: All command metadata derives from COMMAND_REGISTRY.
317
+ *
318
+ * 3. SOFT FAILURES
319
+ * Forbidden: Logging a warning and continuing when validation fails.
320
+ * Required: process.exit(EXIT_CODES.ARG_VALIDATION_ERROR) on any
321
+ * argument contract violation.
322
+ *
323
+ * 4. INFERENCE / AUTO-CORRECTION
324
+ * Forbidden: "Did you mean 'plan create'?" or fuzzy matching.
325
+ * Required: Exact match or deterministic error. No guessing.
326
+ *
327
+ * 5. BYPASS FLAGS
328
+ * Forbidden: --no-validate, --skip-gates, --unsafe-mode.
329
+ * Required: All commands pass through all applicable gates.
330
+ *
331
+ * 6. DYNAMIC SCHEMA LOADING
332
+ * Forbidden: Reading command specs from a config file at runtime.
333
+ * Required: COMMAND_REGISTRY is a compile-time TypeScript constant.
334
+ * This provides type safety, tree-shaking, and audit traceability.
335
+ *
336
+ * 7. GATE REORDERING
337
+ * Forbidden: Moving the Argument Guard before the Auth gate.
338
+ * Required: Gates execute in the defined order (1-5).
339
+ *
340
+ * 8. UNREGISTERED COMMANDS
341
+ * Forbidden: Adding a case to the CLI dispatch switch without
342
+ * a corresponding COMMAND_REGISTRY entry.
343
+ * Required: Schema-first development — register, then implement.
344
+ *
345
+ * ============================================================================
346
+ * ADR SCHEMA SPECIFICATION
347
+ * ============================================================================
348
+ *
349
+ * This section defines the schema structure that COMMAND_REGISTRY entries
350
+ * must conform to. It is the formal specification for ADR-001's
351
+ * machine-readable representation.
352
+ *
353
+ * FIELD DEFINITIONS:
354
+ *
355
+ * CommandSpec (required fields):
356
+ * command: string
357
+ * Full command path. Format: "<primary>" or "<primary> <subcommand>".
358
+ * Must be unique across the registry. Lowercase, space-separated.
359
+ *
360
+ * primary: string
361
+ * The top-level command name. Matches the CLI dispatch case label.
362
+ * Lowercase, no spaces.
363
+ *
364
+ * description: string
365
+ * One-line human-readable description. Used in help output.
366
+ * Must start with a verb. Must not exceed 80 characters.
367
+ *
368
+ * synthesis: SynthesisClass
369
+ * One of: 'SYNTHESIS_REQUIRED', 'SYNTHESIS_FORBIDDEN', 'COMMITMENT_GRADE'.
370
+ * Governs whether LLM synthesis may be triggered by this command.
371
+ *
372
+ * args: readonly ArgumentSpec[]
373
+ * Ordered positional arguments. May be empty for zero-argument commands.
374
+ *
375
+ * irreversible: boolean
376
+ * Whether this command performs an irreversible state change.
377
+ * true requires confirmation before execution.
378
+ *
379
+ * requiresConfirmation: boolean
380
+ * Whether this command requires explicit user confirmation.
381
+ * May be satisfied by --force flag or interactive prompt.
382
+ *
383
+ * CommandSpec (optional fields):
384
+ * subcommand: string
385
+ * The subcommand name, if this is a sub-operation of a primary command.
386
+ * Lowercase, no spaces.
387
+ *
388
+ * ArgumentSpec (all fields required):
389
+ * name: string
390
+ * Argument name for help output. Lowercase, hyphenated.
391
+ *
392
+ * type: ArgumentType
393
+ * One of: 'ID', 'NATURAL_LANGUAGE', 'SELECTOR'.
394
+ *
395
+ * required: boolean
396
+ * Whether this argument must be provided.
397
+ *
398
+ * description: string
399
+ * Human-readable description for help and error messages.
400
+ *
401
+ * example: string
402
+ * Example value shown in usage output and error messages.
403
+ *
404
+ * EXAMPLE ENTRIES:
405
+ *
406
+ * // Zero-argument, synthesis-forbidden, read-only command
407
+ * {
408
+ * command: 'whoami',
409
+ * primary: 'whoami',
410
+ * description: 'Show current identity, org, and role',
411
+ * synthesis: 'SYNTHESIS_FORBIDDEN',
412
+ * args: [],
413
+ * irreversible: false,
414
+ * requiresConfirmation: false,
415
+ * }
416
+ *
417
+ * // Single NL argument, synthesis-required, safe command
418
+ * {
419
+ * command: 'simulate create',
420
+ * primary: 'simulate',
421
+ * subcommand: 'create',
422
+ * description: 'Create a new simulation from a natural language description',
423
+ * synthesis: 'SYNTHESIS_REQUIRED',
424
+ * args: [{
425
+ * name: 'description',
426
+ * type: 'NATURAL_LANGUAGE',
427
+ * required: true,
428
+ * description: 'Quoted natural language description of the simulation',
429
+ * example: '"Simulate enterprise migration to cloud"',
430
+ * }],
431
+ * irreversible: false,
432
+ * requiresConfirmation: false,
433
+ * }
434
+ *
435
+ * // Single ID argument, commitment-grade, irreversible command
436
+ * {
437
+ * command: 'simulate run',
438
+ * primary: 'simulate',
439
+ * subcommand: 'run',
440
+ * description: 'Execute a simulation by ID',
441
+ * synthesis: 'COMMITMENT_GRADE',
442
+ * args: [{
443
+ * name: 'simulation-id',
444
+ * type: 'ID',
445
+ * required: true,
446
+ * description: 'ID of the simulation to run',
447
+ * example: 'enterprise-cloud-migration',
448
+ * }],
449
+ * irreversible: true,
450
+ * requiresConfirmation: true,
451
+ * }
452
+ *
453
+ * ============================================================================
454
+ * MIDDLEWARE INTEGRATION SPEC
455
+ * ============================================================================
456
+ *
457
+ * WHERE IT LIVES:
458
+ * src/gates/argument-guard.ts
459
+ *
460
+ * HOW IT LOADS THE SCHEMA:
461
+ * import { lookupCommand, classifyArgument, validateArgument }
462
+ * from '../contracts/adr-command-semantics.js';
463
+ *
464
+ * The import is resolved at compile time. The registry is available
465
+ * as a module-level constant. No file I/O. No async loading.
466
+ *
467
+ * EXECUTION ORDER:
468
+ * 1. CLI entrypoint (src/cli/index.ts) calls parser.parse(args)
469
+ * 2. Built-in commands (help, version) exit early
470
+ * 3. Gate 1: enforceExecutionGate(command)
471
+ * 4. Gate 2: enforceAuthSessionGate() [if applicable]
472
+ * 5. Gate 3: enforceServiceHealthGate() [if applicable]
473
+ * 6. Gate 4: enforceOutputFormatGate(format, command) [if applicable]
474
+ * 7. Gate 5: enforceArgumentGuard(parsedCommand) [if applicable]
475
+ * 8. Command dispatch (switch/case)
476
+ *
477
+ * ERROR HANDLING CONTRACT:
478
+ * On validation failure, enforceArgumentGuard():
479
+ * 1. Writes a structured error message to stderr
480
+ * 2. Calls process.exit(EXIT_CODES.ARG_VALIDATION_ERROR)
481
+ * 3. Never returns — the process terminates
482
+ * 4. Never throws — exit is immediate
483
+ * 5. Never logs to stdout — only stderr
484
+ *
485
+ * The error message format is deterministic:
486
+ * Line 1: "Error: <violation type>"
487
+ * Line 2: (blank)
488
+ * Line 3+: Contextual details (expected type, received value)
489
+ * Line N-2: (blank)
490
+ * Line N-1: "Usage: agentics <command> <args...>"
491
+ * Line N: "Example: agentics <command> <example-value>"
492
+ *
493
+ * ============================================================================
494
+ * CI ENFORCEMENT PLAN
495
+ * ============================================================================
496
+ *
497
+ * WHAT RUNS ON PR:
498
+ * 1. Schema structural validation (all fields present, no duplicates)
499
+ * 2. Schema-command parity check (every dispatch has a schema entry)
500
+ * 3. Argument contract behavior tests (generated from schema)
501
+ * 4. TypeScript compilation (catches type-level contract violations)
502
+ * 5. Existing unit test suite
503
+ *
504
+ * WHAT RUNS ON MERGE TO MAIN:
505
+ * All PR checks, plus:
506
+ * 6. Help output snapshot comparison
507
+ * 7. Gate bypass static analysis
508
+ * 8. Schema version consistency check
509
+ *
510
+ * WHAT RUNS ON RELEASE:
511
+ * All merge checks, plus:
512
+ * 9. Schema export as CI artifact (for external consumers)
513
+ * 10. ADR version compatibility validation
514
+ * 11. Changelog entry verification for schema changes
515
+ *
516
+ * FAILURE CONDITIONS:
517
+ * - Command in dispatch without schema entry → FAIL with file:line
518
+ * - Schema entry without dispatch implementation → FAIL with command name
519
+ * - Argument contract change without version bump → FAIL with diff
520
+ * - Help snapshot changed without schema change → FAIL with snapshot diff
521
+ * - Gate bypassed in any code path → FAIL with bypass location
522
+ *
523
+ * DEVELOPER FEEDBACK LOOP:
524
+ * CI failures include:
525
+ * 1. The specific ADR rule violated (e.g., "Decision 3, Rule 2")
526
+ * 2. The file and line where the violation was detected
527
+ * 3. The exact fix required (add schema entry / update version / etc.)
528
+ * 4. A link to this ADR for full context
529
+ *
530
+ * ============================================================================
531
+ * EXPLICIT NON-GOALS
532
+ * ============================================================================
533
+ *
534
+ * 1. This ADR does NOT redefine command semantics.
535
+ * ADR-001 defines what commands mean. This ADR defines how those
536
+ * definitions are enforced at runtime and in CI.
537
+ *
538
+ * 2. This ADR does NOT introduce new commands.
539
+ * Adding commands is governed by ADR-001. This ADR governs the
540
+ * process by which new commands are registered and validated.
541
+ *
542
+ * 3. This ADR does NOT allow CLI inference or "helpful guessing".
543
+ * The CLI is deterministic. Invalid input produces a fixed error.
544
+ * There is no fuzzy matching, no "did you mean", no autocorrect.
545
+ *
546
+ * 4. This ADR does NOT weaken synthesis boundaries.
547
+ * SYNTHESIS_FORBIDDEN means forbidden. No exceptions. No overrides.
548
+ * No environment variables to relax this constraint.
549
+ *
550
+ * 5. This ADR does NOT replace existing gate logic.
551
+ * Gates 1-4 remain unchanged. This ADR formalizes Gate 5 and
552
+ * adds CI enforcement across all gates.
553
+ *
554
+ * ============================================================================
555
+ * SUCCESS CRITERIA
556
+ * ============================================================================
557
+ *
558
+ * This ADR is successful if and only if:
559
+ *
560
+ * 1. Changing CLI behavior REQUIRES changing the schema
561
+ * - No command can be added, removed, or modified without updating
562
+ * COMMAND_REGISTRY in adr-command-semantics.ts
563
+ *
564
+ * 2. Breaking the schema BREAKS CI
565
+ * - Any structural or semantic violation in the registry causes
566
+ * CI to fail with an actionable error message
567
+ *
568
+ * 3. Help text CANNOT lie
569
+ * - All user-facing help text is derived from COMMAND_REGISTRY
570
+ * - Snapshot tests detect any divergence
571
+ *
572
+ * 4. Validation CANNOT be bypassed
573
+ * - The 5-gate pipeline is the only execution path
574
+ * - Static analysis detects any bypass in PRs
575
+ *
576
+ * 5. The CLI behaves like claude-flow / claude-code, not a chat tool
577
+ * - Deterministic: same inputs → same dispatch path
578
+ * - Explicit: no inference, no guessing, no auto-correction
579
+ * - Enterprise-grade: fail fast with instructional errors
580
+ * - Composable: commands are pipeline stages, not chat turns
581
+ *
582
+ * ============================================================================
583
+ * ALTERNATIVES CONSIDERED
584
+ * ============================================================================
585
+ *
586
+ * A. External YAML/JSON schema file loaded at runtime:
587
+ * Rejected — loses TypeScript compile-time safety, adds file I/O
588
+ * at startup, creates a second source of truth that can diverge
589
+ * from the TypeScript types.
590
+ *
591
+ * B. Runtime schema generation from TypeScript decorators:
592
+ * Rejected — decorators add complexity, are hard to audit, and
593
+ * create implicit registration that's easy to miss in review.
594
+ *
595
+ * C. Per-command validation in each handler:
596
+ * Rejected — distributes validation logic, makes it impossible
597
+ * to audit centrally, and guarantees drift over time.
598
+ *
599
+ * D. Lint rules instead of CI tests:
600
+ * Rejected — lint rules can be disabled with inline comments,
601
+ * and don't catch semantic violations (e.g., schema entry
602
+ * exists but with wrong synthesis class).
603
+ *
604
+ * E. Optional enforcement with gradual rollout:
605
+ * Rejected — optional enforcement is no enforcement. The gate
606
+ * is either in the pipeline or it isn't.
607
+ *
608
+ * ============================================================================
609
+ * CLAUDE-CODE PARITY STATEMENT
610
+ * ============================================================================
611
+ *
612
+ * This operational enforcement model mirrors claude-flow / claude-code
613
+ * behavior:
614
+ *
615
+ * - Schema-driven: behavior is defined by data structures, not prose
616
+ * - Gate pipeline: sequential validation before any side effects
617
+ * - Fail-fast: violations terminate immediately with clear diagnostics
618
+ * - No inference: the system does what it's told, or rejects the input
619
+ * - Auditable: every decision can be traced to a registry entry
620
+ * - CI-enforced: governance is mechanical, not aspirational
621
+ */
622
+ /**
623
+ * ADR schema version. Must be bumped when:
624
+ * - MAJOR: argument contracts change in a breaking way
625
+ * - MINOR: new commands are added
626
+ * - PATCH: help text, examples, or descriptions are corrected
627
+ */
628
+ export declare const ADR_SCHEMA_VERSION: "1.0.0";
629
+ /**
630
+ * ADR-002 identifier. Distinct from ADR-001.
631
+ */
632
+ export declare const ADR_002_ID: "ADR-002";
633
+ export declare const ADR_002_TITLE: "Operational Enforcement of CLI Governance";
634
+ export declare const ADR_002_STATUS: "Accepted";
635
+ export declare const ADR_002_DATE: "2026-01-28";
636
+ /**
637
+ * Gate enforcement order. This is the canonical definition of the
638
+ * gate pipeline. Any code that dispatches commands must execute
639
+ * these gates in this exact order.
640
+ */
641
+ export declare const GATE_PIPELINE: readonly [{
642
+ readonly gate: 1;
643
+ readonly name: "ExecutionGate";
644
+ readonly module: "gates/execution-gate.ts";
645
+ readonly description: "Kill-switch / entitlement check";
646
+ }, {
647
+ readonly gate: 2;
648
+ readonly name: "AuthSessionGate";
649
+ readonly module: "gates/auth-session-gate.ts";
650
+ readonly description: "Requires authenticated session";
651
+ }, {
652
+ readonly gate: 3;
653
+ readonly name: "ServiceHealthGate";
654
+ readonly module: "gates/service-health-gate.ts";
655
+ readonly description: "Validates backend availability";
656
+ }, {
657
+ readonly gate: 4;
658
+ readonly name: "OutputFormatGate";
659
+ readonly module: "gates/output-format-gate.ts";
660
+ readonly description: "Enforces structured output";
661
+ }, {
662
+ readonly gate: 5;
663
+ readonly name: "ArgumentGuard";
664
+ readonly module: "gates/argument-guard.ts";
665
+ readonly description: "ADR-001 contract enforcement";
666
+ }];
667
+ /**
668
+ * Commands exempt from argument validation.
669
+ * These commands exit before the gate pipeline.
670
+ */
671
+ export declare const GATE_EXEMPT_COMMANDS: readonly ["help", "version"];
672
+ /**
673
+ * CI check identifiers for traceability in failure messages.
674
+ */
675
+ export declare const CI_CHECK_IDS: {
676
+ readonly SCHEMA_STRUCTURAL_VALIDATION: "ADR-002.D3.R1";
677
+ readonly COMMAND_SCHEMA_PARITY: "ADR-002.D3.R2";
678
+ readonly SCHEMA_IMPLEMENTATION_PARITY: "ADR-002.D3.R3";
679
+ readonly HELP_SCHEMA_DERIVATION: "ADR-002.D3.R4";
680
+ readonly COMMAND_BEHAVIOR_TESTS: "ADR-002.D3.R5";
681
+ readonly GATE_BYPASS_DETECTION: "ADR-002.D3.R6";
682
+ readonly VERSION_COMPATIBILITY: "ADR-002.D3.R7";
683
+ };
684
+ //# sourceMappingURL=adr-002-operational-enforcement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adr-002-operational-enforcement.d.ts","sourceRoot":"","sources":["../../src/contracts/adr-002-operational-enforcement.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4mBG;AAMH;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,EAAG,OAAgB,CAAC;AAEnD;;GAEG;AACH,eAAO,MAAM,UAAU,EAAG,SAAkB,CAAC;AAC7C,eAAO,MAAM,aAAa,EAAG,2CAAoD,CAAC;AAClF,eAAO,MAAM,cAAc,EAAG,UAAmB,CAAC;AAClD,eAAO,MAAM,YAAY,EAAG,YAAqB,CAAC;AAMlD;;;;GAIG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;EAMhB,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,oBAAoB,8BAA+B,CAAC;AAEjE;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;;;;CAQf,CAAC"}