@powerhousedao/ph-cli 6.2.3-dev.58 → 6.2.3-dev.59

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 (49) hide show
  1. package/dist/{cli-connect-override-DGXyoqdV.mjs → cli-connect-override-65mFEDEB.mjs} +4 -4
  2. package/dist/{cli-connect-override-DGXyoqdV.mjs.map → cli-connect-override-65mFEDEB.mjs.map} +1 -1
  3. package/dist/cli.mjs +4 -4
  4. package/dist/{connect-build-EYGNSUc_.mjs → connect-build-D9zrBKG4.mjs} +4 -4
  5. package/dist/{connect-build-EYGNSUc_.mjs.map → connect-build-D9zrBKG4.mjs.map} +1 -1
  6. package/dist/{connect-config-BDmghUZF.mjs → connect-config-C1tf7DqD.mjs} +4 -4
  7. package/dist/{connect-config-BDmghUZF.mjs.map → connect-config-C1tf7DqD.mjs.map} +1 -1
  8. package/dist/{connect-studio-CM4t2tWz.mjs → connect-studio-BbsQuED_.mjs} +3 -3
  9. package/dist/{connect-studio-sc-e0xBI.mjs → connect-studio-Q93rzqnC.mjs} +4 -4
  10. package/dist/{connect-studio-sc-e0xBI.mjs.map → connect-studio-Q93rzqnC.mjs.map} +1 -1
  11. package/dist/{dist-BVyjAjXL.mjs → dist-D5lAfbKQ.mjs} +55 -5
  12. package/dist/dist-D5lAfbKQ.mjs.map +1 -0
  13. package/dist/explain-BHB_4rJ3.mjs +27 -0
  14. package/dist/explain-BHB_4rJ3.mjs.map +1 -0
  15. package/dist/host-schemas-CL_wFpY7-DOvIjrBA.mjs +478 -0
  16. package/dist/host-schemas-CL_wFpY7-DOvIjrBA.mjs.map +1 -0
  17. package/dist/{index-s1ABBFjB.d.mts → index-CApW1xbO.d.mts} +3 -3
  18. package/dist/{index-s1ABBFjB.d.mts.map → index-CApW1xbO.d.mts.map} +1 -1
  19. package/dist/ph-cli-commands-BxKtXZgb.mjs +4 -0
  20. package/dist/{ph-cli-commands-D5W9l8Or.mjs → ph-cli-commands-DGOKk392.mjs} +21 -8
  21. package/dist/{ph-cli-commands-D5W9l8Or.mjs.map → ph-cli-commands-DGOKk392.mjs.map} +1 -1
  22. package/dist/{host-schemas-C_MLcYX6-B2qQIdZ-.mjs → plugins-DtJUVtyg.mjs} +200 -308
  23. package/dist/plugins-DtJUVtyg.mjs.map +1 -0
  24. package/dist/reactor-env-D9p2G8jW.mjs +4 -0
  25. package/dist/{reactor-env-CtavpGtJ.mjs → reactor-env-Da_bfekg.mjs} +4 -4
  26. package/dist/{reactor-env-CtavpGtJ.mjs.map → reactor-env-Da_bfekg.mjs.map} +1 -1
  27. package/dist/{run-sugar-Dqn7up5U.mjs → run-sugar-Dq3ZrLL_.mjs} +4 -4
  28. package/dist/{run-sugar-Dqn7up5U.mjs.map → run-sugar-Dq3ZrLL_.mjs.map} +1 -1
  29. package/dist/runners/compound.d.mts +40 -3
  30. package/dist/runners/compound.d.mts.map +1 -1
  31. package/dist/runners/compound.mjs +6 -5
  32. package/dist/runners/compound.mjs.map +1 -1
  33. package/dist/runners/connect.d.mts +49 -5
  34. package/dist/runners/connect.d.mts.map +1 -1
  35. package/dist/runners/connect.mjs +57 -12
  36. package/dist/runners/connect.mjs.map +1 -1
  37. package/dist/runners/switchboard.d.mts +48 -5
  38. package/dist/runners/switchboard.d.mts.map +1 -1
  39. package/dist/runners/switchboard.mjs +62 -17
  40. package/dist/runners/switchboard.mjs.map +1 -1
  41. package/dist/{start-run-CAgkeWI1.mjs → start-run-DsZRHbM1.mjs} +4 -4
  42. package/dist/{start-run-CAgkeWI1.mjs.map → start-run-DsZRHbM1.mjs.map} +1 -1
  43. package/dist/{vetra-BY-MHg9R.mjs → vetra-BNJZ5LHN.mjs} +6 -6
  44. package/dist/{vetra-BY-MHg9R.mjs.map → vetra-BNJZ5LHN.mjs.map} +1 -1
  45. package/package.json +12 -12
  46. package/dist/dist-BVyjAjXL.mjs.map +0 -1
  47. package/dist/host-schemas-C_MLcYX6-B2qQIdZ-.mjs.map +0 -1
  48. package/dist/ph-cli-commands-DGLyiuvW.mjs +0 -4
  49. package/dist/reactor-env-BXG9PlMa.mjs +0 -4
@@ -1,9 +1,5 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="bc5cf4d9-5c7c-5994-8593-ac0a839008ee")}catch(e){}}();
3
- import { createRequire } from "node:module";
4
- import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
5
- import path from "node:path";
6
- import { pathToFileURL } from "node:url";
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="8948eb3e-0a18-5df6-b283-b8271fb9f8ba")}catch(e){}}();
7
3
  Object.freeze({ status: "aborted" });
