rainskills 0.1.19 → 0.1.21

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 (40) hide show
  1. package/README.md +34 -39
  2. package/SKILL.md +12 -10
  3. package/bin/rainskills-tools.js +114 -240
  4. package/bin/rainskills.js +134 -591
  5. package/install.sh +68 -94
  6. package/marketplace/rainskills/.claude-plugin/plugin.json +1 -1
  7. package/marketplace/rainskills/.codex-plugin/plugin.json +1 -1
  8. package/marketplace/rainskills/skills/rainskills/SKILL.md +13 -11
  9. package/package.json +2 -2
  10. package/rainbond-app-assistant/SKILL.md +116 -151
  11. package/rainbond-app-version-assistant/SKILL.md +98 -98
  12. package/rainbond-delivery-verifier/SKILL.md +98 -68
  13. package/rainbond-env-sync/SKILL.md +98 -69
  14. package/rainbond-fullstack-bootstrap/SKILL.md +101 -89
  15. package/rainbond-fullstack-bootstrap/modules/10-context-loading.md +1 -1
  16. package/rainbond-fullstack-troubleshooter/SKILL.md +98 -68
  17. package/rainbond-opensource-app-deploy/SKILL.md +102 -81
  18. package/rainbond-platform-installer/SKILL.md +4 -4
  19. package/rainbond-platform-installer/scripts/auto-update.js +0 -9
  20. package/rainbond-platform-installer/scripts/installed-version.js +1 -1
  21. package/rainbond-platform-installer/scripts/platform-installer.js +3 -89
  22. package/rainbond-platform-installer/scripts/runtime-state.js +14 -251
  23. package/rainbond-platform-installer/scripts/single-runtime.js +114 -0
  24. package/rainbond-platform-installer/scripts/user-message.js +3 -49
  25. package/rainbond-platform-installer/scripts/windows-client-config.js +0 -51
  26. package/rainbond-platform-installer/scripts/windows-onboarding.js +0 -3
  27. package/rainbond-platform-installer/scripts/windows-platform.ps1 +1 -1
  28. package/rainbond-platform-query/SKILL.md +103 -61
  29. package/rainbond-project-init/SKILL.md +102 -79
  30. package/rainbond-template-installer/SKILL.md +102 -80
  31. package/rainbond-platform-installer/scripts/environment-credentials.js +0 -225
  32. package/rainbond-platform-installer/scripts/environment-registry.js +0 -349
  33. package/rainbond-platform-installer/scripts/local-runtime-commands.js +0 -180
  34. package/rainbond-platform-installer/scripts/local-runtime.js +0 -58
  35. package/rainbond-platform-installer/scripts/runtime-context-resolver.js +0 -189
  36. package/rainbond-platform-installer/scripts/runtime-credentials.js +0 -163
  37. package/rainbond-platform-installer/scripts/runtime-intents.js +0 -386
  38. package/rainbond-platform-installer/scripts/runtime-operations.js +0 -597
  39. package/rainbond-platform-installer/scripts/windows-client-config.ps1 +0 -9
  40. package/rainbond-platform-installer/scripts/windows-read-user-environment.ps1 +0 -16
@@ -6,96 +6,124 @@ description: "Use when the user explicitly asks to install a local or cloud Rain
6
6
  # Rainbond Template Installer
7
7
 
8
8
  <!-- rainskills-runtime-gate:start -->
9
- ## 运行环境门禁(最高优先级)
9
+ ## 单运行环境 CLI 门禁(最高优先级)
10
10
 
11
- ### CLI 调用格式(强制)
11
+ 本机只允许连接一个 Rainbond 运行环境。当前 Skill 在本会话第一次调用 Rainbond 前,执行固定 launcher 的 `runtime status --json`。返回 `connected` 且 `usable=true` 后,所有查询和变更直接通过本地 `~/.rainbond/bin/rainskills-tools.js` 执行。不得配置或直接调用客户端 MCP,不得执行环境枚举或业务 operation 生命周期命令,也不得生成或传递运行环境 ID、业务 operation ID 或 intent JSON。
12
12
 
