@nolto/cli 0.14.0 → 0.15.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/dist/index.js +85 -15
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -525,6 +525,9 @@ function normalizeRemote(raw) {
|
|
|
525
525
|
if (HOSTED_LOWERCASE_PATH.has(host)) path21 = path21.toLowerCase();
|
|
526
526
|
return `${host}/${path21}`;
|
|
527
527
|
}
|
|
528
|
+
function repoIdentityToString(id) {
|
|
529
|
+
return `${id.kind}:${id.value}`;
|
|
530
|
+
}
|
|
528
531
|
|
|
529
532
|
// ../roadmap-schema/src/index.ts
|
|
530
533
|
var STATUSES = /* @__PURE__ */ new Set(["todo", "in-progress", "done", "blocked"]);
|
|
@@ -1201,7 +1204,10 @@ async function readCache(env, projectId, slug) {
|
|
|
1201
1204
|
if ("currentTaskId" in parsed && parsed.currentTaskId !== null && typeof parsed.currentTaskId !== "string") {
|
|
1202
1205
|
throw new Error("Invalid currentTaskId");
|
|
1203
1206
|
}
|
|
1204
|
-
|
|
1207
|
+
if ("repoIdentity" in parsed && parsed.repoIdentity !== null && typeof parsed.repoIdentity !== "string") {
|
|
1208
|
+
throw new Error("Invalid repoIdentity");
|
|
1209
|
+
}
|
|
1210
|
+
meta = { ...parsed, currentTaskId: parsed.currentTaskId ?? null, repoIdentity: parsed.repoIdentity ?? null };
|
|
1205
1211
|
} catch (err) {
|
|
1206
1212
|
if (err.code !== "ENOENT") {
|
|
1207
1213
|
throw new CliError(`Invalid cache metadata at ${paths.meta}: ${String(err)}`, 2);
|
|
@@ -1212,7 +1218,7 @@ async function readCache(env, projectId, slug) {
|
|
|
1212
1218
|
async function writeCache(env, projectId, slug, roadmap, meta) {
|
|
1213
1219
|
const paths = cachePaths(env, projectId, slug);
|
|
1214
1220
|
const raw = serializeRoadmap(roadmap);
|
|
1215
|
-
const metadata = { ...meta, currentTaskId: meta.currentTaskId ?? null, contentHash: sha256Hex(raw) };
|
|
1221
|
+
const metadata = { ...meta, currentTaskId: meta.currentTaskId ?? null, repoIdentity: meta.repoIdentity ?? null, contentHash: sha256Hex(raw) };
|
|
1216
1222
|
await mkdir2(cacheDir(env, projectId), { recursive: true, mode: 448 });
|
|
1217
1223
|
for (const [filePath, content] of [[paths.json, raw], [paths.meta, JSON.stringify(metadata, null, 2) + "\n"]]) {
|
|
1218
1224
|
const temp = `${filePath}.tmp-${process.pid}-${randomUUID2()}`;
|
|
@@ -1265,13 +1271,15 @@ async function pullRoadmapCache(args) {
|
|
|
1265
1271
|
await writeCache(env, projectId, slug, response.roadmap, {
|
|
1266
1272
|
revision: response.revision,
|
|
1267
1273
|
pulledAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1268
|
-
currentTaskId: response.currentTaskId
|
|
1274
|
+
currentTaskId: response.currentTaskId,
|
|
1275
|
+
repoIdentity: response.repoIdentity ?? null
|
|
1269
1276
|
});
|
|
1270
1277
|
args.log(unchanged ? `unchanged ${slug}` : `pulled ${slug} (rev ${response.revision})`);
|
|
1271
1278
|
return true;
|
|
1272
1279
|
}
|
|
1273
1280
|
async function ensureRoadmapCache(args) {
|
|
1274
1281
|
const { env, projectId } = args;
|
|
1282
|
+
const identity = repoIdentityToString(args.repoIdentity);
|
|
1275
1283
|
const list = await args.http.get(`/api/projects/${projectId}/roadmaps`);
|
|
1276
1284
|
const warn2 = (line) => {
|
|
1277
1285
|
process.stderr.write(line + "\n");
|
|
@@ -1283,10 +1291,12 @@ async function ensureRoadmapCache(args) {
|
|
|
1283
1291
|
if (!await pullRoadmapCache({ ...args, slug: slug2, warn: warn2, log, recoverInvalid: true })) skipped = true;
|
|
1284
1292
|
}
|
|
1285
1293
|
if (skipped) throw new CliError("Some roadmaps have local changes that are not synced.", 4);
|
|
1286
|
-
return;
|
|
1294
|
+
if (list.roadmaps.some((row) => row.repoIdentity == null || row.repoIdentity === identity)) return;
|
|
1287
1295
|
}
|
|
1288
1296
|
const basename = path5.basename(args.repoRoot);
|
|
1289
|
-
const slug = slugifyProjectId(basename);
|
|
1297
|
+
const slug = args.slug ?? slugifyProjectId(basename);
|
|
1298
|
+
const collision = list.roadmaps.find((row) => row.slug === slug);
|
|
1299
|
+
if (collision) throw new CliError(`Roadmap slug "${slug}" already exists in this project (repo: ${collision.repoIdentity ?? "unknown"}). Run \`nolto link --slug <other-slug>\` to name this repository's roadmap.`, 2);
|
|
1290
1300
|
let existing;
|
|
1291
1301
|
try {
|
|
1292
1302
|
existing = await readCache(env, projectId, slug);
|
|
@@ -1299,7 +1309,7 @@ async function ensureRoadmapCache(args) {
|
|
|
1299
1309
|
throw new CliError("Roadmap has local changes that are not synced.", 4);
|
|
1300
1310
|
}
|
|
1301
1311
|
const roadmap = existing?.roadmap ?? buildScaffold(args.projectName, basename);
|
|
1302
|
-
await writeCache(env, projectId, slug, roadmap, { revision: 0, pulledAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
1312
|
+
await writeCache(env, projectId, slug, roadmap, { repoIdentity: identity, revision: 0, pulledAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
1303
1313
|
const response = await runSync({ ...args, slug, roadmap, baseRevision: 0 }, {
|
|
1304
1314
|
http: args.http,
|
|
1305
1315
|
readFile: (p) => readFile4(p, "utf8"),
|
|
@@ -1308,7 +1318,7 @@ async function ensureRoadmapCache(args) {
|
|
|
1308
1318
|
log: () => void 0,
|
|
1309
1319
|
warn: warn2
|
|
1310
1320
|
});
|
|
1311
|
-
await writeCache(env, projectId, slug, response.roadmap ?? roadmap, { revision: response.revision, pulledAt: (/* @__PURE__ */ new Date()).toISOString(), currentTaskId: response.currentTaskId !== void 0 ? response.currentTaskId : existing?.meta?.currentTaskId });
|
|
1321
|
+
await writeCache(env, projectId, slug, response.roadmap ?? roadmap, { repoIdentity: identity, revision: response.revision, pulledAt: (/* @__PURE__ */ new Date()).toISOString(), currentTaskId: response.currentTaskId !== void 0 ? response.currentTaskId : existing?.meta?.currentTaskId });
|
|
1312
1322
|
log(`created ${slug} on server (rev ${response.revision})`);
|
|
1313
1323
|
}
|
|
1314
1324
|
|
|
@@ -1633,7 +1643,7 @@ async function handleUnlink(projectBindingPath, mode2) {
|
|
|
1633
1643
|
`);
|
|
1634
1644
|
}
|
|
1635
1645
|
}
|
|
1636
|
-
async function performLink(deps, projectId, mode2) {
|
|
1646
|
+
async function performLink(deps, projectId, mode2, slug) {
|
|
1637
1647
|
if (!UUID_RE2.test(projectId)) {
|
|
1638
1648
|
throw new CliError(
|
|
1639
1649
|
`Invalid project ID: "${projectId}". Must be a UUID (e.g. 00000000-0000-0000-0000-000000000001).`,
|
|
@@ -1691,6 +1701,7 @@ Proceeding anyway \u2014 verify the ID is correct.
|
|
|
1691
1701
|
projectId,
|
|
1692
1702
|
projectName,
|
|
1693
1703
|
repoRoot: root,
|
|
1704
|
+
slug,
|
|
1694
1705
|
repoIdentity: await makeRepoIdentityResolver(deps)(root),
|
|
1695
1706
|
log: (line) => {
|
|
1696
1707
|
if (mode2 !== "json") process.stdout.write(line + "\n");
|
|
@@ -1731,8 +1742,8 @@ Commit nolto.json to share the binding with your team.
|
|
|
1731
1742
|
}
|
|
1732
1743
|
function register2(program, deps) {
|
|
1733
1744
|
const cmd = program.command("link [projectId]").description(
|
|
1734
|
-
"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"
|
|
1735
|
-
).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");
|
|
1745
|
+
"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 --list List project repositories\n nolto link --add Add this repository to the project\n nolto link --remove <identity-or-id> Remove a project repository\n nolto link --unlink Remove the projectId from nolto.json"
|
|
1746
|
+
).option("--slug <slug>", "Name this repository's roadmap").option("--list", "List project repositories").option("--add", "Add this repository to the project").option("--label <text>", "Label the added repository").option("--remove <identity-or-id>", "Remove a project repository").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");
|
|
1736
1747
|
cmd.action(async (projectId) => {
|
|
1737
1748
|
const { output } = deps;
|
|
1738
1749
|
const projectBindingPath = deps.repoBinding?.path ?? deps.projectBindingPath ?? null;
|
|
@@ -1752,6 +1763,56 @@ function register2(program, deps) {
|
|
|
1752
1763
|
await handleUnlink(projectBindingPath, mode2);
|
|
1753
1764
|
return;
|
|
1754
1765
|
}
|
|
1766
|
+
const opts = cmd.opts();
|
|
1767
|
+
if (opts["list"] || opts["add"] || opts["remove"] !== void 0 || opts["slug"] !== void 0) {
|
|
1768
|
+
if (projectId == null) {
|
|
1769
|
+
if (bindingError != null) throw invalidBindingError(projectBindingPath, bindingError);
|
|
1770
|
+
const binding = deps.repoBinding?.binding ?? (projectBindingPath ? await loadRepoBinding(projectBindingPath) : null);
|
|
1771
|
+
projectId = binding?.projectId;
|
|
1772
|
+
}
|
|
1773
|
+
if (projectId == null) throw new CliError("No project binding. Run `nolto link <projectId>` first.", 2);
|
|
1774
|
+
if (!UUID_RE2.test(projectId)) throw new CliError(`Invalid project ID: "${projectId}". Must be a UUID.`, 2);
|
|
1775
|
+
if (opts["add"]) {
|
|
1776
|
+
const root = findRepoRoot(resolveStartDir(process.env, process.cwd())).root;
|
|
1777
|
+
const repoIdentity = await makeRepoIdentityResolver(deps)(root);
|
|
1778
|
+
const repo = await deps.http.post(`/api/projects/${projectId}/repos`, {
|
|
1779
|
+
repoIdentity,
|
|
1780
|
+
...opts["label"] !== void 0 ? { label: opts["label"] } : {}
|
|
1781
|
+
});
|
|
1782
|
+
printResult(mode2 === "json" ? { added: true, projectId, repo } : `Added ${repoIdentity.kind}:${repoIdentity.value} to project ${projectId}.`, mode2);
|
|
1783
|
+
return;
|
|
1784
|
+
}
|
|
1785
|
+
if (opts["list"] || opts["remove"] !== void 0) {
|
|
1786
|
+
const { repos } = await deps.http.get(`/api/projects/${projectId}`);
|
|
1787
|
+
if (opts["list"]) {
|
|
1788
|
+
if (mode2 === "json") printResult({ repos }, mode2);
|
|
1789
|
+
else for (const repo2 of repos) printResult(`${repo2.identity}${repo2.label ? ` (${repo2.label})` : ""} ${repo2.boundAt} ${repo2.id}`, mode2);
|
|
1790
|
+
return;
|
|
1791
|
+
}
|
|
1792
|
+
const input = opts["remove"];
|
|
1793
|
+
const identity = /^(remote|local):/.test(input) ? input : `remote:${input}`;
|
|
1794
|
+
const repo = repos.find((row) => row.id === input || row.identity === identity);
|
|
1795
|
+
if (!repo) throw new CliError(`Repository ${input} is not bound to this project.`, 2);
|
|
1796
|
+
if (!opts["yes"]) {
|
|
1797
|
+
if (mode2 === "json") throw new CliError("--remove requires confirmation. Pass --yes to skip the prompt in --json mode.", 2);
|
|
1798
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
1799
|
+
let confirmed = false;
|
|
1800
|
+
try {
|
|
1801
|
+
const answer = await rl.question(`Remove "${repo.identity}" from project ${projectId}? [y/N] `);
|
|
1802
|
+
confirmed = answer.trim().toLowerCase() === "y";
|
|
1803
|
+
} finally {
|
|
1804
|
+
rl.close();
|
|
1805
|
+
}
|
|
1806
|
+
if (!confirmed) {
|
|
1807
|
+
process.stdout.write("Aborted.\n");
|
|
1808
|
+
return;
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
await deps.http.delete(`/api/projects/${projectId}/repos/${repo.id}`);
|
|
1812
|
+
printResult(mode2 === "json" ? { removed: true, projectId, repoId: repo.id } : `Removed ${repo.identity} from project ${projectId}.`, mode2);
|
|
1813
|
+
return;
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1755
1816
|
if (cmd.opts()["rebind"]) {
|
|
1756
1817
|
const boundProjectId = deps.repoBinding?.binding?.projectId;
|
|
1757
1818
|
const effectiveProjectId = projectId ?? boundProjectId;
|
|
@@ -1772,7 +1833,7 @@ function register2(program, deps) {
|
|
|
1772
1833
|
2
|
|
1773
1834
|
);
|
|
1774
1835
|
}
|
|
1775
|
-
await performLink(deps, projectId, mode2);
|
|
1836
|
+
await performLink(deps, projectId, mode2, opts["slug"]);
|
|
1776
1837
|
});
|
|
1777
1838
|
}
|
|
1778
1839
|
function invalidBindingError(projectBindingPath, error) {
|
|
@@ -2434,6 +2495,8 @@ function collectContainedPlanAbsPaths(roadmaps, root, warn2) {
|
|
|
2434
2495
|
}
|
|
2435
2496
|
async function syncRepo(args, io) {
|
|
2436
2497
|
const { projectId } = args;
|
|
2498
|
+
const repoIdentity = await io.repoIdentity(args.root);
|
|
2499
|
+
const identity = repoIdentityToString(repoIdentity);
|
|
2437
2500
|
const slugs = args.slugs ?? await listCachedSlugs(io.env, projectId);
|
|
2438
2501
|
if (slugs.length === 0) {
|
|
2439
2502
|
let legacyFiles = [];
|
|
@@ -2451,10 +2514,14 @@ async function syncRepo(args, io) {
|
|
|
2451
2514
|
for (const slug of slugs) {
|
|
2452
2515
|
const entry = await readCache(io.env, projectId, slug);
|
|
2453
2516
|
if (!entry) throw new CliError(`No cached roadmap "${slug}". Run \`nolto roadmap pull ${slug}\`.`, 2);
|
|
2517
|
+
if (args.slugs === void 0 && entry.meta?.repoIdentity != null && entry.meta.repoIdentity !== identity) {
|
|
2518
|
+
io.log(`skipped ${slug} (belongs to ${entry.meta.repoIdentity})`);
|
|
2519
|
+
continue;
|
|
2520
|
+
}
|
|
2454
2521
|
roadmaps.push({ slug, ...entry });
|
|
2455
2522
|
}
|
|
2523
|
+
if (roadmaps.length === 0) throw new CliError("No cached roadmap belongs to this repository. Run `nolto link --slug <slug>` to create one, or `nolto pull`.", 2);
|
|
2456
2524
|
const results = [];
|
|
2457
|
-
const repoIdentity = await io.repoIdentity(args.root);
|
|
2458
2525
|
for (const entry of roadmaps) {
|
|
2459
2526
|
const { slug, roadmap, meta } = entry;
|
|
2460
2527
|
if (args.onlyDirty && !isDirty(entry)) continue;
|
|
@@ -2464,6 +2531,7 @@ async function syncRepo(args, io) {
|
|
|
2464
2531
|
{ http: io.http, readFile: io.readFile, fileExists: io.fileExists, realpath: io.realpath, log: io.log, warn: io.warn }
|
|
2465
2532
|
);
|
|
2466
2533
|
await writeCache(io.env, projectId, slug, response.roadmap ?? roadmap, {
|
|
2534
|
+
repoIdentity: identity,
|
|
2467
2535
|
revision: response.revision,
|
|
2468
2536
|
pulledAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2469
2537
|
currentTaskId: response.currentTaskId !== void 0 ? response.currentTaskId : meta?.currentTaskId
|
|
@@ -2499,7 +2567,7 @@ async function syncRepo(args, io) {
|
|
|
2499
2567
|
for (let offset = 0; offset < body.links.length; offset += 500) {
|
|
2500
2568
|
const response = await io.http.post(
|
|
2501
2569
|
`/api/projects/${projectId}/git-links`,
|
|
2502
|
-
{ links: body.links.slice(offset, offset + 500) }
|
|
2570
|
+
{ links: body.links.slice(offset, offset + 500), repoIdentity }
|
|
2503
2571
|
);
|
|
2504
2572
|
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");
|
|
2505
2573
|
gitLinks = { linked: gitLinks.linked + response.linked, existing: gitLinks.existing + response.existing, skipped: gitLinks.skipped + response.skipped };
|
|
@@ -2880,6 +2948,7 @@ async function patchTask(args) {
|
|
|
2880
2948
|
const { errors } = validateRoadmap(response.roadmap);
|
|
2881
2949
|
if (errors.length) throw new CliError(`Server roadmap "${slug}" failed validation: ${errors.join("; ")}`, 5);
|
|
2882
2950
|
await writeCache(env, projectId, slug, response.roadmap, {
|
|
2951
|
+
repoIdentity: entry?.meta?.repoIdentity ?? null,
|
|
2883
2952
|
revision: response.revision,
|
|
2884
2953
|
pulledAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2885
2954
|
currentTaskId: response.currentTaskId
|
|
@@ -2951,11 +3020,12 @@ async function roadmapMigrate(deps, yes = false) {
|
|
|
2951
3020
|
rl.close();
|
|
2952
3021
|
}
|
|
2953
3022
|
}
|
|
3023
|
+
const repoIdentity = (await readCache(process.env, projectId, slug))?.meta?.repoIdentity ?? null;
|
|
2954
3024
|
let revision = server?.revision ?? 0;
|
|
2955
3025
|
let saved = unchanged ? server.roadmap : roadmap;
|
|
2956
3026
|
let currentTaskId = server?.currentTaskId;
|
|
2957
3027
|
if (unchanged || !server) {
|
|
2958
|
-
await writeCache(process.env, projectId, slug, saved, { revision, pulledAt: (/* @__PURE__ */ new Date()).toISOString(), currentTaskId });
|
|
3028
|
+
await writeCache(process.env, projectId, slug, saved, { repoIdentity, revision, pulledAt: (/* @__PURE__ */ new Date()).toISOString(), currentTaskId });
|
|
2959
3029
|
}
|
|
2960
3030
|
if (!unchanged) {
|
|
2961
3031
|
const response = await runSync({ repoRoot: root, projectId, slug, roadmap, baseRevision: revision, repoIdentity: await makeRepoIdentityResolver(deps)(root) }, {
|
|
@@ -2969,7 +3039,7 @@ async function roadmapMigrate(deps, yes = false) {
|
|
|
2969
3039
|
revision = response.revision;
|
|
2970
3040
|
saved = response.roadmap ?? roadmap;
|
|
2971
3041
|
if (response.currentTaskId !== void 0) currentTaskId = response.currentTaskId;
|
|
2972
|
-
await writeCache(process.env, projectId, slug, saved, { revision, pulledAt: (/* @__PURE__ */ new Date()).toISOString(), currentTaskId });
|
|
3042
|
+
await writeCache(process.env, projectId, slug, saved, { repoIdentity, revision, pulledAt: (/* @__PURE__ */ new Date()).toISOString(), currentTaskId });
|
|
2973
3043
|
}
|
|
2974
3044
|
const action = unchanged ? "unchanged" : server ? "replaced" : "created";
|
|
2975
3045
|
results.push({ slug, action, revision });
|