@master4n/master-cli 3.0.1 → 3.0.3

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 (57) hide show
  1. package/README.md +91 -21
  2. package/SECURITY.md +90 -0
  3. package/bin/catalog.agent.d.ts +3 -0
  4. package/bin/catalog.classic.d.ts +3 -0
  5. package/bin/catalog.d.ts +5 -1
  6. package/bin/catalog.os.d.ts +7 -0
  7. package/bin/catalog.power.d.ts +7 -0
  8. package/bin/commands/base.d.ts +7 -0
  9. package/bin/commands/calc.d.ts +7 -0
  10. package/bin/commands/case.d.ts +7 -0
  11. package/bin/commands/clip.d.ts +7 -0
  12. package/bin/commands/count.d.ts +7 -0
  13. package/bin/commands/cron.d.ts +7 -0
  14. package/bin/commands/cron.engine.d.ts +18 -0
  15. package/bin/commands/diff.d.ts +7 -0
  16. package/bin/commands/disk.d.ts +7 -0
  17. package/bin/commands/dns.d.ts +7 -0
  18. package/bin/commands/dotenv.d.ts +7 -0
  19. package/bin/commands/env.d.ts +7 -0
  20. package/bin/commands/epoch.interactive.d.ts +6 -0
  21. package/bin/commands/escape.d.ts +7 -0
  22. package/bin/commands/ext.d.ts +7 -0
  23. package/bin/commands/freq.d.ts +7 -0
  24. package/bin/commands/have.d.ts +7 -0
  25. package/bin/commands/http.d.ts +7 -0
  26. package/bin/commands/imports.d.ts +7 -0
  27. package/bin/commands/index.d.ts +38 -1
  28. package/bin/commands/ip.d.ts +7 -0
  29. package/bin/commands/json.d.ts +7 -0
  30. package/bin/commands/lines.d.ts +7 -0
  31. package/bin/commands/notify.d.ts +7 -0
  32. package/bin/commands/open.d.ts +7 -0
  33. package/bin/commands/outline.d.ts +7 -0
  34. package/bin/commands/outline.engine.d.ts +13 -0
  35. package/bin/commands/pkg.d.ts +7 -0
  36. package/bin/commands/ports.d.ts +7 -0
  37. package/bin/commands/procs.d.ts +7 -0
  38. package/bin/commands/recent.d.ts +7 -0
  39. package/bin/commands/regex.d.ts +7 -0
  40. package/bin/commands/replace.d.ts +7 -0
  41. package/bin/commands/repo.d.ts +7 -0
  42. package/bin/commands/schema.d.ts +7 -0
  43. package/bin/commands/semver.d.ts +7 -0
  44. package/bin/commands/size.d.ts +7 -0
  45. package/bin/commands/sys.d.ts +7 -0
  46. package/bin/commands/trash.d.ts +7 -0
  47. package/bin/commands/url.d.ts +7 -0
  48. package/bin/commands/wait.d.ts +7 -0
  49. package/bin/index.js +6 -6
  50. package/bin/index.js.map +1 -1
  51. package/bin/interface/CliCommand.d.ts +15 -0
  52. package/bin/interface/index.d.ts +1 -0
  53. package/bin/utility/guard.d.ts +28 -0
  54. package/bin/utility/index.d.ts +1 -1
  55. package/bin/utility/suggest.d.ts +6 -0
  56. package/llms.txt +114 -45
  57. package/package.json +12 -1
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Shape every command module exports and `src/index.ts` registers. Typing the
3
+ * registration (instead of `any`) means a malformed command module fails the
4
+ * typecheck instead of failing at runtime.
5
+ */
6
+ export interface CliCommand {
7
+ /** yargs command spec, e.g. `epoch <value>` or `sc [pattern]`. */
8
+ command: string;
9
+ /** One-line description shown in `mfn -h`. */
10
+ describe: string;
11
+ /** yargs builder adding the command's options/examples. */
12
+ builder: (yargs: any) => any;
13
+ /** Command implementation; receives parsed argv. */
14
+ handler: (argv: any) => void | Promise<void>;
15
+ }
@@ -1,2 +1,3 @@
1
1
  export * from './InquirerPrompt';
2
2
  export * from './ProcessInfo';