13
- 所有可变 `call` 都必须使用完整 argv:`call <tool> --input - --operation-id <uuid> --skill-id rainbond-template-installer`。CLI 返回确认 ID 后,只能在同一 argv 末尾加入 `--confirm <confirmation-id>`;不得省略 `--skill-id`、猜测参数,或根据泛化错误反复重试。
13
+ 没有运行环境时,让用户选择 Rainbond Cloud 或一个已有/新建的私有 Rainbond,并执行对应的 `runtime connect`。连接和重新授权必须进入浏览器 Device Flow,不复用 Shell 中缓存的 JWT;新凭据通过 live probe 后才覆盖唯一运行环境。CLI 返回 401 时,只读调用可在 `runtime reconnect` 成功后重试一次;写调用不得自动重放,必须先查询平台真实状态。403 直接停止,不重新授权。
14
14
 
15
- ### 多运行环境操作契约
15
+ `context resolve` 是无状态调用:单一工作空间直接返回上下文,多个候选返回组合选项;用户选择后由当前任务直接携带 team/region 参数,不执行 `context select`,不写本地 operation。所有可变 `call` 仍需先取得 confirmation ID,再以完全相同的输入追加 `--confirm` 执行一次。
16
16
 
17
- Node.js 前置检查通过后,每次请求先执行本地 launcher + `["environment", "list", "--json"]`,按用户明确指定的运行环境选择不可变环境 ID;未指定时只用全局默认环境,默认不可用时停止且不回退。生成 UUID 后执行本地 launcher + `["operation", "begin", "--operation-id", "<uuid>", "--environment-id", "<id>", "--intent-json", "<intent-json>"]`,并在之后每个 Rainbond MCP 调用中加入 `rainskills_operation_id`。环境、团队和应用只属于本次操作,禁止保存项目绑定;同一项目可以部署到多个环境。明确“团队”表示环境内团队;明确“运行环境/平台”表示环境;裸名称同时匹配环境和团队时必须询问。
18
-
19
- 第一步检查 Node.js 是否存在且主版本不低于 18。Node.js 缺失或低于 18 时,只说明“Rainskills 执行组件需要 Node.js 18 或更高版本”并停止:不选择运行环境,不调用 MCP,不猜测替代命令。只有用户或 agent 明确同意后才安装或升级 Node.js,再从同一原始 intent 继续。
20
-
21
- 固定 launcher 是 `["node", "<home>/.rainbond/lib/rainskills/bin/rainskills.js"]`;运行包版本标记为 `rainskills@0.1.19`,且必须与本技能包 `package.json` 一致。把 launcher 与参数拼成 argv 数组直接执行,禁止 `rainskills@latest` 或执行 shell 字符串。
22
-
23
- 本地 launcher 必须从当前 Skill 所在目录的同级目录定位 `rainbond-platform-installer/scripts/local-runtime.js`,解析为绝对路径后使用 `["node", "<绝对路径>"]` 执行。`environment list`、`operation begin`、`operation complete` 和 `runtime message` 只能使用本地 launcher;本地 launcher 只读取已安装文件和本机受保护状态,不得访问 npm 或其它网络。只有用户选定连接或安装运行环境后,才使用上面的固定本地 launcher。
24
-
25
- 所有 Rainbond 查询和变更必须通过本地 `~/.rainbond/bin/rainskills-tools.js` 执行,并绑定本次 operation ID。禁止 Agent 直接调用 Rainbond MCP,也不得启动本地 Rainskills MCP 服务;只允许执行 CLI 返回的结构化结果与确认续接 argv。
26
-
27
- 业务操作开始后,必须使用 runtime contract 的 `input_commands.context-resolve` 完整 argv 和配套 stdin。返回 `resolved` 时只使用该 operation 已保存的企业、工作空间和集群上下文;返回 `needs-selection` 时,把 CLI 返回的“工作空间 + 集群”组合选项一次性列给用户,不得逐项询问,也不得让用户提供 enterprise_id。用户选择后必须使用 `input_commands.context-select` 的完整 argv 和配套 stdin;选择成功后继续原操作,同一 operation 不再重复查询上下文。
28
-
29
- 只有 CLI 返回并通过校验的 `rainskills.next-action.v1` argv 才能执行续接。普通失败一律禁止自动重试:不得再次执行原命令,不得执行 `--help`、`sleep`、`rg`、`grep`,不得搜索 Rainskills 源码;同一 `operation complete` 最多执行一次。
30
-
31
- <!-- rainskills-runtime-contract:start -->
32
17
  ```json
33
18
  {
34
- "schema": "rainskills.skill-runtime-contract.v1",
35
- "package_version": "rainskills@0.1.19",
36
- "launcher": ["node", "<home>/.rainbond/lib/rainskills/bin/rainskills.js"],
37
- "local_launcher": ["node", "<installed-skills-root>/rainbond-platform-installer/scripts/local-runtime.js"],
38
- "local_argv": {
39
- "environment-list": ["node", "<installed-skills-root>/rainbond-platform-installer/scripts/local-runtime.js", "environment", "list", "--json"],
40
- "operation-begin-default": ["node", "<installed-skills-root>/rainbond-platform-installer/scripts/local-runtime.js", "operation", "begin", "--operation-id", "<uuid>", "--intent-json", "<intent-json>"],
41
- "operation-begin-selected": ["node", "<installed-skills-root>/rainbond-platform-installer/scripts/local-runtime.js", "operation", "begin", "--operation-id", "<uuid>", "--environment-id", "<environment-id>", "--intent-json", "<intent-json>"],
42
- "operation-complete": ["node", "<installed-skills-root>/rainbond-platform-installer/scripts/local-runtime.js", "operation", "complete", "--operation-id", "<uuid>"],
43
- "runtime-message": ["node", "<installed-skills-root>/rainbond-platform-installer/scripts/local-runtime.js", "runtime", "message", "--id", "<message-id>"]
44
- },
45
- "intents": {
46
- "template-install": {
47
- "type": "template-install",
48
- "required": ["type", "template_id", "install_scope"],
49
- "optional": ["team_id", "app_id"],
50
- "enums": {
51
- "install_scope": ["new-app", "existing-app"]
52
- },
53
- "example": {
54
- "type": "template-install",
55
- "template_id": "template",
56
- "install_scope": "new-app"
57
- }
58
- }
59
- },
60
- "routes": {
61
- "new": ["saas", "private-existing", "install-private"],
62
- "existing": ["saas", "private-existing"]
63
- },
64
- "connect_argv": {
65
- "saas": ["node", "<home>/.rainbond/lib/rainskills/bin/rainskills.js", "runtime", "connect", "<target>", "--saas", "--intent-json", "<intent-json>"],
66
- "private-existing": ["node", "<home>/.rainbond/lib/rainskills/bin/rainskills.js", "runtime", "connect", "<target>", "--rainbond-url", "<rainbond-url>", "--intent-json", "<intent-json>"],
67
- "install-private": ["node", "<home>/.rainbond/lib/rainskills/bin/rainskills.js", "runtime", "connect", "<target>", "--install-private", "--location", "<private-location>", "--intent-json", "<intent-json>"]
19
+ "schema": "rainskills.single-runtime-contract.v1",
20
+ "package_version": "rainskills@0.1.21",
21
+ "runtime_status": [
22
+ "node",
23
+ "<home>/.rainbond/lib/rainskills/bin/rainskills.js",
24
+ "runtime",
25
+ "status",
26
+ "--json"
27
+ ],
28
+ "runtime_connect": {
29
+ "saas": [
30
+ "node",
31
+ "<home>/.rainbond/lib/rainskills/bin/rainskills.js",
32
+ "runtime",
33
+ "connect",
34
+ "<target>",
35
+ "--saas"
36
+ ],
37
+ "private_existing": [
38
+ "node",
39
+ "<home>/.rainbond/lib/rainskills/bin/rainskills.js",
40
+ "runtime",
41
+ "connect",
42
+ "<target>",
43
+ "--rainbond-url",
44
+ "<console-origin>"
45
+ ],
46
+ "install_private": [
47
+ "node",
48
+ "<home>/.rainbond/lib/rainskills/bin/rainskills.js",
49
+ "runtime",
50
+ "connect",
51
+ "<target>",
52
+ "--install-private",
53
+ "--location",
54
+ "<local-or-server>"
55
+ ],
56
+ "reconnect": [
57
+ "node",
58
+ "<home>/.rainbond/lib/rainskills/bin/rainskills.js",
59
+ "runtime",
60
+ "reconnect",
61
+ "<target>"
62
+ ]
68
63
  },
69
64
  "input_commands": {
70
- "context-resolve": {
71
- "argv": ["node", "<home>/.rainbond/bin/rainskills-tools.js", "context", "resolve", "--input", "-", "--operation-id", "<uuid>", "--skill-id", "rainbond-template-installer"],
65
+ "context_resolve": {
66
+ "argv": [
67
+ "node",
68
+ "<home>/.rainbond/bin/rainskills-tools.js",
69
+ "context",
70
+ "resolve",
71
+ "--input",
72
+ "-",
73
+ "--skill-id",
74
+ "rainbond-template-installer"
75
+ ],
72
76
  "stdin": {
73
- "required": ["enterprise", "workspace"]
74
- }
75
- },
76
- "context-select": {
77
- "argv": ["node", "<home>/.rainbond/bin/rainskills-tools.js", "context", "select", "--input", "-", "--operation-id", "<uuid>", "--skill-id", "rainbond-template-installer"],
78
- "stdin": {
79
- "selection_id": "<selection-id>",
80
- "option_id": "<option-id>"
77
+ "required": [
78
+ "enterprise",
79
+ "workspace"
80
+ ]
81
81
  }
82
82
  },
83
83
  "read": {
84
- "argv": ["node", "<home>/.rainbond/bin/rainskills-tools.js", "read", "<tool>", "--input", "-", "--operation-id", "<uuid>", "--skill-id", "rainbond-template-installer"],
84
+ "argv": [
85
+ "node",
86
+ "<home>/.rainbond/bin/rainskills-tools.js",
87
+ "read",
88
+ "<tool>",
89
+ "--input",
90
+ "-",
91
+ "--skill-id",
92
+ "rainbond-template-installer"
93
+ ],
85
94
  "stdin_schema_source": "tool-catalog"
86
95
  },
87
96
  "call": {
88
- "argv": ["node", "<home>/.rainbond/bin/rainskills-tools.js", "call", "<tool>", "--input", "-", "--operation-id", "<uuid>", "--skill-id", "rainbond-template-installer"],
97
+ "argv": [
98
+ "node",
99
+ "<home>/.rainbond/bin/rainskills-tools.js",
100
+ "call",
101
+ "<tool>",
102
+ "--input",
103
+ "-",
104
+ "--skill-id",
105
+ "rainbond-template-installer"
106
+ ],
89
107
  "stdin_schema_source": "tool-catalog"
108
+ },
109
+ "call_confirm": {
110
+ "argv": [
111
+ "node",
112
+ "<home>/.rainbond/bin/rainskills-tools.js",
113
+ "call",
114
+ "<tool>",
115
+ "--input",
116
+ "-",
117
+ "--skill-id",
118
+ "rainbond-template-installer",
119
+ "--confirm",
120
+ "<confirmation-id>"
121
+ ],
122
+ "stdin_schema_source": "same-confirmed-input"
90
123
  }
91
124
  }
92
125
  }
93
126
  ```
