workos 0.13.4 → 0.14.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 (85) hide show
  1. package/README.md +39 -3
  2. package/dist/bin.js +100 -12
  3. package/dist/bin.js.map +1 -1
  4. package/dist/commands/api/catalog.d.ts +23 -0
  5. package/dist/commands/api/catalog.js +97 -0
  6. package/dist/commands/api/catalog.js.map +1 -0
  7. package/dist/commands/api/format.d.ts +5 -0
  8. package/dist/commands/api/format.js +46 -0
  9. package/dist/commands/api/format.js.map +1 -0
  10. package/dist/commands/api/index.d.ts +15 -0
  11. package/dist/commands/api/index.js +200 -0
  12. package/dist/commands/api/index.js.map +1 -0
  13. package/dist/commands/api/interactive.d.ts +3 -0
  14. package/dist/commands/api/interactive.js +127 -0
  15. package/dist/commands/api/interactive.js.map +1 -0
  16. package/dist/commands/api/request.d.ts +14 -0
  17. package/dist/commands/api/request.js +38 -0
  18. package/dist/commands/api/request.js.map +1 -0
  19. package/dist/commands/claim.js +21 -2
  20. package/dist/commands/claim.js.map +1 -1
  21. package/dist/commands/connection.js +5 -3
  22. package/dist/commands/connection.js.map +1 -1
  23. package/dist/commands/debug.js +5 -4
  24. package/dist/commands/debug.js.map +1 -1
  25. package/dist/commands/directory.js +5 -3
  26. package/dist/commands/directory.js.map +1 -1
  27. package/dist/commands/env.js +13 -3
  28. package/dist/commands/env.js.map +1 -1
  29. package/dist/commands/login.js +20 -4
  30. package/dist/commands/login.js.map +1 -1
  31. package/dist/doctor/checks/auth-patterns.js +12 -1
  32. package/dist/doctor/checks/auth-patterns.js.map +1 -1
  33. package/dist/doctor/checks/host-execution.d.ts +2 -0
  34. package/dist/doctor/checks/host-execution.js +21 -0
  35. package/dist/doctor/checks/host-execution.js.map +1 -0
  36. package/dist/doctor/index.js +9 -1
  37. package/dist/doctor/index.js.map +1 -1
  38. package/dist/doctor/issues.d.ts +5 -0
  39. package/dist/doctor/issues.js +12 -0
  40. package/dist/doctor/issues.js.map +1 -1
  41. package/dist/doctor/output.d.ts +2 -0
  42. package/dist/doctor/output.js +42 -0
  43. package/dist/doctor/output.js.map +1 -1
  44. package/dist/doctor/types.d.ts +16 -0
  45. package/dist/doctor/types.js.map +1 -1
  46. package/dist/lib/config-store.js +51 -7
  47. package/dist/lib/config-store.js.map +1 -1
  48. package/dist/lib/credential-proxy.js +14 -1
  49. package/dist/lib/credential-proxy.js.map +1 -1
  50. package/dist/lib/credential-store.js +51 -7
  51. package/dist/lib/credential-store.js.map +1 -1
  52. package/dist/lib/ensure-auth.d.ts +0 -10
  53. package/dist/lib/ensure-auth.js +27 -9
  54. package/dist/lib/ensure-auth.js.map +1 -1
  55. package/dist/lib/host-probe.d.ts +28 -0
  56. package/dist/lib/host-probe.js +154 -0
  57. package/dist/lib/host-probe.js.map +1 -0
  58. package/dist/lib/run-with-core.js +26 -7
  59. package/dist/lib/run-with-core.js.map +1 -1
  60. package/dist/utils/cli-symbols.d.ts +1 -1
  61. package/dist/utils/command-invocation.d.ts +2 -0
  62. package/dist/utils/command-invocation.js +9 -0
  63. package/dist/utils/command-invocation.js.map +1 -1
  64. package/dist/utils/debug.d.ts +1 -0
  65. package/dist/utils/debug.js +10 -2
  66. package/dist/utils/debug.js.map +1 -1
  67. package/dist/utils/environment.d.ts +6 -0
  68. package/dist/utils/environment.js +8 -16
  69. package/dist/utils/environment.js.map +1 -1
  70. package/dist/utils/exit-codes.d.ts +9 -5
  71. package/dist/utils/exit-codes.js +10 -2
  72. package/dist/utils/exit-codes.js.map +1 -1
  73. package/dist/utils/help-json.d.ts +7 -0
  74. package/dist/utils/help-json.js +101 -0
  75. package/dist/utils/help-json.js.map +1 -1
  76. package/dist/utils/interaction-mode.d.ts +25 -0
  77. package/dist/utils/interaction-mode.js +102 -0
  78. package/dist/utils/interaction-mode.js.map +1 -0
  79. package/dist/utils/output.d.ts +20 -12
  80. package/dist/utils/output.js +16 -4
  81. package/dist/utils/output.js.map +1 -1
  82. package/dist/utils/recovery-hints.d.ts +37 -0
  83. package/dist/utils/recovery-hints.js +80 -0
  84. package/dist/utils/recovery-hints.js.map +1 -0
  85. package/package.json +4 -3
