@powerhousedao/ph-cli 6.2.3-dev.72 → 6.2.3-dev.74

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 (72) hide show
  1. package/dist/check-9KDSF1Wj.mjs +53 -0
  2. package/dist/check-9KDSF1Wj.mjs.map +1 -0
  3. package/dist/{cli-connect-override-CEJhQWRX.mjs → cli-connect-override-BrS-X8Rs.mjs} +4 -4
  4. package/dist/{cli-connect-override-CEJhQWRX.mjs.map → cli-connect-override-BrS-X8Rs.mjs.map} +1 -1
  5. package/dist/cli.mjs +11 -7
  6. package/dist/cli.mjs.map +1 -1
  7. package/dist/{compound-B6RZMA0Y-Cv3XMQ3Y.mjs → compound-Gjt5rBfF-BmSW1XPB.mjs} +178 -43
  8. package/dist/compound-Gjt5rBfF-BmSW1XPB.mjs.map +1 -0
  9. package/dist/{connect-build-BfhOGbha.mjs → connect-build-B5nYqlLc.mjs} +4 -4
  10. package/dist/{connect-build-BfhOGbha.mjs.map → connect-build-B5nYqlLc.mjs.map} +1 -1
  11. package/dist/{connect-config-DblqJgxR.mjs → connect-config-Bi95JhNG.mjs} +4 -4
  12. package/dist/{connect-config-DblqJgxR.mjs.map → connect-config-Bi95JhNG.mjs.map} +1 -1
  13. package/dist/{connect-plugin-configs-D2fwYpMw.mjs → connect-plugin-configs-BwYEbQSY.mjs} +4 -4
  14. package/dist/{connect-plugin-configs-D2fwYpMw.mjs.map → connect-plugin-configs-BwYEbQSY.mjs.map} +1 -1
  15. package/dist/{connect-studio-BS26pchr.mjs → connect-studio-Co_UNyEC.mjs} +3 -3
  16. package/dist/{connect-studio-B1_4TNEb.mjs → connect-studio-DGWUidCV.mjs} +4 -4
  17. package/dist/{connect-studio-B1_4TNEb.mjs.map → connect-studio-DGWUidCV.mjs.map} +1 -1
  18. package/dist/{dist-CCLkwpTS.mjs → dist-BVqNlv1z.mjs} +243 -14
  19. package/dist/dist-BVqNlv1z.mjs.map +1 -0
  20. package/dist/{explain-DUXbB9jf.mjs → explain-CPD1tzoV.mjs} +5 -5
  21. package/dist/{explain-DUXbB9jf.mjs.map → explain-CPD1tzoV.mjs.map} +1 -1
  22. package/dist/{generate-all-Dgyy_kT-.mjs → generate-all-CaAHbviS.mjs} +4 -4
  23. package/dist/{generate-all-Dgyy_kT-.mjs.map → generate-all-CaAHbviS.mjs.map} +1 -1
  24. package/dist/generate-app-hm6CJ_4O.mjs +72 -0
  25. package/dist/generate-app-hm6CJ_4O.mjs.map +1 -0
  26. package/dist/{generate-document-model-BfFIQ35q.mjs → generate-document-model-CiW13Vf7.mjs} +23 -9
  27. package/dist/generate-document-model-CiW13Vf7.mjs.map +1 -0
  28. package/dist/generate-editor-kTiUOmDW.mjs +64 -0
  29. package/dist/generate-editor-kTiUOmDW.mjs.map +1 -0
  30. package/dist/{generate-piece-QTt-ddt2.mjs → generate-piece-U3tP-Sex.mjs} +14 -6
  31. package/dist/generate-piece-U3tP-Sex.mjs.map +1 -0
  32. package/dist/{generate-processor-DBtTkgo5.mjs → generate-processor-B9Umgjy9.mjs} +18 -7
  33. package/dist/generate-processor-B9Umgjy9.mjs.map +1 -0
  34. package/dist/generate-subgraph-DRrInOOv.mjs +64 -0
  35. package/dist/generate-subgraph-DRrInOOv.mjs.map +1 -0
  36. package/dist/{index-BIbx17vt.d.mts → index-7hbcAZpm.d.mts} +17 -3
  37. package/dist/{index-BIbx17vt.d.mts.map → index-7hbcAZpm.d.mts.map} +1 -1
  38. package/dist/migrate-b38W7NH_.mjs +177 -0
  39. package/dist/migrate-b38W7NH_.mjs.map +1 -0
  40. package/dist/module-dir-1avCXsBi.mjs +17 -0
  41. package/dist/module-dir-1avCXsBi.mjs.map +1 -0
  42. package/dist/ph-cli-commands-D4y7NPxI.mjs +4 -0
  43. package/dist/{ph-cli-commands-DSAhaETu.mjs → ph-cli-commands-kLUOOYuy.mjs} +59 -35
  44. package/dist/ph-cli-commands-kLUOOYuy.mjs.map +1 -0
  45. package/dist/{run-sugar-Ns53R6lU.mjs → run-sugar-BJxPKwlM.mjs} +4 -4
  46. package/dist/{run-sugar-Ns53R6lU.mjs.map → run-sugar-BJxPKwlM.mjs.map} +1 -1
  47. package/dist/runners/connect.d.mts +1 -1
  48. package/dist/runners/connect.mjs +5 -5
  49. package/dist/runners/switchboard.d.mts +3 -1
  50. package/dist/runners/switchboard.d.mts.map +1 -1
  51. package/dist/runners/switchboard.mjs +48 -10
  52. package/dist/runners/switchboard.mjs.map +1 -1
  53. package/dist/{start-run-BIaYSpHh.mjs → start-run-CDZ3YAr9.mjs} +4 -4
  54. package/dist/{start-run-BIaYSpHh.mjs.map → start-run-CDZ3YAr9.mjs.map} +1 -1
  55. package/dist/{vetra-UQsfYM_Q.mjs → vetra-DO5eUgAo.mjs} +6 -6
  56. package/dist/{vetra-UQsfYM_Q.mjs.map → vetra-DO5eUgAo.mjs.map} +1 -1
  57. package/package.json +14 -13
  58. package/dist/compound-B6RZMA0Y-Cv3XMQ3Y.mjs.map +0 -1
  59. package/dist/dist-CCLkwpTS.mjs.map +0 -1
  60. package/dist/generate-app-BTs1u-9l.mjs +0 -50
  61. package/dist/generate-app-BTs1u-9l.mjs.map +0 -1
  62. package/dist/generate-document-model-BfFIQ35q.mjs.map +0 -1
  63. package/dist/generate-editor-CW7Do69u.mjs +0 -50
  64. package/dist/generate-editor-CW7Do69u.mjs.map +0 -1
  65. package/dist/generate-piece-QTt-ddt2.mjs.map +0 -1
  66. package/dist/generate-processor-DBtTkgo5.mjs.map +0 -1
  67. package/dist/generate-subgraph-CVlTo7qk.mjs +0 -44
  68. package/dist/generate-subgraph-CVlTo7qk.mjs.map +0 -1
  69. package/dist/migrate-DK4HK7Dn.mjs +0 -83
  70. package/dist/migrate-DK4HK7Dn.mjs.map +0 -1
  71. package/dist/ph-cli-commands-DSAhaETu.mjs.map +0 -1
  72. package/dist/ph-cli-commands-d5XjMWW0.mjs +0 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dist-BVqNlv1z.mjs","sources":["../../../packages/host-core/dist/index.mjs"],"sourcesContent":["import { $ as unsetEnvMessage, $t as keyTokenSchema, A as lintHostImportGraph, At as makeHostSchemas, B as RunnerError, Bt as buildDriveDeclarationSchema, C as runRecordMemberSchema, Cn as runTransformHook, Ct as compoundWiringSchema, D as computeOutputsHash, Dt as emitHostJsonSchema, E as OUTPUTS_FILE, Et as defineHostSchemas, F as readOutputsFileHash, Ft as reactorProtocolSchema, G as knownVerbIssues, Gt as TOKEN_KEYS, H as hostSchemaIssues, Ht as drivesSchema, I as scanHostImports, It as reactorSchema, J as validateDeclaredHost, Jt as envTokenable, K as listVerbs, Kt as concatTokenSchema, L as stripComments, Lt as refineStartOrder, M as lintOutputsFile, Mt as reactorBackendKindSchema, N as loadHost, Nt as reactorBackendSchema, O as describeHostOutputs, Ot as emittedHostSchemas, P as probeHostsFolder, Pt as reactorHostSchema, Q as resolveHostOutputs, Qt as itemTokenSchema, R as CONNECT_RUNNER, Rt as runnerBaseSchema, S as writeRunRecord, Sn as runProvideHook, St as compoundHostSchema, T as HostLoadError, Tt as declaredHostSchemas, U as isSchemaLike, Ut as projectDriveIdWith, V as getVerb, Vt as driveDeclarationSchema, W as kindShapeIssues, Wt as TOKEN_ESCAPE_KEY, X as TokenResolutionError, Xt as forbidRef, Y as validateHost, Yt as findToken, Z as describeMapElements, Zt as isToken, _ as isPidAlive, _n as pluginEntrySchema, _t as isPlainObject, a as takesCspRegistrySync, an as tokenable, at as substituteBuiltinEnv, b as readProjectName, bn as runObserveHook, bt as childWrapperSchema, c as compoundOutputSource, cn as resolveHostPlugins, ct as checkTokenSites, d as producerOutputsSchemas, dn as entryActiveForVerb, dt as outputSitesOf, en as mapTokenSchema, et as PlanError, f as runRecordOutputSource, fn as hostTypeSatisfies, ft as refKey, g as clearRunRecord, gn as pluginEntryObjectSchema, gt as formatPath, h as resolveUserDataPlaceholders, hn as normalizePluginEntry, ht as describeToken, i as runCompound, in as tokenSchema, it as isBuiltinEnvName, j as lintHostImports, jt as profileSchema, k as findNonStaticValue, kt as genericCompoundHostSchema, l as loadProducers, ln as resolvePluginContributions, lt as envSitesOf, m as defaultUserDataDir, mn as normalizePluginEntries, mt as collectTokenSites, n as memberVerbOf, nn as ref, nt as planCompound, o as runnerHandleSchema, on as CONNECT_PLUGIN_OWNED_SLICES, ot as findRemovedForms, p as runnerOutputsSchema, pn as mergeContributions, pt as schemaAtPath, q as resolveRunnerModule, qt as envTokenSchema, r as prepareMember, rn as tokenKeyOf, rt as BUILTIN_ENV_NAMES, s as toStartedHandle, sn as findDeadConnectConfig, st as checkOutputPaths, t as compoundStartVerb, tn as outputTokenSchema, tt as memberForRef, u as processResolveEnv, un as PluginError, ut as outputRefsOf, v as listRunRecords, vn as registerHostType, vt as renderTokens, w as runRecordSchema, wt as declaredGenericCompoundHostSchema, x as readRunRecord, xn as runObserveHookSequential, xt as childrenSchema, y as probeRun, yn as resolveOrder, yt as unwrapEscapes, z as ONE_SHOT_VERBS, zt as runnerKindSchema } from \"./compound-Gjt5rBfF.mjs\";\nimport { createRequire } from \"node:module\";\nimport crypto from \"node:crypto\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { spawn } from \"node:child_process\";\nimport { DRIVE_ICON_MAX_BYTES, resolveImageRef } from \"@powerhousedao/shared/connect/image-ref\";\n//#region src/spawn-host.ts\nvar SpawnHostError = class extends Error {\n\tphase;\n\toutputTail;\n\texit;\n\tconstructor(message, phase, outputTail, exit) {\n\t\tsuper(outputTail ? `${message}\\n--- output tail ---\\n${outputTail}` : message);\n\t\tthis.phase = phase;\n\t\tthis.outputTail = outputTail;\n\t\tthis.exit = exit;\n\t\tthis.name = \"SpawnHostError\";\n\t}\n};\nconst READY_TIMEOUT_MS = 12e4;\nconst STOP_TIMEOUT_MS = 3e4;\nconst POLL_MS = 100;\nconst CLOSE_WAIT_MS = 1e3;\nconst BASE_ENV_KEYS = [\n\t\"PATH\",\n\t\"HOME\",\n\t\"TMPDIR\"\n];\nconst WIN32_ENV_KEYS = [\n\t\"SystemRoot\",\n\t\"USERPROFILE\",\n\t\"APPDATA\",\n\t\"LOCALAPPDATA\",\n\t\"TEMP\",\n\t\"TMP\",\n\t\"ComSpec\",\n\t\"PATHEXT\"\n];\n/** The child's whole env: no other `process.env` key reaches it. */\nfunction childEnv(dataDir, env = {}) {\n\tif (\"PH_USER_DATA_DIR\" in env) throw new Error(\"spawnHost: set the data dir with `dataDir`, not env.PH_USER_DATA_DIR.\");\n\tconst keys = process.platform === \"win32\" ? [...BASE_ENV_KEYS, ...WIN32_ENV_KEYS] : BASE_ENV_KEYS;\n\tconst base = {};\n\tfor (const key of keys) {\n\t\tconst value = process.env[key];\n\t\tif (value !== void 0) base[key] = value;\n\t}\n\treturn {\n\t\t...base,\n\t\tFEATURE_UNIFORM_RUNNERS_ENABLED: \"1\",\n\t\tPH_USER_DATA_DIR: dataDir,\n\t\tPH_NO_TELEMETRY: \"1\",\n\t\tPH_NO_DOTENV: \"1\",\n\t\t...env\n\t};\n}\nfunction resolvePhCliEntry(projectRoot) {\n\tconst pkgPath = createRequire(pathToFileURL(path.join(projectRoot, \"package.json\")).href).resolve(\"@powerhousedao/ph-cli/package.json\");\n\treturn path.join(path.dirname(pkgPath), \"dist\", \"cli.mjs\");\n}\n/** Readiness waits for a record; refuse a host/verb that writes none. */\nasync function assertWritesRecord(projectRoot, host, verb) {\n\tif (verb !== void 0 && ONE_SHOT_VERBS.has(verb)) throw new Error(`spawnHost: \"${verb}\" is a one-shot verb; it writes no run record to wait for.`);\n\tconst loaded = await loadHost(projectRoot, host);\n\tconst specifier = loaded.host.runner.module;\n\tconst runner = await resolveRunnerModule(projectRoot, specifier);\n\tif (runner.kind === \"compound\") {\n\t\tif (loaded.host.config?.runtimeRecord === false) throw new Error(`spawnHost: hosts/${host} sets config.runtimeRecord: false, so it writes no run record to wait for.`);\n\t\treturn;\n\t}\n\tif (!isSchemaLike(runner.outputsSchema)) throw new Error(`spawnHost: hosts/${host} runs \"${specifier}\", which exports no outputsSchema, so it writes no run record to wait for.`);\n}\nconst sleep = (ms) => new Promise((resolve) => {\n\tsetTimeout(resolve, ms).unref();\n});\nconst live = /* @__PURE__ */ new Set();\nlet exitHookInstalled = false;\nfunction track(child) {\n\tlive.add(child);\n\tchild.once(\"exit\", () => live.delete(child));\n\tif (exitHookInstalled) return;\n\texitHookInstalled = true;\n\tprocess.once(\"exit\", () => {\n\t\tfor (const running of live) running.kill(\"SIGTERM\");\n\t});\n}\n/**\n* `ph run <host> [verb]` as a child; ready when its run record appears.\n*\n* The child shares this process's group, so a terminal Ctrl-C reaches both.\n* It runs the project's own ph-cli: one older than PH_NO_DOTENV reads the\n* project's `.env` anyway.\n*/\nasync function spawnHost(options) {\n\tconst projectRoot = path.resolve(options.projectRoot);\n\tconst dataDir = path.resolve(options.dataDir);\n\tconst env = childEnv(dataDir, options.env);\n\tconst readerEnv = { PH_USER_DATA_DIR: dataDir };\n\tconst readyTimeoutMs = options.readyTimeoutMs ?? READY_TIMEOUT_MS;\n\tconst stopTimeoutMs = options.stopTimeoutMs ?? STOP_TIMEOUT_MS;\n\tconst { signal } = options;\n\tif (signal?.aborted) throw new SpawnHostError(\"spawnHost: aborted before start.\", \"aborted\", \"\");\n\tawait assertWritesRecord(projectRoot, options.host, options.verb);\n\tconst cli = options.cli ?? resolvePhCliEntry(projectRoot);\n\tfs.mkdirSync(dataDir, { recursive: true });\n\tconst log = options.logFile ? fs.createWriteStream(options.logFile, { flags: \"a\" }) : void 0;\n\tlet tail = \"\";\n\tlog?.on(\"error\", (error) => {\n\t\ttail = (tail + `logFile: ${error.message}\\n`).slice(-8192);\n\t});\n\tconst args = [\n\t\tcli,\n\t\t\"run\",\n\t\toptions.host\n\t];\n\tif (options.verb !== void 0) args.push(options.verb);\n\tconst child = spawn(process.execPath, args, {\n\t\tcwd: projectRoot,\n\t\tenv,\n\t\tstdio: [\n\t\t\t\"ignore\",\n\t\t\t\"pipe\",\n\t\t\t\"pipe\"\n\t\t],\n\t\twindowsHide: true\n\t});\n\ttrack(child);\n\tconst onChunk = (stream) => (chunk) => {\n\t\ttail = (tail + chunk).slice(-8192);\n\t\tlog?.write(chunk);\n\t\ttry {\n\t\t\toptions.onOutput?.(stream, chunk);\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\ttail = (tail + `onOutput: ${message}\\n`).slice(-8192);\n\t\t}\n\t};\n\tchild.stdout.setEncoding(\"utf8\").on(\"data\", onChunk(\"stdout\"));\n\tchild.stderr.setEncoding(\"utf8\").on(\"data\", onChunk(\"stderr\"));\n\tlet forced = false;\n\tlet exit;\n\tconst exited = new Promise((resolve) => {\n\t\tconst done = (code, sig) => {\n\t\t\tif (exit) return;\n\t\t\texit = {\n\t\t\t\tcode,\n\t\t\t\tsignal: sig,\n\t\t\t\tforced\n\t\t\t};\n\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\tresolve(exit);\n\t\t};\n\t\tchild.once(\"exit\", done);\n\t\tchild.once(\"error\", (error) => {\n\t\t\ttail = (tail + `${error.message}\\n`).slice(-8192);\n\t\t\tif (child.pid === void 0) done(null, null);\n\t\t});\n\t});\n\tconst closed = new Promise((resolve) => {\n\t\tchild.once(\"close\", () => {\n\t\t\tlog?.end();\n\t\t\tresolve();\n\t\t});\n\t});\n\tconst pid = child.pid;\n\tconst ownRecords = () => pid === void 0 ? [] : listRunRecords(projectRoot, readerEnv).filter((r) => r.pid === pid);\n\tconst kill = (sig) => {\n\t\tif (pid === void 0) return;\n\t\ttry {\n\t\t\tprocess.kill(pid, sig);\n\t\t} catch {}\n\t};\n\tconst clearOwnRecords = () => {\n\t\tfor (const record of ownRecords()) clearRunRecord(projectRoot, record.host, readerEnv);\n\t};\n\tlet stopping;\n\tconst stop = () => {\n\t\tstopping ??= (async () => {\n\t\t\tif (!exit) {\n\t\t\t\tkill(\"SIGTERM\");\n\t\t\t\tlet timer;\n\t\t\t\tconst timedOut = await Promise.race([exited.then(() => false), new Promise((resolve) => {\n\t\t\t\t\ttimer = setTimeout(() => resolve(true), stopTimeoutMs);\n\t\t\t\t})]);\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tif (timedOut) {\n\t\t\t\t\tforced = true;\n\t\t\t\t\tkill(\"SIGKILL\");\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst result = await exited;\n\t\t\tclearOwnRecords();\n\t\t\treturn result;\n\t\t})();\n\t\treturn stopping;\n\t};\n\tfunction onAbort() {\n\t\tstop();\n\t}\n\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\tconst deadline = Date.now() + readyTimeoutMs;\n\tfor (;;) {\n\t\tconst aborted = signal?.aborted ?? false;\n\t\tif (exit && !aborted) {\n\t\t\tclearOwnRecords();\n\t\t\tlet timer;\n\t\t\tawait Promise.race([closed, new Promise((resolve) => {\n\t\t\t\ttimer = setTimeout(resolve, CLOSE_WAIT_MS);\n\t\t\t})]);\n\t\t\tclearTimeout(timer);\n\t\t\tconst how = exit.signal !== null ? `signal ${exit.signal}` : `code ${exit.code}`;\n\t\t\tthrow new SpawnHostError(`spawnHost: ph run ${options.host} exited (${how}) before writing its run record.`, \"exited\", tail, exit);\n\t\t}\n\t\tconst record = aborted ? void 0 : ownRecords().at(0);\n\t\tif (record) return {\n\t\t\tpid: record.pid,\n\t\t\tdataDir,\n\t\t\trecord,\n\t\t\toutputs: record.outputs,\n\t\t\tmembers: record.members,\n\t\t\texited,\n\t\t\tstop\n\t\t};\n\t\tif (aborted || Date.now() >= deadline) {\n\t\t\tconst phase = aborted ? \"aborted\" : \"timeout\";\n\t\t\tconst stopped = await stop();\n\t\t\tthrow new SpawnHostError(phase === \"aborted\" ? `spawnHost: aborted before ph run ${options.host} was ready.` : `spawnHost: ph run ${options.host} wrote no run record within ${readyTimeoutMs} ms.`, phase, tail, stopped);\n\t\t}\n\t\tawait Promise.race([sleep(POLL_MS), exited]);\n\t}\n}\n//#endregion\n//#region src/check-host.ts\n/** The `ph run` pipeline up to the verb, collecting every issue; starts nothing. */\nasync function checkHost(name, options) {\n\tconst result = {\n\t\tissues: [],\n\t\tdeferred: []\n\t};\n\tconst file = `hosts/${name}/host.js`;\n\tconst issue = issuer(result, file);\n\tconst verb = options.verb ?? \"run\";\n\tlet host;\n\tlet runner;\n\ttry {\n\t\thost = (await loadHost(options.projectRoot, name)).host;\n\t\trunner = await resolveRunnerModule(options.projectRoot, host.runner.module);\n\t} catch (error) {\n\t\tissue(\"load\", \"\", error);\n\t\treturn result;\n\t}\n\tconst specifier = host.runner.module;\n\tif (runner.kind === \"compound\") {\n\t\tawait checkCompound(result, options, {\n\t\t\tfile,\n\t\t\thost,\n\t\t\trunner,\n\t\t\tspecifier,\n\t\t\tverb\n\t\t});\n\t\treturn result;\n\t}\n\tconst refs = outputRefsOf(host);\n\tconst producers = await loadProducers(options.projectRoot, refs);\n\tawait checkSubject(result, options, {\n\t\tfile,\n\t\thost,\n\t\trunner,\n\t\tspecifier,\n\t\tverb,\n\t\toutputsSchemaOf: producerOutputsSchemas(producers),\n\t\tself: \"outputs\"\n\t});\n\treturn result;\n}\n/** Declared validation; returns whether its tokens and its shape passed. */\nfunction checkDeclared(result, subject, outputsSchemaOf) {\n\tconst issue = issuer(result, subject.file);\n\tconst { host, runner, specifier } = subject;\n\ttry {\n\t\tgetVerb(runner, specifier, subject.verb);\n\t} catch (error) {\n\t\tissue(\"declared\", \"\", error);\n\t}\n\tconst tokenIssues = [\n\t\t...findRemovedForms(host),\n\t\t...checkTokenSites(host),\n\t\t...outputsSchemaOf ? checkOutputPaths(host, outputsSchemaOf) : []\n\t];\n\tfor (const i of tokenIssues) issue(\"declared\", i);\n\tconst shapeIssues = runner.declaredHostSchema ? schemaIssuesOf(runner, runner.declaredHostSchema, specifier, host, true) : kindShapeIssues(runner.kind, specifier, host);\n\tfor (const i of shapeIssues) issue(\"declared\", i);\n\treturn {\n\t\ttokens: tokenIssues.length === 0,\n\t\tshape: shapeIssues.length === 0\n\t};\n}\nfunction schemaIssuesOf(runner, schema, specifier, host, allowTokens) {\n\tconst checked = hostSchemaIssues(runner, schema, specifier, host, { tokens: allowTokens ? \"allow\" : \"forbid\" });\n\treturn [...checked.issues, ...checked.schemaIssues ?? []];\n}\nasync function checkSubject(result, options, subject) {\n\tconst issue = issuer(result, subject.file);\n\tconst { runner, specifier, file } = subject;\n\tconst declared = checkDeclared(result, subject, subject.outputsSchemaOf);\n\tconst resolveEnv = processResolveEnv(options.projectRoot, options.env);\n\tconst patch = subject.patch ?? ((host) => host);\n\tif (ONE_SHOT_VERBS.has(subject.verb)) {\n\t\tif (!declared.tokens || !declared.shape) return;\n\t\tconst host = patch(substituteBuiltinEnv(subject.host, resolveEnv.builtins ?? {}));\n\t\tconst schema = runner.declaredHostSchema ?? runner.hostSchema;\n\t\tfor (const i of schemaIssuesOf(runner, schema, specifier, host, true)) issue(\"resolved\", i);\n\t\treturn;\n\t}\n\tconst unset = envSitesOf(subject.host).filter((site) => !site.optional && !isBuiltinEnvName(site.name) && options.env[site.name] === void 0);\n\tfor (const site of unset) issue(\"resolve\", {\n\t\tpath: site.path,\n\t\tmessage: unsetEnvMessage(site.name)\n\t});\n\tif (!declared.tokens || unset.length > 0) return;\n\tlet resolved;\n\tlet deferred = [];\n\ttry {\n\t\tif (options.outputs) resolved = resolveHostOutputs(subject.host, {\n\t\t\toutputs: options.outputs,\n\t\t\t...resolveEnv\n\t\t});\n\t\telse {\n\t\t\tconst partial = resolveHostOutputs(subject.host, resolveEnv, { deferSelf: subject.self });\n\t\t\tresolved = partial.host;\n\t\t\tdeferred = partial.deferred;\n\t\t}\n\t} catch (error) {\n\t\tif (error instanceof TokenResolutionError && error.detail) issue(\"resolve\", {\n\t\t\tpath: error.detail.path,\n\t\t\tmessage: error.detail.reason\n\t\t});\n\t\telse issue(\"resolve\", \"\", error);\n\t\treturn;\n\t}\n\tresult.deferred.push(...deferred.map((d) => ({\n\t\t...d,\n\t\tfile\n\t})));\n\tif (!declared.shape) return;\n\tconst allow = deferred.length > 0;\n\tconst schema = allow ? runner.declaredHostSchema ?? runner.hostSchema : runner.hostSchema;\n\tconst checked = hostSchemaIssues(runner, schema, specifier, patch(resolved), { tokens: allow ? \"allow\" : \"forbid\" });\n\tconst resolvedIssues = [...checked.issues, ...checked.schemaIssues ?? []];\n\tfor (const i of resolvedIssues) issue(\"resolved\", i);\n\tif (resolvedIssues.length > 0 || !runner.checkBoot) return;\n\ttry {\n\t\tconst boot = await runner.checkBoot(checked.data, {\n\t\t\tprojectRoot: options.projectRoot,\n\t\t\tverb: subject.verb,\n\t\t\tenv: options.env,\n\t\t\tfile\n\t\t});\n\t\tfor (const i of boot) issue(\"boot\", {\n\t\t\t...i,\n\t\t\tpath: i.path ?? \"\"\n\t\t});\n\t} catch (error) {\n\t\tissue(\"boot\", \"\", error);\n\t}\n}\nasync function checkCompound(result, options, subject) {\n\tconst issue = issuer(result, subject.file);\n\tconst { host, runner, specifier } = subject;\n\tconst declared = checkDeclared(result, subject);\n\tif (!declared.tokens || !declared.shape) return;\n\tif (!runner.declaredHostSchema) {\n\t\tconst own = schemaIssuesOf(runner, runner.hostSchema, specifier, host, true);\n\t\tfor (const i of own) issue(\"resolved\", i);\n\t\tif (own.length > 0) return;\n\t}\n\tconst children = isPlainObject(host.children) ? host.children : {};\n\tconst wiring = isPlainObject(host.config) ? host.config : {};\n\tconst verb = compoundStartVerb(subject.verb, host.runner);\n\tconst prepared = [];\n\tfor (const [key, member] of Object.entries(children)) try {\n\t\tprepared.push(await prepareMember(options.projectRoot, key, member));\n\t} catch (error) {\n\t\tissuer(result, `hosts/${member.host}/host.js`)(\"load\", \"\", error);\n\t}\n\tconst members = Object.entries(children).map(([key, m]) => ({\n\t\tkey,\n\t\thost: m.host\n\t}));\n\tif (prepared.length === members.length) try {\n\t\tplanCompound(prepared.map((m) => ({\n\t\t\tkey: m.key,\n\t\t\thost: m.member.host,\n\t\t\trefs: outputSitesOf(m.draft).map(({ ref, path }) => ({\n\t\t\t\tref,\n\t\t\t\tpath\n\t\t\t}))\n\t\t})), wiring.startOrder);\n\t} catch (error) {\n\t\tissue(\"declared\", \"\", error);\n\t}\n\tconst byKey = new Map(prepared.map((m) => [m.key, m]));\n\tconst outputsSchemaOf = (ref) => {\n\t\tconst target = memberForRef(ref, members);\n\t\tif (\"error\" in target) return { error: target.error };\n\t\tconst producer = byKey.get(target.key);\n\t\treturn producer ? runnerOutputsSchema(producer.runner, producer.specifier, `member \"${target.key}\"`) : { error: `names member \"${target.key}\", which was not prepared.` };\n\t};\n\tfor (const m of prepared) {\n\t\tconst csp = wiring.cspRegistrySync === true && takesCspRegistrySync(m);\n\t\tawait checkSubject(result, options, {\n\t\t\tfile: m.file,\n\t\t\thost: m.draft,\n\t\t\trunner: m.runner,\n\t\t\tspecifier: m.specifier,\n\t\t\tverb: memberVerbOf(verb, m.draft.runner),\n\t\t\toutputsSchemaOf,\n\t\t\tself: { members },\n\t\t\t...csp ? { patch: (resolved) => ({\n\t\t\t\t...resolved,\n\t\t\t\trunner: {\n\t\t\t\t\t...resolved.runner,\n\t\t\t\t\tcspRegistrySync: true\n\t\t\t\t}\n\t\t\t}) } : {}\n\t\t});\n\t}\n}\nfunction issuer(result, file) {\n\treturn (stage, found, error) => {\n\t\tif (typeof found !== \"string\") {\n\t\t\tconst { path, message, hint } = found;\n\t\t\tresult.issues.push({\n\t\t\t\tstage,\n\t\t\t\tfile,\n\t\t\t\tpath,\n\t\t\t\tmessage,\n\t\t\t\t...hint ? { hint } : {}\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tconst [message, hint] = (error instanceof Error ? error.message : String(error)).split(\"\\n Hint: \");\n\t\tresult.issues.push({\n\t\t\tstage,\n\t\t\tfile,\n\t\t\tpath: found,\n\t\t\tmessage,\n\t\t\t...hint ? { hint } : {}\n\t\t});\n\t};\n}\n//#endregion\n//#region src/drives.ts\nconst sha256Hex = (input) => crypto.createHash(\"sha256\").update(input).digest(\"hex\");\nfunction projectDriveId(projectRoot, slug) {\n\treturn projectDriveIdWith(sha256Hex, projectRoot, slug);\n}\nfunction resolveDriveDeclaration(projectRoot, decl) {\n\tconst id = decl.projectHash ? projectDriveId(projectRoot, decl.slug) : decl.id ?? decl.slug;\n\tconst slug = decl.projectHash === true ? id : decl.slug;\n\tif (decl.remote) return {\n\t\tkind: \"remote\",\n\t\tid,\n\t\tslug,\n\t\tname: decl.name ?? decl.slug,\n\t\tremoteUrl: decl.remote.url,\n\t\tsharingType: decl.sharingType ?? \"public\",\n\t\tavailableOffline: decl.availableOffline ?? true\n\t};\n\treturn {\n\t\tkind: \"local\",\n\t\tid,\n\t\tslug,\n\t\tname: decl.name ?? decl.slug,\n\t\ticon: resolveImageRef(projectRoot, decl.icon, {\n\t\t\tmaxBytes: DRIVE_ICON_MAX_BYTES,\n\t\t\twarn: (m) => console.warn(m)\n\t\t}),\n\t\tpreferredEditor: decl.preferredEditor,\n\t\tsharingType: decl.sharingType ?? \"public\",\n\t\tavailableOffline: decl.availableOffline ?? true\n\t};\n}\n/** Idempotent, slug-keyed: an existing slug is left untouched (never\n* recreated, never mutated — preserveStrategy refinements live here later). */\nasync function seedDrives(client, drives) {\n\tconst result = {\n\t\tcreated: [],\n\t\texisting: [],\n\t\tattached: []\n\t};\n\tfor (const drive of drives) {\n\t\tif (drive.kind === \"remote\") {\n\t\t\tawait client.attachRemoteDrive(drive.remoteUrl);\n\t\t\tresult.attached.push(drive.slug);\n\t\t\tcontinue;\n\t\t}\n\t\tif (await client.findDriveBySlug(drive.slug) !== void 0) {\n\t\t\tresult.existing.push(drive.slug);\n\t\t\tcontinue;\n\t\t}\n\t\tawait client.createDrive(drive);\n\t\tresult.created.push(drive.slug);\n\t}\n\treturn result;\n}\n/** Merge host-declared drives with plugin contributions, slug-keyed — the\n* host file wins on conflicts (it is the most explicit source). */\nfunction mergeDrivePlan(projectRoot, hostDeclared, contributed) {\n\tconst plan = /* @__PURE__ */ new Map();\n\tfor (const { declaration, source } of contributed) {\n\t\tconst drive = resolveDriveDeclaration(projectRoot, declaration);\n\t\tplan.set(drive.slug, {\n\t\t\tdrive,\n\t\t\tsource\n\t\t});\n\t}\n\tfor (const declaration of hostDeclared) {\n\t\tconst drive = resolveDriveDeclaration(projectRoot, declaration);\n\t\tplan.set(drive.slug, {\n\t\t\tdrive,\n\t\t\tsource: \"host\"\n\t\t});\n\t}\n\treturn [...plan.values()];\n}\nfunction explainDrivePlan(plan) {\n\tif (plan.length === 0) return \"(no drives declared)\";\n\treturn [\"drives:\", ...plan.map(({ drive, source }) => {\n\t\tconst kind = drive.kind === \"remote\" ? `remote ${drive.remoteUrl}` : \"local\";\n\t\tconst editor = drive.preferredEditor ? ` editor=${drive.preferredEditor}` : \"\";\n\t\treturn ` ${drive.slug} (${kind}, id=${drive.id}${editor}) [${source}]`;\n\t})].join(\"\\n\");\n}\n//#endregion\n//#region src/reactor-config.ts\n/** The single primary backend for phase-2 projection (multi-backend routing is\n* track R). Prefers placement.primary, else \"main\"/\"local\", else the first. */\nfunction primaryBackend(reactor) {\n\tconst backends = reactor?.backends;\n\tif (!backends) return void 0;\n\tconst names = Object.keys(backends);\n\tif (names.length === 0) return void 0;\n\treturn backends[reactor.placement?.primary ?? (names.includes(\"main\") ? \"main\" : names.includes(\"local\") ? \"local\" : names[0])];\n}\nconst FLAG_ENV = {\n\tdocumentDecisions: \"REACTOR_DOCUMENT_DECISIONS\",\n\tauthEnforcement: \"REACTOR_AUTH_ENFORCEMENT\",\n\tauthGroups: \"REACTOR_AUTH_GROUPS\",\n\tauthConditions: \"REACTOR_AUTH_CONDITIONS\"\n};\n/** The env vars a protocol block maps onto, with their string values. Only\n* keys the block actually sets appear. */\nfunction protocolEnv(protocol) {\n\tconst env = {};\n\tif (!protocol) return env;\n\tfor (const [key, varName] of Object.entries(FLAG_ENV)) {\n\t\tconst value = protocol.featureFlags?.[key];\n\t\tif (value !== void 0) env[varName] = value ? \"true\" : \"false\";\n\t}\n\tif (protocol.createSignaturePolicy !== void 0) env.CREATE_SIGNATURE_POLICY = protocol.createSignaturePolicy;\n\tif (protocol.unsupportedStoredDocuments !== void 0) env.REACTOR_UNSUPPORTED_STORED_DOCUMENTS = protocol.unsupportedStoredDocuments;\n\treturn env;\n}\n/** Project the reactor block onto the switchboard's env + options. */\nfunction projectReactorToSwitchboard(reactor) {\n\tconst env = protocolEnv(reactor?.protocol);\n\tconst backend = primaryBackend(reactor);\n\tconst options = {};\n\tif (backend?.storage) {\n\t\tconst s = backend.storage;\n\t\tconst dbUrl = s.kind === \"postgres\" ? s.url : s.dataDir;\n\t\tif (dbUrl) env.PH_REACTOR_DATABASE_URL = dbUrl;\n\t}\n\tif (backend?.readModel?.url) options.dbPath = backend.readModel.url;\n\tif (backend?.packages?.dynamic) env.DYNAMIC_MODEL_LOADING = \"true\";\n\tif (reactor?.workflows !== void 0) env.PH_WORKFLOWS_ENABLED = reactor.workflows ? \"1\" : \"0\";\n\treturn {\n\t\tenv,\n\t\toptions\n\t};\n}\nconst LOCAL_BACKEND_KINDS = /* @__PURE__ */ new Set([\"in-process\", \"worker\"]);\n/**\n* Which reactor client the backend topology asks for:\n* - local (in-process/worker) AND remote backends -> `router`\n* - remote backend(s) only -> `remote`\n* - a worker backend -> `worker`\n* - anything else local -> `in-process`\n* `undefined` when no backends are declared — the caller then keeps the\n* legacy reactorWorker/multiReactor behaviour untouched.\n*/\nfunction reactorClientMode(reactor) {\n\tconst backends = reactor?.backends;\n\tif (!backends) return void 0;\n\tconst kinds = Object.values(backends).map((b) => b.kind);\n\tif (kinds.length === 0) return void 0;\n\tconst hasLocal = kinds.some((k) => LOCAL_BACKEND_KINDS.has(k));\n\tconst hasRemote = kinds.some((k) => k === \"remote\");\n\tif (hasLocal && hasRemote) return \"router\";\n\tif (hasRemote) return \"remote\";\n\treturn primaryBackend(reactor)?.kind === \"worker\" ? \"worker\" : \"in-process\";\n}\n/** Project the reactor block onto the Connect runtime config: protocol →\n* connect.reactor (same shape), backend topology → instance.reactorWorker\n* (legacy) + instance.reactorClient (the explicit 4-way selector),\n* workflows → app.workflowsEnabled. */\nfunction projectReactorToConnect(reactor) {\n\tconst connect = {};\n\tif (reactor?.protocol) connect.reactor = reactor.protocol;\n\tconst backend = primaryBackend(reactor);\n\tconst mode = reactorClientMode(reactor);\n\tif (backend?.kind !== void 0 || mode !== void 0) connect.instance = {\n\t\t...backend?.kind !== void 0 ? { reactorWorker: backend.kind === \"worker\" } : {},\n\t\t...mode !== void 0 ? { reactorClient: mode } : {}\n\t};\n\tif (reactor?.workflows !== void 0) connect.app = { workflowsEnabled: reactor.workflows };\n\treturn { connect };\n}\n/** Each pre-set env var that CONTRADICTS the host's protocol block, as a\n* message naming the var, the host value and the env value. An env var that\n* merely matches, or is unset, is fine. */\nfunction protocolConflicts(protocol, env, hostFile = \"the host file\") {\n\tif (!protocol) return [];\n\treturn Object.entries(protocolEnv(protocol)).flatMap(([varName, hostValue]) => {\n\t\tconst envValue = env[varName];\n\t\tif (envValue === void 0 || envValue === hostValue) return [];\n\t\treturn [`reactor.protocol conflict: ${varName} is \"${envValue}\" in the environment but \"${hostValue}\" in ${hostFile}. These are fleet-consensus settings — a mismatch would diverge replay. Remove the env override or align the host.`];\n\t});\n}\n/**\n* The enforcement teeth of single-sourcing: if a pre-set env var CONTRADICTS\n* the host's protocol block, fail loudly naming the var, the host value, and\n* the env value (phase-2 transition keeps an operator's explicit env as an\n* escape hatch unless it disagrees with the protocol — see the WBS\n* precedence note).\n*/\nfunction assertProtocolConsistency(protocol, env, hostFile = \"the host file\") {\n\tconst conflict = protocolConflicts(protocol, env, hostFile).at(0);\n\tif (conflict) throw new Error(conflict);\n}\n//#endregion\n//#region src/backend-projection.ts\nfunction projectStorage(name, storage) {\n\tswitch (storage.kind) {\n\t\tcase \"idb\": return { kind: \"idb\" };\n\t\tcase \"memory\": return { kind: \"memory\" };\n\t\tcase \"path\":\n\t\t\tif (!storage.dataDir) throw new Error(`Backend \"${name}\": storage kind \"path\" requires dataDir.`);\n\t\t\treturn {\n\t\t\t\tkind: \"path\",\n\t\t\t\tdataDir: storage.dataDir\n\t\t\t};\n\t\tcase \"postgres\": throw new Error(`Backend \"${name}\": storage kind \"postgres\" is server-side only — a provisioned (in-process/worker) reactor cannot use it. Point a \"remote\" backend at the switchboard that owns that database instead.`);\n\t}\n}\n/** One backend → one descriptor. The protocol's featureFlags ride every\n* descriptor (they are fleet consensus, not per-backend). A remote backend\n* must carry remote.url — provision() requires it. */\nfunction backendToDescriptor(name, backend, protocol) {\n\tconst descriptor = {\n\t\tkind: backend.kind,\n\t\tname\n\t};\n\tif (descriptor.kind === \"remote\") {\n\t\tconst url = backend.remote?.url;\n\t\tif (!url) throw new Error(`Backend \"${name}\" is kind \"remote\" but has no remote.url — a remote descriptor attaches to an already-running reactor by URL.`);\n\t\tdescriptor.remote = { url };\n\t\treturn descriptor;\n\t}\n\tif (backend.storage) descriptor.storage = projectStorage(name, backend.storage);\n\tif (backend.packages) descriptor.packages = backend.packages;\n\tif (protocol?.featureFlags) descriptor.featureFlags = protocol.featureFlags;\n\treturn descriptor;\n}\n/** All named backends, in placement-primary-first order (the order a\n* createReactorClients step would provision them). */\nfunction backendsToDescriptors(reactor) {\n\tconst backends = reactor?.backends;\n\tif (!backends) return [];\n\tconst names = Object.keys(backends);\n\tconst primary = reactor.placement?.primary;\n\treturn (primary && names.includes(primary) ? [primary, ...names.filter((n) => n !== primary)] : names).map((name) => backendToDescriptor(name, backends[name], reactor.protocol));\n}\nconst LOCAL_KINDS = /* @__PURE__ */ new Set([\"in-process\", \"worker\"]);\n/**\n* Structural multi-reactor (phase 4): true when the block names BOTH a local\n* backend (in-process/worker — the tab's own reactor) and a remote one. This\n* is the shape Connect's routing client serves; a lone remote backend is an\n* attach-only host (assistant/agent shape), not a routed tab.\n*/\nfunction isStructuralMultiReactor(reactor) {\n\tconst backends = reactor?.backends;\n\tif (!backends) return false;\n\tconst kinds = Object.values(backends).map((b) => b.kind);\n\treturn kinds.some((k) => LOCAL_KINDS.has(k)) && kinds.some((k) => k === \"remote\");\n}\n/** The remote backends' urls, placement order — what the routing client dials. */\nfunction remoteBackendUrls(reactor) {\n\treturn backendsToDescriptors(reactor).filter((d) => d.kind === \"remote\").map((d) => d.remote?.url).filter((u) => typeof u === \"string\");\n}\n//#endregion\n//#region src/connect-projection.ts\n/**\n* Instance-fact projection for compound hosts: the drives a compound's\n* reactor member created, projected into the Connect member's runtime-config\n* override. Pure functions, moved from ph-cli's vetra service so the generic\n* compound and the classic path share one implementation.\n*/\nfunction isLocalDrive(drive) {\n\treturn \"local\" in drive;\n}\nconst driveKey = (drive) => isLocalDrive(drive) ? `local:${drive.id}` : drive.url;\n/**\n* Concatenate groups of `connect.drives.defaultDrives` in the order given,\n* de-duplicating by drive identity (URL for remote entries, id for local\n* ones). The first occurrence of a drive wins, so earlier groups keep their\n* position and metadata — e.g. the Vetra drive `ph vetra` starts stays first\n* even when the project's `powerhouse.config.json` lists the same drive.\n*/\nfunction mergeDefaultDrives(...groups) {\n\tconst seen = /* @__PURE__ */ new Set();\n\tconst out = [];\n\tfor (const group of groups) for (const drive of group) {\n\t\tconst key = driveKey(drive);\n\t\tif (seen.has(key)) continue;\n\t\tseen.add(key);\n\t\tout.push(drive);\n\t}\n\treturn out;\n}\n/**\n* Rebase a local drive URL onto a public base: keeps the /d/<slug> path,\n* swaps the loopback origin for the public base. Browser clients behind a\n* reverse proxy can't reach http://localhost:<port>. Non-loopback URLs\n* (e.g. a remote drive) are already public and pass through unchanged, as do\n* unparseable ones.\n*/\nfunction rebaseDriveUrl(driveUrl, publicBase) {\n\tlet url;\n\ttry {\n\t\turl = new URL(driveUrl);\n\t} catch {\n\t\treturn driveUrl;\n\t}\n\tif (![\n\t\t\"localhost\",\n\t\t\"127.0.0.1\",\n\t\t\"[::1]\"\n\t].includes(url.hostname)) return driveUrl;\n\treturn `${publicBase.replace(/\\/+$/, \"\")}${url.pathname}`;\n}\n/**\n* The compound's drives projection: created drives first (rebased onto the\n* public base when given), then the project's configured drives, de-duplicated\n* — and `preserve-all`, because compound-injected drive lists change per\n* launch context and must never detach drives the user added by hand.\n*/\nfunction projectDrivesIntoConnect(input) {\n\treturn { drives: {\n\t\tdefaultDrives: mergeDefaultDrives(input.createdDriveUrls.filter((url) => typeof url === \"string\" && url.length > 0).map((url) => ({\n\t\t\turl: input.publicBase ? rebaseDriveUrl(url, input.publicBase) : url,\n\t\t\tname: null,\n\t\t\ticon: null\n\t\t})), input.configuredDefaultDrives ?? []),\n\t\tpreserveStrategy: \"preserve-all\"\n\t} };\n}\n//#endregion\n//#region src/expect-host.ts\nfunction isRecord(value) {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\nfunction runnerOf(host) {\n\treturn isRecord(host.runner) ? host.runner : {};\n}\nfunction defaultVerbOf(host) {\n\tconst verb = runnerOf(host).defaultVerb;\n\treturn typeof verb === \"string\" ? verb : void 0;\n}\n/** At compound verb \"run\" each member runs its own defaultVerb; any other\n* compound verb is forwarded uniformly (compound.ts `memberVerbOf`). */\nfunction memberVerb(compoundVerb, member) {\n\treturn compoundVerb === \"run\" ? defaultVerbOf(member) ?? \"run\" : compoundVerb;\n}\n/** Backend names, placement-primary first (`backendsToDescriptors` order). */\nfunction orderedBackends(reactor) {\n\tconst backends = Object.entries(reactor.backends ?? {});\n\tconst primary = reactor.placement?.primary;\n\treturn [...backends.filter(([name]) => name === primary), ...backends.filter(([name]) => name !== primary)];\n}\nfunction expectBackend(name, backend, reactor) {\n\tconst out = {\n\t\tname,\n\t\tkind: backend.kind\n\t};\n\tif (backend.storage) out.storage = backend.storage.kind;\n\tif (typeof backend.storage?.dataDir === \"string\") out.dataDir = backend.storage.dataDir;\n\ttry {\n\t\tbackendToDescriptor(name, backend, reactor.protocol);\n\t} catch (error) {\n\t\tout.provisionError = error instanceof Error ? error.message : String(error);\n\t}\n\treturn out;\n}\nfunction expectDrive(declaration, source) {\n\tif (typeof declaration.slug !== \"string\") return void 0;\n\tconst remote = isRecord(declaration.remote) ? declaration.remote : void 0;\n\tconst drive = {\n\t\tslug: declaration.slug,\n\t\tkind: remote ? \"remote\" : \"local\",\n\t\tsource\n\t};\n\tif (remote && typeof remote.url === \"string\") drive.url = remote.url;\n\tif (typeof declaration.id === \"string\") drive.id = declaration.id;\n\tconst projectHash = declaration.projectHash;\n\tif (typeof projectHash === \"boolean\" || projectHash === \"id\") drive.projectHash = projectHash;\n\treturn drive;\n}\n/** The key `mergeDrivePlan` merges on: the SERVED slug, which for\n* `projectHash: true` is the hashed id (never equal to a plain slug). */\nfunction servedSlugKey(drive) {\n\treturn drive.projectHash === true ? `${drive.slug}\\0hashed` : drive.slug;\n}\n/** Contributions first, then host declarations; keyed by served slug, the\n* host wins (and keeps the contribution's position), like `mergeDrivePlan`. */\nfunction drivePlan(reactor, contributed) {\n\tconst plan = /* @__PURE__ */ new Map();\n\tfor (const { declaration, source } of contributed) {\n\t\tconst drive = expectDrive(declaration, source);\n\t\tif (drive) plan.set(servedSlugKey(drive), drive);\n\t}\n\tfor (const declaration of reactor?.drives ?? []) {\n\t\tconst drive = expectDrive(declaration, \"host\");\n\t\tif (drive) plan.set(servedSlugKey(drive), drive);\n\t}\n\treturn [...plan.values()];\n}\n/** Token facts of the host's OWN fields (a compound's `children` are its\n* members' own). */\nfunction tokenFacts(declared, kind) {\n\tconst own = kind === \"compound\" ? Object.fromEntries(Object.entries(declared).filter(([key]) => key !== \"children\")) : declared;\n\tconst sites = outputSitesOf(own);\n\tconst consumes = sites.map(({ path, ref, outputPath }) => ({\n\t\tat: path,\n\t\thost: ref.host,\n\t\t...ref.member !== void 0 ? { member: ref.member } : {},\n\t\tpath: outputPath\n\t}));\n\treturn {\n\t\tdependsOn: [...new Set(sites.map(({ ref }) => refKey(ref)))].sort(),\n\t\tconsumes,\n\t\tenv: [...new Set(envSitesOf(own).map(({ name }) => name))].sort()\n\t};\n}\nfunction expectOwn(input, verb) {\n\tconst resolved = input.resolved ?? input.declared;\n\tconst expectation = {\n\t\tname: typeof resolved.name === \"string\" ? resolved.name : \"\",\n\t\tkind: input.kind,\n\t\tverb,\n\t\t...tokenFacts(input.declared, input.kind)\n\t};\n\tif (input.kind !== \"reactor\") return expectation;\n\tconst reactor = isRecord(resolved.reactor) ? resolved.reactor : void 0;\n\tconst mode = reactorClientMode(reactor);\n\tif (mode !== void 0) expectation.clientMode = mode;\n\texpectation.multiReactor = isStructuralMultiReactor(reactor);\n\tconst backends = reactor ? orderedBackends(reactor) : [];\n\tif (reactor && backends.length > 0) {\n\t\texpectation.backends = backends.map(([name, backend]) => expectBackend(name, backend, reactor));\n\t\texpectation.remotes = backends.flatMap(([, backend]) => backend.kind === \"remote\" && typeof backend.remote?.url === \"string\" ? [backend.remote.url] : []);\n\t}\n\texpectation.drives = drivePlan(reactor, input.contributed ?? []);\n\treturn expectation;\n}\n/**\n* The expectation for one host. A reactor host's comes from its resolved\n* reactor block and contributed drives; a compound's lists its members in\n* plan order, each with the verb it runs at under the compound's own verb\n* and the members it starts after.\n*/\nfunction expectHost(input) {\n\tconst verb = defaultVerbOf(input.declared) ?? \"run\";\n\tconst expectation = expectOwn(input, verb);\n\tif (input.kind !== \"compound\" || !input.members) return expectation;\n\tconst order = input.plan?.order ?? input.members.map((m) => m.key);\n\tconst edges = input.plan?.edges ?? [];\n\tconst byKey = new Map(input.members.map((m) => [m.key, m]));\n\tconst members = {};\n\tfor (const key of order) {\n\t\tconst member = byKey.get(key);\n\t\tif (!member) continue;\n\t\tmembers[key] = {\n\t\t\thost: member.host,\n\t\t\t...expectOwn(member, memberVerb(verb, member.declared)),\n\t\t\tafter: [...new Set(edges.filter((e) => e.consumer === key).map((e) => e.producer))].sort()\n\t\t};\n\t}\n\texpectation.startOrder = order.filter((key) => byKey.has(key));\n\texpectation.members = members;\n\treturn expectation;\n}\n//#endregion\nexport { BUILTIN_ENV_NAMES, CONNECT_PLUGIN_OWNED_SLICES, CONNECT_RUNNER, HostLoadError, ONE_SHOT_VERBS, OUTPUTS_FILE, PlanError, PluginError, RunnerError, SpawnHostError, TOKEN_ESCAPE_KEY, TOKEN_KEYS, TokenResolutionError, assertProtocolConsistency, backendToDescriptor, backendsToDescriptors, buildDriveDeclarationSchema, checkHost, checkOutputPaths, checkTokenSites, childWrapperSchema, childrenSchema, clearRunRecord, collectTokenSites, compoundHostSchema, compoundOutputSource, compoundWiringSchema, computeOutputsHash, concatTokenSchema, declaredGenericCompoundHostSchema, declaredHostSchemas, defaultUserDataDir, defineHostSchemas, describeHostOutputs, describeMapElements, describeToken, driveDeclarationSchema, drivesSchema, emitHostJsonSchema, emittedHostSchemas, entryActiveForVerb, envSitesOf, envTokenSchema, envTokenable, expectHost, explainDrivePlan, findDeadConnectConfig, findNonStaticValue, findRemovedForms, findToken, forbidRef, formatPath, genericCompoundHostSchema, getVerb, hostSchemaIssues, hostTypeSatisfies, isBuiltinEnvName, isPidAlive, isSchemaLike, isStructuralMultiReactor, isToken, itemTokenSchema, keyTokenSchema, kindShapeIssues, knownVerbIssues, lintHostImportGraph, lintHostImports, lintOutputsFile, listRunRecords, listVerbs, loadHost, loadProducers, makeHostSchemas, mapTokenSchema, memberForRef, mergeContributions, mergeDefaultDrives, mergeDrivePlan, normalizePluginEntries, normalizePluginEntry, outputRefsOf, outputSitesOf, outputTokenSchema, planCompound, pluginEntryObjectSchema, pluginEntrySchema, primaryBackend, probeHostsFolder, probeRun, processResolveEnv, producerOutputsSchemas, profileSchema, projectDriveId, projectDriveIdWith, projectDrivesIntoConnect, projectReactorToConnect, projectReactorToSwitchboard, protocolConflicts, protocolEnv, reactorBackendKindSchema, reactorBackendSchema, reactorClientMode, reactorHostSchema, reactorProtocolSchema, reactorSchema, readOutputsFileHash, readProjectName, readRunRecord, rebaseDriveUrl, ref, refKey, refineStartOrder, registerHostType, remoteBackendUrls, renderTokens, resolveDriveDeclaration, resolveHostOutputs, resolveHostPlugins, resolveOrder, resolvePluginContributions, resolveRunnerModule, resolveUserDataPlaceholders, runCompound, runObserveHook, runObserveHookSequential, runProvideHook, runRecordMemberSchema, runRecordOutputSource, runRecordSchema, runTransformHook, runnerBaseSchema, runnerHandleSchema, runnerKindSchema, runnerOutputsSchema, scanHostImports, schemaAtPath, seedDrives, spawnHost, stripComments, substituteBuiltinEnv, toStartedHandle, tokenKeyOf, tokenSchema, tokenable, unwrapEscapes, validateDeclaredHost, validateHost, writeRunRecord };\n\n//# sourceMappingURL=index.mjs.map"],"names":[],"mappings":";;;;;;;;;;;AA4OA,eAAe,UAAU,MAAM,SAAS;CACvC,MAAM,SAAS;EACd,QAAQ,CAAC;EACT,UAAU,CAAC;CACZ;CACA,MAAM,OAAO,SAAS,KAAK;CAC3B,MAAM,QAAQ,OAAO,QAAQ,IAAI;CACjC,MAAM,OAAO,QAAQ,QAAQ;CAC7B,IAAI;CACJ,IAAI;CACJ,IAAI;EACH,QAAQ,MAAM,SAAS,QAAQ,aAAa,IAAI,EAAA,CAAG;EACnD,SAAS,MAAM,oBAAoB,QAAQ,aAAa,KAAK,OAAO,MAAM;CAC3E,SAAS,OAAO;EACf,MAAM,QAAQ,IAAI,KAAK;EACvB,OAAO;CACR;CACA,MAAM,YAAY,KAAK,OAAO;CAC9B,IAAI,OAAO,SAAS,YAAY;EAC/B,MAAM,cAAc,QAAQ,SAAS;GACpC;GACA;GACA;GACA;GACA;EACD,CAAC;EACD,OAAO;CACR;CACA,MAAM,OAAO,aAAa,IAAI;CAC9B,MAAM,YAAY,MAAM,cAAc,QAAQ,aAAa,IAAI;CAC/D,MAAM,aAAa,QAAQ,SAAS;EACnC;EACA;EACA;EACA;EACA;EACA,iBAAiB,uBAAuB,SAAS;EACjD,MAAM;CACP,CAAC;CACD,OAAO;AACR;;AAEA,SAAS,cAAc,QAAQ,SAAS,iBAAiB;CACxD,MAAM,QAAQ,OAAO,QAAQ,QAAQ,IAAI;CACzC,MAAM,EAAE,MAAM,QAAQ,cAAc;CACpC,IAAI;EACH,QAAQ,QAAQ,WAAW,QAAQ,IAAI;CACxC,SAAS,OAAO;EACf,MAAM,YAAY,IAAI,KAAK;CAC5B;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ACN,MAAM;EACP,EAAE,GAAG,MAAM,2BAA2B,CAAC,CAAC;EACxC,kBAAkB;CACnB,EAAE;AACH","debug_id":"9fc09fc9-4f15-550a-a799-b2774c7feaf8"}
