@pluginfinity/engine 0.2.0 → 0.3.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/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AgentFrontmatter, FieldMapEntry, HookEntry, SkillFrontmatter, Target } from "@pluginfinity/core";
1
+ import { AgentFrontmatter, EnvConfig, FieldMapEntry, HookEntry, MonitorEntry, SkillFrontmatter, Target } from "@pluginfinity/core";
2
2
  import { KnownTargetId, PluginfinityConfig } from "@pluginfinity/targets";
3
3
  import { Duration, Effect, FileSystem, Layer, Path, PlatformError, Schema } from "effect";
4
4
  import { Remediation } from "@effected/engine";
@@ -283,13 +283,15 @@ export declare class HookEventUnsupported extends HookEventUnsupported_base {
283
283
  *
284
284
  * @public
285
285
  */
286
- export declare const HookScriptProblem: Schema.Literals<readonly ["missing", "not-executable"]>;
286
+ export declare const HookScriptProblem: Schema.Literals<readonly ["missing", "not-executable", "equals-in-path"]>;
287
287
  declare const HookScriptInvalid_base: Schema.Class<HookScriptInvalid, Schema.TaggedStruct<"HookScriptInvalid", {
288
288
  /** The config. */
289
289
  readonly path: Schema.String;
290
290
  /** The script, relative to the plugin root. */
291
291
  readonly script: Schema.String;
292
- readonly problem: Schema.Literals<readonly ["missing", "not-executable"]>;
292
+ readonly problem: Schema.Literals<readonly ["missing", "not-executable", "equals-in-path"]>;
293
+ /** The component that runs the script: `hooks`, `monitors`, or `env` for the `env.setup` script. */
294
+ readonly component: Schema.Literals<readonly ["hooks", "monitors", "env"]>;
293
295
  }>, import("effect/Cause").YieldableError>;
294
296
  /**
295
297
  * A hook `script` cannot be shipped as configured.
@@ -297,6 +299,7 @@ declare const HookScriptInvalid_base: Schema.Class<HookScriptInvalid, Schema.Tag
297
299
  * @public
298
300
  */
299
301
  export declare class HookScriptInvalid extends HookScriptInvalid_base {
302
+ private get kind();
300
303
  get message(): string;
301
304
  get remediation(): Remediation;
302
305
  }
@@ -330,9 +333,16 @@ declare const PathConflict_base: Schema.Class<PathConflict, Schema.TaggedStruct<
330
333
  readonly target: Schema.String;
331
334
  /** The build path both claim, relative to `builds/<target>/`. */
332
335
  readonly file: Schema.String;
336
+ /**
337
+ * Why the path is taken: a generated file, a reserved library directory, a reserved server file,
338
+ * or the monitors file a `monitors` field generates.
339
+ */
340
+ readonly conflict: Schema.Literals<readonly ["generated", "reserved-dir", "reserved-server-file", "reserved-monitors-file"]>;
333
341
  }>, import("effect/Cause").YieldableError>;
334
342
  /**
335
- * A copied source file and a generated file would land on the same build path.
343
+ * A copied source file would land on a path pluginfinity owns: a file it
344
+ * generates, a directory it reserves for an injected library, or a server
345
+ * config file the host loads beside servers written inline.
336
346
  *
337
347
  * @public
338
348
  */
@@ -392,12 +402,22 @@ export declare const isBuildError: (error: unknown) => error is BuildError;
392
402
  *
393
403
  * @public
394
404
  */
395
- export declare const BUILD_NOTE_KINDS: readonly ["dropped", "degraded", "tool-dropped", "hook-omitted"];
405
+ export declare const BUILD_NOTE_KINDS: readonly ["dropped", "degraded", "tool-dropped", "hook-matcher-runtime", "hook-output-ignored", "hook-omitted", "monitor-omitted", "env-shell-unsupported", "env-wait-timeout", "hook-matcher-widened", "hook-matcher-regex"];
396
406
  /**
397
407
  * What a target did to something it could not carry as written: `dropped` a
398
408
  * field, `degraded` a field into another form (a description suffix or a body
399
- * section), `tool-dropped` a tool it cannot name, or `hook-omitted` an event
400
- * it lacks whose entries all set `fallback: "omit"`.
409
+ * section), `tool-dropped` a tool it cannot name, moved a
410
+ * `hook-matcher-runtime` matcher the host ignores into the hook library,
411
+ * noted a script that calls a helper whose output the host ignores
412
+ * (`hook-output-ignored`), `hook-omitted` an event it lacks whose entries all set `fallback: "omit"`,
413
+ * `monitor-omitted` a monitor on a host that has none, or noted that the host
414
+ * passes no session env to the model's shell (`env-shell-unsupported`), so a
415
+ * skill script must source `env.sh`, or a SessionStart hook whose `timeout`
416
+ * is under the 3 seconds a reader may wait for the env runner plus headroom
417
+ * (`env-wait-timeout`), or widened a SessionStart matcher that matches
418
+ * `startup` to match a host's `new` source too (`hook-matcher-widened`), or left
419
+ * a regex matcher as written that matches `startup` but not `new`
420
+ * (`hook-matcher-regex`).
401
421
  *
402
422
  * @public
403
423
  */