@@ -0,0 +1,102 @@
1
+ const VALID_MODES = ['human', 'agent', 'ci'];
2
+ let currentMode = { mode: 'human', source: 'default' };
3
+ export class InvalidInteractionModeError extends Error {
4
+ value;
5
+ source;
6
+ constructor(value, source) {
7
+ const label = source === 'flag' ? '--mode' : 'WORKOS_MODE';
8
+ super(`${label} must be one of: ${VALID_MODES.join(', ')}`);
9
+ this.value = value;
10
+ this.source = source;
11
+ this.name = 'InvalidInteractionModeError';
12
+ }
13
+ }
14
+ function isTruthy(value) {
15
+ return value === '1' || value?.toLowerCase() === 'true';
16
+ }
17
+ function parseModeValue(value, source) {
18
+ const normalized = value?.toLowerCase();
19
+ if (normalized && VALID_MODES.includes(normalized)) {
20
+ return normalized;
21
+ }
22
+ throw new InvalidInteractionModeError(value, source);
23
+ }
24
+ function parseModeFromArgv(argv) {
25
+ for (let i = 0; i < argv.length; i++) {
26
+ const arg = argv[i];
27
+ if (arg === '--mode') {
28
+ const value = argv[i + 1];
29
+ if (!value || value.startsWith('-')) {
30
+ throw new InvalidInteractionModeError(value, 'flag');
31
+ }
32
+ return parseModeValue(value, 'flag');
33
+ }
34
+ if (arg.startsWith('--mode=')) {
35
+ return parseModeValue(arg.slice('--mode='.length), 'flag');
36
+ }
37
+ }
38
+ return undefined;
39
+ }
40
+ function hasCiMarker(env) {
41
+ return (isTruthy(env.CI) ||
42
+ isTruthy(env.GITHUB_ACTIONS) ||
43
+ isTruthy(env.GITLAB_CI) ||
44
+ isTruthy(env.CIRCLECI) ||
45
+ isTruthy(env.BUILDKITE) ||
46
+ isTruthy(env.TF_BUILD));
47
+ }
48
+ function hasAgentMarker(env) {
49
+ return (isTruthy(env.WORKOS_AGENT) ||
50
+ isTruthy(env.CLAUDECODE) ||
51
+ isTruthy(env.CLAUDE_CODE) ||
52
+ isTruthy(env.CURSOR_AGENT) ||
53
+ isTruthy(env.CODEX_SANDBOX) ||
54
+ env.CURSOR_TRACE_ID !== undefined);
55
+ }
56
+ export function resolveInteractionMode(options = {}) {
57
+ const argv = options.argv ?? [];
58
+ const env = options.env ?? process.env;
59
+ const flagMode = parseModeFromArgv(argv);
60
+ if (flagMode)
61
+ return { mode: flagMode, source: 'flag' };
62
+ if (env.WORKOS_MODE !== undefined) {
63
+ return { mode: parseModeValue(env.WORKOS_MODE, 'env'), source: 'env' };
64
+ }
65
+ if (isTruthy(env.WORKOS_NO_PROMPT)) {
66
+ return { mode: 'agent', source: 'workos_no_prompt' };
67
+ }
68
+ if (hasCiMarker(env)) {
69
+ return { mode: 'ci', source: 'ci_env' };
70
+ }
71
+ if (hasAgentMarker(env)) {
72
+ return { mode: 'agent', source: 'agent_env' };
73
+ }
74
+ const stdoutIsTTY = options.stdoutIsTTY ?? process.stdout.isTTY;
75
+ const stderrIsTTY = options.stderrIsTTY ?? process.stderr.isTTY;
76
+ if (!stdoutIsTTY || !stderrIsTTY) {
77
+ return { mode: 'agent', source: 'non_tty' };
78
+ }
79
+ return { mode: 'human', source: 'default' };
80
+ }
81
+ export function setInteractionMode(info) {
82
+ currentMode = info;
83
+ }
84
+ export function getInteractionMode() {
85
+ return currentMode;
86
+ }
87
+ export function isHumanMode() {
88
+ return currentMode.mode === 'human';
89
+ }
90
+ export function isAgentMode() {
91
+ return currentMode.mode === 'agent';
92
+ }
93
+ export function isCiMode() {
94
+ return currentMode.mode === 'ci';
95
+ }
96
+ export function isPromptAllowed() {
97
+ return isHumanMode();
98
+ }
99
+ export function resetInteractionModeForTests() {
100
+ currentMode = { mode: 'human', source: 'default' };
101
+ }
102
+ //# sourceMappingURL=interaction-mode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interaction-mode.js","sourceRoot":"","sources":["../../src/utils/interaction-mode.ts"],"names":[],"mappings":"AAuBA,MAAM,WAAW,GAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,CAA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kBAAkB;IAChC,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,WAAW;IACzB,OAAO,WAAW,CAAC,IAAI,KAAK,OAAO,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,WAAW;IACzB,OAAO,WAAW,CAAC,IAAI,KAAK,OAAO,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,QAAQ;IACtB,OAAO,WAAW,CAAC,IAAI,KAAK,IAAI,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,eAAe;IAC7B,OAAO,WAAW,EAAE,CAAC;AACvB,CAAC;AAED,MAAM,UAAU,4BAA4B;IAC1C,WAAW,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;AACrD,CAAC","sourcesContent":["export type InteractionMode = 'human' | 'agent' | 'ci';\n\nexport type InteractionModeSource =\n | 'flag'\n | 'env'\n | 'workos_no_prompt'\n | 'ci_env'\n | 'agent_env'\n | 'non_tty'\n | 'default';\n\nexport interface InteractionModeInfo {\n mode: InteractionMode;\n source: InteractionModeSource;\n}\n\nexport interface ResolveInteractionModeOptions {\n argv?: string[];\n env?: NodeJS.ProcessEnv;\n stdoutIsTTY?: boolean;\n stderrIsTTY?: boolean;\n}\n\nconst VALID_MODES: InteractionMode[] = ['human', 'agent', 'ci'];\n\nlet currentMode: InteractionModeInfo = { mode: 'human', source: 'default' };\n\nexport class InvalidInteractionModeError extends Error {\n constructor(\n public readonly value: string | undefined,\n public readonly source: 'flag' | 'env',\n ) {\n const label = source === 'flag' ? '--mode' : 'WORKOS_MODE';\n super(`${label} must be one of: ${VALID_MODES.join(', ')}`);\n this.name = 'InvalidInteractionModeError';\n }\n}\n\nfunction isTruthy(value: string | undefined): boolean {\n return value === '1' || value?.toLowerCase() === 'true';\n}\n\nfunction parseModeValue(value: string | undefined, source: 'flag' | 'env'): InteractionMode {\n const normalized = value?.toLowerCase();\n if (normalized && VALID_MODES.includes(normalized as InteractionMode)) {\n return normalized as InteractionMode;\n }\n throw new InvalidInteractionModeError(value, source);\n}\n\nfunction parseModeFromArgv(argv: string[]): InteractionMode | undefined {\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i];\n if (arg === '--mode') {\n const value = argv[i + 1];\n if (!value || value.startsWith('-')) {\n throw new InvalidInteractionModeError(value, 'flag');\n }\n return parseModeValue(value, 'flag');\n }\n if (arg.startsWith('--mode=')) {\n return parseModeValue(arg.slice('--mode='.length), 'flag');\n }\n }\n\n return undefined;\n}\n\nfunction hasCiMarker(env: NodeJS.ProcessEnv): boolean {\n return (\n isTruthy(env.CI) ||\n isTruthy(env.GITHUB_ACTIONS) ||\n isTruthy(env.GITLAB_CI) ||\n isTruthy(env.CIRCLECI) ||\n isTruthy(env.BUILDKITE) ||\n isTruthy(env.TF_BUILD)\n );\n}\n\nfunction hasAgentMarker(env: NodeJS.ProcessEnv): boolean {\n return (\n isTruthy(env.WORKOS_AGENT) ||\n isTruthy(env.CLAUDECODE) ||\n isTruthy(env.CLAUDE_CODE) ||\n isTruthy(env.CURSOR_AGENT) ||\n isTruthy(env.CODEX_SANDBOX) ||\n env.CURSOR_TRACE_ID !== undefined\n );\n}\n\nexport function resolveInteractionMode(options: ResolveInteractionModeOptions = {}): InteractionModeInfo {\n const argv = options.argv ?? [];\n const env = options.env ?? process.env;\n\n const flagMode = parseModeFromArgv(argv);\n if (flagMode) return { mode: flagMode, source: 'flag' };\n\n if (env.WORKOS_MODE !== undefined) {\n return { mode: parseModeValue(env.WORKOS_MODE, 'env'), source: 'env' };\n }\n\n if (isTruthy(env.WORKOS_NO_PROMPT)) {\n return { mode: 'agent', source: 'workos_no_prompt' };\n }\n\n if (hasCiMarker(env)) {\n return { mode: 'ci', source: 'ci_env' };\n }\n\n if (hasAgentMarker(env)) {\n return { mode: 'agent', source: 'agent_env' };\n }\n\n const stdoutIsTTY = options.stdoutIsTTY ?? process.stdout.isTTY;\n const stderrIsTTY = options.stderrIsTTY ?? process.stderr.isTTY;\n if (!stdoutIsTTY || !stderrIsTTY) {\n return { mode: 'agent', source: 'non_tty' };\n }\n\n return { mode: 'human', source: 'default' };\n}\n\nexport function setInteractionMode(info: InteractionModeInfo): void {\n currentMode = info;\n}\n\nexport function getInteractionMode(): InteractionModeInfo {\n return currentMode;\n}\n\nexport function isHumanMode(): boolean {\n return currentMode.mode === 'human';\n}\n\nexport function isAgentMode(): boolean {\n return currentMode.mode === 'agent';\n}\n\nexport function isCiMode(): boolean {\n return currentMode.mode === 'ci';\n}\n\nexport function isPromptAllowed(): boolean {\n return isHumanMode();\n}\n\nexport function resetInteractionModeForTests(): void {\n currentMode = { mode: 'human', source: 'default' };\n}\n"]}
@@ -1,22 +1,26 @@
1
1
  /**
2
2
  * Output mode system for non-TTY / JSON support.
3
3
  *
4
- * Resolves once at startup, drives all output formatting.
4
+ * Resolves once at startup, drives output formatting only.
5
5
  * In JSON mode: structured JSON to stdout, structured errors to stderr.
6
6
  * In human mode: chalk-formatted output (existing behavior).
7
7
  */
