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.
Files changed (161) hide show
  1. package/README.md +3 -1
  2. package/package.json +3 -1
  3. package/plugins/huaweicloud-core/.claude-plugin/plugin.json +16 -3
  4. package/plugins/huaweicloud-core/.codex-plugin/plugin.json +16 -3
  5. package/plugins/huaweicloud-core/.cursor-plugin/plugin.json +16 -3
  6. package/plugins/huaweicloud-core/.hermes-plugin/plugin.json +16 -3
  7. package/plugins/huaweicloud-core/.mcp.json +55 -1
  8. package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +16 -3
  9. package/plugins/huaweicloud-core/dist/agents/codex-config.js +374 -0
  10. package/plugins/huaweicloud-core/dist/agents/codex-desktop.js +8 -1
  11. package/plugins/huaweicloud-core/dist/agents/codex.js +9 -0
  12. package/plugins/huaweicloud-core/dist/agents/opencode-config.js +157 -31
  13. package/plugins/huaweicloud-core/dist/agents/opencode.js +129 -1
  14. package/plugins/huaweicloud-core/dist/approval-gate.js +1185 -0
  15. package/plugins/huaweicloud-core/dist/approval-ledger.js +2331 -0
  16. package/plugins/huaweicloud-core/dist/approval-roster.js +89 -0
  17. package/plugins/huaweicloud-core/dist/approval-types.js +1 -0
  18. package/plugins/huaweicloud-core/dist/approvals-cli.js +4 -4
  19. package/plugins/huaweicloud-core/dist/data/icons-manifest.v1.json +23 -5
  20. package/plugins/huaweicloud-core/dist/dep/receipts.js +65 -5
  21. package/plugins/huaweicloud-core/dist/hcloud-cli.js +1 -1
  22. package/plugins/huaweicloud-core/dist/hcloud-plan.js +77 -56
  23. package/plugins/huaweicloud-core/dist/lib/approval-mode.js +32 -0
  24. package/plugins/huaweicloud-core/dist/lib/approval-tokens.js +18 -4
  25. package/plugins/huaweicloud-core/dist/lib/call-trace.js +7 -14
  26. package/plugins/huaweicloud-core/dist/lib/confirm-language.js +50 -0
  27. package/plugins/huaweicloud-core/dist/lib/credentials.js +9 -9
  28. package/plugins/huaweicloud-core/dist/lib/hdkit/hdkit-gate.js +1398 -0
  29. package/plugins/huaweicloud-core/dist/lib/hdkit/hdkitservice-api.js +362 -32
  30. package/plugins/huaweicloud-core/dist/lib/hdkit/sandbox-pool.js +6 -16
  31. package/plugins/huaweicloud-core/dist/lib/opencode-ask-rule.js +262 -0
  32. package/plugins/huaweicloud-core/dist/lib/opencode-saved-perms.js +282 -0
  33. package/plugins/huaweicloud-core/dist/lib/supplemental-redaction.js +116 -0
  34. package/plugins/huaweicloud-core/dist/lib/tool-schema-parts.js +31 -0
  35. package/plugins/huaweicloud-core/dist/lib/workspace-glob.js +442 -0
  36. package/plugins/huaweicloud-core/dist/mcp-config-io.js +28 -1
  37. package/plugins/huaweicloud-core/dist/mcp-protocol.js +75 -4
  38. package/plugins/huaweicloud-core/dist/mcp-server.js +6560 -898
  39. package/plugins/huaweicloud-core/dist/mcp-server.js.map +4 -4
  40. package/plugins/huaweicloud-core/dist/mcp-stdio-transport.js +14 -4
  41. package/plugins/huaweicloud-core/dist/packs/auth/approval.js +249 -0
  42. package/plugins/huaweicloud-core/dist/packs/auth/tools.js +44 -44
  43. package/plugins/huaweicloud-core/dist/packs/huaweicloud-cli/tools.js +119 -112
  44. package/plugins/huaweicloud-core/dist/packs/obs/approval.js +110 -0
  45. package/plugins/huaweicloud-core/dist/packs/obs/tools.js +7 -2
  46. package/plugins/huaweicloud-core/dist/packs/registry.js +19 -1
  47. package/plugins/huaweicloud-core/dist/packs/sandbox/approval.js +245 -0
  48. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-account.js +156 -23
  49. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-credentials.js +13 -1
  50. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-hwexec.js +136 -0
  51. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-session.js +11 -1
  52. package/plugins/huaweicloud-core/dist/packs/sandbox/handlers-tunnel.js +1 -0
  53. package/plugins/huaweicloud-core/dist/packs/sandbox/schemas.js +79 -9
  54. package/plugins/huaweicloud-core/dist/packs/sandbox/tools.js +28 -9
  55. package/plugins/huaweicloud-core/dist/packs/secrets/approval.js +46 -0
  56. package/plugins/huaweicloud-core/dist/packs/secrets/tools.js +4 -1
  57. package/plugins/huaweicloud-core/dist/packs/update/approval.js +79 -0
  58. package/plugins/huaweicloud-core/dist/packs/update/tools.js +8 -1
  59. package/plugins/huaweicloud-core/dist/packs/voucher/tools.js +1 -1
  60. package/plugins/huaweicloud-core/dist/packs-configure.js +74 -0
  61. package/plugins/huaweicloud-core/dist/safety/classify-text.js +36 -0
  62. package/plugins/huaweicloud-core/dist/safety/policy.js +2 -0
  63. package/plugins/huaweicloud-core/dist/sandbox/deploy-check.js +1 -1
  64. package/plugins/huaweicloud-core/dist/sandbox/devbridge-auth.js +65 -14
  65. package/plugins/huaweicloud-core/dist/sandbox/devbridge-cleanup.js +422 -0
  66. package/plugins/huaweicloud-core/dist/sandbox/devbridge-expose-flow.js +66 -16
  67. package/plugins/huaweicloud-core/dist/sandbox/devbridge-expose.js +13 -10
  68. package/plugins/huaweicloud-core/dist/sandbox/devbridge-keepalive.js +42 -2
  69. package/plugins/huaweicloud-core/dist/sandbox/devbridge-key.js +11 -3
  70. package/plugins/huaweicloud-core/dist/sandbox/devbridge-tunnel.js +6 -0
  71. package/plugins/huaweicloud-core/dist/sandbox/devbridge-validation.js +10 -1
  72. package/plugins/huaweicloud-core/dist/sandbox/hwexec-task.js +244 -0
  73. package/plugins/huaweicloud-core/dist/setup-cli.js +42 -4
  74. package/plugins/huaweicloud-core/dist/tool-definitions.js +9 -1
  75. package/plugins/huaweicloud-core/dist/tool-schemas.js +32 -6
  76. package/plugins/huaweicloud-core/dist/tools.js +76 -9
  77. package/plugins/huaweicloud-core/dist/update-registry.js +358 -5
  78. package/plugins/huaweicloud-core/dist/update-upgrade.js +1083 -14
  79. package/plugins/huaweicloud-core/dist/vendor-gate.js +2 -2
  80. package/plugins/huaweicloud-core/hooks/huaweicloud-safety.mjs +150 -1
  81. package/plugins/huaweicloud-core/hooks/huaweicloud-safety.py +53 -3
  82. package/plugins/huaweicloud-core/openclaw.plugin.json +1 -1
  83. package/plugins/huaweicloud-core/safety/policy.json +18 -11
  84. package/plugins/huaweicloud-core/safety/rules/cloud-risk-rules.json +114 -10
  85. package/plugins/huaweicloud-core/skills/huawei-sandbox/SKILL.md +190 -138
  86. package/plugins/huaweicloud-core/skills/huawei-sandbox/references/resource-pool.md +36 -12
  87. package/plugins/huaweicloud-core/skills/huawei-voucher/SKILL.md +2 -0
  88. package/plugins/huaweicloud-core/skills/huaweicloud-cli-and-auth/SKILL.md +5 -5
  89. package/plugins/huaweicloud-core/skills/huaweicloud-safety/SKILL.md +13 -8
  90. package/plugins/huaweicloud-core/skills/huaweicloud-safety/references/approvals.md +78 -23
  91. package/plugins/huaweicloud-core/skills/huaweicloud-troubleshooting/SKILL.md +21 -19
  92. package/plugins/huaweicloud-core/src/agents/codex-config.ts +432 -0
  93. package/plugins/huaweicloud-core/src/agents/codex-desktop.ts +8 -1
  94. package/plugins/huaweicloud-core/src/agents/codex.ts +10 -0
  95. package/plugins/huaweicloud-core/src/agents/opencode-config.ts +198 -30
  96. package/plugins/huaweicloud-core/src/agents/opencode.ts +157 -1
  97. package/plugins/huaweicloud-core/src/approval-gate.ts +1306 -0
  98. package/plugins/huaweicloud-core/src/approval-ledger.ts +2446 -0
  99. package/plugins/huaweicloud-core/src/approval-roster.ts +127 -0
  100. package/plugins/huaweicloud-core/src/approval-types.ts +237 -0
  101. package/plugins/huaweicloud-core/src/approvals-cli.ts +4 -4
  102. package/plugins/huaweicloud-core/src/data/icons-manifest.v1.json +23 -5
  103. package/plugins/huaweicloud-core/src/dep/receipts.ts +84 -5
  104. package/plugins/huaweicloud-core/src/hcloud-cli.ts +3 -0
  105. package/plugins/huaweicloud-core/src/hcloud-plan.ts +93 -63
  106. package/plugins/huaweicloud-core/src/lib/approval-mode.ts +34 -0
  107. package/plugins/huaweicloud-core/src/lib/approval-tokens.ts +19 -4
  108. package/plugins/huaweicloud-core/src/lib/call-trace.ts +7 -17
  109. package/plugins/huaweicloud-core/src/lib/confirm-language.ts +51 -0
  110. package/plugins/huaweicloud-core/src/lib/credentials.ts +9 -8
  111. package/plugins/huaweicloud-core/src/lib/hdkit/hdkit-gate.ts +1428 -0
  112. package/plugins/huaweicloud-core/src/lib/hdkit/hdkitservice-api.ts +377 -30
  113. package/plugins/huaweicloud-core/src/lib/hdkit/sandbox-pool.ts +8 -15
  114. package/plugins/huaweicloud-core/src/lib/opencode-ask-rule.ts +350 -0
  115. package/plugins/huaweicloud-core/src/lib/opencode-saved-perms.ts +354 -0
  116. package/plugins/huaweicloud-core/src/lib/supplemental-redaction.ts +129 -0
  117. package/plugins/huaweicloud-core/src/lib/tool-schema-parts.ts +40 -0
  118. package/plugins/huaweicloud-core/src/lib/workspace-glob.ts +414 -0
  119. package/plugins/huaweicloud-core/src/mcp-config-io.ts +27 -1
  120. package/plugins/huaweicloud-core/src/mcp-protocol.ts +88 -5
  121. package/plugins/huaweicloud-core/src/mcp-server.ts +13 -0
  122. package/plugins/huaweicloud-core/src/mcp-stdio-transport.ts +14 -4
  123. package/plugins/huaweicloud-core/src/packs/auth/approval.ts +302 -0
  124. package/plugins/huaweicloud-core/src/packs/auth/tools.ts +54 -45
  125. package/plugins/huaweicloud-core/src/packs/huaweicloud-cli/tools.ts +139 -120
  126. package/plugins/huaweicloud-core/src/packs/obs/approval.ts +122 -0
  127. package/plugins/huaweicloud-core/src/packs/obs/tools.ts +7 -2
  128. package/plugins/huaweicloud-core/src/packs/registry.ts +42 -1
  129. package/plugins/huaweicloud-core/src/packs/sandbox/approval.ts +296 -0
  130. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-account.ts +168 -23
  131. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-credentials.ts +11 -1
  132. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-hwexec.ts +228 -0
  133. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-session.ts +11 -1
  134. package/plugins/huaweicloud-core/src/packs/sandbox/handlers-tunnel.ts +1 -0
  135. package/plugins/huaweicloud-core/src/packs/sandbox/schemas.ts +100 -8
  136. package/plugins/huaweicloud-core/src/packs/sandbox/tools.ts +31 -8
  137. package/plugins/huaweicloud-core/src/packs/secrets/approval.ts +50 -0
  138. package/plugins/huaweicloud-core/src/packs/secrets/tools.ts +4 -1
  139. package/plugins/huaweicloud-core/src/packs/update/approval.ts +87 -0
  140. package/plugins/huaweicloud-core/src/packs/update/tools.ts +8 -1
  141. package/plugins/huaweicloud-core/src/packs/voucher/tools.ts +1 -1
  142. package/plugins/huaweicloud-core/src/packs-configure.ts +75 -0
  143. package/plugins/huaweicloud-core/src/safety/classify-text.ts +40 -0
  144. package/plugins/huaweicloud-core/src/safety/policy.ts +7 -0
  145. package/plugins/huaweicloud-core/src/sandbox/deploy-check.ts +1 -1
  146. package/plugins/huaweicloud-core/src/sandbox/devbridge-auth.ts +74 -14
  147. package/plugins/huaweicloud-core/src/sandbox/devbridge-cleanup.ts +509 -0
  148. package/plugins/huaweicloud-core/src/sandbox/devbridge-expose-flow.ts +70 -18
  149. package/plugins/huaweicloud-core/src/sandbox/devbridge-expose.ts +26 -10
  150. package/plugins/huaweicloud-core/src/sandbox/devbridge-keepalive.ts +41 -2
  151. package/plugins/huaweicloud-core/src/sandbox/devbridge-key.ts +9 -3
  152. package/plugins/huaweicloud-core/src/sandbox/devbridge-tunnel.ts +24 -0
  153. package/plugins/huaweicloud-core/src/sandbox/devbridge-validation.ts +11 -1
  154. package/plugins/huaweicloud-core/src/sandbox/hwexec-task.ts +304 -0
  155. package/plugins/huaweicloud-core/src/setup-cli.ts +45 -3
  156. package/plugins/huaweicloud-core/src/tool-definitions.ts +9 -1
  157. package/plugins/huaweicloud-core/src/tool-schemas.ts +39 -6
  158. package/plugins/huaweicloud-core/src/tools.ts +124 -10
  159. package/plugins/huaweicloud-core/src/update-registry.ts +340 -5
  160. package/plugins/huaweicloud-core/src/update-upgrade.ts +1130 -14
  161. package/plugins/huaweicloud-core/src/vendor-gate.ts +2 -2
