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.
- package/CHANGELOG.md +65 -1
- package/README.md +17 -19
- package/bin/argsbarg +10 -0
- package/docs/README.md +4 -3
- package/docs/ai-skills.md +4 -2
- package/docs/bundled-docs.md +50 -25
- package/docs/cli-program.md +52 -10
- package/docs/config-schema.md +10 -11
- package/docs/configure.md +2 -0
- package/docs/decisions.md +40 -0
- package/docs/developing.md +43 -5
- package/docs/http-server.md +171 -0
- package/docs/json-schema-subset.md +51 -0
- package/docs/mcp.md +4 -2
- package/docs/output-schema.md +55 -62
- package/examples/formats.ts +6 -6
- package/examples/full-example/Formula/full-example.rb +35 -0
- package/examples/full-example/README.md +20 -21
- package/examples/full-example/docs/README.md +1 -1
- package/examples/full-example/docs/cli-schema.json +1790 -98
- package/examples/full-example/docs/cli.md +1990 -0
- package/examples/full-example/docs/http.md +28 -29
- package/examples/full-example/docs/mcp.md +8 -22
- package/examples/full-example/docs/openapi.json +783 -50
- package/examples/full-example/docs/skill.md +10 -10
- package/examples/full-example/justfile +11 -1
- package/examples/full-example/src/commands/render-json/__generated__/RenderJsonInputSchema.json +15 -0
- package/examples/full-example/src/commands/render-json/__generated__/index.ts +5 -0
- package/examples/full-example/src/commands/render-json/command.test.ts +46 -0
- package/examples/full-example/src/commands/render-json/command.ts +30 -0
- package/examples/full-example/src/commands/render-json/types.ts +9 -0
- package/examples/full-example/src/commands/status/__generated__/StatusJsonOutputSchema.json +15 -0
- package/examples/full-example/src/commands/status/__generated__/index.ts +2 -2
- package/examples/full-example/src/commands/status/command.ts +5 -13
- package/examples/full-example/src/commands/status/types.ts +1 -14
- package/examples/full-example/src/commands/workspaces/__generated__/WorkspaceNameInputSchema.json +15 -0
- package/examples/full-example/src/commands/workspaces/__generated__/index.ts +5 -0
- package/examples/full-example/src/commands/workspaces/command.test.ts +58 -0
- package/examples/full-example/src/commands/workspaces/command.ts +94 -0
- package/examples/full-example/src/commands/workspaces/types.ts +6 -0
- package/examples/full-example/src/db/index.test.ts +86 -0
- package/examples/full-example/src/db/index.ts +101 -0
- package/examples/full-example/src/db/migrate.test.ts +35 -0
- package/examples/full-example/src/db/migrate.ts +69 -0
- package/examples/full-example/src/db/migrations/001_workspaces.sql +6 -0
- package/examples/full-example/src/db/tables/workspaces.ts +66 -0
- package/examples/full-example/src/program.ts +11 -36
- package/examples/full-example/src/types/argsbarg.d.ts +11 -0
- package/examples/full-example/src/types/md.d.ts +4 -0
- package/examples/full-example/tsconfig.json +5 -2
- package/examples/mcp-test.ts +1 -2
- package/examples/minimal.ts +1 -7
- package/examples/nested.ts +1 -2
- package/examples/option-required.ts +1 -1
- package/examples/servers.ts +4 -5
- package/index.d.ts +431 -136
- package/package.json +19 -2
- package/src/builtins/builtins.test.ts +7 -7
- package/src/builtins/completion-bash.ts +1 -1
- package/src/builtins/completion-fish.ts +1 -1
- package/src/builtins/completion-group.ts +4 -4
- package/src/builtins/completion-simulate-shared.ts +9 -0
- package/src/builtins/completion-zsh.ts +1 -1
- package/src/builtins/config.test.ts +3 -3
- package/src/builtins/config.ts +9 -9
- package/src/builtins/configure-copy.ts +2 -2
- package/src/builtins/configure.ts +4 -4
- package/src/builtins/dispatch.ts +19 -18
- package/src/builtins/export.ts +7 -5
- package/src/builtins/http.ts +68 -0
- package/src/builtins/mcp.ts +28 -4
- package/src/builtins/presentation.ts +6 -6
- package/src/builtins/registry.ts +6 -6
- package/src/builtins/scopes.ts +2 -2
- package/src/builtins/version.ts +1 -1
- package/src/cli-tool/full-example-capabilities.test.ts +10 -15
- package/src/cli-tool/main.ts +1 -1
- package/src/cli-tool/program.ts +3 -2
- package/src/cli-tool/prompt.ts +1 -1
- package/src/cli-tool/run-schemagen.ts +1 -3
- package/src/cli-tool/schemagen/cleanup.ts +6 -7
- package/src/cli-tool/schemagen/discover-schema-roots.ts +66 -120
- package/src/cli-tool/schemagen/index.ts +2 -2
- package/src/cli-tool/schemagen/names.ts +8 -13
- package/src/cli-tool/schemagen/run.ts +21 -28
- package/src/cli-tool/schemagen/schemagen.test.ts +136 -46
- package/src/config/bindings.test.ts +1 -1
- package/src/config/bindings.ts +1 -1
- package/src/config/bootstrap.test.ts +1 -1
- package/src/config/bootstrap.ts +36 -4
- package/src/config/context.test.ts +1 -1
- package/src/config/context.ts +1 -1
- package/src/config/entry.ts +1 -1
- package/src/config/file.test.ts +1 -1
- package/src/config/file.ts +3 -3
- package/src/config/manifest.ts +1 -1
- package/src/config/resolve.test.ts +1 -1
- package/src/config/resolve.ts +1 -1
- package/src/config/schema.ts +1 -1
- package/src/config/validate.ts +1 -1
- package/src/{install → configure/artifacts}/binary-placement.test.ts +1 -1
- package/src/{install → configure/artifacts}/binary-placement.ts +1 -1
- package/src/{install → configure/artifacts}/gh-release-update.ts +1 -1
- package/src/{install → configure/artifacts}/install-validate.test.ts +3 -3
- package/src/{install → configure/artifacts}/mcp-config.ts +1 -1
- package/src/{install → configure/artifacts}/mcp-opencode.test.ts +1 -1
- package/src/{install → configure/artifacts}/mcp-opencode.ts +1 -1
- package/src/{install → configure/artifacts}/paths.ts +5 -5
- package/src/configure/artifacts/plan.ts +24 -0
- package/src/{install → configure/artifacts}/status.test.ts +1 -1
- package/src/{install → configure/artifacts}/status.ts +2 -2
- package/src/{install → configure/artifacts}/target-base.ts +1 -1
- package/src/{install → configure/artifacts}/target-detect.ts +1 -1
- package/src/{install → configure/artifacts}/target-effective.ts +3 -9
- package/src/{install → configure/artifacts}/target-mcp-cli.ts +1 -1
- package/src/{install → configure/artifacts}/target-mcp-json.ts +1 -1
- package/src/{install → configure/artifacts}/target-plan-build.ts +2 -2
- package/src/{install → configure/artifacts}/target-registry.ts +2 -2
- package/src/{install → configure/artifacts}/target-scope.ts +3 -3
- package/src/{install → configure/artifacts}/target-skill.ts +1 -1
- package/src/{install → configure/artifacts}/target-types.ts +2 -2
- package/src/{install → configure/artifacts}/targets/app.ts +5 -5
- package/src/{install → configure/artifacts}/targets/chatgpt-mcp.ts +2 -2
- package/src/{install → configure/artifacts}/targets/claude-code-mcp.ts +2 -2
- package/src/{install → configure/artifacts}/targets/claude-desktop-mcp.ts +2 -2
- package/src/{install → configure/artifacts}/targets/claude-skill.ts +2 -2
- package/src/{install → configure/artifacts}/targets/codex-mcp.ts +2 -2
- package/src/{install → configure/artifacts}/targets/codex-skill.ts +2 -2
- package/src/{install → configure/artifacts}/targets/configure.ts +5 -5
- package/src/{install → configure/artifacts}/targets/cursor-mcp.ts +2 -2
- package/src/{install → configure/artifacts}/targets/cursor-skill.ts +2 -2
- package/src/{install → configure/artifacts}/targets/index.ts +1 -1
- package/src/{install → configure/artifacts}/targets/openclaw-mcp.ts +2 -2
- package/src/{install → configure/artifacts}/targets/openclaw-skill.ts +3 -3
- package/src/{install → configure/artifacts}/targets/opencode-mcp.ts +5 -5
- package/src/{install → configure/artifacts}/targets/opencode-skill.ts +3 -3
- package/src/{install → configure/artifacts}/targets.test.ts +1 -1
- package/src/{install → configure/artifacts}/uninstall.ts +1 -1
- package/src/configure/configure.test.ts +11 -11
- package/src/configure/index.ts +14 -14
- package/src/configure/prompt.ts +2 -2
- package/src/{context.ts → core/context.ts} +26 -20
- package/src/{json-leaf.test.ts → core/json-leaf.test.ts} +4 -4
- package/src/{leaf-inputs.test.ts → core/leaf-inputs.test.ts} +7 -7
- package/src/{leaf-inputs.ts → core/leaf-inputs.ts} +16 -12
- package/src/{parse.test.ts → core/parse.test.ts} +97 -109
- package/src/{parse.ts → core/parse.ts} +129 -31
- package/src/{schema.ts → core/schema.ts} +25 -13
- package/src/{types.ts → core/types.ts} +225 -35
- package/src/{validate.ts → core/validate.ts} +39 -29
- package/src/docs/builtin.ts +8 -19
- package/src/docs/{api-guide.test.ts → cli-guide.test.ts} +21 -21
- package/src/docs/{api-guide.ts → cli-guide.ts} +45 -16
- package/src/docs/docs.test.ts +76 -41
- package/src/docs/http-guide.ts +37 -34
- package/src/docs/mcp-guide.ts +12 -14
- package/src/docs/mcp-resources.test.ts +2 -3
- package/src/docs/mcp-resources.ts +6 -11
- package/src/docs/resolve.ts +22 -30
- package/src/docs/save.ts +3 -3
- package/src/exports/cli.ts +47 -0
- package/src/exports/headless.ts +13 -0
- package/src/exports/http.ts +6 -0
- package/src/exports/mcp.ts +6 -0
- package/src/{headless.test.ts → headless/routing.test.ts} +3 -3
- package/src/{headless.ts → headless/routing.ts} +3 -3
- package/src/headless/tool-call.ts +114 -46
- package/src/help.test.ts +152 -0
- package/src/help.ts +3 -3
- package/src/hooks/builtin.ts +20 -0
- package/src/hooks/run.ts +142 -0
- package/src/http/openapi.ts +182 -0
- package/src/http/readiness.ts +78 -0
- package/src/{api → http}/result.ts +16 -5
- package/src/http/routes.ts +329 -0
- package/src/http/server.ts +225 -0
- package/src/index.ts +36 -25
- package/src/log/ecs.test.ts +43 -0
- package/src/log/ecs.ts +59 -0
- package/src/log/emitter.ts +166 -0
- package/src/mcp/bundle.ts +2 -2
- package/src/mcp/claude.test.ts +1 -1
- package/src/mcp/claude.ts +4 -4
- package/src/{hidden-mcpb.test.ts → mcp/hidden-mcpb.test.ts} +10 -9
- package/src/mcp/result.ts +2 -2
- package/src/mcp/server.ts +54 -6
- package/src/mcp/tools.ts +9 -20
- package/src/{capabilities.ts → runtime/capabilities.ts} +11 -11
- package/src/{cli-errors.ts → runtime/cli-errors.ts} +4 -4
- package/src/{cli.ts → runtime/cli.ts} +159 -49
- package/src/runtime/exposure.ts +102 -0
- package/src/{invoke.test.ts → runtime/invoke.test.ts} +31 -7
- package/src/server/context.ts +25 -0
- package/src/server/overrides.ts +112 -0
- package/src/skill/generate.ts +8 -8
- package/src/skill/hint.ts +1 -1
- package/src/skill/install.ts +2 -2
- package/src/skill/naming.ts +1 -1
- package/src/{test-fixtures.ts → test/fixtures.ts} +3 -2
- package/src/{config.integration.test.ts → test/integration/config.test.ts} +8 -8
- package/src/{api.integration.test.ts → test/integration/http.test.ts} +170 -67
- package/src/{mcp.integration.test.ts → test/integration/mcp.test.ts} +11 -57
- package/docs/api-server.md +0 -141
- package/examples/full-example/docs/api.md +0 -511
- package/examples/full-example/src/commands/status/__generated__/outputSchema.json +0 -28
- package/examples/full-example/src/config/__generated__/configSchema.json +0 -40
- package/examples/full-example/src/config/__generated__/index.ts +0 -5
- package/examples/full-example/src/config/types.ts +0 -24
- package/src/api/openapi.ts +0 -117
- package/src/api/server.ts +0 -120
- package/src/builtins/api.ts +0 -38
- package/src/hidden.ts +0 -30
- package/src/install/plan.ts +0 -53
- /package/src/{install → configure/artifacts}/detect-installed.ts +0 -0
- /package/src/{install → configure/artifacts}/gh-release-update.test.ts +0 -0
- /package/src/{install → configure/artifacts}/mcp-codex.test.ts +0 -0
- /package/src/{install → configure/artifacts}/mcp-codex.ts +0 -0
- /package/src/{install → configure/artifacts}/mcp-openclaw.test.ts +0 -0
- /package/src/{install → configure/artifacts}/mcp-openclaw.ts +0 -0
- /package/src/{install → configure/artifacts}/normalize-uninstall.ts +0 -0
- /package/src/{install → configure/artifacts}/normalize.ts +0 -0
- /package/src/{install → configure/artifacts}/opts.ts +0 -0
- /package/src/{install → configure/artifacts}/shell.ts +0 -0
- /package/src/{formats.test.ts → core/formats.test.ts} +0 -0
- /package/src/{formats.ts → core/formats.ts} +0 -0
- /package/src/{respond.ts → core/respond.ts} +0 -0
- /package/src/{types.test.ts → core/types.test.ts} +0 -0
- /package/src/{api → http}/schema-deref.test.ts +0 -0
- /package/src/{api → http}/schema-deref.ts +0 -0
package/src/api/openapi.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Hand-built OpenAPI 3.1 document from exposed MCP tools.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { collectMcpTools } from "../mcp/tools.ts";
|
|
6
|
-
import type { CliProgram } from "../types.ts";
|
|
7
|
-
import { dereferenceJsonSchema } from "./schema-deref.ts";
|
|
8
|
-
|
|
9
|
-
const JSON_CONTENT_TYPE = "application/json; charset=utf-8";
|
|
10
|
-
|
|
11
|
-
/** Resolves the effective API content type for OpenAPI response mapping. */
|
|
12
|
-
function effectiveApiContentType(tool: ReturnType<typeof collectMcpTools>[number]): string {
|
|
13
|
-
return tool.leaf.apiResponse?.contentType ?? "application/json";
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/** Builds an OpenAPI 3.1 response schema for a tool's success payload. */
|
|
17
|
-
function buildSuccessResponse(tool: ReturnType<typeof collectMcpTools>[number]): Record<string, unknown> {
|
|
18
|
-
const contentType = effectiveApiContentType(tool);
|
|
19
|
-
const media: Record<string, unknown> = {};
|
|
20
|
-
|
|
21
|
-
if (contentType.includes("application/json")) {
|
|
22
|
-
const outputSchema = tool.outputSchema ?? { type: "object" };
|
|
23
|
-
media[contentType] = {
|
|
24
|
-
schema: dereferenceJsonSchema(outputSchema),
|
|
25
|
-
};
|
|
26
|
-
} else if (contentType.includes("text/html")) {
|
|
27
|
-
media[contentType] = { schema: { type: "string" } };
|
|
28
|
-
} else {
|
|
29
|
-
media[contentType] = { schema: { type: "string", format: "binary" } };
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return {
|
|
33
|
-
description: "Successful tool invocation",
|
|
34
|
-
content: media,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** Generates an OpenAPI 3.1 document for the program's exposed tools. */
|
|
39
|
-
export function generateOpenApi(program: CliProgram): Record<string, unknown> {
|
|
40
|
-
const tools = collectMcpTools(program);
|
|
41
|
-
const paths: Record<string, unknown> = {};
|
|
42
|
-
|
|
43
|
-
for (const tool of tools) {
|
|
44
|
-
const pathKey = `/tools/${tool.apiName}`;
|
|
45
|
-
paths[pathKey] = {
|
|
46
|
-
post: {
|
|
47
|
-
operationId: tool.apiName,
|
|
48
|
-
summary: tool.description,
|
|
49
|
-
requestBody: {
|
|
50
|
-
required: false,
|
|
51
|
-
content: {
|
|
52
|
-
[JSON_CONTENT_TYPE]: {
|
|
53
|
-
schema: dereferenceJsonSchema(tool.inputSchema),
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
responses: {
|
|
58
|
-
"200": buildSuccessResponse(tool),
|
|
59
|
-
"400": {
|
|
60
|
-
description: "Invalid arguments or help requested",
|
|
61
|
-
content: {
|
|
62
|
-
[JSON_CONTENT_TYPE]: {
|
|
63
|
-
schema: {
|
|
64
|
-
type: "object",
|
|
65
|
-
properties: {
|
|
66
|
-
error: { type: "string" },
|
|
67
|
-
exitCode: { type: "integer" },
|
|
68
|
-
},
|
|
69
|
-
required: ["error"],
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
"404": {
|
|
75
|
-
description: "Unknown tool",
|
|
76
|
-
content: {
|
|
77
|
-
[JSON_CONTENT_TYPE]: {
|
|
78
|
-
schema: {
|
|
79
|
-
type: "object",
|
|
80
|
-
properties: { error: { type: "string" } },
|
|
81
|
-
required: ["error"],
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
"500": {
|
|
87
|
-
description: "Handler error",
|
|
88
|
-
content: {
|
|
89
|
-
[JSON_CONTENT_TYPE]: {
|
|
90
|
-
schema: {
|
|
91
|
-
type: "object",
|
|
92
|
-
properties: { error: { type: "string" } },
|
|
93
|
-
required: ["error"],
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return {
|
|
104
|
-
openapi: "3.1.0",
|
|
105
|
-
info: {
|
|
106
|
-
title: program.key,
|
|
107
|
-
version: program.version,
|
|
108
|
-
description: program.description,
|
|
109
|
-
},
|
|
110
|
-
paths,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/** Pretty-printed OpenAPI JSON (same document as `GET /openapi.json`). */
|
|
115
|
-
export function openApiJson(program: CliProgram): string {
|
|
116
|
-
return `${JSON.stringify(generateOpenApi(program), null, 2)}\n`;
|
|
117
|
-
}
|
package/src/api/server.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
HTTP tool server for ArgsBarg programs: health, OpenAPI, and tool invocation.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { Cli } from "../cli.ts";
|
|
6
|
-
import {
|
|
7
|
-
executeHeadlessToolCall,
|
|
8
|
-
headlessFailureToHttpResponse,
|
|
9
|
-
headlessSuccessToHttpResponse,
|
|
10
|
-
lookupHeadlessTool,
|
|
11
|
-
} from "../headless/tool-call.ts";
|
|
12
|
-
import type { CliProgram } from "../types.ts";
|
|
13
|
-
import { generateOpenApi } from "./openapi.ts";
|
|
14
|
-
import { API_CORS_HEADERS, apiDocsHtml, apiErrorResponse, apiOptionsResponse } from "./result.ts";
|
|
15
|
-
|
|
16
|
-
const DEFAULT_HOST = "127.0.0.1";
|
|
17
|
-
const DEFAULT_PORT = 3000;
|
|
18
|
-
|
|
19
|
-
/** Resolved listen address for the HTTP API server. */
|
|
20
|
-
export function resolveApiListenAddress(program: CliProgram): { hostname: string; port: number } {
|
|
21
|
-
const config = program.apiServer;
|
|
22
|
-
return {
|
|
23
|
-
hostname: config?.host ?? DEFAULT_HOST,
|
|
24
|
-
port: config?.port ?? DEFAULT_PORT,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** Writes a JSON HTTP response with CORS headers. */
|
|
29
|
-
function jsonResponse(status: number, body: unknown): Response {
|
|
30
|
-
return new Response(JSON.stringify(body), {
|
|
31
|
-
status,
|
|
32
|
-
headers: {
|
|
33
|
-
...API_CORS_HEADERS,
|
|
34
|
-
"content-type": "application/json; charset=utf-8",
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** Handles one HTTP request for the API server. */
|
|
40
|
-
export async function handleApiRequest(cli: Cli, request: Request): Promise<Response> {
|
|
41
|
-
if (request.method === "OPTIONS") {
|
|
42
|
-
return apiOptionsResponse();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const root = cli.program;
|
|
46
|
-
const url = new URL(request.url);
|
|
47
|
-
const path = url.pathname;
|
|
48
|
-
|
|
49
|
-
if (request.method === "GET" && path === "/health") {
|
|
50
|
-
return jsonResponse(200, { ok: true });
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (request.method === "GET" && path === "/openapi.json") {
|
|
54
|
-
return jsonResponse(200, generateOpenApi(root));
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (request.method === "GET" && path === "/openapi-browser") {
|
|
58
|
-
return new Response(apiDocsHtml(), {
|
|
59
|
-
status: 200,
|
|
60
|
-
headers: {
|
|
61
|
-
...API_CORS_HEADERS,
|
|
62
|
-
"content-type": "text/html; charset=utf-8",
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const toolPathMatch = /^\/tools\/([^/]+)$/.exec(path);
|
|
68
|
-
if (request.method === "POST" && toolPathMatch) {
|
|
69
|
-
const toolName = decodeURIComponent(toolPathMatch[1] ?? "");
|
|
70
|
-
let body: unknown = {};
|
|
71
|
-
const rawBody = await request.text();
|
|
72
|
-
if (rawBody.trim().length > 0) {
|
|
73
|
-
try {
|
|
74
|
-
body = JSON.parse(rawBody);
|
|
75
|
-
} catch {
|
|
76
|
-
return apiErrorResponse(400, { error: "Invalid JSON body" });
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (typeof body !== "object" || body === null || Array.isArray(body)) {
|
|
80
|
-
return apiErrorResponse(400, { error: "Request body must be a JSON object" });
|
|
81
|
-
}
|
|
82
|
-
return invokeApiTool(cli, toolName, body as Record<string, unknown>);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (path === "/tools" || path.startsWith("/tools/")) {
|
|
86
|
-
return apiErrorResponse(405, { error: "Method not allowed" });
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return apiErrorResponse(404, { error: "Not found" });
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/** Resolves a tool and runs it through the shared headless invoke path. */
|
|
93
|
-
async function invokeApiTool(cli: Cli, toolName: string, args: Record<string, unknown>): Promise<Response> {
|
|
94
|
-
const lookup = lookupHeadlessTool(cli.program, toolName, "api");
|
|
95
|
-
if (!lookup.ok) {
|
|
96
|
-
if (lookup.kind === "unknown") {
|
|
97
|
-
return apiErrorResponse(404, { error: lookup.message });
|
|
98
|
-
}
|
|
99
|
-
return apiErrorResponse(503, { error: lookup.message });
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const result = await executeHeadlessToolCall(cli, lookup.tool, args, "api");
|
|
103
|
-
if (result.ok) {
|
|
104
|
-
return headlessSuccessToHttpResponse(result, lookup.tool.leaf.apiResponse);
|
|
105
|
-
}
|
|
106
|
-
return headlessFailureToHttpResponse(result);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/** Runs the HTTP API server until the process is interrupted. */
|
|
110
|
-
export async function apiServeHttp(cli: Cli): Promise<never> {
|
|
111
|
-
const { hostname, port } = resolveApiListenAddress(cli.program);
|
|
112
|
-
const server = Bun.serve({
|
|
113
|
-
hostname,
|
|
114
|
-
port,
|
|
115
|
-
fetch: (request) => handleApiRequest(cli, request),
|
|
116
|
-
});
|
|
117
|
-
process.stderr.write(`HTTP API listening on http://${server.hostname}:${server.port}\n`);
|
|
118
|
-
await new Promise<never>(() => {});
|
|
119
|
-
throw new Error("HTTP API server stopped unexpectedly");
|
|
120
|
-
}
|
package/src/builtins/api.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { resolveApiListenAddress } from "../api/server.ts";
|
|
2
|
-
import { resolveCapabilities } from "../capabilities.ts";
|
|
3
|
-
import { docsEnabled } from "../docs/resolve.ts";
|
|
4
|
-
import { CliFallbackMode, type CliLeaf, type CliProgram, type CliRouter } from "../types.ts";
|
|
5
|
-
|
|
6
|
-
/** Built-in `api` router: bare `myapp api` runs the HTTP server (via hidden `serve` fallback). */
|
|
7
|
-
export function cliBuiltinApiCommand(program: CliProgram): CliRouter {
|
|
8
|
-
const caps = resolveCapabilities(program);
|
|
9
|
-
const { hostname, port } = resolveApiListenAddress(program);
|
|
10
|
-
const lines = [
|
|
11
|
-
`HTTP tool server on http://${hostname}:${port}.`,
|
|
12
|
-
"",
|
|
13
|
-
"Endpoints: GET /health, GET /openapi.json, GET /openapi-browser, POST /tools/:name",
|
|
14
|
-
"",
|
|
15
|
-
];
|
|
16
|
-
if (caps.configure) {
|
|
17
|
-
lines.push("Configure app settings:", "", " {argsbarg:program} configure", "");
|
|
18
|
-
}
|
|
19
|
-
if (docsEnabled(program)) {
|
|
20
|
-
lines.push("Full setup guide: {argsbarg:program} docs http");
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const serve: CliLeaf = {
|
|
24
|
-
key: "serve",
|
|
25
|
-
hidden: true,
|
|
26
|
-
description: "Run as an HTTP API server for tools.",
|
|
27
|
-
handler: () => {},
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
key: "api",
|
|
32
|
-
description: "HTTP API server for tools.",
|
|
33
|
-
notes: lines.join("\n"),
|
|
34
|
-
fallbackCommand: "serve",
|
|
35
|
-
fallbackMode: CliFallbackMode.MissingOnly,
|
|
36
|
-
commands: [serve],
|
|
37
|
-
};
|
|
38
|
-
}
|
package/src/hidden.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Filters hidden commands and options from presentation surfaces (help, schema, completions).
|
|
3
|
-
Parsing still uses the full tree via cliParseRoot.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { CliNode, CliOption } from "./types.ts";
|
|
7
|
-
import { isCliRouter } from "./types.ts";
|
|
8
|
-
|
|
9
|
-
/** Options visible in help, schema, completions, and MCP tool schemas. */
|
|
10
|
-
export function visibleOptions(options: CliOption[] | undefined): CliOption[] {
|
|
11
|
-
return (options ?? []).filter((o) => !o.hidden);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** Strips hidden commands and options from one node for presentation export. */
|
|
15
|
-
export function presentationNode(node: CliNode): CliNode | null {
|
|
16
|
-
if (node.hidden) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
const options = visibleOptions(node.options);
|
|
20
|
-
if (isCliRouter(node)) {
|
|
21
|
-
const commands = node.commands.map((ch) => presentationNode(ch)).filter((ch): ch is CliNode => ch !== null);
|
|
22
|
-
return { ...node, options, commands };
|
|
23
|
-
}
|
|
24
|
-
return { ...node, options };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** Subcommands visible in help listings (parent may be any node in the parse tree). */
|
|
28
|
-
export function visibleSubcommands(cmds: CliNode[]): CliNode[] {
|
|
29
|
-
return cmds.filter((c) => !c.hidden);
|
|
30
|
-
}
|
package/src/install/plan.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { resolveCapabilities } from "../capabilities.ts";
|
|
2
|
-
import type { CliProgram } from "../types.ts";
|
|
3
|
-
import type { InstallPaths } from "./paths.ts";
|
|
4
|
-
import { buildInstallPlanFromTargets } from "./target-plan-build.ts";
|
|
5
|
-
import type { InstallAction, InstallOpts } from "./target-types.ts";
|
|
6
|
-
|
|
7
|
-
export type { InstallAction, InstallActionKind, InstallOpts } from "./target-types.ts";
|
|
8
|
-
|
|
9
|
-
/** Builds install actions for normal mode (--all / scoped targets). */
|
|
10
|
-
export function buildInstallPlan(root: CliProgram, paths: InstallPaths, opts: InstallOpts): InstallAction[] {
|
|
11
|
-
return buildInstallPlanFromTargets(root, paths, opts);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** Builds update/reinstall actions; greenfield fallback when nothing detected. */
|
|
15
|
-
export function buildUpdatePlan(root: CliProgram, paths: InstallPaths, opts: InstallOpts): InstallAction[] {
|
|
16
|
-
const refresh = buildInstallPlanFromTargets(root, paths, {
|
|
17
|
-
...opts,
|
|
18
|
-
reinstall: true,
|
|
19
|
-
all: true,
|
|
20
|
-
});
|
|
21
|
-
if (refresh.length > 0) {
|
|
22
|
-
return refresh;
|
|
23
|
-
}
|
|
24
|
-
return buildInstallPlanFromTargets(root, paths, { ...opts, reinstall: false, all: true });
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** @deprecated Use resolveInstallPlanMode + shouldIncludeArtifact. */
|
|
28
|
-
export function wantsInstallApp(_opts: InstallOpts): boolean {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** @deprecated Use {@link wantsInstallApp}. */
|
|
33
|
-
export const wantsInstallBin = wantsInstallApp;
|
|
34
|
-
|
|
35
|
-
/** @deprecated Use resolveInstallPlanMode + shouldIncludeArtifact. */
|
|
36
|
-
export function wantsInstallCompletions(_opts: InstallOpts): boolean {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** @deprecated Use resolveInstallPlanMode + shouldIncludeArtifact. */
|
|
41
|
-
export function wantsInstallSkill(opts: InstallOpts): boolean {
|
|
42
|
-
return !!(opts.all || opts.skill);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** @deprecated Use resolveInstallPlanMode + shouldIncludeArtifact. */
|
|
46
|
-
export function wantsInstallMcp(opts: InstallOpts, root: CliProgram): boolean {
|
|
47
|
-
return !!(opts.mcp || opts.all) && resolveCapabilities(root).mcp;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** @deprecated Use configure target + shouldIncludeArtifact. */
|
|
51
|
-
export function wantsUninstallConfig(opts: InstallOpts, root: CliProgram): boolean {
|
|
52
|
-
return !!(opts.configure || opts.all) && root.appConfig !== undefined;
|
|
53
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|