8
8
  import { type TableColumn } from './table.js';
9
+ import type { RecoveryHints } from './recovery-hints.js';
10
+ import type { InteractionModeInfo } from './interaction-mode.js';
9
11
  export type OutputMode = 'human' | 'json';
10
12
  /**
11
13
  * Resolve the output mode based on flags and environment.
12
14
  *
13
15
  * Priority:
14
16
  * 1. Explicit --json flag
15
- * 2. WORKOS_FORCE_TTY env var → human
16
- * 3. Non-TTY auto-detection → json
17
- * 4. Defaulthuman
17
+ * 2. WORKOS_FORCE_TTY env var → human output compatibility
18
+ * 3. WORKOS_NO_PROMPT legacy compatibility → json
19
+ * 4. Non-TTY auto-detection json
20
+ * 5. Default → human
18
21
  */
19
22
  export declare function resolveOutputMode(jsonFlag?: boolean): OutputMode;
23
+ export declare function resolveEffectiveOutputMode(mode: OutputMode, interaction: InteractionModeInfo): OutputMode;
20
24
  export declare function setOutputMode(mode: OutputMode): void;
21
25
  export declare function getOutputMode(): OutputMode;
22
26
  export declare function isJsonMode(): boolean;
@@ -29,17 +33,21 @@ export declare function outputSuccess(message: string, data?: object, options?:
29
33
  message: string;
30
34
  }>;