@@ -0,0 +1,127 @@
1
+ // The approval-gate roster: which tools the dispatch-layer approval gate
2
+ // covers. A const string tuple, zod-free, import-free — the .mjs hook twin
3
+ // and the opencode ask-rule writer both import this shape from the compiled
4
+ // tree, and neither may pull the SDK/zod graph (the hook runs before dist
5
+ // exists in a raw checkout; the writer lives in the unbundled setup-cli
6
+ // graph). The gate (approval-gate.ts) resolves specs from packs/registry.ts's
7
+ // APPROVAL_SPECS merge, whose satisfies check is keyed by THIS tuple's
8
+ // literal union — that coupling is the reason for `as const`: a
9
+ // ReadonlyArray<string> widens the key type to string and silently inerts
10
+ // the compile-time closure (an interrogate-round-1 finding).
11
+ //
12
+ // PR-1 populated the roster with the hcloud pair's run face; PR-3a added
13
+ // the sandbox pack's eight mutating faces (connect, the two exec tools,
14
+ // the three tunnel faces, sign_agreement, credentials); the port-pr6 wave
15
+ // added shutdown — the irreversible core-hour stop (an unrostered shutdown
16
+ // is a safety hole: the tool exists but nothing gates it); PR-3b adds the auth
17
+ // account-switch pair — the account switch can redirect every downstream
18
+ // approved write to a different account, so it earns a human present on
19
+ // every call; PR-3c adds the obs pair as the first classified members
20
+ // (action=get is a signed read and must never confirm) and the three
21
+ // always tools (upgrade replaces its description-level consent with the
22
+ // mechanical gate; secret_delete is destructive with no version history;
23
+ // packs_configure widens the disclosure face). secret_set stays OFF the
24
+ // roster — the user is the plaintext source and is therefore present —
25
+ // and setup_obs_config stays off as the flagged boundary item. Two
26
+ // lists, not one, because the two flavors need different downstream
27
+ // facts: always tools get client allow rules on install (the yield
28
+ // posture), classified tools additionally need a classify in their spec
29
+ // (pinned by structure.test.ts: every APPROVAL_CLASSIFIED_TOOLS entry
30
+ // must provide one).
31
+
32
+ export const APPROVAL_TOOLS = [
33
+ 'huaweicloud_run_approved_command',
34
+ 'huaweicloud_sandbox_connect',
35
+ 'huaweicloud_sandbox_exec_with_session',
36
+ 'huaweicloud_sandbox_exec_one_shot',
37
+ 'huaweicloud_sandbox_expose_tunnel',
38
+ 'huaweicloud_sandbox_renew_tunnel',
39
+ 'huaweicloud_sandbox_keepalive_watchdog',
40
+ 'huaweicloud_sandbox_sign_agreement',
41
+ 'huaweicloud_sandbox_credentials',
42
+ 'huaweicloud_sandbox_shutdown',
43
+ 'huaweicloud_auth_init',
44
+ 'huaweicloud_auth_switch',
45
+ 'huaweicloud_obs_set_website_config',
46
+ 'huaweicloud_obs_set_cors',
47
+ 'huaweicloud_upgrade',
48
+ 'huaweicloud_secret_delete',
49
+ 'huaweicloud_packs_configure',
50
+ ] as const;
51
+
52
+ // The classified members: PR-3a's exec pair and PR-3c's obs pair. A const
53
+ // tuple by the same round-1..5 widening doctrine as APPROVAL_TOOLS (the
54
+ // compile-time classified-provides-classify consumers key on the runtime
55
+ // list, and a widened element would inert them) — structure.test.ts pins
56
+ // the shape.
57
+ export const APPROVAL_CLASSIFIED_TOOLS = [
58
+ 'huaweicloud_sandbox_exec_with_session',
59
+ 'huaweicloud_sandbox_exec_one_shot',
60
+ 'huaweicloud_obs_set_website_config',
61
+ 'huaweicloud_obs_set_cors',
62
+ ] as const;
63
+
64
+ // Each roster member's MCP payload shape class (round 10, finding 3): the
65
+ // hook exemption admits a roster-attributed payload only when it matches
66
+ // ITS tool's row here. The run face carries its argv as an `args` array;
67
+ // the sandbox exec faces carry a `command` string — a payload shape the
68
+ // round-1/round-2 exemption had to reject on the run face's name (a command
69
+ // string there is the Bash-shaped smuggle the shape test exists to block),
70
+ // so without this table the sandbox registrations could never reach the
71
+ // server gate on hook-bearing harnesses. The Record is keyed by the roster
72
+ // tuple, so a registration that widens APPROVAL_TOOLS fails the build until
73
+ // its shape row lands with it. The hook's shape switch knows 'argsArray',
74
+ // 'commandString', and 'structured': the first two are the exempt classes
75
+ // (with different skip sets); 'structured' declares a no-command-surface
76
+ // payload — the hook branch returns no exemption for it, and full
77
+ // classification stands (fail-closed: their payload shapes classify clean,
78
+ // and any deny the classifier ever adds still blocks the call at the hook
79
+ // layer, while a stuffed command/argv on those names can never borrow the
80
+ // exempt classes). The auth pair (PR-3b) rides 'structured' too: its named
81
+ // credential fields are a no-command-surface payload, and the server gate
82
+ // does not classify that payload text. The fallback below exists ONLY for
83
+ // a MISSING row (an older roster leaf or the landing transition), never
84
+ // for a present row the hook does not know.
85
+ // The Record is keyed by the roster tuple inline (this module is
86
+ // import-free — it cannot take ApprovalRosterName from the registry, so
87
+ // the tuple is widened here the same way the registry widens it).
88
+ // PR-3c's registrations (obs config, upgrade, secret_delete,
89
+ // packs_configure) ride 'structured' like PR-3a's lifecycle faces and
90
+ // PR-3b's auth pair: plain argument payloads, no command surface, no
91
+ // exemption (measured: every real payload classifies allow, so the calls
92
+ // reach the server gate with full hook classification standing). The
93
+ // port-pr6 shutdown row rides 'structured' the same way — plain id
94
+ // fields (session_id/dev_stage_id/workspace_id), no command surface.
95
+ export type ApprovalToolInputShape = 'argsArray' | 'commandString' | 'structured';
96
+
97
+ export const APPROVAL_TOOL_INPUT_SHAPES: Record<(typeof APPROVAL_TOOLS)[number], ApprovalToolInputShape> = {
98
+ huaweicloud_run_approved_command: 'argsArray',
99
+ huaweicloud_sandbox_connect: 'structured',
100
+ huaweicloud_sandbox_exec_with_session: 'commandString',
101
+ huaweicloud_sandbox_exec_one_shot: 'commandString',
102
+ huaweicloud_sandbox_expose_tunnel: 'structured',
103
+ huaweicloud_sandbox_renew_tunnel: 'structured',
104
+ huaweicloud_sandbox_keepalive_watchdog: 'structured',
105
+ huaweicloud_sandbox_sign_agreement: 'structured',
106
+ huaweicloud_sandbox_credentials: 'structured',
107
+ huaweicloud_sandbox_shutdown: 'structured',
108
+ huaweicloud_auth_init: 'structured',
109
+ huaweicloud_auth_switch: 'structured',
110
+ huaweicloud_obs_set_website_config: 'structured',
111
+ huaweicloud_obs_set_cors: 'structured',
112
+ huaweicloud_upgrade: 'structured',
113
+ huaweicloud_secret_delete: 'structured',
114
+ huaweicloud_packs_configure: 'structured',
115
+ };
116
+
117
+ // The client-facing permission action opencode namespaces a roster tool
118
+ // under: `<mcp server key>_<tool>`, the key being our `.mcp.json` server name
119
+ // (measured on 2.2.7, and byte-identical across the 1.19 V1 key and the 2.x
120
+ // permission action). One home for the derivation, so the doctor's hygiene
121
+ // reader (lib/opencode-saved-perms.ts), the ask-rule writer, and the doctor
122
+ // can never drift onto different spellings of the same grant.
123
+ export const APPROVAL_MCP_SERVER = 'huaweicloud-devkit';
124
+
125
+ export function approvalToolAction(tool: string): string {
126
+ return `${APPROVAL_MCP_SERVER}_${tool}`;
127
+ }
@@ -0,0 +1,237 @@
1
+ // The generalized approval gate's vocabulary: the spec a tool's owner
2
+ // registers, and the consent event the ledger records. Zod-free by design
3
+ // — the bundled mcp-server graph, the hook graph (the .mjs twin imports
4
+ // only the roster leaf), and PR-2's unbundled opencode-writer graph all
5
+ // consume this shape. The only import is type-only (erased at runtime, the
6
+ // pack-types.ts precedent), so the roster leaf (approval-roster.ts) stays
7
+ // import-free for the hook's src fallback and this module adds no runtime
8
+ // edge to any graph.
9
+ //
10
+ // PR-1 registers one tool (huaweicloud_run_approved_command, tokenSource
11
+ // 'plan-face'); the pack registrations land in PR-3. The shape below is
12
+ // the whole program's contract surface, landed once so later PRs only add
13
+ // data.
14
+ import type { ToolArgs, CallToolOptions } from './tools.ts';
15
+
16
+ // Which flavor of gate a registered tool carries. 'always' engages the
17
+ // approval gate on every call; 'classified' first consults the pure
18
+ // classify function and engages only when it says the content requires a
19
+ // human (ApprovalCoreMint's classify-before-mint: destructive content is a
20
+ // disabled guard at the gate face, never a minted token the run then
21
+ // denies — NoDoomedToken).
22
+ export type GateFlavor = 'always' | 'classified';
23
+
24
+ // Where the token that spends an approval comes from. 'plan-face' keeps
25
+ // the trunk contract for the hcloud pair: the plan face
26
+ // (planHcloudCommand) is the ONLY minter, so a no-token run call returns
27
+ // CONFIRM_TOKEN_NOT_FOUND and the gate mints nothing. 'gate' is every
28
+ // PR-3 registration: the gate itself mints on the first no-token call and
29
+ // returns the USER_CONFIRMATION_REQUIRED envelope with the fresh
30
+ // approvalToken, executing nothing.
31
+ export type ApprovalTokenSource = 'plan-face' | 'gate';
32
+
33
+ // The consent channel a ledger entry records. 'terminal' is the approve CLI
34
+ // (PIN-checked, the human's own TTY). 'elicitation' is the server-raised
35
+ // form the gate sends from inside a tool call: the human answered the
36
+ // client's own form UI, so the acceptance is machine-verified evidence of a
37
+ // human answer (not human-PRESENT: the client relayed it). 'posture' is the
38
+ // T3 chat round-trip's attested retry: the model reports that the user
39
+ // approved in chat, with no mechanical proof a human answered — posture
40
+ // trust, labeled as such on every teaching surface. Neither tier is a client
41
+ // permission popup; the client's own rules no longer gate the call.
42
+ export type ConsentEvidence = 'terminal' | 'elicitation' | 'posture';
43
+
44
+ // The result a classified tool's pure classify function reports:
45
+ // 'required' engages the approval gate (and, at consume time on a
46
+ // plan-face tool, is exactly the grant requirement the trunk strict plan
47
+ // computed — a read-classified command executes on an unconfirmed token);
48
+ // 'none' lets the call pass through ungated.
49
+ export type ClassifyVerdict = 'required' | 'none';
50
+
51
+ // What a registered tool declares to the dispatch-layer gate. Every spec
52
+ // function operates on the BINDING VALUE — normalizeArgs(args) when the
53
+ // tool provides one, the raw args otherwise — so the gate hashes, guards,
54
+ // and summarizes exactly the value the token binds, never a wrapper-noise
55
+ // variant of it.
56
+ export interface ApprovalSpec {
57
+ // The capability domain the gate protects ('cli', 'sandbox', 'auth',
58
+ // 'obs', 'secrets', 'packs'). A seam for later per-domain reporting;
59
+ // per Appendix B there is deliberately no second mode knob.
60
+ domain: string;
61
+ flavor: GateFlavor;
62
+ tokenSource: ApprovalTokenSource;
63
+ // Content classification over the binding value. For a classified
64
+ // flavor it gates engagement (before any mint). For the plan-face hcloud
65
+ // tool it answers the consume's requireGrant, replacing the strict
66
+ // plan's userConfirmation.needed with the same pure verdict.
67
+ classify?: (bindingValue: unknown, opts: CallToolOptions) => ClassifyVerdict;
68
+ // Effective-args binding: the value whose hash the token binds and the
69
+ // ledger records. The hcloud pair strips a leading bin token, so a run
70
+ // call that echoes the plan verbatim and one that sends the cleaned
71
+ // args bind identically (2026-11-05 UX report #6).
72
+ normalizeArgs?: (args: ToolArgs) => unknown;
73
+ // Execution-readiness floor the gate enforces BEFORE the token is
74
+ // consumed (the hcloud placeholder-secret guard): throwing rejects the
75
+ // call without burning the token, so the guidance stays followable on
76
+ // the same approval. Mode-aware because the re-run wording differs —
77
+ // token mode keeps the guidance on the same approval, ask mode has no
78
+ // token to reference.
79
+ assertArgsExecutable?: (bindingValue: unknown, mode: 'token' | 'ask') => void;
80
+ // True when the tool's own handler refuses calls that lack the stdio
81
+ // session seam (packs_configure: the refusal lives inside the handler,
82
+ // downstream of any dispatch-layer gate). The gate checks
83
+ // opts.onPacksChanged presence BEFORE engaging, mirroring the handler's
84
+ // own refusal, so a no-seam call returns the stdio-only refusal with no
85
+ // token minted and no ledger entry (ApprovalCoreMint GateMintSeam's
86
+ // disabled-guard posture).
87
+ requiresSessionSeam?: boolean;
88
+ // The command-forward anchor (the operator-approved display field): the
89
+ // accepted executable lines for this call, derived from the binding
90
+ // value. A call that carries the tool's `command` field must match one of
91
+ // them exactly (the gate compares before any mint, consent record, or
92
+ // execution); a call that omits the field keeps the legacy shape and is
93
+ // untouched. Tools whose args carry no executable line (the later pack
94
+ // registrations) simply leave it out, and the field is then ignored.
95
+ commandAnchor?: (bindingValue: unknown) => string[];
96
+ // The redacted popup view plus the pin-view binding: one or two short
97
+ // lines naming the tool and the pinned arguments (never the raw argument
98
+ // stream — a popup must not leak secrets), the binding-value hash, the
99
+ // pin view the mismatch path compares against the stored entry, and —
100
+ // when the tool has an executable line — the redacted command string the
101
+ // consent row carries.
102
+ summarize: (bindingValue: unknown) => {
103
+ summary: string;
104
+ argsHash: string;
105
+ pinView: unknown;
106
+ command?: string;
107
+ };
108
+ }
109
+
110
+ // ── The server-run confirmation ladder (PR-1.5) ──────────────────────────
111
+ //
112
+ // The operator's 2026-11-15 pivot moves the ask-mode confirmation onto the
113
+ // server. On a client that declares the MCP elicitation form capability, the
114
+ // gate itself asks the human (T1): a form whose message carries the command
115
+ // line and whose single boolean field is the approval. On a client that does
116
+ // not declare it, the gate refuses with a chat round-trip envelope (T3) that
117
+ // teaches the model to show the command and retry with the attestation.
118
+ // Token mode (T4) is untouched. The types below are the transport-free seam:
119
+ // the protocol layer implements ElicitationSeam over the SDK's elicitInput,
120
+ // the gate consumes it, and tests inject a fake — no SDK import reaches the
121
+ // gate, and the shapes stay zod-free.
122
+ export type ElicitDecision = 'accept' | 'decline' | 'cancel' | 'timeout' | 'error';
123
+
124
+ export interface ElicitOutcome {
125
+ decision: ElicitDecision;
126
+ /** The accepted form content (present on 'accept' only). */
127
+ content?: Record<string, unknown>;
128
+ /** Human-readable detail for a timeout or transport failure. */
129
+ detail?: string;
130
+ }
131
+
132
+ // The restricted top-level JSON Schema the elicitation form mode accepts
133
+ // (flat properties, primitive values only). Kept structural so this module
134
+ // needs no JSON-Schema dependency.
135
+ export interface ElicitFormSchema {
136
+ type: 'object';
137
+ properties: Record<string, Record<string, unknown>>;
138
+ required?: string[];
139
+ }
140
+
141
+ export interface ElicitFormRequest {
142
+ /** The form body: the command line, the redacted summarize view, the effect. */
143
+ message: string;
144
+ schema: ElicitFormSchema;
145
+ /** The explicit bound (the SDK default is shorter than a human reading). */
146
+ timeoutMs: number;
147
+ }
148
+
149
+ export interface ElicitationSeam {
150
+ /** True when the client declared elicitation.form in its initialize params. */
151
+ capable: boolean;
152
+ /** Ask the human; resolves with the decision, never throws. */
153
+ prompt: (request: ElicitFormRequest) => Promise<ElicitOutcome>;
154
+ }
155
+
156
+ // The consent event the ledger stores (approval-ledger.ts). Ask-mode
157
+ // arrivals write one; token mode keeps its existing semantics (single use,
158
+ // tombstone, five-minute TTL) and records nothing — its evidence is the
159
+ // custody-HMAC grant inside approvals.json. The event's subject is the
160
+ // CONSENT's lifecycle, not the handler's internals: it records that the
161
+ // user allowed this exact call (the arrival ApprovalCoreConsent models as
162
+ // the human yes) and — as a best-effort follow-up the dispatch layer
163
+ // writes after the handler returns (round 10, finding 4) — what became of
164
+ // the call the consent authorized, in outcomeDetail. `outcome` is the
165
+ // consent's own outcome — 'granted' when the call was allowed, 'denied'
166
+ // when the popup was declined; `outcomeDetail` is the dispatch result of
167
+ // the approved call ('delivered' | 'uncertain' | 'failed') — the AUDIT
168
+ // record of the delivery class. The retry memo's state is the gate's
169
+ // in-memory record, keyed on the same class as computed at dispatch time,
170
+ // never on this stored field. Neither field claims anything about
171
+ // the handler's internal execution beyond that delivery class.
172
+ export interface ConsentEvent {
173
+ sessionId: string;
174
+ tool: string;
175
+ argsHash: string;
176
+ outcome: 'granted' | 'denied';
177
+ grantedAt: number;
178
+ scope: 'once' | 'session';
179
+ evidence: ConsentEvidence;
180
+ // The arrival counter (rounds 13-15): a monotonically increasing
181
+ // per-store sequence the ledger assigns on EVERY append — the true
182
+ // chronology key for the tier resolution, immune to clock steps. A
183
+ // backward NTP/VM-restore step gives a later-written copy a SMALLER
184
+ // grantedAt, and grantedAt-only chronology then names the failure-born
185
+ // copy the original — the fabricated upgrade the never-upgrade rule
186
+ // exists to prevent, with no tiebreak firing (the stamps differ). The
187
+ // resolution orders by (arrivalSeq, grantedAt): the counter tracks real
188
+ // arrival order (floored by the parsed store, the streamed sidecar/spool
189
+ // scans, and this process's last assignment on every append — the seq
190
+ // file is an operator-visible high-water, never a floor source), so a
191
+ // later-arriving row never sorts as the original whatever the wall
192
+ // clock did. grantedAt stays for display and the annotate's keyed join.
193
+ //
194
+ // The assignable space is integers in [0, SEQ_CEILING) — MAX_SAFE_INTEGER-2
195
+ // is the EXCLUSIVE ceiling, so the three values below the sentinel (the
196
+ // ceiling band, the seats' poison value, and the sentinel itself) are
197
+ // never assigned and never valid. Round 15 bounded the space (a corrupted
198
+ // row or file near 2^53 used to walk the counter onto the sentinel and
199
+ // past the safe range, permanently duplicating locked writers' seqs and
200
+ // re-opening the r13 upgrade); round 16, finding 1 made SATURATION a
201
+ // state: the r15 clamp treated "no room left" as "re-issue the top", so
202
+ // one value at the boundary duplicated every later append forever with no
203
+ // repair — when the floor leaves no assignable value above it, the new
204
+ // row takes the SENTINEL instead (chronology-unknown, sorts newest,
205
+ // never an original), and the high-water file keeps the last assignable
206
+ // value. A row whose seq is absent, null, fractional, negative,
207
+ // Infinite, or at/beyond the ceiling reads as the SENTINEL: the row stays
208
+ // VISIBLE, sorts newest, and can never be an original — never invisible
209
+ // (the pre-r15 fix lost an Infinity-serialized row entirely when it
210
+ // round-tripped as arrivalSeq:null). Ledger-written rows always carry a
211
+ // valid seq until the space is exhausted, and then the sentinel; the
212
+ // normalization covers corruption, pre-field rows, and the ceiling band.
213
+ arrivalSeq: number;
214
+ // The dispatch outcome of the call this consent authorized (round 10,
215
+ // finding 4) — the AUDIT record of the delivery class; the gate's
216
+ // in-memory retry memo keys on the computed class at dispatch time,
217
+ // never on this stored field. Absent on every row written before the
218
+ // dispatch layer's follow-up lands, and on any follow-up that could
219
+ // not be recorded best-effort.
220
+ outcomeDetail?: ConsentDeliveryOutcome;
221
+ // The command-forward line the user allowed, as the summarize view
222
+ // rendered it (REDACTED by construction — the summarize contract never
223
+ // stores the raw argument stream). Absent on rows from tools with no
224
+ // executable line, and on every row written before the field landed.
225
+ command?: string;
226
+ }
227
+
228
+ // What became of the call a consent authorized, as observed by the
229
+ // dispatch layer that ran the handler: 'delivered' when the handler
230
+ // returned an ok result, 'failed' when it returned a not-ok result (the
231
+ // non-delivered class — the child answered with a failure), 'uncertain'
232
+ // when the handler threw and whether the call completed is unknowable.
233
+ // The stored annotation is the audit record; the gate's in-memory retry
234
+ // memo keys on the same class as computed at dispatch time
235
+ // (ApprovalCoreConsent's result-conditioned scope) and never reads the
236
+ // stored field back.
237
+ export type ConsentDeliveryOutcome = 'delivered' | 'uncertain' | 'failed';
@@ -55,7 +55,7 @@ function printRefusal(io: ApproveIo, inspectionState: string): number {
55
55
  io.write('No pending approval matches that token.\n');
56
56
  } else if (inspectionState === 'expired') {
57
57
  io.write(
58
- 'That approval expired. A confirmation must happen within 5 minutes of the plan; ask the agent to plan the command again.\n',
58
+ 'That approval expired. A confirmation must happen within 5 minutes of the mint; ask the agent to make the approved call again for a fresh approval.\n',
59
59
  );
60
60
  } else {
61
61
  io.write('This approval was already used.\n');
@@ -103,17 +103,17 @@ function printConfirmResult(
103
103
  ): number {
104
104
  switch (status) {
105
105
  case 'confirmed':
106
- io.write('Confirmed. The agent may now run this command once.\n');
106
+ io.write('Confirmed. The agent may now run this approved call once.\n');
107
107
  return 0;
108
108
  case 'already_confirmed':
109
- io.write('This approval was already confirmed. The agent may run this command once.\n');
109
+ io.write('This approval was already confirmed. The agent may run this approved call once.\n');
110
110
  return 0;
111
111
  case 'already_consumed':
112
112
  io.write('This approval was already used.\n');
113
113
  return 0;
114
114
  case 'expired':
115
115
  io.write(
116
- 'That approval expired. A confirmation must happen within 5 minutes of the plan; ask the agent to plan the command again.\n',
116
+ 'That approval expired. A confirmation must happen within 5 minutes of the mint; ask the agent to make the approved call again for a fresh approval.\n',
117
117
  );
118
118
  return 1;
119
119
  case 'custody_unavailable':
@@ -5,7 +5,7 @@
5
5
  "icons": [
6
6
  {
7
7
  "id": "codeartsdoer",
8
- "name": "华为云码道(CodeArts)代码智能体",
8
+ "name": "华为云码道CodeArts代码智能体",
9
9
  "category": "人工智能",
10
10
  "subcategory": "智能体",
11
11
  "description": "更懂你编码需求的AI研发专家",
@@ -41,13 +41,13 @@
41
41
  },
42
42
  {
43
43
  "id": "modelarts",
44
- "name": "魔坊(ModelArts)模型训推平台",
44
+ "name": "魔坊(ModelArts)",
45
45
  "category": "人工智能",
46
46
  "subcategory": "模型开发平台",
47
47
  "description": "“数-训-推-强”,一站式AI开发平台",
48
48
  "product_url": "https://www.huaweicloud.com/product/modelarts.html",
49
49
  "logo": {
50
- "source_url": "https://res-static.hc-cdn.cn/cloudbu-site/public/new-product-icon/AI/ModelArts.png",
50
+ "source_url": "https://res-static.hc-cdn.cn/cloudbu-site/public/%E6%96%B0%E7%89%88/CF057503-AE1E-48CA-E8C1-1919F51A1261.png",
51
51
  "local_path": "icons/assets/logo/modelarts.png"
52
52
  },
53
53
  "architecture": {
@@ -155,8 +155,8 @@
155
155
  "description": "高效敏捷安全的一站式企业级智能体平台",
156
156
  "product_url": "https://www.huaweicloud.com/product/agentarts.html",
157
157
  "logo": {
158
- "source_url": "https://res-static.hc-cdn.cn/cloudbu-site/public/new-product-icon/aPaaS/Versatile.svg",
159
- "local_path": "icons/assets/logo/agentarts.svg"
158
+ "source_url": "https://res-static.hc-cdn.cn/cloudbu-site/china/zh-cn/%E6%99%BA%E6%9E%9CAgentArts/AgentArts-%E5%AE%98%E7%BD%91%E4%BA%A7%E5%93%81%E9%A1%B5%E5%88%87%E5%9B%BE/bannerlogo.png",
159
+ "local_path": "icons/assets/logo/agentarts.png"
160
160
  },
161
161
  "architecture": {
162
162
  "status": "planned",
@@ -165,6 +165,24 @@
165
165
  "aliases": ["agentarts"],
166
166
  "tags": ["人工智能", "智能体平台", "agentarts"]
167
167
  },
168
+ {
169
+ "id": "officeace",
170
+ "name": "果办OfficeAce 办公智能体",
171
+ "category": "人工智能",
172
+ "subcategory": "智能体",
173
+ "description": "专业办公级AI助手,PPT一键生成、专家团研讨,安全高效随时待命",
174
+ "product_url": "https://www.huaweicloud.com/product/agentarts/officeace.html",
175
+ "logo": {
176
+ "source_url": "https://res-static.hc-cdn.cn/cloudbu-site/china/zh-cn/yunying/product/OfficeAce-v2.svg",
177
+ "local_path": "icons/assets/logo/officeace.svg"
178
+ },
179
+ "architecture": {
180
+ "status": "planned",
181
+ "local_path": "icons/assets/architecture/officeace.svg"
182
+ },
183
+ "aliases": ["officeace", "office-ace"],
184
+ "tags": ["人工智能", "智能体", "办公", "officeace"]
185
+ },
168
186
  {
169
187
  "id": "pangu-nlp",
170
188
  "name": "LLM大模型",
@@ -1,6 +1,17 @@
1
- import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
1
+ import {
2
+ existsSync,
3
+ mkdirSync,
4
+ readdirSync,
5
+ readFileSync,
6
+ renameSync,
7
+ rmSync,
8
+ statSync,
9
+ utimesSync,
10
+ writeFileSync,
11
+ } from 'node:fs';
2
12
  import { homedir } from 'node:os';
3
13
  import { join } from 'node:path';
14
+ import { Worker } from 'node:worker_threads';
4
15
 
5
16
  import { DEPENDENCIES, type DependencyId } from '../lib/dependency-model.ts';
6
17
  import type { ResolvedDependency } from '../lib/dep-resolve.ts';
@@ -199,7 +210,13 @@ const LOCK_POLL_MS = 50;
199
210
  // window is taken over anyway — the guard must never block forever. The
200
211
  // window must exceed the longest critical section (the tier uninstall's
201
212
  // 60s spawnSync) plus resolution margin, or a legitimate holder still
202
- // inside its section gets its lock taken over mid-flight.
213
+ // inside its section gets its lock taken over mid-flight. A holder whose
214
+ // claim goes stale while its pid is STILL alive is judged wedged by this
215
+ // same window — correct for the installer's bounded sections, wrong for
216
+ // a caller whose section cost is unbounded: such callers pass the
217
+ // heartbeatMs option (below), which refreshes the claim's mtime for the
218
+ // duration of the section so a live productive holder never goes stale
219
+ // however long its section runs.
203
220
  const LOCK_TAKEOVER_MS = 90_000;
204
221
 
205
222
  const lockDepth = new Map<string, number>();
@@ -284,12 +301,38 @@ function sweepStaleStashes(dir: string): void {
284
301
  }
285
302
  }
286
303
 
287
- function acquireLock(dir: string, takeoverMs: number = LOCK_TAKEOVER_MS): void {
304
+ // Thrown by acquireLock when the opt-in wait budget expires: the caller's
305
+ // documented posture for this error is degrade-and-proceed (the ledger
306
+ // runs the append unlocked), never fail the approved call. Only the
307
+ // opt-in maxWaitMs path can produce it; the dep installer never passes
308
+ // one and keeps today's unbounded wait.
309
+ export class LockWaitBudgetExceeded extends Error {
310
+ readonly waitedMs: number;
311
+ constructor(waitedMs: number) {
312
+ super(`lock wait budget exceeded after ${waitedMs}ms (holder still alive)`);
313
+ this.name = 'LockWaitBudgetExceeded';
314
+ this.waitedMs = waitedMs;
315
+ }
316
+ }
317
+
318
+ function acquireLock(dir: string, takeoverMs: number = LOCK_TAKEOVER_MS, maxWaitMs: number = 0): void {
288
319
  mkdirSync(dir, { recursive: true });
289
320
  sweepStaleStashes(dir);
290
321
  const lock = lockDirPath(dir);
291
322
  const deadline = Date.now() + takeoverMs;
323
+ const acquireStarted = Date.now();
292
324
  for (;;) {
325
+ // The opt-in TOTAL wait cap (interrogate round 5, finding 1): the
326
+ // heartbeat keeps a live-but-wedged holder's claim fresh forever —
327
+ // its worker thread beats while its main thread hangs — so a waiter
328
+ // with no cap would block the caller's event loop for the wedge's
329
+ // whole duration, unbounded. A caller that passes maxWaitMs gets a
330
+ // bounded wait instead: past the cap with the lock still held, this
331
+ // throw hands the caller its documented degradation. Checked at the
332
+ // loop top only, so a claim that succeeded never throws.
333
+ if (maxWaitMs > 0 && Date.now() - acquireStarted > maxWaitMs) {
334
+ throw new LockWaitBudgetExceeded(Date.now() - acquireStarted);
335
+ }
293
336
  // Identity of the directory THIS iteration creates at the lock path —
294
337
  // the claim is only complete once the pid file lands in THAT directory.
295
338
  // Round-9 (CI, live-reproduced under CPU load): a past-deadline rival
@@ -440,7 +483,41 @@ function installExitCleanup(): void {
440
483
  });
441
484
  }
442
485
 
443
- export function withDepLock<T>(fn: () => T, dir: string = receiptDir(), takeoverMs: number = LOCK_TAKEOVER_MS): T {
486
+ // The opt-in claim heartbeat (interrogate round 4): a worker thread that
487
+ // refreshes the claim pid file's mtime every intervalMs for the duration
488
+ // of the section. The acquire loop judges liveness by that mtime, so a
489
+ // beating holder never goes stale however long its section runs — the
490
+ // worker's timer fires on its own OS thread while the holder's main
491
+ // thread is blocked in a multi-second parse/write, which no in-section
492
+ // refresh could cover. Opt-in only: the dep installer's call sites pass
493
+ // no heartbeat and keep exactly today's semantics (bounded sections,
494
+ // window-sized takeover). A worker that fails to spawn degrades to the
495
+ // no-heartbeat behavior — the documented residual for that path.
496
+ function startClaimHeartbeat(lock: string, heartbeatMs: number): Worker | undefined {
497
+ try {
498
+ return new Worker(
499
+ [
500
+ "const { utimesSync } = require('node:fs');",
501
+ "const { workerData } = require('node:worker_threads');",
502
+ 'setInterval(() => {',
503
+ ' const now = Date.now() / 1000;',
504
+ ' try { utimesSync(workerData.pidFile, now, now); } catch {}',
505
+ '}, workerData.intervalMs);',
506
+ ].join('\n'),
507
+ { eval: true, workerData: { pidFile: join(lock, LOCK_PID_FILE), intervalMs: heartbeatMs } },
508
+ );
509
+ } catch {
510
+ return undefined;
511
+ }
512
+ }
513
+
514
+ export function withDepLock<T>(
515
+ fn: () => T,
516
+ dir: string = receiptDir(),
517
+ takeoverMs: number = LOCK_TAKEOVER_MS,
518
+ heartbeatMs: number = 0,
519
+ maxWaitMs: number = 0,
520
+ ): T {
444
521
  const depth = lockDepth.get(dir) ?? 0;
445
522
  if (depth > 0) {
446
523
  lockDepth.set(dir, depth + 1);
@@ -450,13 +527,15 @@ export function withDepLock<T>(fn: () => T, dir: string = receiptDir(), takeover
450
527
  lockDepth.set(dir, depth - 1);
451
528
  }
452
529
  }
453
- acquireLock(dir, takeoverMs);
530
+ acquireLock(dir, takeoverMs, maxWaitMs);
454
531
  installExitCleanup();
455
532
  heldDirs.add(dir);
456
533
  lockDepth.set(dir, 1);
534
+ const heartbeat = heartbeatMs > 0 ? startClaimHeartbeat(lockDirPath(dir), heartbeatMs) : undefined;
457
535
  try {
458
536
  return fn();
459
537
  } finally {
538
+ if (heartbeat) heartbeat.terminate().catch(() => {});
460
539
  lockDepth.set(dir, 0);
461
540
  releaseLock(dir);
462
541
  heldDirs.delete(dir);
@@ -35,6 +35,9 @@ export {
35
35
  stripLeadingHcloudBinArgs,
36
36
  firstPlaceholderSecretArg,
37
37
  pinViewArgs,
38
+ needsUserConfirmation,
39
+ quoteShellArg,
40
+ hcloudExecutableLines,
38
41
  type HcloudPlan,
39
42
  type HcloudPlanWithArgs,
40
43
  } from './hcloud-plan.ts';