@nolto/cli 0.14.0 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +116 -18
  2. 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"]);
@@ -549,7 +552,7 @@ function checkKeys(value, allowed, at, errors) {
549
552
  function isValidPlanPath(value) {
550
553
  if (typeof value !== "string" || value.length === 0) return false;
551
554
  if (value.includes("\\") || value.startsWith("/") || /^[A-Za-z]:/.test(value)) return false;
552
- return value.split("/").every((segment) => segment !== "" && segment !== "." && segment !== "..");
555
+ return /\.(md|markdown)$/i.test(value) && value.split("/").every((segment, index) => segment !== "" && (!segment.startsWith(".") || index === 0 && segment === ".nolto"));
553
556
  }
554
557
  function daysInMonth(year, month) {
555
558
  if (month === 2) {
@@ -590,7 +593,7 @@ function validatePlanPath(value, at) {
590
593
  }
591
594
  if (!isValidPlanPath(value)) {
592
595
  return [
593
- `${at} must be a repository-relative path using '/' separators (no absolute paths, '\\', '.' or '..' segments).`
596
+ `${at} must be a repository-relative path using '/' separators (no absolute paths, '\\', segments starting with '.' except a leading '.nolto/'; Markdown '.md' / '.markdown' only).`
594
597
  ];
595
598
  }
596
599
  return [];
@@ -1100,6 +1103,17 @@ async function loadValidRoadmap(filePath, readFile13) {
1100
1103
  async function buildSyncBody(args) {
1101
1104
  const planDocuments = [];
1102
1105
  for (const ref of collectPlanRefs(args.roadmap)) {
1106
+ if (!isValidPlanPath(ref.path)) {
1107
+ args.deps.warn(`plan path not allowed (markdown only, no dot segments), skipping: ${ref.path}`);
1108
+ continue;
1109
+ }
1110
+ try {
1111
+ if (await args.deps.isIgnored?.(args.repoRoot, ref.path)) {
1112
+ args.deps.warn(`plan path is git-ignored, skipping: ${ref.path}`);
1113
+ continue;
1114
+ }
1115
+ } catch {
1116
+ }
1103
1117
  const root = path3.resolve(args.repoRoot);
1104
1118
  const absolute = path3.resolve(root, ref.path);
1105
1119
  if (absolute !== root && !absolute.startsWith(root + path3.sep)) {
@@ -1124,6 +1138,10 @@ async function buildSyncBody(args) {
1124
1138
  args.deps.warn(`symlink escapes repository root, skipping: ${ref.path}`);
1125
1139
  continue;
1126
1140
  }
1141
+ if (!isValidPlanPath(path3.relative(realRoot, real).split(path3.sep).join("/"))) {
1142
+ args.deps.warn(`plan path not allowed (markdown only, no dot segments), skipping: ${ref.path}`);
1143
+ continue;
1144
+ }
1127
1145
  }
1128
1146
  const content = await args.deps.readFile(absolute);
1129
1147
  planDocuments.push({
@@ -1201,7 +1219,10 @@ async function readCache(env, projectId, slug) {
1201
1219
  if ("currentTaskId" in parsed && parsed.currentTaskId !== null && typeof parsed.currentTaskId !== "string") {
1202
1220
  throw new Error("Invalid currentTaskId");
1203
1221
  }
1204
- meta = { ...parsed, currentTaskId: parsed.currentTaskId ?? null };
1222
+ if ("repoIdentity" in parsed && parsed.repoIdentity !== null && typeof parsed.repoIdentity !== "string") {
1223
+ throw new Error("Invalid repoIdentity");
1224
+ }
1225
+ meta = { ...parsed, currentTaskId: parsed.currentTaskId ?? null, repoIdentity: parsed.repoIdentity ?? null };
1205
1226
  } catch (err) {
1206
1227
  if (err.code !== "ENOENT") {
1207
1228
  throw new CliError(`Invalid cache metadata at ${paths.meta}: ${String(err)}`, 2);
@@ -1212,7 +1233,7 @@ async function readCache(env, projectId, slug) {
1212
1233
  async function writeCache(env, projectId, slug, roadmap, meta) {
1213
1234
  const paths = cachePaths(env, projectId, slug);
1214
1235
  const raw = serializeRoadmap(roadmap);
1215
- const metadata = { ...meta, currentTaskId: meta.currentTaskId ?? null, contentHash: sha256Hex(raw) };
1236
+ const metadata = { ...meta, currentTaskId: meta.currentTaskId ?? null, repoIdentity: meta.repoIdentity ?? null, contentHash: sha256Hex(raw) };
1216
1237
  await mkdir2(cacheDir(env, projectId), { recursive: true, mode: 448 });
1217
1238
  for (const [filePath, content] of [[paths.json, raw], [paths.meta, JSON.stringify(metadata, null, 2) + "\n"]]) {
1218
1239
  const temp = `${filePath}.tmp-${process.pid}-${randomUUID2()}`;
@@ -1265,13 +1286,15 @@ async function pullRoadmapCache(args) {
1265
1286
  await writeCache(env, projectId, slug, response.roadmap, {
1266
1287
  revision: response.revision,
1267
1288
  pulledAt: (/* @__PURE__ */ new Date()).toISOString(),
1268
- currentTaskId: response.currentTaskId
1289
+ currentTaskId: response.currentTaskId,
1290
+ repoIdentity: response.repoIdentity ?? null
1269
1291
  });
1270
1292
  args.log(unchanged ? `unchanged ${slug}` : `pulled ${slug} (rev ${response.revision})`);
1271
1293
  return true;
1272
1294
  }
1273
1295
  async function ensureRoadmapCache(args) {
1274
1296
  const { env, projectId } = args;
1297
+ const identity = repoIdentityToString(args.repoIdentity);
1275
1298
  const list = await args.http.get(`/api/projects/${projectId}/roadmaps`);
1276
1299
  const warn2 = (line) => {
1277
1300
  process.stderr.write(line + "\n");
@@ -1283,10 +1306,12 @@ async function ensureRoadmapCache(args) {
1283
1306
  if (!await pullRoadmapCache({ ...args, slug: slug2, warn: warn2, log, recoverInvalid: true })) skipped = true;
1284
1307
  }
1285
1308
  if (skipped) throw new CliError("Some roadmaps have local changes that are not synced.", 4);
1286
- return;
1309
+ if (list.roadmaps.some((row) => row.repoIdentity == null || row.repoIdentity === identity)) return;
1287
1310
  }
1288
1311
  const basename = path5.basename(args.repoRoot);
1289
- const slug = slugifyProjectId(basename);
1312
+ const slug = args.slug ?? slugifyProjectId(basename);
1313
+ const collision = list.roadmaps.find((row) => row.slug === slug);
1314
+ 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
1315
  let existing;
1291
1316
  try {
1292
1317
  existing = await readCache(env, projectId, slug);
@@ -1299,7 +1324,7 @@ async function ensureRoadmapCache(args) {
1299
1324
  throw new CliError("Roadmap has local changes that are not synced.", 4);
1300
1325
  }
1301
1326
  const roadmap = existing?.roadmap ?? buildScaffold(args.projectName, basename);
1302
- await writeCache(env, projectId, slug, roadmap, { revision: 0, pulledAt: (/* @__PURE__ */ new Date()).toISOString() });
1327
+ await writeCache(env, projectId, slug, roadmap, { repoIdentity: identity, revision: 0, pulledAt: (/* @__PURE__ */ new Date()).toISOString() });
1303
1328
  const response = await runSync({ ...args, slug, roadmap, baseRevision: 0 }, {
1304
1329
  http: args.http,
1305
1330
  readFile: (p) => readFile4(p, "utf8"),
@@ -1308,7 +1333,7 @@ async function ensureRoadmapCache(args) {
1308
1333
  log: () => void 0,
1309
1334
  warn: warn2
1310
1335
  });
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 });
1336
+ 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
1337
  log(`created ${slug} on server (rev ${response.revision})`);
1313
1338
  }
1314
1339
 
@@ -1633,7 +1658,7 @@ async function handleUnlink(projectBindingPath, mode2) {
1633
1658
  `);
1634
1659
  }
1635
1660
  }
1636
- async function performLink(deps, projectId, mode2) {
1661
+ async function performLink(deps, projectId, mode2, slug) {
1637
1662
  if (!UUID_RE2.test(projectId)) {
1638
1663
  throw new CliError(
1639
1664
  `Invalid project ID: "${projectId}". Must be a UUID (e.g. 00000000-0000-0000-0000-000000000001).`,
@@ -1691,6 +1716,7 @@ Proceeding anyway \u2014 verify the ID is correct.
1691
1716
  projectId,
1692
1717
  projectName,
1693
1718
  repoRoot: root,
1719
+ slug,
1694
1720
  repoIdentity: await makeRepoIdentityResolver(deps)(root),
1695
1721
  log: (line) => {
1696
1722
  if (mode2 !== "json") process.stdout.write(line + "\n");
@@ -1731,8 +1757,8 @@ Commit nolto.json to share the binding with your team.
1731
1757
  }
1732
1758
  function register2(program, deps) {
1733
1759
  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");
1760
+ "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"
1761
+ ).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
1762
  cmd.action(async (projectId) => {
1737
1763
  const { output } = deps;
1738
1764
  const projectBindingPath = deps.repoBinding?.path ?? deps.projectBindingPath ?? null;
@@ -1752,6 +1778,56 @@ function register2(program, deps) {
1752
1778
  await handleUnlink(projectBindingPath, mode2);
1753
1779
  return;
1754
1780
  }
1781
+ const opts = cmd.opts();
1782
+ if (opts["list"] || opts["add"] || opts["remove"] !== void 0 || opts["slug"] !== void 0) {
1783
+ if (projectId == null) {
1784
+ if (bindingError != null) throw invalidBindingError(projectBindingPath, bindingError);
1785
+ const binding = deps.repoBinding?.binding ?? (projectBindingPath ? await loadRepoBinding(projectBindingPath) : null);
1786
+ projectId = binding?.projectId;
1787
+ }
1788
+ if (projectId == null) throw new CliError("No project binding. Run `nolto link <projectId>` first.", 2);
1789
+ if (!UUID_RE2.test(projectId)) throw new CliError(`Invalid project ID: "${projectId}". Must be a UUID.`, 2);
1790
+ if (opts["add"]) {
1791
+ const root = findRepoRoot(resolveStartDir(process.env, process.cwd())).root;
1792
+ const repoIdentity = await makeRepoIdentityResolver(deps)(root);
1793
+ const repo = await deps.http.post(`/api/projects/${projectId}/repos`, {
1794
+ repoIdentity,
1795
+ ...opts["label"] !== void 0 ? { label: opts["label"] } : {}
1796
+ });
1797
+ printResult(mode2 === "json" ? { added: true, projectId, repo } : `Added ${repoIdentity.kind}:${repoIdentity.value} to project ${projectId}.`, mode2);
1798
+ return;
1799
+ }
1800
+ if (opts["list"] || opts["remove"] !== void 0) {
1801
+ const { repos } = await deps.http.get(`/api/projects/${projectId}`);
1802
+ if (opts["list"]) {
1803
+ if (mode2 === "json") printResult({ repos }, mode2);
1804
+ else for (const repo2 of repos) printResult(`${repo2.identity}${repo2.label ? ` (${repo2.label})` : ""} ${repo2.boundAt} ${repo2.id}`, mode2);
1805
+ return;
1806
+ }
1807
+ const input = opts["remove"];
1808
+ const identity = /^(remote|local):/.test(input) ? input : `remote:${input}`;
1809
+ const repo = repos.find((row) => row.id === input || row.identity === identity);
1810
+ if (!repo) throw new CliError(`Repository ${input} is not bound to this project.`, 2);
1811
+ if (!opts["yes"]) {
1812
+ if (mode2 === "json") throw new CliError("--remove requires confirmation. Pass --yes to skip the prompt in --json mode.", 2);
1813
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
1814
+ let confirmed = false;
1815
+ try {
1816
+ const answer = await rl.question(`Remove "${repo.identity}" from project ${projectId}? [y/N] `);
1817
+ confirmed = answer.trim().toLowerCase() === "y";
1818
+ } finally {
1819
+ rl.close();
1820
+ }
1821
+ if (!confirmed) {
1822
+ process.stdout.write("Aborted.\n");
1823
+ return;
1824
+ }
1825
+ }
1826
+ await deps.http.delete(`/api/projects/${projectId}/repos/${repo.id}`);
1827
+ printResult(mode2 === "json" ? { removed: true, projectId, repoId: repo.id } : `Removed ${repo.identity} from project ${projectId}.`, mode2);
1828
+ return;
1829
+ }
1830
+ }
1755
1831
  if (cmd.opts()["rebind"]) {
1756
1832
  const boundProjectId = deps.repoBinding?.binding?.projectId;
1757
1833
  const effectiveProjectId = projectId ?? boundProjectId;
@@ -1772,7 +1848,7 @@ function register2(program, deps) {
1772
1848
  2
1773
1849
  );
1774
1850
  }
1775
- await performLink(deps, projectId, mode2);
1851
+ await performLink(deps, projectId, mode2, opts["slug"]);
1776
1852
  });
1777
1853
  }
1778
1854
  function invalidBindingError(projectBindingPath, error) {
@@ -2427,6 +2503,10 @@ function collectContainedPlanAbsPaths(roadmaps, root, warn2) {
2427
2503
  warn2(`chokidar target outside repo, skipping: ${ref.path}`);
2428
2504
  continue;
2429
2505
  }
2506
+ if (!isValidPlanPath(ref.path)) {
2507
+ warn2(`plan path not allowed (markdown only, no dot segments), skipping: ${ref.path}`);
2508
+ continue;
2509
+ }
2430
2510
  planAbsPaths.add(absolute);
2431
2511
  }
2432
2512
  }
@@ -2434,6 +2514,8 @@ function collectContainedPlanAbsPaths(roadmaps, root, warn2) {
2434
2514
  }
2435
2515
  async function syncRepo(args, io) {
2436
2516
  const { projectId } = args;
2517
+ const repoIdentity = await io.repoIdentity(args.root);
2518
+ const identity = repoIdentityToString(repoIdentity);
2437
2519
  const slugs = args.slugs ?? await listCachedSlugs(io.env, projectId);
2438
2520
  if (slugs.length === 0) {
2439
2521
  let legacyFiles = [];
@@ -2451,19 +2533,33 @@ async function syncRepo(args, io) {
2451
2533
  for (const slug of slugs) {
2452
2534
  const entry = await readCache(io.env, projectId, slug);
2453
2535
  if (!entry) throw new CliError(`No cached roadmap "${slug}". Run \`nolto roadmap pull ${slug}\`.`, 2);
2536
+ if (args.slugs === void 0 && entry.meta?.repoIdentity != null && entry.meta.repoIdentity !== identity) {
2537
+ io.log(`skipped ${slug} (belongs to ${entry.meta.repoIdentity})`);
2538
+ continue;
2539
+ }
2454
2540
  roadmaps.push({ slug, ...entry });
2455
2541
  }
2542
+ 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);
2543
+ const exec = io.exec;
2544
+ const isIgnored = exec === void 0 ? void 0 : async (root, relPath) => {
2545
+ try {
2546
+ await exec("git", ["check-ignore", "-q", "--", relPath], { cwd: root });
2547
+ return true;
2548
+ } catch {
2549
+ return false;
2550
+ }
2551
+ };
2456
2552
  const results = [];
2457
- const repoIdentity = await io.repoIdentity(args.root);
2458
2553
  for (const entry of roadmaps) {
2459
2554
  const { slug, roadmap, meta } = entry;
2460
2555
  if (args.onlyDirty && !isDirty(entry)) continue;
2461
2556
  try {
2462
2557
  const response = await runSync(
2463
2558
  { repoRoot: args.root, projectId, slug, roadmap, repoIdentity, baseRevision: meta?.revision ?? 0 },
2464
- { http: io.http, readFile: io.readFile, fileExists: io.fileExists, realpath: io.realpath, log: io.log, warn: io.warn }
2559
+ { http: io.http, readFile: io.readFile, fileExists: io.fileExists, realpath: io.realpath, ...isIgnored ? { isIgnored } : {}, log: io.log, warn: io.warn }
2465
2560
  );
2466
2561
  await writeCache(io.env, projectId, slug, response.roadmap ?? roadmap, {
2562
+ repoIdentity: identity,
2467
2563
  revision: response.revision,
2468
2564
  pulledAt: (/* @__PURE__ */ new Date()).toISOString(),
2469
2565
  currentTaskId: response.currentTaskId !== void 0 ? response.currentTaskId : meta?.currentTaskId
@@ -2499,7 +2595,7 @@ async function syncRepo(args, io) {
2499
2595
  for (let offset = 0; offset < body.links.length; offset += 500) {
2500
2596
  const response = await io.http.post(
2501
2597
  `/api/projects/${projectId}/git-links`,
2502
- { links: body.links.slice(offset, offset + 500) }
2598
+ { links: body.links.slice(offset, offset + 500), repoIdentity }
2503
2599
  );
2504
2600
  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
2601
  gitLinks = { linked: gitLinks.linked + response.linked, existing: gitLinks.existing + response.existing, skipped: gitLinks.skipped + response.skipped };
@@ -2880,6 +2976,7 @@ async function patchTask(args) {
2880
2976
  const { errors } = validateRoadmap(response.roadmap);
2881
2977
  if (errors.length) throw new CliError(`Server roadmap "${slug}" failed validation: ${errors.join("; ")}`, 5);
2882
2978
  await writeCache(env, projectId, slug, response.roadmap, {
2979
+ repoIdentity: entry?.meta?.repoIdentity ?? null,
2883
2980
  revision: response.revision,
2884
2981
  pulledAt: (/* @__PURE__ */ new Date()).toISOString(),
2885
2982
  currentTaskId: response.currentTaskId
@@ -2951,11 +3048,12 @@ async function roadmapMigrate(deps, yes = false) {
2951
3048
  rl.close();
2952
3049
  }
2953
3050
  }
3051
+ const repoIdentity = (await readCache(process.env, projectId, slug))?.meta?.repoIdentity ?? null;
2954
3052
  let revision = server?.revision ?? 0;
2955
3053
  let saved = unchanged ? server.roadmap : roadmap;
2956
3054
  let currentTaskId = server?.currentTaskId;
2957
3055
  if (unchanged || !server) {
2958
- await writeCache(process.env, projectId, slug, saved, { revision, pulledAt: (/* @__PURE__ */ new Date()).toISOString(), currentTaskId });
3056
+ await writeCache(process.env, projectId, slug, saved, { repoIdentity, revision, pulledAt: (/* @__PURE__ */ new Date()).toISOString(), currentTaskId });
2959
3057
  }
2960
3058
  if (!unchanged) {
2961
3059
  const response = await runSync({ repoRoot: root, projectId, slug, roadmap, baseRevision: revision, repoIdentity: await makeRepoIdentityResolver(deps)(root) }, {
@@ -2969,7 +3067,7 @@ async function roadmapMigrate(deps, yes = false) {
2969
3067
  revision = response.revision;
2970
3068
  saved = response.roadmap ?? roadmap;
2971
3069
  if (response.currentTaskId !== void 0) currentTaskId = response.currentTaskId;
2972
- await writeCache(process.env, projectId, slug, saved, { revision, pulledAt: (/* @__PURE__ */ new Date()).toISOString(), currentTaskId });
3070
+ await writeCache(process.env, projectId, slug, saved, { repoIdentity, revision, pulledAt: (/* @__PURE__ */ new Date()).toISOString(), currentTaskId });
2973
3071
  }
2974
3072
  const action = unchanged ? "unchanged" : server ? "replaced" : "created";
2975
3073
  results.push({ slug, action, revision });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nolto/cli",
3
- "version": "0.14.0",
3
+ "version": "0.15.1",
4
4
  "description": "CLI for syncing repository roadmaps with Nolto.",
5
5
  "license": "MIT",
6
6
  "type": "module",