31
35
  }): void;
32
- /** Write a structured error to stderr. */
33
- export declare function outputError(error: {
36
+ export interface StructuredError {
34
37
  code: string;
35
38
  message: string;
36
39
  details?: unknown;
37
- }): void;
40
+ /**
41
+ * Optional structured recovery metadata for agents.
42
+ *
43
+ * Only include for deterministic recovery paths. Human output prints the
44
+ * first hint as a follow-up line; JSON output serializes the full structure.
45
+ */
46
+ recovery?: RecoveryHints;
47
+ }
48
+ /** Write a structured error to stderr. */
49
+ export declare function outputError(error: StructuredError): void;
38
50
  /** Write tabular data — chalk table in human mode, JSON array in json mode. */
39
51
  export declare function outputTable(columns: TableColumn[], rows: string[][], rawData?: unknown[]): void;
40
52
  /** Exit with a structured error. Writes error then exits with code 1. */
41
- export declare function exitWithError(error: {
42
- code: string;
43
- message: string;
44
- details?: unknown;
45
- }): never;
53
+ export declare function exitWithError(error: StructuredError): never;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Output mode system for non-TTY / JSON support.
3
3
  *
4
- * Resolves once at startup, drives all output formatting.
4
+ * Resolves once at startup, drives output formatting only.
5
5
  * In JSON mode: structured JSON to stdout, structured errors to stderr.
6
6
  * In human mode: chalk-formatted output (existing behavior).
7
7
  */
@@ -13,9 +13,10 @@ let currentMode = 'human';
13
13
  *
14
14
  * Priority:
15
15
  * 1. Explicit --json flag
16
- * 2. WORKOS_FORCE_TTY env var → human
17
- * 3. Non-TTY auto-detection → json
18
- * 4. Defaulthuman
16
+ * 2. WORKOS_FORCE_TTY env var → human output compatibility
17
+ * 3. WORKOS_NO_PROMPT legacy compatibility → json
18
+ * 4. Non-TTY auto-detection json
19
+ * 5. Default → human
19
20
  */
