@nolto/cli 0.19.3 → 0.19.4
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 +5 -5
- package/dist/index.js +1996 -2021
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -218,12 +218,7 @@ async function checkSkillDrift(repoRoot, opts = {}) {
|
|
|
218
218
|
for (const parent of [".claude", ".agents"]) {
|
|
219
219
|
const dir = path.join(repoRoot, parent, "skills", name);
|
|
220
220
|
if (!existsSync(dir)) continue;
|
|
221
|
-
|
|
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("/"));
|
|
221
|
+
if (await skillContentHash(dir) !== sourceHash) drifted.push(path.relative(repoRoot, dir).split(path.sep).join("/"));
|
|
227
222
|
}
|
|
228
223
|
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
224
|
for (const parent of opts.homeSkillDirs ?? []) {
|
|
@@ -249,6 +244,10 @@ async function installSkill(args) {
|
|
|
249
244
|
if (dirExists && installedHash === sourceHash && args.force !== true) {
|
|
250
245
|
return { action: "skipped", targetDir };
|
|
251
246
|
}
|
|
247
|
+
if (dirExists && args.force !== true && await skillContentHash(targetDir) === sourceHash) {
|
|
248
|
+
await writeFile(markerPath, sourceHash + "\n", "utf8");
|
|
249
|
+
return { action: "updated", targetDir };
|
|
250
|
+
}
|
|
252
251
|
await rm(targetDir, { recursive: true, force: true });
|
|
253
252
|
await mkdir(args.skillsParentDir, { recursive: true });
|
|
254
253
|
await cp(args.sourceDir, targetDir, { recursive: true });
|
|
@@ -387,7 +386,7 @@ ${MEMORY_INSTRUCTIONS}
|
|
|
387
386
|
// src/index.ts
|
|
388
387
|
import { createRequire as createRequire3 } from "module";
|
|
389
388
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
390
|
-
import
|
|
389
|
+
import path23 from "path";
|
|
391
390
|
import os5 from "os";
|
|
392
391
|
import { CommanderError } from "commander";
|
|
393
392
|
|
|
@@ -606,11 +605,11 @@ function maskToken(token) {
|
|
|
606
605
|
function createHttpClient(opts) {
|
|
607
606
|
const { baseUrl, version, token } = opts;
|
|
608
607
|
const base = baseUrl.replace(/\/+$/, "");
|
|
609
|
-
async function request(method,
|
|
610
|
-
if (!
|
|
611
|
-
throw new CliError(`HTTP client path must start with /api/, got: ${
|
|
608
|
+
async function request(method, path24, body, extraHeaders, signal) {
|
|
609
|
+
if (!path24.startsWith("/api/")) {
|
|
610
|
+
throw new CliError(`HTTP client path must start with /api/, got: ${path24}`, 2);
|
|
612
611
|
}
|
|
613
|
-
const url = `${base}${
|
|
612
|
+
const url = `${base}${path24}`;
|
|
614
613
|
const headers2 = {
|
|
615
614
|
...extraHeaders,
|
|
616
615
|
"Content-Type": "application/json",
|
|
@@ -683,9 +682,7 @@ function createHttpClient(opts) {
|
|
|
683
682
|
import { Command } from "commander";
|
|
684
683
|
|
|
685
684
|
// src/commands/issue.ts
|
|
686
|
-
import { readFile as
|
|
687
|
-
import path4 from "path";
|
|
688
|
-
import { randomUUID } from "crypto";
|
|
685
|
+
import { readFile as readFile10 } from "fs/promises";
|
|
689
686
|
|
|
690
687
|
// src/output.ts
|
|
691
688
|
function printResult(value, mode2, opts = {}) {
|
|
@@ -750,6 +747,66 @@ function formatValue(value) {
|
|
|
750
747
|
return JSON.stringify(value, null, 2);
|
|
751
748
|
}
|
|
752
749
|
|
|
750
|
+
// src/watch-state.ts
|
|
751
|
+
import * as fs from "fs/promises";
|
|
752
|
+
import { randomUUID } from "crypto";
|
|
753
|
+
import path4 from "path";
|
|
754
|
+
import { z as z2 } from "zod";
|
|
755
|
+
var watchStateSchema = z2.object({
|
|
756
|
+
pid: z2.number().int().positive(),
|
|
757
|
+
version: z2.string().min(1),
|
|
758
|
+
startedAt: z2.string().datetime()
|
|
759
|
+
});
|
|
760
|
+
function getWatchStatePath(env) {
|
|
761
|
+
return path4.join(getConfigDir(env), "watch.json");
|
|
762
|
+
}
|
|
763
|
+
async function readWatchState(filePath, io = fs) {
|
|
764
|
+
try {
|
|
765
|
+
const result = watchStateSchema.safeParse(JSON.parse(await io.readFile(filePath, "utf8")));
|
|
766
|
+
return result.success ? result.data : null;
|
|
767
|
+
} catch {
|
|
768
|
+
return null;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
async function writeWatchState(filePath, state, io = fs) {
|
|
772
|
+
await io.mkdir(path4.dirname(filePath), { recursive: true, mode: 448 });
|
|
773
|
+
const tempPath = `${filePath}.tmp-${process.pid}-${randomUUID()}`;
|
|
774
|
+
try {
|
|
775
|
+
await io.writeFile(tempPath, JSON.stringify(state, null, 2) + "\n", { encoding: "utf8", mode: 384 });
|
|
776
|
+
await io.rename(tempPath, filePath);
|
|
777
|
+
} catch (error) {
|
|
778
|
+
await io.unlink(tempPath).catch(() => void 0);
|
|
779
|
+
throw error;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
async function removeWatchState(filePath, pid, io = fs) {
|
|
783
|
+
if ((await readWatchState(filePath, io))?.pid === pid) {
|
|
784
|
+
await io.unlink(filePath).catch(() => void 0);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
function isAlive(pid, kill = process.kill) {
|
|
788
|
+
try {
|
|
789
|
+
kill(pid, 0);
|
|
790
|
+
return true;
|
|
791
|
+
} catch (error) {
|
|
792
|
+
if (error.code === "ESRCH") return false;
|
|
793
|
+
if (error.code === "EPERM") return true;
|
|
794
|
+
throw error;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
async function staleWatchWarning(env, currentVersion, kill = process.kill) {
|
|
798
|
+
const state = await readWatchState(getWatchStatePath(env));
|
|
799
|
+
if (!state || state.version === currentVersion || !isAlive(state.pid, kill)) return null;
|
|
800
|
+
return `Warning: nolto watch (pid ${state.pid}) is running CLI v${state.version}, this CLI is v${currentVersion}. Restart it: nolto watch stop, then start it again (or nolto update).`;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
// src/roadmap-commands.ts
|
|
804
|
+
import path14 from "path";
|
|
805
|
+
import { existsSync as existsSync5 } from "fs";
|
|
806
|
+
import { readFile as readFile9, readdir as readdir4, writeFile as writeFile7, rename as rename3, unlink as unlink3, realpath as realpath3 } from "fs/promises";
|
|
807
|
+
import { randomUUID as randomUUID5 } from "crypto";
|
|
808
|
+
import readline2 from "readline/promises";
|
|
809
|
+
|
|
753
810
|
// ../roadmap-schema/src/repo-identity.ts
|
|
754
811
|
var HOSTED_LOWERCASE_PATH = /* @__PURE__ */ new Set(["github.com", "gitlab.com", "bitbucket.org"]);
|
|
755
812
|
function normalizeRemote(raw) {
|
|
@@ -769,12 +826,12 @@ function normalizeRemote(raw) {
|
|
|
769
826
|
const firstSlash = s.indexOf("/");
|
|
770
827
|
if (firstSlash <= 0) return null;
|
|
771
828
|
let host = s.slice(0, firstSlash).toLowerCase();
|
|
772
|
-
let
|
|
829
|
+
let path24 = s.slice(firstSlash + 1);
|
|
773
830
|
if (hadScheme) host = host.replace(/:\d+$/, "");
|
|
774
|
-
|
|
775
|
-
if (
|
|
776
|
-
if (HOSTED_LOWERCASE_PATH.has(host))
|
|
777
|
-
return `${host}/${
|
|
831
|
+
path24 = path24.replace(/\/+/g, "/").replace(/^\/+/, "").replace(/\/+$/, "").replace(/\.git$/i, "").replace(/\/+$/, "");
|
|
832
|
+
if (path24.length === 0) return null;
|
|
833
|
+
if (HOSTED_LOWERCASE_PATH.has(host)) path24 = path24.toLowerCase();
|
|
834
|
+
return `${host}/${path24}`;
|
|
778
835
|
}
|
|
779
836
|
function repoIdentityToString(id) {
|
|
780
837
|
return `${id.kind}:${id.value}`;
|
|
@@ -988,10 +1045,11 @@ function deriveTaskStats(roadmap) {
|
|
|
988
1045
|
let inProgress = 0;
|
|
989
1046
|
let todo = 0;
|
|
990
1047
|
for (const phase of roadmap.phases) {
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
else if (
|
|
1048
|
+
const items = phase.tasks.length > 0 ? phase.tasks : [phase];
|
|
1049
|
+
for (const item of items) {
|
|
1050
|
+
if (item.status === "done") done += 1;
|
|
1051
|
+
else if (item.status === "blocked") blocked += 1;
|
|
1052
|
+
else if (item.status === "in-progress") inProgress += 1;
|
|
995
1053
|
else todo += 1;
|
|
996
1054
|
}
|
|
997
1055
|
}
|
|
@@ -1112,14 +1170,14 @@ function formatIssueView(bundle) {
|
|
|
1112
1170
|
${comment.deletedAt ? "\u30B3\u30E1\u30F3\u30C8\u306F\u524A\u9664\u3055\u308C\u3066\u3044\u307E\u3059\u3002" : comment.body}`);
|
|
1113
1171
|
return [attributes, issue.body, ...comments].join("\n\n");
|
|
1114
1172
|
}
|
|
1115
|
-
function addIssueToRoadmapTask(roadmapJson, taskId, key
|
|
1173
|
+
function addIssueToRoadmapTask(roadmapJson, taskId, key) {
|
|
1116
1174
|
const validation = validateRoadmap(roadmapJson);
|
|
1117
1175
|
if (validation.errors.length) return { error: `Invalid roadmap: ${validation.errors.join("; ")}` };
|
|
1118
1176
|
const input = roadmapJson;
|
|
1119
1177
|
const target = input.phases.flatMap((phase) => phase.tasks).find((task) => task.id === taskId);
|
|
1120
1178
|
if (!target) return { error: `roadmap task ${taskId} was not found` };
|
|
1121
1179
|
if (target.issues?.includes(key)) return { roadmap: input, changed: false };
|
|
1122
|
-
const roadmap = { ...input,
|
|
1180
|
+
const roadmap = { ...input, phases: input.phases.map((phase) => ({
|
|
1123
1181
|
...phase,
|
|
1124
1182
|
tasks: phase.tasks.map((task) => task.id === taskId ? { ...task, issues: [...task.issues ?? [], key] } : task)
|
|
1125
1183
|
})) };
|
|
@@ -1133,429 +1191,430 @@ function draftUrl(baseUrl, projectId, id) {
|
|
|
1133
1191
|
return `${baseUrl.replace(/\/+$/, "")}/projects/${encodeURIComponent(projectId)}/issues/drafts/${id}`;
|
|
1134
1192
|
}
|
|
1135
1193
|
|
|
1136
|
-
// src/
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
mode: globals.json ? "json" : deps.output.mode
|
|
1147
|
-
};
|
|
1194
|
+
// src/roadmap-cache.ts
|
|
1195
|
+
import { mkdir as mkdir4, readdir as readdir2, readFile as readFile4, writeFile as writeFile4, rename, unlink } from "fs/promises";
|
|
1196
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
1197
|
+
import path6 from "path";
|
|
1198
|
+
|
|
1199
|
+
// src/sync-core.ts
|
|
1200
|
+
import { createHash as createHash2 } from "crypto";
|
|
1201
|
+
import path5 from "path";
|
|
1202
|
+
function sha256Hex(content) {
|
|
1203
|
+
return "sha256:" + createHash2("sha256").update(content, "utf8").digest("hex");
|
|
1148
1204
|
}
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
if (
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1205
|
+
function collectPlanRefs(roadmap) {
|
|
1206
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1207
|
+
const refs = [];
|
|
1208
|
+
for (const phase of roadmap.phases) {
|
|
1209
|
+
if (phase.plan != null && !seen.has(phase.plan)) {
|
|
1210
|
+
seen.add(phase.plan);
|
|
1211
|
+
refs.push({ path: phase.plan, ownerId: phase.id });
|
|
1212
|
+
}
|
|
1213
|
+
for (const task of phase.tasks) {
|
|
1214
|
+
if (task.plan != null && !seen.has(task.plan)) {
|
|
1215
|
+
seen.add(task.plan);
|
|
1216
|
+
refs.push({ path: task.plan, ownerId: task.id });
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1159
1219
|
}
|
|
1220
|
+
return refs;
|
|
1160
1221
|
}
|
|
1161
|
-
async function
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
if (flags.assignee !== void 0) {
|
|
1168
|
-
if (flags.assignee === "none") assigneeId = null;
|
|
1169
|
-
else if (flags.assignee === "me") assigneeId = (await deps.http.get("/api/me/profile")).profile.id;
|
|
1170
|
-
else if (isUuid(flags.assignee)) assigneeId = flags.assignee;
|
|
1171
|
-
else throw new CliError("--assignee must be me, none or a UUID.", 2);
|
|
1222
|
+
async function loadValidRoadmap(filePath, readFile19) {
|
|
1223
|
+
let raw;
|
|
1224
|
+
try {
|
|
1225
|
+
raw = await readFile19(filePath);
|
|
1226
|
+
} catch {
|
|
1227
|
+
throw new CliError(`No roadmap found at ${filePath}. Run \`nolto init\` first.`, 2);
|
|
1172
1228
|
}
|
|
1173
|
-
let
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
throw new CliError(
|
|
1229
|
+
let parsed;
|
|
1230
|
+
try {
|
|
1231
|
+
parsed = JSON.parse(raw);
|
|
1232
|
+
} catch {
|
|
1233
|
+
throw new CliError(`Malformed JSON in ${filePath}.`, 2);
|
|
1178
1234
|
}
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
...flags.category !== void 0 ? { categoryIds: flags.category.map((name) => resolveMaster("category", name, settings).id) } : {},
|
|
1189
|
-
...parentId !== void 0 ? { parentId } : {},
|
|
1190
|
-
...flags.comment !== void 0 ? { comment: flags.comment } : {}
|
|
1191
|
-
};
|
|
1192
|
-
if (Object.keys(input).length === 0) throw new CliError("No changes. Pass a field option or --comment.", 2);
|
|
1193
|
-
return { input, fromTemplate: template != null };
|
|
1194
|
-
}
|
|
1195
|
-
function localTimestamp() {
|
|
1196
|
-
const date = /* @__PURE__ */ new Date();
|
|
1197
|
-
const minutes = -date.getTimezoneOffset();
|
|
1198
|
-
const pad = (value) => String(Math.abs(value)).padStart(2, "0");
|
|
1199
|
-
return `${new Date(date.getTime() + minutes * 6e4).toISOString().slice(0, -1)}${minutes >= 0 ? "+" : "-"}${pad(Math.trunc(minutes / 60))}:${pad(minutes % 60)}`;
|
|
1235
|
+
const { errors } = validateRoadmap(parsed);
|
|
1236
|
+
if (errors.length > 0) {
|
|
1237
|
+
throw new CliError(
|
|
1238
|
+
`${filePath} failed validation \u2014 not syncing:
|
|
1239
|
+
${errors.join("\n ")}`,
|
|
1240
|
+
2
|
|
1241
|
+
);
|
|
1242
|
+
}
|
|
1243
|
+
return parsed;
|
|
1200
1244
|
}
|
|
1201
|
-
async function
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
if (error.code !== "ENOENT" || path4.dirname(directory) === directory) throw error;
|
|
1213
|
-
directory = path4.dirname(directory);
|
|
1245
|
+
async function buildSyncBody(args) {
|
|
1246
|
+
const planDocuments = [];
|
|
1247
|
+
for (const ref of collectPlanRefs(args.roadmap)) {
|
|
1248
|
+
if (!isValidPlanPath(ref.path)) {
|
|
1249
|
+
args.deps.warn(`plan path not allowed (markdown only, no dot segments), skipping: ${ref.path}`);
|
|
1250
|
+
continue;
|
|
1251
|
+
}
|
|
1252
|
+
try {
|
|
1253
|
+
if (await args.deps.isIgnored?.(args.repoRoot, ref.path)) {
|
|
1254
|
+
args.deps.warn(`plan path is git-ignored, skipping: ${ref.path}`);
|
|
1255
|
+
continue;
|
|
1214
1256
|
}
|
|
1257
|
+
} catch {
|
|
1258
|
+
}
|
|
1259
|
+
const root = path5.resolve(args.repoRoot);
|
|
1260
|
+
const absolute = path5.resolve(root, ref.path);
|
|
1261
|
+
if (absolute !== root && !absolute.startsWith(root + path5.sep)) {
|
|
1262
|
+
args.deps.warn(`plan path outside repository root, skipping: ${ref.path}`);
|
|
1263
|
+
continue;
|
|
1264
|
+
}
|
|
1265
|
+
if (!args.deps.fileExists(absolute)) {
|
|
1266
|
+
args.deps.warn(`plan file not found, skipping: ${ref.path}`);
|
|
1267
|
+
continue;
|
|
1215
1268
|
}
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
const result = addIssueToRoadmapTask(JSON.parse(await readFile4(file, "utf8")), taskId, key, localTimestamp());
|
|
1220
|
-
if ("error" in result) throw new Error(`${result.error} in ${file}`);
|
|
1221
|
-
if (result.changed) {
|
|
1222
|
-
const temp = `${file}.${randomUUID()}.tmp`;
|
|
1269
|
+
if (args.deps.realpath !== void 0) {
|
|
1270
|
+
let real;
|
|
1271
|
+
let realRoot;
|
|
1223
1272
|
try {
|
|
1224
|
-
await
|
|
1225
|
-
await
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1273
|
+
real = await args.deps.realpath(absolute);
|
|
1274
|
+
realRoot = await args.deps.realpath(root);
|
|
1275
|
+
} catch {
|
|
1276
|
+
args.deps.warn(`plan file not found, skipping: ${ref.path}`);
|
|
1277
|
+
continue;
|
|
1278
|
+
}
|
|
1279
|
+
if (real !== realRoot && !real.startsWith(realRoot + path5.sep)) {
|
|
1280
|
+
args.deps.warn(`symlink escapes repository root, skipping: ${ref.path}`);
|
|
1281
|
+
continue;
|
|
1282
|
+
}
|
|
1283
|
+
if (!isValidPlanPath(path5.relative(realRoot, real).split(path5.sep).join("/"))) {
|
|
1284
|
+
args.deps.warn(`plan path not allowed (markdown only, no dot segments), skipping: ${ref.path}`);
|
|
1285
|
+
continue;
|
|
1228
1286
|
}
|
|
1229
1287
|
}
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
);
|
|
1288
|
+
const content = await args.deps.readFile(absolute);
|
|
1289
|
+
planDocuments.push({
|
|
1290
|
+
path: ref.path,
|
|
1291
|
+
taskId: ref.ownerId,
|
|
1292
|
+
content,
|
|
1293
|
+
contentHash: sha256Hex(content)
|
|
1294
|
+
});
|
|
1238
1295
|
}
|
|
1296
|
+
return { roadmap: args.roadmap, planDocuments, repoIdentity: args.repoIdentity };
|
|
1239
1297
|
}
|
|
1240
|
-
function
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1298
|
+
async function runSync(args, deps) {
|
|
1299
|
+
const body = await buildSyncBody({
|
|
1300
|
+
roadmap: args.roadmap,
|
|
1301
|
+
repoRoot: args.repoRoot,
|
|
1302
|
+
repoIdentity: args.repoIdentity,
|
|
1303
|
+
deps
|
|
1304
|
+
});
|
|
1305
|
+
const response = await deps.http.put(
|
|
1306
|
+
`/api/projects/${args.projectId}/roadmaps/${args.slug}`,
|
|
1307
|
+
{ ...body, baseRevision: args.baseRevision }
|
|
1308
|
+
);
|
|
1309
|
+
for (const warning of response.warnings ?? []) deps.warn(warning);
|
|
1310
|
+
const stats = deriveTaskStats(response.roadmap ?? args.roadmap);
|
|
1311
|
+
deps.log(
|
|
1312
|
+
`Synced ${args.slug}${response.merged ? " (merged with server changes)" : ""}: ${stats.done}/${stats.total} done \u2014 docs upserted ${response.documents.upserted}, unchanged ${response.documents.unchanged}, deleted ${response.documents.deleted}${response.issues ? `, issues linked ${response.issues.linked} (skipped ${response.issues.skipped})` : ""}`
|
|
1313
|
+
);
|
|
1314
|
+
return response;
|
|
1247
1315
|
}
|
|
1248
|
-
function register(program, deps) {
|
|
1249
|
-
const group = program.command("issue").description("List, view and manage project issues.").addHelpText("after", `
|
|
1250
|
-
All commands accept global \`--project <id>\`, \`--json\`, \`--token <value>\` and \`--base-url <url>\`.
|
|
1251
|
-
Project priority: flag \u2192 NOLTO_PROJECT \u2192 nearest ancestor nolto.json \u2192 config defaultProjectId. Git is not required. An invalid nolto.json remains an error.
|
|
1252
1316
|
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
| 0 | Success |
|
|
1260
|
-
| 2 | Invalid input, recognized API 404, HTTP 422 (details shown), or local roadmap failure after creation |
|
|
1261
|
-
| 3 | HTTP 401/403; token_scope/token_project includes a token settings hint |
|
|
1262
|
-
| 4 | HTTP 402/429 (quota/rate limit). API token writes: 60/minute. On 429, wait Retry-After seconds before retrying. |
|
|
1263
|
-
| 5 | Network/generic HTTP errors, including a 404 without an API error string |
|
|
1264
|
-
`);
|
|
1265
|
-
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) => {
|
|
1266
|
-
const ctx = context(deps, command);
|
|
1267
|
-
const settings = flags.status || flags.type || flags.category ? await deps.http.get(`${ctx.root}/issue-settings`) : emptySettings;
|
|
1268
|
-
const query = buildListQuery(flags, settings).toString();
|
|
1269
|
-
const result = await deps.http.get(`${ctx.root}/issues${query ? `?${query}` : ""}`);
|
|
1270
|
-
printResult(ctx.mode === "json" ? result : formatIssueList(result.issues, result), ctx.mode);
|
|
1271
|
-
});
|
|
1272
|
-
group.command("view <ref>").description("Show issue details and comments.").action(async (ref, _flags, command) => {
|
|
1273
|
-
const ctx = context(deps, command);
|
|
1274
|
-
const result = await deps.http.get(`${ctx.root}/issues/${parseIssueRef(ref)}`);
|
|
1275
|
-
printResult(ctx.mode === "json" ? result : formatIssueView(result), ctx.mode);
|
|
1276
|
-
});
|
|
1277
|
-
writeOptions(group.command("create").description("Create an issue."), true).action(async (flags, command) => {
|
|
1278
|
-
const ctx = context(deps, command);
|
|
1279
|
-
if (flags.draft && (flags.phase !== void 0 || flags.roadmap !== void 0)) throw new CliError("--phase and --roadmap cannot be used with --draft. Publish the draft first.", 2);
|
|
1280
|
-
if (flags.roadmap !== void 0 && flags.phase === void 0) throw new CliError("--roadmap requires --phase.", 2);
|
|
1281
|
-
const { input, fromTemplate } = await writeInput(deps, ctx.root, flags, true);
|
|
1282
|
-
if (flags.draft) {
|
|
1283
|
-
const result2 = await deps.http.post(`${ctx.root}/issue-drafts`, input);
|
|
1284
|
-
printResult(ctx.mode === "json" ? result2 : `draft ${result2.draft.id} created
|
|
1285
|
-
${draftUrl(deps.settings.baseUrl, ctx.projectId, result2.draft.id)}`, ctx.mode);
|
|
1286
|
-
return;
|
|
1287
|
-
}
|
|
1288
|
-
const result = await deps.http.post(`${ctx.root}/issues`, input);
|
|
1289
|
-
const roadmap = flags.phase === void 0 ? void 0 : await attachRoadmap(deps, flags.phase, flags.roadmap, result.issue.key);
|
|
1290
|
-
printResult(ctx.mode === "json" ? { ...result, ...roadmap ? { roadmap } : {} } : `${result.issue.key} created
|
|
1291
|
-
${issueUrl(deps.settings.baseUrl, ctx.projectId, result.issue.number)}${fromTemplate ? "\nbody: from template" : ""}`, ctx.mode);
|
|
1292
|
-
});
|
|
1293
|
-
group.command("drafts").description("List your issue drafts (visible only to you).").action(async (_flags, command) => {
|
|
1294
|
-
const ctx = context(deps, command);
|
|
1295
|
-
const result = await deps.http.get(`${ctx.root}/issue-drafts`);
|
|
1296
|
-
printResult(ctx.mode === "json" ? result : formatDraftList(result), ctx.mode);
|
|
1297
|
-
});
|
|
1298
|
-
group.command("publish <draft-id>").description("Publish a draft as an issue.").action(async (id, _flags, command) => {
|
|
1299
|
-
const ctx = context(deps, command);
|
|
1300
|
-
if (!isUuid(id)) throw new CliError("<draft-id> must be a UUID. Run `nolto issue drafts` to list drafts.", 2);
|
|
1301
|
-
const result = await deps.http.post(`${ctx.root}/issue-drafts/${id}/publish`, void 0);
|
|
1302
|
-
printResult(ctx.mode === "json" ? result : `${result.issue.key} published
|
|
1303
|
-
${issueUrl(deps.settings.baseUrl, ctx.projectId, result.issue.number)}`, ctx.mode);
|
|
1304
|
-
});
|
|
1305
|
-
writeOptions(group.command("update <ref>").description("Update issue fields."), false).action(async (ref, flags, command) => {
|
|
1306
|
-
const ctx = context(deps, command);
|
|
1307
|
-
const number = parseIssueRef(ref);
|
|
1308
|
-
const { input } = await writeInput(deps, ctx.root, flags, false);
|
|
1309
|
-
const result = await deps.http.patch(`${ctx.root}/issues/${number}`, input);
|
|
1310
|
-
printResult(ctx.mode === "json" ? result : `${result.issue.key} updated
|
|
1311
|
-
${issueUrl(deps.settings.baseUrl, ctx.projectId, number)}`, ctx.mode);
|
|
1312
|
-
});
|
|
1313
|
-
group.command("comment <ref>").description("Post a comment.").option("-m, --comment <text>", "Comment text").option("--body-file <path>", "Read comment from file (- for stdin)").action(async (ref, flags, command) => {
|
|
1314
|
-
const ctx = context(deps, command);
|
|
1315
|
-
const number = parseIssueRef(ref);
|
|
1316
|
-
const body = await bodyText(flags.comment, flags.bodyFile);
|
|
1317
|
-
if (!body?.trim()) throw new CliError("A comment is required. Use -m or --body-file.", 2);
|
|
1318
|
-
const issue = ctx.mode === "human" ? (await deps.http.get(`${ctx.root}/issues/${number}`)).issue : void 0;
|
|
1319
|
-
const result = await deps.http.post(`${ctx.root}/issues/${number}/comments`, { body });
|
|
1320
|
-
printResult(ctx.mode === "json" ? result : `${issue.key} commented
|
|
1321
|
-
${issueUrl(deps.settings.baseUrl, ctx.projectId, number)}`, ctx.mode);
|
|
1322
|
-
});
|
|
1323
|
-
group.command("close <ref>").description("Move an issue to a closed status.").option("--status <name-or-id>", "Closed status (defaults to first by sort order)").option("-m, --comment <text>", "Comment in the same update").action(async (ref, flags, command) => {
|
|
1324
|
-
const ctx = context(deps, command);
|
|
1325
|
-
const number = parseIssueRef(ref);
|
|
1326
|
-
const settings = await deps.http.get(`${ctx.root}/issue-settings`);
|
|
1327
|
-
const status = pickClosedStatus(settings, flags.status);
|
|
1328
|
-
const result = await deps.http.patch(`${ctx.root}/issues/${number}`, { statusId: status.id, ...flags.comment !== void 0 ? { comment: flags.comment } : {} });
|
|
1329
|
-
printResult(ctx.mode === "json" ? result : `${result.issue.key} closed
|
|
1330
|
-
${issueUrl(deps.settings.baseUrl, ctx.projectId, number)}`, ctx.mode);
|
|
1331
|
-
});
|
|
1332
|
-
}
|
|
1333
|
-
|
|
1334
|
-
// src/memory-import.ts
|
|
1335
|
-
import { readFile as readFile7, readdir as readdir3 } from "fs/promises";
|
|
1336
|
-
import path8 from "path";
|
|
1337
|
-
|
|
1338
|
-
// src/memory-format.ts
|
|
1339
|
-
var oneLine = (value) => value.replace(/[\r\n\u0085\u2028\u2029]/g, " ");
|
|
1340
|
-
var shellArg = (value) => /^[A-Za-z0-9._/-]+$/.test(value) ? value : JSON.stringify(value);
|
|
1341
|
-
var memoryClient = (via) => via?.client || via?.tokenName || "Web";
|
|
1342
|
-
function parseMemory(text, importing = false) {
|
|
1343
|
-
const lines = text.replace(/\r\n/g, "\n").split("\n");
|
|
1344
|
-
if (/^<!--.*-->$/.test(lines[0] ?? "")) lines.shift();
|
|
1345
|
-
if (lines.shift() !== "---") throw new CliError("frontmatter \u306E --- \u304C\u3042\u308A\u307E\u305B\u3093\u3002", 2);
|
|
1346
|
-
const end = lines.indexOf("---");
|
|
1347
|
-
if (end < 0) throw new CliError("frontmatter \u3092 --- \u3067\u9589\u3058\u3066\u304F\u3060\u3055\u3044\u3002", 2);
|
|
1348
|
-
const fields = {};
|
|
1349
|
-
let metadata = false;
|
|
1350
|
-
for (const line2 of lines.slice(0, end)) {
|
|
1351
|
-
const match = /^(\s*)([a-zA-Z]+):\s*(.*)$/.exec(line2);
|
|
1352
|
-
if (!match) continue;
|
|
1353
|
-
const indent = match[1], key = match[2], raw = match[3];
|
|
1354
|
-
if (!indent) metadata = key === "metadata";
|
|
1355
|
-
if (indent && !(importing && metadata && key === "type")) continue;
|
|
1356
|
-
let value = raw.trim();
|
|
1357
|
-
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) value = value.slice(1, -1);
|
|
1358
|
-
if (["name", "description", "type", "scope", "branch", "revision"].includes(key)) fields[key] = value;
|
|
1359
|
-
}
|
|
1360
|
-
const body = lines.slice(end + 1);
|
|
1361
|
-
if (body[0] === "") body.shift();
|
|
1362
|
-
return { ...fields, name: fields.name ?? "", description: fields.description ?? "", body: body.join("\n") };
|
|
1317
|
+
// src/roadmap-cache.ts
|
|
1318
|
+
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
1319
|
+
var ROADMAP_SLUG_PATTERN = /^[a-z0-9][a-z0-9._-]*$/;
|
|
1320
|
+
function cacheDir(env, projectId) {
|
|
1321
|
+
if (!UUID_RE.test(projectId)) throw new CliError(`Invalid project id "${projectId}".`, 2);
|
|
1322
|
+
return path6.join(getConfigDir(env), "projects", projectId, "roadmaps");
|
|
1363
1323
|
}
|
|
1364
|
-
function
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
};
|
|
1369
|
-
return [
|
|
1370
|
-
"<!-- 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 -->",
|
|
1371
|
-
"---",
|
|
1372
|
-
`name: ${entry.name}`,
|
|
1373
|
-
`description: ${value(entry.description)}`,
|
|
1374
|
-
...entry.type == null ? [] : [`type: ${entry.type}`],
|
|
1375
|
-
`scope: ${entry.scope}`,
|
|
1376
|
-
...entry.scope === "branch" ? [`branch: ${value(entry.branch ?? "")}`] : [],
|
|
1377
|
-
`revision: ${entry.revision}`,
|
|
1378
|
-
`updated: ${oneLine(entry.updatedAt)}${entry.updatedBy?.name ? ` by ${oneLine(entry.updatedBy.name)}` : ""} (${oneLine(memoryClient(entry.updatedVia))})`,
|
|
1379
|
-
"---",
|
|
1380
|
-
"",
|
|
1381
|
-
entry.body
|
|
1382
|
-
].join("\n");
|
|
1324
|
+
function cachePaths(env, projectId, slug) {
|
|
1325
|
+
if (!ROADMAP_SLUG_PATTERN.test(slug)) throw new CliError(`Invalid roadmap slug "${slug}".`, 2);
|
|
1326
|
+
const dir = cacheDir(env, projectId);
|
|
1327
|
+
return { json: path6.join(dir, `${slug}.json`), meta: path6.join(dir, `${slug}.meta.json`) };
|
|
1383
1328
|
}
|
|
1384
|
-
function
|
|
1385
|
-
|
|
1386
|
-
|
|
1329
|
+
async function listCachedSlugs(env, projectId) {
|
|
1330
|
+
try {
|
|
1331
|
+
const entries = await readdir2(cacheDir(env, projectId), { withFileTypes: true });
|
|
1332
|
+
return entries.filter((entry) => entry.isFile() && entry.name.endsWith(".json") && !entry.name.endsWith(".meta.json")).map((entry) => entry.name.slice(0, -5)).sort();
|
|
1333
|
+
} catch (err) {
|
|
1334
|
+
if (err.code === "ENOENT") return [];
|
|
1335
|
+
throw err;
|
|
1387
1336
|
}
|
|
1388
|
-
return scope;
|
|
1389
1337
|
}
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
}
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
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");
|
|
1399
|
-
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");
|
|
1400
|
-
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");
|
|
1401
|
-
if (draft.type && !["user", "feedback", "project", "reference"].includes(draft.type)) {
|
|
1402
|
-
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");
|
|
1338
|
+
async function readCache(env, projectId, slug) {
|
|
1339
|
+
const paths = cachePaths(env, projectId, slug);
|
|
1340
|
+
let raw;
|
|
1341
|
+
try {
|
|
1342
|
+
raw = await readFile4(paths.json, "utf8");
|
|
1343
|
+
} catch (err) {
|
|
1344
|
+
if (err.code === "ENOENT") return null;
|
|
1345
|
+
throw err;
|
|
1403
1346
|
}
|
|
1404
|
-
|
|
1405
|
-
function parseRevision(value) {
|
|
1406
|
-
const revision = Number(value);
|
|
1407
|
-
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);
|
|
1408
|
-
return revision;
|
|
1409
|
-
}
|
|
1410
|
-
function detectMemoryClient(env) {
|
|
1411
|
-
const agent = env.NOLTO_AGENT?.trim();
|
|
1412
|
-
if (agent && /^[\x20-\x7e]+$/.test(agent)) return agent;
|
|
1413
|
-
if (env.CLAUDECODE === "1") return "Claude Code";
|
|
1414
|
-
if (env.GEMINI_CLI === "1") return "Gemini CLI";
|
|
1415
|
-
if (env.CODEX_THREAD_ID) return "Codex";
|
|
1416
|
-
return "CLI";
|
|
1417
|
-
}
|
|
1418
|
-
|
|
1419
|
-
// src/memory-cache.ts
|
|
1420
|
-
import { mkdir as mkdir4, readFile as readFile5, rename as rename2, rm as rm3, unlink, writeFile as writeFile5 } from "fs/promises";
|
|
1421
|
-
import { randomUUID as randomUUID2 } from "crypto";
|
|
1422
|
-
import path5 from "path";
|
|
1423
|
-
function memoryDir(configPath, project) {
|
|
1424
|
-
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);
|
|
1425
|
-
return path5.join(path5.dirname(configPath), "projects", project, "memory");
|
|
1426
|
-
}
|
|
1427
|
-
function memoryEntryPath(entry) {
|
|
1428
|
-
if (!/^[a-z0-9][a-z0-9-]{0,63}$/.test(entry.name)) throw new CliError("Invalid memory name in cache.", 2);
|
|
1429
|
-
if (entry.scope === "project" || entry.scope === "user") return `${entry.scope}/${entry.name}.md`;
|
|
1430
|
-
if (entry.scope !== "branch" || !entry.repoIdentity || !entry.branch) throw new CliError("Invalid memory scope in cache.", 2);
|
|
1431
|
-
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);
|
|
1432
|
-
const repoDir = encodeURIComponent(entry.repoIdentity);
|
|
1433
|
-
if (Buffer.byteLength(repoDir) > 200) throw new CliError("Unsafe memory repo path.", 2);
|
|
1434
|
-
return `branch/${repoDir}/${entry.branch}/${entry.name}.md`;
|
|
1435
|
-
}
|
|
1436
|
-
function storableMemoryEntry(entry) {
|
|
1347
|
+
let roadmap;
|
|
1437
1348
|
try {
|
|
1438
|
-
|
|
1439
|
-
return true;
|
|
1349
|
+
roadmap = JSON.parse(raw);
|
|
1440
1350
|
} catch {
|
|
1441
|
-
|
|
1351
|
+
throw new CliError(`Malformed JSON in ${paths.json}.`, 2);
|
|
1442
1352
|
}
|
|
1443
|
-
}
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
const temp = `${file}.tmp-${randomUUID2()}`;
|
|
1353
|
+
const { errors } = validateRoadmap(roadmap);
|
|
1354
|
+
if (errors.length) throw new CliError(`${paths.json} failed validation: ${errors.join("; ")}`, 2);
|
|
1355
|
+
let meta = null;
|
|
1447
1356
|
try {
|
|
1448
|
-
await
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
}
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1357
|
+
const parsed = JSON.parse(await readFile4(paths.meta, "utf8"));
|
|
1358
|
+
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") {
|
|
1359
|
+
throw new Error("Invalid cache metadata");
|
|
1360
|
+
}
|
|
1361
|
+
if ("currentTaskId" in parsed && parsed.currentTaskId !== null && typeof parsed.currentTaskId !== "string") {
|
|
1362
|
+
throw new Error("Invalid currentTaskId");
|
|
1363
|
+
}
|
|
1364
|
+
if ("repoIdentity" in parsed && parsed.repoIdentity !== null && typeof parsed.repoIdentity !== "string") {
|
|
1365
|
+
throw new Error("Invalid repoIdentity");
|
|
1366
|
+
}
|
|
1367
|
+
meta = { ...parsed, currentTaskId: parsed.currentTaskId ?? null, repoIdentity: parsed.repoIdentity ?? null };
|
|
1368
|
+
} catch (err) {
|
|
1369
|
+
if (err.code !== "ENOENT") {
|
|
1370
|
+
throw new CliError(`Invalid cache metadata at ${paths.meta}: ${String(err)}`, 2);
|
|
1371
|
+
}
|
|
1455
1372
|
}
|
|
1373
|
+
return { roadmap, meta, raw };
|
|
1456
1374
|
}
|
|
1457
|
-
async function
|
|
1458
|
-
const
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1375
|
+
async function writeCache(env, projectId, slug, roadmap, meta) {
|
|
1376
|
+
const paths = cachePaths(env, projectId, slug);
|
|
1377
|
+
const raw = serializeRoadmap(roadmap);
|
|
1378
|
+
const metadata = { ...meta, currentTaskId: meta.currentTaskId ?? null, repoIdentity: meta.repoIdentity ?? null, contentHash: sha256Hex(raw) };
|
|
1379
|
+
await mkdir4(cacheDir(env, projectId), { recursive: true, mode: 448 });
|
|
1380
|
+
for (const [filePath, content] of [[paths.json, raw], [paths.meta, JSON.stringify(metadata, null, 2) + "\n"]]) {
|
|
1381
|
+
const temp = `${filePath}.tmp-${process.pid}-${randomUUID2()}`;
|
|
1464
1382
|
try {
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1383
|
+
await writeFile4(temp, content, { mode: 384 });
|
|
1384
|
+
await rename(temp, filePath);
|
|
1385
|
+
} finally {
|
|
1386
|
+
await unlink(temp).catch(() => void 0);
|
|
1468
1387
|
}
|
|
1469
|
-
if (!Number.isSafeInteger(meta.cursor) || meta.cursor < 0 || typeof meta.pulledAt !== "string") throw new Error("Invalid cursor");
|
|
1470
|
-
return { state, meta };
|
|
1471
|
-
} catch (error) {
|
|
1472
|
-
if (error.code === "ENOENT") return empty;
|
|
1473
|
-
throw new CliError(`\u30E1\u30E2\u30EA\u30AD\u30E3\u30C3\u30B7\u30E5\u3092\u8AAD\u3081\u307E\u305B\u3093: ${String(error)}`, 2, "nolto memory pull");
|
|
1474
1388
|
}
|
|
1475
1389
|
}
|
|
1476
|
-
function
|
|
1477
|
-
|
|
1478
|
-
for (const entry of updates) {
|
|
1479
|
-
const old = byId.get(entry.id);
|
|
1480
|
-
if (!old || old.revision <= entry.revision) byId.set(entry.id, entry);
|
|
1481
|
-
}
|
|
1482
|
-
return [...byId.values()];
|
|
1390
|
+
function isDirty(entry) {
|
|
1391
|
+
return entry.meta === null || sha256Hex(entry.raw) !== entry.meta.contentHash;
|
|
1483
1392
|
}
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
}
|
|
1495
|
-
await atomicMemoryFile(path5.join(dir, ".entries.json"), JSON.stringify(cache.state) + "\n");
|
|
1496
|
-
await atomicMemoryFile(path5.join(dir, "MEMORY.md"), index);
|
|
1497
|
-
await atomicMemoryFile(path5.join(dir, ".meta.json"), JSON.stringify(cache.meta) + "\n");
|
|
1498
|
-
return unsafe;
|
|
1393
|
+
|
|
1394
|
+
// src/roadmap-bootstrap.ts
|
|
1395
|
+
import { existsSync as existsSync3 } from "fs";
|
|
1396
|
+
import { readFile as readFile5, realpath } from "fs/promises";
|
|
1397
|
+
import path7 from "path";
|
|
1398
|
+
|
|
1399
|
+
// src/roadmap-scaffold.ts
|
|
1400
|
+
function slugifyProjectId(name) {
|
|
1401
|
+
const slug = name.toLowerCase().replace(/[^a-z0-9.-]+/g, "-").replace(/^[^a-z0-9]+/, "").replace(/[-_.]+$/, "");
|
|
1402
|
+
return slug.length > 0 ? slug : "project";
|
|
1499
1403
|
}
|
|
1500
|
-
function
|
|
1501
|
-
return
|
|
1404
|
+
function buildScaffold(projectName, repoBasename) {
|
|
1405
|
+
return {
|
|
1406
|
+
schemaVersion: 3,
|
|
1407
|
+
project: { id: slugifyProjectId(repoBasename), name: projectName, repository: repoBasename },
|
|
1408
|
+
summary: "",
|
|
1409
|
+
phases: []
|
|
1410
|
+
};
|
|
1502
1411
|
}
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1412
|
+
|
|
1413
|
+
// src/roadmap-bootstrap.ts
|
|
1414
|
+
async function pullRoadmapCache(args) {
|
|
1415
|
+
const { env, projectId, slug } = args;
|
|
1416
|
+
const response = await args.http.get(`/api/projects/${projectId}/roadmaps/${encodeURIComponent(slug)}`);
|
|
1417
|
+
const validation = validateRoadmap(response.roadmap);
|
|
1418
|
+
if (validation.errors.length > 0) {
|
|
1419
|
+
throw new CliError(`Server roadmap "${slug}" failed validation: ${validation.errors.join("; ")}`, 5);
|
|
1420
|
+
}
|
|
1421
|
+
let existing;
|
|
1422
|
+
try {
|
|
1423
|
+
existing = await readCache(env, projectId, slug);
|
|
1424
|
+
} catch (err) {
|
|
1425
|
+
if (!(err instanceof CliError) || !(args.force || args.recoverInvalid)) throw err;
|
|
1426
|
+
existing = null;
|
|
1427
|
+
}
|
|
1428
|
+
if (existing && isDirty(existing) && !args.force) {
|
|
1429
|
+
args.warn(`Warning: ${slug} has local changes that are not synced; use --force to overwrite or run nolto sync first`);
|
|
1430
|
+
return false;
|
|
1431
|
+
}
|
|
1432
|
+
const unchanged = existing?.raw === serializeRoadmap(response.roadmap) && existing.meta?.revision === response.revision;
|
|
1433
|
+
await writeCache(env, projectId, slug, response.roadmap, {
|
|
1434
|
+
revision: response.revision,
|
|
1435
|
+
pulledAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1436
|
+
currentTaskId: response.currentTaskId,
|
|
1437
|
+
repoIdentity: response.repoIdentity ?? null
|
|
1438
|
+
});
|
|
1439
|
+
args.log(unchanged ? `unchanged ${slug}` : `pulled ${slug} (rev ${response.revision})`);
|
|
1440
|
+
return true;
|
|
1506
1441
|
}
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
const
|
|
1510
|
-
const
|
|
1511
|
-
const
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
const
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1442
|
+
async function ensureRoadmapCache(args) {
|
|
1443
|
+
const { env, projectId } = args;
|
|
1444
|
+
const identity = repoIdentityToString(args.repoIdentity);
|
|
1445
|
+
const list = await args.http.get(`/api/projects/${projectId}/roadmaps`);
|
|
1446
|
+
const warn2 = (line2) => {
|
|
1447
|
+
process.stderr.write(line2 + "\n");
|
|
1448
|
+
};
|
|
1449
|
+
const log = (line2) => args.log(`roadmap: ${line2}`);
|
|
1450
|
+
if (list.roadmaps.length > 0) {
|
|
1451
|
+
let skipped = false;
|
|
1452
|
+
for (const { slug: slug2 } of list.roadmaps) {
|
|
1453
|
+
if (!await pullRoadmapCache({ ...args, slug: slug2, warn: warn2, log, recoverInvalid: true })) skipped = true;
|
|
1454
|
+
}
|
|
1455
|
+
if (skipped) throw new CliError("Some roadmaps have local changes that are not synced.", 4);
|
|
1456
|
+
if (list.roadmaps.some((row) => row.repoIdentity == null || row.repoIdentity === identity)) return;
|
|
1457
|
+
}
|
|
1458
|
+
const basename = path7.basename(args.repoRoot);
|
|
1459
|
+
const slug = args.slug ?? slugifyProjectId(basename);
|
|
1460
|
+
const collision = list.roadmaps.find((row) => row.slug === slug);
|
|
1461
|
+
if (collision) {
|
|
1462
|
+
if (args.slug === void 0) {
|
|
1463
|
+
log(`skipped \u2014 "${slug}" is another repository's roadmap (${collision.repoIdentity ?? "unknown"}). Run \`nolto link --slug <name>\` to create one for this repository.`);
|
|
1464
|
+
return;
|
|
1465
|
+
}
|
|
1466
|
+
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);
|
|
1467
|
+
}
|
|
1468
|
+
let existing;
|
|
1469
|
+
try {
|
|
1470
|
+
existing = await readCache(env, projectId, slug);
|
|
1471
|
+
} catch (err) {
|
|
1472
|
+
if (!(err instanceof CliError)) throw err;
|
|
1473
|
+
existing = null;
|
|
1474
|
+
}
|
|
1475
|
+
if (existing && isDirty(existing)) {
|
|
1476
|
+
warn2(`Warning: ${slug} has local changes that are not synced; use --force to overwrite or run nolto sync first`);
|
|
1477
|
+
throw new CliError("Roadmap has local changes that are not synced.", 4);
|
|
1478
|
+
}
|
|
1479
|
+
const roadmap = existing?.roadmap ?? buildScaffold(args.projectName, basename);
|
|
1480
|
+
await writeCache(env, projectId, slug, roadmap, { repoIdentity: identity, revision: 0, pulledAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
1481
|
+
const response = await runSync({ ...args, slug, roadmap, baseRevision: 0 }, {
|
|
1482
|
+
http: args.http,
|
|
1483
|
+
readFile: (p) => readFile5(p, "utf8"),
|
|
1484
|
+
realpath,
|
|
1485
|
+
fileExists: existsSync3,
|
|
1486
|
+
log: () => void 0,
|
|
1487
|
+
warn: warn2
|
|
1488
|
+
});
|
|
1489
|
+
await writeCache(env, projectId, slug, response.roadmap ?? roadmap, { repoIdentity: identity, revision: response.revision, pulledAt: (/* @__PURE__ */ new Date()).toISOString(), currentTaskId: response.currentTaskId !== void 0 ? response.currentTaskId : existing?.meta?.currentTaskId });
|
|
1490
|
+
log(`created ${slug} on server (rev ${response.revision})`);
|
|
1491
|
+
}
|
|
1492
|
+
async function ensureProjectRepo(args) {
|
|
1493
|
+
let repos;
|
|
1494
|
+
try {
|
|
1495
|
+
const project = await args.http.get(`/api/projects/${args.projectId}`);
|
|
1496
|
+
repos = Array.isArray(project.repos) ? project.repos : [];
|
|
1497
|
+
} catch (error) {
|
|
1498
|
+
if (error instanceof CliError && (error.status === 401 || error.status === 403)) throw error;
|
|
1499
|
+
process.stderr.write(`Warning: could not check project repositories: ${error instanceof Error ? error.message : String(error)}
|
|
1500
|
+
`);
|
|
1501
|
+
return "unbound";
|
|
1502
|
+
}
|
|
1503
|
+
if (repos.length === 0) return "unbound";
|
|
1504
|
+
const identity = repoIdentityToString(args.repoIdentity);
|
|
1505
|
+
if (repos.some((repo) => repo.identity === identity)) return "bound";
|
|
1506
|
+
if (!await args.confirm(`Project is bound to ${repos.map((repo) => repo.identity).join(", ")}. Add this repository (${identity}) to the project? [Y/n] `)) return "declined";
|
|
1507
|
+
try {
|
|
1508
|
+
await args.http.post(`/api/projects/${args.projectId}/repos`, { repoIdentity: args.repoIdentity });
|
|
1509
|
+
} catch (error) {
|
|
1510
|
+
if (error instanceof CliError) {
|
|
1511
|
+
if (error.status === 409 && error.serverError === "repo_already_bound_to_this") return "bound";
|
|
1512
|
+
if (error.status === 403) {
|
|
1513
|
+
throw new CliError(
|
|
1514
|
+
"Only the project owner can add a repository.",
|
|
1515
|
+
2,
|
|
1516
|
+
"Ask the owner to run `nolto link --add` in this repository."
|
|
1517
|
+
);
|
|
1532
1518
|
}
|
|
1519
|
+
if (error.status === 402) process.stderr.write("binding and skill are kept; retry after upgrading.\n");
|
|
1533
1520
|
}
|
|
1534
|
-
|
|
1535
|
-
entries.splice(project < 0 ? entries.length - 1 : project, 1);
|
|
1536
|
-
omitted++;
|
|
1537
|
-
} else if (mergedLines.length) {
|
|
1538
|
-
mergedLines.pop();
|
|
1539
|
-
omitted++;
|
|
1540
|
-
} else break;
|
|
1541
|
-
lines = build();
|
|
1521
|
+
throw error;
|
|
1542
1522
|
}
|
|
1543
|
-
|
|
1523
|
+
args.log(`Added ${identity} to project.`);
|
|
1524
|
+
return "added";
|
|
1544
1525
|
}
|
|
1545
1526
|
|
|
1546
|
-
// src/
|
|
1547
|
-
import
|
|
1548
|
-
|
|
1527
|
+
// src/roadmap-read.ts
|
|
1528
|
+
import path12 from "path";
|
|
1529
|
+
|
|
1530
|
+
// src/commands/link.ts
|
|
1531
|
+
import readline from "readline/promises";
|
|
1532
|
+
import os2 from "os";
|
|
1533
|
+
import path11 from "path";
|
|
1534
|
+
import { statSync as statSync3 } from "fs";
|
|
1535
|
+
|
|
1536
|
+
// src/registry.ts
|
|
1537
|
+
import { readFile as readFile6, writeFile as writeFile5, mkdir as mkdir5, rename as rename2, unlink as unlink2 } from "fs/promises";
|
|
1538
|
+
import { randomUUID as randomUUID3 } from "crypto";
|
|
1539
|
+
import path8 from "path";
|
|
1540
|
+
import { z as z3 } from "zod";
|
|
1541
|
+
var registrySchema = z3.object({
|
|
1542
|
+
schemaVersion: z3.literal(1),
|
|
1543
|
+
repos: z3.array(z3.object({ root: z3.string().min(1), projectId: z3.string().uuid().optional() }).passthrough())
|
|
1544
|
+
}).passthrough();
|
|
1545
|
+
function getRegistryPath(env) {
|
|
1546
|
+
return path8.join(getConfigDir(env), "registry.json");
|
|
1547
|
+
}
|
|
1548
|
+
async function loadRegistry(filePath) {
|
|
1549
|
+
let raw;
|
|
1550
|
+
try {
|
|
1551
|
+
raw = await readFile6(filePath, "utf8");
|
|
1552
|
+
} catch (err) {
|
|
1553
|
+
const code = err != null && typeof err === "object" && "code" in err ? err.code : "";
|
|
1554
|
+
if (code === "ENOENT") {
|
|
1555
|
+
return { schemaVersion: 1, repos: [] };
|
|
1556
|
+
}
|
|
1557
|
+
throw new CliError(`Cannot read registry: ${filePath}: ${String(err)}`, 2);
|
|
1558
|
+
}
|
|
1559
|
+
let parsed;
|
|
1560
|
+
try {
|
|
1561
|
+
parsed = JSON.parse(raw);
|
|
1562
|
+
} catch {
|
|
1563
|
+
throw new CliError(`Malformed JSON in ${filePath}. Fix or remove the file.`, 2);
|
|
1564
|
+
}
|
|
1565
|
+
const result = registrySchema.safeParse(parsed);
|
|
1566
|
+
if (!result.success) {
|
|
1567
|
+
const issue = result.error.issues[0];
|
|
1568
|
+
const fieldPath = issue?.path.join(".") ?? "";
|
|
1569
|
+
throw new CliError(
|
|
1570
|
+
`Invalid registry at ${filePath}: ${fieldPath.length > 0 ? `field "${fieldPath}" \u2014 ` : ""}${issue?.message ?? "validation failed"}`,
|
|
1571
|
+
2
|
|
1572
|
+
);
|
|
1573
|
+
}
|
|
1574
|
+
return result.data;
|
|
1575
|
+
}
|
|
1576
|
+
async function addRepoToRegistry(filePath, entry) {
|
|
1577
|
+
const registry = await loadRegistry(filePath);
|
|
1578
|
+
const existing = registry.repos.find((repo) => repo.root === entry.root);
|
|
1579
|
+
if (existing?.projectId === entry.projectId) {
|
|
1580
|
+
return { added: false, updated: false, registry };
|
|
1581
|
+
}
|
|
1582
|
+
const updated = {
|
|
1583
|
+
...registry,
|
|
1584
|
+
repos: existing ? registry.repos.map((repo) => repo.root === entry.root ? { ...repo, projectId: entry.projectId } : repo) : [...registry.repos, entry]
|
|
1585
|
+
};
|
|
1586
|
+
await writeRegistry(filePath, updated);
|
|
1587
|
+
return { added: !existing, updated: !!existing, registry: updated };
|
|
1588
|
+
}
|
|
1589
|
+
async function writeRegistry(filePath, registry) {
|
|
1590
|
+
await mkdir5(path8.dirname(filePath), { recursive: true, mode: 448 });
|
|
1591
|
+
const tempPath = `${filePath}.tmp-${process.pid}-${randomUUID3()}`;
|
|
1592
|
+
try {
|
|
1593
|
+
await writeFile5(tempPath, JSON.stringify(registry, null, 2) + "\n", "utf8");
|
|
1594
|
+
await rename2(tempPath, filePath);
|
|
1595
|
+
} catch (err) {
|
|
1596
|
+
await unlink2(tempPath).catch(() => void 0);
|
|
1597
|
+
throw err;
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
async function removeRepoFromRegistry(filePath, root) {
|
|
1601
|
+
const registry = await loadRegistry(filePath);
|
|
1602
|
+
const repos = registry.repos.filter((repo) => repo.root !== root);
|
|
1603
|
+
if (repos.length === registry.repos.length) return { removed: false, registry };
|
|
1604
|
+
const updated = { ...registry, repos };
|
|
1605
|
+
await writeRegistry(filePath, updated);
|
|
1606
|
+
return { removed: true, registry: updated };
|
|
1607
|
+
}
|
|
1549
1608
|
|
|
1550
1609
|
// src/repo-identity.ts
|
|
1551
1610
|
import { execFile } from "child_process";
|
|
1552
1611
|
import { realpathSync } from "fs";
|
|
1553
|
-
import
|
|
1612
|
+
import path10 from "path";
|
|
1554
1613
|
|
|
1555
1614
|
// src/machine-id.ts
|
|
1556
|
-
import { chmod, mkdir as
|
|
1557
|
-
import { randomUUID as
|
|
1558
|
-
import
|
|
1615
|
+
import { chmod, mkdir as mkdir6, readFile as readFile7, writeFile as writeFile6 } from "fs/promises";
|
|
1616
|
+
import { randomUUID as randomUUID4 } from "crypto";
|
|
1617
|
+
import path9 from "path";
|
|
1559
1618
|
var inFlightByConfigDir = /* @__PURE__ */ new Map();
|
|
1560
1619
|
function parseMachineId(raw, file) {
|
|
1561
1620
|
let parsed;
|
|
@@ -1571,10 +1630,10 @@ function parseMachineId(raw, file) {
|
|
|
1571
1630
|
return id;
|
|
1572
1631
|
}
|
|
1573
1632
|
async function loadOrCreate(configDir) {
|
|
1574
|
-
const file =
|
|
1633
|
+
const file = path9.join(configDir, "machine.json");
|
|
1575
1634
|
let raw = null;
|
|
1576
1635
|
try {
|
|
1577
|
-
raw = await
|
|
1636
|
+
raw = await readFile7(file, "utf8");
|
|
1578
1637
|
} catch (err) {
|
|
1579
1638
|
const code = err.code;
|
|
1580
1639
|
if (code !== "ENOENT") {
|
|
@@ -1584,8 +1643,8 @@ async function loadOrCreate(configDir) {
|
|
|
1584
1643
|
if (raw !== null) {
|
|
1585
1644
|
return parseMachineId(raw, file);
|
|
1586
1645
|
}
|
|
1587
|
-
const machineId =
|
|
1588
|
-
await
|
|
1646
|
+
const machineId = randomUUID4();
|
|
1647
|
+
await mkdir6(configDir, { recursive: true, mode: 448 });
|
|
1589
1648
|
try {
|
|
1590
1649
|
await writeFile6(file, `${JSON.stringify({ machineId }, null, 2)}
|
|
1591
1650
|
`, {
|
|
@@ -1594,7 +1653,7 @@ async function loadOrCreate(configDir) {
|
|
|
1594
1653
|
});
|
|
1595
1654
|
} catch (err) {
|
|
1596
1655
|
if (err.code === "EEXIST") {
|
|
1597
|
-
return parseMachineId(await
|
|
1656
|
+
return parseMachineId(await readFile7(file, "utf8"), file);
|
|
1598
1657
|
}
|
|
1599
1658
|
throw new CliError(`Cannot write ${file}: ${String(err)}`, 2);
|
|
1600
1659
|
}
|
|
@@ -1602,7 +1661,7 @@ async function loadOrCreate(configDir) {
|
|
|
1602
1661
|
return machineId;
|
|
1603
1662
|
}
|
|
1604
1663
|
function loadOrCreateMachineId(configDir) {
|
|
1605
|
-
const key =
|
|
1664
|
+
const key = path9.resolve(configDir);
|
|
1606
1665
|
const existing = inFlightByConfigDir.get(key);
|
|
1607
1666
|
if (existing !== void 0) return existing;
|
|
1608
1667
|
const pending = loadOrCreate(key).finally(() => {
|
|
@@ -1636,7 +1695,7 @@ async function resolveRepoIdentity(root, deps) {
|
|
|
1636
1695
|
try {
|
|
1637
1696
|
canonicalRoot = realpathSync(root);
|
|
1638
1697
|
} catch {
|
|
1639
|
-
canonicalRoot =
|
|
1698
|
+
canonicalRoot = path10.resolve(root);
|
|
1640
1699
|
}
|
|
1641
1700
|
return { kind: "local", value: `${machineId}:${canonicalRoot}` };
|
|
1642
1701
|
}
|
|
@@ -1647,1042 +1706,1470 @@ function makeRepoIdentityResolver(deps) {
|
|
|
1647
1706
|
}));
|
|
1648
1707
|
}
|
|
1649
1708
|
|
|
1650
|
-
// src/
|
|
1651
|
-
var
|
|
1652
|
-
|
|
1653
|
-
const
|
|
1654
|
-
|
|
1709
|
+
// src/commands/link.ts
|
|
1710
|
+
var UUID_RE2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
1711
|
+
function resolveStartDir(env, cwd) {
|
|
1712
|
+
const cpd = env["CLAUDE_PROJECT_DIR"];
|
|
1713
|
+
return cpd != null && cpd.length > 0 ? cpd : cwd;
|
|
1714
|
+
}
|
|
1715
|
+
function dirHasGit(dir) {
|
|
1655
1716
|
try {
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
result.repoIdentity = `${identity.kind}:${identity.value}`;
|
|
1659
|
-
result.branch = await git(["symbolic-ref", "--quiet", "--short", "HEAD"], root).catch(() => null);
|
|
1660
|
-
const remote = await git(["symbolic-ref", "refs/remotes/origin/HEAD"], root).catch(() => "");
|
|
1661
|
-
if (remote.startsWith("refs/remotes/origin/")) result.defaultBranch = remote.slice("refs/remotes/origin/".length);
|
|
1662
|
-
else {
|
|
1663
|
-
for (const branch of ["main", "master"]) {
|
|
1664
|
-
try {
|
|
1665
|
-
await git(["show-ref", "--verify", `refs/heads/${branch}`], root);
|
|
1666
|
-
result.defaultBranch = branch;
|
|
1667
|
-
break;
|
|
1668
|
-
} catch {
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
}
|
|
1717
|
+
statSync3(path11.join(dir, ".git"));
|
|
1718
|
+
return true;
|
|
1672
1719
|
} catch {
|
|
1720
|
+
return false;
|
|
1673
1721
|
}
|
|
1674
|
-
return result;
|
|
1675
1722
|
}
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
await git(["show-ref", "--verify", "--quiet", ref], root);
|
|
1682
|
-
return true;
|
|
1683
|
-
} catch (error) {
|
|
1684
|
-
if (error.code === 1) return false;
|
|
1685
|
-
throw error;
|
|
1686
|
-
}
|
|
1687
|
-
};
|
|
1688
|
-
let checkedOut, target, targetTip;
|
|
1689
|
-
try {
|
|
1690
|
-
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)));
|
|
1691
|
-
target = await hasRef(`refs/heads/${context3.defaultBranch}`) ? `refs/heads/${context3.defaultBranch}` : `refs/remotes/origin/${context3.defaultBranch}`;
|
|
1692
|
-
targetTip = await git(["rev-parse", target], root);
|
|
1693
|
-
} catch {
|
|
1694
|
-
return merged;
|
|
1695
|
-
}
|
|
1696
|
-
for (const branch of branches) {
|
|
1697
|
-
if (branch === context3.defaultBranch || branch === context3.branch || checkedOut.has(branch)) continue;
|
|
1698
|
-
try {
|
|
1699
|
-
const local = `refs/heads/${branch}`;
|
|
1700
|
-
if (await hasRef(local)) {
|
|
1701
|
-
if (await git(["rev-parse", local], root) === targetTip) continue;
|
|
1702
|
-
await git(["merge-base", "--is-ancestor", local, target], root);
|
|
1703
|
-
merged.add(branch);
|
|
1704
|
-
} else if (mine.has(branch) && !await hasRef(`refs/remotes/origin/${branch}`)) merged.add(branch);
|
|
1705
|
-
} catch {
|
|
1723
|
+
function findRepoRoot(startDir, hasGit = dirHasGit) {
|
|
1724
|
+
let current = startDir;
|
|
1725
|
+
while (true) {
|
|
1726
|
+
if (hasGit(current)) {
|
|
1727
|
+
return { root: current, foundGit: true };
|
|
1706
1728
|
}
|
|
1729
|
+
const parent = path11.dirname(current);
|
|
1730
|
+
if (parent === current) break;
|
|
1731
|
+
current = parent;
|
|
1707
1732
|
}
|
|
1708
|
-
return
|
|
1709
|
-
}
|
|
1710
|
-
|
|
1711
|
-
// src/memory-import.ts
|
|
1712
|
-
function aiHeading(response, requestedName) {
|
|
1713
|
-
const { entry, ai } = response;
|
|
1714
|
-
if (!ai || ai.action !== "merge" && ai.action !== "replace") return null;
|
|
1715
|
-
if (requestedName !== void 0 && requestedName !== entry.name) {
|
|
1716
|
-
return `\u65B0\u898F\u306E ${requestedName} \u306F\u4F5C\u3089\u305A\u3001AI \u304C ${entry.scope}/${entry.name} ${ai.action === "merge" ? "\u306B\u7D71\u5408\u3057\u307E\u3057\u305F" : "\u306E\u77DB\u76FE\u3092\u89E3\u6D88\u3057\u307E\u3057\u305F"} (r${entry.revision}) \u2014 ${oneLine(ai.reason ?? "")}`;
|
|
1717
|
-
}
|
|
1718
|
-
return `AI \u304C\u6574\u7406: ${entry.scope}/${entry.name} ${ai.action === "merge" ? "\u306B\u7D71\u5408" : "\u306E\u77DB\u76FE\u3092\u89E3\u6D88"} (r${entry.revision}) \u2014 ${oneLine(ai.reason ?? "")}`;
|
|
1719
|
-
}
|
|
1720
|
-
async function createMemoryContext(opts, recover = false) {
|
|
1721
|
-
const { projectId: project, root, git } = opts;
|
|
1722
|
-
const dir = memoryDir(opts.configPath, project);
|
|
1723
|
-
const cache = await readMemoryCache(dir, project).catch((error) => {
|
|
1724
|
-
if (!recover) throw error;
|
|
1725
|
-
return { state: { entries: [], scope: "", projectName: project.slice(0, 8) }, meta: { cursor: 0, pulledAt: "" } };
|
|
1726
|
-
});
|
|
1727
|
-
return { project, dir, root, git, cache, api: `/api/projects/${project}/memory` };
|
|
1733
|
+
return { root: startDir, foundGit: false };
|
|
1728
1734
|
}
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
const branches = [...new Set(entries.map((e) => e.branch))];
|
|
1732
|
-
const userId = ctx.cache.state.userId;
|
|
1733
|
-
const mine = new Set(userId ? entries.filter((e) => e.updatedBy?.id === userId).map((e) => e.branch) : []);
|
|
1734
|
-
return memoryIndex(ctx.cache, ctx.git, await mergedMemoryBranches(branches, ctx.git, ctx.root, deps.memoryGit ?? runMemoryGit, mine), ctx.dir);
|
|
1735
|
+
function isHomeDirectory(dir, home = os2.homedir()) {
|
|
1736
|
+
return path11.resolve(dir) === path11.resolve(home);
|
|
1735
1737
|
}
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
const
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1738
|
+
async function handleShow(deps, projectBindingPath, mode2) {
|
|
1739
|
+
const startDir = resolveStartDir(process.env, process.cwd());
|
|
1740
|
+
const root = findRepoRoot(startDir).root;
|
|
1741
|
+
const repoIdentity = await makeRepoIdentityResolver(deps)(root);
|
|
1742
|
+
if (projectBindingPath == null) {
|
|
1743
|
+
if (mode2 === "json") {
|
|
1744
|
+
printResult({ bound: false, projectBindingPath: null, repoIdentity }, mode2);
|
|
1745
|
+
} else {
|
|
1746
|
+
process.stdout.write("No nolto.json binding found in this directory tree.\n");
|
|
1747
|
+
process.stdout.write(`repoIdentity : ${repoIdentity.kind}:${repoIdentity.value}
|
|
1748
|
+
`);
|
|
1749
|
+
}
|
|
1750
|
+
return;
|
|
1746
1751
|
}
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
const cached = a.deleted && a.entryId !== response.entry.id ? ctx.cache.state.entries.find((e) => e.id === a.entryId) : void 0;
|
|
1751
|
-
return cached ? [{ ...cached, deleted: true, revision: a.toRevision }] : [];
|
|
1752
|
+
const binding = deps.repoBinding != null ? deps.repoBinding.binding : await loadRepoBinding(projectBindingPath).catch((err) => {
|
|
1753
|
+
if (err instanceof CliError) throw err;
|
|
1754
|
+
throw new CliError(`Cannot read binding: ${String(err)}`, 2);
|
|
1752
1755
|
});
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1756
|
+
if (mode2 === "json") {
|
|
1757
|
+
printResult({
|
|
1758
|
+
bound: binding != null,
|
|
1759
|
+
projectId: binding?.projectId ?? null,
|
|
1760
|
+
projectBindingPath,
|
|
1761
|
+
source: deps.settings.source.project === "repo" ? "repo" : "file",
|
|
1762
|
+
repoIdentity
|
|
1763
|
+
}, mode2);
|
|
1764
|
+
} else {
|
|
1765
|
+
if (binding == null) {
|
|
1766
|
+
process.stdout.write(`Binding file found at ${projectBindingPath} but could not be read.
|
|
1767
|
+
`);
|
|
1768
|
+
} else {
|
|
1769
|
+
process.stdout.write(`Binding file : ${projectBindingPath}
|
|
1770
|
+
`);
|
|
1771
|
+
process.stdout.write(`projectId : ${binding.projectId}
|
|
1772
|
+
`);
|
|
1773
|
+
const active = deps.settings.source.project === "repo" ? "repo (active)" : "repo (not active \u2014 overridden)";
|
|
1774
|
+
process.stdout.write(`source : ${active}
|
|
1775
|
+
`);
|
|
1776
|
+
process.stdout.write(`repoIdentity : ${repoIdentity.kind}:${repoIdentity.value}
|
|
1777
|
+
`);
|
|
1772
1778
|
}
|
|
1773
1779
|
}
|
|
1774
|
-
return { ok, invalid };
|
|
1775
1780
|
}
|
|
1776
|
-
function
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
}
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
const
|
|
1784
|
-
|
|
1785
|
-
|
|
1781
|
+
async function handleRebind(deps, projectId, root, mode2, yes) {
|
|
1782
|
+
if (!UUID_RE2.test(projectId)) {
|
|
1783
|
+
throw new CliError(
|
|
1784
|
+
`Invalid project ID: "${projectId}". Must be a UUID (e.g. 00000000-0000-0000-0000-000000000001).`,
|
|
1785
|
+
2
|
|
1786
|
+
);
|
|
1787
|
+
}
|
|
1788
|
+
const result = await deps.http.get("/api/projects");
|
|
1789
|
+
const projects = Array.isArray(result.projects) ? result.projects : [];
|
|
1790
|
+
const project = projects.find((candidate) => candidate.id === projectId);
|
|
1791
|
+
if (project == null) {
|
|
1792
|
+
throw new CliError(
|
|
1793
|
+
`Project ${projectId} is not in your accessible projects. Check nolto.json (nolto link --show) before rebinding.`,
|
|
1794
|
+
2
|
|
1795
|
+
);
|
|
1796
|
+
}
|
|
1797
|
+
const repoIdentity = await makeRepoIdentityResolver(deps)(root);
|
|
1798
|
+
if (mode2 !== "json") {
|
|
1799
|
+
process.stdout.write(`Project : ${project.name} (${project.id})
|
|
1800
|
+
`);
|
|
1801
|
+
process.stdout.write(`Bound to : ${project.repoIdentity ?? "not bound"}
|
|
1802
|
+
`);
|
|
1803
|
+
process.stdout.write(`Rebind to : ${repoIdentity.kind}:${repoIdentity.value}
|
|
1804
|
+
`);
|
|
1805
|
+
}
|
|
1806
|
+
if (!yes) {
|
|
1807
|
+
if (mode2 === "json") {
|
|
1808
|
+
throw new CliError(
|
|
1809
|
+
"--rebind requires confirmation. Pass --yes to skip the prompt in --json mode.",
|
|
1810
|
+
2
|
|
1811
|
+
);
|
|
1812
|
+
}
|
|
1813
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
1814
|
+
let confirmed = false;
|
|
1786
1815
|
try {
|
|
1787
|
-
const
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
}, { "X-Nolto-Client": detectMemoryClient(process.env) });
|
|
1796
|
-
cached = await updateCache(ctx, opts, writtenEntries(ctx, response), true) && cached;
|
|
1797
|
-
heading = aiHeading(response);
|
|
1798
|
-
imported++;
|
|
1799
|
-
status = "imported";
|
|
1800
|
-
} catch (error) {
|
|
1801
|
-
if (error instanceof CliError && error.serverError === "memory_exists") {
|
|
1802
|
-
skipped++;
|
|
1803
|
-
status = "skipped";
|
|
1804
|
-
if (error.body?.entry) cached = await updateCache(ctx, opts, [error.body.entry], true) && cached;
|
|
1805
|
-
} else {
|
|
1806
|
-
failed++;
|
|
1807
|
-
status = "failed";
|
|
1808
|
-
message = error instanceof Error ? error.message : String(error);
|
|
1809
|
-
}
|
|
1816
|
+
const answer = await rl.question(`Rebind "${project.name}" to this repository? [y/N] `);
|
|
1817
|
+
confirmed = answer.trim().toLowerCase() === "y";
|
|
1818
|
+
} finally {
|
|
1819
|
+
rl.close();
|
|
1820
|
+
}
|
|
1821
|
+
if (!confirmed) {
|
|
1822
|
+
process.stdout.write("Aborted.\n");
|
|
1823
|
+
return;
|
|
1810
1824
|
}
|
|
1811
|
-
const result = { file, name, original, status, ...message ? { message } : {} };
|
|
1812
|
-
results.push(result);
|
|
1813
|
-
opts.write(heading ? `${heading} (\u5143: ${oneLine(file)})` : importResultLine(opts.scope, result));
|
|
1814
1825
|
}
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
// src/watch-state.ts
|
|
1822
|
-
import * as fs from "fs/promises";
|
|
1823
|
-
import { randomUUID as randomUUID4 } from "crypto";
|
|
1824
|
-
import path9 from "path";
|
|
1825
|
-
import { z as z2 } from "zod";
|
|
1826
|
-
var watchStateSchema = z2.object({
|
|
1827
|
-
pid: z2.number().int().positive(),
|
|
1828
|
-
version: z2.string().min(1),
|
|
1829
|
-
startedAt: z2.string().datetime()
|
|
1830
|
-
});
|
|
1831
|
-
function getWatchStatePath(env) {
|
|
1832
|
-
return path9.join(getConfigDir(env), "watch.json");
|
|
1833
|
-
}
|
|
1834
|
-
async function readWatchState(filePath, io = fs) {
|
|
1835
|
-
try {
|
|
1836
|
-
const result = watchStateSchema.safeParse(JSON.parse(await io.readFile(filePath, "utf8")));
|
|
1837
|
-
return result.success ? result.data : null;
|
|
1838
|
-
} catch {
|
|
1839
|
-
return null;
|
|
1826
|
+
await deps.http.post(`/api/projects/${projectId}/repo-binding`, { repoIdentity });
|
|
1827
|
+
if (mode2 === "json") {
|
|
1828
|
+
printResult({ rebound: true, projectId, repoIdentity }, mode2);
|
|
1829
|
+
} else {
|
|
1830
|
+
process.stdout.write(`Rebound project ${projectId} to ${repoIdentity.kind}:${repoIdentity.value}.
|
|
1831
|
+
`);
|
|
1840
1832
|
}
|
|
1841
1833
|
}
|
|
1842
|
-
async function
|
|
1843
|
-
|
|
1844
|
-
|
|
1834
|
+
async function handleUnlink(projectBindingPath, mode2) {
|
|
1835
|
+
const { readFile: readFile19, writeFile: writeFile11, chmod: chmod2 } = await import("fs/promises");
|
|
1836
|
+
let existing = {};
|
|
1845
1837
|
try {
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
async function removeWatchState(filePath, pid, io = fs) {
|
|
1854
|
-
if ((await readWatchState(filePath, io))?.pid === pid) {
|
|
1855
|
-
await io.unlink(filePath).catch(() => void 0);
|
|
1856
|
-
}
|
|
1857
|
-
}
|
|
1858
|
-
function isAlive(pid, kill = process.kill) {
|
|
1859
|
-
try {
|
|
1860
|
-
kill(pid, 0);
|
|
1861
|
-
return true;
|
|
1862
|
-
} catch (error) {
|
|
1863
|
-
if (error.code === "ESRCH") return false;
|
|
1864
|
-
if (error.code === "EPERM") return true;
|
|
1865
|
-
throw error;
|
|
1866
|
-
}
|
|
1867
|
-
}
|
|
1868
|
-
async function staleWatchWarning(env, currentVersion, kill = process.kill) {
|
|
1869
|
-
const state = await readWatchState(getWatchStatePath(env));
|
|
1870
|
-
if (!state || state.version === currentVersion || !isAlive(state.pid, kill)) return null;
|
|
1871
|
-
return `Warning: nolto watch (pid ${state.pid}) is running CLI v${state.version}, this CLI is v${currentVersion}. Restart it: nolto watch stop, then start it again (or nolto update).`;
|
|
1872
|
-
}
|
|
1873
|
-
|
|
1874
|
-
// src/commands/init.ts
|
|
1875
|
-
import readline2 from "readline/promises";
|
|
1876
|
-
import { createRequire } from "module";
|
|
1877
|
-
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
1878
|
-
import os3 from "os";
|
|
1879
|
-
import path15 from "path";
|
|
1880
|
-
import fs2 from "fs";
|
|
1881
|
-
|
|
1882
|
-
// src/roadmap-bootstrap.ts
|
|
1883
|
-
import { existsSync as existsSync3 } from "fs";
|
|
1884
|
-
import { readFile as readFile9, realpath } from "fs/promises";
|
|
1885
|
-
import path12 from "path";
|
|
1886
|
-
|
|
1887
|
-
// src/roadmap-cache.ts
|
|
1888
|
-
import { mkdir as mkdir6, readdir as readdir4, readFile as readFile8, writeFile as writeFile7, rename as rename3, unlink as unlink2 } from "fs/promises";
|
|
1889
|
-
import { randomUUID as randomUUID5 } from "crypto";
|
|
1890
|
-
import path11 from "path";
|
|
1891
|
-
|
|
1892
|
-
// src/sync-core.ts
|
|
1893
|
-
import { createHash as createHash2 } from "crypto";
|
|
1894
|
-
import path10 from "path";
|
|
1895
|
-
function sha256Hex(content) {
|
|
1896
|
-
return "sha256:" + createHash2("sha256").update(content, "utf8").digest("hex");
|
|
1897
|
-
}
|
|
1898
|
-
function collectPlanRefs(roadmap) {
|
|
1899
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1900
|
-
const refs = [];
|
|
1901
|
-
for (const phase of roadmap.phases) {
|
|
1902
|
-
if (phase.plan != null && !seen.has(phase.plan)) {
|
|
1903
|
-
seen.add(phase.plan);
|
|
1904
|
-
refs.push({ path: phase.plan, ownerId: phase.id });
|
|
1905
|
-
}
|
|
1906
|
-
for (const task of phase.tasks) {
|
|
1907
|
-
if (task.plan != null && !seen.has(task.plan)) {
|
|
1908
|
-
seen.add(task.plan);
|
|
1909
|
-
refs.push({ path: task.plan, ownerId: task.id });
|
|
1910
|
-
}
|
|
1838
|
+
const raw = await readFile19(projectBindingPath, "utf8");
|
|
1839
|
+
const parsed = JSON.parse(raw);
|
|
1840
|
+
if (parsed == null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
1841
|
+
throw new CliError(
|
|
1842
|
+
`Cannot unlink ${projectBindingPath}: file contains valid JSON but is not a plain object (got ${Array.isArray(parsed) ? "array" : String(parsed)}). Remove or fix the file manually.`,
|
|
1843
|
+
2
|
|
1844
|
+
);
|
|
1911
1845
|
}
|
|
1846
|
+
existing = parsed;
|
|
1847
|
+
} catch (err) {
|
|
1848
|
+
if (err instanceof CliError) throw err;
|
|
1849
|
+
throw new CliError(`Cannot read ${projectBindingPath}: ${String(err)}`, 2);
|
|
1912
1850
|
}
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
}
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
let parsed;
|
|
1923
|
-
try {
|
|
1924
|
-
parsed = JSON.parse(raw);
|
|
1925
|
-
} catch {
|
|
1926
|
-
throw new CliError(`Malformed JSON in ${filePath}.`, 2);
|
|
1851
|
+
const { projectId: _removed, ...rest } = existing;
|
|
1852
|
+
void _removed;
|
|
1853
|
+
await writeFile11(projectBindingPath, JSON.stringify(rest, null, 2) + "\n", { mode: 420 });
|
|
1854
|
+
await chmod2(projectBindingPath, 420);
|
|
1855
|
+
if (mode2 === "json") {
|
|
1856
|
+
printResult({ unlinked: true, projectBindingPath }, mode2);
|
|
1857
|
+
} else {
|
|
1858
|
+
process.stdout.write(`Removed projectId from ${projectBindingPath}.
|
|
1859
|
+
`);
|
|
1927
1860
|
}
|
|
1928
|
-
|
|
1929
|
-
|
|
1861
|
+
}
|
|
1862
|
+
async function performLink(deps, projectId, mode2, slug, yes = false) {
|
|
1863
|
+
if (!UUID_RE2.test(projectId)) {
|
|
1930
1864
|
throw new CliError(
|
|
1931
|
-
|
|
1932
|
-
${errors.join("\n ")}`,
|
|
1865
|
+
`Invalid project ID: "${projectId}". Must be a UUID (e.g. 00000000-0000-0000-0000-000000000001).`,
|
|
1933
1866
|
2
|
|
1934
1867
|
);
|
|
1935
1868
|
}
|
|
1936
|
-
|
|
1937
|
-
}
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1869
|
+
const startDir = resolveStartDir(process.env, process.cwd());
|
|
1870
|
+
const { root, foundGit } = findRepoRoot(startDir);
|
|
1871
|
+
if (!foundGit) {
|
|
1872
|
+
process.stderr.write(
|
|
1873
|
+
`Warning: no .git directory found above ${startDir}. Writing nolto.json to current directory.
|
|
1874
|
+
`
|
|
1875
|
+
);
|
|
1876
|
+
}
|
|
1877
|
+
const http = deps.http ?? createHttpClient({
|
|
1878
|
+
baseUrl: deps.settings.baseUrl,
|
|
1879
|
+
token: deps.settings.token,
|
|
1880
|
+
version: deps.version
|
|
1881
|
+
});
|
|
1882
|
+
let projectName = path11.basename(root);
|
|
1883
|
+
if (deps.settings.token != null) {
|
|
1945
1884
|
try {
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1885
|
+
const result = await http.get(
|
|
1886
|
+
"/api/projects"
|
|
1887
|
+
);
|
|
1888
|
+
const projects = Array.isArray(result.projects) ? result.projects : [];
|
|
1889
|
+
projectName = projects.find((p) => p.id === projectId)?.name ?? projectName;
|
|
1890
|
+
if (!projects.some((p) => p.id === projectId)) {
|
|
1891
|
+
process.stderr.write(
|
|
1892
|
+
`Warning: project ${projectId} was not found in GET /api/projects.
|
|
1893
|
+
Proceeding anyway \u2014 verify the ID is correct.
|
|
1894
|
+
`
|
|
1895
|
+
);
|
|
1949
1896
|
}
|
|
1950
1897
|
} catch {
|
|
1898
|
+
process.stderr.write(
|
|
1899
|
+
"Warning: could not verify project membership (offline or token issue). Proceeding anyway.\n"
|
|
1900
|
+
);
|
|
1951
1901
|
}
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1902
|
+
}
|
|
1903
|
+
if (deps.repoBinding?.error != null) {
|
|
1904
|
+
process.stderr.write(
|
|
1905
|
+
`Warning: existing nolto.json is invalid (${deps.repoBinding.error.message}). Overwriting it to repair.
|
|
1906
|
+
`
|
|
1907
|
+
);
|
|
1908
|
+
}
|
|
1909
|
+
await writeRepoBinding(root, projectId);
|
|
1910
|
+
const writtenPath = path11.join(root, "nolto.json");
|
|
1911
|
+
let repoAdded = false;
|
|
1912
|
+
if (deps.settings.token == null) {
|
|
1913
|
+
process.stderr.write("Warning: roadmap cache not initialized (no token); run nolto pull after nolto login\n");
|
|
1914
|
+
} else {
|
|
1915
|
+
const repoIdentity = await makeRepoIdentityResolver(deps)(root);
|
|
1916
|
+
const result = await ensureProjectRepo({
|
|
1917
|
+
http,
|
|
1918
|
+
projectId,
|
|
1919
|
+
repoIdentity,
|
|
1920
|
+
confirm: async (question) => {
|
|
1921
|
+
if (yes) return true;
|
|
1922
|
+
if (mode2 === "json") throw new CliError("Adding this repository requires confirmation. Pass --yes to skip the prompt in --json mode.", 2);
|
|
1923
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
1924
|
+
try {
|
|
1925
|
+
const answer = (await rl.question(question)).trim().toLowerCase();
|
|
1926
|
+
return answer === "" || answer === "y" || answer === "yes";
|
|
1927
|
+
} finally {
|
|
1928
|
+
rl.close();
|
|
1929
|
+
}
|
|
1930
|
+
},
|
|
1931
|
+
log: (line2) => {
|
|
1932
|
+
if (mode2 !== "json") process.stdout.write(line2 + "\n");
|
|
1971
1933
|
}
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1934
|
+
});
|
|
1935
|
+
if (result === "declined") {
|
|
1936
|
+
process.stdout.write("Skipped adding this repository. Run `nolto link --add` later; roadmap sync will fail until then.\n");
|
|
1937
|
+
return;
|
|
1938
|
+
}
|
|
1939
|
+
repoAdded = result === "added";
|
|
1940
|
+
await ensureRoadmapCache({
|
|
1941
|
+
env: process.env,
|
|
1942
|
+
http,
|
|
1943
|
+
projectId,
|
|
1944
|
+
projectName,
|
|
1945
|
+
repoRoot: root,
|
|
1946
|
+
slug,
|
|
1947
|
+
repoIdentity,
|
|
1948
|
+
log: (line2) => {
|
|
1949
|
+
if (mode2 !== "json") process.stdout.write(line2 + "\n");
|
|
1975
1950
|
}
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1951
|
+
});
|
|
1952
|
+
}
|
|
1953
|
+
let registryAdded = false;
|
|
1954
|
+
if (isHomeDirectory(root)) {
|
|
1955
|
+
process.stderr.write(`Warning: refusing to add home directory ${root} to the watch registry.
|
|
1956
|
+
`);
|
|
1957
|
+
} else {
|
|
1958
|
+
try {
|
|
1959
|
+
registryAdded = (await addRepoToRegistry(getRegistryPath(process.env), { root, projectId })).added;
|
|
1960
|
+
if (registryAdded) {
|
|
1961
|
+
const warning = await staleWatchWarning(process.env, deps.version, process.kill);
|
|
1962
|
+
if (warning) process.stderr.write(warning + "\n");
|
|
1979
1963
|
}
|
|
1964
|
+
} catch (err) {
|
|
1965
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1966
|
+
process.stderr.write(`Warning: could not update watch registry: ${message}
|
|
1967
|
+
`);
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
if (mode2 === "json") {
|
|
1971
|
+
printResult({
|
|
1972
|
+
linked: true,
|
|
1973
|
+
projectId,
|
|
1974
|
+
projectBindingPath: writtenPath,
|
|
1975
|
+
registryAdded,
|
|
1976
|
+
repoAdded
|
|
1977
|
+
}, mode2);
|
|
1978
|
+
} else {
|
|
1979
|
+
process.stdout.write(
|
|
1980
|
+
`Linked this repo to project ${projectId} (wrote ${writtenPath}).
|
|
1981
|
+
Commit nolto.json to share the binding with your team.
|
|
1982
|
+
`
|
|
1983
|
+
);
|
|
1984
|
+
if (registryAdded) {
|
|
1985
|
+
process.stdout.write(`watch registry: added ${root}
|
|
1986
|
+
`);
|
|
1980
1987
|
}
|
|
1981
|
-
const content = await args.deps.readFile(absolute);
|
|
1982
|
-
planDocuments.push({
|
|
1983
|
-
path: ref.path,
|
|
1984
|
-
taskId: ref.ownerId,
|
|
1985
|
-
content,
|
|
1986
|
-
contentHash: sha256Hex(content)
|
|
1987
|
-
});
|
|
1988
1988
|
}
|
|
1989
|
-
return { roadmap: args.roadmap, planDocuments, repoIdentity: args.repoIdentity };
|
|
1990
1989
|
}
|
|
1991
|
-
|
|
1992
|
-
const
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
deps
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
);
|
|
2007
|
-
return response;
|
|
2008
|
-
}
|
|
2009
|
-
|
|
2010
|
-
// src/roadmap-cache.ts
|
|
2011
|
-
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
2012
|
-
var ROADMAP_SLUG_PATTERN = /^[a-z0-9][a-z0-9._-]*$/;
|
|
2013
|
-
function cacheDir(env, projectId) {
|
|
2014
|
-
if (!UUID_RE.test(projectId)) throw new CliError(`Invalid project id "${projectId}".`, 2);
|
|
2015
|
-
return path11.join(getConfigDir(env), "projects", projectId, "roadmaps");
|
|
2016
|
-
}
|
|
2017
|
-
function cachePaths(env, projectId, slug) {
|
|
2018
|
-
if (!ROADMAP_SLUG_PATTERN.test(slug)) throw new CliError(`Invalid roadmap slug "${slug}".`, 2);
|
|
2019
|
-
const dir = cacheDir(env, projectId);
|
|
2020
|
-
return { json: path11.join(dir, `${slug}.json`), meta: path11.join(dir, `${slug}.meta.json`) };
|
|
2021
|
-
}
|
|
2022
|
-
async function listCachedSlugs(env, projectId) {
|
|
2023
|
-
try {
|
|
2024
|
-
const entries = await readdir4(cacheDir(env, projectId), { withFileTypes: true });
|
|
2025
|
-
return entries.filter((entry) => entry.isFile() && entry.name.endsWith(".json") && !entry.name.endsWith(".meta.json")).map((entry) => entry.name.slice(0, -5)).sort();
|
|
2026
|
-
} catch (err) {
|
|
2027
|
-
if (err.code === "ENOENT") return [];
|
|
2028
|
-
throw err;
|
|
2029
|
-
}
|
|
2030
|
-
}
|
|
2031
|
-
async function readCache(env, projectId, slug) {
|
|
2032
|
-
const paths = cachePaths(env, projectId, slug);
|
|
2033
|
-
let raw;
|
|
2034
|
-
try {
|
|
2035
|
-
raw = await readFile8(paths.json, "utf8");
|
|
2036
|
-
} catch (err) {
|
|
2037
|
-
if (err.code === "ENOENT") return null;
|
|
2038
|
-
throw err;
|
|
2039
|
-
}
|
|
2040
|
-
let roadmap;
|
|
2041
|
-
try {
|
|
2042
|
-
roadmap = JSON.parse(raw);
|
|
2043
|
-
} catch {
|
|
2044
|
-
throw new CliError(`Malformed JSON in ${paths.json}.`, 2);
|
|
2045
|
-
}
|
|
2046
|
-
const { errors } = validateRoadmap(roadmap);
|
|
2047
|
-
if (errors.length) throw new CliError(`${paths.json} failed validation: ${errors.join("; ")}`, 2);
|
|
2048
|
-
let meta = null;
|
|
2049
|
-
try {
|
|
2050
|
-
const parsed = JSON.parse(await readFile8(paths.meta, "utf8"));
|
|
2051
|
-
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") {
|
|
2052
|
-
throw new Error("Invalid cache metadata");
|
|
1990
|
+
function register(program, deps) {
|
|
1991
|
+
const cmd = program.command("link [projectId]").description(
|
|
1992
|
+
"Bind this repository to a Nolto project.\nWrites nolto.json at the repo root. Commit it to share the binding with your team.\n\nExamples:\n nolto link <uuid> Write / update nolto.json\n nolto link --show Show the current binding\n nolto link --rebind Rebind the project to this repository\n nolto link --list List project repositories\n nolto link --add Add this repository to the project\n nolto link --remove <identity-or-id> Remove a project repository\n nolto link --unlink Remove the projectId from nolto.json"
|
|
1993
|
+
).option("--slug <slug>", "Name this repository's roadmap").option("--list", "List project repositories").option("--add", "Add this repository to the project").option("--label <text>", "Label the added repository").option("--remove <identity-or-id>", "Remove a project repository").option("--show", "Show the current repo binding (path + projectId + source)").option("--rebind", "Rebind the project to this repository (owner only, once per 7 days)").option("-y, --yes", "Skip repository addition, rebind, and removal confirmation prompts").option("--unlink", "Remove the projectId key from nolto.json");
|
|
1994
|
+
cmd.action(async (projectId) => {
|
|
1995
|
+
const { output } = deps;
|
|
1996
|
+
const projectBindingPath = deps.repoBinding?.path ?? deps.projectBindingPath ?? null;
|
|
1997
|
+
const bindingError = deps.repoBinding?.error ?? null;
|
|
1998
|
+
const mode2 = output.mode;
|
|
1999
|
+
if (cmd.opts()["show"]) {
|
|
2000
|
+
if (bindingError != null) {
|
|
2001
|
+
throw invalidBindingError(projectBindingPath, bindingError);
|
|
2002
|
+
}
|
|
2003
|
+
await handleShow(deps, projectBindingPath, mode2);
|
|
2004
|
+
return;
|
|
2053
2005
|
}
|
|
2054
|
-
if (
|
|
2055
|
-
|
|
2006
|
+
if (cmd.opts()["unlink"]) {
|
|
2007
|
+
if (projectBindingPath == null) {
|
|
2008
|
+
throw new CliError("No nolto.json found in this directory tree. Nothing to unlink.", 2);
|
|
2009
|
+
}
|
|
2010
|
+
await handleUnlink(projectBindingPath, mode2);
|
|
2011
|
+
return;
|
|
2056
2012
|
}
|
|
2057
|
-
|
|
2058
|
-
|
|
2013
|
+
const opts = cmd.opts();
|
|
2014
|
+
if (opts["list"] || opts["add"] || opts["remove"] !== void 0 || opts["slug"] !== void 0) {
|
|
2015
|
+
if (projectId == null) {
|
|
2016
|
+
if (bindingError != null) throw invalidBindingError(projectBindingPath, bindingError);
|
|
2017
|
+
const binding = deps.repoBinding?.binding ?? (projectBindingPath ? await loadRepoBinding(projectBindingPath) : null);
|
|
2018
|
+
projectId = binding?.projectId;
|
|
2019
|
+
}
|
|
2020
|
+
if (projectId == null) throw new CliError("No project binding. Run `nolto link <projectId>` first.", 2);
|
|
2021
|
+
if (!UUID_RE2.test(projectId)) throw new CliError(`Invalid project ID: "${projectId}". Must be a UUID.`, 2);
|
|
2022
|
+
if (opts["add"]) {
|
|
2023
|
+
const root = findRepoRoot(resolveStartDir(process.env, process.cwd())).root;
|
|
2024
|
+
const repoIdentity = await makeRepoIdentityResolver(deps)(root);
|
|
2025
|
+
const repo = await deps.http.post(`/api/projects/${projectId}/repos`, {
|
|
2026
|
+
repoIdentity,
|
|
2027
|
+
...opts["label"] !== void 0 ? { label: opts["label"] } : {}
|
|
2028
|
+
});
|
|
2029
|
+
printResult(mode2 === "json" ? { added: true, projectId, repo } : `Added ${repoIdentity.kind}:${repoIdentity.value} to project ${projectId}.`, mode2);
|
|
2030
|
+
return;
|
|
2031
|
+
}
|
|
2032
|
+
if (opts["list"] || opts["remove"] !== void 0) {
|
|
2033
|
+
const { repos } = await deps.http.get(`/api/projects/${projectId}`);
|
|
2034
|
+
if (opts["list"]) {
|
|
2035
|
+
if (mode2 === "json") printResult({ repos }, mode2);
|
|
2036
|
+
else for (const repo2 of repos) printResult(`${repo2.identity}${repo2.label ? ` (${repo2.label})` : ""} ${repo2.boundAt} ${repo2.id}`, mode2);
|
|
2037
|
+
return;
|
|
2038
|
+
}
|
|
2039
|
+
const input = opts["remove"];
|
|
2040
|
+
const identity = /^(remote|local):/.test(input) ? input : `remote:${input}`;
|
|
2041
|
+
const repo = repos.find((row) => row.id === input || row.identity === identity);
|
|
2042
|
+
if (!repo) throw new CliError(`Repository ${input} is not bound to this project.`, 2);
|
|
2043
|
+
if (!opts["yes"]) {
|
|
2044
|
+
if (mode2 === "json") throw new CliError("--remove requires confirmation. Pass --yes to skip the prompt in --json mode.", 2);
|
|
2045
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
2046
|
+
let confirmed = false;
|
|
2047
|
+
try {
|
|
2048
|
+
const answer = await rl.question(`Remove "${repo.identity}" from project ${projectId}? [y/N] `);
|
|
2049
|
+
confirmed = answer.trim().toLowerCase() === "y";
|
|
2050
|
+
} finally {
|
|
2051
|
+
rl.close();
|
|
2052
|
+
}
|
|
2053
|
+
if (!confirmed) {
|
|
2054
|
+
process.stdout.write("Aborted.\n");
|
|
2055
|
+
return;
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
await deps.http.delete(`/api/projects/${projectId}/repos/${repo.id}`);
|
|
2059
|
+
printResult(mode2 === "json" ? { removed: true, projectId, repoId: repo.id } : `Removed ${repo.identity} from project ${projectId}.`, mode2);
|
|
2060
|
+
return;
|
|
2061
|
+
}
|
|
2059
2062
|
}
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2063
|
+
if (cmd.opts()["rebind"]) {
|
|
2064
|
+
const boundProjectId = deps.repoBinding?.binding?.projectId;
|
|
2065
|
+
const effectiveProjectId = projectId ?? boundProjectId;
|
|
2066
|
+
if (effectiveProjectId == null) {
|
|
2067
|
+
throw new CliError("No project binding. Run `nolto link <projectId>` first.", 2);
|
|
2068
|
+
}
|
|
2069
|
+
const startDir = resolveStartDir(process.env, process.cwd());
|
|
2070
|
+
const root = findRepoRoot(startDir).root;
|
|
2071
|
+
await handleRebind(deps, effectiveProjectId, root, mode2, cmd.opts()["yes"] === true);
|
|
2072
|
+
return;
|
|
2064
2073
|
}
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
for (const [filePath, content] of [[paths.json, raw], [paths.meta, JSON.stringify(metadata, null, 2) + "\n"]]) {
|
|
2074
|
-
const temp = `${filePath}.tmp-${process.pid}-${randomUUID5()}`;
|
|
2075
|
-
try {
|
|
2076
|
-
await writeFile7(temp, content, { mode: 384 });
|
|
2077
|
-
await rename3(temp, filePath);
|
|
2078
|
-
} finally {
|
|
2079
|
-
await unlink2(temp).catch(() => void 0);
|
|
2074
|
+
if (projectId == null || projectId.trim().length === 0) {
|
|
2075
|
+
if (bindingError != null) {
|
|
2076
|
+
throw invalidBindingError(projectBindingPath, bindingError);
|
|
2077
|
+
}
|
|
2078
|
+
throw new CliError(
|
|
2079
|
+
"Usage: nolto link <projectId> (provide a UUID)\nOr use --show to view the current binding, --rebind to rebind it, --unlink to remove it.",
|
|
2080
|
+
2
|
|
2081
|
+
);
|
|
2080
2082
|
}
|
|
2081
|
-
|
|
2082
|
-
}
|
|
2083
|
-
function isDirty(entry) {
|
|
2084
|
-
return entry.meta === null || sha256Hex(entry.raw) !== entry.meta.contentHash;
|
|
2085
|
-
}
|
|
2086
|
-
|
|
2087
|
-
// src/roadmap-scaffold.ts
|
|
2088
|
-
function slugifyProjectId(name) {
|
|
2089
|
-
const slug = name.toLowerCase().replace(/[^a-z0-9.-]+/g, "-").replace(/^[^a-z0-9]+/, "").replace(/[-_.]+$/, "");
|
|
2090
|
-
return slug.length > 0 ? slug : "project";
|
|
2083
|
+
await performLink(deps, projectId, mode2, opts["slug"], opts["yes"] === true);
|
|
2084
|
+
});
|
|
2091
2085
|
}
|
|
2092
|
-
function
|
|
2093
|
-
return
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
phases: []
|
|
2098
|
-
};
|
|
2086
|
+
function invalidBindingError(projectBindingPath, error) {
|
|
2087
|
+
return new CliError(
|
|
2088
|
+
`Invalid nolto.json at ${projectBindingPath ?? "unknown path"}: ${error.message}. Repair it with \`nolto link <projectId>\` or \`nolto init\`.`,
|
|
2089
|
+
2
|
|
2090
|
+
);
|
|
2099
2091
|
}
|
|
2100
2092
|
|
|
2101
|
-
// src/roadmap-
|
|
2102
|
-
async function
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
const validation = validateRoadmap(response.roadmap);
|
|
2106
|
-
if (validation.errors.length > 0) {
|
|
2107
|
-
throw new CliError(`Server roadmap "${slug}" failed validation: ${validation.errors.join("; ")}`, 5);
|
|
2093
|
+
// src/roadmap-read.ts
|
|
2094
|
+
async function resolveRoadmapReadContext(deps) {
|
|
2095
|
+
if (deps.settings.token == null) {
|
|
2096
|
+
throw new CliError("Not authenticated. Run `nolto login` or set NOLTO_TOKEN.", 3);
|
|
2108
2097
|
}
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
if (!(err instanceof CliError) || !(args.force || args.recoverInvalid)) throw err;
|
|
2114
|
-
existing = null;
|
|
2098
|
+
const startDir = resolveStartDir(process.env, process.cwd());
|
|
2099
|
+
const { root, foundGit } = findRepoRoot(startDir);
|
|
2100
|
+
if (!foundGit) {
|
|
2101
|
+
throw new CliError("No git repository found. Run inside a repo set up with `nolto init`.", 2);
|
|
2115
2102
|
}
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2103
|
+
const binding = await loadRepoBinding(path12.join(root, "nolto.json"));
|
|
2104
|
+
const projectId = binding?.projectId ?? deps.settings.defaultProjectId;
|
|
2105
|
+
if (projectId == null) {
|
|
2106
|
+
throw new CliError("No project binding. Run `nolto init` or `nolto link <projectId>`.", 2);
|
|
2119
2107
|
}
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2108
|
+
return { root, projectId };
|
|
2109
|
+
}
|
|
2110
|
+
|
|
2111
|
+
// src/commands/pull.ts
|
|
2112
|
+
function register2(program, deps) {
|
|
2113
|
+
program.command("pull [slug]").description("Pull server roadmaps into the local cache.").option("--all", "Pull all roadmaps (the default when no slug is specified)").option("--force", "Overwrite local changes that have not been synced").action(async (requestedSlug, opts) => {
|
|
2114
|
+
await runPull(deps, { ...opts, slug: requestedSlug });
|
|
2126
2115
|
});
|
|
2127
|
-
args.log(unchanged ? `unchanged ${slug}` : `pulled ${slug} (rev ${response.revision})`);
|
|
2128
|
-
return true;
|
|
2129
2116
|
}
|
|
2130
|
-
async function
|
|
2131
|
-
const
|
|
2132
|
-
const
|
|
2133
|
-
const list = await
|
|
2134
|
-
const
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
const log = (line2) => args.log(`roadmap: ${line2}`);
|
|
2138
|
-
if (list.roadmaps.length > 0) {
|
|
2139
|
-
let skipped = false;
|
|
2140
|
-
for (const { slug: slug2 } of list.roadmaps) {
|
|
2141
|
-
if (!await pullRoadmapCache({ ...args, slug: slug2, warn: warn2, log, recoverInvalid: true })) skipped = true;
|
|
2142
|
-
}
|
|
2143
|
-
if (skipped) throw new CliError("Some roadmaps have local changes that are not synced.", 4);
|
|
2144
|
-
if (list.roadmaps.some((row) => row.repoIdentity == null || row.repoIdentity === identity)) return;
|
|
2145
|
-
}
|
|
2146
|
-
const basename = path12.basename(args.repoRoot);
|
|
2147
|
-
const slug = args.slug ?? slugifyProjectId(basename);
|
|
2148
|
-
const collision = list.roadmaps.find((row) => row.slug === slug);
|
|
2149
|
-
if (collision) {
|
|
2150
|
-
if (args.slug === void 0) {
|
|
2151
|
-
log(`skipped \u2014 "${slug}" is another repository's roadmap (${collision.repoIdentity ?? "unknown"}). Run \`nolto link --slug <name>\` to create one for this repository.`);
|
|
2152
|
-
return;
|
|
2153
|
-
}
|
|
2154
|
-
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);
|
|
2117
|
+
async function runPull(deps, opts = {}) {
|
|
2118
|
+
const messages = [];
|
|
2119
|
+
const { projectId } = await resolveRoadmapReadContext(deps);
|
|
2120
|
+
const list = await deps.http.get(`/api/projects/${projectId}/roadmaps`);
|
|
2121
|
+
const serverBySlug = new Map(list.roadmaps.map((roadmap) => [roadmap.slug, roadmap]));
|
|
2122
|
+
if (opts.slug != null && !serverBySlug.has(opts.slug)) {
|
|
2123
|
+
throw new CliError(`Roadmap "${opts.slug}" was not found on the server.`, 2);
|
|
2155
2124
|
}
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
readFile: (p) => readFile9(p, "utf8"),
|
|
2172
|
-
realpath,
|
|
2173
|
-
fileExists: existsSync3,
|
|
2174
|
-
log: () => void 0,
|
|
2175
|
-
warn: warn2
|
|
2176
|
-
});
|
|
2177
|
-
await writeCache(env, projectId, slug, response.roadmap ?? roadmap, { repoIdentity: identity, revision: response.revision, pulledAt: (/* @__PURE__ */ new Date()).toISOString(), currentTaskId: response.currentTaskId !== void 0 ? response.currentTaskId : existing?.meta?.currentTaskId });
|
|
2178
|
-
log(`created ${slug} on server (rev ${response.revision})`);
|
|
2179
|
-
}
|
|
2180
|
-
async function ensureProjectRepo(args) {
|
|
2181
|
-
let repos;
|
|
2182
|
-
try {
|
|
2183
|
-
const project = await args.http.get(`/api/projects/${args.projectId}`);
|
|
2184
|
-
repos = Array.isArray(project.repos) ? project.repos : [];
|
|
2185
|
-
} catch (error) {
|
|
2186
|
-
if (error instanceof CliError && (error.status === 401 || error.status === 403)) throw error;
|
|
2187
|
-
process.stderr.write(`Warning: could not check project repositories: ${error instanceof Error ? error.message : String(error)}
|
|
2188
|
-
`);
|
|
2189
|
-
return "unbound";
|
|
2190
|
-
}
|
|
2191
|
-
if (repos.length === 0) return "unbound";
|
|
2192
|
-
const identity = repoIdentityToString(args.repoIdentity);
|
|
2193
|
-
if (repos.some((repo) => repo.identity === identity)) return "bound";
|
|
2194
|
-
if (!await args.confirm(`Project is bound to ${repos.map((repo) => repo.identity).join(", ")}. Add this repository (${identity}) to the project? [Y/n] `)) return "declined";
|
|
2195
|
-
try {
|
|
2196
|
-
await args.http.post(`/api/projects/${args.projectId}/repos`, { repoIdentity: args.repoIdentity });
|
|
2197
|
-
} catch (error) {
|
|
2198
|
-
if (error instanceof CliError) {
|
|
2199
|
-
if (error.status === 409 && error.serverError === "repo_already_bound_to_this") return "bound";
|
|
2200
|
-
if (error.status === 403) {
|
|
2201
|
-
throw new CliError(
|
|
2202
|
-
"Only the project owner can add a repository.",
|
|
2203
|
-
2,
|
|
2204
|
-
"Ask the owner to run `nolto link --add` in this repository."
|
|
2205
|
-
);
|
|
2125
|
+
const slugs = opts.slug == null ? [...serverBySlug.keys()] : [opts.slug];
|
|
2126
|
+
let skipped = false;
|
|
2127
|
+
for (const slug of slugs) {
|
|
2128
|
+
if (!await pullRoadmapCache({
|
|
2129
|
+
env: process.env,
|
|
2130
|
+
http: deps.http,
|
|
2131
|
+
projectId,
|
|
2132
|
+
slug,
|
|
2133
|
+
force: opts.force,
|
|
2134
|
+
log: (line2) => {
|
|
2135
|
+
messages.push(line2);
|
|
2136
|
+
if (!opts.quiet && deps.output.mode !== "json") process.stdout.write(line2 + "\n");
|
|
2137
|
+
},
|
|
2138
|
+
warn: (line2) => {
|
|
2139
|
+
process.stderr.write(line2 + "\n");
|
|
2206
2140
|
}
|
|
2207
|
-
|
|
2208
|
-
}
|
|
2209
|
-
throw error;
|
|
2141
|
+
})) skipped = true;
|
|
2210
2142
|
}
|
|
2211
|
-
|
|
2212
|
-
|
|
2143
|
+
if (skipped) throw new CliError("Some roadmaps have local changes that are not synced.", 4);
|
|
2144
|
+
if (!opts.quiet && deps.output.mode === "json") printResult({ messages }, "json");
|
|
2213
2145
|
}
|
|
2214
2146
|
|
|
2215
|
-
// src/commands/
|
|
2216
|
-
import
|
|
2217
|
-
import
|
|
2218
|
-
import
|
|
2219
|
-
import {
|
|
2147
|
+
// src/commands/sync.ts
|
|
2148
|
+
import { execFile as execFile2 } from "child_process";
|
|
2149
|
+
import { promisify } from "util";
|
|
2150
|
+
import { readFile as readFile8, realpath as realpath2 } from "fs/promises";
|
|
2151
|
+
import { existsSync as existsSync4 } from "fs";
|
|
2220
2152
|
|
|
2221
|
-
// src/
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
repos: z3.array(z3.object({ root: z3.string().min(1), projectId: z3.string().uuid().optional() }).passthrough())
|
|
2229
|
-
}).passthrough();
|
|
2230
|
-
function getRegistryPath(env) {
|
|
2231
|
-
return path13.join(getConfigDir(env), "registry.json");
|
|
2232
|
-
}
|
|
2233
|
-
async function loadRegistry(filePath) {
|
|
2234
|
-
let raw;
|
|
2235
|
-
try {
|
|
2236
|
-
raw = await readFile10(filePath, "utf8");
|
|
2237
|
-
} catch (err) {
|
|
2238
|
-
const code = err != null && typeof err === "object" && "code" in err ? err.code : "";
|
|
2239
|
-
if (code === "ENOENT") {
|
|
2240
|
-
return { schemaVersion: 1, repos: [] };
|
|
2153
|
+
// src/git-links.ts
|
|
2154
|
+
function parseGitLog(raw) {
|
|
2155
|
+
return raw.split("\n").filter((line2) => line2.length > 0).map((line2) => {
|
|
2156
|
+
const fields = line2.replace(/\r$/, "").split("");
|
|
2157
|
+
const [ref, subject, author, committedAt] = fields;
|
|
2158
|
+
if (fields.length !== 4 || !ref || !/^[0-9a-f]{40}$/.test(ref) || subject === void 0 || author === void 0 || !committedAt || !Number.isFinite(Date.parse(committedAt))) {
|
|
2159
|
+
throw new Error("Malformed git log entry");
|
|
2241
2160
|
}
|
|
2242
|
-
|
|
2243
|
-
}
|
|
2244
|
-
let parsed;
|
|
2245
|
-
try {
|
|
2246
|
-
parsed = JSON.parse(raw);
|
|
2247
|
-
} catch {
|
|
2248
|
-
throw new CliError(`Malformed JSON in ${filePath}. Fix or remove the file.`, 2);
|
|
2249
|
-
}
|
|
2250
|
-
const result = registrySchema.safeParse(parsed);
|
|
2251
|
-
if (!result.success) {
|
|
2252
|
-
const issue = result.error.issues[0];
|
|
2253
|
-
const fieldPath = issue?.path.join(".") ?? "";
|
|
2254
|
-
throw new CliError(
|
|
2255
|
-
`Invalid registry at ${filePath}: ${fieldPath.length > 0 ? `field "${fieldPath}" \u2014 ` : ""}${issue?.message ?? "validation failed"}`,
|
|
2256
|
-
2
|
|
2257
|
-
);
|
|
2258
|
-
}
|
|
2259
|
-
return result.data;
|
|
2161
|
+
return { ref, subject, author, committedAt: new Date(committedAt).toISOString() };
|
|
2162
|
+
});
|
|
2260
2163
|
}
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
const existing = registry.repos.find((repo) => repo.root === entry.root);
|
|
2264
|
-
if (existing?.projectId === entry.projectId) {
|
|
2265
|
-
return { added: false, updated: false, registry };
|
|
2266
|
-
}
|
|
2267
|
-
const updated = {
|
|
2268
|
-
...registry,
|
|
2269
|
-
repos: existing ? registry.repos.map((repo) => repo.root === entry.root ? { ...repo, projectId: entry.projectId } : repo) : [...registry.repos, entry]
|
|
2270
|
-
};
|
|
2271
|
-
await writeRegistry(filePath, updated);
|
|
2272
|
-
return { added: !existing, updated: !!existing, registry: updated };
|
|
2164
|
+
function extractIssueKeys(subject) {
|
|
2165
|
+
return [...new Set([...subject.matchAll(/\b([A-Z][A-Z0-9]{1,9})-([1-9][0-9]{0,8})\b/g)].map((match) => match[0]))];
|
|
2273
2166
|
}
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
const tempPath = `${filePath}.tmp-${process.pid}-${randomUUID6()}`;
|
|
2277
|
-
try {
|
|
2278
|
-
await writeFile8(tempPath, JSON.stringify(registry, null, 2) + "\n", "utf8");
|
|
2279
|
-
await rename4(tempPath, filePath);
|
|
2280
|
-
} catch (err) {
|
|
2281
|
-
await unlink3(tempPath).catch(() => void 0);
|
|
2282
|
-
throw err;
|
|
2283
|
-
}
|
|
2167
|
+
function extractPrNumber(subject) {
|
|
2168
|
+
return /\(#([1-9][0-9]{0,8})\)$/.exec(subject)?.[1] ?? /^Merge pull request #([1-9][0-9]{0,8})\b/.exec(subject)?.[1] ?? null;
|
|
2284
2169
|
}
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2170
|
+
function buildGitLinksPayload(entries) {
|
|
2171
|
+
return { links: entries.flatMap((entry) => {
|
|
2172
|
+
const keys = extractIssueKeys(entry.subject);
|
|
2173
|
+
const pr = extractPrNumber(entry.subject);
|
|
2174
|
+
const refs = [{ kind: "commit", ref: entry.ref }, ...pr ? [{ kind: "pr", ref: pr }] : []];
|
|
2175
|
+
return refs.flatMap((ref) => Array.from({ length: Math.ceil(keys.length / 20) }, (_, index) => ({
|
|
2176
|
+
...ref,
|
|
2177
|
+
title: entry.subject.slice(0, 500),
|
|
2178
|
+
author: entry.author.slice(0, 500),
|
|
2179
|
+
committedAt: entry.committedAt,
|
|
2180
|
+
issueKeys: keys.slice(index * 20, (index + 1) * 20)
|
|
2181
|
+
})));
|
|
2182
|
+
}) };
|
|
2292
2183
|
}
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
function resolveStartDir(env, cwd) {
|
|
2297
|
-
const cpd = env["CLAUDE_PROJECT_DIR"];
|
|
2298
|
-
return cpd != null && cpd.length > 0 ? cpd : cwd;
|
|
2184
|
+
function stdout(result) {
|
|
2185
|
+
if (typeof result === "object" && result !== null && "stdout" in result && typeof result.stdout === "string") return result.stdout;
|
|
2186
|
+
throw new Error("Git command returned no text output");
|
|
2299
2187
|
}
|
|
2300
|
-
function
|
|
2188
|
+
async function collectGitLinks(root, exec) {
|
|
2189
|
+
let probe;
|
|
2301
2190
|
try {
|
|
2302
|
-
|
|
2303
|
-
return true;
|
|
2191
|
+
probe = await exec("git", ["rev-parse", "--is-inside-work-tree"], { cwd: root });
|
|
2304
2192
|
} catch {
|
|
2305
|
-
return
|
|
2193
|
+
return null;
|
|
2306
2194
|
}
|
|
2195
|
+
if (stdout(probe).trim() !== "true") return null;
|
|
2196
|
+
const result = await exec("git", ["log", "--no-color", "--format=%H%x1f%s%x1f%an%x1f%cI", "-n", "300"], { cwd: root });
|
|
2197
|
+
return buildGitLinksPayload(parseGitLog(stdout(result)));
|
|
2307
2198
|
}
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2199
|
+
|
|
2200
|
+
// src/sync-repo.ts
|
|
2201
|
+
import path13 from "path";
|
|
2202
|
+
import { readdir as readdir3 } from "fs/promises";
|
|
2203
|
+
function collectContainedPlanAbsPaths(roadmaps, root, warn2) {
|
|
2204
|
+
const planAbsPaths = /* @__PURE__ */ new Set();
|
|
2205
|
+
const resolvedRoot = path13.resolve(root);
|
|
2206
|
+
for (const roadmap of roadmaps) {
|
|
2207
|
+
for (const ref of collectPlanRefs(roadmap)) {
|
|
2208
|
+
const absolute = path13.resolve(resolvedRoot, ref.path);
|
|
2209
|
+
if (absolute !== resolvedRoot && !absolute.startsWith(resolvedRoot + path13.sep)) {
|
|
2210
|
+
warn2(`chokidar target outside repo, skipping: ${ref.path}`);
|
|
2211
|
+
continue;
|
|
2212
|
+
}
|
|
2213
|
+
if (!isValidPlanPath(ref.path)) {
|
|
2214
|
+
warn2(`plan path not allowed (markdown only, no dot segments), skipping: ${ref.path}`);
|
|
2215
|
+
continue;
|
|
2216
|
+
}
|
|
2217
|
+
planAbsPaths.add(absolute);
|
|
2313
2218
|
}
|
|
2314
|
-
const parent = path14.dirname(current);
|
|
2315
|
-
if (parent === current) break;
|
|
2316
|
-
current = parent;
|
|
2317
2219
|
}
|
|
2318
|
-
return
|
|
2319
|
-
}
|
|
2320
|
-
function isHomeDirectory(dir, home = os2.homedir()) {
|
|
2321
|
-
return path14.resolve(dir) === path14.resolve(home);
|
|
2220
|
+
return [...planAbsPaths];
|
|
2322
2221
|
}
|
|
2323
|
-
async function
|
|
2324
|
-
const
|
|
2325
|
-
const
|
|
2326
|
-
const
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2222
|
+
async function syncRepo(args, io) {
|
|
2223
|
+
const { projectId } = args;
|
|
2224
|
+
const repoIdentity = await io.repoIdentity(args.root);
|
|
2225
|
+
const identity = repoIdentityToString(repoIdentity);
|
|
2226
|
+
const slugs = args.slugs ?? await listCachedSlugs(io.env, projectId);
|
|
2227
|
+
if (slugs.length === 0) {
|
|
2228
|
+
let legacyFiles = [];
|
|
2229
|
+
try {
|
|
2230
|
+
legacyFiles = await readdir3(path13.join(args.root, ".nolto", "roadmaps"));
|
|
2231
|
+
} catch (err) {
|
|
2232
|
+
if (err.code !== "ENOENT") throw err;
|
|
2334
2233
|
}
|
|
2335
|
-
|
|
2234
|
+
if (legacyFiles.some((file) => file.endsWith(".json"))) {
|
|
2235
|
+
throw new CliError("Roadmaps are still in .nolto/roadmaps. Run `nolto roadmap migrate`.", 2);
|
|
2236
|
+
}
|
|
2237
|
+
throw new CliError("No cached roadmap for this project. Run `nolto pull` or `nolto init`.", 2);
|
|
2336
2238
|
}
|
|
2337
|
-
const
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
projectId: binding?.projectId ?? null,
|
|
2345
|
-
projectBindingPath,
|
|
2346
|
-
source: deps.settings.source.project === "repo" ? "repo" : "file",
|
|
2347
|
-
repoIdentity
|
|
2348
|
-
}, mode2);
|
|
2349
|
-
} else {
|
|
2350
|
-
if (binding == null) {
|
|
2351
|
-
process.stdout.write(`Binding file found at ${projectBindingPath} but could not be read.
|
|
2352
|
-
`);
|
|
2353
|
-
} else {
|
|
2354
|
-
process.stdout.write(`Binding file : ${projectBindingPath}
|
|
2355
|
-
`);
|
|
2356
|
-
process.stdout.write(`projectId : ${binding.projectId}
|
|
2357
|
-
`);
|
|
2358
|
-
const active = deps.settings.source.project === "repo" ? "repo (active)" : "repo (not active \u2014 overridden)";
|
|
2359
|
-
process.stdout.write(`source : ${active}
|
|
2360
|
-
`);
|
|
2361
|
-
process.stdout.write(`repoIdentity : ${repoIdentity.kind}:${repoIdentity.value}
|
|
2362
|
-
`);
|
|
2239
|
+
const roadmaps = [];
|
|
2240
|
+
for (const slug of slugs) {
|
|
2241
|
+
const entry = await readCache(io.env, projectId, slug);
|
|
2242
|
+
if (!entry) throw new CliError(`No cached roadmap "${slug}". Run \`nolto roadmap pull ${slug}\`.`, 2);
|
|
2243
|
+
if (args.slugs === void 0 && entry.meta?.repoIdentity != null && entry.meta.repoIdentity !== identity) {
|
|
2244
|
+
io.log(`skipped ${slug} (belongs to ${entry.meta.repoIdentity})`);
|
|
2245
|
+
continue;
|
|
2363
2246
|
}
|
|
2247
|
+
roadmaps.push({ slug, ...entry });
|
|
2364
2248
|
}
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
const
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
if (mode2 !== "json") {
|
|
2384
|
-
process.stdout.write(`Project : ${project.name} (${project.id})
|
|
2385
|
-
`);
|
|
2386
|
-
process.stdout.write(`Bound to : ${project.repoIdentity ?? "not bound"}
|
|
2387
|
-
`);
|
|
2388
|
-
process.stdout.write(`Rebind to : ${repoIdentity.kind}:${repoIdentity.value}
|
|
2389
|
-
`);
|
|
2390
|
-
}
|
|
2391
|
-
if (!yes) {
|
|
2392
|
-
if (mode2 === "json") {
|
|
2393
|
-
throw new CliError(
|
|
2394
|
-
"--rebind requires confirmation. Pass --yes to skip the prompt in --json mode.",
|
|
2395
|
-
2
|
|
2249
|
+
if (roadmaps.length === 0) throw new CliError("No cached roadmap belongs to this repository. Run `nolto link --slug <slug>` to create one, or `nolto pull`.", 2);
|
|
2250
|
+
const exec = io.exec;
|
|
2251
|
+
const isIgnored = exec === void 0 ? void 0 : async (root, relPath) => {
|
|
2252
|
+
try {
|
|
2253
|
+
await exec("git", ["check-ignore", "-q", "--", relPath], { cwd: root });
|
|
2254
|
+
return true;
|
|
2255
|
+
} catch {
|
|
2256
|
+
return false;
|
|
2257
|
+
}
|
|
2258
|
+
};
|
|
2259
|
+
const results = [];
|
|
2260
|
+
for (const entry of roadmaps) {
|
|
2261
|
+
const { slug, roadmap, meta } = entry;
|
|
2262
|
+
if (args.onlyDirty && !isDirty(entry)) continue;
|
|
2263
|
+
try {
|
|
2264
|
+
const response = await runSync(
|
|
2265
|
+
{ repoRoot: args.root, projectId, slug, roadmap, repoIdentity, baseRevision: meta?.revision ?? 0 },
|
|
2266
|
+
{ http: io.http, readFile: io.readFile, fileExists: io.fileExists, realpath: io.realpath, ...isIgnored ? { isIgnored } : {}, log: io.log, warn: io.warn }
|
|
2396
2267
|
);
|
|
2268
|
+
await writeCache(io.env, projectId, slug, response.roadmap ?? roadmap, {
|
|
2269
|
+
repoIdentity: identity,
|
|
2270
|
+
revision: response.revision,
|
|
2271
|
+
pulledAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2272
|
+
currentTaskId: response.currentTaskId !== void 0 ? response.currentTaskId : meta?.currentTaskId
|
|
2273
|
+
});
|
|
2274
|
+
results.push(response);
|
|
2275
|
+
entry.roadmap = response.roadmap ?? roadmap;
|
|
2276
|
+
} catch (err) {
|
|
2277
|
+
if (err instanceof CliError && err.status === 409) {
|
|
2278
|
+
if (err.serverError === "task_conflict") {
|
|
2279
|
+
const conflicts = err.body?.["conflicts"];
|
|
2280
|
+
if (Array.isArray(conflicts)) {
|
|
2281
|
+
for (const conflict of conflicts) {
|
|
2282
|
+
if (conflict !== null && typeof conflict === "object") {
|
|
2283
|
+
io.warn(` ${conflict.level} ${conflict.id} ${conflict.field}: ours=${JSON.stringify(conflict.ours)} theirs=${JSON.stringify(conflict.theirs)}`);
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
throw new CliError(`Roadmap ${slug} conflicts with the server. Run \`nolto pull\` and resolve, then sync again.`, 4);
|
|
2288
|
+
}
|
|
2289
|
+
if (err.serverError === "base_revision_expired") {
|
|
2290
|
+
throw new CliError(`Roadmap ${slug} is based on an expired revision. Run \`nolto pull\` and reapply your changes.`, 4);
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
throw err;
|
|
2397
2294
|
}
|
|
2398
|
-
|
|
2399
|
-
|
|
2295
|
+
}
|
|
2296
|
+
let gitLinks = null;
|
|
2297
|
+
if (io.exec && io.gitLinks !== false) {
|
|
2400
2298
|
try {
|
|
2401
|
-
const
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2299
|
+
const body = await collectGitLinks(args.root, io.exec);
|
|
2300
|
+
if (body && body.links.length > 0) {
|
|
2301
|
+
gitLinks = { linked: 0, existing: 0, skipped: 0 };
|
|
2302
|
+
for (let offset = 0; offset < body.links.length; offset += 500) {
|
|
2303
|
+
const response = await io.http.post(
|
|
2304
|
+
`/api/projects/${projectId}/git-links`,
|
|
2305
|
+
{ links: body.links.slice(offset, offset + 500), repoIdentity }
|
|
2306
|
+
);
|
|
2307
|
+
if (!Number.isSafeInteger(response.linked) || response.linked < 0 || !Number.isSafeInteger(response.existing) || response.existing < 0 || !Number.isSafeInteger(response.skipped) || response.skipped < 0 || !Array.isArray(response.warnings) || response.warnings.some((warning) => typeof warning !== "string")) throw new Error("Invalid git links response");
|
|
2308
|
+
gitLinks = { linked: gitLinks.linked + response.linked, existing: gitLinks.existing + response.existing, skipped: gitLinks.skipped + response.skipped };
|
|
2309
|
+
for (const warning of response.warnings) io.warn(`git links: ${warning}`);
|
|
2310
|
+
}
|
|
2311
|
+
io.log(`git links: linked ${gitLinks.linked} (existing ${gitLinks.existing}, skipped ${gitLinks.skipped})`);
|
|
2312
|
+
}
|
|
2313
|
+
} catch (error) {
|
|
2314
|
+
gitLinks = null;
|
|
2315
|
+
io.warn(`git links: skipped \u2014 ${error instanceof Error ? error.message : String(error)}`);
|
|
2405
2316
|
}
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2317
|
+
}
|
|
2318
|
+
return { results, planAbsPaths: collectContainedPlanAbsPaths(roadmaps.map((entry) => entry.roadmap), args.root, io.warn), gitLinks };
|
|
2319
|
+
}
|
|
2320
|
+
|
|
2321
|
+
// src/commands/sync.ts
|
|
2322
|
+
function register3(program, deps) {
|
|
2323
|
+
program.command("sync").description("Push cached roadmaps and linked plan documents to Nolto (baseRevision-aware)").option("--no-git-links", "Skip commit / PR issue links").action(async (opts) => {
|
|
2324
|
+
await runSyncCommand(deps, opts);
|
|
2325
|
+
});
|
|
2326
|
+
}
|
|
2327
|
+
async function runSyncCommand(deps, opts = {}) {
|
|
2328
|
+
const { root, projectId } = await resolveRoadmapReadContext(deps);
|
|
2329
|
+
const http = deps.http;
|
|
2330
|
+
const warn2 = (line2) => {
|
|
2331
|
+
process.stderr.write((line2.startsWith(" ") ? "" : "Warning: ") + line2 + "\n");
|
|
2332
|
+
};
|
|
2333
|
+
const response = await syncRepo(
|
|
2334
|
+
{ root, projectId, slugs: opts.slug === void 0 ? void 0 : [opts.slug] },
|
|
2335
|
+
{
|
|
2336
|
+
env: process.env,
|
|
2337
|
+
readFile: (p) => readFile8(p, "utf8"),
|
|
2338
|
+
realpath: (p) => realpath2(p),
|
|
2339
|
+
fileExists: (p) => existsSync4(p),
|
|
2340
|
+
repoIdentity: makeRepoIdentityResolver(deps),
|
|
2341
|
+
exec: promisify(execFile2),
|
|
2342
|
+
gitLinks: (opts.gitLinks ?? true) && process.env.NOLTO_GIT_LINKS !== "0",
|
|
2343
|
+
http,
|
|
2344
|
+
log: (line2) => {
|
|
2345
|
+
if (!opts.quiet && deps.output.mode !== "json") process.stdout.write(line2 + "\n");
|
|
2346
|
+
},
|
|
2347
|
+
warn: warn2
|
|
2409
2348
|
}
|
|
2349
|
+
);
|
|
2350
|
+
try {
|
|
2351
|
+
const drifted = await checkSkillDrift(root, { homeSkillDirs: deps.homeSkillDirs });
|
|
2352
|
+
for (const warning of drifted) warn2(warning);
|
|
2353
|
+
} catch {
|
|
2410
2354
|
}
|
|
2411
|
-
|
|
2412
|
-
if (
|
|
2413
|
-
|
|
2355
|
+
let registryAdded = false;
|
|
2356
|
+
if (isHomeDirectory(root)) {
|
|
2357
|
+
process.stderr.write(`Warning: refusing to add home directory ${root} to the watch registry.
|
|
2358
|
+
`);
|
|
2414
2359
|
} else {
|
|
2415
|
-
|
|
2360
|
+
try {
|
|
2361
|
+
registryAdded = (await addRepoToRegistry(getRegistryPath(process.env), { root, projectId })).added;
|
|
2362
|
+
if (registryAdded) {
|
|
2363
|
+
const warning = await staleWatchWarning(process.env, deps.version, process.kill);
|
|
2364
|
+
if (warning) process.stderr.write(warning + "\n");
|
|
2365
|
+
}
|
|
2366
|
+
} catch (err) {
|
|
2367
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
2368
|
+
process.stderr.write(`Warning: could not update watch registry: ${message}
|
|
2416
2369
|
`);
|
|
2417
|
-
}
|
|
2418
|
-
}
|
|
2419
|
-
async function handleUnlink(projectBindingPath, mode2) {
|
|
2420
|
-
const { readFile: readFile19, writeFile: writeFile12, chmod: chmod2 } = await import("fs/promises");
|
|
2421
|
-
let existing = {};
|
|
2422
|
-
try {
|
|
2423
|
-
const raw = await readFile19(projectBindingPath, "utf8");
|
|
2424
|
-
const parsed = JSON.parse(raw);
|
|
2425
|
-
if (parsed == null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
2426
|
-
throw new CliError(
|
|
2427
|
-
`Cannot unlink ${projectBindingPath}: file contains valid JSON but is not a plain object (got ${Array.isArray(parsed) ? "array" : String(parsed)}). Remove or fix the file manually.`,
|
|
2428
|
-
2
|
|
2429
|
-
);
|
|
2430
2370
|
}
|
|
2431
|
-
existing = parsed;
|
|
2432
|
-
} catch (err) {
|
|
2433
|
-
if (err instanceof CliError) throw err;
|
|
2434
|
-
throw new CliError(`Cannot read ${projectBindingPath}: ${String(err)}`, 2);
|
|
2435
2371
|
}
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
printResult({ unlinked: true, projectBindingPath }, mode2);
|
|
2442
|
-
} else {
|
|
2443
|
-
process.stdout.write(`Removed projectId from ${projectBindingPath}.
|
|
2372
|
+
if (!opts.quiet && deps.output.mode === "json") {
|
|
2373
|
+
const { planAbsPaths: _planAbsPaths, ...publicResponse } = response;
|
|
2374
|
+
printResult({ ...publicResponse, registryAdded }, "json");
|
|
2375
|
+
} else if (!opts.quiet && registryAdded) {
|
|
2376
|
+
process.stdout.write(`watch registry: added ${root}
|
|
2444
2377
|
`);
|
|
2445
2378
|
}
|
|
2379
|
+
return response;
|
|
2446
2380
|
}
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
}
|
|
2454
|
-
|
|
2455
|
-
const { root, foundGit } = findRepoRoot(startDir);
|
|
2456
|
-
if (!foundGit) {
|
|
2457
|
-
process.stderr.write(
|
|
2458
|
-
`Warning: no .git directory found above ${startDir}. Writing nolto.json to current directory.
|
|
2459
|
-
`
|
|
2460
|
-
);
|
|
2381
|
+
|
|
2382
|
+
// src/roadmap-commands.ts
|
|
2383
|
+
var warn = (line2) => {
|
|
2384
|
+
process.stderr.write(line2 + "\n");
|
|
2385
|
+
};
|
|
2386
|
+
async function pull(deps, projectId, slug) {
|
|
2387
|
+
if (!await pullRoadmapCache({ env: process.env, http: deps.http, projectId, slug, log: () => void 0, warn })) {
|
|
2388
|
+
throw new CliError("Cache has unsynced structural changes; run nolto roadmap sync first.", 4);
|
|
2461
2389
|
}
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
"/api/projects"
|
|
2472
|
-
);
|
|
2473
|
-
const projects = Array.isArray(result.projects) ? result.projects : [];
|
|
2474
|
-
projectName = projects.find((p) => p.id === projectId)?.name ?? projectName;
|
|
2475
|
-
if (!projects.some((p) => p.id === projectId)) {
|
|
2476
|
-
process.stderr.write(
|
|
2477
|
-
`Warning: project ${projectId} was not found in GET /api/projects.
|
|
2478
|
-
Proceeding anyway \u2014 verify the ID is correct.
|
|
2479
|
-
`
|
|
2480
|
-
);
|
|
2481
|
-
}
|
|
2482
|
-
} catch {
|
|
2483
|
-
process.stderr.write(
|
|
2484
|
-
"Warning: could not verify project membership (offline or token issue). Proceeding anyway.\n"
|
|
2485
|
-
);
|
|
2390
|
+
}
|
|
2391
|
+
async function selectRoadmap(deps, requestedSlug) {
|
|
2392
|
+
const context3 = await resolveRoadmapReadContext(deps);
|
|
2393
|
+
let slug = requestedSlug;
|
|
2394
|
+
if (slug === void 0) {
|
|
2395
|
+
let slugs = await listCachedSlugs(process.env, context3.projectId);
|
|
2396
|
+
if (slugs.length === 0) {
|
|
2397
|
+
await runPull(deps, { quiet: true });
|
|
2398
|
+
slugs = await listCachedSlugs(process.env, context3.projectId);
|
|
2486
2399
|
}
|
|
2400
|
+
if (slugs.length !== 1) {
|
|
2401
|
+
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);
|
|
2402
|
+
}
|
|
2403
|
+
slug = slugs[0];
|
|
2487
2404
|
}
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2405
|
+
const paths = cachePaths(process.env, context3.projectId, slug);
|
|
2406
|
+
if (!existsSync5(paths.json)) await pull(deps, context3.projectId, slug);
|
|
2407
|
+
return { ...context3, slug, paths };
|
|
2408
|
+
}
|
|
2409
|
+
async function roadmapPath(deps, slug) {
|
|
2410
|
+
const { paths } = await selectRoadmap(deps, slug);
|
|
2411
|
+
printResult(path14.resolve(paths.json), deps.output.mode);
|
|
2412
|
+
}
|
|
2413
|
+
async function roadmapStatus(deps, slug, fresh = false) {
|
|
2414
|
+
const selected = await selectRoadmap(deps, slug);
|
|
2415
|
+
if (fresh) await pull(deps, selected.projectId, selected.slug);
|
|
2416
|
+
const entry = await readCache(process.env, selected.projectId, selected.slug);
|
|
2417
|
+
const { roadmap, meta } = entry;
|
|
2418
|
+
const stats = deriveTaskStats(roadmap);
|
|
2419
|
+
const tasks = roadmap.phases.flatMap((phase) => phase.tasks);
|
|
2420
|
+
const current = tasks.find((task) => task.id === meta?.currentTaskId && task.status === "in-progress");
|
|
2421
|
+
const blocked = tasks.filter((task) => task.status === "blocked");
|
|
2422
|
+
const age = meta ? (Date.now() - Date.parse(meta.pulledAt)) / 6e4 : NaN;
|
|
2423
|
+
if (age > 10) warn(`Warning: cache is ${Math.floor(age)} minutes old; run with --fresh or nolto roadmap pull`);
|
|
2424
|
+
if (deps.output.mode === "json") {
|
|
2425
|
+
printResult({ roadmap, stats, currentTaskId: current?.id ?? null, revision: meta?.revision ?? 0, pulledAt: meta?.pulledAt ?? null }, "json");
|
|
2426
|
+
return;
|
|
2493
2427
|
}
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
try {
|
|
2510
|
-
const answer = (await rl.question(question)).trim().toLowerCase();
|
|
2511
|
-
return answer === "" || answer === "y" || answer === "yes";
|
|
2512
|
-
} finally {
|
|
2513
|
-
rl.close();
|
|
2514
|
-
}
|
|
2515
|
-
},
|
|
2516
|
-
log: (line2) => {
|
|
2517
|
-
if (mode2 !== "json") process.stdout.write(line2 + "\n");
|
|
2518
|
-
}
|
|
2519
|
-
});
|
|
2520
|
-
if (result === "declined") {
|
|
2521
|
-
process.stdout.write("Skipped adding this repository. Run `nolto link --add` later; roadmap sync will fail until then.\n");
|
|
2522
|
-
return;
|
|
2523
|
-
}
|
|
2524
|
-
repoAdded = result === "added";
|
|
2525
|
-
await ensureRoadmapCache({
|
|
2526
|
-
env: process.env,
|
|
2527
|
-
http,
|
|
2528
|
-
projectId,
|
|
2529
|
-
projectName,
|
|
2530
|
-
repoRoot: root,
|
|
2531
|
-
slug,
|
|
2532
|
-
repoIdentity,
|
|
2533
|
-
log: (line2) => {
|
|
2534
|
-
if (mode2 !== "json") process.stdout.write(line2 + "\n");
|
|
2535
|
-
}
|
|
2536
|
-
});
|
|
2428
|
+
printResult([
|
|
2429
|
+
`${roadmap.project.name}: ${stats.done}/${stats.total} done (${stats.progressPct}%)`,
|
|
2430
|
+
`Current: ${current ? `${current.id} \u2014 ${current.title}` : "none"}`,
|
|
2431
|
+
`Blocked: ${blocked.map((task) => `${task.id} \u2014 ${task.title}`).join(", ") || "none"}`,
|
|
2432
|
+
`Summary: ${roadmap.summary}`,
|
|
2433
|
+
`Revision: ${meta?.revision ?? 0} (pulled ${meta?.pulledAt ?? "unknown"})`
|
|
2434
|
+
].join("\n"), "human");
|
|
2435
|
+
}
|
|
2436
|
+
async function roadmapValidate(deps, slug) {
|
|
2437
|
+
const { paths } = await selectRoadmap(deps, slug);
|
|
2438
|
+
let parsed;
|
|
2439
|
+
try {
|
|
2440
|
+
parsed = JSON.parse(await readFile9(paths.json, "utf8"));
|
|
2441
|
+
} catch {
|
|
2442
|
+
throw new CliError(`ERROR Malformed JSON in ${paths.json}.`, 1);
|
|
2537
2443
|
}
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
`);
|
|
2542
|
-
|
|
2444
|
+
const result = validateRoadmap(parsed);
|
|
2445
|
+
for (const warning of result.warnings) warn(`WARN ${warning}`);
|
|
2446
|
+
if (result.errors.length) {
|
|
2447
|
+
for (const error of result.errors) warn(`ERROR ${error}`);
|
|
2448
|
+
throw new CliError(`Roadmap validation failed: ${paths.json}`, 1);
|
|
2449
|
+
}
|
|
2450
|
+
printResult(deps.output.mode === "json" ? { path: paths.json, ...result } : `OK ${paths.json}`, deps.output.mode);
|
|
2451
|
+
}
|
|
2452
|
+
async function roadmapSummary(deps, slug, text) {
|
|
2453
|
+
const selected = await selectRoadmap(deps, slug);
|
|
2454
|
+
const entry = await readCache(process.env, selected.projectId, selected.slug);
|
|
2455
|
+
entry.roadmap.summary = text;
|
|
2456
|
+
const temp = `${selected.paths.json}.tmp-${randomUUID5()}`;
|
|
2457
|
+
try {
|
|
2458
|
+
await writeFile7(temp, serializeRoadmap(entry.roadmap), { mode: 384 });
|
|
2459
|
+
await rename3(temp, selected.paths.json);
|
|
2460
|
+
} finally {
|
|
2461
|
+
await unlink3(temp).catch(() => void 0);
|
|
2462
|
+
}
|
|
2463
|
+
await runSyncCommand(deps, { slug: selected.slug });
|
|
2464
|
+
}
|
|
2465
|
+
async function roadmapAddIssue(deps, slug, taskId, key) {
|
|
2466
|
+
const selected = await selectRoadmap(deps, slug);
|
|
2467
|
+
const entry = await readCache(process.env, selected.projectId, selected.slug);
|
|
2468
|
+
const result = addIssueToRoadmapTask(entry.roadmap, taskId, key);
|
|
2469
|
+
if ("error" in result) throw new CliError(`${result.error} in ${selected.paths.json}`, 2);
|
|
2470
|
+
if (result.changed) {
|
|
2471
|
+
const temp = `${selected.paths.json}.tmp-${randomUUID5()}`;
|
|
2543
2472
|
try {
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
}
|
|
2549
|
-
} catch (err) {
|
|
2550
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
2551
|
-
process.stderr.write(`Warning: could not update watch registry: ${message}
|
|
2552
|
-
`);
|
|
2473
|
+
await writeFile7(temp, serializeRoadmap(result.roadmap), { mode: 384 });
|
|
2474
|
+
await rename3(temp, selected.paths.json);
|
|
2475
|
+
} finally {
|
|
2476
|
+
await unlink3(temp).catch(() => void 0);
|
|
2553
2477
|
}
|
|
2478
|
+
await runSyncCommand(deps, { slug: selected.slug, quiet: true });
|
|
2554
2479
|
}
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2480
|
+
return { file: selected.paths.json, taskId };
|
|
2481
|
+
}
|
|
2482
|
+
async function patchTask(args) {
|
|
2483
|
+
const { env, projectId, slug, taskId } = args;
|
|
2484
|
+
const entry = await readCache(env, projectId, slug);
|
|
2485
|
+
if (entry && isDirty(entry)) throw new CliError("Cache has unsynced structural changes; run nolto roadmap sync first.", 4);
|
|
2486
|
+
let response;
|
|
2487
|
+
try {
|
|
2488
|
+
response = await args.http.patch(`/api/projects/${projectId}/roadmaps/${encodeURIComponent(slug)}/tasks/${encodeURIComponent(taskId)}`, args.body);
|
|
2489
|
+
} catch (error) {
|
|
2490
|
+
if (error instanceof CliError && error.status === 404) throw new CliError(`Task ${taskId} not found in ${slug}.`, 2);
|
|
2491
|
+
throw error;
|
|
2492
|
+
}
|
|
2493
|
+
const { errors } = validateRoadmap(response.roadmap);
|
|
2494
|
+
if (errors.length) throw new CliError(`Server roadmap "${slug}" failed validation: ${errors.join("; ")}`, 5);
|
|
2495
|
+
await writeCache(env, projectId, slug, response.roadmap, {
|
|
2496
|
+
repoIdentity: entry?.meta?.repoIdentity ?? null,
|
|
2497
|
+
revision: response.revision,
|
|
2498
|
+
pulledAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2499
|
+
currentTaskId: response.currentTaskId
|
|
2500
|
+
});
|
|
2501
|
+
return response;
|
|
2502
|
+
}
|
|
2503
|
+
async function roadmapTask(deps, taskId, slug, body) {
|
|
2504
|
+
const selected = await selectRoadmap(deps, slug);
|
|
2505
|
+
if (body.status === "blocked" && !body.note?.trim()) throw new CliError("block requires a non-empty --note.", 2);
|
|
2506
|
+
if (body.plan !== void 0) {
|
|
2507
|
+
const absolute = path14.resolve(selected.root, body.plan);
|
|
2508
|
+
if (!isValidPlanPath(body.plan) || !absolute.startsWith(path14.resolve(selected.root) + path14.sep)) {
|
|
2509
|
+
throw new CliError("plan must be a repository-relative path without . or .. segments.", 2);
|
|
2572
2510
|
}
|
|
2511
|
+
if (!existsSync5(absolute)) warn(`WARN plan file not found at ${absolute}`);
|
|
2573
2512
|
}
|
|
2513
|
+
const response = await patchTask({ ...selected, env: process.env, http: deps.http, taskId, body });
|
|
2514
|
+
if (body.plan !== void 0) await runSyncCommand(deps, { slug: selected.slug, quiet: true });
|
|
2515
|
+
printResult(deps.output.mode === "json" ? response : body.plan !== void 0 ? `${taskId} plan -> ${body.plan}` : `${taskId} -> ${body.status}`, deps.output.mode);
|
|
2574
2516
|
}
|
|
2575
|
-
function
|
|
2576
|
-
const
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2517
|
+
async function roadmapEvents(deps, slug, opts) {
|
|
2518
|
+
const selected = await selectRoadmap(deps, slug);
|
|
2519
|
+
const query = new URLSearchParams();
|
|
2520
|
+
if (opts.since !== void 0) query.set("since", opts.since);
|
|
2521
|
+
if (opts.limit !== void 0) query.set("limit", opts.limit);
|
|
2522
|
+
const response = await deps.http.get(`/api/projects/${selected.projectId}/roadmaps/${encodeURIComponent(selected.slug)}/events${query.size ? `?${query}` : ""}`);
|
|
2523
|
+
if (deps.output.mode === "json") printResult(response, "json");
|
|
2524
|
+
else for (const event of response.events) {
|
|
2525
|
+
printResult(`rev ${event.revision} ${event.createdAt} ${event.actor?.name ?? "system"} ${event.source} ${event.taskId} ${event.field}: ${event.from ?? "\u2014"} \u2192 ${event.to ?? "\u2014"}`, "human");
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
async function roadmapMigrate(deps, yes = false) {
|
|
2529
|
+
const { root, projectId } = await resolveRoadmapReadContext(deps);
|
|
2530
|
+
const dir = path14.join(root, ".nolto", "roadmaps");
|
|
2531
|
+
let files;
|
|
2532
|
+
try {
|
|
2533
|
+
files = (await readdir4(dir, { withFileTypes: true })).filter((file) => file.isFile() && file.name.endsWith(".json")).map((file) => file.name).sort();
|
|
2534
|
+
} catch (error) {
|
|
2535
|
+
if (error.code !== "ENOENT") throw error;
|
|
2536
|
+
files = [];
|
|
2537
|
+
}
|
|
2538
|
+
if (!files.length) {
|
|
2539
|
+
printResult("Nothing to migrate.", deps.output.mode);
|
|
2540
|
+
return;
|
|
2541
|
+
}
|
|
2542
|
+
const local = [];
|
|
2543
|
+
for (const file of files) {
|
|
2544
|
+
const slug = file.slice(0, -5);
|
|
2545
|
+
cachePaths(process.env, projectId, slug);
|
|
2546
|
+
const roadmap = await loadValidRoadmap(path14.join(dir, file), (p) => readFile9(p, "utf8"));
|
|
2547
|
+
roadmap.schemaVersion = 3;
|
|
2548
|
+
delete roadmap.updatedAt;
|
|
2549
|
+
delete roadmap.currentTaskId;
|
|
2550
|
+
local.push({ slug, roadmap });
|
|
2551
|
+
}
|
|
2552
|
+
const list = await deps.http.get(`/api/projects/${projectId}/roadmaps`);
|
|
2553
|
+
const results = [];
|
|
2554
|
+
for (const { slug, roadmap } of local) {
|
|
2555
|
+
let server;
|
|
2556
|
+
if (list.roadmaps.some((item) => item.slug === slug)) server = await deps.http.get(`/api/projects/${projectId}/roadmaps/${encodeURIComponent(slug)}`);
|
|
2557
|
+
const unchanged = server !== void 0 && serializeRoadmap(roadmap) === serializeRoadmap(server.roadmap);
|
|
2558
|
+
if (server && !unchanged && !yes) {
|
|
2559
|
+
if (!process.stdin.isTTY) throw new CliError(`Replacing ${slug} at server rev ${server.revision} requires confirmation; rerun with --yes.`, 2);
|
|
2560
|
+
const rl = readline2.createInterface({ input: process.stdin, output: process.stderr });
|
|
2561
|
+
try {
|
|
2562
|
+
const answer = await rl.question(`Replace ${slug} on the server at rev ${server.revision} with the local file? [y/N] `);
|
|
2563
|
+
if (!/^y(es)?$/i.test(answer.trim())) throw new CliError(`Migration of ${slug} cancelled.`, 2);
|
|
2564
|
+
} finally {
|
|
2565
|
+
rl.close();
|
|
2587
2566
|
}
|
|
2588
|
-
await handleShow(deps, projectBindingPath, mode2);
|
|
2589
|
-
return;
|
|
2590
2567
|
}
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2568
|
+
const repoIdentity = (await readCache(process.env, projectId, slug))?.meta?.repoIdentity ?? null;
|
|
2569
|
+
let revision = server?.revision ?? 0;
|
|
2570
|
+
let saved = unchanged ? server.roadmap : roadmap;
|
|
2571
|
+
let currentTaskId = server?.currentTaskId;
|
|
2572
|
+
if (unchanged || !server) {
|
|
2573
|
+
await writeCache(process.env, projectId, slug, saved, { repoIdentity, revision, pulledAt: (/* @__PURE__ */ new Date()).toISOString(), currentTaskId });
|
|
2574
|
+
}
|
|
2575
|
+
if (!unchanged) {
|
|
2576
|
+
const response = await runSync({ repoRoot: root, projectId, slug, roadmap, baseRevision: revision, repoIdentity: await makeRepoIdentityResolver(deps)(root) }, {
|
|
2577
|
+
http: deps.http,
|
|
2578
|
+
readFile: (p) => readFile9(p, "utf8"),
|
|
2579
|
+
realpath: realpath3,
|
|
2580
|
+
fileExists: existsSync5,
|
|
2581
|
+
log: () => void 0,
|
|
2582
|
+
warn
|
|
2583
|
+
});
|
|
2584
|
+
revision = response.revision;
|
|
2585
|
+
saved = response.roadmap ?? roadmap;
|
|
2586
|
+
if (response.currentTaskId !== void 0) currentTaskId = response.currentTaskId;
|
|
2587
|
+
await writeCache(process.env, projectId, slug, saved, { repoIdentity, revision, pulledAt: (/* @__PURE__ */ new Date()).toISOString(), currentTaskId });
|
|
2588
|
+
}
|
|
2589
|
+
const action = unchanged ? "unchanged" : server ? "replaced" : "created";
|
|
2590
|
+
results.push({ slug, action, revision });
|
|
2591
|
+
if (deps.output.mode !== "json") printResult(`${action} ${slug} (rev ${revision})`, "human");
|
|
2592
|
+
}
|
|
2593
|
+
const nextSteps = ["Next steps (run yourself):", " git rm -r .nolto/roadmaps"];
|
|
2594
|
+
let attributes = "";
|
|
2595
|
+
try {
|
|
2596
|
+
attributes = await readFile9(path14.join(root, ".gitattributes"), "utf8");
|
|
2597
|
+
} catch (error) {
|
|
2598
|
+
if (error.code !== "ENOENT") throw error;
|
|
2599
|
+
}
|
|
2600
|
+
if (attributes.split(/\r?\n/).some((line2) => /^\s*\.nolto\/roadmaps\/\*\.json\s+.*\bmerge=nolto-roadmap(?:\s|$)/.test(line2))) {
|
|
2601
|
+
nextSteps.push(' # remove the ".nolto/roadmaps/*.json merge=nolto-roadmap" line from .gitattributes');
|
|
2602
|
+
}
|
|
2603
|
+
nextSteps.push(" git config --unset-all merge.nolto-roadmap.name; git config --unset-all merge.nolto-roadmap.driver");
|
|
2604
|
+
const { added } = await addRepoToRegistry(getRegistryPath(process.env), { root, projectId });
|
|
2605
|
+
if (added) {
|
|
2606
|
+
const warning = await staleWatchWarning(process.env, deps.version, process.kill);
|
|
2607
|
+
if (warning) process.stderr.write(warning + "\n");
|
|
2608
|
+
}
|
|
2609
|
+
printResult(deps.output.mode === "json" ? { results, nextSteps } : nextSteps.join("\n"), deps.output.mode);
|
|
2610
|
+
}
|
|
2611
|
+
|
|
2612
|
+
// src/commands/issue.ts
|
|
2613
|
+
var emptySettings = { types: [], statuses: [], categories: [] };
|
|
2614
|
+
function context(deps, command) {
|
|
2615
|
+
if (!deps.settings.token) throw new CliError("Not authenticated. Run `nolto login` or set NOLTO_TOKEN.", 3);
|
|
2616
|
+
const globals = command.optsWithGlobals();
|
|
2617
|
+
const projectId = globals.project ?? deps.settings.defaultProjectId;
|
|
2618
|
+
if (!projectId) throw new CliError("No project. Pass --project <id> or run nolto link.", 2);
|
|
2619
|
+
return {
|
|
2620
|
+
projectId,
|
|
2621
|
+
root: `/api/projects/${encodeURIComponent(projectId)}`,
|
|
2622
|
+
mode: globals.json ? "json" : deps.output.mode
|
|
2623
|
+
};
|
|
2624
|
+
}
|
|
2625
|
+
async function bodyText(body, file) {
|
|
2626
|
+
if (body !== void 0 && file !== void 0) throw new CliError("Use either --body/-m or --body-file, not both.", 2);
|
|
2627
|
+
if (file === void 0) return body;
|
|
2628
|
+
try {
|
|
2629
|
+
if (file !== "-") return await readFile10(file, "utf8");
|
|
2630
|
+
const chunks = [];
|
|
2631
|
+
for await (const chunk of process.stdin) chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
2632
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
2633
|
+
} catch (error) {
|
|
2634
|
+
throw new CliError(`Cannot read body from ${file}: ${String(error)}`, 2);
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2637
|
+
async function writeInput(deps, root, flags, create) {
|
|
2638
|
+
const body = await bodyText(flags.body, flags.bodyFile);
|
|
2639
|
+
const settings = flags.type || flags.status || flags.category ? await deps.http.get(`${root}/issue-settings`) : emptySettings;
|
|
2640
|
+
const typeId = flags.type === void 0 ? void 0 : resolveMaster("type", flags.type, settings).id;
|
|
2641
|
+
const template = create && body === void 0 && typeId !== void 0 ? settings.types.find((type) => type.id === typeId)?.bodyTemplate : void 0;
|
|
2642
|
+
let assigneeId;
|
|
2643
|
+
if (flags.assignee !== void 0) {
|
|
2644
|
+
if (flags.assignee === "none") assigneeId = null;
|
|
2645
|
+
else if (flags.assignee === "me") assigneeId = (await deps.http.get("/api/me/profile")).profile.id;
|
|
2646
|
+
else if (isUuid(flags.assignee)) assigneeId = flags.assignee;
|
|
2647
|
+
else throw new CliError("--assignee must be me, none or a UUID.", 2);
|
|
2648
|
+
}
|
|
2649
|
+
let parentId;
|
|
2650
|
+
if (flags.parent === false) parentId = null;
|
|
2651
|
+
else if (flags.parent !== void 0) parentId = (await deps.http.get(`${root}/issues/${parseIssueRef(flags.parent)}`)).issue.id;
|
|
2652
|
+
if (typeof flags.due === "string" && (!/^\d{4}-\d{2}-\d{2}$/.test(flags.due) || !Number.isFinite(Date.parse(flags.due)) || new Date(flags.due).toISOString().slice(0, 10) !== flags.due)) {
|
|
2653
|
+
throw new CliError("--due must be a valid YYYY-MM-DD date.", 2);
|
|
2654
|
+
}
|
|
2655
|
+
if (flags.priority !== void 0 && !["high", "normal", "low"].includes(flags.priority)) throw new CliError("--priority must be high, normal or low.", 2);
|
|
2656
|
+
const input = {
|
|
2657
|
+
...flags.subject !== void 0 ? { subject: flags.subject } : {},
|
|
2658
|
+
...body !== void 0 ? { body } : template != null ? { body: template } : {},
|
|
2659
|
+
...typeId !== void 0 ? { typeId } : {},
|
|
2660
|
+
...flags.status !== void 0 ? { statusId: resolveMaster("status", flags.status, settings).id } : {},
|
|
2661
|
+
...flags.priority !== void 0 ? { priority: flags.priority } : {},
|
|
2662
|
+
...assigneeId !== void 0 ? { assigneeId } : {},
|
|
2663
|
+
...flags.due !== void 0 ? { dueDate: flags.due === false ? null : flags.due } : {},
|
|
2664
|
+
...flags.category !== void 0 ? { categoryIds: flags.category.map((name) => resolveMaster("category", name, settings).id) } : {},
|
|
2665
|
+
...parentId !== void 0 ? { parentId } : {},
|
|
2666
|
+
...flags.comment !== void 0 ? { comment: flags.comment } : {}
|
|
2667
|
+
};
|
|
2668
|
+
if (Object.keys(input).length === 0) throw new CliError("No changes. Pass a field option or --comment.", 2);
|
|
2669
|
+
return { input, fromTemplate: template != null };
|
|
2670
|
+
}
|
|
2671
|
+
async function attachRoadmap(deps, taskId, slug, key) {
|
|
2672
|
+
try {
|
|
2673
|
+
return await roadmapAddIssue(deps, slug, taskId, key);
|
|
2674
|
+
} catch (error) {
|
|
2675
|
+
throw new CliError(
|
|
2676
|
+
`Issue ${key} was created, but ${error instanceof Error ? error.message : String(error)}`,
|
|
2677
|
+
2,
|
|
2678
|
+
"Do not create it again. Add the existing issue key to the task's issues in the `nolto roadmap path` cache, then run `nolto roadmap sync`."
|
|
2679
|
+
);
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
function writeOptions(command, create) {
|
|
2683
|
+
if (create) command.requiredOption("--subject <text>", "Issue subject");
|
|
2684
|
+
else command.option("--subject <text>", "Issue subject");
|
|
2685
|
+
command.option("--body <text>", "Issue body").option("--body-file <path>", "Read body from file (- for stdin)").option("--type <name-or-id>", "Issue type").option("--status <name-or-id>", "Issue status").option("--priority <priority>", "high, normal or low").option("--assignee <assignee>", "me, none or UUID").option("--due <YYYY-MM-DD>", "Due date").option("--category <names...>", "Category names or UUIDs").option("--parent <ref>", "Parent issue key or number");
|
|
2686
|
+
if (create) command.option("--draft", "Create a draft visible only to you instead of an issue").option("--phase <task-id>", "Attach the created key to a roadmap task (cache) and sync").option("--roadmap <slug>", "Roadmap slug (with --phase; required with multiple cached roadmaps)");
|
|
2687
|
+
else command.option("--no-due", "Clear due date").option("--no-parent", "Clear parent").option("-m, --comment <text>", "Comment in the same update");
|
|
2688
|
+
return command;
|
|
2689
|
+
}
|
|
2690
|
+
function register4(program, deps) {
|
|
2691
|
+
const group = program.command("issue").description("List, view and manage project issues.").addHelpText("after", `
|
|
2692
|
+
All commands accept global \`--project <id>\`, \`--json\`, \`--token <value>\` and \`--base-url <url>\`.
|
|
2693
|
+
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.
|
|
2694
|
+
|
|
2695
|
+
nolto issue create --draft --subject "\u2026"
|
|
2696
|
+
nolto issue drafts
|
|
2697
|
+
nolto issue publish <draft-id>
|
|
2698
|
+
|
|
2699
|
+
| Exit | Meaning |
|
|
2700
|
+
|---|---|
|
|
2701
|
+
| 0 | Success |
|
|
2702
|
+
| 2 | Invalid input, recognized API 404, HTTP 422 (details shown), or roadmap cache/sync failure after creation |
|
|
2703
|
+
| 3 | HTTP 401/403; token_scope/token_project includes a token settings hint |
|
|
2704
|
+
| 4 | HTTP 402/429 (quota/rate limit). API token writes: 60/minute. On 429, wait Retry-After seconds before retrying. |
|
|
2705
|
+
| 5 | Network/generic HTTP errors, including a 404 without an API error string |
|
|
2706
|
+
`);
|
|
2707
|
+
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) => {
|
|
2708
|
+
const ctx = context(deps, command);
|
|
2709
|
+
const settings = flags.status || flags.type || flags.category ? await deps.http.get(`${ctx.root}/issue-settings`) : emptySettings;
|
|
2710
|
+
const query = buildListQuery(flags, settings).toString();
|
|
2711
|
+
const result = await deps.http.get(`${ctx.root}/issues${query ? `?${query}` : ""}`);
|
|
2712
|
+
printResult(ctx.mode === "json" ? result : formatIssueList(result.issues, result), ctx.mode);
|
|
2713
|
+
});
|
|
2714
|
+
group.command("view <ref>").description("Show issue details and comments.").action(async (ref, _flags, command) => {
|
|
2715
|
+
const ctx = context(deps, command);
|
|
2716
|
+
const result = await deps.http.get(`${ctx.root}/issues/${parseIssueRef(ref)}`);
|
|
2717
|
+
printResult(ctx.mode === "json" ? result : formatIssueView(result), ctx.mode);
|
|
2718
|
+
});
|
|
2719
|
+
writeOptions(group.command("create").description("Create an issue."), true).action(async (flags, command) => {
|
|
2720
|
+
const ctx = context(deps, command);
|
|
2721
|
+
if (flags.draft && (flags.phase !== void 0 || flags.roadmap !== void 0)) throw new CliError("--phase and --roadmap cannot be used with --draft. Publish the draft first.", 2);
|
|
2722
|
+
if (flags.roadmap !== void 0 && flags.phase === void 0) throw new CliError("--roadmap requires --phase.", 2);
|
|
2723
|
+
const { input, fromTemplate } = await writeInput(deps, ctx.root, flags, true);
|
|
2724
|
+
if (flags.draft) {
|
|
2725
|
+
const result2 = await deps.http.post(`${ctx.root}/issue-drafts`, input);
|
|
2726
|
+
printResult(ctx.mode === "json" ? result2 : `draft ${result2.draft.id} created
|
|
2727
|
+
${draftUrl(deps.settings.baseUrl, ctx.projectId, result2.draft.id)}`, ctx.mode);
|
|
2728
|
+
return;
|
|
2729
|
+
}
|
|
2730
|
+
const result = await deps.http.post(`${ctx.root}/issues`, input);
|
|
2731
|
+
const roadmap = flags.phase === void 0 ? void 0 : await attachRoadmap(deps, flags.phase, flags.roadmap, result.issue.key);
|
|
2732
|
+
printResult(ctx.mode === "json" ? { ...result, ...roadmap ? { roadmap } : {} } : `${result.issue.key} created
|
|
2733
|
+
${issueUrl(deps.settings.baseUrl, ctx.projectId, result.issue.number)}${fromTemplate ? "\nbody: from template" : ""}`, ctx.mode);
|
|
2734
|
+
});
|
|
2735
|
+
group.command("drafts").description("List your issue drafts (visible only to you).").action(async (_flags, command) => {
|
|
2736
|
+
const ctx = context(deps, command);
|
|
2737
|
+
const result = await deps.http.get(`${ctx.root}/issue-drafts`);
|
|
2738
|
+
printResult(ctx.mode === "json" ? result : formatDraftList(result), ctx.mode);
|
|
2739
|
+
});
|
|
2740
|
+
group.command("publish <draft-id>").description("Publish a draft as an issue.").action(async (id, _flags, command) => {
|
|
2741
|
+
const ctx = context(deps, command);
|
|
2742
|
+
if (!isUuid(id)) throw new CliError("<draft-id> must be a UUID. Run `nolto issue drafts` to list drafts.", 2);
|
|
2743
|
+
const result = await deps.http.post(`${ctx.root}/issue-drafts/${id}/publish`, void 0);
|
|
2744
|
+
printResult(ctx.mode === "json" ? result : `${result.issue.key} published
|
|
2745
|
+
${issueUrl(deps.settings.baseUrl, ctx.projectId, result.issue.number)}`, ctx.mode);
|
|
2746
|
+
});
|
|
2747
|
+
writeOptions(group.command("update <ref>").description("Update issue fields."), false).action(async (ref, flags, command) => {
|
|
2748
|
+
const ctx = context(deps, command);
|
|
2749
|
+
const number = parseIssueRef(ref);
|
|
2750
|
+
const { input } = await writeInput(deps, ctx.root, flags, false);
|
|
2751
|
+
const result = await deps.http.patch(`${ctx.root}/issues/${number}`, input);
|
|
2752
|
+
printResult(ctx.mode === "json" ? result : `${result.issue.key} updated
|
|
2753
|
+
${issueUrl(deps.settings.baseUrl, ctx.projectId, number)}`, ctx.mode);
|
|
2754
|
+
});
|
|
2755
|
+
group.command("comment <ref>").description("Post a comment.").option("-m, --comment <text>", "Comment text").option("--body-file <path>", "Read comment from file (- for stdin)").action(async (ref, flags, command) => {
|
|
2756
|
+
const ctx = context(deps, command);
|
|
2757
|
+
const number = parseIssueRef(ref);
|
|
2758
|
+
const body = await bodyText(flags.comment, flags.bodyFile);
|
|
2759
|
+
if (!body?.trim()) throw new CliError("A comment is required. Use -m or --body-file.", 2);
|
|
2760
|
+
const issue = ctx.mode === "human" ? (await deps.http.get(`${ctx.root}/issues/${number}`)).issue : void 0;
|
|
2761
|
+
const result = await deps.http.post(`${ctx.root}/issues/${number}/comments`, { body });
|
|
2762
|
+
printResult(ctx.mode === "json" ? result : `${issue.key} commented
|
|
2763
|
+
${issueUrl(deps.settings.baseUrl, ctx.projectId, number)}`, ctx.mode);
|
|
2764
|
+
});
|
|
2765
|
+
group.command("close <ref>").description("Move an issue to a closed status.").option("--status <name-or-id>", "Closed status (defaults to first by sort order)").option("-m, --comment <text>", "Comment in the same update").action(async (ref, flags, command) => {
|
|
2766
|
+
const ctx = context(deps, command);
|
|
2767
|
+
const number = parseIssueRef(ref);
|
|
2768
|
+
const settings = await deps.http.get(`${ctx.root}/issue-settings`);
|
|
2769
|
+
const status = pickClosedStatus(settings, flags.status);
|
|
2770
|
+
const result = await deps.http.patch(`${ctx.root}/issues/${number}`, { statusId: status.id, ...flags.comment !== void 0 ? { comment: flags.comment } : {} });
|
|
2771
|
+
printResult(ctx.mode === "json" ? result : `${result.issue.key} closed
|
|
2772
|
+
${issueUrl(deps.settings.baseUrl, ctx.projectId, number)}`, ctx.mode);
|
|
2773
|
+
});
|
|
2774
|
+
}
|
|
2775
|
+
|
|
2776
|
+
// src/memory-import.ts
|
|
2777
|
+
import { readFile as readFile12, readdir as readdir5 } from "fs/promises";
|
|
2778
|
+
import path16 from "path";
|
|
2779
|
+
|
|
2780
|
+
// src/memory-format.ts
|
|
2781
|
+
var oneLine = (value) => value.replace(/[\r\n\u0085\u2028\u2029]/g, " ");
|
|
2782
|
+
var shellArg = (value) => /^[A-Za-z0-9._/-]+$/.test(value) ? value : JSON.stringify(value);
|
|
2783
|
+
var memoryClient = (via) => via?.client || via?.tokenName || "Web";
|
|
2784
|
+
function parseMemory(text, importing = false) {
|
|
2785
|
+
const lines = text.replace(/\r\n/g, "\n").split("\n");
|
|
2786
|
+
if (/^<!--.*-->$/.test(lines[0] ?? "")) lines.shift();
|
|
2787
|
+
if (lines.shift() !== "---") throw new CliError("frontmatter \u306E --- \u304C\u3042\u308A\u307E\u305B\u3093\u3002", 2);
|
|
2788
|
+
const end = lines.indexOf("---");
|
|
2789
|
+
if (end < 0) throw new CliError("frontmatter \u3092 --- \u3067\u9589\u3058\u3066\u304F\u3060\u3055\u3044\u3002", 2);
|
|
2790
|
+
const fields = {};
|
|
2791
|
+
let metadata = false;
|
|
2792
|
+
for (const line2 of lines.slice(0, end)) {
|
|
2793
|
+
const match = /^(\s*)([a-zA-Z]+):\s*(.*)$/.exec(line2);
|
|
2794
|
+
if (!match) continue;
|
|
2795
|
+
const indent = match[1], key = match[2], raw = match[3];
|
|
2796
|
+
if (!indent) metadata = key === "metadata";
|
|
2797
|
+
if (indent && !(importing && metadata && key === "type")) continue;
|
|
2798
|
+
let value = raw.trim();
|
|
2799
|
+
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) value = value.slice(1, -1);
|
|
2800
|
+
if (["name", "description", "type", "scope", "branch", "revision"].includes(key)) fields[key] = value;
|
|
2801
|
+
}
|
|
2802
|
+
const body = lines.slice(end + 1);
|
|
2803
|
+
if (body[0] === "") body.shift();
|
|
2804
|
+
return { ...fields, name: fields.name ?? "", description: fields.description ?? "", body: body.join("\n") };
|
|
2805
|
+
}
|
|
2806
|
+
function formatMemory(entry) {
|
|
2807
|
+
const value = (s) => {
|
|
2808
|
+
const safe = oneLine(s);
|
|
2809
|
+
return /^['"]|['"]$|^\s|\s$/.test(safe) ? `"${safe}"` : safe;
|
|
2810
|
+
};
|
|
2811
|
+
return [
|
|
2812
|
+
"<!-- 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 -->",
|
|
2813
|
+
"---",
|
|
2814
|
+
`name: ${entry.name}`,
|
|
2815
|
+
`description: ${value(entry.description)}`,
|
|
2816
|
+
...entry.type == null ? [] : [`type: ${entry.type}`],
|
|
2817
|
+
`scope: ${entry.scope}`,
|
|
2818
|
+
...entry.scope === "branch" ? [`branch: ${value(entry.branch ?? "")}`] : [],
|
|
2819
|
+
`revision: ${entry.revision}`,
|
|
2820
|
+
`updated: ${oneLine(entry.updatedAt)}${entry.updatedBy?.name ? ` by ${oneLine(entry.updatedBy.name)}` : ""} (${oneLine(memoryClient(entry.updatedVia))})`,
|
|
2821
|
+
"---",
|
|
2822
|
+
"",
|
|
2823
|
+
entry.body
|
|
2824
|
+
].join("\n");
|
|
2825
|
+
}
|
|
2826
|
+
function parseScope(scope, hint = "scope: project|user|branch \u3092 frontmatter \u306B\u66F8\u304F") {
|
|
2827
|
+
if (scope !== "project" && scope !== "user" && scope !== "branch") {
|
|
2828
|
+
throw new CliError(scope ? `scope \u304C\u4E0D\u6B63\u3067\u3059: ${scope}` : "scope \u304C\u5FC5\u8981\u3067\u3059\u3002", 2, hint);
|
|
2829
|
+
}
|
|
2830
|
+
return scope;
|
|
2831
|
+
}
|
|
2832
|
+
var count = (n) => n.toLocaleString("en-US");
|
|
2833
|
+
var invalidInput = (message, hint) => new CliError(message, 2, hint, void 0, "invalid_input");
|
|
2834
|
+
function validateDraft(draft) {
|
|
2835
|
+
if (!/^[a-z0-9][a-z0-9-]{0,63}$/.test(draft.name)) {
|
|
2836
|
+
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");
|
|
2837
|
+
}
|
|
2838
|
+
const description = draft.description.trim();
|
|
2839
|
+
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");
|
|
2840
|
+
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");
|
|
2841
|
+
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");
|
|
2842
|
+
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");
|
|
2843
|
+
if (draft.type && !["user", "feedback", "project", "reference"].includes(draft.type)) {
|
|
2844
|
+
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");
|
|
2845
|
+
}
|
|
2846
|
+
}
|
|
2847
|
+
function parseRevision(value) {
|
|
2848
|
+
const revision = Number(value);
|
|
2849
|
+
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);
|
|
2850
|
+
return revision;
|
|
2851
|
+
}
|
|
2852
|
+
function detectMemoryClient(env) {
|
|
2853
|
+
const agent = env.NOLTO_AGENT?.trim();
|
|
2854
|
+
if (agent && /^[\x20-\x7e]+$/.test(agent)) return agent;
|
|
2855
|
+
if (env.CLAUDECODE === "1") return "Claude Code";
|
|
2856
|
+
if (env.GEMINI_CLI === "1") return "Gemini CLI";
|
|
2857
|
+
if (env.CODEX_THREAD_ID) return "Codex";
|
|
2858
|
+
return "CLI";
|
|
2859
|
+
}
|
|
2860
|
+
|
|
2861
|
+
// src/memory-cache.ts
|
|
2862
|
+
import { mkdir as mkdir7, readFile as readFile11, rename as rename4, rm as rm2, unlink as unlink4, writeFile as writeFile8 } from "fs/promises";
|
|
2863
|
+
import { randomUUID as randomUUID6 } from "crypto";
|
|
2864
|
+
import path15 from "path";
|
|
2865
|
+
function memoryDir(configPath, project) {
|
|
2866
|
+
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);
|
|
2867
|
+
return path15.join(path15.dirname(configPath), "projects", project, "memory");
|
|
2868
|
+
}
|
|
2869
|
+
function memoryEntryPath(entry) {
|
|
2870
|
+
if (!/^[a-z0-9][a-z0-9-]{0,63}$/.test(entry.name)) throw new CliError("Invalid memory name in cache.", 2);
|
|
2871
|
+
if (entry.scope === "project" || entry.scope === "user") return `${entry.scope}/${entry.name}.md`;
|
|
2872
|
+
if (entry.scope !== "branch" || !entry.repoIdentity || !entry.branch) throw new CliError("Invalid memory scope in cache.", 2);
|
|
2873
|
+
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);
|
|
2874
|
+
const repoDir = encodeURIComponent(entry.repoIdentity);
|
|
2875
|
+
if (Buffer.byteLength(repoDir) > 200) throw new CliError("Unsafe memory repo path.", 2);
|
|
2876
|
+
return `branch/${repoDir}/${entry.branch}/${entry.name}.md`;
|
|
2877
|
+
}
|
|
2878
|
+
function storableMemoryEntry(entry) {
|
|
2879
|
+
try {
|
|
2880
|
+
memoryEntryPath(entry);
|
|
2881
|
+
return true;
|
|
2882
|
+
} catch {
|
|
2883
|
+
return false;
|
|
2884
|
+
}
|
|
2885
|
+
}
|
|
2886
|
+
async function atomicMemoryFile(file, content) {
|
|
2887
|
+
await mkdir7(path15.dirname(file), { recursive: true, mode: 448 });
|
|
2888
|
+
const temp = `${file}.tmp-${randomUUID6()}`;
|
|
2889
|
+
try {
|
|
2890
|
+
await writeFile8(temp, content, { mode: 292 });
|
|
2891
|
+
await unlink4(file).catch((error) => {
|
|
2892
|
+
if (error.code !== "ENOENT") throw error;
|
|
2893
|
+
});
|
|
2894
|
+
await rename4(temp, file);
|
|
2895
|
+
} finally {
|
|
2896
|
+
await unlink4(temp).catch(() => void 0);
|
|
2897
|
+
}
|
|
2898
|
+
}
|
|
2899
|
+
async function readMemoryCache(dir, project) {
|
|
2900
|
+
const empty = { state: { entries: [], scope: "", projectName: project.slice(0, 8) }, meta: { cursor: 0, pulledAt: "" } };
|
|
2901
|
+
try {
|
|
2902
|
+
const state = JSON.parse(await readFile11(path15.join(dir, ".entries.json"), "utf8"));
|
|
2903
|
+
if (!Array.isArray(state.entries) || typeof state.scope !== "string" || typeof state.projectName !== "string") throw new Error("Invalid state");
|
|
2904
|
+
if (state.entries.some((e) => e == null || typeof e !== "object" || typeof e.id !== "string" || typeof e.name !== "string")) throw new Error("Invalid entry");
|
|
2905
|
+
let meta = empty.meta;
|
|
2906
|
+
try {
|
|
2907
|
+
meta = JSON.parse(await readFile11(path15.join(dir, ".meta.json"), "utf8"));
|
|
2908
|
+
} catch (error) {
|
|
2909
|
+
if (error.code !== "ENOENT") throw error;
|
|
2910
|
+
}
|
|
2911
|
+
if (!Number.isSafeInteger(meta.cursor) || meta.cursor < 0 || typeof meta.pulledAt !== "string") throw new Error("Invalid cursor");
|
|
2912
|
+
return { state, meta };
|
|
2913
|
+
} catch (error) {
|
|
2914
|
+
if (error.code === "ENOENT") return empty;
|
|
2915
|
+
throw new CliError(`\u30E1\u30E2\u30EA\u30AD\u30E3\u30C3\u30B7\u30E5\u3092\u8AAD\u3081\u307E\u305B\u3093: ${String(error)}`, 2, "nolto memory pull");
|
|
2916
|
+
}
|
|
2917
|
+
}
|
|
2918
|
+
function mergeMemoryEntries(entries, updates) {
|
|
2919
|
+
const byId = new Map(entries.map((entry) => [entry.id, entry]));
|
|
2920
|
+
for (const entry of updates) {
|
|
2921
|
+
const old = byId.get(entry.id);
|
|
2922
|
+
if (!old || old.revision <= entry.revision) byId.set(entry.id, entry);
|
|
2923
|
+
}
|
|
2924
|
+
return [...byId.values()];
|
|
2925
|
+
}
|
|
2926
|
+
async function saveMemoryCache(dir, cache, previous, index, reset = false) {
|
|
2927
|
+
const unsafe = cache.state.entries.filter((e) => !storableMemoryEntry(e));
|
|
2928
|
+
if (reset) await rm2(dir, { recursive: true, force: true });
|
|
2929
|
+
const livePaths = new Set(cache.state.entries.filter((e) => !e.deleted && storableMemoryEntry(e)).map(memoryEntryPath));
|
|
2930
|
+
for (const entry of previous.filter(storableMemoryEntry)) {
|
|
2931
|
+
const relative = memoryEntryPath(entry);
|
|
2932
|
+
if (!livePaths.has(relative)) await rm2(path15.join(dir, relative), { force: true });
|
|
2933
|
+
}
|
|
2934
|
+
for (const entry of cache.state.entries) {
|
|
2935
|
+
if (!entry.deleted && storableMemoryEntry(entry)) await atomicMemoryFile(path15.join(dir, memoryEntryPath(entry)), formatMemory(entry));
|
|
2936
|
+
}
|
|
2937
|
+
await atomicMemoryFile(path15.join(dir, ".entries.json"), JSON.stringify(cache.state) + "\n");
|
|
2938
|
+
await atomicMemoryFile(path15.join(dir, "MEMORY.md"), index);
|
|
2939
|
+
await atomicMemoryFile(path15.join(dir, ".meta.json"), JSON.stringify(cache.meta) + "\n");
|
|
2940
|
+
return unsafe;
|
|
2941
|
+
}
|
|
2942
|
+
function currentMemoryEntries(entries, context3, allBranches = false) {
|
|
2943
|
+
return entries.filter((e) => !e.deleted && storableMemoryEntry(e) && (e.scope !== "branch" || allBranches || context3.branch !== context3.defaultBranch && e.repoIdentity === context3.repoIdentity && e.branch === context3.branch));
|
|
2944
|
+
}
|
|
2945
|
+
var scopeOrder = ["project", "user", "branch"];
|
|
2946
|
+
function sortMemoryEntries(entries) {
|
|
2947
|
+
return entries.sort((a, b) => scopeOrder.indexOf(a.scope) - scopeOrder.indexOf(b.scope) || b.updatedAt.localeCompare(a.updatedAt) || a.name.localeCompare(b.name));
|
|
2948
|
+
}
|
|
2949
|
+
var MEMORY_INDEX_MAX_CHARS = 9500;
|
|
2950
|
+
function memoryIndex(cache, context3, merged = /* @__PURE__ */ new Set(), dir) {
|
|
2951
|
+
const branch = context3.branch && context3.branch !== context3.defaultBranch ? context3.branch : null;
|
|
2952
|
+
const entries = sortMemoryEntries(currentMemoryEntries(cache.state.entries, context3));
|
|
2953
|
+
const groups = ["project", "user", ...branch ? ["branch"] : []];
|
|
2954
|
+
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)}`);
|
|
2955
|
+
let omitted = 0;
|
|
2956
|
+
const build = () => [
|
|
2957
|
+
`# 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)}` : ""})`,
|
|
2958
|
+
"\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",
|
|
2959
|
+
...dir ? [`\u30AD\u30E3\u30C3\u30B7\u30E5: ${dir}`] : [],
|
|
2960
|
+
...groups.flatMap((scope) => {
|
|
2961
|
+
const lines2 = entries.filter((e) => e.scope === scope).map((e) => `- ${e.name} \u2014 ${oneLine(e.description)}`);
|
|
2962
|
+
return lines2.length ? [`## ${scope === "branch" ? `branch ${oneLine(branch)}` : scope}`, ...lines2] : [];
|
|
2963
|
+
}),
|
|
2964
|
+
...mergedLines,
|
|
2965
|
+
...omitted ? [`\u6B8B\u308A ${omitted} \u4EF6: nolto memory list`] : []
|
|
2966
|
+
];
|
|
2967
|
+
let lines = build();
|
|
2968
|
+
while (lines.length > 200 || lines.join("\n").length + 1 > MEMORY_INDEX_MAX_CHARS) {
|
|
2969
|
+
let project = -1;
|
|
2970
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
2971
|
+
if (entries[i].scope === "project") {
|
|
2972
|
+
project = i;
|
|
2973
|
+
break;
|
|
2594
2974
|
}
|
|
2595
|
-
await handleUnlink(projectBindingPath, mode2);
|
|
2596
|
-
return;
|
|
2597
2975
|
}
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
let confirmed = false;
|
|
2632
|
-
try {
|
|
2633
|
-
const answer = await rl.question(`Remove "${repo.identity}" from project ${projectId}? [y/N] `);
|
|
2634
|
-
confirmed = answer.trim().toLowerCase() === "y";
|
|
2635
|
-
} finally {
|
|
2636
|
-
rl.close();
|
|
2637
|
-
}
|
|
2638
|
-
if (!confirmed) {
|
|
2639
|
-
process.stdout.write("Aborted.\n");
|
|
2640
|
-
return;
|
|
2641
|
-
}
|
|
2976
|
+
if (entries.length) {
|
|
2977
|
+
entries.splice(project < 0 ? entries.length - 1 : project, 1);
|
|
2978
|
+
omitted++;
|
|
2979
|
+
} else if (mergedLines.length) {
|
|
2980
|
+
mergedLines.pop();
|
|
2981
|
+
omitted++;
|
|
2982
|
+
} else break;
|
|
2983
|
+
lines = build();
|
|
2984
|
+
}
|
|
2985
|
+
return lines.join("\n") + "\n";
|
|
2986
|
+
}
|
|
2987
|
+
|
|
2988
|
+
// src/memory-git.ts
|
|
2989
|
+
import { execFile as execFile3 } from "child_process";
|
|
2990
|
+
import { promisify as promisify2 } from "util";
|
|
2991
|
+
var runMemoryGit = async (args, root) => (await promisify2(execFile3)("git", args, { cwd: root, timeout: 5e3 })).stdout.trim();
|
|
2992
|
+
async function memoryGitContext(root, deps) {
|
|
2993
|
+
const git = deps.memoryGit ?? runMemoryGit;
|
|
2994
|
+
const result = { repoIdentity: null, branch: null, defaultBranch: null };
|
|
2995
|
+
try {
|
|
2996
|
+
await git(["rev-parse", "--show-toplevel"], root);
|
|
2997
|
+
const identity = await makeRepoIdentityResolver(deps)(root);
|
|
2998
|
+
result.repoIdentity = `${identity.kind}:${identity.value}`;
|
|
2999
|
+
result.branch = await git(["symbolic-ref", "--quiet", "--short", "HEAD"], root).catch(() => null);
|
|
3000
|
+
const remote = await git(["symbolic-ref", "refs/remotes/origin/HEAD"], root).catch(() => "");
|
|
3001
|
+
if (remote.startsWith("refs/remotes/origin/")) result.defaultBranch = remote.slice("refs/remotes/origin/".length);
|
|
3002
|
+
else {
|
|
3003
|
+
for (const branch of ["main", "master"]) {
|
|
3004
|
+
try {
|
|
3005
|
+
await git(["show-ref", "--verify", `refs/heads/${branch}`], root);
|
|
3006
|
+
result.defaultBranch = branch;
|
|
3007
|
+
break;
|
|
3008
|
+
} catch {
|
|
2642
3009
|
}
|
|
2643
|
-
await deps.http.delete(`/api/projects/${projectId}/repos/${repo.id}`);
|
|
2644
|
-
printResult(mode2 === "json" ? { removed: true, projectId, repoId: repo.id } : `Removed ${repo.identity} from project ${projectId}.`, mode2);
|
|
2645
|
-
return;
|
|
2646
3010
|
}
|
|
2647
3011
|
}
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
3012
|
+
} catch {
|
|
3013
|
+
}
|
|
3014
|
+
return result;
|
|
3015
|
+
}
|
|
3016
|
+
async function mergedMemoryBranches(branches, context3, root, git, mine = /* @__PURE__ */ new Set()) {
|
|
3017
|
+
const merged = /* @__PURE__ */ new Set();
|
|
3018
|
+
if (!context3.defaultBranch || !context3.repoIdentity) return merged;
|
|
3019
|
+
const hasRef = async (ref) => {
|
|
3020
|
+
try {
|
|
3021
|
+
await git(["show-ref", "--verify", "--quiet", ref], root);
|
|
3022
|
+
return true;
|
|
3023
|
+
} catch (error) {
|
|
3024
|
+
if (error.code === 1) return false;
|
|
3025
|
+
throw error;
|
|
2658
3026
|
}
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
3027
|
+
};
|
|
3028
|
+
let checkedOut, target, targetTip;
|
|
3029
|
+
try {
|
|
3030
|
+
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)));
|
|
3031
|
+
target = await hasRef(`refs/heads/${context3.defaultBranch}`) ? `refs/heads/${context3.defaultBranch}` : `refs/remotes/origin/${context3.defaultBranch}`;
|
|
3032
|
+
targetTip = await git(["rev-parse", target], root);
|
|
3033
|
+
} catch {
|
|
3034
|
+
return merged;
|
|
3035
|
+
}
|
|
3036
|
+
for (const branch of branches) {
|
|
3037
|
+
if (branch === context3.defaultBranch || branch === context3.branch || checkedOut.has(branch)) continue;
|
|
3038
|
+
try {
|
|
3039
|
+
const local = `refs/heads/${branch}`;
|
|
3040
|
+
if (await hasRef(local)) {
|
|
3041
|
+
if (await git(["rev-parse", local], root) === targetTip) continue;
|
|
3042
|
+
await git(["merge-base", "--is-ancestor", local, target], root);
|
|
3043
|
+
merged.add(branch);
|
|
3044
|
+
} else if (mine.has(branch) && !await hasRef(`refs/remotes/origin/${branch}`)) merged.add(branch);
|
|
3045
|
+
} catch {
|
|
2667
3046
|
}
|
|
2668
|
-
|
|
3047
|
+
}
|
|
3048
|
+
return merged;
|
|
3049
|
+
}
|
|
3050
|
+
|
|
3051
|
+
// src/memory-import.ts
|
|
3052
|
+
function aiHeading(response, requestedName) {
|
|
3053
|
+
const { entry, ai } = response;
|
|
3054
|
+
if (!ai || ai.action !== "merge" && ai.action !== "replace") return null;
|
|
3055
|
+
if (requestedName !== void 0 && requestedName !== entry.name) {
|
|
3056
|
+
return `\u65B0\u898F\u306E ${requestedName} \u306F\u4F5C\u3089\u305A\u3001AI \u304C ${entry.scope}/${entry.name} ${ai.action === "merge" ? "\u306B\u7D71\u5408\u3057\u307E\u3057\u305F" : "\u306E\u77DB\u76FE\u3092\u89E3\u6D88\u3057\u307E\u3057\u305F"} (r${entry.revision}) \u2014 ${oneLine(ai.reason ?? "")}`;
|
|
3057
|
+
}
|
|
3058
|
+
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 ?? "")}`;
|
|
3059
|
+
}
|
|
3060
|
+
async function createMemoryContext(opts, recover = false) {
|
|
3061
|
+
const { projectId: project, root, git } = opts;
|
|
3062
|
+
const dir = memoryDir(opts.configPath, project);
|
|
3063
|
+
const cache = await readMemoryCache(dir, project).catch((error) => {
|
|
3064
|
+
if (!recover) throw error;
|
|
3065
|
+
return { state: { entries: [], scope: "", projectName: project.slice(0, 8) }, meta: { cursor: 0, pulledAt: "" } };
|
|
2669
3066
|
});
|
|
3067
|
+
return { project, dir, root, git, cache, api: `/api/projects/${project}/memory` };
|
|
2670
3068
|
}
|
|
2671
|
-
function
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
);
|
|
3069
|
+
async function memoryIndexText(ctx, deps) {
|
|
3070
|
+
const entries = ctx.cache.state.entries.filter((e) => !e.deleted && e.scope === "branch" && e.repoIdentity === ctx.git.repoIdentity);
|
|
3071
|
+
const branches = [...new Set(entries.map((e) => e.branch))];
|
|
3072
|
+
const userId = ctx.cache.state.userId;
|
|
3073
|
+
const mine = new Set(userId ? entries.filter((e) => e.updatedBy?.id === userId).map((e) => e.branch) : []);
|
|
3074
|
+
return memoryIndex(ctx.cache, ctx.git, await mergedMemoryBranches(branches, ctx.git, ctx.root, deps.memoryGit ?? runMemoryGit, mine), ctx.dir);
|
|
3075
|
+
}
|
|
3076
|
+
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";
|
|
3077
|
+
async function updateCache(ctx, deps, entries, quiet = false) {
|
|
3078
|
+
const previous = ctx.cache.state.entries;
|
|
3079
|
+
try {
|
|
3080
|
+
ctx.cache.state.entries = mergeMemoryEntries(previous, entries);
|
|
3081
|
+
await saveMemoryCache(ctx.dir, ctx.cache, previous, await memoryIndexText(ctx, deps));
|
|
3082
|
+
return true;
|
|
3083
|
+
} catch {
|
|
3084
|
+
if (!quiet) process.stderr.write(cacheWarning);
|
|
3085
|
+
return false;
|
|
3086
|
+
}
|
|
3087
|
+
}
|
|
3088
|
+
function writtenEntries(ctx, response) {
|
|
3089
|
+
const tombstones = (response.affected ?? []).flatMap((a) => {
|
|
3090
|
+
const cached = a.deleted && a.entryId !== response.entry.id ? ctx.cache.state.entries.find((e) => e.id === a.entryId) : void 0;
|
|
3091
|
+
return cached ? [{ ...cached, deleted: true, revision: a.toRevision }] : [];
|
|
3092
|
+
});
|
|
3093
|
+
return [response.entry, ...tombstones];
|
|
3094
|
+
}
|
|
3095
|
+
async function scanMemoryDir(dir) {
|
|
3096
|
+
const ok = [], invalid = [];
|
|
3097
|
+
const seen = /* @__PURE__ */ new Map();
|
|
3098
|
+
for (const file of (await readdir5(dir, { withFileTypes: true })).filter((f) => f.isFile() && f.name.endsWith(".md") && f.name !== "MEMORY.md").sort((a, b) => a.name.localeCompare(b.name))) {
|
|
3099
|
+
let original = file.name.slice(0, -3), name = original;
|
|
3100
|
+
try {
|
|
3101
|
+
const draft = parseMemory(await readFile12(path16.join(dir, file.name), "utf8"), true);
|
|
3102
|
+
original = draft.name || original;
|
|
3103
|
+
name = original.toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/^-+/, "").slice(0, 64);
|
|
3104
|
+
if (!name) throw new CliError(`name \u3092\u6B63\u898F\u5316\u3067\u304D\u307E\u305B\u3093: ${original}`, 2);
|
|
3105
|
+
validateDraft({ ...draft, name });
|
|
3106
|
+
const first = seen.get(name);
|
|
3107
|
+
if (first) throw new CliError(`import \u5185\u3067 name \u304C\u91CD\u8907\u3057\u3066\u3044\u307E\u3059(\u5148: ${first})\u3002`, 2);
|
|
3108
|
+
seen.set(name, file.name);
|
|
3109
|
+
ok.push({ file: file.name, name, original, draft: { ...draft, name } });
|
|
3110
|
+
} catch (error) {
|
|
3111
|
+
invalid.push({ file: file.name, name, original, status: "failed", message: error instanceof Error ? error.message : String(error) });
|
|
3112
|
+
}
|
|
3113
|
+
}
|
|
3114
|
+
return { ok, invalid };
|
|
3115
|
+
}
|
|
3116
|
+
function importResultLine(scope, result) {
|
|
3117
|
+
const { status, name, original, message } = result;
|
|
3118
|
+
return `${status} ${scope}/${name}${original !== name ? ` (\u5143: ${oneLine(original)})` : ""}${message ? ` \u2014 ${oneLine(message)}` : ""}`;
|
|
3119
|
+
}
|
|
3120
|
+
async function importMemoryFiles(opts) {
|
|
3121
|
+
const ctx = await createMemoryContext(opts, true);
|
|
3122
|
+
let imported = 0, skipped = 0, failed = 0, cached = true;
|
|
3123
|
+
const results = [];
|
|
3124
|
+
for (const { file, name, original, draft } of opts.targets) {
|
|
3125
|
+
let status, message, heading = null;
|
|
3126
|
+
try {
|
|
3127
|
+
const response = await opts.http.put(ctx.api, {
|
|
3128
|
+
scope: opts.scope,
|
|
3129
|
+
name,
|
|
3130
|
+
description: draft.description,
|
|
3131
|
+
body: draft.body,
|
|
3132
|
+
...draft.type ? { type: draft.type } : {},
|
|
3133
|
+
allowNew: true,
|
|
3134
|
+
...opts.ai ? {} : { aiSkip: true }
|
|
3135
|
+
}, { "X-Nolto-Client": detectMemoryClient(process.env) });
|
|
3136
|
+
cached = await updateCache(ctx, opts, writtenEntries(ctx, response), true) && cached;
|
|
3137
|
+
heading = aiHeading(response);
|
|
3138
|
+
imported++;
|
|
3139
|
+
status = "imported";
|
|
3140
|
+
} catch (error) {
|
|
3141
|
+
if (error instanceof CliError && error.serverError === "memory_exists") {
|
|
3142
|
+
skipped++;
|
|
3143
|
+
status = "skipped";
|
|
3144
|
+
if (error.body?.entry) cached = await updateCache(ctx, opts, [error.body.entry], true) && cached;
|
|
3145
|
+
} else {
|
|
3146
|
+
failed++;
|
|
3147
|
+
status = "failed";
|
|
3148
|
+
message = error instanceof Error ? error.message : String(error);
|
|
3149
|
+
}
|
|
3150
|
+
}
|
|
3151
|
+
const result = { file, name, original, status, ...message ? { message } : {} };
|
|
3152
|
+
results.push(result);
|
|
3153
|
+
opts.write(heading ? `${heading} (\u5143: ${oneLine(file)})` : importResultLine(opts.scope, result));
|
|
3154
|
+
}
|
|
3155
|
+
return { imported, skipped, failed, results, cached };
|
|
2676
3156
|
}
|
|
2677
3157
|
|
|
2678
3158
|
// src/commands/init.ts
|
|
2679
|
-
|
|
3159
|
+
import { readFile as readFile13 } from "fs/promises";
|
|
3160
|
+
import readline3 from "readline/promises";
|
|
3161
|
+
import { createRequire } from "module";
|
|
3162
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
3163
|
+
import os3 from "os";
|
|
3164
|
+
import path17 from "path";
|
|
3165
|
+
import fs2 from "fs";
|
|
3166
|
+
var __dirname2 = path17.dirname(fileURLToPath2(import.meta.url));
|
|
2680
3167
|
var _require = createRequire(import.meta.url);
|
|
2681
3168
|
function getCliVersion() {
|
|
2682
3169
|
const candidates = [
|
|
2683
|
-
|
|
3170
|
+
path17.resolve(__dirname2, "../package.json"),
|
|
2684
3171
|
// bundled: dist/../package.json
|
|
2685
|
-
|
|
3172
|
+
path17.resolve(__dirname2, "../../package.json")
|
|
2686
3173
|
// source: src/commands/../../package.json
|
|
2687
3174
|
];
|
|
2688
3175
|
for (const pkgPath of candidates) {
|
|
@@ -2831,10 +3318,10 @@ async function setupMemory(opts) {
|
|
|
2831
3318
|
}
|
|
2832
3319
|
}
|
|
2833
3320
|
if (!agents.includes("claude")) return;
|
|
2834
|
-
const file =
|
|
3321
|
+
const file = path17.join(root, ".claude", "settings.local.json");
|
|
2835
3322
|
let settings = {};
|
|
2836
3323
|
try {
|
|
2837
|
-
settings = JSON.parse(await
|
|
3324
|
+
settings = JSON.parse(await readFile13(file, "utf8"));
|
|
2838
3325
|
} catch (error) {
|
|
2839
3326
|
if (error.code !== "ENOENT") {
|
|
2840
3327
|
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
|
|
@@ -2853,10 +3340,10 @@ async function setupMemory(opts) {
|
|
|
2853
3340
|
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"}
|
|
2854
3341
|
`);
|
|
2855
3342
|
}
|
|
2856
|
-
function
|
|
3343
|
+
function register5(program, deps) {
|
|
2857
3344
|
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) => {
|
|
2858
3345
|
const configPath = deps.configPath;
|
|
2859
|
-
const rl =
|
|
3346
|
+
const rl = readline3.createInterface({ input: process.stdin, output: process.stdout });
|
|
2860
3347
|
try {
|
|
2861
3348
|
let configureGlobal = opts.force === true;
|
|
2862
3349
|
if (!configureGlobal) {
|
|
@@ -2946,7 +3433,7 @@ Saved ${configPath}
|
|
|
2946
3433
|
}
|
|
2947
3434
|
if (isHomeDirectory(root)) {
|
|
2948
3435
|
process.stderr.write(
|
|
2949
|
-
`Refusing to set up your home directory as a repository root (found ${
|
|
3436
|
+
`Refusing to set up your home directory as a repository root (found ${path17.join(os3.homedir(), ".git")}). Run nolto init inside a project repository.
|
|
2950
3437
|
`
|
|
2951
3438
|
);
|
|
2952
3439
|
return;
|
|
@@ -2978,7 +3465,7 @@ Saved ${configPath}
|
|
|
2978
3465
|
boundProject != null ? "Keep this binding? [Y/n] " : "Keep this binding? [y/N] "
|
|
2979
3466
|
);
|
|
2980
3467
|
keepExistingBinding = boundProject != null ? keep.trim().toLowerCase() !== "n" : keep.trim().toLowerCase() === "y";
|
|
2981
|
-
repoProject = keepExistingBinding ? boundProject ?? { id: existingBinding.projectId, name:
|
|
3468
|
+
repoProject = keepExistingBinding ? boundProject ?? { id: existingBinding.projectId, name: path17.basename(root) } : await selectRepoProject(rl, repoHttp, projects, defaultProjectId, baseUrl);
|
|
2982
3469
|
} else {
|
|
2983
3470
|
repoProject = await selectRepoProject(rl, repoHttp, projects, defaultProjectId, baseUrl);
|
|
2984
3471
|
}
|
|
@@ -2992,7 +3479,7 @@ Set up this repository (${root}) for roadmap sync? [Y/n] `);
|
|
|
2992
3479
|
process.stdout.write("Skipped repo setup.\n");
|
|
2993
3480
|
return;
|
|
2994
3481
|
}
|
|
2995
|
-
const bindingPath = deps.repoBinding?.path ??
|
|
3482
|
+
const bindingPath = deps.repoBinding?.path ?? path17.join(root, "nolto.json");
|
|
2996
3483
|
if (keepExistingBinding) {
|
|
2997
3484
|
process.stdout.write(`binding: kept ${bindingPath} (${repoProject.id})
|
|
2998
3485
|
`);
|
|
@@ -3004,20 +3491,20 @@ Set up this repository (${root}) for roadmap sync? [Y/n] `);
|
|
|
3004
3491
|
);
|
|
3005
3492
|
}
|
|
3006
3493
|
await writeRepoBinding(root, repoProject.id);
|
|
3007
|
-
process.stdout.write(`binding: wrote ${
|
|
3494
|
+
process.stdout.write(`binding: wrote ${path17.join(root, "nolto.json")}
|
|
3008
3495
|
`);
|
|
3009
3496
|
}
|
|
3010
3497
|
const sourceDir = resolveSkillSourceDir();
|
|
3011
3498
|
const claudeInstall = await installSkill({
|
|
3012
|
-
skillsParentDir:
|
|
3499
|
+
skillsParentDir: path17.join(root, ".claude", "skills"),
|
|
3013
3500
|
sourceDir
|
|
3014
3501
|
});
|
|
3015
3502
|
process.stdout.write(`skill (claude): ${claudeInstall.action} ${claudeInstall.targetDir}
|
|
3016
3503
|
`);
|
|
3017
|
-
const usesAgentsTooling = fs2.existsSync(
|
|
3504
|
+
const usesAgentsTooling = fs2.existsSync(path17.join(root, ".agents")) || fs2.existsSync(path17.join(root, ".codex")) || fs2.existsSync(path17.join(root, "AGENTS.md"));
|
|
3018
3505
|
if (usesAgentsTooling) {
|
|
3019
3506
|
const agentsInstall = await installSkill({
|
|
3020
|
-
skillsParentDir:
|
|
3507
|
+
skillsParentDir: path17.join(root, ".agents", "skills"),
|
|
3021
3508
|
sourceDir
|
|
3022
3509
|
});
|
|
3023
3510
|
process.stdout.write(`skill (agents): ${agentsInstall.action} ${agentsInstall.targetDir}
|
|
@@ -3095,7 +3582,7 @@ async function promptHidden(rl, prompt) {
|
|
|
3095
3582
|
}
|
|
3096
3583
|
|
|
3097
3584
|
// src/commands/login.ts
|
|
3098
|
-
import
|
|
3585
|
+
import readline4 from "readline/promises";
|
|
3099
3586
|
|
|
3100
3587
|
// src/login-poll.ts
|
|
3101
3588
|
async function pollUntilToken(opts) {
|
|
@@ -3150,7 +3637,7 @@ function sleep(ms) {
|
|
|
3150
3637
|
}
|
|
3151
3638
|
|
|
3152
3639
|
// src/commands/login.ts
|
|
3153
|
-
function
|
|
3640
|
+
function register6(program, deps) {
|
|
3154
3641
|
program.command("login").description("Authenticate via browser and save an API token to the config file.").option("--force", "Overwrite existing token without prompting").action(
|
|
3155
3642
|
async (opts) => {
|
|
3156
3643
|
const { configPath, settings, output } = deps;
|
|
@@ -3161,7 +3648,7 @@ function register4(program, deps) {
|
|
|
3161
3648
|
} catch {
|
|
3162
3649
|
}
|
|
3163
3650
|
if (existing?.token) {
|
|
3164
|
-
const rl =
|
|
3651
|
+
const rl = readline4.createInterface({
|
|
3165
3652
|
input: process.stdin,
|
|
3166
3653
|
output: process.stdout
|
|
3167
3654
|
});
|
|
@@ -3232,7 +3719,7 @@ function register4(program, deps) {
|
|
|
3232
3719
|
}
|
|
3233
3720
|
|
|
3234
3721
|
// src/commands/whoami.ts
|
|
3235
|
-
function
|
|
3722
|
+
function register7(program, deps) {
|
|
3236
3723
|
program.command("whoami").description("Show the current authentication and configuration state.").action(async () => {
|
|
3237
3724
|
const { settings, output, configPath } = deps;
|
|
3238
3725
|
const mode2 = output.mode;
|
|
@@ -3274,280 +3761,26 @@ function register5(program, deps) {
|
|
|
3274
3761
|
},
|
|
3275
3762
|
mode2
|
|
3276
3763
|
);
|
|
3277
|
-
} else {
|
|
3278
|
-
const tokenDisplay = settings.token != null ? `${maskToken(settings.token)} (source: ${settings.source.token})` : "(not configured)";
|
|
3279
|
-
const bindingDisplay = settings.source.project === "repo" && projectBindingPath != null ? `${settings.defaultProjectId ?? "none"} (source: repo, binding: ${projectBindingPath})` : `${settings.defaultProjectId ?? "none"} (source: ${settings.source.project})`;
|
|
3280
|
-
const lines = [
|
|
3281
|
-
["baseUrl", `${settings.baseUrl} (source: ${settings.source.baseUrl})`],
|
|
3282
|
-
["configPath", configPath],
|
|
3283
|
-
["token", tokenDisplay],
|
|
3284
|
-
["defaultProject", bindingDisplay],
|
|
3285
|
-
["projects", projectCount != null ? String(projectCount) : settings.token != null ? "(unavailable)" : "(no token)"]
|
|
3286
|
-
];
|
|
3287
|
-
if (tokenInfo) {
|
|
3288
|
-
lines.push(["scopes", tokenInfo.scopes === null ? "full" : tokenInfo.scopes.join(", ")], ["project", tokenInfo.projectId ?? "all"]);
|
|
3289
|
-
}
|
|
3290
|
-
const maxKey = lines.reduce((m, [k]) => Math.max(m, k.length), 0);
|
|
3291
|
-
for (const [key, val] of lines) {
|
|
3292
|
-
process.stdout.write(`${key.padEnd(maxKey)}: ${val}
|
|
3293
|
-
`);
|
|
3294
|
-
}
|
|
3295
|
-
}
|
|
3296
|
-
});
|
|
3297
|
-
}
|
|
3298
|
-
|
|
3299
|
-
// src/commands/sync.ts
|
|
3300
|
-
import { execFile as execFile3 } from "child_process";
|
|
3301
|
-
import { promisify as promisify2 } from "util";
|
|
3302
|
-
import { readFile as readFile12, realpath as realpath2 } from "fs/promises";
|
|
3303
|
-
import { existsSync as existsSync4 } from "fs";
|
|
3304
|
-
|
|
3305
|
-
// src/roadmap-read.ts
|
|
3306
|
-
import path16 from "path";
|
|
3307
|
-
async function resolveRoadmapReadContext(deps) {
|
|
3308
|
-
if (deps.settings.token == null) {
|
|
3309
|
-
throw new CliError("Not authenticated. Run `nolto login` or set NOLTO_TOKEN.", 3);
|
|
3310
|
-
}
|
|
3311
|
-
const startDir = resolveStartDir(process.env, process.cwd());
|
|
3312
|
-
const { root, foundGit } = findRepoRoot(startDir);
|
|
3313
|
-
if (!foundGit) {
|
|
3314
|
-
throw new CliError("No git repository found. Run inside a repo set up with `nolto init`.", 2);
|
|
3315
|
-
}
|
|
3316
|
-
const binding = await loadRepoBinding(path16.join(root, "nolto.json"));
|
|
3317
|
-
const projectId = binding?.projectId ?? deps.settings.defaultProjectId;
|
|
3318
|
-
if (projectId == null) {
|
|
3319
|
-
throw new CliError("No project binding. Run `nolto init` or `nolto link <projectId>`.", 2);
|
|
3320
|
-
}
|
|
3321
|
-
return { root, projectId };
|
|
3322
|
-
}
|
|
3323
|
-
|
|
3324
|
-
// src/git-links.ts
|
|
3325
|
-
function parseGitLog(raw) {
|
|
3326
|
-
return raw.split("\n").filter((line2) => line2.length > 0).map((line2) => {
|
|
3327
|
-
const fields = line2.replace(/\r$/, "").split("");
|
|
3328
|
-
const [ref, subject, author, committedAt] = fields;
|
|
3329
|
-
if (fields.length !== 4 || !ref || !/^[0-9a-f]{40}$/.test(ref) || subject === void 0 || author === void 0 || !committedAt || !Number.isFinite(Date.parse(committedAt))) {
|
|
3330
|
-
throw new Error("Malformed git log entry");
|
|
3331
|
-
}
|
|
3332
|
-
return { ref, subject, author, committedAt: new Date(committedAt).toISOString() };
|
|
3333
|
-
});
|
|
3334
|
-
}
|
|
3335
|
-
function extractIssueKeys(subject) {
|
|
3336
|
-
return [...new Set([...subject.matchAll(/\b([A-Z][A-Z0-9]{1,9})-([1-9][0-9]{0,8})\b/g)].map((match) => match[0]))];
|
|
3337
|
-
}
|
|
3338
|
-
function extractPrNumber(subject) {
|
|
3339
|
-
return /\(#([1-9][0-9]{0,8})\)$/.exec(subject)?.[1] ?? /^Merge pull request #([1-9][0-9]{0,8})\b/.exec(subject)?.[1] ?? null;
|
|
3340
|
-
}
|
|
3341
|
-
function buildGitLinksPayload(entries) {
|
|
3342
|
-
return { links: entries.flatMap((entry) => {
|
|
3343
|
-
const keys = extractIssueKeys(entry.subject);
|
|
3344
|
-
const pr = extractPrNumber(entry.subject);
|
|
3345
|
-
const refs = [{ kind: "commit", ref: entry.ref }, ...pr ? [{ kind: "pr", ref: pr }] : []];
|
|
3346
|
-
return refs.flatMap((ref) => Array.from({ length: Math.ceil(keys.length / 20) }, (_, index) => ({
|
|
3347
|
-
...ref,
|
|
3348
|
-
title: entry.subject.slice(0, 500),
|
|
3349
|
-
author: entry.author.slice(0, 500),
|
|
3350
|
-
committedAt: entry.committedAt,
|
|
3351
|
-
issueKeys: keys.slice(index * 20, (index + 1) * 20)
|
|
3352
|
-
})));
|
|
3353
|
-
}) };
|
|
3354
|
-
}
|
|
3355
|
-
function stdout(result) {
|
|
3356
|
-
if (typeof result === "object" && result !== null && "stdout" in result && typeof result.stdout === "string") return result.stdout;
|
|
3357
|
-
throw new Error("Git command returned no text output");
|
|
3358
|
-
}
|
|
3359
|
-
async function collectGitLinks(root, exec) {
|
|
3360
|
-
let probe;
|
|
3361
|
-
try {
|
|
3362
|
-
probe = await exec("git", ["rev-parse", "--is-inside-work-tree"], { cwd: root });
|
|
3363
|
-
} catch {
|
|
3364
|
-
return null;
|
|
3365
|
-
}
|
|
3366
|
-
if (stdout(probe).trim() !== "true") return null;
|
|
3367
|
-
const result = await exec("git", ["log", "--no-color", "--format=%H%x1f%s%x1f%an%x1f%cI", "-n", "300"], { cwd: root });
|
|
3368
|
-
return buildGitLinksPayload(parseGitLog(stdout(result)));
|
|
3369
|
-
}
|
|
3370
|
-
|
|
3371
|
-
// src/sync-repo.ts
|
|
3372
|
-
import path17 from "path";
|
|
3373
|
-
import { readdir as readdir5 } from "fs/promises";
|
|
3374
|
-
function collectContainedPlanAbsPaths(roadmaps, root, warn2) {
|
|
3375
|
-
const planAbsPaths = /* @__PURE__ */ new Set();
|
|
3376
|
-
const resolvedRoot = path17.resolve(root);
|
|
3377
|
-
for (const roadmap of roadmaps) {
|
|
3378
|
-
for (const ref of collectPlanRefs(roadmap)) {
|
|
3379
|
-
const absolute = path17.resolve(resolvedRoot, ref.path);
|
|
3380
|
-
if (absolute !== resolvedRoot && !absolute.startsWith(resolvedRoot + path17.sep)) {
|
|
3381
|
-
warn2(`chokidar target outside repo, skipping: ${ref.path}`);
|
|
3382
|
-
continue;
|
|
3383
|
-
}
|
|
3384
|
-
if (!isValidPlanPath(ref.path)) {
|
|
3385
|
-
warn2(`plan path not allowed (markdown only, no dot segments), skipping: ${ref.path}`);
|
|
3386
|
-
continue;
|
|
3387
|
-
}
|
|
3388
|
-
planAbsPaths.add(absolute);
|
|
3389
|
-
}
|
|
3390
|
-
}
|
|
3391
|
-
return [...planAbsPaths];
|
|
3392
|
-
}
|
|
3393
|
-
async function syncRepo(args, io) {
|
|
3394
|
-
const { projectId } = args;
|
|
3395
|
-
const repoIdentity = await io.repoIdentity(args.root);
|
|
3396
|
-
const identity = repoIdentityToString(repoIdentity);
|
|
3397
|
-
const slugs = args.slugs ?? await listCachedSlugs(io.env, projectId);
|
|
3398
|
-
if (slugs.length === 0) {
|
|
3399
|
-
let legacyFiles = [];
|
|
3400
|
-
try {
|
|
3401
|
-
legacyFiles = await readdir5(path17.join(args.root, ".nolto", "roadmaps"));
|
|
3402
|
-
} catch (err) {
|
|
3403
|
-
if (err.code !== "ENOENT") throw err;
|
|
3404
|
-
}
|
|
3405
|
-
if (legacyFiles.some((file) => file.endsWith(".json"))) {
|
|
3406
|
-
throw new CliError("Roadmaps are still in .nolto/roadmaps. Run `nolto roadmap migrate`.", 2);
|
|
3407
|
-
}
|
|
3408
|
-
throw new CliError("No cached roadmap for this project. Run `nolto pull` or `nolto init`.", 2);
|
|
3409
|
-
}
|
|
3410
|
-
const roadmaps = [];
|
|
3411
|
-
for (const slug of slugs) {
|
|
3412
|
-
const entry = await readCache(io.env, projectId, slug);
|
|
3413
|
-
if (!entry) throw new CliError(`No cached roadmap "${slug}". Run \`nolto roadmap pull ${slug}\`.`, 2);
|
|
3414
|
-
if (args.slugs === void 0 && entry.meta?.repoIdentity != null && entry.meta.repoIdentity !== identity) {
|
|
3415
|
-
io.log(`skipped ${slug} (belongs to ${entry.meta.repoIdentity})`);
|
|
3416
|
-
continue;
|
|
3417
|
-
}
|
|
3418
|
-
roadmaps.push({ slug, ...entry });
|
|
3419
|
-
}
|
|
3420
|
-
if (roadmaps.length === 0) throw new CliError("No cached roadmap belongs to this repository. Run `nolto link --slug <slug>` to create one, or `nolto pull`.", 2);
|
|
3421
|
-
const exec = io.exec;
|
|
3422
|
-
const isIgnored = exec === void 0 ? void 0 : async (root, relPath) => {
|
|
3423
|
-
try {
|
|
3424
|
-
await exec("git", ["check-ignore", "-q", "--", relPath], { cwd: root });
|
|
3425
|
-
return true;
|
|
3426
|
-
} catch {
|
|
3427
|
-
return false;
|
|
3428
|
-
}
|
|
3429
|
-
};
|
|
3430
|
-
const results = [];
|
|
3431
|
-
for (const entry of roadmaps) {
|
|
3432
|
-
const { slug, roadmap, meta } = entry;
|
|
3433
|
-
if (args.onlyDirty && !isDirty(entry)) continue;
|
|
3434
|
-
try {
|
|
3435
|
-
const response = await runSync(
|
|
3436
|
-
{ repoRoot: args.root, projectId, slug, roadmap, repoIdentity, baseRevision: meta?.revision ?? 0 },
|
|
3437
|
-
{ http: io.http, readFile: io.readFile, fileExists: io.fileExists, realpath: io.realpath, ...isIgnored ? { isIgnored } : {}, log: io.log, warn: io.warn }
|
|
3438
|
-
);
|
|
3439
|
-
await writeCache(io.env, projectId, slug, response.roadmap ?? roadmap, {
|
|
3440
|
-
repoIdentity: identity,
|
|
3441
|
-
revision: response.revision,
|
|
3442
|
-
pulledAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3443
|
-
currentTaskId: response.currentTaskId !== void 0 ? response.currentTaskId : meta?.currentTaskId
|
|
3444
|
-
});
|
|
3445
|
-
results.push(response);
|
|
3446
|
-
entry.roadmap = response.roadmap ?? roadmap;
|
|
3447
|
-
} catch (err) {
|
|
3448
|
-
if (err instanceof CliError && err.status === 409) {
|
|
3449
|
-
if (err.serverError === "task_conflict") {
|
|
3450
|
-
const conflicts = err.body?.["conflicts"];
|
|
3451
|
-
if (Array.isArray(conflicts)) {
|
|
3452
|
-
for (const conflict of conflicts) {
|
|
3453
|
-
if (conflict !== null && typeof conflict === "object") {
|
|
3454
|
-
io.warn(` ${conflict.level} ${conflict.id} ${conflict.field}: ours=${JSON.stringify(conflict.ours)} theirs=${JSON.stringify(conflict.theirs)}`);
|
|
3455
|
-
}
|
|
3456
|
-
}
|
|
3457
|
-
}
|
|
3458
|
-
throw new CliError(`Roadmap ${slug} conflicts with the server. Run \`nolto pull\` and resolve, then sync again.`, 4);
|
|
3459
|
-
}
|
|
3460
|
-
if (err.serverError === "base_revision_expired") {
|
|
3461
|
-
throw new CliError(`Roadmap ${slug} is based on an expired revision. Run \`nolto pull\` and reapply your changes.`, 4);
|
|
3462
|
-
}
|
|
3463
|
-
}
|
|
3464
|
-
throw err;
|
|
3465
|
-
}
|
|
3466
|
-
}
|
|
3467
|
-
let gitLinks = null;
|
|
3468
|
-
if (io.exec && io.gitLinks !== false) {
|
|
3469
|
-
try {
|
|
3470
|
-
const body = await collectGitLinks(args.root, io.exec);
|
|
3471
|
-
if (body && body.links.length > 0) {
|
|
3472
|
-
gitLinks = { linked: 0, existing: 0, skipped: 0 };
|
|
3473
|
-
for (let offset = 0; offset < body.links.length; offset += 500) {
|
|
3474
|
-
const response = await io.http.post(
|
|
3475
|
-
`/api/projects/${projectId}/git-links`,
|
|
3476
|
-
{ links: body.links.slice(offset, offset + 500), repoIdentity }
|
|
3477
|
-
);
|
|
3478
|
-
if (!Number.isSafeInteger(response.linked) || response.linked < 0 || !Number.isSafeInteger(response.existing) || response.existing < 0 || !Number.isSafeInteger(response.skipped) || response.skipped < 0 || !Array.isArray(response.warnings) || response.warnings.some((warning) => typeof warning !== "string")) throw new Error("Invalid git links response");
|
|
3479
|
-
gitLinks = { linked: gitLinks.linked + response.linked, existing: gitLinks.existing + response.existing, skipped: gitLinks.skipped + response.skipped };
|
|
3480
|
-
for (const warning of response.warnings) io.warn(`git links: ${warning}`);
|
|
3481
|
-
}
|
|
3482
|
-
io.log(`git links: linked ${gitLinks.linked} (existing ${gitLinks.existing}, skipped ${gitLinks.skipped})`);
|
|
3483
|
-
}
|
|
3484
|
-
} catch (error) {
|
|
3485
|
-
gitLinks = null;
|
|
3486
|
-
io.warn(`git links: skipped \u2014 ${error instanceof Error ? error.message : String(error)}`);
|
|
3487
|
-
}
|
|
3488
|
-
}
|
|
3489
|
-
return { results, planAbsPaths: collectContainedPlanAbsPaths(roadmaps.map((entry) => entry.roadmap), args.root, io.warn), gitLinks };
|
|
3490
|
-
}
|
|
3491
|
-
|
|
3492
|
-
// src/commands/sync.ts
|
|
3493
|
-
function register6(program, deps) {
|
|
3494
|
-
program.command("sync").description("Push cached roadmaps and linked plan documents to Nolto (baseRevision-aware)").option("--no-git-links", "Skip commit / PR issue links").action(async (opts) => {
|
|
3495
|
-
await runSyncCommand(deps, opts);
|
|
3496
|
-
});
|
|
3497
|
-
}
|
|
3498
|
-
async function runSyncCommand(deps, opts = {}) {
|
|
3499
|
-
const { root, projectId } = await resolveRoadmapReadContext(deps);
|
|
3500
|
-
const http = deps.http;
|
|
3501
|
-
const warn2 = (line2) => {
|
|
3502
|
-
process.stderr.write((line2.startsWith(" ") ? "" : "Warning: ") + line2 + "\n");
|
|
3503
|
-
};
|
|
3504
|
-
const response = await syncRepo(
|
|
3505
|
-
{ root, projectId, slugs: opts.slug === void 0 ? void 0 : [opts.slug] },
|
|
3506
|
-
{
|
|
3507
|
-
env: process.env,
|
|
3508
|
-
readFile: (p) => readFile12(p, "utf8"),
|
|
3509
|
-
realpath: (p) => realpath2(p),
|
|
3510
|
-
fileExists: (p) => existsSync4(p),
|
|
3511
|
-
repoIdentity: makeRepoIdentityResolver(deps),
|
|
3512
|
-
exec: promisify2(execFile3),
|
|
3513
|
-
gitLinks: (opts.gitLinks ?? true) && process.env.NOLTO_GIT_LINKS !== "0",
|
|
3514
|
-
http,
|
|
3515
|
-
log: (line2) => {
|
|
3516
|
-
if (!opts.quiet && deps.output.mode !== "json") process.stdout.write(line2 + "\n");
|
|
3517
|
-
},
|
|
3518
|
-
warn: warn2
|
|
3519
|
-
}
|
|
3520
|
-
);
|
|
3521
|
-
try {
|
|
3522
|
-
const drifted = await checkSkillDrift(root, { homeSkillDirs: deps.homeSkillDirs });
|
|
3523
|
-
for (const warning of drifted) warn2(warning);
|
|
3524
|
-
} catch {
|
|
3525
|
-
}
|
|
3526
|
-
let registryAdded = false;
|
|
3527
|
-
if (isHomeDirectory(root)) {
|
|
3528
|
-
process.stderr.write(`Warning: refusing to add home directory ${root} to the watch registry.
|
|
3529
|
-
`);
|
|
3530
|
-
} else {
|
|
3531
|
-
try {
|
|
3532
|
-
registryAdded = (await addRepoToRegistry(getRegistryPath(process.env), { root, projectId })).added;
|
|
3533
|
-
if (registryAdded) {
|
|
3534
|
-
const warning = await staleWatchWarning(process.env, deps.version, process.kill);
|
|
3535
|
-
if (warning) process.stderr.write(warning + "\n");
|
|
3764
|
+
} else {
|
|
3765
|
+
const tokenDisplay = settings.token != null ? `${maskToken(settings.token)} (source: ${settings.source.token})` : "(not configured)";
|
|
3766
|
+
const bindingDisplay = settings.source.project === "repo" && projectBindingPath != null ? `${settings.defaultProjectId ?? "none"} (source: repo, binding: ${projectBindingPath})` : `${settings.defaultProjectId ?? "none"} (source: ${settings.source.project})`;
|
|
3767
|
+
const lines = [
|
|
3768
|
+
["baseUrl", `${settings.baseUrl} (source: ${settings.source.baseUrl})`],
|
|
3769
|
+
["configPath", configPath],
|
|
3770
|
+
["token", tokenDisplay],
|
|
3771
|
+
["defaultProject", bindingDisplay],
|
|
3772
|
+
["projects", projectCount != null ? String(projectCount) : settings.token != null ? "(unavailable)" : "(no token)"]
|
|
3773
|
+
];
|
|
3774
|
+
if (tokenInfo) {
|
|
3775
|
+
lines.push(["scopes", tokenInfo.scopes === null ? "full" : tokenInfo.scopes.join(", ")], ["project", tokenInfo.projectId ?? "all"]);
|
|
3536
3776
|
}
|
|
3537
|
-
|
|
3538
|
-
const
|
|
3539
|
-
|
|
3777
|
+
const maxKey = lines.reduce((m, [k]) => Math.max(m, k.length), 0);
|
|
3778
|
+
for (const [key, val] of lines) {
|
|
3779
|
+
process.stdout.write(`${key.padEnd(maxKey)}: ${val}
|
|
3540
3780
|
`);
|
|
3781
|
+
}
|
|
3541
3782
|
}
|
|
3542
|
-
}
|
|
3543
|
-
if (!opts.quiet && deps.output.mode === "json") {
|
|
3544
|
-
const { planAbsPaths: _planAbsPaths, ...publicResponse } = response;
|
|
3545
|
-
printResult({ ...publicResponse, registryAdded }, "json");
|
|
3546
|
-
} else if (!opts.quiet && registryAdded) {
|
|
3547
|
-
process.stdout.write(`watch registry: added ${root}
|
|
3548
|
-
`);
|
|
3549
|
-
}
|
|
3550
|
-
return response;
|
|
3783
|
+
});
|
|
3551
3784
|
}
|
|
3552
3785
|
|
|
3553
3786
|
// src/roadmap-diff.ts
|
|
@@ -3593,390 +3826,132 @@ function diffRoadmaps(local, server) {
|
|
|
3593
3826
|
if (!localTaskIds.has(serverTask.id)) {
|
|
3594
3827
|
entries.push({
|
|
3595
3828
|
kind: "task-added",
|
|
3596
|
-
id: serverTask.id,
|
|
3597
|
-
title: serverTask.title,
|
|
3598
|
-
side: "server"
|
|
3599
|
-
});
|
|
3600
|
-
}
|
|
3601
|
-
}
|
|
3602
|
-
}
|
|
3603
|
-
const localPhaseIds = new Set(local.phases.map((phase) => phase.id));
|
|
3604
|
-
for (const serverPhase of server.phases) {
|
|
3605
|
-
if (!localPhaseIds.has(serverPhase.id)) {
|
|
3606
|
-
entries.push({
|
|
3607
|
-
kind: "phase-added",
|
|
3608
|
-
id: serverPhase.id,
|
|
3609
|
-
title: serverPhase.title,
|
|
3610
|
-
side: "server"
|
|
3611
|
-
});
|
|
3612
|
-
}
|
|
3613
|
-
}
|
|
3614
|
-
const meta = [
|
|
3615
|
-
{ field: "updatedAt", local: local.updatedAt ?? null, server: server.updatedAt ?? null },
|
|
3616
|
-
{
|
|
3617
|
-
field: "currentTaskId",
|
|
3618
|
-
local: local.currentTaskId ?? null,
|
|
3619
|
-
server: server.currentTaskId ?? null
|
|
3620
|
-
},
|
|
3621
|
-
{ field: "summary", local: local.summary, server: server.summary }
|
|
3622
|
-
];
|
|
3623
|
-
for (const item of meta) {
|
|
3624
|
-
if (item.local !== item.server) entries.push({ kind: "meta", ...item });
|
|
3625
|
-
}
|
|
3626
|
-
return entries;
|
|
3627
|
-
}
|
|
3628
|
-
function truncate(value) {
|
|
3629
|
-
if (value == null) return "none";
|
|
3630
|
-
const singleLine2 = value.replace(/\s+/g, " ");
|
|
3631
|
-
return singleLine2.length <= 60 ? singleLine2 : singleLine2.slice(0, 57) + "...";
|
|
3632
|
-
}
|
|
3633
|
-
function formatRoadmapDiff(slug, entries) {
|
|
3634
|
-
if (entries.length === 0) return [];
|
|
3635
|
-
const lines = [`${slug}:`];
|
|
3636
|
-
for (const entry of entries) {
|
|
3637
|
-
if (entry.kind === "task-status") {
|
|
3638
|
-
lines.push(` ${entry.id}: ${entry.local} (local) != ${entry.server} (server)`);
|
|
3639
|
-
} else if (entry.kind === "task-added" || entry.kind === "task-removed") {
|
|
3640
|
-
lines.push(` ${entry.side} only task ${entry.id} "${truncate(entry.title)}"`);
|
|
3641
|
-
} else if (entry.kind === "phase-added" || entry.kind === "phase-removed") {
|
|
3642
|
-
lines.push(` ${entry.side} only phase ${entry.id} "${truncate(entry.title)}"`);
|
|
3643
|
-
} else if (entry.field === "roadmap") {
|
|
3644
|
-
lines.push(` ${entry.side} only roadmap`);
|
|
3645
|
-
} else {
|
|
3646
|
-
lines.push(
|
|
3647
|
-
` ${entry.field}: ${truncate(entry.local)} (local) != ${truncate(entry.server)} (server)`
|
|
3648
|
-
);
|
|
3649
|
-
}
|
|
3650
|
-
}
|
|
3651
|
-
return lines;
|
|
3652
|
-
}
|
|
3653
|
-
|
|
3654
|
-
// src/commands/diff.ts
|
|
3655
|
-
function register7(program, deps) {
|
|
3656
|
-
program.command("diff [slug]").description("Compare local roadmaps with the server without changing either side.").action(async (requestedSlug) => {
|
|
3657
|
-
const { projectId } = await resolveRoadmapReadContext(deps);
|
|
3658
|
-
const list = await deps.http.get(
|
|
3659
|
-
`/api/projects/${projectId}/roadmaps`
|
|
3660
|
-
);
|
|
3661
|
-
const serverBySlug = new Map(list.roadmaps.map((roadmap) => [roadmap.slug, roadmap]));
|
|
3662
|
-
const localSlugs = await listCachedSlugs(process.env, projectId);
|
|
3663
|
-
const localSlugSet = new Set(localSlugs);
|
|
3664
|
-
const allSlugs = [.../* @__PURE__ */ new Set([...localSlugs, ...serverBySlug.keys()])].sort();
|
|
3665
|
-
if (requestedSlug != null && !allSlugs.includes(requestedSlug)) {
|
|
3666
|
-
throw new CliError(
|
|
3667
|
-
`Roadmap "${requestedSlug}" was not found locally or on the server.`,
|
|
3668
|
-
2
|
|
3669
|
-
);
|
|
3670
|
-
}
|
|
3671
|
-
const targetSlugs = requestedSlug == null ? allSlugs : [requestedSlug];
|
|
3672
|
-
let differing = 0;
|
|
3673
|
-
for (const slug of targetSlugs) {
|
|
3674
|
-
let local = null;
|
|
3675
|
-
if (localSlugSet.has(slug)) {
|
|
3676
|
-
try {
|
|
3677
|
-
local = (await readCache(process.env, projectId, slug))?.roadmap ?? null;
|
|
3678
|
-
} catch (err) {
|
|
3679
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
3680
|
-
process.stderr.write(`Warning: could not diff ${slug}.json: ${message}
|
|
3681
|
-
`);
|
|
3682
|
-
process.stdout.write(`${slug}:
|
|
3683
|
-
local roadmap is present but invalid
|
|
3684
|
-
`);
|
|
3685
|
-
differing += 1;
|
|
3686
|
-
continue;
|
|
3687
|
-
}
|
|
3688
|
-
}
|
|
3689
|
-
let server = null;
|
|
3690
|
-
if (serverBySlug.has(slug) && local !== null) {
|
|
3691
|
-
const response = await deps.http.get(
|
|
3692
|
-
`/api/projects/${projectId}/roadmaps/${encodeURIComponent(slug)}`
|
|
3693
|
-
);
|
|
3694
|
-
const validation = validateRoadmap(response.roadmap);
|
|
3695
|
-
if (validation.errors.length > 0) {
|
|
3696
|
-
throw new CliError(
|
|
3697
|
-
`Server roadmap "${slug}" failed validation: ${validation.errors.join("; ")}`,
|
|
3698
|
-
5
|
|
3699
|
-
);
|
|
3700
|
-
}
|
|
3701
|
-
server = response.roadmap;
|
|
3702
|
-
}
|
|
3703
|
-
const entries = local === null && serverBySlug.has(slug) ? [{ kind: "meta", field: "roadmap", side: "server" }] : diffRoadmaps(local, server);
|
|
3704
|
-
if (entries.length === 0) continue;
|
|
3705
|
-
differing += 1;
|
|
3706
|
-
process.stdout.write(formatRoadmapDiff(slug, entries).join("\n") + "\n");
|
|
3707
|
-
}
|
|
3708
|
-
if (differing === 0) {
|
|
3709
|
-
process.stdout.write("Up to date with the server.\n");
|
|
3710
|
-
process.exitCode = 0;
|
|
3711
|
-
} else {
|
|
3712
|
-
process.stdout.write(`${differing} roadmap(s) differ
|
|
3713
|
-
`);
|
|
3714
|
-
process.exitCode = 1;
|
|
3715
|
-
}
|
|
3716
|
-
});
|
|
3717
|
-
}
|
|
3718
|
-
|
|
3719
|
-
// src/commands/roadmap.ts
|
|
3720
|
-
import { readFile as readFile14 } from "fs/promises";
|
|
3721
|
-
import { existsSync as existsSync6 } from "fs";
|
|
3722
|
-
|
|
3723
|
-
// src/roadmap-commands.ts
|
|
3724
|
-
import path18 from "path";
|
|
3725
|
-
import { existsSync as existsSync5 } from "fs";
|
|
3726
|
-
import { readFile as readFile13, readdir as readdir6, writeFile as writeFile9, rename as rename5, unlink as unlink4, realpath as realpath3 } from "fs/promises";
|
|
3727
|
-
import { randomUUID as randomUUID7 } from "crypto";
|
|
3728
|
-
import readline4 from "readline/promises";
|
|
3729
|
-
|
|
3730
|
-
// src/commands/pull.ts
|
|
3731
|
-
function register8(program, deps) {
|
|
3732
|
-
program.command("pull [slug]").description("Pull server roadmaps into the local cache.").option("--all", "Pull all roadmaps (the default when no slug is specified)").option("--force", "Overwrite local changes that have not been synced").action(async (requestedSlug, opts) => {
|
|
3733
|
-
await runPull(deps, { ...opts, slug: requestedSlug });
|
|
3734
|
-
});
|
|
3735
|
-
}
|
|
3736
|
-
async function runPull(deps, opts = {}) {
|
|
3737
|
-
const messages = [];
|
|
3738
|
-
const { projectId } = await resolveRoadmapReadContext(deps);
|
|
3739
|
-
const list = await deps.http.get(`/api/projects/${projectId}/roadmaps`);
|
|
3740
|
-
const serverBySlug = new Map(list.roadmaps.map((roadmap) => [roadmap.slug, roadmap]));
|
|
3741
|
-
if (opts.slug != null && !serverBySlug.has(opts.slug)) {
|
|
3742
|
-
throw new CliError(`Roadmap "${opts.slug}" was not found on the server.`, 2);
|
|
3743
|
-
}
|
|
3744
|
-
const slugs = opts.slug == null ? [...serverBySlug.keys()] : [opts.slug];
|
|
3745
|
-
let skipped = false;
|
|
3746
|
-
for (const slug of slugs) {
|
|
3747
|
-
if (!await pullRoadmapCache({
|
|
3748
|
-
env: process.env,
|
|
3749
|
-
http: deps.http,
|
|
3750
|
-
projectId,
|
|
3751
|
-
slug,
|
|
3752
|
-
force: opts.force,
|
|
3753
|
-
log: (line2) => {
|
|
3754
|
-
messages.push(line2);
|
|
3755
|
-
if (!opts.quiet && deps.output.mode !== "json") process.stdout.write(line2 + "\n");
|
|
3756
|
-
},
|
|
3757
|
-
warn: (line2) => {
|
|
3758
|
-
process.stderr.write(line2 + "\n");
|
|
3759
|
-
}
|
|
3760
|
-
})) skipped = true;
|
|
3761
|
-
}
|
|
3762
|
-
if (skipped) throw new CliError("Some roadmaps have local changes that are not synced.", 4);
|
|
3763
|
-
if (!opts.quiet && deps.output.mode === "json") printResult({ messages }, "json");
|
|
3764
|
-
}
|
|
3765
|
-
|
|
3766
|
-
// src/roadmap-commands.ts
|
|
3767
|
-
var warn = (line2) => {
|
|
3768
|
-
process.stderr.write(line2 + "\n");
|
|
3769
|
-
};
|
|
3770
|
-
async function pull(deps, projectId, slug) {
|
|
3771
|
-
if (!await pullRoadmapCache({ env: process.env, http: deps.http, projectId, slug, log: () => void 0, warn })) {
|
|
3772
|
-
throw new CliError("Cache has unsynced structural changes; run nolto roadmap sync first.", 4);
|
|
3773
|
-
}
|
|
3774
|
-
}
|
|
3775
|
-
async function selectRoadmap(deps, requestedSlug) {
|
|
3776
|
-
const context3 = await resolveRoadmapReadContext(deps);
|
|
3777
|
-
let slug = requestedSlug;
|
|
3778
|
-
if (slug === void 0) {
|
|
3779
|
-
let slugs = await listCachedSlugs(process.env, context3.projectId);
|
|
3780
|
-
if (slugs.length === 0) {
|
|
3781
|
-
await runPull(deps, { quiet: true });
|
|
3782
|
-
slugs = await listCachedSlugs(process.env, context3.projectId);
|
|
3783
|
-
}
|
|
3784
|
-
if (slugs.length !== 1) {
|
|
3785
|
-
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);
|
|
3786
|
-
}
|
|
3787
|
-
slug = slugs[0];
|
|
3788
|
-
}
|
|
3789
|
-
const paths = cachePaths(process.env, context3.projectId, slug);
|
|
3790
|
-
if (!existsSync5(paths.json)) await pull(deps, context3.projectId, slug);
|
|
3791
|
-
return { ...context3, slug, paths };
|
|
3792
|
-
}
|
|
3793
|
-
async function roadmapPath(deps, slug) {
|
|
3794
|
-
const { paths } = await selectRoadmap(deps, slug);
|
|
3795
|
-
printResult(path18.resolve(paths.json), deps.output.mode);
|
|
3796
|
-
}
|
|
3797
|
-
async function roadmapStatus(deps, slug, fresh = false) {
|
|
3798
|
-
const selected = await selectRoadmap(deps, slug);
|
|
3799
|
-
if (fresh) await pull(deps, selected.projectId, selected.slug);
|
|
3800
|
-
const entry = await readCache(process.env, selected.projectId, selected.slug);
|
|
3801
|
-
const { roadmap, meta } = entry;
|
|
3802
|
-
const stats = deriveTaskStats(roadmap);
|
|
3803
|
-
const tasks = roadmap.phases.flatMap((phase) => phase.tasks);
|
|
3804
|
-
const current = tasks.find((task) => task.id === meta?.currentTaskId && task.status === "in-progress");
|
|
3805
|
-
const blocked = tasks.filter((task) => task.status === "blocked");
|
|
3806
|
-
const age = meta ? (Date.now() - Date.parse(meta.pulledAt)) / 6e4 : NaN;
|
|
3807
|
-
if (age > 10) warn(`Warning: cache is ${Math.floor(age)} minutes old; run with --fresh or nolto roadmap pull`);
|
|
3808
|
-
if (deps.output.mode === "json") {
|
|
3809
|
-
printResult({ roadmap, stats, currentTaskId: current?.id ?? null, revision: meta?.revision ?? 0, pulledAt: meta?.pulledAt ?? null }, "json");
|
|
3810
|
-
return;
|
|
3811
|
-
}
|
|
3812
|
-
printResult([
|
|
3813
|
-
`${roadmap.project.name}: ${stats.done}/${stats.total} done (${stats.progressPct}%)`,
|
|
3814
|
-
`Current: ${current ? `${current.id} \u2014 ${current.title}` : "none"}`,
|
|
3815
|
-
`Blocked: ${blocked.map((task) => `${task.id} \u2014 ${task.title}`).join(", ") || "none"}`,
|
|
3816
|
-
`Summary: ${roadmap.summary}`,
|
|
3817
|
-
`Revision: ${meta?.revision ?? 0} (pulled ${meta?.pulledAt ?? "unknown"})`
|
|
3818
|
-
].join("\n"), "human");
|
|
3819
|
-
}
|
|
3820
|
-
async function roadmapValidate(deps, slug) {
|
|
3821
|
-
const { paths } = await selectRoadmap(deps, slug);
|
|
3822
|
-
let parsed;
|
|
3823
|
-
try {
|
|
3824
|
-
parsed = JSON.parse(await readFile13(paths.json, "utf8"));
|
|
3825
|
-
} catch {
|
|
3826
|
-
throw new CliError(`ERROR Malformed JSON in ${paths.json}.`, 1);
|
|
3829
|
+
id: serverTask.id,
|
|
3830
|
+
title: serverTask.title,
|
|
3831
|
+
side: "server"
|
|
3832
|
+
});
|
|
3833
|
+
}
|
|
3834
|
+
}
|
|
3827
3835
|
}
|
|
3828
|
-
const
|
|
3829
|
-
for (const
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3836
|
+
const localPhaseIds = new Set(local.phases.map((phase) => phase.id));
|
|
3837
|
+
for (const serverPhase of server.phases) {
|
|
3838
|
+
if (!localPhaseIds.has(serverPhase.id)) {
|
|
3839
|
+
entries.push({
|
|
3840
|
+
kind: "phase-added",
|
|
3841
|
+
id: serverPhase.id,
|
|
3842
|
+
title: serverPhase.title,
|
|
3843
|
+
side: "server"
|
|
3844
|
+
});
|
|
3845
|
+
}
|
|
3833
3846
|
}
|
|
3834
|
-
|
|
3835
|
-
}
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
await unlink4(temp).catch(() => void 0);
|
|
3847
|
+
const meta = [
|
|
3848
|
+
{ field: "updatedAt", local: local.updatedAt ?? null, server: server.updatedAt ?? null },
|
|
3849
|
+
{
|
|
3850
|
+
field: "currentTaskId",
|
|
3851
|
+
local: local.currentTaskId ?? null,
|
|
3852
|
+
server: server.currentTaskId ?? null
|
|
3853
|
+
},
|
|
3854
|
+
{ field: "summary", local: local.summary, server: server.summary }
|
|
3855
|
+
];
|
|
3856
|
+
for (const item of meta) {
|
|
3857
|
+
if (item.local !== item.server) entries.push({ kind: "meta", ...item });
|
|
3846
3858
|
}
|
|
3847
|
-
|
|
3859
|
+
return entries;
|
|
3848
3860
|
}
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
const
|
|
3852
|
-
|
|
3853
|
-
let response;
|
|
3854
|
-
try {
|
|
3855
|
-
response = await args.http.patch(`/api/projects/${projectId}/roadmaps/${encodeURIComponent(slug)}/tasks/${encodeURIComponent(taskId)}`, args.body);
|
|
3856
|
-
} catch (error) {
|
|
3857
|
-
if (error instanceof CliError && error.status === 404) throw new CliError(`Task ${taskId} not found in ${slug}.`, 2);
|
|
3858
|
-
throw error;
|
|
3859
|
-
}
|
|
3860
|
-
const { errors } = validateRoadmap(response.roadmap);
|
|
3861
|
-
if (errors.length) throw new CliError(`Server roadmap "${slug}" failed validation: ${errors.join("; ")}`, 5);
|
|
3862
|
-
await writeCache(env, projectId, slug, response.roadmap, {
|
|
3863
|
-
repoIdentity: entry?.meta?.repoIdentity ?? null,
|
|
3864
|
-
revision: response.revision,
|
|
3865
|
-
pulledAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3866
|
-
currentTaskId: response.currentTaskId
|
|
3867
|
-
});
|
|
3868
|
-
return response;
|
|
3861
|
+
function truncate(value) {
|
|
3862
|
+
if (value == null) return "none";
|
|
3863
|
+
const singleLine2 = value.replace(/\s+/g, " ");
|
|
3864
|
+
return singleLine2.length <= 60 ? singleLine2 : singleLine2.slice(0, 57) + "...";
|
|
3869
3865
|
}
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
|
|
3866
|
+
function formatRoadmapDiff(slug, entries) {
|
|
3867
|
+
if (entries.length === 0) return [];
|
|
3868
|
+
const lines = [`${slug}:`];
|
|
3869
|
+
for (const entry of entries) {
|
|
3870
|
+
if (entry.kind === "task-status") {
|
|
3871
|
+
lines.push(` ${entry.id}: ${entry.local} (local) != ${entry.server} (server)`);
|
|
3872
|
+
} else if (entry.kind === "task-added" || entry.kind === "task-removed") {
|
|
3873
|
+
lines.push(` ${entry.side} only task ${entry.id} "${truncate(entry.title)}"`);
|
|
3874
|
+
} else if (entry.kind === "phase-added" || entry.kind === "phase-removed") {
|
|
3875
|
+
lines.push(` ${entry.side} only phase ${entry.id} "${truncate(entry.title)}"`);
|
|
3876
|
+
} else if (entry.field === "roadmap") {
|
|
3877
|
+
lines.push(` ${entry.side} only roadmap`);
|
|
3878
|
+
} else {
|
|
3879
|
+
lines.push(
|
|
3880
|
+
` ${entry.field}: ${truncate(entry.local)} (local) != ${truncate(entry.server)} (server)`
|
|
3881
|
+
);
|
|
3877
3882
|
}
|
|
3878
|
-
if (!existsSync5(absolute)) warn(`WARN plan file not found at ${absolute}`);
|
|
3879
|
-
}
|
|
3880
|
-
const response = await patchTask({ ...selected, env: process.env, http: deps.http, taskId, body });
|
|
3881
|
-
if (body.plan !== void 0) await runSyncCommand(deps, { slug: selected.slug, quiet: true });
|
|
3882
|
-
printResult(deps.output.mode === "json" ? response : body.plan !== void 0 ? `${taskId} plan -> ${body.plan}` : `${taskId} -> ${body.status}`, deps.output.mode);
|
|
3883
|
-
}
|
|
3884
|
-
async function roadmapEvents(deps, slug, opts) {
|
|
3885
|
-
const selected = await selectRoadmap(deps, slug);
|
|
3886
|
-
const query = new URLSearchParams();
|
|
3887
|
-
if (opts.since !== void 0) query.set("since", opts.since);
|
|
3888
|
-
if (opts.limit !== void 0) query.set("limit", opts.limit);
|
|
3889
|
-
const response = await deps.http.get(`/api/projects/${selected.projectId}/roadmaps/${encodeURIComponent(selected.slug)}/events${query.size ? `?${query}` : ""}`);
|
|
3890
|
-
if (deps.output.mode === "json") printResult(response, "json");
|
|
3891
|
-
else for (const event of response.events) {
|
|
3892
|
-
printResult(`rev ${event.revision} ${event.createdAt} ${event.actor?.name ?? "system"} ${event.source} ${event.taskId} ${event.field}: ${event.from ?? "\u2014"} \u2192 ${event.to ?? "\u2014"}`, "human");
|
|
3893
3883
|
}
|
|
3884
|
+
return lines;
|
|
3894
3885
|
}
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
cachePaths(process.env, projectId, slug);
|
|
3913
|
-
const roadmap = await loadValidRoadmap(path18.join(dir, file), (p) => readFile13(p, "utf8"));
|
|
3914
|
-
roadmap.schemaVersion = 3;
|
|
3915
|
-
delete roadmap.updatedAt;
|
|
3916
|
-
delete roadmap.currentTaskId;
|
|
3917
|
-
local.push({ slug, roadmap });
|
|
3918
|
-
}
|
|
3919
|
-
const list = await deps.http.get(`/api/projects/${projectId}/roadmaps`);
|
|
3920
|
-
const results = [];
|
|
3921
|
-
for (const { slug, roadmap } of local) {
|
|
3922
|
-
let server;
|
|
3923
|
-
if (list.roadmaps.some((item) => item.slug === slug)) server = await deps.http.get(`/api/projects/${projectId}/roadmaps/${encodeURIComponent(slug)}`);
|
|
3924
|
-
const unchanged = server !== void 0 && serializeRoadmap(roadmap) === serializeRoadmap(server.roadmap);
|
|
3925
|
-
if (server && !unchanged && !yes) {
|
|
3926
|
-
if (!process.stdin.isTTY) throw new CliError(`Replacing ${slug} at server rev ${server.revision} requires confirmation; rerun with --yes.`, 2);
|
|
3927
|
-
const rl = readline4.createInterface({ input: process.stdin, output: process.stderr });
|
|
3928
|
-
try {
|
|
3929
|
-
const answer = await rl.question(`Replace ${slug} on the server at rev ${server.revision} with the local file? [y/N] `);
|
|
3930
|
-
if (!/^y(es)?$/i.test(answer.trim())) throw new CliError(`Migration of ${slug} cancelled.`, 2);
|
|
3931
|
-
} finally {
|
|
3932
|
-
rl.close();
|
|
3933
|
-
}
|
|
3886
|
+
|
|
3887
|
+
// src/commands/diff.ts
|
|
3888
|
+
function register8(program, deps) {
|
|
3889
|
+
program.command("diff [slug]").description("Compare local roadmaps with the server without changing either side.").action(async (requestedSlug) => {
|
|
3890
|
+
const { projectId } = await resolveRoadmapReadContext(deps);
|
|
3891
|
+
const list = await deps.http.get(
|
|
3892
|
+
`/api/projects/${projectId}/roadmaps`
|
|
3893
|
+
);
|
|
3894
|
+
const serverBySlug = new Map(list.roadmaps.map((roadmap) => [roadmap.slug, roadmap]));
|
|
3895
|
+
const localSlugs = await listCachedSlugs(process.env, projectId);
|
|
3896
|
+
const localSlugSet = new Set(localSlugs);
|
|
3897
|
+
const allSlugs = [.../* @__PURE__ */ new Set([...localSlugs, ...serverBySlug.keys()])].sort();
|
|
3898
|
+
if (requestedSlug != null && !allSlugs.includes(requestedSlug)) {
|
|
3899
|
+
throw new CliError(
|
|
3900
|
+
`Roadmap "${requestedSlug}" was not found locally or on the server.`,
|
|
3901
|
+
2
|
|
3902
|
+
);
|
|
3934
3903
|
}
|
|
3935
|
-
const
|
|
3936
|
-
let
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3904
|
+
const targetSlugs = requestedSlug == null ? allSlugs : [requestedSlug];
|
|
3905
|
+
let differing = 0;
|
|
3906
|
+
for (const slug of targetSlugs) {
|
|
3907
|
+
let local = null;
|
|
3908
|
+
if (localSlugSet.has(slug)) {
|
|
3909
|
+
try {
|
|
3910
|
+
local = (await readCache(process.env, projectId, slug))?.roadmap ?? null;
|
|
3911
|
+
} catch (err) {
|
|
3912
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
3913
|
+
process.stderr.write(`Warning: could not diff ${slug}.json: ${message}
|
|
3914
|
+
`);
|
|
3915
|
+
process.stdout.write(`${slug}:
|
|
3916
|
+
local roadmap is present but invalid
|
|
3917
|
+
`);
|
|
3918
|
+
differing += 1;
|
|
3919
|
+
continue;
|
|
3920
|
+
}
|
|
3921
|
+
}
|
|
3922
|
+
let server = null;
|
|
3923
|
+
if (serverBySlug.has(slug) && local !== null) {
|
|
3924
|
+
const response = await deps.http.get(
|
|
3925
|
+
`/api/projects/${projectId}/roadmaps/${encodeURIComponent(slug)}`
|
|
3926
|
+
);
|
|
3927
|
+
const validation = validateRoadmap(response.roadmap);
|
|
3928
|
+
if (validation.errors.length > 0) {
|
|
3929
|
+
throw new CliError(
|
|
3930
|
+
`Server roadmap "${slug}" failed validation: ${validation.errors.join("; ")}`,
|
|
3931
|
+
5
|
|
3932
|
+
);
|
|
3933
|
+
}
|
|
3934
|
+
server = response.roadmap;
|
|
3935
|
+
}
|
|
3936
|
+
const entries = local === null && serverBySlug.has(slug) ? [{ kind: "meta", field: "roadmap", side: "server" }] : diffRoadmaps(local, server);
|
|
3937
|
+
if (entries.length === 0) continue;
|
|
3938
|
+
differing += 1;
|
|
3939
|
+
process.stdout.write(formatRoadmapDiff(slug, entries).join("\n") + "\n");
|
|
3941
3940
|
}
|
|
3942
|
-
if (
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
warn
|
|
3950
|
-
});
|
|
3951
|
-
revision = response.revision;
|
|
3952
|
-
saved = response.roadmap ?? roadmap;
|
|
3953
|
-
if (response.currentTaskId !== void 0) currentTaskId = response.currentTaskId;
|
|
3954
|
-
await writeCache(process.env, projectId, slug, saved, { repoIdentity, revision, pulledAt: (/* @__PURE__ */ new Date()).toISOString(), currentTaskId });
|
|
3941
|
+
if (differing === 0) {
|
|
3942
|
+
process.stdout.write("Up to date with the server.\n");
|
|
3943
|
+
process.exitCode = 0;
|
|
3944
|
+
} else {
|
|
3945
|
+
process.stdout.write(`${differing} roadmap(s) differ
|
|
3946
|
+
`);
|
|
3947
|
+
process.exitCode = 1;
|
|
3955
3948
|
}
|
|
3956
|
-
|
|
3957
|
-
results.push({ slug, action, revision });
|
|
3958
|
-
if (deps.output.mode !== "json") printResult(`${action} ${slug} (rev ${revision})`, "human");
|
|
3959
|
-
}
|
|
3960
|
-
const nextSteps = ["Next steps (run yourself):", " git rm -r .nolto/roadmaps"];
|
|
3961
|
-
let attributes = "";
|
|
3962
|
-
try {
|
|
3963
|
-
attributes = await readFile13(path18.join(root, ".gitattributes"), "utf8");
|
|
3964
|
-
} catch (error) {
|
|
3965
|
-
if (error.code !== "ENOENT") throw error;
|
|
3966
|
-
}
|
|
3967
|
-
if (attributes.split(/\r?\n/).some((line2) => /^\s*\.nolto\/roadmaps\/\*\.json\s+.*\bmerge=nolto-roadmap(?:\s|$)/.test(line2))) {
|
|
3968
|
-
nextSteps.push(' # remove the ".nolto/roadmaps/*.json merge=nolto-roadmap" line from .gitattributes');
|
|
3969
|
-
}
|
|
3970
|
-
nextSteps.push(" git config --unset-all merge.nolto-roadmap.name; git config --unset-all merge.nolto-roadmap.driver");
|
|
3971
|
-
const { added } = await addRepoToRegistry(getRegistryPath(process.env), { root, projectId });
|
|
3972
|
-
if (added) {
|
|
3973
|
-
const warning = await staleWatchWarning(process.env, deps.version, process.kill);
|
|
3974
|
-
if (warning) process.stderr.write(warning + "\n");
|
|
3975
|
-
}
|
|
3976
|
-
printResult(deps.output.mode === "json" ? { results, nextSteps } : nextSteps.join("\n"), deps.output.mode);
|
|
3949
|
+
});
|
|
3977
3950
|
}
|
|
3978
3951
|
|
|
3979
3952
|
// src/commands/roadmap.ts
|
|
3953
|
+
import { readFile as readFile14 } from "fs/promises";
|
|
3954
|
+
import { existsSync as existsSync6 } from "fs";
|
|
3980
3955
|
function register9(program, deps) {
|
|
3981
3956
|
const roadmap = program.command("roadmap").description("Read and update server roadmaps through the local cache.");
|
|
3982
3957
|
roadmap.command("schema").description("Print the roadmap schema reference").action(async () => {
|
|
@@ -4015,11 +3990,11 @@ import { execFile as execFile4 } from "child_process";
|
|
|
4015
3990
|
import { promisify as promisify3 } from "util";
|
|
4016
3991
|
import { readFile as readFile15, realpath as realpath4 } from "fs/promises";
|
|
4017
3992
|
import { existsSync as existsSync7, mkdirSync } from "fs";
|
|
4018
|
-
import
|
|
3993
|
+
import path20 from "path";
|
|
4019
3994
|
import chokidar from "chokidar";
|
|
4020
3995
|
|
|
4021
3996
|
// src/watch-core.ts
|
|
4022
|
-
import
|
|
3997
|
+
import path18 from "path";
|
|
4023
3998
|
var WatchSet = class {
|
|
4024
3999
|
constructor(deps) {
|
|
4025
4000
|
this.deps = deps;
|
|
@@ -4068,7 +4043,7 @@ async function reloadRoots(deps) {
|
|
|
4068
4043
|
continue;
|
|
4069
4044
|
}
|
|
4070
4045
|
try {
|
|
4071
|
-
const projectId = repo.projectId ?? (await loadRepoBinding(
|
|
4046
|
+
const projectId = repo.projectId ?? (await loadRepoBinding(path18.join(repo.root, "nolto.json")))?.projectId;
|
|
4072
4047
|
if (projectId) repos.push({ root: repo.root, projectId });
|
|
4073
4048
|
else deps.warn(`registered repo has no project binding, skipping: ${repo.root}`);
|
|
4074
4049
|
} catch (err) {
|
|
@@ -4139,7 +4114,7 @@ var RepoWatch = class {
|
|
|
4139
4114
|
};
|
|
4140
4115
|
|
|
4141
4116
|
// src/service-install.ts
|
|
4142
|
-
import
|
|
4117
|
+
import path19 from "path";
|
|
4143
4118
|
import os4 from "os";
|
|
4144
4119
|
function buildUnitFile(args) {
|
|
4145
4120
|
return [
|
|
@@ -4159,8 +4134,8 @@ function buildUnitFile(args) {
|
|
|
4159
4134
|
}
|
|
4160
4135
|
function getUnitPath(env) {
|
|
4161
4136
|
const xdg = env["XDG_CONFIG_HOME"];
|
|
4162
|
-
const base = xdg != null && xdg.length > 0 ? xdg :
|
|
4163
|
-
return
|
|
4137
|
+
const base = xdg != null && xdg.length > 0 ? xdg : path19.join(os4.homedir(), ".config");
|
|
4138
|
+
return path19.join(base, "systemd", "user", "nolto-watch.service");
|
|
4164
4139
|
}
|
|
4165
4140
|
async function installServiceWith(deps) {
|
|
4166
4141
|
if (deps.platform !== "linux") {
|
|
@@ -4171,7 +4146,7 @@ async function installServiceWith(deps) {
|
|
|
4171
4146
|
);
|
|
4172
4147
|
}
|
|
4173
4148
|
const unitPath = getUnitPath(deps.env);
|
|
4174
|
-
await deps.mkdir(
|
|
4149
|
+
await deps.mkdir(path19.dirname(unitPath));
|
|
4175
4150
|
await deps.writeFile(unitPath, buildUnitFile({ nodePath: deps.nodePath, scriptPath: deps.scriptPath }));
|
|
4176
4151
|
deps.log(`Wrote ${unitPath}`);
|
|
4177
4152
|
const reload = await deps.exec(["systemctl", "--user", "daemon-reload"]);
|
|
@@ -4185,7 +4160,7 @@ async function installServiceWith(deps) {
|
|
|
4185
4160
|
deps.log("Service nolto-watch enabled and started. Logs: journalctl --user -u nolto-watch -f");
|
|
4186
4161
|
}
|
|
4187
4162
|
async function installService() {
|
|
4188
|
-
const { writeFile:
|
|
4163
|
+
const { writeFile: writeFile11, mkdir: mkdir9 } = await import("fs/promises");
|
|
4189
4164
|
const { execFile: execFile6 } = await import("child_process");
|
|
4190
4165
|
const { promisify: promisify5 } = await import("util");
|
|
4191
4166
|
const execFileAsync = promisify5(execFile6);
|
|
@@ -4193,8 +4168,8 @@ async function installService() {
|
|
|
4193
4168
|
platform: process.platform,
|
|
4194
4169
|
env: process.env,
|
|
4195
4170
|
nodePath: process.execPath,
|
|
4196
|
-
scriptPath:
|
|
4197
|
-
writeFile: (p, content) =>
|
|
4171
|
+
scriptPath: path19.resolve(process.argv[1] ?? ""),
|
|
4172
|
+
writeFile: (p, content) => writeFile11(p, content, "utf8"),
|
|
4198
4173
|
mkdir: async (p) => {
|
|
4199
4174
|
await mkdir9(p, { recursive: true });
|
|
4200
4175
|
},
|
|
@@ -4335,7 +4310,7 @@ function register10(program, deps) {
|
|
|
4335
4310
|
const startRepo = ({ root, projectId }) => {
|
|
4336
4311
|
const roadmapsPath = cacheDir(process.env, projectId);
|
|
4337
4312
|
const warn2 = (line2) => {
|
|
4338
|
-
process.stderr.write(line2.startsWith(" ") ? line2 + "\n" : `Warning: [${
|
|
4313
|
+
process.stderr.write(line2.startsWith(" ") ? line2 + "\n" : `Warning: [${path20.basename(root)}] ${line2}
|
|
4339
4314
|
`);
|
|
4340
4315
|
};
|
|
4341
4316
|
mkdirSync(roadmapsPath, { recursive: true, mode: 448 });
|
|
@@ -4352,7 +4327,7 @@ function register10(program, deps) {
|
|
|
4352
4327
|
exec: promisify3(execFile4),
|
|
4353
4328
|
gitLinks: process.env.NOLTO_GIT_LINKS !== "0",
|
|
4354
4329
|
http,
|
|
4355
|
-
log: (line2) => process.stdout.write(`[${
|
|
4330
|
+
log: (line2) => process.stdout.write(`[${path20.basename(root)}] ${line2}
|
|
4356
4331
|
`),
|
|
4357
4332
|
warn: warn2
|
|
4358
4333
|
}
|
|
@@ -4365,7 +4340,7 @@ function register10(program, deps) {
|
|
|
4365
4340
|
warn: (line2) => process.stderr.write(line2 + "\n")
|
|
4366
4341
|
});
|
|
4367
4342
|
watcher.on("all", (_event, filePath) => {
|
|
4368
|
-
if (
|
|
4343
|
+
if (path20.dirname(filePath) === roadmapsPath && !filePath.endsWith(".json")) return;
|
|
4369
4344
|
repoWatch.handleEvent(filePath);
|
|
4370
4345
|
});
|
|
4371
4346
|
void checkSkillDrift(root, { homeSkillDirs: deps.homeSkillDirs }).then((drifted) => {
|
|
@@ -4485,7 +4460,7 @@ stale: ${result.stale}`, deps.output.mode);
|
|
|
4485
4460
|
printResult(deps.output.mode === "json" ? { repos } : repos.map((repo) => `${repo.root} ${repo.projectId ?? "\u2014"}${repo.exists ? "" : " (missing)"}`).join("\n"), deps.output.mode);
|
|
4486
4461
|
});
|
|
4487
4462
|
watch.command("remove [root]").description("Remove a repository from the watch registry.").action(async (arg) => {
|
|
4488
|
-
const root = arg === void 0 ? findRepoRoot(resolveStartDir(process.env, process.cwd())).root :
|
|
4463
|
+
const root = arg === void 0 ? findRepoRoot(resolveStartDir(process.env, process.cwd())).root : path20.resolve(arg);
|
|
4489
4464
|
const { removed } = await removeRepoFromRegistry(getRegistryPath(process.env), root);
|
|
4490
4465
|
if (!removed) throw new CliError(`${root} is not in the watch registry.`, 2, "Run `nolto watch list` to see registered repositories.");
|
|
4491
4466
|
printResult(deps.output.mode === "json" ? { removed: true, root } : `Removed ${root} from the watch registry.`, deps.output.mode);
|
|
@@ -4497,14 +4472,14 @@ import { execFile as execFile5 } from "child_process";
|
|
|
4497
4472
|
import { existsSync as existsSync8 } from "fs";
|
|
4498
4473
|
import { realpath as realpath5 } from "fs/promises";
|
|
4499
4474
|
import { createRequire as createRequire2 } from "module";
|
|
4500
|
-
import
|
|
4475
|
+
import path22 from "path";
|
|
4501
4476
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
4502
4477
|
import { promisify as promisify4 } from "util";
|
|
4503
4478
|
|
|
4504
4479
|
// src/update-notifier.ts
|
|
4505
|
-
import { readFile as readFile16, writeFile as
|
|
4480
|
+
import { readFile as readFile16, writeFile as writeFile9, mkdir as mkdir8 } from "fs/promises";
|
|
4506
4481
|
import https from "https";
|
|
4507
|
-
import
|
|
4482
|
+
import path21 from "path";
|
|
4508
4483
|
var PACKAGE = "@nolto/cli";
|
|
4509
4484
|
var CACHE_FILE = "update-check.json";
|
|
4510
4485
|
var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
@@ -4562,9 +4537,9 @@ function fetchLatestFromRegistry(timeoutMs = REQUEST_TIMEOUT_MS, opts = {}) {
|
|
|
4562
4537
|
});
|
|
4563
4538
|
}
|
|
4564
4539
|
async function writeUpdateCache(cachePath, now, latest2) {
|
|
4565
|
-
await mkdir8(
|
|
4540
|
+
await mkdir8(path21.dirname(cachePath), { recursive: true });
|
|
4566
4541
|
const payload = { checkedAt: now, latest: latest2 };
|
|
4567
|
-
await
|
|
4542
|
+
await writeFile9(cachePath, JSON.stringify(payload), { mode: 384 });
|
|
4568
4543
|
}
|
|
4569
4544
|
async function refreshCache(cachePath, now, fetchLatest) {
|
|
4570
4545
|
const latest2 = await fetchLatest();
|
|
@@ -4573,7 +4548,7 @@ async function refreshCache(cachePath, now, fetchLatest) {
|
|
|
4573
4548
|
}
|
|
4574
4549
|
async function checkForUpdate(opts) {
|
|
4575
4550
|
if (isDisabled(opts.env)) return null;
|
|
4576
|
-
const cachePath =
|
|
4551
|
+
const cachePath = path21.join(opts.configDir, CACHE_FILE);
|
|
4577
4552
|
let cache = {};
|
|
4578
4553
|
try {
|
|
4579
4554
|
cache = JSON.parse(await readFile16(cachePath, "utf8"));
|
|
@@ -4681,7 +4656,7 @@ async function updateCliWith(deps) {
|
|
|
4681
4656
|
}
|
|
4682
4657
|
deps.log(`Updated ${PACKAGE2} ${deps.currentVersion} \u2192 ${latest2}.`);
|
|
4683
4658
|
await deps.writeCache(
|
|
4684
|
-
|
|
4659
|
+
path22.join(deps.configDir, UPDATE_CACHE_FILE),
|
|
4685
4660
|
deps.now,
|
|
4686
4661
|
latest2
|
|
4687
4662
|
).catch(() => void 0);
|
|
@@ -4712,10 +4687,10 @@ async function updateCliWith(deps) {
|
|
|
4712
4687
|
};
|
|
4713
4688
|
}
|
|
4714
4689
|
function getCurrentVersion() {
|
|
4715
|
-
const dirname =
|
|
4690
|
+
const dirname = path22.dirname(fileURLToPath3(import.meta.url));
|
|
4716
4691
|
const require3 = createRequire2(import.meta.url);
|
|
4717
4692
|
try {
|
|
4718
|
-
const pkg = require3(
|
|
4693
|
+
const pkg = require3(path22.resolve(dirname, "../package.json"));
|
|
4719
4694
|
return pkg.version ?? "0.0.0";
|
|
4720
4695
|
} catch {
|
|
4721
4696
|
return "0.0.0";
|
|
@@ -4765,7 +4740,7 @@ function register11(program, deps) {
|
|
|
4765
4740
|
}
|
|
4766
4741
|
|
|
4767
4742
|
// src/commands/merge-file.ts
|
|
4768
|
-
import { readFile as readFile17, writeFile as
|
|
4743
|
+
import { readFile as readFile17, writeFile as writeFile10 } from "fs/promises";
|
|
4769
4744
|
|
|
4770
4745
|
// src/roadmap-merge.ts
|
|
4771
4746
|
import { isDeepStrictEqual } from "util";
|
|
@@ -5029,7 +5004,7 @@ function register12(program) {
|
|
|
5029
5004
|
const theirs = await readRoadmap(theirsPath);
|
|
5030
5005
|
const base = opts.base == null ? null : await readRoadmap(opts.base);
|
|
5031
5006
|
const merged = mergeRoadmaps({ base, ours, theirs });
|
|
5032
|
-
await
|
|
5007
|
+
await writeFile10(
|
|
5033
5008
|
opts.output ?? oursPath,
|
|
5034
5009
|
JSON.stringify(merged, null, 2) + "\n",
|
|
5035
5010
|
"utf8"
|
|
@@ -5333,14 +5308,14 @@ function buildProgram(deps) {
|
|
|
5333
5308
|
};
|
|
5334
5309
|
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");
|
|
5335
5310
|
register13(program, deps);
|
|
5336
|
-
register(program, deps);
|
|
5337
|
-
register3(program, deps);
|
|
5338
5311
|
register4(program, deps);
|
|
5339
5312
|
register5(program, deps);
|
|
5340
|
-
register2(program, deps);
|
|
5341
5313
|
register6(program, deps);
|
|
5342
5314
|
register7(program, deps);
|
|
5315
|
+
register(program, deps);
|
|
5316
|
+
register3(program, deps);
|
|
5343
5317
|
register8(program, deps);
|
|
5318
|
+
register2(program, deps);
|
|
5344
5319
|
register9(program, deps);
|
|
5345
5320
|
register10(program, deps);
|
|
5346
5321
|
register11(program, deps);
|
|
@@ -5360,11 +5335,11 @@ function buildProgram(deps) {
|
|
|
5360
5335
|
}
|
|
5361
5336
|
|
|
5362
5337
|
// src/index.ts
|
|
5363
|
-
var __dirname3 =
|
|
5338
|
+
var __dirname3 = path23.dirname(fileURLToPath4(import.meta.url));
|
|
5364
5339
|
var require2 = createRequire3(import.meta.url);
|
|
5365
5340
|
function getVersion() {
|
|
5366
5341
|
try {
|
|
5367
|
-
const pkgPath =
|
|
5342
|
+
const pkgPath = path23.resolve(__dirname3, "../package.json");
|
|
5368
5343
|
const pkg = require2(pkgPath);
|
|
5369
5344
|
return pkg.version ?? "0.0.0";
|
|
5370
5345
|
} catch {
|
|
@@ -5418,10 +5393,10 @@ async function main() {
|
|
|
5418
5393
|
output: { mode },
|
|
5419
5394
|
version,
|
|
5420
5395
|
configPath,
|
|
5421
|
-
claudeProjectsDir:
|
|
5396
|
+
claudeProjectsDir: path23.join(process.env.CLAUDE_CONFIG_DIR ?? path23.join(os5.homedir(), ".claude"), "projects"),
|
|
5422
5397
|
homeSkillDirs: [
|
|
5423
|
-
|
|
5424
|
-
|
|
5398
|
+
path23.join(process.env.CLAUDE_CONFIG_DIR ?? path23.join(os5.homedir(), ".claude"), "skills"),
|
|
5399
|
+
path23.join(os5.homedir(), ".agents", "skills")
|
|
5425
5400
|
],
|
|
5426
5401
|
repoBinding
|
|
5427
5402
|
});
|