@nolto/cli 0.15.1 → 0.17.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 +28 -0
- package/dist/index.js +405 -128
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,6 +22,9 @@ nolto init
|
|
|
22
22
|
repo-local `nolto.json` binding, installs the bundled `roadmap-progress` skill,
|
|
23
23
|
and pulls roadmaps into the project cache. If the server has none, it creates a
|
|
24
24
|
schema v3 roadmap on the server. `nolto link` also pulls or creates roadmaps.
|
|
25
|
+
|
|
26
|
+
When creating a project, `nolto init` uses your only eligible organization automatically, or asks you to select one by number when several are available. If none are available, create an organization at `<baseURL>/orgs/new` first. Projects are always created in an organization.
|
|
27
|
+
|
|
25
28
|
Re-running it inside a repository keeps the saved token and only sets up that
|
|
26
29
|
repository; use `--force` to reconfigure the global settings.
|
|
27
30
|
|
|
@@ -43,6 +46,16 @@ nolto whoami # Show resolved auth/config state and project count
|
|
|
43
46
|
|
|
44
47
|
### Repository Binding
|
|
45
48
|
|
|
49
|
+
To add a second repository to an existing project, run `nolto init` or
|
|
50
|
+
`nolto link <projectId>`. The CLI asks before adding an unrecognized repository;
|
|
51
|
+
press Enter to accept, or use `link --yes` to skip the prompt. JSON mode requires
|
|
52
|
+
`--yes` when addition is needed. Only the project owner can add repositories.
|
|
53
|
+
Declining keeps the local binding (and init's skill), but skips roadmap cache
|
|
54
|
+
initialization and watch registration. Run `nolto link --add` later before syncing.
|
|
55
|
+
If addition hits a plan limit (HTTP 402), the CLI exits with code 4 and an upgrade
|
|
56
|
+
URL. The binding and skill remain; upgrade and retry. `link --json` includes
|
|
57
|
+
`repoAdded` to indicate whether this command added the repository.
|
|
58
|
+
|
|
46
59
|
```bash
|
|
47
60
|
nolto link <projectId> # Write or update nolto.json at the repository root
|
|
48
61
|
nolto link --show # Show the current binding, source, and repository identity
|
|
@@ -71,6 +84,10 @@ nolto diff [slug] # Compare local and server roadmaps without c
|
|
|
71
84
|
nolto pull [slug] [--all] # Pull server roadmaps into the cache
|
|
72
85
|
nolto pull [slug] --force # Overwrite unsynced local changes
|
|
73
86
|
nolto watch [--debounce <ms>] # Watch registered repositories and auto-sync
|
|
87
|
+
nolto watch status # Show pid, version, start time, and service status
|
|
88
|
+
nolto watch stop # Stop watch (leaves the service installed)
|
|
89
|
+
nolto watch list # List registered repositories, including missing roots
|
|
90
|
+
nolto watch remove [root] # Unregister a repository (defaults to the current repo)
|
|
74
91
|
nolto watch --install-service # Install the Linux systemd user service
|
|
75
92
|
```
|
|
76
93
|
|
|
@@ -97,6 +114,17 @@ Timestamp fields (`updatedAt`, `startedAt`, and `completedAt`) must be RFC 3339
|
|
|
97
114
|
The shared proxy rejects a sync request body over 10 MB with HTTP `413`. Free
|
|
98
115
|
plan documents are already limited to 2 MB per roadmap before that shared cap.
|
|
99
116
|
|
|
117
|
+
`watch` records its PID, CLI version, and start time in `<config dir>/watch.json`
|
|
118
|
+
(mode 0600). `watch status` reports version drift; these four subcommands support
|
|
119
|
+
`--json`. `watch stop` leaves the systemd unit enabled for the next login; use
|
|
120
|
+
`watch --uninstall-service` to remove it permanently. Removing a registry entry
|
|
121
|
+
stops watching that repository without restarting watch and does not delete its files.
|
|
122
|
+
|
|
123
|
+
When init, link, sync, or roadmap migrate adds a registry entry, it warns if a
|
|
124
|
+
running watch uses a different CLI version. Watch from 0.15.x and earlier does
|
|
125
|
+
not write `watch.json` and cannot be detected. `nolto update` restarts the systemd
|
|
126
|
+
watch service so the updated watcher can report its version.
|
|
127
|
+
|
|
100
128
|
`watch` uses `{ root, projectId }` entries in the registry maintained by init, link,
|
|
101
129
|
and sync. Older entries resolve their project from `nolto.json`; missing repositories
|
|
102
130
|
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}`;
|
|
@@ -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
|
}
|
|
@@ -1114,9 +1167,9 @@ async function buildSyncBody(args) {
|
|
|
1114
1167
|
}
|
|
1115
1168
|
} catch {
|
|
1116
1169
|
}
|
|
1117
|
-
const root =
|
|
1118
|
-
const absolute =
|
|
1119
|
-
if (absolute !== root && !absolute.startsWith(root +
|
|
1170
|
+
const root = path4.resolve(args.repoRoot);
|
|
1171
|
+
const absolute = path4.resolve(root, ref.path);
|
|
1172
|
+
if (absolute !== root && !absolute.startsWith(root + path4.sep)) {
|
|
1120
1173
|
args.deps.warn(`plan path outside repository root, skipping: ${ref.path}`);
|
|
1121
1174
|
continue;
|
|
1122
1175
|
}
|
|
@@ -1134,11 +1187,11 @@ async function buildSyncBody(args) {
|
|
|
1134
1187
|
args.deps.warn(`plan file not found, skipping: ${ref.path}`);
|
|
1135
1188
|
continue;
|
|
1136
1189
|
}
|
|
1137
|
-
if (real !== realRoot && !real.startsWith(realRoot +
|
|
1190
|
+
if (real !== realRoot && !real.startsWith(realRoot + path4.sep)) {
|
|
1138
1191
|
args.deps.warn(`symlink escapes repository root, skipping: ${ref.path}`);
|
|
1139
1192
|
continue;
|
|
1140
1193
|
}
|
|
1141
|
-
if (!isValidPlanPath(
|
|
1194
|
+
if (!isValidPlanPath(path4.relative(realRoot, real).split(path4.sep).join("/"))) {
|
|
1142
1195
|
args.deps.warn(`plan path not allowed (markdown only, no dot segments), skipping: ${ref.path}`);
|
|
1143
1196
|
continue;
|
|
1144
1197
|
}
|
|
@@ -1177,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;
|
|
|
1177
1230
|
var ROADMAP_SLUG_PATTERN = /^[a-z0-9][a-z0-9._-]*$/;
|
|
1178
1231
|
function cacheDir(env, projectId) {
|
|
1179
1232
|
if (!UUID_RE.test(projectId)) throw new CliError(`Invalid project id "${projectId}".`, 2);
|
|
1180
|
-
return
|
|
1233
|
+
return path5.join(getConfigDir(env), "projects", projectId, "roadmaps");
|
|
1181
1234
|
}
|
|
1182
1235
|
function cachePaths(env, projectId, slug) {
|
|
1183
1236
|
if (!ROADMAP_SLUG_PATTERN.test(slug)) throw new CliError(`Invalid roadmap slug "${slug}".`, 2);
|
|
1184
1237
|
const dir = cacheDir(env, projectId);
|
|
1185
|
-
return { json:
|
|
1238
|
+
return { json: path5.join(dir, `${slug}.json`), meta: path5.join(dir, `${slug}.meta.json`) };
|
|
1186
1239
|
}
|
|
1187
1240
|
async function listCachedSlugs(env, projectId) {
|
|
1188
1241
|
try {
|
|
@@ -1236,7 +1289,7 @@ async function writeCache(env, projectId, slug, roadmap, meta) {
|
|
|
1236
1289
|
const metadata = { ...meta, currentTaskId: meta.currentTaskId ?? null, repoIdentity: meta.repoIdentity ?? null, contentHash: sha256Hex(raw) };
|
|
1237
1290
|
await mkdir2(cacheDir(env, projectId), { recursive: true, mode: 448 });
|
|
1238
1291
|
for (const [filePath, content] of [[paths.json, raw], [paths.meta, JSON.stringify(metadata, null, 2) + "\n"]]) {
|
|
1239
|
-
const temp = `${filePath}.tmp-${process.pid}-${
|
|
1292
|
+
const temp = `${filePath}.tmp-${process.pid}-${randomUUID3()}`;
|
|
1240
1293
|
try {
|
|
1241
1294
|
await writeFile3(temp, content, { mode: 384 });
|
|
1242
1295
|
await rename2(temp, filePath);
|
|
@@ -1308,7 +1361,7 @@ async function ensureRoadmapCache(args) {
|
|
|
1308
1361
|
if (skipped) throw new CliError("Some roadmaps have local changes that are not synced.", 4);
|
|
1309
1362
|
if (list.roadmaps.some((row) => row.repoIdentity == null || row.repoIdentity === identity)) return;
|
|
1310
1363
|
}
|
|
1311
|
-
const basename =
|
|
1364
|
+
const basename = path6.basename(args.repoRoot);
|
|
1312
1365
|
const slug = args.slug ?? slugifyProjectId(basename);
|
|
1313
1366
|
const collision = list.roadmaps.find((row) => row.slug === slug);
|
|
1314
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);
|
|
@@ -1336,24 +1389,58 @@ async function ensureRoadmapCache(args) {
|
|
|
1336
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 });
|
|
1337
1390
|
log(`created ${slug} on server (rev ${response.revision})`);
|
|
1338
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
|
+
}
|
|
1339
1426
|
|
|
1340
1427
|
// src/commands/link.ts
|
|
1341
1428
|
import readline from "readline/promises";
|
|
1342
1429
|
import os2 from "os";
|
|
1343
|
-
import
|
|
1430
|
+
import path10 from "path";
|
|
1344
1431
|
import { statSync as statSync2 } from "fs";
|
|
1345
1432
|
|
|
1346
1433
|
// src/registry.ts
|
|
1347
1434
|
import { readFile as readFile5, writeFile as writeFile4, mkdir as mkdir3, rename as rename3, unlink as unlink2 } from "fs/promises";
|
|
1348
|
-
import { randomUUID as
|
|
1349
|
-
import
|
|
1350
|
-
import { z as
|
|
1351
|
-
var registrySchema =
|
|
1352
|
-
schemaVersion:
|
|
1353
|
-
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())
|
|
1354
1441
|
}).passthrough();
|
|
1355
1442
|
function getRegistryPath(env) {
|
|
1356
|
-
return
|
|
1443
|
+
return path7.join(getConfigDir(env), "registry.json");
|
|
1357
1444
|
}
|
|
1358
1445
|
async function loadRegistry(filePath) {
|
|
1359
1446
|
let raw;
|
|
@@ -1393,27 +1480,38 @@ async function addRepoToRegistry(filePath, entry) {
|
|
|
1393
1480
|
...registry,
|
|
1394
1481
|
repos: existing ? registry.repos.map((repo) => repo.root === entry.root ? { ...repo, projectId: entry.projectId } : repo) : [...registry.repos, entry]
|
|
1395
1482
|
};
|
|
1396
|
-
await
|
|
1397
|
-
|
|
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()}`;
|
|
1398
1489
|
try {
|
|
1399
|
-
await writeFile4(tempPath, JSON.stringify(
|
|
1490
|
+
await writeFile4(tempPath, JSON.stringify(registry, null, 2) + "\n", "utf8");
|
|
1400
1491
|
await rename3(tempPath, filePath);
|
|
1401
1492
|
} catch (err) {
|
|
1402
1493
|
await unlink2(tempPath).catch(() => void 0);
|
|
1403
1494
|
throw err;
|
|
1404
1495
|
}
|
|
1405
|
-
|
|
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 };
|
|
1406
1504
|
}
|
|
1407
1505
|
|
|
1408
1506
|
// src/repo-identity.ts
|
|
1409
1507
|
import { execFile } from "child_process";
|
|
1410
1508
|
import { realpathSync } from "fs";
|
|
1411
|
-
import
|
|
1509
|
+
import path9 from "path";
|
|
1412
1510
|
|
|
1413
1511
|
// src/machine-id.ts
|
|
1414
1512
|
import { chmod, mkdir as mkdir4, readFile as readFile6, writeFile as writeFile5 } from "fs/promises";
|
|
1415
|
-
import { randomUUID as
|
|
1416
|
-
import
|
|
1513
|
+
import { randomUUID as randomUUID5 } from "crypto";
|
|
1514
|
+
import path8 from "path";
|
|
1417
1515
|
var inFlightByConfigDir = /* @__PURE__ */ new Map();
|
|
1418
1516
|
function parseMachineId(raw, file) {
|
|
1419
1517
|
let parsed;
|
|
@@ -1429,7 +1527,7 @@ function parseMachineId(raw, file) {
|
|
|
1429
1527
|
return id;
|
|
1430
1528
|
}
|
|
1431
1529
|
async function loadOrCreate(configDir) {
|
|
1432
|
-
const file =
|
|
1530
|
+
const file = path8.join(configDir, "machine.json");
|
|
1433
1531
|
let raw = null;
|
|
1434
1532
|
try {
|
|
1435
1533
|
raw = await readFile6(file, "utf8");
|
|
@@ -1442,7 +1540,7 @@ async function loadOrCreate(configDir) {
|
|
|
1442
1540
|
if (raw !== null) {
|
|
1443
1541
|
return parseMachineId(raw, file);
|
|
1444
1542
|
}
|
|
1445
|
-
const machineId =
|
|
1543
|
+
const machineId = randomUUID5();
|
|
1446
1544
|
await mkdir4(configDir, { recursive: true, mode: 448 });
|
|
1447
1545
|
try {
|
|
1448
1546
|
await writeFile5(file, `${JSON.stringify({ machineId }, null, 2)}
|
|
@@ -1460,7 +1558,7 @@ async function loadOrCreate(configDir) {
|
|
|
1460
1558
|
return machineId;
|
|
1461
1559
|
}
|
|
1462
1560
|
function loadOrCreateMachineId(configDir) {
|
|
1463
|
-
const key =
|
|
1561
|
+
const key = path8.resolve(configDir);
|
|
1464
1562
|
const existing = inFlightByConfigDir.get(key);
|
|
1465
1563
|
if (existing !== void 0) return existing;
|
|
1466
1564
|
const pending = loadOrCreate(key).finally(() => {
|
|
@@ -1494,7 +1592,7 @@ async function resolveRepoIdentity(root, deps) {
|
|
|
1494
1592
|
try {
|
|
1495
1593
|
canonicalRoot = realpathSync(root);
|
|
1496
1594
|
} catch {
|
|
1497
|
-
canonicalRoot =
|
|
1595
|
+
canonicalRoot = path9.resolve(root);
|
|
1498
1596
|
}
|
|
1499
1597
|
return { kind: "local", value: `${machineId}:${canonicalRoot}` };
|
|
1500
1598
|
}
|
|
@@ -1513,7 +1611,7 @@ function resolveStartDir(env, cwd) {
|
|
|
1513
1611
|
}
|
|
1514
1612
|
function dirHasGit(dir) {
|
|
1515
1613
|
try {
|
|
1516
|
-
statSync2(
|
|
1614
|
+
statSync2(path10.join(dir, ".git"));
|
|
1517
1615
|
return true;
|
|
1518
1616
|
} catch {
|
|
1519
1617
|
return false;
|
|
@@ -1525,14 +1623,14 @@ function findRepoRoot(startDir, hasGit = dirHasGit) {
|
|
|
1525
1623
|
if (hasGit(current)) {
|
|
1526
1624
|
return { root: current, foundGit: true };
|
|
1527
1625
|
}
|
|
1528
|
-
const parent =
|
|
1626
|
+
const parent = path10.dirname(current);
|
|
1529
1627
|
if (parent === current) break;
|
|
1530
1628
|
current = parent;
|
|
1531
1629
|
}
|
|
1532
1630
|
return { root: startDir, foundGit: false };
|
|
1533
1631
|
}
|
|
1534
1632
|
function isHomeDirectory(dir, home = os2.homedir()) {
|
|
1535
|
-
return
|
|
1633
|
+
return path10.resolve(dir) === path10.resolve(home);
|
|
1536
1634
|
}
|
|
1537
1635
|
async function handleShow(deps, projectBindingPath, mode2) {
|
|
1538
1636
|
const startDir = resolveStartDir(process.env, process.cwd());
|
|
@@ -1658,7 +1756,7 @@ async function handleUnlink(projectBindingPath, mode2) {
|
|
|
1658
1756
|
`);
|
|
1659
1757
|
}
|
|
1660
1758
|
}
|
|
1661
|
-
async function performLink(deps, projectId, mode2, slug) {
|
|
1759
|
+
async function performLink(deps, projectId, mode2, slug, yes = false) {
|
|
1662
1760
|
if (!UUID_RE2.test(projectId)) {
|
|
1663
1761
|
throw new CliError(
|
|
1664
1762
|
`Invalid project ID: "${projectId}". Must be a UUID (e.g. 00000000-0000-0000-0000-000000000001).`,
|
|
@@ -1678,7 +1776,7 @@ async function performLink(deps, projectId, mode2, slug) {
|
|
|
1678
1776
|
token: deps.settings.token,
|
|
1679
1777
|
version: deps.version
|
|
1680
1778
|
});
|
|
1681
|
-
let projectName =
|
|
1779
|
+
let projectName = path10.basename(root);
|
|
1682
1780
|
if (deps.settings.token != null) {
|
|
1683
1781
|
try {
|
|
1684
1782
|
const result = await http.get(
|
|
@@ -1706,10 +1804,36 @@ Proceeding anyway \u2014 verify the ID is correct.
|
|
|
1706
1804
|
);
|
|
1707
1805
|
}
|
|
1708
1806
|
await writeRepoBinding(root, projectId);
|
|
1709
|
-
const writtenPath =
|
|
1807
|
+
const writtenPath = path10.join(root, "nolto.json");
|
|
1808
|
+
let repoAdded = false;
|
|
1710
1809
|
if (deps.settings.token == null) {
|
|
1711
1810
|
process.stderr.write("Warning: roadmap cache not initialized (no token); run nolto pull after nolto login\n");
|
|
1712
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";
|
|
1713
1837
|
await ensureRoadmapCache({
|
|
1714
1838
|
env: process.env,
|
|
1715
1839
|
http,
|
|
@@ -1717,7 +1841,7 @@ Proceeding anyway \u2014 verify the ID is correct.
|
|
|
1717
1841
|
projectName,
|
|
1718
1842
|
repoRoot: root,
|
|
1719
1843
|
slug,
|
|
1720
|
-
repoIdentity
|
|
1844
|
+
repoIdentity,
|
|
1721
1845
|
log: (line) => {
|
|
1722
1846
|
if (mode2 !== "json") process.stdout.write(line + "\n");
|
|
1723
1847
|
}
|
|
@@ -1730,6 +1854,10 @@ Proceeding anyway \u2014 verify the ID is correct.
|
|
|
1730
1854
|
} else {
|
|
1731
1855
|
try {
|
|
1732
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
|
+
}
|
|
1733
1861
|
} catch (err) {
|
|
1734
1862
|
const message = err instanceof Error ? err.message : String(err);
|
|
1735
1863
|
process.stderr.write(`Warning: could not update watch registry: ${message}
|
|
@@ -1741,7 +1869,8 @@ Proceeding anyway \u2014 verify the ID is correct.
|
|
|
1741
1869
|
linked: true,
|
|
1742
1870
|
projectId,
|
|
1743
1871
|
projectBindingPath: writtenPath,
|
|
1744
|
-
registryAdded
|
|
1872
|
+
registryAdded,
|
|
1873
|
+
repoAdded
|
|
1745
1874
|
}, mode2);
|
|
1746
1875
|
} else {
|
|
1747
1876
|
process.stdout.write(
|
|
@@ -1758,7 +1887,7 @@ Commit nolto.json to share the binding with your team.
|
|
|
1758
1887
|
function register2(program, deps) {
|
|
1759
1888
|
const cmd = program.command("link [projectId]").description(
|
|
1760
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"
|
|
1761
|
-
).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");
|
|
1762
1891
|
cmd.action(async (projectId) => {
|
|
1763
1892
|
const { output } = deps;
|
|
1764
1893
|
const projectBindingPath = deps.repoBinding?.path ?? deps.projectBindingPath ?? null;
|
|
@@ -1848,7 +1977,7 @@ function register2(program, deps) {
|
|
|
1848
1977
|
2
|
|
1849
1978
|
);
|
|
1850
1979
|
}
|
|
1851
|
-
await performLink(deps, projectId, mode2, opts["slug"]);
|
|
1980
|
+
await performLink(deps, projectId, mode2, opts["slug"], opts["yes"] === true);
|
|
1852
1981
|
});
|
|
1853
1982
|
}
|
|
1854
1983
|
function invalidBindingError(projectBindingPath, error) {
|
|
@@ -1861,33 +1990,33 @@ function invalidBindingError(projectBindingPath, error) {
|
|
|
1861
1990
|
// src/skill-install.ts
|
|
1862
1991
|
import { cp, mkdir as mkdir5, readFile as readFile7, writeFile as writeFile6, rm as rm2 } from "fs/promises";
|
|
1863
1992
|
import { existsSync as existsSync2 } from "fs";
|
|
1864
|
-
import
|
|
1993
|
+
import path11 from "path";
|
|
1865
1994
|
import { fileURLToPath } from "url";
|
|
1866
|
-
var __dirname =
|
|
1995
|
+
var __dirname = path11.dirname(fileURLToPath(import.meta.url));
|
|
1867
1996
|
function resolveSkillSourceDir() {
|
|
1868
1997
|
const candidates = [
|
|
1869
|
-
|
|
1998
|
+
path11.resolve(__dirname, "skill/roadmap-progress"),
|
|
1870
1999
|
// bundled: dist/skill/...
|
|
1871
|
-
|
|
2000
|
+
path11.resolve(__dirname, "../../../skills/roadmap-progress")
|
|
1872
2001
|
// source: <repo>/skills/...
|
|
1873
2002
|
];
|
|
1874
2003
|
for (const candidate of candidates) {
|
|
1875
|
-
if (existsSync2(
|
|
2004
|
+
if (existsSync2(path11.join(candidate, "SKILL.md"))) return candidate;
|
|
1876
2005
|
}
|
|
1877
2006
|
throw new Error("Bundled roadmap-progress skill not found. Reinstall @nolto/cli.");
|
|
1878
2007
|
}
|
|
1879
2008
|
var VERSION_MARKER = ".nolto-skill-version";
|
|
1880
2009
|
async function checkSkillVersionDrift(repoRoot, cliVersion) {
|
|
1881
2010
|
const skillDirs = [
|
|
1882
|
-
|
|
1883
|
-
|
|
2011
|
+
path11.join(repoRoot, ".claude", "skills", "roadmap-progress"),
|
|
2012
|
+
path11.join(repoRoot, ".agents", "skills", "roadmap-progress")
|
|
1884
2013
|
];
|
|
1885
2014
|
const drifted = [];
|
|
1886
2015
|
for (const dir of skillDirs) {
|
|
1887
2016
|
if (!existsSync2(dir)) continue;
|
|
1888
2017
|
let installed;
|
|
1889
2018
|
try {
|
|
1890
|
-
const marker = (await readFile7(
|
|
2019
|
+
const marker = (await readFile7(path11.join(dir, VERSION_MARKER), "utf8")).trim();
|
|
1891
2020
|
installed = marker.length > 0 ? marker : null;
|
|
1892
2021
|
} catch {
|
|
1893
2022
|
installed = null;
|
|
@@ -1897,13 +2026,13 @@ async function checkSkillVersionDrift(repoRoot, cliVersion) {
|
|
|
1897
2026
|
return drifted;
|
|
1898
2027
|
}
|
|
1899
2028
|
function formatSkillVersionDriftWarning(repoRoot, cliVersion, drifted) {
|
|
1900
|
-
const dirs = drifted.map(({ dir }) =>
|
|
2029
|
+
const dirs = drifted.map(({ dir }) => path11.relative(repoRoot, dir).split(path11.sep).join("/")).join(", ");
|
|
1901
2030
|
const installed = [...new Set(drifted.map((entry) => entry.installed ?? "unknown"))].join(", ");
|
|
1902
2031
|
return `roadmap-progress skill is outdated in ${dirs} (installed ${installed}, CLI ${cliVersion}). Run \`nolto init\` in this repo to update it.`;
|
|
1903
2032
|
}
|
|
1904
2033
|
async function installSkill(args) {
|
|
1905
|
-
const targetDir =
|
|
1906
|
-
const markerPath =
|
|
2034
|
+
const targetDir = path11.join(args.skillsParentDir, "roadmap-progress");
|
|
2035
|
+
const markerPath = path11.join(targetDir, VERSION_MARKER);
|
|
1907
2036
|
const dirExists = existsSync2(targetDir);
|
|
1908
2037
|
let installedVersion = null;
|
|
1909
2038
|
if (dirExists) {
|
|
@@ -1924,17 +2053,17 @@ async function installSkill(args) {
|
|
|
1924
2053
|
}
|
|
1925
2054
|
|
|
1926
2055
|
// src/commands/init.ts
|
|
1927
|
-
var __dirname2 =
|
|
2056
|
+
var __dirname2 = path12.dirname(fileURLToPath2(import.meta.url));
|
|
1928
2057
|
var _require = createRequire(import.meta.url);
|
|
1929
2058
|
function getCliVersion() {
|
|
1930
2059
|
const candidates = [
|
|
1931
|
-
|
|
2060
|
+
path12.resolve(__dirname2, "../package.json"),
|
|
1932
2061
|
// bundled: dist/../package.json
|
|
1933
|
-
|
|
2062
|
+
path12.resolve(__dirname2, "../../package.json")
|
|
1934
2063
|
// source: src/commands/../../package.json
|
|
1935
2064
|
];
|
|
1936
2065
|
for (const pkgPath of candidates) {
|
|
1937
|
-
if (
|
|
2066
|
+
if (fs2.existsSync(pkgPath)) {
|
|
1938
2067
|
try {
|
|
1939
2068
|
const pkg = _require(pkgPath);
|
|
1940
2069
|
return pkg.version ?? "0.0.0";
|
|
@@ -1944,7 +2073,7 @@ function getCliVersion() {
|
|
|
1944
2073
|
}
|
|
1945
2074
|
return "0.0.0";
|
|
1946
2075
|
}
|
|
1947
|
-
async function pickProject(rl, http, projects, promptText) {
|
|
2076
|
+
async function pickProject(rl, http, projects, promptText, baseUrl) {
|
|
1948
2077
|
if (projects.length > 0) {
|
|
1949
2078
|
process.stdout.write("\nProjects:\n");
|
|
1950
2079
|
projects.forEach((project, index) => {
|
|
@@ -1961,9 +2090,27 @@ async function pickProject(rl, http, projects, promptText) {
|
|
|
1961
2090
|
if (name.trim().length === 0) {
|
|
1962
2091
|
throw new CliError("Project name is required.", 2);
|
|
1963
2092
|
}
|
|
2093
|
+
const { orgs } = await http.get("/api/orgs/eligible");
|
|
2094
|
+
if (orgs.length === 0) {
|
|
2095
|
+
throw new CliError(`No organization to create the project in. Create one at ${baseUrl.replace(/\/+$/, "")}/orgs/new first.`, 2);
|
|
2096
|
+
}
|
|
2097
|
+
let organization = orgs[0];
|
|
2098
|
+
if (orgs.length > 1) {
|
|
2099
|
+
process.stdout.write("\nOrganizations:\n");
|
|
2100
|
+
orgs.forEach((org, index2) => {
|
|
2101
|
+
process.stdout.write(` (${index2 + 1}) ${org.name} \u2014 ${org.id}
|
|
2102
|
+
`);
|
|
2103
|
+
});
|
|
2104
|
+
const choice = (await rl.question("Organization number: ")).trim();
|
|
2105
|
+
const index = Number(choice);
|
|
2106
|
+
if (!/^\d+$/.test(choice) || !Number.isSafeInteger(index) || index < 1 || index > orgs.length) {
|
|
2107
|
+
throw new CliError("Invalid organization number.", 2);
|
|
2108
|
+
}
|
|
2109
|
+
organization = orgs[index - 1];
|
|
2110
|
+
}
|
|
1964
2111
|
const created = await http.post(
|
|
1965
2112
|
"/api/projects",
|
|
1966
|
-
{ name: name.trim() }
|
|
2113
|
+
{ name: name.trim(), orgId: organization.id }
|
|
1967
2114
|
);
|
|
1968
2115
|
if (created.project?.id == null) {
|
|
1969
2116
|
throw new CliError("Project API did not return a project id.", 2);
|
|
@@ -1972,7 +2119,7 @@ async function pickProject(rl, http, projects, promptText) {
|
|
|
1972
2119
|
id: created.project.id,
|
|
1973
2120
|
name: created.project.name ?? name.trim()
|
|
1974
2121
|
};
|
|
1975
|
-
process.stdout.write(`Created project ${project.name} (${project.id})
|
|
2122
|
+
process.stdout.write(`Created project ${project.name} (${project.id}) in ${organization.name}
|
|
1976
2123
|
`);
|
|
1977
2124
|
return project;
|
|
1978
2125
|
}
|
|
@@ -1982,7 +2129,7 @@ async function pickProject(rl, http, projects, promptText) {
|
|
|
1982
2129
|
}
|
|
1983
2130
|
return void 0;
|
|
1984
2131
|
}
|
|
1985
|
-
async function selectRepoProject(rl, http, projects, defaultProjectId) {
|
|
2132
|
+
async function selectRepoProject(rl, http, projects, defaultProjectId, baseUrl) {
|
|
1986
2133
|
const defaultProject = defaultProjectId == null ? void 0 : projects.find((project) => project.id === defaultProjectId);
|
|
1987
2134
|
if (defaultProject != null) {
|
|
1988
2135
|
const useDefault = await rl.question(
|
|
@@ -1996,7 +2143,8 @@ async function selectRepoProject(rl, http, projects, defaultProjectId) {
|
|
|
1996
2143
|
rl,
|
|
1997
2144
|
http,
|
|
1998
2145
|
projects,
|
|
1999
|
-
"Project number for this repository, 'c' to create new (or Enter to skip): "
|
|
2146
|
+
"Project number for this repository, 'c' to create new (or Enter to skip): ",
|
|
2147
|
+
baseUrl
|
|
2000
2148
|
);
|
|
2001
2149
|
}
|
|
2002
2150
|
function register3(program, deps) {
|
|
@@ -2054,7 +2202,8 @@ function register3(program, deps) {
|
|
|
2054
2202
|
rl,
|
|
2055
2203
|
http,
|
|
2056
2204
|
projects,
|
|
2057
|
-
"Default project number, 'c' to create new (or Enter to skip): "
|
|
2205
|
+
"Default project number, 'c' to create new (or Enter to skip): ",
|
|
2206
|
+
baseUrl
|
|
2058
2207
|
);
|
|
2059
2208
|
defaultProjectId = selected?.id;
|
|
2060
2209
|
defaultProjectName = selected?.name;
|
|
@@ -2091,7 +2240,7 @@ Saved ${configPath}
|
|
|
2091
2240
|
}
|
|
2092
2241
|
if (isHomeDirectory(root)) {
|
|
2093
2242
|
process.stderr.write(
|
|
2094
|
-
`Refusing to set up your home directory as a repository root (found ${
|
|
2243
|
+
`Refusing to set up your home directory as a repository root (found ${path12.join(os3.homedir(), ".git")}). Run nolto init inside a project repository.
|
|
2095
2244
|
`
|
|
2096
2245
|
);
|
|
2097
2246
|
return;
|
|
@@ -2123,9 +2272,9 @@ Saved ${configPath}
|
|
|
2123
2272
|
boundProject != null ? "Keep this binding? [Y/n] " : "Keep this binding? [y/N] "
|
|
2124
2273
|
);
|
|
2125
2274
|
keepExistingBinding = boundProject != null ? keep.trim().toLowerCase() !== "n" : keep.trim().toLowerCase() === "y";
|
|
2126
|
-
repoProject = keepExistingBinding ? boundProject ?? { id: existingBinding.projectId, name:
|
|
2275
|
+
repoProject = keepExistingBinding ? boundProject ?? { id: existingBinding.projectId, name: path12.basename(root) } : await selectRepoProject(rl, repoHttp, projects, defaultProjectId, baseUrl);
|
|
2127
2276
|
} else {
|
|
2128
|
-
repoProject = await selectRepoProject(rl, repoHttp, projects, defaultProjectId);
|
|
2277
|
+
repoProject = await selectRepoProject(rl, repoHttp, projects, defaultProjectId, baseUrl);
|
|
2129
2278
|
}
|
|
2130
2279
|
if (repoProject == null) {
|
|
2131
2280
|
process.stdout.write("Skipped repo setup (no project selected).\n");
|
|
@@ -2137,7 +2286,7 @@ Set up this repository (${root}) for roadmap sync? [Y/n] `);
|
|
|
2137
2286
|
process.stdout.write("Skipped repo setup.\n");
|
|
2138
2287
|
return;
|
|
2139
2288
|
}
|
|
2140
|
-
const bindingPath = deps.repoBinding?.path ??
|
|
2289
|
+
const bindingPath = deps.repoBinding?.path ?? path12.join(root, "nolto.json");
|
|
2141
2290
|
if (keepExistingBinding) {
|
|
2142
2291
|
process.stdout.write(`binding: kept ${bindingPath} (${repoProject.id})
|
|
2143
2292
|
`);
|
|
@@ -2149,40 +2298,61 @@ Set up this repository (${root}) for roadmap sync? [Y/n] `);
|
|
|
2149
2298
|
);
|
|
2150
2299
|
}
|
|
2151
2300
|
await writeRepoBinding(root, repoProject.id);
|
|
2152
|
-
process.stdout.write(`binding: wrote ${
|
|
2301
|
+
process.stdout.write(`binding: wrote ${path12.join(root, "nolto.json")}
|
|
2153
2302
|
`);
|
|
2154
2303
|
}
|
|
2155
2304
|
const sourceDir = resolveSkillSourceDir();
|
|
2156
2305
|
const version = getCliVersion();
|
|
2157
2306
|
const claudeInstall = await installSkill({
|
|
2158
|
-
skillsParentDir:
|
|
2307
|
+
skillsParentDir: path12.join(root, ".claude", "skills"),
|
|
2159
2308
|
sourceDir,
|
|
2160
2309
|
version
|
|
2161
2310
|
});
|
|
2162
2311
|
process.stdout.write(`skill (claude): ${claudeInstall.action} ${claudeInstall.targetDir}
|
|
2163
2312
|
`);
|
|
2164
|
-
const usesAgentsTooling =
|
|
2313
|
+
const usesAgentsTooling = fs2.existsSync(path12.join(root, ".agents")) || fs2.existsSync(path12.join(root, ".codex")) || fs2.existsSync(path12.join(root, "AGENTS.md"));
|
|
2165
2314
|
if (usesAgentsTooling) {
|
|
2166
2315
|
const agentsInstall = await installSkill({
|
|
2167
|
-
skillsParentDir:
|
|
2316
|
+
skillsParentDir: path12.join(root, ".agents", "skills"),
|
|
2168
2317
|
sourceDir,
|
|
2169
2318
|
version
|
|
2170
2319
|
});
|
|
2171
2320
|
process.stdout.write(`skill (agents): ${agentsInstall.action} ${agentsInstall.targetDir}
|
|
2172
2321
|
`);
|
|
2173
2322
|
}
|
|
2323
|
+
const repoIdentity = await makeRepoIdentityResolver(deps)(root);
|
|
2324
|
+
const repoResult = await ensureProjectRepo({
|
|
2325
|
+
http: repoHttp,
|
|
2326
|
+
projectId: repoProject.id,
|
|
2327
|
+
repoIdentity,
|
|
2328
|
+
confirm: async (question) => {
|
|
2329
|
+
const answer = (await rl.question(question)).trim().toLowerCase();
|
|
2330
|
+
return answer === "" || answer === "y" || answer === "yes";
|
|
2331
|
+
},
|
|
2332
|
+
log: (line) => {
|
|
2333
|
+
process.stdout.write(line + "\n");
|
|
2334
|
+
}
|
|
2335
|
+
});
|
|
2336
|
+
if (repoResult === "declined") {
|
|
2337
|
+
process.stdout.write("Skipped adding this repository. Run `nolto link --add` later; roadmap sync will fail until then.\n");
|
|
2338
|
+
return;
|
|
2339
|
+
}
|
|
2174
2340
|
await ensureRoadmapCache({
|
|
2175
2341
|
env: process.env,
|
|
2176
2342
|
http: repoHttp,
|
|
2177
2343
|
projectId: repoProject.id,
|
|
2178
2344
|
projectName: repoProject.name,
|
|
2179
2345
|
repoRoot: root,
|
|
2180
|
-
repoIdentity
|
|
2346
|
+
repoIdentity,
|
|
2181
2347
|
log: (line) => {
|
|
2182
2348
|
process.stdout.write(line + "\n");
|
|
2183
2349
|
}
|
|
2184
2350
|
});
|
|
2185
2351
|
const registryResult = await addRepoToRegistry(getRegistryPath(process.env), { root, projectId: repoProject.id });
|
|
2352
|
+
if (registryResult.added) {
|
|
2353
|
+
const warning = await staleWatchWarning(process.env, deps.version, process.kill);
|
|
2354
|
+
if (warning) process.stderr.write(warning + "\n");
|
|
2355
|
+
}
|
|
2186
2356
|
process.stdout.write(
|
|
2187
2357
|
registryResult.added ? `watch registry: added ${root}
|
|
2188
2358
|
` : `watch registry: already registered
|
|
@@ -2425,7 +2595,7 @@ import { readFile as readFile8, realpath as realpath2 } from "fs/promises";
|
|
|
2425
2595
|
import { existsSync as existsSync3 } from "fs";
|
|
2426
2596
|
|
|
2427
2597
|
// src/roadmap-read.ts
|
|
2428
|
-
import
|
|
2598
|
+
import path13 from "path";
|
|
2429
2599
|
async function resolveRoadmapReadContext(deps) {
|
|
2430
2600
|
if (deps.settings.token == null) {
|
|
2431
2601
|
throw new CliError("Not authenticated. Run `nolto login` or set NOLTO_TOKEN.", 3);
|
|
@@ -2435,7 +2605,7 @@ async function resolveRoadmapReadContext(deps) {
|
|
|
2435
2605
|
if (!foundGit) {
|
|
2436
2606
|
throw new CliError("No git repository found. Run inside a repo set up with `nolto init`.", 2);
|
|
2437
2607
|
}
|
|
2438
|
-
const binding = await loadRepoBinding(
|
|
2608
|
+
const binding = await loadRepoBinding(path13.join(root, "nolto.json"));
|
|
2439
2609
|
const projectId = binding?.projectId ?? deps.settings.defaultProjectId;
|
|
2440
2610
|
if (projectId == null) {
|
|
2441
2611
|
throw new CliError("No project binding. Run `nolto init` or `nolto link <projectId>`.", 2);
|
|
@@ -2491,15 +2661,15 @@ async function collectGitLinks(root, exec) {
|
|
|
2491
2661
|
}
|
|
2492
2662
|
|
|
2493
2663
|
// src/sync-repo.ts
|
|
2494
|
-
import
|
|
2664
|
+
import path14 from "path";
|
|
2495
2665
|
import { readdir as readdir3 } from "fs/promises";
|
|
2496
2666
|
function collectContainedPlanAbsPaths(roadmaps, root, warn2) {
|
|
2497
2667
|
const planAbsPaths = /* @__PURE__ */ new Set();
|
|
2498
|
-
const resolvedRoot =
|
|
2668
|
+
const resolvedRoot = path14.resolve(root);
|
|
2499
2669
|
for (const roadmap of roadmaps) {
|
|
2500
2670
|
for (const ref of collectPlanRefs(roadmap)) {
|
|
2501
|
-
const absolute =
|
|
2502
|
-
if (absolute !== resolvedRoot && !absolute.startsWith(resolvedRoot +
|
|
2671
|
+
const absolute = path14.resolve(resolvedRoot, ref.path);
|
|
2672
|
+
if (absolute !== resolvedRoot && !absolute.startsWith(resolvedRoot + path14.sep)) {
|
|
2503
2673
|
warn2(`chokidar target outside repo, skipping: ${ref.path}`);
|
|
2504
2674
|
continue;
|
|
2505
2675
|
}
|
|
@@ -2520,7 +2690,7 @@ async function syncRepo(args, io) {
|
|
|
2520
2690
|
if (slugs.length === 0) {
|
|
2521
2691
|
let legacyFiles = [];
|
|
2522
2692
|
try {
|
|
2523
|
-
legacyFiles = await readdir3(
|
|
2693
|
+
legacyFiles = await readdir3(path14.join(args.root, ".nolto", "roadmaps"));
|
|
2524
2694
|
} catch (err) {
|
|
2525
2695
|
if (err.code !== "ENOENT") throw err;
|
|
2526
2696
|
}
|
|
@@ -2654,6 +2824,10 @@ async function runSyncCommand(deps, opts = {}) {
|
|
|
2654
2824
|
} else {
|
|
2655
2825
|
try {
|
|
2656
2826
|
registryAdded = (await addRepoToRegistry(getRegistryPath(process.env), { root, projectId })).added;
|
|
2827
|
+
if (registryAdded) {
|
|
2828
|
+
const warning = await staleWatchWarning(process.env, deps.version, process.kill);
|
|
2829
|
+
if (warning) process.stderr.write(warning + "\n");
|
|
2830
|
+
}
|
|
2657
2831
|
} catch (err) {
|
|
2658
2832
|
const message = err instanceof Error ? err.message : String(err);
|
|
2659
2833
|
process.stderr.write(`Warning: could not update watch registry: ${message}
|
|
@@ -2837,10 +3011,10 @@ function register7(program, deps) {
|
|
|
2837
3011
|
}
|
|
2838
3012
|
|
|
2839
3013
|
// src/roadmap-commands.ts
|
|
2840
|
-
import
|
|
3014
|
+
import path15 from "path";
|
|
2841
3015
|
import { existsSync as existsSync4 } from "fs";
|
|
2842
3016
|
import { readFile as readFile9, readdir as readdir4, writeFile as writeFile7, rename as rename4, unlink as unlink3, realpath as realpath3 } from "fs/promises";
|
|
2843
|
-
import { randomUUID as
|
|
3017
|
+
import { randomUUID as randomUUID6 } from "crypto";
|
|
2844
3018
|
import readline4 from "readline/promises";
|
|
2845
3019
|
|
|
2846
3020
|
// src/commands/pull.ts
|
|
@@ -2908,7 +3082,7 @@ async function selectRoadmap(deps, requestedSlug) {
|
|
|
2908
3082
|
}
|
|
2909
3083
|
async function roadmapPath(deps, slug) {
|
|
2910
3084
|
const { paths } = await selectRoadmap(deps, slug);
|
|
2911
|
-
printResult(
|
|
3085
|
+
printResult(path15.resolve(paths.json), deps.output.mode);
|
|
2912
3086
|
}
|
|
2913
3087
|
async function roadmapStatus(deps, slug, fresh = false) {
|
|
2914
3088
|
const selected = await selectRoadmap(deps, slug);
|
|
@@ -2917,12 +3091,12 @@ async function roadmapStatus(deps, slug, fresh = false) {
|
|
|
2917
3091
|
const { roadmap, meta } = entry;
|
|
2918
3092
|
const stats = deriveTaskStats(roadmap);
|
|
2919
3093
|
const tasks = roadmap.phases.flatMap((phase) => phase.tasks);
|
|
2920
|
-
const current = tasks.find((task) => task.id === meta?.currentTaskId);
|
|
3094
|
+
const current = tasks.find((task) => task.id === meta?.currentTaskId && task.status === "in-progress");
|
|
2921
3095
|
const blocked = tasks.filter((task) => task.status === "blocked");
|
|
2922
3096
|
const age = meta ? (Date.now() - Date.parse(meta.pulledAt)) / 6e4 : NaN;
|
|
2923
3097
|
if (age > 10) warn(`Warning: cache is ${Math.floor(age)} minutes old; run with --fresh or nolto roadmap pull`);
|
|
2924
3098
|
if (deps.output.mode === "json") {
|
|
2925
|
-
printResult({ roadmap, stats, currentTaskId:
|
|
3099
|
+
printResult({ roadmap, stats, currentTaskId: current?.id ?? null, revision: meta?.revision ?? 0, pulledAt: meta?.pulledAt ?? null }, "json");
|
|
2926
3100
|
return;
|
|
2927
3101
|
}
|
|
2928
3102
|
printResult([
|
|
@@ -2953,7 +3127,7 @@ async function roadmapSummary(deps, slug, text) {
|
|
|
2953
3127
|
const selected = await selectRoadmap(deps, slug);
|
|
2954
3128
|
const entry = await readCache(process.env, selected.projectId, selected.slug);
|
|
2955
3129
|
entry.roadmap.summary = text;
|
|
2956
|
-
const temp = `${selected.paths.json}.tmp-${
|
|
3130
|
+
const temp = `${selected.paths.json}.tmp-${randomUUID6()}`;
|
|
2957
3131
|
try {
|
|
2958
3132
|
await writeFile7(temp, serializeRoadmap(entry.roadmap), { mode: 384 });
|
|
2959
3133
|
await rename4(temp, selected.paths.json);
|
|
@@ -2987,8 +3161,8 @@ async function roadmapTask(deps, taskId, slug, body) {
|
|
|
2987
3161
|
const selected = await selectRoadmap(deps, slug);
|
|
2988
3162
|
if (body.status === "blocked" && !body.note?.trim()) throw new CliError("block requires a non-empty --note.", 2);
|
|
2989
3163
|
if (body.plan !== void 0) {
|
|
2990
|
-
const absolute =
|
|
2991
|
-
if (!isValidPlanPath(body.plan) || !absolute.startsWith(
|
|
3164
|
+
const absolute = path15.resolve(selected.root, body.plan);
|
|
3165
|
+
if (!isValidPlanPath(body.plan) || !absolute.startsWith(path15.resolve(selected.root) + path15.sep)) {
|
|
2992
3166
|
throw new CliError("plan must be a repository-relative path without . or .. segments.", 2);
|
|
2993
3167
|
}
|
|
2994
3168
|
if (!existsSync4(absolute)) warn(`WARN plan file not found at ${absolute}`);
|
|
@@ -3010,7 +3184,7 @@ async function roadmapEvents(deps, slug, opts) {
|
|
|
3010
3184
|
}
|
|
3011
3185
|
async function roadmapMigrate(deps, yes = false) {
|
|
3012
3186
|
const { root, projectId } = await resolveRoadmapReadContext(deps);
|
|
3013
|
-
const dir =
|
|
3187
|
+
const dir = path15.join(root, ".nolto", "roadmaps");
|
|
3014
3188
|
let files;
|
|
3015
3189
|
try {
|
|
3016
3190
|
files = (await readdir4(dir, { withFileTypes: true })).filter((file) => file.isFile() && file.name.endsWith(".json")).map((file) => file.name).sort();
|
|
@@ -3026,7 +3200,7 @@ async function roadmapMigrate(deps, yes = false) {
|
|
|
3026
3200
|
for (const file of files) {
|
|
3027
3201
|
const slug = file.slice(0, -5);
|
|
3028
3202
|
cachePaths(process.env, projectId, slug);
|
|
3029
|
-
const roadmap = await loadValidRoadmap(
|
|
3203
|
+
const roadmap = await loadValidRoadmap(path15.join(dir, file), (p) => readFile9(p, "utf8"));
|
|
3030
3204
|
roadmap.schemaVersion = 3;
|
|
3031
3205
|
delete roadmap.updatedAt;
|
|
3032
3206
|
delete roadmap.currentTaskId;
|
|
@@ -3076,7 +3250,7 @@ async function roadmapMigrate(deps, yes = false) {
|
|
|
3076
3250
|
const nextSteps = ["Next steps (run yourself):", " git rm -r .nolto/roadmaps"];
|
|
3077
3251
|
let attributes = "";
|
|
3078
3252
|
try {
|
|
3079
|
-
attributes = await readFile9(
|
|
3253
|
+
attributes = await readFile9(path15.join(root, ".gitattributes"), "utf8");
|
|
3080
3254
|
} catch (error) {
|
|
3081
3255
|
if (error.code !== "ENOENT") throw error;
|
|
3082
3256
|
}
|
|
@@ -3084,7 +3258,11 @@ async function roadmapMigrate(deps, yes = false) {
|
|
|
3084
3258
|
nextSteps.push(' # remove the ".nolto/roadmaps/*.json merge=nolto-roadmap" line from .gitattributes');
|
|
3085
3259
|
}
|
|
3086
3260
|
nextSteps.push(" git config --unset-all merge.nolto-roadmap.name; git config --unset-all merge.nolto-roadmap.driver");
|
|
3087
|
-
await addRepoToRegistry(getRegistryPath(process.env), { root, projectId });
|
|
3261
|
+
const { added } = await addRepoToRegistry(getRegistryPath(process.env), { root, projectId });
|
|
3262
|
+
if (added) {
|
|
3263
|
+
const warning = await staleWatchWarning(process.env, deps.version, process.kill);
|
|
3264
|
+
if (warning) process.stderr.write(warning + "\n");
|
|
3265
|
+
}
|
|
3088
3266
|
printResult(deps.output.mode === "json" ? { results, nextSteps } : nextSteps.join("\n"), deps.output.mode);
|
|
3089
3267
|
}
|
|
3090
3268
|
|
|
@@ -3099,9 +3277,9 @@ function register9(program, deps) {
|
|
|
3099
3277
|
roadmap.command("summary [slug]").description("Replace the summary and sync").requiredOption("--text <text>", "New summary").action((slug, opts) => roadmapSummary(deps, slug, opts.text));
|
|
3100
3278
|
const bodies = {
|
|
3101
3279
|
start: { status: "in-progress", currentTask: true },
|
|
3102
|
-
done: { status: "done" },
|
|
3103
|
-
block: { status: "blocked" },
|
|
3104
|
-
todo: { status: "todo", startedAt: null, completedAt: null }
|
|
3280
|
+
done: { status: "done", currentTask: false },
|
|
3281
|
+
block: { status: "blocked", currentTask: false },
|
|
3282
|
+
todo: { status: "todo", currentTask: false, startedAt: null, completedAt: null }
|
|
3105
3283
|
};
|
|
3106
3284
|
for (const [name, body] of Object.entries(bodies)) {
|
|
3107
3285
|
const command = roadmap.command(`${name} <task>`).description(`Set task status to ${body.status}`).option("--slug <slug>", "Roadmap slug (required with multiple cached roadmaps)");
|
|
@@ -3122,11 +3300,11 @@ import { execFile as execFile3 } from "child_process";
|
|
|
3122
3300
|
import { promisify as promisify2 } from "util";
|
|
3123
3301
|
import { readFile as readFile10, realpath as realpath4 } from "fs/promises";
|
|
3124
3302
|
import { existsSync as existsSync5, mkdirSync } from "fs";
|
|
3125
|
-
import
|
|
3303
|
+
import path18 from "path";
|
|
3126
3304
|
import chokidar from "chokidar";
|
|
3127
3305
|
|
|
3128
3306
|
// src/watch-core.ts
|
|
3129
|
-
import
|
|
3307
|
+
import path16 from "path";
|
|
3130
3308
|
var WatchSet = class {
|
|
3131
3309
|
constructor(deps) {
|
|
3132
3310
|
this.deps = deps;
|
|
@@ -3175,7 +3353,7 @@ async function reloadRoots(deps) {
|
|
|
3175
3353
|
continue;
|
|
3176
3354
|
}
|
|
3177
3355
|
try {
|
|
3178
|
-
const projectId = repo.projectId ?? (await loadRepoBinding(
|
|
3356
|
+
const projectId = repo.projectId ?? (await loadRepoBinding(path16.join(repo.root, "nolto.json")))?.projectId;
|
|
3179
3357
|
if (projectId) repos.push({ root: repo.root, projectId });
|
|
3180
3358
|
else deps.warn(`registered repo has no project binding, skipping: ${repo.root}`);
|
|
3181
3359
|
} catch (err) {
|
|
@@ -3246,7 +3424,7 @@ var RepoWatch = class {
|
|
|
3246
3424
|
};
|
|
3247
3425
|
|
|
3248
3426
|
// src/service-install.ts
|
|
3249
|
-
import
|
|
3427
|
+
import path17 from "path";
|
|
3250
3428
|
import os4 from "os";
|
|
3251
3429
|
function buildUnitFile(args) {
|
|
3252
3430
|
return [
|
|
@@ -3266,8 +3444,8 @@ function buildUnitFile(args) {
|
|
|
3266
3444
|
}
|
|
3267
3445
|
function getUnitPath(env) {
|
|
3268
3446
|
const xdg = env["XDG_CONFIG_HOME"];
|
|
3269
|
-
const base = xdg != null && xdg.length > 0 ? xdg :
|
|
3270
|
-
return
|
|
3447
|
+
const base = xdg != null && xdg.length > 0 ? xdg : path17.join(os4.homedir(), ".config");
|
|
3448
|
+
return path17.join(base, "systemd", "user", "nolto-watch.service");
|
|
3271
3449
|
}
|
|
3272
3450
|
async function installServiceWith(deps) {
|
|
3273
3451
|
if (deps.platform !== "linux") {
|
|
@@ -3278,7 +3456,7 @@ async function installServiceWith(deps) {
|
|
|
3278
3456
|
);
|
|
3279
3457
|
}
|
|
3280
3458
|
const unitPath = getUnitPath(deps.env);
|
|
3281
|
-
await deps.mkdir(
|
|
3459
|
+
await deps.mkdir(path17.dirname(unitPath));
|
|
3282
3460
|
await deps.writeFile(unitPath, buildUnitFile({ nodePath: deps.nodePath, scriptPath: deps.scriptPath }));
|
|
3283
3461
|
deps.log(`Wrote ${unitPath}`);
|
|
3284
3462
|
const reload = await deps.exec(["systemctl", "--user", "daemon-reload"]);
|
|
@@ -3300,7 +3478,7 @@ async function installService() {
|
|
|
3300
3478
|
platform: process.platform,
|
|
3301
3479
|
env: process.env,
|
|
3302
3480
|
nodePath: process.execPath,
|
|
3303
|
-
scriptPath:
|
|
3481
|
+
scriptPath: path17.resolve(process.argv[1] ?? ""),
|
|
3304
3482
|
writeFile: (p, content) => writeFile10(p, content, "utf8"),
|
|
3305
3483
|
mkdir: async (p) => {
|
|
3306
3484
|
await mkdir7(p, { recursive: true });
|
|
@@ -3378,10 +3556,23 @@ async function uninstallService() {
|
|
|
3378
3556
|
warn: (line) => process.stderr.write("Warning: " + line + "\n")
|
|
3379
3557
|
});
|
|
3380
3558
|
}
|
|
3559
|
+
async function stopServiceWith(deps) {
|
|
3560
|
+
if (deps.platform !== "linux") {
|
|
3561
|
+
throw new CliError("Stopping the watch service requires systemd and is only supported on Linux.", 2);
|
|
3562
|
+
}
|
|
3563
|
+
const result = await deps.exec(["systemctl", "--user", "stop", "nolto-watch"]);
|
|
3564
|
+
if (result.code !== 0) {
|
|
3565
|
+
throw new CliError(
|
|
3566
|
+
`Could not stop the watch service: ${result.stderr}`,
|
|
3567
|
+
2,
|
|
3568
|
+
"Run `systemctl --user stop nolto-watch` manually."
|
|
3569
|
+
);
|
|
3570
|
+
}
|
|
3571
|
+
}
|
|
3381
3572
|
|
|
3382
3573
|
// src/commands/watch.ts
|
|
3383
3574
|
function register10(program, deps) {
|
|
3384
|
-
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) => {
|
|
3575
|
+
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) => {
|
|
3385
3576
|
if (opts.installService && opts.uninstallService) {
|
|
3386
3577
|
throw new CliError("--install-service and --uninstall-service cannot be used together.", 2);
|
|
3387
3578
|
}
|
|
@@ -3400,6 +3591,15 @@ function register10(program, deps) {
|
|
|
3400
3591
|
if (Number.isNaN(debounceMs) || debounceMs < 0) {
|
|
3401
3592
|
throw new CliError("--debounce must be a non-negative integer.", 2);
|
|
3402
3593
|
}
|
|
3594
|
+
const statePath = getWatchStatePath(process.env);
|
|
3595
|
+
const previous = await readWatchState(statePath);
|
|
3596
|
+
if (previous && previous.pid !== process.pid && isAlive(previous.pid)) {
|
|
3597
|
+
throw new CliError(
|
|
3598
|
+
`nolto watch is already running (pid ${previous.pid}, v${previous.version}).`,
|
|
3599
|
+
2,
|
|
3600
|
+
"Run `nolto watch stop` first."
|
|
3601
|
+
);
|
|
3602
|
+
}
|
|
3403
3603
|
const registryPath = getRegistryPath(process.env);
|
|
3404
3604
|
const roots = await reloadRoots({
|
|
3405
3605
|
load: () => loadRegistry(registryPath),
|
|
@@ -3420,7 +3620,7 @@ function register10(program, deps) {
|
|
|
3420
3620
|
const startRepo = ({ root, projectId }) => {
|
|
3421
3621
|
const roadmapsPath = cacheDir(process.env, projectId);
|
|
3422
3622
|
const warn2 = (line) => {
|
|
3423
|
-
process.stderr.write(line.startsWith(" ") ? line + "\n" : `Warning: [${
|
|
3623
|
+
process.stderr.write(line.startsWith(" ") ? line + "\n" : `Warning: [${path18.basename(root)}] ${line}
|
|
3424
3624
|
`);
|
|
3425
3625
|
};
|
|
3426
3626
|
mkdirSync(roadmapsPath, { recursive: true, mode: 448 });
|
|
@@ -3437,7 +3637,7 @@ function register10(program, deps) {
|
|
|
3437
3637
|
exec: promisify2(execFile3),
|
|
3438
3638
|
gitLinks: process.env.NOLTO_GIT_LINKS !== "0",
|
|
3439
3639
|
http,
|
|
3440
|
-
log: (line) => process.stdout.write(`[${
|
|
3640
|
+
log: (line) => process.stdout.write(`[${path18.basename(root)}] ${line}
|
|
3441
3641
|
`),
|
|
3442
3642
|
warn: warn2
|
|
3443
3643
|
}
|
|
@@ -3450,7 +3650,7 @@ function register10(program, deps) {
|
|
|
3450
3650
|
warn: (line) => process.stderr.write(line + "\n")
|
|
3451
3651
|
});
|
|
3452
3652
|
watcher.on("all", (_event, filePath) => {
|
|
3453
|
-
if (
|
|
3653
|
+
if (path18.dirname(filePath) === roadmapsPath && !filePath.endsWith(".json")) return;
|
|
3454
3654
|
repoWatch.handleEvent(filePath);
|
|
3455
3655
|
});
|
|
3456
3656
|
void checkSkillVersionDrift(root, deps.version).then((drifted) => {
|
|
@@ -3467,6 +3667,12 @@ function register10(program, deps) {
|
|
|
3467
3667
|
log: (line) => process.stdout.write(line + "\n")
|
|
3468
3668
|
});
|
|
3469
3669
|
await watchSet.reconcile(roots);
|
|
3670
|
+
try {
|
|
3671
|
+
await writeWatchState(statePath, { pid: process.pid, version: deps.version, startedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
3672
|
+
} catch (error) {
|
|
3673
|
+
await watchSet.stopAll();
|
|
3674
|
+
throw error;
|
|
3675
|
+
}
|
|
3470
3676
|
const registryWatcher = chokidar.watch(registryPath, { ignoreInitial: true });
|
|
3471
3677
|
let registryReloadTimer = null;
|
|
3472
3678
|
registryWatcher.on("all", () => {
|
|
@@ -3493,13 +3699,84 @@ function register10(program, deps) {
|
|
|
3493
3699
|
`);
|
|
3494
3700
|
await new Promise((resolve) => {
|
|
3495
3701
|
const stop = () => {
|
|
3702
|
+
process.removeListener("SIGINT", stop);
|
|
3703
|
+
process.removeListener("SIGTERM", stop);
|
|
3496
3704
|
if (registryReloadTimer != null) clearTimeout(registryReloadTimer);
|
|
3497
|
-
void Promise.all([registryWatcher.close(), watchSet.stopAll()]).
|
|
3705
|
+
void Promise.all([registryWatcher.close(), watchSet.stopAll()]).finally(() => removeWatchState(statePath, process.pid)).finally(resolve);
|
|
3498
3706
|
};
|
|
3499
3707
|
process.once("SIGINT", stop);
|
|
3500
3708
|
process.once("SIGTERM", stop);
|
|
3501
3709
|
});
|
|
3502
3710
|
});
|
|
3711
|
+
watch.addHelpText("after", "\nstop leaves the service installed for the next login; use --uninstall-service to remove it permanently.");
|
|
3712
|
+
watch.command("status").description("Show watch process and service status.").action(async () => {
|
|
3713
|
+
const state = await readWatchState(getWatchStatePath(process.env));
|
|
3714
|
+
const running = state !== null && isAlive(state.pid);
|
|
3715
|
+
const result = {
|
|
3716
|
+
running,
|
|
3717
|
+
pid: running ? state.pid : null,
|
|
3718
|
+
version: running ? state.version : null,
|
|
3719
|
+
startedAt: running ? state.startedAt : null,
|
|
3720
|
+
stale: running && state.version !== deps.version,
|
|
3721
|
+
service: existsSync5(getUnitPath(process.env)) ? "installed" : "not-installed"
|
|
3722
|
+
};
|
|
3723
|
+
printResult(deps.output.mode === "json" ? result : `${running ? "running" : "not running"}
|
|
3724
|
+
service: ${result.service}
|
|
3725
|
+
pid: ${result.pid ?? "\u2014"}
|
|
3726
|
+
version: ${result.version ?? "\u2014"}
|
|
3727
|
+
startedAt: ${result.startedAt ?? "\u2014"}
|
|
3728
|
+
stale: ${result.stale}`, deps.output.mode);
|
|
3729
|
+
});
|
|
3730
|
+
watch.command("stop").description("Stop watch without disabling the installed service.").action(async () => {
|
|
3731
|
+
const statePath = getWatchStatePath(process.env);
|
|
3732
|
+
const state = await readWatchState(statePath);
|
|
3733
|
+
const service = existsSync5(getUnitPath(process.env));
|
|
3734
|
+
let via = null;
|
|
3735
|
+
if (service) {
|
|
3736
|
+
await stopServiceWith({
|
|
3737
|
+
platform: process.platform,
|
|
3738
|
+
exec: async (cmd) => {
|
|
3739
|
+
try {
|
|
3740
|
+
await promisify2(execFile3)(cmd[0], cmd.slice(1));
|
|
3741
|
+
return { code: 0, stderr: "" };
|
|
3742
|
+
} catch (error) {
|
|
3743
|
+
const e = error;
|
|
3744
|
+
return { code: e.code ?? 1, stderr: e.stderr ?? String(error) };
|
|
3745
|
+
}
|
|
3746
|
+
}
|
|
3747
|
+
});
|
|
3748
|
+
via = "systemd";
|
|
3749
|
+
}
|
|
3750
|
+
if (state && isAlive(state.pid)) {
|
|
3751
|
+
try {
|
|
3752
|
+
process.kill(state.pid, "SIGTERM");
|
|
3753
|
+
} catch (error) {
|
|
3754
|
+
if (error.code !== "ESRCH") {
|
|
3755
|
+
throw new CliError(`Could not stop nolto watch (pid ${state.pid}): ${String(error)}`, 2);
|
|
3756
|
+
}
|
|
3757
|
+
}
|
|
3758
|
+
via ??= "signal";
|
|
3759
|
+
}
|
|
3760
|
+
if (state) {
|
|
3761
|
+
for (let attempt = 0; attempt < 50 && isAlive(state.pid); attempt++) {
|
|
3762
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
3763
|
+
}
|
|
3764
|
+
if (isAlive(state.pid)) throw new CliError(`nolto watch (pid ${state.pid}) did not stop within 5 seconds.`, 2);
|
|
3765
|
+
await removeWatchState(statePath, state.pid);
|
|
3766
|
+
}
|
|
3767
|
+
printResult(deps.output.mode === "json" ? { stopped: via !== null, via } : via === null ? "not running" : `Stopped nolto watch via ${via}.`, deps.output.mode);
|
|
3768
|
+
});
|
|
3769
|
+
watch.command("list").description("List repositories in the watch registry.").action(async () => {
|
|
3770
|
+
const registry = await loadRegistry(getRegistryPath(process.env));
|
|
3771
|
+
const repos = registry.repos.map((repo) => ({ root: repo.root, projectId: repo.projectId ?? null, exists: existsSync5(repo.root) }));
|
|
3772
|
+
printResult(deps.output.mode === "json" ? { repos } : repos.map((repo) => `${repo.root} ${repo.projectId ?? "\u2014"}${repo.exists ? "" : " (missing)"}`).join("\n"), deps.output.mode);
|
|
3773
|
+
});
|
|
3774
|
+
watch.command("remove [root]").description("Remove a repository from the watch registry.").action(async (arg) => {
|
|
3775
|
+
const root = arg === void 0 ? findRepoRoot(resolveStartDir(process.env, process.cwd())).root : path18.resolve(arg);
|
|
3776
|
+
const { removed } = await removeRepoFromRegistry(getRegistryPath(process.env), root);
|
|
3777
|
+
if (!removed) throw new CliError(`${root} is not in the watch registry.`, 2, "Run `nolto watch list` to see registered repositories.");
|
|
3778
|
+
printResult(deps.output.mode === "json" ? { removed: true, root } : `Removed ${root} from the watch registry.`, deps.output.mode);
|
|
3779
|
+
});
|
|
3503
3780
|
}
|
|
3504
3781
|
|
|
3505
3782
|
// src/update-cli.ts
|
|
@@ -3507,14 +3784,14 @@ import { execFile as execFile4 } from "child_process";
|
|
|
3507
3784
|
import { existsSync as existsSync6 } from "fs";
|
|
3508
3785
|
import { realpath as realpath5 } from "fs/promises";
|
|
3509
3786
|
import { createRequire as createRequire2 } from "module";
|
|
3510
|
-
import
|
|
3787
|
+
import path20 from "path";
|
|
3511
3788
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
3512
3789
|
import { promisify as promisify3 } from "util";
|
|
3513
3790
|
|
|
3514
3791
|
// src/update-notifier.ts
|
|
3515
3792
|
import { readFile as readFile11, writeFile as writeFile8, mkdir as mkdir6 } from "fs/promises";
|
|
3516
3793
|
import https from "https";
|
|
3517
|
-
import
|
|
3794
|
+
import path19 from "path";
|
|
3518
3795
|
var PACKAGE = "@nolto/cli";
|
|
3519
3796
|
var CACHE_FILE = "update-check.json";
|
|
3520
3797
|
var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
@@ -3572,7 +3849,7 @@ function fetchLatestFromRegistry(timeoutMs = REQUEST_TIMEOUT_MS, opts = {}) {
|
|
|
3572
3849
|
});
|
|
3573
3850
|
}
|
|
3574
3851
|
async function writeUpdateCache(cachePath, now, latest2) {
|
|
3575
|
-
await mkdir6(
|
|
3852
|
+
await mkdir6(path19.dirname(cachePath), { recursive: true });
|
|
3576
3853
|
const payload = { checkedAt: now, latest: latest2 };
|
|
3577
3854
|
await writeFile8(cachePath, JSON.stringify(payload), { mode: 384 });
|
|
3578
3855
|
}
|
|
@@ -3583,7 +3860,7 @@ async function refreshCache(cachePath, now, fetchLatest) {
|
|
|
3583
3860
|
}
|
|
3584
3861
|
async function checkForUpdate(opts) {
|
|
3585
3862
|
if (isDisabled(opts.env)) return null;
|
|
3586
|
-
const cachePath =
|
|
3863
|
+
const cachePath = path19.join(opts.configDir, CACHE_FILE);
|
|
3587
3864
|
let cache = {};
|
|
3588
3865
|
try {
|
|
3589
3866
|
cache = JSON.parse(await readFile11(cachePath, "utf8"));
|
|
@@ -3691,7 +3968,7 @@ async function updateCliWith(deps) {
|
|
|
3691
3968
|
}
|
|
3692
3969
|
deps.log(`Updated ${PACKAGE2} ${deps.currentVersion} \u2192 ${latest2}.`);
|
|
3693
3970
|
await deps.writeCache(
|
|
3694
|
-
|
|
3971
|
+
path20.join(deps.configDir, UPDATE_CACHE_FILE),
|
|
3695
3972
|
deps.now,
|
|
3696
3973
|
latest2
|
|
3697
3974
|
).catch(() => void 0);
|
|
@@ -3722,10 +3999,10 @@ async function updateCliWith(deps) {
|
|
|
3722
3999
|
};
|
|
3723
4000
|
}
|
|
3724
4001
|
function getCurrentVersion() {
|
|
3725
|
-
const dirname =
|
|
4002
|
+
const dirname = path20.dirname(fileURLToPath3(import.meta.url));
|
|
3726
4003
|
const require3 = createRequire2(import.meta.url);
|
|
3727
4004
|
try {
|
|
3728
|
-
const pkg = require3(
|
|
4005
|
+
const pkg = require3(path20.resolve(dirname, "../package.json"));
|
|
3729
4006
|
return pkg.version ?? "0.0.0";
|
|
3730
4007
|
} catch {
|
|
3731
4008
|
return "0.0.0";
|
|
@@ -4085,11 +4362,11 @@ function buildProgram(deps) {
|
|
|
4085
4362
|
}
|
|
4086
4363
|
|
|
4087
4364
|
// src/index.ts
|
|
4088
|
-
var __dirname3 =
|
|
4365
|
+
var __dirname3 = path21.dirname(fileURLToPath4(import.meta.url));
|
|
4089
4366
|
var require2 = createRequire3(import.meta.url);
|
|
4090
4367
|
function getVersion() {
|
|
4091
4368
|
try {
|
|
4092
|
-
const pkgPath =
|
|
4369
|
+
const pkgPath = path21.resolve(__dirname3, "../package.json");
|
|
4093
4370
|
const pkg = require2(pkgPath);
|
|
4094
4371
|
return pkg.version ?? "0.0.0";
|
|
4095
4372
|
} catch {
|