@@ -532,6 +552,11 @@ interface TokenContext {
532
552
  readonly plugin: string;
533
553
  /** The plugin's skill names. */
534
554
  readonly skills: ReadonlySet<string>;
555
+ /**
556
+ * The skill whose body (or bundled markdown file) is being rendered, so
557
+ * `{{skill_dir}}` can name it; absent when rendering an agent body.
558
+ */
559
+ readonly skill?: string;
535
560
  /** The plugin's agent names. */
536
561
  readonly agents: ReadonlySet<string>;
537
562
  /** Every file under a skill directory, as `<skill>/<path>`, `SKILL.md` included. */
@@ -559,8 +584,45 @@ interface TokenProblem {
559
584
  * or report every one it cannot render.
560
585
  *
561
586
  * @remarks
562
- * A token is `{{tool <name>}}`, `{{agent <name>}}`, `{{skill <name>}}` or
563
- * `{{plugin_root}}`, with whitespace allowed inside the braces, on one line.
587
+ * A token is one of the following, with whitespace allowed inside the braces,
588
+ * on one line:
589
+ *
590
+ * ```text
591
+ * {{tool <name>}}
592
+ * {{tool <name> | <fallback>}}
593
+ * {{agent <name>}}
594
+ * {{skill <name>}}
595
+ * {{skill_dir}}
596
+ * {{skill_dir <name>}}
597
+ * {{plugin_root}}
598
+ * ```
599
+ *
600
+ * `{{skill_dir}}` is the directory of the skill whose body it is written in,
601
+ * and `{{skill_dir <name>}}` that of the named skill (naming the own skill is
602
+ * the own form). Claude spells them `${CLAUDE_SKILL_DIR}` and
603
+ * `${CLAUDE_PLUGIN_ROOT}/skills/<name>`, which it expands in skill bodies;
604
+ * Copilot expands nothing, so on Copilot the token is a placeholder the model
605
+ * resolves from the "Base directory for this skill" line the host puts above
606
+ * the body (`<skill base directory>`, and `<skill base directory>/../<name>`
607
+ * for a sibling), not a literal path. An agent has no skill directory, so the
608
+ * bare form there is a problem, as is a named skill on a target with no
609
+ * spelling for it from an agent (Copilot), an unknown skill or one the target
610
+ * does not build. It takes neither a `|` fallback nor backticks.
611
+ *
612
+ * A tool token may wrap its name in exactly one pair of backticks:
613
+ *
614
+ * ```text
615
+ * {{tool `Name`}}
616
+ * {{tool `Name` | <fallback>}}
617
+ * ```
618
+ *
619
+ * It then renders as a code span of the spelling where the tool spells, and as
620
+ * the fallback in plain text where it does not;
621
+ * unbalanced or doubled backticks, and backticks on any other kind, are
622
+ * problems. Only a tool token takes
623
+ * a `|` fallback: literal prose, trimmed, that replaces the token on a target
624
+ * where the tool has no spelling (and is discarded where it has one). It may
625
+ * not be empty or contain `{` or `}`.
564
626
  * Tokens are replaced everywhere, fenced and inline code included; `\{{`
565
627
  * before a token renders it literally, and before any other `{{` the
566
628
  * backslash stays. A `{{` whose first word is not a kind is text, so
@@ -920,6 +982,12 @@ export declare const targetHooks: (target: Target, id: KnownTargetId, config: Pl
920
982
  * @public
921
983
  */
922
984
  export declare const hookScripts: (events: ReadonlyArray<TargetHookEvent>) => ReadonlyArray<string>;
985
+ /**
986
+ * Every file a command names as `${PLUGIN_ROOT}/<path>`, in order.
987
+ *
988
+ * @public
989
+ */
990
+ export declare const commandFiles: (command: string) => ReadonlyArray<string>;
923
991
  /**
924
992
  * Every file the given events' `command` entries name as
925
993
  * `${PLUGIN_ROOT}/<path>`, so the build can ship and check them as it does
@@ -928,6 +996,22 @@ export declare const hookScripts: (events: ReadonlyArray<TargetHookEvent>) => Re
928
996
  * @public
929
997
  */
930
998
  export declare const hookCommandFiles: (events: ReadonlyArray<TargetHookEvent>) => ReadonlyArray<string>;
999
+ /**
1000
+ * The environment every hook entry runs with: the event the library reads
1001
+ * (camelCase Copilot payloads carry no `hook_event_name`), `"1"` for
1002
+ * `PLUGINFINITY_FAIL_CLOSED` when the entry sets `failClosed`, and the
1003
+ * matcher when one is given.
1004
+ *
1005
+ * @public
1006
+ */
1007
+ export declare const entryEnv: (event: string, entry: HookEntry, matcher?: string) => Readonly<Record<string, string>>;
1008
+ /**
1009
+ * An env as a shell prefix, `K='V' ` per pair: every value single-quoted, and
1010
+ * empty for an empty env.
1011
+ *
1012
+ * @public
1013
+ */
1014
+ export declare const shellEnvPrefix: (env: Readonly<Record<string, string>>) => string;
931
1015
  /**
932
1016
  * The shell command a hook entry runs on a target: a `script` through `bash`
933
1017
  * (or executed directly under `scripts.invoke: "exec"`) at the target's
@@ -935,7 +1019,7 @@ export declare const hookCommandFiles: (events: ReadonlyArray<TargetHookEvent>)
935
1019
  *
936
1020
  * @public
937
1021
  */
938
- export declare const hookCommand: (entry: HookEntry, root: string, invoke: "bash" | "exec") => string;
1022
+ export declare const hookCommand: (entry: HookEntry, root: string, invoke: "bash" | "exec", env?: Readonly<Record<string, string>>) => string;
939
1023
  /**
940
1024
  * A `script` entry in exec form, for a host that spawns `command` with `args`
941
1025
  * and no shell: `bash` with the script path as its first argument, or under
@@ -946,10 +1030,37 @@ export declare const hookCommand: (entry: HookEntry, root: string, invoke: "bash
946
1030
  */
947
1031
  export declare const hookExec: (entry: Extract<HookEntry, {
948
1032
  readonly script: string;
949
- }>, root: string, invoke: "bash" | "exec") => {
1033
+ }>, root: string, invoke: "bash" | "exec", env?: Readonly<Record<string, string>>) => {
950
1034
  readonly command: string;
951
1035
  readonly args: ReadonlyArray<string>;
952
1036
  };
1037
+ /**
1038
+ * How a host that ignores the SessionStart matcher is told a matcher: a host
1039
+ * names a fresh session's source `new` where Claude says `startup`, so a
1040
+ * matcher that matches `startup` must match `new` too.
1041
+ *
1042
+ * An exact list holding `startup` gains `new` right after it (`startup|resume`
1043
+ * becomes `startup|new|resume`); one that already holds `new`, an empty or `*`
1044
+ * matcher and any matcher not matching `startup` stay as written. A regex
1045
+ * that matches `startup` but not `new` also stays as written, reported as
1046
+ * `unwidened` so the build can note it. The regex is tried as a JavaScript
1047
+ * `RegExp` while the hook library matches with `grep -E`, so exotic syntax
1048
+ * may differ.
1049
+ *
1050
+ * @public
1051
+ */
1052
+ export declare const sessionStartMatcher: (matcher: string) => {
1053
+ readonly matcher: string;
1054
+ readonly widened: boolean;
1055
+ readonly unwidened: boolean;
1056
+ };
1057
+ /**
1058
+ * Whether a host that ignores matchers on `event` (`ignored` is its list) is
1059
+ * given a widened SessionStart matcher.
1060
+ *
1061
+ * @public
1062
+ */
1063
+ export declare const widensSessionStart: (ignored: ReadonlyArray<string>, event: string) => boolean;
953
1064
  /**
954
1065
  * Render a target's hooks file as JSON text, or `undefined` when the target
955
1066
  * builds no hooks.
@@ -958,6 +1069,196 @@ export declare const hookExec: (entry: Extract<HookEntry, {
958
1069
  */
959
1070
  export declare const renderHooks: (target: Target, events: ReadonlyArray<TargetHookEvent>, invoke: "bash" | "exec") => string | undefined;
960
1071
  //#endregion
1072
+ //#region src/env.d.ts
1073
+ /**
1074
+ * Seconds the env runner gives the `setup` script before it discards its
1075
+ * output and resolves without it.
1076
+ *
1077
+ * @public
1078
+ */
1079
+ export declare const ENV_SETUP_TIMEOUT = 10;
1080
+ /**
1081
+ * The host timeout, in seconds, of the generated SessionStart entry: the setup
1082
+ * bound plus room for the runner to write the values after a setup timeout.
1083
+ *
1084
+ * @public
1085
+ */
1086
+ export declare const ENV_RUNNER_TIMEOUT = 15;
1087
+ /**
1088
+ * `env.sh` with its declarations block filled in: the declared names in
1089
+ * config order, each default, the setup path and its time bound.
1090
+ *
1091
+ * @remarks
1092
+ * Every value is single-quoted for the shell. The names need no quoting: the
1093
+ * config schema admits only `[A-Z_][A-Z0-9_]*`.
1094
+ *
1095
+ * @public
1096
+ */
1097
+ export declare const renderEnvLib: (env: EnvConfig) => string;
1098
+ /**
1099
+ * The session env library as a build writes it under `dir`: `env.sh` with its
1100
+ * declarations, and the SessionStart runner `env-run.sh`.
1101
+ *
1102
+ * @public
1103
+ */
1104
+ export declare const envLibFiles: (env: EnvConfig, dir: string) => ReadonlyArray<EmittedFile>;
1105
+ /**
1106
+ * The hook entry that runs the env runner at `${PLUGIN_ROOT}/<dir>/env-run.sh`
1107
+ * under `sh`, with no matcher, so it runs for every SessionStart source.
1108
+ *
1109
+ * @public
1110
+ */
1111
+ export declare const envRunnerEntry: (dir: string) => HookEntry;
1112
+ /**
1113
+ * The events with `entry` first among the SessionStart entries, adding the
1114
+ * event (first) when the plugin has no SessionStart hooks. A target without
1115
+ * SessionStart gets the events unchanged.
1116
+ *
1117
+ * @remarks
1118
+ * First in order is not first to finish: Claude Code runs an event's matching
1119
+ * hooks in parallel, so another SessionStart hook may read before the runner
1120
+ * has written the session values, and then resolves the chain live.
1121
+ *
1122
+ * @public
1123
+ */
1124
+ export declare const withEnvRunner: (target: Target, events: ReadonlyArray<TargetHookEvent>, entry: HookEntry) => ReadonlyArray<TargetHookEvent>;
1125
+ /**
1126
+ * The build notes for a target's session env: `env-shell-unsupported` when
1127
+ * the host cannot pass values from SessionStart to the model's shell, so a
1128
+ * skill script must source `env.sh` to see them.
1129
+ *
1130
+ * @public
1131
+ */
1132
+ export declare const envNotes: (target: Target, id: KnownTargetId) => ReadonlyArray<BuildNote>;
1133
+ /**
1134
+ * Seconds a SessionStart reader may wait for the env runner (3) plus headroom;
1135
+ * a SessionStart hook with a smaller `timeout` can be killed while it waits.
1136
+ *
1137
+ * @public
1138
+ */
1139
+ export declare const ENV_WAIT_TIMEOUT_FLOOR = 5;
1140
+ /**
1141
+ * An `env-wait-timeout` note for each SessionStart entry (other than the
1142
+ * runner, which is added later) whose `timeout` is set and under
1143
+ * {@link ENV_WAIT_TIMEOUT_FLOOR}: its hook library waits up to 3 s for the
1144
+ * runner before it reads. The note's path is the entry's script, else `config`.
1145
+ *
1146
+ * @public
1147
+ */
1148
+ export declare const envWaitNotes: (id: KnownTargetId, events: ReadonlyArray<TargetHookEvent>) => ReadonlyArray<BuildNote>;
1149
+ //#endregion
1150
+ //#region src/logs.d.ts
1151
+ /**
1152
+ * The two files a plugin's components log to.
1153
+ *
1154
+ * @public
1155
+ */
1156
+ type LogFileName = "error.log" | "debug.log";
1157
+ /**
1158
+ * One parsed log line: `<ISO-8601 UTC> [<host>] <component>/<script>: <message>`.
1159
+ *
1160
+ * @public
1161
+ */
1162
+ interface LogEntry {
1163
+ readonly ts: string;
1164
+ readonly host: string;
1165
+ readonly component: "hook" | "server" | "monitor" | "script";
1166
+ readonly script: string;
1167
+ readonly message: string;
1168
+ readonly plugin: string;
1169
+ readonly file: LogFileName;
1170
+ }
1171
+ /**
1172
+ * A line that does not follow the standard, carried through whole.
1173
+ *
1174
+ * @public
1175
+ */
1176
+ interface RawLogLine {
1177
+ readonly raw: string;
1178
+ readonly plugin: string;
1179
+ readonly file: LogFileName;
1180
+ }
1181
+ /**
1182
+ * Parse one log line, or carry it through as raw when it does not follow the
1183
+ * standard.
1184
+ *
1185
+ * @public
1186
+ */
1187
+ export declare const parseLogLine: (line: string, plugin: string, file: LogFileName) => LogEntry | RawLogLine;
1188
+ /**
1189
+ * The directory every plugin's logs live under: `<stateHome>/pluginfinity`.
1190
+ *
1191
+ * @public
1192
+ */
1193
+ export declare const logRoot: (stateHome: string) => Effect.Effect<string, never, Path.Path>;
1194
+ /**
1195
+ * One plugin's log directory: `<stateHome>/pluginfinity/<plugin>`.
1196
+ *
1197
+ * @public
1198
+ */
1199
+ export declare const logDirectory: (stateHome: string, plugin: string) => Effect.Effect<string, never, Path.Path>;
1200
+ /**
1201
+ * The plugin names that have a log directory, sorted; none when the state
1202
+ * directory does not exist.
1203
+ *
1204
+ * @public
1205
+ */
1206
+ export declare const listLogPlugins: (stateHome: string) => Effect.Effect<ReadonlyArray<string>, PlatformError.PlatformError, FileSystem.FileSystem | Path.Path>;
1207
+ /**
1208
+ * The names the selected config's targets publish under: the config's `name`
1209
+ * and each target's own `name` override, deduplicated, in first-seen order.
1210
+ * Each target's components log under its own name.
1211
+ *
1212
+ * @public
1213
+ */
1214
+ export declare const configPluginNames: (selection: ConfigSelection) => Effect.Effect<ReadonlyArray<string>, ConfigError, FileSystem.FileSystem | Path.Path>;
1215
+ /**
1216
+ * The tail of one log file.
1217
+ *
1218
+ * @public
1219
+ */
1220
+ interface LogTail {
1221
+ readonly plugin: string;
1222
+ readonly file: LogFileName;
1223
+ /** The file's absolute path, whether or not it exists. */
1224
+ readonly path: string;
1225
+ /** Whether the file exists. */
1226
+ readonly present: boolean;
1227
+ /** The last lines asked for, oldest first. */
1228
+ readonly lines: ReadonlyArray<string>;
1229
+ /** The byte offset after the last complete line: where {@link readLogFrom} resumes. */
1230
+ readonly offset: number;
1231
+ }
1232
+ /**
1233
+ * The last `lines` complete lines of a plugin's log file.
1234
+ *
1235
+ * @remarks
1236
+ * An absent file is `present: false` with no lines, not a failure: a plugin
1237
+ * that has logged nothing has no file.
1238
+ *
1239
+ * @public
1240
+ */
1241
+ export declare const readLog: (input: {
1242
+ readonly stateHome: string;
1243
+ readonly plugin: string;
1244
+ readonly file: LogFileName;
1245
+ readonly lines: number;
1246
+ }) => Effect.Effect<LogTail, PlatformError.PlatformError, FileSystem.FileSystem | Path.Path>;
1247
+ /**
1248
+ * The complete lines appended to `path` after byte `offset`, and the offset to
1249
+ * resume from.
1250
+ *
1251
+ * @remarks
1252
+ * A file smaller than `offset` was truncated or replaced, so reading restarts
1253
+ * from its beginning. A file that does not exist yields no lines at offset 0.
1254
+ *
1255
+ * @public
1256
+ */
1257
+ export declare const readLogFrom: (path: string, offset: number) => Effect.Effect<{
1258
+ readonly lines: ReadonlyArray<string>;
1259
+ readonly offset: number;
1260
+ }, PlatformError.PlatformError, FileSystem.FileSystem>;
1261
+ //#endregion
961
1262
  //#region src/manifest.d.ts
962
1263
  /**
963
1264
  * A manifest as written: a JSON object in the target's key order.
@@ -966,13 +1267,14 @@ export declare const renderHooks: (target: Target, events: ReadonlyArray<TargetH
966
1267
  */
967
1268
  type Manifest = Readonly<Record<string, unknown>>;
968
1269
  /**
969
- * Render a target's manifest from the config and the package version: the
970
- * format's record, cut to the target's key allowlist, in allowlist order, with
971
- * unset keys left out.
1270
+ * Render a target's manifest from the config, the package version and the
1271
+ * server maps the target places in its manifest (`ServerRender.manifest`):
1272
+ * the format's record, cut to the target's key allowlist, in allowlist order,
1273
+ * with unset keys left out.
972
1274
  *
973
1275
  * @public
974
1276
  */
975
- export declare const renderManifest: (target: Target, id: KnownTargetId, config: PluginfinityConfig, version: string) => Manifest;
1277
+ export declare const renderManifest: (target: Target, id: KnownTargetId, config: PluginfinityConfig, version: string, servers?: Readonly<Record<string, unknown>>) => Manifest;
976
1278
  /**
977
1279
  * The bytes a manifest is written as: tab-indented JSON with a final newline.
978
1280
  *
@@ -980,6 +1282,65 @@ export declare const renderManifest: (target: Target, id: KnownTargetId, config:
980
1282
  */
981
1283
  export declare const serializeManifest: (manifest: Manifest) => string;
982
1284
  //#endregion
1285
+ //#region src/monitors.d.ts
1286
+ /**
1287
+ * Monitors by name.
1288
+ *
1289
+ * @public
1290
+ */
1291
+ type MonitorMap = Readonly<Record<string, MonitorEntry>>;
1292
+ /**
1293
+ * The monitors a target builds: the base `monitors` with the target's own
1294
+ * replacing the base monitor of the same name.
1295
+ *
1296
+ * @public
1297
+ */
1298
+ export declare const targetMonitors: (id: KnownTargetId, config: PluginfinityConfig) => MonitorMap;
1299
+ /**
1300
+ * What a target builds of its monitors, before the build checks and ships the files.
1301
+ *
1302
+ * @public
1303
+ */
1304
+ interface RenderedMonitors {
1305
+ /** The monitors file, or none when the target has no monitors or the plugin sets none. */
1306
+ readonly file?: {
1307
+ readonly path: string;
1308
+ readonly content: string;
1309
+ };
1310
+ readonly notes: ReadonlyArray<BuildNote>;
1311
+ /** Each `when` that names a skill this target does not build, keyed `monitors.<name>.when`. */
1312
+ readonly issues: ReadonlyArray<ConfigIssue>;
1313
+ /** Every `script` the monitors run, plugin-relative. */
1314
+ readonly scripts: ReadonlyArray<string>;
1315
+ /** Every file a `command` monitor names as `${PLUGIN_ROOT}/<path>`. */
1316
+ readonly commandFiles: ReadonlyArray<string>;
1317
+ }
1318
+ /**
1319
+ * What a monitor's `when` may name: the plugin's name on the target, and the skills it builds.
1320
+ *
1321
+ * @public
1322
+ */
1323
+ interface MonitorContext {
1324
+ readonly plugin: string;
1325
+ readonly skills: ReadonlySet<string>;
1326
+ }
1327
+ /**
1328
+ * Render a target's monitors file. A target with no monitors drops every
1329
+ * monitor with a `monitor-omitted` note and ships neither file nor script.
1330
+ *
1331
+ * @remarks
1332
+ * Each entry's command carries `PLUGINFINITY_MONITOR` (the monitor's name,
1333
+ * which the monitor library logs under), quoted by `shellEnvPrefix`: a prefix
1334
+ * on a script, an `export` before a command.
1335
+ *
1336
+ * A `when` of `on-skill-invoke:<skill>` is written `on-skill-invoke:<plugin>:<skill>`: Claude
1337
+ * Code matches the plugin-qualified skill name only, and a bare name never starts the monitor.
1338
+ * A skill the target does not build is an issue, since the monitor would never start.
1339
+ *
1340
+ * @public
1341
+ */
1342
+ export declare const renderMonitors: (target: Target, id: KnownTargetId, monitors: MonitorMap, invoke: "bash" | "exec", context: MonitorContext) => RenderedMonitors;
1343
+ //#endregion
983
1344
  //#region src/operations.d.ts
984
1345
  /**
985
1346
  * The input to `build`.
@@ -1057,24 +1418,30 @@ export declare const validate: (input: ValidateInput) => Effect.Effect<ReadonlyA
1057
1418
  //#endregion
1058
1419
  //#region src/servers.d.ts
1059
1420
  /**
1060
- * A target's server config files, the problems that stop it building them,
1061
- * whether any server is a local process that needs the server library, and
1062
- * the server fields the target dropped.
1421
+ * A target's server config files, the server maps it writes inline in its
1422
+ * manifest, the problems that stop it building them, whether any server is a
1423
+ * local process that needs the server library, and the server fields the
1424
+ * target dropped.
1063
1425
  *
1064
1426
  * @public
1065
1427
  */
1066
1428
  interface ServerRender {
1429
+ /** The server files of a target that places its servers in files. */
1067
1430
  readonly files: ReadonlyArray<EmittedFile>;
1431
+ /** The server maps of a target that places its servers in its manifest, by manifest key. */
1432
+ readonly manifest: Readonly<Record<string, unknown>>;
1068
1433
  readonly issues: ReadonlyArray<ConfigIssue>;
1069
1434
  readonly stdio: boolean;
1070
1435
  /** Each LSP field dropped, as a `config` note named `<origin>.<server>.<field>`, in the order met. */
1071
1436
  readonly notes: ReadonlyArray<BuildNote>;
1072
1437
  }
1073
1438
  /**
1074
- * The target's MCP and LSP config files: base servers with the target's
1439
+ * The target's MCP and LSP configs: base servers with the target's
1075
1440
  * overrides applied by name, `${PLUGIN_ROOT}` rewritten to the target's
1076
1441
  * spelling, LSP fields mapped through the target's field map, and the
1077
- * server-library variables added to every local server's `env`.
1442
+ * server-library variables added to every local server's `env`. Each config
1443
+ * goes where the target places it: a file of its own, or inline under a
1444
+ * manifest key, for `renderManifest` to write.
1078
1445
  *
1079
1446
  * @public
1080
1447
  */
@@ -1195,5 +1562,5 @@ export declare const ToolDiscoveryLive: Layer.Layer<ToolDiscovery, never, ChildP
1195
1562
  */
1196
1563
  export declare const ENGINE_VERSION: string;
1197
1564
  //#endregion
1198
- export type { BuildError, BuildInput, BuildNote, BuildNoteKind, ConfigError, ConfigSelection, DoctorInput, EmittedFile, FieldDrop, HostBlockProblem, LoadedConfig, Manifest, MappedFrontmatter, OwnMcp, PlanError, PreparedPlugin, RenderedAgent, RenderedSkill, ServerFiles, ServerRender, SourceAgent, SourceSkill, SplitMarkdown, TargetBuild, TargetHookEvent, TargetValidation, TokenContext, TokenProblem, UnresolvedField, UnsupportedHookEvent, ValidateInput };
1565
+ export type { BuildError, BuildInput, BuildNote, BuildNoteKind, ConfigError, ConfigSelection, DoctorInput, EmittedFile, FieldDrop, HostBlockProblem, LoadedConfig, LogEntry, LogFileName, LogTail, Manifest, MappedFrontmatter, MonitorContext, MonitorMap, OwnMcp, PlanError, PreparedPlugin, RawLogLine, RenderedAgent, RenderedMonitors, RenderedSkill, ServerFiles, ServerRender, SourceAgent, SourceSkill, SplitMarkdown, TargetBuild, TargetHookEvent, TargetValidation, TokenContext, TokenProblem, UnresolvedField, UnsupportedHookEvent, ValidateInput };
1199
1566
  //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -9,12 +9,15 @@ import { preparePlugins, selectConfigPaths } from "./selection.js";
9
9
  import { ENGINE_VERSION } from "./version.js";
10
10
  import { CheckGroup, CheckSeverity, CheckStatus, DEFAULT_CHECK_TIMEOUT, DoctorCheck, DoctorReport, NODE_FLOOR, runDoctor } from "./doctor.js";
11
11
  import { EmitPlan, GENERATED_MODE, applyEmit, planEmit } from "./emit.js";
12
- import { hookCommand, hookCommandFiles, hookExec, hookScripts, renderHooks, targetHooks } from "./hooks.js";
13
- import { renderManifest, serializeManifest } from "./manifest.js";
14
12
  import { BUILD_NOTE_KINDS } from "./notes.js";
13
+ import { ENV_RUNNER_TIMEOUT, ENV_SETUP_TIMEOUT, ENV_WAIT_TIMEOUT_FLOOR, envLibFiles, envNotes, envRunnerEntry, envWaitNotes, renderEnvLib, withEnvRunner } from "./env.js";
14
+ import { commandFiles, entryEnv, hookCommand, hookCommandFiles, hookExec, hookScripts, renderHooks, sessionStartMatcher, shellEnvPrefix, targetHooks, widensSessionStart } from "./hooks.js";
15
+ import { renderManifest, serializeManifest } from "./manifest.js";
16
+ import { configPluginNames, listLogPlugins, logDirectory, logRoot, parseLogLine, readLog, readLogFrom } from "./logs.js";
17
+ import { renderMonitors, targetMonitors } from "./monitors.js";
15
18
  import { renderServers, serverFiles } from "./servers.js";
16
19
  import { SKILL_DESCRIPTION_MAX, readSkills, renderSkill } from "./skills.js";
17
20
  import { build, validate } from "./operations.js";
18
21
  import { ToolDiscoveryLive } from "./tools.js";
19
22
 
20
- export { BUILD_NOTE_KINDS, BuildStale, CONFIG_FILE_NAMES, CheckGroup, CheckSeverity, CheckStatus, ComponentInvalid, ComponentsInvalid, ConfigAmbiguous, ConfigDiscovery, ConfigInvalid, ConfigIssue, ConfigLoadFailed, ConfigLoader, ConfigNotFound, DEFAULT_CHECK_TIMEOUT, DoctorCheck, DoctorReport, ENGINE_VERSION, EmitPlan, GENERATED_MODE, HookEventUnsupported, HookScriptInvalid, HookScriptProblem, HostRejected, NODE_FLOOR, NotImplemented, PackageVersionMissing, PathConflict, SKILL_DESCRIPTION_MAX, ShippedFileInvalid, ShippedFileProblem, TargetDrift, TargetNotEnabled, ToolDiscoveryLive, UnknownTarget, appendSections, applyEmit, applyHostBlocks, build, hookCommand, hookCommandFiles, hookExec, hookScripts, isBuildError, isConfigError, mapFrontmatter, planEmit, preparePlugins, readAgents, readSkills, renderAgent, renderHooks, renderManifest, renderServers, renderSkill, renderTokens, runDoctor, selectConfigPaths, serializeManifest, serverFiles, splitFrontmatter, targetHooks, validate };
23
+ export { BUILD_NOTE_KINDS, BuildStale, CONFIG_FILE_NAMES, CheckGroup, CheckSeverity, CheckStatus, ComponentInvalid, ComponentsInvalid, ConfigAmbiguous, ConfigDiscovery, ConfigInvalid, ConfigIssue, ConfigLoadFailed, ConfigLoader, ConfigNotFound, DEFAULT_CHECK_TIMEOUT, DoctorCheck, DoctorReport, ENGINE_VERSION, ENV_RUNNER_TIMEOUT, ENV_SETUP_TIMEOUT, ENV_WAIT_TIMEOUT_FLOOR, EmitPlan, GENERATED_MODE, HookEventUnsupported, HookScriptInvalid, HookScriptProblem, HostRejected, NODE_FLOOR, NotImplemented, PackageVersionMissing, PathConflict, SKILL_DESCRIPTION_MAX, ShippedFileInvalid, ShippedFileProblem, TargetDrift, TargetNotEnabled, ToolDiscoveryLive, UnknownTarget, appendSections, applyEmit, applyHostBlocks, build, commandFiles, configPluginNames, entryEnv, envLibFiles, envNotes, envRunnerEntry, envWaitNotes, hookCommand, hookCommandFiles, hookExec, hookScripts, isBuildError, isConfigError, listLogPlugins, logDirectory, logRoot, mapFrontmatter, parseLogLine, planEmit, preparePlugins, readAgents, readLog, readLogFrom, readSkills, renderAgent, renderEnvLib, renderHooks, renderManifest, renderMonitors, renderServers, renderSkill, renderTokens, runDoctor, selectConfigPaths, serializeManifest, serverFiles, sessionStartMatcher, shellEnvPrefix, splitFrontmatter, targetHooks, targetMonitors, validate, widensSessionStart, withEnvRunner };
package/lib-files.js ADDED
@@ -0,0 +1,39 @@
1
+ import { envLibFiles } from "./env.js";
2
+ import { renderHostFile } from "./hook-lib.js";
3
+ import { LOG_LIB_FILES } from "./log-lib.generated.js";
4
+ import { MONITOR_LIB_FILES } from "./monitor-lib.generated.js";
5
+
6
+ //#region src/lib-files.ts
7
+ /**
8
+ * Where every build gets the shared libraries (`log.sh`, `host.sh`, the server library when
9
+ * there is a local server, `monitor.sh` when a target has monitors, and `env.sh` with its
10
+ * runner `env-run.sh` when the config declares `env`), relative to the build root.
11
+ *
12
+ * @public
13
+ */
14
+ const LIB_DIR = "lib/pluginfinity";
15
+ /**
16
+ * The files every build carries under `lib/pluginfinity`: the logging library and the
17
+ * generated `host.sh` that names the host and plugin, plus the monitor library when the
18
+ * target has monitors and the session env library when the config declares `env`.
19
+ *
20
+ * @public
21
+ */
22
+ const libFiles = (host, plugin, version, options) => [
23
+ ...LOG_LIB_FILES.map((file) => ({
24
+ path: `${LIB_DIR}/${file.name}`,
25
+ content: file.content
26
+ })),
27
+ {
28
+ path: `${LIB_DIR}/host.sh`,
29
+ content: renderHostFile(host, plugin, version)
30
+ },
31
+ ...options.monitors ? MONITOR_LIB_FILES.map((file) => ({
32
+ path: `${LIB_DIR}/${file.name}`,
33
+ content: file.content
34
+ })) : [],
35
+ ...options.env === void 0 ? [] : envLibFiles(options.env, LIB_DIR)
36
+ ];
37
+
38
+ //#endregion
39
+ export { LIB_DIR, libFiles };
@@ -0,0 +1,9 @@
1
+ //#region src/log-lib.generated.ts
2
+ /** The logging library's files, embedded so a build needs no asset on disk. */
3
+ const LOG_LIB_FILES = [{
4
+ name: "log.sh",
5
+ content: "# shellcheck shell=sh\n# pluginfinity logging. `pluginfinity build` writes this file into every\n# target at lib/pluginfinity/log.sh; do not edit a copy under builds/, the next\n# build overwrites it.\n#\n# POSIX sh. Writes nothing to stdout. Set _pf_log_dir to this file's directory,\n# source it, then call pf_log / pf_debug. From a skill script:\n# _pf_log_dir=\"$(dirname \"$0\")/../../../lib/pluginfinity\"; . \"$_pf_log_dir/log.sh\"\n#\n# Lines go to ${XDG_STATE_HOME:-$HOME/.local/state}/pluginfinity/<plugin>/error.log\n# and, when PLUGINFINITY_DEBUG=1, debug.log, as\n# <ISO-8601 UTC> [<host>] <component>/<script>: <message>\n\n# POSIX sh cannot find a sourced file's own path, so the sourcer sets\n# _pf_log_dir first. host.sh there names the host and plugin.\nif [ -z \"${PLUGINFINITY_PLUGIN:-}\" ] && [ -n \"${_pf_log_dir:-}\" ] && [ -f \"$_pf_log_dir/host.sh\" ]; then\n # shellcheck source=/dev/null\n . \"$_pf_log_dir/host.sh\" 2>/dev/null || :\nfi\n\n_pf_log_write() { # file component message\n _pf_d=\"${XDG_STATE_HOME:-${HOME:-/nonexistent}/.local/state}/pluginfinity/${PLUGINFINITY_PLUGIN:-unknown}\"\n mkdir -p \"$_pf_d\" 2>/dev/null || return 0\n printf '%s [%s] %s/%s: %s\\n' \"$(date -u +%Y-%m-%dT%H:%M:%SZ)\" \"${PLUGINFINITY_HOST:-unknown}\" \\\n \"$2\" \"$(basename \"$0\")\" \"$3\" >>\"$_pf_d/$1\" 2>/dev/null || return 0\n}\n\n# True when PLUGINFINITY_DEBUG=1.\npf_debug_on() { [ \"${PLUGINFINITY_DEBUG:-0}\" = 1 ]; }\n\n# pf_log <component> <message...>: append to error.log. Never fails.\npf_log() {\n _pf_c=${1:-}\n if [ $# -gt 0 ]; then shift; fi\n _pf_log_write error.log \"$_pf_c\" \"$*\"\n return 0\n}\n\n# pf_debug <component> <message...>: append to debug.log when PLUGINFINITY_DEBUG=1.\npf_debug() {\n pf_debug_on || return 0\n _pf_c=${1:-}\n if [ $# -gt 0 ]; then shift; fi\n _pf_log_write debug.log \"$_pf_c\" \"$*\"\n return 0\n}\n\nscript_log() { pf_log script \"$@\"; }\nscript_debug() { pf_debug script \"$@\"; }\n"
6
+ }];
7
+
8
+ //#endregion
9
+ export { LOG_LIB_FILES };