@nolto/cli 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -0
- package/dist/index.js +403 -118
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,6 +43,16 @@ nolto whoami # Show resolved auth/config state and project count
|
|
|
43
43
|
|
|
44
44
|
### Repository Binding
|
|
45
45
|
|
|
46
|
+
To add a second repository to an existing project, run `nolto init` or
|
|
47
|
+
`nolto link <projectId>`. The CLI asks before adding an unrecognized repository;
|
|
48
|
+
press Enter to accept, or use `link --yes` to skip the prompt. JSON mode requires
|
|
49
|
+
`--yes` when addition is needed. Only the project owner can add repositories.
|
|
50
|
+
Declining keeps the local binding (and init's skill), but skips roadmap cache
|
|
51
|
+
initialization and watch registration. Run `nolto link --add` later before syncing.
|
|
52
|
+
If addition hits a plan limit (HTTP 402), the CLI exits with code 4 and an upgrade
|
|
53
|
+
URL. The binding and skill remain; upgrade and retry. `link --json` includes
|
|
54
|
+
`repoAdded` to indicate whether this command added the repository.
|
|
55
|
+
|
|
46
56
|
```bash
|
|
47
57
|
nolto link <projectId> # Write or update nolto.json at the repository root
|
|
48
58
|
nolto link --show # Show the current binding, source, and repository identity
|
|
@@ -71,6 +81,10 @@ nolto diff [slug] # Compare local and server roadmaps without c
|
|
|
71
81
|
nolto pull [slug] [--all] # Pull server roadmaps into the cache
|
|
72
82
|
nolto pull [slug] --force # Overwrite unsynced local changes
|
|
73
83
|
nolto watch [--debounce <ms>] # Watch registered repositories and auto-sync
|
|
84
|
+
nolto watch status # Show pid, version, start time, and service status
|
|
85
|
+
nolto watch stop # Stop watch (leaves the service installed)
|
|
86
|
+
nolto watch list # List registered repositories, including missing roots
|
|
87
|
+
nolto watch remove [root] # Unregister a repository (defaults to the current repo)
|
|
74
88
|
nolto watch --install-service # Install the Linux systemd user service
|
|
75
89
|
```
|
|
76
90
|
|
|
@@ -97,6 +111,17 @@ Timestamp fields (`updatedAt`, `startedAt`, and `completedAt`) must be RFC 3339
|
|
|
97
111
|
The shared proxy rejects a sync request body over 10 MB with HTTP `413`. Free
|
|
98
112
|
plan documents are already limited to 2 MB per roadmap before that shared cap.
|
|
99
113
|
|
|
114
|
+
`watch` records its PID, CLI version, and start time in `<config dir>/watch.json`
|
|
115
|
+
(mode 0600). `watch status` reports version drift; these four subcommands support
|
|
116
|
+
`--json`. `watch stop` leaves the systemd unit enabled for the next login; use
|
|
117
|
+
`watch --uninstall-service` to remove it permanently. Removing a registry entry
|
|
118
|
+
stops watching that repository without restarting watch and does not delete its files.
|
|
119
|
+
|
|
120
|
+
When init, link, sync, or roadmap migrate adds a registry entry, it warns if a
|
|
121
|
+
running watch uses a different CLI version. Watch from 0.15.x and earlier does
|
|
122
|
+
not write `watch.json` and cannot be detected. `nolto update` restarts the systemd
|
|
123
|
+
watch service so the updated watcher can report its version.
|
|
124
|
+
|
|
100
125
|
`watch` uses `{ root, projectId }` entries in the registry maintained by init, link,
|
|
101
126
|
and sync. Older entries resolve their project from `nolto.json`; missing repositories
|
|
102
127
|
or bindings are skipped with a warning. It watches the project cache (excluding
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
import { createRequire as createRequire3 } from "module";
|
|
5
5
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
6
|
-
import
|
|
6
|
+
import path21 from "path";
|
|
7
7
|
import { CommanderError } from "commander";
|
|
8
8
|
|
|
9
9
|
// src/config.ts
|
|
@@ -372,11 +372,11 @@ function maskToken(token) {
|
|
|
372
372
|
function createHttpClient(opts) {
|
|
373
373
|
const { baseUrl, version, token } = opts;
|
|
374
374
|
const base = baseUrl.replace(/\/+$/, "");
|
|
375
|
-
async function request(method,
|
|
376
|
-
if (!
|
|
377
|
-
throw new CliError(`HTTP client path must start with /api/, got: ${
|
|
375
|
+
async function request(method, path22, body) {
|
|
376
|
+
if (!path22.startsWith("/api/")) {
|
|
377
|
+
throw new CliError(`HTTP client path must start with /api/, got: ${path22}`, 2);
|
|
378
378
|
}
|
|
379
|
-
const url = `${base}${
|
|
379
|
+
const url = `${base}${path22}`;
|
|
380
380
|
const headers = {
|
|
381
381
|
"Content-Type": "application/json",
|
|
382
382
|
"User-Agent": `${CLI_USER_AGENT_NAME}/${version}`
|
|
@@ -518,12 +518,12 @@ function normalizeRemote(raw) {
|
|
|
518
518
|
const firstSlash = s.indexOf("/");
|
|
519
519
|
if (firstSlash <= 0) return null;
|
|
520
520
|
let host = s.slice(0, firstSlash).toLowerCase();
|
|
521
|
-
let
|
|
521
|
+
let path22 = s.slice(firstSlash + 1);
|
|
522
522
|
if (hadScheme) host = host.replace(/:\d+$/, "");
|
|
523
|
-
|
|
524
|
-
if (
|
|
525
|
-
if (HOSTED_LOWERCASE_PATH.has(host))
|
|
526
|
-
return `${host}/${
|
|
523
|
+
path22 = path22.replace(/\/+/g, "/").replace(/^\/+/, "").replace(/\/+$/, "").replace(/\.git$/i, "").replace(/\/+$/, "");
|
|
524
|
+
if (path22.length === 0) return null;
|
|
525
|
+
if (HOSTED_LOWERCASE_PATH.has(host)) path22 = path22.toLowerCase();
|
|
526
|
+
return `${host}/${path22}`;
|
|
527
527
|
}
|
|
528
528
|
function repoIdentityToString(id) {
|
|
529
529
|
return `${id.kind}:${id.value}`;
|
|
@@ -552,7 +552,7 @@ function checkKeys(value, allowed, at, errors) {
|
|
|
552
552
|
function isValidPlanPath(value) {
|
|
553
553
|
if (typeof value !== "string" || value.length === 0) return false;
|
|
554
554
|
if (value.includes("\\") || value.startsWith("/") || /^[A-Za-z]:/.test(value)) return false;
|
|
555
|
-
return value.split("/").every((segment) => segment !== "" && segment
|
|
555
|
+
return /\.(md|markdown)$/i.test(value) && value.split("/").every((segment, index) => segment !== "" && (!segment.startsWith(".") || index === 0 && segment === ".nolto"));
|
|
556
556
|
}
|
|
557
557
|
function daysInMonth(year, month) {
|
|
558
558
|
if (month === 2) {
|
|
@@ -593,7 +593,7 @@ function validatePlanPath(value, at) {
|
|
|
593
593
|
}
|
|
594
594
|
if (!isValidPlanPath(value)) {
|
|
595
595
|
return [
|
|
596
|
-
`${at} must be a repository-relative path using '/' separators (no absolute paths, '\\', '.'
|
|
596
|
+
`${at} must be a repository-relative path using '/' separators (no absolute paths, '\\', segments starting with '.' except a leading '.nolto/'; Markdown '.md' / '.markdown' only).`
|
|
597
597
|
];
|
|
598
598
|
}
|
|
599
599
|
return [];
|
|
@@ -1036,27 +1036,80 @@ ${issueUrl(deps.settings.baseUrl, ctx.projectId, number)}`, ctx.mode);
|
|
|
1036
1036
|
});
|
|
1037
1037
|
}
|
|
1038
1038
|
|
|
1039
|
+
// src/watch-state.ts
|
|
1040
|
+
import * as fs from "fs/promises";
|
|
1041
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
1042
|
+
import path3 from "path";
|
|
1043
|
+
import { z as z2 } from "zod";
|
|
1044
|
+
var watchStateSchema = z2.object({
|
|
1045
|
+
pid: z2.number().int().positive(),
|
|
1046
|
+
version: z2.string().min(1),
|
|
1047
|
+
startedAt: z2.string().datetime()
|
|
1048
|
+
});
|
|
1049
|
+
function getWatchStatePath(env) {
|
|
1050
|
+
return path3.join(getConfigDir(env), "watch.json");
|
|
1051
|
+
}
|
|
1052
|
+
async function readWatchState(filePath, io = fs) {
|
|
1053
|
+
try {
|
|
1054
|
+
const result = watchStateSchema.safeParse(JSON.parse(await io.readFile(filePath, "utf8")));
|
|
1055
|
+
return result.success ? result.data : null;
|
|
1056
|
+
} catch {
|
|
1057
|
+
return null;
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
async function writeWatchState(filePath, state, io = fs) {
|
|
1061
|
+
await io.mkdir(path3.dirname(filePath), { recursive: true, mode: 448 });
|
|
1062
|
+
const tempPath = `${filePath}.tmp-${process.pid}-${randomUUID2()}`;
|
|
1063
|
+
try {
|
|
1064
|
+
await io.writeFile(tempPath, JSON.stringify(state, null, 2) + "\n", { encoding: "utf8", mode: 384 });
|
|
1065
|
+
await io.rename(tempPath, filePath);
|
|
1066
|
+
} catch (error) {
|
|
1067
|
+
await io.unlink(tempPath).catch(() => void 0);
|
|
1068
|
+
throw error;
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
async function removeWatchState(filePath, pid, io = fs) {
|
|
1072
|
+
if ((await readWatchState(filePath, io))?.pid === pid) {
|
|
1073
|
+
await io.unlink(filePath).catch(() => void 0);
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
function isAlive(pid, kill = process.kill) {
|
|
1077
|
+
try {
|
|
1078
|
+
kill(pid, 0);
|
|
1079
|
+
return true;
|
|
1080
|
+
} catch (error) {
|
|
1081
|
+
if (error.code === "ESRCH") return false;
|
|
1082
|
+
if (error.code === "EPERM") return true;
|
|
1083
|
+
throw error;
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
async function staleWatchWarning(env, currentVersion, kill = process.kill) {
|
|
1087
|
+
const state = await readWatchState(getWatchStatePath(env));
|
|
1088
|
+
if (!state || state.version === currentVersion || !isAlive(state.pid, kill)) return null;
|
|
1089
|
+
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).`;
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1039
1092
|
// src/commands/init.ts
|
|
1040
1093
|
import readline2 from "readline/promises";
|
|
1041
1094
|
import { createRequire } from "module";
|
|
1042
1095
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
1043
1096
|
import os3 from "os";
|
|
1044
|
-
import
|
|
1045
|
-
import
|
|
1097
|
+
import path12 from "path";
|
|
1098
|
+
import fs2 from "fs";
|
|
1046
1099
|
|
|
1047
1100
|
// src/roadmap-bootstrap.ts
|
|
1048
1101
|
import { existsSync } from "fs";
|
|
1049
1102
|
import { readFile as readFile4, realpath } from "fs/promises";
|
|
1050
|
-
import
|
|
1103
|
+
import path6 from "path";
|
|
1051
1104
|
|
|
1052
1105
|
// src/roadmap-cache.ts
|
|
1053
1106
|
import { mkdir as mkdir2, readdir as readdir2, readFile as readFile3, writeFile as writeFile3, rename as rename2, unlink } from "fs/promises";
|
|
1054
|
-
import { randomUUID as
|
|
1055
|
-
import
|
|
1107
|
+
import { randomUUID as randomUUID3 } from "crypto";
|
|
1108
|
+
import path5 from "path";
|
|
1056
1109
|
|
|
1057
1110
|
// src/sync-core.ts
|
|
1058
1111
|
import { createHash } from "crypto";
|
|
1059
|
-
import
|
|
1112
|
+
import path4 from "path";
|
|
1060
1113
|
function sha256Hex(content) {
|
|
1061
1114
|
return "sha256:" + createHash("sha256").update(content, "utf8").digest("hex");
|
|
1062
1115
|
}
|
|
@@ -1103,9 +1156,20 @@ async function loadValidRoadmap(filePath, readFile13) {
|
|
|
1103
1156
|
async function buildSyncBody(args) {
|
|
1104
1157
|
const planDocuments = [];
|
|
1105
1158
|
for (const ref of collectPlanRefs(args.roadmap)) {
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1159
|
+
if (!isValidPlanPath(ref.path)) {
|
|
1160
|
+
args.deps.warn(`plan path not allowed (markdown only, no dot segments), skipping: ${ref.path}`);
|
|
1161
|
+
continue;
|
|
1162
|
+
}
|
|
1163
|
+
try {
|
|
1164
|
+
if (await args.deps.isIgnored?.(args.repoRoot, ref.path)) {
|
|
1165
|
+
args.deps.warn(`plan path is git-ignored, skipping: ${ref.path}`);
|
|
1166
|
+
continue;
|
|
1167
|
+
}
|
|
1168
|
+
} catch {
|
|
1169
|
+
}
|
|
1170
|
+
const root = path4.resolve(args.repoRoot);
|
|
1171
|
+
const absolute = path4.resolve(root, ref.path);
|
|
1172
|
+
if (absolute !== root && !absolute.startsWith(root + path4.sep)) {
|
|
1109
1173
|
args.deps.warn(`plan path outside repository root, skipping: ${ref.path}`);
|
|
1110
1174
|
continue;
|
|
1111
1175
|
}
|
|
@@ -1123,10 +1187,14 @@ async function buildSyncBody(args) {
|
|
|
1123
1187
|
args.deps.warn(`plan file not found, skipping: ${ref.path}`);
|
|
1124
1188
|
continue;
|
|
1125
1189
|
}
|
|
1126
|
-
if (real !== realRoot && !real.startsWith(realRoot +
|
|
1190
|
+
if (real !== realRoot && !real.startsWith(realRoot + path4.sep)) {
|
|
1127
1191
|
args.deps.warn(`symlink escapes repository root, skipping: ${ref.path}`);
|
|
1128
1192
|
continue;
|
|
1129
1193
|
}
|
|
1194
|
+
if (!isValidPlanPath(path4.relative(realRoot, real).split(path4.sep).join("/"))) {
|
|
1195
|
+
args.deps.warn(`plan path not allowed (markdown only, no dot segments), skipping: ${ref.path}`);
|
|
1196
|
+
continue;
|
|
1197
|
+
}
|
|
1130
1198
|
}
|
|
1131
1199
|
const content = await args.deps.readFile(absolute);
|
|
1132
1200
|
planDocuments.push({
|
|
@@ -1162,12 +1230,12 @@ var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
|
1162
1230
|
var ROADMAP_SLUG_PATTERN = /^[a-z0-9][a-z0-9._-]*$/;
|
|
1163
1231
|
function cacheDir(env, projectId) {
|
|
1164
1232
|
if (!UUID_RE.test(projectId)) throw new CliError(`Invalid project id "${projectId}".`, 2);
|
|
1165
|
-
return
|
|
1233
|
+
return path5.join(getConfigDir(env), "projects", projectId, "roadmaps");
|
|
1166
1234
|
}
|
|
1167
1235
|
function cachePaths(env, projectId, slug) {
|
|
1168
1236
|
if (!ROADMAP_SLUG_PATTERN.test(slug)) throw new CliError(`Invalid roadmap slug "${slug}".`, 2);
|
|
1169
1237
|
const dir = cacheDir(env, projectId);
|
|
1170
|
-
return { json:
|
|
1238
|
+
return { json: path5.join(dir, `${slug}.json`), meta: path5.join(dir, `${slug}.meta.json`) };
|
|
1171
1239
|
}
|
|
1172
1240
|
async function listCachedSlugs(env, projectId) {
|
|
1173
1241
|
try {
|
|
@@ -1221,7 +1289,7 @@ async function writeCache(env, projectId, slug, roadmap, meta) {
|
|
|
1221
1289
|
const metadata = { ...meta, currentTaskId: meta.currentTaskId ?? null, repoIdentity: meta.repoIdentity ?? null, contentHash: sha256Hex(raw) };
|
|
1222
1290
|
await mkdir2(cacheDir(env, projectId), { recursive: true, mode: 448 });
|
|
1223
1291
|
for (const [filePath, content] of [[paths.json, raw], [paths.meta, JSON.stringify(metadata, null, 2) + "\n"]]) {
|
|
1224
|
-
const temp = `${filePath}.tmp-${process.pid}-${
|
|
1292
|
+
const temp = `${filePath}.tmp-${process.pid}-${randomUUID3()}`;
|
|
1225
1293
|
try {
|
|
1226
1294
|
await writeFile3(temp, content, { mode: 384 });
|
|
1227
1295
|
await rename2(temp, filePath);
|
|
@@ -1293,7 +1361,7 @@ async function ensureRoadmapCache(args) {
|
|
|
1293
1361
|
if (skipped) throw new CliError("Some roadmaps have local changes that are not synced.", 4);
|
|
1294
1362
|
if (list.roadmaps.some((row) => row.repoIdentity == null || row.repoIdentity === identity)) return;
|
|
1295
1363
|
}
|
|
1296
|
-
const basename =
|
|
1364
|
+
const basename = path6.basename(args.repoRoot);
|
|
1297
1365
|
const slug = args.slug ?? slugifyProjectId(basename);
|
|
1298
1366
|
const collision = list.roadmaps.find((row) => row.slug === slug);
|
|
1299
1367
|
if (collision) throw new CliError(`Roadmap slug "${slug}" already exists in this project (repo: ${collision.repoIdentity ?? "unknown"}). Run \`nolto link --slug <other-slug>\` to name this repository's roadmap.`, 2);
|
|
@@ -1321,24 +1389,58 @@ async function ensureRoadmapCache(args) {
|
|
|
1321
1389
|
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 });
|
|
1322
1390
|
log(`created ${slug} on server (rev ${response.revision})`);
|
|
1323
1391
|
}
|
|
1392
|
+
async function ensureProjectRepo(args) {
|
|
1393
|
+
let repos;
|
|
1394
|
+
try {
|
|
1395
|
+
const project = await args.http.get(`/api/projects/${args.projectId}`);
|
|
1396
|
+
repos = Array.isArray(project.repos) ? project.repos : [];
|
|
1397
|
+
} catch (error) {
|
|
1398
|
+
if (error instanceof CliError && (error.status === 401 || error.status === 403)) throw error;
|
|
1399
|
+
process.stderr.write(`Warning: could not check project repositories: ${error instanceof Error ? error.message : String(error)}
|
|
1400
|
+
`);
|
|
1401
|
+
return "unbound";
|
|
1402
|
+
}
|
|
1403
|
+
if (repos.length === 0) return "unbound";
|
|
1404
|
+
const identity = repoIdentityToString(args.repoIdentity);
|
|
1405
|
+
if (repos.some((repo) => repo.identity === identity)) return "bound";
|
|
1406
|
+
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";
|
|
1407
|
+
try {
|
|
1408
|
+
await args.http.post(`/api/projects/${args.projectId}/repos`, { repoIdentity: args.repoIdentity });
|
|
1409
|
+
} catch (error) {
|
|
1410
|
+
if (error instanceof CliError) {
|
|
1411
|
+
if (error.status === 409 && error.serverError === "repo_already_bound_to_this") return "bound";
|
|
1412
|
+
if (error.status === 403) {
|
|
1413
|
+
throw new CliError(
|
|
1414
|
+
"Only the project owner can add a repository.",
|
|
1415
|
+
2,
|
|
1416
|
+
"Ask the owner to run `nolto link --add` in this repository."
|
|
1417
|
+
);
|
|
1418
|
+
}
|
|
1419
|
+
if (error.status === 402) process.stderr.write("binding and skill are kept; retry after upgrading.\n");
|
|
1420
|
+
}
|
|
1421
|
+
throw error;
|
|
1422
|
+
}
|
|
1423
|
+
args.log(`Added ${identity} to project.`);
|
|
1424
|
+
return "added";
|
|
1425
|
+
}
|
|
1324
1426
|
|
|
1325
1427
|
// src/commands/link.ts
|
|
1326
1428
|
import readline from "readline/promises";
|
|
1327
1429
|
import os2 from "os";
|
|
1328
|
-
import
|
|
1430
|
+
import path10 from "path";
|
|
1329
1431
|
import { statSync as statSync2 } from "fs";
|
|
1330
1432
|
|
|
1331
1433
|
// src/registry.ts
|
|
1332
1434
|
import { readFile as readFile5, writeFile as writeFile4, mkdir as mkdir3, rename as rename3, unlink as unlink2 } from "fs/promises";
|
|
1333
|
-
import { randomUUID as
|
|
1334
|
-
import
|
|
1335
|
-
import { z as
|
|
1336
|
-
var registrySchema =
|
|
1337
|
-
schemaVersion:
|
|
1338
|
-
repos:
|
|
1435
|
+
import { randomUUID as randomUUID4 } from "crypto";
|
|
1436
|
+
import path7 from "path";
|
|
1437
|
+
import { z as z3 } from "zod";
|
|
1438
|
+
var registrySchema = z3.object({
|
|
1439
|
+
schemaVersion: z3.literal(1),
|
|
1440
|
+
repos: z3.array(z3.object({ root: z3.string().min(1), projectId: z3.string().uuid().optional() }).passthrough())
|
|
1339
1441
|
}).passthrough();
|
|
1340
1442
|
function getRegistryPath(env) {
|
|
1341
|
-
return
|
|
1443
|
+
return path7.join(getConfigDir(env), "registry.json");
|
|
1342
1444
|
}
|
|
1343
1445
|
async function loadRegistry(filePath) {
|
|
1344
1446
|
let raw;
|
|
@@ -1378,27 +1480,38 @@ async function addRepoToRegistry(filePath, entry) {
|
|
|
1378
1480
|
...registry,
|
|
1379
1481
|
repos: existing ? registry.repos.map((repo) => repo.root === entry.root ? { ...repo, projectId: entry.projectId } : repo) : [...registry.repos, entry]
|
|
1380
1482
|
};
|
|
1381
|
-
await
|
|
1382
|
-
|
|
1483
|
+
await writeRegistry(filePath, updated);
|
|
1484
|
+
return { added: !existing, updated: !!existing, registry: updated };
|
|
1485
|
+
}
|
|
1486
|
+
async function writeRegistry(filePath, registry) {
|
|
1487
|
+
await mkdir3(path7.dirname(filePath), { recursive: true, mode: 448 });
|
|
1488
|
+
const tempPath = `${filePath}.tmp-${process.pid}-${randomUUID4()}`;
|
|
1383
1489
|
try {
|
|
1384
|
-
await writeFile4(tempPath, JSON.stringify(
|
|
1490
|
+
await writeFile4(tempPath, JSON.stringify(registry, null, 2) + "\n", "utf8");
|
|
1385
1491
|
await rename3(tempPath, filePath);
|
|
1386
1492
|
} catch (err) {
|
|
1387
1493
|
await unlink2(tempPath).catch(() => void 0);
|
|
1388
1494
|
throw err;
|
|
1389
1495
|
}
|
|
1390
|
-
|
|
1496
|
+
}
|
|
1497
|
+
async function removeRepoFromRegistry(filePath, root) {
|
|
1498
|
+
const registry = await loadRegistry(filePath);
|
|
1499
|
+
const repos = registry.repos.filter((repo) => repo.root !== root);
|
|
1500
|
+
if (repos.length === registry.repos.length) return { removed: false, registry };
|
|
1501
|
+
const updated = { ...registry, repos };
|
|
1502
|
+
await writeRegistry(filePath, updated);
|
|
1503
|
+
return { removed: true, registry: updated };
|
|
1391
1504
|
}
|
|
1392
1505
|
|
|
1393
1506
|
// src/repo-identity.ts
|
|
1394
1507
|
import { execFile } from "child_process";
|
|
1395
1508
|
import { realpathSync } from "fs";
|
|
1396
|
-
import
|
|
1509
|
+
import path9 from "path";
|
|
1397
1510
|
|
|
1398
1511
|
// src/machine-id.ts
|
|
1399
1512
|
import { chmod, mkdir as mkdir4, readFile as readFile6, writeFile as writeFile5 } from "fs/promises";
|
|
1400
|
-
import { randomUUID as
|
|
1401
|
-
import
|
|
1513
|
+
import { randomUUID as randomUUID5 } from "crypto";
|
|
1514
|
+
import path8 from "path";
|
|
1402
1515
|
var inFlightByConfigDir = /* @__PURE__ */ new Map();
|
|
1403
1516
|
function parseMachineId(raw, file) {
|
|
1404
1517
|
let parsed;
|
|
@@ -1414,7 +1527,7 @@ function parseMachineId(raw, file) {
|
|
|
1414
1527
|
return id;
|
|
1415
1528
|
}
|
|
1416
1529
|
async function loadOrCreate(configDir) {
|
|
1417
|
-
const file =
|
|
1530
|
+
const file = path8.join(configDir, "machine.json");
|
|
1418
1531
|
let raw = null;
|
|
1419
1532
|
try {
|
|
1420
1533
|
raw = await readFile6(file, "utf8");
|
|
@@ -1427,7 +1540,7 @@ async function loadOrCreate(configDir) {
|
|
|
1427
1540
|
if (raw !== null) {
|
|
1428
1541
|
return parseMachineId(raw, file);
|
|
1429
1542
|
}
|
|
1430
|
-
const machineId =
|
|
1543
|
+
const machineId = randomUUID5();
|
|
1431
1544
|
await mkdir4(configDir, { recursive: true, mode: 448 });
|
|
1432
1545
|
try {
|
|
1433
1546
|
await writeFile5(file, `${JSON.stringify({ machineId }, null, 2)}
|
|
@@ -1445,7 +1558,7 @@ async function loadOrCreate(configDir) {
|
|
|
1445
1558
|
return machineId;
|
|
1446
1559
|
}
|
|
1447
1560
|
function loadOrCreateMachineId(configDir) {
|
|
1448
|
-
const key =
|
|
1561
|
+
const key = path8.resolve(configDir);
|
|
1449
1562
|
const existing = inFlightByConfigDir.get(key);
|
|
1450
1563
|
if (existing !== void 0) return existing;
|
|
1451
1564
|
const pending = loadOrCreate(key).finally(() => {
|
|
@@ -1479,7 +1592,7 @@ async function resolveRepoIdentity(root, deps) {
|
|
|
1479
1592
|
try {
|
|
1480
1593
|
canonicalRoot = realpathSync(root);
|
|
1481
1594
|
} catch {
|
|
1482
|
-
canonicalRoot =
|
|
1595
|
+
canonicalRoot = path9.resolve(root);
|
|
1483
1596
|
}
|
|
1484
1597
|
return { kind: "local", value: `${machineId}:${canonicalRoot}` };
|
|
1485
1598
|
}
|
|
@@ -1498,7 +1611,7 @@ function resolveStartDir(env, cwd) {
|
|
|
1498
1611
|
}
|
|
1499
1612
|
function dirHasGit(dir) {
|
|
1500
1613
|
try {
|
|
1501
|
-
statSync2(
|
|
1614
|
+
statSync2(path10.join(dir, ".git"));
|
|
1502
1615
|
return true;
|
|
1503
1616
|
} catch {
|
|
1504
1617
|
return false;
|
|
@@ -1510,14 +1623,14 @@ function findRepoRoot(startDir, hasGit = dirHasGit) {
|
|
|
1510
1623
|
if (hasGit(current)) {
|
|
1511
1624
|
return { root: current, foundGit: true };
|
|
1512
1625
|
}
|
|
1513
|
-
const parent =
|
|
1626
|
+
const parent = path10.dirname(current);
|
|
1514
1627
|
if (parent === current) break;
|
|
1515
1628
|
current = parent;
|
|
1516
1629
|
}
|
|
1517
1630
|
return { root: startDir, foundGit: false };
|
|
1518
1631
|
}
|
|
1519
1632
|
function isHomeDirectory(dir, home = os2.homedir()) {
|
|
1520
|
-
return
|
|
1633
|
+
return path10.resolve(dir) === path10.resolve(home);
|
|
1521
1634
|
}
|
|
1522
1635
|
async function handleShow(deps, projectBindingPath, mode2) {
|
|
1523
1636
|
const startDir = resolveStartDir(process.env, process.cwd());
|
|
@@ -1643,7 +1756,7 @@ async function handleUnlink(projectBindingPath, mode2) {
|
|
|
1643
1756
|
`);
|
|
1644
1757
|
}
|
|
1645
1758
|
}
|
|
1646
|
-
async function performLink(deps, projectId, mode2, slug) {
|
|
1759
|
+
async function performLink(deps, projectId, mode2, slug, yes = false) {
|
|
1647
1760
|
if (!UUID_RE2.test(projectId)) {
|
|
1648
1761
|
throw new CliError(
|
|
1649
1762
|
`Invalid project ID: "${projectId}". Must be a UUID (e.g. 00000000-0000-0000-0000-000000000001).`,
|
|
@@ -1663,7 +1776,7 @@ async function performLink(deps, projectId, mode2, slug) {
|
|
|
1663
1776
|
token: deps.settings.token,
|
|
1664
1777
|
version: deps.version
|
|
1665
1778
|
});
|
|
1666
|
-
let projectName =
|
|
1779
|
+
let projectName = path10.basename(root);
|
|
1667
1780
|
if (deps.settings.token != null) {
|
|
1668
1781
|
try {
|
|
1669
1782
|
const result = await http.get(
|
|
@@ -1691,10 +1804,36 @@ Proceeding anyway \u2014 verify the ID is correct.
|
|
|
1691
1804
|
);
|
|
1692
1805
|
}
|
|
1693
1806
|
await writeRepoBinding(root, projectId);
|
|
1694
|
-
const writtenPath =
|
|
1807
|
+
const writtenPath = path10.join(root, "nolto.json");
|
|
1808
|
+
let repoAdded = false;
|
|
1695
1809
|
if (deps.settings.token == null) {
|
|
1696
1810
|
process.stderr.write("Warning: roadmap cache not initialized (no token); run nolto pull after nolto login\n");
|
|
1697
1811
|
} else {
|
|
1812
|
+
const repoIdentity = await makeRepoIdentityResolver(deps)(root);
|
|
1813
|
+
const result = await ensureProjectRepo({
|
|
1814
|
+
http,
|
|
1815
|
+
projectId,
|
|
1816
|
+
repoIdentity,
|
|
1817
|
+
confirm: async (question) => {
|
|
1818
|
+
if (yes) return true;
|
|
1819
|
+
if (mode2 === "json") throw new CliError("Adding this repository requires confirmation. Pass --yes to skip the prompt in --json mode.", 2);
|
|
1820
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
1821
|
+
try {
|
|
1822
|
+
const answer = (await rl.question(question)).trim().toLowerCase();
|
|
1823
|
+
return answer === "" || answer === "y" || answer === "yes";
|
|
1824
|
+
} finally {
|
|
1825
|
+
rl.close();
|
|
1826
|
+
}
|
|
1827
|
+
},
|
|
1828
|
+
log: (line) => {
|
|
1829
|
+
if (mode2 !== "json") process.stdout.write(line + "\n");
|
|
1830
|
+
}
|
|
1831
|
+
});
|
|
1832
|
+
if (result === "declined") {
|
|
1833
|
+
process.stdout.write("Skipped adding this repository. Run `nolto link --add` later; roadmap sync will fail until then.\n");
|
|
1834
|
+
return;
|
|
1835
|
+
}
|
|
1836
|
+
repoAdded = result === "added";
|
|
1698
1837
|
await ensureRoadmapCache({
|
|
1699
1838
|
env: process.env,
|
|
1700
1839
|
http,
|
|
@@ -1702,7 +1841,7 @@ Proceeding anyway \u2014 verify the ID is correct.
|
|
|
1702
1841
|
projectName,
|
|
1703
1842
|
repoRoot: root,
|
|
1704
1843
|
slug,
|
|
1705
|
-
repoIdentity
|
|
1844
|
+
repoIdentity,
|
|
1706
1845
|
log: (line) => {
|
|
1707
1846
|
if (mode2 !== "json") process.stdout.write(line + "\n");
|
|
1708
1847
|
}
|
|
@@ -1715,6 +1854,10 @@ Proceeding anyway \u2014 verify the ID is correct.
|
|
|
1715
1854
|
} else {
|
|
1716
1855
|
try {
|
|
1717
1856
|
registryAdded = (await addRepoToRegistry(getRegistryPath(process.env), { root, projectId })).added;
|
|
1857
|
+
if (registryAdded) {
|
|
1858
|
+
const warning = await staleWatchWarning(process.env, deps.version, process.kill);
|
|
1859
|
+
if (warning) process.stderr.write(warning + "\n");
|
|
1860
|
+
}
|
|
1718
1861
|
} catch (err) {
|
|
1719
1862
|
const message = err instanceof Error ? err.message : String(err);
|
|
1720
1863
|
process.stderr.write(`Warning: could not update watch registry: ${message}
|
|
@@ -1726,7 +1869,8 @@ Proceeding anyway \u2014 verify the ID is correct.
|
|
|
1726
1869
|
linked: true,
|
|
1727
1870
|
projectId,
|
|
1728
1871
|
projectBindingPath: writtenPath,
|
|
1729
|
-
registryAdded
|
|
1872
|
+
registryAdded,
|
|
1873
|
+
repoAdded
|
|
1730
1874
|
}, mode2);
|
|
1731
1875
|
} else {
|
|
1732
1876
|
process.stdout.write(
|
|
@@ -1743,7 +1887,7 @@ Commit nolto.json to share the binding with your team.
|
|
|
1743
1887
|
function register2(program, deps) {
|
|
1744
1888
|
const cmd = program.command("link [projectId]").description(
|
|
1745
1889
|
"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"
|
|
1746
|
-
).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
|
|
1890
|
+
).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");
|
|
1747
1891
|
cmd.action(async (projectId) => {
|
|
1748
1892
|
const { output } = deps;
|
|
1749
1893
|
const projectBindingPath = deps.repoBinding?.path ?? deps.projectBindingPath ?? null;
|
|
@@ -1833,7 +1977,7 @@ function register2(program, deps) {
|
|
|
1833
1977
|
2
|
|
1834
1978
|
);
|
|
1835
1979
|
}
|
|
1836
|
-
await performLink(deps, projectId, mode2, opts["slug"]);
|
|
1980
|
+
await performLink(deps, projectId, mode2, opts["slug"], opts["yes"] === true);
|
|
1837
1981
|
});
|
|
1838
1982
|
}
|
|
1839
1983
|
function invalidBindingError(projectBindingPath, error) {
|
|
@@ -1846,33 +1990,33 @@ function invalidBindingError(projectBindingPath, error) {
|
|
|
1846
1990
|
// src/skill-install.ts
|
|
1847
1991
|
import { cp, mkdir as mkdir5, readFile as readFile7, writeFile as writeFile6, rm as rm2 } from "fs/promises";
|
|
1848
1992
|
import { existsSync as existsSync2 } from "fs";
|
|
1849
|
-
import
|
|
1993
|
+
import path11 from "path";
|
|
1850
1994
|
import { fileURLToPath } from "url";
|
|
1851
|
-
var __dirname =
|
|
1995
|
+
var __dirname = path11.dirname(fileURLToPath(import.meta.url));
|
|
1852
1996
|
function resolveSkillSourceDir() {
|
|
1853
1997
|
const candidates = [
|
|
1854
|
-
|
|
1998
|
+
path11.resolve(__dirname, "skill/roadmap-progress"),
|
|
1855
1999
|
// bundled: dist/skill/...
|
|
1856
|
-
|
|
2000
|
+
path11.resolve(__dirname, "../../../skills/roadmap-progress")
|
|
1857
2001
|
// source: <repo>/skills/...
|
|
1858
2002
|
];
|
|
1859
2003
|
for (const candidate of candidates) {
|
|
1860
|
-
if (existsSync2(
|
|
2004
|
+
if (existsSync2(path11.join(candidate, "SKILL.md"))) return candidate;
|
|
1861
2005
|
}
|
|
1862
2006
|
throw new Error("Bundled roadmap-progress skill not found. Reinstall @nolto/cli.");
|
|
1863
2007
|
}
|
|
1864
2008
|
var VERSION_MARKER = ".nolto-skill-version";
|
|
1865
2009
|
async function checkSkillVersionDrift(repoRoot, cliVersion) {
|
|
1866
2010
|
const skillDirs = [
|
|
1867
|
-
|
|
1868
|
-
|
|
2011
|
+
path11.join(repoRoot, ".claude", "skills", "roadmap-progress"),
|
|
2012
|
+
path11.join(repoRoot, ".agents", "skills", "roadmap-progress")
|
|
1869
2013
|
];
|
|
1870
2014
|
const drifted = [];
|
|
1871
2015
|
for (const dir of skillDirs) {
|
|
1872
2016
|
if (!existsSync2(dir)) continue;
|
|
1873
2017
|
let installed;
|
|
1874
2018
|
try {
|
|
1875
|
-
const marker = (await readFile7(
|
|
2019
|
+
const marker = (await readFile7(path11.join(dir, VERSION_MARKER), "utf8")).trim();
|
|
1876
2020
|
installed = marker.length > 0 ? marker : null;
|
|
1877
2021
|
} catch {
|
|
1878
2022
|
installed = null;
|
|
@@ -1882,13 +2026,13 @@ async function checkSkillVersionDrift(repoRoot, cliVersion) {
|
|
|
1882
2026
|
return drifted;
|
|
1883
2027
|
}
|
|
1884
2028
|
function formatSkillVersionDriftWarning(repoRoot, cliVersion, drifted) {
|
|
1885
|
-
const dirs = drifted.map(({ dir }) =>
|
|
2029
|
+
const dirs = drifted.map(({ dir }) => path11.relative(repoRoot, dir).split(path11.sep).join("/")).join(", ");
|
|
1886
2030
|
const installed = [...new Set(drifted.map((entry) => entry.installed ?? "unknown"))].join(", ");
|
|
1887
2031
|
return `roadmap-progress skill is outdated in ${dirs} (installed ${installed}, CLI ${cliVersion}). Run \`nolto init\` in this repo to update it.`;
|
|
1888
2032
|
}
|
|
1889
2033
|
async function installSkill(args) {
|
|
1890
|
-
const targetDir =
|
|
1891
|
-
const markerPath =
|
|
2034
|
+
const targetDir = path11.join(args.skillsParentDir, "roadmap-progress");
|
|
2035
|
+
const markerPath = path11.join(targetDir, VERSION_MARKER);
|
|
1892
2036
|
const dirExists = existsSync2(targetDir);
|
|
1893
2037
|
let installedVersion = null;
|
|
1894
2038
|
if (dirExists) {
|
|
@@ -1909,17 +2053,17 @@ async function installSkill(args) {
|
|
|
1909
2053
|
}
|
|
1910
2054
|
|
|
1911
2055
|
// src/commands/init.ts
|
|
1912
|
-
var __dirname2 =
|
|
2056
|
+
var __dirname2 = path12.dirname(fileURLToPath2(import.meta.url));
|
|
1913
2057
|
var _require = createRequire(import.meta.url);
|
|
1914
2058
|
function getCliVersion() {
|
|
1915
2059
|
const candidates = [
|
|
1916
|
-
|
|
2060
|
+
path12.resolve(__dirname2, "../package.json"),
|
|
1917
2061
|
// bundled: dist/../package.json
|
|
1918
|
-
|
|
2062
|
+
path12.resolve(__dirname2, "../../package.json")
|
|
1919
2063
|
// source: src/commands/../../package.json
|
|
1920
2064
|
];
|
|
1921
2065
|
for (const pkgPath of candidates) {
|
|
1922
|
-
if (
|
|
2066
|
+
if (fs2.existsSync(pkgPath)) {
|
|
1923
2067
|
try {
|
|
1924
2068
|
const pkg = _require(pkgPath);
|
|
1925
2069
|
return pkg.version ?? "0.0.0";
|
|
@@ -2076,7 +2220,7 @@ Saved ${configPath}
|
|
|
2076
2220
|
}
|
|
2077
2221
|
if (isHomeDirectory(root)) {
|
|
2078
2222
|
process.stderr.write(
|
|
2079
|
-
`Refusing to set up your home directory as a repository root (found ${
|
|
2223
|
+
`Refusing to set up your home directory as a repository root (found ${path12.join(os3.homedir(), ".git")}). Run nolto init inside a project repository.
|
|
2080
2224
|
`
|
|
2081
2225
|
);
|
|
2082
2226
|
return;
|
|
@@ -2108,7 +2252,7 @@ Saved ${configPath}
|
|
|
2108
2252
|
boundProject != null ? "Keep this binding? [Y/n] " : "Keep this binding? [y/N] "
|
|
2109
2253
|
);
|
|
2110
2254
|
keepExistingBinding = boundProject != null ? keep.trim().toLowerCase() !== "n" : keep.trim().toLowerCase() === "y";
|
|
2111
|
-
repoProject = keepExistingBinding ? boundProject ?? { id: existingBinding.projectId, name:
|
|
2255
|
+
repoProject = keepExistingBinding ? boundProject ?? { id: existingBinding.projectId, name: path12.basename(root) } : await selectRepoProject(rl, repoHttp, projects, defaultProjectId);
|
|
2112
2256
|
} else {
|
|
2113
2257
|
repoProject = await selectRepoProject(rl, repoHttp, projects, defaultProjectId);
|
|
2114
2258
|
}
|
|
@@ -2122,7 +2266,7 @@ Set up this repository (${root}) for roadmap sync? [Y/n] `);
|
|
|
2122
2266
|
process.stdout.write("Skipped repo setup.\n");
|
|
2123
2267
|
return;
|
|
2124
2268
|
}
|
|
2125
|
-
const bindingPath = deps.repoBinding?.path ??
|
|
2269
|
+
const bindingPath = deps.repoBinding?.path ?? path12.join(root, "nolto.json");
|
|
2126
2270
|
if (keepExistingBinding) {
|
|
2127
2271
|
process.stdout.write(`binding: kept ${bindingPath} (${repoProject.id})
|
|
2128
2272
|
`);
|
|
@@ -2134,40 +2278,61 @@ Set up this repository (${root}) for roadmap sync? [Y/n] `);
|
|
|
2134
2278
|
);
|
|
2135
2279
|
}
|
|
2136
2280
|
await writeRepoBinding(root, repoProject.id);
|
|
2137
|
-
process.stdout.write(`binding: wrote ${
|
|
2281
|
+
process.stdout.write(`binding: wrote ${path12.join(root, "nolto.json")}
|
|
2138
2282
|
`);
|
|
2139
2283
|
}
|
|
2140
2284
|
const sourceDir = resolveSkillSourceDir();
|
|
2141
2285
|
const version = getCliVersion();
|
|
2142
2286
|
const claudeInstall = await installSkill({
|
|
2143
|
-
skillsParentDir:
|
|
2287
|
+
skillsParentDir: path12.join(root, ".claude", "skills"),
|
|
2144
2288
|
sourceDir,
|
|
2145
2289
|
version
|
|
2146
2290
|
});
|
|
2147
2291
|
process.stdout.write(`skill (claude): ${claudeInstall.action} ${claudeInstall.targetDir}
|
|
2148
2292
|
`);
|
|
2149
|
-
const usesAgentsTooling =
|
|
2293
|
+
const usesAgentsTooling = fs2.existsSync(path12.join(root, ".agents")) || fs2.existsSync(path12.join(root, ".codex")) || fs2.existsSync(path12.join(root, "AGENTS.md"));
|
|
2150
2294
|
if (usesAgentsTooling) {
|
|
2151
2295
|
const agentsInstall = await installSkill({
|
|
2152
|
-
skillsParentDir:
|
|
2296
|
+
skillsParentDir: path12.join(root, ".agents", "skills"),
|
|
2153
2297
|
sourceDir,
|
|
2154
2298
|
version
|
|
2155
2299
|
});
|
|
2156
2300
|
process.stdout.write(`skill (agents): ${agentsInstall.action} ${agentsInstall.targetDir}
|
|
2157
2301
|
`);
|
|
2158
2302
|
}
|
|
2303
|
+
const repoIdentity = await makeRepoIdentityResolver(deps)(root);
|
|
2304
|
+
const repoResult = await ensureProjectRepo({
|
|
2305
|
+
http: repoHttp,
|
|
2306
|
+
projectId: repoProject.id,
|
|
2307
|
+
repoIdentity,
|
|
2308
|
+
confirm: async (question) => {
|
|
2309
|
+
const answer = (await rl.question(question)).trim().toLowerCase();
|
|
2310
|
+
return answer === "" || answer === "y" || answer === "yes";
|
|
2311
|
+
},
|
|
2312
|
+
log: (line) => {
|
|
2313
|
+
process.stdout.write(line + "\n");
|
|
2314
|
+
}
|
|
2315
|
+
});
|
|
2316
|
+
if (repoResult === "declined") {
|
|
2317
|
+
process.stdout.write("Skipped adding this repository. Run `nolto link --add` later; roadmap sync will fail until then.\n");
|
|
2318
|
+
return;
|
|
2319
|
+
}
|
|
2159
2320
|
await ensureRoadmapCache({
|
|
2160
2321
|
env: process.env,
|
|
2161
2322
|
http: repoHttp,
|
|
2162
2323
|
projectId: repoProject.id,
|
|
2163
2324
|
projectName: repoProject.name,
|
|
2164
2325
|
repoRoot: root,
|
|
2165
|
-
repoIdentity
|
|
2326
|
+
repoIdentity,
|
|
2166
2327
|
log: (line) => {
|
|
2167
2328
|
process.stdout.write(line + "\n");
|
|
2168
2329
|
}
|
|
2169
2330
|
});
|
|
2170
2331
|
const registryResult = await addRepoToRegistry(getRegistryPath(process.env), { root, projectId: repoProject.id });
|
|
2332
|
+
if (registryResult.added) {
|
|
2333
|
+
const warning = await staleWatchWarning(process.env, deps.version, process.kill);
|
|
2334
|
+
if (warning) process.stderr.write(warning + "\n");
|
|
2335
|
+
}
|
|
2171
2336
|
process.stdout.write(
|
|
2172
2337
|
registryResult.added ? `watch registry: added ${root}
|
|
2173
2338
|
` : `watch registry: already registered
|
|
@@ -2410,7 +2575,7 @@ import { readFile as readFile8, realpath as realpath2 } from "fs/promises";
|
|
|
2410
2575
|
import { existsSync as existsSync3 } from "fs";
|
|
2411
2576
|
|
|
2412
2577
|
// src/roadmap-read.ts
|
|
2413
|
-
import
|
|
2578
|
+
import path13 from "path";
|
|
2414
2579
|
async function resolveRoadmapReadContext(deps) {
|
|
2415
2580
|
if (deps.settings.token == null) {
|
|
2416
2581
|
throw new CliError("Not authenticated. Run `nolto login` or set NOLTO_TOKEN.", 3);
|
|
@@ -2420,7 +2585,7 @@ async function resolveRoadmapReadContext(deps) {
|
|
|
2420
2585
|
if (!foundGit) {
|
|
2421
2586
|
throw new CliError("No git repository found. Run inside a repo set up with `nolto init`.", 2);
|
|
2422
2587
|
}
|
|
2423
|
-
const binding = await loadRepoBinding(
|
|
2588
|
+
const binding = await loadRepoBinding(path13.join(root, "nolto.json"));
|
|
2424
2589
|
const projectId = binding?.projectId ?? deps.settings.defaultProjectId;
|
|
2425
2590
|
if (projectId == null) {
|
|
2426
2591
|
throw new CliError("No project binding. Run `nolto init` or `nolto link <projectId>`.", 2);
|
|
@@ -2476,18 +2641,22 @@ async function collectGitLinks(root, exec) {
|
|
|
2476
2641
|
}
|
|
2477
2642
|
|
|
2478
2643
|
// src/sync-repo.ts
|
|
2479
|
-
import
|
|
2644
|
+
import path14 from "path";
|
|
2480
2645
|
import { readdir as readdir3 } from "fs/promises";
|
|
2481
2646
|
function collectContainedPlanAbsPaths(roadmaps, root, warn2) {
|
|
2482
2647
|
const planAbsPaths = /* @__PURE__ */ new Set();
|
|
2483
|
-
const resolvedRoot =
|
|
2648
|
+
const resolvedRoot = path14.resolve(root);
|
|
2484
2649
|
for (const roadmap of roadmaps) {
|
|
2485
2650
|
for (const ref of collectPlanRefs(roadmap)) {
|
|
2486
|
-
const absolute =
|
|
2487
|
-
if (absolute !== resolvedRoot && !absolute.startsWith(resolvedRoot +
|
|
2651
|
+
const absolute = path14.resolve(resolvedRoot, ref.path);
|
|
2652
|
+
if (absolute !== resolvedRoot && !absolute.startsWith(resolvedRoot + path14.sep)) {
|
|
2488
2653
|
warn2(`chokidar target outside repo, skipping: ${ref.path}`);
|
|
2489
2654
|
continue;
|
|
2490
2655
|
}
|
|
2656
|
+
if (!isValidPlanPath(ref.path)) {
|
|
2657
|
+
warn2(`plan path not allowed (markdown only, no dot segments), skipping: ${ref.path}`);
|
|
2658
|
+
continue;
|
|
2659
|
+
}
|
|
2491
2660
|
planAbsPaths.add(absolute);
|
|
2492
2661
|
}
|
|
2493
2662
|
}
|
|
@@ -2501,7 +2670,7 @@ async function syncRepo(args, io) {
|
|
|
2501
2670
|
if (slugs.length === 0) {
|
|
2502
2671
|
let legacyFiles = [];
|
|
2503
2672
|
try {
|
|
2504
|
-
legacyFiles = await readdir3(
|
|
2673
|
+
legacyFiles = await readdir3(path14.join(args.root, ".nolto", "roadmaps"));
|
|
2505
2674
|
} catch (err) {
|
|
2506
2675
|
if (err.code !== "ENOENT") throw err;
|
|
2507
2676
|
}
|
|
@@ -2521,6 +2690,15 @@ async function syncRepo(args, io) {
|
|
|
2521
2690
|
roadmaps.push({ slug, ...entry });
|
|
2522
2691
|
}
|
|
2523
2692
|
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);
|
|
2693
|
+
const exec = io.exec;
|
|
2694
|
+
const isIgnored = exec === void 0 ? void 0 : async (root, relPath) => {
|
|
2695
|
+
try {
|
|
2696
|
+
await exec("git", ["check-ignore", "-q", "--", relPath], { cwd: root });
|
|
2697
|
+
return true;
|
|
2698
|
+
} catch {
|
|
2699
|
+
return false;
|
|
2700
|
+
}
|
|
2701
|
+
};
|
|
2524
2702
|
const results = [];
|
|
2525
2703
|
for (const entry of roadmaps) {
|
|
2526
2704
|
const { slug, roadmap, meta } = entry;
|
|
@@ -2528,7 +2706,7 @@ async function syncRepo(args, io) {
|
|
|
2528
2706
|
try {
|
|
2529
2707
|
const response = await runSync(
|
|
2530
2708
|
{ repoRoot: args.root, projectId, slug, roadmap, repoIdentity, baseRevision: meta?.revision ?? 0 },
|
|
2531
|
-
{ http: io.http, readFile: io.readFile, fileExists: io.fileExists, realpath: io.realpath, log: io.log, warn: io.warn }
|
|
2709
|
+
{ http: io.http, readFile: io.readFile, fileExists: io.fileExists, realpath: io.realpath, ...isIgnored ? { isIgnored } : {}, log: io.log, warn: io.warn }
|
|
2532
2710
|
);
|
|
2533
2711
|
await writeCache(io.env, projectId, slug, response.roadmap ?? roadmap, {
|
|
2534
2712
|
repoIdentity: identity,
|
|
@@ -2626,6 +2804,10 @@ async function runSyncCommand(deps, opts = {}) {
|
|
|
2626
2804
|
} else {
|
|
2627
2805
|
try {
|
|
2628
2806
|
registryAdded = (await addRepoToRegistry(getRegistryPath(process.env), { root, projectId })).added;
|
|
2807
|
+
if (registryAdded) {
|
|
2808
|
+
const warning = await staleWatchWarning(process.env, deps.version, process.kill);
|
|
2809
|
+
if (warning) process.stderr.write(warning + "\n");
|
|
2810
|
+
}
|
|
2629
2811
|
} catch (err) {
|
|
2630
2812
|
const message = err instanceof Error ? err.message : String(err);
|
|
2631
2813
|
process.stderr.write(`Warning: could not update watch registry: ${message}
|
|
@@ -2809,10 +2991,10 @@ function register7(program, deps) {
|
|
|
2809
2991
|
}
|
|
2810
2992
|
|
|
2811
2993
|
// src/roadmap-commands.ts
|
|
2812
|
-
import
|
|
2994
|
+
import path15 from "path";
|
|
2813
2995
|
import { existsSync as existsSync4 } from "fs";
|
|
2814
2996
|
import { readFile as readFile9, readdir as readdir4, writeFile as writeFile7, rename as rename4, unlink as unlink3, realpath as realpath3 } from "fs/promises";
|
|
2815
|
-
import { randomUUID as
|
|
2997
|
+
import { randomUUID as randomUUID6 } from "crypto";
|
|
2816
2998
|
import readline4 from "readline/promises";
|
|
2817
2999
|
|
|
2818
3000
|
// src/commands/pull.ts
|
|
@@ -2880,7 +3062,7 @@ async function selectRoadmap(deps, requestedSlug) {
|
|
|
2880
3062
|
}
|
|
2881
3063
|
async function roadmapPath(deps, slug) {
|
|
2882
3064
|
const { paths } = await selectRoadmap(deps, slug);
|
|
2883
|
-
printResult(
|
|
3065
|
+
printResult(path15.resolve(paths.json), deps.output.mode);
|
|
2884
3066
|
}
|
|
2885
3067
|
async function roadmapStatus(deps, slug, fresh = false) {
|
|
2886
3068
|
const selected = await selectRoadmap(deps, slug);
|
|
@@ -2925,7 +3107,7 @@ async function roadmapSummary(deps, slug, text) {
|
|
|
2925
3107
|
const selected = await selectRoadmap(deps, slug);
|
|
2926
3108
|
const entry = await readCache(process.env, selected.projectId, selected.slug);
|
|
2927
3109
|
entry.roadmap.summary = text;
|
|
2928
|
-
const temp = `${selected.paths.json}.tmp-${
|
|
3110
|
+
const temp = `${selected.paths.json}.tmp-${randomUUID6()}`;
|
|
2929
3111
|
try {
|
|
2930
3112
|
await writeFile7(temp, serializeRoadmap(entry.roadmap), { mode: 384 });
|
|
2931
3113
|
await rename4(temp, selected.paths.json);
|
|
@@ -2959,8 +3141,8 @@ async function roadmapTask(deps, taskId, slug, body) {
|
|
|
2959
3141
|
const selected = await selectRoadmap(deps, slug);
|
|
2960
3142
|
if (body.status === "blocked" && !body.note?.trim()) throw new CliError("block requires a non-empty --note.", 2);
|
|
2961
3143
|
if (body.plan !== void 0) {
|
|
2962
|
-
const absolute =
|
|
2963
|
-
if (!isValidPlanPath(body.plan) || !absolute.startsWith(
|
|
3144
|
+
const absolute = path15.resolve(selected.root, body.plan);
|
|
3145
|
+
if (!isValidPlanPath(body.plan) || !absolute.startsWith(path15.resolve(selected.root) + path15.sep)) {
|
|
2964
3146
|
throw new CliError("plan must be a repository-relative path without . or .. segments.", 2);
|
|
2965
3147
|
}
|
|
2966
3148
|
if (!existsSync4(absolute)) warn(`WARN plan file not found at ${absolute}`);
|
|
@@ -2982,7 +3164,7 @@ async function roadmapEvents(deps, slug, opts) {
|
|
|
2982
3164
|
}
|
|
2983
3165
|
async function roadmapMigrate(deps, yes = false) {
|
|
2984
3166
|
const { root, projectId } = await resolveRoadmapReadContext(deps);
|
|
2985
|
-
const dir =
|
|
3167
|
+
const dir = path15.join(root, ".nolto", "roadmaps");
|
|
2986
3168
|
let files;
|
|
2987
3169
|
try {
|
|
2988
3170
|
files = (await readdir4(dir, { withFileTypes: true })).filter((file) => file.isFile() && file.name.endsWith(".json")).map((file) => file.name).sort();
|
|
@@ -2998,7 +3180,7 @@ async function roadmapMigrate(deps, yes = false) {
|
|
|
2998
3180
|
for (const file of files) {
|
|
2999
3181
|
const slug = file.slice(0, -5);
|
|
3000
3182
|
cachePaths(process.env, projectId, slug);
|
|
3001
|
-
const roadmap = await loadValidRoadmap(
|
|
3183
|
+
const roadmap = await loadValidRoadmap(path15.join(dir, file), (p) => readFile9(p, "utf8"));
|
|
3002
3184
|
roadmap.schemaVersion = 3;
|
|
3003
3185
|
delete roadmap.updatedAt;
|
|
3004
3186
|
delete roadmap.currentTaskId;
|
|
@@ -3048,7 +3230,7 @@ async function roadmapMigrate(deps, yes = false) {
|
|
|
3048
3230
|
const nextSteps = ["Next steps (run yourself):", " git rm -r .nolto/roadmaps"];
|
|
3049
3231
|
let attributes = "";
|
|
3050
3232
|
try {
|
|
3051
|
-
attributes = await readFile9(
|
|
3233
|
+
attributes = await readFile9(path15.join(root, ".gitattributes"), "utf8");
|
|
3052
3234
|
} catch (error) {
|
|
3053
3235
|
if (error.code !== "ENOENT") throw error;
|
|
3054
3236
|
}
|
|
@@ -3056,7 +3238,11 @@ async function roadmapMigrate(deps, yes = false) {
|
|
|
3056
3238
|
nextSteps.push(' # remove the ".nolto/roadmaps/*.json merge=nolto-roadmap" line from .gitattributes');
|
|
3057
3239
|
}
|
|
3058
3240
|
nextSteps.push(" git config --unset-all merge.nolto-roadmap.name; git config --unset-all merge.nolto-roadmap.driver");
|
|
3059
|
-
await addRepoToRegistry(getRegistryPath(process.env), { root, projectId });
|
|
3241
|
+
const { added } = await addRepoToRegistry(getRegistryPath(process.env), { root, projectId });
|
|
3242
|
+
if (added) {
|
|
3243
|
+
const warning = await staleWatchWarning(process.env, deps.version, process.kill);
|
|
3244
|
+
if (warning) process.stderr.write(warning + "\n");
|
|
3245
|
+
}
|
|
3060
3246
|
printResult(deps.output.mode === "json" ? { results, nextSteps } : nextSteps.join("\n"), deps.output.mode);
|
|
3061
3247
|
}
|
|
3062
3248
|
|
|
@@ -3094,11 +3280,11 @@ import { execFile as execFile3 } from "child_process";
|
|
|
3094
3280
|
import { promisify as promisify2 } from "util";
|
|
3095
3281
|
import { readFile as readFile10, realpath as realpath4 } from "fs/promises";
|
|
3096
3282
|
import { existsSync as existsSync5, mkdirSync } from "fs";
|
|
3097
|
-
import
|
|
3283
|
+
import path18 from "path";
|
|
3098
3284
|
import chokidar from "chokidar";
|
|
3099
3285
|
|
|
3100
3286
|
// src/watch-core.ts
|
|
3101
|
-
import
|
|
3287
|
+
import path16 from "path";
|
|
3102
3288
|
var WatchSet = class {
|
|
3103
3289
|
constructor(deps) {
|
|
3104
3290
|
this.deps = deps;
|
|
@@ -3147,7 +3333,7 @@ async function reloadRoots(deps) {
|
|
|
3147
3333
|
continue;
|
|
3148
3334
|
}
|
|
3149
3335
|
try {
|
|
3150
|
-
const projectId = repo.projectId ?? (await loadRepoBinding(
|
|
3336
|
+
const projectId = repo.projectId ?? (await loadRepoBinding(path16.join(repo.root, "nolto.json")))?.projectId;
|
|
3151
3337
|
if (projectId) repos.push({ root: repo.root, projectId });
|
|
3152
3338
|
else deps.warn(`registered repo has no project binding, skipping: ${repo.root}`);
|
|
3153
3339
|
} catch (err) {
|
|
@@ -3218,7 +3404,7 @@ var RepoWatch = class {
|
|
|
3218
3404
|
};
|
|
3219
3405
|
|
|
3220
3406
|
// src/service-install.ts
|
|
3221
|
-
import
|
|
3407
|
+
import path17 from "path";
|
|
3222
3408
|
import os4 from "os";
|
|
3223
3409
|
function buildUnitFile(args) {
|
|
3224
3410
|
return [
|
|
@@ -3238,8 +3424,8 @@ function buildUnitFile(args) {
|
|
|
3238
3424
|
}
|
|
3239
3425
|
function getUnitPath(env) {
|
|
3240
3426
|
const xdg = env["XDG_CONFIG_HOME"];
|
|
3241
|
-
const base = xdg != null && xdg.length > 0 ? xdg :
|
|
3242
|
-
return
|
|
3427
|
+
const base = xdg != null && xdg.length > 0 ? xdg : path17.join(os4.homedir(), ".config");
|
|
3428
|
+
return path17.join(base, "systemd", "user", "nolto-watch.service");
|
|
3243
3429
|
}
|
|
3244
3430
|
async function installServiceWith(deps) {
|
|
3245
3431
|
if (deps.platform !== "linux") {
|
|
@@ -3250,7 +3436,7 @@ async function installServiceWith(deps) {
|
|
|
3250
3436
|
);
|
|
3251
3437
|
}
|
|
3252
3438
|
const unitPath = getUnitPath(deps.env);
|
|
3253
|
-
await deps.mkdir(
|
|
3439
|
+
await deps.mkdir(path17.dirname(unitPath));
|
|
3254
3440
|
await deps.writeFile(unitPath, buildUnitFile({ nodePath: deps.nodePath, scriptPath: deps.scriptPath }));
|
|
3255
3441
|
deps.log(`Wrote ${unitPath}`);
|
|
3256
3442
|
const reload = await deps.exec(["systemctl", "--user", "daemon-reload"]);
|
|
@@ -3272,7 +3458,7 @@ async function installService() {
|
|
|
3272
3458
|
platform: process.platform,
|
|
3273
3459
|
env: process.env,
|
|
3274
3460
|
nodePath: process.execPath,
|
|
3275
|
-
scriptPath:
|
|
3461
|
+
scriptPath: path17.resolve(process.argv[1] ?? ""),
|
|
3276
3462
|
writeFile: (p, content) => writeFile10(p, content, "utf8"),
|
|
3277
3463
|
mkdir: async (p) => {
|
|
3278
3464
|
await mkdir7(p, { recursive: true });
|
|
@@ -3350,10 +3536,23 @@ async function uninstallService() {
|
|
|
3350
3536
|
warn: (line) => process.stderr.write("Warning: " + line + "\n")
|
|
3351
3537
|
});
|
|
3352
3538
|
}
|
|
3539
|
+
async function stopServiceWith(deps) {
|
|
3540
|
+
if (deps.platform !== "linux") {
|
|
3541
|
+
throw new CliError("Stopping the watch service requires systemd and is only supported on Linux.", 2);
|
|
3542
|
+
}
|
|
3543
|
+
const result = await deps.exec(["systemctl", "--user", "stop", "nolto-watch"]);
|
|
3544
|
+
if (result.code !== 0) {
|
|
3545
|
+
throw new CliError(
|
|
3546
|
+
`Could not stop the watch service: ${result.stderr}`,
|
|
3547
|
+
2,
|
|
3548
|
+
"Run `systemctl --user stop nolto-watch` manually."
|
|
3549
|
+
);
|
|
3550
|
+
}
|
|
3551
|
+
}
|
|
3353
3552
|
|
|
3354
3553
|
// src/commands/watch.ts
|
|
3355
3554
|
function register10(program, deps) {
|
|
3356
|
-
program.command("watch").description("Watch every registered repository's roadmap + plan files and sync on change.").option("--debounce <ms>", "Debounce window in milliseconds", "2000").option("--install-service", "Install and enable a systemd user unit (nolto-watch) instead of watching").option("--uninstall-service", "Stop and remove the systemd user unit (nolto-watch) instead of watching").action(async (opts) => {
|
|
3555
|
+
const watch = program.command("watch").description("Watch every registered repository's roadmap + plan files and sync on change.").option("--debounce <ms>", "Debounce window in milliseconds", "2000").option("--install-service", "Install and enable a systemd user unit (nolto-watch) instead of watching").option("--uninstall-service", "Stop and remove the systemd user unit (nolto-watch) instead of watching").action(async (opts) => {
|
|
3357
3556
|
if (opts.installService && opts.uninstallService) {
|
|
3358
3557
|
throw new CliError("--install-service and --uninstall-service cannot be used together.", 2);
|
|
3359
3558
|
}
|
|
@@ -3372,6 +3571,15 @@ function register10(program, deps) {
|
|
|
3372
3571
|
if (Number.isNaN(debounceMs) || debounceMs < 0) {
|
|
3373
3572
|
throw new CliError("--debounce must be a non-negative integer.", 2);
|
|
3374
3573
|
}
|
|
3574
|
+
const statePath = getWatchStatePath(process.env);
|
|
3575
|
+
const previous = await readWatchState(statePath);
|
|
3576
|
+
if (previous && previous.pid !== process.pid && isAlive(previous.pid)) {
|
|
3577
|
+
throw new CliError(
|
|
3578
|
+
`nolto watch is already running (pid ${previous.pid}, v${previous.version}).`,
|
|
3579
|
+
2,
|
|
3580
|
+
"Run `nolto watch stop` first."
|
|
3581
|
+
);
|
|
3582
|
+
}
|
|
3375
3583
|
const registryPath = getRegistryPath(process.env);
|
|
3376
3584
|
const roots = await reloadRoots({
|
|
3377
3585
|
load: () => loadRegistry(registryPath),
|
|
@@ -3392,7 +3600,7 @@ function register10(program, deps) {
|
|
|
3392
3600
|
const startRepo = ({ root, projectId }) => {
|
|
3393
3601
|
const roadmapsPath = cacheDir(process.env, projectId);
|
|
3394
3602
|
const warn2 = (line) => {
|
|
3395
|
-
process.stderr.write(line.startsWith(" ") ? line + "\n" : `Warning: [${
|
|
3603
|
+
process.stderr.write(line.startsWith(" ") ? line + "\n" : `Warning: [${path18.basename(root)}] ${line}
|
|
3396
3604
|
`);
|
|
3397
3605
|
};
|
|
3398
3606
|
mkdirSync(roadmapsPath, { recursive: true, mode: 448 });
|
|
@@ -3409,7 +3617,7 @@ function register10(program, deps) {
|
|
|
3409
3617
|
exec: promisify2(execFile3),
|
|
3410
3618
|
gitLinks: process.env.NOLTO_GIT_LINKS !== "0",
|
|
3411
3619
|
http,
|
|
3412
|
-
log: (line) => process.stdout.write(`[${
|
|
3620
|
+
log: (line) => process.stdout.write(`[${path18.basename(root)}] ${line}
|
|
3413
3621
|
`),
|
|
3414
3622
|
warn: warn2
|
|
3415
3623
|
}
|
|
@@ -3422,7 +3630,7 @@ function register10(program, deps) {
|
|
|
3422
3630
|
warn: (line) => process.stderr.write(line + "\n")
|
|
3423
3631
|
});
|
|
3424
3632
|
watcher.on("all", (_event, filePath) => {
|
|
3425
|
-
if (
|
|
3633
|
+
if (path18.dirname(filePath) === roadmapsPath && !filePath.endsWith(".json")) return;
|
|
3426
3634
|
repoWatch.handleEvent(filePath);
|
|
3427
3635
|
});
|
|
3428
3636
|
void checkSkillVersionDrift(root, deps.version).then((drifted) => {
|
|
@@ -3439,6 +3647,12 @@ function register10(program, deps) {
|
|
|
3439
3647
|
log: (line) => process.stdout.write(line + "\n")
|
|
3440
3648
|
});
|
|
3441
3649
|
await watchSet.reconcile(roots);
|
|
3650
|
+
try {
|
|
3651
|
+
await writeWatchState(statePath, { pid: process.pid, version: deps.version, startedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
3652
|
+
} catch (error) {
|
|
3653
|
+
await watchSet.stopAll();
|
|
3654
|
+
throw error;
|
|
3655
|
+
}
|
|
3442
3656
|
const registryWatcher = chokidar.watch(registryPath, { ignoreInitial: true });
|
|
3443
3657
|
let registryReloadTimer = null;
|
|
3444
3658
|
registryWatcher.on("all", () => {
|
|
@@ -3465,13 +3679,84 @@ function register10(program, deps) {
|
|
|
3465
3679
|
`);
|
|
3466
3680
|
await new Promise((resolve) => {
|
|
3467
3681
|
const stop = () => {
|
|
3682
|
+
process.removeListener("SIGINT", stop);
|
|
3683
|
+
process.removeListener("SIGTERM", stop);
|
|
3468
3684
|
if (registryReloadTimer != null) clearTimeout(registryReloadTimer);
|
|
3469
|
-
void Promise.all([registryWatcher.close(), watchSet.stopAll()]).
|
|
3685
|
+
void Promise.all([registryWatcher.close(), watchSet.stopAll()]).finally(() => removeWatchState(statePath, process.pid)).finally(resolve);
|
|
3470
3686
|
};
|
|
3471
3687
|
process.once("SIGINT", stop);
|
|
3472
3688
|
process.once("SIGTERM", stop);
|
|
3473
3689
|
});
|
|
3474
3690
|
});
|
|
3691
|
+
watch.addHelpText("after", "\nstop leaves the service installed for the next login; use --uninstall-service to remove it permanently.");
|
|
3692
|
+
watch.command("status").description("Show watch process and service status.").action(async () => {
|
|
3693
|
+
const state = await readWatchState(getWatchStatePath(process.env));
|
|
3694
|
+
const running = state !== null && isAlive(state.pid);
|
|
3695
|
+
const result = {
|
|
3696
|
+
running,
|
|
3697
|
+
pid: running ? state.pid : null,
|
|
3698
|
+
version: running ? state.version : null,
|
|
3699
|
+
startedAt: running ? state.startedAt : null,
|
|
3700
|
+
stale: running && state.version !== deps.version,
|
|
3701
|
+
service: existsSync5(getUnitPath(process.env)) ? "installed" : "not-installed"
|
|
3702
|
+
};
|
|
3703
|
+
printResult(deps.output.mode === "json" ? result : `${running ? "running" : "not running"}
|
|
3704
|
+
service: ${result.service}
|
|
3705
|
+
pid: ${result.pid ?? "\u2014"}
|
|
3706
|
+
version: ${result.version ?? "\u2014"}
|
|
3707
|
+
startedAt: ${result.startedAt ?? "\u2014"}
|
|
3708
|
+
stale: ${result.stale}`, deps.output.mode);
|
|
3709
|
+
});
|
|
3710
|
+
watch.command("stop").description("Stop watch without disabling the installed service.").action(async () => {
|
|
3711
|
+
const statePath = getWatchStatePath(process.env);
|
|
3712
|
+
const state = await readWatchState(statePath);
|
|
3713
|
+
const service = existsSync5(getUnitPath(process.env));
|
|
3714
|
+
let via = null;
|
|
3715
|
+
if (service) {
|
|
3716
|
+
await stopServiceWith({
|
|
3717
|
+
platform: process.platform,
|
|
3718
|
+
exec: async (cmd) => {
|
|
3719
|
+
try {
|
|
3720
|
+
await promisify2(execFile3)(cmd[0], cmd.slice(1));
|
|
3721
|
+
return { code: 0, stderr: "" };
|
|
3722
|
+
} catch (error) {
|
|
3723
|
+
const e = error;
|
|
3724
|
+
return { code: e.code ?? 1, stderr: e.stderr ?? String(error) };
|
|
3725
|
+
}
|
|
3726
|
+
}
|
|
3727
|
+
});
|
|
3728
|
+
via = "systemd";
|
|
3729
|
+
}
|
|
3730
|
+
if (state && isAlive(state.pid)) {
|
|
3731
|
+
try {
|
|
3732
|
+
process.kill(state.pid, "SIGTERM");
|
|
3733
|
+
} catch (error) {
|
|
3734
|
+
if (error.code !== "ESRCH") {
|
|
3735
|
+
throw new CliError(`Could not stop nolto watch (pid ${state.pid}): ${String(error)}`, 2);
|
|
3736
|
+
}
|
|
3737
|
+
}
|
|
3738
|
+
via ??= "signal";
|
|
3739
|
+
}
|
|
3740
|
+
if (state) {
|
|
3741
|
+
for (let attempt = 0; attempt < 50 && isAlive(state.pid); attempt++) {
|
|
3742
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
3743
|
+
}
|
|
3744
|
+
if (isAlive(state.pid)) throw new CliError(`nolto watch (pid ${state.pid}) did not stop within 5 seconds.`, 2);
|
|
3745
|
+
await removeWatchState(statePath, state.pid);
|
|
3746
|
+
}
|
|
3747
|
+
printResult(deps.output.mode === "json" ? { stopped: via !== null, via } : via === null ? "not running" : `Stopped nolto watch via ${via}.`, deps.output.mode);
|
|
3748
|
+
});
|
|
3749
|
+
watch.command("list").description("List repositories in the watch registry.").action(async () => {
|
|
3750
|
+
const registry = await loadRegistry(getRegistryPath(process.env));
|
|
3751
|
+
const repos = registry.repos.map((repo) => ({ root: repo.root, projectId: repo.projectId ?? null, exists: existsSync5(repo.root) }));
|
|
3752
|
+
printResult(deps.output.mode === "json" ? { repos } : repos.map((repo) => `${repo.root} ${repo.projectId ?? "\u2014"}${repo.exists ? "" : " (missing)"}`).join("\n"), deps.output.mode);
|
|
3753
|
+
});
|
|
3754
|
+
watch.command("remove [root]").description("Remove a repository from the watch registry.").action(async (arg) => {
|
|
3755
|
+
const root = arg === void 0 ? findRepoRoot(resolveStartDir(process.env, process.cwd())).root : path18.resolve(arg);
|
|
3756
|
+
const { removed } = await removeRepoFromRegistry(getRegistryPath(process.env), root);
|
|
3757
|
+
if (!removed) throw new CliError(`${root} is not in the watch registry.`, 2, "Run `nolto watch list` to see registered repositories.");
|
|
3758
|
+
printResult(deps.output.mode === "json" ? { removed: true, root } : `Removed ${root} from the watch registry.`, deps.output.mode);
|
|
3759
|
+
});
|
|
3475
3760
|
}
|
|
3476
3761
|
|
|
3477
3762
|
// src/update-cli.ts
|
|
@@ -3479,14 +3764,14 @@ import { execFile as execFile4 } from "child_process";
|
|
|
3479
3764
|
import { existsSync as existsSync6 } from "fs";
|
|
3480
3765
|
import { realpath as realpath5 } from "fs/promises";
|
|
3481
3766
|
import { createRequire as createRequire2 } from "module";
|
|
3482
|
-
import
|
|
3767
|
+
import path20 from "path";
|
|
3483
3768
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
3484
3769
|
import { promisify as promisify3 } from "util";
|
|
3485
3770
|
|
|
3486
3771
|
// src/update-notifier.ts
|
|
3487
3772
|
import { readFile as readFile11, writeFile as writeFile8, mkdir as mkdir6 } from "fs/promises";
|
|
3488
3773
|
import https from "https";
|
|
3489
|
-
import
|
|
3774
|
+
import path19 from "path";
|
|
3490
3775
|
var PACKAGE = "@nolto/cli";
|
|
3491
3776
|
var CACHE_FILE = "update-check.json";
|
|
3492
3777
|
var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
@@ -3544,7 +3829,7 @@ function fetchLatestFromRegistry(timeoutMs = REQUEST_TIMEOUT_MS, opts = {}) {
|
|
|
3544
3829
|
});
|
|
3545
3830
|
}
|
|
3546
3831
|
async function writeUpdateCache(cachePath, now, latest2) {
|
|
3547
|
-
await mkdir6(
|
|
3832
|
+
await mkdir6(path19.dirname(cachePath), { recursive: true });
|
|
3548
3833
|
const payload = { checkedAt: now, latest: latest2 };
|
|
3549
3834
|
await writeFile8(cachePath, JSON.stringify(payload), { mode: 384 });
|
|
3550
3835
|
}
|
|
@@ -3555,7 +3840,7 @@ async function refreshCache(cachePath, now, fetchLatest) {
|
|
|
3555
3840
|
}
|
|
3556
3841
|
async function checkForUpdate(opts) {
|
|
3557
3842
|
if (isDisabled(opts.env)) return null;
|
|
3558
|
-
const cachePath =
|
|
3843
|
+
const cachePath = path19.join(opts.configDir, CACHE_FILE);
|
|
3559
3844
|
let cache = {};
|
|
3560
3845
|
try {
|
|
3561
3846
|
cache = JSON.parse(await readFile11(cachePath, "utf8"));
|
|
@@ -3663,7 +3948,7 @@ async function updateCliWith(deps) {
|
|
|
3663
3948
|
}
|
|
3664
3949
|
deps.log(`Updated ${PACKAGE2} ${deps.currentVersion} \u2192 ${latest2}.`);
|
|
3665
3950
|
await deps.writeCache(
|
|
3666
|
-
|
|
3951
|
+
path20.join(deps.configDir, UPDATE_CACHE_FILE),
|
|
3667
3952
|
deps.now,
|
|
3668
3953
|
latest2
|
|
3669
3954
|
).catch(() => void 0);
|
|
@@ -3694,10 +3979,10 @@ async function updateCliWith(deps) {
|
|
|
3694
3979
|
};
|
|
3695
3980
|
}
|
|
3696
3981
|
function getCurrentVersion() {
|
|
3697
|
-
const dirname =
|
|
3982
|
+
const dirname = path20.dirname(fileURLToPath3(import.meta.url));
|
|
3698
3983
|
const require3 = createRequire2(import.meta.url);
|
|
3699
3984
|
try {
|
|
3700
|
-
const pkg = require3(
|
|
3985
|
+
const pkg = require3(path20.resolve(dirname, "../package.json"));
|
|
3701
3986
|
return pkg.version ?? "0.0.0";
|
|
3702
3987
|
} catch {
|
|
3703
3988
|
return "0.0.0";
|
|
@@ -4057,11 +4342,11 @@ function buildProgram(deps) {
|
|
|
4057
4342
|
}
|
|
4058
4343
|
|
|
4059
4344
|
// src/index.ts
|
|
4060
|
-
var __dirname3 =
|
|
4345
|
+
var __dirname3 = path21.dirname(fileURLToPath4(import.meta.url));
|
|
4061
4346
|
var require2 = createRequire3(import.meta.url);
|
|
4062
4347
|
function getVersion() {
|
|
4063
4348
|
try {
|
|
4064
|
-
const pkgPath =
|
|
4349
|
+
const pkgPath = path21.resolve(__dirname3, "../package.json");
|
|
4065
4350
|
const pkg = require2(pkgPath);
|
|
4066
4351
|
return pkg.version ?? "0.0.0";
|
|
4067
4352
|
} catch {
|