@guildai/cli 0.3.16 → 0.3.18

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 (69) hide show
  1. package/dist/commands/agent/clone.js +22 -67
  2. package/dist/commands/agent/code.js +12 -32
  3. package/dist/commands/agent/create.js +14 -30
  4. package/dist/commands/agent/fork.js +27 -73
  5. package/dist/commands/agent/get.js +5 -4
  6. package/dist/commands/agent/grep.js +7 -9
  7. package/dist/commands/agent/init.js +2 -0
  8. package/dist/commands/agent/list.js +5 -6
  9. package/dist/commands/agent/publish.js +27 -44
  10. package/dist/commands/agent/pull.js +8 -35
  11. package/dist/commands/agent/revalidate.js +8 -16
  12. package/dist/commands/agent/save.js +30 -76
  13. package/dist/commands/agent/search.js +5 -6
  14. package/dist/commands/agent/tags/add.js +14 -24
  15. package/dist/commands/agent/tags/list.js +12 -23
  16. package/dist/commands/agent/tags/remove.js +16 -27
  17. package/dist/commands/agent/tags/set.js +14 -19
  18. package/dist/commands/agent/unpublish.js +12 -17
  19. package/dist/commands/agent/update.js +12 -29
  20. package/dist/commands/agent/versions.js +13 -11
  21. package/dist/commands/agent/workspaces.d.ts +3 -0
  22. package/dist/commands/agent/workspaces.js +51 -0
  23. package/dist/commands/auth/login.js +4 -2
  24. package/dist/commands/auth/logout.js +3 -1
  25. package/dist/commands/auth/status.js +4 -3
  26. package/dist/commands/auth/token.js +3 -2
  27. package/dist/commands/config/get.js +7 -9
  28. package/dist/commands/config/list.js +13 -11
  29. package/dist/commands/config/path.js +6 -4
  30. package/dist/commands/config/set.js +17 -22
  31. package/dist/commands/doctor.js +9 -7
  32. package/dist/commands/session/create.js +7 -5
  33. package/dist/commands/session/events.js +5 -3
  34. package/dist/commands/session/get.js +5 -3
  35. package/dist/commands/session/list.js +5 -4
  36. package/dist/commands/session/send.js +7 -5
  37. package/dist/commands/session/tasks.js +5 -3
  38. package/dist/commands/setup.js +15 -14
  39. package/dist/commands/trigger/activate.js +7 -6
  40. package/dist/commands/trigger/create.js +16 -15
  41. package/dist/commands/trigger/deactivate.js +7 -6
  42. package/dist/commands/trigger/get.js +5 -4
  43. package/dist/commands/trigger/list.js +5 -5
  44. package/dist/commands/trigger/sessions.js +7 -6
  45. package/dist/commands/trigger/update.js +11 -10
  46. package/dist/commands/version.js +7 -5
  47. package/dist/commands/workspace/agent/add.js +16 -22
  48. package/dist/commands/workspace/agent/list.js +12 -32
  49. package/dist/commands/workspace/agent/remove.js +9 -15
  50. package/dist/commands/workspace/context/edit.js +13 -27
  51. package/dist/commands/workspace/context/get.js +8 -14
  52. package/dist/commands/workspace/context/list.js +12 -37
  53. package/dist/commands/workspace/context/publish.js +7 -11
  54. package/dist/commands/workspace/create.js +7 -11
  55. package/dist/commands/workspace/current.js +19 -31
  56. package/dist/commands/workspace/get.js +7 -11
  57. package/dist/commands/workspace/list.js +5 -8
  58. package/dist/commands/workspace/select.js +17 -22
  59. package/dist/index.js +2 -0
  60. package/dist/lib/agent-helpers.js +2 -2
  61. package/dist/lib/generated-types.d.ts +1 -1
  62. package/dist/lib/generated-types.js +1 -0
  63. package/dist/lib/npmrc.js +9 -1
  64. package/dist/lib/output.d.ts +18 -4
  65. package/dist/lib/output.js +112 -19
  66. package/docs/getting-started.md +1 -1
  67. package/docs/output-format.md +1 -1
  68. package/docs/skills/agent-dev.md +18 -17
  69. package/package.json +1 -1
