@ogment-ai/cli 0.4.2 → 0.6.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.
Files changed (87) hide show
  1. package/README.md +0 -9
  2. package/dist/cli/commands.d.ts +37 -0
  3. package/dist/cli/commands.d.ts.map +1 -0
  4. package/dist/cli/commands.js +56 -0
  5. package/dist/cli/execute.d.ts +11 -0
  6. package/dist/cli/execute.d.ts.map +1 -0
  7. package/dist/cli/execute.js +468 -0
  8. package/dist/cli/invocations.d.ts +31 -0
  9. package/dist/cli/invocations.d.ts.map +1 -0
  10. package/dist/cli/invocations.js +1 -0
  11. package/dist/cli/parse-errors.d.ts +17 -0
  12. package/dist/cli/parse-errors.d.ts.map +1 -0
  13. package/dist/cli/parse-errors.js +184 -0
  14. package/dist/cli/program.d.ts +10 -0
  15. package/dist/cli/program.d.ts.map +1 -0
  16. package/dist/cli/program.js +174 -0
  17. package/dist/cli/run.d.ts +6 -0
  18. package/dist/cli/run.d.ts.map +1 -0
  19. package/dist/cli/run.js +83 -0
  20. package/dist/cli/runtime.d.ts +21 -0
  21. package/dist/cli/runtime.d.ts.map +1 -0
  22. package/dist/cli/runtime.js +80 -0
  23. package/dist/cli.d.ts +2 -20
  24. package/dist/cli.d.ts.map +1 -1
  25. package/dist/cli.js +2 -737
  26. package/dist/commands/auth.d.ts +1 -4
  27. package/dist/commands/auth.d.ts.map +1 -1
  28. package/dist/commands/auth.js +0 -8
  29. package/dist/commands/catalog.d.ts +3 -1
  30. package/dist/commands/catalog.d.ts.map +1 -1
  31. package/dist/commands/catalog.js +19 -2
  32. package/dist/commands/invoke.d.ts.map +1 -1
  33. package/dist/commands/invoke.js +53 -3
  34. package/dist/infra/credentials.d.ts.map +1 -1
  35. package/dist/infra/credentials.js +0 -7
  36. package/dist/infra/http.d.ts +5 -1
  37. package/dist/infra/http.d.ts.map +1 -1
  38. package/dist/infra/http.js +62 -5
  39. package/dist/output/envelope.d.ts +5 -2
  40. package/dist/output/envelope.d.ts.map +1 -1
  41. package/dist/output/envelope.js +39 -23
  42. package/dist/output/manager.d.ts +9 -5
  43. package/dist/output/manager.d.ts.map +1 -1
  44. package/dist/output/manager.js +52 -9
  45. package/dist/services/account.d.ts.map +1 -1
  46. package/dist/services/account.js +9 -16
  47. package/dist/services/auth.d.ts +3 -15
  48. package/dist/services/auth.d.ts.map +1 -1
  49. package/dist/services/auth.js +32 -483
  50. package/dist/services/info.d.ts.map +1 -1
  51. package/dist/services/info.js +62 -0
  52. package/dist/services/mcp-error-mapping.d.ts +9 -0
  53. package/dist/services/mcp-error-mapping.d.ts.map +1 -0
  54. package/dist/services/mcp-error-mapping.js +129 -0
  55. package/dist/services/mcp.d.ts +8 -2
  56. package/dist/services/mcp.d.ts.map +1 -1
  57. package/dist/services/mcp.js +24 -14
  58. package/dist/shared/constants.d.ts +0 -2
  59. package/dist/shared/constants.d.ts.map +1 -1
  60. package/dist/shared/constants.js +0 -2
  61. package/dist/shared/error-codes.d.ts +4 -1
  62. package/dist/shared/error-codes.d.ts.map +1 -1
  63. package/dist/shared/error-presentation.d.ts +17 -0
  64. package/dist/shared/error-presentation.d.ts.map +1 -0
  65. package/dist/shared/error-presentation.js +151 -0
  66. package/dist/shared/errors.d.ts +34 -14
  67. package/dist/shared/errors.d.ts.map +1 -1
  68. package/dist/shared/errors.js +126 -25
  69. package/dist/shared/guards.d.ts +2 -1
  70. package/dist/shared/guards.d.ts.map +1 -1
  71. package/dist/shared/guards.js +1 -3
  72. package/dist/shared/recovery.d.ts +5 -0
  73. package/dist/shared/recovery.d.ts.map +1 -0
  74. package/dist/shared/recovery.js +123 -0
  75. package/dist/shared/schemas.d.ts +2 -3
  76. package/dist/shared/schemas.d.ts.map +1 -1
  77. package/dist/shared/schemas.js +2 -3
  78. package/dist/shared/types.d.ts +53 -13
  79. package/dist/shared/types.d.ts.map +1 -1
  80. package/dist/shared/types.js +1 -1
  81. package/package.json +2 -4
  82. package/dist/infra/browser.d.ts +0 -12
  83. package/dist/infra/browser.d.ts.map +0 -1
  84. package/dist/infra/browser.js +0 -20
  85. package/dist/shared/retry.d.ts +0 -17
  86. package/dist/shared/retry.d.ts.map +0 -1
  87. package/dist/shared/retry.js +0 -27
