@ogment-ai/cli 0.4.1 → 0.5.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 (74) hide show
  1. package/dist/cli/commands.d.ts +38 -0
  2. package/dist/cli/commands.d.ts.map +1 -0
  3. package/dist/cli/commands.js +57 -0
  4. package/dist/cli/execute.d.ts +11 -0
  5. package/dist/cli/execute.d.ts.map +1 -0
  6. package/dist/cli/execute.js +487 -0
  7. package/dist/cli/invocations.d.ts +32 -0
  8. package/dist/cli/invocations.d.ts.map +1 -0
  9. package/dist/cli/invocations.js +1 -0
  10. package/dist/cli/parse-errors.d.ts +17 -0
  11. package/dist/cli/parse-errors.d.ts.map +1 -0
  12. package/dist/cli/parse-errors.js +184 -0
  13. package/dist/cli/program.d.ts +10 -0
  14. package/dist/cli/program.d.ts.map +1 -0
  15. package/dist/cli/program.js +183 -0
  16. package/dist/cli/run.d.ts +6 -0
  17. package/dist/cli/run.d.ts.map +1 -0
  18. package/dist/cli/run.js +83 -0
  19. package/dist/cli/runtime.d.ts +22 -0
  20. package/dist/cli/runtime.d.ts.map +1 -0
  21. package/dist/cli/runtime.js +86 -0
  22. package/dist/cli.d.ts +2 -20
  23. package/dist/cli.d.ts.map +1 -1
  24. package/dist/cli.js +2 -736
  25. package/dist/commands/catalog.d.ts +3 -1
  26. package/dist/commands/catalog.d.ts.map +1 -1
  27. package/dist/commands/catalog.js +19 -3
  28. package/dist/commands/invoke.d.ts.map +1 -1
  29. package/dist/commands/invoke.js +53 -3
  30. package/dist/infra/http.d.ts +5 -1
  31. package/dist/infra/http.d.ts.map +1 -1
  32. package/dist/infra/http.js +62 -5
  33. package/dist/output/envelope.d.ts +5 -2
  34. package/dist/output/envelope.d.ts.map +1 -1
  35. package/dist/output/envelope.js +39 -23
  36. package/dist/output/manager.d.ts +9 -3
  37. package/dist/output/manager.d.ts.map +1 -1
  38. package/dist/output/manager.js +53 -2
  39. package/dist/services/account.d.ts.map +1 -1
  40. package/dist/services/account.js +9 -16
  41. package/dist/services/auth.d.ts.map +1 -1
  42. package/dist/services/auth.js +70 -52
  43. package/dist/services/info.d.ts.map +1 -1
  44. package/dist/services/info.js +62 -0
  45. package/dist/services/mcp-error-mapping.d.ts +9 -0
  46. package/dist/services/mcp-error-mapping.d.ts.map +1 -0
  47. package/dist/services/mcp-error-mapping.js +129 -0
  48. package/dist/services/mcp.d.ts +8 -2
  49. package/dist/services/mcp.d.ts.map +1 -1
  50. package/dist/services/mcp.js +24 -14
  51. package/dist/shared/error-codes.d.ts +4 -1
  52. package/dist/shared/error-codes.d.ts.map +1 -1
  53. package/dist/shared/error-presentation.d.ts +17 -0
  54. package/dist/shared/error-presentation.d.ts.map +1 -0
  55. package/dist/shared/error-presentation.js +151 -0
  56. package/dist/shared/errors.d.ts +34 -14
  57. package/dist/shared/errors.d.ts.map +1 -1
  58. package/dist/shared/errors.js +126 -25
  59. package/dist/shared/guards.d.ts +2 -1
  60. package/dist/shared/guards.d.ts.map +1 -1
  61. package/dist/shared/guards.js +1 -3
  62. package/dist/shared/recovery.d.ts +5 -0
  63. package/dist/shared/recovery.d.ts.map +1 -0
  64. package/dist/shared/recovery.js +123 -0
  65. package/dist/shared/schema-example.d.ts +1 -0
  66. package/dist/shared/schema-example.d.ts.map +1 -1
  67. package/dist/shared/schema-example.js +13 -36
  68. package/dist/shared/types.d.ts +53 -14
  69. package/dist/shared/types.d.ts.map +1 -1
  70. package/dist/shared/types.js +1 -1
  71. package/package.json +2 -2
  72. package/dist/shared/retry.d.ts +0 -17
  73. package/dist/shared/retry.d.ts.map +0 -1
  74. package/dist/shared/retry.js +0 -27
@@ -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,2 +1,3 @@
1
+ export declare const EXAMPLE_PLACEHOLDER = " ... ";
1
2
  export declare const buildJsonSchemaExample: (schema: Record<string, unknown>) => unknown;