@@ -1,7 +1,7 @@
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]="12291c6c-c10c-513b-bb73-4a9e8362c0b4")}catch(e){}}();
3
- import { A as readProjectName, B as validateDeclaredHost, C as outputSitesOf, D as processResolveEnv, E as probeRun, F as resolvePluginContributions, I as resolveRunnerModule, L as runRecordOutputSource, M as renderTokens, N as resolveHostOutputs, O as producerOutputsSchemas, R as runnerOutputsSchema, S as outputRefsOf, V as validateHost, _ as isToken, a as collectTokenSites, b as memberForRef, f as envSitesOf, l as describeToken, m as formatPath, o as compoundOutputSource, p as findDeadConnectConfig, s as declaredHostSchemas, u as drivesSchema, v as loadHost, w as planCompound, y as loadProducers } from "./compound-B6RZMA0Y-Cv3XMQ3Y.mjs";
4
- import { a as mergeDrivePlan, n as explainDrivePlan } from "./dist-CCLkwpTS.mjs";
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]="1c4096ed-cc4f-5917-b403-860a6c40e78d")}catch(e){}}();
3
+ import { D as loadHost, J as runRecordOutputSource, K as resolvePluginContributions, L as probeRun, M as outputRefsOf, N as outputSitesOf, O as loadProducers, P as planCompound, R as processResolveEnv, T as isToken, U as renderTokens, V as readProjectName, W as resolveHostOutputs, Y as runnerOutputsSchema, _ as findDeadConnectConfig, c as collectTokenSites, d as declaredHostSchemas, et as validateDeclaredHost, g as envSitesOf, k as memberForRef, l as compoundOutputSource, m as drivesSchema, p as describeToken, q as resolveRunnerModule, tt as validateHost, y as formatPath, z as producerOutputsSchemas } from "./compound-Gjt5rBfF-BmSW1XPB.mjs";
4
+ import { o as mergeDrivePlan, r as explainDrivePlan } from "./dist-BVqNlv1z.mjs";
5
5
  //#region src/services/run/explain.ts
