argsbarg 4.0.1 → 4.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.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [4.0.3] - 2026-06-24
11
+
12
+
13
+ ## [4.0.2] - 2026-06-24
14
+
15
+
10
16
  ## [4.0.1] - 2026-06-24
11
17
 
12
18
 
@@ -452,7 +458,9 @@ const cli = { ... } satisfies CliProgram; // or : CliProgram
452
458
  - 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
459
  - Imports: use `CliPositional` where needed; replace `CliOptionDef` with `CliOption` or `CliPositional` as appropriate.
454
460
 
455
- [Unreleased]: https://github.com/bdombro/bun-argsbarg/compare/v4.0.1...HEAD
461
+ [Unreleased]: https://github.com/bdombro/bun-argsbarg/compare/v4.0.3...HEAD
462
+ [4.0.3]: https://github.com/bdombro/bun-argsbarg/releases/tag/v4.0.3
463
+ [4.0.2]: https://github.com/bdombro/bun-argsbarg/releases/tag/v4.0.2
456
464
  [4.0.1]: https://github.com/bdombro/bun-argsbarg/releases/tag/v4.0.1
457
465
  [4.0.0]: https://github.com/bdombro/bun-argsbarg/releases/tag/v4.0.0
458
466
  [3.6.4]: https://github.com/bdombro/bun-argsbarg/releases/tag/v3.6.4
@@ -425,13 +425,13 @@ 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
 
432
432
  See [config-schema.md](config-schema.md) for codegen, [install.md](install.md), and [mcp.md](mcp.md).
433
433
 
434
- **Handler access (`ctx.appConfig`):** `get`, `require`, `set`, `read`, `path` — prefer over `process.env` in handlers; env export remains for subprocess inheritance. `path` is the resolved absolute config file path (`program.appConfig.path` when set, otherwise the OS default from `program.key`).
434
+ **Handler access (`ctx.appConfig`):** `get`, `require`, `set`, `read`, `path`, `dir` — prefer over `process.env` in handlers; env export remains for subprocess inheritance. `path` is the resolved absolute config file path; `dir` is its parent directory (both honor `program.appConfig.path` when set, otherwise the OS default from `program.key`).
435
435
 
436
436
  ## Reserved names
437
437
 
@@ -42,7 +42,7 @@ await cli.run();
42
42
  | `install --configure` / `--status` | Interactive setup and status |
43
43
  | Built-in `config get` / `config set` | Read/write resolved values (opt-out via `commands: false`) |
44
44
  | MCP bundle / Claude plugin | `userConfig` for entries with `env` set |
45
- | `ctx.appConfig` in handlers | `get`, `require`, `set`, `read`, `path` — prefer over `process.env` |
45
+ | `ctx.appConfig` in handlers | `get`, `require`, `set`, `read`, `path`, `dir` — prefer over `process.env` |
46
46
 
47
47
  **Validation at runtime** — argsbarg validates the config file and `config set` / `ctx.appConfig.set` against the effective JSON Schema (block `jsonSchema` or synthesized all-string schema).
48
48
 
package/index.d.ts CHANGED
@@ -10,6 +10,8 @@ declare class EmptyAppConfigSnapshot {
10
10
  read(): ResolvedConfig;
11
11
  /** Resolved absolute path to the app JSON config file (OS default from `program.key`). */
12
12
  get path(): string;
13
+ /** Resolved absolute directory containing the config file. */
14
+ get dir(): string;
13
15
  }