94
- <!-- rainskills-runtime-contract:end -->
95
-
96
- `install_scope=new-app` 使用 new route,`install_scope=existing-app` 使用 existing route;existing 路径绝不执行 `install-private`。target 只允许 `codex`、`claude`、`pi`、`all`。校验 intent 后只执行对应 scope 的完整 argv;只消费 schema 为 `rainskills.next-action.v1` 且校验后的 `argv` 数组。
97
-
98
- 连接完成后用固定 `onboarding-id` 执行 launcher + `["intent", "resume", "--onboarding-id", "<同一 onboarding-id>"]`,恢复原始 intent 和 `resume_step`。401 先执行 launcher + `["runtime", "record-failure", "--onboarding-id", "<同一 onboarding-id>", "--step", "<当前固定步骤>", "--reason", "credential-expired"]`,再仅一次执行 launcher + `["runtime", "reconnect", "--onboarding-id", "<同一 onboarding-id>"]` 后 resume,只重试该步骤;第二次 401 停止。403 执行 launcher + `["runtime", "record-failure", "--onboarding-id", "<同一 onboarding-id>", "--step", "<当前固定步骤>", "--reason", "permission-denied"]` 后停止,不得 reconnect、重新授权或自动重试。
99
127
  <!-- rainskills-runtime-gate:end -->
