@secretstartups/workshop 0.1.3 → 0.2.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 (175) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/README.md +198 -2
  3. package/dist/agent/agent-session.d.ts +60 -0
  4. package/dist/agent/agent-session.js +262 -0
  5. package/dist/agent/agent-session.js.map +1 -0
  6. package/dist/agent/agent.module.d.ts +2 -0
  7. package/dist/agent/agent.module.js +46 -0
  8. package/dist/agent/agent.module.js.map +1 -0
  9. package/dist/agent/build-api.service.d.ts +141 -0
  10. package/dist/agent/build-api.service.js +100 -0
  11. package/dist/agent/build-api.service.js.map +1 -0
  12. package/dist/agent/build-events.types.d.ts +172 -0
  13. package/dist/agent/build-events.types.js +11 -0
  14. package/dist/agent/build-events.types.js.map +1 -0
  15. package/dist/agent/commands/agent-diff.command.d.ts +17 -0
  16. package/dist/agent/commands/agent-diff.command.js +84 -0
  17. package/dist/agent/commands/agent-diff.command.js.map +1 -0
  18. package/dist/agent/commands/agent-files.command.d.ts +19 -0
  19. package/dist/agent/commands/agent-files.command.js +93 -0
  20. package/dist/agent/commands/agent-files.command.js.map +1 -0
  21. package/dist/agent/commands/agent-merge.command.d.ts +17 -0
  22. package/dist/agent/commands/agent-merge.command.js +101 -0
  23. package/dist/agent/commands/agent-merge.command.js.map +1 -0
  24. package/dist/agent/commands/agent-models.command.d.ts +14 -0
  25. package/dist/agent/commands/agent-models.command.js +49 -0
  26. package/dist/agent/commands/agent-models.command.js.map +1 -0
  27. package/dist/agent/commands/agent-resume.command.d.ts +14 -0
  28. package/dist/agent/commands/agent-resume.command.js +72 -0
  29. package/dist/agent/commands/agent-resume.command.js.map +1 -0
  30. package/dist/agent/commands/agent-rm.command.d.ts +16 -0
  31. package/dist/agent/commands/agent-rm.command.js +71 -0
  32. package/dist/agent/commands/agent-rm.command.js.map +1 -0
  33. package/dist/agent/commands/agent-sessions.command.d.ts +22 -0
  34. package/dist/agent/commands/agent-sessions.command.js +92 -0
  35. package/dist/agent/commands/agent-sessions.command.js.map +1 -0
  36. package/dist/agent/commands/agent.command.d.ts +65 -0
  37. package/dist/agent/commands/agent.command.js +819 -0
  38. package/dist/agent/commands/agent.command.js.map +1 -0
  39. package/dist/agent/executor/allowlist.d.ts +11 -0
  40. package/dist/agent/executor/allowlist.js +56 -0
  41. package/dist/agent/executor/allowlist.js.map +1 -0
  42. package/dist/agent/executor/approval.d.ts +24 -0
  43. package/dist/agent/executor/approval.js +90 -0
  44. package/dist/agent/executor/approval.js.map +1 -0
  45. package/dist/agent/executor/atomic-write.d.ts +9 -0
  46. package/dist/agent/executor/atomic-write.js +89 -0
  47. package/dist/agent/executor/atomic-write.js.map +1 -0
  48. package/dist/agent/executor/executor-client.d.ts +39 -0
  49. package/dist/agent/executor/executor-client.js +197 -0
  50. package/dist/agent/executor/executor-client.js.map +1 -0
  51. package/dist/agent/executor/executor.types.d.ts +97 -0
  52. package/dist/agent/executor/executor.types.js +10 -0
  53. package/dist/agent/executor/executor.types.js.map +1 -0
  54. package/dist/agent/executor/ops/file-ops.d.ts +8 -0
  55. package/dist/agent/executor/ops/file-ops.js +290 -0
  56. package/dist/agent/executor/ops/file-ops.js.map +1 -0
  57. package/dist/agent/executor/ops/run-command.d.ts +2 -0
  58. package/dist/agent/executor/ops/run-command.js +67 -0
  59. package/dist/agent/executor/ops/run-command.js.map +1 -0
  60. package/dist/agent/executor/roots.d.ts +9 -0
  61. package/dist/agent/executor/roots.js +140 -0
  62. package/dist/agent/executor/roots.js.map +1 -0
  63. package/dist/agent/executor/safe-path.d.ts +3 -0
  64. package/dist/agent/executor/safe-path.js +102 -0
  65. package/dist/agent/executor/safe-path.js.map +1 -0
  66. package/dist/agent/gates/gate-prompter.d.ts +21 -0
  67. package/dist/agent/gates/gate-prompter.js +189 -0
  68. package/dist/agent/gates/gate-prompter.js.map +1 -0
  69. package/dist/agent/prompt/cancellable.d.ts +5 -0
  70. package/dist/agent/prompt/cancellable.js +49 -0
  71. package/dist/agent/prompt/cancellable.js.map +1 -0
  72. package/dist/agent/prompt/mode-prompt.d.ts +14 -0
  73. package/dist/agent/prompt/mode-prompt.js +61 -0
  74. package/dist/agent/prompt/mode-prompt.js.map +1 -0
  75. package/dist/agent/render/diff-renderer.d.ts +14 -0
  76. package/dist/agent/render/diff-renderer.js +57 -0
  77. package/dist/agent/render/diff-renderer.js.map +1 -0
  78. package/dist/agent/render/event-renderer.d.ts +35 -0
  79. package/dist/agent/render/event-renderer.js +226 -0
  80. package/dist/agent/render/event-renderer.js.map +1 -0
  81. package/dist/agent/render/live-console.d.ts +17 -0
  82. package/dist/agent/render/live-console.js +84 -0
  83. package/dist/agent/render/live-console.js.map +1 -0
  84. package/dist/agent/render/plan-renderer.d.ts +2 -0
  85. package/dist/agent/render/plan-renderer.js +51 -0
  86. package/dist/agent/render/plan-renderer.js.map +1 -0
  87. package/dist/agent/render/run-summary.d.ts +13 -0
  88. package/dist/agent/render/run-summary.js +103 -0
  89. package/dist/agent/render/run-summary.js.map +1 -0
  90. package/dist/agent/render/sandbox-log.grouper.d.ts +10 -0
  91. package/dist/agent/render/sandbox-log.grouper.js +76 -0
  92. package/dist/agent/render/sandbox-log.grouper.js.map +1 -0
  93. package/dist/agent/slash-commands.d.ts +11 -0
  94. package/dist/agent/slash-commands.js +43 -0
  95. package/dist/agent/slash-commands.js.map +1 -0
  96. package/dist/agent/sse/build-stream.client.d.ts +20 -0
  97. package/dist/agent/sse/build-stream.client.js +206 -0
  98. package/dist/agent/sse/build-stream.client.js.map +1 -0
  99. package/dist/agent/sse/sse-parser.d.ts +11 -0
  100. package/dist/agent/sse/sse-parser.js +55 -0
  101. package/dist/agent/sse/sse-parser.js.map +1 -0
  102. package/dist/agent/target-resolver.d.ts +35 -0
  103. package/dist/agent/target-resolver.js +223 -0
  104. package/dist/agent/target-resolver.js.map +1 -0
  105. package/dist/app.module.js +4 -0
  106. package/dist/app.module.js.map +1 -1
  107. package/dist/auth/commands/login.command.d.ts +8 -0
  108. package/dist/auth/commands/login.command.js +115 -2
  109. package/dist/auth/commands/login.command.js.map +1 -1
  110. package/dist/auth/commands/token/token-create.command.d.ts +4 -0
  111. package/dist/auth/commands/token/token-create.command.js +91 -26
  112. package/dist/auth/commands/token/token-create.command.js.map +1 -1
  113. package/dist/clone/clone-runner.d.ts +26 -0
  114. package/dist/clone/clone-runner.js +108 -0
  115. package/dist/clone/clone-runner.js.map +1 -0
  116. package/dist/clone/clone.command.d.ts +30 -0
  117. package/dist/clone/clone.command.js +262 -0
  118. package/dist/clone/clone.command.js.map +1 -0
  119. package/dist/cluster/commands/cluster-delete.command.js +11 -11
  120. package/dist/cluster/commands/cluster-delete.command.js.map +1 -1
  121. package/dist/cluster/commands/cluster-install-local.command.d.ts +15 -0
  122. package/dist/cluster/commands/cluster-install-local.command.js +292 -22
  123. package/dist/cluster/commands/cluster-install-local.command.js.map +1 -1
  124. package/dist/cluster/commands/cluster.command.js +1 -1
  125. package/dist/cluster/commands/cluster.command.js.map +1 -1
  126. package/dist/cluster/kind-manager.d.ts +12 -1
  127. package/dist/cluster/kind-manager.js +55 -12
  128. package/dist/cluster/kind-manager.js.map +1 -1
  129. package/dist/common/api/api.service.d.ts +3 -1
  130. package/dist/common/api/api.service.js +13 -3
  131. package/dist/common/api/api.service.js.map +1 -1
  132. package/dist/common/config/cli-config.service.d.ts +28 -2
  133. package/dist/common/config/cli-config.service.js +37 -6
  134. package/dist/common/config/cli-config.service.js.map +1 -1
  135. package/dist/common/output/output.service.d.ts +1 -0
  136. package/dist/common/output/output.service.js +3 -0
  137. package/dist/common/output/output.service.js.map +1 -1
  138. package/dist/project/commands/project-use.command.d.ts +16 -0
  139. package/dist/project/commands/project-use.command.js +65 -0
  140. package/dist/project/commands/project-use.command.js.map +1 -0
  141. package/dist/project/commands/project.command.js +9 -1
  142. package/dist/project/commands/project.command.js.map +1 -1
  143. package/dist/project/project.module.js +2 -1
  144. package/dist/project/project.module.js.map +1 -1
  145. package/dist/service/commands/service-stop.command.js +12 -5
  146. package/dist/service/commands/service-stop.command.js.map +1 -1
  147. package/dist/tsconfig.build.tsbuildinfo +1 -1
  148. package/dist/vpn/commands/vpn-connect.command.d.ts +28 -0
  149. package/dist/vpn/commands/vpn-connect.command.js +213 -0
  150. package/dist/vpn/commands/vpn-connect.command.js.map +1 -0
  151. package/dist/vpn/commands/vpn-disconnect.command.d.ts +24 -0
  152. package/dist/vpn/commands/vpn-disconnect.command.js +149 -0
  153. package/dist/vpn/commands/vpn-disconnect.command.js.map +1 -0
  154. package/dist/vpn/commands/vpn-status.command.d.ts +18 -0
  155. package/dist/vpn/commands/vpn-status.command.js +94 -0
  156. package/dist/vpn/commands/vpn-status.command.js.map +1 -0
  157. package/dist/vpn/commands/vpn.command.d.ts +4 -0
  158. package/dist/vpn/commands/vpn.command.js +30 -0
  159. package/dist/vpn/commands/vpn.command.js.map +1 -0
  160. package/dist/vpn/kubectl-manager.d.ts +31 -0
  161. package/dist/vpn/kubectl-manager.js +276 -0
  162. package/dist/vpn/kubectl-manager.js.map +1 -0
  163. package/dist/vpn/vpn-api.d.ts +45 -0
  164. package/dist/vpn/vpn-api.js +51 -0
  165. package/dist/vpn/vpn-api.js.map +1 -0
  166. package/dist/vpn/vpn-connect.flow.d.ts +41 -0
  167. package/dist/vpn/vpn-connect.flow.js +172 -0
  168. package/dist/vpn/vpn-connect.flow.js.map +1 -0
  169. package/dist/vpn/vpn.module.d.ts +2 -0
  170. package/dist/vpn/vpn.module.js +23 -0
  171. package/dist/vpn/vpn.module.js.map +1 -0
  172. package/dist/vpn/wireguard-keys.d.ts +5 -0
  173. package/dist/vpn/wireguard-keys.js +12 -0
  174. package/dist/vpn/wireguard-keys.js.map +1 -0
  175. package/package.json +10 -3
