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.
Files changed (229) hide show
  1. package/CHANGELOG.md +72 -1
  2. package/README.md +17 -19
  3. package/bin/argsbarg +10 -0
  4. package/docs/README.md +4 -3
  5. package/docs/ai-skills.md +4 -2
  6. package/docs/bundled-docs.md +50 -25
  7. package/docs/cli-program.md +76 -10
  8. package/docs/config-schema.md +10 -11
  9. package/docs/configure.md +2 -0
  10. package/docs/decisions.md +40 -0
  11. package/docs/developing.md +43 -5
  12. package/docs/http-server.md +171 -0
  13. package/docs/json-schema-subset.md +51 -0
  14. package/docs/mcp.md +4 -2
  15. package/docs/output-schema.md +55 -62
  16. package/examples/formats.ts +6 -6
  17. package/examples/full-example/Formula/full-example.rb +35 -0
  18. package/examples/full-example/README.md +20 -21
  19. package/examples/full-example/docs/README.md +1 -1
  20. package/examples/full-example/docs/cli-schema.json +1790 -98
  21. package/examples/full-example/docs/cli.md +1990 -0
  22. package/examples/full-example/docs/http.md +28 -29
  23. package/examples/full-example/docs/mcp.md +8 -22
  24. package/examples/full-example/docs/openapi.json +783 -50
  25. package/examples/full-example/docs/skill.md +10 -10
  26. package/examples/full-example/justfile +11 -1
  27. package/examples/full-example/src/commands/render-json/__generated__/RenderJsonInputSchema.json +15 -0
  28. package/examples/full-example/src/commands/render-json/__generated__/index.ts +5 -0
  29. package/examples/full-example/src/commands/render-json/command.test.ts +46 -0
  30. package/examples/full-example/src/commands/render-json/command.ts +30 -0
  31. package/examples/full-example/src/commands/render-json/types.ts +9 -0
  32. package/examples/full-example/src/commands/status/__generated__/StatusJsonOutputSchema.json +15 -0
  33. package/examples/full-example/src/commands/status/__generated__/index.ts +2 -2
  34. package/examples/full-example/src/commands/status/command.ts +5 -13
  35. package/examples/full-example/src/commands/status/types.ts +1 -14
  36. package/examples/full-example/src/commands/workspaces/__generated__/WorkspaceNameInputSchema.json +15 -0
  37. package/examples/full-example/src/commands/workspaces/__generated__/index.ts +5 -0
  38. package/examples/full-example/src/commands/workspaces/command.test.ts +58 -0
  39. package/examples/full-example/src/commands/workspaces/command.ts +94 -0
  40. package/examples/full-example/src/commands/workspaces/types.ts +6 -0
  41. package/examples/full-example/src/db/index.test.ts +86 -0
  42. package/examples/full-example/src/db/index.ts +101 -0
  43. package/examples/full-example/src/db/migrate.test.ts +35 -0
  44. package/examples/full-example/src/db/migrate.ts +69 -0
  45. package/examples/full-example/src/db/migrations/001_workspaces.sql +6 -0
  46. package/examples/full-example/src/db/tables/workspaces.ts +66 -0
  47. package/examples/full-example/src/program.ts +11 -36
  48. package/examples/full-example/src/types/argsbarg.d.ts +11 -0
  49. package/examples/full-example/src/types/md.d.ts +4 -0
  50. package/examples/full-example/tsconfig.json +5 -2
  51. package/examples/mcp-test.ts +1 -2
  52. package/examples/minimal.ts +1 -7
  53. package/examples/nested.ts +1 -2
  54. package/examples/option-required.ts +1 -1
  55. package/examples/servers.ts +4 -5
  56. package/index.d.ts +440 -136
  57. package/package.json +19 -2
  58. package/src/builtins/builtins.test.ts +7 -7
  59. package/src/builtins/completion-bash.ts +1 -1
  60. package/src/builtins/completion-fish.ts +1 -1
  61. package/src/builtins/completion-group.ts +4 -4
  62. package/src/builtins/completion-simulate-shared.ts +9 -0
  63. package/src/builtins/completion-zsh.ts +1 -1
  64. package/src/builtins/config.test.ts +3 -3
  65. package/src/builtins/config.ts +9 -9
  66. package/src/builtins/configure-copy.ts +2 -2
  67. package/src/builtins/configure.ts +4 -4
  68. package/src/builtins/dispatch.ts +19 -18
  69. package/src/builtins/export.ts +7 -5
  70. package/src/builtins/http.ts +68 -0
  71. package/src/builtins/mcp.ts +28 -4
  72. package/src/builtins/presentation.ts +6 -6
  73. package/src/builtins/registry.ts +6 -6
  74. package/src/builtins/scopes.ts +2 -2
  75. package/src/builtins/version.ts +1 -1
  76. package/src/cli-tool/full-example-capabilities.test.ts +10 -15
  77. package/src/cli-tool/main.ts +1 -1
  78. package/src/cli-tool/program.ts +3 -2
  79. package/src/cli-tool/prompt.ts +1 -1
  80. package/src/cli-tool/run-schemagen.ts +1 -3
  81. package/src/cli-tool/schemagen/cleanup.ts +6 -7
  82. package/src/cli-tool/schemagen/discover-schema-roots.ts +66 -120
  83. package/src/cli-tool/schemagen/index.ts +2 -2
  84. package/src/cli-tool/schemagen/names.ts +8 -13
  85. package/src/cli-tool/schemagen/run.ts +21 -28
  86. package/src/cli-tool/schemagen/schemagen.test.ts +136 -46
  87. package/src/config/bindings.test.ts +1 -1
  88. package/src/config/bindings.ts +1 -1
  89. package/src/config/bootstrap.test.ts +1 -1
  90. package/src/config/bootstrap.ts +36 -4
  91. package/src/config/context.test.ts +1 -1
  92. package/src/config/context.ts +1 -1
  93. package/src/config/entry.ts +1 -1
  94. package/src/config/file.test.ts +1 -1
  95. package/src/config/file.ts +3 -3
  96. package/src/config/manifest.ts +1 -1
  97. package/src/config/resolve.test.ts +1 -1
  98. package/src/config/resolve.ts +1 -1
  99. package/src/config/schema.ts +1 -1
  100. package/src/config/validate.ts +1 -1
  101. package/src/{install → configure/artifacts}/binary-placement.test.ts +1 -1
  102. package/src/{install → configure/artifacts}/binary-placement.ts +1 -1
  103. package/src/{install → configure/artifacts}/gh-release-update.ts +1 -1
  104. package/src/{install → configure/artifacts}/install-validate.test.ts +3 -3
  105. package/src/{install → configure/artifacts}/mcp-config.ts +1 -1
  106. package/src/{install → configure/artifacts}/mcp-opencode.test.ts +1 -1
  107. package/src/{install → configure/artifacts}/mcp-opencode.ts +1 -1
  108. package/src/{install → configure/artifacts}/paths.ts +5 -5
  109. package/src/configure/artifacts/plan.ts +24 -0
  110. package/src/{install → configure/artifacts}/status.test.ts +1 -1
  111. package/src/{install → configure/artifacts}/status.ts +2 -2
  112. package/src/{install → configure/artifacts}/target-base.ts +1 -1
  113. package/src/{install → configure/artifacts}/target-detect.ts +1 -1
  114. package/src/{install → configure/artifacts}/target-effective.ts +3 -9
  115. package/src/{install → configure/artifacts}/target-mcp-cli.ts +1 -1
  116. package/src/{install → configure/artifacts}/target-mcp-json.ts +1 -1
  117. package/src/{install → configure/artifacts}/target-plan-build.ts +2 -2
  118. package/src/{install → configure/artifacts}/target-registry.ts +2 -2
  119. package/src/{install → configure/artifacts}/target-scope.ts +3 -3
  120. package/src/{install → configure/artifacts}/target-skill.ts +1 -1
  121. package/src/{install → configure/artifacts}/target-types.ts +2 -2
  122. package/src/{install → configure/artifacts}/targets/app.ts +5 -5
  123. package/src/{install → configure/artifacts}/targets/chatgpt-mcp.ts +2 -2
  124. package/src/{install → configure/artifacts}/targets/claude-code-mcp.ts +2 -2
  125. package/src/{install → configure/artifacts}/targets/claude-desktop-mcp.ts +2 -2
  126. package/src/{install → configure/artifacts}/targets/claude-skill.ts +2 -2
  127. package/src/{install → configure/artifacts}/targets/codex-mcp.ts +2 -2
  128. package/src/{install → configure/artifacts}/targets/codex-skill.ts +2 -2
  129. package/src/{install → configure/artifacts}/targets/configure.ts +5 -5
  130. package/src/{install → configure/artifacts}/targets/cursor-mcp.ts +2 -2
  131. package/src/{install → configure/artifacts}/targets/cursor-skill.ts +2 -2
  132. package/src/{install → configure/artifacts}/targets/index.ts +1 -1
  133. package/src/{install → configure/artifacts}/targets/openclaw-mcp.ts +2 -2
  134. package/src/{install → configure/artifacts}/targets/openclaw-skill.ts +3 -3
  135. package/src/{install → configure/artifacts}/targets/opencode-mcp.ts +5 -5
  136. package/src/{install → configure/artifacts}/targets/opencode-skill.ts +3 -3
  137. package/src/{install → configure/artifacts}/targets.test.ts +1 -1
  138. package/src/{install → configure/artifacts}/uninstall.ts +1 -1
  139. package/src/configure/configure.test.ts +11 -11
  140. package/src/configure/index.ts +14 -14
  141. package/src/configure/prompt.ts +2 -2
  142. package/src/{context.ts → core/context.ts} +26 -20
  143. package/src/core/json-leaf.test.ts +156 -0
  144. package/src/{leaf-inputs.test.ts → core/leaf-inputs.test.ts} +7 -7
  145. package/src/{leaf-inputs.ts → core/leaf-inputs.ts} +76 -16
  146. package/src/{parse.test.ts → core/parse.test.ts} +97 -109
  147. package/src/{parse.ts → core/parse.ts} +173 -25
  148. package/src/{schema.ts → core/schema.ts} +25 -13
  149. package/src/{types.ts → core/types.ts} +238 -35
  150. package/src/{validate.ts → core/validate.ts} +51 -29
  151. package/src/docs/builtin.ts +8 -19
  152. package/src/docs/{api-guide.test.ts → cli-guide.test.ts} +21 -21
  153. package/src/docs/{api-guide.ts → cli-guide.ts} +45 -16
  154. package/src/docs/docs.test.ts +76 -41
  155. package/src/docs/http-guide.ts +37 -34
  156. package/src/docs/mcp-guide.ts +12 -14
  157. package/src/docs/mcp-resources.test.ts +2 -3
  158. package/src/docs/mcp-resources.ts +6 -11
  159. package/src/docs/resolve.ts +22 -30
  160. package/src/docs/save.ts +3 -3
  161. package/src/exports/cli.ts +47 -0
  162. package/src/exports/headless.ts +13 -0
  163. package/src/exports/http.ts +6 -0
  164. package/src/exports/mcp.ts +6 -0
  165. package/src/{headless.test.ts → headless/routing.test.ts} +3 -3
  166. package/src/{headless.ts → headless/routing.ts} +3 -3
  167. package/src/headless/tool-call.ts +114 -46
  168. package/src/help.test.ts +152 -0
  169. package/src/help.ts +54 -18
  170. package/src/hooks/builtin.ts +20 -0
  171. package/src/hooks/run.ts +142 -0
  172. package/src/http/openapi.ts +182 -0
  173. package/src/http/readiness.ts +78 -0
  174. package/src/{api → http}/result.ts +16 -5
  175. package/src/http/routes.ts +329 -0
  176. package/src/http/server.ts +225 -0
  177. package/src/index.ts +38 -25
  178. package/src/log/ecs.test.ts +43 -0
  179. package/src/log/ecs.ts +59 -0
  180. package/src/log/emitter.ts +166 -0
  181. package/src/mcp/bundle.ts +2 -2
  182. package/src/mcp/claude.test.ts +1 -1
  183. package/src/mcp/claude.ts +4 -4
  184. package/src/{hidden-mcpb.test.ts → mcp/hidden-mcpb.test.ts} +10 -9
  185. package/src/mcp/result.ts +2 -2
  186. package/src/mcp/server.ts +54 -6
  187. package/src/mcp/tools.ts +18 -20
  188. package/src/{capabilities.ts → runtime/capabilities.ts} +11 -11
  189. package/src/{cli-errors.ts → runtime/cli-errors.ts} +4 -4
  190. package/src/{cli.ts → runtime/cli.ts} +160 -50
  191. package/src/runtime/exposure.ts +102 -0
  192. package/src/{invoke.test.ts → runtime/invoke.test.ts} +31 -7
  193. package/src/server/context.ts +25 -0
  194. package/src/server/overrides.ts +112 -0
  195. package/src/skill/generate.ts +8 -8
  196. package/src/skill/hint.ts +1 -1
  197. package/src/skill/install.ts +2 -2
  198. package/src/skill/naming.ts +1 -1
  199. package/src/{test-fixtures.ts → test/fixtures.ts} +3 -2
  200. package/src/{config.integration.test.ts → test/integration/config.test.ts} +8 -8
  201. package/src/{api.integration.test.ts → test/integration/http.test.ts} +170 -67
  202. package/src/{mcp.integration.test.ts → test/integration/mcp.test.ts} +11 -57
  203. package/docs/api-server.md +0 -141
  204. package/examples/full-example/docs/api.md +0 -511
  205. package/examples/full-example/src/commands/status/__generated__/outputSchema.json +0 -28
  206. package/examples/full-example/src/config/__generated__/configSchema.json +0 -40
  207. package/examples/full-example/src/config/__generated__/index.ts +0 -5
  208. package/examples/full-example/src/config/types.ts +0 -24
  209. package/src/api/openapi.ts +0 -117
  210. package/src/api/server.ts +0 -120
  211. package/src/builtins/api.ts +0 -38
  212. package/src/hidden.ts +0 -30
  213. package/src/install/plan.ts +0 -53
  214. /package/src/{install → configure/artifacts}/detect-installed.ts +0 -0
  215. /package/src/{install → configure/artifacts}/gh-release-update.test.ts +0 -0
  216. /package/src/{install → configure/artifacts}/mcp-codex.test.ts +0 -0
  217. /package/src/{install → configure/artifacts}/mcp-codex.ts +0 -0
  218. /package/src/{install → configure/artifacts}/mcp-openclaw.test.ts +0 -0
  219. /package/src/{install → configure/artifacts}/mcp-openclaw.ts +0 -0
  220. /package/src/{install → configure/artifacts}/normalize-uninstall.ts +0 -0
  221. /package/src/{install → configure/artifacts}/normalize.ts +0 -0
  222. /package/src/{install → configure/artifacts}/opts.ts +0 -0
  223. /package/src/{install → configure/artifacts}/shell.ts +0 -0
  224. /package/src/{formats.test.ts → core/formats.test.ts} +0 -0
  225. /package/src/{formats.ts → core/formats.ts} +0 -0
  226. /package/src/{respond.ts → core/respond.ts} +0 -0
  227. /package/src/{types.test.ts → core/types.test.ts} +0 -0
  228. /package/src/{api → http}/schema-deref.test.ts +0 -0
  229. /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.1...HEAD
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
- - `api` — when `apiServer.enabled` is `true`, run as an HTTP tool server (`myapp api`).
99
- - `docs` — when `docs.enabled` is `true`, print bundled markdown topics, schema JSON, API markdown, and generated skill content (`myapp docs`, `myapp docs readme`, `myapp docs cli-schema`, `myapp docs api`, `myapp docs skill`, …). See [docs/bundled-docs.md](docs/bundled-docs.md).
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 `apiServer.enabled` is `true`, do not declare a top-level command named `api` — it is reserved for the HTTP API built-in.
105
- When `docs.enabled` is `true`, do not declare a top-level command named `docs` — it is reserved for the docs built-in.
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 API
113
+ ### HTTP tool server
114
114
 