6
6
  const TOPICS = ["drives", "outputs"];
7
7
  async function loadView(projectRoot, name) {
@@ -237,5 +237,5 @@ function explainOutputs(name, view) {
237
237
  //#endregion
238
238
  export { explainHost };
239
239
 
240
- //# sourceMappingURL=explain-DUXbB9jf.mjs.map
241
- //# debugId=12291c6c-c10c-513b-bb73-4a9e8362c0b4
240
+ //# sourceMappingURL=explain-CPD1tzoV.mjs.map
241
+ //# debugId=1c4096ed-cc4f-5917-b403-860a6c40e78d
@@ -1 +1 @@
1
- {"version":3,"file":"explain-DUXbB9jf.mjs","sources":["../src/services/run/explain.ts"],"sourcesContent":["import {\n collectTokenSites,\n compoundOutputSource,\n CONNECT_RUNNER,\n declaredHostSchemas,\n describeToken,\n drivesSchema,\n envSitesOf,\n explainDrivePlan,\n findDeadConnectConfig,\n formatPath,\n isToken,\n loadHost,\n loadProducers,\n memberForRef,\n mergeDrivePlan,\n outputRefsOf,\n outputSitesOf,\n planCompound,\n probeRun,\n processResolveEnv,\n producerOutputsSchemas,\n readProjectName,\n renderTokens,\n resolveHostOutputs,\n resolvePluginContributions,\n resolveRunnerModule,\n runnerOutputsSchema,\n runRecordOutputSource,\n validateDeclaredHost,\n validateHost,\n type ChildWrapper,\n type DriveDeclaration,\n type HostDefinition,\n type OutputSource,\n type PluginEntryData,\n type ReactorHostInput,\n type RunnerModule,\n} from \"@powerhousedao/host-core\";\n\n/**\n * `ph run <host> --explain <topic>`: print instead of running, after the\n * same declared validation `ph run` does first (so a printed explain is a\n * host that loads). `drives`: the merged drive plan with provenance\n * (browser-only plugins listed as unresolvable). `outputs`: the resolution\n * plan — consumed outputs and their producers, `$env` names, the compound\n * start order the tokens imply, which producers are running and, for a\n * running producer, the value each token resolves to now. A `$map` in\n * `reactor.drives` is shown as the token and, when its producer runs, as the\n * drives it renders.\n */\n\ninterface ExplainOptions {\n host: string;\n topic: string;\n}\n\nconst TOPICS = [\"drives\", \"outputs\"];\n\n/** A reactor host as explained: a standalone host, or a compound member\n * with its wrapper applied (declared form). */\ninterface ReactorView {\n name: string;\n runner: HostDefinition[\"runner\"];\n config?: Record<string, unknown>;\n reactor?: ReactorHostInput[\"reactor\"];\n}\n\ninterface MemberView {\n key: string;\n wrapper: ChildWrapper;\n host: ReactorView;\n runner: RunnerModule;\n specifier: string;\n file: string;\n /** Where the effective `config` lives (a wrapper `config` is a full\n * statement in the compound's file). */\n configWhere: string;\n}\n\ninterface LoadedView {\n host: HostDefinition;\n runner: RunnerModule;\n specifier: string;\n file: string;\n /** Set for a compound. */\n members?: MemberView[];\n /** Where tokens resolve NOW (for printing values): a standalone host's\n * producers' live run records; a compound's own live record (its members'\n * outputs), or none when it is not running. */\n source?: OutputSource;\n}\n\nasync function loadView(\n projectRoot: string,\n name: string,\n): Promise<LoadedView> {\n const loaded = await loadHost(projectRoot, name);\n const specifier = loaded.host.runner.module;\n const runner = await resolveRunnerModule(projectRoot, specifier);\n const file = `hosts/${name}/host.js`;\n if (runner.kind !== \"compound\") {\n const producers = await loadProducers(\n projectRoot,\n outputRefsOf(loaded.host),\n );\n validateDeclaredHost(runner, specifier, loaded.host, file, {\n outputsSchemaOf: producerOutputsSchemas(producers),\n });\n // The same lookup `ph run` resolves through.\n const source = runRecordOutputSource(projectRoot, {\n consumer: name,\n producers,\n projectName: readProjectName(projectRoot),\n });\n return { host: loaded.host, runner, specifier, file, source };\n }\n validateDeclaredHost(runner, specifier, loaded.host, file);\n validateHost(runner, specifier, loaded.host, file, { tokens: \"allow\" });\n // The compound runner's schema owns `config`; `children` is shared.\n const children = declaredHostSchemas.childrenSchema.parse(\n loaded.host.children,\n );\n const members: MemberView[] = [];\n for (const [key, wrapper] of Object.entries(children)) {\n const base = (await loadHost(projectRoot, wrapper.host)).host;\n const reactor = wrapper.reactor ?? base.reactor;\n const config = wrapper.config ?? base.config;\n const host: ReactorView = {\n name: base.name,\n runner: { ...base.runner, ...wrapper.runner },\n ...(config !== undefined ? { config } : {}),\n ...(reactor !== undefined ? { reactor } : {}),\n };\n const memberSpecifier = host.runner.module;\n members.push({\n key,\n wrapper,\n host,\n runner: await resolveRunnerModule(projectRoot, memberSpecifier),\n specifier: memberSpecifier,\n file: `hosts/${wrapper.host}/host.js`,\n configWhere:\n wrapper.config !== undefined\n ? `hosts/${name}/host.js (children.${key}.config)`\n : `hosts/${wrapper.host}/host.js`,\n });\n }\n const refs = members.map((m) => ({ key: m.key, host: m.wrapper.host }));\n for (const m of members) {\n validateDeclaredHost(m.runner, m.specifier, m.host, m.file, {\n outputsSchemaOf: (ref) => {\n const target = memberForRef(ref, refs);\n if (\"error\" in target) return { error: target.error };\n const producer = members.find((p) => p.key === target.key);\n return producer\n ? runnerOutputsSchema(\n producer.runner,\n producer.specifier,\n `member \"${producer.key}\"`,\n )\n : { error: `names member \"${target.key}\", which is not declared.` };\n },\n });\n }\n // Members read each other's live outputs: shown only while this\n // compound runs (its record carries every member's outputs).\n const probe = probeRun(\n projectRoot,\n loaded.host.name,\n readProjectName(projectRoot),\n );\n const live = new Map<string, unknown>();\n if (probe.status === \"live\") {\n for (const [key, member] of Object.entries(probe.record.members ?? {})) {\n live.set(key, member.outputs);\n }\n }\n const source =\n probe.status === \"live\"\n ? compoundOutputSource(refs, live, loaded.host.name)\n : undefined;\n return { host: loaded.host, runner, specifier, file, members, source };\n}\n\n/** A token's value from running producers, or undefined (producer not\n * running, or the token reads the environment: `$env` values may be\n * secrets, so explain never prints them). */\nfunction currentValue(token: unknown, source?: OutputSource): unknown {\n if (!source) return undefined;\n if (collectTokenSites(token).some((site) => site.key === \"$env\")) {\n return undefined;\n }\n try {\n return resolveHostOutputs(token, { outputs: source });\n } catch {\n return undefined;\n }\n}\n\nexport async function explainHost(options: ExplainOptions): Promise<void> {\n if (!TOPICS.includes(options.topic)) {\n throw new Error(\n `Unknown --explain topic \"${options.topic}\" (supported: ${TOPICS.join(\", \")}).`,\n );\n }\n const projectRoot = process.cwd();\n const view = await loadView(projectRoot, options.host);\n if (options.topic === \"outputs\") {\n explainOutputs(options.host, view);\n return;\n }\n\n if (view.members) {\n // One plan per member, with the wrapper's full-statement semantics.\n const verb = view.host.runner.defaultVerb ?? \"run\";\n for (const m of view.members) {\n await explainDrives(\n projectRoot,\n `${options.host} › ${m.key} (${m.wrapper.host})`,\n m.host,\n verb,\n m.file,\n m.configWhere,\n view.source,\n );\n }\n return;\n }\n await explainDrives(\n projectRoot,\n options.host,\n view.host,\n \"run\",\n view.file,\n view.file,\n view.source,\n );\n}\n\n/* ------------------------------------------------------------------ drives */\n\nasync function explainDrives(\n projectRoot: string,\n label: string,\n host: ReactorView,\n verb: string,\n where: string,\n configWhere: string,\n source?: OutputSource,\n): Promise<void> {\n const entries: PluginEntryData[] = host.runner.plugins ?? [];\n const contributions =\n entries.length > 0\n ? await resolvePluginContributions(projectRoot, verb, entries, where)\n : { drives: [], unresolved: [] };\n const contributed = contributions.drives.map(({ declaration, source }) => {\n const parsed = drivesSchema.safeParse([declaration]);\n if (!parsed.success) {\n throw new Error(\n `${where}: plugin \"${source}\" contributes an invalid drive declaration.`,\n );\n }\n return { declaration: parsed.data[0], source };\n });\n // Declared drives may carry output tokens (a remote url): shown as\n // «$output …», resolved only at `ph run`. The whole list may be a token\n // (`$map` over a producer's drives): rendered from the running producer\n // when there is one, otherwise named and left out of the plan.\n const rawDrives: unknown = host.reactor?.drives ?? [];\n let listed: unknown = rawDrives;\n let listNote: string | undefined;\n if (isToken(rawDrives)) {\n const value = currentValue(rawDrives, source);\n listed = Array.isArray(value) ? value : [];\n listNote = ` reactor.drives ← «${describeToken(rawDrives)}»${\n Array.isArray(value)\n ? \" (rendered from the running producer's outputs)\"\n : \" (rendered at ph run from the producer's live outputs; its producer is not running now, so the plan below leaves them out)\"\n }`;\n }\n const parsed = drivesSchema.safeParse(renderTokens(listed));\n if (!parsed.success && listNote === undefined) {\n // a literal list: declared validation already ran; keep its error\n throw parsed.error;\n }\n const declared: DriveDeclaration[] = parsed.success ? parsed.data : [];\n console.log(`[${label}]`);\n if (listNote) console.log(listNote);\n if (!parsed.success) {\n console.log(\n ` the rendered drives fail the drive schema (ph run rejects them): ${parsed.error.issues\n .map((i) => `${i.path.map(String).join(\".\") || \"<root>\"}: ${i.message}`)\n .join(\"; \")}`,\n );\n }\n console.log(\n explainDrivePlan(mergeDrivePlan(projectRoot, declared, contributed)),\n );\n for (const module of contributions.unresolved) {\n const entry = entries\n .map((e) => (typeof e === \"string\" ? { module: e } : e))\n .find((e) => e.module === module);\n const drive: unknown =\n entry && \"config\" in entry ? entry.config?.drive : undefined;\n const attached =\n typeof drive === \"string\"\n ? ` attaches ${drive}`\n : isToken(drive)\n ? ` attaches «${describeToken(drive)}»`\n : \"\";\n console.log(\n ` (browser plugin ${module}: not resolvable from the project tree)${attached}`,\n );\n }\n // The same dead-config warnings the connect runner prints at boot,\n // naming the file the config lives in.\n if (host.runner.module === CONNECT_RUNNER) {\n for (const warning of findDeadConnectConfig(\n host.config,\n host.runner.plugins,\n verb,\n configWhere,\n )) {\n console.warn(warning.message);\n }\n }\n}\n\n/* ----------------------------------------------------------------- outputs */\n\nfunction outputKeys(runner: RunnerModule): string {\n const schema = runner.outputsSchema;\n if (typeof schema !== \"object\" || schema === null) return \"(no outputs)\";\n const shape =\n \"shape\" in schema && typeof schema.shape === \"object\" && schema.shape\n ? Object.keys(schema.shape)\n : [];\n return shape.length ? shape.join(\", \") : \"(declared)\";\n}\n\nfunction printConsumes(\n host: unknown,\n indent: string,\n producerNote: (folder: string, member?: string) => string,\n source?: OutputSource,\n): void {\n const outputs = outputSitesOf(host);\n const env = envSitesOf(host);\n if (outputs.length === 0 && env.length === 0) {\n console.log(`${indent}consumes: nothing (no $output or $env tokens)`);\n return;\n }\n const valueLine = (token: unknown) => {\n const value = currentValue(token, source);\n if (value !== undefined) {\n console.log(`${indent} = ${JSON.stringify(value)}`);\n }\n };\n for (const site of outputs) {\n const token = { $output: { ...site.ref, path: site.outputPath } };\n console.log(\n `${indent}${site.path} ← ${describeToken(token)}${producerNote(site.ref.host, site.ref.member)}`,\n );\n valueLine(token);\n }\n // Composite tokens (`$concat`, `$map`) outside any template: the value\n // the field gets, once its producers run.\n for (const site of collectTokenSites(host)) {\n const nested =\n site.scopes.length > 0 ||\n site.position === \"concat\" ||\n site.position === \"over\";\n if (nested || (site.key !== \"$concat\" && site.key !== \"$map\")) continue;\n console.log(\n `${indent}${formatPath(site.path)} ← ${describeToken(site.token)}`,\n );\n valueLine(site.token);\n }\n const { env: processEnv } = processResolveEnv(process.cwd());\n for (const site of env) {\n const builtin = site.name === \"userData\" || site.name === \"projectRoot\";\n const state =\n builtin || processEnv?.[site.name] !== undefined\n ? \"set\"\n : site.optional\n ? \"unset: the property is omitted\"\n : \"UNSET: ph run fails\";\n console.log(\n `${indent}${site.path} ← $env ${site.name}${site.optional ? \" (optional)\" : \"\"} [${state}]`,\n );\n }\n}\n\nfunction explainOutputs(name: string, view: LoadedView): void {\n if (!view.members) {\n const source = view.source;\n console.log(`[${name}] ${view.specifier}`);\n console.log(` produces: ${outputKeys(view.runner)}`);\n printConsumes(\n view.host,\n \" \",\n (folder, member) => {\n const ref =\n member === undefined ? { host: folder } : { host: folder, member };\n return source?.lookup(ref).status === \"available\"\n ? ` (host \"${folder}\": running)`\n : ` (host \"${folder}\": not running; start it first: ph run ${folder})`;\n },\n source,\n );\n return;\n }\n\n const members = view.members;\n const refs = members.map((x) => ({ key: x.key, host: x.wrapper.host }));\n const config: unknown = view.host.config;\n const startOrder =\n typeof config === \"object\" &&\n config !== null &&\n \"startOrder\" in config &&\n Array.isArray(config.startOrder)\n ? config.startOrder.filter((k): k is string => typeof k === \"string\")\n : undefined;\n const plan = planCompound(\n members.map((m) => ({\n key: m.key,\n host: m.wrapper.host,\n refs: outputSitesOf(m.host).map(({ ref, path }) => ({ ref, path })),\n })),\n startOrder,\n );\n console.log(\n `[${name}] start order (${plan.source === \"tokens\" ? \"from the output tokens\" : \"config.startOrder, checked against the tokens\"}):`,\n );\n plan.order.forEach((key, index) => {\n const m = members.find((x) => x.key === key);\n const needs = plan.edges\n .filter((e) => e.consumer === key)\n .map((e) => e.producer);\n console.log(\n ` ${index + 1}. ${key} (${m?.wrapper.host ?? \"?\"})${needs.length ? ` after ${needs.join(\", \")}` : \"\"}`,\n );\n });\n console.log(\" Ctrl-C stops members in reverse order (consumers first).\");\n for (const key of plan.order) {\n const m = members.find((x) => x.key === key);\n if (!m) continue;\n console.log(`[${name} › ${key} (${m.wrapper.host})] ${m.specifier}`);\n console.log(` produces: ${outputKeys(m.runner)}`);\n printConsumes(\n m.host,\n \" \",\n (folder, member) => {\n const ref =\n member === undefined ? { host: folder } : { host: folder, member };\n const target = memberForRef(ref, refs);\n return \"key\" in target\n ? ` (member \"${target.key}\", live outputs)`\n : \"\";\n },\n view.source,\n );\n }\n const own = { ...view.host, children: undefined };\n if (outputSitesOf(own).length > 0 || envSitesOf(own).length > 0) {\n console.log(`[${name}] the compound's own fields:`);\n printConsumes(own, \" \", () => \"\");\n }\n}\n"],"names":[],"mappings":";;;;;AAyDA,MAAM,SAAS,CAAC,UAAU,SAAS;AAoCnC,eAAe,SACb,aACA,MACqB;CACrB,MAAM,SAAS,MAAM,SAAS,aAAa,IAAI;CAC/C,MAAM,YAAY,OAAO,KAAK,OAAO;CACrC,MAAM,SAAS,MAAM,oBAAoB,aAAa,SAAS;CAC/D,MAAM,OAAO,SAAS,KAAK;CAC3B,IAAI,OAAO,SAAS,YAAY;EAC9B,MAAM,YAAY,MAAM,cACtB,aACA,aAAa,OAAO,IAAI,CAC1B;EACA,qBAAqB,QAAQ,WAAW,OAAO,MAAM,MAAM,EACzD,iBAAiB,uBAAuB,SAAS,EACnD,CAAC;EAED,MAAM,SAAS,sBAAsB,aAAa;GAChD,UAAU;GAC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AI,CAAC,GAAG;EACR,QAAQ,IAAI,IAAI,KAAK,KAAK,IAAI,IAAI,EAAE,QAAQ,KAAK,KAAK,EAAE,WAAW;EACnE,QAAQ,IAAI,eAAe,WAAW,EAAE,MAAM,GAAG;EACjD,cACE,EAAE,MACF,OACC,QAAQ,WAAW;GAGlB,MAAM,SAAS,aADb,WAAW,KAAA,IAAY,EAAE,MAAM,OAAO,IAAI;IAAE,MAAM;IAAQ;GAAO,GAClC,IAAI;GACrC,OAAO,SAAS,SACZ,cAAc,OAAO,IAAI,oBACzB;EACN,GACA,KAAK,MACP;CACF;CACA,MAAM,MAAM;EAAE,GAAG,KAAK;EAAM,UAAU,KAAA;CAAU;CAChD,IAAI,cAAc,GAAG,CAAC,CAAC,SAAS,KAAK,WAAW,GAAG,CAAC,CAAC,SAAS,GAAG;EAC/D,QAAQ,IAAI,IAAI,KAAK,6BAA6B;EAClD,cAAc,KAAK,YAAY,EAAE;CACnC;AACF","debug_id":"12291c6c-c10c-513b-bb73-4a9e8362c0b4"}
1
+ {"version":3,"file":"explain-CPD1tzoV.mjs","sources":["../src/services/run/explain.ts"],"sourcesContent":["import {\n collectTokenSites,\n compoundOutputSource,\n CONNECT_RUNNER,\n declaredHostSchemas,\n describeToken,\n drivesSchema,\n envSitesOf,\n explainDrivePlan,\n findDeadConnectConfig,\n formatPath,\n isToken,\n loadHost,\n loadProducers,\n memberForRef,\n mergeDrivePlan,\n outputRefsOf,\n outputSitesOf,\n planCompound,\n probeRun,\n processResolveEnv,\n producerOutputsSchemas,\n readProjectName,\n renderTokens,\n resolveHostOutputs,\n resolvePluginContributions,\n resolveRunnerModule,\n runnerOutputsSchema,\n runRecordOutputSource,\n validateDeclaredHost,\n validateHost,\n type ChildWrapper,\n type DriveDeclaration,\n type HostDefinition,\n type OutputSource,\n type PluginEntryData,\n type ReactorHostInput,\n type RunnerModule,\n} from \"@powerhousedao/host-core\";\n\n/**\n * `ph run <host> --explain <topic>`: print instead of running, after the\n * same declared validation `ph run` does first (so a printed explain is a\n * host that loads). `drives`: the merged drive plan with provenance\n * (browser-only plugins listed as unresolvable). `outputs`: the resolution\n * plan — consumed outputs and their producers, `$env` names, the compound\n * start order the tokens imply, which producers are running and, for a\n * running producer, the value each token resolves to now. A `$map` in\n * `reactor.drives` is shown as the token and, when its producer runs, as the\n * drives it renders.\n */\n\ninterface ExplainOptions {\n host: string;\n topic: string;\n}\n\nconst TOPICS = [\"drives\", \"outputs\"];\n\n/** A reactor host as explained: a standalone host, or a compound member\n * with its wrapper applied (declared form). */\ninterface ReactorView {\n name: string;\n runner: HostDefinition[\"runner\"];\n config?: Record<string, unknown>;\n reactor?: ReactorHostInput[\"reactor\"];\n}\n\ninterface MemberView {\n key: string;\n wrapper: ChildWrapper;\n host: ReactorView;\n runner: RunnerModule;\n specifier: string;\n file: string;\n /** Where the effective `config` lives (a wrapper `config` is a full\n * statement in the compound's file). */\n configWhere: string;\n}\n\ninterface LoadedView {\n host: HostDefinition;\n runner: RunnerModule;\n specifier: string;\n file: string;\n /** Set for a compound. */\n members?: MemberView[];\n /** Where tokens resolve NOW (for printing values): a standalone host's\n * producers' live run records; a compound's own live record (its members'\n * outputs), or none when it is not running. */\n source?: OutputSource;\n}\n\nasync function loadView(\n projectRoot: string,\n name: string,\n): Promise<LoadedView> {\n const loaded = await loadHost(projectRoot, name);\n const specifier = loaded.host.runner.module;\n const runner = await resolveRunnerModule(projectRoot, specifier);\n const file = `hosts/${name}/host.js`;\n if (runner.kind !== \"compound\") {\n const producers = await loadProducers(\n projectRoot,\n outputRefsOf(loaded.host),\n );\n validateDeclaredHost(runner, specifier, loaded.host, file, {\n outputsSchemaOf: producerOutputsSchemas(producers),\n });\n // The same lookup `ph run` resolves through.\n const source = runRecordOutputSource(projectRoot, {\n consumer: name,\n producers,\n projectName: readProjectName(projectRoot),\n });\n return { host: loaded.host, runner, specifier, file, source };\n }\n validateDeclaredHost(runner, specifier, loaded.host, file);\n validateHost(runner, specifier, loaded.host, file, { tokens: \"allow\" });\n // The compound runner's schema owns `config`; `children` is shared.\n const children = declaredHostSchemas.childrenSchema.parse(\n loaded.host.children,\n );\n const members: MemberView[] = [];\n for (const [key, wrapper] of Object.entries(children)) {\n const base = (await loadHost(projectRoot, wrapper.host)).host;\n const reactor = wrapper.reactor ?? base.reactor;\n const config = wrapper.config ?? base.config;\n const host: ReactorView = {\n name: base.name,\n runner: { ...base.runner, ...wrapper.runner },\n ...(config !== undefined ? { config } : {}),\n ...(reactor !== undefined ? { reactor } : {}),\n };\n const memberSpecifier = host.runner.module;\n members.push({\n key,\n wrapper,\n host,\n runner: await resolveRunnerModule(projectRoot, memberSpecifier),\n specifier: memberSpecifier,\n file: `hosts/${wrapper.host}/host.js`,\n configWhere:\n wrapper.config !== undefined\n ? `hosts/${name}/host.js (children.${key}.config)`\n : `hosts/${wrapper.host}/host.js`,\n });\n }\n const refs = members.map((m) => ({ key: m.key, host: m.wrapper.host }));\n for (const m of members) {\n validateDeclaredHost(m.runner, m.specifier, m.host, m.file, {\n outputsSchemaOf: (ref) => {\n const target = memberForRef(ref, refs);\n if (\"error\" in target) return { error: target.error };\n const producer = members.find((p) => p.key === target.key);\n return producer\n ? runnerOutputsSchema(\n producer.runner,\n producer.specifier,\n `member \"${producer.key}\"`,\n )\n : { error: `names member \"${target.key}\", which is not declared.` };\n },\n });\n }\n // Members read each other's live outputs: shown only while this\n // compound runs (its record carries every member's outputs).\n const probe = probeRun(\n projectRoot,\n loaded.host.name,\n readProjectName(projectRoot),\n );\n const live = new Map<string, unknown>();\n if (probe.status === \"live\") {\n for (const [key, member] of Object.entries(probe.record.members ?? {})) {\n live.set(key, member.outputs);\n }\n }\n const source =\n probe.status === \"live\"\n ? compoundOutputSource(refs, live, loaded.host.name)\n : undefined;\n return { host: loaded.host, runner, specifier, file, members, source };\n}\n\n/** A token's value from running producers, or undefined (producer not\n * running, or the token reads the environment: `$env` values may be\n * secrets, so explain never prints them). */\nfunction currentValue(token: unknown, source?: OutputSource): unknown {\n if (!source) return undefined;\n if (collectTokenSites(token).some((site) => site.key === \"$env\")) {\n return undefined;\n }\n try {\n return resolveHostOutputs(token, { outputs: source });\n } catch {\n return undefined;\n }\n}\n\nexport async function explainHost(options: ExplainOptions): Promise<void> {\n if (!TOPICS.includes(options.topic)) {\n throw new Error(\n `Unknown --explain topic \"${options.topic}\" (supported: ${TOPICS.join(\", \")}).`,\n );\n }\n const projectRoot = process.cwd();\n const view = await loadView(projectRoot, options.host);\n if (options.topic === \"outputs\") {\n explainOutputs(options.host, view);\n return;\n }\n\n if (view.members) {\n // One plan per member, with the wrapper's full-statement semantics.\n const verb = view.host.runner.defaultVerb ?? \"run\";\n for (const m of view.members) {\n await explainDrives(\n projectRoot,\n `${options.host} › ${m.key} (${m.wrapper.host})`,\n m.host,\n verb,\n m.file,\n m.configWhere,\n view.source,\n );\n }\n return;\n }\n await explainDrives(\n projectRoot,\n options.host,\n view.host,\n \"run\",\n view.file,\n view.file,\n view.source,\n );\n}\n\n/* ------------------------------------------------------------------ drives */\n\nasync function explainDrives(\n projectRoot: string,\n label: string,\n host: ReactorView,\n verb: string,\n where: string,\n configWhere: string,\n source?: OutputSource,\n): Promise<void> {\n const entries: PluginEntryData[] = host.runner.plugins ?? [];\n const contributions =\n entries.length > 0\n ? await resolvePluginContributions(projectRoot, verb, entries, where)\n : { drives: [], unresolved: [] };\n const contributed = contributions.drives.map(({ declaration, source }) => {\n const parsed = drivesSchema.safeParse([declaration]);\n if (!parsed.success) {\n throw new Error(\n `${where}: plugin \"${source}\" contributes an invalid drive declaration.`,\n );\n }\n return { declaration: parsed.data[0], source };\n });\n // Declared drives may carry output tokens (a remote url): shown as\n // «$output …», resolved only at `ph run`. The whole list may be a token\n // (`$map` over a producer's drives): rendered from the running producer\n // when there is one, otherwise named and left out of the plan.\n const rawDrives: unknown = host.reactor?.drives ?? [];\n let listed: unknown = rawDrives;\n let listNote: string | undefined;\n if (isToken(rawDrives)) {\n const value = currentValue(rawDrives, source);\n listed = Array.isArray(value) ? value : [];\n listNote = ` reactor.drives ← «${describeToken(rawDrives)}»${\n Array.isArray(value)\n ? \" (rendered from the running producer's outputs)\"\n : \" (rendered at ph run from the producer's live outputs; its producer is not running now, so the plan below leaves them out)\"\n }`;\n }\n const parsed = drivesSchema.safeParse(renderTokens(listed));\n if (!parsed.success && listNote === undefined) {\n // a literal list: declared validation already ran; keep its error\n throw parsed.error;\n }\n const declared: DriveDeclaration[] = parsed.success ? parsed.data : [];\n console.log(`[${label}]`);\n if (listNote) console.log(listNote);\n if (!parsed.success) {\n console.log(\n ` the rendered drives fail the drive schema (ph run rejects them): ${parsed.error.issues\n .map((i) => `${i.path.map(String).join(\".\") || \"<root>\"}: ${i.message}`)\n .join(\"; \")}`,\n );\n }\n console.log(\n explainDrivePlan(mergeDrivePlan(projectRoot, declared, contributed)),\n );\n for (const module of contributions.unresolved) {\n const entry = entries\n .map((e) => (typeof e === \"string\" ? { module: e } : e))\n .find((e) => e.module === module);\n const drive: unknown =\n entry && \"config\" in entry ? entry.config?.drive : undefined;\n const attached =\n typeof drive === \"string\"\n ? ` attaches ${drive}`\n : isToken(drive)\n ? ` attaches «${describeToken(drive)}»`\n : \"\";\n console.log(\n ` (browser plugin ${module}: not resolvable from the project tree)${attached}`,\n );\n }\n // The same dead-config warnings the connect runner prints at boot,\n // naming the file the config lives in.\n if (host.runner.module === CONNECT_RUNNER) {\n for (const warning of findDeadConnectConfig(\n host.config,\n host.runner.plugins,\n verb,\n configWhere,\n )) {\n console.warn(warning.message);\n }\n }\n}\n\n/* ----------------------------------------------------------------- outputs */\n\nfunction outputKeys(runner: RunnerModule): string {\n const schema = runner.outputsSchema;\n if (typeof schema !== \"object\" || schema === null) return \"(no outputs)\";\n const shape =\n \"shape\" in schema && typeof schema.shape === \"object\" && schema.shape\n ? Object.keys(schema.shape)\n : [];\n return shape.length ? shape.join(\", \") : \"(declared)\";\n}\n\nfunction printConsumes(\n host: unknown,\n indent: string,\n producerNote: (folder: string, member?: string) => string,\n source?: OutputSource,\n): void {\n const outputs = outputSitesOf(host);\n const env = envSitesOf(host);\n if (outputs.length === 0 && env.length === 0) {\n console.log(`${indent}consumes: nothing (no $output or $env tokens)`);\n return;\n }\n const valueLine = (token: unknown) => {\n const value = currentValue(token, source);\n if (value !== undefined) {\n console.log(`${indent} = ${JSON.stringify(value)}`);\n }\n };\n for (const site of outputs) {\n const token = { $output: { ...site.ref, path: site.outputPath } };\n console.log(\n `${indent}${site.path} ← ${describeToken(token)}${producerNote(site.ref.host, site.ref.member)}`,\n );\n valueLine(token);\n }\n // Composite tokens (`$concat`, `$map`) outside any template: the value\n // the field gets, once its producers run.\n for (const site of collectTokenSites(host)) {\n const nested =\n site.scopes.length > 0 ||\n site.position === \"concat\" ||\n site.position === \"over\";\n if (nested || (site.key !== \"$concat\" && site.key !== \"$map\")) continue;\n console.log(\n `${indent}${formatPath(site.path)} ← ${describeToken(site.token)}`,\n );\n valueLine(site.token);\n }\n const { env: processEnv } = processResolveEnv(process.cwd());\n for (const site of env) {\n const builtin = site.name === \"userData\" || site.name === \"projectRoot\";\n const state =\n builtin || processEnv?.[site.name] !== undefined\n ? \"set\"\n : site.optional\n ? \"unset: the property is omitted\"\n : \"UNSET: ph run fails\";\n console.log(\n `${indent}${site.path} ← $env ${site.name}${site.optional ? \" (optional)\" : \"\"} [${state}]`,\n );\n }\n}\n\nfunction explainOutputs(name: string, view: LoadedView): void {\n if (!view.members) {\n const source = view.source;\n console.log(`[${name}] ${view.specifier}`);\n console.log(` produces: ${outputKeys(view.runner)}`);\n printConsumes(\n view.host,\n \" \",\n (folder, member) => {\n const ref =\n member === undefined ? { host: folder } : { host: folder, member };\n return source?.lookup(ref).status === \"available\"\n ? ` (host \"${folder}\": running)`\n : ` (host \"${folder}\": not running; start it first: ph run ${folder})`;\n },\n source,\n );\n return;\n }\n\n const members = view.members;\n const refs = members.map((x) => ({ key: x.key, host: x.wrapper.host }));\n const config: unknown = view.host.config;\n const startOrder =\n typeof config === \"object\" &&\n config !== null &&\n \"startOrder\" in config &&\n Array.isArray(config.startOrder)\n ? config.startOrder.filter((k): k is string => typeof k === \"string\")\n : undefined;\n const plan = planCompound(\n members.map((m) => ({\n key: m.key,\n host: m.wrapper.host,\n refs: outputSitesOf(m.host).map(({ ref, path }) => ({ ref, path })),\n })),\n startOrder,\n );\n console.log(\n `[${name}] start order (${plan.source === \"tokens\" ? \"from the output tokens\" : \"config.startOrder, checked against the tokens\"}):`,\n );\n plan.order.forEach((key, index) => {\n const m = members.find((x) => x.key === key);\n const needs = plan.edges\n .filter((e) => e.consumer === key)\n .map((e) => e.producer);\n console.log(\n ` ${index + 1}. ${key} (${m?.wrapper.host ?? \"?\"})${needs.length ? ` after ${needs.join(\", \")}` : \"\"}`,\n );\n });\n console.log(\" Ctrl-C stops members in reverse order (consumers first).\");\n for (const key of plan.order) {\n const m = members.find((x) => x.key === key);\n if (!m) continue;\n console.log(`[${name} › ${key} (${m.wrapper.host})] ${m.specifier}`);\n console.log(` produces: ${outputKeys(m.runner)}`);\n printConsumes(\n m.host,\n \" \",\n (folder, member) => {\n const ref =\n member === undefined ? { host: folder } : { host: folder, member };\n const target = memberForRef(ref, refs);\n return \"key\" in target\n ? ` (member \"${target.key}\", live outputs)`\n : \"\";\n },\n view.source,\n );\n }\n const own = { ...view.host, children: undefined };\n if (outputSitesOf(own).length > 0 || envSitesOf(own).length > 0) {\n console.log(`[${name}] the compound's own fields:`);\n printConsumes(own, \" \", () => \"\");\n }\n}\n"],"names":[],"mappings":";;;;;AAyDA,MAAM,SAAS,CAAC,UAAU,SAAS;AAoCnC,eAAe,SACb,aACA,MACqB;CACrB,MAAM,SAAS,MAAM,SAAS,aAAa,IAAI;CAC/C,MAAM,YAAY,OAAO,KAAK,OAAO;CACrC,MAAM,SAAS,MAAM,oBAAoB,aAAa,SAAS;CAC/D,MAAM,OAAO,SAAS,KAAK;CAC3B,IAAI,OAAO,SAAS,YAAY;EAC9B,MAAM,YAAY,MAAM,cACtB,aACA,aAAa,OAAO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ACtG;CACF,CAAC;CACD,QAAQ,IAAI,4DAA4D;CACxE,KAAK,MAAM,OAAO,KAAK,OAAO;EAC5B,MAAM,IAAI,QAAQ,MAAM,MAAM,EAAE,QAAQ,GAAG;EAC3C,IAAI,CAAC,GAAG;EACR,QAAQ,IAAI,IAAI,KAAK,KAAK,IAAI,IAAI,EAAE,QAAQ,KAAK,KAAK,EAAE,WAAW;EACnE,QAAQ,IAAI,eAAe,WAAW,EAAE,MAAM,GAAG;EACjD,cACE,EAAE,MACF,OACC,QAAQ,WAAW;GAGlB,MAAM,SAAS,aADb,WAAW,KAAA,IAAY,EAAE,MAAM,OAAO,IAAI;IAAE,MAAM;IAAQ;GAAO,GAClC,IAAI;GACrC,OAAO,SAAS,SACZ,cAAc,OAAO,IAAI,oBACzB;EACN,GACA,KAAK,MACP;CACF;CACA,MAAM,MAAM;EAAE,GAAG,KAAK;EAAM,UAAU,KAAA;CAAU;CAChD,IAAI,cAAc,GAAG,CAAC,CAAC,SAAS,KAAK,WAAW,GAAG,CAAC,CAAC,SAAS,GAAG;EAC/D,QAAQ,IAAI,IAAI,KAAK,6BAA6B;EAClD,cAAc,KAAK,YAAY,EAAE;CACnC;AACF","debug_id":"1c4096ed-cc4f-5917-b403-860a6c40e78d"}
@@ -1,7 +1,7 @@
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]="9447b850-b9e5-5086-9f44-7f1ebc256fd9")}catch(e){}}();
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]="5c19513d-41a5-5bb0-9dac-696b59f67061")}catch(e){}}();
3
3
  import { t as isUniformRunnersEnabled } from "./feature-flags-xwqcHEWC.mjs";