20
21
  export function resolveOutputMode(jsonFlag) {
21
22
  if (jsonFlag)
@@ -28,6 +29,12 @@ export function resolveOutputMode(jsonFlag) {
28
29
  return 'json';
29
30
  return 'human';
30
31
  }
32
+ export function resolveEffectiveOutputMode(mode, interaction) {
33
+ if (interaction.mode === 'human' || interaction.source === 'non_tty') {
34
+ return mode;
35
+ }
36
+ return 'json';
37
+ }
31
38
  export function setOutputMode(mode) {
32
39
  currentMode = mode;
33
40
  if (mode === 'json') {
@@ -73,6 +80,11 @@ export function outputError(error) {
73
80
  }
74
81
  else {
75
82
  console.error(chalk.red(error.message));
83
+ const firstHint = error.recovery?.hints[0];
84
+ if (firstHint) {
85
+ const suffix = firstHint.command ? ` Run: ${firstHint.command}` : '';
86
+ console.error(chalk.dim(`→ ${firstHint.description}${suffix}`));
87
+ }
76
88
  }
77
89
  }
78
90
  /** Write tabular data — chalk table in human mode, JSON array in json mode. */
@@ -1 +1 @@
1
- {"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/utils/output.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAoB,MAAM,YAAY,CAAC;AAI3D,IAAI,WAAW,GAAe,OAAO,CAAC;AAEtC;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAAkB;IAClD,IAAI,QAAQ;QAAE,OAAO,MAAM,CAAC;IAC5B,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,KAAK,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,KAAK,MAAM;QAAE,OAAO,OAAO,CAAC;IACpG,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,KAAK,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,KAAK,MAAM;QAAE,OAAO,MAAM,CAAC;IACnG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK;QAAE,OAAO,MAAM,CAAC;IACzC,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAgB;IAC5C,WAAW,GAAG,IAAI,CAAC;IACnB,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QACpB,KAAK,CAAC,KAAK,GAAG,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;AAED,yEAAyE;AACzE,MAAM,UAAU,aAAa,CAAC,KAA2D;IACvF,WAAW,CAAC,KAAK,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC","sourcesContent":["/**\n * Output mode system for non-TTY / JSON support.\n *\n * Resolves once at startup, drives all output formatting.\n * In JSON mode: structured JSON to stdout, structured errors to stderr.\n * In human mode: chalk-formatted output (existing behavior).\n */\n\nimport chalk from 'chalk';\nimport { formatTable, type TableColumn } from './table.js';\n\nexport type OutputMode = 'human' | 'json';\n\nlet currentMode: OutputMode = 'human';\n\n/**\n * Resolve the output mode based on flags and environment.\n *\n * Priority:\n * 1. Explicit --json flag\n * 2. WORKOS_FORCE_TTY env var → human\n * 3. Non-TTY auto-detection → json\n * 4. Default → human\n */\nexport function resolveOutputMode(jsonFlag?: boolean): OutputMode {\n if (jsonFlag) return 'json';\n if (process.env.WORKOS_FORCE_TTY === '1' || process.env.WORKOS_FORCE_TTY === 'true') return 'human';\n if (process.env.WORKOS_NO_PROMPT === '1' || process.env.WORKOS_NO_PROMPT === 'true') return 'json';\n if (!process.stdout.isTTY) return 'json';\n return 'human';\n}\n\nexport function setOutputMode(mode: OutputMode): void {\n currentMode = mode;\n if (mode === 'json') {\n chalk.level = 0;\n }\n}\n\nexport function getOutputMode(): OutputMode {\n return currentMode;\n}\n\nexport function isJsonMode(): boolean {\n return currentMode === 'json';\n}\n\n/** Write structured JSON to stdout (one line, no pretty-print). */\nexport function outputJson(data: unknown): void {\n console.log(JSON.stringify(data));\n}\n\n/** Write a success result — chalk in human mode, JSON in json mode. */\nexport function outputSuccess(\n message: string,\n data?: object,\n options?: { warnings?: Array<{ code: string; message: string }> },\n): void {\n if (currentMode === 'json') {\n const result: Record<string, unknown> = { status: 'ok', message };\n if (data) result.data = data;\n if (options?.warnings?.length) result.warnings = options.warnings;\n console.log(JSON.stringify(result));\n } else {\n console.log(chalk.green(message));\n if (data) {\n console.log(JSON.stringify(data, null, 2));\n }\n if (options?.warnings?.length) {\n for (const w of options.warnings) {\n console.error(chalk.yellow(w.message));\n }\n }\n }\n}\n\n/** Write a structured error to stderr. */\nexport function outputError(error: { code: string; message: string; details?: unknown }): void {\n if (currentMode === 'json') {\n console.error(JSON.stringify({ error }));\n } else {\n console.error(chalk.red(error.message));\n }\n}\n\n/** Write tabular data — chalk table in human mode, JSON array in json mode. */\nexport function outputTable(columns: TableColumn[], rows: string[][], rawData?: unknown[]): void {\n if (currentMode === 'json') {\n if (rawData) {\n console.log(JSON.stringify(rawData));\n } else {\n const headers = columns.map((c) => c.header);\n const jsonRows = rows.map((row) => {\n const obj: Record<string, string> = {};\n headers.forEach((h, i) => {\n obj[h] = row[i] ?? '';\n });\n return obj;\n });\n console.log(JSON.stringify(jsonRows));\n }\n } else {\n console.log(formatTable(columns, rows));\n }\n}\n\n/** Exit with a structured error. Writes error then exits with code 1. */\nexport function exitWithError(error: { code: string; message: string; details?: unknown }): never {\n outputError(error);\n process.exit(1);\n}\n"]}
1
+ {"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/utils/output.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAoB,MAAM,YAAY,CAAC;AAM3D,IAAI,WAAW,GAAe,OAAO,CAAC;AAEtC;;;;;;;;;GASG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAAkB;IAClD,IAAI,QAAQ;QAAE,OAAO,MAAM,CAAC;IAC5B,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,KAAK,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,KAAK,MAAM;QAAE,OAAO,OAAO,CAAC;IACpG,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,KAAK,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,KAAK,MAAM;QAAE,OAAO,MAAM,CAAC;IACnG,IAAI,CAAC,OAAO,CA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AC;QAC3B,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;QACvC,CAAC;aAAM,CAAC;YACN,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;YAC7C,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;gBAChC,MAAM,GAAG,GAA2B,EAAE,CAAC;gBACvC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;oBACvB,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;gBACxB,CAAC,CAAC,CAAC;gBACH,OAAO,GAAG,CAAC;YACb,CAAC,CAAC,CAAC;YACH,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;IAC1C,CAAC;AACH,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,aAAa,CAAC,KAAsB;IAClD,WAAW,CAAC,KAAK,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC","sourcesContent":["/**\n * Output mode system for non-TTY / JSON support.\n *\n * Resolves once at startup, drives output formatting only.\n * In JSON mode: structured JSON to stdout, structured errors to stderr.\n * In human mode: chalk-formatted output (existing behavior).\n */\n\nimport chalk from 'chalk';\nimport { formatTable, type TableColumn } from './table.js';\nimport type { RecoveryHints } from './recovery-hints.js';\nimport type { InteractionModeInfo } from './interaction-mode.js';\n\nexport type OutputMode = 'human' | 'json';\n\nlet currentMode: OutputMode = 'human';\n\n/**\n * Resolve the output mode based on flags and environment.\n *\n * Priority:\n * 1. Explicit --json flag\n * 2. WORKOS_FORCE_TTY env var → human output compatibility\n * 3. WORKOS_NO_PROMPT legacy compatibility → json\n * 4. Non-TTY auto-detection → json\n * 5. Default → human\n */\nexport function resolveOutputMode(jsonFlag?: boolean): OutputMode {\n if (jsonFlag) return 'json';\n if (process.env.WORKOS_FORCE_TTY === '1' || process.env.WORKOS_FORCE_TTY === 'true') return 'human';\n if (process.env.WORKOS_NO_PROMPT === '1' || process.env.WORKOS_NO_PROMPT === 'true') return 'json';\n if (!process.stdout.isTTY) return 'json';\n return 'human';\n}\n\nexport function resolveEffectiveOutputMode(mode: OutputMode, interaction: InteractionModeInfo): OutputMode {\n if (interaction.mode === 'human' || interaction.source === 'non_tty') {\n return mode;\n }\n return 'json';\n}\n\nexport function setOutputMode(mode: OutputMode): void {\n currentMode = mode;\n if (mode === 'json') {\n chalk.level = 0;\n }\n}\n\nexport function getOutputMode(): OutputMode {\n return currentMode;\n}\n\nexport function isJsonMode(): boolean {\n return currentMode === 'json';\n}\n\n/** Write structured JSON to stdout (one line, no pretty-print). */\nexport function outputJson(data: unknown): void {\n console.log(JSON.stringify(data));\n}\n\n/** Write a success result — chalk in human mode, JSON in json mode. */\nexport function outputSuccess(\n message: string,\n data?: object,\n options?: { warnings?: Array<{ code: string; message: string }> },\n): void {\n if (currentMode === 'json') {\n const result: Record<string, unknown> = { status: 'ok', message };\n if (data) result.data = data;\n if (options?.warnings?.length) result.warnings = options.warnings;\n console.log(JSON.stringify(result));\n } else {\n console.log(chalk.green(message));\n if (data) {\n console.log(JSON.stringify(data, null, 2));\n }\n if (options?.warnings?.length) {\n for (const w of options.warnings) {\n console.error(chalk.yellow(w.message));\n }\n }\n }\n}\n\nexport interface StructuredError {\n code: string;\n message: string;\n details?: unknown;\n /**\n * Optional structured recovery metadata for agents.\n *\n * Only include for deterministic recovery paths. Human output prints the\n * first hint as a follow-up line; JSON output serializes the full structure.\n */\n recovery?: RecoveryHints;\n}\n\n/** Write a structured error to stderr. */\nexport function outputError(error: StructuredError): void {\n if (currentMode === 'json') {\n console.error(JSON.stringify({ error }));\n } else {\n console.error(chalk.red(error.message));\n const firstHint = error.recovery?.hints[0];\n if (firstHint) {\n const suffix = firstHint.command ? ` Run: ${firstHint.command}` : '';\n console.error(chalk.dim(`→ ${firstHint.description}${suffix}`));\n }\n }\n}\n\n/** Write tabular data — chalk table in human mode, JSON array in json mode. */\nexport function outputTable(columns: TableColumn[], rows: string[][], rawData?: unknown[]): void {\n if (currentMode === 'json') {\n if (rawData) {\n console.log(JSON.stringify(rawData));\n } else {\n const headers = columns.map((c) => c.header);\n const jsonRows = rows.map((row) => {\n const obj: Record<string, string> = {};\n headers.forEach((h, i) => {\n obj[h] = row[i] ?? '';\n });\n return obj;\n });\n console.log(JSON.stringify(jsonRows));\n }\n } else {\n console.log(formatTable(columns, rows));\n }\n}\n\n/** Exit with a structured error. Writes error then exits with code 1. */\nexport function exitWithError(error: StructuredError): never {\n outputError(error);\n process.exit(1);\n}\n"]}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Recovery hints for structured CLI errors.
3
+ *
4
+ * Recovery metadata is consumed by coding agents through JSON stderr output.
5
+ * Hints describe the deterministic next step the caller can take to fix the
6
+ * failure: the exact command to run, whether host shell access is required,
7
+ * and (optionally) related docs links.
8
+ *
9
+ * Keep hints conservative: only include `command` when the next action is
10
+ * unambiguous and safe. When the correct next step depends on user intent,
11
+ * provide `description` only.
12
+ */
13
+ import type { InteractionMode } from './interaction-mode.js';
14
+ export interface RecoveryHint {
15
+ /** Human-readable next step for both humans and agents. */
16
+ description: string;
17
+ /** Exact command to run, when deterministic. */
18
+ command?: string;
19
+ /** True when the command must run on the user's host shell, not in the current sandbox. */
20
+ hostShellRequired?: boolean;
21
+ /** Optional documentation URL. */
22
+ docsUrl?: string;
23
+ /** Optional markdown-capable documentation URL. Only set when route support is verified. */
24
+ docsMarkdownUrl?: string;
25
+ }
26
+ export interface RecoveryHints {
27
+ hints: RecoveryHint[];
28
+ }
29
+ /** Build mode-aware recovery hints for `auth_required` errors. */
30
+ export declare function authLoginRecovery(options: {
31
+ mode: InteractionMode;
32
+ env?: NodeJS.ProcessEnv;
33
+ }): RecoveryHints;
34
+ /** Build a `confirmation_required` recovery hint, attaching a command only when the exact rerun is known. */
35
+ export declare function confirmationRecovery(command?: string): RecoveryHints;
36
+ /** Build a `missing_args` recovery hint, attaching a command only when it is directly runnable. */
37
+ export declare function missingArgsRecovery(command: string | undefined, description: string): RecoveryHints;
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Recovery hints for structured CLI errors.
3
+ *
4
+ * Recovery metadata is consumed by coding agents through JSON stderr output.
5
+ * Hints describe the deterministic next step the caller can take to fix the
6
+ * failure: the exact command to run, whether host shell access is required,
7
+ * and (optionally) related docs links.
8
+ *
9
+ * Keep hints conservative: only include `command` when the next action is
10
+ * unambiguous and safe. When the correct next step depends on user intent,
11
+ * provide `description` only.
12
+ */
13
+ import { formatWorkOSCommand } from './command-invocation.js';
14
+ /** Build mode-aware recovery hints for `auth_required` errors. */
15
+ export function authLoginRecovery(options) {
16
+ const env = options.env ?? process.env;
17
+ const loginCommand = formatWorkOSCommand('auth login', env);
18
+ if (options.mode === 'ci') {
19
+ return {
20
+ hints: [
21
+ {
22
+ description: 'Set WORKOS_API_KEY in the CI environment.',
23
+ },
24
+ {
25
+ description: 'Or refresh stored credentials before the CI run.',
26
+ command: loginCommand,
27
+ hostShellRequired: true,
28
+ },
29
+ ],
30
+ };
31
+ }
32
+ if (options.mode === 'agent') {
33
+ return {
34
+ hints: [
35
+ {
36
+ description: "Authenticate on the user's host shell.",
37
+ command: loginCommand,
38
+ hostShellRequired: true,
39
+ },
40
+ {
41
+ description: 'Or set WORKOS_API_KEY before invoking the CLI.',
42
+ },
43
+ ],
44
+ };
45
+ }
46
+ return {
47
+ hints: [
48
+ {
49
+ description: 'Authenticate via browser-based device login.',
50
+ command: loginCommand,
51
+ },
52
+ {
53
+ description: 'Or set WORKOS_API_KEY.',
54
+ },
55
+ ],
56
+ };
57
+ }
58
+ /** Build a `confirmation_required` recovery hint, attaching a command only when the exact rerun is known. */
59
+ export function confirmationRecovery(command) {
60
+ return {
61
+ hints: [
62
+ {
63
+ description: 'Re-run with explicit confirmation.',
64
+ ...(command && { command }),
65
+ },
66
+ ],
67
+ };
68
+ }
69
+ /** Build a `missing_args` recovery hint, attaching a command only when it is directly runnable. */
70
+ export function missingArgsRecovery(command, description) {
71
+ return {
72
+ hints: [
73
+ {
74
+ description,
75
+ ...(command && { command }),
76
+ },
77
+ ],
78
+ };
79
+ }
80
+ //# sourceMappingURL=recovery-hints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recovery-hints.js","sourceRoot":"","sources":["../../src/utils/recovery-hints.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAmB9D,kEAAkE;AAClE,MAAM,UAAU,iBAAiB,CAAC,OAA2D;IAC3F,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC;IACvC,MAAM,YAAY,GAAG,mBAAmB,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC;IAE5D,IAAI,OAAO,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;QAC1B,OAAO;YACL,KAAK,EAAE;gBACL;oBACE,WAAW,EAAE,2CAA2C;iBACzD;gBACD;oBACE,WAAW,EAAE,kDAAkD;oBAC/D,OAAO,EAAE,YAAY;oBACrB,iBAAiB,EAAE,IAAI;iBACxB;aACF;SACF,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC7B,OAAO;YACL,KAAK,EAAE;gBACL;oBACE,WAAW,EAAE,wCAAwC;oBACrD,OAAO,EAAE,YAAY;oBACrB,iBAAiB,EAAE,IAAI;iBACxB;gBACD;oBACE,WAAW,EAAE,gDAAgD;iBAC9D;aACF;SACF,CAAC;IACJ,CAAC;IAED,OAAO;QACL,KAAK,EAAE;YACL;gBACE,WAAW,EAAE,8CAA8C;gBAC3D,OAAO,EAAE,YAAY;aACtB;YACD;gBACE,WAAW,EAAE,wBAAwB;aACtC;SACF;KACF,CAAC;AACJ,CAAC;AAED,6GAA6G;AAC7G,MAAM,UAAU,oBAAoB,CAAC,OAAgB;IACnD,OAAO;QACL,KAAK,EAAE;YACL;gBACE,WAAW,EAAE,oCAAoC;gBACjD,GAAG,CAAC,OAAO,IAAI,EAAE,OAAO,EAAE,CAAC;aAC5B;SACF;KACF,CAAC;AACJ,CAAC;AAED,mGAAmG;AACnG,MAAM,UAAU,mBAAmB,CAAC,OAA2B,EAAE,WAAmB;IAClF,OAAO;QACL,KAAK,EAAE;YACL;gBACE,WAAW;gBACX,GAAG,CAAC,OAAO,IAAI,EAAE,OAAO,EAAE,CAAC;aAC5B;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Recovery hints for structured CLI errors.\n *\n * Recovery metadata is consumed by coding agents through JSON stderr output.\n * Hints describe the deterministic next step the caller can take to fix the\n * failure: the exact command to run, whether host shell access is required,\n * and (optionally) related docs links.\n *\n * Keep hints conservative: only include `command` when the next action is\n * unambiguous and safe. When the correct next step depends on user intent,\n * provide `description` only.\n */\n\nimport type { InteractionMode } from './interaction-mode.js';\nimport { formatWorkOSCommand } from './command-invocation.js';\n\nexport interface RecoveryHint {\n /** Human-readable next step for both humans and agents. */\n description: string;\n /** Exact command to run, when deterministic. */\n command?: string;\n /** True when the command must run on the user's host shell, not in the current sandbox. */\n hostShellRequired?: boolean;\n /** Optional documentation URL. */\n docsUrl?: string;\n /** Optional markdown-capable documentation URL. Only set when route support is verified. */\n docsMarkdownUrl?: string;\n}\n\nexport interface RecoveryHints {\n hints: RecoveryHint[];\n}\n\n/** Build mode-aware recovery hints for `auth_required` errors. */\nexport function authLoginRecovery(options: { mode: InteractionMode; env?: NodeJS.ProcessEnv }): RecoveryHints {\n const env = options.env ?? process.env;\n const loginCommand = formatWorkOSCommand('auth login', env);\n\n if (options.mode === 'ci') {\n return {\n hints: [\n {\n description: 'Set WORKOS_API_KEY in the CI environment.',\n },\n {\n description: 'Or refresh stored credentials before the CI run.',\n command: loginCommand,\n hostShellRequired: true,\n },\n ],\n };\n }\n\n if (options.mode === 'agent') {\n return {\n hints: [\n {\n description: \"Authenticate on the user's host shell.\",\n command: loginCommand,\n hostShellRequired: true,\n },\n {\n description: 'Or set WORKOS_API_KEY before invoking the CLI.',\n },\n ],\n };\n }\n\n return {\n hints: [\n {\n description: 'Authenticate via browser-based device login.',\n command: loginCommand,\n },\n {\n description: 'Or set WORKOS_API_KEY.',\n },\n ],\n };\n}\n\n/** Build a `confirmation_required` recovery hint, attaching a command only when the exact rerun is known. */\nexport function confirmationRecovery(command?: string): RecoveryHints {\n return {\n hints: [\n {\n description: 'Re-run with explicit confirmation.',\n ...(command && { command }),\n },\n ],\n };\n}\n\n/** Build a `missing_args` recovery hint, attaching a command only when it is directly runnable. */\nexport function missingArgsRecovery(command: string | undefined, description: string): RecoveryHints {\n return {\n hints: [\n {\n description,\n ...(command && { command }),\n },\n ],\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "workos",
3
- "version": "0.13.4",
3
+ "version": "0.14.0",
4
4
  "type": "module",
5
5
  "description": "The Official Workos CLI",
6
6
  "repository": {
@@ -49,20 +49,21 @@
49
49
  "@anthropic-ai/sdk": "^0.78.0",
50
50
  "@clack/core": "^1.0.1",
51
51
  "@clack/prompts": "1.0.1",
52
+ "@hono/node-server": "^1",
52
53
  "@napi-rs/keyring": "^1.2.0",
53
54
  "@workos-inc/node": "^8.7.0",
55
+ "@workos/openapi-spec": "^0.1.0",
54
56
  "@workos/skills": "0.5.0",
55
57
  "chalk": "^5.6.2",
56
58
  "diff": "^8.0.3",
57
59
  "fast-glob": "^3.3.3",
60
+ "hono": "^4",
58
61
  "ink": "^6.8.0",
59
62
  "opn": "^5.4.0",
60
63
  "react": "^19.2.4",
61
64
  "semver": "^7.7.4",
62
65
  "uuid": "^13.0.0",
63
66
  "xstate": "^5.28.0",
64
- "hono": "^4",
65
- "@hono/node-server": "^1",
66
67
  "yaml": "^2.8.2",
67
68
  "yargs": "^18.0.0",
68
69
  "zod": "^4.3.6"