openxiangda 1.0.198 → 1.0.199

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 CHANGED
@@ -55,6 +55,13 @@ openxiangda environment attach --logical-app example-app --preproduction-target
55
55
  openxiangda environment status --json
56
56
  # 仅限投产前环境角色重分类:原子交换两个既有应用的角色,应用数据和 Release Head 不移动
57
57
  openxiangda environment swap --reason "投产前将现有业务应用调整为正式应用" --confirm-production --profile dev
58
+ # 单独调整一个环境的副作用策略:先只读预览,再按当前 revision 审计式更新;不会交换环境角色
59
+ openxiangda environment policy update preproduction \
60
+ --side-effect-policy-json '{"organizationWrites":"explicit_capability_only"}' \
61
+ --reason "为预发真实 UAT 开放受权限保护的组织写入" --dry-run --profile dev
62
+ openxiangda environment policy update preproduction \
63
+ --side-effect-policy-json '{"organizationWrites":"explicit_capability_only"}' \
64
+ --reason "为预发真实 UAT 开放受权限保护的组织写入" --profile dev
58
65
  openxiangda studio
59
66
  # 环境托管应用日常发布:首次命令只部署预发并停止
60
67
  openxiangda release ship --change mainline-release --profile dev
@@ -78,6 +85,8 @@ Existing workspaces connect to a server-side environment set with `environment a
78
85
 
79
86
  `environment swap` is a commissioning/reclassification operation, not a release shortcut. It requires `--confirm-production` and a reason, atomically exchanges the two existing environment roles, preserves each application's data and Release Heads, and remaps local resource IDs by appType. Existing side-effect policies remain restricted unless explicit replacement policy JSON is supplied.
80
87
 
88
+ Use `environment policy update <kind|id>` when only one environment's side-effect policy must change. The CLI reads the current revision and shows the exact before/after diff; `--dry-run` performs GET only. The write uses CAS, increments only that environment revision, writes a durable before/after audit, and preserves unspecified fields unless `--full-replace` is explicit. Production writes additionally require `--confirm-production`. `organizationWrites=explicit_capability_only` removes the environment-level deny but still requires `app:organization:manage`; there is no unrestricted bypass mode.
89
+
81
90
  `openxiangda studio` starts a loopback-only local Developer Center with a random session token. It shows target bindings, candidate/deployment status, Git state, test evidence, drift, and the next safe action. Its buttons invoke only registered OpenXiangda operations; it does not expose arbitrary shell execution. Production promotion and rollback still require an explicit production confirmation.
82
91
 
83
92
  `resource plan` and `resource publish --dry-run` run behind a strict GET/HEAD-only HTTP guard. If a read receives HTTP 401, the command fails with `READ_ONLY_AUTH_REQUIRED` and never calls the token refresh POST from inside the plan. Run `openxiangda auth refresh --profile <name>` (or log in again) before retrying; a plan must not mutate auth state or platform resources.
@@ -3,6 +3,20 @@ const fs = require('fs');
3
3
  const path = require('path');
4
4
 
5
5
  const ENVIRONMENT_KINDS = new Set(['preproduction', 'production']);
6
+ const SIDE_EFFECT_POLICY_ENUMS = Object.freeze({
7
+ notifications: ['disabled', 'tester_allowlist', 'enabled', 'real'],
8
+ organizationWrites: ['deny', 'explicit_capability_only'],
9
+ scheduledAutomations: ['disabled', 'enabled'],
10
+ externalWrites: ['deny', 'allowlist', 'configured', 'sandbox'],
11
+ payments: ['deny', 'configured', 'sandbox'],
12
+ publicIndexing: ['deny', 'configured', 'enabled'],
13
+ });
14
+ const SIDE_EFFECT_POLICY_FIELDS = new Set([
15
+ ...Object.keys(SIDE_EFFECT_POLICY_ENUMS),
16
+ 'notificationAllowlist',
17
+ 'environmentBanner',
18
+ 'externalDingTalkDepartmentRootId',
19
+ ]);
6
20
 
7
21
  function canonicalJson(value) {
8
22
  if (Array.isArray(value)) {
@@ -45,6 +59,114 @@ function cloneJsonValue(value) {
45
59
  : JSON.parse(JSON.stringify(value));
46
60
  }
47
61
 
62
+ function normalizeSideEffectPolicyInput(value, label = 'sideEffectPolicy') {
63
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
64
+ throw new Error(`${label} 必须是对象`);
65
+ }
66
+ for (const key of Object.keys(value)) {
67
+ if (!SIDE_EFFECT_POLICY_FIELDS.has(key)) {
68
+ throw new Error(`${label}.${key} 不是允许的副作用策略字段`);
69
+ }
70
+ }
71
+ const result = {};
72
+ for (const [key, allowed] of Object.entries(SIDE_EFFECT_POLICY_ENUMS)) {
73
+ if (!Object.prototype.hasOwnProperty.call(value, key)) continue;
74
+ const normalized = String(value[key] || '').trim();
75
+ if (!allowed.includes(normalized)) {
76
+ throw new Error(`${label}.${key} 必须是 ${allowed.join('、')} 之一`);
77
+ }
78
+ result[key] = normalized;
79
+ }
80
+ if (Object.prototype.hasOwnProperty.call(value, 'notificationAllowlist')) {
81
+ if (!Array.isArray(value.notificationAllowlist)) {
82
+ throw new Error(`${label}.notificationAllowlist 必须是数组`);
83
+ }
84
+ if (value.notificationAllowlist.length > 500) {
85
+ throw new Error(`${label}.notificationAllowlist 最多包含 500 项`);
86
+ }
87
+ result.notificationAllowlist = Array.from(
88
+ new Set(
89
+ value.notificationAllowlist.map((item, index) => {
90
+ const normalized = String(item ?? '').trim();
91
+ if (!normalized || normalized.length > 255) {
92
+ throw new Error(
93
+ `${label}.notificationAllowlist[${index}] 必须是 1-255 字符的字符串`,
94
+ );
95
+ }
96
+ return normalized;
97
+ }),
98
+ ),
99
+ );
100
+ }
101
+ if (Object.prototype.hasOwnProperty.call(value, 'environmentBanner')) {
102
+ if (typeof value.environmentBanner !== 'boolean') {
103
+ throw new Error(`${label}.environmentBanner 必须是布尔值`);
104
+ }
105
+ result.environmentBanner = value.environmentBanner;
106
+ }
107
+ if (
108
+ Object.prototype.hasOwnProperty.call(
109
+ value,
110
+ 'externalDingTalkDepartmentRootId',
111
+ )
112
+ ) {
113
+ const raw = value.externalDingTalkDepartmentRootId;
114
+ if (
115
+ !['string', 'number'].includes(typeof raw) ||
116
+ (typeof raw === 'number' && !Number.isSafeInteger(raw))
117
+ ) {
118
+ throw new Error(
119
+ `${label}.externalDingTalkDepartmentRootId 必须是字符串或安全整数`,
120
+ );
121
+ }
122
+ const normalized = String(raw).trim();
123
+ if (!/^\d{1,64}$/.test(normalized)) {
124
+ throw new Error(
125
+ `${label}.externalDingTalkDepartmentRootId 必须是数字型钉钉部门 ID`,
126
+ );
127
+ }
128
+ result.externalDingTalkDepartmentRootId = normalized;
129
+ }
130
+ return result;
131
+ }
132
+
133
+ function buildSideEffectPolicyDiff(beforeInput, updateInput, options = {}) {
134
+ const before = normalizeSideEffectPolicyInput(
135
+ beforeInput || {},
136
+ 'currentSideEffectPolicy',
137
+ );
138
+ const update = normalizeSideEffectPolicyInput(
139
+ updateInput,
140
+ 'sideEffectPolicy',
141
+ );
142
+ const fullReplace = options.fullReplace === true;
143
+ const after = normalizeSideEffectPolicyInput(
144
+ fullReplace ? update : { ...before, ...update },
145
+ 'nextSideEffectPolicy',
146
+ );
147
+ const fields = Array.from(
148
+ new Set([...Object.keys(before), ...Object.keys(after)]),
149
+ ).sort();
150
+ const changes = fields
151
+ .filter(key => canonicalJson(before[key]) !== canonicalJson(after[key]))
152
+ .map(key => ({
153
+ field: key,
154
+ before: Object.prototype.hasOwnProperty.call(before, key)
155
+ ? cloneJsonValue(before[key])
156
+ : null,
157
+ after: Object.prototype.hasOwnProperty.call(after, key)
158
+ ? cloneJsonValue(after[key])
159
+ : null,
160
+ }));
161
+ return {
162
+ fullReplace,
163
+ changed: changes.length > 0,
164
+ before,
165
+ after,
166
+ changes,
167
+ };
168
+ }
169
+
48
170
  function normalizeIdentityList(values) {
49
171
  return Array.from(
50
172
  new Set(
@@ -203,6 +325,10 @@ function bindEnvironmentTarget(state, input) {
203
325
  input.sideEffectPolicy === undefined
204
326
  ? previous.sideEffectPolicy || {}
205
327
  : input.sideEffectPolicy,
328
+ revision:
329
+ input.revision === undefined
330
+ ? previous.revision || null
331
+ : Number(input.revision),
206
332
  resources,
207
333
  updatedAt: new Date().toISOString(),
208
334
  };
@@ -449,12 +575,14 @@ function isRecoverablePostActivationDeploymentError(error, deployment) {
449
575
 
450
576
  module.exports = {
451
577
  bindEnvironmentTarget,
578
+ buildSideEffectPolicyDiff,
452
579
  buildCandidateBundle,
453
580
  canonicalJson,
454
581
  isRecoverablePostActivationDeploymentError,
455
582
  normalizeEnvironmentKind,
456
583
  normalizeManagedChangeSourceBase,
457
584
  normalizeManagedReleaseSourceRevision,
585
+ normalizeSideEffectPolicyInput,
458
586
  normalizeTargetName,
459
587
  hasStateResourceMappings,
460
588
  readCandidate,
package/lib/cli.js CHANGED
@@ -130,6 +130,7 @@ const { buildDesignReview, renderDesignReview } = require('./design-review');
130
130
  const {
131
131
  bindEnvironmentTarget,
132
132
  buildCandidateBundle,
133
+ buildSideEffectPolicyDiff,
133
134
  isRecoverablePostActivationDeploymentError,
134
135
  normalizeEnvironmentKind,
135
136
  normalizeManagedChangeSourceBase,
@@ -299,7 +300,7 @@ Usage:
299
300
  openxiangda open-api credential list|get|create|update|rotate-secret [id] [--profile name] [--show-secret] [--yes] [--json]
300
301
  openxiangda design gates|template|review [--topic code] [--json]
301
302
  openxiangda sdd init|migrate|propose|quick|bundle|approve|status|context|verify|sync|archive [change] [--change id] [--json]
302
- openxiangda environment init|attach|bind|swap|list|status|diff|use [preproduction|production] [--logical-app code] [--environment target] [--json]
303
+ openxiangda environment init|attach|bind|swap|policy update|list|status|diff|use [preproduction|production] [--logical-app code] [--environment target] [--json]
303
304
  openxiangda release publish|begin|status|integration-status|renew|end [--change id] [--profile name] [--watch] [--json]
304
305
  openxiangda release ship|candidate|deploy|test|promote|rollback [--candidate id] [--environment target] [--json]
305
306
  openxiangda task status --change <id> [--profile name] [--watch] [--json]
@@ -384,6 +385,7 @@ const SUBCOMMAND_BOOLEAN_FLAGS = new Set([
384
385
  '--dry-run',
385
386
  '--enabled',
386
387
  '--force',
388
+ '--full-replace',
387
389
  '--help',
388
390
  '--include-sourcemaps',
389
391
  '--json',
@@ -1920,6 +1922,7 @@ function saveEnvironmentWorkspaceState(state, setDetail, environmentDetail, inpu
1920
1922
  displayName: environmentDetail.displayName,
1921
1923
  publicOrigin: environmentDetail.publicOrigin,
1922
1924
  sideEffectPolicy: environmentDetail.sideEffectPolicy,
1925
+ revision: environmentDetail.revision,
1923
1926
  seedResources,
1924
1927
  replaceResources: input.replaceResources,
1925
1928
  seedAppScopedState: input.seedAppScopedState,
@@ -1939,6 +1942,7 @@ async function environment(args) {
1939
1942
  ' openxiangda environment attach --logical-app <code> [--preproduction-target name] [--production-target name] [--profile name]',
1940
1943
  ' openxiangda environment bind preproduction|production --app-type APP_XXX [--target name] [--profile name]',
1941
1944
  ' openxiangda environment swap --reason <text> --confirm-production [--preproduction-side-effect-policy-json <JSON|file>] [--production-side-effect-policy-json <JSON|file>] [--profile name]',
1945
+ ' openxiangda environment policy update preproduction|production --side-effect-policy-json <JSON|file> --reason <text> [--dry-run] [--full-replace] [--confirm-production] [--profile name]',
1942
1946
  ' openxiangda environment list|status|diff [--logical-app code] [--profile name] [--json]',
1943
1947
  ' openxiangda environment use <target|preproduction|production>',
1944
1948
  ].join('\n'));
@@ -2099,6 +2103,133 @@ async function environment(args) {
2099
2103
  Object.values(state.targets || {})[0]?.profile ||
2100
2104
  config.currentProfile;
2101
2105
 
2106
+ if (subcommand === 'policy') {
2107
+ if (positional[0] !== 'update') {
2108
+ fail(
2109
+ '用法: openxiangda environment policy update preproduction|production --side-effect-policy-json <JSON|file> --reason <text> [--dry-run]',
2110
+ );
2111
+ }
2112
+ const selector = positional[1] || flags.environment || flags.target;
2113
+ if (!selector) {
2114
+ fail('environment policy update 必须指定环境 kind、id 或本地 target');
2115
+ }
2116
+ const reason = readStringFlag(flags, 'reason');
2117
+ if (!reason || reason.length < 10) {
2118
+ fail('environment policy update 必须提供至少 10 个字符的 --reason');
2119
+ }
2120
+ const policySource = readStringFlag(flags, 'side-effect-policy-json');
2121
+ if (!policySource) {
2122
+ fail('environment policy update 必须提供 --side-effect-policy-json');
2123
+ }
2124
+ const profile = getProfile(config, selectedProfile);
2125
+ const setDetail = await requestWithAuth(
2126
+ config,
2127
+ profile.profileName,
2128
+ environmentSetApiPath(code),
2129
+ );
2130
+ const localTarget = state.targets?.[selector];
2131
+ const environmentSelector = localTarget?.environmentId || selector;
2132
+ const matches = (setDetail.environments || []).filter(
2133
+ item =>
2134
+ item.id === environmentSelector || item.kind === environmentSelector,
2135
+ );
2136
+ if (matches.length !== 1) {
2137
+ fail(`应用环境不存在或不唯一: ${selector}`);
2138
+ }
2139
+ const environmentDetail = matches[0];
2140
+ const explicitExpectedRevision = readStringFlag(
2141
+ flags,
2142
+ 'expected-revision',
2143
+ );
2144
+ const expectedRevision = explicitExpectedRevision
2145
+ ? Number(explicitExpectedRevision)
2146
+ : Number(environmentDetail.revision);
2147
+ if (!Number.isSafeInteger(expectedRevision) || expectedRevision < 1) {
2148
+ fail('environment policy update 缺少有效的环境 revision');
2149
+ }
2150
+ const policyUpdate = readJsonInput(
2151
+ policySource,
2152
+ 'side-effect-policy-json',
2153
+ );
2154
+ const diff = buildSideEffectPolicyDiff(
2155
+ environmentDetail.sideEffectPolicy || {},
2156
+ policyUpdate,
2157
+ { fullReplace: Boolean(flags['full-replace']) },
2158
+ );
2159
+ const preview = {
2160
+ logicalApp: {
2161
+ id: setDetail.id,
2162
+ code: setDetail.code,
2163
+ },
2164
+ environment: {
2165
+ id: environmentDetail.id,
2166
+ kind: environmentDetail.kind,
2167
+ appType: environmentDetail.appType,
2168
+ revision: environmentDetail.revision,
2169
+ },
2170
+ expectedRevision,
2171
+ reason,
2172
+ dryRun: Boolean(flags['dry-run']),
2173
+ ...diff,
2174
+ };
2175
+ if (flags['dry-run'] || !diff.changed) {
2176
+ if (flags.json) return writeJson(preview);
2177
+ print(JSON.stringify(preview, null, 2));
2178
+ return;
2179
+ }
2180
+ if (
2181
+ environmentDetail.kind === 'production' &&
2182
+ !flags['confirm-production']
2183
+ ) {
2184
+ fail(
2185
+ 'environment policy update 正式环境写入必须提供 --confirm-production;--dry-run 不需要',
2186
+ );
2187
+ }
2188
+ const data = await requestWithAuth(
2189
+ config,
2190
+ profile.profileName,
2191
+ environmentSetApiPath(
2192
+ code,
2193
+ `/environments/${encodeURIComponent(environmentDetail.id)}/policy`,
2194
+ ),
2195
+ {
2196
+ method: 'POST',
2197
+ body: {
2198
+ expectedRevision,
2199
+ sideEffectPolicy: policyUpdate,
2200
+ reason,
2201
+ fullReplace: Boolean(flags['full-replace']),
2202
+ confirmProduction: Boolean(flags['confirm-production']),
2203
+ },
2204
+ },
2205
+ );
2206
+ const previousTarget = Object.values(state.targets || {}).find(
2207
+ target => target.environmentId === environmentDetail.id,
2208
+ );
2209
+ const updatedTarget = saveEnvironmentWorkspaceState(
2210
+ state,
2211
+ setDetail,
2212
+ data.environment,
2213
+ {
2214
+ targetName:
2215
+ previousTarget?.targetName ||
2216
+ localTarget?.targetName ||
2217
+ data.environment.kind,
2218
+ profile: previousTarget?.profile || profile.profileName,
2219
+ },
2220
+ );
2221
+ const result = {
2222
+ ...preview,
2223
+ dryRun: false,
2224
+ environment: data.environment,
2225
+ audit: data.audit,
2226
+ target: updatedTarget,
2227
+ };
2228
+ if (flags.json) return writeJson(result);
2229
+ print(JSON.stringify(result, null, 2));
2230
+ return;
2231
+ }
2232
+
2102
2233
  if (subcommand === 'swap') {
2103
2234
  if (!flags['confirm-production']) {
2104
2235
  fail(
@@ -2240,7 +2371,7 @@ async function environment(args) {
2240
2371
  return;
2241
2372
  }
2242
2373
 
2243
- fail('用法: openxiangda environment init|attach|bind|swap|list|status|diff|use');
2374
+ fail('用法: openxiangda environment init|attach|bind|swap|policy update|list|status|diff|use');
2244
2375
  }
2245
2376
 
2246
2377
  function buildEnvironmentStatusDiff(status) {
@@ -13947,7 +14078,7 @@ async function commands(args) {
13947
14078
  'open-api credential list|get|create|update|rotate-secret [id]',
13948
14079
  'design gates|template|review [--topic code]',
13949
14080
  'sdd init|migrate|propose|quick|bundle|approve|status|context|verify|sync|archive',
13950
- 'environment init|attach|bind|swap|list|status|diff|use',
14081
+ 'environment init|attach|bind|swap|policy update|list|status|diff|use',
13951
14082
  'release ship|candidate|deploy|test|promote|rollback|publish|begin|status|integration-status|renew|end|backend-head|backend-list|backend-detail|backend-diff|backend-rollback|backend-abort|backend-retry|app-capture|app-head|app-list|app-detail|app-diff|app-prepare|app-verify|app-activate|app-finalize|app-rollback|app-abort',
13952
14083
  'studio [--no-open] [--port 0]',
13953
14084
  'env',
@@ -104,7 +104,7 @@ openxiangda release ship --change <release-change> --profile <name> \
104
104
  --confirm-production
105
105
  ```
