@guildai/cli 0.10.0 → 0.12.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 (203) hide show
  1. package/dist/auth-CRMO5O3N.js +29 -0
  2. package/dist/auth-CRMO5O3N.js.map +7 -0
  3. package/dist/chat-5VX2WJH2.js +303 -0
  4. package/dist/chat-5VX2WJH2.js.map +7 -0
  5. package/dist/chat-SIKDYZQK.js +31 -0
  6. package/dist/chat-SIKDYZQK.js.map +7 -0
  7. package/dist/chunk-56YCMGL3.js +522 -0
  8. package/dist/chunk-56YCMGL3.js.map +7 -0
  9. package/dist/chunk-6EX6E7WP.js +7042 -0
  10. package/dist/chunk-6EX6E7WP.js.map +7 -0
  11. package/dist/chunk-B7VAF5UG.js +532 -0
  12. package/dist/chunk-B7VAF5UG.js.map +7 -0
  13. package/dist/chunk-DOIYVBNY.js +3057 -0
  14. package/dist/chunk-DOIYVBNY.js.map +7 -0
  15. package/dist/chunk-ENKEEJ45.js +17 -0
  16. package/dist/chunk-ENKEEJ45.js.map +7 -0
  17. package/dist/chunk-IBRKVGMZ.js +97041 -0
  18. package/dist/chunk-IBRKVGMZ.js.map +7 -0
  19. package/dist/chunk-LFMQJOKC.js +19778 -0
  20. package/dist/chunk-LFMQJOKC.js.map +7 -0
  21. package/dist/chunk-M347HP6M.js +22896 -0
  22. package/dist/chunk-M347HP6M.js.map +7 -0
  23. package/dist/chunk-OYQ476FQ.js +44 -0
  24. package/dist/chunk-OYQ476FQ.js.map +7 -0
  25. package/dist/chunk-PNCUR4OB.js +257 -0
  26. package/dist/chunk-PNCUR4OB.js.map +7 -0
  27. package/dist/chunk-RIG2HZWM.js +317 -0
  28. package/dist/chunk-RIG2HZWM.js.map +7 -0
  29. package/dist/chunk-SPZPZXUN.js +826 -0
  30. package/dist/chunk-SPZPZXUN.js.map +7 -0
  31. package/dist/chunk-VVSOU6ON.js +53 -0
  32. package/dist/chunk-VVSOU6ON.js.map +7 -0
  33. package/dist/chunk-X3ADGWOF.js +3643 -0
  34. package/dist/chunk-X3ADGWOF.js.map +7 -0
  35. package/dist/commands/agent/logs.d.ts +3 -0
  36. package/dist/commands/setup.d.ts +16 -0
  37. package/dist/commands/skill/create.d.ts +3 -0
  38. package/dist/commands/skill/get.d.ts +3 -0
  39. package/dist/commands/skill/list.d.ts +3 -0
  40. package/dist/commands/skill/update.d.ts +3 -0
  41. package/dist/commands/skill/version/create.d.ts +3 -0
  42. package/dist/commands/skill/version/get.d.ts +3 -0
  43. package/dist/commands/skill/version/list.d.ts +3 -0
  44. package/dist/devtools-AO7YSDOD.js +67 -0
  45. package/dist/devtools-AO7YSDOD.js.map +7 -0
  46. package/dist/dist-4CBK6X5H.js +1566 -0
  47. package/dist/dist-4CBK6X5H.js.map +7 -0
  48. package/dist/esm-FRAVZP4J.js +13 -0
  49. package/dist/esm-FRAVZP4J.js.map +7 -0
  50. package/dist/execa-XQMWSABC.js +35 -0
  51. package/dist/execa-XQMWSABC.js.map +7 -0
  52. package/dist/index.js +8231 -253
  53. package/dist/index.js.map +7 -0
  54. package/dist/lib/api-types.d.ts +44 -0
  55. package/dist/lib/auth.d.ts +1 -1
  56. package/dist/lib/config.d.ts +9 -0
  57. package/dist/lib/errors.d.ts +1 -1
  58. package/dist/lib/output-mode.d.ts +9 -2
  59. package/dist/lib/output.d.ts +17 -1
  60. package/dist/lib/session-events.d.ts +14 -3
  61. package/dist/lib/session-polling.d.ts +24 -1
  62. package/dist/lib/session-resume.d.ts +15 -1
  63. package/dist/lib/stdin.d.ts +5 -1
  64. package/dist/lib/websocket-client.d.ts +46 -0
  65. package/dist/open-RF4X5MOP.js +13 -0
  66. package/dist/open-RF4X5MOP.js.map +7 -0
  67. package/dist/server-JYVH64FD.js +27659 -0
  68. package/dist/server-JYVH64FD.js.map +7 -0
  69. package/dist/test-SNIYRJ32.js +692 -0
  70. package/dist/test-SNIYRJ32.js.map +7 -0
  71. package/docs/skills/codex-agent-dev.md +2 -2
  72. package/package.json +8 -12
  73. package/dist/commands/agent/chat.js +0 -278
  74. package/dist/commands/agent/clone.js +0 -116
  75. package/dist/commands/agent/code.js +0 -87
  76. package/dist/commands/agent/fork.js +0 -218
  77. package/dist/commands/agent/get.js +0 -37
  78. package/dist/commands/agent/grep.js +0 -107
  79. package/dist/commands/agent/init.js +0 -390
  80. package/dist/commands/agent/list.js +0 -110
  81. package/dist/commands/agent/owners.js +0 -74
  82. package/dist/commands/agent/publish.js +0 -91
  83. package/dist/commands/agent/pull.js +0 -198
  84. package/dist/commands/agent/revalidate.js +0 -56
  85. package/dist/commands/agent/save.js +0 -346
  86. package/dist/commands/agent/search.js +0 -61
  87. package/dist/commands/agent/tags/add.js +0 -73
  88. package/dist/commands/agent/tags/list.js +0 -43
  89. package/dist/commands/agent/tags/remove.js +0 -84
  90. package/dist/commands/agent/tags/set.js +0 -71
  91. package/dist/commands/agent/test.js +0 -486
  92. package/dist/commands/agent/unpublish.js +0 -64
  93. package/dist/commands/agent/update.js +0 -110
  94. package/dist/commands/agent/versions.js +0 -55
  95. package/dist/commands/agent/workspaces.js +0 -54
  96. package/dist/commands/auth/login.js +0 -33
  97. package/dist/commands/auth/logout.js +0 -24
  98. package/dist/commands/auth/status.js +0 -38
  99. package/dist/commands/auth/token.js +0 -19
  100. package/dist/commands/chat.js +0 -1345
  101. package/dist/commands/config/get.js +0 -64
  102. package/dist/commands/config/list.js +0 -47
  103. package/dist/commands/config/path.js +0 -38
  104. package/dist/commands/config/set.js +0 -132
  105. package/dist/commands/credentials/endpoint-list.js +0 -88
  106. package/dist/commands/credentials/list.js +0 -50
  107. package/dist/commands/credentials/policy-create.js +0 -66
  108. package/dist/commands/credentials/policy-delete.js +0 -33
  109. package/dist/commands/credentials/policy-list.js +0 -45
  110. package/dist/commands/credentials/policy-update.js +0 -66
  111. package/dist/commands/doctor.js +0 -233
  112. package/dist/commands/integration/connect.js +0 -76
  113. package/dist/commands/integration/create.js +0 -298
  114. package/dist/commands/integration/get.js +0 -95
  115. package/dist/commands/integration/list.js +0 -62
  116. package/dist/commands/integration/operation/create.js +0 -164
  117. package/dist/commands/integration/operation/list.js +0 -92
  118. package/dist/commands/integration/update.js +0 -139
  119. package/dist/commands/integration/version/build.js +0 -86
  120. package/dist/commands/integration/version/create.js +0 -45
  121. package/dist/commands/integration/version/get.js +0 -72
  122. package/dist/commands/integration/version/list.js +0 -45
  123. package/dist/commands/integration/version/publish.js +0 -79
  124. package/dist/commands/integration/version/test.js +0 -104
  125. package/dist/commands/job/get-step.js +0 -40
  126. package/dist/commands/job/get.js +0 -44
  127. package/dist/commands/mcp.js +0 -34
  128. package/dist/commands/session/create.js +0 -59
  129. package/dist/commands/session/events.js +0 -56
  130. package/dist/commands/session/get.js +0 -33
  131. package/dist/commands/session/interrupt.js +0 -33
  132. package/dist/commands/session/list.js +0 -59
  133. package/dist/commands/session/send.js +0 -54
  134. package/dist/commands/session/tasks.js +0 -45
  135. package/dist/commands/setup.js +0 -230
  136. package/dist/commands/trigger/activate.js +0 -41
  137. package/dist/commands/trigger/create.js +0 -197
  138. package/dist/commands/trigger/deactivate.js +0 -41
  139. package/dist/commands/trigger/get.js +0 -33
  140. package/dist/commands/trigger/list.js +0 -57
  141. package/dist/commands/trigger/sessions.js +0 -48
  142. package/dist/commands/trigger/update.js +0 -128
  143. package/dist/commands/version.js +0 -24
  144. package/dist/commands/workspace/agent/add.js +0 -114
  145. package/dist/commands/workspace/agent/list.js +0 -78
  146. package/dist/commands/workspace/agent/remove.js +0 -78
  147. package/dist/commands/workspace/clear.js +0 -45
  148. package/dist/commands/workspace/context/edit.js +0 -107
  149. package/dist/commands/workspace/context/get.js +0 -47
  150. package/dist/commands/workspace/context/list.js +0 -51
  151. package/dist/commands/workspace/context/publish.js +0 -42
  152. package/dist/commands/workspace/create.js +0 -51
  153. package/dist/commands/workspace/current.js +0 -63
  154. package/dist/commands/workspace/get.js +0 -39
  155. package/dist/commands/workspace/list.js +0 -70
  156. package/dist/commands/workspace/select.js +0 -184
  157. package/dist/components/AgentInstallPrompt.js +0 -97
  158. package/dist/components/SplashAnimation.js +0 -321
  159. package/dist/components/TaskView.js +0 -268
  160. package/dist/lib/agent-helpers.js +0 -306
  161. package/dist/lib/alternate-screen.js +0 -59
  162. package/dist/lib/api-client.js +0 -154
  163. package/dist/lib/api-types.js +0 -10
  164. package/dist/lib/auth.js +0 -284
  165. package/dist/lib/braille-canvas.js +0 -321
  166. package/dist/lib/colors.js +0 -46
  167. package/dist/lib/config-cache.js +0 -45
  168. package/dist/lib/config.js +0 -153
  169. package/dist/lib/did-you-mean.js +0 -144
  170. package/dist/lib/errors.js +0 -375
  171. package/dist/lib/event-filter.js +0 -91
  172. package/dist/lib/generated-types.js +0 -56
  173. package/dist/lib/git.js +0 -176
  174. package/dist/lib/gk.js +0 -91
  175. package/dist/lib/guild-config.js +0 -178
  176. package/dist/lib/iap.js +0 -117
  177. package/dist/lib/integration-helpers.js +0 -38
  178. package/dist/lib/loading-messages.js +0 -72
  179. package/dist/lib/logo.js +0 -141
  180. package/dist/lib/lottie-serverside.js +0 -181
  181. package/dist/lib/markdown.js +0 -38
  182. package/dist/lib/npmrc.js +0 -59
  183. package/dist/lib/output-mode.js +0 -33
  184. package/dist/lib/output.js +0 -591
  185. package/dist/lib/owner-helpers.js +0 -112
  186. package/dist/lib/polling.js +0 -76
  187. package/dist/lib/progress.js +0 -324
  188. package/dist/lib/session-events-fetch.js +0 -25
  189. package/dist/lib/session-events.js +0 -112
  190. package/dist/lib/session-polling.js +0 -160
  191. package/dist/lib/session-resume.js +0 -96
  192. package/dist/lib/spinners.js +0 -770
  193. package/dist/lib/splash.js +0 -41
  194. package/dist/lib/stdin.js +0 -84
  195. package/dist/lib/svg-to-braille.js +0 -76
  196. package/dist/lib/table.js +0 -59
  197. package/dist/lib/update-check.js +0 -65
  198. package/dist/lib/validate-input-schema.js +0 -208
  199. package/dist/lib/version-helpers.js +0 -121
  200. package/dist/lib/workspace-helpers.js +0 -49
  201. package/dist/mcp/resources.js +0 -67
  202. package/dist/mcp/server.js +0 -64
  203. package/dist/mcp/tools.js +0 -753