4
- import { T as probeHostsFolder } from "./compound-B6RZMA0Y-Cv3XMQ3Y.mjs";
4
+ import { I as probeHostsFolder } from "./compound-Gjt5rBfF-BmSW1XPB.mjs";
5
5
  import { t as warnSubgraphTypeConflicts } from "./warn-subgraph-type-conflicts-BOHBmThq.mjs";
6
6
  import { t as startGenerateHosts } from "./generate-hosts-BFmPIW2X.mjs";
7
7
  import { generateAll } from "@powerhousedao/codegen";
@@ -32,5 +32,5 @@ async function startGenerateAll(args, projectDir) {
32
32
  //#endregion
33
33
  export { startGenerateAll };
34
34
 
35
- //# sourceMappingURL=generate-all-Dgyy_kT-.mjs.map
36
- //# debugId=9447b850-b9e5-5086-9f44-7f1ebc256fd9
35
+ //# sourceMappingURL=generate-all-CaAHbviS.mjs.map
36
+ //# debugId=5c19513d-41a5-5bb0-9dac-696b59f67061
@@ -1 +1 @@
1
- {"version":3,"file":"generate-all-Dgyy_kT-.mjs","sources":["../src/services/generate-all.ts"],"sourcesContent":["import { generateAll } from \"@powerhousedao/codegen\";\nimport { buildTsMorphProject } from \"@powerhousedao/codegen/utils\";\nimport { extractAllDocuments, saveSpec } from \"@powerhousedao/vetra/codegen\";\nimport { probeHostsFolder } from \"@powerhousedao/host-core\";\nimport { isUniformRunnersEnabled } from \"../utils/feature-flags.js\";\nimport { warnSubgraphTypeConflicts } from \"../utils/warn-subgraph-type-conflicts.js\";\nimport { startGenerateHosts } from \"./generate-hosts.js\";\n\nexport async function startGenerateAll(\n args: { extract?: boolean },\n projectDir: string,\n) {\n const project = buildTsMorphProject(projectDir);\n if (args.extract) {\n const all = extractAllDocuments(project);\n for (const doc of [\n ...all.documentModels,\n ...all.editors,\n ...all.processors,\n ...all.subgraphs,\n ...all.apps,\n ]) {\n const path = await saveSpec(doc, projectDir);\n console.log(`Wrote ${path}`);\n }\n return;\n }\n await generateAll(project);\n await project.save();\n await warnSubgraphTypeConflicts(projectDir);\n if (\n isUniformRunnersEnabled() &&\n probeHostsFolder(projectDir).kind === \"present\" &&\n !(await startGenerateHosts(projectDir))\n ) {\n process.exitCode = 1;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAQA,eAAsB,iBACpB,MACA,YACA;CACA,MAAM,UAAU,oBAAoB,UAAU;CAC9C,IAAI,KAAK,SAAS;EAChB,MAAM,MAAM,oBAAoB,OAAO;EACvC,KAAK,MAAM,OAAO;GAChB,GAAG,IAAI;GACP,GAAG,IAAI;GACP,GAAG,IAAI;GACP,GAAG,IAAI;GACP,GAAG,IAAI;EACT,GAAG;GACD,MAAM,OAAO,MAAM,SAAS,KAAK,UAAU;GAC3C,QAAQ,IAAI,SAAS,MAAM;EAC7B;EACA;CACF;CACA,MAAM,YAAY,OAAO;CACzB,MAAM,QAAQ,KAAK;CACnB,MAAM,0BAA0B,UAAU;CAC1C,IACE,wBAAwB,KACxB,iBAAiB,UAAU,CAAC,CAAC,SAAS,aACtC,CAAE,MAAM,mBAAmB,UAAU,GAErC,QAAQ,WAAW;AAEvB","debug_id":"9447b850-b9e5-5086-9f44-7f1ebc256fd9"}
1
+ {"version":3,"file":"generate-all-CaAHbviS.mjs","sources":["../src/services/generate-all.ts"],"sourcesContent":["import { generateAll } from \"@powerhousedao/codegen\";\nimport { buildTsMorphProject } from \"@powerhousedao/codegen/utils\";\nimport { extractAllDocuments, saveSpec } from \"@powerhousedao/vetra/codegen\";\nimport { probeHostsFolder } from \"@powerhousedao/host-core\";\nimport { isUniformRunnersEnabled } from \"../utils/feature-flags.js\";\nimport { warnSubgraphTypeConflicts } from \"../utils/warn-subgraph-type-conflicts.js\";\nimport { startGenerateHosts } from \"./generate-hosts.js\";\n\nexport async function startGenerateAll(\n args: { extract?: boolean },\n projectDir: string,\n) {\n const project = buildTsMorphProject(projectDir);\n if (args.extract) {\n const all = extractAllDocuments(project);\n for (const doc of [\n ...all.documentModels,\n ...all.editors,\n ...all.processors,\n ...all.subgraphs,\n ...all.apps,\n ]) {\n const path = await saveSpec(doc, projectDir);\n console.log(`Wrote ${path}`);\n }\n return;\n }\n await generateAll(project);\n await project.save();\n await warnSubgraphTypeConflicts(projectDir);\n if (\n isUniformRunnersEnabled() &&\n probeHostsFolder(projectDir).kind === \"present\" &&\n !(await startGenerateHosts(projectDir))\n ) {\n process.exitCode = 1;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAQA,eAAsB,iBACpB,MACA,YACA;CACA,MAAM,UAAU,oBAAoB,UAAU;CAC9C,IAAI,KAAK,SAAS;EAChB,MAAM,MAAM,oBAAoB,OAAO;EACvC,KAAK,MAAM,OAAO;GAChB,GAAG,IAAI;GACP,GAAG,IAAI;GACP,GAAG,IAAI;GACP,GAAG,IAAI;GACP,GAAG,IAAI;EACT,GAAG;GACD,MAAM,OAAO,MAAM,SAAS,KAAK,UAAU;GAC3C,QAAQ,IAAI,SAAS,MAAM;EAC7B;EACA;CACF;CACA,MAAM,YAAY,OAAO;CACzB,MAAM,QAAQ,KAAK;CACnB,MAAM,0BAA0B,UAAU;CAC1C,IACE,wBAAwB,KACxB,iBAAiB,UAAU,CAAC,CAAC,SAAS,aACtC,CAAE,MAAM,mBAAmB,UAAU,GAErC,QAAQ,WAAW;AAEvB","debug_id":"5c19513d-41a5-5bb0-9dac-696b59f67061"}
@@ -0,0 +1,72 @@
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]="598034cf-aa42-5189-8607-4625d64996ff")}catch(e){}}();
3
+ import { t as resolveModuleDirName } from "./module-dir-1avCXsBi.mjs";
4
+ import { existsSync } from "node:fs";
5
+ import { join } from "node:path";
6
+ import { generateAllApps, generateApp } from "@powerhousedao/codegen";
7
+ import { buildTsMorphProject, getAppMetadata, getEditorMetadata } from "@powerhousedao/codegen/utils";
8
+ import { extractAppDocuments, generateAppFromDocument, getDocument, saveSpec } from "@powerhousedao/vetra/codegen";
9
+ //#region src/services/generate-app.ts
10
+ const MODULE_FILE_EXPECTATION = "an EditorModule with string literals for config.id, config.name and documentTypes";
11
+ async function startGenerateApp(args, projectDir) {
12
+ const { name, allowedDocumentTypes = [], disableDragAndDrop, document, dir, all, extract, debug } = args;
13
+ if (debug) console.log({ args });
14
+ const project = buildTsMorphProject(projectDir);
15
+ if (extract) {
16
+ const docs = extractAppDocuments(project);
17
+ if (docs.length === 0) console.log("No drive apps found in editors/.");
18
+ for (const doc of docs) {
19
+ const path = await saveSpec(doc, projectDir);
20
+ console.log(`Wrote ${path}`);
21
+ }
22
+ return;
23
+ }
24
+ if (all) {
25
+ const { apps, unreadableDirs } = await generateAllApps(project);
26
+ await project.save();
27
+ if (apps.length === 0 && unreadableDirs.length === 0) console.log("No drive apps found in editors/.");
28
+ for (const app of apps) console.log(`Regenerated app "${app.name}" in editors/${app.dirName}`);
29
+ for (const dirName of unreadableDirs) console.warn(`Skipped editors/${dirName}: expected its module.ts to export ${MODULE_FILE_EXPECTATION}. Kept the manifest's apps.`);
30
+ return;
31
+ } else if (document) {
32
+ const doc = await getDocument(document);
33
+ await generateAppFromDocument(doc, project);
34
+ } else if (name) await generateApp({
35
+ appName: name,
36
+ allowedDocumentTypes,
37
+ isDragAndDropEnabled: !disableDragAndDrop
38
+ }, project);
39
+ else if (dir) {
40
+ const appMetadata = getAppMetadata(project, resolveAppDirName(project, projectDir, dir));
41
+ if (!appMetadata) throw new Error(`Failed to get data for app in dir "${dir}"`);
42
+ const { name: appName, id: appId, dirName: appDirName, allowedDocumentTypes, isDragAndDropEnabled } = appMetadata;
43
+ await generateApp({
44
+ appName,
45
+ appId,
46
+ appDirName,
47
+ allowedDocumentTypes,
48
+ isDragAndDropEnabled
49
+ }, project);
50
+ await project.save();
51
+ console.log(`Regenerated app "${appName}" in editors/${appDirName}`);
52
+ return;
53
+ } else {
54
+ console.log("Please specify one of `name`, `document`, `dir`, `all`, or `extract`.");
55
+ return;
56
+ }
57
+ await project.save();
58
+ }
59
+ /** The app directory that `--dir` names, checked to hold a drive app's module.ts */
60
+ function resolveAppDirName(project, projectDir, dir) {
61
+ const dirName = resolveModuleDirName(projectDir, "editors", dir, "my-app");
62
+ if (!existsSync(join(projectDir, "editors", dirName, "module.ts"))) throw new Error(`editors/${dirName} has no module.ts.`);
63
+ const editorMetadata = getEditorMetadata(project, dirName);
64
+ if (!editorMetadata) throw new Error(`Could not read editors/${dirName}/module.ts: expected ${MODULE_FILE_EXPECTATION}.`);
65
+ if (!editorMetadata.documentTypes.includes("powerhouse/document-drive")) throw new Error(`editors/${dirName} is a document editor, not a drive app: its documentTypes don't include "powerhouse/document-drive". Use \`ph-cli generate editor --dir ${dirName}\` instead.`);
66
+ return dirName;
67
+ }
68
+ //#endregion
69
+ export { startGenerateApp };
70
+
71
+ //# sourceMappingURL=generate-app-hm6CJ_4O.mjs.map
72
+ //# debugId=598034cf-aa42-5189-8607-4625d64996ff
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-app-hm6CJ_4O.mjs","sources":["../src/services/generate-app.ts"],"sourcesContent":["import { generateAllApps, generateApp } from \"@powerhousedao/codegen\";\nimport {\n buildTsMorphProject,\n getAppMetadata,\n getEditorMetadata,\n} from \"@powerhousedao/codegen/utils\";\nimport {\n extractAppDocuments,\n generateAppFromDocument,\n getDocument,\n saveSpec,\n} from \"@powerhousedao/vetra/codegen\";\nimport type { AppModuleDocument } from \"@powerhousedao/vetra/document-models/app-module\";\nimport { existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport type { GenerateAppArgs } from \"../types.js\";\nimport { resolveModuleDirName } from \"../utils/module-dir.js\";\n\nconst MODULE_FILE_EXPECTATION =\n \"an EditorModule with string literals for config.id, config.name and documentTypes\";\n\nexport async function startGenerateApp(\n args: GenerateAppArgs,\n projectDir: string,\n) {\n const {\n name,\n allowedDocumentTypes = [],\n disableDragAndDrop,\n document,\n dir,\n all,\n extract,\n debug,\n } = args;\n if (debug) {\n console.log({ args });\n }\n const project = buildTsMorphProject(projectDir);\n if (extract) {\n const docs = extractAppDocuments(project);\n if (docs.length === 0) {\n console.log(\"No drive apps found in editors/.\");\n }\n for (const doc of docs) {\n const path = await saveSpec(doc, projectDir);\n console.log(`Wrote ${path}`);\n }\n return;\n }\n if (all) {\n const { apps, unreadableDirs } = await generateAllApps(project);\n await project.save();\n if (apps.length === 0 && unreadableDirs.length === 0) {\n console.log(\"No drive apps found in editors/.\");\n }\n for (const app of apps) {\n console.log(`Regenerated app \"${app.name}\" in editors/${app.dirName}`);\n }\n for (const dirName of unreadableDirs) {\n console.warn(\n `Skipped editors/${dirName}: expected its module.ts to export ${MODULE_FILE_EXPECTATION}. Kept the manifest's apps.`,\n );\n }\n return;\n } else if (document) {\n const doc = (await getDocument(document)) as AppModuleDocument;\n await generateAppFromDocument(doc, project);\n } else if (name) {\n await generateApp(\n {\n appName: name,\n allowedDocumentTypes,\n isDragAndDropEnabled: !disableDragAndDrop,\n },\n project,\n );\n } else if (dir) {\n const appMetadata = getAppMetadata(\n project,\n resolveAppDirName(project, projectDir, dir),\n );\n if (!appMetadata) {\n throw new Error(`Failed to get data for app in dir \"${dir}\"`);\n }\n const {\n name: appName,\n id: appId,\n dirName: appDirName,\n allowedDocumentTypes,\n isDragAndDropEnabled,\n } = appMetadata;\n\n await generateApp(\n {\n appName,\n appId,\n appDirName,\n allowedDocumentTypes,\n isDragAndDropEnabled,\n },\n project,\n );\n await project.save();\n console.log(`Regenerated app \"${appName}\" in editors/${appDirName}`);\n return;\n } else {\n console.log(\n \"Please specify one of `name`, `document`, `dir`, `all`, or `extract`.\",\n );\n return;\n }\n await project.save();\n}\n\n/** The app directory that `--dir` names, checked to hold a drive app's module.ts */\nfunction resolveAppDirName(\n project: ReturnType<typeof buildTsMorphProject>,\n projectDir: string,\n dir: string,\n) {\n const dirName = resolveModuleDirName(projectDir, \"editors\", dir, \"my-app\");\n if (!existsSync(join(projectDir, \"editors\", dirName, \"module.ts\"))) {\n throw new Error(`editors/${dirName} has no module.ts.`);\n }\n const editorMetadata = getEditorMetadata(project, dirName);\n if (!editorMetadata) {\n throw new Error(\n `Could not read editors/${dirName}/module.ts: expected ${MODULE_FILE_EXPECTATION}.`,\n );\n }\n if (!editorMetadata.documentTypes.includes(\"powerhouse/document-drive\")) {\n throw new Error(\n `editors/${dirName} is a document editor, not a drive app: its documentTypes don't include \"powerhouse/document-drive\". Use \\`ph-cli generate editor --dir ${dirName}\\` instead.`,\n );\n }\n return dirName;\n}\n"],"names":[],"mappings":";;;;;;;;;AAkBA,MAAM,0BACJ;AAEF,eAAsB,iBACpB,MACA,YACA;CACA,MAAM,EACJ,MACA,uBAAuB,CAAC,GACxB,oBACA,UACA,KACA,KACA,SACA,UACE;CACJ,IAAI,OACF,QAAQ,IAAI,EAAE,KAAK,CAAC;CAEtB,MAAM,UAAU,oBAAoB,UAAU;CAC9C,IAAI,SAAS;EACX,MAAM,OAAO,oBAAoB,OAAO;EACxC,IAAI,KAAK,WAAW,GAClB,QAAQ,IAAI,kCAAkC;EAEhD,KAAK,MAAM,OAAO,MAAM;GACtB,MAAM,OAAO,MAAM,SAAS,KAAK,UAAU;GAC3C,QAAQ,IAAI,SAAS,MAAM;EAC7B;EACA;CACF;CACA,IAAI,KAAK;EACP,MAAM,EAAE,MAAM,mBAAmB,MAAM,gBAAgB,OAAO;EAC9D,MAAM,QAAQ,KAAK;EACnB,IAAI,KAAK,WAAW,KAAK,eAAe,WAAW,GACjD,QAAQ,IAAI,kCAAkC;EAEhD,KAAK,MAAM,OAAO,MAChB,QAAQ,IAAI,oBAAoB,IAAI,KAAK,eAAe,IAAI,SAAS;EAEvE,KAAK,MAAM,WAAW,gBACpB,QAAQ,KACN,mBAAmB,QAAQ,qCAAqC,wBAAwB,4BAC1F;EAEF;CACF,OAAO,IAAI,UAAU;EACnB,MAAM,MAAO,MAAM,YAAY,QAAQ;EACvC,MAAM,wBAAwB,KAAK,OAAO;CAC5C,OAAO,IAAI,MACT,MAAM,YACJ;EACE,SAAS;EACT;EACA,sBAAsB,CAAC;CACzB,GACA,OACF;MACK,IAAI,KAAK;EACd,MAAM,cAAc,eAClB,SACA,kBAAkB,SAAS,YAAY,GAAG,CAC5C;EACA,IAAI,CAAC,aACH,MAAM,IAAI,MAAM,sCAAsC,IAAI,EAAE;EAE9D,MAAM,EACJ,MAAM,SACN,IAAI,OACJ,SAAS,YACT,sBACA,yBACE;EAEJ,MAAM,YACJ;GACE;GACA;GACA;GACA;GACA;EACF,GACA,OACF;EACA,MAAM,QAAQ,KAAK;EACnB,QAAQ,IAAI,oBAAoB,QAAQ,eAAe,YAAY;EACnE;CACF,OAAO;EACL,QAAQ,IACN,uEACF;EACA;CACF;CACA,MAAM,QAAQ,KAAK;AACrB;;AAGA,SAAS,kBACP,SACA,YACA,KACA;CACA,MAAM,UAAU,qBAAqB,YAAY,WAAW,KAAK,QAAQ;CACzE,IAAI,CAAC,WAAW,KAAK,YAAY,WAAW,SAAS,WAAW,CAAC,GAC/D,MAAM,IAAI,MAAM,WAAW,QAAQ,mBAAmB;CAExD,MAAM,iBAAiB,kBAAkB,SAAS,OAAO;CACzD,IAAI,CAAC,gBACH,MAAM,IAAI,MACR,0BAA0B,QAAQ,uBAAuB,wBAAwB,EACnF;CAEF,IAAI,CAAC,eAAe,cAAc,SAAS,2BAA2B,GACpE,MAAM,IAAI,MACR,WAAW,QAAQ,0IAA0I,QAAQ,YACvK;CAEF,OAAO;AACT","debug_id":"598034cf-aa42-5189-8607-4625d64996ff"}
@@ -1,7 +1,9 @@
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]="47909a1f-ed7f-5d8f-b920-cc584f7f1d11")}catch(e){}}();
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]="ed8e6868-4817-5728-b076-e0cac26aea80")}catch(e){}}();
3
3
  import { t as warnSubgraphTypeConflicts } from "./warn-subgraph-type-conflicts-BOHBmThq.mjs";