@@ -0,0 +1,819 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ var AgentCommand_1;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.AgentCommand = void 0;
17
+ const nest_commander_1 = require("nest-commander");
18
+ const prompts_1 = require("@inquirer/prompts");
19
+ const child_process_1 = require("child_process");
20
+ const chalk_1 = __importDefault(require("chalk"));
21
+ const cli_config_service_1 = require("../../common/config/cli-config.service");
22
+ const output_service_1 = require("../../common/output/output.service");
23
+ const agent_session_1 = require("../agent-session");
24
+ const build_api_service_1 = require("../build-api.service");
25
+ const gate_prompter_1 = require("../gates/gate-prompter");
26
+ const live_console_1 = require("../render/live-console");
27
+ const build_stream_client_1 = require("../sse/build-stream.client");
28
+ const target_resolver_1 = require("../target-resolver");
29
+ const crypto_1 = require("crypto");
30
+ const slash_commands_1 = require("../slash-commands");
31
+ const cancellable_1 = require("../prompt/cancellable");
32
+ const executor_client_1 = require("../executor/executor-client");
33
+ const allowlist_1 = require("../executor/allowlist");
34
+ const approval_1 = require("../executor/approval");
35
+ const roots_1 = require("../executor/roots");
36
+ const executor_types_1 = require("../executor/executor.types");
37
+ const mode_prompt_1 = require("../prompt/mode-prompt");
38
+ const agent_diff_command_1 = require("./agent-diff.command");
39
+ const agent_files_command_1 = require("./agent-files.command");
40
+ const agent_merge_command_1 = require("./agent-merge.command");
41
+ const agent_models_command_1 = require("./agent-models.command");
42
+ const agent_resume_command_1 = require("./agent-resume.command");
43
+ const agent_rm_command_1 = require("./agent-rm.command");
44
+ const agent_sessions_command_1 = require("./agent-sessions.command");
45
+ const MODES = ['plan', 'auto', 'discuss'];
46
+ const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
47
+ const CANCEL = '__cancel__';
48
+ const HINT_LAUNCHES = 5;
49
+ let AgentCommand = AgentCommand_1 = class AgentCommand extends nest_commander_1.CommandRunner {
50
+ constructor(api, stream, gates, targets, config, output) {
51
+ super();
52
+ this.api = api;
53
+ this.stream = stream;
54
+ this.gates = gates;
55
+ this.targets = targets;
56
+ this.config = config;
57
+ this.output = output;
58
+ this.pendingRecap = false;
59
+ }
60
+ async run(_args, options = {}) {
61
+ const oneShot = typeof options.print === 'string';
62
+ const nonInteractive = oneShot || Boolean(options.json) || !process.stdout.isTTY;
63
+ if (options.json && !oneShot) {
64
+ return this.output.error('--json requires --print (a REPL cannot emit JSON).');
65
+ }
66
+ if (options.mode && !MODES.includes(options.mode)) {
67
+ return this.output.error(`Unknown mode '${options.mode}'. Use: ${MODES.join(', ')}.`);
68
+ }
69
+ let target;
70
+ try {
71
+ target = await this.targets.resolve({
72
+ workspace: options.workspace,
73
+ service: options.service,
74
+ project: options.project,
75
+ nonInteractive,
76
+ });
77
+ }
78
+ catch (err) {
79
+ if (err instanceof target_resolver_1.TargetCancelled || (0, cancellable_1.isCancellation)(err))
80
+ return;
81
+ if (err instanceof target_resolver_1.TargetUnresolvedError) {
82
+ console.error(chalk_1.default.red('✗') + ' ' + err.message);
83
+ process.exit(2);
84
+ }
85
+ return this.output.error(err.message);
86
+ }
87
+ this.config.setAgentTarget(target);
88
+ const defaults = this.config.getAgentDefaults();
89
+ const console_ = new live_console_1.LiveConsole({ spinner: options.spinner !== false && !options.json });
90
+ const verbosity = options.quiet ? -1 : (options.verbose ?? 0);
91
+ let executor;
92
+ if (options.local) {
93
+ executor = await this.buildExecutor(target, options, console_);
94
+ if (!executor)
95
+ return;
96
+ }
97
+ const session = new agent_session_1.AgentSession(target, this.api, this.stream, this.gates, console_, {
98
+ mode: options.mode ?? defaults.mode ?? 'plan',
99
+ modelId: options.model ?? defaults.modelId,
100
+ verbosity,
101
+ gates: { autoApprove: options.yes, nonInteractive },
102
+ executor,
103
+ });
104
+ if (options.resume) {
105
+ const ok = await this.attachSession(session, options, target.id);
106
+ if (!ok)
107
+ return;
108
+ }
109
+ if (oneShot)
110
+ return this.runOnce(session, options, console_);
111
+ return this.runRepl(session, console_);
112
+ }
113
+ async attachSession(session, options, _targetId) {
114
+ try {
115
+ const ref = typeof options.resume === 'string' ? options.resume : '';
116
+ const target = await this.resolveSessionRef(ref, session);
117
+ if (!target) {
118
+ this.output.warn('Starting a new session instead.');
119
+ return true;
120
+ }
121
+ await session.attach(target.id);
122
+ this.pendingRecap = true;
123
+ return true;
124
+ }
125
+ catch (err) {
126
+ this.output.error(`Could not resume: ${err.message}`);
127
+ return false;
128
+ }
129
+ }
130
+ async runOnce(session, options, console_) {
131
+ try {
132
+ const record = await session.runTurn(options.print);
133
+ if (options.json) {
134
+ console_.stop();
135
+ this.output.json(record);
136
+ }
137
+ if (record && record.status === 'failed')
138
+ process.exit(1);
139
+ }
140
+ catch (err) {
141
+ console_.stop();
142
+ if (err instanceof gate_prompter_1.GateAbort)
143
+ process.exit(2);
144
+ this.output.error(err.message);
145
+ }
146
+ }
147
+ async runRepl(session, console_) {
148
+ this.printBanner(session);
149
+ if (this.pendingRecap) {
150
+ this.printRecap(session);
151
+ this.pendingRecap = false;
152
+ }
153
+ const restore = () => process.stdout.write('[?25h');
154
+ process.on('exit', restore);
155
+ while (true) {
156
+ let answer;
157
+ try {
158
+ answer = await (0, mode_prompt_1.modePrompt)({
159
+ mode: session.mode,
160
+ local: Boolean(session.executorContext),
161
+ });
162
+ }
163
+ catch (err) {
164
+ if (err?.name === 'ExitPromptError') {
165
+ console_.stop();
166
+ this.printOutro(session);
167
+ restore();
168
+ process.exit(130);
169
+ }
170
+ throw err;
171
+ }
172
+ if (answer.mode !== session.mode) {
173
+ session.setMode(answer.mode);
174
+ this.config.setAgentDefaults({ mode: answer.mode });
175
+ }
176
+ const text = answer.value.trim();
177
+ if (!text)
178
+ continue;
179
+ const slash = (0, slash_commands_1.parseSlash)(text);
180
+ if (slash) {
181
+ let keepGoing = true;
182
+ try {
183
+ keepGoing = await this.handleSlash(slash, session, console_);
184
+ }
185
+ catch (err) {
186
+ console_.stop();
187
+ if ((0, cancellable_1.isCancellation)(err))
188
+ continue;
189
+ this.output.fail(err?.message ?? String(err));
190
+ }
191
+ if (!keepGoing) {
192
+ console_.stop();
193
+ this.printOutro(session);
194
+ restore();
195
+ return;
196
+ }
197
+ continue;
198
+ }
199
+ await this.runTurnInterruptibly(session, text, console_);
200
+ }
201
+ }
202
+ async runTurnInterruptibly(session, prompt, console_) {
203
+ const controller = new AbortController();
204
+ let lastInterrupt = 0;
205
+ const onSigint = () => {
206
+ const now = Date.now();
207
+ if (now - lastInterrupt < 2000) {
208
+ console_.stop();
209
+ process.stdout.write('[?25h');
210
+ process.exit(130);
211
+ }
212
+ lastInterrupt = now;
213
+ controller.abort();
214
+ console_.stop();
215
+ void session.detachExecutor('the user interrupted');
216
+ console.log(chalk_1.default.dim(`\nDetached. The build keeps running — workshop agent resume ${session.lastBuildId ?? ''}`));
217
+ };
218
+ process.on('SIGINT', onSigint);
219
+ try {
220
+ await session.runTurn(prompt, controller.signal);
221
+ }
222
+ catch (err) {
223
+ console_.stop();
224
+ if (!(err instanceof gate_prompter_1.GateAbort))
225
+ this.output.fail(err.message);
226
+ }
227
+ finally {
228
+ process.removeListener('SIGINT', onSigint);
229
+ }
230
+ }
231
+ async handleSlash(slash, session, console_) {
232
+ const { name, args } = slash;
233
+ const local = Boolean(session.executorContext);
234
+ switch (name) {
235
+ case 'exit':
236
+ case 'quit':
237
+ return false;
238
+ case 'help':
239
+ for (const line of (0, slash_commands_1.renderSlashHelp)())
240
+ console.log(line);
241
+ return true;
242
+ case 'clear':
243
+ process.stdout.write('c');
244
+ return true;
245
+ case 'mode': {
246
+ const mode = args[0]
247
+ ? args[0]
248
+ : await (0, cancellable_1.cancellable)((signal) => (0, prompts_1.select)({
249
+ message: 'Mode:',
250
+ default: session.mode,
251
+ choices: mode_prompt_1.MODE_CYCLE.map((m) => ({
252
+ name: `${m} ${chalk_1.default.dim((0, mode_prompt_1.modeDescription)(m, local))}`,
253
+ value: m,
254
+ })),
255
+ }, { signal }));
256
+ if (!MODES.includes(mode)) {
257
+ this.output.fail(`Unknown mode '${args[0]}'. Use: ${MODES.join(', ')}.`);
258
+ return true;
259
+ }
260
+ session.setMode(mode);
261
+ this.config.setAgentDefaults({ mode });
262
+ this.output.info(`Mode: ${(0, mode_prompt_1.modeBadge)(mode)} — ${(0, mode_prompt_1.modeDescription)(mode, local)}`);
263
+ return true;
264
+ }
265
+ case 'model': {
266
+ let modelId = args[0];
267
+ if (!modelId) {
268
+ const models = (await this.api.listModels()).filter((m) => m.enabled);
269
+ if (!models.length) {
270
+ this.output.fail('No models are available.');
271
+ return true;
272
+ }
273
+ modelId = await (0, cancellable_1.cancellable)((signal) => (0, prompts_1.select)({
274
+ message: 'Model:',
275
+ default: session.modelId,
276
+ pageSize: 12,
277
+ choices: models.map((m) => ({
278
+ name: `${m.label} ${chalk_1.default.dim(m.provider)}`,
279
+ value: m.id,
280
+ description: m.description,
281
+ })),
282
+ }, { signal }));
283
+ }
284
+ session.setModel(modelId);
285
+ this.config.setAgentDefaults({ modelId });
286
+ this.output.info(`Model: ${modelId}`);
287
+ return true;
288
+ }
289
+ case 'new':
290
+ session.reset();
291
+ this.output.info('Started a new session.');
292
+ return true;
293
+ case 'target': {
294
+ try {
295
+ const next = await this.targets.resolve({ force: true });
296
+ this.config.setAgentTarget(next);
297
+ session.setTarget(next);
298
+ this.output.info(`Now working on ${next.kind} ${chalk_1.default.bold(next.label)} — new session.`);
299
+ }
300
+ catch (err) {
301
+ if ((0, cancellable_1.isCancellation)(err))
302
+ return true;
303
+ this.output.fail(err.message);
304
+ }
305
+ return true;
306
+ }
307
+ case 'status':
308
+ this.output.keyValue({
309
+ Target: `${session.target.kind} ${session.target.label}`,
310
+ Mode: `${(0, mode_prompt_1.modeBadge)(session.mode)} — ${(0, mode_prompt_1.modeDescription)(session.mode, Boolean(session.executorContext))}`,
311
+ Model: session.modelId ?? 'default',
312
+ Session: session.sessionId ?? '—',
313
+ 'Last build': session.lastBuildId ?? '—',
314
+ Turns: session.turns.length,
315
+ });
316
+ return true;
317
+ case 'allow': {
318
+ const executor = session.executorContext;
319
+ if (!executor) {
320
+ this.output.fail('Not running locally — start with --local.');
321
+ return true;
322
+ }
323
+ const rule = args.join(' ').trim();
324
+ if (!rule) {
325
+ this.output.fail('Usage: /allow <command> (or "npm *" for a prefix)');
326
+ return true;
327
+ }
328
+ executor.allowlist.add(rule);
329
+ this.config.setAgentDefaults({
330
+ executorAllow: executor.allowlist.rules(),
331
+ });
332
+ this.output.info(`Allowed: ${rule}`);
333
+ return true;
334
+ }
335
+ case 'allowed': {
336
+ const rules = session.executorContext?.allowlist.rules() ?? [];
337
+ if (!rules.length) {
338
+ this.output.info('Nothing is pre-approved — every command will ask.');
339
+ return true;
340
+ }
341
+ rules.forEach((rule) => console.log(` ${rule}`));
342
+ return true;
343
+ }
344
+ case 'roots': {
345
+ const executor = session.executorContext;
346
+ if (!executor) {
347
+ this.output.info('Not running locally — the agent edits a copy and opens a PR.');
348
+ return true;
349
+ }
350
+ for (const root of executor.declaration.roots) {
351
+ console.log(` ${chalk_1.default.bold(root.slug)} ${chalk_1.default.dim(root.path)}`);
352
+ }
353
+ return true;
354
+ }
355
+ case 'pr': {
356
+ const urls = session.turns.flatMap((t) => t.prUrls);
357
+ if (!urls.length)
358
+ this.output.info('No pull requests opened yet.');
359
+ else
360
+ urls.forEach((u) => console.log(` ${chalk_1.default.underline(u)}`));
361
+ return true;
362
+ }
363
+ case 'sessions':
364
+ case 'resume': {
365
+ const ref = args.join(' ').trim();
366
+ try {
367
+ const target = await this.resolveSessionRef(ref, session);
368
+ if (!target)
369
+ return true;
370
+ await session.attach(target.id);
371
+ this.printRecap(session);
372
+ }
373
+ catch (err) {
374
+ this.output.fail(err.message);
375
+ }
376
+ return true;
377
+ }
378
+ case 'diff': {
379
+ const local = session.executorContext;
380
+ if (local) {
381
+ this.showLocalDiff(local.declaration.roots, args[0]);
382
+ return true;
383
+ }
384
+ if (!session.lastBuildId) {
385
+ this.output.fail('No turn yet in this session.');
386
+ return true;
387
+ }
388
+ await new agent_diff_command_1.AgentDiffCommand(this.api, this.output).show(session.lastBuildId, args[0]);
389
+ return true;
390
+ }
391
+ case 'files': {
392
+ if (!session.lastBuildId) {
393
+ this.output.fail('No turn yet in this session.');
394
+ return true;
395
+ }
396
+ await new agent_files_command_1.AgentFilesCommand(this.api, this.output).list(session.lastBuildId, args[0]);
397
+ return true;
398
+ }
399
+ case 'merge': {
400
+ const turn = session.lastTurnWithPrs();
401
+ if (!turn) {
402
+ this.output.fail(session.turns.length
403
+ ? 'No pull requests in this session yet.'
404
+ : 'No turn yet in this session.');
405
+ return true;
406
+ }
407
+ const all = args.includes('--all') || session.target.kind === 'workspace';
408
+ const merged = await new agent_merge_command_1.AgentMergeCommand(this.api, this.output).mergeBuild(turn.buildId, all);
409
+ session.markPrsSettled(merged);
410
+ return true;
411
+ }
412
+ case 'editor': {
413
+ const text = await (0, prompts_1.editor)({ message: 'Prompt:' });
414
+ if (text.trim())
415
+ await this.runTurnInterruptibly(session, text.trim(), console_);
416
+ return true;
417
+ }
418
+ default:
419
+ this.output.fail(`Unknown command /${name}. Try /help.`);
420
+ return true;
421
+ }
422
+ }
423
+ showLocalDiff(roots, only) {
424
+ const wanted = only
425
+ ? roots.filter((root) => root.slug === only)
426
+ : roots;
427
+ if (!wanted.length) {
428
+ this.output.fail(`No working tree called '${only}'. Try: ${roots.map((r) => r.slug).join(', ')}.`);
429
+ return;
430
+ }
431
+ for (const root of wanted) {
432
+ const shown = (0, child_process_1.spawnSync)('git', ['--no-pager', 'diff'], {
433
+ cwd: root.path,
434
+ stdio: ['ignore', 'inherit', 'inherit'],
435
+ });
436
+ if (shown.error) {
437
+ this.output.fail(`${root.slug}: ${shown.error.message}`);
438
+ }
439
+ }
440
+ }
441
+ async resolveSessionRef(ref, session) {
442
+ const listing = async () => {
443
+ const sessions = await this.api.listSessions(session.target.kind === 'workspace'
444
+ ? { workspaceId: session.target.id }
445
+ : { serviceId: session.target.id });
446
+ this.lastSessions = sessions.map((s) => ({
447
+ id: s.latest.id,
448
+ title: (s.title ?? s.sessionId).split('\n')[0],
449
+ detail: `${s.turnCount} turn${s.turnCount === 1 ? '' : 's'} · ${s.latest.status}`,
450
+ }));
451
+ return this.lastSessions;
452
+ };
453
+ if (!ref) {
454
+ const sessions = await listing();
455
+ if (!sessions.length) {
456
+ this.output.fail('No previous sessions for this target.');
457
+ return null;
458
+ }
459
+ if (!process.stdout.isTTY)
460
+ return sessions[0];
461
+ let id;
462
+ try {
463
+ id = await (0, cancellable_1.cancellable)((signal) => (0, prompts_1.select)({
464
+ message: `Resume which session? ${chalk_1.default.dim('(esc to cancel)')}`,
465
+ pageSize: 12,
466
+ choices: [
467
+ ...sessions.map((s) => ({
468
+ name: `${s.title} ${chalk_1.default.dim(s.detail)}` +
469
+ (s.id === session.lastBuildId
470
+ ? chalk_1.default.green(' ← current')
471
+ : ''),
472
+ value: s.id,
473
+ })),
474
+ { name: chalk_1.default.dim('Cancel'), value: CANCEL },
475
+ ],
476
+ }, { signal }));
477
+ }
478
+ catch (err) {
479
+ if ((0, cancellable_1.isCancellation)(err))
480
+ return null;
481
+ throw err;
482
+ }
483
+ if (id === CANCEL)
484
+ return null;
485
+ return sessions.find((s) => s.id === id) ?? null;
486
+ }
487
+ const index = Number(ref);
488
+ if (Number.isInteger(index) && index > 0) {
489
+ const sessions = this.lastSessions?.length ? this.lastSessions : await listing();
490
+ const picked = sessions[index - 1];
491
+ if (!picked) {
492
+ this.output.fail(`There is no session ${index}. There are ${sessions.length}.`);
493
+ return null;
494
+ }
495
+ return picked;
496
+ }
497
+ if (UUID_PATTERN.test(ref)) {
498
+ return { id: ref, title: ref, detail: '' };
499
+ }
500
+ const sessions = this.lastSessions?.length ? this.lastSessions : await listing();
501
+ const needle = ref.toLowerCase();
502
+ const matches = sessions.filter((s) => s.title.toLowerCase().includes(needle));
503
+ if (matches.length === 1)
504
+ return matches[0];
505
+ if (matches.length > 1) {
506
+ this.output.fail(`'${ref}' matches ${matches.length} sessions — use its number from /sessions.`);
507
+ return null;
508
+ }
509
+ this.output.fail(`No session matches '${ref}'. Use /sessions and then /resume <number>.`);
510
+ return null;
511
+ }
512
+ async buildExecutor(target, options, console_) {
513
+ const workspace = target.kind === 'workspace';
514
+ let members;
515
+ try {
516
+ members = workspace
517
+ ? await this.targets.workspaceMembers(target)
518
+ : await this.targets.serviceRepo(target);
519
+ }
520
+ catch (err) {
521
+ this.output.error(`Could not read the ${workspace ? 'workspace' : 'service'}: ${err.message}`);
522
+ return undefined;
523
+ }
524
+ const roots = await (0, roots_1.resolveRoots)(members, options.root ?? [], process.cwd());
525
+ if (!roots.length) {
526
+ this.output.error(`Could not find ${workspace ? "any of this workspace's repositories" : 'this service\'s repository'} on this machine. Point at ${workspace ? 'them' : 'it'} with --root ${workspace ? '<slug>=<path>' : '<path>'}.`);
527
+ return undefined;
528
+ }
529
+ const missing = members.filter((m) => !roots.some((root) => root.slug === m.slug));
530
+ for (const member of missing) {
531
+ this.output.warn(`No local checkout found for ${member.slug} — the agent cannot touch it.`);
532
+ }
533
+ const clientId = (0, crypto_1.randomUUID)();
534
+ const allowlist = new allowlist_1.CommandAllowlist([
535
+ ...(this.config.getAgentDefaults().executorAllow ?? []),
536
+ ...(options.allow ?? []),
537
+ ]);
538
+ const approver = new approval_1.CommandApprover(console_, allowlist, {
539
+ nonInteractive: typeof options.print === 'string' || Boolean(options.json),
540
+ allowAll: options.dangerouslyAllowAll,
541
+ });
542
+ const declaration = {
543
+ mode: 'local',
544
+ clientId,
545
+ protocolVersion: executor_types_1.EXECUTOR_PROTOCOL_VERSION,
546
+ roots,
547
+ capabilities: executor_types_1.EXECUTOR_CAPABILITIES,
548
+ };
549
+ const client = new executor_client_1.ExecutorClient(this.api, console_, approver, {
550
+ buildId: '',
551
+ clientId,
552
+ roots: Object.fromEntries(roots.map((r) => [r.slug, r.path])),
553
+ });
554
+ console.log('');
555
+ console.log(chalk_1.default.yellow('Local mode') +
556
+ chalk_1.default.dim(roots.length === 1
557
+ ? ' — the agent edits this working tree and opens no pull request:'
558
+ : ' — the agent edits these working trees and opens no pull request:'));
559
+ const slugWidth = Math.max(...roots.map((root) => root.slug.length));
560
+ for (const root of roots) {
561
+ console.log(chalk_1.default.dim(` ${root.slug.padEnd(slugWidth)} ${root.path}`));
562
+ }
563
+ if (options.dangerouslyAllowAll) {
564
+ console.log(chalk_1.default.red(' every command will run without asking (--dangerously-allow-all)'));
565
+ }
566
+ return { client, declaration, allowlist };
567
+ }
568
+ printBanner(session) {
569
+ console.log('');
570
+ console.log(`${chalk_1.default.bold.cyan('Workshop agent')} ${chalk_1.default.dim('·')} ${chalk_1.default.bold(session.target.label)} ${chalk_1.default.dim(`(${session.target.kind})`)}`);
571
+ console.log(chalk_1.default.dim(`Mode ${(0, mode_prompt_1.modeBadge)(session.mode)}${chalk_1.default.dim(` — ${(0, mode_prompt_1.modeDescription)(session.mode, Boolean(session.executorContext))}`)}`));
572
+ const launches = this.config.getAgentLaunches();
573
+ this.config.setAgentLaunches(launches + 1);
574
+ console.log(chalk_1.default.dim(launches < HINT_LAUNCHES
575
+ ? 'shift+tab changes mode · /help for commands · Ctrl+C detaches'
576
+ : '/help for commands'));
577
+ console.log('');
578
+ }
579
+ printRecap(session) {
580
+ const turns = session.turns;
581
+ if (!turns.length) {
582
+ this.output.info('Resumed an empty session.');
583
+ return;
584
+ }
585
+ const shown = turns.slice(-AgentCommand_1.RECAP_TURNS);
586
+ const hidden = turns.length - shown.length;
587
+ console.log('');
588
+ console.log(chalk_1.default.dim(`Resumed · ${turns.length} turn${turns.length === 1 ? '' : 's'}` +
589
+ (hidden ? ` (showing the last ${shown.length})` : '')));
590
+ for (const turn of shown) {
591
+ const mark = turn.status === 'succeeded'
592
+ ? chalk_1.default.green('✓')
593
+ : turn.status === 'failed'
594
+ ? chalk_1.default.red('✗')
595
+ : chalk_1.default.yellow('·');
596
+ const prompt = turn.prompt.split('\n')[0];
597
+ console.log(` ${mark} ${prompt.length > 72 ? `${prompt.slice(0, 69)}…` : prompt}`);
598
+ for (const url of turn.prUrls) {
599
+ const done = session.settledPrs.has(url);
600
+ console.log(` ${done ? chalk_1.default.dim('✓') : chalk_1.default.green('⇡')} ${done ? chalk_1.default.dim(url) : chalk_1.default.underline(url)}${done ? chalk_1.default.dim(' merged') : ''}`);
601
+ }
602
+ }
603
+ const last = turns[turns.length - 1];
604
+ if (last.summary) {
605
+ console.log('');
606
+ console.log(chalk_1.default.dim(` ${last.summary.split('\n')[0]}`));
607
+ }
608
+ console.log('');
609
+ }
610
+ printOutro(session) {
611
+ if (!session.turns.length)
612
+ return;
613
+ const open = session.openPrUrls();
614
+ const settled = session.settledPrs.size;
615
+ const turns = session.turns.length;
616
+ const parts = [`${turns} turn${turns === 1 ? '' : 's'} on ${session.target.label}`];
617
+ if (open.length) {
618
+ parts.push(`${open.length} pull request${open.length === 1 ? '' : 's'} open`);
619
+ }
620
+ if (settled)
621
+ parts.push(`${settled} merged`);
622
+ console.log('');
623
+ console.log(chalk_1.default.dim(parts.join(' · ')));
624
+ for (const url of open) {
625
+ console.log(` ${chalk_1.default.green('⇡')} ${chalk_1.default.underline(url)}`);
626
+ }
627
+ if (session.lastBuildId) {
628
+ console.log(chalk_1.default.dim(` continue: workshop agent --resume ${session.lastBuildId}`));
629
+ }
630
+ console.log('');
631
+ }
632
+ parseLocal() {
633
+ return true;
634
+ }
635
+ parseRoot(val, previous = []) {
636
+ return [...previous, val];
637
+ }
638
+ parseAllow(val, previous = []) {
639
+ return [...previous, val];
640
+ }
641
+ parseDangerouslyAllowAll() {
642
+ return true;
643
+ }
644
+ parseWorkspace(val) {
645
+ return val;
646
+ }
647
+ parseService(val) {
648
+ return val;
649
+ }
650
+ parseProject(val) {
651
+ return val;
652
+ }
653
+ parseResume(val) {
654
+ return val ?? true;
655
+ }
656
+ parseMode(val) {
657
+ return val;
658
+ }
659
+ parseModel(val) {
660
+ return val;
661
+ }
662
+ parsePrint(val) {
663
+ return val;
664
+ }
665
+ parseYes() {
666
+ return true;
667
+ }
668
+ parseJson() {
669
+ return true;
670
+ }
671
+ parseVerbose(_val, previous = 0) {
672
+ return previous + 1;
673
+ }
674
+ parseQuiet() {
675
+ return true;
676
+ }
677
+ parseSpinner() {
678
+ return false;
679
+ }
680
+ };
681
+ exports.AgentCommand = AgentCommand;
682
+ AgentCommand.RECAP_TURNS = 5;
683
+ __decorate([
684
+ (0, nest_commander_1.Option)({
685
+ flags: '--local',
686
+ description: 'Run this turn against your own working tree: the agent edits your files ' +
687
+ 'and runs commands here, and does not open a pull request',
688
+ }),
689
+ __metadata("design:type", Function),
690
+ __metadata("design:paramtypes", []),
691
+ __metadata("design:returntype", void 0)
692
+ ], AgentCommand.prototype, "parseLocal", null);
693
+ __decorate([
694
+ (0, nest_commander_1.Option)({
695
+ flags: '--root <slug=path>',
696
+ description: 'Where a member repo lives locally (repeatable)',
697
+ }),
698
+ __metadata("design:type", Function),
699
+ __metadata("design:paramtypes", [String, Array]),
700
+ __metadata("design:returntype", void 0)
701
+ ], AgentCommand.prototype, "parseRoot", null);
702
+ __decorate([
703
+ (0, nest_commander_1.Option)({
704
+ flags: '--allow <command>',
705
+ description: 'Pre-approve a command for this session (repeatable)',
706
+ }),
707
+ __metadata("design:type", Function),
708
+ __metadata("design:paramtypes", [String, Array]),
709
+ __metadata("design:returntype", void 0)
710
+ ], AgentCommand.prototype, "parseAllow", null);
711
+ __decorate([
712
+ (0, nest_commander_1.Option)({
713
+ flags: '--dangerously-allow-all',
714
+ description: 'Run every command the agent proposes without asking',
715
+ }),
716
+ __metadata("design:type", Function),
717
+ __metadata("design:paramtypes", []),
718
+ __metadata("design:returntype", void 0)
719
+ ], AgentCommand.prototype, "parseDangerouslyAllowAll", null);
720
+ __decorate([
721
+ (0, nest_commander_1.Option)({ flags: '-w, --workspace <id>', description: 'Workspace to work on' }),
722
+ __metadata("design:type", Function),
723
+ __metadata("design:paramtypes", [String]),
724
+ __metadata("design:returntype", void 0)
725
+ ], AgentCommand.prototype, "parseWorkspace", null);
726
+ __decorate([
727
+ (0, nest_commander_1.Option)({ flags: '-s, --service <id>', description: 'Service to work on' }),
728
+ __metadata("design:type", Function),
729
+ __metadata("design:paramtypes", [String]),
730
+ __metadata("design:returntype", void 0)
731
+ ], AgentCommand.prototype, "parseService", null);
732
+ __decorate([
733
+ (0, nest_commander_1.Option)({ flags: '-p, --project <id>', description: 'Project the target belongs to' }),
734
+ __metadata("design:type", Function),
735
+ __metadata("design:paramtypes", [String]),
736
+ __metadata("design:returntype", void 0)
737
+ ], AgentCommand.prototype, "parseProject", null);
738
+ __decorate([
739
+ (0, nest_commander_1.Option)({
740
+ flags: '-r, --resume [id]',
741
+ description: 'Resume the latest session, or a specific build id',
742
+ }),
743
+ __metadata("design:type", Function),
744
+ __metadata("design:paramtypes", [String]),
745
+ __metadata("design:returntype", void 0)
746
+ ], AgentCommand.prototype, "parseResume", null);
747
+ __decorate([
748
+ (0, nest_commander_1.Option)({ flags: '-m, --mode <mode>', description: 'plan | auto | discuss' }),
749
+ __metadata("design:type", Function),
750
+ __metadata("design:paramtypes", [String]),
751
+ __metadata("design:returntype", void 0)
752
+ ], AgentCommand.prototype, "parseMode", null);
753
+ __decorate([
754
+ (0, nest_commander_1.Option)({ flags: '--model <id>', description: 'Model to use' }),
755
+ __metadata("design:type", Function),
756
+ __metadata("design:paramtypes", [String]),
757
+ __metadata("design:returntype", void 0)
758
+ ], AgentCommand.prototype, "parseModel", null);
759
+ __decorate([
760
+ (0, nest_commander_1.Option)({ flags: '--print <prompt>', description: 'Run one prompt and exit' }),
761
+ __metadata("design:type", Function),
762
+ __metadata("design:paramtypes", [String]),
763
+ __metadata("design:returntype", void 0)
764
+ ], AgentCommand.prototype, "parsePrint", null);
765
+ __decorate([
766
+ (0, nest_commander_1.Option)({ flags: '-y, --yes', description: 'Auto-approve plans (with --print)' }),
767
+ __metadata("design:type", Function),
768
+ __metadata("design:paramtypes", []),
769
+ __metadata("design:returntype", void 0)
770
+ ], AgentCommand.prototype, "parseYes", null);
771
+ __decorate([
772
+ (0, nest_commander_1.Option)({ flags: '--json', description: 'JSON output (requires --print)' }),
773
+ __metadata("design:type", Function),
774
+ __metadata("design:paramtypes", []),
775
+ __metadata("design:returntype", void 0)
776
+ ], AgentCommand.prototype, "parseJson", null);
777
+ __decorate([
778
+ (0, nest_commander_1.Option)({
779
+ flags: '-v, --verbose',
780
+ description: 'More detail (repeat for raw events)',
781
+ }),
782
+ __metadata("design:type", Function),
783
+ __metadata("design:paramtypes", [String, Object]),
784
+ __metadata("design:returntype", void 0)
785
+ ], AgentCommand.prototype, "parseVerbose", null);
786
+ __decorate([
787
+ (0, nest_commander_1.Option)({ flags: '-q, --quiet', description: 'Only warnings and results' }),
788
+ __metadata("design:type", Function),
789
+ __metadata("design:paramtypes", []),
790
+ __metadata("design:returntype", void 0)
791
+ ], AgentCommand.prototype, "parseQuiet", null);
792
+ __decorate([
793
+ (0, nest_commander_1.Option)({ flags: '--no-spinner', description: 'Disable the progress spinner' }),
794
+ __metadata("design:type", Function),
795
+ __metadata("design:paramtypes", []),
796
+ __metadata("design:returntype", void 0)
797
+ ], AgentCommand.prototype, "parseSpinner", null);
798
+ exports.AgentCommand = AgentCommand = AgentCommand_1 = __decorate([
799
+ (0, nest_commander_1.Command)({
800
+ name: 'agent',
801
+ description: 'Chat with the Workshop AI agent about your code',
802
+ subCommands: [
803
+ agent_sessions_command_1.AgentSessionsCommand,
804
+ agent_resume_command_1.AgentResumeCommand,
805
+ agent_rm_command_1.AgentRmCommand,
806
+ agent_diff_command_1.AgentDiffCommand,
807
+ agent_files_command_1.AgentFilesCommand,
808
+ agent_merge_command_1.AgentMergeCommand,
809
+ agent_models_command_1.AgentModelsCommand,
810
+ ],
811
+ }),
812
+ __metadata("design:paramtypes", [build_api_service_1.BuildApiService,
813
+ build_stream_client_1.BuildStreamClient,
814
+ gate_prompter_1.GatePrompter,
815
+ target_resolver_1.TargetResolver,
816
+ cli_config_service_1.CliConfigService,
817
+ output_service_1.OutputService])
818
+ ], AgentCommand);
819
+ //# sourceMappingURL=agent.command.js.map