@treeseed/cli 0.6.44 → 0.6.46

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.
@@ -3,6 +3,8 @@ import {
3
3
  resolveTreeseedLaunchEnvironment,
4
4
  resolveTreeseedToolCommand
5
5
  } from "@treeseed/sdk/workflow-support";
6
+ import { existsSync, readFileSync } from "node:fs";
7
+ import { join } from "node:path";
6
8
  import { workflowErrorResult } from "./workflow.js";
7
9
  const WRAPPED_TOOLS = /* @__PURE__ */ new Set(["gh", "railway", "wrangler"]);
8
10
  const ENVIRONMENT_SCOPES = /* @__PURE__ */ new Set(["local", "staging", "prod"]);
@@ -21,6 +23,49 @@ function wrapperScope(value) {
21
23
  function railwayEnvironmentName(scope) {
22
24
  return scope === "prod" ? "production" : scope;
23
25
  }
26
+ function findRailwayProjectId(value) {
27
+ if (!value || typeof value !== "object") {
28
+ return null;
29
+ }
30
+ if (Array.isArray(value)) {
31
+ for (const entry of value) {
32
+ const found = findRailwayProjectId(entry);
33
+ if (found) {
34
+ return found;
35
+ }
36
+ }
37
+ return null;
38
+ }
39
+ const record = value;
40
+ if (typeof record.projectId === "string" && /^[0-9a-f]{8}-[0-9a-f-]{27,}$/iu.test(record.projectId.trim())) {
41
+ return record.projectId.trim();
42
+ }
43
+ if (typeof record.lastDeploymentCommand === "string") {
44
+ const match = record.lastDeploymentCommand.match(/--project\s+([0-9a-f]{8}-[0-9a-f-]{27,})/iu);
45
+ if (match?.[1]) {
46
+ return match[1];
47
+ }
48
+ }
49
+ for (const entry of Object.values(record)) {
50
+ const found = findRailwayProjectId(entry);
51
+ if (found) {
52
+ return found;
53
+ }
54
+ }
55
+ return null;
56
+ }
57
+ function railwayProjectIdFromDeployState(cwd, scope) {
58
+ const stateScope = scope === "prod" ? "prod" : scope;
59
+ const statePath = join(cwd, ".treeseed", "state", "environments", stateScope, "deploy.json");
60
+ if (!existsSync(statePath)) {
61
+ return null;
62
+ }
63
+ try {
64
+ return findRailwayProjectId(JSON.parse(readFileSync(statePath, "utf8")));
65
+ } catch {
66
+ return null;
67
+ }
68
+ }
24
69
  const handleToolWrapper = (invocation, context) => {
25
70
  try {
26
71
  const toolName = wrappedToolName(invocation.commandName);
@@ -53,11 +98,28 @@ const handleToolWrapper = (invocation, context) => {
53
98
  };
54
99
  }
55
100
  const targetArgs = invocation.positionals;
56
- if (toolName === "railway" && scope !== "local") {
101
+ if (toolName === "railway" && scope !== "local" && targetArgs[0] !== "link") {
102
+ const environmentName = railwayEnvironmentName(scope);
103
+ const projectId = managedEnv.TREESEED_RAILWAY_PROJECT_ID || railwayProjectIdFromDeployState(context.cwd, scope);
104
+ if (projectId) {
105
+ context.spawn(resolved.command, [
106
+ ...resolved.argsPrefix,
107
+ "link",
108
+ "--project",
109
+ projectId,
110
+ "--environment",
111
+ environmentName,
112
+ "--json"
113
+ ], {
114
+ cwd: context.cwd,
115
+ env: managedEnv,
116
+ stdio: "pipe"
117
+ });
118
+ }
57
119
  const environmentResult = context.spawn(resolved.command, [
58
120
  ...resolved.argsPrefix,
59
121
  "environment",
60
- railwayEnvironmentName(scope),
122
+ environmentName,
61
123
  "--json"
62
124
  ], {
63
125
  cwd: context.cwd,
@@ -77,7 +139,7 @@ const handleToolWrapper = (invocation, context) => {
77
139
  argsPrefix: resolved.argsPrefix,
78
140
  args: targetArgs,
79
141
  environmentSelection: {
80
- environment: railwayEnvironmentName(scope),
142
+ environment: environmentName,
81
143
  status: environmentResult.status ?? 1
82
144
  }
83
145
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@treeseed/cli",
3
- "version": "0.6.44",
3
+ "version": "0.6.46",
4
4
  "description": "Operator-facing Treeseed CLI package.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": {
@@ -45,7 +45,7 @@
45
45
  "release:publish": "node ./scripts/run-ts.mjs ./scripts/publish-package.ts"
46
46
  },
47
47
  "dependencies": {
48
- "@treeseed/sdk": "0.6.48",
48
+ "@treeseed/sdk": "0.6.50",
49
49
  "ink": "^7.0.0",
50
50
  "react": "^19.2.5"
51
51
  },