@llm-dev-ops/agentics-cli 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/adapters/base-adapter.d.ts +73 -0
- package/dist/adapters/base-adapter.d.ts.map +1 -0
- package/dist/adapters/base-adapter.js +311 -0
- package/dist/adapters/base-adapter.js.map +1 -0
- package/dist/adapters/index.d.ts +8 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +7 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/audit/audit-trail.d.ts +68 -0
- package/dist/audit/audit-trail.d.ts.map +1 -0
- package/dist/audit/audit-trail.js +172 -0
- package/dist/audit/audit-trail.js.map +1 -0
- package/dist/cli/index.d.ts +15 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +265 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/commands/deploy.d.ts +23 -0
- package/dist/commands/deploy.d.ts.map +1 -0
- package/dist/commands/deploy.js +97 -0
- package/dist/commands/deploy.js.map +1 -0
- package/dist/commands/diligence.d.ts +23 -0
- package/dist/commands/diligence.d.ts.map +1 -0
- package/dist/commands/diligence.js +97 -0
- package/dist/commands/diligence.js.map +1 -0
- package/dist/commands/export.d.ts +23 -0
- package/dist/commands/export.d.ts.map +1 -0
- package/dist/commands/export.js +99 -0
- package/dist/commands/export.js.map +1 -0
- package/dist/commands/index.d.ts +20 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +13 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/inspect.d.ts +25 -0
- package/dist/commands/inspect.d.ts.map +1 -0
- package/dist/commands/inspect.js +101 -0
- package/dist/commands/inspect.js.map +1 -0
- package/dist/commands/plan.d.ts +23 -0
- package/dist/commands/plan.d.ts.map +1 -0
- package/dist/commands/plan.js +114 -0
- package/dist/commands/plan.js.map +1 -0
- package/dist/commands/quantify.d.ts +26 -0
- package/dist/commands/quantify.d.ts.map +1 -0
- package/dist/commands/quantify.js +102 -0
- package/dist/commands/quantify.js.map +1 -0
- package/dist/commands/simulate.d.ts +23 -0
- package/dist/commands/simulate.d.ts.map +1 -0
- package/dist/commands/simulate.js +97 -0
- package/dist/commands/simulate.js.map +1 -0
- package/dist/config/endpoints.d.ts +16 -0
- package/dist/config/endpoints.d.ts.map +1 -0
- package/dist/config/endpoints.js +73 -0
- package/dist/config/endpoints.js.map +1 -0
- package/dist/errors/index.d.ts +120 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +281 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/modules/artifact-handoff.d.ts +57 -0
- package/dist/modules/artifact-handoff.d.ts.map +1 -0
- package/dist/modules/artifact-handoff.js +85 -0
- package/dist/modules/artifact-handoff.js.map +1 -0
- package/dist/modules/command-parser.d.ts +28 -0
- package/dist/modules/command-parser.d.ts.map +1 -0
- package/dist/modules/command-parser.js +176 -0
- package/dist/modules/command-parser.js.map +1 -0
- package/dist/modules/index.d.ts +14 -0
- package/dist/modules/index.d.ts.map +1 -0
- package/dist/modules/index.js +10 -0
- package/dist/modules/index.js.map +1 -0
- package/dist/modules/orchestration-engine.d.ts +43 -0
- package/dist/modules/orchestration-engine.d.ts.map +1 -0
- package/dist/modules/orchestration-engine.js +159 -0
- package/dist/modules/orchestration-engine.js.map +1 -0
- package/dist/modules/output-renderer.d.ts +51 -0
- package/dist/modules/output-renderer.d.ts.map +1 -0
- package/dist/modules/output-renderer.js +193 -0
- package/dist/modules/output-renderer.js.map +1 -0
- package/dist/types/index.d.ts +223 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +33 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simulate Command
|
|
3
|
+
*
|
|
4
|
+
* SPARC Pseudocode Reference: §2.2
|
|
5
|
+
*
|
|
6
|
+
* FLOW:
|
|
7
|
+
* 1. Parse arguments → CommandObject
|
|
8
|
+
* 2. Execute simulation via agentics-simulation-runner
|
|
9
|
+
* 3. Record audit entry
|
|
10
|
+
* 4. Return SimulationReference
|
|
11
|
+
*/
|
|
12
|
+
import { RunnerAdapter } from '../adapters/base-adapter.js';
|
|
13
|
+
import { createOrchestrationEngine, } from '../modules/orchestration-engine.js';
|
|
14
|
+
import { createArtifactHandoff } from '../modules/artifact-handoff.js';
|
|
15
|
+
import { createAuditTrail } from '../audit/audit-trail.js';
|
|
16
|
+
import { failFast } from '../errors/index.js';
|
|
17
|
+
import { loadEndpointConfig } from '../config/endpoints.js';
|
|
18
|
+
// ============================================================================
|
|
19
|
+
// Simulate Command Implementation
|
|
20
|
+
// ============================================================================
|
|
21
|
+
export async function executeSimulateCommand(input, options) {
|
|
22
|
+
const correlationId = options.trace_id ?? crypto.randomUUID();
|
|
23
|
+
const startTime = Date.now();
|
|
24
|
+
// Initialize components
|
|
25
|
+
const engine = createOrchestrationEngine(correlationId);
|
|
26
|
+
const handoff = createArtifactHandoff();
|
|
27
|
+
const audit = createAuditTrail();
|
|
28
|
+
// Create adapter
|
|
29
|
+
const runnerConfig = loadEndpointConfig('agentics-simulation-runner');
|
|
30
|
+
const runnerAdapter = new RunnerAdapter(runnerConfig, correlationId);
|
|
31
|
+
// Define orchestration stages
|
|
32
|
+
const stages = [
|
|
33
|
+
{
|
|
34
|
+
name: 'execute-simulation',
|
|
35
|
+
adapter: runnerAdapter,
|
|
36
|
+
request: {
|
|
37
|
+
endpoint: '/api/v1/simulations/execute',
|
|
38
|
+
method: 'POST',
|
|
39
|
+
buildBody: () => ({
|
|
40
|
+
plan_ref: handoff.passthrough(input.planRef),
|
|
41
|
+
config: input.config ?? {},
|
|
42
|
+
iterations: input.iterations ?? 1,
|
|
43
|
+
}),
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
try {
|
|
48
|
+
// Execute orchestration
|
|
49
|
+
const result = await engine.execute(stages, options);
|
|
50
|
+
if (!result.success) {
|
|
51
|
+
const failedStage = result.stages.find(s => s.status === 'failed');
|
|
52
|
+
throw new Error(failedStage?.error?.message ?? 'Simulation failed');
|
|
53
|
+
}
|
|
54
|
+
// Extract simulation reference
|
|
55
|
+
const simStage = result.stages.find(s => s.name === 'execute-simulation');
|
|
56
|
+
const simRef = handoff.extractReference(simStage?.response);
|
|
57
|
+
// Record audit entry
|
|
58
|
+
audit.record({
|
|
59
|
+
command: 'simulate',
|
|
60
|
+
inputs: { planRef: input.planRef.id, config: input.config, iterations: input.iterations },
|
|
61
|
+
outputs: simRef,
|
|
62
|
+
dependencies: [
|
|
63
|
+
{ service: 'agentics-simulation-runner', method: 'execute', timestamp: new Date().toISOString(), duration_ms: result.timing.total, success: true },
|
|
64
|
+
],
|
|
65
|
+
duration_ms: result.timing.total,
|
|
66
|
+
status: 'SUCCESS',
|
|
67
|
+
trace_id: correlationId,
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
reference: simRef,
|
|
71
|
+
timing: Date.now() - startTime,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
// Record failure in audit
|
|
76
|
+
audit.record({
|
|
77
|
+
command: 'simulate',
|
|
78
|
+
inputs: { planRef: input.planRef.id, config: input.config },
|
|
79
|
+
outputs: null,
|
|
80
|
+
dependencies: [],
|
|
81
|
+
duration_ms: Date.now() - startTime,
|
|
82
|
+
status: 'FAILED',
|
|
83
|
+
error_code: error instanceof Error ? error.name : 'UNKNOWN',
|
|
84
|
+
error_message: error instanceof Error ? error.message : 'Unknown error',
|
|
85
|
+
trace_id: correlationId,
|
|
86
|
+
});
|
|
87
|
+
// Fail fast
|
|
88
|
+
failFast({
|
|
89
|
+
command: 'simulate',
|
|
90
|
+
phase: 'execution',
|
|
91
|
+
upstreamError: error instanceof Error ? error : new Error(String(error)),
|
|
92
|
+
inputs: input,
|
|
93
|
+
correlationId,
|
|
94
|
+
});
|
|
95
|
+
}
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*
|
|
4
|
+
* SPARC Architecture Reference: §2.4
|
|
5
|
+
*
|
|
6
|
+
* PURPOSE: Define downstream service endpoints
|
|
7
|
+
*
|
|
8
|
+
* FORBIDDEN:
|
|
9
|
+
* - Business Logic
|
|
10
|
+
* - Dynamic endpoint construction based on data
|
|
11
|
+
*/
|
|
12
|
+
import type { EndpointRegistry, EndpointConfig } from '../types/index.js';
|
|
13
|
+
export declare const DEFAULT_ENDPOINTS: EndpointRegistry;
|
|
14
|
+
export declare function loadEndpointConfig(serviceName: keyof EndpointRegistry, overrides?: Partial<EndpointConfig>): EndpointConfig;
|
|
15
|
+
export declare function loadAllEndpoints(overrides?: Partial<EndpointRegistry>): EndpointRegistry;
|
|
16
|
+
//# sourceMappingURL=endpoints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoints.d.ts","sourceRoot":"","sources":["../../src/config/endpoints.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAM1E,eAAO,MAAM,iBAAiB,EAAE,gBAyC/B,CAAC;AAMF,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,MAAM,gBAAgB,EACnC,SAAS,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,GAClC,cAAc,CAMhB;AAED,wBAAgB,gBAAgB,CAC9B,SAAS,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GACpC,gBAAgB,CAKlB"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Endpoint Configuration
|
|
3
|
+
*
|
|
4
|
+
* SPARC Architecture Reference: §2.4
|
|
5
|
+
*
|
|
6
|
+
* PURPOSE: Define downstream service endpoints
|
|
7
|
+
*
|
|
8
|
+
* FORBIDDEN:
|
|
9
|
+
* - Business Logic
|
|
10
|
+
* - Dynamic endpoint construction based on data
|
|
11
|
+
*/
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// Default Endpoint Configuration
|
|
14
|
+
// ============================================================================
|
|
15
|
+
export const DEFAULT_ENDPOINTS = {
|
|
16
|
+
'agentics-org-manifests': {
|
|
17
|
+
baseUrl: process.env['AGENTICS_MANIFESTS_URL'] ?? 'https://manifests.agentics.org',
|
|
18
|
+
version: 'v1',
|
|
19
|
+
timeout: 30000,
|
|
20
|
+
},
|
|
21
|
+
'agentics-simulation-planner': {
|
|
22
|
+
baseUrl: process.env['AGENTICS_PLANNER_URL'] ?? 'https://planner.agentics.org',
|
|
23
|
+
version: 'v1',
|
|
24
|
+
timeout: 60000,
|
|
25
|
+
},
|
|
26
|
+
'agentics-simulation-runner': {
|
|
27
|
+
baseUrl: process.env['AGENTICS_RUNNER_URL'] ?? 'https://runner.agentics.org',
|
|
28
|
+
version: 'v1',
|
|
29
|
+
timeout: 300000, // 5 minutes for simulations
|
|
30
|
+
},
|
|
31
|
+
'agentics-simulation-engine': {
|
|
32
|
+
baseUrl: process.env['AGENTICS_SIMULATION_ENGINE_URL'] ?? 'https://simulation-engine.agentics.org',
|
|
33
|
+
version: 'v1',
|
|
34
|
+
timeout: 120000, // 2 minutes for artifact retrieval
|
|
35
|
+
},
|
|
36
|
+
'enterprise-roi-engine': {
|
|
37
|
+
baseUrl: process.env['ENTERPRISE_ROI_ENGINE_URL'] ?? 'https://roi-engine.agentics.org',
|
|
38
|
+
version: 'v1',
|
|
39
|
+
timeout: 180000, // 3 minutes for ROI calculations
|
|
40
|
+
},
|
|
41
|
+
'agentics-deployment-intent': {
|
|
42
|
+
baseUrl: process.env['AGENTICS_INTENT_URL'] ?? 'https://intent.agentics.org',
|
|
43
|
+
version: 'v1',
|
|
44
|
+
timeout: 60000,
|
|
45
|
+
},
|
|
46
|
+
'agentics-deployment-exporters': {
|
|
47
|
+
baseUrl: process.env['AGENTICS_EXPORTERS_URL'] ?? 'https://exporters.agentics.org',
|
|
48
|
+
version: 'v1',
|
|
49
|
+
timeout: 120000,
|
|
50
|
+
},
|
|
51
|
+
'diligence-artifacts': {
|
|
52
|
+
baseUrl: process.env['DILIGENCE_URL'] ?? 'https://diligence.agentics.org',
|
|
53
|
+
version: 'v1',
|
|
54
|
+
timeout: 180000,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
// ============================================================================
|
|
58
|
+
// Configuration Loader
|
|
59
|
+
// ============================================================================
|
|
60
|
+
export function loadEndpointConfig(serviceName, overrides) {
|
|
61
|
+
const defaults = DEFAULT_ENDPOINTS[serviceName];
|
|
62
|
+
return {
|
|
63
|
+
...defaults,
|
|
64
|
+
...overrides,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export function loadAllEndpoints(overrides) {
|
|
68
|
+
return {
|
|
69
|
+
...DEFAULT_ENDPOINTS,
|
|
70
|
+
...overrides,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=endpoints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoints.js","sourceRoot":"","sources":["../../src/config/endpoints.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,+EAA+E;AAC/E,iCAAiC;AACjC,+EAA+E;AAE/E,MAAM,CAAC,MAAM,iBAAiB,GAAqB;IACjD,wBAAwB,EAAE;QACxB,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,IAAI,gCAAgC;QAClF,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,KAAK;KACf;IACD,6BAA6B,EAAE;QAC7B,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,IAAI,8BAA8B;QAC9E,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,KAAK;KACf;IACD,4BAA4B,EAAE;QAC5B,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,IAAI,6BAA6B;QAC5E,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,MAAM,EAAE,4BAA4B;KAC9C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
|
|
6
|
+
* PURPOSE: Surface errors with context (no recovery)
|
|
7
|
+
*
|
|
8
|
+
* FORBIDDEN:
|
|
9
|
+
* - Error Recovery (NO retry logic)
|
|
10
|
+
* - Error Suppression (NO swallowing errors)
|
|
11
|
+
* - Error Transformation (NO changing error semantics)
|
|
12
|
+
* - Fallback Logic (NO alternative paths on error)
|
|
13
|
+
*/
|
|
14
|
+
import type { ErrorInfo, ErrorCategory, ContractViolation, ViolationType, ExitCode } from '../types/index.js';
|
|
15
|
+
export declare class CLIError extends Error {
|
|
16
|
+
readonly code: string;
|
|
17
|
+
readonly category: ErrorCategory;
|
|
18
|
+
readonly details?: Record<string, unknown>;
|
|
19
|
+
readonly timestamp: string;
|
|
20
|
+
readonly module: string;
|
|
21
|
+
readonly correlationId?: string;
|
|
22
|
+
readonly recoverable: boolean;
|
|
23
|
+
readonly exitCode: ExitCode;
|
|
24
|
+
constructor(options: {
|
|
25
|
+
code: string;
|
|
26
|
+
category: ErrorCategory;
|
|
27
|
+
message: string;
|
|
28
|
+
details?: Record<string, unknown>;
|
|
29
|
+
module: string;
|
|
30
|
+
correlationId?: string;
|
|
31
|
+
recoverable?: boolean;
|
|
32
|
+
exitCode?: ExitCode;
|
|
33
|
+
cause?: Error;
|
|
34
|
+
});
|
|
35
|
+
toErrorInfo(): ErrorInfo;
|
|
36
|
+
}
|
|
37
|
+
export declare class ValidationError extends CLIError {
|
|
38
|
+
constructor(options: {
|
|
39
|
+
message: string;
|
|
40
|
+
field?: string;
|
|
41
|
+
expected?: string;
|
|
42
|
+
actual?: string;
|
|
43
|
+
correlationId?: string;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
export declare class ReferenceValidationError extends CLIError {
|
|
47
|
+
constructor(options: {
|
|
48
|
+
refId: string;
|
|
49
|
+
refType: string;
|
|
50
|
+
repository: string;
|
|
51
|
+
reason: string;
|
|
52
|
+
correlationId?: string;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
export declare class ServiceError extends CLIError {
|
|
56
|
+
constructor(options: {
|
|
57
|
+
service: string;
|
|
58
|
+
operation: string;
|
|
59
|
+
type: 'unavailable' | 'timeout' | 'internal_error';
|
|
60
|
+
statusCode?: number;
|
|
61
|
+
upstreamMessage?: string;
|
|
62
|
+
correlationId?: string;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
export declare class ContractViolationError extends CLIError {
|
|
66
|
+
readonly violation: ContractViolation;
|
|
67
|
+
constructor(options: {
|
|
68
|
+
service: string;
|
|
69
|
+
expectedContract: string;
|
|
70
|
+
actualResponse: unknown;
|
|
71
|
+
violationType: ViolationType;
|
|
72
|
+
correlationId?: string;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
export declare class ConfigError extends CLIError {
|
|
76
|
+
constructor(options: {
|
|
77
|
+
message: string;
|
|
78
|
+
configPath?: string;
|
|
79
|
+
missingKey?: string;
|
|
80
|
+
correlationId?: string;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
export declare class AuthError extends CLIError {
|
|
84
|
+
constructor(options: {
|
|
85
|
+
type: 'missing' | 'invalid' | 'expired' | 'insufficient';
|
|
86
|
+
message: string;
|
|
87
|
+
correlationId?: string;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
export interface IErrorHandler {
|
|
91
|
+
handle(error: Error, context: ErrorContext): ErrorInfo;
|
|
92
|
+
format(info: ErrorInfo, options: FormatOptions): string;
|
|
93
|
+
}
|
|
94
|
+
export interface ErrorContext {
|
|
95
|
+
command?: string;
|
|
96
|
+
phase?: string;
|
|
97
|
+
inputs?: unknown;
|
|
98
|
+
correlationId?: string;
|
|
99
|
+
}
|
|
100
|
+
export interface FormatOptions {
|
|
101
|
+
format: 'json' | 'text';
|
|
102
|
+
pretty?: boolean;
|
|
103
|
+
includeStack?: boolean;
|
|
104
|
+
}
|
|
105
|
+
export declare class ErrorHandler implements IErrorHandler {
|
|
106
|
+
handle(error: Error, context: ErrorContext): ErrorInfo;
|
|
107
|
+
format(info: ErrorInfo, options: FormatOptions): string;
|
|
108
|
+
}
|
|
109
|
+
export declare function failFast(options: {
|
|
110
|
+
command: string;
|
|
111
|
+
phase: string;
|
|
112
|
+
upstreamError: Error;
|
|
113
|
+
inputs: unknown;
|
|
114
|
+
partialRefs?: {
|
|
115
|
+
id: string;
|
|
116
|
+
}[];
|
|
117
|
+
correlationId?: string;
|
|
118
|
+
}): never;
|
|
119
|
+
export declare const errorHandler: ErrorHandler;
|
|
120
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,QAAQ,EACT,MAAM,mBAAmB,CAAC;AAM3B,qBAAa,QAAS,SAAQ,KAAK;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;IACjC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;gBAEhB,OAAO,EAAE;QACnB,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,aAAa,CAAC;QACxB,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAClC,MAAM,EAAE,MAAM,CAAC;QACf,aAAa,CAAC,EAAE,MAAM,CAAC;Q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,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC/B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,GAAG,KAAK,CAoCR;AAYD,eAAO,MAAM,YAAY,cAAqB,CAAC"}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error Handling Module (Module F)
|
|
3
|
+
*
|
|
4
|
+
* SPARC Architecture Reference: §2.7
|
|
5
|
+
*
|
|
6
|
+
* PURPOSE: Surface errors with context (no recovery)
|
|
7
|
+
*
|
|
8
|
+
* FORBIDDEN:
|
|
9
|
+
* - Error Recovery (NO retry logic)
|
|
10
|
+
* - Error Suppression (NO swallowing errors)
|
|
11
|
+
* - Error Transformation (NO changing error semantics)
|
|
12
|
+
* - Fallback Logic (NO alternative paths on error)
|
|
13
|
+
*/
|
|
14
|
+
import * as crypto from 'node:crypto';
|
|
15
|
+
// ============================================================================
|
|
16
|
+
// Base CLI Error Class
|
|
17
|
+
// ============================================================================
|
|
18
|
+
export class CLIError extends Error {
|
|
19
|
+
code;
|
|
20
|
+
category;
|
|
21
|
+
details;
|
|
22
|
+
timestamp;
|
|
23
|
+
module;
|
|
24
|
+
correlationId;
|
|
25
|
+
recoverable;
|
|
26
|
+
exitCode;
|
|
27
|
+
constructor(options) {
|
|
28
|
+
super(options.message);
|
|
29
|
+
this.name = 'CLIError';
|
|
30
|
+
this.code = options.code;
|
|
31
|
+
this.category = options.category;
|
|
32
|
+
this.details = options.details;
|
|
33
|
+
this.timestamp = new Date().toISOString();
|
|
34
|
+
this.module = options.module;
|
|
35
|
+
this.correlationId = options.correlationId;
|
|
36
|
+
this.recoverable = options.recoverable ?? false;
|
|
37
|
+
this.exitCode = options.exitCode ?? 1;
|
|
38
|
+
if (options.cause) {
|
|
39
|
+
this.cause = options.cause;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
toErrorInfo() {
|
|
43
|
+
return {
|
|
44
|
+
code: this.code,
|
|
45
|
+
category: this.category,
|
|
46
|
+
message: this.message,
|
|
47
|
+
details: this.details,
|
|
48
|
+
stack: this.stack,
|
|
49
|
+
timestamp: this.timestamp,
|
|
50
|
+
module: this.module,
|
|
51
|
+
correlationId: this.correlationId,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// ============================================================================
|
|
56
|
+
// Specific Error Classes (SPARC_PSEUDOCODE §4.1)
|
|
57
|
+
// ============================================================================
|
|
58
|
+
export class ValidationError extends CLIError {
|
|
59
|
+
constructor(options) {
|
|
60
|
+
super({
|
|
61
|
+
code: 'ECLI-ARG-002',
|
|
62
|
+
category: 'INPUT_ERROR',
|
|
63
|
+
message: options.message,
|
|
64
|
+
details: {
|
|
65
|
+
field: options.field,
|
|
66
|
+
expected: options.expected,
|
|
67
|
+
actual: options.actual,
|
|
68
|
+
},
|
|
69
|
+
module: 'validation',
|
|
70
|
+
correlationId: options.correlationId,
|
|
71
|
+
recoverable: false,
|
|
72
|
+
exitCode: 100,
|
|
73
|
+
});
|
|
74
|
+
this.name = 'ValidationError';
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
export class ReferenceValidationError extends CLIError {
|
|
78
|
+
constructor(options) {
|
|
79
|
+
super({
|
|
80
|
+
code: 'ECLI-ARG-003',
|
|
81
|
+
category: 'INPUT_ERROR',
|
|
82
|
+
message: `Reference validation failed: ${options.reason}`,
|
|
83
|
+
details: {
|
|
84
|
+
ref_id: options.refId,
|
|
85
|
+
ref_type: options.refType,
|
|
86
|
+
repository: options.repository,
|
|
87
|
+
},
|
|
88
|
+
module: 'validation',
|
|
89
|
+
correlationId: options.correlationId,
|
|
90
|
+
recoverable: false,
|
|
91
|
+
exitCode: 100,
|
|
92
|
+
});
|
|
93
|
+
this.name = 'ReferenceValidationError';
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
export class ServiceError extends CLIError {
|
|
97
|
+
constructor(options) {
|
|
98
|
+
const exitCodes = {
|
|
99
|
+
unavailable: 69,
|
|
100
|
+
timeout: 75,
|
|
101
|
+
internal_error: 140,
|
|
102
|
+
};
|
|
103
|
+
super({
|
|
104
|
+
code: options.type === 'unavailable'
|
|
105
|
+
? 'ECLI-SVC-001'
|
|
106
|
+
: options.type === 'timeout'
|
|
107
|
+
? 'ECLI-NET-002'
|
|
108
|
+
: 'ECLI-SVC-002',
|
|
109
|
+
category: options.type === 'timeout' ? 'NETWORK_ERROR' : 'DOWNSTREAM_ERROR',
|
|
110
|
+
message: `Service '${options.service}' ${options.type}: ${options.upstreamMessage ?? 'unknown error'}`,
|
|
111
|
+
details: {
|
|
112
|
+
service: options.service,
|
|
113
|
+
operation: options.operation,
|
|
114
|
+
status_code: options.statusCode,
|
|
115
|
+
},
|
|
116
|
+
module: 'adapter',
|
|
117
|
+
correlationId: options.correlationId,
|
|
118
|
+
recoverable: options.type !== 'internal_error',
|
|
119
|
+
exitCode: exitCodes[options.type] ?? 140,
|
|
120
|
+
});
|
|
121
|
+
this.name = 'ServiceError';
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
export class ContractViolationError extends CLIError {
|
|
125
|
+
violation;
|
|
126
|
+
constructor(options) {
|
|
127
|
+
super({
|
|
128
|
+
code: 'ECLI-SVC-003',
|
|
129
|
+
category: 'DOWNSTREAM_ERROR',
|
|
130
|
+
message: `Contract violation from service '${options.service}': ${options.violationType}`,
|
|
131
|
+
details: {
|
|
132
|
+
service: options.service,
|
|
133
|
+
expected_contract: options.expectedContract,
|
|
134
|
+
violation_type: options.violationType,
|
|
135
|
+
},
|
|
136
|
+
module: 'adapter',
|
|
137
|
+
correlationId: options.correlationId,
|
|
138
|
+
recoverable: false,
|
|
139
|
+
exitCode: 140,
|
|
140
|
+
});
|
|
141
|
+
this.name = 'ContractViolationError';
|
|
142
|
+
this.violation = {
|
|
143
|
+
service: options.service,
|
|
144
|
+
expected_contract: options.expectedContract,
|
|
145
|
+
actual_response: options.actualResponse,
|
|
146
|
+
violation_type: options.violationType,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
export class ConfigError extends CLIError {
|
|
151
|
+
constructor(options) {
|
|
152
|
+
super({
|
|
153
|
+
code: options.missingKey ? 'ECLI-CFG-003' : 'ECLI-CFG-002',
|
|
154
|
+
category: 'CONFIG_ERROR',
|
|
155
|
+
message: options.message,
|
|
156
|
+
details: {
|
|
157
|
+
config_path: options.configPath,
|
|
158
|
+
missing_key: options.missingKey,
|
|
159
|
+
},
|
|
160
|
+
module: 'config',
|
|
161
|
+
correlationId: options.correlationId,
|
|
162
|
+
recoverable: false,
|
|
163
|
+
exitCode: 78,
|
|
164
|
+
});
|
|
165
|
+
this.name = 'ConfigError';
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
export class AuthError extends CLIError {
|
|
169
|
+
constructor(options) {
|
|
170
|
+
const codes = {
|
|
171
|
+
missing: 'ECLI-AUTH-001',
|
|
172
|
+
invalid: 'ECLI-AUTH-002',
|
|
173
|
+
expired: 'ECLI-AUTH-002',
|
|
174
|
+
insufficient: 'ECLI-AUTH-003',
|
|
175
|
+
};
|
|
176
|
+
super({
|
|
177
|
+
code: codes[options.type] ?? 'ECLI-AUTH-001',
|
|
178
|
+
category: 'AUTH_ERROR',
|
|
179
|
+
message: options.message,
|
|
180
|
+
details: {
|
|
181
|
+
type: options.type,
|
|
182
|
+
},
|
|
183
|
+
module: 'auth',
|
|
184
|
+
correlationId: options.correlationId,
|
|
185
|
+
recoverable: false,
|
|
186
|
+
exitCode: 77,
|
|
187
|
+
});
|
|
188
|
+
this.name = 'AuthError';
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// ============================================================================
|
|
192
|
+
// Error Handler Implementation
|
|
193
|
+
// ============================================================================
|
|
194
|
+
export class ErrorHandler {
|
|
195
|
+
handle(error, context) {
|
|
196
|
+
if (error instanceof CLIError) {
|
|
197
|
+
return error.toErrorInfo();
|
|
198
|
+
}
|
|
199
|
+
// Normalize unknown errors
|
|
200
|
+
return {
|
|
201
|
+
code: 'ECLI-INT-001',
|
|
202
|
+
category: 'INTERNAL_ERROR',
|
|
203
|
+
message: error.message || 'An unexpected error occurred',
|
|
204
|
+
details: {
|
|
205
|
+
command: context.command,
|
|
206
|
+
phase: context.phase,
|
|
207
|
+
},
|
|
208
|
+
stack: error.stack,
|
|
209
|
+
timestamp: new Date().toISOString(),
|
|
210
|
+
module: 'unknown',
|
|
211
|
+
correlationId: context.correlationId,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
format(info, options) {
|
|
215
|
+
if (options.format === 'json') {
|
|
216
|
+
const output = options.includeStack
|
|
217
|
+
? info
|
|
218
|
+
: { ...info, stack: undefined };
|
|
219
|
+
return options.pretty
|
|
220
|
+
? JSON.stringify(output, null, 2)
|
|
221
|
+
: JSON.stringify(output);
|
|
222
|
+
}
|
|
223
|
+
// Text format
|
|
224
|
+
let output = `Error [${info.code}]: ${info.message}`;
|
|
225
|
+
if (info.details && Object.keys(info.details).length > 0) {
|
|
226
|
+
output += `\n Details: ${JSON.stringify(info.details)}`;
|
|
227
|
+
}
|
|
228
|
+
if (options.includeStack && info.stack) {
|
|
229
|
+
output += `\n Stack: ${info.stack}`;
|
|
230
|
+
}
|
|
231
|
+
return output;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
// ============================================================================
|
|
235
|
+
// Fail-Fast Implementation (SPARC_PSEUDOCODE §4.4)
|
|
236
|
+
// ============================================================================
|
|
237
|
+
export function failFast(options) {
|
|
238
|
+
const errorContext = {
|
|
239
|
+
command: options.command,
|
|
240
|
+
phase: options.phase,
|
|
241
|
+
inputs_hash: hashInputs(options.inputs),
|
|
242
|
+
upstream_error_code: options.upstreamError instanceof CLIError
|
|
243
|
+
? options.upstreamError.code
|
|
244
|
+
: 'UNKNOWN',
|
|
245
|
+
upstream_error_message: options.upstreamError.message,
|
|
246
|
+
partial_refs: options.partialRefs?.map(r => r.id) ?? [],
|
|
247
|
+
timestamp: new Date().toISOString(),
|
|
248
|
+
trace_id: options.correlationId,
|
|
249
|
+
};
|
|
250
|
+
// Log failure for observability
|
|
251
|
+
console.error(JSON.stringify({
|
|
252
|
+
level: 'ERROR',
|
|
253
|
+
category: 'COMMAND_FAILURE',
|
|
254
|
+
context: errorContext,
|
|
255
|
+
}));
|
|
256
|
+
// Throw wrapped error
|
|
257
|
+
throw new CLIError({
|
|
258
|
+
code: 'COMMAND_FAILED',
|
|
259
|
+
category: options.upstreamError instanceof CLIError
|
|
260
|
+
? options.upstreamError.category
|
|
261
|
+
: 'INTERNAL_ERROR',
|
|
262
|
+
message: `Command '${options.command}' failed at phase '${options.phase}': ${options.upstreamError.message}`,
|
|
263
|
+
details: errorContext,
|
|
264
|
+
module: 'orchestration',
|
|
265
|
+
correlationId: options.correlationId,
|
|
266
|
+
recoverable: options.upstreamError instanceof CLIError
|
|
267
|
+
? options.upstreamError.recoverable
|
|
268
|
+
: false,
|
|
269
|
+
cause: options.upstreamError,
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
// ============================================================================
|
|
273
|
+
// Utility Functions
|
|
274
|
+
// ============================================================================
|
|
275
|
+
function hashInputs(inputs) {
|
|
276
|
+
const canonical = JSON.stringify(inputs, Object.keys(inputs).sort());
|
|
277
|
+
return crypto.createHash('sha256').update(canonical).digest('hex').slice(0, 16);
|
|
278
|
+
}
|
|
279
|
+
// Singleton handler instance
|
|
280
|
+
export const errorHandler = new ErrorHandler();
|
|
281
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAStC,+EAA+E;AAC/E,uBAAuB;AACvB,+EAA+E;AAE/E,MAAM,OAAO,QAAS,SAAQ,KAAK;IACxB,IAAI,CAAS;IACb,QAAQ,CAAgB;IACxB,OAAO,CAA2B;IAClC,SAAS,CAAS;IACl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