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
@@ -7,12 +7,12 @@ How to describe JSON stdout on leaf commands — and the **argsbarg schemagen**
7
7
  On **leaf commands**, set `outputSchema` to a JSON Schema object when the handler emits JSON (typically with `--json`, always for JSON-only commands, or on the MCP headless path).
8
8
 
9
9
  ```typescript
10
- import { outputSchema } from "./__generated__/index.ts";
10
+ import { StatusJsonOutputSchema } from "./__generated__";
11
11
 
12
12
  export const status = {
13
13
  key: "status",
14
14
  description: "Show environment status.",
15
- outputSchema,
15
+ outputSchema: StatusJsonOutputSchema,
16
16
  handler: async (ctx) => { /* writes JSON to stdout */ },
17
17
  } satisfies CliLeaf;
18
18
  ```
@@ -20,14 +20,14 @@ export const status = {
20
20
  | Where argsbarg uses it | Purpose |
21
21
  | --- | --- |
22
22
  | `myapp docs cli-schema` | Full command tree JSON export |
23
- | `myapp docs api` | Markdown per-command **Output** section |
23
+ | `myapp docs cli` | Markdown per-command **Output** section |
24
24
  | `myapp docs skill` | `reference.md` for agent skills |
25
25
  | MCP `tools/list` | Optional `outputSchema` on each tool |
26
26
  | HTTP `GET /openapi.json` | Response schema per tool |
27
27
 
28
28
  **Not validated at runtime** — argsbarg does not parse or reject handler stdout against the schema today. The schema is documentation and MCP/HTTP metadata.
29
29
 
30
- **Set on the leaf only** — not under `mcpTool` (legacy `mcpTool.outputSchema` still resolves but is deprecated).
30
+ **Set on the leaf only** — not under `mcpTool`.
31
31
 
32
32
  **Draft version** — argsbarg accepts any JSON Schema object (`type`, `properties`, `definitions`, etc.). Generators may emit draft-07 or draft 2020-12; docgen embeds the object as-is.
33
33
 
@@ -38,7 +38,7 @@ See [cli-program.md — Structured stdout](cli-program.md#structured-stdout) for
38
38
  | Approach | When |
39
39
  | --- | --- |
40
40
  | **Inline object** on the leaf | One-off commands, spikes, very small shapes |
41
- | **Codegen from TypeScript** | Multiple commands share a shape, nested objects, or you want rich `description` fields in `docs api` / skills |
41
+ | **Codegen from TypeScript** | Multiple commands share a shape, nested objects, or you want rich `description` fields in `docs cli` / skills |
42
42
 
43
43
  Production CLIs with several JSON commands tend to use **codegen** so types, handlers, and schemas stay aligned.
44
44
 
@@ -50,137 +50,129 @@ Reference implementations: **sqsp-qa-manager-poc**, **sqsp-workspaces**, **sqsp-
50
50
 
51
51
  ```mermaid
52
52
  flowchart LR
53
- subgraph types [types.ts]
54
- Config["export type configType = AppConfig"]
55
- Output["export type outputType = StatusJsonOutput"]
56
- Input["export type inputType = ToolInput (optional)"]
53
+ subgraph src [src/**/*.ts]
54
+ Sg["/** @sg */ export interface TypeName"]
57
55
  end
58
56
  subgraph gen [argsbarg schemagen]
59
- Discover["discover types.ts roots"]
57
+ Walk["walk src/ minus tests and __generated__"]
60
58
  Gen["ts-json-schema-generator"]
61
59
  end
62
60
  subgraph artifacts [Gitignored __generated__]
63
- Json["configSchema.json / inputSchema.json / outputSchema.json"]
61
+ Json["TypeNameSchema.json"]
64
62
  Index["index.ts re-exports"]
65
63
  end
66
64
  subgraph runtime [Runtime]
67
- Leaves["import { outputSchema } from ./__generated__/index.ts"]
65
+ Leaves["import { TypeNameSchema } from ./__generated__"]
68
66
  Docgen["just docgen"]
69
67
  end
70
- types --> Discover --> Gen --> Json
68
+ src --> Walk --> Gen --> Json
71
69
  Gen --> Index --> Leaves --> Docgen
72
70
  ```
73
71
 
74
72
  | Piece | Convention |
75
73
  | --- | --- |
76
74
  | Generator | [`ts-json-schema-generator`](https://github.com/vega/ts-json-schema-generator) (bundled as an argsbarg dependency) |
77
- | Discovery | Walk `src/**/types.ts` for `export type outputType` / `inputType` / `configType`; generate from the aliased type in the same file |
78
- | Artifacts | `src/**/__generated__/` — gitignored; run schemagen after clone or when `types.ts` changes |
75
+ | Discovery | Walk `src/**/*.ts` (exclude `*.test.ts`, `__generated__/`); find `/** @sg */` JSDoc immediately followed by `export interface` or `export type` |
76
+ | Artifacts | One `__generated__/` per source directory; `{TypeName}Schema.json` + `export const {TypeName}Schema` in `index.ts` |
79
77
  | Invocation | `just schemagen` — justfile exports `node_modules/.bin` on `PATH` for local `argsbarg` |
80
78
  | tsconfig | `"resolveJsonModule": true` |
81
79
  | CI | `just check`: `schemagen` → typecheck (no git diff on generated files) |
82
- | Cleanup | Schemagen removes orphan `__generated__/` dirs and stale JSON when roots or kinds are removed |
83
- | Docgen | `docgen` depends on `schemagen` so saved `./docs/api.md` and `./docs/cli-schema.json` are fresh |
80
+ | Cleanup | Schemagen removes orphan `__generated__/` dirs and stale JSON when roots are removed |
81
+ | Docgen | `docgen` depends on `schemagen` so saved `./docs/cli.md` and `./docs/cli-schema.json` are fresh |
84
82
 
85
83
  ### Declaring a schema root
86
84
 
87
- Put schema-facing interfaces and role exports in **`types.ts`** (or `core/types.ts` for shared shapes):
85
+ Mark any exported interface or type with `/** @sg */` on the line immediately above the declaration (no blank line):
88
86
 
89
87
  ```typescript
90
88
  // src/commands/status/types.ts
91
- /** JSON stdout for `myapp status --json`. */
89
+ /** @sg */
92
90
  export interface StatusJsonOutput {
93
- workspaces: WorkspaceStatus[];
91
+ version: string;
94
92
  }
93
+ ```
94
+
95
+ Handlers import types from the same module; leaves import schemas from `./__generated__`:
95
96
 
96
- /** Schemagen root for leaf outputSchema. */
97
- export type outputType = StatusJsonOutput;
97
+ ```typescript
98
+ import { StatusJsonOutputSchema } from "./__generated__";
98
99
  ```
99
100
 
100
- Handlers and other modules import from the same **`types.ts`** module.
101
+ Shared shapes in one directory share one `__generated__/index.ts`:
101
102
 
102
103
  ```typescript
103
- // src/ui/runHeadless/types.ts — shared by many mutating commands
104
+ // src/ui/runHeadless/types.ts
105
+ /** @sg */
104
106
  export interface HeadlessOpResult {
105
107
  command: string;
106
108
  exitCode: number;
107
109
  tasks: HeadlessTaskResult[];
108
110
  }
109
-
110
- export type outputType = HeadlessOpResult;
111
111
  ```
112
112
 
113
113
  ```typescript
114
- // src/commands/render-invoice/types.ts — custom HTTP/MCP body (pdf-gen)
114
+ // src/commands/render-invoice/types.ts
115
+ /** @sg */
115
116
  export interface RenderInvoiceInput {
116
117
  format: "pdf" | "html";
117
118
  invoice: InvoiceData;
118
119
  }
119
120
 
121
+ /** @sg */
120
122
  export interface RenderInvoiceOutput {
121
123
  bytes: number;
122
124
  }
123
-
124
- export type inputType = RenderInvoiceInput;
125
- export type outputType = RenderInvoiceOutput;
126
125
  ```
127
126
 
128
- | Export | Role |
129
- | --- | --- |
130
- | `export type configType = AppConfig` | `program.appConfig.jsonSchema` (one per repo, typically `src/config/types.ts`) |
131
- | `export type outputType = …` | `leaf.outputSchema` |
132
- | `export type inputType = …` | `leaf.inputSchema` (only when the tool body is not flat CLI flags) |
127
+ Wire on the leaf or `program.appConfig`:
133
128
 
134
- **Domain helpers** and **role exports** live in `types.ts`. Commands without structured JSON omit role exports. Shared shapes (e.g. `HeadlessOpResult`) are defined once in `types.ts` with a single `outputType`; other commands import `{ outputSchema }` from that module’s `__generated__/index.ts`.
129
+ | Generated export | Typical use |
130
+ | --- | --- |
131
+ | `AppConfigSchema` | `program.appConfig.jsonSchema` (optional — `src/config/types.ts`) |
132
+ | `StatusJsonOutputSchema` | `leaf.outputSchema` |
133
+ | `RenderInvoiceInputSchema` | `leaf.inputSchema` |
135
134
 
136
- For nested MCP/HTTP bodies, add a `kind: Json` option (same name as the `inputType` property) and use `ctx.jsonOpt(...)` or `ctx.readLeafInputs()` — see [cli-program.md](cli-program.md#json-options-and-piped-stdin).
135
+ For nested MCP/HTTP bodies, add a `kind: Json` option (same name as the schema property) and use `ctx.jsonOpt(...)`, `ctx.inputs`, or `ctx.inputsAs<T>()` — see [cli-program.md](cli-program.md#json-options-and-piped-stdin).
137
136
 
138
137
  When you do **not** set `inputSchema`, argsbarg builds tool input from CLI `options` + `positionals`.
139
138
 
140
139
  ### Generated artifacts
141
140
 
142
- Schemagen writes under `__generated__/` beside each `types.ts` with role exports:
141
+ Schemagen writes under `__generated__/` beside the `@sg` source files in each directory:
143
142
 
144
- | Kind | Generated file | Exported const (from `__generated__/index.ts`) |
143
+ | Type name | Generated file | Exported const |
145
144
  | --- | --- | --- |
146
- | config | `configSchema.json` | `configSchema` |
147
- | output | `outputSchema.json` | `outputSchema` |
148
- | input | `inputSchema.json` | `inputSchema` |
145
+ | `StatusJsonOutput` | `StatusJsonOutputSchema.json` | `StatusJsonOutputSchema` |
146
+ | `RenderInvoiceInput` | `RenderInvoiceInputSchema.json` | `RenderInvoiceInputSchema` |
149
147
 
150
148
  Wire on the leaf:
151
149
 
152
150
  ```typescript
153
- import { outputSchema } from "./__generated__/index.ts";
151
+ import { StatusJsonOutputSchema } from "./__generated__";
154
152
 
155
153
  export const statusCommand = {
156
- outputSchema,
154
+ outputSchema: StatusJsonOutputSchema,
157
155
  // …
158
156
  } satisfies CliLeaf;
159
157
  ```
160
158
 
161
- Shared mutators:
162
-
163
- ```typescript
164
- import { outputSchema } from "../../../ui/runHeadless/__generated__/index.ts";
165
- ```
166
-
167
- App config:
159
+ App config (when used):
168
160
 
169
161
  ```typescript
170
- import { configSchema } from "./config/__generated__/index.ts";
162
+ import { AppConfigSchema } from "./config/__generated__";
171
163
 
172
- appConfig: { jsonSchema: configSchema, entries: { … } },
164
+ appConfig: { jsonSchema: AppConfigSchema, entries: { … } },
173
165
  ```
174
166
 
175
167
  ## Schema-facing types
176
168
 
177
- **Goal:** generated schemas match what handlers actually print, with descriptions agents can read in `docs api`.
169
+ **Goal:** generated schemas match what handlers actually print, with descriptions agents can read in `docs cli`.
178
170
 
179
- 1. **Schema roots** — `export interface` in `types.ts`, with `export type outputType = …` (or `inputType` / `configType`).
171
+ 1. **Schema roots** — `/** @sg */` immediately above `export interface` or `export type`, with per-field JSDoc.
180
172
  2. **Per property** — `/** … */` on every field that should appear in JSON Schema `properties` (including nested named types).
181
173
  3. **Unions / enums** — document the alias; generator emits `enum` / `anyOf` with type-level description.
182
174
  4. **Formats** — property JSDoc can include `@format date-time` for ISO timestamps; add a smoke test that the generated property has `format: "date-time"`.
183
- 5. **Do not hand-edit** `__generated__/` — change types/JSDoc in `types.ts`, run `just schemagen`.
175
+ 5. **Do not hand-edit** `__generated__/` — change types/JSDoc in source files, run `just schemagen`.
184
176
 
185
177
  ### Narrowing when runtime ≠ stdout
186
178
 
@@ -193,7 +185,8 @@ export interface TranslationReadinessResult {
193
185
  evaluatedAt: string;
194
186
  }
195
187
 
196
- export type outputType = TranslationReadinessResult;
188
+ /** @sg */
189
+ export interface TranslationReadinessResult {
197
190
  ```
198
191
 
199
192
  Patterns:
@@ -213,15 +206,15 @@ Per consumer repo (optional):
213
206
 
214
207
  ## Contributor workflow
215
208
 
216
- 1. Add or edit schema roots in `src/**/types.ts` with `outputType` / `inputType` / `configType` and per-field JSDoc.
209
+ 1. Add or edit `/** @sg */` roots in `src/**/*.ts` with per-field JSDoc.
217
210
  2. `just schemagen` — refresh `src/**/__generated__/`.
218
- 3. Import `{ outputSchema }` / `{ inputSchema }` / `{ configSchema }` from the relevant `__generated__/index.ts`.
219
- 4. `just docgen` / `myapp docs api --save` — refresh consumer docs.
211
+ 3. Import `{ TypeNameSchema }` from the relevant `./__generated__` barrel.
212
+ 4. `just docgen` / `myapp docs cli --save` — refresh consumer docs.
220
213
  5. Document which commands use which roots in **your** `docs/architecture.md` (argsbarg does not maintain per-app tables).
221
214
 
222
215
  Add a bullet under your app’s `**… conventions:**` block in `.cursor/rules/cli-program.mdc` pointing at `node_modules/argsbarg/docs/output-schema.md`.
223
216
 
224
- **Reference implementation:** [`examples/full-example/`](../examples/full-example/) in this repo — `types.ts` roots, `__generated__/`, and `status` leaf with `outputSchema`.
217
+ **Reference implementation:** [`examples/full-example/`](../examples/full-example/) in this repo — `@sg` on command types, `__generated__/`, and `status` leaf with `StatusJsonOutputSchema`.
225
218
 
226
219
  ## Out of scope
227
220
 
@@ -233,5 +226,5 @@ Add a bullet under your app’s `**… conventions:**` block in `.cursor/rules/c
233
226
  - [config-schema.md](config-schema.md) — `configType` / `program.appConfig`
234
227
  - [cli-program.md](cli-program.md) — structured stdout, headless JSON, `read*Flags`
235
228
  - [mcp.md](mcp.md) — `tools/list`, `structuredContent`
236
- - [bundled-docs.md](bundled-docs.md) — `docs api` / `docs cli-schema` docgen
229
+ - [bundled-docs.md](bundled-docs.md) — `docs cli` / `docs cli-schema` docgen
237
230
  - [docs/README.md](README.md) — documentation map
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bun
2
2
  /*
3
- * Value formats demo: duration, comma-list, date, default, and readLeafInputs().
3
+ * Value formats demo: duration, comma-list, date, default, and ctx.inputs.
4
4
  * Run: bun ./examples/formats.ts run --tags alpha,beta --on 2026-06-22
5
5
  * MCP: pass comma-list as string or array; varargs N/A on this leaf.
6
6
  */
@@ -12,19 +12,19 @@ import {
12
12
  CliOptionKind,
13
13
  type CliProgram,
14
14
  CliValueFormat,
15
- } from "../src/index.ts";
15
+ } from "../src/index";
16
16
 
17
17
  const program = {
18
18
  key: "formats.ts",
19
19
  version: pkg.version,
20
- description: "Value formats and readLeafInputs demo.",
20
+ description: "Value formats and ctx.inputs demo.",
21
21
  fallbackCommand: "run",
22
22
  fallbackMode: CliFallbackMode.MissingOnly,
23
23
  mcpServer: { enabled: true },
24
24
  commands: [
25
25
  {
26
26
  key: "run",
27
- description: "Print coerced option values from readLeafInputs().",
27
+ description: "Print coerced option values from ctx.inputs.",
28
28
  options: [
29
29
  {
30
30
  name: "timeout",
@@ -53,9 +53,9 @@ const program = {
53
53
  },
54
54
  ],
55
55
  handler: (ctx) => {
56
- const inputs = ctx.readLeafInputs();
56
+ const inputs = ctx.inputs;
57
57
  const out = {
58
- readLeafInputs: inputs,
58
+ inputs,
59
59
  durationMs: ctx.durationOpt("timeout"),
60
60
  tags: ctx.commaListOpt("tags"),
61
61
  on: ctx.dateOpt("on"),
@@ -0,0 +1,35 @@
1
+ class FullExample < Formula
2
+ desc "Argsbarg full example reference app"
3
+ homepage "https://github.com/bdombro/bun-argsbarg"
4
+ version "1.0.0"
5
+ sha256 "d6dbe3233152d2f51feca068b23e6fd133940232fb4bb7c3f08c2d1024c10c30"
6
+
7
+ def install
8
+ bin.install "full-example"
9
+ chmod 0755, bin/"full-example"
10
+ generate_completions_from_executable(bin/"full-example", "completion", base_name: "full-example")
11
+ end
12
+
13
+ def post_install
14
+ system bin/"full-example", "configure", "--sync", "--yes"
15
+ end
16
+
17
+ def uninstall
18
+ system bin/"full-example", "configure", "--remove-all", "--yes"
19
+ end
20
+
21
+ def caveats
22
+ <<~EOS
23
+ Run `full-example configure` to set up agent artifacts and app config (interactive).
24
+ Restart MCP chat apps (Cursor, Claude Desktop, etc.) after install or upgrade so they load the updated server.
25
+ EOS
26
+ end
27
+
28
+ test do
29
+ assert_match version.to_s, shell_output("#{bin}/full-example version")
30
+ assert_predicate bash_completion/"full-example", :exist?
31
+ assert_predicate zsh_completion/"_full-example", :exist?
32
+ assert_predicate fish_completion/"full-example.fish", :exist?
33
+ end
34
+ url "file:///Users/briandombrowski/dev/bdombro/bun-argsbarg/examples/full-example/Formula/.staging/full-example"
35
+ end
@@ -1,6 +1,16 @@
1
1
  # full-example
2
2
 
3
- Argsbarg full example reference app
3
+ Argsbarg copy template / reference app (not a kitchen-sink product).
4
+
5
+ ## What's in this app
6
+
7
+ - **Builtins enabled:** CLI, shell completion, `docs`, MCP, HTTP API, `configure` (wizard available; no default `appConfig` in the template)
8
+ - **Commands:**
9
+ - `echo` — simple flags/positionals
10
+ - `render-json` — `kind: "json"` leaf, schemagen `inputSchema`, `ctx.inputsAs`
11
+ - `status` — schemagen `outputSchema`, `--json`
12
+ - `workspaces` — REST CRUD, `:id` param routers, verb leaves, schemagen input schemas
13
+ - **Tooling:** `@sg` schemagen, `just docgen`, Homebrew/just dev workflow
4
14
 
5
15
  ## Quick start
6
16
 
@@ -9,13 +19,11 @@ From a git checkout at this directory (requires [Homebrew](https://brew.sh), [ju
9
19
  ```bash
10
20
  brew install just bun
11
21
  just setup
12
- just schemagen # after changing src/**/types.ts
22
+ just schemagen # after changing @sg types in src/
13
23
  just run status --json
14
24
  just run docs readme
15
25
  ```
16
26
 
17
- Run `full-example configure` when the app needs secrets or other app config (interactive wizard).
18
-
19
27
  ## Install
20
28
 
21
29
  Requires [Homebrew](https://brew.sh).
@@ -34,7 +42,6 @@ Install:
34
42
  ```bash
35
43
  brew tap bdombro/bun-argsbarg git@github.com:bdombro/bun-argsbarg.git
36
44
  brew install bdombro/bun-argsbarg/full-example
37
- full-example configure
38
45
  ```
39
46
 
40
47
  Upgrade:
@@ -58,17 +65,17 @@ just install-production # remote tap install (requires gh auth login)
58
65
  just test-release
59
66
  ```
60
67
 
61
- Undo a local dev install: `just uninstall` (formula + agent artifacts; app config removed by formula `uninstall`), `just uninstall-config` (app config only, without uninstalling the formula).
68
+ Undo a local dev install: `just uninstall` (formula + agent artifacts), `just uninstall-config` (app config only, without uninstalling the formula).
62
69
 
63
- ## Schemagen roots
70
+ ## Schemagen (`@sg`)
64
71
 
65
- | Export in `types.ts` | Generated artifact | Import on leaf / program |
66
- | --- | --- | --- |
67
- | `export type configType = …` | `config/__generated__/configSchema.json` | `{ configSchema }` from `config/__generated__/index.ts` |
68
- | `export type outputType = …` | `__generated__/outputSchema.json` | `{ outputSchema }` from `__generated__/index.ts` |
69
- | `export type inputType = …` | `__generated__/inputSchema.json` | `{ inputSchema }` from `__generated__/index.ts` |
72
+ Mark schema-facing types with `/** @sg */` immediately above the declaration (no blank line). Run `argsbarg schemagen` (via `just schemagen` or `just setup`).
70
73
 
71
- Type definitions and schemagen role exports live in `types.ts`. Run `argsbarg schemagen` (via `just schemagen` or `just setup`).
74
+ | Type | Generated artifact | Import |
75
+ | --- | --- | --- |
76
+ | `RenderJsonInput` | `RenderJsonInputSchema.json` | `RenderJsonInputSchema` from `./__generated__` |
77
+ | `StatusJsonOutput` | `StatusJsonOutputSchema.json` | `StatusJsonOutputSchema` from `./__generated__` |
78
+ | `WorkspaceNameInput` | `WorkspaceNameInputSchema.json` | `WorkspaceNameInputSchema` from `./__generated__` |
72
79
 
73
80
  ## Consumer docs
74
81
 
@@ -77,11 +84,3 @@ Regenerate committed reference docs under `docs/` (see [docs/README.md](docs/REA
77
84
  ```bash
78
85
  just docgen
79
86
  ```
80
-
81
- ## Environment
82
-
83
- Optional overrides for `program.appConfig` (the configure wizard is the usual path):
84
-
85
- | Variable | Purpose |
86
- | --- | --- |
87
- | `FULL_EXAMPLE_API_TOKEN` | Overrides `apiToken` when set in the shell |
@@ -8,7 +8,7 @@ Reference template for argsbarg consumer docgen. Every builtin is enabled in `sr
8
8
  | **Authoring argsbarg schema** | `node_modules/argsbarg/docs/cli-program.md` — see `.cursor/rules/cli-program.mdc` |
9
9
  | **HTTP API / curl** | [http.md](http.md) — generated; or run `full-example docs http` |
10
10
  | **MCP tools** | [mcp.md](mcp.md) — generated; or run `full-example docs mcp` |
11
- | **Full command tree (markdown)** | [api.md](api.md) — generated |
11
+ | **Full command tree (markdown)** | [cli.md](cli.md) — generated |
12
12
  | **Full command tree (JSON)** | [cli-schema.json](cli-schema.json) — generated |
13
13
  | **OpenAPI 3.1** | [openapi.json](openapi.json) — generated |
14
14
  | **Agent skill index** | [skill.md](skill.md) — generated |