@nolto/cli 0.11.0 → 0.13.0
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/README.md +81 -8
- package/dist/index.js +735 -262
- package/dist/skill/roadmap-progress/SKILL.md +19 -2
- package/dist/skill/roadmap-progress/references/issue-cli.md +46 -0
- package/dist/skill/roadmap-progress/references/schema.md +8 -5
- package/dist/skill/roadmap-progress/scripts/roadmap.mjs +14 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
import { createRequire as createRequire3 } from "module";
|
|
5
5
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
6
|
-
import
|
|
6
|
+
import path20 from "path";
|
|
7
7
|
import { CommanderError } from "commander";
|
|
8
8
|
|
|
9
9
|
// src/config.ts
|
|
@@ -60,6 +60,14 @@ function mapHttpStatusToCliError(status, opts = {}) {
|
|
|
60
60
|
status
|
|
61
61
|
);
|
|
62
62
|
}
|
|
63
|
+
if (status === 409 && opts.serverError === "project_archived") {
|
|
64
|
+
return new CliError(
|
|
65
|
+
opts.serverMessage ?? "This project is archived.",
|
|
66
|
+
2,
|
|
67
|
+
"\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u304C\u30A2\u30FC\u30AB\u30A4\u30D6\u3055\u308C\u3066\u3044\u307E\u3059\u3002\u89E3\u9664\u3059\u308B\u306B\u306F Web \u306E\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u8A2D\u5B9A\u3067\u300C\u30A2\u30FC\u30AB\u30A4\u30D6\u3092\u89E3\u9664\u300D\u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044\u3002",
|
|
68
|
+
status
|
|
69
|
+
);
|
|
70
|
+
}
|
|
63
71
|
if (status === 429 && opts.serverError === "rebind_cooldown") {
|
|
64
72
|
return new CliError(
|
|
65
73
|
opts.serverMessage ?? "Rebind cooldown active.",
|
|
@@ -77,6 +85,21 @@ function mapHttpStatusToCliError(status, opts = {}) {
|
|
|
77
85
|
status
|
|
78
86
|
);
|
|
79
87
|
}
|
|
88
|
+
if (status === 404 && opts.serverError) {
|
|
89
|
+
return new CliError(opts.serverError, 2, void 0, status);
|
|
90
|
+
}
|
|
91
|
+
if (status === 422) {
|
|
92
|
+
const details = Array.isArray(opts.details) ? opts.details.map((detail) => typeof detail === "string" ? detail : JSON.stringify(detail)).join("\n") : "";
|
|
93
|
+
return new CliError([opts.serverError ?? opts.serverMessage ?? "Validation failed", details].filter(Boolean).join("\n"), 2, void 0, status);
|
|
94
|
+
}
|
|
95
|
+
if (status === 403 && (opts.serverError === "token_scope" || opts.serverError === "token_project")) {
|
|
96
|
+
return new CliError(
|
|
97
|
+
opts.serverMessage ?? opts.serverError,
|
|
98
|
+
3,
|
|
99
|
+
`Issue a token with the required scope at ${opts.baseUrl ?? "https://nolto.app"}/settings/tokens (nolto whoami shows the current scopes).`,
|
|
100
|
+
status
|
|
101
|
+
);
|
|
102
|
+
}
|
|
80
103
|
if (status === 403) {
|
|
81
104
|
return new CliError(
|
|
82
105
|
opts.serverMessage ?? opts.serverError ?? "Forbidden",
|
|
@@ -87,7 +110,7 @@ function mapHttpStatusToCliError(status, opts = {}) {
|
|
|
87
110
|
}
|
|
88
111
|
if (status === 429) {
|
|
89
112
|
const waitMsg = opts.retryAfter ? ` Retry-After: ${opts.retryAfter}s` : "";
|
|
90
|
-
return new CliError(
|
|
113
|
+
return new CliError(`${opts.serverMessage ?? "Rate limit exceeded."}${waitMsg}`, 4, void 0, status);
|
|
91
114
|
}
|
|
92
115
|
return new CliError(`Server returned HTTP ${status}`, 5, void 0, status);
|
|
93
116
|
}
|
|
@@ -314,11 +337,11 @@ function maskToken(token) {
|
|
|
314
337
|
function createHttpClient(opts) {
|
|
315
338
|
const { baseUrl, version, token } = opts;
|
|
316
339
|
const base = baseUrl.replace(/\/+$/, "");
|
|
317
|
-
async function request(method,
|
|
318
|
-
if (!
|
|
319
|
-
throw new CliError(`HTTP client path must start with /api/, got: ${
|
|
340
|
+
async function request(method, path21, body) {
|
|
341
|
+
if (!path21.startsWith("/api/")) {
|
|
342
|
+
throw new CliError(`HTTP client path must start with /api/, got: ${path21}`, 2);
|
|
320
343
|
}
|
|
321
|
-
const url = `${base}${
|
|
344
|
+
const url = `${base}${path21}`;
|
|
322
345
|
const headers = {
|
|
323
346
|
"Content-Type": "application/json",
|
|
324
347
|
"User-Agent": `${CLI_USER_AGENT_NAME}/${version}`
|
|
@@ -354,6 +377,8 @@ function createHttpClient(opts) {
|
|
|
354
377
|
} catch {
|
|
355
378
|
}
|
|
356
379
|
throw mapHttpStatusToCliError(response.status, {
|
|
380
|
+
baseUrl: base,
|
|
381
|
+
details: errorBody?.["details"],
|
|
357
382
|
retryAfter,
|
|
358
383
|
wwwAuthenticate,
|
|
359
384
|
serverError: typeof errorBody?.["error"] === "string" ? errorBody["error"] : void 0,
|
|
@@ -361,11 +386,14 @@ function createHttpClient(opts) {
|
|
|
361
386
|
upgradeUrl: typeof errorBody?.["upgradeUrl"] === "string" ? errorBody["upgradeUrl"] : void 0
|
|
362
387
|
});
|
|
363
388
|
}
|
|
389
|
+
if (response.status === 204) return void 0;
|
|
364
390
|
return response.json();
|
|
365
391
|
}
|
|
366
392
|
return {
|
|
367
393
|
get: (p) => request("GET", p),
|
|
368
394
|
post: (p, b) => request("POST", p, b),
|
|
395
|
+
patch: (p, b) => request("PATCH", p, b),
|
|
396
|
+
delete: (p) => request("DELETE", p),
|
|
369
397
|
put: (p, b) => request("PUT", p, b)
|
|
370
398
|
};
|
|
371
399
|
}
|
|
@@ -373,19 +401,10 @@ function createHttpClient(opts) {
|
|
|
373
401
|
// src/program.ts
|
|
374
402
|
import { Command } from "commander";
|
|
375
403
|
|
|
376
|
-
// src/commands/
|
|
377
|
-
import
|
|
378
|
-
import
|
|
379
|
-
import {
|
|
380
|
-
import os3 from "os";
|
|
381
|
-
import path9 from "path";
|
|
382
|
-
import fs from "fs";
|
|
383
|
-
|
|
384
|
-
// src/commands/link.ts
|
|
385
|
-
import readline from "readline/promises";
|
|
386
|
-
import os2 from "os";
|
|
387
|
-
import path5 from "path";
|
|
388
|
-
import { statSync as statSync2 } from "fs";
|
|
404
|
+
// src/commands/issue.ts
|
|
405
|
+
import { readFile as readFile2, readdir, writeFile as writeFile2, rename, rm } from "fs/promises";
|
|
406
|
+
import path2 from "path";
|
|
407
|
+
import { randomUUID } from "crypto";
|
|
389
408
|
|
|
390
409
|
// src/output.ts
|
|
391
410
|
function printResult(value, mode2, opts = {}) {
|
|
@@ -416,6 +435,11 @@ function printError(err, mode2) {
|
|
|
416
435
|
}
|
|
417
436
|
}
|
|
418
437
|
}
|
|
438
|
+
function formatRecord(record) {
|
|
439
|
+
const keys = Object.keys(record);
|
|
440
|
+
const maxKeyLen = keys.reduce((m, k) => Math.max(m, k.length), 0);
|
|
441
|
+
return keys.map((k) => `${k.padEnd(maxKeyLen)}: ${record[k] ?? ""}`).join("\n");
|
|
442
|
+
}
|
|
419
443
|
function formatValue(value) {
|
|
420
444
|
if (value === null || value === void 0) {
|
|
421
445
|
return "";
|
|
@@ -438,69 +462,6 @@ function formatValue(value) {
|
|
|
438
462
|
return JSON.stringify(value, null, 2);
|
|
439
463
|
}
|
|
440
464
|
|
|
441
|
-
// src/registry.ts
|
|
442
|
-
import { readFile as readFile2, writeFile as writeFile2, mkdir as mkdir2, rename, unlink } from "fs/promises";
|
|
443
|
-
import { randomUUID } from "crypto";
|
|
444
|
-
import path2 from "path";
|
|
445
|
-
import { z as z2 } from "zod";
|
|
446
|
-
var registrySchema = z2.object({
|
|
447
|
-
schemaVersion: z2.literal(1),
|
|
448
|
-
repos: z2.array(z2.object({ root: z2.string().min(1) }).passthrough())
|
|
449
|
-
}).passthrough();
|
|
450
|
-
function getRegistryPath(env) {
|
|
451
|
-
return path2.join(getConfigDir(env), "registry.json");
|
|
452
|
-
}
|
|
453
|
-
async function loadRegistry(filePath) {
|
|
454
|
-
let raw;
|
|
455
|
-
try {
|
|
456
|
-
raw = await readFile2(filePath, "utf8");
|
|
457
|
-
} catch (err) {
|
|
458
|
-
const code = err != null && typeof err === "object" && "code" in err ? err.code : "";
|
|
459
|
-
if (code === "ENOENT") {
|
|
460
|
-
return { schemaVersion: 1, repos: [] };
|
|
461
|
-
}
|
|
462
|
-
throw new CliError(`Cannot read registry: ${filePath}: ${String(err)}`, 2);
|
|
463
|
-
}
|
|
464
|
-
let parsed;
|
|
465
|
-
try {
|
|
466
|
-
parsed = JSON.parse(raw);
|
|
467
|
-
} catch {
|
|
468
|
-
throw new CliError(`Malformed JSON in ${filePath}. Fix or remove the file.`, 2);
|
|
469
|
-
}
|
|
470
|
-
const result = registrySchema.safeParse(parsed);
|
|
471
|
-
if (!result.success) {
|
|
472
|
-
const issue = result.error.issues[0];
|
|
473
|
-
const fieldPath = issue?.path.join(".") ?? "";
|
|
474
|
-
throw new CliError(
|
|
475
|
-
`Invalid registry at ${filePath}: ${fieldPath.length > 0 ? `field "${fieldPath}" \u2014 ` : ""}${issue?.message ?? "validation failed"}`,
|
|
476
|
-
2
|
|
477
|
-
);
|
|
478
|
-
}
|
|
479
|
-
return result.data;
|
|
480
|
-
}
|
|
481
|
-
async function addRepoToRegistry(filePath, repoRoot) {
|
|
482
|
-
const registry = await loadRegistry(filePath);
|
|
483
|
-
if (registry.repos.some((repo) => repo.root === repoRoot)) {
|
|
484
|
-
return { added: false, registry };
|
|
485
|
-
}
|
|
486
|
-
const updated = { ...registry, repos: [...registry.repos, { root: repoRoot }] };
|
|
487
|
-
await mkdir2(path2.dirname(filePath), { recursive: true, mode: 448 });
|
|
488
|
-
const tempPath = `${filePath}.tmp-${process.pid}-${randomUUID()}`;
|
|
489
|
-
try {
|
|
490
|
-
await writeFile2(tempPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
491
|
-
await rename(tempPath, filePath);
|
|
492
|
-
} catch (err) {
|
|
493
|
-
await unlink(tempPath).catch(() => void 0);
|
|
494
|
-
throw err;
|
|
495
|
-
}
|
|
496
|
-
return { added: true, registry: updated };
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
// src/repo-identity.ts
|
|
500
|
-
import { execFile } from "child_process";
|
|
501
|
-
import { realpathSync } from "fs";
|
|
502
|
-
import path4 from "path";
|
|
503
|
-
|
|
504
465
|
// ../roadmap-schema/src/repo-identity.ts
|
|
505
466
|
var HOSTED_LOWERCASE_PATH = /* @__PURE__ */ new Set(["github.com", "gitlab.com", "bitbucket.org"]);
|
|
506
467
|
function normalizeRemote(raw) {
|
|
@@ -520,22 +481,24 @@ function normalizeRemote(raw) {
|
|
|
520
481
|
const firstSlash = s.indexOf("/");
|
|
521
482
|
if (firstSlash <= 0) return null;
|
|
522
483
|
let host = s.slice(0, firstSlash).toLowerCase();
|
|
523
|
-
let
|
|
484
|
+
let path21 = s.slice(firstSlash + 1);
|
|
524
485
|
if (hadScheme) host = host.replace(/:\d+$/, "");
|
|
525
|
-
|
|
526
|
-
if (
|
|
527
|
-
if (HOSTED_LOWERCASE_PATH.has(host))
|
|
528
|
-
return `${host}/${
|
|
486
|
+
path21 = path21.replace(/\/+/g, "/").replace(/^\/+/, "").replace(/\/+$/, "").replace(/\.git$/i, "").replace(/\/+$/, "");
|
|
487
|
+
if (path21.length === 0) return null;
|
|
488
|
+
if (HOSTED_LOWERCASE_PATH.has(host)) path21 = path21.toLowerCase();
|
|
489
|
+
return `${host}/${path21}`;
|
|
529
490
|
}
|
|
530
491
|
|
|
531
492
|
// ../roadmap-schema/src/index.ts
|
|
532
493
|
var STATUSES = /* @__PURE__ */ new Set(["todo", "in-progress", "done", "blocked"]);
|
|
533
494
|
var ID_PATTERN = /^[a-z0-9][a-z0-9._-]*$/;
|
|
495
|
+
var DATE_TIME_PATTERN = /^(\d{4})-(\d{2})-(\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:[Zz]|([+-])(\d{2}):(\d{2}))$/;
|
|
496
|
+
var ISSUE_KEY_REF_PATTERN = /^[A-Z][A-Z0-9]{1,9}-[1-9][0-9]{0,8}$/;
|
|
534
497
|
var ALLOWED_KEYS = {
|
|
535
498
|
roadmap: /* @__PURE__ */ new Set(["schemaVersion", "project", "updatedAt", "currentTaskId", "summary", "phases"]),
|
|
536
499
|
project: /* @__PURE__ */ new Set(["id", "name", "repository"]),
|
|
537
500
|
phase: /* @__PURE__ */ new Set(["id", "title", "status", "plan", "tasks"]),
|
|
538
|
-
task: /* @__PURE__ */ new Set(["id", "title", "status", "startedAt", "completedAt", "note", "dependsOn", "plan"])
|
|
501
|
+
task: /* @__PURE__ */ new Set(["id", "title", "status", "startedAt", "completedAt", "note", "dependsOn", "plan", "issues"])
|
|
539
502
|
};
|
|
540
503
|
function isRecord(value) {
|
|
541
504
|
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
@@ -551,6 +514,39 @@ function isValidPlanPath(value) {
|
|
|
551
514
|
if (value.includes("\\") || value.startsWith("/") || /^[A-Za-z]:/.test(value)) return false;
|
|
552
515
|
return value.split("/").every((segment) => segment !== "" && segment !== "." && segment !== "..");
|
|
553
516
|
}
|
|
517
|
+
function daysInMonth(year, month) {
|
|
518
|
+
if (month === 2) {
|
|
519
|
+
const leap = year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
520
|
+
return leap ? 29 : 28;
|
|
521
|
+
}
|
|
522
|
+
return [4, 6, 9, 11].includes(month) ? 30 : 31;
|
|
523
|
+
}
|
|
524
|
+
function isValidDateTime(value) {
|
|
525
|
+
if (typeof value !== "string") return false;
|
|
526
|
+
const m = DATE_TIME_PATTERN.exec(value);
|
|
527
|
+
if (m === null) return false;
|
|
528
|
+
const year = Number(m[1]);
|
|
529
|
+
const month = Number(m[2]);
|
|
530
|
+
const day = Number(m[3]);
|
|
531
|
+
const hour = Number(m[4]);
|
|
532
|
+
const minute = Number(m[5]);
|
|
533
|
+
const second = Number(m[6]);
|
|
534
|
+
if (month < 1 || month > 12) return false;
|
|
535
|
+
if (day < 1 || day > daysInMonth(year, month)) return false;
|
|
536
|
+
if (hour > 23 || minute > 59 || second > 59) return false;
|
|
537
|
+
if (m[7] !== void 0) {
|
|
538
|
+
const offsetHour = Number(m[8]);
|
|
539
|
+
const offsetMinute = Number(m[9]);
|
|
540
|
+
if (offsetHour > 23 || offsetMinute > 59) return false;
|
|
541
|
+
}
|
|
542
|
+
return true;
|
|
543
|
+
}
|
|
544
|
+
function validateDateTime(value, at) {
|
|
545
|
+
if (!isValidDateTime(value)) {
|
|
546
|
+
return [`${at} must be an RFC 3339 date-time with timezone offset, e.g. 2026-09-02T10:00:00+09:00.`];
|
|
547
|
+
}
|
|
548
|
+
return [];
|
|
549
|
+
}
|
|
554
550
|
function validatePlanPath(value, at) {
|
|
555
551
|
if (typeof value !== "string" || value.length === 0) {
|
|
556
552
|
return [`${at} must be a non-empty string.`];
|
|
@@ -586,10 +582,10 @@ function validateRoadmap(value) {
|
|
|
586
582
|
const project = value["project"];
|
|
587
583
|
checkKeys(project, ALLOWED_KEYS.project, "project", errors);
|
|
588
584
|
const projectRecord = isRecord(project) ? project : {};
|
|
589
|
-
if (!ID_PATTERN.test(
|
|
590
|
-
if (projectRecord["name"]
|
|
591
|
-
if (projectRecord["repository"]
|
|
592
|
-
|
|
585
|
+
if (typeof projectRecord["id"] !== "string" || !ID_PATTERN.test(projectRecord["id"])) errors.push("project.id is invalid.");
|
|
586
|
+
if (typeof projectRecord["name"] !== "string" || projectRecord["name"].length === 0) errors.push("project.name must be a non-empty string.");
|
|
587
|
+
if (typeof projectRecord["repository"] !== "string" || projectRecord["repository"].length === 0) errors.push("project.repository must be a non-empty string.");
|
|
588
|
+
errors.push(...validateDateTime(value["updatedAt"], "updatedAt"));
|
|
593
589
|
if (typeof value["summary"] !== "string") errors.push("summary must be a string.");
|
|
594
590
|
if (!Array.isArray(value["phases"])) errors.push("phases must be an array.");
|
|
595
591
|
const allIds = /* @__PURE__ */ new Set();
|
|
@@ -599,11 +595,14 @@ function validateRoadmap(value) {
|
|
|
599
595
|
const at = `phases[${phaseIndex}]`;
|
|
600
596
|
checkKeys(rawPhase, ALLOWED_KEYS.phase, at, errors);
|
|
601
597
|
const phase = isRecord(rawPhase) ? rawPhase : {};
|
|
602
|
-
const phaseId =
|
|
603
|
-
if (!ID_PATTERN.test(
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
598
|
+
const phaseId = typeof phase["id"] === "string" ? phase["id"] : "";
|
|
599
|
+
if (typeof phase["id"] !== "string" || !ID_PATTERN.test(phase["id"])) {
|
|
600
|
+
errors.push(`${at}.id is invalid.`);
|
|
601
|
+
} else {
|
|
602
|
+
if (allIds.has(phaseId)) errors.push(`Duplicate id "${phaseId}".`);
|
|
603
|
+
allIds.add(phaseId);
|
|
604
|
+
}
|
|
605
|
+
if (typeof phase["title"] !== "string" || phase["title"].length === 0) errors.push(`${at}.title must be a non-empty string.`);
|
|
607
606
|
if (!STATUSES.has(String(phase["status"]))) errors.push(`${at}.status is invalid.`);
|
|
608
607
|
checkPlan(phase["plan"], at, errors);
|
|
609
608
|
if (!Array.isArray(phase["tasks"])) errors.push(`${at}.tasks must be an array.`);
|
|
@@ -612,34 +611,81 @@ function validateRoadmap(value) {
|
|
|
612
611
|
const taskAt = `${at}.tasks[${taskIndex}]`;
|
|
613
612
|
checkKeys(rawTask, ALLOWED_KEYS.task, taskAt, errors);
|
|
614
613
|
const task = isRecord(rawTask) ? rawTask : {};
|
|
615
|
-
const taskId =
|
|
616
|
-
if (!ID_PATTERN.test(
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
614
|
+
const taskId = typeof task["id"] === "string" ? task["id"] : "";
|
|
615
|
+
if (typeof task["id"] !== "string" || !ID_PATTERN.test(task["id"])) {
|
|
616
|
+
errors.push(`${taskAt}.id is invalid.`);
|
|
617
|
+
} else {
|
|
618
|
+
if (allIds.has(taskId)) errors.push(`Duplicate id "${taskId}".`);
|
|
619
|
+
allIds.add(taskId);
|
|
620
|
+
tasks.set(taskId, task);
|
|
621
|
+
}
|
|
622
|
+
if (typeof task["title"] !== "string" || task["title"].length === 0) errors.push(`${taskAt}.title must be a non-empty string.`);
|
|
621
623
|
if (!STATUSES.has(String(task["status"]))) errors.push(`${taskAt}.status is invalid.`);
|
|
622
624
|
checkPlan(task["plan"], taskAt, errors);
|
|
625
|
+
if (task["startedAt"] !== void 0 && task["startedAt"] !== null) {
|
|
626
|
+
errors.push(...validateDateTime(task["startedAt"], `${taskAt}.startedAt`));
|
|
627
|
+
}
|
|
628
|
+
if (task["completedAt"] !== void 0 && task["completedAt"] !== null) {
|
|
629
|
+
errors.push(...validateDateTime(task["completedAt"], `${taskAt}.completedAt`));
|
|
630
|
+
}
|
|
623
631
|
if (task["status"] === "done" && task["completedAt"] == null) warnings.push(`${taskId} is done without completedAt.`);
|
|
624
632
|
if (task["status"] === "in-progress" && task["startedAt"] == null) warnings.push(`${taskId} is in-progress without startedAt.`);
|
|
625
|
-
if (task["
|
|
633
|
+
if (task["issues"] !== void 0 && !Array.isArray(task["issues"])) {
|
|
634
|
+
errors.push(`${taskAt}.issues must be an array.`);
|
|
635
|
+
} else if (Array.isArray(task["issues"])) {
|
|
636
|
+
const seenIssues = /* @__PURE__ */ new Set();
|
|
637
|
+
for (const [i, key] of task["issues"].entries()) {
|
|
638
|
+
if (typeof key !== "string") {
|
|
639
|
+
errors.push(`${taskAt}.issues[${i}] must be a string.`);
|
|
640
|
+
continue;
|
|
641
|
+
}
|
|
642
|
+
if (!ISSUE_KEY_REF_PATTERN.test(key)) {
|
|
643
|
+
errors.push(`${taskAt}.issues[${i}] is not an issue key (e.g. NOLTO-12).`);
|
|
644
|
+
continue;
|
|
645
|
+
}
|
|
646
|
+
if (seenIssues.has(key)) errors.push(`${taskAt}.issues contains duplicate key "${key}".`);
|
|
647
|
+
seenIssues.add(key);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
if (task["dependsOn"] !== void 0 && !Array.isArray(task["dependsOn"])) {
|
|
651
|
+
errors.push(`${taskAt}.dependsOn must be an array.`);
|
|
652
|
+
} else if (Array.isArray(task["dependsOn"])) {
|
|
653
|
+
const seenDeps = /* @__PURE__ */ new Set();
|
|
654
|
+
for (const [i, dep] of task["dependsOn"].entries()) {
|
|
655
|
+
if (typeof dep !== "string") {
|
|
656
|
+
errors.push(`${taskAt}.dependsOn[${i}] must be a string.`);
|
|
657
|
+
continue;
|
|
658
|
+
}
|
|
659
|
+
if (!ID_PATTERN.test(dep)) {
|
|
660
|
+
errors.push(`${taskAt}.dependsOn[${i}] is invalid.`);
|
|
661
|
+
continue;
|
|
662
|
+
}
|
|
663
|
+
if (seenDeps.has(dep)) errors.push(`${taskAt}.dependsOn contains duplicate id "${dep}".`);
|
|
664
|
+
seenDeps.add(dep);
|
|
665
|
+
}
|
|
666
|
+
}
|
|
626
667
|
}
|
|
627
|
-
if (Array.isArray(phase["tasks"]) && STATUSES.has(String(phase["status"]))) {
|
|
668
|
+
if (Array.isArray(phase["tasks"]) && rawTasks.every(isRecord) && STATUSES.has(String(phase["status"]))) {
|
|
628
669
|
const expected = derivePhaseStatus({ ...phase, tasks: rawTasks });
|
|
629
670
|
if (phase["status"] !== expected) warnings.push(`${phaseId} status is ${String(phase["status"])}; task states derive ${expected}.`);
|
|
630
671
|
}
|
|
631
672
|
}
|
|
632
673
|
for (const task of tasks.values()) {
|
|
633
674
|
for (const dependency of task.dependsOn ?? []) {
|
|
675
|
+
if (typeof dependency !== "string") continue;
|
|
634
676
|
if (!tasks.has(dependency)) warnings.push(`${task.id} depends on unknown task ${dependency}.`);
|
|
635
677
|
if (task.id === dependency) errors.push(`${task.id} cannot depend on itself.`);
|
|
636
678
|
}
|
|
637
679
|
}
|
|
638
680
|
const currentTaskId = value["currentTaskId"];
|
|
639
681
|
if (currentTaskId !== null && currentTaskId !== void 0) {
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
else
|
|
682
|
+
if (typeof currentTaskId !== "string") {
|
|
683
|
+
errors.push("currentTaskId must be a string id or null.");
|
|
684
|
+
} else {
|
|
685
|
+
const current = tasks.get(currentTaskId);
|
|
686
|
+
if (current == null) errors.push(`currentTaskId ${String(currentTaskId)} does not exist.`);
|
|
687
|
+
else if (current.status !== "in-progress") warnings.push(`currentTaskId ${String(currentTaskId)} is not in-progress.`);
|
|
688
|
+
}
|
|
643
689
|
}
|
|
644
690
|
return { errors, warnings };
|
|
645
691
|
}
|
|
@@ -667,10 +713,341 @@ function deriveTaskStats(roadmap) {
|
|
|
667
713
|
};
|
|
668
714
|
}
|
|
669
715
|
|
|
670
|
-
// src/
|
|
671
|
-
|
|
716
|
+
// src/issue-core.ts
|
|
717
|
+
var isUuid = (value) => /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
|
|
718
|
+
function parseIssueRef(input) {
|
|
719
|
+
const match = /^(?:[A-Z][A-Z0-9]{1,9}-)?([1-9][0-9]{0,8})$/i.exec(input);
|
|
720
|
+
if (!match) throw new CliError(`Invalid issue reference: ${input}. Use KEY-12 or 12.`, 2);
|
|
721
|
+
return Number(match[1]);
|
|
722
|
+
}
|
|
723
|
+
function resolveMaster(kind, input, settings) {
|
|
724
|
+
const rows = kind === "status" ? settings.statuses : kind === "type" ? settings.types : settings.categories;
|
|
725
|
+
const normalized = input.toLowerCase();
|
|
726
|
+
const matches = rows.filter((row) => (isUuid(input) ? row.id : row.name).toLowerCase() === normalized);
|
|
727
|
+
if (matches.length !== 1) throw new CliError(`Unknown or ambiguous ${kind}: ${input}. Candidates: ${rows.map((row) => row.name).join(", ") || "(none)"}`, 2);
|
|
728
|
+
return { id: matches[0].id };
|
|
729
|
+
}
|
|
730
|
+
function pickClosedStatus(settings, override) {
|
|
731
|
+
const id = override === void 0 ? void 0 : resolveMaster("status", override, settings).id;
|
|
732
|
+
const selected = [...settings.statuses].filter((row) => row.isClosed && (id === void 0 || row.id === id)).sort((a, b) => a.sortOrder - b.sortOrder)[0];
|
|
733
|
+
if (!selected) throw new CliError("No matching closed status. Choose a closed status with --status.", 2);
|
|
734
|
+
return { id: selected.id, name: selected.name };
|
|
735
|
+
}
|
|
736
|
+
function buildListQuery(flags, settings) {
|
|
737
|
+
const params = new URLSearchParams();
|
|
738
|
+
for (const status of flags.status ?? []) params.append("status", resolveMaster("status", status, settings).id);
|
|
739
|
+
for (const kind of ["type", "category"]) {
|
|
740
|
+
const value = flags[kind];
|
|
741
|
+
if (value !== void 0) params.set(kind, resolveMaster(kind, value, settings).id);
|
|
742
|
+
}
|
|
743
|
+
const choices = {
|
|
744
|
+
closed: ["exclude", "include", "only"],
|
|
745
|
+
priority: ["high", "normal", "low"],
|
|
746
|
+
sort: ["updated", "due", "priority", "number", "created", "assignee", "status", "type", "subject"],
|
|
747
|
+
order: ["asc", "desc"]
|
|
748
|
+
};
|
|
749
|
+
for (const field of ["assignee", "closed", "q", "sort", "order", "page", "priority", "parent"]) {
|
|
750
|
+
const value = flags[field];
|
|
751
|
+
if (value === void 0) continue;
|
|
752
|
+
if (choices[field] && !choices[field].includes(value)) throw new CliError(`Invalid --${field}: ${value}. Choose ${choices[field].join(", ")}.`, 2);
|
|
753
|
+
if (field === "page" && (!/^[1-9][0-9]*$/.test(value) || !Number.isSafeInteger(Number(value)))) throw new CliError("--page must be a positive integer.", 2);
|
|
754
|
+
if (field === "assignee" && !["me", "none"].includes(value) && !isUuid(value)) throw new CliError("--assignee must be me, none or a UUID.", 2);
|
|
755
|
+
params.set(field, field === "parent" && value !== "none" ? String(parseIssueRef(value)) : value);
|
|
756
|
+
}
|
|
757
|
+
return params;
|
|
758
|
+
}
|
|
759
|
+
var personLabel = (person) => person?.name ?? person?.email ?? "\u2014";
|
|
760
|
+
var singleLine = (value) => value.replace(/[\r\n\t]/g, " ");
|
|
761
|
+
var formatTimestamp = (value) => value.replace("T", " ").replace(/\.\d+/, "").replace(/([+-]\d{2})$/, "$1:00").replace(/Z$/, "+00:00");
|
|
762
|
+
function formatIssueList(rows, meta) {
|
|
763
|
+
const values = rows.map((row) => {
|
|
764
|
+
const subject = Array.from(singleLine(row.subject));
|
|
765
|
+
return [row.key, row.status.name, row.priority, personLabel(row.assignee), subject.length > 60 ? `${subject.slice(0, 59).join("")}\u2026` : subject.join("")].map(singleLine);
|
|
766
|
+
});
|
|
767
|
+
const widths = [0, 1, 2, 3].map((index) => Math.max(0, ...values.map((row) => row[index].length)));
|
|
768
|
+
const lines = values.map((row) => row.map((value, index) => index < 4 ? value.padEnd(widths[index]) : value).join(" "));
|
|
769
|
+
return [...lines, `${rows.length} / ${meta.total} (page ${meta.page})`].join("\n");
|
|
770
|
+
}
|
|
771
|
+
function formatIssueView(bundle) {
|
|
772
|
+
const issue = bundle.issue;
|
|
773
|
+
const attributes = formatRecord({
|
|
774
|
+
key: issue.key,
|
|
775
|
+
subject: issue.subject,
|
|
776
|
+
status: issue.status.name,
|
|
777
|
+
type: issue.type.name,
|
|
778
|
+
priority: issue.priority,
|
|
779
|
+
assignee: personLabel(issue.assignee),
|
|
780
|
+
due: issue.dueDate ?? "\u2014",
|
|
781
|
+
categories: issue.categories.map((row) => row.name).join(", "),
|
|
782
|
+
parent: issue.parent?.key ?? "\u2014"
|
|
783
|
+
});
|
|
784
|
+
const comments = bundle.comments.map((comment) => `${personLabel(comment.author)} / ${formatTimestamp(comment.createdAt)}${!comment.deletedAt && comment.via ? ` [API \u7D4C\u7531: ${comment.via.tokenName}]` : ""}
|
|
785
|
+
${comment.deletedAt ? "\u30B3\u30E1\u30F3\u30C8\u306F\u524A\u9664\u3055\u308C\u3066\u3044\u307E\u3059\u3002" : comment.body}`);
|
|
786
|
+
return [attributes, issue.body, ...comments].join("\n\n");
|
|
787
|
+
}
|
|
788
|
+
function addIssueToRoadmapTask(roadmapJson, taskId, key, now) {
|
|
789
|
+
const validation = validateRoadmap(roadmapJson);
|
|
790
|
+
if (validation.errors.length) return { error: `Invalid roadmap: ${validation.errors.join("; ")}` };
|
|
791
|
+
const input = roadmapJson;
|
|
792
|
+
const target = input.phases.flatMap((phase) => phase.tasks).find((task) => task.id === taskId);
|
|
793
|
+
if (!target) return { error: `roadmap task ${taskId} was not found` };
|
|
794
|
+
if (target.issues?.includes(key)) return { roadmap: input, changed: false };
|
|
795
|
+
const roadmap = { ...input, schemaVersion: 2, updatedAt: now, phases: input.phases.map((phase) => ({
|
|
796
|
+
...phase,
|
|
797
|
+
tasks: phase.tasks.map((task) => task.id === taskId ? { ...task, issues: [...task.issues ?? [], key] } : task)
|
|
798
|
+
})) };
|
|
799
|
+
const result = validateRoadmap(roadmap);
|
|
800
|
+
return result.errors.length ? { error: `Invalid roadmap: ${result.errors.join("; ")}` } : { roadmap, changed: true };
|
|
801
|
+
}
|
|
802
|
+
function issueUrl(baseUrl, projectId, number) {
|
|
803
|
+
return `${baseUrl.replace(/\/+$/, "")}/projects/${encodeURIComponent(projectId)}/issues/${number}`;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
// src/commands/issue.ts
|
|
807
|
+
var emptySettings = { types: [], statuses: [], categories: [] };
|
|
808
|
+
function context(deps, command) {
|
|
809
|
+
if (!deps.settings.token) throw new CliError("Not authenticated. Run `nolto login` or set NOLTO_TOKEN.", 3);
|
|
810
|
+
const globals = command.optsWithGlobals();
|
|
811
|
+
const projectId = globals.project ?? deps.settings.defaultProjectId;
|
|
812
|
+
if (!projectId) throw new CliError("No project. Pass --project <id> or run nolto link.", 2);
|
|
813
|
+
return {
|
|
814
|
+
projectId,
|
|
815
|
+
root: `/api/projects/${encodeURIComponent(projectId)}`,
|
|
816
|
+
mode: globals.json ? "json" : deps.output.mode
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
async function bodyText(body, file) {
|
|
820
|
+
if (body !== void 0 && file !== void 0) throw new CliError("Use either --body/-m or --body-file, not both.", 2);
|
|
821
|
+
if (file === void 0) return body;
|
|
822
|
+
try {
|
|
823
|
+
if (file !== "-") return await readFile2(file, "utf8");
|
|
824
|
+
const chunks = [];
|
|
825
|
+
for await (const chunk of process.stdin) chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
826
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
827
|
+
} catch (error) {
|
|
828
|
+
throw new CliError(`Cannot read body from ${file}: ${String(error)}`, 2);
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
async function writeInput(deps, root, flags, create) {
|
|
832
|
+
const body = await bodyText(flags.body, flags.bodyFile);
|
|
833
|
+
const settings = flags.type || flags.status || flags.category ? await deps.http.get(`${root}/issue-settings`) : emptySettings;
|
|
834
|
+
const typeId = flags.type === void 0 ? void 0 : resolveMaster("type", flags.type, settings).id;
|
|
835
|
+
const template = create && body === void 0 && typeId !== void 0 ? settings.types.find((type) => type.id === typeId)?.bodyTemplate : void 0;
|
|
836
|
+
let assigneeId;
|
|
837
|
+
if (flags.assignee !== void 0) {
|
|
838
|
+
if (flags.assignee === "none") assigneeId = null;
|
|
839
|
+
else if (flags.assignee === "me") assigneeId = (await deps.http.get("/api/me/profile")).profile.id;
|
|
840
|
+
else if (isUuid(flags.assignee)) assigneeId = flags.assignee;
|
|
841
|
+
else throw new CliError("--assignee must be me, none or a UUID.", 2);
|
|
842
|
+
}
|
|
843
|
+
let parentId;
|
|
844
|
+
if (flags.parent === false) parentId = null;
|
|
845
|
+
else if (flags.parent !== void 0) parentId = (await deps.http.get(`${root}/issues/${parseIssueRef(flags.parent)}`)).issue.id;
|
|
846
|
+
if (typeof flags.due === "string" && (!/^\d{4}-\d{2}-\d{2}$/.test(flags.due) || !Number.isFinite(Date.parse(flags.due)) || new Date(flags.due).toISOString().slice(0, 10) !== flags.due)) {
|
|
847
|
+
throw new CliError("--due must be a valid YYYY-MM-DD date.", 2);
|
|
848
|
+
}
|
|
849
|
+
if (flags.priority !== void 0 && !["high", "normal", "low"].includes(flags.priority)) throw new CliError("--priority must be high, normal or low.", 2);
|
|
850
|
+
const input = {
|
|
851
|
+
...flags.subject !== void 0 ? { subject: flags.subject } : {},
|
|
852
|
+
...body !== void 0 ? { body } : template != null ? { body: template } : {},
|
|
853
|
+
...typeId !== void 0 ? { typeId } : {},
|
|
854
|
+
...flags.status !== void 0 ? { statusId: resolveMaster("status", flags.status, settings).id } : {},
|
|
855
|
+
...flags.priority !== void 0 ? { priority: flags.priority } : {},
|
|
856
|
+
...assigneeId !== void 0 ? { assigneeId } : {},
|
|
857
|
+
...flags.due !== void 0 ? { dueDate: flags.due === false ? null : flags.due } : {},
|
|
858
|
+
...flags.category !== void 0 ? { categoryIds: flags.category.map((name) => resolveMaster("category", name, settings).id) } : {},
|
|
859
|
+
...parentId !== void 0 ? { parentId } : {},
|
|
860
|
+
...flags.comment !== void 0 ? { comment: flags.comment } : {}
|
|
861
|
+
};
|
|
862
|
+
if (Object.keys(input).length === 0) throw new CliError("No changes. Pass a field option or --comment.", 2);
|
|
863
|
+
return { input, fromTemplate: template != null };
|
|
864
|
+
}
|
|
865
|
+
function localTimestamp() {
|
|
866
|
+
const date = /* @__PURE__ */ new Date();
|
|
867
|
+
const minutes = -date.getTimezoneOffset();
|
|
868
|
+
const pad = (value) => String(Math.abs(value)).padStart(2, "0");
|
|
869
|
+
return `${new Date(date.getTime() + minutes * 6e4).toISOString().slice(0, -1)}${minutes >= 0 ? "+" : "-"}${pad(Math.trunc(minutes / 60))}:${pad(minutes % 60)}`;
|
|
870
|
+
}
|
|
871
|
+
async function attachRoadmap(deps, taskId, slug, key) {
|
|
872
|
+
let directory = path2.dirname(deps.repoBinding?.path ?? deps.projectBindingPath ?? path2.join(process.cwd(), "nolto.json"));
|
|
873
|
+
let file = "";
|
|
874
|
+
try {
|
|
875
|
+
if (slug !== void 0 && !/^[a-z0-9][a-z0-9._-]*$/.test(slug)) throw new Error("Invalid --roadmap slug.");
|
|
876
|
+
let entries;
|
|
877
|
+
for (; ; ) {
|
|
878
|
+
try {
|
|
879
|
+
entries = await readdir(path2.join(directory, ".nolto", "roadmaps"));
|
|
880
|
+
break;
|
|
881
|
+
} catch (error) {
|
|
882
|
+
if (error.code !== "ENOENT" || path2.dirname(directory) === directory) throw error;
|
|
883
|
+
directory = path2.dirname(directory);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
const names = entries.filter((name) => name.endsWith(".json")).sort();
|
|
887
|
+
if (slug === void 0 && names.length !== 1) throw new Error(`Choose --roadmap <slug>. Candidates: ${names.map((name) => name.slice(0, -5)).join(", ") || "(none)"}`);
|
|
888
|
+
file = path2.join(directory, ".nolto", "roadmaps", slug === void 0 ? names[0] : `${slug}.json`);
|
|
889
|
+
const result = addIssueToRoadmapTask(JSON.parse(await readFile2(file, "utf8")), taskId, key, localTimestamp());
|
|
890
|
+
if ("error" in result) throw new Error(`${result.error} in ${file}`);
|
|
891
|
+
if (result.changed) {
|
|
892
|
+
const temp = `${file}.${randomUUID()}.tmp`;
|
|
893
|
+
try {
|
|
894
|
+
await writeFile2(temp, JSON.stringify(result.roadmap, null, 2) + "\n", { flag: "wx" });
|
|
895
|
+
await rename(temp, file);
|
|
896
|
+
} finally {
|
|
897
|
+
await rm(temp, { force: true });
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
process.stderr.write("Run `nolto sync` to link it on Nolto.\n");
|
|
901
|
+
return { file, taskId };
|
|
902
|
+
} catch (error) {
|
|
903
|
+
throw new CliError(
|
|
904
|
+
`Issue ${key} was created, but ${error instanceof Error ? error.message : String(error)}`,
|
|
905
|
+
2,
|
|
906
|
+
"Do not create it again. Add the existing issue key to the roadmap task, then run `nolto sync`."
|
|
907
|
+
);
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
function writeOptions(command, create) {
|
|
911
|
+
if (create) command.requiredOption("--subject <text>", "Issue subject");
|
|
912
|
+
else command.option("--subject <text>", "Issue subject");
|
|
913
|
+
command.option("--body <text>", "Issue body").option("--body-file <path>", "Read body from file (- for stdin)").option("--type <name-or-id>", "Issue type").option("--status <name-or-id>", "Issue status").option("--priority <priority>", "high, normal or low").option("--assignee <assignee>", "me, none or UUID").option("--due <YYYY-MM-DD>", "Due date").option("--category <names...>", "Category names or UUIDs").option("--parent <ref>", "Parent issue key or number");
|
|
914
|
+
if (create) command.option("--phase <task-id>", "Attach the created key to a local roadmap task").option("--roadmap <slug>", "Roadmap filename slug (with --phase)");
|
|
915
|
+
else command.option("--no-due", "Clear due date").option("--no-parent", "Clear parent").option("-m, --comment <text>", "Comment in the same update");
|
|
916
|
+
return command;
|
|
917
|
+
}
|
|
918
|
+
function register(program, deps) {
|
|
919
|
+
const group = program.command("issue").description("List, view and manage project issues.");
|
|
920
|
+
group.command("list").description("List or search issues.").option("--status <names...>", "Status names or UUIDs").option("--assignee <assignee>", "me, none or UUID").option("--closed <mode>", "exclude, include or only").option("--q <text>", "Search text").option("--sort <field>", "updated, due, priority, number, created, assignee, status, type or subject").option("--order <order>", "asc or desc").option("--page <number>", "Page number").option("--type <name-or-id>", "Issue type").option("--priority <priority>", "high, normal or low").option("--category <name-or-id>", "Category").option("--parent <ref>", "Parent issue or none").action(async (flags, command) => {
|
|
921
|
+
const ctx = context(deps, command);
|
|
922
|
+
const settings = flags.status || flags.type || flags.category ? await deps.http.get(`${ctx.root}/issue-settings`) : emptySettings;
|
|
923
|
+
const query = buildListQuery(flags, settings).toString();
|
|
924
|
+
const result = await deps.http.get(`${ctx.root}/issues${query ? `?${query}` : ""}`);
|
|
925
|
+
printResult(ctx.mode === "json" ? result : formatIssueList(result.issues, result), ctx.mode);
|
|
926
|
+
});
|
|
927
|
+
group.command("view <ref>").description("Show issue details and comments.").action(async (ref, _flags, command) => {
|
|
928
|
+
const ctx = context(deps, command);
|
|
929
|
+
const result = await deps.http.get(`${ctx.root}/issues/${parseIssueRef(ref)}`);
|
|
930
|
+
printResult(ctx.mode === "json" ? result : formatIssueView(result), ctx.mode);
|
|
931
|
+
});
|
|
932
|
+
writeOptions(group.command("create").description("Create an issue."), true).action(async (flags, command) => {
|
|
933
|
+
const ctx = context(deps, command);
|
|
934
|
+
if (flags.roadmap !== void 0 && flags.phase === void 0) throw new CliError("--roadmap requires --phase.", 2);
|
|
935
|
+
const { input, fromTemplate } = await writeInput(deps, ctx.root, flags, true);
|
|
936
|
+
const result = await deps.http.post(`${ctx.root}/issues`, input);
|
|
937
|
+
const roadmap = flags.phase === void 0 ? void 0 : await attachRoadmap(deps, flags.phase, flags.roadmap, result.issue.key);
|
|
938
|
+
printResult(ctx.mode === "json" ? { ...result, ...roadmap ? { roadmap } : {} } : `${result.issue.key} created
|
|
939
|
+
${issueUrl(deps.settings.baseUrl, ctx.projectId, result.issue.number)}${fromTemplate ? "\nbody: from template" : ""}`, ctx.mode);
|
|
940
|
+
});
|
|
941
|
+
writeOptions(group.command("update <ref>").description("Update issue fields."), false).action(async (ref, flags, command) => {
|
|
942
|
+
const ctx = context(deps, command);
|
|
943
|
+
const number = parseIssueRef(ref);
|
|
944
|
+
const { input } = await writeInput(deps, ctx.root, flags, false);
|
|
945
|
+
const result = await deps.http.patch(`${ctx.root}/issues/${number}`, input);
|
|
946
|
+
printResult(ctx.mode === "json" ? result : `${result.issue.key} updated
|
|
947
|
+
${issueUrl(deps.settings.baseUrl, ctx.projectId, number)}`, ctx.mode);
|
|
948
|
+
});
|
|
949
|
+
group.command("comment <ref>").description("Post a comment.").option("-m, --comment <text>", "Comment text").option("--body-file <path>", "Read comment from file (- for stdin)").action(async (ref, flags, command) => {
|
|
950
|
+
const ctx = context(deps, command);
|
|
951
|
+
const number = parseIssueRef(ref);
|
|
952
|
+
const body = await bodyText(flags.comment, flags.bodyFile);
|
|
953
|
+
if (!body?.trim()) throw new CliError("A comment is required. Use -m or --body-file.", 2);
|
|
954
|
+
const issue = ctx.mode === "human" ? (await deps.http.get(`${ctx.root}/issues/${number}`)).issue : void 0;
|
|
955
|
+
const result = await deps.http.post(`${ctx.root}/issues/${number}/comments`, { body });
|
|
956
|
+
printResult(ctx.mode === "json" ? result : `${issue.key} commented
|
|
957
|
+
${issueUrl(deps.settings.baseUrl, ctx.projectId, number)}`, ctx.mode);
|
|
958
|
+
});
|
|
959
|
+
group.command("close <ref>").description("Move an issue to a closed status.").option("--status <name-or-id>", "Closed status (defaults to first by sort order)").option("-m, --comment <text>", "Comment in the same update").action(async (ref, flags, command) => {
|
|
960
|
+
const ctx = context(deps, command);
|
|
961
|
+
const number = parseIssueRef(ref);
|
|
962
|
+
const settings = await deps.http.get(`${ctx.root}/issue-settings`);
|
|
963
|
+
const status = pickClosedStatus(settings, flags.status);
|
|
964
|
+
const result = await deps.http.patch(`${ctx.root}/issues/${number}`, { statusId: status.id, ...flags.comment !== void 0 ? { comment: flags.comment } : {} });
|
|
965
|
+
printResult(ctx.mode === "json" ? result : `${result.issue.key} closed
|
|
966
|
+
${issueUrl(deps.settings.baseUrl, ctx.projectId, number)}`, ctx.mode);
|
|
967
|
+
});
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
// src/commands/init.ts
|
|
971
|
+
import readline2 from "readline/promises";
|
|
972
|
+
import { createRequire } from "module";
|
|
973
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
974
|
+
import os3 from "os";
|
|
975
|
+
import path10 from "path";
|
|
976
|
+
import fs from "fs";
|
|
977
|
+
|
|
978
|
+
// src/commands/link.ts
|
|
979
|
+
import readline from "readline/promises";
|
|
980
|
+
import os2 from "os";
|
|
981
|
+
import path6 from "path";
|
|
982
|
+
import { statSync as statSync2 } from "fs";
|
|
983
|
+
|
|
984
|
+
// src/registry.ts
|
|
985
|
+
import { readFile as readFile3, writeFile as writeFile3, mkdir as mkdir2, rename as rename2, unlink } from "fs/promises";
|
|
672
986
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
673
987
|
import path3 from "path";
|
|
988
|
+
import { z as z2 } from "zod";
|
|
989
|
+
var registrySchema = z2.object({
|
|
990
|
+
schemaVersion: z2.literal(1),
|
|
991
|
+
repos: z2.array(z2.object({ root: z2.string().min(1) }).passthrough())
|
|
992
|
+
}).passthrough();
|
|
993
|
+
function getRegistryPath(env) {
|
|
994
|
+
return path3.join(getConfigDir(env), "registry.json");
|
|
995
|
+
}
|
|
996
|
+
async function loadRegistry(filePath) {
|
|
997
|
+
let raw;
|
|
998
|
+
try {
|
|
999
|
+
raw = await readFile3(filePath, "utf8");
|
|
1000
|
+
} catch (err) {
|
|
1001
|
+
const code = err != null && typeof err === "object" && "code" in err ? err.code : "";
|
|
1002
|
+
if (code === "ENOENT") {
|
|
1003
|
+
return { schemaVersion: 1, repos: [] };
|
|
1004
|
+
}
|
|
1005
|
+
throw new CliError(`Cannot read registry: ${filePath}: ${String(err)}`, 2);
|
|
1006
|
+
}
|
|
1007
|
+
let parsed;
|
|
1008
|
+
try {
|
|
1009
|
+
parsed = JSON.parse(raw);
|
|
1010
|
+
} catch {
|
|
1011
|
+
throw new CliError(`Malformed JSON in ${filePath}. Fix or remove the file.`, 2);
|
|
1012
|
+
}
|
|
1013
|
+
const result = registrySchema.safeParse(parsed);
|
|
1014
|
+
if (!result.success) {
|
|
1015
|
+
const issue = result.error.issues[0];
|
|
1016
|
+
const fieldPath = issue?.path.join(".") ?? "";
|
|
1017
|
+
throw new CliError(
|
|
1018
|
+
`Invalid registry at ${filePath}: ${fieldPath.length > 0 ? `field "${fieldPath}" \u2014 ` : ""}${issue?.message ?? "validation failed"}`,
|
|
1019
|
+
2
|
|
1020
|
+
);
|
|
1021
|
+
}
|
|
1022
|
+
return result.data;
|
|
1023
|
+
}
|
|
1024
|
+
async function addRepoToRegistry(filePath, repoRoot) {
|
|
1025
|
+
const registry = await loadRegistry(filePath);
|
|
1026
|
+
if (registry.repos.some((repo) => repo.root === repoRoot)) {
|
|
1027
|
+
return { added: false, registry };
|
|
1028
|
+
}
|
|
1029
|
+
const updated = { ...registry, repos: [...registry.repos, { root: repoRoot }] };
|
|
1030
|
+
await mkdir2(path3.dirname(filePath), { recursive: true, mode: 448 });
|
|
1031
|
+
const tempPath = `${filePath}.tmp-${process.pid}-${randomUUID2()}`;
|
|
1032
|
+
try {
|
|
1033
|
+
await writeFile3(tempPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
1034
|
+
await rename2(tempPath, filePath);
|
|
1035
|
+
} catch (err) {
|
|
1036
|
+
await unlink(tempPath).catch(() => void 0);
|
|
1037
|
+
throw err;
|
|
1038
|
+
}
|
|
1039
|
+
return { added: true, registry: updated };
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
// src/repo-identity.ts
|
|
1043
|
+
import { execFile } from "child_process";
|
|
1044
|
+
import { realpathSync } from "fs";
|
|
1045
|
+
import path5 from "path";
|
|
1046
|
+
|
|
1047
|
+
// src/machine-id.ts
|
|
1048
|
+
import { chmod, mkdir as mkdir3, readFile as readFile4, writeFile as writeFile4 } from "fs/promises";
|
|
1049
|
+
import { randomUUID as randomUUID3 } from "crypto";
|
|
1050
|
+
import path4 from "path";
|
|
674
1051
|
var inFlightByConfigDir = /* @__PURE__ */ new Map();
|
|
675
1052
|
function parseMachineId(raw, file) {
|
|
676
1053
|
let parsed;
|
|
@@ -686,10 +1063,10 @@ function parseMachineId(raw, file) {
|
|
|
686
1063
|
return id;
|
|
687
1064
|
}
|
|
688
1065
|
async function loadOrCreate(configDir) {
|
|
689
|
-
const file =
|
|
1066
|
+
const file = path4.join(configDir, "machine.json");
|
|
690
1067
|
let raw = null;
|
|
691
1068
|
try {
|
|
692
|
-
raw = await
|
|
1069
|
+
raw = await readFile4(file, "utf8");
|
|
693
1070
|
} catch (err) {
|
|
694
1071
|
const code = err.code;
|
|
695
1072
|
if (code !== "ENOENT") {
|
|
@@ -699,17 +1076,17 @@ async function loadOrCreate(configDir) {
|
|
|
699
1076
|
if (raw !== null) {
|
|
700
1077
|
return parseMachineId(raw, file);
|
|
701
1078
|
}
|
|
702
|
-
const machineId =
|
|
1079
|
+
const machineId = randomUUID3();
|
|
703
1080
|
await mkdir3(configDir, { recursive: true, mode: 448 });
|
|
704
1081
|
try {
|
|
705
|
-
await
|
|
1082
|
+
await writeFile4(file, `${JSON.stringify({ machineId }, null, 2)}
|
|
706
1083
|
`, {
|
|
707
1084
|
flag: "wx",
|
|
708
1085
|
mode: 384
|
|
709
1086
|
});
|
|
710
1087
|
} catch (err) {
|
|
711
1088
|
if (err.code === "EEXIST") {
|
|
712
|
-
return parseMachineId(await
|
|
1089
|
+
return parseMachineId(await readFile4(file, "utf8"), file);
|
|
713
1090
|
}
|
|
714
1091
|
throw new CliError(`Cannot write ${file}: ${String(err)}`, 2);
|
|
715
1092
|
}
|
|
@@ -717,7 +1094,7 @@ async function loadOrCreate(configDir) {
|
|
|
717
1094
|
return machineId;
|
|
718
1095
|
}
|
|
719
1096
|
function loadOrCreateMachineId(configDir) {
|
|
720
|
-
const key =
|
|
1097
|
+
const key = path4.resolve(configDir);
|
|
721
1098
|
const existing = inFlightByConfigDir.get(key);
|
|
722
1099
|
if (existing !== void 0) return existing;
|
|
723
1100
|
const pending = loadOrCreate(key).finally(() => {
|
|
@@ -734,9 +1111,9 @@ function defaultGetRemoteUrl(root) {
|
|
|
734
1111
|
"git",
|
|
735
1112
|
["-C", root, "remote", "get-url", "origin"],
|
|
736
1113
|
{ timeout: 5e3 },
|
|
737
|
-
(err,
|
|
1114
|
+
(err, stdout2) => {
|
|
738
1115
|
if (err) return resolve(null);
|
|
739
|
-
const line =
|
|
1116
|
+
const line = stdout2.split(/\r?\n/)[0]?.trim() ?? "";
|
|
740
1117
|
resolve(line.length > 0 ? line : null);
|
|
741
1118
|
}
|
|
742
1119
|
);
|
|
@@ -751,7 +1128,7 @@ async function resolveRepoIdentity(root, deps) {
|
|
|
751
1128
|
try {
|
|
752
1129
|
canonicalRoot = realpathSync(root);
|
|
753
1130
|
} catch {
|
|
754
|
-
canonicalRoot =
|
|
1131
|
+
canonicalRoot = path5.resolve(root);
|
|
755
1132
|
}
|
|
756
1133
|
return { kind: "local", value: `${machineId}:${canonicalRoot}` };
|
|
757
1134
|
}
|
|
@@ -770,7 +1147,7 @@ function resolveStartDir(env, cwd) {
|
|
|
770
1147
|
}
|
|
771
1148
|
function dirHasGit(dir) {
|
|
772
1149
|
try {
|
|
773
|
-
statSync2(
|
|
1150
|
+
statSync2(path6.join(dir, ".git"));
|
|
774
1151
|
return true;
|
|
775
1152
|
} catch {
|
|
776
1153
|
return false;
|
|
@@ -782,14 +1159,14 @@ function findRepoRoot(startDir, hasGit = dirHasGit) {
|
|
|
782
1159
|
if (hasGit(current)) {
|
|
783
1160
|
return { root: current, foundGit: true };
|
|
784
1161
|
}
|
|
785
|
-
const parent =
|
|
1162
|
+
const parent = path6.dirname(current);
|
|
786
1163
|
if (parent === current) break;
|
|
787
1164
|
current = parent;
|
|
788
1165
|
}
|
|
789
1166
|
return { root: startDir, foundGit: false };
|
|
790
1167
|
}
|
|
791
1168
|
function isHomeDirectory(dir, home = os2.homedir()) {
|
|
792
|
-
return
|
|
1169
|
+
return path6.resolve(dir) === path6.resolve(home);
|
|
793
1170
|
}
|
|
794
1171
|
async function handleShow(deps, projectBindingPath, mode2) {
|
|
795
1172
|
const startDir = resolveStartDir(process.env, process.cwd());
|
|
@@ -888,10 +1265,10 @@ async function handleRebind(deps, projectId, root, mode2, yes) {
|
|
|
888
1265
|
}
|
|
889
1266
|
}
|
|
890
1267
|
async function handleUnlink(projectBindingPath, mode2) {
|
|
891
|
-
const { readFile:
|
|
1268
|
+
const { readFile: readFile13, writeFile: writeFile11, chmod: chmod2 } = await import("fs/promises");
|
|
892
1269
|
let existing = {};
|
|
893
1270
|
try {
|
|
894
|
-
const raw = await
|
|
1271
|
+
const raw = await readFile13(projectBindingPath, "utf8");
|
|
895
1272
|
const parsed = JSON.parse(raw);
|
|
896
1273
|
if (parsed == null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
897
1274
|
throw new CliError(
|
|
@@ -906,7 +1283,7 @@ async function handleUnlink(projectBindingPath, mode2) {
|
|
|
906
1283
|
}
|
|
907
1284
|
const { projectId: _removed, ...rest } = existing;
|
|
908
1285
|
void _removed;
|
|
909
|
-
await
|
|
1286
|
+
await writeFile11(projectBindingPath, JSON.stringify(rest, null, 2) + "\n", { mode: 420 });
|
|
910
1287
|
await chmod2(projectBindingPath, 420);
|
|
911
1288
|
if (mode2 === "json") {
|
|
912
1289
|
printResult({ unlinked: true, projectBindingPath }, mode2);
|
|
@@ -961,7 +1338,7 @@ Proceeding anyway \u2014 verify the ID is correct.
|
|
|
961
1338
|
);
|
|
962
1339
|
}
|
|
963
1340
|
await writeRepoBinding(root, projectId);
|
|
964
|
-
const writtenPath =
|
|
1341
|
+
const writtenPath = path6.join(root, "nolto.json");
|
|
965
1342
|
let registryAdded = false;
|
|
966
1343
|
if (isHomeDirectory(root)) {
|
|
967
1344
|
process.stderr.write(`Warning: refusing to add home directory ${root} to the watch registry.
|
|
@@ -994,7 +1371,7 @@ Commit nolto.json to share the binding with your team.
|
|
|
994
1371
|
}
|
|
995
1372
|
}
|
|
996
1373
|
}
|
|
997
|
-
function
|
|
1374
|
+
function register2(program, deps) {
|
|
998
1375
|
const cmd = program.command("link [projectId]").description(
|
|
999
1376
|
"Bind this repository to a Nolto project.\nWrites nolto.json at the repo root. Commit it to share the binding with your team.\n\nExamples:\n nolto link <uuid> Write / update nolto.json\n nolto link --show Show the current binding\n nolto link --rebind Rebind the project to this repository\n nolto link --unlink Remove the projectId from nolto.json"
|
|
1000
1377
|
).option("--show", "Show the current repo binding (path + projectId + source)").option("--rebind", "Rebind the project to this repository (owner only, once per 7 days)").option("-y, --yes", "Skip the rebind confirmation prompt").option("--unlink", "Remove the projectId key from nolto.json");
|
|
@@ -1048,35 +1425,35 @@ function invalidBindingError(projectBindingPath, error) {
|
|
|
1048
1425
|
}
|
|
1049
1426
|
|
|
1050
1427
|
// src/skill-install.ts
|
|
1051
|
-
import { cp, mkdir as mkdir4, readFile as
|
|
1428
|
+
import { cp, mkdir as mkdir4, readFile as readFile5, writeFile as writeFile5, rm as rm2 } from "fs/promises";
|
|
1052
1429
|
import { existsSync } from "fs";
|
|
1053
|
-
import
|
|
1430
|
+
import path7 from "path";
|
|
1054
1431
|
import { fileURLToPath } from "url";
|
|
1055
|
-
var __dirname =
|
|
1432
|
+
var __dirname = path7.dirname(fileURLToPath(import.meta.url));
|
|
1056
1433
|
function resolveSkillSourceDir() {
|
|
1057
1434
|
const candidates = [
|
|
1058
|
-
|
|
1435
|
+
path7.resolve(__dirname, "skill/roadmap-progress"),
|
|
1059
1436
|
// bundled: dist/skill/...
|
|
1060
|
-
|
|
1437
|
+
path7.resolve(__dirname, "../../../skills/roadmap-progress")
|
|
1061
1438
|
// source: <repo>/skills/...
|
|
1062
1439
|
];
|
|
1063
1440
|
for (const candidate of candidates) {
|
|
1064
|
-
if (existsSync(
|
|
1441
|
+
if (existsSync(path7.join(candidate, "SKILL.md"))) return candidate;
|
|
1065
1442
|
}
|
|
1066
1443
|
throw new Error("Bundled roadmap-progress skill not found. Reinstall @nolto/cli.");
|
|
1067
1444
|
}
|
|
1068
1445
|
var VERSION_MARKER = ".nolto-skill-version";
|
|
1069
1446
|
async function checkSkillVersionDrift(repoRoot, cliVersion) {
|
|
1070
1447
|
const skillDirs = [
|
|
1071
|
-
|
|
1072
|
-
|
|
1448
|
+
path7.join(repoRoot, ".claude", "skills", "roadmap-progress"),
|
|
1449
|
+
path7.join(repoRoot, ".agents", "skills", "roadmap-progress")
|
|
1073
1450
|
];
|
|
1074
1451
|
const drifted = [];
|
|
1075
1452
|
for (const dir of skillDirs) {
|
|
1076
1453
|
if (!existsSync(dir)) continue;
|
|
1077
1454
|
let installed;
|
|
1078
1455
|
try {
|
|
1079
|
-
const marker = (await
|
|
1456
|
+
const marker = (await readFile5(path7.join(dir, VERSION_MARKER), "utf8")).trim();
|
|
1080
1457
|
installed = marker.length > 0 ? marker : null;
|
|
1081
1458
|
} catch {
|
|
1082
1459
|
installed = null;
|
|
@@ -1086,18 +1463,18 @@ async function checkSkillVersionDrift(repoRoot, cliVersion) {
|
|
|
1086
1463
|
return drifted;
|
|
1087
1464
|
}
|
|
1088
1465
|
function formatSkillVersionDriftWarning(repoRoot, cliVersion, drifted) {
|
|
1089
|
-
const dirs = drifted.map(({ dir }) =>
|
|
1466
|
+
const dirs = drifted.map(({ dir }) => path7.relative(repoRoot, dir).split(path7.sep).join("/")).join(", ");
|
|
1090
1467
|
const installed = [...new Set(drifted.map((entry) => entry.installed ?? "unknown"))].join(", ");
|
|
1091
1468
|
return `roadmap-progress skill is outdated in ${dirs} (installed ${installed}, CLI ${cliVersion}). Run \`nolto init\` in this repo to update it.`;
|
|
1092
1469
|
}
|
|
1093
1470
|
async function installSkill(args) {
|
|
1094
|
-
const targetDir =
|
|
1095
|
-
const markerPath =
|
|
1471
|
+
const targetDir = path7.join(args.skillsParentDir, "roadmap-progress");
|
|
1472
|
+
const markerPath = path7.join(targetDir, VERSION_MARKER);
|
|
1096
1473
|
const dirExists = existsSync(targetDir);
|
|
1097
1474
|
let installedVersion = null;
|
|
1098
1475
|
if (dirExists) {
|
|
1099
1476
|
try {
|
|
1100
|
-
installedVersion = (await
|
|
1477
|
+
installedVersion = (await readFile5(markerPath, "utf8")).trim();
|
|
1101
1478
|
} catch {
|
|
1102
1479
|
installedVersion = null;
|
|
1103
1480
|
}
|
|
@@ -1105,30 +1482,30 @@ async function installSkill(args) {
|
|
|
1105
1482
|
if (dirExists && installedVersion === args.version && args.force !== true) {
|
|
1106
1483
|
return { action: "skipped", targetDir };
|
|
1107
1484
|
}
|
|
1108
|
-
await
|
|
1485
|
+
await rm2(targetDir, { recursive: true, force: true });
|
|
1109
1486
|
await mkdir4(args.skillsParentDir, { recursive: true });
|
|
1110
1487
|
await cp(args.sourceDir, targetDir, { recursive: true });
|
|
1111
|
-
await
|
|
1488
|
+
await writeFile5(markerPath, args.version + "\n", "utf8");
|
|
1112
1489
|
return { action: dirExists ? "updated" : "installed", targetDir };
|
|
1113
1490
|
}
|
|
1114
1491
|
|
|
1115
1492
|
// src/roadmap-scaffold.ts
|
|
1116
|
-
import { mkdir as mkdir5, readdir, writeFile as
|
|
1493
|
+
import { mkdir as mkdir5, readdir as readdir2, writeFile as writeFile6 } from "fs/promises";
|
|
1117
1494
|
import { existsSync as existsSync2 } from "fs";
|
|
1118
|
-
import
|
|
1495
|
+
import path8 from "path";
|
|
1119
1496
|
function slugifyProjectId(name) {
|
|
1120
1497
|
const slug = name.toLowerCase().replace(/[^a-z0-9.-]+/g, "-").replace(/^[^a-z0-9]+/, "").replace(/[-_.]+$/, "");
|
|
1121
1498
|
return slug.length > 0 ? slug : "project";
|
|
1122
1499
|
}
|
|
1123
1500
|
async function scaffoldRoadmap(args) {
|
|
1124
|
-
const repoBasename =
|
|
1125
|
-
const dir =
|
|
1126
|
-
const filePath =
|
|
1127
|
-
const legacyPath =
|
|
1501
|
+
const repoBasename = path8.basename(args.repoRoot);
|
|
1502
|
+
const dir = path8.join(args.repoRoot, ".nolto", "roadmaps");
|
|
1503
|
+
const filePath = path8.join(dir, `${slugifyProjectId(repoBasename)}.json`);
|
|
1504
|
+
const legacyPath = path8.join(args.repoRoot, ".roadmap", "roadmap.json");
|
|
1128
1505
|
try {
|
|
1129
|
-
const existing = (await
|
|
1506
|
+
const existing = (await readdir2(dir)).sort();
|
|
1130
1507
|
if (existing.length > 0) {
|
|
1131
|
-
return { created: false, path:
|
|
1508
|
+
return { created: false, path: path8.join(dir, existing[0]) };
|
|
1132
1509
|
}
|
|
1133
1510
|
} catch (err) {
|
|
1134
1511
|
if (err == null || typeof err !== "object" || !("code" in err) || err.code !== "ENOENT") {
|
|
@@ -1151,28 +1528,28 @@ async function scaffoldRoadmap(args) {
|
|
|
1151
1528
|
phases: []
|
|
1152
1529
|
};
|
|
1153
1530
|
await mkdir5(dir, { recursive: true });
|
|
1154
|
-
await
|
|
1531
|
+
await writeFile6(filePath, JSON.stringify(roadmap, null, 2) + "\n", "utf8");
|
|
1155
1532
|
return { created: true, path: filePath };
|
|
1156
1533
|
}
|
|
1157
1534
|
|
|
1158
1535
|
// src/git-merge-driver.ts
|
|
1159
1536
|
import { execFile as execFile2 } from "child_process";
|
|
1160
|
-
import { readFile as
|
|
1161
|
-
import
|
|
1537
|
+
import { readFile as readFile6, writeFile as writeFile7 } from "fs/promises";
|
|
1538
|
+
import path9 from "path";
|
|
1162
1539
|
import { promisify } from "util";
|
|
1163
1540
|
var ATTRIBUTE_LINE = ".nolto/roadmaps/*.json merge=nolto-roadmap";
|
|
1164
1541
|
var DRIVER_COMMAND = "nolto merge-file %A %B --base %O";
|
|
1165
1542
|
async function ensureGitAttributes(root) {
|
|
1166
|
-
const filePath =
|
|
1543
|
+
const filePath = path9.join(root, ".gitattributes");
|
|
1167
1544
|
let content = "";
|
|
1168
1545
|
try {
|
|
1169
|
-
content = await
|
|
1546
|
+
content = await readFile6(filePath, "utf8");
|
|
1170
1547
|
} catch (err) {
|
|
1171
1548
|
if (err.code !== "ENOENT") throw err;
|
|
1172
1549
|
}
|
|
1173
1550
|
if (content.split(/\r?\n/).includes(ATTRIBUTE_LINE)) return "exists";
|
|
1174
1551
|
const separator = content.length > 0 && !content.endsWith("\n") ? "\n" : "";
|
|
1175
|
-
await
|
|
1552
|
+
await writeFile7(filePath, content + separator + ATTRIBUTE_LINE + "\n", "utf8");
|
|
1176
1553
|
return "added";
|
|
1177
1554
|
}
|
|
1178
1555
|
async function configureMergeDriver(root, exec = async (file, args, options) => {
|
|
@@ -1197,13 +1574,13 @@ async function configureMergeDriver(root, exec = async (file, args, options) =>
|
|
|
1197
1574
|
}
|
|
1198
1575
|
|
|
1199
1576
|
// src/commands/init.ts
|
|
1200
|
-
var __dirname2 =
|
|
1577
|
+
var __dirname2 = path10.dirname(fileURLToPath2(import.meta.url));
|
|
1201
1578
|
var _require = createRequire(import.meta.url);
|
|
1202
1579
|
function getCliVersion() {
|
|
1203
1580
|
const candidates = [
|
|
1204
|
-
|
|
1581
|
+
path10.resolve(__dirname2, "../package.json"),
|
|
1205
1582
|
// bundled: dist/../package.json
|
|
1206
|
-
|
|
1583
|
+
path10.resolve(__dirname2, "../../package.json")
|
|
1207
1584
|
// source: src/commands/../../package.json
|
|
1208
1585
|
];
|
|
1209
1586
|
for (const pkgPath of candidates) {
|
|
@@ -1272,7 +1649,7 @@ async function selectRepoProject(rl, http, projects, defaultProjectId) {
|
|
|
1272
1649
|
"Project number for this repository, 'c' to create new (or Enter to skip): "
|
|
1273
1650
|
);
|
|
1274
1651
|
}
|
|
1275
|
-
function
|
|
1652
|
+
function register3(program, deps) {
|
|
1276
1653
|
program.command("init").description("Interactive setup: configure token, base URL, and default project.").option("--force", "Overwrite existing config without prompting").action(async (opts) => {
|
|
1277
1654
|
const configPath = deps.configPath;
|
|
1278
1655
|
const rl = readline2.createInterface({ input: process.stdin, output: process.stdout });
|
|
@@ -1364,7 +1741,7 @@ Saved ${configPath}
|
|
|
1364
1741
|
}
|
|
1365
1742
|
if (isHomeDirectory(root)) {
|
|
1366
1743
|
process.stderr.write(
|
|
1367
|
-
`Refusing to set up your home directory as a repository root (found ${
|
|
1744
|
+
`Refusing to set up your home directory as a repository root (found ${path10.join(os3.homedir(), ".git")}). Run nolto init inside a project repository.
|
|
1368
1745
|
`
|
|
1369
1746
|
);
|
|
1370
1747
|
return;
|
|
@@ -1396,7 +1773,7 @@ Saved ${configPath}
|
|
|
1396
1773
|
boundProject != null ? "Keep this binding? [Y/n] " : "Keep this binding? [y/N] "
|
|
1397
1774
|
);
|
|
1398
1775
|
keepExistingBinding = boundProject != null ? keep.trim().toLowerCase() !== "n" : keep.trim().toLowerCase() === "y";
|
|
1399
|
-
repoProject = keepExistingBinding ? boundProject ?? { id: existingBinding.projectId, name:
|
|
1776
|
+
repoProject = keepExistingBinding ? boundProject ?? { id: existingBinding.projectId, name: path10.basename(root) } : await selectRepoProject(rl, repoHttp, projects, defaultProjectId);
|
|
1400
1777
|
} else {
|
|
1401
1778
|
repoProject = await selectRepoProject(rl, repoHttp, projects, defaultProjectId);
|
|
1402
1779
|
}
|
|
@@ -1410,7 +1787,7 @@ Set up this repository (${root}) for roadmap sync? [Y/n] `);
|
|
|
1410
1787
|
process.stdout.write("Skipped repo setup.\n");
|
|
1411
1788
|
return;
|
|
1412
1789
|
}
|
|
1413
|
-
const bindingPath = deps.repoBinding?.path ??
|
|
1790
|
+
const bindingPath = deps.repoBinding?.path ?? path10.join(root, "nolto.json");
|
|
1414
1791
|
if (keepExistingBinding) {
|
|
1415
1792
|
process.stdout.write(`binding: kept ${bindingPath} (${repoProject.id})
|
|
1416
1793
|
`);
|
|
@@ -1422,22 +1799,22 @@ Set up this repository (${root}) for roadmap sync? [Y/n] `);
|
|
|
1422
1799
|
);
|
|
1423
1800
|
}
|
|
1424
1801
|
await writeRepoBinding(root, repoProject.id);
|
|
1425
|
-
process.stdout.write(`binding: wrote ${
|
|
1802
|
+
process.stdout.write(`binding: wrote ${path10.join(root, "nolto.json")}
|
|
1426
1803
|
`);
|
|
1427
1804
|
}
|
|
1428
1805
|
const sourceDir = resolveSkillSourceDir();
|
|
1429
1806
|
const version = getCliVersion();
|
|
1430
1807
|
const claudeInstall = await installSkill({
|
|
1431
|
-
skillsParentDir:
|
|
1808
|
+
skillsParentDir: path10.join(root, ".claude", "skills"),
|
|
1432
1809
|
sourceDir,
|
|
1433
1810
|
version
|
|
1434
1811
|
});
|
|
1435
1812
|
process.stdout.write(`skill (claude): ${claudeInstall.action} ${claudeInstall.targetDir}
|
|
1436
1813
|
`);
|
|
1437
|
-
const usesAgentsTooling = fs.existsSync(
|
|
1814
|
+
const usesAgentsTooling = fs.existsSync(path10.join(root, ".agents")) || fs.existsSync(path10.join(root, ".codex")) || fs.existsSync(path10.join(root, "AGENTS.md"));
|
|
1438
1815
|
if (usesAgentsTooling) {
|
|
1439
1816
|
const agentsInstall = await installSkill({
|
|
1440
|
-
skillsParentDir:
|
|
1817
|
+
skillsParentDir: path10.join(root, ".agents", "skills"),
|
|
1441
1818
|
sourceDir,
|
|
1442
1819
|
version
|
|
1443
1820
|
});
|
|
@@ -1550,7 +1927,7 @@ function sleep(ms) {
|
|
|
1550
1927
|
}
|
|
1551
1928
|
|
|
1552
1929
|
// src/commands/login.ts
|
|
1553
|
-
function
|
|
1930
|
+
function register4(program, deps) {
|
|
1554
1931
|
program.command("login").description("Authenticate via browser and save an API token to the config file.").option("--force", "Overwrite existing token without prompting").action(
|
|
1555
1932
|
async (opts) => {
|
|
1556
1933
|
const { configPath, settings, output } = deps;
|
|
@@ -1632,10 +2009,11 @@ function register3(program, deps) {
|
|
|
1632
2009
|
}
|
|
1633
2010
|
|
|
1634
2011
|
// src/commands/whoami.ts
|
|
1635
|
-
function
|
|
2012
|
+
function register5(program, deps) {
|
|
1636
2013
|
program.command("whoami").description("Show the current authentication and configuration state.").action(async () => {
|
|
1637
2014
|
const { settings, output, configPath } = deps;
|
|
1638
2015
|
const mode2 = output.mode;
|
|
2016
|
+
let tokenInfo;
|
|
1639
2017
|
let projectCount;
|
|
1640
2018
|
if (settings.token != null) {
|
|
1641
2019
|
try {
|
|
@@ -1649,6 +2027,13 @@ function register4(program, deps) {
|
|
|
1649
2027
|
} catch {
|
|
1650
2028
|
}
|
|
1651
2029
|
}
|
|
2030
|
+
if (settings.token != null) {
|
|
2031
|
+
try {
|
|
2032
|
+
const result = await deps.http.get("/api/me/token");
|
|
2033
|
+
tokenInfo = result.token;
|
|
2034
|
+
} catch {
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
1652
2037
|
const projectBindingPath = deps.repoBinding?.path ?? deps.projectBindingPath ?? null;
|
|
1653
2038
|
if (mode2 === "json") {
|
|
1654
2039
|
printResult(
|
|
@@ -1661,7 +2046,8 @@ function register4(program, deps) {
|
|
|
1661
2046
|
defaultProject: settings.defaultProjectId ?? null,
|
|
1662
2047
|
defaultProjectSource: settings.source.project,
|
|
1663
2048
|
projectBindingPath: projectBindingPath ?? null,
|
|
1664
|
-
projects: projectCount ?? null
|
|
2049
|
+
projects: projectCount ?? null,
|
|
2050
|
+
...tokenInfo ? { tokenScopes: tokenInfo.scopes, tokenProject: tokenInfo.projectId } : {}
|
|
1665
2051
|
},
|
|
1666
2052
|
mode2
|
|
1667
2053
|
);
|
|
@@ -1675,6 +2061,9 @@ function register4(program, deps) {
|
|
|
1675
2061
|
["defaultProject", bindingDisplay],
|
|
1676
2062
|
["projects", projectCount != null ? String(projectCount) : settings.token != null ? "(unavailable)" : "(no token)"]
|
|
1677
2063
|
];
|
|
2064
|
+
if (tokenInfo) {
|
|
2065
|
+
lines.push(["scopes", tokenInfo.scopes === null ? "full" : tokenInfo.scopes.join(", ")], ["project", tokenInfo.projectId ?? "all"]);
|
|
2066
|
+
}
|
|
1678
2067
|
const maxKey = lines.reduce((m, [k]) => Math.max(m, k.length), 0);
|
|
1679
2068
|
for (const [key, val] of lines) {
|
|
1680
2069
|
process.stdout.write(`${key.padEnd(maxKey)}: ${val}
|
|
@@ -1685,15 +2074,64 @@ function register4(program, deps) {
|
|
|
1685
2074
|
}
|
|
1686
2075
|
|
|
1687
2076
|
// src/commands/sync.ts
|
|
1688
|
-
import {
|
|
2077
|
+
import { execFile as execFile3 } from "child_process";
|
|
2078
|
+
import { promisify as promisify2 } from "util";
|
|
2079
|
+
import { copyFile, mkdir as mkdir6, readFile as readFile7, readdir as readdir3, realpath, rename as rename3, rmdir, unlink as unlink2 } from "fs/promises";
|
|
1689
2080
|
import { existsSync as existsSync3 } from "fs";
|
|
1690
2081
|
|
|
2082
|
+
// src/git-links.ts
|
|
2083
|
+
function parseGitLog(raw) {
|
|
2084
|
+
return raw.split("\n").filter((line) => line.length > 0).map((line) => {
|
|
2085
|
+
const fields = line.replace(/\r$/, "").split("");
|
|
2086
|
+
const [ref, subject, author, committedAt] = fields;
|
|
2087
|
+
if (fields.length !== 4 || !ref || !/^[0-9a-f]{40}$/.test(ref) || subject === void 0 || author === void 0 || !committedAt || !Number.isFinite(Date.parse(committedAt))) {
|
|
2088
|
+
throw new Error("Malformed git log entry");
|
|
2089
|
+
}
|
|
2090
|
+
return { ref, subject, author, committedAt: new Date(committedAt).toISOString() };
|
|
2091
|
+
});
|
|
2092
|
+
}
|
|
2093
|
+
function extractIssueKeys(subject) {
|
|
2094
|
+
return [...new Set([...subject.matchAll(/\b([A-Z][A-Z0-9]{1,9})-([1-9][0-9]{0,8})\b/g)].map((match) => match[0]))];
|
|
2095
|
+
}
|
|
2096
|
+
function extractPrNumber(subject) {
|
|
2097
|
+
return /\(#([1-9][0-9]{0,8})\)$/.exec(subject)?.[1] ?? /^Merge pull request #([1-9][0-9]{0,8})\b/.exec(subject)?.[1] ?? null;
|
|
2098
|
+
}
|
|
2099
|
+
function buildGitLinksPayload(entries) {
|
|
2100
|
+
return { links: entries.flatMap((entry) => {
|
|
2101
|
+
const keys = extractIssueKeys(entry.subject);
|
|
2102
|
+
const pr = extractPrNumber(entry.subject);
|
|
2103
|
+
const refs = [{ kind: "commit", ref: entry.ref }, ...pr ? [{ kind: "pr", ref: pr }] : []];
|
|
2104
|
+
return refs.flatMap((ref) => Array.from({ length: Math.ceil(keys.length / 20) }, (_, index) => ({
|
|
2105
|
+
...ref,
|
|
2106
|
+
title: entry.subject.slice(0, 500),
|
|
2107
|
+
author: entry.author.slice(0, 500),
|
|
2108
|
+
committedAt: entry.committedAt,
|
|
2109
|
+
issueKeys: keys.slice(index * 20, (index + 1) * 20)
|
|
2110
|
+
})));
|
|
2111
|
+
}) };
|
|
2112
|
+
}
|
|
2113
|
+
function stdout(result) {
|
|
2114
|
+
if (typeof result === "object" && result !== null && "stdout" in result && typeof result.stdout === "string") return result.stdout;
|
|
2115
|
+
throw new Error("Git command returned no text output");
|
|
2116
|
+
}
|
|
2117
|
+
async function collectGitLinks(root, exec) {
|
|
2118
|
+
let probe;
|
|
2119
|
+
try {
|
|
2120
|
+
probe = await exec("git", ["rev-parse", "--is-inside-work-tree"], { cwd: root });
|
|
2121
|
+
} catch {
|
|
2122
|
+
return null;
|
|
2123
|
+
}
|
|
2124
|
+
if (stdout(probe).trim() !== "true") return null;
|
|
2125
|
+
const result = await exec("git", ["log", "--no-color", "--format=%H%x1f%s%x1f%an%x1f%cI", "-n", "300"], { cwd: root });
|
|
2126
|
+
return buildGitLinksPayload(parseGitLog(stdout(result)));
|
|
2127
|
+
}
|
|
2128
|
+
|
|
1691
2129
|
// src/sync-repo.ts
|
|
1692
|
-
import
|
|
2130
|
+
import path12 from "path";
|
|
1693
2131
|
|
|
1694
2132
|
// src/sync-core.ts
|
|
1695
2133
|
import { createHash } from "crypto";
|
|
1696
|
-
import
|
|
2134
|
+
import path11 from "path";
|
|
1697
2135
|
function sha256Hex(content) {
|
|
1698
2136
|
return "sha256:" + createHash("sha256").update(content, "utf8").digest("hex");
|
|
1699
2137
|
}
|
|
@@ -1714,10 +2152,10 @@ function collectPlanRefs(roadmap) {
|
|
|
1714
2152
|
}
|
|
1715
2153
|
return refs;
|
|
1716
2154
|
}
|
|
1717
|
-
async function loadValidRoadmap(filePath,
|
|
2155
|
+
async function loadValidRoadmap(filePath, readFile13) {
|
|
1718
2156
|
let raw;
|
|
1719
2157
|
try {
|
|
1720
|
-
raw = await
|
|
2158
|
+
raw = await readFile13(filePath);
|
|
1721
2159
|
} catch {
|
|
1722
2160
|
throw new CliError(`No roadmap found at ${filePath}. Run \`nolto init\` first.`, 2);
|
|
1723
2161
|
}
|
|
@@ -1740,9 +2178,9 @@ async function loadValidRoadmap(filePath, readFile12) {
|
|
|
1740
2178
|
async function buildSyncBody(args) {
|
|
1741
2179
|
const planDocuments = [];
|
|
1742
2180
|
for (const ref of collectPlanRefs(args.roadmap)) {
|
|
1743
|
-
const root =
|
|
1744
|
-
const absolute =
|
|
1745
|
-
if (absolute !== root && !absolute.startsWith(root +
|
|
2181
|
+
const root = path11.resolve(args.repoRoot);
|
|
2182
|
+
const absolute = path11.resolve(root, ref.path);
|
|
2183
|
+
if (absolute !== root && !absolute.startsWith(root + path11.sep)) {
|
|
1746
2184
|
args.deps.warn(`plan path outside repository root, skipping: ${ref.path}`);
|
|
1747
2185
|
continue;
|
|
1748
2186
|
}
|
|
@@ -1760,7 +2198,7 @@ async function buildSyncBody(args) {
|
|
|
1760
2198
|
args.deps.warn(`plan file not found, skipping: ${ref.path}`);
|
|
1761
2199
|
continue;
|
|
1762
2200
|
}
|
|
1763
|
-
if (real !== realRoot && !real.startsWith(realRoot +
|
|
2201
|
+
if (real !== realRoot && !real.startsWith(realRoot + path11.sep)) {
|
|
1764
2202
|
args.deps.warn(`symlink escapes repository root, skipping: ${ref.path}`);
|
|
1765
2203
|
continue;
|
|
1766
2204
|
}
|
|
@@ -1786,9 +2224,10 @@ async function runSync(args, deps) {
|
|
|
1786
2224
|
`/api/projects/${args.projectId}/roadmaps/${args.slug}`,
|
|
1787
2225
|
body
|
|
1788
2226
|
);
|
|
2227
|
+
for (const warning of response.warnings ?? []) deps.warn(warning);
|
|
1789
2228
|
const stats = deriveTaskStats(args.roadmap);
|
|
1790
2229
|
deps.log(
|
|
1791
|
-
`Synced ${args.slug}: ${stats.done}/${stats.total} done \u2014 docs upserted ${response.documents.upserted}, unchanged ${response.documents.unchanged}, deleted ${response.documents.deleted}`
|
|
2230
|
+
`Synced ${args.slug}: ${stats.done}/${stats.total} done \u2014 docs upserted ${response.documents.upserted}, unchanged ${response.documents.unchanged}, deleted ${response.documents.deleted}${response.issues ? `, issues linked ${response.issues.linked} (skipped ${response.issues.skipped})` : ""}`
|
|
1792
2231
|
);
|
|
1793
2232
|
return response;
|
|
1794
2233
|
}
|
|
@@ -1797,11 +2236,11 @@ async function runSync(args, deps) {
|
|
|
1797
2236
|
var ROADMAP_SLUG_PATTERN = /^[a-z0-9][a-z0-9._-]*$/;
|
|
1798
2237
|
function collectContainedPlanAbsPaths(roadmaps, root, warn) {
|
|
1799
2238
|
const planAbsPaths = /* @__PURE__ */ new Set();
|
|
1800
|
-
const resolvedRoot =
|
|
2239
|
+
const resolvedRoot = path12.resolve(root);
|
|
1801
2240
|
for (const roadmap of roadmaps) {
|
|
1802
2241
|
for (const ref of collectPlanRefs(roadmap)) {
|
|
1803
|
-
const absolute =
|
|
1804
|
-
if (absolute !== resolvedRoot && !absolute.startsWith(resolvedRoot +
|
|
2242
|
+
const absolute = path12.resolve(resolvedRoot, ref.path);
|
|
2243
|
+
if (absolute !== resolvedRoot && !absolute.startsWith(resolvedRoot + path12.sep)) {
|
|
1805
2244
|
warn(`chokidar target outside repo, skipping: ${ref.path}`);
|
|
1806
2245
|
continue;
|
|
1807
2246
|
}
|
|
@@ -1822,7 +2261,7 @@ async function listRoadmapFiles(roadmapsDir, io) {
|
|
|
1822
2261
|
}
|
|
1823
2262
|
}
|
|
1824
2263
|
async function migrateLegacyRoadmap(args) {
|
|
1825
|
-
const targetPath =
|
|
2264
|
+
const targetPath = path12.join(args.roadmapsDir, `${args.slug}.json`);
|
|
1826
2265
|
await args.io.mkdir(args.roadmapsDir);
|
|
1827
2266
|
try {
|
|
1828
2267
|
await args.io.rename(args.legacyPath, targetPath);
|
|
@@ -1831,7 +2270,7 @@ async function migrateLegacyRoadmap(args) {
|
|
|
1831
2270
|
await args.io.unlink(args.legacyPath);
|
|
1832
2271
|
}
|
|
1833
2272
|
try {
|
|
1834
|
-
await args.io.rmdir(
|
|
2273
|
+
await args.io.rmdir(path12.dirname(args.legacyPath));
|
|
1835
2274
|
} catch {
|
|
1836
2275
|
}
|
|
1837
2276
|
args.io.log(
|
|
@@ -1840,14 +2279,14 @@ async function migrateLegacyRoadmap(args) {
|
|
|
1840
2279
|
return `${args.slug}.json`;
|
|
1841
2280
|
}
|
|
1842
2281
|
async function syncRepo(args, io) {
|
|
1843
|
-
const bindingPath =
|
|
2282
|
+
const bindingPath = path12.join(args.root, "nolto.json");
|
|
1844
2283
|
const binding = await loadRepoBinding(bindingPath);
|
|
1845
2284
|
const projectId = binding?.projectId ?? args.defaultProjectId;
|
|
1846
2285
|
if (projectId == null) {
|
|
1847
2286
|
throw new CliError("No project binding. Run `nolto init` or `nolto link <projectId>`.", 2);
|
|
1848
2287
|
}
|
|
1849
|
-
const roadmapsDir =
|
|
1850
|
-
const legacyPath =
|
|
2288
|
+
const roadmapsDir = path12.join(args.root, ".nolto", "roadmaps");
|
|
2289
|
+
const legacyPath = path12.join(args.root, ".roadmap", "roadmap.json");
|
|
1851
2290
|
let roadmapFiles = await listRoadmapFiles(roadmapsDir, io);
|
|
1852
2291
|
if (roadmapFiles.length > 0) {
|
|
1853
2292
|
if (io.fileExists(legacyPath)) {
|
|
@@ -1862,7 +2301,7 @@ async function syncRepo(args, io) {
|
|
|
1862
2301
|
);
|
|
1863
2302
|
return { results: [], planAbsPaths: [] };
|
|
1864
2303
|
}
|
|
1865
|
-
const migrationSlug = binding?.roadmapSlug ?? slugifyProjectId(
|
|
2304
|
+
const migrationSlug = binding?.roadmapSlug ?? slugifyProjectId(path12.basename(args.root));
|
|
1866
2305
|
roadmapFiles = [
|
|
1867
2306
|
await migrateLegacyRoadmap({
|
|
1868
2307
|
slug: migrationSlug,
|
|
@@ -1886,7 +2325,7 @@ async function syncRepo(args, io) {
|
|
|
1886
2325
|
2
|
|
1887
2326
|
);
|
|
1888
2327
|
}
|
|
1889
|
-
const filePath =
|
|
2328
|
+
const filePath = path12.join(roadmapsDir, fileName);
|
|
1890
2329
|
return { slug, roadmap: await loadValidRoadmap(filePath, io.readFile) };
|
|
1891
2330
|
})
|
|
1892
2331
|
);
|
|
@@ -1912,12 +2351,34 @@ async function syncRepo(args, io) {
|
|
|
1912
2351
|
)
|
|
1913
2352
|
);
|
|
1914
2353
|
}
|
|
1915
|
-
|
|
2354
|
+
let gitLinks = null;
|
|
2355
|
+
if (io.exec && io.gitLinks !== false) {
|
|
2356
|
+
try {
|
|
2357
|
+
const body = await collectGitLinks(args.root, io.exec);
|
|
2358
|
+
if (body && body.links.length > 0) {
|
|
2359
|
+
gitLinks = { linked: 0, existing: 0, skipped: 0 };
|
|
2360
|
+
for (let offset = 0; offset < body.links.length; offset += 500) {
|
|
2361
|
+
const response = await io.http.post(
|
|
2362
|
+
`/api/projects/${projectId}/git-links`,
|
|
2363
|
+
{ links: body.links.slice(offset, offset + 500) }
|
|
2364
|
+
);
|
|
2365
|
+
if (!Number.isSafeInteger(response.linked) || response.linked < 0 || !Number.isSafeInteger(response.existing) || response.existing < 0 || !Number.isSafeInteger(response.skipped) || response.skipped < 0 || !Array.isArray(response.warnings) || response.warnings.some((warning) => typeof warning !== "string")) throw new Error("Invalid git links response");
|
|
2366
|
+
gitLinks = { linked: gitLinks.linked + response.linked, existing: gitLinks.existing + response.existing, skipped: gitLinks.skipped + response.skipped };
|
|
2367
|
+
for (const warning of response.warnings) io.warn(`git links: ${warning}`);
|
|
2368
|
+
}
|
|
2369
|
+
io.log(`git links: linked ${gitLinks.linked} (existing ${gitLinks.existing}, skipped ${gitLinks.skipped})`);
|
|
2370
|
+
}
|
|
2371
|
+
} catch (error) {
|
|
2372
|
+
gitLinks = null;
|
|
2373
|
+
io.warn(`git links: skipped \u2014 ${error instanceof Error ? error.message : String(error)}`);
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
return { results, planAbsPaths, gitLinks };
|
|
1916
2377
|
}
|
|
1917
2378
|
|
|
1918
2379
|
// src/commands/sync.ts
|
|
1919
|
-
function
|
|
1920
|
-
program.command("sync").description("Push .nolto/roadmaps/*.json and linked plan documents to Nolto (idempotent full upsert).").action(async () => {
|
|
2380
|
+
function register6(program, deps) {
|
|
2381
|
+
program.command("sync").description("Push .nolto/roadmaps/*.json and linked plan documents to Nolto (idempotent full upsert).").option("--no-git-links", "Skip commit / PR issue links").action(async (opts) => {
|
|
1921
2382
|
if (deps.settings.token == null) {
|
|
1922
2383
|
throw new CliError("Not authenticated. Run `nolto login` or set NOLTO_TOKEN.", 3);
|
|
1923
2384
|
}
|
|
@@ -1933,18 +2394,22 @@ function register5(program, deps) {
|
|
|
1933
2394
|
const response = await syncRepo(
|
|
1934
2395
|
{ root, defaultProjectId: deps.settings.defaultProjectId, migrateLegacy: true },
|
|
1935
2396
|
{
|
|
1936
|
-
readFile: (p) =>
|
|
2397
|
+
readFile: (p) => readFile7(p, "utf8"),
|
|
1937
2398
|
realpath: (p) => realpath(p),
|
|
1938
2399
|
fileExists: (p) => existsSync3(p),
|
|
1939
|
-
listDir: (p) =>
|
|
1940
|
-
rename:
|
|
2400
|
+
listDir: (p) => readdir3(p),
|
|
2401
|
+
rename: rename3,
|
|
1941
2402
|
copyFile,
|
|
1942
2403
|
mkdir: (p) => mkdir6(p, { recursive: true }).then(() => void 0),
|
|
1943
2404
|
unlink: unlink2,
|
|
1944
2405
|
rmdir,
|
|
1945
2406
|
repoIdentity: makeRepoIdentityResolver(deps),
|
|
2407
|
+
exec: promisify2(execFile3),
|
|
2408
|
+
gitLinks: opts.gitLinks && process.env.NOLTO_GIT_LINKS !== "0",
|
|
1946
2409
|
http,
|
|
1947
|
-
log: (line) =>
|
|
2410
|
+
log: (line) => {
|
|
2411
|
+
if (deps.output.mode !== "json") process.stdout.write(line + "\n");
|
|
2412
|
+
},
|
|
1948
2413
|
warn
|
|
1949
2414
|
}
|
|
1950
2415
|
);
|
|
@@ -1979,8 +2444,8 @@ function register5(program, deps) {
|
|
|
1979
2444
|
}
|
|
1980
2445
|
|
|
1981
2446
|
// src/commands/diff.ts
|
|
1982
|
-
import { readFile as
|
|
1983
|
-
import
|
|
2447
|
+
import { readFile as readFile8 } from "fs/promises";
|
|
2448
|
+
import path14 from "path";
|
|
1984
2449
|
|
|
1985
2450
|
// src/roadmap-diff.ts
|
|
1986
2451
|
function diffRoadmaps(local, server) {
|
|
@@ -2059,8 +2524,8 @@ function diffRoadmaps(local, server) {
|
|
|
2059
2524
|
}
|
|
2060
2525
|
function truncate(value) {
|
|
2061
2526
|
if (value == null) return "none";
|
|
2062
|
-
const
|
|
2063
|
-
return
|
|
2527
|
+
const singleLine2 = value.replace(/\s+/g, " ");
|
|
2528
|
+
return singleLine2.length <= 60 ? singleLine2 : singleLine2.slice(0, 57) + "...";
|
|
2064
2529
|
}
|
|
2065
2530
|
function formatRoadmapDiff(slug, entries) {
|
|
2066
2531
|
if (entries.length === 0) return [];
|
|
@@ -2084,8 +2549,8 @@ function formatRoadmapDiff(slug, entries) {
|
|
|
2084
2549
|
}
|
|
2085
2550
|
|
|
2086
2551
|
// src/roadmap-read.ts
|
|
2087
|
-
import { readdir as
|
|
2088
|
-
import
|
|
2552
|
+
import { readdir as readdir4 } from "fs/promises";
|
|
2553
|
+
import path13 from "path";
|
|
2089
2554
|
async function resolveRoadmapReadContext(deps) {
|
|
2090
2555
|
if (deps.settings.token == null) {
|
|
2091
2556
|
throw new CliError("Not authenticated. Run `nolto login` or set NOLTO_TOKEN.", 3);
|
|
@@ -2095,7 +2560,7 @@ async function resolveRoadmapReadContext(deps) {
|
|
|
2095
2560
|
if (!foundGit) {
|
|
2096
2561
|
throw new CliError("No git repository found. Run inside a repo set up with `nolto init`.", 2);
|
|
2097
2562
|
}
|
|
2098
|
-
const binding = await loadRepoBinding(
|
|
2563
|
+
const binding = await loadRepoBinding(path13.join(root, "nolto.json"));
|
|
2099
2564
|
const projectId = binding?.projectId ?? deps.settings.defaultProjectId;
|
|
2100
2565
|
if (projectId == null) {
|
|
2101
2566
|
throw new CliError("No project binding. Run `nolto init` or `nolto link <projectId>`.", 2);
|
|
@@ -2104,7 +2569,7 @@ async function resolveRoadmapReadContext(deps) {
|
|
|
2104
2569
|
}
|
|
2105
2570
|
async function listLocalRoadmapSlugs(root) {
|
|
2106
2571
|
try {
|
|
2107
|
-
const entries = await
|
|
2572
|
+
const entries = await readdir4(path13.join(root, ".nolto", "roadmaps"));
|
|
2108
2573
|
return entries.filter((entry) => entry.endsWith(".json")).map((entry) => entry.slice(0, -".json".length)).sort();
|
|
2109
2574
|
} catch (err) {
|
|
2110
2575
|
if (err != null && typeof err === "object" && "code" in err && err.code === "ENOENT") {
|
|
@@ -2115,7 +2580,7 @@ async function listLocalRoadmapSlugs(root) {
|
|
|
2115
2580
|
}
|
|
2116
2581
|
|
|
2117
2582
|
// src/commands/diff.ts
|
|
2118
|
-
function
|
|
2583
|
+
function register7(program, deps) {
|
|
2119
2584
|
program.command("diff [slug]").description("Compare local roadmaps with the server without changing either side.").action(async (requestedSlug) => {
|
|
2120
2585
|
const { root, projectId } = await resolveRoadmapReadContext(deps);
|
|
2121
2586
|
const list = await deps.http.get(
|
|
@@ -2136,9 +2601,9 @@ function register6(program, deps) {
|
|
|
2136
2601
|
for (const slug of targetSlugs) {
|
|
2137
2602
|
let local = null;
|
|
2138
2603
|
if (localSlugSet.has(slug)) {
|
|
2139
|
-
const localPath =
|
|
2604
|
+
const localPath = path14.join(root, ".nolto", "roadmaps", `${slug}.json`);
|
|
2140
2605
|
try {
|
|
2141
|
-
local = await loadValidRoadmap(localPath, (filePath) =>
|
|
2606
|
+
local = await loadValidRoadmap(localPath, (filePath) => readFile8(filePath, "utf8"));
|
|
2142
2607
|
} catch (err) {
|
|
2143
2608
|
const message = err instanceof Error ? err.message : String(err);
|
|
2144
2609
|
process.stderr.write(`Warning: could not diff ${slug}.json: ${message}
|
|
@@ -2181,8 +2646,8 @@ function register6(program, deps) {
|
|
|
2181
2646
|
}
|
|
2182
2647
|
|
|
2183
2648
|
// src/commands/pull.ts
|
|
2184
|
-
import { mkdir as mkdir7, readFile as
|
|
2185
|
-
import
|
|
2649
|
+
import { mkdir as mkdir7, readFile as readFile9, writeFile as writeFile8 } from "fs/promises";
|
|
2650
|
+
import path15 from "path";
|
|
2186
2651
|
|
|
2187
2652
|
// src/roadmap-merge.ts
|
|
2188
2653
|
import { isDeepStrictEqual } from "util";
|
|
@@ -2227,6 +2692,7 @@ function assignOptional(target, key, value) {
|
|
|
2227
2692
|
function cloneSingleTask(task) {
|
|
2228
2693
|
const cloned = { ...task };
|
|
2229
2694
|
if (task.dependsOn !== void 0) cloned.dependsOn = [...task.dependsOn];
|
|
2695
|
+
if (task.issues !== void 0) cloned.issues = [...task.issues];
|
|
2230
2696
|
if (cloned.status !== "done") delete cloned.completedAt;
|
|
2231
2697
|
return cloned;
|
|
2232
2698
|
}
|
|
@@ -2275,6 +2741,8 @@ function mergeTask(args) {
|
|
|
2275
2741
|
...args.theirs.dependsOn ?? []
|
|
2276
2742
|
].filter((id, index, values) => values.indexOf(id) === index);
|
|
2277
2743
|
if (dependsOn.length > 0) merged.dependsOn = dependsOn;
|
|
2744
|
+
const issues = [.../* @__PURE__ */ new Set([...args.ours.issues ?? [], ...args.theirs.issues ?? []])];
|
|
2745
|
+
if (issues.length > 0) merged.issues = issues;
|
|
2278
2746
|
return merged;
|
|
2279
2747
|
}
|
|
2280
2748
|
function shouldKeep(base, ours, theirs) {
|
|
@@ -2418,7 +2886,7 @@ function mergeRoadmaps(args) {
|
|
|
2418
2886
|
// src/commands/pull.ts
|
|
2419
2887
|
async function readExisting(filePath) {
|
|
2420
2888
|
try {
|
|
2421
|
-
return await
|
|
2889
|
+
return await readFile9(filePath, "utf8");
|
|
2422
2890
|
} catch (err) {
|
|
2423
2891
|
if (err != null && typeof err === "object" && "code" in err && err.code === "ENOENT") {
|
|
2424
2892
|
return null;
|
|
@@ -2426,7 +2894,7 @@ async function readExisting(filePath) {
|
|
|
2426
2894
|
throw err;
|
|
2427
2895
|
}
|
|
2428
2896
|
}
|
|
2429
|
-
function
|
|
2897
|
+
function register8(program, deps) {
|
|
2430
2898
|
program.command("pull [slug]").description(
|
|
2431
2899
|
"Pull server roadmaps, optionally merging them with valid local copies."
|
|
2432
2900
|
).option("--merge", "Structurally merge server and local roadmap changes").action(async (requestedSlug, opts) => {
|
|
@@ -2439,7 +2907,7 @@ function register7(program, deps) {
|
|
|
2439
2907
|
throw new CliError(`Roadmap "${requestedSlug}" was not found on the server.`, 2);
|
|
2440
2908
|
}
|
|
2441
2909
|
const targets = requestedSlug == null ? [...serverBySlug.values()] : [serverBySlug.get(requestedSlug)];
|
|
2442
|
-
const roadmapsDir =
|
|
2910
|
+
const roadmapsDir = path15.join(root, ".nolto", "roadmaps");
|
|
2443
2911
|
for (const summary of targets) {
|
|
2444
2912
|
const response = await deps.http.get(
|
|
2445
2913
|
`/api/projects/${projectId}/roadmaps/${encodeURIComponent(summary.slug)}`
|
|
@@ -2451,7 +2919,7 @@ function register7(program, deps) {
|
|
|
2451
2919
|
5
|
|
2452
2920
|
);
|
|
2453
2921
|
}
|
|
2454
|
-
const filePath =
|
|
2922
|
+
const filePath = path15.join(roadmapsDir, `${summary.slug}.json`);
|
|
2455
2923
|
const existing = await readExisting(filePath);
|
|
2456
2924
|
let roadmap = response.roadmap;
|
|
2457
2925
|
let outputVerb = "pulled";
|
|
@@ -2488,7 +2956,7 @@ function register7(program, deps) {
|
|
|
2488
2956
|
continue;
|
|
2489
2957
|
}
|
|
2490
2958
|
await mkdir7(roadmapsDir, { recursive: true });
|
|
2491
|
-
await
|
|
2959
|
+
await writeFile8(filePath, serialized, "utf8");
|
|
2492
2960
|
process.stdout.write(
|
|
2493
2961
|
outputVerb === "merged" ? `merged ${summary.slug}.json
|
|
2494
2962
|
` : `pulled ${summary.slug}.json (${summary.taskDone}/${summary.taskTotal} done)
|
|
@@ -2500,9 +2968,11 @@ function register7(program, deps) {
|
|
|
2500
2968
|
}
|
|
2501
2969
|
|
|
2502
2970
|
// src/commands/watch.ts
|
|
2503
|
-
import {
|
|
2971
|
+
import { execFile as execFile4 } from "child_process";
|
|
2972
|
+
import { promisify as promisify3 } from "util";
|
|
2973
|
+
import { copyFile as copyFile2, mkdir as mkdir8, readFile as readFile10, readdir as readdir5, realpath as realpath2, rename as rename4, rmdir as rmdir2, unlink as unlink3 } from "fs/promises";
|
|
2504
2974
|
import { existsSync as existsSync4 } from "fs";
|
|
2505
|
-
import
|
|
2975
|
+
import path17 from "path";
|
|
2506
2976
|
import chokidar from "chokidar";
|
|
2507
2977
|
|
|
2508
2978
|
// src/watch-core.ts
|
|
@@ -2608,7 +3078,7 @@ var RepoWatch = class {
|
|
|
2608
3078
|
};
|
|
2609
3079
|
|
|
2610
3080
|
// src/service-install.ts
|
|
2611
|
-
import
|
|
3081
|
+
import path16 from "path";
|
|
2612
3082
|
import os4 from "os";
|
|
2613
3083
|
function buildUnitFile(args) {
|
|
2614
3084
|
return [
|
|
@@ -2628,8 +3098,8 @@ function buildUnitFile(args) {
|
|
|
2628
3098
|
}
|
|
2629
3099
|
function getUnitPath(env) {
|
|
2630
3100
|
const xdg = env["XDG_CONFIG_HOME"];
|
|
2631
|
-
const base = xdg != null && xdg.length > 0 ? xdg :
|
|
2632
|
-
return
|
|
3101
|
+
const base = xdg != null && xdg.length > 0 ? xdg : path16.join(os4.homedir(), ".config");
|
|
3102
|
+
return path16.join(base, "systemd", "user", "nolto-watch.service");
|
|
2633
3103
|
}
|
|
2634
3104
|
async function installServiceWith(deps) {
|
|
2635
3105
|
if (deps.platform !== "linux") {
|
|
@@ -2640,7 +3110,7 @@ async function installServiceWith(deps) {
|
|
|
2640
3110
|
);
|
|
2641
3111
|
}
|
|
2642
3112
|
const unitPath = getUnitPath(deps.env);
|
|
2643
|
-
await deps.mkdir(
|
|
3113
|
+
await deps.mkdir(path16.dirname(unitPath));
|
|
2644
3114
|
await deps.writeFile(unitPath, buildUnitFile({ nodePath: deps.nodePath, scriptPath: deps.scriptPath }));
|
|
2645
3115
|
deps.log(`Wrote ${unitPath}`);
|
|
2646
3116
|
const reload = await deps.exec(["systemctl", "--user", "daemon-reload"]);
|
|
@@ -2654,16 +3124,16 @@ async function installServiceWith(deps) {
|
|
|
2654
3124
|
deps.log("Service nolto-watch enabled and started. Logs: journalctl --user -u nolto-watch -f");
|
|
2655
3125
|
}
|
|
2656
3126
|
async function installService() {
|
|
2657
|
-
const { writeFile:
|
|
2658
|
-
const { execFile:
|
|
2659
|
-
const { promisify:
|
|
2660
|
-
const execFileAsync =
|
|
3127
|
+
const { writeFile: writeFile11, mkdir: mkdir10 } = await import("fs/promises");
|
|
3128
|
+
const { execFile: execFile6 } = await import("child_process");
|
|
3129
|
+
const { promisify: promisify5 } = await import("util");
|
|
3130
|
+
const execFileAsync = promisify5(execFile6);
|
|
2661
3131
|
await installServiceWith({
|
|
2662
3132
|
platform: process.platform,
|
|
2663
3133
|
env: process.env,
|
|
2664
3134
|
nodePath: process.execPath,
|
|
2665
|
-
scriptPath:
|
|
2666
|
-
writeFile: (p, content) =>
|
|
3135
|
+
scriptPath: path16.resolve(process.argv[1] ?? ""),
|
|
3136
|
+
writeFile: (p, content) => writeFile11(p, content, "utf8"),
|
|
2667
3137
|
mkdir: async (p) => {
|
|
2668
3138
|
await mkdir10(p, { recursive: true });
|
|
2669
3139
|
},
|
|
@@ -2720,9 +3190,9 @@ async function uninstallServiceWith(deps) {
|
|
|
2720
3190
|
}
|
|
2721
3191
|
async function uninstallService() {
|
|
2722
3192
|
const { unlink: unlink4 } = await import("fs/promises");
|
|
2723
|
-
const { execFile:
|
|
2724
|
-
const { promisify:
|
|
2725
|
-
const execFileAsync =
|
|
3193
|
+
const { execFile: execFile6 } = await import("child_process");
|
|
3194
|
+
const { promisify: promisify5 } = await import("util");
|
|
3195
|
+
const execFileAsync = promisify5(execFile6);
|
|
2726
3196
|
await uninstallServiceWith({
|
|
2727
3197
|
platform: process.platform,
|
|
2728
3198
|
env: process.env,
|
|
@@ -2742,7 +3212,7 @@ async function uninstallService() {
|
|
|
2742
3212
|
}
|
|
2743
3213
|
|
|
2744
3214
|
// src/commands/watch.ts
|
|
2745
|
-
function
|
|
3215
|
+
function register9(program, deps) {
|
|
2746
3216
|
program.command("watch").description("Watch every registered repository's roadmap + plan files and sync on change.").option("--debounce <ms>", "Debounce window in milliseconds", "2000").option("--install-service", "Install and enable a systemd user unit (nolto-watch) instead of watching").option("--uninstall-service", "Stop and remove the systemd user unit (nolto-watch) instead of watching").action(async (opts) => {
|
|
2747
3217
|
if (opts.installService && opts.uninstallService) {
|
|
2748
3218
|
throw new CliError("--install-service and --uninstall-service cannot be used together.", 2);
|
|
@@ -2779,10 +3249,10 @@ function register8(program, deps) {
|
|
|
2779
3249
|
token: deps.settings.token
|
|
2780
3250
|
});
|
|
2781
3251
|
const startRepo = (root) => {
|
|
2782
|
-
const roadmapsPath =
|
|
2783
|
-
const legacyRoadmapPath =
|
|
3252
|
+
const roadmapsPath = path17.join(root, ".nolto", "roadmaps");
|
|
3253
|
+
const legacyRoadmapPath = path17.join(root, ".roadmap", "roadmap.json");
|
|
2784
3254
|
const warn = (line) => {
|
|
2785
|
-
process.stderr.write(`Warning: [${
|
|
3255
|
+
process.stderr.write(`Warning: [${path17.basename(root)}] ${line}
|
|
2786
3256
|
`);
|
|
2787
3257
|
};
|
|
2788
3258
|
const watcher = chokidar.watch([roadmapsPath, legacyRoadmapPath], { ignoreInitial: true });
|
|
@@ -2791,18 +3261,20 @@ function register8(program, deps) {
|
|
|
2791
3261
|
// #316: watch must warn about legacy roadmaps without migrating them.
|
|
2792
3262
|
{ root, defaultProjectId: deps.settings.defaultProjectId, migrateLegacy: false },
|
|
2793
3263
|
{
|
|
2794
|
-
readFile: (p) =>
|
|
3264
|
+
readFile: (p) => readFile10(p, "utf8"),
|
|
2795
3265
|
realpath: (p) => realpath2(p),
|
|
2796
3266
|
fileExists: (p) => existsSync4(p),
|
|
2797
|
-
listDir: (p) =>
|
|
2798
|
-
rename:
|
|
3267
|
+
listDir: (p) => readdir5(p),
|
|
3268
|
+
rename: rename4,
|
|
2799
3269
|
copyFile: copyFile2,
|
|
2800
3270
|
mkdir: (p) => mkdir8(p, { recursive: true }).then(() => void 0),
|
|
2801
3271
|
unlink: unlink3,
|
|
2802
3272
|
rmdir: rmdir2,
|
|
2803
3273
|
repoIdentity: makeRepoIdentityResolver(deps),
|
|
3274
|
+
exec: promisify3(execFile4),
|
|
3275
|
+
gitLinks: process.env.NOLTO_GIT_LINKS !== "0",
|
|
2804
3276
|
http,
|
|
2805
|
-
log: (line) => process.stdout.write(`[${
|
|
3277
|
+
log: (line) => process.stdout.write(`[${path17.basename(root)}] ${line}
|
|
2806
3278
|
`),
|
|
2807
3279
|
warn
|
|
2808
3280
|
}
|
|
@@ -2865,18 +3337,18 @@ function register8(program, deps) {
|
|
|
2865
3337
|
}
|
|
2866
3338
|
|
|
2867
3339
|
// src/update-cli.ts
|
|
2868
|
-
import { execFile as
|
|
3340
|
+
import { execFile as execFile5 } from "child_process";
|
|
2869
3341
|
import { existsSync as existsSync5 } from "fs";
|
|
2870
3342
|
import { realpath as realpath3 } from "fs/promises";
|
|
2871
3343
|
import { createRequire as createRequire2 } from "module";
|
|
2872
|
-
import
|
|
3344
|
+
import path19 from "path";
|
|
2873
3345
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
2874
|
-
import { promisify as
|
|
3346
|
+
import { promisify as promisify4 } from "util";
|
|
2875
3347
|
|
|
2876
3348
|
// src/update-notifier.ts
|
|
2877
|
-
import { readFile as
|
|
3349
|
+
import { readFile as readFile11, writeFile as writeFile9, mkdir as mkdir9 } from "fs/promises";
|
|
2878
3350
|
import https from "https";
|
|
2879
|
-
import
|
|
3351
|
+
import path18 from "path";
|
|
2880
3352
|
var PACKAGE = "@nolto/cli";
|
|
2881
3353
|
var CACHE_FILE = "update-check.json";
|
|
2882
3354
|
var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
@@ -2934,9 +3406,9 @@ function fetchLatestFromRegistry(timeoutMs = REQUEST_TIMEOUT_MS, opts = {}) {
|
|
|
2934
3406
|
});
|
|
2935
3407
|
}
|
|
2936
3408
|
async function writeUpdateCache(cachePath, now, latest2) {
|
|
2937
|
-
await mkdir9(
|
|
3409
|
+
await mkdir9(path18.dirname(cachePath), { recursive: true });
|
|
2938
3410
|
const payload = { checkedAt: now, latest: latest2 };
|
|
2939
|
-
await
|
|
3411
|
+
await writeFile9(cachePath, JSON.stringify(payload), { mode: 384 });
|
|
2940
3412
|
}
|
|
2941
3413
|
async function refreshCache(cachePath, now, fetchLatest) {
|
|
2942
3414
|
const latest2 = await fetchLatest();
|
|
@@ -2945,10 +3417,10 @@ async function refreshCache(cachePath, now, fetchLatest) {
|
|
|
2945
3417
|
}
|
|
2946
3418
|
async function checkForUpdate(opts) {
|
|
2947
3419
|
if (isDisabled(opts.env)) return null;
|
|
2948
|
-
const cachePath =
|
|
3420
|
+
const cachePath = path18.join(opts.configDir, CACHE_FILE);
|
|
2949
3421
|
let cache = {};
|
|
2950
3422
|
try {
|
|
2951
|
-
cache = JSON.parse(await
|
|
3423
|
+
cache = JSON.parse(await readFile11(cachePath, "utf8"));
|
|
2952
3424
|
} catch {
|
|
2953
3425
|
}
|
|
2954
3426
|
if (typeof cache.checkedAt !== "number" || opts.now - cache.checkedAt > CACHE_TTL_MS) {
|
|
@@ -3053,7 +3525,7 @@ async function updateCliWith(deps) {
|
|
|
3053
3525
|
}
|
|
3054
3526
|
deps.log(`Updated ${PACKAGE2} ${deps.currentVersion} \u2192 ${latest2}.`);
|
|
3055
3527
|
await deps.writeCache(
|
|
3056
|
-
|
|
3528
|
+
path19.join(deps.configDir, UPDATE_CACHE_FILE),
|
|
3057
3529
|
deps.now,
|
|
3058
3530
|
latest2
|
|
3059
3531
|
).catch(() => void 0);
|
|
@@ -3084,17 +3556,17 @@ async function updateCliWith(deps) {
|
|
|
3084
3556
|
};
|
|
3085
3557
|
}
|
|
3086
3558
|
function getCurrentVersion() {
|
|
3087
|
-
const dirname =
|
|
3559
|
+
const dirname = path19.dirname(fileURLToPath3(import.meta.url));
|
|
3088
3560
|
const require3 = createRequire2(import.meta.url);
|
|
3089
3561
|
try {
|
|
3090
|
-
const pkg = require3(
|
|
3562
|
+
const pkg = require3(path19.resolve(dirname, "../package.json"));
|
|
3091
3563
|
return pkg.version ?? "0.0.0";
|
|
3092
3564
|
} catch {
|
|
3093
3565
|
return "0.0.0";
|
|
3094
3566
|
}
|
|
3095
3567
|
}
|
|
3096
3568
|
async function updateCli(opts = {}) {
|
|
3097
|
-
const execFileAsync =
|
|
3569
|
+
const execFileAsync = promisify4(execFile5);
|
|
3098
3570
|
const scriptPath = await realpath3(process.argv[1] ?? "");
|
|
3099
3571
|
return updateCliWith({
|
|
3100
3572
|
currentVersion: getCurrentVersion(),
|
|
@@ -3126,7 +3598,7 @@ async function updateCli(opts = {}) {
|
|
|
3126
3598
|
}
|
|
3127
3599
|
|
|
3128
3600
|
// src/commands/update.ts
|
|
3129
|
-
function
|
|
3601
|
+
function register10(program, deps) {
|
|
3130
3602
|
program.command("update").description("Update @nolto/cli to the latest version and restart the watch service if installed").action(async () => {
|
|
3131
3603
|
const mode2 = deps.output.mode;
|
|
3132
3604
|
const result = await updateCli({ quiet: mode2 === "json" });
|
|
@@ -3137,11 +3609,11 @@ function register9(program, deps) {
|
|
|
3137
3609
|
}
|
|
3138
3610
|
|
|
3139
3611
|
// src/commands/merge-file.ts
|
|
3140
|
-
import { readFile as
|
|
3612
|
+
import { readFile as readFile12, writeFile as writeFile10 } from "fs/promises";
|
|
3141
3613
|
async function readRoadmap(filePath) {
|
|
3142
3614
|
let parsed;
|
|
3143
3615
|
try {
|
|
3144
|
-
parsed = JSON.parse(await
|
|
3616
|
+
parsed = JSON.parse(await readFile12(filePath, "utf8"));
|
|
3145
3617
|
} catch (err) {
|
|
3146
3618
|
const message = err instanceof SyntaxError ? "malformed JSON" : String(err);
|
|
3147
3619
|
throw new CliError(`${filePath}: ${message}`, 1);
|
|
@@ -3156,7 +3628,7 @@ async function readRoadmap(filePath) {
|
|
|
3156
3628
|
}
|
|
3157
3629
|
return parsed;
|
|
3158
3630
|
}
|
|
3159
|
-
function
|
|
3631
|
+
function register11(program) {
|
|
3160
3632
|
program.command("merge-file <ours> <theirs>").description(
|
|
3161
3633
|
'Structurally merge roadmap files for Git.\ngit config merge.nolto-roadmap.driver "nolto merge-file %A %B --base %O"'
|
|
3162
3634
|
).option("--base <path>", "Common ancestor roadmap file").option("--output <path>", "Write the result here (defaults to <ours>)").action(async (oursPath, theirsPath, opts) => {
|
|
@@ -3164,7 +3636,7 @@ function register10(program) {
|
|
|
3164
3636
|
const theirs = await readRoadmap(theirsPath);
|
|
3165
3637
|
const base = opts.base == null ? null : await readRoadmap(opts.base);
|
|
3166
3638
|
const merged = mergeRoadmaps({ base, ours, theirs });
|
|
3167
|
-
await
|
|
3639
|
+
await writeFile10(
|
|
3168
3640
|
opts.output ?? oursPath,
|
|
3169
3641
|
JSON.stringify(merged, null, 2) + "\n",
|
|
3170
3642
|
"utf8"
|
|
@@ -3184,20 +3656,21 @@ function buildProgram(deps) {
|
|
|
3184
3656
|
const writeErr = (_msg) => {
|
|
3185
3657
|
};
|
|
3186
3658
|
const program = new Command("nolto").version(deps.version, "-V, --version", "Print version number").exitOverride().configureOutput({ writeErr }).description("Nolto CLI \u2014 sync repository roadmaps with Nolto.").option("--token <value>", "API token (overrides env/file)").option("--base-url <url>", "Nolto base URL (default: https://nolto.app)").option("--project <projectId>", "Default project ID").option("--json", "Output as JSON");
|
|
3187
|
-
|
|
3659
|
+
register(program, deps);
|
|
3188
3660
|
register3(program, deps);
|
|
3189
3661
|
register4(program, deps);
|
|
3190
|
-
register(program, deps);
|
|
3191
3662
|
register5(program, deps);
|
|
3663
|
+
register2(program, deps);
|
|
3192
3664
|
register6(program, deps);
|
|
3193
3665
|
register7(program, deps);
|
|
3194
3666
|
register8(program, deps);
|
|
3195
3667
|
register9(program, deps);
|
|
3196
|
-
register10(program);
|
|
3668
|
+
register10(program, deps);
|
|
3669
|
+
register11(program);
|
|
3197
3670
|
program.hook("preAction", (_thisCommand, actionCommand) => {
|
|
3198
3671
|
const bindingError = deps.repoBinding?.error;
|
|
3199
3672
|
const bindingExemptCommands = ["init", "link", "update", "merge-file"];
|
|
3200
|
-
if (bindingError != null && !bindingExemptCommands.includes(actionCommand.name())) {
|
|
3673
|
+
if (bindingError != null && !(actionCommand.parent === program && bindingExemptCommands.includes(actionCommand.name()))) {
|
|
3201
3674
|
throw bindingError;
|
|
3202
3675
|
}
|
|
3203
3676
|
});
|
|
@@ -3205,11 +3678,11 @@ function buildProgram(deps) {
|
|
|
3205
3678
|
}
|
|
3206
3679
|
|
|
3207
3680
|
// src/index.ts
|
|
3208
|
-
var __dirname3 =
|
|
3681
|
+
var __dirname3 = path20.dirname(fileURLToPath4(import.meta.url));
|
|
3209
3682
|
var require2 = createRequire3(import.meta.url);
|
|
3210
3683
|
function getVersion() {
|
|
3211
3684
|
try {
|
|
3212
|
-
const pkgPath =
|
|
3685
|
+
const pkgPath = path20.resolve(__dirname3, "../package.json");
|
|
3213
3686
|
const pkg = require2(pkgPath);
|
|
3214
3687
|
return pkg.version ?? "0.0.0";
|
|
3215
3688
|
} catch {
|