argsbarg 4.0.1 → 4.0.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.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [4.0.2] - 2026-06-24
11
+
12
+
10
13
  ## [4.0.1] - 2026-06-24
11
14
 
12
15
 
@@ -452,7 +455,8 @@ const cli = { ... } satisfies CliProgram; // or : CliProgram
452
455
  - Migrate schemas: rename every `children` property to **`commands`**; move positional definitions to **`CliPositional`** objects on `positionals` and strip `positional` / `argMin` / `argMax` from flag definitions under `options` (flags only carry `name`, `description`, `kind`, and optional `shortName`).
453
456
  - Imports: use `CliPositional` where needed; replace `CliOptionDef` with `CliOption` or `CliPositional` as appropriate.
454
457
 
455
- [Unreleased]: https://github.com/bdombro/bun-argsbarg/compare/v4.0.1...HEAD
458
+ [Unreleased]: https://github.com/bdombro/bun-argsbarg/compare/v4.0.2...HEAD
459
+ [4.0.2]: https://github.com/bdombro/bun-argsbarg/releases/tag/v4.0.2
456
460
  [4.0.1]: https://github.com/bdombro/bun-argsbarg/releases/tag/v4.0.1
457
461
  [4.0.0]: https://github.com/bdombro/bun-argsbarg/releases/tag/v4.0.0
458
462
  [3.6.4]: https://github.com/bdombro/bun-argsbarg/releases/tag/v3.6.4
@@ -425,7 +425,7 @@ await cli.run();
425
425
  - Default: `$XDG_CONFIG_HOME/<sanitized-key>/config` or `%APPDATA%/<key>/config`.
426
426
  - JSON: flat object keyed by schema names — `{ "apiToken": "…", "maxRetries": 5 }`.
427
427
  - **Strict:** unknown keys rejected on load.
428
- - **CLI:** missing required config exits 1 before the leaf handler (TTY prompt when interactive). Built-in `config get`/`set` skip this exit.
428
+ - **CLI:** missing required config exits 1 before the leaf handler (TTY prompt when interactive). Built-in `docs` and `config get`/`set` skip this exit.
429
429
  - **MCP:** server stays up; missing config returns `isError: true` at `tools/call`.
430
430
  - **Configure:** `myapp install --configure` (not part of `--all`).
431
431
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "argsbarg",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "bun": ">=1.3"
@@ -47,6 +47,18 @@ export function reservedCommandNames(caps: CliCapabilities): string[] {
47
47
  return names;
48
48
  }
49
49
 
50
+ /** Commands that may run without required appConfig values (read-only / config introspection). */
51
+ export function skipsRequiredAppConfigExit(path: string[], caps: CliCapabilities): boolean {
52
+ const root = path[0];
53
+ if (root === "config" && caps.configCommands) {
54
+ return true;
55
+ }
56
+ if (root === "docs" && caps.docs) {
57
+ return true;
58
+ }
59
+ return false;
60
+ }
61
+
50
62
  export type CapabilityFeature = "mcp" | "install" | "docs" | "config";
51
63
 
52
64
  /** Stderr message when a disabled built-in is invoked from the CLI. */
package/src/cli.ts CHANGED
@@ -5,7 +5,12 @@ Runtime entry point: validate program, cache derived state, run / invoke / MCP s
5
5
  import { format } from "node:util";
6
6
  import { builtinInterceptRoot, dispatchBuiltin } from "./builtins/dispatch.ts";
7
7
  import { cliParseRoot, cliPresentationRoot } from "./builtins/presentation.ts";
8
- import { assertBuiltinAllowed, type CliCapabilities, resolveCapabilities } from "./capabilities.ts";
8
+ import {
9
+ assertBuiltinAllowed,
10
+ type CliCapabilities,
11
+ resolveCapabilities,
12
+ skipsRequiredAppConfigExit,
13
+ } from "./capabilities.ts";
9
14
  import {
10
15
  bootstrapAppConfig,
11
16
  type EnsureAppConfigOpts,
@@ -113,10 +118,10 @@ export class Cli {
113
118
  });
114
119
  }
115
120
 