100
128
 
101
129
  受限沙箱(包括 Codex)执行本地状态命令时,必须申请用户级受保护目录访问权限;在 Codex 中使用 `require_escalated`。不得修改 `~/.rainbond` 权限、复制受保护状态到工作区,或因沙箱权限错误建议重装。
@@ -118,17 +146,11 @@ description: "Use when the user explicitly asks to install a local or cloud Rain
118
146
  请提示“请选择应用要运行的环境:”,并只显示:
119
147
 
120
148
  1) 云端环境(免费体验)
121
- 2) 私有环境(去对接)
122
-
123
- 用户选择私有环境后,立即执行本地 launcher + `["runtime", "message", "--id", "private-deployment-location"]`,并原样输出固定消息:
124
-
125
- 请选择部署位置:
126
-
127
- 1、部署到本机
128
- 2、部署到独立服务器
129
- 3、部署到已有 Rainbond
149
+ 2) 本机环境
150
+ 3) 独立服务器
151
+ 4) 已有 Rainbond
130
152
 
131
- 选择 1 时执行 `install-private` route,并使用 `["--location", "local"]`;选择 2 时执行 `install-private` route,并使用 `["--location", "server"]`;选择 3 时执行本地 launcher + `["runtime", "message", "--id", "private-console-origin"]`,收到地址后执行 `private-existing`。不得显示额外的接入方式中间步骤,不得重复询问部署位置,也不得在环境准备完成前询问应用来源。
153
+ 选择 1 时执行 `saas` route;选择 2 时执行 `install-private` route,并使用 `["--location", "local"]`;选择 3 时执行 `install-private` route,并使用 `["--location", "server"]`;选择 4 时执行本地 launcher + `["runtime", "message", "--id", "private-console-origin"]`,收到地址后执行 `private-existing`。不得显示“私有环境”或部署位置中间层,不得重复询问部署位置,也不得在环境准备完成前询问应用来源。
132
154
 
