@red-codes/agentguard 1.0.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 +190 -0
- package/README.md +298 -0
- package/dist/adapters/claude-code.d.ts +24 -0
- package/dist/adapters/claude-code.d.ts.map +1 -0
- package/dist/adapters/claude-code.js +99 -0
- package/dist/adapters/claude-code.js.map +1 -0
- package/dist/adapters/file.d.ts +3 -0
- package/dist/adapters/file.d.ts.map +1 -0
- package/dist/adapters/file.js +35 -0
- package/dist/adapters/file.js.map +1 -0
- package/dist/adapters/git.d.ts +3 -0
- package/dist/adapters/git.d.ts.map +1 -0
- package/dist/adapters/git.js +61 -0
- package/dist/adapters/git.js.map +1 -0
- package/dist/adapters/registry.d.ts +5 -0
- package/dist/adapters/registry.d.ts.map +1 -0
- package/dist/adapters/registry.js +15 -0
- package/dist/adapters/registry.js.map +1 -0
- package/dist/adapters/shell.d.ts +8 -0
- package/dist/adapters/shell.d.ts.map +1 -0
- package/dist/adapters/shell.js +27 -0
- package/dist/adapters/shell.js.map +1 -0
- package/dist/cli/args.d.ts +25 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +63 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/bin.d.ts +3 -0
- package/dist/cli/bin.d.ts.map +1 -0
- package/dist/cli/bin.js +5769 -0
- package/dist/cli/bin.js.map +7 -0
- package/dist/cli/colors.d.ts +11 -0
- package/dist/cli/colors.d.ts.map +1 -0
- package/dist/cli/colors.js +44 -0
- package/dist/cli/colors.js.map +1 -0
- package/dist/cli/commands/claude-hook.d.ts +2 -0
- package/dist/cli/commands/claude-hook.d.ts.map +1 -0
- package/dist/cli/commands/claude-hook.js +110 -0
- package/dist/cli/commands/claude-hook.js.map +1 -0
- package/dist/cli/commands/claude-init.d.ts +2 -0
- package/dist/cli/commands/claude-init.d.ts.map +1 -0
- package/dist/cli/commands/claude-init.js +150 -0
- package/dist/cli/commands/claude-init.js.map +1 -0
- package/dist/cli/commands/export.d.ts +11 -0
- package/dist/cli/commands/export.d.ts.map +1 -0
- package/dist/cli/commands/export.js +113 -0
- package/dist/cli/commands/export.js.map +1 -0
- package/dist/cli/commands/guard.d.ts +12 -0
- package/dist/cli/commands/guard.d.ts.map +1 -0
- package/dist/cli/commands/guard.js +145 -0
- package/dist/cli/commands/guard.js.map +1 -0
- package/dist/cli/commands/import.d.ts +2 -0
- package/dist/cli/commands/import.d.ts.map +1 -0
- package/dist/cli/commands/import.js +115 -0
- package/dist/cli/commands/import.js.map +1 -0
- package/dist/cli/commands/inspect.d.ts +3 -0
- package/dist/cli/commands/inspect.d.ts.map +1 -0
- package/dist/cli/commands/inspect.js +185 -0
- package/dist/cli/commands/inspect.js.map +1 -0
- package/dist/cli/commands/plugin.d.ts +7 -0
- package/dist/cli/commands/plugin.d.ts.map +1 -0
- package/dist/cli/commands/plugin.js +234 -0
- package/dist/cli/commands/plugin.js.map +1 -0
- package/dist/cli/commands/replay.d.ts +12 -0
- package/dist/cli/commands/replay.d.ts.map +1 -0
- package/dist/cli/commands/replay.js +208 -0
- package/dist/cli/commands/replay.js.map +1 -0
- package/dist/cli/file-event-store.d.ts +41 -0
- package/dist/cli/file-event-store.d.ts.map +1 -0
- package/dist/cli/file-event-store.js +219 -0
- package/dist/cli/file-event-store.js.map +1 -0
- package/dist/cli/policy-resolver.d.ts +4 -0
- package/dist/cli/policy-resolver.d.ts.map +1 -0
- package/dist/cli/policy-resolver.js +62 -0
- package/dist/cli/policy-resolver.js.map +1 -0
- package/dist/cli/recorder.d.ts +36 -0
- package/dist/cli/recorder.d.ts.map +1 -0
- package/dist/cli/recorder.js +85 -0
- package/dist/cli/recorder.js.map +1 -0
- package/dist/cli/replay.d.ts +2 -0
- package/dist/cli/replay.d.ts.map +1 -0
- package/dist/cli/replay.js +310 -0
- package/dist/cli/replay.js.map +1 -0
- package/dist/cli/session-store.d.ts +41 -0
- package/dist/cli/session-store.d.ts.map +1 -0
- package/dist/cli/session-store.js +95 -0
- package/dist/cli/session-store.js.map +1 -0
- package/dist/cli/tui.d.ts +24 -0
- package/dist/cli/tui.d.ts.map +1 -0
- package/dist/cli/tui.js +197 -0
- package/dist/cli/tui.js.map +1 -0
- package/dist/core/actions.d.ts +11 -0
- package/dist/core/actions.d.ts.map +1 -0
- package/dist/core/actions.js +112 -0
- package/dist/core/actions.js.map +1 -0
- package/dist/core/adapters.d.ts +19 -0
- package/dist/core/adapters.d.ts.map +1 -0
- package/dist/core/adapters.js +85 -0
- package/dist/core/adapters.js.map +1 -0
- package/dist/core/execution-log/bridge.d.ts +12 -0
- package/dist/core/execution-log/bridge.d.ts.map +1 -0
- package/dist/core/execution-log/bridge.js +112 -0
- package/dist/core/execution-log/bridge.js.map +1 -0
- package/dist/core/execution-log/event-log.d.ts +7 -0
- package/dist/core/execution-log/event-log.d.ts.map +1 -0
- package/dist/core/execution-log/event-log.js +103 -0
- package/dist/core/execution-log/event-log.js.map +1 -0
- package/dist/core/execution-log/event-projections.d.ts +28 -0
- package/dist/core/execution-log/event-projections.d.ts.map +1 -0
- package/dist/core/execution-log/event-projections.js +272 -0
- package/dist/core/execution-log/event-projections.js.map +1 -0
- package/dist/core/execution-log/event-schema.d.ts +56 -0
- package/dist/core/execution-log/event-schema.d.ts.map +1 -0
- package/dist/core/execution-log/event-schema.js +160 -0
- package/dist/core/execution-log/event-schema.js.map +1 -0
- package/dist/core/execution-log/index.d.ts +7 -0
- package/dist/core/execution-log/index.d.ts.map +1 -0
- package/dist/core/execution-log/index.js +13 -0
- package/dist/core/execution-log/index.js.map +1 -0
- package/dist/core/hash.d.ts +5 -0
- package/dist/core/hash.d.ts.map +1 -0
- package/dist/core/hash.js +13 -0
- package/dist/core/hash.js.map +1 -0
- package/dist/core/rng.d.ts +29 -0
- package/dist/core/rng.d.ts.map +1 -0
- package/dist/core/rng.js +48 -0
- package/dist/core/rng.js.map +1 -0
- package/dist/core/types.d.ts +746 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +8 -0
- package/dist/core/types.js.map +1 -0
- package/dist/events/bus.d.ts +24 -0
- package/dist/events/bus.d.ts.map +1 -0
- package/dist/events/bus.js +64 -0
- package/dist/events/bus.js.map +1 -0
- package/dist/events/decision-jsonl.d.ts +8 -0
- package/dist/events/decision-jsonl.d.ts.map +1 -0
- package/dist/events/decision-jsonl.js +44 -0
- package/dist/events/decision-jsonl.js.map +1 -0
- package/dist/events/jsonl.d.ts +8 -0
- package/dist/events/jsonl.d.ts.map +1 -0
- package/dist/events/jsonl.js +46 -0
- package/dist/events/jsonl.js.map +1 -0
- package/dist/events/schema.d.ts +59 -0
- package/dist/events/schema.d.ts.map +1 -0
- package/dist/events/schema.js +296 -0
- package/dist/events/schema.js.map +1 -0
- package/dist/events/store.d.ts +7 -0
- package/dist/events/store.d.ts.map +1 -0
- package/dist/events/store.js +64 -0
- package/dist/events/store.js.map +1 -0
- package/dist/invariants/checker.d.ts +15 -0
- package/dist/invariants/checker.d.ts.map +1 -0
- package/dist/invariants/checker.js +52 -0
- package/dist/invariants/checker.js.map +1 -0
- package/dist/invariants/definitions.d.ts +33 -0
- package/dist/invariants/definitions.d.ts.map +1 -0
- package/dist/invariants/definitions.js +168 -0
- package/dist/invariants/definitions.js.map +1 -0
- package/dist/kernel/aab.d.ts +26 -0
- package/dist/kernel/aab.d.ts.map +1 -0
- package/dist/kernel/aab.js +149 -0
- package/dist/kernel/aab.js.map +1 -0
- package/dist/kernel/blast-radius.d.ts +60 -0
- package/dist/kernel/blast-radius.d.ts.map +1 -0
- package/dist/kernel/blast-radius.js +146 -0
- package/dist/kernel/blast-radius.js.map +1 -0
- package/dist/kernel/decision.d.ts +40 -0
- package/dist/kernel/decision.d.ts.map +1 -0
- package/dist/kernel/decision.js +92 -0
- package/dist/kernel/decision.js.map +1 -0
- package/dist/kernel/decisions/factory.d.ts +12 -0
- package/dist/kernel/decisions/factory.d.ts.map +1 -0
- package/dist/kernel/decisions/factory.js +56 -0
- package/dist/kernel/decisions/factory.js.map +1 -0
- package/dist/kernel/decisions/types.d.ts +70 -0
- package/dist/kernel/decisions/types.d.ts.map +1 -0
- package/dist/kernel/decisions/types.js +5 -0
- package/dist/kernel/decisions/types.js.map +1 -0
- package/dist/kernel/evidence.d.ts +29 -0
- package/dist/kernel/evidence.d.ts.map +1 -0
- package/dist/kernel/evidence.js +61 -0
- package/dist/kernel/evidence.js.map +1 -0
- package/dist/kernel/kernel.d.ts +47 -0
- package/dist/kernel/kernel.d.ts.map +1 -0
- package/dist/kernel/kernel.js +377 -0
- package/dist/kernel/kernel.js.map +1 -0
- package/dist/kernel/monitor.d.ts +35 -0
- package/dist/kernel/monitor.d.ts.map +1 -0
- package/dist/kernel/monitor.js +144 -0
- package/dist/kernel/monitor.js.map +1 -0
- package/dist/kernel/replay-comparator.d.ts +72 -0
- package/dist/kernel/replay-comparator.d.ts.map +1 -0
- package/dist/kernel/replay-comparator.js +251 -0
- package/dist/kernel/replay-comparator.js.map +1 -0
- package/dist/kernel/replay-engine.d.ts +108 -0
- package/dist/kernel/replay-engine.d.ts.map +1 -0
- package/dist/kernel/replay-engine.js +241 -0
- package/dist/kernel/replay-engine.js.map +1 -0
- package/dist/kernel/replay-processor.d.ts +109 -0
- package/dist/kernel/replay-processor.d.ts.map +1 -0
- package/dist/kernel/replay-processor.js +118 -0
- package/dist/kernel/replay-processor.js.map +1 -0
- package/dist/kernel/simulation/filesystem-simulator.d.ts +3 -0
- package/dist/kernel/simulation/filesystem-simulator.d.ts.map +1 -0
- package/dist/kernel/simulation/filesystem-simulator.js +81 -0
- package/dist/kernel/simulation/filesystem-simulator.js.map +1 -0
- package/dist/kernel/simulation/git-simulator.d.ts +5 -0
- package/dist/kernel/simulation/git-simulator.d.ts.map +1 -0
- package/dist/kernel/simulation/git-simulator.js +115 -0
- package/dist/kernel/simulation/git-simulator.js.map +1 -0
- package/dist/kernel/simulation/package-simulator.d.ts +5 -0
- package/dist/kernel/simulation/package-simulator.d.ts.map +1 -0
- package/dist/kernel/simulation/package-simulator.js +164 -0
- package/dist/kernel/simulation/package-simulator.js.map +1 -0
- package/dist/kernel/simulation/registry.d.ts +3 -0
- package/dist/kernel/simulation/registry.d.ts.map +1 -0
- package/dist/kernel/simulation/registry.js +24 -0
- package/dist/kernel/simulation/registry.js.map +1 -0
- package/dist/kernel/simulation/types.d.ts +35 -0
- package/dist/kernel/simulation/types.d.ts.map +1 -0
- package/dist/kernel/simulation/types.js +4 -0
- package/dist/kernel/simulation/types.js.map +1 -0
- package/dist/plugins/discovery.d.ts +45 -0
- package/dist/plugins/discovery.d.ts.map +1 -0
- package/dist/plugins/discovery.js +89 -0
- package/dist/plugins/discovery.js.map +1 -0
- package/dist/plugins/index.d.ts +10 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +7 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/registry.d.ts +52 -0
- package/dist/plugins/registry.d.ts.map +1 -0
- package/dist/plugins/registry.js +148 -0
- package/dist/plugins/registry.js.map +1 -0
- package/dist/plugins/sandbox.d.ts +87 -0
- package/dist/plugins/sandbox.d.ts.map +1 -0
- package/dist/plugins/sandbox.js +122 -0
- package/dist/plugins/sandbox.js.map +1 -0
- package/dist/plugins/types.d.ts +61 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +16 -0
- package/dist/plugins/types.js.map +1 -0
- package/dist/plugins/validator.d.ts +36 -0
- package/dist/plugins/validator.d.ts.map +1 -0
- package/dist/plugins/validator.js +276 -0
- package/dist/plugins/validator.js.map +1 -0
- package/dist/policy/evaluator.d.ts +41 -0
- package/dist/policy/evaluator.d.ts.map +1 -0
- package/dist/policy/evaluator.js +111 -0
- package/dist/policy/evaluator.js.map +1 -0
- package/dist/policy/loader.d.ts +13 -0
- package/dist/policy/loader.d.ts.map +1 -0
- package/dist/policy/loader.js +118 -0
- package/dist/policy/loader.js.map +1 -0
- package/dist/policy/pack-loader.d.ts +40 -0
- package/dist/policy/pack-loader.d.ts.map +1 -0
- package/dist/policy/pack-loader.js +138 -0
- package/dist/policy/pack-loader.js.map +1 -0
- package/dist/policy/yaml-loader.d.ts +23 -0
- package/dist/policy/yaml-loader.d.ts.map +1 -0
- package/dist/policy/yaml-loader.js +222 -0
- package/dist/policy/yaml-loader.js.map +1 -0
- package/dist/renderers/index.d.ts +6 -0
- package/dist/renderers/index.d.ts.map +1 -0
- package/dist/renderers/index.js +4 -0
- package/dist/renderers/index.js.map +1 -0
- package/dist/renderers/registry.d.ts +39 -0
- package/dist/renderers/registry.d.ts.map +1 -0
- package/dist/renderers/registry.js +97 -0
- package/dist/renderers/registry.js.map +1 -0
- package/dist/renderers/tui-renderer.d.ts +18 -0
- package/dist/renderers/tui-renderer.d.ts.map +1 -0
- package/dist/renderers/tui-renderer.js +57 -0
- package/dist/renderers/tui-renderer.js.map +1 -0
- package/dist/renderers/types.d.ts +52 -0
- package/dist/renderers/types.d.ts.map +1 -0
- package/dist/renderers/types.js +4 -0
- package/dist/renderers/types.js.map +1 -0
- package/dist/telemetry/index.d.ts +3 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +2 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/telemetry/runtimeLogger.d.ts +9 -0
- package/dist/telemetry/runtimeLogger.d.ts.map +1 -0
- package/dist/telemetry/runtimeLogger.js +68 -0
- package/dist/telemetry/runtimeLogger.js.map +1 -0
- package/dist/telemetry/types.d.ts +22 -0
- package/dist/telemetry/types.d.ts.map +1 -0
- package/dist/telemetry/types.js +4 -0
- package/dist/telemetry/types.js.map +1 -0
- package/hooks/post-commit +57 -0
- package/hooks/post-merge +33 -0
- package/hooks/pre-commit +28 -0
- package/package.json +72 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Jared Pleva
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
# AgentGuard
|
|
2
|
+
|
|
3
|
+
**Governed action runtime for AI coding agents.**
|
|
4
|
+
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](CONTRIBUTING.md)
|
|
7
|
+
[](https://www.npmjs.com/package/@red-codes/agentguard)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
AgentGuard intercepts AI agent tool calls, enforces policies and invariants, and produces a verifiable execution trail. Traditional AI safety focuses on model behavior — AgentGuard enforces safety at the execution layer through deterministic governance of every action.
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
agent proposes action → policy evaluated → invariants checked → allow/deny → execute → events emitted
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
**30 seconds to see it work:**
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
git clone https://github.com/jpleva91/agent-guard.git
|
|
23
|
+
cd agent-guard
|
|
24
|
+
npm install && npm run build:ts
|
|
25
|
+
npm run demo:guard
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Expected output:
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
AgentGuard Runtime Active
|
|
32
|
+
policy: Demo Safety Policy | invariants: 8 active
|
|
33
|
+
|
|
34
|
+
✓ file.read src/auth/service.ts (dry-run)
|
|
35
|
+
✓ file.write src/auth/service.ts (dry-run)
|
|
36
|
+
✓ shell.exec npm test (dry-run)
|
|
37
|
+
✗ git.push main → DENIED (demo-policy)
|
|
38
|
+
Protected branch — use a PR
|
|
39
|
+
✗ file.write .env → DENIED (demo-policy)
|
|
40
|
+
Secrets files must not be modified
|
|
41
|
+
|
|
42
|
+
3 allowed, 2 denied, 15 events emitted
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Try it on your own repo:**
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# Pipe an action into the kernel
|
|
49
|
+
echo '{"tool":"Bash","command":"git push origin main"}' | npx @red-codes/agentguard guard --dry-run
|
|
50
|
+
|
|
51
|
+
# Start the runtime with a policy file
|
|
52
|
+
npx @red-codes/agentguard guard --policy agentguard.yaml
|
|
53
|
+
|
|
54
|
+
# Inspect the last run
|
|
55
|
+
npx @red-codes/agentguard inspect --last
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Why AgentGuard Exists
|
|
59
|
+
|
|
60
|
+
AI coding agents execute file writes, shell commands, and git operations autonomously — but there's no governance layer between what an agent proposes and what actually runs. One bad tool call can push to main, leak secrets, or delete production files.
|
|
61
|
+
|
|
62
|
+
AgentGuard adds a **deterministic decision point** between proposal and execution:
|
|
63
|
+
|
|
64
|
+
- **Safety policies** — declare what agents can and cannot do in YAML
|
|
65
|
+
- **Invariant enforcement** — 8 built-in checks (secrets, protected branches, blast radius, skill/task protection) run on every action
|
|
66
|
+
- **Audit trail** — every decision is recorded as structured JSONL, inspectable after the fact
|
|
67
|
+
- **Session debugging** — replay any agent session to see exactly what happened and why
|
|
68
|
+
|
|
69
|
+
## How It Works
|
|
70
|
+
|
|
71
|
+
AgentGuard evaluates every agent action through a **governed action kernel**:
|
|
72
|
+
|
|
73
|
+
1. **Normalize** — Claude Code tool calls (Bash, Write, Edit, Read) are mapped to canonical action types (shell.exec, file.write, file.read)
|
|
74
|
+
2. **Evaluate** — policies match against the action (deny git.push to main, deny destructive commands, enforce scope limits)
|
|
75
|
+
3. **Check invariants** — 8 built-in safety checks run on every action
|
|
76
|
+
4. **Execute** — if allowed, the action runs via adapters (file, shell, git handlers)
|
|
77
|
+
5. **Emit events** — full lifecycle events sunk to JSONL for audit trail
|
|
78
|
+
|
|
79
|
+
### Example Output
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
AgentGuard Runtime Active
|
|
83
|
+
policy: agentguard.yaml | invariants: 8 active
|
|
84
|
+
|
|
85
|
+
✓ file.write src/auth/service.ts
|
|
86
|
+
✓ shell.exec npm test
|
|
87
|
+
✗ git.push main → DENIED (protect-main)
|
|
88
|
+
⚠ invariant violated: protected-branch
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Policy Format
|
|
92
|
+
|
|
93
|
+
Policies are YAML or JSON files that declare what agents can and cannot do:
|
|
94
|
+
|
|
95
|
+
```yaml
|
|
96
|
+
id: project-policy
|
|
97
|
+
name: Project Policy
|
|
98
|
+
severity: 4
|
|
99
|
+
rules:
|
|
100
|
+
- action: git.push
|
|
101
|
+
effect: deny
|
|
102
|
+
branches: [main, master]
|
|
103
|
+
reason: Protected branch
|
|
104
|
+
|
|
105
|
+
- action: git.force-push
|
|
106
|
+
effect: deny
|
|
107
|
+
reason: Force push not allowed
|
|
108
|
+
|
|
109
|
+
- action: file.write
|
|
110
|
+
effect: deny
|
|
111
|
+
target: .env
|
|
112
|
+
reason: No secrets modification
|
|
113
|
+
|
|
114
|
+
- action: file.read
|
|
115
|
+
effect: allow
|
|
116
|
+
reason: Reading is always safe
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Drop an `agentguard.yaml` in your repo root — the CLI picks it up automatically.
|
|
120
|
+
|
|
121
|
+
## Built-in Invariants
|
|
122
|
+
|
|
123
|
+
8 safety invariants run on every action evaluation:
|
|
124
|
+
|
|
125
|
+
| Invariant | Severity | Description |
|
|
126
|
+
|-----------|----------|-------------|
|
|
127
|
+
| **no-secret-exposure** | 5 (critical) | Blocks access to .env, credentials, .pem, .key files |
|
|
128
|
+
| **protected-branch** | 4 (high) | Prevents direct push to main/master |
|
|
129
|
+
| **no-force-push** | 4 (high) | Forbids force push |
|
|
130
|
+
| **no-skill-modification** | 4 (high) | Prevents modification of .claude/skills/ files |
|
|
131
|
+
| **no-scheduled-task-modification** | 4 (high) | Prevents modification of scheduled task files |
|
|
132
|
+
| **blast-radius-limit** | 3 (medium) | Enforces file modification limit (default 20) |
|
|
133
|
+
| **test-before-push** | 3 (medium) | Requires tests pass before push |
|
|
134
|
+
| **lockfile-integrity** | 2 (low) | Ensures package.json changes sync with lockfiles |
|
|
135
|
+
|
|
136
|
+
## Escalation
|
|
137
|
+
|
|
138
|
+
AgentGuard tracks repeated denials and invariant violations. If an agent repeatedly attempts blocked actions, the runtime escalates to lockdown — all actions denied until a human intervenes. See [escalation state machine](docs/unified-architecture.md) for the full detail.
|
|
139
|
+
|
|
140
|
+
## CLI
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
# === Governance ===
|
|
144
|
+
agentguard guard # Start governed action runtime
|
|
145
|
+
agentguard guard --policy <file> # Use a specific policy file (YAML/JSON)
|
|
146
|
+
agentguard guard --dry-run # Evaluate without executing actions
|
|
147
|
+
agentguard inspect [runId] # Show action graph and decisions for a run
|
|
148
|
+
agentguard inspect --last # Inspect most recent run
|
|
149
|
+
agentguard events [runId] # Show raw event stream for a run
|
|
150
|
+
|
|
151
|
+
# === Portability ===
|
|
152
|
+
agentguard export <runId> # Export a governance session to JSONL
|
|
153
|
+
agentguard export --last # Export the most recent run
|
|
154
|
+
agentguard import <file> # Import a governance session from JSONL
|
|
155
|
+
|
|
156
|
+
# === Replay ===
|
|
157
|
+
agentguard replay --last # Replay a governance session timeline
|
|
158
|
+
agentguard replay --last --step # Step through events interactively
|
|
159
|
+
|
|
160
|
+
# === Plugins ===
|
|
161
|
+
agentguard plugin list # List installed plugins
|
|
162
|
+
agentguard plugin install <path> # Install a plugin from a local path
|
|
163
|
+
agentguard plugin remove <id> # Remove a plugin by ID
|
|
164
|
+
agentguard plugin search [query] # Search for plugins on npm
|
|
165
|
+
|
|
166
|
+
# === Integration ===
|
|
167
|
+
agentguard claude-init # Set up Claude Code hook integration
|
|
168
|
+
agentguard help # Show all commands
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Install globally: `npm i -g @red-codes/agentguard`
|
|
172
|
+
|
|
173
|
+
## Claude Code Integration
|
|
174
|
+
|
|
175
|
+
AgentGuard hooks into [Claude Code](https://docs.anthropic.com/en/docs/claude-code) sessions via PreToolUse/PostToolUse hooks. Every tool call is normalized into a canonical action and evaluated by the kernel.
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
npx @red-codes/agentguard claude-init # Set up Claude Code hooks
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Tool call mapping:
|
|
182
|
+
|
|
183
|
+
| Claude Code Tool | AgentGuard Action |
|
|
184
|
+
|-----------------|-------------------|
|
|
185
|
+
| Write | file.write |
|
|
186
|
+
| Edit | file.write |
|
|
187
|
+
| Read | file.read |
|
|
188
|
+
| Bash | shell.exec (or git.push, git.commit if git command detected) |
|
|
189
|
+
| Glob | file.read |
|
|
190
|
+
| Grep | file.read |
|
|
191
|
+
|
|
192
|
+
## Event Trail
|
|
193
|
+
|
|
194
|
+
Every action proposal, decision, and execution is recorded as JSONL:
|
|
195
|
+
|
|
196
|
+
```
|
|
197
|
+
.agentguard/events/<runId>.jsonl
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Inspect with:
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
agentguard inspect --last # Action summary + event stream
|
|
204
|
+
agentguard events --last # Raw JSONL to stdout (pipe to jq, etc.)
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Architecture
|
|
208
|
+
|
|
209
|
+
```
|
|
210
|
+
Agent Tool Call → AgentGuard Kernel → Policy + Invariants → allow / deny
|
|
211
|
+
│
|
|
212
|
+
┌────────────────────────┤
|
|
213
|
+
▼ ▼
|
|
214
|
+
Execution Adapter Event Stream
|
|
215
|
+
(file, shell, git) (JSONL audit trail)
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Full kernel loop detail: [docs/unified-architecture.md](docs/unified-architecture.md)
|
|
219
|
+
|
|
220
|
+
### Repository Structure
|
|
221
|
+
|
|
222
|
+
```
|
|
223
|
+
src/
|
|
224
|
+
├── kernel/ # Governed action kernel
|
|
225
|
+
│ ├── kernel.ts # Orchestrator (propose → evaluate → execute → emit)
|
|
226
|
+
│ ├── aab.ts # Action Authorization Boundary (normalization)
|
|
227
|
+
│ ├── blast-radius.ts # Weighted blast radius computation engine
|
|
228
|
+
│ ├── decision.ts # Runtime assurance engine
|
|
229
|
+
│ ├── monitor.ts # Escalation state machine
|
|
230
|
+
│ ├── evidence.ts # Evidence pack generation
|
|
231
|
+
│ ├── replay-comparator.ts # Replay outcome comparison
|
|
232
|
+
│ ├── replay-engine.ts # Deterministic replay engine
|
|
233
|
+
│ ├── replay-processor.ts # Replay event processor
|
|
234
|
+
│ ├── decisions/ # Typed decision records
|
|
235
|
+
│ └── simulation/ # Pre-execution impact simulation
|
|
236
|
+
├── events/ # Canonical event model
|
|
237
|
+
│ ├── schema.ts # Event kinds, factory, validation
|
|
238
|
+
│ ├── bus.ts # Generic typed EventBus
|
|
239
|
+
│ ├── store.ts # In-memory event store
|
|
240
|
+
│ ├── jsonl.ts # JSONL event persistence (audit trail)
|
|
241
|
+
│ └── decision-jsonl.ts # Decision record persistence
|
|
242
|
+
├── policy/ # Policy system
|
|
243
|
+
│ ├── evaluator.ts # Rule matching engine
|
|
244
|
+
│ ├── loader.ts # Policy validation + loading
|
|
245
|
+
│ ├── pack-loader.ts # Policy pack loader (community policy sets)
|
|
246
|
+
│ └── yaml-loader.ts # YAML policy parser
|
|
247
|
+
├── invariants/ # Invariant system
|
|
248
|
+
│ ├── definitions.ts # 8 built-in invariants
|
|
249
|
+
│ └── checker.ts # Invariant evaluation engine
|
|
250
|
+
├── adapters/ # Execution adapters
|
|
251
|
+
│ ├── file.ts, shell.ts, git.ts # Action handlers
|
|
252
|
+
│ ├── claude-code.ts # Claude Code hook adapter
|
|
253
|
+
│ └── registry.ts # Adapter registry
|
|
254
|
+
├── plugins/ # Plugin ecosystem
|
|
255
|
+
│ ├── discovery.ts # Plugin discovery mechanism
|
|
256
|
+
│ ├── registry.ts # Plugin registry
|
|
257
|
+
│ ├── sandbox.ts # Plugin sandboxing
|
|
258
|
+
│ ├── validator.ts # Plugin validation
|
|
259
|
+
│ ├── types.ts # Plugin type definitions
|
|
260
|
+
│ └── index.ts # Module re-exports
|
|
261
|
+
├── renderers/ # Renderer plugin system
|
|
262
|
+
│ ├── registry.ts # Renderer registry
|
|
263
|
+
│ ├── tui-renderer.ts # TUI renderer implementation
|
|
264
|
+
│ ├── types.ts # Renderer type definitions
|
|
265
|
+
│ └── index.ts # Module re-exports
|
|
266
|
+
├── cli/ # CLI entry point + commands
|
|
267
|
+
│ ├── bin.ts # Main entry
|
|
268
|
+
│ └── commands/ # guard, inspect, replay, export, import, plugin, claude-hook, claude-init
|
|
269
|
+
├── telemetry/ # Runtime telemetry and logging
|
|
270
|
+
└── core/ # Shared utilities (types, actions, hash, rng, execution-log)
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## Run Locally
|
|
274
|
+
|
|
275
|
+
```bash
|
|
276
|
+
git clone https://github.com/jpleva91/agent-guard.git
|
|
277
|
+
cd agent-guard
|
|
278
|
+
npm install
|
|
279
|
+
npm run build:ts # Compile TypeScript → dist/
|
|
280
|
+
npm run ts:test # Run TypeScript tests (vitest)
|
|
281
|
+
npm test # Run JavaScript tests
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## Documentation
|
|
285
|
+
|
|
286
|
+
| Document | Description |
|
|
287
|
+
|----------|-------------|
|
|
288
|
+
| [AgentGuard Spec](docs/agentguard.md) | Governance runtime specification |
|
|
289
|
+
| [Architecture](docs/unified-architecture.md) | Governed action kernel model |
|
|
290
|
+
| [Priorities](docs/current-priorities.md) | Current roadmap and next steps |
|
|
291
|
+
| [Product Positioning](docs/product-positioning.md) | What this is and isn't |
|
|
292
|
+
| [Event Model](docs/event-model.md) | Canonical event schema |
|
|
293
|
+
| [Plugin API](docs/plugin-api.md) | Event sources and extension points |
|
|
294
|
+
| [Contributing](CONTRIBUTING.md) | How to contribute |
|
|
295
|
+
|
|
296
|
+
## License
|
|
297
|
+
|
|
298
|
+
[Apache 2.0](LICENSE)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { RawAgentAction } from '../kernel/aab.js';
|
|
2
|
+
import type { Kernel, KernelResult } from '../kernel/kernel.js';
|
|
3
|
+
export interface ClaudeCodeToolUse {
|
|
4
|
+
tool_name: string;
|
|
5
|
+
tool_input?: Record<string, unknown>;
|
|
6
|
+
tool_output?: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
export interface ClaudeCodeHookPayload {
|
|
9
|
+
hook: 'PreToolUse' | 'PostToolUse';
|
|
10
|
+
tool_name: string;
|
|
11
|
+
tool_input?: Record<string, unknown>;
|
|
12
|
+
tool_output?: Record<string, unknown>;
|
|
13
|
+
/** Claude Code session identifier for agent identity propagation */
|
|
14
|
+
session_id?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Resolve a meaningful agent identity from the session ID.
|
|
18
|
+
* Format: 'claude-code' (no session) or 'claude-code:<hash>' (with session).
|
|
19
|
+
*/
|
|
20
|
+
export declare function resolveAgentIdentity(sessionId?: string): string;
|
|
21
|
+
export declare function normalizeClaudeCodeAction(payload: ClaudeCodeHookPayload): RawAgentAction;
|
|
22
|
+
export declare function processClaudeCodeHook(kernel: Kernel, payload: ClaudeCodeHookPayload, systemContext?: Record<string, unknown>): Promise<KernelResult>;
|
|
23
|
+
export declare function formatHookResponse(result: KernelResult): string;
|
|
24
|
+
//# sourceMappingURL=claude-code.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-code.d.ts","sourceRoot":"","sources":["../../src/adapters/claude-code.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGhE,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACvC;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,YAAY,GAAG,aAAa,CAAC;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,oEAAoE;IACpE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAK/D;AAED,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,qBAAqB,GAAG,cAAc,CA0ExF;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,qBAAqB,EAC9B,aAAa,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAC1C,OAAO,CAAC,YAAY,CAAC,CAGvB;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAW/D"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Claude Code adapter — normalizes Claude Code hook payloads into kernel actions.
|
|
2
|
+
// Handles PreToolUse and PostToolUse hook events.
|
|
3
|
+
// Propagates agent session identity for audit correlation.
|
|
4
|
+
import { simpleHash } from '../core/hash.js';
|
|
5
|
+
/**
|
|
6
|
+
* Resolve a meaningful agent identity from the session ID.
|
|
7
|
+
* Format: 'claude-code' (no session) or 'claude-code:<hash>' (with session).
|
|
8
|
+
*/
|
|
9
|
+
export function resolveAgentIdentity(sessionId) {
|
|
10
|
+
if (!sessionId || typeof sessionId !== 'string' || sessionId.trim() === '') {
|
|
11
|
+
return 'claude-code';
|
|
12
|
+
}
|
|
13
|
+
return `claude-code:${simpleHash(sessionId.trim())}`;
|
|
14
|
+
}
|
|
15
|
+
export function normalizeClaudeCodeAction(payload) {
|
|
16
|
+
const input = payload.tool_input || {};
|
|
17
|
+
const agent = resolveAgentIdentity(payload.session_id);
|
|
18
|
+
switch (payload.tool_name) {
|
|
19
|
+
case 'Write':
|
|
20
|
+
return {
|
|
21
|
+
tool: 'Write',
|
|
22
|
+
file: input.file_path,
|
|
23
|
+
content: input.content,
|
|
24
|
+
agent,
|
|
25
|
+
metadata: { hook: payload.hook, sessionId: payload.session_id },
|
|
26
|
+
};
|
|
27
|
+
case 'Edit':
|
|
28
|
+
return {
|
|
29
|
+
tool: 'Edit',
|
|
30
|
+
file: input.file_path,
|
|
31
|
+
content: input.new_string,
|
|
32
|
+
agent,
|
|
33
|
+
metadata: {
|
|
34
|
+
hook: payload.hook,
|
|
35
|
+
old_string: input.old_string,
|
|
36
|
+
sessionId: payload.session_id,
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
case 'Read':
|
|
40
|
+
return {
|
|
41
|
+
tool: 'Read',
|
|
42
|
+
file: input.file_path,
|
|
43
|
+
agent,
|
|
44
|
+
metadata: { hook: payload.hook, sessionId: payload.session_id },
|
|
45
|
+
};
|
|
46
|
+
case 'Bash': {
|
|
47
|
+
const command = input.command;
|
|
48
|
+
return {
|
|
49
|
+
tool: 'Bash',
|
|
50
|
+
command,
|
|
51
|
+
target: command?.slice(0, 100),
|
|
52
|
+
agent,
|
|
53
|
+
metadata: {
|
|
54
|
+
hook: payload.hook,
|
|
55
|
+
timeout: input.timeout,
|
|
56
|
+
description: input.description,
|
|
57
|
+
sessionId: payload.session_id,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
case 'Glob':
|
|
62
|
+
return {
|
|
63
|
+
tool: 'Glob',
|
|
64
|
+
target: input.pattern,
|
|
65
|
+
agent,
|
|
66
|
+
metadata: { hook: payload.hook, path: input.path, sessionId: payload.session_id },
|
|
67
|
+
};
|
|
68
|
+
case 'Grep':
|
|
69
|
+
return {
|
|
70
|
+
tool: 'Grep',
|
|
71
|
+
target: input.pattern,
|
|
72
|
+
agent,
|
|
73
|
+
metadata: { hook: payload.hook, path: input.path, sessionId: payload.session_id },
|
|
74
|
+
};
|
|
75
|
+
default:
|
|
76
|
+
return {
|
|
77
|
+
tool: payload.tool_name,
|
|
78
|
+
agent,
|
|
79
|
+
metadata: { hook: payload.hook, input, sessionId: payload.session_id },
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export async function processClaudeCodeHook(kernel, payload, systemContext = {}) {
|
|
84
|
+
const rawAction = normalizeClaudeCodeAction(payload);
|
|
85
|
+
return kernel.propose(rawAction, systemContext);
|
|
86
|
+
}
|
|
87
|
+
export function formatHookResponse(result) {
|
|
88
|
+
if (!result.allowed) {
|
|
89
|
+
const reason = result.decision.decision.reason;
|
|
90
|
+
const violations = result.decision.violations;
|
|
91
|
+
const parts = [`DENIED: ${reason}`];
|
|
92
|
+
if (violations.length > 0) {
|
|
93
|
+
parts.push(`Violations: ${violations.map((v) => v.name).join(', ')}`);
|
|
94
|
+
}
|
|
95
|
+
return JSON.stringify({ error: parts.join(' | ') });
|
|
96
|
+
}
|
|
97
|
+
return '';
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=claude-code.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-code.js","sourceRoot":"","sources":["../../src/adapters/claude-code.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/adapters/file.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD,wBAAsB,WAAW,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAmC3E"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// File operation adapter — executes file.read, file.write, file.delete actions.
|
|
2
|
+
// Node.js adapter. Uses fs APIs.
|
|
3
|
+
import { readFile, writeFile, unlink, rename } from 'node:fs/promises';
|
|
4
|
+
export async function fileAdapter(action) {
|
|
5
|
+
const target = action.target;
|
|
6
|
+
switch (action.type) {
|
|
7
|
+
case 'file.read': {
|
|
8
|
+
const content = await readFile(target, 'utf8');
|
|
9
|
+
return { path: target, size: content.length };
|
|
10
|
+
}
|
|
11
|
+
case 'file.write': {
|
|
12
|
+
const content = action.content;
|
|
13
|
+
if (content === undefined) {
|
|
14
|
+
throw new Error('file.write requires content');
|
|
15
|
+
}
|
|
16
|
+
await writeFile(target, content, 'utf8');
|
|
17
|
+
return { path: target, written: content.length };
|
|
18
|
+
}
|
|
19
|
+
case 'file.delete': {
|
|
20
|
+
await unlink(target);
|
|
21
|
+
return { path: target, deleted: true };
|
|
22
|
+
}
|
|
23
|
+
case 'file.move': {
|
|
24
|
+
const destination = action.destination;
|
|
25
|
+
if (!destination) {
|
|
26
|
+
throw new Error('file.move requires destination');
|
|
27
|
+
}
|
|
28
|
+
await rename(target, destination);
|
|
29
|
+
return { from: target, to: destination };
|
|
30
|
+
}
|
|
31
|
+
default:
|
|
32
|
+
throw new Error(`Unsupported file action: ${action.type}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/adapters/file.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,iCAAiC;AAEjC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAGvE,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAAuB;IACvD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAE7B,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,WAAW,CAAC,CAAC,CAAC;YACjB,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;QAChD,CAAC;QAED,KAAK,YAAY,CAAC,CAAC,CAAC;YAClB,MAAM,OAAO,GAAI,MAAkC,CAAC,OAA6B,CAAC;YAClF,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;gBAC1B,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;YACjD,CAAC;YACD,MAAM,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;YACzC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;QACnD,CAAC;QAED,KAAK,aAAa,CAAC,CAAC,CAAC;YACnB,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;YACrB,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QACzC,CAAC;QAED,KAAK,WAAW,CAAC,CAAC,CAAC;YACjB,MAAM,WAAW,GAAI,MAAkC,CAAC,WAAiC,CAAC;YAC1F,IAAI,CAAC,WAAW,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;YACpD,CAAC;YACD,MAAM,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;YAClC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC;QAC3C,CAAC;QAED;YACE,MAAM,IAAI,KAAK,CAAC,4BAA4B,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAC/D,CAAC;AACH,CAAC"}
|