huaweicloud-devkit 2.0.0-next.3 → 2.0.0-next.5
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 +3 -1
- package/package.json +3 -1
- package/plugins/huaweicloud-core/.claude-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/.codex-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/.cursor-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/.hermes-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/.mcp.json +55 -1
- package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/dist/agents/codex-config.js +374 -0
- package/plugins/huaweicloud-core/dist/agents/codex-desktop.js +8 -1
- package/plugins/huaweicloud-core/dist/agents/codex.js +9 -0
- package/plugins/huaweicloud-core/dist/agents/opencode-config.js +141 -86
- package/plugins/huaweicloud-core/dist/agents/opencode.js +106 -39
- package/plugins/huaweicloud-core/dist/approval-gate.js +1185 -0
- package/plugins/huaweicloud-core/dist/approval-ledger.js +2331 -0
- package/plugins/huaweicloud-core/dist/approval-roster.js +89 -0
- package/plugins/huaweicloud-core/dist/approval-types.js +1 -0
- package/plugins/huaweicloud-core/dist/approvals-cli.js +4 -4
- package/plugins/huaweicloud-core/dist/data/icons-manifest.v1.json +23 -5
- package/plugins/huaweicloud-core/dist/dep/receipts.js +65 -5
- package/plugins/huaweicloud-core/dist/explain-error.js +9 -1
- package/plugins/huaweicloud-core/dist/hcloud-cli.js +1 -1
- package/plugins/huaweicloud-core/dist/hcloud-plan.js +68 -62
- package/plugins/huaweicloud-core/dist/lib/approval-mode.js +7 -5
- package/plugins/huaweicloud-core/dist/lib/approval-tokens.js +18 -4
- package/plugins/huaweicloud-core/dist/lib/call-trace.js +7 -14
- package/plugins/huaweicloud-core/dist/lib/confirm-language.js +50 -0
- package/plugins/huaweicloud-core/dist/lib/credentials.js +9 -9
- package/plugins/huaweicloud-core/dist/lib/hdkit/hdkit-gate.js +1398 -0
- package/plugins/huaweicloud-core/dist/lib/hdkit/hdkitservice-api.js +371 -32
- package/plugins/huaweicloud-core/dist/lib/hdkit/sandbox-pool.js +6 -16
- package/plugins/huaweicloud-core/dist/lib/opencode-ask-rule.js +224 -78
- package/plugins/huaweicloud-core/dist/lib/opencode-saved-perms.js +282 -0
- package/plugins/huaweicloud-core/dist/lib/supplemental-redaction.js +116 -0
- package/plugins/huaweicloud-core/dist/lib/tool-schema-parts.js +31 -0
- package/plugins/huaweicloud-core/dist/lib/workspace-glob.js +442 -0
- package/plugins/huaweicloud-core/dist/mcp-config-io.js +28 -1
- package/plugins/huaweicloud-core/dist/mcp-protocol.js +68 -16
- package/plugins/huaweicloud-core/dist/mcp-server.js +6933 -1186
- package/plugins/huaweicloud-core/dist/mcp-server.js.map +4 -4
- package/plugins/huaweicloud-core/dist/mcp-stdio-transport.js +14 -4
- package/plugins/huaweicloud-core/dist/packs/auth/approval.js +249 -0
- package/plugins/huaweicloud-core/dist/packs/auth/tools.js +44 -44
- package/plugins/huaweicloud-core/dist/packs/huaweicloud-cli/tools.js +85 -130
- package/plugins/huaweicloud-core/dist/packs/obs/approval.js +110 -0
- package/plugins/huaweicloud-core/dist/packs/obs/tools.js +7 -2
- package/plugins/huaweicloud-core/dist/packs/registry.js +20 -1
- package/plugins/huaweicloud-core/dist/packs/sandbox/approval.js +245 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/expose-task.js +71 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-account.js +180 -23
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-credentials.js +13 -1
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-hwexec.js +136 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-session.js +11 -1
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-tunnel.js +29 -3
- package/plugins/huaweicloud-core/dist/packs/sandbox/schemas.js +93 -9
- package/plugins/huaweicloud-core/dist/packs/sandbox/tools.js +37 -10
- package/plugins/huaweicloud-core/dist/packs/secrets/approval.js +46 -0
- package/plugins/huaweicloud-core/dist/packs/secrets/tools.js +4 -1
- package/plugins/huaweicloud-core/dist/packs/update/approval.js +79 -0
- package/plugins/huaweicloud-core/dist/packs/update/tools.js +8 -1
- package/plugins/huaweicloud-core/dist/packs/voucher/tools.js +1 -1
- package/plugins/huaweicloud-core/dist/packs-configure.js +74 -0
- package/plugins/huaweicloud-core/dist/risk-rule-engine.js +20 -4
- package/plugins/huaweicloud-core/dist/safety/classify-hcloud.js +6 -6
- package/plugins/huaweicloud-core/dist/safety/classify-text.js +36 -0
- package/plugins/huaweicloud-core/dist/safety/policy.js +2 -0
- package/plugins/huaweicloud-core/dist/safety/redact.js +21 -3
- package/plugins/huaweicloud-core/dist/safety/risk-merge.js +24 -4
- package/plugins/huaweicloud-core/dist/sandbox/deploy-check.js +1 -1
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-auth.js +65 -14
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-cleanup.js +422 -0
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-expose-flow.js +66 -16
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-expose.js +13 -10
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-keepalive.js +42 -2
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-key.js +11 -3
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-tunnel.js +6 -0
- package/plugins/huaweicloud-core/dist/sandbox/devbridge-validation.js +10 -1
- package/plugins/huaweicloud-core/dist/sandbox/hwexec-task.js +244 -0
- package/plugins/huaweicloud-core/dist/setup-cli.js +36 -1
- package/plugins/huaweicloud-core/dist/tool-definitions.js +13 -1
- package/plugins/huaweicloud-core/dist/tool-schemas.js +32 -6
- package/plugins/huaweicloud-core/dist/tools.js +76 -9
- package/plugins/huaweicloud-core/dist/update-registry.js +358 -5
- package/plugins/huaweicloud-core/dist/update-upgrade.js +1083 -14
- package/plugins/huaweicloud-core/dist/vendor-gate.js +2 -2
- package/plugins/huaweicloud-core/hooks/huaweicloud-safety.mjs +150 -1
- package/plugins/huaweicloud-core/hooks/huaweicloud-safety.py +67 -4
- package/plugins/huaweicloud-core/openclaw.plugin.json +2 -2
- package/plugins/huaweicloud-core/safety/policy.json +18 -11
- package/plugins/huaweicloud-core/safety/rules/cloud-risk-rules.json +115 -11
- package/plugins/huaweicloud-core/skills/huawei-sandbox/SKILL.md +198 -143
- package/plugins/huaweicloud-core/skills/huawei-sandbox/references/resource-pool.md +36 -12
- package/plugins/huaweicloud-core/skills/huawei-voucher/SKILL.md +2 -0
- package/plugins/huaweicloud-core/skills/huaweicloud-cli-and-auth/SKILL.md +2 -2
- package/plugins/huaweicloud-core/skills/huaweicloud-safety/SKILL.md +11 -7
- package/plugins/huaweicloud-core/skills/huaweicloud-safety/references/approvals.md +74 -29
- package/plugins/huaweicloud-core/skills/huaweicloud-troubleshooting/SKILL.md +21 -19
- package/plugins/huaweicloud-core/src/agents/codex-config.ts +432 -0
- package/plugins/huaweicloud-core/src/agents/codex-desktop.ts +8 -1
- package/plugins/huaweicloud-core/src/agents/codex.ts +10 -0
- package/plugins/huaweicloud-core/src/agents/opencode-config.ts +176 -88
- package/plugins/huaweicloud-core/src/agents/opencode.ts +125 -54
- package/plugins/huaweicloud-core/src/approval-gate.ts +1306 -0
- package/plugins/huaweicloud-core/src/approval-ledger.ts +2446 -0
- package/plugins/huaweicloud-core/src/approval-roster.ts +127 -0
- package/plugins/huaweicloud-core/src/approval-types.ts +237 -0
- package/plugins/huaweicloud-core/src/approvals-cli.ts +4 -4
- package/plugins/huaweicloud-core/src/data/icons-manifest.v1.json +23 -5
- package/plugins/huaweicloud-core/src/dep/receipts.ts +84 -5
- package/plugins/huaweicloud-core/src/explain-error.ts +9 -1
- package/plugins/huaweicloud-core/src/hcloud-cli.ts +3 -0
- package/plugins/huaweicloud-core/src/hcloud-plan.ts +74 -71
- package/plugins/huaweicloud-core/src/lib/approval-mode.ts +7 -5
- package/plugins/huaweicloud-core/src/lib/approval-tokens.ts +19 -4
- package/plugins/huaweicloud-core/src/lib/call-trace.ts +7 -17
- package/plugins/huaweicloud-core/src/lib/confirm-language.ts +51 -0
- package/plugins/huaweicloud-core/src/lib/credentials.ts +9 -8
- package/plugins/huaweicloud-core/src/lib/hdkit/hdkit-gate.ts +1428 -0
- package/plugins/huaweicloud-core/src/lib/hdkit/hdkitservice-api.ts +408 -30
- package/plugins/huaweicloud-core/src/lib/hdkit/sandbox-pool.ts +8 -15
- package/plugins/huaweicloud-core/src/lib/opencode-ask-rule.ts +302 -83
- package/plugins/huaweicloud-core/src/lib/opencode-saved-perms.ts +354 -0
- package/plugins/huaweicloud-core/src/lib/supplemental-redaction.ts +129 -0
- package/plugins/huaweicloud-core/src/lib/tool-schema-parts.ts +40 -0
- package/plugins/huaweicloud-core/src/lib/workspace-glob.ts +414 -0
- package/plugins/huaweicloud-core/src/mcp-config-io.ts +27 -1
- package/plugins/huaweicloud-core/src/mcp-protocol.ts +81 -17
- package/plugins/huaweicloud-core/src/mcp-server.ts +7 -7
- package/plugins/huaweicloud-core/src/mcp-stdio-transport.ts +14 -4
- package/plugins/huaweicloud-core/src/packs/auth/approval.ts +302 -0
- package/plugins/huaweicloud-core/src/packs/auth/tools.ts +54 -45
- package/plugins/huaweicloud-core/src/packs/huaweicloud-cli/tools.ts +99 -137
- package/plugins/huaweicloud-core/src/packs/obs/approval.ts +122 -0
- package/plugins/huaweicloud-core/src/packs/obs/tools.ts +7 -2
- package/plugins/huaweicloud-core/src/packs/registry.ts +43 -1
- package/plugins/huaweicloud-core/src/packs/sandbox/approval.ts +296 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/expose-task.ts +105 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-account.ts +195 -23
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-credentials.ts +11 -1
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-hwexec.ts +228 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-session.ts +11 -1
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-tunnel.ts +41 -14
- package/plugins/huaweicloud-core/src/packs/sandbox/schemas.ts +120 -8
- package/plugins/huaweicloud-core/src/packs/sandbox/tools.ts +42 -9
- package/plugins/huaweicloud-core/src/packs/secrets/approval.ts +50 -0
- package/plugins/huaweicloud-core/src/packs/secrets/tools.ts +4 -1
- package/plugins/huaweicloud-core/src/packs/update/approval.ts +87 -0
- package/plugins/huaweicloud-core/src/packs/update/tools.ts +8 -1
- package/plugins/huaweicloud-core/src/packs/voucher/tools.ts +1 -1
- package/plugins/huaweicloud-core/src/packs-configure.ts +75 -0
- package/plugins/huaweicloud-core/src/risk-rule-engine.ts +20 -7
- package/plugins/huaweicloud-core/src/safety/classify-hcloud.ts +28 -16
- package/plugins/huaweicloud-core/src/safety/classify-text.ts +40 -0
- package/plugins/huaweicloud-core/src/safety/policy.ts +7 -0
- package/plugins/huaweicloud-core/src/safety/redact.ts +24 -6
- package/plugins/huaweicloud-core/src/safety/risk-merge.ts +26 -5
- package/plugins/huaweicloud-core/src/sandbox/deploy-check.ts +1 -1
- package/plugins/huaweicloud-core/src/sandbox/devbridge-auth.ts +74 -14
- package/plugins/huaweicloud-core/src/sandbox/devbridge-cleanup.ts +511 -0
- package/plugins/huaweicloud-core/src/sandbox/devbridge-expose-flow.ts +70 -18
- package/plugins/huaweicloud-core/src/sandbox/devbridge-expose.ts +26 -10
- package/plugins/huaweicloud-core/src/sandbox/devbridge-keepalive.ts +41 -2
- package/plugins/huaweicloud-core/src/sandbox/devbridge-key.ts +9 -3
- package/plugins/huaweicloud-core/src/sandbox/devbridge-tunnel.ts +24 -0
- package/plugins/huaweicloud-core/src/sandbox/devbridge-validation.ts +11 -1
- package/plugins/huaweicloud-core/src/sandbox/hwexec-task.ts +304 -0
- package/plugins/huaweicloud-core/src/setup-cli.ts +39 -1
- package/plugins/huaweicloud-core/src/tool-definitions.ts +13 -1
- package/plugins/huaweicloud-core/src/tool-schemas.ts +39 -6
- package/plugins/huaweicloud-core/src/tools.ts +124 -10
- package/plugins/huaweicloud-core/src/update-registry.ts +340 -5
- package/plugins/huaweicloud-core/src/update-upgrade.ts +1130 -14
- package/plugins/huaweicloud-core/src/vendor-gate.ts +2 -2
|
@@ -15,7 +15,7 @@ import { mergeCommandStyle, extractUserDelta, applyUserDelta } from "../mcp-conf
|
|
|
15
15
|
import { saveAgentDelta, takeAgentDelta } from "../mcp-config-backup.js";
|
|
16
16
|
import { readJsonRecord, writeMcpSettingsFile } from "../mcp-config-io.js";
|
|
17
17
|
import { applySkillTreePermissionSeam, opencodeSeamVersionSupported, removeSkillTreePermissionSeam, skillTreePermissionGlobs, } from "../lib/opencode-permission-seam.js";
|
|
18
|
-
import {
|
|
18
|
+
import { applyAllowPermissionRules, applyAllowPermissionRulesV1, askRuleShapeFor, removeAllowPermissionRules, removeAllowPermissionRulesV1, removeAskPermissionRules, removeAskPermissionRulesV1, } from "../lib/opencode-ask-rule.js";
|
|
19
19
|
import { asRecord } from "../lib/as-record.js";
|
|
20
20
|
import { devkitOwnedSkillNames, tryCoreSkillNames } from "../install-payload.js";
|
|
21
21
|
// The seam's version gate. HUAWEICLOUD_OPENCODE_PERMISSION_SEAM=on|off is
|
|
@@ -27,19 +27,26 @@ import { devkitOwnedSkillNames, tryCoreSkillNames } from "../install-payload.js"
|
|
|
27
27
|
// an older version may reject the keys outright. A later update heals the
|
|
28
28
|
// skip: the seam is a third change source in updateOpenCodeConfig, so an
|
|
29
29
|
// unchanged mcp config no longer short-circuits.
|
|
30
|
+
// Spawned at most once per process: the seam gate, the ask gate, and the
|
|
31
|
+
// ask-shape probe under the 'on' override all ask the same question, and
|
|
32
|
+
// a second spawn in one process can only return the same answer.
|
|
30
33
|
function probeOpencodeVersion() {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
return probedVersion === undefined ? (probedVersion = probeOpencodeVersionUncached()) : probedVersion;
|
|
35
|
+
}
|
|
36
|
+
let probedVersion;
|
|
37
|
+
// The probe runs the agent's own binary, which initializes its config
|
|
38
|
+
// root on every run — so the probe must pin that root to a throwaway
|
|
39
|
+
// mkdtemp directory instead of inheriting the caller's XDG/HOME: a
|
|
40
|
+
// relative XDG_CONFIG_HOME makes opencode materialize dirs against its
|
|
41
|
+
// cwd (the known 1.19.0 divergence cross-platform-install.test.ts
|
|
42
|
+
// pins), and an inherited HOME would create legacy ~/.config/opencode
|
|
43
|
+
// roots in fake-home installs. A fixed shared name would be clippable
|
|
44
|
+
// on multi-user machines, so the root is per-run and best-effort
|
|
45
|
+
// cleaned. The version string never depends on the config root. The
|
|
46
|
+
// win32 retries cover npm-global .cmd shims (spawn cannot execute them
|
|
47
|
+
// without a shell — the hasCodexCLI precedent; the shell string is a
|
|
48
|
+
// fixed literal, no interpolation surface).
|
|
49
|
+
function probeOpencodeVersionUncached() {
|
|
43
50
|
let probeRoot;
|
|
44
51
|
try {
|
|
45
52
|
probeRoot = mkdtempSync(join(tmpdir(), 'devkit-opencode-probe-'));
|
|
@@ -88,40 +95,31 @@ export function openCodeSeamGate() {
|
|
|
88
95
|
return forced;
|
|
89
96
|
return opencodeSeamVersionSupported(probeOpencodeVersion()) ? 'on' : 'off';
|
|
90
97
|
}
|
|
91
|
-
// The ask rule's version gate, same doctrine as the seam's:
|
|
92
|
-
// HUAWEICLOUD_OPENCODE_ASK_RULE=on|off is the deterministic override for
|
|
93
|
-
// the installer test suite (e2e strips it — the runner's install relies on
|
|
94
|
-
// the natural probe); unset runs the probe. Unknown polarity is off: the
|
|
95
|
-
// `permissions` array is the V2 shape measured on 2.2.7 only, so a
|
|
96
|
-
// below-2.0, absent, or unparsable opencode writes NEITHER half of the
|
|
97
|
-
// posture — the client rule without the server env double-gates, the env
|
|
98
|
-
// without the rule fail-opens, and the pair must move together.
|
|
99
98
|
export function openCodeAskGate() {
|
|
100
99
|
const forced = process.env.HUAWEICLOUD_OPENCODE_ASK_RULE;
|
|
101
|
-
if (forced === '
|
|
102
|
-
return
|
|
103
|
-
|
|
100
|
+
if (forced === 'off')
|
|
101
|
+
return 'off';
|
|
102
|
+
if (forced === 'v2')
|
|
103
|
+
return 'v2-array';
|
|
104
|
+
if (forced === 'v1')
|
|
105
|
+
return 'v1-object';
|
|
106
|
+
const shape = askRuleShapeFor(probeOpencodeVersion());
|
|
107
|
+
if (shape !== 'unsupported')
|
|
108
|
+
return shape;
|
|
109
|
+
return forced === 'on' ? 'v2-array' : 'off';
|
|
104
110
|
}
|
|
105
|
-
// The server half of the ask posture: DEVKIT_APPROVAL_MODE=ask in the mcp
|
|
106
|
-
// entry's environment (the field OpenCode reads — the applyPacksToEntry
|
|
107
|
-
// 'environment' precedent). Add-only-if-absent with the packs-write
|
|
108
|
-
// doctrine: a user-set value other than 'ask' is theirs and wins with a
|
|
109
|
-
// one-line WARN; 'ask' already present needs no write. An absent or empty
|
|
110
|
-
// environment object is created. No delete path: uninstall removes the
|
|
111
|
-
// whole mcp entry wholesale. Runs ONLY under the ask gate — see
|
|
112
|
-
// openCodeAskGate for why the halves must move together.
|
|
113
111
|
function applyApprovalModeToEntry(entry) {
|
|
114
112
|
const env = asRecord(entry.environment);
|
|
115
113
|
const current = env.DEVKIT_APPROVAL_MODE;
|
|
116
114
|
if (current === 'ask')
|
|
117
|
-
return
|
|
115
|
+
return 'present';
|
|
118
116
|
if (current !== undefined) {
|
|
119
117
|
const shown = typeof current === 'string' ? current : JSON.stringify(current);
|
|
120
|
-
console.log(` \x1b[33m[WARN]\x1b[0m OpenCode mcp entry already sets DEVKIT_APPROVAL_MODE=${shown} — keeping the user's value
|
|
121
|
-
return
|
|
118
|
+
console.log(` \x1b[33m[WARN]\x1b[0m OpenCode mcp entry already sets DEVKIT_APPROVAL_MODE=${shown} — keeping the user's value, so no client allow rules are kept (devkit-written ones are removed; see README, Harness permission notes).`);
|
|
119
|
+
return 'user';
|
|
122
120
|
}
|
|
123
121
|
entry.environment = { ...env, DEVKIT_APPROVAL_MODE: 'ask' };
|
|
124
|
-
return
|
|
122
|
+
return 'established';
|
|
125
123
|
}
|
|
126
124
|
// The glob set the seam covers: the plugin-dir tree actually deployed by
|
|
127
125
|
// this run plus per-skill globs for the native core meta-skill copies
|
|
@@ -165,58 +163,107 @@ export function updateOpenCodeConfig(pluginDir) {
|
|
|
165
163
|
else {
|
|
166
164
|
console.log(' \x1b[33m[INFO]\x1b[0m opencode not verifiably at or above the measured permission floor — skipping the skills-tree permission write; see README (Harness permission notes) if direct skill reads prompt for approval.');
|
|
167
165
|
}
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
//
|
|
171
|
-
//
|
|
172
|
-
//
|
|
173
|
-
//
|
|
174
|
-
//
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
166
|
+
const askGate = openCodeAskGate();
|
|
167
|
+
const askOn = askGate !== 'off';
|
|
168
|
+
// The posture migration runs on EVERY path that touches the config, gate or
|
|
169
|
+
// no gate: the abandoned ask rules from any earlier install are removed
|
|
170
|
+
// value-exact in both generations, so the old posture never survives an
|
|
171
|
+
// install or update. Both shapes are attempted independently (a config can
|
|
172
|
+
// carry both, and the first removal must not short-circuit the second).
|
|
173
|
+
const migratedV2 = removeAskPermissionRules(config);
|
|
174
|
+
const migratedV1 = removeAskPermissionRulesV1(config);
|
|
175
|
+
const migrated = migratedV2 || migratedV1;
|
|
176
|
+
// The mcp entry's server half is resolved BEFORE the client rules: the
|
|
177
|
+
// allow set is written only when the server gate is established this run or
|
|
178
|
+
// already present, and a user-set mode value wins with no client rules.
|
|
179
|
+
const existing = asRecord(config.mcp)['huaweicloud-devkit'];
|
|
180
|
+
let entry;
|
|
181
|
+
let entryChanged = false;
|
|
182
|
+
let rebuilt = false;
|
|
183
|
+
let approvalMode = 'off';
|
|
184
|
+
if (existing) {
|
|
185
|
+
const merged = mergeCommandStyle(existing, { mcpPath });
|
|
186
|
+
entry = merged.entry;
|
|
187
|
+
entryChanged = merged.changed;
|
|
188
|
+
if (applyPacksToEntry(entry, 'environment', 'OpenCode'))
|
|
189
|
+
entryChanged = true;
|
|
190
|
+
if (askOn) {
|
|
191
|
+
approvalMode = applyApprovalModeToEntry(entry);
|
|
192
|
+
if (approvalMode === 'established')
|
|
193
|
+
entryChanged = true;
|
|
181
194
|
}
|
|
182
195
|
}
|
|
183
196
|
else {
|
|
184
|
-
|
|
197
|
+
entry = mergeCommandStyle(undefined, { mcpPath }).entry;
|
|
198
|
+
// Restore user fields saved by a previous uninstall (issue #615) before the
|
|
199
|
+
// packs write so a delta-carried DEVKIT_PACKS counts as the current value.
|
|
200
|
+
const delta = takeAgentDelta('opencode');
|
|
201
|
+
if (delta)
|
|
202
|
+
entry = asRecord(applyUserDelta(entry, delta, 'command'));
|
|
203
|
+
applyPacksToEntry(entry, 'environment', 'OpenCode');
|
|
204
|
+
if (askOn)
|
|
205
|
+
approvalMode = applyApprovalModeToEntry(entry);
|
|
206
|
+
rebuilt = true;
|
|
185
207
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
208
|
+
// The client half — one exact allow rule per roster tool, no wildcard. Its
|
|
209
|
+
// SHAPE rides the probed generation: the V2 permissions array on 2.0+, the
|
|
210
|
+
// V1 permission object on 1.19–1.x (the roster action is byte-identical
|
|
211
|
+
// across shapes, and the mcp env half is shared). It is a FOURTH change
|
|
212
|
+
// source, computed before the unchanged short-circuit for the same reason
|
|
213
|
+
// as the seam: an unchanged mcp entry is the dominant update shape, and
|
|
214
|
+
// every install made before the posture existed is the population this
|
|
215
|
+
// must heal.
|
|
216
|
+
let clientChanged = false;
|
|
217
|
+
let clientRemoved = false;
|
|
218
|
+
if (askOn && approvalMode === 'user') {
|
|
219
|
+
// The server half left the pair (the user's own mode value governs the
|
|
220
|
+
// posture), so the client half leaves with it: any allow rules a past
|
|
221
|
+
// install wrote are removed value-exact, both shapes independently (a
|
|
222
|
+
// config can carry both). Without this, the doctor's mixed-state WARN
|
|
223
|
+
// could never heal — re-running install would reproduce it forever.
|
|
224
|
+
// After the removal the user's posture (token mode) is fully mechanical.
|
|
225
|
+
const removedV2 = removeAllowPermissionRules(config);
|
|
226
|
+
const removedV1 = removeAllowPermissionRulesV1(config);
|
|
227
|
+
clientRemoved = removedV2 || removedV1;
|
|
228
|
+
}
|
|
229
|
+
else if (askOn) {
|
|
230
|
+
const applied = askGate === 'v1-object' ? applyAllowPermissionRulesV1(config) : applyAllowPermissionRules(config);
|
|
231
|
+
clientChanged = applied.changed;
|
|
232
|
+
for (const action of applied.skipped) {
|
|
233
|
+
console.log(askGate === 'v1-object'
|
|
234
|
+
? ` \x1b[33m[WARN]\x1b[0m opencode permission already has the ${action} key — keeping it as the user's, so no allow rule is written for it (see README, Harness permission notes).`
|
|
235
|
+
: ` \x1b[33m[WARN]\x1b[0m opencode permissions already has an entry for ${action} — keeping it as the user's, so no allow rule is written for it (see README, Harness permission notes).`);
|
|
194
236
|
}
|
|
237
|
+
if (applied.shapeUnreadable) {
|
|
238
|
+
console.log(askGate === 'v1-object'
|
|
239
|
+
? ` \x1b[33m[WARN]\x1b[0m opencode permission is not object-shaped — keeping the user's global posture; add the client allow rules manually (see README, Harness permission notes).`
|
|
240
|
+
: ` \x1b[33m[WARN]\x1b[0m opencode permissions is not array-shaped — keeping the user's value; add the client allow rules manually (see README, Harness permission notes).`);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
else if (!askOn) {
|
|
244
|
+
console.log(' \x1b[33m[INFO]\x1b[0m opencode not verifiably at or above 1.19.0 — keeping the terminal token approval gate; no client allow rules or DEVKIT_APPROVAL_MODE is written.');
|
|
245
|
+
}
|
|
246
|
+
if (rebuilt || entryChanged) {
|
|
195
247
|
const mcpMap = asRecord(config.mcp);
|
|
196
248
|
mcpMap['huaweicloud-devkit'] = entry;
|
|
197
249
|
config.mcp = mcpMap;
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
console.log(` ASK approval (permissions ask rule + DEVKIT_APPROVAL_MODE) -> ${configPath}`);
|
|
202
|
-
}
|
|
250
|
+
}
|
|
251
|
+
if (!rebuilt && !entryChanged && !permChanged && !clientChanged && !migrated && !clientRemoved) {
|
|
252
|
+
console.log(` OpenCode MCP config unchanged: ${configPath}`);
|
|
203
253
|
return;
|
|
204
254
|
}
|
|
205
|
-
const mcpMap = asRecord(config.mcp);
|
|
206
|
-
let entry = mergeCommandStyle(undefined, { mcpPath }).entry;
|
|
207
|
-
// Restore user fields saved by a previous uninstall (issue #615) before the
|
|
208
|
-
// packs write so a delta-carried DEVKIT_PACKS counts as the current value.
|
|
209
|
-
const delta = takeAgentDelta('opencode');
|
|
210
|
-
if (delta)
|
|
211
|
-
entry = asRecord(applyUserDelta(entry, delta, 'command'));
|
|
212
|
-
applyPacksToEntry(entry, 'environment', 'OpenCode');
|
|
213
|
-
const askEnvChanged = askOn && applyApprovalModeToEntry(entry);
|
|
214
|
-
mcpMap['huaweicloud-devkit'] = entry;
|
|
215
|
-
config.mcp = mcpMap;
|
|
216
255
|
writeMcpSettingsFile(configPath, config);
|
|
217
|
-
console.log(
|
|
218
|
-
|
|
219
|
-
|
|
256
|
+
console.log(rebuilt
|
|
257
|
+
? ` OpenCode config updated: ${configPath}`
|
|
258
|
+
: ` OpenCode MCP config merged (user fields preserved): ${configPath}`);
|
|
259
|
+
if (migrated) {
|
|
260
|
+
console.log(` ASK posture migrated (legacy ask rules removed) -> ${configPath}`);
|
|
261
|
+
}
|
|
262
|
+
if (clientRemoved) {
|
|
263
|
+
console.log(` ASK client allow rules removed (DEVKIT_APPROVAL_MODE is the user's own) -> ${configPath}`);
|
|
264
|
+
}
|
|
265
|
+
if (clientChanged) {
|
|
266
|
+
console.log(` ASK approval (client allow rules + DEVKIT_APPROVAL_MODE server gate) -> ${configPath}`);
|
|
220
267
|
}
|
|
221
268
|
}
|
|
222
269
|
export function removeOpenCodeConfig() {
|
|
@@ -244,20 +291,28 @@ export function removeOpenCodeConfig() {
|
|
|
244
291
|
// value-exact deletion keeps user-modified rules (the ownership contract
|
|
245
292
|
// lives in lib/opencode-permission-seam.ts).
|
|
246
293
|
const permCleaned = removeSkillTreePermissionSeam(config, openCodeSeamGlobs(opencodePluginsDir()));
|
|
247
|
-
// The
|
|
294
|
+
// The client-rule cleanup also runs unconditionally of the version gate: an
|
|
248
295
|
// uninstall must remove what any past install wrote — the opencode that
|
|
249
|
-
// gated the write may since have been upgraded, downgraded, or removed
|
|
250
|
-
//
|
|
251
|
-
//
|
|
252
|
-
//
|
|
253
|
-
|
|
254
|
-
|
|
296
|
+
// gated the write may since have been upgraded, downgraded, or removed from
|
|
297
|
+
// PATH, and the rule's shape rode the generation that was current then. All
|
|
298
|
+
// four shape/effect pairs are attempted independently (a config can carry
|
|
299
|
+
// both generations, and the legacy ask rules as well as the allow set), each
|
|
300
|
+
// value-exact so a user-modified rule survives — the ownership contract
|
|
301
|
+
// lives in lib/opencode-ask-rule.ts. The mcp entry (and its
|
|
302
|
+
// DEVKIT_APPROVAL_MODE env) is already gone wholesale above.
|
|
303
|
+
const allowCleanedV2 = removeAllowPermissionRules(config);
|
|
304
|
+
const allowCleanedV1 = removeAllowPermissionRulesV1(config);
|
|
305
|
+
const askCleanedV2 = removeAskPermissionRules(config);
|
|
306
|
+
const askCleanedV1 = removeAskPermissionRulesV1(config);
|
|
307
|
+
const allowCleaned = allowCleanedV2 || allowCleanedV1;
|
|
308
|
+
const askCleaned = askCleanedV2 || askCleanedV1;
|
|
309
|
+
if (!hadEntry && !permCleaned && !allowCleaned && !askCleaned)
|
|
255
310
|
return;
|
|
256
311
|
writeMcpSettingsFile(configPath, config);
|
|
257
312
|
if (hadEntry)
|
|
258
313
|
console.log(` OpenCode MCP config cleaned: ${configPath}`);
|
|
259
314
|
if (permCleaned)
|
|
260
315
|
console.log(` Skills-tree permission rules removed: ${configPath}`);
|
|
261
|
-
if (askCleaned)
|
|
262
|
-
console.log(` ASK permission
|
|
316
|
+
if (allowCleaned || askCleaned)
|
|
317
|
+
console.log(` ASK client permission rules removed: ${configPath}`);
|
|
263
318
|
}
|
|
@@ -10,7 +10,8 @@ import { configRoot, opencodeCommandsDir, opencodeConfigFile, opencodePluginsDir
|
|
|
10
10
|
import { printMcpConfigStatus } from "../mcp-config-io.js";
|
|
11
11
|
import { PACKAGE_ROOT, copyDir, copyServerPayload, deployWord, installRuntimeDeps, payloadStatusLines, pruneStale, removeHuaweiCommandsFrom, removeIfExists, } from "../install-payload.js";
|
|
12
12
|
import { removeOpenCodeConfig, updateOpenCodeConfig, openCodeSeamGate, openCodeSeamGlobs, openCodeAskGate, } from "./opencode-config.js";
|
|
13
|
-
import {
|
|
13
|
+
import { readPermissionRules, readPermissionRulesV1 } from "../lib/opencode-ask-rule.js";
|
|
14
|
+
import { scanSavedAllowRows } from "../lib/opencode-saved-perms.js";
|
|
14
15
|
import { asRecord } from "../lib/as-record.js";
|
|
15
16
|
// Doctor: the OpenCode MCP-configured candidate — the opencode config's
|
|
16
17
|
// mcp.huaweicloud-devkit entry.
|
|
@@ -29,22 +30,37 @@ export function opencodeDoctorMcpConfigured() {
|
|
|
29
30
|
return null;
|
|
30
31
|
}
|
|
31
32
|
// Doctor: the ASK approval posture check — OpenCode installs only. The
|
|
32
|
-
// posture is a PAIR: the client half (
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
//
|
|
33
|
+
// posture is a PAIR the installer writes together: the client half (one exact
|
|
34
|
+
// allow rule per roster tool — a `permissions` array entry on 2.0+, a
|
|
35
|
+
// `permission` object key on 1.19–1.x, both naming the same actions) and the
|
|
36
|
+
// server half (DEVKIT_APPROVAL_MODE=ask in the mcp entry's env). Ask mode now
|
|
37
|
+
// means the SERVER-RUN gate: the confirmation is raised inside the tool call
|
|
38
|
+
// (elicitation form, or the T3 chat round-trip), so the client rules are
|
|
39
|
+
// yield-only — they suppress the redundant client popup — and a client allow
|
|
40
|
+
// rule can no longer fail anything open. The directions that survive the flip:
|
|
41
|
+
// - a deny rule bricks the call in the client, so it stays a FAIL;
|
|
42
|
+
// - a devkit-written ask rule is migration residue: FAIL, re-run install;
|
|
43
|
+
// - missing client coverage while the server gate is on is drift: FAIL;
|
|
44
|
+
// - allow rules without the server gate are the mixed state: WARN;
|
|
45
|
+
// - an unreadable shape with the gate on is a WARN, never silent (the
|
|
46
|
+
// verification's B2 invariant — the gate still holds server-side, so a
|
|
47
|
+
// WARN is honest, not a FAIL);
|
|
48
|
+
// - a user-owned rule on a roster action is surfaced by name with the skip
|
|
49
|
+
// recorded, never silently dropped.
|
|
50
|
+
// A gate-off opencode is a SKIP — token mode is that install's legitimate
|
|
51
|
+
// posture, and the migration still removes the legacy ask rules.
|
|
43
52
|
export function opencodeDoctorAskRule(ctx) {
|
|
44
|
-
|
|
45
|
-
|
|
53
|
+
const gate = openCodeAskGate();
|
|
54
|
+
if (gate === 'off') {
|
|
55
|
+
ctx.skip('ASK approval posture (opencode not verifiably at or above 1.19.0)');
|
|
46
56
|
return;
|
|
47
57
|
}
|
|
58
|
+
askPostureCheck(ctx, gate);
|
|
59
|
+
savedAllowStoreCheck(ctx);
|
|
60
|
+
}
|
|
61
|
+
const ASK_POSTURE_LABEL = 'ASK approval posture (client allow rules + server gate)';
|
|
62
|
+
function askPostureCheck(ctx, gate) {
|
|
63
|
+
const v1 = gate === 'v1-object';
|
|
48
64
|
let cfg;
|
|
49
65
|
try {
|
|
50
66
|
cfg = asRecord(JSON.parse(readFileSync(opencodeConfigFile(), 'utf8')));
|
|
@@ -52,41 +68,92 @@ export function opencodeDoctorAskRule(ctx) {
|
|
|
52
68
|
catch {
|
|
53
69
|
cfg = null;
|
|
54
70
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
ctx.skip('ASK approval posture: opencode config unreadable or permissions not array-shaped — the installer keeps it untouched; add the ask rule and DEVKIT_APPROVAL_MODE manually (see README, Harness permission notes)');
|
|
71
|
+
if (cfg === null) {
|
|
72
|
+
ctx.warn(`${ASK_POSTURE_LABEL}: the opencode config is unreadable, so the client half cannot be verified — the server gate still confirms every roster call; fix the file and re-run: npx huaweicloud-devkit install --target opencode`);
|
|
58
73
|
return;
|
|
59
74
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const envAsk = env.DEVKIT_APPROVAL_MODE === 'ask';
|
|
64
|
-
const label = 'ASK approval posture (client prompt + server env)';
|
|
65
|
-
if (posture === 'ask') {
|
|
66
|
-
ctx.check(label, envAsk, envAsk
|
|
67
|
-
? ''
|
|
68
|
-
: 'DEVKIT_APPROVAL_MODE=ask missing from the mcp entry — the client prompts AND the server still demands a token (re-run: npx huaweicloud-devkit install --target opencode)');
|
|
75
|
+
const reading = v1 ? readPermissionRulesV1(cfg) : readPermissionRules(cfg);
|
|
76
|
+
if (reading.sectionUnreadable) {
|
|
77
|
+
ctx.warn(`${ASK_POSTURE_LABEL}: opencode ${v1 ? 'permission is not object-shaped' : 'permissions is not array-shaped'}, so the client half cannot be verified — the server gate still confirms every roster call; fix the shape and re-run: npx huaweicloud-devkit install --target opencode`);
|
|
69
78
|
return;
|
|
70
79
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
80
|
+
// The mcp entry carries the server half; a missing entry counts as no env.
|
|
81
|
+
const env = asRecord(asRecord(asRecord(cfg.mcp)['huaweicloud-devkit']).environment);
|
|
82
|
+
const gateOn = env.DEVKIT_APPROVAL_MODE === 'ask';
|
|
83
|
+
const actionsIn = (state) => reading.rules.filter((rule) => rule.state === state).map((rule) => rule.action);
|
|
84
|
+
const allow = actionsIn('allow');
|
|
85
|
+
const absent = actionsIn('absent');
|
|
86
|
+
const deny = actionsIn('deny');
|
|
87
|
+
const foreign = actionsIn('foreign');
|
|
88
|
+
const userOther = actionsIn('user-other');
|
|
89
|
+
const residue = reading.rules.filter((rule) => rule.askResidue).map((rule) => rule.action);
|
|
90
|
+
// Token mode with no client rules at all is the legitimate default posture.
|
|
91
|
+
if (!gateOn && absent.length === reading.rules.length) {
|
|
92
|
+
ctx.check('ASK approval posture (token mode)', true, '');
|
|
77
93
|
return;
|
|
78
94
|
}
|
|
79
|
-
|
|
80
|
-
|
|
95
|
+
const fails = [];
|
|
96
|
+
const warns = [];
|
|
97
|
+
if (deny.length > 0) {
|
|
98
|
+
fails.push(v1
|
|
99
|
+
? `the permission value on ${deny.join(', ')} is "deny" — the write tool is blocked outright in the client; delete that key`
|
|
100
|
+
: `a permissions rule on ${deny.join(', ')} is "deny" — the write tool is blocked outright in the client; delete that rule`);
|
|
101
|
+
}
|
|
102
|
+
if (residue.length > 0) {
|
|
103
|
+
fails.push(`the devkit-written ask ${v1 ? 'value' : 'rule'} is still present on ${residue.join(', ')} — the posture migration missed it (re-run: npx huaweicloud-devkit install --target opencode)`);
|
|
104
|
+
}
|
|
105
|
+
if (gateOn && absent.length > 0) {
|
|
106
|
+
fails.push(`the client allow ${v1 ? 'value' : 'rule'} is missing on ${absent.join(', ')} while DEVKIT_APPROVAL_MODE=ask is set — the pair has drifted from what this installer writes (re-run: npx huaweicloud-devkit install --target opencode)`);
|
|
107
|
+
}
|
|
108
|
+
if (!gateOn && allow.length > 0) {
|
|
109
|
+
warns.push(`client allow ${v1 ? 'values' : 'rules'} on ${allow.join(', ')} are present but DEVKIT_APPROVAL_MODE=ask is missing from the mcp entry — the mixed state suppresses the client prompt while the server runs the token gate (re-run: npx huaweicloud-devkit install --target opencode)`);
|
|
110
|
+
}
|
|
111
|
+
if (userOther.length > 0) {
|
|
112
|
+
warns.push(`a user-owned ${v1 ? 'permission value' : 'rule'} on ${userOther.join(', ')} covers a different resource, so the installer keeps it (skip recorded) and no exact "*" allow rule is written there (see README, Harness permission notes)`);
|
|
113
|
+
}
|
|
114
|
+
if (foreign.length > 0) {
|
|
115
|
+
warns.push(`the ${v1 ? 'permission value' : 'permissions rule'} on ${foreign.join(', ')} is not a readable effect, so the client half cannot be verified there`);
|
|
116
|
+
}
|
|
117
|
+
if (fails.length > 0) {
|
|
118
|
+
ctx.check(ASK_POSTURE_LABEL, false, [...fails, ...warns].join(' '));
|
|
119
|
+
}
|
|
120
|
+
else if (warns.length > 0) {
|
|
121
|
+
ctx.warn(`${ASK_POSTURE_LABEL}: ${warns.join(' ')}`);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
ctx.check(ASK_POSTURE_LABEL, true, '');
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Doctor: the opencode saved-permission store, the client-side twin of the
|
|
128
|
+
// ask rule. One "Always allow" click on the client prompt persists an allow
|
|
129
|
+
// row that opencode evaluates AFTER the configured rules (findLast), so it
|
|
130
|
+
// silently converts every future call on the action into an unprompted
|
|
131
|
+
// execution of opencode's own permission layer. That no longer gates anything
|
|
132
|
+
// the devkit relies on: the confirmation runs on the server (the gate raises
|
|
133
|
+
// the form, or the T3 chat round-trip), inside the tool call and outside
|
|
134
|
+
// opencode's evaluation. The row is therefore a stale grant, reported as a
|
|
135
|
+
// WARN with the probe-measured removal commands, not a failing gate. Zero rows
|
|
136
|
+
// prints nothing at all (the healthy fresh state), so a clean install's
|
|
137
|
+
// doctor output stays byte-identical.
|
|
138
|
+
function savedAllowStoreCheck(ctx) {
|
|
139
|
+
const scan = scanSavedAllowRows({ scope: 'all' });
|
|
140
|
+
if (scan.status === 'absent')
|
|
141
|
+
return;
|
|
142
|
+
if (scan.status === 'unreadable') {
|
|
143
|
+
ctx.warn(`ASK approval hygiene: opencode saved-permission store unreadable (${scan.dbPath}): ${scan.detail} — saved "always allow" rows cannot be listed`);
|
|
81
144
|
return;
|
|
82
145
|
}
|
|
83
|
-
if (
|
|
84
|
-
// posture === 'absent': the fail-open direction.
|
|
85
|
-
ctx.check(label, false, 'DEVKIT_APPROVAL_MODE=ask is set but the permissions ask rule is missing — the server trusts a client prompt nobody shows (re-run: npx huaweicloud-devkit install --target opencode, or unset DEVKIT_APPROVAL_MODE in the mcp entry)');
|
|
146
|
+
if (scan.rows.length === 0)
|
|
86
147
|
return;
|
|
148
|
+
// WARN, not FAIL (PR-1.5 demotion): the confirmation runs server-side, so a
|
|
149
|
+
// saved client-side allow row can no longer suppress it (the form is raised
|
|
150
|
+
// inside the tool call and never routes through opencode's permission
|
|
151
|
+
// evaluation). The row is a stale grant worth cleaning up, not a gate.
|
|
152
|
+
const actions = [...new Set(scan.rows.map((row) => row.action))].join(', ');
|
|
153
|
+
ctx.warn(`ASK approval hygiene: opencode's permission store holds a saved "always allow" rule for ${actions} — the server-run confirmation ignores it, so calls are not fail-open; the row is still a stale grant. List them: opencode api GET /api/permission/saved. Remove one: opencode api DELETE /api/permission/saved/<id>. It lives in ${scan.dbPath}, table "permission".`);
|
|
154
|
+
for (const row of scan.rows) {
|
|
155
|
+
ctx.raw(` ${row.id} → ${row.projectWorktree ?? row.projectId} (action ${row.action})`);
|
|
87
156
|
}
|
|
88
|
-
// Token mode is the legitimate default posture, not an error.
|
|
89
|
-
ctx.check('ASK approval posture (token mode)', true, '');
|
|
90
157
|
}
|
|
91
158
|
// Doctor: the skills-tree permission seam check — OpenCode installs only
|
|
92
159
|
// (the seam is the installer's zero-prompt path for direct skill reads on
|