@nolto/cli 0.22.1 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +2 -3
  2. package/dist/index.js +136 -92
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -231,7 +231,7 @@ Git commands.
231
231
  ### Issues
232
232
 
233
233
  All commands accept global `--project <id>`, `--json`, `--token <value>` and `--base-url <url>`.
234
- Project priority: flag → NOLTO_PROJECT → nearest ancestor nolto.json → config defaultProjectId. Git is not required. An invalid nolto.json remains an error.
234
+ Project priority: flag → NOLTO_PROJECT → nearest ancestor nolto.json. Git is not required. An invalid nolto.json remains an error.
235
235
  References accept a key (NOLTO-12) or number (12). Only the number is sent. With `--shared`, a key prefix must match the selected project's key when the project has one; without `--shared`, a different prefix does not protect against acting on the same number in the selected project.
236
236
 
237
237
  | Command | Options |
@@ -281,8 +281,7 @@ A non-empty `NOLTO_HOME` selects the directory as-is; otherwise use
281
281
  ```json
282
282
  {
283
283
  "token": "nolto_user_...",
284
- "baseUrl": "https://nolto.app",
285
- "defaultProjectId": "00000000-0000-0000-0000-000000000001"
284
+ "baseUrl": "https://nolto.app"
286
285
  }
287
286
  ```
288
287
 
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,7 +24,15 @@ var CliError = class extends Error {
23
24
  serverError;
24
25
  body;
25
26
  detail;
27
+ retryAfter;
26
28
  };
29
+ function projectRequiredError() {
30
+ return new CliError(
31
+ "\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u304C\u6C7A\u307E\u308A\u307E\u305B\u3093\u3002nolto.json \u306E\u3042\u308B\u30EA\u30DD\u30B8\u30C8\u30EA(\u304B\u3001\u305D\u306E\u4E0B)\u3067\u5B9F\u884C\u3059\u308B\u304B\u3001--project <id> / NOLTO_PROJECT \u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002",
32
+ 2,
33
+ "nolto init \u307E\u305F\u306F nolto link <projectId> \u3067 nolto.json \u3092\u4F5C\u308B"
34
+ );
35
+ }
27
36
  function mapHttpStatusToCliError(status, opts = {}) {
28
37
  if (opts.serverError?.startsWith("memory_") || status === 400 && opts.serverError === "invalid_input") {
29
38
  return new CliError(opts.serverMessage ?? opts.serverError, 2, void 0, status, opts.serverError, opts.body);
@@ -149,7 +158,7 @@ function mapHttpStatusToCliError(status, opts = {}) {
149
158
  return new CliError(`${opts.serverMessage ?? "Rate limit exceeded."}${waitMsg}`, 4, void 0, status, opts.serverError, opts.body);
150
159
  }
151
160
  const reason = opts.serverMessage ?? opts.serverError;
152
- return new CliError(reason ? `Server returned HTTP ${status}: ${reason}` : `Server returned HTTP ${status}`, 5, void 0, status, opts.serverError, opts.body);
161
+ 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);
153
162
  }