@@ -1,13 +1,15 @@
1
1
  import { ERROR_CODE, type ErrorCategory, type ErrorCode } from "./error-codes.js";
2
+ import { type RecoveryOverride } from "./recovery.js";
3
+ import type { CliNextAction, RemoteErrorDiagnostics, RemoteErrorSource } from "./types.js";
2
4
  type AuthErrorCode = typeof ERROR_CODE.authDeviceExpired | typeof ERROR_CODE.authDevicePending | typeof ERROR_CODE.authInvalidCredentials | typeof ERROR_CODE.authRequired;
3
- type RemoteErrorCode = typeof ERROR_CODE.remoteRateLimited | typeof ERROR_CODE.remoteUnavailable | typeof ERROR_CODE.transportRequestFailed;
5
+ type RemoteErrorCode = typeof ERROR_CODE.remoteRateLimited | typeof ERROR_CODE.remoteUnavailable | typeof ERROR_CODE.transportRequestFailed | `HTTP_${number}` | `MCP_${number}`;
4
6
  type ValidationErrorCode = typeof ERROR_CODE.toolInputSchemaViolation | typeof ERROR_CODE.validationInvalidInput;
5
7
  type ContractMismatchErrorCode = typeof ERROR_CODE.contractVersionUnsupported;
6
8
  interface BaseAppErrorFields {
7
9
  category: ErrorCategory;
8
10
  code: ErrorCode;
11
+ recovery: CliNextAction | undefined;
9
12
  retryable: boolean;
10
- suggestedCommand: string | undefined;
11
13
  }
