agentmask 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.
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ DEFAULT_BLOCKED_PATTERNS,
4
+ isBlockedPath
5
+ } from "./chunk-Q7ZBIDBL.js";
6
+ import {
7
+ allow,
8
+ block,
9
+ readStdin,
10
+ startSafetyTimer
11
+ } from "./chunk-YASOHGJL.js";
12
+ import {
13
+ scanContent
14
+ } from "./chunk-P7BRPZBB.js";
15
+ import "./chunk-2H7UOFLK.js";
16
+
17
+ // src/hooks/pre-write.ts
18
+ import { basename } from "path";
19
+ startSafetyTimer();
20
+ async function main() {
21
+ const input = await readStdin();
22
+ const filePath = input.tool_input?.file_path;
23
+ if (!filePath) {
24
+ allow();
25
+ return;
26
+ }
27
+ if (isBlockedPath(filePath, DEFAULT_BLOCKED_PATTERNS)) {
28
+ allow();
29
+ return;
30
+ }
31
+ const content = input.tool_input?.content ?? input.tool_input?.new_string;
32
+ if (!content) {
33
+ allow();
34
+ return;
35
+ }
36
+ try {
37
+ const findings = await scanContent(content, basename(filePath));
38
+ if (findings.length > 0) {
39
+ const details = findings.map((f) => ` Line ${f.StartLine}: ${f.Description}`).join("\n");
40
+ block(
41
+ `[agentmask] BLOCKED: Detected ${findings.length} secret(s) in content being written to ${filePath}:
42
+ ${details}
43
+
44
+ Use environment variable references instead of hardcoding secrets.
45
+ Example: process.env.API_KEY or os.environ["API_KEY"]`
46
+ );
47
+ }
48
+ } catch {
49
+ }
50
+ allow();
51
+ }
52
+ main().catch(() => process.exit(1));
53
+ //# sourceMappingURL=pre-write-EBMADS22.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/pre-write.ts"],"sourcesContent":["import { readStdin, block, allow, startSafetyTimer } from \"./common.js\";\nimport { isBlockedPath, DEFAULT_BLOCKED_PATTERNS } from \"../scanner/file-patterns.js\";\nimport { scanContent } from \"../gitleaks/runner.js\";\nimport { basename } from \"node:path\";\n\nstartSafetyTimer();\n\nasync function main() {\n const input = await readStdin();\n const filePath = input.tool_input?.file_path as string | undefined;\n\n if (!filePath) {\n allow();\n return;\n }\n\n // Don't scan writes TO secret files (they're expected to have secrets)\n if (isBlockedPath(filePath, DEFAULT_BLOCKED_PATTERNS)) {\n allow();\n return;\n }\n\n // Get the content being written\n const content =\n (input.tool_input?.content as string | undefined) ??\n (input.tool_input?.new_string as string | undefined);\n\n if (!content) {\n allow();\n return;\n }\n\n try {\n const findings = await scanContent(content, basename(filePath));\n\n if (findings.length > 0) {\n const details = findings\n .map((f) => ` Line ${f.StartLine}: ${f.Description}`)\n .join(\"\\n\");\n block(\n `[agentmask] BLOCKED: Detected ${findings.length} secret(s) in content being written to ${filePath}:\\n` +\n `${details}\\n\\n` +\n `Use environment variable references instead of hardcoding secrets.\\n` +\n `Example: process.env.API_KEY or os.environ[\"API_KEY\"]`,\n );\n }\n } catch {\n // gitleaks failed — degrade gracefully, allow the write\n }\n\n allow();\n}\n\nmain().catch(() => process.exit(1));\n"],"mappings":";;;;;;;;;;;;;;;;;AAGA,SAAS,gBAAgB;AAEzB,iBAAiB;AAEjB,eAAe,OAAO;AACpB,QAAM,QAAQ,MAAM,UAAU;AAC9B,QAAM,WAAW,MAAM,YAAY;AAEnC,MAAI,CAAC,UAAU;AACb,UAAM;AACN;AAAA,EACF;AAGA,MAAI,cAAc,UAAU,wBAAwB,GAAG;AACrD,UAAM;AACN;AAAA,EACF;AAGA,QAAM,UACH,MAAM,YAAY,WAClB,MAAM,YAAY;AAErB,MAAI,CAAC,SAAS;AACZ,UAAM;AACN;AAAA,EACF;AAEA,MAAI;AACF,UAAM,WAAW,MAAM,YAAY,SAAS,SAAS,QAAQ,CAAC;AAE9D,QAAI,SAAS,SAAS,GAAG;AACvB,YAAM,UAAU,SACb,IAAI,CAAC,MAAM,UAAU,EAAE,SAAS,KAAK,EAAE,WAAW,EAAE,EACpD,KAAK,IAAI;AACZ;AAAA,QACE,iCAAiC,SAAS,MAAM,0CAA0C,QAAQ;AAAA,EAC7F,OAAO;AAAA;AAAA;AAAA;AAAA,MAGd;AAAA,IACF;AAAA,EACF,QAAQ;AAAA,EAER;AAEA,QAAM;AACR;AAEA,KAAK,EAAE,MAAM,MAAM,QAAQ,KAAK,CAAC,CAAC;","names":[]}