oh-my-claude-sisyphus 1.1.1 → 1.2.1

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,326 @@
1
+ /**
2
+ * Auto-Update System
3
+ *
4
+ * Provides version checking and auto-update functionality for Oh-My-Claude-Sisyphus.
5
+ *
6
+ * Features:
7
+ * - Check for new versions from GitHub releases
8
+ * - Download and install updates automatically
9
+ * - Store version metadata for installed components
10
+ * - Configurable update notifications
11
+ */
12
+ import { readFileSync, writeFileSync, existsSync, mkdirSync, unlinkSync } from 'fs';
13
+ import { join, dirname } from 'path';
14
+ import { homedir, tmpdir } from 'os';
15
+ import { execSync } from 'child_process';
16
+ /** GitHub repository information */
17
+ export const REPO_OWNER = 'Yeachan-Heo';
18
+ export const REPO_NAME = 'oh-my-claude-sisyphus';
19
+ export const GITHUB_API_URL = `https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}`;
20
+ export const GITHUB_RAW_URL = `https://raw.githubusercontent.com/${REPO_OWNER}/${REPO_NAME}`;
21
+ /** Installation paths */
22
+ export const CLAUDE_CONFIG_DIR = join(homedir(), '.claude');
23
+ export const VERSION_FILE = join(CLAUDE_CONFIG_DIR, '.sisyphus-version.json');
24
+ /**
25
+ * Read the current version metadata
26
+ */
27
+ export function getInstalledVersion() {
28
+ if (!existsSync(VERSION_FILE)) {
29
+ // Try to detect version from package.json if installed via npm
30
+ try {
31
+ // Check if we can find the package in node_modules
32
+ const result = execSync('npm list -g oh-my-claude-sisyphus --json 2>/dev/null', {
33
+ encoding: 'utf-8',
34
+ timeout: 5000
35
+ });
36
+ const data = JSON.parse(result);
37
+ if (data.dependencies?.['oh-my-claude-sisyphus']?.version) {
38
+ return {
39
+ version: data.dependencies['oh-my-claude-sisyphus'].version,
40
+ installedAt: new Date().toISOString(),
41
+ installMethod: 'npm'
42
+ };
43
+ }
44
+ }
45
+ catch {
46
+ // Not installed via npm or command failed
47
+ }
48
+ return null;
49
+ }
50
+ try {
51
+ const content = readFileSync(VERSION_FILE, 'utf-8');
52
+ return JSON.parse(content);
53
+ }
54
+ catch (error) {
55
+ console.error('Error reading version file:', error);
56
+ return null;
57
+ }
58
+ }
59
+ /**
60
+ * Save version metadata after installation/update
61
+ */
62
+ export function saveVersionMetadata(metadata) {
63
+ const dir = dirname(VERSION_FILE);
64
+ if (!existsSync(dir)) {
65
+ mkdirSync(dir, { recursive: true });
66
+ }
67
+ writeFileSync(VERSION_FILE, JSON.stringify(metadata, null, 2));
68
+ }
69
+ /**
70
+ * Update the last check timestamp
71
+ */
72
+ export function updateLastCheckTime() {
73
+ const current = getInstalledVersion();
74
+ if (current) {
75
+ current.lastCheckAt = new Date().toISOString();
76
+ saveVersionMetadata(current);
77
+ }
78
+ }
79
+ /**
80
+ * Fetch the latest release from GitHub
81
+ */
82
+ export async function fetchLatestRelease() {
83
+ const response = await fetch(`${GITHUB_API_URL}/releases/latest`, {
84
+ headers: {
85
+ 'Accept': 'application/vnd.github.v3+json',
86
+ 'User-Agent': 'oh-my-claude-sisyphus-updater'
87
+ }
88
+ });
89
+ if (response.status === 404) {
90
+ // No releases found - try to get version from package.json in repo
91
+ const pkgResponse = await fetch(`${GITHUB_RAW_URL}/main/package.json`, {
92
+ headers: {
93
+ 'User-Agent': 'oh-my-claude-sisyphus-updater'
94
+ }
95
+ });
96
+ if (pkgResponse.ok) {
97
+ const pkg = await pkgResponse.json();
98
+ return {
99
+ tag_name: `v${pkg.version}`,
100
+ name: `Version ${pkg.version}`,
101
+ published_at: new Date().toISOString(),
102
+ html_url: `https://github.com/${REPO_OWNER}/${REPO_NAME}`,
103
+ body: 'No release notes available (fetched from package.json)',
104
+ prerelease: false,
105
+ draft: false
106
+ };
107
+ }
108
+ throw new Error('No releases found and could not fetch package.json');
109
+ }
110
+ if (!response.ok) {
111
+ throw new Error(`Failed to fetch release info: ${response.status} ${response.statusText}`);
112
+ }
113
+ return await response.json();
114
+ }
115
+ /**
116
+ * Compare semantic versions
117
+ * Returns: -1 if a < b, 0 if a == b, 1 if a > b
118
+ */
119
+ export function compareVersions(a, b) {
120
+ // Remove 'v' prefix if present
121
+ const cleanA = a.replace(/^v/, '');
122
+ const cleanB = b.replace(/^v/, '');
123
+ const partsA = cleanA.split('.').map(n => parseInt(n, 10) || 0);
124
+ const partsB = cleanB.split('.').map(n => parseInt(n, 10) || 0);
125
+ const maxLength = Math.max(partsA.length, partsB.length);
126
+ for (let i = 0; i < maxLength; i++) {
127
+ const numA = partsA[i] || 0;
128
+ const numB = partsB[i] || 0;
129
+ if (numA < numB)
130
+ return -1;
131
+ if (numA > numB)
132
+ return 1;
133
+ }
134
+ return 0;
135
+ }
136
+ /**
137
+ * Check for available updates
138
+ */
139
+ export async function checkForUpdates() {
140
+ const installed = getInstalledVersion();
141
+ const release = await fetchLatestRelease();
142
+ const currentVersion = installed?.version ?? null;
143
+ const latestVersion = release.tag_name.replace(/^v/, '');
144
+ const updateAvailable = currentVersion === null || compareVersions(currentVersion, latestVersion) < 0;
145
+ // Update last check time
146
+ updateLastCheckTime();
147
+ return {
148
+ currentVersion,
149
+ latestVersion,
150
+ updateAvailable,
151
+ releaseInfo: release,
152
+ releaseNotes: release.body || 'No release notes available.'
153
+ };
154
+ }
155
+ /**
156
+ * Download and execute the install script to perform an update
157
+ */
158
+ export async function performUpdate(options) {
159
+ const installed = getInstalledVersion();
160
+ const previousVersion = installed?.version ?? null;
161
+ try {
162
+ // Fetch the latest release to get the version
163
+ const release = await fetchLatestRelease();
164
+ const newVersion = release.tag_name.replace(/^v/, '');
165
+ // Download the install script
166
+ const installScriptUrl = `${GITHUB_RAW_URL}/main/scripts/install.sh`;
167
+ const response = await fetch(installScriptUrl);
168
+ if (!response.ok) {
169
+ throw new Error(`Failed to download install script: ${response.status}`);
170
+ }
171
+ const scriptContent = await response.text();
172
+ // Save to a temporary file
173
+ const tempDir = tmpdir();
174
+ const tempScript = join(tempDir, `sisyphus-update-${Date.now()}.sh`);
175
+ writeFileSync(tempScript, scriptContent, { mode: 0o755 });
176
+ // Execute the install script
177
+ try {
178
+ execSync(`bash "${tempScript}"`, {
179
+ encoding: 'utf-8',
180
+ stdio: options?.verbose ? 'inherit' : 'pipe',
181
+ timeout: 60000 // 1 minute timeout
182
+ });
183
+ // Update version metadata
184
+ saveVersionMetadata({
185
+ version: newVersion,
186
+ installedAt: new Date().toISOString(),
187
+ installMethod: 'script',
188
+ lastCheckAt: new Date().toISOString()
189
+ });
190
+ // Clean up temp file
191
+ try {
192
+ unlinkSync(tempScript);
193
+ }
194
+ catch {
195
+ // Ignore cleanup errors
196
+ }
197
+ return {
198
+ success: true,
199
+ previousVersion,
200
+ newVersion,
201
+ message: `Successfully updated from ${previousVersion ?? 'unknown'} to ${newVersion}`
202
+ };
203
+ }
204
+ catch (error) {
205
+ // Clean up temp file on error too
206
+ try {
207
+ unlinkSync(tempScript);
208
+ }
209
+ catch {
210
+ // Ignore cleanup errors
211
+ }
212
+ throw error;
213
+ }
214
+ }
215
+ catch (error) {
216
+ const errorMessage = error instanceof Error ? error.message : String(error);
217
+ return {
218
+ success: false,
219
+ previousVersion,
220
+ newVersion: 'unknown',
221
+ message: `Update failed: ${errorMessage}`,
222
+ errors: [errorMessage]
223
+ };
224
+ }
225
+ }
226
+ /**
227
+ * Get a formatted update notification message
228
+ */
229
+ export function formatUpdateNotification(checkResult) {
230
+ if (!checkResult.updateAvailable) {
231
+ return `Oh-My-Claude-Sisyphus is up to date (v${checkResult.currentVersion ?? 'unknown'})`;
232
+ }
233
+ const lines = [
234
+ '╔═══════════════════════════════════════════════════════════╗',
235
+ '║ Oh-My-Claude-Sisyphus Update Available! ║',
236
+ '╚═══════════════════════════════════════════════════════════╝',
237
+ '',
238
+ ` Current version: ${checkResult.currentVersion ?? 'unknown'}`,
239
+ ` Latest version: ${checkResult.latestVersion}`,
240
+ '',
241
+ ' To update, run: /update',
242
+ ' Or run: curl -fsSL https://raw.githubusercontent.com/Yeachan-Heo/oh-my-claude-sisyphus/main/scripts/install.sh | bash',
243
+ ''
244
+ ];
245
+ // Add truncated release notes if available
246
+ if (checkResult.releaseNotes && checkResult.releaseNotes !== 'No release notes available.') {
247
+ lines.push(' Release notes:');
248
+ const notes = checkResult.releaseNotes.split('\n').slice(0, 5);
249
+ notes.forEach(line => lines.push(` ${line}`));
250
+ if (checkResult.releaseNotes.split('\n').length > 5) {
251
+ lines.push(' ...');
252
+ }
253
+ lines.push('');
254
+ }
255
+ return lines.join('\n');
256
+ }
257
+ /**
258
+ * Check if enough time has passed since the last update check
259
+ */
260
+ export function shouldCheckForUpdates(intervalHours = 24) {
261
+ const installed = getInstalledVersion();
262
+ if (!installed?.lastCheckAt) {
263
+ return true;
264
+ }
265
+ const lastCheck = new Date(installed.lastCheckAt).getTime();
266
+ const now = Date.now();
267
+ const hoursSinceLastCheck = (now - lastCheck) / (1000 * 60 * 60);
268
+ return hoursSinceLastCheck >= intervalHours;
269
+ }
270
+ /**
271
+ * Perform a background update check (non-blocking)
272
+ */
273
+ export function backgroundUpdateCheck(callback) {
274
+ if (!shouldCheckForUpdates()) {
275
+ return;
276
+ }
277
+ // Run the check asynchronously without blocking
278
+ checkForUpdates()
279
+ .then(result => {
280
+ if (callback) {
281
+ callback(result);
282
+ }
283
+ else if (result.updateAvailable) {
284
+ // Default behavior: print notification to console
285
+ console.log('\n' + formatUpdateNotification(result));
286
+ }
287
+ })
288
+ .catch(error => {
289
+ // Silently ignore errors in background checks
290
+ if (process.env.SISYPHUS_DEBUG) {
291
+ console.error('Background update check failed:', error);
292
+ }
293
+ });
294
+ }
295
+ /**
296
+ * CLI helper: perform interactive update
297
+ */
298
+ export async function interactiveUpdate() {
299
+ console.log('Checking for updates...');
300
+ try {
301
+ const checkResult = await checkForUpdates();
302
+ if (!checkResult.updateAvailable) {
303
+ console.log(`✓ You are running the latest version (${checkResult.currentVersion})`);
304
+ return;
305
+ }
306
+ console.log(formatUpdateNotification(checkResult));
307
+ console.log('Starting update...\n');
308
+ const result = await performUpdate({ verbose: true });
309
+ if (result.success) {
310
+ console.log(`\n✓ ${result.message}`);
311
+ console.log('\nPlease restart your Claude Code session to use the new version.');
312
+ }
313
+ else {
314
+ console.error(`\n✗ ${result.message}`);
315
+ if (result.errors) {
316
+ result.errors.forEach(err => console.error(` - ${err}`));
317
+ }
318
+ process.exit(1);
319
+ }
320
+ }
321
+ catch (error) {
322
+ console.error('Update check failed:', error instanceof Error ? error.message : error);
323
+ process.exit(1);
324
+ }
325
+ }
326
+ //# sourceMappingURL=auto-update.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto-update.js","sourceRoot":"","sources":["../../src/features/auto-update.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AACpF,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,oCAAoC;AACpC,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CAAC;AACxC,MAAM,CAAC,MAAM,SAAS,GAAG,uBAAuB,CAAC;AACjD,MAAM,CAAC,MAAM,cAAc,GAAG,gCAAgC,UAAU,IAAI,SAAS,EAAE,CAAC;AACxF,MAAM,CAAC,MAAM,cAAc,GAAG,qCAAqC,UAAU,IAAI,SAAS,EAAE,CAAC;AAE7F,yBAAyB;AACzB,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAC;AAC5D,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,CAAC,iBAAiB,EAAE,wBAAwB,CAAC,CAAC;AAqD9E;;GAEG;AACH,MAAM,UAAU,mBAAmB;IACjC,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC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AK,CAAC,CAAC;QACtF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Background Task Management
3
+ *
4
+ * Provides utilities for managing background task execution,
5
+ * similar to oh-my-opencode's Background Task Manager.
6
+ *
7
+ * In Claude Code, background execution is controlled via:
8
+ * - Bash tool's `run_in_background` parameter
9
+ * - Task tool's `run_in_background` parameter
10
+ * - TaskOutput tool for retrieving results
11
+ *
12
+ * This module provides:
13
+ * - Decision heuristics for when to use background execution
14
+ * - Task lifecycle management
15
+ * - Concurrency limit enforcement
16
+ * - System prompt guidance for agents
17
+ */
18
+ import type { BackgroundTask, SessionState, PluginConfig } from '../shared/types.js';
19
+ /**
20
+ * Default maximum concurrent background tasks
21
+ */
22
+ export declare const DEFAULT_MAX_BACKGROUND_TASKS = 5;
23
+ /**
24
+ * Patterns that indicate long-running operations
25
+ * These should typically run in background
26
+ */
27
+ export declare const LONG_RUNNING_PATTERNS: RegExp[];
28
+ /**
29
+ * Patterns that should always run blocking (foreground)
30
+ * These are quick operations or need immediate feedback
31
+ */
32
+ export declare const BLOCKING_PATTERNS: RegExp[];
33
+ /**
34
+ * Result of background execution decision
35
+ */
36
+ export interface TaskExecutionDecision {
37
+ /** Whether to run in background */
38
+ runInBackground: boolean;
39
+ /** Human-readable reason for the decision */
40
+ reason: string;
41
+ /** Estimated duration category */
42
+ estimatedDuration: 'quick' | 'medium' | 'long' | 'unknown';
43
+ /** Confidence level of the decision */
44
+ confidence: 'high' | 'medium' | 'low';
45
+ }
46
+ /**
47
+ * Determine if a command should run in background
48
+ *
49
+ * This is the core heuristic function that decides whether a command
50
+ * should be executed with `run_in_background: true`.
51
+ *
52
+ * @param command - The command to analyze
53
+ * @param currentBackgroundCount - Number of currently running background tasks
54
+ * @param maxBackgroundTasks - Maximum allowed concurrent background tasks
55
+ * @returns Decision object with recommendation and reasoning
56
+ */
57
+ export declare function shouldRunInBackground(command: string, currentBackgroundCount?: number, maxBackgroundTasks?: number): TaskExecutionDecision;
58
+ /**
59
+ * BackgroundTaskManager interface
60
+ *
61
+ * Manages background task lifecycle, enforces concurrency limits,
62
+ * and provides utilities for tracking task status.
63
+ */
64
+ export interface BackgroundTaskManager {
65
+ /** Register a new background task */
66
+ registerTask(agentName: string, prompt: string): BackgroundTask;
67
+ /** Get all background tasks */
68
+ getTasks(): BackgroundTask[];
69
+ /** Get tasks by status */
70
+ getTasksByStatus(status: BackgroundTask['status']): BackgroundTask[];
71
+ /** Get count of running tasks */
72
+ getRunningCount(): number;
73
+ /** Check if we can start a new background task */
74
+ canStartNewTask(): boolean;
75
+ /** Update task status */
76
+ updateTaskStatus(taskId: string, status: BackgroundTask['status'], result?: string, error?: string): void;
77
+ /** Mark task as completed */
78
+ completeTask(taskId: string, result: string): void;
79
+ /** Mark task as failed */
80
+ failTask(taskId: string, error: string): void;
81
+ /** Remove completed tasks older than specified age (ms) */
82
+ pruneCompletedTasks(maxAge?: number): number;
83
+ /** Get the maximum allowed background tasks */
84
+ getMaxTasks(): number;
85
+ /** Check if a command should run in background */
86
+ shouldRunInBackground(command: string): TaskExecutionDecision;
87
+ }
88
+ /**
89
+ * Create a BackgroundTaskManager instance
90
+ */
91
+ export declare function createBackgroundTaskManager(state: SessionState, config: PluginConfig): BackgroundTaskManager;
92
+ /**
93
+ * System prompt guidance for background task execution
94
+ *
95
+ * This text should be appended to the system prompt to guide agents
96
+ * on when and how to use background execution.
97
+ */
98
+ export declare function getBackgroundTaskGuidance(maxBackgroundTasks?: number): string;
99
+ //# sourceMappingURL=background-tasks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"background-tasks.d.ts","sourceRoot":"","sources":["../../src/features/background-tasks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAErF;;GAEG;AACH,e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