@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,56 @@
1
+ import type { TreeseedWorkflowNextStep } from './workflow.ts';
2
+ export type TreeseedBranchRole = 'feature' | 'staging' | 'main' | 'detached' | 'none';
3
+ export type TreeseedWorkflowRecommendation = TreeseedWorkflowNextStep;
4
+ export type TreeseedWorkflowState = {
5
+ cwd: string;
6
+ workspaceRoot: boolean;
7
+ tenantRoot: boolean;
8
+ deployConfigPresent: boolean;
9
+ repoRoot: string | null;
10
+ branchName: string | null;
11
+ branchRole: TreeseedBranchRole;
12
+ environment: 'local' | 'staging' | 'prod' | 'none';
13
+ dirtyWorktree: boolean;
14
+ preview: {
15
+ enabled: boolean;
16
+ url: string | null;
17
+ lastDeploymentTimestamp: string | null;
18
+ };
19
+ persistentEnvironments: Record<string, {
20
+ initialized: boolean;
21
+ lastValidatedAt: string | null;
22
+ lastDeploymentTimestamp: string | null;
23
+ lastDeployedUrl: string | null;
24
+ }>;
25
+ auth: {
26
+ gh: boolean;
27
+ wrangler: boolean;
28
+ railway: boolean;
29
+ copilot: boolean;
30
+ remoteApi: boolean;
31
+ };
32
+ managedServices: Record<string, {
33
+ enabled: boolean;
34
+ initialized: boolean;
35
+ lastDeploymentTimestamp: string | null;
36
+ lastDeployedUrl: string | null;
37
+ provider: string | null;
38
+ }>;
39
+ files: {
40
+ treeseedConfig: boolean;
41
+ machineConfig: boolean;
42
+ machineKey: boolean;
43
+ envLocal: boolean;
44
+ devVars: boolean;
45
+ };
46
+ releaseReady: boolean;
47
+ rollbackCandidates: Array<{
48
+ scope: 'staging' | 'prod';
49
+ commit: string | null;
50
+ timestamp: string | null;
51
+ url: string | null;
52
+ }>;
53
+ recommendations: TreeseedWorkflowRecommendation[];
54
+ };
55
+ export declare function resolveTreeseedWorkflowState(cwd: string): TreeseedWorkflowState;
56
+ export declare function recommendTreeseedNextSteps(state: TreeseedWorkflowState): TreeseedWorkflowRecommendation[];
@@ -0,0 +1,195 @@
1
+ import { existsSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import { getTreeseedMachineConfigPaths, resolveTreeseedRemoteSession } from "./operations/services/config-runtime.js";
4
+ import {
5
+ createBranchPreviewDeployTarget,
6
+ createPersistentDeployTarget,
7
+ loadDeployState
8
+ } from "./operations/services/deploy.js";
9
+ import { PRODUCTION_BRANCH, STAGING_BRANCH } from "./operations/services/git-workflow.js";
10
+ import { loadCliDeployConfig } from "./operations/services/runtime-tools.js";
11
+ import { collectCliPreflight } from "./operations/services/workspace-preflight.js";
12
+ import { currentBranch, gitStatusPorcelain, repoRoot } from "./operations/services/workspace-save.js";
13
+ import { isWorkspaceRoot } from "./operations/services/workspace-tools.js";
14
+ function safeResolveRepoRoot(cwd) {
15
+ try {
16
+ return repoRoot(cwd);
17
+ } catch {
18
+ return null;
19
+ }
20
+ }
21
+ function branchRoleFor(branchName) {
22
+ if (!branchName) return "none";
23
+ if (branchName === STAGING_BRANCH) return "staging";
24
+ if (branchName === PRODUCTION_BRANCH) return "main";
25
+ return "feature";
26
+ }
27
+ function environmentForBranchRole(branchRole) {
28
+ if (branchRole === "staging") return "staging";
29
+ if (branchRole === "main") return "prod";
30
+ if (branchRole === "feature") return "local";
31
+ return "none";
32
+ }
33
+ function emptyPersistentEnvironments() {
34
+ return {
35
+ local: { initialized: false, lastValidatedAt: null, lastDeploymentTimestamp: null, lastDeployedUrl: null },
36
+ staging: { initialized: false, lastValidatedAt: null, lastDeploymentTimestamp: null, lastDeployedUrl: null },
37
+ prod: { initialized: false, lastValidatedAt: null, lastDeploymentTimestamp: null, lastDeployedUrl: null }
38
+ };
39
+ }
40
+ function resolveTreeseedWorkflowState(cwd) {
41
+ const workspaceRoot = isWorkspaceRoot(cwd);
42
+ const treeseedConfigPath = resolve(cwd, "treeseed.site.yaml");
43
+ const tenantRoot = existsSync(treeseedConfigPath);
44
+ const root = safeResolveRepoRoot(cwd);
45
+ const branchName = root ? currentBranch(root) || null : null;
46
+ const branchRole = branchRoleFor(branchName);
47
+ const dirtyWorktree = root ? gitStatusPorcelain(root).length > 0 : false;
48
+ const preflight = collectCliPreflight({ cwd, requireAuth: false });
49
+ const { configPath, keyPath } = getTreeseedMachineConfigPaths(cwd);
50
+ const state = {
51
+ cwd,
52
+ workspaceRoot,
53
+ tenantRoot,
54
+ deployConfigPresent: tenantRoot,
55
+ repoRoot: root,
56
+ branchName,
57
+ branchRole,
58
+ environment: environmentForBranchRole(branchRole),
59
+ dirtyWorktree,
60
+ preview: {
61
+ enabled: false,
62
+ url: null,
63
+ lastDeploymentTimestamp: null
64
+ },
65
+ persistentEnvironments: emptyPersistentEnvironments(),
66
+ auth: {
67
+ gh: preflight.checks.auth.gh?.authenticated === true,
68
+ wrangler: preflight.checks.auth.wrangler?.authenticated === true,
69
+ railway: preflight.checks.auth.railway?.authenticated === true,
70
+ copilot: preflight.checks.auth.copilot?.configured === true,
71
+ remoteApi: Boolean(resolveTreeseedRemoteSession(cwd))
72
+ },
73
+ managedServices: {
74
+ api: { enabled: false, initialized: false, lastDeploymentTimestamp: null, lastDeployedUrl: null, provider: null },
75
+ agents: { enabled: false, initialized: false, lastDeploymentTimestamp: null, lastDeployedUrl: null, provider: null },
76
+ manager: { enabled: false, initialized: false, lastDeploymentTimestamp: null, lastDeployedUrl: null, provider: null },
77
+ worker: { enabled: false, initialized: false, lastDeploymentTimestamp: null, lastDeployedUrl: null, provider: null },
78
+ workdayStart: { enabled: false, initialized: false, lastDeploymentTimestamp: null, lastDeployedUrl: null, provider: null },
79
+ workdayReport: { enabled: false, initialized: false, lastDeploymentTimestamp: null, lastDeployedUrl: null, provider: null }
80
+ },
81
+ files: {
82
+ treeseedConfig: tenantRoot,
83
+ machineConfig: existsSync(configPath),
84
+ machineKey: existsSync(keyPath),
85
+ envLocal: existsSync(resolve(cwd, ".env.local")),
86
+ devVars: existsSync(resolve(cwd, ".dev.vars"))
87
+ },
88
+ releaseReady: branchRole === "staging" && !dirtyWorktree,
89
+ rollbackCandidates: [],
90
+ recommendations: []
91
+ };
92
+ if (tenantRoot) {
93
+ try {
94
+ const deployConfig = loadCliDeployConfig(cwd);
95
+ for (const scope of ["local", "staging", "prod"]) {
96
+ const deployState = loadDeployState(cwd, deployConfig, { target: createPersistentDeployTarget(scope) });
97
+ state.persistentEnvironments[scope] = {
98
+ initialized: deployState.readiness?.initialized === true || scope === "local",
99
+ lastValidatedAt: deployState.readiness?.lastValidatedAt ?? deployState.readiness?.initializedAt ?? null,
100
+ lastDeploymentTimestamp: deployState.lastDeploymentTimestamp ?? null,
101
+ lastDeployedUrl: deployState.lastDeployedUrl ?? null
102
+ };
103
+ if (scope !== "local") {
104
+ const history = Array.isArray(deployState.deploymentHistory) ? deployState.deploymentHistory ?? [] : [];
105
+ const latestHistory = history.at(-1) ?? null;
106
+ state.rollbackCandidates.push({
107
+ scope,
108
+ commit: typeof latestHistory?.commit === "string" ? latestHistory.commit : deployState.lastDeployedCommit ?? null,
109
+ timestamp: typeof latestHistory?.timestamp === "string" ? latestHistory.timestamp : deployState.lastDeploymentTimestamp ?? null,
110
+ url: typeof latestHistory?.url === "string" ? latestHistory.url : deployState.lastDeployedUrl ?? null
111
+ });
112
+ }
113
+ for (const serviceKey of ["api", "agents", "manager", "worker", "workdayStart", "workdayReport"]) {
114
+ const service = deployState.services?.[serviceKey];
115
+ if (!service) continue;
116
+ state.managedServices[serviceKey] = {
117
+ enabled: service.enabled === true,
118
+ initialized: service.initialized === true,
119
+ lastDeploymentTimestamp: service.lastDeploymentTimestamp ?? null,
120
+ lastDeployedUrl: service.lastDeployedUrl ?? service.publicBaseUrl ?? null,
121
+ provider: service.provider ?? null
122
+ };
123
+ }
124
+ }
125
+ if (branchRole === "feature" && branchName) {
126
+ const previewState = loadDeployState(cwd, deployConfig, { target: createBranchPreviewDeployTarget(branchName) });
127
+ state.preview = {
128
+ enabled: previewState.previewEnabled === true || previewState.readiness?.initialized === true,
129
+ url: previewState.lastDeployedUrl ?? null,
130
+ lastDeploymentTimestamp: previewState.lastDeploymentTimestamp ?? null
131
+ };
132
+ }
133
+ } catch {
134
+ }
135
+ }
136
+ state.recommendations = recommendTreeseedNextSteps(state);
137
+ return state;
138
+ }
139
+ function recommendTreeseedNextSteps(state) {
140
+ const recommendations = [];
141
+ if (!state.workspaceRoot) {
142
+ return [{ operation: "status", reason: "Run this from inside a Treeseed workspace so the project root can be resolved." }];
143
+ }
144
+ if (!state.deployConfigPresent) {
145
+ return [{ operation: "init", reason: "Create a new Treeseed tenant before configuring or releasing anything.", input: { directory: "<directory>" } }];
146
+ }
147
+ if (!state.files.machineConfig) {
148
+ recommendations.push({ operation: "status", reason: "Validate tooling, auth, and repository readiness first." });
149
+ recommendations.push({ operation: "config", reason: "Bootstrap the local machine config and local environment files." });
150
+ return recommendations;
151
+ }
152
+ if (state.branchRole === "feature") {
153
+ if (state.dirtyWorktree) {
154
+ recommendations.push({ operation: "save", reason: "Persist, verify, and push the current task branch before staging or closing it.", input: { message: "describe your change" } });
155
+ } else {
156
+ recommendations.push({ operation: "stage", reason: "Merge this task branch into staging and clean up branch artifacts.", input: { message: "describe the resolution" } });
157
+ }
158
+ if (state.preview.enabled && state.branchName) {
159
+ recommendations.push({ operation: "save", reason: "Save refreshes the branch preview deployment when one is enabled.", input: { message: "describe your change" } });
160
+ } else {
161
+ recommendations.push({ operation: "dev", reason: "Use the local environment for iterative work on this feature branch." });
162
+ }
163
+ recommendations.push({ operation: "close", reason: "Archive this task without merging if it should be abandoned.", input: { message: "reason" } });
164
+ return recommendations.slice(0, 3);
165
+ }
166
+ if (state.branchRole === "staging") {
167
+ if (!state.persistentEnvironments.staging.initialized) {
168
+ recommendations.push({ operation: "config", reason: "Initialize the staging environment before releasing.", input: { environment: ["staging"] } });
169
+ } else {
170
+ recommendations.push({ operation: "release", reason: "Promote staging into main when the integration branch is ready for production.", input: { bump: "patch" } });
171
+ if (state.managedServices.api.enabled || state.managedServices.agents.enabled) {
172
+ recommendations.push({ operation: "auth:login", reason: "Keep the local runtime authenticated to the remote API used by managed services." });
173
+ }
174
+ }
175
+ return recommendations.slice(0, 3);
176
+ }
177
+ if (state.branchRole === "main") {
178
+ if (state.dirtyWorktree) {
179
+ recommendations.push({ operation: "save", reason: "Only explicit hotfix saves are allowed on main.", input: { message: "describe the hotfix", hotfix: true } });
180
+ } else if (!state.persistentEnvironments.prod.initialized) {
181
+ recommendations.push({ operation: "config", reason: "Initialize production before a release requires it.", input: { environment: ["prod"] } });
182
+ } else {
183
+ recommendations.push({ operation: "status", reason: "Inspect production state and release readiness." });
184
+ recommendations.push({ operation: "rollback", reason: "Roll back production to the previous recorded deployment if needed.", input: { environment: "prod" } });
185
+ }
186
+ return recommendations.slice(0, 3);
187
+ }
188
+ recommendations.push({ operation: "dev", reason: "Start the local Treeseed development environment." });
189
+ recommendations.push({ operation: "switch", reason: "Create a task branch from the latest staging commit.", input: { branch: "feature/my-change" } });
190
+ return recommendations.slice(0, 3);
191
+ }
192
+ export {
193
+ recommendTreeseedNextSteps,
194
+ resolveTreeseedWorkflowState
195
+ };
@@ -0,0 +1,9 @@
1
+ export { applyTreeseedEnvironmentToProcess, assertTreeseedCommandEnvironment, checkTreeseedProviderConnections, clearTreeseedRemoteSession, createDefaultTreeseedMachineConfig, ensureTreeseedGitignoreEntries, formatTreeseedConfigEnvironmentReport, formatTreeseedProviderConnectionReport, getTreeseedMachineConfigPaths, loadTreeseedMachineConfig, resolveTreeseedMachineEnvironmentValues, resolveTreeseedRemoteConfig, resolveTreeseedRemoteSession, rotateTreeseedMachineKey, runTreeseedConfigWizard, setTreeseedRemoteSession, writeTreeseedLocalEnvironmentFiles, writeTreeseedMachineConfig, } from './operations/services/config-runtime.ts';
2
+ export { assertDeploymentInitialized, cleanupDestroyedState, createBranchPreviewDeployTarget, createPersistentDeployTarget, deployTargetLabel, destroyCloudflareResources, ensureGeneratedWranglerConfig, finalizeDeploymentState, loadDeployState, printDeploySummary, printDestroySummary, provisionCloudflareResources, runRemoteD1Migrations, syncCloudflareSecrets, validateDeployPrerequisites, validateDestroyPrerequisites, } from './operations/services/deploy.ts';
3
+ export { assertCleanWorktree, assertFeatureBranch, branchExists, checkoutBranch, createDeprecatedTaskTag, createFeatureBranchFromStaging, currentManagedBranch, deleteLocalBranch, deleteRemoteBranch, ensureLocalBranchTracking, gitWorkflowRoot, listTaskBranches, mergeCurrentBranchIntoStaging, mergeStagingIntoMain, prepareReleaseBranches, PRODUCTION_BRANCH, pushBranch, remoteBranchExists, STAGING_BRANCH, syncBranchWithOrigin, waitForStagingAutomation, } from './operations/services/git-workflow.ts';
4
+ export { loadCliDeployConfig, packageScriptPath, resolveWranglerBin, } from './operations/services/runtime-tools.ts';
5
+ export { configuredRailwayServices, deployRailwayService, validateRailwayDeployPrerequisites, } from './operations/services/railway-deploy.ts';
6
+ export { runTenantDeployPreflight, runWorkspaceSavePreflight, } from './operations/services/save-deploy-preflight.ts';
7
+ export { collectCliPreflight } from './operations/services/workspace-preflight.ts';
8
+ export { applyWorkspaceVersionChanges, collectMergeConflictReport, currentBranch, formatMergeConflictReport, gitStatusPorcelain, hasMeaningfulChanges, incrementVersion, originRemoteUrl, planWorkspaceReleaseBump, repoRoot, } from './operations/services/workspace-save.ts';
9
+ export { findNearestTreeseedRoot, findNearestTreeseedWorkspaceRoot, isWorkspaceRoot, run, workspaceRoot, } from './operations/services/workspace-tools.ts';
@@ -0,0 +1,176 @@
1
+ import {
2
+ applyTreeseedEnvironmentToProcess,
3
+ assertTreeseedCommandEnvironment,
4
+ checkTreeseedProviderConnections,
5
+ clearTreeseedRemoteSession,
6
+ createDefaultTreeseedMachineConfig,
7
+ ensureTreeseedGitignoreEntries,
8
+ formatTreeseedConfigEnvironmentReport,
9
+ formatTreeseedProviderConnectionReport,
10
+ getTreeseedMachineConfigPaths,
11
+ loadTreeseedMachineConfig,
12
+ resolveTreeseedMachineEnvironmentValues,
13
+ resolveTreeseedRemoteConfig,
14
+ resolveTreeseedRemoteSession,
15
+ rotateTreeseedMachineKey,
16
+ runTreeseedConfigWizard,
17
+ setTreeseedRemoteSession,
18
+ writeTreeseedLocalEnvironmentFiles,
19
+ writeTreeseedMachineConfig
20
+ } from "./operations/services/config-runtime.js";
21
+ import {
22
+ assertDeploymentInitialized,
23
+ cleanupDestroyedState,
24
+ createBranchPreviewDeployTarget,
25
+ createPersistentDeployTarget,
26
+ deployTargetLabel,
27
+ destroyCloudflareResources,
28
+ ensureGeneratedWranglerConfig,
29
+ finalizeDeploymentState,
30
+ loadDeployState,
31
+ printDeploySummary,
32
+ printDestroySummary,
33
+ provisionCloudflareResources,
34
+ runRemoteD1Migrations,
35
+ syncCloudflareSecrets,
36
+ validateDeployPrerequisites,
37
+ validateDestroyPrerequisites
38
+ } from "./operations/services/deploy.js";
39
+ import {
40
+ assertCleanWorktree,
41
+ assertFeatureBranch,
42
+ branchExists,
43
+ checkoutBranch,
44
+ createDeprecatedTaskTag,
45
+ createFeatureBranchFromStaging,
46
+ currentManagedBranch,
47
+ deleteLocalBranch,
48
+ deleteRemoteBranch,
49
+ ensureLocalBranchTracking,
50
+ gitWorkflowRoot,
51
+ listTaskBranches,
52
+ mergeCurrentBranchIntoStaging,
53
+ mergeStagingIntoMain,
54
+ prepareReleaseBranches,
55
+ PRODUCTION_BRANCH,
56
+ pushBranch,
57
+ remoteBranchExists,
58
+ STAGING_BRANCH,
59
+ syncBranchWithOrigin,
60
+ waitForStagingAutomation
61
+ } from "./operations/services/git-workflow.js";
62
+ import {
63
+ loadCliDeployConfig,
64
+ packageScriptPath,
65
+ resolveWranglerBin
66
+ } from "./operations/services/runtime-tools.js";
67
+ import {
68
+ configuredRailwayServices,
69
+ deployRailwayService,
70
+ validateRailwayDeployPrerequisites
71
+ } from "./operations/services/railway-deploy.js";
72
+ import {
73
+ runTenantDeployPreflight,
74
+ runWorkspaceSavePreflight
75
+ } from "./operations/services/save-deploy-preflight.js";
76
+ import { collectCliPreflight } from "./operations/services/workspace-preflight.js";
77
+ import {
78
+ applyWorkspaceVersionChanges,
79
+ collectMergeConflictReport,
80
+ currentBranch,
81
+ formatMergeConflictReport,
82
+ gitStatusPorcelain,
83
+ hasMeaningfulChanges,
84
+ incrementVersion,
85
+ originRemoteUrl,
86
+ planWorkspaceReleaseBump,
87
+ repoRoot
88
+ } from "./operations/services/workspace-save.js";
89
+ import {
90
+ findNearestTreeseedRoot,
91
+ findNearestTreeseedWorkspaceRoot,
92
+ isWorkspaceRoot,
93
+ run,
94
+ workspaceRoot
95
+ } from "./operations/services/workspace-tools.js";
96
+ export {
97
+ PRODUCTION_BRANCH,
98
+ STAGING_BRANCH,
99
+ applyTreeseedEnvironmentToProcess,
100
+ applyWorkspaceVersionChanges,
101
+ assertCleanWorktree,
102
+ assertDeploymentInitialized,
103
+ assertFeatureBranch,
104
+ assertTreeseedCommandEnvironment,
105
+ branchExists,
106
+ checkTreeseedProviderConnections,
107
+ checkoutBranch,
108
+ cleanupDestroyedState,
109
+ clearTreeseedRemoteSession,
110
+ collectCliPreflight,
111
+ collectMergeConflictReport,
112
+ configuredRailwayServices,
113
+ createBranchPreviewDeployTarget,
114
+ createDefaultTreeseedMachineConfig,
115
+ createDeprecatedTaskTag,
116
+ createFeatureBranchFromStaging,
117
+ createPersistentDeployTarget,
118
+ currentBranch,
119
+ currentManagedBranch,
120
+ deleteLocalBranch,
121
+ deleteRemoteBranch,
122
+ deployRailwayService,
123
+ deployTargetLabel,
124
+ destroyCloudflareResources,
125
+ ensureGeneratedWranglerConfig,
126
+ ensureLocalBranchTracking,
127
+ ensureTreeseedGitignoreEntries,
128
+ finalizeDeploymentState,
129
+ findNearestTreeseedRoot,
130
+ findNearestTreeseedWorkspaceRoot,
131
+ formatMergeConflictReport,
132
+ formatTreeseedConfigEnvironmentReport,
133
+ formatTreeseedProviderConnectionReport,
134
+ getTreeseedMachineConfigPaths,
135
+ gitStatusPorcelain,
136
+ gitWorkflowRoot,
137
+ hasMeaningfulChanges,
138
+ incrementVersion,
139
+ isWorkspaceRoot,
140
+ listTaskBranches,
141
+ loadCliDeployConfig,
142
+ loadDeployState,
143
+ loadTreeseedMachineConfig,
144
+ mergeCurrentBranchIntoStaging,
145
+ mergeStagingIntoMain,
146
+ originRemoteUrl,
147
+ packageScriptPath,
148
+ planWorkspaceReleaseBump,
149
+ prepareReleaseBranches,
150
+ printDeploySummary,
151
+ printDestroySummary,
152
+ provisionCloudflareResources,
153
+ pushBranch,
154
+ remoteBranchExists,
155
+ repoRoot,
156
+ resolveTreeseedMachineEnvironmentValues,
157
+ resolveTreeseedRemoteConfig,
158
+ resolveTreeseedRemoteSession,
159
+ resolveWranglerBin,
160
+ rotateTreeseedMachineKey,
161
+ run,
162
+ runRemoteD1Migrations,
163
+ runTenantDeployPreflight,
164
+ runTreeseedConfigWizard,
165
+ runWorkspaceSavePreflight,
166
+ setTreeseedRemoteSession,
167
+ syncBranchWithOrigin,
168
+ syncCloudflareSecrets,
169
+ validateDeployPrerequisites,
170
+ validateDestroyPrerequisites,
171
+ validateRailwayDeployPrerequisites,
172
+ waitForStagingAutomation,
173
+ workspaceRoot,
174
+ writeTreeseedLocalEnvironmentFiles,
175
+ writeTreeseedMachineConfig
176
+ };
@@ -0,0 +1,111 @@
1
+ import { resolveTreeseedWorkflowState } from './workflow-state.ts';
2
+ import { listTaskBranches } from './operations/services/git-workflow.ts';
3
+ import { TreeseedWorkflowError, type TreeseedWorkflowErrorCode } from './workflow/operations.ts';
4
+ export type TreeseedWorkflowOperationId = 'status' | 'config' | 'tasks' | 'switch' | 'dev' | 'save' | 'close' | 'stage' | 'release' | 'destroy';
5
+ export type TreeseedWorkflowNextStep = {
6
+ operation: string;
7
+ reason?: string;
8
+ input?: Record<string, unknown>;
9
+ };
10
+ export type TreeseedWorkflowContext = {
11
+ cwd?: string;
12
+ env?: NodeJS.ProcessEnv;
13
+ write?: (output: string, stream?: 'stdout' | 'stderr') => void;
14
+ prompt?: (message: string) => Promise<string> | string;
15
+ confirm?: (message: string, expected: string) => Promise<boolean> | boolean;
16
+ transport?: 'sdk' | 'cli' | 'api';
17
+ };
18
+ export type TreeseedWorkflowResult<TPayload = Record<string, unknown>> = {
19
+ ok: boolean;
20
+ operation: TreeseedWorkflowOperationId;
21
+ payload: TPayload;
22
+ nextSteps?: TreeseedWorkflowNextStep[];
23
+ };
24
+ export type TreeseedTaskBranchMetadata = ReturnType<typeof listTaskBranches>[number] & {
25
+ ageDays: number | null;
26
+ dirtyCurrent: boolean;
27
+ preview: {
28
+ enabled: boolean;
29
+ url: string | null;
30
+ lastDeploymentTimestamp: string | null;
31
+ };
32
+ };
33
+ export type TreeseedSaveInput = {
34
+ message: string;
35
+ hotfix?: boolean;
36
+ verify?: boolean;
37
+ refreshPreview?: boolean;
38
+ rebase?: boolean;
39
+ };
40
+ export type TreeseedCloseInput = {
41
+ message: string;
42
+ deletePreview?: boolean;
43
+ deleteBranch?: boolean;
44
+ };
45
+ export type TreeseedStageInput = {
46
+ message: string;
47
+ waitForStaging?: boolean;
48
+ deletePreview?: boolean;
49
+ deleteBranch?: boolean;
50
+ };
51
+ export type TreeseedSwitchInput = {
52
+ branch?: string;
53
+ branchName?: string;
54
+ preview?: boolean;
55
+ createIfMissing?: boolean;
56
+ baseBranch?: string;
57
+ };
58
+ export type TreeseedConfigScope = 'all' | 'local' | 'staging' | 'prod';
59
+ export type TreeseedConfigInput = {
60
+ target?: TreeseedConfigScope[] | TreeseedConfigScope;
61
+ environment?: TreeseedConfigScope[] | TreeseedConfigScope;
62
+ syncProviders?: 'none' | 'github' | 'cloudflare' | 'railway' | 'all';
63
+ sync?: 'none' | 'github' | 'cloudflare' | 'railway' | 'all';
64
+ repair?: boolean;
65
+ printEnv?: boolean;
66
+ printEnvOnly?: boolean;
67
+ showSecrets?: boolean;
68
+ rotateMachineKey?: boolean;
69
+ nonInteractive?: boolean;
70
+ };
71
+ export type TreeseedReleaseInput = {
72
+ bump: 'major' | 'minor' | 'patch';
73
+ };
74
+ export type TreeseedDestroyInput = {
75
+ target?: 'local' | 'staging' | 'prod';
76
+ environment?: 'local' | 'staging' | 'prod';
77
+ confirm?: boolean | string;
78
+ dryRun?: boolean;
79
+ destroyRemote?: boolean;
80
+ destroyLocal?: boolean;
81
+ force?: boolean;
82
+ removeBuildArtifacts?: boolean;
83
+ };
84
+ export type TreeseedWorkflowDevInput = {
85
+ watch?: boolean;
86
+ port?: number | string;
87
+ background?: boolean;
88
+ stdio?: 'inherit' | 'pipe';
89
+ };
90
+ export { TreeseedWorkflowError };
91
+ export type { TreeseedWorkflowErrorCode };
92
+ export declare class TreeseedWorkflowSdk {
93
+ private readonly context;
94
+ constructor(context?: TreeseedWorkflowContext);
95
+ private helpers;
96
+ execute(operation: TreeseedWorkflowOperationId, input?: Record<string, unknown>): Promise<TreeseedWorkflowResult<import("./workflow-state.ts").TreeseedWorkflowState> | TreeseedWorkflowResult<Record<string, unknown>> | TreeseedWorkflowResult<{
97
+ tasks: TreeseedTaskBranchMetadata[];
98
+ }>>;
99
+ status(): Promise<TreeseedWorkflowResult<ReturnType<typeof resolveTreeseedWorkflowState>>>;
100
+ tasks(): Promise<TreeseedWorkflowResult<{
101
+ tasks: TreeseedTaskBranchMetadata[];
102
+ }>>;
103
+ config(input?: TreeseedConfigInput): Promise<TreeseedWorkflowResult>;
104
+ switchTask(input: TreeseedSwitchInput): Promise<TreeseedWorkflowResult>;
105
+ dev(input?: TreeseedWorkflowDevInput): Promise<TreeseedWorkflowResult>;
106
+ save(input: TreeseedSaveInput): Promise<TreeseedWorkflowResult>;
107
+ close(input: TreeseedCloseInput): Promise<TreeseedWorkflowResult>;
108
+ stage(input: TreeseedStageInput): Promise<TreeseedWorkflowResult>;
109
+ release(input: TreeseedReleaseInput): Promise<TreeseedWorkflowResult>;
110
+ destroy(input: TreeseedDestroyInput): Promise<TreeseedWorkflowResult>;
111
+ }
@@ -0,0 +1,97 @@
1
+ import {
2
+ TreeseedWorkflowError,
3
+ workflowClose,
4
+ workflowConfig,
5
+ workflowDestroy,
6
+ workflowDev,
7
+ workflowRelease,
8
+ workflowSave,
9
+ workflowStage,
10
+ workflowStatus,
11
+ workflowSwitch,
12
+ workflowTasks
13
+ } from "./workflow/operations.js";
14
+ function defaultWrite(output, stream = "stdout") {
15
+ if (!output) return;
16
+ (stream === "stderr" ? process.stderr : process.stdout).write(`${output}
17
+ `);
18
+ }
19
+ class TreeseedWorkflowSdk {
20
+ constructor(context = {}) {
21
+ this.context = context;
22
+ }
23
+ context;
24
+ helpers() {
25
+ const context = {
26
+ transport: "sdk",
27
+ ...this.context
28
+ };
29
+ return {
30
+ context,
31
+ cwd: () => context.cwd ?? process.cwd(),
32
+ write: context.write ?? defaultWrite,
33
+ runStatus: async () => this.status(),
34
+ runTasks: async () => this.tasks()
35
+ };
36
+ }
37
+ async execute(operation, input = {}) {
38
+ switch (operation) {
39
+ case "status":
40
+ return this.status();
41
+ case "tasks":
42
+ return this.tasks();
43
+ case "config":
44
+ return this.config(input);
45
+ case "switch":
46
+ return this.switchTask(input);
47
+ case "dev":
48
+ return this.dev(input);
49
+ case "save":
50
+ return this.save(input);
51
+ case "close":
52
+ return this.close(input);
53
+ case "stage":
54
+ return this.stage(input);
55
+ case "release":
56
+ return this.release(input);
57
+ case "destroy":
58
+ return this.destroy(input);
59
+ default:
60
+ throw new Error(`Unsupported workflow operation "${operation}".`);
61
+ }
62
+ }
63
+ async status() {
64
+ return workflowStatus(this.helpers());
65
+ }
66
+ async tasks() {
67
+ return workflowTasks(this.helpers());
68
+ }
69
+ async config(input = {}) {
70
+ return workflowConfig(this.helpers(), input);
71
+ }
72
+ async switchTask(input) {
73
+ return workflowSwitch(this.helpers(), input);
74
+ }
75
+ async dev(input = {}) {
76
+ return workflowDev(this.helpers(), input);
77
+ }
78
+ async save(input) {
79
+ return workflowSave(this.helpers(), input);
80
+ }
81
+ async close(input) {
82
+ return workflowClose(this.helpers(), input);
83
+ }
84
+ async stage(input) {
85
+ return workflowStage(this.helpers(), input);
86
+ }
87
+ async release(input) {
88
+ return workflowRelease(this.helpers(), input);
89
+ }
90
+ async destroy(input) {
91
+ return workflowDestroy(this.helpers(), input);
92
+ }
93
+ }
94
+ export {
95
+ TreeseedWorkflowError,
96
+ TreeseedWorkflowSdk
97
+ };