@nolto/cli 0.17.0 → 0.19.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.
- package/README.md +9 -3
- package/dist/index.js +1397 -455
- package/dist/skill/project-memory/SKILL.md +57 -0
- package/dist/skill/roadmap-progress/SKILL.md +16 -72
- package/dist/skill/roadmap-progress/agents/openai.yaml +1 -1
- package/dist/skill/roadmap-progress/scripts/roadmap.mjs +1 -32
- package/package.json +1 -1
- package/dist/skill/roadmap-progress/references/issue-cli.md +0 -46
- /package/dist/{skill/roadmap-progress/references/schema.md → roadmap-schema-reference.md} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,27 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
// src/
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import { CommanderError } from "commander";
|
|
8
|
-
|
|
9
|
-
// src/config.ts
|
|
10
|
-
import { readFile, writeFile, mkdir, stat } from "fs/promises";
|
|
11
|
-
import { statSync } from "fs";
|
|
12
|
-
import os from "os";
|
|
13
|
-
import path from "path";
|
|
14
|
-
import { z } from "zod";
|
|
3
|
+
// src/memory-hooks.ts
|
|
4
|
+
import { mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
|
|
5
|
+
import { existsSync as existsSync2 } from "fs";
|
|
6
|
+
import path2 from "path";
|
|
15
7
|
|
|
16
8
|
// src/errors.ts
|
|
17
9
|
var CliError = class extends Error {
|
|
18
|
-
constructor(message, exitCode, hint, status, serverError, body) {
|
|
10
|
+
constructor(message, exitCode, hint, status, serverError, body, detail) {
|
|
19
11
|
super(message);
|
|
20
12
|
this.exitCode = exitCode;
|
|
21
13
|
this.hint = hint;
|
|
22
14
|
this.status = status;
|
|
23
15
|
this.serverError = serverError;
|
|
24
16
|
this.body = body;
|
|
17
|
+
this.detail = detail;
|
|
25
18
|
this.name = "CliError";
|
|
26
19
|
}
|
|
27
20
|
exitCode;
|
|
@@ -29,8 +22,12 @@ var CliError = class extends Error {
|
|
|
29
22
|
status;
|
|
30
23
|
serverError;
|
|
31
24
|
body;
|
|
25
|
+
detail;
|
|
32
26
|
};
|
|
33
27
|
function mapHttpStatusToCliError(status, opts = {}) {
|
|
28
|
+
if (opts.serverError?.startsWith("memory_") || status === 400 && opts.serverError === "invalid_input") {
|
|
29
|
+
return new CliError(opts.serverMessage ?? opts.serverError, 2, void 0, status, opts.serverError, opts.body);
|
|
30
|
+
}
|
|
34
31
|
if (status === 401) {
|
|
35
32
|
const detail = opts.wwwAuthenticate ? ` (${opts.wwwAuthenticate})` : "";
|
|
36
33
|
return new CliError(
|
|
@@ -148,22 +145,248 @@ function mapHttpStatusToCliError(status, opts = {}) {
|
|
|
148
145
|
const reason = opts.serverMessage ?? opts.serverError;
|
|
149
146
|
return new CliError(reason ? `Server returned HTTP ${status}: ${reason}` : `Server returned HTTP ${status}`, 5, void 0, status, opts.serverError, opts.body);
|
|
150
147
|
}
|
|
148
|
+
var NETWORK_ERROR_CODES = [
|
|
149
|
+
"ECONNREFUSED",
|
|
150
|
+
"ENOTFOUND",
|
|
151
|
+
"EAI_AGAIN",
|
|
152
|
+
"ETIMEDOUT",
|
|
153
|
+
"ECONNRESET",
|
|
154
|
+
"ENETUNREACH",
|
|
155
|
+
"EHOSTUNREACH",
|
|
156
|
+
"EPERM",
|
|
157
|
+
"EACCES",
|
|
158
|
+
"UND_ERR_CONNECT_TIMEOUT"
|
|
159
|
+
];
|
|
151
160
|
function isNetworkError(err) {
|
|
152
161
|
if (!(err instanceof Error)) {
|
|
153
162
|
return false;
|
|
154
163
|
}
|
|
155
|
-
const
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
164
|
+
const codes = /* @__PURE__ */ new Set();
|
|
165
|
+
const collect = (value, depth) => {
|
|
166
|
+
if (value == null || typeof value !== "object" || depth > 3) return;
|
|
167
|
+
const record = value;
|
|
168
|
+
if (typeof record.code === "string") codes.add(record.code);
|
|
169
|
+
collect(record.cause, depth + 1);
|
|
170
|
+
if (Array.isArray(record.errors)) for (const inner of record.errors) collect(inner, depth + 1);
|
|
171
|
+
};
|
|
172
|
+
collect(err, 0);
|
|
173
|
+
return [...codes].some((code) => NETWORK_ERROR_CODES.includes(code));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// src/skill-install.ts
|
|
177
|
+
import { cp, mkdir, readFile, writeFile, rm, readdir } from "fs/promises";
|
|
178
|
+
import { createHash } from "crypto";
|
|
179
|
+
import { existsSync } from "fs";
|
|
180
|
+
import path from "path";
|
|
181
|
+
import { fileURLToPath } from "url";
|
|
182
|
+
var __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
183
|
+
function resolveSkillSourceDir(name = "roadmap-progress") {
|
|
184
|
+
const candidates = [
|
|
185
|
+
path.resolve(__dirname, `skill/${name}`),
|
|
186
|
+
// bundled: dist/skill/...
|
|
187
|
+
path.resolve(__dirname, `../../../skills/${name}`)
|
|
188
|
+
// source: <repo>/skills/...
|
|
189
|
+
];
|
|
190
|
+
for (const candidate of candidates) {
|
|
191
|
+
if (existsSync(path.join(candidate, "SKILL.md"))) return candidate;
|
|
160
192
|
}
|
|
161
|
-
|
|
162
|
-
|
|
193
|
+
throw new Error(`Bundled ${name} skill not found. Reinstall @nolto/cli.`);
|
|
194
|
+
}
|
|
195
|
+
var VERSION_MARKER = ".nolto-skill-version";
|
|
196
|
+
async function skillContentHash(dir) {
|
|
197
|
+
const files = [];
|
|
198
|
+
async function walk(relative) {
|
|
199
|
+
for (const entry of await readdir(path.join(dir, relative), { withFileTypes: true })) {
|
|
200
|
+
if (entry.name === VERSION_MARKER) continue;
|
|
201
|
+
const file = relative ? `${relative}/${entry.name}` : entry.name;
|
|
202
|
+
if (entry.isDirectory()) await walk(file);
|
|
203
|
+
else if (entry.isFile()) files.push(file);
|
|
204
|
+
}
|
|
163
205
|
}
|
|
164
|
-
|
|
206
|
+
await walk("");
|
|
207
|
+
const hash = createHash("sha256");
|
|
208
|
+
for (const file of files.sort()) {
|
|
209
|
+
hash.update(file).update("\0").update(await readFile(path.join(dir, file))).update("\0");
|
|
210
|
+
}
|
|
211
|
+
return `sha256:${hash.digest("hex").slice(0, 12)}`;
|
|
212
|
+
}
|
|
213
|
+
async function checkSkillDrift(repoRoot, opts = {}) {
|
|
214
|
+
const warnings = [];
|
|
215
|
+
for (const name of ["roadmap-progress", "project-memory"]) {
|
|
216
|
+
const sourceHash = await skillContentHash(resolveSkillSourceDir(name));
|
|
217
|
+
const drifted = [];
|
|
218
|
+
for (const parent of [".claude", ".agents"]) {
|
|
219
|
+
const dir = path.join(repoRoot, parent, "skills", name);
|
|
220
|
+
if (!existsSync(dir)) continue;
|
|
221
|
+
let installed = null;
|
|
222
|
+
try {
|
|
223
|
+
installed = (await readFile(path.join(dir, VERSION_MARKER), "utf8")).trim();
|
|
224
|
+
} catch {
|
|
225
|
+
}
|
|
226
|
+
if (installed !== sourceHash) drifted.push(path.relative(repoRoot, dir).split(path.sep).join("/"));
|
|
227
|
+
}
|
|
228
|
+
if (drifted.length) warnings.push(`${name} skill differs from the version bundled with this CLI in ${drifted.join(", ")}. Run \`nolto init\` in this repo to update it.`);
|
|
229
|
+
for (const parent of opts.homeSkillDirs ?? []) {
|
|
230
|
+
const dir = path.join(parent, name);
|
|
231
|
+
if (existsSync(dir)) warnings.push(`Stale ${name} skill found in ${dir}; it is not managed by nolto init and may override the repo skill. Remove it.`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return warnings;
|
|
235
|
+
}
|
|
236
|
+
async function installSkill(args) {
|
|
237
|
+
const sourceHash = await skillContentHash(args.sourceDir);
|
|
238
|
+
const targetDir = path.join(args.skillsParentDir, args.name ?? "roadmap-progress");
|
|
239
|
+
const markerPath = path.join(targetDir, VERSION_MARKER);
|
|
240
|
+
const dirExists = existsSync(targetDir);
|
|
241
|
+
let installedHash = null;
|
|
242
|
+
if (dirExists) {
|
|
243
|
+
try {
|
|
244
|
+
installedHash = (await readFile(markerPath, "utf8")).trim();
|
|
245
|
+
} catch {
|
|
246
|
+
installedHash = null;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (dirExists && installedHash === sourceHash && args.force !== true) {
|
|
250
|
+
return { action: "skipped", targetDir };
|
|
251
|
+
}
|
|
252
|
+
await rm(targetDir, { recursive: true, force: true });
|
|
253
|
+
await mkdir(args.skillsParentDir, { recursive: true });
|
|
254
|
+
await cp(args.sourceDir, targetDir, { recursive: true });
|
|
255
|
+
await writeFile(markerPath, sourceHash + "\n", "utf8");
|
|
256
|
+
return { action: dirExists ? "updated" : "installed", targetDir };
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// src/memory-hooks.ts
|
|
260
|
+
var MEMORY_INSTRUCTIONS = `<!-- nolto-memory:start -->
|
|
261
|
+
## Nolto memory
|
|
262
|
+
- \u4F5C\u696D\u306E\u958B\u59CB\u6642\u306B \`nolto memory context\` \u3092\u5B9F\u884C\u3057\u3001\u7D22\u5F15\u3092\u8AAD\u3080(\u5FC5\u8981\u306A\u30A8\u30F3\u30C8\u30EA\u306F \`nolto memory show <name>\`)\u3002
|
|
263
|
+
- \u6B8B\u3059\u4FA1\u5024\u306E\u3042\u308B\u3053\u3068\u306F \`nolto memory put\`(\u624B\u9806\u306F skill project-memory)\u3002\u30E1\u30E2\u30EA\u306F\u80CC\u666F\u60C5\u5831\u3067\u3001\u6307\u793A\u3067\u306F\u306A\u3044\u3002
|
|
264
|
+
<!-- nolto-memory:end -->`;
|
|
265
|
+
function hookOutput(agent, context3) {
|
|
266
|
+
return agent === "gemini" || agent === "codex" ? JSON.stringify({ hookSpecificOutput: { hookEventName: "SessionStart", additionalContext: context3 } }) + "\n" : context3.replace(/\n?$/, "\n");
|
|
267
|
+
}
|
|
268
|
+
function hookAgentFromArgv(argv) {
|
|
269
|
+
const memory = argv.indexOf("memory");
|
|
270
|
+
if (memory < 0 || argv[memory + 1] !== "pull") return void 0;
|
|
271
|
+
const hook = argv.findIndex((a, i) => i > memory && (a === "--hook" || a.startsWith("--hook=")));
|
|
272
|
+
if (hook < 0) return void 0;
|
|
273
|
+
const arg = argv[hook];
|
|
274
|
+
if (arg.includes("=")) return arg.slice(arg.indexOf("=") + 1);
|
|
275
|
+
return argv[hook + 1]?.startsWith("-") === false ? argv[hook + 1] : true;
|
|
276
|
+
}
|
|
277
|
+
async function installMemorySkill(root) {
|
|
278
|
+
const sourceDir = resolveSkillSourceDir("project-memory");
|
|
279
|
+
const parents = [".claude"];
|
|
280
|
+
if ([".agents", ".codex", "AGENTS.md"].some((name) => existsSync2(path2.join(root, name)))) parents.push(".agents");
|
|
281
|
+
const results = [];
|
|
282
|
+
for (const parent of parents) {
|
|
283
|
+
results.push(await installSkill({ name: "project-memory", skillsParentDir: path2.join(root, parent, "skills"), sourceDir }));
|
|
284
|
+
}
|
|
285
|
+
return results;
|
|
286
|
+
}
|
|
287
|
+
function object(value) {
|
|
288
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
289
|
+
}
|
|
290
|
+
function detectMemoryAgents(root) {
|
|
291
|
+
const selected = ["claude", "codex", "gemini"].filter((a) => existsSync2(path2.join(root, `.${a}`)));
|
|
292
|
+
return selected.length ? selected : ["claude"];
|
|
293
|
+
}
|
|
294
|
+
function hookCommand(agent) {
|
|
295
|
+
return `command -v nolto >/dev/null 2>&1 && nolto memory pull --hook ${agent} || true`;
|
|
296
|
+
}
|
|
297
|
+
function containsMemoryHook(start, agent) {
|
|
298
|
+
return start.some((group) => object(group) && Array.isArray(group.hooks) && group.hooks.some((h) => object(h) && h.command === hookCommand(agent)));
|
|
299
|
+
}
|
|
300
|
+
async function hasMemoryHook(root, agent) {
|
|
301
|
+
try {
|
|
302
|
+
const settings = JSON.parse(await readFile2(path2.join(root, `.${agent}`, agent === "codex" ? "hooks.json" : "settings.json"), "utf8"));
|
|
303
|
+
return object(settings) && object(settings.hooks) && Array.isArray(settings.hooks.SessionStart) && containsMemoryHook(settings.hooks.SessionStart, agent);
|
|
304
|
+
} catch {
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function claudeMemoryDir(root, projectsDir) {
|
|
309
|
+
return path2.join(projectsDir, path2.resolve(root).replace(/[^a-zA-Z0-9]/g, "-"), "memory");
|
|
310
|
+
}
|
|
311
|
+
async function disableClaudeAutoMemory(root) {
|
|
312
|
+
const file = path2.join(root, ".claude", "settings.local.json");
|
|
313
|
+
let settings = {};
|
|
314
|
+
try {
|
|
315
|
+
settings = JSON.parse(await readFile2(file, "utf8"));
|
|
316
|
+
} catch (error) {
|
|
317
|
+
if (error.code !== "ENOENT") return "invalid";
|
|
318
|
+
}
|
|
319
|
+
if (!object(settings)) return "invalid";
|
|
320
|
+
if (settings.autoMemoryEnabled === false) return "already";
|
|
321
|
+
settings.autoMemoryEnabled = false;
|
|
322
|
+
await mkdir2(path2.dirname(file), { recursive: true });
|
|
323
|
+
await writeFile2(file, JSON.stringify(settings, null, 2) + "\n");
|
|
324
|
+
return "written";
|
|
325
|
+
}
|
|
326
|
+
async function installMemoryHooks(root, agent, writeAgentsMd = false) {
|
|
327
|
+
const agents = ["claude", "codex", "gemini"];
|
|
328
|
+
if (agent && agent !== "all" && !agents.includes(agent)) throw new CliError("--agent \u306F claude|codex|gemini|all", 2);
|
|
329
|
+
const selected = agent && agent !== "all" ? [agent] : detectMemoryAgents(root);
|
|
330
|
+
const messages = [];
|
|
331
|
+
for (const a of selected) {
|
|
332
|
+
const file = path2.join(root, `.${a}`, a === "codex" ? "hooks.json" : "settings.json");
|
|
333
|
+
let settings = {};
|
|
334
|
+
try {
|
|
335
|
+
settings = JSON.parse(await readFile2(file, "utf8"));
|
|
336
|
+
} catch (error) {
|
|
337
|
+
if (error.code !== "ENOENT") throw new CliError(`${file} \u3092\u8AAD\u3081\u307E\u305B\u3093\u3002`, 2);
|
|
338
|
+
}
|
|
339
|
+
if (!object(settings) || settings.hooks !== void 0 && !object(settings.hooks)) throw new CliError(`${file}: hooks \u306E\u5F62\u304C\u4E0D\u6B63\u3067\u3059\u3002`, 2);
|
|
340
|
+
const hooks = settings.hooks ?? {};
|
|
341
|
+
const start = hooks.SessionStart ?? [];
|
|
342
|
+
if (!Array.isArray(start)) throw new CliError(`${file}: SessionStart \u306F\u914D\u5217\u306B\u3057\u3066\u304F\u3060\u3055\u3044\u3002`, 2);
|
|
343
|
+
const command = hookCommand(a);
|
|
344
|
+
const present = containsMemoryHook(start, a);
|
|
345
|
+
if (!present) {
|
|
346
|
+
hooks.SessionStart = [...start, { hooks: [{ type: "command", command }] }];
|
|
347
|
+
settings.hooks = hooks;
|
|
348
|
+
await mkdir2(path2.dirname(file), { recursive: true });
|
|
349
|
+
await writeFile2(file, JSON.stringify(settings, null, 2) + "\n");
|
|
350
|
+
}
|
|
351
|
+
messages.push(`hook ${a}: ${present ? "\u8A2D\u5B9A\u6E08\u307F" : "\u8FFD\u52A0"}`);
|
|
352
|
+
if (a === "codex") messages.push(
|
|
353
|
+
"Codex 0.157.0: hooks \u306F\u65E2\u5B9A\u3067\u6709\u52B9\u3002\u7121\u52B9\u306A\u3089 config.toml \u306E [features] \u306B hooks = true \u3092\u8A2D\u5B9A\u3057\u3001\u4FE1\u983C\u6E08\u307F repo \u3067 /hooks \u304B\u3089\u627F\u8A8D\u3059\u308B\u3002"
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
for (const skill of await installMemorySkill(root)) messages.push(`skill project-memory: ${skill.action} ${path2.relative(root, skill.targetDir)}`);
|
|
357
|
+
messages.push("AGENTS.md \u306B\u8DB3\u3059\u6307\u793A\u306F nolto memory instructions");
|
|
358
|
+
if (writeAgentsMd) {
|
|
359
|
+
const file = path2.join(root, "AGENTS.md");
|
|
360
|
+
try {
|
|
361
|
+
const old = await readFile2(file, "utf8");
|
|
362
|
+
const block = /<!-- nolto-memory:start -->[\s\S]*?<!-- nolto-memory:end -->/g;
|
|
363
|
+
const next = block.test(old) ? old.replace(block, () => MEMORY_INSTRUCTIONS) : `${old.replace(/\n?$/, "\n")}
|
|
364
|
+
${MEMORY_INSTRUCTIONS}
|
|
365
|
+
`;
|
|
366
|
+
if (old !== next) await writeFile2(file, next);
|
|
367
|
+
messages.push(old !== next ? "AGENTS.md \u3092\u66F4\u65B0\u3057\u305F" : "AGENTS.md \u306F\u6700\u65B0");
|
|
368
|
+
} catch (error) {
|
|
369
|
+
if (error.code !== "ENOENT") throw error;
|
|
370
|
+
messages.push("AGENTS.md \u304C\u7121\u3044\u305F\u3081\u6307\u793A\u306E\u8FFD\u52A0\u3092\u7701\u7565\u3057\u305F");
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
return messages;
|
|
165
374
|
}
|
|
166
375
|
|
|
376
|
+
// src/index.ts
|
|
377
|
+
import { createRequire as createRequire3 } from "module";
|
|
378
|
+
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
379
|
+
import path24 from "path";
|
|
380
|
+
import os5 from "os";
|
|
381
|
+
import { CommanderError } from "commander";
|
|
382
|
+
|
|
383
|
+
// src/config.ts
|
|
384
|
+
import { readFile as readFile3, writeFile as writeFile3, mkdir as mkdir3, stat } from "fs/promises";
|
|
385
|
+
import { statSync } from "fs";
|
|
386
|
+
import os from "os";
|
|
387
|
+
import path3 from "path";
|
|
388
|
+
import { z } from "zod";
|
|
389
|
+
|
|
167
390
|
// src/constants.ts
|
|
168
391
|
var DOCUMENT_MAX_BYTES = 2 * 1024 * 1024;
|
|
169
392
|
var DEFAULT_BASE_URL = "https://nolto.app";
|
|
@@ -182,7 +405,7 @@ var repoBindingSchema = z.object({
|
|
|
182
405
|
async function loadRepoBinding(filePath) {
|
|
183
406
|
let raw;
|
|
184
407
|
try {
|
|
185
|
-
raw = await
|
|
408
|
+
raw = await readFile3(filePath, "utf8");
|
|
186
409
|
} catch (err) {
|
|
187
410
|
const code = err != null && typeof err === "object" && "code" in err ? err.code : "";
|
|
188
411
|
if (code === "ENOENT") {
|
|
@@ -210,13 +433,13 @@ async function loadRepoBinding(filePath) {
|
|
|
210
433
|
function findNoltoJsonSync(startDir) {
|
|
211
434
|
let current = startDir;
|
|
212
435
|
while (true) {
|
|
213
|
-
const candidate =
|
|
436
|
+
const candidate = path3.join(current, "nolto.json");
|
|
214
437
|
try {
|
|
215
438
|
statSync(candidate);
|
|
216
439
|
return candidate;
|
|
217
440
|
} catch {
|
|
218
441
|
}
|
|
219
|
-
const parent =
|
|
442
|
+
const parent = path3.dirname(current);
|
|
220
443
|
if (parent === current) break;
|
|
221
444
|
current = parent;
|
|
222
445
|
}
|
|
@@ -230,7 +453,7 @@ function findRepoBindingFile(args) {
|
|
|
230
453
|
async function mergeJsonFile(filePath, patch) {
|
|
231
454
|
let existing = {};
|
|
232
455
|
try {
|
|
233
|
-
const raw = await
|
|
456
|
+
const raw = await readFile3(filePath, "utf8");
|
|
234
457
|
const parsed = JSON.parse(raw);
|
|
235
458
|
if (parsed == null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
236
459
|
throw new CliError(
|
|
@@ -247,20 +470,20 @@ async function mergeJsonFile(filePath, patch) {
|
|
|
247
470
|
}
|
|
248
471
|
const merged = { ...existing, ...patch };
|
|
249
472
|
const { chmod: chmod2 } = await import("fs/promises");
|
|
250
|
-
await
|
|
473
|
+
await writeFile3(filePath, JSON.stringify(merged, null, 2) + "\n", { mode: 420 });
|
|
251
474
|
await chmod2(filePath, 420);
|
|
252
475
|
}
|
|
253
476
|
async function writeRepoBinding(root, projectId) {
|
|
254
|
-
await mergeJsonFile(
|
|
477
|
+
await mergeJsonFile(path3.join(root, "nolto.json"), { projectId });
|
|
255
478
|
}
|
|
256
479
|
function getConfigDir(env) {
|
|
257
480
|
if (env["NOLTO_HOME"]) return env["NOLTO_HOME"];
|
|
258
481
|
const xdg = env["XDG_CONFIG_HOME"];
|
|
259
|
-
const base = xdg != null && xdg.length > 0 ? xdg :
|
|
260
|
-
return
|
|
482
|
+
const base = xdg != null && xdg.length > 0 ? xdg : path3.join(os.homedir(), ".config");
|
|
483
|
+
return path3.join(base, "nolto");
|
|
261
484
|
}
|
|
262
485
|
function getConfigPath(env) {
|
|
263
|
-
return
|
|
486
|
+
return path3.join(getConfigDir(env), "config.json");
|
|
264
487
|
}
|
|
265
488
|
async function loadConfigFile(filePath) {
|
|
266
489
|
try {
|
|
@@ -278,7 +501,7 @@ async function loadConfigFile(filePath) {
|
|
|
278
501
|
}
|
|
279
502
|
let raw;
|
|
280
503
|
try {
|
|
281
|
-
raw = await
|
|
504
|
+
raw = await readFile3(filePath, "utf8");
|
|
282
505
|
} catch (err) {
|
|
283
506
|
throw new CliError(`Cannot read config file: ${filePath}: ${String(err)}`, 2);
|
|
284
507
|
}
|
|
@@ -304,8 +527,8 @@ async function loadConfigFile(filePath) {
|
|
|
304
527
|
return result.data;
|
|
305
528
|
}
|
|
306
529
|
async function saveConfigFile(filePath, value) {
|
|
307
|
-
await
|
|
308
|
-
await
|
|
530
|
+
await mkdir3(path3.dirname(filePath), { recursive: true, mode: 448 });
|
|
531
|
+
await writeFile3(filePath, JSON.stringify(value, null, 2) + "\n", { mode: 384 });
|
|
309
532
|
}
|
|
310
533
|
function resolveProjectId(args) {
|
|
311
534
|
const { flagProject, envProject, repoBinding, fileProjectId } = args;
|
|
@@ -372,32 +595,42 @@ function maskToken(token) {
|
|
|
372
595
|
function createHttpClient(opts) {
|
|
373
596
|
const { baseUrl, version, token } = opts;
|
|
374
597
|
const base = baseUrl.replace(/\/+$/, "");
|
|
375
|
-
async function request(method,
|
|
376
|
-
if (!
|
|
377
|
-
throw new CliError(`HTTP client path must start with /api/, got: ${
|
|
598
|
+
async function request(method, path25, body, extraHeaders, signal) {
|
|
599
|
+
if (!path25.startsWith("/api/")) {
|
|
600
|
+
throw new CliError(`HTTP client path must start with /api/, got: ${path25}`, 2);
|
|
378
601
|
}
|
|
379
|
-
const url = `${base}${
|
|
380
|
-
const
|
|
602
|
+
const url = `${base}${path25}`;
|
|
603
|
+
const headers2 = {
|
|
604
|
+
...extraHeaders,
|
|
381
605
|
"Content-Type": "application/json",
|
|
382
606
|
"User-Agent": `${CLI_USER_AGENT_NAME}/${version}`
|
|
383
607
|
};
|
|
384
608
|
if (token) {
|
|
385
|
-
|
|
609
|
+
headers2["Authorization"] = `Bearer ${token}`;
|
|
386
610
|
}
|
|
387
611
|
let response;
|
|
388
612
|
try {
|
|
389
613
|
response = await fetch(url, {
|
|
390
614
|
method,
|
|
391
|
-
headers,
|
|
392
|
-
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
615
|
+
headers: headers2,
|
|
616
|
+
body: body === void 0 ? void 0 : JSON.stringify(body),
|
|
617
|
+
...signal ? { signal } : {}
|
|
393
618
|
});
|
|
394
619
|
} catch (err) {
|
|
395
620
|
if (isNetworkError(err)) {
|
|
396
621
|
throw new CliError(
|
|
397
622
|
`Network error contacting ${base}: ${err instanceof Error ? err.message : String(err)}`,
|
|
398
|
-
5
|
|
623
|
+
5,
|
|
624
|
+
"\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u306B\u51FA\u3089\u308C\u306A\u3044\u74B0\u5883(Codex \u306E sandbox \u306A\u3069)\u3002sandbox \u306E\u5916\u3067\u5B9F\u884C\u3059\u308B\u627F\u8A8D\u3092\u6C42\u3081\u308B",
|
|
625
|
+
void 0,
|
|
626
|
+
"network_unavailable"
|
|
399
627
|
);
|
|
400
628
|
}
|
|
629
|
+
if (err instanceof TypeError && err.message === "fetch failed") {
|
|
630
|
+
const cause = err.cause;
|
|
631
|
+
const code = typeof cause?.code === "string" ? ` (${cause.code})` : "";
|
|
632
|
+
throw new CliError(`Network error contacting ${base}: fetch failed${code}`, 5);
|
|
633
|
+
}
|
|
401
634
|
throw err;
|
|
402
635
|
}
|
|
403
636
|
if (!response.ok) {
|
|
@@ -427,11 +660,11 @@ function createHttpClient(opts) {
|
|
|
427
660
|
return response.json();
|
|
428
661
|
}
|
|
429
662
|
return {
|
|
430
|
-
get: (p) => request("GET", p),
|
|
431
|
-
post: (p, b) => request("POST", p, b),
|
|
432
|
-
patch: (p, b) => request("PATCH", p, b),
|
|
433
|
-
delete: (p) => request("DELETE", p),
|
|
434
|
-
put: (p, b) => request("PUT", p, b)
|
|
663
|
+
get: (p, signal) => request("GET", p, void 0, void 0, signal),
|
|
664
|
+
post: (p, b, h) => request("POST", p, b, h),
|
|
665
|
+
patch: (p, b, h) => request("PATCH", p, b, h),
|
|
666
|
+
delete: (p, h) => request("DELETE", p, void 0, h),
|
|
667
|
+
put: (p, b, h) => request("PUT", p, b, h)
|
|
435
668
|
};
|
|
436
669
|
}
|
|
437
670
|
|
|
@@ -439,8 +672,8 @@ function createHttpClient(opts) {
|
|
|
439
672
|
import { Command } from "commander";
|
|
440
673
|
|
|
441
674
|
// src/commands/issue.ts
|
|
442
|
-
import { readFile as
|
|
443
|
-
import
|
|
675
|
+
import { readFile as readFile4, readdir as readdir2, writeFile as writeFile4, rename, rm as rm2 } from "fs/promises";
|
|
676
|
+
import path4 from "path";
|
|
444
677
|
import { randomUUID } from "crypto";
|
|
445
678
|
|
|
446
679
|
// src/output.ts
|
|
@@ -457,6 +690,11 @@ function printError(err, mode2) {
|
|
|
457
690
|
const envelope = {
|
|
458
691
|
error: {
|
|
459
692
|
message: err.message,
|
|
693
|
+
...err.serverError ? { code: err.serverError } : {},
|
|
694
|
+
...err.body?.["entry"] ? { entry: err.body["entry"] } : {},
|
|
695
|
+
...err.body?.["candidates"] ? { candidates: err.body["candidates"] } : {},
|
|
696
|
+
...err.body?.["conflicts"] ? { conflicts: err.body["conflicts"] } : {},
|
|
697
|
+
...err.body && "aiSkipped" in err.body ? { aiSkipped: err.body["aiSkipped"] } : {},
|
|
460
698
|
exitCode: err.exitCode,
|
|
461
699
|
...err.status != null ? { status: err.status } : {},
|
|
462
700
|
...err.hint != null ? { hint: err.hint } : {}
|
|
@@ -464,8 +702,10 @@ function printError(err, mode2) {
|
|
|
464
702
|
};
|
|
465
703
|
process.stderr.write(JSON.stringify(envelope, null, 2) + "\n");
|
|
466
704
|
} else {
|
|
467
|
-
|
|
705
|
+
const code = err.serverError && !err.message.startsWith(err.serverError) ? `${err.serverError}: ` : "";
|
|
706
|
+
process.stderr.write(`Error: ${code}${err.message}
|
|
468
707
|
`);
|
|
708
|
+
if (err.detail) process.stderr.write(err.detail.replace(/\n?$/, "\n"));
|
|
469
709
|
if (err.hint != null) {
|
|
470
710
|
process.stderr.write(`Hint: ${err.hint}
|
|
471
711
|
`);
|
|
@@ -518,12 +758,12 @@ function normalizeRemote(raw) {
|
|
|
518
758
|
const firstSlash = s.indexOf("/");
|
|
519
759
|
if (firstSlash <= 0) return null;
|
|
520
760
|
let host = s.slice(0, firstSlash).toLowerCase();
|
|
521
|
-
let
|
|
761
|
+
let path25 = s.slice(firstSlash + 1);
|
|
522
762
|
if (hadScheme) host = host.replace(/:\d+$/, "");
|
|
523
|
-
|
|
524
|
-
if (
|
|
525
|
-
if (HOSTED_LOWERCASE_PATH.has(host))
|
|
526
|
-
return `${host}/${
|
|
763
|
+
path25 = path25.replace(/\/+/g, "/").replace(/^\/+/, "").replace(/\/+$/, "").replace(/\.git$/i, "").replace(/\/+$/, "");
|
|
764
|
+
if (path25.length === 0) return null;
|
|
765
|
+
if (HOSTED_LOWERCASE_PATH.has(host)) path25 = path25.toLowerCase();
|
|
766
|
+
return `${host}/${path25}`;
|
|
527
767
|
}
|
|
528
768
|
function repoIdentityToString(id) {
|
|
529
769
|
return `${id.kind}:${id.value}`;
|
|
@@ -889,7 +1129,7 @@ async function bodyText(body, file) {
|
|
|
889
1129
|
if (body !== void 0 && file !== void 0) throw new CliError("Use either --body/-m or --body-file, not both.", 2);
|
|
890
1130
|
if (file === void 0) return body;
|
|
891
1131
|
try {
|
|
892
|
-
if (file !== "-") return await
|
|
1132
|
+
if (file !== "-") return await readFile4(file, "utf8");
|
|
893
1133
|
const chunks = [];
|
|
894
1134
|
for await (const chunk of process.stdin) chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
895
1135
|
return Buffer.concat(chunks).toString("utf8");
|
|
@@ -938,32 +1178,32 @@ function localTimestamp() {
|
|
|
938
1178
|
return `${new Date(date.getTime() + minutes * 6e4).toISOString().slice(0, -1)}${minutes >= 0 ? "+" : "-"}${pad(Math.trunc(minutes / 60))}:${pad(minutes % 60)}`;
|
|
939
1179
|
}
|
|
940
1180
|
async function attachRoadmap(deps, taskId, slug, key) {
|
|
941
|
-
let directory =
|
|
1181
|
+
let directory = path4.dirname(deps.repoBinding?.path ?? deps.projectBindingPath ?? path4.join(process.cwd(), "nolto.json"));
|
|
942
1182
|
let file = "";
|
|
943
1183
|
try {
|
|
944
1184
|
if (slug !== void 0 && !/^[a-z0-9][a-z0-9._-]*$/.test(slug)) throw new Error("Invalid --roadmap slug.");
|
|
945
1185
|
let entries;
|
|
946
1186
|
for (; ; ) {
|
|
947
1187
|
try {
|
|
948
|
-
entries = await
|
|
1188
|
+
entries = await readdir2(path4.join(directory, ".nolto", "roadmaps"));
|
|
949
1189
|
break;
|
|
950
1190
|
} catch (error) {
|
|
951
|
-
if (error.code !== "ENOENT" ||
|
|
952
|
-
directory =
|
|
1191
|
+
if (error.code !== "ENOENT" || path4.dirname(directory) === directory) throw error;
|
|
1192
|
+
directory = path4.dirname(directory);
|
|
953
1193
|
}
|
|
954
1194
|
}
|
|
955
1195
|
const names = entries.filter((name) => name.endsWith(".json")).sort();
|
|
956
1196
|
if (slug === void 0 && names.length !== 1) throw new Error(`Choose --roadmap <slug>. Candidates: ${names.map((name) => name.slice(0, -5)).join(", ") || "(none)"}`);
|
|
957
|
-
file =
|
|
958
|
-
const result = addIssueToRoadmapTask(JSON.parse(await
|
|
1197
|
+
file = path4.join(directory, ".nolto", "roadmaps", slug === void 0 ? names[0] : `${slug}.json`);
|
|
1198
|
+
const result = addIssueToRoadmapTask(JSON.parse(await readFile4(file, "utf8")), taskId, key, localTimestamp());
|
|
959
1199
|
if ("error" in result) throw new Error(`${result.error} in ${file}`);
|
|
960
1200
|
if (result.changed) {
|
|
961
1201
|
const temp = `${file}.${randomUUID()}.tmp`;
|
|
962
1202
|
try {
|
|
963
|
-
await
|
|
1203
|
+
await writeFile4(temp, JSON.stringify(result.roadmap, null, 2) + "\n", { flag: "wx" });
|
|
964
1204
|
await rename(temp, file);
|
|
965
1205
|
} finally {
|
|
966
|
-
await
|
|
1206
|
+
await rm2(temp, { force: true });
|
|
967
1207
|
}
|
|
968
1208
|
}
|
|
969
1209
|
process.stderr.write("Run `nolto sync` to link it on Nolto.\n");
|
|
@@ -985,7 +1225,18 @@ function writeOptions(command, create) {
|
|
|
985
1225
|
return command;
|
|
986
1226
|
}
|
|
987
1227
|
function register(program, deps) {
|
|
988
|
-
const group = program.command("issue").description("List, view and manage project issues.")
|
|
1228
|
+
const group = program.command("issue").description("List, view and manage project issues.").addHelpText("after", `
|
|
1229
|
+
All commands accept global \`--project <id>\`, \`--json\`, \`--token <value>\` and \`--base-url <url>\`.
|
|
1230
|
+
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
|
+
|
|
1232
|
+
| Exit | Meaning |
|
|
1233
|
+
|---|---|
|
|
1234
|
+
| 0 | Success |
|
|
1235
|
+
| 2 | Invalid input, recognized API 404, HTTP 422 (details shown), or local roadmap failure after creation |
|
|
1236
|
+
| 3 | HTTP 401/403; token_scope/token_project includes a token settings hint |
|
|
1237
|
+
| 4 | HTTP 402/429 (quota/rate limit). API token writes: 60/minute. On 429, wait Retry-After seconds before retrying. |
|
|
1238
|
+
| 5 | Network/generic HTTP errors, including a 404 without an API error string |
|
|
1239
|
+
`);
|
|
989
1240
|
group.command("list").description("List or search issues.").option("--status <names...>", "Status names or UUIDs").option("--assignee <assignee>", "me, none or UUID").option("--closed <mode>", "exclude, include or only").option("--q <text>", "Search text").option("--sort <field>", "updated, due, priority, number, created, assignee, status, type or subject").option("--order <order>", "asc or desc").option("--page <number>", "Page number").option("--type <name-or-id>", "Issue type").option("--priority <priority>", "high, normal or low").option("--category <name-or-id>", "Category").option("--parent <ref>", "Parent issue or none").action(async (flags, command) => {
|
|
990
1241
|
const ctx = context(deps, command);
|
|
991
1242
|
const settings = flags.status || flags.type || flags.category ? await deps.http.get(`${ctx.root}/issue-settings`) : emptySettings;
|
|
@@ -1036,10 +1287,491 @@ ${issueUrl(deps.settings.baseUrl, ctx.projectId, number)}`, ctx.mode);
|
|
|
1036
1287
|
});
|
|
1037
1288
|
}
|
|
1038
1289
|
|
|
1290
|
+
// src/memory-import.ts
|
|
1291
|
+
import { readFile as readFile7, readdir as readdir3 } from "fs/promises";
|
|
1292
|
+
import path8 from "path";
|
|
1293
|
+
|
|
1294
|
+
// src/memory-format.ts
|
|
1295
|
+
var oneLine = (value) => value.replace(/[\r\n\u0085\u2028\u2029]/g, " ");
|
|
1296
|
+
var shellArg = (value) => /^[A-Za-z0-9._/-]+$/.test(value) ? value : JSON.stringify(value);
|
|
1297
|
+
var memoryClient = (via) => via?.client || via?.tokenName || "Web";
|
|
1298
|
+
function parseMemory(text, importing = false) {
|
|
1299
|
+
const lines = text.replace(/\r\n/g, "\n").split("\n");
|
|
1300
|
+
if (/^<!--.*-->$/.test(lines[0] ?? "")) lines.shift();
|
|
1301
|
+
if (lines.shift() !== "---") throw new CliError("frontmatter \u306E --- \u304C\u3042\u308A\u307E\u305B\u3093\u3002", 2);
|
|
1302
|
+
const end = lines.indexOf("---");
|
|
1303
|
+
if (end < 0) throw new CliError("frontmatter \u3092 --- \u3067\u9589\u3058\u3066\u304F\u3060\u3055\u3044\u3002", 2);
|
|
1304
|
+
const fields = {};
|
|
1305
|
+
let metadata = false;
|
|
1306
|
+
for (const line2 of lines.slice(0, end)) {
|
|
1307
|
+
const match = /^(\s*)([a-zA-Z]+):\s*(.*)$/.exec(line2);
|
|
1308
|
+
if (!match) continue;
|
|
1309
|
+
const indent = match[1], key = match[2], raw = match[3];
|
|
1310
|
+
if (!indent) metadata = key === "metadata";
|
|
1311
|
+
if (indent && !(importing && metadata && key === "type")) continue;
|
|
1312
|
+
let value = raw.trim();
|
|
1313
|
+
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) value = value.slice(1, -1);
|
|
1314
|
+
if (["name", "description", "type", "scope", "branch", "revision"].includes(key)) fields[key] = value;
|
|
1315
|
+
}
|
|
1316
|
+
const body = lines.slice(end + 1);
|
|
1317
|
+
if (body[0] === "") body.shift();
|
|
1318
|
+
return { ...fields, name: fields.name ?? "", description: fields.description ?? "", body: body.join("\n") };
|
|
1319
|
+
}
|
|
1320
|
+
function formatMemory(entry) {
|
|
1321
|
+
const value = (s) => {
|
|
1322
|
+
const safe = oneLine(s);
|
|
1323
|
+
return /^['"]|['"]$|^\s|\s$/.test(safe) ? `"${safe}"` : safe;
|
|
1324
|
+
};
|
|
1325
|
+
return [
|
|
1326
|
+
"<!-- 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 -->",
|
|
1327
|
+
"---",
|
|
1328
|
+
`name: ${entry.name}`,
|
|
1329
|
+
`description: ${value(entry.description)}`,
|
|
1330
|
+
...entry.type == null ? [] : [`type: ${entry.type}`],
|
|
1331
|
+
`scope: ${entry.scope}`,
|
|
1332
|
+
...entry.scope === "branch" ? [`branch: ${value(entry.branch ?? "")}`] : [],
|
|
1333
|
+
`revision: ${entry.revision}`,
|
|
1334
|
+
`updated: ${oneLine(entry.updatedAt)}${entry.updatedBy?.name ? ` by ${oneLine(entry.updatedBy.name)}` : ""} (${oneLine(memoryClient(entry.updatedVia))})`,
|
|
1335
|
+
"---",
|
|
1336
|
+
"",
|
|
1337
|
+
entry.body
|
|
1338
|
+
].join("\n");
|
|
1339
|
+
}
|
|
1340
|
+
function parseScope(scope, hint = "scope: project|user|branch \u3092 frontmatter \u306B\u66F8\u304F") {
|
|
1341
|
+
if (scope !== "project" && scope !== "user" && scope !== "branch") {
|
|
1342
|
+
throw new CliError(scope ? `scope \u304C\u4E0D\u6B63\u3067\u3059: ${scope}` : "scope \u304C\u5FC5\u8981\u3067\u3059\u3002", 2, hint);
|
|
1343
|
+
}
|
|
1344
|
+
return scope;
|
|
1345
|
+
}
|
|
1346
|
+
var count = (n) => n.toLocaleString("en-US");
|
|
1347
|
+
var invalidInput = (message, hint) => new CliError(message, 2, hint, void 0, "invalid_input");
|
|
1348
|
+
function validateDraft(draft) {
|
|
1349
|
+
if (!/^[a-z0-9][a-z0-9-]{0,63}$/.test(draft.name)) {
|
|
1350
|
+
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");
|
|
1351
|
+
}
|
|
1352
|
+
const description = draft.description.trim();
|
|
1353
|
+
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");
|
|
1354
|
+
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");
|
|
1355
|
+
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");
|
|
1356
|
+
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");
|
|
1357
|
+
if (draft.type && !["user", "feedback", "project", "reference"].includes(draft.type)) {
|
|
1358
|
+
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");
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
function parseRevision(value) {
|
|
1362
|
+
const revision = Number(value);
|
|
1363
|
+
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);
|
|
1364
|
+
return revision;
|
|
1365
|
+
}
|
|
1366
|
+
function detectMemoryClient(env) {
|
|
1367
|
+
const agent = env.NOLTO_AGENT?.trim();
|
|
1368
|
+
if (agent && /^[\x20-\x7e]+$/.test(agent)) return agent;
|
|
1369
|
+
if (env.CLAUDECODE === "1") return "Claude Code";
|
|
1370
|
+
if (env.GEMINI_CLI === "1") return "Gemini CLI";
|
|
1371
|
+
if (env.CODEX_THREAD_ID) return "Codex";
|
|
1372
|
+
return "CLI";
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
// src/memory-cache.ts
|
|
1376
|
+
import { mkdir as mkdir4, readFile as readFile5, rename as rename2, rm as rm3, unlink, writeFile as writeFile5 } from "fs/promises";
|
|
1377
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
1378
|
+
import path5 from "path";
|
|
1379
|
+
function memoryDir(configPath, project) {
|
|
1380
|
+
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(project)) throw new CliError("Invalid project id.", 2);
|
|
1381
|
+
return path5.join(path5.dirname(configPath), "projects", project, "memory");
|
|
1382
|
+
}
|
|
1383
|
+
function memoryEntryPath(entry) {
|
|
1384
|
+
if (!/^[a-z0-9][a-z0-9-]{0,63}$/.test(entry.name)) throw new CliError("Invalid memory name in cache.", 2);
|
|
1385
|
+
if (entry.scope === "project" || entry.scope === "user") return `${entry.scope}/${entry.name}.md`;
|
|
1386
|
+
if (entry.scope !== "branch" || !entry.repoIdentity || !entry.branch) throw new CliError("Invalid memory scope in cache.", 2);
|
|
1387
|
+
if (entry.branch.split("/").some((p) => !p || p === "." || p === ".." || p.includes("\\") || /[\x00-\x1f\x7f]/.test(p) || Buffer.byteLength(p) > 200)) throw new CliError("Unsafe memory branch path.", 2);
|
|
1388
|
+
const repoDir = encodeURIComponent(entry.repoIdentity);
|
|
1389
|
+
if (Buffer.byteLength(repoDir) > 200) throw new CliError("Unsafe memory repo path.", 2);
|
|
1390
|
+
return `branch/${repoDir}/${entry.branch}/${entry.name}.md`;
|
|
1391
|
+
}
|
|
1392
|
+
function storableMemoryEntry(entry) {
|
|
1393
|
+
try {
|
|
1394
|
+
memoryEntryPath(entry);
|
|
1395
|
+
return true;
|
|
1396
|
+
} catch {
|
|
1397
|
+
return false;
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
async function atomicMemoryFile(file, content) {
|
|
1401
|
+
await mkdir4(path5.dirname(file), { recursive: true, mode: 448 });
|
|
1402
|
+
const temp = `${file}.tmp-${randomUUID2()}`;
|
|
1403
|
+
try {
|
|
1404
|
+
await writeFile5(temp, content, { mode: 292 });
|
|
1405
|
+
await unlink(file).catch((error) => {
|
|
1406
|
+
if (error.code !== "ENOENT") throw error;
|
|
1407
|
+
});
|
|
1408
|
+
await rename2(temp, file);
|
|
1409
|
+
} finally {
|
|
1410
|
+
await unlink(temp).catch(() => void 0);
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
async function readMemoryCache(dir, project) {
|
|
1414
|
+
const empty = { state: { entries: [], scope: "", projectName: project.slice(0, 8) }, meta: { cursor: 0, pulledAt: "" } };
|
|
1415
|
+
try {
|
|
1416
|
+
const state = JSON.parse(await readFile5(path5.join(dir, ".entries.json"), "utf8"));
|
|
1417
|
+
if (!Array.isArray(state.entries) || typeof state.scope !== "string" || typeof state.projectName !== "string") throw new Error("Invalid state");
|
|
1418
|
+
if (state.entries.some((e) => e == null || typeof e !== "object" || typeof e.id !== "string" || typeof e.name !== "string")) throw new Error("Invalid entry");
|
|
1419
|
+
let meta = empty.meta;
|
|
1420
|
+
try {
|
|
1421
|
+
meta = JSON.parse(await readFile5(path5.join(dir, ".meta.json"), "utf8"));
|
|
1422
|
+
} catch (error) {
|
|
1423
|
+
if (error.code !== "ENOENT") throw error;
|
|
1424
|
+
}
|
|
1425
|
+
if (!Number.isSafeInteger(meta.cursor) || meta.cursor < 0 || typeof meta.pulledAt !== "string") throw new Error("Invalid cursor");
|
|
1426
|
+
return { state, meta };
|
|
1427
|
+
} catch (error) {
|
|
1428
|
+
if (error.code === "ENOENT") return empty;
|
|
1429
|
+
throw new CliError(`\u30E1\u30E2\u30EA\u30AD\u30E3\u30C3\u30B7\u30E5\u3092\u8AAD\u3081\u307E\u305B\u3093: ${String(error)}`, 2, "nolto memory pull");
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
function mergeMemoryEntries(entries, updates) {
|
|
1433
|
+
const byId = new Map(entries.map((entry) => [entry.id, entry]));
|
|
1434
|
+
for (const entry of updates) {
|
|
1435
|
+
const old = byId.get(entry.id);
|
|
1436
|
+
if (!old || old.revision <= entry.revision) byId.set(entry.id, entry);
|
|
1437
|
+
}
|
|
1438
|
+
return [...byId.values()];
|
|
1439
|
+
}
|
|
1440
|
+
async function saveMemoryCache(dir, cache, previous, index, reset = false) {
|
|
1441
|
+
const unsafe = cache.state.entries.filter((e) => !storableMemoryEntry(e));
|
|
1442
|
+
if (reset) await rm3(dir, { recursive: true, force: true });
|
|
1443
|
+
const livePaths = new Set(cache.state.entries.filter((e) => !e.deleted && storableMemoryEntry(e)).map(memoryEntryPath));
|
|
1444
|
+
for (const entry of previous.filter(storableMemoryEntry)) {
|
|
1445
|
+
const relative = memoryEntryPath(entry);
|
|
1446
|
+
if (!livePaths.has(relative)) await rm3(path5.join(dir, relative), { force: true });
|
|
1447
|
+
}
|
|
1448
|
+
for (const entry of cache.state.entries) {
|
|
1449
|
+
if (!entry.deleted && storableMemoryEntry(entry)) await atomicMemoryFile(path5.join(dir, memoryEntryPath(entry)), formatMemory(entry));
|
|
1450
|
+
}
|
|
1451
|
+
await atomicMemoryFile(path5.join(dir, ".entries.json"), JSON.stringify(cache.state) + "\n");
|
|
1452
|
+
await atomicMemoryFile(path5.join(dir, "MEMORY.md"), index);
|
|
1453
|
+
await atomicMemoryFile(path5.join(dir, ".meta.json"), JSON.stringify(cache.meta) + "\n");
|
|
1454
|
+
return unsafe;
|
|
1455
|
+
}
|
|
1456
|
+
function currentMemoryEntries(entries, context3, allBranches = false) {
|
|
1457
|
+
return entries.filter((e) => !e.deleted && storableMemoryEntry(e) && (e.scope !== "branch" || allBranches || context3.branch !== context3.defaultBranch && e.repoIdentity === context3.repoIdentity && e.branch === context3.branch));
|
|
1458
|
+
}
|
|
1459
|
+
var scopeOrder = ["project", "user", "branch"];
|
|
1460
|
+
function sortMemoryEntries(entries) {
|
|
1461
|
+
return entries.sort((a, b) => scopeOrder.indexOf(a.scope) - scopeOrder.indexOf(b.scope) || b.updatedAt.localeCompare(a.updatedAt) || a.name.localeCompare(b.name));
|
|
1462
|
+
}
|
|
1463
|
+
function memoryIndex(cache, context3, merged = /* @__PURE__ */ new Set(), dir) {
|
|
1464
|
+
const branch = context3.branch && context3.branch !== context3.defaultBranch ? context3.branch : null;
|
|
1465
|
+
const entries = sortMemoryEntries(currentMemoryEntries(cache.state.entries, context3));
|
|
1466
|
+
const groups = ["project", "user", ...branch ? ["branch"] : []];
|
|
1467
|
+
const mergedLines = [...merged].sort().map((b) => `merge \u6E08\u307F\u306E ${oneLine(b)} \u306B ${cache.state.entries.filter((e) => !e.deleted && e.scope === "branch" && e.repoIdentity === context3.repoIdentity && e.branch === b).length} \u4EF6: nolto memory promote --branch ${shellArg(b)}`);
|
|
1468
|
+
let omitted = 0;
|
|
1469
|
+
const build = () => [
|
|
1470
|
+
`# Nolto memory \u2014 ${oneLine(cache.state.projectName)}(\u540C\u671F ${cache.meta.pulledAt ? new Date(cache.meta.pulledAt).toTimeString().slice(0, 5) : "\u672A\u540C\u671F"}${branch ? `\u3001branch ${oneLine(branch)}` : ""})`,
|
|
1471
|
+
"\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
|
+
...dir ? [`\u30AD\u30E3\u30C3\u30B7\u30E5: ${dir}`] : [],
|
|
1473
|
+
...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] : [];
|
|
1476
|
+
}),
|
|
1477
|
+
...mergedLines,
|
|
1478
|
+
...omitted ? [`\u6B8B\u308A ${omitted} \u4EF6: nolto memory list`] : []
|
|
1479
|
+
];
|
|
1480
|
+
while (build().length > 200) {
|
|
1481
|
+
let project = -1;
|
|
1482
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
1483
|
+
if (entries[i].scope === "project") {
|
|
1484
|
+
project = i;
|
|
1485
|
+
break;
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
if (entries.length) {
|
|
1489
|
+
entries.splice(project < 0 ? entries.length - 1 : project, 1);
|
|
1490
|
+
omitted++;
|
|
1491
|
+
} else {
|
|
1492
|
+
mergedLines.pop();
|
|
1493
|
+
omitted++;
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
return build().join("\n") + "\n";
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
// src/memory-git.ts
|
|
1500
|
+
import { execFile as execFile2 } from "child_process";
|
|
1501
|
+
import { promisify } from "util";
|
|
1502
|
+
|
|
1503
|
+
// src/repo-identity.ts
|
|
1504
|
+
import { execFile } from "child_process";
|
|
1505
|
+
import { realpathSync } from "fs";
|
|
1506
|
+
import path7 from "path";
|
|
1507
|
+
|
|
1508
|
+
// src/machine-id.ts
|
|
1509
|
+
import { chmod, mkdir as mkdir5, readFile as readFile6, writeFile as writeFile6 } from "fs/promises";
|
|
1510
|
+
import { randomUUID as randomUUID3 } from "crypto";
|
|
1511
|
+
import path6 from "path";
|
|
1512
|
+
var inFlightByConfigDir = /* @__PURE__ */ new Map();
|
|
1513
|
+
function parseMachineId(raw, file) {
|
|
1514
|
+
let parsed;
|
|
1515
|
+
try {
|
|
1516
|
+
parsed = JSON.parse(raw);
|
|
1517
|
+
} catch {
|
|
1518
|
+
throw new CliError(`Malformed JSON in ${file}. Remove the file to regenerate it.`, 2);
|
|
1519
|
+
}
|
|
1520
|
+
const id = parsed?.machineId;
|
|
1521
|
+
if (typeof id !== "string" || id.length === 0) {
|
|
1522
|
+
throw new CliError(`Invalid ${file}: missing machineId. Remove the file to regenerate it.`, 2);
|
|
1523
|
+
}
|
|
1524
|
+
return id;
|
|
1525
|
+
}
|
|
1526
|
+
async function loadOrCreate(configDir) {
|
|
1527
|
+
const file = path6.join(configDir, "machine.json");
|
|
1528
|
+
let raw = null;
|
|
1529
|
+
try {
|
|
1530
|
+
raw = await readFile6(file, "utf8");
|
|
1531
|
+
} catch (err) {
|
|
1532
|
+
const code = err.code;
|
|
1533
|
+
if (code !== "ENOENT") {
|
|
1534
|
+
throw new CliError(`Cannot read ${file}: ${String(err)}`, 2);
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
if (raw !== null) {
|
|
1538
|
+
return parseMachineId(raw, file);
|
|
1539
|
+
}
|
|
1540
|
+
const machineId = randomUUID3();
|
|
1541
|
+
await mkdir5(configDir, { recursive: true, mode: 448 });
|
|
1542
|
+
try {
|
|
1543
|
+
await writeFile6(file, `${JSON.stringify({ machineId }, null, 2)}
|
|
1544
|
+
`, {
|
|
1545
|
+
flag: "wx",
|
|
1546
|
+
mode: 384
|
|
1547
|
+
});
|
|
1548
|
+
} catch (err) {
|
|
1549
|
+
if (err.code === "EEXIST") {
|
|
1550
|
+
return parseMachineId(await readFile6(file, "utf8"), file);
|
|
1551
|
+
}
|
|
1552
|
+
throw new CliError(`Cannot write ${file}: ${String(err)}`, 2);
|
|
1553
|
+
}
|
|
1554
|
+
await chmod(file, 384);
|
|
1555
|
+
return machineId;
|
|
1556
|
+
}
|
|
1557
|
+
function loadOrCreateMachineId(configDir) {
|
|
1558
|
+
const key = path6.resolve(configDir);
|
|
1559
|
+
const existing = inFlightByConfigDir.get(key);
|
|
1560
|
+
if (existing !== void 0) return existing;
|
|
1561
|
+
const pending = loadOrCreate(key).finally(() => {
|
|
1562
|
+
if (inFlightByConfigDir.get(key) === pending) inFlightByConfigDir.delete(key);
|
|
1563
|
+
});
|
|
1564
|
+
inFlightByConfigDir.set(key, pending);
|
|
1565
|
+
return pending;
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1568
|
+
// src/repo-identity.ts
|
|
1569
|
+
function defaultGetRemoteUrl(root) {
|
|
1570
|
+
return new Promise((resolve) => {
|
|
1571
|
+
execFile(
|
|
1572
|
+
"git",
|
|
1573
|
+
["-C", root, "remote", "get-url", "origin"],
|
|
1574
|
+
{ timeout: 5e3 },
|
|
1575
|
+
(err, stdout2) => {
|
|
1576
|
+
if (err) return resolve(null);
|
|
1577
|
+
const line2 = stdout2.split(/\r?\n/)[0]?.trim() ?? "";
|
|
1578
|
+
resolve(line2.length > 0 ? line2 : null);
|
|
1579
|
+
}
|
|
1580
|
+
);
|
|
1581
|
+
});
|
|
1582
|
+
}
|
|
1583
|
+
async function resolveRepoIdentity(root, deps) {
|
|
1584
|
+
const remote = await deps.getRemoteUrl(root);
|
|
1585
|
+
const normalized = remote === null ? null : normalizeRemote(remote);
|
|
1586
|
+
if (normalized !== null) return { kind: "remote", value: normalized };
|
|
1587
|
+
const machineId = await deps.machineId();
|
|
1588
|
+
let canonicalRoot;
|
|
1589
|
+
try {
|
|
1590
|
+
canonicalRoot = realpathSync(root);
|
|
1591
|
+
} catch {
|
|
1592
|
+
canonicalRoot = path7.resolve(root);
|
|
1593
|
+
}
|
|
1594
|
+
return { kind: "local", value: `${machineId}:${canonicalRoot}` };
|
|
1595
|
+
}
|
|
1596
|
+
function makeRepoIdentityResolver(deps) {
|
|
1597
|
+
return deps.repoIdentity ?? ((root) => resolveRepoIdentity(root, {
|
|
1598
|
+
getRemoteUrl: defaultGetRemoteUrl,
|
|
1599
|
+
machineId: () => loadOrCreateMachineId(getConfigDir(process.env))
|
|
1600
|
+
}));
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1603
|
+
// src/memory-git.ts
|
|
1604
|
+
var runMemoryGit = async (args, root) => (await promisify(execFile2)("git", args, { cwd: root, timeout: 5e3 })).stdout.trim();
|
|
1605
|
+
async function memoryGitContext(root, deps) {
|
|
1606
|
+
const git = deps.memoryGit ?? runMemoryGit;
|
|
1607
|
+
const result = { repoIdentity: null, branch: null, defaultBranch: null };
|
|
1608
|
+
try {
|
|
1609
|
+
await git(["rev-parse", "--show-toplevel"], root);
|
|
1610
|
+
const identity = await makeRepoIdentityResolver(deps)(root);
|
|
1611
|
+
result.repoIdentity = `${identity.kind}:${identity.value}`;
|
|
1612
|
+
result.branch = await git(["symbolic-ref", "--quiet", "--short", "HEAD"], root).catch(() => null);
|
|
1613
|
+
const remote = await git(["symbolic-ref", "refs/remotes/origin/HEAD"], root).catch(() => "");
|
|
1614
|
+
if (remote.startsWith("refs/remotes/origin/")) result.defaultBranch = remote.slice("refs/remotes/origin/".length);
|
|
1615
|
+
else {
|
|
1616
|
+
for (const branch of ["main", "master"]) {
|
|
1617
|
+
try {
|
|
1618
|
+
await git(["show-ref", "--verify", `refs/heads/${branch}`], root);
|
|
1619
|
+
result.defaultBranch = branch;
|
|
1620
|
+
break;
|
|
1621
|
+
} catch {
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
} catch {
|
|
1626
|
+
}
|
|
1627
|
+
return result;
|
|
1628
|
+
}
|
|
1629
|
+
async function mergedMemoryBranches(branches, context3, root, git, mine = /* @__PURE__ */ new Set()) {
|
|
1630
|
+
const merged = /* @__PURE__ */ new Set();
|
|
1631
|
+
if (!context3.defaultBranch || !context3.repoIdentity) return merged;
|
|
1632
|
+
const hasRef = async (ref) => {
|
|
1633
|
+
try {
|
|
1634
|
+
await git(["show-ref", "--verify", "--quiet", ref], root);
|
|
1635
|
+
return true;
|
|
1636
|
+
} catch (error) {
|
|
1637
|
+
if (error.code === 1) return false;
|
|
1638
|
+
throw error;
|
|
1639
|
+
}
|
|
1640
|
+
};
|
|
1641
|
+
let checkedOut, target, targetTip;
|
|
1642
|
+
try {
|
|
1643
|
+
checkedOut = new Set((await git(["worktree", "list", "--porcelain"], root)).split("\n").filter((l) => l.startsWith("branch refs/heads/")).map((l) => l.slice("branch refs/heads/".length)));
|
|
1644
|
+
target = await hasRef(`refs/heads/${context3.defaultBranch}`) ? `refs/heads/${context3.defaultBranch}` : `refs/remotes/origin/${context3.defaultBranch}`;
|
|
1645
|
+
targetTip = await git(["rev-parse", target], root);
|
|
1646
|
+
} catch {
|
|
1647
|
+
return merged;
|
|
1648
|
+
}
|
|
1649
|
+
for (const branch of branches) {
|
|
1650
|
+
if (branch === context3.defaultBranch || branch === context3.branch || checkedOut.has(branch)) continue;
|
|
1651
|
+
try {
|
|
1652
|
+
const local = `refs/heads/${branch}`;
|
|
1653
|
+
if (await hasRef(local)) {
|
|
1654
|
+
if (await git(["rev-parse", local], root) === targetTip) continue;
|
|
1655
|
+
await git(["merge-base", "--is-ancestor", local, target], root);
|
|
1656
|
+
merged.add(branch);
|
|
1657
|
+
} else if (mine.has(branch) && !await hasRef(`refs/remotes/origin/${branch}`)) merged.add(branch);
|
|
1658
|
+
} catch {
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
return merged;
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1664
|
+
// src/memory-import.ts
|
|
1665
|
+
function aiHeading(response) {
|
|
1666
|
+
const { entry, ai } = response;
|
|
1667
|
+
if (!ai || ai.action !== "merge" && ai.action !== "replace") return null;
|
|
1668
|
+
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
|
+
}
|
|
1670
|
+
async function createMemoryContext(opts, recover = false) {
|
|
1671
|
+
const { projectId: project, root, git } = opts;
|
|
1672
|
+
const dir = memoryDir(opts.configPath, project);
|
|
1673
|
+
const cache = await readMemoryCache(dir, project).catch((error) => {
|
|
1674
|
+
if (!recover) throw error;
|
|
1675
|
+
return { state: { entries: [], scope: "", projectName: project.slice(0, 8) }, meta: { cursor: 0, pulledAt: "" } };
|
|
1676
|
+
});
|
|
1677
|
+
return { project, dir, root, git, cache, api: `/api/projects/${project}/memory` };
|
|
1678
|
+
}
|
|
1679
|
+
async function memoryIndexText(ctx, deps) {
|
|
1680
|
+
const entries = ctx.cache.state.entries.filter((e) => !e.deleted && e.scope === "branch" && e.repoIdentity === ctx.git.repoIdentity);
|
|
1681
|
+
const branches = [...new Set(entries.map((e) => e.branch))];
|
|
1682
|
+
const userId = ctx.cache.state.userId;
|
|
1683
|
+
const mine = new Set(userId ? entries.filter((e) => e.updatedBy?.id === userId).map((e) => e.branch) : []);
|
|
1684
|
+
return memoryIndex(ctx.cache, ctx.git, await mergedMemoryBranches(branches, ctx.git, ctx.root, deps.memoryGit ?? runMemoryGit, mine), ctx.dir);
|
|
1685
|
+
}
|
|
1686
|
+
var cacheWarning = "Warning: \u30B5\u30FC\u30D0\u30FC\u3078\u306E\u66F8\u304D\u8FBC\u307F\u306F\u6210\u529F\u3057\u307E\u3057\u305F\u304C\u3001\u30AD\u30E3\u30C3\u30B7\u30E5\u3092\u66F4\u65B0\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\u3002nolto memory pull \u3067\u540C\u671F\u3057\u3066\u304F\u3060\u3055\u3044\u3002\n";
|
|
1687
|
+
async function updateCache(ctx, deps, entries, quiet = false) {
|
|
1688
|
+
const previous = ctx.cache.state.entries;
|
|
1689
|
+
try {
|
|
1690
|
+
ctx.cache.state.entries = mergeMemoryEntries(previous, entries);
|
|
1691
|
+
await saveMemoryCache(ctx.dir, ctx.cache, previous, await memoryIndexText(ctx, deps));
|
|
1692
|
+
return true;
|
|
1693
|
+
} catch {
|
|
1694
|
+
if (!quiet) process.stderr.write(cacheWarning);
|
|
1695
|
+
return false;
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
function writtenEntries(ctx, response) {
|
|
1699
|
+
const tombstones = (response.affected ?? []).flatMap((a) => {
|
|
1700
|
+
const cached = a.deleted && a.entryId !== response.entry.id ? ctx.cache.state.entries.find((e) => e.id === a.entryId) : void 0;
|
|
1701
|
+
return cached ? [{ ...cached, deleted: true, revision: a.toRevision }] : [];
|
|
1702
|
+
});
|
|
1703
|
+
return [response.entry, ...tombstones];
|
|
1704
|
+
}
|
|
1705
|
+
async function scanMemoryDir(dir) {
|
|
1706
|
+
const ok = [], invalid = [];
|
|
1707
|
+
const seen = /* @__PURE__ */ new Map();
|
|
1708
|
+
for (const file of (await readdir3(dir, { withFileTypes: true })).filter((f) => f.isFile() && f.name.endsWith(".md") && f.name !== "MEMORY.md").sort((a, b) => a.name.localeCompare(b.name))) {
|
|
1709
|
+
let original = file.name.slice(0, -3), name = original;
|
|
1710
|
+
try {
|
|
1711
|
+
const draft = parseMemory(await readFile7(path8.join(dir, file.name), "utf8"), true);
|
|
1712
|
+
original = draft.name || original;
|
|
1713
|
+
name = original.toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/^-+/, "").slice(0, 64);
|
|
1714
|
+
if (!name) throw new CliError(`name \u3092\u6B63\u898F\u5316\u3067\u304D\u307E\u305B\u3093: ${original}`, 2);
|
|
1715
|
+
validateDraft({ ...draft, name });
|
|
1716
|
+
const first = seen.get(name);
|
|
1717
|
+
if (first) throw new CliError(`import \u5185\u3067 name \u304C\u91CD\u8907\u3057\u3066\u3044\u307E\u3059(\u5148: ${first})\u3002`, 2);
|
|
1718
|
+
seen.set(name, file.name);
|
|
1719
|
+
ok.push({ file: file.name, name, original, draft: { ...draft, name } });
|
|
1720
|
+
} catch (error) {
|
|
1721
|
+
invalid.push({ file: file.name, name, original, status: "failed", message: error instanceof Error ? error.message : String(error) });
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
return { ok, invalid };
|
|
1725
|
+
}
|
|
1726
|
+
function importResultLine(scope, result) {
|
|
1727
|
+
const { status, name, original, message } = result;
|
|
1728
|
+
return `${status} ${scope}/${name}${original !== name ? ` (\u5143: ${oneLine(original)})` : ""}${message ? ` \u2014 ${oneLine(message)}` : ""}`;
|
|
1729
|
+
}
|
|
1730
|
+
async function importMemoryFiles(opts) {
|
|
1731
|
+
const ctx = await createMemoryContext(opts, true);
|
|
1732
|
+
let imported = 0, skipped = 0, failed = 0, cached = true;
|
|
1733
|
+
const results = [];
|
|
1734
|
+
for (const { file, name, original, draft } of opts.targets) {
|
|
1735
|
+
let status, message, heading = null;
|
|
1736
|
+
try {
|
|
1737
|
+
const response = await opts.http.put(ctx.api, {
|
|
1738
|
+
scope: opts.scope,
|
|
1739
|
+
name,
|
|
1740
|
+
description: draft.description,
|
|
1741
|
+
body: draft.body,
|
|
1742
|
+
...draft.type ? { type: draft.type } : {},
|
|
1743
|
+
allowNew: true,
|
|
1744
|
+
...opts.ai ? {} : { aiSkip: true }
|
|
1745
|
+
}, { "X-Nolto-Client": detectMemoryClient(process.env) });
|
|
1746
|
+
cached = await updateCache(ctx, opts, writtenEntries(ctx, response), true) && cached;
|
|
1747
|
+
heading = aiHeading(response);
|
|
1748
|
+
imported++;
|
|
1749
|
+
status = "imported";
|
|
1750
|
+
} catch (error) {
|
|
1751
|
+
if (error instanceof CliError && error.serverError === "memory_exists") {
|
|
1752
|
+
skipped++;
|
|
1753
|
+
status = "skipped";
|
|
1754
|
+
if (error.body?.entry) cached = await updateCache(ctx, opts, [error.body.entry], true) && cached;
|
|
1755
|
+
} else {
|
|
1756
|
+
failed++;
|
|
1757
|
+
status = "failed";
|
|
1758
|
+
message = error instanceof Error ? error.message : String(error);
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
const result = { file, name, original, status, ...message ? { message } : {} };
|
|
1762
|
+
results.push(result);
|
|
1763
|
+
opts.write(heading ? `${heading} (\u5143: ${oneLine(file)})` : importResultLine(opts.scope, result));
|
|
1764
|
+
}
|
|
1765
|
+
return { imported, skipped, failed, results, cached };
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1768
|
+
// src/commands/init.ts
|
|
1769
|
+
import { readFile as readFile11 } from "fs/promises";
|
|
1770
|
+
|
|
1039
1771
|
// src/watch-state.ts
|
|
1040
1772
|
import * as fs from "fs/promises";
|
|
1041
|
-
import { randomUUID as
|
|
1042
|
-
import
|
|
1773
|
+
import { randomUUID as randomUUID4 } from "crypto";
|
|
1774
|
+
import path9 from "path";
|
|
1043
1775
|
import { z as z2 } from "zod";
|
|
1044
1776
|
var watchStateSchema = z2.object({
|
|
1045
1777
|
pid: z2.number().int().positive(),
|
|
@@ -1047,7 +1779,7 @@ var watchStateSchema = z2.object({
|
|
|
1047
1779
|
startedAt: z2.string().datetime()
|
|
1048
1780
|
});
|
|
1049
1781
|
function getWatchStatePath(env) {
|
|
1050
|
-
return
|
|
1782
|
+
return path9.join(getConfigDir(env), "watch.json");
|
|
1051
1783
|
}
|
|
1052
1784
|
async function readWatchState(filePath, io = fs) {
|
|
1053
1785
|
try {
|
|
@@ -1058,8 +1790,8 @@ async function readWatchState(filePath, io = fs) {
|
|
|
1058
1790
|
}
|
|
1059
1791
|
}
|
|
1060
1792
|
async function writeWatchState(filePath, state, io = fs) {
|
|
1061
|
-
await io.mkdir(
|
|
1062
|
-
const tempPath = `${filePath}.tmp-${process.pid}-${
|
|
1793
|
+
await io.mkdir(path9.dirname(filePath), { recursive: true, mode: 448 });
|
|
1794
|
+
const tempPath = `${filePath}.tmp-${process.pid}-${randomUUID4()}`;
|
|
1063
1795
|
try {
|
|
1064
1796
|
await io.writeFile(tempPath, JSON.stringify(state, null, 2) + "\n", { encoding: "utf8", mode: 384 });
|
|
1065
1797
|
await io.rename(tempPath, filePath);
|
|
@@ -1094,24 +1826,24 @@ import readline2 from "readline/promises";
|
|
|
1094
1826
|
import { createRequire } from "module";
|
|
1095
1827
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
1096
1828
|
import os3 from "os";
|
|
1097
|
-
import
|
|
1829
|
+
import path15 from "path";
|
|
1098
1830
|
import fs2 from "fs";
|
|
1099
1831
|
|
|
1100
1832
|
// src/roadmap-bootstrap.ts
|
|
1101
|
-
import { existsSync } from "fs";
|
|
1102
|
-
import { readFile as
|
|
1103
|
-
import
|
|
1833
|
+
import { existsSync as existsSync3 } from "fs";
|
|
1834
|
+
import { readFile as readFile9, realpath } from "fs/promises";
|
|
1835
|
+
import path12 from "path";
|
|
1104
1836
|
|
|
1105
1837
|
// src/roadmap-cache.ts
|
|
1106
|
-
import { mkdir as
|
|
1107
|
-
import { randomUUID as
|
|
1108
|
-
import
|
|
1838
|
+
import { mkdir as mkdir6, readdir as readdir4, readFile as readFile8, writeFile as writeFile7, rename as rename3, unlink as unlink2 } from "fs/promises";
|
|
1839
|
+
import { randomUUID as randomUUID5 } from "crypto";
|
|
1840
|
+
import path11 from "path";
|
|
1109
1841
|
|
|
1110
1842
|
// src/sync-core.ts
|
|
1111
|
-
import { createHash } from "crypto";
|
|
1112
|
-
import
|
|
1843
|
+
import { createHash as createHash2 } from "crypto";
|
|
1844
|
+
import path10 from "path";
|
|
1113
1845
|
function sha256Hex(content) {
|
|
1114
|
-
return "sha256:" +
|
|
1846
|
+
return "sha256:" + createHash2("sha256").update(content, "utf8").digest("hex");
|
|
1115
1847
|
}
|
|
1116
1848
|
function collectPlanRefs(roadmap) {
|
|
1117
1849
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -1130,10 +1862,10 @@ function collectPlanRefs(roadmap) {
|
|
|
1130
1862
|
}
|
|
1131
1863
|
return refs;
|
|
1132
1864
|
}
|
|
1133
|
-
async function loadValidRoadmap(filePath,
|
|
1865
|
+
async function loadValidRoadmap(filePath, readFile19) {
|
|
1134
1866
|
let raw;
|
|
1135
1867
|
try {
|
|
1136
|
-
raw = await
|
|
1868
|
+
raw = await readFile19(filePath);
|
|
1137
1869
|
} catch {
|
|
1138
1870
|
throw new CliError(`No roadmap found at ${filePath}. Run \`nolto init\` first.`, 2);
|
|
1139
1871
|
}
|
|
@@ -1167,9 +1899,9 @@ async function buildSyncBody(args) {
|
|
|
1167
1899
|
}
|
|
1168
1900
|
} catch {
|
|
1169
1901
|
}
|
|
1170
|
-
const root =
|
|
1171
|
-
const absolute =
|
|
1172
|
-
if (absolute !== root && !absolute.startsWith(root +
|
|
1902
|
+
const root = path10.resolve(args.repoRoot);
|
|
1903
|
+
const absolute = path10.resolve(root, ref.path);
|
|
1904
|
+
if (absolute !== root && !absolute.startsWith(root + path10.sep)) {
|
|
1173
1905
|
args.deps.warn(`plan path outside repository root, skipping: ${ref.path}`);
|
|
1174
1906
|
continue;
|
|
1175
1907
|
}
|
|
@@ -1187,11 +1919,11 @@ async function buildSyncBody(args) {
|
|
|
1187
1919
|
args.deps.warn(`plan file not found, skipping: ${ref.path}`);
|
|
1188
1920
|
continue;
|
|
1189
1921
|
}
|
|
1190
|
-
if (real !== realRoot && !real.startsWith(realRoot +
|
|
1922
|
+
if (real !== realRoot && !real.startsWith(realRoot + path10.sep)) {
|
|
1191
1923
|
args.deps.warn(`symlink escapes repository root, skipping: ${ref.path}`);
|
|
1192
1924
|
continue;
|
|
1193
1925
|
}
|
|
1194
|
-
if (!isValidPlanPath(
|
|
1926
|
+
if (!isValidPlanPath(path10.relative(realRoot, real).split(path10.sep).join("/"))) {
|
|
1195
1927
|
args.deps.warn(`plan path not allowed (markdown only, no dot segments), skipping: ${ref.path}`);
|
|
1196
1928
|
continue;
|
|
1197
1929
|
}
|
|
@@ -1230,16 +1962,16 @@ var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
|
1230
1962
|
var ROADMAP_SLUG_PATTERN = /^[a-z0-9][a-z0-9._-]*$/;
|
|
1231
1963
|
function cacheDir(env, projectId) {
|
|
1232
1964
|
if (!UUID_RE.test(projectId)) throw new CliError(`Invalid project id "${projectId}".`, 2);
|
|
1233
|
-
return
|
|
1965
|
+
return path11.join(getConfigDir(env), "projects", projectId, "roadmaps");
|
|
1234
1966
|
}
|
|
1235
1967
|
function cachePaths(env, projectId, slug) {
|
|
1236
1968
|
if (!ROADMAP_SLUG_PATTERN.test(slug)) throw new CliError(`Invalid roadmap slug "${slug}".`, 2);
|
|
1237
1969
|
const dir = cacheDir(env, projectId);
|
|
1238
|
-
return { json:
|
|
1970
|
+
return { json: path11.join(dir, `${slug}.json`), meta: path11.join(dir, `${slug}.meta.json`) };
|
|
1239
1971
|
}
|
|
1240
1972
|
async function listCachedSlugs(env, projectId) {
|
|
1241
1973
|
try {
|
|
1242
|
-
const entries = await
|
|
1974
|
+
const entries = await readdir4(cacheDir(env, projectId), { withFileTypes: true });
|
|
1243
1975
|
return entries.filter((entry) => entry.isFile() && entry.name.endsWith(".json") && !entry.name.endsWith(".meta.json")).map((entry) => entry.name.slice(0, -5)).sort();
|
|
1244
1976
|
} catch (err) {
|
|
1245
1977
|
if (err.code === "ENOENT") return [];
|
|
@@ -1250,7 +1982,7 @@ async function readCache(env, projectId, slug) {
|
|
|
1250
1982
|
const paths = cachePaths(env, projectId, slug);
|
|
1251
1983
|
let raw;
|
|
1252
1984
|
try {
|
|
1253
|
-
raw = await
|
|
1985
|
+
raw = await readFile8(paths.json, "utf8");
|
|
1254
1986
|
} catch (err) {
|
|
1255
1987
|
if (err.code === "ENOENT") return null;
|
|
1256
1988
|
throw err;
|
|
@@ -1265,7 +1997,7 @@ async function readCache(env, projectId, slug) {
|
|
|
1265
1997
|
if (errors.length) throw new CliError(`${paths.json} failed validation: ${errors.join("; ")}`, 2);
|
|
1266
1998
|
let meta = null;
|
|
1267
1999
|
try {
|
|
1268
|
-
const parsed = JSON.parse(await
|
|
2000
|
+
const parsed = JSON.parse(await readFile8(paths.meta, "utf8"));
|
|
1269
2001
|
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed) || !("revision" in parsed) || !Number.isSafeInteger(parsed.revision) || Number(parsed.revision) < 0 || !("pulledAt" in parsed) || typeof parsed.pulledAt !== "string" || !("contentHash" in parsed) || typeof parsed.contentHash !== "string") {
|
|
1270
2002
|
throw new Error("Invalid cache metadata");
|
|
1271
2003
|
}
|
|
@@ -1287,14 +2019,14 @@ async function writeCache(env, projectId, slug, roadmap, meta) {
|
|
|
1287
2019
|
const paths = cachePaths(env, projectId, slug);
|
|
1288
2020
|
const raw = serializeRoadmap(roadmap);
|
|
1289
2021
|
const metadata = { ...meta, currentTaskId: meta.currentTaskId ?? null, repoIdentity: meta.repoIdentity ?? null, contentHash: sha256Hex(raw) };
|
|
1290
|
-
await
|
|
2022
|
+
await mkdir6(cacheDir(env, projectId), { recursive: true, mode: 448 });
|
|
1291
2023
|
for (const [filePath, content] of [[paths.json, raw], [paths.meta, JSON.stringify(metadata, null, 2) + "\n"]]) {
|
|
1292
|
-
const temp = `${filePath}.tmp-${process.pid}-${
|
|
2024
|
+
const temp = `${filePath}.tmp-${process.pid}-${randomUUID5()}`;
|
|
1293
2025
|
try {
|
|
1294
|
-
await
|
|
1295
|
-
await
|
|
2026
|
+
await writeFile7(temp, content, { mode: 384 });
|
|
2027
|
+
await rename3(temp, filePath);
|
|
1296
2028
|
} finally {
|
|
1297
|
-
await
|
|
2029
|
+
await unlink2(temp).catch(() => void 0);
|
|
1298
2030
|
}
|
|
1299
2031
|
}
|
|
1300
2032
|
}
|
|
@@ -1349,10 +2081,10 @@ async function ensureRoadmapCache(args) {
|
|
|
1349
2081
|
const { env, projectId } = args;
|
|
1350
2082
|
const identity = repoIdentityToString(args.repoIdentity);
|
|
1351
2083
|
const list = await args.http.get(`/api/projects/${projectId}/roadmaps`);
|
|
1352
|
-
const warn2 = (
|
|
1353
|
-
process.stderr.write(
|
|
2084
|
+
const warn2 = (line2) => {
|
|
2085
|
+
process.stderr.write(line2 + "\n");
|
|
1354
2086
|
};
|
|
1355
|
-
const log = (
|
|
2087
|
+
const log = (line2) => args.log(`roadmap: ${line2}`);
|
|
1356
2088
|
if (list.roadmaps.length > 0) {
|
|
1357
2089
|
let skipped = false;
|
|
1358
2090
|
for (const { slug: slug2 } of list.roadmaps) {
|
|
@@ -1361,7 +2093,7 @@ async function ensureRoadmapCache(args) {
|
|
|
1361
2093
|
if (skipped) throw new CliError("Some roadmaps have local changes that are not synced.", 4);
|
|
1362
2094
|
if (list.roadmaps.some((row) => row.repoIdentity == null || row.repoIdentity === identity)) return;
|
|
1363
2095
|
}
|
|
1364
|
-
const basename =
|
|
2096
|
+
const basename = path12.basename(args.repoRoot);
|
|
1365
2097
|
const slug = args.slug ?? slugifyProjectId(basename);
|
|
1366
2098
|
const collision = list.roadmaps.find((row) => row.slug === slug);
|
|
1367
2099
|
if (collision) 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);
|
|
@@ -1380,9 +2112,9 @@ async function ensureRoadmapCache(args) {
|
|
|
1380
2112
|
await writeCache(env, projectId, slug, roadmap, { repoIdentity: identity, revision: 0, pulledAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
1381
2113
|
const response = await runSync({ ...args, slug, roadmap, baseRevision: 0 }, {
|
|
1382
2114
|
http: args.http,
|
|
1383
|
-
readFile: (p) =>
|
|
2115
|
+
readFile: (p) => readFile9(p, "utf8"),
|
|
1384
2116
|
realpath,
|
|
1385
|
-
fileExists:
|
|
2117
|
+
fileExists: existsSync3,
|
|
1386
2118
|
log: () => void 0,
|
|
1387
2119
|
warn: warn2
|
|
1388
2120
|
});
|
|
@@ -1427,25 +2159,25 @@ async function ensureProjectRepo(args) {
|
|
|
1427
2159
|
// src/commands/link.ts
|
|
1428
2160
|
import readline from "readline/promises";
|
|
1429
2161
|
import os2 from "os";
|
|
1430
|
-
import
|
|
2162
|
+
import path14 from "path";
|
|
1431
2163
|
import { statSync as statSync2 } from "fs";
|
|
1432
2164
|
|
|
1433
2165
|
// src/registry.ts
|
|
1434
|
-
import { readFile as
|
|
1435
|
-
import { randomUUID as
|
|
1436
|
-
import
|
|
2166
|
+
import { readFile as readFile10, writeFile as writeFile8, mkdir as mkdir7, rename as rename4, unlink as unlink3 } from "fs/promises";
|
|
2167
|
+
import { randomUUID as randomUUID6 } from "crypto";
|
|
2168
|
+
import path13 from "path";
|
|
1437
2169
|
import { z as z3 } from "zod";
|
|
1438
2170
|
var registrySchema = z3.object({
|
|
1439
2171
|
schemaVersion: z3.literal(1),
|
|
1440
2172
|
repos: z3.array(z3.object({ root: z3.string().min(1), projectId: z3.string().uuid().optional() }).passthrough())
|
|
1441
2173
|
}).passthrough();
|
|
1442
2174
|
function getRegistryPath(env) {
|
|
1443
|
-
return
|
|
2175
|
+
return path13.join(getConfigDir(env), "registry.json");
|
|
1444
2176
|
}
|
|
1445
2177
|
async function loadRegistry(filePath) {
|
|
1446
2178
|
let raw;
|
|
1447
2179
|
try {
|
|
1448
|
-
raw = await
|
|
2180
|
+
raw = await readFile10(filePath, "utf8");
|
|
1449
2181
|
} catch (err) {
|
|
1450
2182
|
const code = err != null && typeof err === "object" && "code" in err ? err.code : "";
|
|
1451
2183
|
if (code === "ENOENT") {
|
|
@@ -1484,13 +2216,13 @@ async function addRepoToRegistry(filePath, entry) {
|
|
|
1484
2216
|
return { added: !existing, updated: !!existing, registry: updated };
|
|
1485
2217
|
}
|
|
1486
2218
|
async function writeRegistry(filePath, registry) {
|
|
1487
|
-
await
|
|
1488
|
-
const tempPath = `${filePath}.tmp-${process.pid}-${
|
|
2219
|
+
await mkdir7(path13.dirname(filePath), { recursive: true, mode: 448 });
|
|
2220
|
+
const tempPath = `${filePath}.tmp-${process.pid}-${randomUUID6()}`;
|
|
1489
2221
|
try {
|
|
1490
|
-
await
|
|
1491
|
-
await
|
|
2222
|
+
await writeFile8(tempPath, JSON.stringify(registry, null, 2) + "\n", "utf8");
|
|
2223
|
+
await rename4(tempPath, filePath);
|
|
1492
2224
|
} catch (err) {
|
|
1493
|
-
await
|
|
2225
|
+
await unlink3(tempPath).catch(() => void 0);
|
|
1494
2226
|
throw err;
|
|
1495
2227
|
}
|
|
1496
2228
|
}
|
|
@@ -1503,106 +2235,6 @@ async function removeRepoFromRegistry(filePath, root) {
|
|
|
1503
2235
|
return { removed: true, registry: updated };
|
|
1504
2236
|
}
|
|
1505
2237
|
|
|
1506
|
-
// src/repo-identity.ts
|
|
1507
|
-
import { execFile } from "child_process";
|
|
1508
|
-
import { realpathSync } from "fs";
|
|
1509
|
-
import path9 from "path";
|
|
1510
|
-
|
|
1511
|
-
// src/machine-id.ts
|
|
1512
|
-
import { chmod, mkdir as mkdir4, readFile as readFile6, writeFile as writeFile5 } from "fs/promises";
|
|
1513
|
-
import { randomUUID as randomUUID5 } from "crypto";
|
|
1514
|
-
import path8 from "path";
|
|
1515
|
-
var inFlightByConfigDir = /* @__PURE__ */ new Map();
|
|
1516
|
-
function parseMachineId(raw, file) {
|
|
1517
|
-
let parsed;
|
|
1518
|
-
try {
|
|
1519
|
-
parsed = JSON.parse(raw);
|
|
1520
|
-
} catch {
|
|
1521
|
-
throw new CliError(`Malformed JSON in ${file}. Remove the file to regenerate it.`, 2);
|
|
1522
|
-
}
|
|
1523
|
-
const id = parsed?.machineId;
|
|
1524
|
-
if (typeof id !== "string" || id.length === 0) {
|
|
1525
|
-
throw new CliError(`Invalid ${file}: missing machineId. Remove the file to regenerate it.`, 2);
|
|
1526
|
-
}
|
|
1527
|
-
return id;
|
|
1528
|
-
}
|
|
1529
|
-
async function loadOrCreate(configDir) {
|
|
1530
|
-
const file = path8.join(configDir, "machine.json");
|
|
1531
|
-
let raw = null;
|
|
1532
|
-
try {
|
|
1533
|
-
raw = await readFile6(file, "utf8");
|
|
1534
|
-
} catch (err) {
|
|
1535
|
-
const code = err.code;
|
|
1536
|
-
if (code !== "ENOENT") {
|
|
1537
|
-
throw new CliError(`Cannot read ${file}: ${String(err)}`, 2);
|
|
1538
|
-
}
|
|
1539
|
-
}
|
|
1540
|
-
if (raw !== null) {
|
|
1541
|
-
return parseMachineId(raw, file);
|
|
1542
|
-
}
|
|
1543
|
-
const machineId = randomUUID5();
|
|
1544
|
-
await mkdir4(configDir, { recursive: true, mode: 448 });
|
|
1545
|
-
try {
|
|
1546
|
-
await writeFile5(file, `${JSON.stringify({ machineId }, null, 2)}
|
|
1547
|
-
`, {
|
|
1548
|
-
flag: "wx",
|
|
1549
|
-
mode: 384
|
|
1550
|
-
});
|
|
1551
|
-
} catch (err) {
|
|
1552
|
-
if (err.code === "EEXIST") {
|
|
1553
|
-
return parseMachineId(await readFile6(file, "utf8"), file);
|
|
1554
|
-
}
|
|
1555
|
-
throw new CliError(`Cannot write ${file}: ${String(err)}`, 2);
|
|
1556
|
-
}
|
|
1557
|
-
await chmod(file, 384);
|
|
1558
|
-
return machineId;
|
|
1559
|
-
}
|
|
1560
|
-
function loadOrCreateMachineId(configDir) {
|
|
1561
|
-
const key = path8.resolve(configDir);
|
|
1562
|
-
const existing = inFlightByConfigDir.get(key);
|
|
1563
|
-
if (existing !== void 0) return existing;
|
|
1564
|
-
const pending = loadOrCreate(key).finally(() => {
|
|
1565
|
-
if (inFlightByConfigDir.get(key) === pending) inFlightByConfigDir.delete(key);
|
|
1566
|
-
});
|
|
1567
|
-
inFlightByConfigDir.set(key, pending);
|
|
1568
|
-
return pending;
|
|
1569
|
-
}
|
|
1570
|
-
|
|
1571
|
-
// src/repo-identity.ts
|
|
1572
|
-
function defaultGetRemoteUrl(root) {
|
|
1573
|
-
return new Promise((resolve) => {
|
|
1574
|
-
execFile(
|
|
1575
|
-
"git",
|
|
1576
|
-
["-C", root, "remote", "get-url", "origin"],
|
|
1577
|
-
{ timeout: 5e3 },
|
|
1578
|
-
(err, stdout2) => {
|
|
1579
|
-
if (err) return resolve(null);
|
|
1580
|
-
const line = stdout2.split(/\r?\n/)[0]?.trim() ?? "";
|
|
1581
|
-
resolve(line.length > 0 ? line : null);
|
|
1582
|
-
}
|
|
1583
|
-
);
|
|
1584
|
-
});
|
|
1585
|
-
}
|
|
1586
|
-
async function resolveRepoIdentity(root, deps) {
|
|
1587
|
-
const remote = await deps.getRemoteUrl(root);
|
|
1588
|
-
const normalized = remote === null ? null : normalizeRemote(remote);
|
|
1589
|
-
if (normalized !== null) return { kind: "remote", value: normalized };
|
|
1590
|
-
const machineId = await deps.machineId();
|
|
1591
|
-
let canonicalRoot;
|
|
1592
|
-
try {
|
|
1593
|
-
canonicalRoot = realpathSync(root);
|
|
1594
|
-
} catch {
|
|
1595
|
-
canonicalRoot = path9.resolve(root);
|
|
1596
|
-
}
|
|
1597
|
-
return { kind: "local", value: `${machineId}:${canonicalRoot}` };
|
|
1598
|
-
}
|
|
1599
|
-
function makeRepoIdentityResolver(deps) {
|
|
1600
|
-
return deps.repoIdentity ?? ((root) => resolveRepoIdentity(root, {
|
|
1601
|
-
getRemoteUrl: defaultGetRemoteUrl,
|
|
1602
|
-
machineId: () => loadOrCreateMachineId(getConfigDir(process.env))
|
|
1603
|
-
}));
|
|
1604
|
-
}
|
|
1605
|
-
|
|
1606
2238
|
// src/commands/link.ts
|
|
1607
2239
|
var UUID_RE2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
1608
2240
|
function resolveStartDir(env, cwd) {
|
|
@@ -1611,7 +2243,7 @@ function resolveStartDir(env, cwd) {
|
|
|
1611
2243
|
}
|
|
1612
2244
|
function dirHasGit(dir) {
|
|
1613
2245
|
try {
|
|
1614
|
-
statSync2(
|
|
2246
|
+
statSync2(path14.join(dir, ".git"));
|
|
1615
2247
|
return true;
|
|
1616
2248
|
} catch {
|
|
1617
2249
|
return false;
|
|
@@ -1623,14 +2255,14 @@ function findRepoRoot(startDir, hasGit = dirHasGit) {
|
|
|
1623
2255
|
if (hasGit(current)) {
|
|
1624
2256
|
return { root: current, foundGit: true };
|
|
1625
2257
|
}
|
|
1626
|
-
const parent =
|
|
2258
|
+
const parent = path14.dirname(current);
|
|
1627
2259
|
if (parent === current) break;
|
|
1628
2260
|
current = parent;
|
|
1629
2261
|
}
|
|
1630
2262
|
return { root: startDir, foundGit: false };
|
|
1631
2263
|
}
|
|
1632
2264
|
function isHomeDirectory(dir, home = os2.homedir()) {
|
|
1633
|
-
return
|
|
2265
|
+
return path14.resolve(dir) === path14.resolve(home);
|
|
1634
2266
|
}
|
|
1635
2267
|
async function handleShow(deps, projectBindingPath, mode2) {
|
|
1636
2268
|
const startDir = resolveStartDir(process.env, process.cwd());
|
|
@@ -1729,10 +2361,10 @@ async function handleRebind(deps, projectId, root, mode2, yes) {
|
|
|
1729
2361
|
}
|
|
1730
2362
|
}
|
|
1731
2363
|
async function handleUnlink(projectBindingPath, mode2) {
|
|
1732
|
-
const { readFile:
|
|
2364
|
+
const { readFile: readFile19, writeFile: writeFile12, chmod: chmod2 } = await import("fs/promises");
|
|
1733
2365
|
let existing = {};
|
|
1734
2366
|
try {
|
|
1735
|
-
const raw = await
|
|
2367
|
+
const raw = await readFile19(projectBindingPath, "utf8");
|
|
1736
2368
|
const parsed = JSON.parse(raw);
|
|
1737
2369
|
if (parsed == null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
1738
2370
|
throw new CliError(
|
|
@@ -1747,7 +2379,7 @@ async function handleUnlink(projectBindingPath, mode2) {
|
|
|
1747
2379
|
}
|
|
1748
2380
|
const { projectId: _removed, ...rest } = existing;
|
|
1749
2381
|
void _removed;
|
|
1750
|
-
await
|
|
2382
|
+
await writeFile12(projectBindingPath, JSON.stringify(rest, null, 2) + "\n", { mode: 420 });
|
|
1751
2383
|
await chmod2(projectBindingPath, 420);
|
|
1752
2384
|
if (mode2 === "json") {
|
|
1753
2385
|
printResult({ unlinked: true, projectBindingPath }, mode2);
|
|
@@ -1776,7 +2408,7 @@ async function performLink(deps, projectId, mode2, slug, yes = false) {
|
|
|
1776
2408
|
token: deps.settings.token,
|
|
1777
2409
|
version: deps.version
|
|
1778
2410
|
});
|
|
1779
|
-
let projectName =
|
|
2411
|
+
let projectName = path14.basename(root);
|
|
1780
2412
|
if (deps.settings.token != null) {
|
|
1781
2413
|
try {
|
|
1782
2414
|
const result = await http.get(
|
|
@@ -1804,7 +2436,7 @@ Proceeding anyway \u2014 verify the ID is correct.
|
|
|
1804
2436
|
);
|
|
1805
2437
|
}
|
|
1806
2438
|
await writeRepoBinding(root, projectId);
|
|
1807
|
-
const writtenPath =
|
|
2439
|
+
const writtenPath = path14.join(root, "nolto.json");
|
|
1808
2440
|
let repoAdded = false;
|
|
1809
2441
|
if (deps.settings.token == null) {
|
|
1810
2442
|
process.stderr.write("Warning: roadmap cache not initialized (no token); run nolto pull after nolto login\n");
|
|
@@ -1825,8 +2457,8 @@ Proceeding anyway \u2014 verify the ID is correct.
|
|
|
1825
2457
|
rl.close();
|
|
1826
2458
|
}
|
|
1827
2459
|
},
|
|
1828
|
-
log: (
|
|
1829
|
-
if (mode2 !== "json") process.stdout.write(
|
|
2460
|
+
log: (line2) => {
|
|
2461
|
+
if (mode2 !== "json") process.stdout.write(line2 + "\n");
|
|
1830
2462
|
}
|
|
1831
2463
|
});
|
|
1832
2464
|
if (result === "declined") {
|
|
@@ -1842,8 +2474,8 @@ Proceeding anyway \u2014 verify the ID is correct.
|
|
|
1842
2474
|
repoRoot: root,
|
|
1843
2475
|
slug,
|
|
1844
2476
|
repoIdentity,
|
|
1845
|
-
log: (
|
|
1846
|
-
if (mode2 !== "json") process.stdout.write(
|
|
2477
|
+
log: (line2) => {
|
|
2478
|
+
if (mode2 !== "json") process.stdout.write(line2 + "\n");
|
|
1847
2479
|
}
|
|
1848
2480
|
});
|
|
1849
2481
|
}
|
|
@@ -1987,79 +2619,14 @@ function invalidBindingError(projectBindingPath, error) {
|
|
|
1987
2619
|
);
|
|
1988
2620
|
}
|
|
1989
2621
|
|
|
1990
|
-
// src/skill-install.ts
|
|
1991
|
-
import { cp, mkdir as mkdir5, readFile as readFile7, writeFile as writeFile6, rm as rm2 } from "fs/promises";
|
|
1992
|
-
import { existsSync as existsSync2 } from "fs";
|
|
1993
|
-
import path11 from "path";
|
|
1994
|
-
import { fileURLToPath } from "url";
|
|
1995
|
-
var __dirname = path11.dirname(fileURLToPath(import.meta.url));
|
|
1996
|
-
function resolveSkillSourceDir() {
|
|
1997
|
-
const candidates = [
|
|
1998
|
-
path11.resolve(__dirname, "skill/roadmap-progress"),
|
|
1999
|
-
// bundled: dist/skill/...
|
|
2000
|
-
path11.resolve(__dirname, "../../../skills/roadmap-progress")
|
|
2001
|
-
// source: <repo>/skills/...
|
|
2002
|
-
];
|
|
2003
|
-
for (const candidate of candidates) {
|
|
2004
|
-
if (existsSync2(path11.join(candidate, "SKILL.md"))) return candidate;
|
|
2005
|
-
}
|
|
2006
|
-
throw new Error("Bundled roadmap-progress skill not found. Reinstall @nolto/cli.");
|
|
2007
|
-
}
|
|
2008
|
-
var VERSION_MARKER = ".nolto-skill-version";
|
|
2009
|
-
async function checkSkillVersionDrift(repoRoot, cliVersion) {
|
|
2010
|
-
const skillDirs = [
|
|
2011
|
-
path11.join(repoRoot, ".claude", "skills", "roadmap-progress"),
|
|
2012
|
-
path11.join(repoRoot, ".agents", "skills", "roadmap-progress")
|
|
2013
|
-
];
|
|
2014
|
-
const drifted = [];
|
|
2015
|
-
for (const dir of skillDirs) {
|
|
2016
|
-
if (!existsSync2(dir)) continue;
|
|
2017
|
-
let installed;
|
|
2018
|
-
try {
|
|
2019
|
-
const marker = (await readFile7(path11.join(dir, VERSION_MARKER), "utf8")).trim();
|
|
2020
|
-
installed = marker.length > 0 ? marker : null;
|
|
2021
|
-
} catch {
|
|
2022
|
-
installed = null;
|
|
2023
|
-
}
|
|
2024
|
-
if (installed !== cliVersion) drifted.push({ dir, installed });
|
|
2025
|
-
}
|
|
2026
|
-
return drifted;
|
|
2027
|
-
}
|
|
2028
|
-
function formatSkillVersionDriftWarning(repoRoot, cliVersion, drifted) {
|
|
2029
|
-
const dirs = drifted.map(({ dir }) => path11.relative(repoRoot, dir).split(path11.sep).join("/")).join(", ");
|
|
2030
|
-
const installed = [...new Set(drifted.map((entry) => entry.installed ?? "unknown"))].join(", ");
|
|
2031
|
-
return `roadmap-progress skill is outdated in ${dirs} (installed ${installed}, CLI ${cliVersion}). Run \`nolto init\` in this repo to update it.`;
|
|
2032
|
-
}
|
|
2033
|
-
async function installSkill(args) {
|
|
2034
|
-
const targetDir = path11.join(args.skillsParentDir, "roadmap-progress");
|
|
2035
|
-
const markerPath = path11.join(targetDir, VERSION_MARKER);
|
|
2036
|
-
const dirExists = existsSync2(targetDir);
|
|
2037
|
-
let installedVersion = null;
|
|
2038
|
-
if (dirExists) {
|
|
2039
|
-
try {
|
|
2040
|
-
installedVersion = (await readFile7(markerPath, "utf8")).trim();
|
|
2041
|
-
} catch {
|
|
2042
|
-
installedVersion = null;
|
|
2043
|
-
}
|
|
2044
|
-
}
|
|
2045
|
-
if (dirExists && installedVersion === args.version && args.force !== true) {
|
|
2046
|
-
return { action: "skipped", targetDir };
|
|
2047
|
-
}
|
|
2048
|
-
await rm2(targetDir, { recursive: true, force: true });
|
|
2049
|
-
await mkdir5(args.skillsParentDir, { recursive: true });
|
|
2050
|
-
await cp(args.sourceDir, targetDir, { recursive: true });
|
|
2051
|
-
await writeFile6(markerPath, args.version + "\n", "utf8");
|
|
2052
|
-
return { action: dirExists ? "updated" : "installed", targetDir };
|
|
2053
|
-
}
|
|
2054
|
-
|
|
2055
2622
|
// src/commands/init.ts
|
|
2056
|
-
var __dirname2 =
|
|
2623
|
+
var __dirname2 = path15.dirname(fileURLToPath2(import.meta.url));
|
|
2057
2624
|
var _require = createRequire(import.meta.url);
|
|
2058
2625
|
function getCliVersion() {
|
|
2059
2626
|
const candidates = [
|
|
2060
|
-
|
|
2627
|
+
path15.resolve(__dirname2, "../package.json"),
|
|
2061
2628
|
// bundled: dist/../package.json
|
|
2062
|
-
|
|
2629
|
+
path15.resolve(__dirname2, "../../package.json")
|
|
2063
2630
|
// source: src/commands/../../package.json
|
|
2064
2631
|
];
|
|
2065
2632
|
for (const pkgPath of candidates) {
|
|
@@ -2147,8 +2714,91 @@ async function selectRepoProject(rl, http, projects, defaultProjectId, baseUrl)
|
|
|
2147
2714
|
baseUrl
|
|
2148
2715
|
);
|
|
2149
2716
|
}
|
|
2717
|
+
async function setupMemory(opts) {
|
|
2718
|
+
const { rl, root, projectId, http, deps, memory } = opts;
|
|
2719
|
+
if (memory === false) return;
|
|
2720
|
+
const agents = detectMemoryAgents(root);
|
|
2721
|
+
const scan = deps.claudeProjectsDir ? await scanMemoryDir(claudeMemoryDir(root, deps.claudeProjectsDir)).catch((error) => {
|
|
2722
|
+
if (error.code === "ENOENT") return { ok: [], invalid: [] };
|
|
2723
|
+
throw error;
|
|
2724
|
+
}) : { ok: [], invalid: [] };
|
|
2725
|
+
if (!scan.ok.length && !scan.invalid.length && (await Promise.all(agents.map((agent) => hasMemoryHook(root, agent)))).every(Boolean)) {
|
|
2726
|
+
process.stdout.write(`memory: \u8A2D\u5B9A\u6E08\u307F(hook ${agents.join(", ")})
|
|
2727
|
+
`);
|
|
2728
|
+
return;
|
|
2729
|
+
}
|
|
2730
|
+
if (memory !== true && (await rl.question("\u3053\u306E\u30EA\u30DD\u30B8\u30C8\u30EA\u306E\u30E1\u30E2\u30EA\u3092 Nolto \u3067\u7BA1\u7406\u3057\u307E\u3059\u304B? [Y/n] ")).trim().toLowerCase() === "n") {
|
|
2731
|
+
process.stdout.write("\u5F8C\u304B\u3089\u8A2D\u5B9A\u3059\u308B\u306B\u306F nolto memory hook install\n");
|
|
2732
|
+
return;
|
|
2733
|
+
}
|
|
2734
|
+
for (const message of await installMemoryHooks(root)) process.stdout.write(`memory: ${message}
|
|
2735
|
+
`);
|
|
2736
|
+
if (scan.invalid.length) {
|
|
2737
|
+
process.stdout.write(`\u53D6\u308A\u8FBC\u3081\u306A\u3044\u30E1\u30E2\u30EA ${scan.invalid.length} \u4EF6(\u672C\u6587\u3092\u5206\u3051\u308B\u304B\u8981\u70B9\u306B\u7D5E\u3063\u3066\u304B\u3089 nolto memory put \u3067\u767B\u9332\u3057\u3066\u304F\u3060\u3055\u3044):
|
|
2738
|
+
`);
|
|
2739
|
+
for (const invalid of scan.invalid) process.stdout.write(` - ${oneLine(invalid.file)} \u2014 ${oneLine(invalid.message)}
|
|
2740
|
+
`);
|
|
2741
|
+
}
|
|
2742
|
+
const ask = async (prompt) => memory === true && !process.stdin.isTTY ? "" : (await rl.question(prompt)).trim().toLowerCase();
|
|
2743
|
+
if (scan.ok.length) {
|
|
2744
|
+
const users = scan.ok.filter((target) => target.draft.type === "user").length;
|
|
2745
|
+
process.stdout.write(`Claude Code \u306E\u30E1\u30E2\u30EA\u304C ${scan.ok.length} \u4EF6\u3042\u308A\u307E\u3059(type user ${users} \u4EF6\u3001\u305D\u308C\u4EE5\u5916 ${scan.ok.length - users} \u4EF6)\u3002
|
|
2746
|
+
`);
|
|
2747
|
+
const choice = await ask("\u53D6\u308A\u8FBC\u307F\u307E\u3059\u304B? [a] type \u3067\u632F\u308A\u5206\u3051(user \u2192 user\u3001\u4ED6 \u2192 project) / [p] \u3059\u3079\u3066 project / [u] \u3059\u3079\u3066 user / [n] \u53D6\u308A\u8FBC\u307E\u306A\u3044 [a] ");
|
|
2748
|
+
if (choice !== "n") {
|
|
2749
|
+
const git = await memoryGitContext(root, deps);
|
|
2750
|
+
let imported = 0, skipped = 0, failed = 0, cached = true;
|
|
2751
|
+
for (const scope of ["project", "user"]) {
|
|
2752
|
+
const targets = scan.ok.filter((target) => (choice === "p" ? "project" : choice === "u" ? "user" : target.draft.type === "user" ? "user" : "project") === scope);
|
|
2753
|
+
if (!targets.length) continue;
|
|
2754
|
+
const result2 = await importMemoryFiles({
|
|
2755
|
+
http,
|
|
2756
|
+
projectId,
|
|
2757
|
+
configPath: deps.configPath,
|
|
2758
|
+
root,
|
|
2759
|
+
scope,
|
|
2760
|
+
targets,
|
|
2761
|
+
git,
|
|
2762
|
+
memoryGit: deps.memoryGit,
|
|
2763
|
+
write: (line2) => {
|
|
2764
|
+
process.stdout.write(line2 + "\n");
|
|
2765
|
+
}
|
|
2766
|
+
});
|
|
2767
|
+
imported += result2.imported;
|
|
2768
|
+
skipped += result2.skipped;
|
|
2769
|
+
failed += result2.failed;
|
|
2770
|
+
cached = result2.cached && cached;
|
|
2771
|
+
}
|
|
2772
|
+
process.stdout.write(`imported ${imported}, skipped ${skipped}, failed ${failed}
|
|
2773
|
+
`);
|
|
2774
|
+
if (!cached) process.stderr.write(cacheWarning);
|
|
2775
|
+
}
|
|
2776
|
+
}
|
|
2777
|
+
if (!agents.includes("claude")) return;
|
|
2778
|
+
const file = path15.join(root, ".claude", "settings.local.json");
|
|
2779
|
+
let settings = {};
|
|
2780
|
+
try {
|
|
2781
|
+
settings = JSON.parse(await readFile11(file, "utf8"));
|
|
2782
|
+
} catch (error) {
|
|
2783
|
+
if (error.code !== "ENOENT") {
|
|
2784
|
+
process.stderr.write(`Warning: ${file} \u3092\u8AAD\u3081\u306A\u3044\u305F\u3081\u3001\u81EA\u52D5\u30E1\u30E2\u30EA\u306E\u8A2D\u5B9A\u3092\u7701\u7565\u3057\u307E\u3057\u305F\u3002
|
|
2785
|
+
`);
|
|
2786
|
+
return;
|
|
2787
|
+
}
|
|
2788
|
+
}
|
|
2789
|
+
if (settings && typeof settings === "object" && !Array.isArray(settings) && "autoMemoryEnabled" in settings && settings.autoMemoryEnabled === false) {
|
|
2790
|
+
process.stdout.write("memory: Claude Code \u306E\u81EA\u52D5\u30E1\u30E2\u30EA\u505C\u6B62\u306F\u8A2D\u5B9A\u6E08\u307F\n");
|
|
2791
|
+
return;
|
|
2792
|
+
}
|
|
2793
|
+
if (await ask("Claude Code \u306E\u81EA\u52D5\u30E1\u30E2\u30EA\u3092\u6B62\u3081\u307E\u3059\u304B(Nolto \u3068\u306E\u4E8C\u91CD\u7BA1\u7406\u3092\u907F\u3051\u307E\u3059)? .claude/settings.local.json \u306B autoMemoryEnabled: false \u3092\u66F8\u304D\u307E\u3059 [Y/n] ") === "n") return;
|
|
2794
|
+
const result = await disableClaudeAutoMemory(root);
|
|
2795
|
+
if (result === "invalid") process.stderr.write(`Warning: ${file} \u304C\u4E0D\u6B63\u306A\u305F\u3081\u3001\u81EA\u52D5\u30E1\u30E2\u30EA\u306E\u8A2D\u5B9A\u3092\u7701\u7565\u3057\u307E\u3057\u305F\u3002
|
|
2796
|
+
`);
|
|
2797
|
+
else process.stdout.write(`memory: Claude Code \u306E\u81EA\u52D5\u30E1\u30E2\u30EA\u505C\u6B62${result === "already" ? "\u306F\u8A2D\u5B9A\u6E08\u307F" : "\u3092\u8A2D\u5B9A\u3057\u307E\u3057\u305F"}
|
|
2798
|
+
`);
|
|
2799
|
+
}
|
|
2150
2800
|
function register3(program, deps) {
|
|
2151
|
-
program.command("init").description("Interactive setup: configure token, base URL, and default project.").option("--force", "Overwrite existing config without prompting").action(async (opts) => {
|
|
2801
|
+
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) => {
|
|
2152
2802
|
const configPath = deps.configPath;
|
|
2153
2803
|
const rl = readline2.createInterface({ input: process.stdin, output: process.stdout });
|
|
2154
2804
|
try {
|
|
@@ -2240,7 +2890,7 @@ Saved ${configPath}
|
|
|
2240
2890
|
}
|
|
2241
2891
|
if (isHomeDirectory(root)) {
|
|
2242
2892
|
process.stderr.write(
|
|
2243
|
-
`Refusing to set up your home directory as a repository root (found ${
|
|
2893
|
+
`Refusing to set up your home directory as a repository root (found ${path15.join(os3.homedir(), ".git")}). Run nolto init inside a project repository.
|
|
2244
2894
|
`
|
|
2245
2895
|
);
|
|
2246
2896
|
return;
|
|
@@ -2272,7 +2922,7 @@ Saved ${configPath}
|
|
|
2272
2922
|
boundProject != null ? "Keep this binding? [Y/n] " : "Keep this binding? [y/N] "
|
|
2273
2923
|
);
|
|
2274
2924
|
keepExistingBinding = boundProject != null ? keep.trim().toLowerCase() !== "n" : keep.trim().toLowerCase() === "y";
|
|
2275
|
-
repoProject = keepExistingBinding ? boundProject ?? { id: existingBinding.projectId, name:
|
|
2925
|
+
repoProject = keepExistingBinding ? boundProject ?? { id: existingBinding.projectId, name: path15.basename(root) } : await selectRepoProject(rl, repoHttp, projects, defaultProjectId, baseUrl);
|
|
2276
2926
|
} else {
|
|
2277
2927
|
repoProject = await selectRepoProject(rl, repoHttp, projects, defaultProjectId, baseUrl);
|
|
2278
2928
|
}
|
|
@@ -2286,7 +2936,7 @@ Set up this repository (${root}) for roadmap sync? [Y/n] `);
|
|
|
2286
2936
|
process.stdout.write("Skipped repo setup.\n");
|
|
2287
2937
|
return;
|
|
2288
2938
|
}
|
|
2289
|
-
const bindingPath = deps.repoBinding?.path ??
|
|
2939
|
+
const bindingPath = deps.repoBinding?.path ?? path15.join(root, "nolto.json");
|
|
2290
2940
|
if (keepExistingBinding) {
|
|
2291
2941
|
process.stdout.write(`binding: kept ${bindingPath} (${repoProject.id})
|
|
2292
2942
|
`);
|
|
@@ -2298,28 +2948,30 @@ Set up this repository (${root}) for roadmap sync? [Y/n] `);
|
|
|
2298
2948
|
);
|
|
2299
2949
|
}
|
|
2300
2950
|
await writeRepoBinding(root, repoProject.id);
|
|
2301
|
-
process.stdout.write(`binding: wrote ${
|
|
2951
|
+
process.stdout.write(`binding: wrote ${path15.join(root, "nolto.json")}
|
|
2302
2952
|
`);
|
|
2303
2953
|
}
|
|
2304
2954
|
const sourceDir = resolveSkillSourceDir();
|
|
2305
|
-
const version = getCliVersion();
|
|
2306
2955
|
const claudeInstall = await installSkill({
|
|
2307
|
-
skillsParentDir:
|
|
2308
|
-
sourceDir
|
|
2309
|
-
version
|
|
2956
|
+
skillsParentDir: path15.join(root, ".claude", "skills"),
|
|
2957
|
+
sourceDir
|
|
2310
2958
|
});
|
|
2311
2959
|
process.stdout.write(`skill (claude): ${claudeInstall.action} ${claudeInstall.targetDir}
|
|
2312
2960
|
`);
|
|
2313
|
-
const usesAgentsTooling = fs2.existsSync(
|
|
2961
|
+
const usesAgentsTooling = fs2.existsSync(path15.join(root, ".agents")) || fs2.existsSync(path15.join(root, ".codex")) || fs2.existsSync(path15.join(root, "AGENTS.md"));
|
|
2314
2962
|
if (usesAgentsTooling) {
|
|
2315
2963
|
const agentsInstall = await installSkill({
|
|
2316
|
-
skillsParentDir:
|
|
2317
|
-
sourceDir
|
|
2318
|
-
version
|
|
2964
|
+
skillsParentDir: path15.join(root, ".agents", "skills"),
|
|
2965
|
+
sourceDir
|
|
2319
2966
|
});
|
|
2320
2967
|
process.stdout.write(`skill (agents): ${agentsInstall.action} ${agentsInstall.targetDir}
|
|
2321
2968
|
`);
|
|
2322
2969
|
}
|
|
2970
|
+
for (const memorySkill of await installMemorySkill(root)) {
|
|
2971
|
+
process.stdout.write(`skill (memory): ${memorySkill.action} ${memorySkill.targetDir}
|
|
2972
|
+
`);
|
|
2973
|
+
}
|
|
2974
|
+
await setupMemory({ rl, root, projectId: repoProject.id, http: repoHttp, deps, memory: opts.memory });
|
|
2323
2975
|
const repoIdentity = await makeRepoIdentityResolver(deps)(root);
|
|
2324
2976
|
const repoResult = await ensureProjectRepo({
|
|
2325
2977
|
http: repoHttp,
|
|
@@ -2329,8 +2981,8 @@ Set up this repository (${root}) for roadmap sync? [Y/n] `);
|
|
|
2329
2981
|
const answer = (await rl.question(question)).trim().toLowerCase();
|
|
2330
2982
|
return answer === "" || answer === "y" || answer === "yes";
|
|
2331
2983
|
},
|
|
2332
|
-
log: (
|
|
2333
|
-
process.stdout.write(
|
|
2984
|
+
log: (line2) => {
|
|
2985
|
+
process.stdout.write(line2 + "\n");
|
|
2334
2986
|
}
|
|
2335
2987
|
});
|
|
2336
2988
|
if (repoResult === "declined") {
|
|
@@ -2344,8 +2996,8 @@ Set up this repository (${root}) for roadmap sync? [Y/n] `);
|
|
|
2344
2996
|
projectName: repoProject.name,
|
|
2345
2997
|
repoRoot: root,
|
|
2346
2998
|
repoIdentity,
|
|
2347
|
-
log: (
|
|
2348
|
-
process.stdout.write(
|
|
2999
|
+
log: (line2) => {
|
|
3000
|
+
process.stdout.write(line2 + "\n");
|
|
2349
3001
|
}
|
|
2350
3002
|
});
|
|
2351
3003
|
const registryResult = await addRepoToRegistry(getRegistryPath(process.env), { root, projectId: repoProject.id });
|
|
@@ -2589,13 +3241,13 @@ function register5(program, deps) {
|
|
|
2589
3241
|
}
|
|
2590
3242
|
|
|
2591
3243
|
// src/commands/sync.ts
|
|
2592
|
-
import { execFile as
|
|
2593
|
-
import { promisify } from "util";
|
|
2594
|
-
import { readFile as
|
|
2595
|
-
import { existsSync as
|
|
3244
|
+
import { execFile as execFile3 } from "child_process";
|
|
3245
|
+
import { promisify as promisify2 } from "util";
|
|
3246
|
+
import { readFile as readFile12, realpath as realpath2 } from "fs/promises";
|
|
3247
|
+
import { existsSync as existsSync4 } from "fs";
|
|
2596
3248
|
|
|
2597
3249
|
// src/roadmap-read.ts
|
|
2598
|
-
import
|
|
3250
|
+
import path16 from "path";
|
|
2599
3251
|
async function resolveRoadmapReadContext(deps) {
|
|
2600
3252
|
if (deps.settings.token == null) {
|
|
2601
3253
|
throw new CliError("Not authenticated. Run `nolto login` or set NOLTO_TOKEN.", 3);
|
|
@@ -2605,7 +3257,7 @@ async function resolveRoadmapReadContext(deps) {
|
|
|
2605
3257
|
if (!foundGit) {
|
|
2606
3258
|
throw new CliError("No git repository found. Run inside a repo set up with `nolto init`.", 2);
|
|
2607
3259
|
}
|
|
2608
|
-
const binding = await loadRepoBinding(
|
|
3260
|
+
const binding = await loadRepoBinding(path16.join(root, "nolto.json"));
|
|
2609
3261
|
const projectId = binding?.projectId ?? deps.settings.defaultProjectId;
|
|
2610
3262
|
if (projectId == null) {
|
|
2611
3263
|
throw new CliError("No project binding. Run `nolto init` or `nolto link <projectId>`.", 2);
|
|
@@ -2615,8 +3267,8 @@ async function resolveRoadmapReadContext(deps) {
|
|
|
2615
3267
|
|
|
2616
3268
|
// src/git-links.ts
|
|
2617
3269
|
function parseGitLog(raw) {
|
|
2618
|
-
return raw.split("\n").filter((
|
|
2619
|
-
const fields =
|
|
3270
|
+
return raw.split("\n").filter((line2) => line2.length > 0).map((line2) => {
|
|
3271
|
+
const fields = line2.replace(/\r$/, "").split("");
|
|
2620
3272
|
const [ref, subject, author, committedAt] = fields;
|
|
2621
3273
|
if (fields.length !== 4 || !ref || !/^[0-9a-f]{40}$/.test(ref) || subject === void 0 || author === void 0 || !committedAt || !Number.isFinite(Date.parse(committedAt))) {
|
|
2622
3274
|
throw new Error("Malformed git log entry");
|
|
@@ -2661,15 +3313,15 @@ async function collectGitLinks(root, exec) {
|
|
|
2661
3313
|
}
|
|
2662
3314
|
|
|
2663
3315
|
// src/sync-repo.ts
|
|
2664
|
-
import
|
|
2665
|
-
import { readdir as
|
|
3316
|
+
import path17 from "path";
|
|
3317
|
+
import { readdir as readdir5 } from "fs/promises";
|
|
2666
3318
|
function collectContainedPlanAbsPaths(roadmaps, root, warn2) {
|
|
2667
3319
|
const planAbsPaths = /* @__PURE__ */ new Set();
|
|
2668
|
-
const resolvedRoot =
|
|
3320
|
+
const resolvedRoot = path17.resolve(root);
|
|
2669
3321
|
for (const roadmap of roadmaps) {
|
|
2670
3322
|
for (const ref of collectPlanRefs(roadmap)) {
|
|
2671
|
-
const absolute =
|
|
2672
|
-
if (absolute !== resolvedRoot && !absolute.startsWith(resolvedRoot +
|
|
3323
|
+
const absolute = path17.resolve(resolvedRoot, ref.path);
|
|
3324
|
+
if (absolute !== resolvedRoot && !absolute.startsWith(resolvedRoot + path17.sep)) {
|
|
2673
3325
|
warn2(`chokidar target outside repo, skipping: ${ref.path}`);
|
|
2674
3326
|
continue;
|
|
2675
3327
|
}
|
|
@@ -2690,7 +3342,7 @@ async function syncRepo(args, io) {
|
|
|
2690
3342
|
if (slugs.length === 0) {
|
|
2691
3343
|
let legacyFiles = [];
|
|
2692
3344
|
try {
|
|
2693
|
-
legacyFiles = await
|
|
3345
|
+
legacyFiles = await readdir5(path17.join(args.root, ".nolto", "roadmaps"));
|
|
2694
3346
|
} catch (err) {
|
|
2695
3347
|
if (err.code !== "ENOENT") throw err;
|
|
2696
3348
|
}
|
|
@@ -2790,31 +3442,29 @@ function register6(program, deps) {
|
|
|
2790
3442
|
async function runSyncCommand(deps, opts = {}) {
|
|
2791
3443
|
const { root, projectId } = await resolveRoadmapReadContext(deps);
|
|
2792
3444
|
const http = deps.http;
|
|
2793
|
-
const warn2 = (
|
|
2794
|
-
process.stderr.write((
|
|
3445
|
+
const warn2 = (line2) => {
|
|
3446
|
+
process.stderr.write((line2.startsWith(" ") ? "" : "Warning: ") + line2 + "\n");
|
|
2795
3447
|
};
|
|
2796
3448
|
const response = await syncRepo(
|
|
2797
3449
|
{ root, projectId, slugs: opts.slug === void 0 ? void 0 : [opts.slug] },
|
|
2798
3450
|
{
|
|
2799
3451
|
env: process.env,
|
|
2800
|
-
readFile: (p) =>
|
|
3452
|
+
readFile: (p) => readFile12(p, "utf8"),
|
|
2801
3453
|
realpath: (p) => realpath2(p),
|
|
2802
|
-
fileExists: (p) =>
|
|
3454
|
+
fileExists: (p) => existsSync4(p),
|
|
2803
3455
|
repoIdentity: makeRepoIdentityResolver(deps),
|
|
2804
|
-
exec:
|
|
3456
|
+
exec: promisify2(execFile3),
|
|
2805
3457
|
gitLinks: (opts.gitLinks ?? true) && process.env.NOLTO_GIT_LINKS !== "0",
|
|
2806
3458
|
http,
|
|
2807
|
-
log: (
|
|
2808
|
-
if (!opts.quiet && deps.output.mode !== "json") process.stdout.write(
|
|
3459
|
+
log: (line2) => {
|
|
3460
|
+
if (!opts.quiet && deps.output.mode !== "json") process.stdout.write(line2 + "\n");
|
|
2809
3461
|
},
|
|
2810
3462
|
warn: warn2
|
|
2811
3463
|
}
|
|
2812
3464
|
);
|
|
2813
3465
|
try {
|
|
2814
|
-
const drifted = await
|
|
2815
|
-
|
|
2816
|
-
warn2(formatSkillVersionDriftWarning(root, deps.version, drifted));
|
|
2817
|
-
}
|
|
3466
|
+
const drifted = await checkSkillDrift(root, { homeSkillDirs: deps.homeSkillDirs });
|
|
3467
|
+
for (const warning of drifted) warn2(warning);
|
|
2818
3468
|
} catch {
|
|
2819
3469
|
}
|
|
2820
3470
|
let registryAdded = false;
|
|
@@ -3010,11 +3660,15 @@ function register7(program, deps) {
|
|
|
3010
3660
|
});
|
|
3011
3661
|
}
|
|
3012
3662
|
|
|
3663
|
+
// src/commands/roadmap.ts
|
|
3664
|
+
import { readFile as readFile14 } from "fs/promises";
|
|
3665
|
+
import { existsSync as existsSync6 } from "fs";
|
|
3666
|
+
|
|
3013
3667
|
// src/roadmap-commands.ts
|
|
3014
|
-
import
|
|
3015
|
-
import { existsSync as
|
|
3016
|
-
import { readFile as
|
|
3017
|
-
import { randomUUID as
|
|
3668
|
+
import path18 from "path";
|
|
3669
|
+
import { existsSync as existsSync5 } from "fs";
|
|
3670
|
+
import { readFile as readFile13, readdir as readdir6, writeFile as writeFile9, rename as rename5, unlink as unlink4, realpath as realpath3 } from "fs/promises";
|
|
3671
|
+
import { randomUUID as randomUUID7 } from "crypto";
|
|
3018
3672
|
import readline4 from "readline/promises";
|
|
3019
3673
|
|
|
3020
3674
|
// src/commands/pull.ts
|
|
@@ -3040,12 +3694,12 @@ async function runPull(deps, opts = {}) {
|
|
|
3040
3694
|
projectId,
|
|
3041
3695
|
slug,
|
|
3042
3696
|
force: opts.force,
|
|
3043
|
-
log: (
|
|
3044
|
-
messages.push(
|
|
3045
|
-
if (!opts.quiet && deps.output.mode !== "json") process.stdout.write(
|
|
3697
|
+
log: (line2) => {
|
|
3698
|
+
messages.push(line2);
|
|
3699
|
+
if (!opts.quiet && deps.output.mode !== "json") process.stdout.write(line2 + "\n");
|
|
3046
3700
|
},
|
|
3047
|
-
warn: (
|
|
3048
|
-
process.stderr.write(
|
|
3701
|
+
warn: (line2) => {
|
|
3702
|
+
process.stderr.write(line2 + "\n");
|
|
3049
3703
|
}
|
|
3050
3704
|
})) skipped = true;
|
|
3051
3705
|
}
|
|
@@ -3054,8 +3708,8 @@ async function runPull(deps, opts = {}) {
|
|
|
3054
3708
|
}
|
|
3055
3709
|
|
|
3056
3710
|
// src/roadmap-commands.ts
|
|
3057
|
-
var warn = (
|
|
3058
|
-
process.stderr.write(
|
|
3711
|
+
var warn = (line2) => {
|
|
3712
|
+
process.stderr.write(line2 + "\n");
|
|
3059
3713
|
};
|
|
3060
3714
|
async function pull(deps, projectId, slug) {
|
|
3061
3715
|
if (!await pullRoadmapCache({ env: process.env, http: deps.http, projectId, slug, log: () => void 0, warn })) {
|
|
@@ -3063,26 +3717,26 @@ async function pull(deps, projectId, slug) {
|
|
|
3063
3717
|
}
|
|
3064
3718
|
}
|
|
3065
3719
|
async function selectRoadmap(deps, requestedSlug) {
|
|
3066
|
-
const
|
|
3720
|
+
const context3 = await resolveRoadmapReadContext(deps);
|
|
3067
3721
|
let slug = requestedSlug;
|
|
3068
3722
|
if (slug === void 0) {
|
|
3069
|
-
let slugs = await listCachedSlugs(process.env,
|
|
3723
|
+
let slugs = await listCachedSlugs(process.env, context3.projectId);
|
|
3070
3724
|
if (slugs.length === 0) {
|
|
3071
3725
|
await runPull(deps, { quiet: true });
|
|
3072
|
-
slugs = await listCachedSlugs(process.env,
|
|
3726
|
+
slugs = await listCachedSlugs(process.env, context3.projectId);
|
|
3073
3727
|
}
|
|
3074
3728
|
if (slugs.length !== 1) {
|
|
3075
3729
|
throw new CliError(slugs.length === 0 ? "No roadmap found. Run `nolto init`." : `Multiple roadmaps found (${slugs.join(", ")}); specify a slug (task commands: --slug <slug>).`, 2);
|
|
3076
3730
|
}
|
|
3077
3731
|
slug = slugs[0];
|
|
3078
3732
|
}
|
|
3079
|
-
const paths = cachePaths(process.env,
|
|
3080
|
-
if (!
|
|
3081
|
-
return { ...
|
|
3733
|
+
const paths = cachePaths(process.env, context3.projectId, slug);
|
|
3734
|
+
if (!existsSync5(paths.json)) await pull(deps, context3.projectId, slug);
|
|
3735
|
+
return { ...context3, slug, paths };
|
|
3082
3736
|
}
|
|
3083
3737
|
async function roadmapPath(deps, slug) {
|
|
3084
3738
|
const { paths } = await selectRoadmap(deps, slug);
|
|
3085
|
-
printResult(
|
|
3739
|
+
printResult(path18.resolve(paths.json), deps.output.mode);
|
|
3086
3740
|
}
|
|
3087
3741
|
async function roadmapStatus(deps, slug, fresh = false) {
|
|
3088
3742
|
const selected = await selectRoadmap(deps, slug);
|
|
@@ -3111,7 +3765,7 @@ async function roadmapValidate(deps, slug) {
|
|
|
3111
3765
|
const { paths } = await selectRoadmap(deps, slug);
|
|
3112
3766
|
let parsed;
|
|
3113
3767
|
try {
|
|
3114
|
-
parsed = JSON.parse(await
|
|
3768
|
+
parsed = JSON.parse(await readFile13(paths.json, "utf8"));
|
|
3115
3769
|
} catch {
|
|
3116
3770
|
throw new CliError(`ERROR Malformed JSON in ${paths.json}.`, 1);
|
|
3117
3771
|
}
|
|
@@ -3127,12 +3781,12 @@ async function roadmapSummary(deps, slug, text) {
|
|
|
3127
3781
|
const selected = await selectRoadmap(deps, slug);
|
|
3128
3782
|
const entry = await readCache(process.env, selected.projectId, selected.slug);
|
|
3129
3783
|
entry.roadmap.summary = text;
|
|
3130
|
-
const temp = `${selected.paths.json}.tmp-${
|
|
3784
|
+
const temp = `${selected.paths.json}.tmp-${randomUUID7()}`;
|
|
3131
3785
|
try {
|
|
3132
|
-
await
|
|
3133
|
-
await
|
|
3786
|
+
await writeFile9(temp, serializeRoadmap(entry.roadmap), { mode: 384 });
|
|
3787
|
+
await rename5(temp, selected.paths.json);
|
|
3134
3788
|
} finally {
|
|
3135
|
-
await
|
|
3789
|
+
await unlink4(temp).catch(() => void 0);
|
|
3136
3790
|
}
|
|
3137
3791
|
await runSyncCommand(deps, { slug: selected.slug });
|
|
3138
3792
|
}
|
|
@@ -3161,11 +3815,11 @@ async function roadmapTask(deps, taskId, slug, body) {
|
|
|
3161
3815
|
const selected = await selectRoadmap(deps, slug);
|
|
3162
3816
|
if (body.status === "blocked" && !body.note?.trim()) throw new CliError("block requires a non-empty --note.", 2);
|
|
3163
3817
|
if (body.plan !== void 0) {
|
|
3164
|
-
const absolute =
|
|
3165
|
-
if (!isValidPlanPath(body.plan) || !absolute.startsWith(
|
|
3818
|
+
const absolute = path18.resolve(selected.root, body.plan);
|
|
3819
|
+
if (!isValidPlanPath(body.plan) || !absolute.startsWith(path18.resolve(selected.root) + path18.sep)) {
|
|
3166
3820
|
throw new CliError("plan must be a repository-relative path without . or .. segments.", 2);
|
|
3167
3821
|
}
|
|
3168
|
-
if (!
|
|
3822
|
+
if (!existsSync5(absolute)) warn(`WARN plan file not found at ${absolute}`);
|
|
3169
3823
|
}
|
|
3170
3824
|
const response = await patchTask({ ...selected, env: process.env, http: deps.http, taskId, body });
|
|
3171
3825
|
if (body.plan !== void 0) await runSyncCommand(deps, { slug: selected.slug, quiet: true });
|
|
@@ -3184,10 +3838,10 @@ async function roadmapEvents(deps, slug, opts) {
|
|
|
3184
3838
|
}
|
|
3185
3839
|
async function roadmapMigrate(deps, yes = false) {
|
|
3186
3840
|
const { root, projectId } = await resolveRoadmapReadContext(deps);
|
|
3187
|
-
const dir =
|
|
3841
|
+
const dir = path18.join(root, ".nolto", "roadmaps");
|
|
3188
3842
|
let files;
|
|
3189
3843
|
try {
|
|
3190
|
-
files = (await
|
|
3844
|
+
files = (await readdir6(dir, { withFileTypes: true })).filter((file) => file.isFile() && file.name.endsWith(".json")).map((file) => file.name).sort();
|
|
3191
3845
|
} catch (error) {
|
|
3192
3846
|
if (error.code !== "ENOENT") throw error;
|
|
3193
3847
|
files = [];
|
|
@@ -3200,7 +3854,7 @@ async function roadmapMigrate(deps, yes = false) {
|
|
|
3200
3854
|
for (const file of files) {
|
|
3201
3855
|
const slug = file.slice(0, -5);
|
|
3202
3856
|
cachePaths(process.env, projectId, slug);
|
|
3203
|
-
const roadmap = await loadValidRoadmap(
|
|
3857
|
+
const roadmap = await loadValidRoadmap(path18.join(dir, file), (p) => readFile13(p, "utf8"));
|
|
3204
3858
|
roadmap.schemaVersion = 3;
|
|
3205
3859
|
delete roadmap.updatedAt;
|
|
3206
3860
|
delete roadmap.currentTaskId;
|
|
@@ -3232,9 +3886,9 @@ async function roadmapMigrate(deps, yes = false) {
|
|
|
3232
3886
|
if (!unchanged) {
|
|
3233
3887
|
const response = await runSync({ repoRoot: root, projectId, slug, roadmap, baseRevision: revision, repoIdentity: await makeRepoIdentityResolver(deps)(root) }, {
|
|
3234
3888
|
http: deps.http,
|
|
3235
|
-
readFile: (p) =>
|
|
3889
|
+
readFile: (p) => readFile13(p, "utf8"),
|
|
3236
3890
|
realpath: realpath3,
|
|
3237
|
-
fileExists:
|
|
3891
|
+
fileExists: existsSync5,
|
|
3238
3892
|
log: () => void 0,
|
|
3239
3893
|
warn
|
|
3240
3894
|
});
|
|
@@ -3250,11 +3904,11 @@ async function roadmapMigrate(deps, yes = false) {
|
|
|
3250
3904
|
const nextSteps = ["Next steps (run yourself):", " git rm -r .nolto/roadmaps"];
|
|
3251
3905
|
let attributes = "";
|
|
3252
3906
|
try {
|
|
3253
|
-
attributes = await
|
|
3907
|
+
attributes = await readFile13(path18.join(root, ".gitattributes"), "utf8");
|
|
3254
3908
|
} catch (error) {
|
|
3255
3909
|
if (error.code !== "ENOENT") throw error;
|
|
3256
3910
|
}
|
|
3257
|
-
if (attributes.split(/\r?\n/).some((
|
|
3911
|
+
if (attributes.split(/\r?\n/).some((line2) => /^\s*\.nolto\/roadmaps\/\*\.json\s+.*\bmerge=nolto-roadmap(?:\s|$)/.test(line2))) {
|
|
3258
3912
|
nextSteps.push(' # remove the ".nolto/roadmaps/*.json merge=nolto-roadmap" line from .gitattributes');
|
|
3259
3913
|
}
|
|
3260
3914
|
nextSteps.push(" git config --unset-all merge.nolto-roadmap.name; git config --unset-all merge.nolto-roadmap.driver");
|
|
@@ -3269,6 +3923,11 @@ async function roadmapMigrate(deps, yes = false) {
|
|
|
3269
3923
|
// src/commands/roadmap.ts
|
|
3270
3924
|
function register9(program, deps) {
|
|
3271
3925
|
const roadmap = program.command("roadmap").description("Read and update server roadmaps through the local cache.");
|
|
3926
|
+
roadmap.command("schema").description("Print the roadmap schema reference").action(async () => {
|
|
3927
|
+
const bundled = new URL("./roadmap-schema-reference.md", import.meta.url);
|
|
3928
|
+
const source = new URL("../roadmap-schema-reference.md", import.meta.url);
|
|
3929
|
+
process.stdout.write(await readFile14(existsSync6(bundled) ? bundled : source, "utf8"));
|
|
3930
|
+
});
|
|
3272
3931
|
roadmap.command("path [slug]").description("Print the cached roadmap path").action((slug) => roadmapPath(deps, slug));
|
|
3273
3932
|
roadmap.command("pull [slug]").description("Pull one roadmap, or all when slug is omitted").option("--all", "Pull all roadmaps (default without a slug)").option("--force", "Overwrite unsynced local changes").action((slug, opts) => runPull(deps, { ...opts, slug }));
|
|
3274
3933
|
roadmap.command("sync [slug]").description("Push one roadmap, or all when slug is omitted").option("--no-git-links", "Skip commit / PR issue links").action((slug, opts) => runSyncCommand(deps, { ...opts, slug }).then(() => void 0));
|
|
@@ -3296,15 +3955,15 @@ function register9(program, deps) {
|
|
|
3296
3955
|
}
|
|
3297
3956
|
|
|
3298
3957
|
// src/commands/watch.ts
|
|
3299
|
-
import { execFile as
|
|
3300
|
-
import { promisify as
|
|
3301
|
-
import { readFile as
|
|
3302
|
-
import { existsSync as
|
|
3303
|
-
import
|
|
3958
|
+
import { execFile as execFile4 } from "child_process";
|
|
3959
|
+
import { promisify as promisify3 } from "util";
|
|
3960
|
+
import { readFile as readFile15, realpath as realpath4 } from "fs/promises";
|
|
3961
|
+
import { existsSync as existsSync7, mkdirSync } from "fs";
|
|
3962
|
+
import path21 from "path";
|
|
3304
3963
|
import chokidar from "chokidar";
|
|
3305
3964
|
|
|
3306
3965
|
// src/watch-core.ts
|
|
3307
|
-
import
|
|
3966
|
+
import path19 from "path";
|
|
3308
3967
|
var WatchSet = class {
|
|
3309
3968
|
constructor(deps) {
|
|
3310
3969
|
this.deps = deps;
|
|
@@ -3353,7 +4012,7 @@ async function reloadRoots(deps) {
|
|
|
3353
4012
|
continue;
|
|
3354
4013
|
}
|
|
3355
4014
|
try {
|
|
3356
|
-
const projectId = repo.projectId ?? (await loadRepoBinding(
|
|
4015
|
+
const projectId = repo.projectId ?? (await loadRepoBinding(path19.join(repo.root, "nolto.json")))?.projectId;
|
|
3357
4016
|
if (projectId) repos.push({ root: repo.root, projectId });
|
|
3358
4017
|
else deps.warn(`registered repo has no project binding, skipping: ${repo.root}`);
|
|
3359
4018
|
} catch (err) {
|
|
@@ -3424,7 +4083,7 @@ var RepoWatch = class {
|
|
|
3424
4083
|
};
|
|
3425
4084
|
|
|
3426
4085
|
// src/service-install.ts
|
|
3427
|
-
import
|
|
4086
|
+
import path20 from "path";
|
|
3428
4087
|
import os4 from "os";
|
|
3429
4088
|
function buildUnitFile(args) {
|
|
3430
4089
|
return [
|
|
@@ -3444,8 +4103,8 @@ function buildUnitFile(args) {
|
|
|
3444
4103
|
}
|
|
3445
4104
|
function getUnitPath(env) {
|
|
3446
4105
|
const xdg = env["XDG_CONFIG_HOME"];
|
|
3447
|
-
const base = xdg != null && xdg.length > 0 ? xdg :
|
|
3448
|
-
return
|
|
4106
|
+
const base = xdg != null && xdg.length > 0 ? xdg : path20.join(os4.homedir(), ".config");
|
|
4107
|
+
return path20.join(base, "systemd", "user", "nolto-watch.service");
|
|
3449
4108
|
}
|
|
3450
4109
|
async function installServiceWith(deps) {
|
|
3451
4110
|
if (deps.platform !== "linux") {
|
|
@@ -3456,7 +4115,7 @@ async function installServiceWith(deps) {
|
|
|
3456
4115
|
);
|
|
3457
4116
|
}
|
|
3458
4117
|
const unitPath = getUnitPath(deps.env);
|
|
3459
|
-
await deps.mkdir(
|
|
4118
|
+
await deps.mkdir(path20.dirname(unitPath));
|
|
3460
4119
|
await deps.writeFile(unitPath, buildUnitFile({ nodePath: deps.nodePath, scriptPath: deps.scriptPath }));
|
|
3461
4120
|
deps.log(`Wrote ${unitPath}`);
|
|
3462
4121
|
const reload = await deps.exec(["systemctl", "--user", "daemon-reload"]);
|
|
@@ -3470,18 +4129,18 @@ async function installServiceWith(deps) {
|
|
|
3470
4129
|
deps.log("Service nolto-watch enabled and started. Logs: journalctl --user -u nolto-watch -f");
|
|
3471
4130
|
}
|
|
3472
4131
|
async function installService() {
|
|
3473
|
-
const { writeFile:
|
|
3474
|
-
const { execFile:
|
|
3475
|
-
const { promisify:
|
|
3476
|
-
const execFileAsync =
|
|
4132
|
+
const { writeFile: writeFile12, mkdir: mkdir9 } = await import("fs/promises");
|
|
4133
|
+
const { execFile: execFile6 } = await import("child_process");
|
|
4134
|
+
const { promisify: promisify5 } = await import("util");
|
|
4135
|
+
const execFileAsync = promisify5(execFile6);
|
|
3477
4136
|
await installServiceWith({
|
|
3478
4137
|
platform: process.platform,
|
|
3479
4138
|
env: process.env,
|
|
3480
4139
|
nodePath: process.execPath,
|
|
3481
|
-
scriptPath:
|
|
3482
|
-
writeFile: (p, content) =>
|
|
4140
|
+
scriptPath: path20.resolve(process.argv[1] ?? ""),
|
|
4141
|
+
writeFile: (p, content) => writeFile12(p, content, "utf8"),
|
|
3483
4142
|
mkdir: async (p) => {
|
|
3484
|
-
await
|
|
4143
|
+
await mkdir9(p, { recursive: true });
|
|
3485
4144
|
},
|
|
3486
4145
|
exec: async (cmd) => {
|
|
3487
4146
|
try {
|
|
@@ -3492,8 +4151,8 @@ async function installService() {
|
|
|
3492
4151
|
return { code: e.code ?? 1, stderr: e.stderr ?? String(err) };
|
|
3493
4152
|
}
|
|
3494
4153
|
},
|
|
3495
|
-
log: (
|
|
3496
|
-
warn: (
|
|
4154
|
+
log: (line2) => process.stdout.write(line2 + "\n"),
|
|
4155
|
+
warn: (line2) => process.stderr.write("Warning: " + line2 + "\n")
|
|
3497
4156
|
});
|
|
3498
4157
|
}
|
|
3499
4158
|
async function uninstallServiceWith(deps) {
|
|
@@ -3535,14 +4194,14 @@ async function uninstallServiceWith(deps) {
|
|
|
3535
4194
|
deps.log("Service nolto-watch stopped, disabled, and removed.");
|
|
3536
4195
|
}
|
|
3537
4196
|
async function uninstallService() {
|
|
3538
|
-
const { unlink:
|
|
3539
|
-
const { execFile:
|
|
3540
|
-
const { promisify:
|
|
3541
|
-
const execFileAsync =
|
|
4197
|
+
const { unlink: unlink5 } = await import("fs/promises");
|
|
4198
|
+
const { execFile: execFile6 } = await import("child_process");
|
|
4199
|
+
const { promisify: promisify5 } = await import("util");
|
|
4200
|
+
const execFileAsync = promisify5(execFile6);
|
|
3542
4201
|
await uninstallServiceWith({
|
|
3543
4202
|
platform: process.platform,
|
|
3544
4203
|
env: process.env,
|
|
3545
|
-
unlink:
|
|
4204
|
+
unlink: unlink5,
|
|
3546
4205
|
exec: async (cmd) => {
|
|
3547
4206
|
try {
|
|
3548
4207
|
await execFileAsync(cmd[0], cmd.slice(1));
|
|
@@ -3552,8 +4211,8 @@ async function uninstallService() {
|
|
|
3552
4211
|
return { code: e.code ?? 1, stderr: e.stderr ?? String(err) };
|
|
3553
4212
|
}
|
|
3554
4213
|
},
|
|
3555
|
-
log: (
|
|
3556
|
-
warn: (
|
|
4214
|
+
log: (line2) => process.stdout.write(line2 + "\n"),
|
|
4215
|
+
warn: (line2) => process.stderr.write("Warning: " + line2 + "\n")
|
|
3557
4216
|
});
|
|
3558
4217
|
}
|
|
3559
4218
|
async function stopServiceWith(deps) {
|
|
@@ -3603,9 +4262,9 @@ function register10(program, deps) {
|
|
|
3603
4262
|
const registryPath = getRegistryPath(process.env);
|
|
3604
4263
|
const roots = await reloadRoots({
|
|
3605
4264
|
load: () => loadRegistry(registryPath),
|
|
3606
|
-
exists:
|
|
3607
|
-
warn: (
|
|
3608
|
-
process.stderr.write(`Warning: ${
|
|
4265
|
+
exists: existsSync7,
|
|
4266
|
+
warn: (line2) => {
|
|
4267
|
+
process.stderr.write(`Warning: ${line2}
|
|
3609
4268
|
`);
|
|
3610
4269
|
}
|
|
3611
4270
|
});
|
|
@@ -3619,8 +4278,8 @@ function register10(program, deps) {
|
|
|
3619
4278
|
});
|
|
3620
4279
|
const startRepo = ({ root, projectId }) => {
|
|
3621
4280
|
const roadmapsPath = cacheDir(process.env, projectId);
|
|
3622
|
-
const warn2 = (
|
|
3623
|
-
process.stderr.write(
|
|
4281
|
+
const warn2 = (line2) => {
|
|
4282
|
+
process.stderr.write(line2.startsWith(" ") ? line2 + "\n" : `Warning: [${path21.basename(root)}] ${line2}
|
|
3624
4283
|
`);
|
|
3625
4284
|
};
|
|
3626
4285
|
mkdirSync(roadmapsPath, { recursive: true, mode: 448 });
|
|
@@ -3630,14 +4289,14 @@ function register10(program, deps) {
|
|
|
3630
4289
|
{ root, projectId, onlyDirty },
|
|
3631
4290
|
{
|
|
3632
4291
|
env: process.env,
|
|
3633
|
-
readFile: (p) =>
|
|
4292
|
+
readFile: (p) => readFile15(p, "utf8"),
|
|
3634
4293
|
realpath: (p) => realpath4(p),
|
|
3635
|
-
fileExists: (p) =>
|
|
4294
|
+
fileExists: (p) => existsSync7(p),
|
|
3636
4295
|
repoIdentity: makeRepoIdentityResolver(deps),
|
|
3637
|
-
exec:
|
|
4296
|
+
exec: promisify3(execFile4),
|
|
3638
4297
|
gitLinks: process.env.NOLTO_GIT_LINKS !== "0",
|
|
3639
4298
|
http,
|
|
3640
|
-
log: (
|
|
4299
|
+
log: (line2) => process.stdout.write(`[${path21.basename(root)}] ${line2}
|
|
3641
4300
|
`),
|
|
3642
4301
|
warn: warn2
|
|
3643
4302
|
}
|
|
@@ -3646,17 +4305,15 @@ function register10(program, deps) {
|
|
|
3646
4305
|
debounceMs,
|
|
3647
4306
|
setTimeoutFn: (fn, ms) => setTimeout(fn, ms),
|
|
3648
4307
|
clearTimeoutFn: (t) => clearTimeout(t),
|
|
3649
|
-
log: (
|
|
3650
|
-
warn: (
|
|
4308
|
+
log: (line2) => process.stdout.write(line2 + "\n"),
|
|
4309
|
+
warn: (line2) => process.stderr.write(line2 + "\n")
|
|
3651
4310
|
});
|
|
3652
4311
|
watcher.on("all", (_event, filePath) => {
|
|
3653
|
-
if (
|
|
4312
|
+
if (path21.dirname(filePath) === roadmapsPath && !filePath.endsWith(".json")) return;
|
|
3654
4313
|
repoWatch.handleEvent(filePath);
|
|
3655
4314
|
});
|
|
3656
|
-
void
|
|
3657
|
-
|
|
3658
|
-
warn2(formatSkillVersionDriftWarning(root, deps.version, drifted));
|
|
3659
|
-
}
|
|
4315
|
+
void checkSkillDrift(root, { homeSkillDirs: deps.homeSkillDirs }).then((drifted) => {
|
|
4316
|
+
for (const warning of drifted) warn2(warning);
|
|
3660
4317
|
}).catch(() => {
|
|
3661
4318
|
});
|
|
3662
4319
|
void repoWatch.flush();
|
|
@@ -3664,7 +4321,7 @@ function register10(program, deps) {
|
|
|
3664
4321
|
};
|
|
3665
4322
|
const watchSet = new WatchSet({
|
|
3666
4323
|
start: startRepo,
|
|
3667
|
-
log: (
|
|
4324
|
+
log: (line2) => process.stdout.write(line2 + "\n")
|
|
3668
4325
|
});
|
|
3669
4326
|
await watchSet.reconcile(roots);
|
|
3670
4327
|
try {
|
|
@@ -3681,8 +4338,8 @@ function register10(program, deps) {
|
|
|
3681
4338
|
registryReloadTimer = null;
|
|
3682
4339
|
void reloadRoots({
|
|
3683
4340
|
load: () => loadRegistry(registryPath),
|
|
3684
|
-
exists: (root) =>
|
|
3685
|
-
warn: (
|
|
4341
|
+
exists: (root) => existsSync7(root),
|
|
4342
|
+
warn: (line2) => process.stderr.write(`Warning: ${line2}
|
|
3686
4343
|
`)
|
|
3687
4344
|
}).then(async (newRoots) => {
|
|
3688
4345
|
if (newRoots == null) return;
|
|
@@ -3718,7 +4375,7 @@ function register10(program, deps) {
|
|
|
3718
4375
|
version: running ? state.version : null,
|
|
3719
4376
|
startedAt: running ? state.startedAt : null,
|
|
3720
4377
|
stale: running && state.version !== deps.version,
|
|
3721
|
-
service:
|
|
4378
|
+
service: existsSync7(getUnitPath(process.env)) ? "installed" : "not-installed"
|
|
3722
4379
|
};
|
|
3723
4380
|
printResult(deps.output.mode === "json" ? result : `${running ? "running" : "not running"}
|
|
3724
4381
|
service: ${result.service}
|
|
@@ -3730,14 +4387,14 @@ stale: ${result.stale}`, deps.output.mode);
|
|
|
3730
4387
|
watch.command("stop").description("Stop watch without disabling the installed service.").action(async () => {
|
|
3731
4388
|
const statePath = getWatchStatePath(process.env);
|
|
3732
4389
|
const state = await readWatchState(statePath);
|
|
3733
|
-
const service =
|
|
4390
|
+
const service = existsSync7(getUnitPath(process.env));
|
|
3734
4391
|
let via = null;
|
|
3735
4392
|
if (service) {
|
|
3736
4393
|
await stopServiceWith({
|
|
3737
4394
|
platform: process.platform,
|
|
3738
4395
|
exec: async (cmd) => {
|
|
3739
4396
|
try {
|
|
3740
|
-
await
|
|
4397
|
+
await promisify3(execFile4)(cmd[0], cmd.slice(1));
|
|
3741
4398
|
return { code: 0, stderr: "" };
|
|
3742
4399
|
} catch (error) {
|
|
3743
4400
|
const e = error;
|
|
@@ -3768,11 +4425,11 @@ stale: ${result.stale}`, deps.output.mode);
|
|
|
3768
4425
|
});
|
|
3769
4426
|
watch.command("list").description("List repositories in the watch registry.").action(async () => {
|
|
3770
4427
|
const registry = await loadRegistry(getRegistryPath(process.env));
|
|
3771
|
-
const repos = registry.repos.map((repo) => ({ root: repo.root, projectId: repo.projectId ?? null, exists:
|
|
4428
|
+
const repos = registry.repos.map((repo) => ({ root: repo.root, projectId: repo.projectId ?? null, exists: existsSync7(repo.root) }));
|
|
3772
4429
|
printResult(deps.output.mode === "json" ? { repos } : repos.map((repo) => `${repo.root} ${repo.projectId ?? "\u2014"}${repo.exists ? "" : " (missing)"}`).join("\n"), deps.output.mode);
|
|
3773
4430
|
});
|
|
3774
4431
|
watch.command("remove [root]").description("Remove a repository from the watch registry.").action(async (arg) => {
|
|
3775
|
-
const root = arg === void 0 ? findRepoRoot(resolveStartDir(process.env, process.cwd())).root :
|
|
4432
|
+
const root = arg === void 0 ? findRepoRoot(resolveStartDir(process.env, process.cwd())).root : path21.resolve(arg);
|
|
3776
4433
|
const { removed } = await removeRepoFromRegistry(getRegistryPath(process.env), root);
|
|
3777
4434
|
if (!removed) throw new CliError(`${root} is not in the watch registry.`, 2, "Run `nolto watch list` to see registered repositories.");
|
|
3778
4435
|
printResult(deps.output.mode === "json" ? { removed: true, root } : `Removed ${root} from the watch registry.`, deps.output.mode);
|
|
@@ -3780,18 +4437,18 @@ stale: ${result.stale}`, deps.output.mode);
|
|
|
3780
4437
|
}
|
|
3781
4438
|
|
|
3782
4439
|
// src/update-cli.ts
|
|
3783
|
-
import { execFile as
|
|
3784
|
-
import { existsSync as
|
|
4440
|
+
import { execFile as execFile5 } from "child_process";
|
|
4441
|
+
import { existsSync as existsSync8 } from "fs";
|
|
3785
4442
|
import { realpath as realpath5 } from "fs/promises";
|
|
3786
4443
|
import { createRequire as createRequire2 } from "module";
|
|
3787
|
-
import
|
|
4444
|
+
import path23 from "path";
|
|
3788
4445
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
3789
|
-
import { promisify as
|
|
4446
|
+
import { promisify as promisify4 } from "util";
|
|
3790
4447
|
|
|
3791
4448
|
// src/update-notifier.ts
|
|
3792
|
-
import { readFile as
|
|
4449
|
+
import { readFile as readFile16, writeFile as writeFile10, mkdir as mkdir8 } from "fs/promises";
|
|
3793
4450
|
import https from "https";
|
|
3794
|
-
import
|
|
4451
|
+
import path22 from "path";
|
|
3795
4452
|
var PACKAGE = "@nolto/cli";
|
|
3796
4453
|
var CACHE_FILE = "update-check.json";
|
|
3797
4454
|
var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
@@ -3849,9 +4506,9 @@ function fetchLatestFromRegistry(timeoutMs = REQUEST_TIMEOUT_MS, opts = {}) {
|
|
|
3849
4506
|
});
|
|
3850
4507
|
}
|
|
3851
4508
|
async function writeUpdateCache(cachePath, now, latest2) {
|
|
3852
|
-
await
|
|
4509
|
+
await mkdir8(path22.dirname(cachePath), { recursive: true });
|
|
3853
4510
|
const payload = { checkedAt: now, latest: latest2 };
|
|
3854
|
-
await
|
|
4511
|
+
await writeFile10(cachePath, JSON.stringify(payload), { mode: 384 });
|
|
3855
4512
|
}
|
|
3856
4513
|
async function refreshCache(cachePath, now, fetchLatest) {
|
|
3857
4514
|
const latest2 = await fetchLatest();
|
|
@@ -3860,10 +4517,10 @@ async function refreshCache(cachePath, now, fetchLatest) {
|
|
|
3860
4517
|
}
|
|
3861
4518
|
async function checkForUpdate(opts) {
|
|
3862
4519
|
if (isDisabled(opts.env)) return null;
|
|
3863
|
-
const cachePath =
|
|
4520
|
+
const cachePath = path22.join(opts.configDir, CACHE_FILE);
|
|
3864
4521
|
let cache = {};
|
|
3865
4522
|
try {
|
|
3866
|
-
cache = JSON.parse(await
|
|
4523
|
+
cache = JSON.parse(await readFile16(cachePath, "utf8"));
|
|
3867
4524
|
} catch {
|
|
3868
4525
|
}
|
|
3869
4526
|
if (typeof cache.checkedAt !== "number" || opts.now - cache.checkedAt > CACHE_TTL_MS) {
|
|
@@ -3968,7 +4625,7 @@ async function updateCliWith(deps) {
|
|
|
3968
4625
|
}
|
|
3969
4626
|
deps.log(`Updated ${PACKAGE2} ${deps.currentVersion} \u2192 ${latest2}.`);
|
|
3970
4627
|
await deps.writeCache(
|
|
3971
|
-
|
|
4628
|
+
path23.join(deps.configDir, UPDATE_CACHE_FILE),
|
|
3972
4629
|
deps.now,
|
|
3973
4630
|
latest2
|
|
3974
4631
|
).catch(() => void 0);
|
|
@@ -3999,17 +4656,17 @@ async function updateCliWith(deps) {
|
|
|
3999
4656
|
};
|
|
4000
4657
|
}
|
|
4001
4658
|
function getCurrentVersion() {
|
|
4002
|
-
const dirname =
|
|
4659
|
+
const dirname = path23.dirname(fileURLToPath3(import.meta.url));
|
|
4003
4660
|
const require3 = createRequire2(import.meta.url);
|
|
4004
4661
|
try {
|
|
4005
|
-
const pkg = require3(
|
|
4662
|
+
const pkg = require3(path23.resolve(dirname, "../package.json"));
|
|
4006
4663
|
return pkg.version ?? "0.0.0";
|
|
4007
4664
|
} catch {
|
|
4008
4665
|
return "0.0.0";
|
|
4009
4666
|
}
|
|
4010
4667
|
}
|
|
4011
4668
|
async function updateCli(opts = {}) {
|
|
4012
|
-
const execFileAsync =
|
|
4669
|
+
const execFileAsync = promisify4(execFile5);
|
|
4013
4670
|
const scriptPath = await realpath5(process.argv[1] ?? "");
|
|
4014
4671
|
return updateCliWith({
|
|
4015
4672
|
currentVersion: getCurrentVersion(),
|
|
@@ -4034,9 +4691,9 @@ async function updateCli(opts = {}) {
|
|
|
4034
4691
|
realpath: realpath5,
|
|
4035
4692
|
fetchLatest: () => fetchLatestFromRegistry(UPDATE_REQUEST_TIMEOUT_MS, UPDATE_FETCH_OPTIONS),
|
|
4036
4693
|
writeCache: writeUpdateCache,
|
|
4037
|
-
unitExists:
|
|
4038
|
-
log: opts.quiet === true ? () => void 0 : (
|
|
4039
|
-
warn: (
|
|
4694
|
+
unitExists: existsSync8,
|
|
4695
|
+
log: opts.quiet === true ? () => void 0 : (line2) => process.stdout.write(line2 + "\n"),
|
|
4696
|
+
warn: (line2) => process.stderr.write("Warning: " + line2 + "\n")
|
|
4040
4697
|
});
|
|
4041
4698
|
}
|
|
4042
4699
|
|
|
@@ -4052,7 +4709,7 @@ function register11(program, deps) {
|
|
|
4052
4709
|
}
|
|
4053
4710
|
|
|
4054
4711
|
// src/commands/merge-file.ts
|
|
4055
|
-
import { readFile as
|
|
4712
|
+
import { readFile as readFile17, writeFile as writeFile11 } from "fs/promises";
|
|
4056
4713
|
|
|
4057
4714
|
// src/roadmap-merge.ts
|
|
4058
4715
|
import { isDeepStrictEqual } from "util";
|
|
@@ -4292,7 +4949,7 @@ function mergeRoadmaps(args) {
|
|
|
4292
4949
|
async function readRoadmap(filePath) {
|
|
4293
4950
|
let parsed;
|
|
4294
4951
|
try {
|
|
4295
|
-
parsed = JSON.parse(await
|
|
4952
|
+
parsed = JSON.parse(await readFile17(filePath, "utf8"));
|
|
4296
4953
|
} catch (err) {
|
|
4297
4954
|
const message = err instanceof SyntaxError ? "malformed JSON" : String(err);
|
|
4298
4955
|
throw new CliError(`${filePath}: ${message}`, 1);
|
|
@@ -4316,7 +4973,7 @@ function register12(program) {
|
|
|
4316
4973
|
const theirs = await readRoadmap(theirsPath);
|
|
4317
4974
|
const base = opts.base == null ? null : await readRoadmap(opts.base);
|
|
4318
4975
|
const merged = mergeRoadmaps({ base, ours, theirs });
|
|
4319
|
-
await
|
|
4976
|
+
await writeFile11(
|
|
4320
4977
|
opts.output ?? oursPath,
|
|
4321
4978
|
JSON.stringify(merged, null, 2) + "\n",
|
|
4322
4979
|
"utf8"
|
|
@@ -4328,6 +4985,287 @@ function register12(program) {
|
|
|
4328
4985
|
});
|
|
4329
4986
|
}
|
|
4330
4987
|
|
|
4988
|
+
// src/commands/memory.ts
|
|
4989
|
+
import { readFile as readFile18 } from "fs/promises";
|
|
4990
|
+
var aiSkipReasons = { timeout: "\u6642\u9593\u5207\u308C", limit: "\u4ECA\u65E5\u306E\u4E0A\u9650", size: "\u672C\u6587\u304C\u9577\u3044", invalid: "\u7D50\u679C\u304C\u4E0D\u6B63", stale: "\u540C\u6642\u306B\u66F4\u65B0\u304C\u3042\u3063\u305F", unavailable: "AI \u3092\u4F7F\u3048\u306A\u3044" };
|
|
4991
|
+
var aiSkippedLine = (reason) => `AI \u6574\u7406\u306A\u3057(${aiSkipReasons[reason] ?? oneLine(reason)})`;
|
|
4992
|
+
var pullHint = "nolto memory pull \u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044";
|
|
4993
|
+
var scopeHint = "--scope project|user|branch";
|
|
4994
|
+
async function context2(deps, recover = false) {
|
|
4995
|
+
const bindingPath = deps.repoBinding?.path ?? deps.projectBindingPath;
|
|
4996
|
+
const binding = deps.repoBinding?.binding ?? (bindingPath ? await loadRepoBinding(bindingPath) : null);
|
|
4997
|
+
const project = deps.settings.defaultProjectId ?? binding?.projectId;
|
|
4998
|
+
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>");
|
|
4999
|
+
const root = findRepoRoot(resolveStartDir(process.env, process.cwd())).root;
|
|
5000
|
+
return createMemoryContext({ projectId: project, configPath: deps.configPath, root, git: await memoryGitContext(root, deps) }, recover);
|
|
5001
|
+
}
|
|
5002
|
+
function headers() {
|
|
5003
|
+
return { "X-Nolto-Client": detectMemoryClient(process.env) };
|
|
5004
|
+
}
|
|
5005
|
+
function line(entry) {
|
|
5006
|
+
return `${entry.scope}/${entry.name} r${entry.revision} \u2014 ${oneLine(entry.description)}`;
|
|
5007
|
+
}
|
|
5008
|
+
function resolveEntry(ctx, name, target, deleted = false) {
|
|
5009
|
+
if (target.scope) parseScope(target.scope, scopeHint);
|
|
5010
|
+
if (target.branch !== void 0 && target.scope && target.scope !== "branch") throw new CliError("--branch \u306F --scope branch \u3068\u3060\u3051\u7D44\u307F\u5408\u308F\u305B\u3089\u308C\u307E\u3059\u3002", 2, "--scope \u3092\u5916\u3059\u304B --scope branch \u306B\u3059\u308B");
|
|
5011
|
+
const scope = target.branch !== void 0 ? "branch" : target.scope;
|
|
5012
|
+
const branch = target.branch ?? ctx.git.branch;
|
|
5013
|
+
const named = ctx.cache.state.entries.filter((e) => e.name === name && (!scope || e.scope === scope));
|
|
5014
|
+
const inRepo = (e) => e.scope !== "branch" || e.repoIdentity === ctx.git.repoIdentity;
|
|
5015
|
+
const candidates = named.filter((e) => inRepo(e) && (e.scope !== "branch" || e.branch === branch) && (deleted || !e.deleted));
|
|
5016
|
+
if (candidates.length > 1) throw new CliError(`\u30E1\u30E2\u30EA ${name} \u306F\u66D6\u6627\u3067\u3059: ${candidates.map((e) => `${e.scope}/${e.name}`).join(", ")}`, 2, "--scope \u3092\u4ED8\u3051\u308B");
|
|
5017
|
+
if (candidates.length) return candidates[0];
|
|
5018
|
+
const others = [...new Set(named.filter((e) => e.scope === "branch" && inRepo(e) && e.branch !== branch && !e.deleted).map((e) => e.branch))];
|
|
5019
|
+
if (others.length) {
|
|
5020
|
+
throw new CliError(`\u30E1\u30E2\u30EA ${name} \u306F\u4ECA\u306E\u30D6\u30E9\u30F3\u30C1\u306B\u3042\u308A\u307E\u305B\u3093\u3002\u307B\u304B\u306E\u30D6\u30E9\u30F3\u30C1: ${others.map(oneLine).join(", ")}`, 2, `--branch ${shellArg(others[0])} \u3092\u4ED8\u3051\u308B`);
|
|
5021
|
+
}
|
|
5022
|
+
if (!deleted && named.some((e) => inRepo(e) && e.deleted)) {
|
|
5023
|
+
throw new CliError(`\u30E1\u30E2\u30EA ${name} \u306F\u524A\u9664\u6E08\u307F\u3067\u3059\u3002`, 2, `\u5C65\u6B74\u306F nolto memory log ${name}\u3001\u623B\u3059\u306A\u3089 nolto memory revert ${name} <revision>`);
|
|
5024
|
+
}
|
|
5025
|
+
throw new CliError(`\u30E1\u30E2\u30EA ${name} \u304C\u30AD\u30E3\u30C3\u30B7\u30E5\u306B\u3042\u308A\u307E\u305B\u3093\u3002`, 2, "nolto memory pull");
|
|
5026
|
+
}
|
|
5027
|
+
async function apiCall(deps, ctx, call, op = "read", name = "<name>") {
|
|
5028
|
+
try {
|
|
5029
|
+
return await call();
|
|
5030
|
+
} catch (error) {
|
|
5031
|
+
if (!(error instanceof CliError)) throw error;
|
|
5032
|
+
const code = error.serverError;
|
|
5033
|
+
let hint = error.hint;
|
|
5034
|
+
const body = error.body;
|
|
5035
|
+
const latest2 = body?.entry;
|
|
5036
|
+
if (latest2 && (code === "memory_exists" || code === "memory_conflict")) await updateCache(ctx, deps, [latest2], true);
|
|
5037
|
+
let detail;
|
|
5038
|
+
if (code === "memory_similar") {
|
|
5039
|
+
hint = "nolto memory show <name> \u3067\u8AAD\u307F\u3001\u540C\u3058\u8A71\u306A\u3089 frontmatter \u306B revision \u3092\u8DB3\u3057\u3066\u305D\u306E name \u3067 put\u3002\u5225\u306E\u8A71\u306A\u3089 --new";
|
|
5040
|
+
const lines = typeof body?.aiSkipped === "string" ? [aiSkippedLine(body.aiSkipped)] : [];
|
|
5041
|
+
if (Array.isArray(body?.candidates)) {
|
|
5042
|
+
lines.push(...body.candidates.map((candidate) => `${candidate.scope}/${candidate.name} r${candidate.revision} (${candidate.score.toFixed(2)}) \u2014 ${oneLine(candidate.description)}`));
|
|
5043
|
+
}
|
|
5044
|
+
if (lines.length) detail = lines.join("\n");
|
|
5045
|
+
} else if (code === "memory_exists" && Array.isArray(body?.conflicts)) {
|
|
5046
|
+
const conflicts = body.conflicts;
|
|
5047
|
+
await updateCache(ctx, deps, conflicts.flatMap((c) => [c.branchEntry, c.projectEntry]), true);
|
|
5048
|
+
detail = conflicts.map((c) => `project/${c.name} r${c.projectEntry.revision} \u2190 branch/${c.name} r${c.branchEntry.revision}`).join("\n");
|
|
5049
|
+
const branch = shellArg(conflicts[0]?.branchEntry.branch ?? "<branch>");
|
|
5050
|
+
const n = conflicts.length === 1 ? conflicts[0].name : "<name>";
|
|
5051
|
+
hint = `\u4E21\u65B9\u3092\u8AAD\u3080: nolto memory show ${n} --scope branch --branch ${branch} \u3068 nolto memory show ${n} --scope project\u3002project \u5074\u306B\u7D71\u5408\u3057\u3066 put \u2192 nolto memory promote --branch ${branch} --discard ${n}\u3002\u6B8B\u308A\u306F\u305D\u306E\u3042\u3068 promote`;
|
|
5052
|
+
} else if (code === "memory_not_found" && op === "put") {
|
|
5053
|
+
hint = `\u524A\u9664\u6E08\u307F\u304B\u3001\u898B\u3064\u304B\u3089\u306A\u3044\u3002revision \u884C\u3092\u6D88\u3057\u3066\u65B0\u898F\u3067 put \u3059\u308B\u304B\u3001nolto memory log ${name} \u3067\u5C65\u6B74\u3092\u898B\u3066 revert`;
|
|
5054
|
+
} else if (code === "memory_conflict" && latest2 && (op === "rm" || op === "revert")) {
|
|
5055
|
+
hint = "\u6700\u65B0\u306E\u5185\u5BB9\u3092\u78BA\u8A8D\u3057\u3001\u540C\u3058\u30B3\u30DE\u30F3\u30C9\u3092\u518D\u5B9F\u884C(\u30AD\u30E3\u30C3\u30B7\u30E5\u306F\u66F4\u65B0\u6E08\u307F)";
|
|
5056
|
+
detail = formatMemory(latest2);
|
|
5057
|
+
} else if (code === "memory_exists") {
|
|
5058
|
+
hint = `nolto memory show ${latest2 ? `${latest2.name} --scope ${latest2.scope}` : "<name>"} --fresh > \u4E0B\u66F8\u304D.md \u3067\u4ECA\u306E\u5185\u5BB9\u3068 revision \u3092\u53D6\u308A\u3001\u7D71\u5408\u3057\u3066 put`;
|
|
5059
|
+
} else if (code === "memory_conflict" && latest2) {
|
|
5060
|
+
hint = `\u5185\u5BB9\u3092\u7D71\u5408\u3057\u3001revision \u3092 ${latest2.revision} \u306B\u3057\u3066 put \u3057\u76F4\u3059`;
|
|
5061
|
+
detail = formatMemory(latest2);
|
|
5062
|
+
} else if (code === "repo_unbound") hint = "nolto link --add \u3067\u3053\u306E repo \u3092\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u306B\u7D10\u4ED8\u3051\u308B";
|
|
5063
|
+
throw new CliError(error.message, error.exitCode, hint, error.status, code, body, detail);
|
|
5064
|
+
}
|
|
5065
|
+
}
|
|
5066
|
+
function printWrite(deps, ctx, action, response, isNew = false) {
|
|
5067
|
+
if (deps.output.mode === "json") {
|
|
5068
|
+
printResult(response, "json");
|
|
5069
|
+
return;
|
|
5070
|
+
}
|
|
5071
|
+
const { entry } = response;
|
|
5072
|
+
const lines = [aiHeading(response) ?? `${action} ${entry.scope}/${entry.name} r${entry.revision}${isNew ? " (\u65B0\u898F)" : ""}`];
|
|
5073
|
+
if (response.aiSkipped) lines.push(aiSkippedLine(response.aiSkipped));
|
|
5074
|
+
const affected = response.affected ?? [];
|
|
5075
|
+
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}`}`);
|
|
5076
|
+
const reverts = affected.filter((a) => a.fromRevision >= 1).map((a) => {
|
|
5077
|
+
const shared = ctx.cache.state.entries.some((e) => e.name === a.name && e.id !== a.entryId && e.scope !== a.scope);
|
|
5078
|
+
return `nolto memory revert ${shellArg(a.name)} ${a.fromRevision}${shared ? ` --scope ${a.scope}` : ""}`;
|
|
5079
|
+
});
|
|
5080
|
+
if (reverts.length) lines.push(`\u623B\u3059: ${reverts.join(" / ")}`);
|
|
5081
|
+
for (const warning of response.warnings ?? []) lines.push(`\u6CE8\u610F: ${typeof warning === "string" ? oneLine(warning) : JSON.stringify(warning)}`);
|
|
5082
|
+
process.stdout.write(lines.join("\n") + "\n");
|
|
5083
|
+
}
|
|
5084
|
+
async function pull2(deps, opts) {
|
|
5085
|
+
let ctx;
|
|
5086
|
+
const signal = opts.hook ? AbortSignal.timeout(8e3) : void 0;
|
|
5087
|
+
try {
|
|
5088
|
+
const explicitProject = deps.settings.source?.project === "flag" || deps.settings.source?.project === "env";
|
|
5089
|
+
if (opts.hook && !explicitProject && !(deps.repoBinding?.path ?? deps.projectBindingPath)) {
|
|
5090
|
+
process.stdout.write(hookOutput(opts.hook, "nolto link \u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044"));
|
|
5091
|
+
return;
|
|
5092
|
+
}
|
|
5093
|
+
if (opts.hook && !deps.settings.token) {
|
|
5094
|
+
process.stdout.write(hookOutput(opts.hook, "nolto login \u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044"));
|
|
5095
|
+
return;
|
|
5096
|
+
}
|
|
5097
|
+
ctx = await context2(deps, true);
|
|
5098
|
+
if (opts.hook && typeof opts.hook === "string" && !["claude", "codex", "gemini"].includes(opts.hook)) throw new CliError("Unknown hook agent", 2);
|
|
5099
|
+
const scope = opts.scope ? [...new Set(opts.scope.split(",").map((s) => parseScope(s.trim(), scopeHint)))].sort().join(",") : "";
|
|
5100
|
+
const previous = ctx.cache.state.entries;
|
|
5101
|
+
const reset = ctx.cache.meta.cursor === 0 || ctx.cache.state.scope !== scope;
|
|
5102
|
+
let cursor = reset ? 0 : ctx.cache.meta.cursor;
|
|
5103
|
+
let entries = reset ? [] : previous;
|
|
5104
|
+
while (true) {
|
|
5105
|
+
const query = new URLSearchParams({ since: String(cursor), ...scope ? { scope } : {} });
|
|
5106
|
+
const page = await apiCall(deps, ctx, () => deps.http.get(`${ctx.api}?${query}`, signal));
|
|
5107
|
+
if (!Array.isArray(page.entries) || !Number.isSafeInteger(page.cursor) || page.cursor < cursor || page.hasMore && page.cursor === cursor) throw new CliError("Invalid memory cursor response", 5);
|
|
5108
|
+
entries = mergeMemoryEntries(entries, page.entries);
|
|
5109
|
+
cursor = page.cursor;
|
|
5110
|
+
if (!page.hasMore) break;
|
|
5111
|
+
}
|
|
5112
|
+
const [projects, profile] = await Promise.all([
|
|
5113
|
+
deps.http.get("/api/projects", signal).catch(() => null),
|
|
5114
|
+
deps.http.get("/api/me/profile", signal).catch(() => null)
|
|
5115
|
+
]);
|
|
5116
|
+
const projectName = projects?.projects?.find((p) => p.id === ctx.project)?.name ?? ctx.cache.state.projectName;
|
|
5117
|
+
const userId = typeof profile?.profile?.id === "string" ? profile.profile.id : ctx.cache.state.userId;
|
|
5118
|
+
const next = { ...ctx, cache: { state: { entries, scope, projectName, ...userId ? { userId } : {} }, meta: { cursor, pulledAt: (/* @__PURE__ */ new Date()).toISOString() } } };
|
|
5119
|
+
const text = await memoryIndexText(next, deps);
|
|
5120
|
+
const unsafe = await saveMemoryCache(ctx.dir, next.cache, previous, text, reset);
|
|
5121
|
+
if (unsafe.length && !opts.hook) process.stderr.write(`Warning: \u30AD\u30E3\u30C3\u30B7\u30E5\u306B\u7F6E\u3051\u306A\u3044\u30A8\u30F3\u30C8\u30EA ${unsafe.length} \u4EF6\u3092\u7D22\u5F15\u3068 list \u304B\u3089\u5916\u3057\u305F: ${unsafe.map((e) => `${e.scope}/${oneLine(e.name)}`).join(", ")}
|
|
5122
|
+
`);
|
|
5123
|
+
if (opts.hook) process.stdout.write(hookOutput(opts.hook, text));
|
|
5124
|
+
else printResult(deps.output.mode === "json" ? { cursor, entries: entries.filter((e) => !e.deleted).length } : `pulled memory (${entries.filter((e) => !e.deleted).length} \u4EF6)`, deps.output.mode);
|
|
5125
|
+
} catch (error) {
|
|
5126
|
+
if (!opts.hook) throw error;
|
|
5127
|
+
let text = pullHint;
|
|
5128
|
+
if (ctx?.cache.meta.pulledAt) {
|
|
5129
|
+
try {
|
|
5130
|
+
const age = Math.max(0, Math.floor((Date.now() - Date.parse(ctx.cache.meta.pulledAt)) / 6e4));
|
|
5131
|
+
text = `(\u6700\u7D42\u540C\u671F ${Number.isFinite(age) ? age : "\u4E0D\u660E"} \u5206\u524D\u3002\u4ECA\u56DE\u306F\u540C\u671F\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F)
|
|
5132
|
+
${await memoryIndexText(ctx, deps)}`;
|
|
5133
|
+
} catch {
|
|
5134
|
+
}
|
|
5135
|
+
}
|
|
5136
|
+
process.stdout.write(hookOutput(opts.hook, text));
|
|
5137
|
+
}
|
|
5138
|
+
}
|
|
5139
|
+
async function inputText(file) {
|
|
5140
|
+
if (file !== "-") return readFile18(file, "utf8");
|
|
5141
|
+
let text = "";
|
|
5142
|
+
process.stdin.setEncoding("utf8");
|
|
5143
|
+
for await (const chunk of process.stdin) text += chunk;
|
|
5144
|
+
return text;
|
|
5145
|
+
}
|
|
5146
|
+
function register13(program, deps) {
|
|
5147
|
+
const memory = program.command("memory").description("Read and write project memory.");
|
|
5148
|
+
memory.command("pull").option("--hook [agent]", "SessionStart output; always exit 0").option("--scope <csv>").action((opts) => pull2(deps, opts));
|
|
5149
|
+
memory.command("context").action(async () => {
|
|
5150
|
+
const ctx = await context2(deps);
|
|
5151
|
+
process.stdout.write(ctx.cache.meta.pulledAt || ctx.cache.state.entries.length ? await memoryIndexText(ctx, deps) : pullHint + "\n");
|
|
5152
|
+
});
|
|
5153
|
+
memory.command("instructions").action(() => {
|
|
5154
|
+
process.stdout.write(MEMORY_INSTRUCTIONS + "\n");
|
|
5155
|
+
});
|
|
5156
|
+
memory.command("list").option("--scope <scope>").option("--all-branches").action(async (opts) => {
|
|
5157
|
+
const ctx = await context2(deps);
|
|
5158
|
+
if (opts.scope) parseScope(opts.scope, scopeHint);
|
|
5159
|
+
const entries = sortMemoryEntries(currentMemoryEntries(ctx.cache.state.entries, ctx.git, opts.allBranches).filter((e) => !opts.scope || e.scope === opts.scope));
|
|
5160
|
+
printResult(deps.output.mode === "json" ? entries : entries.map((e) => line(e) + (opts.allBranches && e.scope === "branch" ? ` [${e.repoIdentity} ${e.branch}]` : "")).join("\n"), deps.output.mode);
|
|
5161
|
+
});
|
|
5162
|
+
memory.command("show <name>").option("--scope <scope>").option("--branch <branch>", "branch entry of the current repo").option("--fresh").action(async (name, opts) => {
|
|
5163
|
+
const ctx = await context2(deps);
|
|
5164
|
+
let entry = resolveEntry(ctx, name, opts);
|
|
5165
|
+
if (opts.fresh) {
|
|
5166
|
+
entry = await apiCall(deps, ctx, () => deps.http.get(`${ctx.api}/${encodeURIComponent(entry.id)}`));
|
|
5167
|
+
await updateCache(ctx, deps, [entry]);
|
|
5168
|
+
}
|
|
5169
|
+
if (deps.output.mode === "json") printResult(entry, "json");
|
|
5170
|
+
else process.stdout.write(formatMemory(entry));
|
|
5171
|
+
});
|
|
5172
|
+
memory.command("put <file>").option("--new").option("--no-ai", "skip AI cleanup (Pro+)").action(async (file, opts) => {
|
|
5173
|
+
const draft = parseMemory(await inputText(file));
|
|
5174
|
+
const scope = parseScope(draft.scope);
|
|
5175
|
+
validateDraft(draft);
|
|
5176
|
+
const ctx = await context2(deps, true);
|
|
5177
|
+
if (scope === "branch" && (!ctx.git.branch || !ctx.git.repoIdentity || ctx.git.branch === ctx.git.defaultBranch || ["main", "master"].includes(ctx.git.branch) && !ctx.git.defaultBranch)) throw new CliError("branch \u30B9\u30B3\u30FC\u30D7\u306F\u4F5C\u696D\u30D6\u30E9\u30F3\u30C1\u3067\u3060\u3051\u4F7F\u3048\u307E\u3059\u3002", 2, "\u4F5C\u696D\u30D6\u30E9\u30F3\u30C1\u306B\u5207\u308A\u66FF\u3048\u308B(git switch -c <branch>)\u304B\u3001scope \u3092 project / user \u306B\u3059\u308B");
|
|
5178
|
+
if (scope === "branch" && draft.branch !== void 0 && draft.branch !== ctx.git.branch) throw new CliError(`branch ${draft.branch} \u304C\u4ECA\u306E\u30D6\u30E9\u30F3\u30C1 ${ctx.git.branch} \u3068\u7570\u306A\u308A\u307E\u3059\u3002`, 2, `frontmatter \u306E branch \u3092\u6D88\u3059\u304B ${ctx.git.branch} \u306B\u3059\u308B`);
|
|
5179
|
+
const response = await apiCall(deps, ctx, () => deps.http.put(ctx.api, {
|
|
5180
|
+
scope,
|
|
5181
|
+
name: draft.name,
|
|
5182
|
+
description: draft.description,
|
|
5183
|
+
body: draft.body,
|
|
5184
|
+
...draft.type ? { type: draft.type } : {},
|
|
5185
|
+
...draft.revision !== void 0 ? { baseRevision: parseRevision(draft.revision) } : {},
|
|
5186
|
+
...opts.new ? { allowNew: true } : {},
|
|
5187
|
+
...opts.ai === false ? { aiSkip: true } : {},
|
|
5188
|
+
...scope === "branch" ? { repoIdentity: ctx.git.repoIdentity, branch: ctx.git.branch } : {}
|
|
5189
|
+
}, headers()), "put", draft.name);
|
|
5190
|
+
await updateCache(ctx, deps, writtenEntries(ctx, response));
|
|
5191
|
+
printWrite(deps, ctx, "put", response, draft.revision === void 0);
|
|
5192
|
+
});
|
|
5193
|
+
memory.command("rm <name>").option("--scope <scope>").option("--branch <branch>", "branch entry of the current repo").action(async (name, opts) => {
|
|
5194
|
+
const ctx = await context2(deps);
|
|
5195
|
+
const entry = resolveEntry(ctx, name, opts);
|
|
5196
|
+
const response = await apiCall(deps, ctx, () => deps.http.delete(`${ctx.api}/${encodeURIComponent(entry.id)}?baseRevision=${entry.revision}`, headers()), "rm", name);
|
|
5197
|
+
await updateCache(ctx, deps, writtenEntries(ctx, response));
|
|
5198
|
+
printWrite(deps, ctx, "rm", response);
|
|
5199
|
+
});
|
|
5200
|
+
memory.command("revert <name> <revision>").option("--scope <scope>").option("--branch <branch>", "branch entry of the current repo").action(async (name, revision, opts) => {
|
|
5201
|
+
const ctx = await context2(deps);
|
|
5202
|
+
const entry = resolveEntry(ctx, name, opts, true);
|
|
5203
|
+
const response = await apiCall(deps, ctx, () => deps.http.post(`${ctx.api}/${encodeURIComponent(entry.id)}/revert`, { revision: parseRevision(revision), baseRevision: entry.revision }, headers()), "revert", name);
|
|
5204
|
+
await updateCache(ctx, deps, writtenEntries(ctx, response));
|
|
5205
|
+
printWrite(deps, ctx, "revert", response);
|
|
5206
|
+
});
|
|
5207
|
+
memory.command("log <name>").option("--scope <scope>").option("--branch <branch>", "branch entry of the current repo").action(async (name, opts) => {
|
|
5208
|
+
const ctx = await context2(deps);
|
|
5209
|
+
const entry = resolveEntry(ctx, name, opts, true);
|
|
5210
|
+
const names = new Map(ctx.cache.state.entries.flatMap((e) => e.updatedBy?.name ? [[e.updatedBy.id, e.updatedBy.name]] : []));
|
|
5211
|
+
const response = await apiCall(deps, ctx, () => deps.http.get(`${ctx.api}/${encodeURIComponent(entry.id)}/revisions`));
|
|
5212
|
+
printResult(deps.output.mode === "json" ? response : response.revisions.map((r) => `r${r.revision} ${r.source}${r.revertOf ? ` \u2190 r${r.revertOf}` : r.fromBranch ? ` \u2190 ${oneLine(r.fromBranch)}` : ""} ${r.createdAt} ${r.actorUserId ? oneLine(names.get(r.actorUserId) ?? r.actorUserId) : "\u4E0D\u660E"} (${oneLine(memoryClient(r.via))})${r.aiReason ? ` \u2014 ${oneLine(r.aiReason)}` : ""}`).join("\n"), deps.output.mode);
|
|
5213
|
+
});
|
|
5214
|
+
memory.command("promote [names...]").requiredOption("--branch <branch>").option("--all").option("--discard").action(async (names, opts) => {
|
|
5215
|
+
if (opts.all && names.length) throw new CliError("--all \u3068 name \u306F\u540C\u6642\u306B\u6307\u5B9A\u3067\u304D\u307E\u305B\u3093\u3002", 2);
|
|
5216
|
+
const ctx = await context2(deps);
|
|
5217
|
+
if (!ctx.git.repoIdentity) throw new CliError("repo \u3092\u8B58\u5225\u3067\u304D\u307E\u305B\u3093\u3002", 2);
|
|
5218
|
+
const selected = ctx.cache.state.entries.filter((e) => !e.deleted && e.scope === "branch" && e.repoIdentity === ctx.git.repoIdentity && e.branch === opts.branch && (!names.length || names.includes(e.name)));
|
|
5219
|
+
if (!opts.all && !names.length) {
|
|
5220
|
+
printResult(deps.output.mode === "json" ? selected : selected.length ? selected.map(line).join("\n") : `branch ${opts.branch} \u306E\u30E1\u30E2\u30EA\u306F\u30AD\u30E3\u30C3\u30B7\u30E5\u306B\u3042\u308A\u307E\u305B\u3093(nolto memory pull \u3067\u66F4\u65B0)`, deps.output.mode);
|
|
5221
|
+
return;
|
|
5222
|
+
}
|
|
5223
|
+
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");
|
|
5224
|
+
const retired = selected.map((e) => ({ ...e, deleted: true }));
|
|
5225
|
+
await updateCache(ctx, deps, [...retired, ...response.promoted, ...response.discarded]);
|
|
5226
|
+
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);
|
|
5227
|
+
});
|
|
5228
|
+
memory.command("hook").command("install").option("--agent <agent>").option("--write-agents-md").action(async (opts) => {
|
|
5229
|
+
const { root } = findRepoRoot(resolveStartDir(process.env, process.cwd()));
|
|
5230
|
+
const messages = await installMemoryHooks(root, opts.agent, opts.writeAgentsMd);
|
|
5231
|
+
printResult(deps.output.mode === "json" ? { messages } : messages.join("\n"), deps.output.mode);
|
|
5232
|
+
});
|
|
5233
|
+
memory.command("import <dir>").description("Import memory files. AI cleanup is off by default (--ai to use it).").requiredOption("--scope <scope>").option("--ai", "use AI cleanup (Pro+)").action(async (dir, opts) => {
|
|
5234
|
+
const scope = parseScope(opts.scope, "--scope project|user");
|
|
5235
|
+
if (scope === "branch") throw new CliError("branch \u30B9\u30B3\u30FC\u30D7\u3078\u306E import \u306F\u3067\u304D\u307E\u305B\u3093\u3002", 2, "--scope project|user");
|
|
5236
|
+
const ctx = await context2(deps, true);
|
|
5237
|
+
const scan = await scanMemoryDir(dir);
|
|
5238
|
+
const lines = /* @__PURE__ */ new Map();
|
|
5239
|
+
let position = 0;
|
|
5240
|
+
const result = await importMemoryFiles({
|
|
5241
|
+
http: deps.http,
|
|
5242
|
+
projectId: ctx.project,
|
|
5243
|
+
configPath: deps.configPath,
|
|
5244
|
+
root: ctx.root,
|
|
5245
|
+
scope,
|
|
5246
|
+
targets: scan.ok,
|
|
5247
|
+
ai: opts.ai,
|
|
5248
|
+
git: ctx.git,
|
|
5249
|
+
memoryGit: deps.memoryGit,
|
|
5250
|
+
write: (line2) => {
|
|
5251
|
+
lines.set(scan.ok[position++].file, line2);
|
|
5252
|
+
}
|
|
5253
|
+
});
|
|
5254
|
+
const { imported, skipped, cached } = result;
|
|
5255
|
+
const failed = result.failed + scan.invalid.length;
|
|
5256
|
+
const results = [...result.results, ...scan.invalid].sort((a, b) => a.file.localeCompare(b.file));
|
|
5257
|
+
if (deps.output.mode !== "json") {
|
|
5258
|
+
for (const item of results) process.stdout.write((lines.get(item.file) ?? importResultLine(scope, item)) + "\n");
|
|
5259
|
+
}
|
|
5260
|
+
const skippedNames = results.filter((r) => r.status === "skipped").map((r) => `${scope}/${String(r.name)}`);
|
|
5261
|
+
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(", ")}
|
|
5262
|
+
`);
|
|
5263
|
+
printResult(deps.output.mode === "json" ? { imported, skipped, failed, results } : `imported ${imported}, skipped ${skipped}, failed ${failed}`, deps.output.mode);
|
|
5264
|
+
if (!cached) process.stderr.write(cacheWarning);
|
|
5265
|
+
if (failed) process.exitCode = 2;
|
|
5266
|
+
});
|
|
5267
|
+
}
|
|
5268
|
+
|
|
4331
5269
|
// src/program.ts
|
|
4332
5270
|
function stripCommanderErrorPrefix(msg) {
|
|
4333
5271
|
return msg.startsWith("error: ") ? msg.slice("error: ".length) : msg;
|
|
@@ -4336,6 +5274,7 @@ function buildProgram(deps) {
|
|
|
4336
5274
|
const writeErr = (_msg) => {
|
|
4337
5275
|
};
|
|
4338
5276
|
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");
|
|
5277
|
+
register13(program, deps);
|
|
4339
5278
|
register(program, deps);
|
|
4340
5279
|
register3(program, deps);
|
|
4341
5280
|
register4(program, deps);
|
|
@@ -4352,6 +5291,7 @@ function buildProgram(deps) {
|
|
|
4352
5291
|
program.help();
|
|
4353
5292
|
});
|
|
4354
5293
|
program.hook("preAction", (_thisCommand, actionCommand) => {
|
|
5294
|
+
if (actionCommand.parent?.name() === "memory" && actionCommand.name() === "pull" && actionCommand.opts().hook) return;
|
|
4355
5295
|
const bindingError = deps.repoBinding?.error;
|
|
4356
5296
|
const bindingExemptCommands = ["init", "link", "update", "merge-file"];
|
|
4357
5297
|
if (bindingError != null && !(actionCommand.parent === program && bindingExemptCommands.includes(actionCommand.name()))) {
|
|
@@ -4362,11 +5302,11 @@ function buildProgram(deps) {
|
|
|
4362
5302
|
}
|
|
4363
5303
|
|
|
4364
5304
|
// src/index.ts
|
|
4365
|
-
var __dirname3 =
|
|
5305
|
+
var __dirname3 = path24.dirname(fileURLToPath4(import.meta.url));
|
|
4366
5306
|
var require2 = createRequire3(import.meta.url);
|
|
4367
5307
|
function getVersion() {
|
|
4368
5308
|
try {
|
|
4369
|
-
const pkgPath =
|
|
5309
|
+
const pkgPath = path24.resolve(__dirname3, "../package.json");
|
|
4370
5310
|
const pkg = require2(pkgPath);
|
|
4371
5311
|
return pkg.version ?? "0.0.0";
|
|
4372
5312
|
} catch {
|
|
@@ -4374,6 +5314,8 @@ function getVersion() {
|
|
|
4374
5314
|
}
|
|
4375
5315
|
}
|
|
4376
5316
|
var mode = "human";
|
|
5317
|
+
var memoryHook = hookAgentFromArgv(process.argv.slice(2));
|
|
5318
|
+
if (memoryHook) process.stderr.write = (() => true);
|
|
4377
5319
|
async function main() {
|
|
4378
5320
|
const argv = process.argv.slice(2);
|
|
4379
5321
|
const flagToken = extractFlag(argv, "--token");
|
|
@@ -4381,22 +5323,12 @@ async function main() {
|
|
|
4381
5323
|
const flagProject = extractFlag(argv, "--project");
|
|
4382
5324
|
mode = argv.includes("--json") ? "json" : "human";
|
|
4383
5325
|
const configPath = getConfigPath(process.env);
|
|
4384
|
-
const configFile = await loadConfigFile(configPath)
|
|
4385
|
-
if (err instanceof CliError) {
|
|
4386
|
-
printError(err, mode);
|
|
4387
|
-
process.exitCode = err.exitCode;
|
|
4388
|
-
process.exit();
|
|
4389
|
-
}
|
|
4390
|
-
throw err;
|
|
4391
|
-
});
|
|
5326
|
+
const configFile = await loadConfigFile(configPath);
|
|
4392
5327
|
if (flagBaseUrl != null) {
|
|
4393
5328
|
try {
|
|
4394
5329
|
new URL(flagBaseUrl);
|
|
4395
5330
|
} catch {
|
|
4396
|
-
|
|
4397
|
-
printError(err, mode);
|
|
4398
|
-
process.exitCode = 2;
|
|
4399
|
-
process.exit();
|
|
5331
|
+
throw new CliError(`Invalid base URL: ${flagBaseUrl}`, 2);
|
|
4400
5332
|
}
|
|
4401
5333
|
}
|
|
4402
5334
|
const projectBindingPath = findRepoBindingFile({ env: process.env, cwd: process.cwd() });
|
|
@@ -4428,10 +5360,15 @@ async function main() {
|
|
|
4428
5360
|
output: { mode },
|
|
4429
5361
|
version,
|
|
4430
5362
|
configPath,
|
|
5363
|
+
claudeProjectsDir: path24.join(process.env.CLAUDE_CONFIG_DIR ?? path24.join(os5.homedir(), ".claude"), "projects"),
|
|
5364
|
+
homeSkillDirs: [
|
|
5365
|
+
path24.join(process.env.CLAUDE_CONFIG_DIR ?? path24.join(os5.homedir(), ".claude"), "skills"),
|
|
5366
|
+
path24.join(os5.homedir(), ".agents", "skills")
|
|
5367
|
+
],
|
|
4431
5368
|
repoBinding
|
|
4432
5369
|
});
|
|
4433
5370
|
await program.parseAsync(process.argv);
|
|
4434
|
-
await notifyUpdate({ current: version, env: process.env, isJson: mode === "json", now: Date.now() });
|
|
5371
|
+
if (!memoryHook) await notifyUpdate({ current: version, env: process.env, isJson: mode === "json", now: Date.now() });
|
|
4435
5372
|
}
|
|
4436
5373
|
function extractFlag(argv, name) {
|
|
4437
5374
|
const idx = argv.indexOf(name);
|
|
@@ -4441,6 +5378,11 @@ function extractFlag(argv, name) {
|
|
|
4441
5378
|
return void 0;
|
|
4442
5379
|
}
|
|
4443
5380
|
main().catch((err) => {
|
|
5381
|
+
if (memoryHook) {
|
|
5382
|
+
process.stdout.write(hookOutput(memoryHook, "nolto memory pull \u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044"));
|
|
5383
|
+
process.exitCode = 0;
|
|
5384
|
+
return;
|
|
5385
|
+
}
|
|
4444
5386
|
if (err instanceof CommanderError) {
|
|
4445
5387
|
if (err.exitCode === 0) {
|
|
4446
5388
|
process.exit(0);
|