115
- Opt in on the program root with `apiServer: { enabled: true }`, then run `myapp api` for an HTTP tool server (default `http://127.0.0.1:3000`). Same tool exposure as MCP: `POST /tools/:name` (hyphen-joined command paths). Discover tools via `GET /openapi.json`.
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/api-server.md](docs/api-server.md)** for endpoints, curl examples, and response shapes.
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.readLeafInputs()` — deprecated; use `ctx.inputs` or `ctx.inputsAs()`.
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`, `install`, `mcp`, and `api` are not part of your schema — they are injected at runtime from program-level config (`mcpServer`, `apiServer`, `install`, `docs`). Reserved command names: `completion` and `version` always; `install` unless `install.enabled: false`; `mcp` when `mcpServer.enabled` is `true`; `api` when `apiServer.enabled` is `true`; `docs` when `docs.enabled` is `true`.
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`, `readLeafInputs()`. |
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 the Cursor rule in an existing consumer: `bun scripts/merge-cli-program-rule.ts .` from an argsbarg checkout (or pass the npm package path to the template).
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`, `api`, `configure get`/`set` |
274
- | `program.appConfig` | `src/config/types.ts` → `configSchema` from `__generated__/` |
275
- | `outputSchema` | `src/commands/status/types.ts` → `outputSchema` from `__generated__/` |
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.readLeafInputs`, `ctx.invocation`, …). |
317
- | `CliLeafInputs` | Record type returned by `readLeafInputs()` — coerced option/positional values keyed by schema name. |
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`, `install`, `docs` (when `docs.enabled` is `true`), `mcp` (when `mcpServer.enabled` is `true`), and `api` (when `apiServer.enabled` is `true`).
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** | [api-server.md](api-server.md) — `myapp api`, endpoints, curl examples |
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 api`, `docs cli-schema`, `docs mcp` — written to `./docs/` with `--save` |
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/api.md` in a consumer repo describes **your** CLI, not argsbarg itself.
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 api` markdown reference
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 api`. Prefer `configure` over `docs skill` for agents. See [cli-program.md](cli-program.md).
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
 
