loremfile 0.2.0 → 0.2.2

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 CHANGED
@@ -26,7 +26,9 @@ correctly by default: every file is verified, and a file that fails is not writt
26
26
 
27
27
  Every command takes `--json` for scripts, `--quiet`, and `--catalog-version X.Y.Z` to
28
28
  refuse to run if loremfile.dev has moved on. `get` also takes `--force` (overwrite) and
29
- `--dry-run` (what it would fetch, and how many bytes).
29
+ `--dry-run` (what it would fetch, and how many bytes). `get`, `list` and `verify` leave out the
30
+ `sample.{format}` aliases, which repeat another file's bytes, unless you pass `--include-aliases`;
31
+ a path you name is always fetched.
30
32
 
31
33
  Exit codes: `0` fine, `1` a file failed verification or is missing, `2` the request was
32
34
  wrong, `3` loremfile.dev could not be read.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loremfile",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Download CC0 sample files from loremfile.dev and verify every byte",
5
5
  "keywords": ["fixtures", "test-data", "sample-files", "cc0", "download", "mcp"],
6
6
  "homepage": "https://loremfile.dev",
package/src/api.js CHANGED
@@ -209,8 +209,23 @@ export function active(document) {
209
209
  return (document.fixtures ?? []).filter((entry) => (entry.status ?? "active") === "active");
210
210
  }
211
211
 
