@nolto/cli 0.20.2 → 0.21.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 +12 -4
- package/dist/index.js +140 -23
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -89,7 +89,8 @@ nolto watch status # Show pid, version, start time, and service s
|
|
|
89
89
|
nolto watch stop # Stop watch (leaves the service installed)
|
|
90
90
|
nolto watch list # List registered repositories, including missing roots
|
|
91
91
|
nolto watch remove [root] # Unregister a repository (defaults to the current repo)
|
|
92
|
-
nolto watch --install-service
|
|
92
|
+
nolto watch --install-service # Install the background service (Linux systemd / macOS launchd)
|
|
93
|
+
nolto watch --uninstall-service # Stop and remove the background service
|
|
93
94
|
```
|
|
94
95
|
|
|
95
96
|
Roadmaps live outside the repository at `<config dir>/projects/<projectId>/roadmaps/<slug>.json`,
|
|
@@ -117,14 +118,21 @@ plan documents are already limited to 2 MB per roadmap before that shared cap.
|
|
|
117
118
|
|
|
118
119
|
`watch` records its PID, CLI version, and start time in `<config dir>/watch.json`
|
|
119
120
|
(mode 0600). `watch status` reports version drift; these four subcommands support
|
|
120
|
-
`--json`. `watch stop` leaves the
|
|
121
|
+
`--json`. `watch stop` leaves the service installed for the next login; use
|
|
121
122
|
`watch --uninstall-service` to remove it permanently. Removing a registry entry
|
|
122
123
|
stops watching that repository without restarting watch and does not delete its files.
|
|
123
124
|
|
|
124
125
|
When init, link, sync, or roadmap migrate adds a registry entry, it warns if a
|
|
125
126
|
running watch uses a different CLI version. Watch from 0.15.x and earlier does
|
|
126
|
-
not write `watch.json` and cannot be detected. `nolto update` restarts the
|
|
127
|
-
watch service so the updated watcher can report its version.
|
|
127
|
+
not write `watch.json` and cannot be detected. `nolto update` restarts the
|
|
128
|
+
watch service on Linux and macOS so the updated watcher can report its version.
|
|
129
|
+
|
|
130
|
+
On macOS, the service installs `~/Library/LaunchAgents/app.nolto.watch.plist`
|
|
131
|
+
and writes logs to `~/Library/Logs/nolto/watch.log`. Authenticate with `nolto login`;
|
|
132
|
+
`NOLTO_TOKEN` is not passed to the service. The service resolves `node` from PATH
|
|
133
|
+
in this order: the Node directory used at install time, `/opt/homebrew/bin`,
|
|
134
|
+
`/usr/local/bin`, `/usr/bin`, and `/bin`, so if the Node used at install time
|
|
135
|
+
disappears, the service runs with another Node.
|
|
128
136
|
|
|
129
137
|
`watch` uses `{ root, projectId }` entries in the registry maintained by init, link,
|
|
130
138
|
and sync. Older entries resolve their project from `nolto.json`; missing repositories
|
package/dist/index.js
CHANGED
|
@@ -4175,6 +4175,50 @@ var RepoWatch = class {
|
|
|
4175
4175
|
// src/service-install.ts
|
|
4176
4176
|
import path19 from "path";
|
|
4177
4177
|
import os4 from "os";
|
|
4178
|
+
var LAUNCHD_LABEL = "app.nolto.watch";
|
|
4179
|
+
function getPlistPath(env) {
|
|
4180
|
+
return path19.join(env.HOME || os4.homedir(), "Library", "LaunchAgents", `${LAUNCHD_LABEL}.plist`);
|
|
4181
|
+
}
|
|
4182
|
+
function getLaunchdLogPath(env) {
|
|
4183
|
+
return path19.join(env.HOME || os4.homedir(), "Library", "Logs", "nolto", "watch.log");
|
|
4184
|
+
}
|
|
4185
|
+
function getServicePath(platform, env) {
|
|
4186
|
+
return platform === "darwin" ? getPlistPath(env) : getUnitPath(env);
|
|
4187
|
+
}
|
|
4188
|
+
function buildPlist(args) {
|
|
4189
|
+
const escapeXml = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
4190
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
4191
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
4192
|
+
<plist version="1.0">
|
|
4193
|
+
<dict>
|
|
4194
|
+
<key>Label</key><string>${LAUNCHD_LABEL}</string>
|
|
4195
|
+
<key>ProgramArguments</key>
|
|
4196
|
+
<array>
|
|
4197
|
+
<string>/usr/bin/env</string>
|
|
4198
|
+
<string>node</string>
|
|
4199
|
+
<string>${escapeXml(args.scriptPath)}</string>
|
|
4200
|
+
<string>watch</string>
|
|
4201
|
+
</array>
|
|
4202
|
+
<key>EnvironmentVariables</key>
|
|
4203
|
+
<dict>
|
|
4204
|
+
<key>PATH</key><string>${escapeXml(args.nodeDir)}:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin</string>
|
|
4205
|
+
</dict>
|
|
4206
|
+
<key>RunAtLoad</key><true/>
|
|
4207
|
+
<key>KeepAlive</key>
|
|
4208
|
+
<dict><key>SuccessfulExit</key><false/></dict>
|
|
4209
|
+
<key>StandardOutPath</key><string>${escapeXml(args.logPath)}</string>
|
|
4210
|
+
<key>StandardErrorPath</key><string>${escapeXml(args.logPath)}</string>
|
|
4211
|
+
</dict>
|
|
4212
|
+
</plist>
|
|
4213
|
+
`;
|
|
4214
|
+
}
|
|
4215
|
+
function restartServiceCommand(platform, uid) {
|
|
4216
|
+
if (platform === "linux") return ["systemctl", "--user", "restart", "nolto-watch"];
|
|
4217
|
+
if (platform === "darwin" && uid !== void 0 && uid !== 0) {
|
|
4218
|
+
return ["launchctl", "kickstart", "-k", `gui/${uid}/${LAUNCHD_LABEL}`];
|
|
4219
|
+
}
|
|
4220
|
+
return null;
|
|
4221
|
+
}
|
|
4178
4222
|
function buildUnitFile(args) {
|
|
4179
4223
|
return [
|
|
4180
4224
|
"[Unit]",
|
|
@@ -4197,9 +4241,39 @@ function getUnitPath(env) {
|
|
|
4197
4241
|
return path19.join(base, "systemd", "user", "nolto-watch.service");
|
|
4198
4242
|
}
|
|
4199
4243
|
async function installServiceWith(deps) {
|
|
4244
|
+
if (deps.platform === "darwin") {
|
|
4245
|
+
if (deps.uid === void 0 || deps.uid === 0) {
|
|
4246
|
+
throw new CliError("The watch service must be managed as your login user, not root (do not use sudo).", 2);
|
|
4247
|
+
}
|
|
4248
|
+
const plistPath = getPlistPath(deps.env);
|
|
4249
|
+
const logPath = getLaunchdLogPath(deps.env);
|
|
4250
|
+
const domain = `gui/${deps.uid}`;
|
|
4251
|
+
await deps.mkdir(path19.dirname(plistPath));
|
|
4252
|
+
await deps.mkdir(path19.dirname(logPath), 448);
|
|
4253
|
+
await deps.writeFile(plistPath, buildPlist({
|
|
4254
|
+
nodeDir: path19.dirname(deps.nodePath),
|
|
4255
|
+
scriptPath: deps.scriptPath,
|
|
4256
|
+
logPath
|
|
4257
|
+
}), 420);
|
|
4258
|
+
deps.log(`Wrote ${plistPath}`);
|
|
4259
|
+
await deps.exec(["launchctl", "bootout", `${domain}/${LAUNCHD_LABEL}`]);
|
|
4260
|
+
for (let attempt = 0; attempt < 5; attempt++) {
|
|
4261
|
+
const result = await deps.exec(["launchctl", "bootstrap", domain, plistPath]);
|
|
4262
|
+
if (result.code === 0) {
|
|
4263
|
+
deps.log(`Service ${LAUNCHD_LABEL} loaded and started. Logs: ${logPath}`);
|
|
4264
|
+
return;
|
|
4265
|
+
}
|
|
4266
|
+
if (attempt < 4) await deps.sleep(500);
|
|
4267
|
+
}
|
|
4268
|
+
deps.warn(
|
|
4269
|
+
`Could not activate the service automatically. Run manually:
|
|
4270
|
+
launchctl bootstrap ${domain} "${plistPath}"`
|
|
4271
|
+
);
|
|
4272
|
+
return;
|
|
4273
|
+
}
|
|
4200
4274
|
if (deps.platform !== "linux") {
|
|
4201
4275
|
throw new CliError(
|
|
4202
|
-
"--install-service
|
|
4276
|
+
"--install-service is supported on Linux (systemd) and macOS (launchd) only.",
|
|
4203
4277
|
2,
|
|
4204
4278
|
"Run `nolto watch` manually in a terminal instead."
|
|
4205
4279
|
);
|
|
@@ -4225,13 +4299,15 @@ async function installService() {
|
|
|
4225
4299
|
const execFileAsync = promisify5(execFile6);
|
|
4226
4300
|
await installServiceWith({
|
|
4227
4301
|
platform: process.platform,
|
|
4302
|
+
uid: process.getuid?.(),
|
|
4228
4303
|
env: process.env,
|
|
4229
4304
|
nodePath: process.execPath,
|
|
4230
4305
|
scriptPath: path19.resolve(process.argv[1] ?? ""),
|
|
4231
|
-
writeFile: (p, content) => writeFile11(p, content, "utf8"),
|
|
4232
|
-
mkdir: async (p) => {
|
|
4233
|
-
await mkdir9(p, { recursive: true });
|
|
4306
|
+
writeFile: (p, content, mode2) => writeFile11(p, content, mode2 === void 0 ? "utf8" : { encoding: "utf8", mode: mode2 }),
|
|
4307
|
+
mkdir: async (p, mode2) => {
|
|
4308
|
+
await mkdir9(p, mode2 === void 0 ? { recursive: true } : { recursive: true, mode: mode2 });
|
|
4234
4309
|
},
|
|
4310
|
+
sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
4235
4311
|
exec: async (cmd) => {
|
|
4236
4312
|
try {
|
|
4237
4313
|
await execFileAsync(cmd[0], cmd.slice(1));
|
|
@@ -4246,9 +4322,40 @@ async function installService() {
|
|
|
4246
4322
|
});
|
|
4247
4323
|
}
|
|
4248
4324
|
async function uninstallServiceWith(deps) {
|
|
4325
|
+
if (deps.platform === "darwin") {
|
|
4326
|
+
if (deps.uid === void 0 || deps.uid === 0) {
|
|
4327
|
+
throw new CliError("The watch service must be managed as your login user, not root (do not use sudo).", 2);
|
|
4328
|
+
}
|
|
4329
|
+
const plistPath = getPlistPath(deps.env);
|
|
4330
|
+
const service = `gui/${deps.uid}/${LAUNCHD_LABEL}`;
|
|
4331
|
+
const loaded = await deps.exec(["launchctl", "print", service]);
|
|
4332
|
+
const bootoutFailed = loaded.code === 0 && (await deps.exec(["launchctl", "bootout", service])).code !== 0;
|
|
4333
|
+
let unlinkError2;
|
|
4334
|
+
try {
|
|
4335
|
+
await deps.unlink(plistPath);
|
|
4336
|
+
deps.log(`Removed ${plistPath}`);
|
|
4337
|
+
} catch (err) {
|
|
4338
|
+
if (err.code === "ENOENT") {
|
|
4339
|
+
deps.log(`Plist not found at ${plistPath}; nothing to remove.`);
|
|
4340
|
+
} else {
|
|
4341
|
+
unlinkError2 = err;
|
|
4342
|
+
}
|
|
4343
|
+
}
|
|
4344
|
+
if (bootoutFailed) {
|
|
4345
|
+
deps.warn(
|
|
4346
|
+
`Could not deactivate the service automatically. Run manually:
|
|
4347
|
+
launchctl bootout ${service}
|
|
4348
|
+
rm -f "${plistPath}"`
|
|
4349
|
+
);
|
|
4350
|
+
}
|
|
4351
|
+
if (unlinkError2 != null) throw unlinkError2;
|
|
4352
|
+
if (bootoutFailed) return;
|
|
4353
|
+
deps.log(`Service ${LAUNCHD_LABEL} stopped and removed.`);
|
|
4354
|
+
return;
|
|
4355
|
+
}
|
|
4249
4356
|
if (deps.platform !== "linux") {
|
|
4250
4357
|
throw new CliError(
|
|
4251
|
-
"--uninstall-service
|
|
4358
|
+
"--uninstall-service is supported on Linux (systemd) and macOS (launchd) only.",
|
|
4252
4359
|
2
|
|
4253
4360
|
);
|
|
4254
4361
|
}
|
|
@@ -4290,6 +4397,7 @@ async function uninstallService() {
|
|
|
4290
4397
|
const execFileAsync = promisify5(execFile6);
|
|
4291
4398
|
await uninstallServiceWith({
|
|
4292
4399
|
platform: process.platform,
|
|
4400
|
+
uid: process.getuid?.(),
|
|
4293
4401
|
env: process.env,
|
|
4294
4402
|
unlink: unlink5,
|
|
4295
4403
|
exec: async (cmd) => {
|
|
@@ -4306,8 +4414,15 @@ async function uninstallService() {
|
|
|
4306
4414
|
});
|
|
4307
4415
|
}
|
|
4308
4416
|
async function stopServiceWith(deps) {
|
|
4417
|
+
if (deps.platform === "darwin") {
|
|
4418
|
+
if (deps.uid === void 0 || deps.uid === 0) {
|
|
4419
|
+
throw new CliError("The watch service must be managed as your login user, not root (do not use sudo).", 2);
|
|
4420
|
+
}
|
|
4421
|
+
const result2 = await deps.exec(["launchctl", "kill", "SIGTERM", `gui/${deps.uid}/${LAUNCHD_LABEL}`]);
|
|
4422
|
+
return result2.code === 0;
|
|
4423
|
+
}
|
|
4309
4424
|
if (deps.platform !== "linux") {
|
|
4310
|
-
throw new CliError("Stopping the watch service
|
|
4425
|
+
throw new CliError("Stopping the watch service is supported on Linux (systemd) and macOS (launchd) only.", 2);
|
|
4311
4426
|
}
|
|
4312
4427
|
const result = await deps.exec(["systemctl", "--user", "stop", "nolto-watch"]);
|
|
4313
4428
|
if (result.code !== 0) {
|
|
@@ -4317,11 +4432,12 @@ async function stopServiceWith(deps) {
|
|
|
4317
4432
|
"Run `systemctl --user stop nolto-watch` manually."
|
|
4318
4433
|
);
|
|
4319
4434
|
}
|
|
4435
|
+
return false;
|
|
4320
4436
|
}
|
|
4321
4437
|
|
|
4322
4438
|
// src/commands/watch.ts
|
|
4323
4439
|
function register10(program, deps) {
|
|
4324
|
-
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
|
|
4440
|
+
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 start a background service (systemd user unit on Linux, launchd agent on macOS) instead of watching").option("--uninstall-service", "Stop and remove the background service instead of watching").action(async (opts) => {
|
|
4325
4441
|
if (opts.installService && opts.uninstallService) {
|
|
4326
4442
|
throw new CliError("--install-service and --uninstall-service cannot be used together.", 2);
|
|
4327
4443
|
}
|
|
@@ -4465,7 +4581,7 @@ function register10(program, deps) {
|
|
|
4465
4581
|
version: running ? state.version : null,
|
|
4466
4582
|
startedAt: running ? state.startedAt : null,
|
|
4467
4583
|
stale: running && state.version !== deps.version,
|
|
4468
|
-
service: existsSync7(
|
|
4584
|
+
service: existsSync7(getServicePath(process.platform, process.env)) ? "installed" : "not-installed"
|
|
4469
4585
|
};
|
|
4470
4586
|
printResult(deps.output.mode === "json" ? result : `${running ? "running" : "not running"}
|
|
4471
4587
|
service: ${result.service}
|
|
@@ -4477,11 +4593,13 @@ stale: ${result.stale}`, deps.output.mode);
|
|
|
4477
4593
|
watch.command("stop").description("Stop watch without disabling the installed service.").action(async () => {
|
|
4478
4594
|
const statePath = getWatchStatePath(process.env);
|
|
4479
4595
|
const state = await readWatchState(statePath);
|
|
4480
|
-
const service = existsSync7(
|
|
4596
|
+
const service = existsSync7(getServicePath(process.platform, process.env));
|
|
4481
4597
|
let via = null;
|
|
4598
|
+
let signalSent = false;
|
|
4482
4599
|
if (service) {
|
|
4483
|
-
await stopServiceWith({
|
|
4600
|
+
signalSent = await stopServiceWith({
|
|
4484
4601
|
platform: process.platform,
|
|
4602
|
+
uid: process.getuid?.(),
|
|
4485
4603
|
exec: async (cmd) => {
|
|
4486
4604
|
try {
|
|
4487
4605
|
await promisify3(execFile4)(cmd[0], cmd.slice(1));
|
|
@@ -4492,9 +4610,9 @@ stale: ${result.stale}`, deps.output.mode);
|
|
|
4492
4610
|
}
|
|
4493
4611
|
}
|
|
4494
4612
|
});
|
|
4495
|
-
via = "systemd";
|
|
4613
|
+
via = process.platform === "darwin" ? "launchd" : "systemd";
|
|
4496
4614
|
}
|
|
4497
|
-
if (state && isAlive(state.pid)) {
|
|
4615
|
+
if (!signalSent && state && isAlive(state.pid)) {
|
|
4498
4616
|
try {
|
|
4499
4617
|
process.kill(state.pid, "SIGTERM");
|
|
4500
4618
|
} catch (error) {
|
|
@@ -4721,21 +4839,19 @@ async function updateCliWith(deps) {
|
|
|
4721
4839
|
latest2
|
|
4722
4840
|
).catch(() => void 0);
|
|
4723
4841
|
let watchService = "not-installed";
|
|
4724
|
-
const
|
|
4725
|
-
if (deps.platform === "linux" && deps.unitExists(
|
|
4726
|
-
const
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
"nolto-watch"
|
|
4731
|
-
]);
|
|
4732
|
-
if (restartResult.code === 0) {
|
|
4842
|
+
const servicePath = getServicePath(deps.platform, deps.env);
|
|
4843
|
+
if ((deps.platform === "linux" || deps.platform === "darwin") && deps.unitExists(servicePath)) {
|
|
4844
|
+
const command = restartServiceCommand(deps.platform, deps.uid);
|
|
4845
|
+
const serviceName = deps.platform === "darwin" ? LAUNCHD_LABEL : "nolto-watch";
|
|
4846
|
+
const restartResult = command === null ? null : await deps.exec(command);
|
|
4847
|
+
if (restartResult?.code === 0) {
|
|
4733
4848
|
watchService = "restarted";
|
|
4734
|
-
deps.log(
|
|
4849
|
+
deps.log(`Restarted ${serviceName} service.`);
|
|
4735
4850
|
} else {
|
|
4736
4851
|
watchService = "restart-failed";
|
|
4737
4852
|
deps.warn(
|
|
4738
|
-
"Could not restart
|
|
4853
|
+
command === null ? "The watch service must be managed as your login user, not root (do not use sudo)." : `Could not restart ${serviceName} automatically. Run manually:
|
|
4854
|
+
${command.join(" ")}`
|
|
4739
4855
|
);
|
|
4740
4856
|
}
|
|
4741
4857
|
}
|
|
@@ -4763,6 +4879,7 @@ async function updateCli(opts = {}) {
|
|
|
4763
4879
|
currentVersion: getCurrentVersion(),
|
|
4764
4880
|
scriptPath,
|
|
4765
4881
|
platform: process.platform,
|
|
4882
|
+
uid: process.getuid?.(),
|
|
4766
4883
|
env: process.env,
|
|
4767
4884
|
configDir: getConfigDir(process.env),
|
|
4768
4885
|
now: Date.now(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nolto/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "CLI for syncing repository roadmaps with Nolto.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@nolto/roadmap-schema": "0.1.0",
|
|
45
|
-
"@types/node": "^22.
|
|
45
|
+
"@types/node": "^22.20.4",
|
|
46
46
|
"tsup": "^8.3.5",
|
|
47
47
|
"typescript": "^5.7.2",
|
|
48
48
|
"vitest": "^4.1.7",
|