3
+ export * from './CliCommand';
@@ -0,0 +1,28 @@
1
+ /**
2
+ * True when reading this file's CONTENT would expose credentials/keys/PII.
3
+ * Checks the literal path AND the resolved realpath, so an innocently named
4
+ * symlink ("notes.txt" → "~/.ssh/id_rsa") can't smuggle a secret past the
5
+ * basename check (found by an adversarial review).
6
+ */
7
+ export declare function isSensitivePath(p: string): boolean;
8
+ /** Standard refusal message for a sensitive path (stable error: SensitivePath). */
9
+ export declare const sensitivePathMessage: (p: string) => string;
10
+ /** Returns what kind of secret the text contains, or null when none detected. */
11
+ export declare function scanSecrets(text: string): string | null;
12
+ /**
13
+ * Mask secret-shaped substrings inside text that a command echoes back. This
14
+ * is the content-level backstop to isSensitivePath's path-level check: even
15
+ * when a secret arrives via stdin (`cat .env | mfn freq`) — where there is no
16
+ * path to vet — a JWT/private key/cloud token is replaced before it reaches
17
+ * stdout. Returns the (possibly) masked text and how many tokens were masked.
18
+ */
19
+ export declare function redactSecrets(text: string): {
20
+ text: string;
21
+ redactedCount: number;
22
+ };
23
+ /**
24
+ * True for URLs that must never be probed: cloud metadata services. Local
25
+ * dev servers (localhost/127.0.0.1) stay allowed — probing them is the point.
26
+ */
27
+ export declare function isBlockedUrl(url: URL): boolean;
28
+ export declare const blockedUrlMessage: (url: string) => string;
@@ -5,7 +5,7 @@ export declare function Logger(): {
5
5
  debug: (debug: string) => void;
6
6
  };
7
7
  export declare function CommandBuilder(instance: any): {
8
- add: (alias: string, describe: string, builder: object, handler: (argv: any) => any) => void;
8
+ add: (alias: string, describe: string, builder: (yargs: any) => any, handler: (argv: any) => void | Promise<void>) => void;
9
9
  };
10
10
  /**
11
11
  * Get the current user's name based on the operating system.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Rewrite yargs' "Unknown argument: X" into an agent-actionable message when X
3
+ * is the attempted command: name the problem correctly, suggest the nearest
4
+ * real command, and point at `mfn capabilities`.
5
+ */
6
+ export declare function improveUnknownCommandMessage(msg: string): string;
package/llms.txt CHANGED
@@ -1,58 +1,127 @@
1
1
  # @master4n/master-cli (`mfn`)
2
2
 
3
- > A headless-friendly developer CLI that replaces boilerplate agents otherwise
4
- > regenerate on every machine: epoch/date conversions, JWT decoding, freeing
5
- > ports, finding files, and printing directory trees. Every command is designed
6
- > to be called by both humans and AI agents.
3
+ > 50 headless, JSON-first commands for AI agents and developers: extract instead
4
+ > of dump (token savers), compute instead of guess (hallucination killers),
5
+ > one-call system/code/network facts, and cross-platform OS actions (clipboard,
6
+ > notifications, trash, processes). Every command behaves identically for a
7
+ > human at a terminal and an agent reading stdout.
7
8
 
8
9
  ## Agent contract (read this first)
9
10
 
11
+ - **Zero-install:** `npx -y @master4n/master-cli <command> --json` works without a
12
+ global install; with it installed, the binary is `mfn`.
10
13
  - **Discover commands:** `mfn capabilities --json` returns the full manifest
11
- (`{ name, version, bin, conventions, commands:[{name,summary,examples}] }`).
14
+ (`{ name, version, bin, conventions, docs, categories, commands:[{name,category,summary,examples}] }`).
12
15
  - **Machine output:** pass `--json`, OR just pipe the command (when stdout is not
13
16
  a TTY the CLI auto-emits JSON). Output is exactly one object on stdout:
14
17
  success → `{ "ok": true, ... }`, failure → `{ "ok": false, "error", "message" }`.
15
18
  - **Exit codes:** `0` success · `1` runtime error · `2` usage error.