8
4
  function $constructor(name, initializer, params) {
9
5
  function init(inst, def) {
@@ -429,6 +425,59 @@ function formatError(error, mapper = (issue) => issue.message) {
429
425
  processError(error);
430
426
  return fieldErrors;
431
427
  }
428
+ /** Format a ZodError as a human-readable string in the following form.
429
+ *
430
+ * From
431
+ *
432
+ * ```ts
433
+ * ZodError {
434
+ * issues: [
435
+ * {
436
+ * expected: 'string',
437
+ * code: 'invalid_type',
438
+ * path: [ 'username' ],
439
+ * message: 'Invalid input: expected string'
440
+ * },
441
+ * {
442
+ * expected: 'number',
443
+ * code: 'invalid_type',
444
+ * path: [ 'favoriteNumbers', 1 ],
445
+ * message: 'Invalid input: expected number'
446
+ * }
447
+ * ];
448
+ * }
449
+ * ```
450
+ *
451
+ * to
452
+ *
453
+ * ```
454
+ * username
455
+ * ✖ Expected number, received string at "username
456
+ * favoriteNumbers[0]
457
+ * ✖ Invalid input: expected number
458
+ * ```
459
+ */
460
+ function toDotPath(_path) {
461
+ const segs = [];
462
+ const path = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
463
+ for (const seg of path) if (typeof seg === "number") segs.push(`[${seg}]`);
464
+ else if (typeof seg === "symbol") segs.push(`[${JSON.stringify(String(seg))}]`);
465
+ else if (/[^\w$]/.test(seg)) segs.push(`[${JSON.stringify(seg)}]`);
466
+ else {
467
+ if (segs.length) segs.push(".");
468
+ segs.push(seg);
469
+ }
470
+ return segs.join("");
471
+ }
472
+ function prettifyError(error) {
473
+ const lines = [];
474
+ const issues = [...error.issues].sort((a, b) => (a.path ?? []).length - (b.path ?? []).length);
475
+ for (const issue of issues) {
476
+ lines.push(`✖ ${issue.message}`);
477
+ if (issue.path?.length) lines.push(` → at ${toDotPath(issue.path)}`);
478
+ }
479
+ return lines.join("\n");
480
+ }
432
481
  //#endregion
433
482
  //#region ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/parse.js
434
483
  const _parse = (_Err) => (schema, value, _ctx, _params) => {
@@ -1886,6 +1935,24 @@ const $ZodEnum = /*@__PURE__*/ $constructor("$ZodEnum", (inst, def) => {
1886
1935
  return payload;
1887
1936
  };
1888
1937
  });
1938
+ const $ZodLiteral = /*@__PURE__*/ $constructor("$ZodLiteral", (inst, def) => {
1939
+ $ZodType.init(inst, def);
1940
+ if (def.values.length === 0) throw new Error("Cannot create literal schema with no valid values");
1941
+ const values = new Set(def.values);
1942
+ inst._zod.values = values;
1943
+ inst._zod.pattern = new RegExp(`^(${def.values.map((o) => typeof o === "string" ? escapeRegex(o) : o ? escapeRegex(o.toString()) : String(o)).join("|")})$`);
1944
+ inst._zod.parse = (payload, _ctx) => {
1945
+ const input = payload.value;
1946
+ if (values.has(input)) return payload;
1947
+ payload.issues.push({
1948
+ code: "invalid_value",
1949
+ values: def.values,
1950
+ input,
1951
+ inst
1952
+ });
1953
+ return payload;
1954
+ };
1955
+ });
1889
1956
  const $ZodTransform = /*@__PURE__*/ $constructor("$ZodTransform", (inst, def) => {
1890
1957
  $ZodType.init(inst, def);
1891
1958
  inst._zod.parse = (payload, ctx) => {
@@ -2674,7 +2741,7 @@ function initializeContext(params) {
2674
2741
  external: params?.external ?? void 0
2675
2742
  };
2676
2743
  }
2677
- function process$1(schema, ctx, _params = {
2744
+ function process(schema, ctx, _params = {
2678
2745
  path: [],
2679
2746
  schemaPath: []
2680
2747
  }) {
@@ -2711,7 +2778,7 @@ function process$1(schema, ctx, _params = {
2711
2778
  const parent = schema._zod.parent;
2712
2779
  if (parent) {
2713
2780
  if (!result.ref) result.ref = parent;
2714
- process$1(parent, ctx, params);
2781
+ process(parent, ctx, params);
2715
2782
  ctx.seen.get(parent).isParent = true;
2716
2783
  }
2717
2784
  }
@@ -2925,7 +2992,7 @@ const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
2925
2992
  ...params,
2926
2993
  processors
2927
2994
  });
2928
- process$1(schema, ctx);
2995
+ process(schema, ctx);
2929
2996
  extractDefs(ctx, schema);
2930
2997
  return finalize(ctx, schema);
2931
2998
  };
@@ -2937,7 +3004,7 @@ const createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params)
2937
3004
  io,
2938
3005
  processors
2939
3006
  });
2940
- process$1(schema, ctx);
3007
+ process(schema, ctx);
2941
3008
  extractDefs(ctx, schema);
2942
3009
  return finalize(ctx, schema);
2943
3010
  };
@@ -3017,6 +3084,28 @@ const enumProcessor = (schema, _ctx, json, _params) => {
3017
3084
  if (values.every((v) => typeof v === "string")) json.type = "string";
3018
3085
  json.enum = values;
3019
3086
  };
3087
+ const literalProcessor = (schema, ctx, json, _params) => {
3088
+ const def = schema._zod.def;
3089
+ const vals = [];
3090
+ for (const val of def.values) if (val === void 0) {
3091
+ if (ctx.unrepresentable === "throw") throw new Error("Literal `undefined` cannot be represented in JSON Schema");
3092
+ } else if (typeof val === "bigint") {
3093
+ if (ctx.unrepresentable === "throw") throw new Error("BigInt literals cannot be represented in JSON Schema");
3094
+ else vals.push(Number(val));
3095
+ } else vals.push(val);
3096
+ if (vals.length === 0) {} else if (vals.length === 1) {
3097
+ const val = vals[0];
3098
+ json.type = val === null ? "null" : typeof val;
3099
+ if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") json.enum = [val];
3100
+ else json.const = val;
3101
+ } else {
3102
+ if (vals.every((v) => typeof v === "number")) json.type = "number";
3103
+ if (vals.every((v) => typeof v === "string")) json.type = "string";
3104
+ if (vals.every((v) => typeof v === "boolean")) json.type = "boolean";
3105
+ if (vals.every((v) => v === null)) json.type = "null";
3106
+ json.enum = vals;
3107
+ }
3108
+ };
3020
3109
  const customProcessor = (_schema, ctx, _json, _params) => {
3021
3110
  if (ctx.unrepresentable === "throw") throw new Error("Custom types cannot be represented in JSON Schema");
3022
3111
  };
@@ -3030,7 +3119,7 @@ const arrayProcessor = (schema, ctx, _json, params) => {
3030
3119
  if (typeof minimum === "number") json.minItems = minimum;
3031
3120
  if (typeof maximum === "number") json.maxItems = maximum;
3032
3121
  json.type = "array";
3033
- json.items = process$1(def.element, ctx, {
3122
+ json.items = process(def.element, ctx, {
3034
3123
  ...params,
3035
3124
  path: [...params.path, "items"]
3036
3125
  });
@@ -3041,7 +3130,7 @@ const objectProcessor = (schema, ctx, _json, params) => {
3041
3130
  json.type = "object";
3042
3131
  json.properties = {};
3043
3132
  const shape = def.shape;
3044
- for (const key in shape) json.properties[key] = process$1(shape[key], ctx, {
3133
+ for (const key in shape) json.properties[key] = process(shape[key], ctx, {
3045
3134
  ...params,
3046
3135
  path: [
3047
3136
  ...params.path,
@@ -3059,7 +3148,7 @@ const objectProcessor = (schema, ctx, _json, params) => {
3059
3148
  if (def.catchall?._zod.def.type === "never") json.additionalProperties = false;
3060
3149
  else if (!def.catchall) {
3061
3150
  if (ctx.io === "output") json.additionalProperties = false;
3062
- } else if (def.catchall) json.additionalProperties = process$1(def.catchall, ctx, {
3151
+ } else if (def.catchall) json.additionalProperties = process(def.catchall, ctx, {
3063
3152
  ...params,
3064
3153
  path: [...params.path, "additionalProperties"]
3065
3154
  });
@@ -3067,7 +3156,7 @@ const objectProcessor = (schema, ctx, _json, params) => {
3067
3156
  const unionProcessor = (schema, ctx, json, params) => {
3068
3157
  const def = schema._zod.def;
3069
3158
  const isExclusive = def.inclusive === false;
3070
- const options = def.options.map((x, i) => process$1(x, ctx, {
3159
+ const options = def.options.map((x, i) => process(x, ctx, {
3071
3160
  ...params,
3072
3161
  path: [
3073
3162
  ...params.path,
@@ -3080,7 +3169,7 @@ const unionProcessor = (schema, ctx, json, params) => {
3080
3169
  };
3081
3170
  const intersectionProcessor = (schema, ctx, json, params) => {
3082
3171
  const def = schema._zod.def;
3083
- const a = process$1(def.left, ctx, {
3172
+ const a = process(def.left, ctx, {
3084
3173
  ...params,
3085
3174
  path: [
3086
3175
  ...params.path,
@@ -3088,7 +3177,7 @@ const intersectionProcessor = (schema, ctx, json, params) => {
3088
3177
  0
3089
3178
  ]
3090
3179
  });
3091
- const b = process$1(def.right, ctx, {
3180
+ const b = process(def.right, ctx, {
3092
3181
  ...params,
3093
3182
  path: [
3094
3183
  ...params.path,
@@ -3106,7 +3195,7 @@ const recordProcessor = (schema, ctx, _json, params) => {
3106
3195
  const keyType = def.keyType;
3107
3196
  const patterns = keyType._zod.bag?.patterns;
3108
3197
  if (def.mode === "loose" && patterns && patterns.size > 0) {
3109
- const valueSchema = process$1(def.valueType, ctx, {
3198
+ const valueSchema = process(def.valueType, ctx, {
3110
3199
  ...params,
3111
3200
  path: [
3112
3201
  ...params.path,
@@ -3117,11 +3206,11 @@ const recordProcessor = (schema, ctx, _json, params) => {
3117
3206
  json.patternProperties = {};
3118
3207
  for (const pattern of patterns) json.patternProperties[pattern.source] = valueSchema;
3119
3208
  } else {
3120
- if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") json.propertyNames = process$1(def.keyType, ctx, {
3209
+ if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") json.propertyNames = process(def.keyType, ctx, {
3121
3210
  ...params,
3122
3211
  path: [...params.path, "propertyNames"]
3123
3212
  });
3124
- json.additionalProperties = process$1(def.valueType, ctx, {
3213
+ json.additionalProperties = process(def.valueType, ctx, {
3125
3214
  ...params,
3126
3215
  path: [...params.path, "additionalProperties"]
3127
3216
  });
@@ -3134,7 +3223,7 @@ const recordProcessor = (schema, ctx, _json, params) => {
3134
3223
  };
3135
3224
  const nullableProcessor = (schema, ctx, json, params) => {
3136
3225
  const def = schema._zod.def;
3137
- const inner = process$1(def.innerType, ctx, params);
3226
+ const inner = process(def.innerType, ctx, params);
3138
3227
  const seen = ctx.seen.get(schema);
3139
3228
  if (ctx.target === "openapi-3.0") {
3140
3229
  seen.ref = def.innerType;
@@ -3143,27 +3232,27 @@ const nullableProcessor = (schema, ctx, json, params) => {
3143
3232
  };
3144
3233
  const nonoptionalProcessor = (schema, ctx, _json, params) => {
3145
3234
  const def = schema._zod.def;
3146
- process$1(def.innerType, ctx, params);
3235
+ process(def.innerType, ctx, params);
3147
3236
  const seen = ctx.seen.get(schema);
3148
3237
  seen.ref = def.innerType;
3149
3238
  };
3150
3239
  const defaultProcessor = (schema, ctx, json, params) => {
3151
3240
  const def = schema._zod.def;
3152
- process$1(def.innerType, ctx, params);
3241
+ process(def.innerType, ctx, params);
3153
3242
  const seen = ctx.seen.get(schema);
3154
3243
  seen.ref = def.innerType;
3155
3244
  json.default = JSON.parse(JSON.stringify(def.defaultValue));
3156
3245
  };
3157
3246
  const prefaultProcessor = (schema, ctx, json, params) => {
3158
3247
  const def = schema._zod.def;
3159
- process$1(def.innerType, ctx, params);
3248
+ process(def.innerType, ctx, params);
3160
3249
  const seen = ctx.seen.get(schema);
3161
3250
  seen.ref = def.innerType;
3162
3251
  if (ctx.io === "input") json._prefault = JSON.parse(JSON.stringify(def.defaultValue));
3163
3252
  };
3164
3253
  const catchProcessor = (schema, ctx, json, params) => {
3165
3254
  const def = schema._zod.def;
3166
- process$1(def.innerType, ctx, params);
3255
+ process(def.innerType, ctx, params);
3167
3256
  const seen = ctx.seen.get(schema);
3168
3257
  seen.ref = def.innerType;
3169
3258
  let catchValue;
@@ -3177,20 +3266,20 @@ const catchProcessor = (schema, ctx, json, params) => {
3177
3266
  const pipeProcessor = (schema, ctx, _json, params) => {
3178
3267
  const def = schema._zod.def;
3179
3268
  const innerType = ctx.io === "input" ? def.in._zod.def.type === "transform" ? def.out : def.in : def.out;
3180
- process$1(innerType, ctx, params);
3269
+ process(innerType, ctx, params);
3181
3270
  const seen = ctx.seen.get(schema);
3182
3271
  seen.ref = innerType;
3183
3272
  };
3184
3273
  const readonlyProcessor = (schema, ctx, json, params) => {
3185
3274
  const def = schema._zod.def;
3186
- process$1(def.innerType, ctx, params);
3275
+ process(def.innerType, ctx, params);
3187
3276
  const seen = ctx.seen.get(schema);
3188
3277
  seen.ref = def.innerType;
3189
3278
  json.readOnly = true;
3190
3279
  };
3191
3280
  const optionalProcessor = (schema, ctx, _json, params) => {
3192
3281
  const def = schema._zod.def;
3193
- process$1(def.innerType, ctx, params);
3282
+ process(def.innerType, ctx, params);
3194
3283
  const seen = ctx.seen.get(schema);
3195
3284
  seen.ref = def.innerType;
3196
3285
  };
@@ -3686,6 +3775,23 @@ function _enum(values, params) {
3686
3775
  ...normalizeParams(params)
3687
3776
  });
3688
3777
  }
3778
+ const ZodLiteral = /*@__PURE__*/ $constructor("ZodLiteral", (inst, def) => {
3779
+ $ZodLiteral.init(inst, def);
3780
+ ZodType.init(inst, def);
3781
+ inst._zod.processJSONSchema = (ctx, json, params) => literalProcessor(inst, ctx, json, params);
3782
+ inst.values = new Set(def.values);
3783
+ Object.defineProperty(inst, "value", { get() {
3784
+ if (def.values.length > 1) throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");
3785
+ return def.values[0];
3786
+ } });
3787
+ });
3788
+ function literal(value, params) {
3789
+ return new ZodLiteral({
3790
+ type: "literal",
3791
+ values: Array.isArray(value) ? value : [value],
3792
+ ...normalizeParams(params)
3793
+ });
3794
+ }
3689
3795
  const ZodTransform = /*@__PURE__*/ $constructor("ZodTransform", (inst, def) => {
3690
3796
  $ZodTransform.init(inst, def);
3691
3797
  ZodType.init(inst, def);
@@ -3850,305 +3956,91 @@ function superRefine(fn) {
3850
3956
  return /* @__PURE__ */ _superRefine(fn);
3851
3957
  }
3852
3958
  //#endregion
3853
- //#region ../../packages/host-core/dist/host-schemas-C_MLcYX6.mjs
3854
- /**
3855
- * Instance-fact projection for compound hosts: the drives a compound's
3856
- * reactor member created, projected into the Connect member's runtime-config
3857
- * override. Pure functions, moved from ph-cli's vetra service so the generic
3858
- * compound and the classic path share one implementation.
3859
- */
3860
- function isLocalDrive(drive) {
3861
- return "local" in drive;
3862
- }
3863
- const driveKey = (drive) => isLocalDrive(drive) ? `local:${drive.id}` : drive.url;
3864
- /**
3865
- * Concatenate groups of `connect.drives.defaultDrives` in the order given,
3866
- * de-duplicating by drive identity (URL for remote entries, id for local
3867
- * ones). The first occurrence of a drive wins, so earlier groups keep their
3868
- * position and metadata — e.g. the Vetra drive `ph vetra` starts stays first
3869
- * even when the project's `powerhouse.config.json` lists the same drive.
3870
- */
3871
- function mergeDefaultDrives(...groups) {
3872
- const seen = /* @__PURE__ */ new Set();
3873
- const out = [];
3874
- for (const group of groups) for (const drive of group) {
3875
- const key = driveKey(drive);
3876
- if (seen.has(key)) continue;
3877
- seen.add(key);
3878
- out.push(drive);
3879
- }
3880
- return out;
3881
- }
3959
+ //#region ../../packages/host-core/dist/plugins.mjs
3882
3960
  /**
3883
- * Rebase a local drive URL onto a public base: keeps the /d/<slug> path,
3884
- * swaps the loopback origin for the public base. Browser clients behind a
3885
- * reverse proxy can't reach http://localhost:<port>. Non-loopback URLs
3886
- * (e.g. a remote drive) are already public and pass through unchanged, as do
3887
- * unparseable ones.
3888
- */
3889
- function rebaseDriveUrl(driveUrl, publicBase) {
3890
- let url;
3891
- try {
3892
- url = new URL(driveUrl);
3893
- } catch {
3894
- return driveUrl;
3895
- }
3896
- if (![
3897
- "localhost",
3898
- "127.0.0.1",
3899
- "[::1]"
3900
- ].includes(url.hostname)) return driveUrl;
3901
- return `${publicBase.replace(/\/+$/, "")}${url.pathname}`;
3902
- }
3903
- /**
3904
- * The compound's drives projection: created drives first (rebased onto the
3905
- * public base when given), then the project's configured drives, de-duplicated
3906
- * — and `preserve-all`, because compound-injected drive lists change per
3907
- * launch context and must never detach drives the user added by hand.
3908
- */
3909
- function projectDrivesIntoConnect(input) {
3910
- return { drives: {
3911
- defaultDrives: mergeDefaultDrives(input.createdDriveUrls.filter((url) => typeof url === "string" && url.length > 0).map((url) => ({
3912
- url: input.publicBase ? rebaseDriveUrl(url, input.publicBase) : url,
3913
- name: null,
3914
- icon: null
3915
- })), input.configuredDefaultDrives ?? []),
3916
- preserveStrategy: "preserve-all"
3917
- } };
3918
- }
3919
- /**
3920
- * Loads and pre-validates a `hosts/<name>/host.js` definition.
3961
+ * R1 — the host plugin framework (bridge-runners-to-plugins plan,
3962
+ * customization-references/host-core as the blueprint).
3921
3963
  *
3922
- * A host file is a static PROJECTION of powerhouse.config.json: plain ESM,
3923
- * default-exporting a data object. Three gates run before any runner sees it:
3924
- * 1. import lint — the only legal import is the project's
3925
- * powerhouse.config.json (host files are data, not programs);
3926
- * 2. static check — the exported object must survive a JSON round trip
3927
- * (functions, undefined, class instances, Dates etc. are rejected,
3928
- * reporting the offending path);
3929
- * 3. shape pre-check — `name`, `runner.module`, and the reactor XOR children
3930
- * rule. Full validation is the runner's `hostSchema` (phase 2).
3964
+ * A plugin is hooks + contributions; hooks are boot wiring (main realm only),
3965
+ * contributions are declarative, serializable surface. Host RUNTIMES define
3966
+ * the hook vocabulary and interleave their own wiring between stages — they
3967
+ * are never plugins themselves.
3931
3968
  *
3932
- * This module never exits the process — callers own error presentation.
3969
+ * host.js carries the COMPOSITION as `runner.plugins` entries:
3970
+ * string | { module, enabled?, verbs?, config? }
3971
+ * Presence is activation (enabled defaults true); `verbs` scopes an entry to
3972
+ * matching run verbs; `config` is validated against the plugin's declared
3973
+ * zod schema. Entries resolve from the PROJECT's dependency tree exactly
3974
+ * like runner modules.
3933
3975
  */
3934
- const HOST_FILE = "host.js";
3935
- const CONFIG_IMPORT_SUFFIX = "powerhouse.config.json";
3936
- var HostLoadError = class extends Error {
3976
+ var PluginError = class extends Error {
3937
3977
  constructor(message, hint) {
3938
3978
  super(hint ? `${message}\n Hint: ${hint}` : message);
3939
- this.name = "HostLoadError";
3979
+ this.name = "PluginError";
3940
3980
  }
3941
3981
  };
3942
- /** A `hosts/` folder with no `<name>/host.js` inside is "empty" — the guard
3943
- * state: callers warn loudly and fall back to legacy rather than activating
3944
- * the new architecture off a stray `mkdir hosts`. */
3945
- function probeHostsFolder(projectRoot) {
3946
- const dir = path.join(projectRoot, "hosts");
3947
- if (!existsSync(dir) || !statSync(dir).isDirectory()) return { kind: "absent" };
3948
- const hosts = readdirSync(dir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && existsSync(path.join(dir, entry.name, HOST_FILE))).map((entry) => entry.name).sort();
3949
- return hosts.length === 0 ? {
3950
- kind: "empty",
3951
- dir
3952
- } : {
3953
- kind: "present",
3954
- dir,
3955
- hosts
3982
+ const pluginEntryObjectSchema = strictObject({
3983
+ module: string().min(1),
3984
+ /** Presence is activation BY DEFAULT; false is the explicit off-switch. */
3985
+ enabled: boolean().optional(),
3986
+ /** "*" (default) or the run verbs this entry is active for. */
3987
+ verbs: union([literal("*"), array(string().min(1)).min(1)]).optional(),
3988
+ /** Validated against the plugin's declared configSchema at resolution. */
3989
+ config: record(string(), unknown()).optional()
3990
+ });
3991
+ const pluginEntrySchema = union([string().min(1), pluginEntryObjectSchema]);
3992
+ function normalizePluginEntry(entry) {
3993
+ if (typeof entry === "string") return {
3994
+ module: entry,
3995
+ enabled: true,
3996
+ verbs: "*",
3997
+ config: {}
3998
+ };
3999
+ return {
4000
+ module: entry.module,
4001
+ enabled: entry.enabled ?? true,
4002
+ verbs: entry.verbs ?? "*",
4003
+ config: entry.config ?? {}
3956
4004
  };
3957
4005
  }
3958
- /** Rejects every import except the project's powerhouse.config.json, plus any
3959
- * dynamic `import(...)` or `require(...)`. Source-level enforcement: the JSON
3960
- * round trip below is the hard gate; this one produces the better error. */
3961
- function lintHostImports(source, file) {
3962
- for (const match of source.matchAll(/^\s*import\b[^;'"]*?from\s+["']([^"']+)["']/gm)) {
3963
- const specifier = match[1];
3964
- if (!specifier.endsWith(CONFIG_IMPORT_SUFFIX)) throw new HostLoadError(`${file} imports "${specifier}" — a host file may only import the project's powerhouse.config.json.`, "Host files are static projections; code belongs in plugins.js or the runner.");
3965
- }
3966
- if (/^\s*import\s+["']/m.test(source)) throw new HostLoadError(`${file} contains a side-effect import — a host file may only import the project's powerhouse.config.json.`);
3967
- if (/\bimport\s*\(/.test(source) || /\brequire\s*\(/.test(source)) throw new HostLoadError(`${file} uses dynamic import()/require() — host files are static data.`);
3968
- }
3969
- /** Returns the path of the first value that would not survive a JSON round
3970
- * trip, or undefined when the object is fully static. */
3971
- function findNonStaticValue(value, trail = "") {
3972
- if (value === null) return void 0;
3973
- const kind = typeof value;
3974
- if (kind === "string" || kind === "number" || kind === "boolean") return;
3975
- if (kind !== "object") return `${trail || "<root>"} (${kind})`;
3976
- if (Array.isArray(value)) {
3977
- for (let i = 0; i < value.length; i++) {
3978
- const hit = findNonStaticValue(value[i], `${trail}[${i}]`);
3979
- if (hit) return hit;
3980
- }
3981
- return;
3982
- }
3983
- const proto = Object.getPrototypeOf(value);
3984
- if (proto !== Object.prototype && proto !== null) return `${trail || "<root>"} (non-plain object)`;
3985
- for (const [key, child] of Object.entries(value)) {
3986
- const hit = findNonStaticValue(child, trail ? `${trail}.${key}` : key);
3987
- if (hit) return hit;
4006
+ /** Module is the identity key: a duplicate makes override targeting and
4007
+ * ordering ambiguous, so it fails loudly. */
4008
+ function normalizePluginEntries(entries, where) {
4009
+ const normalized = entries.map(normalizePluginEntry);
4010
+ const seen = /* @__PURE__ */ new Set();
4011
+ for (const entry of normalized) {
4012
+ if (seen.has(entry.module)) throw new PluginError(`${where}: plugin "${entry.module}" is listed twice.`, "Module specifiers are the identity key of a composition; a plugin meant to run twice needs distinct subpath specifiers.");
4013
+ seen.add(entry.module);
3988
4014
  }
4015
+ return normalized;
3989
4016
  }
3990
- function assertHostShape(host, file) {
3991
- if (typeof host.name !== "string" || host.name.length === 0) throw new HostLoadError(`${file}: \`name\` must be a non-empty string.`);
3992
- const runner = host.runner;
3993
- if (runner === null || typeof runner !== "object" || typeof runner.module !== "string") throw new HostLoadError(`${file}: \`runner\` must be an object with a \`module\` specifier string.`);
3994
- if (host.reactor !== void 0 && host.children !== void 0) throw new HostLoadError(`${file}: \`reactor\` and \`children\` are mutually exclusive — a host is a reactor runner or a compound runner, never both.`);
3995
- }
3996
- async function loadHost(projectRoot, hostName) {
3997
- const probe = probeHostsFolder(projectRoot);
3998
- if (probe.kind === "absent") throw new HostLoadError(`No hosts/ folder found in ${projectRoot}.`, "Scaffold one with `ph init --uniform-runners` (or create hosts/<name>/host.js).");
3999
- if (probe.kind === "empty") throw new HostLoadError(`hosts/ exists at ${probe.dir} but contains no <name>/host.js.`, "An empty hosts/ folder does not activate the uniform-runners architecture; add a host definition or remove the folder.");
4000
- if (!probe.hosts.includes(hostName)) throw new HostLoadError(`Unknown host "${hostName}". Available hosts: ${probe.hosts.join(", ")}.`);
4001
- const file = path.join(probe.dir, hostName, HOST_FILE);
4002
- lintHostImports(readFileSync(file, "utf8"), file);
4003
- const host = (await import(pathToFileURL(file).href)).default;
4004
- if (host === null || typeof host !== "object" || Array.isArray(host)) throw new HostLoadError(`${file} must default-export the host object (\`export default { name, runner, ... }\`).`);
4005
- const nonStatic = findNonStaticValue(host);
4006
- if (nonStatic) throw new HostLoadError(`${file} exports a non-static value at \`${nonStatic}\` — host files must survive a JSON round trip.`, "Runtime behavior belongs in the runner; host files only carry data.");
4007
- assertHostShape(host, file);
4008
- return {
4009
- name: hostName,
4010
- dir: path.dirname(file),
4011
- file,
4012
- host
4013
- };
4017
+ function entryActiveForVerb(entry, verb) {
4018
+ if (!entry.enabled) return false;
4019
+ return entry.verbs === "*" || entry.verbs.includes(verb);
4014
4020
  }
4015
4021
  /**
4016
- * Resolves a host's `runner.module` specifier from the PROJECT's dependency
4017
- * tree (not ph-cli's), imports it, and checks the runner-module contract:
4018
- * `{ run, hostSchema, kind, ...optionalVerbs }`. Phase-0 home is ph-cli; the
4019
- * uniform-runners plan moves this into @powerhousedao/host-core with the
4020
- * generic compound (phase 1).
4022
+ * The appliesTo hierarchy. "reactor" is the base every reactor host extends;
4023
+ * "compound" is its own branch (plugins over the member set — e.g. the clint
4024
+ * proxy). Host runtimes register their id with a parent; compatibility walks
4025
+ * the parent chain.
4021
4026
  */
4022
- var RunnerError = class extends Error {
4023
- constructor(message, hint) {
4024
- super(hint ? `${message}\n Hint: ${hint}` : message);
4025
- this.name = "RunnerError";
4026
- }
4027
+ const HOST_TYPE_PARENTS = {
4028
+ reactor: null,
4029
+ compound: null,
4030
+ connect: "reactor",
4031
+ switchboard: "reactor",
4032
+ mastra: "reactor"
4027
4033
  };
4028
- /** Exports that are part of the contract but are not verbs. */
4029
- const NON_VERB_EXPORTS = /* @__PURE__ */ new Set([
4030
- "hostSchema",
4031
- "kind",
4032
- "default"
4033
- ]);
4034
- async function resolveRunnerModule(projectRoot, specifier) {
4035
- const projectRequire = createRequire(pathToFileURL(path.join(projectRoot, "package.json")).href);
4036
- let resolved;
4037
- try {
4038
- resolved = projectRequire.resolve(specifier);
4039
- } catch {
4040
- throw new RunnerError(`Cannot resolve runner module "${specifier}" from ${projectRoot}.`, "The runner must be a dependency of the project (install it, then retry).");
4034
+ function hostTypeSatisfies(hostType, appliesTo) {
4035
+ let current = hostType;
4036
+ while (current !== null) {
4037
+ if (current === appliesTo) return true;
4038
+ current = current in HOST_TYPE_PARENTS ? HOST_TYPE_PARENTS[current] : null;
4041
4039
  }
4042
- const module = await import(pathToFileURL(resolved).href);
4043
- if (typeof module.run !== "function") throw new RunnerError(`Runner "${specifier}" does not export a \`run\` function (required verb).`);
4044
- const hostSchema = module.hostSchema;
4045
- if (!hostSchema || typeof hostSchema.safeParse !== "function") throw new RunnerError(`Runner "${specifier}" does not export a \`hostSchema\` — runners validate their own host shape.`);
4046
- if (typeof module.kind !== "string") throw new RunnerError(`Runner "${specifier}" does not export \`kind\` (e.g. "reactor" | "compound").`);
4047
- return module;
4048
- }
4049
- function listVerbs(runner) {
4050
- return Object.entries(runner).filter(([name, value]) => typeof value === "function" && !NON_VERB_EXPORTS.has(name)).map(([name]) => name).sort();
4051
- }
4052
- function getVerb(runner, specifier, verb) {
4053
- const candidate = runner[verb];
4054
- if (typeof candidate !== "function" || NON_VERB_EXPORTS.has(verb)) throw new RunnerError(`Runner "${specifier}" does not support the verb "${verb}". Supported verbs: ${listVerbs(runner).join(", ")}.`);
4055
- return candidate;
4056
- }
4057
- function validateHost(runner, specifier, host, file) {
4058
- const result = runner.hostSchema.safeParse(host);
4059
- if (!result.success) throw new RunnerError(`${file} failed validation against the hostSchema of "${specifier}":\n${(result.error?.issues ?? []).map((issue) => ` - ${issue.path.join(".") || "<root>"}: ${issue.message}`).join("\n") || " (no details reported)"}`);
4040
+ return false;
4060
4041
  }
4061
- /**
4062
- * The shared zod schemas for host.js blocks (D2.a). The `reactor` block
4063
- * validates STRICTLY (D2.d — phase 0's tolerated-unknown-keys notice ends
4064
- * here): a typo'd protocol key must fail, not silently not-apply, because
4065
- * these are fleet-consensus settings. `config` stays loose — it is
4066
- * runner-defined by design.
4067
- */
4068
- const profileSchema = strictObject({
4069
- appId: string().min(1).optional(),
4070
- name: string().min(1).optional(),
4071
- description: string().optional(),
4072
- icon: string().optional()
4073
- }).optional();
4074
- const reactorProtocolSchema = strictObject({
4075
- featureFlags: strictObject({
4076
- documentDecisions: boolean().optional(),
4077
- authEnforcement: boolean().optional(),
4078
- authGroups: boolean().optional(),
4079
- authConditions: boolean().optional()
4080
- }).optional(),
4081
- createSignaturePolicy: _enum(["legacy", "v2-required"]).optional(),
4082
- unsupportedStoredDocuments: _enum(["refuse", "read-only"]).optional()
4083
- });
4084
- const reactorBackendSchema = strictObject({
4085
- kind: _enum([
4086
- "in-process",
4087
- "worker",
4088
- "remote"
4089
- ]).optional(),
4090
- storage: strictObject({
4091
- kind: _enum([
4092
- "idb",
4093
- "memory",
4094
- "path",
4095
- "postgres"
4096
- ]),
4097
- dataDir: string().optional(),
4098
- url: string().optional()
4099
- }).optional(),
4100
- readModel: strictObject({ url: string().optional() }).optional(),
4101
- packages: strictObject({
4102
- cdnUrl: string().optional(),
4103
- specs: array(string()).optional(),
4104
- dynamic: boolean().optional()
4105
- }).optional(),
4106
- remote: strictObject({
4107
- host: string().optional(),
4108
- url: string().optional()
4109
- }).optional()
4110
- });
4111
- const reactorSchema = strictObject({
4112
- backends: record(string(), reactorBackendSchema).optional(),
4113
- placement: strictObject({
4114
- primary: string().optional(),
4115
- default: looseObject({}).optional()
4116
- }).optional(),
4117
- workflows: boolean().optional(),
4118
- protocol: reactorProtocolSchema.optional()
4119
- });
4120
- /** Common runner options every host.runner carries; runner modules extend it
4121
- * loosely with their own process options. */
4122
- const runnerBaseSchema = looseObject({
4123
- module: string().min(1),
4124
- defaultVerb: string().optional(),
4125
- port: number().int().positive().optional()
4126
- });
4127
- /** A compound's children map (mutually exclusive with `reactor` — the XOR is
4128
- * structural, enforced by the loader; schemas validate each side's shape). */
4129
- const childrenSchema = record(string(), strictObject({
4130
- host: string().min(1),
4131
- plugins: array(string()).optional(),
4132
- runner: looseObject({}).optional(),
4133
- config: looseObject({}).optional(),
4134
- reactor: reactorSchema.optional()
4135
- }));
4136
- looseObject({
4137
- name: string().min(1),
4138
- runner: runnerBaseSchema,
4139
- config: looseObject({}).optional(),
4140
- profile: profileSchema,
4141
- reactor: reactorSchema.optional()
4142
- });
4143
- looseObject({
4144
- name: string().min(1),
4145
- runner: runnerBaseSchema,
4146
- children: childrenSchema,
4147
- config: looseObject({}).optional(),
4148
- profile: profileSchema
4149
- });
4150
4042
  //#endregion
4151
- export { probeHostsFolder as a, reactorSchema as c, validateHost as d, boolean as f, string as h, mergeDefaultDrives as i, rebaseDriveUrl as l, number as m, getVerb as n, profileSchema as o, looseObject as p, loadHost as r, projectDrivesIntoConnect as s, childrenSchema as t, resolveRunnerModule as u };
4043
+ export { pluginEntrySchema as a, boolean as c, number as d, record as f, prettifyError as g, union as h, normalizePluginEntries as i, literal as l, string as m, entryActiveForVerb as n, _enum as o, strictObject as p, hostTypeSatisfies as r, array as s, PluginError as t, looseObject as u };
4152
4044
 
4153
- //# sourceMappingURL=host-schemas-C_MLcYX6-B2qQIdZ-.mjs.map
4154
- //# debugId=bc5cf4d9-5c7c-5994-8593-ac0a839008ee
4045
+ //# sourceMappingURL=plugins-DtJUVtyg.mjs.map
4046
+ //# debugId=8948eb3e-0a18-5df6-b283-b8271fb9f8ba