@powerhousedao/host-core 6.2.3-dev.88 → 6.2.3-dev.90

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.
@@ -424,6 +424,8 @@ function buildDriveDeclarationSchema(urlField) {
424
424
  * only the id and keeps the declared slug (the classic Workflows drive:
425
425
  * `/d/workflows`, id `workflows-<hash>`). */
426
426
  projectHash: z.union([z.boolean(), z.literal("id")]).optional(),
427
+ /** What a missing drive is created as. Default powerhouse/document-drive. */
428
+ documentType: z.enum(["powerhouse/document-drive", "powerhouse/reactor-drive"]).optional(),
427
429
  name: z.string().min(1).optional(),
428
430
  icon: z.string().optional(),
429
431
  preferredEditor: z.string().optional(),
@@ -2200,11 +2202,27 @@ const NON_VERB_EXPORTS = /* @__PURE__ */ new Set([
2200
2202
  "checkBoot",
2201
2203
  "default"
2202
2204
  ]);
2205
+ /** ph-cli's runners are ph-run's plus the verbs that build. A packaged app has
2206
+ * only ph-run, and its host files, generated against ph-cli's, name ph-cli's. */
2207
+ function runnerFallback(specifier) {
2208
+ const name = /^@powerhousedao\/ph-cli\/(runners\/.+)$/.exec(specifier)?.[1];
2209
+ return name ? `@powerhousedao/ph-run/${name}` : void 0;
2210
+ }
2203
2211
  async function resolveRunnerModule(projectRoot, specifier) {
2204
2212
  const projectRequire = createRequire(pathToFileURL(path.join(projectRoot, "package.json")).href);
2213
+ const resolveFirst = (candidates) => {
2214
+ const [first, ...rest] = candidates;
2215
+ try {
2216
+ return projectRequire.resolve(first);
2217
+ } catch (error) {
2218
+ if (rest.length === 0) throw error;
2219
+ return resolveFirst(rest);
2220
+ }
2221
+ };
2205
2222
  let resolved;
2206
2223
  try {
2207
- resolved = projectRequire.resolve(specifier);
2224
+ const fallback = runnerFallback(specifier);
2225
+ resolved = resolveFirst(fallback ? [specifier, fallback] : [specifier]);
2208
2226
  } catch {
2209
2227
  throw new RunnerError(`Cannot resolve runner module "${specifier}" from ${projectRoot}.`, "The runner must be a dependency of the project (install it, then retry).");
2210
2228
  }
@@ -3042,6 +3060,29 @@ async function memberDraft(projectRoot, member) {
3042
3060
  function takesCspRegistrySync(m) {
3043
3061
  return m.specifier === "@powerhousedao/ph-cli/runners/connect" || declaresKey(m.runner.hostSchema, ["runner"], "cspRegistrySync");
3044
3062
  }
3063
+ /**
3064
+ * Windows has no SIGTERM, so a supervisor asks a stack to stop through its
3065
+ * stdin: a line, or the pipe closing, which also covers the supervisor dying.
3066
+ * Only when it asks to: a stack started from a script may have no stdin.
3067
+ */
3068
+ function stopStreamOf(env, stdin) {
3069
+ return env["PH_STOP_ON_STDIN"] === "1" ? stdin() : void 0;
3070
+ }
3071
+ function whenStreamStops(stream, stop) {
3072
+ let stopped = false;
3073
+ const once = () => {
3074
+ if (stopped) return;
3075
+ stopped = true;
3076
+ stop();
3077
+ };
3078
+ for (const event of [
3079
+ "data",
3080
+ "end",
3081
+ "close",
3082
+ "error"
3083
+ ]) stream.once(event, once);
3084
+ stream.resume();
3085
+ }
3045
3086
  /** The verb the generic compound starts its members at for its own `verb`:
3046
3087
  * `run` follows the compound's defaultVerb. */
3047
3088
  function compoundStartVerb(verb, runner) {
@@ -3065,6 +3106,15 @@ async function runCompound(hostInput, ctx, options) {
3065
3106
  const verb = ctx.verb;
3066
3107
  const oneShotCompound = ONE_SHOT_VERBS.has(verb);
3067
3108
  const keepsRecord = wiring.runtimeRecord !== false && !oneShotCompound;
3109
+ let stopRequested = false;
3110
+ let stopFromStream = () => {
3111
+ stopRequested = true;
3112
+ };
3113
+ if (options.stopStream && !oneShotCompound) {
3114
+ whenStreamStops(options.stopStream, () => stopFromStream());
3115
+ const outputs = options.supervisedOutputs ?? [process.stdout, process.stderr];
3116
+ for (const output of outputs) output.on("error", () => void 0);
3117
+ }
3068
3118
  const probe = oneShotCompound ? void 0 : probeRun(projectRoot, host.name, options.projectName);
3069
3119
  if (probe?.status === "live") throw new Error(`${host.name} is already running for this project (pid ${probe.record.pid}). Stop it before starting another.`);
3070
3120
  if (probe?.status === "foreign") throw new Error(`.ph/run/${host.name}.json describes a live "${probe.record.projectName}", but this project is "${options.projectName}". Refusing to start a second instance.`);
@@ -3187,6 +3237,12 @@ async function runCompound(hostInput, ctx, options) {
3187
3237
  process.on("SIGINT", () => void handleSignal("SIGINT"));
3188
3238
  process.on("SIGTERM", () => void handleSignal("SIGTERM"));
3189
3239
  }
3240
+ stopFromStream = () => {
3241
+ const limit = options.stopStreamLimitMs ?? 15e3;
3242
+ setTimeout(() => exit(143), limit).unref();
3243
+ handleSignal("SIGTERM");
3244
+ };
3245
+ if (stopRequested) stopFromStream();
3190
3246
  return {
3191
3247
  started,
3192
3248
  shutdown,
@@ -3213,6 +3269,6 @@ async function prepareMember(projectRoot, key, member) {
3213
3269
  };
3214
3270
  }
3215
3271
  //#endregion
3216
- export { resolveHostOutputs as $, projectDriveIdWith as $t, findNonStaticValue as A, runObserveHook as An, declaredGenericCompoundHostSchema as At, ONE_SHOT_VERBS as B, profileSchema as Bt, writeRunRecord as C, mergeContributions as Cn, HOST_NAME_MESSAGE as Ct, OUTPUTS_FILE as D, pluginEntrySchema as Dn, compoundHostSchema as Dt, HostLoadError as E, pluginEntryObjectSchema as En, childrenSchema as Et, probeHostsFolder as F, genericCompoundHostSchema as Ft, kindShapeIssues as G, reactorSchema as Gt, getVerb as H, reactorBackendSchema as Ht, readOutputsFileHash as I, hostNameSchema as It, resolveRunnerModule as J, runnerBaseSchema as Jt, knownVerbIssues as K, refineConnectReactor as Kt, scanHostImports as L, makeHostSchemas as Lt, lintHostImports as M, runProvideHook as Mn, defineHostSchemas as Mt, lintOutputsFile as N, runTransformHook as Nn, emitHostJsonSchema as Nt, computeOutputsHash as O, registerHostType as On, compoundWiringSchema as Ot, loadHost as P, emittedHostSchemas as Pt, describeMapElements as Q, drivesSchema as Qt, stripComments as R, originOrUrlSchema as Rt, readRunRecord as S, hostTypeSatisfies as Sn, HOST_NAME_MAX_LENGTH as St, runRecordSchema as T, normalizePluginEntry as Tn, childWrapperSchema as Tt, hostSchemaIssues as U, reactorHostSchema as Ut, RunnerError as V, reactorBackendKindSchema as Vt, isSchemaLike as W, reactorProtocolSchema as Wt, validateHost as X, buildDriveDeclarationSchema as Xt, validateDeclaredHost as Y, runnerKindSchema as Yt, TokenResolutionError as Z, driveDeclarationSchema as Zt, clearRunRecord as _, findDeadConnectConfig as _n, formatPath as _t, takesCspRegistrySync as a, findToken as an, isBuiltinEnvName as at, probeRun as b, PluginError as bn, unwrapEscapes as bt, compoundOutputSource as c, itemTokenSchema as cn, checkOutputPaths as ct, producerOutputsSchemas as d, outputTokenSchema as dn, outputRefsOf as dt, TOKEN_ESCAPE_KEY as en, unsetEnvMessage as et, runRecordOutputSource as f, ref as fn, outputSitesOf as ft, applyChildWrapper as g, CONNECT_PLUGIN_OWNED_SLICES as gn, describeToken as gt, resolveUserDataPlaceholders as h, tokenable as hn, collectTokenSites as ht, runCompound as i, envTokenable as in, BUILTIN_ENV_NAMES as it, lintHostImportGraph as j, runObserveHookSequential as jn, declaredHostSchemas as jt, describeHostOutputs as k, resolveOrder as kn, connectReactorIssues as kt, loadProducers as l, keyTokenSchema as ln, checkTokenSites as lt, defaultUserDataDir as m, tokenSchema as mn, schemaAtPath as mt, memberVerbOf as n, concatTokenSchema as nn, memberForRef as nt, runnerHandleSchema as o, forbidRef as on, substituteBuiltinEnv as ot, runnerOutputsSchema as p, tokenKeyOf as pn, refKey as pt, listVerbs as q, refineStartOrder as qt, prepareMember as r, envTokenSchema as rn, planCompound as rt, toStartedHandle as s, isToken as sn, findRemovedForms as st, compoundStartVerb as t, TOKEN_KEYS as tn, PlanError as tt, processResolveEnv as u, mapTokenSchema as un, envSitesOf as ut, isPidAlive as v, resolveHostPlugins as vn, isPlainObject as vt, runRecordMemberSchema as w, normalizePluginEntries as wn, HOST_NAME_PATTERN as wt, readProjectName as x, entryActiveForVerb as xn, CONNECT_PRIMARY_MESSAGE as xt, listRunRecords as y, resolvePluginContributions as yn, renderTokens as yt, CONNECT_RUNNER as z, placementKeyIssues as zt };
3272
+ export { describeMapElements as $, drivesSchema as $t, describeHostOutputs as A, resolveOrder as An, connectReactorIssues as At, CONNECT_RUNNER as B, placementKeyIssues as Bt, readRunRecord as C, hostTypeSatisfies as Cn, HOST_NAME_MAX_LENGTH as Ct, HostLoadError as D, pluginEntryObjectSchema as Dn, childrenSchema as Dt, runRecordSchema as E, normalizePluginEntry as En, childWrapperSchema as Et, loadHost as F, emittedHostSchemas as Ft, isSchemaLike as G, reactorProtocolSchema as Gt, RunnerError as H, reactorBackendKindSchema as Ht, probeHostsFolder as I, genericCompoundHostSchema as It, listVerbs as J, refineStartOrder as Jt, kindShapeIssues as K, reactorSchema as Kt, readOutputsFileHash as L, hostNameSchema as Lt, lintHostImportGraph as M, runObserveHookSequential as Mn, declaredHostSchemas as Mt, lintHostImports as N, runProvideHook as Nn, defineHostSchemas as Nt, OUTPUTS_FILE as O, pluginEntrySchema as On, compoundHostSchema as Ot, lintOutputsFile as P, runTransformHook as Pn, emitHostJsonSchema as Pt, TokenResolutionError as Q, driveDeclarationSchema as Qt, scanHostImports as R, makeHostSchemas as Rt, readProjectName as S, entryActiveForVerb as Sn, CONNECT_PRIMARY_MESSAGE as St, runRecordMemberSchema as T, normalizePluginEntries as Tn, HOST_NAME_PATTERN as Tt, getVerb as U, reactorBackendSchema as Ut, ONE_SHOT_VERBS as V, profileSchema as Vt, hostSchemaIssues as W, reactorHostSchema as Wt, validateDeclaredHost as X, runnerKindSchema as Xt, resolveRunnerModule as Y, runnerBaseSchema as Yt, validateHost as Z, buildDriveDeclarationSchema as Zt, applyChildWrapper as _, CONNECT_PLUGIN_OWNED_SLICES as _n, describeToken as _t, stopStreamOf as a, envTokenable as an, BUILTIN_ENV_NAMES as at, listRunRecords as b, resolvePluginContributions as bn, renderTokens as bt, toStartedHandle as c, isToken as cn, findRemovedForms as ct, processResolveEnv as d, mapTokenSchema as dn, envSitesOf as dt, projectDriveIdWith as en, resolveHostOutputs as et, producerOutputsSchemas as f, outputTokenSchema as fn, outputRefsOf as ft, resolveUserDataPlaceholders as g, tokenable as gn, collectTokenSites as gt, defaultUserDataDir as h, tokenSchema as hn, schemaAtPath as ht, runCompound as i, envTokenSchema as in, planCompound as it, findNonStaticValue as j, runObserveHook as jn, declaredGenericCompoundHostSchema as jt, computeOutputsHash as k, registerHostType as kn, compoundWiringSchema as kt, compoundOutputSource as l, itemTokenSchema as ln, checkOutputPaths as lt, runnerOutputsSchema as m, tokenKeyOf as mn, refKey as mt, memberVerbOf as n, TOKEN_KEYS as nn, PlanError as nt, takesCspRegistrySync as o, findToken as on, isBuiltinEnvName as ot, runRecordOutputSource as p, ref as pn, outputSitesOf as pt, knownVerbIssues as q, refineConnectReactor as qt, prepareMember as r, concatTokenSchema as rn, memberForRef as rt, runnerHandleSchema as s, forbidRef as sn, substituteBuiltinEnv as st, compoundStartVerb as t, TOKEN_ESCAPE_KEY as tn, unsetEnvMessage as tt, loadProducers as u, keyTokenSchema as un, checkTokenSites as ut, clearRunRecord as v, findDeadConnectConfig as vn, formatPath as vt, writeRunRecord as w, mergeContributions as wn, HOST_NAME_MESSAGE as wt, probeRun as x, PluginError as xn, unwrapEscapes as xt, isPidAlive as y, resolveHostPlugins as yn, isPlainObject as yt, stripComments as z, originOrUrlSchema as zt };
3217
3273
 
3218
- //# sourceMappingURL=compound-BZb3tR_c.mjs.map
3274
+ //# sourceMappingURL=compound-BSOW40st.mjs.map