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
|
@@ -47,6 +47,7 @@ export function buildDevbridgeKeepaliveScript(tunnels) {
|
|
|
47
47
|
const body = [
|
|
48
48
|
`#!/bin/bash`,
|
|
49
49
|
`export PATH="/workspace/.local/bin:$HOME/.huawei/bin:$PATH"`,
|
|
50
|
+
`export DBUS_SESSION_BUS_ADDRESS="\${DBUS_SESSION_BUS_ADDRESS:-unix:path=/run/dbus-session}"`,
|
|
50
51
|
`# entries: tunnelId:url (URLs are stable — tunnel IDs never change)`,
|
|
51
52
|
`TUNNELS="${entries}"`,
|
|
52
53
|
`declare -A LAST_RENEW`,
|
|
@@ -65,6 +66,29 @@ export function buildDevbridgeKeepaliveScript(tunnels) {
|
|
|
65
66
|
` echo "$TS renew $ID ok (${DEVBRIDGE_RENEW_HOURS}h)" >> /tmp/tunnel-keepalive.log`,
|
|
66
67
|
` else`,
|
|
67
68
|
` echo "$TS renew $ID FAILED: $(head -1 /tmp/keepalive-last-update.log)" >> /tmp/tunnel-keepalive.log`,
|
|
69
|
+
// Self-heal (bde7ae56): a valid key can coexist with an expired CLI token
|
|
70
|
+
// (renew returns 40100 while auth status still prints Logged in) —
|
|
71
|
+
// re-login from keyring/file (never create a key) and retry once now;
|
|
72
|
+
// the next tick retries normally if even that fails.
|
|
73
|
+
` DB_KEY=""`,
|
|
74
|
+
` if command -v hwcloud >/dev/null 2>&1; then`,
|
|
75
|
+
` DB_KEY=$(hwcloud keyring get HW_DEVBRIDGE_API_KEY 2>&1 || true)`,
|
|
76
|
+
` case "$DB_KEY" in "devbridge_"*) : ;; *) DB_KEY="";; esac`,
|
|
77
|
+
` fi`,
|
|
78
|
+
` if [ -z "$DB_KEY" ] && [ -s /tmp/hw_api_key ]; then`,
|
|
79
|
+
` source /tmp/hw_api_key 2>/dev/null || true`,
|
|
80
|
+
` DB_KEY="\${HW_API_KEY:-}"`,
|
|
81
|
+
` fi`,
|
|
82
|
+
` if [ -n "$DB_KEY" ] && devbridge auth login --api-key "$DB_KEY" >/tmp/keepalive-auth.log 2>&1; then`,
|
|
83
|
+
` if devbridge update "$ID" -e ${DEVBRIDGE_RENEW_HOURS} > /tmp/keepalive-last-update.log 2>&1; then`,
|
|
84
|
+
` echo "$TS renew $ID ok after re-login (${DEVBRIDGE_RENEW_HOURS}h)" >> /tmp/tunnel-keepalive.log`,
|
|
85
|
+
` else`,
|
|
86
|
+
` echo "$TS renew $ID FAILED after re-login: $(head -1 /tmp/keepalive-last-update.log)" >> /tmp/tunnel-keepalive.log`,
|
|
87
|
+
` fi`,
|
|
88
|
+
` else`,
|
|
89
|
+
` echo "$TS renew $ID AUTH_FAILED: no usable key; next expose_tunnel will auto-create" >> /tmp/tunnel-keepalive.log`,
|
|
90
|
+
` fi`,
|
|
91
|
+
` unset DB_KEY HW_API_KEY 2>/dev/null`,
|
|
68
92
|
` fi`,
|
|
69
93
|
` LAST_RENEW[$ID]=$NOW`,
|
|
70
94
|
` fi`,
|
|
@@ -110,7 +134,14 @@ export function buildKeepaliveTunnelsReadScript() {
|
|
|
110
134
|
].join('\n');
|
|
111
135
|
}
|
|
112
136
|
// Parse the raw stdout of buildKeepaliveTunnelsReadScript. Empty output (no
|
|
113
|
-
// watchdog installed yet) yields [].
|
|
137
|
+
// watchdog installed yet) yields []. Entries are the generated three-field
|
|
138
|
+
// `id:url:port` form (plus the two-field legacy form): the tunnel URL's last
|
|
139
|
+
// segment is the domain, so a trailing `:<digits>` (or the empty port field's
|
|
140
|
+
// bare `:`) is never part of the URL — strip every tail, including the legacy
|
|
141
|
+
// double tails the pre-fix round trip wrote. A kept tail mangles the watchdog's
|
|
142
|
+
// health-check target and grows one field per roster rewrite (interrogate
|
|
143
|
+
// port-pr4 A-F1; the parse shape predates this port — the fix lands with the
|
|
144
|
+
// cleanup sync, the second roster-rewrite path, so both round trips are stable).
|
|
114
145
|
export function parseKeepaliveTunnelsOutput(stdout) {
|
|
115
146
|
const text = stripTerminalEscapes(stdout);
|
|
116
147
|
const m = text.match(/^DB_KEEPALIVE_TUNNELS=(.*)$/m);
|
|
@@ -121,7 +152,16 @@ export function parseKeepaliveTunnelsOutput(stdout) {
|
|
|
121
152
|
.split(/\s+/)
|
|
122
153
|
.map((entry) => {
|
|
123
154
|
const i = entry.indexOf(':');
|
|
124
|
-
|
|
155
|
+
if (i <= 0)
|
|
156
|
+
return null;
|
|
157
|
+
let url = entry.slice(i + 1);
|
|
158
|
+
// Strip every generated/legacy tail in one converging loop: digit tails
|
|
159
|
+
// and bare colons alike (the pre-fix shapes could leave one behind for a
|
|
160
|
+
// generation — a `:18082:` tail kept `:18082` after a single pass).
|
|
161
|
+
while (/:$/.test(url) || /:\d+$/.test(url)) {
|
|
162
|
+
url = url.slice(0, url.lastIndexOf(':'));
|
|
163
|
+
}
|
|
164
|
+
return { tunnelId: entry.slice(0, i), url };
|
|
125
165
|
})
|
|
126
166
|
.filter((t) => t !== null);
|
|
127
167
|
}
|
|
@@ -17,6 +17,7 @@ import { join, dirname } from 'node:path';
|
|
|
17
17
|
import { homedir } from 'node:os';
|
|
18
18
|
import { createHash } from 'node:crypto';
|
|
19
19
|
import { hdkitCreateApiKey, hdkitListApiKeys, hdkitDeleteApiKey } from "../lib/hdkit/hdkitservice-api.js";
|
|
20
|
+
import { isVersionGateError } from "../lib/hdkit/hdkit-gate.js";
|
|
20
21
|
import { getCredentials } from "../lib/hdkit/hwlink-api.js";
|
|
21
22
|
const POOL_KEY_NAMES = {
|
|
22
23
|
ephemeral: 'devkit-ephemeral',
|
|
@@ -107,8 +108,11 @@ export async function ensureDevbridgeKey(poolType) {
|
|
|
107
108
|
await hdkitDeleteApiKey(orphan['id']);
|
|
108
109
|
}
|
|
109
110
|
}
|
|
110
|
-
catch {
|
|
111
|
-
//
|
|
111
|
+
catch (error) {
|
|
112
|
+
// 409 版本门禁必须穿透(relay 侧按出口折叠的前提):吞掉它会被后续 create
|
|
113
|
+
// 失败的泛化降级掩盖成凭证误诊;其余 list/delete 失败仍不阻断创建
|
|
114
|
+
if (isVersionGateError(error))
|
|
115
|
+
throw error;
|
|
112
116
|
}
|
|
113
117
|
// 3. 创建
|
|
114
118
|
const created = await hdkitCreateApiKey(name, 'devbridge');
|
|
@@ -142,7 +146,11 @@ export async function listKeysForQuotaHint() {
|
|
|
142
146
|
lastUsed: typeof k['last_used_at'] === 'string' ? k['last_used_at'] : '',
|
|
143
147
|
}));
|
|
144
148
|
}
|
|
145
|
-
catch {
|
|
149
|
+
catch (error) {
|
|
150
|
+
// 409 门禁必须穿透:配额信封拿着读不出来的 currentKeys 教用户清 key 是误诊
|
|
151
|
+
// (devbridge-auth 侧按出口折叠);其余读取失败仍降级为空清单
|
|
152
|
+
if (isVersionGateError(error))
|
|
153
|
+
throw error;
|
|
146
154
|
return [];
|
|
147
155
|
}
|
|
148
156
|
}
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
// devbridge-verify.ts — the fresh-session re-verify family (#919/#922)
|
|
13
13
|
// devbridge-renew.ts — the renew flow (script, parser, renewTunnel)
|
|
14
14
|
// devbridge-keepalive.ts — the keepalive watchdog family + enrollment
|
|
15
|
+
// devbridge-cleanup.ts — the selective tunnel cleanup family
|
|
15
16
|
// devbridge-expose-flow.ts — the exposeTunnel orchestration
|
|
16
17
|
// The sandbox siblings import each other's canonical modules directly (the
|
|
17
18
|
// DEVBRIDGE_* gateway constants from devbridge-gateway.ts, the escape stripper
|
|
@@ -42,6 +43,11 @@ export { buildDevbridgeRenewScript, parseDevbridgeRenewOutput, renewTunnel } fro
|
|
|
42
43
|
// The keepalive watchdog family lives in devbridge-keepalive.ts; re-exported
|
|
43
44
|
// as the public face.
|
|
44
45
|
export { buildDevbridgeKeepaliveScript, buildKeepaliveTunnelsReadScript, installKeepaliveWatchdog, mergeKeepaliveTunnels, parseKeepaliveTunnelsOutput, } from "./devbridge-keepalive.js";
|
|
46
|
+
// The selective-cleanup family (parsers, cleanup plan, lock/state/apply
|
|
47
|
+
// scripts, the cleanup orchestration) lives in devbridge-cleanup.ts;
|
|
48
|
+
// re-exported as the public face (the sandbox pack's handlers and the tests
|
|
49
|
+
// import these names here).
|
|
50
|
+
export { buildDevbridgeCleanupApplyScript, buildDevbridgeCleanupLockScript, buildDevbridgeCleanupStateScript, cleanupDevbridgeTunnels, normalizeCleanupMode, parseDevbridgeHostProcesses, parseDevbridgePortQueries, parseDevbridgeTunnelList, planDevbridgeCleanup, } from "./devbridge-cleanup.js";
|
|
45
51
|
// The exposeTunnel orchestration lives in devbridge-expose-flow.ts;
|
|
46
52
|
// re-exported as the public face (the sandbox pack's handlers-tunnel.ts and
|
|
47
53
|
// the test harness import it here).
|
|
@@ -35,13 +35,22 @@ export function validateExpiryHours(hours) {
|
|
|
35
35
|
}
|
|
36
36
|
return n;
|
|
37
37
|
}
|
|
38
|
+
// The tunnel-ID charset as one shared pattern: validateTunnelId guards shell
|
|
39
|
+
// splices with it, and the selective-cleanup parsers (devbridge-cleanup.ts)
|
|
40
|
+
// recognize real IDs with it. The real CLI accepts only lowercase base32
|
|
41
|
+
// (a-z2-7, length 8); this superset over-accepts by design — parsing and
|
|
42
|
+
// shell-splice guarding fail SAFE on junk (the CLI's own validation rejects
|
|
43
|
+
// any phantom delete; a phantom matching a real hostless tunnel is a
|
|
44
|
+
// documented orphan-delete), while a strict pattern would silently DROP real
|
|
45
|
+
// IDs on any charset drift.
|
|
46
|
+
export const DEVBRIDGE_TUNNEL_ID_PATTERN = /^[A-Za-z0-9_-]{4,32}$/;
|
|
38
47
|
// Validate a DevBridge tunnel ID destined for shell interpolation in
|
|
39
48
|
// `devbridge update <id>` / `devbridge host <id>` / pgrep patterns. IDs are
|
|
40
49
|
// short lowercase base36 tokens (e.g. nv2dvv6w, kag7rozs); the strict charset
|
|
41
50
|
// keeps shell metacharacters out of the splice.
|
|
42
51
|
export function validateTunnelId(tunnelId) {
|
|
43
52
|
const id = asText(tunnelId ?? '');
|
|
44
|
-
if (
|
|
53
|
+
if (!DEVBRIDGE_TUNNEL_ID_PATTERN.test(id)) {
|
|
45
54
|
throw new Error(`sandbox tunnel: invalid tunnel_id ${JSON.stringify(id.slice(0, 40))}. Expected the short ID from huaweicloud_sandbox_expose_tunnel's "tunnelId" field (URL-safe characters only).`);
|
|
46
55
|
}
|
|
47
56
|
return id;
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { asText } from "../lib/as-text.js";
|
|
3
|
+
import { stripTerminalEscapes } from "./sandbox-output.js";
|
|
4
|
+
// The async sandbox-task family — the claim protocol as formalized and
|
|
5
|
+
// TLC-verified (the HwExecClaim spec, 9/9 invariants). One directory per
|
|
6
|
+
// task, /tmp/.hwexec/<taskId>/, whose files ARE the state:
|
|
7
|
+
// claim — the start script's O_EXCL create; existence means some start
|
|
8
|
+
// already won the spawn right, so a retry is structurally
|
|
9
|
+
// unable to spawn a second copy.
|
|
10
|
+
// cmd — the original command line (diagnostics only; poll never
|
|
11
|
+
// reads it; a retry rewrite is harmless).
|
|
12
|
+
// launched — the wrapper's first-action guard file, separating never
|
|
13
|
+
// (claimed, never spawned) from lost (ran, died without
|
|
14
|
+
// writing a status).
|
|
15
|
+
// log — the command's stdout+stderr append stream.
|
|
16
|
+
// status — the terminal `exit:<n>` line; the write is non-atomic, so a
|
|
17
|
+
// torn read must converge to running — the field is matched by
|
|
18
|
+
// CONTENT (full `exit:<digits>` line), never by existence.
|
|
19
|
+
// The claim's deliberate trade: an exec that dies between claim and spawn
|
|
20
|
+
// leaves a task that never runs, and no same-id retry can recover it — the
|
|
21
|
+
// poll's `never` verdict is exactly that state, and the teaching is a NEW
|
|
22
|
+
// task_id. The guard-file variant (check `launched` before spawning — the
|
|
23
|
+
// HwExecGuard3 spec) is falsified by OneCopyRunning (Start, then a retry
|
|
24
|
+
// inside the unconfirmed window, runs two copies); never reintroduce any
|
|
25
|
+
// pre-spawn launched check — the O_EXCL claim create is the only spawn
|
|
26
|
+
// arbiter, and the elif after it only classifies the create failure.
|
|
27
|
+
// Server-side truth root, one directory per task. /tmp is session-scoped: a
|
|
28
|
+
// sandbox reboot wipes it — the poll's lost/unknown split models exactly
|
|
29
|
+
// that boundary.
|
|
30
|
+
export const HWEXEC_TASK_ROOT = '/tmp/.hwexec';
|
|
31
|
+
// Task ids are path- and pgrep-safe by charset (lowercase, digits, hyphen,
|
|
32
|
+
// 1-64 chars): they ride file paths AND the pgrep -f pattern, so no shell
|
|
33
|
+
// metacharacter can ever travel through one.
|
|
34
|
+
export const HWEXEC_TASK_ID_PATTERN = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
35
|
+
// The poll's bounded wait: sleep-2 intervals checking the status file; the
|
|
36
|
+
// loop count is folded from wait_ms.
|
|
37
|
+
export const HWEXEC_WAIT_STEP_MS = 2000;
|
|
38
|
+
// The wait_ms ceiling (the zod text and the validator both read this).
|
|
39
|
+
export const HWEXEC_WAIT_MS_MAX = 60000;
|
|
40
|
+
// Default log-tail size for a poll (and the dup receipt's verdict poll).
|
|
41
|
+
export const HWEXEC_TAIL_BYTES_DEFAULT = 4096;
|
|
42
|
+
// Log-tail ceiling: the tail rides the poll exec's stdout, and the exec
|
|
43
|
+
// channel is fragile for large single payloads — it stays bounded.
|
|
44
|
+
export const HWEXEC_TAIL_BYTES_MAX = 65536;
|
|
45
|
+
// The poll exec's headroom over wait_ms (the devbridge-expose-flow A2
|
|
46
|
+
// budget doctrine): the bounded wait plus the field round-trips must sit
|
|
47
|
+
// INSIDE the ws-exec timeout, so the effective timeout folds to
|
|
48
|
+
// wait_ms + 15s and the wait loop can never die as a mid-exec timeout.
|
|
49
|
+
export const HWEXEC_POLL_HEADROOM_MS = 15000;
|
|
50
|
+
export function hwexecTaskDir(taskId) {
|
|
51
|
+
return `${HWEXEC_TASK_ROOT}/${taskId}`;
|
|
52
|
+
}
|
|
53
|
+
// Validate a task id destined for path and pgrep-pattern interpolation.
|
|
54
|
+
export function validateHwexecTaskId(id) {
|
|
55
|
+
const value = asText(id ?? '');
|
|
56
|
+
if (!HWEXEC_TASK_ID_PATTERN.test(value)) {
|
|
57
|
+
throw new Error(`sandbox exec: invalid task_id ${JSON.stringify(value.slice(0, 40))}. ` +
|
|
58
|
+
`Expected ${HWEXEC_TASK_ID_PATTERN.source} (path- and pgrep-safe); omit task_id to let the tool generate one.`);
|
|
59
|
+
}
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
// Generate a task id (t-<12 hex>). Collision resistance within one sandbox
|
|
63
|
+
// session is the only requirement — ids scope per-task directories.
|
|
64
|
+
export function generateHwexecTaskId() {
|
|
65
|
+
return `t-${randomBytes(6).toString('hex')}`;
|
|
66
|
+
}
|
|
67
|
+
// Escape a command line for embedding inside a shell single-quoted span —
|
|
68
|
+
// both the cmd-file write and the wrapper's sh -c splice the command this
|
|
69
|
+
// way (close quote, escaped quote, reopen).
|
|
70
|
+
export function escapeHwexecCommand(command) {
|
|
71
|
+
return command.replaceAll("'", "'\\''");
|
|
72
|
+
}
|
|
73
|
+
// The start script: claim → spawn → receipt, in that line order. The O_EXCL
|
|
74
|
+
// claim create is the only spawn arbiter; the elif only classifies the
|
|
75
|
+
// create failure (dup vs error) and never gates the spawn. The wrapper
|
|
76
|
+
// writes the launched guard as its FIRST action, appends the command's
|
|
77
|
+
// stdout+stderr to the log, then commits `exit:<n>`.
|
|
78
|
+
export function buildHwexecStartScript(taskId, command) {
|
|
79
|
+
const id = validateHwexecTaskId(taskId);
|
|
80
|
+
const dir = hwexecTaskDir(id);
|
|
81
|
+
const escaped = escapeHwexecCommand(command);
|
|
82
|
+
// The wrapper's sh -c does not inherit the outer shell's variables, and
|
|
83
|
+
// poll liveness is detected by pgrep -f matching the literal
|
|
84
|
+
// <dir>/launched path inside the wrapper's own command line — so the
|
|
85
|
+
// wrapper's paths are inlined, never $D-expanded.
|
|
86
|
+
const wrapper = `: > "${dir}/launched"; ( ${escaped} ) >> "${dir}/log" 2>&1; echo "exit:$?" > "${dir}/status"`;
|
|
87
|
+
return [
|
|
88
|
+
`D=${dir}`,
|
|
89
|
+
`mkdir -p "$D"`,
|
|
90
|
+
`printf '%s\\n' '${escaped}' > "$D/cmd"`,
|
|
91
|
+
`if (set -C; : > "$D/claim") 2>/dev/null; then`,
|
|
92
|
+
// #919/#922 (the devbridge-expose trio): setsid detaches the process
|
|
93
|
+
// group so the task survives the exec session's teardown, < /dev/null
|
|
94
|
+
// drops the controlling tty, disown removes the job-table entry. A
|
|
95
|
+
// missing setsid falls back to a bare nohup launch — the task still
|
|
96
|
+
// starts; disown is guarded so shells without the builtin survive.
|
|
97
|
+
` if command -v setsid > /dev/null 2>&1; then setsid nohup sh -c '${wrapper}' >/dev/null 2>&1 < /dev/null & else nohup sh -c '${wrapper}' >/dev/null 2>&1 < /dev/null & fi`,
|
|
98
|
+
` disown 2>/dev/null || true`,
|
|
99
|
+
` echo "HW_STARTED=${id}"`,
|
|
100
|
+
`elif [ -f "$D/claim" ]; then`,
|
|
101
|
+
` echo "HW_DUP=${id}"`,
|
|
102
|
+
`else`,
|
|
103
|
+
` echo "HW_CLAIM_ERROR=1"`,
|
|
104
|
+
`fi`,
|
|
105
|
+
].join('\n');
|
|
106
|
+
}
|
|
107
|
+
// Fold wait_ms into the bounded-wait loop count. Floor division keeps the
|
|
108
|
+
// total sleep ≤ wait_ms — the budget the exec timeout is folded from.
|
|
109
|
+
export function hwexecPollLoops(waitMs) {
|
|
110
|
+
return Math.floor(waitMs / HWEXEC_WAIT_STEP_MS);
|
|
111
|
+
}
|
|
112
|
+
// Validate wait_ms (0-60000, integer; the default is 0 — no in-poll wait).
|
|
113
|
+
export function validateHwexecWaitMs(waitMs) {
|
|
114
|
+
const n = Number(waitMs ?? 0);
|
|
115
|
+
if (!Number.isSafeInteger(n) || n < 0 || n > HWEXEC_WAIT_MS_MAX) {
|
|
116
|
+
throw new Error(`sandbox exec poll: invalid wait_ms ${JSON.stringify(waitMs)}. ` +
|
|
117
|
+
`Expected an integer between 0 and ${HWEXEC_WAIT_MS_MAX}.`);
|
|
118
|
+
}
|
|
119
|
+
return n;
|
|
120
|
+
}
|
|
121
|
+
// Validate tail_bytes (1-65536; the default is 4096).
|
|
122
|
+
export function validateHwexecTailBytes(tailBytes) {
|
|
123
|
+
const n = Number(tailBytes ?? HWEXEC_TAIL_BYTES_DEFAULT);
|
|
124
|
+
if (!Number.isSafeInteger(n) || n < 1 || n > HWEXEC_TAIL_BYTES_MAX) {
|
|
125
|
+
throw new Error(`sandbox exec poll: invalid tail_bytes ${JSON.stringify(tailBytes)}. ` +
|
|
126
|
+
`Expected an integer between 1 and ${HWEXEC_TAIL_BYTES_MAX}.`);
|
|
127
|
+
}
|
|
128
|
+
return n;
|
|
129
|
+
}
|
|
130
|
+
// The poll exec timeout: wait_ms + headroom, never below the table default.
|
|
131
|
+
// A timeout on a poll must mean the sandbox is unreachable — never that the
|
|
132
|
+
// script's own bounded wait ran out of clock.
|
|
133
|
+
export function resolveHwexecPollTimeoutMs(waitMs, baseTimeoutMs) {
|
|
134
|
+
return Math.max(baseTimeoutMs, waitMs + HWEXEC_POLL_HEADROOM_MS);
|
|
135
|
+
}
|
|
136
|
+
// The poll script: a bounded wait (sleep-2 intervals, loop count folded from
|
|
137
|
+
// wait_ms, early exit the moment the status line commits), then the one-shot
|
|
138
|
+
// field echo. The HW_* fields are read only from the region before
|
|
139
|
+
// HW_LOG_BEGIN, so log content can never line-inject a verdict field.
|
|
140
|
+
export function buildHwexecPollScript(taskId, waitMs, tailBytes) {
|
|
141
|
+
const id = validateHwexecTaskId(taskId);
|
|
142
|
+
const loops = hwexecPollLoops(validateHwexecWaitMs(waitMs));
|
|
143
|
+
const bytes = validateHwexecTailBytes(tailBytes);
|
|
144
|
+
return [
|
|
145
|
+
// #999-class guard: the pgrep pattern is assembled from concatenated
|
|
146
|
+
// quoted fragments, so its VALUE never appears literally in this
|
|
147
|
+
// script's own text — a shell whose command line carries the script
|
|
148
|
+
// (an sh -c wrapper) can never match itself. The /launched suffix
|
|
149
|
+
// anchors the pattern to THIS task's wrapper: a bare hwexec/<id>
|
|
150
|
+
// prefix would also match hwexec/<id>-suffix sibling tasks and break
|
|
151
|
+
// the per-task independence the claim protocol's model assumes.
|
|
152
|
+
`P="hwexec/""${id}""/launched"`,
|
|
153
|
+
`D="/tmp/"".hwexec/""${id}"`,
|
|
154
|
+
`i=0`,
|
|
155
|
+
`while [ "$i" -lt ${loops} ]; do`,
|
|
156
|
+
` grep -q '^exit:[0-9][0-9]*$' "$D/status" 2>/dev/null && break`,
|
|
157
|
+
` sleep 2`,
|
|
158
|
+
` i=$((i+1))`,
|
|
159
|
+
`done`,
|
|
160
|
+
`if [ -d "$D" ]; then echo "HW_DIR=1"; else echo "HW_DIR=0"; fi`,
|
|
161
|
+
`S=$(grep -m1 '^exit:[0-9][0-9]*$' "$D/status" 2>/dev/null || true)`,
|
|
162
|
+
`echo "HW_STATUS=$S"`,
|
|
163
|
+
// Missing pgrep (a procps-less image) must not read as dead: an
|
|
164
|
+
// unprobeable aliveness fails SAFE toward alive, because a false
|
|
165
|
+
// 'lost' verdict would send the caller to a new task_id while a copy
|
|
166
|
+
// still runs — the one direction the claim protocol exists to make
|
|
167
|
+
// impossible. The verdict still converges: the task's own completion
|
|
168
|
+
// writes the status file.
|
|
169
|
+
`if command -v pgrep > /dev/null 2>&1 && pgrep -f "$P" > /dev/null 2>&1; then echo "HW_ALIVE=1"; elif command -v pgrep > /dev/null 2>&1; then echo "HW_ALIVE=0"; else echo "HW_ALIVE=1"; fi`,
|
|
170
|
+
`if [ -f "$D/launched" ]; then echo "HW_LAUNCHED=1"; else echo "HW_LAUNCHED=0"; fi`,
|
|
171
|
+
`echo "HW_LOG_BEGIN"`,
|
|
172
|
+
`tail -c ${bytes} "$D/log" 2>/dev/null`,
|
|
173
|
+
`echo "HW_LOG_END"`,
|
|
174
|
+
].join('\n');
|
|
175
|
+
}
|
|
176
|
+
export function deriveHwexecVerdict(facts, knowTask) {
|
|
177
|
+
if (!facts.dir) {
|
|
178
|
+
// logTail is '' here by construction: the script's tail on a missing
|
|
179
|
+
// directory produces nothing — the field stays uniform for consumers.
|
|
180
|
+
return knowTask ? { verdict: 'lost', logTail: facts.logTail } : { verdict: 'unknown' };
|
|
181
|
+
}
|
|
182
|
+
const exitMatch = facts.status.match(/^exit:(\d+)$/);
|
|
183
|
+
if (exitMatch) {
|
|
184
|
+
return { verdict: 'done', exitCode: Number(exitMatch[1]), logTail: facts.logTail };
|
|
185
|
+
}
|
|
186
|
+
if (facts.alive) {
|
|
187
|
+
return { verdict: 'running', logTail: facts.logTail };
|
|
188
|
+
}
|
|
189
|
+
if (facts.launched) {
|
|
190
|
+
return { verdict: 'lost', logTail: facts.logTail };
|
|
191
|
+
}
|
|
192
|
+
return { verdict: 'never' };
|
|
193
|
+
}
|
|
194
|
+
const HW_LOG_BEGIN_MARKER = 'HW_LOG_BEGIN';
|
|
195
|
+
const HW_LOG_END_MARKER = 'HW_LOG_END';
|
|
196
|
+
// Anchored ^KEY= reader over a field region — the HW_* grammar's single
|
|
197
|
+
// lookup rule (the readDbField doctrine). Returns undefined when the field
|
|
198
|
+
// is absent, so presence and value stay distinguishable.
|
|
199
|
+
function readHwField(text, key) {
|
|
200
|
+
const m = text.match(new RegExp(`^${key}=(.*)$`, 'm'));
|
|
201
|
+
return m === null ? undefined : (m[1] ?? '').trim();
|
|
202
|
+
}
|
|
203
|
+
// Parse one poll exec's stdout into the facts. #946: strip OSC/CSI escapes
|
|
204
|
+
// and \r before the anchored lookups. The four verdict fields are
|
|
205
|
+
// presence-required — the script emits them unconditionally, so a missing
|
|
206
|
+
// field means the output was truncated or garbled, and an unreadable poll
|
|
207
|
+
// must FAIL instead of misjudging: a defaulted 'never'/'lost' would send
|
|
208
|
+
// the caller to a new task_id while a copy still runs.
|
|
209
|
+
export function parseHwexecPollOutput(stdout) {
|
|
210
|
+
const text = stripTerminalEscapes(stdout);
|
|
211
|
+
const beginIdx = text.indexOf(HW_LOG_BEGIN_MARKER);
|
|
212
|
+
const head = beginIdx === -1 ? text : text.slice(0, beginIdx);
|
|
213
|
+
let logTail = '';
|
|
214
|
+
if (beginIdx !== -1) {
|
|
215
|
+
const afterBegin = text.slice(beginIdx + HW_LOG_BEGIN_MARKER.length);
|
|
216
|
+
const endIdx = afterBegin.indexOf(HW_LOG_END_MARKER);
|
|
217
|
+
const raw = endIdx === -1 ? afterBegin : afterBegin.slice(0, endIdx);
|
|
218
|
+
logTail = raw.replace(/^\n/, '').replace(/\n$/, '');
|
|
219
|
+
}
|
|
220
|
+
const required = (key) => {
|
|
221
|
+
const value = readHwField(head, key);
|
|
222
|
+
if (value === undefined) {
|
|
223
|
+
throw new Error(`sandbox exec poll: unreadable output — the ${key} field is missing, so no verdict can be derived; retry the poll.`);
|
|
224
|
+
}
|
|
225
|
+
return value;
|
|
226
|
+
};
|
|
227
|
+
return {
|
|
228
|
+
dir: required('HW_DIR') === '1',
|
|
229
|
+
status: required('HW_STATUS'),
|
|
230
|
+
alive: required('HW_ALIVE') === '1',
|
|
231
|
+
launched: required('HW_LAUNCHED') === '1',
|
|
232
|
+
logTail,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
export function classifyHwexecStartOutput(stdout, taskId) {
|
|
236
|
+
const text = stripTerminalEscapes(stdout);
|
|
237
|
+
if (readHwField(text, 'HW_STARTED') === taskId)
|
|
238
|
+
return 'started';
|
|
239
|
+
if (readHwField(text, 'HW_DUP') === taskId)
|
|
240
|
+
return 'dup';
|
|
241
|
+
if (readHwField(text, 'HW_CLAIM_ERROR') === '1')
|
|
242
|
+
return 'claim_error';
|
|
243
|
+
return 'uncertain';
|
|
244
|
+
}
|
|
@@ -15,6 +15,7 @@ import { removeKooCli, removeObsConfig } from "./sandbox/uninstall-cleanup.js";
|
|
|
15
15
|
import { readReceipt, removeReceipt } from "./dep/receipts.js";
|
|
16
16
|
import { runSecretCommand } from "./lib/secret-vault/cli.js";
|
|
17
17
|
import { createProcessApproveIo, runApproveCommand, runPinCommand } from "./approvals-cli.js";
|
|
18
|
+
import { readConsentEvents } from "./approval-ledger.js";
|
|
18
19
|
import { custodyReport } from "./lib/secret-vault/custody.js";
|
|
19
20
|
import { vaultList } from "./lib/secret-vault/store.js";
|
|
20
21
|
import { detectCodeartsSandbox } from "./codearts-sandbox.js";
|
|
@@ -63,6 +64,7 @@ import { deployHermes, hermesDoctorMcpConfigured, hermesStatus, uninstallHermes
|
|
|
63
64
|
import { hermesDoctorSdkCheck } from "./agents/hermes-sdk.js";
|
|
64
65
|
import { codexDesktopStatus, codexSectionStatus, codexStatus, hasCodexCLI, installCodex, uninstallCodex, } from "./agents/codex.js";
|
|
65
66
|
import { codexDesktopDoctorMcpConfigured, deployCodexDesktop, uninstallCodexDesktop } from "./agents/codex-desktop.js";
|
|
67
|
+
import { codexDoctorApprovalRow } from "./agents/codex-config.js";
|
|
66
68
|
import { deployDsh, dshStatus, uninstallDsh } from "./agents/dsh.js";
|
|
67
69
|
import { dshDoctorMcpConfigured, dshPayloadDoctorSection } from "./agents/dsh-patch.js";
|
|
68
70
|
import { deployOpenCode, opencodeDoctorAskRule, opencodeDoctorMcpConfigured, opencodeDoctorSeam, opencodeStatus, uninstallOpenCode, } from "./agents/opencode.js";
|
|
@@ -105,7 +107,7 @@ async function checkForUpdate() {
|
|
|
105
107
|
// target can only be non-null when distTags carried a candidate, so the
|
|
106
108
|
// optional chain never short-circuits a reachable path.
|
|
107
109
|
const tag = distTags?.next && semverCompare(target, distTags.next) === 0 ? 'next' : 'latest';
|
|
108
|
-
console.log(`\n\x1b[33mℹ️ 检测到新版本:${target}(当前 ${pkgVersion},${tag} 频道)。建议运行 \`npx --yes huaweicloud-devkit@${tag} update\` 更新。\x1b[0m`);
|
|
110
|
+
console.log(`\n\x1b[33mℹ️ 检测到新版本:${target}(当前 ${pkgVersion},${tag} 频道)。建议运行 \`npx --yes --foreground-scripts huaweicloud-devkit@${tag} update\` 更新。\x1b[0m`);
|
|
109
111
|
}
|
|
110
112
|
}
|
|
111
113
|
// The .installed marker directory for a target. A lookup over
|
|
@@ -878,6 +880,35 @@ async function cmdDoctor() {
|
|
|
878
880
|
opencodeDoctorSeam(ctx);
|
|
879
881
|
opencodeDoctorAskRule(ctx);
|
|
880
882
|
}
|
|
883
|
+
// The codex client yield (PR-5): the per-tool approval_mode blocks the
|
|
884
|
+
// devkit payload's .mcp.json carries (agents/codex-config.ts records why
|
|
885
|
+
// the yield lives there, never in the user's config.toml). The row gates
|
|
886
|
+
// itself on the machine's codex relationship (no payload, no plugin, no
|
|
887
|
+
// desktop registration → silent), so it adds nothing to a codex-less
|
|
888
|
+
// doctor run. The desktop registration bit comes from the candidate the
|
|
889
|
+
// shell already probed above — passed in so the row never probes twice.
|
|
890
|
+
codexDoctorApprovalRow(ctx, codexDesktopDoctorMcpConfigured() !== null);
|
|
891
|
+
// Session standing consents (PR-3a's S3): the "remember for this
|
|
892
|
+
// session" grants the elicitation form's tick recorded in the ask-mode
|
|
893
|
+
// consent ledger. Listing only, zero rows print nothing: a clean home's
|
|
894
|
+
// doctor output stays byte-identical. A row is a RECORD of a grant the
|
|
895
|
+
// user ticked — the grant's operative lifetime is the devkit server
|
|
896
|
+
// process (it forgets on restart, fail-closed), so the line names what
|
|
897
|
+
// was consented and when, never a live permission claim.
|
|
898
|
+
try {
|
|
899
|
+
const standing = readConsentEvents().filter((event) => event.scope === 'session');
|
|
900
|
+
if (standing.length > 0) {
|
|
901
|
+
ctx.info('Session standing consents recorded in the consent ledger (each dies with the devkit server process):');
|
|
902
|
+
for (const grant of standing) {
|
|
903
|
+
console.log(` ${grant.tool} — args hash ${grant.argsHash.slice(0, 16)}, granted ` +
|
|
904
|
+
`${new Date(grant.grantedAt).toISOString()}, evidence ${grant.evidence}`);
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
catch {
|
|
909
|
+
// An unreadable ledger is not a health failure: doctor lists state, it
|
|
910
|
+
// never gates on it.
|
|
911
|
+
}
|
|
881
912
|
// Hermes MCP Python SDK (only checked when Hermes config is found).
|
|
882
913
|
hermesDoctorSdkCheck(ctx, mcpCfgTarget);
|
|
883
914
|
// hcloud CLI
|
|
@@ -976,6 +1007,9 @@ async function cmdDoctor() {
|
|
|
976
1007
|
}
|
|
977
1008
|
if (fail > 0) {
|
|
978
1009
|
console.log('\x1b[33mFix failures above, then restart your session.\x1b[0m');
|
|
1010
|
+
// A FAIL line is the command's verdict, so CI and scripts can gate on the
|
|
1011
|
+
// exit code: a doctor that prints [FAIL] and exits 0 is not a check.
|
|
1012
|
+
process.exitCode = 1;
|
|
979
1013
|
}
|
|
980
1014
|
if (fail === 0 && mcpConfigured) {
|
|
981
1015
|
console.log('\n\x1b[32mAll checks passed.\x1b[0m You can now describe your Huawei Cloud task');
|
|
@@ -996,6 +1030,7 @@ async function cmdUpdate() {
|
|
|
996
1030
|
console.log(BANNER);
|
|
997
1031
|
resolvePacksFlag(); // fail fast on bogus --packs before any file is copied
|
|
998
1032
|
const target = parseTarget();
|
|
1033
|
+
checkNode();
|
|
999
1034
|
await checkForUpdate();
|
|
1000
1035
|
// Reconcile the native dirs only when this run will actually place the new
|
|
1001
1036
|
// payload somewhere. A target whose server is absent gets "Not installed"
|
|
@@ -152,6 +152,10 @@ export const TOOL_DEFINITIONS_LITERALS = [
|
|
|
152
152
|
name: 'huaweicloud_sandbox_exec_one_shot',
|
|
153
153
|
description: packDescription('huaweicloud_sandbox_exec_one_shot'),
|
|
154
154
|
},
|
|
155
|
+
{
|
|
156
|
+
name: 'huaweicloud_sandbox_exec_poll',
|
|
157
|
+
description: packDescription('huaweicloud_sandbox_exec_poll'),
|
|
158
|
+
},
|
|
155
159
|
{
|
|
156
160
|
name: 'huaweicloud_sandbox_close_session',
|
|
157
161
|
description: packDescription('huaweicloud_sandbox_close_session'),
|
|
@@ -176,6 +180,10 @@ export const TOOL_DEFINITIONS_LITERALS = [
|
|
|
176
180
|
name: 'huaweicloud_sandbox_expose_tunnel',
|
|
177
181
|
description: packDescription('huaweicloud_sandbox_expose_tunnel'),
|
|
178
182
|
},
|
|
183
|
+
{
|
|
184
|
+
name: 'huaweicloud_sandbox_expose_poll',
|
|
185
|
+
description: packDescription('huaweicloud_sandbox_expose_poll'),
|
|
186
|
+
},
|
|
179
187
|
{
|
|
180
188
|
name: 'huaweicloud_sandbox_check_user',
|
|
181
189
|
description: packDescription('huaweicloud_sandbox_check_user'),
|
|
@@ -192,6 +200,10 @@ export const TOOL_DEFINITIONS_LITERALS = [
|
|
|
192
200
|
name: 'huaweicloud_sandbox_credentials',
|
|
193
201
|
description: packDescription('huaweicloud_sandbox_credentials'),
|
|
194
202
|
},
|
|
203
|
+
{
|
|
204
|
+
name: 'huaweicloud_sandbox_shutdown',
|
|
205
|
+
description: packDescription('huaweicloud_sandbox_shutdown'),
|
|
206
|
+
},
|
|
195
207
|
{
|
|
196
208
|
name: 'huaweicloud_voucher_status',
|
|
197
209
|
description: packDescription('huaweicloud_voucher_status'),
|
|
@@ -246,7 +258,7 @@ export const TOOL_DEFINITIONS_LITERALS = [
|
|
|
246
258
|
},
|
|
247
259
|
{
|
|
248
260
|
name: 'huaweicloud_packs_configure',
|
|
249
|
-
description: 'Enable or disable capability packs for THIS session, or reset to the operator posture. Session-scoped: the change lives in this server process only and the next session restart restores the DEVKIT_PACKS posture the operator configured. Takes enable (pack ids to add), disable (pack ids to remove; core cannot be disabled), and reset (drop the session override). The refreshed tool list is pushed to the agent immediately.
|
|
261
|
+
description: 'Enable or disable capability packs for THIS session, or reset to the operator posture. Session-scoped: the change lives in this server process only and the next session restart restores the DEVKIT_PACKS posture the operator configured. Takes enable (pack ids to add), disable (pack ids to remove; core cannot be disabled), and reset (drop the session override). The refreshed tool list is pushed to the agent immediately. Approval-gated in every mode because widening the disclosure face is the consequence: the no-token call returns USER_CONFIRMATION_REQUIRED naming the pack ids with the approve line for the user\u2019s own terminal (token mode), and under DEVKIT_APPROVAL_MODE=ask the server raises the confirmation itself (a form on a capable client, else an ASK_CONFIRMATION_REQUIRED chat round-trip). Stdio agent sessions only — surfaces with no session state are refused outright. The persistent equivalent is the operator CLI (npx huaweicloud-devkit packs enable <ids> --target <agent>); ask the operator to run it and restart the agent.',
|
|
250
262
|
},
|
|
251
263
|
{
|
|
252
264
|
name: 'huaweicloud_gateway_list_tools',
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { PACK_IDS } from "./lib/pack-types.js";
|
|
3
|
-
import { looseObject, vendorConfirmed } from "./lib/tool-schema-parts.js";
|
|
3
|
+
import { looseObject, vendorConfirmed, approvalTokenArg, approvedByUserArg, confirmLanguageArg, } from "./lib/tool-schema-parts.js";
|
|
4
|
+
import { APPROVAL_TOOLS } from "./approval-roster.js";
|
|
4
5
|
import { UPDATE_TOOL_SCHEMAS } from "./packs/update/tools.js";
|
|
5
6
|
import { HUAWEICLOUD_OPEN_MCP_TOOL_SCHEMAS } from "./packs/huaweicloud-open-mcp/tools.js";
|
|
6
7
|
import { HUAWEICLOUD_CLI_TOOL_SCHEMAS } from "./packs/huaweicloud-cli/tools.js";
|
|
@@ -28,7 +29,7 @@ const TOOL_SCHEMAS = {
|
|
|
28
29
|
command: z.string().describe('The exact command text to inspect.'),
|
|
29
30
|
}),
|
|
30
31
|
huaweicloud_hook_check_artifacts: z.looseObject({
|
|
31
|
-
artifacts: z.array(artifactsItem),
|
|
32
|
+
artifacts: z.array(artifactsItem).describe('Artifacts to inspect, each with a path and its full text content.'),
|
|
32
33
|
}),
|
|
33
34
|
huaweicloud_hook_check_deploy_plan: z.looseObject({
|
|
34
35
|
plan: z
|
|
@@ -43,11 +44,17 @@ const TOOL_SCHEMAS = {
|
|
|
43
44
|
.describe('Developer intent to route, such as deploy app, use API, debug error, or inspect resources.'),
|
|
44
45
|
}),
|
|
45
46
|
huaweicloud_explain_error: z.looseObject({
|
|
46
|
-
service: z.string().optional(),
|
|
47
|
-
errorCode: z
|
|
47
|
+
service: z.string().optional().describe('Optional service name (e.g., ECS, VPC, APIG) to route the lookup.'),
|
|
48
|
+
errorCode: z
|
|
49
|
+
.string()
|
|
50
|
+
.optional()
|
|
51
|
+
.describe('The error code to explain, such as APIGW.0301 or Ecs.0038. Extracted from message when omitted.'),
|
|
48
52
|
code: z.string().optional().describe('Alias of errorCode, accepted for compatibility. Prefer errorCode.'),
|
|
49
|
-
message: z
|
|
50
|
-
|
|
53
|
+
message: z
|
|
54
|
+
.string()
|
|
55
|
+
.optional()
|
|
56
|
+
.describe('Optional raw error message; the error code is extracted from it when errorCode is not provided.'),
|
|
57
|
+
requestId: z.string().optional().describe('Optional request ID from the failed response, for support escalation.'),
|
|
51
58
|
}),
|
|
52
59
|
huaweicloud_search_docs: z.looseObject({
|
|
53
60
|
query: z.string().describe('Search query across skill descriptions and documentation.'),
|
|
@@ -134,8 +141,27 @@ const TOOL_SCHEMAS = {
|
|
|
134
141
|
.boolean()
|
|
135
142
|
.optional()
|
|
136
143
|
.describe('Drop the session override and return to the operator DEVKIT_PACKS posture.'),
|
|
144
|
+
approvalToken: approvalTokenArg,
|
|
145
|
+
approvedByUser: approvedByUserArg,
|
|
137
146
|
}),
|
|
138
147
|
};
|
|
148
|
+
// The confirm-language hint rides every roster tool — the approval
|
|
149
|
+
// domain's parameter, injected HERE rather than in any pack's schema
|
|
150
|
+
// (the field belongs to the roster concept, which is cross-pack; the pack
|
|
151
|
+
// files stay untouched and the pack-boundaries guard stays clean). The
|
|
152
|
+
// roster is a zod-free leaf (approval-roster.ts), so this import adds no
|
|
153
|
+
// pack edge. The extend preserves each schema's loose catchall
|
|
154
|
+
// (probe-verified on zod 4.6.7), so the #530 pass-through leniency is
|
|
155
|
+
// unchanged; the field stays optional everywhere (a missing value must
|
|
156
|
+
// reach the gate, same doctrine as the other approval args). The legacy
|
|
157
|
+
// registry snapshot gate consults DELIBERATE_ADDITIONS for this property
|
|
158
|
+
// on every non-exempt roster tool.
|
|
159
|
+
for (const name of APPROVAL_TOOLS) {
|
|
160
|
+
const base = TOOL_SCHEMAS[name];
|
|
161
|
+
TOOL_SCHEMAS[name] = base.extend({
|
|
162
|
+
confirmLanguage: confirmLanguageArg,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
139
165
|
export function getToolSchema(name) {
|
|
140
166
|
return TOOL_SCHEMAS[name];
|
|
141
167
|
}
|