@nolto/cli 0.12.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 +43 -3
- package/dist/index.js +648 -242
- package/dist/skill/roadmap-progress/SKILL.md +18 -2
- package/dist/skill/roadmap-progress/references/issue-cli.md +46 -0
- package/dist/skill/roadmap-progress/references/schema.md +4 -1
- 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,23 +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._-]*$/;
|
|
534
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}$/;
|
|
535
497
|
var ALLOWED_KEYS = {
|
|
536
498
|
roadmap: /* @__PURE__ */ new Set(["schemaVersion", "project", "updatedAt", "currentTaskId", "summary", "phases"]),
|
|
537
499
|
project: /* @__PURE__ */ new Set(["id", "name", "repository"]),
|
|
538
500
|
phase: /* @__PURE__ */ new Set(["id", "title", "status", "plan", "tasks"]),
|
|
539
|
-
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"])
|
|
540
502
|
};
|
|
541
503
|
function isRecord(value) {
|
|
542
504
|
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
@@ -668,6 +630,23 @@ function validateRoadmap(value) {
|
|
|
668
630
|
}
|
|
669
631
|
if (task["status"] === "done" && task["completedAt"] == null) warnings.push(`${taskId} is done without completedAt.`);
|
|
670
632
|
if (task["status"] === "in-progress" && task["startedAt"] == null) warnings.push(`${taskId} is in-progress without startedAt.`);
|
|
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
|
+
}
|
|
671
650
|
if (task["dependsOn"] !== void 0 && !Array.isArray(task["dependsOn"])) {
|
|
672
651
|
errors.push(`${taskAt}.dependsOn must be an array.`);
|
|
673
652
|
} else if (Array.isArray(task["dependsOn"])) {
|
|
@@ -734,10 +713,341 @@ function deriveTaskStats(roadmap) {
|
|
|
734
713
|
};
|
|
735
714
|
}
|
|
736
715
|
|
|
737
|
-
// src/
|
|
738
|
-
|
|
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";
|
|
739
986
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
740
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";
|
|
741
1051
|
var inFlightByConfigDir = /* @__PURE__ */ new Map();
|
|
742
1052
|
function parseMachineId(raw, file) {
|
|
743
1053
|
let parsed;
|
|
@@ -753,10 +1063,10 @@ function parseMachineId(raw, file) {
|
|
|
753
1063
|
return id;
|
|
754
1064
|
}
|
|
755
1065
|
async function loadOrCreate(configDir) {
|
|
756
|
-
const file =
|
|
1066
|
+
const file = path4.join(configDir, "machine.json");
|
|
757
1067
|
let raw = null;
|
|
758
1068
|
try {
|
|
759
|
-
raw = await
|
|
1069
|
+
raw = await readFile4(file, "utf8");
|
|
760
1070
|
} catch (err) {
|
|
761
1071
|
const code = err.code;
|
|
762
1072
|
if (code !== "ENOENT") {
|
|
@@ -766,17 +1076,17 @@ async function loadOrCreate(configDir) {
|
|
|
766
1076
|
if (raw !== null) {
|
|
767
1077
|
return parseMachineId(raw, file);
|
|
768
1078
|
}
|
|
769
|
-
const machineId =
|
|
1079
|
+
const machineId = randomUUID3();
|
|
770
1080
|
await mkdir3(configDir, { recursive: true, mode: 448 });
|
|
771
1081
|
try {
|
|
772
|
-
await
|
|
1082
|
+
await writeFile4(file, `${JSON.stringify({ machineId }, null, 2)}
|
|
773
1083
|
`, {
|
|
774
1084
|
flag: "wx",
|
|
775
1085
|
mode: 384
|
|
776
1086
|
});
|
|
777
1087
|
} catch (err) {
|
|
778
1088
|
if (err.code === "EEXIST") {
|
|
779
|
-
return parseMachineId(await
|
|
1089
|
+
return parseMachineId(await readFile4(file, "utf8"), file);
|
|
780
1090
|
}
|
|
781
1091
|
throw new CliError(`Cannot write ${file}: ${String(err)}`, 2);
|
|
782
1092
|
}
|
|
@@ -784,7 +1094,7 @@ async function loadOrCreate(configDir) {
|
|
|
784
1094
|
return machineId;
|
|
785
1095
|
}
|
|
786
1096
|
function loadOrCreateMachineId(configDir) {
|
|
787
|
-
const key =
|
|
1097
|
+
const key = path4.resolve(configDir);
|
|
788
1098
|
const existing = inFlightByConfigDir.get(key);
|
|
789
1099
|
if (existing !== void 0) return existing;
|
|
790
1100
|
const pending = loadOrCreate(key).finally(() => {
|
|
@@ -801,9 +1111,9 @@ function defaultGetRemoteUrl(root) {
|
|
|
801
1111
|
"git",
|
|
802
1112
|
["-C", root, "remote", "get-url", "origin"],
|
|
803
1113
|
{ timeout: 5e3 },
|
|
804
|
-
(err,
|
|
1114
|
+
(err, stdout2) => {
|
|
805
1115
|
if (err) return resolve(null);
|
|
806
|
-
const line =
|
|
1116
|
+
const line = stdout2.split(/\r?\n/)[0]?.trim() ?? "";
|
|
807
1117
|
resolve(line.length > 0 ? line : null);
|
|
808
1118
|
}
|
|
809
1119
|
);
|
|
@@ -818,7 +1128,7 @@ async function resolveRepoIdentity(root, deps) {
|
|
|
818
1128
|
try {
|
|
819
1129
|
canonicalRoot = realpathSync(root);
|
|
820
1130
|
} catch {
|
|
821
|
-
canonicalRoot =
|
|
1131
|
+
canonicalRoot = path5.resolve(root);
|
|
822
1132
|
}
|
|
823
1133
|
return { kind: "local", value: `${machineId}:${canonicalRoot}` };
|
|
824
1134
|
}
|
|
@@ -837,7 +1147,7 @@ function resolveStartDir(env, cwd) {
|
|
|
837
1147
|
}
|
|
838
1148
|
function dirHasGit(dir) {
|
|
839
1149
|
try {
|
|
840
|
-
statSync2(
|
|
1150
|
+
statSync2(path6.join(dir, ".git"));
|
|
841
1151
|
return true;
|
|
842
1152
|
} catch {
|
|
843
1153
|
return false;
|
|
@@ -849,14 +1159,14 @@ function findRepoRoot(startDir, hasGit = dirHasGit) {
|
|
|
849
1159
|
if (hasGit(current)) {
|
|
850
1160
|
return { root: current, foundGit: true };
|
|
851
1161
|
}
|
|
852
|
-
const parent =
|
|
1162
|
+
const parent = path6.dirname(current);
|
|
853
1163
|
if (parent === current) break;
|
|
854
1164
|
current = parent;
|
|
855
1165
|
}
|
|
856
1166
|
return { root: startDir, foundGit: false };
|
|
857
1167
|
}
|
|
858
1168
|
function isHomeDirectory(dir, home = os2.homedir()) {
|
|
859
|
-
return
|
|
1169
|
+
return path6.resolve(dir) === path6.resolve(home);
|
|
860
1170
|
}
|
|
861
1171
|
async function handleShow(deps, projectBindingPath, mode2) {
|
|
862
1172
|
const startDir = resolveStartDir(process.env, process.cwd());
|
|
@@ -955,10 +1265,10 @@ async function handleRebind(deps, projectId, root, mode2, yes) {
|
|
|
955
1265
|
}
|
|
956
1266
|
}
|
|
957
1267
|
async function handleUnlink(projectBindingPath, mode2) {
|
|
958
|
-
const { readFile:
|
|
1268
|
+
const { readFile: readFile13, writeFile: writeFile11, chmod: chmod2 } = await import("fs/promises");
|
|
959
1269
|
let existing = {};
|
|
960
1270
|
try {
|
|
961
|
-
const raw = await
|
|
1271
|
+
const raw = await readFile13(projectBindingPath, "utf8");
|
|
962
1272
|
const parsed = JSON.parse(raw);
|
|
963
1273
|
if (parsed == null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
964
1274
|
throw new CliError(
|
|
@@ -973,7 +1283,7 @@ async function handleUnlink(projectBindingPath, mode2) {
|
|
|
973
1283
|
}
|
|
974
1284
|
const { projectId: _removed, ...rest } = existing;
|
|
975
1285
|
void _removed;
|
|
976
|
-
await
|
|
1286
|
+
await writeFile11(projectBindingPath, JSON.stringify(rest, null, 2) + "\n", { mode: 420 });
|
|
977
1287
|
await chmod2(projectBindingPath, 420);
|
|
978
1288
|
if (mode2 === "json") {
|
|
979
1289
|
printResult({ unlinked: true, projectBindingPath }, mode2);
|
|
@@ -1028,7 +1338,7 @@ Proceeding anyway \u2014 verify the ID is correct.
|
|
|
1028
1338
|
);
|
|
1029
1339
|
}
|
|
1030
1340
|
await writeRepoBinding(root, projectId);
|
|
1031
|
-
const writtenPath =
|
|
1341
|
+
const writtenPath = path6.join(root, "nolto.json");
|
|
1032
1342
|
let registryAdded = false;
|
|
1033
1343
|
if (isHomeDirectory(root)) {
|
|
1034
1344
|
process.stderr.write(`Warning: refusing to add home directory ${root} to the watch registry.
|
|
@@ -1061,7 +1371,7 @@ Commit nolto.json to share the binding with your team.
|
|
|
1061
1371
|
}
|
|
1062
1372
|
}
|
|
1063
1373
|
}
|
|
1064
|
-
function
|
|
1374
|
+
function register2(program, deps) {
|
|
1065
1375
|
const cmd = program.command("link [projectId]").description(
|
|
1066
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"
|
|
1067
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");
|
|
@@ -1115,35 +1425,35 @@ function invalidBindingError(projectBindingPath, error) {
|
|
|
1115
1425
|
}
|
|
1116
1426
|
|
|
1117
1427
|
// src/skill-install.ts
|
|
1118
|
-
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";
|
|
1119
1429
|
import { existsSync } from "fs";
|
|
1120
|
-
import
|
|
1430
|
+
import path7 from "path";
|
|
1121
1431
|
import { fileURLToPath } from "url";
|
|
1122
|
-
var __dirname =
|
|
1432
|
+
var __dirname = path7.dirname(fileURLToPath(import.meta.url));
|
|
1123
1433
|
function resolveSkillSourceDir() {
|
|
1124
1434
|
const candidates = [
|
|
1125
|
-
|
|
1435
|
+
path7.resolve(__dirname, "skill/roadmap-progress"),
|
|
1126
1436
|
// bundled: dist/skill/...
|
|
1127
|
-
|
|
1437
|
+
path7.resolve(__dirname, "../../../skills/roadmap-progress")
|
|
1128
1438
|
// source: <repo>/skills/...
|
|
1129
1439
|
];
|
|
1130
1440
|
for (const candidate of candidates) {
|
|
1131
|
-
if (existsSync(
|
|
1441
|
+
if (existsSync(path7.join(candidate, "SKILL.md"))) return candidate;
|
|
1132
1442
|
}
|
|
1133
1443
|
throw new Error("Bundled roadmap-progress skill not found. Reinstall @nolto/cli.");
|
|
1134
1444
|
}
|
|
1135
1445
|
var VERSION_MARKER = ".nolto-skill-version";
|
|
1136
1446
|
async function checkSkillVersionDrift(repoRoot, cliVersion) {
|
|
1137
1447
|
const skillDirs = [
|
|
1138
|
-
|
|
1139
|
-
|
|
1448
|
+
path7.join(repoRoot, ".claude", "skills", "roadmap-progress"),
|
|
1449
|
+
path7.join(repoRoot, ".agents", "skills", "roadmap-progress")
|
|
1140
1450
|
];
|
|
1141
1451
|
const drifted = [];
|
|
1142
1452
|
for (const dir of skillDirs) {
|
|
1143
1453
|
if (!existsSync(dir)) continue;
|
|
1144
1454
|
let installed;
|
|
1145
1455
|
try {
|
|
1146
|
-
const marker = (await
|
|
1456
|
+
const marker = (await readFile5(path7.join(dir, VERSION_MARKER), "utf8")).trim();
|
|
1147
1457
|
installed = marker.length > 0 ? marker : null;
|
|
1148
1458
|
} catch {
|
|
1149
1459
|
installed = null;
|
|
@@ -1153,18 +1463,18 @@ async function checkSkillVersionDrift(repoRoot, cliVersion) {
|
|
|
1153
1463
|
return drifted;
|
|
1154
1464
|
}
|
|
1155
1465
|
function formatSkillVersionDriftWarning(repoRoot, cliVersion, drifted) {
|
|
1156
|
-
const dirs = drifted.map(({ dir }) =>
|
|
1466
|
+
const dirs = drifted.map(({ dir }) => path7.relative(repoRoot, dir).split(path7.sep).join("/")).join(", ");
|
|
1157
1467
|
const installed = [...new Set(drifted.map((entry) => entry.installed ?? "unknown"))].join(", ");
|
|
1158
1468
|
return `roadmap-progress skill is outdated in ${dirs} (installed ${installed}, CLI ${cliVersion}). Run \`nolto init\` in this repo to update it.`;
|
|
1159
1469
|
}
|
|
1160
1470
|
async function installSkill(args) {
|
|
1161
|
-
const targetDir =
|
|
1162
|
-
const markerPath =
|
|
1471
|
+
const targetDir = path7.join(args.skillsParentDir, "roadmap-progress");
|
|
1472
|
+
const markerPath = path7.join(targetDir, VERSION_MARKER);
|
|
1163
1473
|
const dirExists = existsSync(targetDir);
|
|
1164
1474
|
let installedVersion = null;
|
|
1165
1475
|
if (dirExists) {
|
|
1166
1476
|
try {
|
|
1167
|
-
installedVersion = (await
|
|
1477
|
+
installedVersion = (await readFile5(markerPath, "utf8")).trim();
|
|
1168
1478
|
} catch {
|
|
1169
1479
|
installedVersion = null;
|
|
1170
1480
|
}
|
|
@@ -1172,30 +1482,30 @@ async function installSkill(args) {
|
|
|
1172
1482
|
if (dirExists && installedVersion === args.version && args.force !== true) {
|
|
1173
1483
|
return { action: "skipped", targetDir };
|
|
1174
1484
|
}
|
|
1175
|
-
await
|
|
1485
|
+
await rm2(targetDir, { recursive: true, force: true });
|
|
1176
1486
|
await mkdir4(args.skillsParentDir, { recursive: true });
|
|
1177
1487
|
await cp(args.sourceDir, targetDir, { recursive: true });
|
|
1178
|
-
await
|
|
1488
|
+
await writeFile5(markerPath, args.version + "\n", "utf8");
|
|
1179
1489
|
return { action: dirExists ? "updated" : "installed", targetDir };
|
|
1180
1490
|
}
|
|
1181
1491
|
|
|
1182
1492
|
// src/roadmap-scaffold.ts
|
|
1183
|
-
import { mkdir as mkdir5, readdir, writeFile as
|
|
1493
|
+
import { mkdir as mkdir5, readdir as readdir2, writeFile as writeFile6 } from "fs/promises";
|
|
1184
1494
|
import { existsSync as existsSync2 } from "fs";
|
|
1185
|
-
import
|
|
1495
|
+
import path8 from "path";
|
|
1186
1496
|
function slugifyProjectId(name) {
|
|
1187
1497
|
const slug = name.toLowerCase().replace(/[^a-z0-9.-]+/g, "-").replace(/^[^a-z0-9]+/, "").replace(/[-_.]+$/, "");
|
|
1188
1498
|
return slug.length > 0 ? slug : "project";
|
|
1189
1499
|
}
|
|
1190
1500
|
async function scaffoldRoadmap(args) {
|
|
1191
|
-
const repoBasename =
|
|
1192
|
-
const dir =
|
|
1193
|
-
const filePath =
|
|
1194
|
-
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");
|
|
1195
1505
|
try {
|
|
1196
|
-
const existing = (await
|
|
1506
|
+
const existing = (await readdir2(dir)).sort();
|
|
1197
1507
|
if (existing.length > 0) {
|
|
1198
|
-
return { created: false, path:
|
|
1508
|
+
return { created: false, path: path8.join(dir, existing[0]) };
|
|
1199
1509
|
}
|
|
1200
1510
|
} catch (err) {
|
|
1201
1511
|
if (err == null || typeof err !== "object" || !("code" in err) || err.code !== "ENOENT") {
|
|
@@ -1218,28 +1528,28 @@ async function scaffoldRoadmap(args) {
|
|
|
1218
1528
|
phases: []
|
|
1219
1529
|
};
|
|
1220
1530
|
await mkdir5(dir, { recursive: true });
|
|
1221
|
-
await
|
|
1531
|
+
await writeFile6(filePath, JSON.stringify(roadmap, null, 2) + "\n", "utf8");
|
|
1222
1532
|
return { created: true, path: filePath };
|
|
1223
1533
|
}
|
|
1224
1534
|
|
|
1225
1535
|
// src/git-merge-driver.ts
|
|
1226
1536
|
import { execFile as execFile2 } from "child_process";
|
|
1227
|
-
import { readFile as
|
|
1228
|
-
import
|
|
1537
|
+
import { readFile as readFile6, writeFile as writeFile7 } from "fs/promises";
|
|
1538
|
+
import path9 from "path";
|
|
1229
1539
|
import { promisify } from "util";
|
|
1230
1540
|
var ATTRIBUTE_LINE = ".nolto/roadmaps/*.json merge=nolto-roadmap";
|
|
1231
1541
|
var DRIVER_COMMAND = "nolto merge-file %A %B --base %O";
|
|
1232
1542
|
async function ensureGitAttributes(root) {
|
|
1233
|
-
const filePath =
|
|
1543
|
+
const filePath = path9.join(root, ".gitattributes");
|
|
1234
1544
|
let content = "";
|
|
1235
1545
|
try {
|
|
1236
|
-
content = await
|
|
1546
|
+
content = await readFile6(filePath, "utf8");
|
|
1237
1547
|
} catch (err) {
|
|
1238
1548
|
if (err.code !== "ENOENT") throw err;
|
|
1239
1549
|
}
|
|
1240
1550
|
if (content.split(/\r?\n/).includes(ATTRIBUTE_LINE)) return "exists";
|
|
1241
1551
|
const separator = content.length > 0 && !content.endsWith("\n") ? "\n" : "";
|
|
1242
|
-
await
|
|
1552
|
+
await writeFile7(filePath, content + separator + ATTRIBUTE_LINE + "\n", "utf8");
|
|
1243
1553
|
return "added";
|
|
1244
1554
|
}
|
|
1245
1555
|
async function configureMergeDriver(root, exec = async (file, args, options) => {
|
|
@@ -1264,13 +1574,13 @@ async function configureMergeDriver(root, exec = async (file, args, options) =>
|
|
|
1264
1574
|
}
|
|
1265
1575
|
|
|
1266
1576
|
// src/commands/init.ts
|
|
1267
|
-
var __dirname2 =
|
|
1577
|
+
var __dirname2 = path10.dirname(fileURLToPath2(import.meta.url));
|
|
1268
1578
|
var _require = createRequire(import.meta.url);
|
|
1269
1579
|
function getCliVersion() {
|
|
1270
1580
|
const candidates = [
|
|
1271
|
-
|
|
1581
|
+
path10.resolve(__dirname2, "../package.json"),
|
|
1272
1582
|
// bundled: dist/../package.json
|
|
1273
|
-
|
|
1583
|
+
path10.resolve(__dirname2, "../../package.json")
|
|
1274
1584
|
// source: src/commands/../../package.json
|
|
1275
1585
|
];
|
|
1276
1586
|
for (const pkgPath of candidates) {
|
|
@@ -1339,7 +1649,7 @@ async function selectRepoProject(rl, http, projects, defaultProjectId) {
|
|
|
1339
1649
|
"Project number for this repository, 'c' to create new (or Enter to skip): "
|
|
1340
1650
|
);
|
|
1341
1651
|
}
|
|
1342
|
-
function
|
|
1652
|
+
function register3(program, deps) {
|
|
1343
1653
|
program.command("init").description("Interactive setup: configure token, base URL, and default project.").option("--force", "Overwrite existing config without prompting").action(async (opts) => {
|
|
1344
1654
|
const configPath = deps.configPath;
|
|
1345
1655
|
const rl = readline2.createInterface({ input: process.stdin, output: process.stdout });
|
|
@@ -1431,7 +1741,7 @@ Saved ${configPath}
|
|
|
1431
1741
|
}
|
|
1432
1742
|
if (isHomeDirectory(root)) {
|
|
1433
1743
|
process.stderr.write(
|
|
1434
|
-
`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.
|
|
1435
1745
|
`
|
|
1436
1746
|
);
|
|
1437
1747
|
return;
|
|
@@ -1463,7 +1773,7 @@ Saved ${configPath}
|
|
|
1463
1773
|
boundProject != null ? "Keep this binding? [Y/n] " : "Keep this binding? [y/N] "
|
|
1464
1774
|
);
|
|
1465
1775
|
keepExistingBinding = boundProject != null ? keep.trim().toLowerCase() !== "n" : keep.trim().toLowerCase() === "y";
|
|
1466
|
-
repoProject = keepExistingBinding ? boundProject ?? { id: existingBinding.projectId, name:
|
|
1776
|
+
repoProject = keepExistingBinding ? boundProject ?? { id: existingBinding.projectId, name: path10.basename(root) } : await selectRepoProject(rl, repoHttp, projects, defaultProjectId);
|
|
1467
1777
|
} else {
|
|
1468
1778
|
repoProject = await selectRepoProject(rl, repoHttp, projects, defaultProjectId);
|
|
1469
1779
|
}
|
|
@@ -1477,7 +1787,7 @@ Set up this repository (${root}) for roadmap sync? [Y/n] `);
|
|
|
1477
1787
|
process.stdout.write("Skipped repo setup.\n");
|
|
1478
1788
|
return;
|
|
1479
1789
|
}
|
|
1480
|
-
const bindingPath = deps.repoBinding?.path ??
|
|
1790
|
+
const bindingPath = deps.repoBinding?.path ?? path10.join(root, "nolto.json");
|
|
1481
1791
|
if (keepExistingBinding) {
|
|
1482
1792
|
process.stdout.write(`binding: kept ${bindingPath} (${repoProject.id})
|
|
1483
1793
|
`);
|
|
@@ -1489,22 +1799,22 @@ Set up this repository (${root}) for roadmap sync? [Y/n] `);
|
|
|
1489
1799
|
);
|
|
1490
1800
|
}
|
|
1491
1801
|
await writeRepoBinding(root, repoProject.id);
|
|
1492
|
-
process.stdout.write(`binding: wrote ${
|
|
1802
|
+
process.stdout.write(`binding: wrote ${path10.join(root, "nolto.json")}
|
|
1493
1803
|
`);
|
|
1494
1804
|
}
|
|
1495
1805
|
const sourceDir = resolveSkillSourceDir();
|
|
1496
1806
|
const version = getCliVersion();
|
|
1497
1807
|
const claudeInstall = await installSkill({
|
|
1498
|
-
skillsParentDir:
|
|
1808
|
+
skillsParentDir: path10.join(root, ".claude", "skills"),
|
|
1499
1809
|
sourceDir,
|
|
1500
1810
|
version
|
|
1501
1811
|
});
|
|
1502
1812
|
process.stdout.write(`skill (claude): ${claudeInstall.action} ${claudeInstall.targetDir}
|
|
1503
1813
|
`);
|
|
1504
|
-
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"));
|
|
1505
1815
|
if (usesAgentsTooling) {
|
|
1506
1816
|
const agentsInstall = await installSkill({
|
|
1507
|
-
skillsParentDir:
|
|
1817
|
+
skillsParentDir: path10.join(root, ".agents", "skills"),
|
|
1508
1818
|
sourceDir,
|
|
1509
1819
|
version
|
|
1510
1820
|
});
|
|
@@ -1617,7 +1927,7 @@ function sleep(ms) {
|
|
|
1617
1927
|
}
|
|
1618
1928
|
|
|
1619
1929
|
// src/commands/login.ts
|
|
1620
|
-
function
|
|
1930
|
+
function register4(program, deps) {
|
|
1621
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(
|
|
1622
1932
|
async (opts) => {
|
|
1623
1933
|
const { configPath, settings, output } = deps;
|
|
@@ -1699,10 +2009,11 @@ function register3(program, deps) {
|
|
|
1699
2009
|
}
|
|
1700
2010
|
|
|
1701
2011
|
// src/commands/whoami.ts
|
|
1702
|
-
function
|
|
2012
|
+
function register5(program, deps) {
|
|
1703
2013
|
program.command("whoami").description("Show the current authentication and configuration state.").action(async () => {
|
|
1704
2014
|
const { settings, output, configPath } = deps;
|
|
1705
2015
|
const mode2 = output.mode;
|
|
2016
|
+
let tokenInfo;
|
|
1706
2017
|
let projectCount;
|
|
1707
2018
|
if (settings.token != null) {
|
|
1708
2019
|
try {
|
|
@@ -1716,6 +2027,13 @@ function register4(program, deps) {
|
|
|
1716
2027
|
} catch {
|
|
1717
2028
|
}
|
|
1718
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
|
+
}
|
|
1719
2037
|
const projectBindingPath = deps.repoBinding?.path ?? deps.projectBindingPath ?? null;
|
|
1720
2038
|
if (mode2 === "json") {
|
|
1721
2039
|
printResult(
|
|
@@ -1728,7 +2046,8 @@ function register4(program, deps) {
|
|
|
1728
2046
|
defaultProject: settings.defaultProjectId ?? null,
|
|
1729
2047
|
defaultProjectSource: settings.source.project,
|
|
1730
2048
|
projectBindingPath: projectBindingPath ?? null,
|
|
1731
|
-
projects: projectCount ?? null
|
|
2049
|
+
projects: projectCount ?? null,
|
|
2050
|
+
...tokenInfo ? { tokenScopes: tokenInfo.scopes, tokenProject: tokenInfo.projectId } : {}
|
|
1732
2051
|
},
|
|
1733
2052
|
mode2
|
|
1734
2053
|
);
|
|
@@ -1742,6 +2061,9 @@ function register4(program, deps) {
|
|
|
1742
2061
|
["defaultProject", bindingDisplay],
|
|
1743
2062
|
["projects", projectCount != null ? String(projectCount) : settings.token != null ? "(unavailable)" : "(no token)"]
|
|
1744
2063
|
];
|
|
2064
|
+
if (tokenInfo) {
|
|
2065
|
+
lines.push(["scopes", tokenInfo.scopes === null ? "full" : tokenInfo.scopes.join(", ")], ["project", tokenInfo.projectId ?? "all"]);
|
|
2066
|
+
}
|
|
1745
2067
|
const maxKey = lines.reduce((m, [k]) => Math.max(m, k.length), 0);
|
|
1746
2068
|
for (const [key, val] of lines) {
|
|
1747
2069
|
process.stdout.write(`${key.padEnd(maxKey)}: ${val}
|
|
@@ -1752,15 +2074,64 @@ function register4(program, deps) {
|
|
|
1752
2074
|
}
|
|
1753
2075
|
|
|
1754
2076
|
// src/commands/sync.ts
|
|
1755
|
-
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";
|
|
1756
2080
|
import { existsSync as existsSync3 } from "fs";
|
|
1757
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
|
+
|
|
1758
2129
|
// src/sync-repo.ts
|
|
1759
|
-
import
|
|
2130
|
+
import path12 from "path";
|
|
1760
2131
|
|
|
1761
2132
|
// src/sync-core.ts
|
|
1762
2133
|
import { createHash } from "crypto";
|
|
1763
|
-
import
|
|
2134
|
+
import path11 from "path";
|
|
1764
2135
|
function sha256Hex(content) {
|
|
1765
2136
|
return "sha256:" + createHash("sha256").update(content, "utf8").digest("hex");
|
|
1766
2137
|
}
|
|
@@ -1781,10 +2152,10 @@ function collectPlanRefs(roadmap) {
|
|
|
1781
2152
|
}
|
|
1782
2153
|
return refs;
|
|
1783
2154
|
}
|
|
1784
|
-
async function loadValidRoadmap(filePath,
|
|
2155
|
+
async function loadValidRoadmap(filePath, readFile13) {
|
|
1785
2156
|
let raw;
|
|
1786
2157
|
try {
|
|
1787
|
-
raw = await
|
|
2158
|
+
raw = await readFile13(filePath);
|
|
1788
2159
|
} catch {
|
|
1789
2160
|
throw new CliError(`No roadmap found at ${filePath}. Run \`nolto init\` first.`, 2);
|
|
1790
2161
|
}
|
|
@@ -1807,9 +2178,9 @@ async function loadValidRoadmap(filePath, readFile12) {
|
|
|
1807
2178
|
async function buildSyncBody(args) {
|
|
1808
2179
|
const planDocuments = [];
|
|
1809
2180
|
for (const ref of collectPlanRefs(args.roadmap)) {
|
|
1810
|
-
const root =
|
|
1811
|
-
const absolute =
|
|
1812
|
-
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)) {
|
|
1813
2184
|
args.deps.warn(`plan path outside repository root, skipping: ${ref.path}`);
|
|
1814
2185
|
continue;
|
|
1815
2186
|
}
|
|
@@ -1827,7 +2198,7 @@ async function buildSyncBody(args) {
|
|
|
1827
2198
|
args.deps.warn(`plan file not found, skipping: ${ref.path}`);
|
|
1828
2199
|
continue;
|
|
1829
2200
|
}
|
|
1830
|
-
if (real !== realRoot && !real.startsWith(realRoot +
|
|
2201
|
+
if (real !== realRoot && !real.startsWith(realRoot + path11.sep)) {
|
|
1831
2202
|
args.deps.warn(`symlink escapes repository root, skipping: ${ref.path}`);
|
|
1832
2203
|
continue;
|
|
1833
2204
|
}
|
|
@@ -1853,9 +2224,10 @@ async function runSync(args, deps) {
|
|
|
1853
2224
|
`/api/projects/${args.projectId}/roadmaps/${args.slug}`,
|
|
1854
2225
|
body
|
|
1855
2226
|
);
|
|
2227
|
+
for (const warning of response.warnings ?? []) deps.warn(warning);
|
|
1856
2228
|
const stats = deriveTaskStats(args.roadmap);
|
|
1857
2229
|
deps.log(
|
|
1858
|
-
`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})` : ""}`
|
|
1859
2231
|
);
|
|
1860
2232
|
return response;
|
|
1861
2233
|
}
|
|
@@ -1864,11 +2236,11 @@ async function runSync(args, deps) {
|
|
|
1864
2236
|
var ROADMAP_SLUG_PATTERN = /^[a-z0-9][a-z0-9._-]*$/;
|
|
1865
2237
|
function collectContainedPlanAbsPaths(roadmaps, root, warn) {
|
|
1866
2238
|
const planAbsPaths = /* @__PURE__ */ new Set();
|
|
1867
|
-
const resolvedRoot =
|
|
2239
|
+
const resolvedRoot = path12.resolve(root);
|
|
1868
2240
|
for (const roadmap of roadmaps) {
|
|
1869
2241
|
for (const ref of collectPlanRefs(roadmap)) {
|
|
1870
|
-
const absolute =
|
|
1871
|
-
if (absolute !== resolvedRoot && !absolute.startsWith(resolvedRoot +
|
|
2242
|
+
const absolute = path12.resolve(resolvedRoot, ref.path);
|
|
2243
|
+
if (absolute !== resolvedRoot && !absolute.startsWith(resolvedRoot + path12.sep)) {
|
|
1872
2244
|
warn(`chokidar target outside repo, skipping: ${ref.path}`);
|
|
1873
2245
|
continue;
|
|
1874
2246
|
}
|
|
@@ -1889,7 +2261,7 @@ async function listRoadmapFiles(roadmapsDir, io) {
|
|
|
1889
2261
|
}
|
|
1890
2262
|
}
|
|
1891
2263
|
async function migrateLegacyRoadmap(args) {
|
|
1892
|
-
const targetPath =
|
|
2264
|
+
const targetPath = path12.join(args.roadmapsDir, `${args.slug}.json`);
|
|
1893
2265
|
await args.io.mkdir(args.roadmapsDir);
|
|
1894
2266
|
try {
|
|
1895
2267
|
await args.io.rename(args.legacyPath, targetPath);
|
|
@@ -1898,7 +2270,7 @@ async function migrateLegacyRoadmap(args) {
|
|
|
1898
2270
|
await args.io.unlink(args.legacyPath);
|
|
1899
2271
|
}
|
|
1900
2272
|
try {
|
|
1901
|
-
await args.io.rmdir(
|
|
2273
|
+
await args.io.rmdir(path12.dirname(args.legacyPath));
|
|
1902
2274
|
} catch {
|
|
1903
2275
|
}
|
|
1904
2276
|
args.io.log(
|
|
@@ -1907,14 +2279,14 @@ async function migrateLegacyRoadmap(args) {
|
|
|
1907
2279
|
return `${args.slug}.json`;
|
|
1908
2280
|
}
|
|
1909
2281
|
async function syncRepo(args, io) {
|
|
1910
|
-
const bindingPath =
|
|
2282
|
+
const bindingPath = path12.join(args.root, "nolto.json");
|
|
1911
2283
|
const binding = await loadRepoBinding(bindingPath);
|
|
1912
2284
|
const projectId = binding?.projectId ?? args.defaultProjectId;
|
|
1913
2285
|
if (projectId == null) {
|
|
1914
2286
|
throw new CliError("No project binding. Run `nolto init` or `nolto link <projectId>`.", 2);
|
|
1915
2287
|
}
|
|
1916
|
-
const roadmapsDir =
|
|
1917
|
-
const legacyPath =
|
|
2288
|
+
const roadmapsDir = path12.join(args.root, ".nolto", "roadmaps");
|
|
2289
|
+
const legacyPath = path12.join(args.root, ".roadmap", "roadmap.json");
|
|
1918
2290
|
let roadmapFiles = await listRoadmapFiles(roadmapsDir, io);
|
|
1919
2291
|
if (roadmapFiles.length > 0) {
|
|
1920
2292
|
if (io.fileExists(legacyPath)) {
|
|
@@ -1929,7 +2301,7 @@ async function syncRepo(args, io) {
|
|
|
1929
2301
|
);
|
|
1930
2302
|
return { results: [], planAbsPaths: [] };
|
|
1931
2303
|
}
|
|
1932
|
-
const migrationSlug = binding?.roadmapSlug ?? slugifyProjectId(
|
|
2304
|
+
const migrationSlug = binding?.roadmapSlug ?? slugifyProjectId(path12.basename(args.root));
|
|
1933
2305
|
roadmapFiles = [
|
|
1934
2306
|
await migrateLegacyRoadmap({
|
|
1935
2307
|
slug: migrationSlug,
|
|
@@ -1953,7 +2325,7 @@ async function syncRepo(args, io) {
|
|
|
1953
2325
|
2
|
|
1954
2326
|
);
|
|
1955
2327
|
}
|
|
1956
|
-
const filePath =
|
|
2328
|
+
const filePath = path12.join(roadmapsDir, fileName);
|
|
1957
2329
|
return { slug, roadmap: await loadValidRoadmap(filePath, io.readFile) };
|
|
1958
2330
|
})
|
|
1959
2331
|
);
|
|
@@ -1979,12 +2351,34 @@ async function syncRepo(args, io) {
|
|
|
1979
2351
|
)
|
|
1980
2352
|
);
|
|
1981
2353
|
}
|
|
1982
|
-
|
|
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 };
|
|
1983
2377
|
}
|
|
1984
2378
|
|
|
1985
2379
|
// src/commands/sync.ts
|
|
1986
|
-
function
|
|
1987
|
-
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) => {
|
|
1988
2382
|
if (deps.settings.token == null) {
|
|
1989
2383
|
throw new CliError("Not authenticated. Run `nolto login` or set NOLTO_TOKEN.", 3);
|
|
1990
2384
|
}
|
|
@@ -2000,18 +2394,22 @@ function register5(program, deps) {
|
|
|
2000
2394
|
const response = await syncRepo(
|
|
2001
2395
|
{ root, defaultProjectId: deps.settings.defaultProjectId, migrateLegacy: true },
|
|
2002
2396
|
{
|
|
2003
|
-
readFile: (p) =>
|
|
2397
|
+
readFile: (p) => readFile7(p, "utf8"),
|
|
2004
2398
|
realpath: (p) => realpath(p),
|
|
2005
2399
|
fileExists: (p) => existsSync3(p),
|
|
2006
|
-
listDir: (p) =>
|
|
2007
|
-
rename:
|
|
2400
|
+
listDir: (p) => readdir3(p),
|
|
2401
|
+
rename: rename3,
|
|
2008
2402
|
copyFile,
|
|
2009
2403
|
mkdir: (p) => mkdir6(p, { recursive: true }).then(() => void 0),
|
|
2010
2404
|
unlink: unlink2,
|
|
2011
2405
|
rmdir,
|
|
2012
2406
|
repoIdentity: makeRepoIdentityResolver(deps),
|
|
2407
|
+
exec: promisify2(execFile3),
|
|
2408
|
+
gitLinks: opts.gitLinks && process.env.NOLTO_GIT_LINKS !== "0",
|
|
2013
2409
|
http,
|
|
2014
|
-
log: (line) =>
|
|
2410
|
+
log: (line) => {
|
|
2411
|
+
if (deps.output.mode !== "json") process.stdout.write(line + "\n");
|
|
2412
|
+
},
|
|
2015
2413
|
warn
|
|
2016
2414
|
}
|
|
2017
2415
|
);
|
|
@@ -2046,8 +2444,8 @@ function register5(program, deps) {
|
|
|
2046
2444
|
}
|
|
2047
2445
|
|
|
2048
2446
|
// src/commands/diff.ts
|
|
2049
|
-
import { readFile as
|
|
2050
|
-
import
|
|
2447
|
+
import { readFile as readFile8 } from "fs/promises";
|
|
2448
|
+
import path14 from "path";
|
|
2051
2449
|
|
|
2052
2450
|
// src/roadmap-diff.ts
|
|
2053
2451
|
function diffRoadmaps(local, server) {
|
|
@@ -2126,8 +2524,8 @@ function diffRoadmaps(local, server) {
|
|
|
2126
2524
|
}
|
|
2127
2525
|
function truncate(value) {
|
|
2128
2526
|
if (value == null) return "none";
|
|
2129
|
-
const
|
|
2130
|
-
return
|
|
2527
|
+
const singleLine2 = value.replace(/\s+/g, " ");
|
|
2528
|
+
return singleLine2.length <= 60 ? singleLine2 : singleLine2.slice(0, 57) + "...";
|
|
2131
2529
|
}
|
|
2132
2530
|
function formatRoadmapDiff(slug, entries) {
|
|
2133
2531
|
if (entries.length === 0) return [];
|
|
@@ -2151,8 +2549,8 @@ function formatRoadmapDiff(slug, entries) {
|
|
|
2151
2549
|
}
|
|
2152
2550
|
|
|
2153
2551
|
// src/roadmap-read.ts
|
|
2154
|
-
import { readdir as
|
|
2155
|
-
import
|
|
2552
|
+
import { readdir as readdir4 } from "fs/promises";
|
|
2553
|
+
import path13 from "path";
|
|
2156
2554
|
async function resolveRoadmapReadContext(deps) {
|
|
2157
2555
|
if (deps.settings.token == null) {
|
|
2158
2556
|
throw new CliError("Not authenticated. Run `nolto login` or set NOLTO_TOKEN.", 3);
|
|
@@ -2162,7 +2560,7 @@ async function resolveRoadmapReadContext(deps) {
|
|
|
2162
2560
|
if (!foundGit) {
|
|
2163
2561
|
throw new CliError("No git repository found. Run inside a repo set up with `nolto init`.", 2);
|
|
2164
2562
|
}
|
|
2165
|
-
const binding = await loadRepoBinding(
|
|
2563
|
+
const binding = await loadRepoBinding(path13.join(root, "nolto.json"));
|
|
2166
2564
|
const projectId = binding?.projectId ?? deps.settings.defaultProjectId;
|
|
2167
2565
|
if (projectId == null) {
|
|
2168
2566
|
throw new CliError("No project binding. Run `nolto init` or `nolto link <projectId>`.", 2);
|
|
@@ -2171,7 +2569,7 @@ async function resolveRoadmapReadContext(deps) {
|
|
|
2171
2569
|
}
|
|
2172
2570
|
async function listLocalRoadmapSlugs(root) {
|
|
2173
2571
|
try {
|
|
2174
|
-
const entries = await
|
|
2572
|
+
const entries = await readdir4(path13.join(root, ".nolto", "roadmaps"));
|
|
2175
2573
|
return entries.filter((entry) => entry.endsWith(".json")).map((entry) => entry.slice(0, -".json".length)).sort();
|
|
2176
2574
|
} catch (err) {
|
|
2177
2575
|
if (err != null && typeof err === "object" && "code" in err && err.code === "ENOENT") {
|
|
@@ -2182,7 +2580,7 @@ async function listLocalRoadmapSlugs(root) {
|
|
|
2182
2580
|
}
|
|
2183
2581
|
|
|
2184
2582
|
// src/commands/diff.ts
|
|
2185
|
-
function
|
|
2583
|
+
function register7(program, deps) {
|
|
2186
2584
|
program.command("diff [slug]").description("Compare local roadmaps with the server without changing either side.").action(async (requestedSlug) => {
|
|
2187
2585
|
const { root, projectId } = await resolveRoadmapReadContext(deps);
|
|
2188
2586
|
const list = await deps.http.get(
|
|
@@ -2203,9 +2601,9 @@ function register6(program, deps) {
|
|
|
2203
2601
|
for (const slug of targetSlugs) {
|
|
2204
2602
|
let local = null;
|
|
2205
2603
|
if (localSlugSet.has(slug)) {
|
|
2206
|
-
const localPath =
|
|
2604
|
+
const localPath = path14.join(root, ".nolto", "roadmaps", `${slug}.json`);
|
|
2207
2605
|
try {
|
|
2208
|
-
local = await loadValidRoadmap(localPath, (filePath) =>
|
|
2606
|
+
local = await loadValidRoadmap(localPath, (filePath) => readFile8(filePath, "utf8"));
|
|
2209
2607
|
} catch (err) {
|
|
2210
2608
|
const message = err instanceof Error ? err.message : String(err);
|
|
2211
2609
|
process.stderr.write(`Warning: could not diff ${slug}.json: ${message}
|
|
@@ -2248,8 +2646,8 @@ function register6(program, deps) {
|
|
|
2248
2646
|
}
|
|
2249
2647
|
|
|
2250
2648
|
// src/commands/pull.ts
|
|
2251
|
-
import { mkdir as mkdir7, readFile as
|
|
2252
|
-
import
|
|
2649
|
+
import { mkdir as mkdir7, readFile as readFile9, writeFile as writeFile8 } from "fs/promises";
|
|
2650
|
+
import path15 from "path";
|
|
2253
2651
|
|
|
2254
2652
|
// src/roadmap-merge.ts
|
|
2255
2653
|
import { isDeepStrictEqual } from "util";
|
|
@@ -2294,6 +2692,7 @@ function assignOptional(target, key, value) {
|
|
|
2294
2692
|
function cloneSingleTask(task) {
|
|
2295
2693
|
const cloned = { ...task };
|
|
2296
2694
|
if (task.dependsOn !== void 0) cloned.dependsOn = [...task.dependsOn];
|
|
2695
|
+
if (task.issues !== void 0) cloned.issues = [...task.issues];
|
|
2297
2696
|
if (cloned.status !== "done") delete cloned.completedAt;
|
|
2298
2697
|
return cloned;
|
|
2299
2698
|
}
|
|
@@ -2342,6 +2741,8 @@ function mergeTask(args) {
|
|
|
2342
2741
|
...args.theirs.dependsOn ?? []
|
|
2343
2742
|
].filter((id, index, values) => values.indexOf(id) === index);
|
|
2344
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;
|
|
2345
2746
|
return merged;
|
|
2346
2747
|
}
|
|
2347
2748
|
function shouldKeep(base, ours, theirs) {
|
|
@@ -2485,7 +2886,7 @@ function mergeRoadmaps(args) {
|
|
|
2485
2886
|
// src/commands/pull.ts
|
|
2486
2887
|
async function readExisting(filePath) {
|
|
2487
2888
|
try {
|
|
2488
|
-
return await
|
|
2889
|
+
return await readFile9(filePath, "utf8");
|
|
2489
2890
|
} catch (err) {
|
|
2490
2891
|
if (err != null && typeof err === "object" && "code" in err && err.code === "ENOENT") {
|
|
2491
2892
|
return null;
|
|
@@ -2493,7 +2894,7 @@ async function readExisting(filePath) {
|
|
|
2493
2894
|
throw err;
|
|
2494
2895
|
}
|
|
2495
2896
|
}
|
|
2496
|
-
function
|
|
2897
|
+
function register8(program, deps) {
|
|
2497
2898
|
program.command("pull [slug]").description(
|
|
2498
2899
|
"Pull server roadmaps, optionally merging them with valid local copies."
|
|
2499
2900
|
).option("--merge", "Structurally merge server and local roadmap changes").action(async (requestedSlug, opts) => {
|
|
@@ -2506,7 +2907,7 @@ function register7(program, deps) {
|
|
|
2506
2907
|
throw new CliError(`Roadmap "${requestedSlug}" was not found on the server.`, 2);
|
|
2507
2908
|
}
|
|
2508
2909
|
const targets = requestedSlug == null ? [...serverBySlug.values()] : [serverBySlug.get(requestedSlug)];
|
|
2509
|
-
const roadmapsDir =
|
|
2910
|
+
const roadmapsDir = path15.join(root, ".nolto", "roadmaps");
|
|
2510
2911
|
for (const summary of targets) {
|
|
2511
2912
|
const response = await deps.http.get(
|
|
2512
2913
|
`/api/projects/${projectId}/roadmaps/${encodeURIComponent(summary.slug)}`
|
|
@@ -2518,7 +2919,7 @@ function register7(program, deps) {
|
|
|
2518
2919
|
5
|
|
2519
2920
|
);
|
|
2520
2921
|
}
|
|
2521
|
-
const filePath =
|
|
2922
|
+
const filePath = path15.join(roadmapsDir, `${summary.slug}.json`);
|
|
2522
2923
|
const existing = await readExisting(filePath);
|
|
2523
2924
|
let roadmap = response.roadmap;
|
|
2524
2925
|
let outputVerb = "pulled";
|
|
@@ -2555,7 +2956,7 @@ function register7(program, deps) {
|
|
|
2555
2956
|
continue;
|
|
2556
2957
|
}
|
|
2557
2958
|
await mkdir7(roadmapsDir, { recursive: true });
|
|
2558
|
-
await
|
|
2959
|
+
await writeFile8(filePath, serialized, "utf8");
|
|
2559
2960
|
process.stdout.write(
|
|
2560
2961
|
outputVerb === "merged" ? `merged ${summary.slug}.json
|
|
2561
2962
|
` : `pulled ${summary.slug}.json (${summary.taskDone}/${summary.taskTotal} done)
|
|
@@ -2567,9 +2968,11 @@ function register7(program, deps) {
|
|
|
2567
2968
|
}
|
|
2568
2969
|
|
|
2569
2970
|
// src/commands/watch.ts
|
|
2570
|
-
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";
|
|
2571
2974
|
import { existsSync as existsSync4 } from "fs";
|
|
2572
|
-
import
|
|
2975
|
+
import path17 from "path";
|
|
2573
2976
|
import chokidar from "chokidar";
|
|
2574
2977
|
|
|
2575
2978
|
// src/watch-core.ts
|
|
@@ -2675,7 +3078,7 @@ var RepoWatch = class {
|
|
|
2675
3078
|
};
|
|
2676
3079
|
|
|
2677
3080
|
// src/service-install.ts
|
|
2678
|
-
import
|
|
3081
|
+
import path16 from "path";
|
|
2679
3082
|
import os4 from "os";
|
|
2680
3083
|
function buildUnitFile(args) {
|
|
2681
3084
|
return [
|
|
@@ -2695,8 +3098,8 @@ function buildUnitFile(args) {
|
|
|
2695
3098
|
}
|
|
2696
3099
|
function getUnitPath(env) {
|
|
2697
3100
|
const xdg = env["XDG_CONFIG_HOME"];
|
|
2698
|
-
const base = xdg != null && xdg.length > 0 ? xdg :
|
|
2699
|
-
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");
|
|
2700
3103
|
}
|
|
2701
3104
|
async function installServiceWith(deps) {
|
|
2702
3105
|
if (deps.platform !== "linux") {
|
|
@@ -2707,7 +3110,7 @@ async function installServiceWith(deps) {
|
|
|
2707
3110
|
);
|
|
2708
3111
|
}
|
|
2709
3112
|
const unitPath = getUnitPath(deps.env);
|
|
2710
|
-
await deps.mkdir(
|
|
3113
|
+
await deps.mkdir(path16.dirname(unitPath));
|
|
2711
3114
|
await deps.writeFile(unitPath, buildUnitFile({ nodePath: deps.nodePath, scriptPath: deps.scriptPath }));
|
|
2712
3115
|
deps.log(`Wrote ${unitPath}`);
|
|
2713
3116
|
const reload = await deps.exec(["systemctl", "--user", "daemon-reload"]);
|
|
@@ -2721,16 +3124,16 @@ async function installServiceWith(deps) {
|
|
|
2721
3124
|
deps.log("Service nolto-watch enabled and started. Logs: journalctl --user -u nolto-watch -f");
|
|
2722
3125
|
}
|
|
2723
3126
|
async function installService() {
|
|
2724
|
-
const { writeFile:
|
|
2725
|
-
const { execFile:
|
|
2726
|
-
const { promisify:
|
|
2727
|
-
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);
|
|
2728
3131
|
await installServiceWith({
|
|
2729
3132
|
platform: process.platform,
|
|
2730
3133
|
env: process.env,
|
|
2731
3134
|
nodePath: process.execPath,
|
|
2732
|
-
scriptPath:
|
|
2733
|
-
writeFile: (p, content) =>
|
|
3135
|
+
scriptPath: path16.resolve(process.argv[1] ?? ""),
|
|
3136
|
+
writeFile: (p, content) => writeFile11(p, content, "utf8"),
|
|
2734
3137
|
mkdir: async (p) => {
|
|
2735
3138
|
await mkdir10(p, { recursive: true });
|
|
2736
3139
|
},
|
|
@@ -2787,9 +3190,9 @@ async function uninstallServiceWith(deps) {
|
|
|
2787
3190
|
}
|
|
2788
3191
|
async function uninstallService() {
|
|
2789
3192
|
const { unlink: unlink4 } = await import("fs/promises");
|
|
2790
|
-
const { execFile:
|
|
2791
|
-
const { promisify:
|
|
2792
|
-
const execFileAsync =
|
|
3193
|
+
const { execFile: execFile6 } = await import("child_process");
|
|
3194
|
+
const { promisify: promisify5 } = await import("util");
|
|
3195
|
+
const execFileAsync = promisify5(execFile6);
|
|
2793
3196
|
await uninstallServiceWith({
|
|
2794
3197
|
platform: process.platform,
|
|
2795
3198
|
env: process.env,
|
|
@@ -2809,7 +3212,7 @@ async function uninstallService() {
|
|
|
2809
3212
|
}
|
|
2810
3213
|
|
|
2811
3214
|
// src/commands/watch.ts
|
|
2812
|
-
function
|
|
3215
|
+
function register9(program, deps) {
|
|
2813
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) => {
|
|
2814
3217
|
if (opts.installService && opts.uninstallService) {
|
|
2815
3218
|
throw new CliError("--install-service and --uninstall-service cannot be used together.", 2);
|
|
@@ -2846,10 +3249,10 @@ function register8(program, deps) {
|
|
|
2846
3249
|
token: deps.settings.token
|
|
2847
3250
|
});
|
|
2848
3251
|
const startRepo = (root) => {
|
|
2849
|
-
const roadmapsPath =
|
|
2850
|
-
const legacyRoadmapPath =
|
|
3252
|
+
const roadmapsPath = path17.join(root, ".nolto", "roadmaps");
|
|
3253
|
+
const legacyRoadmapPath = path17.join(root, ".roadmap", "roadmap.json");
|
|
2851
3254
|
const warn = (line) => {
|
|
2852
|
-
process.stderr.write(`Warning: [${
|
|
3255
|
+
process.stderr.write(`Warning: [${path17.basename(root)}] ${line}
|
|
2853
3256
|
`);
|
|
2854
3257
|
};
|
|
2855
3258
|
const watcher = chokidar.watch([roadmapsPath, legacyRoadmapPath], { ignoreInitial: true });
|
|
@@ -2858,18 +3261,20 @@ function register8(program, deps) {
|
|
|
2858
3261
|
// #316: watch must warn about legacy roadmaps without migrating them.
|
|
2859
3262
|
{ root, defaultProjectId: deps.settings.defaultProjectId, migrateLegacy: false },
|
|
2860
3263
|
{
|
|
2861
|
-
readFile: (p) =>
|
|
3264
|
+
readFile: (p) => readFile10(p, "utf8"),
|
|
2862
3265
|
realpath: (p) => realpath2(p),
|
|
2863
3266
|
fileExists: (p) => existsSync4(p),
|
|
2864
|
-
listDir: (p) =>
|
|
2865
|
-
rename:
|
|
3267
|
+
listDir: (p) => readdir5(p),
|
|
3268
|
+
rename: rename4,
|
|
2866
3269
|
copyFile: copyFile2,
|
|
2867
3270
|
mkdir: (p) => mkdir8(p, { recursive: true }).then(() => void 0),
|
|
2868
3271
|
unlink: unlink3,
|
|
2869
3272
|
rmdir: rmdir2,
|
|
2870
3273
|
repoIdentity: makeRepoIdentityResolver(deps),
|
|
3274
|
+
exec: promisify3(execFile4),
|
|
3275
|
+
gitLinks: process.env.NOLTO_GIT_LINKS !== "0",
|
|
2871
3276
|
http,
|
|
2872
|
-
log: (line) => process.stdout.write(`[${
|
|
3277
|
+
log: (line) => process.stdout.write(`[${path17.basename(root)}] ${line}
|
|
2873
3278
|
`),
|
|
2874
3279
|
warn
|
|
2875
3280
|
}
|
|
@@ -2932,18 +3337,18 @@ function register8(program, deps) {
|
|
|
2932
3337
|
}
|
|
2933
3338
|
|
|
2934
3339
|
// src/update-cli.ts
|
|
2935
|
-
import { execFile as
|
|
3340
|
+
import { execFile as execFile5 } from "child_process";
|
|
2936
3341
|
import { existsSync as existsSync5 } from "fs";
|
|
2937
3342
|
import { realpath as realpath3 } from "fs/promises";
|
|
2938
3343
|
import { createRequire as createRequire2 } from "module";
|
|
2939
|
-
import
|
|
3344
|
+
import path19 from "path";
|
|
2940
3345
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
2941
|
-
import { promisify as
|
|
3346
|
+
import { promisify as promisify4 } from "util";
|
|
2942
3347
|
|
|
2943
3348
|
// src/update-notifier.ts
|
|
2944
|
-
import { readFile as
|
|
3349
|
+
import { readFile as readFile11, writeFile as writeFile9, mkdir as mkdir9 } from "fs/promises";
|
|
2945
3350
|
import https from "https";
|
|
2946
|
-
import
|
|
3351
|
+
import path18 from "path";
|
|
2947
3352
|
var PACKAGE = "@nolto/cli";
|
|
2948
3353
|
var CACHE_FILE = "update-check.json";
|
|
2949
3354
|
var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
@@ -3001,9 +3406,9 @@ function fetchLatestFromRegistry(timeoutMs = REQUEST_TIMEOUT_MS, opts = {}) {
|
|
|
3001
3406
|
});
|
|
3002
3407
|
}
|
|
3003
3408
|
async function writeUpdateCache(cachePath, now, latest2) {
|
|
3004
|
-
await mkdir9(
|
|
3409
|
+
await mkdir9(path18.dirname(cachePath), { recursive: true });
|
|
3005
3410
|
const payload = { checkedAt: now, latest: latest2 };
|
|
3006
|
-
await
|
|
3411
|
+
await writeFile9(cachePath, JSON.stringify(payload), { mode: 384 });
|
|
3007
3412
|
}
|
|
3008
3413
|
async function refreshCache(cachePath, now, fetchLatest) {
|
|
3009
3414
|
const latest2 = await fetchLatest();
|
|
@@ -3012,10 +3417,10 @@ async function refreshCache(cachePath, now, fetchLatest) {
|
|
|
3012
3417
|
}
|
|
3013
3418
|
async function checkForUpdate(opts) {
|
|
3014
3419
|
if (isDisabled(opts.env)) return null;
|
|
3015
|
-
const cachePath =
|
|
3420
|
+
const cachePath = path18.join(opts.configDir, CACHE_FILE);
|
|
3016
3421
|
let cache = {};
|
|
3017
3422
|
try {
|
|
3018
|
-
cache = JSON.parse(await
|
|
3423
|
+
cache = JSON.parse(await readFile11(cachePath, "utf8"));
|
|
3019
3424
|
} catch {
|
|
3020
3425
|
}
|
|
3021
3426
|
if (typeof cache.checkedAt !== "number" || opts.now - cache.checkedAt > CACHE_TTL_MS) {
|
|
@@ -3120,7 +3525,7 @@ async function updateCliWith(deps) {
|
|
|
3120
3525
|
}
|
|
3121
3526
|
deps.log(`Updated ${PACKAGE2} ${deps.currentVersion} \u2192 ${latest2}.`);
|
|
3122
3527
|
await deps.writeCache(
|
|
3123
|
-
|
|
3528
|
+
path19.join(deps.configDir, UPDATE_CACHE_FILE),
|
|
3124
3529
|
deps.now,
|
|
3125
3530
|
latest2
|
|
3126
3531
|
).catch(() => void 0);
|
|
@@ -3151,17 +3556,17 @@ async function updateCliWith(deps) {
|
|
|
3151
3556
|
};
|
|
3152
3557
|
}
|
|
3153
3558
|
function getCurrentVersion() {
|
|
3154
|
-
const dirname =
|
|
3559
|
+
const dirname = path19.dirname(fileURLToPath3(import.meta.url));
|
|
3155
3560
|
const require3 = createRequire2(import.meta.url);
|
|
3156
3561
|
try {
|
|
3157
|
-
const pkg = require3(
|
|
3562
|
+
const pkg = require3(path19.resolve(dirname, "../package.json"));
|
|
3158
3563
|
return pkg.version ?? "0.0.0";
|
|
3159
3564
|
} catch {
|
|
3160
3565
|
return "0.0.0";
|
|
3161
3566
|
}
|
|
3162
3567
|
}
|
|
3163
3568
|
async function updateCli(opts = {}) {
|
|
3164
|
-
const execFileAsync =
|
|
3569
|
+
const execFileAsync = promisify4(execFile5);
|
|
3165
3570
|
const scriptPath = await realpath3(process.argv[1] ?? "");
|
|
3166
3571
|
return updateCliWith({
|
|
3167
3572
|
currentVersion: getCurrentVersion(),
|
|
@@ -3193,7 +3598,7 @@ async function updateCli(opts = {}) {
|
|
|
3193
3598
|
}
|
|
3194
3599
|
|
|
3195
3600
|
// src/commands/update.ts
|
|
3196
|
-
function
|
|
3601
|
+
function register10(program, deps) {
|
|
3197
3602
|
program.command("update").description("Update @nolto/cli to the latest version and restart the watch service if installed").action(async () => {
|
|
3198
3603
|
const mode2 = deps.output.mode;
|
|
3199
3604
|
const result = await updateCli({ quiet: mode2 === "json" });
|
|
@@ -3204,11 +3609,11 @@ function register9(program, deps) {
|
|
|
3204
3609
|
}
|
|
3205
3610
|
|
|
3206
3611
|
// src/commands/merge-file.ts
|
|
3207
|
-
import { readFile as
|
|
3612
|
+
import { readFile as readFile12, writeFile as writeFile10 } from "fs/promises";
|
|
3208
3613
|
async function readRoadmap(filePath) {
|
|
3209
3614
|
let parsed;
|
|
3210
3615
|
try {
|
|
3211
|
-
parsed = JSON.parse(await
|
|
3616
|
+
parsed = JSON.parse(await readFile12(filePath, "utf8"));
|
|
3212
3617
|
} catch (err) {
|
|
3213
3618
|
const message = err instanceof SyntaxError ? "malformed JSON" : String(err);
|
|
3214
3619
|
throw new CliError(`${filePath}: ${message}`, 1);
|
|
@@ -3223,7 +3628,7 @@ async function readRoadmap(filePath) {
|
|
|
3223
3628
|
}
|
|
3224
3629
|
return parsed;
|
|
3225
3630
|
}
|
|
3226
|
-
function
|
|
3631
|
+
function register11(program) {
|
|
3227
3632
|
program.command("merge-file <ours> <theirs>").description(
|
|
3228
3633
|
'Structurally merge roadmap files for Git.\ngit config merge.nolto-roadmap.driver "nolto merge-file %A %B --base %O"'
|
|
3229
3634
|
).option("--base <path>", "Common ancestor roadmap file").option("--output <path>", "Write the result here (defaults to <ours>)").action(async (oursPath, theirsPath, opts) => {
|
|
@@ -3231,7 +3636,7 @@ function register10(program) {
|
|
|
3231
3636
|
const theirs = await readRoadmap(theirsPath);
|
|
3232
3637
|
const base = opts.base == null ? null : await readRoadmap(opts.base);
|
|
3233
3638
|
const merged = mergeRoadmaps({ base, ours, theirs });
|
|
3234
|
-
await
|
|
3639
|
+
await writeFile10(
|
|
3235
3640
|
opts.output ?? oursPath,
|
|
3236
3641
|
JSON.stringify(merged, null, 2) + "\n",
|
|
3237
3642
|
"utf8"
|
|
@@ -3251,20 +3656,21 @@ function buildProgram(deps) {
|
|
|
3251
3656
|
const writeErr = (_msg) => {
|
|
3252
3657
|
};
|
|
3253
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");
|
|
3254
|
-
|
|
3659
|
+
register(program, deps);
|
|
3255
3660
|
register3(program, deps);
|
|
3256
3661
|
register4(program, deps);
|
|
3257
|
-
register(program, deps);
|
|
3258
3662
|
register5(program, deps);
|
|
3663
|
+
register2(program, deps);
|
|
3259
3664
|
register6(program, deps);
|
|
3260
3665
|
register7(program, deps);
|
|
3261
3666
|
register8(program, deps);
|
|
3262
3667
|
register9(program, deps);
|
|
3263
|
-
register10(program);
|
|
3668
|
+
register10(program, deps);
|
|
3669
|
+
register11(program);
|
|
3264
3670
|
program.hook("preAction", (_thisCommand, actionCommand) => {
|
|
3265
3671
|
const bindingError = deps.repoBinding?.error;
|
|
3266
3672
|
const bindingExemptCommands = ["init", "link", "update", "merge-file"];
|
|
3267
|
-
if (bindingError != null && !bindingExemptCommands.includes(actionCommand.name())) {
|
|
3673
|
+
if (bindingError != null && !(actionCommand.parent === program && bindingExemptCommands.includes(actionCommand.name()))) {
|
|
3268
3674
|
throw bindingError;
|
|
3269
3675
|
}
|
|
3270
3676
|
});
|
|
@@ -3272,11 +3678,11 @@ function buildProgram(deps) {
|
|
|
3272
3678
|
}
|
|
3273
3679
|
|
|
3274
3680
|
// src/index.ts
|
|
3275
|
-
var __dirname3 =
|
|
3681
|
+
var __dirname3 = path20.dirname(fileURLToPath4(import.meta.url));
|
|
3276
3682
|
var require2 = createRequire3(import.meta.url);
|
|
3277
3683
|
function getVersion() {
|
|
3278
3684
|
try {
|
|
3279
|
-
const pkgPath =
|
|
3685
|
+
const pkgPath = path20.resolve(__dirname3, "../package.json");
|
|
3280
3686
|
const pkg = require2(pkgPath);
|
|
3281
3687
|
return pkg.version ?? "0.0.0";
|
|
3282
3688
|
} catch {
|