@ontologie/cli 0.1.0-preview.1
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 +492 -0
- package/dist/cache/keys.d.ts +11 -0
- package/dist/cache/keys.d.ts.map +1 -0
- package/dist/cache/keys.js +14 -0
- package/dist/cache/keys.js.map +1 -0
- package/dist/cache/store.d.ts +23 -0
- package/dist/cache/store.d.ts.map +1 -0
- package/dist/cache/store.js +160 -0
- package/dist/cache/store.js.map +1 -0
- package/dist/cli-compat.d.ts +6 -0
- package/dist/cli-compat.d.ts.map +1 -0
- package/dist/cli-compat.js +11 -0
- package/dist/cli-compat.js.map +1 -0
- package/dist/cli.d.ts +30 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +119 -0
- package/dist/cli.js.map +1 -0
- package/dist/client.d.ts +7 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +15 -0
- package/dist/client.js.map +1 -0
- package/dist/commands/actions.d.ts +22 -0
- package/dist/commands/actions.d.ts.map +1 -0
- package/dist/commands/actions.js +211 -0
- package/dist/commands/actions.js.map +1 -0
- package/dist/commands/agent-files.d.ts +27 -0
- package/dist/commands/agent-files.d.ts.map +1 -0
- package/dist/commands/agent-files.js +167 -0
- package/dist/commands/agent-files.js.map +1 -0
- package/dist/commands/agent.d.ts +23 -0
- package/dist/commands/agent.d.ts.map +1 -0
- package/dist/commands/agent.js +314 -0
- package/dist/commands/agent.js.map +1 -0
- package/dist/commands/audit.d.ts +11 -0
- package/dist/commands/audit.d.ts.map +1 -0
- package/dist/commands/audit.js +94 -0
- package/dist/commands/audit.js.map +1 -0
- package/dist/commands/cache.d.ts +8 -0
- package/dist/commands/cache.d.ts.map +1 -0
- package/dist/commands/cache.js +40 -0
- package/dist/commands/cache.js.map +1 -0
- package/dist/commands/capabilities.d.ts +56 -0
- package/dist/commands/capabilities.d.ts.map +1 -0
- package/dist/commands/capabilities.js +304 -0
- package/dist/commands/capabilities.js.map +1 -0
- package/dist/commands/check.d.ts +7 -0
- package/dist/commands/check.d.ts.map +1 -0
- package/dist/commands/check.js +16 -0
- package/dist/commands/check.js.map +1 -0
- package/dist/commands/config.d.ts +6 -0
- package/dist/commands/config.d.ts.map +1 -0
- package/dist/commands/config.js +133 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/context.d.ts +6 -0
- package/dist/commands/context.d.ts.map +1 -0
- package/dist/commands/context.js +226 -0
- package/dist/commands/context.js.map +1 -0
- package/dist/commands/dev.d.ts +15 -0
- package/dist/commands/dev.d.ts.map +1 -0
- package/dist/commands/dev.js +62 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/docs-alias.d.ts +14 -0
- package/dist/commands/docs-alias.d.ts.map +1 -0
- package/dist/commands/docs-alias.js +28 -0
- package/dist/commands/docs-alias.js.map +1 -0
- package/dist/commands/docs.d.ts +6 -0
- package/dist/commands/docs.d.ts.map +1 -0
- package/dist/commands/docs.js +67 -0
- package/dist/commands/docs.js.map +1 -0
- package/dist/commands/doctor.d.ts +6 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +161 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/generate.d.ts +7 -0
- package/dist/commands/generate.d.ts.map +1 -0
- package/dist/commands/generate.js +36 -0
- package/dist/commands/generate.js.map +1 -0
- package/dist/commands/graph.d.ts +9 -0
- package/dist/commands/graph.d.ts.map +1 -0
- package/dist/commands/graph.js +149 -0
- package/dist/commands/graph.js.map +1 -0
- package/dist/commands/import.d.ts +19 -0
- package/dist/commands/import.d.ts.map +1 -0
- package/dist/commands/import.js +330 -0
- package/dist/commands/import.js.map +1 -0
- package/dist/commands/index.d.ts +80 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +345 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/init.d.ts +7 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +101 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/instances.d.ts +7 -0
- package/dist/commands/instances.d.ts.map +1 -0
- package/dist/commands/instances.js +418 -0
- package/dist/commands/instances.js.map +1 -0
- package/dist/commands/keys.d.ts +6 -0
- package/dist/commands/keys.d.ts.map +1 -0
- package/dist/commands/keys.js +113 -0
- package/dist/commands/keys.js.map +1 -0
- package/dist/commands/knowledge.d.ts +6 -0
- package/dist/commands/knowledge.d.ts.map +1 -0
- package/dist/commands/knowledge.js +76 -0
- package/dist/commands/knowledge.js.map +1 -0
- package/dist/commands/model.d.ts +3 -0
- package/dist/commands/model.d.ts.map +1 -0
- package/dist/commands/model.js +40 -0
- package/dist/commands/model.js.map +1 -0
- package/dist/commands/nodes.d.ts +6 -0
- package/dist/commands/nodes.d.ts.map +1 -0
- package/dist/commands/nodes.js +111 -0
- package/dist/commands/nodes.js.map +1 -0
- package/dist/commands/openapi.d.ts +7 -0
- package/dist/commands/openapi.d.ts.map +1 -0
- package/dist/commands/openapi.js +17 -0
- package/dist/commands/openapi.js.map +1 -0
- package/dist/commands/plan.d.ts +19 -0
- package/dist/commands/plan.d.ts.map +1 -0
- package/dist/commands/plan.js +563 -0
- package/dist/commands/plan.js.map +1 -0
- package/dist/commands/process.d.ts +3 -0
- package/dist/commands/process.d.ts.map +1 -0
- package/dist/commands/process.js +67 -0
- package/dist/commands/process.js.map +1 -0
- package/dist/commands/query.d.ts +26 -0
- package/dist/commands/query.d.ts.map +1 -0
- package/dist/commands/query.js +253 -0
- package/dist/commands/query.js.map +1 -0
- package/dist/commands/schema.d.ts +24 -0
- package/dist/commands/schema.d.ts.map +1 -0
- package/dist/commands/schema.js +933 -0
- package/dist/commands/schema.js.map +1 -0
- package/dist/commands/search.d.ts +10 -0
- package/dist/commands/search.d.ts.map +1 -0
- package/dist/commands/search.js +74 -0
- package/dist/commands/search.js.map +1 -0
- package/dist/commands/shared.d.ts +32 -0
- package/dist/commands/shared.d.ts.map +1 -0
- package/dist/commands/shared.js +63 -0
- package/dist/commands/shared.js.map +1 -0
- package/dist/commands/usage.d.ts +6 -0
- package/dist/commands/usage.d.ts.map +1 -0
- package/dist/commands/usage.js +86 -0
- package/dist/commands/usage.js.map +1 -0
- package/dist/commands/validators.d.ts +30 -0
- package/dist/commands/validators.d.ts.map +1 -0
- package/dist/commands/validators.js +93 -0
- package/dist/commands/validators.js.map +1 -0
- package/dist/commands/whoami.d.ts +6 -0
- package/dist/commands/whoami.d.ts.map +1 -0
- package/dist/commands/whoami.js +48 -0
- package/dist/commands/whoami.js.map +1 -0
- package/dist/config.d.ts +47 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +127 -0
- package/dist/config.js.map +1 -0
- package/dist/credentials.d.ts +9 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +79 -0
- package/dist/credentials.js.map +1 -0
- package/dist/keychain.d.ts +9 -0
- package/dist/keychain.d.ts.map +1 -0
- package/dist/keychain.js +51 -0
- package/dist/keychain.js.map +1 -0
- package/dist/output/csv.d.ts +5 -0
- package/dist/output/csv.d.ts.map +1 -0
- package/dist/output/csv.js +22 -0
- package/dist/output/csv.js.map +1 -0
- package/dist/output/envelope.schema.d.ts +1053 -0
- package/dist/output/envelope.schema.d.ts.map +1 -0
- package/dist/output/envelope.schema.js +256 -0
- package/dist/output/envelope.schema.js.map +1 -0
- package/dist/output/errors.d.ts +58 -0
- package/dist/output/errors.d.ts.map +1 -0
- package/dist/output/errors.js +339 -0
- package/dist/output/errors.js.map +1 -0
- package/dist/output/formatter.d.ts +27 -0
- package/dist/output/formatter.d.ts.map +1 -0
- package/dist/output/formatter.js +80 -0
- package/dist/output/formatter.js.map +1 -0
- package/dist/output/json.d.ts +41 -0
- package/dist/output/json.d.ts.map +1 -0
- package/dist/output/json.js +215 -0
- package/dist/output/json.js.map +1 -0
- package/dist/output/markdown.d.ts +6 -0
- package/dist/output/markdown.d.ts.map +1 -0
- package/dist/output/markdown.js +51 -0
- package/dist/output/markdown.js.map +1 -0
- package/dist/output/meta.d.ts +49 -0
- package/dist/output/meta.d.ts.map +1 -0
- package/dist/output/meta.js +96 -0
- package/dist/output/meta.js.map +1 -0
- package/dist/output/plain.d.ts +6 -0
- package/dist/output/plain.d.ts.map +1 -0
- package/dist/output/plain.js +51 -0
- package/dist/output/plain.js.map +1 -0
- package/dist/output/table.d.ts +5 -0
- package/dist/output/table.d.ts.map +1 -0
- package/dist/output/table.js +54 -0
- package/dist/output/table.js.map +1 -0
- package/dist/output/types.d.ts +54 -0
- package/dist/output/types.d.ts.map +1 -0
- package/dist/output/types.js +80 -0
- package/dist/output/types.js.map +1 -0
- package/dist/output/warnings.d.ts +15 -0
- package/dist/output/warnings.d.ts.map +1 -0
- package/dist/output/warnings.js +46 -0
- package/dist/output/warnings.js.map +1 -0
- package/dist/output/yaml.d.ts +6 -0
- package/dist/output/yaml.d.ts.map +1 -0
- package/dist/output/yaml.js +9 -0
- package/dist/output/yaml.js.map +1 -0
- package/dist/schema/breaking-changes.d.ts +17 -0
- package/dist/schema/breaking-changes.d.ts.map +1 -0
- package/dist/schema/breaking-changes.js +108 -0
- package/dist/schema/breaking-changes.js.map +1 -0
- package/dist/schema/helpers.d.ts +18 -0
- package/dist/schema/helpers.d.ts.map +1 -0
- package/dist/schema/helpers.js +48 -0
- package/dist/schema/helpers.js.map +1 -0
- package/dist/schema/load-schema-file.d.ts +13 -0
- package/dist/schema/load-schema-file.d.ts.map +1 -0
- package/dist/schema/load-schema-file.js +88 -0
- package/dist/schema/load-schema-file.js.map +1 -0
- package/dist/schema/lockfile.d.ts +6 -0
- package/dist/schema/lockfile.d.ts.map +1 -0
- package/dist/schema/lockfile.js +34 -0
- package/dist/schema/lockfile.js.map +1 -0
- package/dist/schema/manifest-client.d.ts +31 -0
- package/dist/schema/manifest-client.d.ts.map +1 -0
- package/dist/schema/manifest-client.js +282 -0
- package/dist/schema/manifest-client.js.map +1 -0
- package/dist/schema/output.d.ts +38 -0
- package/dist/schema/output.d.ts.map +1 -0
- package/dist/schema/output.js +95 -0
- package/dist/schema/output.js.map +1 -0
- package/dist/stdin.d.ts +8 -0
- package/dist/stdin.d.ts.map +1 -0
- package/dist/stdin.js +21 -0
- package/dist/stdin.js.map +1 -0
- package/dist/templates/basic.d.ts +6 -0
- package/dist/templates/basic.d.ts.map +1 -0
- package/dist/templates/basic.js +90 -0
- package/dist/templates/basic.js.map +1 -0
- package/dist/templates/contract-review.d.ts +9 -0
- package/dist/templates/contract-review.d.ts.map +1 -0
- package/dist/templates/contract-review.js +172 -0
- package/dist/templates/contract-review.js.map +1 -0
- package/dist/templates/customer-onboarding.d.ts +9 -0
- package/dist/templates/customer-onboarding.d.ts.map +1 -0
- package/dist/templates/customer-onboarding.js +176 -0
- package/dist/templates/customer-onboarding.js.map +1 -0
- package/dist/templates/index.d.ts +11 -0
- package/dist/templates/index.d.ts.map +1 -0
- package/dist/templates/index.js +16 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/react-dashboard.d.ts +6 -0
- package/dist/templates/react-dashboard.d.ts.map +1 -0
- package/dist/templates/react-dashboard.js +146 -0
- package/dist/templates/react-dashboard.js.map +1 -0
- package/dist/templates/vendor-risk.d.ts +9 -0
- package/dist/templates/vendor-risk.d.ts.map +1 -0
- package/dist/templates/vendor-risk.js +186 -0
- package/dist/templates/vendor-risk.js.map +1 -0
- package/package.json +47 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.schema.d.ts","sourceRoot":"","sources":["../../src/output/envelope.schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,EAAG,kBAA2B,CAAC;AACnE,MAAM,MAAM,oBAAoB,GAAG,OAAO,uBAAuB,CAAC;AAoBlE,QAAA,MAAM,qBAAqB,gDAA6B,CAAC;AAEzD,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAA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,QAAQ,EAAE,CAAC;gBAElB,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;CAQjC;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,CAM1E;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,GAAG,OAAO,EAC3C,KAAK,EAAE,OAAO,GAEZ;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,CAAA;CAAE,GACnC;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAA;CAAE,CAItC"}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod runtime lock for CLI JSON Contract — `dataforge.cli.v1`.
|
|
3
|
+
*
|
|
4
|
+
* Canonical contract: `sdk/docs/cli-contract.md`
|
|
5
|
+
* Type definitions: `./types.ts`
|
|
6
|
+
*
|
|
7
|
+
* This module provides runtime validation so the contract cannot drift silently
|
|
8
|
+
* as commands evolve. Validation is invoked from `output/json.ts` before any
|
|
9
|
+
* envelope is written to stdout.
|
|
10
|
+
*
|
|
11
|
+
* Design:
|
|
12
|
+
* - Every shape declared in `types.ts` has a matching Zod schema here.
|
|
13
|
+
* - The schemas use `z.object(...).strict()` to reject unknown keys (avoids
|
|
14
|
+
* silent contract drift via passthrough fields).
|
|
15
|
+
* - `EnvelopeSchema` is the single entry point used by `validateEnvelope()`.
|
|
16
|
+
* - On mismatch we throw `EnvelopeViolationError` rather than emitting a
|
|
17
|
+
* malformed envelope (loud errors > silent fallbacks).
|
|
18
|
+
*/
|
|
19
|
+
import { z } from 'zod';
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// SOT primitives — owned by this file (Zod is the source of truth, TS derives)
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
/**
|
|
24
|
+
* Schema version literal — bumped on a breaking contract change.
|
|
25
|
+
* Owned here because `CliMetaSchema` consumes it at module-init via `z.literal`.
|
|
26
|
+
* Re-exported from `./types.ts` for external consumers.
|
|
27
|
+
*/
|
|
28
|
+
export const CLI_META_SCHEMA_VERSION = 'dataforge.cli.v1';
|
|
29
|
+
/** `req_*`, `local_req_*`, `mock_req_*` — see cli-contract.md §3.1 */
|
|
30
|
+
const RequestIdSchema = z
|
|
31
|
+
.string()
|
|
32
|
+
.regex(/^(req|local_req|mock_req)_[a-zA-Z0-9]+$/, {
|
|
33
|
+
message: 'requestId must match /^(req|local_req|mock_req)_[a-zA-Z0-9]+$/',
|
|
34
|
+
});
|
|
35
|
+
/** Workspace identifier string or null for auth-free commands. */
|
|
36
|
+
const WorkspaceIdSchema = z
|
|
37
|
+
.string()
|
|
38
|
+
.min(1)
|
|
39
|
+
.nullable();
|
|
40
|
+
/**
|
|
41
|
+
* Canonical environment classifier — see cli-contract.md §3.2.
|
|
42
|
+
* `CliEnvironment` (TS) is derived from this Zod enum (no manual mirror).
|
|
43
|
+
*/
|
|
44
|
+
const ENVIRONMENT_VALUES = ['local', 'dev', 'staging', 'prod'];
|
|
45
|
+
const EnvironmentBaseSchema = z.enum(ENVIRONMENT_VALUES);
|
|
46
|
+
const EnvironmentSchema = EnvironmentBaseSchema.nullable();
|
|
47
|
+
/**
|
|
48
|
+
* Like z.unknown() but rejects undefined — ensures the value is
|
|
49
|
+
* JSON-serializable (null is allowed, undefined is not).
|
|
50
|
+
*/
|
|
51
|
+
const DefinedUnknownSchema = z
|
|
52
|
+
.unknown()
|
|
53
|
+
.refine((value) => value !== undefined, {
|
|
54
|
+
message: 'value must not be undefined (use null for absent values)',
|
|
55
|
+
});
|
|
56
|
+
/** Stable error code enum — see cli-contract-v1.md §4 */
|
|
57
|
+
export const CliErrorCodeSchema = z.enum([
|
|
58
|
+
'INVALID_USAGE',
|
|
59
|
+
'AUTHENTICATION_ERROR',
|
|
60
|
+
'AUTHORIZATION_ERROR',
|
|
61
|
+
'POLICY_VIOLATION',
|
|
62
|
+
'WRITE_POLICY_VIOLATION',
|
|
63
|
+
'VALIDATION_ERROR',
|
|
64
|
+
'CAPABILITY_DRIFT_ERROR',
|
|
65
|
+
'SCHEMA_DRIFT_ERROR',
|
|
66
|
+
'QUOTA_EXCEEDED',
|
|
67
|
+
'BUDGET_EXCEEDED',
|
|
68
|
+
'RATE_LIMITED',
|
|
69
|
+
'CONFLICT_ERROR',
|
|
70
|
+
'PLAN_POLICY_MISMATCH',
|
|
71
|
+
'SOURCE_OF_TRUTH_CONFLICT',
|
|
72
|
+
'PLAN_CONTEXT_MISMATCH',
|
|
73
|
+
'PRECONDITION_FAILED',
|
|
74
|
+
'NETWORK_ERROR',
|
|
75
|
+
'TIMEOUT_ERROR',
|
|
76
|
+
'RUNTIME_UNAVAILABLE',
|
|
77
|
+
'NOT_FOUND',
|
|
78
|
+
'UNAVAILABLE',
|
|
79
|
+
'INTERNAL_ERROR',
|
|
80
|
+
'CONFIRMATION_REQUIRED',
|
|
81
|
+
'CONFIGURATION_ERROR',
|
|
82
|
+
]);
|
|
83
|
+
// ---------------------------------------------------------------------------
|
|
84
|
+
// Composed schemas
|
|
85
|
+
// ---------------------------------------------------------------------------
|
|
86
|
+
export const CliWarningSchema = z
|
|
87
|
+
.object({
|
|
88
|
+
code: z.string().min(1),
|
|
89
|
+
message: z.string().min(1),
|
|
90
|
+
severity: z.enum(['info', 'warning', 'deprecated', 'danger']),
|
|
91
|
+
// Non-empty string. Either an absolute URL (`https://docs.dataforge.dev/...`)
|
|
92
|
+
// or a relative one (`/docs/migration`) — the contract in `cli-contract.md`
|
|
93
|
+
// does not require absolute URLs, so we keep this matching the TypeScript
|
|
94
|
+
// interface (`docsUrl?: string`) and avoid runtime rejection of valid
|
|
95
|
+
// relative paths.
|
|
96
|
+
docsUrl: z.string().min(1).optional(),
|
|
97
|
+
})
|
|
98
|
+
.strict();
|
|
99
|
+
export const CliMetaSchema = z
|
|
100
|
+
.object({
|
|
101
|
+
schemaVersion: z.literal(CLI_META_SCHEMA_VERSION),
|
|
102
|
+
command: z.string().min(1),
|
|
103
|
+
requestId: RequestIdSchema,
|
|
104
|
+
workspaceId: WorkspaceIdSchema,
|
|
105
|
+
environment: EnvironmentSchema,
|
|
106
|
+
manifestVersion: z.string().nullable(),
|
|
107
|
+
costUnits: z.number().int().min(0),
|
|
108
|
+
estimatedCostUnits: z.number().int().min(0).nullable(),
|
|
109
|
+
quotaRemaining: z.number().int().min(0).nullable(),
|
|
110
|
+
rateLimitRemaining: z.number().int().min(0).nullable(),
|
|
111
|
+
warnings: z.array(CliWarningSchema),
|
|
112
|
+
})
|
|
113
|
+
.strict();
|
|
114
|
+
export const CliErrorSchema = z
|
|
115
|
+
.object({
|
|
116
|
+
code: CliErrorCodeSchema,
|
|
117
|
+
message: z.string().min(1),
|
|
118
|
+
details: DefinedUnknownSchema,
|
|
119
|
+
retryable: z.boolean(),
|
|
120
|
+
correlationId: z.string().min(1),
|
|
121
|
+
})
|
|
122
|
+
.strict();
|
|
123
|
+
export const CliPageSchema = z
|
|
124
|
+
.object({
|
|
125
|
+
limit: z.number().int().min(0),
|
|
126
|
+
nextCursor: z.string().nullable(),
|
|
127
|
+
hasMore: z.boolean(),
|
|
128
|
+
})
|
|
129
|
+
.strict();
|
|
130
|
+
/**
|
|
131
|
+
* Top-level envelope schema. Enforces the cli-contract.md §2 invariants:
|
|
132
|
+
* - `ok === true` → `data !== null`, `error === null`
|
|
133
|
+
* - `ok === false` → `data === null`, `error !== null`
|
|
134
|
+
*/
|
|
135
|
+
export const EnvelopeSchema = z
|
|
136
|
+
.object({
|
|
137
|
+
ok: z.boolean(),
|
|
138
|
+
data: DefinedUnknownSchema.nullable(),
|
|
139
|
+
error: CliErrorSchema.nullable(),
|
|
140
|
+
page: CliPageSchema.nullable(),
|
|
141
|
+
meta: CliMetaSchema,
|
|
142
|
+
})
|
|
143
|
+
.strict()
|
|
144
|
+
.superRefine((env, ctx) => {
|
|
145
|
+
if (env.ok === true) {
|
|
146
|
+
if (env.data === null) {
|
|
147
|
+
ctx.addIssue({
|
|
148
|
+
code: z.ZodIssueCode.custom,
|
|
149
|
+
path: ['data'],
|
|
150
|
+
message: 'envelope.ok=true requires data !== null',
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
if (env.error !== null) {
|
|
154
|
+
ctx.addIssue({
|
|
155
|
+
code: z.ZodIssueCode.custom,
|
|
156
|
+
path: ['error'],
|
|
157
|
+
message: 'envelope.ok=true requires error === null',
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
if (env.data !== null) {
|
|
163
|
+
ctx.addIssue({
|
|
164
|
+
code: z.ZodIssueCode.custom,
|
|
165
|
+
path: ['data'],
|
|
166
|
+
message: 'envelope.ok=false requires data === null',
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
if (env.error === null) {
|
|
170
|
+
ctx.addIssue({
|
|
171
|
+
code: z.ZodIssueCode.custom,
|
|
172
|
+
path: ['error'],
|
|
173
|
+
message: 'envelope.ok=false requires error !== null',
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
// ---------------------------------------------------------------------------
|
|
179
|
+
// JSONL event schemas (J1 — dev-mode validation for JSONL output)
|
|
180
|
+
// ---------------------------------------------------------------------------
|
|
181
|
+
export const JsonlStartedEventSchema = z.object({
|
|
182
|
+
type: z.literal('started'), meta: CliMetaSchema, total: z.number().nullable()
|
|
183
|
+
}).strict();
|
|
184
|
+
export const JsonlItemEventSchema = z.object({
|
|
185
|
+
type: z.literal('item'), data: DefinedUnknownSchema
|
|
186
|
+
}).strict();
|
|
187
|
+
export const JsonlCompletedEventSchema = z.object({
|
|
188
|
+
type: z.literal('completed'), meta: CliMetaSchema, summary: z.record(z.string(), z.unknown())
|
|
189
|
+
}).strict();
|
|
190
|
+
export const JsonlErrorEventSchema = z.object({
|
|
191
|
+
type: z.literal('error'), error: CliErrorSchema
|
|
192
|
+
}).strict();
|
|
193
|
+
export const JsonlProgressEventSchema = z.object({
|
|
194
|
+
type: z.literal('progress'),
|
|
195
|
+
current: z.number().int().min(0),
|
|
196
|
+
total: z.number().int().min(0).nullable(),
|
|
197
|
+
message: z.string(),
|
|
198
|
+
}).strict();
|
|
199
|
+
export const JsonlWarningEventSchema = z.object({
|
|
200
|
+
type: z.literal('warning'),
|
|
201
|
+
warning: CliWarningSchema,
|
|
202
|
+
}).strict();
|
|
203
|
+
export const JsonlEventSchema = z.discriminatedUnion('type', [
|
|
204
|
+
JsonlStartedEventSchema,
|
|
205
|
+
JsonlItemEventSchema,
|
|
206
|
+
JsonlCompletedEventSchema,
|
|
207
|
+
JsonlErrorEventSchema,
|
|
208
|
+
JsonlProgressEventSchema,
|
|
209
|
+
JsonlWarningEventSchema,
|
|
210
|
+
]);
|
|
211
|
+
// ---------------------------------------------------------------------------
|
|
212
|
+
// Public API
|
|
213
|
+
// ---------------------------------------------------------------------------
|
|
214
|
+
/**
|
|
215
|
+
* Thrown when an envelope does not conform to `dataforge.cli.v1`. Surfaces
|
|
216
|
+
* the Zod issue list so the offending field/value is visible.
|
|
217
|
+
*
|
|
218
|
+
* Design choice (loud errors, no silent fallback):
|
|
219
|
+
* - In `NODE_ENV !== 'production'` we throw immediately.
|
|
220
|
+
* - In production we log to stderr and emit a synthesized error envelope
|
|
221
|
+
* (handled by the caller in `output/json.ts`).
|
|
222
|
+
*/
|
|
223
|
+
export class EnvelopeViolationError extends Error {
|
|
224
|
+
issues;
|
|
225
|
+
constructor(issues) {
|
|
226
|
+
const summary = issues
|
|
227
|
+
.map((iss) => `${iss.path.join('.') || '<root>'}: ${iss.message}`)
|
|
228
|
+
.join('; ');
|
|
229
|
+
super(`CLI envelope violates dataforge.cli.v1 contract: ${summary}`);
|
|
230
|
+
this.name = 'EnvelopeViolationError';
|
|
231
|
+
this.issues = issues;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Parse + assert. Returns the envelope unchanged on success. Throws
|
|
236
|
+
* `EnvelopeViolationError` on contract violation.
|
|
237
|
+
*/
|
|
238
|
+
export function assertEnvelope(value) {
|
|
239
|
+
const parsed = EnvelopeSchema.safeParse(value);
|
|
240
|
+
if (!parsed.success) {
|
|
241
|
+
throw new EnvelopeViolationError(parsed.error.issues);
|
|
242
|
+
}
|
|
243
|
+
return parsed.data;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Non-throwing variant. Returns `{ ok: true, value }` or `{ ok: false, issues }`.
|
|
247
|
+
* Use in production paths where we prefer to log + emit a synthesized error
|
|
248
|
+
* envelope rather than crash the CLI.
|
|
249
|
+
*/
|
|
250
|
+
export function tryAssertEnvelope(value) {
|
|
251
|
+
const parsed = EnvelopeSchema.safeParse(value);
|
|
252
|
+
if (!parsed.success)
|
|
253
|
+
return { ok: false, issues: parsed.error.issues };
|
|
254
|
+
return { ok: true, value: parsed.data };
|
|
255
|
+
}
|
|
256
|
+
//# sourceMappingURL=envelope.schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.schema.js","sourceRoot":"","sources":["../../src/output/envelope.schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,8EAA8E;AAC9E,+EAA+E;AAC/E,8EAA8E;AAE9E;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,kBAA2B,CAAC;AAGnE,sEAAsE;AACtE,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,EAAE;KACR,KAAK,CAAC,yCAAyC,EAAE;IAChD,OAAO,EAAE,gEAAgE;CAC1E,CAAC,CAAC;AAEL,kEAAkE;AAClE,MAAM,iBAAiB,GAAG,CAAC;KACxB,MAAM,EAAE;KACR,GAAG,CAAC,CAAC,CAAC;KACN,QAA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EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,QAAQ,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC;aACjE,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,KAAK,CAAC,oDAAoD,OAAO,EAAE,CAAC,CAAC;QACrE,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAc,KAAc;IACxD,MAAM,MAAM,GAAG,cAAc,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC/C,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,IAAI,sBAAsB,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACxD,CAAC;IACD,OAAO,MAAM,CAAC,IAAsB,CAAC;AACvC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAAc;IAId,MAAM,MAAM,GAAG,cAAc,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC/C,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;IACvE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,IAAsB,EAAE,CAAC;AAC5D,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI error classification, structured output, and exit code resolution.
|
|
3
|
+
*
|
|
4
|
+
* Canonical reference: sdk/docs/cli-contract.md (Section 7)
|
|
5
|
+
*/
|
|
6
|
+
import type { CliError, CliErrorCode, CliMeta, CliEnvelope } from './types.js';
|
|
7
|
+
interface ClassifiedError {
|
|
8
|
+
code: CliErrorCode;
|
|
9
|
+
message: string;
|
|
10
|
+
details: unknown;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Classify a caught error into a structured CliErrorCode.
|
|
14
|
+
* Replaces the string-matching in shared.ts and cli.ts.
|
|
15
|
+
*/
|
|
16
|
+
declare function redactSecrets(msg: string): string;
|
|
17
|
+
export { redactSecrets };
|
|
18
|
+
/**
|
|
19
|
+
* Thrown for user-caused errors (bad arguments, invalid input values).
|
|
20
|
+
* classifyError maps these to INVALID_USAGE.
|
|
21
|
+
*/
|
|
22
|
+
export declare class CliUsageError extends Error {
|
|
23
|
+
readonly cliCode: "INVALID_USAGE";
|
|
24
|
+
readonly details: unknown;
|
|
25
|
+
constructor(message: string, details?: unknown);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Thrown when a precondition is not met (file exists, breaking changes, etc).
|
|
29
|
+
* classifyError maps these to PRECONDITION_FAILED.
|
|
30
|
+
*/
|
|
31
|
+
export declare class CliPreconditionError extends Error {
|
|
32
|
+
readonly cliCode: CliErrorCode;
|
|
33
|
+
readonly details: unknown;
|
|
34
|
+
constructor(message: string, details?: unknown, code?: CliErrorCode);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Recursively redact secrets from any value tree.
|
|
38
|
+
* Handles strings, arrays, and plain objects. Detects circular references.
|
|
39
|
+
*/
|
|
40
|
+
export declare function redactSecretsDeep(value: unknown, seen?: WeakSet<object>): unknown;
|
|
41
|
+
export declare function classifyError(err: unknown): ClassifiedError;
|
|
42
|
+
/**
|
|
43
|
+
* Build a CliError from a classified error and optional request context.
|
|
44
|
+
*/
|
|
45
|
+
export declare function buildCliError(classified: ClassifiedError, correlationId?: string): CliError;
|
|
46
|
+
/**
|
|
47
|
+
* Build a complete error envelope.
|
|
48
|
+
*/
|
|
49
|
+
export declare function buildErrorEnvelope(error: CliError, meta: CliMeta): CliEnvelope<never>;
|
|
50
|
+
/**
|
|
51
|
+
* Get the process exit code for an error code.
|
|
52
|
+
*/
|
|
53
|
+
export declare function getExitCode(code: CliErrorCode): number;
|
|
54
|
+
/**
|
|
55
|
+
* Handle a CLI error: classify, format as JSON or stderr text, and exit.
|
|
56
|
+
*/
|
|
57
|
+
export declare function handleCliError(err: unknown, meta: CliMeta | null, format: 'json' | 'jsonl' | 'text'): never;
|
|
58
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/output/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAqB,MAAM,YAAY,CAAC;AASlG,UAAU,eAAe;IACvB,IAAI,EAAE,YAAY,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CAClB;AAqED;;;GAGG;AAEH,iBAAS,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAK1C;AAED,OAAO,EAAE,aAAa,EAAE,CAAC;AAMzB;;;GAGG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,OAAO,EAAG,eAAe,CAAU;IAC5C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;gBAEd,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;CAK/C;AAED;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;gBAEd,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,GAAE,YAAoC;CAM3F;AAMD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,kBAAwB,GAAG,OAAO,CAsBvF;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,eAAe,CAmG3D;AAMD;;GAEG;AACH,wBAAgB,aAAa,CAC3B,UAAU,EAAE,eAAe,EAC3B,aAAa,CAAC,EAAE,MAAM,GACrB,QAAQ,CAQV;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,CAQrF;AAMD;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAEtD;AAMD;;GAEG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,OAAO,GAAG,IAAI,EACpB,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,GAChC,KAAK,CAiCP"}
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI error classification, structured output, and exit code resolution.
|
|
3
|
+
*
|
|
4
|
+
* Canonical reference: sdk/docs/cli-contract.md (Section 7)
|
|
5
|
+
*/
|
|
6
|
+
import { ERROR_EXIT_MAP, isRetryable, generateRequestId } from './types.js';
|
|
7
|
+
import { outputJsonlError } from './json.js';
|
|
8
|
+
import { extractFsCode } from '../schema/helpers.js';
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
// Plan error code → CLI error code mapping
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
const PLAN_ERROR_TO_CLI = {
|
|
13
|
+
PLAN_NOT_FOUND: 'NOT_FOUND',
|
|
14
|
+
PLAN_EXPIRED: 'CONFLICT_ERROR',
|
|
15
|
+
PLAN_ALREADY_APPLIED: 'CONFLICT_ERROR',
|
|
16
|
+
PLAN_REVOKED: 'CONFLICT_ERROR',
|
|
17
|
+
PLAN_HASH_MISMATCH: 'VALIDATION_ERROR',
|
|
18
|
+
PLAN_SIGNATURE_INVALID: 'VALIDATION_ERROR',
|
|
19
|
+
PLAN_BODY_HASH_MISMATCH: 'VALIDATION_ERROR',
|
|
20
|
+
PLAN_WORKSPACE_MISMATCH: 'AUTHORIZATION_ERROR',
|
|
21
|
+
PLAN_ACTOR_MISMATCH: 'AUTHORIZATION_ERROR',
|
|
22
|
+
PLAN_POLICY_BLOCKED: 'POLICY_VIOLATION',
|
|
23
|
+
PLAN_WRITE_POLICY_VIOLATION: 'WRITE_POLICY_VIOLATION',
|
|
24
|
+
SOURCE_OF_TRUTH_CONFLICT: 'SOURCE_OF_TRUTH_CONFLICT',
|
|
25
|
+
PLAN_RISK_NOT_ACKNOWLEDGED: 'CONFIRMATION_REQUIRED',
|
|
26
|
+
PLAN_CONFIRMATION_REQUIRED: 'CONFIRMATION_REQUIRED',
|
|
27
|
+
PLAN_SCHEMA_VERSION_MISMATCH: 'PLAN_CONTEXT_MISMATCH',
|
|
28
|
+
PLAN_ACTION_VERSION_MISMATCH: 'PLAN_CONTEXT_MISMATCH',
|
|
29
|
+
PLAN_POLICY_MISMATCH: 'PLAN_POLICY_MISMATCH',
|
|
30
|
+
PLAN_DEPENDENCY_VERSION_MISMATCH: 'CONFLICT_ERROR',
|
|
31
|
+
PLAN_TARGET_VERSION_CONFLICT: 'CONFLICT_ERROR',
|
|
32
|
+
PLAN_EXPECTED_ABSENT_CONFLICT: 'CONFLICT_ERROR',
|
|
33
|
+
PLAN_IDEMPOTENCY_CONFLICT: 'CONFLICT_ERROR',
|
|
34
|
+
PLAN_QUOTA_EXCEEDED: 'QUOTA_EXCEEDED',
|
|
35
|
+
PLAN_APPLY_FAILED: 'INTERNAL_ERROR',
|
|
36
|
+
PLAN_OPERATION_MISMATCH: 'INVALID_USAGE',
|
|
37
|
+
APPLY_PLAN_INPUT_NOT_ALLOWED: 'INVALID_USAGE',
|
|
38
|
+
PLAN_TARGET_NOT_FOUND: 'NOT_FOUND',
|
|
39
|
+
PLAN_AUTHORIZATION_CHANGED: 'AUTHORIZATION_ERROR',
|
|
40
|
+
PLAN_INPUT_ARTIFACT_MISMATCH: 'VALIDATION_ERROR',
|
|
41
|
+
PLAN_LOCAL_SCHEMA_MISMATCH: 'PLAN_CONTEXT_MISMATCH',
|
|
42
|
+
PLAN_INTERNAL_ERROR: 'INTERNAL_ERROR',
|
|
43
|
+
PLAN_EXECUTION_MODE_MISSING: 'VALIDATION_ERROR',
|
|
44
|
+
PLAN_EXECUTION_MODE_INVALID: 'VALIDATION_ERROR',
|
|
45
|
+
PLAN_EXECUTION_MODE_MISMATCH: 'CONFLICT_ERROR',
|
|
46
|
+
PLAN_EXECUTION_MODE_NOT_SUPPORTED: 'VALIDATION_ERROR',
|
|
47
|
+
};
|
|
48
|
+
function extractPlanErrorCode(err) {
|
|
49
|
+
if (!err || typeof err !== 'object')
|
|
50
|
+
return null;
|
|
51
|
+
// Check err.body.code or err.data.code (API response patterns)
|
|
52
|
+
for (const prop of ['body', 'data', 'response']) {
|
|
53
|
+
const container = err[prop];
|
|
54
|
+
if (container && typeof container === 'object') {
|
|
55
|
+
const code = container.code;
|
|
56
|
+
if (typeof code === 'string' && code in PLAN_ERROR_TO_CLI)
|
|
57
|
+
return code;
|
|
58
|
+
// Nested: err.response.data.code
|
|
59
|
+
const innerData = container.data;
|
|
60
|
+
if (innerData && typeof innerData === 'object') {
|
|
61
|
+
const innerCode = innerData.code;
|
|
62
|
+
if (typeof innerCode === 'string' && innerCode in PLAN_ERROR_TO_CLI)
|
|
63
|
+
return innerCode;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// Direct code property
|
|
68
|
+
const directCode = err.code;
|
|
69
|
+
if (typeof directCode === 'string' && directCode in PLAN_ERROR_TO_CLI)
|
|
70
|
+
return directCode;
|
|
71
|
+
// Check error message for PLAN_* codes
|
|
72
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
73
|
+
const match = message.match(/\b(PLAN_[A-Z_]+|APPLY_PLAN_[A-Z_]+)\b/);
|
|
74
|
+
if (match && match[1] in PLAN_ERROR_TO_CLI)
|
|
75
|
+
return match[1];
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Classify a caught error into a structured CliErrorCode.
|
|
80
|
+
* Replaces the string-matching in shared.ts and cli.ts.
|
|
81
|
+
*/
|
|
82
|
+
// E2: Redact secrets from error messages to prevent API key / token leakage
|
|
83
|
+
function redactSecrets(msg) {
|
|
84
|
+
return msg
|
|
85
|
+
.replace(/\b(df_[a-zA-Z0-9]{6,})\b/g, '[REDACTED:api_key]')
|
|
86
|
+
.replace(/Bearer\s+[a-zA-Z0-9._-]+/gi, 'Bearer [REDACTED]')
|
|
87
|
+
.replace(/([a-zA-Z0-9_-]*(?:key|token|secret|password)[a-zA-Z0-9_-]*)\s*[=:]\s*\S+/gi, '$1=[REDACTED]');
|
|
88
|
+
}
|
|
89
|
+
export { redactSecrets };
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
// Typed CLI error classes (thrown by commands, caught by classifyError)
|
|
92
|
+
// ---------------------------------------------------------------------------
|
|
93
|
+
/**
|
|
94
|
+
* Thrown for user-caused errors (bad arguments, invalid input values).
|
|
95
|
+
* classifyError maps these to INVALID_USAGE.
|
|
96
|
+
*/
|
|
97
|
+
export class CliUsageError extends Error {
|
|
98
|
+
cliCode = 'INVALID_USAGE';
|
|
99
|
+
details;
|
|
100
|
+
constructor(message, details) {
|
|
101
|
+
super(message);
|
|
102
|
+
this.name = 'CliUsageError';
|
|
103
|
+
this.details = details ?? null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Thrown when a precondition is not met (file exists, breaking changes, etc).
|
|
108
|
+
* classifyError maps these to PRECONDITION_FAILED.
|
|
109
|
+
*/
|
|
110
|
+
export class CliPreconditionError extends Error {
|
|
111
|
+
cliCode;
|
|
112
|
+
details;
|
|
113
|
+
constructor(message, details, code = 'PRECONDITION_FAILED') {
|
|
114
|
+
super(message);
|
|
115
|
+
this.name = 'CliPreconditionError';
|
|
116
|
+
this.cliCode = code;
|
|
117
|
+
this.details = details ?? null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// ---------------------------------------------------------------------------
|
|
121
|
+
// Deep secret redaction (recursive)
|
|
122
|
+
// ---------------------------------------------------------------------------
|
|
123
|
+
/**
|
|
124
|
+
* Recursively redact secrets from any value tree.
|
|
125
|
+
* Handles strings, arrays, and plain objects. Detects circular references.
|
|
126
|
+
*/
|
|
127
|
+
export function redactSecretsDeep(value, seen = new WeakSet()) {
|
|
128
|
+
if (typeof value === 'string')
|
|
129
|
+
return redactSecrets(value);
|
|
130
|
+
if (value === null || value === undefined || typeof value !== 'object')
|
|
131
|
+
return value;
|
|
132
|
+
if (seen.has(value))
|
|
133
|
+
return '[Circular]';
|
|
134
|
+
seen.add(value);
|
|
135
|
+
if (Array.isArray(value)) {
|
|
136
|
+
return value.map((item) => redactSecretsDeep(item, seen));
|
|
137
|
+
}
|
|
138
|
+
const out = {};
|
|
139
|
+
for (const [key, child] of Object.entries(value)) {
|
|
140
|
+
if (/key|token|secret|password|authorization/i.test(key)) {
|
|
141
|
+
out[key] = '[REDACTED]';
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
out[key] = redactSecretsDeep(child, seen);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return out;
|
|
148
|
+
}
|
|
149
|
+
export function classifyError(err) {
|
|
150
|
+
const message = redactSecrets(err instanceof Error ? err.message : String(err));
|
|
151
|
+
// Plan-specific error codes (highest priority — preserves PLAN_* detail)
|
|
152
|
+
const planCode = extractPlanErrorCode(err);
|
|
153
|
+
if (planCode) {
|
|
154
|
+
return { code: PLAN_ERROR_TO_CLI[planCode], message: `[${planCode}] ${message}`, details: { planErrorCode: planCode } };
|
|
155
|
+
}
|
|
156
|
+
// Typed CLI error classes (CliUsageError, CliPreconditionError)
|
|
157
|
+
if (err &&
|
|
158
|
+
typeof err === 'object' &&
|
|
159
|
+
'cliCode' in err &&
|
|
160
|
+
typeof err.cliCode === 'string') {
|
|
161
|
+
const code = err.cliCode;
|
|
162
|
+
const details = 'details' in err ? err.details : null;
|
|
163
|
+
return { code, message, details };
|
|
164
|
+
}
|
|
165
|
+
const statusCode = extractStatusCode(err);
|
|
166
|
+
// Status-code based classification (most reliable)
|
|
167
|
+
if (statusCode !== null) {
|
|
168
|
+
switch (statusCode) {
|
|
169
|
+
case 400: return { code: 'VALIDATION_ERROR', message, details: null };
|
|
170
|
+
case 401: return { code: 'AUTHENTICATION_ERROR', message, details: null };
|
|
171
|
+
case 403: return { code: 'AUTHORIZATION_ERROR', message, details: null };
|
|
172
|
+
case 404: return { code: 'NOT_FOUND', message, details: null };
|
|
173
|
+
case 409: return { code: 'CONFLICT_ERROR', message, details: null };
|
|
174
|
+
case 412: return { code: 'PRECONDITION_FAILED', message, details: null };
|
|
175
|
+
case 422: return { code: 'VALIDATION_ERROR', message, details: null };
|
|
176
|
+
case 429: return { code: 'RATE_LIMITED', message, details: null };
|
|
177
|
+
case 503: return { code: 'UNAVAILABLE', message, details: null };
|
|
178
|
+
}
|
|
179
|
+
if (statusCode >= 500)
|
|
180
|
+
return { code: 'INTERNAL_ERROR', message, details: null };
|
|
181
|
+
}
|
|
182
|
+
// String-based fallback classification
|
|
183
|
+
if (/\b(ECONNREFUSED|ECONNRESET|ENOTFOUND|EAI_AGAIN|fetch failed)\b/i.test(message)) {
|
|
184
|
+
return { code: 'NETWORK_ERROR', message, details: null };
|
|
185
|
+
}
|
|
186
|
+
if (/\b(ETIMEDOUT|timeout|timed?\s*out)\b/i.test(message)) {
|
|
187
|
+
return { code: 'TIMEOUT_ERROR', message, details: null };
|
|
188
|
+
}
|
|
189
|
+
if (/\b(401|Unauthorized|Authentication)\b/i.test(message)) {
|
|
190
|
+
return { code: 'AUTHENTICATION_ERROR', message, details: null };
|
|
191
|
+
}
|
|
192
|
+
if (/\b(403|Forbidden)\b/i.test(message)) {
|
|
193
|
+
return { code: 'AUTHORIZATION_ERROR', message, details: null };
|
|
194
|
+
}
|
|
195
|
+
if (/\b(404|Not Found)\b/i.test(message)) {
|
|
196
|
+
return { code: 'NOT_FOUND', message, details: null };
|
|
197
|
+
}
|
|
198
|
+
if (/\b(409|Conflict)\b/i.test(message)) {
|
|
199
|
+
return { code: 'CONFLICT_ERROR', message, details: null };
|
|
200
|
+
}
|
|
201
|
+
if (/\b(422|Validation)\b/i.test(message)) {
|
|
202
|
+
return { code: 'VALIDATION_ERROR', message, details: null };
|
|
203
|
+
}
|
|
204
|
+
if (/\b(429|Rate.?Limit|Too Many Requests)\b/i.test(message)) {
|
|
205
|
+
return { code: 'RATE_LIMITED', message, details: null };
|
|
206
|
+
}
|
|
207
|
+
if (/\b(quota|limit exceeded)\b/i.test(message)) {
|
|
208
|
+
return { code: 'QUOTA_EXCEEDED', message, details: null };
|
|
209
|
+
}
|
|
210
|
+
if (/\bschema.?drift\b/i.test(message)) {
|
|
211
|
+
return { code: 'SCHEMA_DRIFT_ERROR', message, details: null };
|
|
212
|
+
}
|
|
213
|
+
if (/\bwrite.?policy\b/i.test(message)) {
|
|
214
|
+
return { code: 'WRITE_POLICY_VIOLATION', message, details: null };
|
|
215
|
+
}
|
|
216
|
+
if (/\bpolicy.?violation\b/i.test(message)) {
|
|
217
|
+
return { code: 'POLICY_VIOLATION', message, details: null };
|
|
218
|
+
}
|
|
219
|
+
if (/\bbudget.?exceeded\b/i.test(message)) {
|
|
220
|
+
return { code: 'BUDGET_EXCEEDED', message, details: null };
|
|
221
|
+
}
|
|
222
|
+
if (/\bruntime.?unavailable\b/i.test(message)) {
|
|
223
|
+
return { code: 'RUNTIME_UNAVAILABLE', message, details: null };
|
|
224
|
+
}
|
|
225
|
+
// Filesystem errors
|
|
226
|
+
const fsCode = extractFsCode(err);
|
|
227
|
+
if (fsCode) {
|
|
228
|
+
switch (fsCode) {
|
|
229
|
+
case 'ENOENT':
|
|
230
|
+
return { code: 'NOT_FOUND', message, details: { fsCode } };
|
|
231
|
+
case 'EACCES':
|
|
232
|
+
case 'EPERM':
|
|
233
|
+
return { code: 'AUTHORIZATION_ERROR', message, details: { fsCode } };
|
|
234
|
+
case 'EISDIR':
|
|
235
|
+
case 'ENOTDIR':
|
|
236
|
+
return { code: 'INVALID_USAGE', message, details: { fsCode } };
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return { code: 'INTERNAL_ERROR', message, details: null };
|
|
240
|
+
}
|
|
241
|
+
// ---------------------------------------------------------------------------
|
|
242
|
+
// Error envelope builders
|
|
243
|
+
// ---------------------------------------------------------------------------
|
|
244
|
+
/**
|
|
245
|
+
* Build a CliError from a classified error and optional request context.
|
|
246
|
+
*/
|
|
247
|
+
export function buildCliError(classified, correlationId) {
|
|
248
|
+
return {
|
|
249
|
+
code: classified.code,
|
|
250
|
+
message: redactSecrets(classified.message),
|
|
251
|
+
details: redactSecretsDeep(classified.details),
|
|
252
|
+
retryable: isRetryable(classified.code),
|
|
253
|
+
correlationId: correlationId ?? generateRequestId(),
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Build a complete error envelope.
|
|
258
|
+
*/
|
|
259
|
+
export function buildErrorEnvelope(error, meta) {
|
|
260
|
+
return {
|
|
261
|
+
ok: false,
|
|
262
|
+
data: null,
|
|
263
|
+
error,
|
|
264
|
+
page: null,
|
|
265
|
+
meta,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
// ---------------------------------------------------------------------------
|
|
269
|
+
// Exit code resolution
|
|
270
|
+
// ---------------------------------------------------------------------------
|
|
271
|
+
/**
|
|
272
|
+
* Get the process exit code for an error code.
|
|
273
|
+
*/
|
|
274
|
+
export function getExitCode(code) {
|
|
275
|
+
return ERROR_EXIT_MAP[code];
|
|
276
|
+
}
|
|
277
|
+
// ---------------------------------------------------------------------------
|
|
278
|
+
// CLI error handler
|
|
279
|
+
// ---------------------------------------------------------------------------
|
|
280
|
+
/**
|
|
281
|
+
* Handle a CLI error: classify, format as JSON or stderr text, and exit.
|
|
282
|
+
*/
|
|
283
|
+
export function handleCliError(err, meta, format) {
|
|
284
|
+
const classified = classifyError(err);
|
|
285
|
+
const correlationId = meta?.requestId ?? generateRequestId();
|
|
286
|
+
const cliError = buildCliError(classified, correlationId);
|
|
287
|
+
const exitCode = getExitCode(classified.code);
|
|
288
|
+
// Build fallback meta when none is provided (e.g. error before API call)
|
|
289
|
+
const effectiveMeta = meta ?? {
|
|
290
|
+
schemaVersion: 'dataforge.cli.v1',
|
|
291
|
+
command: 'unknown',
|
|
292
|
+
requestId: correlationId,
|
|
293
|
+
workspaceId: null,
|
|
294
|
+
environment: null,
|
|
295
|
+
manifestVersion: null,
|
|
296
|
+
costUnits: 0,
|
|
297
|
+
estimatedCostUnits: null,
|
|
298
|
+
quotaRemaining: null,
|
|
299
|
+
rateLimitRemaining: null,
|
|
300
|
+
warnings: [],
|
|
301
|
+
};
|
|
302
|
+
if (format === 'json') {
|
|
303
|
+
const envelope = buildErrorEnvelope(cliError, effectiveMeta);
|
|
304
|
+
process.stdout.write(JSON.stringify(envelope, null, 2) + '\n');
|
|
305
|
+
}
|
|
306
|
+
else if (format === 'jsonl') {
|
|
307
|
+
const started = { type: 'started', meta: effectiveMeta, total: null };
|
|
308
|
+
process.stdout.write(JSON.stringify(started) + '\n');
|
|
309
|
+
outputJsonlError(cliError);
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
process.stderr.write(`Error [${classified.code}]: ${classified.message}\n`);
|
|
313
|
+
}
|
|
314
|
+
process.exit(exitCode);
|
|
315
|
+
}
|
|
316
|
+
// ---------------------------------------------------------------------------
|
|
317
|
+
// Helpers
|
|
318
|
+
// ---------------------------------------------------------------------------
|
|
319
|
+
function extractStatusCode(err) {
|
|
320
|
+
if (err && typeof err === 'object') {
|
|
321
|
+
// Axios-style: err.response.status
|
|
322
|
+
const response = err.response;
|
|
323
|
+
if (response && typeof response === 'object') {
|
|
324
|
+
const status = response.status;
|
|
325
|
+
if (typeof status === 'number')
|
|
326
|
+
return status;
|
|
327
|
+
}
|
|
328
|
+
// Direct status property
|
|
329
|
+
const status = err.status;
|
|
330
|
+
if (typeof status === 'number')
|
|
331
|
+
return status;
|
|
332
|
+
// statusCode property
|
|
333
|
+
const statusCode = err.statusCode;
|
|
334
|
+
if (typeof statusCode === 'number')
|
|
335
|
+
return statusCode;
|
|
336
|
+
}
|
|
337
|
+
return null;
|
|
338
|
+
}
|
|
339
|
+
//# sourceMappingURL=errors.js.map
|