106
106
 
107
- For a workspace registered by `openxiangda environment init` or connected to an existing set with `openxiangda environment attach`, production is never a direct publish target. Use the two-phase `release ship` fast path by default. Its first invocation creates/deploys the immutable candidate to preproduction and always returns `awaiting_production_confirmation`; it cannot promote. A second invocation with `--confirm-production` promotes the exact same candidate hash. Real human acceptance is the recommended normal practice and can be recorded with optional `--acceptance-note`, but do not invent an acceptance note and do not treat it as a universal hard platform gate when the user explicitly authorizes a low-risk or emergency promotion. The lower-level candidate/deploy/test/promote commands are recovery primitives, not the normal agent loop. Preproduction and production keep independent app/resource/data identities in `.openxiangda/state.json`; do not copy IDs between targets. `environment attach` may seed only the matching legacy app binding into preproduction and must leave production empty. Only during authorized commissioning/reclassification may `environment swap --reason "..." --confirm-production` atomically exchange the two existing roles; it preserves each app's data and Release Heads, remaps local resource IDs by appType, and does not enable production side effects by default. Use `openxiangda studio` for the loopback-only developer view of bindings, drift, evidence, and safe next actions.
107
+ For a workspace registered by `openxiangda environment init` or connected to an existing set with `openxiangda environment attach`, production is never a direct publish target. Use the two-phase `release ship` fast path by default. Its first invocation creates/deploys the immutable candidate to preproduction and always returns `awaiting_production_confirmation`; it cannot promote. A second invocation with `--confirm-production` promotes the exact same candidate hash. Real human acceptance is the recommended normal practice and can be recorded with optional `--acceptance-note`, but do not invent an acceptance note and do not treat it as a universal hard platform gate when the user explicitly authorizes a low-risk or emergency promotion. The lower-level candidate/deploy/test/promote commands are recovery primitives, not the normal agent loop. Preproduction and production keep independent app/resource/data identities in `.openxiangda/state.json`; do not copy IDs between targets. `environment attach` may seed only the matching legacy app binding into preproduction and must leave production empty. Only during authorized commissioning/reclassification may `environment swap --reason "..." --confirm-production` atomically exchange the two existing roles; it preserves each app's data and Release Heads, remaps local resource IDs by appType, and does not enable production side effects by default. To change only one environment's side-effect policy, run `environment policy update <kind|id> --side-effect-policy-json <JSON|file> --reason "..." --dry-run` first, then repeat without `--dry-run`; never use swap for this. The update is revision-CAS and patch-preserving unless `--full-replace` is explicit, production needs `--confirm-production`, and `organizationWrites=explicit_capability_only` still requires `app:organization:manage`. Use `openxiangda studio` for the loopback-only developer view of bindings, drift, evidence, and safe next actions.
108
108
 
