@misterhuydo/sentinel 1.0.2 → 1.0.3

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 (2) hide show
  1. package/lib/init.js +246 -250
  2. package/package.json +21 -21
package/lib/init.js CHANGED
@@ -1,250 +1,246 @@
1
- 'use strict';
2
-
3
- const fs = require('fs-extra');
4
- const path = require('path');
5
- const os = require('os');
6
- const { execSync, spawnSync } = require('child_process');
7
- const prompts = require('prompts');
8
- const chalk = require('chalk');
9
- const { generateProjectScripts, generateWorkspaceScripts, writeExampleProject } = require('./generate');
10
-
11
- const ok = msg => console.log(chalk.green(' ✔'), msg);
12
- const info = msg => console.log(chalk.cyan(' →'), msg);
13
- const warn = msg => console.log(chalk.yellow(' ⚠'), msg);
14
- const step = msg => console.log('\n' + chalk.bold.white(msg));
15
-
16
- module.exports = async function init() {
17
- // ── Prompts ─────────────────────────────────────────────────────────────────
18
- const answers = await prompts([
19
- {
20
- type: 'text',
21
- name: 'workspace',
22
- message: 'Workspace directory (each project lives here as a subdirectory)',
23
- initial: path.join(os.homedir(), 'sentinel'),
24
- format: v => v.replace(/^~/, os.homedir()),
25
- },
26
- {
27
- type: 'select',
28
- name: 'authMode',
29
- message: 'How will Claude Code authenticate?',
30
- choices: [
31
- { title: 'API key (Anthropic API account — recommended for servers)', value: 'apikey' },
32
- { title: 'Claude Pro / OAuth (will give you a URL to open in any browser)', value: 'oauth' },
33
- { title: 'Skip (I will configure this later)', value: 'skip' },
34
- ],
35
- },
36
- {
37
- type: prev => prev === 'apikey' ? 'password' : null,
38
- name: 'anthropicKey',
39
- message: 'Anthropic API key (sk-ant-...)',
40
- validate: v => v.startsWith('sk-ant-') ? true : 'Key should start with sk-ant-',
41
- },
42
- {
43
- type: 'confirm',
44
- name: 'example',
45
- message: 'Create an example project to show how to configure?',
46
- initial: true,
47
- },
48
- {
49
- type: 'confirm',
50
- name: 'systemd',
51
- message: 'Set up systemd service for auto-start on reboot?',
52
- initial: process.platform === 'linux',
53
- },
54
- ], { onCancel: () => process.exit(0) });
55
-
56
- const { workspace, authMode, anthropicKey, example, systemd } = answers;
57
- const codeDir = path.join(workspace, 'code');
58
-
59
- // ── Python ──────────────────────────────────────────────────────────────────
60
- step('Checking Python…');
61
- const python = findPython();
62
- if (!python) {
63
- console.error(chalk.red(' ✖ python3 not found. Install it first:'));
64
- console.error(' sudo apt-get install -y python3 python3-pip python3-venv');
65
- process.exit(1);
66
- }
67
- ok(`Python: ${run(python, ['--version']).trim()}`);
68
-
69
- // ── Copy Sentinel Python source ─────────────────────────────────────────────
70
- step('Installing Sentinel code…');
71
- const bundledPython = path.join(__dirname, '..', 'python');
72
- if (!fs.existsSync(bundledPython)) {
73
- console.error(chalk.red(' ✖ Bundled Python source not found (run npm publish from the Sentinel repo)'));
74
- process.exit(1);
75
- }
76
- fs.ensureDirSync(codeDir);
77
- fs.copySync(bundledPython, codeDir, { overwrite: true });
78
- ok(`Sentinel code → ${codeDir}`);
79
-
80
- // ── Python venv ─────────────────────────────────────────────────────────────
81
- step('Setting up Python environment…');
82
- const venv = path.join(codeDir, '.venv');
83
- if (!fs.existsSync(venv)) {
84
- info('Creating virtual environment…');
85
- runLive(python, ['-m', 'venv', venv]);
86
- }
87
- const pip = path.join(venv, 'bin', 'pip3');
88
- const pythonBin = path.join(venv, 'bin', 'python3');
89
- info('Installing Python packages…');
90
- runLive(pip, ['install', '--quiet', '--upgrade', 'pip']);
91
- runLive(pip, ['install', '--quiet', '-r', path.join(codeDir, 'requirements.txt')]);
92
- ok('Python packages installed');
93
-
94
- // ── Node tools ──────────────────────────────────────────────────────────────
95
- step('Installing Node tools…');
96
- installNpmGlobal('@misterhuydo/cairn-mcp', 'cairn');
97
- installNpmGlobal('@anthropic-ai/claude-code', 'claude');
98
-
99
- // ── Claude Code auth ─────────────────────────────────────────────────────────
100
- step('Claude Code authentication…');
101
- if (authMode === 'apikey' && anthropicKey) {
102
- ok('API key will be written to each project\'s sentinel.properties');
103
- } else if (authMode === 'oauth') {
104
- console.log(chalk.yellow(
105
- '\n Claude Code OAuth requires an interactive step.\n' +
106
- ' After setup completes, run this command on the server:\n\n' +
107
- chalk.bold(' claude\n\n') +
108
- ' It will print a URL like:\n' +
109
- ' https://claude.ai/oauth/authorize?...\n\n' +
110
- ' Open that URL in any browser, log in with your Claude Pro account,\n' +
111
- ' and the server will be authenticated. The token is stored in ~/.claude/\n' +
112
- ' and persists across restarts.\n'
113
- ));
114
- warn('OAuth not completed yet — run "claude" after setup to authenticate');
115
- } else {
116
- warn('Skipping auth set ANTHROPIC_API_KEY in sentinel.properties or run "claude" to authenticate');
117
- }
118
-
119
- // ── Workspace structure ─────────────────────────────────────────────────────
120
- step('Creating workspace…');
121
- fs.ensureDirSync(workspace);
122
- ok(`Workspace: ${workspace}`);
123
-
124
- // ── Example project ─────────────────────────────────────────────────────────
125
- if (example) {
126
- step('Creating example project…');
127
- const exampleDir = path.join(workspace, 'my-project');
128
- writeExampleProject(exampleDir, codeDir, pythonBin, anthropicKey || '');
129
- ok(`Example project: ${exampleDir}`);
130
- }
131
-
132
- // ── Workspace start/stop scripts ─────────────────────────────────────────────
133
- step('Generating scripts…');
134
- generateWorkspaceScripts(workspace);
135
- ok(`${workspace}/startAll.sh`);
136
- ok(`${workspace}/stopAll.sh`);
137
-
138
- // ── systemd ──────────────────────────────────────────────────────────────────
139
- if (systemd) {
140
- step('Setting up systemd…');
141
- setupSystemd(workspace);
142
- }
143
-
144
- // ── Done ─────────────────────────────────────────────────────────────────────
145
- console.log('\n' + chalk.bold.green('══ Done! ══') + '\n');
146
- console.log(`${chalk.bold('Next steps:')}`);
147
- if (example) {
148
- console.log(`
149
- 1. Configure your first project:
150
- ${chalk.cyan(`${workspace}/my-project/config/sentinel.properties`)}
151
- ${chalk.cyan(`${workspace}/my-project/config/log-configs/`)}
152
- ${chalk.cyan(`${workspace}/my-project/config/repo-configs/`)}
153
-
154
- 2. First-time init (clones repos, tests SSH, sends test email):
155
- ${chalk.cyan(`${workspace}/my-project/init.sh`)}
156
-
157
- 3. Start all projects:
158
- ${chalk.cyan(`${workspace}/startAll.sh`)}
159
-
160
- 4. Stop all projects:
161
- ${chalk.cyan(`${workspace}/stopAll.sh`)}
162
- `);
163
- }
164
- if (systemd) {
165
- console.log(` Auto-start is enabled. To manage:
166
- ${chalk.cyan('sudo systemctl start sentinel')}
167
- ${chalk.cyan('sudo systemctl status sentinel')}
168
- ${chalk.cyan('journalctl -u sentinel -f')}
169
- `);
170
- }
171
- if (authMode === 'oauth') {
172
- console.log(
173
- chalk.bold.yellow(' ⚠ Complete Claude Code login now:\n') +
174
- ` ${chalk.bold.cyan('claude')}\n` +
175
- ' Open the URL it prints in any browser → log in with Claude Pro.\n'
176
- );
177
- }
178
-
179
- console.log(` Add another project anytime:
180
- ${chalk.cyan('sentinel add <project-name>')}
181
- `);
182
- };
183
-
184
- // ── Helpers ──────────────────────────────────────────────────────────────────
185
-
186
- function findPython() {
187
- for (const bin of ['python3', 'python']) {
188
- try {
189
- execSync(`${bin} --version`, { stdio: 'pipe' });
190
- return bin;
191
- } catch (_) {}
192
- }
193
- return null;
194
- }
195
-
196
- function run(bin, args) {
197
- const r = spawnSync(bin, args, { encoding: 'utf8' });
198
- return (r.stdout || '') + (r.stderr || '');
199
- }
200
-
201
- function runLive(bin, args) {
202
- const r = spawnSync(bin, args, { stdio: 'inherit' });
203
- if (r.status !== 0) {
204
- console.error(chalk.red(` ✖ Command failed: ${bin} ${args.join(' ')}`));
205
- process.exit(1);
206
- }
207
- }
208
-
209
- function installNpmGlobal(pkg, checkBin) {
210
- try {
211
- execSync(`${checkBin} --version`, { stdio: 'pipe' });
212
- ok(`${pkg} already installed`);
213
- } catch (_) {
214
- info(`Installing ${pkg}…`);
215
- runLive('npm', ['install', '-g', pkg]);
216
- ok(`${pkg} installed`);
217
- }
218
- }
219
-
220
- function setupSystemd(workspace) {
221
- const user = os.userInfo().username;
222
- const svc = `/etc/systemd/system/sentinel.service`;
223
- const content = `[Unit]
224
- Description=Sentinel — Autonomous DevOps Agent
225
- After=network-online.target
226
- Wants=network-online.target
227
-
228
- [Service]
229
- Type=forking
230
- User=${user}
231
- WorkingDirectory=${workspace}
232
- ExecStart=${workspace}/startAll.sh
233
- ExecStop=${workspace}/stopAll.sh
234
- Restart=on-failure
235
- RestartSec=10
236
-
237
- [Install]
238
- WantedBy=multi-user.target
239
- `;
240
- try {
241
- fs.writeFileSync('/tmp/sentinel.service', content);
242
- execSync(`sudo mv /tmp/sentinel.service ${svc}`);
243
- execSync('sudo systemctl daemon-reload');
244
- execSync('sudo systemctl enable sentinel');
245
- ok('sentinel.service enabled');
246
- } catch (e) {
247
- warn(`Could not write systemd service (need sudo): ${e.message}`);
248
- warn(`Manually create ${svc} to auto-start on reboot`);
249
- }
250
- }
1
+ 'use strict';
2
+
3
+ const fs = require('fs-extra');
4
+ const path = require('path');
5
+ const os = require('os');
6
+ const { execSync, spawnSync } = require('child_process');
7
+ const prompts = require('prompts');
8
+ const chalk = require('chalk');
9
+ const { generateProjectScripts, generateWorkspaceScripts, writeExampleProject } = require('./generate');
10
+
11
+ const ok = msg => console.log(chalk.green(' ✔'), msg);
12
+ const info = msg => console.log(chalk.cyan(' →'), msg);
13
+ const warn = msg => console.log(chalk.yellow(' ⚠'), msg);
14
+ const step = msg => console.log('\n' + chalk.bold.white(msg));
15
+
16
+ module.exports = async function init() {
17
+ // ── Prompts ─────────────────────────────────────────────────────────────────
18
+ const answers = await prompts([
19
+ {
20
+ type: 'text',
21
+ name: 'workspace',
22
+ message: 'Workspace directory (each project lives here as a subdirectory)',
23
+ initial: path.join(os.homedir(), 'sentinel'),
24
+ format: v => v.replace(/^~/, os.homedir()),
25
+ },
26
+ {
27
+ type: 'select',
28
+ name: 'authMode',
29
+ message: 'How will Claude Code authenticate?',
30
+ choices: [
31
+ { title: 'API key (Anthropic API account — recommended for servers)', value: 'apikey' },
32
+ { title: 'Claude Pro / OAuth (will give you a URL to open in any browser)', value: 'oauth' },
33
+ { title: 'Skip (I will configure this later)', value: 'skip' },
34
+ ],
35
+ },
36
+ {
37
+ type: prev => prev === 'apikey' ? 'password' : null,
38
+ name: 'anthropicKey',
39
+ message: 'Anthropic API key (sk-ant-...)',
40
+ validate: v => v.startsWith('sk-ant-') ? true : 'Key should start with sk-ant-',
41
+ },
42
+ {
43
+ type: 'confirm',
44
+ name: 'example',
45
+ message: 'Create an example project to show how to configure?',
46
+ initial: true,
47
+ },
48
+ {
49
+ type: 'confirm',
50
+ name: 'systemd',
51
+ message: 'Set up systemd service for auto-start on reboot?',
52
+ initial: process.platform === 'linux',
53
+ },
54
+ ], { onCancel: () => process.exit(0) });
55
+
56
+ const { workspace, authMode, anthropicKey, example, systemd } = answers;
57
+ const codeDir = path.join(workspace, 'code');
58
+
59
+ // ── Python ──────────────────────────────────────────────────────────────────
60
+ step('Checking Python…');
61
+ const python = findPython();
62
+ if (!python) {
63
+ console.error(chalk.red(' ✖ python3 not found. Install it first:'));
64
+ console.error(' sudo apt-get install -y python3 python3-pip python3-venv');
65
+ process.exit(1);
66
+ }
67
+ ok(`Python: ${run(python, ['--version']).trim()}`);
68
+
69
+ // ── Copy Sentinel Python source ─────────────────────────────────────────────
70
+ step('Installing Sentinel code…');
71
+ const bundledPython = path.join(__dirname, '..', 'python');
72
+ if (!fs.existsSync(bundledPython)) {
73
+ console.error(chalk.red(' ✖ Bundled Python source not found (run npm publish from the Sentinel repo)'));
74
+ process.exit(1);
75
+ }
76
+ fs.ensureDirSync(codeDir);
77
+ fs.copySync(bundledPython, codeDir, { overwrite: true });
78
+ ok(`Sentinel code → ${codeDir}`);
79
+
80
+ // ── Python venv ─────────────────────────────────────────────────────────────
81
+ step('Setting up Python environment…');
82
+ const venv = path.join(codeDir, '.venv');
83
+ if (!fs.existsSync(venv)) {
84
+ info('Creating virtual environment…');
85
+ runLive(python, ['-m', 'venv', venv]);
86
+ }
87
+ const pip = path.join(venv, 'bin', 'pip3');
88
+ const pythonBin = path.join(venv, 'bin', 'python3');
89
+ info('Installing Python packages…');
90
+ runLive(pip, ['install', '--quiet', '--upgrade', 'pip']);
91
+ runLive(pip, ['install', '--quiet', '-r', path.join(codeDir, 'requirements.txt')]);
92
+ ok('Python packages installed');
93
+
94
+ // ── Node tools ──────────────────────────────────────────────────────────────
95
+ step('Installing Node tools…');
96
+ installNpmGlobal('@misterhuydo/cairn-mcp', 'cairn');
97
+ installNpmGlobal('@anthropic-ai/claude-code', 'claude');
98
+
99
+ // ── Claude Code auth ─────────────────────────────────────────────────────────
100
+ step('Claude Code authentication…');
101
+ if (authMode === 'apikey' && anthropicKey) {
102
+ ok('API key will be written to each project\'s sentinel.properties');
103
+ } else if (authMode === 'oauth') {
104
+ console.log(chalk.yellow(
105
+ '\n Launching Claude Code login type /login at the prompt to get your auth URL.\n' +
106
+ ' Open the URL in any browser, log in with your Claude Pro account,\n' +
107
+ ' then type /exit (or Ctrl-C) to return here.\n'
108
+ ));
109
+ spawnSync('claude', [], { stdio: 'inherit' });
110
+ // Verify auth succeeded after the user exits claude
111
+ const authCheck = spawnSync('claude', ['--print', 'hi'], { encoding: 'utf8', timeout: 15000 });
112
+ const authOut = (authCheck.stdout || '') + (authCheck.stderr || '');
113
+ if (authOut.toLowerCase().includes('not logged in') || authOut.toLowerCase().includes('/login')) {
114
+ warn('Not authenticated yet — run "claude" and type /login when ready');
115
+ } else {
116
+ ok('Claude Code authenticated via OAuth');
117
+ }
118
+ } else {
119
+ warn('Skipping auth set ANTHROPIC_API_KEY in sentinel.properties or run "claude" to authenticate');
120
+ }
121
+
122
+ // ── Workspace structure ─────────────────────────────────────────────────────
123
+ step('Creating workspace…');
124
+ fs.ensureDirSync(workspace);
125
+ ok(`Workspace: ${workspace}`);
126
+
127
+ // ── Example project ─────────────────────────────────────────────────────────
128
+ if (example) {
129
+ step('Creating example project…');
130
+ const exampleDir = path.join(workspace, 'my-project');
131
+ writeExampleProject(exampleDir, codeDir, pythonBin, anthropicKey || '');
132
+ ok(`Example project: ${exampleDir}`);
133
+ }
134
+
135
+ // ── Workspace start/stop scripts ─────────────────────────────────────────────
136
+ step('Generating scripts…');
137
+ generateWorkspaceScripts(workspace);
138
+ ok(`${workspace}/startAll.sh`);
139
+ ok(`${workspace}/stopAll.sh`);
140
+
141
+ // ── systemd ──────────────────────────────────────────────────────────────────
142
+ if (systemd) {
143
+ step('Setting up systemd…');
144
+ setupSystemd(workspace);
145
+ }
146
+
147
+ // ── Done ─────────────────────────────────────────────────────────────────────
148
+ console.log('\n' + chalk.bold.green('══ Done! ══') + '\n');
149
+ console.log(`${chalk.bold('Next steps:')}`);
150
+ if (example) {
151
+ console.log(`
152
+ 1. Configure your first project:
153
+ ${chalk.cyan(`${workspace}/my-project/config/sentinel.properties`)}
154
+ ${chalk.cyan(`${workspace}/my-project/config/log-configs/`)}
155
+ ${chalk.cyan(`${workspace}/my-project/config/repo-configs/`)}
156
+
157
+ 2. First-time init (clones repos, tests SSH, sends test email):
158
+ ${chalk.cyan(`${workspace}/my-project/init.sh`)}
159
+
160
+ 3. Start all projects:
161
+ ${chalk.cyan(`${workspace}/startAll.sh`)}
162
+
163
+ 4. Stop all projects:
164
+ ${chalk.cyan(`${workspace}/stopAll.sh`)}
165
+ `);
166
+ }
167
+ if (systemd) {
168
+ console.log(` Auto-start is enabled. To manage:
169
+ ${chalk.cyan('sudo systemctl start sentinel')}
170
+ ${chalk.cyan('sudo systemctl status sentinel')}
171
+ ${chalk.cyan('journalctl -u sentinel -f')}
172
+ `);
173
+ }
174
+
175
+ console.log(` Add another project anytime:
176
+ ${chalk.cyan('sentinel add <project-name>')}
177
+ `);
178
+ };
179
+
180
+ // ── Helpers ──────────────────────────────────────────────────────────────────
181
+
182
+ function findPython() {
183
+ for (const bin of ['python3', 'python']) {
184
+ try {
185
+ execSync(`${bin} --version`, { stdio: 'pipe' });
186
+ return bin;
187
+ } catch (_) {}
188
+ }
189
+ return null;
190
+ }
191
+
192
+ function run(bin, args) {
193
+ const r = spawnSync(bin, args, { encoding: 'utf8' });
194
+ return (r.stdout || '') + (r.stderr || '');
195
+ }
196
+
197
+ function runLive(bin, args) {
198
+ const r = spawnSync(bin, args, { stdio: 'inherit' });
199
+ if (r.status !== 0) {
200
+ console.error(chalk.red(` ✖ Command failed: ${bin} ${args.join(' ')}`));
201
+ process.exit(1);
202
+ }
203
+ }
204
+
205
+ function installNpmGlobal(pkg, checkBin) {
206
+ try {
207
+ execSync(`${checkBin} --version`, { stdio: 'pipe' });
208
+ ok(`${pkg} already installed`);
209
+ } catch (_) {
210
+ info(`Installing ${pkg}…`);
211
+ runLive('npm', ['install', '-g', pkg]);
212
+ ok(`${pkg} installed`);
213
+ }
214
+ }
215
+
216
+ function setupSystemd(workspace) {
217
+ const user = os.userInfo().username;
218
+ const svc = `/etc/systemd/system/sentinel.service`;
219
+ const content = `[Unit]
220
+ Description=Sentinel Autonomous DevOps Agent
221
+ After=network-online.target
222
+ Wants=network-online.target
223
+
224
+ [Service]
225
+ Type=forking
226
+ User=${user}
227
+ WorkingDirectory=${workspace}
228
+ ExecStart=${workspace}/startAll.sh
229
+ ExecStop=${workspace}/stopAll.sh
230
+ Restart=on-failure
231
+ RestartSec=10
232
+
233
+ [Install]
234
+ WantedBy=multi-user.target
235
+ `;
236
+ try {
237
+ fs.writeFileSync('/tmp/sentinel.service', content);
238
+ execSync(`sudo mv /tmp/sentinel.service ${svc}`);
239
+ execSync('sudo systemctl daemon-reload');
240
+ execSync('sudo systemctl enable sentinel');
241
+ ok('sentinel.service enabled');
242
+ } catch (e) {
243
+ warn(`Could not write systemd service (need sudo): ${e.message}`);
244
+ warn(`Manually create ${svc} to auto-start on reboot`);
245
+ }
246
+ }
package/package.json CHANGED
@@ -1,21 +1,21 @@
1
- {
2
- "name": "@misterhuydo/sentinel",
3
- "version": "1.0.2",
4
- "description": "Sentinel — Autonomous DevOps Agent installer and manager",
5
- "bin": {
6
- "sentinel": "./bin/sentinel.js"
7
- },
8
- "scripts": {
9
- "prepublishOnly": "node scripts/bundle.js"
10
- },
11
- "dependencies": {
12
- "chalk": "^4.1.2",
13
- "fs-extra": "^11.2.0",
14
- "prompts": "^2.4.2"
15
- },
16
- "engines": {
17
- "node": ">=16"
18
- },
19
- "author": "misterhuydo",
20
- "license": "MIT"
21
- }
1
+ {
2
+ "name": "@misterhuydo/sentinel",
3
+ "version": "1.0.3",
4
+ "description": "Sentinel — Autonomous DevOps Agent installer and manager",
5
+ "bin": {
6
+ "sentinel": "./bin/sentinel.js"
7
+ },
8
+ "scripts": {
9
+ "prepublishOnly": "node scripts/bundle.js"
10
+ },
11
+ "dependencies": {
12
+ "chalk": "^4.1.2",
13
+ "fs-extra": "^11.2.0",
14
+ "prompts": "^2.4.2"
15
+ },
16
+ "engines": {
17
+ "node": ">=16"
18
+ },
19
+ "author": "misterhuydo",
20
+ "license": "MIT"
21
+ }