s9n-devops-agent 1.7.4 → 2.0.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.
@@ -0,0 +1,550 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * ============================================================================
5
+ * TUTORIAL MODE - Interactive Learning for DevOps Agent v2.0
6
+ * ============================================================================
7
+ *
8
+ * Provides hands-on, interactive tutorial to help new users understand
9
+ * DevOps Agent concepts through guided examples and practice.
10
+ *
11
+ * Modules:
12
+ * 1. Understanding Sessions
13
+ * 2. Creating Your First Session
14
+ * 3. Working with AI Assistants
15
+ * 4. Multi-Agent Workflow
16
+ * 5. Advanced Features
17
+ *
18
+ * ============================================================================
19
+ */
20
+
21
+ import {
22
+ showWelcome,
23
+ sectionTitle,
24
+ explain,
25
+ tip,
26
+ confirm,
27
+ choose,
28
+ prompt,
29
+ success,
30
+ info,
31
+ warn,
32
+ colors,
33
+ status,
34
+ drawSection,
35
+ progressStep
36
+ } from './ui-utils.js';
37
+ import { showTopicHelp } from './help-system.js';
38
+
39
+ // ============================================================================
40
+ // TUTORIAL STATE
41
+ // ============================================================================
42
+
43
+ const tutorialState = {
44
+ currentModule: 0,
45
+ completed: [],
46
+ startTime: null,
47
+ };
48
+
49
+ // ============================================================================
50
+ // TUTORIAL MODULES
51
+ // ============================================================================
52
+
53
+ /**
54
+ * Module 1: Understanding Sessions
55
+ */
56
+ async function module1_understandingSessions() {
57
+ sectionTitle('Module 1: Understanding Sessions');
58
+
59
+ explain(`
60
+ Welcome to DevOps Agent! Let's start by understanding the core concept: ${colors.bright}sessions${colors.reset}.
61
+
62
+ Think of a session as giving an AI assistant its own private office to work in.
63
+ Each session is completely isolated from others, preventing conflicts and chaos.
64
+ `);
65
+
66
+ console.log();
67
+ console.log(`${colors.bright}What makes up a session?${colors.reset}`);
68
+ console.log();
69
+ console.log(`${status.folder} ${colors.cyan}Git Worktree${colors.reset}`);
70
+ console.log(` A separate directory with full git history`);
71
+ console.log(` Example: local_deploy/worktrees/abc1-23d4/`);
72
+ console.log();
73
+ console.log(`${status.branch} ${colors.cyan}Dedicated Branch${colors.reset}`);
74
+ console.log(` Auto-named based on task and date`);
75
+ console.log(` Example: session/implement-auth_abc1_2024-10-31`);
76
+ console.log();
77
+ console.log(`${status.lock} ${colors.cyan}File Locks${colors.reset}`);
78
+ console.log(` Prevents other agents from editing same files`);
79
+ console.log(` Released when session closes`);
80
+ console.log();
81
+ console.log(`${status.robot} ${colors.cyan}Auto-Monitoring${colors.reset}`);
82
+ console.log(` Watches for changes and commits automatically`);
83
+ console.log(` You never run git commands manually`);
84
+ console.log();
85
+
86
+ const viewExample = await confirm('Would you like to see a real-world example?', true);
87
+
88
+ if (viewExample) {
89
+ console.log();
90
+ drawSection('Example Workflow', [
91
+ `${colors.bright}Scenario:${colors.reset} You want Claude to implement authentication`,
92
+ ``,
93
+ `${status.arrow} ${colors.cyan}Step 1:${colors.reset} Create session`,
94
+ ` ${colors.dim}s9n-devops-agent start${colors.reset}`,
95
+ ` ${colors.dim}Task: implement-authentication${colors.reset}`,
96
+ ``,
97
+ `${status.arrow} ${colors.cyan}Step 2:${colors.reset} Session created`,
98
+ ` ${colors.dim}Workspace: local_deploy/worktrees/abc1/`,
99
+ ` ${colors.dim}Branch: session/implement-authentication_abc1${colors.reset}`,
100
+ ``,
101
+ `${status.arrow} ${colors.cyan}Step 3:${colors.reset} Give instructions to Claude`,
102
+ ` ${colors.dim}(Copy-paste provided instructions)${colors.reset}`,
103
+ ``,
104
+ `${status.arrow} ${colors.cyan}Step 4:${colors.reset} Claude works in isolation`,
105
+ ` ${colors.dim}Writes code in the worktree directory`,
106
+ ` ${colors.dim}DevOps Agent auto-commits and pushes${colors.reset}`,
107
+ ``,
108
+ `${status.arrow} ${colors.cyan}Step 5:${colors.reset} Close session when done`,
109
+ ` ${colors.dim}Merges to daily branch, then to main`,
110
+ ` ${colors.dim}Cleans up worktree directory${colors.reset}`,
111
+ ]);
112
+ }
113
+
114
+ console.log();
115
+ const learnMore = await confirm('Want to see the detailed help for sessions?', false);
116
+ if (learnMore) {
117
+ await showTopicHelp('sessions');
118
+ }
119
+
120
+ tutorialState.completed.push('module1');
121
+ success('Module 1 complete! You understand what sessions are.');
122
+ }
123
+
124
+ /**
125
+ * Module 2: Creating Your First Session
126
+ */
127
+ async function module2_creatingFirstSession() {
128
+ sectionTitle('Module 2: Creating Your First Session');
129
+
130
+ explain(`
131
+ Now let's walk through creating a session step by step.
132
+ I'll show you what happens at each stage.
133
+ `);
134
+
135
+ console.log();
136
+ progressStep(1, 5, 'Start the session manager');
137
+ console.log();
138
+ console.log(` Command: ${colors.green}s9n-devops-agent start${colors.reset}`);
139
+ console.log();
140
+ console.log(` ${colors.dim}This opens an interactive menu${colors.reset}`);
141
+ console.log();
142
+
143
+ await confirm('Press Enter to continue', true);
144
+
145
+ progressStep(2, 5, 'Choose to create a new session');
146
+ console.log();
147
+ console.log(` You'll see options like:`);
148
+ console.log(` ${colors.bright}N)${colors.reset} Create a new session`);
149
+ console.log(` ${colors.bright}1)${colors.reset} Resume existing session (if any exist)`);
150
+ console.log();
151
+
152
+ await confirm('Press Enter to continue', true);
153
+
154
+ progressStep(3, 5, 'Enter task name');
155
+ console.log();
156
+ console.log(` ${colors.cyan}?${colors.reset} Enter task/feature name: ${colors.dim}api-authentication${colors.reset}`);
157
+ console.log();
158
+ tip('Use descriptive names. They become part of your branch name.');
159
+ console.log();
160
+
161
+ await confirm('Press Enter to continue', true);
162
+
163
+ progressStep(4, 5, 'Select AI agent type');
164
+ console.log();
165
+ console.log(` ${colors.bright}1)${colors.reset} Claude (Anthropic)`);
166
+ console.log(` ${colors.bright}2)${colors.reset} Cursor`);
167
+ console.log(` ${colors.bright}3)${colors.reset} GitHub Copilot`);
168
+ console.log(` ${colors.bright}4)${colors.reset} Cline (VS Code)`);
169
+ console.log();
170
+ console.log(` ${colors.cyan}?${colors.reset} Your choice: ${colors.dim}1${colors.reset}`);
171
+ console.log();
172
+
173
+ await confirm('Press Enter to continue', true);
174
+
175
+ progressStep(5, 5, 'Session created!');
176
+ console.log();
177
+ console.log(` ${status.success} Session created: ${colors.cyan}abc1-23d4${colors.reset}`);
178
+ console.log(` ${status.folder} Workspace: ${colors.dim}local_deploy/worktrees/abc1-23d4/${colors.reset}`);
179
+ console.log(` ${status.branch} Branch: ${colors.dim}session/api-authentication_abc1${colors.reset}`);
180
+ console.log();
181
+ console.log(` ${colors.bright}Next: Copy instructions to your AI assistant${colors.reset}`);
182
+ console.log();
183
+
184
+ const practiceNow = await confirm('Would you like to practice creating a real session now?', false);
185
+
186
+ if (practiceNow) {
187
+ info('Great! Exit this tutorial and run: s9n-devops-agent start');
188
+ info('Then come back to continue the tutorial when ready.');
189
+ console.log();
190
+ }
191
+
192
+ tutorialState.completed.push('module2');
193
+ success('Module 2 complete! You know how to create sessions.');
194
+ }
195
+
196
+ /**
197
+ * Module 3: Working with AI Assistants
198
+ */
199
+ async function module3_workingWithAI() {
200
+ sectionTitle('Module 3: Working with AI Assistants');
201
+
202
+ explain(`
203
+ After creating a session, you need to give instructions to your AI assistant.
204
+ DevOps Agent provides perfectly formatted instructions to copy-paste.
205
+ `);
206
+
207
+ console.log();
208
+ console.log(`${colors.bright}The instructions tell the AI:${colors.reset}`);
209
+ console.log();
210
+ console.log(`${status.checkmark} ${colors.cyan}Where to work${colors.reset}`);
211
+ console.log(` The exact worktree directory path`);
212
+ console.log();
213
+ console.log(`${status.checkmark} ${colors.cyan}What rules to follow${colors.reset}`);
214
+ console.log(` Read the house rules file first`);
215
+ console.log();
216
+ console.log(`${status.checkmark} ${colors.cyan}How to declare files${colors.reset}`);
217
+ console.log(` Prevent conflicts with other agents`);
218
+ console.log();
219
+ console.log(`${status.checkmark} ${colors.cyan}How to commit changes${colors.reset}`);
220
+ console.log(` Write messages to special file`);
221
+ console.log();
222
+
223
+ const showInstructions = await confirm('See example instructions?', true);
224
+
225
+ if (showInstructions) {
226
+ console.log();
227
+ drawSection('Example Instructions for Claude', [
228
+ `${status.robot} DevOps Session Configuration`,
229
+ ``,
230
+ `Session ID: ${colors.cyan}abc1-23d4${colors.reset}`,
231
+ `Task: api-authentication`,
232
+ ``,
233
+ `${colors.bright}${status.point} STEP 1: Read house rules${colors.reset} ${colors.red}(CRITICAL!)${colors.reset}`,
234
+ ` cat "docs/houserules.md"`,
235
+ ``,
236
+ `${colors.bright}${status.point} STEP 2: Switch to workspace${colors.reset}`,
237
+ ` cd "local_deploy/worktrees/abc1-23d4"`,
238
+ ``,
239
+ `${colors.bright}${status.point} STEP 3: Declare files before editing${colors.reset}`,
240
+ ` Create: .file-coordination/active-edits/claude-abc1.json`,
241
+ ``,
242
+ `${colors.bright}${status.point} STEP 4: Write commits${colors.reset}`,
243
+ ` After changes: write to .devops-commit-abc1.msg`,
244
+ ` DevOps Agent auto-commits and pushes`,
245
+ ]);
246
+ }
247
+
248
+ console.log();
249
+ console.log(`${colors.bright}What happens automatically:${colors.reset}`);
250
+ console.log();
251
+ console.log(`${status.checkmark} DevOps Agent ${colors.cyan}watches${colors.reset} the worktree directory`);
252
+ console.log(`${status.checkmark} When commit message file changes, it ${colors.cyan}commits${colors.reset}`);
253
+ console.log(`${status.checkmark} After commit, it ${colors.cyan}pushes${colors.reset} to GitHub`);
254
+ console.log(`${status.checkmark} On session close, it ${colors.cyan}merges${colors.reset} to daily & main`);
255
+ console.log();
256
+
257
+ tutorialState.completed.push('module3');
258
+ success('Module 3 complete! You know how to work with AI assistants.');
259
+ }
260
+
261
+ /**
262
+ * Module 4: Multi-Agent Workflow
263
+ */
264
+ async function module4_multiAgent() {
265
+ sectionTitle('Module 4: Multi-Agent Workflow');
266
+
267
+ explain(`
268
+ One of DevOps Agent's powerful features is running multiple AI assistants
269
+ simultaneously without conflicts. Let's see how this works.
270
+ `);
271
+
272
+ console.log();
273
+ console.log(`${colors.bright}Scenario: Two features at once${colors.reset}`);
274
+ console.log();
275
+
276
+ drawSection('Terminal 1: Claude on Backend', [
277
+ `${colors.cyan}s9n-devops-agent create --task api --agent claude${colors.reset}`,
278
+ ``,
279
+ `${status.folder} Workspace: local_deploy/worktrees/abc1/`,
280
+ `${status.lock} Files locked: src/api/*.js, tests/api/*.js`,
281
+ `${status.commit} Status: Working on API endpoints`,
282
+ ]);
283
+
284
+ console.log();
285
+
286
+ drawSection('Terminal 2: Cursor on Frontend', [
287
+ `${colors.cyan}s9n-devops-agent create --task ui --agent cursor${colors.reset}`,
288
+ ``,
289
+ `${status.folder} Workspace: local_deploy/worktrees/def2/`,
290
+ `${status.lock} Files locked: src/components/*.tsx, src/styles/*.css`,
291
+ `${status.commit} Status: Working on UI components`,
292
+ ]);
293
+
294
+ console.log();
295
+ console.log(`${colors.bright}How conflicts are prevented:${colors.reset}`);
296
+ console.log();
297
+ console.log(`${status.point} ${colors.cyan}File Coordination${colors.reset}`);
298
+ console.log(` Each agent declares which files they'll edit`);
299
+ console.log(` System alerts if two agents try to edit the same file`);
300
+ console.log();
301
+ console.log(`${status.point} ${colors.cyan}Isolated Workspaces${colors.reset}`);
302
+ console.log(` Separate directories mean no accidental interference`);
303
+ console.log();
304
+ console.log(`${status.point} ${colors.cyan}Sequential Merging${colors.reset}`);
305
+ console.log(` Changes merge to daily branch in order`);
306
+ console.log(` Each merge is tested before the next`);
307
+ console.log();
308
+
309
+ const learnMore = await confirm('Learn more about file coordination?', false);
310
+ if (learnMore) {
311
+ await showTopicHelp('fileCoordination');
312
+ }
313
+
314
+ tutorialState.completed.push('module4');
315
+ success('Module 4 complete! You understand multi-agent collaboration.');
316
+ }
317
+
318
+ /**
319
+ * Module 5: Advanced Features
320
+ */
321
+ async function module5_advancedFeatures() {
322
+ sectionTitle('Module 5: Advanced Features');
323
+
324
+ explain(`
325
+ DevOps Agent has several advanced features that make development smoother.
326
+ Let's explore the most useful ones.
327
+ `);
328
+
329
+ console.log();
330
+
331
+ const topics = [
332
+ {
333
+ label: 'Branch Hierarchy',
334
+ description: 'session → daily → weekly → main structure'
335
+ },
336
+ {
337
+ label: 'House Rules',
338
+ description: 'Teaching AI agents your project conventions'
339
+ },
340
+ {
341
+ label: 'Version Strategies',
342
+ description: 'Automatic daily version incrementing'
343
+ },
344
+ {
345
+ label: 'Docker Integration',
346
+ description: 'Auto-restart containers after push'
347
+ },
348
+ {
349
+ label: 'Weekly Consolidation',
350
+ description: 'Automatic cleanup and rollup'
351
+ }
352
+ ];
353
+
354
+ for (const [index, topic] of topics.entries()) {
355
+ console.log(`${status.point} ${colors.bright}${topic.label}${colors.reset}`);
356
+ console.log(` ${colors.dim}${topic.description}${colors.reset}`);
357
+ console.log();
358
+ }
359
+
360
+ const exploreMore = await confirm('Explore these features in detail?', true);
361
+
362
+ if (exploreMore) {
363
+ const choice = await choose('Which feature interests you most?', [
364
+ 'Branch Hierarchy & Merging',
365
+ 'House Rules System',
366
+ 'Version Strategies',
367
+ 'Docker Integration',
368
+ 'All of them!'
369
+ ]);
370
+
371
+ const helpTopics = ['branches', 'houseRules', 'versions', 'docker', null];
372
+
373
+ if (choice === 4) {
374
+ info('Great! Check out the comprehensive help:');
375
+ console.log(` ${colors.green}s9n-devops-agent help${colors.reset}`);
376
+ console.log();
377
+ console.log('Or read the documentation:');
378
+ console.log(` ${colors.cyan}docs/V2_IMPLEMENTATION_GUIDE.md${colors.reset}`);
379
+ } else {
380
+ await showTopicHelp(helpTopics[choice]);
381
+ }
382
+ }
383
+
384
+ tutorialState.completed.push('module5');
385
+ success('Module 5 complete! You know about advanced features.');
386
+ }
387
+
388
+ // ============================================================================
389
+ // TUTORIAL COMPLETION
390
+ // ============================================================================
391
+
392
+ async function showCompletion() {
393
+ console.log();
394
+ console.log();
395
+ console.log(colors.bright + colors.green + '═'.repeat(70) + colors.reset);
396
+ console.log();
397
+ console.log(` ${status.success} ${colors.bright}Tutorial Complete!${colors.reset}`);
398
+ console.log();
399
+ console.log(colors.green + '═'.repeat(70) + colors.reset);
400
+ console.log();
401
+
402
+ const duration = Math.floor((Date.now() - tutorialState.startTime) / 1000 / 60);
403
+ console.log(`You completed all 5 modules in ${colors.cyan}${duration} minutes${colors.reset}!`);
404
+ console.log();
405
+
406
+ console.log(`${colors.bright}What you learned:${colors.reset}`);
407
+ console.log(` ${status.checkmark} Understanding Sessions`);
408
+ console.log(` ${status.checkmark} Creating Your First Session`);
409
+ console.log(` ${status.checkmark} Working with AI Assistants`);
410
+ console.log(` ${status.checkmark} Multi-Agent Workflow`);
411
+ console.log(` ${status.checkmark} Advanced Features`);
412
+ console.log();
413
+
414
+ console.log(`${colors.bright}Next steps:${colors.reset}`);
415
+ console.log();
416
+ console.log(` ${status.rocket} ${colors.green}Create your first real session:${colors.reset}`);
417
+ console.log(` s9n-devops-agent start`);
418
+ console.log();
419
+ console.log(` ${status.book} ${colors.cyan}Browse help topics:${colors.reset}`);
420
+ console.log(` s9n-devops-agent help`);
421
+ console.log();
422
+ console.log(` ${status.folder} ${colors.cyan}Read the documentation:${colors.reset}`);
423
+ console.log(` docs/V2_IMPLEMENTATION_GUIDE.md`);
424
+ console.log();
425
+
426
+ const setupNow = await confirm('Run setup wizard now?', false);
427
+
428
+ if (setupNow) {
429
+ console.log();
430
+ info('Great! Running setup wizard...');
431
+ console.log();
432
+ // Note: In full implementation, this would call the setup wizard
433
+ console.log(`${colors.dim}s9n-devops-agent setup${colors.reset}`);
434
+ } else {
435
+ console.log();
436
+ success('Tutorial complete! Happy coding with DevOps Agent! 🚀');
437
+ }
438
+ }
439
+
440
+ // ============================================================================
441
+ // MAIN TUTORIAL RUNNER
442
+ // ============================================================================
443
+
444
+ /**
445
+ * Run the complete interactive tutorial
446
+ */
447
+ export async function runTutorial() {
448
+ tutorialState.startTime = Date.now();
449
+
450
+ showWelcome('2.0.0');
451
+
452
+ console.log(`${status.book} ${colors.bright}Interactive Tutorial${colors.reset}`);
453
+ console.log();
454
+ explain(`
455
+ This tutorial will teach you everything you need to know about DevOps Agent.
456
+ It takes about 10-15 minutes and includes hands-on examples.
457
+
458
+ You can exit anytime with Ctrl+C and resume later.
459
+ `);
460
+
461
+ const ready = await confirm('Ready to start?', true);
462
+
463
+ if (!ready) {
464
+ info('No problem! Run this tutorial anytime with: s9n-devops-agent tutorial');
465
+ return;
466
+ }
467
+
468
+ console.log();
469
+
470
+ // Run all modules
471
+ try {
472
+ await module1_understandingSessions();
473
+ console.log();
474
+
475
+ await module2_creatingFirstSession();
476
+ console.log();
477
+
478
+ await module3_workingWithAI();
479
+ console.log();
480
+
481
+ await module4_multiAgent();
482
+ console.log();
483
+
484
+ await module5_advancedFeatures();
485
+ console.log();
486
+
487
+ await showCompletion();
488
+
489
+ } catch (error) {
490
+ if (error.message === 'User cancelled') {
491
+ console.log();
492
+ warn('Tutorial paused. Run again with: s9n-devops-agent tutorial');
493
+ console.log();
494
+ console.log(`Progress saved: ${tutorialState.completed.length}/5 modules complete`);
495
+ } else {
496
+ throw error;
497
+ }
498
+ }
499
+ }
500
+
501
+ /**
502
+ * Quick tutorial - condensed version
503
+ */
504
+ export async function runQuickTutorial() {
505
+ showWelcome('2.0.0');
506
+
507
+ console.log(`${status.rocket} ${colors.bright}Quick Start Tutorial (5 minutes)${colors.reset}`);
508
+ console.log();
509
+
510
+ explain(`
511
+ This quick tutorial covers the essentials to get you started immediately.
512
+ `);
513
+
514
+ console.log();
515
+ console.log(`${colors.bright}In 3 simple steps:${colors.reset}`);
516
+ console.log();
517
+ console.log(`${status.point} ${colors.cyan}Create a session${colors.reset}`);
518
+ console.log(` Isolated workspace for AI to work in`);
519
+ console.log(` ${colors.dim}Command: s9n-devops-agent start${colors.reset}`);
520
+ console.log();
521
+ console.log(`${status.point} ${colors.cyan}Give instructions to AI${colors.reset}`);
522
+ console.log(` Copy-paste provided instructions to Claude/Cursor`);
523
+ console.log(` AI works in the session workspace`);
524
+ console.log();
525
+ console.log(`${status.point} ${colors.cyan}Close session when done${colors.reset}`);
526
+ console.log(` Automatically merges to main and cleans up`);
527
+ console.log(` ${colors.dim}Command: s9n-devops-agent close${colors.reset}`);
528
+ console.log();
529
+
530
+ const fullTutorial = await confirm('Want the full tutorial with examples?', true);
531
+
532
+ if (fullTutorial) {
533
+ await runTutorial();
534
+ } else {
535
+ success('Quick tutorial complete! Run setup: s9n-devops-agent setup');
536
+ }
537
+ }
538
+
539
+ // Run tutorial if executed directly
540
+ if (import.meta.url === `file://${process.argv[1]}`) {
541
+ runTutorial().catch(error => {
542
+ console.error(error);
543
+ process.exit(1);
544
+ });
545
+ }
546
+
547
+ export default {
548
+ runTutorial,
549
+ runQuickTutorial,
550
+ };