@nolto/cli 0.22.0 → 0.22.2

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 (3) hide show
  1. package/README.md +3 -3
  2. package/dist/index.js +238 -179
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -248,14 +248,14 @@ References accept a key (NOLTO-12) or number (12). Only the number is sent. With
248
248
 
249
249
  Status/type/category accept case-insensitive exact names or UUIDs from the project's settings. Unknown or ambiguous names list candidates. Create with `--type` and no body uses that type's body template. Update never inserts a template automatically. Close chooses the first closed status by sortOrder unless overridden; it fails if no matching closed status exists. `--assignee me` on writes resolves /api/me/profile; none clears the assignee.
250
250
 
251
- List output is one line per issue plus `n / total (page p)`. View includes body and comments with API-token provenance. Writes print the issue key and URL. `--json` preserves API responses: list `{ issues, total, page, pageSize }`, view the full bundle, create `{ issue }`, update/close `{ issue, comment }`, comment `{ comment }`. Successful create with phase additionally returns `roadmap: { file, taskId }`. Human template creation adds `body: from template`. `whoami` adds scopes (null displayed as full) and project binding; JSON uses tokenScopes/tokenProject when introspection succeeds. Introspection failure is non-fatal and retains the old output.
251
+ List output is one line per issue plus `n / total (page p)`. View includes body and comments with API-token provenance. Writes print the issue key and URL. `--json` preserves API responses: list `{ issues, total, page, pageSize }`, view the full bundle, create `{ issue }`, update/close `{ issue, comment }`, comment `{ comment }`. Successful create with phase additionally returns `roadmap: { file, taskId }`. Human template creation adds `body: from template`. Successful issue create (including `--draft`), update, comment, publish and close append API warnings as `注意: <message>` lines. JSON keeps the response `warnings` unchanged. `whoami` adds scopes (null displayed as full) and project binding; JSON uses tokenScopes/tokenProject when introspection succeeds. Introspection failure is non-fatal and retains the old output.
252
252
 
253
253
  `--phase` refers to a **task ID**, not a phase ID. After creation it adds the issue key to task.issues in the cached roadmap (`nolto roadmap path`), avoids duplicates, keeps schemaVersion and updatedAt unchanged, and runs `nolto roadmap sync` for that slug. If the key is already attached, nothing is written or synced. If multiple roadmaps are cached, use `--roadmap <slug>`. A failure after issue creation (missing task, roadmap selection, or sync) exits 2 and the error includes the created key; add it to task.issues in the cache and run `nolto roadmap sync` instead of repeating create.
254
254
 
255
255
  | Exit | Meaning |
256
256
  |---|---|
257
257
  | 0 | Success |
258
- | 2 | Invalid input, recognized API 404, HTTP 422 (details shown), internal_references (confirmation required), or roadmap cache/sync failure after creation |
258
+ | 2 | Invalid input, recognized API 404, HTTP 422 (details shown), secret_detected (possible secret; message shown), internal_references (confirmation required), or roadmap cache/sync failure after creation |
259
259
  | 3 | HTTP 401/403; token_scope/token_project includes a token settings hint |
260
260
  | 4 | Plan / quota limit (HTTP 402) or rate limit (HTTP 429); resolve or wait before retrying. Token writes: 60/minute; wait Retry-After seconds before retrying. |
261
261
  | 5 | Network/generic HTTP errors, including a 404 without an API error string |
@@ -333,7 +333,7 @@ Errors are written to stderr:
333
333
 
334
334
  ## Exit Codes
335
335
 
336
- Issue validation and API 404 with an error string exit 2; 422 includes details. Token scope/project denial exits 3 with a token-settings URL and whoami hint. A create/phase failure explicitly reports the already-created key.
336
+ Issue validation and API 404 with an error string exit 2; 422 includes details. `secret_detected` exits 2 and displays the server message (possible secret; message shown), without a details line. JSON errors also include `code` and `findings` (field/rule/line only). Token scope/project denial exits 3 with a token-settings URL and whoami hint. A create/phase failure explicitly reports the already-created key.
337
337
 
338
338
  | Code | Meaning |
339
339
  |---|---|
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import path2 from "path";
7
7
 
8
8
  // src/errors.ts
