@outputai/cli 0.2.1-next.bd54540.0 → 0.2.1-next.e1a91cf.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 (41) hide show
  1. package/bin/run.js +2 -2
  2. package/dist/api/generated/api.d.ts +21 -5
  3. package/dist/api/generated/api.js +1 -1
  4. package/dist/assets/docker/docker-compose-dev.yml +5 -9
  5. package/dist/commands/dev/index.js +12 -1
  6. package/dist/commands/init.d.ts +1 -0
  7. package/dist/commands/init.js +5 -1
  8. package/dist/commands/init.spec.js +10 -5
  9. package/dist/commands/workflow/run.d.ts +1 -1
  10. package/dist/commands/workflow/run.js +8 -5
  11. package/dist/commands/workflow/run.spec.js +3 -3
  12. package/dist/commands/workflow/runs/list.d.ts +1 -0
  13. package/dist/commands/workflow/runs/list.js +7 -0
  14. package/dist/commands/workflow/start.d.ts +1 -1
  15. package/dist/commands/workflow/start.js +8 -5
  16. package/dist/commands/workflow/start.spec.js +1 -1
  17. package/dist/config.d.ts +5 -0
  18. package/dist/config.js +13 -1
  19. package/dist/config.spec.js +54 -0
  20. package/dist/generated/framework_version.json +1 -1
  21. package/dist/hooks/init.d.ts +4 -0
  22. package/dist/hooks/init.js +14 -2
  23. package/dist/hooks/init.spec.js +79 -5
  24. package/dist/services/docker.js +5 -2
  25. package/dist/services/docker.spec.js +74 -3
  26. package/dist/services/messages.js +2 -1
  27. package/dist/services/project_scaffold.d.ts +1 -1
  28. package/dist/services/project_scaffold.js +16 -1
  29. package/dist/services/workflow_runs.d.ts +1 -0
  30. package/dist/services/workflow_runs.js +3 -0
  31. package/dist/templates/project/.env.example.template +17 -0
  32. package/dist/utils/credentials_loader.d.ts +1 -0
  33. package/dist/utils/credentials_loader.js +18 -0
  34. package/dist/utils/credentials_loader.spec.d.ts +1 -0
  35. package/dist/utils/credentials_loader.spec.js +84 -0
  36. package/dist/utils/validation.d.ts +13 -0
  37. package/dist/utils/validation.js +31 -0
  38. package/dist/utils/validation.spec.js +47 -1
  39. package/dist/views/dev.js +3 -3
  40. package/dist/views/workflow/list.js +10 -8
  41. package/package.json +10 -10
@@ -1,9 +1,13 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { describe, it, expect, beforeEach, vi } from 'vitest';
2
+ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
3
3
  import { checkForUpdate } from '#services/version_check.js';
4
+ import { setNonInteractive } from '#utils/interactive.js';
4
5
  vi.mock('#services/version_check.js', () => ({
5
6
  checkForUpdate: vi.fn()
6
7
  }));
