huaweicloud-devkit 2.0.0-next.5 → 2.0.0-next.6
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 +1 -1
- package/integrations/opencode/commands/huaweicloud-doctor.md +1 -1
- package/integrations/opencode/hooks/safety-gate.js +235 -0
- package/package.json +1 -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/.workbuddy-plugin/plugin.json +1 -1
- package/plugins/huaweicloud-core/dist/agents/opencode-config.js +29 -4
- package/plugins/huaweicloud-core/dist/agents/opencode.js +55 -14
- package/plugins/huaweicloud-core/dist/approval-gate.js +23 -5
- package/plugins/huaweicloud-core/dist/doctor-payload.js +29 -0
- package/plugins/huaweicloud-core/dist/lib/opencode-permission-seam.js +51 -20
- package/plugins/huaweicloud-core/dist/mcp-server.js +85 -8
- package/plugins/huaweicloud-core/dist/mcp-server.js.map +4 -4
- package/plugins/huaweicloud-core/dist/packs/auth/tools.js +5 -1
- package/plugins/huaweicloud-core/dist/payload-placement.js +8 -0
- package/plugins/huaweicloud-core/dist/safety/classify-text.js +10 -0
- package/plugins/huaweicloud-core/dist/safety/policy.js +12 -0
- package/plugins/huaweicloud-core/dist/safety/protected-payload.js +93 -0
- package/plugins/huaweicloud-core/dist/safety-integrity.js +122 -0
- package/plugins/huaweicloud-core/dist/setup-cli.js +8 -1
- package/plugins/huaweicloud-core/hooks/huaweicloud-safety.mjs +44 -1
- package/plugins/huaweicloud-core/hooks/huaweicloud-safety.py +61 -1
- package/plugins/huaweicloud-core/openclaw.plugin.json +2 -2
- package/plugins/huaweicloud-core/safety/policy.json +5 -0
- package/plugins/huaweicloud-core/skills/huaweicloud-safety/references/approvals.md +1 -1
- package/plugins/huaweicloud-core/src/agents/opencode-config.ts +33 -3
- package/plugins/huaweicloud-core/src/agents/opencode.ts +66 -15
- package/plugins/huaweicloud-core/src/approval-gate.ts +29 -4
- package/plugins/huaweicloud-core/src/doctor-payload.ts +40 -2
- package/plugins/huaweicloud-core/src/lib/opencode-permission-seam.ts +60 -19
- package/plugins/huaweicloud-core/src/packs/auth/tools.ts +7 -1
- package/plugins/huaweicloud-core/src/payload-placement.ts +8 -0
- package/plugins/huaweicloud-core/src/safety/classify-text.ts +10 -0
- package/plugins/huaweicloud-core/src/safety/policy.ts +13 -0
- package/plugins/huaweicloud-core/src/safety/protected-payload.ts +97 -0
- package/plugins/huaweicloud-core/src/safety-integrity.ts +132 -0
- package/plugins/huaweicloud-core/src/setup-cli.ts +8 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
|
|
5
|
+
// The deployed-payload integrity receipt (the integrity unit's layer 3):
|
|
6
|
+
// install/update records a hash manifest of the CLASSIFIER files the
|
|
7
|
+
// in-process gates import — the same artifacts the layer-1 path gate
|
|
8
|
+
// protects and the layer-2 canaries behavior-check. Doctor compares the
|
|
9
|
+
// current hashes against the receipt: drift (an agent-side rewrite the
|
|
10
|
+
// path gate missed, a half-landed overwrite) FAILs with the reinstall
|
|
11
|
+
// remediation; a payload placed by an older devkit (no receipt yet) WARNs
|
|
12
|
+
// instead — backward compatibility, never a false red.
|
|
13
|
+
//
|
|
14
|
+
// Scope is the classifier chain, not the whole payload: dist/safety-policy.js
|
|
15
|
+
// plus its dist/safety/ import graph (the JS classifier the adapter and the
|
|
16
|
+
// .mjs hook load), safety/policy.json (the vocabulary both faces read), and
|
|
17
|
+
// safety/rules/ (the risk catalog). skills/ and node_modules/ are outside
|
|
18
|
+
// it — they have their own freshness/equality probes, and hashing them
|
|
19
|
+
// would make the receipt churn on every skill edit.
|
|
20
|
+
//
|
|
21
|
+
// A receipt-style marker beside the `.installed` precedent: written by the
|
|
22
|
+
// one shared placement seam (copyServerPayload), owned by the devkit,
|
|
23
|
+
// removed with the plugin dir on uninstall. Unlike `.installed` it
|
|
24
|
+
// persists across server boots (the server deletes the restart marker at
|
|
25
|
+
// boot; the receipt must survive for doctor to read).
|
|
26
|
+
|
|
27
|
+
export const INTEGRITY_RECEIPT_FILE = '.safety-integrity.json';
|
|
28
|
+
|
|
29
|
+
export interface IntegrityReceipt {
|
|
30
|
+
version: 1;
|
|
31
|
+
files: Record<string, string>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type IntegrityStatus =
|
|
35
|
+
| { status: 'no-payload' }
|
|
36
|
+
| { status: 'no-receipt' }
|
|
37
|
+
| { status: 'match' }
|
|
38
|
+
| { status: 'mismatch'; drifted: string[]; missing: string[]; unrecorded: string[] };
|
|
39
|
+
|
|
40
|
+
function sha256Of(file: string): string {
|
|
41
|
+
return createHash('sha256').update(readFileSync(file)).digest('hex');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function filesUnder(dir: string): string[] {
|
|
45
|
+
if (!existsSync(dir)) return [];
|
|
46
|
+
const out: string[] = [];
|
|
47
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
48
|
+
const full = join(dir, entry.name);
|
|
49
|
+
if (entry.isDirectory()) out.push(...filesUnder(full));
|
|
50
|
+
else if (entry.isFile()) out.push(full);
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// The classifier artifacts present under a deployed payload dir, as sorted
|
|
56
|
+
// relative paths. Absent entries (a skipDist payload ships safety/ without
|
|
57
|
+
// dist/) simply stay out of the scope — the receipt records what shipped.
|
|
58
|
+
// The receipt's keys are wire vocabulary (pinned deep-equal in the tests and
|
|
59
|
+
// spelled forward-slash in policy docs), so the platform separator is
|
|
60
|
+
// normalized to posix: join()/readdirSync() produce '\' segments on win32
|
|
61
|
+
// and a raw slice would ship platform-dependent receipt keys.
|
|
62
|
+
export function integrityScopeFiles(dir: string): string[] {
|
|
63
|
+
const rel: string[] = [];
|
|
64
|
+
const push = (path: string) => {
|
|
65
|
+
if (existsSync(join(dir, path))) rel.push(path);
|
|
66
|
+
};
|
|
67
|
+
push('dist/safety-policy.js');
|
|
68
|
+
for (const file of filesUnder(join(dir, 'dist', 'safety'))) {
|
|
69
|
+
rel.push(file.slice(dir.length + 1).replaceAll('\\', '/'));
|
|
70
|
+
}
|
|
71
|
+
push('safety/policy.json');
|
|
72
|
+
for (const file of filesUnder(join(dir, 'safety', 'rules'))) {
|
|
73
|
+
rel.push(file.slice(dir.length + 1).replaceAll('\\', '/'));
|
|
74
|
+
}
|
|
75
|
+
return rel.sort((a, b) => a.localeCompare(b));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function integrityReceiptPath(dir: string): string {
|
|
79
|
+
return join(dir, INTEGRITY_RECEIPT_FILE);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Written at placement time over what actually landed (the verified-copy
|
|
83
|
+
// seam guarantees the bytes; hashing the DEST is the honest record).
|
|
84
|
+
export function writeIntegrityReceipt(dir: string): void {
|
|
85
|
+
const files: Record<string, string> = {};
|
|
86
|
+
for (const rel of integrityScopeFiles(dir)) files[rel] = sha256Of(join(dir, rel));
|
|
87
|
+
const receipt: IntegrityReceipt = { version: 1, files };
|
|
88
|
+
writeFileSync(integrityReceiptPath(dir), `${JSON.stringify(receipt, null, 2)}\n`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// The doctor-side comparison. A receipt entry whose file changed or vanished
|
|
92
|
+
// drifts; a scope file present on disk but absent from the receipt drifts
|
|
93
|
+
// too — no legit path lands classifier files without rewriting the receipt
|
|
94
|
+
// (every install/update writes it), so an unrecorded classifier file is the
|
|
95
|
+
// dropped-in-later tamper shape.
|
|
96
|
+
export function verifyIntegrity(dir: string): IntegrityStatus {
|
|
97
|
+
const receiptFile = integrityReceiptPath(dir);
|
|
98
|
+
const scope = integrityScopeFiles(dir);
|
|
99
|
+
if (scope.length === 0) return { status: 'no-payload' };
|
|
100
|
+
if (!existsSync(receiptFile)) return { status: 'no-receipt' };
|
|
101
|
+
let receipt: IntegrityReceipt;
|
|
102
|
+
try {
|
|
103
|
+
receipt = JSON.parse(readFileSync(receiptFile, 'utf8')) as IntegrityReceipt;
|
|
104
|
+
} catch {
|
|
105
|
+
return { status: 'no-receipt' };
|
|
106
|
+
}
|
|
107
|
+
if (
|
|
108
|
+
receipt === null ||
|
|
109
|
+
typeof receipt !== 'object' ||
|
|
110
|
+
receipt.version !== 1 ||
|
|
111
|
+
receipt.files === null ||
|
|
112
|
+
typeof receipt.files !== 'object'
|
|
113
|
+
) {
|
|
114
|
+
return { status: 'no-receipt' };
|
|
115
|
+
}
|
|
116
|
+
const recorded = new Set(Object.keys(receipt.files));
|
|
117
|
+
const drifted: string[] = [];
|
|
118
|
+
const missing: string[] = [];
|
|
119
|
+
for (const rel of scope) {
|
|
120
|
+
if (!recorded.has(rel)) continue; // counted as unrecorded below
|
|
121
|
+
const expected = receipt.files[rel];
|
|
122
|
+
if (typeof expected !== 'string' || sha256Of(join(dir, rel)) !== expected) drifted.push(rel);
|
|
123
|
+
}
|
|
124
|
+
for (const rel of Object.keys(receipt.files)) {
|
|
125
|
+
if (!existsSync(join(dir, rel))) missing.push(rel);
|
|
126
|
+
}
|
|
127
|
+
const unrecorded = scope.filter((rel) => !recorded.has(rel));
|
|
128
|
+
if (drifted.length > 0 || missing.length > 0 || unrecorded.length > 0) {
|
|
129
|
+
return { status: 'mismatch', drifted, missing, unrecorded };
|
|
130
|
+
}
|
|
131
|
+
return { status: 'match' };
|
|
132
|
+
}
|
|
@@ -123,6 +123,7 @@ import {
|
|
|
123
123
|
deployOpenCode,
|
|
124
124
|
opencodeDoctorAskRule,
|
|
125
125
|
opencodeDoctorMcpConfigured,
|
|
126
|
+
opencodeDoctorSafetyGate,
|
|
126
127
|
opencodeDoctorSeam,
|
|
127
128
|
opencodeStatus,
|
|
128
129
|
uninstallOpenCode,
|
|
@@ -975,6 +976,12 @@ async function cmdDoctor(): Promise<void> {
|
|
|
975
976
|
const safetyOk = sections.some((section) => section.triple.safety);
|
|
976
977
|
check('Safety policy installed', safetyOk, 'Run: npx huaweicloud-devkit install');
|
|
977
978
|
|
|
979
|
+
// The integrity unit's layer 3: per-row comparison of the deployed
|
|
980
|
+
// classifier files against the receipt the placement seam wrote. A row
|
|
981
|
+
// with no payload stays silent; a payload without a receipt WARNs (a
|
|
982
|
+
// pre-integrity install); drift FAILs with the reinstall remediation.
|
|
983
|
+
for (const section of sections) section.integrity(ctx);
|
|
984
|
+
|
|
978
985
|
// Secret vault — custody tier and inventory only; doctor never decrypts.
|
|
979
986
|
try {
|
|
980
987
|
const custody = custodyReport();
|
|
@@ -1057,6 +1064,7 @@ async function cmdDoctor(): Promise<void> {
|
|
|
1057
1064
|
if (installedPayload?.id === 'opencode') {
|
|
1058
1065
|
opencodeDoctorSeam(ctx);
|
|
1059
1066
|
opencodeDoctorAskRule(ctx);
|
|
1067
|
+
opencodeDoctorSafetyGate(ctx);
|
|
1060
1068
|
}
|
|
1061
1069
|
|
|
1062
1070
|
// The codex client yield (PR-5): the per-tool approval_mode blocks the
|