@guildai/cli 0.6.0 → 0.6.2

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 (59) hide show
  1. package/README.md +17 -0
  2. package/dist/commands/agent/chat.js +31 -31
  3. package/dist/commands/agent/fork.js +1 -1
  4. package/dist/commands/agent/init.js +1 -1
  5. package/dist/commands/agent/publish.js +13 -53
  6. package/dist/commands/agent/pull.js +36 -21
  7. package/dist/commands/agent/save.js +16 -52
  8. package/dist/commands/agent/test.js +8 -12
  9. package/dist/commands/auth/login.js +3 -3
  10. package/dist/commands/chat.js +68 -106
  11. package/dist/commands/credentials/endpoint-list.js +1 -1
  12. package/dist/commands/integration/connect.d.ts +3 -0
  13. package/dist/commands/integration/connect.js +76 -0
  14. package/dist/commands/integration/create.d.ts +3 -0
  15. package/dist/commands/integration/create.js +298 -0
  16. package/dist/commands/integration/get.d.ts +3 -0
  17. package/dist/commands/integration/get.js +95 -0
  18. package/dist/commands/integration/list.d.ts +3 -0
  19. package/dist/commands/integration/list.js +61 -0
  20. package/dist/commands/integration/operation/create.d.ts +3 -0
  21. package/dist/commands/integration/operation/create.js +163 -0
  22. package/dist/commands/integration/operation/list.d.ts +3 -0
  23. package/dist/commands/integration/operation/list.js +83 -0
  24. package/dist/commands/integration/update.d.ts +3 -0
  25. package/dist/commands/integration/update.js +139 -0
  26. package/dist/commands/integration/version/build.d.ts +3 -0
  27. package/dist/commands/integration/version/build.js +86 -0
  28. package/dist/commands/integration/version/create.d.ts +3 -0
  29. package/dist/commands/integration/version/create.js +45 -0
  30. package/dist/commands/integration/version/get.d.ts +3 -0
  31. package/dist/commands/integration/version/get.js +72 -0
  32. package/dist/commands/integration/version/list.d.ts +3 -0
  33. package/dist/commands/integration/version/list.js +44 -0
  34. package/dist/commands/integration/version/publish.d.ts +3 -0
  35. package/dist/commands/integration/version/publish.js +79 -0
  36. package/dist/commands/integration/version/test.d.ts +3 -0
  37. package/dist/commands/integration/version/test.js +104 -0
  38. package/dist/commands/workspace/create.js +10 -4
  39. package/dist/index.js +38 -0
  40. package/dist/lib/api-types.d.ts +69 -12
  41. package/dist/lib/auth.d.ts +1 -1
  42. package/dist/lib/auth.js +3 -2
  43. package/dist/lib/integration-helpers.d.ts +15 -0
  44. package/dist/lib/integration-helpers.js +38 -0
  45. package/dist/lib/output.d.ts +11 -1
  46. package/dist/lib/output.js +94 -0
  47. package/dist/lib/session-events-fetch.d.ts +27 -0
  48. package/dist/lib/session-events-fetch.js +25 -0
  49. package/dist/lib/session-polling.d.ts +7 -2
  50. package/dist/lib/session-polling.js +19 -12
  51. package/dist/lib/session-resume.js +2 -5
  52. package/dist/lib/table.d.ts +0 -1
  53. package/dist/lib/table.js +0 -1
  54. package/dist/lib/version-helpers.d.ts +15 -0
  55. package/dist/lib/version-helpers.js +83 -0
  56. package/dist/mcp/tools.js +6 -12
  57. package/docs/CLI_WORKFLOW.md +15 -0
  58. package/docs/skills/agent-dev.md +15 -0
  59. package/package.json +4 -3
@@ -15,6 +15,7 @@ import path from 'path';
15
15
  import { fileURLToPath } from 'url';
16
16
  import { isUnfulfilledAgentInstallRequest, isFilteredTaskName, getTaskDisplayName, matchesAgent, getAgentName, } from '../lib/session-events.js';
17
17
  import { printResumeHint, fetchSession, fetchSessionEvents, eventsToDisplayMessages, } from '../lib/session-resume.js';
18
+ import { fetchEvents, fetchTasks } from '../lib/session-events-fetch.js';
18
19
  import { AgentInstallPrompt } from '../components/AgentInstallPrompt.js';
19
20
  import { getWorkspaceId } from '../lib/guild-config.js';
20
21
  import { ensureInteractiveStdin } from '../lib/stdin.js';
