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,475 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * ============================================================================
5
+ * HELP SYSTEM - Contextual Help for DevOps Agent v2.0
6
+ * ============================================================================
7
+ *
8
+ * Provides comprehensive, context-aware help throughout the application.
9
+ * Users can access help with [?] option or dedicated help commands.
10
+ *
11
+ * ============================================================================
12
+ */
13
+
14
+ import { showHelp, colors, status } from './ui-utils.js';
15
+
16
+ // ============================================================================
17
+ // HELP CONTENT
18
+ // ============================================================================
19
+
20
+ export const helpTopics = {
21
+ sessions: {
22
+ title: 'Sessions',
23
+ content: {
24
+ 'What is a Session?': `
25
+ A session is an isolated workspace where one AI agent works on
26
+ a specific task. Think of it like giving each AI assistant their
27
+ own office to work in.
28
+
29
+ Each session includes:
30
+ ${status.point} Git Worktree: Separate folder with full git history
31
+ ${status.point} Dedicated Branch: Auto-named based on task and date
32
+ ${status.point} File Locks: Prevents other agents from editing same files
33
+ ${status.point} Auto-Monitoring: Watches for changes and commits automatically`,
34
+
35
+ 'Why Use Sessions?': `
36
+ Sessions prevent chaos when working with AI assistants:
37
+
38
+ ${status.checkmark} No conflicts: Each agent has its own workspace
39
+ ${status.checkmark} Safe experimentation: Isolated from your main code
40
+ ${status.checkmark} Easy cleanup: Close session to merge and remove worktree
41
+ ${status.checkmark} Multi-agent: Run multiple AI assistants simultaneously`,
42
+
43
+ 'Workflow': `
44
+ ${colors.cyan}1.${colors.reset} Create session ${colors.dim}→${colors.reset} Get isolated workspace
45
+ ${colors.cyan}2.${colors.reset} Give AI instructions ${colors.dim}→${colors.reset} Paste to Claude/Cursor
46
+ ${colors.cyan}3.${colors.reset} AI works safely ${colors.dim}→${colors.reset} DevOps Agent commits automatically
47
+ ${colors.cyan}4.${colors.reset} Close session ${colors.dim}→${colors.reset} Merges to main, cleans up worktree`,
48
+
49
+ 'Common Commands': `
50
+ ${colors.green}s9n-devops-agent start${colors.reset} - Create new session
51
+ ${colors.green}s9n-devops-agent list${colors.reset} - Show all sessions
52
+ ${colors.green}s9n-devops-agent close${colors.reset} - Close active session`
53
+ }
54
+ },
55
+
56
+ worktrees: {
57
+ title: 'Git Worktrees',
58
+ content: {
59
+ 'What are Worktrees?': `
60
+ Git worktrees let you have multiple working directories for the
61
+ same repository. DevOps Agent uses them to give each session
62
+ its own isolated workspace.
63
+
64
+ ${status.folder} Main repo: /your/project
65
+ ${status.folder} Session 1: /your/project/local_deploy/worktrees/abc1
66
+ ${status.folder} Session 2: /your/project/local_deploy/worktrees/def2`,
67
+
68
+ 'Why Worktrees?': `
69
+ ${status.checkmark} Work on multiple features simultaneously
70
+ ${status.checkmark} Each AI agent gets its own space
71
+ ${status.checkmark} No need to stash or switch branches
72
+ ${status.checkmark} All worktrees share git history (efficient)`,
73
+
74
+ 'Automatic Management': `
75
+ You don't need to manage worktrees manually. DevOps Agent:
76
+ ${status.point} Creates worktree when you start a session
77
+ ${status.point} Monitors it for changes
78
+ ${status.point} Removes it when you close the session
79
+ ${status.point} Cleans up abandoned worktrees automatically`
80
+ }
81
+ },
82
+
83
+ fileCoordination: {
84
+ title: 'File Coordination',
85
+ content: {
86
+ 'What is File Coordination?': `
87
+ File coordination prevents multiple AI agents from editing
88
+ the same files simultaneously. It's like a "reserved" sign
89
+ on files being worked on.`,
90
+
91
+ 'How It Works': `
92
+ ${colors.cyan}1.${colors.reset} Agent declares files before editing
93
+ Creates: .file-coordination/active-edits/agent-session.json
94
+
95
+ ${colors.cyan}2.${colors.reset} System checks for conflicts
96
+ Looks for other agents editing same files
97
+
98
+ ${colors.cyan}3.${colors.reset} Agent works on declared files
99
+ Other agents see files are locked
100
+
101
+ ${colors.cyan}4.${colors.reset} Session closes, locks released
102
+ Files available for other agents`,
103
+
104
+ 'Declaration Format': `
105
+ {
106
+ "agent": "claude",
107
+ "session": "abc1-23d4",
108
+ "files": ["src/auth.js", "tests/auth.test.js"],
109
+ "reason": "Implementing JWT authentication",
110
+ "declaredAt": "2024-10-31T12:00:00Z"
111
+ }`,
112
+
113
+ 'Alert System': `
114
+ ${colors.yellow}${status.warning} Orange Alert${colors.reset} - File edited without declaration
115
+ ${colors.red}${status.error} Red Alert${colors.reset} - File being edited by another agent
116
+
117
+ Both alerts provide copy-paste instructions to fix the issue.`
118
+ }
119
+ },
120
+
121
+ branches: {
122
+ title: 'Branch Management',
123
+ content: {
124
+ 'Branch Hierarchy': `
125
+ DevOps Agent uses hierarchical branching for organization:
126
+
127
+ session/task_abc1 ${colors.dim}→${colors.reset} Session branch (your AI works here)
128
+ ${colors.dim}↓${colors.reset}
129
+ daily/dev_sdd_2024-10-31 ${colors.dim}→${colors.reset} Daily branch (merged on close)
130
+ ${colors.dim}↓${colors.reset}
131
+ weekly/2024-W44 ${colors.dim}→${colors.reset} Weekly branch (consolidated Sunday)
132
+ ${colors.dim}↓${colors.reset}
133
+ main ${colors.dim}→${colors.reset} Production branch`,
134
+
135
+ 'Why This Structure?': `
136
+ ${status.checkmark} ${colors.bright}Organized History${colors.reset} - Easy to see what was done when
137
+ ${status.checkmark} ${colors.bright}Easy Rollbacks${colors.reset} - Revert to any day or week
138
+ ${status.checkmark} ${colors.bright}Clear Progress${colors.reset} - Track development over time
139
+ ${status.checkmark} ${colors.bright}Safe Merging${colors.reset} - Changes flow through tested layers`,
140
+
141
+ 'Auto-Merging': `
142
+ ${colors.green}On Session Close:${colors.reset}
143
+ ${status.point} Merges session branch to daily branch
144
+ ${status.point} Merges daily branch to main (configurable)
145
+ ${status.point} Removes session branch and worktree
146
+
147
+ ${colors.green}Weekly Consolidation:${colors.reset}
148
+ ${status.point} Runs every Sunday at midnight
149
+ ${status.point} Merges all daily branches into weekly branch
150
+ ${status.point} Cleans up old daily branches`
151
+ }
152
+ },
153
+
154
+ houseRules: {
155
+ title: 'House Rules',
156
+ content: {
157
+ 'What are House Rules?': `
158
+ House rules are instructions for AI assistants in docs/houserules.md.
159
+ They teach AI agents about your project's conventions, testing
160
+ requirements, and coding standards.`,
161
+
162
+ 'What They Include': `
163
+ ${status.point} Commit message format and conventions
164
+ ${status.point} Testing requirements (what tests to run)
165
+ ${status.point} Code style preferences
166
+ ${status.point} File organization rules
167
+ ${status.point} Multi-agent coordination protocols
168
+ ${status.point} Project-specific guidelines`,
169
+
170
+ 'Auto-Management': `
171
+ ${colors.green}DevOps Agent manages house rules for you:${colors.reset}
172
+
173
+ ${status.checkmark} Creates on first setup
174
+ ${status.checkmark} Updates DevOps sections automatically
175
+ ${status.checkmark} Preserves your custom rules
176
+ ${status.checkmark} Self-heals if deleted
177
+ ${status.checkmark} Version tracked per section`,
178
+
179
+ 'Commands': `
180
+ ${colors.green}npm run house-rules:status${colors.reset} - Check status
181
+ ${colors.green}npm run house-rules:update${colors.reset} - Update/create
182
+ ${colors.green}npm run house-rules:repair${colors.reset} - Health check`
183
+ }
184
+ },
185
+
186
+ versions: {
187
+ title: 'Version Strategies',
188
+ content: {
189
+ 'Daily Versioning': `
190
+ DevOps Agent auto-increments versions daily. Choose your style:
191
+
192
+ ${colors.cyan}Option 1:${colors.reset} v0.20 → v0.21 → v0.22 (0.01 increments)
193
+ ${colors.dim}Best for: Frequent daily releases${colors.reset}
194
+
195
+ ${colors.cyan}Option 2:${colors.reset} v0.20 → v0.30 → v0.40 (0.1 increments)
196
+ ${colors.dim}Best for: Weekly milestone tracking${colors.reset}
197
+
198
+ ${colors.cyan}Option 3:${colors.reset} v0.20 → v0.40 → v0.60 (0.2 increments)
199
+ ${colors.dim}Best for: Bi-weekly sprints${colors.reset}`,
200
+
201
+ 'Why Daily Versions?': `
202
+ ${status.checkmark} Clear timeline of development
203
+ ${status.checkmark} Easy to reference specific days
204
+ ${status.checkmark} Automatic version bumps (no manual work)
205
+ ${status.checkmark} Aligned with daily branch structure`,
206
+
207
+ 'Configuration': `
208
+ Set in local_deploy/project-settings.json:
209
+
210
+ {
211
+ "versionPrefix": "v0.",
212
+ "versionStartMinor": "20",
213
+ "versionIncrement": "1"
214
+ }
215
+
216
+ ${colors.dim}Increment: 1 = 0.01, 10 = 0.1, 20 = 0.2${colors.reset}`
217
+ }
218
+ },
219
+
220
+ multiAgent: {
221
+ title: 'Multi-Agent Collaboration',
222
+ content: {
223
+ 'Working with Multiple AIs': `
224
+ DevOps Agent lets multiple AI assistants work simultaneously
225
+ without conflicts. Each gets their own session and workspace.`,
226
+
227
+ 'Example Workflow': `
228
+ ${colors.cyan}Terminal 1:${colors.reset} Claude working on backend API
229
+ ${colors.dim}s9n-devops-agent create --task api --agent claude${colors.reset}
230
+
231
+ ${colors.cyan}Terminal 2:${colors.reset} Cursor working on frontend UI
232
+ ${colors.dim}s9n-devops-agent create --task ui --agent cursor${colors.reset}
233
+
234
+ ${status.checkmark} Each agent has isolated workspace
235
+ ${status.checkmark} File coordination prevents conflicts
236
+ ${status.checkmark} Both can work independently`,
237
+
238
+ 'Safety Mechanisms': `
239
+ ${colors.green}File Locking:${colors.reset}
240
+ Agents declare files before editing. System alerts on conflicts.
241
+
242
+ ${colors.green}Session Isolation:${colors.reset}
243
+ Separate worktrees mean no accidental interference.
244
+
245
+ ${colors.green}Merge Coordination:${colors.reset}
246
+ Changes merge to daily branch in order, tested at each step.`,
247
+
248
+ 'Best Practices': `
249
+ ${status.point} Divide work by feature or component
250
+ ${status.point} Use clear, descriptive task names
251
+ ${status.point} Monitor file coordination alerts
252
+ ${status.point} Close sessions promptly when done`
253
+ }
254
+ },
255
+
256
+ docker: {
257
+ title: 'Docker Integration',
258
+ content: {
259
+ 'Auto-Restart Feature': `
260
+ DevOps Agent can automatically restart Docker containers
261
+ after pushing code changes. Great for testing immediately.`,
262
+
263
+ 'How to Enable': `
264
+ During session creation, when docker-compose is detected:
265
+
266
+ ${colors.cyan}?${colors.reset} Auto-restart Docker containers after push? ${colors.dim}(y/N)${colors.reset}: y
267
+ ${colors.cyan}?${colors.reset} Rebuild containers on restart? ${colors.dim}(y/N)${colors.reset}: n
268
+ ${colors.cyan}?${colors.reset} Specific service to restart ${colors.dim}(or empty for all)${colors.reset}: app`,
269
+
270
+ 'Supported Files': `
271
+ ${status.checkmark} docker-compose.yml / docker-compose.yaml
272
+ ${status.checkmark} compose.yml / compose.yaml
273
+ ${status.checkmark} docker-compose.dev.yml
274
+ ${status.checkmark} docker-compose.local.yml`,
275
+
276
+ 'Behavior': `
277
+ ${colors.green}On Every Push:${colors.reset}
278
+ 1. Git push completes successfully
279
+ 2. Docker restart command runs
280
+ 3. Containers restart with new code
281
+ 4. DevOps Agent continues monitoring
282
+
283
+ ${colors.yellow}Note:${colors.reset} Docker failures don't affect git workflow.`
284
+ }
285
+ },
286
+
287
+ troubleshooting: {
288
+ title: 'Troubleshooting',
289
+ content: {
290
+ 'Session Not Found': `
291
+ ${colors.red}Error:${colors.reset} "Session abc1 not found"
292
+
293
+ ${colors.cyan}Possible causes:${colors.reset}
294
+ ${status.point} Session already closed
295
+ ${status.point} Session expired (inactive >24h)
296
+ ${status.point} Wrong session ID
297
+
298
+ ${colors.cyan}Solutions:${colors.reset}
299
+ 1. List sessions: ${colors.green}s9n-devops-agent list${colors.reset}
300
+ 2. Check closed: ${colors.green}s9n-devops-agent list --all${colors.reset}
301
+ 3. Create new: ${colors.green}s9n-devops-agent start${colors.reset}`,
302
+
303
+ 'Agent Not Detecting Changes': `
304
+ ${colors.red}Problem:${colors.reset} Files changed but not committed
305
+
306
+ ${colors.cyan}Debug steps:${colors.reset}
307
+ 1. Check commit message file exists:
308
+ ${colors.dim}ls -la .devops-commit-*.msg${colors.reset}
309
+
310
+ 2. Verify file has content:
311
+ ${colors.dim}cat .devops-commit-abc1.msg${colors.reset}
312
+
313
+ 3. Enable debug mode:
314
+ ${colors.dim}AC_DEBUG=true s9n-devops-agent start${colors.reset}
315
+
316
+ 4. Check agent is running:
317
+ ${colors.dim}ps aux | grep cs-devops-agent-worker${colors.reset}`,
318
+
319
+ 'Merge Conflicts': `
320
+ ${colors.red}Problem:${colors.reset} Conflicts when closing session
321
+
322
+ ${colors.cyan}Why it happens:${colors.reset}
323
+ ${status.point} Someone else modified same files in main
324
+ ${status.point} Daily branch diverged from main
325
+
326
+ ${colors.cyan}How to resolve:${colors.reset}
327
+ 1. Agent pauses and shows conflict files
328
+ 2. Manually resolve conflicts in worktree
329
+ 3. Mark as resolved
330
+ 4. Agent completes merge`,
331
+
332
+ 'Performance Issues': `
333
+ ${colors.red}Problem:${colors.reset} Agent slow or high CPU usage
334
+
335
+ ${colors.cyan}Solutions:${colors.reset}
336
+ ${status.point} Reduce AC_DEBOUNCE_MS for faster commits
337
+ ${status.point} Exclude large directories from watch
338
+ ${status.point} Close unused sessions
339
+ ${status.point} Clean up old worktrees: ${colors.green}npm run devops:cleanup${colors.reset}`
340
+ }
341
+ }
342
+ };
343
+
344
+ // ============================================================================
345
+ // HELP FUNCTIONS
346
+ // ============================================================================
347
+
348
+ /**
349
+ * Show help for a specific topic
350
+ */
351
+ export async function showTopicHelp(topicKey) {
352
+ const topic = helpTopics[topicKey];
353
+
354
+ if (!topic) {
355
+ console.log(`${colors.red}Unknown help topic: ${topicKey}${colors.reset}`);
356
+ console.log(`\nAvailable topics: ${Object.keys(helpTopics).join(', ')}`);
357
+ return;
358
+ }
359
+
360
+ await showHelp(topic.title, topic.content);
361
+ }
362
+
363
+ /**
364
+ * Show help menu with all topics
365
+ */
366
+ export async function showHelpMenu() {
367
+ console.log();
368
+ console.log(`${colors.bright}${colors.cyan}DevOps Agent Help${colors.reset}`);
369
+ console.log();
370
+ console.log('Available help topics:');
371
+ console.log();
372
+
373
+ const topics = [
374
+ { key: 'sessions', desc: 'Understanding sessions and workflows' },
375
+ { key: 'worktrees', desc: 'Git worktrees and isolation' },
376
+ { key: 'fileCoordination', desc: 'Multi-agent file coordination' },
377
+ { key: 'branches', desc: 'Branch hierarchy and management' },
378
+ { key: 'houseRules', desc: 'House rules for AI agents' },
379
+ { key: 'versions', desc: 'Version strategies and daily versioning' },
380
+ { key: 'multiAgent', desc: 'Working with multiple AI assistants' },
381
+ { key: 'docker', desc: 'Docker container integration' },
382
+ { key: 'troubleshooting', desc: 'Common issues and solutions' },
383
+ ];
384
+
385
+ topics.forEach((topic, index) => {
386
+ console.log(` ${colors.cyan}${index + 1})${colors.reset} ${colors.bright}${topic.key}${colors.reset}`);
387
+ console.log(` ${colors.dim}${topic.desc}${colors.reset}`);
388
+ console.log();
389
+ });
390
+
391
+ console.log(`Enter topic number, name, or 'q' to quit:`);
392
+ console.log();
393
+ }
394
+
395
+ /**
396
+ * Interactive help browser
397
+ */
398
+ export async function helpBrowser() {
399
+ const readline = require('readline').createInterface({
400
+ input: process.stdin,
401
+ output: process.stdout
402
+ });
403
+
404
+ while (true) {
405
+ await showHelpMenu();
406
+
407
+ const answer = await new Promise((resolve) => {
408
+ readline.question('> ', resolve);
409
+ });
410
+
411
+ const cleaned = answer.trim().toLowerCase();
412
+
413
+ if (cleaned === 'q' || cleaned === 'quit' || cleaned === 'exit') {
414
+ readline.close();
415
+ break;
416
+ }
417
+
418
+ // Check if it's a number
419
+ const num = parseInt(cleaned);
420
+ if (!isNaN(num) && num >= 1 && num <= Object.keys(helpTopics).length) {
421
+ const topicKey = Object.keys(helpTopics)[num - 1];
422
+ await showTopicHelp(topicKey);
423
+ continue;
424
+ }
425
+
426
+ // Check if it's a topic name
427
+ if (helpTopics[cleaned]) {
428
+ await showTopicHelp(cleaned);
429
+ continue;
430
+ }
431
+
432
+ console.log(`${colors.red}Unknown topic. Try again.${colors.reset}`);
433
+ }
434
+ }
435
+
436
+ /**
437
+ * Quick help for specific context
438
+ */
439
+ export function quickHelp(context) {
440
+ const quickHelps = {
441
+ setup: `${colors.cyan}💡 Setup Help:${colors.reset}
442
+ Configuring DevOps Agent for your project. You'll set:
443
+ ${status.point} Developer initials (for branch naming)
444
+ ${status.point} Version strategy (how versions increment)
445
+ ${status.point} Timezone (for daily rollover)
446
+
447
+ Press [?] at any prompt for detailed help on that topic.`,
448
+
449
+ sessionCreate: `${colors.cyan}💡 Session Creation Help:${colors.reset}
450
+ Creating an isolated workspace for an AI agent.
451
+ ${status.point} Task name becomes part of branch name
452
+ ${status.point} Each session gets its own git worktree
453
+ ${status.point} File locks prevent conflicts with other agents
454
+
455
+ Type '?' at any prompt for more information.`,
456
+
457
+ versionStrategy: `${colors.cyan}💡 Version Strategy Help:${colors.reset}
458
+ Choose how version numbers increment each day:
459
+ ${colors.bright}0.01 increments:${colors.reset} v0.20 → v0.21 (daily releases)
460
+ ${colors.bright}0.1 increments:${colors.reset} v0.20 → v0.30 (weekly milestones)
461
+ ${colors.bright}0.2 increments:${colors.reset} v0.20 → v0.40 (bi-weekly sprints)
462
+
463
+ For full details: s9n-devops-agent help versions`,
464
+ };
465
+
466
+ return quickHelps[context] || '';
467
+ }
468
+
469
+ export default {
470
+ helpTopics,
471
+ showTopicHelp,
472
+ showHelpMenu,
473
+ helpBrowser,
474
+ quickHelp,
475
+ };