@acid-cat/cli 0.11.1 → 0.12.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/README.md +11 -2
- package/conformance/fixture.acidcat.json +100 -1
- package/dist/catalog.d.ts +0 -4
- package/dist/catalog.js +14 -29
- package/dist/conform/check.d.ts +0 -27
- package/dist/conform/check.js +0 -27
- package/dist/conform/cli.js +212 -16
- package/dist/conform/http.js +0 -5
- package/dist/conform/index.js +0 -4
- package/dist/conform/mcp-stdio.js +1 -23
- package/dist/conform/mcp.d.ts +0 -28
- package/dist/conform/mcp.js +0 -30
- package/dist/conform/poll.js +0 -18
- package/dist/conform/properties.d.ts +0 -3
- package/dist/conform/properties.js +0 -18
- package/dist/conform/serve.js +1 -10
- package/dist/conform/sse.d.ts +0 -6
- package/dist/conform/sse.js +10 -13
- package/dist/conform/webhook.d.ts +0 -2
- package/dist/conform/webhook.js +2 -26
- package/dist/conform/webmcp.d.ts +1 -17
- package/dist/conform/webmcp.js +8 -23
- package/dist/index.d.ts +0 -1
- package/dist/json/catalog.schema.json.js +29 -1
- package/dist/json/fixture.acidcat.json.js +58 -1
- package/dist/json/package.json.js +1 -1
- package/dist/json.d.ts +0 -11
- package/dist/json.js +0 -7
- package/dist/main.js +62 -22
- package/package.json +3 -3
|
@@ -6,9 +6,45 @@ var fixture_acidcat_default = {
|
|
|
6
6
|
targets: {
|
|
7
7
|
"api": { "bindings": ["http"] },
|
|
8
8
|
"app": { "bindings": ["typescript", "webmcp"] },
|
|
9
|
-
"cli": {
|
|
9
|
+
"cli": {
|
|
10
|
+
"bindings": ["cli"],
|
|
11
|
+
"options": { "cli": {
|
|
12
|
+
"aliases": {
|
|
13
|
+
"--hello": {
|
|
14
|
+
"capability": "fixture.echo",
|
|
15
|
+
"input": { "text": "hello" }
|
|
16
|
+
},
|
|
17
|
+
"broken-ticks": { "event": "fixture.broken" },
|
|
18
|
+
"echoes": { "event": "fixture.echoes" },
|
|
19
|
+
"fixed-note": {
|
|
20
|
+
"capability": "fixture.note",
|
|
21
|
+
"input": { "text": "fixed" }
|
|
22
|
+
},
|
|
23
|
+
"held-keys": { "capability": "fixture.held" },
|
|
24
|
+
"quick": {
|
|
25
|
+
"capability": "fixture.flags",
|
|
26
|
+
"input": { "mode": "fast" }
|
|
27
|
+
},
|
|
28
|
+
"raw": { "capability": "fixture.raw" },
|
|
29
|
+
"say": { "capability": "fixture.echo" },
|
|
30
|
+
"ticks": {
|
|
31
|
+
"event": "fixture.ticks",
|
|
32
|
+
"input": { "count": 2 }
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"default": "quick"
|
|
36
|
+
} }
|
|
37
|
+
},
|
|
10
38
|
"mcp": { "bindings": ["mcp"] }
|
|
11
39
|
},
|
|
40
|
+
$defs: { "Note": {
|
|
41
|
+
"properties": {
|
|
42
|
+
"loud": { "type": "boolean" },
|
|
43
|
+
"text": { "type": "string" }
|
|
44
|
+
},
|
|
45
|
+
"required": ["text"],
|
|
46
|
+
"type": "object"
|
|
47
|
+
} },
|
|
12
48
|
capabilities: {
|
|
13
49
|
"fixture.crash": {
|
|
14
50
|
"description": "Always fail with a defect.",
|
|
@@ -133,6 +169,21 @@ var fixture_acidcat_default = {
|
|
|
133
169
|
"type": "object"
|
|
134
170
|
}
|
|
135
171
|
},
|
|
172
|
+
"fixture.note": {
|
|
173
|
+
"description": "Return the input. The input schema is a $ref with a description beside it.",
|
|
174
|
+
"audience": ["cli"],
|
|
175
|
+
"input": {
|
|
176
|
+
"$ref": "#/$defs/Note",
|
|
177
|
+
"description": "The note."
|
|
178
|
+
},
|
|
179
|
+
"output": { "$ref": "#/$defs/Note" }
|
|
180
|
+
},
|
|
181
|
+
"fixture.raw": {
|
|
182
|
+
"description": "Return the input. The input schema has no top-level properties member.",
|
|
183
|
+
"audience": ["cli"],
|
|
184
|
+
"input": { "type": "object" },
|
|
185
|
+
"output": { "type": "object" }
|
|
186
|
+
},
|
|
136
187
|
"fixture.refuse": {
|
|
137
188
|
"description": "Always return the failure Refused.",
|
|
138
189
|
"audience": [
|
|
@@ -250,6 +301,12 @@ var fixture_acidcat_default = {
|
|
|
250
301
|
"type": "object"
|
|
251
302
|
}
|
|
252
303
|
},
|
|
304
|
+
"fixture.echoes": {
|
|
305
|
+
"description": "Give one occurrence whose data is the input, then end.",
|
|
306
|
+
"audience": ["cli"],
|
|
307
|
+
"input": { "type": "object" },
|
|
308
|
+
"payload": { "type": "object" }
|
|
309
|
+
},
|
|
253
310
|
"fixture.secret": {
|
|
254
311
|
"description": "Only the app target can follow this event. It never gives an occurrence.",
|
|
255
312
|
"audience": ["app"]
|
package/dist/json.d.ts
CHANGED
|
@@ -1,22 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks of JSON values at run time. A value from a file, a process or a network is not trusted. These checks give it a
|
|
3
|
-
* type only after they examine it.
|
|
4
|
-
*/
|
|
5
1
|
import type { JsonObject } from "@acid-cat/spec-ts";
|
|
6
2
|
export type { JsonObject };
|
|
7
|
-
/** True if the value is a JSON object: not `null`, and not an array. */
|
|
8
3
|
export declare const isObject: (value: unknown) => value is JsonObject;
|
|
9
|
-
/** True if the value is an array of strings. */
|
|
10
4
|
export declare const isStringArray: (value: unknown) => value is readonly string[];
|
|
11
|
-
/** True if the value is a JSON object, and `isMember` is true for each of its member values. */
|
|
12
5
|
export declare const isRecordOf: <T>(value: unknown, isMember: (member: unknown) => member is T) => value is {
|
|
13
6
|
readonly [key: string]: T;
|
|
14
7
|
};
|
|
15
|
-
/** The member `key` of a value, or `undefined` when the value is not an object. */
|
|
16
8
|
export declare const memberOf: (value: unknown, key: string) => unknown;
|
|
17
|
-
/** Parse JSON text. The value is not trusted, so its type is `unknown`. */
|
|
18
9
|
export declare function parseJson(text: string): unknown;
|
|
19
|
-
/** Read the body of a response as JSON. The value is not trusted, so its type is `unknown`. */
|
|
20
10
|
export declare function readJson(response: Response): Promise<unknown>;
|
|
21
|
-
/** True if the value is an array, and `isItem` is true for each of its items. */
|
|
22
11
|
export declare const isArrayOf: <T>(value: unknown, isItem: (item: unknown) => item is T) => value is readonly T[];
|
package/dist/json.js
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
// src/json.ts
|
|
2
|
-
/** True if the value is a JSON object: not `null`, and not an array. */
|
|
3
2
|
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4
|
-
/** True if the value is an array of strings. */
|
|
5
3
|
const isStringArray = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
6
|
-
/** True if the value is a JSON object, and `isMember` is true for each of its member values. */
|
|
7
4
|
const isRecordOf = (value, isMember) => isObject(value) && Object.values(value).every(isMember);
|
|
8
|
-
/** The member `key` of a value, or `undefined` when the value is not an object. */
|
|
9
5
|
const memberOf = (value, key) => isObject(value) ? value[key] : void 0;
|
|
10
|
-
/** Parse JSON text. The value is not trusted, so its type is `unknown`. */
|
|
11
6
|
function parseJson(text) {
|
|
12
7
|
return JSON.parse(text);
|
|
13
8
|
}
|
|
14
|
-
/** Read the body of a response as JSON. The value is not trusted, so its type is `unknown`. */
|
|
15
9
|
async function readJson(response) {
|
|
16
10
|
return await response.json();
|
|
17
11
|
}
|
|
18
|
-
/** True if the value is an array, and `isItem` is true for each of its items. */
|
|
19
12
|
const isArrayOf = (value, isItem) => Array.isArray(value) && value.every(isItem);
|
|
20
13
|
export { isArrayOf, isObject, isRecordOf, isStringArray, memberOf, parseJson, readJson };
|
package/dist/main.js
CHANGED
|
@@ -5,38 +5,68 @@ import { DEADLINE } from "./conform/check.js";
|
|
|
5
5
|
import { conform } from "./conform/index.js";
|
|
6
6
|
import { parseJson } from "./json.js";
|
|
7
7
|
import { canonicalText } from "@acid-cat/catalog";
|
|
8
|
-
import { Console, Effect, FileSystem, Option } from "effect";
|
|
8
|
+
import { Console, Data, Effect, FileSystem, Option } from "effect";
|
|
9
9
|
import { NodeRuntime, NodeServices } from "@effect/platform-node";
|
|
10
10
|
import { Argument, Command, Flag } from "effect/cli";
|
|
11
11
|
// src/main.ts
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
|
|
12
|
+
var UnreadableFile = class extends Data.TaggedError("UnreadableFile") {};
|
|
13
|
+
const messageOf = (error) => error instanceof Error ? error.message : String(error);
|
|
14
|
+
const readText = Effect.fn("readText")(function* (file) {
|
|
15
|
+
return yield* (yield* FileSystem.FileSystem).readFileString(file).pipe(Effect.mapError((error) => new UnreadableFile({
|
|
16
|
+
file,
|
|
17
|
+
reason: `the file cannot be read: ${error.message}`
|
|
18
|
+
})));
|
|
19
|
+
});
|
|
17
20
|
const readCatalog = Effect.fn("readCatalog")(function* (file) {
|
|
18
|
-
const text = yield* (
|
|
21
|
+
const text = yield* readText(file);
|
|
19
22
|
return {
|
|
20
23
|
text,
|
|
21
|
-
document:
|
|
24
|
+
document: yield* Effect.try({
|
|
25
|
+
try: () => parseJson(text),
|
|
26
|
+
catch: (error) => new UnreadableFile({
|
|
27
|
+
file,
|
|
28
|
+
reason: `the file is not JSON: ${messageOf(error)}`
|
|
29
|
+
})
|
|
30
|
+
})
|
|
22
31
|
};
|
|
23
32
|
});
|
|
33
|
+
const reportUnreadable = (error) => Effect.andThen(Console.error(`${error.file}: error: ${error.reason}`), fail);
|
|
24
34
|
const fail = Effect.sync(() => {
|
|
25
35
|
process.exitCode = 1;
|
|
26
36
|
});
|
|
27
37
|
const files = Argument.String("catalog").pipe(Argument.withDescription("A catalog file, such as acidcat.catalog.json"), Argument.variadic({ min: 1 }));
|
|
38
|
+
const output = Flag.Literals("output", ["human", "json"]).pipe(Flag.withDescription("human: text for a person. json: one JSON document on standard output, for a script or an agent"), Flag.withDefault("human"));
|
|
39
|
+
const printJson = (value) => Effect.sync(() => process.stdout.write(`${JSON.stringify(value)}\n`));
|
|
28
40
|
const checkCommand = Command.make("check", {
|
|
29
41
|
files,
|
|
30
|
-
strict: Flag.Boolean("strict").pipe(Flag.withDescription("Fail on warnings too"), Flag.withDefault(false))
|
|
31
|
-
|
|
42
|
+
strict: Flag.Boolean("strict").pipe(Flag.withDescription("Fail on warnings too"), Flag.withDefault(false)),
|
|
43
|
+
output
|
|
44
|
+
}, Effect.fn(function* ({ files, strict, output }) {
|
|
32
45
|
let failed = false;
|
|
46
|
+
const reports = [];
|
|
33
47
|
for (const file of files) {
|
|
34
|
-
const { text, document }
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
48
|
+
const report = yield* readCatalog(file).pipe(Effect.map(({ text, document }) => check(document, text)), Effect.catchTag("UnreadableFile", (error) => Effect.succeed({
|
|
49
|
+
errors: [error.reason],
|
|
50
|
+
warnings: []
|
|
51
|
+
})));
|
|
52
|
+
reports.push({
|
|
53
|
+
file,
|
|
54
|
+
...report
|
|
55
|
+
});
|
|
38
56
|
failed ||= report.errors.length > 0 || strict && report.warnings.length > 0;
|
|
39
57
|
}
|
|
58
|
+
if (output === "json") {
|
|
59
|
+
yield* printJson({
|
|
60
|
+
conforms: !failed,
|
|
61
|
+
catalogs: reports
|
|
62
|
+
});
|
|
63
|
+
if (failed) return yield* fail;
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
for (const { file, errors, warnings } of reports) {
|
|
67
|
+
for (const error of errors) yield* Console.error(`${file}: error: ${error}`);
|
|
68
|
+
for (const warning of warnings) yield* Console.error(`${file}: warning: ${warning}`);
|
|
69
|
+
}
|
|
40
70
|
if (failed) return yield* fail;
|
|
41
71
|
yield* Console.log(files.length === 1 ? "The catalog conforms." : "Every catalog conforms.");
|
|
42
72
|
})).pipe(Command.withDescription("Check that catalogs conform to the specification."));
|
|
@@ -51,7 +81,7 @@ const formatCommand = Command.make("format", {
|
|
|
51
81
|
if (write) yield* fs.writeFileString(file, text);
|
|
52
82
|
else yield* Effect.sync(() => process.stdout.write(text));
|
|
53
83
|
}
|
|
54
|
-
})).pipe(Command.withDescription("Write catalogs in canonical form."));
|
|
84
|
+
}, Effect.catchTag("UnreadableFile", reportUnreadable))).pipe(Command.withDescription("Write catalogs in canonical form."));
|
|
55
85
|
const viewCommand = Command.make("view", {
|
|
56
86
|
file: Argument.String("catalog").pipe(Argument.withDescription("A catalog file")),
|
|
57
87
|
target: Argument.String("target").pipe(Argument.withDescription("The name of a target in the catalog"))
|
|
@@ -66,7 +96,7 @@ const viewCommand = Command.make("view", {
|
|
|
66
96
|
return yield* fail;
|
|
67
97
|
}
|
|
68
98
|
yield* Effect.sync(() => process.stdout.write(canonicalText(viewOf(catalog, target))));
|
|
69
|
-
})).pipe(Command.withDescription("Print the view of one target."));
|
|
99
|
+
}, Effect.catchTag("UnreadableFile", reportUnreadable))).pipe(Command.withDescription("Print the view of one target."));
|
|
70
100
|
const url = (name, description) => Flag.String(name).pipe(Flag.withDescription(description), Flag.optional);
|
|
71
101
|
const conformCommand = Command.make("conform", {
|
|
72
102
|
mcp: url("mcp", "The URL of the MCP server"),
|
|
@@ -85,12 +115,12 @@ const conformCommand = Command.make("conform", {
|
|
|
85
115
|
webhookMinTtlMs: Flag.Int("webhook-min-ttl-ms").pipe(Flag.withDescription("The minimum lifetime of a webhook subscription in the deployment, shorter than the deadline. With it, conform tests that a subscription with no renewal ends"), Flag.optional),
|
|
86
116
|
webhookMaxSubscriptions: Flag.Int("webhook-max-subscriptions").pipe(Flag.withDescription("The maximum number of webhook subscriptions of one principal in the deployment. With it, conform tests the limit"), Flag.optional),
|
|
87
117
|
maximumBytes: Flag.Int("max-bytes").pipe(Flag.withDescription("The body limit of the remote bindings"), Flag.withDefault(1048576)),
|
|
88
|
-
deadline: Flag.Int("deadline").pipe(Flag.withDescription("The time, in milliseconds, that each check has to settle. A check that does not settle in this time fails"), Flag.withDefault(DEADLINE))
|
|
118
|
+
deadline: Flag.Int("deadline").pipe(Flag.withDescription("The time, in milliseconds, that each check has to settle. A check that does not settle in this time fails"), Flag.withDefault(DEADLINE)),
|
|
119
|
+
output
|
|
89
120
|
}, Effect.fn(function* (options) {
|
|
90
121
|
const value = (option) => Option.isSome(option) ? option.value : void 0;
|
|
91
122
|
const words = (option) => value(option)?.split(/\s+/).filter((word) => word !== "");
|
|
92
123
|
const optionalInt = (option) => Option.isSome(option) ? option.value : void 0;
|
|
93
|
-
const fs = yield* FileSystem.FileSystem;
|
|
94
124
|
const given = [
|
|
95
125
|
options.webhookPrincipal,
|
|
96
126
|
options.webhookCert,
|
|
@@ -112,8 +142,8 @@ const conformCommand = Command.make("conform", {
|
|
|
112
142
|
}
|
|
113
143
|
const webhook = Option.isSome(options.webhookPrincipal) && Option.isSome(options.webhookCert) && Option.isSome(options.webhookKey) ? {
|
|
114
144
|
principal: options.webhookPrincipal.value,
|
|
115
|
-
cert: yield*
|
|
116
|
-
key: yield*
|
|
145
|
+
cert: yield* readText(options.webhookCert.value),
|
|
146
|
+
key: yield* readText(options.webhookKey.value),
|
|
117
147
|
otherPrincipal: value(options.webhookOtherPrincipal),
|
|
118
148
|
maxTtlMs: optionalInt(options.webhookMaxTtlMs),
|
|
119
149
|
minTtlMs: optionalInt(options.webhookMinTtlMs),
|
|
@@ -138,12 +168,22 @@ const conformCommand = Command.make("conform", {
|
|
|
138
168
|
yield* Console.error("Give at least one binding: --mcp, --mcp-stdio, --http, --cli or --webmcp.");
|
|
139
169
|
return yield* fail;
|
|
140
170
|
}
|
|
141
|
-
for (const result of results) yield* Console.log(`${result.warning === true ? "!" : result.passed ? "✓" : "✗"} ${result.binding}: ${result.name} (${result.rule})${result.detail ? `\n ${result.detail}` : ""}`);
|
|
142
171
|
const failed = results.filter((result) => !result.passed).length;
|
|
143
172
|
const warnings = results.filter((result) => result.warning === true).length;
|
|
173
|
+
if (options.output === "json") {
|
|
174
|
+
yield* printJson({
|
|
175
|
+
passed: results.length - failed,
|
|
176
|
+
failed,
|
|
177
|
+
warnings,
|
|
178
|
+
checks: results
|
|
179
|
+
});
|
|
180
|
+
if (failed > 0) return yield* fail;
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
for (const result of results) yield* Console.log(`${result.warning === true ? "!" : result.passed ? "✓" : "✗"} ${result.binding}: ${result.name} (${result.rule})${result.detail ? `\n ${result.detail}` : ""}`);
|
|
144
184
|
yield* Console.log(`\n${results.length - failed} passed, ${failed} failed${warnings === 0 ? "" : `, ${warnings} with a warning`}.`);
|
|
145
185
|
if (failed > 0) return yield* fail;
|
|
146
|
-
})).pipe(Command.withDescription("Test a running implementation of the conformance fixture through its bindings."));
|
|
186
|
+
}, Effect.catchTag("UnreadableFile", reportUnreadable))).pipe(Command.withDescription("Test a running implementation of the conformance fixture through its bindings."));
|
|
147
187
|
Command.make("acid-cat").pipe(Command.withDescription("Check, format and view AcidCat catalogs, and test implementations."), Command.withSubcommands([
|
|
148
188
|
checkCommand,
|
|
149
189
|
formatCommand,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acid-cat/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "The AcidCat command line: check, format and view catalogs, and test implementations.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"acidcat",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@acid-cat/catalog": "0.
|
|
41
|
-
"@acid-cat/spec-ts": "0.
|
|
40
|
+
"@acid-cat/catalog": "0.12.0",
|
|
41
|
+
"@acid-cat/spec-ts": "0.12.0",
|
|
42
42
|
"@effect/platform-node": "^4.1.3",
|
|
43
43
|
"@effect/platform-node-shared": "^4.1.3",
|
|
44
44
|
"@modelcontextprotocol/client": "2.4.0",
|