huaweicloud-devkit 2.0.0-next.2 → 2.0.0-next.4
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 +16 -3
- package/plugins/huaweicloud-core/.codex-plugin/plugin.json +16 -3
- package/plugins/huaweicloud-core/.cursor-plugin/plugin.json +16 -3
- package/plugins/huaweicloud-core/.hermes-plugin/plugin.json +16 -3
- package/plugins/huaweicloud-core/.mcp.json +55 -1
- package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +16 -3
- 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 +157 -31
- package/plugins/huaweicloud-core/dist/agents/opencode.js +129 -1
- 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/hcloud-cli.js +1 -1
- package/plugins/huaweicloud-core/dist/hcloud-plan.js +77 -56
- package/plugins/huaweicloud-core/dist/lib/approval-mode.js +32 -0
- 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 +362 -32
- package/plugins/huaweicloud-core/dist/lib/hdkit/sandbox-pool.js +6 -16
- package/plugins/huaweicloud-core/dist/lib/opencode-ask-rule.js +262 -0
- 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 +75 -4
- package/plugins/huaweicloud-core/dist/mcp-server.js +6560 -898
- 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 +119 -112
- 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 +19 -1
- package/plugins/huaweicloud-core/dist/packs/sandbox/approval.js +245 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-account.js +156 -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 +1 -0
- package/plugins/huaweicloud-core/dist/packs/sandbox/schemas.js +79 -9
- package/plugins/huaweicloud-core/dist/packs/sandbox/tools.js +28 -9
- 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/safety/classify-text.js +36 -0
- package/plugins/huaweicloud-core/dist/safety/policy.js +2 -0
- 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 +42 -4
- package/plugins/huaweicloud-core/dist/tool-definitions.js +9 -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 +53 -3
- package/plugins/huaweicloud-core/openclaw.plugin.json +1 -1
- package/plugins/huaweicloud-core/safety/policy.json +18 -11
- package/plugins/huaweicloud-core/safety/rules/cloud-risk-rules.json +114 -10
- package/plugins/huaweicloud-core/skills/huawei-sandbox/SKILL.md +190 -138
- 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 +5 -5
- package/plugins/huaweicloud-core/skills/huaweicloud-safety/SKILL.md +13 -8
- package/plugins/huaweicloud-core/skills/huaweicloud-safety/references/approvals.md +78 -23
- 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 +198 -30
- package/plugins/huaweicloud-core/src/agents/opencode.ts +157 -1
- 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/hcloud-cli.ts +3 -0
- package/plugins/huaweicloud-core/src/hcloud-plan.ts +93 -63
- package/plugins/huaweicloud-core/src/lib/approval-mode.ts +34 -0
- 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 +377 -30
- package/plugins/huaweicloud-core/src/lib/hdkit/sandbox-pool.ts +8 -15
- package/plugins/huaweicloud-core/src/lib/opencode-ask-rule.ts +350 -0
- 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 +88 -5
- package/plugins/huaweicloud-core/src/mcp-server.ts +13 -0
- 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 +139 -120
- 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 +42 -1
- package/plugins/huaweicloud-core/src/packs/sandbox/approval.ts +296 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/handlers-account.ts +168 -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 +1 -0
- package/plugins/huaweicloud-core/src/packs/sandbox/schemas.ts +100 -8
- package/plugins/huaweicloud-core/src/packs/sandbox/tools.ts +31 -8
- 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/safety/classify-text.ts +40 -0
- package/plugins/huaweicloud-core/src/safety/policy.ts +7 -0
- 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 +509 -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 +45 -3
- package/plugins/huaweicloud-core/src/tool-definitions.ts +9 -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
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
// The codex client approval yield: per-tool `approval_mode` config for the
|
|
2
|
+
// devkit's MCP server — the codex half of the approval-chain yield (PR-5).
|
|
3
|
+
//
|
|
4
|
+
// Under codex's default approvalPolicy ("on-request") codex fires its OWN
|
|
5
|
+
// approval gate ahead of every MCP tool call, so a roster call is a double
|
|
6
|
+
// interaction: the codex dialog first, the devkit server's confirmation
|
|
7
|
+
// second (measured on codex-cli 0.167.2, probe home
|
|
8
|
+
// /tmp/opencode/probe-non-elicit-dlg — the same geometry PR-2 removed on
|
|
9
|
+
// opencode). The yield is the per-tool value the codex config understands,
|
|
10
|
+
// measured live on the same build: `approve` runs the call straight through
|
|
11
|
+
// with no codex dialog, so the devkit's own confirmation is the single
|
|
12
|
+
// surface. `prompt` shows an Allow/Cancel dialog with the tool name and up
|
|
13
|
+
// to 3 truncated argument lines (no persistence options); `auto` keeps
|
|
14
|
+
// codex's 4-option gate with persistence options. Neither fails anything
|
|
15
|
+
// open — the server gate confirms every roster call regardless of the
|
|
16
|
+
// client value — so the doctor treats every non-approve value as a WARN
|
|
17
|
+
// naming its direction, never a FAIL: a wrong value degrades UX (double
|
|
18
|
+
// interaction) or fails closed, and WARN is the honest ceiling. `prompt` is
|
|
19
|
+
// the taught fallback for the policy-off branch only, never a written value.
|
|
20
|
+
//
|
|
21
|
+
// WHERE the yield lives, settled by live measurement against codex 0.167.2
|
|
22
|
+
// plus the upstream source (core mcp_tool_call.rs,
|
|
23
|
+
// resolve_user_configured_approval_mode): codex reads per-tool
|
|
24
|
+
// approval_mode from TWO places, in order — the config layer stack's
|
|
25
|
+
// mcp_servers.<server>.tools.<tool> (the user's config.toml), then the
|
|
26
|
+
// PLUGIN-provided server definition (plugin.mcp_servers.<server>.tools.<tool>).
|
|
27
|
+
// The devkit server is plugin-provided on every current install (the CLI
|
|
28
|
+
// marketplace flow copies plugins/huaweicloud-core — including .mcp.json —
|
|
29
|
+
// into codex's cache; Codex Desktop reads the plugin dir), so the yield
|
|
30
|
+
// belongs in the devkit-owned .mcp.json. Writing config.toml instead is
|
|
31
|
+
// actively harmful: a tools table under [mcp_servers.huaweicloud-devkit]
|
|
32
|
+
// implies a config-declared server, and with no command/url codex refuses
|
|
33
|
+
// to load the whole config ("Error: failed to load bootstrap configuration
|
|
34
|
+
// — Caused by: invalid transport in `mcp_servers.huaweicloud-devkit`",
|
|
35
|
+
// measured live; the probe's config.toml always carried a transport for
|
|
36
|
+
// its probe server, which is why the plan's original config.toml dialect
|
|
37
|
+
// never met this shape). The installer therefore never touches the user's
|
|
38
|
+
// config.toml; a user's own per-tool value there WINS over the payload
|
|
39
|
+
// (the source's precedence), and the doctor surfaces it as a WARN.
|
|
40
|
+
//
|
|
41
|
+
// Ownership contracts: the payload .mcp.json is devkit-owned end to end —
|
|
42
|
+
// regenerated on every deploy, removed with the plugin dir / cache on
|
|
43
|
+
// uninstall — so the yield needs no add-only-if-absent or value-exact
|
|
44
|
+
// machinery. The user's config.toml is never written, so its values are
|
|
45
|
+
// user-owned by construction; the doctor reports them by name.
|
|
46
|
+
//
|
|
47
|
+
// Policy directions the doctor names, both measured on 0.167.2: codex's
|
|
48
|
+
// granular `mcp_elicitations = false` auto-declines every server form and
|
|
49
|
+
// substitutes codex's built-in gate, so every roster call fails CLOSED at
|
|
50
|
+
// the devkit gate until the policy is on — the remediation names the flip.
|
|
51
|
+
// A top-level `approval_policy = "never"` blocks MCP tool calls outright,
|
|
52
|
+
// ahead of the devkit gate.
|
|
53
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
54
|
+
import { homedir } from 'node:os';
|
|
55
|
+
import { join } from 'node:path';
|
|
56
|
+
import { APPROVAL_MCP_SERVER, APPROVAL_TOOLS } from "../approval-roster.js";
|
|
57
|
+
import { codexPluginProbe, getCodexPluginName, getMarketplaceName } from "../codex-probe.js";
|
|
58
|
+
import { codexDesktopPluginsDir } from "../targets.js";
|
|
59
|
+
import { asRecord } from "../lib/as-record.js";
|
|
60
|
+
// The yield value the devkit owns. Never "prompt" or "auto": those are
|
|
61
|
+
// remediation shapes for the policy-off branch, taught by the doctor only.
|
|
62
|
+
export const CODEX_APPROVAL_MODE = 'approve';
|
|
63
|
+
// The ask-mode env the payload .mcp.json carries beside the yield: codex
|
|
64
|
+
// passes the plugin-provided server entry's env to the MCP child (live-
|
|
65
|
+
// measured on codex-cli 0.167.2 — a roster call returned ELICITATION_DECLINED,
|
|
66
|
+
// the headless auto-decline of the server-raised form, proving both the
|
|
67
|
+
// passthrough and the capable-client ladder). The payload is the devkit-owned
|
|
68
|
+
// channel: there is no codex-side override for plugin-provided env, so an
|
|
69
|
+
// operator wanting token mode on codex edits their cached copy (and re-runs
|
|
70
|
+
// the install to restore it) — the doctor flags the drift.
|
|
71
|
+
export const CODEX_APPROVAL_MODE_ENV = 'ask';
|
|
72
|
+
// The `tools` map the payload .mcp.json carries inside the devkit's server
|
|
73
|
+
// entry — one per-tool block per roster tool, roster-driven so a
|
|
74
|
+
// registration PR widens the yield with the roster, not by hand. JSON
|
|
75
|
+
// object key order matches the roster order; callers that deep-compare
|
|
76
|
+
// should compare structurally, not by serialization.
|
|
77
|
+
export function codexApprovalToolsBlock() {
|
|
78
|
+
return Object.fromEntries(APPROVAL_TOOLS.map((tool) => [tool, { approval_mode: CODEX_APPROVAL_MODE }]));
|
|
79
|
+
}
|
|
80
|
+
// The ask-mode env half of the payload posture, as a record for entry writes
|
|
81
|
+
// (writeMcpServersFile merges it under the same `agentKey !== 'openclaw'`
|
|
82
|
+
// condition as the tools block, with the same wholesale drift healing).
|
|
83
|
+
export function codexApprovalEnv() {
|
|
84
|
+
return { DEVKIT_APPROVAL_MODE: CODEX_APPROVAL_MODE_ENV };
|
|
85
|
+
}
|
|
86
|
+
function classifyMode(mode) {
|
|
87
|
+
if (mode === 'approve' || mode === 'prompt' || mode === 'auto')
|
|
88
|
+
return mode;
|
|
89
|
+
return mode === undefined ? 'absent' : 'foreign';
|
|
90
|
+
}
|
|
91
|
+
// The per-tool states from a parsed .mcp.json (the payload shape codex's
|
|
92
|
+
// plugin loader reads): mcpServers.<server>.tools.<tool>.approval_mode. A
|
|
93
|
+
// file without our server entry reads as all-absent (a foreign server map
|
|
94
|
+
// never leaks in — asRecord drops nothing, the server key is exact).
|
|
95
|
+
export function readMcpJsonApprovalStates(config, tools = APPROVAL_TOOLS) {
|
|
96
|
+
const server = asRecord(asRecord(config.mcpServers)[APPROVAL_MCP_SERVER]);
|
|
97
|
+
const blocks = asRecord(server.tools);
|
|
98
|
+
return tools.map((tool) => {
|
|
99
|
+
const mode = asRecord(blocks[tool]).approval_mode;
|
|
100
|
+
return classifyMode(typeof mode === 'string' ? mode : undefined);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
// Any mcp_servers tool table header in config.toml: the server segment is
|
|
104
|
+
// captured so the reader can pin the devkit's own server name instead of a
|
|
105
|
+
// regex that would silently accept a lookalike server. Trailing comments
|
|
106
|
+
// are tolerated (valid TOML) so a commented header still reads as the block
|
|
107
|
+
// it is, not as absence.
|
|
108
|
+
const BLOCK_HEADER_RE = /^\s*\[mcp_servers\.([A-Za-z0-9_-]+)\.tools\.([A-Za-z0-9_-]+)\]\s*(?:#.*)?$/;
|
|
109
|
+
const APPROVAL_MODE_LINE_RE = /^\s*approval_mode\s*=\s*"([^"]*)"\s*(?:#.*)?$/;
|
|
110
|
+
const ANY_TABLE_RE = /^\s*\[/;
|
|
111
|
+
// Reads every roster tool's per-tool state from the USER's config.toml
|
|
112
|
+
// text — the config-layer override channel, which the upstream source
|
|
113
|
+
// resolves BEFORE the plugin payload, so a value here wins over our yield.
|
|
114
|
+
// A block runs from its header to the next table header (or EOF); the FIRST
|
|
115
|
+
// approval_mode assignment in the body decides. Blocks under a different
|
|
116
|
+
// server name, or on a non-roster tool, are the user's own config and never
|
|
117
|
+
// read.
|
|
118
|
+
export function readCodexApprovalBlocks(text, tools = APPROVAL_TOOLS) {
|
|
119
|
+
const wanted = new Set(tools);
|
|
120
|
+
const state = new Map(tools.map((tool) => [tool, 'absent']));
|
|
121
|
+
let inBlock = null;
|
|
122
|
+
let mode;
|
|
123
|
+
const closeBlock = () => {
|
|
124
|
+
if (inBlock !== null)
|
|
125
|
+
state.set(inBlock, classifyMode(mode));
|
|
126
|
+
inBlock = null;
|
|
127
|
+
mode = undefined;
|
|
128
|
+
};
|
|
129
|
+
for (const line of text.split(/\r?\n/)) {
|
|
130
|
+
const header = BLOCK_HEADER_RE.exec(line);
|
|
131
|
+
if (header) {
|
|
132
|
+
closeBlock();
|
|
133
|
+
if (header[1] === APPROVAL_MCP_SERVER && wanted.has(header[2]))
|
|
134
|
+
inBlock = header[2];
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (inBlock === null || mode !== undefined)
|
|
138
|
+
continue;
|
|
139
|
+
const assignment = APPROVAL_MODE_LINE_RE.exec(line);
|
|
140
|
+
if (assignment)
|
|
141
|
+
mode = assignment[1];
|
|
142
|
+
}
|
|
143
|
+
closeBlock();
|
|
144
|
+
return tools.map((tool) => state.get(tool));
|
|
145
|
+
}
|
|
146
|
+
// codex's granular approval policy, measured on 0.167.2: with
|
|
147
|
+
// `mcp_elicitations = false` codex auto-declines every server form and
|
|
148
|
+
// substitutes its built-in gate, so every roster call fails CLOSED at the
|
|
149
|
+
// devkit gate until the policy is on. codex accepts TWO spellings of the
|
|
150
|
+
// value (both live-measured): the [approval_policy.granular] table and
|
|
151
|
+
// the inline table `approval_policy = { granular = { mcp_elicitations =
|
|
152
|
+
// false, … } }` — the inline spelling is exactly the machine the
|
|
153
|
+
// remediation-naming contract exists for, so the detector is a whole-file
|
|
154
|
+
// match on the false spelling. The negative lookbehind keeps lookalike
|
|
155
|
+
// keys (`allow_mcp_elicitations = false`) from tripping it; `true` is the
|
|
156
|
+
// healthy granular spelling and never does.
|
|
157
|
+
export function codexElicitPolicyOff(text) {
|
|
158
|
+
return /(?<![A-Za-z_])mcp_elicitations\s*=\s*false\b/.test(text);
|
|
159
|
+
}
|
|
160
|
+
// A top-level `approval_policy = "never"` blocks MCP tool calls outright,
|
|
161
|
+
// ahead of the devkit gate. TOML pins top-level keys before the first table
|
|
162
|
+
// header, so the scan stops at the first header — a [projects.*]-scoped
|
|
163
|
+
// spelling must not be misread as the machine's posture.
|
|
164
|
+
export function codexApprovalPolicyNever(text) {
|
|
165
|
+
for (const line of text.split(/\r?\n/)) {
|
|
166
|
+
if (ANY_TABLE_RE.test(line))
|
|
167
|
+
return false;
|
|
168
|
+
if (/^\s*approval_policy\s*=\s*"never"\s*(#.*)?$/.test(line))
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
// The user-override spellings codex honors that this doctor cannot parse
|
|
174
|
+
// (a full TOML parser is deliberately out of scope): dotted keys
|
|
175
|
+
// (mcp_servers.<server>.tools.<tool>.approval_mode = "…") and inline
|
|
176
|
+
// tables (tools = { <tool> = { approval_mode = "…" } } inside our server's
|
|
177
|
+
// section). Both live-verified to win over the payload, so a value in
|
|
178
|
+
// either shape must never read as absence — the doctor reports the
|
|
179
|
+
// dialect instead, the same honesty as the unreadable-config WARN.
|
|
180
|
+
export function codexOverridesUnparseableDialect(text) {
|
|
181
|
+
let inOurServer = false;
|
|
182
|
+
for (const line of text.split(/\r?\n/)) {
|
|
183
|
+
const header = /^\s*\[mcp_servers\.([A-Za-z0-9_-]+)[.\]]/.exec(line);
|
|
184
|
+
if (header) {
|
|
185
|
+
inOurServer = header[1] === APPROVAL_MCP_SERVER;
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (ANY_TABLE_RE.test(line)) {
|
|
189
|
+
inOurServer = false;
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
const dotted = /^\s*mcp_servers\.([A-Za-z0-9_-]+)\.tools\./.exec(line);
|
|
193
|
+
if (dotted && dotted[1] === APPROVAL_MCP_SERVER)
|
|
194
|
+
return true;
|
|
195
|
+
if (inOurServer && /^\s*tools\s*=\s*\{/.test(line))
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
// ── The payload candidates (what codex actually loads) ──
|
|
201
|
+
// The devkit plugin's cache dir under CODEX_HOME — the CLI marketplace
|
|
202
|
+
// flow's payload home. CODEX_HOME mirrors the resolution codex.ts's cache
|
|
203
|
+
// cleanup uses; codex resolves its whole home from this override.
|
|
204
|
+
export function codexPluginCacheDir() {
|
|
205
|
+
return join(process.env.CODEX_HOME || join(homedir(), '.codex'), 'plugins', 'cache', getMarketplaceName(), getCodexPluginName());
|
|
206
|
+
}
|
|
207
|
+
// Every .mcp.json under the cache dir (one per version dir). Every copy is
|
|
208
|
+
// verified, not just the newest: which version codex loads is codex's
|
|
209
|
+
// call, and a stale copy missing the yield changes that machine's posture.
|
|
210
|
+
// A missing cache dir reads as no candidates (not installed that way).
|
|
211
|
+
export function codexCacheMcpJsonPaths() {
|
|
212
|
+
const cacheDir = codexPluginCacheDir();
|
|
213
|
+
if (!existsSync(cacheDir))
|
|
214
|
+
return [];
|
|
215
|
+
let entries;
|
|
216
|
+
try {
|
|
217
|
+
entries = readdirSync(cacheDir);
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
220
|
+
return [];
|
|
221
|
+
}
|
|
222
|
+
const out = [];
|
|
223
|
+
for (const name of entries) {
|
|
224
|
+
const path = join(cacheDir, name, '.mcp.json');
|
|
225
|
+
try {
|
|
226
|
+
if (statSync(path).isFile())
|
|
227
|
+
out.push(path);
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
// unreadable or not a file — not a candidate
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return out;
|
|
234
|
+
}
|
|
235
|
+
// The Codex Desktop payload's .mcp.json (the desktop deploy's plugin dir).
|
|
236
|
+
export function codexDesktopMcpJsonPath() {
|
|
237
|
+
return join(codexDesktopPluginsDir(), '.mcp.json');
|
|
238
|
+
}
|
|
239
|
+
// The doctor's shared reading: which roster tools sit in each non-approve
|
|
240
|
+
// state. Both channels (payload .mcp.json, config.toml overrides) ask the
|
|
241
|
+
// same question, so the derivation has one home.
|
|
242
|
+
function toolsInStates(states) {
|
|
243
|
+
const names = (wanted) => APPROVAL_TOOLS.filter((_tool, index) => states[index] === wanted).join(', ');
|
|
244
|
+
return {
|
|
245
|
+
prompt: names('prompt'),
|
|
246
|
+
auto: names('auto'),
|
|
247
|
+
foreign: names('foreign'),
|
|
248
|
+
absent: names('absent'),
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
// The payload half of the doctor row: every cached copy that carries our
|
|
252
|
+
// server must carry the full yield; a stale or hand-stripped copy is
|
|
253
|
+
// drift, healable by re-running the install (the payload is regenerated
|
|
254
|
+
// wholesale). A relevant machine with NO payload file at all gets a WARN,
|
|
255
|
+
// never a vacuous pass — the yield cannot be verified without the file
|
|
256
|
+
// codex reads it from.
|
|
257
|
+
function payloadDriftWarns(payloadPaths) {
|
|
258
|
+
const warns = [];
|
|
259
|
+
if (payloadPaths.length === 0) {
|
|
260
|
+
warns.push(`no devkit payload .mcp.json was found in the codex plugin cache or the Codex Desktop plugin dir, so the yield cannot be verified (${RERUN})`);
|
|
261
|
+
return warns;
|
|
262
|
+
}
|
|
263
|
+
for (const path of payloadPaths) {
|
|
264
|
+
let config;
|
|
265
|
+
let states;
|
|
266
|
+
try {
|
|
267
|
+
config = asRecord(JSON.parse(readFileSync(path, 'utf8')));
|
|
268
|
+
states = readMcpJsonApprovalStates(config);
|
|
269
|
+
}
|
|
270
|
+
catch {
|
|
271
|
+
warns.push(`${path} is unparseable, so its yield cannot be verified (${RERUN})`);
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
// The env half: a copy that carries our server entry but not the ask env
|
|
275
|
+
// runs the devkit in token mode (a stale pre-ask payload) — drift,
|
|
276
|
+
// healable by the same re-run.
|
|
277
|
+
if (asRecord(asRecord(asRecord(config.mcpServers)[APPROVAL_MCP_SERVER]).env).DEVKIT_APPROVAL_MODE !==
|
|
278
|
+
CODEX_APPROVAL_MODE_ENV) {
|
|
279
|
+
warns.push(`${path} does not set DEVKIT_APPROVAL_MODE="${CODEX_APPROVAL_MODE_ENV}" in the server env, so the devkit runs its default token mode under codex (${RERUN})`);
|
|
280
|
+
}
|
|
281
|
+
if (states.every((state) => state === 'approve'))
|
|
282
|
+
continue;
|
|
283
|
+
const { prompt, auto, foreign, absent } = toolsInStates(states);
|
|
284
|
+
if (prompt)
|
|
285
|
+
warns.push(`approval_mode "prompt" on ${prompt} in ${path} (double interaction) (${RERUN})`);
|
|
286
|
+
if (auto)
|
|
287
|
+
warns.push(`approval_mode "auto" on ${auto} in ${path} keeps codex's own gate ahead of the devkit's confirmation (${RERUN})`);
|
|
288
|
+
if (foreign)
|
|
289
|
+
warns.push(`approval_mode on ${foreign} in ${path} is not "approve", so codex's own approval gate may fire ahead of the devkit's confirmation (${RERUN})`);
|
|
290
|
+
if (absent)
|
|
291
|
+
warns.push(`the approve block is missing for ${absent} in ${path} (${RERUN})`);
|
|
292
|
+
}
|
|
293
|
+
return warns;
|
|
294
|
+
}
|
|
295
|
+
// ── The doctor row ──
|
|
296
|
+
const CODEX_POSTURE_LABEL = 'Codex approval posture';
|
|
297
|
+
const RERUN = 're-run: npx huaweicloud-devkit install --target codex (or update)';
|
|
298
|
+
// Verifies the yield where codex reads it. Self-gating, silent on machines
|
|
299
|
+
// the devkit has no codex relationship with: no payload .mcp.json (cache or
|
|
300
|
+
// desktop), no codex plugin answering installed, no desktop marketplace
|
|
301
|
+
// registration. `desktopRegistered` is passed in by the doctor shell
|
|
302
|
+
// (codexDesktopDoctorMcpConfigured already runs there as an MCP-configured
|
|
303
|
+
// candidate).
|
|
304
|
+
export function codexDoctorApprovalRow(ctx, desktopRegistered) {
|
|
305
|
+
const payloadPaths = [...codexCacheMcpJsonPaths(), codexDesktopMcpJsonPath()].filter((p) => existsSync(p));
|
|
306
|
+
// The user override + policy channel. An absent config.toml is the
|
|
307
|
+
// healthy no-overrides default (nothing to warn about); a present but
|
|
308
|
+
// unreadable one cannot be verified, which earns a WARN below when the
|
|
309
|
+
// machine has a devkit payload.
|
|
310
|
+
const configPath = join(process.env.CODEX_HOME || join(homedir(), '.codex'), 'config.toml');
|
|
311
|
+
let configText = null;
|
|
312
|
+
let configUnreadable = false;
|
|
313
|
+
try {
|
|
314
|
+
configText = readFileSync(configPath, 'utf8');
|
|
315
|
+
}
|
|
316
|
+
catch (error) {
|
|
317
|
+
configUnreadable = error.code !== 'ENOENT';
|
|
318
|
+
}
|
|
319
|
+
let relevant = payloadPaths.length > 0 || desktopRegistered;
|
|
320
|
+
if (!relevant) {
|
|
321
|
+
const probe = codexPluginProbe();
|
|
322
|
+
relevant = probe.ok && probe.installed;
|
|
323
|
+
}
|
|
324
|
+
if (!relevant)
|
|
325
|
+
return;
|
|
326
|
+
// 1. The payload half — every copy that carries our server must carry
|
|
327
|
+
// the full yield; a stale or hand-stripped copy is drift, healable by
|
|
328
|
+
// re-running the install (the payload is regenerated wholesale).
|
|
329
|
+
const payloadWarns = payloadDriftWarns(payloadPaths);
|
|
330
|
+
// 2. The user override half (config.toml) — a value here WINS over the
|
|
331
|
+
// payload (the config layer resolves first, upstream source), so it
|
|
332
|
+
// decides the machine's actual posture; WARN, never FAIL: no client
|
|
333
|
+
// value fails anything open. Overrides in a dialect this doctor cannot
|
|
334
|
+
// parse (dotted keys, inline tables) get the dialect WARN, never
|
|
335
|
+
// silence — reading them as absence would hide the winning value.
|
|
336
|
+
const overrideWarns = [];
|
|
337
|
+
if (configText !== null) {
|
|
338
|
+
if (codexOverridesUnparseableDialect(configText)) {
|
|
339
|
+
overrideWarns.push(`the user's config.toml carries per-tool overrides in a dialect this doctor cannot parse (dotted keys or inline tables), so the winning values cannot be verified — codex's own approval gate may fire ahead of the devkit's confirmation`);
|
|
340
|
+
}
|
|
341
|
+
const { prompt, auto, foreign } = toolsInStates(readCodexApprovalBlocks(configText));
|
|
342
|
+
if (prompt) {
|
|
343
|
+
overrideWarns.push(`the user's config.toml sets approval_mode "prompt" on ${prompt}, which wins over the payload and shows codex's own Allow/Cancel dialog ahead of the devkit's confirmation (double interaction)`);
|
|
344
|
+
}
|
|
345
|
+
if (auto) {
|
|
346
|
+
overrideWarns.push(`the user's config.toml sets approval_mode "auto" on ${auto}, which wins over the payload and keeps codex's own approval gate (with persistence options) ahead of the devkit's confirmation`);
|
|
347
|
+
}
|
|
348
|
+
if (foreign) {
|
|
349
|
+
overrideWarns.push(`the user's config.toml sets approval_mode on ${foreign}, which wins over the payload — codex's own approval gate may fire ahead of the devkit's confirmation`);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
// 3. The policy directions, both config.toml-borne.
|
|
353
|
+
const policyWarns = [];
|
|
354
|
+
if (configText !== null) {
|
|
355
|
+
if (codexElicitPolicyOff(configText)) {
|
|
356
|
+
policyWarns.push(`codex's granular policy sets mcp_elicitations = false, so codex auto-declines every devkit confirmation form and every roster call fails closed at the devkit gate until the policy is on — flip it: set mcp_elicitations = true (or drop the granular approval_policy) in ${configPath}`);
|
|
357
|
+
}
|
|
358
|
+
if (codexApprovalPolicyNever(configText)) {
|
|
359
|
+
policyWarns.push(`approval_policy = "never" blocks MCP tool calls outright, ahead of the devkit gate — choose a policy that can ask, e.g. approval_policy = "on-request"`);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
else if (configUnreadable) {
|
|
363
|
+
// A devkit payload exists but the override channel is unreadable, so
|
|
364
|
+
// user per-tool overrides and the approval policy cannot be verified.
|
|
365
|
+
overrideWarns.push(`the codex config at ${configPath} is unreadable, so user per-tool overrides and the approval policy cannot be verified`);
|
|
366
|
+
}
|
|
367
|
+
const warns = [...payloadWarns, ...overrideWarns, ...policyWarns];
|
|
368
|
+
if (warns.length === 0) {
|
|
369
|
+
ctx.check(`${CODEX_POSTURE_LABEL} (${APPROVAL_TOOLS.length} per-tool approve blocks + DEVKIT_APPROVAL_MODE="${CODEX_APPROVAL_MODE_ENV}" in the devkit payload)`, true, '');
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
ctx.warn(`${CODEX_POSTURE_LABEL}: ${warns.join(' ')}`);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
@@ -170,7 +170,14 @@ export function uninstallCodexDesktop() {
|
|
|
170
170
|
if (removeIfExists(cacheDir)) {
|
|
171
171
|
console.log(' Codex plugin cache cleaned');
|
|
172
172
|
}
|
|
173
|
-
// Clean up old config.toml section from pre-marketplace era
|
|
173
|
+
// Clean up old config.toml section from pre-marketplace era. The sweep is
|
|
174
|
+
// wholesale trunk behavior: EVERY [mcp_servers.huaweicloud-devkit…] table
|
|
175
|
+
// goes, including user-authored subtables under our server name (a user
|
|
176
|
+
// tools block vanishes with ours, and the doctor never sees it after the
|
|
177
|
+
// uninstall). The devkit's own yield never lands in config.toml at all
|
|
178
|
+
// (agents/codex-config.ts records why), so this pass removes legacy
|
|
179
|
+
// server sections plus whatever users placed under that name — nothing
|
|
180
|
+
// the current installer writes.
|
|
174
181
|
const configPath = join(homedir(), '.codex', 'config.toml');
|
|
175
182
|
if (existsSync(configPath)) {
|
|
176
183
|
const lines = readFileSync(configPath, 'utf8').split(/\r?\n/);
|
|
@@ -125,6 +125,15 @@ export function installCodex() {
|
|
|
125
125
|
console.log(` \x1b[31mCodex plugin installation failed.\x1b[0m`);
|
|
126
126
|
return false;
|
|
127
127
|
}
|
|
128
|
+
// The client yield (PR-5) needs no step here: the per-tool approve blocks
|
|
129
|
+
// ship inside the plugin payload's own .mcp.json (the repo's
|
|
130
|
+
// plugins/huaweicloud-core/.mcp.json, which `codex plugin add` copies
|
|
131
|
+
// into its cache) — the file codex reads per-tool approval_mode from for
|
|
132
|
+
// a plugin-provided server (agents/codex-config.ts). The user's
|
|
133
|
+
// config.toml is never touched: a tools table under
|
|
134
|
+
// [mcp_servers.huaweicloud-devkit] would imply a config-declared server,
|
|
135
|
+
// and without a transport codex refuses to load the whole config
|
|
136
|
+
// (live-measured "invalid transport" on codex-cli 0.167.2).
|
|
128
137
|
return true;
|
|
129
138
|
}
|
|
130
139
|
export function uninstallCodex() {
|
|
@@ -15,6 +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 { applyAllowPermissionRules, applyAllowPermissionRulesV1, askRuleShapeFor, removeAllowPermissionRules, removeAllowPermissionRulesV1, removeAskPermissionRules, removeAskPermissionRulesV1, } from "../lib/opencode-ask-rule.js";
|
|
18
19
|
import { asRecord } from "../lib/as-record.js";
|
|
19
20
|
import { devkitOwnedSkillNames, tryCoreSkillNames } from "../install-payload.js";
|
|
20
21
|
// The seam's version gate. HUAWEICLOUD_OPENCODE_PERMISSION_SEAM=on|off is
|
|
@@ -26,19 +27,26 @@ import { devkitOwnedSkillNames, tryCoreSkillNames } from "../install-payload.js"
|
|
|
26
27
|
// an older version may reject the keys outright. A later update heals the
|
|
27
28
|
// skip: the seam is a third change source in updateOpenCodeConfig, so an
|
|
28
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.
|
|
29
33
|
function probeOpencodeVersion() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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() {
|
|
42
50
|
let probeRoot;
|
|
43
51
|
try {
|
|
44
52
|
probeRoot = mkdtempSync(join(tmpdir(), 'devkit-opencode-probe-'));
|
|
@@ -87,6 +95,32 @@ export function openCodeSeamGate() {
|
|
|
87
95
|
return forced;
|
|
88
96
|
return opencodeSeamVersionSupported(probeOpencodeVersion()) ? 'on' : 'off';
|
|
89
97
|
}
|
|
98
|
+
export function openCodeAskGate() {
|
|
99
|
+
const forced = process.env.HUAWEICLOUD_OPENCODE_ASK_RULE;
|
|
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';
|
|
110
|
+
}
|
|
111
|
+
function applyApprovalModeToEntry(entry) {
|
|
112
|
+
const env = asRecord(entry.environment);
|
|
113
|
+
const current = env.DEVKIT_APPROVAL_MODE;
|
|
114
|
+
if (current === 'ask')
|
|
115
|
+
return 'present';
|
|
116
|
+
if (current !== undefined) {
|
|
117
|
+
const shown = typeof current === 'string' ? current : JSON.stringify(current);
|
|
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';
|
|
120
|
+
}
|
|
121
|
+
entry.environment = { ...env, DEVKIT_APPROVAL_MODE: 'ask' };
|
|
122
|
+
return 'established';
|
|
123
|
+
}
|
|
90
124
|
// The glob set the seam covers: the plugin-dir tree actually deployed by
|
|
91
125
|
// this run plus per-skill globs for the native core meta-skill copies
|
|
92
126
|
// (under the XDG opencode skills dir). An unusable manifest degrades to the
|
|
@@ -129,33 +163,108 @@ export function updateOpenCodeConfig(pluginDir) {
|
|
|
129
163
|
else {
|
|
130
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.');
|
|
131
165
|
}
|
|
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.
|
|
132
179
|
const existing = asRecord(config.mcp)['huaweicloud-devkit'];
|
|
180
|
+
let entry;
|
|
181
|
+
let entryChanged = false;
|
|
182
|
+
let rebuilt = false;
|
|
183
|
+
let approvalMode = 'off';
|
|
133
184
|
if (existing) {
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
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;
|
|
207
|
+
}
|
|
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).`);
|
|
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).`);
|
|
139
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) {
|
|
140
247
|
const mcpMap = asRecord(config.mcp);
|
|
141
248
|
mcpMap['huaweicloud-devkit'] = entry;
|
|
142
249
|
config.mcp = mcpMap;
|
|
143
|
-
|
|
144
|
-
|
|
250
|
+
}
|
|
251
|
+
if (!rebuilt && !entryChanged && !permChanged && !clientChanged && !migrated && !clientRemoved) {
|
|
252
|
+
console.log(` OpenCode MCP config unchanged: ${configPath}`);
|
|
145
253
|
return;
|
|
146
254
|
}
|
|
147
|
-
const mcpMap = asRecord(config.mcp);
|
|
148
|
-
let entry = mergeCommandStyle(undefined, { mcpPath }).entry;
|
|
149
|
-
// Restore user fields saved by a previous uninstall (issue #615) before the
|
|
150
|
-
// packs write so a delta-carried DEVKIT_PACKS counts as the current value.
|
|
151
|
-
const delta = takeAgentDelta('opencode');
|
|
152
|
-
if (delta)
|
|
153
|
-
entry = asRecord(applyUserDelta(entry, delta, 'command'));
|
|
154
|
-
applyPacksToEntry(entry, 'environment', 'OpenCode');
|
|
155
|
-
mcpMap['huaweicloud-devkit'] = entry;
|
|
156
|
-
config.mcp = mcpMap;
|
|
157
255
|
writeMcpSettingsFile(configPath, config);
|
|
158
|
-
console.log(
|
|
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}`);
|
|
267
|
+
}
|
|
159
268
|
}
|
|
160
269
|
export function removeOpenCodeConfig() {
|
|
161
270
|
const configPath = opencodeConfigFile();
|
|
@@ -182,11 +291,28 @@ export function removeOpenCodeConfig() {
|
|
|
182
291
|
// value-exact deletion keeps user-modified rules (the ownership contract
|
|
183
292
|
// lives in lib/opencode-permission-seam.ts).
|
|
184
293
|
const permCleaned = removeSkillTreePermissionSeam(config, openCodeSeamGlobs(opencodePluginsDir()));
|
|
185
|
-
|
|
294
|
+
// The client-rule cleanup also runs unconditionally of the version gate: an
|
|
295
|
+
// uninstall must remove what any past install wrote — the opencode that
|
|
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)
|
|
186
310
|
return;
|
|
187
311
|
writeMcpSettingsFile(configPath, config);
|
|
188
312
|
if (hadEntry)
|
|
189
313
|
console.log(` OpenCode MCP config cleaned: ${configPath}`);
|
|
190
314
|
if (permCleaned)
|
|
191
315
|
console.log(` Skills-tree permission rules removed: ${configPath}`);
|
|
316
|
+
if (allowCleaned || askCleaned)
|
|
317
|
+
console.log(` ASK client permission rules removed: ${configPath}`);
|
|
192
318
|
}
|