133
155
  ### 已有应用
134
156
 
@@ -1,225 +0,0 @@
1
- "use strict";
2
-
3
- const fs = require("node:fs");
4
- const os = require("node:os");
5
- const path = require("node:path");
6
-
7
- const { normalizeConsoleOrigin } = require("./console-origin.js");
8
- const { createSecureStateStore } = require("./secure-state.js");
9
- const { looksLikeJwt } = require("./windows-auth.js");
10
-
11
- const CREDENTIAL_SCHEMA = "rainskills.environment-credential.v1";
12
- const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
13
- const CREDENTIAL_FIELDS = new Set([
14
- "schema", "version", "environment_id", "origin", "token",
15
- ]);
16
- const MAX_CREDENTIAL_BYTES = 16384;
17
-
18
- function assertEnvironmentId(environmentId) {
19
- if (!UUID_PATTERN.test(environmentId || "")) throw new Error("环境 ID 无效");
20
- return environmentId;
21
- }
22
-
23
- function validateCredential(input, expected = {}) {
24
- if (!input || typeof input !== "object" || Array.isArray(input)) {
25
- throw new Error("环境凭据无效");
26
- }
27
- for (const field of Object.keys(input)) {
28
- if (!CREDENTIAL_FIELDS.has(field)) throw new Error(`环境凭据包含未知字段:${field}`);
29
- }
30
- if (
31
- Object.keys(input).length !== CREDENTIAL_FIELDS.size
32
- || input.schema !== CREDENTIAL_SCHEMA
33
- || input.version !== 1
34
- ) {
35
- throw new Error("环境凭据 schema 无效");
36
- }
37
- const environmentId = assertEnvironmentId(input.environment_id);
38
- if (expected.environmentId && environmentId !== assertEnvironmentId(expected.environmentId)) {
39
- throw new Error("环境凭据 ID 不匹配");
40
- }
41
- if (!looksLikeJwt(input.token)) throw new Error("环境凭据格式无效");
42
- const origin = normalizeConsoleOrigin(input.origin);
43
- if (expected.expectedOrigin && origin !== normalizeConsoleOrigin(expected.expectedOrigin)) {
44
- throw new Error("环境凭据 origin 不匹配");
45
- }
46
- return {
47
- schema: CREDENTIAL_SCHEMA,
48
- version: 1,
49
- environment_id: environmentId,
50
- origin,
51
- token: input.token,
52
- };
53
- }
54
-
55
- function createEnvironmentCredentialStore({
56
- platform = process.platform,
57
- home = os.homedir(),
58
- stateStore = createSecureStateStore({ platform, home }),
59
- } = {}) {
60
- const directory = path.join(home, ".rainbond", "rainskills", "credentials");
61
-
62
- function pathFor(environmentId) {
63
- return path.join(directory, `${assertEnvironmentId(environmentId)}.json`);
64
- }
65
-
66
- function write({ environmentId, origin, token } = {}) {
67
- const payload = validateCredential({
68
- schema: CREDENTIAL_SCHEMA,
69
- version: 1,
70
- environment_id: environmentId,
71
- origin,
72
- token,
73
- });
74
- const target = pathFor(environmentId);
75
- stateStore.ensurePrivateDirectory(directory);
76
- if (fs.existsSync(target)) stateStore.assertProtectedRegularFile(target);
77
- stateStore.atomicWriteJson(target, payload);
78
- return { environmentId: payload.environment_id, origin: payload.origin };
79
- }
80
-
81
- function read({ environmentId, expectedOrigin } = {}) {
82
- const target = pathFor(environmentId);
83
- stateStore.assertProtectedRegularFile(target);
84
- const info = fs.lstatSync(target);
85
- if (info.size > MAX_CREDENTIAL_BYTES) throw new Error("环境凭据文件过大");
86
- const credential = validateCredential(stateStore.readProtectedJson(target), {
87
- environmentId,
88
- expectedOrigin,
89
- });
90
- return { origin: credential.origin, token: credential.token };
91
- }
92
-
93
- function has(environmentId) {
94
- const target = pathFor(environmentId);
95
- if (!fs.existsSync(target)) return false;
96
- stateStore.assertProtectedRegularFile(target);
97
- return true;
98
- }
99
-
100
- function remove(environmentId) {
101
- const target = pathFor(environmentId);
102
- if (!fs.existsSync(target)) return false;
103
- stateStore.assertProtectedRegularFile(target);
104
- fs.unlinkSync(target);
105
- return true;
106
- }
107
-
108
- return { directory, has, pathFor, read, remove, write };
109
- }
110
-
111
- function readLegacyPosixCredential({ home, stateStore }) {
112
- const directory = path.join(home, ".rainbond");
113
- const credentialPath = path.join(directory, "mcp.env");
114
- if (!fs.existsSync(credentialPath)) return null;
115
- stateStore.assertProtectedRegularFile(credentialPath);
116
- const flags = fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW || 0);
117
- const fd = fs.openSync(credentialPath, flags);
118
- let content;
119
- try {
120
- const info = fs.fstatSync(fd);
121
- if (!info.isFile() || info.size > MAX_CREDENTIAL_BYTES) {
122
- throw new Error("旧 Rainbond 凭据文件无效");
123
- }
124
- content = fs.readFileSync(fd, "utf8");
125
- } finally {
126
- fs.closeSync(fd);
127
- }
128
- const match = content.match(
129
- /^export RAINBOND_JWT='([A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+)'\nexport RAINBOND_URL='([^'\r\n]+)'\n?$/
130
- );
131
- if (!match) throw new Error("旧 Rainbond 凭据文件语法无效");
132
- return { token: match[1], origin: normalizeConsoleOrigin(match[2]) };
133
- }
134
-
135
- function defaultLegacyReader({ platform, home, stateStore }) {
136
- if (platform === "win32") {
137
- const origin = process.env.RAINBOND_URL;
138
- if (!origin) return null;
139
- return require("./runtime-credentials.js").readRuntimeCredential({
140
- platform,
141
- home,
142
- stateStore,
143
- expectedOrigin: origin,
144
- });
145
- }
146
- return readLegacyPosixCredential({ home, stateStore });
147
- }
148
-
149
- function migrateLegacyCredential({
150
- platform = process.platform,
151
- home = os.homedir(),
152
- stateStore = createSecureStateStore({ platform, home }),
153
- registry,
154
- credentialStore = createEnvironmentCredentialStore({ platform, home, stateStore }),
155
- readLegacy = defaultLegacyReader,
156
- } = {}) {
157
- if (!registry || typeof registry.add !== "function" || typeof registry.findByOrigin !== "function") {
158
- throw new Error("旧凭据迁移缺少环境注册表");
159
- }
160
- const legacy = readLegacy({ platform, home, stateStore });
161
- if (!legacy) return { migrated: false, environment: null };
162
- const origin = normalizeConsoleOrigin(legacy.origin);
163
- let environment = registry.findByOrigin(origin);
164
- if (!environment) {
165
- environment = registry.add({
166
- kind: origin === "https://run.rainbond.com" ? "saas" : "private",
167
- consoleOrigin: origin,
168
- connectionState: "connected",
169
- }).environment;
170
- }
171
- if (credentialStore.has(environment.id)) {
172
- credentialStore.read({ environmentId: environment.id, expectedOrigin: origin });
173
- return { migrated: false, environment };
174
- }
175
- credentialStore.write({
176
- environmentId: environment.id,
177
- origin,
178
- token: legacy.token,
179
- });
180
- return { migrated: true, environment };
181
- }
182
-
183
- function registerConnectedEnvironment({
184
- registry,
185
- credentialStore,
186
- origin,
187
- token,
188
- kind,
189
- name,
190
- } = {}) {
191
- if (!registry || typeof registry.add !== "function") {
192
- throw new Error("连接环境缺少环境注册表");
193
- }
194
- if (!credentialStore || typeof credentialStore.write !== "function") {
195
- throw new Error("连接环境缺少凭据存储");
196
- }
197
- const normalizedOrigin = normalizeConsoleOrigin(origin);
198
- const registration = registry.add({
199
- kind,
200
- consoleOrigin: normalizedOrigin,
201
- connectionState: "needs-reconnect",
202
- ...(name === undefined ? {} : { name }),
203
- });
204
- credentialStore.write({
205
- environmentId: registration.environment.id,
206
- origin: normalizedOrigin,
207
- token,
208
- });
209
- return {
210
- ...registration,
211
- environment: registry.updateConnection(
212
- registration.environment.id,
213
- "connected"
214
- ),
215
- };
216
- }
217
-
218
- module.exports = {
219
- CREDENTIAL_SCHEMA,
220
- createEnvironmentCredentialStore,
221
- migrateLegacyCredential,
222
- readLegacyPosixCredential,
223
- registerConnectedEnvironment,
224
- validateCredential,
225
- };