212
- /** The entries a request names, or `Refused` naming what does not exist. */
213
- export function select(entries, { paths = [], formats = [] } = {}) {
212
+ /**
213
+ * A `sample.{format}` alias is a second URL for bytes that already have one. Its manifest entry
214
+ * is the only place that says so, and the field that does is `generator`; its original is
215
+ * `generator_params.of`. (`aliasOf`, which 1.15.0 carried until 1.15.1, matches nothing.)
216
+ */
217
+ export const ALIAS_GENERATOR = "alias.copy";
218
+
219
+ export function isAlias(entry) {
220
+ return entry.generator === ALIAS_GENERATOR;
221
+ }
222
+
223
+ /**
224
+ * The entries a request names, or `Refused` naming what does not exist. A format selects its
225
+ * files, not the aliases that repeat them, unless `includeAliases`; a path that is named is
226
+ * always honoured, alias or not.
227
+ */
228
+ export function select(entries, { paths = [], formats = [], includeAliases = false } = {}) {
214
229
  const wantedPaths = new Set(paths);
215
230
  const wantedFormats = new Set(formats);
216
231
  if (wantedPaths.size === 0 && wantedFormats.size === 0) {
@@ -227,7 +242,11 @@ export function select(entries, { paths = [], formats = [] } = {}) {
227
242
  throw new Refused(`no such format: ${unknownFormats.join(", ")}`);
228
243
  }
229
244
  return entries
230
- .filter((entry) => wantedPaths.has(entry.path) || wantedFormats.has(entry.format))
245
+ .filter(
246
+ (entry) =>
247
+ wantedPaths.has(entry.path) ||
248
+ (wantedFormats.has(entry.format) && (includeAliases || !isAlias(entry))),
249
+ )
231
250
  .sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
232
251
  }
233
252
 
package/src/cli.js CHANGED
@@ -33,6 +33,10 @@ const SHARED = {
33
33
  };
34
34
  const FORMAT = { type: "string", multiple: true, value: "FMT" };
35
35
  const DEST = { type: "string", value: "DIR", help: `Default: ${DEFAULT_DEST}` };
36
+ const ALIASES = {
37
+ type: "boolean",
38
+ help: "Also the sample.{format} copies, which repeat another file's bytes.",
39
+ };
36
40
 
37
41
  /** Every option each command accepts. Exported so a test can read them off, not the source. */
38
42
  export const COMMANDS = {
@@ -44,6 +48,7 @@ export const COMMANDS = {
44
48
  dest: DEST,
45
49
  force: { type: "boolean", help: "Overwrite files already there." },
46
50
  "dry-run": { type: "boolean", help: "List what would be fetched." },
51
+ "include-aliases": ALIASES,
47
52
  ...SHARED,
48
53
  },
49
54
  },
@@ -54,6 +59,7 @@ export const COMMANDS = {
54
59
  format: { ...FORMAT, help: "Only this format. Repeatable." },
55
60
  tag: { type: "string", multiple: true, value: "TAG", help: "Only this tag. Repeatable." },
56
61
  "max-bytes": { type: "string", value: "N", help: "Only files of at most N bytes." },
62
+ "include-aliases": ALIASES,
57
63
  ...SHARED,
58
64
  },
59
65
  },
@@ -63,6 +69,7 @@ export const COMMANDS = {
63
69
  options: {
64
70
  format: { ...FORMAT, help: "Every published file of this format. Repeatable." },
65
71
  dest: DEST,
72
+ "include-aliases": ALIASES,
66
73
  ...SHARED,
67
74
  },
68
75
  },
@@ -138,6 +145,7 @@ function parse(argv) {
138
145
  dest: values.dest ?? DEFAULT_DEST,
139
146
  force: Boolean(values.force),
140
147
  dryRun: Boolean(values["dry-run"]),
148
+ includeAliases: Boolean(values["include-aliases"]),
141
149
  json: Boolean(values.json),
142
150
  quiet: Boolean(values.quiet),
143
151
  catalogVersion: values["catalog-version"],
@@ -173,7 +181,11 @@ function emit(args, summary, results, io) {
173
181
 
174
182
  async function runGet(args, io) {
175
183
  const published = api.active(await api.manifest({ catalogVersion: args.catalogVersion }));
176
- const entries = api.select(published, { paths: args.paths, formats: args.format });
184
+ const entries = api.select(published, {
185
+ paths: args.paths,
186
+ formats: args.format,
187
+ includeAliases: args.includeAliases,
188
+ });
177
189
  if (args.dryRun) {
178
190
  const total = entries.reduce((sum, entry) => sum + entry.bytes, 0);
179
191
  emit(
@@ -197,6 +209,9 @@ async function runGet(args, io) {
197
209
 
198
210
  async function runList(args, io) {
199
211
  let entries = api.active(await api.manifest({ catalogVersion: args.catalogVersion }));
212
+ if (!args.includeAliases) {
213
+ entries = entries.filter((e) => !api.isAlias(e));
214
+ }
200
215
  if (args.format.length > 0) {
201
216
  entries = entries.filter((e) => args.format.includes(e.format));
202
217
  }
@@ -216,9 +231,14 @@ async function runList(args, io) {
216
231
  async function runVerify(args, io) {
217
232
  let entries = api.active(await api.manifest({ catalogVersion: args.catalogVersion }));
218
233
  if (args.paths.length > 0 || args.format.length > 0) {
219
- entries = api.select(entries, { paths: args.paths, formats: args.format });
234
+ entries = api.select(entries, {
235
+ paths: args.paths,
236
+ formats: args.format,
237
+ includeAliases: args.includeAliases,
238
+ });
220
239
  } else {
221
- // Everything the destination actually holds, so `verify` alone checks a directory.
240
+ // Everything the destination actually holds, so `verify` alone checks a directory,
241
+ // aliases included: a copy that is on disk was put there on purpose.
222
242
  const held = [];
223
243
  for (const entry of entries) {
224
244
  if (await api.held(entry, args.dest)) {
package/src/mcp.js CHANGED
@@ -43,164 +43,12 @@ const INSTRUCTIONS =
43
43
  "list_fixtures to find one, describe_fixture for its size, hash and measured properties, " +
44
44
  "and verify_file to check a copy on disk. The tools return URLs, never file contents.";
45
45
 
46
- const READ_ONLY = {
47
- readOnlyHint: true,
48
- destructiveHint: false,
49
- idempotentHint: true,
50
- // One host and one published list, not an open world.
51
- openWorldHint: false,
52
- };
53
-
54
- const STRINGS = {
55
- anyOf: [{ type: "string" }, { type: "array", items: { type: "string" } }],
56
- };
57
- const NULLABLE_STRING = { type: ["string", "null"] };
58
- const NULLABLE_INTEGER = { type: ["integer", "null"] };
59
-
60
- const LISTED = {
61
- type: "object",
62
- properties: {
63
- path: { type: "string" },
64
- url: { type: "string" },
65
- format: { type: "string" },
66
- mime: { type: "string" },
67
- bytes: { type: "integer" },
68
- tags: { type: "array", items: { type: "string" } },
69
- description: { type: "string" },
70
- },
71
- required: ["path", "url", "format", "mime", "bytes", "tags", "description"],
72
- };
73
-
74
- /** The tool surface. client-js/README.md documents it, and a test holds the two together. */
75
- export const TOOLS = [
76
- {
77
- name: "list_fixtures",
78
- title: "List loremfile.dev fixtures",
79
- description:
80
- "One page of the published sample files, filtered by format, tag and size. Each comes " +
81
- "with its URL and a description of what it is for. `total` counts every match and " +
82
- "`next_offset` fetches the next page; it is null on the last.",
83
- inputSchema: {
84
- type: "object",
85
- properties: {
86
- format: { ...STRINGS, description: 'Formats to include, any of, e.g. ["pdf", "png"].' },
87
- tag: { ...STRINGS, description: 'Tags to include, any of, e.g. ["encrypted"].' },
88
- max_bytes: { type: "integer", minimum: 0, description: "Only files of at most this size." },
89
- limit: {
90
- type: "integer",
91
- minimum: 1,
92
- maximum: MAX_LIMIT,
93
- default: DEFAULT_LIMIT,
94
- description: `Fixtures per page, ${DEFAULT_LIMIT} unless set, at most ${MAX_LIMIT}.`,
95
- },
96
- offset: { type: "integer", minimum: 0, default: 0, description: "Matches to skip." },
97
- },
98
- additionalProperties: false,
99
- },
100
- outputSchema: {
101
- type: "object",
102
- properties: {
103
- catalog_version: { type: "string" },
104
- total: { type: "integer" },
105
- offset: { type: "integer" },
106
- limit: { type: "integer" },
107
- count: { type: "integer" },
108
- next_offset: NULLABLE_INTEGER,
109
- fixtures: { type: "array", items: LISTED },
110
- },
111
- required: ["catalog_version", "total", "offset", "limit", "count", "next_offset", "fixtures"],
112
- },
113
- annotations: READ_ONLY,
114
- },
115
- {
116
- name: "describe_fixture",
117
- title: "Describe one loremfile.dev fixture",
118
- description:
119
- "The published manifest entry for one fixture: its URL, MIME type, size, SHA-256, tags, " +
120
- "description and measured properties. Metadata only; fetch the URL for the file.",
121
- inputSchema: {
122
- type: "object",
123
- properties: {
124
- path: { type: "string", description: 'A fixture path, e.g. "pdf/minimal.pdf".' },
125
- },
126
- required: ["path"],
127
- additionalProperties: false,
128
- },
129
- outputSchema: {
130
- type: "object",
131
- properties: {
132
- catalog_version: { type: "string" },
133
- path: { type: "string" },
134
- url: { type: "string" },
135
- format: { type: "string" },
136
- mime: { type: "string" },
137
- bytes: { type: "integer" },
138
- sha256: { type: "string" },
139
- size_class: NULLABLE_STRING,
140
- tags: { type: "array", items: { type: "string" } },
141
- description: { type: "string" },
142
- props: { type: ["object", "null"] },
143
- added_in: NULLABLE_STRING,
144
- },
145
- required: [
146
- "catalog_version",
147
- "path",
148
- "url",
149
- "format",
150
- "mime",
151
- "bytes",
152
- "sha256",
153
- "size_class",
154
- "tags",
155
- "description",
156
- "props",
157
- "added_in",
158
- ],
159
- },
160
- annotations: READ_ONLY,
161
- },
162
- {
163
- name: "verify_file",
164
- title: "Verify a local copy of a loremfile.dev fixture",
165
- description:
166
- "Hash a file on this machine and compare it with the published SHA-256 and size of a " +
167
- "fixture. `status` is ok, changed or missing. The file is read only to hash it.",
168
- inputSchema: {
169
- type: "object",
170
- properties: {
171
- path: { type: "string", description: 'The fixture path, e.g. "pdf/minimal.pdf".' },
172
- file: {
173
- type: "string",
174
- description: "The local file: absolute, or relative to where the server was started.",
175
- },
176
- },
177
- required: ["path", "file"],
178
- additionalProperties: false,
179
- },
180
- outputSchema: {
181
- type: "object",
182
- properties: {
183
- path: { type: "string" },
184
- file: { type: "string" },
185
- status: { type: "string", enum: ["ok", "changed", "missing"] },
186
- expected_sha256: { type: "string" },
187
- actual_sha256: NULLABLE_STRING,
188
- expected_bytes: { type: "integer" },
189
- actual_bytes: NULLABLE_INTEGER,
190
- },
191
- required: [
192
- "path",
193
- "file",
194
- "status",
195
- "expected_sha256",
196
- "actual_sha256",
197
- "expected_bytes",
198
- "actual_bytes",
199
- ],
200
- },
201
- annotations: READ_ONLY,
202
- },
203
- ];
46
+ /**
47
+ * The tool surface, shared byte for byte with the Python client (tools.json in both trees;
48
+ * a test at the repository root holds the two copies together, and client-js/README.md
49
+ * documents it). Read-only tools, URLs and metadata only.
50
+ */
51
+ export const TOOLS = JSON.parse(readFileSync(new URL("./tools.json", import.meta.url), "utf8"));
204
52
 
205
53
  /** A failure the model can act on: a tool result with `isError`, not a protocol error. */
206
54
  export class ToolError extends Error {}
@@ -282,8 +130,11 @@ async function listFixtures(document, args) {
282
130
  const limit = integer(args.limit, "limit", { min: 1, max: MAX_LIMIT, fallback: DEFAULT_LIMIT });
283
131
  const offset = integer(args.offset, "offset", { min: 0, fallback: 0 });
284
132
  // The same filters as `loremfile list`: any of the formats, any of the tags, all three kinds.
133
+ // The sample.{format} aliases repeat another file's bytes and stay out; describe_fixture and
134
+ // verify_file still take one by path.
285
135
  const matches = api
286
136
  .active(document)
137
+ .filter((e) => !api.isAlias(e))
287
138
  .filter((e) => formats.length === 0 || formats.includes(e.format))
288
139
  .filter((e) => tags.length === 0 || (e.tags ?? []).some((tag) => tags.includes(tag)))
289
140
  .filter((e) => maxBytes === null || e.bytes <= maxBytes)
package/src/tools.json ADDED
@@ -0,0 +1,307 @@
1
+ [
2
+ {
3
+ "name": "list_fixtures",
4
+ "title": "List loremfile.dev fixtures",
5
+ "description": "One page of the published sample files, filtered by format, tag and size. Reads the published manifest over the network. Each comes with its URL and a description of what it is for. `total` counts every match and `next_offset` fetches the next page; it is null on the last.",
6
+ "inputSchema": {
7
+ "type": "object",
8
+ "properties": {
9
+ "format": {
10
+ "anyOf": [
11
+ {
12
+ "type": "string"
13
+ },
14
+ {
15
+ "type": "array",
16
+ "items": {
17
+ "type": "string"
18
+ }
19
+ }
20
+ ],
21
+ "description": "Formats to include, any of, e.g. [\"pdf\", \"png\"]."
22
+ },
23
+ "tag": {
24
+ "anyOf": [
25
+ {
26
+ "type": "string"
27
+ },
28
+ {
29
+ "type": "array",
30
+ "items": {
31
+ "type": "string"
32
+ }
33
+ }
34
+ ],
35
+ "description": "Tags to include, any of, e.g. [\"encrypted\"]."
36
+ },
37
+ "max_bytes": {
38
+ "type": "integer",
39
+ "minimum": 0,
40
+ "description": "Only files of at most this size."
41
+ },
42
+ "limit": {
43
+ "type": "integer",
44
+ "minimum": 1,
45
+ "maximum": 250,
46
+ "default": 50,
47
+ "description": "Fixtures per page, 50 unless set, at most 250."
48
+ },
49
+ "offset": {
50
+ "type": "integer",
51
+ "minimum": 0,
52
+ "default": 0,
53
+ "description": "Matches to skip."
54
+ }
55
+ },
56
+ "additionalProperties": false
57
+ },
58
+ "outputSchema": {
59
+ "type": "object",
60
+ "properties": {
61
+ "catalog_version": {
62
+ "type": "string"
63
+ },
64
+ "total": {
65
+ "type": "integer"
66
+ },
67
+ "offset": {
68
+ "type": "integer"
69
+ },
70
+ "limit": {
71
+ "type": "integer"
72
+ },
73
+ "count": {
74
+ "type": "integer"
75
+ },
76
+ "next_offset": {
77
+ "type": [
78
+ "integer",
79
+ "null"
80
+ ]
81
+ },
82
+ "fixtures": {
83
+ "type": "array",
84
+ "items": {
85
+ "type": "object",
86
+ "properties": {
87
+ "path": {
88
+ "type": "string"
89
+ },
90
+ "url": {
91
+ "type": "string"
92
+ },
93
+ "format": {
94
+ "type": "string"
95
+ },
96
+ "mime": {
97
+ "type": "string"
98
+ },
99
+ "bytes": {
100
+ "type": "integer"
101
+ },
102
+ "tags": {
103
+ "type": "array",
104
+ "items": {
105
+ "type": "string"
106
+ }
107
+ },
108
+ "description": {
109
+ "type": "string"
110
+ }
111
+ },
112
+ "required": [
113
+ "path",
114
+ "url",
115
+ "format",
116
+ "mime",
117
+ "bytes",
118
+ "tags",
119
+ "description"
120
+ ]
121
+ }
122
+ }
123
+ },
124
+ "required": [
125
+ "catalog_version",
126
+ "total",
127
+ "offset",
128
+ "limit",
129
+ "count",
130
+ "next_offset",
131
+ "fixtures"
132
+ ]
133
+ },
134
+ "annotations": {
135
+ "readOnlyHint": true,
136
+ "destructiveHint": false,
137
+ "idempotentHint": true,
138
+ "openWorldHint": true
139
+ }
140
+ },
141
+ {
142
+ "name": "describe_fixture",
143
+ "title": "Describe one loremfile.dev fixture",
144
+ "description": "The published manifest entry for one fixture: its URL, MIME type, size, SHA-256, tags, description and measured properties. Reads the published manifest over the network. Metadata only; fetch the URL for the file.",
145
+ "inputSchema": {
146
+ "type": "object",
147
+ "properties": {
148
+ "path": {
149
+ "type": "string",
150
+ "description": "A fixture path, e.g. \"pdf/minimal.pdf\"."
151
+ }
152
+ },
153
+ "required": [
154
+ "path"
155
+ ],
156
+ "additionalProperties": false
157
+ },
158
+ "outputSchema": {
159
+ "type": "object",
160
+ "properties": {
161
+ "catalog_version": {
162
+ "type": "string"
163
+ },
164
+ "path": {
165
+ "type": "string"
166
+ },
167
+ "url": {
168
+ "type": "string"
169
+ },
170
+ "format": {
171
+ "type": "string"
172
+ },
173
+ "mime": {
174
+ "type": "string"
175
+ },
176
+ "bytes": {
177
+ "type": "integer"
178
+ },
179
+ "sha256": {
180
+ "type": "string"
181
+ },
182
+ "size_class": {
183
+ "type": [
184
+ "string",
185
+ "null"
186
+ ]
187
+ },
188
+ "tags": {
189
+ "type": "array",
190
+ "items": {
191
+ "type": "string"
192
+ }
193
+ },
194
+ "description": {
195
+ "type": "string"
196
+ },
197
+ "props": {
198
+ "type": [
199
+ "object",
200
+ "null"
201
+ ]
202
+ },
203
+ "added_in": {
204
+ "type": [
205
+ "string",
206
+ "null"
207
+ ]
208
+ }
209
+ },
210
+ "required": [
211
+ "catalog_version",
212
+ "path",
213
+ "url",
214
+ "format",
215
+ "mime",
216
+ "bytes",
217
+ "sha256",
218
+ "size_class",
219
+ "tags",
220
+ "description",
221
+ "props",
222
+ "added_in"
223
+ ]
224
+ },
225
+ "annotations": {
226
+ "readOnlyHint": true,
227
+ "destructiveHint": false,
228
+ "idempotentHint": true,
229
+ "openWorldHint": true
230
+ }
231
+ },
232
+ {
233
+ "name": "verify_file",
234
+ "title": "Verify a local copy of a loremfile.dev fixture",
235
+ "description": "Hash a file on this machine and compare it with the published SHA-256 and size of a fixture. Reads the published manifest over the network. `status` is ok, changed or missing. The file is read only to hash it.",
236
+ "inputSchema": {
237
+ "type": "object",
238
+ "properties": {
239
+ "path": {
240
+ "type": "string",
241
+ "description": "The fixture path, e.g. \"pdf/minimal.pdf\"."
242
+ },
243
+ "file": {
244
+ "type": "string",
245
+ "description": "The local file: absolute, or relative to where the server was started."
246
+ }
247
+ },
248
+ "required": [
249
+ "path",
250
+ "file"
251
+ ],
252
+ "additionalProperties": false
253
+ },
254
+ "outputSchema": {
255
+ "type": "object",
256
+ "properties": {
257
+ "path": {
258
+ "type": "string"
259
+ },
260
+ "file": {
261
+ "type": "string"
262
+ },
263
+ "status": {
264
+ "type": "string",
265
+ "enum": [
266
+ "ok",
267
+ "changed",
268
+ "missing"
269
+ ]
270
+ },
271
+ "expected_sha256": {
272
+ "type": "string"
273
+ },
274
+ "actual_sha256": {
275
+ "type": [
276
+ "string",
277
+ "null"
278
+ ]
279
+ },
280
+ "expected_bytes": {
281
+ "type": "integer"
282
+ },
283
+ "actual_bytes": {
284
+ "type": [
285
+ "integer",
286
+ "null"
287
+ ]
288
+ }
289
+ },
290
+ "required": [
291
+ "path",
292
+ "file",
293
+ "status",
294
+ "expected_sha256",
295
+ "actual_sha256",
296
+ "expected_bytes",
297
+ "actual_bytes"
298
+ ]
299
+ },
300
+ "annotations": {
301
+ "readOnlyHint": true,
302
+ "destructiveHint": false,
303
+ "idempotentHint": true,
304
+ "openWorldHint": true
305
+ }
306
+ }
307
+ ]