@red-codes/agentguard 1.1.3 → 1.1.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/dist/bin.js +26 -6
- package/dist/bin.js.map +2 -2
- package/package.json +7 -7
package/dist/bin.js
CHANGED
|
@@ -9497,6 +9497,20 @@ function resolveAgentIdentity(sessionId) {
|
|
|
9497
9497
|
}
|
|
9498
9498
|
return `claude-code:${simpleHash(sessionId.trim())}`;
|
|
9499
9499
|
}
|
|
9500
|
+
function normalizeFilePath(filePath) {
|
|
9501
|
+
if (!filePath)
|
|
9502
|
+
return filePath;
|
|
9503
|
+
const normalized = filePath.replace(/\\/g, "/");
|
|
9504
|
+
const isAbsolute = normalized.startsWith("/") || /^[a-zA-Z]:\//.test(normalized);
|
|
9505
|
+
if (!isAbsolute)
|
|
9506
|
+
return normalized;
|
|
9507
|
+
const cwd = process.cwd().replace(/\\/g, "/");
|
|
9508
|
+
if (normalized.startsWith(cwd + "/")) {
|
|
9509
|
+
return normalized.slice(cwd.length + 1);
|
|
9510
|
+
}
|
|
9511
|
+
const lastSlash = normalized.lastIndexOf("/");
|
|
9512
|
+
return lastSlash >= 0 ? normalized.slice(lastSlash + 1) : normalized;
|
|
9513
|
+
}
|
|
9500
9514
|
function normalizeClaudeCodeAction(payload, persona) {
|
|
9501
9515
|
const input = payload.tool_input || {};
|
|
9502
9516
|
const agent = resolveAgentIdentity(payload.session_id);
|
|
@@ -9507,7 +9521,7 @@ function normalizeClaudeCodeAction(payload, persona) {
|
|
|
9507
9521
|
case "Write":
|
|
9508
9522
|
baseAction = {
|
|
9509
9523
|
tool: "Write",
|
|
9510
|
-
file: input.file_path,
|
|
9524
|
+
file: normalizeFilePath(input.file_path),
|
|
9511
9525
|
content: input.content,
|
|
9512
9526
|
agent,
|
|
9513
9527
|
metadata: { hook: payload.hook, sessionId: payload.session_id }
|
|
@@ -9516,7 +9530,7 @@ function normalizeClaudeCodeAction(payload, persona) {
|
|
|
9516
9530
|
case "Edit":
|
|
9517
9531
|
baseAction = {
|
|
9518
9532
|
tool: "Edit",
|
|
9519
|
-
file: input.file_path,
|
|
9533
|
+
file: normalizeFilePath(input.file_path),
|
|
9520
9534
|
content: input.new_string,
|
|
9521
9535
|
agent,
|
|
9522
9536
|
metadata: {
|
|
@@ -9529,7 +9543,7 @@ function normalizeClaudeCodeAction(payload, persona) {
|
|
|
9529
9543
|
case "Read":
|
|
9530
9544
|
baseAction = {
|
|
9531
9545
|
tool: "Read",
|
|
9532
|
-
file: input.file_path,
|
|
9546
|
+
file: normalizeFilePath(input.file_path),
|
|
9533
9547
|
agent,
|
|
9534
9548
|
metadata: { hook: payload.hook, sessionId: payload.session_id }
|
|
9535
9549
|
};
|
|
@@ -9639,11 +9653,17 @@ function formatHookResponse(result) {
|
|
|
9639
9653
|
if (!result.allowed) {
|
|
9640
9654
|
const reason = result.decision?.decision?.reason ?? "Action denied";
|
|
9641
9655
|
const violations = result.decision?.violations ?? [];
|
|
9642
|
-
const parts = [
|
|
9656
|
+
const parts = [reason];
|
|
9643
9657
|
if (violations.length > 0) {
|
|
9644
9658
|
parts.push(`Violations: ${violations.map((v) => v.name).join(", ")}`);
|
|
9645
9659
|
}
|
|
9646
|
-
return JSON.stringify({
|
|
9660
|
+
return JSON.stringify({
|
|
9661
|
+
hookSpecificOutput: {
|
|
9662
|
+
hookEventName: "PreToolUse",
|
|
9663
|
+
permissionDecision: "deny",
|
|
9664
|
+
permissionDecisionReason: parts.join(" | ")
|
|
9665
|
+
}
|
|
9666
|
+
});
|
|
9647
9667
|
}
|
|
9648
9668
|
return "";
|
|
9649
9669
|
}
|
|
@@ -29048,7 +29068,7 @@ async function main() {
|
|
|
29048
29068
|
}
|
|
29049
29069
|
case "--version":
|
|
29050
29070
|
case "-v": {
|
|
29051
|
-
console.log(`agentguard v${"1.1.
|
|
29071
|
+
console.log(`agentguard v${"1.1.5"}`);
|
|
29052
29072
|
break;
|
|
29053
29073
|
}
|
|
29054
29074
|
case "help":
|