9
9
  var CliError = class extends Error {
10
- constructor(message, exitCode, hint, status, serverError, body, detail) {
10
+ constructor(message, exitCode, hint, status, serverError, body, detail, retryAfter) {
11
11
  super(message);
12
12
  this.exitCode = exitCode;
13
13
  this.hint = hint;
@@ -15,6 +15,7 @@ var CliError = class extends Error {
15
15
  this.serverError = serverError;
16
16
  this.body = body;
17
17
  this.detail = detail;
18
+ this.retryAfter = retryAfter;
18
19
  this.name = "CliError";
19
20
  }
20
21
  exitCode;
@@ -23,6 +24,7 @@ var CliError = class extends Error {
23
24
  serverError;
24
25
  body;
25
26
  detail;
27
+ retryAfter;
26
28
  };
27
29
  function mapHttpStatusToCliError(status, opts = {}) {
28
30
  if (opts.serverError?.startsWith("memory_") || status === 400 && opts.serverError === "invalid_input") {
@@ -117,6 +119,9 @@ function mapHttpStatusToCliError(status, opts = {}) {
117
119
  if (status === 404 && opts.serverError) {
118
120
  return new CliError(opts.serverError, 2, void 0, status, opts.serverError, opts.body);
119
121
  }
122
+ if (status === 422 && opts.serverError === "secret_detected") {
123
+ return new CliError(opts.serverMessage ?? opts.serverError, 2, void 0, status, opts.serverError, opts.body);
124
+ }
120
125
  if (status === 422) {
121
126
  const details = Array.isArray(opts.details) ? opts.details.map((detail) => typeof detail === "string" ? detail : JSON.stringify(detail)).join("\n") : "";
122
127
  return new CliError([opts.serverError ?? opts.serverMessage ?? "Validation failed", details].filter(Boolean).join("\n"), 2, void 0, status, opts.serverError, opts.body);
@@ -146,7 +151,7 @@ function mapHttpStatusToCliError(status, opts = {}) {
146
151
  return new CliError(`${opts.serverMessage ?? "Rate limit exceeded."}${waitMsg}`, 4, void 0, status, opts.serverError, opts.body);
147
152
  }
148
153
  const reason = opts.serverMessage ?? opts.serverError;
149
- return new CliError(reason ? `Server returned HTTP ${status}: ${reason}` : `Server returned HTTP ${status}`, 5, void 0, status, opts.serverError, opts.body);
154
+ return new CliError(reason ? `Server returned HTTP ${status}: ${reason}` : `Server returned HTTP ${status}`, 5, void 0, status, opts.serverError, opts.body, void 0, opts.retryAfter);
150
155
  }
151
156
  var NETWORK_ERROR_CODES = [
152
157
  "ECONNREFUSED",
@@ -686,6 +691,133 @@ function createHttpClient(opts) {
686
691
  // src/program.ts
687
692
  import { Command } from "commander";
688
693
 
694
+ // src/memory-format.ts
695
+ var oneLine = (value) => value.replace(new RegExp("\\p{Cs}", "gu"), "\uFFFD").replace(/[\x00-\x1f\x7f-\x9f\u2028\u2029]/gu, " ").replace(new RegExp("(?![\\u200c\\u200d])\\p{Cf}|[\\u{e0100}-\\u{e01ef}\\u3164\\u115f\\u1160\\uffa0]", "gu"), "");
696
+ var commandArg = (value, placeholder) => {
697
+ const safe = oneLine(value);
698
+ return /^[A-Za-z0-9._/][A-Za-z0-9._/-]*$/.test(safe) ? safe : placeholder;
699
+ };
700
+ var shellArg = (value) => {
701
+ const safe = oneLine(value);
702
+ return /^[A-Za-z0-9._/][A-Za-z0-9._/-]*$/.test(safe) ? safe : "'" + safe.replace(/'/g, "'\\''") + "'";
703
+ };
704
+ var memoryClient = (via) => via?.client || via?.tokenName || "Web";
705
+ function parseMemory(text, importing = false) {
706
+ const lines = text.replace(/\r\n/g, "\n").split("\n");
707
+ if (/^<!--.*-->$/.test(lines[0] ?? "")) lines.shift();
708
+ if (lines.shift() !== "---") throw new CliError("frontmatter \u306E --- \u304C\u3042\u308A\u307E\u305B\u3093\u3002", 2);
709
+ const end = lines.indexOf("---");
710
+ if (end < 0) throw new CliError("frontmatter \u3092 --- \u3067\u9589\u3058\u3066\u304F\u3060\u3055\u3044\u3002", 2);
711
+ const fields = {};
712
+ let metadata = false;
713
+ for (const line2 of lines.slice(0, end)) {
714
+ const match = /^(\s*)([a-zA-Z]+):\s*(.*)$/.exec(line2);
715
+ if (!match) continue;
716
+ const indent = match[1], key = match[2], raw = match[3];
717
+ if (!indent) metadata = key === "metadata";
718
+ if (indent && !(importing && metadata && key === "type")) continue;
719
+ if (importing && ["expires", "ttl", "until"].includes(key)) continue;
720
+ let value = raw.trim();
721
+ if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) value = value.slice(1, -1);
722
+ if (["name", "description", "type", "scope", "branch", "revision", "expires", "ttl", "until"].includes(key)) fields[key] = value;
723
+ }
724
+ const body = lines.slice(end + 1);
725
+ if (body[0] === "") body.shift();
726
+ return { ...fields, name: fields.name ?? "", description: fields.description ?? "", body: body.join("\n") };
727
+ }
728
+ function cleanupReason(reason) {
729
+ let text;
730
+ switch (reason.code) {
731
+ case "expired":
732
+ text = `\u671F\u9650\u5207\u308C(${reason.expiresOn ?? ""} \u307E\u3067)`;
733
+ break;
734
+ case "issue_closed":
735
+ text = `${reason.until ?? ""} \u304C\u5B8C\u4E86`;
736
+ break;
737
+ case "task_done":
738
+ text = `task ${reason.until ?? ""} \u304C\u5B8C\u4E86`;
739
+ break;
740
+ case "ref_missing":
741
+ text = `${reason.until ?? ""} \u304C\u898B\u3064\u304B\u3089\u306A\u3044`;
742
+ break;
743
+ case "superseded":
744
+ text = `\u65B0\u3057\u3044\u518D\u958B\u30DD\u30A4\u30F3\u30C8\u3042\u308A(${reason.newer ?? ""})`;
745
+ break;
746
+ default:
747
+ text = reason.code;
748
+ }
749
+ const chars = Array.from(oneLine(text));
750
+ return chars.length > 200 ? chars.slice(0, 199).join("") + "\u2026" : chars.join("");
751
+ }
752
+ function ttlExpires(ttl, today) {
753
+ const date = new Date(today.getTime());
754
+ date.setDate(date.getDate() + Number(ttl.slice(0, -1)));
755
+ return `${String(date.getFullYear()).padStart(4, "0")}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
756
+ }
757
+ function formatMemory(entry, cleanup, scoped = false) {
758
+ const value = (s) => {
759
+ const safe = oneLine(s);
760
+ return /^['"]|['"]$|^\s|\s$/.test(safe) ? `"${safe}"` : safe;
761
+ };
762
+ return [
763
+ `<!-- ${cleanup ? `\u6574\u7406\u5019\u88DC: ${cleanupReason(cleanup)}\u3002\u6D88\u3059\u306A\u3089 nolto memory rm ${commandArg(entry.name, "<name>")}${scoped && ["project", "user", "branch"].includes(entry.scope) ? ` --scope ${entry.scope}` : ""}\u3002` : ""}nolto memory \u306E\u30AD\u30E3\u30C3\u30B7\u30E5\u3002\u7DE8\u96C6\u3057\u306A\u3044\u3002\u5909\u66F4\u306F\u4E0B\u66F8\u304D\u306B\u30B3\u30D4\u30FC\u3057\u3066 nolto memory put -->`,
764
+ "---",
765
+ `name: ${oneLine(entry.name)}`,
766
+ `description: ${value(entry.description)}`,
767
+ ...entry.type == null ? [] : [`type: ${entry.type}`],
768
+ `scope: ${entry.scope}`,
769
+ ...entry.scope === "branch" ? [`branch: ${value(entry.branch ?? "")}`] : [],
770
+ ...entry.expiresOn ? [`expires: ${value(entry.expiresOn)}`] : [],
771
+ ...entry.until ? [`until: ${value(entry.until)}`] : [],
772
+ `revision: ${entry.revision}`,
773
+ `updated: ${oneLine(entry.updatedAt)}${entry.updatedBy?.name ? ` by ${oneLine(entry.updatedBy.name)}` : ""} (${oneLine(memoryClient(entry.updatedVia))})`,
774
+ "---",
775
+ "",
776
+ entry.body
777
+ ].join("\n");
778
+ }
779
+ function parseScope(scope, hint = "scope: project|user|branch \u3092 frontmatter \u306B\u66F8\u304F") {
780
+ if (scope !== "project" && scope !== "user" && scope !== "branch") {
781
+ throw new CliError(scope ? `scope \u304C\u4E0D\u6B63\u3067\u3059: ${scope}` : "scope \u304C\u5FC5\u8981\u3067\u3059\u3002", 2, hint);
782
+ }
783
+ return scope;
784
+ }
785
+ var count = (n) => n.toLocaleString("en-US");
786
+ var invalidInput = (message, hint) => new CliError(message, 2, hint, void 0, "invalid_input");
787
+ function validateDraft(draft) {
788
+ if (!/^[a-z0-9][a-z0-9-]{0,63}$/.test(draft.name)) {
789
+ throw invalidInput(draft.name ? `name \u306E\u5F62\u304C\u4E0D\u6B63\u3067\u3059(${oneLine(draft.name)})\u3002` : "name \u304C\u3042\u308A\u307E\u305B\u3093\u3002", "name \u306F\u82F1\u5C0F\u6587\u5B57\u30FB\u6570\u5B57\u30FB\u30CF\u30A4\u30D5\u30F3\u3067 64 \u5B57\u307E\u3067\u3001\u5148\u982D\u306F\u82F1\u6570\u5B57");
790
+ }
791
+ const description = draft.description.trim();
792
+ if (/[\r\n\u0085\u2028\u2029]/.test(draft.description)) throw invalidInput("description \u306B\u6539\u884C\u304C\u3042\u308A\u307E\u3059\u3002", "description \u306F 1 \u884C\u306B\u3059\u308B");
793
+ if (!description) throw invalidInput("description \u304C\u3042\u308A\u307E\u305B\u3093\u3002", "\u7D22\u5F15\u3067\u8AAD\u3080\u304B\u3069\u3046\u304B\u3092\u6C7A\u3081\u3089\u308C\u308B 1 \u884C\u3092\u66F8\u304F");
794
+ if (description.length > 200) throw invalidInput(`description \u304C 200 \u5B57\u3092\u8D85\u3048\u3066\u3044\u307E\u3059(${count(description.length)} \u5B57)\u3002`, "\u7D22\u5F15\u3067\u8AAD\u3080\u304B\u3069\u3046\u304B\u3092\u6C7A\u3081\u3089\u308C\u308B 1 \u884C\u306B\u7E2E\u3081\u308B");
795
+ if (draft.body.length > 1e4) throw invalidInput(`\u672C\u6587\u304C 10,000 \u5B57\u3092\u8D85\u3048\u3066\u3044\u307E\u3059(${count(draft.body.length)} \u5B57)\u3002`, "\u30A8\u30F3\u30C8\u30EA\u3092\u5206\u3051\u308B\u304B\u3001\u8981\u70B9\u306B\u7D5E\u308B");
796
+ if (draft.type && !["user", "feedback", "project", "reference"].includes(draft.type)) {
797
+ throw invalidInput(`type \u304C\u4E0D\u6B63\u3067\u3059(${oneLine(draft.type)})\u3002`, "type \u306F user / feedback / project / reference \u306E\u3069\u308C\u304B\u3002\u4E0D\u8981\u306A\u3089\u884C\u3054\u3068\u6D88\u3059");
798
+ }
799
+ if (draft.expires !== void 0 && draft.ttl !== void 0) throw invalidInput("expires \u3068 ttl \u306F\u4E21\u65B9\u66F8\u3051\u307E\u305B\u3093\u3002", "expires \u304B ttl \u306E\u3069\u3061\u3089\u304B\u3092\u66F8\u304F");
800
+ if (draft.expires !== void 0) {
801
+ const parsed = /* @__PURE__ */ new Date(`${draft.expires}T00:00:00Z`);
802
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(draft.expires) || !Number.isFinite(parsed.getTime()) || parsed.toISOString().slice(0, 10) !== draft.expires) throw invalidInput("expires \u304C\u4E0D\u6B63\u3067\u3059\u3002", "expires \u306F YYYY-MM-DD \u306E\u5B9F\u5728\u3059\u308B\u65E5\u4ED8\u3067\u66F8\u304F");
803
+ }
804
+ if (draft.ttl !== void 0 && (!/^([1-9][0-9]{0,2})d$/.test(draft.ttl) || Number(draft.ttl.slice(0, -1)) > 365)) throw invalidInput("ttl \u304C\u4E0D\u6B63\u3067\u3059\u3002", "ttl \u306F 7d \u306E\u3088\u3046\u306B\u65E5\u6570\u3067\u66F8\u304F(1\u301C365)");
805
+ if (draft.until !== void 0 && draft.until.length > 200) throw invalidInput("until \u304C 200 \u5B57\u3092\u8D85\u3048\u3066\u3044\u307E\u3059\u3002", "until \u306F 200 \u5B57\u307E\u3067");
806
+ }
807
+ function parseRevision(value) {
808
+ const revision = Number(value);
809
+ if (!/^\d+$/.test(value) || !Number.isSafeInteger(revision) || revision < 1) throw new CliError("revision \u306F\u6B63\u306E\u6574\u6570\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002", 2);
810
+ return revision;
811
+ }
812
+ function detectMemoryClient(env) {
813
+ const agent = env.NOLTO_AGENT?.trim();
814
+ if (agent && /^[\x20-\x7e]+$/.test(agent)) return agent;
815
+ if (env.CLAUDECODE === "1") return "Claude Code";
816
+ if (env.GEMINI_CLI === "1") return "Gemini CLI";
817
+ if (env.CODEX_THREAD_ID) return "Codex";
818
+ return "CLI";
819
+ }
820
+
689
821
  // src/commands/issue.ts
690
822
  import { readFile as readFile10 } from "fs/promises";
691
823
 
@@ -708,6 +840,12 @@ function printError(err, mode2) {
708
840
  ...err.body?.["candidates"] ? { candidates: err.body["candidates"] } : {},
709
841
  ...err.body?.["conflicts"] ? { conflicts: err.body["conflicts"] } : {},
710
842
  ...err.body && "aiSkipped" in err.body ? { aiSkipped: err.body["aiSkipped"] } : {},
843
+ ...Array.isArray(err.body?.["findings"]) ? { findings: err.body["findings"].flatMap((item) => {
844
+ if (!item || typeof item !== "object") return [];
845
+ const { field, rule, line: line2 } = item;
846
+ if (typeof field !== "string" || typeof rule !== "string") return [];
847
+ return [{ field, rule, ...typeof line2 === "number" ? { line: line2 } : {} }];
848
+ }) } : {},
711
849
  ...err.body && "references" in err.body ? { references: err.body["references"] } : {},
712
850
  ...err.body && "total" in err.body ? { total: err.body["total"] } : {},
713
851
  exitCode: err.exitCode,
@@ -1145,12 +1283,13 @@ var personLabel = (person) => person?.name ?? person?.email ?? "\u2014";
1145
1283
  var singleLine = (value) => (value ?? "").replace(/[\r\n\t\u2028\u2029]/g, " ");
1146
1284
  var stripControl = (value, multiline = false) => multiline ? (value ?? "").replace(new RegExp("\\p{Cc}", "gu"), (c) => c === "\n" || c === " " ? c : "") : singleLine(value).replace(new RegExp("\\p{Cc}", "gu"), "");
1147
1285
  var stripFormatControl = (value) => value.replace(new RegExp("\\p{Cf}", "gu"), (c) => c === "\u200C" || c === "\u200D" ? c : "");
1286
+ var stripTerminal = (value) => stripFormatControl(stripControl(value));
1148
1287
  function formatInternalReferences(body) {
1149
1288
  const references = Array.isArray(body.references) ? body.references : [];
1150
1289
  const rows = [];
1151
1290
  for (const ref of references) {
1152
1291
  if (!ref || typeof ref !== "object" || Array.isArray(ref) || typeof ref.label !== "string") continue;
1153
- const label = Array.from(stripFormatControl(stripControl(ref.label)));
1292
+ const label = Array.from(stripTerminal(ref.label));
1154
1293
  rows.push(`- ${label.length > 200 ? `${label.slice(0, 199).join("")}\u2026` : label.join("")}`);
1155
1294
  }
1156
1295
  const total = typeof body.total === "number" && Number.isSafeInteger(body.total) && body.total >= 0 ? body.total : references.length;
@@ -1229,6 +1368,33 @@ import path6 from "path";
1229
1368
  // src/sync-core.ts
1230
1369
  import { createHash as createHash2 } from "crypto";
1231
1370
  import path5 from "path";
1371
+
1372
+ // src/busy-retry.ts
1373
+ var MAX_RETRIES = 3;
1374
+ function busyWaitSeconds(retryAfter) {
1375
+ const seconds = Number(retryAfter.trim());
1376
+ if (retryAfter.trim() === "" || !Number.isFinite(seconds)) return void 0;
1377
+ return Math.min(30, Math.max(1, Math.ceil(seconds)));
1378
+ }
1379
+ async function retryWhenBusy(send, hooks = {}) {
1380
+ const sleep2 = hooks.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
1381
+ const random = hooks.random ?? Math.random;
1382
+ const notify = hooks.notify ?? ((line2) => {
1383
+ process.stderr.write(line2 + "\n");
1384
+ });
1385
+ for (let attempt = 1; ; attempt++) {
1386
+ try {
1387
+ return await send();
1388
+ } catch (err) {
1389
+ const wait = err instanceof CliError && err.status === 503 && err.retryAfter !== void 0 ? busyWaitSeconds(err.retryAfter) : void 0;
1390
+ if (wait === void 0 || attempt > MAX_RETRIES) throw err;
1391
+ notify(`Server busy; retrying in ${wait} s (attempt ${attempt}/${MAX_RETRIES})`);
1392
+ await sleep2(wait * 1e3 + Math.floor(random() * 1e3));
1393
+ }
1394
+ }
1395
+ }
1396
+
1397
+ // src/sync-core.ts
1232
1398
  function sha256Hex(content) {
1233
1399
  return "sha256:" + createHash2("sha256").update(content, "utf8").digest("hex");
1234
1400
  }
@@ -1332,10 +1498,9 @@ async function runSync(args, deps) {
1332
1498
  repoIdentity: args.repoIdentity,
1333
1499
  deps
1334
1500
  });
1335
- const response = await deps.http.put(
1336
- `/api/projects/${args.projectId}/roadmaps/${args.slug}`,
1337
- { ...body, baseRevision: args.baseRevision }
1338
- );
1501
+ const syncPath = `/api/projects/${args.projectId}/roadmaps/${encodeURIComponent(args.slug)}`;
1502
+ const syncBody = { ...body, baseRevision: args.baseRevision };
1503
+ const response = await retryWhenBusy(() => deps.http.put(syncPath, syncBody), deps.retry);
1339
1504
  for (const warning of response.warnings ?? []) deps.warn(warning);
1340
1505
  const stats = deriveTaskStats(response.roadmap ?? args.roadmap);
1341
1506
  deps.log(
@@ -1351,8 +1516,14 @@ function cacheDir(env, projectId) {
1351
1516
  if (!UUID_RE.test(projectId)) throw new CliError(`Invalid project id "${projectId}".`, 2);
1352
1517
  return path6.join(getConfigDir(env), "projects", projectId, "roadmaps");
1353
1518
  }
1519
+ function isCacheableSlug(slug) {
1520
+ return ROADMAP_SLUG_PATTERN.test(slug) && !slug.endsWith(".meta");
1521
+ }
1522
+ function assertCacheableSlug(slug) {
1523
+ if (!isCacheableSlug(slug)) throw new CliError(`Invalid roadmap slug "${stripTerminal(slug)}".`, 2);
1524
+ }
1354
1525
  function cachePaths(env, projectId, slug) {
1355
- if (!ROADMAP_SLUG_PATTERN.test(slug)) throw new CliError(`Invalid roadmap slug "${slug}".`, 2);
1526
+ assertCacheableSlug(slug);
1356
1527
  const dir = cacheDir(env, projectId);
1357
1528
  return { json: path6.join(dir, `${slug}.json`), meta: path6.join(dir, `${slug}.meta.json`) };
1358
1529
  }
@@ -1428,7 +1599,7 @@ import path7 from "path";
1428
1599
 
1429
1600
  // src/roadmap-scaffold.ts
1430
1601
  function slugifyProjectId(name) {
1431
- const slug = name.toLowerCase().replace(/[^a-z0-9.-]+/g, "-").replace(/^[^a-z0-9]+/, "").replace(/[-_.]+$/, "");
1602
+ const slug = name.toLowerCase().replace(/[^a-z0-9.-]+/g, "-").replace(/^[^a-z0-9]+/, "").replace(/[-_.]+$/, "").replace(/\.meta$/, "-meta");
1432
1603
  return slug.length > 0 ? slug : "project";
1433
1604
  }
1434
1605
  function buildScaffold(projectName, repoBasename) {
@@ -1441,12 +1612,14 @@ function buildScaffold(projectName, repoBasename) {
1441
1612
  }
1442
1613
 
1443
1614
  // src/roadmap-bootstrap.ts
1615
+ var uncacheableSlugWarning = (slug) => `Warning: skipped roadmap "${stripTerminal(slug)}" \u2014 its slug cannot be cached locally.`;
1444
1616
  async function pullRoadmapCache(args) {
1445
1617
  const { env, projectId, slug } = args;
1618
+ assertCacheableSlug(slug);
1446
1619
  const response = await args.http.get(`/api/projects/${projectId}/roadmaps/${encodeURIComponent(slug)}`);
1447
1620
  const validation = validateRoadmap(response.roadmap);
1448
1621
  if (validation.errors.length > 0) {
1449
- throw new CliError(`Server roadmap "${slug}" failed validation: ${validation.errors.join("; ")}`, 5);
1622
+ throw new CliError(`Server roadmap "${slug}" failed validation: ${stripTerminal(validation.errors.join("; "))}`, 5);
1450
1623
  }
1451
1624
  let existing;
1452
1625
  try {
@@ -1471,38 +1644,40 @@ async function pullRoadmapCache(args) {
1471
1644
  }
1472
1645
  async function ensureRoadmapCache(args) {
1473
1646
  const { env, projectId } = args;
1474
- if (args.slug?.endsWith(".meta")) throw new CliError(`Roadmap slug cannot end with ".meta".`, 2);
1647
+ const basename = path7.basename(args.repoRoot);
1648
+ const slug = args.slug ?? slugifyProjectId(basename);
1649
+ assertCacheableSlug(slug);
1475
1650
  const identity = repoIdentityToString(args.repoIdentity);
1476
1651
  const list = await args.http.get(`/api/projects/${projectId}/roadmaps`);
1477
1652
  const warn2 = (line2) => {
1478
1653
  process.stderr.write(line2 + "\n");
1479
1654
  };
1480
1655
  const log = (line2) => args.log(`roadmap: ${line2}`);
1481
- const mine = list.roadmaps.filter((row) => row.repoIdentity == null || row.repoIdentity === identity);
1482
- if (list.roadmaps.length > 0) {
1656
+ const roadmaps = list.roadmaps.filter((row) => {
1657
+ if (isCacheableSlug(row.slug)) return true;
1658
+ warn2(uncacheableSlugWarning(row.slug));
1659
+ return false;
1660
+ });
1661
+ const mine = roadmaps.filter((row) => row.repoIdentity == null || row.repoIdentity === identity);
1662
+ if (roadmaps.length > 0) {
1483
1663
  let skipped = false;
1484
- for (const { slug: slug2 } of list.roadmaps) {
1485
- if (!await pullRoadmapCache({ ...args, slug: slug2, warn: warn2, log, recoverInvalid: true })) skipped = true;
1664
+ for (const row of roadmaps) {
1665
+ if (!await pullRoadmapCache({ ...args, slug: row.slug, warn: warn2, log, recoverInvalid: true })) skipped = true;
1486
1666
  }
1487
1667
  if (skipped) throw new CliError("Some roadmaps have local changes that are not synced.", 4);
1488
1668
  if (args.slug === void 0 ? mine.length > 0 : mine.some((row) => row.slug === args.slug)) return;
1489
1669
  }
1490
- const basename = path7.basename(args.repoRoot);
1491
- const slug = args.slug ?? slugifyProjectId(basename);
1492
- const collision = list.roadmaps.find((row) => row.slug === slug);
1670
+ const collision = roadmaps.find((row) => row.slug === slug);
1493
1671
  if (collision) {
1494
1672
  if (args.slug === void 0) {
1495
- log(`skipped \u2014 "${slug}" is another repository's roadmap (${collision.repoIdentity ?? "unknown"}). Run \`nolto link --slug <name>\` to create one for this repository.`);
1673
+ log(`skipped \u2014 "${slug}" is another repository's roadmap (${stripTerminal(collision.repoIdentity ?? "unknown")}). Run \`nolto link --slug <name>\` to create one for this repository.`);
1496
1674
  return;
1497
1675
  }
1498
- 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);
1676
+ throw new CliError(`Roadmap slug "${slug}" already exists in this project (repo: ${stripTerminal(collision.repoIdentity ?? "unknown")}). Run \`nolto link --slug <other-slug>\` to name this repository's roadmap.`, 2);
1499
1677
  }
1500
- let existing;
1501
- try {
1502
- existing = await readCache(env, projectId, slug);
1503
- } catch (err) {
1504
- if (!(err instanceof CliError)) throw err;
1505
- existing = null;
1678
+ const existing = await readCache(env, projectId, slug);
1679
+ if (existing?.meta && (existing.meta.revision > 0 || existing.meta.repoIdentity != null && existing.meta.repoIdentity !== identity)) {
1680
+ throw new CliError(`Local cache for "${slug}" belongs to a roadmap that is no longer on the server (${cachePaths(env, projectId, slug).json}). Remove it or choose another slug with \`nolto link --slug\`.`, 2);
1506
1681
  }
1507
1682
  if (existing && isDirty(existing)) {
1508
1683
  warn2(`Warning: ${slug} has local changes that are not synced; use --force to overwrite or run nolto sync first`);
@@ -1538,7 +1713,7 @@ async function ensureProjectRepo(args) {
1538
1713
  if (repos.length === 0) return "unbound";
1539
1714
  const identity = repoIdentityToString(args.repoIdentity);
1540
1715
  if (repos.some((repo) => repo.identity === identity)) return "bound";
1541
- if (!await args.confirm(`Project is bound to ${repos.map((repo) => repo.identity).join(", ")}. Add this repository (${identity}) to the project? [Y/n] `)) return "declined";
1716
+ if (!await args.confirm(`Project is bound to ${repos.map((repo) => stripTerminal(repo.identity)).join(", ")}. Add this repository (${identity}) to the project? [Y/n] `)) return "declined";
1542
1717
  try {
1543
1718
  await args.http.post(`/api/projects/${args.projectId}/repos`, { repoIdentity: args.repoIdentity });
1544
1719
  } catch (error) {
@@ -1831,9 +2006,9 @@ async function handleRebind(deps, projectId, root, mode2, yes) {
1831
2006
  }
1832
2007
  const repoIdentity = await makeRepoIdentityResolver(deps)(root);
1833
2008
  if (mode2 !== "json") {
1834
- process.stdout.write(`Project : ${project.name} (${project.id})
2009
+ process.stdout.write(`Project : ${stripTerminal(project.name)} (${project.id})
1835
2010
  `);
1836
- process.stdout.write(`Bound to : ${project.repoIdentity ?? "not bound"}
2011
+ process.stdout.write(`Bound to : ${stripTerminal(project.repoIdentity ?? "not bound")}
1837
2012
  `);
1838
2013
  process.stdout.write(`Rebind to : ${repoIdentity.kind}:${repoIdentity.value}
1839
2014
  `);
@@ -1848,7 +2023,7 @@ async function handleRebind(deps, projectId, root, mode2, yes) {
1848
2023
  const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
1849
2024
  let confirmed = false;
1850
2025
  try {
1851
- const answer = await rl.question(`Rebind "${project.name}" to this repository? [y/N] `);
2026
+ const answer = await rl.question(`Rebind "${stripTerminal(project.name)}" to this repository? [y/N] `);
1852
2027
  confirmed = answer.trim().toLowerCase() === "y";
1853
2028
  } finally {
1854
2029
  rl.close();
@@ -2046,6 +2221,7 @@ function register(program, deps) {
2046
2221
  return;
2047
2222
  }
2048
2223
  const opts = cmd.opts();
2224
+ if (opts["slug"] !== void 0) assertCacheableSlug(opts["slug"]);
2049
2225
  if (opts["list"] || opts["add"] || opts["remove"] !== void 0 || opts["slug"] !== void 0) {
2050
2226
  if (projectId == null) {
2051
2227
  if (bindingError != null) throw invalidBindingError(projectBindingPath, bindingError);
@@ -2068,7 +2244,7 @@ function register(program, deps) {
2068
2244
  const { repos } = await deps.http.get(`/api/projects/${projectId}`);
2069
2245
  if (opts["list"]) {
2070
2246
  if (mode2 === "json") printResult({ repos }, mode2);
2071
- else for (const repo2 of repos) printResult(`${repo2.identity}${repo2.label ? ` (${repo2.label})` : ""} ${repo2.boundAt} ${repo2.id}`, mode2);
2247
+ else for (const repo2 of repos) printResult(`${stripTerminal(repo2.identity)}${repo2.label ? ` (${stripTerminal(repo2.label)})` : ""} ${stripTerminal(repo2.boundAt)} ${stripTerminal(repo2.id)}`, mode2);
2072
2248
  return;
2073
2249
  }
2074
2250
  const input = opts["remove"];
@@ -2080,7 +2256,7 @@ function register(program, deps) {
2080
2256
  const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
2081
2257
  let confirmed = false;
2082
2258
  try {
2083
- const answer = await rl.question(`Remove "${repo.identity}" from project ${projectId}? [y/N] `);
2259
+ const answer = await rl.question(`Remove "${stripTerminal(repo.identity)}" from project ${projectId}? [y/N] `);
2084
2260
  confirmed = answer.trim().toLowerCase() === "y";
2085
2261
  } finally {
2086
2262
  rl.close();
@@ -2091,7 +2267,7 @@ function register(program, deps) {
2091
2267
  }
2092
2268
  }
2093
2269
  await deps.http.delete(`/api/projects/${projectId}/repos/${repo.id}`);
2094
- printResult(mode2 === "json" ? { removed: true, projectId, repoId: repo.id } : `Removed ${repo.identity} from project ${projectId}.`, mode2);
2270
+ printResult(mode2 === "json" ? { removed: true, projectId, repoId: repo.id } : `Removed ${stripTerminal(repo.identity)} from project ${projectId}.`, mode2);
2095
2271
  return;
2096
2272
  }
2097
2273
  }
@@ -2151,13 +2327,18 @@ function register2(program, deps) {
2151
2327
  }
2152
2328
  async function runPull(deps, opts = {}) {
2153
2329
  const messages = [];
2330
+ if (opts.slug != null) assertCacheableSlug(opts.slug);
2154
2331
  const { projectId } = await resolveRoadmapReadContext(deps);
2155
2332
  const list = await deps.http.get(`/api/projects/${projectId}/roadmaps`);
2156
2333
  const serverBySlug = new Map(list.roadmaps.map((roadmap) => [roadmap.slug, roadmap]));
2157
2334
  if (opts.slug != null && !serverBySlug.has(opts.slug)) {
2158
2335
  throw new CliError(`Roadmap "${opts.slug}" was not found on the server.`, 2);
2159
2336
  }
2160
- const slugs = opts.slug == null ? [...serverBySlug.keys()] : [opts.slug];
2337
+ const slugs = opts.slug == null ? [...serverBySlug.keys()].filter((slug) => {
2338
+ if (isCacheableSlug(slug)) return true;
2339
+ process.stderr.write(uncacheableSlugWarning(slug) + "\n");
2340
+ return false;
2341
+ }) : [opts.slug];
2161
2342
  let skipped = false;
2162
2343
  for (const slug of slugs) {
2163
2344
  if (!await pullRoadmapCache({
@@ -2276,7 +2457,7 @@ async function syncRepo(args, io) {
2276
2457
  const entry = await readCache(io.env, projectId, slug);
2277
2458
  if (!entry) throw new CliError(`No cached roadmap "${slug}". Run \`nolto roadmap pull ${slug}\`.`, 2);
2278
2459
  if (args.slugs === void 0 && entry.meta?.repoIdentity != null && entry.meta.repoIdentity !== identity) {
2279
- io.log(`skipped ${slug} (belongs to ${entry.meta.repoIdentity})`);
2460
+ io.log(`skipped ${slug} (belongs to ${stripTerminal(entry.meta.repoIdentity)})`);
2280
2461
  continue;
2281
2462
  }
2282
2463
  roadmaps.push({ slug, ...entry });
@@ -2298,7 +2479,7 @@ async function syncRepo(args, io) {
2298
2479
  try {
2299
2480
  const response = await runSync(
2300
2481
  { repoRoot: args.root, projectId, slug, roadmap, repoIdentity, baseRevision: meta?.revision ?? 0 },
2301
- { http: io.http, readFile: io.readFile, fileExists: io.fileExists, realpath: io.realpath, ...isIgnored ? { isIgnored } : {}, log: io.log, warn: io.warn }
2482
+ { http: io.http, readFile: io.readFile, fileExists: io.fileExists, realpath: io.realpath, ...isIgnored ? { isIgnored } : {}, log: io.log, warn: io.warn, ...io.retry ? { retry: io.retry } : {} }
2302
2483
  );
2303
2484
  await writeCache(io.env, projectId, slug, response.roadmap ?? roadmap, {
2304
2485
  repoIdentity: identity,
@@ -2335,10 +2516,11 @@ async function syncRepo(args, io) {
2335
2516
  if (body && body.links.length > 0) {
2336
2517
  gitLinks = { linked: 0, existing: 0, skipped: 0 };
2337
2518
  for (let offset = 0; offset < body.links.length; offset += 500) {
2338
- const response = await io.http.post(
2519
+ const chunk = { links: body.links.slice(offset, offset + 500), repoIdentity };
2520
+ const response = await retryWhenBusy(() => io.http.post(
2339
2521
  `/api/projects/${projectId}/git-links`,
2340
- { links: body.links.slice(offset, offset + 500), repoIdentity }
2341
- );
2522
+ chunk
2523
+ ), io.retry);
2342
2524
  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");
2343
2525
  gitLinks = { linked: gitLinks.linked + response.linked, existing: gitLinks.existing + response.existing, skipped: gitLinks.skipped + response.skipped };
2344
2526
  for (const warning of response.warnings) io.warn(`git links: ${warning}`);
@@ -2674,6 +2856,10 @@ async function checkShared(deps, root, flags, ref) {
2674
2856
  throw new CliError(`${stripControl(ref)} \u306F\u3053\u306E\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8(${stripControl(key)})\u306E\u8AB2\u984C\u30AD\u30FC\u3067\u306F\u3042\u308A\u307E\u305B\u3093\u3002`, 2);
2675
2857
  }
2676
2858
  }
2859
+ function warningLines(warnings) {
2860
+ return Array.isArray(warnings) ? warnings.filter((text) => typeof text === "string").map((text) => `
2861
+ \u6CE8\u610F: ${oneLine(text)}`).join("") : "";
2862
+ }
2677
2863
  function writeSuffix(flags) {
2678
2864
  if (flags.shared && flags.confirmReferences) return " (shared, references confirmed)";
2679
2865
  return flags.shared ? " (shared)" : flags.confirmReferences ? " (references confirmed)" : "";
@@ -2801,7 +2987,7 @@ nolto issue publish <draft-id>
2801
2987
  | Exit | Meaning |
2802
2988
  |---|---|
2803
2989
  | 0 | Success |
2804
- | 2 | Invalid input, recognized API 404, HTTP 422 (details shown), internal_references (confirmation required), or roadmap cache/sync failure after creation |
2990
+ | 2 | Invalid input, recognized API 404, HTTP 422 (details shown), secret_detected (possible secret; message shown), internal_references (confirmation required), or roadmap cache/sync failure after creation |
2805
2991
  | 3 | HTTP 401/403; token_scope/token_project includes a token settings hint |
2806
2992
  | 4 | HTTP 402/429 (quota/rate limit). API token writes: 60/minute. On 429, wait Retry-After seconds before retrying. |
2807
2993
  | 5 | Network/generic HTTP errors, including a 404 without an API error string |
@@ -2828,13 +3014,13 @@ nolto issue publish <draft-id>
2828
3014
  if (flags.draft) {
2829
3015
  const result2 = await writeRequest(deps, ctx.mode, flags, "post", `${ctx.root}/issue-drafts`, input);
2830
3016
  printResult(ctx.mode === "json" ? result2 : `draft ${result2.draft.id} created${writeSuffix(flags)}
2831
- ${draftUrl(deps.settings.baseUrl, ctx.projectId, result2.draft.id)}`, ctx.mode);
3017
+ ${draftUrl(deps.settings.baseUrl, ctx.projectId, result2.draft.id)}${warningLines(result2.warnings)}`, ctx.mode);
2832
3018
  return;
2833
3019
  }
2834
3020
  const result = await writeRequest(deps, ctx.mode, flags, "post", `${ctx.root}/issues`, input);
2835
3021
  const roadmap = flags.phase === void 0 ? void 0 : await attachRoadmap(deps, flags.phase, flags.roadmap, result.issue.key);
2836
3022
  printResult(ctx.mode === "json" ? { ...result, ...roadmap ? { roadmap } : {} } : `${result.issue.key} created${writeSuffix(flags)}
2837
- ${issueUrl(deps.settings.baseUrl, ctx.projectId, result.issue.number)}${fromTemplate ? "\nbody: from template" : ""}`, ctx.mode);
3023
+ ${issueUrl(deps.settings.baseUrl, ctx.projectId, result.issue.number)}${fromTemplate ? "\nbody: from template" : ""}${warningLines(result.warnings)}`, ctx.mode);
2838
3024
  });
2839
3025
  group.command("drafts").description("List your issue drafts (visible only to you).").action(async (_flags, command) => {
2840
3026
  const ctx = context(deps, command);
@@ -2846,7 +3032,7 @@ ${issueUrl(deps.settings.baseUrl, ctx.projectId, result.issue.number)}${fromTemp
2846
3032
  if (!isUuid(id)) throw new CliError("<draft-id> must be a UUID. Run `nolto issue drafts` to list drafts.", 2);
2847
3033
  const result = await writeRequest(deps, ctx.mode, flags, "post", `${ctx.root}/issue-drafts/${id}/publish`, void 0);
2848
3034
  printResult(ctx.mode === "json" ? result : `${result.issue.key} published
2849
- ${issueUrl(deps.settings.baseUrl, ctx.projectId, result.issue.number)}`, ctx.mode);
3035
+ ${issueUrl(deps.settings.baseUrl, ctx.projectId, result.issue.number)}${warningLines(result.warnings)}`, ctx.mode);
2850
3036
  });
2851
3037
  writeOptions(group.command("update <ref>").description("Update issue fields."), false).action(async (ref, flags, command) => {
2852
3038
  const ctx = context(deps, command);
@@ -2855,7 +3041,7 @@ ${issueUrl(deps.settings.baseUrl, ctx.projectId, result.issue.number)}`, ctx.mod
2855
3041
  const { input } = await writeInput(deps, ctx.root, flags, false);
2856
3042
  const result = await writeRequest(deps, ctx.mode, flags, "patch", `${ctx.root}/issues/${number}`, input);
2857
3043
  printResult(ctx.mode === "json" ? result : `${result.issue.key} updated${writeSuffix(flags)}
2858
- ${issueUrl(deps.settings.baseUrl, ctx.projectId, number)}`, ctx.mode);
3044
+ ${issueUrl(deps.settings.baseUrl, ctx.projectId, number)}${warningLines(result.warnings)}`, ctx.mode);
2859
3045
  });
2860
3046
  sharedOptions(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) => {
2861
3047
  const ctx = context(deps, command);
@@ -2866,7 +3052,7 @@ ${issueUrl(deps.settings.baseUrl, ctx.projectId, number)}`, ctx.mode);
2866
3052
  const issue = ctx.mode === "human" ? (await deps.http.get(`${ctx.root}/issues/${number}`)).issue : void 0;
2867
3053
  const result = await writeRequest(deps, ctx.mode, flags, "post", `${ctx.root}/issues/${number}/comments`, { body });
2868
3054
  printResult(ctx.mode === "json" ? result : `${issue.key} commented${writeSuffix(flags)}
2869
- ${issueUrl(deps.settings.baseUrl, ctx.projectId, number)}`, ctx.mode);
3055
+ ${issueUrl(deps.settings.baseUrl, ctx.projectId, number)}${warningLines(result.warnings)}`, ctx.mode);
2870
3056
  });
2871
3057
  sharedOptions(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) => {
2872
3058
  const ctx = context(deps, command);
@@ -2876,7 +3062,7 @@ ${issueUrl(deps.settings.baseUrl, ctx.projectId, number)}`, ctx.mode);
2876
3062
  const status = pickClosedStatus(settings, flags.status);
2877
3063
  const result = await writeRequest(deps, ctx.mode, flags, "patch", `${ctx.root}/issues/${number}`, { statusId: status.id, ...flags.comment !== void 0 ? { comment: flags.comment } : {} });
2878
3064
  printResult(ctx.mode === "json" ? result : `${result.issue.key} closed${writeSuffix(flags)}
2879
- ${issueUrl(deps.settings.baseUrl, ctx.projectId, number)}`, ctx.mode);
3065
+ ${issueUrl(deps.settings.baseUrl, ctx.projectId, number)}${warningLines(result.warnings)}`, ctx.mode);
2880
3066
  });
2881
3067
  }
2882
3068
 
@@ -2884,133 +3070,6 @@ ${issueUrl(deps.settings.baseUrl, ctx.projectId, number)}`, ctx.mode);
2884
3070
  import { readFile as readFile12, readdir as readdir6, rm as rm3 } from "fs/promises";
2885
3071
  import path16 from "path";
2886
3072
 
2887
- // src/memory-format.ts
2888
- var oneLine = (value) => value.replace(new RegExp("\\p{Cs}", "gu"), "\uFFFD").replace(/[\x00-\x1f\x7f-\x9f\u2028\u2029]/gu, " ").replace(new RegExp("(?![\\u200c\\u200d])\\p{Cf}|[\\u{e0100}-\\u{e01ef}\\u3164\\u115f\\u1160\\uffa0]", "gu"), "");
2889
- var commandArg = (value, placeholder) => {
2890
- const safe = oneLine(value);
2891
- return /^[A-Za-z0-9._/][A-Za-z0-9._/-]*$/.test(safe) ? safe : placeholder;
2892
- };
2893
- var shellArg = (value) => {
2894
- const safe = oneLine(value);
2895
- return /^[A-Za-z0-9._/][A-Za-z0-9._/-]*$/.test(safe) ? safe : "'" + safe.replace(/'/g, "'\\''") + "'";
2896
- };
2897
- var memoryClient = (via) => via?.client || via?.tokenName || "Web";
2898
- function parseMemory(text, importing = false) {
2899
- const lines = text.replace(/\r\n/g, "\n").split("\n");
2900
- if (/^<!--.*-->$/.test(lines[0] ?? "")) lines.shift();
2901
- if (lines.shift() !== "---") throw new CliError("frontmatter \u306E --- \u304C\u3042\u308A\u307E\u305B\u3093\u3002", 2);
2902
- const end = lines.indexOf("---");
2903
- if (end < 0) throw new CliError("frontmatter \u3092 --- \u3067\u9589\u3058\u3066\u304F\u3060\u3055\u3044\u3002", 2);
2904
- const fields = {};
2905
- let metadata = false;
2906
- for (const line2 of lines.slice(0, end)) {
2907
- const match = /^(\s*)([a-zA-Z]+):\s*(.*)$/.exec(line2);
2908
- if (!match) continue;
2909
- const indent = match[1], key = match[2], raw = match[3];
2910
- if (!indent) metadata = key === "metadata";
2911
- if (indent && !(importing && metadata && key === "type")) continue;
2912
- if (importing && ["expires", "ttl", "until"].includes(key)) continue;
2913
- let value = raw.trim();
2914
- if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) value = value.slice(1, -1);
2915
- if (["name", "description", "type", "scope", "branch", "revision", "expires", "ttl", "until"].includes(key)) fields[key] = value;
2916
- }
2917
- const body = lines.slice(end + 1);
2918
- if (body[0] === "") body.shift();
2919
- return { ...fields, name: fields.name ?? "", description: fields.description ?? "", body: body.join("\n") };
2920
- }
2921
- function cleanupReason(reason) {
2922
- let text;
2923
- switch (reason.code) {
2924
- case "expired":
2925
- text = `\u671F\u9650\u5207\u308C(${reason.expiresOn ?? ""} \u307E\u3067)`;
2926
- break;
2927
- case "issue_closed":
2928
- text = `${reason.until ?? ""} \u304C\u5B8C\u4E86`;
2929
- break;
2930
- case "task_done":
2931
- text = `task ${reason.until ?? ""} \u304C\u5B8C\u4E86`;
2932
- break;
2933
- case "ref_missing":
2934
- text = `${reason.until ?? ""} \u304C\u898B\u3064\u304B\u3089\u306A\u3044`;
2935
- break;
2936
- case "superseded":
2937
- text = `\u65B0\u3057\u3044\u518D\u958B\u30DD\u30A4\u30F3\u30C8\u3042\u308A(${reason.newer ?? ""})`;
2938
- break;
2939
- default:
2940
- text = reason.code;
2941
- }
2942
- const chars = Array.from(oneLine(text));
2943
- return chars.length > 200 ? chars.slice(0, 199).join("") + "\u2026" : chars.join("");
2944
- }
2945
- function ttlExpires(ttl, today) {
2946
- const date = new Date(today.getTime());
2947
- date.setDate(date.getDate() + Number(ttl.slice(0, -1)));
2948
- return `${String(date.getFullYear()).padStart(4, "0")}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
2949
- }
2950
- function formatMemory(entry, cleanup, scoped = false) {
2951
- const value = (s) => {
2952
- const safe = oneLine(s);
2953
- return /^['"]|['"]$|^\s|\s$/.test(safe) ? `"${safe}"` : safe;
2954
- };
2955
- return [
2956
- `<!-- ${cleanup ? `\u6574\u7406\u5019\u88DC: ${cleanupReason(cleanup)}\u3002\u6D88\u3059\u306A\u3089 nolto memory rm ${commandArg(entry.name, "<name>")}${scoped && ["project", "user", "branch"].includes(entry.scope) ? ` --scope ${entry.scope}` : ""}\u3002` : ""}nolto memory \u306E\u30AD\u30E3\u30C3\u30B7\u30E5\u3002\u7DE8\u96C6\u3057\u306A\u3044\u3002\u5909\u66F4\u306F\u4E0B\u66F8\u304D\u306B\u30B3\u30D4\u30FC\u3057\u3066 nolto memory put -->`,
2957
- "---",
2958
- `name: ${oneLine(entry.name)}`,
2959
- `description: ${value(entry.description)}`,
2960
- ...entry.type == null ? [] : [`type: ${entry.type}`],
2961
- `scope: ${entry.scope}`,
2962
- ...entry.scope === "branch" ? [`branch: ${value(entry.branch ?? "")}`] : [],
2963
- ...entry.expiresOn ? [`expires: ${value(entry.expiresOn)}`] : [],
2964
- ...entry.until ? [`until: ${value(entry.until)}`] : [],
2965
- `revision: ${entry.revision}`,
2966
- `updated: ${oneLine(entry.updatedAt)}${entry.updatedBy?.name ? ` by ${oneLine(entry.updatedBy.name)}` : ""} (${oneLine(memoryClient(entry.updatedVia))})`,
2967
- "---",
2968
- "",
2969
- entry.body
2970
- ].join("\n");
2971
- }
2972
- function parseScope(scope, hint = "scope: project|user|branch \u3092 frontmatter \u306B\u66F8\u304F") {
2973
- if (scope !== "project" && scope !== "user" && scope !== "branch") {
2974
- throw new CliError(scope ? `scope \u304C\u4E0D\u6B63\u3067\u3059: ${scope}` : "scope \u304C\u5FC5\u8981\u3067\u3059\u3002", 2, hint);
2975
- }
2976
- return scope;
2977
- }
2978
- var count = (n) => n.toLocaleString("en-US");
2979
- var invalidInput = (message, hint) => new CliError(message, 2, hint, void 0, "invalid_input");
2980
- function validateDraft(draft) {
2981
- if (!/^[a-z0-9][a-z0-9-]{0,63}$/.test(draft.name)) {
2982
- throw invalidInput(draft.name ? `name \u306E\u5F62\u304C\u4E0D\u6B63\u3067\u3059(${oneLine(draft.name)})\u3002` : "name \u304C\u3042\u308A\u307E\u305B\u3093\u3002", "name \u306F\u82F1\u5C0F\u6587\u5B57\u30FB\u6570\u5B57\u30FB\u30CF\u30A4\u30D5\u30F3\u3067 64 \u5B57\u307E\u3067\u3001\u5148\u982D\u306F\u82F1\u6570\u5B57");
2983
- }
2984
- const description = draft.description.trim();
2985
- if (/[\r\n\u0085\u2028\u2029]/.test(draft.description)) throw invalidInput("description \u306B\u6539\u884C\u304C\u3042\u308A\u307E\u3059\u3002", "description \u306F 1 \u884C\u306B\u3059\u308B");
2986
- if (!description) throw invalidInput("description \u304C\u3042\u308A\u307E\u305B\u3093\u3002", "\u7D22\u5F15\u3067\u8AAD\u3080\u304B\u3069\u3046\u304B\u3092\u6C7A\u3081\u3089\u308C\u308B 1 \u884C\u3092\u66F8\u304F");
2987
- if (description.length > 200) throw invalidInput(`description \u304C 200 \u5B57\u3092\u8D85\u3048\u3066\u3044\u307E\u3059(${count(description.length)} \u5B57)\u3002`, "\u7D22\u5F15\u3067\u8AAD\u3080\u304B\u3069\u3046\u304B\u3092\u6C7A\u3081\u3089\u308C\u308B 1 \u884C\u306B\u7E2E\u3081\u308B");
2988
- if (draft.body.length > 1e4) throw invalidInput(`\u672C\u6587\u304C 10,000 \u5B57\u3092\u8D85\u3048\u3066\u3044\u307E\u3059(${count(draft.body.length)} \u5B57)\u3002`, "\u30A8\u30F3\u30C8\u30EA\u3092\u5206\u3051\u308B\u304B\u3001\u8981\u70B9\u306B\u7D5E\u308B");
2989
- if (draft.type && !["user", "feedback", "project", "reference"].includes(draft.type)) {
2990
- throw invalidInput(`type \u304C\u4E0D\u6B63\u3067\u3059(${oneLine(draft.type)})\u3002`, "type \u306F user / feedback / project / reference \u306E\u3069\u308C\u304B\u3002\u4E0D\u8981\u306A\u3089\u884C\u3054\u3068\u6D88\u3059");
2991
- }
2992
- if (draft.expires !== void 0 && draft.ttl !== void 0) throw invalidInput("expires \u3068 ttl \u306F\u4E21\u65B9\u66F8\u3051\u307E\u305B\u3093\u3002", "expires \u304B ttl \u306E\u3069\u3061\u3089\u304B\u3092\u66F8\u304F");
2993
- if (draft.expires !== void 0) {
2994
- const parsed = /* @__PURE__ */ new Date(`${draft.expires}T00:00:00Z`);
2995
- if (!/^\d{4}-\d{2}-\d{2}$/.test(draft.expires) || !Number.isFinite(parsed.getTime()) || parsed.toISOString().slice(0, 10) !== draft.expires) throw invalidInput("expires \u304C\u4E0D\u6B63\u3067\u3059\u3002", "expires \u306F YYYY-MM-DD \u306E\u5B9F\u5728\u3059\u308B\u65E5\u4ED8\u3067\u66F8\u304F");
2996
- }
2997
- if (draft.ttl !== void 0 && (!/^([1-9][0-9]{0,2})d$/.test(draft.ttl) || Number(draft.ttl.slice(0, -1)) > 365)) throw invalidInput("ttl \u304C\u4E0D\u6B63\u3067\u3059\u3002", "ttl \u306F 7d \u306E\u3088\u3046\u306B\u65E5\u6570\u3067\u66F8\u304F(1\u301C365)");
2998
- if (draft.until !== void 0 && draft.until.length > 200) throw invalidInput("until \u304C 200 \u5B57\u3092\u8D85\u3048\u3066\u3044\u307E\u3059\u3002", "until \u306F 200 \u5B57\u307E\u3067");
2999
- }
3000
- function parseRevision(value) {
3001
- const revision = Number(value);
3002
- if (!/^\d+$/.test(value) || !Number.isSafeInteger(revision) || revision < 1) throw new CliError("revision \u306F\u6B63\u306E\u6574\u6570\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002", 2);
3003
- return revision;
3004
- }
3005
- function detectMemoryClient(env) {
3006
- const agent = env.NOLTO_AGENT?.trim();
3007
- if (agent && /^[\x20-\x7e]+$/.test(agent)) return agent;
3008
- if (env.CLAUDECODE === "1") return "Claude Code";
3009
- if (env.GEMINI_CLI === "1") return "Gemini CLI";
3010
- if (env.CODEX_THREAD_ID) return "Codex";
3011
- return "CLI";
3012
- }
3013
-
3014
3073
  // src/memory-cache.ts
3015
3074
  import { mkdir as mkdir7, readFile as readFile11, readdir as readdir5, rename as rename4, rm as rm2, unlink as unlink4, writeFile as writeFile8 } from "fs/promises";
3016
3075
  import { createHash as createHash3, randomUUID as randomUUID6 } from "crypto";
@@ -3413,7 +3472,7 @@ async function pickProject(rl, http, projects, promptText, baseUrl) {
3413
3472
  if (projects.length > 0) {
3414
3473
  process.stdout.write("\nProjects:\n");
3415
3474
  projects.forEach((project, index) => {
3416
- process.stdout.write(` (${index + 1}) ${project.name} \u2014 ${project.id}
3475
+ process.stdout.write(` (${index + 1}) ${stripTerminal(project.name)} \u2014 ${project.id}
3417
3476
  `);
3418
3477
  });
3419
3478
  } else {
@@ -3439,7 +3498,7 @@ async function pickProject(rl, http, projects, promptText, baseUrl) {
3439
3498
  if (orgs.length > 1) {
3440
3499
  process.stdout.write("\nOrganizations:\n");
3441
3500
  orgs.forEach((org, index2) => {
3442
- process.stdout.write(` (${index2 + 1}) ${org.name} \u2014 ${org.id}
3501
+ process.stdout.write(` (${index2 + 1}) ${stripTerminal(org.name)} \u2014 ${org.id}
3443
3502
  `);
3444
3503
  });
3445
3504
  const choice = (await rl.question("Organization number: ")).trim();
@@ -3460,7 +3519,7 @@ async function pickProject(rl, http, projects, promptText, baseUrl) {
3460
3519
  id: created.project.id,
3461
3520
  name: created.project.name ?? name.trim()
3462
3521
  };
3463
- process.stdout.write(`Created project ${project.name} [${key}] (${project.id}) in ${organization.name}
3522
+ process.stdout.write(`Created project ${stripTerminal(project.name)} [${key}] (${project.id}) in ${stripTerminal(organization.name)}
3464
3523
  `);
3465
3524
  return project;
3466
3525
  }
@@ -3474,7 +3533,7 @@ async function selectRepoProject(rl, http, projects, defaultProjectId, baseUrl)
3474
3533
  const defaultProject = defaultProjectId == null ? void 0 : projects.find((project) => project.id === defaultProjectId);
3475
3534
  if (defaultProject != null) {
3476
3535
  const useDefault = await rl.question(
3477
- `Use "${defaultProject.name}" (${defaultProject.id}) for this repository? [Y/n] `
3536
+ `Use "${stripTerminal(defaultProject.name)}" (${defaultProject.id}) for this repository? [Y/n] `
3478
3537
  );
3479
3538
  if (useDefault.trim().toLowerCase() !== "n") {
3480
3539
  return defaultProject;
@@ -3641,7 +3700,7 @@ function register5(program, deps) {
3641
3700
  baseUrl: baseUrl !== DEFAULT_BASE_URL ? baseUrl : void 0,
3642
3701
  defaultProjectId
3643
3702
  });
3644
- const projectDisplay = defaultProjectId != null ? `${defaultProjectName ?? ""} (${defaultProjectId})` : "not set";
3703
+ const projectDisplay = defaultProjectId != null ? `${stripTerminal(defaultProjectName)} (${defaultProjectId})` : "not set";
3645
3704
  process.stdout.write(`
3646
3705
  Saved ${configPath}
3647
3706
  `);
@@ -3685,7 +3744,7 @@ Saved ${configPath}
3685
3744
  );
3686
3745
  if (boundProject != null) {
3687
3746
  process.stdout.write(
3688
- `Existing binding: nolto.json \u2192 "${boundProject.name}" (${boundProject.id})
3747
+ `Existing binding: nolto.json \u2192 "${stripTerminal(boundProject.name)}" (${boundProject.id})
3689
3748
  `
3690
3749
  );
3691
3750
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nolto/cli",
3
- "version": "0.22.0",
3
+ "version": "0.22.2",
4
4
  "description": "CLI for syncing repository roadmaps with Nolto.",
5
5
  "license": "MIT",
6
6
  "type": "module",