2
3
  //# sourceMappingURL=schema-example.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema-example.d.ts","sourceRoot":"","sources":["../../src/shared/schema-example.ts"],"names":[],"mappings":"AAyJA,eAAO,MAAM,sBAAsB,GAAI,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,OAExE,CAAC"}
1
+ {"version":3,"file":"schema-example.d.ts","sourceRoot":"","sources":["../../src/shared/schema-example.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,mBAAmB,UAAU,CAAC;AA8H3C,eAAO,MAAM,sBAAsB,GAAI,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,OAExE,CAAC"}
@@ -1,4 +1,5 @@
1
1
  const MAX_EXAMPLE_DEPTH = 6;
2
+ export const EXAMPLE_PLACEHOLDER = " ... ";
2
3
  const isRecord = (value) => {
3
4
  return typeof value === "object" && value !== null && !Array.isArray(value);
4
5
  };
@@ -31,38 +32,25 @@ const deriveType = (schema) => {
31
32
  }
32
33
  return undefined;
33
34
  };
34
- const baseScalarExample = (typeName, schema) => {
35
+ const baseScalarExample = (typeName) => {
35
36
  switch (typeName) {
36
37
  case "string": {
37
- const format = schema["format"];
38
- if (format === "email") {
39
- return "agent@example.com";
40
- }
41
- if (format === "uri" || format === "url") {
42
- return "https://example.com";
43
- }
44
- if (format === "date-time") {
45
- return "2026-01-01T00:00:00Z";
46
- }
47
- if (format === "uuid") {
48
- return "00000000-0000-0000-0000-000000000000";
49
- }
50
- return "string";
38
+ return EXAMPLE_PLACEHOLDER;
51
39
  }
52
40
  case "integer": {
53
- return 0;
41
+ return EXAMPLE_PLACEHOLDER;
54
42
  }
55
43
  case "number": {
56
- return 0;
44
+ return EXAMPLE_PLACEHOLDER;
57
45
  }
58
46
  case "boolean": {
59
- return false;
47
+ return EXAMPLE_PLACEHOLDER;
60
48
  }
61
49
  case "null": {
62
- return null;
50
+ return EXAMPLE_PLACEHOLDER;
63
51
  }
64
52
  default: {
65
- return {};
53
+ return EXAMPLE_PLACEHOLDER;
66
54
  }
67
55
  }
68
56
  };
@@ -73,20 +61,6 @@ const buildExample = (value, depth) => {
73
61
  if (depth > MAX_EXAMPLE_DEPTH) {
74
62
  return {};
75
63
  }
76
- if (value["default"] !== undefined) {
77
- return value["default"];
78
- }
79
- if (value["const"] !== undefined) {
80
- return value["const"];
81
- }
82
- const enumValue = firstKnown(value["enum"]);
83
- if (enumValue !== undefined) {
84
- return enumValue;
85
- }
86
- const examplesValue = firstKnown(value["examples"]);
87
- if (examplesValue !== undefined) {
88
- return examplesValue;
89
- }
90
64
  const oneOfCandidate = firstKnown(value["oneOf"]);
91
65
  if (oneOfCandidate !== undefined) {
92
66
  return buildExample(oneOfCandidate, depth + 1);
@@ -116,12 +90,15 @@ const buildExample = (value, depth) => {
116
90
  return result;
117
91
  }
118
92
  if (typeName === "array") {
93
+ if (value["items"] === undefined) {
94
+ return [EXAMPLE_PLACEHOLDER];
95
+ }
119
96
  return [buildExample(value["items"], depth + 1)];
120
97
  }
121
98
  if (typeName === undefined) {
122
- return {};
99
+ return depth === 0 ? {} : EXAMPLE_PLACEHOLDER;
123
100
  }
124
- return baseScalarExample(typeName, value);
101
+ return baseScalarExample(typeName);
125
102
  };
126
103
  export const buildJsonSchemaExample = (schema) => {
127
104
  return buildExample(schema, 0);
@@ -30,9 +30,20 @@ export interface ToolCallResult {
30
30
  structuredContent: unknown;
31
31
  isError: boolean;
32
32
  }
33
+ export type RemoteErrorSource = "http" | "mcp_jsonrpc" | "mcp_transport_http" | "network" | "unknown";
34
+ export interface RemoteErrorDiagnostics {
35
+ httpStatus?: number | undefined;
36
+ mcpCode?: number | undefined;
37
+ mcpData?: unknown;
38
+ operation?: string | undefined;
39
+ raw?: unknown;
40
+ source: RemoteErrorSource;
41
+ }
42
+ export type LoginOutcome = "already_authenticated" | "authenticated";
33
43
  export interface LoginSuccess {
34
44
  agentName: string;
35
- alreadyLoggedIn: boolean;
45
+ loggedIn: true;
46
+ outcome: LoginOutcome;
36
47
  }
37
48
  export interface LogoutSuccess {
38
49
  revoked: boolean;
@@ -70,6 +81,12 @@ export interface InfoPingCheck {
70
81
  }
71
82
  export type InfoAccountStatus = "auth_error" | "remote_error" | "skipped" | "success" | "unexpected_error" | "validation_error";
72
83
  export interface InfoAccountCheck {
84
+ errorCode: string | null;
85
+ errorHttpStatus: number | null;
86
+ errorMcpCode: number | null;
87
+ errorRaw: unknown;
88
+ errorRetryable: boolean | null;
89
+ errorSource: string | null;
73
90
  errorType: string | null;
74
91
  latencyMs: number | null;
75
92
  message: string | null;
@@ -99,17 +116,15 @@ export interface InfoPayload {
99
116
  runtime: InfoRuntimeDetails;
100
117
  summary: InfoSummary;
101
118
  }
102
- export declare const CLI_CONTRACT_VERSION: "0.4";
103
- export type CliContractVersion = typeof CLI_CONTRACT_VERSION;
104
119
  export interface CliPaginationMeta {
105
120
  nextCursor: string | null;
106
121
  }
107
122
  export interface CliMeta {
108
123
  command: string;
109
- entity: Record<string, unknown> | null;
110
- pagination: CliPaginationMeta | null;
111
- requestId: string;
112
- timestamp: string;
124
+ entity?: Record<string, unknown> | null;
125
+ pagination?: CliPaginationMeta;
126
+ requestId?: string;
127
+ timestamp?: string;
113
128
  }
114
129
  export interface CliNextAction {
115
130
  command: string;
@@ -118,19 +133,32 @@ export interface CliNextAction {
118
133
  title: string;
119
134
  when: string | null;
120
135
  }
121
- export interface CliErrorPayload {
136
+ export interface CliRuntimeErrorPayload {
122
137
  category: string;
123
138
  code: string;
124
139
  detail: string;
125
140
  diagnostics: Record<string, unknown>;
126
- docsUrl: string | null;
127
- retryAfterMs: number | null;
141
+ related_codes?: string[];
128
142
  retryable: boolean;
129
- suggestedCommand: string | null;
130
143
  title: string;
131
144
  }
145
+ export type CliParseErrorKind = "missing_argument" | "missing_option_value" | "missing_subcommand" | "invalid_argument" | "conflicting_option" | "excess_arguments" | "unknown_command" | "unknown_option" | "other";
146
+ export interface CliParseErrorDiagnostics {
147
+ kind: CliParseErrorKind;
148
+ parserCode?: string;
149
+ helpText?: string | null;
150
+ scope: string | null;
151
+ }
152
+ export interface CliParseErrorPayload {
153
+ category: "parse";
154
+ code: "CLI_PARSE_ERROR";
155
+ detail: string;
156
+ diagnostics: CliParseErrorDiagnostics;
157
+ retryable: false;
158
+ title: string;
159
+ }
160
+ export type CliErrorPayload = CliParseErrorPayload | CliRuntimeErrorPayload;
132
161
  export interface CliSuccessEnvelope<TData> {
133
- version: CliContractVersion;
134
162
  data: TData;
135
163
  error: null;
136
164
  meta: CliMeta;
@@ -138,7 +166,6 @@ export interface CliSuccessEnvelope<TData> {
138
166
  ok: true;
139
167
  }
140
168
  export interface CliErrorEnvelope {
141
- version: CliContractVersion;
142
169
  data: null;
143
170
  error: CliErrorPayload;
144
171
  meta: CliMeta;
@@ -160,11 +187,23 @@ export interface CatalogServerSummary {
160
187
  version: string | null;
161
188
  }
162
189
  export interface CatalogSummarySuccess {
190
+ failures: CatalogServerFailure[];
163
191
  servers: CatalogServerSummary[];
164
192
  }
193
+ export interface CatalogServerFailure {
194
+ error: {
195
+ code: string;
196
+ diagnostics: Record<string, unknown>;
197
+ detail: string;
198
+ related_codes?: string[];
199
+ retryable: boolean;
200
+ title: string;
201
+ };
202
+ orgSlug: string;
203
+ serverId: string;
204
+ }
165
205
  export interface CatalogToolSummary {
166
206
  description: string | null;
167
- inputSchemaRef: string | null;
168
207
  name: string;
169
208
  }
170
209
  export interface CatalogToolsSuccess {