autopilot-code 0.0.7 → 0.0.8
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/cli.js +113 -37
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -16,6 +16,26 @@ const GLOBAL_CONFIG_DIR = node_path_1.default.join(process.env.HOME || "", ".con
|
|
|
16
16
|
const GLOBAL_CONFIG_FILE = node_path_1.default.join(GLOBAL_CONFIG_DIR, "config.json");
|
|
17
17
|
const SYSTEM_DIR = "/etc/systemd/system";
|
|
18
18
|
const USER_DIR = node_path_1.default.join(process.env.HOME || "", ".config", "systemd", "user");
|
|
19
|
+
function getRepoName(dir) {
|
|
20
|
+
try {
|
|
21
|
+
const res = (0, node_child_process_1.spawnSync)("git", ["remote", "get-url", "origin"], { cwd: dir, encoding: "utf8" });
|
|
22
|
+
if (res.status !== 0)
|
|
23
|
+
return null;
|
|
24
|
+
const url = res.stdout.trim();
|
|
25
|
+
// Handle SSH: git@github.com:owner/repo.git
|
|
26
|
+
if (url.includes("@github.com:")) {
|
|
27
|
+
return url.split("@github.com:")[1].replace(".git", "");
|
|
28
|
+
}
|
|
29
|
+
// Handle HTTPS: https://github.com/owner/repo.git
|
|
30
|
+
if (url.includes("github.com/")) {
|
|
31
|
+
return url.split("github.com/")[1].replace(".git", "");
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
19
39
|
function run(cmd, args) {
|
|
20
40
|
const res = (0, node_child_process_1.spawnSync)(cmd, args, { stdio: "inherit" });
|
|
21
41
|
if (res.error)
|
|
@@ -164,8 +184,8 @@ function installSystemdService() {
|
|
|
164
184
|
const { unitPath, logPath, useSystem } = getSystemdPaths();
|
|
165
185
|
const intervalSeconds = "60";
|
|
166
186
|
if (!(0, node_fs_1.existsSync)(GLOBAL_CONFIG_FILE)) {
|
|
167
|
-
console.
|
|
168
|
-
|
|
187
|
+
console.log("Global configuration not found. Creating a basic one...");
|
|
188
|
+
saveGlobalConfig({ sourceFolders: [] });
|
|
169
189
|
}
|
|
170
190
|
if (!systemctl("--version", [], true)) {
|
|
171
191
|
console.error("systemd is not available on this system.");
|
|
@@ -254,31 +274,75 @@ function statusSystemdService() {
|
|
|
254
274
|
spawnSync("systemctl", ["status", "autopilot.service", ...daemonReloadArgs], { stdio: "inherit" });
|
|
255
275
|
}
|
|
256
276
|
async function initCommand() {
|
|
257
|
-
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
277
|
+
const cwd = process.cwd();
|
|
278
|
+
const validation = validatePath(cwd);
|
|
279
|
+
// 1. Ensure global config exists
|
|
280
|
+
let globalConfig = loadGlobalConfig();
|
|
281
|
+
if (!globalConfig) {
|
|
282
|
+
console.log("Creating new global configuration...");
|
|
283
|
+
globalConfig = { sourceFolders: [] };
|
|
284
|
+
saveGlobalConfig(globalConfig);
|
|
285
|
+
}
|
|
286
|
+
if (validation.isGit) {
|
|
287
|
+
// REPO MODE
|
|
288
|
+
console.log("🚀 Initializing Autopilot in this repository...");
|
|
289
|
+
// a) Add to global scan list if not already there
|
|
290
|
+
if (!globalConfig.sourceFolders.includes(cwd)) {
|
|
291
|
+
globalConfig.sourceFolders.push(cwd);
|
|
292
|
+
saveGlobalConfig(globalConfig);
|
|
293
|
+
}
|
|
294
|
+
// b) Create .autopilot/autopilot.json
|
|
295
|
+
const autopilotDir = node_path_1.default.join(cwd, ".autopilot");
|
|
296
|
+
const autopilotFile = node_path_1.default.join(autopilotDir, "autopilot.json");
|
|
297
|
+
if (!(0, node_fs_1.existsSync)(autopilotDir))
|
|
298
|
+
(0, node_fs_1.mkdirSync)(autopilotDir, { recursive: true });
|
|
299
|
+
if ((0, node_fs_1.existsSync)(autopilotFile)) {
|
|
300
|
+
console.log("⚠️ Autopilot config already exists in this repo.");
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
const repoName = getRepoName(cwd) || "owner/repo";
|
|
304
|
+
const templatePath = node_path_1.default.join(repoRoot, "templates", "autopilot.json");
|
|
305
|
+
let template;
|
|
306
|
+
if ((0, node_fs_1.existsSync)(templatePath)) {
|
|
307
|
+
template = JSON.parse((0, node_fs_1.readFileSync)(templatePath, "utf8"));
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
// Fallback internal default
|
|
311
|
+
template = {
|
|
312
|
+
enabled: true,
|
|
313
|
+
repo: repoName,
|
|
314
|
+
agent: "opencode",
|
|
315
|
+
issueLabels: {
|
|
316
|
+
queue: ["autopilot:todo"],
|
|
317
|
+
blocked: "autopilot:blocked",
|
|
318
|
+
inProgress: "autopilot:in-progress",
|
|
319
|
+
done: "autopilot:done"
|
|
320
|
+
},
|
|
321
|
+
priorityLabels: ["p0", "p1", "p2"],
|
|
322
|
+
maxParallel: 1,
|
|
323
|
+
branchPrefix: "autopilot/",
|
|
324
|
+
allowedBaseBranch: "main"
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
template.repo = repoName;
|
|
328
|
+
(0, node_fs_1.writeFileSync)(autopilotFile, JSON.stringify(template, null, 2) + "\n", "utf8");
|
|
329
|
+
console.log(`✅ Created .autopilot/autopilot.json (repo: ${repoName})`);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
// FOLDER MODE
|
|
334
|
+
console.log(`🚀 Adding directory to Autopilot scan list: ${cwd}`);
|
|
335
|
+
if (!globalConfig.sourceFolders.includes(cwd)) {
|
|
336
|
+
globalConfig.sourceFolders.push(cwd);
|
|
337
|
+
saveGlobalConfig(globalConfig);
|
|
338
|
+
console.log("✅ Added to global scan folders.");
|
|
271
339
|
}
|
|
340
|
+
else {
|
|
341
|
+
console.log("ℹ️ This folder is already in the scan list.");
|
|
342
|
+
}
|
|
343
|
+
console.log("\nNote: Autopilot will now scan all sub-folders of this directory for git repos.");
|
|
344
|
+
console.log("You must still run 'autopilot init' inside each repo you want to activate (unless it already has a config).");
|
|
272
345
|
}
|
|
273
|
-
const sourceFolders = await collectSourceFolders();
|
|
274
|
-
const config = {
|
|
275
|
-
sourceFolders,
|
|
276
|
-
};
|
|
277
|
-
saveGlobalConfig(config);
|
|
278
|
-
console.log("\n✅ Configuration saved to:", GLOBAL_CONFIG_FILE);
|
|
279
|
-
console.log("\nYou can now run:");
|
|
280
|
-
console.log(" autopilot scan # Scan repos without claiming issues");
|
|
281
|
-
console.log(" autopilot run-once # Claim and work on one issue");
|
|
282
346
|
}
|
|
283
347
|
const runnerPath = node_path_1.default.join(repoRoot, "scripts", "run_autopilot.py");
|
|
284
348
|
const program = new commander_1.Command();
|
|
@@ -314,13 +378,17 @@ program
|
|
|
314
378
|
.action((opts) => {
|
|
315
379
|
let rootPaths = opts.root;
|
|
316
380
|
if (!rootPaths || rootPaths.length === 0) {
|
|
317
|
-
|
|
318
|
-
if (!config
|
|
319
|
-
|
|
320
|
-
|
|
381
|
+
let config = loadGlobalConfig();
|
|
382
|
+
if (!config) {
|
|
383
|
+
config = { sourceFolders: [] };
|
|
384
|
+
saveGlobalConfig(config);
|
|
321
385
|
}
|
|
322
386
|
rootPaths = config.sourceFolders;
|
|
323
387
|
}
|
|
388
|
+
if (!rootPaths || rootPaths.length === 0) {
|
|
389
|
+
console.log("No source folders configured. Run 'autopilot init' to add some.");
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
324
392
|
const args = [runnerPath, "--root", ...rootPaths];
|
|
325
393
|
if (opts.maxDepth)
|
|
326
394
|
args.push("--max-depth", opts.maxDepth);
|
|
@@ -342,13 +410,17 @@ program
|
|
|
342
410
|
.action((opts) => {
|
|
343
411
|
let rootPaths = opts.root;
|
|
344
412
|
if (!rootPaths || rootPaths.length === 0) {
|
|
345
|
-
|
|
346
|
-
if (!config
|
|
347
|
-
|
|
348
|
-
|
|
413
|
+
let config = loadGlobalConfig();
|
|
414
|
+
if (!config) {
|
|
415
|
+
config = { sourceFolders: [] };
|
|
416
|
+
saveGlobalConfig(config);
|
|
349
417
|
}
|
|
350
418
|
rootPaths = config.sourceFolders;
|
|
351
419
|
}
|
|
420
|
+
if (!rootPaths || rootPaths.length === 0) {
|
|
421
|
+
console.log("No source folders configured. Run 'autopilot init' to add some.");
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
352
424
|
const args = [runnerPath, "--root", ...rootPaths];
|
|
353
425
|
if (opts.maxDepth)
|
|
354
426
|
args.push("--max-depth", opts.maxDepth);
|
|
@@ -371,13 +443,17 @@ program
|
|
|
371
443
|
.action((opts) => {
|
|
372
444
|
let rootPaths = opts.root;
|
|
373
445
|
if (!rootPaths || rootPaths.length === 0) {
|
|
374
|
-
|
|
375
|
-
if (!config
|
|
376
|
-
|
|
377
|
-
|
|
446
|
+
let config = loadGlobalConfig();
|
|
447
|
+
if (!config) {
|
|
448
|
+
config = { sourceFolders: [] };
|
|
449
|
+
saveGlobalConfig(config);
|
|
378
450
|
}
|
|
379
451
|
rootPaths = config.sourceFolders;
|
|
380
452
|
}
|
|
453
|
+
if (!rootPaths || rootPaths.length === 0) {
|
|
454
|
+
console.log("No source folders configured. Run 'autopilot init' to add some.");
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
381
457
|
const args = [runnerPath, "--root", ...rootPaths];
|
|
382
458
|
if (opts.maxDepth)
|
|
383
459
|
args.push("--max-depth", opts.maxDepth);
|