argsbarg 6.1.2 → 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 +65 -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 +52 -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 +431 -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/{json-leaf.test.ts → core/json-leaf.test.ts} +4 -4
  144. package/src/{leaf-inputs.test.ts → core/leaf-inputs.test.ts} +7 -7
  145. package/src/{leaf-inputs.ts → core/leaf-inputs.ts} +16 -12
  146. package/src/{parse.test.ts → core/parse.test.ts} +97 -109
  147. package/src/{parse.ts → core/parse.ts} +129 -31
  148. package/src/{schema.ts → core/schema.ts} +25 -13
  149. package/src/{types.ts → core/types.ts} +225 -35
  150. package/src/{validate.ts → core/validate.ts} +39 -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 +3 -3
  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 +36 -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 +9 -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} +159 -49
  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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "argsbarg",
3
- "version": "6.1.2",
3
+ "version": "6.1.3",
4
4
  "main": "./src/index.ts",
5
5
  "module": "./src/index.ts",
6
6
  "dependencies": {
@@ -17,18 +17,35 @@
17
17
  "types": "./index.d.ts",
18
18
  "default": "./src/index.ts"
19
19
  },
20
+ "./cli": {
21
+ "types": "./src/exports/cli.ts",
22
+ "default": "./src/exports/cli.ts"
23
+ },
24
+ "./headless": {
25
+ "types": "./src/exports/headless.ts",
26
+ "default": "./src/exports/headless.ts"
27
+ },
28
+ "./http": {
29
+ "types": "./src/exports/http.ts",
30
+ "default": "./src/exports/http.ts"
31
+ },
32
+ "./mcp": {
33
+ "types": "./src/exports/mcp.ts",
34
+ "default": "./src/exports/mcp.ts"
35
+ },
20
36
  "./schemagen": {
21
37
  "types": "./src/cli-tool/schemagen/index.ts",
22
38
  "default": "./src/cli-tool/schemagen/index.ts"
23
39
  }
24
40
  },
25
41
  "bin": {
26
- "argsbarg": "src/cli-tool/main.ts"
42
+ "argsbarg": "bin/argsbarg"
27
43
  },
28
44
  "engines": {
29
45
  "bun": ">=1.3"
30
46
  },