14
16
  declare class AppConfigSnapshot {
15
17
  private readonly program;
@@ -22,6 +24,8 @@ declare class AppConfigSnapshot {
22
24
  read(): ResolvedConfig;
23
25
  /** Resolved absolute path to the app JSON config file (honors `program.appConfig.path` or OS default). */
24
26
  get path(): string;
27
+ /** Resolved absolute directory containing the config file. */
28
+ get dir(): string;
25
29
  /** Replace snapshot after external bootstrap (internal). */
26
30
  refresh(fileData: Record<string, unknown>, resolved: ResolvedConfig): void;
27
31
  private assertEntryKey;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "argsbarg",
3
- "version": "4.0.1",
3
+ "version": "4.0.3",
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(
@@ -1,9 +1,10 @@
1
1
  import { describe, expect, test } from "bun:test";
2
2
  import { mkdtempSync, rmSync } from "node:fs";
3
3
  import { tmpdir } from "node:os";
4
- import { join } from "node:path";
4
+ import { dirname, join } from "node:path";
5
5
  import type { CliProgram } from "../types.ts";
6
6
  import { createAppConfigSnapshot } from "./context.ts";
7
+ import { resolveAppConfigDir } from "./file.ts";
7
8
  import { resolveAppConfig } from "./resolve.ts";
8
9
 
9
10
  function configProgram(configPath: string): CliProgram {
@@ -37,6 +38,7 @@ describe("config/context", () => {
37
38
  expect(ctx.get("note")).toBe("hello");
38
39
  expect(ctx.require("apiToken")).toBe("tok");
39
40
  expect(ctx.path).toBe(path);
41
+ expect(ctx.dir).toBe(dirname(path));
40
42
 
41
43
  ctx.set("note", "updated");
42
44
  expect(ctx.get("note")).toBe("updated");
@@ -60,6 +62,7 @@ describe("config/context", () => {
60
62
  expect(() => empty.set("any", "v")).toThrow(/program.appConfig is not set/);
61
63
  expect(empty.path).toContain("x");
62
64
  expect(empty.path.endsWith("/config") || empty.path.endsWith("\\config")).toBe(true);
65
+ expect(empty.dir).toBe(dirname(empty.path));
63
66
  });
64
67
 
65
68
  test("AppConfigSnapshot path uses OS default when program.appConfig.path omitted", () => {
@@ -75,5 +78,12 @@ describe("config/context", () => {
75
78
  const ctx = createAppConfigSnapshot(program, {}, {});
76
79
  expect(ctx.path).toContain("ctx_test");
77
80
  expect(ctx.path.endsWith("/config") || ctx.path.endsWith("\\config")).toBe(true);
81
+ expect(ctx.dir).toBe(resolveAppConfigDir(program));
82
+ expect(ctx.dir).toBe(dirname(ctx.path));
83
+ });
84
+
85
+ test("resolveAppConfigDir honors custom program.appConfig.path", () => {
86
+ const program = configProgram("/tmp/custom/settings.json");
87
+ expect(resolveAppConfigDir(program)).toBe("/tmp/custom");
78
88
  });
79
89
  });
@@ -3,7 +3,7 @@ Handler-facing resolved app config snapshot (ctx.appConfig).
3
3
  */
4
4
 
5
5
  import type { CliProgram } from "../types.ts";
6
- import { resolveAppConfigPath, writeAppConfigFile } from "./file.ts";
6
+ import { resolveAppConfigDir, resolveAppConfigPath, writeAppConfigFile } from "./file.ts";
7
7
  import type { ResolvedConfig } from "./resolve.ts";
8
8
  import { exportConfigToEnv, resolveAppConfig } from "./resolve.ts";
9
9
 
@@ -31,6 +31,11 @@ export class EmptyAppConfigSnapshot {
31
31
  get path(): string {
32
32
  return resolveAppConfigPath(this.program);
33
33
  }
34
+
35
+ /** Resolved absolute directory containing the config file. */
36
+ get dir(): string {
37
+ return resolveAppConfigDir(this.program);
38
+ }
34
39
  }
35
40
 
36
41
  /** Resolved config for handlers with program.appConfig set. */
@@ -82,6 +87,11 @@ export class AppConfigSnapshot {
82
87
  return resolveAppConfigPath(this.program);
83
88
  }
84
89
 
90
+ /** Resolved absolute directory containing the config file. */
91
+ get dir(): string {
92
+ return resolveAppConfigDir(this.program);
93
+ }
94
+
85
95
  /** Replace snapshot after external bootstrap (internal). */
86
96
  refresh(fileData: Record<string, unknown>, resolved: ResolvedConfig): void {
87
97
  this.fileData = { ...fileData };
@@ -22,6 +22,11 @@ export function resolveAppConfigPath(program: CliProgram): string {
22
22
  return join(appConfigHome(), dirName, "config");
23
23
  }
24
24
 
25
+ /** Resolved absolute directory containing the app JSON config file. */
26
+ export function resolveAppConfigDir(program: CliProgram): string {
27
+ return dirname(resolveAppConfigPath(program));
28
+ }
29
+
25
30
  /** Human-readable config path for error messages (`~` when under home). */
26
31
  export function displayAppConfigPath(program: CliProgram): string {
27
32
  const resolved = resolveAppConfigPath(program);
@@ -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);