-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·211 lines (186 loc) · 7.62 KB
/
index.js
File metadata and controls
executable file
·211 lines (186 loc) · 7.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/env node
import { Command } from 'commander';
import chalk from 'chalk';
import ora from 'ora';
import prompts from 'prompts';
import fs from 'fs/promises';
import path from 'path';
import { fileURLToPath } from 'url';
import https from 'https';
import { createWriteStream } from 'fs';
import { pipeline } from 'stream/promises';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const program = new Command();
async function fetchGitHubContent(url) {
return new Promise((resolve, reject) => {
https.get(url, { headers: { 'User-Agent': 'hello-simone' } }, (res) => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => {
if (res.statusCode === 200) {
try {
resolve(JSON.parse(data));
} catch (e) {
reject(new Error('Failed to parse JSON response from GitHub.'));
}
} else {
reject(new Error(`Failed to fetch ${url}: ${res.statusCode}`));
}
});
}).on('error', reject);
});
}
async function fetchLatestVersion() {
try {
const tags = await fetchGitHubContent('https://api.github.com/repos/helmi/claude-simone/tags');
// Filter for version tags and sort
const versionTags = tags
.map(tag => tag.name)
.filter(name => name.match(/^v\d+\.\d+(\.\d+)?$/))
.sort((a, b) => {
const parseVersion = (v) => v.slice(1).split('.').map(n => parseInt(n, 10));
const va = parseVersion(a);
const vb = parseVersion(b);
for (let i = 0; i < Math.max(va.length, vb.length); i++) {
const diff = (vb[i] || 0) - (va[i] || 0);
if (diff !== 0) return diff;
}
return 0;
});
return versionTags[0] || 'v0.3.5'; // fallback to known version
} catch (error) {
console.warn(chalk.yellow('Unable to fetch latest version, using default.'));
return 'v0.3.5'; // fallback version
}
}
async function downloadFile(url, destPath) {
await fs.mkdir(path.dirname(destPath), { recursive: true });
return new Promise((resolve, reject) => {
const file = createWriteStream(destPath);
https.get(url, { headers: { 'User-Agent': 'hello-simone' } }, (response) => {
if (response.statusCode !== 200) {
reject(new Error(`Failed to download ${url}: ${response.statusCode}`));
return;
}
pipeline(response, file)
.then(() => resolve())
.catch(reject);
}).on('error', reject);
});
}
async function downloadDirectory(githubPath, localPath, spinner, branch) {
try {
await fs.mkdir(localPath, { recursive: true });
const apiUrl = `https://api.github.com/repos/helmi/claude-simone/contents/${githubPath}?ref=${branch}`;
const items = await fetchGitHubContent(apiUrl);
for (const item of items) {
const itemLocalPath = path.join(localPath, item.name);
if (item.type === 'dir') {
await downloadDirectory(item.path, itemLocalPath, spinner, branch);
} else if (item.type === 'file') {
spinner.text = `Downloading ${item.path}...`;
await downloadFile(item.download_url, itemLocalPath);
}
}
} catch (error) {
throw new Error(`Failed to download ${githubPath}: ${error.message}`);
}
}
async function checkExistingInstallation() {
// Check if Simone is already installed by looking for key directories
const simoneDirs = ['.simone/03_SPRINTS', '.simone/02_REQUIREMENTS'];
for (const dir of simoneDirs) {
try {
await fs.access(dir);
return true; // Found a Simone directory, so it's already installed
} catch {
// Directory not found, continue checking
}
}
return false;
}
async function backupCommands() {
const commandsDir = '.claude/commands/simone';
const backupDir = '.claude/simone-commands-backup';
try {
await fs.access(commandsDir);
// Commands exist, create backup
await fs.rm(backupDir, { recursive: true, force: true }); // Remove old backup if exists
await fs.mkdir(path.dirname(backupDir), { recursive: true });
await fs.rename(commandsDir, backupDir);
return true;
} catch {
// No commands to backup
return false;
}
}
async function installSimone(options = {}) {
const branch = 'master';
const latestVersion = await fetchLatestVersion();
const versionDisplay = latestVersion.replace('v', '');
console.log(chalk.blue.bold('\n🎉 Welcome to HelloSimone!\n'));
console.log(chalk.gray(`This installer will set up the Simone ${latestVersion} project management framework`));
console.log(chalk.gray('for your Claude Code project.\n'));
const spinner = ora('Initializing...').start();
try {
spinner.text = 'Checking for existing installation...';
const hasExisting = await checkExistingInstallation();
if (hasExisting) {
// SCENARIO: Update existing installation
spinner.text = 'Updating existing Simone installation...';
// Backup commands
const backedUp = await backupCommands();
if (backedUp) {
spinner.info(chalk.yellow('Existing commands moved to .claude/simone-commands-backup/'));
}
// Only update CLAUDE.md files and commands, NOT the .simone directory structure
const GITHUB_RAW_URL = `https://raw.githubusercontent.com/helmi/claude-simone/${branch}`;
const claudeFiles = [
'.simone/CLAUDE.md', '.simone/02_REQUIREMENTS/CLAUDE.md',
'.simone/03_SPRINTS/CLAUDE.md', '.simone/04_GENERAL_TASKS/CLAUDE.md'
];
spinner.text = 'Updating CLAUDE.md files...';
for (const claudeFile of claudeFiles) {
await downloadFile(`${GITHUB_RAW_URL}/${claudeFile}`, claudeFile).catch(()=>{});
}
} else {
// SCENARIO: Fresh install
spinner.text = 'Installing Simone framework...';
const simoneDirs = [
'.simone', '.simone/01_PROJECT_DOCS', '.simone/02_REQUIREMENTS',
'.simone/03_SPRINTS', '.simone/04_GENERAL_TASKS', '.simone/05_ARCHITECTURE_DECISIONS',
'.simone/10_STATE_OF_PROJECT', '.simone/99_TEMPLATES'
];
for (const dir of simoneDirs) {
await fs.mkdir(dir, { recursive: true });
}
const GITHUB_RAW_URL = `https://raw.githubusercontent.com/helmi/claude-simone/${branch}`;
await downloadFile(`${GITHUB_RAW_URL}/.simone/00_PROJECT_MANIFEST.md`, '.simone/00_PROJECT_MANIFEST.md').catch(()=>{});
await downloadDirectory('.simone/99_TEMPLATES', '.simone/99_TEMPLATES', spinner, branch).catch(()=>{});
const claudeFiles = [
'.simone/CLAUDE.md', '.simone/02_REQUIREMENTS/CLAUDE.md',
'.simone/03_SPRINTS/CLAUDE.md', '.simone/04_GENERAL_TASKS/CLAUDE.md'
];
for (const claudeFile of claudeFiles) {
await downloadFile(`${GITHUB_RAW_URL}/${claudeFile}`, claudeFile).catch(()=>{});
}
}
// Always download/update commands
spinner.text = 'Downloading latest commands...';
await downloadDirectory('.claude/commands/simone', '.claude/commands/simone', spinner, branch).catch(()=>{});
spinner.succeed(chalk.green(`✅ Simone ${latestVersion} framework ${hasExisting ? 'updated' : 'installed'} successfully!`));
console.log(chalk.green('\n🚀 Next steps:'));
console.log(chalk.white(' 1. Open this project in Claude Code'));
console.log(chalk.white(' 2. Use /simone:initialize to set up your project\n'));
} catch (error) {
spinner.fail(chalk.red('Installation failed'));
console.error(chalk.red('\nError details:'), error.message);
process.exit(1);
}
}
program
.name('hello-simone')
.description('Installer for the Simone project management framework')
.version('0.5.4')
.action(installSimone);
program.parse();