31
47
  "files": [
48
+ "bin",
32
49
  "src",
33
50
  "index.d.ts",
34
51
  "docs",
@@ -3,14 +3,14 @@ Tests for builtins/builtins module behavior.
3
3
  */
4
4
 
5
5
  import { describe, expect, test } from "bun:test";
6
- import { resolveCapabilities } from "../capabilities.ts";
7
- import { cliBuiltinDocsGroup } from "../docs/builtin.ts";
8
- import { ParseKind, parse, postParseValidate } from "../parse.ts";
9
- import type { CliProgram } from "../types.ts";
6
+ import { ParseKind, parse, postParseValidate } from "~/core/parse.ts";
7
+ import type { CliProgram } from "~/core/types.ts";
8
+ import { cliBuiltinDocsGroup } from "~/docs/builtin.ts";
9
+ import { resolveCapabilities } from "~/runtime/capabilities.ts";
10
+ import { completionBashScript, completionFishScript, completionZshScript } from ".";
10
11
  import { cliBuiltinConfigureCommand, configureBuiltinOptions } from "./configure.ts";
11
12
  import { configureCommandDescription, configureSyncOptionDescription } from "./configure-copy.ts";
12
13
  import { exportPresentationBuiltins } from "./export.ts";
13
- import { completionBashScript, completionFishScript, completionZshScript } from "./index.ts";
14
14
  import { cliBuiltinMcpCommand } from "./mcp.ts";
15
15
  import { cliParseRoot, cliPresentationRoot } from "./presentation.ts";
16
16
 
@@ -88,7 +88,7 @@ describe("builtins help copy", () => {
88
88
  test("mcp builtin description is user-facing", () => {
89
89
  const withDocs: CliProgram = {
90
90
  ...fixture,
91
- docs: { enabled: true, topics: { readme: { text: "# r\n" } } },
91
+ docs: { topics: { readme: { text: "# r\n" } } },
92
92
  };
93
93
  const mcp = cliBuiltinMcpCommand(withDocs);
94
94
  expect(mcp.description).toContain("MCP server");
@@ -185,7 +185,7 @@ describe("docs skill topic copy", () => {
185
185
  test("mentions configure when configure is enabled", () => {
186
186
  const withDocs: CliProgram = {
187
187
  ...noMcp,
188
- docs: { enabled: true, topics: { readme: { text: "# r\n" } } },
188
+ docs: { topics: { readme: { text: "# r\n" } } },
189
189
  };
190
190
  const skill = cliBuiltinDocsGroup(withDocs).commands.find((c) => c.key === "skill");
191
191
  expect(skill?.description).toContain("configure");
@@ -1,4 +1,4 @@
1
- import { CliOptionKind, type CliRouter } from "../types.ts";
1
+ import { CliOptionKind, type CliRouter } from "~/core/types.ts";
2
2
  import { emitConsumeLong, emitConsumeShort, emitMatchChild } from "./completion-simulate-shared.ts";
3
3
  import { collectScopes, type ScopeRec } from "./scopes.ts";
4
4
  import { escShellSingleQuoted, identToken, kHelpLong, kHelpShort, mainName } from "./shell-helpers.ts";
@@ -1,4 +1,4 @@
1
- import { CliOptionKind, type CliRouter } from "../types.ts";
1
+ import { CliOptionKind, type CliRouter } from "~/core/types.ts";
2
2
  import { collectScopes } from "./scopes.ts";
3
3
  import { escFishSingleQuoted, identToken } from "./shell-helpers.ts";
4
4
 
@@ -1,13 +1,13 @@
1
- import type { CliProgram } from "../types.ts";
1
+ import type { CliProgram } from "~/core/types.ts";
2
2
 
3
3
  /**
4
4
  * Builds the static `completion` / `bash` / `zsh` / `fish` command subtree (merged into the program root at runtime).
5
5
  */
6
- export function cliBuiltinCompletionGroup(program: CliProgram): import("../types.ts").CliRouter {
6
+ export function cliBuiltinCompletionGroup(program: CliProgram): import("~/core/types.ts").CliRouter {
7
7
  const appName = program.key;
8
- const router: import("../types.ts").CliRouter = {
8
+ const router: import("~/core/types.ts").CliRouter = {
9
9
  key: "completion",
10
- hidden: true,
10
+ cli: { hidden: true },
11
11
  description: "Generate the autocompletion script for shells.",
12
12
  commands: [
13
13
  {
@@ -98,10 +98,19 @@ export function emitMatchChild(ident: string, scopes: ScopeRec[], pathIndex: Rec
98
98
  o += ` ${sid})\n`;
99
99
  o += " case $w in\n";
100
100
  for (const ch of sc.kids) {
101
+ if (ch.key.startsWith(":")) {
102
+ continue;
103
+ }
101
104
  const childPath = sc.path === "" ? ch.key : `${sc.path}/${ch.key}`;
102
105
  const cid = pathIndex[childPath] ?? 0;
103
106
  o += ` ${ch.key}) echo ${cid}; return 0 ;;\n`;
104
107
  }
108
+ const paramChild = sc.kids.find((ch) => ch.key.startsWith(":"));
109
+ if (paramChild) {
110
+ const childPath = sc.path === "" ? paramChild.key : `${sc.path}/${paramChild.key}`;
111
+ const cid = pathIndex[childPath] ?? 0;
112
+ o += ` *) echo ${cid}; return 0 ;;\n`;
113
+ }
105
114
  o += " esac\n";
106
115
  o += " ;;\n";
107
116
  }
@@ -1,4 +1,4 @@
1
- import { CliOptionKind, type CliRouter } from "../types.ts";
1
+ import { CliOptionKind, type CliRouter } from "~/core/types.ts";
2
2
  import { emitConsumeLong, emitConsumeShort, emitMatchChild } from "./completion-simulate-shared.ts";
3
3
  import { collectScopes, type ScopeRec } from "./scopes.ts";
4
4
  import { escShellSingleQuoted, identToken, kHelpLong, kHelpShort, mainName } from "./shell-helpers.ts";
@@ -6,9 +6,9 @@ import { describe, expect, test } from "bun:test";
6
6
  import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
7
7
  import { tmpdir } from "node:os";
8
8
  import { dirname, join } from "node:path";
9
- import { readBindings } from "../config/bindings.ts";
10
- import { resolveAppConfigPath, writeAppConfigFile } from "../config/file.ts";
11
- import { Cli, type CliProgram } from "../index.ts";
9
+ import { readBindings } from "~/config/bindings.ts";
10
+ import { resolveAppConfigPath, writeAppConfigFile } from "~/config/file.ts";
11
+ import { Cli, type CliProgram } from "~/index";
12
12
 
13
13
  function configFixture(): CliProgram {
14
14
  return {
@@ -2,20 +2,20 @@
2
2
  Built-in `configure get` / `configure set` subcommands.
3
3
  */
4
4
 
5
- import { clearFileValue, setBinding } from "../config/bindings.ts";
6
- import { bootstrapAppConfig } from "../config/bootstrap.ts";
5
+ import { clearFileValue, setBinding } from "~/config/bindings.ts";
6
+ import { bootstrapAppConfig } from "~/config/bootstrap.ts";
7
7
  import {
8
8
  configCommandsEnabled,
9
9
  configEntrySensitive,
10
10
  configMcpSetEnabled,
11
11
  defaultConfigEntryTitle,
12
- } from "../config/entry.ts";
13
- import { writeAppConfigFile } from "../config/file.ts";
14
- import { captureMappedHostEnv, exportConfigToEnv, resolveAppConfig } from "../config/resolve.ts";
15
- import { configPropertySchema, effectiveJsonSchema } from "../config/schema.ts";
16
- import { parseConfigSetValue } from "../config/validate.ts";
17
- import type { CliLeaf, CliOption, CliProgram } from "../types.ts";
18
- import { CliOptionKind } from "../types.ts";
12
+ } from "~/config/entry.ts";
13
+ import { writeAppConfigFile } from "~/config/file.ts";
14
+ import { captureMappedHostEnv, exportConfigToEnv, resolveAppConfig } from "~/config/resolve.ts";
15
+ import { configPropertySchema, effectiveJsonSchema } from "~/config/schema.ts";
16
+ import { parseConfigSetValue } from "~/config/validate.ts";
17
+ import type { CliLeaf, CliOption, CliProgram } from "~/core/types.ts";
18
+ import { CliOptionKind } from "~/core/types.ts";
19
19
 
20
20
  const JSON_OPTION: CliOption = {
21
21
  name: "json",
@@ -1,7 +1,7 @@
1
1
  /** Capability-aware labels for configure builtin and docs copy. */
2
2
 
3
- import type { CliCapabilities } from "../capabilities.ts";
4
- import type { CliProgram } from "../types.ts";
3
+ import type { CliProgram } from "~/core/types.ts";
4
+ import type { CliCapabilities } from "~/runtime/capabilities.ts";
5
5
 
6
6
  type Kind = "skills" | "mcp" | "config";
7
7
 
@@ -1,5 +1,4 @@
1
- import { resolveCapabilities } from "../capabilities.ts";
2
- import { configCommandsEnabled, configMcpSetEnabled } from "../config/entry.ts";
1
+ import { configCommandsEnabled, configMcpSetEnabled } from "~/config/entry.ts";
3
2
  import {
4
3
  CliFallbackMode,
5
4
  type CliLeaf,
@@ -7,7 +6,8 @@ import {
7
6
  CliOptionKind,
8
7
  type CliProgram,
9
8
  type CliRouter,
10
- } from "../types.ts";
9
+ } from "~/core/types.ts";
10
+ import { resolveCapabilities } from "~/runtime/capabilities.ts";
11
11
  import { configureConfigSubcommands } from "./config.ts";
12
12
  import {
13
13
  configureCommandDescription,
@@ -79,7 +79,7 @@ export function cliBuiltinConfigureCommand(root: CliProgram): CliRouter {
79
79
  const caps = resolveCapabilities(root);
80
80
  const run: CliLeaf = {
81
81
  key: CONFIGURE_RUN_KEY,
82
- hidden: true,
82
+ cli: { hidden: true },
83
83
  description: "Interactive or flag-driven configure (skills, MCP, app config).",
84
84
  handler: () => {},
85
85
  };
@@ -1,18 +1,19 @@
1
- import { capabilityDeniedMessage, resolveCapabilities } from "../capabilities.ts";
2
- import { Cli } from "../cli.ts";
3
- import { cliConfigure } from "../configure/index.ts";
4
- import { cliBuiltinDocsGroupIfEnabled } from "../docs/builtin.ts";
5
- import { runMcpBundle } from "../mcp/bundle.ts";
6
- import type { ParseResult } from "../parse.ts";
7
- import { ParseKind } from "../parse.ts";
8
- import type { CliNode, CliProgram, CliRouter } from "../types.ts";
9
- import { isCliLeaf } from "../types.ts";
10
- import { cliBuiltinApiCommand } from "./api.ts";
1
+ import { cliConfigure } from "~/configure";
2
+ import type { ParseResult } from "~/core/parse.ts";
3
+ import { ParseKind } from "~/core/parse.ts";
4
+ import type { CliNode, CliProgram, CliRouter } from "~/core/types.ts";
5
+ import { isCliLeaf } from "~/core/types.ts";
6
+ import { cliBuiltinDocsGroupIfEnabled } from "~/docs/builtin.ts";
7
+ import { runMcpBundle } from "~/mcp/bundle.ts";
8
+ import { capabilityDeniedMessage, resolveCapabilities } from "~/runtime/capabilities.ts";
9
+ import { Cli } from "~/runtime/cli.ts";
10
+ import { serveOverridesFromOpts } from "~/server/overrides.ts";
11
11
  import { completionBashScript } from "./completion-bash.ts";
12
12
  import { completionFishScript } from "./completion-fish.ts";
13
13
  import { cliBuiltinCompletionGroup as completionGroup } from "./completion-group.ts";
14
14
  import { completionZshScript } from "./completion-zsh.ts";
15
15
  import { CONFIGURE_RUN_KEY, cliBuiltinConfigureCommand, isConfigureConfigPath } from "./configure.ts";
16
+ import { cliBuiltinHttpCommand } from "./http.ts";
16
17
  import { cliBuiltinMcpCommand } from "./mcp.ts";
17
18
  import { cliPresentationRoot } from "./presentation.ts";
18
19
  import { cliBuiltinVersionCommand } from "./version.ts";
@@ -69,17 +70,17 @@ export async function dispatchBuiltin(program: CliProgram, pr: ParseResult, opts
69
70
  process.exit(0);
70
71
  }
71
72
 
72
- if (pr.path[0] === "api") {
73
- if (!caps.api) {
74
- process.stderr.write(capabilityDeniedMessage("api"));
73
+ if (pr.path[0] === "http") {
74
+ if (!caps.http) {
75
+ process.stderr.write(capabilityDeniedMessage("http"));
75
76
  process.exit(1);
76
77
  }
77
78
  const sub = pr.path[1];
78
79
  if (pr.path.length === 1 || sub === "serve") {
79
- await new Cli(program).serveApi();
80
+ await new Cli(program).serveHttp(serveOverridesFromOpts(pr.opts, "http"));
80
81
  process.exit(0);
81
82
  }
82
- process.stderr.write(`Unknown subcommand: api ${pr.path.slice(1).join(" ")}\n`);
83
+ process.stderr.write(`Unknown subcommand: http ${pr.path.slice(1).join(" ")}\n`);
83
84
  process.exit(1);
84
85
  }
85
86
 
@@ -90,7 +91,7 @@ export async function dispatchBuiltin(program: CliProgram, pr: ParseResult, opts
90
91
  }
91
92
  const sub = pr.path[1];
92
93
  if (pr.path.length === 1 || sub === "serve") {
93
- await new Cli(program).serveMcp();
94
+ await new Cli(program).serveMcp(serveOverridesFromOpts(pr.opts, "mcp"));
94
95
  process.exit(0);
95
96
  }
96
97
  if (pr.path.length === 2 && sub === "bundle") {
@@ -157,12 +158,12 @@ export function builtinInterceptRoot(
157
158
  };
158
159
  }
159
160
 
160
- if (first === "api" && caps.api) {
161
+ if (first === "http" && caps.http) {
161
162
  return {
162
163
  parseRoot: {
163
164
  key: program.key,
164
165
  description: program.description,
165
- commands: [cliBuiltinApiCommand(program)],
166
+ commands: [cliBuiltinHttpCommand(program)],
166
167
  },
167
168
  isLeafCompletionIntercept: false,
168
169
  };
@@ -1,7 +1,7 @@
1
- import { resolveCapabilities } from "../capabilities.ts";
2
- import { visibleOptions } from "../hidden.ts";
3
- import type { CliFallbackMode, CliNode, CliOption, CliPositional, CliProgram } from "../types.ts";
4
- import { isCliRouter } from "../types.ts";
1
+ import type { CliFallbackMode, CliNode, CliOption, CliPositional, CliProgram } from "~/core/types.ts";
2
+ import { isCliRouter } from "~/core/types.ts";
3
+ import { resolveCapabilities } from "~/runtime/capabilities.ts";
4
+ import { isCliSchemaHidden, visibleOptions } from "~/runtime/exposure.ts";
5
5
  import { resolveBuiltins } from "./registry.ts";
6
6
 
7
7
  /** JSON-safe command node (no handlers). */
@@ -11,6 +11,8 @@ export interface CliSchemaExport {
11
11
  notes?: string;
12
12
  /** JSON Schema for structured stdout when set on the leaf. */
13
13
  outputSchema?: Record<string, unknown>;
14
+ /** Default success Content-Type when `outputSchema` is omitted but `http.successContentType` is set. */
15
+ outputContentType?: string;
14
16
  options?: CliOption[];
15
17
  fallbackCommand?: string;
16
18
  fallbackMode?: CliFallbackMode;
@@ -19,7 +21,7 @@ export interface CliSchemaExport {
19
21
  }
20
22
 
21
23
  function exportBuiltinNode(cmd: CliNode): CliSchemaExport | null {
22
- if (cmd.hidden) {
24
+ if (isCliSchemaHidden(cmd)) {
23
25
  return null;
24
26
  }
25
27
 
@@ -0,0 +1,68 @@
1
+ import {
2
+ CliFallbackMode,
3
+ type CliLeaf,
4
+ type CliOption,
5
+ CliOptionKind,
6
+ type CliProgram,
7
+ type CliRouter,
8
+ } from "~/core/types.ts";
9
+ import { docsEnabled } from "~/docs/resolve.ts";
10
+ import { resolveHttpListenAddress } from "~/http/server.ts";
11
+ import { resolveCapabilities } from "~/runtime/capabilities.ts";
12
+
13
+ const HTTP_SERVE_OPTIONS: CliOption[] = [
14
+ { name: "host", description: "Listen host.", kind: CliOptionKind.String },
15
+ { name: "port", description: "Listen port.", kind: CliOptionKind.Number },
16
+ { name: "trust-proxy", description: "Honor X-Forwarded-For for client IP.", kind: CliOptionKind.Presence },
17
+ { name: "obscure-errors", description: "Hide unexpected errors from clients.", kind: CliOptionKind.Presence },
18
+ {
19
+ name: "log-format",
20
+ description: "Log format: json (ECS) or text.",
21
+ kind: CliOptionKind.Enum,
22
+ choices: ["json", "text"],
23
+ },
24
+ {
25
+ name: "log-file",
26
+ description: "Append logs to this file (relative → app config dir).",
27
+ kind: CliOptionKind.String,
28
+ },
29
+ { name: "no-access-log", description: "Disable HTTP access logs.", kind: CliOptionKind.Presence },
30
+ { name: "dev", description: "Print full stacks to stderr on errors.", kind: CliOptionKind.Presence },
31
+ ];
32
+
33
+ /** Built-in `http` router: bare `myapp http` runs the HTTP server (via hidden `serve` fallback). */
34
+ export function cliBuiltinHttpCommand(program: CliProgram): CliRouter {
35
+ const caps = resolveCapabilities(program);
36
+ const { hostname, port } = resolveHttpListenAddress(program);
37
+ const lines = [
38
+ `HTTP tool server on http://${hostname}:${port}.`,
39
+ "",
40
+ "Endpoints: GET /health, GET /health/ready, GET /openapi.json, GET /openapi-browser, /api/*",
41
+ "",
42
+ ];
43
+ if (caps.configure) {
44
+ lines.push("Configure app settings:", "", " {argsbarg:program} configure", "");
45
+ }
46
+ if (docsEnabled(program)) {
47
+ lines.push("Full setup guide: {argsbarg:program} docs http");
48
+ }
49
+
50
+ const serve: CliLeaf = {
51
+ key: "serve",
52
+ cli: { hidden: true },
53
+ description: "Run as an HTTP API server for tools.",
54
+ handler: () => {},
55
+ };
56
+
57
+ return {
58
+ key: "http",
59
+ description: "HTTP API server for tools.",
60
+ notes: lines.join("\n"),
61
+ options: [...HTTP_SERVE_OPTIONS],
62
+ fallbackCommand: "serve",
63
+ fallbackMode: CliFallbackMode.MissingOnly,
64
+ commands: [serve],
65
+ };
66
+ }
67
+
68
+ export { HTTP_SERVE_OPTIONS };
@@ -1,6 +1,29 @@
1
- import { resolveCapabilities } from "../capabilities.ts";
2
- import { docsEnabled } from "../docs/resolve.ts";
3
- import { CliFallbackMode, type CliLeaf, type CliProgram, type CliRouter } from "../types.ts";
1
+ import {
2
+ CliFallbackMode,
3
+ type CliLeaf,
4
+ type CliOption,
5
+ CliOptionKind,
6
+ type CliProgram,
7
+ type CliRouter,
8
+ } from "~/core/types.ts";
9
+ import { docsEnabled } from "~/docs/resolve.ts";
10
+ import { resolveCapabilities } from "~/runtime/capabilities.ts";
11
+
12
+ const MCP_SERVE_OPTIONS: CliOption[] = [
13
+ { name: "obscure-errors", description: "Hide unexpected errors from clients.", kind: CliOptionKind.Presence },
14
+ {
15
+ name: "log-format",
16
+ description: "Log format: json (ECS) or text.",
17
+ kind: CliOptionKind.Enum,
18
+ choices: ["json", "text"],
19
+ },
20
+ {
21
+ name: "log-file",
22
+ description: "Append logs to this file (relative → app config dir).",
23
+ kind: CliOptionKind.String,
24
+ },
25
+ { name: "dev", description: "Print full stacks to stderr on errors.", kind: CliOptionKind.Presence },
26
+ ];
4
27
 
5
28
  /** Built-in `mcp` router: bare `myapp mcp` runs stdio (via hidden `serve` fallback); `mcp bundle` packs `.mcpb`. */
6
29
  export function cliBuiltinMcpCommand(program: CliProgram): CliRouter {
@@ -21,7 +44,7 @@ export function cliBuiltinMcpCommand(program: CliProgram): CliRouter {
21
44
 
22
45
  const serve: CliLeaf = {
23
46
  key: "serve",
24
- hidden: true,
47
+ cli: { hidden: true },
25
48
  description: "Run as an MCP server over stdio for AI agents.",
26
49
  handler: () => {},
27
50
  };
@@ -36,6 +59,7 @@ export function cliBuiltinMcpCommand(program: CliProgram): CliRouter {
36
59
  key: "mcp",
37
60
  description: "MCP server and bundle tools.",
38
61
  notes: lines.join("\n"),
62
+ options: [...MCP_SERVE_OPTIONS],
39
63
  fallbackCommand: "serve",
40
64
  fallbackMode: CliFallbackMode.MissingOnly,
41
65
  commands: [serve, bundle],
@@ -1,8 +1,8 @@
1
- import type { CliCapabilities } from "../capabilities.ts";
2
- import { resolveCapabilities } from "../capabilities.ts";
3
- import { presentationNode, visibleOptions } from "../hidden.ts";
4
- import type { CliLeaf, CliNode, CliProgram, CliRouter } from "../types.ts";
5
- import { isCliLeaf } from "../types.ts";
1
+ import type { CliLeaf, CliNode, CliProgram, CliRouter } from "~/core/types.ts";
2
+ import { isCliLeaf } from "~/core/types.ts";
3
+ import type { CliCapabilities } from "~/runtime/capabilities.ts";
4
+ import { resolveCapabilities } from "~/runtime/capabilities.ts";
5
+ import { isCliHidden, presentationNode, visibleOptions } from "~/runtime/exposure.ts";
6
6
  import { resolveBuiltins } from "./registry.ts";
7
7
 
8
8
  /** All built-in command nodes for argv parsing (includes hidden builtins). */
@@ -12,7 +12,7 @@ export function parseBuiltins(program: CliProgram, caps: CliCapabilities): CliNo
12
12
 
13
13
  /** Built-in subtrees visible in help, schema, and completions (hidden builtins omitted). */
14
14
  export function presentationBuiltins(program: CliProgram, caps: CliCapabilities): CliNode[] {
15
- return parseBuiltins(program, caps).filter((b) => !b.hidden);
15
+ return parseBuiltins(program, caps).filter((b) => !isCliHidden(b));
16
16
  }
17
17
 
18
18
  /**
@@ -1,9 +1,9 @@
1
- import type { CliCapabilities } from "../capabilities.ts";
2
- import { cliBuiltinDocsGroupIfEnabled } from "../docs/builtin.ts";
3
- import type { CliNode, CliProgram } from "../types.ts";
4
- import { cliBuiltinApiCommand } from "./api.ts";
1
+ import type { CliNode, CliProgram } from "~/core/types.ts";
2
+ import { cliBuiltinDocsGroupIfEnabled } from "~/docs/builtin.ts";
3
+ import type { CliCapabilities } from "~/runtime/capabilities.ts";
5
4
  import { cliBuiltinCompletionGroup } from "./completion-group.ts";
6
5
  import { cliBuiltinConfigureCommand } from "./configure.ts";
6
+ import { cliBuiltinHttpCommand } from "./http.ts";
7
7
  import { cliBuiltinMcpCommand } from "./mcp.ts";
8
8
  import { cliBuiltinVersionCommand } from "./version.ts";
9
9
 
@@ -33,8 +33,8 @@ export function resolveBuiltins(program: CliProgram, caps: CliCapabilities): Cli
33
33
  if (caps.mcp) {
34
34
  pushBuiltin(builtins, program, (p) => cliBuiltinMcpCommand(p));
35
35
  }
36
- if (caps.api) {
37
- pushBuiltin(builtins, program, (p) => cliBuiltinApiCommand(p));
36
+ if (caps.http) {
37
+ pushBuiltin(builtins, program, (p) => cliBuiltinHttpCommand(p));
38
38
  }
39
39
  return builtins;
40
40
  }
@@ -2,12 +2,12 @@
2
2
  Shared completion scope walk used by bash, zsh, and fish emitters.
3
3
  */
4
4
 
5
- import { type CliNode, type CliRouter, isCliLeaf, isCliRouter } from "../types.ts";
5
+ import { type CliNode, type CliRouter, isCliLeaf, isCliRouter } from "~/core/types.ts";
6
6
 
7
7
  /** One tab-completion scope: child commands, options, and path key for the schema walk. */
8
8
  export interface ScopeRec {
9
9
  kids: CliNode[];
10
- opts: import("../types.ts").CliOption[];
10
+ opts: import("~/core/types.ts").CliOption[];
11
11
  path: string;
12
12
  wantsFiles: boolean;
13
13
  }
@@ -1,4 +1,4 @@
1
- import type { CliLeaf } from "../types.ts";
1
+ import type { CliLeaf } from "~/core/types.ts";
2
2
 
3
3
  /** Top-level `version` built-in (leaf). */
4
4
  export function cliBuiltinVersionCommand(): CliLeaf {
@@ -5,8 +5,8 @@ Tests for cli-tool/full-example-capabilities module behavior.
5
5
  import { describe, expect, test } from "bun:test";
6
6
  import { readFileSync } from "node:fs";
7
7
  import { join } from "node:path";
8
- import { resolveCapabilities } from "../capabilities.ts";
9
- import { CliOptionKind, type CliProgram } from "../types.ts";
8
+ import { CliOptionKind, type CliProgram } from "~/core/types.ts";
9
+ import { resolveCapabilities } from "~/runtime/capabilities.ts";
10
10
 
11
11
  const exampleRoot = join(import.meta.dir, "../../examples/full-example");
12
12
  const programSource = readFileSync(join(exampleRoot, "src/program.ts"), "utf8");
@@ -16,17 +16,11 @@ const sinkProgram = {
16
16
  key: "full-example",
17
17
  version: "1.0.0",
18
18
  description: "Full example reference.",
19
- appConfig: {
20
- entries: {
21
- apiToken: { description: "Token.", env: "FULL_EXAMPLE_API_TOKEN" },
22
- },
23
- },
24
19
  docs: {
25
- enabled: true,
26
20
  topics: { readme: { text: "# readme\n" } },
27
21
  },
28
22
  mcpServer: { enabled: true },
29
- apiServer: { enabled: true },
23
+ httpServer: { enabled: true },
30
24
  configure: {},
31
25
  commands: [
32
26
  {
@@ -55,26 +49,27 @@ describe("full-example template", () => {
55
49
  /** Tests that program source enables every builtin flag. */
56
50
  test("program source enables every builtin flag", () => {
57
51
  expect(programSource).toContain("mcpServer: {");
58
- expect(programSource).toContain("apiServer: {");
59
- expect(programSource).toContain("enabled: true");
52
+ expect(programSource).toContain("httpServer: {");
60
53
  expect(programSource).toContain("docs:");
61
- expect(programSource).toContain("appConfig:");
54
+ expect(programSource).not.toMatch(/docs:\s*\{[^}]*enabled:\s*true/s);
55
+ expect(programSource).not.toContain("appConfig:");
62
56
  });
63
57
 
64
58
  test("status command defines outputSchema", () => {
65
59
  const statusSource = readFileSync(join(exampleRoot, "src/commands/status/command.ts"), "utf8");
66
60
  expect(statusSource).toMatch(/outputSchema[,:]/);
67
- expect(statusSource).toContain('from "./__generated__/index.ts"');
61
+ expect(statusSource).toContain("StatusJsonOutputSchema");
62
+ expect(statusSource).toContain('from "./__generated__"');
68
63
  });
69
64
 
70
65
  test("resolveCapabilities matches full sink shape", () => {
71
66
  expect(resolveCapabilities(sinkProgram)).toEqual({
72
- api: true,
67
+ http: true,
73
68
  completion: true,
74
69
  mcp: true,
75
70
  configure: true,
76
71
  docs: true,
77
- configCommands: true,
72
+ configCommands: false,
78
73
  });
79
74
  });
80
75
  });
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env bun
2
2
  /** Argsbarg package CLI (`bunx argsbarg`) — bootstrap and tooling; library API is `import from "argsbarg"`. */
3
3
 
4
- import { Cli } from "../index.ts";
4
+ import { Cli } from "~/index";
5
5
  import { program } from "./program.ts";
6
6
 
7
7
  const cli = new Cli(program);
@@ -2,8 +2,8 @@
2
2
  Argsbarg developer tools — bootstrap consumer CLIs via `create`.
3
3
  */
4
4
 
5
+ import { CliOptionKind, type CliProgram } from "~/index";
5
6
  import pkg from "../../package.json" with { type: "json" };
6
- import { CliOptionKind, type CliProgram } from "../index.ts";
7
7
  import { runCreate } from "./run-create.ts";
8
8
  import { runSchemagenCli } from "./run-schemagen.ts";
9
9
 
@@ -13,6 +13,7 @@ export const program = {
13
13
  description: "Argsbarg developer tools — bootstrap CLIs from the full-example template.",
14
14
  completion: { enabled: false },
15
15
  configure: { enabled: false },
16
+ docs: { enabled: false },
16
17
  commands: [
17
18
  {
18
19
  key: "create",
@@ -96,7 +97,7 @@ export const program = {
96
97
  {
97
98
  key: "schemagen",
98
99
  description:
99
- "Generate JSON Schema artifacts from src/**/types.ts role exports into colocated __generated__/ directories.",
100
+ "Generate JSON Schema artifacts from @sg markers in src/**/*.ts into colocated __generated__/ directories.",
100
101
  options: [
101
102
  {
102
103
  name: "root",
@@ -1,6 +1,6 @@
1
1
  /** Interactive prompts for `argsbarg create`. */
2
2
 
3
- import { readPromptLine as readStdinLine } from "../prompt.ts";
3
+ import { readPromptLine as readStdinLine } from "~/prompt.ts";
4
4
 
5
5
  export function readPromptLine(prompt: string): string {
6
6
  process.stderr.write(prompt);
@@ -17,7 +17,5 @@ export function runSchemagenCli(options: RunSchemagenCliOptions = {}): void {
17
17
  srcDir: options.srcDir,
18
18
  tsconfig: options.tsconfig,
19
19
  });
20
- console.log(
21
- `config roots: ${counts.configRoots}, input roots: ${counts.inputRoots}, output roots: ${counts.outputRoots}`,
22
- );
20
+ console.log(`schemas: ${counts.schemas}`);
23
21
  }