kiriya 0.1.0
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 +58 -0
- package/LICENSE +21 -0
- package/README.md +87 -0
- package/dist/src/config/clean-rules.js +39 -0
- package/dist/src/config/config-keys.js +24 -0
- package/dist/src/config/dependency-directories.js +16 -0
- package/dist/src/config/modules.js +38 -0
- package/dist/src/config/protected-paths.js +32 -0
- package/dist/src/config/rebuildable-directories.js +20 -0
- package/dist/src/core/application/command-registry.js +57 -0
- package/dist/src/core/application/config-values.js +33 -0
- package/dist/src/core/application/path-guard.js +69 -0
- package/dist/src/core/application/paths.js +77 -0
- package/dist/src/core/application/plugin-loader.js +100 -0
- package/dist/src/core/application/process-ending.js +28 -0
- package/dist/src/core/application/root-scope.js +123 -0
- package/dist/src/core/application/safety.js +26 -0
- package/dist/src/core/application/text-input.js +44 -0
- package/dist/src/core/application/walk.js +34 -0
- package/dist/src/core/domain/command.js +8 -0
- package/dist/src/core/domain/encodings.js +70 -0
- package/dist/src/core/domain/errors.js +49 -0
- package/dist/src/core/domain/glob.js +57 -0
- package/dist/src/core/domain/global-options.js +10 -0
- package/dist/src/core/domain/input-schema.js +54 -0
- package/dist/src/core/domain/message.js +7 -0
- package/dist/src/core/domain/module.js +2 -0
- package/dist/src/core/domain/names.js +22 -0
- package/dist/src/core/domain/ports/clipboard.js +2 -0
- package/dist/src/core/domain/ports/clock.js +2 -0
- package/dist/src/core/domain/ports/command-catalog.js +2 -0
- package/dist/src/core/domain/ports/compression.js +2 -0
- package/dist/src/core/domain/ports/config-store.js +2 -0
- package/dist/src/core/domain/ports/confirmation.js +2 -0
- package/dist/src/core/domain/ports/environment.js +2 -0
- package/dist/src/core/domain/ports/file-content.js +2 -0
- package/dist/src/core/domain/ports/file-system.js +2 -0
- package/dist/src/core/domain/ports/hasher.js +2 -0
- package/dist/src/core/domain/ports/network.js +2 -0
- package/dist/src/core/domain/ports/opener.js +2 -0
- package/dist/src/core/domain/ports/passthrough.js +2 -0
- package/dist/src/core/domain/ports/plugin-inventory.js +2 -0
- package/dist/src/core/domain/ports/plugin-source.js +2 -0
- package/dist/src/core/domain/ports/port-table.js +2 -0
- package/dist/src/core/domain/ports/process-runner.js +2 -0
- package/dist/src/core/domain/ports/process-table.js +2 -0
- package/dist/src/core/domain/ports/protected-paths.js +2 -0
- package/dist/src/core/domain/ports/random-source.js +2 -0
- package/dist/src/core/domain/ports/standard-input.js +2 -0
- package/dist/src/core/domain/ports/system-info.js +2 -0
- package/dist/src/core/domain/ports/trash.js +2 -0
- package/dist/src/core/domain/secrets.js +59 -0
- package/dist/src/core/domain/targets.js +41 -0
- package/dist/src/core/domain/text-case.js +39 -0
- package/dist/src/core/domain/values/bytes.js +13 -0
- package/dist/src/core/domain/view.js +2 -0
- package/dist/src/core/infrastructure/node/can-listen.js +10 -0
- package/dist/src/core/infrastructure/node/closed-standard-input.adapter.js +12 -0
- package/dist/src/core/infrastructure/node/config-location.js +27 -0
- package/dist/src/core/infrastructure/node/fs-errors.js +22 -0
- package/dist/src/core/infrastructure/node/json-config-store.adapter.js +69 -0
- package/dist/src/core/infrastructure/node/node-compression.adapter.js +82 -0
- package/dist/src/core/infrastructure/node/node-environment.adapter.js +21 -0
- package/dist/src/core/infrastructure/node/node-file-content.adapter.js +99 -0
- package/dist/src/core/infrastructure/node/node-file-system.adapter.js +169 -0
- package/dist/src/core/infrastructure/node/node-hasher.adapter.js +32 -0
- package/dist/src/core/infrastructure/node/node-network.adapter.js +168 -0
- package/dist/src/core/infrastructure/node/node-plugin-source.adapter.js +89 -0
- package/dist/src/core/infrastructure/node/node-process-runner.adapter.js +48 -0
- package/dist/src/core/infrastructure/node/node-random-source.adapter.js +7 -0
- package/dist/src/core/infrastructure/node/node-standard-input.adapter.js +24 -0
- package/dist/src/core/infrastructure/node/node-system-info.adapter.js +63 -0
- package/dist/src/core/infrastructure/node/process-signals.js +51 -0
- package/dist/src/core/infrastructure/node/run-program.js +65 -0
- package/dist/src/core/infrastructure/node/system-clock.adapter.js +22 -0
- package/dist/src/core/infrastructure/node/typed-programs.js +45 -0
- package/dist/src/core/infrastructure/platform/linux/freedesktop-trash.adapter.js +115 -0
- package/dist/src/core/infrastructure/platform/linux/linux-clipboard.adapter.js +70 -0
- package/dist/src/core/infrastructure/platform/linux/linux-opener.adapter.js +21 -0
- package/dist/src/core/infrastructure/platform/linux/linux-port-table.adapter.js +97 -0
- package/dist/src/core/infrastructure/platform/linux/linux-process-table.adapter.js +61 -0
- package/dist/src/core/infrastructure/platform/macos/macos-clipboard.adapter.js +29 -0
- package/dist/src/core/infrastructure/platform/macos/macos-opener.adapter.js +13 -0
- package/dist/src/core/infrastructure/platform/macos/macos-port-table.adapter.js +86 -0
- package/dist/src/core/infrastructure/platform/macos/macos-process-table.adapter.js +62 -0
- package/dist/src/core/infrastructure/platform/macos/macos-trash.adapter.js +64 -0
- package/dist/src/core/infrastructure/platform/windows/system32.js +6 -0
- package/dist/src/core/infrastructure/platform/windows/windows-clipboard.adapter.js +50 -0
- package/dist/src/core/infrastructure/platform/windows/windows-opener.adapter.js +11 -0
- package/dist/src/core/infrastructure/platform/windows/windows-port-table.adapter.js +38 -0
- package/dist/src/core/infrastructure/platform/windows/windows-process-table.adapter.js +134 -0
- package/dist/src/core/infrastructure/platform/windows/windows-trash.adapter.js +86 -0
- package/dist/src/core/presentation/cli/argv.js +83 -0
- package/dist/src/core/presentation/cli/cli-application.js +201 -0
- package/dist/src/core/presentation/cli/cli-view-format.js +46 -0
- package/dist/src/core/presentation/cli/help.js +202 -0
- package/dist/src/core/presentation/cli/json-output.js +28 -0
- package/dist/src/core/presentation/cli/style.js +21 -0
- package/dist/src/core/presentation/cli/suggest.js +25 -0
- package/dist/src/core/presentation/cli/terminal-confirmation.js +63 -0
- package/dist/src/core/presentation/ended-processes.js +18 -0
- package/dist/src/core/presentation/i18n/translator.js +23 -0
- package/dist/src/core/presentation/list-preview.js +10 -0
- package/dist/src/core/presentation/mcp/elicitation.js +55 -0
- package/dist/src/core/presentation/mcp/mcp-application.js +60 -0
- package/dist/src/core/presentation/mcp/mcp-confirmation.js +59 -0
- package/dist/src/core/presentation/mcp/mcp-server.js +355 -0
- package/dist/src/core/presentation/mcp/protocol.js +32 -0
- package/dist/src/core/presentation/mcp/request-state.js +66 -0
- package/dist/src/core/presentation/mcp/tool-definitions.js +149 -0
- package/dist/src/core/presentation/mcp/tool-results.js +56 -0
- package/dist/src/i18n/locales/en.js +827 -0
- package/dist/src/main.js +154 -0
- package/dist/src/modules/archive/application/archive-sources.js +55 -0
- package/dist/src/modules/archive/application/create-tar.use-case.js +123 -0
- package/dist/src/modules/archive/application/create-zip.use-case.js +106 -0
- package/dist/src/modules/archive/application/extract-tar.use-case.js +240 -0
- package/dist/src/modules/archive/application/extract-zip.use-case.js +181 -0
- package/dist/src/modules/archive/application/tar-reader.js +45 -0
- package/dist/src/modules/archive/application/zip-reader.js +57 -0
- package/dist/src/modules/archive/archive.module.js +27 -0
- package/dist/src/modules/archive/domain/crc32.js +18 -0
- package/dist/src/modules/archive/domain/tar-format.js +97 -0
- package/dist/src/modules/archive/domain/tar-stream.js +223 -0
- package/dist/src/modules/archive/domain/zip-format.js +158 -0
- package/dist/src/modules/archive/presentation/tar.view.js +17 -0
- package/dist/src/modules/archive/presentation/untar.view.js +30 -0
- package/dist/src/modules/archive/presentation/unzip.view.js +24 -0
- package/dist/src/modules/archive/presentation/zip.view.js +17 -0
- package/dist/src/modules/clip/application/copy-text.use-case.js +43 -0
- package/dist/src/modules/clip/application/paste-text.use-case.js +25 -0
- package/dist/src/modules/clip/clip.module.js +16 -0
- package/dist/src/modules/clip/presentation/clip.views.js +7 -0
- package/dist/src/modules/completion/application/print-script.use-case.js +38 -0
- package/dist/src/modules/completion/application/suggest-words.use-case.js +37 -0
- package/dist/src/modules/completion/completion.module.js +14 -0
- package/dist/src/modules/completion/domain/scripts.js +91 -0
- package/dist/src/modules/completion/domain/suggest.js +134 -0
- package/dist/src/modules/completion/presentation/completion.views.js +6 -0
- package/dist/src/modules/config/application/config-commands.js +14 -0
- package/dist/src/modules/config/application/get-setting.use-case.js +25 -0
- package/dist/src/modules/config/application/list-config-keys.use-case.js +26 -0
- package/dist/src/modules/config/application/list-settings.use-case.js +28 -0
- package/dist/src/modules/config/application/set-setting.use-case.js +53 -0
- package/dist/src/modules/config/application/show-config-path.use-case.js +21 -0
- package/dist/src/modules/config/application/unset-setting.use-case.js +28 -0
- package/dist/src/modules/config/config.module.js +28 -0
- package/dist/src/modules/config/presentation/config.views.js +33 -0
- package/dist/src/modules/convert/application/convert-case.use-case.js +38 -0
- package/dist/src/modules/convert/application/convert-codecs.use-case.js +92 -0
- package/dist/src/modules/convert/application/convert-input.js +16 -0
- package/dist/src/modules/convert/application/convert-json.use-case.js +51 -0
- package/dist/src/modules/convert/application/convert-time.use-case.js +39 -0
- package/dist/src/modules/convert/application/decode-jwt.use-case.js +52 -0
- package/dist/src/modules/convert/convert.module.js +29 -0
- package/dist/src/modules/convert/domain/json-syntax.js +135 -0
- package/dist/src/modules/convert/domain/jwt.js +29 -0
- package/dist/src/modules/convert/domain/moments.js +20 -0
- package/dist/src/modules/convert/presentation/convert.views.js +44 -0
- package/dist/src/modules/docker/application/clean-engine.use-case.js +77 -0
- package/dist/src/modules/docker/application/compose-project.js +45 -0
- package/dist/src/modules/docker/application/docker-engine.js +40 -0
- package/dist/src/modules/docker/application/list-containers.use-case.js +69 -0
- package/dist/src/modules/docker/application/run-compose.use-case.js +83 -0
- package/dist/src/modules/docker/application/show-logs.use-case.js +51 -0
- package/dist/src/modules/docker/application/stop-project.use-case.js +56 -0
- package/dist/src/modules/docker/docker.module.js +23 -0
- package/dist/src/modules/docker/domain/compose-file.js +105 -0
- package/dist/src/modules/docker/domain/engine-output.js +65 -0
- package/dist/src/modules/docker/presentation/docker.views.js +63 -0
- package/dist/src/modules/doctor/application/run-checks.use-case.js +128 -0
- package/dist/src/modules/doctor/doctor.module.js +13 -0
- package/dist/src/modules/doctor/domain/versions.js +22 -0
- package/dist/src/modules/doctor/presentation/doctor.view.js +30 -0
- package/dist/src/modules/env/application/check-dotenv.use-case.js +116 -0
- package/dist/src/modules/env/application/inspect-path.use-case.js +71 -0
- package/dist/src/modules/env/application/path-entries.js +28 -0
- package/dist/src/modules/env/application/show-variables.use-case.js +47 -0
- package/dist/src/modules/env/domain/dotenv.js +62 -0
- package/dist/src/modules/env/env.module.js +17 -0
- package/dist/src/modules/env/presentation/env.views.js +43 -0
- package/dist/src/modules/files/application/clean-builds.use-case.js +149 -0
- package/dist/src/modules/files/application/compare-paths.use-case.js +127 -0
- package/dist/src/modules/files/application/copy-paths.use-case.js +101 -0
- package/dist/src/modules/files/application/create-paths.use-case.js +85 -0
- package/dist/src/modules/files/application/delete-paths.use-case.js +127 -0
- package/dist/src/modules/files/application/find-duplicates.use-case.js +105 -0
- package/dist/src/modules/files/application/find-files.use-case.js +131 -0
- package/dist/src/modules/files/application/hash-files.use-case.js +73 -0
- package/dist/src/modules/files/application/list-entries.use-case.js +87 -0
- package/dist/src/modules/files/application/measure-folders.use-case.js +102 -0
- package/dist/src/modules/files/application/move-entry.js +19 -0
- package/dist/src/modules/files/application/move-paths.use-case.js +82 -0
- package/dist/src/modules/files/application/read-text.use-case.js +92 -0
- package/dist/src/modules/files/application/rename-paths.use-case.js +184 -0
- package/dist/src/modules/files/application/replace-text.use-case.js +146 -0
- package/dist/src/modules/files/application/search-text.use-case.js +115 -0
- package/dist/src/modules/files/application/show-info.use-case.js +80 -0
- package/dist/src/modules/files/application/show-tree.use-case.js +75 -0
- package/dist/src/modules/files/application/sync-folders.use-case.js +162 -0
- package/dist/src/modules/files/application/text-files.js +46 -0
- package/dist/src/modules/files/application/transfers.js +35 -0
- package/dist/src/modules/files/domain/case-style.js +18 -0
- package/dist/src/modules/files/domain/filters.js +9 -0
- package/dist/src/modules/files/domain/sync-plan.js +35 -0
- package/dist/src/modules/files/domain/text-encoding.js +75 -0
- package/dist/src/modules/files/domain/values.js +28 -0
- package/dist/src/modules/files/files.module.js +70 -0
- package/dist/src/modules/files/presentation/clean.view.js +15 -0
- package/dist/src/modules/files/presentation/compare.view.js +50 -0
- package/dist/src/modules/files/presentation/copy.view.js +17 -0
- package/dist/src/modules/files/presentation/delete.view.js +16 -0
- package/dist/src/modules/files/presentation/dupes.view.js +20 -0
- package/dist/src/modules/files/presentation/find.view.js +16 -0
- package/dist/src/modules/files/presentation/grep.view.js +27 -0
- package/dist/src/modules/files/presentation/hash.view.js +15 -0
- package/dist/src/modules/files/presentation/info.view.js +36 -0
- package/dist/src/modules/files/presentation/list.view.js +17 -0
- package/dist/src/modules/files/presentation/move.view.js +14 -0
- package/dist/src/modules/files/presentation/new.view.js +8 -0
- package/dist/src/modules/files/presentation/read.view.js +6 -0
- package/dist/src/modules/files/presentation/rename.view.js +16 -0
- package/dist/src/modules/files/presentation/replace.view.js +26 -0
- package/dist/src/modules/files/presentation/size.view.js +24 -0
- package/dist/src/modules/files/presentation/sync.view.js +37 -0
- package/dist/src/modules/files/presentation/tree.view.js +22 -0
- package/dist/src/modules/gen/application/gen-options.js +18 -0
- package/dist/src/modules/gen/application/generate-passwords.use-case.js +39 -0
- package/dist/src/modules/gen/application/generate-tokens.use-case.js +38 -0
- package/dist/src/modules/gen/application/generate-ulids.use-case.js +40 -0
- package/dist/src/modules/gen/application/generate-uuids.use-case.js +32 -0
- package/dist/src/modules/gen/domain/identifiers.js +65 -0
- package/dist/src/modules/gen/domain/secrets.js +43 -0
- package/dist/src/modules/gen/gen.module.js +20 -0
- package/dist/src/modules/git/application/fetch-repositories.use-case.js +50 -0
- package/dist/src/modules/git/application/git-client.js +62 -0
- package/dist/src/modules/git/application/pull-repositories.use-case.js +67 -0
- package/dist/src/modules/git/application/repositories.js +67 -0
- package/dist/src/modules/git/application/show-status.use-case.js +49 -0
- package/dist/src/modules/git/application/switch-branch.use-case.js +118 -0
- package/dist/src/modules/git/domain/repository-status.js +37 -0
- package/dist/src/modules/git/git.module.js +25 -0
- package/dist/src/modules/git/presentation/git.views.js +100 -0
- package/dist/src/modules/net/application/check-connection.use-case.js +71 -0
- package/dist/src/modules/net/application/list-addresses.use-case.js +29 -0
- package/dist/src/modules/net/application/lookup-name.use-case.js +55 -0
- package/dist/src/modules/net/net.module.js +17 -0
- package/dist/src/modules/net/presentation/net.views.js +39 -0
- package/dist/src/modules/open/application/open-target.use-case.js +53 -0
- package/dist/src/modules/open/domain/targets.js +45 -0
- package/dist/src/modules/open/open.module.js +12 -0
- package/dist/src/modules/open/presentation/open.view.js +6 -0
- package/dist/src/modules/port/application/end-port-owners.use-case.js +68 -0
- package/dist/src/modules/port/application/find-free-port.use-case.js +40 -0
- package/dist/src/modules/port/application/find-listeners.use-case.js +34 -0
- package/dist/src/modules/port/application/port-owners.js +25 -0
- package/dist/src/modules/port/domain/port-number.js +8 -0
- package/dist/src/modules/port/port.module.js +17 -0
- package/dist/src/modules/port/presentation/port.views.js +27 -0
- package/dist/src/modules/proc/application/end-processes.use-case.js +77 -0
- package/dist/src/modules/proc/application/find-processes.use-case.js +50 -0
- package/dist/src/modules/proc/application/list-processes.use-case.js +41 -0
- package/dist/src/modules/proc/application/show-tree.use-case.js +40 -0
- package/dist/src/modules/proc/domain/process-tree.js +55 -0
- package/dist/src/modules/proc/presentation/proc.views.js +28 -0
- package/dist/src/modules/proc/proc.module.js +19 -0
- package/dist/src/modules/sys/application/create-report.use-case.js +30 -0
- package/dist/src/modules/sys/application/find-tools.use-case.js +20 -0
- package/dist/src/modules/sys/application/machine-facts.js +44 -0
- package/dist/src/modules/sys/application/show-info.use-case.js +29 -0
- package/dist/src/modules/sys/domain/tools.js +17 -0
- package/dist/src/modules/sys/presentation/sys.views.js +67 -0
- package/dist/src/modules/sys/sys.module.js +17 -0
- package/dist/src/modules/wait/application/poll.js +26 -0
- package/dist/src/modules/wait/application/wait-file.use-case.js +55 -0
- package/dist/src/modules/wait/application/wait-port.use-case.js +76 -0
- package/dist/src/modules/wait/application/wait-url.use-case.js +71 -0
- package/dist/src/modules/wait/domain/reasons.js +14 -0
- package/dist/src/modules/wait/domain/wait-input.js +50 -0
- package/dist/src/modules/wait/presentation/wait.views.js +31 -0
- package/dist/src/modules/wait/wait.module.js +21 -0
- package/package.json +57 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { UsageError } from "../../domain/errors.js";
|
|
2
|
+
import { message } from "../../domain/message.js";
|
|
3
|
+
import { isObject } from "./protocol.js";
|
|
4
|
+
const MESSAGES = { type: "array", items: { type: "object" } };
|
|
5
|
+
/** The JSON document `--json` prints, for a result and for an error alike, plus what the server adds. */
|
|
6
|
+
export const OUTPUT_SCHEMA = {
|
|
7
|
+
type: "object",
|
|
8
|
+
properties: {
|
|
9
|
+
ok: { type: "boolean" },
|
|
10
|
+
command: { type: "string" },
|
|
11
|
+
kind: { type: "string", enum: ["done", "preview"] },
|
|
12
|
+
applyFlag: { type: "string" },
|
|
13
|
+
data: {},
|
|
14
|
+
warnings: MESSAGES,
|
|
15
|
+
failures: MESSAGES,
|
|
16
|
+
error: { type: "object" },
|
|
17
|
+
output: { type: "string", description: "What a program the command ran printed" },
|
|
18
|
+
truncated: {
|
|
19
|
+
type: "array",
|
|
20
|
+
items: { type: "object" },
|
|
21
|
+
description: "Where the result was cut to fit, and how much",
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
required: ["ok"],
|
|
25
|
+
};
|
|
26
|
+
const READING = { sensitive: false, changes: false };
|
|
27
|
+
export function toolAccess(spec, allowWrite) {
|
|
28
|
+
return { sensitive: allowWrite, changes: spec.safety !== "read" };
|
|
29
|
+
}
|
|
30
|
+
/** The options a tool takes: never those only for a terminal, and the others as access allows. */
|
|
31
|
+
function toolOptions(input, access) {
|
|
32
|
+
return Object.entries(input.options).filter(([, option]) => option.terminalOnly !== true &&
|
|
33
|
+
(option.sensitive !== true || access.sensitive) &&
|
|
34
|
+
(option.reachesHidden !== true || !access.changes));
|
|
35
|
+
}
|
|
36
|
+
/** All four annotations, always, because a client assumes the worst for any left out. */
|
|
37
|
+
export function annotationsOf(spec) {
|
|
38
|
+
return {
|
|
39
|
+
readOnlyHint: spec.safety === "read",
|
|
40
|
+
destructiveHint: spec.safety === "destroy",
|
|
41
|
+
idempotentHint: spec.idempotent,
|
|
42
|
+
openWorldHint: spec.usesNetwork,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/** One property per argument and option, named as in help; arguments a command needs are required. */
|
|
46
|
+
export function inputSchemaOf(commandId, input, translator, access = READING) {
|
|
47
|
+
const properties = {};
|
|
48
|
+
const required = [];
|
|
49
|
+
const claim = (name, schema) => {
|
|
50
|
+
if (Object.hasOwn(properties, name))
|
|
51
|
+
throw new Error(`${commandId}: ${name} is both an argument and an option`);
|
|
52
|
+
properties[name] = schema;
|
|
53
|
+
};
|
|
54
|
+
for (const positional of input.positionals) {
|
|
55
|
+
const description = translator.text(message(positional.description));
|
|
56
|
+
const value = {
|
|
57
|
+
type: "string",
|
|
58
|
+
...(positional.choices === undefined ? {} : { enum: [...positional.choices] }),
|
|
59
|
+
};
|
|
60
|
+
claim(positional.name, positional.variadic
|
|
61
|
+
? { type: "array", items: value, ...(positional.required ? { minItems: 1 } : {}), description }
|
|
62
|
+
: { ...value, description });
|
|
63
|
+
if (positional.required)
|
|
64
|
+
required.push(positional.name);
|
|
65
|
+
}
|
|
66
|
+
for (const [name, option] of toolOptions(input, access)) {
|
|
67
|
+
const text = translator.text(message(option.description));
|
|
68
|
+
const description = option.valueName === undefined ? text : `${text} ${option.valueName}`;
|
|
69
|
+
if (option.type === "boolean")
|
|
70
|
+
claim(name, { type: "boolean", description });
|
|
71
|
+
else if (option.multiple === true)
|
|
72
|
+
claim(name, { type: "array", items: { type: "string" }, description });
|
|
73
|
+
else
|
|
74
|
+
claim(name, { type: "string", description });
|
|
75
|
+
}
|
|
76
|
+
return { type: "object", properties, ...(required.length > 0 ? { required } : {}), additionalProperties: false };
|
|
77
|
+
}
|
|
78
|
+
export function toolDefinition(spec, translator, allowWrite) {
|
|
79
|
+
return {
|
|
80
|
+
name: spec.id,
|
|
81
|
+
description: translator.text(message(spec.summary)),
|
|
82
|
+
inputSchema: inputSchemaOf(spec.id, spec.input, translator, toolAccess(spec, allowWrite)),
|
|
83
|
+
outputSchema: OUTPUT_SCHEMA,
|
|
84
|
+
annotations: annotationsOf(spec),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function text(value, name) {
|
|
88
|
+
if (typeof value !== "string")
|
|
89
|
+
throw new UsageError("core.mcp.expects-text", { name });
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
function textList(value, name) {
|
|
93
|
+
if (!Array.isArray(value) || !value.every((item) => typeof item === "string")) {
|
|
94
|
+
throw new UsageError("core.mcp.expects-list", { name });
|
|
95
|
+
}
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The JSON arguments of a call as the command's raw input, checked against the schema
|
|
100
|
+
* the tool publishes. The command's own parse checks the values next, as it does for argv.
|
|
101
|
+
*/
|
|
102
|
+
export function rawInputOf(input, args, access = READING) {
|
|
103
|
+
const given = args ?? {};
|
|
104
|
+
if (!isObject(given))
|
|
105
|
+
throw new UsageError("core.mcp.arguments-not-object");
|
|
106
|
+
const options = new Map(toolOptions(input, access));
|
|
107
|
+
for (const name of Object.keys(given)) {
|
|
108
|
+
if (!options.has(name) && !input.positionals.some((positional) => positional.name === name)) {
|
|
109
|
+
throw new UsageError("core.mcp.unknown-argument", { name });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const positionals = [];
|
|
113
|
+
let skipped;
|
|
114
|
+
for (const positional of input.positionals) {
|
|
115
|
+
const value = given[positional.name];
|
|
116
|
+
const values = value === undefined
|
|
117
|
+
? []
|
|
118
|
+
: positional.variadic
|
|
119
|
+
? textList(value, positional.name)
|
|
120
|
+
: [text(value, positional.name)];
|
|
121
|
+
if (values.length === 0) {
|
|
122
|
+
if (positional.required)
|
|
123
|
+
throw new UsageError("core.usage.missing-argument", { name: positional.name });
|
|
124
|
+
skipped ??= positional.name;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
// Arguments are positional underneath, so a later one cannot stand in for an earlier one left out.
|
|
128
|
+
if (skipped !== undefined)
|
|
129
|
+
throw new UsageError("core.usage.missing-argument", { name: skipped });
|
|
130
|
+
positionals.push(...values);
|
|
131
|
+
}
|
|
132
|
+
const raw = {};
|
|
133
|
+
for (const [name, option] of options) {
|
|
134
|
+
const value = given[name];
|
|
135
|
+
if (value === undefined)
|
|
136
|
+
continue;
|
|
137
|
+
if (option.type === "boolean") {
|
|
138
|
+
if (typeof value !== "boolean")
|
|
139
|
+
throw new UsageError("core.mcp.expects-boolean", { name });
|
|
140
|
+
if (value)
|
|
141
|
+
raw[name] = true;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
raw[name] = option.multiple === true ? textList(value, name) : text(value, name);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return { positionals, options: raw };
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=tool-definitions.js.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { errorJson, resultJson } from "../cli/json-output.js";
|
|
2
|
+
import { isObject } from "./protocol.js";
|
|
3
|
+
/** Roughly ten thousand tokens: enough for a model to act on, small enough for its context. */
|
|
4
|
+
export const OUTPUT_LIMITS = { items: 200, characters: 40_000 };
|
|
5
|
+
function trim(value, at, items, characters, cuts) {
|
|
6
|
+
if (typeof value === "string") {
|
|
7
|
+
if (value.length <= characters)
|
|
8
|
+
return value;
|
|
9
|
+
cuts.push({ at, omitted: value.length - characters, unit: "characters" });
|
|
10
|
+
return value.slice(0, characters);
|
|
11
|
+
}
|
|
12
|
+
if (Array.isArray(value)) {
|
|
13
|
+
if (value.length > items)
|
|
14
|
+
cuts.push({ at, omitted: value.length - items, unit: "items" });
|
|
15
|
+
return value.slice(0, items).map((item, index) => trim(item, `${at}[${index}]`, items, characters, cuts));
|
|
16
|
+
}
|
|
17
|
+
if (isObject(value)) {
|
|
18
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [
|
|
19
|
+
key,
|
|
20
|
+
trim(item, at === "" ? key : `${at}.${key}`, items, characters, cuts),
|
|
21
|
+
]));
|
|
22
|
+
}
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
/** Long lists keep their first items and long texts their start, tighter each round, until the document fits. */
|
|
26
|
+
export function limitDocument(document, limits) {
|
|
27
|
+
let items = limits.items;
|
|
28
|
+
let characters = limits.characters;
|
|
29
|
+
for (;;) {
|
|
30
|
+
const cuts = [];
|
|
31
|
+
const trimmed = trim(document, "", items, characters, cuts);
|
|
32
|
+
const limited = cuts.length === 0 ? trimmed : { ...trimmed, truncated: cuts };
|
|
33
|
+
if (JSON.stringify(limited).length <= limits.characters || (items === 10 && characters === 1000))
|
|
34
|
+
return limited;
|
|
35
|
+
items = Math.max(10, Math.floor(items / 2));
|
|
36
|
+
characters = Math.max(1000, Math.floor(characters / 2));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function toolResult(document, isError, limits) {
|
|
40
|
+
const structuredContent = limitDocument(document, limits);
|
|
41
|
+
return { content: [{ type: "text", text: JSON.stringify(structuredContent) }], structuredContent, isError };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The document `--json` prints, as structured content and repeated as text. Output a
|
|
45
|
+
* program printed on the way, such as docker's, is added; failures make it an error.
|
|
46
|
+
*/
|
|
47
|
+
export function commandToolResult(commandId, result, output, translator, limits = OUTPUT_LIMITS) {
|
|
48
|
+
const document = JSON.parse(resultJson(commandId, result, translator));
|
|
49
|
+
const failed = result.kind === "done" && result.failures.length > 0;
|
|
50
|
+
return toolResult(output === "" ? document : { ...document, output }, failed, limits);
|
|
51
|
+
}
|
|
52
|
+
/** A typed error as the document `--json` prints, so the model reads what to change. */
|
|
53
|
+
export function errorToolResult(error, translator, limits = OUTPUT_LIMITS) {
|
|
54
|
+
return toolResult(JSON.parse(errorJson(error, translator)), true, limits);
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=tool-results.js.map
|