@nolto/cli 0.19.2 → 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.
Files changed (2) hide show
  1. package/dist/index.js +27 -13
  2. package/package.json +1 -1
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
  }
@@ -1493,6 +1504,7 @@ var scopeOrder = ["project", "user", "branch"];
1493
1504
  function sortMemoryEntries(entries) {
1494
1505
  return entries.sort((a, b) => scopeOrder.indexOf(a.scope) - scopeOrder.indexOf(b.scope) || b.updatedAt.localeCompare(a.updatedAt) || a.name.localeCompare(b.name));
1495
1506
  }
1507
+ var MEMORY_INDEX_MAX_CHARS = 9500;
1496
1508
  function memoryIndex(cache, context3, merged = /* @__PURE__ */ new Set(), dir) {
1497
1509
  const branch = context3.branch && context3.branch !== context3.defaultBranch ? context3.branch : null;
1498
1510
  const entries = sortMemoryEntries(currentMemoryEntries(cache.state.entries, context3));
@@ -1504,13 +1516,14 @@ function memoryIndex(cache, context3, merged = /* @__PURE__ */ new Set(), dir) {
1504
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",
1505
1517
  ...dir ? [`\u30AD\u30E3\u30C3\u30B7\u30E5: ${dir}`] : [],
1506
1518
  ...groups.flatMap((scope) => {
1507
- const lines = entries.filter((e) => e.scope === scope).map((e) => `- ${e.name} \u2014 ${oneLine(e.description)}`);
1508
- 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] : [];
1509
1521
  }),
1510
1522
  ...mergedLines,
1511
1523
  ...omitted ? [`\u6B8B\u308A ${omitted} \u4EF6: nolto memory list`] : []
1512
1524
  ];
1513
- while (build().length > 200) {
1525
+ let lines = build();
1526
+ while (lines.length > 200 || lines.join("\n").length + 1 > MEMORY_INDEX_MAX_CHARS) {
1514
1527
  let project = -1;
1515
1528
  for (let i = entries.length - 1; i >= 0; i--) {
1516
1529
  if (entries[i].scope === "project") {
@@ -1521,12 +1534,13 @@ function memoryIndex(cache, context3, merged = /* @__PURE__ */ new Set(), dir) {
1521
1534
  if (entries.length) {
1522
1535
  entries.splice(project < 0 ? entries.length - 1 : project, 1);
1523
1536
  omitted++;
1524
- } else {
1537
+ } else if (mergedLines.length) {
1525
1538
  mergedLines.pop();
1526
1539
  omitted++;
1527
- }
1540
+ } else break;
1541
+ lines = build();
1528
1542
  }
1529
- return build().join("\n") + "\n";
1543
+ return lines.join("\n") + "\n";
1530
1544
  }
1531
1545
 
1532
1546
  // src/memory-git.ts
@@ -2202,7 +2216,7 @@ async function ensureProjectRepo(args) {
2202
2216
  import readline from "readline/promises";
2203
2217
  import os2 from "os";
2204
2218
  import path14 from "path";
2205
- import { statSync as statSync2 } from "fs";
2219
+ import { statSync as statSync3 } from "fs";
2206
2220
 
2207
2221
  // src/registry.ts
2208
2222
  import { readFile as readFile10, writeFile as writeFile8, mkdir as mkdir7, rename as rename4, unlink as unlink3 } from "fs/promises";
@@ -2285,7 +2299,7 @@ function resolveStartDir(env, cwd) {
2285
2299
  }
2286
2300
  function dirHasGit(dir) {
2287
2301
  try {
2288
- statSync2(path14.join(dir, ".git"));
2302
+ statSync3(path14.join(dir, ".git"));
2289
2303
  return true;
2290
2304
  } catch {
2291
2305
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nolto/cli",
3
- "version": "0.19.2",
3
+ "version": "0.19.3",
4
4
  "description": "CLI for syncing repository roadmaps with Nolto.",
5
5
  "license": "MIT",
6
6
  "type": "module",