154
163
  var NETWORK_ERROR_CODES = [
155
164
  "ECONNREFUSED",
@@ -414,6 +423,7 @@ var CLI_USER_AGENT_NAME = "nolto-cli";
414
423
  var configSchema = z.object({
415
424
  token: z.string().min(1).optional(),
416
425
  baseUrl: z.string().url().optional(),
426
+ // NF-165 で廃止。読まない。
417
427
  defaultProjectId: z.string().uuid().optional()
418
428
  }).strict();
419
429
  var repoBindingSchema = z.object({
@@ -549,20 +559,17 @@ async function saveConfigFile(filePath, value) {
549
559
  await writeFile3(filePath, JSON.stringify(value, null, 2) + "\n", { mode: 384 });
550
560
  }
551
561
  function resolveProjectId(args) {
552
- const { flagProject, envProject, repoBinding, fileProjectId } = args;
562
+ const { flagProject, envProject, repoBinding } = args;
553
563
  if (flagProject != null && flagProject.length > 0) {
554
- return { defaultProjectId: flagProject, projectSource: "flag" };
564
+ return { projectId: flagProject, projectSource: "flag" };
555
565
  }
556
566
  if (envProject != null && envProject.length > 0) {
557
- return { defaultProjectId: envProject, projectSource: "env" };
567
+ return { projectId: envProject, projectSource: "env" };
558
568
  }
559
569
  if (repoBinding != null && repoBinding.projectId.length > 0) {
560
- return { defaultProjectId: repoBinding.projectId, projectSource: "repo" };
561
- }
562
- if (fileProjectId != null && fileProjectId.length > 0) {
563
- return { defaultProjectId: fileProjectId, projectSource: "file" };
570
+ return { projectId: repoBinding.projectId, projectSource: "repo" };
564
571
  }
565
- return { defaultProjectId: void 0, projectSource: "none" };
572
+ return { projectId: void 0, projectSource: "none" };
566
573
  }
567
574
  function resolveSettings(args) {
568
575
  const { flags, env, file, repoBinding } = args;
@@ -592,16 +599,15 @@ function resolveSettings(args) {
592
599
  } else {
593
600
  baseUrl = DEFAULT_BASE_URL;
594
601
  }
595
- const { defaultProjectId, projectSource } = resolveProjectId({
602
+ const { projectId, projectSource } = resolveProjectId({
596
603
  flagProject: flags.project,
597
604
  envProject: env["NOLTO_PROJECT"],
598
- repoBinding,
599
- fileProjectId: file?.defaultProjectId
605
+ repoBinding
600
606
  });
601
607
  return {
602
608
  token,
603
609
  baseUrl,
604
- defaultProjectId,
610
+ projectId,
605
611
  source: { token: tokenSource, baseUrl: baseUrlSource, project: projectSource }
606
612
  };
607
613
  }
@@ -1366,6 +1372,33 @@ import path6 from "path";
1366
1372
  // src/sync-core.ts
1367
1373
  import { createHash as createHash2 } from "crypto";
1368
1374
  import path5 from "path";
1375
+
1376
+ // src/busy-retry.ts
1377
+ var MAX_RETRIES = 3;
1378
+ function busyWaitSeconds(retryAfter) {
1379
+ const seconds = Number(retryAfter.trim());
1380
+ if (retryAfter.trim() === "" || !Number.isFinite(seconds)) return void 0;
1381
+ return Math.min(30, Math.max(1, Math.ceil(seconds)));
1382
+ }
1383
+ async function retryWhenBusy(send, hooks = {}) {
1384
+ const sleep2 = hooks.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
1385
+ const random = hooks.random ?? Math.random;
1386
+ const notify = hooks.notify ?? ((line2) => {
1387
+ process.stderr.write(line2 + "\n");
1388
+ });
1389
+ for (let attempt = 1; ; attempt++) {
1390
+ try {
1391
+ return await send();
1392
+ } catch (err) {
1393
+ const wait = err instanceof CliError && err.status === 503 && err.retryAfter !== void 0 ? busyWaitSeconds(err.retryAfter) : void 0;
1394
+ if (wait === void 0 || attempt > MAX_RETRIES) throw err;
1395
+ notify(`Server busy; retrying in ${wait} s (attempt ${attempt}/${MAX_RETRIES})`);
1396
+ await sleep2(wait * 1e3 + Math.floor(random() * 1e3));
1397
+ }
1398
+ }
1399
+ }
1400
+
1401
+ // src/sync-core.ts
1369
1402
  function sha256Hex(content) {
1370
1403
  return "sha256:" + createHash2("sha256").update(content, "utf8").digest("hex");
1371
1404
  }
@@ -1469,10 +1502,9 @@ async function runSync(args, deps) {
1469
1502
  repoIdentity: args.repoIdentity,
1470
1503
  deps
1471
1504
  });
1472
- const response = await deps.http.put(
1473
- `/api/projects/${args.projectId}/roadmaps/${encodeURIComponent(args.slug)}`,
1474
- { ...body, baseRevision: args.baseRevision }
1475
- );
1505
+ const syncPath = `/api/projects/${args.projectId}/roadmaps/${encodeURIComponent(args.slug)}`;
1506
+ const syncBody = { ...body, baseRevision: args.baseRevision };
1507
+ const response = await retryWhenBusy(() => deps.http.put(syncPath, syncBody), deps.retry);
1476
1508
  for (const warning of response.warnings ?? []) deps.warn(warning);
1477
1509
  const stats = deriveTaskStats(response.roadmap ?? args.roadmap);
1478
1510
  deps.log(
@@ -2280,13 +2312,13 @@ async function resolveRoadmapReadContext(deps) {
2280
2312
  }
2281
2313
  const startDir = resolveStartDir(process.env, process.cwd());
2282
2314
  const { root, foundGit } = findRepoRoot(startDir);
2283
- if (!foundGit) {
2284
- throw new CliError("No git repository found. Run inside a repo set up with `nolto init`.", 2);
2285
- }
2286
2315
  const binding = await loadRepoBinding(path12.join(root, "nolto.json"));
2287
- const projectId = binding?.projectId ?? deps.settings.defaultProjectId;
2316
+ const projectId = binding?.projectId ?? deps.settings.projectId;
2288
2317
  if (projectId == null) {
2289
- throw new CliError("No project binding. Run `nolto init` or `nolto link <projectId>`.", 2);
2318
+ throw projectRequiredError();
2319
+ }
2320
+ if (!foundGit) {
2321
+ throw new CliError("No git repository found. Run inside a repo set up with `nolto init`.", 2);
2290
2322
  }
2291
2323
  return { root, projectId };
2292
2324
  }
@@ -2451,7 +2483,7 @@ async function syncRepo(args, io) {
2451
2483
  try {
2452
2484
  const response = await runSync(
2453
2485
  { repoRoot: args.root, projectId, slug, roadmap, repoIdentity, baseRevision: meta?.revision ?? 0 },
2454
- { http: io.http, readFile: io.readFile, fileExists: io.fileExists, realpath: io.realpath, ...isIgnored ? { isIgnored } : {}, log: io.log, warn: io.warn }
2486
+ { 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 } : {} }
2455
2487
  );
2456
2488
  await writeCache(io.env, projectId, slug, response.roadmap ?? roadmap, {
2457
2489
  repoIdentity: identity,
@@ -2488,10 +2520,11 @@ async function syncRepo(args, io) {
2488
2520
  if (body && body.links.length > 0) {
2489
2521
  gitLinks = { linked: 0, existing: 0, skipped: 0 };
2490
2522
  for (let offset = 0; offset < body.links.length; offset += 500) {
2491
- const response = await io.http.post(
2523
+ const chunk = { links: body.links.slice(offset, offset + 500), repoIdentity };
2524
+ const response = await retryWhenBusy(() => io.http.post(
2492
2525
  `/api/projects/${projectId}/git-links`,
2493
- { links: body.links.slice(offset, offset + 500), repoIdentity }
2494
- );
2526
+ chunk
2527
+ ), io.retry);
2495
2528
  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");
2496
2529
  gitLinks = { linked: gitLinks.linked + response.linked, existing: gitLinks.existing + response.existing, skipped: gitLinks.skipped + response.skipped };
2497
2530
  for (const warning of response.warnings) io.warn(`git links: ${warning}`);
@@ -2826,6 +2859,7 @@ async function checkShared(deps, root, flags, ref) {
2826
2859
  if (ref?.includes("-") && key && ref.slice(0, ref.lastIndexOf("-")).toUpperCase() !== key.toUpperCase()) {
2827
2860
  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);
2828
2861
  }
2862
+ return context3.project?.name;
2829
2863
  }
2830
2864
  function warningLines(warnings) {
2831
2865
  return Array.isArray(warnings) ? warnings.filter((text) => typeof text === "string").map((text) => `
@@ -2873,14 +2907,25 @@ async function writeRequest(deps, mode2, flags, method, path24, body) {
2873
2907
  function context(deps, command) {
2874
2908
  if (!deps.settings.token) throw new CliError("Not authenticated. Run `nolto login` or set NOLTO_TOKEN.", 3);
2875
2909
  const globals = command.optsWithGlobals();
2876
- const projectId = globals.project ?? deps.settings.defaultProjectId;
2877
- if (!projectId) throw new CliError("No project. Pass --project <id> or run nolto link.", 2);
2910
+ const projectId = globals.project ?? deps.settings.projectId;
2911
+ if (!projectId) throw projectRequiredError();
2878
2912
  return {
2879
2913
  projectId,
2880
2914
  root: `/api/projects/${encodeURIComponent(projectId)}`,
2881
- mode: globals.json ? "json" : deps.output.mode
2915
+ mode: globals.json ? "json" : deps.output.mode,
2916
+ projectName: void 0
2882
2917
  };
2883
2918
  }
2919
+ async function projectLine(deps, ctx) {
2920
+ if (ctx.mode === "json") return "";
2921
+ let name = ctx.projectName;
2922
+ if (!name) {
2923
+ const result = await deps.http.get(ctx.root).catch(() => null);
2924
+ name = result?.project?.name;
2925
+ }
2926
+ return `
2927
+ \u30D7\u30ED\u30B8\u30A7\u30AF\u30C8: ${oneLine(name || ctx.projectId)}`;
2928
+ }
2884
2929
  async function bodyText(body, file) {
2885
2930
  if (body !== void 0 && file !== void 0) throw new CliError("Use either --body/-m or --body-file, not both.", 2);
2886
2931
  if (file === void 0) return body;
@@ -2949,7 +2994,7 @@ function writeOptions(command, create) {
2949
2994
  function register4(program, deps) {
2950
2995
  const group = program.command("issue").description("List, view and manage project issues.").addHelpText("after", `
2951
2996
  All commands accept global \`--project <id>\`, \`--json\`, \`--token <value>\` and \`--base-url <url>\`.
2952
- Project priority: flag \u2192 NOLTO_PROJECT \u2192 nearest ancestor nolto.json \u2192 config defaultProjectId. Git is not required. An invalid nolto.json remains an error.
2997
+ Project priority: flag \u2192 NOLTO_PROJECT \u2192 nearest ancestor nolto.json. Git is not required. An invalid nolto.json remains an error.
2953
2998
 
2954
2999
  nolto issue create --draft --subject "\u2026"
2955
3000
  nolto issue drafts
@@ -2980,17 +3025,19 @@ nolto issue publish <draft-id>
2980
3025
  if (flags.draft && flags.shared) throw new CliError("--shared cannot be combined with --draft.", 2);
2981
3026
  if (flags.draft && (flags.phase !== void 0 || flags.roadmap !== void 0)) throw new CliError("--phase and --roadmap cannot be used with --draft. Publish the draft first.", 2);
2982
3027
  if (flags.roadmap !== void 0 && flags.phase === void 0) throw new CliError("--roadmap requires --phase.", 2);
2983
- await checkShared(deps, ctx.root, flags);
3028
+ ctx.projectName = await checkShared(deps, ctx.root, flags);
2984
3029
  const { input, fromTemplate } = await writeInput(deps, ctx.root, flags, true);
2985
3030
  if (flags.draft) {
3031
+ const project2 = await projectLine(deps, ctx);
2986
3032
  const result2 = await writeRequest(deps, ctx.mode, flags, "post", `${ctx.root}/issue-drafts`, input);
2987
- printResult(ctx.mode === "json" ? result2 : `draft ${result2.draft.id} created${writeSuffix(flags)}
3033
+ printResult(ctx.mode === "json" ? result2 : `draft ${result2.draft.id} created${writeSuffix(flags)}${project2}
2988
3034
  ${draftUrl(deps.settings.baseUrl, ctx.projectId, result2.draft.id)}${warningLines(result2.warnings)}`, ctx.mode);
2989
3035
  return;
2990
3036
  }
3037
+ const project = await projectLine(deps, ctx);
2991
3038
  const result = await writeRequest(deps, ctx.mode, flags, "post", `${ctx.root}/issues`, input);
2992
3039
  const roadmap = flags.phase === void 0 ? void 0 : await attachRoadmap(deps, flags.phase, flags.roadmap, result.issue.key);
2993
- printResult(ctx.mode === "json" ? { ...result, ...roadmap ? { roadmap } : {} } : `${result.issue.key} created${writeSuffix(flags)}
3040
+ printResult(ctx.mode === "json" ? { ...result, ...roadmap ? { roadmap } : {} } : `${result.issue.key} created${writeSuffix(flags)}${project}
2994
3041
  ${issueUrl(deps.settings.baseUrl, ctx.projectId, result.issue.number)}${fromTemplate ? "\nbody: from template" : ""}${warningLines(result.warnings)}`, ctx.mode);
2995
3042
  });
2996
3043
  group.command("drafts").description("List your issue drafts (visible only to you).").action(async (_flags, command) => {
@@ -3001,38 +3048,42 @@ ${issueUrl(deps.settings.baseUrl, ctx.projectId, result.issue.number)}${fromTemp
3001
3048
  group.command("publish <draft-id>").description("Publish a draft as an issue.").action(async (id, flags, command) => {
3002
3049
  const ctx = context(deps, command);
3003
3050
  if (!isUuid(id)) throw new CliError("<draft-id> must be a UUID. Run `nolto issue drafts` to list drafts.", 2);
3051
+ const project = await projectLine(deps, ctx);
3004
3052
  const result = await writeRequest(deps, ctx.mode, flags, "post", `${ctx.root}/issue-drafts/${id}/publish`, void 0);
3005
- printResult(ctx.mode === "json" ? result : `${result.issue.key} published
3053
+ printResult(ctx.mode === "json" ? result : `${result.issue.key} published${project}
3006
3054
  ${issueUrl(deps.settings.baseUrl, ctx.projectId, result.issue.number)}${warningLines(result.warnings)}`, ctx.mode);
3007
3055
  });
3008
3056
  writeOptions(group.command("update <ref>").description("Update issue fields."), false).action(async (ref, flags, command) => {
3009
3057
  const ctx = context(deps, command);
3010
3058
  const number = parseIssueRef(ref);
3011
- await checkShared(deps, ctx.root, flags, ref);
3059
+ ctx.projectName = await checkShared(deps, ctx.root, flags, ref);
3012
3060
  const { input } = await writeInput(deps, ctx.root, flags, false);
3061
+ const project = await projectLine(deps, ctx);
3013
3062
  const result = await writeRequest(deps, ctx.mode, flags, "patch", `${ctx.root}/issues/${number}`, input);
3014
- printResult(ctx.mode === "json" ? result : `${result.issue.key} updated${writeSuffix(flags)}
3063
+ printResult(ctx.mode === "json" ? result : `${result.issue.key} updated${writeSuffix(flags)}${project}
3015
3064
  ${issueUrl(deps.settings.baseUrl, ctx.projectId, number)}${warningLines(result.warnings)}`, ctx.mode);
3016
3065
  });
3017
3066
  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) => {
3018
3067
  const ctx = context(deps, command);
3019
3068
  const number = parseIssueRef(ref);
3020
- await checkShared(deps, ctx.root, flags, ref);
3069
+ ctx.projectName = await checkShared(deps, ctx.root, flags, ref);
3021
3070
  const body = await bodyText(flags.comment, flags.bodyFile);
3022
3071
  if (!body?.trim()) throw new CliError("A comment is required. Use -m or --body-file.", 2);
3023
3072
  const issue = ctx.mode === "human" ? (await deps.http.get(`${ctx.root}/issues/${number}`)).issue : void 0;
3073
+ const project = await projectLine(deps, ctx);
3024
3074
  const result = await writeRequest(deps, ctx.mode, flags, "post", `${ctx.root}/issues/${number}/comments`, { body });
3025
- printResult(ctx.mode === "json" ? result : `${issue.key} commented${writeSuffix(flags)}
3075
+ printResult(ctx.mode === "json" ? result : `${issue.key} commented${writeSuffix(flags)}${project}
3026
3076
  ${issueUrl(deps.settings.baseUrl, ctx.projectId, number)}${warningLines(result.warnings)}`, ctx.mode);
3027
3077
  });
3028
3078
  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) => {
3029
3079
  const ctx = context(deps, command);
3030
3080
  const number = parseIssueRef(ref);
3031
- await checkShared(deps, ctx.root, flags, ref);
3081
+ ctx.projectName = await checkShared(deps, ctx.root, flags, ref);
3032
3082
  const settings = await deps.http.get(`${ctx.root}/issue-settings`);
3033
3083
  const status = pickClosedStatus(settings, flags.status);
3084
+ const project = await projectLine(deps, ctx);
3034
3085
  const result = await writeRequest(deps, ctx.mode, flags, "patch", `${ctx.root}/issues/${number}`, { statusId: status.id, ...flags.comment !== void 0 ? { comment: flags.comment } : {} });
3035
- printResult(ctx.mode === "json" ? result : `${result.issue.key} closed${writeSuffix(flags)}
3086
+ printResult(ctx.mode === "json" ? result : `${result.issue.key} closed${writeSuffix(flags)}${project}
3036
3087
  ${issueUrl(deps.settings.baseUrl, ctx.projectId, number)}${warningLines(result.warnings)}`, ctx.mode);
3037
3088
  });
3038
3089
  }
@@ -3302,6 +3353,19 @@ async function createMemoryContext(opts, recover = false) {
3302
3353
  const cache = owned ? read : { state: { entries: [], scope: "", projectName: project.slice(0, 8), ...fingerprint ? { tokenFingerprint: fingerprint } : {} }, meta: { cursor: 0, pulledAt: "" } };
3303
3354
  return { project, dir, root, git, cache, api: `/api/projects/${project}/memory`, stale: !owned };
3304
3355
  }
3356
+ async function resolveMemoryProjectName(ctx, http, human) {
3357
+ const name = ctx.cache.state.projectName;
3358
+ if (!human || ctx.projectNameRequested || name && name !== ctx.project.slice(0, 8)) return;
3359
+ ctx.projectNameRequested = true;
3360
+ const result = await http.get(`/api/projects/${encodeURIComponent(ctx.project)}`).catch(() => null);
3361
+ if (typeof result?.project?.name === "string" && result.project.name.trim()) {
3362
+ ctx.cache.state.projectName = result.project.name;
3363
+ }
3364
+ }
3365
+ function memoryProjectSuffix(ctx) {
3366
+ const name = ctx.cache.state.projectName;
3367
+ return ` \u2192 \u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u300C${oneLine(name && name !== ctx.project.slice(0, 8) ? name : ctx.project)}\u300D`;
3368
+ }
3305
3369
  async function memoryIndexText(ctx, deps) {
3306
3370
  const entries = ctx.cache.state.entries.filter((e) => !e.deleted && e.scope === "branch" && e.repoIdentity === ctx.git.repoIdentity);
3307
3371
  const branches = [...new Set(entries.map((e) => e.branch))];
@@ -3370,6 +3434,7 @@ async function importMemoryFiles(opts) {
3370
3434
  allowNew: true,
3371
3435
  ...opts.ai ? {} : { aiSkip: true }
3372
3436
  }, { "X-Nolto-Client": detectMemoryClient(process.env) });
3437
+ await resolveMemoryProjectName(ctx, opts.http, opts.human !== false);
3373
3438
  cached = await updateCache(ctx, opts, writtenEntries(ctx, response), true) && cached;
3374
3439
  heading = aiHeading(response);
3375
3440
  imported++;
@@ -3387,7 +3452,7 @@ async function importMemoryFiles(opts) {
3387
3452
  }
3388
3453
  const result = { file, name, original, status, ...message ? { message } : {} };
3389
3454
  results.push(result);
3390
- opts.write(heading ? `${heading} (\u5143: ${oneLine(file)})` : importResultLine(opts.scope, result));
3455
+ opts.write((heading ? `${heading} (\u5143: ${oneLine(file)})` : importResultLine(opts.scope, result)) + memoryProjectSuffix(ctx));
3391
3456
  }
3392
3457
  return { imported, skipped, failed, results, cached };
3393
3458
  }
@@ -3500,16 +3565,7 @@ async function pickProject(rl, http, projects, promptText, baseUrl) {
3500
3565
  }
3501
3566
  return void 0;
3502
3567
  }
3503
- async function selectRepoProject(rl, http, projects, defaultProjectId, baseUrl) {
3504
- const defaultProject = defaultProjectId == null ? void 0 : projects.find((project) => project.id === defaultProjectId);
3505
- if (defaultProject != null) {
3506
- const useDefault = await rl.question(
3507
- `Use "${stripTerminal(defaultProject.name)}" (${defaultProject.id}) for this repository? [Y/n] `
3508
- );
3509
- if (useDefault.trim().toLowerCase() !== "n") {
3510
- return defaultProject;
3511
- }
3512
- }
3568
+ async function selectRepoProject(rl, http, projects, baseUrl) {
3513
3569
  return pickProject(
3514
3570
  rl,
3515
3571
  http,
@@ -3565,6 +3621,7 @@ async function setupMemory(opts) {
3565
3621
  git,
3566
3622
  memoryGit: deps.memoryGit,
3567
3623
  token,
3624
+ human: deps.output.mode !== "json",
3568
3625
  write: (line2) => {
3569
3626
  process.stdout.write(line2 + "\n");
3570
3627
  }
@@ -3603,7 +3660,7 @@ async function setupMemory(opts) {
3603
3660
  `);
3604
3661
  }
3605
3662
  function register5(program, deps) {
3606
- program.command("init").description("Interactive setup: configure token, base URL, and default project.").option("--force", "Overwrite existing config without prompting").option("--memory", "Set up Nolto memory without the initial confirmation").option("--no-memory", "Skip memory setup").action(async (opts) => {
3663
+ program.command("init").description("Interactive setup: configure token, base URL, and repository project.").option("--force", "Overwrite existing config without prompting").option("--memory", "Set up Nolto memory without the initial confirmation").option("--no-memory", "Skip memory setup").action(async (opts) => {
3607
3664
  const configPath = deps.configPath;
3608
3665
  const rl = readline3.createInterface({ input: process.stdin, output: process.stdout });
3609
3666
  try {
@@ -3625,8 +3682,6 @@ function register5(program, deps) {
3625
3682
  }
3626
3683
  let token = deps.settings.token ?? "";
3627
3684
  let baseUrl = deps.settings.baseUrl;
3628
- let defaultProjectId = deps.settings.defaultProjectId;
3629
- let defaultProjectName;
3630
3685
  let http;
3631
3686
  let projects;
3632
3687
  if (configureGlobal) {
@@ -3653,45 +3708,28 @@ function register5(program, deps) {
3653
3708
  }
3654
3709
  throw err;
3655
3710
  }
3656
- const selected = await pickProject(
3657
- rl,
3658
- http,
3659
- projects,
3660
- "Default project number, 'c' to create new (or Enter to skip): ",
3661
- baseUrl
3662
- );
3663
- defaultProjectId = selected?.id;
3664
- defaultProjectName = selected?.name;
3665
- if (selected != null && !projects.some((project) => project.id === selected.id)) {
3666
- projects = [...projects, selected];
3667
- }
3668
3711
  await clearMemoryCaches(configPath);
3669
3712
  await saveConfigFile(configPath, {
3670
3713
  token,
3671
- baseUrl: baseUrl !== DEFAULT_BASE_URL ? baseUrl : void 0,
3672
- defaultProjectId
3714
+ baseUrl: baseUrl !== DEFAULT_BASE_URL ? baseUrl : void 0
3673
3715
  });
3674
- const projectDisplay = defaultProjectId != null ? `${stripTerminal(defaultProjectName)} (${defaultProjectId})` : "not set";
3675
3716
  process.stdout.write(`
3676
3717
  Saved ${configPath}
3677
3718
  `);
3678
3719
  process.stdout.write(`baseUrl: ${baseUrl}
3679
3720
  `);
3680
3721
  process.stdout.write(`token: ${maskToken(token)} (verified)
3681
- `);
3682
- process.stdout.write(`defaultProject: ${projectDisplay}
3683
3722
  `);
3684
3723
  } else {
3685
- const projectDisplay = defaultProjectId ?? "not set";
3686
3724
  process.stdout.write(
3687
- `Using existing config: baseUrl=${baseUrl}, token=${maskToken(token)}, defaultProject=${projectDisplay}
3725
+ `Using existing config: baseUrl=${baseUrl}, token=${maskToken(token)}
3688
3726
  `
3689
3727
  );
3690
3728
  }
3691
3729
  const startDir = resolveStartDir(process.env, process.cwd());
3692
3730
  const { root, foundGit } = findRepoRoot(startDir);
3693
3731
  if (!foundGit) {
3694
- process.stdout.write("\nNo git repository found here \u2014 skipped repo setup. Run `nolto init` inside a repo to set up roadmap sync.\n");
3732
+ process.stdout.write("\nNo git repository found here \u2014 skipped repo setup. Run `nolto init` inside a repo to set up roadmap sync. Project commands require nolto.json in this directory or an ancestor, or --project / NOLTO_PROJECT.\n");
3695
3733
  return;
3696
3734
  }
3697
3735
  if (isHomeDirectory(root)) {
@@ -3728,9 +3766,9 @@ Saved ${configPath}
3728
3766
  boundProject != null ? "Keep this binding? [Y/n] " : "Keep this binding? [y/N] "
3729
3767
  );
3730
3768
  keepExistingBinding = boundProject != null ? keep.trim().toLowerCase() !== "n" : keep.trim().toLowerCase() === "y";
3731
- repoProject = keepExistingBinding ? boundProject ?? { id: existingBinding.projectId, name: path17.basename(root) } : await selectRepoProject(rl, repoHttp, projects, defaultProjectId, baseUrl);
3769
+ repoProject = keepExistingBinding ? boundProject ?? { id: existingBinding.projectId, name: path17.basename(root) } : await selectRepoProject(rl, repoHttp, projects, baseUrl);
3732
3770
  } else {
3733
- repoProject = await selectRepoProject(rl, repoHttp, projects, defaultProjectId, baseUrl);
3771
+ repoProject = await selectRepoProject(rl, repoHttp, projects, baseUrl);
3734
3772
  }
3735
3773
  if (repoProject == null) {
3736
3774
  process.stdout.write("Skipped repo setup (no project selected).\n");
@@ -3962,7 +4000,7 @@ function register6(program, deps) {
3962
4000
  });
3963
4001
  const existingConfig = await loadConfigFile(configPath).catch(() => null);
3964
4002
  const newConfig = {
3965
- ...existingConfig,
4003
+ baseUrl: existingConfig?.baseUrl,
3966
4004
  token
3967
4005
  };
3968
4006
  await clearMemoryCaches(configPath);
@@ -4017,8 +4055,8 @@ function register7(program, deps) {
4017
4055
  configPath,
4018
4056
  tokenLast4: settings.token != null ? settings.token.slice(-4) : null,
4019
4057
  tokenSource: settings.source.token,
4020
- defaultProject: settings.defaultProjectId ?? null,
4021
- defaultProjectSource: settings.source.project,
4058
+ project: settings.projectId ?? null,
4059
+ projectSource: settings.source.project,
4022
4060
  projectBindingPath: projectBindingPath ?? null,
4023
4061
  projects: projectCount ?? null,
4024
4062
  ...tokenInfo ? { tokenScopes: tokenInfo.scopes, tokenProject: tokenInfo.projectId } : {}
@@ -4027,22 +4065,26 @@ function register7(program, deps) {
4027
4065
  );
4028
4066
  } else {
4029
4067
  const tokenDisplay = settings.token != null ? `${maskToken(settings.token)} (source: ${settings.source.token})` : "(not configured)";
4030
- const bindingDisplay = settings.source.project === "repo" && projectBindingPath != null ? `${settings.defaultProjectId ?? "none"} (source: repo, binding: ${projectBindingPath})` : `${settings.defaultProjectId ?? "none"} (source: ${settings.source.project})`;
4068
+ const bindingDisplay = settings.source.project === "repo" && projectBindingPath != null ? `${settings.projectId ?? "none"} (source: repo, binding: ${projectBindingPath})` : `${settings.projectId ?? "none"} (source: ${settings.source.project})`;
4031
4069
  const lines = [
4032
4070
  ["baseUrl", `${settings.baseUrl} (source: ${settings.source.baseUrl})`],
4033
4071
  ["configPath", configPath],
4034
4072
  ["token", tokenDisplay],
4035
- ["defaultProject", bindingDisplay],
4073
+ ["project", bindingDisplay],
4036
4074
  ["projects", projectCount != null ? String(projectCount) : settings.token != null ? "(unavailable)" : "(no token)"]
4037
4075
  ];
4038
4076
  if (tokenInfo) {
4039
- lines.push(["scopes", tokenInfo.scopes === null ? "full" : tokenInfo.scopes.join(", ")], ["project", tokenInfo.projectId ?? "all"]);
4077
+ lines.push(["scopes", tokenInfo.scopes === null ? "full" : tokenInfo.scopes.join(", ")], ["tokenProject", tokenInfo.projectId ?? "all"]);
4040
4078
  }
4079
+ const legacyConfig = await loadConfigFile(configPath).catch(() => null);
4041
4080
  const maxKey = lines.reduce((m, [k]) => Math.max(m, k.length), 0);
4042
4081
  for (const [key, val] of lines) {
4043
4082
  process.stdout.write(`${key.padEnd(maxKey)}: ${val}
4044
4083
  `);
4045
4084
  }
4085
+ if (legacyConfig?.defaultProjectId) {
4086
+ process.stdout.write("(config \u306E defaultProjectId \u306F\u4F7F\u308F\u308C\u307E\u305B\u3093\u3002nolto init \u304B nolto login \u3067\u8A2D\u5B9A\u3092\u4FDD\u5B58\u3057\u76F4\u3059\u3068\u6D88\u3048\u307E\u3059)\n");
4087
+ }
4046
4088
  }
4047
4089
  });
4048
4090
  }
@@ -5405,10 +5447,8 @@ var aiSkippedLine = (reason) => `AI \u6574\u7406\u306A\u3057(${aiSkipReasons[rea
5405
5447
  var pullHint = "nolto memory pull \u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044";
5406
5448
  var scopeHint = "--scope project|user|branch";
5407
5449
  async function context2(deps, recover = false) {
5408
- const bindingPath = deps.repoBinding?.path ?? deps.projectBindingPath;
5409
- const binding = deps.repoBinding?.binding ?? (bindingPath ? await loadRepoBinding(bindingPath) : null);
5410
- const project = deps.settings.defaultProjectId ?? binding?.projectId;
5411
- if (!project) throw new CliError("\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u304C\u672A\u8A2D\u5B9A\u3067\u3059\u3002", 2, "nolto link \u307E\u305F\u306F --project <id>");
5450
+ const project = deps.settings.projectId;
5451
+ if (!project) throw projectRequiredError();
5412
5452
  const root = findRepoRoot(resolveStartDir(process.env, process.cwd())).root;
5413
5453
  return createMemoryContext({ projectId: project, configPath: deps.configPath, root, git: await memoryGitContext(root, deps), token: deps.settings.token }, recover);
5414
5454
  }
@@ -5493,7 +5533,7 @@ function printWrite(deps, ctx, action, response, isNew = false, put) {
5493
5533
  const { entry } = response;
5494
5534
  const heading = aiHeading(response, put?.name);
5495
5535
  const lifetime = action === "put" ? [entry.expiresOn ? `expires ${oneLine(entry.expiresOn)}` : "", entry.until ? `until ${oneLine(entry.until)}` : ""].filter(Boolean) : [];
5496
- const lines = [heading ?? `${action} ${entry.scope}/${entry.name} r${entry.revision}${isNew ? " (\u65B0\u898F)" : ""}${lifetime.length ? ` (${lifetime.join("\u3001")})` : ""}`];
5536
+ const lines = [(heading ?? `${action} ${entry.scope}/${entry.name} r${entry.revision}${isNew ? " (\u65B0\u898F)" : ""}${lifetime.length ? ` (${lifetime.join("\u3001")})` : ""}`) + memoryProjectSuffix(ctx)];
5497
5537
  if (heading && put && put.name !== entry.name && !put.allowNew) lines.push(`\u65B0\u898F\u306B\u4F5C\u308B\u306A\u3089: nolto memory put --new ${shellArg(put.file)}`);
5498
5538
  if (response.aiSkipped) lines.push(aiSkippedLine(response.aiSkipped));
5499
5539
  const affected = response.affected ?? [];
@@ -5515,7 +5555,6 @@ async function pull2(deps, opts) {
5515
5555
  try {
5516
5556
  const explicitProject = deps.settings.source?.project === "flag" || deps.settings.source?.project === "env";
5517
5557
  if (opts.hook && !explicitProject && !(deps.repoBinding?.path ?? deps.projectBindingPath)) {
5518
- process.stdout.write(hookOutput(opts.hook, "nolto link \u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044"));
5519
5558
  return;
5520
5559
  }
5521
5560
  if (opts.hook && !deps.settings.token) {
@@ -5677,6 +5716,7 @@ function register13(program, deps) {
5677
5716
  const changed = /* @__PURE__ */ new Set([response.entry.id, ...(response.affected ?? []).map((a) => a.entryId)]);
5678
5717
  ctx.cache.state.cleanupCandidates = (ctx.cache.state.cleanupCandidates ?? []).filter((c) => !changed.has(c.entryId));
5679
5718
  }
5719
+ await resolveMemoryProjectName(ctx, deps.http, deps.output.mode !== "json");
5680
5720
  await updateCache(ctx, deps, writtenEntries(ctx, response));
5681
5721
  printWrite(deps, ctx, "put", response, draft.revision === void 0, { name: draft.name, file, allowNew: opts.new });
5682
5722
  });
@@ -5687,6 +5727,7 @@ function register13(program, deps) {
5687
5727
  try {
5688
5728
  const entry = resolveEntry(ctx, name, opts);
5689
5729
  const response = await apiCall(deps, ctx, () => deps.http.delete(`${ctx.api}/${encodeURIComponent(entry.id)}?baseRevision=${entry.revision}`, headers()), "rm", name);
5730
+ await resolveMemoryProjectName(ctx, deps.http, deps.output.mode !== "json");
5690
5731
  await updateCache(ctx, deps, writtenEntries(ctx, response));
5691
5732
  results.push(response);
5692
5733
  if (names.length === 1 || deps.output.mode !== "json") printWrite(deps, ctx, "rm", response);
@@ -5705,6 +5746,7 @@ function register13(program, deps) {
5705
5746
  const ctx = await context2(deps);
5706
5747
  const entry = resolveEntry(ctx, name, opts, true);
5707
5748
  const response = await apiCall(deps, ctx, () => deps.http.post(`${ctx.api}/${encodeURIComponent(entry.id)}/revert`, { revision: parseRevision(revision), baseRevision: entry.revision }, headers()), "revert", name);
5749
+ await resolveMemoryProjectName(ctx, deps.http, deps.output.mode !== "json");
5708
5750
  await updateCache(ctx, deps, writtenEntries(ctx, response));
5709
5751
  printWrite(deps, ctx, "revert", response);
5710
5752
  });
@@ -5726,8 +5768,9 @@ function register13(program, deps) {
5726
5768
  }
5727
5769
  const response = await apiCall(deps, ctx, () => deps.http.post(`${ctx.api}/promote`, { repoIdentity: ctx.git.repoIdentity, branch: opts.branch, ...names.length ? { names } : {}, ...opts.discard ? { discard: true } : {} }, headers()), "promote");
5728
5770
  const retired = selected.map((e) => ({ ...e, deleted: true }));
5771
+ await resolveMemoryProjectName(ctx, deps.http, deps.output.mode !== "json");
5729
5772
  await updateCache(ctx, deps, [...retired, ...response.promoted, ...response.discarded]);
5730
- printResult(deps.output.mode === "json" ? response : [...response.promoted.map((e) => `promote ${line(e)}`), ...response.discarded.map((e) => `discard ${line(e)}`)].join("\n"), deps.output.mode);
5773
+ printResult(deps.output.mode === "json" ? response : [...response.promoted.map((e) => `promote ${line(e)}${memoryProjectSuffix(ctx)}`), ...response.discarded.map((e) => `discard ${line(e)}${memoryProjectSuffix(ctx)}`)].join("\n"), deps.output.mode);
5731
5774
  });
5732
5775
  memory.command("hook").command("install").option("--agent <agent>").option("--write-agents-md").action(async (opts) => {
5733
5776
  const { root } = findRepoRoot(resolveStartDir(process.env, process.cwd()));
@@ -5749,6 +5792,7 @@ function register13(program, deps) {
5749
5792
  token: deps.settings.token,
5750
5793
  scope,
5751
5794
  targets: scan.ok,
5795
+ human: deps.output.mode !== "json",
5752
5796
  ai: opts.ai,
5753
5797
  git: ctx.git,
5754
5798
  memoryGit: deps.memoryGit,
@@ -5760,7 +5804,7 @@ function register13(program, deps) {
5760
5804
  const failed = result.failed + scan.invalid.length;
5761
5805
  const results = [...result.results, ...scan.invalid].sort((a, b) => a.file.localeCompare(b.file));
5762
5806
  if (deps.output.mode !== "json") {
5763
- for (const item of results) process.stdout.write((lines.get(item.file) ?? importResultLine(scope, item)) + "\n");
5807
+ for (const item of results) process.stdout.write((lines.get(item.file) ?? importResultLine(scope, item) + memoryProjectSuffix(ctx)) + "\n");
5764
5808
  }
5765
5809
  const skippedNames = results.filter((r) => r.status === "skipped").map((r) => `${scope}/${String(r.name)}`);
5766
5810
  if (deps.output.mode !== "json" && skippedNames.length) process.stdout.write(`skipped (\u540C\u540D\u3042\u308A\u3002\u7D71\u5408\u3059\u308B\u306A\u3089 nolto memory show <name> --fresh): ${skippedNames.join(", ")}
@@ -5778,7 +5822,7 @@ function stripCommanderErrorPrefix(msg) {
5778
5822
  function buildProgram(deps) {
5779
5823
  const writeErr = (_msg) => {
5780
5824
  };
5781
- const program = new Command("nolto").version(deps.version, "-V, --version", "Print version number").exitOverride().configureOutput({ writeErr }).description("Nolto CLI \u2014 sync repository roadmaps with Nolto.").option("--token <value>", "API token (overrides env/file)").option("--base-url <url>", "Nolto base URL (default: https://nolto.app)").option("--project <projectId>", "Default project ID").option("--json", "Output as JSON");
5825
+ const program = new Command("nolto").version(deps.version, "-V, --version", "Print version number").exitOverride().configureOutput({ writeErr }).description("Nolto CLI \u2014 sync repository roadmaps with Nolto.").option("--token <value>", "API token (overrides env/file)").option("--base-url <url>", "Nolto base URL (default: https://nolto.app)").option("--project <projectId>", "Project ID (overrides env/repo)").option("--json", "Output as JSON");
5782
5826
  register13(program, deps);
5783
5827
  register4(program, deps);
5784
5828
  register5(program, deps);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nolto/cli",
3
- "version": "0.22.1",
3
+ "version": "0.23.0",
4
4
  "description": "CLI for syncing repository roadmaps with Nolto.",
5
5
  "license": "MIT",
6
6
  "type": "module",