@@ -46,6 +47,35 @@ function fixListItemMarkdown(text) {
46
47
  text = text.replace(/(?<![\\w])_([^_]+)_(?![\\w])/g, (_, content) => chalk.italic(content));
47
48
  return text;
48
49
  }
50
+ /**
51
+ * Output the result of a --once mode session.
52
+ * Handles both JSON and human-readable output formats.
53
+ */
54
+ async function outputOnceResult(sessionId, events, mode) {
55
+ if (mode === 'json') {
56
+ console.log(JSON.stringify({ session_id: sessionId, events }, null, 2));
57
+ }
58
+ else {
59
+ const agentMessages = events.filter((e) => e.type === 'agent_notification_message');
60
+ if (agentMessages.length > 0) {
61
+ let messageContent = agentMessages[agentMessages.length - 1].content.data;
62
+ const trimmed = messageContent.trim();
63
+ if (trimmed.startsWith('{') && trimmed.endsWith('}')) {
64
+ try {
65
+ const parsed = JSON.parse(trimmed);
66
+ if (typeof parsed === 'object' && parsed !== null && 'message' in parsed) {
67
+ messageContent = parsed.message;
68
+ }
69
+ }
70
+ catch {
71
+ // If parsing fails, use content as-is
72
+ }
73
+ }
74
+ const rendered = fixListItemMarkdown(await marked(messageContent));
75
+ console.log(rendered.trim());
76
+ }
77
+ }
78
+ }
49
79
  import { createSpinner as createAnimatedSpinner, createRandomSpinner, } from '../lib/spinners.js';