@@ -1,6 +1,6 @@
1
1
  # Bundled documentation (`docs`)
2
2
 
3
- ArgsBarg can expose bundled markdown topics as the built-in `docs` command group. Opt in on the program root with `docs: { enabled: true, topics: { ... } }`.
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 api`, `docs cli-schema`, `docs mcp` — save with `--save` to `./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 api` 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.
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/api.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.
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 # first topic (readme) via fallback
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 api # command tree as markdown
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 apiServer.enabled
50
- myapp docs openapi # OpenAPI 3.1 JSON when apiServer.enabled
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
- When `docs` is enabled, top-level `myapp --help` points agents at `myapp docs skill`. The `docs skill` subcommand description recommends `configure` for a persisted bundle.
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` | *(required)* | Must be `true` when `docs` is set |
74
+ | `enabled` | `true` | Set `false` to disable the `docs` built-in |
63
75
  | `description` | `"Print bundled CLI documentation."` | Router help for `myapp docs` |
64
- | `defaultTopic` | first key in `topics` | `fallbackCommand` for bare `myapp docs` |
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`**, **`api`**, **`skill`**, **`openapi`** (reserved — use the matching `docs <name>` subcommand instead).
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 api`, `docs skill`)
94
+ ## CLI schema, API, and skill (`docs cli-schema`, `docs cli`, `docs skill`)
84
95
 