16
- - **Clean channels:** the welcome banner, spinners, and logs go to **stderr**;
17
- **stdout carries only the JSON result**, so `mfn <cmd> --json | jq` always works.
18
- - **No prompts in headless mode:** interactive prompts appear only on a TTY when
19
- required input is missing; with `--json` or when piped, commands never block.
20
- - **Strict parsing:** unknown commands, unknown flags, and missing required
21
- arguments are rejected with `{ "ok": false, "error": "UsageError", ... }` and
22
- exit `2` a typo never silently "succeeds".
23
-
24
- ## Commands
25
-
26
- - `mfn id [-t uuid|uuid7|nano] [-n count] [--size N] --json` — generate ids. UUID v4
27
- (default), time-ordered UUID v7 (RFC 9562), or a URL-safe nano id. Returns `{ type, count, ids }`.
28
- - `mfn hash [text] [-a md5|sha1|sha256|sha512] [-f file] [-e hex|base64|base64url] --json`
29
- hash a string, a file, or piped stdin. Returns `{ algo, encoding, source, bytes, hash }`.
30
- - `mfn encode [text] [--as base64|base64url|hex|url] [-d] --json` — encode (or `-d` decode)
31
- text or stdin. Returns `{ operation, codec, input, output }`.
32
- - `mfn random [-b bytes] [-e hex|base64|base64url] | [-p [-l length]] --json` — secure random
33
- bytes, or an unbiased password. Returns `{ kind, ..., value }`.
34
- - `mfn port [--json] | [-c port] | [-n count]` — find free port(s), or check a specific port.
35
- Returns `{ port }` / `{ count, ports }` / `{ port, available }`.
36
- - `mfn epoch <value> [--tz] [--format] --json` — epoch date (unit auto-detected:
37
- s/ms/µs/ns). `mfn epoch --from <dateString> [--format] [--tz] --json` — date epoch.
38
- Fractional/invalid epochs fail with exit 1.
39
- - `mfn date [from] [--tz] [--format] [--in-format] [--in-tz] --json` — convert/format
40
- a date across timezones; omit `from` for now. Returns epoch + UTC + target-zone.
41
- - `mfn decode -t <jwt> --json` — decode a JWT's header and payload (signature NOT verified).
42
- If the payload has a numeric `exp`, also returns `expiry: { exp, expired, expiresInSeconds }`.
43
- - `mfn kill -p <port...> [-y] --json` kill the process(es) listening on the given
44
- ports. Headless/`--json` (and `-y`) kill all matches without prompting; in headless
45
- mode you MUST pass `-p` (no cached-port replay). Returns `{ killed, failed, notFound }`.
46
- - `mfn sc [pattern] [--ignore...] [--depth] [--limit] --json` — fuzzy-find files/folders
47
- under the current directory. Returns `{ pattern, root, count, truncated, matches }`.
48
- - `mfn cts [--type text|svg|png|jpeg] [--ignore...] --json` — print the directory tree as
49
- text (default) or export it to an image. Ignores node_modules/.git/.nx by default.
50
- - `mfn update [package] --json` — update the CLI (or a named package) globally via npm.
51
- - `mfn capabilities --json` — self-describing manifest of all of the above.
19
+ - **Clean channels:** banners/spinners/logs go to **stderr**; **stdout carries only
20
+ the JSON result**, so `mfn <cmd> --json | jq` always works.
21
+ - **No prompts in headless mode:** with `--json` or when piped, commands never block.
22
+ - **Strict parsing:** unknown commands/flags and missing args → `{ok:false, error:"UsageError"}`, exit 2.
23
+ - **Fast:** ~60ms per invocation; heavy/TTY-only deps load lazily.
24
+
25
+ ## Token savers (read less, extract exactly)
26
+
27
+ - `mfn json [query] [-f file] [--keys] [--length] --json` — one value from JSON by
28
+ dot/bracket path (`scripts.build`, `users[0].name`); stdin or file. Don't read the document.
29
+ - `mfn schema [query] [-f file] --json` — infer JSON shape (dot-paths → types, arrays
30
+ sampled). A 10MB payload becomes ~20 lines.
31
+ - `mfn count [text] [-f file] --json` — lines/words/chars/bytes + `tokensEstimate`
32
+ (~4 chars/token heuristic). Know the cost before reading.
33
+ - `mfn lines <file> [-s start] [-e end | -n count] --json` — exact 1-based line range,
34
+ capped at 2000 lines. Returns `totalLines` too.
35
+ - `mfn outline <file> [-k kind] [-e] --json` — symbols + line numbers for
36
+ .ts/.tsx/.js/.jsx/.py/.go/.md. Pair with `lines` to read only what matters.
37
+ - `mfn diff <a> <b> [-s] --json` — structured hunks `{aStart,aLines,bStart,bLines,removed,added}`;
38
+ `-s` for locations/counts only.
39
+ - `mfn freq [file] [-t top] [-m min] --json` — most repeated lines (log triage in one call).
40
+ - `mfn imports [file] | --who <module> --json` — a file's imports (grouped
41
+ relative/packages/builtin), or every file importing a module.
42
+ - `mfn repo [-n commits] --json` — git branch, staged/unstaged/untracked counts,
43
+ ahead/behind, remotes, recent commits. Replaces 4-5 git calls.
44
+ - `mfn sys --json` — OS, arch, node, CPU, memory, user, shell, timezone, cwd in one object.
45
+ - `mfn have <tools...> --json` which tools exist, their path + version, in one call.
46
+ - `mfn size [dir] [-t top] --json` / `mfn ext [dir] --json` / `mfn recent [dir] [-t top] --json`
47
+ disk usage, project composition by extension, newest files.
48
+ - `mfn ports [--min N] --json` ALL listening TCP ports with pid/command.
49
+ - `mfn ip [-a] --json` — local interfaces/addresses; `primaryIPv4` convenience field.
50
+ - `mfn pkg [name] --json` declared vs installed dependency versions; `missing` list.
51
+ - `mfn env [names...] [-p prefix] --json` — env vars; secret-looking values are
52
+ ALWAYS redacted; no names name list only.
53
+ - `mfn dotenv [-f .env] [-e .env.example] --json` — missing/extra keys; values never read.
54
+
55
+ ## Exact computation (never guess)
56
+
57
+ - `mfn calc <expr> --json` — `+ - * / % ^` with parens; integer math in BigInt
58
+ (`2^53 + 1` → `9007199254740993`, exact). `exact:true|false` flag in output.
59
+ - `mfn base <value> [-f hex|dec|bin|oct] --json` — 0xff/0b1010/0o755/decimal → all bases, BigInt-safe.
60
+ - `mfn semver <versions...> [-b major|minor|patch] [-s] --json` — validate/compare/sort/bump
61
+ per semver.org (prerelease ordering correct).
62
+ - `mfn cron <expr> [-n next] --json` — validate 5-field cron (+ @daily etc.), plain-English
63
+ description, next run times (local + ISO + epochMs).
64
+ - `mfn regex <pattern> [text] [-f file] [--flags imsuvy] --json` — all matches with
65
+ line/index/groups. Test, don't assume.
66
+ - `mfn url <value> --json` — components + decoded query params (repeats → arrays).
67
+ - `mfn escape [text] [-a shell|json|regex|html|url|string] --json` — context-exact escaping.
68
+ - `mfn case [text] [-t camel|snake|kebab|pascal|constant|dot|path|title|sentence|lower|upper] --json`
69
+ — identifier style conversion; omit `-t` for all styles.
70
+ - `mfn epoch <value> --json` / `mfn epoch --from <date> --json` — epoch ↔ date
71
+ (unit auto-detected s/ms/µs/ns).
72
+ - `mfn date [from] [--tz] [--format] --json` — date across timezones (IANA), defaults to now.
73
+ - `mfn decode -t <jwt> --json` — JWT header+payload+expiry (signature NOT verified).
74
+
75
+ ## Actions (do, don't script)
76
+
77
+ - `mfn replace <search> <replacement> -g <glob> [--write] --json` — literal find/replace
78
+ across files; DRY-RUN by default, `--write` to apply; per-file counts.
79
+ - `mfn wait [-p port | -u url | -f file] [-t seconds] --json` — block until ready;
80
+ replaces sleep-and-retry loops. Exit 1 on timeout.
81
+ - `mfn kill -p <ports...> [-y] --json` — kill listeners on ports (headless: needs explicit -p).
82
+ - `mfn http <url> [-m GET|HEAD] [-H "Name: value"] --json` — status/headers/timing
83
+ + body preview capped at 2KB (never a full dump). Exit 1 on non-2xx.
84
+ - `mfn port [-c port | -n count] --json` — find free port(s) / check one.
85
+ - `mfn id [-t uuid|uuid7|nano] [-n count] --json` — UUID v4, time-ordered v7 (RFC 9562), nano.
86
+ - `mfn hash [text] [-a md5|sha1|sha256|sha512] [-f file] --json` — digest of string/file/stdin.
87
+ - `mfn encode [text] [--as base64|base64url|hex|url] [-d] --json` — encode/decode (strict charset).
88
+ - `mfn random [-b bytes] | [-p [-l length]] --json` — CSPRNG bytes / unbiased password.
89
+ - `mfn sc [pattern] [--depth] [--limit] --json` — fuzzy file find under cwd.
90
+ - `mfn cts [--type text|svg|png|jpeg] --json` — directory tree.
91
+ - `mfn update [package] --json` — global npm update of the CLI (or named package).
92
+
93
+ ## OS-level (cross-platform: macOS / Windows / Linux)
94
+
95
+ - `mfn clip [text] [-r] --json` — read/write the system clipboard. Write via arg or
96
+ stdin (`git diff | mfn clip`); read returns `{chars, text}`. Headless sessions fail
97
+ cleanly with `ClipboardUnavailable`.
98
+ - `mfn notify <message> [-t title] --json` — desktop notification (osascript /
99
+ notify-send / WinRT toast). Ping the user when a long task finishes.
100
+ - `mfn open <target> --json` — open an http(s) URL or existing file in the default
101
+ app/browser. Non-http schemes and missing paths are rejected (exit 2).
102
+ - `mfn procs [pattern] [-t top] --json` — search processes by name: pid/cpu/memMB,
103
+ sorted by cpu. One call instead of ps|grep (or tasklist parsing).
104
+ - `mfn disk [-a] --json` — per-mount totals/free/used% (df -kP / Win32_LogicalDisk).
105
+ - `mfn trash <paths...> --json` — move to the OS trash (reversible; ~/.Trash, XDG
106
+ spec, Recycle Bin). Refuses root/home/cwd and parents of cwd. Use instead of rm.
107
+ - `mfn dns <hostname> [-t a|aaaa|cname|mx|txt|ns] --json` — system resolver +
108
+ record sweep; missing record types are null, not errors.
109
+
110
+ ## Guardrails (always on — there are no bypass flags)
111
+
112
+ - File-content commands (`lines` `json` `schema` `diff` `freq` `regex -f`) refuse
113
+ credential/secret paths (`~/.ssh`, `.env*`, `*.pem`, `.npmrc`, …) → `SensitivePath`, exit 2.
114
+ - `clip` read redacts secret-shaped content (keys/JWTs/tokens) → `redacted:true`.
115
+ - `env` redacts by name AND value shape; `dotenv` never reads values at all.
116
+ - `http`/`wait -u` refuse cloud metadata endpoints (169.254.169.254 etc.) → `BlockedTarget`;
117
+ `http` redacts `set-cookie` response headers.
118
+ - `open` allows only http(s)/existing paths; `trash` is reversible and refuses
119
+ root/home/cwd; `kill` validates ports and PIDs; `replace` is dry-run unless `--write`.
120
+ - Full threat model: SECURITY.md (shipped in this package).
52
121
 