116
- const isConfigCmd = pr.path[0] === "config" && this.caps.configCommands;
121
+ const skipRequiredConfig = skipsRequiredAppConfigExit(pr.path, this.caps);
117
122
  const snapshot = this.buildAppConfigSnapshot({
118
- interactive: !isConfigCmd && !!process.stdin.isTTY,
119
- exitOnMissing: !isConfigCmd,
123
+ interactive: !skipRequiredConfig && !!process.stdin.isTTY,
124
+ exitOnMissing: !skipRequiredConfig,
120
125
  });
121
126
 
122
127
  const ctx = new CliContext(
@@ -98,3 +98,47 @@ test("MCP config file loads and exports vars for tool handlers", async () => {
98
98
  expect(res.result.isError).toBe(false);
99
99
  expect(res.result.content[0]?.text.trim()).toBe("present");
100
100
  });
101
+
102
+ test("Cli.run docs api skips required appConfig exit", async () => {
103
+ const dir = mkdtempSync(join(tmpdir(), "argsbarg-docs-skip-"));
104
+ const configFile = join(dir, "config");
105
+ writeFileSync(configFile, "{}\n");
106
+ const entry = join(import.meta.dir, "index.ts");
107
+ const mainPath = join(dir, "run-docs.ts");
108
+ writeFileSync(
109
+ mainPath,
110
+ `import { Cli, type CliProgram } from ${JSON.stringify(entry)};
111
+ const program = {
112
+ key: "docs-skip-test",
113
+ version: "1.0.0",
114
+ description: "test",
115
+ docs: { enabled: true, topics: { readme: { text: "# readme\\n" } } },
116
+ appConfig: {
117
+ path: ${JSON.stringify(configFile)},
118
+ entries: { token: { description: "Token.", env: "DOCS_SKIP_RUN_TOKEN" } },
119
+ },
120
+ handler: () => {},
121
+ } satisfies CliProgram;
122
+ await new Cli(program).run(process.argv.slice(2));
123
+ `,
124
+ );
125
+ const env = { ...process.env };
126
+ delete env.DOCS_SKIP_RUN_TOKEN;
127
+ try {
128
+ const proc = Bun.spawn(["bun", "run", mainPath, "docs", "api"], {
129
+ stdout: "pipe",
130
+ stderr: "pipe",
131
+ env,
132
+ });
133
+ const [stdout, stderr, exitCode] = await Promise.all([
134
+ new Response(proc.stdout).text(),
135
+ new Response(proc.stderr).text(),
136
+ proc.exited,
137
+ ]);
138
+ expect(exitCode).toBe(0);
139
+ expect(stdout).toContain("# docs-skip-test — CLI API reference");
140
+ expect(stderr).not.toContain("Missing required configuration");
141
+ } finally {
142
+ rmSync(dir, { recursive: true, force: true });
143
+ }
144
+ });
@@ -4,6 +4,7 @@ import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
5
  import { completionBashScript } from "../builtins/index.ts";
6
6
  import { cliPresentationRoot } from "../builtins/presentation.ts";
7
+ import { resolveCapabilities, skipsRequiredAppConfigExit } from "../capabilities.ts";
7
8
  import { Cli } from "../index.ts";
8
9
  import type { CliProgram } from "../types.ts";
9
10
  import { cliValidateProgram } from "../validate.ts";
@@ -151,6 +152,19 @@ test("docs api prints markdown reference", async () => {
151
152
  expect(result.stdout).toContain("myapp docs schema");
152
153
  });
153
154
 
155
+ test("skipsRequiredAppConfigExit includes docs and config builtins", () => {
156
+ const program = {
157
+ ...docsFixture(),
158
+ appConfig: {
159
+ entries: { token: { description: "Token.", env: "DOCS_SKIP_TOKEN" } },
160
+ },
161
+ };
162
+ const caps = resolveCapabilities(program);
163
+ expect(skipsRequiredAppConfigExit(["docs", "api"], caps)).toBe(true);
164
+ expect(skipsRequiredAppConfigExit(["config", "get"], caps)).toBe(true);
165
+ expect(skipsRequiredAppConfigExit(["run"], caps)).toBe(false);
166
+ });
167
+
154
168
  test("docs skill prints Cursor SKILL.md", async () => {
155
169
  const result = await new Cli(docsFixture()).invoke(["docs", "skill"]);
156
170
  expect(result.exitCode).toBe(0);