109
109
  `resource plan` and publish dry-runs are strictly GET/HEAD-only. `READ_ONLY_AUTH_REQUIRED` means the access token expired; run `openxiangda auth refresh --profile <name>` or log in again before retrying. Never add an automatic refresh POST inside a plan.
110
110
 
@@ -866,6 +866,10 @@ Binds the missing `preproduction` or `production` app identity. An appType can b
866
866
 
867
867
  Atomically exchanges the roles of the two existing app identities during an explicitly confirmed commissioning/reclassification operation. The request requires `confirmation=SWAP_PREPRODUCTION_AND_PRODUCTION` and a reason. Application data and Release Heads stay with their appType; local target resources are remapped by appType. Existing side-effect restrictions remain unless the request explicitly supplies replacement policies.
868
868
 
869
+ ### POST `/environment-sets/:code/environments/:kindOrId/policy`
870
+
871
+ Updates only one environment's side-effect policy. The request requires `expectedRevision`, `reason`, and a strictly validated `sideEffectPolicy` patch; `fullReplace=true` is the only way to replace rather than merge. Production additionally requires `confirmProduction=true`. A successful transaction increments that environment revision and writes a durable audit containing actor, environment identity, reason, and secret-free before/after policies. It does not change either environment role, business data, or any App/Runtime/Backend/Page/Workflow Release Head. `externalDingTalkDepartmentRootId` accepts a string or safe integer and is stored as a string. `organizationWrites=explicit_capability_only` still requires the normal `app:organization:manage` permission.
872
+
869
873
  ### GET `/environment-sets/:code/status`
