@nolto/cli 0.25.0 → 0.25.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 +155 -38
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -745,6 +745,9 @@ function maskToken(token) {
745
745
  }
746
746
 
747
747
  // src/http.ts
748
+ function redirectError(base) {
749
+ return new CliError(`The server at ${base} returned an unexpected redirect; refusing to follow it.`, 5);
750
+ }
748
751
  function createHttpClient(opts) {
749
752
  const { baseUrl, version, token } = opts;
750
753
  const base = baseUrl.replace(/\/+$/, "");
@@ -767,9 +770,15 @@ function createHttpClient(opts) {
767
770
  method,
768
771
  headers: headers2,
769
772
  body: body === void 0 ? void 0 : JSON.stringify(body),
773
+ // Never follow a redirect: it would forward the Authorization header to another origin.
774
+ redirect: "error",
770
775
  ...signal ? { signal } : {}
771
776
  });
772
777
  } catch (err) {
778
+ if (err instanceof TypeError) {
779
+ const cause = err.cause;
780
+ if (/redirect/i.test(String(cause?.message ?? err.message))) throw redirectError(base);
781
+ }
773
782
  if (isNetworkError(err)) {
774
783
  throw new CliError(
775
784
  `Network error contacting ${base}: ${err instanceof Error ? err.message : String(err)}`,
@@ -786,6 +795,7 @@ function createHttpClient(opts) {
786
795
  }
787
796
  throw err;
788
797
  }
798
+ if (response.status >= 300 && response.status < 400) throw redirectError(base);
789
799
  if (!response.ok) {
790
800
  const retryAfter = response.headers.get("retry-after") ?? void 0;
791
801
  const wwwAuthenticate = response.headers.get("www-authenticate") ?? void 0;
@@ -1187,6 +1197,40 @@ function serializeRoadmap(roadmap) {
1187
1197
  return JSON.stringify(ordered, null, 2) + "\n";
1188
1198
  }
1189
1199
 
1200
+ // src/git-ignore.ts
1201
+ import { execFile } from "child_process";
1202
+ import { promisify } from "util";
1203
+ async function probeWorkTree(exec, root) {
1204
+ try {
1205
+ const result = await exec("git", ["rev-parse", "--is-inside-work-tree"], { cwd: root, env: { ...process.env, LC_ALL: "C" } });
1206
+ const stdout2 = result?.stdout;
1207
+ return typeof stdout2 === "string" && stdout2.trim() === "false" ? "outside" : "inside";
1208
+ } catch (err) {
1209
+ const { code, stderr } = err ?? {};
1210
+ if (code === "ENOENT" || typeof stderr === "string" && stderr.includes("not a git repository")) return "outside";
1211
+ return "broken";
1212
+ }
1213
+ }
1214
+ function makeIgnoreChecker(exec = promisify(execFile)) {
1215
+ const workTrees = /* @__PURE__ */ new Map();
1216
+ return async (root, relPath) => {
1217
+ let probe = workTrees.get(root);
1218
+ if (probe === void 0) {
1219
+ probe = probeWorkTree(exec, root);
1220
+ workTrees.set(root, probe);
1221
+ }
1222
+ const state = await probe;
1223
+ if (state === "outside") return "not-ignored";
1224
+ if (state === "broken") return "unknown";
1225
+ try {
1226
+ await exec("git", ["check-ignore", "-q", "--", relPath], { cwd: root });
1227
+ return "ignored";
1228
+ } catch (err) {
1229
+ return err?.code === 1 ? "not-ignored" : "unknown";
1230
+ }
1231
+ };
1232
+ }
1233
+
1190
1234
  // src/issue-core.ts
1191
1235
  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);
1192
1236
  function parseIssueRef(input) {
@@ -1392,12 +1436,18 @@ async function buildSyncBody(args) {
1392
1436
  args.deps.warn(`plan path not allowed (markdown only, no dot segments), skipping: ${ref.path}`);
1393
1437
  continue;
1394
1438
  }
1395
- try {
1396
- if (await args.deps.isIgnored?.(args.repoRoot, ref.path)) {
1397
- args.deps.warn(`plan path is git-ignored, skipping: ${ref.path}`);
1398
- continue;
1439
+ const check = async (relPath) => {
1440
+ if (args.deps.isIgnored === void 0) return "not-ignored";
1441
+ try {
1442
+ return await args.deps.isIgnored(args.repoRoot, relPath);
1443
+ } catch {
1444
+ return "unknown";
1399
1445
  }
1400
- } catch {
1446
+ };
1447
+ const refVerdict = await check(ref.path);
1448
+ if (refVerdict === "ignored") {
1449
+ args.deps.warn(`plan path is git-ignored, skipping: ${ref.path}`);
1450
+ continue;
1401
1451
  }
1402
1452
  const root = path5.resolve(args.repoRoot);
1403
1453
  const absolute = path5.resolve(root, ref.path);
@@ -1409,6 +1459,7 @@ async function buildSyncBody(args) {
1409
1459
  args.deps.warn(`plan file not found, skipping: ${ref.path}`);
1410
1460
  continue;
1411
1461
  }
1462
+ let readPath = absolute;
1412
1463
  if (args.deps.realpath !== void 0) {
1413
1464
  let real;
1414
1465
  let realRoot;
@@ -1423,12 +1474,26 @@ async function buildSyncBody(args) {
1423
1474
  args.deps.warn(`symlink escapes repository root, skipping: ${ref.path}`);
1424
1475
  continue;
1425
1476
  }
1426
- if (!isValidPlanPath(path5.relative(realRoot, real).split(path5.sep).join("/"))) {
1477
+ const realRel = path5.relative(realRoot, real).split(path5.sep).join("/");
1478
+ if (!isValidPlanPath(realRel)) {
1427
1479
  args.deps.warn(`plan path not allowed (markdown only, no dot segments), skipping: ${ref.path}`);
1428
1480
  continue;
1429
1481
  }
1482
+ const verdict = realRel === ref.path ? refVerdict : await check(realRel);
1483
+ if (verdict === "ignored") {
1484
+ args.deps.warn(`plan path is git-ignored, skipping: ${ref.path}`);
1485
+ continue;
1486
+ }
1487
+ if (verdict === "unknown") {
1488
+ args.deps.warn(`cannot determine whether plan path is git-ignored, skipping: ${ref.path}`);
1489
+ continue;
1490
+ }
1491
+ readPath = real;
1492
+ } else if (refVerdict === "unknown") {
1493
+ args.deps.warn(`cannot determine whether plan path is git-ignored, skipping: ${ref.path}`);
1494
+ continue;
1430
1495
  }
1431
- const content = await args.deps.readFile(absolute);
1496
+ const content = await args.deps.readFile(readPath);
1432
1497
  planDocuments.push({
1433
1498
  path: ref.path,
1434
1499
  taskId: ref.ownerId,
@@ -1535,6 +1600,37 @@ async function writeCache(env, projectId, slug, roadmap, meta) {
1535
1600
  }
1536
1601
  }
1537
1602
  }
1603
+ function normalizeIdentity(identity) {
1604
+ if (!identity.startsWith("remote:")) return identity;
1605
+ const normalized = normalizeRemote(identity.slice("remote:".length));
1606
+ return normalized === null ? identity : `remote:${normalized}`;
1607
+ }
1608
+ async function rewriteCachedRepoIdentity(env, projectId, from, to) {
1609
+ const fromKey = normalizeIdentity(from);
1610
+ const updated = [];
1611
+ const failed = [];
1612
+ for (const slug of await listCachedSlugs(env, projectId)) {
1613
+ let entry;
1614
+ try {
1615
+ entry = await readCache(env, projectId, slug);
1616
+ } catch {
1617
+ continue;
1618
+ }
1619
+ if (entry?.meta == null || entry.meta.repoIdentity == null || normalizeIdentity(entry.meta.repoIdentity) !== fromKey) continue;
1620
+ const metaPath = cachePaths(env, projectId, slug).meta;
1621
+ const temp = `${metaPath}.tmp-${process.pid}-${randomUUID2()}`;
1622
+ try {
1623
+ await writeFile4(temp, JSON.stringify({ ...entry.meta, repoIdentity: to }, null, 2) + "\n", { mode: 384 });
1624
+ await rename(temp, metaPath);
1625
+ updated.push(slug);
1626
+ } catch {
1627
+ failed.push(slug);
1628
+ } finally {
1629
+ await unlink(temp).catch(() => void 0);
1630
+ }
1631
+ }
1632
+ return { updated, failed };
1633
+ }
1538
1634
  function isDirty(entry) {
1539
1635
  return entry.meta === null || sha256Hex(entry.raw) !== entry.meta.contentHash;
1540
1636
  }
@@ -1640,6 +1736,7 @@ async function ensureRoadmapCache(args) {
1640
1736
  readFile: (p) => readFile6(p, "utf8"),
1641
1737
  realpath,
1642
1738
  fileExists: existsSync3,
1739
+ isIgnored: makeIgnoreChecker(),
1643
1740
  log: () => void 0,
1644
1741
  warn: warn2
1645
1742
  });
@@ -1764,7 +1861,7 @@ async function removeRepoFromRegistry(filePath, root) {
1764
1861
  }
1765
1862
 
1766
1863
  // src/repo-identity.ts
1767
- import { execFile } from "child_process";
1864
+ import { execFile as execFile2 } from "child_process";
1768
1865
  import { realpathSync } from "fs";
1769
1866
  import path10 from "path";
1770
1867
 
@@ -1831,7 +1928,7 @@ function loadOrCreateMachineId(configDir) {
1831
1928
  // src/repo-identity.ts
1832
1929
  function defaultGetRemoteUrl(root) {
1833
1930
  return new Promise((resolve) => {
1834
- execFile(
1931
+ execFile2(
1835
1932
  "git",
1836
1933
  ["-C", root, "remote", "get-url", "origin"],
1837
1934
  { timeout: 5e3 },
@@ -1981,10 +2078,32 @@ async function handleRebind(deps, projectId, root, mode2, yes) {
1981
2078
  }
1982
2079
  }
1983
2080
  await deps.http.post(`/api/projects/${projectId}/repo-binding`, { repoIdentity });
2081
+ let cacheUpdated = [];
2082
+ if (project.repoIdentity != null) {
2083
+ try {
2084
+ const { updated, failed } = await rewriteCachedRepoIdentity(
2085
+ process.env,
2086
+ projectId,
2087
+ project.repoIdentity,
2088
+ repoIdentityToString(repoIdentity)
2089
+ );
2090
+ cacheUpdated = updated;
2091
+ if (failed.length > 0) {
2092
+ writeErr(`Warning: could not update the local roadmap cache for: ${failed.map(terminalLine).join(", ")}. Run \`nolto roadmap sync <slug>\` to fix it.
2093
+ `);
2094
+ }
2095
+ } catch (err) {
2096
+ const message = err instanceof Error ? err.message : String(err);
2097
+ writeErr(`Warning: could not update the local roadmap cache (${message}). Run \`nolto roadmap sync <slug>\` to fix it.
2098
+ `);
2099
+ }
2100
+ }
1984
2101
  if (mode2 === "json") {
1985
- printResult({ rebound: true, projectId, repoIdentity }, mode2);
2102
+ printResult({ rebound: true, projectId, repoIdentity, cacheUpdated }, mode2);
1986
2103
  } else {
1987
2104
  writeOut(`Rebound project ${projectId} to ${repoIdentity.kind}:${repoIdentity.value}.
2105
+ `);
2106
+ if (cacheUpdated.length > 0) writeOut(`Updated local roadmap cache: ${cacheUpdated.map(terminalLine).join(", ")}
1988
2107
  `);
1989
2108
  }
1990
2109
  }
@@ -2308,8 +2427,8 @@ async function runPull(deps, opts = {}) {
2308
2427
  }
2309
2428
 
2310
2429
  // src/commands/sync.ts
2311
- import { execFile as execFile2 } from "child_process";
2312
- import { promisify } from "util";
2430
+ import { execFile as execFile3 } from "child_process";
2431
+ import { promisify as promisify2 } from "util";
2313
2432
  import { readFile as readFile9, realpath as realpath2 } from "fs/promises";
2314
2433
  import { existsSync as existsSync4 } from "fs";
2315
2434
 
@@ -2410,15 +2529,7 @@ async function syncRepo(args, io) {
2410
2529
  roadmaps.push({ slug, ...entry });
2411
2530
  }
2412
2531
  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);
2413
- const exec = io.exec;
2414
- const isIgnored = exec === void 0 ? void 0 : async (root, relPath) => {
2415
- try {
2416
- await exec("git", ["check-ignore", "-q", "--", relPath], { cwd: root });
2417
- return true;
2418
- } catch {
2419
- return false;
2420
- }
2421
- };
2532
+ const isIgnored = io.exec === void 0 ? void 0 : makeIgnoreChecker(io.exec);
2422
2533
  const results = [];
2423
2534
  for (const entry of roadmaps) {
2424
2535
  const { slug, roadmap, meta } = entry;
@@ -2502,7 +2613,7 @@ async function runSyncCommand(deps, opts = {}) {
2502
2613
  realpath: (p) => realpath2(p),
2503
2614
  fileExists: (p) => existsSync4(p),
2504
2615
  repoIdentity: makeRepoIdentityResolver(deps),
2505
- exec: promisify(execFile2),
2616
+ exec: promisify2(execFile3),
2506
2617
  gitLinks: (opts.gitLinks ?? true) && process.env.NOLTO_GIT_LINKS !== "0",
2507
2618
  http,
2508
2619
  log: (line2) => {
@@ -2754,6 +2865,7 @@ async function roadmapMigrate(deps, yes = false) {
2754
2865
  readFile: (p) => readFile10(p, "utf8"),
2755
2866
  realpath: realpath3,
2756
2867
  fileExists: existsSync5,
2868
+ isIgnored: makeIgnoreChecker(),
2757
2869
  log: () => void 0,
2758
2870
  warn
2759
2871
  });
@@ -3209,6 +3321,8 @@ nolto wiki update <page> --body-file page.md --base-revision <revision>
3209
3321
 
3210
3322
  Secrets: view shows a \`\`\`secret id=\u2026 line instead of the value. Keep that line when you send the body back.
3211
3323
  To store a new secret, write a \`\`\`secret <name> fence; it is encrypted when saved.
3324
+ Only a fence at the start of a line (up to 3 spaces of indent), outside any list or quote, with a closing fence, is recognized;
3325
+ otherwise the value is saved as plain text. After saving, run view and check the line became \`\`\`secret id=\u2026.
3212
3326
 
3213
3327
  | Exit | Meaning |
3214
3328
  |---|---|
@@ -3596,9 +3710,9 @@ function memoryIndex(cache, context4, merged = /* @__PURE__ */ new Set(), dir) {
3596
3710
  }
3597
3711
 
3598
3712
  // src/memory-git.ts
3599
- import { execFile as execFile3 } from "child_process";
3600
- import { promisify as promisify2 } from "util";
3601
- var runMemoryGit = async (args, root) => (await promisify2(execFile3)("git", args, { cwd: root, timeout: 5e3 })).stdout.trim();
3713
+ import { execFile as execFile4 } from "child_process";
3714
+ import { promisify as promisify3 } from "util";
3715
+ var runMemoryGit = async (args, root) => (await promisify3(execFile4)("git", args, { cwd: root, timeout: 5e3 })).stdout.trim();
3602
3716
  async function memoryGitContext(root, deps) {
3603
3717
  const git = deps.memoryGit ?? runMemoryGit;
3604
3718
  const result = { repoIdentity: null, branch: null, defaultBranch: null };
@@ -4669,8 +4783,8 @@ function register11(program, deps) {
4669
4783
  }
4670
4784
 
4671
4785
  // src/commands/watch.ts
4672
- import { execFile as execFile4 } from "child_process";
4673
- import { promisify as promisify3 } from "util";
4786
+ import { execFile as execFile5 } from "child_process";
4787
+ import { promisify as promisify4 } from "util";
4674
4788
  import { readFile as readFile15, realpath as realpath4 } from "fs/promises";
4675
4789
  import { existsSync as existsSync7, mkdirSync } from "fs";
4676
4790
  import path20 from "path";
@@ -4918,9 +5032,9 @@ async function installServiceWith(deps) {
4918
5032
  }
4919
5033
  async function installService() {
4920
5034
  const { writeFile: writeFile12, mkdir: mkdir9 } = await import("fs/promises");
4921
- const { execFile: execFile6 } = await import("child_process");
4922
- const { promisify: promisify5 } = await import("util");
4923
- const execFileAsync = promisify5(execFile6);
5035
+ const { execFile: execFile7 } = await import("child_process");
5036
+ const { promisify: promisify6 } = await import("util");
5037
+ const execFileAsync = promisify6(execFile7);
4924
5038
  await installServiceWith({
4925
5039
  platform: process.platform,
4926
5040
  uid: process.getuid?.(),
@@ -5016,9 +5130,9 @@ async function uninstallServiceWith(deps) {
5016
5130
  }
5017
5131
  async function uninstallService() {
5018
5132
  const { unlink: unlink5 } = await import("fs/promises");
5019
- const { execFile: execFile6 } = await import("child_process");
5020
- const { promisify: promisify5 } = await import("util");
5021
- const execFileAsync = promisify5(execFile6);
5133
+ const { execFile: execFile7 } = await import("child_process");
5134
+ const { promisify: promisify6 } = await import("util");
5135
+ const execFileAsync = promisify6(execFile7);
5022
5136
  await uninstallServiceWith({
5023
5137
  platform: process.platform,
5024
5138
  uid: process.getuid?.(),
@@ -5123,7 +5237,7 @@ function register12(program, deps) {
5123
5237
  realpath: (p) => realpath4(p),
5124
5238
  fileExists: (p) => existsSync7(p),
5125
5239
  repoIdentity: makeRepoIdentityResolver(deps),
5126
- exec: promisify3(execFile4),
5240
+ exec: promisify4(execFile5),
5127
5241
  gitLinks: process.env.NOLTO_GIT_LINKS !== "0",
5128
5242
  http,
5129
5243
  log: (line2) => writeOut(`[${path20.basename(root)}] ${line2}
@@ -5226,7 +5340,7 @@ stale: ${result.stale}`, deps.output.mode);
5226
5340
  uid: process.getuid?.(),
5227
5341
  exec: async (cmd) => {
5228
5342
  try {
5229
- await promisify3(execFile4)(cmd[0], cmd.slice(1));
5343
+ await promisify4(execFile5)(cmd[0], cmd.slice(1));
5230
5344
  return { code: 0, stderr: "" };
5231
5345
  } catch (error) {
5232
5346
  const e = error;
@@ -5269,13 +5383,13 @@ stale: ${result.stale}`, deps.output.mode);
5269
5383
  }
5270
5384
 
5271
5385
  // src/update-cli.ts
5272
- import { execFile as execFile5 } from "child_process";
5386
+ import { execFile as execFile6 } from "child_process";
5273
5387
  import { existsSync as existsSync8 } from "fs";
5274
5388
  import { realpath as realpath5 } from "fs/promises";
5275
5389
  import { createRequire as createRequire2 } from "module";
5276
5390
  import path22 from "path";
5277
5391
  import { fileURLToPath as fileURLToPath3 } from "url";
5278
- import { promisify as promisify4 } from "util";
5392
+ import { promisify as promisify5 } from "util";
5279
5393
 
5280
5394
  // src/update-notifier.ts
5281
5395
  import { readFile as readFile16, writeFile as writeFile10, mkdir as mkdir8 } from "fs/promises";
@@ -5434,6 +5548,9 @@ async function updateCliWith(deps) {
5434
5548
  5
5435
5549
  );
5436
5550
  }
5551
+ if (!VERSION_PATTERN.test(latest2)) {
5552
+ throw new CliError("The npm registry returned an unexpected version string; not updating.", 5);
5553
+ }
5437
5554
  if (!isNewerVersion(latest2, deps.currentVersion)) {
5438
5555
  deps.log(`Already up to date (${PACKAGE2} ${deps.currentVersion}).`);
5439
5556
  return {
@@ -5498,7 +5615,7 @@ function getCurrentVersion() {
5498
5615
  }
5499
5616
  }
5500
5617
  async function updateCli(opts = {}) {
5501
- const execFileAsync = promisify4(execFile5);
5618
+ const execFileAsync = promisify5(execFile6);
5502
5619
  const scriptPath = await realpath5(process.argv[1] ?? "");
5503
5620
  return updateCliWith({
5504
5621
  currentVersion: getCurrentVersion(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nolto/cli",
3
- "version": "0.25.0",
3
+ "version": "0.25.1",
4
4
  "description": "CLI for syncing repository roadmaps with Nolto.",
5
5
  "license": "MIT",
6
6
  "type": "module",