8
+ vi.mock('#utils/interactive.js', () => ({
9
+ setNonInteractive: vi.fn()
10
+ }));
7
11
  vi.mock('@oclif/core', () => ({
8
12
  ux: {
9
13
  stdout: vi.fn(),
@@ -11,7 +15,7 @@ vi.mock('@oclif/core', () => ({
11
15
  }
12
16
  }));
13
17
  import { ux } from '@oclif/core';
14
- import hook from './init.js';
18
+ import hook, { hasInteractiveFlag, stripGlobalFlags } from './init.js';
15
19
  describe('init hook', () => {
16
20
  beforeEach(() => {
17
21
  vi.clearAllMocks();
@@ -26,7 +30,7 @@ describe('init hook', () => {
26
30
  latestVersion: '1.0.0'
27
31
  });
28
32
  const ctx = createHookContext();
29
- await hook.call(ctx, {});
33
+ await hook.call(ctx, { argv: [], id: undefined });
30
34
  expect(checkForUpdate).toHaveBeenCalledWith('0.8.4', '/tmp/test-cache');
31
35
  expect(ux.stdout).toHaveBeenCalled();
32
36
  const output = vi.mocked(ux.stdout).mock.calls.map(c => c[0]).join('\n');
@@ -42,13 +46,83 @@ describe('init hook', () => {
42
46
  latestVersion: '0.8.4'
43
47
  });
44
48
  const ctx = createHookContext();
45
- await hook.call(ctx, {});
49
+ await hook.call(ctx, { argv: [], id: undefined });
46
50
  expect(ux.stdout).not.toHaveBeenCalled();
47
51
  });
48
52
  it('should silently handle errors', async () => {
49
53
  vi.mocked(checkForUpdate).mockRejectedValue(new Error('network failure'));
50
54
  const ctx = createHookContext();
51
- await hook.call(ctx, {});
55
+ await hook.call(ctx, { argv: [], id: undefined });
52
56
  expect(ux.stdout).not.toHaveBeenCalled();
53
57
  });
58
+ describe('global interactive flags', () => {
59
+ const originalArgv = process.argv;
60
+ beforeEach(() => {
61
+ vi.mocked(checkForUpdate).mockResolvedValue({
62
+ updateAvailable: false,
63
+ currentVersion: '0.8.4',
64
+ latestVersion: '0.8.4'
65
+ });
66
+ });
67
+ afterEach(() => {
68
+ process.argv = originalArgv;
69
+ });
70
+ it('should mutate opts.argv in place to strip --yes', async () => {
71
+ process.argv = ['node', 'run.js', 'init', '--yes', 'my-project'];
72
+ const optsArgv = ['--yes', 'my-project'];
73
+ const argvRef = optsArgv;
74
+ const ctx = createHookContext();
75
+ await hook.call(ctx, { argv: optsArgv, id: 'init' });
76
+ expect(setNonInteractive).toHaveBeenCalledWith(true);
77
+ expect(optsArgv).toBe(argvRef);
78
+ expect(optsArgv).toEqual(['my-project']);
79
+ expect(process.argv).toEqual(['node', 'run.js', 'init', 'my-project']);
80
+ });
81
+ it('should mutate opts.argv in place to strip --non-interactive', async () => {
82
+ process.argv = ['node', 'run.js', 'init', '--non-interactive'];
83
+ const optsArgv = ['--non-interactive'];
84
+ const ctx = createHookContext();
85
+ await hook.call(ctx, { argv: optsArgv, id: 'init' });
86
+ expect(setNonInteractive).toHaveBeenCalledWith(true);
87
+ expect(optsArgv).toEqual([]);
88
+ expect(process.argv).toEqual(['node', 'run.js', 'init']);
89
+ });
90
+ it('should leave argv untouched when no global flag is present', async () => {
91
+ process.argv = ['node', 'run.js', 'init', '--skip-env'];
92
+ const optsArgv = ['--skip-env'];
93
+ const ctx = createHookContext();
94
+ await hook.call(ctx, { argv: optsArgv, id: 'init' });
95
+ expect(setNonInteractive).not.toHaveBeenCalled();
96
+ expect(optsArgv).toEqual(['--skip-env']);
97
+ expect(process.argv).toEqual(['node', 'run.js', 'init', '--skip-env']);
98
+ });
99
+ });
100
+ describe('hasInteractiveFlag', () => {
101
+ it('returns true when --yes is present', () => {
102
+ expect(hasInteractiveFlag(['init', '--yes', 'foo'])).toBe(true);
103
+ });
104
+ it('returns true when --non-interactive is present', () => {
105
+ expect(hasInteractiveFlag(['--non-interactive'])).toBe(true);
106
+ });
107
+ it('returns false for unrelated flags', () => {
108
+ expect(hasInteractiveFlag(['init', '--skip-env', '--skip-git'])).toBe(false);
109
+ });
110
+ it('returns false for an empty argv', () => {
111
+ expect(hasInteractiveFlag([])).toBe(false);
112
+ });
113
+ });
114
+ describe('stripGlobalFlags', () => {
115
+ it('mutates argv in place to remove global flags', () => {
116
+ const argv = ['init', '--yes', 'foo', '--non-interactive'];
117
+ const ref = argv;
118
+ stripGlobalFlags(argv);
119
+ expect(argv).toBe(ref);
120
+ expect(argv).toEqual(['init', 'foo']);
121
+ });
122
+ it('leaves argv untouched when no global flag is present', () => {
123
+ const argv = ['init', '--skip-env'];
124
+ stripGlobalFlags(argv);
125
+ expect(argv).toEqual(['init', '--skip-env']);
126
+ });
127
+ });
54
128
  });
@@ -3,6 +3,7 @@ import path from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  import { ux } from '@oclif/core';
5
5
  import semver from 'semver';
6
+ import { config } from '#config.js';
6
7
  const DEFAULT_COMPOSE_PATH = '../assets/docker/docker-compose-dev.yml';
7
8
  export const SERVICE_HEALTH = {
8
9
  HEALTHY: 'healthy',
@@ -100,7 +101,7 @@ export function parseServiceStatus(jsonOutput) {
100
101
  });
101
102
  }
102
103
  export async function getServiceStatus(dockerComposePath) {
103
- const result = execFileSync('docker', ['compose', '-f', dockerComposePath, 'ps', '--all', '--format', 'json'], { encoding: 'utf-8', cwd: process.cwd() });
104
+ const result = execFileSync('docker', ['compose', '-f', dockerComposePath, '--project-name', config.dockerServiceName, 'ps', '--all', '--format', 'json'], { encoding: 'utf-8', cwd: process.cwd() });
104
105
  return parseServiceStatus(result);
105
106
  }
106
107
  export function isServiceHealthy(service) {
@@ -126,6 +127,7 @@ export async function startDockerCompose(dockerComposePath, pullPolicy) {
126
127
  'compose',
127
128
  '-f', dockerComposePath,
128
129
  '--project-directory', process.cwd(),
130
+ '--project-name', config.dockerServiceName,
129
131
  'up'
130
132
  ];
131
133
  if (pullPolicy) {
@@ -143,6 +145,7 @@ export function startDockerComposeDetached(dockerComposePath, pullPolicy) {
143
145
  'compose',
144
146
  '-f', dockerComposePath,
145
147
  '--project-directory', process.cwd(),
148
+ '--project-name', config.dockerServiceName,
146
149
  'up', '-d'
147
150
  ];
148
151
  if (pullPolicy) {
@@ -152,6 +155,6 @@ export function startDockerComposeDetached(dockerComposePath, pullPolicy) {
152
155
  }
153
156
  export async function stopDockerCompose(dockerComposePath) {
154
157
  ux.stdout('⏹️ Stopping services...\n');
155
- execFileSync('docker', ['compose', '-f', dockerComposePath, 'down'], { stdio: 'inherit', cwd: process.cwd() });
158
+ execFileSync('docker', ['compose', '-f', dockerComposePath, '--project-directory', process.cwd(), '--project-name', config.dockerServiceName, 'down'], { stdio: 'inherit', cwd: process.cwd() });
156
159
  }
157
160
  export { isDockerInstalled, DockerValidationError };
@@ -1,6 +1,6 @@
1
1
  import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
- import { execFileSync } from 'node:child_process';
3
- import { parseServiceStatus, getServiceStatus, waitForServicesHealthy, isServiceHealthy, isServiceFailed } from './docker.js';
2
+ import { execFileSync, spawn } from 'node:child_process';
3
+ import { parseServiceStatus, getServiceStatus, startDockerCompose, startDockerComposeDetached, stopDockerCompose, waitForServicesHealthy, isServiceHealthy, isServiceFailed } from './docker.js';
4
4
  vi.mock('node:child_process', () => ({
5
5
  execSync: vi.fn(),
6
6
  execFileSync: vi.fn(),
@@ -73,7 +73,7 @@ describe('docker service', () => {
73
73
  const mockOutput = '{"Service":"redis","State":"running","Health":"healthy","Publishers":[]}';
74
74
  vi.mocked(execFileSync).mockReturnValue(mockOutput);
75
75
  await getServiceStatus('/path/to/docker-compose.yml');
76
- expect(execFileSync).toHaveBeenCalledWith('docker', ['compose', '-f', '/path/to/docker-compose.yml', 'ps', '--all', '--format', 'json'], expect.objectContaining({ encoding: 'utf-8' }));
76
+ expect(execFileSync).toHaveBeenCalledWith('docker', ['compose', '-f', '/path/to/docker-compose.yml', '--project-name', 'output-sdk', 'ps', '--all', '--format', 'json'], expect.objectContaining({ encoding: 'utf-8' }));
77
77
  });
78
78
  it('should return parsed service status', async () => {
79
79
  const mockOutput = '{"Service":"redis","State":"running","Health":"healthy","Publishers":[{"PublishedPort":6379,"TargetPort":6379}]}';
@@ -89,6 +89,77 @@ describe('docker service', () => {
89
89
  await expect(getServiceStatus('/path/to/docker-compose.yml')).rejects.toThrow();
90
90
  });
91
91
  });
92
+ describe('startDockerCompose', () => {
93
+ it('should pass --project-name to docker compose up', async () => {
94
+ await startDockerCompose('/path/to/docker-compose.yml');
95
+ expect(spawn).toHaveBeenCalledWith('docker', [
96
+ 'compose', '-f', '/path/to/docker-compose.yml',
97
+ '--project-directory', process.cwd(),
98
+ '--project-name', 'output-sdk',
99
+ 'up'
100
+ ], expect.objectContaining({ stdio: ['ignore', 'pipe', 'pipe'], cwd: process.cwd() }));
101
+ });
102
+ it('should append --pull when pullPolicy is provided', async () => {
103
+ await startDockerCompose('/path/to/docker-compose.yml', 'always');
104
+ expect(spawn).toHaveBeenCalledWith('docker', [
105
+ 'compose', '-f', '/path/to/docker-compose.yml',
106
+ '--project-directory', process.cwd(),
107
+ '--project-name', 'output-sdk',
108
+ 'up', '--pull', 'always'
109
+ ], expect.objectContaining({ stdio: ['ignore', 'pipe', 'pipe'], cwd: process.cwd() }));
110
+ });
111
+ });
112
+ describe('startDockerComposeDetached', () => {
113
+ it('should pass --project-name and -d to docker compose up', () => {
114
+ vi.mocked(execFileSync).mockReturnValue('');
115
+ startDockerComposeDetached('/path/to/docker-compose.yml');
116
+ expect(execFileSync).toHaveBeenCalledWith('docker', [
117
+ 'compose', '-f', '/path/to/docker-compose.yml',
118
+ '--project-directory', process.cwd(),
119
+ '--project-name', 'output-sdk',
120
+ 'up', '-d'
121
+ ], expect.objectContaining({ stdio: 'inherit', cwd: process.cwd() }));
122
+ });
123
+ it('should append --pull when pullPolicy is provided', () => {
124
+ vi.mocked(execFileSync).mockReturnValue('');
125
+ startDockerComposeDetached('/path/to/docker-compose.yml', 'missing');
126
+ expect(execFileSync).toHaveBeenCalledWith('docker', [
127
+ 'compose', '-f', '/path/to/docker-compose.yml',
128
+ '--project-directory', process.cwd(),
129
+ '--project-name', 'output-sdk',
130
+ 'up', '-d', '--pull', 'missing'
131
+ ], expect.objectContaining({ stdio: 'inherit', cwd: process.cwd() }));
132
+ });
133
+ });
134
+ describe('DOCKER_SERVICE_NAME wiring', () => {
135
+ const saved = process.env.DOCKER_SERVICE_NAME;
136
+ afterEach(() => {
137
+ if (saved === undefined) {
138
+ delete process.env.DOCKER_SERVICE_NAME;
139
+ }
140
+ else {
141
+ process.env.DOCKER_SERVICE_NAME = saved;
142
+ }
143
+ });
144
+ it('threads DOCKER_SERVICE_NAME through to --project-name (not hardcoded output-sdk)', async () => {
145
+ process.env.DOCKER_SERVICE_NAME = 'custom-project';
146
+ vi.mocked(execFileSync).mockReturnValue('');
147
+ await stopDockerCompose('/path/to/docker-compose.yml');
148
+ expect(execFileSync).toHaveBeenCalledWith('docker', [
149
+ 'compose', '-f', '/path/to/docker-compose.yml',
150
+ '--project-directory', process.cwd(),
151
+ '--project-name', 'custom-project',
152
+ 'down'
153
+ ], expect.objectContaining({ stdio: 'inherit' }));
154
+ });
155
+ });
156
+ describe('stopDockerCompose', () => {
157
+ it('should pass --project-name and --project-directory to docker compose down', async () => {
158
+ vi.mocked(execFileSync).mockReturnValue('');
159
+ await stopDockerCompose('/path/to/docker-compose.yml');
160
+ expect(execFileSync).toHaveBeenCalledWith('docker', ['compose', '-f', '/path/to/docker-compose.yml', '--project-directory', process.cwd(), '--project-name', 'output-sdk', 'down'], expect.objectContaining({ stdio: 'inherit' }));
161
+ });
162
+ });
92
163
  describe('isServiceHealthy', () => {
93
164
  it('should return true for a running service with health: healthy', () => {
94
165
  expect(isServiceHealthy({ name: 'redis', state: 'running', health: 'healthy', ports: [] })).toBe(true);
@@ -2,6 +2,7 @@
2
2
  * Success and informational messages for project initialization
3
3
  */
4
4
  import { ux } from '@oclif/core';
5
+ import { config } from '#config.js';
5
6
  /**
6
7
  * Creates a colored ASCII art banner for Output.ai
7
8
  */
@@ -180,7 +181,7 @@ export const getProjectSuccessMessage = (folderName, installSuccess, credentials
180
181
  note: 'Execute in a new terminal after services are running'
181
182
  }, {
182
183
  step: 'Monitor workflows',
183
- command: 'open http://localhost:8080',
184
+ command: `open ${config.temporalUiUrl}`,
184
185
  note: 'Access Temporal UI for workflow visualization'
185
186
  });
186
187
  // Format each step with proper indentation and colors
@@ -27,5 +27,5 @@ export declare function createSigintHandler(projectPath: string, folderCreated:
27
27
  * @param skipEnv - Whether to skip environment configuration prompts
28
28
  * @param folderName - Optional folder name to skip folder name prompt
29
29
  */
30
- export declare function runInit(skipEnv?: boolean, folderName?: string): Promise<void>;
30
+ export declare function runInit(skipEnv?: boolean, skipGit?: boolean, folderName?: string): Promise<void>;
31
31
  export {};
@@ -119,6 +119,18 @@ async function executeNpmInstall(projectPath) {
119
119
  async function initializeAgents(projectPath) {
120
120
  await initializeAgentConfig({ projectRoot: projectPath, force: false });
121
121
  }
122
+ async function maybeInitializeGit(projectPath) {
123
+ const shouldInit = await confirm({
124
+ message: 'Initialize a git repository?',
125
+ default: true
126
+ });
127
+ if (!shouldInit) {
128
+ return false;
129
+ }
130
+ return executeCommandWithMessages(async () => {
131
+ await executeCommand('git', ['init'], projectPath);
132
+ }, 'Initializing git repository...', 'Git repository initialized');
133
+ }
122
134
  /**
123
135
  * Format error message for init errors
124
136
  * Single responsibility: only format error messages, no cleanup logic
@@ -172,7 +184,7 @@ function handleRunInitError(error, projectPath, projectFolderCreated) {
172
184
  * @param skipEnv - Whether to skip environment configuration prompts
173
185
  * @param folderName - Optional folder name to skip folder name prompt
174
186
  */
175
- export async function runInit(skipEnv = false, folderName) {
187
+ export async function runInit(skipEnv = false, skipGit = false, folderName) {
176
188
  // Track state for SIGINT cleanup using an object to avoid let
177
189
  const state = {
178
190
  projectFolderCreated: false,
@@ -210,6 +222,9 @@ export async function runInit(skipEnv = false, folderName) {
210
222
  await fs.copyFile(path.join(config.projectPath, '.env.example'), path.join(config.projectPath, '.env'));
211
223
  await executeCommandWithMessages(() => initializeAgents(config.projectPath), 'Initializing agent system...', 'Agent system initialized');
212
224
  const installSuccess = await executeCommandWithMessages(() => executeNpmInstall(config.projectPath), 'Installing dependencies...', 'Dependencies installed');
225
+ if (!skipGit) {
226
+ await maybeInitializeGit(config.projectPath);
227
+ }
213
228
  const nextSteps = getProjectSuccessMessage(config.folderName, installSuccess, credentialsConfigured);
214
229
  ux.stdout('Project created successfully!');
215
230
  ux.stdout(nextSteps);
@@ -9,6 +9,7 @@ export interface WorkflowRunsResult {
9
9
  }
10
10
  export interface FetchWorkflowRunsOptions {
11
11
  workflowType?: string;
12
+ catalog?: string;
12
13
  limit?: number;
13
14
  }
14
15
  export declare function fetchWorkflowRuns(options?: FetchWorkflowRunsOptions): Promise<WorkflowRunsResult>;
@@ -10,6 +10,9 @@ export async function fetchWorkflowRuns(options = {}) {
10
10
  if (options.workflowType) {
11
11
  params.workflowType = options.workflowType;
12
12
  }
13
+ if (options.catalog) {
14
+ params.catalog = options.catalog;
15
+ }
13
16
  const response = await getWorkflowRuns(params);
14
17
  if (!response) {
15
18
  throw new Error('Failed to connect to API server. Is it running?');
@@ -7,3 +7,20 @@ ANTHROPIC_API_KEY=credential:anthropic.api_key
7
7
  # Configure if you plan to use OpenAI in your LLM prompts
8
8
  OPENAI_API_KEY=credential:openai.api_key
9
9
 
10
+ # --- Host port overrides (for running multiple dev stacks) ---
11
+ # Only the host-side port changes; inter-service traffic (e.g. worker -> Temporal
12
+ # at temporal:7233) is unaffected.
13
+ # OUTPUT_API_HOST_PORT=3001
14
+ # OUTPUT_TEMPORAL_UI_HOST_PORT=8080
15
+
16
+ # --- API connection ---
17
+ # If OUTPUT_API_URL is set, it overrides OUTPUT_API_HOST_PORT.
18
+ # Use OUTPUT_API_URL for remote/staging servers; use OUTPUT_API_HOST_PORT for local port shifts.
19
+ # OUTPUT_API_URL=http://localhost:3001
20
+
21
+ # --- Project isolation ---
22
+ # Compose prefixes named volumes with the project name, so changing
23
+ # DOCKER_SERVICE_NAME creates fresh volumes and leaves the previous ones behind.
24
+ # Run `docker volume ls --filter name=<old-project-name>` to find orphaned
25
+ # volumes and `docker volume rm` to remove them.
26
+
@@ -0,0 +1 @@
1
+ export declare const loadCredentialRefs: () => void;
@@ -0,0 +1,18 @@
1
+ import { InvalidCredentialsKeyError, MalformedCredentialsKeyError, MissingKeyError, resolveCredentialRefs } from '@outputai/credentials';
2
+ const isCredentialsConfigError = (error) => error instanceof MissingKeyError ||
3
+ error instanceof InvalidCredentialsKeyError ||
4
+ error instanceof MalformedCredentialsKeyError;
5
+ export const loadCredentialRefs = () => {
6
+ try {
7
+ resolveCredentialRefs();
8
+ }
9
+ catch (error) {
10
+ if (isCredentialsConfigError(error)) {
11
+ console.error(`Error: ${error.message}`);
12
+ process.exit(1);
13
+ }
14
+ else {
15
+ throw error;
16
+ }
17
+ }
18
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,84 @@
1
+ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
2
+ import * as credentials from '@outputai/credentials';
3
+ import { loadCredentialRefs } from './credentials_loader.js';
4
+ vi.mock('@outputai/credentials', async () => {
5
+ const actual = await vi.importActual('@outputai/credentials');
6
+ return {
7
+ ...actual,
8
+ resolveCredentialRefs: vi.fn()
9
+ };
10
+ });
11
+ describe('loadCredentialRefs', () => {
12
+ beforeEach(() => {
13
+ vi.clearAllMocks();
14
+ });
15
+ afterEach(() => {
16
+ vi.restoreAllMocks();
17
+ });
18
+ it('should call resolveCredentialRefs without errors when no credentials are misconfigured', () => {
19
+ vi.mocked(credentials.resolveCredentialRefs).mockReturnValue([]);
20
+ expect(() => loadCredentialRefs()).not.toThrow();
21
+ expect(credentials.resolveCredentialRefs).toHaveBeenCalledTimes(1);
22
+ });
23
+ it('should print a clean error message and exit on MissingKeyError without dumping a stack trace', () => {
24
+ vi.mocked(credentials.resolveCredentialRefs).mockImplementation(() => {
25
+ throw new credentials.MissingKeyError();
26
+ });
27
+ const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => { });
28
+ const exitSpy = vi.spyOn(process, 'exit').mockImplementation((() => undefined));
29
+ loadCredentialRefs();
30
+ expect(consoleErrorSpy).toHaveBeenCalledTimes(1);
31
+ const printedMessage = consoleErrorSpy.mock.calls[0]?.[0];
32
+ expect(printedMessage).toContain('No credentials key found');
33
+ expect(printedMessage).toContain('OUTPUT_CREDENTIALS_KEY');
34
+ expect(printedMessage).toContain('config/credentials.key');
35
+ expect(printedMessage).not.toContain(' at ');
36
+ expect(exitSpy).toHaveBeenCalledWith(1);
37
+ });
38
+ it('should include the environment-specific hints in the printed message when an environment is set', () => {
39
+ vi.mocked(credentials.resolveCredentialRefs).mockImplementation(() => {
40
+ throw new credentials.MissingKeyError('production');
41
+ });
42
+ const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => { });
43
+ const exitSpy = vi.spyOn(process, 'exit').mockImplementation((() => undefined));
44
+ loadCredentialRefs();
45
+ const printedMessage = consoleErrorSpy.mock.calls[0]?.[0];
46
+ expect(printedMessage).toContain('OUTPUT_CREDENTIALS_KEY_PRODUCTION');
47
+ expect(printedMessage).toContain('config/credentials/production.key');
48
+ expect(exitSpy).toHaveBeenCalledWith(1);
49
+ });
50
+ it('should print a clean error message and exit on InvalidCredentialsKeyError', () => {
51
+ vi.mocked(credentials.resolveCredentialRefs).mockImplementation(() => {
52
+ throw new credentials.InvalidCredentialsKeyError('config/credentials.yml.enc');
53
+ });
54
+ const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => { });
55
+ const exitSpy = vi.spyOn(process, 'exit').mockImplementation((() => undefined));
56
+ loadCredentialRefs();
57
+ expect(consoleErrorSpy).toHaveBeenCalledTimes(1);
58
+ const printedMessage = consoleErrorSpy.mock.calls[0]?.[0];
59
+ expect(printedMessage).toContain('Failed to decrypt config/credentials.yml.enc');
60
+ expect(printedMessage).toContain('does not match');
61
+ expect(printedMessage).not.toContain(' at ');
62
+ expect(exitSpy).toHaveBeenCalledWith(1);
63
+ });
64
+ it('should print a clean error message and exit on MalformedCredentialsKeyError', () => {
65
+ vi.mocked(credentials.resolveCredentialRefs).mockImplementation(() => {
66
+ throw new credentials.MalformedCredentialsKeyError('config/credentials.yml.enc', 'hex string expected, got unpadded hex of length 55');
67
+ });
68
+ const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => { });
69
+ const exitSpy = vi.spyOn(process, 'exit').mockImplementation((() => undefined));
70
+ loadCredentialRefs();
71
+ const printedMessage = consoleErrorSpy.mock.calls[0]?.[0];
72
+ expect(printedMessage).toContain('is malformed');
73
+ expect(printedMessage).toContain('must be exactly 64 hex characters');
74
+ expect(printedMessage).toContain('unpadded hex of length 55');
75
+ expect(printedMessage).not.toContain(' at ');
76
+ expect(exitSpy).toHaveBeenCalledWith(1);
77
+ });
78
+ it('should rethrow unexpected errors so they are not silently swallowed', () => {
79
+ vi.mocked(credentials.resolveCredentialRefs).mockImplementation(() => {
80
+ throw new Error('something else broke');
81
+ });
82
+ expect(() => loadCredentialRefs()).toThrow('something else broke');
83
+ });
84
+ });
@@ -11,3 +11,16 @@ export declare function validateWorkflowName(name: string): void;
11
11
  * Validate that a directory path is safe to create
12
12
  */
13
13
  export declare function validateOutputDirectory(outputDir: string): void;
14
+ export declare class InvalidPortError extends Error {
15
+ constructor(envVarName: string, raw: string, reason: string);
16
+ }
17
+ /**
18
+ * Parse a port number from an env var. Empty string and undefined fall back to
19
+ * the default silently (matching Compose's `${VAR:-default}` semantics).
20
+ * Throws InvalidPortError on anything else: non-numeric, signed, decimal,
21
+ * trailing junk (e.g. "3001abc"), or out of range 1-65535. Throwing (vs
22
+ * warn-and-fallback) prevents CLI/Docker disagreement: Compose reads the same
23
+ * env var via `${VAR:-default}` and uses its own parser, so a CLI fallback
24
+ * would silently desync from the bound port.
25
+ */
26
+ export declare function parsePort(raw: string | undefined, defaultPort: number, envVarName: string): number;
@@ -23,3 +23,34 @@ export function validateOutputDirectory(outputDir) {
23
23
  throw new InvalidOutputDirectoryError(outputDir, 'Output directory cannot be empty');
24
24
  }
25
25
  }
26
+ const MIN_PORT = 1;
27
+ const MAX_PORT = 65535;
28
+ export class InvalidPortError extends Error {
29
+ constructor(envVarName, raw, reason) {
30
+ super(`${envVarName}=${raw} is invalid (${reason}). ` +
31
+ `Set a port in ${MIN_PORT}-${MAX_PORT} in your .env file, or unset the variable to use the default.`);
32
+ this.name = 'InvalidPortError';
33
+ }
34
+ }
35
+ /**
36
+ * Parse a port number from an env var. Empty string and undefined fall back to
37
+ * the default silently (matching Compose's `${VAR:-default}` semantics).
38
+ * Throws InvalidPortError on anything else: non-numeric, signed, decimal,
39
+ * trailing junk (e.g. "3001abc"), or out of range 1-65535. Throwing (vs
40
+ * warn-and-fallback) prevents CLI/Docker disagreement: Compose reads the same
41
+ * env var via `${VAR:-default}` and uses its own parser, so a CLI fallback
42
+ * would silently desync from the bound port.
43
+ */
44
+ export function parsePort(raw, defaultPort, envVarName) {
45
+ if (raw === undefined || raw === '') {
46
+ return defaultPort;
47
+ }
48
+ if (!/^\d+$/.test(raw)) {
49
+ throw new InvalidPortError(envVarName, raw, 'not a positive integer');
50
+ }
51
+ const n = parseInt(raw, 10);
52
+ if (n < MIN_PORT || n > MAX_PORT) {
53
+ throw new InvalidPortError(envVarName, raw, `out of range ${MIN_PORT}-${MAX_PORT}`);
54
+ }
55
+ return n;
56
+ }
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { isValidWorkflowName } from './validation.js';
2
+ import { isValidWorkflowName, parsePort, InvalidPortError } from './validation.js';
3
3
  describe('isValidWorkflowName', () => {
4
4
  describe('valid workflow names', () => {
5
5
  it('should accept single letter', () => {
@@ -138,3 +138,49 @@ describe('isValidWorkflowName', () => {
138
138
  });
139
139
  });
140
140
  });
141
+ describe('parsePort', () => {
142
+ it('returns the parsed value for a valid port', () => {
143
+ expect(parsePort('3001', 3001, 'P')).toBe(3001);
144
+ expect(parsePort('7234', 7233, 'P')).toBe(7234);
145
+ });
146
+ it('falls back to default for undefined silently', () => {
147
+ expect(parsePort(undefined, 3001, 'P')).toBe(3001);
148
+ });
149
+ it('falls back to default for empty string silently (matches Compose ${VAR:-default})', () => {
150
+ expect(parsePort('', 3001, 'P')).toBe(3001);
151
+ });
152
+ it('throws InvalidPortError for non-numeric input', () => {
153
+ expect(() => parsePort('abc', 3001, 'OUTPUT_API_HOST_PORT')).toThrow(InvalidPortError);
154
+ expect(() => parsePort('abc', 3001, 'OUTPUT_API_HOST_PORT'))
155
+ .toThrow(/OUTPUT_API_HOST_PORT=abc/);
156
+ });
157
+ it('throws for trailing junk (parseInt would silently truncate)', () => {
158
+ expect(() => parsePort('3001abc', 3001, 'P')).toThrow(InvalidPortError);
159
+ });
160
+ it('throws for negative input', () => {
161
+ expect(() => parsePort('-1', 3001, 'P')).toThrow(InvalidPortError);
162
+ });
163
+ it('throws for port 0 (CLI rejects but Compose would treat as ephemeral - prevents desync)', () => {
164
+ expect(() => parsePort('0', 3001, 'P')).toThrow(InvalidPortError);
165
+ });
166
+ it('throws for port above 65535', () => {
167
+ expect(() => parsePort('65536', 3001, 'P')).toThrow(InvalidPortError);
168
+ expect(() => parsePort('99999', 3001, 'P')).toThrow(InvalidPortError);
169
+ });
170
+ it('accepts boundary ports 1 and 65535', () => {
171
+ expect(parsePort('1', 3001, 'P')).toBe(1);
172
+ expect(parsePort('65535', 3001, 'P')).toBe(65535);
173
+ });
174
+ it('error message includes env var name and remediation hint', () => {
175
+ try {
176
+ parsePort('abc', 3001, 'OUTPUT_API_HOST_PORT');
177
+ expect.fail('expected throw');
178
+ }
179
+ catch (err) {
180
+ expect(err).toBeInstanceOf(InvalidPortError);
181
+ expect(err.message).toContain('OUTPUT_API_HOST_PORT=abc');
182
+ expect(err.message).toContain('1-65535');
183
+ expect(err.message).toContain('.env file');
184
+ }
185
+ });
186
+ });
package/dist/views/dev.js CHANGED
@@ -138,10 +138,10 @@ const DevSuccessMessage = ({ services }) => {
138
138
  const divider = '─'.repeat(80);
139
139
  const sortedNames = services.map(s => s.name).sort().join('|');
140
140
  const logsCommand = `docker compose -p ${config.dockerServiceName} logs -f <${sortedNames}>`;
141
- return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsx(Box, { marginTop: 1, marginBottom: 1, children: _jsx(Text, { dimColor: true, children: divider }) }), _jsxs(Box, { children: [_jsx(Text, { color: "green", bold: true, children: '✅ SUCCESS! ' }), _jsx(Text, { bold: true, children: "Development services are running" })] }), _jsx(Box, { marginTop: 1, marginBottom: 1, children: _jsx(Text, { dimColor: true, children: divider }) }), _jsx(Box, { marginBottom: 1, children: _jsx(Text, { bold: true, children: "\uD83D\uDC33 SERVICES" }) }), _jsxs(Box, { flexDirection: "column", marginLeft: 2, children: [_jsxs(Box, { children: [_jsx(Text, { color: "white", children: 'Temporal: ' }), _jsx(Text, { color: "yellow", children: "localhost:7233" })] }), _jsxs(Box, { children: [_jsx(Text, { color: "white", children: 'Temporal UI: ' }), _jsx(Text, { color: "cyan", children: "http://localhost:8080" })] }), _jsxs(Box, { children: [_jsx(Text, { color: "white", children: 'API Server: ' }), _jsx(Text, { color: "yellow", children: "localhost:3001" })] }), _jsxs(Box, { children: [_jsx(Text, { color: "white", children: 'Redis: ' }), _jsx(Text, { color: "yellow", children: "localhost:6379" })] })] }), _jsx(Box, { marginTop: 1, marginBottom: 1, children: _jsx(Text, { dimColor: true, children: divider }) }), _jsx(Box, { marginBottom: 1, children: _jsx(Text, { bold: true, children: "\uD83D\uDE80 RUN A WORKFLOW" }) }), _jsxs(Box, { flexDirection: "column", marginLeft: 2, children: [_jsx(Text, { color: "white", children: "In a new terminal, execute:" }), _jsx(Box, { marginLeft: 2, children: _jsx(Text, { color: "cyan", children: "npx output workflow run blog_evaluator paulgraham_hwh" }) })] }), _jsx(Box, { marginTop: 1, marginBottom: 1, children: _jsx(Text, { dimColor: true, children: divider }) }), _jsx(Box, { marginBottom: 1, children: _jsx(Text, { bold: true, children: "\u26A1 USEFUL COMMANDS" }) }), _jsxs(Box, { flexDirection: "column", marginLeft: 2, children: [_jsxs(Box, { children: [_jsx(Text, { color: "white", children: 'Open Temporal UI: ' }), _jsx(Text, { color: "cyan", children: "open http://localhost:8080" })] }), _jsxs(Box, { children: [_jsx(Text, { color: "white", children: 'View logs: ' }), _jsx(Text, { color: "cyan", children: logsCommand })] }), _jsxs(Box, { children: [_jsx(Text, { color: "white", children: 'Stop services: ' }), _jsx(Text, { color: "cyan", children: "Press Ctrl+C" })] })] }), _jsx(Box, { marginTop: 1, marginBottom: 1, children: _jsx(Text, { dimColor: true, children: divider }) }), _jsx(Text, { dimColor: true, children: "\uD83D\uDCA1 Tip: The Temporal UI lets you monitor workflow executions in real-time" })] }));
141
+ return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsx(Box, { marginTop: 1, marginBottom: 1, children: _jsx(Text, { dimColor: true, children: divider }) }), _jsxs(Box, { children: [_jsx(Text, { color: "green", bold: true, children: '✅ SUCCESS! ' }), _jsx(Text, { bold: true, children: "Development services are running" })] }), _jsx(Box, { marginTop: 1, marginBottom: 1, children: _jsx(Text, { dimColor: true, children: divider }) }), _jsx(Box, { marginBottom: 1, children: _jsx(Text, { bold: true, children: "\uD83D\uDC33 SERVICES" }) }), _jsxs(Box, { flexDirection: "column", marginLeft: 2, children: [_jsxs(Box, { children: [_jsx(Text, { color: "white", children: 'Temporal UI: ' }), _jsx(Text, { color: "cyan", children: config.temporalUiUrl })] }), _jsxs(Box, { children: [_jsx(Text, { color: "white", children: 'API Server: ' }), _jsxs(Text, { color: "yellow", children: ["localhost:", config.ports.api] })] })] }), _jsx(Box, { marginTop: 1, marginBottom: 1, children: _jsx(Text, { dimColor: true, children: divider }) }), _jsx(Box, { marginBottom: 1, children: _jsx(Text, { bold: true, children: "\uD83D\uDE80 RUN A WORKFLOW" }) }), _jsxs(Box, { flexDirection: "column", marginLeft: 2, children: [_jsx(Text, { color: "white", children: "In a new terminal, execute:" }), _jsx(Box, { marginLeft: 2, children: _jsx(Text, { color: "cyan", children: "npx output workflow run blog_evaluator paulgraham_hwh" }) })] }), _jsx(Box, { marginTop: 1, marginBottom: 1, children: _jsx(Text, { dimColor: true, children: divider }) }), _jsx(Box, { marginBottom: 1, children: _jsx(Text, { bold: true, children: "\u26A1 USEFUL COMMANDS" }) }), _jsxs(Box, { flexDirection: "column", marginLeft: 2, children: [_jsxs(Box, { children: [_jsx(Text, { color: "white", children: 'Open Temporal UI: ' }), _jsxs(Text, { color: "cyan", children: ["open ", config.temporalUiUrl] })] }), _jsxs(Box, { children: [_jsx(Text, { color: "white", children: 'View logs: ' }), _jsx(Text, { color: "cyan", children: logsCommand })] }), _jsxs(Box, { children: [_jsx(Text, { color: "white", children: 'Stop services: ' }), _jsx(Text, { color: "cyan", children: "Press Ctrl+C" })] })] }), _jsx(Box, { marginTop: 1, marginBottom: 1, children: _jsx(Text, { dimColor: true, children: divider }) }), _jsx(Text, { dimColor: true, children: "\uD83D\uDCA1 Tip: The Temporal UI lets you monitor workflow executions in real-time" })] }));
142
142
  };
143
143
  const WaitingView = ({ services }) => (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { children: [_jsx(Text, { color: "yellow", children: _jsx(Spinner, { type: "dots" }) }), _jsx(Text, { children: " Waiting for services to become healthy..." })] }), services.length > 0 && (_jsx(Box, { flexDirection: "column", marginTop: 1, children: services.map(s => _jsx(ServiceRow, { service: s }, s.name)) }))] }));
144
- const RunningView = ({ services, workflowSummary }) => (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, children: "\uD83D\uDCCA Service Status" }), _jsx(Box, { flexDirection: "column", marginTop: 1, children: services.map(s => _jsx(ServiceRow, { service: s }, s.name)) }), _jsx(FailureWarning, { services: services }), workflowSummary && _jsx(WorkflowSummarySection, { summary: workflowSummary }), _jsxs(Box, { marginTop: 1, children: [_jsx(Text, { color: "cyan", children: '🌐 Temporal UI: ' }), _jsx(Text, { bold: true, children: "http://localhost:8080" })] }), _jsx(CommandFooter, { hints: [
144
+ const RunningView = ({ services, workflowSummary }) => (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, children: "\uD83D\uDCCA Service Status" }), _jsx(Box, { flexDirection: "column", marginTop: 1, children: services.map(s => _jsx(ServiceRow, { service: s }, s.name)) }), _jsx(FailureWarning, { services: services }), workflowSummary && _jsx(WorkflowSummarySection, { summary: workflowSummary }), _jsxs(Box, { marginTop: 1, children: [_jsx(Text, { color: "cyan", children: '🌐 Temporal UI: ' }), _jsx(Text, { bold: true, children: config.temporalUiUrl })] }), _jsx(CommandFooter, { hints: [
145
145
  { key: 'o', label: 'open ui' },
146
146
  { key: 'w', label: 'view workflow runs' },
147
147
  { key: 'ctrl+c', label: 'stop' }
@@ -173,7 +173,7 @@ export const DevApp = ({ dockerComposePath, onCleanup }) => {
173
173
  useStatusRefresh(dockerComposePath, phase === 'running', setServices);
174
174
  useWorkflowPolling(phase === 'running' || phase === 'failed', setWorkflowRuns);
175
175
  useMainViewInput(activeView === 'main' && phase !== 'waiting', {
176
- onOpenTemporal: () => openUrl('http://localhost:8080'),
176
+ onOpenTemporal: () => openUrl(config.temporalUiUrl),
177
177
  onOpenWorkflows: () => setActiveView('workflows')
178
178
  });
179
179
  useCtrlC(onCleanup);