870
874
 
871
875
  Returns each target's active heads, latest deployment, side-effect policy, and candidate drift state for the local Developer Center.
@@ -68,9 +68,16 @@ Environment-managed workspaces add a logical application and target-specific bin
68
68
  "environmentId": "PRE_ENV_UUID",
69
69
  "kind": "preproduction",
70
70
  "appType": "APP_PRE",
71
+ "revision": 4,
71
72
  "sideEffectPolicy": {
72
- "notificationsEnabled": false,
73
- "scheduledAutomationsEnabled": false
73
+ "notifications": "tester_allowlist",
74
+ "notificationAllowlist": [],
75
+ "organizationWrites": "deny",
76
+ "scheduledAutomations": "disabled",
77
+ "externalWrites": "allowlist",
78
+ "payments": "deny",
79
+ "publicIndexing": "deny",
80
+ "environmentBanner": true
74
81
  },
75
82
  "resources": {}
76
83
  },
@@ -102,4 +109,5 @@ Environment-managed workspaces add a logical application and target-specific bin
102
109
  - A prod publish must not read dev IDs.
103
110
  - Never copy target resource bindings. Use `openxiangda environment use <target>` or pass `--environment <target>` and let the CLI populate that target from its own deployment.
104
111
  - Managed targets cannot use direct `release publish`; use two-phase `release ship`. The first invocation only prepares preproduction and stops; after confirming the preproduction result, a separate invocation with `--confirm-production` promotes the same candidate. Human acceptance is recommended and may be recorded with optional `--acceptance-note`.
