@treeseed/sdk 0.1.2 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/README.md +97 -506
  2. package/dist/{src/cli-tools.d.ts → cli-tools.d.ts} +1 -1
  3. package/dist/cli-tools.js +5 -3
  4. package/dist/{src/content-store.d.ts → content-store.d.ts} +3 -2
  5. package/dist/content-store.js +52 -20
  6. package/dist/{src/d1-store.d.ts → d1-store.d.ts} +62 -1
  7. package/dist/d1-store.js +625 -65
  8. package/dist/field-aliases.d.ts +11 -0
  9. package/dist/field-aliases.js +41 -0
  10. package/dist/graph/build.d.ts +19 -0
  11. package/dist/graph/build.js +949 -0
  12. package/dist/graph/dsl.d.ts +2 -0
  13. package/dist/graph/dsl.js +243 -0
  14. package/dist/graph/query.d.ts +47 -0
  15. package/dist/graph/query.js +447 -0
  16. package/dist/graph/ranking.d.ts +3 -0
  17. package/dist/graph/ranking.js +483 -0
  18. package/dist/graph/schema.d.ts +142 -0
  19. package/dist/graph/schema.js +133 -0
  20. package/dist/graph.d.ts +52 -0
  21. package/dist/graph.js +133 -0
  22. package/dist/index.d.ts +28 -0
  23. package/dist/index.js +91 -2
  24. package/dist/model-registry.d.ts +8 -0
  25. package/dist/model-registry.js +351 -25
  26. package/dist/operations/providers/default.d.ts +10 -0
  27. package/dist/operations/providers/default.js +514 -0
  28. package/dist/operations/runtime.d.ts +7 -0
  29. package/dist/operations/runtime.js +60 -0
  30. package/dist/operations/services/config-runtime.d.ts +269 -0
  31. package/dist/operations/services/config-runtime.js +1397 -0
  32. package/dist/operations/services/d1-migration.d.ts +6 -0
  33. package/dist/operations/services/d1-migration.js +89 -0
  34. package/dist/operations/services/deploy.d.ts +371 -0
  35. package/dist/operations/services/deploy.js +981 -0
  36. package/dist/operations/services/git-workflow.d.ts +49 -0
  37. package/dist/operations/services/git-workflow.js +218 -0
  38. package/dist/operations/services/github-automation.d.ts +156 -0
  39. package/dist/operations/services/github-automation.js +256 -0
  40. package/dist/operations/services/local-dev.d.ts +9 -0
  41. package/dist/operations/services/local-dev.js +106 -0
  42. package/dist/operations/services/mailpit-runtime.d.ts +4 -0
  43. package/dist/operations/services/mailpit-runtime.js +59 -0
  44. package/dist/operations/services/railway-deploy.d.ts +53 -0
  45. package/dist/operations/services/railway-deploy.js +123 -0
  46. package/dist/operations/services/runtime-paths.d.ts +19 -0
  47. package/dist/operations/services/runtime-paths.js +54 -0
  48. package/dist/operations/services/runtime-tools.d.ts +117 -0
  49. package/dist/operations/services/runtime-tools.js +358 -0
  50. package/dist/operations/services/save-deploy-preflight.d.ts +34 -0
  51. package/dist/operations/services/save-deploy-preflight.js +76 -0
  52. package/dist/operations/services/template-registry.d.ts +88 -0
  53. package/dist/operations/services/template-registry.js +407 -0
  54. package/dist/operations/services/watch-dev.d.ts +21 -0
  55. package/dist/operations/services/watch-dev.js +284 -0
  56. package/dist/operations/services/workspace-preflight.d.ts +40 -0
  57. package/dist/operations/services/workspace-preflight.js +165 -0
  58. package/dist/operations/services/workspace-save.d.ts +42 -0
  59. package/dist/operations/services/workspace-save.js +235 -0
  60. package/dist/operations/services/workspace-tools.d.ts +16 -0
  61. package/dist/operations/services/workspace-tools.js +270 -0
  62. package/dist/operations-registry.d.ts +5 -0
  63. package/dist/operations-registry.js +68 -0
  64. package/dist/operations-types.d.ts +71 -0
  65. package/dist/operations-types.js +17 -0
  66. package/dist/operations.d.ts +6 -0
  67. package/dist/operations.js +16 -0
  68. package/dist/platform/books-data.d.ts +1 -0
  69. package/dist/platform/books-data.js +1 -0
  70. package/dist/platform/contracts.d.ts +158 -0
  71. package/dist/platform/contracts.js +0 -0
  72. package/dist/platform/deploy/config.d.ts +4 -0
  73. package/dist/platform/deploy/config.js +222 -0
  74. package/dist/platform/deploy-config.d.ts +1 -0
  75. package/dist/platform/deploy-config.js +1 -0
  76. package/dist/platform/deploy-runtime.d.ts +18 -0
  77. package/dist/platform/deploy-runtime.js +78 -0
  78. package/dist/platform/env.yaml +394 -0
  79. package/dist/platform/environment.d.ts +130 -0
  80. package/dist/platform/environment.js +331 -0
  81. package/dist/platform/plugin.d.ts +2 -0
  82. package/dist/platform/plugin.js +4 -0
  83. package/dist/platform/plugins/constants.d.ts +22 -0
  84. package/dist/platform/plugins/constants.js +29 -0
  85. package/dist/platform/plugins/plugin.d.ts +51 -0
  86. package/dist/platform/plugins/plugin.js +6 -0
  87. package/dist/platform/plugins/runtime.d.ts +35 -0
  88. package/dist/platform/plugins/runtime.js +161 -0
  89. package/dist/platform/plugins.d.ts +6 -0
  90. package/dist/platform/plugins.js +38 -0
  91. package/dist/platform/site-config-schema.js +1 -0
  92. package/dist/platform/tenant/config.d.ts +9 -0
  93. package/dist/platform/tenant/config.js +154 -0
  94. package/dist/platform/tenant/runtime-config.d.ts +4 -0
  95. package/dist/platform/tenant/runtime-config.js +20 -0
  96. package/dist/platform/tenant-config.d.ts +1 -0
  97. package/dist/platform/tenant-config.js +1 -0
  98. package/dist/platform/utils/books-data.d.ts +29 -0
  99. package/dist/platform/utils/books-data.js +82 -0
  100. package/dist/platform/utils/site-config-schema.js +321 -0
  101. package/dist/remote.d.ts +175 -0
  102. package/dist/remote.js +202 -0
  103. package/dist/runtime.js +35 -22
  104. package/dist/scripts/aggregate-book.js +121 -0
  105. package/dist/scripts/build-dist.js +54 -13
  106. package/dist/scripts/build-tenant-worker.js +36 -0
  107. package/dist/scripts/cleanup-markdown.js +373 -0
  108. package/dist/scripts/cli-test-fixtures.js +48 -0
  109. package/dist/scripts/config-treeseed.js +95 -0
  110. package/dist/scripts/ensure-mailpit.js +29 -0
  111. package/dist/scripts/local-dev.js +129 -0
  112. package/dist/scripts/logs-mailpit.js +2 -0
  113. package/dist/scripts/patch-starlight-content-path.js +172 -0
  114. package/dist/scripts/release-verify.js +34 -6
  115. package/dist/scripts/run-fixture-astro-command.js +18 -0
  116. package/dist/scripts/scaffold-site.js +65 -0
  117. package/dist/scripts/stop-mailpit.js +5 -0
  118. package/dist/scripts/sync-dev-vars.js +6 -0
  119. package/dist/scripts/sync-template.js +20 -0
  120. package/dist/scripts/template-catalog.test.js +100 -0
  121. package/dist/scripts/template-command.js +31 -0
  122. package/dist/scripts/tenant-astro-command.js +3 -0
  123. package/dist/scripts/tenant-build.js +16 -0
  124. package/dist/scripts/tenant-check.js +7 -0
  125. package/dist/scripts/tenant-d1-migrate-local.js +11 -0
  126. package/dist/scripts/tenant-deploy.js +180 -0
  127. package/dist/scripts/tenant-destroy.js +104 -0
  128. package/dist/scripts/tenant-dev.js +171 -0
  129. package/dist/scripts/tenant-lint.js +4 -0
  130. package/dist/scripts/tenant-test.js +4 -0
  131. package/dist/scripts/test-cloudflare-local.js +212 -0
  132. package/dist/scripts/test-scaffold.js +314 -0
  133. package/dist/scripts/test-smoke.js +71 -13
  134. package/dist/scripts/treeseed-assert-release-tag-version.js +21 -0
  135. package/dist/scripts/treeseed-build-dist.js +134 -0
  136. package/dist/scripts/treeseed-publish-package.js +19 -0
  137. package/dist/scripts/treeseed-release-verify.js +131 -0
  138. package/dist/scripts/treeseed-run-ts.js +45 -0
  139. package/dist/scripts/validate-templates.js +6 -0
  140. package/dist/scripts/verify-driver.js +29 -0
  141. package/dist/scripts/workflow-commands.test.js +39 -0
  142. package/dist/scripts/workspace-close.js +24 -0
  143. package/dist/scripts/workspace-command-e2e.js +718 -0
  144. package/dist/scripts/workspace-lint.js +9 -0
  145. package/dist/scripts/workspace-preflight.js +22 -0
  146. package/dist/scripts/workspace-publish-changed-packages.js +16 -0
  147. package/dist/scripts/workspace-release-verify.js +81 -0
  148. package/dist/scripts/workspace-release.js +42 -0
  149. package/dist/scripts/workspace-save.js +124 -0
  150. package/dist/scripts/workspace-start-warning.js +3 -0
  151. package/dist/scripts/workspace-start.js +71 -0
  152. package/dist/scripts/workspace-test-unit.js +4 -0
  153. package/dist/scripts/workspace-test.js +11 -0
  154. package/dist/sdk-fields.d.ts +11 -0
  155. package/dist/sdk-fields.js +169 -0
  156. package/dist/sdk-filters.d.ts +4 -0
  157. package/dist/sdk-filters.js +12 -15
  158. package/dist/sdk-types.d.ts +796 -0
  159. package/dist/sdk-types.js +7 -1
  160. package/dist/sdk-version.d.ts +2 -0
  161. package/dist/sdk-version.js +42 -0
  162. package/dist/sdk.d.ts +215 -0
  163. package/dist/sdk.js +235 -11
  164. package/dist/stores/cursor-store.js +9 -3
  165. package/dist/stores/lease-store.js +8 -2
  166. package/dist/{src/stores → stores}/message-store.d.ts +1 -1
  167. package/dist/stores/message-store.js +27 -3
  168. package/dist/stores/operational-store.d.ts +24 -0
  169. package/dist/stores/operational-store.js +279 -0
  170. package/dist/stores/run-store.js +8 -1
  171. package/dist/stores/subscription-store.js +7 -5
  172. package/dist/template-catalog.d.ts +13 -0
  173. package/dist/template-catalog.js +141 -0
  174. package/dist/treeseed/services/compose.yml +7 -0
  175. package/dist/treeseed/template-catalog/catalog.fixture.json +55 -0
  176. package/dist/treeseed/template-catalog/templates/starter-basic/template/astro.config.d.ts +2 -0
  177. package/dist/treeseed/template-catalog/templates/starter-basic/template/astro.config.ts +3 -0
  178. package/dist/treeseed/template-catalog/templates/starter-basic/template/package.json +32 -0
  179. package/dist/treeseed/template-catalog/templates/starter-basic/template/src/config.yaml +40 -0
  180. package/dist/treeseed/template-catalog/templates/starter-basic/template/src/content/empty/.gitkeep +1 -0
  181. package/dist/treeseed/template-catalog/templates/starter-basic/template/src/content/knowledge/handbook/index.mdx +11 -0
  182. package/dist/treeseed/template-catalog/templates/starter-basic/template/src/content/pages/welcome.mdx +11 -0
  183. package/dist/treeseed/template-catalog/templates/starter-basic/template/src/content.config.d.ts +1 -0
  184. package/dist/treeseed/template-catalog/templates/starter-basic/template/src/content.config.ts +3 -0
  185. package/dist/treeseed/template-catalog/templates/starter-basic/template/src/env.yaml +1 -0
  186. package/dist/treeseed/template-catalog/templates/starter-basic/template/src/manifest.yaml +19 -0
  187. package/dist/treeseed/template-catalog/templates/starter-basic/template/treeseed.site.yaml +26 -0
  188. package/dist/treeseed/template-catalog/templates/starter-basic/template/tsconfig.json +9 -0
  189. package/dist/treeseed/template-catalog/templates/starter-basic/template.config.json +90 -0
  190. package/dist/utils/agents/contracts/messages.d.ts +88 -0
  191. package/dist/utils/agents/contracts/messages.js +138 -0
  192. package/dist/utils/agents/contracts/run.d.ts +20 -0
  193. package/dist/utils/agents/contracts/run.js +0 -0
  194. package/dist/utils/agents/runtime-types.d.ts +117 -0
  195. package/dist/utils/agents/runtime-types.js +4 -0
  196. package/dist/verification.d.ts +20 -0
  197. package/dist/verification.js +98 -0
  198. package/dist/workflow/operations.d.ts +396 -0
  199. package/dist/workflow/operations.js +841 -0
  200. package/dist/workflow-state.d.ts +56 -0
  201. package/dist/workflow-state.js +195 -0
  202. package/dist/workflow-support.d.ts +9 -0
  203. package/dist/workflow-support.js +176 -0
  204. package/dist/workflow.d.ts +111 -0
  205. package/dist/workflow.js +97 -0
  206. package/package.json +111 -5
  207. package/scripts/verify-driver.mjs +29 -0
  208. package/dist/scripts/.ts-run-1775630384291-crtqr3izsa.js +0 -22
  209. package/dist/scripts/.ts-run-1775630388025-vnjle0z75a.js +0 -129
  210. package/dist/scripts/assert-release-tag-version.d.ts +0 -1
  211. package/dist/scripts/build-dist.d.ts +0 -1
  212. package/dist/scripts/fixture-tools.d.ts +0 -5
  213. package/dist/scripts/package-tools.d.ts +0 -15
  214. package/dist/scripts/publish-package.d.ts +0 -1
  215. package/dist/scripts/release-verify.d.ts +0 -1
  216. package/dist/scripts/test-smoke.d.ts +0 -1
  217. package/dist/src/index.d.ts +0 -6
  218. package/dist/src/model-registry.d.ts +0 -4
  219. package/dist/src/sdk-filters.d.ts +0 -4
  220. package/dist/src/sdk-types.d.ts +0 -285
  221. package/dist/src/sdk.d.ts +0 -109
  222. package/dist/test/test-fixture.d.ts +0 -1
  223. package/dist/test/utils/envelopes.test.d.ts +0 -1
  224. package/dist/test/utils/sdk.test.d.ts +0 -1
  225. package/dist/vitest.config.d.ts +0 -2
  226. /package/dist/{src/frontmatter.d.ts → frontmatter.d.ts} +0 -0
  227. /package/dist/{src/git-runtime.d.ts → git-runtime.d.ts} +0 -0
  228. /package/dist/{src/runtime.d.ts → runtime.d.ts} +0 -0
  229. /package/dist/{src/stores → stores}/cursor-store.d.ts +0 -0
  230. /package/dist/{src/stores → stores}/envelopes.d.ts +0 -0
  231. /package/dist/{src/stores → stores}/helpers.d.ts +0 -0
  232. /package/dist/{src/stores → stores}/lease-store.d.ts +0 -0
  233. /package/dist/{src/stores → stores}/run-store.d.ts +0 -0
  234. /package/dist/{src/stores → stores}/subscription-store.d.ts +0 -0
  235. /package/dist/{src/types → types}/agents.d.ts +0 -0
  236. /package/dist/{src/types → types}/cloudflare.d.ts +0 -0
  237. /package/dist/{src/wrangler-d1.d.ts → wrangler-d1.d.ts} +0 -0