50
80
  function CustomInput({ value, onChange, onSubmit, trackedTasksSize, setShowTaskPanel, isActive, }) {
51
81
  useInput((input, key) => {
@@ -146,6 +176,16 @@ export function ChatApp({ initialPrompt, version, workspaceId, versionId, agentN
146
176
  initialDelay: 500,
147
177
  maxDelay: 5000,
148
178
  backoffMultiplier: 1.5,
179
+ shouldRetry: (error) => {
180
+ if (typeof error === 'object' && error !== null) {
181
+ const err = error;
182
+ return (err.code === 'ECONNREFUSED' ||
183
+ err.code === 'ETIMEDOUT' ||
184
+ err.code === 'ENOTFOUND' ||
185
+ err.code === 'ECONNABORTED');
186
+ }
187
+ return false;
188
+ },
149
189
  });
150
190
  setConnectedClient(client);
151
191
  setConnectedSession(session);
@@ -382,7 +422,7 @@ function ChatUIWithConnection({ initialPrompt, version: _version, versionId: _ve
382
422
  const sentMessages = useRef(new Set());
383
423
  const pollInterval = useRef(null);
384
424
  const spinnerInterval = useRef(null);
385
- const lastMessageCountRef = useRef(resumeEvents?.length || 0);
425
+ const lastEventIdRef = useRef(resumeEvents?.length ? resumeEvents[resumeEvents.length - 1].id : undefined);
386
426
  const isPolling = useRef(false);
387
427
  const receivedResponseSinceLastInput = useRef(false);
388
428
  const firstMessageNotified = useRef(!!resumeEvents);
@@ -435,10 +475,7 @@ function ChatUIWithConnection({ initialPrompt, version: _version, versionId: _ve
435
475
  return;
436
476
  isPollingTasks.current = true;
437
477
  try {
438
- const response = await client.get(`/sessions/${session.id}/tasks?limit=1000`);
439
- const tasksList = (Array.isArray(response)
440
- ? response
441
- : response?.items || []);
478
+ const tasksList = await fetchTasks(client, session.id);
442
479
  setTasks(tasksList);
443
480
  }
444
481
  catch (error) {
@@ -448,9 +485,9 @@ function ChatUIWithConnection({ initialPrompt, version: _version, versionId: _ve
448
485
  isPollingTasks.current = false;
449
486
  }
450
487
  };
451
- // Poll immediately and then every second (like web)
488
+ // Poll immediately and then every 2 seconds
452
489
  pollTasks();
453
- const interval = setInterval(pollTasks, 1000);
490
+ const interval = setInterval(pollTasks, 2000);
454
491
  return () => {
455
492
  clearInterval(interval);
456
493
  };
@@ -463,20 +500,14 @@ function ChatUIWithConnection({ initialPrompt, version: _version, versionId: _ve
463
500
  if (isPolling.current)
464
501
  return;
465
502
  isPolling.current = true;
466
- debug(`poll() called, session=${session.id}`);
503
+ debug(`poll() called, session=${session.id}, fromId=${lastEventIdRef.current}`);
467
504
  try {
468
- const response = await client.get(`/sessions/${session.id}/events?limit=1000`);
469
- // Debug: log raw response structure
470
- const keys = response ? Object.keys(response) : [];
471
- debug(`Response: isArray=${Array.isArray(response)}, keys=${keys.join(',')}, type=${typeof response}`);
472
- const allEvents = (Array.isArray(response)
473
- ? response
474
- : response?.items || []);
475
- const newEvents = allEvents.slice(lastMessageCountRef.current);
476
- // Debug: log event counts
477
- debug(`Events: total=${allEvents.length}, lastCount=${lastMessageCountRef.current}, new=${newEvents.length}`);
505
+ const newEvents = await fetchEvents(client, session.id, {
506
+ fromId: lastEventIdRef.current,
507
+ });
508
+ debug(`Events: fromId=${lastEventIdRef.current}, new=${newEvents.length}`);
478
509
  if (newEvents.length > 0) {
479
- lastMessageCountRef.current = allEvents.length;
510
+ lastEventIdRef.current = newEvents[newEvents.length - 1].id;
480
511
  for (const event of newEvents) {
481
512
  // Track task from event if present
482
513
  const taskInfo = event.task;
@@ -653,7 +684,7 @@ function ChatUIWithConnection({ initialPrompt, version: _version, versionId: _ve
653
684
  isPolling.current = false;
654
685
  }
655
686
  };
656
- pollInterval.current = setInterval(poll, 500);
687
+ pollInterval.current = setInterval(poll, 2000);
657
688
  poll();
658
689
  return () => {
659
690
  if (pollInterval.current) {
@@ -919,7 +950,7 @@ export function createChatCommand() {
919
950
  .option('--workspace <identifier>', 'Workspace ID or full name (e.g., owner/workspace-name)')
920
951
  .option('--no-splash', 'Skip the splash screen animation')
921
952
  .option('--resume <session-id>', 'Resume an existing session')
922
- .addHelpText('after', '\nTo chat with the agent you are developing, use: guild agent chat')
953
+ .addHelpText('after', '\nTo chat with a local agent under development: guild agent chat')
923
954
  .action(async (promptArgs, options) => {
924
955
  const initialPrompt = promptArgs.length > 0 ? promptArgs.join(' ') : 'Hello';
925
956
  if (options.once) {
@@ -941,21 +972,17 @@ export function createChatCommand() {
941
972
  // Timeout after 5 minutes of INACTIVITY (no new messages)
942
973
  // Agent initialization can take 1-2 minutes with no events
943
974
  const inactivityTimeoutMs = 300000; // 5 minutes
944
- const pollIntervalMs = 500;
975
+ const pollIntervalMs = 2000;
945
976
  const maxInactivityAttempts = inactivityTimeoutMs / pollIntervalMs;
946
- let lastMessageCount = 0;
977
+ let lastSeenEventId;
978
+ const allEvents = [];
947
979
  let inactivityCounter = 0;
948
980
  while (true) {
949
981
  await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
950
- const response = await client.get(`/sessions/${session.id}/events?limit=1000`);
951
- // Handle both array and paginated object responses (backend may return either)
952
- const events = (Array.isArray(response)
953
- ? response
954
- : response?.items || []);
955
- // Check if we got new events (reset inactivity counter)
956
- if (events.length > lastMessageCount) {
957
- // Debug: log all new events
958
- const newEvents = events.slice(lastMessageCount);
982
+ const newEvents = await fetchEvents(client, session.id, {
983
+ fromId: lastSeenEventId,
984
+ });
985
+ if (newEvents.length > 0) {
959
986
  for (const evt of newEvents) {
960
987
  const taskInfo = evt.task;
961
988
  if (taskInfo) {
@@ -965,8 +992,9 @@ export function createChatCommand() {
965
992
  debug(`Event: ${evt.type} (no task info)`);
966
993
  }
967
994
  }
968
- lastMessageCount = events.length;
969
- inactivityCounter = 0; // Reset - we got activity!
995
+ allEvents.push(...newEvents);
996
+ lastSeenEventId = newEvents[newEvents.length - 1].id;
997
+ inactivityCounter = 0;
970
998
  }
971
999
  else {
972
1000
  inactivityCounter++;
@@ -976,93 +1004,27 @@ export function createChatCommand() {
976
1004
  // For orchestrating agents like agent-builder that spawn child tasks, we need to
977
1005
  // wait for the root agent's completion, not just any runtime_done event.
978
1006
  const targetAgent = options.agent || 'assistant';
979
- const hasRootTaskDone = events.some((e) => e.type === 'runtime_done' &&
1007
+ const hasRootTaskDone = allEvents.some((e) => e.type === 'runtime_done' &&
980
1008
  matchesAgent(e.task?.agent, targetAgent) &&
981
1009
  !e.task?.parent_task_id // Root task has no parent
982
1010
  );
983
1011
  // Also check for agent_notification_message events from the root agent
984
- const hasAgentMessage = events.some((e) => e.type === 'agent_notification_message' &&
1012
+ const hasAgentMessage = allEvents.some((e) => e.type === 'agent_notification_message' &&
985
1013
  matchesAgent(e.task?.agent, targetAgent) &&
986
1014
  !e.task?.parent_task_id);
987
1015
  // Check for a ui_prompt request... that ends the game.
988
- const hasUIPromptMessage = events.some((e) => e.type === 'agent_notification_message' &&
1016
+ const hasUIPromptMessage = allEvents.some((e) => e.type === 'agent_notification_message' &&
989
1017
  e.task?.tool_name === 'ui_prompt');
990
1018
  if (hasRootTaskDone || hasAgentMessage || hasUIPromptMessage) {
991
1019
  debug(`Found completion event from root agent (${targetAgent}), exiting --once mode`);
992
- // Output format depends on --mode flag
993
- if (options.mode === 'json') {
994
- // JSON mode: output structured events
995
- console.log(JSON.stringify({
996
- session_id: session.id,
997
- events: events,
998
- }, null, 2));
999
- }
1000
- else {
1001
- // Human-readable mode (default): extract and render message content
1002
- const agentMessages = events.filter((e) => e.type === 'agent_notification_message');
1003
- if (agentMessages.length > 0) {
1004
- // Get the last message content
1005
- let messageContent = agentMessages[agentMessages.length - 1].content.data;
1006
- // Handle JSON {"message": "..."} wrapper
1007
- const trimmed = messageContent.trim();
1008
- if (trimmed.startsWith('{') && trimmed.endsWith('}')) {
1009
- try {
1010
- const parsed = JSON.parse(trimmed);
1011
- if (typeof parsed === 'object' &&
1012
- parsed !== null &&
1013
- 'message' in parsed) {
1014
- messageContent = parsed.message;
1015
- }
1016
- }
1017
- catch {
1018
- // If parsing fails, use content as-is
1019
- }
1020
- }
1021
- // Render markdown and output
1022
- const rendered = fixListItemMarkdown(await marked(messageContent));
1023
- console.log(rendered.trim());
1024
- }
1025
- }
1020
+ await outputOnceResult(session.id, allEvents, options.mode);
1026
1021
  process.exit(0);
1027
1022
  }
1028
1023
  // Timeout if no activity for too long
1029
1024
  if (inactivityCounter >= maxInactivityAttempts) {
1030
1025
  debug(`Inactivity timeout reached (${maxInactivityAttempts} attempts with no new events)`);
1031
- debug(`Exiting with ${events.length} events total`);
1032
- // Output format depends on --mode flag
1033
- if (options.mode === 'json') {
1034
- // JSON mode: output structured events
1035
- console.log(JSON.stringify({
1036
- session_id: session.id,
1037
- events: events,
1038
- }, null, 2));
1039
- }
1040
- else {
1041
- // Human-readable mode (default): extract and render message content
1042
- const agentMessages = events.filter((e) => e.type === 'agent_notification_message');
1043
- if (agentMessages.length > 0) {
1044
- // Get the last message content
1045
- let messageContent = agentMessages[agentMessages.length - 1].content.data;
1046
- // Handle JSON {"message": "..."} wrapper
1047
- const trimmed = messageContent.trim();
1048
- if (trimmed.startsWith('{') && trimmed.endsWith('}')) {
1049
- try {
1050
- const parsed = JSON.parse(trimmed);
1051
- if (typeof parsed === 'object' &&
1052
- parsed !== null &&
1053
- 'message' in parsed) {
1054
- messageContent = parsed.message;
1055
- }
1056
- }
1057
- catch {
1058
- // If parsing fails, use content as-is
1059
- }
1060
- }
1061
- // Render markdown and output
1062
- const rendered = fixListItemMarkdown(await marked(messageContent));
1063
- console.log(rendered.trim());
1064
- }
1065
- }
1026
+ debug(`Exiting with ${allEvents.length} events total`);
1027
+ await outputOnceResult(session.id, allEvents, options.mode);
1066
1028
  process.exit(0);
1067
1029
  }
1068
1030
  }
@@ -35,7 +35,7 @@ export function createCredentialsEndpointListCommand() {
35
35
  if (options.search) {
36
36
  params.append('search', options.search);
37
37
  }
38
- const response = await client.get(`/credentials/${credentialId}/endpoints/new?${params.toString()}`);
38
+ const response = await client.get(`/credentials/${credentialId}/endpoints?${params.toString()}`);
39
39
  if (getOutputMode() === 'json') {
40
40
  console.log(JSON.stringify(response, null, 2));
41
41
  }
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ export declare function createIntegrationConnectCommand(): Command;
3
+ //# sourceMappingURL=connect.d.ts.map
@@ -0,0 +1,76 @@
1
+ // Copyright 2026 Guild.ai
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { Command } from 'commander';
4
+ import chalk from 'chalk';
5
+ import inquirer from 'inquirer';
6
+ import { GuildAPIClient } from '../../lib/api-client.js';
7
+ import { getAuthToken } from '../../lib/auth.js';
8
+ import { handleAxiosError } from '../../lib/errors.js';
9
+ import { getOutputMode } from '../../lib/output-mode.js';
10
+ import { createOutputWriter } from '../../lib/output.js';
11
+ import { isInteractive } from '../../lib/stdin.js';
12
+ export function createIntegrationConnectCommand() {
13
+ const cmd = new Command('connect');
14
+ cmd
15
+ .description('Connect credentials to an integration')
16
+ .argument('<id_or_name>', 'Integration ID (UUID) or name in owner~name format (e.g. myorg~my-integration)')
17
+ .option('--token <value>', 'API key value (required in non-interactive mode)')
18
+ .requiredOption('--owner <id_or_name>', 'Account to own the credential — username, org name, or account ID')
19
+ .action(async (identifier, options) => {
20
+ const output = createOutputWriter();
21
+ try {
22
+ const token = await getAuthToken();
23
+ if (!token) {
24
+ output.error('Not authenticated. Please log in first.', 'Run: guild auth login');
25
+ process.exit(1);
26
+ }
27
+ if (!options.token && !isInteractive()) {
28
+ output.error('--token is required in non-interactive mode');
29
+ process.exit(1);
30
+ }
31
+ const client = new GuildAPIClient();
32
+ const integration = await client.get(`/integrations/${identifier}`);
33
+ if (!integration.auth_config) {
34
+ output.error('This integration has no authentication configured.');
35
+ process.exit(1);
36
+ }
37
+ if (integration.auth_config.entity_type !== 'EntIntegrationAuthConfigApiKey') {
38
+ output.error('OAuth integrations must be connected via the dashboard.');
39
+ process.exit(1);
40
+ }
41
+ let apiKey = options.token;
42
+ if (!apiKey) {
43
+ const answer = await inquirer.prompt([
44
+ {
45
+ type: 'password',
46
+ name: 'apiKey',
47
+ message: 'API Key:',
48
+ validate: (input) => input.length > 0 || 'API key cannot be empty',
49
+ },
50
+ ]);
51
+ apiKey = answer.apiKey;
52
+ }
53
+ const params = new URLSearchParams();
54
+ params.append('auth_config_id', integration.auth_config.id);
55
+ params.append('owner_id', options.owner);
56
+ const credential = await client.post(`/credentials/api-key?${params.toString()}`, { tokens: { token: apiKey } });
57
+ if (getOutputMode() === 'json') {
58
+ output.data(credential);
59
+ }
60
+ else {
61
+ console.log(chalk.green('Connected to ') + chalk.bold(integration.name));
62
+ console.log();
63
+ console.log(` ${'Credential ID'.padEnd(15)}${credential.id}`);
64
+ console.log(` ${'Integration'.padEnd(15)}${integration.owner.name}~${integration.name}`);
65
+ console.log(` ${'Owner'.padEnd(15)}${options.owner}`);
66
+ }
67
+ }
68
+ catch (error) {
69
+ const formattedError = handleAxiosError(error);
70
+ output.error(`Failed to connect: ${formattedError.details}`);
71
+ process.exit(1);
72
+ }
73
+ });
74
+ return cmd;
75
+ }
76
+ //# sourceMappingURL=connect.js.map
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ export declare function createIntegrationCreateCommand(): Command;
3
+ //# sourceMappingURL=create.d.ts.map