@nolto/cli 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/dist/index.js +52 -20
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/index.ts
4
- import { createRequire } from "module";
5
- import { fileURLToPath } from "url";
6
- import path3 from "path";
4
+ import { createRequire as createRequire2 } from "module";
5
+ import { fileURLToPath as fileURLToPath2 } from "url";
6
+ import path4 from "path";
7
7
  import { CommanderError } from "commander";
8
8
 
9
9
  // src/config.ts
@@ -270,6 +270,30 @@ import { Command } from "commander";
270
270
 
271
271
  // src/commands/init.ts
272
272
  import readline from "readline/promises";
273
+ import { createRequire } from "module";
274
+ import { fileURLToPath } from "url";
275
+ import path2 from "path";
276
+ import fs from "fs";
277
+ var __dirname = path2.dirname(fileURLToPath(import.meta.url));
278
+ var _require = createRequire(import.meta.url);
279
+ function getCliVersion() {
280
+ const candidates = [
281
+ path2.resolve(__dirname, "../package.json"),
282
+ // bundled: dist/../package.json
283
+ path2.resolve(__dirname, "../../package.json")
284
+ // source: src/commands/../../package.json
285
+ ];
286
+ for (const pkgPath of candidates) {
287
+ if (fs.existsSync(pkgPath)) {
288
+ try {
289
+ const pkg = _require(pkgPath);
290
+ return pkg.version ?? "0.0.0";
291
+ } catch {
292
+ }
293
+ }
294
+ }
295
+ return "0.0.0";
296
+ }
273
297
  function register(program, _deps) {
274
298
  program.command("init").description("Interactive setup: configure token, base URL, and default project.").option("--force", "Overwrite existing config without prompting").action(async (opts) => {
275
299
  const configPath = getConfigPath(process.env);
@@ -301,7 +325,7 @@ function register(program, _deps) {
301
325
  if (token.length === 0) {
302
326
  throw new CliError("Token is required.", 2);
303
327
  }
304
- const caller = createMcpCaller({ baseUrl, token, version: "0.1.0" });
328
+ const caller = createMcpCaller({ baseUrl, token, version: getCliVersion() });
305
329
  let projects = [];
306
330
  try {
307
331
  const result = await caller.call("list_projects", {});
@@ -552,9 +576,9 @@ import { z as z2 } from "zod";
552
576
 
553
577
  // src/fsx.ts
554
578
  import { readFile as readFile2, stat as stat2 } from "fs/promises";
555
- import path2 from "path";
579
+ import path3 from "path";
556
580
  async function readPlanFile(filePath) {
557
- const absPath = path2.resolve(filePath);
581
+ const absPath = path3.resolve(filePath);
558
582
  let content;
559
583
  try {
560
584
  content = await readFile2(absPath, "utf8");
@@ -575,11 +599,11 @@ async function readPlanFile(filePath) {
575
599
  2
576
600
  );
577
601
  }
578
- const stem = path2.basename(absPath, path2.extname(absPath));
602
+ const stem = path3.basename(absPath, path3.extname(absPath));
579
603
  return { content: trimmed, sourcePath: absPath, titleFallback: stem };
580
604
  }
581
605
  async function readDocFile(filePath) {
582
- const absPath = path2.resolve(filePath);
606
+ const absPath = path3.resolve(filePath);
583
607
  let fileSize;
584
608
  try {
585
609
  const info = await stat2(absPath);
@@ -601,7 +625,7 @@ async function readDocFile(filePath) {
601
625
  throw new CliError(`Cannot read file: ${absPath}: ${String(err)}`, 2);
602
626
  }
603
627
  const isBinary = buf.includes(0) || !isUtf8RoundTrip(buf);
604
- const rawFilename = path2.basename(absPath);
628
+ const rawFilename = path3.basename(absPath);
605
629
  const filename = rawFilename.slice(0, DOCUMENT_FILENAME_MAX);
606
630
  if (isBinary) {
607
631
  return { content: buf.toString("base64"), encoding: "base64", filename };
@@ -732,8 +756,13 @@ function registerPlanRegisterSubcommand(plan, deps) {
732
756
  }
733
757
  const phaseResult = phaseArraySchema.safeParse(parsedPhases);
734
758
  if (!phaseResult.success) {
735
- const field = phaseResult.error.issues[0]?.path.join(".") ?? "unknown";
736
- throw new CliError(`Invalid --phases JSON: field "${field}"`, 2);
759
+ const issue = phaseResult.error.issues[0];
760
+ if (issue?.code === "too_big" && issue.path.length === 0) {
761
+ throw new CliError(`Too many phases (max ${PHASES_MAX}).`, 2);
762
+ }
763
+ const fieldPath = issue?.path.join(".") ?? "";
764
+ const fieldDesc = fieldPath.length > 0 ? `field "${fieldPath}"` : "unknown field";
765
+ throw new CliError(`Invalid --phases JSON: ${fieldDesc}`, 2);
737
766
  }
738
767
  parsedPhases = phaseResult.data;
739
768
  }
@@ -925,7 +954,7 @@ function register5(program, deps) {
925
954
  }
926
955
  let round;
927
956
  if (opts.round != null) {
928
- if (!/^\d+$/.test(opts.round)) {
957
+ if (!/^[1-9]\d*$/.test(opts.round)) {
929
958
  throw new CliError(`--round must be a positive integer, got "${opts.round}"`, 2);
930
959
  }
931
960
  const parsed = Number(opts.round);
@@ -995,11 +1024,13 @@ function register6(program, deps) {
995
1024
  }
996
1025
 
997
1026
  // src/program.ts
1027
+ function stripCommanderErrorPrefix(msg) {
1028
+ return msg.startsWith("error: ") ? msg.slice("error: ".length) : msg;
1029
+ }
998
1030
  function buildProgram(deps) {
999
- const isJson = deps.output.mode === "json";
1000
- const writeErr = isJson ? (_msg) => {
1001
- } : void 0;
1002
- const program = new Command("nolto").version(deps.version, "-V, --version", "Print version number").exitOverride().configureOutput(writeErr != null ? { writeErr } : {}).description("Nolto CLI \u2014 register plans and update progress from your terminal.").option("--token <value>", "API token (overrides env/file)").option("--base-url <url>", "Nolto base URL (default: https://nolto.app)").option("--project <projectId>", "Default project ID").option("--json", "Output as JSON");
1031
+ const writeErr = (_msg) => {
1032
+ };
1033
+ const program = new Command("nolto").version(deps.version, "-V, --version", "Print version number").exitOverride().configureOutput({ writeErr }).description("Nolto CLI \u2014 register plans and update progress from your terminal.").option("--token <value>", "API token (overrides env/file)").option("--base-url <url>", "Nolto base URL (default: https://nolto.app)").option("--project <projectId>", "Default project ID").option("--json", "Output as JSON");
1003
1034
  register(program, deps);
1004
1035
  register2(program, deps);
1005
1036
  register3(program, deps);
@@ -1010,11 +1041,11 @@ function buildProgram(deps) {
1010
1041
  }
1011
1042
 
1012
1043
  // src/index.ts
1013
- var __dirname = path3.dirname(fileURLToPath(import.meta.url));
1014
- var require2 = createRequire(import.meta.url);
1044
+ var __dirname2 = path4.dirname(fileURLToPath2(import.meta.url));
1045
+ var require2 = createRequire2(import.meta.url);
1015
1046
  function getVersion() {
1016
1047
  try {
1017
- const pkgPath = path3.resolve(__dirname, "../package.json");
1048
+ const pkgPath = path4.resolve(__dirname2, "../package.json");
1018
1049
  const pkg = require2(pkgPath);
1019
1050
  return pkg.version ?? "0.0.0";
1020
1051
  } catch {
@@ -1076,7 +1107,8 @@ main().catch((err) => {
1076
1107
  if (err.exitCode === 0) {
1077
1108
  process.exit(0);
1078
1109
  }
1079
- const cliErr2 = new CliError(err.message, 2);
1110
+ const cleanMsg = stripCommanderErrorPrefix(err.message);
1111
+ const cliErr2 = new CliError(cleanMsg, 2);
1080
1112
  printError(cliErr2, mode);
1081
1113
  process.exitCode = 2;
1082
1114
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nolto/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "CLI for Nolto — register plans and update progress from your terminal.",
5
5
  "license": "MIT",
6
6
  "type": "module",