@pellux/goodvibes-agent 0.1.114 → 0.1.116

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.
@@ -0,0 +1,534 @@
1
+ import type { AgentWorkspaceActionResult, AgentWorkspaceLocalEditor } from './agent-workspace-types.ts';
2
+ import { quoteSlashCommandArg, tokenizeSlashCommand } from './slash-command-parser.ts';
3
+
4
+ type AgentWorkspaceFieldReader = (fieldId: string) => string;
5
+
6
+ export type AgentWorkspaceBasicCommandEditorSubmission =
7
+ | {
8
+ readonly kind: 'editor';
9
+ readonly editor: AgentWorkspaceLocalEditor;
10
+ readonly status: string;
11
+ readonly actionResult?: AgentWorkspaceActionResult;
12
+ }
13
+ | {
14
+ readonly kind: 'dispatch';
15
+ readonly command: string;
16
+ readonly status: string;
17
+ readonly actionResult: AgentWorkspaceActionResult;
18
+ };
19
+
20
+ function isAffirmative(value: string): boolean {
21
+ return /^(y|yes|true)$/i.test(value.trim());
22
+ }
23
+
24
+ function splitCommaList(value: string): readonly string[] {
25
+ return value.split(',').map((entry) => entry.trim()).filter(Boolean);
26
+ }
27
+
28
+ export function buildAgentWorkspaceBasicCommandEditorSubmission(
29
+ editor: AgentWorkspaceLocalEditor,
30
+ readField: AgentWorkspaceFieldReader,
31
+ commandDispatchAvailable: boolean,
32
+ ): AgentWorkspaceBasicCommandEditorSubmission {
33
+ if (!commandDispatchAvailable) {
34
+ return {
35
+ kind: 'editor',
36
+ editor: { ...editor, message: 'Command dispatch is unavailable; this action cannot run from this workspace.' },
37
+ status: 'Command dispatch unavailable.',
38
+ actionResult: {
39
+ kind: 'error',
40
+ title: 'Command dispatch unavailable',
41
+ detail: 'The Agent workspace cannot hand this action to the shell-owned command router.',
42
+ },
43
+ };
44
+ }
45
+ if (editor.kind === 'knowledge-bookmarks') {
46
+ if (!isAffirmative(readField('confirm'))) {
47
+ return {
48
+ kind: 'editor',
49
+ editor: { ...editor, message: 'Bookmark import not confirmed. Type yes, then press Enter.' },
50
+ status: 'Agent Knowledge bookmark import not confirmed.',
51
+ };
52
+ }
53
+ const command = `/knowledge import-bookmarks ${quoteSlashCommandArg(readField('path'))} --yes`;
54
+ return {
55
+ kind: 'dispatch',
56
+ command,
57
+ status: 'Opening Agent Knowledge bookmark import.',
58
+ actionResult: {
59
+ kind: 'dispatched',
60
+ title: 'Opening Agent Knowledge bookmark import',
61
+ detail: 'The workspace handed a confirmed bookmark import command to the shell-owned command router.',
62
+ command,
63
+ safety: 'safe',
64
+ },
65
+ };
66
+ }
67
+ if (editor.kind === 'knowledge-file') {
68
+ if (!isAffirmative(readField('confirm'))) {
69
+ return {
70
+ kind: 'editor',
71
+ editor: { ...editor, message: 'File ingest not confirmed. Type yes, then press Enter.' },
72
+ status: 'Agent Knowledge file ingest not confirmed.',
73
+ };
74
+ }
75
+ const parts = ['/knowledge', 'ingest-file', quoteSlashCommandArg(readField('path'))];
76
+ const title = readField('title');
77
+ const tags = readField('tags');
78
+ const folder = readField('folder');
79
+ if (title.length > 0) parts.push('--title', quoteSlashCommandArg(title));
80
+ if (tags.length > 0) parts.push('--tags', quoteSlashCommandArg(tags));
81
+ if (folder.length > 0) parts.push('--folder', quoteSlashCommandArg(folder));
82
+ parts.push('--yes');
83
+ const command = parts.join(' ');
84
+ return {
85
+ kind: 'dispatch',
86
+ command,
87
+ status: 'Opening Agent Knowledge file ingest.',
88
+ actionResult: {
89
+ kind: 'dispatched',
90
+ title: 'Opening Agent Knowledge file ingest',
91
+ detail: 'The workspace handed a confirmed file ingest command to the shell-owned command router.',
92
+ command,
93
+ safety: 'safe',
94
+ },
95
+ };
96
+ }
97
+ if (editor.kind === 'knowledge-browser-history') {
98
+ if (!isAffirmative(readField('confirm'))) {
99
+ return {
100
+ kind: 'editor',
101
+ editor: { ...editor, message: 'Browser history import not confirmed. Type yes, then press Enter.' },
102
+ status: 'Agent Knowledge browser history import not confirmed.',
103
+ };
104
+ }
105
+ const parts = ['/knowledge', 'import-browser-history'];
106
+ const browsers = readField('browsers');
107
+ const sources = readField('sources');
108
+ const limit = readField('limit');
109
+ const sinceDays = readField('sinceDays');
110
+ if (browsers.length > 0) parts.push('--browsers', quoteSlashCommandArg(browsers));
111
+ if (sources.length > 0) parts.push('--sources', quoteSlashCommandArg(sources));
112
+ if (limit.length > 0) parts.push('--limit', quoteSlashCommandArg(limit));
113
+ if (sinceDays.length > 0) parts.push('--since-days', quoteSlashCommandArg(sinceDays));
114
+ parts.push('--yes');
115
+ const command = parts.join(' ');
116
+ return {
117
+ kind: 'dispatch',
118
+ command,
119
+ status: 'Opening Agent Knowledge browser history import.',
120
+ actionResult: {
121
+ kind: 'dispatched',
122
+ title: 'Opening Agent Knowledge browser history import',
123
+ detail: 'The workspace handed a confirmed browser-history import command to the shell-owned command router.',
124
+ command,
125
+ safety: 'safe',
126
+ },
127
+ };
128
+ }
129
+ if (editor.kind === 'knowledge-connector-ingest') {
130
+ if (!isAffirmative(readField('confirm'))) {
131
+ return {
132
+ kind: 'editor',
133
+ editor: { ...editor, message: 'Connector ingest not confirmed. Type yes, then press Enter.' },
134
+ status: 'Agent Knowledge connector ingest not confirmed.',
135
+ };
136
+ }
137
+ const connectorId = readField('connectorId');
138
+ const input = readField('input');
139
+ const path = readField('path');
140
+ const content = readField('content');
141
+ const parts = ['/knowledge', 'ingest-connector', quoteSlashCommandArg(connectorId)];
142
+ if (input.length > 0) parts.push('--input', quoteSlashCommandArg(input));
143
+ if (path.length > 0) parts.push('--path', quoteSlashCommandArg(path));
144
+ if (content.length > 0) parts.push('--content', quoteSlashCommandArg(content));
145
+ if (isAffirmative(readField('allowPrivateHosts'))) parts.push('--allow-private-hosts');
146
+ parts.push('--yes');
147
+ const command = parts.join(' ');
148
+ return {
149
+ kind: 'dispatch',
150
+ command,
151
+ status: 'Opening Agent Knowledge connector ingest.',
152
+ actionResult: {
153
+ kind: 'dispatched',
154
+ title: 'Opening Agent Knowledge connector ingest',
155
+ detail: 'The workspace handed a confirmed connector ingest command to the shell-owned command router.',
156
+ command,
157
+ safety: 'safe',
158
+ },
159
+ };
160
+ }
161
+ if (editor.kind === 'mcp-server') {
162
+ if (!isAffirmative(readField('confirm'))) {
163
+ return {
164
+ kind: 'editor',
165
+ editor: { ...editor, message: 'MCP server add/update not confirmed. Type yes, then press Enter.' },
166
+ status: 'MCP server add/update not confirmed.',
167
+ };
168
+ }
169
+ const parts = [
170
+ '/mcp',
171
+ 'add',
172
+ quoteSlashCommandArg(readField('name')),
173
+ quoteSlashCommandArg(readField('command')),
174
+ ...tokenizeSlashCommand(readField('args')).map(quoteSlashCommandArg),
175
+ ];
176
+ const scope = readField('scope');
177
+ const role = readField('role');
178
+ const trust = readField('trust');
179
+ if (scope.length > 0) parts.push('--scope', quoteSlashCommandArg(scope));
180
+ if (role.length > 0) parts.push('--role', quoteSlashCommandArg(role));
181
+ if (trust.length > 0) parts.push('--trust', quoteSlashCommandArg(trust));
182
+ for (const env of splitCommaList(readField('env'))) parts.push('--env', quoteSlashCommandArg(env));
183
+ for (const path of splitCommaList(readField('paths'))) parts.push('--path', quoteSlashCommandArg(path));
184
+ for (const host of splitCommaList(readField('hosts'))) parts.push('--host', quoteSlashCommandArg(host));
185
+ parts.push('--yes');
186
+ const command = parts.join(' ');
187
+ return {
188
+ kind: 'dispatch',
189
+ command,
190
+ status: 'Opening MCP server add/update.',
191
+ actionResult: {
192
+ kind: 'dispatched',
193
+ title: 'Opening MCP server add/update',
194
+ detail: 'The workspace handed a confirmed MCP server add/update command to the shell-owned command router.',
195
+ command,
196
+ safety: 'safe',
197
+ },
198
+ };
199
+ }
200
+ if (editor.kind === 'notify-webhook') {
201
+ if (!isAffirmative(readField('confirm'))) {
202
+ return {
203
+ kind: 'editor',
204
+ editor: { ...editor, message: 'Notification webhook add not confirmed. Type yes, then press Enter.' },
205
+ status: 'Notification webhook add not confirmed.',
206
+ };
207
+ }
208
+ const command = `/notify add ${quoteSlashCommandArg(readField('url'))} --yes`;
209
+ return {
210
+ kind: 'dispatch',
211
+ command,
212
+ status: 'Opening notification webhook add.',
213
+ actionResult: {
214
+ kind: 'dispatched',
215
+ title: 'Opening notification webhook add',
216
+ detail: 'The workspace handed a confirmed notification target command to the shell-owned command router.',
217
+ command,
218
+ safety: 'safe',
219
+ },
220
+ };
221
+ }
222
+ if (editor.kind === 'notify-webhook-remove') {
223
+ if (!isAffirmative(readField('confirm'))) {
224
+ return {
225
+ kind: 'editor',
226
+ editor: { ...editor, message: 'Notification webhook remove not confirmed. Type yes, then press Enter.' },
227
+ status: 'Notification webhook remove not confirmed.',
228
+ };
229
+ }
230
+ const command = `/notify remove ${quoteSlashCommandArg(readField('url'))} --yes`;
231
+ return {
232
+ kind: 'dispatch',
233
+ command,
234
+ status: 'Opening notification webhook remove.',
235
+ actionResult: {
236
+ kind: 'dispatched',
237
+ title: 'Opening notification webhook remove',
238
+ detail: 'The workspace handed a confirmed notification target remove command to the shell-owned command router.',
239
+ command,
240
+ safety: 'safe',
241
+ },
242
+ };
243
+ }
244
+ if (editor.kind === 'notify-webhook-test') {
245
+ if (!isAffirmative(readField('confirm'))) {
246
+ return {
247
+ kind: 'editor',
248
+ editor: { ...editor, message: 'Notification webhook test not confirmed. Type yes, then press Enter.' },
249
+ status: 'Notification webhook test not confirmed.',
250
+ };
251
+ }
252
+ const command = '/notify test --yes';
253
+ return {
254
+ kind: 'dispatch',
255
+ command,
256
+ status: 'Opening notification webhook test.',
257
+ actionResult: {
258
+ kind: 'dispatched',
259
+ title: 'Opening notification webhook test',
260
+ detail: 'The workspace handed a confirmed notification test command to the shell-owned command router.',
261
+ command,
262
+ safety: 'safe',
263
+ },
264
+ };
265
+ }
266
+ if (editor.kind === 'tts-prompt') {
267
+ const command = `/tts ${quoteSlashCommandArg(readField('prompt'))}`;
268
+ return {
269
+ kind: 'dispatch',
270
+ command,
271
+ status: 'Opening spoken assistant prompt.',
272
+ actionResult: {
273
+ kind: 'dispatched',
274
+ title: 'Opening spoken assistant prompt',
275
+ detail: 'The workspace handed a spoken prompt to the shell-owned command router.',
276
+ command,
277
+ safety: 'safe',
278
+ },
279
+ };
280
+ }
281
+ if (editor.kind === 'image-input') {
282
+ const prompt = readField('prompt');
283
+ const command = prompt.length > 0
284
+ ? `/image ${quoteSlashCommandArg(readField('path'))} ${quoteSlashCommandArg(prompt)}`
285
+ : `/image ${quoteSlashCommandArg(readField('path'))}`;
286
+ return {
287
+ kind: 'dispatch',
288
+ command,
289
+ status: 'Opening image input.',
290
+ actionResult: {
291
+ kind: 'dispatched',
292
+ title: 'Opening image input',
293
+ detail: 'The workspace handed an image attachment command to the shell-owned command router.',
294
+ command,
295
+ safety: 'safe',
296
+ },
297
+ };
298
+ }
299
+ if (editor.kind === 'profile-template-export') {
300
+ if (!isAffirmative(readField('confirm'))) {
301
+ return {
302
+ kind: 'editor',
303
+ editor: { ...editor, message: 'Starter template export not confirmed. Type yes, then press Enter.' },
304
+ status: 'Agent starter template export not confirmed.',
305
+ };
306
+ }
307
+ const command = `/agent-profile template export ${quoteSlashCommandArg(readField('templateId'))} ${quoteSlashCommandArg(readField('path'))} --yes`;
308
+ return {
309
+ kind: 'dispatch',
310
+ command,
311
+ status: 'Opening Agent starter template export.',
312
+ actionResult: {
313
+ kind: 'dispatched',
314
+ title: 'Opening Agent starter template export',
315
+ detail: 'The workspace handed a confirmed starter template export command to the shell-owned command router.',
316
+ command,
317
+ safety: 'safe',
318
+ },
319
+ };
320
+ }
321
+ if (editor.kind === 'profile-template-import') {
322
+ if (!isAffirmative(readField('confirm'))) {
323
+ return {
324
+ kind: 'editor',
325
+ editor: { ...editor, message: 'Starter template import not confirmed. Type yes, then press Enter.' },
326
+ status: 'Agent starter template import not confirmed.',
327
+ };
328
+ }
329
+ const command = `/agent-profile template import ${quoteSlashCommandArg(readField('path'))} --yes`;
330
+ return {
331
+ kind: 'dispatch',
332
+ command,
333
+ status: 'Opening Agent starter template import.',
334
+ actionResult: {
335
+ kind: 'dispatched',
336
+ title: 'Opening Agent starter template import',
337
+ detail: 'The workspace handed a confirmed starter template import command to the shell-owned command router.',
338
+ command,
339
+ safety: 'safe',
340
+ },
341
+ };
342
+ }
343
+ if (editor.kind === 'profile-template-from-discovered') {
344
+ if (!isAffirmative(readField('confirm'))) {
345
+ return {
346
+ kind: 'editor',
347
+ editor: { ...editor, message: 'Starter-from-discovered creation not confirmed. Type yes, then press Enter.' },
348
+ status: 'Agent starter-from-discovered creation not confirmed.',
349
+ };
350
+ }
351
+ const parts = [
352
+ '/agent-profile',
353
+ 'template',
354
+ 'from-discovered',
355
+ quoteSlashCommandArg(readField('id')),
356
+ ];
357
+ const name = readField('name');
358
+ const description = readField('description');
359
+ const persona = readField('persona');
360
+ const skills = readField('skills');
361
+ const routines = readField('routines');
362
+ if (name.length > 0) parts.push('--name', quoteSlashCommandArg(name));
363
+ if (description.length > 0) parts.push('--description', quoteSlashCommandArg(description));
364
+ if (persona.length > 0) parts.push('--persona', quoteSlashCommandArg(persona));
365
+ if (skills.length > 0) parts.push('--skills', quoteSlashCommandArg(skills));
366
+ if (routines.length > 0) parts.push('--routines', quoteSlashCommandArg(routines));
367
+ if (isAffirmative(readField('replace'))) parts.push('--replace');
368
+ parts.push('--yes');
369
+ const command = parts.join(' ');
370
+ return {
371
+ kind: 'dispatch',
372
+ command,
373
+ status: 'Opening Agent starter-from-discovered creation.',
374
+ actionResult: {
375
+ kind: 'dispatched',
376
+ title: 'Opening Agent starter-from-discovered creation',
377
+ detail: 'The workspace handed a confirmed starter creation command to the shell-owned command router.',
378
+ command,
379
+ safety: 'safe',
380
+ },
381
+ };
382
+ }
383
+ if (editor.kind === 'profile-from-discovered') {
384
+ if (!isAffirmative(readField('confirm'))) {
385
+ return {
386
+ kind: 'editor',
387
+ editor: { ...editor, message: 'Profile-from-discovered creation not confirmed. Type yes, then press Enter.' },
388
+ status: 'Agent profile-from-discovered creation not confirmed.',
389
+ };
390
+ }
391
+ const parts = [
392
+ '/agent-profile',
393
+ 'create-from-discovered',
394
+ quoteSlashCommandArg(readField('profile')),
395
+ ];
396
+ const templateId = readField('templateId');
397
+ const name = readField('name');
398
+ const description = readField('description');
399
+ const persona = readField('persona');
400
+ const skills = readField('skills');
401
+ const routines = readField('routines');
402
+ if (templateId.length > 0) parts.push('--template-id', quoteSlashCommandArg(templateId));
403
+ if (name.length > 0) parts.push('--name', quoteSlashCommandArg(name));
404
+ if (description.length > 0) parts.push('--description', quoteSlashCommandArg(description));
405
+ if (persona.length > 0) parts.push('--persona', quoteSlashCommandArg(persona));
406
+ if (skills.length > 0) parts.push('--skills', quoteSlashCommandArg(skills));
407
+ if (routines.length > 0) parts.push('--routines', quoteSlashCommandArg(routines));
408
+ if (isAffirmative(readField('replace'))) parts.push('--replace');
409
+ parts.push('--yes');
410
+ const command = parts.join(' ');
411
+ return {
412
+ kind: 'dispatch',
413
+ command,
414
+ status: 'Opening Agent profile-from-discovered creation.',
415
+ actionResult: {
416
+ kind: 'dispatched',
417
+ title: 'Opening Agent profile-from-discovered creation',
418
+ detail: 'The workspace handed a confirmed discovered-behavior profile creation command to the shell-owned command router.',
419
+ command,
420
+ safety: 'safe',
421
+ },
422
+ };
423
+ }
424
+ if (editor.kind === 'skill-discovery-import') {
425
+ if (!isAffirmative(readField('confirm'))) {
426
+ return {
427
+ kind: 'editor',
428
+ editor: { ...editor, message: 'Discovered skill import not confirmed. Type yes, then press Enter.' },
429
+ status: 'Agent skill import not confirmed.',
430
+ };
431
+ }
432
+ const parts = [
433
+ '/agent-skills',
434
+ 'import-discovered',
435
+ quoteSlashCommandArg(readField('name')),
436
+ ];
437
+ if (isAffirmative(readField('enabled'))) parts.push('--enabled');
438
+ parts.push('--yes');
439
+ const command = parts.join(' ');
440
+ return {
441
+ kind: 'dispatch',
442
+ command,
443
+ status: 'Opening discovered skill import.',
444
+ actionResult: {
445
+ kind: 'dispatched',
446
+ title: 'Opening discovered skill import',
447
+ detail: 'The workspace handed a confirmed local skill import command to the shell-owned command router.',
448
+ command,
449
+ safety: 'safe',
450
+ },
451
+ };
452
+ }
453
+ if (editor.kind === 'persona-discovery-import') {
454
+ if (!isAffirmative(readField('confirm'))) {
455
+ return {
456
+ kind: 'editor',
457
+ editor: { ...editor, message: 'Discovered persona import not confirmed. Type yes, then press Enter.' },
458
+ status: 'Agent persona import not confirmed.',
459
+ };
460
+ }
461
+ const parts = [
462
+ '/personas',
463
+ 'import-discovered',
464
+ quoteSlashCommandArg(readField('name')),
465
+ ];
466
+ if (isAffirmative(readField('use'))) parts.push('--use');
467
+ parts.push('--yes');
468
+ const command = parts.join(' ');
469
+ return {
470
+ kind: 'dispatch',
471
+ command,
472
+ status: 'Opening discovered persona import.',
473
+ actionResult: {
474
+ kind: 'dispatched',
475
+ title: 'Opening discovered persona import',
476
+ detail: 'The workspace handed a confirmed local persona import command to the shell-owned command router.',
477
+ command,
478
+ safety: 'safe',
479
+ },
480
+ };
481
+ }
482
+ if (editor.kind === 'routine-discovery-import') {
483
+ if (!isAffirmative(readField('confirm'))) {
484
+ return {
485
+ kind: 'editor',
486
+ editor: { ...editor, message: 'Discovered routine import not confirmed. Type yes, then press Enter.' },
487
+ status: 'Agent routine import not confirmed.',
488
+ };
489
+ }
490
+ const parts = [
491
+ '/routines',
492
+ 'import-discovered',
493
+ quoteSlashCommandArg(readField('name')),
494
+ ];
495
+ if (isAffirmative(readField('enabled'))) parts.push('--enabled');
496
+ parts.push('--yes');
497
+ const command = parts.join(' ');
498
+ return {
499
+ kind: 'dispatch',
500
+ command,
501
+ status: 'Opening discovered routine import.',
502
+ actionResult: {
503
+ kind: 'dispatched',
504
+ title: 'Opening discovered routine import',
505
+ detail: 'The workspace handed a confirmed local routine import command to the shell-owned command router.',
506
+ command,
507
+ safety: 'safe',
508
+ },
509
+ };
510
+ }
511
+ const commandParts = [
512
+ '/agent-skills bundle create',
513
+ '--name',
514
+ quoteSlashCommandArg(readField('name')),
515
+ '--description',
516
+ quoteSlashCommandArg(readField('description')),
517
+ '--skills',
518
+ quoteSlashCommandArg(readField('skills')),
519
+ ];
520
+ if (isAffirmative(readField('enabled'))) commandParts.push('--enabled');
521
+ const command = commandParts.join(' ');
522
+ return {
523
+ kind: 'dispatch',
524
+ command,
525
+ status: 'Opening skill bundle creation.',
526
+ actionResult: {
527
+ kind: 'dispatched',
528
+ title: 'Opening skill bundle creation',
529
+ detail: 'The workspace handed a concrete local skill bundle command to the shell-owned command router.',
530
+ command,
531
+ safety: 'safe',
532
+ },
533
+ };
534
+ }