@treeseed/sdk 0.1.1 → 0.3.0
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.
- package/README.md +97 -494
- package/dist/{src/cli-tools.d.ts → cli-tools.d.ts} +1 -1
- package/dist/cli-tools.js +5 -3
- package/dist/{src/content-store.d.ts → content-store.d.ts} +3 -2
- package/dist/content-store.js +52 -20
- package/dist/{src/d1-store.d.ts → d1-store.d.ts} +62 -1
- package/dist/d1-store.js +625 -65
- package/dist/field-aliases.d.ts +11 -0
- package/dist/field-aliases.js +41 -0
- package/dist/graph/build.d.ts +19 -0
- package/dist/graph/build.js +949 -0
- package/dist/graph/dsl.d.ts +2 -0
- package/dist/graph/dsl.js +243 -0
- package/dist/graph/query.d.ts +47 -0
- package/dist/graph/query.js +447 -0
- package/dist/graph/ranking.d.ts +3 -0
- package/dist/graph/ranking.js +483 -0
- package/dist/graph/schema.d.ts +142 -0
- package/dist/graph/schema.js +133 -0
- package/dist/graph.d.ts +52 -0
- package/dist/graph.js +133 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +90 -2
- package/dist/model-registry.d.ts +8 -0
- package/dist/model-registry.js +351 -25
- package/dist/operations/providers/default.d.ts +10 -0
- package/dist/operations/providers/default.js +514 -0
- package/dist/operations/runtime.d.ts +7 -0
- package/dist/operations/runtime.js +60 -0
- package/dist/operations/services/config-runtime.d.ts +269 -0
- package/dist/operations/services/config-runtime.js +1397 -0
- package/dist/operations/services/d1-migration.d.ts +6 -0
- package/dist/operations/services/d1-migration.js +89 -0
- package/dist/operations/services/deploy.d.ts +371 -0
- package/dist/operations/services/deploy.js +981 -0
- package/dist/operations/services/git-workflow.d.ts +49 -0
- package/dist/operations/services/git-workflow.js +218 -0
- package/dist/operations/services/github-automation.d.ts +156 -0
- package/dist/operations/services/github-automation.js +256 -0
- package/dist/operations/services/local-dev.d.ts +9 -0
- package/dist/operations/services/local-dev.js +106 -0
- package/dist/operations/services/mailpit-runtime.d.ts +4 -0
- package/dist/operations/services/mailpit-runtime.js +59 -0
- package/dist/operations/services/railway-deploy.d.ts +53 -0
- package/dist/operations/services/railway-deploy.js +123 -0
- package/dist/operations/services/runtime-paths.d.ts +19 -0
- package/dist/operations/services/runtime-paths.js +54 -0
- package/dist/operations/services/runtime-tools.d.ts +117 -0
- package/dist/operations/services/runtime-tools.js +358 -0
- package/dist/operations/services/save-deploy-preflight.d.ts +34 -0
- package/dist/operations/services/save-deploy-preflight.js +76 -0
- package/dist/operations/services/template-registry.d.ts +88 -0
- package/dist/operations/services/template-registry.js +407 -0
- package/dist/operations/services/watch-dev.d.ts +21 -0
- package/dist/operations/services/watch-dev.js +284 -0
- package/dist/operations/services/workspace-preflight.d.ts +40 -0
- package/dist/operations/services/workspace-preflight.js +165 -0
- package/dist/operations/services/workspace-save.d.ts +42 -0
- package/dist/operations/services/workspace-save.js +235 -0
- package/dist/operations/services/workspace-tools.d.ts +16 -0
- package/dist/operations/services/workspace-tools.js +270 -0
- package/dist/operations-registry.d.ts +5 -0
- package/dist/operations-registry.js +68 -0
- package/dist/operations-types.d.ts +71 -0
- package/dist/operations-types.js +17 -0
- package/dist/operations.d.ts +6 -0
- package/dist/operations.js +16 -0
- package/dist/platform/books-data.d.ts +1 -0
- package/dist/platform/books-data.js +1 -0
- package/dist/platform/contracts.d.ts +158 -0
- package/dist/platform/contracts.js +0 -0
- package/dist/platform/deploy/config.d.ts +4 -0
- package/dist/platform/deploy/config.js +222 -0
- package/dist/platform/deploy-config.d.ts +1 -0
- package/dist/platform/deploy-config.js +1 -0
- package/dist/platform/env.yaml +394 -0
- package/dist/platform/environment.d.ts +130 -0
- package/dist/platform/environment.js +331 -0
- package/dist/platform/plugin.d.ts +2 -0
- package/dist/platform/plugin.js +4 -0
- package/dist/platform/plugins/constants.d.ts +22 -0
- package/dist/platform/plugins/constants.js +29 -0
- package/dist/platform/plugins/plugin.d.ts +51 -0
- package/dist/platform/plugins/plugin.js +6 -0
- package/dist/platform/plugins/runtime.d.ts +35 -0
- package/dist/platform/plugins/runtime.js +142 -0
- package/dist/platform/plugins.d.ts +5 -0
- package/dist/platform/plugins.js +16 -0
- package/dist/platform/site-config-schema.js +1 -0
- package/dist/platform/tenant/config.d.ts +9 -0
- package/dist/platform/tenant/config.js +154 -0
- package/dist/platform/tenant/runtime-config.d.ts +4 -0
- package/dist/platform/tenant/runtime-config.js +20 -0
- package/dist/platform/tenant-config.d.ts +1 -0
- package/dist/platform/tenant-config.js +1 -0
- package/dist/platform/utils/books-data.d.ts +29 -0
- package/dist/platform/utils/books-data.js +82 -0
- package/dist/platform/utils/site-config-schema.js +321 -0
- package/dist/remote.d.ts +175 -0
- package/dist/remote.js +202 -0
- package/dist/runtime.js +50 -3
- package/dist/scripts/aggregate-book.js +121 -0
- package/dist/scripts/build-dist.js +57 -13
- package/dist/scripts/build-tenant-worker.js +36 -0
- package/dist/scripts/cleanup-markdown.js +373 -0
- package/dist/scripts/cli-test-fixtures.js +48 -0
- package/dist/scripts/config-treeseed.js +95 -0
- package/dist/scripts/ensure-mailpit.js +29 -0
- package/dist/scripts/local-dev.js +129 -0
- package/dist/scripts/logs-mailpit.js +2 -0
- package/dist/scripts/patch-starlight-content-path.js +172 -0
- package/dist/scripts/release-verify.js +34 -5
- package/dist/scripts/run-fixture-astro-command.js +18 -0
- package/dist/scripts/scaffold-site.js +65 -0
- package/dist/scripts/stop-mailpit.js +5 -0
- package/dist/scripts/sync-dev-vars.js +6 -0
- package/dist/scripts/sync-template.js +20 -0
- package/dist/scripts/template-catalog.test.js +100 -0
- package/dist/scripts/template-command.js +31 -0
- package/dist/scripts/tenant-astro-command.js +3 -0
- package/dist/scripts/tenant-build.js +16 -0
- package/dist/scripts/tenant-check.js +7 -0
- package/dist/scripts/tenant-d1-migrate-local.js +11 -0
- package/dist/scripts/tenant-deploy.js +180 -0
- package/dist/scripts/tenant-destroy.js +104 -0
- package/dist/scripts/tenant-dev.js +171 -0
- package/dist/scripts/tenant-lint.js +4 -0
- package/dist/scripts/tenant-test.js +4 -0
- package/dist/scripts/test-cloudflare-local.js +212 -0
- package/dist/scripts/test-scaffold.js +314 -0
- package/dist/scripts/test-smoke.js +71 -13
- package/dist/scripts/treeseed-assert-release-tag-version.js +21 -0
- package/dist/scripts/treeseed-build-dist.js +134 -0
- package/dist/scripts/treeseed-publish-package.js +19 -0
- package/dist/scripts/treeseed-release-verify.js +131 -0
- package/dist/scripts/treeseed-run-ts.js +45 -0
- package/dist/scripts/validate-templates.js +6 -0
- package/dist/scripts/verify-driver.js +29 -0
- package/dist/scripts/workflow-commands.test.js +39 -0
- package/dist/scripts/workspace-close.js +24 -0
- package/dist/scripts/workspace-command-e2e.js +718 -0
- package/dist/scripts/workspace-lint.js +9 -0
- package/dist/scripts/workspace-preflight.js +22 -0
- package/dist/scripts/workspace-publish-changed-packages.js +16 -0
- package/dist/scripts/workspace-release-verify.js +81 -0
- package/dist/scripts/workspace-release.js +42 -0
- package/dist/scripts/workspace-save.js +124 -0
- package/dist/scripts/workspace-start-warning.js +3 -0
- package/dist/scripts/workspace-start.js +71 -0
- package/dist/scripts/workspace-test-unit.js +4 -0
- package/dist/scripts/workspace-test.js +11 -0
- package/dist/sdk-fields.d.ts +11 -0
- package/dist/sdk-fields.js +169 -0
- package/dist/sdk-filters.d.ts +4 -0
- package/dist/sdk-filters.js +12 -15
- package/dist/sdk-types.d.ts +796 -0
- package/dist/sdk-types.js +7 -1
- package/dist/sdk-version.d.ts +2 -0
- package/dist/sdk-version.js +42 -0
- package/dist/sdk.d.ts +215 -0
- package/dist/sdk.js +235 -11
- package/dist/stores/cursor-store.js +9 -3
- package/dist/stores/lease-store.js +8 -2
- package/dist/{src/stores → stores}/message-store.d.ts +1 -1
- package/dist/stores/message-store.js +27 -3
- package/dist/stores/operational-store.d.ts +24 -0
- package/dist/stores/operational-store.js +279 -0
- package/dist/stores/run-store.js +8 -1
- package/dist/stores/subscription-store.js +7 -5
- package/dist/template-catalog.d.ts +13 -0
- package/dist/template-catalog.js +141 -0
- package/dist/treeseed/services/compose.yml +7 -0
- package/dist/treeseed/template-catalog/catalog.fixture.json +55 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/astro.config.d.ts +2 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/astro.config.ts +3 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/package.json +32 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/src/config.yaml +40 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/src/content/empty/.gitkeep +1 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/src/content/knowledge/handbook/index.mdx +11 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/src/content/pages/welcome.mdx +11 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/src/content.config.d.ts +1 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/src/content.config.ts +3 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/src/env.yaml +1 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/src/manifest.yaml +19 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/treeseed.site.yaml +26 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/tsconfig.json +9 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template.config.json +90 -0
- package/dist/verification.d.ts +20 -0
- package/dist/verification.js +98 -0
- package/dist/workflow/operations.d.ts +396 -0
- package/dist/workflow/operations.js +841 -0
- package/dist/workflow-state.d.ts +56 -0
- package/dist/workflow-state.js +195 -0
- package/dist/workflow-support.d.ts +9 -0
- package/dist/workflow-support.js +176 -0
- package/dist/workflow.d.ts +111 -0
- package/dist/workflow.js +97 -0
- package/package.json +97 -5
- package/scripts/verify-driver.mjs +29 -0
- package/dist/scripts/.ts-run-1775616845195-odh4xzphk3l.js +0 -22
- package/dist/scripts/.ts-run-1775616848931-9386s6kwrl.js +0 -126
- package/dist/scripts/assert-release-tag-version.d.ts +0 -1
- package/dist/scripts/build-dist.d.ts +0 -1
- package/dist/scripts/package-tools.d.ts +0 -15
- package/dist/scripts/publish-package.d.ts +0 -1
- package/dist/scripts/release-verify.d.ts +0 -1
- package/dist/scripts/test-smoke.d.ts +0 -1
- package/dist/src/index.d.ts +0 -6
- package/dist/src/model-registry.d.ts +0 -4
- package/dist/src/sdk-filters.d.ts +0 -4
- package/dist/src/sdk-types.d.ts +0 -285
- package/dist/src/sdk.d.ts +0 -109
- package/dist/test/test-fixture.d.ts +0 -1
- package/dist/test/utils/envelopes.test.d.ts +0 -1
- package/dist/test/utils/sdk.test.d.ts +0 -1
- package/dist/vitest.config.d.ts +0 -2
- /package/dist/{src/frontmatter.d.ts → frontmatter.d.ts} +0 -0
- /package/dist/{src/git-runtime.d.ts → git-runtime.d.ts} +0 -0
- /package/dist/{src/runtime.d.ts → runtime.d.ts} +0 -0
- /package/dist/{src/stores → stores}/cursor-store.d.ts +0 -0
- /package/dist/{src/stores → stores}/envelopes.d.ts +0 -0
- /package/dist/{src/stores → stores}/helpers.d.ts +0 -0
- /package/dist/{src/stores → stores}/lease-store.d.ts +0 -0
- /package/dist/{src/stores → stores}/run-store.d.ts +0 -0
- /package/dist/{src/stores → stores}/subscription-store.d.ts +0 -0
- /package/dist/{src/types → types}/agents.d.ts +0 -0
- /package/dist/{src/types → types}/cloudflare.d.ts +0 -0
- /package/dist/{src/wrangler-d1.d.ts → wrangler-d1.d.ts} +0 -0
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, relative, resolve, sep } from "node:path";
|
|
3
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
4
|
+
import { corePackageRoot, sdkPackageRoot } from "./runtime-tools.js";
|
|
5
|
+
const WATCH_INTERVAL_MS = 900;
|
|
6
|
+
const DEBOUNCE_MS = 350;
|
|
7
|
+
const DEV_RELOAD_FILE = "public/__treeseed/dev-reload.json";
|
|
8
|
+
const PROCESS_SHUTDOWN_TIMEOUT_MS = 5e3;
|
|
9
|
+
const WATCH_BUILD_ROOT = ".local/treeseed-watch";
|
|
10
|
+
const PROCESS_SETTLE_DELAY_MS = 300;
|
|
11
|
+
function isNodeModulesPath(filePath) {
|
|
12
|
+
return filePath.split(sep).includes("node_modules");
|
|
13
|
+
}
|
|
14
|
+
function isEditablePackageWorkspace() {
|
|
15
|
+
return !isNodeModulesPath(corePackageRoot);
|
|
16
|
+
}
|
|
17
|
+
function workspaceSdkRoot() {
|
|
18
|
+
return existsSync(resolve(sdkPackageRoot, "package.json")) ? sdkPackageRoot : null;
|
|
19
|
+
}
|
|
20
|
+
function writeDevReloadStamp(projectRoot) {
|
|
21
|
+
const outputPath = resolve(projectRoot, DEV_RELOAD_FILE);
|
|
22
|
+
mkdirSync(dirname(outputPath), { recursive: true });
|
|
23
|
+
writeFileSync(
|
|
24
|
+
outputPath,
|
|
25
|
+
`${JSON.stringify(
|
|
26
|
+
{
|
|
27
|
+
buildId: `${Date.now()}`,
|
|
28
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
29
|
+
},
|
|
30
|
+
null,
|
|
31
|
+
2
|
|
32
|
+
)}
|
|
33
|
+
`,
|
|
34
|
+
"utf8"
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
function shouldIgnoreWatchPath(filePath, rootPath) {
|
|
38
|
+
const rel = relative(rootPath, filePath);
|
|
39
|
+
if (!rel || rel.startsWith(`..${sep}`) || rel === "..") {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
const normalized = rel.split(sep).join("/");
|
|
43
|
+
return normalized === ".git" || normalized.startsWith(".git/") || normalized === "node_modules" || normalized.startsWith("node_modules/") || normalized === ".astro" || normalized.startsWith(".astro/") || normalized === ".wrangler" || normalized.startsWith(".wrangler/") || normalized === ".local" || normalized.startsWith(".local/") || normalized === ".treeseed" || normalized.startsWith(".treeseed/") || normalized === "dist" || normalized.startsWith("dist/") || normalized === "coverage" || normalized.startsWith("coverage/") || normalized === ".dev.vars" || normalized === "books" || normalized.startsWith("books/") || normalized === "__treeseed" || normalized.startsWith("__treeseed/") || normalized.startsWith("public/books/") || normalized.startsWith("public/__treeseed/");
|
|
44
|
+
}
|
|
45
|
+
function collectRootSnapshot(rootPath, snapshot) {
|
|
46
|
+
if (!existsSync(rootPath)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const rootStats = statSync(rootPath);
|
|
50
|
+
if (rootStats.isFile()) {
|
|
51
|
+
snapshot.set(rootPath, `${rootStats.mtimeMs}:${rootStats.size}`);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
for (const entry of readdirSync(rootPath, { withFileTypes: true })) {
|
|
55
|
+
const fullPath = resolve(rootPath, entry.name);
|
|
56
|
+
if (shouldIgnoreWatchPath(fullPath, rootPath)) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (entry.isDirectory()) {
|
|
60
|
+
collectDirectorySnapshot(fullPath, rootPath, snapshot);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const stats = statSync(fullPath);
|
|
64
|
+
snapshot.set(fullPath, `${stats.mtimeMs}:${stats.size}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function collectDirectorySnapshot(directoryPath, rootPath, snapshot) {
|
|
68
|
+
if (shouldIgnoreWatchPath(directoryPath, rootPath)) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
for (const entry of readdirSync(directoryPath, { withFileTypes: true })) {
|
|
72
|
+
const fullPath = resolve(directoryPath, entry.name);
|
|
73
|
+
if (shouldIgnoreWatchPath(fullPath, rootPath)) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (entry.isDirectory()) {
|
|
77
|
+
collectDirectorySnapshot(fullPath, rootPath, snapshot);
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const stats = statSync(fullPath);
|
|
81
|
+
snapshot.set(fullPath, `${stats.mtimeMs}:${stats.size}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function collectSnapshot(entries) {
|
|
85
|
+
const snapshot = /* @__PURE__ */ new Map();
|
|
86
|
+
for (const entry of entries) {
|
|
87
|
+
collectRootSnapshot(entry.root, snapshot);
|
|
88
|
+
}
|
|
89
|
+
return snapshot;
|
|
90
|
+
}
|
|
91
|
+
function diffSnapshots(previousSnapshot, nextSnapshot) {
|
|
92
|
+
const changed = /* @__PURE__ */ new Set();
|
|
93
|
+
for (const [filePath, signature] of nextSnapshot.entries()) {
|
|
94
|
+
if (previousSnapshot.get(filePath) !== signature) {
|
|
95
|
+
changed.add(filePath);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
for (const filePath of previousSnapshot.keys()) {
|
|
99
|
+
if (!nextSnapshot.has(filePath)) {
|
|
100
|
+
changed.add(filePath);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return [...changed];
|
|
104
|
+
}
|
|
105
|
+
function classifyChanges(changedPaths, watchEntries) {
|
|
106
|
+
function matchesEntry(filePath, entry) {
|
|
107
|
+
return filePath === entry.root || filePath.startsWith(`${entry.root}${sep}`);
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
changedPaths,
|
|
111
|
+
sdkChanged: changedPaths.some(
|
|
112
|
+
(filePath) => watchEntries.some((entry) => entry.kind === "sdk" && matchesEntry(filePath, entry))
|
|
113
|
+
),
|
|
114
|
+
packageChanged: changedPaths.some(
|
|
115
|
+
(filePath) => watchEntries.some((entry) => entry.kind === "package" && matchesEntry(filePath, entry))
|
|
116
|
+
),
|
|
117
|
+
tenantChanged: changedPaths.some(
|
|
118
|
+
(filePath) => watchEntries.some((entry) => entry.kind === "tenant" && matchesEntry(filePath, entry))
|
|
119
|
+
)
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function readDevReloadState(projectRoot) {
|
|
123
|
+
const filePath = resolve(projectRoot, DEV_RELOAD_FILE);
|
|
124
|
+
if (!existsSync(filePath)) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
return JSON.parse(readFileSync(filePath, "utf8"));
|
|
129
|
+
} catch {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function createTenantWatchEntries(tenantRoot) {
|
|
134
|
+
const entries = [
|
|
135
|
+
{ kind: "tenant", root: resolve(tenantRoot, "src") },
|
|
136
|
+
{ kind: "tenant", root: resolve(tenantRoot, "public") },
|
|
137
|
+
{ kind: "tenant", root: resolve(tenantRoot, "astro.config.ts") },
|
|
138
|
+
{ kind: "tenant", root: resolve(tenantRoot, "treeseed.site.yaml") },
|
|
139
|
+
{ kind: "tenant", root: resolve(tenantRoot, ".env.local") },
|
|
140
|
+
{ kind: "tenant", root: resolve(tenantRoot, ".env.local.example") }
|
|
141
|
+
];
|
|
142
|
+
if (isEditablePackageWorkspace()) {
|
|
143
|
+
const sdkRoot = workspaceSdkRoot();
|
|
144
|
+
entries.push(
|
|
145
|
+
{ kind: "package", root: resolve(corePackageRoot, "src") },
|
|
146
|
+
{ kind: "package", root: resolve(corePackageRoot, "scripts") },
|
|
147
|
+
{ kind: "package", root: resolve(corePackageRoot, "services") },
|
|
148
|
+
{ kind: "package", root: resolve(corePackageRoot, "tsconfigs") },
|
|
149
|
+
{ kind: "package", root: resolve(corePackageRoot, "package.json") }
|
|
150
|
+
);
|
|
151
|
+
if (sdkRoot) {
|
|
152
|
+
entries.push(
|
|
153
|
+
{ kind: "sdk", root: resolve(sdkRoot, "src") },
|
|
154
|
+
{ kind: "sdk", root: resolve(sdkRoot, "scripts") },
|
|
155
|
+
{ kind: "sdk", root: resolve(sdkRoot, "package.json") }
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return entries;
|
|
160
|
+
}
|
|
161
|
+
function startPollingWatch({ watchEntries, onChange }) {
|
|
162
|
+
let previousSnapshot = collectSnapshot(watchEntries);
|
|
163
|
+
let queuedPaths = [];
|
|
164
|
+
let debounceTimer = null;
|
|
165
|
+
let running = false;
|
|
166
|
+
let intervalId = null;
|
|
167
|
+
async function flush() {
|
|
168
|
+
if (running || queuedPaths.length === 0) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const changedPaths = [...new Set(queuedPaths)];
|
|
172
|
+
queuedPaths = [];
|
|
173
|
+
running = true;
|
|
174
|
+
try {
|
|
175
|
+
await onChange(classifyChanges(changedPaths, watchEntries));
|
|
176
|
+
} finally {
|
|
177
|
+
running = false;
|
|
178
|
+
if (queuedPaths.length > 0) {
|
|
179
|
+
debounceTimer = setTimeout(flush, DEBOUNCE_MS);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function queueChanges(changedPaths) {
|
|
184
|
+
if (changedPaths.length === 0) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
queuedPaths.push(...changedPaths);
|
|
188
|
+
if (debounceTimer) {
|
|
189
|
+
clearTimeout(debounceTimer);
|
|
190
|
+
}
|
|
191
|
+
debounceTimer = setTimeout(flush, DEBOUNCE_MS);
|
|
192
|
+
}
|
|
193
|
+
intervalId = setInterval(() => {
|
|
194
|
+
const nextSnapshot = collectSnapshot(watchEntries);
|
|
195
|
+
const changedPaths = diffSnapshots(previousSnapshot, nextSnapshot);
|
|
196
|
+
previousSnapshot = nextSnapshot;
|
|
197
|
+
queueChanges(changedPaths);
|
|
198
|
+
}, WATCH_INTERVAL_MS);
|
|
199
|
+
return () => {
|
|
200
|
+
if (debounceTimer) {
|
|
201
|
+
clearTimeout(debounceTimer);
|
|
202
|
+
}
|
|
203
|
+
if (intervalId) {
|
|
204
|
+
clearInterval(intervalId);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
async function stopManagedProcess(child, signal = "SIGTERM") {
|
|
209
|
+
if (!child || child.exitCode !== null || child.killed) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const groupSignalSupported = process.platform !== "win32" && child.pid && child.spawnargs;
|
|
213
|
+
let signaled = false;
|
|
214
|
+
if (groupSignalSupported) {
|
|
215
|
+
try {
|
|
216
|
+
process.kill(-child.pid, signal);
|
|
217
|
+
signaled = true;
|
|
218
|
+
} catch {
|
|
219
|
+
signaled = false;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (!signaled) {
|
|
223
|
+
child.kill(signal);
|
|
224
|
+
}
|
|
225
|
+
await Promise.race([
|
|
226
|
+
new Promise((resolve2) => child.once("exit", resolve2)),
|
|
227
|
+
delay(PROCESS_SHUTDOWN_TIMEOUT_MS)
|
|
228
|
+
]);
|
|
229
|
+
if (child.exitCode === null && !child.killed) {
|
|
230
|
+
if (groupSignalSupported) {
|
|
231
|
+
try {
|
|
232
|
+
process.kill(-child.pid, "SIGKILL");
|
|
233
|
+
} catch {
|
|
234
|
+
child.kill("SIGKILL");
|
|
235
|
+
}
|
|
236
|
+
} else {
|
|
237
|
+
child.kill("SIGKILL");
|
|
238
|
+
}
|
|
239
|
+
await Promise.race([
|
|
240
|
+
new Promise((resolve2) => child.once("exit", resolve2)),
|
|
241
|
+
delay(PROCESS_SHUTDOWN_TIMEOUT_MS)
|
|
242
|
+
]);
|
|
243
|
+
}
|
|
244
|
+
await delay(PROCESS_SETTLE_DELAY_MS);
|
|
245
|
+
}
|
|
246
|
+
function createWatchBuildPaths(projectRoot) {
|
|
247
|
+
const watchRoot = resolve(projectRoot, WATCH_BUILD_ROOT);
|
|
248
|
+
return {
|
|
249
|
+
watchRoot,
|
|
250
|
+
stagedDistRoot: resolve(watchRoot, "dist-next"),
|
|
251
|
+
backupDistRoot: resolve(watchRoot, "dist-prev"),
|
|
252
|
+
liveDistRoot: resolve(projectRoot, "dist")
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function swapStagedBuildOutput(projectRoot) {
|
|
256
|
+
const { watchRoot, stagedDistRoot, backupDistRoot, liveDistRoot } = createWatchBuildPaths(projectRoot);
|
|
257
|
+
mkdirSync(watchRoot, { recursive: true });
|
|
258
|
+
rmSync(backupDistRoot, { recursive: true, force: true });
|
|
259
|
+
if (existsSync(liveDistRoot)) {
|
|
260
|
+
try {
|
|
261
|
+
renameSync(liveDistRoot, backupDistRoot);
|
|
262
|
+
} catch {
|
|
263
|
+
rmSync(liveDistRoot, { recursive: true, force: true });
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
renameSync(stagedDistRoot, liveDistRoot);
|
|
267
|
+
rmSync(backupDistRoot, { recursive: true, force: true });
|
|
268
|
+
}
|
|
269
|
+
function clearStagedBuildOutput(projectRoot) {
|
|
270
|
+
const { stagedDistRoot } = createWatchBuildPaths(projectRoot);
|
|
271
|
+
rmSync(stagedDistRoot, { recursive: true, force: true });
|
|
272
|
+
}
|
|
273
|
+
export {
|
|
274
|
+
clearStagedBuildOutput,
|
|
275
|
+
createTenantWatchEntries,
|
|
276
|
+
createWatchBuildPaths,
|
|
277
|
+
isEditablePackageWorkspace,
|
|
278
|
+
readDevReloadState,
|
|
279
|
+
startPollingWatch,
|
|
280
|
+
stopManagedProcess,
|
|
281
|
+
swapStagedBuildOutput,
|
|
282
|
+
workspaceSdkRoot,
|
|
283
|
+
writeDevReloadStamp
|
|
284
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export declare function createWranglerCommandEnv(overrides?: {}): {
|
|
2
|
+
XDG_CONFIG_HOME: string;
|
|
3
|
+
WRANGLER_SEND_METRICS: string;
|
|
4
|
+
};
|
|
5
|
+
export declare function parseGitHubAuthStatus(): {
|
|
6
|
+
authenticated: boolean;
|
|
7
|
+
detail: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function parseWranglerWhoAmI(): {
|
|
10
|
+
authenticated: boolean;
|
|
11
|
+
detail: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function parseRailwayWhoAmI(): {
|
|
14
|
+
authenticated: boolean;
|
|
15
|
+
detail: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function parseCopilotSessionStatus(): {
|
|
18
|
+
configured: boolean;
|
|
19
|
+
detail: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function collectCliPreflight({ cwd, requireAuth }?: {
|
|
22
|
+
cwd?: string | undefined;
|
|
23
|
+
requireAuth?: boolean | undefined;
|
|
24
|
+
}): {
|
|
25
|
+
ok: boolean;
|
|
26
|
+
requireAuth: boolean;
|
|
27
|
+
missingCommands: string[];
|
|
28
|
+
failingAuth: string[];
|
|
29
|
+
checks: {
|
|
30
|
+
commands: {
|
|
31
|
+
[k: string]: {
|
|
32
|
+
installed: boolean;
|
|
33
|
+
path: string | null;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
auth: {};
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export declare function formatCliPreflightReport(report: any): string;
|
|
40
|
+
export declare function writeJsonArtifact(filePath: any, value: any): void;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { dirname, resolve } from "node:path";
|
|
4
|
+
import { createTempDir } from "./workspace-tools.js";
|
|
5
|
+
function runCapture(command, args, options = {}) {
|
|
6
|
+
const result = spawnSync(command, args, {
|
|
7
|
+
cwd: options.cwd ?? process.cwd(),
|
|
8
|
+
env: { ...process.env, ...options.env ?? {} },
|
|
9
|
+
stdio: "pipe",
|
|
10
|
+
encoding: "utf8",
|
|
11
|
+
timeout: options.timeoutMs
|
|
12
|
+
});
|
|
13
|
+
return {
|
|
14
|
+
status: result.status ?? 1,
|
|
15
|
+
signal: result.signal ?? null,
|
|
16
|
+
stdout: result.stdout ?? "",
|
|
17
|
+
stderr: result.stderr ?? "",
|
|
18
|
+
error: result.error?.message ?? null
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function locateBinary(candidate) {
|
|
22
|
+
const result = runCapture("bash", ["-lc", `command -v ${candidate}`]);
|
|
23
|
+
return result.status === 0 ? result.stdout.trim() : null;
|
|
24
|
+
}
|
|
25
|
+
function createWranglerCommandEnv(overrides = {}) {
|
|
26
|
+
const configHome = createTempDir("treeseed-wrangler-config-");
|
|
27
|
+
const logDir = resolve(configHome, ".wrangler", "logs");
|
|
28
|
+
mkdirSync(logDir, { recursive: true });
|
|
29
|
+
return {
|
|
30
|
+
XDG_CONFIG_HOME: configHome,
|
|
31
|
+
WRANGLER_SEND_METRICS: "false",
|
|
32
|
+
...overrides
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function envTokenStatus(keys, label) {
|
|
36
|
+
const foundKey = keys.find((key) => {
|
|
37
|
+
const value = process.env[key];
|
|
38
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
39
|
+
}) ?? null;
|
|
40
|
+
return {
|
|
41
|
+
ready: Boolean(foundKey),
|
|
42
|
+
detail: foundKey ? `${label} token detected from ${foundKey}.` : `${label} token is not configured. Set ${keys.join(" or ")}.`,
|
|
43
|
+
source: foundKey ? "env" : "missing"
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function parseGitHubAuthStatus() {
|
|
47
|
+
return {
|
|
48
|
+
authenticated: envTokenStatus(["GH_TOKEN"], "GitHub").ready,
|
|
49
|
+
detail: envTokenStatus(["GH_TOKEN"], "GitHub").detail
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function parseWranglerWhoAmI() {
|
|
53
|
+
return {
|
|
54
|
+
authenticated: envTokenStatus(["CLOUDFLARE_API_TOKEN"], "Cloudflare").ready,
|
|
55
|
+
detail: envTokenStatus(["CLOUDFLARE_API_TOKEN"], "Cloudflare").detail
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function parseRailwayWhoAmI() {
|
|
59
|
+
return {
|
|
60
|
+
authenticated: envTokenStatus(["RAILWAY_API_TOKEN"], "Railway").ready,
|
|
61
|
+
detail: envTokenStatus(["RAILWAY_API_TOKEN"], "Railway").detail
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function parseCopilotSessionStatus() {
|
|
65
|
+
const status = envTokenStatus(["GH_TOKEN"], "GitHub");
|
|
66
|
+
return {
|
|
67
|
+
configured: status.ready,
|
|
68
|
+
detail: status.ready ? "GitHub token detected from GH_TOKEN for Copilot-backed workflows." : "GitHub token is not configured. Set GH_TOKEN for Copilot-backed workflows."
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function collectCliPreflight({ cwd = process.cwd(), requireAuth = false } = {}) {
|
|
72
|
+
const binaries = {
|
|
73
|
+
git: locateBinary("git"),
|
|
74
|
+
npm: locateBinary("npm"),
|
|
75
|
+
gh: locateBinary("gh"),
|
|
76
|
+
wrangler: locateBinary("wrangler"),
|
|
77
|
+
railway: locateBinary("railway"),
|
|
78
|
+
copilot: locateBinary("copilot")
|
|
79
|
+
};
|
|
80
|
+
const checks = {
|
|
81
|
+
commands: Object.fromEntries(
|
|
82
|
+
Object.entries(binaries).map(([name, path]) => [name, {
|
|
83
|
+
installed: Boolean(path),
|
|
84
|
+
path
|
|
85
|
+
}])
|
|
86
|
+
),
|
|
87
|
+
auth: {}
|
|
88
|
+
};
|
|
89
|
+
if (binaries.gh) {
|
|
90
|
+
checks.auth.gh = parseGitHubAuthStatus();
|
|
91
|
+
} else {
|
|
92
|
+
checks.auth.gh = { authenticated: false, detail: "GitHub CLI is not installed." };
|
|
93
|
+
}
|
|
94
|
+
if (binaries.wrangler) {
|
|
95
|
+
checks.auth.wrangler = parseWranglerWhoAmI();
|
|
96
|
+
} else {
|
|
97
|
+
checks.auth.wrangler = { authenticated: false, detail: "Wrangler CLI is not installed." };
|
|
98
|
+
}
|
|
99
|
+
if (binaries.railway) {
|
|
100
|
+
checks.auth.railway = parseRailwayWhoAmI();
|
|
101
|
+
} else {
|
|
102
|
+
checks.auth.railway = { authenticated: false, detail: "Railway CLI is not installed." };
|
|
103
|
+
}
|
|
104
|
+
if (binaries.copilot) {
|
|
105
|
+
checks.auth.copilot = parseCopilotSessionStatus();
|
|
106
|
+
} else {
|
|
107
|
+
checks.auth.copilot = { configured: false, detail: "Copilot CLI is not installed." };
|
|
108
|
+
}
|
|
109
|
+
const missingCommands = Object.entries(checks.commands).filter(([, value]) => !value.installed).map(([name]) => name);
|
|
110
|
+
const failingAuth = [];
|
|
111
|
+
if (requireAuth) {
|
|
112
|
+
if (!checks.auth.gh?.authenticated) failingAuth.push("gh");
|
|
113
|
+
if (!checks.auth.wrangler?.authenticated) failingAuth.push("wrangler");
|
|
114
|
+
if (!checks.auth.railway?.authenticated) failingAuth.push("railway");
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
ok: missingCommands.length === 0 && failingAuth.length === 0,
|
|
118
|
+
requireAuth,
|
|
119
|
+
missingCommands,
|
|
120
|
+
failingAuth,
|
|
121
|
+
checks
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function formatCliPreflightReport(report) {
|
|
125
|
+
const lines = [
|
|
126
|
+
"Treeseed preflight summary",
|
|
127
|
+
`Status: ${report.ok ? "ok" : "failed"}`,
|
|
128
|
+
`Require auth: ${report.requireAuth ? "yes" : "no"}`,
|
|
129
|
+
"Commands:"
|
|
130
|
+
];
|
|
131
|
+
for (const [name, info] of Object.entries(report.checks.commands)) {
|
|
132
|
+
lines.push(`- ${name}: ${info.installed ? `installed (${info.path})` : "missing"}`);
|
|
133
|
+
}
|
|
134
|
+
lines.push("Auth/session:");
|
|
135
|
+
lines.push(`- gh: ${report.checks.auth.gh?.authenticated ? "authenticated" : "not authenticated"}`);
|
|
136
|
+
lines.push(` ${report.checks.auth.gh?.detail ?? ""}`.trimEnd());
|
|
137
|
+
lines.push(`- wrangler: ${report.checks.auth.wrangler?.authenticated ? "authenticated" : "not authenticated"}`);
|
|
138
|
+
lines.push(` ${report.checks.auth.wrangler?.detail ?? ""}`.trimEnd());
|
|
139
|
+
lines.push(`- railway: ${report.checks.auth.railway?.authenticated ? "authenticated" : "not authenticated"}`);
|
|
140
|
+
lines.push(` ${report.checks.auth.railway?.detail ?? ""}`.trimEnd());
|
|
141
|
+
lines.push(`- copilot: ${report.checks.auth.copilot?.configured ? "configured" : "not configured"}`);
|
|
142
|
+
lines.push(` ${report.checks.auth.copilot?.detail ?? ""}`.trimEnd());
|
|
143
|
+
if (report.missingCommands.length > 0) {
|
|
144
|
+
lines.push(`Missing commands: ${report.missingCommands.join(", ")}`);
|
|
145
|
+
}
|
|
146
|
+
if (report.failingAuth.length > 0) {
|
|
147
|
+
lines.push(`Auth failures: ${report.failingAuth.join(", ")}`);
|
|
148
|
+
}
|
|
149
|
+
return lines.filter(Boolean).join("\n");
|
|
150
|
+
}
|
|
151
|
+
function writeJsonArtifact(filePath, value) {
|
|
152
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
153
|
+
writeFileSync(filePath, `${JSON.stringify(value, null, 2)}
|
|
154
|
+
`, "utf8");
|
|
155
|
+
}
|
|
156
|
+
export {
|
|
157
|
+
collectCliPreflight,
|
|
158
|
+
createWranglerCommandEnv,
|
|
159
|
+
formatCliPreflightReport,
|
|
160
|
+
parseCopilotSessionStatus,
|
|
161
|
+
parseGitHubAuthStatus,
|
|
162
|
+
parseRailwayWhoAmI,
|
|
163
|
+
parseWranglerWhoAmI,
|
|
164
|
+
writeJsonArtifact
|
|
165
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export declare const MERGE_CONFLICT_EXIT_CODE = 12;
|
|
2
|
+
export declare function incrementPatchVersion(version: any): string;
|
|
3
|
+
export declare function incrementVersion(version: any, level?: string): string;
|
|
4
|
+
export declare function planWorkspaceVersionChanges(root?: any): {
|
|
5
|
+
packages: any[];
|
|
6
|
+
publishable: Set<any>;
|
|
7
|
+
bumped: Set<any>;
|
|
8
|
+
touched: Set<unknown>;
|
|
9
|
+
};
|
|
10
|
+
export declare function applyWorkspaceVersionChanges(plan: any): any;
|
|
11
|
+
export declare function planWorkspaceReleaseBump(level?: string, root?: any): {
|
|
12
|
+
packages: any[];
|
|
13
|
+
touched: Set<unknown>;
|
|
14
|
+
versions: Map<any, any>;
|
|
15
|
+
level: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function repoRoot(cwd?: any): string;
|
|
18
|
+
export declare function currentBranch(repoDir: any): string;
|
|
19
|
+
export declare function originRemoteUrl(repoDir: any): string;
|
|
20
|
+
export declare function gitStatusPorcelain(repoDir: any): string;
|
|
21
|
+
export declare function hasMeaningfulChanges(repoDir: any): boolean;
|
|
22
|
+
export declare function countConflictMarkers(source: any): {
|
|
23
|
+
start: any;
|
|
24
|
+
middle: any;
|
|
25
|
+
end: any;
|
|
26
|
+
};
|
|
27
|
+
export declare function collectMergeConflictReport(repoDir: any): {
|
|
28
|
+
branch: string;
|
|
29
|
+
rebaseInProgress: boolean;
|
|
30
|
+
conflictedFiles: string[];
|
|
31
|
+
status: string;
|
|
32
|
+
perFile: {
|
|
33
|
+
filePath: string;
|
|
34
|
+
markers: {
|
|
35
|
+
start: any;
|
|
36
|
+
middle: any;
|
|
37
|
+
end: any;
|
|
38
|
+
};
|
|
39
|
+
diff: string;
|
|
40
|
+
}[];
|
|
41
|
+
};
|
|
42
|
+
export declare function formatMergeConflictReport(report: any, repoDir: any, targetBranch?: string): string;
|