12
14
  declare const ValidationErrorBase: import("better-result").TaggedErrorClass<"ValidationError", {
13
15
  details?: string;
@@ -17,13 +19,13 @@ interface ValidationErrorPayload {
17
19
  code?: ValidationErrorCode;
18
20
  details?: string;
19
21
  message: string;
20
- suggestedCommand?: string;
22
+ recovery?: RecoveryOverride;
21
23
  }
22
24
  export declare class ValidationError extends ValidationErrorBase implements BaseAppErrorFields {
23
25
  readonly category: "validation";
24
26
  readonly code: ValidationErrorCode;
27
+ readonly recovery: CliNextAction | undefined;
25
28
  readonly retryable = false;
26
- readonly suggestedCommand: string | undefined;
27
29
  constructor(payload: ValidationErrorPayload);
28
30
  }
29
31
  declare const AuthErrorBase: import("better-result").TaggedErrorClass<"AuthError", {
@@ -34,14 +36,14 @@ interface AuthErrorPayload {
34
36
  code?: AuthErrorCode;
35
37
  details?: string;
36
38
  message: string;
39
+ recovery?: RecoveryOverride;
37
40
  retryable?: boolean;
38
- suggestedCommand?: string;
39
41
  }
40
42
  export declare class AuthError extends AuthErrorBase implements BaseAppErrorFields {
41
43
  readonly category: "auth";
42
44
  readonly code: AuthErrorCode;
45
+ readonly recovery: CliNextAction | undefined;
43
46
  readonly retryable: boolean;
44
- readonly suggestedCommand: string | undefined;
45
47
  constructor(payload: AuthErrorPayload);
46
48
  }
47
49
  declare const NotFoundErrorBase: import("better-result").TaggedErrorClass<"NotFoundError", {
@@ -51,33 +53,48 @@ declare const NotFoundErrorBase: import("better-result").TaggedErrorClass<"NotFo
51
53
  interface NotFoundErrorPayload {
52
54
  code?: typeof ERROR_CODE.toolNotFound;
53
55
  message: string;
56
+ recovery?: RecoveryOverride;
54
57
  resource: string;
55
- suggestedCommand?: string;
56
58
  }
57
59
  export declare class NotFoundError extends NotFoundErrorBase implements BaseAppErrorFields {
58
60
  readonly category: "not_found";
59
61
  readonly code: typeof ERROR_CODE.toolNotFound;
62
+ readonly recovery: CliNextAction | undefined;
60
63
  readonly retryable = false;
61
- readonly suggestedCommand: string | undefined;
62
64
  constructor(payload: NotFoundErrorPayload);
63
65
  }
64
66
  declare const RemoteRequestErrorBase: import("better-result").TaggedErrorClass<"RemoteRequestError", {
65
67
  body?: string;
66
68
  message: string;
69
+ mcpCode?: number;
70
+ mcpData?: unknown;
71
+ operation?: string;
72
+ raw?: unknown;
73
+ source: RemoteErrorSource;
67
74
  status?: number;
68
75
  }>;
69
76
  interface RemoteRequestErrorPayload {
70
77
  body?: string;
71
78
  code?: RemoteErrorCode;
79
+ diagnostics?: Partial<RemoteErrorDiagnostics>;
80
+ httpStatus?: number;
81
+ mcpCode?: number;
82
+ mcpData?: unknown;
72
83
  message: string;
84
+ operation?: string;
85
+ raw?: unknown;
86
+ recovery?: RecoveryOverride;
87
+ retryable?: boolean;
88
+ source?: RemoteErrorSource;
73
89
  status?: number;
74
- suggestedCommand?: string;
75
90
  }
76
91
  export declare class RemoteRequestError extends RemoteRequestErrorBase implements BaseAppErrorFields {
77
92
  readonly category: ErrorCategory;
78
93
  readonly code: RemoteErrorCode;
94
+ readonly diagnostics: RemoteErrorDiagnostics;
95
+ readonly httpStatus: number | undefined;
96
+ readonly recovery: CliNextAction | undefined;
79
97
  readonly retryable: boolean;
80
- readonly suggestedCommand: string | undefined;
81
98
  constructor(payload: RemoteRequestErrorPayload);
82
99
  }
83
100
  declare const ContractMismatchErrorBase: import("better-result").TaggedErrorClass<"ContractMismatchError", {
@@ -88,13 +105,13 @@ interface ContractMismatchErrorPayload {
88
105
  code?: ContractMismatchErrorCode;
89
106
  details?: string;
90
107
  message: string;
91
- suggestedCommand?: string;
108
+ recovery?: RecoveryOverride;
92
109
  }
93
110
  export declare class ContractMismatchError extends ContractMismatchErrorBase implements BaseAppErrorFields {
94
111
  readonly category: "contract_mismatch";
95
112
  readonly code: ContractMismatchErrorCode;
113
+ readonly recovery: CliNextAction | undefined;
96
114
  readonly retryable = false;
97
- readonly suggestedCommand: string | undefined;
98
115
  constructor(payload: ContractMismatchErrorPayload);
99
116
  }
100
117
  declare const UnexpectedErrorBase: import("better-result").TaggedErrorClass<"UnexpectedError", {
@@ -105,22 +122,25 @@ interface UnexpectedErrorPayload {
105
122
  cause?: unknown;
106
123
  code?: typeof ERROR_CODE.internalUnexpected;
107
124
  message: string;
125
+ recovery?: RecoveryOverride;
108
126
  }
109
127
  export declare class UnexpectedError extends UnexpectedErrorBase implements BaseAppErrorFields {
110
128
  readonly category: "internal";
111
129
  readonly code: typeof ERROR_CODE.internalUnexpected;
130
+ readonly recovery: CliNextAction | undefined;
112
131
  readonly retryable = false;
113
- readonly suggestedCommand: undefined;
114
132
  constructor(payload: UnexpectedErrorPayload);
115
133
  }
116
134
  export type AppError = AuthError | ContractMismatchError | NotFoundError | RemoteRequestError | UnexpectedError | ValidationError;
117
135
  export interface AppErrorMeta {
118
136
  category: ErrorCategory;
119
137
  code: ErrorCode;
138
+ recovery: CliNextAction | undefined;
120
139
  retryable: boolean;
121
- suggestedCommand: string | undefined;
122
140
  }
123
141
  export declare const appErrorMeta: (error: AppError) => AppErrorMeta;
142
+ export declare const appErrorDiagnostics: (error: AppError) => Record<string, unknown>;
143
+ export declare const appErrorTitle: (error: AppError) => string;
124
144
  export declare const formatAppError: (error: AppError) => string;
125
145
  export {};
126
146
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/shared/errors.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,UAAU,EAAE,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElG,KAAK,aAAa,GACd,OAAO,UAAU,CAAC,iBAAiB,GACnC,OAAO,UAAU,CAAC,iBAAiB,GACnC,OAAO,UAAU,CAAC,sBAAsB,GACxC,OAAO,UAAU,CAAC,YAAY,CAAC;AAEnC,KAAK,eAAe,GAChB,OAAO,UAAU,CAAC,iBAAiB,GACnC,OAAO,UAAU,CAAC,iBAAiB,GACnC,OAAO,UAAU,CAAC,sBAAsB,CAAC;AAE7C,KAAK,mBAAmB,GACpB,OAAO,UAAU,CAAC,wBAAwB,GAC1C,OAAO,UAAU,CAAC,sBAAsB,CAAC;AAE7C,KAAK,yBAAyB,GAAG,OAAO,UAAU,CAAC,0BAA0B,CAAC;AAE9E,UAAU,kBAAkB;IAC1B,QAAQ,EAAE,aAAa,CAAC;IACxB,IAAI,EAAE,SAAS,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;CACtC;AAED,QAAA,MAAM,mBAAmB;cACb,MAAM;aACP,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;EACb,CAAC;AAEL,UAAU,sBAAsB;IAC9B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,UAAU,CAAC,kBAAkB,CAAC;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,gBAAgB,CAAC;CAC7B;AAED,qBAAa,eAAgB,SAAQ,mBAAoB,YAAW,kBAAkB;IACpF,QAAQ,CAAC,QAAQ,aAA2B;IAC5C,QAAQ,CAAC,IAAI,EAAE,OAAO,UAAU,CAAC,kBAAkB,CAAC;IACpD,QAAQ,CAAC,QAAQ,EAAE,aAAa,GAAG,SAAS,CAAC;IAC7C,QAAQ,CAAC,SAAS,SAAS;gBAER,OAAO,EAAE,sBAAsB;CASnD;AAED,MAAM,MAAM,QAAQ,GAChB,SAAS,GACT,qBAAqB,GACrB,aAAa,GACb,kBAAkB,GAClB,eAAe,GACf,eAAe,CAAC;AAEpB,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,aAAa,CAAC;IACxB,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,EAAE,aAAa,GAAG,SAAS,CAAC;IACpC,SAAS,EAAE,OAAO,CAAC;CACpB;AAqBD,eAAO,MAAM,YAAY,GAAI,OAAO,QAAQ,KAAG,YAO9C,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,OAAO,QAAQ,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAsC3E,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,OAAO,QAAQ,KAAG,MAU/C,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,OAAO,QAAQ,KAAG,MAchD,CAAC"}
@@ -1,112 +1,171 @@
1
1
  import { TaggedError } from "better-result";
2
2
  import { ERROR_CATEGORY, ERROR_CODE } from "./error-codes.js";
3
+ import { normalizeRecovery } from "./recovery.js";
3
4
  const ValidationErrorBase = TaggedError("ValidationError")();
4
5
  export class ValidationError extends ValidationErrorBase {
5
6
  category = ERROR_CATEGORY.validation;
6
7
  code;
8
+ recovery;
7
9
  retryable = false;
8
- suggestedCommand;
9
10
  constructor(payload) {
10
11
  super({
11
12
  message: payload.message,
12
13
  ...(payload.details === undefined ? {} : { details: payload.details }),
13
14
  });
14
15
  this.code = payload.code ?? ERROR_CODE.validationInvalidInput;
15
- this.suggestedCommand = payload.suggestedCommand;
16
+ this.recovery = normalizeRecovery(this.code, payload.recovery);
16
17
  }
17
18
  }
18
19
  const AuthErrorBase = TaggedError("AuthError")();
19
20
  export class AuthError extends AuthErrorBase {
20
21
  category = ERROR_CATEGORY.auth;
21
22
  code;
23
+ recovery;
22
24
  retryable;
23
- suggestedCommand;
24
25
  constructor(payload) {
25
26
  super({
26
27
  message: payload.message,
27
28
  ...(payload.details === undefined ? {} : { details: payload.details }),
28
29
  });
29
30
  this.code = payload.code ?? ERROR_CODE.authRequired;
31
+ this.recovery = normalizeRecovery(this.code, payload.recovery);
30
32
  this.retryable = payload.retryable ?? this.code === ERROR_CODE.authDeviceExpired;
31
- this.suggestedCommand = payload.suggestedCommand;
32
33
  }
33
34
  }
34
35
  const NotFoundErrorBase = TaggedError("NotFoundError")();
35
36
  export class NotFoundError extends NotFoundErrorBase {
36
37
  category = ERROR_CATEGORY.notFound;
37
38
  code;
39
+ recovery;
38
40
  retryable = false;
39
- suggestedCommand;
40
41
  constructor(payload) {
41
42
  super({
42
43
  message: payload.message,
43
44
  resource: payload.resource,
44
45
  });
45
46
  this.code = payload.code ?? ERROR_CODE.toolNotFound;
46
- this.suggestedCommand = payload.suggestedCommand;
47
+ this.recovery = normalizeRecovery(this.code, payload.recovery);
47
48
  }
48
49
  }
49
50
  const RemoteRequestErrorBase = TaggedError("RemoteRequestError")();
50
- const resolveRemoteErrorCode = (payload) => {
51
+ const parseHttpCode = (code) => {
52
+ if (!code.startsWith("HTTP_")) {
53
+ return undefined;
54
+ }
55
+ const parsed = Number.parseInt(code.slice("HTTP_".length), 10);
56
+ if (!Number.isFinite(parsed)) {
57
+ return undefined;
58
+ }
59
+ return parsed;
60
+ };
61
+ const resolveRemoteErrorCode = (payload, diagnostics) => {
51
62
  if (payload.code !== undefined) {
52
63
  return payload.code;
53
64
  }
54
- if (payload.status === 429) {
55
- return ERROR_CODE.remoteRateLimited;
65
+ if (typeof diagnostics.httpStatus === "number") {
66
+ return `HTTP_${diagnostics.httpStatus}`;
56
67
  }
57
- if (payload.status !== undefined && payload.status >= 500) {
58
- return ERROR_CODE.remoteUnavailable;
68
+ if (typeof diagnostics.mcpCode === "number") {
69
+ return `MCP_${diagnostics.mcpCode}`;
59
70
  }
60
71
  return ERROR_CODE.transportRequestFailed;
61
72
  };
73
+ const resolveRemoteDiagnostics = (payload) => {
74
+ const source = payload.source ?? payload.diagnostics?.source ?? "network";
75
+ return {
76
+ httpStatus: payload.httpStatus ?? payload.status ?? payload.diagnostics?.httpStatus,
77
+ mcpCode: payload.mcpCode ?? payload.diagnostics?.mcpCode,
78
+ mcpData: payload.mcpData ?? payload.diagnostics?.mcpData,
79
+ operation: payload.operation ?? payload.diagnostics?.operation,
80
+ raw: payload.raw ?? payload.diagnostics?.raw,
81
+ source,
82
+ };
83
+ };
84
+ const resolveRetryableRemoteError = (diagnostics, code) => {
85
+ const httpStatus = diagnostics.httpStatus ?? parseHttpCode(code);
86
+ if (typeof httpStatus === "number") {
87
+ return httpStatus === 429 || httpStatus >= 500;
88
+ }
89
+ if (typeof diagnostics.mcpCode === "number") {
90
+ return diagnostics.mcpCode === -32_001;
91
+ }
92
+ return diagnostics.source === "network";
93
+ };
94
+ const resolveRemoteCategory = (code, diagnostics) => {
95
+ const httpStatus = diagnostics.httpStatus ?? parseHttpCode(code);
96
+ if (code === ERROR_CODE.remoteRateLimited || httpStatus === 429) {
97
+ return ERROR_CATEGORY.rateLimit;
98
+ }
99
+ return ERROR_CATEGORY.remote;
100
+ };
62
101
  export class RemoteRequestError extends RemoteRequestErrorBase {
63
102
  category;
64
103
  code;
104
+ diagnostics;
105
+ httpStatus;
106
+ recovery;
65
107
  retryable;
66
- suggestedCommand;
67
108
  constructor(payload) {
109
+ const diagnostics = resolveRemoteDiagnostics(payload);
110
+ const code = resolveRemoteErrorCode(payload, diagnostics);
111
+ const status = diagnostics.httpStatus;
68
112
  super({
69
113
  message: payload.message,
70
114
  ...(payload.body === undefined ? {} : { body: payload.body }),
71
- ...(payload.status === undefined ? {} : { status: payload.status }),
115
+ ...(status === undefined ? {} : { status }),
116
+ source: diagnostics.source,
117
+ ...(diagnostics.mcpCode === undefined ? {} : { mcpCode: diagnostics.mcpCode }),
118
+ ...(diagnostics.mcpData === undefined ? {} : { mcpData: diagnostics.mcpData }),
119
+ ...(diagnostics.operation === undefined ? {} : { operation: diagnostics.operation }),
120
+ ...(diagnostics.raw === undefined ? {} : { raw: diagnostics.raw }),
72
121
  });
73
- this.code = resolveRemoteErrorCode(payload);
74
- this.category =
75
- this.code === ERROR_CODE.remoteRateLimited ? ERROR_CATEGORY.rateLimit : ERROR_CATEGORY.remote;
76
- const status = payload.status;
77
- this.retryable = status === undefined || status === 429 || status >= 500;
78
- this.suggestedCommand = payload.suggestedCommand;
122
+ this.code = code;
123
+ this.category = resolveRemoteCategory(code, diagnostics);
124
+ this.diagnostics = diagnostics;
125
+ this.httpStatus = diagnostics.httpStatus;
126
+ this.recovery = normalizeRecovery(this.code, payload.recovery);
127
+ this.retryable = payload.retryable ?? resolveRetryableRemoteError(diagnostics, code);
79
128
  }
80
129
  }
81
130
  const ContractMismatchErrorBase = TaggedError("ContractMismatchError")();
82
131
  export class ContractMismatchError extends ContractMismatchErrorBase {
83
132
  category = ERROR_CATEGORY.contractMismatch;
84
133
  code;
134
+ recovery;
85
135
  retryable = false;
86
- suggestedCommand;
87
136
  constructor(payload) {
88
137
  super({
89
138
  message: payload.message,
90
139
  ...(payload.details === undefined ? {} : { details: payload.details }),
91
140
  });
92
141
  this.code = payload.code ?? ERROR_CODE.contractVersionUnsupported;
93
- this.suggestedCommand = payload.suggestedCommand;
142
+ this.recovery = normalizeRecovery(this.code, payload.recovery);
94
143
  }
95
144
  }
96
145
  const UnexpectedErrorBase = TaggedError("UnexpectedError")();
97
146
  export class UnexpectedError extends UnexpectedErrorBase {
98
147
  category = ERROR_CATEGORY.internal;
99
148
  code;
149
+ recovery;
100
150
  retryable = false;
101
- suggestedCommand = undefined;
102
151
  constructor(payload) {
103
152
  super({
104
153
  message: payload.message,
105
154
  ...(payload.cause === undefined ? {} : { cause: payload.cause }),
106
155
  });
107
156
  this.code = payload.code ?? ERROR_CODE.internalUnexpected;
157
+ this.recovery = normalizeRecovery(this.code, payload.recovery);
108
158
  }
109
159
  }
160
+ const withIfDefined = (base, key, value) => {
161
+ if (value === undefined) {
162
+ return base;
163
+ }
164
+ return {
165
+ ...base,
166
+ [key]: value,
167
+ };
168
+ };
110
169
  const hasDetails = (error) => {
111
170
  return error._tag === "AuthError" || error._tag === "ValidationError";
112
171
  };
@@ -114,16 +173,58 @@ export const appErrorMeta = (error) => {
114
173
  return {
115
174
  category: error.category,
116
175
  code: error.code,
176
+ recovery: error.recovery,
117
177
  retryable: error.retryable,
118
- suggestedCommand: error.suggestedCommand,
119
178
  };
120
179
  };
180
+ export const appErrorDiagnostics = (error) => {
181
+ if (error._tag === "RemoteRequestError") {
182
+ let diagnostics = {
183
+ source: error.source,
184
+ };
185
+ diagnostics = withIfDefined(diagnostics, "httpStatus", error.httpStatus);
186
+ diagnostics = withIfDefined(diagnostics, "mcpCode", error.mcpCode);
187
+ diagnostics = withIfDefined(diagnostics, "mcpData", error.mcpData);
188
+ diagnostics = withIfDefined(diagnostics, "operation", error.operation);
189
+ diagnostics = withIfDefined(diagnostics, "raw", error.raw);
190
+ diagnostics = withIfDefined(diagnostics, "body", error.body);
191
+ return diagnostics;
192
+ }
193
+ if (error._tag === "NotFoundError") {
194
+ return {
195
+ resource: error.resource,
196
+ };
197
+ }
198
+ if (error._tag === "UnexpectedError") {
199
+ if (error.cause === undefined) {
200
+ return {};
201
+ }
202
+ return {
203
+ cause: error.cause,
204
+ };
205
+ }
206
+ if (hasDetails(error) && typeof error.details === "string" && error.details.length > 0) {
207
+ return {
208
+ details: error.details,
209
+ };
210
+ }
211
+ return {};
212
+ };
213
+ export const appErrorTitle = (error) => {
214
+ if (error._tag === "UnexpectedError") {
215
+ return "Unexpected CLI error";
216
+ }
217
+ if (error._tag === "ContractMismatchError") {
218
+ return "Contract version unsupported";
219
+ }
220
+ return error.message;
221
+ };
121
222
  export const formatAppError = (error) => {
122
223
  if (error._tag === "NotFoundError") {
123
224
  return `${error.message} (${error.resource})`;
124
225
  }
125
- if (error._tag === "RemoteRequestError" && typeof error.status === "number") {
126
- return `${error.message} (status ${error.status})`;
226
+ if (error._tag === "RemoteRequestError" && typeof error.httpStatus === "number") {
227
+ return `${error.message} (status ${error.httpStatus})`;
127
228
  }
128
229
  if (hasDetails(error) && typeof error.details === "string" && error.details.length > 0) {
129
230
  return `${error.message}: ${error.details}`;
@@ -3,8 +3,9 @@ import type { ZodTypeAny } from "zod";
3
3
  import { z } from "zod";
4
4
  import { ERROR_CODE } from "./error-codes.js";
5
5
  import { ValidationError } from "./errors.js";
6
+ import type { RecoveryOverride } from "./recovery.js";
6
7
  export declare const parseWithSchema: <TSchema extends ZodTypeAny>(schema: TSchema, payload: unknown, context: string, options?: {
7
8
  code?: typeof ERROR_CODE.toolInputSchemaViolation | typeof ERROR_CODE.validationInvalidInput;
8
- suggestedCommand?: string;
9
+ recovery?: RecoveryOverride;
9
10
  }) => ResultType<z.infer<TSchema>, ValidationError>;
10
11
  //# sourceMappingURL=guards.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/shared/guards.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACtC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAoB9C,eAAO,MAAM,eAAe,GAAI,OAAO,SAAS,UAAU,EACxD,QAAQ,OAAO,EACf,SAAS,OAAO,EAChB,SAAS,MAAM,EACf,UAAS;IACP,IAAI,CAAC,EAAE,OAAO,UAAU,CAAC,wBAAwB,GAAG,OAAO,UAAU,CAAC,sBAAsB,CAAC;IAC7F,gBAAgB,CAAC,EAAE,MAAM,CAAC;CACtB,KACL,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,eAAe,CAiB9C,CAAC"}
1
+ {"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/shared/guards.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACtC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAoBtD,eAAO,MAAM,eAAe,GAAI,OAAO,SAAS,UAAU,EACxD,QAAQ,OAAO,EACf,SAAS,OAAO,EAChB,SAAS,MAAM,EACf,UAAS;IACP,IAAI,CAAC,EAAE,OAAO,UAAU,CAAC,wBAAwB,GAAG,OAAO,UAAU,CAAC,sBAAsB,CAAC;IAC7F,QAAQ,CAAC,EAAE,gBAAgB,CAAC;CACxB,KACL,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,eAAe,CAe9C,CAAC"}
@@ -22,9 +22,7 @@ export const parseWithSchema = (schema, payload, context, options = {}) => {
22
22
  details: formatIssues(parsed.error.issues),
23
23
  message: `Invalid ${context}`,
24
24
  ...(options.code === undefined ? {} : { code: options.code }),
25
- ...(options.suggestedCommand === undefined
26
- ? {}
27
- : { suggestedCommand: options.suggestedCommand }),
25
+ ...(options.recovery === undefined ? {} : { recovery: options.recovery }),
28
26
  }));
29
27
  }
30
28
  return Result.ok(parsed.data);
@@ -0,0 +1,5 @@
1
+ import { type ErrorCode } from "./error-codes.js";
2
+ import type { CliNextAction } from "./types.js";
3
+ export type RecoveryOverride = Partial<CliNextAction>;
4
+ export declare const normalizeRecovery: (code: ErrorCode, override?: RecoveryOverride) => CliNextAction | undefined;
5
+ //# sourceMappingURL=recovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recovery.d.ts","sourceRoot":"","sources":["../../src/shared/recovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,SAAS,EAAwB,MAAM,kBAAkB,CAAC;AACpF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AA0HtD,eAAO,MAAM,iBAAiB,GAC5B,MAAM,SAAS,EACf,WAAW,gBAAgB,KAC1B,aAAa,GAAG,SAkBlB,CAAC"}
@@ -0,0 +1,123 @@
1
+ import { ERROR_CODE } from "./error-codes.js";
2
+ const defaultRecoveryByCode = {
3
+ [ERROR_CODE.authDeviceExpired]: {
4
+ command: "ogment auth login",
5
+ reason: "Device code expired; restart login to continue.",
6
+ title: "Restart login",
7
+ when: "immediate",
8
+ },
9
+ [ERROR_CODE.authDevicePending]: {
10
+ command: "ogment auth status",
11
+ reason: "Authorization is pending; check whether credentials are now available.",
12
+ title: "Check auth status",
13
+ when: "immediate",
14
+ },
15
+ [ERROR_CODE.authInvalidCredentials]: {
16
+ command: "ogment auth logout",
17
+ reason: "Credentials are invalid; clear local state before re-authenticating.",
18
+ title: "Reset auth state",
19
+ when: "immediate",
20
+ },
21
+ [ERROR_CODE.authRequired]: {
22
+ command: "ogment auth login",
23
+ reason: "Authentication is required before catalog or invoke commands can run.",
24
+ title: "Authenticate",
25
+ when: "immediate",
26
+ },
27
+ [ERROR_CODE.contractVersionUnsupported]: {
28
+ command: "ogment --version",
29
+ reason: "Contract mismatch detected; verify CLI version and upgrade before retrying.",
30
+ title: "Inspect CLI version",
31
+ when: "immediate",
32
+ },
33
+ [ERROR_CODE.internalUnexpected]: {
34
+ command: "ogment status",
35
+ reason: "Unexpected failure detected; run diagnostics before retrying the workflow.",
36
+ title: "Inspect diagnostics",
37
+ when: "immediate",
38
+ },
39
+ [ERROR_CODE.remoteRateLimited]: {
40
+ command: "ogment status",
41
+ reason: "Remote rate limit detected; check diagnostics before retrying.",
42
+ title: "Inspect diagnostics",
43
+ when: "immediate",
44
+ },
45
+ [ERROR_CODE.remoteUnavailable]: {
46
+ command: "ogment status",
47
+ reason: "Remote service is unavailable; check connectivity and endpoint health.",
48
+ title: "Inspect diagnostics",
49
+ when: "immediate",
50
+ },
51
+ [ERROR_CODE.toolInputSchemaViolation]: {
52
+ command: "ogment catalog",
53
+ reason: "Tool contract did not validate; inspect available servers and tool metadata.",
54
+ title: "Inspect catalog",
55
+ when: "immediate",
56
+ },
57
+ [ERROR_CODE.toolNotFound]: {
58
+ command: "ogment catalog",
59
+ reason: "Requested tool could not be found; rediscover servers and tools.",
60
+ title: "Rediscover tools",
61
+ when: "immediate",
62
+ },
63
+ [ERROR_CODE.transportRequestFailed]: {
64
+ command: "ogment status",
65
+ reason: "Transport request failed; inspect connectivity diagnostics.",
66
+ title: "Inspect diagnostics",
67
+ when: "immediate",
68
+ },
69
+ [ERROR_CODE.validationInvalidInput]: {
70
+ command: "ogment --help",
71
+ reason: "Input validation failed; inspect canonical command syntax.",
72
+ title: "Show command help",
73
+ when: "immediate",
74
+ },
75
+ };
76
+ const dynamicRecoveryForCode = (code) => {
77
+ if (code.startsWith("HTTP_")) {
78
+ return {
79
+ command: "ogment status",
80
+ reason: `HTTP error ${code} detected; inspect diagnostics and remote connectivity.`,
81
+ title: "Inspect diagnostics",
82
+ when: "immediate",
83
+ };
84
+ }
85
+ if (code.startsWith("MCP_")) {
86
+ return {
87
+ command: "ogment status",
88
+ reason: `MCP error ${code} detected; inspect diagnostics and remote server state.`,
89
+ title: "Inspect diagnostics",
90
+ when: "immediate",
91
+ };
92
+ }
93
+ return undefined;
94
+ };
95
+ const hasPlaceholderTokens = (command) => {
96
+ return command.includes("<") || command.includes(">");
97
+ };
98
+ const sanitizedCommand = (command) => {
99
+ if (typeof command !== "string") {
100
+ return undefined;
101
+ }
102
+ if (hasPlaceholderTokens(command)) {
103
+ return undefined;
104
+ }
105
+ return command;
106
+ };
107
+ export const normalizeRecovery = (code, override) => {
108
+ const fallback = defaultRecoveryByCode[code] ?? dynamicRecoveryForCode(code);
109
+ if (fallback === undefined) {
110
+ return undefined;
111
+ }
112
+ const overrideCommand = sanitizedCommand(override?.command);
113
+ const command = overrideCommand ?? fallback.command;
114
+ const usesCustomCommand = overrideCommand !== undefined && overrideCommand !== fallback.command;
115
+ return {
116
+ command,
117
+ id: override?.id ?? `recover_${code.toLowerCase()}`,
118
+ reason: override?.reason ??
119
+ (usesCustomCommand ? `Suggested recovery for error ${code}.` : fallback.reason),
120
+ title: override?.title ?? (usesCustomCommand ? "Run suggested command" : fallback.title),
121
+ when: override?.when ?? fallback.when,
122
+ };
123
+ };
@@ -1,8 +1,7 @@
1
- import { accountMeSchema, browserAgentCallbackSchema, cliExchangeErrorSchema, cliExchangeRequestSchema, cliExchangeSuccessSchema, deviceCodeStartSchema, deviceTokenApprovedSchema, oauthClientRegistrationSchema, oauthTokenSchema, orgServerSchema, organizationSchema } from "@ogment-ai/cli-contract/v1";
1
+ import { accountMeSchema, deviceCodeStartSchema, deviceTokenApprovedSchema, orgServerSchema, organizationSchema } from "@ogment-ai/cli-contract/v1";
2
2
  import { z } from "zod";
3
- export { accountMeSchema, browserAgentCallbackSchema, cliExchangeErrorSchema, cliExchangeRequestSchema, cliExchangeSuccessSchema, deviceCodeStartSchema, deviceTokenApprovedSchema, oauthClientRegistrationSchema, oauthTokenSchema, orgServerSchema, organizationSchema, };
3
+ export { accountMeSchema, deviceCodeStartSchema, deviceTokenApprovedSchema, orgServerSchema, organizationSchema, };
4
4
  export declare const credentialsFileSchema: z.ZodObject<{
5
- accessToken: z.ZodOptional<z.ZodString>;
6
5
  agentName: z.ZodOptional<z.ZodString>;
7
6
  apiKey: z.ZodOptional<z.ZodString>;
8
7
  }, z.core.$strip>;
@@ -1 +1 @@
1
- {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/shared/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,0BAA0B,EAC1B,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,EACxB,qBAAqB,EACrB,yBAAyB,EACzB,6BAA6B,EAC7B,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,eAAe,EACf,0BAA0B,EAC1B,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,EACxB,qBAAqB,EACrB,yBAAyB,EACzB,6BAA6B,EAC7B,gBAAgB,EAChB,eAAe,EACf,kBAAkB,GACnB,CAAC;AAIF,eAAO,MAAM,qBAAqB;;;;iBAIhC,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;;iBAK/B,CAAC"}
1
+ {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/shared/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,yBAAyB,EACzB,eAAe,EACf,kBAAkB,EACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,yBAAyB,EACzB,eAAe,EACf,kBAAkB,GACnB,CAAC;AAIF,eAAO,MAAM,qBAAqB;;;iBAGhC,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;;iBAK/B,CAAC"}
@@ -1,9 +1,8 @@
1
- import { accountMeSchema, browserAgentCallbackSchema, cliExchangeErrorSchema, cliExchangeRequestSchema, cliExchangeSuccessSchema, deviceCodeStartSchema, deviceTokenApprovedSchema, oauthClientRegistrationSchema, oauthTokenSchema, orgServerSchema, organizationSchema, } from "@ogment-ai/cli-contract/v1";
1
+ import { accountMeSchema, deviceCodeStartSchema, deviceTokenApprovedSchema, orgServerSchema, organizationSchema, } from "@ogment-ai/cli-contract/v1";
2
2
  import { z } from "zod";
3
- export { accountMeSchema, browserAgentCallbackSchema, cliExchangeErrorSchema, cliExchangeRequestSchema, cliExchangeSuccessSchema, deviceCodeStartSchema, deviceTokenApprovedSchema, oauthClientRegistrationSchema, oauthTokenSchema, orgServerSchema, organizationSchema, };
3
+ export { accountMeSchema, deviceCodeStartSchema, deviceTokenApprovedSchema, orgServerSchema, organizationSchema, };
4
4
  const jsonObjectSchema = z.record(z.string(), z.unknown());
5
5
  export const credentialsFileSchema = z.object({
6
- accessToken: z.string().min(1).optional(),
7
6
  agentName: z.string().optional(),
8
7
  apiKey: z.string().min(1).optional(),
9
8
  });