@@ -4,6 +4,7 @@ import { GuildAPIClient } from '../../../lib/api-client.js';
4
4
  import { getAuthToken } from '../../../lib/auth.js';
5
5
  import { getWorkspaceId } from '../../../lib/guild-config.js';
6
6
  import { handleAxiosError, ErrorCodes } from '../../../lib/errors.js';
7
+ import { createOutputWriter } from '../../../lib/output.js';
7
8
  export function createWorkspaceAgentRemoveCommand() {
8
9
  const cmd = new Command('remove');
9
10
  cmd
@@ -11,11 +12,11 @@ export function createWorkspaceAgentRemoveCommand() {
11
12
  .argument('<agent>', 'Agent identifier (e.g., owner/agent-name or UUID)')
12
13
  .option('--workspace <id>', 'Workspace ID or name')
13
14
  .action(async (agentIdentifier, options) => {
15
+ const output = createOutputWriter();
14
16
  try {
15
17
  const token = await getAuthToken();
16
18
  if (!token) {
17
- console.error('Not authenticated. Please log in first.');
18
- console.error('Run: guild auth login');
19
+ output.error('Not authenticated. Please log in first.', 'Run: guild auth login');
19
20
  process.exit(1);
20
21
  }
21
22
  const client = new GuildAPIClient();
@@ -24,13 +25,7 @@ export function createWorkspaceAgentRemoveCommand() {
24
25
  if (!workspaceId) {
25
26
  const resolved = await getWorkspaceId();
26
27
  if (!resolved) {
27
- console.error('Error: No workspace specified.');
28
- console.error('');
29
- console.error('Either use --workspace flag:');
30
- console.error(' guild workspace agent remove <agent> --workspace <workspace-id>');
31
- console.error('');
32
- console.error('Or select a default workspace:');
33
- console.error(' guild workspace select');
28
+ output.error('No workspace specified.', 'Either use --workspace flag:\n guild workspace agent remove <agent> --workspace <workspace-id>\n\nOr select a default workspace:\n guild workspace select');
34
29
  process.exit(1);
35
30
  }
36
31
  workspaceId = resolved.workspaceId;
@@ -43,25 +38,24 @@ export function createWorkspaceAgentRemoveCommand() {
43
38
  wa.agent.name === agentIdentifier ||
44
39
  wa.agent.id === agentIdentifier);
45
40
  if (!workspaceAgent) {
46
- console.error(`Error: Agent "${agentIdentifier}" is not installed in this workspace`);
41
+ output.error(`Agent "${agentIdentifier}" is not installed in this workspace`);
47
42
  process.exit(1);
48
43
  }
49
44
  // Remove the workspace agent
50
45
  await client.delete(`/workspace_agents/${workspaceAgent.id}`);
51
- console.log(`✓ Removed ${workspaceAgent.agent.full_name} from workspace`);
46
+ output.success(`Removed ${workspaceAgent.agent.full_name} from workspace`);
52
47
  }
53
48
  catch (error) {
54
49
  const formattedError = handleAxiosError(error);
55
50
  if (formattedError.code === ErrorCodes.AUTH_REQUIRED) {
56
- console.error('Not authenticated. Please log in first.');
57
- console.error('Run: guild auth login');
51
+ output.error('Not authenticated. Please log in first.', 'Run: guild auth login');
58
52
  process.exit(1);
59
53
  }
60
54
  if (formattedError.code === ErrorCodes.NOT_FOUND) {
61
- console.error('Error: Workspace or agent not found');
55
+ output.error('Workspace or agent not found');
62
56
  process.exit(1);
63
57
  }
64
- console.error(`Failed to remove agent: ${formattedError.details}`);
58
+ output.error(`Failed to remove agent: ${formattedError.details}`);
65
59
  process.exit(1);
66
60
  }
67
61
  });
@@ -6,6 +6,7 @@ import { join } from 'path';
6
6
  import { tmpdir } from 'os';
7
7
  import { GuildAPIClient } from '../../../lib/api-client.js';
8
8
  import { handleAxiosError, ErrorCodes } from '../../../lib/errors.js';
9
+ import { createOutputWriter } from '../../../lib/output.js';
9
10
  export function createWorkspaceContextEditCommand() {
10
11
  const cmd = new Command('edit');
11
12
  cmd
@@ -13,6 +14,7 @@ export function createWorkspaceContextEditCommand() {
13
14
  .argument('<workspace>', 'Workspace ID or full name (e.g., owner/workspace-name)')
14
15
  .option('--from <context-id>', 'Edit from a specific context version')
15
16
  .action(async (workspaceId, options) => {
17
+ const output = createOutputWriter();
16
18
  let tempDir = null;
17
19
  try {
18
20
  const client = new GuildAPIClient();
@@ -25,9 +27,7 @@ export function createWorkspaceContextEditCommand() {
25
27
  // Edit from specific context version
26
28
  sourceContext = contexts.find((ctx) => ctx.id === options.from) || null;
27
29
  if (!sourceContext) {
28
- console.error(`Context not found: ${options.from}`);
29
- console.error('');
30
- console.error(`Run: guild workspace context list ${workspaceId}`);
30
+ output.error(`Context not found: ${options.from}`, `Run: guild workspace context list ${workspaceId}`);
31
31
  process.exit(1);
32
32
  }
33
33
  }
@@ -38,12 +38,7 @@ export function createWorkspaceContextEditCommand() {
38
38
  // Get the editor from environment
39
39
  const editor = process.env.EDITOR || process.env.VISUAL || process.env.GIT_EDITOR;
40
40
  if (!editor) {
41
- console.error('No editor configured');
42
- console.error('');
43
- console.error('Set EDITOR environment variable:');
44
- console.error(' export EDITOR=vim');
45
- console.error(' # or');
46
- console.error(' export EDITOR="code --wait"');
41
+ output.error('No editor configured', 'Set EDITOR environment variable:\n export EDITOR=vim\n # or\n export EDITOR="code --wait"');
47
42
  process.exit(1);
48
43
  }
49
44
  // Create temp file with current context content
@@ -51,7 +46,7 @@ export function createWorkspaceContextEditCommand() {
51
46
  const tempFile = join(tempDir, 'workspace.md');
52
47
  const currentContent = sourceContext?.manual_context || '';
53
48
  writeFileSync(tempFile, currentContent, 'utf-8');
54
- console.log('Opening editor...');
49
+ output.progress('Opening editor...');
55
50
  // Open editor
56
51
  const result = spawnSync(editor, [tempFile], {
57
52
  stdio: 'inherit',
@@ -68,39 +63,30 @@ export function createWorkspaceContextEditCommand() {
68
63
  context: editedContent,
69
64
  summary: null,
70
65
  });
71
- console.log(`Draft context created: ${newContext.id}`);
72
- console.log('');
73
- console.log('To publish this draft:');
74
- console.log(` guild workspace context publish ${workspaceId} ${newContext.id}`);
66
+ output.success(`Draft context created: ${newContext.id}`, {
67
+ publish: `guild workspace context publish ${workspaceId} ${newContext.id}`,
68
+ });
75
69
  }
76
70
  catch (error) {
77
71
  const formattedError = handleAxiosError(error);
78
72
  if (formattedError.code === ErrorCodes.AUTH_REQUIRED) {
79
- console.error('Not authenticated. Please log in first.');
80
- console.error('');
81
- console.error('Run: guild auth login');
73
+ output.error('Not authenticated. Please log in first.', 'Run: guild auth login');
82
74
  process.exit(1);
83
75
  }
84
76
  if (formattedError.code === ErrorCodes.NOT_FOUND) {
85
77
  if (options.from) {
86
- console.error(`Context not found: ${options.from}`);
87
- console.error('');
88
- console.error(`Run: guild workspace context list ${workspaceId}`);
78
+ output.error(`Context not found: ${options.from}`, `Run: guild workspace context list ${workspaceId}`);
89
79
  }
90
80
  else {
91
- console.error(`Workspace not found: ${workspaceId}`);
92
- console.error('');
93
- console.error('Run: guild workspace list');
81
+ output.error(`Workspace not found: ${workspaceId}`, 'Run: guild workspace list');
94
82
  }
95
83
  process.exit(1);
96
84
  }
97
85
  if (formattedError.code === ErrorCodes.CONN_REFUSED) {
98
- console.error(`Failed to edit context: ${formattedError.details}`);
99
- console.error('');
100
- console.error('Run with --debug for more details');
86
+ output.error(`Failed to edit context: ${formattedError.details}`, 'Run with --debug for more details');
101
87
  process.exit(1);
102
88
  }
103
- console.error(`Failed to edit context: ${formattedError.details}`);
89
+ output.error(`Failed to edit context: ${formattedError.details}`);
104
90
  process.exit(1);
105
91
  }
106
92
  finally {
@@ -2,6 +2,7 @@
2
2
  import { Command } from 'commander';
3
3
  import { GuildAPIClient } from '../../../lib/api-client.js';
4
4
  import { handleAxiosError, ErrorCodes } from '../../../lib/errors.js';
5
+ import { createOutputWriter } from '../../../lib/output.js';
5
6
  export function createWorkspaceContextGetCommand() {
6
7
  const cmd = new Command('get');
7
8
  cmd
@@ -9,6 +10,7 @@ export function createWorkspaceContextGetCommand() {
9
10
  .argument('<workspace>', 'Workspace ID or full name (e.g., owner/workspace-name)')
10
11
  .argument('<context-id>', 'Context ID')
11
12
  .action(async (workspaceId, contextId) => {
13
+ const output = createOutputWriter();
12
14
  try {
13
15
  const client = new GuildAPIClient();
14
16
  // Backend doesn't have GET endpoint for individual context
@@ -16,34 +18,26 @@ export function createWorkspaceContextGetCommand() {
16
18
  const response = await client.get(`/workspaces/${workspaceId}/contexts`);
17
19
  const context = response.items.find((ctx) => ctx.id === contextId);
18
20
  if (!context) {
19
- console.error(`Context not found: ${contextId}`);
20
- console.error('');
21
- console.error(`Run: guild workspace context list ${workspaceId}`);
21
+ output.error(`Context not found: ${contextId}`, `Run: guild workspace context list ${workspaceId}`);
22
22
  process.exit(1);
23
23
  }
24
- console.log(JSON.stringify(context, null, 2));
24
+ output.data(context);
25
25
  }
26
26
  catch (error) {
27
27
  const formattedError = handleAxiosError(error);
28
28
  if (formattedError.code === ErrorCodes.AUTH_REQUIRED) {
29
- console.error('Not authenticated. Please log in first.');
30
- console.error('');
31
- console.error('Run: guild auth login');
29
+ output.error('Not authenticated. Please log in first.', 'Run: guild auth login');
32
30
  process.exit(1);
33
31
  }
34
32
  if (formattedError.code === ErrorCodes.NOT_FOUND) {
35
- console.error(`Context not found: ${contextId}`);
36
- console.error('');
37
- console.error(`Run: guild workspace context list ${workspaceId}`);
33
+ output.error(`Context not found: ${contextId}`, `Run: guild workspace context list ${workspaceId}`);
38
34
  process.exit(1);
39
35
  }
40
36
  if (formattedError.code === ErrorCodes.CONN_REFUSED) {
41
- console.error(`Failed to get context: ${formattedError.details}`);
42
- console.error('');
43
- console.error('Run with --debug for more details');
37
+ output.error(`Failed to get context: ${formattedError.details}`, 'Run with --debug for more details');
44
38
  process.exit(1);
45
39
  }
46
- console.error(`Failed to get context: ${formattedError.details}`);
40
+ output.error(`Failed to get context: ${formattedError.details}`);
47
41
  process.exit(1);
48
42
  }
49
43
  });
@@ -2,6 +2,8 @@
2
2
  import { Command } from 'commander';
3
3
  import { GuildAPIClient } from '../../../lib/api-client.js';
4
4
  import { handleAxiosError, ErrorCodes } from '../../../lib/errors.js';
5
+ import { getOutputMode } from '../../../lib/output-mode.js';
6
+ import { createOutputWriter, formatContextTable } from '../../../lib/output.js';
5
7
  export function createWorkspaceContextListCommand() {
6
8
  const cmd = new Command('list');
7
9
  cmd
@@ -10,62 +12,35 @@ export function createWorkspaceContextListCommand() {
10
12
  .option('--limit <number>', 'Number of results to return', '20')
11
13
  .option('--offset <number>', 'Offset for pagination', '0')
12
14
  .action(async (workspaceId, options) => {
15
+ const output = createOutputWriter();
13
16
  try {
14
17
  const client = new GuildAPIClient();
15
18
  const params = new URLSearchParams();
16
19
  params.append('limit', options.limit);
17
20
  params.append('offset', options.offset);
18
21
  const response = await client.get(`/workspaces/${workspaceId}/contexts?${params.toString()}`);
19
- const contexts = response.items;
20
- console.log(`Context Versions for workspace ${workspaceId}:`);
21
- console.log('');
22
- if (contexts.length === 0) {
23
- console.log(`No context versions found for workspace ${workspaceId}`);
24
- return;
22
+ if (getOutputMode() === 'json') {
23
+ output.data(response);
24
+ }
25
+ else {
26
+ formatContextTable(response.items, response.pagination);
25
27
  }
26
- // Print table header
27
- console.log('ID'.padEnd(36) +
28
- ' ' +
29
- 'Status'.padEnd(12) +
30
- ' ' +
31
- 'Summary'.padEnd(20) +
32
- ' ' +
33
- 'Created');
34
- // Print each context
35
- contexts.forEach((ctx) => {
36
- const date = new Date(ctx.created_at).toISOString().split('T')[0];
37
- const summary = ctx.summary || '';
38
- const truncatedSummary = summary.length > 17 ? summary.substring(0, 17) : summary;
39
- console.log(ctx.id.padEnd(36) +
40
- ' ' +
41
- ctx.status.padEnd(12) +
42
- ' ' +
43
- truncatedSummary.padEnd(20) +
44
- ' ' +
45
- date);
46
- });
47
28
  }
48
29
  catch (error) {
49
30
  const formattedError = handleAxiosError(error);
50
31
  if (formattedError.code === ErrorCodes.AUTH_REQUIRED) {
51
- console.error('Not authenticated. Please log in first.');
52
- console.error('');
53
- console.error('Run: guild auth login');
32
+ output.error('Not authenticated. Please log in first.', 'Run: guild auth login');
54
33
  process.exit(1);
55
34
  }
56
35
  if (formattedError.code === ErrorCodes.NOT_FOUND) {
57
- console.error(`Workspace not found: ${workspaceId}`);
58
- console.error('');
59
- console.error('Run: guild workspace list');
36
+ output.error(`Workspace not found: ${workspaceId}`, 'Run: guild workspace list');
60
37
  process.exit(1);
61
38
  }
62
39
  if (formattedError.code === ErrorCodes.CONN_REFUSED) {
63
- console.error(`Failed to list contexts: ${formattedError.details}`);
64
- console.error('');
65
- console.error('Run with --debug for more details');
40
+ output.error(`Failed to list contexts: ${formattedError.details}`, 'Run with --debug for more details');
66
41
  process.exit(1);
67
42
  }
68
- console.error(`Failed to list contexts: ${formattedError.details}`);
43
+ output.error(`Failed to list contexts: ${formattedError.details}`);
69
44
  process.exit(1);
70
45
  }
71
46
  });
@@ -2,6 +2,7 @@
2
2
  import { Command } from 'commander';
3
3
  import { GuildAPIClient } from '../../../lib/api-client.js';
4
4
  import { handleAxiosError, ErrorCodes } from '../../../lib/errors.js';
5
+ import { createOutputWriter } from '../../../lib/output.js';
5
6
  export function createWorkspaceContextPublishCommand() {
6
7
  const cmd = new Command('publish');
7
8
  cmd
@@ -9,34 +10,29 @@ export function createWorkspaceContextPublishCommand() {
9
10
  .argument('<workspace>', 'Workspace ID or full name (e.g., owner/workspace-name)')
10
11
  .argument('<context-id>', 'Context ID to publish')
11
12
  .action(async (workspaceId, contextId) => {
13
+ const output = createOutputWriter();
12
14
  try {
13
15
  const client = new GuildAPIClient();
14
16
  await client.patch(`/workspaces/${workspaceId}/contexts/${contextId}`, {
15
17
  status: 'PUBLISHED',
16
18
  });
17
- console.log(`✓ Context ${contextId} published successfully`);
19
+ output.success(`Context ${contextId} published successfully`);
18
20
  }
19
21
  catch (error) {
20
22
  const formattedError = handleAxiosError(error);
21
23
  if (formattedError.code === ErrorCodes.AUTH_REQUIRED) {
22
- console.error('Not authenticated. Please log in first.');
23
- console.error('');
24
- console.error('Run: guild auth login');
24
+ output.error('Not authenticated. Please log in first.', 'Run: guild auth login');
25
25
  process.exit(1);
26
26
  }
27
27
  if (formattedError.code === ErrorCodes.NOT_FOUND) {
28
- console.error(`Context not found: ${contextId}`);
29
- console.error('');
30
- console.error(`Run: guild workspace context list ${workspaceId}`);
28
+ output.error(`Context not found: ${contextId}`, `Run: guild workspace context list ${workspaceId}`);
31
29
  process.exit(1);
32
30
  }
33
31
  if (formattedError.code === ErrorCodes.CONN_REFUSED) {
34
- console.error(`Failed to publish context: ${formattedError.details}`);
35
- console.error('');
36
- console.error('Run with --debug for more details');
32
+ output.error(`Failed to publish context: ${formattedError.details}`, 'Run with --debug for more details');
37
33
  process.exit(1);
38
34
  }
39
- console.error(`Failed to publish context: ${formattedError.details}`);
35
+ output.error(`Failed to publish context: ${formattedError.details}`);
40
36
  process.exit(1);
41
37
  }
42
38
  });
@@ -2,12 +2,14 @@
2
2
  import { Command } from 'commander';
3
3
  import { GuildAPIClient } from '../../lib/api-client.js';
4
4
  import { handleAxiosError, ErrorCodes } from '../../lib/errors.js';
5
+ import { createOutputWriter } from '../../lib/output.js';
5
6
  export function createWorkspaceCreateCommand() {
6
7
  const cmd = new Command('create');
7
8
  cmd
8
9
  .description('Create a new workspace')
9
10
  .argument('<name>', 'Workspace name')
10
11
  .action(async (name) => {
12
+ const output = createOutputWriter();
11
13
  try {
12
14
  const client = new GuildAPIClient();
13
15
  // Get current user info to use as workspace owner
@@ -17,29 +19,23 @@ export function createWorkspaceCreateCommand() {
17
19
  name,
18
20
  owner_id: me.id,
19
21
  });
20
- console.log(JSON.stringify(workspace, null, 2));
22
+ output.data(workspace);
21
23
  }
22
24
  catch (error) {
23
25
  const formattedError = handleAxiosError(error);
24
26
  if (formattedError.code === ErrorCodes.AUTH_REQUIRED) {
25
- console.error('Not authenticated. Please log in first.');
26
- console.error('');
27
- console.error('Run: guild auth login');
27
+ output.error('Not authenticated. Please log in first.', 'Run: guild auth login');
28
28
  process.exit(1);
29
29
  }
30
30
  if (formattedError.code === ErrorCodes.CONN_REFUSED) {
31
- console.error(`Failed to create workspace: ${formattedError.details}`);
32
- console.error('');
33
- console.error('Run with --debug for more details');
31
+ output.error(`Failed to create workspace: ${formattedError.details}`, 'Run with --debug for more details');
34
32
  process.exit(1);
35
33
  }
36
34
  if (formattedError.code === ErrorCodes.BAD_REQUEST) {
37
- console.error(`Failed to create workspace: ${formattedError.details}`);
38
- console.error('');
39
- console.error('Run with --debug for more details');
35
+ output.error(`Failed to create workspace: ${formattedError.details}`, 'Run with --debug for more details');
40
36
  process.exit(1);
41
37
  }
42
- console.error(`Failed to create workspace: ${formattedError.details}`);
38
+ output.error(`Failed to create workspace: ${formattedError.details}`);
43
39
  process.exit(1);
44
40
  }
45
41
  });
@@ -1,32 +1,30 @@
1
1
  // Copyright (c) 2026 Guild.ai All Rights Reserved
2
2
  import { Command } from 'commander';
3
- import chalk from 'chalk';
4
3
  import { GuildAPIClient } from '../../lib/api-client.js';
5
4
  import { handleAxiosError, ErrorCodes } from '../../lib/errors.js';
5
+ import { createOutputWriter } from '../../lib/output.js';
6
6
  import { getWorkspaceId, loadGlobalConfig } from '../../lib/guild-config.js';
7
- import { warn } from '../../lib/colors.js';
8
7
  export function createWorkspaceCurrentCommand() {
9
8
  const cmd = new Command('current');
10
9
  cmd.description('Show current default workspace').action(async () => {
10
+ const output = createOutputWriter();
11
11
  try {
12
12
  // Get configured workspace ID
13
13
  const resolved = await getWorkspaceId();
14
14
  if (!resolved) {
15
- console.log(warn('No default workspace configured.'));
16
- console.log('');
17
- console.log('Set a default workspace:');
18
- console.log(chalk.dim(' guild workspace select'));
15
+ output.data({ configured: false, message: 'No default workspace configured.' });
16
+ output.progress('Set a default workspace:\n guild workspace select');
19
17
  return;
20
18
  }
21
19
  const { workspaceId, source } = resolved;
22
20
  // Fetch workspace details from API
23
21
  const client = new GuildAPIClient();
24
22
  const workspace = await client.get(`/workspaces/${workspaceId}`);
25
- console.log(chalk.green('Current workspace:'));
26
- console.log('');
27
- console.log(` ${chalk.bold('Name:')} ${workspace.name}`);
28
- console.log(` ${chalk.bold('ID:')} ${workspaceId}`);
29
- console.log(` ${chalk.bold('Source:')} ${source === 'local' ? 'guild.json (local)' : '~/.guild/config.json (global)'}`);
23
+ output.data({
24
+ name: workspace.name,
25
+ id: workspaceId,
26
+ source: source === 'local' ? 'guild.json (local)' : '~/.guild/config.json (global)',
27
+ });
30
28
  }
31
29
  catch (error) {
32
30
  const formattedError = handleAxiosError(error);
@@ -34,38 +32,28 @@ export function createWorkspaceCurrentCommand() {
34
32
  // Still show configured workspace ID even if not authenticated
35
33
  const globalConfig = await loadGlobalConfig();
36
34
  if (globalConfig?.default_workspace) {
37
- console.log(warn('Current workspace (not authenticated):'));
38
- console.log('');
39
- console.log(` ${chalk.bold('ID:')} ${globalConfig.default_workspace}`);
40
- console.log(` ${chalk.bold('Source:')} ~/.guild/config.json (global)`);
41
- console.log('');
42
- console.log(chalk.dim('Log in to see workspace name:'));
43
- console.log(chalk.dim(' guild auth login'));
35
+ output.data({
36
+ id: globalConfig.default_workspace,
37
+ source: '~/.guild/config.json (global)',
38
+ authenticated: false,
39
+ });
40
+ output.progress('Log in to see workspace name:\n guild auth login');
44
41
  return;
45
42
  }
46
- console.error('Not authenticated. Please log in first.');
47
- console.error('');
48
- console.error('Run: guild auth login');
43
+ output.error('Not authenticated. Please log in first.', 'Run: guild auth login');
49
44
  process.exit(1);
50
45
  }
51
46
  if (formattedError.code === ErrorCodes.NOT_FOUND) {
52
47
  // Workspace ID is configured but doesn't exist
53
48
  const resolved = await getWorkspaceId();
54
- console.log(warn('Configured workspace not found:'));
55
- console.log('');
56
- console.log(` ${chalk.bold('ID:')} ${resolved?.workspaceId || 'unknown'}`);
57
- console.log('');
58
- console.log('The workspace may have been deleted. Select a new one:');
59
- console.log(chalk.dim(' guild workspace select'));
49
+ output.error('Configured workspace not found', `ID: ${resolved?.workspaceId || 'unknown'}\n\nThe workspace may have been deleted. Select a new one:\n guild workspace select`);
60
50
  return;
61
51
  }
62
52
  if (formattedError.code === ErrorCodes.CONN_REFUSED) {
63
- console.error(`Failed to fetch workspace: ${formattedError.details}`);
64
- console.error('');
65
- console.error('Run with --debug for more details');
53
+ output.error(`Failed to fetch workspace: ${formattedError.details}`, 'Run with --debug for more details');
66
54
  process.exit(1);
67
55
  }
68
- console.error(`Failed to get workspace: ${formattedError.details}`);
56
+ output.error(`Failed to get workspace: ${formattedError.details}`);
69
57
  process.exit(1);
70
58
  }
71
59
  });
@@ -2,38 +2,34 @@
2
2
  import { Command } from 'commander';
3
3
  import { GuildAPIClient } from '../../lib/api-client.js';
4
4
  import { handleAxiosError, ErrorCodes } from '../../lib/errors.js';
5
+ import { createOutputWriter } from '../../lib/output.js';
5
6
  export function createWorkspaceGetCommand() {
6
7
  const cmd = new Command('get');
7
8
  cmd
8
9
  .description('Get workspace details')
9
10
  .argument('<identifier>', 'Workspace ID or full name (e.g., owner/workspace-name)')
10
11
  .action(async (id) => {
12
+ const output = createOutputWriter();
11
13
  try {
12
14
  const client = new GuildAPIClient();
13
15
  const workspace = await client.get(`/workspaces/${id}`);
14
- console.log(JSON.stringify(workspace, null, 2));
16
+ output.data(workspace);
15
17
  }
16
18
  catch (error) {
17
19
  const formattedError = handleAxiosError(error);
18
20
  if (formattedError.code === ErrorCodes.AUTH_REQUIRED) {
19
- console.error('Not authenticated. Please log in first.');
20
- console.error('');
21
- console.error('Run: guild auth login');
21
+ output.error('Not authenticated. Please log in first.', 'Run: guild auth login');
22
22
  process.exit(1);
23
23
  }
24
24
  if (formattedError.code === ErrorCodes.CONN_REFUSED) {
25
- console.error(`Failed to get workspace: ${formattedError.details}`);
26
- console.error('');
27
- console.error('Run with --debug for more details');
25
+ output.error(`Failed to get workspace: ${formattedError.details}`, 'Run with --debug for more details');
28
26
  process.exit(1);
29
27
  }
30
28
  if (formattedError.code === ErrorCodes.NOT_FOUND) {
31
- console.error(`Workspace not found: ${id}`);
32
- console.error('');
33
- console.error('Run: guild workspace list');
29
+ output.error(`Workspace not found: ${id}`, 'Run: guild workspace list');
34
30
  process.exit(1);
35
31
  }
36
- console.error(`Failed to get workspace: ${formattedError.details}`);
32
+ output.error(`Failed to get workspace: ${formattedError.details}`);
37
33
  process.exit(1);
38
34
  }
39
35
  });
@@ -3,7 +3,7 @@ import { Command } from 'commander';
3
3
  import { GuildAPIClient } from '../../lib/api-client.js';
4
4
  import { handleAxiosError, ErrorCodes } from '../../lib/errors.js';
5
5
  import { getOutputMode } from '../../lib/output-mode.js';
6
- import { formatWorkspaceTable } from '../../lib/output.js';
6
+ import { createOutputWriter, formatWorkspaceTable } from '../../lib/output.js';
7
7
  export function createWorkspaceListCommand() {
8
8
  const cmd = new Command('list');
9
9
  cmd
@@ -11,6 +11,7 @@ export function createWorkspaceListCommand() {
11
11
  .option('--limit <number>', 'Number of results to return', '20')
12
12
  .option('--offset <number>', 'Offset for pagination', '0')
13
13
  .action(async (options) => {
14
+ const output = createOutputWriter();
14
15
  try {
15
16
  const client = new GuildAPIClient();
16
17
  const params = new URLSearchParams();
@@ -29,18 +30,14 @@ export function createWorkspaceListCommand() {
29
30
  catch (error) {
30
31
  const formattedError = handleAxiosError(error);
31
32
  if (formattedError.code === ErrorCodes.AUTH_REQUIRED) {
32
- console.error('Not authenticated. Please log in first.');
33
- console.error('');
34
- console.error('Run: guild auth login');
33
+ output.error('Not authenticated. Please log in first.', 'Run: guild auth login');
35
34
  process.exit(1);
36
35
  }
37
36
  if (formattedError.code === ErrorCodes.CONN_REFUSED) {
38
- console.error(`Failed to list workspaces: ${formattedError.details}`);
39
- console.error('');
40
- console.error('Run with --debug for more details');
37
+ output.error(`Failed to list workspaces: ${formattedError.details}`, 'Run with --debug for more details');
41
38
  process.exit(1);
42
39
  }
43
- console.error(`Failed to list workspaces: ${formattedError.details}`);
40
+ output.error(`Failed to list workspaces: ${formattedError.details}`);
44
41
  process.exit(1);
45
42
  }
46
43
  });