@@ -1,218 +0,0 @@
1
- // Copyright 2026 Guild.ai
2
- // SPDX-License-Identifier: Apache-2.0
3
- import { Command } from 'commander';
4
- import { GuildAPIClient } from '../../lib/api-client.js';
5
- import { getAgentId, resolveAgentRef } from '../../lib/agent-helpers.js';
6
- import { handleAxiosError, ErrorCodes, debug } from '../../lib/errors.js';
7
- import * as fs from 'fs/promises';
8
- import * as readline from 'readline';
9
- import { runGit, GitError, formatGitError } from '../../lib/git.js';
10
- import { createOutputWriter } from '../../lib/output.js';
11
- import { resolveOwnerId } from '../../lib/owner-helpers.js';
12
- import { isInteractive } from '../../lib/stdin.js';
13
- async function promptForName() {
14
- const rl = readline.createInterface({
15
- input: process.stdin,
16
- output: process.stdout,
17
- });
18
- return new Promise((resolve) => {
19
- rl.question('Name for forked agent: ', (answer) => {
20
- rl.close();
21
- resolve(answer.trim());
22
- });
23
- });
24
- }
25
- async function promptForDescription(defaultDescription) {
26
- const rl = readline.createInterface({
27
- input: process.stdin,
28
- output: process.stdout,
29
- });
30
- return new Promise((resolve) => {
31
- rl.question(`Description (default: "${defaultDescription}"): `, (answer) => {
32
- rl.close();
33
- resolve(answer.trim() || defaultDescription);
34
- });
35
- });
36
- }
37
- async function isDirectoryEmpty(dirPath) {
38
- try {
39
- const files = await fs.readdir(dirPath);
40
- return files.length === 0;
41
- }
42
- catch {
43
- // Directory doesn't exist, that's fine
44
- return true;
45
- }
46
- }
47
- export function createAgentForkCommand() {
48
- const cmd = new Command('fork');
49
- cmd
50
- .description('Fork an existing agent version to create a new agent')
51
- .argument('[identifier]', 'Agent ID, full name, or agent:version (e.g., owner~agent-name:version_xyz)')
52
- .option('--name <name>', 'Name for the forked agent')
53
- .option('--description <desc>', 'Description for the forked agent')
54
- .option('--directory <path>', 'Target directory for clone')
55
- .option('--owner <owner>', 'Owner (name or ID)')
56
- .action(async (identifierArg, options) => {
57
- const output = createOutputWriter();
58
- try {
59
- // Resolve agent ID and optional version ID
60
- let sourceAgentId;
61
- let sourceVersionId;
62
- if (identifierArg && identifierArg.includes(':')) {
63
- // Explicit agent:version format
64
- const colonIndex = identifierArg.lastIndexOf(':');
65
- const agentPart = identifierArg.substring(0, colonIndex);
66
- sourceVersionId = identifierArg.substring(colonIndex + 1);
67
- if (!agentPart || !sourceVersionId) {
68
- output.error('Error: Invalid argument format', 'Expected: [identifier] or [identifier]:[version-id]\nExample: guild agent fork owner~agent-name:version_xyz\n\nTo find versions:\n guild agent versions <agent-id>');
69
- process.exit(1);
70
- }
71
- const resolved = await getAgentId(agentPart);
72
- sourceAgentId = resolved.agentId;
73
- }
74
- else {
75
- // No version specified — resolve agent, then find latest published
76
- const resolved = await getAgentId(identifierArg);
77
- sourceAgentId = resolved.agentId;
78
- }
79
- // Auto-resolve version if not specified
80
- const client = new GuildAPIClient();
81
- sourceAgentId = await resolveAgentRef(client, sourceAgentId);
82
- if (!sourceVersionId) {
83
- const versions = await client.get(`/agents/${sourceAgentId}/versions`);
84
- const published = versions.items
85
- .filter((v) => v.status === 'PUBLISHED')
86
- .sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
87
- if (published.length === 0) {
88
- output.error('No published versions found', `Agent ${sourceAgentId} has no published versions to fork.\n\nTo see all versions:\n guild agent versions ${sourceAgentId}`);
89
- process.exit(1);
90
- }
91
- sourceVersionId = published[0].id;
92
- }
93
- // Determine name (validate before API call for better UX)
94
- let agentName = options.name;
95
- if (!agentName) {
96
- if (isInteractive()) {
97
- agentName = await promptForName();
98
- if (!agentName) {
99
- output.error('Error: Agent name is required');
100
- process.exit(1);
101
- }
102
- }
103
- else {
104
- output.error('Error: Agent name required in non-interactive mode', `Provide a name:\n guild agent fork ${identifierArg || '<identifier>'} --name my-forked-agent\n\nOr run interactively to be prompted.`);
105
- process.exit(1);
106
- }
107
- }
108
- // Validate name format (before API call)
109
- if (!/^[a-z0-9_-]{5,100}$/.test(agentName)) {
110
- output.error('Error: Invalid agent name', 'Name must:\n • Be between 5 and 100 characters\n • Only contain lowercase letters, numbers, hyphens, and underscores\n\nExamples: my-agent, weather_bot, agent-007');
111
- process.exit(1);
112
- }
113
- // Determine directory (default to agent name)
114
- const targetDir = options.directory || `./${agentName}`;
115
- // Check if directory exists and is empty (before API call)
116
- const dirExists = await fs
117
- .access(targetDir)
118
- .then(() => true)
119
- .catch(() => false);
120
- if (dirExists) {
121
- const isEmpty = await isDirectoryEmpty(targetDir);
122
- if (!isEmpty) {
123
- output.error(`Error: Directory '${targetDir}' already exists and is not empty`, `Choose a different directory:\n guild agent fork ${identifierArg || '<identifier>'} --directory ./different-path\n\nOr remove the existing directory first.`);
124
- process.exit(1);
125
- }
126
- }
127
- // Fetch source version from API (after local validations)
128
- const sourceVersion = await client.get(`/agents/${sourceAgentId}/versions/${sourceVersionId}`);
129
- output.progress(`✓ Fetched source version from '${sourceVersion.agent.name}' (${sourceVersionId.substring(0, 12)})`);
130
- // Determine description
131
- let description = options.description;
132
- if (!description) {
133
- if (isInteractive()) {
134
- description = await promptForDescription(sourceVersion.agent.description);
135
- }
136
- else {
137
- // Use source description in non-interactive mode
138
- description = sourceVersion.agent.description;
139
- }
140
- }
141
- // Resolve owner
142
- const owner = await resolveOwnerId({
143
- ownerFlag: options.owner,
144
- client,
145
- interactive: isInteractive(),
146
- requireExplicitOwner: true,
147
- });
148
- // Create forked agent
149
- output.progress(`✓ Forking agent '${agentName}'...`);
150
- const newAgent = await client.post('/agents', {
151
- name: agentName,
152
- description,
153
- forked_from_version: sourceVersionId,
154
- owner_id: owner.id,
155
- });
156
- output.progress(`✓ Agent created: ${newAgent.name} (${newAgent.id})`);
157
- // Poll until repository is ready
158
- output.progress('✓ Waiting for repository initialization...');
159
- let attempts = 0;
160
- const maxAttempts = 60; // 2 minutes
161
- let agent = newAgent;
162
- while (agent.status !== 'READY' &&
163
- agent.status !== 'FAILED' &&
164
- attempts < maxAttempts) {
165
- await new Promise((resolve) => setTimeout(resolve, 2000));
166
- agent = await client.get(`/agents/${newAgent.id}`);
167
- attempts++;
168
- debug(`Agent status: ${agent.status} (attempt ${attempts}/${maxAttempts})`);
169
- }
170
- if (agent.status === 'FAILED') {
171
- output.error('Error: Repository initialization failed', `The agent was created but the repository could not be initialized.\nCheck the agent status:\n guild agent get ${newAgent.id}`);
172
- process.exit(1);
173
- }
174
- if (agent.status !== 'READY') {
175
- output.error('Error: Timed out waiting for repository initialization', `The agent was created but the repository is not ready yet.\nCheck the status with:\n guild agent get ${newAgent.id}\n\nOnce ready, clone manually:\n guild agent clone ${newAgent.id} --directory ${targetDir}`);
176
- process.exit(1);
177
- }
178
- output.progress('✓ Repository ready!');
179
- if (!agent.git_url) {
180
- output.error('Error: Agent repository URL not available', `The agent was created but git_url is missing.\nCheck the agent details:\n guild agent get ${newAgent.id}`);
181
- process.exit(1);
182
- }
183
- // Clone the new repository
184
- await runGit(['clone', agent.git_url, targetDir]);
185
- output.progress(`✓ Cloned repository to ${targetDir}`);
186
- // Display next steps
187
- output.progress('');
188
- output.progress('Next steps:');
189
- output.progress(` 1. cd ${targetDir}`);
190
- output.progress(' 2. Make your changes to the code');
191
- output.progress(` 3. Run 'guild agent save --message "your changes"'`);
192
- output.progress(` 4. Run 'guild agent test' to test your changes`);
193
- }
194
- catch (error) {
195
- if (error instanceof GitError) {
196
- output.error('Error: Failed to clone repository', `${formatGitError(error)}\n\nThe agent was created successfully, but cloning failed.\nTry cloning manually:\n guild agent clone <agent-id>`);
197
- process.exit(1);
198
- }
199
- const formattedError = handleAxiosError(error);
200
- if (formattedError.code === ErrorCodes.AUTH_REQUIRED) {
201
- output.error('Not authenticated. Please log in first.', 'Run: guild auth login');
202
- process.exit(1);
203
- }
204
- if (formattedError.code === ErrorCodes.NOT_FOUND) {
205
- output.error(`Error: Agent or version not found: ${identifierArg || '<identifier>'}`, `Check available versions:\n guild agent versions <agent-id>`);
206
- process.exit(1);
207
- }
208
- if (formattedError.code === ErrorCodes.CONN_REFUSED) {
209
- output.error('Cannot connect to Guild servers');
210
- process.exit(1);
211
- }
212
- output.error(`Failed to fork agent: ${formattedError.details}`);
213
- process.exit(1);
214
- }
215
- });
216
- return cmd;
217
- }
218
- //# sourceMappingURL=fork.js.map
@@ -1,37 +0,0 @@
1
- // Copyright 2026 Guild.ai
2
- // SPDX-License-Identifier: Apache-2.0
3
- import { Command } from 'commander';
4
- import { GuildAPIClient } from '../../lib/api-client.js';
5
- import { getAuthToken } from '../../lib/auth.js';
6
- import { getAgentId, resolveAgentRef } from '../../lib/agent-helpers.js';
7
- import { handleAxiosError } from '../../lib/errors.js';
8
- import { createOutputWriter } from '../../lib/output.js';
9
- export function createAgentGetCommand() {
10
- const cmd = new Command('get');
11
- cmd
12
- .description('Get agent details')
13
- .argument('[identifier]', 'Agent ID or full name (e.g., owner~agent-name)')
14
- .action(async (idArg) => {
15
- const output = createOutputWriter();
16
- try {
17
- const token = await getAuthToken();
18
- if (!token) {
19
- output.error('Not authenticated. Please log in first.', 'Run: guild auth login');
20
- process.exit(1);
21
- }
22
- // Get agent ID from argument or guild.json
23
- const { agentId } = await getAgentId(idArg);
24
- const client = new GuildAPIClient();
25
- const resolvedId = await resolveAgentRef(client, agentId);
26
- const response = await client.get(`/agents/${resolvedId}`);
27
- output.data(response);
28
- }
29
- catch (error) {
30
- const formattedError = handleAxiosError(error);
31
- output.error(`Failed to get agent: ${formattedError.details}`);
32
- process.exit(1);
33
- }
34
- });
35
- return cmd;
36
- }
37
- //# sourceMappingURL=get.js.map
@@ -1,107 +0,0 @@
1
- // Copyright 2026 Guild.ai
2
- // SPDX-License-Identifier: Apache-2.0
3
- import { Command } from 'commander';
4
- import { GuildAPIClient } from '../../lib/api-client.js';
5
- import { getAuthToken } from '../../lib/auth.js';
6
- import { createOutputWriter } from '../../lib/output.js';
7
- import { handleAxiosError } from '../../lib/errors.js';
8
- import { loadLocalConfig } from '../../lib/guild-config.js';
9
- export function createAgentGrepCommand() {
10
- const cmd = new Command('grep');
11
- cmd
12
- .description('Search agent files for a matching pattern')
13
- .argument('[pattern]', 'JavaScript regex for which to search: all lines matching this pattern will be printed')
14
- .option('--all', 'Search all agents (default: current agent only)')
15
- .option('--published', 'Only search published agents (requires --all)')
16
- .action(grep);
17
- return cmd;
18
- }
19
- const BATCH_SIZE = 20;
20
- async function grep(patternArg, options) {
21
- const output = createOutputWriter();
22
- try {
23
- const token = await getAuthToken();
24
- if (!token) {
25
- output.error('Not authenticated. Please log in first.', 'Run: guild auth login');
26
- process.exit(1);
27
- }
28
- if (patternArg === undefined) {
29
- output.error('Please specify a pattern to match');
30
- process.exit(1);
31
- }
32
- let patternRE;
33
- try {
34
- patternRE = new RegExp(patternArg);
35
- }
36
- catch {
37
- output.error(`Invalid regex pattern: ${patternArg}`);
38
- process.exit(1);
39
- }
40
- const client = new GuildAPIClient();
41
- if (options.all) {
42
- await grepAllAgents(client, patternRE, options.published, output);
43
- }
44
- else {
45
- await grepCurrentAgent(client, patternRE, output);
46
- }
47
- }
48
- catch (error) {
49
- const formattedError = handleAxiosError(error);
50
- output.error(`Failed to search agents: ${formattedError.details}`);
51
- process.exit(1);
52
- }
53
- }
54
- function searchFiles(files, patternRE, prefix, output) {
55
- for (const { path, content } of files) {
56
- content.split('\n').forEach((line, lineNumber) => {
57
- if (patternRE.test(line)) {
58
- output.progress(`${prefix}${path}:${lineNumber + 1}:${line}`);
59
- }
60
- });
61
- }
62
- }
63
- async function grepCurrentAgent(client, patternRE, output) {
64
- const config = await loadLocalConfig();
65
- if (!config?.agent_id) {
66
- output.error('Not in an agent directory.', 'Either run from an agent directory with guild.json:\n cd <agent-directory>\n guild agent grep <pattern>\n\nOr search all agents:\n guild agent grep <pattern> --all');
67
- process.exit(1);
68
- }
69
- let files = [];
70
- try {
71
- files = await client.get(`/agents/${config.agent_id}/code`);
72
- }
73
- catch (ex) {
74
- const formattedError = handleAxiosError(ex);
75
- output.error(`Failed to fetch agent code: ${formattedError.details}`);
76
- process.exit(1);
77
- }
78
- searchFiles(files, patternRE, '', output);
79
- }
80
- async function grepAllAgents(client, patternRE, publishedOnly, output) {
81
- let offset = 0;
82
- while (true) {
83
- const params = new URLSearchParams();
84
- params.append('offset', `${offset}`);
85
- params.append('limit', `${BATCH_SIZE}`);
86
- if (publishedOnly) {
87
- params.append('published_only', 'true');
88
- }
89
- const response = await client.get(`/agents?${params.toString()}`);
90
- await Promise.all(response.items.map(async (agent) => {
91
- let files = [];
92
- try {
93
- files = await client.get(`/agents/${agent.id}/code`);
94
- }
95
- catch (ex) {
96
- const formattedError = handleAxiosError(ex);
97
- output.error(`${agent.owner?.name}~${agent.name}: ${formattedError.details}`);
98
- return;
99
- }
100
- searchFiles(files, patternRE, `${agent.owner?.name}~${agent.name}/`, output);
101
- }));
102
- offset += response.pagination.limit;
103
- if (!response.pagination.has_more)
104
- break;
105
- }
106
- }
107
- //# sourceMappingURL=grep.js.map