@nolto/cli 0.19.1 → 0.19.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  // src/memory-hooks.ts
4
4
  import { mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
5
- import { existsSync as existsSync2 } from "fs";
5
+ import { existsSync as existsSync2, statSync } from "fs";
6
6
  import path2 from "path";
7
7
 
8
8
  // src/errors.ts
@@ -274,10 +274,17 @@ function hookAgentFromArgv(argv) {
274
274
  if (arg.includes("=")) return arg.slice(arg.indexOf("=") + 1);
275
275
  return argv[hook + 1]?.startsWith("-") === false ? argv[hook + 1] : true;
276
276
  }
277
+ function isDirectory(file) {
278
+ try {
279
+ return statSync(file).isDirectory();
280
+ } catch {
281
+ return false;
282
+ }
283
+ }
277
284
  async function installMemorySkill(root) {
278
285
  const sourceDir = resolveSkillSourceDir("project-memory");
279
286
  const parents = [".claude"];
280
- if ([".agents", ".codex", "AGENTS.md"].some((name) => existsSync2(path2.join(root, name)))) parents.push(".agents");
287
+ if ([".agents", "AGENTS.md"].some((name) => existsSync2(path2.join(root, name))) || isDirectory(path2.join(root, ".codex"))) parents.push(".agents");
281
288
  const results = [];
282
289
  for (const parent of parents) {
283
290
  results.push(await installSkill({ name: "project-memory", skillsParentDir: path2.join(root, parent, "skills"), sourceDir }));
@@ -288,7 +295,7 @@ function object(value) {
288
295
  return value !== null && typeof value === "object" && !Array.isArray(value);
289
296
  }
290
297
  function detectMemoryAgents(root) {
291
- const selected = ["claude", "codex", "gemini"].filter((a) => existsSync2(path2.join(root, `.${a}`)));
298
+ const selected = ["claude", "codex", "gemini"].filter((a) => isDirectory(path2.join(root, `.${a}`)));
292
299
  return selected.length ? selected : ["claude"];
293
300
  }
294
301
  function hookCommand(agent) {
@@ -328,12 +335,16 @@ async function installMemoryHooks(root, agent, writeAgentsMd = false) {
328
335
  if (agent && agent !== "all" && !agents.includes(agent)) throw new CliError("--agent \u306F claude|codex|gemini|all", 2);
329
336
  const selected = agent && agent !== "all" ? [agent] : detectMemoryAgents(root);
330
337
  const messages = [];
338
+ if (!agent || agent === "all") {
339
+ for (const a of agents) if (existsSync2(path2.join(root, `.${a}`)) && !isDirectory(path2.join(root, `.${a}`))) messages.push(`hook ${a}: .${a} \u304C\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u3067\u306F\u306A\u3044\u305F\u3081\u7701\u7565`);
340
+ }
331
341
  for (const a of selected) {
332
342
  const file = path2.join(root, `.${a}`, a === "codex" ? "hooks.json" : "settings.json");
333
343
  let settings = {};
334
344
  try {
335
345
  settings = JSON.parse(await readFile2(file, "utf8"));
336
346
  } catch (error) {
347
+ if (error.code === "ENOTDIR") throw new CliError(`${path2.dirname(file)} \u304C\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u3067\u306F\u306A\u3044\u305F\u3081 hook \u3092\u8A2D\u5B9A\u3067\u304D\u307E\u305B\u3093\u3002`, 2);
337
348
  if (error.code !== "ENOENT") throw new CliError(`${file} \u3092\u8AAD\u3081\u307E\u305B\u3093\u3002`, 2);
338
349
  }
339
350
  if (!object(settings) || settings.hooks !== void 0 && !object(settings.hooks)) throw new CliError(`${file}: hooks \u306E\u5F62\u304C\u4E0D\u6B63\u3067\u3059\u3002`, 2);
@@ -382,7 +393,7 @@ import { CommanderError } from "commander";
382
393
 
383
394
  // src/config.ts
384
395
  import { readFile as readFile3, writeFile as writeFile3, mkdir as mkdir3, stat } from "fs/promises";
385
- import { statSync } from "fs";
396
+ import { statSync as statSync2 } from "fs";
386
397
  import os from "os";
387
398
  import path3 from "path";
388
399
  import { z } from "zod";
@@ -435,7 +446,7 @@ function findNoltoJsonSync(startDir) {
435
446
  while (true) {
436
447
  const candidate = path3.join(current, "nolto.json");
437
448
  try {
438
- statSync(candidate);
449
+ statSync2(candidate);
439
450
  return candidate;
440
451
  } catch {
441
452
  }
@@ -1077,6 +1088,13 @@ function formatIssueList(rows, meta) {
1077
1088
  const lines = values.map((row) => row.map((value, index) => index < 4 ? value.padEnd(widths[index]) : value).join(" "));
1078
1089
  return [...lines, `${rows.length} / ${meta.total} (page ${meta.page})`].join("\n");
1079
1090
  }
1091
+ function formatDraftList(list) {
1092
+ if (list.drafts.length === 0) return "No drafts.";
1093
+ return [
1094
+ ...list.drafts.map((draft) => [draft.id, singleLine(draft.subject) || "(no subject)", draft.source, draft.updatedAt].join(" ")),
1095
+ `${list.count}/${list.limit} drafts`
1096
+ ].join("\n");
1097
+ }
1080
1098
  function formatIssueView(bundle) {
1081
1099
  const issue = bundle.issue;
1082
1100
  const attributes = formatRecord({
@@ -1111,6 +1129,9 @@ function addIssueToRoadmapTask(roadmapJson, taskId, key, now) {
1111
1129
  function issueUrl(baseUrl, projectId, number) {
1112
1130
  return `${baseUrl.replace(/\/+$/, "")}/projects/${encodeURIComponent(projectId)}/issues/${number}`;
1113
1131
  }
1132
+ function draftUrl(baseUrl, projectId, id) {
1133
+ return `${baseUrl.replace(/\/+$/, "")}/projects/${encodeURIComponent(projectId)}/issues/drafts/${id}`;
1134
+ }
1114
1135
 
1115
1136
  // src/commands/issue.ts
1116
1137
  var emptySettings = { types: [], statuses: [], categories: [] };
@@ -1220,7 +1241,7 @@ function writeOptions(command, create) {
1220
1241
  if (create) command.requiredOption("--subject <text>", "Issue subject");
1221
1242
  else command.option("--subject <text>", "Issue subject");
1222
1243
  command.option("--body <text>", "Issue body").option("--body-file <path>", "Read body from file (- for stdin)").option("--type <name-or-id>", "Issue type").option("--status <name-or-id>", "Issue status").option("--priority <priority>", "high, normal or low").option("--assignee <assignee>", "me, none or UUID").option("--due <YYYY-MM-DD>", "Due date").option("--category <names...>", "Category names or UUIDs").option("--parent <ref>", "Parent issue key or number");
1223
- if (create) command.option("--phase <task-id>", "Attach the created key to a local roadmap task").option("--roadmap <slug>", "Roadmap filename slug (with --phase)");
1244
+ if (create) command.option("--draft", "Create a draft visible only to you instead of an issue").option("--phase <task-id>", "Attach the created key to a local roadmap task").option("--roadmap <slug>", "Roadmap filename slug (with --phase)");
1224
1245
  else command.option("--no-due", "Clear due date").option("--no-parent", "Clear parent").option("-m, --comment <text>", "Comment in the same update");
1225
1246
  return command;
1226
1247
  }
@@ -1229,6 +1250,10 @@ function register(program, deps) {
1229
1250
  All commands accept global \`--project <id>\`, \`--json\`, \`--token <value>\` and \`--base-url <url>\`.
1230
1251
  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.
1231
1252
 
1253
+ nolto issue create --draft --subject "\u2026"
1254
+ nolto issue drafts
1255
+ nolto issue publish <draft-id>
1256
+
1232
1257
  | Exit | Meaning |
1233
1258
  |---|---|
1234
1259
  | 0 | Success |
@@ -1251,12 +1276,31 @@ Project priority: flag \u2192 NOLTO_PROJECT \u2192 nearest ancestor nolto.json \
1251
1276
  });
1252
1277
  writeOptions(group.command("create").description("Create an issue."), true).action(async (flags, command) => {
1253
1278
  const ctx = context(deps, command);
1279
+ 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);
1254
1280
  if (flags.roadmap !== void 0 && flags.phase === void 0) throw new CliError("--roadmap requires --phase.", 2);
1255
1281
  const { input, fromTemplate } = await writeInput(deps, ctx.root, flags, true);
1282
+ if (flags.draft) {
1283
+ const result2 = await deps.http.post(`${ctx.root}/issue-drafts`, input);
1284
+ printResult(ctx.mode === "json" ? result2 : `draft ${result2.draft.id} created
1285
+ ${draftUrl(deps.settings.baseUrl, ctx.projectId, result2.draft.id)}`, ctx.mode);
1286
+ return;
1287
+ }
1256
1288
  const result = await deps.http.post(`${ctx.root}/issues`, input);
1257
1289
  const roadmap = flags.phase === void 0 ? void 0 : await attachRoadmap(deps, flags.phase, flags.roadmap, result.issue.key);
1258
1290
  printResult(ctx.mode === "json" ? { ...result, ...roadmap ? { roadmap } : {} } : `${result.issue.key} created
1259
1291
  ${issueUrl(deps.settings.baseUrl, ctx.projectId, result.issue.number)}${fromTemplate ? "\nbody: from template" : ""}`, ctx.mode);
1292
+ });
1293
+ group.command("drafts").description("List your issue drafts (visible only to you).").action(async (_flags, command) => {
1294
+ const ctx = context(deps, command);
1295
+ const result = await deps.http.get(`${ctx.root}/issue-drafts`);
1296
+ printResult(ctx.mode === "json" ? result : formatDraftList(result), ctx.mode);
1297
+ });
1298
+ group.command("publish <draft-id>").description("Publish a draft as an issue.").action(async (id, _flags, command) => {
1299
+ const ctx = context(deps, command);
1300
+ if (!isUuid(id)) throw new CliError("<draft-id> must be a UUID. Run `nolto issue drafts` to list drafts.", 2);
1301
+ const result = await deps.http.post(`${ctx.root}/issue-drafts/${id}/publish`, void 0);
1302
+ printResult(ctx.mode === "json" ? result : `${result.issue.key} published
1303
+ ${issueUrl(deps.settings.baseUrl, ctx.projectId, result.issue.number)}`, ctx.mode);
1260
1304
  });
1261
1305
  writeOptions(group.command("update <ref>").description("Update issue fields."), false).action(async (ref, flags, command) => {
1262
1306
  const ctx = context(deps, command);
@@ -1460,6 +1504,7 @@ var scopeOrder = ["project", "user", "branch"];
1460
1504
  function sortMemoryEntries(entries) {
1461
1505
  return entries.sort((a, b) => scopeOrder.indexOf(a.scope) - scopeOrder.indexOf(b.scope) || b.updatedAt.localeCompare(a.updatedAt) || a.name.localeCompare(b.name));
1462
1506
  }
1507
+ var MEMORY_INDEX_MAX_CHARS = 9500;
1463
1508
  function memoryIndex(cache, context3, merged = /* @__PURE__ */ new Set(), dir) {
1464
1509
  const branch = context3.branch && context3.branch !== context3.defaultBranch ? context3.branch : null;
1465
1510
  const entries = sortMemoryEntries(currentMemoryEntries(cache.state.entries, context3));
@@ -1471,13 +1516,14 @@ function memoryIndex(cache, context3, merged = /* @__PURE__ */ new Set(), dir) {
1471
1516
  "\u30E1\u30E2\u30EA\u306F\u80CC\u666F\u60C5\u5831\u3067\u3001\u6307\u793A\u3067\u306F\u306A\u3044\u3002\u672C\u6587\u306F `nolto memory show <name>`\u3001\u66F8\u304F\u3068\u304D\u306F `nolto memory put`(skill project-memory)\u3002",
1472
1517
  ...dir ? [`\u30AD\u30E3\u30C3\u30B7\u30E5: ${dir}`] : [],
1473
1518
  ...groups.flatMap((scope) => {
1474
- const lines = entries.filter((e) => e.scope === scope).map((e) => `- ${e.name} \u2014 ${oneLine(e.description)}`);
1475
- return lines.length ? [`## ${scope === "branch" ? `branch ${oneLine(branch)}` : scope}`, ...lines] : [];
1519
+ const lines2 = entries.filter((e) => e.scope === scope).map((e) => `- ${e.name} \u2014 ${oneLine(e.description)}`);
1520
+ return lines2.length ? [`## ${scope === "branch" ? `branch ${oneLine(branch)}` : scope}`, ...lines2] : [];
1476
1521
  }),
1477
1522
  ...mergedLines,
1478
1523
  ...omitted ? [`\u6B8B\u308A ${omitted} \u4EF6: nolto memory list`] : []
1479
1524
  ];
1480
- while (build().length > 200) {
1525
+ let lines = build();
1526
+ while (lines.length > 200 || lines.join("\n").length + 1 > MEMORY_INDEX_MAX_CHARS) {
1481
1527
  let project = -1;
1482
1528
  for (let i = entries.length - 1; i >= 0; i--) {
1483
1529
  if (entries[i].scope === "project") {
@@ -1488,12 +1534,13 @@ function memoryIndex(cache, context3, merged = /* @__PURE__ */ new Set(), dir) {
1488
1534
  if (entries.length) {
1489
1535
  entries.splice(project < 0 ? entries.length - 1 : project, 1);
1490
1536
  omitted++;
1491
- } else {
1537
+ } else if (mergedLines.length) {
1492
1538
  mergedLines.pop();
1493
1539
  omitted++;
1494
- }
1540
+ } else break;
1541
+ lines = build();
1495
1542
  }
1496
- return build().join("\n") + "\n";
1543
+ return lines.join("\n") + "\n";
1497
1544
  }
1498
1545
 
1499
1546
  // src/memory-git.ts
@@ -1662,9 +1709,12 @@ async function mergedMemoryBranches(branches, context3, root, git, mine = /* @__
1662
1709
  }
1663
1710
 
1664
1711
  // src/memory-import.ts
1665
- function aiHeading(response) {
1712
+ function aiHeading(response, requestedName) {
1666
1713
  const { entry, ai } = response;
1667
1714
  if (!ai || ai.action !== "merge" && ai.action !== "replace") return null;
1715
+ if (requestedName !== void 0 && requestedName !== entry.name) {
1716
+ return `\u65B0\u898F\u306E ${requestedName} \u306F\u4F5C\u3089\u305A\u3001AI \u304C ${entry.scope}/${entry.name} ${ai.action === "merge" ? "\u306B\u7D71\u5408\u3057\u307E\u3057\u305F" : "\u306E\u77DB\u76FE\u3092\u89E3\u6D88\u3057\u307E\u3057\u305F"} (r${entry.revision}) \u2014 ${oneLine(ai.reason ?? "")}`;
1717
+ }
1668
1718
  return `AI \u304C\u6574\u7406: ${entry.scope}/${entry.name} ${ai.action === "merge" ? "\u306B\u7D71\u5408" : "\u306E\u77DB\u76FE\u3092\u89E3\u6D88"} (r${entry.revision}) \u2014 ${oneLine(ai.reason ?? "")}`;
1669
1719
  }
1670
1720
  async function createMemoryContext(opts, recover = false) {
@@ -2166,7 +2216,7 @@ async function ensureProjectRepo(args) {
2166
2216
  import readline from "readline/promises";
2167
2217
  import os2 from "os";
2168
2218
  import path14 from "path";
2169
- import { statSync as statSync2 } from "fs";
2219
+ import { statSync as statSync3 } from "fs";
2170
2220
 
2171
2221
  // src/registry.ts
2172
2222
  import { readFile as readFile10, writeFile as writeFile8, mkdir as mkdir7, rename as rename4, unlink as unlink3 } from "fs/promises";
@@ -2249,7 +2299,7 @@ function resolveStartDir(env, cwd) {
2249
2299
  }
2250
2300
  function dirHasGit(dir) {
2251
2301
  try {
2252
- statSync2(path14.join(dir, ".git"));
2302
+ statSync3(path14.join(dir, ".git"));
2253
2303
  return true;
2254
2304
  } catch {
2255
2305
  return false;
@@ -5069,13 +5119,15 @@ async function apiCall(deps, ctx, call, op = "read", name = "<name>") {
5069
5119
  throw new CliError(error.message, error.exitCode, hint, error.status, code, body, detail);
5070
5120
  }
5071
5121
  }
5072
- function printWrite(deps, ctx, action, response, isNew = false) {
5122
+ function printWrite(deps, ctx, action, response, isNew = false, put) {
5073
5123
  if (deps.output.mode === "json") {
5074
5124
  printResult(response, "json");
5075
5125
  return;
5076
5126
  }
5077
5127
  const { entry } = response;
5078
- const lines = [aiHeading(response) ?? `${action} ${entry.scope}/${entry.name} r${entry.revision}${isNew ? " (\u65B0\u898F)" : ""}`];
5128
+ const heading = aiHeading(response, put?.name);
5129
+ const lines = [heading ?? `${action} ${entry.scope}/${entry.name} r${entry.revision}${isNew ? " (\u65B0\u898F)" : ""}`];
5130
+ 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)}`);
5079
5131
  if (response.aiSkipped) lines.push(aiSkippedLine(response.aiSkipped));
5080
5132
  const affected = response.affected ?? [];
5081
5133
  for (const a of affected) lines.push(`- ${a.scope}/${a.name} r${a.fromRevision} \u2192 ${a.deleted ? `\u524A\u9664 (r${a.toRevision})` : `r${a.toRevision}`}`);
@@ -5194,7 +5246,7 @@ function register13(program, deps) {
5194
5246
  ...scope === "branch" ? { repoIdentity: ctx.git.repoIdentity, branch: ctx.git.branch } : {}
5195
5247
  }, headers()), "put", draft.name);
5196
5248
  await updateCache(ctx, deps, writtenEntries(ctx, response));
5197
- printWrite(deps, ctx, "put", response, draft.revision === void 0);
5249
+ printWrite(deps, ctx, "put", response, draft.revision === void 0, { name: draft.name, file, allowNew: opts.new });
5198
5250
  });
5199
5251
  memory.command("rm <name>").option("--scope <scope>").option("--branch <branch>", "branch entry of the current repo").action(async (name, opts) => {
5200
5252
  const ctx = await context2(deps);
@@ -58,10 +58,10 @@ Use this reference when creating or structurally editing the cache JSON returned
58
58
  - `summary`: One or two current sentences; do not use as a changelog.
59
59
  - `phases`: Ordered delivery phases.
60
60
  - `phase.status`: `todo`, `in-progress`, `done`, or `blocked`.
61
- - `phase.plan`: Optional repository-relative path (`/`-separated) to a Markdown plan document, for example `docs/plans/auth.md`. Absolute paths, backslashes, and `.`/`..` segments are rejected.
61
+ - `phase.plan`: Optional repository-relative path (`/`-separated) to a Markdown plan document, for example `docs/plans/auth.md`. Absolute paths, backslashes, and `.`/`..` segments are rejected. Attach a shared plan spanning multiple tasks once here, rather than repeating its path on tasks.
62
62
  - `tasks`: Ordered work items. Each must be small enough to verify clearly.
63
63
  - `task.status`: `todo`, `in-progress`, `done`, or `blocked`.
64
- - `task.plan`: Optional repository-relative path (`/`-separated) to a Markdown plan document, for example `docs/plans/auth.md`. Absolute paths, backslashes, and `.`/`..` segments are rejected.
64
+ - `task.plan`: Optional repository-relative path (`/`-separated) to a Markdown plan document, for example `docs/plans/auth.md`. Absolute paths, backslashes, and `.`/`..` segments are rejected. Attach only a task-specific implementation plan; do not repeat the phase plan path. When omitted, the UI shows the phase plan.
65
65
  - `startedAt`: Set by the server for `in-progress` tasks; do not edit manually. Uses the same RFC 3339 date-time format as `updatedAt`.
66
66
  - `completedAt`: Set by the server for `done` tasks; do not edit manually. Uses the same RFC 3339 date-time format as `updatedAt`.
67
67
  - `note`: Current implementation detail or blocker. Omit when it adds no value.
@@ -17,7 +17,7 @@ Use `nolto roadmap --help` and `nolto roadmap <cmd> --help` for commands and opt
17
17
  - Block: run `nolto roadmap block <task-id> [--slug slug] --note text`; describe the blocker and what will unblock it.
18
18
  - Replan: read `nolto roadmap schema` before structural changes. Edit the JSON from `path`, preserve IDs, then run `nolto roadmap validate [slug]` and `nolto roadmap sync [slug]`.
19
19
  On 409, save unsynced edits, `nolto roadmap pull [slug]`, review and reapply changes. Use `--force` only after saving needed edits.
20
- - Plan / summary: use `nolto roadmap plan <task-id> [--slug slug] --path <repo-relative-md>` and `nolto roadmap summary [slug] --text text`; do not edit state, notes, plan links, or summary directly.
20
+ - Plan / summary: use `nolto roadmap plan <task-id> [--slug slug] --path <repo-relative-md>` and `nolto roadmap summary [slug] --text text`; do not edit state, notes, plan links, or summary directly. Attach shared plans once to the phase; task plans are for task-specific implementation plans and must not repeat the phase path. Tasks without a plan show the phase plan in the UI.
21
21
 
22
22
  ## Issues
23
23
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nolto/cli",
3
- "version": "0.19.1",
3
+ "version": "0.19.3",
4
4
  "description": "CLI for syncing repository roadmaps with Nolto.",
5
5
  "license": "MIT",
6
6
  "type": "module",