@flowdot.ai/guardian-agent 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.
Files changed (188) hide show
  1. package/LICENSE +40 -0
  2. package/README.md +281 -0
  3. package/ROADMAP.md +109 -0
  4. package/dist/audit/attestor.d.ts +102 -0
  5. package/dist/audit/attestor.d.ts.map +1 -0
  6. package/dist/audit/attestor.js +103 -0
  7. package/dist/audit/attestor.js.map +1 -0
  8. package/dist/audit/chain.d.ts +30 -0
  9. package/dist/audit/chain.d.ts.map +1 -0
  10. package/dist/audit/chain.js +65 -0
  11. package/dist/audit/chain.js.map +1 -0
  12. package/dist/audit/correlation.d.ts +114 -0
  13. package/dist/audit/correlation.d.ts.map +1 -0
  14. package/dist/audit/correlation.js +259 -0
  15. package/dist/audit/correlation.js.map +1 -0
  16. package/dist/audit/index.d.ts +13 -0
  17. package/dist/audit/index.d.ts.map +1 -0
  18. package/dist/audit/index.js +8 -0
  19. package/dist/audit/index.js.map +1 -0
  20. package/dist/audit/reader.d.ts +30 -0
  21. package/dist/audit/reader.d.ts.map +1 -0
  22. package/dist/audit/reader.js +85 -0
  23. package/dist/audit/reader.js.map +1 -0
  24. package/dist/audit/signature.d.ts +39 -0
  25. package/dist/audit/signature.d.ts.map +1 -0
  26. package/dist/audit/signature.js +73 -0
  27. package/dist/audit/signature.js.map +1 -0
  28. package/dist/audit/stats.d.ts +106 -0
  29. package/dist/audit/stats.d.ts.map +1 -0
  30. package/dist/audit/stats.js +196 -0
  31. package/dist/audit/stats.js.map +1 -0
  32. package/dist/audit/writer.d.ts +96 -0
  33. package/dist/audit/writer.d.ts.map +1 -0
  34. package/dist/audit/writer.js +263 -0
  35. package/dist/audit/writer.js.map +1 -0
  36. package/dist/cli/guardian-baseline.d.ts +42 -0
  37. package/dist/cli/guardian-baseline.d.ts.map +1 -0
  38. package/dist/cli/guardian-baseline.js +265 -0
  39. package/dist/cli/guardian-baseline.js.map +1 -0
  40. package/dist/cli/guardian-correlator.d.ts +47 -0
  41. package/dist/cli/guardian-correlator.d.ts.map +1 -0
  42. package/dist/cli/guardian-correlator.js +217 -0
  43. package/dist/cli/guardian-correlator.js.map +1 -0
  44. package/dist/cli/guardian-verify.d.ts +30 -0
  45. package/dist/cli/guardian-verify.d.ts.map +1 -0
  46. package/dist/cli/guardian-verify.js +149 -0
  47. package/dist/cli/guardian-verify.js.map +1 -0
  48. package/dist/errors.d.ts +28 -0
  49. package/dist/errors.d.ts.map +1 -0
  50. package/dist/errors.js +40 -0
  51. package/dist/errors.js.map +1 -0
  52. package/dist/estop/heartbeat.d.ts +94 -0
  53. package/dist/estop/heartbeat.d.ts.map +1 -0
  54. package/dist/estop/heartbeat.js +135 -0
  55. package/dist/estop/heartbeat.js.map +1 -0
  56. package/dist/estop/hub.d.ts +76 -0
  57. package/dist/estop/hub.d.ts.map +1 -0
  58. package/dist/estop/hub.js +167 -0
  59. package/dist/estop/hub.js.map +1 -0
  60. package/dist/estop/index.d.ts +12 -0
  61. package/dist/estop/index.d.ts.map +1 -0
  62. package/dist/estop/index.js +6 -0
  63. package/dist/estop/index.js.map +1 -0
  64. package/dist/estop/local.d.ts +31 -0
  65. package/dist/estop/local.d.ts.map +1 -0
  66. package/dist/estop/local.js +101 -0
  67. package/dist/estop/local.js.map +1 -0
  68. package/dist/estop/middleware.d.ts +36 -0
  69. package/dist/estop/middleware.d.ts.map +1 -0
  70. package/dist/estop/middleware.js +40 -0
  71. package/dist/estop/middleware.js.map +1 -0
  72. package/dist/estop/poller.d.ts +36 -0
  73. package/dist/estop/poller.d.ts.map +1 -0
  74. package/dist/estop/poller.js +85 -0
  75. package/dist/estop/poller.js.map +1 -0
  76. package/dist/estop/types.d.ts +31 -0
  77. package/dist/estop/types.d.ts.map +1 -0
  78. package/dist/estop/types.js +5 -0
  79. package/dist/estop/types.js.map +1 -0
  80. package/dist/gate/async-callback.d.ts +27 -0
  81. package/dist/gate/async-callback.d.ts.map +1 -0
  82. package/dist/gate/async-callback.js +79 -0
  83. package/dist/gate/async-callback.js.map +1 -0
  84. package/dist/gate/cli.d.ts +29 -0
  85. package/dist/gate/cli.d.ts.map +1 -0
  86. package/dist/gate/cli.js +83 -0
  87. package/dist/gate/cli.js.map +1 -0
  88. package/dist/gate/data-channel.d.ts +41 -0
  89. package/dist/gate/data-channel.d.ts.map +1 -0
  90. package/dist/gate/data-channel.js +132 -0
  91. package/dist/gate/data-channel.js.map +1 -0
  92. package/dist/gate/index.d.ts +13 -0
  93. package/dist/gate/index.d.ts.map +1 -0
  94. package/dist/gate/index.js +7 -0
  95. package/dist/gate/index.js.map +1 -0
  96. package/dist/gate/options.d.ts +90 -0
  97. package/dist/gate/options.d.ts.map +1 -0
  98. package/dist/gate/options.js +131 -0
  99. package/dist/gate/options.js.map +1 -0
  100. package/dist/gate/programmatic.d.ts +9 -0
  101. package/dist/gate/programmatic.d.ts.map +1 -0
  102. package/dist/gate/programmatic.js +20 -0
  103. package/dist/gate/programmatic.js.map +1 -0
  104. package/dist/gate/two-key.d.ts +90 -0
  105. package/dist/gate/two-key.d.ts.map +1 -0
  106. package/dist/gate/two-key.js +78 -0
  107. package/dist/gate/two-key.js.map +1 -0
  108. package/dist/gate/types.d.ts +25 -0
  109. package/dist/gate/types.d.ts.map +1 -0
  110. package/dist/gate/types.js +5 -0
  111. package/dist/gate/types.js.map +1 -0
  112. package/dist/index.d.ts +33 -0
  113. package/dist/index.d.ts.map +1 -0
  114. package/dist/index.js +26 -0
  115. package/dist/index.js.map +1 -0
  116. package/dist/notify/console.d.ts +13 -0
  117. package/dist/notify/console.d.ts.map +1 -0
  118. package/dist/notify/console.js +27 -0
  119. package/dist/notify/console.js.map +1 -0
  120. package/dist/notify/index.d.ts +8 -0
  121. package/dist/notify/index.d.ts.map +1 -0
  122. package/dist/notify/index.js +4 -0
  123. package/dist/notify/index.js.map +1 -0
  124. package/dist/notify/multi.d.ts +14 -0
  125. package/dist/notify/multi.d.ts.map +1 -0
  126. package/dist/notify/multi.js +22 -0
  127. package/dist/notify/multi.js.map +1 -0
  128. package/dist/notify/types.d.ts +21 -0
  129. package/dist/notify/types.d.ts.map +1 -0
  130. package/dist/notify/types.js +5 -0
  131. package/dist/notify/types.js.map +1 -0
  132. package/dist/notify/webhook.d.ts +21 -0
  133. package/dist/notify/webhook.d.ts.map +1 -0
  134. package/dist/notify/webhook.js +37 -0
  135. package/dist/notify/webhook.js.map +1 -0
  136. package/dist/policy/attribution.d.ts +61 -0
  137. package/dist/policy/attribution.d.ts.map +1 -0
  138. package/dist/policy/attribution.js +116 -0
  139. package/dist/policy/attribution.js.map +1 -0
  140. package/dist/policy/evaluator.d.ts +36 -0
  141. package/dist/policy/evaluator.d.ts.map +1 -0
  142. package/dist/policy/evaluator.js +211 -0
  143. package/dist/policy/evaluator.js.map +1 -0
  144. package/dist/policy/index.d.ts +11 -0
  145. package/dist/policy/index.d.ts.map +1 -0
  146. package/dist/policy/index.js +7 -0
  147. package/dist/policy/index.js.map +1 -0
  148. package/dist/policy/integrity.d.ts +17 -0
  149. package/dist/policy/integrity.d.ts.map +1 -0
  150. package/dist/policy/integrity.js +31 -0
  151. package/dist/policy/integrity.js.map +1 -0
  152. package/dist/policy/loader.d.ts +9 -0
  153. package/dist/policy/loader.d.ts.map +1 -0
  154. package/dist/policy/loader.js +124 -0
  155. package/dist/policy/loader.js.map +1 -0
  156. package/dist/policy/site-key.d.ts +22 -0
  157. package/dist/policy/site-key.d.ts.map +1 -0
  158. package/dist/policy/site-key.js +48 -0
  159. package/dist/policy/site-key.js.map +1 -0
  160. package/dist/policy/store.d.ts +45 -0
  161. package/dist/policy/store.d.ts.map +1 -0
  162. package/dist/policy/store.js +223 -0
  163. package/dist/policy/store.js.map +1 -0
  164. package/dist/policy/types.d.ts +72 -0
  165. package/dist/policy/types.d.ts.map +1 -0
  166. package/dist/policy/types.js +5 -0
  167. package/dist/policy/types.js.map +1 -0
  168. package/dist/runtime/capability.d.ts +125 -0
  169. package/dist/runtime/capability.d.ts.map +1 -0
  170. package/dist/runtime/capability.js +121 -0
  171. package/dist/runtime/capability.js.map +1 -0
  172. package/dist/runtime/honeytokens.d.ts +104 -0
  173. package/dist/runtime/honeytokens.d.ts.map +1 -0
  174. package/dist/runtime/honeytokens.js +115 -0
  175. package/dist/runtime/honeytokens.js.map +1 -0
  176. package/dist/runtime/multi-rate-limiter.d.ts +90 -0
  177. package/dist/runtime/multi-rate-limiter.d.ts.map +1 -0
  178. package/dist/runtime/multi-rate-limiter.js +133 -0
  179. package/dist/runtime/multi-rate-limiter.js.map +1 -0
  180. package/dist/runtime/runtime.d.ts +94 -0
  181. package/dist/runtime/runtime.d.ts.map +1 -0
  182. package/dist/runtime/runtime.js +276 -0
  183. package/dist/runtime/runtime.js.map +1 -0
  184. package/dist/types.d.ts +97 -0
  185. package/dist/types.d.ts.map +1 -0
  186. package/dist/types.js +5 -0
  187. package/dist/types.js.map +1 -0
  188. package/package.json +83 -0
