@cyfsh/adapters 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/dist/adapters.d.ts +119 -0
- package/dist/adapters.d.ts.map +1 -0
- package/dist/adapters.js +492 -0
- package/dist/adapters.js.map +1 -0
- package/dist/guard-generator.d.ts +59 -0
- package/dist/guard-generator.d.ts.map +1 -0
- package/dist/guard-generator.js +499 -0
- package/dist/guard-generator.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/sandbox-responder.d.ts +12 -0
- package/dist/sandbox-responder.d.ts.map +1 -0
- package/dist/sandbox-responder.js +199 -0
- package/dist/sandbox-responder.js.map +1 -0
- package/dist/types.d.ts +117 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +44 -3
- package/README.md +0 -3
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { PermissionTier } from "@cyfsh/protocol";
|
|
2
|
+
import type { AcpPermissionCheckInput, AcpPermissionDecision, GeneratedGuardFile } from "./types.js";
|
|
3
|
+
export interface GuardGeneratorOptions {
|
|
4
|
+
shareId: string;
|
|
5
|
+
workspacePath: string;
|
|
6
|
+
permissionTier: PermissionTier;
|
|
7
|
+
writableGlobs?: string[];
|
|
8
|
+
}
|
|
9
|
+
export interface MaterializedGuardBundle {
|
|
10
|
+
guardScriptPath: string;
|
|
11
|
+
emptyMcpConfigPath: string;
|
|
12
|
+
claudeSettingsPath: string;
|
|
13
|
+
dshPatchYamlPath: string;
|
|
14
|
+
files: GeneratedGuardFile[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Resolves a target path safely using fs.realpathSync on the deepest existing ancestor
|
|
18
|
+
* so symlink escapes and non-existent `../../.env` paths are both caught deterministically.
|
|
19
|
+
*/
|
|
20
|
+
export declare function resolveCanonicalTargetPath(workspacePath: string, candidatePath: string): {
|
|
21
|
+
workspaceReal: string;
|
|
22
|
+
targetReal: string;
|
|
23
|
+
};
|
|
24
|
+
export declare function isWithinDirectory(parentReal: string, childReal: string): boolean;
|
|
25
|
+
export declare function isSensitivePath(targetPath: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Evaluates ACP `session/request_permission` or PreToolUse safety in-process.
|
|
28
|
+
*/
|
|
29
|
+
export declare function evaluateAcpPermissionRequest(input: AcpPermissionCheckInput): AcpPermissionDecision;
|
|
30
|
+
/**
|
|
31
|
+
* Generates a standalone cross-platform Node.js Fail-Closed Hook script (.mjs)
|
|
32
|
+
* for `PreToolUse` and `UserPromptSubmit`.
|
|
33
|
+
*
|
|
34
|
+
* Security invariant: ANY uncaught exception, malformed JSON input, symlink escape,
|
|
35
|
+
* sensitive file touch, or unauthorized write exits with code `2` (never `0` or `1`).
|
|
36
|
+
*/
|
|
37
|
+
export declare function generateFailClosedHookScript(options: GuardGeneratorOptions): string;
|
|
38
|
+
/**
|
|
39
|
+
* Generates managed Claude Code / CodeBuddy `settings.json` binding both
|
|
40
|
+
* `UserPromptSubmit` and `PreToolUse` to the Fail-Closed Node guard script.
|
|
41
|
+
*/
|
|
42
|
+
export declare function generateManagedHookSettingsJson(guardScriptPath: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* Generates an empty strict MCP config so `--strict-mcp-config --mcp-config <path>`
|
|
45
|
+
* strips all private database/cloud credentials from the guest shadow process.
|
|
46
|
+
*/
|
|
47
|
+
export declare function generateStrictEmptyMcpJson(): string;
|
|
48
|
+
/**
|
|
49
|
+
* Generates `cyf-dsh-guard-patch.yaml` for DeepSeek Harness (`dsh --patch`),
|
|
50
|
+
* stripping destructive tools & private MCP plugins via Cordis overlay without mutating `~/.dsh`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function generateDshCordisGuardPatchYaml(options: GuardGeneratorOptions & {
|
|
53
|
+
guardScriptPath: string;
|
|
54
|
+
}): string;
|
|
55
|
+
/**
|
|
56
|
+
* Builds virtual or disk-materialized guard artifacts for a given share session.
|
|
57
|
+
*/
|
|
58
|
+
export declare function buildGuardArtifactBundle(baseDir: string, options: GuardGeneratorOptions, writeToDisk?: boolean): MaterializedGuardBundle;
|
|
59
|
+
//# sourceMappingURL=guard-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guard-generator.d.ts","sourceRoot":"","sources":["../src/guard-generator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EACV,uBAAuB,EACvB,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,cAAc,CAAC;IAC/B,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,uBAAuB;IACtC,eAAe,EAAE,MAAM,CAAC;IACxB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,gBAAgB,EAAE,MAAM,CAAC;IACzB,KAAK,EAAE,kBAAkB,EAAE,CAAC;CAC7B;AAsBD;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,GACpB;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAwB/C;AAED,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAehF;AAED,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAc3D;AAaD;;GAEG;AACH,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,uBAAuB,GAC7B,qBAAqB,CA2GvB;AAED;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,qBAAqB,GAAG,MAAM,CAgLnF;AAED;;;GAGG;AACH,wBAAgB,+BAA+B,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAyC/E;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,IAAI,MAAM,CAEnD;AAED;;;GAGG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,qBAAqB,GAAG;IAAE,eAAe,EAAE,MAAM,CAAA;CAAE,GAC3D,MAAM,CAkCR;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,qBAAqB,EAC9B,WAAW,UAAQ,GAClB,uBAAuB,CAwDzB"}
|
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
const SENSITIVE_BASENAME_PATTERNS = [
|
|
4
|
+
/^\.env(\..+)?$/i,
|
|
5
|
+
/\.pem$/i,
|
|
6
|
+
/\.key$/i,
|
|
7
|
+
/\.p12$/i,
|
|
8
|
+
/\.pfx$/i,
|
|
9
|
+
/^id_(rsa|ed25519|ecdsa|dsa)(\.pub)?$/i,
|
|
10
|
+
/^\.npmrc$/i,
|
|
11
|
+
/^\.netrc$/i,
|
|
12
|
+
/credential/i,
|
|
13
|
+
/secret/i,
|
|
14
|
+
];
|
|
15
|
+
const SENSITIVE_SEGMENT_NAMES = new Set([
|
|
16
|
+
".ssh",
|
|
17
|
+
".aws",
|
|
18
|
+
".gnupg",
|
|
19
|
+
".kube",
|
|
20
|
+
]);
|
|
21
|
+
/**
|
|
22
|
+
* Resolves a target path safely using fs.realpathSync on the deepest existing ancestor
|
|
23
|
+
* so symlink escapes and non-existent `../../.env` paths are both caught deterministically.
|
|
24
|
+
*/
|
|
25
|
+
export function resolveCanonicalTargetPath(workspacePath, candidatePath) {
|
|
26
|
+
const workspaceAbs = path.resolve(workspacePath);
|
|
27
|
+
const workspaceReal = fs.existsSync(workspaceAbs)
|
|
28
|
+
? fs.realpathSync(workspaceAbs)
|
|
29
|
+
: workspaceAbs;
|
|
30
|
+
const rawResolved = path.resolve(workspaceReal, candidatePath);
|
|
31
|
+
const trailingParts = [];
|
|
32
|
+
let cursor = rawResolved;
|
|
33
|
+
while (!fs.existsSync(cursor)) {
|
|
34
|
+
const parent = path.dirname(cursor);
|
|
35
|
+
if (parent === cursor) {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
trailingParts.unshift(path.basename(cursor));
|
|
39
|
+
cursor = parent;
|
|
40
|
+
}
|
|
41
|
+
const baseReal = fs.existsSync(cursor) ? fs.realpathSync(cursor) : cursor;
|
|
42
|
+
const targetReal = trailingParts.length > 0 ? path.join(baseReal, ...trailingParts) : baseReal;
|
|
43
|
+
return { workspaceReal, targetReal };
|
|
44
|
+
}
|
|
45
|
+
export function isWithinDirectory(parentReal, childReal) {
|
|
46
|
+
const normalizedParent = path.resolve(parentReal);
|
|
47
|
+
const normalizedChild = path.resolve(childReal);
|
|
48
|
+
const compareParent = process.platform === "win32" ? normalizedParent.toLowerCase() : normalizedParent;
|
|
49
|
+
const compareChild = process.platform === "win32" ? normalizedChild.toLowerCase() : normalizedChild;
|
|
50
|
+
if (compareChild === compareParent) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
const prefix = compareParent.endsWith(path.sep)
|
|
54
|
+
? compareParent
|
|
55
|
+
: compareParent + path.sep;
|
|
56
|
+
return compareChild.startsWith(prefix);
|
|
57
|
+
}
|
|
58
|
+
export function isSensitivePath(targetPath) {
|
|
59
|
+
const normalized = targetPath.replace(/\\/g, "/");
|
|
60
|
+
const segments = normalized.split("/").filter(Boolean);
|
|
61
|
+
const basename = segments[segments.length - 1] ?? "";
|
|
62
|
+
if (normalized.toLowerCase().endsWith("/.git/config") || normalized.toLowerCase() === ".git/config") {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
for (const seg of segments) {
|
|
66
|
+
if (SENSITIVE_SEGMENT_NAMES.has(seg.toLowerCase())) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return SENSITIVE_BASENAME_PATTERNS.some((rx) => rx.test(basename));
|
|
71
|
+
}
|
|
72
|
+
function matchesSimpleGlob(relPosixPath, globPattern) {
|
|
73
|
+
const cleanRel = relPosixPath.replace(/^\/+/, "");
|
|
74
|
+
const cleanGlob = globPattern.replace(/\\/g, "/").replace(/^\/+/, "");
|
|
75
|
+
const regexBody = cleanGlob
|
|
76
|
+
.replace(/[.+^${}()|[\]\\]/g, "\\$&")
|
|
77
|
+
.replace(/\*\*/g, "__DOUBLE_STAR__")
|
|
78
|
+
.replace(/\*/g, "[^/]*")
|
|
79
|
+
.replace(/__DOUBLE_STAR__/g, ".*");
|
|
80
|
+
return new RegExp(`^${regexBody}$`, "i").test(cleanRel);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Evaluates ACP `session/request_permission` or PreToolUse safety in-process.
|
|
84
|
+
*/
|
|
85
|
+
export function evaluateAcpPermissionRequest(input) {
|
|
86
|
+
const toolLower = input.toolName.toLowerCase();
|
|
87
|
+
const targetPaths = input.targetPaths ?? [];
|
|
88
|
+
for (const rawPath of targetPaths) {
|
|
89
|
+
const { workspaceReal, targetReal } = resolveCanonicalTargetPath(input.workspacePath, rawPath);
|
|
90
|
+
if (!isWithinDirectory(workspaceReal, targetReal)) {
|
|
91
|
+
return {
|
|
92
|
+
outcome: "cancelled",
|
|
93
|
+
optionId: "reject-once",
|
|
94
|
+
reason: `Blocked path traversal outside workspace boundary: ${rawPath}`,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
if (isSensitivePath(rawPath) || isSensitivePath(targetReal)) {
|
|
98
|
+
return {
|
|
99
|
+
outcome: "cancelled",
|
|
100
|
+
optionId: "reject-once",
|
|
101
|
+
reason: `Blocked access to sensitive credential/config file: ${rawPath}`,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const isShellTool = toolLower.includes("bash") ||
|
|
106
|
+
toolLower.includes("shell") ||
|
|
107
|
+
toolLower.includes("terminal") ||
|
|
108
|
+
toolLower.includes("exec") ||
|
|
109
|
+
toolLower.includes("command");
|
|
110
|
+
if (isShellTool) {
|
|
111
|
+
const cmd = (input.command ?? "").trim();
|
|
112
|
+
if (/(?:rm\s+-rf|mkfs|del\s+\/[fsq]|format\s+[a-z]:|\.env|\.pem|\.ssh|id_rsa|printenv)/i.test(cmd)) {
|
|
113
|
+
return {
|
|
114
|
+
outcome: "cancelled",
|
|
115
|
+
optionId: "reject-once",
|
|
116
|
+
reason: `Blocked destructive or secret-exfiltrating shell command: ${cmd}`,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const isGreyZoneTest = /\b(?:npm\s+test|pnpm\s+test|yarn\s+test|npx\s+vitest|vitest|jest|pytest|cargo\s+test|go\s+test)\b/i.test(cmd);
|
|
120
|
+
if (isGreyZoneTest && input.ownerApprovalOnGreyZone) {
|
|
121
|
+
return {
|
|
122
|
+
outcome: "escalate_to_owner",
|
|
123
|
+
optionId: "pending-owner",
|
|
124
|
+
reason: `Grey-zone test command escalated for live Owner approval: ${cmd}`,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
outcome: "cancelled",
|
|
129
|
+
optionId: "reject-once",
|
|
130
|
+
reason: "Terminal execution is prohibited in guest shadow sessions without explicit Owner approval.",
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
const isWriteTool = toolLower.includes("write") ||
|
|
134
|
+
toolLower.includes("edit") ||
|
|
135
|
+
toolLower.includes("patch") ||
|
|
136
|
+
toolLower.includes("delete");
|
|
137
|
+
if (isWriteTool) {
|
|
138
|
+
if (input.permissionTier === "TIER_1_DISCUSS_AND_DRAFT") {
|
|
139
|
+
const writableGlobs = input.writableGlobs ?? [];
|
|
140
|
+
if (writableGlobs.length === 0 || targetPaths.length === 0) {
|
|
141
|
+
return {
|
|
142
|
+
outcome: "cancelled",
|
|
143
|
+
optionId: "reject-once",
|
|
144
|
+
reason: "Direct workspace file mutation is disabled in TIER_1_DISCUSS_AND_DRAFT.",
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
const { workspaceReal } = resolveCanonicalTargetPath(input.workspacePath, ".");
|
|
148
|
+
for (const rawPath of targetPaths) {
|
|
149
|
+
const { targetReal } = resolveCanonicalTargetPath(input.workspacePath, rawPath);
|
|
150
|
+
const relPosix = path.relative(workspaceReal, targetReal).replace(/\\/g, "/");
|
|
151
|
+
const allowed = writableGlobs.some((glob) => matchesSimpleGlob(relPosix, glob));
|
|
152
|
+
if (!allowed) {
|
|
153
|
+
return {
|
|
154
|
+
outcome: "cancelled",
|
|
155
|
+
optionId: "reject-once",
|
|
156
|
+
reason: `Write path ${relPosix} is outside allowed draft globs.`,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
outcome: "selected",
|
|
163
|
+
optionId: "allow-once",
|
|
164
|
+
reason: "Authorized sandbox draft write.",
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
outcome: "selected",
|
|
169
|
+
optionId: "allow-once",
|
|
170
|
+
reason: "Authorized read-only workspace inspection.",
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Generates a standalone cross-platform Node.js Fail-Closed Hook script (.mjs)
|
|
175
|
+
* for `PreToolUse` and `UserPromptSubmit`.
|
|
176
|
+
*
|
|
177
|
+
* Security invariant: ANY uncaught exception, malformed JSON input, symlink escape,
|
|
178
|
+
* sensitive file touch, or unauthorized write exits with code `2` (never `0` or `1`).
|
|
179
|
+
*/
|
|
180
|
+
export function generateFailClosedHookScript(options) {
|
|
181
|
+
const serializedConfig = JSON.stringify({
|
|
182
|
+
shareId: options.shareId,
|
|
183
|
+
workspacePath: options.workspacePath,
|
|
184
|
+
permissionTier: options.permissionTier,
|
|
185
|
+
writableGlobs: options.writableGlobs ?? [],
|
|
186
|
+
});
|
|
187
|
+
return `#!/usr/bin/env node
|
|
188
|
+
// Auto-generated by @cyfsh/adapters — Fail-Closed Guest Shadow Guard
|
|
189
|
+
import fs from "node:fs";
|
|
190
|
+
import path from "node:path";
|
|
191
|
+
|
|
192
|
+
process.on("uncaughtException", (err) => {
|
|
193
|
+
process.stderr.write("[CYFGuard] Uncaught error (Fail-Closed Exit 2): " + String(err) + "\\n");
|
|
194
|
+
process.exit(2);
|
|
195
|
+
});
|
|
196
|
+
process.on("unhandledRejection", (reason) => {
|
|
197
|
+
process.stderr.write("[CYFGuard] Unhandled rejection (Fail-Closed Exit 2): " + String(reason) + "\\n");
|
|
198
|
+
process.exit(2);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
const CONFIG = ${serializedConfig};
|
|
202
|
+
|
|
203
|
+
const SENSITIVE_BASENAMES = [
|
|
204
|
+
/^\\.env(\\..+)?$/i,
|
|
205
|
+
/\\.pem$/i,
|
|
206
|
+
/\\.key$/i,
|
|
207
|
+
/\\.p12$/i,
|
|
208
|
+
/\\.pfx$/i,
|
|
209
|
+
/^id_(rsa|ed25519|ecdsa|dsa)(\\.pub)?$/i,
|
|
210
|
+
/^\\.npmrc$/i,
|
|
211
|
+
/^\\.netrc$/i,
|
|
212
|
+
/credential/i,
|
|
213
|
+
/secret/i,
|
|
214
|
+
];
|
|
215
|
+
const SENSITIVE_DIRS = new Set([".ssh", ".aws", ".gnupg", ".kube"]);
|
|
216
|
+
|
|
217
|
+
function resolveReal(workspaceRoot, candidate) {
|
|
218
|
+
const wsAbs = path.resolve(workspaceRoot);
|
|
219
|
+
const wsReal = fs.existsSync(wsAbs) ? fs.realpathSync(wsAbs) : wsAbs;
|
|
220
|
+
const raw = path.resolve(wsReal, candidate);
|
|
221
|
+
const rest = [];
|
|
222
|
+
let cur = raw;
|
|
223
|
+
while (!fs.existsSync(cur)) {
|
|
224
|
+
const parent = path.dirname(cur);
|
|
225
|
+
if (parent === cur) break;
|
|
226
|
+
rest.unshift(path.basename(cur));
|
|
227
|
+
cur = parent;
|
|
228
|
+
}
|
|
229
|
+
const baseReal = fs.existsSync(cur) ? fs.realpathSync(cur) : cur;
|
|
230
|
+
const targetReal = rest.length > 0 ? path.join(baseReal, ...rest) : baseReal;
|
|
231
|
+
return { wsReal, targetReal };
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function isInside(parentReal, childReal) {
|
|
235
|
+
const p = process.platform === "win32" ? path.resolve(parentReal).toLowerCase() : path.resolve(parentReal);
|
|
236
|
+
const c = process.platform === "win32" ? path.resolve(childReal).toLowerCase() : path.resolve(childReal);
|
|
237
|
+
if (c === p) return true;
|
|
238
|
+
const prefix = p.endsWith(path.sep) ? p : p + path.sep;
|
|
239
|
+
return c.startsWith(prefix);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function isSensitive(filePath) {
|
|
243
|
+
const norm = String(filePath).replace(/\\\\/g, "/");
|
|
244
|
+
if (norm.toLowerCase().endsWith("/.git/config") || norm.toLowerCase() === ".git/config") return true;
|
|
245
|
+
const parts = norm.split("/").filter(Boolean);
|
|
246
|
+
for (const part of parts) {
|
|
247
|
+
if (SENSITIVE_DIRS.has(part.toLowerCase())) return true;
|
|
248
|
+
}
|
|
249
|
+
const base = parts[parts.length - 1] ?? "";
|
|
250
|
+
return SENSITIVE_BASENAMES.some((rx) => rx.test(base));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function matchesGlob(relPosix, globPattern) {
|
|
254
|
+
const cleanRel = relPosix.replace(/^\\/+/, "");
|
|
255
|
+
const cleanGlob = String(globPattern).replace(/\\\\/g, "/").replace(/^\\/+/, "");
|
|
256
|
+
const rxBody = cleanGlob
|
|
257
|
+
.replace(/[.+^\${}()|[\\]\\\\]/g, "\\\\$&")
|
|
258
|
+
.replace(/\\*\\*/g, "__DS__")
|
|
259
|
+
.replace(/\\*/g, "[^/]*")
|
|
260
|
+
.replace(/__DS__/g, ".*");
|
|
261
|
+
return new RegExp("^" + rxBody + "$", "i").test(cleanRel);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
try {
|
|
265
|
+
const rawStdin = fs.readFileSync(0, "utf8").trim();
|
|
266
|
+
if (!rawStdin) {
|
|
267
|
+
process.stderr.write("[CYFGuard] Empty hook payload rejected (Fail-Closed).\\n");
|
|
268
|
+
process.exit(2);
|
|
269
|
+
}
|
|
270
|
+
const payload = JSON.parse(rawStdin);
|
|
271
|
+
if (typeof payload !== "object" || payload === null || Array.isArray(payload)) {
|
|
272
|
+
process.stderr.write("[CYFGuard] Non-object hook payload rejected.\\n");
|
|
273
|
+
process.exit(2);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const eventName = String(payload.hook_event_name ?? payload.event ?? "PreToolUse");
|
|
277
|
+
|
|
278
|
+
if (eventName === "UserPromptSubmit") {
|
|
279
|
+
const promptText = String(payload.prompt ?? payload.user_prompt ?? "");
|
|
280
|
+
if (/(?:rm\\s+-rf|cat\\s+.*\\.env|ignore\\s+all\\s+previous\\s+instructions)/i.test(promptText)) {
|
|
281
|
+
process.stderr.write("[CYFGuard] Blocked unsafe guest prompt pattern.\\n");
|
|
282
|
+
process.exit(2);
|
|
283
|
+
}
|
|
284
|
+
process.exit(0);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const toolName = String(payload.tool_name ?? payload.toolName ?? "");
|
|
288
|
+
const toolInput =
|
|
289
|
+
typeof payload.tool_input === "object" && payload.tool_input !== null
|
|
290
|
+
? payload.tool_input
|
|
291
|
+
: {};
|
|
292
|
+
|
|
293
|
+
if (!toolName) {
|
|
294
|
+
process.stderr.write("[CYFGuard] Missing tool_name in PreToolUse payload.\\n");
|
|
295
|
+
process.exit(2);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const shellRx = /^(?:Bash|RunCommand|run_terminal_cmd|shell|exec|terminal)$/i;
|
|
299
|
+
if (shellRx.test(toolName)) {
|
|
300
|
+
const commandStr = String(toolInput.command ?? toolInput.cmd ?? "");
|
|
301
|
+
if (
|
|
302
|
+
CONFIG.permissionTier !== "TIER_2_WORKTREE_SANDBOX" ||
|
|
303
|
+
/(?:rm\\s+-rf|mkfs|del\\s+\\/[fsq]|\\.env|\\.pem|\\.ssh|id_rsa|printenv)/i.test(commandStr)
|
|
304
|
+
) {
|
|
305
|
+
process.stderr.write("[CYFGuard] Terminal command blocked by guest shadow policy.\\n");
|
|
306
|
+
process.exit(2);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const candidatePaths = [];
|
|
311
|
+
for (const key of ["file_path", "path", "target_file", "notebook_path", "cwd"]) {
|
|
312
|
+
if (typeof toolInput[key] === "string" && toolInput[key].trim().length > 0) {
|
|
313
|
+
candidatePaths.push(toolInput[key].trim());
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
if (Array.isArray(toolInput.paths)) {
|
|
317
|
+
for (const item of toolInput.paths) {
|
|
318
|
+
if (typeof item === "string") candidatePaths.push(item);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const writeRx = /^(?:Write|Edit|MultiEdit|NotebookEdit|write_file|patch|DeleteFile)$/i;
|
|
323
|
+
|
|
324
|
+
for (const rawCandidate of candidatePaths) {
|
|
325
|
+
const { wsReal, targetReal } = resolveReal(CONFIG.workspacePath, rawCandidate);
|
|
326
|
+
if (!isInside(wsReal, targetReal)) {
|
|
327
|
+
process.stderr.write("[CYFGuard] Path escape blocked: " + rawCandidate + "\\n");
|
|
328
|
+
process.exit(2);
|
|
329
|
+
}
|
|
330
|
+
if (isSensitive(rawCandidate) || isSensitive(targetReal)) {
|
|
331
|
+
process.stderr.write("[CYFGuard] Sensitive path access blocked: " + rawCandidate + "\\n");
|
|
332
|
+
process.exit(2);
|
|
333
|
+
}
|
|
334
|
+
if (writeRx.test(toolName) && CONFIG.permissionTier === "TIER_1_DISCUSS_AND_DRAFT") {
|
|
335
|
+
const relPosix = path.relative(wsReal, targetReal).replace(/\\\\/g, "/");
|
|
336
|
+
const allowed = CONFIG.writableGlobs.some((g) => matchesGlob(relPosix, g));
|
|
337
|
+
if (!allowed) {
|
|
338
|
+
process.stderr.write("[CYFGuard] Unauthorized write blocked in TIER_1: " + relPosix + "\\n");
|
|
339
|
+
process.exit(2);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
if (writeRx.test(toolName) && candidatePaths.length === 0 && CONFIG.permissionTier === "TIER_1_DISCUSS_AND_DRAFT") {
|
|
345
|
+
process.stderr.write("[CYFGuard] Write tool without explicit path blocked.\\n");
|
|
346
|
+
process.exit(2);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
process.exit(0);
|
|
350
|
+
} catch (err) {
|
|
351
|
+
process.stderr.write("[CYFGuard] Exception caught (Fail-Closed Exit 2): " + String(err) + "\\n");
|
|
352
|
+
process.exit(2);
|
|
353
|
+
}
|
|
354
|
+
`;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Generates managed Claude Code / CodeBuddy `settings.json` binding both
|
|
358
|
+
* `UserPromptSubmit` and `PreToolUse` to the Fail-Closed Node guard script.
|
|
359
|
+
*/
|
|
360
|
+
export function generateManagedHookSettingsJson(guardScriptPath) {
|
|
361
|
+
const normalizedScript = guardScriptPath.replace(/\\/g, "/");
|
|
362
|
+
const hookCommand = `node "${normalizedScript}"`;
|
|
363
|
+
return JSON.stringify({
|
|
364
|
+
permissions: {
|
|
365
|
+
deny: [
|
|
366
|
+
"Read(.env)",
|
|
367
|
+
"Read(.env.*)",
|
|
368
|
+
"Read(**/*.pem)",
|
|
369
|
+
"Read(**/*.key)",
|
|
370
|
+
"Read(~/.ssh/**)",
|
|
371
|
+
],
|
|
372
|
+
},
|
|
373
|
+
hooks: {
|
|
374
|
+
UserPromptSubmit: [
|
|
375
|
+
{
|
|
376
|
+
hooks: [
|
|
377
|
+
{
|
|
378
|
+
type: "command",
|
|
379
|
+
command: hookCommand,
|
|
380
|
+
},
|
|
381
|
+
],
|
|
382
|
+
},
|
|
383
|
+
],
|
|
384
|
+
PreToolUse: [
|
|
385
|
+
{
|
|
386
|
+
matcher: "*",
|
|
387
|
+
hooks: [
|
|
388
|
+
{
|
|
389
|
+
type: "command",
|
|
390
|
+
command: hookCommand,
|
|
391
|
+
},
|
|
392
|
+
],
|
|
393
|
+
},
|
|
394
|
+
],
|
|
395
|
+
},
|
|
396
|
+
}, null, 2);
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Generates an empty strict MCP config so `--strict-mcp-config --mcp-config <path>`
|
|
400
|
+
* strips all private database/cloud credentials from the guest shadow process.
|
|
401
|
+
*/
|
|
402
|
+
export function generateStrictEmptyMcpJson() {
|
|
403
|
+
return JSON.stringify({ mcpServers: {} }, null, 2);
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Generates `cyf-dsh-guard-patch.yaml` for DeepSeek Harness (`dsh --patch`),
|
|
407
|
+
* stripping destructive tools & private MCP plugins via Cordis overlay without mutating `~/.dsh`.
|
|
408
|
+
*/
|
|
409
|
+
export function generateDshCordisGuardPatchYaml(options) {
|
|
410
|
+
const escapedWorkspace = options.workspacePath.replace(/\\/g, "/");
|
|
411
|
+
const escapedScript = options.guardScriptPath.replace(/\\/g, "/");
|
|
412
|
+
const allowSandboxWrite = options.permissionTier === "TIER_2_WORKTREE_SANDBOX";
|
|
413
|
+
return [
|
|
414
|
+
"# Auto-generated by @cyfsh/adapters for DeepSeek Harness (dsh --patch)",
|
|
415
|
+
`# Share ID: ${options.shareId}`,
|
|
416
|
+
"cordis:",
|
|
417
|
+
" profile: cyf-ephemeral-guest",
|
|
418
|
+
" inheritUserMcp: false",
|
|
419
|
+
"tools:",
|
|
420
|
+
" disabled:",
|
|
421
|
+
" - bash",
|
|
422
|
+
" - terminal_exec",
|
|
423
|
+
" - mcp_private_bridge",
|
|
424
|
+
...(allowSandboxWrite ? [] : [" - write_file", " - edit_file", " - delete_file"]),
|
|
425
|
+
"plugins:",
|
|
426
|
+
" cyf-readonly-guard:",
|
|
427
|
+
" enabled: true",
|
|
428
|
+
" failClosedExitCode: 2",
|
|
429
|
+
` shareId: "${options.shareId}"`,
|
|
430
|
+
` workspaceRoot: "${escapedWorkspace}"`,
|
|
431
|
+
` permissionTier: "${options.permissionTier}"`,
|
|
432
|
+
` hookScript: "${escapedScript}"`,
|
|
433
|
+
" blockedPatterns:",
|
|
434
|
+
' - "**/.env"',
|
|
435
|
+
' - "**/.env.*"',
|
|
436
|
+
' - "**/*.pem"',
|
|
437
|
+
' - "**/*.key"',
|
|
438
|
+
' - "**/.ssh/**"',
|
|
439
|
+
' - "**/.git/config"',
|
|
440
|
+
"",
|
|
441
|
+
].join("\n");
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Builds virtual or disk-materialized guard artifacts for a given share session.
|
|
445
|
+
*/
|
|
446
|
+
export function buildGuardArtifactBundle(baseDir, options, writeToDisk = false) {
|
|
447
|
+
const resolvedDir = path.resolve(baseDir);
|
|
448
|
+
const guardScriptPath = path.join(resolvedDir, "cyf-fail-closed-guard.mjs");
|
|
449
|
+
const emptyMcpConfigPath = path.join(resolvedDir, "cyf-strict-mcp.json");
|
|
450
|
+
const claudeSettingsPath = path.join(resolvedDir, "cyf-managed-settings.json");
|
|
451
|
+
const dshPatchYamlPath = path.join(resolvedDir, "cyf-dsh-guard-patch.yaml");
|
|
452
|
+
const guardScriptContent = generateFailClosedHookScript(options);
|
|
453
|
+
const emptyMcpContent = generateStrictEmptyMcpJson();
|
|
454
|
+
const claudeSettingsContent = generateManagedHookSettingsJson(guardScriptPath);
|
|
455
|
+
const dshPatchYamlContent = generateDshCordisGuardPatchYaml({
|
|
456
|
+
...options,
|
|
457
|
+
guardScriptPath,
|
|
458
|
+
});
|
|
459
|
+
const files = [
|
|
460
|
+
{
|
|
461
|
+
relativePath: "cyf-fail-closed-guard.mjs",
|
|
462
|
+
absolutePath: guardScriptPath,
|
|
463
|
+
content: guardScriptContent,
|
|
464
|
+
executable: true,
|
|
465
|
+
},
|
|
466
|
+
{
|
|
467
|
+
relativePath: "cyf-strict-mcp.json",
|
|
468
|
+
absolutePath: emptyMcpConfigPath,
|
|
469
|
+
content: emptyMcpContent,
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
relativePath: "cyf-managed-settings.json",
|
|
473
|
+
absolutePath: claudeSettingsPath,
|
|
474
|
+
content: claudeSettingsContent,
|
|
475
|
+
},
|
|
476
|
+
{
|
|
477
|
+
relativePath: "cyf-dsh-guard-patch.yaml",
|
|
478
|
+
absolutePath: dshPatchYamlPath,
|
|
479
|
+
content: dshPatchYamlContent,
|
|
480
|
+
},
|
|
481
|
+
];
|
|
482
|
+
if (writeToDisk) {
|
|
483
|
+
fs.mkdirSync(resolvedDir, { recursive: true });
|
|
484
|
+
for (const file of files) {
|
|
485
|
+
fs.writeFileSync(file.absolutePath, file.content, "utf8");
|
|
486
|
+
if (file.executable && process.platform !== "win32") {
|
|
487
|
+
fs.chmodSync(file.absolutePath, 0o755);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
return {
|
|
492
|
+
guardScriptPath,
|
|
493
|
+
emptyMcpConfigPath,
|
|
494
|
+
claudeSettingsPath,
|
|
495
|
+
dshPatchYamlPath,
|
|
496
|
+
files,
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
//# sourceMappingURL=guard-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guard-generator.js","sourceRoot":"","sources":["../src/guard-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAuB7B,MAAM,2BAA2B,GAAsB;IACrD,iBAAiB;IACjB,SAAS;IACT,SAA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AChC,OAAO,EAAE,qBAAqB;SAC/B;QACD;YACE,YAAY,EAAE,0BAA0B;YACxC,YAAY,EAAE,gBAAgB;YAC9B,OAAO,EAAE,mBAAmB;SAC7B;KACF,CAAC;IAEF,IAAI,WAAW,EAAE,CAAC;QAChB,EAAE,CAAC,SAAS,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC/C,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YAC1D,IAAI,IAAI,CAAC,UAAU,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;gBACpD,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;YACzC,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO;QACL,eAAe;QACf,kBAAkB;QAClB,kBAAkB;QAClB,gBAAgB;QAChB,KAAK;KACN,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const ADAPTERS_VERSION = "0.1.0";
|
|
2
|
+
export type { AcpPermissionCheckInput, AcpPermissionDecision, AgentRuntimeAdapter, EngineLaunchSpec, GeneratedGuardFile, GuardInterceptionDetail, HttpEndpointDescriptor, JsonRpcRequestFrame, PendingGreyZoneEscalation, RuntimeInjectedContext, RuntimeTurnRequest, RuntimeTurnResult, SessionDiscoveryPort, } from "./types.js";
|
|
3
|
+
export { buildGuardArtifactBundle, evaluateAcpPermissionRequest, generateDshCordisGuardPatchYaml, generateFailClosedHookScript, generateManagedHookSettingsJson, generateStrictEmptyMcpJson, isSensitivePath, isWithinDirectory, resolveCanonicalTargetPath, type GuardGeneratorOptions, type MaterializedGuardBundle, } from "./guard-generator.js";
|
|
4
|
+
export { buildRuntimeSystemEnvelope, runSandboxResponder, } from "./sandbox-responder.js";
|
|
5
|
+
export { ClaudeCodeAdapter, CodeBuddyAdapter, CodexAdapter, createRuntimeAdapterRegistry, DshAdapter, OpenCodeAdapter, RuntimeAdapterRegistry, type RuntimeAdapterOptions, } from "./adapters.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,UAAU,CAAC;AAExC,YAAY,EACV,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,uBAAuB,EACvB,sBAAsB,EACtB,mBAAmB,EACnB,yBAAyB,EACzB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,wBAAwB,EACxB,4BAA4B,EAC5B,+BAA+B,EAC/B,4BAA4B,EAC5B,+BAA+B,EAC/B,0BAA0B,EAC1B,eAAe,EACf,iBAAiB,EACjB,0BAA0B,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,GAC7B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,0BAA0B,EAC1B,mBAAmB,GACpB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,4BAA4B,EAC5B,UAAU,EACV,eAAe,EACf,sBAAsB,EACtB,KAAK,qBAAqB,GAC3B,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export const ADAPTERS_VERSION = "0.1.0";
|
|
2
|
+
export { buildGuardArtifactBundle, evaluateAcpPermissionRequest, generateDshCordisGuardPatchYaml, generateFailClosedHookScript, generateManagedHookSettingsJson, generateStrictEmptyMcpJson, isSensitivePath, isWithinDirectory, resolveCanonicalTargetPath, } from "./guard-generator.js";
|
|
3
|
+
export { buildRuntimeSystemEnvelope, runSandboxResponder, } from "./sandbox-responder.js";
|
|
4
|
+
export { ClaudeCodeAdapter, CodeBuddyAdapter, CodexAdapter, createRuntimeAdapterRegistry, DshAdapter, OpenCodeAdapter, RuntimeAdapterRegistry, } from "./adapters.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC;AAkBxC,OAAO,EACL,wBAAwB,EACxB,4BAA4B,EAC5B,+BAA+B,EAC/B,4BAA4B,EAC5B,+BAA+B,EAC/B,0BAA0B,EAC1B,eAAe,EACf,iBAAiB,EACjB,0BAA0B,GAG3B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,0BAA0B,EAC1B,mBAAmB,GACpB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,4BAA4B,EAC5B,UAAU,EACV,eAAe,EACf,sBAAsB,GAEvB,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RuntimeInjectedContext, RuntimeTurnRequest, RuntimeTurnResult } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Formats the zero-trust runtime system envelope (C_runtime) injected into
|
|
4
|
+
* clean shadow sessions or sandbox responders.
|
|
5
|
+
*/
|
|
6
|
+
export declare function buildRuntimeSystemEnvelope(context: RuntimeInjectedContext): string;
|
|
7
|
+
/**
|
|
8
|
+
* Deterministic, context-grounded sandbox responder used in zero-API-key local mode
|
|
9
|
+
* (and automated integration tests). Relies strictly on sanitized C_runtime inputs.
|
|
10
|
+
*/
|
|
11
|
+
export declare function runSandboxResponder(request: RuntimeTurnRequest): RuntimeTurnResult;
|
|
12
|
+
//# sourceMappingURL=sandbox-responder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox-responder.d.ts","sourceRoot":"","sources":["../src/sandbox-responder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGV,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAEpB;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,sBAAsB,GAAG,MAAM,CAwClF;AAqED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,kBAAkB,GAAG,iBAAiB,CAsIlF"}
|