argsbarg 6.1.1 → 6.1.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 +72 -1
- package/README.md +17 -19
- package/bin/argsbarg +10 -0
- package/docs/README.md +4 -3
- package/docs/ai-skills.md +4 -2
- package/docs/bundled-docs.md +50 -25
- package/docs/cli-program.md +76 -10
- package/docs/config-schema.md +10 -11
- package/docs/configure.md +2 -0
- package/docs/decisions.md +40 -0
- package/docs/developing.md +43 -5
- package/docs/http-server.md +171 -0
- package/docs/json-schema-subset.md +51 -0
- package/docs/mcp.md +4 -2
- package/docs/output-schema.md +55 -62
- package/examples/formats.ts +6 -6
- package/examples/full-example/Formula/full-example.rb +35 -0
- package/examples/full-example/README.md +20 -21
- package/examples/full-example/docs/README.md +1 -1
- package/examples/full-example/docs/cli-schema.json +1790 -98
- package/examples/full-example/docs/cli.md +1990 -0
- package/examples/full-example/docs/http.md +28 -29
- package/examples/full-example/docs/mcp.md +8 -22
- package/examples/full-example/docs/openapi.json +783 -50
- package/examples/full-example/docs/skill.md +10 -10
- package/examples/full-example/justfile +11 -1
- package/examples/full-example/src/commands/render-json/__generated__/RenderJsonInputSchema.json +15 -0
- package/examples/full-example/src/commands/render-json/__generated__/index.ts +5 -0
- package/examples/full-example/src/commands/render-json/command.test.ts +46 -0
- package/examples/full-example/src/commands/render-json/command.ts +30 -0
- package/examples/full-example/src/commands/render-json/types.ts +9 -0
- package/examples/full-example/src/commands/status/__generated__/StatusJsonOutputSchema.json +15 -0
- package/examples/full-example/src/commands/status/__generated__/index.ts +2 -2
- package/examples/full-example/src/commands/status/command.ts +5 -13
- package/examples/full-example/src/commands/status/types.ts +1 -14
- package/examples/full-example/src/commands/workspaces/__generated__/WorkspaceNameInputSchema.json +15 -0
- package/examples/full-example/src/commands/workspaces/__generated__/index.ts +5 -0
- package/examples/full-example/src/commands/workspaces/command.test.ts +58 -0
- package/examples/full-example/src/commands/workspaces/command.ts +94 -0
- package/examples/full-example/src/commands/workspaces/types.ts +6 -0
- package/examples/full-example/src/db/index.test.ts +86 -0
- package/examples/full-example/src/db/index.ts +101 -0
- package/examples/full-example/src/db/migrate.test.ts +35 -0
- package/examples/full-example/src/db/migrate.ts +69 -0
- package/examples/full-example/src/db/migrations/001_workspaces.sql +6 -0
- package/examples/full-example/src/db/tables/workspaces.ts +66 -0
- package/examples/full-example/src/program.ts +11 -36
- package/examples/full-example/src/types/argsbarg.d.ts +11 -0
- package/examples/full-example/src/types/md.d.ts +4 -0
- package/examples/full-example/tsconfig.json +5 -2
- package/examples/mcp-test.ts +1 -2
- package/examples/minimal.ts +1 -7
- package/examples/nested.ts +1 -2
- package/examples/option-required.ts +1 -1
- package/examples/servers.ts +4 -5
- package/index.d.ts +440 -136
- package/package.json +19 -2
- package/src/builtins/builtins.test.ts +7 -7
- package/src/builtins/completion-bash.ts +1 -1
- package/src/builtins/completion-fish.ts +1 -1
- package/src/builtins/completion-group.ts +4 -4
- package/src/builtins/completion-simulate-shared.ts +9 -0
- package/src/builtins/completion-zsh.ts +1 -1
- package/src/builtins/config.test.ts +3 -3
- package/src/builtins/config.ts +9 -9
- package/src/builtins/configure-copy.ts +2 -2
- package/src/builtins/configure.ts +4 -4
- package/src/builtins/dispatch.ts +19 -18
- package/src/builtins/export.ts +7 -5
- package/src/builtins/http.ts +68 -0
- package/src/builtins/mcp.ts +28 -4
- package/src/builtins/presentation.ts +6 -6
- package/src/builtins/registry.ts +6 -6
- package/src/builtins/scopes.ts +2 -2
- package/src/builtins/version.ts +1 -1
- package/src/cli-tool/full-example-capabilities.test.ts +10 -15
- package/src/cli-tool/main.ts +1 -1
- package/src/cli-tool/program.ts +3 -2
- package/src/cli-tool/prompt.ts +1 -1
- package/src/cli-tool/run-schemagen.ts +1 -3
- package/src/cli-tool/schemagen/cleanup.ts +6 -7
- package/src/cli-tool/schemagen/discover-schema-roots.ts +66 -120
- package/src/cli-tool/schemagen/index.ts +2 -2
- package/src/cli-tool/schemagen/names.ts +8 -13
- package/src/cli-tool/schemagen/run.ts +21 -28
- package/src/cli-tool/schemagen/schemagen.test.ts +136 -46
- package/src/config/bindings.test.ts +1 -1
- package/src/config/bindings.ts +1 -1
- package/src/config/bootstrap.test.ts +1 -1
- package/src/config/bootstrap.ts +36 -4
- package/src/config/context.test.ts +1 -1
- package/src/config/context.ts +1 -1
- package/src/config/entry.ts +1 -1
- package/src/config/file.test.ts +1 -1
- package/src/config/file.ts +3 -3
- package/src/config/manifest.ts +1 -1
- package/src/config/resolve.test.ts +1 -1
- package/src/config/resolve.ts +1 -1
- package/src/config/schema.ts +1 -1
- package/src/config/validate.ts +1 -1
- package/src/{install → configure/artifacts}/binary-placement.test.ts +1 -1
- package/src/{install → configure/artifacts}/binary-placement.ts +1 -1
- package/src/{install → configure/artifacts}/gh-release-update.ts +1 -1
- package/src/{install → configure/artifacts}/install-validate.test.ts +3 -3
- package/src/{install → configure/artifacts}/mcp-config.ts +1 -1
- package/src/{install → configure/artifacts}/mcp-opencode.test.ts +1 -1
- package/src/{install → configure/artifacts}/mcp-opencode.ts +1 -1
- package/src/{install → configure/artifacts}/paths.ts +5 -5
- package/src/configure/artifacts/plan.ts +24 -0
- package/src/{install → configure/artifacts}/status.test.ts +1 -1
- package/src/{install → configure/artifacts}/status.ts +2 -2
- package/src/{install → configure/artifacts}/target-base.ts +1 -1
- package/src/{install → configure/artifacts}/target-detect.ts +1 -1
- package/src/{install → configure/artifacts}/target-effective.ts +3 -9
- package/src/{install → configure/artifacts}/target-mcp-cli.ts +1 -1
- package/src/{install → configure/artifacts}/target-mcp-json.ts +1 -1
- package/src/{install → configure/artifacts}/target-plan-build.ts +2 -2
- package/src/{install → configure/artifacts}/target-registry.ts +2 -2
- package/src/{install → configure/artifacts}/target-scope.ts +3 -3
- package/src/{install → configure/artifacts}/target-skill.ts +1 -1
- package/src/{install → configure/artifacts}/target-types.ts +2 -2
- package/src/{install → configure/artifacts}/targets/app.ts +5 -5
- package/src/{install → configure/artifacts}/targets/chatgpt-mcp.ts +2 -2
- package/src/{install → configure/artifacts}/targets/claude-code-mcp.ts +2 -2
- package/src/{install → configure/artifacts}/targets/claude-desktop-mcp.ts +2 -2
- package/src/{install → configure/artifacts}/targets/claude-skill.ts +2 -2
- package/src/{install → configure/artifacts}/targets/codex-mcp.ts +2 -2
- package/src/{install → configure/artifacts}/targets/codex-skill.ts +2 -2
- package/src/{install → configure/artifacts}/targets/configure.ts +5 -5
- package/src/{install → configure/artifacts}/targets/cursor-mcp.ts +2 -2
- package/src/{install → configure/artifacts}/targets/cursor-skill.ts +2 -2
- package/src/{install → configure/artifacts}/targets/index.ts +1 -1
- package/src/{install → configure/artifacts}/targets/openclaw-mcp.ts +2 -2
- package/src/{install → configure/artifacts}/targets/openclaw-skill.ts +3 -3
- package/src/{install → configure/artifacts}/targets/opencode-mcp.ts +5 -5
- package/src/{install → configure/artifacts}/targets/opencode-skill.ts +3 -3
- package/src/{install → configure/artifacts}/targets.test.ts +1 -1
- package/src/{install → configure/artifacts}/uninstall.ts +1 -1
- package/src/configure/configure.test.ts +11 -11
- package/src/configure/index.ts +14 -14
- package/src/configure/prompt.ts +2 -2
- package/src/{context.ts → core/context.ts} +26 -20
- package/src/core/json-leaf.test.ts +156 -0
- package/src/{leaf-inputs.test.ts → core/leaf-inputs.test.ts} +7 -7
- package/src/{leaf-inputs.ts → core/leaf-inputs.ts} +76 -16
- package/src/{parse.test.ts → core/parse.test.ts} +97 -109
- package/src/{parse.ts → core/parse.ts} +173 -25
- package/src/{schema.ts → core/schema.ts} +25 -13
- package/src/{types.ts → core/types.ts} +238 -35
- package/src/{validate.ts → core/validate.ts} +51 -29
- package/src/docs/builtin.ts +8 -19
- package/src/docs/{api-guide.test.ts → cli-guide.test.ts} +21 -21
- package/src/docs/{api-guide.ts → cli-guide.ts} +45 -16
- package/src/docs/docs.test.ts +76 -41
- package/src/docs/http-guide.ts +37 -34
- package/src/docs/mcp-guide.ts +12 -14
- package/src/docs/mcp-resources.test.ts +2 -3
- package/src/docs/mcp-resources.ts +6 -11
- package/src/docs/resolve.ts +22 -30
- package/src/docs/save.ts +3 -3
- package/src/exports/cli.ts +47 -0
- package/src/exports/headless.ts +13 -0
- package/src/exports/http.ts +6 -0
- package/src/exports/mcp.ts +6 -0
- package/src/{headless.test.ts → headless/routing.test.ts} +3 -3
- package/src/{headless.ts → headless/routing.ts} +3 -3
- package/src/headless/tool-call.ts +114 -46
- package/src/help.test.ts +152 -0
- package/src/help.ts +54 -18
- package/src/hooks/builtin.ts +20 -0
- package/src/hooks/run.ts +142 -0
- package/src/http/openapi.ts +182 -0
- package/src/http/readiness.ts +78 -0
- package/src/{api → http}/result.ts +16 -5
- package/src/http/routes.ts +329 -0
- package/src/http/server.ts +225 -0
- package/src/index.ts +38 -25
- package/src/log/ecs.test.ts +43 -0
- package/src/log/ecs.ts +59 -0
- package/src/log/emitter.ts +166 -0
- package/src/mcp/bundle.ts +2 -2
- package/src/mcp/claude.test.ts +1 -1
- package/src/mcp/claude.ts +4 -4
- package/src/{hidden-mcpb.test.ts → mcp/hidden-mcpb.test.ts} +10 -9
- package/src/mcp/result.ts +2 -2
- package/src/mcp/server.ts +54 -6
- package/src/mcp/tools.ts +18 -20
- package/src/{capabilities.ts → runtime/capabilities.ts} +11 -11
- package/src/{cli-errors.ts → runtime/cli-errors.ts} +4 -4
- package/src/{cli.ts → runtime/cli.ts} +160 -50
- package/src/runtime/exposure.ts +102 -0
- package/src/{invoke.test.ts → runtime/invoke.test.ts} +31 -7
- package/src/server/context.ts +25 -0
- package/src/server/overrides.ts +112 -0
- package/src/skill/generate.ts +8 -8
- package/src/skill/hint.ts +1 -1
- package/src/skill/install.ts +2 -2
- package/src/skill/naming.ts +1 -1
- package/src/{test-fixtures.ts → test/fixtures.ts} +3 -2
- package/src/{config.integration.test.ts → test/integration/config.test.ts} +8 -8
- package/src/{api.integration.test.ts → test/integration/http.test.ts} +170 -67
- package/src/{mcp.integration.test.ts → test/integration/mcp.test.ts} +11 -57
- package/docs/api-server.md +0 -141
- package/examples/full-example/docs/api.md +0 -511
- package/examples/full-example/src/commands/status/__generated__/outputSchema.json +0 -28
- package/examples/full-example/src/config/__generated__/configSchema.json +0 -40
- package/examples/full-example/src/config/__generated__/index.ts +0 -5
- package/examples/full-example/src/config/types.ts +0 -24
- package/src/api/openapi.ts +0 -117
- package/src/api/server.ts +0 -120
- package/src/builtins/api.ts +0 -38
- package/src/hidden.ts +0 -30
- package/src/install/plan.ts +0 -53
- /package/src/{install → configure/artifacts}/detect-installed.ts +0 -0
- /package/src/{install → configure/artifacts}/gh-release-update.test.ts +0 -0
- /package/src/{install → configure/artifacts}/mcp-codex.test.ts +0 -0
- /package/src/{install → configure/artifacts}/mcp-codex.ts +0 -0
- /package/src/{install → configure/artifacts}/mcp-openclaw.test.ts +0 -0
- /package/src/{install → configure/artifacts}/mcp-openclaw.ts +0 -0
- /package/src/{install → configure/artifacts}/normalize-uninstall.ts +0 -0
- /package/src/{install → configure/artifacts}/normalize.ts +0 -0
- /package/src/{install → configure/artifacts}/opts.ts +0 -0
- /package/src/{install → configure/artifacts}/shell.ts +0 -0
- /package/src/{formats.test.ts → core/formats.test.ts} +0 -0
- /package/src/{formats.ts → core/formats.ts} +0 -0
- /package/src/{respond.ts → core/respond.ts} +0 -0
- /package/src/{types.test.ts → core/types.test.ts} +0 -0
- /package/src/{api → http}/schema-deref.test.ts +0 -0
- /package/src/{api → http}/schema-deref.ts +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,75 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [6.1.3] - 2026-07-24
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **HTTP REST API** — nested `/api/...` routes from the command tree; `:param` routers; query/body binding; verb inference (`get`/`post`/…); default success statuses (POST **201**, DELETE **204**).
|
|
15
|
+
- **Per-surface exposure** — `cli`, `http`, and `mcpTool` blocks replace global `hidden` (`enabled` / `hidden` per surface; `cli.enabled` cascades).
|
|
16
|
+
- **Invoke hooks and error pipeline** — `program.hooks` (`beforeInvoke`, `afterInvoke`, `formatError`, `onError`), `failureKind` on `CliInvokeResult`, and HTTP/MCP status mapping (`validation`/`help` → 400, `unexpected` → 500, `missing_config`/`not_ready` → 503).
|
|
17
|
+
- **Server runtime and observability** — `ServerRuntime`, ECS logging (`program.log`), `serveHttp(overrides?)` / `serveMcp(overrides?)`, `GET /health/live` and `GET /health/ready`, soft config validation at server start, HTTP/MCP wire hooks, CLI flags on `http` / `mcp serve`.
|
|
18
|
+
- **`pathParams`** on parse results and `ctx.inputs`; `:param` shell completion fallback.
|
|
19
|
+
- **Schema export** — `outputContentType` on leaves without `outputSchema`; program `errorSchema` from server error config.
|
|
20
|
+
- **Export subpaths** — `argsbarg/cli`, `argsbarg/http`, `argsbarg/mcp`, `argsbarg/headless` (root barrel unchanged). See [docs/developing.md](docs/developing.md#advanced-imports).
|
|
21
|
+
- **`docs/json-schema-subset.md`** — documents the custom JSON Schema validator used for `appConfig` and `inputSchema`.
|
|
22
|
+
- **`src/help.test.ts`** — label unit tests and help render regressions (migrated from `parse.test.ts`).
|
|
23
|
+
- **Compact skill `reference.md`** — `generateCliGuideBody({ compact: true })` omits inline `outputSchema` JSON; pointers to `docs cli-schema` / OpenAPI.
|
|
24
|
+
- **`examples/full-example` `render-json` command** — `kind: "json"` leaf with schemagen `inputSchema`, `ctx.inputsAs`, and HTTP invoke test.
|
|
25
|
+
- **`examples/full-example` `workspaces` command** — REST CRUD demo with `:id` router, hooks, readiness, layered in-memory SQLite (`db/`, `store/workspaces`), and versioned migrations.
|
|
26
|
+
- **`scripts/merge-code-rule.ts`** — merge full-example `code.mdc` into consumer repos (preserves app convention footer).
|
|
27
|
+
- **`just consumers-schemagen`** — run schemagen across local `consumer_apps` paths.
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
|
|
31
|
+
- **Breaking: `@sg` schemagen** — role exports (`configType` / `inputType` / `outputType`) removed. Mark types with `/** @sg */` immediately above `export interface` / `export type`; import `{TypeName}Schema` from colocated `__generated__/`.
|
|
32
|
+
- **Breaking: `McpToolDef.apiName` / `apiToolName()` removed** — HTTP uses REST `/api/...` routes only.
|
|
33
|
+
- **Breaking: `loadLeafInputs` and `CliHttpResponseConfig` unexported** from the root barrel (use `ctx.inputs` / `ctx.inputsAs`; leaf `http.successContentType`).
|
|
34
|
+
- **Framework-owned `ctx.locals.requestId`** — seeded before `beforeInvoke` on every invocation (wire HTTP/MCP id when present, else `randomUUID()`).
|
|
35
|
+
- **`examples/full-example` simplified** — no default `appConfig`; commands use `@sg` named schemas; minimal `program.ts`.
|
|
36
|
+
- **Internal refactor** — needless single-use extractions inlined across `src/` per `.cursor/rules/code.mdc`.
|
|
37
|
+
- **Internal: `src/` layout** — `src/core/`, `src/runtime/`, `src/headless/routing.ts`, shared/integration tests → `src/test/`; cross-module imports use `~/` (`tsconfig` `paths`). Public exports unchanged.
|
|
38
|
+
- **Internal: import paths** — directory barrels omit `/index.ts` (`~/configure`, `./__generated__`, `~/index` for the package root).
|
|
39
|
+
- **Breaking: removed `POST /tools/*`** — use `/api/*` REST routes; OpenAPI paths updated.
|
|
40
|
+
- **Breaking: `leaf.apiResponse` removed** — use `http.successContentType` / `http.contentDisposition`.
|
|
41
|
+
- **Breaking: global `hidden` removed** — use per-surface `cli.hidden`, `http.hidden`, `mcpTool.hidden`.
|
|
42
|
+
- **Breaking: HTTP rename (`api` → `http`)** — `apiServer` → `httpServer`, `Cli.serveApi()` → `serveHttp()`, builtin `myapp api` → `myapp http`, `ctx.invocation: "http"`, `capabilities.http`, `src/api/` → `src/http/`, reserved command `http`. OpenAPI generator names unchanged (`generateOpenApi`).
|
|
43
|
+
- **Breaking: docs topic `api` → `cli`** — `docs api` → `docs cli`, saved `docs/cli.md`, `src/docs/cli-guide.ts`. Reserved docs topic key `cli`.
|
|
44
|
+
- **Breaking: removed deprecated input reads** — `readLeafInputs`, `readLeafInputsAsync`, `ctx.readLeafInputs()`, `ctx.readLeafInputsAsync()`. Use `ctx.inputs` / `ctx.inputsAs<T>()`.
|
|
45
|
+
- **Breaking: removed `mcpTool.outputSchema`** — use leaf `outputSchema` only.
|
|
46
|
+
- **Breaking: `src/install/` → `src/configure/artifacts/`** — configure artifact modules colocated under configure; deprecated install stubs removed.
|
|
47
|
+
- **`docs` built-in default-on** — built-in subcommands (`cli-schema`, `cli`, `skill`, conditional `mcp`/`http`/`openapi`) work with no `docs` config block.
|
|
48
|
+
- **`docs.topics` optional** — add `topics` only when bundling consumer markdown.
|
|
49
|
+
- **Experimental callouts** — blockquotes in `docs/mcp.md`, `docs/ai-skills.md`, `docs/configure.md`; `@experimental` JSDoc on MCP/configure bundle types.
|
|
50
|
+
|
|
51
|
+
### Removed
|
|
52
|
+
|
|
53
|
+
- **Breaking: bare `myapp docs` auto-print** — shows router help; `defaultTopic` removed.
|
|
54
|
+
- **Breaking: user `docs` command** — reserved by default; opt out with `docs: { enabled: false }`.
|
|
55
|
+
|
|
56
|
+
### Migration (6.1.2)
|
|
57
|
+
|
|
58
|
+
| Before | After |
|
|
59
|
+
| --- | --- |
|
|
60
|
+
| `POST /tools/:name` | `/api/...` REST (see `openapi.json`) |
|
|
61
|
+
| `hidden: true` on node | `cli.hidden`, `http.hidden`, or `mcpTool.hidden` |
|
|
62
|
+
| `apiResponse.contentType` | `http.successContentType` |
|
|
63
|
+
| `apiServer` | `httpServer` |
|
|
64
|
+
| `myapp api` | `myapp http` |
|
|
65
|
+
| `invocation: "api"` | `invocation: "http"` |
|
|
66
|
+
| `docs api` / `docs/api.md` | `docs cli` / `docs/cli.md` |
|
|
67
|
+
| `ctx.readLeafInputs()` | `ctx.inputs` or `ctx.inputsAs<T>()` |
|
|
68
|
+
| `mcpTool.outputSchema` | `outputSchema` on the leaf |
|
|
69
|
+
| `from "argsbarg/install/..."` | `from "argsbarg/configure/artifacts/..."` (internal) |
|
|
70
|
+
|
|
71
|
+
Regenerate saved docs (`just docgen`) and run `argsbarg schemagen` after upgrading.
|
|
72
|
+
|
|
73
|
+
## [6.1.2] - 2026-07-23
|
|
74
|
+
|
|
75
|
+
### Added
|
|
76
|
+
|
|
77
|
+
- **`kind: "json"` on `CliLeaf`** — pure JSON body leaves with no CLI flags. Requires `inputSchema`; forbids `options` and `positionals`. CLI accepts one JSON positional or piped stdin; MCP/HTTP use the tool args object directly. **`isJsonLeaf()`** helper exported.
|
|
78
|
+
|
|
10
79
|
## [6.1.1] - 2026-07-23
|
|
11
80
|
|
|
12
81
|
### Added
|
|
@@ -764,7 +833,9 @@ const cli = { ... } satisfies CliProgram; // or : CliProgram
|
|
|
764
833
|
- 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`).
|
|
765
834
|
- Imports: use `CliPositional` where needed; replace `CliOptionDef` with `CliOption` or `CliPositional` as appropriate.
|
|
766
835
|
|
|
767
|
-
[Unreleased]: https://github.com/bdombro/bun-argsbarg/compare/v6.1.
|
|
836
|
+
[Unreleased]: https://github.com/bdombro/bun-argsbarg/compare/v6.1.3...HEAD
|
|
837
|
+
[6.1.3]: https://github.com/bdombro/bun-argsbarg/releases/tag/v6.1.3
|
|
838
|
+
[6.1.2]: https://github.com/bdombro/bun-argsbarg/releases/tag/v6.1.2
|
|
768
839
|
[6.1.1]: https://github.com/bdombro/bun-argsbarg/releases/tag/v6.1.1
|
|
769
840
|
[6.1.0]: https://github.com/bdombro/bun-argsbarg/releases/tag/v6.1.0
|
|
770
841
|
[6.0.2]: https://github.com/bdombro/bun-argsbarg/releases/tag/v6.0.2
|
package/README.md
CHANGED
|
@@ -95,14 +95,14 @@ Every app gets:
|
|
|
95
95
|
- `completion bash` **/** `completion zsh` **/** `completion fish` — print shell completion scripts to stdout (injected by `Cli.run()`).
|
|
96
96
|
- `version` — print `CliProgram.version` (`myapp version`).
|
|
97
97
|
- `mcp` — when `mcpServer.enabled` is `true`, run as an MCP stdio server (`myapp mcp`).
|
|
98
|
-
- `
|
|
99
|
-
- `docs` —
|
|
98
|
+
- `http` — when `httpServer.enabled` is `true`, run as an HTTP tool server (`myapp http`).
|
|
99
|
+
- `docs` — print bundled markdown topics, schema JSON, CLI markdown, and generated skill content (`myapp docs cli`, `myapp docs cli-schema`, `myapp docs skill`, …). Enabled by default; opt out with `docs: { enabled: false }`. See [docs/bundled-docs.md](docs/bundled-docs.md).
|
|
100
100
|
- `configure` — manage agent skills, MCP config, and app config (`myapp configure --sync --yes` after Homebrew install). See [docs/configure.md](docs/configure.md).
|
|
101
101
|
|
|
102
102
|
Do not declare a top-level command named `completion`, `version`, or `configure` — they are reserved.
|
|
103
103
|
When `mcpServer.enabled` is `true`, do not declare a top-level command named `mcp` — it is reserved for the MCP built-in.
|
|
104
|
-
When `
|
|
105
|
-
When
|
|
104
|
+
When `httpServer.enabled` is `true`, do not declare a top-level command named `http` — it is reserved for the HTTP built-in.
|
|
105
|
+
When docs is enabled (default), do not declare a top-level command named `docs` — it is reserved for the docs built-in. Opt out with `docs: { enabled: false }` if needed.
|
|
106
106
|
|
|
107
107
|
### MCP (AI agents)
|
|
108
108
|
|
|
@@ -110,11 +110,11 @@ Opt in on the program root with `mcpServer: { enabled: true }`, then run `myapp
|
|
|
110
110
|
|
|
111
111
|
See **[docs/mcp.md](docs/mcp.md)** for configuration, env bootstrapping, custom resources, Cursor setup, and protocol details. See **[docs/cli-program.md](docs/cli-program.md)** for schema authoring (consumer apps: run `bunx argsbarg create` or refresh with `bun scripts/merge-cli-program-rule.ts .` from the argsbarg package).
|
|
112
112
|
|
|
113
|
-
### HTTP
|
|
113
|
+
### HTTP tool server
|
|
114
114
|
|
|
115
|
-
Opt in on the program root with `
|
|
115
|
+
Opt in on the program root with `httpServer: { enabled: true }`, then run `myapp http` for an HTTP REST server (default `http://127.0.0.1:3000`). Nested CLI paths map to `/api/...` with inferred HTTP verbs. Discover routes via `GET /openapi.json`.
|
|
116
116
|
|
|
117
|
-
See **[docs/
|
|
117
|
+
See **[docs/http-server.md](docs/http-server.md)** for endpoints, curl examples, and response shapes.
|
|
118
118
|
|
|
119
119
|
### Configure CLI
|
|
120
120
|
|
|
@@ -209,9 +209,7 @@ Add `CliPositional` entries to the command’s `positionals` list (separate from
|
|
|
209
209
|
- `ctx.dateOpt("on")` / `ctx.dateTimeOpt("since")` — ISO date / date-time options.
|
|
210
210
|
- `ctx.inputs` — coerced option and positional values for the current leaf; when `inputSchema` is set, validated before the handler runs and cached on `ctx`.
|
|
211
211
|
- `ctx.inputsAs<T>()` — `ctx.inputs` cast to a schemagen or app input type.
|
|
212
|
-
- `ctx.
|
|
213
|
-
- `ctx.jsonOpt(name)` — parsed Json option (flag, preloaded stdin, or MCP/API `toolArgs`).
|
|
214
|
-
- `ctx.readLeafInputsAsync()` — deprecated alias for `readLeafInputs()`.
|
|
212
|
+
- `ctx.jsonOpt(name)` — parsed Json option (flag, preloaded stdin, or MCP/HTTP `toolArgs`).
|
|
215
213
|
- `ctx.typedOpt<T>("custom", parseFn)` — custom parsing for type-safe option resolution.
|
|
216
214
|
- `ctx.args` — positional words in order as `string[]`.
|
|
217
215
|
- `ctx.positional("name")` — named positional lookup; varargs slots return `string[]`, single slots return `string | undefined`.
|
|
@@ -221,7 +219,7 @@ Add `CliPositional` entries to the command’s `positionals` list (separate from
|
|
|
221
219
|
|
|
222
220
|
### Capabilities (built-ins)
|
|
223
221
|
|
|
224
|
-
`completion`, `version`, `
|
|
222
|
+
`completion`, `version`, `configure`, `mcp`, and `http` are not part of your schema — they are injected at runtime from program-level config (`mcpServer`, `httpServer`, `configure`, `docs`). Reserved command names: `completion` and `version` always; `configure` unless `configure.enabled: false`; `docs` unless `docs.enabled: false` (default on); `mcp` when `mcpServer.enabled` is `true`; `http` when `httpServer.enabled` is `true`.
|
|
225
223
|
|
|
226
224
|
## Examples
|
|
227
225
|
|
|
@@ -232,7 +230,7 @@ Check the `examples/` directory for full working scripts:
|
|
|
232
230
|
| --------------------- | ------------------------ | ------------------------------------------------------------------------------------------------- |
|
|
233
231
|
| `ArgsBargMinimal` | `examples/minimal.ts` | String + presence flags, `MissingOrUnknown` fallback. |
|
|
234
232
|
| `ArgsBargNested` | `examples/nested.ts` | Nested command tree, positional tails, async handlers. |
|
|
235
|
-
| `ArgsBargFormats` | `examples/formats.ts` | `CliValueFormat`, `default`, `
|
|
233
|
+
| `ArgsBargFormats` | `examples/formats.ts` | `CliValueFormat`, `default`, `ctx.inputs`. |
|
|
236
234
|
| `ArgsBargFullExample` | `examples/full-example/` | **Copy template:** all builtins, schemagen, Homebrew justfile, `outputSchema`, `from "argsbarg"`. |
|
|
237
235
|
|
|
238
236
|
|
|
@@ -263,16 +261,16 @@ Edit `scripts/create-identity.ts` in the new repo to set `desc` (used by `progra
|
|
|
263
261
|
|
|
264
262
|
Verify an existing tree: `bunx argsbarg create --check .`
|
|
265
263
|
|
|
266
|
-
To refresh
|
|
264
|
+
To refresh Cursor rules in an existing consumer: `bun scripts/merge-cli-program-rule.ts .` and `bun scripts/merge-code-rule.ts .` from an argsbarg checkout (or pass the npm package path to the template).
|
|
267
265
|
|
|
268
266
|
### What the full-example template includes
|
|
269
267
|
|
|
270
268
|
|
|
271
269
|
| Area | Files / wiring |
|
|
272
270
|
| --------------------- | -------------------------------------------------------------------------------------- |
|
|
273
|
-
| All builtins | `completion`, `version`, `configure`, `docs`, `mcp`, `
|
|
274
|
-
| `
|
|
275
|
-
| `outputSchema` | `src/commands/status/types.ts` → `
|
|
271
|
+
| All builtins | `completion`, `version`, `configure`, `docs`, `mcp`, `http`, `configure get`/`set` |
|
|
272
|
+
| `@sg` schemagen | `/** @sg */` on types in `src/**/*.ts` → `{TypeName}Schema` in `__generated__/` |
|
|
273
|
+
| `outputSchema` | `src/commands/status/types.ts` → `StatusJsonOutputSchema` from `__generated__/` |
|
|
276
274
|
| Schemagen | `just schemagen` → `argsbarg schemagen` (justfile exports `node_modules/.bin` on `PATH`) |
|
|
277
275
|
| Command layout | `src/commands/<name>/command.ts`; registration in `src/program.ts` |
|
|
278
276
|
| MCP doc topics | `docs.topics` auto-exposed as `<key>://docs/<topic>` resources when docs + MCP enabled |
|
|
@@ -313,8 +311,8 @@ The package root (`argsbarg` / `src/index.ts`) exports the types and runtime you
|
|
|
313
311
|
| `CliProgram`, `CliOption`, `CliPositional`, `CliHandler` | Schema and handler types. |
|
|
314
312
|
| `CliOptionKind`, `CliValueFormat`, `CliFallbackMode` | Option kinds, value formats (`duration`, `comma-list`, `date`, `date-time`), and root fallback behavior. |
|
|
315
313
|
| `CliSchemaValidationError` | Thrown when the static command tree violates schema rules. |
|
|
316
|
-
| `CliContext` | Handler context (`ctx.hasFlag`, `ctx.stringOpt`, `ctx.durationOpt`, `ctx.
|
|
317
|
-
| `CliLeafInputs` | Record type returned by `
|
|
314
|
+
| `CliContext` | Handler context (`ctx.hasFlag`, `ctx.stringOpt`, `ctx.durationOpt`, `ctx.inputs`, `ctx.invocation`, …). |
|
|
315
|
+
| `CliLeafInputs` | Record type returned by `ctx.inputs` — coerced option/positional values keyed by schema name. |
|
|
318
316
|
| `Cli` | Runtime: validate + freeze program, `run()`, `invoke()`, `serveMcp()`, `appConfig` getter, `exportCommandSchema()`, `exportAppConfigSchema()`. |
|
|
319
317
|
| `CliInvokeResult`, `CliInvokeKind` | Result types from `cli.invoke()`. |
|
|
320
318
|
| `CliAppConfig`, `CliAppConfigEntry` | App config block on the program root (`entries` metadata overlay + optional `jsonSchema`). |
|
|
@@ -322,7 +320,7 @@ The package root (`argsbarg` / `src/index.ts`) exports the types and runtime you
|
|
|
322
320
|
| `parseDurationMs`, `parseCommaList`, `parseDate`, `parseDateTime` | Optional format parsers for use outside handlers. |
|
|
323
321
|
|
|
324
322
|
|
|
325
|
-
Reserved identifiers (validated at startup): root commands `completion`, `version`, `
|
|
323
|
+
Reserved identifiers (validated at startup): root commands `completion`, `version`, `configure`, `docs` (unless `docs.enabled: false`), `mcp` (when `mcpServer.enabled` is `true`), and `http` (when `httpServer.enabled` is `true`).
|
|
326
324
|
|
|
327
325
|
---
|
|
328
326
|
|
package/bin/argsbarg
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
SOURCE="${BASH_SOURCE[0]}"
|
|
4
|
+
while [ -L "$SOURCE" ]; do
|
|
5
|
+
DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
|
|
6
|
+
SOURCE="$(readlink "$SOURCE")"
|
|
7
|
+
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
|
|
8
|
+
done
|
|
9
|
+
ROOT="$(cd "$(dirname "$SOURCE")/.." && pwd)"
|
|
10
|
+
exec bun "$ROOT/src/cli-tool/main.ts" "$@"
|
package/docs/README.md
CHANGED
|
@@ -8,8 +8,9 @@ Start here to pick the right guide.
|
|
|
8
8
|
| **Authoring a `CliProgram`** (humans or agents) | [cli-program.md](cli-program.md) — schema, formats, headless, `read*Flags` |
|
|
9
9
|
| **JSON stdout / `outputSchema`** | [output-schema.md](output-schema.md) — codegen pipeline, JSDoc, narrowing |
|
|
10
10
|
| **App config / `program.appConfig`** | [config-schema.md](config-schema.md) — flat JSON file, `ctx.appConfig`, codegen |
|
|
11
|
+
| **JSON Schema subset (validation)** | [json-schema-subset.md](json-schema-subset.md) — supported keywords for config and `inputSchema` |
|
|
11
12
|
| **Exposing MCP tools** | [mcp.md](mcp.md) — stdio server, `inputSchema`, varargs, `configure --sync` |
|
|
12
|
-
| **HTTP tool server** | [
|
|
13
|
+
| **HTTP tool server** | [http-server.md](http-server.md) — `myapp http`, endpoints, curl examples |
|
|
13
14
|
| **Shipping configure / agent artifacts** | [configure.md](configure.md) — Homebrew + `myapp configure --sync` |
|
|
14
15
|
| **Homebrew tap-from-repo distribution** | [distribution-homebrew.md](distribution-homebrew.md) — formula pattern, `argsbarg create` |
|
|
15
16
|
| **Bundling `myapp docs` topics** | [bundled-docs.md](bundled-docs.md) — consumer docgen vs framework docs |
|
|
@@ -32,7 +33,7 @@ Examples are included in the npm tarball (`package.json` `files`). After `bun ad
|
|
|
32
33
|
| Source | What it is | Where it lives |
|
|
33
34
|
| --- | --- | --- |
|
|
34
35
|
| **Framework docs** | How argsbarg works; authoring conventions | This directory — shipped in `node_modules/argsbarg/docs/` after `bun add argsbarg` |
|
|
35
|
-
| **Consumer docgen** | *Your* command tree, API, MCP guide for *your* app | `myapp docs
|
|
36
|
+
| **Consumer docgen** | *Your* command tree, API, MCP guide for *your* app | `myapp docs cli`, `docs cli-schema`, `docs mcp` — written to `./docs/` with `--save` |
|
|
36
37
|
| **Cursor rule** | Thin tripwire telling agents to read framework docs | `node_modules/argsbarg/examples/full-example/.cursor/rules/cli-program.mdc` — included by `create`; refresh with `merge-cli-program-rule.ts` |
|
|
37
38
|
|
|
38
|
-
Agents do **not** load `node_modules/argsbarg/docs/` unless your repo references them (Cursor rule, `AGENTS.md`, or an `alwaysApply` project rule). Generated `./docs/
|
|
39
|
+
Agents do **not** load `node_modules/argsbarg/docs/` unless your repo references them (Cursor rule, `AGENTS.md`, or an `alwaysApply` project rule). Generated `./docs/cli.md` in a consumer repo describes **your** CLI, not argsbarg itself.
|
package/docs/ai-skills.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Agent skills
|
|
2
2
|
|
|
3
|
+
> This feature is experimental.
|
|
4
|
+
|
|
3
5
|
ArgsBarg can generate Cursor and Claude Code skill directories (`SKILL.md` + `reference.md`) from your CLI schema.
|
|
4
6
|
|
|
5
7
|
## Install via `configure` (recommended)
|
|
@@ -35,7 +37,7 @@ For library use, call `cliSkillInstall(root, "cursor" | "claude", { global: true
|
|
|
35
37
|
## Generated content
|
|
36
38
|
|
|
37
39
|
- **`SKILL.md`** — YAML frontmatter, compact command index, pitfalls, and a pointer to `reference.md`
|
|
38
|
-
- **`reference.md`** — full `docs
|
|
40
|
+
- **`reference.md`** — full `docs cli` markdown reference
|
|
39
41
|
|
|
40
42
|
Installed files include an HTML comment hint (`Generated by myapp configure; do not edit.`) after SKILL.md frontmatter and at the top of `reference.md`.
|
|
41
43
|
|
|
@@ -49,7 +51,7 @@ Skills describe **shell invocation only** — no MCP setup, `mcp.json`, or `tool
|
|
|
49
51
|
| **`myapp configure`** (skill targets) | Persists optimized skill bundle (`SKILL.md` index + `reference.md` full API) |
|
|
50
52
|
| **`myapp docs`** (requires `docs`) | Bundled markdown on stdout (`docs mcp` when MCP enabled) |
|
|
51
53
|
|
|
52
|
-
`SKILL.md` is the routing index; `reference.md` matches `docs
|
|
54
|
+
`SKILL.md` is the routing index; `reference.md` matches `docs cli`. Prefer `configure` over `docs skill` for agents. See [cli-program.md](cli-program.md).
|
|
53
55
|
|
|
54
56
|
**Claude Code plugin** (`mcpServer.claudePlugin: true` → `mcp bundle` writes `dist/claude-plugin/<name>.zip`) ships a separate MCP pointer skill (`SKILL.md` only) that routes agents to the bundled MCP server. This is a **dist artifact**, not installed via `configure`. Use **`configure`** for persisted shell-oriented skills.
|
|
55
57
|
|
package/docs/bundled-docs.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Bundled documentation (`docs`)
|
|
2
2
|
|
|
3
|
-
ArgsBarg
|
|
3
|
+
ArgsBarg exposes the built-in `docs` command group on every CLI by default. Built-in subcommands (`cli-schema`, `cli`, `skill`, and conditional `mcp` / `http` / `openapi`) work with zero config. Add optional `docs.topics` for consumer-authored markdown, or opt out with `docs: { enabled: false }`.
|
|
4
4
|
|
|
5
5
|
## Framework docs vs your app's docgen
|
|
6
6
|
|
|
@@ -9,16 +9,29 @@ Two documentation layers often coexist in a consumer repo:
|
|
|
9
9
|
| Layer | Contents | How agents/humans get it |
|
|
10
10
|
| --- | --- | --- |
|
|
11
11
|
| **Argsbarg framework** | How to author `CliProgram`, MCP varargs policy, headless patterns | `node_modules/argsbarg/docs/` — wire via [full-example Cursor rule](../examples/full-example/.cursor/rules/cli-program.mdc) or `AGENTS.md` |
|
|
12
|
-
| **Your CLI (docgen)** | Your command tree, options, MCP tool list, install notes | `myapp docs
|
|
12
|
+
| **Your CLI (docgen)** | Your command tree, options, MCP tool list, install notes | `myapp docs cli`, `docs cli-schema`, `docs mcp` — save with `--save` to `./docs/` |
|
|
13
13
|
|
|
14
|
-
`docs
|
|
14
|
+
`docs cli` and `docs cli-schema` embed each leaf’s `outputSchema` when set — see [output-schema.md](output-schema.md) for how to generate and wire schemas.
|
|
15
15
|
|
|
16
|
-
Do not confuse them: editing `./docs/
|
|
16
|
+
Do not confuse them: editing `./docs/cli.md` after docgen updates **your** app reference; it does not change argsbarg's framework guides. When MCP behavior changes (e.g. varargs arrays in 3.6+), update consumer `docs/mcp.md` via **`myapp docs mcp --save`** and bump the `argsbarg` dependency.
|
|
17
17
|
|
|
18
18
|
See [docs/README.md](README.md) for the full documentation map.
|
|
19
19
|
|
|
20
20
|
## Quick start
|
|
21
21
|
|
|
22
|
+
Zero config — built-in docgen only:
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
const cli = {
|
|
26
|
+
key: "myapp",
|
|
27
|
+
version: "1.0.0",
|
|
28
|
+
description: "My app.",
|
|
29
|
+
commands: [/* ... */],
|
|
30
|
+
} satisfies CliProgram;
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Optional consumer markdown topics:
|
|
34
|
+
|
|
22
35
|
```typescript
|
|
23
36
|
import readmeText from "../README.md" with { type: "text" };
|
|
24
37
|
import archText from "../docs/architecture.md" with { type: "text" };
|
|
@@ -28,7 +41,6 @@ const cli = {
|
|
|
28
41
|
version: "1.0.0",
|
|
29
42
|
description: "My app.",
|
|
30
43
|
docs: {
|
|
31
|
-
enabled: true,
|
|
32
44
|
topics: {
|
|
33
45
|
readme: { text: readmeText },
|
|
34
46
|
architecture: { text: archText, description: "Contributor architecture notes." },
|
|
@@ -39,32 +51,31 @@ const cli = {
|
|
|
39
51
|
```
|
|
40
52
|
|
|
41
53
|
```bash
|
|
42
|
-
myapp docs #
|
|
54
|
+
myapp docs # router help (subcommand list)
|
|
43
55
|
myapp docs readme
|
|
44
56
|
myapp docs architecture
|
|
45
57
|
myapp docs cli-schema # full command tree as JSON
|
|
46
|
-
myapp docs
|
|
58
|
+
myapp docs cli # command tree as markdown
|
|
47
59
|
myapp docs skill # generated Cursor SKILL.md
|
|
48
60
|
myapp docs mcp # auto-generated when mcpServer.enabled
|
|
49
|
-
myapp docs http # auto-generated when
|
|
50
|
-
myapp docs openapi # OpenAPI 3.1 JSON when
|
|
61
|
+
myapp docs http # auto-generated when httpServer.enabled
|
|
62
|
+
myapp docs openapi # OpenAPI 3.1 JSON when httpServer.enabled
|
|
51
63
|
myapp docs readme --save # write ./docs/readme.md
|
|
52
64
|
myapp docs cli-schema --save # write ./docs/cli-schema.json
|
|
53
65
|
myapp docs openapi --save # write ./docs/openapi.json
|
|
54
66
|
```
|
|
55
67
|
|
|
56
|
-
|
|
68
|
+
Top-level `myapp --help` points agents at `myapp docs skill`. The `docs skill` subcommand description recommends `configure` for a persisted bundle.
|
|
57
69
|
|
|
58
70
|
## Configuration
|
|
59
71
|
|
|
60
72
|
| Field | Default | Purpose |
|
|
61
73
|
| --- | --- | --- |
|
|
62
|
-
| `enabled` |
|
|
74
|
+
| `enabled` | `true` | Set `false` to disable the `docs` built-in |
|
|
63
75
|
| `description` | `"Print bundled CLI documentation."` | Router help for `myapp docs` |
|
|
64
|
-
| `
|
|
65
|
-
| `topics` | *(required)* | Topic key → `{ text, description? }` |
|
|
76
|
+
| `topics` | *(none)* | Optional topic key → `{ text, description? }` |
|
|
66
77
|
|
|
67
|
-
Reserved topic keys in `topics`: **`http`**, **`mcp`**, **`all`**, **`schema`**, **`
|
|
78
|
+
Reserved topic keys in `topics`: **`http`**, **`mcp`**, **`all`**, **`schema`**, **`cli`**, **`skill`**, **`openapi`** (reserved — use the matching `docs <name>` subcommand instead).
|
|
68
79
|
|
|
69
80
|
When `description` is omitted on a topic, ArgsBarg generates leaf help (`readme` → "Print README (user guide).").
|
|
70
81
|
|
|
@@ -80,29 +91,29 @@ Bun embeds the file when you `bun build --compile`. ArgsBarg does not read the f
|
|
|
80
91
|
|
|
81
92
|
Inline topics in your program root when the set is small; use a separate module only if the import map grows enough to clutter `index.tsx`.
|
|
82
93
|
|
|
83
|
-
## CLI schema, API, and skill (`docs cli-schema`, `docs
|
|
94
|
+
## CLI schema, API, and skill (`docs cli-schema`, `docs cli`, `docs skill`)
|
|
84
95
|
|
|
85
|
-
|
|
96
|
+
By default (unless `docs.enabled: false`):
|
|
86
97
|
|
|
87
98
|
- **`docs cli-schema`** — same JSON as the former root `--schema` flag (handlers omitted; built-in subtrees included for leaf roots).
|
|
88
|
-
- **`docs
|
|
99
|
+
- **`docs cli`** — markdown rendering of the same command tree (options, positionals, subcommands, fallback routing).
|
|
89
100
|
- **`docs skill`** — prints the compact `SKILL.md` index. Prefer `configure --sync --yes` for agents (persists index + full API in `reference.md`).
|
|
90
101
|
|
|
91
102
|
## MCP guide (`docs mcp`)
|
|
92
103
|
|
|
93
|
-
When both
|
|
104
|
+
When both docs (default) and `mcpServer.enabled` are `true`, ArgsBarg injects a **`docs mcp`** topic with an auto-generated guide: tool list, `program.appConfig`, schema resource URI, `configure --sync`, and protocol notes.
|
|
94
105
|
|
|
95
106
|
There is no override API in v1 — customize behavior via `mcpTool.description` on leaf commands.
|
|
96
107
|
|
|
97
108
|
## HTTP guide (`docs http`)
|
|
98
109
|
|
|
99
|
-
When both
|
|
110
|
+
When both docs (default) and `httpServer.enabled` are `true`, ArgsBarg injects a **`docs http`** topic with curl examples, endpoints, and tool list.
|
|
100
111
|
|
|
101
|
-
Shell invocation tables remain under **`docs
|
|
112
|
+
Shell invocation tables remain under **`docs cli`** (not HTTP).
|
|
102
113
|
|
|
103
114
|
## OpenAPI (`docs openapi`)
|
|
104
115
|
|
|
105
|
-
When both
|
|
116
|
+
When both docs (default) and `httpServer.enabled` are `true`, ArgsBarg injects a **`docs openapi`** topic with the same OpenAPI 3.1 document served at `GET /openapi.json`.
|
|
106
117
|
|
|
107
118
|
## MCP tools
|
|
108
119
|
|
|
@@ -114,13 +125,27 @@ All `docs` subcommands are hidden from MCP `tools/list` (`mcpTool: { enabled: fa
|
|
|
114
125
|
| --- | --- |
|
|
115
126
|
| `configure` (skill targets) | Writes compact `SKILL.md` + full-API `reference.md` to disk |
|
|
116
127
|
| `docs skill` | Print generated `SKILL.md` to stdout |
|
|
117
|
-
| `docs
|
|
128
|
+
| `docs cli` | Print command tree markdown to stdout |
|
|
118
129
|
| `docs cli-schema` | Print command tree JSON to stdout |
|
|
119
130
|
| `docs` | Bundled markdown topics on stdout |
|
|
120
131
|
| MCP docs topic resources | User `docs.topics` on the MCP wire (`<mcpId>://docs/<topic>`) when docs + MCP enabled |
|
|
121
132
|
| `mcp` | Callable tools + schema resource |
|
|
122
133
|
|
|
123
|
-
Do not declare a top-level command named **`docs`**
|
|
134
|
+
Do not declare a top-level command named **`docs`** unless `docs.enabled: false` — it is reserved by default.
|
|
135
|
+
|
|
136
|
+
## Agent artifact contract
|
|
137
|
+
|
|
138
|
+
Load one primary artifact per task — avoid pulling `reference.md`, `cli-schema.json`, and `openapi.json` together unless you need all three.
|
|
139
|
+
|
|
140
|
+
| Goal | Load |
|
|
141
|
+
| --- | --- |
|
|
142
|
+
| Route to the right command | `SKILL.md` (via `configure` or `docs skill`) |
|
|
143
|
+
| Full command tree + option prose | `reference.md` or `docs cli` |
|
|
144
|
+
| Machine-readable CLI tree + schemas | `docs cli-schema` |
|
|
145
|
+
| HTTP request/response shapes | `docs openapi` or `GET /openapi.json` |
|
|
146
|
+
| MCP tool list + env config | `docs mcp` |
|
|
147
|
+
|
|
148
|
+
Skill `reference.md` is **compact** (no embedded `outputSchema` JSON blocks). Fetch `cli-schema` or OpenAPI when you need exact shapes.
|
|
124
149
|
|
|
125
150
|
## Save to disk (`--save`)
|
|
126
151
|
|
|
@@ -131,7 +156,7 @@ Pass **`--save`** on `docs` or any docs subcommand to write files under **`./doc
|
|
|
131
156
|
| `docs readme --save` | `./docs/readme.md` |
|
|
132
157
|
| `docs cli-schema --save` | `./docs/cli-schema.json` |
|
|
133
158
|
| `docs openapi --save` | `./docs/openapi.json` |
|
|
134
|
-
| `docs
|
|
159
|
+
| `docs cli --save` | `./docs/cli.md` |
|
|
135
160
|
| `docs skill --save` | `./docs/skill.md` |
|
|
136
161
|
|
|
137
|
-
Argsbarg-generated markdown (`mcp`, `
|
|
162
|
+
Argsbarg-generated markdown (`mcp`, `http`, `skill`) includes a `Generated by … docs … --save` HTML comment (`skill` places it after YAML frontmatter so parsers still work). `cli-schema.json`, `openapi.json`, and argsbarg-generated markdown resolve `{argsbarg:program}` in `notes` to the program key. Consumer-authored topic files are written as-is.
|
package/docs/cli-program.md
CHANGED
|
@@ -34,12 +34,12 @@ const cli = {
|
|
|
34
34
|
key: "myapp",
|
|
35
35
|
version: "1.0.0",
|
|
36
36
|
description: "One-line summary of what the CLI does.",
|
|
37
|
-
|
|
37
|
+
httpServer: { enabled: true }, // myapp api → http://127.0.0.1:3000
|
|
38
38
|
commands: [/* ... */],
|
|
39
39
|
} satisfies CliProgram;
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
`
|
|
42
|
+
`httpServer` and `mcpServer` are independent. Tool exposure uses the same rules (`mcpTool.enabled: false` hides from MCP and HTTP). See [http-server.md](http-server.md).
|
|
43
43
|
|
|
44
44
|
## Inline schema by default
|
|
45
45
|
|
|
@@ -101,6 +101,18 @@ Option and positional `description` strings appear in `-h`, MCP `inputSchema`, a
|
|
|
101
101
|
|
|
102
102
|
Use root **`notes`** for cross-cutting hints shown in help (install commands, docs topics, VPN requirements).
|
|
103
103
|
|
|
104
|
+
## Agent-friendly schema
|
|
105
|
+
|
|
106
|
+
Descriptions and schemas are copied into MCP tools, HTTP OpenAPI, and generated skills — optimize for smaller, clearer agent payloads:
|
|
107
|
+
|
|
108
|
+
- Prefer **`kind: "json"`** leaves with schemagen `inputSchema` for complex tool bodies (one nested object beats many flat flags).
|
|
109
|
+
- Keep **`description`** strings short and action-oriented; put examples in **`notes`**, not duplicated in every option.
|
|
110
|
+
- Use **`hidden: true`** or **`mcpTool.enabled: false`** for debug/internal commands.
|
|
111
|
+
- For shape discovery: HTTP agents load **`docs openapi`** or `GET /openapi.json`; MCP agents use **`docs cli-schema`**; load full **`docs cli`** only when prose is needed.
|
|
112
|
+
- Skill **`reference.md`** uses a compact CLI guide (no inline `outputSchema` JSON) — see [bundled-docs.md](bundled-docs.md#agent-artifact-contract).
|
|
113
|
+
|
|
114
|
+
Validation keywords: [json-schema-subset.md](json-schema-subset.md).
|
|
115
|
+
|
|
104
116
|
## Well-known option names
|
|
105
117
|
|
|
106
118
|
Prefer **`yes`**, **`dry-run`**, and **`json`** when semantics match. They appear in `-h`, MCP `inputSchema`, and generated skills — write clear option `description` strings (e.g. "Skip confirmation; use for non-interactive runs.").
|
|
@@ -145,7 +157,7 @@ On **leaf commands**, set `outputSchema` to a JSON Schema describing stdout when
|
|
|
145
157
|
}
|
|
146
158
|
```
|
|
147
159
|
|
|
148
|
-
Exported in `docs cli-schema`, `docs
|
|
160
|
+
Exported in `docs cli-schema`, `docs cli`, skill `reference.md`, and MCP `tools/list`. Not validated at runtime yet. Pair with `notes` for prose examples; do not duplicate the full schema in `notes`.
|
|
149
161
|
|
|
150
162
|
For a **outputSchema codegen guidelines** (TypeScript types → JSON Schema → `outputSchema` constants), see [output-schema.md](output-schema.md).
|
|
151
163
|
|
|
@@ -211,8 +223,6 @@ const { limit, "skip-readiness": skipReadiness, timeout } = ctx.inputs;
|
|
|
211
223
|
const { format, invoice } = ctx.inputsAs<RenderInvoiceInput>();
|
|
212
224
|
```
|
|
213
225
|
|
|
214
|
-
**`readLeafInputs()`** — deprecated alias for `ctx.inputs`.
|
|
215
|
-
|
|
216
226
|
**`CliLeafInputs`** — return type of `ctx.inputs` (exported from `"argsbarg"`). A flat record keyed by **schema option and positional names** (hyphens preserved, e.g. `"skip-readiness"`). Values are coerced per kind/format:
|
|
217
227
|
|
|
218
228
|
| Schema | Value in `CliLeafInputs` |
|
|
@@ -230,6 +240,38 @@ const { format, invoice } = ctx.inputsAs<RenderInvoiceInput>();
|
|
|
230
240
|
|
|
231
241
|
Omitted options appear as `undefined` (not absent keys). Options with `default` are filled in post-parse before handlers run, so `ctx.inputs` and `durationOpt` see defaults. **`ctx.opts` always holds raw strings** — use typed accessors or `ctx.inputs` for coerced values.
|
|
232
242
|
|
|
243
|
+
### Typed `locals` and server `state`
|
|
244
|
+
|
|
245
|
+
**`ctx.locals`** — per-invocation bag populated in `program.hooks.beforeInvoke` (framework seeds `requestId` before hooks run). **`ctx.runtime.state`** — shared HTTP/MCP server bag (DB pools, readiness cache, etc.).
|
|
246
|
+
|
|
247
|
+
Argsbarg exports empty **`CliLocals`** and **`ServerState`** interfaces. Augment them once in your app so handlers see typed fields.
|
|
248
|
+
|
|
249
|
+
Create a `src/types/argsbarg.d.ts` file (or any name under your `tsconfig.json`'s `include` path) and ensure it contains at least one top-level `import` or `export` statement so TypeScript treats it as a module (module augmentation). Because it is matched by the `include` paths in `tsconfig.json`, TypeScript automatically loads it globally—no runtime or build-time imports are needed in your entry points!
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
// src/types/argsbarg.d.ts
|
|
253
|
+
import type { AppDb } from "../db";
|
|
254
|
+
|
|
255
|
+
declare module "argsbarg" {
|
|
256
|
+
interface CliLocals {
|
|
257
|
+
db: AppDb;
|
|
258
|
+
}
|
|
259
|
+
interface ServerState {
|
|
260
|
+
db?: AppDb;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
```typescript
|
|
266
|
+
// program.ts
|
|
267
|
+
hooks: { beforeInvoke: AppDb.attach },
|
|
268
|
+
|
|
269
|
+
// handler
|
|
270
|
+
handler: (ctx) => ctx.locals.db.workspaces.list(),
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
Use **`CliLocals`** for handler-facing per-request state (`ctx.locals.db`). Use **`ServerState`** for cross-request server resources (`ctx.runtime.state.db`). Populate both in `beforeInvoke` when needed.
|
|
274
|
+
|
|
233
275
|
### Json options and piped stdin
|
|
234
276
|
|
|
235
277
|
For nested tool bodies (e.g. invoice template data), declare a matching property in schemagen `inputType`, wire `inputSchema` on the leaf, and add a **`kind: Json`** option with the same name:
|
|
@@ -255,7 +297,31 @@ Use **`ctx.jsonOpt("invoice")`**, **`ctx.inputs`**, or **`ctx.inputsAs<MyInput>(
|
|
|
255
297
|
|
|
256
298
|
At most one `pipable` Json option per leaf. Json option names must appear in `inputSchema.properties` when a custom `inputSchema` is set.
|
|
257
299
|
|
|
258
|
-
|
|
300
|
+
### Pure JSON leaves (`kind: "json"`)
|
|
301
|
+
|
|
302
|
+
When the entire tool body is JSON (no CLI flags), set **`kind: "json"`** on the leaf with **`inputSchema`** and **no `options` or `positionals`**:
|
|
303
|
+
|
|
304
|
+
```typescript
|
|
305
|
+
{
|
|
306
|
+
key: "render-invoice",
|
|
307
|
+
description: "Render an invoice from template data",
|
|
308
|
+
kind: "json",
|
|
309
|
+
inputSchema,
|
|
310
|
+
handler: (ctx) => {
|
|
311
|
+
const { format, invoice } = ctx.inputsAs<RenderInvoiceInput>();
|
|
312
|
+
// ...
|
|
313
|
+
},
|
|
314
|
+
}
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
| Surface | How input is supplied |
|
|
318
|
+
| --- | --- |
|
|
319
|
+
| CLI | One JSON positional **or** pipe a JSON document to stdin |
|
|
320
|
+
| MCP / HTTP | Full tool args object (`ctx.toolArgs` / POST body) |
|
|
321
|
+
|
|
322
|
+
Example CLI: `jq '{format:"pdf", invoice:.}' data.json | myapp render-invoice`
|
|
323
|
+
|
|
324
|
+
See [output-schema.md](output-schema.md) for schemagen `inputType`, [http-server.md](http-server.md) for HTTP tool bodies, and [json-schema-subset.md](json-schema-subset.md) for supported schema keywords.
|
|
259
325
|
|
|
260
326
|
`CliLeafInputs` is intentionally untyped at the framework level. Narrow in your app (`read*Flags(ctx)` returning a typed struct) rather than expecting inference from `satisfies CliLeaf`.
|
|
261
327
|
|
|
@@ -269,7 +335,7 @@ For apps with **Ink + headless + MCP** (multiple surfaces per leaf), avoid scatt
|
|
|
269
335
|
|
|
270
336
|
| Layer | Responsibility |
|
|
271
337
|
| --- | --- |
|
|
272
|
-
| **`read*Flags(ctx)`** | Read coerced values from `ctx` (`
|
|
338
|
+
| **`read*Flags(ctx)`** | Read coerced values from `ctx` (`ctx.inputs`, `durationOpt`, `commaListOpt`, shared mutator flags) into one typed struct |
|
|
273
339
|
| **`resolve*Input(flags)`** | Cross-field validation and defaults; returns `{ ok, input }` or `{ ok: false, error }` |
|
|
274
340
|
|
|
275
341
|
The handler calls **`read*Flags` once**, passes the struct to **`resolve*Input`**, then branches to Ink, headless, or MCP with the same resolved input.
|
|
@@ -314,7 +380,7 @@ handler: async (ctx) => {
|
|
|
314
380
|
};
|
|
315
381
|
```
|
|
316
382
|
|
|
317
|
-
**JSON-only CLIs** — a single `readCommandOptions(ctx)` wrapping `
|
|
383
|
+
**JSON-only CLIs** — a single `readCommandOptions(ctx)` wrapping `ctx.inputs` per shared option set is usually enough; full `resolve*` layering is optional.
|
|
318
384
|
|
|
319
385
|
## Upgrading to 3.6+
|
|
320
386
|
|
|
@@ -334,7 +400,7 @@ CLI argv is unchanged: space-separated words. Use `format: comma-list` on an **o
|
|
|
334
400
|
|
|
335
401
|
### Value formats (optional)
|
|
336
402
|
|
|
337
|
-
Add `format`, `default`, or `pattern` on string **options**; read with `ctx.durationOpt`, `ctx.commaListOpt`, `ctx.
|
|
403
|
+
Add `format`, `default`, or `pattern` on string **options**; read with `ctx.durationOpt`, `ctx.commaListOpt`, `ctx.inputs`, etc. Replace hand-rolled `split(",")` / `parseDurationMs` try/catch where the schema can declare the shape.
|
|
338
404
|
|
|
339
405
|
### Handler layering (optional)
|
|
340
406
|
|
|
@@ -345,7 +411,7 @@ Ink + headless + MCP apps benefit from `read*Flags(ctx)` + `resolve*Input(flags)
|
|
|
345
411
|
Simple leaves (read args, print stdout) are already headless — no extra work. **Any handler that might mount Ink, prompt, or open a browser should also implement a scriptable fast path** for:
|
|
346
412
|
|
|
347
413
|
- **MCP** (`ctx.invocation === "mcp"` — always non-interactive)
|
|
348
|
-
- **HTTP API** (`ctx.invocation === "
|
|
414
|
+
- **HTTP API** (`ctx.invocation === "http"` — same headless rules as MCP)
|
|
349
415
|
- **Non-TTY CLI** (pipes, CI, `myapp cmd --yes` in a script)
|
|
350
416
|
- **Explicit flags** (`--json`, `--dry-run`)
|
|
351
417
|
|