cyrus-ai 0.1.58 → 0.2.0-rc.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.
- package/dist/app.js +166 -2
- package/dist/app.js.map +1 -1
- package/dist/src/Application.d.ts +69 -0
- package/dist/src/Application.d.ts.map +1 -0
- package/dist/src/Application.js +273 -0
- package/dist/src/Application.js.map +1 -0
- package/dist/src/app.d.ts +3 -0
- package/dist/src/app.d.ts.map +1 -0
- package/dist/src/app.js +101 -0
- package/dist/src/app.js.map +1 -0
- package/dist/src/commands/AuthCommand.d.ts +8 -0
- package/dist/src/commands/AuthCommand.d.ts.map +1 -0
- package/dist/src/commands/AuthCommand.js +69 -0
- package/dist/src/commands/AuthCommand.js.map +1 -0
- package/dist/src/commands/CheckTokensCommand.d.ts +8 -0
- package/dist/src/commands/CheckTokensCommand.d.ts.map +1 -0
- package/dist/src/commands/CheckTokensCommand.js +53 -0
- package/dist/src/commands/CheckTokensCommand.js.map +1 -0
- package/dist/src/commands/ICommand.d.ts +38 -0
- package/dist/src/commands/ICommand.d.ts.map +1 -0
- package/dist/src/commands/ICommand.js +37 -0
- package/dist/src/commands/ICommand.js.map +1 -0
- package/dist/src/commands/RefreshTokenCommand.d.ts +8 -0
- package/dist/src/commands/RefreshTokenCommand.d.ts.map +1 -0
- package/dist/src/commands/RefreshTokenCommand.js +152 -0
- package/dist/src/commands/RefreshTokenCommand.js.map +1 -0
- package/dist/src/commands/StartCommand.d.ts +8 -0
- package/dist/src/commands/StartCommand.d.ts.map +1 -0
- package/dist/src/commands/StartCommand.js +70 -0
- package/dist/src/commands/StartCommand.js.map +1 -0
- package/dist/src/config/constants.d.ts +12 -0
- package/dist/src/config/constants.d.ts.map +1 -0
- package/dist/src/config/constants.js +19 -0
- package/dist/src/config/constants.js.map +1 -0
- package/dist/src/config/types.d.ts +21 -0
- package/dist/src/config/types.d.ts.map +1 -0
- package/dist/src/config/types.js +2 -0
- package/dist/src/config/types.js.map +1 -0
- package/dist/src/services/ConfigService.d.ts +32 -0
- package/dist/src/services/ConfigService.d.ts.map +1 -0
- package/dist/src/services/ConfigService.js +72 -0
- package/dist/src/services/ConfigService.js.map +1 -0
- package/dist/src/services/GitService.d.ts +28 -0
- package/dist/src/services/GitService.d.ts.map +1 -0
- package/dist/src/services/GitService.js +339 -0
- package/dist/src/services/GitService.js.map +1 -0
- package/dist/src/services/Logger.d.ts +88 -0
- package/dist/src/services/Logger.d.ts.map +1 -0
- package/dist/src/services/Logger.js +146 -0
- package/dist/src/services/Logger.js.map +1 -0
- package/dist/src/services/WorkerService.d.ts +53 -0
- package/dist/src/services/WorkerService.d.ts.map +1 -0
- package/dist/src/services/WorkerService.js +173 -0
- package/dist/src/services/WorkerService.js.map +1 -0
- package/dist/src/ui/CLIPrompts.d.ts +18 -0
- package/dist/src/ui/CLIPrompts.d.ts.map +1 -0
- package/dist/src/ui/CLIPrompts.js +53 -0
- package/dist/src/ui/CLIPrompts.js.map +1 -0
- package/package.json +10 -9
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { execSync } from "node:child_process";
|
|
2
|
+
import { existsSync, mkdirSync, statSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { basename, join } from "node:path";
|
|
5
|
+
/**
|
|
6
|
+
* Service responsible for Git worktree operations
|
|
7
|
+
*/
|
|
8
|
+
export class GitService {
|
|
9
|
+
logger;
|
|
10
|
+
constructor(logger) {
|
|
11
|
+
this.logger = logger;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Check if a branch exists locally or remotely
|
|
15
|
+
*/
|
|
16
|
+
async branchExists(branchName, repoPath) {
|
|
17
|
+
try {
|
|
18
|
+
// Check if branch exists locally
|
|
19
|
+
execSync(`git rev-parse --verify "${branchName}"`, {
|
|
20
|
+
cwd: repoPath,
|
|
21
|
+
stdio: "pipe",
|
|
22
|
+
});
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
// Branch doesn't exist locally, check remote
|
|
27
|
+
try {
|
|
28
|
+
const remoteOutput = execSync(`git ls-remote --heads origin "${branchName}"`, {
|
|
29
|
+
cwd: repoPath,
|
|
30
|
+
stdio: "pipe",
|
|
31
|
+
});
|
|
32
|
+
// Check if output is non-empty (branch actually exists on remote)
|
|
33
|
+
return remoteOutput && remoteOutput.toString().trim().length > 0;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Sanitize branch name by removing backticks to prevent command injection
|
|
42
|
+
*/
|
|
43
|
+
sanitizeBranchName(name) {
|
|
44
|
+
return name ? name.replace(/`/g, "") : name;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Run a setup script with proper error handling and logging
|
|
48
|
+
*/
|
|
49
|
+
async runSetupScript(scriptPath, scriptType, workspacePath, issue) {
|
|
50
|
+
// Expand ~ to home directory
|
|
51
|
+
const expandedPath = scriptPath.replace(/^~/, homedir());
|
|
52
|
+
// Check if script exists
|
|
53
|
+
if (!existsSync(expandedPath)) {
|
|
54
|
+
this.logger.warn(`⚠️ ${scriptType === "global" ? "Global" : "Repository"} setup script not found: ${scriptPath}`);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
// Check if script is executable (Unix only)
|
|
58
|
+
if (process.platform !== "win32") {
|
|
59
|
+
try {
|
|
60
|
+
const stats = statSync(expandedPath);
|
|
61
|
+
// Check if file has execute permission for the owner
|
|
62
|
+
if (!(stats.mode & 0o100)) {
|
|
63
|
+
this.logger.warn(`⚠️ ${scriptType === "global" ? "Global" : "Repository"} setup script is not executable: ${scriptPath}`);
|
|
64
|
+
this.logger.warn(` Run: chmod +x "${expandedPath}"`);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
this.logger.warn(`⚠️ Cannot check permissions for ${scriptType} setup script: ${error.message}`);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const scriptName = basename(expandedPath);
|
|
74
|
+
this.logger.info(`ℹ️ Running ${scriptType} setup script: ${scriptName}`);
|
|
75
|
+
try {
|
|
76
|
+
// Determine the command based on the script extension and platform
|
|
77
|
+
let command;
|
|
78
|
+
const isWindows = process.platform === "win32";
|
|
79
|
+
if (scriptPath.endsWith(".ps1")) {
|
|
80
|
+
command = `powershell -ExecutionPolicy Bypass -File "${expandedPath}"`;
|
|
81
|
+
}
|
|
82
|
+
else if (scriptPath.endsWith(".cmd") || scriptPath.endsWith(".bat")) {
|
|
83
|
+
command = `"${expandedPath}"`;
|
|
84
|
+
}
|
|
85
|
+
else if (isWindows) {
|
|
86
|
+
// On Windows, try to run with bash if available (Git Bash/WSL)
|
|
87
|
+
command = `bash "${expandedPath}"`;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
// On Unix, run directly with bash
|
|
91
|
+
command = `bash "${expandedPath}"`;
|
|
92
|
+
}
|
|
93
|
+
execSync(command, {
|
|
94
|
+
cwd: workspacePath,
|
|
95
|
+
stdio: "inherit",
|
|
96
|
+
env: {
|
|
97
|
+
...process.env,
|
|
98
|
+
LINEAR_ISSUE_ID: issue.id,
|
|
99
|
+
LINEAR_ISSUE_IDENTIFIER: issue.identifier,
|
|
100
|
+
LINEAR_ISSUE_TITLE: issue.title || "",
|
|
101
|
+
},
|
|
102
|
+
timeout: 5 * 60 * 1000, // 5 minute timeout
|
|
103
|
+
});
|
|
104
|
+
this.logger.info(`✅ ${scriptType === "global" ? "Global" : "Repository"} setup script completed successfully`);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
const errorMessage = error.signal === "SIGTERM"
|
|
108
|
+
? "Script execution timed out (exceeded 5 minutes)"
|
|
109
|
+
: error.message;
|
|
110
|
+
this.logger.error(`❌ ${scriptType === "global" ? "Global" : "Repository"} setup script failed: ${errorMessage}`);
|
|
111
|
+
// Log stderr if available
|
|
112
|
+
if (error.stderr) {
|
|
113
|
+
this.logger.error(" stderr:", error.stderr.toString());
|
|
114
|
+
}
|
|
115
|
+
// Continue execution despite setup script failure
|
|
116
|
+
this.logger.info(` Continuing with worktree creation...`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Create a git worktree for an issue
|
|
121
|
+
*/
|
|
122
|
+
async createGitWorktree(issue, repository, globalSetupScript) {
|
|
123
|
+
try {
|
|
124
|
+
// Verify this is a git repository
|
|
125
|
+
try {
|
|
126
|
+
execSync("git rev-parse --git-dir", {
|
|
127
|
+
cwd: repository.repositoryPath,
|
|
128
|
+
stdio: "pipe",
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
catch (_e) {
|
|
132
|
+
this.logger.error(`${repository.repositoryPath} is not a git repository`);
|
|
133
|
+
throw new Error("Not a git repository");
|
|
134
|
+
}
|
|
135
|
+
// Use Linear's preferred branch name, or generate one if not available
|
|
136
|
+
const rawBranchName = issue.branchName ||
|
|
137
|
+
`${issue.identifier}-${issue.title
|
|
138
|
+
?.toLowerCase()
|
|
139
|
+
.replace(/\s+/g, "-")
|
|
140
|
+
.substring(0, 30)}`;
|
|
141
|
+
const branchName = this.sanitizeBranchName(rawBranchName);
|
|
142
|
+
const workspacePath = join(repository.workspaceBaseDir, issue.identifier);
|
|
143
|
+
// Ensure workspace directory exists
|
|
144
|
+
mkdirSync(repository.workspaceBaseDir, { recursive: true });
|
|
145
|
+
// Check if worktree already exists
|
|
146
|
+
try {
|
|
147
|
+
const worktrees = execSync("git worktree list --porcelain", {
|
|
148
|
+
cwd: repository.repositoryPath,
|
|
149
|
+
encoding: "utf-8",
|
|
150
|
+
});
|
|
151
|
+
if (worktrees.includes(workspacePath)) {
|
|
152
|
+
this.logger.info(`Worktree already exists at ${workspacePath}, using existing`);
|
|
153
|
+
return {
|
|
154
|
+
path: workspacePath,
|
|
155
|
+
isGitWorktree: true,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
catch (_e) {
|
|
160
|
+
// git worktree command failed, continue with creation
|
|
161
|
+
}
|
|
162
|
+
// Check if branch already exists
|
|
163
|
+
let createBranch = true;
|
|
164
|
+
try {
|
|
165
|
+
execSync(`git rev-parse --verify "${branchName}"`, {
|
|
166
|
+
cwd: repository.repositoryPath,
|
|
167
|
+
stdio: "pipe",
|
|
168
|
+
});
|
|
169
|
+
createBranch = false;
|
|
170
|
+
}
|
|
171
|
+
catch (_e) {
|
|
172
|
+
// Branch doesn't exist, we'll create it
|
|
173
|
+
}
|
|
174
|
+
// Determine base branch for this issue
|
|
175
|
+
let baseBranch = repository.baseBranch;
|
|
176
|
+
// Check if issue has a parent
|
|
177
|
+
try {
|
|
178
|
+
const parent = await issue.parent;
|
|
179
|
+
if (parent) {
|
|
180
|
+
this.logger.info(`Issue ${issue.identifier} has parent: ${parent.identifier}`);
|
|
181
|
+
// Get parent's branch name
|
|
182
|
+
const parentRawBranchName = parent.branchName ||
|
|
183
|
+
`${parent.identifier}-${parent.title
|
|
184
|
+
?.toLowerCase()
|
|
185
|
+
.replace(/\s+/g, "-")
|
|
186
|
+
.substring(0, 30)}`;
|
|
187
|
+
const parentBranchName = this.sanitizeBranchName(parentRawBranchName);
|
|
188
|
+
// Check if parent branch exists
|
|
189
|
+
const parentBranchExists = await this.branchExists(parentBranchName, repository.repositoryPath);
|
|
190
|
+
if (parentBranchExists) {
|
|
191
|
+
baseBranch = parentBranchName;
|
|
192
|
+
this.logger.info(`Using parent issue branch '${parentBranchName}' as base for sub-issue ${issue.identifier}`);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
this.logger.info(`Parent branch '${parentBranchName}' not found, using default base branch '${repository.baseBranch}'`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
catch (_error) {
|
|
200
|
+
// Parent field might not exist or couldn't be fetched, use default base branch
|
|
201
|
+
this.logger.info(`No parent issue found for ${issue.identifier}, using default base branch '${repository.baseBranch}'`);
|
|
202
|
+
}
|
|
203
|
+
// Fetch latest changes from remote
|
|
204
|
+
this.logger.info("Fetching latest changes from remote...");
|
|
205
|
+
let hasRemote = true;
|
|
206
|
+
try {
|
|
207
|
+
execSync("git fetch origin", {
|
|
208
|
+
cwd: repository.repositoryPath,
|
|
209
|
+
stdio: "pipe",
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
catch (e) {
|
|
213
|
+
this.logger.warn("Warning: git fetch failed, proceeding with local branch:", e.message);
|
|
214
|
+
hasRemote = false;
|
|
215
|
+
}
|
|
216
|
+
// Create the worktree - use determined base branch
|
|
217
|
+
let worktreeCmd;
|
|
218
|
+
if (createBranch) {
|
|
219
|
+
if (hasRemote) {
|
|
220
|
+
// Check if the base branch exists remotely
|
|
221
|
+
let useRemoteBranch = false;
|
|
222
|
+
try {
|
|
223
|
+
const remoteOutput = execSync(`git ls-remote --heads origin "${baseBranch}"`, {
|
|
224
|
+
cwd: repository.repositoryPath,
|
|
225
|
+
stdio: "pipe",
|
|
226
|
+
});
|
|
227
|
+
// Check if output is non-empty (branch actually exists on remote)
|
|
228
|
+
useRemoteBranch =
|
|
229
|
+
remoteOutput && remoteOutput.toString().trim().length > 0;
|
|
230
|
+
if (!useRemoteBranch) {
|
|
231
|
+
this.logger.info(`Base branch '${baseBranch}' not found on remote, checking locally...`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
// Base branch doesn't exist remotely, use local or fall back to default
|
|
236
|
+
this.logger.info(`Base branch '${baseBranch}' not found on remote, checking locally...`);
|
|
237
|
+
}
|
|
238
|
+
if (useRemoteBranch) {
|
|
239
|
+
// Use remote version of base branch
|
|
240
|
+
const remoteBranch = `origin/${baseBranch}`;
|
|
241
|
+
this.logger.info(`Creating git worktree at ${workspacePath} from ${remoteBranch}`);
|
|
242
|
+
worktreeCmd = `git worktree add "${workspacePath}" -b "${branchName}" "${remoteBranch}"`;
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
// Check if base branch exists locally
|
|
246
|
+
try {
|
|
247
|
+
execSync(`git rev-parse --verify "${baseBranch}"`, {
|
|
248
|
+
cwd: repository.repositoryPath,
|
|
249
|
+
stdio: "pipe",
|
|
250
|
+
});
|
|
251
|
+
// Use local base branch
|
|
252
|
+
this.logger.info(`Creating git worktree at ${workspacePath} from local ${baseBranch}`);
|
|
253
|
+
worktreeCmd = `git worktree add "${workspacePath}" -b "${branchName}" "${baseBranch}"`;
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
// Base branch doesn't exist locally either, fall back to remote default
|
|
257
|
+
this.logger.info(`Base branch '${baseBranch}' not found locally, falling back to remote ${repository.baseBranch}`);
|
|
258
|
+
const defaultRemoteBranch = `origin/${repository.baseBranch}`;
|
|
259
|
+
worktreeCmd = `git worktree add "${workspacePath}" -b "${branchName}" "${defaultRemoteBranch}"`;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
// No remote, use local branch
|
|
265
|
+
this.logger.info(`Creating git worktree at ${workspacePath} from local ${baseBranch}`);
|
|
266
|
+
worktreeCmd = `git worktree add "${workspacePath}" -b "${branchName}" "${baseBranch}"`;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
// Branch already exists, just check it out
|
|
271
|
+
this.logger.info(`Creating git worktree at ${workspacePath} with existing branch ${branchName}`);
|
|
272
|
+
worktreeCmd = `git worktree add "${workspacePath}" "${branchName}"`;
|
|
273
|
+
}
|
|
274
|
+
execSync(worktreeCmd, {
|
|
275
|
+
cwd: repository.repositoryPath,
|
|
276
|
+
stdio: "pipe",
|
|
277
|
+
});
|
|
278
|
+
// First, run the global setup script if configured
|
|
279
|
+
if (globalSetupScript) {
|
|
280
|
+
await this.runSetupScript(globalSetupScript, "global", workspacePath, issue);
|
|
281
|
+
}
|
|
282
|
+
// Then, check for repository setup scripts (cross-platform)
|
|
283
|
+
const isWindows = process.platform === "win32";
|
|
284
|
+
const setupScripts = [
|
|
285
|
+
{
|
|
286
|
+
file: "cyrus-setup.sh",
|
|
287
|
+
platform: "unix",
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
file: "cyrus-setup.ps1",
|
|
291
|
+
platform: "windows",
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
file: "cyrus-setup.cmd",
|
|
295
|
+
platform: "windows",
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
file: "cyrus-setup.bat",
|
|
299
|
+
platform: "windows",
|
|
300
|
+
},
|
|
301
|
+
];
|
|
302
|
+
// Find the first available setup script for the current platform
|
|
303
|
+
const availableScript = setupScripts.find((script) => {
|
|
304
|
+
const scriptPath = join(repository.repositoryPath, script.file);
|
|
305
|
+
const isCompatible = isWindows
|
|
306
|
+
? script.platform === "windows"
|
|
307
|
+
: script.platform === "unix";
|
|
308
|
+
return existsSync(scriptPath) && isCompatible;
|
|
309
|
+
});
|
|
310
|
+
// Fallback: on Windows, try bash if no Windows scripts found (for Git Bash/WSL users)
|
|
311
|
+
const fallbackScript = !availableScript && isWindows
|
|
312
|
+
? setupScripts.find((script) => {
|
|
313
|
+
const scriptPath = join(repository.repositoryPath, script.file);
|
|
314
|
+
return script.platform === "unix" && existsSync(scriptPath);
|
|
315
|
+
})
|
|
316
|
+
: null;
|
|
317
|
+
const scriptToRun = availableScript || fallbackScript;
|
|
318
|
+
if (scriptToRun) {
|
|
319
|
+
const scriptPath = join(repository.repositoryPath, scriptToRun.file);
|
|
320
|
+
await this.runSetupScript(scriptPath, "repository", workspacePath, issue);
|
|
321
|
+
}
|
|
322
|
+
return {
|
|
323
|
+
path: workspacePath,
|
|
324
|
+
isGitWorktree: true,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
catch (error) {
|
|
328
|
+
this.logger.error("Failed to create git worktree:", error.message);
|
|
329
|
+
// Fall back to regular directory if git worktree fails
|
|
330
|
+
const fallbackPath = join(repository.workspaceBaseDir, issue.identifier);
|
|
331
|
+
mkdirSync(fallbackPath, { recursive: true });
|
|
332
|
+
return {
|
|
333
|
+
path: fallbackPath,
|
|
334
|
+
isGitWorktree: false,
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
//# sourceMappingURL=GitService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GitService.js","sourceRoot":"","sources":["../../../src/services/GitService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAM3C;;GAEG;AACH,MAAM,OAAO,UAAU;IACF;IAApB,YAAoB,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IACtC;;OAEG;IACH,KAAK,CAAC,YAAY,CAAC,UAAkB,EAAE,QAAgB;QACtD,IAAI,CAAC;YACJ,iCAAiC;YACjC,QAAQ,CAAC,2BAA2B,UAAU,GAAG,EAAE;gBAClD,GAAG,EAAE,QAAQ;gBACb,KAAK,EAAE,MAAM;aACb,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;QACb,CAAC;QAAC,MAAM,CAAC;YACR,6CAA6C;YAC7C,IAAI,CAAC;gBACJ,MAAM,YAAY,GAAG,QAAQ,CAC5B,iCAAiC,UAAU,GAAG,EAC9C;oBACC,GAAG,EAAE,QAAQ;oBACb,KAAK,EAAE,MAAM;iBACb,CACD,CAAC;gBACF,kEAAkE;gBAClE,OAAO,YAAY,IAAI,YAAY,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC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AU,CAAC,UAAU,CAAC,CAAC;gBAC7D,CAAC,CAAC;gBACH,CAAC,CAAC,IAAI,CAAC;YAET,MAAM,WAAW,GAAG,eAAe,IAAI,cAAc,CAAC;YAEtD,IAAI,WAAW,EAAE,CAAC;gBACjB,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,cAAc,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;gBACrE,MAAM,IAAI,CAAC,cAAc,CACxB,UAAU,EACV,YAAY,EACZ,aAAa,EACb,KAAK,CACL,CAAC;YACH,CAAC;YAED,OAAO;gBACN,IAAI,EAAE,aAAa;gBACnB,aAAa,EAAE,IAAI;aACnB,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,IAAI,CAAC,MAAM,CAAC,KAAK,CAChB,gCAAgC,EAC/B,KAAe,CAAC,OAAO,CACxB,CAAC;YACF,uDAAuD;YACvD,MAAM,YAAY,GAAG,IAAI,CAAC,UAAU,CAAC,gBAAgB,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;YACzE,SAAS,CAAC,YAAY,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAC7C,OAAO;gBACN,IAAI,EAAE,YAAY;gBAClB,aAAa,EAAE,KAAK;aACpB,CAAC;QACH,CAAC;IACF,CAAC;CACD"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Log levels in order of severity
|
|
3
|
+
*/
|
|
4
|
+
export declare enum LogLevel {
|
|
5
|
+
DEBUG = 0,
|
|
6
|
+
INFO = 1,
|
|
7
|
+
SUCCESS = 2,
|
|
8
|
+
WARN = 3,
|
|
9
|
+
ERROR = 4,
|
|
10
|
+
SILENT = 5
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Logger configuration options
|
|
14
|
+
*/
|
|
15
|
+
export interface LoggerOptions {
|
|
16
|
+
/** Minimum log level to output */
|
|
17
|
+
level?: LogLevel;
|
|
18
|
+
/** Prefix to add to all log messages */
|
|
19
|
+
prefix?: string;
|
|
20
|
+
/** Whether to include timestamps */
|
|
21
|
+
timestamps?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Simple, zero-dependency logger service with structured logging
|
|
25
|
+
*/
|
|
26
|
+
export declare class Logger {
|
|
27
|
+
private level;
|
|
28
|
+
private prefix;
|
|
29
|
+
private timestamps;
|
|
30
|
+
constructor(options?: LoggerOptions);
|
|
31
|
+
/**
|
|
32
|
+
* Get log level from environment variable
|
|
33
|
+
*/
|
|
34
|
+
private getLogLevelFromEnv;
|
|
35
|
+
/**
|
|
36
|
+
* Format a log message with optional prefix and timestamp
|
|
37
|
+
*/
|
|
38
|
+
private format;
|
|
39
|
+
/**
|
|
40
|
+
* Check if a log level should be output
|
|
41
|
+
*/
|
|
42
|
+
private shouldLog;
|
|
43
|
+
/**
|
|
44
|
+
* Debug log (lowest priority)
|
|
45
|
+
*/
|
|
46
|
+
debug(message: string, ...args: any[]): void;
|
|
47
|
+
/**
|
|
48
|
+
* Info log (normal priority)
|
|
49
|
+
*/
|
|
50
|
+
info(message: string, ...args: any[]): void;
|
|
51
|
+
/**
|
|
52
|
+
* Success log (positive outcome)
|
|
53
|
+
*/
|
|
54
|
+
success(message: string, ...args: any[]): void;
|
|
55
|
+
/**
|
|
56
|
+
* Warning log
|
|
57
|
+
*/
|
|
58
|
+
warn(message: string, ...args: any[]): void;
|
|
59
|
+
/**
|
|
60
|
+
* Error log (highest priority)
|
|
61
|
+
*/
|
|
62
|
+
error(message: string, ...args: any[]): void;
|
|
63
|
+
/**
|
|
64
|
+
* Raw output without formatting (always outputs regardless of level)
|
|
65
|
+
*/
|
|
66
|
+
raw(message: string, ...args: any[]): void;
|
|
67
|
+
/**
|
|
68
|
+
* Create a child logger with a prefix
|
|
69
|
+
*/
|
|
70
|
+
child(prefix: string): Logger;
|
|
71
|
+
/**
|
|
72
|
+
* Print a divider line
|
|
73
|
+
*/
|
|
74
|
+
divider(length?: number): void;
|
|
75
|
+
/**
|
|
76
|
+
* Set log level dynamically
|
|
77
|
+
*/
|
|
78
|
+
setLevel(level: LogLevel): void;
|
|
79
|
+
/**
|
|
80
|
+
* Get current log level
|
|
81
|
+
*/
|
|
82
|
+
getLevel(): LogLevel;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Default logger instance
|
|
86
|
+
*/
|
|
87
|
+
export declare const logger: Logger;
|
|
88
|
+
//# sourceMappingURL=Logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../../src/services/Logger.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,QAAQ;IACnB,KAAK,IAAI;IACT,IAAI,IAAI;IACR,OAAO,IAAI;IACX,IAAI,IAAI;IACR,KAAK,IAAI;IACT,MAAM,IAAI;CACV;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B,kCAAkC;IAClC,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,wCAAwC;IACxC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oCAAoC;IACpC,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;GAEG;AACH,qBAAa,MAAM;IAClB,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAU;gBAEhB,OAAO,GAAE,aAAkB;IAMvC;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAoB1B;;OAEG;IACH,OAAO,CAAC,MAAM;IAed;;OAEG;IACH,OAAO,CAAC,SAAS;IAIjB;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAM5C;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAM3C;;OAEG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAM9C;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAM3C;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAM5C;;OAEG;IACH,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAI1C;;OAEG;IACH,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAQ7B;;OAEG;IACH,OAAO,CAAC,MAAM,SAAK,GAAG,IAAI;IAI1B;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAI/B;;OAEG;IACH,QAAQ,IAAI,QAAQ;CAGpB;AAED;;GAEG;AACH,eAAO,MAAM,MAAM,QAAe,CAAC"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Log levels in order of severity
|
|
3
|
+
*/
|
|
4
|
+
export var LogLevel;
|
|
5
|
+
(function (LogLevel) {
|
|
6
|
+
LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
|
|
7
|
+
LogLevel[LogLevel["INFO"] = 1] = "INFO";
|
|
8
|
+
LogLevel[LogLevel["SUCCESS"] = 2] = "SUCCESS";
|
|
9
|
+
LogLevel[LogLevel["WARN"] = 3] = "WARN";
|
|
10
|
+
LogLevel[LogLevel["ERROR"] = 4] = "ERROR";
|
|
11
|
+
LogLevel[LogLevel["SILENT"] = 5] = "SILENT";
|
|
12
|
+
})(LogLevel || (LogLevel = {}));
|
|
13
|
+
/**
|
|
14
|
+
* Simple, zero-dependency logger service with structured logging
|
|
15
|
+
*/
|
|
16
|
+
export class Logger {
|
|
17
|
+
level;
|
|
18
|
+
prefix;
|
|
19
|
+
timestamps;
|
|
20
|
+
constructor(options = {}) {
|
|
21
|
+
this.level = options.level ?? this.getLogLevelFromEnv();
|
|
22
|
+
this.prefix = options.prefix ?? "";
|
|
23
|
+
this.timestamps = options.timestamps ?? false;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get log level from environment variable
|
|
27
|
+
*/
|
|
28
|
+
getLogLevelFromEnv() {
|
|
29
|
+
const envLevel = process.env.CYRUS_LOG_LEVEL?.toUpperCase();
|
|
30
|
+
switch (envLevel) {
|
|
31
|
+
case "DEBUG":
|
|
32
|
+
return LogLevel.DEBUG;
|
|
33
|
+
case "INFO":
|
|
34
|
+
return LogLevel.INFO;
|
|
35
|
+
case "SUCCESS":
|
|
36
|
+
return LogLevel.SUCCESS;
|
|
37
|
+
case "WARN":
|
|
38
|
+
return LogLevel.WARN;
|
|
39
|
+
case "ERROR":
|
|
40
|
+
return LogLevel.ERROR;
|
|
41
|
+
case "SILENT":
|
|
42
|
+
return LogLevel.SILENT;
|
|
43
|
+
default:
|
|
44
|
+
return LogLevel.INFO;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Format a log message with optional prefix and timestamp
|
|
49
|
+
*/
|
|
50
|
+
format(message) {
|
|
51
|
+
let formatted = message;
|
|
52
|
+
if (this.prefix) {
|
|
53
|
+
formatted = `[${this.prefix}] ${formatted}`;
|
|
54
|
+
}
|
|
55
|
+
if (this.timestamps) {
|
|
56
|
+
const timestamp = new Date().toISOString();
|
|
57
|
+
formatted = `${timestamp} ${formatted}`;
|
|
58
|
+
}
|
|
59
|
+
return formatted;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Check if a log level should be output
|
|
63
|
+
*/
|
|
64
|
+
shouldLog(level) {
|
|
65
|
+
return level >= this.level;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Debug log (lowest priority)
|
|
69
|
+
*/
|
|
70
|
+
debug(message, ...args) {
|
|
71
|
+
if (this.shouldLog(LogLevel.DEBUG)) {
|
|
72
|
+
console.log(this.format(`🔍 ${message}`), ...args);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Info log (normal priority)
|
|
77
|
+
*/
|
|
78
|
+
info(message, ...args) {
|
|
79
|
+
if (this.shouldLog(LogLevel.INFO)) {
|
|
80
|
+
console.log(this.format(message), ...args);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Success log (positive outcome)
|
|
85
|
+
*/
|
|
86
|
+
success(message, ...args) {
|
|
87
|
+
if (this.shouldLog(LogLevel.SUCCESS)) {
|
|
88
|
+
console.log(this.format(`✅ ${message}`), ...args);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Warning log
|
|
93
|
+
*/
|
|
94
|
+
warn(message, ...args) {
|
|
95
|
+
if (this.shouldLog(LogLevel.WARN)) {
|
|
96
|
+
console.warn(this.format(`⚠️ ${message}`), ...args);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Error log (highest priority)
|
|
101
|
+
*/
|
|
102
|
+
error(message, ...args) {
|
|
103
|
+
if (this.shouldLog(LogLevel.ERROR)) {
|
|
104
|
+
console.error(this.format(`❌ ${message}`), ...args);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Raw output without formatting (always outputs regardless of level)
|
|
109
|
+
*/
|
|
110
|
+
raw(message, ...args) {
|
|
111
|
+
console.log(message, ...args);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Create a child logger with a prefix
|
|
115
|
+
*/
|
|
116
|
+
child(prefix) {
|
|
117
|
+
return new Logger({
|
|
118
|
+
level: this.level,
|
|
119
|
+
prefix: this.prefix ? `${this.prefix}:${prefix}` : prefix,
|
|
120
|
+
timestamps: this.timestamps,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Print a divider line
|
|
125
|
+
*/
|
|
126
|
+
divider(length = 70) {
|
|
127
|
+
this.raw("─".repeat(length));
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Set log level dynamically
|
|
131
|
+
*/
|
|
132
|
+
setLevel(level) {
|
|
133
|
+
this.level = level;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Get current log level
|
|
137
|
+
*/
|
|
138
|
+
getLevel() {
|
|
139
|
+
return this.level;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Default logger instance
|
|
144
|
+
*/
|
|
145
|
+
export const logger = new Logger();
|
|
146
|
+
//# sourceMappingURL=Logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../../src/services/Logger.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,QAOX;AAPD,WAAY,QAAQ;IACnB,yCAAS,CAAA;IACT,uCAAQ,CAAA;IACR,6CAAW,CAAA;IACX,uCAAQ,CAAA;IACR,yCAAS,CAAA;IACT,2CAAU,CAAA;AACX,CAAC,EAPW,QAAQ,KAAR,QAAQ,QAOnB;AAcD;;GAEG;AACH,MAAM,OAAO,MAAM;IACV,KAAK,CAAW;IAChB,MAAM,CAAS;IACf,UAAU,CAAU;IAE5B,YAAY,UAAyB,EAAE;QACtC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACxD,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC;QACnC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,KAAK,CAAC;IAC/C,CAAC;IAED;;OAEG;IACK,kBAAkB;QACzB,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,WAAW,EAAE,CAAC;QAC5D,QAAQ,Q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CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM;YACzD,UAAU,EAAE,IAAI,CAAC,UAAU;SAC3B,CAAC,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,MAAM,GAAG,EAAE;QAClB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,KAAe;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACpB,CAAC;IAED;;OAEG;IACH,QAAQ;QACP,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;CACD;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { RepositoryConfig } from "cyrus-core";
|
|
2
|
+
import { EdgeWorker } from "cyrus-edge-worker";
|
|
3
|
+
import type { ConfigService } from "./ConfigService.js";
|
|
4
|
+
import type { GitService } from "./GitService.js";
|
|
5
|
+
import type { Logger } from "./Logger.js";
|
|
6
|
+
/**
|
|
7
|
+
* Service responsible for EdgeWorker and Cloudflare tunnel management
|
|
8
|
+
*/
|
|
9
|
+
export declare class WorkerService {
|
|
10
|
+
private configService;
|
|
11
|
+
private gitService;
|
|
12
|
+
private cyrusHome;
|
|
13
|
+
private logger;
|
|
14
|
+
private edgeWorker;
|
|
15
|
+
private setupWaitingServer;
|
|
16
|
+
private isShuttingDown;
|
|
17
|
+
constructor(configService: ConfigService, gitService: GitService, cyrusHome: string, logger: Logger);
|
|
18
|
+
/**
|
|
19
|
+
* Get the EdgeWorker instance
|
|
20
|
+
*/
|
|
21
|
+
getEdgeWorker(): EdgeWorker | null;
|
|
22
|
+
/**
|
|
23
|
+
* Get the server port from EdgeWorker
|
|
24
|
+
*/
|
|
25
|
+
getServerPort(): number;
|
|
26
|
+
/**
|
|
27
|
+
* Start setup waiting mode - server infrastructure only, no EdgeWorker
|
|
28
|
+
* Used after initial authentication while waiting for server configuration
|
|
29
|
+
*/
|
|
30
|
+
startSetupWaitingMode(): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Stop the setup waiting mode server
|
|
33
|
+
* Must be called before starting EdgeWorker to avoid port conflicts
|
|
34
|
+
*/
|
|
35
|
+
stopSetupWaitingMode(): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Start the EdgeWorker with given configuration
|
|
38
|
+
*/
|
|
39
|
+
startEdgeWorker(params: {
|
|
40
|
+
repositories: RepositoryConfig[];
|
|
41
|
+
ngrokAuthToken?: string;
|
|
42
|
+
onOAuthCallback?: (token: string, workspaceId: string, workspaceName: string) => Promise<void>;
|
|
43
|
+
}): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Set up event handlers for EdgeWorker
|
|
46
|
+
*/
|
|
47
|
+
private setupEventHandlers;
|
|
48
|
+
/**
|
|
49
|
+
* Stop the EdgeWorker
|
|
50
|
+
*/
|
|
51
|
+
stop(): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=WorkerService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WorkerService.d.ts","sourceRoot":"","sources":["../../../src/services/WorkerService.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAoB,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C;;GAEG;AACH,qBAAa,aAAa;IAMxB,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,UAAU;IAClB,OAAO,CA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