@mosse-ai/cli 0.1.1 → 0.1.2

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 +115 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -23159,7 +23159,7 @@ function buildCommandTree(options = {}) {
23159
23159
  }
23160
23160
 
23161
23161
  // src/api.ts
23162
- var CLI_VERSION = true ? "0.1.1" : "0.0.0";
23162
+ var CLI_VERSION = true ? "0.1.2" : "0.0.0";
23163
23163
  var CLI_USER_AGENT = `mosse-cli/${CLI_VERSION}`;
23164
23164
  async function callApi(request) {
23165
23165
  const headers = {
@@ -23629,6 +23629,8 @@ var LOCAL_COMMANDS = [
23629
23629
  "skill upgrade",
23630
23630
  "doctor",
23631
23631
  "completions",
23632
+ "update",
23633
+ "help",
23632
23634
  "inbox list",
23633
23635
  "inbox read",
23634
23636
  "workspace list"
@@ -23747,6 +23749,42 @@ function renderCompletions(tree, shell) {
23747
23749
  return fishScript(words);
23748
23750
  }
23749
23751
 
23752
+ // src/help.ts
23753
+ function editDistance(a, b) {
23754
+ const rows = a.length + 1;
23755
+ const cols = b.length + 1;
23756
+ let prev = Array.from({ length: cols }, (_, i) => i);
23757
+ for (let i = 1; i < rows; i += 1) {
23758
+ const next = [i];
23759
+ for (let j = 1; j < cols; j += 1) {
23760
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1;
23761
+ next[j] = Math.min(prev[j] + 1, next[j - 1] + 1, prev[j - 1] + cost);
23762
+ }
23763
+ prev = next;
23764
+ }
23765
+ return prev[b.length];
23766
+ }
23767
+ function suggestCommands(tree, tokens, limit2 = 3) {
23768
+ const typed = tokens.join(" ");
23769
+ if (!typed) return [];
23770
+ const typedTokens = new Set(tokens);
23771
+ const scored = tree.commands.map((command) => {
23772
+ const path = command.path.join(" ");
23773
+ const overlap = command.path.filter((segment) => typedTokens.has(segment)).length;
23774
+ const distance = editDistance(typed, path);
23775
+ const startsWith = path.startsWith(typed) ? 1 : 0;
23776
+ return { command, score: distance - overlap * 2 - startsWith * 2 };
23777
+ }).filter((entry) => entry.score <= 4).sort((a, b) => a.score - b.score || a.command.path.length - b.command.path.length);
23778
+ return scored.slice(0, limit2).map((entry) => entry.command);
23779
+ }
23780
+ function searchCommands(tree, query) {
23781
+ const q = query.trim().toLowerCase();
23782
+ if (!q) return [];
23783
+ return tree.commands.filter(
23784
+ (command) => command.path.join(" ").includes(q) || command.summary.toLowerCase().includes(q)
23785
+ );
23786
+ }
23787
+
23750
23788
  // src/cli.ts
23751
23789
  var EXIT_USAGE = 2;
23752
23790
  var EXIT_AUTH = 3;
@@ -23850,12 +23888,12 @@ function suggestFlag(name, flags) {
23850
23888
  let best = null;
23851
23889
  for (const flag of flags) {
23852
23890
  const candidate = flag.name.replace(/^--/, "").replace(/-/g, "");
23853
- const distance = editDistance(target, candidate);
23891
+ const distance = editDistance2(target, candidate);
23854
23892
  if (distance <= 2 && (!best || distance < best.distance)) best = { name: flag.name, distance };
23855
23893
  }
23856
23894
  return best ? `; did you mean ${best.name}?` : "";
23857
23895
  }
23858
- function editDistance(a, b) {
23896
+ function editDistance2(a, b) {
23859
23897
  const rows = a.length + 1;
23860
23898
  const cols = b.length + 1;
23861
23899
  let prev = Array.from({ length: cols }, (_, j) => j);
@@ -24038,18 +24076,24 @@ async function runCli(argv, deps) {
24038
24076
  return 0;
24039
24077
  }
24040
24078
  const { head, tail } = splitHead(effective);
24041
- if (!head.length) {
24042
- deps.stdout(`${tree.rootHelp}
24079
+ const rootHelp = () => `${tree.rootHelp}
24043
24080
  Local commands:
24044
24081
  auth <login|logout|status|token> credentials (not part of the tool surface)
24045
24082
  skill [install|status|upgrade] agent cheatsheet (mosse skill for the one-pager)
24046
24083
  doctor local environment check
24047
24084
  completions <bash|zsh|fish> shell completion script
24048
24085
  workspace list list workspaces (alias of auth whoami)
24049
- `);
24086
+ inbox wait [--timeout-ms <ms>] long-poll one inbox notification (exit 4 on timeout)
24087
+ update check npm for a newer @mosse-ai/cli
24088
+ help [query] search commands by path / description
24089
+ `;
24090
+ if (!head.length) {
24091
+ deps.stdout(rootHelp());
24050
24092
  return 0;
24051
24093
  }
24052
24094
  if (head[0] === "inbox" && head[1] === "wait") return handleInboxWait(rest.slice(2), deps, config2, globals);
24095
+ if (head[0] === "update") return handleUpdate(rest.slice(1), deps, globals);
24096
+ if (head[0] === "help") return handleHelpSearch(rest.slice(1), deps, tree, rootHelp());
24053
24097
  if (head[0] === "completions") return handleCompletions(rest.slice(1), deps, tree, globals);
24054
24098
  if (head[0] === "skill") return handleSkill(rest.slice(1), deps, configPath, config2, tree, globals);
24055
24099
  if (head[0] === "doctor") return handleDoctor(deps, config2, globals);
@@ -24061,7 +24105,11 @@ Local commands:
24061
24105
  deps.stdout(renderGroupHelp(tree.commands, head));
24062
24106
  return 0;
24063
24107
  }
24064
- deps.stderr(structuredError(globals, EXIT_USAGE, "unknown_command", `no such command: mosse ${head.join(" ")}`));
24108
+ const suggestions = suggestCommands(tree, head);
24109
+ const hint = suggestions.length ? `; did you mean: ${suggestions.map((item) => `mosse ${item.path.join(" ")}`).join(", ")}` : "";
24110
+ deps.stderr(
24111
+ structuredError(globals, EXIT_USAGE, "unknown_command", `no such command: mosse ${head.join(" ")}${hint}`)
24112
+ );
24065
24113
  deps.stderr(tree.rootHelp);
24066
24114
  return EXIT_USAGE;
24067
24115
  }
@@ -24224,6 +24272,66 @@ function sessionPath(tool, input2) {
24224
24272
  return encodeURIComponent(String(value));
24225
24273
  });
24226
24274
  }
24275
+ async function handleUpdate(args, deps, globals) {
24276
+ if (args[0] === "--help" || args[0] === "-h") {
24277
+ deps.stdout("mosse update\n\n\u68C0\u67E5 npm \u4E0A\u7684\u6700\u65B0\u7248;\u4E0D\u81EA\u52A8\u5B89\u88C5,\u53EA\u6253\u5370\u5347\u7EA7\u547D\u4EE4\u3002\n");
24278
+ return 0;
24279
+ }
24280
+ const registry2 = "https://registry.npmjs.org/@mosse-ai/cli/latest";
24281
+ let latest;
24282
+ try {
24283
+ const response = await deps.fetch(registry2, { headers: { accept: "application/json" } });
24284
+ if (!response.ok) throw new Error(`registry responded ${response.status}`);
24285
+ const body = await response.json();
24286
+ if (!body.version) throw new Error("registry response has no version");
24287
+ latest = body.version;
24288
+ } catch (error62) {
24289
+ deps.stderr(
24290
+ structuredError(
24291
+ globals,
24292
+ 1,
24293
+ "update_check_failed",
24294
+ `could not check the npm registry: ${error62.message}`
24295
+ )
24296
+ );
24297
+ return 1;
24298
+ }
24299
+ const upToDate = compareVersions(latest, CLI_VERSION) <= 0;
24300
+ if (globals.json !== void 0) {
24301
+ deps.stdout(renderOutput({ current: CLI_VERSION, latest, upToDate }, outputOptions(globals)));
24302
+ } else {
24303
+ deps.stdout(
24304
+ upToDate ? `mosse ${CLI_VERSION} is up to date (latest ${latest})` : `mosse ${CLI_VERSION} \u2192 ${latest} available
24305
+ npm i -g @mosse-ai/cli@${latest}
24306
+ # or: npx @mosse-ai/cli@latest <command>`
24307
+ );
24308
+ }
24309
+ return 0;
24310
+ }
24311
+ function compareVersions(a, b) {
24312
+ const pa = a.split(".").map((part) => Number(part) || 0);
24313
+ const pb = b.split(".").map((part) => Number(part) || 0);
24314
+ for (let i = 0; i < Math.max(pa.length, pb.length); i += 1) {
24315
+ const diff = (pa[i] ?? 0) - (pb[i] ?? 0);
24316
+ if (diff !== 0) return diff;
24317
+ }
24318
+ return 0;
24319
+ }
24320
+ async function handleHelpSearch(args, deps, tree, root) {
24321
+ const query = args.filter((arg) => !arg.startsWith("-")).join(" ").trim();
24322
+ if (!query) {
24323
+ deps.stdout(root);
24324
+ return 0;
24325
+ }
24326
+ const matches = searchCommands(tree, query);
24327
+ if (!matches.length) {
24328
+ deps.stderr(`no commands match "${query}" (try \`mosse --help\`)`);
24329
+ return 0;
24330
+ }
24331
+ deps.stdout(matches.map((command) => `mosse ${command.path.join(" ")}
24332
+ ${command.summary}`).join("\n\n"));
24333
+ return 0;
24334
+ }
24227
24335
  async function handleInboxWait(args, deps, config2, globals) {
24228
24336
  if (args[0] === "--help" || args[0] === "-h") {
24229
24337
  deps.stdout(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mosse-ai/cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mosse": "./dist/index.js"