@@ -0,0 +1,13 @@
1
+ export type { ApprovalGate, GateRequest, GateResponse, GateGranularity, GateDecision, } from './types.js';
2
+ export { cliApprovalGate, parseCliAnswer } from './cli.js';
3
+ export type { CliGateOptions } from './cli.js';
4
+ export { asyncCallbackGate } from './async-callback.js';
5
+ export type { AsyncCallbackGateOptions } from './async-callback.js';
6
+ export { programmaticGate } from './programmatic.js';
7
+ export { dataChannelGate, encodeRequest, decodeResponse } from './data-channel.js';
8
+ export type { DataChannelGateOptions, DataChannelSend, DataChannelOnResponse, } from './data-channel.js';
9
+ export { CLASSIC_FOUR, FLOWDOT_FIVE, defineGateOptionSet, findOption, resolveOption, } from './options.js';
10
+ export type { GateOption, GateOptionSet } from './options.js';
11
+ export { callbackOperatorGate, denyAllOperatorGate, newGateId, awaitWithTimeout, } from './two-key.js';
12
+ export type { OperatorConfirmationGate, OperatorConfirmationRequest, OperatorConfirmationResponse, } from './two-key.js';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/gate/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,eAAe,EACf,YAAY,GACb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC3D,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnF,YAAY,EACV,sBAAsB,EACtB,eAAe,EACf,qBAAqB,GACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,mBAAmB,EACnB,UAAU,EACV,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,SAAS,EACT,gBAAgB,GACjB,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,wBAAwB,EACxB,2BAA2B,EAC3B,4BAA4B,GAC7B,MAAM,cAAc,CAAC"}
@@ -0,0 +1,7 @@
1
+ export { cliApprovalGate, parseCliAnswer } from './cli.js';
2
+ export { asyncCallbackGate } from './async-callback.js';
3
+ export { programmaticGate } from './programmatic.js';
4
+ export { dataChannelGate, encodeRequest, decodeResponse } from './data-channel.js';
5
+ export { CLASSIC_FOUR, FLOWDOT_FIVE, defineGateOptionSet, findOption, resolveOption, } from './options.js';
6
+ export { callbackOperatorGate, denyAllOperatorGate, newGateId, awaitWithTimeout, } from './two-key.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/gate/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAMnF,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,mBAAmB,EACnB,UAAU,EACV,aAAa,GACd,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,SAAS,EACT,gBAAgB,GACjB,MAAM,cAAc,CAAC"}
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Gate option sets. SPEC §4 (extension).
3
+ *
4
+ * The fixed 5-button `GateDecision` enum (`allow`/`allow_session`/
5
+ * `allow_forever`/`deny`/`ban_forever`) is preserved for back-compat. This
6
+ * module adds a parallel configurable-option-set system: consumers declare
7
+ * which buttons to show, with their own ids/labels, and the library carries
8
+ * the chosen-option id through gate responses + audit records.
9
+ *
10
+ * FlowDot uses {@link FLOWDOT_FIVE} on its voice/live surface and
11
+ * {@link CLASSIC_FOUR} on its file-permission surface. Anyone else can ship
12
+ * their own `GateOptionSet`.
13
+ */
14
+ import type { PolicyScope } from '../policy/types.js';
15
+ import type { GateGranularity } from './types.js';
16
+ /**
17
+ * One button in an approval prompt.
18
+ *
19
+ * - `id` is the stable wire string surfaced in `GateResponse.chosen_option_id`
20
+ * and recorded in audit records. Keep it short and ASCII (`once`,
21
+ * `session`, `toolkit`, etc.).
22
+ * - `scope` is what gets persisted if the consumer's policy store records the
23
+ * answer. `'once'` means do-not-persist.
24
+ * - `decision` is the immediate yes/no for THIS call.
25
+ * - `granularity` controls what the persisted rule covers when `scope` is
26
+ * anything other than `'once'`. `'tool'` is the default and means "this
27
+ * specific tool name"; `'toolkit'` means "every tool in this toolkit";
28
+ * `'category'` means "every tool in this category".
29
+ */
30
+ export interface GateOption {
31
+ id: string;
32
+ label?: string;
33
+ scope: PolicyScope;
34
+ decision: 'allow' | 'deny';
35
+ granularity?: GateGranularity;
36
+ }
37
+ /**
38
+ * A named collection of {@link GateOption}s, ordered for display.
39
+ *
40
+ * Consumers SHOULD render options in declaration order. The library does not
41
+ * enforce uniqueness of `id` within a set — but lookups by id return the
42
+ * first match, so duplicates only confuse readers.
43
+ */
44
+ export interface GateOptionSet {
45
+ /** Stable identifier for the set itself (recorded in audit on gate_request). */
46
+ id: string;
47
+ /** Optional human note describing what this set is for. */
48
+ description?: string;
49
+ /** The options, in display order. */
50
+ options: GateOption[];
51
+ }
52
+ /**
53
+ * FlowDot's live-call gate. Five buttons.
54
+ *
55
+ * - `once` — allow this call only, persist nothing
56
+ * - `session` — allow for this session
57
+ * - `tool` — allow this specific tool forever
58
+ * - `toolkit` — allow every tool in this toolkit forever
59
+ * - `deny` — refuse this call
60
+ */
61
+ export declare const FLOWDOT_FIVE: GateOptionSet;
62
+ /**
63
+ * FlowDot's classic file-permission gate. Four scopes (`banned` is implied by
64
+ * a deny-forever option).
65
+ *
66
+ * - `once` — allow this call only
67
+ * - `session` — allow for this session
68
+ * - `forever` — allow this tool forever
69
+ * - `banned` — deny this tool forever
70
+ */
71
+ export declare const CLASSIC_FOUR: GateOptionSet;
72
+ /**
73
+ * Build a custom option set. Useful for consumers who want a non-standard
74
+ * combination — e.g. a "stop the world" pseudo-option that triggers an estop.
75
+ *
76
+ * Throws if `options` is empty or contains duplicate ids.
77
+ */
78
+ export declare function defineGateOptionSet(id: string, options: GateOption[], description?: string): GateOptionSet;
79
+ /**
80
+ * Find an option by id. Returns `undefined` when no match.
81
+ */
82
+ export declare function findOption(set: GateOptionSet, optionId: string): GateOption | undefined;
83
+ /**
84
+ * Resolve a chosen option id against a set. Returns the option, or throws
85
+ * with a clear message listing the valid ids. Use this when an external
86
+ * caller (UI, IPC frame, data-channel response) provides a string and you
87
+ * want to fail loudly on typos.
88
+ */
89
+ export declare function resolveOption(set: GateOptionSet, optionId: string): GateOption;
90
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/gate/options.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,OAAO,GAAG,MAAM,CAAC;IAC3B,WAAW,CAAC,EAAE,eAAe,CAAC;CAC/B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC5B,gFAAgF;IAChF,EAAE,EAAE,MAAM,CAAC;IACX,2DAA2D;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qCAAqC;IACrC,OAAO,EAAE,UAAU,EAAE,CAAC;CACvB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,EAAE,aA4B1B,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,EAAE,aA2B1B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,aAAa,CAc1G;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAEvF;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,CAS9E"}
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Gate option sets. SPEC §4 (extension).
3
+ *
4
+ * The fixed 5-button `GateDecision` enum (`allow`/`allow_session`/
5
+ * `allow_forever`/`deny`/`ban_forever`) is preserved for back-compat. This
6
+ * module adds a parallel configurable-option-set system: consumers declare
7
+ * which buttons to show, with their own ids/labels, and the library carries
8
+ * the chosen-option id through gate responses + audit records.
9
+ *
10
+ * FlowDot uses {@link FLOWDOT_FIVE} on its voice/live surface and
11
+ * {@link CLASSIC_FOUR} on its file-permission surface. Anyone else can ship
12
+ * their own `GateOptionSet`.
13
+ */
14
+ /**
15
+ * FlowDot's live-call gate. Five buttons.
16
+ *
17
+ * - `once` — allow this call only, persist nothing
18
+ * - `session` — allow for this session
19
+ * - `tool` — allow this specific tool forever
20
+ * - `toolkit` — allow every tool in this toolkit forever
21
+ * - `deny` — refuse this call
22
+ */
23
+ export const FLOWDOT_FIVE = {
24
+ id: 'flowdot-five',
25
+ description: 'FlowDot voice/live tool-call approval (5 buttons).',
26
+ options: [
27
+ { id: 'once', label: 'Allow once', scope: 'once', decision: 'allow', granularity: 'tool' },
28
+ {
29
+ id: 'session',
30
+ label: 'Allow for this session',
31
+ scope: 'session',
32
+ decision: 'allow',
33
+ granularity: 'tool',
34
+ },
35
+ {
36
+ id: 'tool',
37
+ label: 'Always allow this tool',
38
+ scope: 'forever',
39
+ decision: 'allow',
40
+ granularity: 'tool',
41
+ },
42
+ {
43
+ id: 'toolkit',
44
+ label: 'Always allow this toolkit',
45
+ scope: 'forever',
46
+ decision: 'allow',
47
+ granularity: 'toolkit',
48
+ },
49
+ { id: 'deny', label: 'Deny', scope: 'once', decision: 'deny', granularity: 'tool' },
50
+ ],
51
+ };
52
+ /**
53
+ * FlowDot's classic file-permission gate. Four scopes (`banned` is implied by
54
+ * a deny-forever option).
55
+ *
56
+ * - `once` — allow this call only
57
+ * - `session` — allow for this session
58
+ * - `forever` — allow this tool forever
59
+ * - `banned` — deny this tool forever
60
+ */
61
+ export const CLASSIC_FOUR = {
62
+ id: 'classic-four',
63
+ description: 'FlowDot file-permission scopes (once/session/forever/banned).',
64
+ options: [
65
+ { id: 'once', label: 'Allow once', scope: 'once', decision: 'allow', granularity: 'tool' },
66
+ {
67
+ id: 'session',
68
+ label: 'Allow for this session',
69
+ scope: 'session',
70
+ decision: 'allow',
71
+ granularity: 'tool',
72
+ },
73
+ {
74
+ id: 'forever',
75
+ label: 'Always allow',
76
+ scope: 'forever',
77
+ decision: 'allow',
78
+ granularity: 'tool',
79
+ },
80
+ {
81
+ id: 'banned',
82
+ label: 'Never allow',
83
+ scope: 'banned',
84
+ decision: 'deny',
85
+ granularity: 'tool',
86
+ },
87
+ ],
88
+ };
89
+ /**
90
+ * Build a custom option set. Useful for consumers who want a non-standard
91
+ * combination — e.g. a "stop the world" pseudo-option that triggers an estop.
92
+ *
93
+ * Throws if `options` is empty or contains duplicate ids.
94
+ */
95
+ export function defineGateOptionSet(id, options, description) {
96
+ if (options.length === 0) {
97
+ throw new Error('defineGateOptionSet: options must be non-empty');
98
+ }
99
+ const seen = new Set();
100
+ for (const o of options) {
101
+ if (seen.has(o.id)) {
102
+ throw new Error(`defineGateOptionSet: duplicate option id ${JSON.stringify(o.id)}`);
103
+ }
104
+ seen.add(o.id);
105
+ }
106
+ const out = { id, options };
107
+ if (description !== undefined)
108
+ out.description = description;
109
+ return out;
110
+ }
111
+ /**
112
+ * Find an option by id. Returns `undefined` when no match.
113
+ */
114
+ export function findOption(set, optionId) {
115
+ return set.options.find((o) => o.id === optionId);
116
+ }
117
+ /**
118
+ * Resolve a chosen option id against a set. Returns the option, or throws
119
+ * with a clear message listing the valid ids. Use this when an external
120
+ * caller (UI, IPC frame, data-channel response) provides a string and you
121
+ * want to fail loudly on typos.
122
+ */
123
+ export function resolveOption(set, optionId) {
124
+ const found = findOption(set, optionId);
125
+ if (!found) {
126
+ const valid = set.options.map((o) => o.id).join(', ');
127
+ throw new Error(`Unknown gate option ${JSON.stringify(optionId)} for set ${JSON.stringify(set.id)}. Valid: ${valid}.`);
128
+ }
129
+ return found;
130
+ }
131
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/gate/options.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * programmaticGate — wraps an arbitrary handler. SPEC §4.3.
3
+ *
4
+ * Use when the host application has its own UI (Electron renderer, mobile RN
5
+ * modal, etc.) and the gate is "just call this function and wait."
6
+ */
7
+ import type { ApprovalGate, GateRequest, GateResponse } from './types.js';
8
+ export declare function programmaticGate(handler: (request: GateRequest) => Promise<GateResponse> | GateResponse): ApprovalGate;
9
+ //# sourceMappingURL=programmatic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"programmatic.d.ts","sourceRoot":"","sources":["../../src/gate/programmatic.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1E,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,YAAY,CAAC,GAAG,YAAY,GACtE,YAAY,CAYd"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * programmaticGate — wraps an arbitrary handler. SPEC §4.3.
3
+ *
4
+ * Use when the host application has its own UI (Electron renderer, mobile RN
5
+ * modal, etc.) and the gate is "just call this function and wait."
6
+ */
7
+ export function programmaticGate(handler) {
8
+ return async (request) => {
9
+ const response = await handler(request);
10
+ if (response.granularity !== request.granularity) {
11
+ // SPEC §4.3: gate may not escalate granularity. The library defends by
12
+ // downgrading any wider response to the requested granularity rather
13
+ // than throwing — this preserves liveness while preventing escalation.
14
+ // (A more conservative deployment can wrap the handler to throw.)
15
+ return { ...response, granularity: request.granularity };
16
+ }
17
+ return response;
18
+ };
19
+ }
20
+ //# sourceMappingURL=programmatic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"programmatic.js","sourceRoot":"","sources":["../../src/gate/programmatic.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,UAAU,gBAAgB,CAC9B,OAAuE;IAEvE,OAAO,KAAK,EAAE,OAAoB,EAAyB,EAAE;QAC3D,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;QACxC,IAAI,QAAQ,CAAC,WAAW,KAAK,OAAO,CAAC,WAAW,EAAE,CAAC;YACjD,uEAAuE;YACvE,qEAAqE;YACrE,uEAAuE;YACvE,kEAAkE;YAClE,OAAO,EAAE,GAAG,QAAQ,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC;QAC3D,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Two-key operator authorization. SPEC §4.5 (v0.4.0+).
3
+ *
4
+ * For tool dispatches that require fresh operator confirmation before
5
+ * proceeding (analogous to `sudo` for AI agents, or the Hub's
6
+ * `password.confirm` gate for `panic_clear`), the runtime suspends the
7
+ * call, writes a `policy_check { status: pending_operator }` audit row
8
+ * with a unique `gate_id`, and calls the configured
9
+ * `OperatorConfirmationGate.request()`. The gate's response — approved or
10
+ * denied — resolves the suspended call. A timeout is treated as denied
11
+ * (fail-closed).
12
+ *
13
+ * The library defines the suspend/resume + timeout mechanism. The actual
14
+ * transport (HTTP webhook, IPC frame to a UI process, LiveKit data
15
+ * channel, Hub-side password.confirm endpoint) is consumer-supplied. The
16
+ * library ships:
17
+ *
18
+ * - `OperatorConfirmationGate` interface (one method, `request`)
19
+ * - `callbackOperatorGate(fn)` reference adapter (wraps a plain JS callback)
20
+ * - `denyAllOperatorGate()` reference adapter (defensive fallback)
21
+ *
22
+ * Pure mechanism: blocking wait on an external signal, hard timeout, audit
23
+ * lifecycle. No reasoning about whether the call is safe — only that this
24
+ * class of call requires a human.
25
+ */
26
+ /**
27
+ * Payload supplied to the gate when a suspended call asks for confirmation.
28
+ */
29
+ export interface OperatorConfirmationRequest {
30
+ /** Stable correlation id. Matches `detail.gate_id` on the pending audit row. */
31
+ gate_id: string;
32
+ /** Tool that would be dispatched if approved. */
33
+ tool_name: string;
34
+ /** Tool's args (CALLER REDACTED — same shape that lands in audit). */
35
+ tool_args: Record<string, unknown>;
36
+ /** Human-readable reason this gate fired (rule id, capability name, etc.). */
37
+ reason: string;
38
+ /** Hard timeout in ms. Library enforces this; gate MAY return sooner. */
39
+ timeout_ms: number;
40
+ /** Agent id stamped on the audit row. */
41
+ agent_id: string;
42
+ /** Session id stamped on the audit row. */
43
+ session_id: string;
44
+ }
45
+ /**
46
+ * Response from the gate. Library accepts the decision verbatim; on timeout
47
+ * the library synthesizes `{ decision: 'denied', reason: 'timeout' }`.
48
+ */
49
+ export interface OperatorConfirmationResponse {
50
+ decision: 'approved' | 'denied';
51
+ /** Free-text id of the operator (auth subject, hostname, etc.). */
52
+ operator_id?: string;
53
+ /** Free-text reason; primarily for denied + timeout cases. */
54
+ reason?: string;
55
+ }
56
+ /**
57
+ * The contract a consumer implements. One method.
58
+ *
59
+ * Implementations MUST NOT mutate `request`. Implementations MAY block as
60
+ * long as they like; the library enforces `timeout_ms` independently via
61
+ * Promise.race.
62
+ */
63
+ export interface OperatorConfirmationGate {
64
+ request(req: OperatorConfirmationRequest): Promise<OperatorConfirmationResponse> | OperatorConfirmationResponse;
65
+ }
66
+ /**
67
+ * Wrap a callback as a gate. Useful for in-process testing, simple consumer
68
+ * setups, and the "operator types y/n in the terminal" pattern.
69
+ *
70
+ * The callback receives the request; whatever it resolves/returns becomes
71
+ * the response.
72
+ */
73
+ export declare function callbackOperatorGate(fn: (req: OperatorConfirmationRequest) => Promise<OperatorConfirmationResponse> | OperatorConfirmationResponse): OperatorConfirmationGate;
74
+ /**
75
+ * Reference gate that denies every request. Defensive fallback used when
76
+ * the consumer wants `requiresOperatorConfirmation: true` to fail-closed
77
+ * (e.g., CI environments with no operator transport wired).
78
+ */
79
+ export declare function denyAllOperatorGate(reason?: string): OperatorConfirmationGate;
80
+ /**
81
+ * Generate a fresh gate_id. Exposed for tests; runtime calls this internally.
82
+ */
83
+ export declare function newGateId(): string;
84
+ /**
85
+ * Race a gate response against a timeout. Returns the gate's response, or
86
+ * a synthesized `denied/timeout` response after `timeout_ms`. Internal —
87
+ * the runtime uses this; exposed for tests.
88
+ */
89
+ export declare function awaitWithTimeout(gate: OperatorConfirmationGate, request: OperatorConfirmationRequest): Promise<OperatorConfirmationResponse>;
90
+ //# sourceMappingURL=two-key.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"two-key.d.ts","sourceRoot":"","sources":["../../src/gate/two-key.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAIH;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,gFAAgF;IAChF,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,SAAS,EAAE,MAAM,CAAC;IAClB,sEAAsE;IACtE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,8EAA8E;IAC9E,MAAM,EAAE,MAAM,CAAC;IACf,yEAAyE;IACzE,UAAU,EAAE,MAAM,CAAC;IACnB,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,EAAE,UAAU,GAAG,QAAQ,CAAC;IAChC,mEAAmE;IACnE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8DAA8D;IAC9D,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,wBAAwB;IACvC,OAAO,CACL,GAAG,EAAE,2BAA2B,GAC/B,OAAO,CAAC,4BAA4B,CAAC,GAAG,4BAA4B,CAAC;CACzE;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,EAAE,EAAE,CACF,GAAG,EAAE,2BAA2B,KAC7B,OAAO,CAAC,4BAA4B,CAAC,GAAG,4BAA4B,GACxE,wBAAwB,CAE1B;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,SAAgC,GAAG,wBAAwB,CAIpG;AAED;;GAEG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAElC;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,wBAAwB,EAC9B,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,4BAA4B,CAAC,CAiBvC"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Two-key operator authorization. SPEC §4.5 (v0.4.0+).
3
+ *
4
+ * For tool dispatches that require fresh operator confirmation before
5
+ * proceeding (analogous to `sudo` for AI agents, or the Hub's
6
+ * `password.confirm` gate for `panic_clear`), the runtime suspends the
7
+ * call, writes a `policy_check { status: pending_operator }` audit row
8
+ * with a unique `gate_id`, and calls the configured
9
+ * `OperatorConfirmationGate.request()`. The gate's response — approved or
10
+ * denied — resolves the suspended call. A timeout is treated as denied
11
+ * (fail-closed).
12
+ *
13
+ * The library defines the suspend/resume + timeout mechanism. The actual
14
+ * transport (HTTP webhook, IPC frame to a UI process, LiveKit data
15
+ * channel, Hub-side password.confirm endpoint) is consumer-supplied. The
16
+ * library ships:
17
+ *
18
+ * - `OperatorConfirmationGate` interface (one method, `request`)
19
+ * - `callbackOperatorGate(fn)` reference adapter (wraps a plain JS callback)
20
+ * - `denyAllOperatorGate()` reference adapter (defensive fallback)
21
+ *
22
+ * Pure mechanism: blocking wait on an external signal, hard timeout, audit
23
+ * lifecycle. No reasoning about whether the call is safe — only that this
24
+ * class of call requires a human.
25
+ */
26
+ import { ulid } from 'ulidx';
27
+ /**
28
+ * Wrap a callback as a gate. Useful for in-process testing, simple consumer
29
+ * setups, and the "operator types y/n in the terminal" pattern.
30
+ *
31
+ * The callback receives the request; whatever it resolves/returns becomes
32
+ * the response.
33
+ */
34
+ export function callbackOperatorGate(fn) {
35
+ return { request: fn };
36
+ }
37
+ /**
38
+ * Reference gate that denies every request. Defensive fallback used when
39
+ * the consumer wants `requiresOperatorConfirmation: true` to fail-closed
40
+ * (e.g., CI environments with no operator transport wired).
41
+ */
42
+ export function denyAllOperatorGate(reason = 'no operator gate configured') {
43
+ return {
44
+ request: () => ({ decision: 'denied', reason }),
45
+ };
46
+ }
47
+ /**
48
+ * Generate a fresh gate_id. Exposed for tests; runtime calls this internally.
49
+ */
50
+ export function newGateId() {
51
+ return 'gt_' + ulid();
52
+ }
53
+ /**
54
+ * Race a gate response against a timeout. Returns the gate's response, or
55
+ * a synthesized `denied/timeout` response after `timeout_ms`. Internal —
56
+ * the runtime uses this; exposed for tests.
57
+ */
58
+ export async function awaitWithTimeout(gate, request) {
59
+ const timeoutMs = request.timeout_ms;
60
+ let timer;
61
+ const timeout = new Promise((resolve) => {
62
+ timer = setTimeout(() => {
63
+ resolve({ decision: 'denied', reason: 'timeout' });
64
+ }, timeoutMs);
65
+ });
66
+ try {
67
+ const result = await Promise.race([
68
+ Promise.resolve(gate.request(request)),
69
+ timeout,
70
+ ]);
71
+ return result;
72
+ }
73
+ finally {
74
+ if (timer !== undefined)
75
+ clearTimeout(timer);
76
+ }
77
+ }
78
+ //# sourceMappingURL=two-key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"two-key.js","sourceRoot":"","sources":["../../src/gate/two-key.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AA+C7B;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAClC,EAEyE;IAEzE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AACzB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAM,GAAG,6BAA6B;IACxE,OAAO;QACL,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;KAChD,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS;IACvB,OAAO,KAAK,GAAG,IAAI,EAAE,CAAC;AACxB,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,IAA8B,EAC9B,OAAoC;IAEpC,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC;IACrC,IAAI,KAAgD,CAAC;IACrD,MAAM,OAAO,GAAG,IAAI,OAAO,CAA+B,CAAC,OAAO,EAAE,EAAE;QACpE,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YACtB,OAAO,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;QACrD,CAAC,EAAE,SAAS,CAAC,CAAC;IAChB,CAAC,CAAC,CAAC;IACH,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC;YAChC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACtC,OAAO;SACR,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;YAAS,CAAC;QACT,IAAI,KAAK,KAAK,SAAS;YAAE,YAAY,CAAC,KAAK,CAAC,CAAC;IAC/C,CAAC;AACH,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Gate types. SPEC §4.
3
+ */
4
+ import type { ModelAttribution } from '../types.js';
5
+ export type GateGranularity = 'tool' | 'toolkit' | 'category';
6
+ export type GateDecision = 'allow' | 'allow_session' | 'allow_forever' | 'deny' | 'ban_forever';
7
+ export interface GateRequest {
8
+ event_id: string;
9
+ tool_name: string;
10
+ tool_args: Record<string, unknown>;
11
+ agent_id: string;
12
+ session_id: string;
13
+ model?: ModelAttribution;
14
+ context?: string;
15
+ granularity: GateGranularity;
16
+ timeout_ms?: number;
17
+ }
18
+ export interface GateResponse {
19
+ decision: GateDecision;
20
+ reason?: string;
21
+ operator_id?: string;
22
+ granularity: GateGranularity;
23
+ }
24
+ export type ApprovalGate = (request: GateRequest) => Promise<GateResponse> | GateResponse;
25
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/gate/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,SAAS,GAAG,UAAU,CAAC;AAE9D,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,eAAe,GAAG,eAAe,GAAG,MAAM,GAAG,aAAa,CAAC;AAEhG,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,gBAAgB,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,eAAe,CAAC;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,YAAY,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,eAAe,CAAC;CAC9B;AAED,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Gate types. SPEC §4.
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/gate/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @flowdot.ai/guardian-agent — public API surface.
3
+ * SPEC: see flowdot-llc/guardian-agent/SPEC.md (v0.2.0).
4
+ */
5
+ export declare const VERSION: "0.1.0";
6
+ export { SPEC_VERSION } from './types.js';
7
+ export { GuardianRuntime } from './runtime/runtime.js';
8
+ export type { GuardianRuntimeOptions, ToolOptions } from './runtime/runtime.js';
9
+ export { defineHoneytokenSet, matchPhantomTool, matchHoneytokenInArgs, checkHoneytoken, } from './runtime/honeytokens.js';
10
+ export type { Honeytoken, HoneytokenSet, HoneytokenHit } from './runtime/honeytokens.js';
11
+ export { CapabilityWindow } from './runtime/capability.js';
12
+ export type { CapabilityClass, CapabilityRule, CapabilityEvent, CapabilityMatch, CapabilityWindowOptions, } from './runtime/capability.js';
13
+ export { MultiRateLimiter, DEFAULT_BUCKETS } from './runtime/multi-rate-limiter.js';
14
+ export type { BucketConfig, MultiRateLimiterOptions, ConsumeAllowed, ConsumeDenied, ConsumeResult, } from './runtime/multi-rate-limiter.js';
15
+ export { AuditLogWriter, AuditLogReader, GENESIS_HASH, computeRecordHash, canonicalJsonStringify, canonicalizeForHash, generateEd25519KeyPair, loadPrivateKey, loadPublicKey, signRecord, verifyRecord, SIGNATURE_PREFIX, httpAttestor, nullAttestor, payloadFromRecord, analyzeAgent, analyzeMultiAgent, compareToBaseline, mean, stddev, correlate, summarizeSessions, findOverlappingSessions, findArgsHashCollisions, findSequenceSimilarity, } from './audit/index.js';
16
+ export type { AuditLogWriterOptions, Ed25519KeyPair, Attestor, AttestationPayload, AttestationReceipt, HttpAttestorOptions, AgentProfile, Deviation, DeviationReport, CompareOptions, AuditSource, SessionSummary, CorrelationMatch, CorrelationOptions, } from './audit/index.js';
17
+ export { EStopLocal } from './estop/local.js';
18
+ export type { EStopLocalOptions } from './estop/local.js';
19
+ export { HeartbeatMonitor } from './estop/heartbeat.js';
20
+ export type { HeartbeatMonitorOptions } from './estop/heartbeat.js';
21
+ export type { EStopState, EStopPressOptions, EStopClearOptions, EStopPressResult, EStopClearResult, } from './estop/types.js';
22
+ export { CLASSIC_FOUR, FLOWDOT_FIVE, defineGateOptionSet, findOption, resolveOption, } from './gate/options.js';
23
+ export type { GateOption, GateOptionSet } from './gate/options.js';
24
+ export { callbackOperatorGate, denyAllOperatorGate, newGateId, awaitWithTimeout, } from './gate/two-key.js';
25
+ export type { OperatorConfirmationGate, OperatorConfirmationRequest, OperatorConfirmationResponse, } from './gate/two-key.js';
26
+ export { flatGlobMatch, matchAttributionPath, renderAttributionPath, ATTRIBUTION_MISSING_SEGMENT, } from './policy/attribution.js';
27
+ export type { PolicyWhen } from './policy/types.js';
28
+ export type { Notifier, NotificationEvent, NotificationKind } from './notify/types.js';
29
+ export { consoleNotifier, webhookNotifier, multiNotifier } from './notify/index.js';
30
+ export type { ConsoleNotifierOptions, WebhookNotifierOptions, MultiNotifierOptions, } from './notify/index.js';
31
+ export type { ModelAttribution, AuditRecord, AuditRecordKind, AuditRecordStatus, AuditRecordInitiator, } from './types.js';
32
+ export { GuardianHaltedError, GuardianConfigError, GuardianIntegrityError, } from './errors.js';
33
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}
package/dist/index.js ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @flowdot.ai/guardian-agent — public API surface.
3
+ * SPEC: see flowdot-llc/guardian-agent/SPEC.md (v0.2.0).
4
+ */
5
+ export const VERSION = '0.1.0';
6
+ export { SPEC_VERSION } from './types.js';
7
+ // runtime
8
+ export { GuardianRuntime } from './runtime/runtime.js';
9
+ export { defineHoneytokenSet, matchPhantomTool, matchHoneytokenInArgs, checkHoneytoken, } from './runtime/honeytokens.js';
10
+ export { CapabilityWindow } from './runtime/capability.js';
11
+ export { MultiRateLimiter, DEFAULT_BUCKETS } from './runtime/multi-rate-limiter.js';
12
+ // audit
13
+ export { AuditLogWriter, AuditLogReader, GENESIS_HASH, computeRecordHash, canonicalJsonStringify, canonicalizeForHash, generateEd25519KeyPair, loadPrivateKey, loadPublicKey, signRecord, verifyRecord, SIGNATURE_PREFIX, httpAttestor, nullAttestor, payloadFromRecord, analyzeAgent, analyzeMultiAgent, compareToBaseline, mean, stddev, correlate, summarizeSessions, findOverlappingSessions, findArgsHashCollisions, findSequenceSimilarity, } from './audit/index.js';
14
+ // estop
15
+ export { EStopLocal } from './estop/local.js';
16
+ export { HeartbeatMonitor } from './estop/heartbeat.js';
17
+ // gate option sets (custom + the FlowDot defaults)
18
+ export { CLASSIC_FOUR, FLOWDOT_FIVE, defineGateOptionSet, findOption, resolveOption, } from './gate/options.js';
19
+ // two-key operator authorization (v0.9 / SPEC §4.5)
20
+ export { callbackOperatorGate, denyAllOperatorGate, newGateId, awaitWithTimeout, } from './gate/two-key.js';
21
+ // policy attribution path matching (model/provider/aggregator/surface globs)
22
+ export { flatGlobMatch, matchAttributionPath, renderAttributionPath, ATTRIBUTION_MISSING_SEGMENT, } from './policy/attribution.js';
23
+ export { consoleNotifier, webhookNotifier, multiNotifier } from './notify/index.js';
24
+ // errors
25
+ export { GuardianHaltedError, GuardianConfigError, GuardianIntegrityError, } from './errors.js';
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,OAAgB,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,UAAU;AACV,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,qBAAqB,EACrB,eAAe,GAChB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAQ3D,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AASpF,QAAQ;AACR,OAAO,EACL,cAAc,EACd,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,sBAAsB,EACtB,cAAc,EACd,aAAa,EACb,UAAU,EACV,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,IAAI,EACJ,MAAM,EACN,SAAS,EACT,iBAAiB,EACjB,uBAAuB,EACvB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAkB1B,QAAQ;AACR,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAUxD,mDAAmD;AACnD,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,mBAAmB,EACnB,UAAU,EACV,aAAa,GACd,MAAM,mBAAmB,CAAC;AAG3B,oDAAoD;AACpD,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,SAAS,EACT,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAO3B,6EAA6E;AAC7E,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,qBAAqB,EACrB,2BAA2B,GAC5B,MAAM,yBAAyB,CAAC;AAKjC,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAgBpF,SAAS;AACT,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,aAAa,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * consoleNotifier — writes notification events to stderr (or a configured stream).
3
+ * SPEC §6.3.
4
+ */
5
+ import type { Notifier } from './types.js';
6
+ export interface ConsoleNotifierOptions {
7
+ /** Where to write. Defaults to process.stderr. */
8
+ stream?: NodeJS.WritableStream;
9
+ /** Prefix prepended to every line. Defaults to "[guardian]". */
10
+ prefix?: string;
11
+ }
12
+ export declare function consoleNotifier(options?: ConsoleNotifierOptions): Notifier;
13
+ //# sourceMappingURL=console.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../src/notify/console.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAqB,MAAM,YAAY,CAAC;AAE9D,MAAM,WAAW,sBAAsB;IACrC,kDAAkD;IAClD,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;IAC/B,gEAAgE;IAChE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,eAAe,CAAC,OAAO,GAAE,sBAA2B,GAAG,QAAQ,CAQ9E"}