112
+ - Change a single target's side-effect policy with `openxiangda environment policy update <kind|id> --side-effect-policy-json <JSON|file> --reason "..." --dry-run`, inspect the exact diff, then repeat without `--dry-run`. The write uses the server revision as CAS and updates local `revision`; it does not swap roles or alter Release Heads. Omitted fields are preserved unless `--full-replace` is explicit, and production additionally requires `--confirm-production`.
105
113
  - Before publishing to another platform, run `openxiangda workspace bind --profile <name> --app-type <APP_XXX>`.
@@ -105,7 +105,7 @@ openxiangda release ship --change <release-change> --profile <name> \
105
105
  --confirm-production
106
106
  ```
107
107
 
108
- Once `environment init` registers a logical application, or `environment attach` connects an existing workspace, `preproduction` and `production` are separate target bindings with separate app/resource/data IDs. Never copy IDs between them. Existing legacy resource mappings may seed only the target whose appType matches (normally preproduction); production stays empty. The normal path is the two-phase `release ship`. Its first invocation creates and deploys the immutable candidate only to preproduction and stops at `awaiting_production_confirmation`. A different, later invocation with `--confirm-production` promotes the exact same candidate and fresh deployment-bound evidence. Human acceptance is recommended and an optional `--acceptance-note` records it, but it is not a universal hard platform gate for explicitly authorized low-risk or emergency releases. Direct `release publish` to either managed target fails closed. Only authorized commissioning/reclassification may run `environment swap --reason "..." --confirm-production`; the atomic operation preserves each app's data and Release Heads, remaps local resources by appType, and keeps existing side-effect restrictions unless explicit replacement policies are supplied. `openxiangda studio` is the local loopback-only developer view and exposes only registered safe actions.
108
+ Once `environment init` registers a logical application, or `environment attach` connects an existing workspace, `preproduction` and `production` are separate target bindings with separate app/resource/data IDs. Never copy IDs between them. Existing legacy resource mappings may seed only the target whose appType matches (normally preproduction); production stays empty. The normal path is the two-phase `release ship`. Its first invocation creates and deploys the immutable candidate only to preproduction and stops at `awaiting_production_confirmation`. A different, later invocation with `--confirm-production` promotes the exact same candidate and fresh deployment-bound evidence. Human acceptance is recommended and an optional `--acceptance-note` records it, but it is not a universal hard platform gate for explicitly authorized low-risk or emergency releases. Direct `release publish` to either managed target fails closed. Only authorized commissioning/reclassification may run `environment swap --reason "..." --confirm-production`; the atomic operation preserves each app's data and Release Heads, remaps local resources by appType, and keeps existing side-effect restrictions unless explicit replacement policies are supplied. A single environment policy change uses `environment policy update <kind|id>` with a GET-only `--dry-run` first; it uses revision CAS, preserves omitted fields unless `--full-replace` is explicit, and never swaps roles or Release Heads. Production writes require `--confirm-production`. `organizationWrites=explicit_capability_only` only removes the environment deny and never bypasses `app:organization:manage`. `openxiangda studio` is the local loopback-only developer view and exposes only registered safe actions.
109
109
 
110
110
  `release publish` is the normal whole-app entrypoint for legacy unmanaged workspaces: it verifies SDD without mutating reviewed files, waits for the promotion lease, freezes one App capture, stages the exact Form/Backend/Runtime children, resumes from a private execution journal, finalizes once, and releases the lease. Managed applications use two-phase `release ship` and its deployment-scoped journal. Individual candidate/deploy/test/promote commands are recovery/diagnostic primitives.
111
111
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openxiangda",
3
- "version": "1.0.198",
3
+ "version": "1.0.199",
4
4
  "description": "OpenXiangda CLI, workspace build tools, runtime SDK, and form components.",
5
5
  "private": false,
6
6
  "bin": {
@@ -64,7 +64,7 @@
64
64
  "build:sdk": "tsup --config packages/sdk/tsup.config.ts",
65
65
  "check": "node --check bin/openxiangda.js && node --check lib/*.js && node --check packages/sdk/src/build-source/src/cli.mjs && node --check packages/sdk/src/build-source/scripts/*.mjs && node --check packages/sdk/src/build-source/scripts/utils/*.mjs",
66
66
  "test": "npm run test:fast",
67
- "test:fast": "npm run check && node scripts/http-proxy-smoke.mjs && node scripts/form-export-cli-smoke.mjs && node scripts/open-api-cli-smoke.mjs && node scripts/release-plan-smoke.mjs && node scripts/typed-resource-plan-smoke.mjs && node scripts/integration-bundle-smoke.mjs && node scripts/content-cache-smoke.mjs && node scripts/dependency-capsule-smoke.mjs && node scripts/sdd-stages-smoke.mjs && node scripts/environment-swap-cli-smoke.mjs",
67
+ "test:fast": "npm run check && node scripts/http-proxy-smoke.mjs && node scripts/form-export-cli-smoke.mjs && node scripts/open-api-cli-smoke.mjs && node scripts/release-plan-smoke.mjs && node scripts/typed-resource-plan-smoke.mjs && node scripts/integration-bundle-smoke.mjs && node scripts/content-cache-smoke.mjs && node scripts/dependency-capsule-smoke.mjs && node scripts/sdd-stages-smoke.mjs && node scripts/environment-swap-cli-smoke.mjs && node scripts/environment-policy-cli-smoke.mjs",
68
68
  "test:changed": "npm run check && node scripts/run-test-suite.mjs --changed --evidence",
69
69
  "test:contract": "npm run check && node scripts/run-test-suite.mjs --contract --evidence",
70
70
  "test:release": "npm run check && node scripts/run-test-suite.mjs --release --evidence",
@@ -114,6 +114,7 @@
114
114
  "test:application-environments": "node scripts/application-environments-smoke.mjs",
115
115
  "test:release-ship": "node scripts/release-ship-gate-smoke.mjs",
116
116
  "test:environment-swap": "node scripts/environment-swap-cli-smoke.mjs",
117
+ "test:environment-policy": "node scripts/environment-policy-cli-smoke.mjs",
117
118
  "test:developer-center": "node scripts/developer-center-smoke.mjs",
118
119
  "test:form-release-cas": "node scripts/form-release-cas-smoke.mjs",
119
120
  "test:source-dependencies": "node scripts/source-dependencies-smoke.mjs",
@@ -52,7 +52,7 @@ openxiangda commands --json
52
52
 
53
53
  模板已停用无范围的 `pnpm deploy` 聚合入口。日常变更必须使用 `resource plan|publish <type> --only <codes>`(单资源可用 `--code <code>`)。Form bundle、Backend Release 和 Runtime 都先暂存;CLI 会按 `--change` 自动聚合 `.openxiangda/releases/<change>/staged-resources.json`,最后只由一次 Root App finalize 原子激活。不要使用 `workspace publish --form`、单独 `runtime activate`、`pnpm publish:all`、`pnpm openxiangda:publish` 或 `lowcode-workspace publish-all`。
54
54
 
55
- 工作区一旦通过 `environment init` 登记,或通过 `environment attach` 接入已有环境组,`release publish` 即不再是入口。日常使用两段式 `release ship`:第一次冻结不可变 candidate 并只部署到 preproduction,停止在 `awaiting_production_confirmation`;确认预发结果后,第二次命令提供 `--confirm-production`,把同一 candidate 晋级 production,不会重新构建。真实人工验收是默认建议,可用可选的 `--acceptance-note` 留痕;但用户明确授权的低风险或紧急发布不受僵硬审批门禁阻塞。两套环境的 appType、资源 ID、数据和副作用策略完全独立;旧单目标资源映射只允许迁移到 appType 相同的预发 target,正式 target 必须为空。仅在用户明确授权的投产前重分类中使用 `environment swap --reason "..." --confirm-production` 原子交换两个既有应用的环境角色;数据和 Release Head 不移动,副作用默认不放开。`openxiangda studio` 提供仅本机访问的开发者页面,用于查看绑定、漂移、候选、部署、证据和下一安全动作。
55
+ 工作区一旦通过 `environment init` 登记,或通过 `environment attach` 接入已有环境组,`release publish` 即不再是入口。日常使用两段式 `release ship`:第一次冻结不可变 candidate 并只部署到 preproduction,停止在 `awaiting_production_confirmation`;确认预发结果后,第二次命令提供 `--confirm-production`,把同一 candidate 晋级 production,不会重新构建。真实人工验收是默认建议,可用可选的 `--acceptance-note` 留痕;但用户明确授权的低风险或紧急发布不受僵硬审批门禁阻塞。两套环境的 appType、资源 ID、数据和副作用策略完全独立;旧单目标资源映射只允许迁移到 appType 相同的预发 target,正式 target 必须为空。仅在用户明确授权的投产前重分类中使用 `environment swap --reason "..." --confirm-production` 原子交换两个既有应用的环境角色;数据和 Release Head 不移动,副作用默认不放开。单独调整某个环境的副作用策略时,先运行 `environment policy update <kind|id> ... --dry-run` 查看差异,再按 CAS revision 写入;不得借用 swap,遗漏字段默认保留,正式写入另需 `--confirm-production`。`organizationWrites=explicit_capability_only` 仍强制 `app:organization:manage`。`openxiangda studio` 提供仅本机访问的开发者页面,用于查看绑定、漂移、候选、部署、证据和下一安全动作。
56
56
 
57
57
  `resource plan` 与 publish dry-run 严格只允许 GET/HEAD。遇到 `READ_ONLY_AUTH_REQUIRED` 时,先执行 `openxiangda auth refresh --profile <name>` 或重新登录再重试;不得在 plan 内自动 POST 刷新 token。
58
58
 
@@ -57,7 +57,7 @@
57
57
  - ✅ `resource plan` 与 publish dry-run 严格只允许 GET/HEAD;遇到 `READ_ONLY_AUTH_REQUIRED` 时先执行 `openxiangda auth refresh --profile <name>` 或重新登录,不得在 plan 内自动 POST 刷新 token。
58
58
  - ✅ Function/Automation 使用 Backend Release v2;正式多资源发布用精确 `--only/--code` 加 `--stage-only` 暂存,同一 child 可混合 create、source-only update 和显式 manifest replacement,再由 Root App finalize 原子激活。整包 manifest 替换必须另加 `--replace-manifest --reason "..."`。
59
59
  - ✅ 未登记环境的旧工作区,正式 promotion 先聚合 mainline bundle 并 commit/push,再运行 `release publish --change <id> --profile <name>`。
60
- - ✅ 已通过 `environment init` 登记或 `environment attach` 接入的工作区默认使用两段式 `release ship`。第一次命令只冻结 candidate 并部署 preproduction,停止等待正式晋级确认;确认预发结果后,另一次命令提供 `--confirm-production`,即可晋级同一 candidate。人工验收是默认建议,可用可选的 `--acceptance-note` 留痕,但不是所有低风险或紧急发布的硬审批门禁。preproduction / production 的 appType、资源 ID、数据和副作用策略完全隔离,严禁跨环境复制 ID 或直接 `release publish`。旧单目标映射只允许按相同 appType 迁移到预发。仅在用户明确授权的投产前重分类中使用 `environment swap --reason "..." --confirm-production` 原子交换两个既有应用的环境角色;数据和 Release Head 不移动,副作用默认不放开。
60
+ - ✅ 已通过 `environment init` 登记或 `environment attach` 接入的工作区默认使用两段式 `release ship`。第一次命令只冻结 candidate 并部署 preproduction,停止等待正式晋级确认;确认预发结果后,另一次命令提供 `--confirm-production`,即可晋级同一 candidate。人工验收是默认建议,可用可选的 `--acceptance-note` 留痕,但不是所有低风险或紧急发布的硬审批门禁。preproduction / production 的 appType、资源 ID、数据和副作用策略完全隔离,严禁跨环境复制 ID 或直接 `release publish`。旧单目标映射只允许按相同 appType 迁移到预发。仅在用户明确授权的投产前重分类中使用 `environment swap --reason "..." --confirm-production` 原子交换两个既有应用的环境角色;数据和 Release Head 不移动,副作用默认不放开。单环境副作用策略用 `environment policy update <kind|id> ... --dry-run` 预览后按 revision CAS 写入,禁止借用 swap;默认保留未指定字段,正式写入需 `--confirm-production`,且 `organizationWrites=explicit_capability_only` 不绕过 `app:organization:manage`。
61
61
  - ✅ 本地开发者可运行 `openxiangda studio` 查看两套环境、差异、候选、部署和测试证据;该页面只监听回环地址且只暴露注册动作,生产操作仍需显式确认。
62
62
 
63
63
  ## 严禁