4
- import { dirname, join } from "node:path";
4
+ import { t as resolveModuleDirName } from "./module-dir-1avCXsBi.mjs";
5
+ import { existsSync } from "node:fs";
6
+ import { join } from "node:path";
5
7
  import { generateAllDocumentModels, generateDocumentModel, loadDocumentModel } from "@powerhousedao/codegen";
6
8
  import { buildTsMorphProject } from "@powerhousedao/codegen/utils";
7
9
  import { extractDocumentModelDocuments, generateDocumentModelFromDocument, getDocument, saveSpec } from "@powerhousedao/vetra/codegen";
@@ -18,8 +20,15 @@ async function startGenerateDocumentModel(args, projectDir) {
18
20
  }
19
21
  return;
20
22
  }
21
- if (all) await generateAllDocumentModels(project);
22
- else if (document) {
23
+ if (all) {
24
+ const { documentModels, unreadableDirs } = await generateAllDocumentModels(project);
25
+ await project.save();
26
+ if (documentModels.length === 0 && unreadableDirs.length === 0) console.log("No document models found in document-models/.");
27
+ for (const { name } of documentModels) console.log(`Regenerated document model "${name}"`);
28
+ for (const dirName of unreadableDirs) console.warn(`Skipped document-models/${dirName}: expected a valid document model spec at document-models/${dirName}/${dirName}.json. Kept the manifest's document models.`);
29
+ await warnSubgraphTypeConflicts(projectDir);
30
+ return;
31
+ } else if (document) {
23
32
  if (document.endsWith(".phd")) {
24
33
  const doc = await getDocument(document);
25
34
  await generateDocumentModelFromDocument(doc, project);
@@ -28,10 +37,15 @@ async function startGenerateDocumentModel(args, projectDir) {
28
37
  await generateDocumentModel(state, project);
29
38
  }
30
39
  } else if (dir) {
31
- const documentModelFileName = `${dirname(dir)}.json`;
32
- const documentModelFilePath = join(dir, documentModelFileName);
33
- const state = await loadDocumentModel(documentModelFilePath);
40
+ const dirName = resolveModuleDirName(projectDir, "document-models", dir, "my-document-model");
41
+ const specPath = join(projectDir, "document-models", dirName, `${dirName}.json`);
42
+ if (!existsSync(specPath)) throw new Error(`document-models/${dirName} has no ${dirName}.json.`);
43
+ const state = await loadDocumentModel(specPath);
34
44
  await generateDocumentModel(state, project);
45
+ await project.save();
46
+ console.log(`Regenerated document model "${state.name}" in document-models/${dirName}`);
47
+ await warnSubgraphTypeConflicts(projectDir);
48
+ return;
35
49
  } else {
36
50
  console.log("Please specify one of `document`, `dir`, `all`, or `extract`.");
37
51
  return;
@@ -42,5 +56,5 @@ async function startGenerateDocumentModel(args, projectDir) {
42
56
  //#endregion
43
57
  export { startGenerateDocumentModel };
44
58
 
45
- //# sourceMappingURL=generate-document-model-BfFIQ35q.mjs.map
46
- //# debugId=47909a1f-ed7f-5d8f-b920-cc584f7f1d11
59
+ //# sourceMappingURL=generate-document-model-CiW13Vf7.mjs.map
60
+ //# debugId=ed8e6868-4817-5728-b076-e0cac26aea80
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-document-model-CiW13Vf7.mjs","sources":["../src/services/generate-document-model.ts"],"sourcesContent":["import {\n generateAllDocumentModels,\n generateDocumentModel,\n loadDocumentModel,\n} from \"@powerhousedao/codegen\";\nimport { buildTsMorphProject } from \"@powerhousedao/codegen/utils\";\nimport {\n extractDocumentModelDocuments,\n generateDocumentModelFromDocument,\n getDocument,\n saveSpec,\n} from \"@powerhousedao/vetra/codegen\";\nimport type { DocumentModelDocument } from \"@powerhousedao/shared/document-model\";\nimport { existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport type { GenerateDocumentModelArgs } from \"../types.js\";\nimport { resolveModuleDirName } from \"../utils/module-dir.js\";\nimport { warnSubgraphTypeConflicts } from \"../utils/warn-subgraph-type-conflicts.js\";\n\nexport async function startGenerateDocumentModel(\n args: GenerateDocumentModelArgs,\n projectDir: string,\n) {\n const { document, dir, all, extract, debug } = args;\n if (debug) {\n console.log({ args });\n }\n const project = buildTsMorphProject(projectDir);\n if (extract) {\n const docs = extractDocumentModelDocuments(project);\n for (const doc of docs) {\n const path = await saveSpec(doc, projectDir);\n console.log(`Wrote ${path}`);\n }\n return;\n }\n if (all) {\n const { documentModels, unreadableDirs } =\n await generateAllDocumentModels(project);\n await project.save();\n if (documentModels.length === 0 && unreadableDirs.length === 0) {\n console.log(\"No document models found in document-models/.\");\n }\n for (const { name } of documentModels) {\n console.log(`Regenerated document model \"${name}\"`);\n }\n for (const dirName of unreadableDirs) {\n console.warn(\n `Skipped document-models/${dirName}: expected a valid document model spec at document-models/${dirName}/${dirName}.json. Kept the manifest's document models.`,\n );\n }\n await warnSubgraphTypeConflicts(projectDir);\n return;\n } else if (document) {\n if (document.endsWith(\".phd\")) {\n const doc = (await getDocument(document)) as DocumentModelDocument;\n await generateDocumentModelFromDocument(doc, project);\n } else {\n const state = await loadDocumentModel(document);\n await generateDocumentModel(state, project);\n }\n } else if (dir) {\n const dirName = resolveModuleDirName(\n projectDir,\n \"document-models\",\n dir,\n \"my-document-model\",\n );\n const specPath = join(\n projectDir,\n \"document-models\",\n dirName,\n `${dirName}.json`,\n );\n if (!existsSync(specPath)) {\n throw new Error(`document-models/${dirName} has no ${dirName}.json.`);\n }\n const state = await loadDocumentModel(specPath);\n await generateDocumentModel(state, project);\n await project.save();\n console.log(\n `Regenerated document model \"${state.name}\" in document-models/${dirName}`,\n );\n await warnSubgraphTypeConflicts(projectDir);\n return;\n } else {\n console.log(\n \"Please specify one of `document`, `dir`, `all`, or `extract`.\",\n );\n return;\n }\n await project.save();\n await warnSubgraphTypeConflicts(projectDir);\n}\n"],"names":[],"mappings":";;;;;;;;;;AAmBA,eAAsB,2BACpB,MACA,YACA;CACA,MAAM,EAAE,UAAU,KAAK,KAAK,SAAS,UAAU;CAC/C,IAAI,OACF,QAAQ,IAAI,EAAE,KAAK,CAAC;CAEtB,MAAM,UAAU,oBAAoB,UAAU;CAC9C,IAAI,SAAS;EACX,MAAM,OAAO,8BAA8B,OAAO;EAClD,KAAK,MAAM,OAAO,MAA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0 +1,64 @@
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]="11ae2fde-9c6a-568f-8ad1-312bdab3f1d0")}catch(e){}}();
3
+ import { t as resolveModuleDirName } from "./module-dir-1avCXsBi.mjs";
4
+ import { existsSync } from "node:fs";
5
+ import { join } from "node:path";
6
+ import { generateAllEditors, generateEditor } from "@powerhousedao/codegen";
7
+ import { buildTsMorphProject, getEditorMetadata } from "@powerhousedao/codegen/utils";
8
+ import { extractEditorDocuments, generateEditorFromDocument, getDocument, saveSpec } from "@powerhousedao/vetra/codegen";
9
+ //#region src/services/generate-editor.ts
10
+ const MODULE_FILE_EXPECTATION = "an EditorModule with string literals for config.id, config.name and documentTypes";
11
+ async function startGenerateEditor(args, projectDir) {
12
+ const { name, documentType, document, dir, all, extract, debug } = args;
13
+ if (debug) console.log({ args });
14
+ const project = buildTsMorphProject(projectDir);
15
+ if (extract) {
16
+ const docs = extractEditorDocuments(project);
17
+ if (docs.length === 0) console.log("No document editors found in editors/.");
18
+ for (const doc of docs) {
19
+ const path = await saveSpec(doc, projectDir);
20
+ console.log(`Wrote ${path}`);
21
+ }
22
+ return;
23
+ }
24
+ const report = [];
25
+ if (all) {
26
+ const { editors, unreadableDirs } = await generateAllEditors(project);
27
+ if (editors.length === 0 && unreadableDirs.length === 0) report.push("No document editors found in editors/.");
28
+ for (const editor of editors) report.push(`Regenerated editor "${editor.name}" in editors/${editor.dirName}`);
29
+ for (const dirName of unreadableDirs) console.warn(`Skipped editors/${dirName}: expected its module.ts to export ${MODULE_FILE_EXPECTATION}. Kept the manifest's editors.`);
30
+ } else if (document) {
31
+ const doc = await getDocument(document);
32
+ await generateEditorFromDocument(doc, project);
33
+ } else if (name) {
34
+ if (!documentType) throw new Error("Please specify a document type for the new editor to generate.");
35
+ await generateEditor({
36
+ editorName: name,
37
+ documentTypes: [documentType]
38
+ }, project);
39
+ } else if (dir) {
40
+ const dirName = resolveModuleDirName(projectDir, "editors", dir, "my-editor");
41
+ if (!existsSync(join(projectDir, "editors", dirName, "module.ts"))) throw new Error(`editors/${dirName} has no module.ts.`);
42
+ const editorArgs = getEditorMetadata(project, dirName);
43
+ if (!editorArgs) throw new Error(`Could not read editors/${dirName}/module.ts: expected ${MODULE_FILE_EXPECTATION}.`);
44
+ if (editorArgs.documentTypes.includes("powerhouse/document-drive")) throw new Error(`editors/${dirName} is a drive app, not a document editor. Use \`ph-cli generate app --dir ${dirName}\` instead.`);
45
+ const { name: editorName, id: editorId, dirName: editorDirName, documentTypes } = editorArgs;
46
+ await generateEditor({
47
+ editorName,
48
+ editorId,
49
+ editorDirName,
50
+ documentTypes
51
+ }, project);
52
+ report.push(`Regenerated editor "${editorName}" in editors/${editorDirName}`);
53
+ } else {
54
+ console.log("Please specify one of `name`, `document`, `dir`, `all`, or `extract`.");
55
+ return;
56
+ }
57
+ await project.save();
58
+ for (const line of report) console.log(line);
59
+ }
60
+ //#endregion
61
+ export { startGenerateEditor };
62
+
63
+ //# sourceMappingURL=generate-editor-kTiUOmDW.mjs.map
64
+ //# debugId=11ae2fde-9c6a-568f-8ad1-312bdab3f1d0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-editor-kTiUOmDW.mjs","sources":["../src/services/generate-editor.ts"],"sourcesContent":["import { generateAllEditors, generateEditor } from \"@powerhousedao/codegen\";\nimport {\n buildTsMorphProject,\n getEditorMetadata,\n} from \"@powerhousedao/codegen/utils\";\nimport {\n extractEditorDocuments,\n generateEditorFromDocument,\n getDocument,\n saveSpec,\n} from \"@powerhousedao/vetra/codegen\";\nimport type { DocumentEditorDocument } from \"@powerhousedao/vetra/document-models/document-editor\";\nimport { existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport type { GenerateEditorArgs } from \"../types.js\";\nimport { resolveModuleDirName } from \"../utils/module-dir.js\";\n\nconst MODULE_FILE_EXPECTATION =\n \"an EditorModule with string literals for config.id, config.name and documentTypes\";\n\nexport async function startGenerateEditor(\n args: GenerateEditorArgs,\n projectDir: string,\n) {\n const { name, documentType, document, dir, all, extract, debug } = args;\n if (debug) {\n console.log({ args });\n }\n const project = buildTsMorphProject(projectDir);\n if (extract) {\n const docs = extractEditorDocuments(project);\n if (docs.length === 0) {\n console.log(\"No document editors found in editors/.\");\n }\n for (const doc of docs) {\n const path = await saveSpec(doc, projectDir);\n console.log(`Wrote ${path}`);\n }\n return;\n }\n const report: string[] = [];\n if (all) {\n const { editors, unreadableDirs } = await generateAllEditors(project);\n if (editors.length === 0 && unreadableDirs.length === 0) {\n report.push(\"No document editors found in editors/.\");\n }\n for (const editor of editors) {\n report.push(\n `Regenerated editor \"${editor.name}\" in editors/${editor.dirName}`,\n );\n }\n for (const dirName of unreadableDirs) {\n console.warn(\n `Skipped editors/${dirName}: expected its module.ts to export ${MODULE_FILE_EXPECTATION}. Kept the manifest's editors.`,\n );\n }\n } else if (document) {\n const doc = (await getDocument(document)) as DocumentEditorDocument;\n await generateEditorFromDocument(doc, project);\n } else if (name) {\n if (!documentType) {\n throw new Error(\n \"Please specify a document type for the new editor to generate.\",\n );\n }\n await generateEditor(\n { editorName: name, documentTypes: [documentType] },\n project,\n );\n } else if (dir) {\n const dirName = resolveModuleDirName(\n projectDir,\n \"editors\",\n dir,\n \"my-editor\",\n );\n if (!existsSync(join(projectDir, \"editors\", dirName, \"module.ts\"))) {\n throw new Error(`editors/${dirName} has no module.ts.`);\n }\n const editorArgs = getEditorMetadata(project, dirName);\n if (!editorArgs) {\n throw new Error(\n `Could not read editors/${dirName}/module.ts: expected ${MODULE_FILE_EXPECTATION}.`,\n );\n }\n if (editorArgs.documentTypes.includes(\"powerhouse/document-drive\")) {\n throw new Error(\n `editors/${dirName} is a drive app, not a document editor. Use \\`ph-cli generate app --dir ${dirName}\\` instead.`,\n );\n }\n const {\n name: editorName,\n id: editorId,\n dirName: editorDirName,\n documentTypes,\n } = editorArgs;\n await generateEditor(\n {\n editorName,\n editorId,\n editorDirName,\n documentTypes,\n },\n project,\n );\n report.push(\n `Regenerated editor \"${editorName}\" in editors/${editorDirName}`,\n );\n } else {\n console.log(\n \"Please specify one of `name`, `document`, `dir`, `all`, or `extract`.\",\n );\n return;\n }\n await project.save();\n for (const line of report) {\n console.log(line);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;AAiBA,MAAM,0BACJ;AAEF,eAAsB,oBACpB,MACA,YACA;CACA,MAAM,EAAE,MAAM,cAAc,UAAU,KAAK,KAAK,SAAS,UAAU;CACnE,IAAI,OACF,QAAQ,IAAI,EAAE,KAAK,CAAC;CAEtB,MAAM,UAAU,oBAAoB,UAAU;CAC9C,IAAI,SAAS;EACX,MAAM,OAAO,uBAAuB,OAAO;EAC3C,IAAI,KAAK,WAAW,GAClB,QAAQ,IAAI,wCAAwC;EAEtD,KAAK,MAAM,OAAO,MAAM;GACtB,MAAM,OAAO,MAAM,SAAS,KAAK,UAAU;GAC3C,QAAQ,IAAI,SAAS,MAAM;EAC7B;EACA;CACF;CACA,MAAM,SAAmB,CAAC;CAC1B,IAAI,KAAK;EACP,MAAM,EAAE,SAAS,mBAAmB,MAAM,mBAAmB,OAAO;EACpE,IAAI,QAAQ,WAAW,KAAK,eAAe,WAAW,GACpD,OAAO,KAAK,wCAAwC;EAEtD,KAAK,MAAM,UAAU,SACnB,OAAO,KACL,uBAAuB,OAAO,KAAK,eAAe,OAAO,SAC3D;EAEF,KAAK,MAAM,WAAW,gBACpB,QAAQ,KACN,mBAAmB,QAAQ,qCAAqC,wBAAwB,+BAC1F;CAEJ,OAAO,IAAI,UAAU;EACnB,MAAM,MAAO,MAAM,YAAY,QAAQ;EACvC,MAAM,2BAA2B,KAAK,OAAO;CAC/C,OAAO,IAAI,MAAM;EACf,IAAI,CAAC,cACH,MAAM,IAAI,MACR,gEACF;EAEF,MAAM,eACJ;GAAE,YAAY;GAAM,eAAe,CAAC,YAAY;EAAE,GAClD,OACF;CACF,OAAO,IAAI,KAAK;EACd,MAAM,UAAU,qBACd,YACA,WACA,KACA,WACF;EACA,IAAI,CAAC,WAAW,KAAK,YAAY,WAAW,SAAS,WAAW,CAAC,GAC/D,MAAM,IAAI,MAAM,WAAW,QAAQ,mBAAmB;EAExD,MAAM,aAAa,kBAAkB,SAAS,OAAO;EACrD,IAAI,CAAC,YACH,MAAM,IAAI,MACR,0BAA0B,QAAQ,uBAAuB,wBAAwB,EACnF;EAEF,IAAI,WAAW,cAAc,SAAS,2BAA2B,GAC/D,MAAM,IAAI,MACR,WAAW,QAAQ,0EAA0E,QAAQ,YACvG;EAEF,MAAM,EACJ,MAAM,YACN,IAAI,UACJ,SAAS,eACT,kBACE;EACJ,MAAM,eACJ;GACE;GACA;GACA;GACA;EACF,GACA,OACF;EACA,OAAO,KACL,uBAAuB,WAAW,eAAe,eACnD;CACF,OAAO;EACL,QAAQ,IACN,uEACF;EACA;CACF;CACA,MAAM,QAAQ,KAAK;CACnB,KAAK,MAAM,QAAQ,QACjB,QAAQ,IAAI,IAAI;AAEpB","debug_id":"11ae2fde-9c6a-568f-8ad1-312bdab3f1d0"}
@@ -1,7 +1,9 @@
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]="8b015725-4996-50bb-890c-e6cf4750fe5e")}catch(e){}}();
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]="1aba504c-2944-592a-becb-44b39f8dac04")}catch(e){}}();
3
3
  import { t as installAddedDependencies } from "./install-added-dependencies-DVSbzler.mjs";
