@pluginfinity/engine 0.1.1 → 0.2.1

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/agents.js CHANGED
@@ -1,6 +1,7 @@
1
- import { applyHostBlocks } from "./body.js";
1
+ import { mapHostBlocks } from "./body.js";
2
2
  import { appendSections, mapFrontmatter } from "./frontmatter.js";
3
- import { decodeComponent, frontmatterText, invalid, issue, overlayIssues, unknownTargets } from "./component.js";
3
+ import { decodeComponent, frontmatterText, invalid, issue, lineIssues, overlayIssues, unknownTargets } from "./component.js";
4
+ import { renderTokens } from "./tokens.js";
4
5
  import { AGENT_FIELDS, AgentFrontmatter } from "@pluginfinity/core";
5
6
  import { Effect, FileSystem, Path } from "effect";
6
7
 
@@ -53,34 +54,46 @@ const readAgents = (root, known) => Effect.gen(function* () {
53
54
  /**
54
55
  * Render one agent for a target, or `undefined` when its `targets` block
55
56
  * excludes it: the file at `<agents.dir>/<name><agents.suffix>` with the
56
- * target's frontmatter, degraded fields appended as body sections, and host
57
- * blocks applied. It keeps its source mode.
57
+ * target's frontmatter, host blocks and then body tokens applied, and
58
+ * degraded fields appended as body sections. It keeps its source mode. A
59
+ * token problem is keyed by its file line and names the target.
58
60
  *
59
61
  * @public
60
62
  */
61
- const renderAgent = (target, id, agent, known) => Effect.gen(function* () {
63
+ const renderAgent = (target, id, agent, known, tokens) => Effect.gen(function* () {
62
64
  const fs = yield* FileSystem.FileSystem;
63
65
  const block = agent.frontmatter.targets?.[id];
64
66
  if (block === false) return void 0;
65
- const mapped = mapFrontmatter(target, target.agents.fields, target.agents.hostFields, agent.frontmatter, block ?? {});
67
+ const mapped = mapFrontmatter(target, target.agents.fields, target.agents.hostFields, agent.frontmatter, block ?? {}, tokens.own);
66
68
  const problems = [
67
69
  ...yield* overlayIssues(AgentFrontmatter, AGENT_FIELDS, agent.frontmatter, block ?? {}, id),
68
70
  ...mapped.unresolved.map((field) => issue(field.field, `${id} leaves this field unresolved (${field.note})`)),
69
71
  ...mapped.unknown.map((key) => issue(`targets.${id}.${key}`, `not an agent field or a ${id} agent field`))
70
72
  ];
71
- const body = applyHostBlocks(agent.body, id, known);
73
+ const body = mapHostBlocks(agent.body, id, known);
72
74
  if ("problem" in body) return yield* Effect.fail(invalid(agent.path, [issue(`line ${body.problem.line + agent.bodyOffset}`, body.problem.message)]));
73
- if (problems.length > 0) return yield* Effect.fail(invalid(agent.path, problems, id));
75
+ const rendered = renderTokens(body.text, tokens);
76
+ if ("problems" in rendered) problems.push(...lineIssues(rendered.problems, body.lines, agent.bodyOffset));
77
+ if (problems.length > 0 || !("text" in rendered)) return yield* Effect.fail(invalid(agent.path, problems, id));
74
78
  const { name: _name, description, ...rest } = mapped.fields;
75
79
  const yaml = yield* frontmatterText({
76
80
  name: agent.name,
77
81
  description,
78
82
  ...rest
79
83
  }, agent);
84
+ const source = `agents/${agent.name}.md`;
80
85
  return {
81
- path: `${target.agents.dir}/${agent.name}${target.agents.suffix}`,
82
- content: `---\n${yaml}---\n${appendSections(body.text, mapped.sections)}`,
83
- mode: (yield* fs.stat(agent.path)).mode & 511
86
+ file: {
87
+ path: `${target.agents.dir}/${agent.name}${target.agents.suffix}`,
88
+ content: `---\n${yaml}---\n${appendSections(rendered.text, mapped.sections)}`,
89
+ mode: (yield* fs.stat(agent.path)).mode & 511
90
+ },
91
+ notes: mapped.drops.map(({ field, kind }) => ({
92
+ target: id,
93
+ path: source,
94
+ kind,
95
+ name: field
96
+ }))
84
97
  };
85
98
  });
86
99
 
package/body.js CHANGED
@@ -5,31 +5,98 @@
5
5
  * `<!-- /pluginfinity:only -->` closes it. A marker inside fenced code or an
6
6
  * inline code span is text, so a body can show one.
7
7
  */
8
- const OPEN = /^\s*<!--\s*pluginfinity:only\s+([^>]*?)\s*-->\s*$/;
8
+ const OPEN_PREFIX = /^\s*<!--\s*pluginfinity:only\s+/;
9
9
  const CLOSE = /^\s*<!--\s*\/pluginfinity:only\s*-->\s*$/;
10
10
  const MARKER = /<!--\s*\/?pluginfinity:only/;
11
+ /**
12
+ * The target ids of a host block's opening line, or `undefined` when the line
13
+ * is not an opener. A prefix match, then string operations on the rest, so no
14
+ * pattern has overlapping quantifiers to backtrack on.
15
+ */
16
+ const openingIds = (line) => {
17
+ const prefix = OPEN_PREFIX.exec(line);
18
+ if (prefix === null) return void 0;
19
+ const rest = line.slice(prefix[0].length).trimEnd();
20
+ if (!rest.endsWith("-->")) return void 0;
21
+ const inner = rest.slice(0, -3);
22
+ if (inner.includes(">")) return void 0;
23
+ return inner.split(/\s+/).filter((id) => id.length > 0);
24
+ };
11
25
  const FENCE = /^ {0,3}(`{3,}|~{3,})/;
12
- const INLINE_CODE = /(`+)[\s\S]*?\1/g;
13
26
  /**
14
- * Keep the passages of a body's host blocks that list `target`, drop the
15
- * rest, and remove every marker line. Blocks do not nest; an unclosed block,
16
- * a stray close, a marker that is not on a line of its own, or an id outside
17
- * `known` is a problem, and the body is not rewritten. So, until references
18
- * are built, is a `pluginfinity://` link; see {@link referenceLines}.
27
+ * The inline code spans of one line, as sorted, disjoint `[start, end)` ranges
28
+ * covering the backticks too. A span opens at a run of backticks and closes at
29
+ * the next run of exactly the same length; a run with no such partner is
30
+ * literal text. One pass over the line: runs are indexed, then each is paired
31
+ * with the next run of its length, so no input backtracks.
32
+ */
33
+ const inlineCodeSpans = (line) => {
34
+ const starts = [];
35
+ const lengths = [];
36
+ for (let i = 0; i < line.length;) {
37
+ if (line[i] !== "`") {
38
+ i++;
39
+ continue;
40
+ }
41
+ let j = i;
42
+ while (line[j] === "`") j++;
43
+ starts.push(i);
44
+ lengths.push(j - i);
45
+ i = j;
46
+ }
47
+ const partner = new Array(starts.length).fill(-1);
48
+ const nextOfLength = /* @__PURE__ */ new Map();
49
+ for (let k = starts.length - 1; k >= 0; k--) {
50
+ const len = lengths[k];
51
+ partner[k] = nextOfLength.get(len) ?? -1;
52
+ nextOfLength.set(len, k);
53
+ }
54
+ const spans = [];
55
+ for (let k = 0; k < starts.length;) {
56
+ const close = partner[k];
57
+ if (close === -1) {
58
+ k++;
59
+ continue;
60
+ }
61
+ spans.push({
62
+ start: starts[k],
63
+ end: starts[close] + lengths[close]
64
+ });
65
+ k = close + 1;
66
+ }
67
+ return spans;
68
+ };
69
+ /** The line with its inline code spans removed. */
70
+ const stripInlineCode = (line) => {
71
+ let out = "";
72
+ let at = 0;
73
+ for (const { start, end } of inlineCodeSpans(line)) {
74
+ out += line.slice(at, start);
75
+ at = end;
76
+ }
77
+ return out + line.slice(at);
78
+ };
79
+ /**
80
+ * {@link applyHostBlocks}, also returning the 1-based source line of each
81
+ * line of the result, so a problem found in the result can be reported where
82
+ * the author wrote it.
19
83
  *
20
- * @public
84
+ * @internal
21
85
  */
22
- const applyHostBlocks = (text, target, known) => {
23
- const [reference] = referenceLines(text);
24
- if (reference !== void 0) return { problem: {
25
- line: reference,
26
- message: "pluginfinity:// references are not built yet; link with a relative path instead"
27
- } };
28
- if (!MARKER.test(text)) return { text };
86
+ const mapHostBlocks = (text, target, known) => {
87
+ const lines = text.split("\n");
88
+ if (!MARKER.test(text)) return {
89
+ text,
90
+ lines: lines.map((_, index) => index + 1)
91
+ };
29
92
  const kept = [];
93
+ const sources = [];
94
+ const push = (line, number) => {
95
+ kept.push(line);
96
+ sources.push(number);
97
+ };
30
98
  let open;
31
99
  let fence;
32
- const lines = text.split("\n");
33
100
  for (const [index, line] of lines.entries()) {
34
101
  const number = index + 1;
35
102
  const keep = open === void 0 || open.keep;
@@ -37,16 +104,15 @@ const applyHostBlocks = (text, target, known) => {
37
104
  if (fence !== void 0 || fenceMark !== void 0) {
38
105
  if (fence === void 0) fence = fenceMark;
39
106
  else if (fenceMark !== void 0 && fenceMark[0] === fence[0] && fenceMark.length >= fence.length) fence = void 0;
40
- if (keep) kept.push(line);
107
+ if (keep) push(line, number);
41
108
  continue;
42
109
  }
43
- const opening = OPEN.exec(line);
44
- if (opening !== null) {
110
+ const ids = openingIds(line);
111
+ if (ids !== void 0) {
45
112
  if (open !== void 0) return { problem: {
46
113
  line: number,
47
114
  message: "host blocks do not nest"
48
115
  } };
49
- const ids = (opening[1] ?? "").split(/\s+/).filter((id) => id.length > 0);
50
116
  const unknown = ids.filter((id) => !known.includes(id));
51
117
  if (ids.length === 0) return { problem: {
52
118
  line: number,
@@ -70,41 +136,51 @@ const applyHostBlocks = (text, target, known) => {
70
136
  open = void 0;
71
137
  continue;
72
138
  }
73
- if (MARKER.test(line.replace(INLINE_CODE, ""))) return { problem: {
139
+ if (MARKER.test(stripInlineCode(line))) return { problem: {
74
140
  line: number,
75
141
  message: "a host block marker must be on a line of its own"
76
142
  } };
77
- if (keep) kept.push(line);
143
+ if (keep) push(line, number);
78
144
  }
79
145
  if (open !== void 0) return { problem: {
80
146
  line: open.line,
81
147
  message: "a host block is never closed"
82
148
  } };
83
- return { text: kept.join("\n") };
149
+ return {
150
+ text: kept.join("\n"),
151
+ lines: sources
152
+ };
84
153
  };
85
- const REFERENCE = /\]\(\s*<?pluginfinity:\/\//;
86
154
  /**
87
- * The 1-based lines of a body that link to a `pluginfinity://` reference,
88
- * outside fenced code and inline code spans. References are not built yet,
89
- * and an unbuilt reference must never ship as text, so each is a problem.
155
+ * Keep the passages of a body's host blocks that list `target`, drop the
156
+ * rest, and remove every marker line. Blocks do not nest; an unclosed block,
157
+ * a stray close, a marker that is not on a line of its own, or an id outside
158
+ * `known` is a problem, and the body is not rewritten. Tokens and
159
+ * `pluginfinity://` links are left for {@link renderTokens}, which runs after.
90
160
  *
91
161
  * @public
92
162
  */
93
- const referenceLines = (text) => {
94
- if (!text.includes("pluginfinity://")) return [];
95
- const found = [];
163
+ const applyHostBlocks = (text, target, known) => {
164
+ const mapped = mapHostBlocks(text, target, known);
165
+ return "problem" in mapped ? mapped : { text: mapped.text };
166
+ };
167
+ /**
168
+ * For each line of `text`, whether it belongs to fenced code: a fence's
169
+ * opening and closing lines and everything between. A fence closes on the
170
+ * same character, at least as long; an unclosed fence runs to the end.
171
+ *
172
+ * @internal
173
+ */
174
+ const fencedLines = (lines) => {
96
175
  let fence;
97
- for (const [index, line] of text.split("\n").entries()) {
176
+ return lines.map((line) => {
98
177
  const fenceMark = FENCE.exec(line)?.[1];
99
- if (fence !== void 0 || fenceMark !== void 0) {
100
- if (fence === void 0) fence = fenceMark;
101
- else if (fenceMark !== void 0 && fenceMark[0] === fence[0] && fenceMark.length >= fence.length) fence = void 0;
102
- continue;
103
- }
104
- if (REFERENCE.test(line.replace(INLINE_CODE, ""))) found.push(index + 1);
105
- }
106
- return found;
178
+ if (fence === void 0 && fenceMark === void 0) return false;
179
+ if (fence === void 0) fence = fenceMark;
180
+ else if (fenceMark !== void 0 && fenceMark[0] === fence[0] && fenceMark.length >= fence.length) fence = void 0;
181
+ return true;
182
+ });
107
183
  };
108
184
 
109
185
  //#endregion
110
- export { applyHostBlocks, referenceLines };
186
+ export { FENCE, applyHostBlocks, fencedLines, inlineCodeSpans, mapHostBlocks, stripInlineCode };
package/component.js CHANGED
@@ -15,6 +15,19 @@ const issue = (key, message) => ConfigIssue.make({
15
15
  message
16
16
  });
17
17
  /**
18
+ * Token problems as issues keyed by their source file line: `lines` maps each
19
+ * line of the rendered text to its line in the source text (see
20
+ * `mapHostBlocks`), and the source text starts `offset` lines into the file.
21
+ * Each is marked a token issue, so its remediation names the token fixes.
22
+ *
23
+ * @internal
24
+ */
25
+ const lineIssues = (found, lines, offset) => found.map((problem) => ConfigIssue.make({
26
+ key: `line ${(lines[problem.line - 1] ?? problem.line) + offset}`,
27
+ message: problem.message,
28
+ kind: "token"
29
+ }));
30
+ /**
18
31
  * A `ComponentInvalid` for `path`, optionally specific to one target.
19
32
  *
20
33
  * @internal
@@ -154,4 +167,4 @@ const JUNK = /* @__PURE__ */ new Set([
154
167
  const toLf = (text) => text.replaceAll("\r\n", "\n");
155
168
 
156
169
  //#endregion
157
- export { STRINGIFY, decodeComponent, frontmatterText, invalid, isJunk, issue, overlayIssues, toLf, unknownTargets };
170
+ export { STRINGIFY, decodeComponent, frontmatterText, invalid, isJunk, issue, lineIssues, overlayIssues, toLf, unknownTargets };
package/doctor.js CHANGED
@@ -2,11 +2,11 @@ import { ConfigLoader } from "./loader.js";
2
2
  import { selectConfigPaths } from "./selection.js";
3
3
  import { ENGINE_VERSION } from "./version.js";
4
4
  import { Duration, Effect, FileSystem, Option, Path, Result, Schema } from "effect";
5
+ import { TARGETS } from "@pluginfinity/targets";
5
6
  import { Walker } from "@effected/walker";
6
7
  import { Tool, ToolDiscovery } from "@effected/commands";
7
8
  import { CurrentDistribution, DistributionField, Remediation } from "@effected/engine";
8
9
  import { SemVer } from "@effected/semver";
9
- import { TARGETS } from "@pluginfinity/targets";
10
10
 
11
11
  //#region src/doctor.ts
12
12
  /**
package/emit.js CHANGED
@@ -11,6 +11,14 @@ const encoder = new TextEncoder();
11
11
  const bytesOf = (file) => typeof file.content === "string" ? encoder.encode(file.content) : file.content;
12
12
  const modeOf = (file) => file.mode ?? 420;
13
13
  /**
14
+ * Whether a file's mode on disk matches what the build would write. A
15
+ * generated file's mode is never compared, and a copied file's only by its
16
+ * executable bit: git tracks nothing finer, and tools that flip permission
17
+ * bits behind a commit (a hook running `chmod +x` with `core.fileMode=false`,
18
+ * a umask of 002) would otherwise make a fresh build look stale.
19
+ */
20
+ const sameMode = (file, onDisk) => file.mode === void 0 || (file.mode & 73) !== 0 === ((onDisk & 73) !== 0);
21
+ /**
14
22
  * How an output directory differs from what a build produces. Every list is
15
23
  * sorted and holds `/`-separated paths relative to the output directory.
16
24
  *
@@ -19,11 +27,14 @@ const modeOf = (file) => file.mode ?? 420;
19
27
  var EmitPlan = class extends Schema.Class("EmitPlan")({
20
28
  /** Produced, not on disk. */
21
29
  added: Schema.Array(Schema.String),
22
- /** On disk with other bytes or another mode. */
30
+ /** On disk with other bytes, or a copied file whose executable bit differs. */
23
31
  changed: Schema.Array(Schema.String),
24
32
  /** On disk, no longer produced; an empty directory ends in `/`. */
25
33
  removed: Schema.Array(Schema.String),
26
- /** On disk with the same bytes and mode; never touched, so its mtime stays. */
34
+ /**
35
+ * On disk with the same bytes and, for a copied file, the same executable
36
+ * bit; never touched, so its mtime and mode stay.
37
+ */
27
38
  unchanged: Schema.Array(Schema.String)
28
39
  }) {
29
40
  /** Whether the output directory already matches the build. */
@@ -53,6 +64,10 @@ const inventory = (dir) => Effect.gen(function* () {
53
64
  /**
54
65
  * Compare `files` with what `dir` holds, reading only.
55
66
  *
67
+ * @remarks
68
+ * A file is compared by its bytes and, when it carries a source mode, by its
69
+ * executable bit alone; other permission bits never make a file changed.
70
+ *
56
71
  * @public
57
72
  */
58
73
  const planEmit = (dir, files) => Effect.gen(function* () {
@@ -69,7 +84,7 @@ const planEmit = (dir, files) => Effect.gen(function* () {
69
84
  }
70
85
  const target = path.join(dir, file.path);
71
86
  const info = yield* fs.stat(target);
72
- (info.type === "File" && (info.mode & 511) === modeOf(file) && sameBytes(yield* fs.readFile(target), bytesOf(file)) ? unchanged : changed).push(file.path);
87
+ (info.type === "File" && sameMode(file, info.mode) && sameBytes(yield* fs.readFile(target), bytesOf(file)) ? unchanged : changed).push(file.path);
73
88
  }
74
89
  const produced = new Set(files.map((file) => file.path));
75
90
  const removed = [...existing].filter((file) => !produced.has(file));
package/errors.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Schema } from "effect";
2
+ import { KNOWN_TARGET_IDS } from "@pluginfinity/targets";
2
3
 
3
4
  //#region src/errors.ts
4
5
  /**
@@ -9,9 +10,21 @@ import { Schema } from "effect";
9
10
  var ConfigIssue = class extends Schema.Class("ConfigIssue")({
10
11
  /** The dotted key path inside the config, `""` for the config as a whole. */
11
12
  key: Schema.String,
12
- message: Schema.String
13
+ message: Schema.String,
14
+ /** `"token"` for a body token or `pluginfinity://` link that cannot be built. */
15
+ kind: Schema.optionalKey(Schema.Literal("token"))
13
16
  }) {};
14
17
  /**
18
+ * The ways to clear a token or link problem besides correcting it: keep the
19
+ * passage from the failing target, keep the braces literal, or keep a link
20
+ * literal in inline code. A host block must name a target other than the failing one.
21
+ */
22
+ const tokenAlternatives = (failing) => {
23
+ const named = new Set(failing.filter((target) => target !== void 0));
24
+ const others = KNOWN_TARGET_IDS.filter((target) => !named.has(target));
25
+ return `${others.length > 0 ? `use a host block (<!-- pluginfinity:only ${others.join(" ")} -->) around a passage only another target can build` : "use a host block (<!-- pluginfinity:only <other target> -->) around a passage only another target can build"}, \`\\{{\` to keep a token literal, or inline code to keep a pluginfinity:// link literal`;
26
+ };
27
+ /**
15
28
  * The upward walk reached a `.git` directory or the filesystem root without
16
29
  * finding a config, or an explicit `--config` file does not exist.
17
30
  *
@@ -263,7 +276,55 @@ var HookScriptInvalid = class extends Schema.TaggedError()("HookScriptInvalid",
263
276
  }
264
277
  };
265
278
  /**
266
- * A copied source file and a generated file would land on the same build path.
279
+ * What is wrong with a file a server or the `files` key ships.
280
+ *
281
+ * @public
282
+ */
283
+ const ShippedFileProblem = Schema.Literals([
284
+ "missing",
285
+ "not-executable",
286
+ "directory",
287
+ "outside-root",
288
+ "not-normal"
289
+ ]);
290
+ /**
291
+ * A file the build must ship for a server, or because `files` lists it, cannot be shipped.
292
+ *
293
+ * @public
294
+ */
295
+ var ShippedFileInvalid = class extends Schema.TaggedError()("ShippedFileInvalid", {
296
+ /** The config. */
297
+ path: Schema.String,
298
+ /** The file, relative to the plugin root. */
299
+ file: Schema.String,
300
+ /** What names it: `mcpServers.<name>`, `lspServers.<name>` (prefixed `<target>.` when a target override sets it) or `files`. */
301
+ referencedBy: Schema.String,
302
+ problem: ShippedFileProblem
303
+ }) {
304
+ get message() {
305
+ const why = {
306
+ missing: "does not exist",
307
+ "not-executable": "is its command but is not executable",
308
+ directory: "is its command but is a directory",
309
+ "outside-root": "resolves outside the plugin",
310
+ "not-normal": "has an empty, . or .. segment"
311
+ }[this.problem];
312
+ return `${this.file}, named by ${this.referencedBy} in ${this.path}, ${why}`;
313
+ }
314
+ get remediation() {
315
+ return { hint: {
316
+ missing: `Create ${this.file} under the plugin root, or fix the path in ${this.referencedBy}.`,
317
+ "not-executable": `Run \`chmod +x ${this.file}\`, or run it through sh: command "sh" with the path in args.`,
318
+ directory: `Name the launcher file inside ${this.file} as the command; a directory ships whole only when another server field names it.`,
319
+ "outside-root": "Keep shipped files inside the plugin directory; a path or symlink that leaves it cannot ship.",
320
+ "not-normal": `Write the path in ${this.referencedBy} without . or .. segments, as it lies under the plugin root.`
321
+ }[this.problem] };
322
+ }
323
+ };
324
+ /**
325
+ * A copied source file would land on a path pluginfinity owns: a file it
326
+ * generates, a directory it reserves for an injected library, or a server
327
+ * config file the host loads beside servers written inline.
267
328
  *
268
329
  * @public
269
330
  */
@@ -272,13 +333,27 @@ var PathConflict = class extends Schema.TaggedError()("PathConflict", {
272
333
  path: Schema.String,
273
334
  target: Schema.String,
274
335
  /** The build path both claim, relative to `builds/<target>/`. */
275
- file: Schema.String
336
+ file: Schema.String,
337
+ /** Why the path is taken: a generated file, a reserved library directory, or a reserved server file. */
338
+ conflict: Schema.Literals([
339
+ "generated",
340
+ "reserved-dir",
341
+ "reserved-server-file"
342
+ ])
276
343
  }) {
277
344
  get message() {
278
- return `${this.target} generates ${this.file}, but the plugin also ships a source file at that path`;
345
+ switch (this.conflict) {
346
+ case "reserved-dir": return `${this.file} is under a directory pluginfinity reserves for its injected library`;
347
+ case "reserved-server-file": return `${this.target} loads ${this.file} as a server config file, but the plugin also ships a source file at that path`;
348
+ default: return `${this.target} generates ${this.file}, but the plugin also ships a source file at that path`;
349
+ }
279
350
  }
280
351
  get remediation() {
281
- return { hint: `Delete or move the source ${this.file}; pluginfinity writes that file itself.` };
352
+ switch (this.conflict) {
353
+ case "reserved-dir": return { hint: `Move ${this.file} out of the reserved directory.` };
354
+ case "reserved-server-file": return { hint: `Declare those servers under mcpServers or lspServers in the pluginfinity config instead of shipping ${this.file}.` };
355
+ default: return { hint: `Delete or move the source ${this.file}; pluginfinity writes that file itself.` };
356
+ }
282
357
  }
283
358
  };
284
359
  /**
@@ -299,7 +374,11 @@ var ComponentInvalid = class extends Schema.TaggedError()("ComponentInvalid", {
299
374
  return `${this.target === void 0 ? this.path : `${this.path} (for ${this.target})`}: ${this.issues.map((issue) => issue.key === "" ? issue.message : `${issue.key}: ${issue.message}`).join("; ")}`;
300
375
  }
301
376
  get remediation() {
302
- return this.target === void 0 ? { hint: `Correct the listed problems in ${this.path}.` } : { hint: `Correct the listed problems in ${this.path}, or set the field for ${this.target} in its \`targets.${this.target}\` block.` };
377
+ const tokens = this.issues.filter((issue) => issue.kind === "token").length;
378
+ const lead = `Correct the listed problems in ${this.path}`;
379
+ if (tokens > 0 && tokens === this.issues.length) return { hint: `${lead}; to keep a passage from this target, ${tokenAlternatives([this.target])}.` };
380
+ const field = this.target === void 0 ? lead : `${lead}, or set the field for ${this.target} in its \`targets.${this.target}\` block`;
381
+ return { hint: tokens > 0 ? `${field}; for a token or link, ${tokenAlternatives([this.target])}.` : `${field}.` };
303
382
  }
304
383
  };
305
384
  /**
@@ -318,7 +397,9 @@ var ComponentsInvalid = class extends Schema.TaggedError()("ComponentsInvalid",
318
397
  return [`${count} ${count === 1 ? "component is" : "components are"} invalid in the plugin of ${this.path}:`, ...this.components.map((component) => ` - ${component.message}`)].join("\n");
319
398
  }
320
399
  get remediation() {
321
- return { hint: "Correct each listed file; a field one host cannot take can be set in that host's `targets` block." };
400
+ const failing = this.components.filter((component) => component.issues.some((issue) => issue.kind === "token"));
401
+ const base = "Correct each listed file; a field one host cannot take can be set in that host's `targets` block";
402
+ return { hint: failing.length > 0 ? `${base}; to keep a passage from a target, ${tokenAlternatives(failing.map((component) => component.target))}.` : `${base}.` };
322
403
  }
323
404
  };
324
405
  const BUILD_ERROR_TAGS = [
@@ -327,6 +408,7 @@ const BUILD_ERROR_TAGS = [
327
408
  "HostRejected",
328
409
  "HookEventUnsupported",
329
410
  "HookScriptInvalid",
411
+ "ShippedFileInvalid",
330
412
  "PathConflict",
331
413
  "ComponentsInvalid"
332
414
  ];
@@ -338,4 +420,4 @@ const BUILD_ERROR_TAGS = [
338
420
  const isBuildError = (error) => typeof error === "object" && error !== null && "_tag" in error && typeof error._tag === "string" && BUILD_ERROR_TAGS.includes(error._tag);
339
421
 
340
422
  //#endregion
341
- export { BuildStale, ComponentInvalid, ComponentsInvalid, ConfigAmbiguous, ConfigInvalid, ConfigIssue, ConfigLoadFailed, ConfigNotFound, HookEventUnsupported, HookScriptInvalid, HookScriptProblem, HostRejected, NotImplemented, PackageVersionMissing, PathConflict, TargetDrift, TargetNotEnabled, UnknownTarget, isBuildError, isConfigError };
423
+ export { BuildStale, ComponentInvalid, ComponentsInvalid, ConfigAmbiguous, ConfigInvalid, ConfigIssue, ConfigLoadFailed, ConfigNotFound, HookEventUnsupported, HookScriptInvalid, HookScriptProblem, HostRejected, NotImplemented, PackageVersionMissing, PathConflict, ShippedFileInvalid, ShippedFileProblem, TargetDrift, TargetNotEnabled, UnknownTarget, isBuildError, isConfigError };