@acid-cat/cli 0.19.0 → 0.20.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.
Files changed (42) hide show
  1. package/README.md +32 -2
  2. package/conformance/fixture.acidcat.json +96 -0
  3. package/dist/conform-LH9KgQ9-.js +5045 -0
  4. package/dist/index.d.ts +164 -4
  5. package/dist/index.js +96 -4
  6. package/dist/main.d.ts +1 -2
  7. package/dist/main.js +1090 -7
  8. package/package.json +4 -3
  9. package/dist/catalog.d.ts +0 -12
  10. package/dist/catalog.js +0 -149
  11. package/dist/conform/check.d.ts +0 -47
  12. package/dist/conform/check.js +0 -178
  13. package/dist/conform/cli.d.ts +0 -5
  14. package/dist/conform/cli.js +0 -721
  15. package/dist/conform/http.d.ts +0 -6
  16. package/dist/conform/http.js +0 -297
  17. package/dist/conform/index.d.ts +0 -69
  18. package/dist/conform/index.js +0 -80
  19. package/dist/conform/mcp-stdio.d.ts +0 -7
  20. package/dist/conform/mcp-stdio.js +0 -291
  21. package/dist/conform/mcp.d.ts +0 -47
  22. package/dist/conform/mcp.js +0 -754
  23. package/dist/conform/poll.d.ts +0 -13
  24. package/dist/conform/poll.js +0 -295
  25. package/dist/conform/properties.d.ts +0 -12
  26. package/dist/conform/properties.js +0 -151
  27. package/dist/conform/serve.d.ts +0 -12
  28. package/dist/conform/serve.js +0 -96
  29. package/dist/conform/server-card.d.ts +0 -5
  30. package/dist/conform/server-card.js +0 -142
  31. package/dist/conform/sse.d.ts +0 -9
  32. package/dist/conform/sse.js +0 -53
  33. package/dist/conform/webhook.d.ts +0 -30
  34. package/dist/conform/webhook.js +0 -481
  35. package/dist/conform/webmcp.d.ts +0 -53
  36. package/dist/conform/webmcp.js +0 -232
  37. package/dist/json/catalog.schema.json.js +0 -170
  38. package/dist/json/fixture.acidcat.json.js +0 -396
  39. package/dist/json/package.json.js +0 -3
  40. package/dist/json/server-card.schema.json.js +0 -281
  41. package/dist/json.d.ts +0 -11
  42. package/dist/json.js +0 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acid-cat/cli",
3
- "version": "0.19.0",
3
+ "version": "0.20.0",
4
4
  "description": "The AcidCat command line: check and format catalogs, print the catalog of a target, and test implementations.",
5
5
  "keywords": [
6
6
  "acidcat",
@@ -39,8 +39,8 @@
39
39
  "access": "public"
40
40
  },
41
41
  "dependencies": {
42
- "@acid-cat/catalog": "0.19.0",
43
- "@acid-cat/spec-ts": "0.19.0",
42
+ "@acid-cat/catalog": "0.20.0",
43
+ "@acid-cat/spec-ts": "0.20.0",
44
44
  "@effect/platform-node": "^4.1.3",
45
45
  "@effect/platform-node-shared": "^4.1.3",
46
46
  "@modelcontextprotocol/client": "2.4.0",
@@ -58,6 +58,7 @@
58
58
  "devDependencies": {
59
59
  "@types/node": "26.6.6",
60
60
  "playwright": "1.65.0",
61
+ "tsdown": "0.23.7",
61
62
  "typescript": "7.0.2"
62
63
  }
63
64
  }