4
- import { basename } from "node:path";
4
+ import { t as resolveModuleDirName } from "./module-dir-1avCXsBi.mjs";
5
+ import { existsSync } from "node:fs";
6
+ import { join } from "node:path";
5
7
  import { readPackage } from "read-pkg";
6
8
  import { detectFeatures, generateAllPieces, generatePiece, syncFeatureDependencies } from "@powerhousedao/codegen";
7
9
  import { buildTsMorphProject, readPiecesList } from "@powerhousedao/codegen/utils";
@@ -35,9 +37,14 @@ async function startGeneratePiece(args, projectDir) {
35
37
  if (debug) console.log({ args });
36
38
  const project = buildTsMorphProject(projectDir);
37
39
  const name = namePositional ?? nameOption;
40
+ const report = [];
38
41
  if (all) await generateAllPieces(project);
39
- else if (dir) await generateAllPieces(project, basename(dir.replace(/\/+$/, "")));
40
- else if (name) {
42
+ else if (dir) {
43
+ const dirName = resolveModuleDirName(projectDir, "pieces", dir, "my-piece");
44
+ if (!existsSync(join(projectDir, "pieces", dirName, "index.ts"))) throw new Error(`pieces/${dirName} has no index.ts.`);
45
+ await generateAllPieces(project, dirName);
46
+ report.push(`Re-registered the piece in pieces/${dirName}`);
47
+ } else if (name) {
41
48
  const pieceId = await resolvePieceId({
42
49
  project,
43
50
  projectDir,
@@ -55,11 +62,12 @@ async function startGeneratePiece(args, projectDir) {
55
62
  return;
56
63
  }
57
64
  await project.save();
65
+ for (const line of report) console.log(line);
58
66
  const added = await syncFeatureDependencies(detectFeatures(projectDir), projectDir);
59
67
  await installAddedDependencies(added, projectDir, args.skipInstall);
60
68
  }
61
69
  //#endregion
62
70
  export { startGeneratePiece };
63
71
 
64
- //# sourceMappingURL=generate-piece-QTt-ddt2.mjs.map
65
- //# debugId=8b015725-4996-50bb-890c-e6cf4750fe5e
72
+ //# sourceMappingURL=generate-piece-U3tP-Sex.mjs.map
73
+ //# debugId=1aba504c-2944-592a-becb-44b39f8dac04
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-piece-U3tP-Sex.mjs","sources":["../src/services/generate-piece.ts"],"sourcesContent":["import {\n detectFeatures,\n generateAllPieces,\n generatePiece,\n syncFeatureDependencies,\n} from \"@powerhousedao/codegen\";\nimport { derivePieceId } from \"@powerhousedao/codegen/name-builders\";\nimport {\n buildTsMorphProject,\n readPiecesList,\n} from \"@powerhousedao/codegen/utils\";\nimport { kebabCase } from \"change-case\";\nimport enquirer from \"enquirer\";\nimport { existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { readPackage } from \"read-pkg\";\nimport type { Project } from \"ts-morph\";\nimport type { GeneratePieceArgs } from \"../types.js\";\nimport { installAddedDependencies } from \"../utils/install-added-dependencies.js\";\nimport { resolveModuleDirName } from \"../utils/module-dir.js\";\n\n// The id a block type will name, asked for only where deriving one would claim\n// a namespace nobody owns; CI, with no TTY, takes the derived value.\nasync function resolvePieceId(v: {\n project: Project;\n projectDir: string;\n pieceName: string;\n id?: string;\n}): Promise<string> {\n if (v.id) return v.id;\n const pkg = await readPackage({ cwd: v.projectDir, normalize: false });\n const { id, needsConfirmation } = derivePieceId({\n packageName: pkg.name ?? \"\",\n slug: kebabCase(v.pieceName),\n hasOtherPieces: readPiecesList(v.project).length > 0,\n });\n if (!needsConfirmation || !process.stdin.isTTY) return id;\n const { prompt } = enquirer;\n const result = await prompt<{ pieceId: string }>([\n {\n type: \"input\",\n name: \"pieceId\",\n message:\n \"What id should this piece have? A workflow step names it as its pieceName.\",\n initial: id,\n required: true,\n },\n ]);\n return result.pieceId || id;\n}\n\nexport async function startGeneratePiece(\n args: GeneratePieceArgs,\n projectDir: string,\n) {\n const {\n namePositional,\n name: nameOption,\n id,\n auth,\n description,\n dir,\n all,\n debug,\n } = args;\n if (debug) {\n console.log({ args });\n }\n const project = buildTsMorphProject(projectDir);\n const name = namePositional ?? nameOption;\n const report: string[] = [];\n if (all) {\n await generateAllPieces(project);\n } else if (dir) {\n const dirName = resolveModuleDirName(projectDir, \"pieces\", dir, \"my-piece\");\n if (!existsSync(join(projectDir, \"pieces\", dirName, \"index.ts\"))) {\n throw new Error(`pieces/${dirName} has no index.ts.`);\n }\n await generateAllPieces(project, dirName);\n report.push(`Re-registered the piece in pieces/${dirName}`);\n } else if (name) {\n const pieceId = await resolvePieceId({\n project,\n projectDir,\n pieceName: name,\n id,\n });\n await generatePiece(\n { pieceName: name, pieceId, auth, description },\n project,\n );\n } else {\n console.log(\"Please specify one of `name`, `dir`, or `all`.\");\n return;\n }\n await project.save();\n for (const line of report) {\n console.log(line);\n }\n const added = await syncFeatureDependencies(\n detectFeatures(projectDir),\n projectDir,\n );\n await installAddedDependencies(added, projectDir, args.skipInstall);\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAuBA,eAAe,eAAe,GAKV;CAClB,IAAI,EAAE,IAAI,OAAO,EAAE;CACnB,MAAM,MAAM,MAAM,YAAY;EAAE,KAAK,EAAE;EAAY,WAAW;CAAM,CAAC;CACrE,MAAM,EAAE,IAAI,sBAAsB,cAAc;EAC9C,aAAa,IAAI,QAAQ;EACzB,MAAM,UAAU,EAAE,SAAS;EAC3B,gBAAgB,eAAe,EAAE,OAAO,CAAC,CAAC,SAAS;CACrD,CAAC;CACD,IAAI,CAAC,qBAAqB,CAAC,QAAQ,MAAM,OAAO,OAAO;CACvD,MAAM,EAAE,WAAW;CAWnB,QAAO,MAVc,OAA4B,CAC/C;EACE,MAAM;EACN,MAAM;EACN,SACE;EACF,SAAS;EACT,UAAU;CACZ,CACF,CAAC,EAAA,CACa,WAAW;AAC3B;AAEA,eAAsB,mBACpB,MACA,YACA;CACA,MAAM,EACJ,gBACA,MAAM,YACN,IACA,MACA,aACA,KACA,KACA,UACE;CACJ,IAAI,OACF,QAAQ,IAAI,EAAE,KAAK,CAAC;CAEtB,MAAM,UAAU,oBAAoB,UAAU;CAC9C,MAAM,OAAO,kBAAkB;CAC/B,MAAM,SAAmB,CAAC;CAC1B,IAAI,KACF,MAAM,kBAAkB,OAAO;MAC1B,IAAI,KAAK;EACd,MAAM,UAAU,qBAAqB,YAAY,UAAU,KAAK,UAAU;EAC1E,IAAI,CAAC,WAAW,KAAK,YAAY,UAAU,SAAS,UAAU,CAA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