@@ -0,0 +1,358 @@
1
+ import { readFileSync, existsSync } from "node:fs";
2
+ import { dirname, extname, resolve } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { spawn, spawnSync } from "node:child_process";
5
+ import { createRequire } from "node:module";
6
+ import { parse as parseYaml } from "yaml";
7
+ const require2 = createRequire(import.meta.url);
8
+ const scriptRoot = dirname(fileURLToPath(import.meta.url));
9
+ const packageRootFromSource = resolve(scriptRoot, "..", "..", "..");
10
+ const treeseedRuntimeRoot = resolve(packageRootFromSource, "src", "treeseed");
11
+ const TREESEED_DEFAULT_PLUGIN_REFERENCES = [
12
+ {
13
+ package: "@treeseed/core/plugin-default",
14
+ enabled: true
15
+ }
16
+ ];
17
+ const TREESEED_DEFAULT_PROVIDER_SELECTIONS = {
18
+ forms: "store_only",
19
+ agents: {
20
+ execution: "stub",
21
+ mutation: "local_branch",
22
+ repository: "stub",
23
+ verification: "stub",
24
+ notification: "stub",
25
+ research: "stub"
26
+ },
27
+ deploy: "cloudflare",
28
+ content: {
29
+ docs: "default"
30
+ },
31
+ site: "default"
32
+ };
33
+ const TRESEED_MANAGED_SERVICE_KEYS = ["api", "agents", "gateway", "manager", "worker", "workdayStart", "workdayReport"];
34
+ const TRESEED_WORKSPACE_PACKAGE_DIRS = ["sdk", "core", "cli", "agent", "api"];
35
+ const CLOUDFLARE_ACCOUNT_ID_PLACEHOLDER = "replace-with-cloudflare-account-id";
36
+ function parseServiceEnvironmentConfig(value) {
37
+ const record = optionalRecord(value, "service environment") ?? {};
38
+ return {
39
+ baseUrl: optionalString(record.baseUrl),
40
+ domain: optionalString(record.domain),
41
+ railwayEnvironment: optionalString(record.railwayEnvironment)
42
+ };
43
+ }
44
+ function parseManagedServiceConfig(value, label) {
45
+ const record = optionalRecord(value, label);
46
+ if (!record) {
47
+ return void 0;
48
+ }
49
+ const railway = optionalRecord(record.railway, `${label}.railway`) ?? {};
50
+ const cloudflare = optionalRecord(record.cloudflare, `${label}.cloudflare`) ?? {};
51
+ const environments = optionalRecord(record.environments, `${label}.environments`) ?? {};
52
+ return {
53
+ enabled: record.enabled === void 0 ? void 0 : optionalBoolean(record.enabled, `${label}.enabled`),
54
+ provider: optionalString(record.provider),
55
+ rootDir: optionalString(record.rootDir),
56
+ publicBaseUrl: optionalString(record.publicBaseUrl),
57
+ cloudflare: {
58
+ workerName: optionalString(cloudflare.workerName)
59
+ },
60
+ railway: {
61
+ projectId: optionalString(railway.projectId),
62
+ projectName: optionalString(railway.projectName),
63
+ serviceId: optionalString(railway.serviceId),
64
+ serviceName: optionalString(railway.serviceName),
65
+ rootDir: optionalString(railway.rootDir),
66
+ buildCommand: optionalString(railway.buildCommand),
67
+ startCommand: optionalString(railway.startCommand)
68
+ },
69
+ environments: {
70
+ local: parseServiceEnvironmentConfig(environments.local),
71
+ staging: parseServiceEnvironmentConfig(environments.staging),
72
+ prod: parseServiceEnvironmentConfig(environments.prod)
73
+ }
74
+ };
75
+ }
76
+ function parseManagedServicesConfig(value) {
77
+ const record = optionalRecord(value, "services");
78
+ if (!record) {
79
+ return void 0;
80
+ }
81
+ return Object.fromEntries(
82
+ TRESEED_MANAGED_SERVICE_KEYS.map((serviceKey) => [
83
+ serviceKey,
84
+ parseManagedServiceConfig(record[serviceKey], `services.${serviceKey}`)
85
+ ])
86
+ );
87
+ }
88
+ const packageRoot = packageRootFromSource;
89
+ const packageScriptRoot = resolve(packageRoot, "scripts");
90
+ const runtimeRoot = treeseedRuntimeRoot;
91
+ function resolvePackageBinary(packageName, binName = packageName) {
92
+ const packageJsonPath = require2.resolve(`${packageName}/package.json`);
93
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
94
+ const binField = packageJson.bin;
95
+ const relativePath = typeof binField === "string" ? binField : binField?.[binName];
96
+ if (!relativePath) {
97
+ throw new Error(`Unable to resolve binary "${binName}" from package "${packageName}".`);
98
+ }
99
+ return resolve(dirname(packageJsonPath), relativePath);
100
+ }
101
+ function treeseedWorkspacePackageCheckoutState(root = resolve(packageRoot, "..")) {
102
+ const packages = TRESEED_WORKSPACE_PACKAGE_DIRS.map((dirName) => {
103
+ const dir = resolve(root, dirName);
104
+ return {
105
+ dirName,
106
+ dir,
107
+ present: existsSync(resolve(dir, "package.json"))
108
+ };
109
+ });
110
+ const present = packages.filter((entry) => entry.present);
111
+ return {
112
+ mode: present.length === 0 ? "registry" : present.length === packages.length ? "workspace" : "partial",
113
+ packages,
114
+ missing: packages.filter((entry) => !entry.present)
115
+ };
116
+ }
117
+ function assertUsableTreeseedPackageCheckout(fallbackDirName) {
118
+ if (!fallbackDirName) {
119
+ return;
120
+ }
121
+ const state = treeseedWorkspacePackageCheckoutState();
122
+ const rootHasTreeseedSubmodules = existsSync(resolve(packageRoot, "..", "..", ".gitmodules"));
123
+ if (state.mode !== "partial" || !rootHasTreeseedSubmodules) {
124
+ return;
125
+ }
126
+ const missing = state.missing.map((entry) => `packages/${entry.dirName}`).join(", ");
127
+ throw new Error(
128
+ `Partial Treeseed package checkout detected. Missing package manifests: ${missing}. Run \`git submodule update --init --recursive\` to use workspace mode, or remove the partial checkout to use registry mode.`
129
+ );
130
+ }
131
+ function resolveTreeseedPackageRoot(packageName, exportPath, fallbackDirName) {
132
+ assertUsableTreeseedPackageCheckout(fallbackDirName);
133
+ if (fallbackDirName) {
134
+ const localRoot = resolve(packageRoot, "..", fallbackDirName);
135
+ if (existsSync(resolve(localRoot, "package.json"))) {
136
+ return localRoot;
137
+ }
138
+ }
139
+ try {
140
+ const resolvedEntry = require2.resolve(exportPath ?? packageName);
141
+ if ((exportPath ?? packageName).endsWith("/package.json")) {
142
+ return dirname(resolvedEntry);
143
+ }
144
+ return resolve(dirname(resolvedEntry), "..");
145
+ } catch {
146
+ if (!fallbackDirName) {
147
+ throw new Error(`Unable to resolve package root for "${packageName}".`);
148
+ }
149
+ return resolve(packageRoot, "..", fallbackDirName);
150
+ }
151
+ }
152
+ function resolveAstroBin() {
153
+ return resolvePackageBinary("astro", "astro");
154
+ }
155
+ function resolveWranglerBin() {
156
+ return resolvePackageBinary("wrangler", "wrangler");
157
+ }
158
+ const corePackageRoot = resolveTreeseedPackageRoot("@treeseed/core", "@treeseed/core/config", "core");
159
+ const sdkPackageRoot = resolveTreeseedPackageRoot("@treeseed/sdk", "@treeseed/sdk", "sdk");
160
+ const agentPackageRoot = resolveTreeseedPackageRoot("@treeseed/agent", "@treeseed/agent", "agent");
161
+ function loadPackageJson(root = process.cwd()) {
162
+ const packageJsonPath = resolve(root, "package.json");
163
+ if (!existsSync(packageJsonPath)) {
164
+ return null;
165
+ }
166
+ return JSON.parse(readFileSync(packageJsonPath, "utf8"));
167
+ }
168
+ function isWorkspaceRoot(root = process.cwd()) {
169
+ const packageJson = loadPackageJson(root);
170
+ const workspaces = Array.isArray(packageJson?.workspaces) ? packageJson.workspaces : Array.isArray(packageJson?.workspaces?.packages) ? packageJson.workspaces.packages : [];
171
+ return workspaces.length > 0;
172
+ }
173
+ function createProductionBuildEnv(extraEnv = {}) {
174
+ return {
175
+ TREESEED_LOCAL_DEV_MODE: "cloudflare",
176
+ TREESEED_PUBLIC_FORMS_LOCAL_BYPASS_TURNSTILE: "",
177
+ TREESEED_FORMS_LOCAL_BYPASS_TURNSTILE: "",
178
+ TREESEED_FORMS_LOCAL_BYPASS_CLOUDFLARE_GUARDS: "",
179
+ TREESEED_PUBLIC_DEV_WATCH_RELOAD: "",
180
+ ...extraEnv
181
+ };
182
+ }
183
+ function packageScriptPath(scriptName) {
184
+ if (extname(scriptName)) {
185
+ return resolve(packageScriptRoot, scriptName);
186
+ }
187
+ for (const extension of [".js", ".ts", ".mjs"]) {
188
+ const candidate = resolve(packageScriptRoot, `${scriptName}${extension}`);
189
+ if (existsSync(candidate)) {
190
+ return candidate;
191
+ }
192
+ }
193
+ throw new Error(`Unable to resolve package script "${scriptName}".`);
194
+ }
195
+ function withProcessCwd(cwd, action) {
196
+ const previous = process.cwd();
197
+ if (previous === cwd) {
198
+ return action();
199
+ }
200
+ process.chdir(cwd);
201
+ try {
202
+ return action();
203
+ } finally {
204
+ process.chdir(previous);
205
+ }
206
+ }
207
+ function expectString(value, label) {
208
+ if (typeof value !== "string" || value.trim().length === 0) {
209
+ throw new Error(`Invalid deploy config: expected ${label} to be a non-empty string.`);
210
+ }
211
+ return value.trim();
212
+ }
213
+ function optionalString(value) {
214
+ return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
215
+ }
216
+ function optionalCloudflareAccountId(value) {
217
+ const accountId = optionalString(value);
218
+ return accountId === CLOUDFLARE_ACCOUNT_ID_PLACEHOLDER ? void 0 : accountId;
219
+ }
220
+ function optionalBoolean(value, label) {
221
+ if (value === void 0) {
222
+ return void 0;
223
+ }
224
+ if (typeof value !== "boolean") {
225
+ throw new Error(`Invalid deploy config: expected ${label} to be a boolean when provided.`);
226
+ }
227
+ return value;
228
+ }
229
+ function optionalRecord(value, label) {
230
+ if (value === void 0 || value === null) {
231
+ return void 0;
232
+ }
233
+ if (typeof value !== "object" || Array.isArray(value)) {
234
+ throw new Error(`Invalid deploy config: expected ${label} to be an object when provided.`);
235
+ }
236
+ return value;
237
+ }
238
+ function parsePluginReferences(value) {
239
+ if (value === void 0) {
240
+ return [...TREESEED_DEFAULT_PLUGIN_REFERENCES];
241
+ }
242
+ if (!Array.isArray(value)) {
243
+ throw new Error("Invalid deploy config: expected plugins to be an array.");
244
+ }
245
+ return value.map((entry, index) => {
246
+ const record = optionalRecord(entry, `plugins[${index}]`) ?? {};
247
+ return {
248
+ package: expectString(record.package, `plugins[${index}].package`),
249
+ enabled: record.enabled === void 0 ? true : optionalBoolean(record.enabled, `plugins[${index}].enabled`),
250
+ config: record.config === void 0 ? {} : optionalRecord(record.config, `plugins[${index}].config`)
251
+ };
252
+ });
253
+ }
254
+ function parseFallbackDeployConfig(configPath) {
255
+ const parsed = parseYaml(readFileSync(configPath, "utf8")) ?? {};
256
+ const record = optionalRecord(parsed, "root") ?? {};
257
+ const cloudflare = optionalRecord(record.cloudflare, "cloudflare") ?? {};
258
+ const smtp = optionalRecord(record.smtp, "smtp") ?? {};
259
+ const turnstile = optionalRecord(record.turnstile, "turnstile") ?? {};
260
+ const agentProviders = optionalRecord(optionalRecord(record.providers, "providers")?.agents, "providers.agents") ?? {};
261
+ const contentProviders = optionalRecord(optionalRecord(record.providers, "providers")?.content, "providers.content") ?? {};
262
+ const deployConfig = {
263
+ name: expectString(record.name, "name"),
264
+ slug: expectString(record.slug, "slug"),
265
+ siteUrl: expectString(record.siteUrl, "siteUrl"),
266
+ contactEmail: expectString(record.contactEmail, "contactEmail"),
267
+ cloudflare: {
268
+ accountId: optionalCloudflareAccountId(cloudflare.accountId) ?? optionalCloudflareAccountId(process.env.CLOUDFLARE_ACCOUNT_ID) ?? CLOUDFLARE_ACCOUNT_ID_PLACEHOLDER,
269
+ workerName: optionalString(cloudflare.workerName),
270
+ gatewayWorkerName: optionalString(cloudflare.gatewayWorkerName),
271
+ queueName: optionalString(cloudflare.queueName),
272
+ dlqName: optionalString(cloudflare.dlqName),
273
+ d1Binding: optionalString(cloudflare.d1Binding),
274
+ queueBinding: optionalString(cloudflare.queueBinding)
275
+ },
276
+ plugins: parsePluginReferences(record.plugins),
277
+ providers: {
278
+ forms: expectString(record.providers?.forms ?? TREESEED_DEFAULT_PROVIDER_SELECTIONS.forms, "providers.forms"),
279
+ agents: {
280
+ execution: expectString(agentProviders.execution ?? TREESEED_DEFAULT_PROVIDER_SELECTIONS.agents.execution, "providers.agents.execution"),
281
+ mutation: expectString(agentProviders.mutation ?? TREESEED_DEFAULT_PROVIDER_SELECTIONS.agents.mutation, "providers.agents.mutation"),
282
+ repository: expectString(agentProviders.repository ?? TREESEED_DEFAULT_PROVIDER_SELECTIONS.agents.repository, "providers.agents.repository"),
283
+ verification: expectString(agentProviders.verification ?? TREESEED_DEFAULT_PROVIDER_SELECTIONS.agents.verification, "providers.agents.verification"),
284
+ notification: expectString(agentProviders.notification ?? TREESEED_DEFAULT_PROVIDER_SELECTIONS.agents.notification, "providers.agents.notification"),
285
+ research: expectString(agentProviders.research ?? TREESEED_DEFAULT_PROVIDER_SELECTIONS.agents.research, "providers.agents.research")
286
+ },
287
+ deploy: expectString(record.providers?.deploy ?? TREESEED_DEFAULT_PROVIDER_SELECTIONS.deploy, "providers.deploy"),
288
+ content: {
289
+ docs: expectString(contentProviders.docs ?? TREESEED_DEFAULT_PROVIDER_SELECTIONS.content.docs, "providers.content.docs")
290
+ },
291
+ site: expectString(record.providers?.site ?? TREESEED_DEFAULT_PROVIDER_SELECTIONS.site, "providers.site")
292
+ },
293
+ services: parseManagedServicesConfig(record.services),
294
+ smtp: {
295
+ enabled: optionalBoolean(smtp.enabled, "smtp.enabled")
296
+ },
297
+ turnstile: {
298
+ enabled: optionalBoolean(turnstile.enabled, "turnstile.enabled") ?? true
299
+ }
300
+ };
301
+ Object.defineProperty(deployConfig, "__tenantRoot", {
302
+ value: dirname(configPath),
303
+ enumerable: false
304
+ });
305
+ Object.defineProperty(deployConfig, "__configPath", {
306
+ value: configPath,
307
+ enumerable: false
308
+ });
309
+ return deployConfig;
310
+ }
311
+ function loadCliDeployConfig(tenantRoot) {
312
+ const configPath = resolve(tenantRoot, "treeseed.site.yaml");
313
+ if (!existsSync(configPath)) {
314
+ throw new Error(`Unable to resolve Treeseed deploy config at "${configPath}".`);
315
+ }
316
+ return parseFallbackDeployConfig(configPath);
317
+ }
318
+ function runNodeBinary(binPath, args, options = {}) {
319
+ const result = spawnSync(process.execPath, [binPath, ...args], {
320
+ stdio: options.stdio ?? "inherit",
321
+ cwd: options.cwd ?? process.cwd(),
322
+ env: { ...process.env, ...options.env ?? {} }
323
+ });
324
+ if (result.status !== 0) {
325
+ process.exit(result.status ?? 1);
326
+ }
327
+ }
328
+ function runNodeScript(scriptPath, args = [], options = {}) {
329
+ return runNodeBinary(scriptPath, args, options);
330
+ }
331
+ function spawnNodeBinary(binPath, args, options = {}) {
332
+ return spawn(process.execPath, [binPath, ...args], {
333
+ stdio: options.stdio ?? "inherit",
334
+ cwd: options.cwd ?? process.cwd(),
335
+ env: { ...process.env, ...options.env ?? {} },
336
+ detached: options.detached ?? false
337
+ });
338
+ }
339
+ export {
340
+ agentPackageRoot,
341
+ corePackageRoot,
342
+ createProductionBuildEnv,
343
+ isWorkspaceRoot,
344
+ loadCliDeployConfig,
345
+ loadPackageJson,
346
+ packageRoot,
347
+ packageScriptPath,
348
+ packageScriptRoot,
349
+ resolveAstroBin,
350
+ resolveWranglerBin,
351
+ runNodeBinary,
352
+ runNodeScript,
353
+ runtimeRoot,
354
+ sdkPackageRoot,
355
+ spawnNodeBinary,
356
+ treeseedWorkspacePackageCheckoutState,
357
+ withProcessCwd
358
+ };
@@ -0,0 +1,34 @@
1
+ export declare function validateSaveAutomationPrerequisites({ cwd }: {
2
+ cwd: any;
3
+ }): {
4
+ ok: boolean;
5
+ mode: string;
6
+ missingEnv: never[];
7
+ preflight: null;
8
+ } | {
9
+ ok: boolean;
10
+ mode: string;
11
+ missingEnv: never[];
12
+ preflight: {
13
+ ok: boolean;
14
+ requireAuth: boolean;
15
+ missingCommands: string[];
16
+ failingAuth: string[];
17
+ checks: {
18
+ commands: {
19
+ [k: string]: {
20
+ installed: boolean;
21
+ path: string | null;
22
+ };
23
+ };
24
+ auth: {};
25
+ };
26
+ };
27
+ };
28
+ export declare function runWorkspaceSavePreflight({ cwd }: {
29
+ cwd: any;
30
+ }): void;
31
+ export declare function runTenantDeployPreflight({ cwd, scope }: {
32
+ cwd: any;
33
+ scope?: string | undefined;
34
+ }): void;
@@ -0,0 +1,76 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { packageScriptPath } from "./runtime-tools.js";
3
+ import { applyTreeseedEnvironmentToProcess, assertTreeseedCommandEnvironment } from "./config-runtime.js";
4
+ import { collectCliPreflight } from "./workspace-preflight.js";
5
+ import { getGitHubAutomationMode, requiredGitHubEnvironment } from "./github-automation.js";
6
+ function runStep(label, scriptName, { cwd, env } = {}) {
7
+ const result = spawnSync(process.execPath, [packageScriptPath(scriptName)], {
8
+ cwd,
9
+ env: { ...process.env, ...env ?? {} },
10
+ stdio: "inherit"
11
+ });
12
+ if (result.status !== 0) {
13
+ const error = new Error(`${label} failed.`);
14
+ error.kind = `${label}_failed`;
15
+ error.exitCode = result.status ?? 1;
16
+ throw error;
17
+ }
18
+ }
19
+ function missingRequiredEnv(requiredKeys) {
20
+ return requiredKeys.filter((key) => {
21
+ const value = process.env[key];
22
+ return typeof value !== "string" || value.length === 0;
23
+ });
24
+ }
25
+ function validateSaveAutomationPrerequisites({ cwd }) {
26
+ applyTreeseedEnvironmentToProcess({ tenantRoot: cwd, scope: "prod", override: true });
27
+ assertTreeseedCommandEnvironment({ tenantRoot: cwd, scope: "prod", purpose: "save" });
28
+ if (getGitHubAutomationMode() !== "real") {
29
+ return {
30
+ ok: true,
31
+ mode: "stub",
32
+ missingEnv: [],
33
+ preflight: null
34
+ };
35
+ }
36
+ const preflight = collectCliPreflight({ cwd, requireAuth: true });
37
+ if (!preflight.ok) {
38
+ const error = new Error("Treeseed save prerequisites failed: required GitHub, Cloudflare, or Railway tokens are missing.");
39
+ error.kind = "auth_failed";
40
+ error.details = preflight;
41
+ throw error;
42
+ }
43
+ const required = requiredGitHubEnvironment(cwd, { scope: "prod", purpose: "save" });
44
+ const missingEnv = missingRequiredEnv([...required.secrets, ...required.variables]);
45
+ if (missingEnv.length > 0) {
46
+ const error = new Error(
47
+ `Treeseed save is missing required environment variables: ${missingEnv.join(", ")}.`
48
+ );
49
+ error.kind = "missing_required_env";
50
+ error.missingEnv = missingEnv;
51
+ throw error;
52
+ }
53
+ return {
54
+ ok: true,
55
+ mode: "real",
56
+ missingEnv: [],
57
+ preflight
58
+ };
59
+ }
60
+ function runWorkspaceSavePreflight({ cwd }) {
61
+ runStep("lint", "workspace-lint", { cwd });
62
+ runStep("test", "workspace-test", { cwd });
63
+ runStep("build", "tenant-build", { cwd });
64
+ }
65
+ function runTenantDeployPreflight({ cwd, scope = "prod" }) {
66
+ applyTreeseedEnvironmentToProcess({ tenantRoot: cwd, scope, override: true });
67
+ assertTreeseedCommandEnvironment({ tenantRoot: cwd, scope, purpose: "deploy" });
68
+ runStep("lint", "tenant-lint", { cwd });
69
+ runStep("test", "tenant-test", { cwd });
70
+ runStep("build", "tenant-build", { cwd });
71
+ }
72
+ export {
73
+ runTenantDeployPreflight,
74
+ runWorkspaceSavePreflight,
75
+ validateSaveAutomationPrerequisites
76
+ };
@@ -0,0 +1,88 @@
1
+ import { type SdkTemplateCatalogEntry } from '@treeseed/sdk';
2
+ export declare const TEMPLATE_CATEGORIES: readonly ["starter", "example", "fixture", "reference-app"];
3
+ export type TemplateCategory = (typeof TEMPLATE_CATEGORIES)[number];
4
+ export interface TemplateVariableDefinition {
5
+ name: string;
6
+ token: string;
7
+ deriveFrom?: string;
8
+ required?: boolean;
9
+ default?: string;
10
+ }
11
+ export interface TemplateManifest {
12
+ schemaVersion?: number;
13
+ id: string;
14
+ displayName: string;
15
+ description: string;
16
+ category: TemplateCategory;
17
+ tags: string[];
18
+ templateVersion?: string;
19
+ templateApiVersion: number;
20
+ minCliVersion: string;
21
+ minCoreVersion?: string;
22
+ variables: TemplateVariableDefinition[];
23
+ actions?: string[];
24
+ postCreate?: string[];
25
+ managedSurface?: {
26
+ coreManaged?: string[];
27
+ validatedOnly?: string[];
28
+ tenantManaged?: string[];
29
+ };
30
+ testing: {
31
+ smokeCommand?: string;
32
+ buildCommand?: string;
33
+ };
34
+ }
35
+ export interface TemplateProductDefinition extends SdkTemplateCatalogEntry {
36
+ contentPath: string;
37
+ artifactRoot: string;
38
+ artifactManifestPath: string;
39
+ templateRoot: string;
40
+ }
41
+ export interface ResolvedTemplateDefinition {
42
+ product: TemplateProductDefinition;
43
+ manifestPath: string;
44
+ templateRoot: string;
45
+ manifest: TemplateManifest;
46
+ }
47
+ export interface StarterResolutionInput {
48
+ target: string;
49
+ name?: string | null;
50
+ slug?: string | null;
51
+ siteUrl?: string | null;
52
+ contactEmail?: string | null;
53
+ repositoryUrl?: string | null;
54
+ discordUrl?: string | null;
55
+ }
56
+ interface TemplateCatalogOptions {
57
+ cwd?: string;
58
+ env?: NodeJS.ProcessEnv;
59
+ writeWarning?: (message: string) => void;
60
+ }
61
+ export declare function listTemplateProducts(options?: TemplateCatalogOptions): Promise<TemplateProductDefinition[]>;
62
+ export declare function resolveTemplateProduct(id: string, options?: TemplateCatalogOptions): Promise<TemplateProductDefinition>;
63
+ export declare function resolveTemplateDefinition(id: string, options?: TemplateCatalogOptions, category?: TemplateCategory): Promise<ResolvedTemplateDefinition>;
64
+ export declare function validateTemplateProduct(product: Pick<TemplateProductDefinition, 'id'>, options?: TemplateCatalogOptions): Promise<ResolvedTemplateDefinition>;
65
+ export declare function validateAllTemplateDefinitions(options?: TemplateCatalogOptions): Promise<ResolvedTemplateDefinition[]>;
66
+ export declare function buildTemplateReplacements(manifest: TemplateManifest, input: StarterResolutionInput): Record<string, string>;
67
+ export declare function scaffoldTemplateProject(templateId: string, targetRoot: string, input: StarterResolutionInput, options?: TemplateCatalogOptions): Promise<TemplateProductDefinition>;
68
+ export declare function syncTemplateProject(siteRoot: string, options?: TemplateCatalogOptions & {
69
+ check?: boolean;
70
+ }): Promise<string[]>;
71
+ export declare function serializeTemplateRegistryEntry(product: Pick<TemplateProductDefinition, 'id' | 'displayName' | 'description' | 'summary' | 'status' | 'featured' | 'category' | 'tags' | 'publisher' | 'templateVersion' | 'templateApiVersion' | 'minCliVersion' | 'minCoreVersion' | 'fulfillment'>): {
72
+ id: string;
73
+ displayName: string;
74
+ description: string;
75
+ summary: string;
76
+ status: import("../../sdk-types.ts").SdkTemplateCatalogStatus;
77
+ featured: boolean;
78
+ category: import("../../sdk-types.ts").SdkTemplateCategory;
79
+ tags: string[];
80
+ publisher: import("@treeseed/sdk").SdkTemplateCatalogPublisher;
81
+ templateVersion: string;
82
+ templateApiVersion: number;
83
+ minCliVersion: string;
84
+ minCoreVersion: string | undefined;
85
+ source: import("@treeseed/sdk").SdkTemplateCatalogSource;
86
+ };
87
+ export declare function exportTemplateCatalogYaml(options?: TemplateCatalogOptions): Promise<string>;
88
+ export {};