package/dist/catalog.d.ts DELETED
@@ -1,12 +0,0 @@
1
- import { bundle, targetCatalog } from "@acid-cat/spec-ts";
2
- import type { CatalogDocument as Catalog } from "@acid-cat/spec-ts";
3
- export { bundle, targetCatalog };
4
- export type { Catalog };
5
- /** The result of a check. An error breaks a rule. A warning breaks a recommendation. */
6
- export interface Report {
7
- readonly errors: readonly string[];
8
- readonly warnings: readonly string[];
9
- }
10
- export declare const isCatalog: (value: unknown) => value is Catalog;
11
- /** Check a catalog. When `text` is given, the file must also be in canonical form. */
12
- export declare function check(document: unknown, text?: string): Report;
package/dist/catalog.js DELETED
@@ -1,149 +0,0 @@
1
- import catalog_schema_default from "./json/catalog.schema.json.js";
2
- import { isObject, isRecordOf, isStringArray } from "./json.js";
3
- import { canonicalText } from "@acid-cat/catalog";
4
- import { REFERENCE, bundle, cliAliases, eventSchemasOf, mcpHeaderErrors, resolveType, schemasOf, targetCatalog, visitObjects } from "@acid-cat/spec-ts";
5
- import { Result, Schema, SchemaIssue, SchemaRepresentation } from "effect";
6
- // src/catalog.ts
7
- const KNOWN_MEMBERS = {
8
- catalog: [
9
- "acidcat",
10
- "title",
11
- "description",
12
- "targets",
13
- "$defs",
14
- "capabilities",
15
- "events"
16
- ],
17
- target: [
18
- "surfaces",
19
- "description",
20
- "options"
21
- ],
22
- capability: [
23
- "description",
24
- "audience",
25
- "input",
26
- "output",
27
- "failures",
28
- "readOnly",
29
- "destructive",
30
- "idempotent",
31
- "state"
32
- ],
33
- event: [
34
- "description",
35
- "audience",
36
- "input",
37
- "payload"
38
- ],
39
- cliOptions: ["aliases", "default"]
40
- };
41
- const optional = (object, key, isMember) => !Object.hasOwn(object, key) || isMember(object[key]);
42
- const isString = (value) => typeof value === "string";
43
- const isBoolean = (value) => typeof value === "boolean";
44
- const isTarget = (value) => isObject(value) && isStringArray(value.surfaces);
45
- const isCapability = (value) => isObject(value) && typeof value.description === "string" && optional(value, "audience", isStringArray) && optional(value, "input", isObject) && optional(value, "output", isObject) && optional(value, "state", isObject) && optional(value, "failures", (failures) => isRecordOf(failures, isObject)) && optional(value, "readOnly", isBoolean) && optional(value, "destructive", isBoolean) && optional(value, "idempotent", isBoolean);
46
- const isEvent = (value) => isObject(value) && typeof value.description === "string" && optional(value, "audience", isStringArray) && optional(value, "input", isObject) && optional(value, "payload", isObject);
47
- const isCatalog = (value) => isObject(value) && typeof value.acidcat === "string" && optional(value, "title", isString) && optional(value, "description", isString) && isRecordOf(value.targets, isTarget) && optional(value, "$defs", (types) => isRecordOf(types, isObject)) && isRecordOf(value.capabilities, isCapability) && optional(value, "events", (events) => isRecordOf(events, isEvent));
48
- const decodeCatalog = (() => {
49
- const { $defs, $schema: _schema, $id: _id, ...root } = catalog_schema_default;
50
- const definitions = $defs;
51
- const schema = SchemaRepresentation.fromJsonSchemaDocument({
52
- dialect: "draft-2020-12",
53
- schema: root,
54
- definitions
55
- }, { patterns: "apply" });
56
- const catalog = Schema.toType(schema).pipe(Schema.refine(isCatalog, { message: "the members do not have the types of a catalog" }));
57
- return Schema.decodeUnknownResult(catalog);
58
- })();
59
- const formatIssues = SchemaIssue.makeFormatterStandardSchemaV1();
60
- /** Check a catalog. When `text` is given, the file must also be in canonical form. */
61
- function check(document, text) {
62
- const decoded = decodeCatalog(document);
63
- if (Result.isFailure(decoded)) return {
64
- errors: formatIssues(decoded.failure.issue).issues.map((issue) => `${(issue.path ?? []).map((key) => `[${JSON.stringify(key)}]`).join("") || "the catalog"}: ${issue.message}`),
65
- warnings: []
66
- };
67
- const catalog = decoded.success;
68
- const errors = ruleErrors(catalog);
69
- const warnings = [...unknownMembers(catalog), ...errors.length === 0 ? schemaWarnings(catalog) : []];
70
- if (text !== void 0 && text !== canonicalText(catalog)) warnings.push("the file is not in canonical form: run `acid-cat format --write`");
71
- return {
72
- errors,
73
- warnings
74
- };
75
- }
76
- function ruleErrors(catalog) {
77
- const errors = [];
78
- const types = catalog.$defs ?? {};
79
- for (const [name, type] of Object.entries(types)) errors.push(...referenceErrors(type, types).map((error) => `type ${name} ${error}`));
80
- const entries = [...Object.entries(catalog.capabilities).map(([id, capability]) => ({
81
- id,
82
- entry: capability,
83
- schemas: schemasOf(capability)
84
- })), ...Object.entries(catalog.events ?? {}).map(([id, event]) => ({
85
- id,
86
- entry: event,
87
- schemas: eventSchemasOf(event)
88
- }))];
89
- for (const id of Object.keys(catalog.events ?? {})) if (Object.hasOwn(catalog.capabilities, id)) errors.push(`${id}: the id is both a capability and an event`);
90
- for (const { id, entry, schemas } of entries) {
91
- for (const target of entry.audience ?? []) if (!Object.hasOwn(catalog.targets, target)) errors.push(`${id}: the audience names ${target}, which is not a target`);
92
- for (const [member, schema] of schemas) {
93
- const references = referenceErrors(schema, types);
94
- errors.push(...references.map((error) => `${id} ${member} ${error}`));
95
- if ((member === "input" || member === "payload") && references.length === 0 && resolveType(schema, types).type !== "object") errors.push(`${id}: the ${member} is not an object`);
96
- if (member === "input" && references.length === 0) errors.push(...mcpHeaderErrors(bundle(schema, types)).map((error) => `${id} input: ${error}`));
97
- }
98
- }
99
- for (const target of Object.keys(catalog.targets)) errors.push(...cliAliases(catalog, target).errors);
100
- return errors;
101
- }
102
- function catalogSchemas(catalog) {
103
- return [...Object.entries(catalog.capabilities).flatMap(([id, capability]) => schemasOf(capability).map(([member, schema]) => [
104
- id,
105
- member,
106
- schema
107
- ])), ...Object.entries(catalog.events ?? {}).flatMap(([id, event]) => eventSchemasOf(event).map(([member, schema]) => [
108
- id,
109
- member,
110
- schema
111
- ]))];
112
- }
113
- function unknownMembers(catalog) {
114
- const unknown = (where, value, known) => Object.keys(value).filter((key) => !known.includes(key) && !key.startsWith("x-")).map((key) => `${where}: unknown member ${key}; give extensions an x- prefix`);
115
- return [
116
- ...unknown("the catalog", catalog, KNOWN_MEMBERS.catalog),
117
- ...Object.entries(catalog.targets).flatMap(([name, target]) => [...unknown(`target ${name}`, target, KNOWN_MEMBERS.target), ...isObject(target.options) && isObject(target.options.cli) ? unknown(`target ${name} options.cli`, target.options.cli, KNOWN_MEMBERS.cliOptions) : []]),
118
- ...Object.entries(catalog.capabilities).flatMap(([id, capability]) => unknown(id, capability, KNOWN_MEMBERS.capability)),
119
- ...Object.entries(catalog.events ?? {}).flatMap(([id, event]) => unknown(id, event, KNOWN_MEMBERS.event))
120
- ];
121
- }
122
- function schemaWarnings(catalog) {
123
- const definitions = catalog.$defs ?? {};
124
- const warnings = [];
125
- for (const [id, member, schema] of catalogSchemas(catalog)) try {
126
- SchemaRepresentation.fromJsonSchemaMultiDocument({
127
- dialect: "draft-2020-12",
128
- schemas: [schema],
129
- definitions
130
- }, { patterns: "ignore" });
131
- } catch (cause) {
132
- warnings.push(`${id} ${member}: cannot check this schema: ${cause instanceof Error ? cause.message : String(cause)}`);
133
- }
134
- return warnings;
135
- }
136
- function referenceErrors(schema, types) {
137
- const errors = [];
138
- visitObjects(schema, (node) => {
139
- if (Object.hasOwn(node, "$defs")) errors.push("has its own $defs; put shared types in the catalog's $defs");
140
- if (node.$ref === void 0) return;
141
- const name = typeof node.$ref === "string" ? REFERENCE.exec(node.$ref)?.[1] : void 0;
142
- if (name === void 0 || !Object.hasOwn(types, name)) {
143
- const reference = typeof node.$ref === "string" ? node.$ref : JSON.stringify(node.$ref);
144
- errors.push(`references ${reference}, which is not a type`);
145
- }
146
- });
147
- return errors;
148
- }
149
- export { bundle, check, isCatalog, targetCatalog };
@@ -1,47 +0,0 @@
1
- import type { CatalogDocument, Occurrence, Outcome } from "@acid-cat/spec-ts";
2
- export interface Check {
3
- readonly surface: string;
4
- readonly name: string;
5
- /** The part of the specification that the check tests, for example `spec/surfaces/mcp.md#tools`. */
6
- readonly rule: string;
7
- readonly passed: boolean;
8
- /** `true` when the check tests a recommendation (SHOULD) that the implementation does not follow. The check still passes. */
9
- readonly warning?: boolean | undefined;
10
- readonly detail?: string | undefined;
11
- }
12
- /** The conformance fixture: the catalog that each implementation serves. */
13
- export declare const fixture: CatalogDocument;
14
- export declare const isOutcome: (value: unknown) => value is Outcome<unknown, unknown>;
15
- export declare const idsOf: (target: string) => string[];
16
- export declare const eventIdsOf: (target: string) => string[];
17
- export declare function expectOccurrence(value: unknown, id: string): Occurrence;
18
- export declare const DEADLINE = 30000;
19
- /** A signal that aborts when `signal` aborts, or when `stop`, the signal that stops conform, aborts. */
20
- export declare const orStop: (signal: AbortSignal, stop: AbortSignal | undefined) => AbortSignal;
21
- type Body = (signal: AbortSignal) => Promise<void> | void;
22
- export type Define = (name: string, rule: string, body: Body) => void;
23
- export declare class Checks {
24
- #private;
25
- readonly results: Check[];
26
- readonly surface: string;
27
- readonly deadline: number;
28
- /** When it aborts, each check that runs stops as at its deadline, and no other check starts. */
29
- readonly signal: AbortSignal | undefined;
30
- constructor(surface: string, deadline: number, signal?: AbortSignal);
31
- run(name: string, rule: string, body: Body): Promise<void>;
32
- /**
33
- * Run a check of several runs, such as the runs of a property. Each run has the deadline, so the number of runs that
34
- * fit in the check does not depend on the speed of the computer.
35
- */
36
- runEach(name: string, rule: string, body: (each: (run: Body) => Promise<void>) => Promise<void>): Promise<void>;
37
- concurrently(define: (check: Define) => void): Promise<void>;
38
- should(name: string, rule: string, body: Body): Promise<void>;
39
- }
40
- export declare function until<T, Done extends T>(what: string, read: () => Promise<T>, done: (value: T) => value is Done, signal: AbortSignal): Promise<Done>;
41
- export declare function until<T>(what: string, read: () => Promise<T>, done: (value: T) => boolean, signal: AbortSignal): Promise<T>;
42
- export declare function abortable<T>(promise: Promise<T>, signal: AbortSignal): Promise<T>;
43
- export declare function expect(condition: unknown, message: string): asserts condition;
44
- export declare function expectEqual(actual: unknown, expected: unknown, what: string): void;
45
- export declare const sorted: (values: Iterable<string>) => string[];
46
- export declare const FORBIDDEN_ORIGIN = "https://not-allowed.acid-cat.invalid";
47
- export {};
@@ -1,178 +0,0 @@
1
- import fixture_acidcat_default from "../json/fixture.acidcat.json.js";
2
- import { isObject } from "../json.js";
3
- import { CALL_FAILURE_KINDS, isOccurrence, targetCatalog } from "@acid-cat/spec-ts";
4
- import { Schema, SchemaRepresentation } from "effect";
5
- import { availableParallelism } from "node:os";
6
- import { setTimeout as setTimeout$1 } from "node:timers/promises";
7
- // src/conform/check.ts
8
- /** The conformance fixture: the catalog that each implementation serves. */
9
- const fixture = fixture_acidcat_default;
10
- const isOutcome = (value) => {
11
- if (!isObject(value)) return false;
12
- if (value.ok === true) return "value" in value;
13
- if (value.ok === false) return "error" in value;
14
- return !("ok" in value) && CALL_FAILURE_KINDS.some((kind) => kind === value.kind) && typeof value.message === "string";
15
- };
16
- const idsOf = (target) => Object.keys(targetCatalog(fixture, target).capabilities).sort();
17
- const eventIdsOf = (target) => Object.keys(targetCatalog(fixture, target).events ?? {}).sort();
18
- const payloadChecks = /* @__PURE__ */ new Map();
19
- function agreesWithPayload(id, data) {
20
- let agrees = payloadChecks.get(id);
21
- if (agrees === void 0) {
22
- const payload = fixture.events?.[id]?.payload;
23
- if (payload === void 0) agrees = (value) => isObject(value) && Object.keys(value).length === 0;
24
- else {
25
- const definitions = fixture.$defs ?? {};
26
- const schema = SchemaRepresentation.fromJsonSchemaDocument({
27
- dialect: "draft-2020-12",
28
- schema: payload,
29
- definitions
30
- }, { patterns: "apply" });
31
- agrees = Schema.is(Schema.toType(schema));
32
- }
33
- payloadChecks.set(id, agrees);
34
- }
35
- return agrees(data);
36
- }
37
- function expectOccurrence(value, id) {
38
- expect(isOccurrence(value), `expected an occurrence, got ${JSON.stringify(value)}`);
39
- expectEqual(value.name, id, "the name of the occurrence");
40
- expect(agreesWithPayload(id, value.data), `the data of the occurrence must agree with the payload schema of ${id}, got ${JSON.stringify(value.data)}`);
41
- return value;
42
- }
43
- const DEADLINE = 3e4;
44
- /** A signal that aborts when `signal` aborts, or when `stop`, the signal that stops conform, aborts. */
45
- const orStop = (signal, stop) => stop === void 0 ? signal : AbortSignal.any([signal, stop]);
46
- var Checks = class {
47
- results = [];
48
- surface;
49
- deadline;
50
- /** When it aborts, each check that runs stops as at its deadline, and no other check starts. */
51
- signal;
52
- constructor(surface, deadline, signal) {
53
- this.surface = surface;
54
- this.deadline = deadline;
55
- this.signal = signal;
56
- }
57
- async run(name, rule, body) {
58
- this.results.push(this.#result(name, rule, await this.#settle(body)));
59
- }
60
- /**
61
- * Run a check of several runs, such as the runs of a property. Each run has the deadline, so the number of runs that
62
- * fit in the check does not depend on the speed of the computer.
63
- */
64
- async runEach(name, rule, body) {
65
- let late = false;
66
- const each = async (run) => {
67
- const failure = await this.#settle(run);
68
- if (failure === void 0) return;
69
- late ||= failure.startsWith("did not settle");
70
- throw new Error(failure);
71
- };
72
- let failure;
73
- try {
74
- await body(each);
75
- } catch (error) {
76
- const message = error instanceof Error ? error.message : String(error);
77
- failure = late && !message.startsWith("did not settle") ? `did not settle within ${this.deadline} ms: ${message}` : message;
78
- }
79
- this.results.push(this.#result(name, rule, failure));
80
- }
81
- async concurrently(define) {
82
- const defined = [];
83
- define((name, rule, body) => defined.push({
84
- name,
85
- rule,
86
- body
87
- }));
88
- const queue = defined.entries();
89
- const settled = [];
90
- const worker = async () => {
91
- for (const [index, { name, rule, body }] of queue) settled.push([index, this.#result(name, rule, await this.#settle(body))]);
92
- };
93
- await Promise.all(Array.from({ length: availableParallelism() }, worker));
94
- this.results.push(...settled.sort(([a], [b]) => a - b).map(([, check]) => check));
95
- }
96
- #result(name, rule, failure) {
97
- return failure === void 0 ? {
98
- surface: this.surface,
99
- name,
100
- rule,
101
- passed: true
102
- } : {
103
- surface: this.surface,
104
- name,
105
- rule,
106
- passed: false,
107
- detail: failure
108
- };
109
- }
110
- async should(name, rule, body) {
111
- const failure = await this.#settle(body);
112
- this.results.push(failure === void 0 ? {
113
- surface: this.surface,
114
- name,
115
- rule,
116
- passed: true
117
- } : {
118
- surface: this.surface,
119
- name,
120
- rule,
121
- passed: true,
122
- warning: true,
123
- detail: failure
124
- });
125
- }
126
- #stopped() {
127
- return this.signal?.aborted === true;
128
- }
129
- async #settle(body) {
130
- if (this.#stopped()) return "conform stopped before the check";
131
- const controller = new AbortController();
132
- const stop = () => controller.abort();
133
- const timer = setTimeout(stop, this.deadline);
134
- this.signal?.addEventListener("abort", stop, { once: true });
135
- try {
136
- await body(controller.signal);
137
- return;
138
- } catch (error) {
139
- const message = error instanceof Error ? error.message : String(error);
140
- if (this.#stopped()) return `conform stopped during the check: ${message}`;
141
- return controller.signal.aborted ? `did not settle within ${this.deadline} ms: ${message}` : message;
142
- } finally {
143
- clearTimeout(timer);
144
- this.signal?.removeEventListener("abort", stop);
145
- controller.abort();
146
- }
147
- }
148
- };
149
- async function until(what, read, done, signal) {
150
- let last;
151
- try {
152
- for (;;) {
153
- last = await read();
154
- if (done(last)) return last;
155
- await setTimeout$1(10, void 0, { signal });
156
- }
157
- } catch (error) {
158
- throw signal.aborted ? /* @__PURE__ */ new Error(`waiting until ${what}; the last value was ${JSON.stringify(last)}`) : error;
159
- }
160
- }
161
- function abortable(promise, signal) {
162
- const aborted = new Promise((_, reject) => {
163
- signal.throwIfAborted();
164
- signal.addEventListener("abort", () => reject(signal.reason), { once: true });
165
- });
166
- return Promise.race([promise, aborted]);
167
- }
168
- function expect(condition, message) {
169
- if (!condition) throw new Error(message);
170
- }
171
- function expectEqual(actual, expected, what) {
172
- const a = JSON.stringify(actual);
173
- const b = JSON.stringify(expected);
174
- if (a !== b) throw new Error(`${what}: expected ${b}, got ${a}`);
175
- }
176
- const sorted = (values) => [...values].sort();
177
- const FORBIDDEN_ORIGIN = "https://not-allowed.acid-cat.invalid";
178
- export { Checks, DEADLINE, FORBIDDEN_ORIGIN, abortable, eventIdsOf, expect, expectEqual, expectOccurrence, fixture, idsOf, isOutcome, orStop, sorted, until };
@@ -1,5 +0,0 @@
1
- import { Checks } from "./check.js";
2
- export declare function checkCli(command: readonly string[], options: {
3
- readonly deadline: number;
4
- readonly signal?: AbortSignal | undefined;
5
- }): Promise<Checks>;