53
122
  ## Notes
54
123
 
55
- - Time/date features are powered by `@master4n/temporal-transformer` v2 (Luxon-backed,
56
- integer epochs; Luxon format tokens, e.g. `yyyy-MM-dd HH:mm:ss`).
57
- - Zero shell interpolation: process/port/package operations use `execFile` (no shell),
58
- so inputs cannot inject commands.
124
+ - Time/date powered by `@master4n/temporal-transformer` v2 (Luxon-backed, integer epochs).
125
+ - Zero shell interpolation: every subprocess uses `execFile` (no shell) — inputs cannot
126
+ inject commands. See SECURITY.md (shipped in this package) for the full threat model.
127
+ - `count.tokensEstimate` is a ~4-chars/token heuristic, not a model tokenizer.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@master4n/master-cli",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "description": "AI-agent-friendly command-line toolkit: timestamp/date conversion, JWT decoding, port killing, file finding, and directory trees — headless, --json, with a self-describing manifest.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -21,6 +21,10 @@
21
21
  "ai-agents",
22
22
  "agent-tools",
23
23
  "llm-tools",
24
+ "llms-txt",
25
+ "agent-friendly",
26
+ "claude-code",
27
+ "coding-agent",
24
28
  "automation",
25
29
  "headless",
26
30
  "json-output",
@@ -34,6 +38,13 @@
34
38
  "free-port",
35
39
  "directory-tree",
36
40
  "fuzzy-finder",
41
+ "uuid",
42
+ "sha256",
43
+ "base64",
44
+ "random-password",
45
+ "jwt-decoder",
46
+ "developer-cli",
47
+ "agent-cli",
37
48
  "mfn",
38
49
  "master-cli"
39
50
  ],