85
- When `docs.enabled` is `true`:
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 api`** — markdown rendering of the same command tree (options, positionals, subcommands, fallback routing).
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 `docs.enabled` 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.
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 `docs.enabled` and `apiServer.enabled` are `true`, ArgsBarg injects a **`docs http`** topic with curl examples, endpoints, and tool list.
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 api`** (not HTTP).
112
+ Shell invocation tables remain under **`docs cli`** (not HTTP).
102
113
 
103
114
  ## OpenAPI (`docs openapi`)
104
115
 
105
- When both `docs.enabled` and `apiServer.enabled` are `true`, ArgsBarg injects a **`docs openapi`** topic with the same OpenAPI 3.1 document served at `GET /openapi.json`.
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 api` | Print command tree markdown to stdout |
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`** when `docs.enabled` is `true` — it is reserved.
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 api --save` | `./docs/api.md` |
159
+ | `docs cli --save` | `./docs/cli.md` |
135
160
  | `docs skill --save` | `./docs/skill.md` |
136
161
 
137
- Argsbarg-generated markdown (`mcp`, `api`, `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.
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.
@@ -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
- apiServer: { enabled: true }, // myapp api → http://127.0.0.1:3000
37
+ httpServer: { enabled: true }, // myapp api → http://127.0.0.1:3000
38
38
  commands: [/* ... */],
39
39
  } satisfies CliProgram;
40
40
  ```
41
41
 
42
- `apiServer` and `mcpServer` are independent. Tool exposure uses the same rules (`mcpTool.enabled: false` hides from MCP and HTTP). See [api-server.md](api-server.md).
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 api`, 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`.
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
- See [output-schema.md](output-schema.md) for schemagen `inputType` and [api-server.md](api-server.md) for HTTP tool bodies.
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` (`readLeafInputs()`, `durationOpt`, `commaListOpt`, shared mutator flags) into one typed struct |
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 `readLeafInputs()` per shared option set is usually enough; full `resolve*` layering is optional.
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.readLeafInputs()`, etc. Replace hand-rolled `split(",")` / `parseDurationMs` try/catch where the schema can declare the shape.
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 === "api"` — same headless rules as MCP)
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